diff options
author | Alexandru Croitor <alexandru.croitor@qt.io> | 2019-05-28 16:41:49 +0200 |
---|---|---|
committer | Alexandru Croitor <alexandru.croitor@qt.io> | 2019-06-03 15:14:42 +0200 |
commit | e4079eca49adce16e31dac2a18d49d7a55817891 (patch) | |
tree | 1dfb960ec1115b1f552afe8a013058542389505e /tests | |
parent | f32a6cfb6b6236533508901f114ab57396da8ff3 (diff) | |
parent | ec6dc5f78453048c4f0604655a34c6c20c79d819 (diff) |
Merge remote-tracking branch 'origin/dev' into wip/cmake
Take 5.
Change-Id: Ifb2d20e95ba824e45e667fba6c2ba45389991cc3
Diffstat (limited to 'tests')
201 files changed, 6923 insertions, 2561 deletions
diff --git a/tests/auto/concurrent/qtconcurrentrun/tst_qtconcurrentrun.cpp b/tests/auto/concurrent/qtconcurrentrun/tst_qtconcurrentrun.cpp index 8506d18dae..39d17e0a24 100644 --- a/tests/auto/concurrent/qtconcurrentrun/tst_qtconcurrentrun.cpp +++ b/tests/auto/concurrent/qtconcurrentrun/tst_qtconcurrentrun.cpp @@ -710,14 +710,12 @@ void tst_QtConcurrentRun::lambda() QCOMPARE(QtConcurrent::run([](int a, double b){ return a + b; }, 12, 15).result(), double(12+15)); QCOMPARE(QtConcurrent::run([](int a , int, int, int, int b){ return a + b; }, 1, 2, 3, 4, 5).result(), 1 + 5); -#ifdef Q_COMPILER_INITIALIZER_LISTS { QString str { "Hello World Foo" }; QFuture<QStringList> f1 = QtConcurrent::run([&](){ return str.split(' '); }); auto r = f1.result(); QCOMPARE(r, QStringList({"Hello", "World", "Foo"})); } -#endif // and now with explicit pool: QThreadPool pool; @@ -726,14 +724,12 @@ void tst_QtConcurrentRun::lambda() QCOMPARE(QtConcurrent::run(&pool, [](int a, double b){ return a + b; }, 12, 15).result(), double(12+15)); QCOMPARE(QtConcurrent::run(&pool, [](int a , int, int, int, int b){ return a + b; }, 1, 2, 3, 4, 5).result(), 1 + 5); -#ifdef Q_COMPILER_INITIALIZER_LISTS { QString str { "Hello World Foo" }; QFuture<QStringList> f1 = QtConcurrent::run(&pool, [&](){ return str.split(' '); }); auto r = f1.result(); QCOMPARE(r, QStringList({"Hello", "World", "Foo"})); } -#endif } QTEST_MAIN(tst_QtConcurrentRun) diff --git a/tests/auto/corelib/global/qflags/tst_qflags.cpp b/tests/auto/corelib/global/qflags/tst_qflags.cpp index 8265d21350..1568855032 100644 --- a/tests/auto/corelib/global/qflags/tst_qflags.cpp +++ b/tests/auto/corelib/global/qflags/tst_qflags.cpp @@ -258,7 +258,6 @@ void tst_QFlags::classEnum() void tst_QFlags::initializerLists() { -#if defined(Q_COMPILER_INITIALIZER_LISTS) Qt::MouseButtons bts = { Qt::LeftButton, Qt::RightButton }; QVERIFY(bts.testFlag(Qt::LeftButton)); QVERIFY(bts.testFlag(Qt::RightButton)); @@ -268,10 +267,6 @@ void tst_QFlags::initializerLists() QVERIFY(flags.testFlag(MyStrictNoOpEnum::StrictOne)); QVERIFY(flags.testFlag(MyStrictNoOpEnum::StrictFour)); QVERIFY(!flags.testFlag(MyStrictNoOpEnum::StrictTwo)); - -#else - QSKIP("This test requires C++11 initializer_list support."); -#endif // Q_COMPILER_INITIALIZER_LISTS } void tst_QFlags::testSetFlags() diff --git a/tests/auto/corelib/global/qfloat16/tst_qfloat16.cpp b/tests/auto/corelib/global/qfloat16/tst_qfloat16.cpp index 241dccb90e..0848a4160f 100644 --- a/tests/auto/corelib/global/qfloat16/tst_qfloat16.cpp +++ b/tests/auto/corelib/global/qfloat16/tst_qfloat16.cpp @@ -1,5 +1,6 @@ /**************************************************************************** ** +** Copyright (C) 2019 The Qt Company Ltd. ** Copyright (C) 2016 by Southwest Research Institute (R) ** Contact: https://www.qt.io/licensing/ ** @@ -48,6 +49,7 @@ private slots: void arithOps(); void floatToFloat16(); void floatFromFloat16(); + void limits(); }; void tst_qfloat16::fuzzyCompare_data() @@ -172,7 +174,9 @@ void tst_qfloat16::qNan() QVERIFY(qIsInf(-inf)); QVERIFY(qIsInf(2.f*inf)); QVERIFY(qIsInf(inf*2.f)); - QCOMPARE(qfloat16(1.f/inf), qfloat16(0.f)); + // QTBUG-75812: QEMU's over-optimized arm64 flakily fails 1/inf == 0 :-( + if (qfloat16(9.785e-4f) == qfloat16(9.794e-4f)) + QCOMPARE(qfloat16(1.f/inf), qfloat16(0.f)); #ifdef Q_CC_INTEL QEXPECT_FAIL("", "ICC optimizes zero * anything to zero", Continue); #endif @@ -345,5 +349,164 @@ void tst_qfloat16::floatFromFloat16() QCOMPARE(out[i], expected[i]); } +static qfloat16 powf16(qfloat16 base, int raise) +{ + const qfloat16 one(1.f); + if (raise < 0) { + raise = -raise; + base = one / base; + } + qfloat16 answer = (raise & 1) ? base : one; + while (raise > 0) { + raise >>= 1; + base *= base; + if (raise & 1) + answer *= base; + } + return answer; +} + +void tst_qfloat16::limits() +{ + // *NOT* using QCOMPARE() on finite qfloat16 values, since that uses fuzzy + // comparison, and we need exact here. + using Bounds = std::numeric_limits<qfloat16>; + QVERIFY(Bounds::is_specialized); + QVERIFY(Bounds::is_signed); + QVERIFY(!Bounds::is_integer); + QVERIFY(!Bounds::is_exact); + QVERIFY(Bounds::is_iec559); + QVERIFY(Bounds::is_bounded); + QVERIFY(!Bounds::is_modulo); + QVERIFY(!Bounds::traps); + QVERIFY(Bounds::has_infinity); + QVERIFY(Bounds::has_quiet_NaN); + QVERIFY(Bounds::has_signaling_NaN); + QCOMPARE(Bounds::has_denorm, std::denorm_present); + QCOMPARE(Bounds::round_style, std::round_to_nearest); + QCOMPARE(Bounds::radix, 2); + // Untested: has_denorm_loss + + // A few common values: + const qfloat16 zero(0), one(1), ten(10); + QVERIFY(qIsFinite(zero)); + QVERIFY(!qIsInf(zero)); + QVERIFY(!qIsNaN(zero)); + QCOMPARE(qFpClassify(zero), FP_ZERO); + QVERIFY(qIsFinite(one)); + QVERIFY(!qIsInf(one)); + QCOMPARE(qFpClassify(one), FP_NORMAL); + QVERIFY(!qIsNaN(one)); + QVERIFY(qIsFinite(ten)); + QVERIFY(!qIsInf(ten)); + QVERIFY(!qIsNaN(ten)); + QCOMPARE(qFpClassify(ten), FP_NORMAL); + + // digits in the mantissa, including the implicit 1 before the binary dot at its left: + QVERIFY(qfloat16(1 << (Bounds::digits - 1)) + one > qfloat16(1 << (Bounds::digits - 1))); + QVERIFY(qfloat16(1 << Bounds::digits) + one == qfloat16(1 << Bounds::digits)); + + // There is a wilful of-by-one in how m(ax|in)_exponent are defined; they're + // the lowest and highest n for which radix^{n-1} are normal and finite. + const qfloat16 two(Bounds::radix); + qfloat16 bit = powf16(two, Bounds::max_exponent - 1); + QVERIFY(qIsFinite(bit)); + QVERIFY(qIsInf(bit * two)); + bit = powf16(two, Bounds::min_exponent - 1); + QVERIFY(bit.isNormal()); + QCOMPARE(qFpClassify(bit), FP_NORMAL); + QVERIFY(!(bit / two).isNormal()); + QCOMPARE(qFpClassify(bit / two), FP_SUBNORMAL); + QVERIFY(bit / two > zero); + + // Base ten (with no matching off-by-one idiocy): + // the lowest negative number n such that 10^n is a valid normalized value + qfloat16 low10(powf16(ten, Bounds::min_exponent10)); + QVERIFY(low10 > zero); + QVERIFY(low10.isNormal()); + low10 /= ten; + QVERIFY(low10 == zero || !low10.isNormal()); + // the largest positive number n such that 10^n is a representable finite value + qfloat16 high10(powf16(ten, Bounds::max_exponent10)); + QVERIFY(high10 > zero); + QVERIFY(qIsFinite(high10)); + QVERIFY(!qIsFinite(high10 * ten)); + QCOMPARE(qFpClassify(high10), FP_NORMAL); + + // How many digits are significant ? (Casts avoid linker errors ...) + QCOMPARE(int(Bounds::digits10), 3); // 9.79e-4 has enough sigificant digits: + qfloat16 below(9.785e-4f), above(9.794e-4f); +#if 0 // Sadly, the QEMU x-compile for arm64 "optimises" comparisons: + const bool overOptimised = false; +#else + const bool overOptimised = (below != above); + if (overOptimised) + QEXPECT_FAIL("", "Over-optimised on QEMU", Continue); +#endif // (but it did, so should, pass everywhere else, confirming digits10 is indeed 3). + QVERIFY(below == above); + QCOMPARE(int(Bounds::max_digits10), 5); // we need 5 to distinguish these two: + QVERIFY(qfloat16(1000.5f) != qfloat16(1001.4f)); + + // Actual limiting values of the type: + const qfloat16 rose(one + Bounds::epsilon()); + QVERIFY(rose > one); + if (overOptimised) + QEXPECT_FAIL("", "Over-optimised on QEMU", Continue); + QVERIFY(one + Bounds::epsilon() / rose == one); + QVERIFY(qIsInf(Bounds::infinity())); + QVERIFY(!qIsNaN(Bounds::infinity())); + QVERIFY(!qIsFinite(Bounds::infinity())); + QCOMPARE(Bounds::infinity(), Bounds::infinity()); + QCOMPARE(qFpClassify(Bounds::infinity()), FP_INFINITE); + + QVERIFY(Bounds::infinity() > -Bounds::infinity()); + QVERIFY(Bounds::infinity() > zero); + QVERIFY(qIsInf(-Bounds::infinity())); + QVERIFY(!qIsNaN(-Bounds::infinity())); + QVERIFY(!qIsFinite(-Bounds::infinity())); + QCOMPARE(-Bounds::infinity(), -Bounds::infinity()); + QCOMPARE(qFpClassify(-Bounds::infinity()), FP_INFINITE); + + QVERIFY(-Bounds::infinity() < zero); + QVERIFY(qIsNaN(Bounds::quiet_NaN())); + QVERIFY(!qIsInf(Bounds::quiet_NaN())); + QVERIFY(!qIsFinite(Bounds::quiet_NaN())); + QVERIFY(!(Bounds::quiet_NaN() == Bounds::quiet_NaN())); + QCOMPARE(Bounds::quiet_NaN(), Bounds::quiet_NaN()); + QCOMPARE(qFpClassify(Bounds::quiet_NaN()), FP_NAN); + + QVERIFY(Bounds::max() > zero); + QVERIFY(qIsFinite(Bounds::max())); + QVERIFY(!qIsInf(Bounds::max())); + QVERIFY(!qIsNaN(Bounds::max())); + QVERIFY(qIsInf(Bounds::max() * rose)); + QCOMPARE(qFpClassify(Bounds::max()), FP_NORMAL); + + QVERIFY(Bounds::lowest() < zero); + QVERIFY(qIsFinite(Bounds::lowest())); + QVERIFY(!qIsInf(Bounds::lowest())); + QVERIFY(!qIsNaN(Bounds::lowest())); + QVERIFY(qIsInf(Bounds::lowest() * rose)); + QCOMPARE(qFpClassify(Bounds::lowest()), FP_NORMAL); + + QVERIFY(Bounds::min() > zero); + QVERIFY(Bounds::min().isNormal()); + QVERIFY(!(Bounds::min() / rose).isNormal()); + QVERIFY(qIsFinite(Bounds::min())); + QVERIFY(!qIsInf(Bounds::min())); + QVERIFY(!qIsNaN(Bounds::min())); + QCOMPARE(qFpClassify(Bounds::min()), FP_NORMAL); + + QVERIFY(Bounds::denorm_min() > zero); + QVERIFY(!Bounds::denorm_min().isNormal()); + QVERIFY(qIsFinite(Bounds::denorm_min())); + QVERIFY(!qIsInf(Bounds::denorm_min())); + QVERIFY(!qIsNaN(Bounds::denorm_min())); + if (overOptimised) + QEXPECT_FAIL("", "Over-optimised on QEMU", Continue); + QCOMPARE(Bounds::denorm_min() / rose, zero); + QCOMPARE(qFpClassify(Bounds::denorm_min()), FP_SUBNORMAL); +} + QTEST_APPLESS_MAIN(tst_qfloat16) #include "tst_qfloat16.moc" diff --git a/tests/auto/corelib/global/qglobal/tst_qglobal.cpp b/tests/auto/corelib/global/qglobal/tst_qglobal.cpp index 56da047147..5e5492de59 100644 --- a/tests/auto/corelib/global/qglobal/tst_qglobal.cpp +++ b/tests/auto/corelib/global/qglobal/tst_qglobal.cpp @@ -456,12 +456,8 @@ typedef int (Empty::*memFun) (); } while (false) \ /**/ -#ifdef Q_COMPILER_RVALUE_REFS #define TEST_AlignOf_RValueRef(type, alignment) \ TEST_AlignOf_impl(type, alignment) -#else -#define TEST_AlignOf_RValueRef(type, alignment) do {} while (false) -#endif #define TEST_AlignOf_impl(type, alignment) \ do { \ diff --git a/tests/auto/corelib/global/qrandomgenerator/tst_qrandomgenerator.cpp b/tests/auto/corelib/global/qrandomgenerator/tst_qrandomgenerator.cpp index 7c04611823..64557f1460 100644 --- a/tests/auto/corelib/global/qrandomgenerator/tst_qrandomgenerator.cpp +++ b/tests/auto/corelib/global/qrandomgenerator/tst_qrandomgenerator.cpp @@ -511,7 +511,7 @@ void tst_QRandomGenerator::generateNonContiguous() QFETCH(uint, control); RandomGenerator rng(control); - QLinkedList<quint64> list = { 0, 0, 0, 0, 0, 0, 0, 0 }; + std::list<quint64> list(8); auto longerArrayCheck = [&] { QRandomGenerator().generate(list.begin(), list.end()); return find_if(list.begin(), list.end(), [&](quint64 cur) { diff --git a/tests/auto/corelib/io/largefile/tst_largefile.cpp b/tests/auto/corelib/io/largefile/tst_largefile.cpp index dca7672b8e..f459f62c91 100644 --- a/tests/auto/corelib/io/largefile/tst_largefile.cpp +++ b/tests/auto/corelib/io/largefile/tst_largefile.cpp @@ -36,6 +36,7 @@ #include <QDebug> +#include <algorithm> #include <cstdlib> #include <cstdio> @@ -489,13 +490,13 @@ void tst_LargeFile::mapFile() // Keep full block mapped to facilitate OS and/or internal reuse by Qt. uchar *baseAddress = largeFile.map(position, blockSize); QVERIFY( baseAddress ); - QVERIFY( qEqual(block.begin(), block.end(), reinterpret_cast<char*>(baseAddress)) ); + QVERIFY( std::equal(block.begin(), block.end(), reinterpret_cast<char*>(baseAddress)) ); for (int offset = 1; offset < blockSize; ++offset) { uchar *address = largeFile.map(position + offset, blockSize - offset); QVERIFY( address ); - if ( !qEqual(block.begin() + offset, block.end(), reinterpret_cast<char*>(address)) ) { + if ( !std::equal(block.begin() + offset, block.end(), reinterpret_cast<char*>(address)) ) { qDebug() << "Expected:" << block.toHex(); qDebug() << "Actual :" << QByteArray(reinterpret_cast<char*>(address), blockSize).toHex(); QVERIFY(false); diff --git a/tests/auto/corelib/io/qdebug/tst_qdebug.cpp b/tests/auto/corelib/io/qdebug/tst_qdebug.cpp index 7b8b1df166..a818c6c09d 100644 --- a/tests/auto/corelib/io/qdebug/tst_qdebug.cpp +++ b/tests/auto/corelib/io/qdebug/tst_qdebug.cpp @@ -309,7 +309,7 @@ void tst_QDebug::stateSaver() const QDebug d = qDebug(); { QDebugStateSaver saver(d); - d.nospace() << hex << right << qSetFieldWidth(3) << qSetPadChar('0') << 42; + d.nospace() << Qt::hex << Qt::right << qSetFieldWidth(3) << qSetPadChar('0') << 42; } d << 42; } @@ -327,7 +327,7 @@ void tst_QDebug::stateSaver() const { QDebug d = qDebug(); - d.noquote().nospace() << QStringLiteral("Hello") << hex << 42; + d.noquote().nospace() << QStringLiteral("Hello") << Qt::hex << 42; { QDebugStateSaver saver(d); d.resetFormat(); @@ -660,7 +660,7 @@ void tst_QDebug::textStreamModifiers() const QString file, function; int line = 0; MessageHandlerSetter mhs(myMessageHandler); - { qDebug() << hex << short(0xf) << int(0xf) << unsigned(0xf) << long(0xf) << qint64(0xf) << quint64(0xf); } + { qDebug() << Qt::hex << short(0xf) << int(0xf) << unsigned(0xf) << long(0xf) << qint64(0xf) << quint64(0xf); } #ifndef QT_NO_MESSAGELOGCONTEXT file = __FILE__; line = __LINE__ - 2; function = Q_FUNC_INFO; #endif @@ -678,7 +678,7 @@ void tst_QDebug::resetFormat() const MessageHandlerSetter mhs(myMessageHandler); { QDebug d = qDebug(); - d.nospace().noquote() << hex << int(0xf); + d.nospace().noquote() << Qt::hex << int(0xf); d.resetFormat() << int(0xf) << QStringLiteral("foo"); } #ifndef QT_NO_MESSAGELOGCONTEXT diff --git a/tests/auto/corelib/io/qfile/test.pro b/tests/auto/corelib/io/qfile/test.pro index 95389ab3e2..7a2767bf3c 100644 --- a/tests/auto/corelib/io/qfile/test.pro +++ b/tests/auto/corelib/io/qfile/test.pro @@ -23,4 +23,4 @@ TESTDATA += \ Makefile forCopying.txt forRenaming.txt \ resources/file1.ext1 -win32:!winrt: LIBS += -lole32 -luuid +win32:!winrt: QMAKE_USE += ole32 uuid diff --git a/tests/auto/corelib/io/qfile/tst_qfile.cpp b/tests/auto/corelib/io/qfile/tst_qfile.cpp index 678a80c3f7..4f010f37c2 100644 --- a/tests/auto/corelib/io/qfile/tst_qfile.cpp +++ b/tests/auto/corelib/io/qfile/tst_qfile.cpp @@ -2099,7 +2099,7 @@ void tst_QFile::i18nFileName() QVERIFY2(file.open(QFile::WriteOnly | QFile::Text), msgOpenFailed(file).constData()); QTextStream ts(&file); ts.setCodec("UTF-8"); - ts << fileName << endl; + ts << fileName << Qt::endl; } { QFile file(fileName); @@ -2149,7 +2149,7 @@ void tst_QFile::longFileName() QFile file(fileName); QVERIFY2(file.open(QFile::WriteOnly | QFile::Text), msgOpenFailed(file).constData()); QTextStream ts(&file); - ts << fileName << endl; + ts << fileName << Qt::endl; } { QFile file(fileName); diff --git a/tests/auto/corelib/io/qfileinfo/qfileinfo.pro b/tests/auto/corelib/io/qfileinfo/qfileinfo.pro index 496729f9f1..d181d16a3e 100644 --- a/tests/auto/corelib/io/qfileinfo/qfileinfo.pro +++ b/tests/auto/corelib/io/qfileinfo/qfileinfo.pro @@ -5,4 +5,4 @@ SOURCES = tst_qfileinfo.cpp RESOURCES += qfileinfo.qrc \ testdata.qrc -win32:!winrt: LIBS += -ladvapi32 -lnetapi32 +win32:!winrt: QMAKE_USE += advapi32 netapi32 diff --git a/tests/auto/corelib/io/qfileinfo/tst_qfileinfo.cpp b/tests/auto/corelib/io/qfileinfo/tst_qfileinfo.cpp index 714c96b5e5..0944ec252e 100644 --- a/tests/auto/corelib/io/qfileinfo/tst_qfileinfo.cpp +++ b/tests/auto/corelib/io/qfileinfo/tst_qfileinfo.cpp @@ -655,6 +655,8 @@ void tst_QFileInfo::canonicalFilePath() QVERIFY(tempFile.open(QFile::WriteOnly)); QFileInfo fi(tempFile.fileName()); QCOMPARE(fi.canonicalFilePath(), QDir::currentPath() + "/" + fileName); + fi = QFileInfo(tempFile.fileName() + QString::fromLatin1("/")); + QCOMPARE(fi.canonicalFilePath(), QString::fromLatin1("")); tempFile.remove(); // This used to crash on Mac, verify that it doesn't anymore. @@ -1182,7 +1184,7 @@ void tst_QFileInfo::fileTimes() QTest::qSleep(sleepTime); beforeWrite = QDateTime::currentDateTime().addMSecs(-fsClockSkew); QTextStream ts(&file); - ts << fileName << endl; + ts << fileName << Qt::endl; } { QFileInfo fileInfo(fileName); @@ -1559,6 +1561,16 @@ void tst_QFileInfo::ntfsJunctionPointsAndSymlinks_data() << NtfsTestResource(NtfsTestResource::SymLink, relToRelSymlink, relToRelTarget) << relToRelSymlink << true << QDir::fromNativeSeparators(absTarget) << target.canonicalFilePath(); } + { + // Symlink to UNC share + pwd.mkdir("unc"); + QString errorMessage; + QString uncTarget = QStringLiteral("//") + QtNetworkSettings::winServerName() + "/testshare"; + QString uncSymlink = QDir::toNativeSeparators(pwd.absolutePath().append("\\unc\\link_to_unc")); + QTest::newRow("UNC symlink") + << NtfsTestResource(NtfsTestResource::SymLink, uncSymlink, uncTarget) + << QDir::fromNativeSeparators(uncSymlink) << true << QDir::fromNativeSeparators(uncTarget) << uncTarget; + } //Junctions QString target = "target"; @@ -1630,7 +1642,7 @@ void tst_QFileInfo::ntfsJunctionPointsAndSymlinks() // Ensure that junctions, mountpoints are removed. If this fails, do not remove // temporary directory to prevent it from trashing the system. if (fi.isDir()) { - if (!QDir().rmdir(fi.fileName())) { + if (!QDir().rmdir(fi.filePath())) { qWarning("Unable to remove NTFS junction '%s'', keeping '%s'.", qPrintable(fi.fileName()), qPrintable(QDir::toNativeSeparators(m_dir.path()))); m_dir.setAutoRemove(false); diff --git a/tests/auto/corelib/io/qfilesystemwatcher/tst_qfilesystemwatcher.cpp b/tests/auto/corelib/io/qfilesystemwatcher/tst_qfilesystemwatcher.cpp index 67ffa91e57..cdd1f6361e 100644 --- a/tests/auto/corelib/io/qfilesystemwatcher/tst_qfilesystemwatcher.cpp +++ b/tests/auto/corelib/io/qfilesystemwatcher/tst_qfilesystemwatcher.cpp @@ -46,11 +46,13 @@ public: tst_QFileSystemWatcher(); private slots: +#ifdef QT_BUILD_INTERNAL void basicTest_data(); void basicTest(); void watchDirectory_data(); void watchDirectory(); +#endif void addPath(); void removePath(); @@ -58,8 +60,10 @@ private slots: void removePaths(); void removePathsFilesInSameDirectory(); +#ifdef QT_BUILD_INTERNAL void watchFileAndItsDirectory_data() { basicTest_data(); } void watchFileAndItsDirectory(); +#endif void nonExistingFile(); @@ -67,8 +71,10 @@ private slots: void destroyAfterQCoreApplication(); +#ifdef QT_BUILD_INTERNAL void QTBUG2331(); void QTBUG2331_data() { basicTest_data(); } +#endif void signalsEmittedAfterFileMoved(); @@ -90,6 +96,7 @@ tst_QFileSystemWatcher::tst_QFileSystemWatcher() #endif } +#ifdef QT_BUILD_INTERNAL void tst_QFileSystemWatcher::basicTest_data() { QTest::addColumn<QString>("backend"); @@ -360,6 +367,7 @@ void tst_QFileSystemWatcher::watchDirectory() for (const auto &testDirName : testDirs) QVERIFY(temporaryDir.rmdir(testDirName)); } +#endif // QT_BUILD_INTERNAL void tst_QFileSystemWatcher::addPath() { @@ -502,6 +510,7 @@ void tst_QFileSystemWatcher::removePathsFilesInSameDirectory() QCOMPARE(watcher.files().size(), 0); } +#ifdef QT_BUILD_INTERNAL static QByteArray msgFileOperationFailed(const char *what, const QFile &f) { return what + QByteArrayLiteral(" failed on \"") @@ -601,6 +610,7 @@ void tst_QFileSystemWatcher::watchFileAndItsDirectory() QVERIFY(temporaryDir.rmdir(testDirName)); } +#endif // QT_BUILD_INTERNAL void tst_QFileSystemWatcher::nonExistingFile() { @@ -673,6 +683,7 @@ void tst_QFileSystemWatcher::destroyAfterQCoreApplication() QTest::qWait(30); } +#ifdef QT_BUILD_INTERNAL // regression test for QTBUG2331. // essentially, on windows, directories were not unwatched after being deleted // from the disk, causing all sorts of interesting problems. @@ -696,6 +707,7 @@ void tst_QFileSystemWatcher::QTBUG2331() QTRY_COMPARE(changedSpy.count(), 1); QCOMPARE(watcher.directories(), QStringList()); } +#endif // QT_BUILD_INTERNAL class SignalReceiver : public QObject { diff --git a/tests/auto/corelib/io/qlockfile/tst_qlockfile.pro b/tests/auto/corelib/io/qlockfile/tst_qlockfile.pro index da2660fd02..e33e22b36f 100644 --- a/tests/auto/corelib/io/qlockfile/tst_qlockfile.pro +++ b/tests/auto/corelib/io/qlockfile/tst_qlockfile.pro @@ -3,4 +3,4 @@ TARGET = tst_qlockfile SOURCES += tst_qlockfile.cpp QT = core-private testlib concurrent -win32:!winrt:LIBS += -ladvapi32 +win32:!winrt: QMAKE_USE += advapi32 diff --git a/tests/auto/corelib/io/qloggingcategory/tst_qloggingcategory.cpp b/tests/auto/corelib/io/qloggingcategory/tst_qloggingcategory.cpp index 08635d34c5..79ac6b0fc4 100644 --- a/tests/auto/corelib/io/qloggingcategory/tst_qloggingcategory.cpp +++ b/tests/auto/corelib/io/qloggingcategory/tst_qloggingcategory.cpp @@ -104,7 +104,7 @@ public: for (int a = 0; a < _configitemEntryOrder.count(); a++) { out << _configitemEntryOrder[a] << " = " - << _values.value(_configitemEntryOrder[a]) << endl; + << _values.value(_configitemEntryOrder[a]) << Qt::endl; } out.flush(); return ret.toLatin1(); diff --git a/tests/auto/corelib/io/qprocess/testProcessEOF/testProcessEOF.pro b/tests/auto/corelib/io/qprocess/testProcessEOF/testProcessEOF.pro index ab1394a5c9..6a23e52d95 100644 --- a/tests/auto/corelib/io/qprocess/testProcessEOF/testProcessEOF.pro +++ b/tests/auto/corelib/io/qprocess/testProcessEOF/testProcessEOF.pro @@ -1,6 +1,4 @@ SOURCES = main.cpp CONFIG -= qt CONFIG += cmdline - -win32:!mingw:!equals(TEMPLATE_PREFIX, "vc"):QMAKE_CXXFLAGS += /GS- DESTDIR = ./ diff --git a/tests/auto/corelib/io/qprocess/testProcessEchoGui/testProcessEchoGui.pro b/tests/auto/corelib/io/qprocess/testProcessEchoGui/testProcessEchoGui.pro index 935f43630c..e41ed0a425 100644 --- a/tests/auto/corelib/io/qprocess/testProcessEchoGui/testProcessEchoGui.pro +++ b/tests/auto/corelib/io/qprocess/testProcessEchoGui/testProcessEchoGui.pro @@ -1,6 +1,6 @@ win32 { SOURCES = main_win.cpp - LIBS += -luser32 + QMAKE_USE += user32 } CONFIG -= qt app_bundle diff --git a/tests/auto/corelib/io/qprocess/testSoftExit/testSoftExit.pro b/tests/auto/corelib/io/qprocess/testSoftExit/testSoftExit.pro index 2cfcb4794e..964c47f6ae 100644 --- a/tests/auto/corelib/io/qprocess/testSoftExit/testSoftExit.pro +++ b/tests/auto/corelib/io/qprocess/testSoftExit/testSoftExit.pro @@ -1,6 +1,6 @@ win32 { SOURCES = main_win.cpp - LIBS += -luser32 + QMAKE_USE += user32 } unix { SOURCES = main_unix.cpp diff --git a/tests/auto/corelib/io/qsettings/qsettings.pro b/tests/auto/corelib/io/qsettings/qsettings.pro index 79552b62df..98ea337e7f 100644 --- a/tests/auto/corelib/io/qsettings/qsettings.pro +++ b/tests/auto/corelib/io/qsettings/qsettings.pro @@ -5,7 +5,7 @@ SOURCES = tst_qsettings.cpp RESOURCES += qsettings.qrc INCLUDEPATH += $$PWD/../../kernel/qmetatype -msvc: LIBS += advapi32.lib +msvc: QMAKE_USE += advapi32 darwin: LIBS += -framework CoreFoundation DEFINES += QT_DISABLE_DEPRECATED_BEFORE=0 diff --git a/tests/auto/corelib/io/qstandardpaths/tst_qstandardpaths.cpp b/tests/auto/corelib/io/qstandardpaths/tst_qstandardpaths.cpp index 1379c788d1..155f5b953d 100644 --- a/tests/auto/corelib/io/qstandardpaths/tst_qstandardpaths.cpp +++ b/tests/auto/corelib/io/qstandardpaths/tst_qstandardpaths.cpp @@ -33,7 +33,7 @@ #include <qfileinfo.h> #include <qsysinfo.h> #include <qregexp.h> -#if defined(Q_OS_WIN) && !defined(Q_OS_WINRT) && !defined(Q_OS_WINCE) +#if defined(Q_OS_WIN) && !defined(Q_OS_WINRT) # include <qt_windows.h> #endif @@ -131,7 +131,7 @@ static const char * const enumNames[MaxStandardLocation + 1 - int(QStandardPaths void tst_qstandardpaths::initTestCase() { -#if defined(Q_OS_WIN) && !defined(Q_OS_WINRT) && !defined(Q_OS_WINCE) +#if defined(Q_OS_WIN) && !defined(Q_OS_WINRT) // Disable WOW64 redirection, see testFindExecutable() if (QSysInfo::buildCpuArchitecture() != QSysInfo::currentCpuArchitecture()) { void *oldMode; @@ -140,7 +140,7 @@ void tst_qstandardpaths::initTestCase() qErrnoWarning("Wow64DisableWow64FsRedirection() failed"); QVERIFY(disabledDisableWow64FsRedirection); } -#endif // Q_OS_WIN && !Q_OS_WINRT && !Q_OS_WINCE +#endif // Q_OS_WIN && !Q_OS_WINRT QVERIFY2(m_localConfigTempDir.isValid(), qPrintable(m_localConfigTempDir.errorString())); QVERIFY2(m_globalConfigTempDir.isValid(), qPrintable(m_globalConfigTempDir.errorString())); QVERIFY2(m_localAppTempDir.isValid(), qPrintable(m_localAppTempDir.errorString())); diff --git a/tests/auto/corelib/io/qstorageinfo/tst_qstorageinfo.cpp b/tests/auto/corelib/io/qstorageinfo/tst_qstorageinfo.cpp index 1317489e2f..fe63cecccd 100644 --- a/tests/auto/corelib/io/qstorageinfo/tst_qstorageinfo.cpp +++ b/tests/auto/corelib/io/qstorageinfo/tst_qstorageinfo.cpp @@ -195,6 +195,10 @@ void tst_QStorageInfo::tempFile() file.close(); QStorageInfo storage2(file.fileName()); + if (free == storage2.bytesFree() && storage2.fileSystemType() == "apfs") { + QEXPECT_FAIL("", "This test is likely to fail on APFS", Continue); + } + QVERIFY(free != storage2.bytesFree()); } @@ -221,6 +225,9 @@ void tst_QStorageInfo::caching() QCOMPARE(free, storage2.bytesFree()); storage2.refresh(); QCOMPARE(storage1, storage2); + if (free == storage2.bytesFree() && storage2.fileSystemType() == "apfs") { + QEXPECT_FAIL("", "This test is likely to fail on APFS", Continue); + } QVERIFY(free != storage2.bytesFree()); } #endif diff --git a/tests/auto/corelib/itemmodels/qabstractitemmodel/tst_qabstractitemmodel.cpp b/tests/auto/corelib/itemmodels/qabstractitemmodel/tst_qabstractitemmodel.cpp index b960ca9220..3a4493474b 100644 --- a/tests/auto/corelib/itemmodels/qabstractitemmodel/tst_qabstractitemmodel.cpp +++ b/tests/auto/corelib/itemmodels/qabstractitemmodel/tst_qabstractitemmodel.cpp @@ -309,7 +309,8 @@ bool QtTestModel::moveColumns(const QModelIndex &sourceParent, int src, int cnt, void QtTestModel::reset() { - QAbstractItemModel::reset(); + QAbstractItemModel::beginResetModel(); + QAbstractItemModel::endResetModel(); } bool QtTestModel::canDropMimeData(const QMimeData *data, Qt::DropAction action, @@ -1785,13 +1786,12 @@ class ModelWithCustomRole : public QStringListModel { Q_OBJECT public: - ModelWithCustomRole(QObject *parent = 0) - : QStringListModel(parent) - { - QHash<int, QByteArray> roleNames_ = roleNames(); - roleNames_.insert(Qt::UserRole + 1, "custom"); - setRoleNames(roleNames_); - } + using QStringListModel::QStringListModel; + + QHash<int, QByteArray> roleNames() const override + { + return {{Qt::UserRole + 1, QByteArrayLiteral("custom")}}; + } }; ListenerObject::ListenerObject(QAbstractProxyModel *parent) diff --git a/tests/auto/corelib/itemmodels/qabstractproxymodel/tst_qabstractproxymodel.cpp b/tests/auto/corelib/itemmodels/qabstractproxymodel/tst_qabstractproxymodel.cpp index 886941bff6..adb93b7a75 100644 --- a/tests/auto/corelib/itemmodels/qabstractproxymodel/tst_qabstractproxymodel.cpp +++ b/tests/auto/corelib/itemmodels/qabstractproxymodel/tst_qabstractproxymodel.cpp @@ -313,11 +313,12 @@ public: CustomRole2 }; - StandardItemModelWithCustomRoleNames() { - QHash<int, QByteArray> _roleNames = roleNames(); - _roleNames.insert(CustomRole1, "custom1"); - _roleNames.insert(CustomRole2, "custom2"); - setRoleNames(_roleNames); + QHash<int, QByteArray> roleNames() const override + { + auto result = QStandardItemModel::roleNames(); + result.insert(CustomRole1, QByteArrayLiteral("custom1")); + result.insert(CustomRole2, QByteArrayLiteral("custom2")); + return result; } }; @@ -329,11 +330,10 @@ public: AnotherCustomRole2 }; - AnotherStandardItemModelWithCustomRoleNames() { - QHash<int, QByteArray> _roleNames = roleNames(); - _roleNames.insert(AnotherCustomRole1, "another_custom1"); - _roleNames.insert(AnotherCustomRole2, "another_custom2"); - setRoleNames(_roleNames); + QHash<int, QByteArray> roleNames() const override + { + return {{AnotherCustomRole1, QByteArrayLiteral("another_custom1")}, + {AnotherCustomRole2, QByteArrayLiteral("another_custom2")}}; } }; diff --git a/tests/auto/corelib/itemmodels/qitemselectionmodel/tst_qitemselectionmodel.cpp b/tests/auto/corelib/itemmodels/qitemselectionmodel/tst_qitemselectionmodel.cpp index 6fbaa28d69..1cc671a917 100644 --- a/tests/auto/corelib/itemmodels/qitemselectionmodel/tst_qitemselectionmodel.cpp +++ b/tests/auto/corelib/itemmodels/qitemselectionmodel/tst_qitemselectionmodel.cpp @@ -2211,8 +2211,8 @@ void tst_QItemSelectionModel::childrenDeselectionSignal() } QModelIndex root = model.index(0,0); - QModelIndex par = root.child(0,0); - QModelIndex sel = par.child(0,0); + QModelIndex par = model.index(0, 0, root); + QModelIndex sel = model.index(0, 0, par); QItemSelectionModel selectionModel(&model); selectionModel.select(sel, QItemSelectionModel::SelectCurrent); @@ -2240,9 +2240,9 @@ void tst_QItemSelectionModel::childrenDeselectionSignal() } } - sel = model.index(0, 0).child(0, 0); + sel = model.index(0, 0, model.index(0, 0)); selectionModel.select(sel, QItemSelectionModel::Select); - QModelIndex sel2 = model.index(1, 0).child(0, 0); + QModelIndex sel2 = model.index(0, 0, model.index(1, 0)); selectionModel.select(sel2, QItemSelectionModel::Select); QVERIFY(selectionModel.selection().contains(sel)); diff --git a/tests/auto/corelib/itemmodels/qsortfilterproxymodel_common/tst_qsortfilterproxymodel.cpp b/tests/auto/corelib/itemmodels/qsortfilterproxymodel_common/tst_qsortfilterproxymodel.cpp index ccce5a44e5..0f7588a71a 100644 --- a/tests/auto/corelib/itemmodels/qsortfilterproxymodel_common/tst_qsortfilterproxymodel.cpp +++ b/tests/auto/corelib/itemmodels/qsortfilterproxymodel_common/tst_qsortfilterproxymodel.cpp @@ -3977,7 +3977,7 @@ void tst_QSortFilterProxyModel::hierarchyFilterInvalidation() QTreeView view; view.setModel(&proxy); - view.setCurrentIndex(proxy.index(2, 0).child(0, 0)); + view.setCurrentIndex(proxy.index(0, 0, proxy.index(2, 0))); view.show(); QVERIFY(QTest::qWaitForWindowExposed(&view)); diff --git a/tests/auto/corelib/kernel/qdeadlinetimer/tst_qdeadlinetimer.cpp b/tests/auto/corelib/kernel/qdeadlinetimer/tst_qdeadlinetimer.cpp index 6ab24d2480..4ca68550b9 100644 --- a/tests/auto/corelib/kernel/qdeadlinetimer/tst_qdeadlinetimer.cpp +++ b/tests/auto/corelib/kernel/qdeadlinetimer/tst_qdeadlinetimer.cpp @@ -29,6 +29,7 @@ #include <QtCore/QString> #include <QtCore/QTime> #include <QtCore/QDeadlineTimer> +#include <QtCore/QElapsedTimer> #include <QtTest/QtTest> #if QT_HAS_INCLUDE(<chrono>) @@ -50,6 +51,7 @@ private Q_SLOTS: void current(); void deadlines(); void setDeadline(); + void overflow(); void expire(); void stdchrono(); }; @@ -417,6 +419,83 @@ void tst_QDeadlineTimer::setDeadline() QCOMPARE(deadline.deadlineNSecs(), nsec); } +void tst_QDeadlineTimer::overflow() +{ + QFETCH_GLOBAL(Qt::TimerType, timerType); + // Check the constructor for overflows (should also cover saturating the result of the deadline() method if overflowing) + QDeadlineTimer now = QDeadlineTimer::current(timerType), deadline(std::numeric_limits<qint64>::max() - 1, timerType); + QVERIFY(deadline.isForever() || deadline.deadline() >= now.deadline()); + + // Check the setDeadline with milliseconds (should also cover implicitly setting the nanoseconds as qint64 max) + deadline.setDeadline(std::numeric_limits<qint64>::max() - 1, timerType); + QVERIFY(deadline.isForever() || deadline.deadline() >= now.deadline()); + + // Check the setRemainingTime with milliseconds (should also cover implicitly setting the nanoseconds as qint64 max) + deadline.setRemainingTime(std::numeric_limits<qint64>::max() - 1, timerType); + QVERIFY(deadline.isForever() || deadline.deadline() >= now.deadline()); + + // Check that the deadline gets saturated when the arguments of setPreciseDeadline are large + deadline.setPreciseDeadline(std::numeric_limits<qint64>::max() - 1, std::numeric_limits<qint64>::max() - 1, timerType); + QCOMPARE(deadline.deadline(), std::numeric_limits<qint64>::max()); + QVERIFY(deadline.isForever()); + + // Check that remainingTime gets saturated if we overflow + deadline.setPreciseRemainingTime(std::numeric_limits<qint64>::max() - 1, std::numeric_limits<qint64>::max() - 1, timerType); + QCOMPARE(deadline.remainingTime(), qint64(-1)); + QVERIFY(deadline.isForever()); + + // Check that we saturate the getter for nanoseconds + deadline.setPreciseDeadline(std::numeric_limits<qint64>::max() - 1, 0, timerType); + QCOMPARE(deadline.deadlineNSecs(), std::numeric_limits<qint64>::max()); + + // Check that adding nanoseconds and overflowing is consistent and saturates the timer + deadline = QDeadlineTimer::addNSecs(deadline, std::numeric_limits<qint64>::max() - 1); + QVERIFY(deadline.isForever()); + + // Make sure forever is forever, regardless of us subtracting time from it + deadline = QDeadlineTimer(QDeadlineTimer::Forever, timerType); + deadline = QDeadlineTimer::addNSecs(deadline, -10000); + QVERIFY(deadline.isForever()); + + // Make sure we get the correct result when moving the deadline back and forth in time + QDeadlineTimer current = QDeadlineTimer::current(timerType); + QDeadlineTimer takenNSecs = QDeadlineTimer::addNSecs(current, -1000); + QVERIFY(takenNSecs.deadlineNSecs() - current.deadlineNSecs() == -1000); + QDeadlineTimer addedNSecs = QDeadlineTimer::addNSecs(current, 1000); + QVERIFY(addedNSecs.deadlineNSecs() - current.deadlineNSecs() == 1000); + + // Make sure the calculation goes as expected when we need to subtract nanoseconds + // We make use of an additional timer to be certain that + // even when the environment is under load we can track the + // time needed to do the calls + static constexpr qint64 nsExpected = 1000 * 1000 * 1000 - 1000; // 1s - 1000ns, what we pass to setPreciseRemainingTime() later + + QElapsedTimer callTimer; + callTimer.start(); + + deadline = QDeadlineTimer::current(timerType); + qint64 nsDeadline = deadline.deadlineNSecs(); + // We adjust in relation to current() here, so we expect the difference to be a tad over the exact number. + // However we are tracking the elapsed time, so it shouldn't be a problem. + deadline.setPreciseRemainingTime(1, -1000, timerType); + qint64 difference = (deadline.deadlineNSecs() - nsDeadline) - nsExpected; + QVERIFY(difference >= 0); // Should always be true, but just in case + QVERIFY(difference <= callTimer.nsecsElapsed()); // Ideally difference should be 0 exactly + + // Make sure setRemainingTime underflows gracefully + deadline.setPreciseRemainingTime(std::numeric_limits<qint64>::min() / 10, 0, timerType); + QVERIFY(!deadline.isForever()); // On Win/macOS the above underflows, make sure we don't saturate to Forever + QVERIFY(deadline.remainingTime() == 0); + // If the timer is saturated we don't want to get a valid number of milliseconds + QVERIFY(deadline.deadline() == std::numeric_limits<qint64>::min()); + + // Check that the conversion to milliseconds and nanoseconds underflows gracefully + deadline.setPreciseDeadline(std::numeric_limits<qint64>::min() / 10, 0, timerType); + QVERIFY(!deadline.isForever()); // On Win/macOS the above underflows, make sure we don't saturate to Forever + QVERIFY(deadline.deadline() == std::numeric_limits<qint64>::min()); + QVERIFY(deadline.deadlineNSecs() == std::numeric_limits<qint64>::min()); +} + void tst_QDeadlineTimer::expire() { QFETCH_GLOBAL(Qt::TimerType, timerType); diff --git a/tests/auto/corelib/kernel/qeventloop/qeventloop.pro b/tests/auto/corelib/kernel/qeventloop/qeventloop.pro index 295a42aa9c..159761c0c6 100644 --- a/tests/auto/corelib/kernel/qeventloop/qeventloop.pro +++ b/tests/auto/corelib/kernel/qeventloop/qeventloop.pro @@ -3,6 +3,6 @@ TARGET = tst_qeventloop QT = core network testlib core-private SOURCES = $$PWD/tst_qeventloop.cpp -win32:!winrt: LIBS += -luser32 +win32:!winrt: QMAKE_USE += user32 qtConfig(glib): DEFINES += HAVE_GLIB diff --git a/tests/auto/corelib/kernel/qmetaobject/qmetaobject.pro b/tests/auto/corelib/kernel/qmetaobject/qmetaobject.pro index e7e5a03a86..980c247ab5 100644 --- a/tests/auto/corelib/kernel/qmetaobject/qmetaobject.pro +++ b/tests/auto/corelib/kernel/qmetaobject/qmetaobject.pro @@ -1,4 +1,5 @@ CONFIG += testcase +qtConfig(c++14): CONFIG += c++14 TARGET = tst_qmetaobject QT = core-private testlib SOURCES = tst_qmetaobject.cpp diff --git a/tests/auto/corelib/kernel/qmetaobject/tst_qmetaobject.cpp b/tests/auto/corelib/kernel/qmetaobject/tst_qmetaobject.cpp index 350ed24c28..89a06b358e 100644 --- a/tests/auto/corelib/kernel/qmetaobject/tst_qmetaobject.cpp +++ b/tests/auto/corelib/kernel/qmetaobject/tst_qmetaobject.cpp @@ -816,6 +816,15 @@ void tst_QMetaObject::invokePointer() QCOMPARE(obj.slotResult, QString("sl1:bubu")); } QCOMPARE(countedStructObjectsCount, 0); +#ifdef __cpp_init_captures + { + CountedStruct str; + std::unique_ptr<int> ptr( new int ); + QVERIFY(QMetaObject::invokeMethod(&obj, [str, &t1, &obj, p = std::move(ptr)]() { obj.sl1(t1); })); + QCOMPARE(obj.slotResult, QString("sl1:1")); + } + QCOMPARE(countedStructObjectsCount, 0); +#endif } void tst_QMetaObject::invokeQueuedMetaMember() @@ -1121,6 +1130,15 @@ void tst_QMetaObject::invokeBlockingQueuedPointer() QCOMPARE(exp, QString("yessir")); QCOMPARE(obj.slotResult, QString("sl1:bubu")); } +#ifdef __cpp_init_captures + { + std::unique_ptr<int> ptr(new int); + QVERIFY(QMetaObject::invokeMethod(&obj, + [&obj, p = std::move(ptr)]() { return obj.sl1("hehe"); }, + Qt::BlockingQueuedConnection)); + QCOMPARE(obj.slotResult, QString("sl1:hehe")); + } +#endif QVERIFY(QMetaObject::invokeMethod(&obj, [&](){obj.moveToThread(QThread::currentThread());}, Qt::BlockingQueuedConnection)); t.quit(); QVERIFY(t.wait()); diff --git a/tests/auto/corelib/kernel/qsignalblocker/tst_qsignalblocker.cpp b/tests/auto/corelib/kernel/qsignalblocker/tst_qsignalblocker.cpp index fd18f00cd0..39b03ade61 100644 --- a/tests/auto/corelib/kernel/qsignalblocker/tst_qsignalblocker.cpp +++ b/tests/auto/corelib/kernel/qsignalblocker/tst_qsignalblocker.cpp @@ -66,7 +66,6 @@ void tst_QSignalBlocker::signalBlocking() void tst_QSignalBlocker::moveAssignment() { -#ifdef Q_COMPILER_RVALUE_REFS QObject o1, o2; // move-assignment: both block other objects @@ -157,10 +156,6 @@ void tst_QSignalBlocker::moveAssignment() QVERIFY(!o1.signalsBlocked()); QVERIFY(!o2.signalsBlocked()); - -#else - QSKIP("This compiler is not in C++11 mode or doesn't support move semantics"); -#endif // Q_COMPILER_RVALUE_REFS } QTEST_MAIN(tst_QSignalBlocker) diff --git a/tests/auto/corelib/kernel/qvariant/tst_qvariant.cpp b/tests/auto/corelib/kernel/qvariant/tst_qvariant.cpp index 6ae8fd0010..c75e4ef035 100644 --- a/tests/auto/corelib/kernel/qvariant/tst_qvariant.cpp +++ b/tests/auto/corelib/kernel/qvariant/tst_qvariant.cpp @@ -379,8 +379,10 @@ void tst_QVariant::isNull() QString str1; QVariant var1( str1 ); QVERIFY( var1.isNull() ); - +QT_WARNING_PUSH +QT_WARNING_DISABLE_DEPRECATED QVariant var2( QString::null ); +QT_WARNING_POP QVERIFY( var2.isNull() ); QVariant var3( QString( "blah" ) ); @@ -400,9 +402,15 @@ void tst_QVariant::isNull() QVERIFY( var6.isNull() ); QVariant varLL( (qlonglong)0 ); QVERIFY( !varLL.isNull() ); +QT_WARNING_PUSH +QT_WARNING_DISABLE_DEPRECATED QVariant var7(QString::null); +QT_WARNING_POP QVERIFY(var7.isNull()); +QT_WARNING_PUSH +QT_WARNING_DISABLE_DEPRECATED var7 = QVariant::fromValue<QString>(QString::null); +QT_WARNING_POP QVERIFY(var7.isNull()); QVariant var8(QMetaType::Nullptr, nullptr); @@ -1722,281 +1730,281 @@ void tst_QVariant::compareNumbers_data() const QTest::newRow("bool3") << QVariant(false) << QVariant(true) << -1; QTest::newRow("bool4") << QVariant(true) << QVariant(false) << +1; - QTest::newRow("char1") << qVariantFromValue(char(0)) << qVariantFromValue(char(0)) << 0; - QTest::newRow("char2") << qVariantFromValue(CHAR_MAX) << qVariantFromValue(CHAR_MAX) << 0; - QTest::newRow("char3") << qVariantFromValue(CHAR_MIN) << qVariantFromValue(CHAR_MIN) << 0; - QTest::newRow("char4") << qVariantFromValue(CHAR_MIN) << qVariantFromValue(CHAR_MAX) << -1; - QTest::newRow("char5") << qVariantFromValue(CHAR_MAX) << qVariantFromValue(CHAR_MIN) << +1; - - QTest::newRow("schar1") << qVariantFromValue(schar(0)) << qVariantFromValue(schar(0)) << 0; - QTest::newRow("schar2") << qVariantFromValue(SCHAR_MAX) << qVariantFromValue(SCHAR_MAX) << 0; - QTest::newRow("schar3") << qVariantFromValue(SCHAR_MIN) << qVariantFromValue(SCHAR_MIN) << 0; - QTest::newRow("schar4") << qVariantFromValue(SCHAR_MIN) << qVariantFromValue(SCHAR_MAX) << -1; - QTest::newRow("schar5") << qVariantFromValue(SCHAR_MAX) << qVariantFromValue(SCHAR_MIN) << +1; - - QTest::newRow("uchar1") << qVariantFromValue(uchar(0)) << qVariantFromValue(uchar(0)) << 0; - QTest::newRow("uchar2") << qVariantFromValue(UCHAR_MAX) << qVariantFromValue(UCHAR_MAX) << 0; - QTest::newRow("uchar3") << qVariantFromValue(uchar(0)) << qVariantFromValue(UCHAR_MAX) << -1; - QTest::newRow("uchar4") << qVariantFromValue(UCHAR_MAX) << qVariantFromValue(uchar(0)) << +1; - - QTest::newRow("short1") << qVariantFromValue(short(0)) << qVariantFromValue(short(0)) << 0; - QTest::newRow("short2") << qVariantFromValue(SHRT_MAX) << qVariantFromValue(SHRT_MAX) << 0; - QTest::newRow("short3") << qVariantFromValue(SHRT_MIN) << qVariantFromValue(SHRT_MIN) << 0; - QTest::newRow("short4") << qVariantFromValue(SHRT_MIN) << qVariantFromValue(SHRT_MAX) << -1; - QTest::newRow("short5") << qVariantFromValue(SHRT_MAX) << qVariantFromValue(SHRT_MIN) << +1; - - QTest::newRow("ushort1") << qVariantFromValue(ushort(0)) << qVariantFromValue(ushort(0)) << 0; - QTest::newRow("ushort2") << qVariantFromValue(USHRT_MAX) << qVariantFromValue(USHRT_MAX) << 0; - QTest::newRow("ushort3") << qVariantFromValue(ushort(0)) << qVariantFromValue(USHRT_MAX) << -1; - QTest::newRow("ushort4") << qVariantFromValue(USHRT_MAX) << qVariantFromValue(ushort(0)) << +1; - - QTest::newRow("int1") << qVariantFromValue(int(0)) << qVariantFromValue(int(0)) << 0; - QTest::newRow("int2") << qVariantFromValue(INT_MAX) << qVariantFromValue(INT_MAX) << 0; - QTest::newRow("int3") << qVariantFromValue(INT_MIN) << qVariantFromValue(INT_MIN) << 0; - QTest::newRow("int4") << qVariantFromValue(INT_MIN) << qVariantFromValue(INT_MAX) << -1; - QTest::newRow("int5") << qVariantFromValue(INT_MAX) << qVariantFromValue(INT_MIN) << +1; - - QTest::newRow("uint1") << qVariantFromValue(uint(0)) << qVariantFromValue(uint(0)) << 0; - QTest::newRow("uint2") << qVariantFromValue(UINT_MAX) << qVariantFromValue(UINT_MAX) << 0; - QTest::newRow("uint3") << qVariantFromValue(uint(0)) << qVariantFromValue(UINT_MAX) << -1; - QTest::newRow("uint4") << qVariantFromValue(UINT_MAX) << qVariantFromValue(uint(0)) << +1; - - QTest::newRow("long1") << qVariantFromValue(long(0)) << qVariantFromValue(long(0)) << 0; - QTest::newRow("long2") << qVariantFromValue(LONG_MAX) << qVariantFromValue(LONG_MAX) << 0; - QTest::newRow("long3") << qVariantFromValue(LONG_MIN) << qVariantFromValue(LONG_MIN) << 0; - QTest::newRow("long4") << qVariantFromValue(LONG_MIN) << qVariantFromValue(LONG_MAX) << -1; - QTest::newRow("long5") << qVariantFromValue(LONG_MAX) << qVariantFromValue(LONG_MIN) << +1; - - QTest::newRow("ulong1") << qVariantFromValue(ulong(0)) << qVariantFromValue(ulong(0)) << 0; - QTest::newRow("ulong2") << qVariantFromValue(ULONG_MAX) << qVariantFromValue(ULONG_MAX) << 0; - QTest::newRow("ulong3") << qVariantFromValue(ulong(0)) << qVariantFromValue(ULONG_MAX) << -1; - QTest::newRow("ulong4") << qVariantFromValue(ULONG_MAX) << qVariantFromValue(ulong(0)) << +1; - - QTest::newRow("llong1") << qVariantFromValue(qlonglong(0)) << qVariantFromValue(qlonglong(0)) << 0; - QTest::newRow("llong2") << qVariantFromValue(LLONG_MAX) << qVariantFromValue(LLONG_MAX) << 0; - QTest::newRow("llong3") << qVariantFromValue(LLONG_MIN) << qVariantFromValue(LLONG_MIN) << 0; - QTest::newRow("llong4") << qVariantFromValue(LLONG_MIN) << qVariantFromValue(LLONG_MAX) << -1; - QTest::newRow("llong5") << qVariantFromValue(LLONG_MAX) << qVariantFromValue(LLONG_MIN) << +1; - - QTest::newRow("ullong1") << qVariantFromValue(qulonglong(0)) << qVariantFromValue(qulonglong(0)) << 0; - QTest::newRow("ullong2") << qVariantFromValue(ULLONG_MAX) << qVariantFromValue(ULLONG_MAX) << 0; - QTest::newRow("ullong3") << qVariantFromValue(qulonglong(0)) << qVariantFromValue(ULLONG_MAX) << -1; - QTest::newRow("ullong4") << qVariantFromValue(ULLONG_MAX) << qVariantFromValue(qulonglong(0)) << +1; - - QTest::newRow("float1") << qVariantFromValue(0.f) << qVariantFromValue(0.f) << 0; - QTest::newRow("float2") << qVariantFromValue(-1.f) << qVariantFromValue(0.f) << -1; - QTest::newRow("float3") << qVariantFromValue(0.f) << qVariantFromValue(-1.f) << +1; - QTest::newRow("float4") << qVariantFromValue(-float(qInf())) << qVariantFromValue(0.f) << -1; - QTest::newRow("float5") << qVariantFromValue(0.f) << qVariantFromValue(-float(qInf())) << +1; - QTest::newRow("float6") << qVariantFromValue(-float(qInf())) << qVariantFromValue(-float(qInf())) << 0; - QTest::newRow("float7") << qVariantFromValue(float(qInf())) << qVariantFromValue(float(qInf())) << 0; - - QTest::newRow("double1") << qVariantFromValue(0.) << qVariantFromValue(0.) << 0; - QTest::newRow("double2") << qVariantFromValue(-1.) << qVariantFromValue(0.) << -1; - QTest::newRow("double3") << qVariantFromValue(0.) << qVariantFromValue(-1.) << +1; - QTest::newRow("double4") << qVariantFromValue(-qInf()) << qVariantFromValue(0.) << -1; - QTest::newRow("double5") << qVariantFromValue(0.) << qVariantFromValue(-qInf()) << +1; - QTest::newRow("double6") << qVariantFromValue(-double(qInf())) << qVariantFromValue(-qInf()) << 0; - QTest::newRow("double7") << qVariantFromValue(qInf()) << qVariantFromValue(qInf()) << 0; - QTest::newRow("double8") << qVariantFromValue(-qInf()) << qVariantFromValue(qInf()) << -1; - QTest::newRow("double9") << qVariantFromValue(qQNaN()) << qVariantFromValue(0.) << INT_MAX; - QTest::newRow("double10") << qVariantFromValue(0.) << qVariantFromValue(qQNaN()) << INT_MAX; - QTest::newRow("double11") << qVariantFromValue(qQNaN()) << qVariantFromValue(qQNaN()) << INT_MAX; + QTest::newRow("char1") << QVariant::fromValue(char(0)) << QVariant::fromValue(char(0)) << 0; + QTest::newRow("char2") << QVariant::fromValue(CHAR_MAX) << QVariant::fromValue(CHAR_MAX) << 0; + QTest::newRow("char3") << QVariant::fromValue(CHAR_MIN) << QVariant::fromValue(CHAR_MIN) << 0; + QTest::newRow("char4") << QVariant::fromValue(CHAR_MIN) << QVariant::fromValue(CHAR_MAX) << -1; + QTest::newRow("char5") << QVariant::fromValue(CHAR_MAX) << QVariant::fromValue(CHAR_MIN) << +1; + + QTest::newRow("schar1") << QVariant::fromValue(schar(0)) << QVariant::fromValue(schar(0)) << 0; + QTest::newRow("schar2") << QVariant::fromValue(SCHAR_MAX) << QVariant::fromValue(SCHAR_MAX) << 0; + QTest::newRow("schar3") << QVariant::fromValue(SCHAR_MIN) << QVariant::fromValue(SCHAR_MIN) << 0; + QTest::newRow("schar4") << QVariant::fromValue(SCHAR_MIN) << QVariant::fromValue(SCHAR_MAX) << -1; + QTest::newRow("schar5") << QVariant::fromValue(SCHAR_MAX) << QVariant::fromValue(SCHAR_MIN) << +1; + + QTest::newRow("uchar1") << QVariant::fromValue(uchar(0)) << QVariant::fromValue(uchar(0)) << 0; + QTest::newRow("uchar2") << QVariant::fromValue(UCHAR_MAX) << QVariant::fromValue(UCHAR_MAX) << 0; + QTest::newRow("uchar3") << QVariant::fromValue(uchar(0)) << QVariant::fromValue(UCHAR_MAX) << -1; + QTest::newRow("uchar4") << QVariant::fromValue(UCHAR_MAX) << QVariant::fromValue(uchar(0)) << +1; + + QTest::newRow("short1") << QVariant::fromValue(short(0)) << QVariant::fromValue(short(0)) << 0; + QTest::newRow("short2") << QVariant::fromValue(SHRT_MAX) << QVariant::fromValue(SHRT_MAX) << 0; + QTest::newRow("short3") << QVariant::fromValue(SHRT_MIN) << QVariant::fromValue(SHRT_MIN) << 0; + QTest::newRow("short4") << QVariant::fromValue(SHRT_MIN) << QVariant::fromValue(SHRT_MAX) << -1; + QTest::newRow("short5") << QVariant::fromValue(SHRT_MAX) << QVariant::fromValue(SHRT_MIN) << +1; + + QTest::newRow("ushort1") << QVariant::fromValue(ushort(0)) << QVariant::fromValue(ushort(0)) << 0; + QTest::newRow("ushort2") << QVariant::fromValue(USHRT_MAX) << QVariant::fromValue(USHRT_MAX) << 0; + QTest::newRow("ushort3") << QVariant::fromValue(ushort(0)) << QVariant::fromValue(USHRT_MAX) << -1; + QTest::newRow("ushort4") << QVariant::fromValue(USHRT_MAX) << QVariant::fromValue(ushort(0)) << +1; + + QTest::newRow("int1") << QVariant::fromValue(int(0)) << QVariant::fromValue(int(0)) << 0; + QTest::newRow("int2") << QVariant::fromValue(INT_MAX) << QVariant::fromValue(INT_MAX) << 0; + QTest::newRow("int3") << QVariant::fromValue(INT_MIN) << QVariant::fromValue(INT_MIN) << 0; + QTest::newRow("int4") << QVariant::fromValue(INT_MIN) << QVariant::fromValue(INT_MAX) << -1; + QTest::newRow("int5") << QVariant::fromValue(INT_MAX) << QVariant::fromValue(INT_MIN) << +1; + + QTest::newRow("uint1") << QVariant::fromValue(uint(0)) << QVariant::fromValue(uint(0)) << 0; + QTest::newRow("uint2") << QVariant::fromValue(UINT_MAX) << QVariant::fromValue(UINT_MAX) << 0; + QTest::newRow("uint3") << QVariant::fromValue(uint(0)) << QVariant::fromValue(UINT_MAX) << -1; + QTest::newRow("uint4") << QVariant::fromValue(UINT_MAX) << QVariant::fromValue(uint(0)) << +1; + + QTest::newRow("long1") << QVariant::fromValue(long(0)) << QVariant::fromValue(long(0)) << 0; + QTest::newRow("long2") << QVariant::fromValue(LONG_MAX) << QVariant::fromValue(LONG_MAX) << 0; + QTest::newRow("long3") << QVariant::fromValue(LONG_MIN) << QVariant::fromValue(LONG_MIN) << 0; + QTest::newRow("long4") << QVariant::fromValue(LONG_MIN) << QVariant::fromValue(LONG_MAX) << -1; + QTest::newRow("long5") << QVariant::fromValue(LONG_MAX) << QVariant::fromValue(LONG_MIN) << +1; + + QTest::newRow("ulong1") << QVariant::fromValue(ulong(0)) << QVariant::fromValue(ulong(0)) << 0; + QTest::newRow("ulong2") << QVariant::fromValue(ULONG_MAX) << QVariant::fromValue(ULONG_MAX) << 0; + QTest::newRow("ulong3") << QVariant::fromValue(ulong(0)) << QVariant::fromValue(ULONG_MAX) << -1; + QTest::newRow("ulong4") << QVariant::fromValue(ULONG_MAX) << QVariant::fromValue(ulong(0)) << +1; + + QTest::newRow("llong1") << QVariant::fromValue(qlonglong(0)) << QVariant::fromValue(qlonglong(0)) << 0; + QTest::newRow("llong2") << QVariant::fromValue(LLONG_MAX) << QVariant::fromValue(LLONG_MAX) << 0; + QTest::newRow("llong3") << QVariant::fromValue(LLONG_MIN) << QVariant::fromValue(LLONG_MIN) << 0; + QTest::newRow("llong4") << QVariant::fromValue(LLONG_MIN) << QVariant::fromValue(LLONG_MAX) << -1; + QTest::newRow("llong5") << QVariant::fromValue(LLONG_MAX) << QVariant::fromValue(LLONG_MIN) << +1; + + QTest::newRow("ullong1") << QVariant::fromValue(qulonglong(0)) << QVariant::fromValue(qulonglong(0)) << 0; + QTest::newRow("ullong2") << QVariant::fromValue(ULLONG_MAX) << QVariant::fromValue(ULLONG_MAX) << 0; + QTest::newRow("ullong3") << QVariant::fromValue(qulonglong(0)) << QVariant::fromValue(ULLONG_MAX) << -1; + QTest::newRow("ullong4") << QVariant::fromValue(ULLONG_MAX) << QVariant::fromValue(qulonglong(0)) << +1; + + QTest::newRow("float1") << QVariant::fromValue(0.f) << QVariant::fromValue(0.f) << 0; + QTest::newRow("float2") << QVariant::fromValue(-1.f) << QVariant::fromValue(0.f) << -1; + QTest::newRow("float3") << QVariant::fromValue(0.f) << QVariant::fromValue(-1.f) << +1; + QTest::newRow("float4") << QVariant::fromValue(-float(qInf())) << QVariant::fromValue(0.f) << -1; + QTest::newRow("float5") << QVariant::fromValue(0.f) << QVariant::fromValue(-float(qInf())) << +1; + QTest::newRow("float6") << QVariant::fromValue(-float(qInf())) << QVariant::fromValue(-float(qInf())) << 0; + QTest::newRow("float7") << QVariant::fromValue(float(qInf())) << QVariant::fromValue(float(qInf())) << 0; + + QTest::newRow("double1") << QVariant::fromValue(0.) << QVariant::fromValue(0.) << 0; + QTest::newRow("double2") << QVariant::fromValue(-1.) << QVariant::fromValue(0.) << -1; + QTest::newRow("double3") << QVariant::fromValue(0.) << QVariant::fromValue(-1.) << +1; + QTest::newRow("double4") << QVariant::fromValue(-qInf()) << QVariant::fromValue(0.) << -1; + QTest::newRow("double5") << QVariant::fromValue(0.) << QVariant::fromValue(-qInf()) << +1; + QTest::newRow("double6") << QVariant::fromValue(-double(qInf())) << QVariant::fromValue(-qInf()) << 0; + QTest::newRow("double7") << QVariant::fromValue(qInf()) << QVariant::fromValue(qInf()) << 0; + QTest::newRow("double8") << QVariant::fromValue(-qInf()) << QVariant::fromValue(qInf()) << -1; + QTest::newRow("double9") << QVariant::fromValue(qQNaN()) << QVariant::fromValue(0.) << INT_MAX; + QTest::newRow("double10") << QVariant::fromValue(0.) << QVariant::fromValue(qQNaN()) << INT_MAX; + QTest::newRow("double11") << QVariant::fromValue(qQNaN()) << QVariant::fromValue(qQNaN()) << INT_MAX; // mixed comparisons // fp + fp - QTest::newRow("float+double1") << qVariantFromValue(0.f) << qVariantFromValue(0.) << 0; - QTest::newRow("float+double2") << qVariantFromValue(-1.f) << qVariantFromValue(0.) << -1; - QTest::newRow("float+double3") << qVariantFromValue(0.f) << qVariantFromValue(-1.) << +1; - QTest::newRow("float+double4") << qVariantFromValue(-float(qInf())) << qVariantFromValue(0.) << -1; - QTest::newRow("float+double5") << qVariantFromValue(0.f) << qVariantFromValue(-qInf()) << +1; - QTest::newRow("float+double6") << qVariantFromValue(-float(qInf())) << qVariantFromValue(-qInf()) << 0; - QTest::newRow("float+double7") << qVariantFromValue(float(qInf())) << qVariantFromValue(qInf()) << 0; - QTest::newRow("float+double8") << qVariantFromValue(-float(qInf())) << qVariantFromValue(qInf()) << -1; - QTest::newRow("float+double9") << qVariantFromValue(qQNaN()) << qVariantFromValue(0.) << INT_MAX; - QTest::newRow("float+double10") << qVariantFromValue(0.) << qVariantFromValue(qQNaN()) << INT_MAX; - QTest::newRow("float+double11") << qVariantFromValue(qQNaN()) << qVariantFromValue(qQNaN()) << INT_MAX; + QTest::newRow("float+double1") << QVariant::fromValue(0.f) << QVariant::fromValue(0.) << 0; + QTest::newRow("float+double2") << QVariant::fromValue(-1.f) << QVariant::fromValue(0.) << -1; + QTest::newRow("float+double3") << QVariant::fromValue(0.f) << QVariant::fromValue(-1.) << +1; + QTest::newRow("float+double4") << QVariant::fromValue(-float(qInf())) << QVariant::fromValue(0.) << -1; + QTest::newRow("float+double5") << QVariant::fromValue(0.f) << QVariant::fromValue(-qInf()) << +1; + QTest::newRow("float+double6") << QVariant::fromValue(-float(qInf())) << QVariant::fromValue(-qInf()) << 0; + QTest::newRow("float+double7") << QVariant::fromValue(float(qInf())) << QVariant::fromValue(qInf()) << 0; + QTest::newRow("float+double8") << QVariant::fromValue(-float(qInf())) << QVariant::fromValue(qInf()) << -1; + QTest::newRow("float+double9") << QVariant::fromValue(qQNaN()) << QVariant::fromValue(0.) << INT_MAX; + QTest::newRow("float+double10") << QVariant::fromValue(0.) << QVariant::fromValue(qQNaN()) << INT_MAX; + QTest::newRow("float+double11") << QVariant::fromValue(qQNaN()) << QVariant::fromValue(qQNaN()) << INT_MAX; // fp + int - QTest::newRow("float+int1") << qVariantFromValue(0.f) << qVariantFromValue(0) << 0; - QTest::newRow("double+int1") << qVariantFromValue(0.) << qVariantFromValue(0) << 0; - QTest::newRow("float+int2") << qVariantFromValue(-1.f) << qVariantFromValue(0) << -1; - QTest::newRow("double+int2") << qVariantFromValue(-1.) << qVariantFromValue(0) << -1; - QTest::newRow("float+int3") << qVariantFromValue(0.f) << qVariantFromValue(-1) << +1; - QTest::newRow("double+int3") << qVariantFromValue(0.) << qVariantFromValue(-1) << +1; - QTest::newRow("float+int4") << qVariantFromValue(1.5f) << qVariantFromValue(1) << +1; - QTest::newRow("double+int4") << qVariantFromValue(1.5) << qVariantFromValue(1) << +1; - QTest::newRow("double+int5") << qVariantFromValue(qInf()) << qVariantFromValue(1) << +1; + QTest::newRow("float+int1") << QVariant::fromValue(0.f) << QVariant::fromValue(0) << 0; + QTest::newRow("double+int1") << QVariant::fromValue(0.) << QVariant::fromValue(0) << 0; + QTest::newRow("float+int2") << QVariant::fromValue(-1.f) << QVariant::fromValue(0) << -1; + QTest::newRow("double+int2") << QVariant::fromValue(-1.) << QVariant::fromValue(0) << -1; + QTest::newRow("float+int3") << QVariant::fromValue(0.f) << QVariant::fromValue(-1) << +1; + QTest::newRow("double+int3") << QVariant::fromValue(0.) << QVariant::fromValue(-1) << +1; + QTest::newRow("float+int4") << QVariant::fromValue(1.5f) << QVariant::fromValue(1) << +1; + QTest::newRow("double+int4") << QVariant::fromValue(1.5) << QVariant::fromValue(1) << +1; + QTest::newRow("double+int5") << QVariant::fromValue(qInf()) << QVariant::fromValue(1) << +1; // fp + uint - QTest::newRow("float+uint1") << qVariantFromValue(0.f) << qVariantFromValue(0U) << 0; - QTest::newRow("double+uint1") << qVariantFromValue(0.) << qVariantFromValue(0U) << 0; - QTest::newRow("float+uint2") << qVariantFromValue(-1.f) << qVariantFromValue(0U) << -1; - QTest::newRow("double+uint2") << qVariantFromValue(-1.) << qVariantFromValue(0U) << -1; - QTest::newRow("float+uint3") << qVariantFromValue(0.f) << qVariantFromValue(1U) << -1; - QTest::newRow("double+uint3") << qVariantFromValue(0.) << qVariantFromValue(1U) << -1; - QTest::newRow("float+uint4") << qVariantFromValue(1.5f) << qVariantFromValue(1U) << +1; - QTest::newRow("double+uint4") << qVariantFromValue(1.5) << qVariantFromValue(1U) << +1; + QTest::newRow("float+uint1") << QVariant::fromValue(0.f) << QVariant::fromValue(0U) << 0; + QTest::newRow("double+uint1") << QVariant::fromValue(0.) << QVariant::fromValue(0U) << 0; + QTest::newRow("float+uint2") << QVariant::fromValue(-1.f) << QVariant::fromValue(0U) << -1; + QTest::newRow("double+uint2") << QVariant::fromValue(-1.) << QVariant::fromValue(0U) << -1; + QTest::newRow("float+uint3") << QVariant::fromValue(0.f) << QVariant::fromValue(1U) << -1; + QTest::newRow("double+uint3") << QVariant::fromValue(0.) << QVariant::fromValue(1U) << -1; + QTest::newRow("float+uint4") << QVariant::fromValue(1.5f) << QVariant::fromValue(1U) << +1; + QTest::newRow("double+uint4") << QVariant::fromValue(1.5) << QVariant::fromValue(1U) << +1; // lower ranked + int - QTest::newRow("bool+int1") << qVariantFromValue(false) << qVariantFromValue(0) << 0; - QTest::newRow("bool+int2") << qVariantFromValue(false) << qVariantFromValue(1) << -1; - QTest::newRow("bool+int3") << qVariantFromValue(true) << qVariantFromValue(0) << +1; - QTest::newRow("bool+int4") << qVariantFromValue(true) << qVariantFromValue(1) << 0; - QTest::newRow("bool+int5") << qVariantFromValue(true) << qVariantFromValue(2) << -1; - - QTest::newRow("char+int1") << qVariantFromValue(char(0)) << qVariantFromValue(0) << 0; - QTest::newRow("char+int2") << qVariantFromValue(char(0)) << qVariantFromValue(1) << -1; - QTest::newRow("char+int3") << qVariantFromValue(char(1)) << qVariantFromValue(0) << +1; - QTest::newRow("char+int4") << qVariantFromValue(char(1)) << qVariantFromValue(1) << 0; + QTest::newRow("bool+int1") << QVariant::fromValue(false) << QVariant::fromValue(0) << 0; + QTest::newRow("bool+int2") << QVariant::fromValue(false) << QVariant::fromValue(1) << -1; + QTest::newRow("bool+int3") << QVariant::fromValue(true) << QVariant::fromValue(0) << +1; + QTest::newRow("bool+int4") << QVariant::fromValue(true) << QVariant::fromValue(1) << 0; + QTest::newRow("bool+int5") << QVariant::fromValue(true) << QVariant::fromValue(2) << -1; + + QTest::newRow("char+int1") << QVariant::fromValue(char(0)) << QVariant::fromValue(0) << 0; + QTest::newRow("char+int2") << QVariant::fromValue(char(0)) << QVariant::fromValue(1) << -1; + QTest::newRow("char+int3") << QVariant::fromValue(char(1)) << QVariant::fromValue(0) << +1; + QTest::newRow("char+int4") << QVariant::fromValue(char(1)) << QVariant::fromValue(1) << 0; if (std::numeric_limits<char>::is_signed) { - QTest::newRow("char+int5") << qVariantFromValue(char(-1)) << qVariantFromValue(0) << -1; - QTest::newRow("char+int6") << qVariantFromValue(char(-1)) << qVariantFromValue(-1) << 0; - } - - QTest::newRow("schar+int1") << qVariantFromValue(schar(0)) << qVariantFromValue(0) << 0; - QTest::newRow("schar+int2") << qVariantFromValue(schar(0)) << qVariantFromValue(1) << -1; - QTest::newRow("schar+int3") << qVariantFromValue(schar(1)) << qVariantFromValue(0) << +1; - QTest::newRow("schar+int4") << qVariantFromValue(schar(1)) << qVariantFromValue(1) << 0; - QTest::newRow("schar+int5") << qVariantFromValue(schar(-1)) << qVariantFromValue(0) << -1; - QTest::newRow("schar+int6") << qVariantFromValue(schar(-1)) << qVariantFromValue(-1) << 0; - - QTest::newRow("uchar+int1") << qVariantFromValue(uchar(0)) << qVariantFromValue(0) << 0; - QTest::newRow("uchar+int2") << qVariantFromValue(uchar(0)) << qVariantFromValue(1) << -1; - QTest::newRow("uchar+int3") << qVariantFromValue(uchar(1)) << qVariantFromValue(0) << +1; - QTest::newRow("uchar+int4") << qVariantFromValue(uchar(1)) << qVariantFromValue(1) << 0; - - QTest::newRow("short+int1") << qVariantFromValue(short(0)) << qVariantFromValue(0) << 0; - QTest::newRow("short+int2") << qVariantFromValue(short(0)) << qVariantFromValue(1) << -1; - QTest::newRow("short+int3") << qVariantFromValue(short(1)) << qVariantFromValue(0) << +1; - QTest::newRow("short+int4") << qVariantFromValue(short(1)) << qVariantFromValue(1) << 0; - QTest::newRow("short+int5") << qVariantFromValue(short(-1)) << qVariantFromValue(0) << -1; - QTest::newRow("short+int6") << qVariantFromValue(short(-1)) << qVariantFromValue(-1) << 0; - - QTest::newRow("ushort+int1") << qVariantFromValue(ushort(0)) << qVariantFromValue(0) << 0; - QTest::newRow("ushort+int2") << qVariantFromValue(ushort(0)) << qVariantFromValue(1) << -1; - QTest::newRow("ushort+int3") << qVariantFromValue(ushort(1)) << qVariantFromValue(0) << +1; - QTest::newRow("ushort+int4") << qVariantFromValue(ushort(1)) << qVariantFromValue(1) << 0; + QTest::newRow("char+int5") << QVariant::fromValue(char(-1)) << QVariant::fromValue(0) << -1; + QTest::newRow("char+int6") << QVariant::fromValue(char(-1)) << QVariant::fromValue(-1) << 0; + } + + QTest::newRow("schar+int1") << QVariant::fromValue(schar(0)) << QVariant::fromValue(0) << 0; + QTest::newRow("schar+int2") << QVariant::fromValue(schar(0)) << QVariant::fromValue(1) << -1; + QTest::newRow("schar+int3") << QVariant::fromValue(schar(1)) << QVariant::fromValue(0) << +1; + QTest::newRow("schar+int4") << QVariant::fromValue(schar(1)) << QVariant::fromValue(1) << 0; + QTest::newRow("schar+int5") << QVariant::fromValue(schar(-1)) << QVariant::fromValue(0) << -1; + QTest::newRow("schar+int6") << QVariant::fromValue(schar(-1)) << QVariant::fromValue(-1) << 0; + + QTest::newRow("uchar+int1") << QVariant::fromValue(uchar(0)) << QVariant::fromValue(0) << 0; + QTest::newRow("uchar+int2") << QVariant::fromValue(uchar(0)) << QVariant::fromValue(1) << -1; + QTest::newRow("uchar+int3") << QVariant::fromValue(uchar(1)) << QVariant::fromValue(0) << +1; + QTest::newRow("uchar+int4") << QVariant::fromValue(uchar(1)) << QVariant::fromValue(1) << 0; + + QTest::newRow("short+int1") << QVariant::fromValue(short(0)) << QVariant::fromValue(0) << 0; + QTest::newRow("short+int2") << QVariant::fromValue(short(0)) << QVariant::fromValue(1) << -1; + QTest::newRow("short+int3") << QVariant::fromValue(short(1)) << QVariant::fromValue(0) << +1; + QTest::newRow("short+int4") << QVariant::fromValue(short(1)) << QVariant::fromValue(1) << 0; + QTest::newRow("short+int5") << QVariant::fromValue(short(-1)) << QVariant::fromValue(0) << -1; + QTest::newRow("short+int6") << QVariant::fromValue(short(-1)) << QVariant::fromValue(-1) << 0; + + QTest::newRow("ushort+int1") << QVariant::fromValue(ushort(0)) << QVariant::fromValue(0) << 0; + QTest::newRow("ushort+int2") << QVariant::fromValue(ushort(0)) << QVariant::fromValue(1) << -1; + QTest::newRow("ushort+int3") << QVariant::fromValue(ushort(1)) << QVariant::fromValue(0) << +1; + QTest::newRow("ushort+int4") << QVariant::fromValue(ushort(1)) << QVariant::fromValue(1) << 0; // lower ranked + uint (without sign change) - QTest::newRow("bool+uint1") << qVariantFromValue(false) << qVariantFromValue(0U) << 0; - QTest::newRow("bool+uint2") << qVariantFromValue(false) << qVariantFromValue(1U) << -1; - QTest::newRow("bool+uint3") << qVariantFromValue(true) << qVariantFromValue(0U) << +1; - QTest::newRow("bool+uint4") << qVariantFromValue(true) << qVariantFromValue(1U) << 0; - QTest::newRow("bool+uint5") << qVariantFromValue(true) << qVariantFromValue(2U) << -1; - - QTest::newRow("char+uint1") << qVariantFromValue(char(0)) << qVariantFromValue(0U) << 0; - QTest::newRow("char+uint2") << qVariantFromValue(char(0)) << qVariantFromValue(1U) << -1; - QTest::newRow("char+uint3") << qVariantFromValue(char(1)) << qVariantFromValue(0U) << +1; - QTest::newRow("char+uint4") << qVariantFromValue(char(1)) << qVariantFromValue(1U) << 0; - - QTest::newRow("schar+uint1") << qVariantFromValue(schar(0)) << qVariantFromValue(0U) << 0; - QTest::newRow("schar+uint2") << qVariantFromValue(schar(0)) << qVariantFromValue(1U) << -1; - QTest::newRow("schar+uint3") << qVariantFromValue(schar(1)) << qVariantFromValue(0U) << +1; - QTest::newRow("schar+uint4") << qVariantFromValue(schar(1)) << qVariantFromValue(1U) << 0; - - QTest::newRow("uchar+uint1") << qVariantFromValue(uchar(0)) << qVariantFromValue(0U) << 0; - QTest::newRow("uchar+uint2") << qVariantFromValue(uchar(0)) << qVariantFromValue(1U) << -1; - QTest::newRow("uchar+uint3") << qVariantFromValue(uchar(1)) << qVariantFromValue(0U) << +1; - QTest::newRow("uchar+uint4") << qVariantFromValue(uchar(1)) << qVariantFromValue(1U) << 0; - - QTest::newRow("short+uint1") << qVariantFromValue(short(0)) << qVariantFromValue(0U) << 0; - QTest::newRow("short+uint2") << qVariantFromValue(short(0)) << qVariantFromValue(1U) << -1; - QTest::newRow("short+uint3") << qVariantFromValue(short(1)) << qVariantFromValue(0U) << +1; - QTest::newRow("short+uint4") << qVariantFromValue(short(1)) << qVariantFromValue(1U) << 0; - - QTest::newRow("ushort+uint1") << qVariantFromValue(ushort(0)) << qVariantFromValue(0U) << 0; - QTest::newRow("ushort+uint2") << qVariantFromValue(ushort(0)) << qVariantFromValue(1U) << -1; - QTest::newRow("ushort+uint3") << qVariantFromValue(ushort(1)) << qVariantFromValue(0U) << +1; - QTest::newRow("ushort+uint4") << qVariantFromValue(ushort(1)) << qVariantFromValue(1U) << 0; + QTest::newRow("bool+uint1") << QVariant::fromValue(false) << QVariant::fromValue(0U) << 0; + QTest::newRow("bool+uint2") << QVariant::fromValue(false) << QVariant::fromValue(1U) << -1; + QTest::newRow("bool+uint3") << QVariant::fromValue(true) << QVariant::fromValue(0U) << +1; + QTest::newRow("bool+uint4") << QVariant::fromValue(true) << QVariant::fromValue(1U) << 0; + QTest::newRow("bool+uint5") << QVariant::fromValue(true) << QVariant::fromValue(2U) << -1; + + QTest::newRow("char+uint1") << QVariant::fromValue(char(0)) << QVariant::fromValue(0U) << 0; + QTest::newRow("char+uint2") << QVariant::fromValue(char(0)) << QVariant::fromValue(1U) << -1; + QTest::newRow("char+uint3") << QVariant::fromValue(char(1)) << QVariant::fromValue(0U) << +1; + QTest::newRow("char+uint4") << QVariant::fromValue(char(1)) << QVariant::fromValue(1U) << 0; + + QTest::newRow("schar+uint1") << QVariant::fromValue(schar(0)) << QVariant::fromValue(0U) << 0; + QTest::newRow("schar+uint2") << QVariant::fromValue(schar(0)) << QVariant::fromValue(1U) << -1; + QTest::newRow("schar+uint3") << QVariant::fromValue(schar(1)) << QVariant::fromValue(0U) << +1; + QTest::newRow("schar+uint4") << QVariant::fromValue(schar(1)) << QVariant::fromValue(1U) << 0; + + QTest::newRow("uchar+uint1") << QVariant::fromValue(uchar(0)) << QVariant::fromValue(0U) << 0; + QTest::newRow("uchar+uint2") << QVariant::fromValue(uchar(0)) << QVariant::fromValue(1U) << -1; + QTest::newRow("uchar+uint3") << QVariant::fromValue(uchar(1)) << QVariant::fromValue(0U) << +1; + QTest::newRow("uchar+uint4") << QVariant::fromValue(uchar(1)) << QVariant::fromValue(1U) << 0; + + QTest::newRow("short+uint1") << QVariant::fromValue(short(0)) << QVariant::fromValue(0U) << 0; + QTest::newRow("short+uint2") << QVariant::fromValue(short(0)) << QVariant::fromValue(1U) << -1; + QTest::newRow("short+uint3") << QVariant::fromValue(short(1)) << QVariant::fromValue(0U) << +1; + QTest::newRow("short+uint4") << QVariant::fromValue(short(1)) << QVariant::fromValue(1U) << 0; + + QTest::newRow("ushort+uint1") << QVariant::fromValue(ushort(0)) << QVariant::fromValue(0U) << 0; + QTest::newRow("ushort+uint2") << QVariant::fromValue(ushort(0)) << QVariant::fromValue(1U) << -1; + QTest::newRow("ushort+uint3") << QVariant::fromValue(ushort(1)) << QVariant::fromValue(0U) << +1; + QTest::newRow("ushort+uint4") << QVariant::fromValue(ushort(1)) << QVariant::fromValue(1U) << 0; // int + qlonglong - QTest::newRow("int+qlonglong1") << qVariantFromValue(0) << qVariantFromValue(Q_INT64_C(0)) << 0; - QTest::newRow("int+qlonglong2") << qVariantFromValue(1) << qVariantFromValue(Q_INT64_C(0)) << +1; - QTest::newRow("int+qlonglong3") << qVariantFromValue(0) << qVariantFromValue(Q_INT64_C(1)) << -1; - QTest::newRow("int+qlonglong4") << qVariantFromValue(1) << qVariantFromValue(Q_INT64_C(1)) << 0; - QTest::newRow("int+qlonglong5") << qVariantFromValue(0) << qVariantFromValue(Q_INT64_C(-1)) << +1; - QTest::newRow("int+qlonglong6") << qVariantFromValue(-1) << qVariantFromValue(Q_INT64_C(0)) << -1; - QTest::newRow("int+qlonglong7") << qVariantFromValue(-1) << qVariantFromValue(Q_INT64_C(-1)) << 0; + QTest::newRow("int+qlonglong1") << QVariant::fromValue(0) << QVariant::fromValue(Q_INT64_C(0)) << 0; + QTest::newRow("int+qlonglong2") << QVariant::fromValue(1) << QVariant::fromValue(Q_INT64_C(0)) << +1; + QTest::newRow("int+qlonglong3") << QVariant::fromValue(0) << QVariant::fromValue(Q_INT64_C(1)) << -1; + QTest::newRow("int+qlonglong4") << QVariant::fromValue(1) << QVariant::fromValue(Q_INT64_C(1)) << 0; + QTest::newRow("int+qlonglong5") << QVariant::fromValue(0) << QVariant::fromValue(Q_INT64_C(-1)) << +1; + QTest::newRow("int+qlonglong6") << QVariant::fromValue(-1) << QVariant::fromValue(Q_INT64_C(0)) << -1; + QTest::newRow("int+qlonglong7") << QVariant::fromValue(-1) << QVariant::fromValue(Q_INT64_C(-1)) << 0; // uint + qulonglong - QTest::newRow("uint+qulonglong1") << qVariantFromValue(0U) << qVariantFromValue(Q_UINT64_C(0)) << 0; - QTest::newRow("uint+qulonglong2") << qVariantFromValue(1U) << qVariantFromValue(Q_UINT64_C(0)) << +1; - QTest::newRow("uint+qulonglong3") << qVariantFromValue(0U) << qVariantFromValue(Q_UINT64_C(1)) << -1; - QTest::newRow("uint+qulonglong4") << qVariantFromValue(1U) << qVariantFromValue(Q_UINT64_C(1)) << 0; + QTest::newRow("uint+qulonglong1") << QVariant::fromValue(0U) << QVariant::fromValue(Q_UINT64_C(0)) << 0; + QTest::newRow("uint+qulonglong2") << QVariant::fromValue(1U) << QVariant::fromValue(Q_UINT64_C(0)) << +1; + QTest::newRow("uint+qulonglong3") << QVariant::fromValue(0U) << QVariant::fromValue(Q_UINT64_C(1)) << -1; + QTest::newRow("uint+qulonglong4") << QVariant::fromValue(1U) << QVariant::fromValue(Q_UINT64_C(1)) << 0; // int + uint (without sign change) - QTest::newRow("int+uint1") << qVariantFromValue(0) << qVariantFromValue(0U) << 0; - QTest::newRow("int+uint2") << qVariantFromValue(1) << qVariantFromValue(0U) << +1; - QTest::newRow("int+uint3") << qVariantFromValue(0) << qVariantFromValue(1U) << -1; - QTest::newRow("int+uint4") << qVariantFromValue(1) << qVariantFromValue(1U) << 0; + QTest::newRow("int+uint1") << QVariant::fromValue(0) << QVariant::fromValue(0U) << 0; + QTest::newRow("int+uint2") << QVariant::fromValue(1) << QVariant::fromValue(0U) << +1; + QTest::newRow("int+uint3") << QVariant::fromValue(0) << QVariant::fromValue(1U) << -1; + QTest::newRow("int+uint4") << QVariant::fromValue(1) << QVariant::fromValue(1U) << 0; // uint + qlonglong - QTest::newRow("uint+qlonglong1") << qVariantFromValue(0U) << qVariantFromValue(Q_INT64_C(0)) << 0; - QTest::newRow("uint+qlonglong2") << qVariantFromValue(1U) << qVariantFromValue(Q_INT64_C(0)) << +1; - QTest::newRow("uint+qlonglong3") << qVariantFromValue(0U) << qVariantFromValue(Q_INT64_C(1)) << -1; - QTest::newRow("uint+qlonglong4") << qVariantFromValue(1U) << qVariantFromValue(Q_INT64_C(1)) << 0; - QTest::newRow("uint+qlonglong5") << qVariantFromValue(0U) << qVariantFromValue(Q_INT64_C(-1)) << +1; + QTest::newRow("uint+qlonglong1") << QVariant::fromValue(0U) << QVariant::fromValue(Q_INT64_C(0)) << 0; + QTest::newRow("uint+qlonglong2") << QVariant::fromValue(1U) << QVariant::fromValue(Q_INT64_C(0)) << +1; + QTest::newRow("uint+qlonglong3") << QVariant::fromValue(0U) << QVariant::fromValue(Q_INT64_C(1)) << -1; + QTest::newRow("uint+qlonglong4") << QVariant::fromValue(1U) << QVariant::fromValue(Q_INT64_C(1)) << 0; + QTest::newRow("uint+qlonglong5") << QVariant::fromValue(0U) << QVariant::fromValue(Q_INT64_C(-1)) << +1; // boundary conditions - QTest::newRow("charmax+intmax") << qVariantFromValue(CHAR_MAX) << qVariantFromValue(INT_MAX) << -1; - QTest::newRow("charmax+uintmax") << qVariantFromValue(CHAR_MAX) << qVariantFromValue(UINT_MAX) << -1; - QTest::newRow("scharmax+intmax") << qVariantFromValue(SCHAR_MAX) << qVariantFromValue(INT_MAX) << -1; - QTest::newRow("scharmax+uintmax") << qVariantFromValue(SCHAR_MAX) << qVariantFromValue(UINT_MAX) << -1; - QTest::newRow("ucharmax+intmax") << qVariantFromValue(UCHAR_MAX) << qVariantFromValue(INT_MAX) << -1; - QTest::newRow("ucharmax+uintmax") << qVariantFromValue(UCHAR_MAX) << qVariantFromValue(UINT_MAX) << -1; - QTest::newRow("shortmax+intmax") << qVariantFromValue(SHRT_MAX) << qVariantFromValue(INT_MAX) << -1; - QTest::newRow("shortmax+uintmax") << qVariantFromValue(SHRT_MAX) << qVariantFromValue(UINT_MAX) << -1; - QTest::newRow("ushortmax+intmax") << qVariantFromValue(USHRT_MAX) << qVariantFromValue(INT_MAX) << -1; - QTest::newRow("ushortmax+uintmax") << qVariantFromValue(USHRT_MAX) << qVariantFromValue(UINT_MAX) << -1; - - QTest::newRow("intmin+qlonglongmin") << qVariantFromValue(INT_MIN) << qVariantFromValue(LLONG_MIN) << +1; - QTest::newRow("intmax+uintmax") << qVariantFromValue(INT_MAX) << qVariantFromValue(UINT_MAX) << -1; - QTest::newRow("intmax+qlonglongmax") << qVariantFromValue(INT_MAX) << qVariantFromValue(LLONG_MAX) << -1; - QTest::newRow("uintmax+qlonglongmax") << qVariantFromValue(UINT_MAX) << qVariantFromValue(LLONG_MAX) << -1; - QTest::newRow("intmax+qulonglongmax") << qVariantFromValue(INT_MAX) << qVariantFromValue(ULLONG_MAX) << -1; - QTest::newRow("qlonglongmax+qulonglongmax") << qVariantFromValue(LLONG_MAX) << qVariantFromValue(ULLONG_MAX) << -1; - QTest::newRow("uintmax+qlonglongmin") << qVariantFromValue(UINT_MAX) << qVariantFromValue(LLONG_MIN) << +1; + QTest::newRow("charmax+intmax") << QVariant::fromValue(CHAR_MAX) << QVariant::fromValue(INT_MAX) << -1; + QTest::newRow("charmax+uintmax") << QVariant::fromValue(CHAR_MAX) << QVariant::fromValue(UINT_MAX) << -1; + QTest::newRow("scharmax+intmax") << QVariant::fromValue(SCHAR_MAX) << QVariant::fromValue(INT_MAX) << -1; + QTest::newRow("scharmax+uintmax") << QVariant::fromValue(SCHAR_MAX) << QVariant::fromValue(UINT_MAX) << -1; + QTest::newRow("ucharmax+intmax") << QVariant::fromValue(UCHAR_MAX) << QVariant::fromValue(INT_MAX) << -1; + QTest::newRow("ucharmax+uintmax") << QVariant::fromValue(UCHAR_MAX) << QVariant::fromValue(UINT_MAX) << -1; + QTest::newRow("shortmax+intmax") << QVariant::fromValue(SHRT_MAX) << QVariant::fromValue(INT_MAX) << -1; + QTest::newRow("shortmax+uintmax") << QVariant::fromValue(SHRT_MAX) << QVariant::fromValue(UINT_MAX) << -1; + QTest::newRow("ushortmax+intmax") << QVariant::fromValue(USHRT_MAX) << QVariant::fromValue(INT_MAX) << -1; + QTest::newRow("ushortmax+uintmax") << QVariant::fromValue(USHRT_MAX) << QVariant::fromValue(UINT_MAX) << -1; + + QTest::newRow("intmin+qlonglongmin") << QVariant::fromValue(INT_MIN) << QVariant::fromValue(LLONG_MIN) << +1; + QTest::newRow("intmax+uintmax") << QVariant::fromValue(INT_MAX) << QVariant::fromValue(UINT_MAX) << -1; + QTest::newRow("intmax+qlonglongmax") << QVariant::fromValue(INT_MAX) << QVariant::fromValue(LLONG_MAX) << -1; + QTest::newRow("uintmax+qlonglongmax") << QVariant::fromValue(UINT_MAX) << QVariant::fromValue(LLONG_MAX) << -1; + QTest::newRow("intmax+qulonglongmax") << QVariant::fromValue(INT_MAX) << QVariant::fromValue(ULLONG_MAX) << -1; + QTest::newRow("qlonglongmax+qulonglongmax") << QVariant::fromValue(LLONG_MAX) << QVariant::fromValue(ULLONG_MAX) << -1; + QTest::newRow("uintmax+qlonglongmin") << QVariant::fromValue(UINT_MAX) << QVariant::fromValue(LLONG_MIN) << +1; // check for no sign-extension issues - QTest::newRow("ushortmax+intzero") << qVariantFromValue(USHRT_MAX) << qVariantFromValue(0) << +1; - QTest::newRow("ushortmax+qlonglongzero") << qVariantFromValue(USHRT_MAX) << qVariantFromValue(Q_INT64_C(0)) << +1; - QTest::newRow("uintmax+qlonglongzero") << qVariantFromValue(UINT_MAX) << qVariantFromValue(Q_INT64_C(0)) << +1; + QTest::newRow("ushortmax+intzero") << QVariant::fromValue(USHRT_MAX) << QVariant::fromValue(0) << +1; + QTest::newRow("ushortmax+qlonglongzero") << QVariant::fromValue(USHRT_MAX) << QVariant::fromValue(Q_INT64_C(0)) << +1; + QTest::newRow("uintmax+qlonglongzero") << QVariant::fromValue(UINT_MAX) << QVariant::fromValue(Q_INT64_C(0)) << +1; // sign changes // the tests below check that a signed negative number sign-changes to a non-zero unsigned number and that // signed -1 sign-changes to unsigned maximum (all bits set, ~0). This works on two's complement machines // (all that Qt supports), and would also work on one's complement. if (std::numeric_limits<char>::is_signed) { - QTest::newRow("signchange-char+uint") << qVariantFromValue(char(-1)) << qVariantFromValue(0U) << +1; - QTest::newRow("signchange-char+uintmax") << qVariantFromValue(char(-1)) << qVariantFromValue(UINT_MAX) << 0; - QTest::newRow("signchange-charmin+uint") << qVariantFromValue(CHAR_MIN) << qVariantFromValue(0U) << +1; - QTest::newRow("signchange-char+qulonglong") << qVariantFromValue(char(-1)) << qVariantFromValue(Q_UINT64_C(0)) << +1; - QTest::newRow("signchange-char+qulonglongmax") << qVariantFromValue(char(-1)) << qVariantFromValue(ULLONG_MAX) << 0; - QTest::newRow("signchange-charmin+qulonglong") << qVariantFromValue(CHAR_MIN) << qVariantFromValue(Q_UINT64_C(0)) << +1; - } - QTest::newRow("signchange-schar+uint") << qVariantFromValue(schar(-1)) << qVariantFromValue(0U) << +1; - QTest::newRow("signchange-schar+uintmax") << qVariantFromValue(schar(-1)) << qVariantFromValue(UINT_MAX) << 0; - QTest::newRow("signchange-scharmin+uint") << qVariantFromValue(SCHAR_MIN) << qVariantFromValue(0U) << +1; - QTest::newRow("signchange-schar+qulonglong") << qVariantFromValue(schar(-1)) << qVariantFromValue(Q_UINT64_C(0)) << +1; - QTest::newRow("signchange-schar+qulonglongmax") << qVariantFromValue(schar(-1)) << qVariantFromValue(ULLONG_MAX) << 0; - QTest::newRow("signchange-scharmin+qulonglong") << qVariantFromValue(SCHAR_MIN) << qVariantFromValue(Q_UINT64_C(0)) << +1; - QTest::newRow("signchange-short+uint") << qVariantFromValue(short(-1)) << qVariantFromValue(0U) << +1; - QTest::newRow("signchange-short+uintmax") << qVariantFromValue(short(-1)) << qVariantFromValue(UINT_MAX) << 0; - QTest::newRow("signchange-shortmin+uint") << qVariantFromValue(SHRT_MIN) << qVariantFromValue(0U) << +1; - QTest::newRow("signchange-short+qulonglong") << qVariantFromValue(short(-1)) << qVariantFromValue(Q_UINT64_C(0)) << +1; - QTest::newRow("signchange-short+qulonglongmax") << qVariantFromValue(short(-1)) << qVariantFromValue(ULLONG_MAX) << 0; - QTest::newRow("signchange-shortmin+qulonglong") << qVariantFromValue(SHRT_MIN) << qVariantFromValue(Q_UINT64_C(0)) << +1; - QTest::newRow("signchange-int+uint") << qVariantFromValue(-1) << qVariantFromValue(0U) << +1; - QTest::newRow("signchange-int+uintmax") << qVariantFromValue(-1) << qVariantFromValue(UINT_MAX) << 0; - QTest::newRow("signchange-intmin+uint") << qVariantFromValue(INT_MIN) << qVariantFromValue(0U) << +1; - QTest::newRow("signchange-int+qulonglong") << qVariantFromValue(-1) << qVariantFromValue(Q_UINT64_C(0)) << +1; - QTest::newRow("signchange-int+qulonglongmax") << qVariantFromValue(-1) << qVariantFromValue(ULLONG_MAX) << 0; - QTest::newRow("signchange-intmin+qulonglong") << qVariantFromValue(INT_MIN) << qVariantFromValue(Q_UINT64_C(0)) << +1; + QTest::newRow("signchange-char+uint") << QVariant::fromValue(char(-1)) << QVariant::fromValue(0U) << +1; + QTest::newRow("signchange-char+uintmax") << QVariant::fromValue(char(-1)) << QVariant::fromValue(UINT_MAX) << 0; + QTest::newRow("signchange-charmin+uint") << QVariant::fromValue(CHAR_MIN) << QVariant::fromValue(0U) << +1; + QTest::newRow("signchange-char+qulonglong") << QVariant::fromValue(char(-1)) << QVariant::fromValue(Q_UINT64_C(0)) << +1; + QTest::newRow("signchange-char+qulonglongmax") << QVariant::fromValue(char(-1)) << QVariant::fromValue(ULLONG_MAX) << 0; + QTest::newRow("signchange-charmin+qulonglong") << QVariant::fromValue(CHAR_MIN) << QVariant::fromValue(Q_UINT64_C(0)) << +1; + } + QTest::newRow("signchange-schar+uint") << QVariant::fromValue(schar(-1)) << QVariant::fromValue(0U) << +1; + QTest::newRow("signchange-schar+uintmax") << QVariant::fromValue(schar(-1)) << QVariant::fromValue(UINT_MAX) << 0; + QTest::newRow("signchange-scharmin+uint") << QVariant::fromValue(SCHAR_MIN) << QVariant::fromValue(0U) << +1; + QTest::newRow("signchange-schar+qulonglong") << QVariant::fromValue(schar(-1)) << QVariant::fromValue(Q_UINT64_C(0)) << +1; + QTest::newRow("signchange-schar+qulonglongmax") << QVariant::fromValue(schar(-1)) << QVariant::fromValue(ULLONG_MAX) << 0; + QTest::newRow("signchange-scharmin+qulonglong") << QVariant::fromValue(SCHAR_MIN) << QVariant::fromValue(Q_UINT64_C(0)) << +1; + QTest::newRow("signchange-short+uint") << QVariant::fromValue(short(-1)) << QVariant::fromValue(0U) << +1; + QTest::newRow("signchange-short+uintmax") << QVariant::fromValue(short(-1)) << QVariant::fromValue(UINT_MAX) << 0; + QTest::newRow("signchange-shortmin+uint") << QVariant::fromValue(SHRT_MIN) << QVariant::fromValue(0U) << +1; + QTest::newRow("signchange-short+qulonglong") << QVariant::fromValue(short(-1)) << QVariant::fromValue(Q_UINT64_C(0)) << +1; + QTest::newRow("signchange-short+qulonglongmax") << QVariant::fromValue(short(-1)) << QVariant::fromValue(ULLONG_MAX) << 0; + QTest::newRow("signchange-shortmin+qulonglong") << QVariant::fromValue(SHRT_MIN) << QVariant::fromValue(Q_UINT64_C(0)) << +1; + QTest::newRow("signchange-int+uint") << QVariant::fromValue(-1) << QVariant::fromValue(0U) << +1; + QTest::newRow("signchange-int+uintmax") << QVariant::fromValue(-1) << QVariant::fromValue(UINT_MAX) << 0; + QTest::newRow("signchange-intmin+uint") << QVariant::fromValue(INT_MIN) << QVariant::fromValue(0U) << +1; + QTest::newRow("signchange-int+qulonglong") << QVariant::fromValue(-1) << QVariant::fromValue(Q_UINT64_C(0)) << +1; + QTest::newRow("signchange-int+qulonglongmax") << QVariant::fromValue(-1) << QVariant::fromValue(ULLONG_MAX) << 0; + QTest::newRow("signchange-intmin+qulonglong") << QVariant::fromValue(INT_MIN) << QVariant::fromValue(Q_UINT64_C(0)) << +1; // no qlonglong+uint, since that should promote to qlonglong and then the comparison is signed (tested above) - QTest::newRow("signchange-qlonglong+qulonglong") << qVariantFromValue(Q_INT64_C(-1)) << qVariantFromValue(Q_UINT64_C(0)) << +1; - QTest::newRow("signchange-qlonglong+qulonglongmax") << qVariantFromValue(Q_INT64_C(-1)) << qVariantFromValue(ULLONG_MAX) << 0; - QTest::newRow("signchange-qlonglongmin+qulonglong") << qVariantFromValue(LLONG_MIN) << qVariantFromValue(Q_UINT64_C(0)) << +1; + QTest::newRow("signchange-qlonglong+qulonglong") << QVariant::fromValue(Q_INT64_C(-1)) << QVariant::fromValue(Q_UINT64_C(0)) << +1; + QTest::newRow("signchange-qlonglong+qulonglongmax") << QVariant::fromValue(Q_INT64_C(-1)) << QVariant::fromValue(ULLONG_MAX) << 0; + QTest::newRow("signchange-qlonglongmin+qulonglong") << QVariant::fromValue(LLONG_MIN) << QVariant::fromValue(Q_UINT64_C(0)) << +1; } void tst_QVariant::compareNumbers() const @@ -2865,7 +2873,10 @@ void tst_QVariant::qvariant_cast_QObject_wrapper() } { QFile *f = new QFile(this); +QT_WARNING_PUSH +QT_WARNING_DISABLE_DEPRECATED QWeakPointer<QFile> sp(f); +QT_WARNING_POP QVariant spVar = QVariant::fromValue(sp); QVERIFY(spVar.canConvert<QObject*>()); QCOMPARE(f, spVar.value<QObject*>()); @@ -3945,7 +3956,7 @@ void tst_QVariant::userConversion() QVERIFY(!(QMetaType::hasRegisteredConverterFunction<QString, Convertible>())); Convertible c = { 123 }; - QVariant v = qVariantFromValue(c); + QVariant v = QVariant::fromValue(c); bool ok; v.toInt(&ok); @@ -3979,7 +3990,7 @@ void tst_QVariant::userConversion() QVERIFY(!(QMetaType::hasRegisteredConverterFunction<QString, BigConvertible>())); BigConvertible c = { 123, 0, 0 }; - QVariant v = qVariantFromValue(c); + QVariant v = QVariant::fromValue(c); bool ok; v.toInt(&ok); diff --git a/tests/auto/corelib/mimetypes/qmimetype/tst_qmimetype.cpp b/tests/auto/corelib/mimetypes/qmimetype/tst_qmimetype.cpp index c74bce3b5b..e1357245f3 100644 --- a/tests/auto/corelib/mimetypes/qmimetype/tst_qmimetype.cpp +++ b/tests/auto/corelib/mimetypes/qmimetype/tst_qmimetype.cpp @@ -91,11 +91,7 @@ static QStringList qMimeTypeGlobPatterns() // ------------------------------------------------------------------------------------------------ -#ifndef Q_COMPILER_RVALUE_REFS -QMIMETYPE_BUILDER -#else QMIMETYPE_BUILDER_FROM_RVALUE_REFS -#endif // ------------------------------------------------------------------------------------------------ diff --git a/tests/auto/corelib/serialization/json/tst_qtjson.cpp b/tests/auto/corelib/serialization/json/tst_qtjson.cpp index 083e78375a..1cbe0cae48 100644 --- a/tests/auto/corelib/serialization/json/tst_qtjson.cpp +++ b/tests/auto/corelib/serialization/json/tst_qtjson.cpp @@ -163,7 +163,8 @@ private Q_SLOTS: void streamSerializationQJsonValue(); void streamSerializationQJsonValueEmpty(); void streamVariantSerialization(); - + void escapeSurrogateCodePoints_data(); + void escapeSurrogateCodePoints(); private: QString testDataDir; }; @@ -2754,9 +2755,6 @@ void tst_QtJson::testJsonValueRefDefault() void tst_QtJson::arrayInitializerList() { -#ifndef Q_COMPILER_INITIALIZER_LISTS - QSKIP("initializer_list is enabled only with c++11 support"); -#else QVERIFY(QJsonArray{}.isEmpty()); QCOMPARE(QJsonArray{"one"}.count(), 1); QCOMPARE(QJsonArray{1}.count(), 1); @@ -2802,14 +2800,10 @@ void tst_QtJson::arrayInitializerList() QCOMPARE(QJsonValue(a43["one"]), QJsonValue(1)); } } -#endif } void tst_QtJson::objectInitializerList() { -#ifndef Q_COMPILER_INITIALIZER_LISTS - QSKIP("initializer_list is enabled only with c++11 support"); -#else QVERIFY(QJsonObject{}.isEmpty()); { // one property @@ -2849,7 +2843,6 @@ void tst_QtJson::objectInitializerList() QCOMPARE(QJsonValue(nested[0]), QJsonValue("innerValue")); QCOMPARE(QJsonValue(nested[1]), QJsonValue(2.1)); } -#endif } void tst_QtJson::unicodeKeys() @@ -3093,6 +3086,9 @@ void tst_QtJson::streamSerializationQJsonValue_data() QTest::newRow("string") << QJsonValue{QStringLiteral("bum")}; QTest::newRow("array") << QJsonValue{QJsonArray{12,1,5,6,7}}; QTest::newRow("object") << QJsonValue{QJsonObject{{"foo", 665}, {"bar", 666}}}; + // test json escape sequence + QTest::newRow("array with 0xD800") << QJsonValue(QJsonArray{QString(0xD800)}); + QTest::newRow("array with 0xDF06,0xD834") << QJsonValue(QJsonArray{QString(0xDF06).append(0xD834)}); } void tst_QtJson::streamSerializationQJsonValue() @@ -3181,5 +3177,26 @@ void tst_QtJson::streamVariantSerialization() } } +void tst_QtJson::escapeSurrogateCodePoints_data() +{ + QTest::addColumn<QString>("str"); + QTest::addColumn<QByteArray>("escStr"); + QTest::newRow("0xD800") << QString(0xD800) << QByteArray("\\ud800"); + QTest::newRow("0xDF06,0xD834") << QString(0xDF06).append(0xD834) << QByteArray("\\udf06\\ud834"); +} + +void tst_QtJson::escapeSurrogateCodePoints() +{ + QFETCH(QString, str); + QFETCH(QByteArray, escStr); + QJsonArray array; + array.append(str); + QByteArray buffer; + QDataStream save(&buffer, QIODevice::WriteOnly); + save << array; + // verify the buffer has escaped values + QVERIFY(buffer.contains(escStr)); +} + QTEST_MAIN(tst_QtJson) #include "tst_qtjson.moc" diff --git a/tests/auto/corelib/serialization/qtextstream/readLineStdinProcess/main.cpp b/tests/auto/corelib/serialization/qtextstream/readLineStdinProcess/main.cpp index 41ea5e56f0..2d4aa452ca 100644 --- a/tests/auto/corelib/serialization/qtextstream/readLineStdinProcess/main.cpp +++ b/tests/auto/corelib/serialization/qtextstream/readLineStdinProcess/main.cpp @@ -41,7 +41,7 @@ int main(int argc, char **argv) do { line = qin.readLine(); if (!line.isNull()) - qerr << line << flush; + qerr << line << Qt::flush; } while (!line.isNull()); return 0; } diff --git a/tests/auto/corelib/serialization/qtextstream/tst_qtextstream.cpp b/tests/auto/corelib/serialization/qtextstream/tst_qtextstream.cpp index af97d4a003..c4fb623130 100644 --- a/tests/auto/corelib/serialization/qtextstream/tst_qtextstream.cpp +++ b/tests/auto/corelib/serialization/qtextstream/tst_qtextstream.cpp @@ -245,7 +245,7 @@ private: void runOnExit() { QByteArray buffer; - QTextStream(&buffer) << "This will try to use QTextCodec::codecForLocale" << endl; + QTextStream(&buffer) << "This will try to use QTextCodec::codecForLocale" << Qt::endl; } Q_DESTRUCTOR_FUNCTION(runOnExit) @@ -1506,9 +1506,9 @@ void tst_QTextStream::readStdin() stdinProcess.setReadChannel(QProcess::StandardError); QTextStream stream(&stdinProcess); - stream << "1" << endl; - stream << "2" << endl; - stream << "3" << endl; + stream << "1" << Qt::endl; + stream << "2" << Qt::endl; + stream << "3" << Qt::endl; stdinProcess.closeWriteChannel(); @@ -1534,7 +1534,7 @@ void tst_QTextStream::readAllFromStdin() QTextStream stream(&stdinProcess); stream.setCodec("ISO-8859-1"); - stream << "hello world" << flush; + stream << "hello world" << Qt::flush; stdinProcess.closeWriteChannel(); @@ -1824,7 +1824,7 @@ void tst_QTextStream::utf8IncompleteAtBufferBoundary() out.setFieldWidth(3); for (int i = 0; i < 1000; ++i) { - out << i << lineContents << endl; + out << i << lineContents << Qt::endl; } } data.close(); @@ -2726,7 +2726,7 @@ void tst_QTextStream::generateBOM() QTextStream stream(&file); stream.setCodec(QTextCodec::codecForName("UTF-16LE")); - stream << "Hello" << endl; + stream << "Hello" << Qt::endl; file.close(); QVERIFY(file.open(QFile::ReadOnly)); @@ -2740,7 +2740,7 @@ void tst_QTextStream::generateBOM() QTextStream stream(&file); stream.setCodec(QTextCodec::codecForName("UTF-16LE")); - stream << bom << "Hello" << endl; + stream << Qt::bom << "Hello" << Qt::endl; file.close(); QVERIFY(file.open(QFile::ReadOnly)); diff --git a/tests/auto/corelib/serialization/qxmlstream/tst_qxmlstream.cpp b/tests/auto/corelib/serialization/qxmlstream/tst_qxmlstream.cpp index e4d50607b7..92a0d8bbfa 100644 --- a/tests/auto/corelib/serialization/qxmlstream/tst_qxmlstream.cpp +++ b/tests/auto/corelib/serialization/qxmlstream/tst_qxmlstream.cpp @@ -115,7 +115,7 @@ static QByteArray makeCanonical(const QString &filename, writeDtd << "<!DOCTYPE "; writeDtd << docType; writeDtd << " ["; - writeDtd << endl; + writeDtd << Qt::endl; for (const QXmlStreamNotationDeclaration ¬ation : sorted_by_name(notationDeclarations)) { writeDtd << "<!NOTATION "; writeDtd << notation.name().toString(); @@ -134,11 +134,11 @@ static QByteArray makeCanonical(const QString &filename, } } writeDtd << '>'; - writeDtd << endl; + writeDtd << Qt::endl; } writeDtd << "]>"; - writeDtd << endl; + writeDtd << Qt::endl; writer.writeDTD(dtd); } } else if (reader.isStartElement()) { @@ -740,7 +740,7 @@ QByteArray tst_QXmlStream::readFile(const QString &filename) const auto attributes = reader.attributes(); if (attributes.size()) { for (const QXmlStreamAttribute &attribute : attributes) { - writer << endl << " Attribute("; + writer << Qt::endl << " Attribute("; if (!attribute.name().isEmpty()) writer << " name=\"" << attribute.name().toString() << '"'; if (!attribute.namespaceUri().isEmpty()) @@ -751,37 +751,37 @@ QByteArray tst_QXmlStream::readFile(const QString &filename) writer << " prefix=\"" << attribute.prefix().toString() << '"'; if (!attribute.value().isEmpty()) writer << " value=\"" << attribute.value().toString() << '"'; - writer << " )" << endl; + writer << " )" << Qt::endl; } } const auto namespaceDeclarations = reader.namespaceDeclarations(); if (namespaceDeclarations.size()) { for (const QXmlStreamNamespaceDeclaration &namespaceDeclaration : namespaceDeclarations) { - writer << endl << " NamespaceDeclaration("; + writer << Qt::endl << " NamespaceDeclaration("; if (!namespaceDeclaration.prefix().isEmpty()) writer << " prefix=\"" << namespaceDeclaration.prefix().toString() << '"'; if (!namespaceDeclaration.namespaceUri().isEmpty()) writer << " namespaceUri=\"" << namespaceDeclaration.namespaceUri().toString() << '"'; - writer << " )" << endl; + writer << " )" << Qt::endl; } } const auto notationDeclarations = reader.notationDeclarations(); if (notationDeclarations.size()) { for (const QXmlStreamNotationDeclaration ¬ationDeclaration : notationDeclarations) { - writer << endl << " NotationDeclaration("; + writer << Qt::endl << " NotationDeclaration("; if (!notationDeclaration.name().isEmpty()) writer << " name=\"" << notationDeclaration.name().toString() << '"'; if (!notationDeclaration.systemId().isEmpty()) writer << " systemId=\"" << notationDeclaration.systemId().toString() << '"'; if (!notationDeclaration.publicId().isEmpty()) writer << " publicId=\"" << notationDeclaration.publicId().toString() << '"'; - writer << " )" << endl; + writer << " )" << Qt::endl; } } const auto entityDeclarations = reader.entityDeclarations(); if (entityDeclarations.size()) { for (const QXmlStreamEntityDeclaration &entityDeclaration : entityDeclarations) { - writer << endl << " EntityDeclaration("; + writer << Qt::endl << " EntityDeclaration("; if (!entityDeclaration.name().isEmpty()) writer << " name=\"" << entityDeclaration.name().toString() << '"'; if (!entityDeclaration.notationName().isEmpty()) @@ -792,13 +792,13 @@ QByteArray tst_QXmlStream::readFile(const QString &filename) writer << " publicId=\"" << entityDeclaration.publicId().toString() << '"'; if (!entityDeclaration.value().isEmpty()) writer << " value=\"" << entityDeclaration.value().toString() << '"'; - writer << " )" << endl; + writer << " )" << Qt::endl; } } - writer << " )" << endl; + writer << " )" << Qt::endl; } if (reader.hasError()) - writer << "ERROR: " << reader.errorString() << endl; + writer << "ERROR: " << reader.errorString() << Qt::endl; return outarray; } @@ -1169,7 +1169,7 @@ int main(int argc, char *argv[]) bool error = false; QByteArray canonical = makeCanonical(argv[2], "doc", error); QTextStream myStdOut(stdout); - myStdOut << canonical << endl; + myStdOut << canonical << Qt::endl; exit(0); } diff --git a/tests/auto/corelib/statemachine/qstatemachine/tst_qstatemachine.cpp b/tests/auto/corelib/statemachine/qstatemachine/tst_qstatemachine.cpp index 55a672aae1..0312cff5da 100644 --- a/tests/auto/corelib/statemachine/qstatemachine/tst_qstatemachine.cpp +++ b/tests/auto/corelib/statemachine/qstatemachine/tst_qstatemachine.cpp @@ -336,7 +336,9 @@ void tst_QStateMachine::transitionToRootState() TEST_ACTIVE_CHANGED(initialState, 1); machine.postEvent(new QEvent(QEvent::User)); - QTest::ignoreMessage(QtWarningMsg, "Unrecoverable error detected in running state machine: No common ancestor for targets and source of transition from state 'initial'"); + QTest::ignoreMessage(QtWarningMsg, + "Unrecoverable error detected in running state machine: " + "Child mode of state machine 'machine' is not 'ExclusiveStates'!"); QCoreApplication::processEvents(); QVERIFY(machine.configuration().isEmpty()); QVERIFY(!machine.isRunning()); @@ -1061,7 +1063,8 @@ void tst_QStateMachine::transitionToStateNotInGraph() initialState->addTransition(&independentState); machine.start(); - QTest::ignoreMessage(QtWarningMsg, "Unrecoverable error detected in running state machine: No common ancestor for targets and source of transition from state 'initialState'"); + QTest::ignoreMessage(QtWarningMsg, "Unrecoverable error detected in running state machine: " + "Child mode of state machine '' is not 'ExclusiveStates'!"); QCoreApplication::processEvents(); QCOMPARE(machine.isRunning(), false); @@ -2099,6 +2102,8 @@ void tst_QStateMachine::parallelRootState() QSignalSpy finishedSpy(&machine, &QStateMachine::finished); QVERIFY(finishedSpy.isValid()); machine.start(); + QTest::ignoreMessage(QtWarningMsg, "Unrecoverable error detected in running state machine: " + "Child mode of state machine '' is not 'ExclusiveStates'!"); QTRY_COMPARE(startedSpy.count(), 1); QCOMPARE(machine.configuration().size(), 4); QVERIFY(machine.configuration().contains(s1)); @@ -3310,14 +3315,15 @@ void tst_QStateMachine::targetStateWithNoParent() QVERIFY(runningSpy.isValid()); machine.start(); - QTest::ignoreMessage(QtWarningMsg, "Unrecoverable error detected in running state machine: No common ancestor for targets and source of transition from state 's1'"); + QTest::ignoreMessage(QtWarningMsg, "Unrecoverable error detected in running state machine: " + "Child mode of state machine '' is not 'ExclusiveStates'!"); TEST_ACTIVE_CHANGED(s1, 2); QTRY_COMPARE(startedSpy.count(), 1); QCOMPARE(machine.isRunning(), false); QCOMPARE(stoppedSpy.count(), 1); QCOMPARE(finishedSpy.count(), 0); TEST_RUNNING_CHANGED_STARTED_STOPPED; - QCOMPARE(machine.error(), QStateMachine::NoCommonAncestorForTransitionError); + QCOMPARE(machine.error(), QStateMachine::StateMachineChildModeSetToParallelError); } void tst_QStateMachine::targetStateDeleted() diff --git a/tests/auto/corelib/tools/collections/tst_collections.cpp b/tests/auto/corelib/tools/collections/tst_collections.cpp index 104de4d783..734b018b39 100644 --- a/tests/auto/corelib/tools/collections/tst_collections.cpp +++ b/tests/auto/corelib/tools/collections/tst_collections.cpp @@ -580,73 +580,73 @@ void tst_Collections::list() list1 << 0 << 1 << 2 << 3; list1.removeFirst(); - list1.swap(0, 0); + list1.swapItemsAt(0, 0); QVERIFY(list1 == QList<int>() << 1 << 2 << 3); - list1.swap(1, 1); + list1.swapItemsAt(1, 1); QVERIFY(list1 == QList<int>() << 1 << 2 << 3); - list1.swap(2, 2); + list1.swapItemsAt(2, 2); QVERIFY(list1 == QList<int>() << 1 << 2 << 3); - list1.swap(0, 1); + list1.swapItemsAt(0, 1); QVERIFY(list1 == QList<int>() << 2 << 1 << 3); - list1.swap(0, 2); + list1.swapItemsAt(0, 2); QVERIFY(list1 == QList<int>() << 3 << 1 << 2); - list1.swap(1, 2); + list1.swapItemsAt(1, 2); QVERIFY(list1 == QList<int>() << 3 << 2 << 1); - list1.swap(1, 2); + list1.swapItemsAt(1, 2); QVERIFY(list1 == QList<int>() << 3 << 1 << 2); QList<QString> list2; list2 << "1" << "2" << "3"; - list2.swap(0, 0); + list2.swapItemsAt(0, 0); QVERIFY(list2 == QList<QString>() << "1" << "2" << "3"); - list2.swap(1, 1); + list2.swapItemsAt(1, 1); QVERIFY(list2 == QList<QString>() << "1" << "2" << "3"); - list2.swap(2, 2); + list2.swapItemsAt(2, 2); QVERIFY(list2 == QList<QString>() << "1" << "2" << "3"); - list2.swap(0, 1); + list2.swapItemsAt(0, 1); QVERIFY(list2 == QList<QString>() << "2" << "1" << "3"); - list2.swap(0, 2); + list2.swapItemsAt(0, 2); QVERIFY(list2 == QList<QString>() << "3" << "1" << "2"); - list2.swap(1, 2); + list2.swapItemsAt(1, 2); QVERIFY(list2 == QList<QString>() << "3" << "2" << "1"); - list2.swap(1, 2); + list2.swapItemsAt(1, 2); QVERIFY(list2 == QList<QString>() << "3" << "1" << "2"); QList<double> list3; list3 << 1.0 << 2.0 << 3.0; - list3.swap(0, 0); + list3.swapItemsAt(0, 0); QVERIFY(list3 == QList<double>() << 1.0 << 2.0 << 3.0); - list3.swap(1, 1); + list3.swapItemsAt(1, 1); QVERIFY(list3 == QList<double>() << 1.0 << 2.0 << 3.0); - list3.swap(2, 2); + list3.swapItemsAt(2, 2); QVERIFY(list3 == QList<double>() << 1.0 << 2.0 << 3.0); - list3.swap(0, 1); + list3.swapItemsAt(0, 1); QVERIFY(list3 == QList<double>() << 2.0 << 1.0 << 3.0); - list3.swap(0, 2); + list3.swapItemsAt(0, 2); QVERIFY(list3 == QList<double>() << 3.0 << 1.0 << 2.0); - list3.swap(1, 2); + list3.swapItemsAt(1, 2); QVERIFY(list3 == QList<double>() << 3.0 << 2.0 << 1.0); - list3.swap(1, 2); + list3.swapItemsAt(1, 2); QVERIFY(list3 == QList<double>() << 3.0 << 1.0 << 2.0); } @@ -2531,14 +2531,18 @@ void tst_Collections::conversions() QCOMPARE(list2.size(), 4); QVERIFY(list2 == (QList<QString>() << STUFF)); +#if QT_VERSION < QT_VERSION_CHECK(6,0,0) QSet<QString> set1 = list1.toSet(); +#else + QSet<QString> set1(list1.begin(), list1.end()); +#endif QCOMPARE(set1.size(), 3); QVERIFY(set1.contains("A")); QVERIFY(set1.contains("B")); QVERIFY(set1.contains("C")); QVERIFY(!set1.contains("D")); - QList<QString> list3 = set1.toList(); + QList<QString> list3 = set1.values(); QCOMPARE(list3.size(), 3); QVERIFY(list3.contains("A")); QVERIFY(list3.contains("B")); @@ -2546,9 +2550,11 @@ void tst_Collections::conversions() QVERIFY(!list3.contains("D")); QVERIFY(QList<int>().toVector().isEmpty()); - QVERIFY(QList<int>().toSet().isEmpty()); QVERIFY(QVector<int>().toList().isEmpty()); +#if QT_VERSION < QT_VERSION_CHECK(6,0,0) + QVERIFY(QList<int>().toSet().isEmpty()); QVERIFY(QSet<int>().toList().isEmpty()); +#endif } { @@ -2563,14 +2569,22 @@ void tst_Collections::conversions() QCOMPARE(list2.size(), 4); QVERIFY(list2 == (QList<QString>() << STUFF)); +#if QT_VERSION < QT_VERSION_CHECK(6,0,0) QSet<QString> set1 = QSet<QString>::fromList(list1); +#else + QSet<QString> set1(list1.begin(), list1.end()); +#endif QCOMPARE(set1.size(), 3); QVERIFY(set1.contains("A")); QVERIFY(set1.contains("B")); QVERIFY(set1.contains("C")); QVERIFY(!set1.contains("D")); +#if QT_VERSION < QT_VERSION_CHECK(6,0,0) QList<QString> list3 = QList<QString>::fromSet(set1); +#else + QList<QString> list3 = set1.values(); +#endif QCOMPARE(list3.size(), 3); QVERIFY(list3.contains("A")); QVERIFY(list3.contains("B")); @@ -2578,9 +2592,11 @@ void tst_Collections::conversions() QVERIFY(!list3.contains("D")); QVERIFY(QVector<int>::fromList(QList<int>()).isEmpty()); - QVERIFY(QSet<int>::fromList(QList<int>()).isEmpty()); QVERIFY(QList<int>::fromVector(QVector<int>()).isEmpty()); +#if QT_VERSION < QT_VERSION_CHECK(6,0,0) + QVERIFY(QSet<int>::fromList(QList<int>()).isEmpty()); QVERIFY(QList<int>::fromSet(QSet<int>()).isEmpty()); +#endif } #undef STUFF } @@ -2776,15 +2792,21 @@ void tst_Collections::vector_stl() for (int i = 0; i < elements.count(); ++i) vector << elements.at(i); +#if QT_VERSION < QT_VERSION_CHECK(6,0,0) std::vector<QString> stdVector = vector.toStdVector(); - +#else + std::vector<QString> stdVector(vector.begin(), vector.end()); +#endif QCOMPARE(int(stdVector.size()), elements.size()); std::vector<QString>::const_iterator it = stdVector.begin(); for (uint j = 0; j < stdVector.size() && it != stdVector.end(); ++j, ++it) QCOMPARE(*it, vector[j]); +#if QT_VERSION < QT_VERSION_CHECK(6,0,0) QCOMPARE(QVector<QString>::fromStdVector(stdVector), vector); +#endif + QCOMPARE(QVector<QString>(stdVector.begin(), stdVector.end()), vector); } void tst_Collections::linkedlist_stl_data() @@ -2830,7 +2852,11 @@ void tst_Collections::list_stl() for (int i = 0; i < elements.count(); ++i) list << elements.at(i); +#if QT_VERSION < QT_VERSION_CHECK(6,0,0) std::list<QString> stdList = list.toStdList(); +#else + std::list<QString> stdList(list.begin(), list.end()); +#endif QCOMPARE(int(stdList.size()), elements.size()); @@ -2838,7 +2864,10 @@ void tst_Collections::list_stl() for (uint j = 0; j < stdList.size() && it != stdList.end(); ++j, ++it) QCOMPARE(*it, list[j]); +#if QT_VERSION < QT_VERSION_CHECK(6,0,0) QCOMPARE(QList<QString>::fromStdList(stdList), list); +#endif + QCOMPARE(QList<QString>(stdList.begin(), stdList.end()), list); } template <typename T> diff --git a/tests/auto/corelib/tools/containerapisymmetry/tst_containerapisymmetry.cpp b/tests/auto/corelib/tools/containerapisymmetry/tst_containerapisymmetry.cpp index 3b8111f1a3..4b085d387d 100644 --- a/tests/auto/corelib/tools/containerapisymmetry/tst_containerapisymmetry.cpp +++ b/tests/auto/corelib/tools/containerapisymmetry/tst_containerapisymmetry.cpp @@ -34,13 +34,446 @@ #include "qstring.h" #include "qvarlengtharray.h" #include "qvector.h" +#include "qhash.h" +#include "qdebug.h" +#include <algorithm> +#include <functional> #include <vector> // for reference +#include <list> +#include <set> +#include <map> + +// MSVC has these containers from the Standard Library, but it lacks +// a __has_include mechanism (that we need to use for other stdlibs). +// For the sake of increasing our test coverage, work around the issue. + +#ifdef Q_CC_MSVC +#define COMPILER_HAS_STDLIB_INCLUDE(x) 1 +#else +#define COMPILER_HAS_STDLIB_INCLUDE(x) QT_HAS_INCLUDE(x) +#endif + +#if COMPILER_HAS_STDLIB_INCLUDE(<forward_list>) +#include <forward_list> +#endif +#if COMPILER_HAS_STDLIB_INCLUDE(<unordered_set>) +#include <unordered_set> +#endif +#if COMPILER_HAS_STDLIB_INCLUDE(<unordered_map>) +#include <unordered_map> +#endif + +struct Movable +{ + explicit Movable(int i = 0) Q_DECL_NOTHROW + : i(i) + { + ++instanceCount; + } + + Movable(const Movable &m) + : i(m.i) + { + ++instanceCount; + } + + ~Movable() + { + --instanceCount; + } + + int i; + static int instanceCount; +}; + +int Movable::instanceCount = 0; +bool operator==(Movable lhs, Movable rhs) Q_DECL_NOTHROW { return lhs.i == rhs.i; } +bool operator!=(Movable lhs, Movable rhs) Q_DECL_NOTHROW { return lhs.i != rhs.i; } +bool operator<(Movable lhs, Movable rhs) Q_DECL_NOTHROW { return lhs.i < rhs.i; } + +uint qHash(Movable m, uint seed = 0) Q_DECL_NOTHROW { return qHash(m.i, seed); } +QDebug &operator<<(QDebug &d, Movable m) +{ + const QDebugStateSaver saver(d); + return d.nospace() << "Movable(" << m.i << ")"; +} + +QT_BEGIN_NAMESPACE +Q_DECLARE_TYPEINFO(Movable, Q_MOVABLE_TYPE); +QT_END_NAMESPACE + +struct Complex +{ + explicit Complex(int i = 0) Q_DECL_NOTHROW + : i(i) + { + ++instanceCount; + } + + Complex(const Complex &c) + : i(c.i) + { + ++instanceCount; + } + + ~Complex() + { + --instanceCount; + } + + int i; + static int instanceCount; +}; + +int Complex::instanceCount = 0; +bool operator==(Complex lhs, Complex rhs) Q_DECL_NOTHROW { return lhs.i == rhs.i; } +bool operator!=(Complex lhs, Complex rhs) Q_DECL_NOTHROW { return lhs.i != rhs.i; } +bool operator<(Complex lhs, Complex rhs) Q_DECL_NOTHROW { return lhs.i < rhs.i; } + +uint qHash(Complex c, uint seed = 0) Q_DECL_NOTHROW { return qHash(c.i, seed); } +QDebug &operator<<(QDebug &d, Complex c) +{ + const QDebugStateSaver saver(d); + return d.nospace() << "Complex(" << c.i << ")"; +} + + +struct DuplicateStrategyTestType +{ + explicit DuplicateStrategyTestType(int i = 0) Q_DECL_NOTHROW + : i(i), + j(++counter) + { + } + + int i; + int j; + + static int counter; +}; + +int DuplicateStrategyTestType::counter = 0; + +// only look at the i member, not j. j allows us to identify which instance +// gets inserted in containers that don't allow for duplicates +bool operator==(DuplicateStrategyTestType lhs, DuplicateStrategyTestType rhs) Q_DECL_NOTHROW +{ + return lhs.i == rhs.i; +} + +bool operator!=(DuplicateStrategyTestType lhs, DuplicateStrategyTestType rhs) Q_DECL_NOTHROW +{ + return lhs.i != rhs.i; +} + +bool operator<(DuplicateStrategyTestType lhs, DuplicateStrategyTestType rhs) Q_DECL_NOTHROW +{ + return lhs.i < rhs.i; +} + +uint qHash(DuplicateStrategyTestType c, uint seed = 0) Q_DECL_NOTHROW +{ + return qHash(c.i, seed); +} + +bool reallyEqual(DuplicateStrategyTestType lhs, DuplicateStrategyTestType rhs) Q_DECL_NOTHROW +{ + return lhs.i == rhs.i && lhs.j == rhs.j; +} + +QDebug &operator<<(QDebug &d, DuplicateStrategyTestType c) +{ + const QDebugStateSaver saver(d); + return d.nospace() << "DuplicateStrategyTestType(" << c.i << "," << c.j << ")"; +} + + +namespace std { +template<> +struct hash<Movable> +{ + std::size_t operator()(Movable m) const Q_DECL_NOTHROW + { + return hash<int>()(m.i); + } +}; + +template<> +struct hash<Complex> +{ + std::size_t operator()(Complex m) const Q_DECL_NOTHROW + { + return hash<int>()(m.i); + } +}; + +template<> +struct hash<DuplicateStrategyTestType> +{ + std::size_t operator()(DuplicateStrategyTestType m) const Q_DECL_NOTHROW + { + return hash<int>()(m.i); + } +}; +} + +// work around the fact that QVarLengthArray has a non-type +// template parameter, and that breaks non_associative_container_duplicates_strategy +template<typename T> +class VarLengthArray : public QVarLengthArray<T> +{ +public: +#ifdef Q_COMPILER_INHERITING_CONSTRUCTORS + using QVarLengthArray<T>::QVarLengthArray; +#else + template<typename InputIterator> + VarLengthArray(InputIterator first, InputIterator last) + : QVarLengthArray<T>(first, last) + { + } + + VarLengthArray(std::initializer_list<T> args) + : QVarLengthArray<T>(args) + { + } +#endif +}; class tst_ContainerApiSymmetry : public QObject { Q_OBJECT + int m_movableInstanceCount; + int m_complexInstanceCount; + +private Q_SLOTS: + void init(); + void cleanup(); + +private: + template <typename Container> + void ranged_ctor_non_associative_impl() const; + + template<template<typename ... T> class Container> + void non_associative_container_duplicates_strategy() const; + + template <typename Container> + void ranged_ctor_associative_impl() const; + +private Q_SLOTS: + // non associative + void ranged_ctor_std_vector_int() { ranged_ctor_non_associative_impl<std::vector<int>>(); } + void ranged_ctor_std_vector_char() { ranged_ctor_non_associative_impl<std::vector<char>>(); } + void ranged_ctor_std_vector_QChar() { ranged_ctor_non_associative_impl<std::vector<QChar>>(); } + void ranged_ctor_std_vector_Movable() { ranged_ctor_non_associative_impl<std::vector<Movable>>(); } + void ranged_ctor_std_vector_Complex() { ranged_ctor_non_associative_impl<std::vector<Complex>>(); } + void ranged_ctor_std_vector_duplicates_strategy() { non_associative_container_duplicates_strategy<std::vector>(); } + + void ranged_ctor_QVector_int() { ranged_ctor_non_associative_impl<QVector<int>>(); } + void ranged_ctor_QVector_char() { ranged_ctor_non_associative_impl<QVector<char>>(); } + void ranged_ctor_QVector_QChar() { ranged_ctor_non_associative_impl<QVector<QChar>>(); } + void ranged_ctor_QVector_Movable() { ranged_ctor_non_associative_impl<QVector<Movable>>(); } + void ranged_ctor_QVector_Complex() { ranged_ctor_non_associative_impl<QVector<Complex>>(); } + void ranged_ctor_QVector_duplicates_strategy() { non_associative_container_duplicates_strategy<QVector>(); } + + void ranged_ctor_QVarLengthArray_int() { ranged_ctor_non_associative_impl<QVarLengthArray<int>>(); } + void ranged_ctor_QVarLengthArray_Movable() { ranged_ctor_non_associative_impl<QVarLengthArray<Movable>>(); } + void ranged_ctor_QVarLengthArray_Complex() { ranged_ctor_non_associative_impl<QVarLengthArray<Complex>>(); } + void ranged_ctor_QVarLengthArray_duplicates_strategy() { non_associative_container_duplicates_strategy<VarLengthArray>(); } // note the VarLengthArray passed + + void ranged_ctor_QList_int() { ranged_ctor_non_associative_impl<QList<int>>(); } + void ranged_ctor_QList_Movable() { ranged_ctor_non_associative_impl<QList<Movable>>(); } + void ranged_ctor_QList_Complex() { ranged_ctor_non_associative_impl<QList<Complex>>(); } + void ranged_ctor_QList_duplicates_strategy() { non_associative_container_duplicates_strategy<QList>(); } + + void ranged_ctor_std_list_int() { ranged_ctor_non_associative_impl<std::list<int>>(); } + void ranged_ctor_std_list_Movable() { ranged_ctor_non_associative_impl<std::list<Movable>>(); } + void ranged_ctor_std_list_Complex() { ranged_ctor_non_associative_impl<std::list<Complex>>(); } + void ranged_ctor_std_list_duplicates_strategy() { non_associative_container_duplicates_strategy<std::list>(); } + + void ranged_ctor_std_forward_list_int() { +#if COMPILER_HAS_STDLIB_INCLUDE(<forward_list>) + ranged_ctor_non_associative_impl<std::forward_list<int>>(); +#else + QSKIP("<forward_list> is needed for this test"); +#endif + } + + void ranged_ctor_std_forward_list_Movable() { +#if COMPILER_HAS_STDLIB_INCLUDE(<forward_list>) + ranged_ctor_non_associative_impl<std::forward_list<Movable>>(); +#else + QSKIP("<forward_list> is needed for this test"); +#endif + } + + void ranged_ctor_std_forward_list_Complex() { +#if COMPILER_HAS_STDLIB_INCLUDE(<forward_list>) + ranged_ctor_non_associative_impl<std::forward_list<Complex>>(); +#else + QSKIP("<forward_list> is needed for this test"); +#endif + } + + void ranged_ctor_std_forward_list_duplicates_strategy() { +#if COMPILER_HAS_STDLIB_INCLUDE(<forward_list>) + non_associative_container_duplicates_strategy<std::forward_list>(); +#else + QSKIP("<forward_list> is needed for this test"); +#endif + } + + void ranged_ctor_QLinkedList_int() { ranged_ctor_non_associative_impl<QLinkedList<int>>(); } + void ranged_ctor_QLinkedList_Movable() { ranged_ctor_non_associative_impl<QLinkedList<Movable>>(); } + void ranged_ctor_QLinkedList_Complex() { ranged_ctor_non_associative_impl<QLinkedList<Complex>>(); } + void ranged_ctor_QLinkedList_duplicates_strategy() { non_associative_container_duplicates_strategy<QLinkedList>(); } + + void ranged_ctor_std_set_int() { ranged_ctor_non_associative_impl<std::set<int>>(); } + void ranged_ctor_std_set_Movable() { ranged_ctor_non_associative_impl<std::set<Movable>>(); } + void ranged_ctor_std_set_Complex() { ranged_ctor_non_associative_impl<std::set<Complex>>(); } + void ranged_ctor_std_set_duplicates_strategy() { non_associative_container_duplicates_strategy<std::set>(); } + + void ranged_ctor_std_multiset_int() { ranged_ctor_non_associative_impl<std::multiset<int>>(); } + void ranged_ctor_std_multiset_Movable() { ranged_ctor_non_associative_impl<std::multiset<Movable>>(); } + void ranged_ctor_std_multiset_Complex() { ranged_ctor_non_associative_impl<std::multiset<Complex>>(); } + void ranged_ctor_std_multiset_duplicates_strategy() { non_associative_container_duplicates_strategy<std::multiset>(); } + + void ranged_ctor_std_unordered_set_int() { +#if COMPILER_HAS_STDLIB_INCLUDE(<unordered_set>) + ranged_ctor_non_associative_impl<std::unordered_set<int>>(); +#else + QSKIP("<unordered_set> is needed for this test"); +#endif + } + + void ranged_ctor_std_unordered_set_Movable() { +#if COMPILER_HAS_STDLIB_INCLUDE(<unordered_set>) + ranged_ctor_non_associative_impl<std::unordered_set<Movable>>(); +#else + QSKIP("<unordered_set> is needed for this test"); +#endif + } + + void ranged_ctor_std_unordered_set_Complex() { +#if COMPILER_HAS_STDLIB_INCLUDE(<unordered_set>) + ranged_ctor_non_associative_impl<std::unordered_set<Complex>>(); +#else + QSKIP("<unordered_set> is needed for this test"); +#endif + } + + void ranged_ctor_unordered_set_duplicates_strategy() { +#if COMPILER_HAS_STDLIB_INCLUDE(<unordered_set>) + non_associative_container_duplicates_strategy<std::unordered_set>(); +#else + QSKIP("<unordered_set> is needed for this test"); +#endif + } + + + void ranged_ctor_std_unordered_multiset_int() { +#if COMPILER_HAS_STDLIB_INCLUDE(<unordered_set>) + ranged_ctor_non_associative_impl<std::unordered_multiset<int>>(); +#else + QSKIP("<unordered_set> is needed for this test"); +#endif + } + + void ranged_ctor_std_unordered_multiset_Movable() { +#if COMPILER_HAS_STDLIB_INCLUDE(<unordered_set>) + ranged_ctor_non_associative_impl<std::unordered_multiset<Movable>>(); +#else + QSKIP("<unordered_set> is needed for this test"); +#endif + } + + void ranged_ctor_std_unordered_multiset_Complex() { +#if COMPILER_HAS_STDLIB_INCLUDE(<unordered_set>) + ranged_ctor_non_associative_impl<std::unordered_multiset<Complex>>(); +#else + QSKIP("<unordered_set> is needed for this test"); +#endif + } + + void ranged_ctor_std_unordered_multiset_duplicates_strategy() { +#if COMPILER_HAS_STDLIB_INCLUDE(<unordered_set>) + non_associative_container_duplicates_strategy<std::unordered_multiset>(); +#else + QSKIP("<unordered_set> is needed for this test"); +#endif + } + + void ranged_ctor_QSet_int() { ranged_ctor_non_associative_impl<QSet<int>>(); } + void ranged_ctor_QSet_Movable() { ranged_ctor_non_associative_impl<QSet<Movable>>(); } + void ranged_ctor_QSet_Complex() { ranged_ctor_non_associative_impl<QSet<Complex>>(); } + void ranged_ctor_QSet_duplicates_strategy() { non_associative_container_duplicates_strategy<QSet>(); } + + // associative + void ranged_ctor_std_map_int() { ranged_ctor_associative_impl<std::map<int, int>>(); } + void ranged_ctor_std_map_Movable() { ranged_ctor_associative_impl<std::map<Movable, int>>(); } + void ranged_ctor_std_map_Complex() { ranged_ctor_associative_impl<std::map<Complex, int>>(); } + + void ranged_ctor_std_multimap_int() { ranged_ctor_associative_impl<std::multimap<int, int>>(); } + void ranged_ctor_std_multimap_Movable() { ranged_ctor_associative_impl<std::multimap<Movable, int>>(); } + void ranged_ctor_std_multimap_Complex() { ranged_ctor_associative_impl<std::multimap<Complex, int>>(); } + + void ranged_ctor_unordered_map_int() { +#if COMPILER_HAS_STDLIB_INCLUDE(<unordered_map>) + ranged_ctor_associative_impl<std::unordered_map<int, int>>(); +#else + QSKIP("<unordered_map> is needed for this test"); +#endif + } + + void ranged_ctor_unordered_map_Movable() { +#if COMPILER_HAS_STDLIB_INCLUDE(<unordered_map>) + ranged_ctor_associative_impl<std::unordered_map<Movable, Movable>>(); +#else + QSKIP("<unordered_map> is needed for this test"); +#endif + } + + void ranged_ctor_unordered_map_Complex() { +#if COMPILER_HAS_STDLIB_INCLUDE(<unordered_map>) + ranged_ctor_associative_impl<std::unordered_map<Complex, Complex>>(); +#else + QSKIP("<unordered_map> is needed for this test"); +#endif + } + + void ranged_ctor_QHash_int() { ranged_ctor_associative_impl<QHash<int, int>>(); } + void ranged_ctor_QHash_Movable() { ranged_ctor_associative_impl<QHash<Movable, int>>(); } + void ranged_ctor_QHash_Complex() { ranged_ctor_associative_impl<QHash<Complex, int>>(); } + + void ranged_ctor_unordered_multimap_int() { +#if COMPILER_HAS_STDLIB_INCLUDE(<unordered_map>) + ranged_ctor_associative_impl<std::unordered_multimap<int, int>>(); +#else + QSKIP("<unordered_map> is needed for this test"); +#endif + } + + void ranged_ctor_unordered_multimap_Movable() { +#if COMPILER_HAS_STDLIB_INCLUDE(<unordered_map>) + ranged_ctor_associative_impl<std::unordered_multimap<Movable, Movable>>(); +#else + QSKIP("<unordered_map> is needed for this test"); +#endif + } + + void ranged_ctor_unordered_multimap_Complex() { +#if COMPILER_HAS_STDLIB_INCLUDE(<unordered_map>) + ranged_ctor_associative_impl<std::unordered_multimap<Complex, Complex>>(); +#else + QSKIP("<unordered_map> is needed for this test"); +#endif + } + + void ranged_ctor_QMultiHash_int() { ranged_ctor_associative_impl<QMultiHash<int, int>>(); } + void ranged_ctor_QMultiHash_Movable() { ranged_ctor_associative_impl<QMultiHash<Movable, int>>(); } + void ranged_ctor_QMultiHash_Complex() { ranged_ctor_associative_impl<QMultiHash<Complex, int>>(); } + private: template <typename Container> void front_back_impl() const; @@ -58,6 +491,296 @@ private Q_SLOTS: void front_back_QByteArray() { front_back_impl<QByteArray>(); } }; +void tst_ContainerApiSymmetry::init() +{ + m_movableInstanceCount = Movable::instanceCount; + m_complexInstanceCount = Complex::instanceCount; +} + +void tst_ContainerApiSymmetry::cleanup() +{ + // very simple leak check + QCOMPARE(Movable::instanceCount, m_movableInstanceCount); + QCOMPARE(Complex::instanceCount, m_complexInstanceCount); +} + +template <typename Container> +Container createContainerReference() +{ + using V = typename Container::value_type; + + return {V(0), V(1), V(2), V(0)}; +} + +template <typename Container> +void tst_ContainerApiSymmetry::ranged_ctor_non_associative_impl() const +{ + using V = typename Container::value_type; + + // the double V(0) is deliberate + const auto reference = createContainerReference<Container>(); + + // plain array + const V values1[] = { V(0), V(1), V(2), V(0) }; + + const Container c1(values1, values1 + sizeof(values1)/sizeof(values1[0])); + + // from QList + QList<V> l2; + l2 << V(0) << V(1) << V(2) << V(0); + + const Container c2a(l2.begin(), l2.end()); + const Container c2b(l2.cbegin(), l2.cend()); + + // from std::list + std::list<V> l3; + l3.push_back(V(0)); + l3.push_back(V(1)); + l3.push_back(V(2)); + l3.push_back(V(0)); + const Container c3a(l3.begin(), l3.end()); + + // from const std::list + const std::list<V> l3c = l3; + const Container c3b(l3c.begin(), l3c.end()); + + // from itself + const Container c4(reference.begin(), reference.end()); + + QCOMPARE(c1, reference); + QCOMPARE(c2a, reference); + QCOMPARE(c2b, reference); + QCOMPARE(c3a, reference); + QCOMPARE(c3b, reference); + QCOMPARE(c4, reference); +} + + +// type traits for detecting whether a non-associative container +// accepts duplicated values, and if it doesn't, whether construction/insertion +// prefer the new values (overwriting) or the old values (rejecting) + +struct ContainerAcceptsDuplicateValues {}; +struct ContainerOverwritesDuplicateValues {}; +struct ContainerRejectsDuplicateValues {}; + +template<typename Container> +struct ContainerDuplicatedValuesStrategy {}; + +template<typename ... T> +struct ContainerDuplicatedValuesStrategy<std::vector<T...>> : ContainerAcceptsDuplicateValues {}; + +template<typename ... T> +struct ContainerDuplicatedValuesStrategy<QVector<T...>> : ContainerAcceptsDuplicateValues {}; + +template<typename ... T> +struct ContainerDuplicatedValuesStrategy<QVarLengthArray<T...>> : ContainerAcceptsDuplicateValues {}; + +template<typename ... T> +struct ContainerDuplicatedValuesStrategy<VarLengthArray<T...>> : ContainerAcceptsDuplicateValues {}; + +template<typename ... T> +struct ContainerDuplicatedValuesStrategy<QList<T...>> : ContainerAcceptsDuplicateValues {}; + +template<typename ... T> +struct ContainerDuplicatedValuesStrategy<std::list<T...>> : ContainerAcceptsDuplicateValues {}; + +#if COMPILER_HAS_STDLIB_INCLUDE(<forward_list>) +template<typename ... T> +struct ContainerDuplicatedValuesStrategy<std::forward_list<T...>> : ContainerAcceptsDuplicateValues {}; +#endif + +template<typename ... T> +struct ContainerDuplicatedValuesStrategy<QLinkedList<T...>> : ContainerAcceptsDuplicateValues {}; + +// assuming https://cplusplus.github.io/LWG/lwg-active.html#2844 resolution +template<typename ... T> +struct ContainerDuplicatedValuesStrategy<std::set<T...>> : ContainerRejectsDuplicateValues {}; + +template<typename ... T> +struct ContainerDuplicatedValuesStrategy<std::multiset<T...>> : ContainerAcceptsDuplicateValues {}; + +#if COMPILER_HAS_STDLIB_INCLUDE(<unordered_set>) +// assuming https://cplusplus.github.io/LWG/lwg-active.html#2844 resolution +template<typename ... T> +struct ContainerDuplicatedValuesStrategy<std::unordered_set<T...>> : ContainerRejectsDuplicateValues {}; + +template<typename ... T> +struct ContainerDuplicatedValuesStrategy<std::unordered_multiset<T...>> : ContainerAcceptsDuplicateValues {}; +#endif + +template<typename ... T> +struct ContainerDuplicatedValuesStrategy<QSet<T...>> : ContainerRejectsDuplicateValues {}; + +template<typename Container> +void non_associative_container_check_duplicates_impl(const std::initializer_list<DuplicateStrategyTestType> &reference, const Container &c, ContainerAcceptsDuplicateValues) +{ + // do a deep check for equality, not ordering + QVERIFY(std::distance(reference.begin(), reference.end()) == std::distance(c.begin(), c.end())); + QVERIFY(std::is_permutation(reference.begin(), reference.end(), c.begin(), &reallyEqual)); +} + +enum class IterationOnReference +{ + ForwardIteration, + ReverseIteration +}; + +template<typename Container> +void non_associative_container_check_duplicates_impl_no_duplicates(const std::initializer_list<DuplicateStrategyTestType> &reference, const Container &c, IterationOnReference ior) +{ + std::vector<DuplicateStrategyTestType> valuesAlreadySeen; + + // iterate on reference forward or backwards, depending on ior. this will give + // us the expected semantics when checking for duplicated values into c + auto it = [&reference, ior]() { + switch (ior) { + case IterationOnReference::ForwardIteration: return reference.begin(); + case IterationOnReference::ReverseIteration: return reference.end() - 1; + }; + return std::initializer_list<DuplicateStrategyTestType>::const_iterator(); + }(); + + const auto &end = [&reference, ior]() { + switch (ior) { + case IterationOnReference::ForwardIteration: return reference.end(); + case IterationOnReference::ReverseIteration: return reference.begin() - 1; + }; + return std::initializer_list<DuplicateStrategyTestType>::const_iterator(); + }(); + + while (it != end) { + const auto &value = *it; + + // check that there is indeed the same value in the container (using operator==) + const auto &valueInContainerIterator = std::find(c.begin(), c.end(), value); + QVERIFY(valueInContainerIterator != c.end()); + QVERIFY(value == *valueInContainerIterator); + + // if the value is a duplicate, we don't expect to find it in the container + // (when doing a deep comparison). otherwise it should be there + + const auto &valuesAlreadySeenIterator = std::find(valuesAlreadySeen.cbegin(), valuesAlreadySeen.cend(), value); + const bool valueIsDuplicated = (valuesAlreadySeenIterator != valuesAlreadySeen.cend()); + + const auto &reallyEqualCheck = [&value](const DuplicateStrategyTestType &v) { return reallyEqual(value, v); }; + QCOMPARE(std::find_if(c.begin(), c.end(), reallyEqualCheck) == c.end(), valueIsDuplicated); + + valuesAlreadySeen.push_back(value); + + switch (ior) { + case IterationOnReference::ForwardIteration: + ++it; + break; + case IterationOnReference::ReverseIteration: + --it; + break; + }; + } + +} + +template<typename Container> +void non_associative_container_check_duplicates_impl(const std::initializer_list<DuplicateStrategyTestType> &reference, const Container &c, ContainerRejectsDuplicateValues) +{ + non_associative_container_check_duplicates_impl_no_duplicates(reference, c, IterationOnReference::ForwardIteration); +} + +template<typename Container> +void non_associative_container_check_duplicates_impl(const std::initializer_list<DuplicateStrategyTestType> &reference, const Container &c, ContainerOverwritesDuplicateValues) +{ + non_associative_container_check_duplicates_impl_no_duplicates(reference, c, IterationOnReference::ReverseIteration); +} + +template<typename Container> +void non_associative_container_check_duplicates(const std::initializer_list<DuplicateStrategyTestType> &reference, const Container &c) +{ + non_associative_container_check_duplicates_impl(reference, c, ContainerDuplicatedValuesStrategy<Container>()); +} + +template<template<class ... T> class Container> +void tst_ContainerApiSymmetry::non_associative_container_duplicates_strategy() const +{ + // first and last are "duplicates" -- they compare equal for operator==, + // but they differ when using reallyEqual + const std::initializer_list<DuplicateStrategyTestType> reference{ DuplicateStrategyTestType{0}, + DuplicateStrategyTestType{1}, + DuplicateStrategyTestType{2}, + DuplicateStrategyTestType{0} }; + Container<DuplicateStrategyTestType> c1{reference}; + non_associative_container_check_duplicates(reference, c1); + + Container<DuplicateStrategyTestType> c2{reference.begin(), reference.end()}; + non_associative_container_check_duplicates(reference, c2); +} + +template <typename Container> +void tst_ContainerApiSymmetry::ranged_ctor_associative_impl() const +{ + using K = typename Container::key_type; + using V = typename Container::mapped_type; + + // The double K(0) is deliberate. The order of the elements matters: + // * for unique-key STL containers, the first one should be the one inserted (cf. LWG 2844) + // * for unique-key Qt containers, the last one should be the one inserted + // * for multi-key sorted containers, the order of insertion of identical keys is also the + // iteration order (which establishes the equality of the containers) + // (although nothing of this is being tested here, that deserves its own testing) + const Container reference{ + { K(0), V(1000) }, + { K(1), V(1001) }, + { K(2), V(1002) }, + { K(0), V(1003) } + }; + + // Note that using anything not convertible to std::pair doesn't work for + // std containers. Their ranged construction is defined in terms of + // insert(value_type), which for std associative containers is + // std::pair<const K, T>. + + // plain array + const std::pair<K, V> values1[] = { + std::make_pair(K(0), V(1000)), + std::make_pair(K(1), V(1001)), + std::make_pair(K(2), V(1002)), + std::make_pair(K(0), V(1003)) + }; + + const Container c1(values1, values1 + sizeof(values1)/sizeof(values1[0])); + + // from QList + QList<std::pair<K, V>> l2; + l2 << std::make_pair(K(0), V(1000)) + << std::make_pair(K(1), V(1001)) + << std::make_pair(K(2), V(1002)) + << std::make_pair(K(0), V(1003)); + + const Container c2a(l2.begin(), l2.end()); + const Container c2b(l2.cbegin(), l2.cend()); + + // from std::list + std::list<std::pair<K, V>> l3; + l3.push_back(std::make_pair(K(0), V(1000))); + l3.push_back(std::make_pair(K(1), V(1001))); + l3.push_back(std::make_pair(K(2), V(1002))); + l3.push_back(std::make_pair(K(0), V(1003))); + const Container c3a(l3.begin(), l3.end()); + + // from const std::list + const std::list<std::pair<K, V>> l3c = l3; + const Container c3b(l3c.begin(), l3c.end()); + + // from itself + const Container c4(reference.begin(), reference.end()); + + QCOMPARE(c1, reference); + QCOMPARE(c2a, reference); + QCOMPARE(c2b, reference); + QCOMPARE(c3a, reference); + QCOMPARE(c3b, reference); + QCOMPARE(c4, reference); +} + template <typename Container> Container make(int size) { diff --git a/tests/auto/corelib/tools/qalgorithms/tst_qalgorithms.cpp b/tests/auto/corelib/tools/qalgorithms/tst_qalgorithms.cpp index 72299402f0..06db0e8546 100644 --- a/tests/auto/corelib/tools/qalgorithms/tst_qalgorithms.cpp +++ b/tests/auto/corelib/tools/qalgorithms/tst_qalgorithms.cpp @@ -208,7 +208,7 @@ void printHeader(QStringList &headers) for (int h = 0; h < headers.count(); ++h) { cout << setw(20) << setiosflags(ios_base::left) << headers.at(h).toLatin1().constData(); } - cout << endl; + cout << Qt::endl; } template <typename ContainerType> @@ -220,7 +220,7 @@ void print(ContainerType testContainer) cout << value << " "; } - cout << endl; + cout << Qt::endl; } template <typename Algorithm, typename DataType> @@ -252,7 +252,7 @@ void testAlgorithm(Algorithm algorithm, QStringList &dataSetTypes) lessThan << setiosflags(ios_base::left) << setw(10) << result.lessThanRefCount / result.numSorts; cout << numSorts.str() << lessThan.str(); } - cout << endl; + cout << Qt::endl; } } #endif @@ -765,21 +765,21 @@ public: #if Q_TEST_PERFORMANCE void tst_QAlgorithms::performance() { - cout << endl << "Quick sort" << endl; + cout << Qt::endl << "Quick sort" << Qt::endl; testAlgorithm<QuickSortHelper<TestInt>, TestInt>(QuickSortHelper<TestInt>(), dataSetTypes); - cout << endl << "stable sort" << endl; + cout << Qt::endl << "stable sort" << Qt::endl; testAlgorithm<StableSortHelper<TestInt>, TestInt>(StableSortHelper<TestInt>(), dataSetTypes); - cout << endl << "std::sort" << endl; + cout << Qt::endl << "std::sort" << Qt::endl; testAlgorithm<StlSortHelper<TestInt>, TestInt>(StlSortHelper<TestInt>(), dataSetTypes); - cout << endl << "std::stable_sort" << endl; + cout << Qt::endl << "std::stable_sort" << Qt::endl; testAlgorithm<StlStableSortHelper<TestInt>, TestInt>(StlStableSortHelper<TestInt>(), dataSetTypes); /* - cout << endl << "Sorting lists of ints" << endl; - cout << endl << "Quick sort" << endl; + cout << Qt::endl << "Sorting lists of ints" << Qt::endl; + cout << Qt::endl << "Quick sort" << Qt::endl; testAlgorithm<QuickSortHelper<int>, int>(QuickSortHelper<int>(), dataSetTypes); - cout << endl << "std::sort" << endl; + cout << Qt::endl << "std::sort" << Qt::endl; testAlgorithm<StlSortHelper<int>, int>(StlSortHelper<int>(), dataSetTypes); - cout << endl << "std::stable_sort" << endl; + cout << Qt::endl << "std::stable_sort" << Qt::endl; testAlgorithm<StlStableSortHelper<int>, int>(StlStableSortHelper<int>(), dataSetTypes); */ } diff --git a/tests/auto/corelib/tools/qarraydata/tst_qarraydata.cpp b/tests/auto/corelib/tools/qarraydata/tst_qarraydata.cpp index 2d1ae07b35..6ae2aab5b9 100644 --- a/tests/auto/corelib/tools/qarraydata/tst_qarraydata.cpp +++ b/tests/auto/corelib/tools/qarraydata/tst_qarraydata.cpp @@ -79,9 +79,7 @@ private slots: void fromRawData(); void literals(); void variadicLiterals(); -#ifdef Q_COMPILER_RVALUE_REFS void rValueReferences(); -#endif void grow(); }; @@ -1678,7 +1676,6 @@ void tst_QArrayData::variadicLiterals() } } -#ifdef Q_COMPILER_RVALUE_REFS // std::remove_reference is in C++11, but requires library support template <class T> struct RemoveReference { typedef T Type; }; template <class T> struct RemoveReference<T &> { typedef T Type; }; @@ -1761,7 +1758,6 @@ void tst_QArrayData::rValueReferences() QCOMPARE(v3.size(), size_t(1)); QCOMPARE(v3.front(), 42); } -#endif void tst_QArrayData::grow() { diff --git a/tests/auto/corelib/tools/qbytearraylist/tst_qbytearraylist.cpp b/tests/auto/corelib/tools/qbytearraylist/tst_qbytearraylist.cpp index a28bbc12c8..09ce41337e 100644 --- a/tests/auto/corelib/tools/qbytearraylist/tst_qbytearraylist.cpp +++ b/tests/auto/corelib/tools/qbytearraylist/tst_qbytearraylist.cpp @@ -287,7 +287,6 @@ void tst_QByteArrayList::indexOf() const void tst_QByteArrayList::initializerList() const { -#ifdef Q_COMPILER_INITIALIZER_LISTS // constructor QByteArrayList v1 = {QByteArray("hello"),"world",QByteArray("plop")}; QCOMPARE(v1, (QByteArrayList() << "hello" << "world" << "plop")); @@ -296,9 +295,6 @@ void tst_QByteArrayList::initializerList() const QByteArrayList v2; v2 = {QByteArray("hello"),"world",QByteArray("plop")}; QCOMPARE(v2, v1); -#else - QSKIP("This test requires C++11 initializer_list support in the compiler."); -#endif } QTEST_APPLESS_MAIN(tst_QByteArrayList) diff --git a/tests/auto/corelib/tools/qcollator/tst_qcollator.cpp b/tests/auto/corelib/tools/qcollator/tst_qcollator.cpp index 72f88a235d..2ae9c6e159 100644 --- a/tests/auto/corelib/tools/qcollator/tst_qcollator.cpp +++ b/tests/auto/corelib/tools/qcollator/tst_qcollator.cpp @@ -47,7 +47,6 @@ private Q_SLOTS: void state(); }; -#ifdef Q_COMPILER_RVALUE_REFS static bool dpointer_is_null(QCollator &c) { char mem[sizeof c]; @@ -58,11 +57,9 @@ static bool dpointer_is_null(QCollator &c) return false; return true; } -#endif void tst_QCollator::moveSemantics() { -#ifdef Q_COMPILER_RVALUE_REFS const QLocale de_AT(QLocale::German, QLocale::Austria); QCollator c1(de_AT); @@ -78,9 +75,6 @@ void tst_QCollator::moveSemantics() c1 = std::move(c2); QCOMPARE(c1.locale(), de_AT); QVERIFY(dpointer_is_null(c2)); -#else - QSKIP("The compiler is not in C++11 mode or does not support move semantics."); -#endif } diff --git a/tests/auto/corelib/tools/qcommandlineparser/tst_qcommandlineparser.cpp b/tests/auto/corelib/tools/qcommandlineparser/tst_qcommandlineparser.cpp index 811e9a0010..de51c866e1 100644 --- a/tests/auto/corelib/tools/qcommandlineparser/tst_qcommandlineparser.cpp +++ b/tests/auto/corelib/tools/qcommandlineparser/tst_qcommandlineparser.cpp @@ -499,7 +499,7 @@ void tst_QCommandLineParser::testSingleDashWordOptionModes() void tst_QCommandLineParser::testCpp11StyleInitialization() { -#if defined(Q_COMPILER_INITIALIZER_LISTS) && defined(Q_COMPILER_UNIFORM_INIT) +#if defined(Q_COMPILER_UNIFORM_INIT) QCoreApplication app(empty_argc, empty_argv); QCommandLineParser parser; diff --git a/tests/auto/corelib/tools/qdate/CMakeLists.txt b/tests/auto/corelib/tools/qdate/CMakeLists.txt index e967a03edf..8514c915ad 100644 --- a/tests/auto/corelib/tools/qdate/CMakeLists.txt +++ b/tests/auto/corelib/tools/qdate/CMakeLists.txt @@ -1 +1,15 @@ -add_qt_test(tst_qdate SOURCES tst_qdate.cpp) +# Generated from qdate.pro. + +##################################################################### +## tst_qdate Test: +##################################################################### + +add_qt_test(tst_qdate + SOURCES + tst_qdate.cpp + LIBRARIES + Qt::CorePrivate +) + +#### Keys ignored in scope 1:.:.:qdate.pro:<TRUE>: +# CONFIG = "testcase" diff --git a/tests/auto/corelib/tools/qdate/qdate.pro b/tests/auto/corelib/tools/qdate/qdate.pro index dd7c6cb888..925c3b4c78 100644 --- a/tests/auto/corelib/tools/qdate/qdate.pro +++ b/tests/auto/corelib/tools/qdate/qdate.pro @@ -1,4 +1,4 @@ CONFIG += testcase TARGET = tst_qdate -QT = core testlib +QT = core-private testlib SOURCES = tst_qdate.cpp diff --git a/tests/auto/corelib/tools/qdate/tst_qdate.cpp b/tests/auto/corelib/tools/qdate/tst_qdate.cpp index c17af8741b..0ef494b229 100644 --- a/tests/auto/corelib/tools/qdate/tst_qdate.cpp +++ b/tests/auto/corelib/tools/qdate/tst_qdate.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/ ** @@ -27,6 +27,7 @@ ** ****************************************************************************/ +#include <private/qglobal_p.h> // for the icu feature test #include <QtTest/QtTest> #include <qdatetime.h> #include <qlocale.h> @@ -54,6 +55,13 @@ private slots: void weekNumber_invalid(); void weekNumber_data(); void weekNumber(); +#if QT_CONFIG(timezone) + void startOfDay_endOfDay_data(); + void startOfDay_endOfDay(); +#endif + void startOfDay_endOfDay_fixed_data(); + void startOfDay_endOfDay_fixed(); + void startOfDay_endOfDay_bounds(); void julianDaysLimits(); void addDays_data(); void addDays(); @@ -458,6 +466,164 @@ void tst_QDate::weekNumber_invalid() QCOMPARE( dt.weekNumber( &yearNumber ), 0 ); } +#if QT_CONFIG(timezone) +void tst_QDate::startOfDay_endOfDay_data() +{ + QTest::addColumn<QDate>("date"); // Typically a spring-forward. + // A zone in which that date's start and end are worth checking: + QTest::addColumn<QByteArray>("zoneName"); + // The start and end times in that zone: + QTest::addColumn<QTime>("start"); + QTest::addColumn<QTime>("end"); + + const QTime initial(0, 0), final(23, 59, 59, 999), invalid(QDateTime().time()); + + QTest::newRow("epoch") + << QDate(1970, 1, 1) << QByteArray("UTC") + << initial << final; + QTest::newRow("Brazil") + << QDate(2008, 10, 19) << QByteArray("America/Sao_Paulo") + << QTime(1, 0) << final; +#if QT_CONFIG(icu) || !defined(Q_OS_WIN) // MS's TZ APIs lack data + QTest::newRow("Sofia") + << QDate(1994, 3, 27) << QByteArray("Europe/Sofia") + << QTime(1, 0) << final; +#endif + QTest::newRow("Kiritimati") + << QDate(1994, 12, 31) << QByteArray("Pacific/Kiritimati") + << invalid << invalid; + QTest::newRow("Samoa") + << QDate(2011, 12, 30) << QByteArray("Pacific/Apia") + << invalid << invalid; + // TODO: find other zones with transitions at/crossing midnight. +} + +void tst_QDate::startOfDay_endOfDay() +{ + QFETCH(QDate, date); + QFETCH(QByteArray, zoneName); + QFETCH(QTime, start); + QFETCH(QTime, end); + const QTimeZone zone(zoneName); + const bool isSystem = QTimeZone::systemTimeZone() == zone; + QDateTime front(date.startOfDay(zone)), back(date.endOfDay(zone)); + if (end.isValid()) + QCOMPARE(date.addDays(1).startOfDay(zone).addMSecs(-1), back); + if (start.isValid()) + QCOMPARE(date.addDays(-1).endOfDay(zone).addMSecs(1), front); + do { // Avoids duplicating these tests for local-time when it *is* zone: + if (start.isValid()) { + QCOMPARE(front.date(), date); + QCOMPARE(front.time(), start); + } + if (end.isValid()) { + QCOMPARE(back.date(), date); + QCOMPARE(back.time(), end); + } + if (front.timeSpec() == Qt::LocalTime) + break; + front = date.startOfDay(Qt::LocalTime); + back = date.endOfDay(Qt::LocalTime); + } while (isSystem); + if (end.isValid()) + QCOMPARE(date.addDays(1).startOfDay(Qt::LocalTime).addMSecs(-1), back); + if (start.isValid()) + QCOMPARE(date.addDays(-1).endOfDay(Qt::LocalTime).addMSecs(1), front); + if (!isSystem) { + // These might fail if system zone coincides with zone; but only if it + // did something similarly unusual on the date picked for this test. + if (start.isValid()) { + QCOMPARE(front.date(), date); + QCOMPARE(front.time(), QTime(0, 0)); + } + if (end.isValid()) { + QCOMPARE(back.date(), date); + QCOMPARE(back.time(), QTime(23, 59, 59, 999)); + } + } +} +#endif // timezone + +void tst_QDate::startOfDay_endOfDay_fixed_data() +{ + const qint64 kilo(1000); + using Bounds = std::numeric_limits<qint64>; + const QDateTime + first(QDateTime::fromMSecsSinceEpoch(Bounds::min() + 1, Qt::UTC)), + start32sign(QDateTime::fromMSecsSinceEpoch(-0x80000000L * kilo, Qt::UTC)), + end32sign(QDateTime::fromMSecsSinceEpoch(0x80000000L * kilo, Qt::UTC)), + end32unsign(QDateTime::fromMSecsSinceEpoch(0x100000000L * kilo, Qt::UTC)), + last(QDateTime::fromMSecsSinceEpoch(Bounds::max(), Qt::UTC)); + + const struct { + const char *name; + QDate date; + } data[] = { + { "epoch", QDate(1970, 1, 1) }, + { "y2k-leap-day", QDate(2000, 2, 29) }, + // Just outside the start and end of 32-bit time_t: + { "pre-sign32", QDate(start32sign.date().year(), 1, 1) }, + { "post-sign32", QDate(end32sign.date().year(), 12, 31) }, + { "post-uint32", QDate(end32unsign.date().year(), 12, 31) }, + // Just inside the start and end of QDateTime's range: + { "first-full", first.date().addDays(1) }, + { "last-full", last.date().addDays(-1) } + }; + + QTest::addColumn<QDate>("date"); + for (const auto &r : data) + QTest::newRow(r.name) << r.date; +} + +void tst_QDate::startOfDay_endOfDay_fixed() +{ + const QTime early(0, 0), late(23, 59, 59, 999); + QFETCH(QDate, date); + + QDateTime start(date.startOfDay(Qt::UTC)); + QDateTime end(date.endOfDay(Qt::UTC)); + QCOMPARE(start.date(), date); + QCOMPARE(end.date(), date); + QCOMPARE(start.time(), early); + QCOMPARE(end.time(), late); + QCOMPARE(date.addDays(1).startOfDay(Qt::UTC).addMSecs(-1), end); + QCOMPARE(date.addDays(-1).endOfDay(Qt::UTC).addMSecs(1), start); + for (int offset = -60 * 16; offset <= 60 * 16; offset += 65) { + start = date.startOfDay(Qt::OffsetFromUTC, offset); + end = date.endOfDay(Qt::OffsetFromUTC, offset); + QCOMPARE(start.date(), date); + QCOMPARE(end.date(), date); + QCOMPARE(start.time(), early); + QCOMPARE(end.time(), late); + QCOMPARE(date.addDays(1).startOfDay(Qt::OffsetFromUTC, offset).addMSecs(-1), end); + QCOMPARE(date.addDays(-1).endOfDay(Qt::OffsetFromUTC, offset).addMSecs(1), start); + } +} + +void tst_QDate::startOfDay_endOfDay_bounds() +{ + // Check the days in which QDateTime's range starts and ends: + using Bounds = std::numeric_limits<qint64>; + const QDateTime + first(QDateTime::fromMSecsSinceEpoch(Bounds::min(), Qt::UTC)), + last(QDateTime::fromMSecsSinceEpoch(Bounds::max(), Qt::UTC)), + epoch(QDateTime::fromMSecsSinceEpoch(0, Qt::UTC)); + // First, check these *are* the start and end of QDateTime's range: + QVERIFY(first.isValid()); + QVERIFY(last.isValid()); + QVERIFY(first < epoch); + QVERIFY(last > epoch); + // QDateTime's addMSecs doesn't check against {und,ov}erflow ... + QVERIFY(!first.addMSecs(-1).isValid() || first.addMSecs(-1) > first); + QVERIFY(!last.addMSecs(1).isValid() || last.addMSecs(1) < last); + + // Now test start/end methods with them: + QCOMPARE(first.date().endOfDay(Qt::UTC).time(), QTime(23, 59, 59, 999)); + QCOMPARE(last.date().startOfDay(Qt::UTC).time(), QTime(0, 0)); + QVERIFY(!first.date().startOfDay(Qt::UTC).isValid()); + QVERIFY(!last.date().endOfDay(Qt::UTC).isValid()); +} + void tst_QDate::julianDaysLimits() { qint64 min = std::numeric_limits<qint64>::min(); diff --git a/tests/auto/corelib/tools/qdatetime/tst_qdatetime.cpp b/tests/auto/corelib/tools/qdatetime/tst_qdatetime.cpp index 6ad3357f40..6f0aebb071 100644 --- a/tests/auto/corelib/tools/qdatetime/tst_qdatetime.cpp +++ b/tests/auto/corelib/tools/qdatetime/tst_qdatetime.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/ ** @@ -78,9 +78,11 @@ private slots: void toString_isoDate_data(); void toString_isoDate(); void toString_isoDate_extra(); +#if QT_CONFIG(datestring) void toString_textDate_data(); void toString_textDate(); void toString_textDate_extra(); +#endif void toString_rfcDate_data(); void toString_rfcDate(); void toString_enumformat(); @@ -800,11 +802,11 @@ void tst_QDateTime::toString_isoDate_data() QTest::newRow("positive OffsetFromUTC") << dt << Qt::ISODate << QString("1978-11-09T13:28:34+05:30"); - dt.setUtcOffset(-7200); + dt.setOffsetFromUtc(-7200); QTest::newRow("negative OffsetFromUTC") << dt << Qt::ISODate << QString("1978-11-09T13:28:34-02:00"); - dt.setUtcOffset(-900); + dt.setOffsetFromUtc(-900); QTest::newRow("negative non-integral OffsetFromUTC") << dt << Qt::ISODate << QString("1978-11-09T13:28:34-00:15"); @@ -840,7 +842,7 @@ void tst_QDateTime::toString_isoDate() QCOMPARE(resultDatetime.date(), datetime.date()); QCOMPARE(resultDatetime.time(), datetime.time()); QCOMPARE(resultDatetime.timeSpec(), datetime.timeSpec()); - QCOMPARE(resultDatetime.utcOffset(), datetime.utcOffset()); + QCOMPARE(resultDatetime.offsetFromUtc(), datetime.offsetFromUtc()); } else { QCOMPARE(resultDatetime, QDateTime()); } @@ -870,12 +872,14 @@ void tst_QDateTime::toString_isoDate_extra() #endif // timezone } +#if QT_CONFIG(datestring) void tst_QDateTime::toString_textDate_data() { QTest::addColumn<QDateTime>("datetime"); QTest::addColumn<QString>("expected"); - QString wednesdayJanuary = QDate::shortDayName(3) + ' ' + QDate::shortMonthName(1); + QString wednesdayJanuary = QLocale::system().dayName(3, QLocale::ShortFormat) + + ' ' + QLocale::system().monthName(1, QLocale::ShortFormat); QTest::newRow("localtime") << QDateTime(QDate(2013, 1, 2), QTime(1, 2, 3), Qt::LocalTime) << wednesdayJanuary + QString(" 2 01:02:03 2013"); @@ -904,7 +908,7 @@ void tst_QDateTime::toString_textDate() QCOMPARE(resultDatetime.date(), datetime.date()); QCOMPARE(resultDatetime.time(), datetime.time()); QCOMPARE(resultDatetime.timeSpec(), datetime.timeSpec()); - QCOMPARE(resultDatetime.utcOffset(), datetime.utcOffset()); + QCOMPARE(resultDatetime.offsetFromUtc(), datetime.offsetFromUtc()); } void tst_QDateTime::toString_textDate_extra() @@ -953,6 +957,7 @@ void tst_QDateTime::toString_textDate_extra() dt = QDateTime::fromMSecsSinceEpoch(0, Qt::UTC); QVERIFY(dt.toString().endsWith(GMT)); } +#endif // datestring void tst_QDateTime::toString_rfcDate_data() { @@ -968,11 +973,11 @@ void tst_QDateTime::toString_rfcDate_data() << QDateTime(QDate(1978, 11, 9), QTime(13, 28, 34), Qt::UTC) << QString("09 Nov 1978 13:28:34 +0000"); QDateTime dt(QDate(1978, 11, 9), QTime(13, 28, 34)); - dt.setUtcOffset(19800); + dt.setOffsetFromUtc(19800); QTest::newRow("positive OffsetFromUTC") << dt << QString("09 Nov 1978 13:28:34 +0530"); - dt.setUtcOffset(-7200); + dt.setOffsetFromUtc(-7200); QTest::newRow("negative OffsetFromUTC") << dt << QString("09 Nov 1978 13:28:34 -0200"); @@ -1000,7 +1005,6 @@ void tst_QDateTime::toString_enumformat() { QDateTime dt1(QDate(1995, 5, 20), QTime(12, 34, 56)); - QString str1 = dt1.toString(Qt::TextDate); QVERIFY(!str1.isEmpty()); // It's locale dependent everywhere @@ -2771,9 +2775,9 @@ void tst_QDateTime::getDate() int y = -33, m = -44, d = -55; QDate date; date.getDate(&y, &m, &d); - QVERIFY(date.year() == y); - QVERIFY(date.month() == m); - QVERIFY(date.day() == d); + QCOMPARE(date.year(), y); + QCOMPARE(date.month(), m); + QCOMPARE(date.day(), d); date.getDate(0, 0, 0); } @@ -2785,9 +2789,9 @@ void tst_QDateTime::getDate() date.getDate(&y, 0, 0); date.getDate(0, 0, &d); - QVERIFY(date.year() == y); - QVERIFY(date.month() == m); - QVERIFY(date.day() == d); + QCOMPARE(date.year(), y); + QCOMPARE(date.month(), m); + QCOMPARE(date.day(), d); } } diff --git a/tests/auto/corelib/tools/qeasingcurve/tst_qeasingcurve.cpp b/tests/auto/corelib/tools/qeasingcurve/tst_qeasingcurve.cpp index c21d0afacb..3af6132695 100644 --- a/tests/auto/corelib/tools/qeasingcurve/tst_qeasingcurve.cpp +++ b/tests/auto/corelib/tools/qeasingcurve/tst_qeasingcurve.cpp @@ -30,9 +30,7 @@ #include <qeasingcurve.h> -#ifdef Q_COMPILER_RVALUE_REFS // cpp11() slot -# include <utility> // for std::move() -#endif +#include <utility> // for std::move() class tst_QEasingCurve : public QObject { @@ -794,7 +792,6 @@ void tst_QEasingCurve::testCbrtFloat() void tst_QEasingCurve::cpp11() { -#ifdef Q_COMPILER_RVALUE_REFS { QEasingCurve ec( QEasingCurve::InOutBack ); QEasingCurve copy = std::move(ec); // move ctor @@ -809,7 +806,6 @@ void tst_QEasingCurve::cpp11() QCOMPARE( copy.type(), QEasingCurve::InOutBack ); QCOMPARE( ec.type(), type ); } -#endif } void tst_QEasingCurve::quadraticEquation() { diff --git a/tests/auto/corelib/tools/qhash/tst_qhash.cpp b/tests/auto/corelib/tools/qhash/tst_qhash.cpp index 0015efacfa..d70d488e96 100644 --- a/tests/auto/corelib/tools/qhash/tst_qhash.cpp +++ b/tests/auto/corelib/tools/qhash/tst_qhash.cpp @@ -1480,7 +1480,6 @@ void tst_QHash::twoArguments_qHash() void tst_QHash::initializerList() { -#ifdef Q_COMPILER_INITIALIZER_LISTS QHash<int, QString> hash = {{1, "bar"}, {1, "hello"}, {2, "initializer_list"}}; QCOMPARE(hash.count(), 2); QCOMPARE(hash[1], QString("hello")); @@ -1507,9 +1506,6 @@ void tst_QHash::initializerList() QMultiHash<int, float> emptyPairs2{{}, {}}; QVERIFY(!emptyPairs2.isEmpty()); -#else - QSKIP("Compiler doesn't support initializer lists"); -#endif } void tst_QHash::eraseValidIteratorOnSharedHash() diff --git a/tests/auto/corelib/tools/qline/tst_qline.cpp b/tests/auto/corelib/tools/qline/tst_qline.cpp index ae65d8f697..915a24a1f6 100644 --- a/tests/auto/corelib/tools/qline/tst_qline.cpp +++ b/tests/auto/corelib/tools/qline/tst_qline.cpp @@ -205,7 +205,7 @@ void tst_QLine::testIntersection() QPointF ip; - QLineF::IntersectType itype = a.intersect(b, &ip); + QLineF::IntersectionType itype = a.intersect(b, &ip); QCOMPARE(int(itype), type); if (type != QLineF::NoIntersection) { diff --git a/tests/auto/corelib/tools/qlinkedlist/tst_qlinkedlist.cpp b/tests/auto/corelib/tools/qlinkedlist/tst_qlinkedlist.cpp index f17d6695f0..deb3b68c5c 100644 --- a/tests/auto/corelib/tools/qlinkedlist/tst_qlinkedlist.cpp +++ b/tests/auto/corelib/tools/qlinkedlist/tst_qlinkedlist.cpp @@ -1005,7 +1005,6 @@ void tst_QLinkedList::testSTLIteratorsComplex() const void tst_QLinkedList::initializeList() const { -#ifdef Q_COMPILER_INITIALIZER_LISTS QLinkedList<int> v1 { 2, 3, 4 }; QCOMPARE(v1, QLinkedList<int>() << 2 << 3 << 4); QCOMPARE(v1, (QLinkedList<int> { 2, 3, 4})); @@ -1014,7 +1013,6 @@ void tst_QLinkedList::initializeList() const QLinkedList<QLinkedList<int>> v3; v3 << v1 << (QLinkedList<int>() << 1) << QLinkedList<int>() << v1; QCOMPARE(v3, v2); -#endif } diff --git a/tests/auto/corelib/tools/qlist/tst_qlist.cpp b/tests/auto/corelib/tools/qlist/tst_qlist.cpp index b3f8130d27..5a485e88d2 100644 --- a/tests/auto/corelib/tools/qlist/tst_qlist.cpp +++ b/tests/auto/corelib/tools/qlist/tst_qlist.cpp @@ -364,12 +364,14 @@ private slots: void takeLastOptimal() const; void takeLastMovable() const; void takeLastComplex() const; +#if QT_VERSION < QT_VERSION_CHECK(6,0,0) void toSetOptimal() const; void toSetMovable() const; void toSetComplex() const; void toStdListOptimal() const; void toStdListMovable() const; void toStdListComplex() const; +#endif void toVectorOptimal() const; void toVectorMovable() const; void toVectorComplex() const; @@ -426,8 +428,10 @@ private: template<typename T> void takeAt() const; template<typename T> void takeFirst() const; template<typename T> void takeLast() const; +#if QT_VERSION < QT_VERSION_CHECK(6,0,0) template<typename T> void toSet() const; template<typename T> void toStdList() const; +#endif template<typename T> void toVector() const; template<typename T> void value() const; @@ -1457,11 +1461,11 @@ void tst_QList::swap() const list << T_FOO << T_BAR << T_BAZ; // swap - list.swap(0, 2); + list.swapItemsAt(0, 2); QCOMPARE(list, QList<T>() << T_BAZ << T_BAR << T_FOO); // swap again - list.swap(1, 2); + list.swapItemsAt(1, 2); QCOMPARE(list, QList<T>() << T_BAZ << T_FOO << T_BAR); QList<T> list2; @@ -1595,6 +1599,7 @@ void tst_QList::takeLastComplex() const QCOMPARE(liveCount, Complex::getLiveCount()); } +#if QT_VERSION < QT_VERSION_CHECK(6,0,0) template<typename T> void tst_QList::toSet() const { @@ -1669,6 +1674,7 @@ void tst_QList::toStdListComplex() const toStdList<Complex>(); QCOMPARE(liveCount, Complex::getLiveCount()); } +#endif template<typename T> void tst_QList::toVector() const @@ -1871,7 +1877,6 @@ void tst_QList::testSTLIteratorsComplex() const void tst_QList::initializeList() const { -#ifdef Q_COMPILER_INITIALIZER_LISTS QList<int> v1{2,3,4}; QCOMPARE(v1, QList<int>() << 2 << 3 << 4); QCOMPARE(v1, (QList<int>{2,3,4})); @@ -1880,7 +1885,6 @@ void tst_QList::initializeList() const QList<QList<int>> v3; v3 << v1 << (QList<int>() << 1) << QList<int>() << v1; QCOMPARE(v3, v2); -#endif } template<typename T> diff --git a/tests/auto/corelib/tools/qlocale/tst_qlocale.cpp b/tests/auto/corelib/tools/qlocale/tst_qlocale.cpp index 0b41af3371..ec8f2fc047 100644 --- a/tests/auto/corelib/tools/qlocale/tst_qlocale.cpp +++ b/tests/auto/corelib/tools/qlocale/tst_qlocale.cpp @@ -423,6 +423,7 @@ void tst_QLocale::defaulted_ctor() } QLocale::setDefault(QLocale(QLocale::C)); + const QString empty; TEST_CTOR("C", C, AnyCountry) TEST_CTOR("bla", C, AnyCountry) @@ -431,7 +432,7 @@ void tst_QLocale::defaulted_ctor() TEST_CTOR("zz...", C, AnyCountry) TEST_CTOR("", C, AnyCountry) TEST_CTOR("en/", C, AnyCountry) - TEST_CTOR(QString::null, C, AnyCountry) + TEST_CTOR(empty, C, AnyCountry) TEST_CTOR("en", English, UnitedStates) TEST_CTOR("en", English, UnitedStates) TEST_CTOR("en.", English, UnitedStates) @@ -2458,9 +2459,9 @@ void tst_QLocale::timeFormat() QCOMPARE(c.timeFormat(QLocale::NarrowFormat), c.timeFormat(QLocale::ShortFormat)); const QLocale no("no_NO"); - QCOMPARE(no.timeFormat(QLocale::NarrowFormat), QLatin1String("HH:mm")); - QCOMPARE(no.timeFormat(QLocale::ShortFormat), QLatin1String("HH:mm")); - QCOMPARE(no.timeFormat(QLocale::LongFormat), QLatin1String("HH:mm:ss t")); + QCOMPARE(no.timeFormat(QLocale::NarrowFormat), QLatin1String("HH.mm")); + QCOMPARE(no.timeFormat(QLocale::ShortFormat), QLatin1String("HH.mm")); + QCOMPARE(no.timeFormat(QLocale::LongFormat), QLatin1String("HH.mm.ss t")); const QLocale id("id_ID"); QCOMPARE(id.timeFormat(QLocale::ShortFormat), QLatin1String("HH.mm")); @@ -2482,9 +2483,9 @@ void tst_QLocale::dateTimeFormat() QCOMPARE(c.dateTimeFormat(QLocale::NarrowFormat), c.dateTimeFormat(QLocale::ShortFormat)); const QLocale no("no_NO"); - QCOMPARE(no.dateTimeFormat(QLocale::NarrowFormat), QLatin1String("dd.MM.yyyy HH:mm")); - QCOMPARE(no.dateTimeFormat(QLocale::ShortFormat), QLatin1String("dd.MM.yyyy HH:mm")); - QCOMPARE(no.dateTimeFormat(QLocale::LongFormat), QLatin1String("dddd d. MMMM yyyy HH:mm:ss t")); + QCOMPARE(no.dateTimeFormat(QLocale::NarrowFormat), QLatin1String("dd.MM.yyyy HH.mm")); + QCOMPARE(no.dateTimeFormat(QLocale::ShortFormat), QLatin1String("dd.MM.yyyy HH.mm")); + QCOMPARE(no.dateTimeFormat(QLocale::LongFormat), QLatin1String("dddd d. MMMM yyyy HH.mm.ss t")); } void tst_QLocale::monthName() diff --git a/tests/auto/corelib/tools/qmap/tst_qmap.cpp b/tests/auto/corelib/tools/qmap/tst_qmap.cpp index b39444e76f..d66fd28779 100644 --- a/tests/auto/corelib/tools/qmap/tst_qmap.cpp +++ b/tests/auto/corelib/tools/qmap/tst_qmap.cpp @@ -1319,7 +1319,6 @@ void tst_QMap::checkMostLeftNode() void tst_QMap::initializerList() { -#ifdef Q_COMPILER_INITIALIZER_LISTS QMap<int, QString> map = {{1, "bar"}, {1, "hello"}, {2, "initializer_list"}}; QCOMPARE(map.count(), 2); QCOMPARE(map[1], QString("hello")); @@ -1346,9 +1345,6 @@ void tst_QMap::initializerList() QMultiMap<float, float> emptyPairs2{{}, {}}; QVERIFY(!emptyPairs2.isEmpty()); -#else - QSKIP("Compiler doesn't support initializer lists"); -#endif } void tst_QMap::testInsertWithHint() diff --git a/tests/auto/corelib/tools/qset/tst_qset.cpp b/tests/auto/corelib/tools/qset/tst_qset.cpp index 0b60350380..31b4c0449e 100644 --- a/tests/auto/corelib/tools/qset/tst_qset.cpp +++ b/tests/auto/corelib/tools/qset/tst_qset.cpp @@ -955,7 +955,6 @@ void tst_QSet::makeSureTheComfortFunctionsCompile() void tst_QSet::initializerList() { -#ifdef Q_COMPILER_INITIALIZER_LISTS QSet<int> set = {1, 1, 2, 3, 4, 5}; QCOMPARE(set.count(), 5); QVERIFY(set.contains(1)); @@ -976,9 +975,6 @@ void tst_QSet::initializerList() QSet<int> set3{{}, {}, {}}; QVERIFY(!set3.isEmpty()); -#else - QSKIP("Compiler doesn't support initializer lists"); -#endif } void tst_QSet::qhash() @@ -1011,15 +1007,7 @@ void tst_QSet::qhash() // check that sets of sets work: // { -#ifdef Q_COMPILER_INITIALIZER_LISTS QSet<QSet<int> > intSetSet = { { 0, 1, 2 }, { 0, 1 }, { 1, 2 } }; -#else - QSet<QSet<int> > intSetSet; - QSet<int> intSet01, intSet12; - intSet01 << 0 << 1; - intSet12 << 1 << 2; - intSetSet << intSet01 << intSet12 << (intSet01|intSet12); -#endif QCOMPARE(intSetSet.size(), 3); } } diff --git a/tests/auto/corelib/tools/qsharedpointer/tst_qsharedpointer.cpp b/tests/auto/corelib/tools/qsharedpointer/tst_qsharedpointer.cpp index 19b2aa02f3..42792b5310 100644 --- a/tests/auto/corelib/tools/qsharedpointer/tst_qsharedpointer.cpp +++ b/tests/auto/corelib/tools/qsharedpointer/tst_qsharedpointer.cpp @@ -78,6 +78,7 @@ private slots: void sharedPointerFromQObjectWithWeak(); void weakQObjectFromSharedPointer(); void objectCast(); + void objectCastStdSharedPtr(); void differentPointers(); void virtualBaseDifferentPointers(); #ifndef QTEST_NO_RTTI @@ -224,13 +225,11 @@ struct NoDefaultConstructorConstRef2 NoDefaultConstructorConstRef2(const QByteArray &ba, int i = 42) : str(QString::fromLatin1(ba)), i(i) {} }; -#ifdef Q_COMPILER_RVALUE_REFS struct NoDefaultConstructorRRef1 { int &i; NoDefaultConstructorRRef1(int &&i) : i(i) {} }; -#endif void tst_QSharedPointer::basics_data() { @@ -499,7 +498,6 @@ void tst_QSharedPointer::swap() void tst_QSharedPointer::moveSemantics() { -#ifdef Q_COMPILER_RVALUE_REFS QSharedPointer<int> p1, p2(new int(42)), control = p2; QVERIFY(p1 != control); QVERIFY(p1.isNull()); @@ -552,9 +550,6 @@ void tst_QSharedPointer::moveSemantics() QVERIFY(w1.isNull()); QVERIFY(w2.isNull()); QVERIFY(w3.isNull()); -#else - QSKIP("This test requires C++11 rvalue/move semantics support in the compiler."); -#endif } void tst_QSharedPointer::useOfForwardDeclared() @@ -1113,6 +1108,60 @@ void tst_QSharedPointer::objectCast() safetyCheck(); } + +void tst_QSharedPointer::objectCastStdSharedPtr() +{ + { + OtherObject *data = new OtherObject; + std::shared_ptr<QObject> baseptr = std::shared_ptr<QObject>(data); + QVERIFY(baseptr.get() == data); + + // perform successful object cast + std::shared_ptr<OtherObject> ptr = qobject_pointer_cast<OtherObject>(baseptr); + QVERIFY(ptr.get()); + QVERIFY(ptr.get() == data); + + QVERIFY(baseptr.get() == data); + } + + { + OtherObject *data = new OtherObject; + std::shared_ptr<QObject> baseptr = std::shared_ptr<QObject>(data); + QVERIFY(baseptr.get() == data); + + // perform successful object cast + std::shared_ptr<OtherObject> ptr = qobject_pointer_cast<OtherObject>(std::move(baseptr)); + QVERIFY(ptr.get()); + QVERIFY(ptr.get() == data); + + QVERIFY(!baseptr.get()); + } + + { + QObject *data = new QObject; + std::shared_ptr<QObject> baseptr = std::shared_ptr<QObject>(data); + QVERIFY(baseptr.get() == data); + + // perform unsuccessful object cast + std::shared_ptr<OtherObject> ptr = qobject_pointer_cast<OtherObject>(baseptr); + QVERIFY(!ptr.get()); + + QVERIFY(baseptr.get() == data); + } + + { + QObject *data = new QObject; + std::shared_ptr<QObject> baseptr = std::shared_ptr<QObject>(data); + QVERIFY(baseptr.get() == data); + + // perform unsuccessful object cast + std::shared_ptr<OtherObject> ptr = qobject_pointer_cast<OtherObject>(std::move(baseptr)); + QVERIFY(!ptr.get()); + + QVERIFY(baseptr.get() == data); + } +} + void tst_QSharedPointer::differentPointers() { { diff --git a/tests/auto/corelib/tools/qstringapisymmetry/tst_qstringapisymmetry.cpp b/tests/auto/corelib/tools/qstringapisymmetry/tst_qstringapisymmetry.cpp index cb1fd9eb7d..7e5a855552 100644 --- a/tests/auto/corelib/tools/qstringapisymmetry/tst_qstringapisymmetry.cpp +++ b/tests/auto/corelib/tools/qstringapisymmetry/tst_qstringapisymmetry.cpp @@ -48,6 +48,14 @@ QString toQString(const T &t) { return QString(t); } QString toQString(const QStringRef &ref) { return ref.toString(); } QString toQString(QStringView view) { return view.toString(); } +template <typename Iterable> +QStringList toQStringList(const Iterable &i) { + QStringList result; + for (auto &e : i) + result.push_back(toQString(e)); + return result; +} + // FIXME: these are missing at the time of writing, add them, then remove the dummies here: #define MAKE_RELOP(op, A1, A2) \ static bool operator op (A1 lhs, A2 rhs) \ @@ -293,6 +301,26 @@ private Q_SLOTS: void endsWith_QLatin1String_QChar() { endsWith_impl<QLatin1String, QChar>(); } private: + void split_data(bool rhsHasVariableLength = true); + template <typename Haystack, typename Needle> void split_impl() const; + +private Q_SLOTS: + // test all combinations of {QString, QStringRef} x {QString, QLatin1String, QChar}: + void split_QString_QString_data() { split_data(); } + void split_QString_QString() { split_impl<QString, QString>(); } + void split_QString_QLatin1String_data() { split_data(); } + void split_QString_QLatin1String() { split_impl<QString, QLatin1String>(); } + void split_QString_QChar_data() { split_data(false); } + void split_QString_QChar() { split_impl<QString, QChar>(); } + + void split_QStringRef_QString_data() { split_data(); } + void split_QStringRef_QString() { split_impl<QStringRef, QString>(); } + void split_QStringRef_QLatin1String_data() { split_data(); } + void split_QStringRef_QLatin1String() { split_impl<QStringRef, QLatin1String>(); } + void split_QStringRef_QChar_data() { split_data(false); } + void split_QStringRef_QChar() { split_impl<QStringRef, QChar>(); } + +private: void mid_data(); template <typename String> void mid_impl(); @@ -416,6 +444,47 @@ private Q_SLOTS: void toUcs4_QStringRef() { toUcs4_impl<QStringRef>(); } void toUcs4_QStringView_data() { toUcs4_data(); } void toUcs4_QStringView() { toUcs4_impl<QStringView>(); } + +private: + template <typename Haystack, typename Needle> void indexOf_impl() const; + void indexOf_data(); + +private Q_SLOTS: + void indexOf_QString_QString_data() { indexOf_data(); } + void indexOf_QString_QString() { indexOf_impl<QString, QString>(); } + void indexOf_QString_QLatin1String_data() { indexOf_data(); } + void indexOf_QString_QLatin1String() { indexOf_impl<QString, QLatin1String>(); } + void indexOf_QString_QStringRef_data() { indexOf_data(); } + void indexOf_QString_QStringRef() { indexOf_impl<QString, QStringRef>(); } + void indexOf_QString_QStringView_data() { indexOf_data(); } + void indexOf_QString_QStringView() { indexOf_impl<QString, QStringView>(); } + + void indexOf_QLatin1String_QString_data() { indexOf_data(); } + void indexOf_QLatin1String_QString() { indexOf_impl<QLatin1String, QString>(); } + void indexOf_QLatin1String_QLatin1String_data() { indexOf_data(); } + void indexOf_QLatin1String_QLatin1String() { indexOf_impl<QLatin1String, QLatin1String>(); } + void indexOf_QLatin1String_QStringRef_data() { indexOf_data(); } + void indexOf_QLatin1String_QStringRef() { indexOf_impl<QLatin1String, QStringRef>(); } + void indexOf_QLatin1String_QStringView_data() { indexOf_data(); } + void indexOf_QLatin1String_QStringView() { indexOf_impl<QLatin1String, QStringView>(); } + + void indexOf_QStringRef_QString_data() { indexOf_data(); } + void indexOf_QStringRef_QString() { indexOf_impl<QStringRef, QString>(); } + void indexOf_QStringRef_QLatin1String_data() { indexOf_data(); } + void indexOf_QStringRef_QLatin1String() { indexOf_impl<QStringRef, QLatin1String>(); } + void indexOf_QStringRef_QStringRef_data() { indexOf_data(); } + void indexOf_QStringRef_QStringRef() { indexOf_impl<QStringRef, QStringRef>(); } + void indexOf_QStringRef_QStringView_data() { indexOf_data(); } + void indexOf_QStringRef_QStringView() { indexOf_impl<QStringRef, QStringView>(); } + + void indexOf_QStringView_QString_data() { indexOf_data(); } + void indexOf_QStringView_QString() { indexOf_impl<QStringView, QString>(); } + void indexOf_QStringView_QLatin1String_data() { indexOf_data(); } + void indexOf_QStringView_QLatin1String() { indexOf_impl<QStringView, QLatin1String>(); } + void indexOf_QStringView_QStringRef_data() { indexOf_data(); } + void indexOf_QStringView_QStringRef() { indexOf_impl<QStringView, QStringRef>(); } + void indexOf_QStringView_QStringView_data() { indexOf_data(); } + void indexOf_QStringView_QStringView() { indexOf_impl<QStringView, QStringView>(); } }; void tst_QStringApiSymmetry::compare_data(bool hasConceptOfNullAndEmpty) @@ -540,6 +609,7 @@ void tst_QStringApiSymmetry::compare_impl() const } static QString empty = QLatin1String(""); +static QString null; // the tests below rely on the fact that these objects' names match their contents: static QString a = QStringLiteral("a"); static QString A = QStringLiteral("A"); @@ -738,6 +808,119 @@ void tst_QStringApiSymmetry::endsWith_impl() const QCOMPARE(haystack.endsWith(needle, Qt::CaseInsensitive), resultCIS); } +void tst_QStringApiSymmetry::split_data(bool rhsHasVariableLength) +{ + QTest::addColumn<QStringRef>("haystackU16"); + QTest::addColumn<QLatin1String>("haystackL1"); + QTest::addColumn<QStringRef>("needleU16"); + QTest::addColumn<QLatin1String>("needleL1"); + QTest::addColumn<QStringList>("resultCS"); + QTest::addColumn<QStringList>("resultCIS"); + + if (rhsHasVariableLength) { + QTest::addRow("null ~= null$") << QStringRef{} << QLatin1String{} + << QStringRef{} << QLatin1String{} + << QStringList{{}, {}} << QStringList{{}, {}}; + QTest::addRow("empty ~= null$") << QStringRef{&empty} << QLatin1String("") + << QStringRef{} << QLatin1String{} + << QStringList{empty, empty} << QStringList{empty, empty}; + QTest::addRow("a ~= null$") << QStringRef{&a} << QLatin1String{"a"} + << QStringRef{} << QLatin1String{} + << QStringList{empty, a, empty} << QStringList{empty, a, empty}; + QTest::addRow("null ~= empty$") << QStringRef{} << QLatin1String{} + << QStringRef{&empty} << QLatin1String{""} + << QStringList{{}, {}} << QStringList{{}, {}}; + QTest::addRow("a ~= empty$") << QStringRef{&a} << QLatin1String{"a"} + << QStringRef{&empty} << QLatin1String{""} + << QStringList{empty, a, empty} << QStringList{empty, a, empty}; + QTest::addRow("empty ~= empty$") << QStringRef{&empty} << QLatin1String{""} + << QStringRef{&empty} << QLatin1String{""} + << QStringList{empty, empty} << QStringList{empty, empty}; + } + QTest::addRow("null ~= a$") << QStringRef{} << QLatin1String{} + << QStringRef{&a} << QLatin1String{"a"} + << QStringList{{}} << QStringList{{}}; + QTest::addRow("empty ~= a$") << QStringRef{&empty} << QLatin1String{""} + << QStringRef{&a} << QLatin1String{"a"} + << QStringList{empty} << QStringList{empty}; + +#define ROW(h, n, cs, cis) \ + QTest::addRow("%s ~= %s$", #h, #n) << QStringRef(&h) << QLatin1String(#h) \ + << QStringRef(&n) << QLatin1String(#n) \ + << QStringList cs << QStringList cis + ROW(a, a, ({empty, empty}), ({empty, empty})); + ROW(a, A, {a}, ({empty, empty})); + ROW(a, b, {a}, {a}); + + if (rhsHasVariableLength) + ROW(b, ab, {b}, {b}); + + ROW(ab, b, ({a, empty}), ({a, empty})); + if (rhsHasVariableLength) { + ROW(ab, ab, ({empty, empty}), ({empty, empty})); + ROW(ab, aB, {ab}, ({empty, empty})); + ROW(ab, Ab, {ab}, ({empty, empty})); + } + ROW(ab, c, {ab}, {ab}); + + if (rhsHasVariableLength) + ROW(bc, abc, {bc}, {bc}); + + ROW(Abc, c, ({Ab, empty}), ({Ab, empty})); +#if 0 + if (rhsHasVariableLength) { + ROW(Abc, bc, 1, 1); + ROW(Abc, bC, 0, 1); + ROW(Abc, Bc, 0, 1); + ROW(Abc, BC, 0, 1); + ROW(aBC, bc, 0, 1); + ROW(aBC, bC, 0, 1); + ROW(aBC, Bc, 0, 1); + ROW(aBC, BC, 1, 1); + } +#endif + ROW(ABC, b, {ABC}, ({A, C})); + ROW(ABC, a, {ABC}, ({empty, BC})); +#undef ROW +} + +static QStringList skipped(const QStringList &sl) +{ + QStringList result; + result.reserve(sl.size()); + for (const QString &s : sl) { + if (!s.isEmpty()) + result.push_back(s); + } + return result; +} + +template <typename Haystack, typename Needle> +void tst_QStringApiSymmetry::split_impl() const +{ + QFETCH(const QStringRef, haystackU16); + QFETCH(const QLatin1String, haystackL1); + QFETCH(const QStringRef, needleU16); + QFETCH(const QLatin1String, needleL1); + QFETCH(const QStringList, resultCS); + QFETCH(const QStringList, resultCIS); + + const QStringList skippedResultCS = skipped(resultCS); + const QStringList skippedResultCIS = skipped(resultCIS); + + const auto haystackU8 = haystackU16.toUtf8(); + const auto needleU8 = needleU16.toUtf8(); + + const auto haystack = make<Haystack>(haystackU16, haystackL1, haystackU8); + const auto needle = make<Needle>(needleU16, needleL1, needleU8); + + QCOMPARE(toQStringList(haystack.split(needle)), resultCS); + QCOMPARE(toQStringList(haystack.split(needle, Qt::KeepEmptyParts, Qt::CaseSensitive)), resultCS); + QCOMPARE(toQStringList(haystack.split(needle, Qt::KeepEmptyParts, Qt::CaseInsensitive)), resultCIS); + QCOMPARE(toQStringList(haystack.split(needle, Qt::SkipEmptyParts, Qt::CaseSensitive)), skippedResultCS); + QCOMPARE(toQStringList(haystack.split(needle, Qt::SkipEmptyParts, Qt::CaseInsensitive)), skippedResultCIS); +} + void tst_QStringApiSymmetry::mid_data() { QTest::addColumn<QStringRef>("unicode"); @@ -1020,7 +1203,7 @@ void tst_QStringApiSymmetry::trimmed_data() for (int len = 0; len < latin1Whitespace.size(); ++len) { for (int pos = 0; pos < latin1Whitespace.size() - len; ++pos) { const QString unicode = latin1Whitespace.mid(pos, len) + str + latin1Whitespace.mid(pos, len); - const QScopedPointer<const char> escaped(QTest::toString(unicode)); + const QScopedArrayPointer<const char> escaped(QTest::toString(unicode)); QTest::addRow("%s", escaped.data()) << unicode << QStringRef(&str); } } @@ -1216,6 +1399,109 @@ void tst_QStringApiSymmetry::toUcs4_impl() QCOMPARE(unicode.isEmpty(), ucs4.isEmpty()); } +void tst_QStringApiSymmetry::indexOf_data() +{ + QTest::addColumn<QString>("haystackU16"); + QTest::addColumn<QLatin1String>("haystackL1"); + QTest::addColumn<QString>("needleU16"); + QTest::addColumn<QLatin1String>("needleL1"); + QTest::addColumn<qsizetype>("startpos"); + QTest::addColumn<qsizetype>("resultCS"); + QTest::addColumn<qsizetype>("resultCIS"); + + constexpr qsizetype zeroPos = 0; + constexpr qsizetype minus1Pos = -1; + + QTest::addRow("haystack: null, needle: null") << null << QLatin1String() + << null << QLatin1String() << zeroPos << zeroPos << zeroPos; + QTest::addRow("haystack: empty, needle: null") << empty << QLatin1String("") + << null << QLatin1String() << zeroPos << zeroPos << zeroPos; + QTest::addRow("haystack: a, needle: null") << a << QLatin1String("a") + << null << QLatin1String() << zeroPos << zeroPos << zeroPos; + QTest::addRow("haystack: null, needle: empty") << null << QLatin1String() + << empty << QLatin1String("") << zeroPos << zeroPos << zeroPos; + QTest::addRow("haystack: a, needle: empty") << a << QLatin1String("a") + << empty << QLatin1String("") << zeroPos << zeroPos << zeroPos; + QTest::addRow("haystack: empty, needle: empty") << empty << QLatin1String("") + << empty << QLatin1String("") << zeroPos << zeroPos << zeroPos; + QTest::addRow("haystack: empty, needle: a") << empty << QLatin1String("") + << a << QLatin1String("a") << zeroPos << minus1Pos << minus1Pos; + QTest::addRow("haystack: null, needle: a") << null << QLatin1String() + << a << QLatin1String("a") << zeroPos << minus1Pos << minus1Pos; + + +#define ROW(h, n, st, cs, cis) \ + QTest::addRow("haystack: %s, needle: %s", #h, #n) << h << QLatin1String(#h) \ + << n << QLatin1String(#n) \ + << qsizetype(st) << qsizetype(cs) << qsizetype(cis) + + ROW(abc, a, 0, 0, 0); + ROW(abc, A, 0, -1, 0); + ROW(abc, a, 1, -1, -1); + ROW(abc, A, 1, -1, -1); + ROW(abc, b, 0, 1, 1); + ROW(abc, B, 0, -1, 1); + ROW(abc, b, 1, 1, 1); + ROW(abc, B, 1, -1, 1); + ROW(abc, B, 2, -1, -1); + + ROW(ABC, A, 0, 0, 0); + ROW(ABC, a, 0, -1, 0); + ROW(ABC, A, 1, -1, -1); + ROW(ABC, a, 1, -1, -1); + ROW(ABC, B, 0, 1, 1); + ROW(ABC, b, 0, -1, 1); + ROW(ABC, B, 1, 1, 1); + ROW(ABC, b, 1, -1, 1); + ROW(ABC, B, 2, -1, -1); + + ROW(aBc, bc, 0, -1, 1); + ROW(aBc, Bc, 0, 1, 1); + ROW(aBc, bC, 0, -1, 1); + ROW(aBc, BC, 0, -1, 1); + + ROW(AbC, bc, 0, -1, 1); + ROW(AbC, Bc, 0, -1, 1); + ROW(AbC, bC, 0, 1, 1); + ROW(AbC, BC, 0, -1, 1); + ROW(AbC, BC, 1, -1, 1); + ROW(AbC, BC, 2, -1, -1); +#undef ROW + +} + +template <typename Haystack, typename Needle> +void tst_QStringApiSymmetry::indexOf_impl() const +{ + QFETCH(const QString, haystackU16); + QFETCH(const QLatin1String, haystackL1); + QFETCH(const QString, needleU16); + QFETCH(const QLatin1String, needleL1); + QFETCH(const qsizetype, startpos); + QFETCH(const qsizetype, resultCS); + QFETCH(const qsizetype, resultCIS); + + const auto haystackU8 = haystackU16.toUtf8(); + const auto needleU8 = needleU16.toUtf8(); + + const auto haystack = make<Haystack>(QStringRef(&haystackU16), haystackL1, haystackU8); + const auto needle = make<Needle>(QStringRef(&needleU16), needleL1, needleU8); + + using size_type = typename Haystack::size_type; + + QCOMPARE(haystack.indexOf(needle, startpos), size_type(resultCS)); + QCOMPARE(haystack.indexOf(needle, startpos, Qt::CaseSensitive), size_type(resultCS)); + QCOMPARE(haystack.indexOf(needle, startpos, Qt::CaseInsensitive), size_type(resultCIS)); + + if (needle.size() == 1) + { + QCOMPARE(haystack.indexOf(needle[0], startpos), size_type(resultCS)); + QCOMPARE(haystack.indexOf(needle[0], startpos, Qt::CaseSensitive), size_type(resultCS)); + QCOMPARE(haystack.indexOf(needle[0], startpos, Qt::CaseInsensitive), size_type(resultCIS)); + } +} + + QTEST_APPLESS_MAIN(tst_QStringApiSymmetry) #include "tst_qstringapisymmetry.moc" diff --git a/tests/auto/corelib/tools/qstringlist/tst_qstringlist.cpp b/tests/auto/corelib/tools/qstringlist/tst_qstringlist.cpp index 42bdf62a93..2b5aa8e98b 100644 --- a/tests/auto/corelib/tools/qstringlist/tst_qstringlist.cpp +++ b/tests/auto/corelib/tools/qstringlist/tst_qstringlist.cpp @@ -30,13 +30,17 @@ #include <qregexp.h> #include <qregularexpression.h> #include <qstringlist.h> +#include <qvector.h> #include <locale.h> +#include <algorithm> + class tst_QStringList : public QObject { Q_OBJECT private slots: + void constructors(); void sort(); void filter(); void replaceInStrings(); @@ -59,13 +63,44 @@ private slots: void joinChar() const; void joinChar_data() const; -#ifdef Q_COMPILER_INITIALIZER_LISTS void initializeList() const; -#endif }; extern const char email[]; +void tst_QStringList::constructors() +{ + { + QStringList list; + QVERIFY(list.isEmpty()); + QCOMPARE(list.size(), 0); + QVERIFY(list == QStringList()); + } + { + QString str = "abc"; + QStringList list(str); + QVERIFY(!list.isEmpty()); + QCOMPARE(list.size(), 1); + QCOMPARE(list.at(0), str); + } + { + QStringList list{ "a", "b", "c" }; + QVERIFY(!list.isEmpty()); + QCOMPARE(list.size(), 3); + QCOMPARE(list.at(0), "a"); + QCOMPARE(list.at(1), "b"); + QCOMPARE(list.at(2), "c"); + } + { + const QVector<QString> reference{ "a", "b", "c" }; + QCOMPARE(reference.size(), 3); + + QStringList list(reference.cbegin(), reference.cend()); + QCOMPARE(list.size(), reference.size()); + QVERIFY(std::equal(list.cbegin(), list.cend(), reference.cbegin())); + } +} + void tst_QStringList::indexOf_regExp() { QStringList list; @@ -482,8 +517,6 @@ void tst_QStringList::joinEmptiness() const QVERIFY(string.isNull()); } -#ifdef Q_COMPILER_INITIALIZER_LISTS -// C++0x support is required void tst_QStringList::initializeList() const { @@ -491,7 +524,6 @@ void tst_QStringList::initializeList() const QCOMPARE(v1, (QStringList() << "hello" << "world" << "plop")); QCOMPARE(v1, (QStringList{"hello","world","plop"})); } -#endif QTEST_APPLESS_MAIN(tst_QStringList) #include "tst_qstringlist.moc" diff --git a/tests/auto/corelib/tools/qtimezone/tst_qtimezone.cpp b/tests/auto/corelib/tools/qtimezone/tst_qtimezone.cpp index 4160a00f71..9904719f7c 100644 --- a/tests/auto/corelib/tools/qtimezone/tst_qtimezone.cpp +++ b/tests/auto/corelib/tools/qtimezone/tst_qtimezone.cpp @@ -915,6 +915,14 @@ void tst_QTimeZone::tzTest() QTzTimeZonePrivate tzp("Europe/Berlin"); QVERIFY(tzp.isValid()); + // Test POSIX-format value for $TZ: + QTzTimeZonePrivate tzposix("MET-1METDST-2,M3.5.0/02:00:00,M10.5.0/03:00:00"); + QVERIFY(tzposix.isValid()); + + QTimeZone tzBrazil("BRT+3"); // parts of Northern Brazil, as a POSIX rule + QVERIFY(tzBrazil.isValid()); + QCOMPARE(tzBrazil.offsetFromUtc(QDateTime(QDate(1111, 11, 11).startOfDay())), -10800); + // Test display names by type, either ICU or abbreviation only QLocale enUS("en_US"); // Only test names in debug mode, names used can vary by ICU version installed diff --git a/tests/auto/corelib/tools/qvarlengtharray/tst_qvarlengtharray.cpp b/tests/auto/corelib/tools/qvarlengtharray/tst_qvarlengtharray.cpp index 5737db760c..fff8c75a90 100644 --- a/tests/auto/corelib/tools/qvarlengtharray/tst_qvarlengtharray.cpp +++ b/tests/auto/corelib/tools/qvarlengtharray/tst_qvarlengtharray.cpp @@ -908,7 +908,6 @@ void tst_QVarLengthArray::initializeListComplex() template<typename T> void tst_QVarLengthArray::initializeList() { -#ifdef Q_COMPILER_INITIALIZER_LISTS T val1(110); T val2(105); T val3(101); @@ -945,9 +944,6 @@ void tst_QVarLengthArray::initializeList() v6 = {}; // assign empty QCOMPARE(v6.size(), 0); -#else - QSKIP("This tests requires a compiler that supports initializer lists."); -#endif } void tst_QVarLengthArray::insertMove() diff --git a/tests/auto/corelib/tools/qvector/tst_qvector.cpp b/tests/auto/corelib/tools/qvector/tst_qvector.cpp index 2278e0ba13..11c255b184 100644 --- a/tests/auto/corelib/tools/qvector/tst_qvector.cpp +++ b/tests/auto/corelib/tools/qvector/tst_qvector.cpp @@ -257,7 +257,6 @@ private slots: void fromListInt() const; void fromListMovable() const; void fromListCustom() const; - void fromStdVector() const; void indexOf() const; void insertInt() const; void insertMovable() const; @@ -296,7 +295,10 @@ private slots: void swapMovable() const; void swapCustom() const; void toList() const; +#if QT_VERSION < QT_VERSION_CHECK(6,0,0) + void fromStdVector() const; void toStdVector() const; +#endif void value() const; void testOperators() const; @@ -329,6 +331,8 @@ private slots: void insertMove() const; + void swapItemsAt() const; + private: template<typename T> void copyConstructor() const; template<typename T> void add() const; @@ -549,7 +553,6 @@ void tst_QVector::assignmentCustom() const template<typename T> void tst_QVector::assignFromInitializerList() const { -#ifdef Q_COMPILER_INITIALIZER_LISTS T val1(SimpleValue<T>::at(1)); T val2(SimpleValue<T>::at(2)); T val3(SimpleValue<T>::at(3)); @@ -560,9 +563,6 @@ void tst_QVector::assignFromInitializerList() const v1 = {}; QCOMPARE(v1.size(), 0); -#else - QSKIP("This test requires support for C++11 initializer lists."); -#endif } void tst_QVector::assignFromInitializerListInt() const @@ -709,7 +709,6 @@ void tst_QVector::appendCustom() const void tst_QVector::appendRvalue() const { -#ifdef Q_COMPILER_RVALUE_REFS QVector<QString> v; v.append("hello"); QString world = "world"; @@ -717,9 +716,6 @@ void tst_QVector::appendRvalue() const QVERIFY(world.isEmpty()); QCOMPARE(v.front(), QString("hello")); QCOMPARE(v.back(), QString("world")); -#else - QSKIP("This test requires that C++11 move semantics support is enabled in the compiler"); -#endif } void tst_QVector::at() const @@ -1434,6 +1430,7 @@ void tst_QVector::fromListCustom() const QCOMPARE(instancesCount, Custom::counter.loadAcquire()); } +#if QT_VERSION < QT_VERSION_CHECK(6,0,0) void tst_QVector::fromStdVector() const { // stl = :( @@ -1447,6 +1444,7 @@ void tst_QVector::fromStdVector() const // test it converts ok QCOMPARE(myvec, QVector<QString>() << "aaa" << "bbb" << "ninjas" << "pirates"); } +#endif void tst_QVector::indexOf() const { @@ -2339,6 +2337,7 @@ void tst_QVector::toList() const QCOMPARE(myvec, QVector<QString>() << "A" << "B" << "C"); } +#if QT_VERSION < QT_VERSION_CHECK(6,0,0) void tst_QVector::toStdVector() const { QVector<QString> myvec; @@ -2351,6 +2350,7 @@ void tst_QVector::toStdVector() const QCOMPARE(myvec, QVector<QString>() << "A" << "B" << "C"); } +#endif void tst_QVector::value() const { @@ -2557,7 +2557,6 @@ void tst_QVector::reallocAfterCopy() template<typename T> void tst_QVector::initializeList() { -#ifdef Q_COMPILER_INITIALIZER_LISTS T val1(SimpleValue<T>::at(1)); T val2(SimpleValue<T>::at(2)); T val3(SimpleValue<T>::at(3)); @@ -2574,7 +2573,6 @@ void tst_QVector::initializeList() QVector<T> v4({}); QCOMPARE(v4.size(), 0); -#endif } void tst_QVector::initializeListInt() @@ -2994,5 +2992,22 @@ void tst_QVector::insertMove() const QCOMPARE(Movable::counter.loadAcquire(), instancesCount); } +void tst_QVector::swapItemsAt() const +{ + QVector<int> v; + v << 0 << 1 << 2 << 3; + + v.swapItemsAt(0, 2); + QCOMPARE(v.at(0), 2); + QCOMPARE(v.at(2), 0); + + auto copy = v; + copy.swapItemsAt(0, 2); + QCOMPARE(v.at(0), 2); + QCOMPARE(v.at(2), 0); + QCOMPARE(copy.at(0), 0); + QCOMPARE(copy.at(2), 2); +} + QTEST_MAIN(tst_QVector) #include "tst_qvector.moc" diff --git a/tests/auto/corelib/tools/qversionnumber/tst_qversionnumber.cpp b/tests/auto/corelib/tools/qversionnumber/tst_qversionnumber.cpp index aaf40a9c2e..7c4d1071ce 100644 --- a/tests/auto/corelib/tools/qversionnumber/tst_qversionnumber.cpp +++ b/tests/auto/corelib/tools/qversionnumber/tst_qversionnumber.cpp @@ -260,12 +260,10 @@ void tst_QVersionNumber::constructorExplicit() QCOMPARE(v5.segments(), v6.segments()); -#ifdef Q_COMPILER_INITIALIZER_LISTS QVersionNumber v7(4, 5, 6); QVersionNumber v8 = {4, 5, 6}; QCOMPARE(v7.segments(), v8.segments()); -#endif } void tst_QVersionNumber::constructorCopy_data() @@ -586,7 +584,6 @@ void tst_QVersionNumber::serialize() void tst_QVersionNumber::moveSemantics() { -#ifdef Q_COMPILER_RVALUE_REFS // QVersionNumber(QVersionNumber &&) { QVersionNumber v1(1, 2, 3); @@ -609,7 +606,6 @@ void tst_QVersionNumber::moveSemantics() QVERIFY(!v2.isNull()); QCOMPARE(v1, v2); } -#endif #ifdef Q_COMPILER_REF_QUALIFIERS // normalized() { @@ -636,9 +632,6 @@ void tst_QVersionNumber::moveSemantics() QVERIFY(!segments.empty()); } #endif -#if !defined(Q_COMPILER_RVALUE_REFS) && !defined(Q_COMPILER_REF_QUALIFIERS) - QSKIP("This test requires C++11 move semantics support in the compiler."); -#endif } void tst_QVersionNumber::qtVersion() diff --git a/tests/auto/gui/image/qimage/qimage.pro b/tests/auto/gui/image/qimage/qimage.pro index b40866892e..0593cfbc23 100644 --- a/tests/auto/gui/image/qimage/qimage.pro +++ b/tests/auto/gui/image/qimage/qimage.pro @@ -7,7 +7,7 @@ qtConfig(c++11): CONFIG += c++11 android:!android-embedded: RESOURCES += qimage.qrc -win32:!winrt: LIBS += -lgdi32 -luser32 +win32:!winrt: QMAKE_USE += user32 gdi32 darwin: LIBS += -framework CoreGraphics TESTDATA += images/* diff --git a/tests/auto/gui/image/qpixmap/qpixmap.pro b/tests/auto/gui/image/qpixmap/qpixmap.pro index e6a020af1a..c9219dad1d 100644 --- a/tests/auto/gui/image/qpixmap/qpixmap.pro +++ b/tests/auto/gui/image/qpixmap/qpixmap.pro @@ -5,7 +5,7 @@ QT += core-private gui-private testlib qtHaveModule(widgets): QT += widgets widgets-private SOURCES += tst_qpixmap.cpp -win32:!winrt:LIBS += -lgdi32 -luser32 +win32:!winrt: QMAKE_USE += user32 gdi32 RESOURCES += qpixmap.qrc TESTDATA += convertFromImage/* convertFromToHICON/* loadFromData/* images/* diff --git a/tests/auto/gui/itemmodels/qstandarditemmodel/tst_qstandarditemmodel.cpp b/tests/auto/gui/itemmodels/qstandarditemmodel/tst_qstandarditemmodel.cpp index 550f70890e..bc8bc38da6 100644 --- a/tests/auto/gui/itemmodels/qstandarditemmodel/tst_qstandarditemmodel.cpp +++ b/tests/auto/gui/itemmodels/qstandarditemmodel/tst_qstandarditemmodel.cpp @@ -734,7 +734,7 @@ void tst_QStandardItemModel::data() currentRoles.clear(); // bad args m_model->setData(QModelIndex(), "bla", Qt::DisplayRole); - QCOMPARE(currentRoles, {}); + QCOMPARE(currentRoles, QVector<int>{}); QIcon icon; for (int r=0; r < m_model->rowCount(); ++r) { @@ -742,9 +742,9 @@ void tst_QStandardItemModel::data() m_model->setData(m_model->index(r,c), "initialitem", Qt::DisplayRole); QCOMPARE(currentRoles, QVector<int>({Qt::DisplayRole, Qt::EditRole})); m_model->setData(m_model->index(r,c), "tooltip", Qt::ToolTipRole); - QCOMPARE(currentRoles, {Qt::ToolTipRole}); + QCOMPARE(currentRoles, QVector<int>{Qt::ToolTipRole}); m_model->setData(m_model->index(r,c), icon, Qt::DecorationRole); - QCOMPARE(currentRoles, {Qt::DecorationRole}); + QCOMPARE(currentRoles, QVector<int>{Qt::DecorationRole}); } } @@ -761,7 +761,7 @@ void tst_QStandardItemModel::clearItemData() { currentRoles.clear(); QVERIFY(!m_model->clearItemData(QModelIndex())); - QCOMPARE(currentRoles, {}); + QCOMPARE(currentRoles, QVector<int>{}); const QModelIndex idx = m_model->index(0, 0); const QMap<int, QVariant> oldData = m_model->itemData(idx); m_model->setData(idx, QLatin1String("initialitem"), Qt::DisplayRole); @@ -773,7 +773,7 @@ void tst_QStandardItemModel::clearItemData() QCOMPARE(idx.data(Qt::ToolTipRole), QVariant()); QCOMPARE(idx.data(Qt::DisplayRole), QVariant()); QCOMPARE(idx.data(Qt::EditRole), QVariant()); - QCOMPARE(currentRoles, {}); + QCOMPARE(currentRoles, QVector<int>{}); m_model->setItemData(idx, oldData); currentRoles.clear(); } diff --git a/tests/auto/gui/kernel/noqteventloop/noqteventloop.pro b/tests/auto/gui/kernel/noqteventloop/noqteventloop.pro index 7e98704aea..293a6a8581 100644 --- a/tests/auto/gui/kernel/noqteventloop/noqteventloop.pro +++ b/tests/auto/gui/kernel/noqteventloop/noqteventloop.pro @@ -5,4 +5,4 @@ QT += core-private network gui-private testlib SOURCES += tst_noqteventloop.cpp -qtConfig(dynamicgl):win32:!winrt: LIBS += -luser32 +qtConfig(dynamicgl):win32:!winrt: QMAKE_USE += user32 diff --git a/tests/auto/gui/kernel/qguiapplication/tst_qguiapplication.cpp b/tests/auto/gui/kernel/qguiapplication/tst_qguiapplication.cpp index a304981cd1..09fec89de4 100644 --- a/tests/auto/gui/kernel/qguiapplication/tst_qguiapplication.cpp +++ b/tests/auto/gui/kernel/qguiapplication/tst_qguiapplication.cpp @@ -989,9 +989,13 @@ void tst_QGuiApplication::genericPluginsAndWindowSystemEvents() QCoreApplication::postEvent(&testReceiver, new QEvent(QEvent::User)); QCOMPARE(testReceiver.customEvents, 0); +#if QT_VERSION >= QT_VERSION_CHECK(6, 0, 0) + QStaticPlugin testPluginInfo(qt_plugin_instance, qt_plugin_query_metadata); +#else QStaticPlugin testPluginInfo; testPluginInfo.instance = qt_plugin_instance; testPluginInfo.rawMetaData = qt_plugin_query_metadata; +#endif qRegisterStaticPluginFunction(testPluginInfo); int argc = 3; char *argv[] = { const_cast<char*>(QTest::currentAppName()), const_cast<char*>("-plugin"), const_cast<char*>("testplugin") }; diff --git a/tests/auto/gui/kernel/qkeyevent/tst_qkeyevent.cpp b/tests/auto/gui/kernel/qkeyevent/tst_qkeyevent.cpp index bad021c3b0..9a4c560a08 100644 --- a/tests/auto/gui/kernel/qkeyevent/tst_qkeyevent.cpp +++ b/tests/auto/gui/kernel/qkeyevent/tst_qkeyevent.cpp @@ -121,7 +121,7 @@ static QByteArray modifiersTestRowName(const QString &keySequence) if (uc > 32 && uc < 128) str << '"' << c << '"'; else - str << "U+" << hex << uc << dec; + str << "U+" << Qt::hex << uc << Qt::dec; if (i < size - 1) str << ','; } diff --git a/tests/auto/gui/kernel/qpalette/tst_qpalette.cpp b/tests/auto/gui/kernel/qpalette/tst_qpalette.cpp index 234793a7cf..6ce6422f48 100644 --- a/tests/auto/gui/kernel/qpalette/tst_qpalette.cpp +++ b/tests/auto/gui/kernel/qpalette/tst_qpalette.cpp @@ -141,7 +141,6 @@ void tst_QPalette::copySemantics() void tst_QPalette::moveSemantics() { -#ifdef Q_COMPILER_RVALUE_REFS QPalette src(Qt::red), dst; const QPalette control = src; QVERIFY(src != dst); @@ -163,9 +162,6 @@ void tst_QPalette::moveSemantics() QVERIFY(dst2.isCopyOf(dst)); QVERIFY(dst2.isCopyOf(control)); // check moved-from 'src' can still be destroyed (doesn't crash) -#else - QSKIP("Compiler doesn't support C++11 move semantics"); -#endif } void tst_QPalette::setBrush() diff --git a/tests/auto/gui/kernel/qwindow/BLACKLIST b/tests/auto/gui/kernel/qwindow/BLACKLIST index caf39742f6..1820499a53 100644 --- a/tests/auto/gui/kernel/qwindow/BLACKLIST +++ b/tests/auto/gui/kernel/qwindow/BLACKLIST @@ -17,6 +17,8 @@ android [modalWindowEnterEventOnHide_QTBUG35109] ubuntu-16.04 osx ci +[spuriousMouseMove] +windows ci # QTBUG-69162 android [modalDialogClosingOneOfTwoModal] diff --git a/tests/auto/gui/kernel/qwindow/qwindow.pro b/tests/auto/gui/kernel/qwindow/qwindow.pro index 844b3e8507..e7931ca773 100644 --- a/tests/auto/gui/kernel/qwindow/qwindow.pro +++ b/tests/auto/gui/kernel/qwindow/qwindow.pro @@ -5,4 +5,4 @@ QT += core-private gui-private testlib SOURCES += tst_qwindow.cpp -qtConfig(dynamicgl):win32:!winrt: LIBS += -luser32 +qtConfig(dynamicgl):win32:!winrt: QMAKE_USE += user32 diff --git a/tests/auto/gui/kernel/qwindow/tst_qwindow.cpp b/tests/auto/gui/kernel/qwindow/tst_qwindow.cpp index 9415908383..4f26950192 100644 --- a/tests/auto/gui/kernel/qwindow/tst_qwindow.cpp +++ b/tests/auto/gui/kernel/qwindow/tst_qwindow.cpp @@ -45,10 +45,6 @@ # include <QtCore/qt_windows.h> #endif -// For QSignalSpy slot connections. -Q_DECLARE_METATYPE(Qt::ScreenOrientation) -Q_DECLARE_METATYPE(QWindow::Visibility) - static bool isPlatformWinRT() { static const bool isWinRT = !QGuiApplication::platformName().compare(QLatin1String("winrt"), Qt::CaseInsensitive); @@ -185,7 +181,7 @@ void tst_QWindow::setParent() QVERIFY2(c.children().contains(&d), "Parent should have child in list of children"); a.create(); - b.setParent(0); + b.setParent(nullptr); QVERIFY2(!b.handle(), "Making window top level shouild not automatically create it"); QWindow e; @@ -228,7 +224,7 @@ void tst_QWindow::setVisible() f.setVisible(true); QVERIFY(!f.handle()); QVERIFY(!e.handle()); - f.setParent(0); + f.setParent(nullptr); QVERIFY2(f.handle(), "Making a visible but not created child window top level should create it"); QVERIFY(QTest::qWaitForWindowExposed(&f)); @@ -304,7 +300,7 @@ public: m_framePositionsOnMove.clear(); } - bool event(QEvent *event) + bool event(QEvent *event) override { m_received[event->type()]++; m_order << event->type(); @@ -323,6 +319,7 @@ public: case QEvent::WindowStateChange: lastReceivedWindowState = windowState(); + break; default: break; @@ -363,7 +360,7 @@ private: class ColoredWindow : public QRasterWindow { public: - explicit ColoredWindow(const QColor &color, QWindow *parent = 0) : QRasterWindow(parent), m_color(color) {} + explicit ColoredWindow(const QColor &color, QWindow *parent = nullptr) : QRasterWindow(parent), m_color(color) {} void paintEvent(QPaintEvent *) override { QPainter p(this); @@ -381,6 +378,7 @@ void tst_QWindow::eventOrderOnShow() QRect geometry(m_availableTopLeft + QPoint(80, 80), m_testWindowSize); Window window; + window.setTitle(QLatin1String(QTest::currentTestFunction())); window.setGeometry(geometry); window.show(); QCoreApplication::processEvents(); @@ -440,12 +438,12 @@ void tst_QWindow::exposeEventOnShrink_QTBUG54040() void tst_QWindow::positioning_data() { - QTest::addColumn<int>("windowflags"); + QTest::addColumn<Qt::WindowFlags>("windowflags"); - QTest::newRow("default") << int(Qt::Window | Qt::WindowTitleHint | Qt::WindowMinMaxButtonsHint | Qt::WindowCloseButtonHint | Qt::WindowFullscreenButtonHint); + QTest::newRow("default") << (Qt::Window | Qt::WindowTitleHint | Qt::WindowMinMaxButtonsHint | Qt::WindowCloseButtonHint | Qt::WindowFullscreenButtonHint); -#ifdef Q_OS_OSX - QTest::newRow("fake") << int(Qt::Window | Qt::WindowTitleHint | Qt::WindowMinMaxButtonsHint | Qt::WindowCloseButtonHint); +#ifdef Q_OS_MACOS + QTest::newRow("fake") << (Qt::Window | Qt::WindowTitleHint | Qt::WindowMinMaxButtonsHint | Qt::WindowCloseButtonHint); #endif } @@ -500,8 +498,8 @@ void tst_QWindow::positioning() // events, so set the width to suitably large value to avoid those. const QRect geometry(m_availableTopLeft + QPoint(80, 80), m_testWindowSize); - QFETCH(int, windowflags); - Window window((Qt::WindowFlags)windowflags); + QFETCH(Qt::WindowFlags, windowflags); + Window window(windowflags); window.setGeometry(QRect(m_availableTopLeft + QPoint(20, 20), m_testWindowSize)); window.setFramePosition(m_availableTopLeft + QPoint(40, 40)); // Move window around before show, size must not change. QCOMPARE(window.geometry().size(), m_testWindowSize); @@ -628,14 +626,12 @@ void tst_QWindow::childWindowPositioning() QFETCH(bool, showInsteadOfCreate); - QWindow* windows[] = { &topLevelWindowFirst, &childWindowAfter, &childWindowFirst, &topLevelWindowAfter, 0 }; - for (int i = 0; windows[i]; ++i) { - QWindow *window = windows[i]; - if (showInsteadOfCreate) { + QWindow *windows[] = {&topLevelWindowFirst, &childWindowAfter, &childWindowFirst, &topLevelWindowAfter}; + for (QWindow *window : windows) { + if (showInsteadOfCreate) window->showNormal(); - } else { + else window->create(); - } } if (showInsteadOfCreate) { @@ -712,7 +708,7 @@ void tst_QWindow::stateChange() // explicitly use non-fullscreen show. show() can be fullscreen on some platforms window.showNormal(); QVERIFY(QTest::qWaitForWindowExposed(&window)); - foreach (Qt::WindowState state, stateSequence) { + for (Qt::WindowState state : qAsConst(stateSequence)) { window.setWindowState(state); QCoreApplication::processEvents(); } @@ -726,15 +722,9 @@ class PlatformWindowFilter : public QObject { Q_OBJECT public: - PlatformWindowFilter(QObject *parent = 0) - : QObject(parent) - , m_window(nullptr) - , m_alwaysExisted(true) - {} - - void setWindow(Window *window) { m_window = window; } + explicit PlatformWindowFilter(Window *window) : m_window(window) {} - bool eventFilter(QObject *o, QEvent *e) + bool eventFilter(QObject *o, QEvent *e) override { // Check that the platform surface events are delivered synchronously. // If they are, the native platform surface should always exist when we @@ -749,7 +739,7 @@ public: private: Window *m_window; - bool m_alwaysExisted; + bool m_alwaysExisted = true; }; void tst_QWindow::platformSurface() @@ -757,8 +747,7 @@ void tst_QWindow::platformSurface() QRect geometry(m_availableTopLeft + QPoint(80, 80), m_testWindowSize); Window window; - PlatformWindowFilter filter; - filter.setWindow(&window); + PlatformWindowFilter filter(&window); window.installEventFilter(&filter); window.setGeometry(geometry); @@ -784,6 +773,7 @@ void tst_QWindow::isExposed() QRect geometry(m_availableTopLeft + QPoint(80, 80), m_testWindowSize); Window window; + window.setTitle(QLatin1String(QTest::currentTestFunction())); window.setGeometry(geometry); QCOMPARE(window.geometry(), geometry); window.show(); @@ -818,6 +808,7 @@ void tst_QWindow::isActive() QSKIP("QWindow::requestActivate() is not supported."); Window window; + window.setTitle(QLatin1String(QTest::currentTestFunction())); // Some platforms enforce minimum widths for windows, which can cause extra resize // events, so set the width to suitably large value to avoid those. window.setGeometry(QRect(m_availableTopLeft + QPoint(80, 80), m_testWindowSize)); @@ -916,13 +907,16 @@ void tst_QWindow::isActive() class InputTestWindow : public ColoredWindow { public: - void keyPressEvent(QKeyEvent *event) { + void keyPressEvent(QKeyEvent *event) override + { keyPressCode = event->key(); } - void keyReleaseEvent(QKeyEvent *event) { + void keyReleaseEvent(QKeyEvent *event) override + { keyReleaseCode = event->key(); } - void mousePressEvent(QMouseEvent *event) { + void mousePressEvent(QMouseEvent *event) override + { if (ignoreMouse) { event->ignore(); } else { @@ -935,7 +929,8 @@ public: QCoreApplication::processEvents(); } } - void mouseReleaseEvent(QMouseEvent *event) { + void mouseReleaseEvent(QMouseEvent *event) override + { if (ignoreMouse) { event->ignore(); } else { @@ -944,7 +939,8 @@ public: mouseReleaseButton = event->button(); } } - void mouseMoveEvent(QMouseEvent *event) { + void mouseMoveEvent(QMouseEvent *event) override + { buttonStateInGeneratedMove = event->buttons(); if (ignoreMouse) { event->ignore(); @@ -954,7 +950,8 @@ public: mouseMoveScreenPos = event->screenPos(); } } - void mouseDoubleClickEvent(QMouseEvent *event) { + void mouseDoubleClickEvent(QMouseEvent *event) override + { if (ignoreMouse) { event->ignore(); } else { @@ -962,7 +959,8 @@ public: mouseSequenceSignature += 'd'; } } - void touchEvent(QTouchEvent *event) { + void touchEvent(QTouchEvent *event) override + { if (ignoreTouch) { event->ignore(); return; @@ -987,7 +985,8 @@ public: } } } - bool event(QEvent *e) { + bool event(QEvent *e) override + { switch (e->type()) { case QEvent::Enter: ++enterEventCount; @@ -998,37 +997,31 @@ public: default: break; } - return QWindow::event(e); + return ColoredWindow::event(e); } - void resetCounters() { + void resetCounters() + { mousePressedCount = mouseReleasedCount = mouseMovedCount = mouseDoubleClickedCount = 0; - mouseSequenceSignature = QString(); + mouseSequenceSignature.clear(); touchPressedCount = touchReleasedCount = touchMovedCount = 0; enterEventCount = leaveEventCount = 0; } explicit InputTestWindow(const QColor &color = Qt::white, QWindow *parent = nullptr) - : ColoredWindow(color, parent) - { - keyPressCode = keyReleaseCode = 0; - mousePressButton = mouseReleaseButton = mouseMoveButton = 0; - ignoreMouse = ignoreTouch = false; - spinLoopWhenPressed = false; - resetCounters(); - } + : ColoredWindow(color, parent) {} - int keyPressCode, keyReleaseCode; - int mousePressButton, mouseReleaseButton, mouseMoveButton; - int mousePressedCount, mouseReleasedCount, mouseMovedCount, mouseDoubleClickedCount; + int keyPressCode = 0, keyReleaseCode = 0; + int mousePressButton = 0, mouseReleaseButton = 0, mouseMoveButton = 0; + int mousePressedCount = 0, mouseReleasedCount = 0, mouseMovedCount = 0, mouseDoubleClickedCount = 0; QString mouseSequenceSignature; QPointF mousePressScreenPos, mouseMoveScreenPos, mousePressLocalPos; - int touchPressedCount, touchReleasedCount, touchMovedCount; - QEvent::Type touchEventType; - int enterEventCount, leaveEventCount; + int touchPressedCount = 0, touchReleasedCount = 0, touchMovedCount = 0; + QEvent::Type touchEventType = QEvent::None; + int enterEventCount = 0, leaveEventCount = 0; - bool ignoreMouse, ignoreTouch; + bool ignoreMouse = false, ignoreTouch = false; - bool spinLoopWhenPressed; + bool spinLoopWhenPressed = false; Qt::MouseButtons buttonStateInGeneratedMove; }; @@ -1073,15 +1066,15 @@ void tst_QWindow::testInputEvents() window.mousePressButton = window.mouseReleaseButton = 0; const QPointF nonWindowGlobal(window.geometry().topRight() + QPoint(200, 50)); // not inside the window const QPointF deviceNonWindowGlobal = QHighDpi::toNativePixels(nonWindowGlobal, window.screen()); - QWindowSystemInterface::handleMouseEvent(0, deviceNonWindowGlobal, deviceNonWindowGlobal, Qt::LeftButton); - QWindowSystemInterface::handleMouseEvent(0, deviceNonWindowGlobal, deviceNonWindowGlobal, Qt::NoButton); + QWindowSystemInterface::handleMouseEvent(nullptr, deviceNonWindowGlobal, deviceNonWindowGlobal, Qt::LeftButton); + QWindowSystemInterface::handleMouseEvent(nullptr, deviceNonWindowGlobal, deviceNonWindowGlobal, Qt::NoButton); QCoreApplication::processEvents(); QCOMPARE(window.mousePressButton, 0); QCOMPARE(window.mouseReleaseButton, 0); const QPointF windowGlobal = window.mapToGlobal(local.toPoint()); const QPointF deviceWindowGlobal = QHighDpi::toNativePixels(windowGlobal, window.screen()); - QWindowSystemInterface::handleMouseEvent(0, deviceWindowGlobal, deviceWindowGlobal, Qt::LeftButton); - QWindowSystemInterface::handleMouseEvent(0, deviceWindowGlobal, deviceWindowGlobal, Qt::NoButton); + QWindowSystemInterface::handleMouseEvent(nullptr, deviceWindowGlobal, deviceWindowGlobal, Qt::LeftButton); + QWindowSystemInterface::handleMouseEvent(nullptr, deviceWindowGlobal, deviceWindowGlobal, Qt::NoButton); QCoreApplication::processEvents(); QCOMPARE(window.mousePressButton, int(Qt::LeftButton)); QCOMPARE(window.mouseReleaseButton, int(Qt::LeftButton)); @@ -1092,6 +1085,7 @@ void tst_QWindow::testInputEvents() void tst_QWindow::touchToMouseTranslation() { InputTestWindow window; + window.setTitle(QLatin1String(QTest::currentTestFunction())); window.ignoreTouch = true; window.setGeometry(QRect(m_availableTopLeft + QPoint(80, 80), m_testWindowSize)); window.show(); @@ -1145,7 +1139,7 @@ void tst_QWindow::touchToMouseTranslation() QTRY_COMPARE(window.mousePressButton, 0); QTRY_COMPARE(window.mouseReleaseButton, 0); - qApp->setAttribute(Qt::AA_SynthesizeMouseForUnhandledTouchEvents, false); + QCoreApplication::setAttribute(Qt::AA_SynthesizeMouseForUnhandledTouchEvents, false); window.ignoreTouch = true; points[0].state = Qt::TouchPointPressed; @@ -1156,7 +1150,7 @@ void tst_QWindow::touchToMouseTranslation() QWindowSystemInterface::handleTouchEvent(&window, touchDevice, points); QCoreApplication::processEvents(); - qApp->setAttribute(Qt::AA_SynthesizeMouseForUnhandledTouchEvents, true); + QCoreApplication::setAttribute(Qt::AA_SynthesizeMouseForUnhandledTouchEvents, true); // mouse event synthesizing disabled QTRY_COMPARE(window.mousePressButton, 0); @@ -1166,6 +1160,7 @@ void tst_QWindow::touchToMouseTranslation() void tst_QWindow::touchToMouseTranslationForDevices() { InputTestWindow window; + window.setTitle(QLatin1String(QTest::currentTestFunction())); window.ignoreTouch = true; window.setGeometry(QRect(m_availableTopLeft + QPoint(80, 80), m_testWindowSize)); window.show(); @@ -1194,9 +1189,10 @@ void tst_QWindow::touchToMouseTranslationForDevices() void tst_QWindow::mouseToTouchTranslation() { - qApp->setAttribute(Qt::AA_SynthesizeTouchForUnhandledMouseEvents, true); + QCoreApplication::setAttribute(Qt::AA_SynthesizeTouchForUnhandledMouseEvents, true); InputTestWindow window; + window.setTitle(QLatin1String(QTest::currentTestFunction())); window.ignoreMouse = true; window.setGeometry(QRect(m_availableTopLeft + QPoint(80, 80), m_testWindowSize)); window.show(); @@ -1206,12 +1202,12 @@ void tst_QWindow::mouseToTouchTranslation() QWindowSystemInterface::handleMouseEvent(&window, QPoint(10, 10), window.mapToGlobal(QPoint(10, 10)), Qt::NoButton); QCoreApplication::processEvents(); - qApp->setAttribute(Qt::AA_SynthesizeTouchForUnhandledMouseEvents, false); + QCoreApplication::setAttribute(Qt::AA_SynthesizeTouchForUnhandledMouseEvents, false); QTRY_COMPARE(window.touchPressedCount, 1); QTRY_COMPARE(window.touchReleasedCount, 1); - qApp->setAttribute(Qt::AA_SynthesizeTouchForUnhandledMouseEvents, true); + QCoreApplication::setAttribute(Qt::AA_SynthesizeTouchForUnhandledMouseEvents, true); window.ignoreMouse = false; @@ -1219,7 +1215,7 @@ void tst_QWindow::mouseToTouchTranslation() QWindowSystemInterface::handleMouseEvent(&window, QPoint(10, 10), window.mapToGlobal(QPoint(10, 10)), Qt::NoButton); QCoreApplication::processEvents(); - qApp->setAttribute(Qt::AA_SynthesizeTouchForUnhandledMouseEvents, false); + QCoreApplication::setAttribute(Qt::AA_SynthesizeTouchForUnhandledMouseEvents, false); // no new touch events should be generated since the input window handles the mouse events QTRY_COMPARE(window.touchPressedCount, 1); @@ -1241,10 +1237,12 @@ void tst_QWindow::mouseToTouchTranslation() void tst_QWindow::mouseToTouchLoop() { // make sure there's no infinite loop when synthesizing both ways - qApp->setAttribute(Qt::AA_SynthesizeTouchForUnhandledMouseEvents, true); - qApp->setAttribute(Qt::AA_SynthesizeMouseForUnhandledTouchEvents, true); + QCoreApplication::setAttribute(Qt::AA_SynthesizeTouchForUnhandledMouseEvents, true); + QCoreApplication::setAttribute(Qt::AA_SynthesizeMouseForUnhandledTouchEvents, true); InputTestWindow window; + window.setTitle(QLatin1String(QTest::currentTestFunction())); + window.ignoreMouse = true; window.ignoreTouch = true; window.setGeometry(QRect(m_availableTopLeft + QPoint(80, 80), m_testWindowSize)); @@ -1255,13 +1253,14 @@ void tst_QWindow::mouseToTouchLoop() QWindowSystemInterface::handleMouseEvent(&window, QPoint(10, 10), window.mapToGlobal(QPoint(10, 10)), Qt::NoButton); QCoreApplication::processEvents(); - qApp->setAttribute(Qt::AA_SynthesizeTouchForUnhandledMouseEvents, false); - qApp->setAttribute(Qt::AA_SynthesizeMouseForUnhandledTouchEvents, true); + QCoreApplication::setAttribute(Qt::AA_SynthesizeTouchForUnhandledMouseEvents, false); + QCoreApplication::setAttribute(Qt::AA_SynthesizeMouseForUnhandledTouchEvents, true); } void tst_QWindow::touchCancel() { InputTestWindow window; + window.setTitle(QLatin1String(QTest::currentTestFunction())); window.setGeometry(QRect(m_availableTopLeft + QPoint(80, 80), m_testWindowSize)); window.show(); QVERIFY(QTest::qWaitForWindowExposed(&window)); @@ -1321,6 +1320,7 @@ void tst_QWindow::touchCancel() void tst_QWindow::touchCancelWithTouchToMouse() { InputTestWindow window; + window.setTitle(QLatin1String(QTest::currentTestFunction())); window.ignoreTouch = true; window.setGeometry(QRect(m_availableTopLeft + QPoint(80, 80), m_testWindowSize)); window.show(); @@ -1343,7 +1343,7 @@ void tst_QWindow::touchCancelWithTouchToMouse() // Cancel the touch. Should result in a mouse release for windows that have // have an active touch-to-mouse sequence. - QWindowSystemInterface::handleTouchCancelEvent(0, touchDevice); + QWindowSystemInterface::handleTouchCancelEvent(nullptr, touchDevice); QCoreApplication::processEvents(); QTRY_COMPARE(window.mouseReleaseButton, int(Qt::LeftButton)); @@ -1358,7 +1358,7 @@ void tst_QWindow::touchCancelWithTouchToMouse() QTRY_COMPARE(window.mousePressButton, 0); // Cancel the touch. It should not result in a mouse release with this window. - QWindowSystemInterface::handleTouchCancelEvent(0, touchDevice); + QWindowSystemInterface::handleTouchCancelEvent(nullptr, touchDevice); QCoreApplication::processEvents(); QTRY_COMPARE(window.mouseReleaseButton, 0); } @@ -1369,6 +1369,7 @@ void tst_QWindow::touchInterruptedByPopup() QSKIP("Wayland: This test crashes with xdg-shell unstable v6"); InputTestWindow window; + window.setTitle(QLatin1String(QTest::currentTestFunction())); window.setGeometry(QRect(m_availableTopLeft + QPoint(80, 80), m_testWindowSize)); window.show(); QVERIFY(QTest::qWaitForWindowExposed(&window)); @@ -1489,6 +1490,7 @@ void tst_QWindow::sizes() void tst_QWindow::close() { QWindow a; + a.setTitle(QLatin1String(QTest::currentTestFunction())); QWindow b; QWindow c(&a); @@ -1506,8 +1508,9 @@ void tst_QWindow::activateAndClose() if (!QGuiApplicationPrivate::platformIntegration()->hasCapability(QPlatformIntegration::WindowActivation)) QSKIP("QWindow::requestActivate() is not supported."); - for (int i = 0; i < 10; ++i) { + for (int i = 0; i < 10; ++i) { QWindow window; + window.setTitle(QLatin1String(QTest::currentTestFunction()) + QString::number(i)); #if defined(Q_OS_QNX) window.setSurfaceType(QSurface::OpenGLSurface); #endif @@ -1525,15 +1528,16 @@ void tst_QWindow::activateAndClose() #endif window.requestActivate(); QVERIFY(QTest::qWaitForWindowActive(&window)); - QCOMPARE(qGuiApp->focusWindow(), &window); + QCOMPARE(QGuiApplication::focusWindow(), &window); } } void tst_QWindow::mouseEventSequence() { - int doubleClickInterval = qGuiApp->styleHints()->mouseDoubleClickInterval(); + const auto doubleClickInterval = ulong(QGuiApplication::styleHints()->mouseDoubleClickInterval()); InputTestWindow window; + window.setTitle(QLatin1String(QTest::currentTestFunction())); window.setGeometry(QRect(m_availableTopLeft + QPoint(80, 80), m_testWindowSize)); window.show(); QVERIFY(QTest::qWaitForWindowExposed(&window)); @@ -1655,6 +1659,7 @@ void tst_QWindow::windowModality() void tst_QWindow::inputReentrancy() { InputTestWindow window; + window.setTitle(QLatin1String(QTest::currentTestFunction())); window.spinLoopWhenPressed = true; window.setGeometry(QRect(m_availableTopLeft + QPoint(80, 80), m_testWindowSize)); @@ -1700,17 +1705,20 @@ void tst_QWindow::inputReentrancy() class TabletTestWindow : public QWindow { public: - TabletTestWindow() : eventType(QEvent::None) { } - void tabletEvent(QTabletEvent *ev) { + void tabletEvent(QTabletEvent *ev) override + { eventType = ev->type(); eventGlobal = ev->globalPosF(); eventLocal = ev->posF(); eventDevice = ev->device(); } - QEvent::Type eventType; + + QEvent::Type eventType = QEvent::None; QPointF eventGlobal, eventLocal; - int eventDevice; - bool eventFilter(QObject *obj, QEvent *ev) { + int eventDevice = -1; + + bool eventFilter(QObject *obj, QEvent *ev) override + { if (ev->type() == QEvent::TabletEnterProximity || ev->type() == QEvent::TabletLeaveProximity) { eventType = ev->type(); @@ -1758,6 +1766,7 @@ void tst_QWindow::tabletEvents() void tst_QWindow::windowModality_QTBUG27039() { QWindow parent; + parent.setTitle(QLatin1String(QTest::currentTestFunction())); parent.setGeometry(QRect(m_availableTopLeft + QPoint(10, 10), m_testWindowSize)); parent.show(); @@ -1868,6 +1877,7 @@ void tst_QWindow::initialSize() QSize defaultSize(0,0); { Window w; + w.setTitle(QLatin1String(QTest::currentTestFunction())); w.showNormal(); QTRY_VERIFY(w.width() > 0); QTRY_VERIFY(w.height() > 0); @@ -1875,6 +1885,7 @@ void tst_QWindow::initialSize() } { Window w; + w.setTitle(QLatin1String(QTest::currentTestFunction())); w.setWidth(m_testWindowSize.width()); w.showNormal(); if (isPlatformWinRT()) @@ -1884,6 +1895,7 @@ void tst_QWindow::initialSize() } { Window w; + w.setTitle(QLatin1String(QTest::currentTestFunction())); const QSize testSize(m_testWindowSize.width(), 42); w.resize(testSize); w.showNormal(); @@ -1910,6 +1922,7 @@ void tst_QWindow::modalDialog() QSKIP("Test fails due to QTBUG-61965, and is slow due to QTBUG-61964"); QWindow normalWindow; + normalWindow.setTitle(QLatin1String(QTest::currentTestFunction())); normalWindow.setFramePosition(m_availableTopLeft + QPoint(80, 80)); normalWindow.resize(m_testWindowSize); normalWindow.show(); @@ -1945,6 +1958,7 @@ void tst_QWindow::modalDialogClosingOneOfTwoModal() QSKIP("QWindow::requestActivate() is not supported."); QWindow normalWindow; + normalWindow.setTitle(QLatin1String(QTest::currentTestFunction())); normalWindow.setFramePosition(m_availableTopLeft + QPoint(80, 80)); normalWindow.resize(m_testWindowSize); normalWindow.show(); @@ -1992,6 +2006,7 @@ void tst_QWindow::modalWithChildWindow() QSKIP("QWindow::requestActivate() is not supported."); QWindow normalWindow; + normalWindow.setTitle(QLatin1String(QTest::currentTestFunction())); normalWindow.setFramePosition(m_availableTopLeft + QPoint(80, 80)); normalWindow.resize(m_testWindowSize); normalWindow.show(); @@ -2028,6 +2043,7 @@ void tst_QWindow::modalWindowModallity() QSKIP("QWindow::requestActivate() is not supported."); QWindow normal_window; + normal_window.setTitle(QLatin1String(QTest::currentTestFunction())); normal_window.setFramePosition(m_availableTopLeft + QPoint(80, 80)); normal_window.resize(m_testWindowSize); normal_window.show(); @@ -2058,6 +2074,7 @@ void tst_QWindow::modalWindowModallity() void tst_QWindow::modalWindowPosition() { QWindow window; + window.setTitle(QLatin1String(QTest::currentTestFunction())); window.setGeometry(QRect(m_availableTopLeft + QPoint(100, 100), m_testWindowSize)); // Allow for any potential resizing due to constraints QRect origGeo = window.geometry(); @@ -2341,6 +2358,7 @@ void tst_QWindow::requestUpdate() QRect geometry(m_availableTopLeft + QPoint(80, 80), m_testWindowSize); Window window; + window.setTitle(QLatin1String(QTest::currentTestFunction())); window.setGeometry(geometry); window.show(); QCoreApplication::processEvents(); @@ -2370,10 +2388,10 @@ void tst_QWindow::flags() class EventWindow : public QWindow { public: - EventWindow() : QWindow(), gotBlocked(false) {} - bool gotBlocked; + bool gotBlocked = false; + protected: - bool event(QEvent *e) + bool event(QEvent *e) override { if (e->type() == QEvent::WindowBlocked) gotBlocked = true; @@ -2384,6 +2402,7 @@ protected: void tst_QWindow::testBlockingWindowShownAfterModalDialog() { EventWindow normalWindow; + normalWindow.setTitle(QLatin1String(QTest::currentTestFunction())); normalWindow.setFramePosition(m_availableTopLeft + QPoint(80, 80)); normalWindow.resize(m_testWindowSize); normalWindow.show(); @@ -2411,6 +2430,7 @@ void tst_QWindow::testBlockingWindowShownAfterModalDialog() void tst_QWindow::generatedMouseMove() { InputTestWindow w; + w.setTitle(QLatin1String(QTest::currentTestFunction())); w.setGeometry(QRect(m_availableTopLeft + QPoint(100, 100), m_testWindowSize)); w.setFlags(w.flags() | Qt::FramelessWindowHint); // ### FIXME: QTBUG-63542 w.show(); @@ -2422,34 +2442,34 @@ void tst_QWindow::generatedMouseMove() QTest::mouseMove(&w, point); QVERIFY(w.mouseMovedCount == 1); // A press event that does not change position should not generate mouse move - QTest::mousePress(&w, Qt::LeftButton, 0, point); - QTest::mousePress(&w, Qt::RightButton, 0, point); + QTest::mousePress(&w, Qt::LeftButton, Qt::KeyboardModifiers(), point); + QTest::mousePress(&w, Qt::RightButton, Qt::KeyboardModifiers(), point); QVERIFY(w.mouseMovedCount == 1); // Verify that a move event is generated for a mouse release event that changes position point += step; - QTest::mouseRelease(&w, Qt::LeftButton, 0, point); + QTest::mouseRelease(&w, Qt::LeftButton,Qt::KeyboardModifiers(), point); QVERIFY(w.mouseMovedCount == 2); QVERIFY(w.buttonStateInGeneratedMove == (Qt::LeftButton | Qt::RightButton)); point += step; - QTest::mouseRelease(&w, Qt::RightButton, 0, point); + QTest::mouseRelease(&w, Qt::RightButton, Qt::KeyboardModifiers(), point); QVERIFY(w.mouseMovedCount == 3); QVERIFY(w.buttonStateInGeneratedMove == Qt::RightButton); // Verify that a move event is generated for a mouse press event that changes position point += step; - QTest::mousePress(&w, Qt::LeftButton, 0, point); + QTest::mousePress(&w, Qt::LeftButton, Qt::KeyboardModifiers(), point); QVERIFY(w.mouseMovedCount == 4); QVERIFY(w.buttonStateInGeneratedMove == Qt::NoButton); point += step; - QTest::mousePress(&w, Qt::RightButton, 0, point); + QTest::mousePress(&w, Qt::RightButton, Qt::KeyboardModifiers(), point); QVERIFY(w.mouseMovedCount == 5); QVERIFY(w.buttonStateInGeneratedMove == Qt::LeftButton); // A release event that does not change position should not generate mouse move - QTest::mouseRelease(&w, Qt::RightButton, 0, point); - QTest::mouseRelease(&w, Qt::LeftButton, 0, point); + QTest::mouseRelease(&w, Qt::RightButton, Qt::KeyboardModifiers(), point); + QTest::mouseRelease(&w, Qt::LeftButton, Qt::KeyboardModifiers(), point); QVERIFY(w.mouseMovedCount == 5); } @@ -2458,6 +2478,7 @@ void tst_QWindow::keepPendingUpdateRequests() QRect geometry(m_availableTopLeft + QPoint(80, 80), m_testWindowSize); Window window; + window.setTitle(QLatin1String(QTest::currentTestFunction())); window.setGeometry(geometry); window.show(); QCoreApplication::processEvents(); diff --git a/tests/auto/gui/painting/qcolor/tst_qcolor.cpp b/tests/auto/gui/painting/qcolor/tst_qcolor.cpp index 4d92bdd382..90a216e14a 100644 --- a/tests/auto/gui/painting/qcolor/tst_qcolor.cpp +++ b/tests/auto/gui/painting/qcolor/tst_qcolor.cpp @@ -94,8 +94,8 @@ private slots: void convertTo(); - void light(); - void dark(); + void lighter(); + void darker(); void specConstructor_data(); void specConstructor(); @@ -1419,17 +1419,17 @@ void tst_QColor::convertTo() QCOMPARE(invalid.spec(), QColor::Invalid); } -void tst_QColor::light() +void tst_QColor::lighter() { QColor gray(Qt::gray); - QColor lighter = gray.light(); + QColor lighter = gray.lighter(); QVERIFY(lighter.value() > gray.value()); } -void tst_QColor::dark() +void tst_QColor::darker() { QColor gray(Qt::gray); - QColor darker = gray.dark(); + QColor darker = gray.darker(); QVERIFY(darker.value() < gray.value()); } diff --git a/tests/auto/gui/painting/qcolorspace/tst_qcolorspace.cpp b/tests/auto/gui/painting/qcolorspace/tst_qcolorspace.cpp index 35bca58854..7a88eb18b2 100644 --- a/tests/auto/gui/painting/qcolorspace/tst_qcolorspace.cpp +++ b/tests/auto/gui/painting/qcolorspace/tst_qcolorspace.cpp @@ -33,6 +33,8 @@ #include <qimage.h> #include <qimagereader.h> +#include <private/qcolorspace_p.h> + Q_DECLARE_METATYPE(QColorSpace::ColorSpaceId) Q_DECLARE_METATYPE(QColorSpace::Gamut) Q_DECLARE_METATYPE(QColorSpace::TransferFunction) @@ -59,6 +61,10 @@ private slots: void loadImage(); void gamut(); + void primariesXyz(); + void primaries2_data(); + void primaries2(); + void invalidPrimaries(); }; tst_QColorSpace::tst_QColorSpace() @@ -289,5 +295,67 @@ void tst_QColorSpace::gamut() QVERIFY(tgreen.blueF() > 0.2); } +void tst_QColorSpace::primariesXyz() +{ + QColorSpace sRgb = QColorSpace::SRgb; + QColorSpace adobeRgb = QColorSpace::AdobeRgb; + QColorSpace displayP3 = QColorSpace::DisplayP3; + QColorSpace proPhotoRgb = QColorSpace::ProPhotoRgb; + QColorSpace bt2020 = QColorSpace::Bt2020; + + // Check if our calculated matrices, match the precalculated ones. + QCOMPARE(sRgb.d_func()->toXyz, QColorMatrix::toXyzFromSRgb()); + QCOMPARE(adobeRgb.d_func()->toXyz, QColorMatrix::toXyzFromAdobeRgb()); + QCOMPARE(displayP3.d_func()->toXyz, QColorMatrix::toXyzFromDciP3D65()); + QCOMPARE(proPhotoRgb.d_func()->toXyz, QColorMatrix::toXyzFromProPhotoRgb()); + QCOMPARE(bt2020.d_func()->toXyz, QColorMatrix::toXyzFromBt2020()); +} + +void tst_QColorSpace::primaries2_data() +{ + QTest::addColumn<QColorSpace::Gamut>("gamut"); + + QTest::newRow("sRGB") << QColorSpace::Gamut::SRgb; + QTest::newRow("DCI-P3 (D65)") << QColorSpace::Gamut::DciP3D65; + QTest::newRow("Adobe RGB (1998)") << QColorSpace::Gamut::AdobeRgb; + QTest::newRow("ProPhoto RGB") << QColorSpace::Gamut::ProPhotoRgb; + QTest::newRow("BT.2020") << QColorSpace::Gamut::Bt2020; +} + +void tst_QColorSpace::primaries2() +{ + QFETCH(QColorSpace::Gamut, gamut); + QColorSpacePrimaries primaries(gamut); + + QColorSpace original(gamut, QColorSpace::TransferFunction::Linear); + QColorSpace custom1(primaries.whitePoint, primaries.redPoint, + primaries.greenPoint, primaries.bluePoint, QColorSpace::TransferFunction::Linear); + QCOMPARE(original, custom1); + + // A custom color swizzled color-space: + QColorSpace custom2(primaries.whitePoint, primaries.bluePoint, + primaries.greenPoint, primaries.redPoint, QColorSpace::TransferFunction::Linear); + + QVERIFY(custom1 != custom2); + QColor color1(255, 127, 63); + QColor color2 = custom1.transformationToColorSpace(custom2).map(color1); + QCOMPARE(color2.red(), color1.blue()); + QCOMPARE(color2.green(), color1.green()); + QCOMPARE(color2.blue(), color1.red()); + QCOMPARE(color2.alpha(), color1.alpha()); + QColor color3 = custom2.transformationToColorSpace(custom1).map(color2); + QCOMPARE(color3.red(), color1.red()); + QCOMPARE(color3.green(), color1.green()); + QCOMPARE(color3.blue(), color1.blue()); + QCOMPARE(color3.alpha(), color1.alpha()); +} + +void tst_QColorSpace::invalidPrimaries() +{ + QColorSpace custom(QPointF(), QPointF(), QPointF(), QPointF(), QColorSpace::TransferFunction::Linear); + QVERIFY(!custom.isValid()); + QCOMPARE(custom.colorSpaceId(), QColorSpace::Undefined); +} + QTEST_MAIN(tst_QColorSpace) #include "tst_qcolorspace.moc" diff --git a/tests/auto/gui/painting/qpainter/tst_qpainter.cpp b/tests/auto/gui/painting/qpainter/tst_qpainter.cpp index cec164b8b2..2b53169a45 100644 --- a/tests/auto/gui/painting/qpainter/tst_qpainter.cpp +++ b/tests/auto/gui/painting/qpainter/tst_qpainter.cpp @@ -370,10 +370,10 @@ void tst_QPainter::getSetCheck() // bool QPainter::matrixEnabled() // void QPainter::setMatrixEnabled(bool) - obj1.setMatrixEnabled(false); - QCOMPARE(false, obj1.matrixEnabled()); - obj1.setMatrixEnabled(true); - QCOMPARE(true, obj1.matrixEnabled()); + obj1.setWorldMatrixEnabled(false); + QCOMPARE(false, obj1.worldMatrixEnabled()); + obj1.setWorldMatrixEnabled(true); + QCOMPARE(true, obj1.worldMatrixEnabled()); // bool QPainter::viewTransformEnabled() // void QPainter::setViewTransformEnabled(bool) @@ -699,7 +699,7 @@ void tst_QPainter::initFrom() QCOMPARE(p.font(), font); QCOMPARE(p.pen().color(), pal.color(QPalette::Foreground)); - QCOMPARE(p.background(), pal.background()); + QCOMPARE(p.background(), pal.window()); delete widget; } @@ -3197,7 +3197,7 @@ void tst_QPainter::largeImagePainting() p.translate(4, 0); } - p.resetMatrix(); + p.resetTransform(); for (int i = 4; i < img.height(); i += 4) { p.translate(0, 4); diff --git a/tests/auto/gui/painting/qpdfwriter/tst_qpdfwriter.cpp b/tests/auto/gui/painting/qpdfwriter/tst_qpdfwriter.cpp index c1a8f7f0de..9e9b0db366 100644 --- a/tests/auto/gui/painting/qpdfwriter/tst_qpdfwriter.cpp +++ b/tests/auto/gui/painting/qpdfwriter/tst_qpdfwriter.cpp @@ -154,12 +154,7 @@ void tst_QPdfWriter::testPageMetrics() if (setMargins) { // Setup the given margins - QPdfWriter::Margins margins; - margins.left = leftMMf; - margins.right = rightMMf; - margins.top = topMMf; - margins.bottom = bottomMMf; - writer.setMargins(margins); + writer.setPageMargins({leftMMf, topMMf, rightMMf, bottomMMf}, QPageLayout::Millimeter); QCOMPARE(writer.margins().left, leftMMf); QCOMPARE(writer.margins().right, rightMMf); QCOMPARE(writer.margins().top, topMMf); @@ -169,7 +164,7 @@ void tst_QPdfWriter::testPageMetrics() // Set the given size, in Portrait mode if (pageSize < 0) { - writer.setPageSizeMM(sizeMMf); + writer.setPageSize(QPageSize(sizeMMf, QPageSize::Millimeter)); QCOMPARE(writer.pageSize(), QPdfWriter::Custom); QCOMPARE(writer.pageLayout().pageSize().id(), QPageSize::Custom); } else { @@ -221,7 +216,7 @@ void tst_QPdfWriter::testPageMetrics() // Now while in Landscape mode, set the size again, results should be the same if (pageSize < 0) { - writer.setPageSizeMM(sizeMMf); + writer.setPageSize(QPageSize(sizeMMf, QPageSize::Millimeter)); QCOMPARE(writer.pageSize(), QPdfWriter::Custom); QCOMPARE(writer.pageLayout().pageSize().id(), QPageSize::Custom); } else { @@ -255,7 +250,7 @@ void tst_QPdfWriter::qtbug59443() QTemporaryFile file; QVERIFY2(file.open(), qPrintable(file.errorString())); QPdfWriter writer(file.fileName()); - writer.setPageSize(QPdfWriter::A4); + writer.setPageSize(QPageSize(QPageSize::A4)); QTextDocument doc; doc.documentLayout()->setPaintDevice(&writer); diff --git a/tests/auto/gui/qopenglconfig/tst_qopenglconfig.cpp b/tests/auto/gui/qopenglconfig/tst_qopenglconfig.cpp index f8dfdbd3b0..b82b277781 100644 --- a/tests/auto/gui/qopenglconfig/tst_qopenglconfig.cpp +++ b/tests/auto/gui/qopenglconfig/tst_qopenglconfig.cpp @@ -200,7 +200,7 @@ static void dumpGlConfiguration(QOpenGLContext &context, QTextStream &str) << "\nShading language : " << reinterpret_cast<const char *>(functions.glGetString(GL_SHADING_LANGUAGE_VERSION)) << "\nFormat : " << context.format(); - QList<QByteArray> extensionList = context.extensions().toList(); + QList<QByteArray> extensionList = context.extensions().values(); std::sort(extensionList.begin(), extensionList.end()); const int extensionCount = extensionList.size(); str << "\n\nFound " << extensionCount << " extensions:\n"; @@ -233,9 +233,9 @@ void tst_QOpenGlConfig::testGlConfiguration() static inline QByteArray msgSetMismatch(const QSet<QString> &expected, const QSet<QString> &actual) { - const QString result = QStringList(expected.toList()).join(QLatin1Char(',')) + const QString result = QStringList(expected.values()).join(QLatin1Char(',')) + QLatin1String(" != ") - + QStringList(actual.toList()).join(QLatin1Char(',')); + + QStringList(actual.values()).join(QLatin1Char(',')); return result.toLatin1(); } diff --git a/tests/auto/gui/text/qfontdatabase/BLACKLIST b/tests/auto/gui/text/qfontdatabase/BLACKLIST new file mode 100644 index 0000000000..0870ca11d7 --- /dev/null +++ b/tests/auto/gui/text/qfontdatabase/BLACKLIST @@ -0,0 +1,2 @@ +[systemFixedFont] # QTBUG-54623 +b2qt diff --git a/tests/auto/gui/text/qfontdatabase/tst_qfontdatabase.cpp b/tests/auto/gui/text/qfontdatabase/tst_qfontdatabase.cpp index 68664cdd2f..2b69801b59 100644 --- a/tests/auto/gui/text/qfontdatabase/tst_qfontdatabase.cpp +++ b/tests/auto/gui/text/qfontdatabase/tst_qfontdatabase.cpp @@ -35,6 +35,8 @@ #include <private/qrawfont_p.h> #include <qpa/qplatformfontdatabase.h> +Q_LOGGING_CATEGORY(lcTests, "qt.text.tests") + class tst_QFontDatabase : public QObject { Q_OBJECT @@ -49,6 +51,7 @@ private slots: void fixedPitch_data(); void fixedPitch(); + void systemFixedFont(); #ifdef Q_OS_MAC void trickyFonts_data(); @@ -156,6 +159,16 @@ void tst_QFontDatabase::fixedPitch() QCOMPARE(fi.fixedPitch(), fixedPitch); } +void tst_QFontDatabase::systemFixedFont() // QTBUG-54623 +{ + QFont font = QFontDatabase::systemFont(QFontDatabase::FixedFont); + QFontInfo fontInfo(font); + bool fdbSaysFixed = QFontDatabase().isFixedPitch(fontInfo.family(), fontInfo.styleName()); + qCDebug(lcTests) << "system fixed font is" << font << "really fixed?" << fdbSaysFixed << fontInfo.fixedPitch(); + QVERIFY(fdbSaysFixed); + QVERIFY(fontInfo.fixedPitch()); +} + #ifdef Q_OS_MAC void tst_QFontDatabase::trickyFonts_data() { @@ -198,8 +211,8 @@ void tst_QFontDatabase::widthTwoTimes() f.setPixelSize(pixelSize); QFontMetrics fm(f); - int w1 = fm.charWidth(text, 0); - int w2 = fm.charWidth(text, 0); + int w1 = fm.horizontalAdvance(text, 0); + int w2 = fm.horizontalAdvance(text, 0); QCOMPARE(w1, w2); } diff --git a/tests/auto/gui/text/qstatictext/tst_qstatictext.cpp b/tests/auto/gui/text/qstatictext/tst_qstatictext.cpp index d00dc251d8..b091edb64d 100644 --- a/tests/auto/gui/text/qstatictext/tst_qstatictext.cpp +++ b/tests/auto/gui/text/qstatictext/tst_qstatictext.cpp @@ -681,7 +681,7 @@ static bool checkPixels(const QImage &image, if (pixel != expectedRgb1 && pixel != expectedRgb2) { QString message; QDebug(&message) << "Color mismatch in image" << image - << "at" << x << ',' << y << ':' << showbase << hex << pixel + << "at" << x << ',' << y << ':' << Qt::showbase << Qt::hex << pixel << "(expected: " << expectedRgb1 << ',' << expectedRgb2 << ')'; *errorMessage = message.toLocal8Bit(); return false; diff --git a/tests/auto/gui/text/qtextdocumentfragment/tst_qtextdocumentfragment.cpp b/tests/auto/gui/text/qtextdocumentfragment/tst_qtextdocumentfragment.cpp index fe0b6dae49..3a118f8c91 100644 --- a/tests/auto/gui/text/qtextdocumentfragment/tst_qtextdocumentfragment.cpp +++ b/tests/auto/gui/text/qtextdocumentfragment/tst_qtextdocumentfragment.cpp @@ -944,7 +944,7 @@ void tst_QTextDocumentFragment::namedAnchorFragments3() QCOMPARE(it.fragment().text(), QString::fromLatin1("T")); QVERIFY(it.fragment().charFormat().isAnchor()); - QCOMPARE(it.fragment().charFormat().anchorName(), QString("target")); + QCOMPARE(it.fragment().charFormat().anchorNames().constFirst(), QLatin1String("target")); QStringList targets; targets << "target" << "target2"; QCOMPARE(it.fragment().charFormat().anchorNames(), targets); diff --git a/tests/auto/gui/text/qtextdocumentlayout/tst_qtextdocumentlayout.cpp b/tests/auto/gui/text/qtextdocumentlayout/tst_qtextdocumentlayout.cpp index c79f787547..f66b16b970 100644 --- a/tests/auto/gui/text/qtextdocumentlayout/tst_qtextdocumentlayout.cpp +++ b/tests/auto/gui/text/qtextdocumentlayout/tst_qtextdocumentlayout.cpp @@ -59,6 +59,8 @@ private slots: void imageAtRightAlignedTab(); void blockVisibility(); + void largeImage(); + private: QTextDocument *doc; }; @@ -347,5 +349,63 @@ void tst_QTextDocumentLayout::blockVisibility() QCOMPARE(doc->size(), halfSize); } +void tst_QTextDocumentLayout::largeImage() +{ + auto img = QImage(400, 500, QImage::Format_ARGB32_Premultiplied); + img.fill(Qt::black); + + { + QTextDocument document; + + document.addResource(QTextDocument::ImageResource, + QUrl("data://test.png"), QVariant(img)); + document.setPageSize({500, 504}); + + auto html = "<img src=\"data://test.png\">"; + document.setHtml(html); + + QCOMPARE(document.pageCount(), 2); + } + + { + QTextDocument document; + + document.addResource(QTextDocument::ImageResource, + QUrl("data://test.png"), QVariant(img)); + document.setPageSize({500, 508}); + + auto html = "<img src=\"data://test.png\">"; + document.setHtml(html); + + QCOMPARE(document.pageCount(), 1); + } + + { + QTextDocument document; + + document.addResource(QTextDocument::ImageResource, + QUrl("data://test.png"), QVariant(img)); + document.setPageSize({585, 250}); + + auto html = "<img src=\"data://test.png\">"; + document.setHtml(html); + + QCOMPARE(document.pageCount(), 3); + } + + { + QTextDocument document; + + document.addResource(QTextDocument::ImageResource, + QUrl("data://test.png"), QVariant(img)); + document.setPageSize({585, 258}); + + auto html = "<img src=\"data://test.png\">"; + document.setHtml(html); + + QCOMPARE(document.pageCount(), 2); + } +} + QTEST_MAIN(tst_QTextDocumentLayout) #include "tst_qtextdocumentlayout.moc" diff --git a/tests/auto/gui/text/qtextlayout/tst_qtextlayout.cpp b/tests/auto/gui/text/qtextlayout/tst_qtextlayout.cpp index 9610e5b830..aee2f970fe 100644 --- a/tests/auto/gui/text/qtextlayout/tst_qtextlayout.cpp +++ b/tests/auto/gui/text/qtextlayout/tst_qtextlayout.cpp @@ -2228,7 +2228,6 @@ void tst_QTextLayout::superscriptCrash_qtbug53911() for (int j = 0; j < 4; ++j) { QTextLayout* newTextLayout = new QTextLayout(); newTextLayout->setText(layoutText); - QList<QTextLayout::FormatRange> formatRanges; QTextLayout::FormatRange formatRange; formatRange.format.setFont(QFont()); @@ -2257,8 +2256,7 @@ void tst_QTextLayout::superscriptCrash_qtbug53911() formatRange.start = 0; formatRange.length = layoutText.size(); - formatRanges << formatRange; - newTextLayout->setAdditionalFormats(formatRanges); + newTextLayout->setFormats({formatRange}); textLayouts.push_front(newTextLayout); } @@ -2289,10 +2287,7 @@ void tst_QTextLayout::nbspWithFormat() formatRange.length = 1; formatRange.format.setFontUnderline(true); - QList<QTextLayout::FormatRange> overrides; - overrides.append(formatRange); - - layout.setAdditionalFormats(overrides); + layout.setFormats({formatRange}); layout.beginLayout(); forever { @@ -2327,7 +2322,7 @@ void tst_QTextLayout::koreanWordWrap() QTextLine line = layout.createLine(); if (!line.isValid()) break; - line.setLineWidth(metrics.width(s) * 0.8); + line.setLineWidth(metrics.horizontalAdvance(s) * 0.8); } layout.endLayout(); QCOMPARE(layout.lineCount(), 2); diff --git a/tests/auto/gui/text/qtextlist/tst_qtextlist.cpp b/tests/auto/gui/text/qtextlist/tst_qtextlist.cpp index d623ce4044..93e40e7f23 100644 --- a/tests/auto/gui/text/qtextlist/tst_qtextlist.cpp +++ b/tests/auto/gui/text/qtextlist/tst_qtextlist.cpp @@ -314,7 +314,7 @@ void tst_QTextList::partialRemoval() selection.deleteChar(); // deletes the second list QVERIFY(!secondList); - QVERIFY(!firstList->isEmpty()); + QVERIFY(firstList->count() > 0); doc->undo(); } diff --git a/tests/auto/gui/text/qtextmarkdownimporter/data/headingBulletsContinuations.md b/tests/auto/gui/text/qtextmarkdownimporter/data/headingBulletsContinuations.md new file mode 100644 index 0000000000..99eb633d17 --- /dev/null +++ b/tests/auto/gui/text/qtextmarkdownimporter/data/headingBulletsContinuations.md @@ -0,0 +1,28 @@ +# heading +- bullet 1 + continuation line 1, indented via tab +- bullet 2 + continuation line 2, indented via 4 spaces +- bullet 3 + + continuation paragraph 3, indented via tab + + - bullet 3.1 + + continuation paragraph 3.1, indented via 4 spaces + + - bullet 3.2 + continuation line, indented via 2 tabs +- bullet 4 + + continuation paragraph 4, indented via 4 spaces + and continuing onto another line too + +- bullet 5 + + continuation paragraph 5, indented via 2 spaces and continuing onto another + line too + +- bullet 6 + +plain old paragraph at the end diff --git a/tests/auto/gui/text/qtextmarkdownimporter/data/thematicBreaks.md b/tests/auto/gui/text/qtextmarkdownimporter/data/thematicBreaks.md new file mode 100644 index 0000000000..7a0d5388ad --- /dev/null +++ b/tests/auto/gui/text/qtextmarkdownimporter/data/thematicBreaks.md @@ -0,0 +1,17 @@ +Heading +------- +*** +stars +- bullet + ** not a bullet or a rule, just two stars +- [ ] unchecked + + --- indented too far, so not a rule +* * * +stars with tabs between +*** +stars with whitespace after +--- +hyphens with whitespace after +_____ +underscores with whitespace after diff --git a/tests/auto/gui/text/qtextmarkdownimporter/qtextmarkdownimporter.pro b/tests/auto/gui/text/qtextmarkdownimporter/qtextmarkdownimporter.pro new file mode 100644 index 0000000000..7b7fb61244 --- /dev/null +++ b/tests/auto/gui/text/qtextmarkdownimporter/qtextmarkdownimporter.pro @@ -0,0 +1,9 @@ +CONFIG += testcase +TARGET = tst_qtextmarkdownimporter +QT += core-private gui-private testlib +SOURCES += tst_qtextmarkdownimporter.cpp +TESTDATA += \ + data/thematicBreaks.md \ + data/headingBulletsContinuations.md \ + +DEFINES += SRCDIR=\\\"$$PWD\\\" diff --git a/tests/auto/gui/text/qtextmarkdownimporter/tst_qtextmarkdownimporter.cpp b/tests/auto/gui/text/qtextmarkdownimporter/tst_qtextmarkdownimporter.cpp new file mode 100644 index 0000000000..8f51a7a474 --- /dev/null +++ b/tests/auto/gui/text/qtextmarkdownimporter/tst_qtextmarkdownimporter.cpp @@ -0,0 +1,163 @@ +/**************************************************************************** +** +** Copyright (C) 2019 The Qt Company Ltd. +** Contact: https://www.qt.io/licensing/ +** +** This file is part of the test suite of the Qt Toolkit. +** +** $QT_BEGIN_LICENSE:GPL-EXCEPT$ +** Commercial License Usage +** Licensees holding valid commercial Qt licenses may use this file in +** accordance with the commercial license agreement provided with the +** Software or, alternatively, in accordance with the terms contained in +** a written agreement between you and The Qt Company. For licensing terms +** and conditions see https://www.qt.io/terms-conditions. For further +** information use the contact form at https://www.qt.io/contact-us. +** +** GNU General Public License Usage +** Alternatively, this file may be used under the terms of the GNU +** General Public License version 3 as published by the Free Software +** Foundation with exceptions as appearing in the file LICENSE.GPL3-EXCEPT +** included in the packaging of this file. Please review the following +** information to ensure the GNU General Public License requirements will +** be met: https://www.gnu.org/licenses/gpl-3.0.html. +** +** $QT_END_LICENSE$ +** +****************************************************************************/ + +#include <QtTest/QtTest> +#include <QTextDocument> +#include <QTextCursor> +#include <QTextBlock> +#include <QTextList> +#include <QTextTable> +#include <QBuffer> +#include <QDebug> + +#include <private/qtextmarkdownimporter_p.h> + +// #define DEBUG_WRITE_HTML + +Q_LOGGING_CATEGORY(lcTests, "qt.text.tests") + +static const QChar LineBreak = QChar(0x2028); +static const QChar Tab = QLatin1Char('\t'); +static const QChar Space = QLatin1Char(' '); +static const QChar Period = QLatin1Char('.'); + +class tst_QTextMarkdownImporter : public QObject +{ + Q_OBJECT + +private slots: + void headingBulletsContinuations(); + void thematicBreaks(); +}; + +void tst_QTextMarkdownImporter::headingBulletsContinuations() +{ + const QStringList expectedBlocks = QStringList() << + "" << // we could do without this blank line before the heading, but currently it happens + "heading" << + "bullet 1 continuation line 1, indented via tab" << + "bullet 2 continuation line 2, indented via 4 spaces" << + "bullet 3" << + "continuation paragraph 3, indented via tab" << + "bullet 3.1" << + "continuation paragraph 3.1, indented via 4 spaces" << + "bullet 3.2 continuation line, indented via 2 tabs" << + "bullet 4" << + "continuation paragraph 4, indented via 4 spaces and continuing onto another line too" << + "bullet 5" << + // indenting by only 2 spaces is perhaps non-standard but currently is OK + "continuation paragraph 5, indented via 2 spaces and continuing onto another line too" << + "bullet 6" << + "plain old paragraph at the end"; + + QFile f(QFINDTESTDATA("data/headingBulletsContinuations.md")); + QVERIFY(f.open(QFile::ReadOnly | QIODevice::Text)); + QString md = QString::fromUtf8(f.readAll()); + f.close(); + + QTextDocument doc; + QTextMarkdownImporter(QTextMarkdownImporter::DialectGitHub).import(&doc, md); + QTextFrame::iterator iterator = doc.rootFrame()->begin(); + QTextFrame *currentFrame = iterator.currentFrame(); + QStringList::const_iterator expectedIt = expectedBlocks.constBegin(); + int i = 0; + while (!iterator.atEnd()) { + // There are no child frames + QCOMPARE(iterator.currentFrame(), currentFrame); + // Check whether we got the right child block + QTextBlock block = iterator.currentBlock(); + QCOMPARE(block.text().contains(LineBreak), false); + QCOMPARE(block.text().contains(Tab), false); + QVERIFY(!block.text().startsWith(Space)); + int expectedIndentation = 0; + if (block.text().contains(QLatin1String("continuation paragraph"))) + expectedIndentation = (block.text().contains(Period) ? 2 : 1); + qCDebug(lcTests) << i << "child block" << block.text() << "indentation" << block.blockFormat().indent(); + QVERIFY(expectedIt != expectedBlocks.constEnd()); + QCOMPARE(block.text(), *expectedIt); + if (i > 2) + QCOMPARE(block.blockFormat().indent(), expectedIndentation); + ++iterator; + ++expectedIt; + ++i; + } + QCOMPARE(expectedIt, expectedBlocks.constEnd()); + +#ifdef DEBUG_WRITE_HTML + { + QFile out("/tmp/headingBulletsContinuations.html"); + out.open(QFile::WriteOnly); + out.write(doc.toHtml().toLatin1()); + out.close(); + } +#endif +} + +void tst_QTextMarkdownImporter::thematicBreaks() +{ + int horizontalRuleCount = 0; + int textLinesCount = 0; + + QFile f(QFINDTESTDATA("data/thematicBreaks.md")); + QVERIFY(f.open(QFile::ReadOnly | QIODevice::Text)); + QString md = QString::fromUtf8(f.readAll()); + f.close(); + + QTextDocument doc; + QTextMarkdownImporter(QTextMarkdownImporter::DialectGitHub).import(&doc, md); + QTextFrame::iterator iterator = doc.rootFrame()->begin(); + QTextFrame *currentFrame = iterator.currentFrame(); + int i = 0; + while (!iterator.atEnd()) { + // There are no child frames + QCOMPARE(iterator.currentFrame(), currentFrame); + // Check whether the block is text or a horizontal rule + QTextBlock block = iterator.currentBlock(); + if (block.blockFormat().hasProperty(QTextFormat::BlockTrailingHorizontalRulerWidth)) + ++horizontalRuleCount; + else if (!block.text().isEmpty()) + ++textLinesCount; + qCDebug(lcTests) << i << (block.blockFormat().hasProperty(QTextFormat::BlockTrailingHorizontalRulerWidth) ? QLatin1String("- - -") : block.text()); + ++iterator; + ++i; + } + QCOMPARE(horizontalRuleCount, 5); + QCOMPARE(textLinesCount, 9); + +#ifdef DEBUG_WRITE_HTML + { + QFile out("/tmp/thematicBreaks.html"); + out.open(QFile::WriteOnly); + out.write(doc.toHtml().toLatin1()); + out.close(); + } +#endif +} + +QTEST_MAIN(tst_QTextMarkdownImporter) +#include "tst_qtextmarkdownimporter.moc" diff --git a/tests/auto/gui/text/qtextmarkdownwriter/BLACKLIST b/tests/auto/gui/text/qtextmarkdownwriter/BLACKLIST new file mode 100644 index 0000000000..fc9e5a9efe --- /dev/null +++ b/tests/auto/gui/text/qtextmarkdownwriter/BLACKLIST @@ -0,0 +1,3 @@ +[rewriteDocument] +winrt # QTBUG-54623 + diff --git a/tests/auto/gui/text/qtextmarkdownwriter/data/blockquotes.md b/tests/auto/gui/text/qtextmarkdownwriter/data/blockquotes.md new file mode 100644 index 0000000000..f429fcc21b --- /dev/null +++ b/tests/auto/gui/text/qtextmarkdownwriter/data/blockquotes.md @@ -0,0 +1,39 @@ +In 1958, Mahatma Gandhi was quoted as follows: + +> The Earth provides enough to satisfy every man's need but not for every man's +> greed. + +In [The CommonMark Specification](https://spec.commonmark.org/0.29/) John +MacFarlane writes: + +> What distinguishes Markdown from many other lightweight markup syntaxes, +> which are often easier to write, is its readability. As Gruber writes: + +> > The overriding design goal for Markdown's formatting syntax is to make it +> > as readable as possible. The idea is that a Markdown-formatted document should +> > be publishable as-is, as plain text, without looking like it's been marked up +> > with tags or formatting instructions. ( +> > [http://daringfireball.net/projects/markdown/](http://daringfireball.net/projects/markdown/)) + +> The point can be illustrated by comparing a sample of AsciiDoc with an +> equivalent sample of Markdown. Here is a sample of AsciiDoc from the AsciiDoc +> manual: + +> 1. List item one. +> + +> List item one continued with a second paragraph followed by an +> Indented block. +> + +> ................. +> $ ls *.sh +> $ mv *.sh ~/tmp +> ................. +> + +> List item continued with a third paragraph. +> +> 2. List item two continued with an open block. +> ... +> +The quotation includes an embedded quotation and a code quotation and ends with +an ellipsis due to being incomplete. + diff --git a/tests/auto/gui/text/qtextmarkdownwriter/data/example.md b/tests/auto/gui/text/qtextmarkdownwriter/data/example.md new file mode 100644 index 0000000000..0c3f34e09d --- /dev/null +++ b/tests/auto/gui/text/qtextmarkdownwriter/data/example.md @@ -0,0 +1,95 @@ +# QTextEdit + +The QTextEdit widget is an advanced editor that supports formatted rich text. +It can be used to display HTML and other rich document formats. Internally, +QTextEdit uses the QTextDocument class to describe both the high-level +structure of each document and the low-level formatting of paragraphs. + +If you are viewing this document in the textedit example, you can edit this +document to explore Qt's rich text editing features. We have included some +comments in each of the following sections to encourage you to experiment. + +## Font and Paragraph Styles + +QTextEdit supports **bold**, *italic*, and ~~strikethrough~~ font styles, and can +display multicolored text. Font families such as Times New Roman and `Courier` +can also be used directly. *If you place the cursor in a region of styled text, +the controls in the tool bars will change to reflect the current style.* + +Paragraphs can be formatted so that the text is left-aligned, right-aligned, +centered, or fully justified. + +*Try changing the alignment of some text and resize the editor to see how the +text layout changes.* + +## Lists + +Different kinds of lists can be included in rich text documents. Standard +bullet lists can be nested, using different symbols for each level of the list: + +- Disc symbols are typically used for top-level list items. + * Circle symbols can be used to distinguish between items in lower-level + lists. + + Square symbols provide a reasonable alternative to discs and circles. + +Ordered lists can be created that can be used for tables of contents. Different +characters can be used to enumerate items, and we can use both Roman and Arabic +numerals in the same list structure: + +1. Introduction +2. Qt Tools + 1) Qt Assistant + 2) Qt Designer + 1. Form Editor + 2. Component Architecture + 3) Qt Linguist + +The list will automatically be renumbered if you add or remove items. *Try +adding new sections to the above list or removing existing item to see the +numbers change.* + +## Images + +Inline images are treated like ordinary ranges of characters in the text +editor, so they flow with the surrounding text. Images can also be selected in +the same way as text, making it easy to cut, copy, and paste them. + +![image](images/logo32.png) *Try to select this image by clicking and dragging +over it with the mouse, or use the text cursor to select it by holding down +Shift and using the arrow keys. You can then cut or copy it, and paste it into +different parts of this document.* + +## Tables + +QTextEdit can arrange and format tables, supporting features such as row and +column spans, text formatting within cells, and size constraints for columns. + + +| |Development Tools |Programming Techniques |Graphical User Interfaces| +|-------------|------------------------------------|---------------------------|-------------------------| +|9:00 - 11:00 |Introduction to Qt ||| +|11:00 - 13:00|Using qmake |Object-oriented Programming|Layouts in Qt | +|13:00 - 15:00|Qt Designer Tutorial |Extreme Programming |Writing Custom Styles | +|15:00 - 17:00|Qt Linguist and Internationalization|Â |Â | + +*Try adding text to the cells in the table and experiment with the alignment of +the paragraphs.* + +## Hyperlinks + +QTextEdit is designed to support hyperlinks between documents, and this feature +is used extensively in +[Qt Assistant](http://doc.qt.io/qt-5/qtassistant-index.html). Hyperlinks are +automatically created when an HTML file is imported into an editor. Since the +rich text framework supports hyperlinks natively, they can also be created +programatically. + +## Undo and Redo + +Full support for undo and redo operations is built into QTextEdit and the +underlying rich text framework. Operations on a document can be packaged +together to make editing a more comfortable experience for the user. + +*Try making changes to this document and press `Ctrl+Z` to undo them. You can +always recover the original contents of the document.* + diff --git a/tests/auto/gui/text/qtextmarkdownwriter/qtextmarkdownwriter.pro b/tests/auto/gui/text/qtextmarkdownwriter/qtextmarkdownwriter.pro new file mode 100644 index 0000000000..6144710b99 --- /dev/null +++ b/tests/auto/gui/text/qtextmarkdownwriter/qtextmarkdownwriter.pro @@ -0,0 +1,9 @@ +CONFIG += testcase +TARGET = tst_qtextmarkdownwriter +QT += core-private gui-private testlib +SOURCES += tst_qtextmarkdownwriter.cpp +TESTDATA += \ + data/example.md \ + data/blockquotes.md \ + +DEFINES += SRCDIR=\\\"$$PWD\\\" diff --git a/tests/auto/gui/text/qtextmarkdownwriter/tst_qtextmarkdownwriter.cpp b/tests/auto/gui/text/qtextmarkdownwriter/tst_qtextmarkdownwriter.cpp new file mode 100644 index 0000000000..9998794762 --- /dev/null +++ b/tests/auto/gui/text/qtextmarkdownwriter/tst_qtextmarkdownwriter.cpp @@ -0,0 +1,456 @@ +/**************************************************************************** +** +** Copyright (C) 2019 The Qt Company Ltd. +** Contact: https://www.qt.io/licensing/ +** +** This file is part of the test suite of the Qt Toolkit. +** +** $QT_BEGIN_LICENSE:GPL-EXCEPT$ +** Commercial License Usage +** Licensees holding valid commercial Qt licenses may use this file in +** accordance with the commercial license agreement provided with the +** Software or, alternatively, in accordance with the terms contained in +** a written agreement between you and The Qt Company. For licensing terms +** and conditions see https://www.qt.io/terms-conditions. For further +** information use the contact form at https://www.qt.io/contact-us. +** +** GNU General Public License Usage +** Alternatively, this file may be used under the terms of the GNU +** General Public License version 3 as published by the Free Software +** Foundation with exceptions as appearing in the file LICENSE.GPL3-EXCEPT +** included in the packaging of this file. Please review the following +** information to ensure the GNU General Public License requirements will +** be met: https://www.gnu.org/licenses/gpl-3.0.html. +** +** $QT_END_LICENSE$ +** +****************************************************************************/ + +#include <QtTest/QtTest> +#include <QTextDocument> +#include <QTextCursor> +#include <QTextBlock> +#include <QTextList> +#include <QTextTable> +#include <QBuffer> +#include <QDebug> + +#include <private/qtextmarkdownwriter_p.h> + +// #define DEBUG_WRITE_OUTPUT + +class tst_QTextMarkdownWriter : public QObject +{ + Q_OBJECT +public slots: + void init(); + void cleanup(); + +private slots: + void testWriteParagraph_data(); + void testWriteParagraph(); + void testWriteList(); + void testWriteNestedBulletLists_data(); + void testWriteNestedBulletLists(); + void testWriteNestedNumericLists(); + void testWriteTable(); + void rewriteDocument_data(); + void rewriteDocument(); + void fromHtml_data(); + void fromHtml(); + +private: + QString documentToUnixMarkdown(); + +private: + QTextDocument *document; +}; + +void tst_QTextMarkdownWriter::init() +{ + document = new QTextDocument(); +} + +void tst_QTextMarkdownWriter::cleanup() +{ + delete document; +} + +void tst_QTextMarkdownWriter::testWriteParagraph_data() +{ + QTest::addColumn<QString>("input"); + QTest::addColumn<QString>("output"); + + QTest::newRow("empty") << "" << + ""; + QTest::newRow("spaces") << "foobar word" << + "foobar word\n\n"; + QTest::newRow("starting spaces") << " starting spaces" << + " starting spaces\n\n"; + QTest::newRow("trailing spaces") << "trailing spaces " << + "trailing spaces \n\n"; + QTest::newRow("tab") << "word\ttab x" << + "word\ttab x\n\n"; + QTest::newRow("tab2") << "word\t\ttab\tx" << + "word\t\ttab\tx\n\n"; + QTest::newRow("misc") << "foobar word\ttab x" << + "foobar word\ttab x\n\n"; + QTest::newRow("misc2") << "\t \tFoo" << + "\t \tFoo\n\n"; +} + +void tst_QTextMarkdownWriter::testWriteParagraph() +{ + QFETCH(QString, input); + QFETCH(QString, output); + + QTextCursor cursor(document); + cursor.insertText(input); + + QCOMPARE(documentToUnixMarkdown(), output); +} + +void tst_QTextMarkdownWriter::testWriteList() +{ + QTextCursor cursor(document); + QTextList *list = cursor.createList(QTextListFormat::ListDisc); + cursor.insertText("ListItem 1"); + list->add(cursor.block()); + cursor.insertBlock(); + cursor.insertText("ListItem 2"); + list->add(cursor.block()); + + QCOMPARE(documentToUnixMarkdown(), QString::fromLatin1( + "- ListItem 1\n- ListItem 2\n")); +} + +void tst_QTextMarkdownWriter::testWriteNestedBulletLists_data() +{ + QTest::addColumn<bool>("checkbox"); + QTest::addColumn<bool>("checked"); + QTest::addColumn<bool>("continuationLine"); + QTest::addColumn<bool>("continuationParagraph"); + QTest::addColumn<QString>("expectedOutput"); + + QTest::newRow("plain bullets") << false << false << false << false << + "- ListItem 1\n * ListItem 2\n + ListItem 3\n- ListItem 4\n * ListItem 5\n"; + QTest::newRow("bullets with continuation lines") << false << false << true << false << + "- ListItem 1\n * ListItem 2\n + ListItem 3 with text that won't fit on one line and thus needs a\n continuation\n- ListItem 4\n * ListItem 5 with text that won't fit on one line and thus needs a\n continuation\n"; + QTest::newRow("bullets with continuation paragraphs") << false << false << false << true << + "- ListItem 1\n\n * ListItem 2\n + ListItem 3\n\n continuation\n\n- ListItem 4\n\n * ListItem 5\n\n continuation\n\n"; + QTest::newRow("unchecked") << true << false << false << false << + "- [ ] ListItem 1\n * [ ] ListItem 2\n + [ ] ListItem 3\n- [ ] ListItem 4\n * [ ] ListItem 5\n"; + QTest::newRow("checked") << true << true << false << false << + "- [x] ListItem 1\n * [x] ListItem 2\n + [x] ListItem 3\n- [x] ListItem 4\n * [x] ListItem 5\n"; + QTest::newRow("checked with continuation lines") << true << true << true << false << + "- [x] ListItem 1\n * [x] ListItem 2\n + [x] ListItem 3 with text that won't fit on one line and thus needs a\n continuation\n- [x] ListItem 4\n * [x] ListItem 5 with text that won't fit on one line and thus needs a\n continuation\n"; + QTest::newRow("checked with continuation paragraphs") << true << true << false << true << + "- [x] ListItem 1\n\n * [x] ListItem 2\n + [x] ListItem 3\n\n continuation\n\n- [x] ListItem 4\n\n * [x] ListItem 5\n\n continuation\n\n"; +} + +void tst_QTextMarkdownWriter::testWriteNestedBulletLists() +{ + QFETCH(bool, checkbox); + QFETCH(bool, checked); + QFETCH(bool, continuationParagraph); + QFETCH(bool, continuationLine); + QFETCH(QString, expectedOutput); + + QTextCursor cursor(document); + QTextBlockFormat blockFmt = cursor.blockFormat(); + if (checkbox) { + blockFmt.setMarker(checked ? QTextBlockFormat::Checked : QTextBlockFormat::Unchecked); + cursor.setBlockFormat(blockFmt); + } + + QTextList *list1 = cursor.createList(QTextListFormat::ListDisc); + cursor.insertText("ListItem 1"); + list1->add(cursor.block()); + + QTextListFormat fmt2; + fmt2.setStyle(QTextListFormat::ListCircle); + fmt2.setIndent(2); + QTextList *list2 = cursor.insertList(fmt2); + cursor.insertText("ListItem 2"); + + QTextListFormat fmt3; + fmt3.setStyle(QTextListFormat::ListSquare); + fmt3.setIndent(3); + cursor.insertList(fmt3); + cursor.insertText(continuationLine ? + "ListItem 3 with text that won't fit on one line and thus needs a continuation" : + "ListItem 3"); + if (continuationParagraph) { + QTextBlockFormat blockFmt; + blockFmt.setIndent(2); + cursor.insertBlock(blockFmt); + cursor.insertText("continuation"); + } + + cursor.insertBlock(blockFmt); + cursor.insertText("ListItem 4"); + list1->add(cursor.block()); + + cursor.insertBlock(); + cursor.insertText(continuationLine ? + "ListItem 5 with text that won't fit on one line and thus needs a continuation" : + "ListItem 5"); + list2->add(cursor.block()); + if (continuationParagraph) { + QTextBlockFormat blockFmt; + blockFmt.setIndent(2); + cursor.insertBlock(blockFmt); + cursor.insertText("continuation"); + } + + QString output = documentToUnixMarkdown(); +#ifdef DEBUG_WRITE_OUTPUT + { + QFile out("/tmp/" + QLatin1String(QTest::currentDataTag()) + ".md"); + out.open(QFile::WriteOnly); + out.write(output.toUtf8()); + out.close(); + } +#endif + QCOMPARE(documentToUnixMarkdown(), expectedOutput); +} + +void tst_QTextMarkdownWriter::testWriteNestedNumericLists() +{ + QTextCursor cursor(document); + + QTextList *list1 = cursor.createList(QTextListFormat::ListDecimal); + cursor.insertText("ListItem 1"); + list1->add(cursor.block()); + + QTextListFormat fmt2; + fmt2.setStyle(QTextListFormat::ListLowerAlpha); + fmt2.setNumberSuffix(QLatin1String(")")); + fmt2.setIndent(2); + QTextList *list2 = cursor.insertList(fmt2); + cursor.insertText("ListItem 2"); + + QTextListFormat fmt3; + fmt3.setStyle(QTextListFormat::ListDecimal); + fmt3.setIndent(3); + cursor.insertList(fmt3); + cursor.insertText("ListItem 3"); + + cursor.insertBlock(); + cursor.insertText("ListItem 4"); + list1->add(cursor.block()); + + cursor.insertBlock(); + cursor.insertText("ListItem 5"); + list2->add(cursor.block()); + + // There's no QTextList API to set the starting number so we hard-coded all lists to start at 1 (QTBUG-65384) + QCOMPARE(documentToUnixMarkdown(), QString::fromLatin1( + "1. ListItem 1\n 1) ListItem 2\n 1. ListItem 3\n2. ListItem 4\n 2) ListItem 5\n")); +} + +void tst_QTextMarkdownWriter::testWriteTable() +{ + QTextCursor cursor(document); + QTextTable * table = cursor.insertTable(4, 3); + cursor = table->cellAt(0, 0).firstCursorPosition(); + // valid Markdown tables need headers, but QTextTable doesn't make that distinction + // so QTextMarkdownWriter assumes the first row of any table is a header + cursor.insertText("one"); + cursor.movePosition(QTextCursor::NextCell); + cursor.insertText("two"); + cursor.movePosition(QTextCursor::NextCell); + cursor.insertText("three"); + cursor.movePosition(QTextCursor::NextCell); + + cursor.insertText("alice"); + cursor.movePosition(QTextCursor::NextCell); + cursor.insertText("bob"); + cursor.movePosition(QTextCursor::NextCell); + cursor.insertText("carl"); + cursor.movePosition(QTextCursor::NextCell); + + cursor.insertText("dennis"); + cursor.movePosition(QTextCursor::NextCell); + cursor.insertText("eric"); + cursor.movePosition(QTextCursor::NextCell); + cursor.insertText("fiona"); + cursor.movePosition(QTextCursor::NextCell); + + cursor.insertText("gina"); + /* + |one |two |three| + |------|----|-----| + |alice |bob |carl | + |dennis|eric|fiona| + |gina | | | + */ + + QString md = documentToUnixMarkdown(); + +#ifdef DEBUG_WRITE_OUTPUT + { + QFile out("/tmp/table.md"); + out.open(QFile::WriteOnly); + out.write(md.toUtf8()); + out.close(); + } +#endif + + QString expected = QString::fromLatin1( + "\n|one |two |three|\n|------|----|-----|\n|alice |bob |carl |\n|dennis|eric|fiona|\n|gina | | |\n\n"); + QCOMPARE(md, expected); + + // create table with merged cells + document->clear(); + cursor = QTextCursor(document); + table = cursor.insertTable(3, 3); + table->mergeCells(0, 0, 1, 2); + table->mergeCells(1, 1, 1, 2); + cursor = table->cellAt(0, 0).firstCursorPosition(); + cursor.insertText("a"); + cursor.movePosition(QTextCursor::NextCell); + cursor.insertText("b"); + cursor.movePosition(QTextCursor::NextCell); + cursor.insertText("c"); + cursor.movePosition(QTextCursor::NextCell); + cursor.insertText("d"); + cursor.movePosition(QTextCursor::NextCell); + cursor.insertText("e"); + cursor.movePosition(QTextCursor::NextCell); + cursor.insertText("f"); + /* + +---+-+ + |a |b| + +---+-+ + |c| d| + +-+-+-+ + |e|f| | + +-+-+-+ + + generates + + |a ||b| + |-|-|-| + |c|d || + |e|f| | + + */ + + md = documentToUnixMarkdown(); + +#ifdef DEBUG_WRITE_OUTPUT + { + QFile out("/tmp/table-merged-cells.md"); + out.open(QFile::WriteOnly); + out.write(md.toUtf8()); + out.close(); + } +#endif + + QCOMPARE(md, QString::fromLatin1("\n|a ||b|\n|-|-|-|\n|c|d ||\n|e|f| |\n\n")); +} + +void tst_QTextMarkdownWriter::rewriteDocument_data() +{ + QTest::addColumn<QString>("inputFile"); + + QTest::newRow("block quotes") << "blockquotes.md"; + QTest::newRow("example") << "example.md"; +} + +void tst_QTextMarkdownWriter::rewriteDocument() +{ + QFETCH(QString, inputFile); + QTextDocument doc; + QFile f(QFINDTESTDATA("data/" + inputFile)); + QVERIFY(f.open(QFile::ReadOnly | QIODevice::Text)); + QString orig = QString::fromUtf8(f.readAll()); + f.close(); + doc.setMarkdown(orig); + QString md = doc.toMarkdown(); + +#ifdef DEBUG_WRITE_OUTPUT + QFile out("/tmp/rewrite-" + inputFile); + out.open(QFile::WriteOnly); + out.write(md.toUtf8()); + out.close(); +#endif + + QCOMPARE(md, orig); +} + +void tst_QTextMarkdownWriter::fromHtml_data() +{ + QTest::addColumn<QString>("expectedInput"); + QTest::addColumn<QString>("expectedOutput"); + + QTest::newRow("long URL") << + "<span style=\"font-style:italic;\">https://www.example.com/dir/subdir/subsubdir/subsubsubdir/subsubsubsubdir/subsubsubsubsubdir/</span>" << + "*https://www.example.com/dir/subdir/subsubdir/subsubsubdir/subsubsubsubdir/subsubsubsubsubdir/*\n\n"; + QTest::newRow("non-emphasis inline asterisk") << "3 * 4" << "3 * 4\n\n"; + QTest::newRow("arithmetic") << "(2 * a * x + b)^2 = b^2 - 4 * a * c" << "(2 * a * x + b)^2 = b^2 - 4 * a * c\n\n"; + QTest::newRow("escaped asterisk after newline") << + "The first sentence of this paragraph holds 80 characters, then there's a star. * This is wrapped, but is <em>not</em> a bullet point." << + "The first sentence of this paragraph holds 80 characters, then there's a star.\n\\* This is wrapped, but is *not* a bullet point.\n\n"; + QTest::newRow("escaped plus after newline") << + "The first sentence of this paragraph holds 80 characters, then there's a plus. + This is wrapped, but is <em>not</em> a bullet point." << + "The first sentence of this paragraph holds 80 characters, then there's a plus.\n\\+ This is wrapped, but is *not* a bullet point.\n\n"; + QTest::newRow("escaped hyphen after newline") << + "The first sentence of this paragraph holds 80 characters, then there's a minus. - This is wrapped, but is <em>not</em> a bullet point." << + "The first sentence of this paragraph holds 80 characters, then there's a minus.\n\\- This is wrapped, but is *not* a bullet point.\n\n"; + QTest::newRow("list items with indented continuations") << + "<ul><li>bullet<p>continuation paragraph</p></li><li>another bullet<br/>continuation line</li></ul>" << + "- bullet\n\n continuation paragraph\n\n- another bullet\n continuation line\n"; + QTest::newRow("nested list items with continuations") << + "<ul><li>bullet<p>continuation paragraph</p></li><li>another bullet<br/>continuation line</li><ul><li>bullet<p>continuation paragraph</p></li><li>another bullet<br/>continuation line</li></ul></ul>" << + "- bullet\n\n continuation paragraph\n\n- another bullet\n continuation line\n\n - bullet\n\n continuation paragraph\n\n - another bullet\n continuation line\n"; + QTest::newRow("nested ordered list items with continuations") << + "<ol><li>item<p>continuation paragraph</p></li><li>another item<br/>continuation line</li><ol><li>item<p>continuation paragraph</p></li><li>another item<br/>continuation line</li></ol><li>another</li><li>another</li></ol>" << + "1. item\n\n continuation paragraph\n\n2. another item\n continuation line\n\n 1. item\n\n continuation paragraph\n\n 2. another item\n continuation line\n\n3. another\n4. another\n"; + QTest::newRow("thematic break") << + "something<hr/>something else" << + "something\n\n- - -\nsomething else\n\n"; + QTest::newRow("block quote") << + "<p>In 1958, Mahatma Gandhi was quoted as follows:</p><blockquote>The Earth provides enough to satisfy every man's need but not for every man's greed.</blockquote>" << + "In 1958, Mahatma Gandhi was quoted as follows:\n\n> The Earth provides enough to satisfy every man's need but not for every man's\n> greed.\n\n"; + // TODO +// QTest::newRow("escaped number and paren after double newline") << +// "<p>(The first sentence of this paragraph is a line, the next paragraph has a number</p>13) but that's not part of an ordered list" << +// "(The first sentence of this paragraph is a line, the next paragraph has a number\n\n13\\) but that's not part of an ordered list\n\n"; +// QTest::newRow("preformats with embedded backticks") << +// "<pre>none `one` ``two``</pre><pre>```three``` ````four````</pre>plain" << +// "``` none `one` ``two`` ```\n\n````` ```three``` ````four```` `````\n\nplain\n\n"; +} + +void tst_QTextMarkdownWriter::fromHtml() +{ + QFETCH(QString, expectedInput); + QFETCH(QString, expectedOutput); + + document->setHtml(expectedInput); + QString output = documentToUnixMarkdown(); + +#ifdef DEBUG_WRITE_OUTPUT + { + QFile out("/tmp/" + QLatin1String(QTest::currentDataTag()) + ".md"); + out.open(QFile::WriteOnly); + out.write(output.toUtf8()); + out.close(); + } +#endif + + QCOMPARE(output, expectedOutput); +} + +QString tst_QTextMarkdownWriter::documentToUnixMarkdown() +{ + QString ret; + QTextStream ts(&ret, QIODevice::WriteOnly); + QTextMarkdownWriter writer(ts, QTextDocument::MarkdownDialectGitHub); + writer.writeAll(document); + return ret; +} + +QTEST_MAIN(tst_QTextMarkdownWriter) +#include "tst_qtextmarkdownwriter.moc" diff --git a/tests/auto/gui/text/text.pro b/tests/auto/gui/text/text.pro index 6b033fb506..794d9ea8d3 100644 --- a/tests/auto/gui/text/text.pro +++ b/tests/auto/gui/text/text.pro @@ -28,12 +28,16 @@ SUBDIRS=\ win32:SUBDIRS -= qtextpiecetable +qtConfig(textmarkdownreader): SUBDIRS += qtextmarkdownimporter +qtConfig(textmarkdownwriter): SUBDIRS += qtextmarkdownwriter + !qtConfig(private_tests): SUBDIRS -= \ qfontcache \ qcssparser \ qtextlayout \ qtextpiecetable \ qzip \ + qtextmarkdownwriter \ qtextodfwriter !qtHaveModule(xml): SUBDIRS -= \ diff --git a/tests/auto/gui/util/qshadergenerator/tst_qshadergenerator.cpp b/tests/auto/gui/util/qshadergenerator/tst_qshadergenerator.cpp index 82197f815e..59e93d127f 100644 --- a/tests/auto/gui/util/qshadergenerator/tst_qshadergenerator.cpp +++ b/tests/auto/gui/util/qshadergenerator/tst_qshadergenerator.cpp @@ -35,11 +35,13 @@ namespace { - QShaderFormat createFormat(QShaderFormat::Api api, int majorVersion, int minorVersion) + QShaderFormat createFormat(QShaderFormat::Api api, int majorVersion, int minorVersion, + QShaderFormat::ShaderType shaderType= QShaderFormat::Fragment) { auto format = QShaderFormat(); format.setApi(api); format.setVersion(QVersionNumber(majorVersion, minorVersion)); + format.setShaderType(shaderType); return format; } @@ -74,7 +76,7 @@ namespace return edge; } - QShaderGraph createGraph() + QShaderGraph createFragmentShaderGraph() { const auto openGLES2 = createFormat(QShaderFormat::OpenGLES, 2, 0); const auto openGL3 = createFormat(QShaderFormat::OpenGLCoreProfile, 3, 0); @@ -135,7 +137,7 @@ namespace createPort(QShaderNodePort::Output, "color") }); sampleTexture.addRule(openGLES2, QShaderNode::Rule("highp vec4 $color = texture2D($sampler, $coord);")); - sampleTexture.addRule(openGL3, QShaderNode::Rule("vec4 $color = texture2D($sampler, $coord);")); + sampleTexture.addRule(openGL3, QShaderNode::Rule("vec4 $color = texture($sampler, $coord);")); auto lightFunction = createNode({ createPort(QShaderNodePort::Input, "baseColor"), @@ -194,6 +196,8 @@ private slots: void shouldProcessLanguageQualifierAndTypeEnums_data(); void shouldProcessLanguageQualifierAndTypeEnums(); void shouldGenerateDifferentCodeDependingOnActiveLayers(); + void shouldUseGlobalVariableRatherThanTemporaries(); + void shouldGenerateTemporariesWisely(); }; void tst_QShaderGenerator::shouldHaveDefaultState() @@ -213,7 +217,7 @@ void tst_QShaderGenerator::shouldGenerateShaderCode_data() QTest::addColumn<QShaderFormat>("format"); QTest::addColumn<QByteArray>("expectedCode"); - const auto graph = createGraph(); + const auto graph = createFragmentShaderGraph(); const auto openGLES2 = createFormat(QShaderFormat::OpenGLES, 2, 0); const auto openGL3 = createFormat(QShaderFormat::OpenGLCoreProfile, 3, 0); @@ -234,15 +238,7 @@ void tst_QShaderGenerator::shouldGenerateShaderCode_data() << "" << "void main()" << "{" - << " highp vec2 v2 = texCoord;" - << " sampler2D v1 = texture;" - << " highp float v3 = lightIntensity;" - << " highp vec4 v5 = texture2D(v1, v2);" - << " highp vec3 v0 = worldPosition;" - << " highp float v4 = exposure;" - << " highp vec4 v6 = lightModel(v5, v0, v3);" - << " highp vec4 v7 = v6 * pow(2.0, v4);" - << " gl_fragColor = v7;" + << " gl_fragColor = (((((lightModel(((texture2D(texture, texCoord))), worldPosition, lightIntensity)))) * pow(2.0, exposure)));" << "}" << ""; @@ -256,15 +252,7 @@ void tst_QShaderGenerator::shouldGenerateShaderCode_data() << "" << "void main()" << "{" - << " vec2 v2 = texCoord;" - << " sampler2D v1 = texture;" - << " float v3 = lightIntensity;" - << " vec4 v5 = texture2D(v1, v2);" - << " vec3 v0 = worldPosition;" - << " float v4 = exposure;" - << " vec4 v6 = lightModel(v5, v0, v3);" - << " vec4 v7 = v6 * pow(2.0, v4);" - << " fragColor = v7;" + << " fragColor = (((((lightModel(((texture(texture, texCoord))), worldPosition, lightIntensity)))) * pow(2.0, exposure)));" << "}" << ""; @@ -580,120 +568,190 @@ void tst_QShaderGenerator::shouldProcessLanguageQualifierAndTypeEnums_data() QTest::addColumn<QShaderFormat>("format"); QTest::addColumn<QByteArray>("expectedCode"); - const auto es2 = createFormat(QShaderFormat::OpenGLES, 2, 0); - const auto es3 = createFormat(QShaderFormat::OpenGLES, 3, 0); - const auto gl2 = createFormat(QShaderFormat::OpenGLNoProfile, 2, 0); - const auto gl3 = createFormat(QShaderFormat::OpenGLCoreProfile, 3, 0); - const auto gl4 = createFormat(QShaderFormat::OpenGLCoreProfile, 4, 0); - - const auto qualifierEnum = QMetaEnum::fromType<QShaderLanguage::StorageQualifier>(); - const auto typeEnum = QMetaEnum::fromType<QShaderLanguage::VariableType>(); - - for (int qualifierIndex = 0; qualifierIndex < qualifierEnum.keyCount(); qualifierIndex++) { - const auto qualifierName = qualifierEnum.key(qualifierIndex); - const auto qualifierValue = static_cast<QShaderLanguage::StorageQualifier>(qualifierEnum.value(qualifierIndex)); + { + const auto es2 = createFormat(QShaderFormat::OpenGLES, 2, 0); + const auto es3 = createFormat(QShaderFormat::OpenGLES, 3, 0); + const auto gl2 = createFormat(QShaderFormat::OpenGLNoProfile, 2, 0); + const auto gl3 = createFormat(QShaderFormat::OpenGLCoreProfile, 3, 0); + const auto gl4 = createFormat(QShaderFormat::OpenGLCoreProfile, 4, 0); + + const auto qualifierEnum = QMetaEnum::fromType<QShaderLanguage::StorageQualifier>(); + const auto typeEnum = QMetaEnum::fromType<QShaderLanguage::VariableType>(); + + for (int qualifierIndex = 0; qualifierIndex < qualifierEnum.keyCount(); qualifierIndex++) { + const auto qualifierName = qualifierEnum.key(qualifierIndex); + const auto qualifierValue = static_cast<QShaderLanguage::StorageQualifier>(qualifierEnum.value(qualifierIndex)); + + for (int typeIndex = 0; typeIndex < typeEnum.keyCount(); typeIndex++) { + const auto typeName = typeEnum.key(typeIndex); + const auto typeValue = static_cast<QShaderLanguage::VariableType>(typeEnum.value(typeIndex)); + + auto graph = QShaderGraph(); + + auto worldPosition = createNode({ + createPort(QShaderNodePort::Output, "value") + }); + worldPosition.setParameter("name", "worldPosition"); + worldPosition.setParameter("qualifier", QVariant::fromValue<QShaderLanguage::StorageQualifier>(qualifierValue)); + worldPosition.setParameter("type", QVariant::fromValue<QShaderLanguage::VariableType>(typeValue)); + worldPosition.addRule(es2, QShaderNode::Rule("highp $type $value = $name;", + QByteArrayList() << "$qualifier highp $type $name;")); + worldPosition.addRule(gl2, QShaderNode::Rule("$type $value = $name;", + QByteArrayList() << "$qualifier $type $name;")); + worldPosition.addRule(gl3, QShaderNode::Rule("$type $value = $name;", + QByteArrayList() << "$qualifier $type $name;")); + + auto fragColor = createNode({ + createPort(QShaderNodePort::Input, "fragColor") + }); + fragColor.addRule(es2, QShaderNode::Rule("gl_fragColor = $fragColor;")); + fragColor.addRule(gl2, QShaderNode::Rule("gl_fragColor = $fragColor;")); + fragColor.addRule(gl3, QShaderNode::Rule("fragColor = $fragColor;", + QByteArrayList() << "out vec4 fragColor;")); + + graph.addNode(worldPosition); + graph.addNode(fragColor); + + graph.addEdge(createEdge(worldPosition.uuid(), "value", fragColor.uuid(), "fragColor")); + + const auto gl2Code = (QByteArrayList() << "#version 110" + << "" + << QStringLiteral("%1 %2 worldPosition;").arg(toGlsl(qualifierValue, gl2)) + .arg(toGlsl(typeValue)) + .toUtf8() + << "" + << "void main()" + << "{" + << " gl_fragColor = worldPosition;" + << "}" + << "").join("\n"); + const auto gl3Code = (QByteArrayList() << "#version 130" + << "" + << QStringLiteral("%1 %2 worldPosition;").arg(toGlsl(qualifierValue, gl3)) + .arg(toGlsl(typeValue)) + .toUtf8() + << "out vec4 fragColor;" + << "" + << "void main()" + << "{" + << " fragColor = worldPosition;" + << "}" + << "").join("\n"); + const auto gl4Code = (QByteArrayList() << "#version 400 core" + << "" + << QStringLiteral("%1 %2 worldPosition;").arg(toGlsl(qualifierValue, gl4)) + .arg(toGlsl(typeValue)) + .toUtf8() + << "out vec4 fragColor;" + << "" + << "void main()" + << "{" + << " fragColor = worldPosition;" + << "}" + << "").join("\n"); + const auto es2Code = (QByteArrayList() << "#version 100" + << "" + << QStringLiteral("%1 highp %2 worldPosition;").arg(toGlsl(qualifierValue, es2)) + .arg(toGlsl(typeValue)) + .toUtf8() + << "" + << "void main()" + << "{" + << " gl_fragColor = worldPosition;" + << "}" + << "").join("\n"); + const auto es3Code = (QByteArrayList() << "#version 300 es" + << "" + << QStringLiteral("%1 highp %2 worldPosition;").arg(toGlsl(qualifierValue, es3)) + .arg(toGlsl(typeValue)) + .toUtf8() + << "" + << "void main()" + << "{" + << " gl_fragColor = worldPosition;" + << "}" + << "").join("\n"); + + QTest::addRow("%s %s ES2", qualifierName, typeName) << graph << es2 << es2Code; + QTest::addRow("%s %s ES3", qualifierName, typeName) << graph << es3 << es3Code; + QTest::addRow("%s %s GL2", qualifierName, typeName) << graph << gl2 << gl2Code; + QTest::addRow("%s %s GL3", qualifierName, typeName) << graph << gl3 << gl3Code; + QTest::addRow("%s %s GL4", qualifierName, typeName) << graph << gl4 << gl4Code; + } + } + } - for (int typeIndex = 0; typeIndex < typeEnum.keyCount(); typeIndex++) { - const auto typeName = typeEnum.key(typeIndex); - const auto typeValue = static_cast<QShaderLanguage::VariableType>(typeEnum.value(typeIndex)); + { + const auto es2 = createFormat(QShaderFormat::OpenGLES, 2, 0, QShaderFormat::Vertex); + const auto es3 = createFormat(QShaderFormat::OpenGLES, 3, 0, QShaderFormat::Vertex); + const auto gl2 = createFormat(QShaderFormat::OpenGLNoProfile, 2, 0, QShaderFormat::Vertex); + const auto gl3 = createFormat(QShaderFormat::OpenGLCoreProfile, 3, 0, QShaderFormat::Vertex); + const auto gl4 = createFormat(QShaderFormat::OpenGLCoreProfile, 4, 0, QShaderFormat::Vertex); auto graph = QShaderGraph(); - auto worldPosition = createNode({ + auto vertexPosition = createNode({ createPort(QShaderNodePort::Output, "value") }); - worldPosition.setParameter("name", "worldPosition"); - worldPosition.setParameter("qualifier", QVariant::fromValue<QShaderLanguage::StorageQualifier>(qualifierValue)); - worldPosition.setParameter("type", QVariant::fromValue<QShaderLanguage::VariableType>(typeValue)); - worldPosition.addRule(es2, QShaderNode::Rule("highp $type $value = $name;", + vertexPosition.setParameter("name", "vertexPosition"); + vertexPosition.setParameter("qualifier", QVariant::fromValue<QShaderLanguage::StorageQualifier>(QShaderLanguage::Input)); + vertexPosition.setParameter("type", QVariant::fromValue<QShaderLanguage::VariableType>(QShaderLanguage::Vec4)); + + vertexPosition.addRule(es2, QShaderNode::Rule("", QByteArrayList() << "$qualifier highp $type $name;")); - worldPosition.addRule(gl2, QShaderNode::Rule("$type $value = $name;", + vertexPosition.addRule(gl2, QShaderNode::Rule("", QByteArrayList() << "$qualifier $type $name;")); - worldPosition.addRule(gl3, QShaderNode::Rule("$type $value = $name;", + vertexPosition.addRule(gl3, QShaderNode::Rule("", QByteArrayList() << "$qualifier $type $name;")); - auto fragColor = createNode({ - createPort(QShaderNodePort::Input, "fragColor") - }); - fragColor.addRule(es2, QShaderNode::Rule("gl_fragColor = $fragColor;")); - fragColor.addRule(gl2, QShaderNode::Rule("gl_fragColor = $fragColor;")); - fragColor.addRule(gl3, QShaderNode::Rule("fragColor = $fragColor;", - QByteArrayList() << "out vec4 fragColor;")); - - graph.addNode(worldPosition); - graph.addNode(fragColor); - - graph.addEdge(createEdge(worldPosition.uuid(), "value", fragColor.uuid(), "fragColor")); + graph.addNode(vertexPosition); const auto gl2Code = (QByteArrayList() << "#version 110" << "" - << QStringLiteral("%1 %2 worldPosition;").arg(toGlsl(qualifierValue, gl2)) - .arg(toGlsl(typeValue)) - .toUtf8() + << "attribute vec4 vertexPosition;" << "" << "void main()" << "{" - << QStringLiteral(" %1 v0 = worldPosition;").arg(toGlsl(typeValue)).toUtf8() - << " gl_fragColor = v0;" << "}" << "").join("\n"); const auto gl3Code = (QByteArrayList() << "#version 130" << "" - << QStringLiteral("%1 %2 worldPosition;").arg(toGlsl(qualifierValue, gl3)) - .arg(toGlsl(typeValue)) - .toUtf8() - << "out vec4 fragColor;" + << "in vec4 vertexPosition;" << "" << "void main()" << "{" - << QStringLiteral(" %1 v0 = worldPosition;").arg(toGlsl(typeValue)).toUtf8() - << " fragColor = v0;" << "}" << "").join("\n"); const auto gl4Code = (QByteArrayList() << "#version 400 core" << "" - << QStringLiteral("%1 %2 worldPosition;").arg(toGlsl(qualifierValue, gl4)) - .arg(toGlsl(typeValue)) - .toUtf8() - << "out vec4 fragColor;" + << "in vec4 vertexPosition;" << "" << "void main()" << "{" - << QStringLiteral(" %1 v0 = worldPosition;").arg(toGlsl(typeValue)).toUtf8() - << " fragColor = v0;" << "}" << "").join("\n"); const auto es2Code = (QByteArrayList() << "#version 100" << "" - << QStringLiteral("%1 highp %2 worldPosition;").arg(toGlsl(qualifierValue, es2)) - .arg(toGlsl(typeValue)) - .toUtf8() + << "attribute highp vec4 vertexPosition;" << "" << "void main()" << "{" - << QStringLiteral(" highp %1 v0 = worldPosition;").arg(toGlsl(typeValue)).toUtf8() - << " gl_fragColor = v0;" << "}" << "").join("\n"); const auto es3Code = (QByteArrayList() << "#version 300 es" << "" - << QStringLiteral("%1 highp %2 worldPosition;").arg(toGlsl(qualifierValue, es3)) - .arg(toGlsl(typeValue)) - .toUtf8() + << "in highp vec4 vertexPosition;" << "" << "void main()" << "{" - << QStringLiteral(" highp %1 v0 = worldPosition;").arg(toGlsl(typeValue)).toUtf8() - << " gl_fragColor = v0;" << "}" << "").join("\n"); - QTest::addRow("%s %s ES2", qualifierName, typeName) << graph << es2 << es2Code; - QTest::addRow("%s %s ES3", qualifierName, typeName) << graph << es3 << es3Code; - QTest::addRow("%s %s GL2", qualifierName, typeName) << graph << gl2 << gl2Code; - QTest::addRow("%s %s GL3", qualifierName, typeName) << graph << gl3 << gl3Code; - QTest::addRow("%s %s GL4", qualifierName, typeName) << graph << gl4 << gl4Code; - } + QTest::addRow("Attribute header substitution ES2") << graph << es2 << es2Code; + QTest::addRow("Attribute header substitution ES3") << graph << es3 << es3Code; + QTest::addRow("Attribute header substitution GL2") << graph << gl2 << gl2Code; + QTest::addRow("Attribute header substitution GL3") << graph << gl3 << gl3Code; + QTest::addRow("Attribute header substitution GL4") << graph << gl4 << gl4Code; } } @@ -806,10 +864,7 @@ void tst_QShaderGenerator::shouldGenerateDifferentCodeDependingOnActiveLayers() << "" << "void main()" << "{" - << " vec3 v1 = normalUniform;" - << " vec4 v0 = diffuseUniform;" - << " vec4 v2 = lightModel(v0, v1);" - << " fragColor = v2;" + << " fragColor = ((lightModel(diffuseUniform, normalUniform)));" << "}" << ""; QCOMPARE(code, expected.join("\n")); @@ -831,11 +886,7 @@ void tst_QShaderGenerator::shouldGenerateDifferentCodeDependingOnActiveLayers() << "" << "void main()" << "{" - << " vec2 v0 = texCoord;" - << " vec3 v2 = texture2D(normalTexture, v0).rgb;" - << " vec4 v1 = diffuseUniform;" - << " vec4 v3 = lightModel(v1, v2);" - << " fragColor = v3;" + << " fragColor = ((lightModel(diffuseUniform, texture2D(normalTexture, texCoord).rgb)));" << "}" << ""; QCOMPARE(code, expected.join("\n")); @@ -857,11 +908,7 @@ void tst_QShaderGenerator::shouldGenerateDifferentCodeDependingOnActiveLayers() << "" << "void main()" << "{" - << " vec2 v0 = texCoord;" - << " vec3 v2 = normalUniform;" - << " vec4 v1 = texture2D(diffuseTexture, v0);" - << " vec4 v3 = lightModel(v1, v2);" - << " fragColor = v3;" + << " fragColor = ((lightModel(texture2D(diffuseTexture, texCoord), normalUniform)));" << "}" << ""; QCOMPARE(code, expected.join("\n")); @@ -883,17 +930,305 @@ void tst_QShaderGenerator::shouldGenerateDifferentCodeDependingOnActiveLayers() << "" << "void main()" << "{" - << " vec2 v0 = texCoord;" - << " vec3 v2 = texture2D(normalTexture, v0).rgb;" - << " vec4 v1 = texture2D(diffuseTexture, v0);" - << " vec4 v3 = lightModel(v1, v2);" - << " fragColor = v3;" + << " fragColor = ((lightModel(texture2D(diffuseTexture, texCoord), texture2D(normalTexture, texCoord).rgb)));" << "}" << ""; QCOMPARE(code, expected.join("\n")); } } +void tst_QShaderGenerator::shouldUseGlobalVariableRatherThanTemporaries() +{ + // GIVEN + const auto gl4 = createFormat(QShaderFormat::OpenGLCoreProfile, 4, 0); + + { + // WHEN + auto vertexPosition = createNode({ + createPort(QShaderNodePort::Output, "vertexPosition") + }); + vertexPosition.addRule(gl4, QShaderNode::Rule("vec4 $vertexPosition = vertexPosition;", + QByteArrayList() << "in vec4 vertexPosition;")); + + auto fakeMultiPlyNoSpace = createNode({ + createPort(QShaderNodePort::Input, "varName"), + createPort(QShaderNodePort::Output, "out") + }); + fakeMultiPlyNoSpace.addRule(gl4, QShaderNode::Rule("vec4 $out = $varName*speed;")); + + auto fakeMultiPlySpace = createNode({ + createPort(QShaderNodePort::Input, "varName"), + createPort(QShaderNodePort::Output, "out") + }); + fakeMultiPlySpace.addRule(gl4, QShaderNode::Rule("vec4 $out = $varName * speed;")); + + auto fakeJoinNoSpace = createNode({ + createPort(QShaderNodePort::Input, "varName"), + createPort(QShaderNodePort::Output, "out") + }); + fakeJoinNoSpace.addRule(gl4, QShaderNode::Rule("vec4 $out = vec4($varName.xyz,$varName.w);")); + + auto fakeJoinSpace = createNode({ + createPort(QShaderNodePort::Input, "varName"), + createPort(QShaderNodePort::Output, "out") + }); + fakeJoinSpace.addRule(gl4, QShaderNode::Rule("vec4 $out = vec4($varName.xyz, $varName.w);")); + + auto fakeAdd = createNode({ + createPort(QShaderNodePort::Input, "varName"), + createPort(QShaderNodePort::Output, "out") + }); + fakeAdd.addRule(gl4, QShaderNode::Rule("vec4 $out = $varName.xyzw + $varName;")); + + auto fakeSub = createNode({ + createPort(QShaderNodePort::Input, "varName"), + createPort(QShaderNodePort::Output, "out") + }); + fakeSub.addRule(gl4, QShaderNode::Rule("vec4 $out = $varName.xyzw - $varName;")); + + auto fakeDiv = createNode({ + createPort(QShaderNodePort::Input, "varName"), + createPort(QShaderNodePort::Output, "out") + }); + fakeDiv.addRule(gl4, QShaderNode::Rule("vec4 $out = $varName / v0;")); + + auto fragColor = createNode({ + createPort(QShaderNodePort::Input, "input1"), + createPort(QShaderNodePort::Input, "input2"), + createPort(QShaderNodePort::Input, "input3"), + createPort(QShaderNodePort::Input, "input4"), + createPort(QShaderNodePort::Input, "input5"), + createPort(QShaderNodePort::Input, "input6"), + createPort(QShaderNodePort::Input, "input7") + }); + fragColor.addRule(gl4, QShaderNode::Rule("fragColor = $input1 + $input2 + $input3 + $input4 + $input5 + $input6 + $input7;", + QByteArrayList() << "out vec4 fragColor;")); + + const auto graph = [=] { + auto res = QShaderGraph(); + + res.addNode(vertexPosition); + res.addNode(fakeMultiPlyNoSpace); + res.addNode(fakeMultiPlySpace); + res.addNode(fakeJoinNoSpace); + res.addNode(fakeJoinSpace); + res.addNode(fakeAdd); + res.addNode(fakeSub); + res.addNode(fakeDiv); + res.addNode(fragColor); + + res.addEdge(createEdge(vertexPosition.uuid(), "vertexPosition", fakeMultiPlyNoSpace.uuid(), "varName")); + res.addEdge(createEdge(vertexPosition.uuid(), "vertexPosition", fakeMultiPlySpace.uuid(), "varName")); + res.addEdge(createEdge(vertexPosition.uuid(), "vertexPosition", fakeJoinNoSpace.uuid(), "varName")); + res.addEdge(createEdge(vertexPosition.uuid(), "vertexPosition", fakeJoinSpace.uuid(), "varName")); + res.addEdge(createEdge(vertexPosition.uuid(), "vertexPosition", fakeAdd.uuid(), "varName")); + res.addEdge(createEdge(vertexPosition.uuid(), "vertexPosition", fakeSub.uuid(), "varName")); + res.addEdge(createEdge(vertexPosition.uuid(), "vertexPosition", fakeDiv.uuid(), "varName")); + res.addEdge(createEdge(fakeMultiPlyNoSpace.uuid(), "out", fragColor.uuid(), "input1")); + res.addEdge(createEdge(fakeMultiPlySpace.uuid(), "out", fragColor.uuid(), "input2")); + res.addEdge(createEdge(fakeJoinNoSpace.uuid(), "out", fragColor.uuid(), "input3")); + res.addEdge(createEdge(fakeJoinSpace.uuid(), "out", fragColor.uuid(), "input4")); + res.addEdge(createEdge(fakeAdd.uuid(), "out", fragColor.uuid(), "input5")); + res.addEdge(createEdge(fakeSub.uuid(), "out", fragColor.uuid(), "input6")); + res.addEdge(createEdge(fakeDiv.uuid(), "out", fragColor.uuid(), "input7")); + + return res; + }(); + + auto generator = QShaderGenerator(); + generator.graph = graph; + generator.format = gl4; + + const auto code = generator.createShaderCode({"diffuseUniform", "normalUniform"}); + + // THEN + const auto expected = QByteArrayList() + << "#version 400 core" + << "" + << "in vec4 vertexPosition;" + << "out vec4 fragColor;" + << "" + << "void main()" + << "{" + << " fragColor = (((((((vertexPosition*speed + vertexPosition * speed + ((vec4(vertexPosition.xyz,vertexPosition.w))) + ((vec4(vertexPosition.xyz, vertexPosition.w))) + ((vertexPosition.xyzw + vertexPosition)) + ((vertexPosition.xyzw - vertexPosition)) + ((vertexPosition / vertexPosition)))))))));" + << "}" + << ""; + QCOMPARE(code, expected.join("\n")); + } +} + +void tst_QShaderGenerator::shouldGenerateTemporariesWisely() +{ + // GIVEN + const auto gl4 = createFormat(QShaderFormat::OpenGLCoreProfile, 4, 0); + + { + auto attribute = createNode({ + createPort(QShaderNodePort::Output, "vertexPosition") + }); + attribute.addRule(gl4, QShaderNode::Rule("vec4 $vertexPosition = vertexPosition;", + QByteArrayList() << "in vec4 vertexPosition;")); + + auto complexFunction = createNode({ + createPort(QShaderNodePort::Input, "inputVarName"), + createPort(QShaderNodePort::Output, "out") + }); + complexFunction.addRule(gl4, QShaderNode::Rule("vec4 $out = $inputVarName * 2.0;")); + + auto complexFunction2 = createNode({ + createPort(QShaderNodePort::Input, "inputVarName"), + createPort(QShaderNodePort::Output, "out") + }); + complexFunction2.addRule(gl4, QShaderNode::Rule("vec4 $out = $inputVarName * 4.0;")); + + auto complexFunction3 = createNode({ + createPort(QShaderNodePort::Input, "a"), + createPort(QShaderNodePort::Input, "b"), + createPort(QShaderNodePort::Output, "out") + }); + complexFunction3.addRule(gl4, QShaderNode::Rule("vec4 $out = $a + $b;")); + + auto shaderOutput1 = createNode({ + createPort(QShaderNodePort::Input, "input") + }); + + shaderOutput1.addRule(gl4, QShaderNode::Rule("shaderOutput1 = $input;", + QByteArrayList() << "out vec4 shaderOutput1;")); + + auto shaderOutput2 = createNode({ + createPort(QShaderNodePort::Input, "input") + }); + + shaderOutput2.addRule(gl4, QShaderNode::Rule("shaderOutput2 = $input;", + QByteArrayList() << "out vec4 shaderOutput2;")); + + { + // WHEN + const auto graph = [=] { + auto res = QShaderGraph(); + + res.addNode(attribute); + res.addNode(complexFunction); + res.addNode(shaderOutput1); + + res.addEdge(createEdge(attribute.uuid(), "vertexPosition", complexFunction.uuid(), "inputVarName")); + res.addEdge(createEdge(complexFunction.uuid(), "out", shaderOutput1.uuid(), "input")); + + return res; + }(); + + auto generator = QShaderGenerator(); + generator.graph = graph; + generator.format = gl4; + + const auto code = generator.createShaderCode(); + + // THEN + const auto expected = QByteArrayList() + << "#version 400 core" + << "" + << "in vec4 vertexPosition;" + << "out vec4 shaderOutput1;" + << "" + << "void main()" + << "{" + << " shaderOutput1 = vertexPosition * 2.0;" + << "}" + << ""; + QCOMPARE(code, expected.join("\n")); + } + + { + // WHEN + const auto graph = [=] { + auto res = QShaderGraph(); + + res.addNode(attribute); + res.addNode(complexFunction); + res.addNode(shaderOutput1); + res.addNode(shaderOutput2); + + res.addEdge(createEdge(attribute.uuid(), "vertexPosition", complexFunction.uuid(), "inputVarName")); + res.addEdge(createEdge(complexFunction.uuid(), "out", shaderOutput1.uuid(), "input")); + res.addEdge(createEdge(complexFunction.uuid(), "out", shaderOutput2.uuid(), "input")); + + return res; + }(); + + auto generator = QShaderGenerator(); + generator.graph = graph; + generator.format = gl4; + + const auto code = generator.createShaderCode(); + + // THEN + const auto expected = QByteArrayList() + << "#version 400 core" + << "" + << "in vec4 vertexPosition;" + << "out vec4 shaderOutput1;" + << "out vec4 shaderOutput2;" + << "" + << "void main()" + << "{" + << " vec4 v1 = vertexPosition * 2.0;" + << " shaderOutput2 = v1;" + << " shaderOutput1 = v1;" + << "}" + << ""; + QCOMPARE(code, expected.join("\n")); + } + + { + // WHEN + const auto graph = [=] { + auto res = QShaderGraph(); + + res.addNode(attribute); + res.addNode(complexFunction); + res.addNode(complexFunction2); + res.addNode(complexFunction3); + res.addNode(shaderOutput1); + res.addNode(shaderOutput2); + + res.addEdge(createEdge(attribute.uuid(), "vertexPosition", complexFunction.uuid(), "inputVarName")); + res.addEdge(createEdge(attribute.uuid(), "vertexPosition", complexFunction2.uuid(), "inputVarName")); + + res.addEdge(createEdge(complexFunction.uuid(), "out", complexFunction3.uuid(), "a")); + res.addEdge(createEdge(complexFunction2.uuid(), "out", complexFunction3.uuid(), "b")); + + res.addEdge(createEdge(complexFunction3.uuid(), "out", shaderOutput1.uuid(), "input")); + res.addEdge(createEdge(complexFunction2.uuid(), "out", shaderOutput2.uuid(), "input")); + + return res; + }(); + + auto generator = QShaderGenerator(); + generator.graph = graph; + generator.format = gl4; + + const auto code = generator.createShaderCode(); + + // THEN + const auto expected = QByteArrayList() + << "#version 400 core" + << "" + << "in vec4 vertexPosition;" + << "out vec4 shaderOutput1;" + << "out vec4 shaderOutput2;" + << "" + << "void main()" + << "{" + << " vec4 v2 = vertexPosition * 4.0;" + << " shaderOutput2 = v2;" + << " shaderOutput1 = (vertexPosition * 2.0 + v2);" + << "}" + << ""; + QCOMPARE(code, expected.join("\n")); + } + } +} + QTEST_MAIN(tst_QShaderGenerator) #include "tst_qshadergenerator.moc" diff --git a/tests/auto/network/access/qabstractnetworkcache/qabstractnetworkcache.pro b/tests/auto/network/access/qabstractnetworkcache/qabstractnetworkcache.pro index bdd9d4eb7e..c722100ead 100644 --- a/tests/auto/network/access/qabstractnetworkcache/qabstractnetworkcache.pro +++ b/tests/auto/network/access/qabstractnetworkcache/qabstractnetworkcache.pro @@ -5,5 +5,5 @@ SOURCES += tst_qabstractnetworkcache.cpp TESTDATA += tests/* +CONFIG += unsupported/testserver QT_TEST_SERVER_LIST = apache2 -include($$dirname(_QMAKE_CONF_)/tests/auto/testserver.pri) diff --git a/tests/auto/network/access/qftp/qftp.pro b/tests/auto/network/access/qftp/qftp.pro index 1959c1acac..c78020c5f8 100644 --- a/tests/auto/network/access/qftp/qftp.pro +++ b/tests/auto/network/access/qftp/qftp.pro @@ -4,3 +4,6 @@ SOURCES += tst_qftp.cpp requires(qtConfig(private_tests)) QT = core network network-private testlib + +CONFIG += unsupported/testserver +QT_TEST_SERVER_LIST = vsftpd ftp-proxy squid danted diff --git a/tests/auto/network/access/qftp/tst_qftp.cpp b/tests/auto/network/access/qftp/tst_qftp.cpp index 6e18e1a663..e07588d6c6 100644 --- a/tests/auto/network/access/qftp/tst_qftp.cpp +++ b/tests/auto/network/access/qftp/tst_qftp.cpp @@ -133,8 +133,8 @@ private: bool fileExists( const QString &host, quint16 port, const QString &user, const QString &password, const QString &file, const QString &cdDir = QString() ); bool dirExists( const QString &host, quint16 port, const QString &user, const QString &password, const QString &cdDir, const QString &dirToCreate ); - void renameInit( const QString &host, const QString &user, const QString &password, const QString &createFile ); - void renameCleanup( const QString &host, const QString &user, const QString &password, const QString &fileToDelete ); + void renameInit( bool &isSuccess, const QString &host, const QString &user, const QString &password, const QString &createFile ); + void renameCleanup( bool &isSuccess, const QString &host, const QString &user, const QString &password, const QString &fileToDelete ); QFtp *ftp; #ifndef QT_NO_BEARERMANAGEMENT @@ -208,7 +208,14 @@ void tst_QFtp::initTestCase_data() void tst_QFtp::initTestCase() { +#if defined(QT_TEST_SERVER) + QVERIFY(QtNetworkSettings::verifyConnection(QtNetworkSettings::ftpServerName(), 21)); + QVERIFY(QtNetworkSettings::verifyConnection(QtNetworkSettings::ftpProxyServerName(), 2121)); + QVERIFY(QtNetworkSettings::verifyConnection(QtNetworkSettings::socksProxyServerName(), 1080)); + QVERIFY(QtNetworkSettings::verifyConnection(QtNetworkSettings::httpProxyServerName(), 3128)); +#else QVERIFY(QtNetworkSettings::verifyTestNetworkSettings()); +#endif #ifndef QT_NO_BEARERMANAGEMENT QNetworkConfigurationManager manager; networkSessionImplicit = QSharedPointer<QNetworkSession>::create(manager.defaultConfiguration()); @@ -235,9 +242,9 @@ void tst_QFtp::init() if (setProxy) { #ifndef QT_NO_NETWORKPROXY if (proxyType == QNetworkProxy::Socks5Proxy) { - QNetworkProxy::setApplicationProxy(QNetworkProxy(QNetworkProxy::Socks5Proxy, QtNetworkSettings::serverName(), 1080)); + QNetworkProxy::setApplicationProxy(QNetworkProxy(QNetworkProxy::Socks5Proxy, QtNetworkSettings::socksProxyServerName(), 1080)); } else if (proxyType == QNetworkProxy::HttpProxy) { - QNetworkProxy::setApplicationProxy(QNetworkProxy(QNetworkProxy::HttpProxy, QtNetworkSettings::serverName(), 3128)); + QNetworkProxy::setApplicationProxy(QNetworkProxy(QNetworkProxy::HttpProxy, QtNetworkSettings::httpProxyServerName(), 3128)); } #else // !QT_NO_NETWORKPROXY Q_UNUSED(proxyType); @@ -316,8 +323,8 @@ void tst_QFtp::connectToHost_data() QTest::addColumn<uint>("port"); QTest::addColumn<int>("state"); - QTest::newRow( "ok01" ) << QtNetworkSettings::serverName() << (uint)21 << (int)QFtp::Connected; - QTest::newRow( "error01" ) << QtNetworkSettings::serverName() << (uint)2222 << (int)QFtp::Unconnected; + QTest::newRow( "ok01" ) << QtNetworkSettings::ftpServerName() << (uint)21 << (int)QFtp::Connected; + QTest::newRow( "error01" ) << QtNetworkSettings::ftpServerName() << (uint)2222 << (int)QFtp::Unconnected; QTest::newRow( "error02" ) << QString("foo.bar") << (uint)21 << (int)QFtp::Unconnected; } @@ -328,7 +335,11 @@ static QByteArray msgTimedOut(const QString &host, quint16 port = 0) result += ':'; result += QByteArray::number(port); } - return result; + + if (host == QtNetworkSettings::ftpServerName()) + return "(QTBUG-75549) Flaky results: " % result; + else + return result; } void tst_QFtp::connectToHost() @@ -343,7 +354,7 @@ void tst_QFtp::connectToHost() delete ftp; ftp = 0; if ( QTestEventLoop::instance().timeout() ) - QFAIL( msgTimedOut(host, port) ); + QSKIP( msgTimedOut(host, port) ); QTEST( connectToHost_state, "state" ); @@ -402,13 +413,13 @@ void tst_QFtp::login_data() QTest::addColumn<QString>("password"); QTest::addColumn<int>("success"); - QTest::newRow( "ok01" ) << QtNetworkSettings::serverName() << (uint)21 << QString() << QString() << 1; - QTest::newRow( "ok02" ) << QtNetworkSettings::serverName() << (uint)21 << QString("ftp") << QString("") << 1; - QTest::newRow( "ok03" ) << QtNetworkSettings::serverName() << (uint)21 << QString("ftp") << QString("foo") << 1; - QTest::newRow( "ok04" ) << QtNetworkSettings::serverName() << (uint)21 << QString("ftptest") << QString("password") << 1; + QTest::newRow( "ok01" ) << QtNetworkSettings::ftpServerName() << (uint)21 << QString() << QString() << 1; + QTest::newRow( "ok02" ) << QtNetworkSettings::ftpServerName() << (uint)21 << QString("ftp") << QString("") << 1; + QTest::newRow( "ok03" ) << QtNetworkSettings::ftpServerName() << (uint)21 << QString("ftp") << QString("foo") << 1; + QTest::newRow( "ok04" ) << QtNetworkSettings::ftpServerName() << (uint)21 << QString("ftptest") << QString("password") << 1; - QTest::newRow( "error01" ) << QtNetworkSettings::serverName() << (uint)21 << QString("foo") << QString("") << 0; - QTest::newRow( "error02" ) << QtNetworkSettings::serverName() << (uint)21 << QString("foo") << QString("bar") << 0; + QTest::newRow( "error01" ) << QtNetworkSettings::ftpServerName() << (uint)21 << QString("foo") << QString("") << 0; + QTest::newRow( "error02" ) << QtNetworkSettings::ftpServerName() << (uint)21 << QString("foo") << QString("bar") << 0; } void tst_QFtp::login() @@ -426,7 +437,7 @@ void tst_QFtp::login() delete ftp; ftp = 0; if ( QTestEventLoop::instance().timeout() ) - QFAIL( msgTimedOut(host, port) ); + QSKIP( msgTimedOut(host, port) ); ResMapIt it = resultMap.find( QFtp::Login ); QVERIFY( it != resultMap.end() ); @@ -448,12 +459,12 @@ void tst_QFtp::close_data() QTest::addColumn<QString>("password"); QTest::addColumn<bool>("login"); - QTest::newRow( "login01" ) << QtNetworkSettings::serverName() << (uint)21 << QString() << QString() << true; - QTest::newRow( "login02" ) << QtNetworkSettings::serverName() << (uint)21 << QString("ftp") << QString() << true; - QTest::newRow( "login03" ) << QtNetworkSettings::serverName() << (uint)21 << QString("ftp") << QString("foo") << true; - QTest::newRow( "login04" ) << QtNetworkSettings::serverName() << (uint)21 << QString("ftptest") << QString("password") << true; + QTest::newRow( "login01" ) << QtNetworkSettings::ftpServerName() << (uint)21 << QString() << QString() << true; + QTest::newRow( "login02" ) << QtNetworkSettings::ftpServerName() << (uint)21 << QString("ftp") << QString() << true; + QTest::newRow( "login03" ) << QtNetworkSettings::ftpServerName() << (uint)21 << QString("ftp") << QString("foo") << true; + QTest::newRow( "login04" ) << QtNetworkSettings::ftpServerName() << (uint)21 << QString("ftptest") << QString("password") << true; - QTest::newRow( "no-login01" ) << QtNetworkSettings::serverName() << (uint)21 << QString("") << QString("") << false; + QTest::newRow( "no-login01" ) << QtNetworkSettings::ftpServerName() << (uint)21 << QString("") << QString("") << false; } void tst_QFtp::close() @@ -474,7 +485,7 @@ void tst_QFtp::close() delete ftp; ftp = 0; if ( QTestEventLoop::instance().timeout() ) - QFAIL( msgTimedOut(host, port) ); + QSKIP( msgTimedOut(host, port) ); QCOMPARE( close_state, (int)QFtp::Unconnected ); @@ -503,17 +514,17 @@ void tst_QFtp::list_data() flukeQtest << "rfc3252.txt"; flukeQtest << "upload"; - QTest::newRow( "workDir01" ) << QtNetworkSettings::serverName() << (uint)21 << QString() << QString() << QString() << 1 << flukeRoot; - QTest::newRow( "workDir02" ) << QtNetworkSettings::serverName() << (uint)21 << QString("ftptest") << QString("password") << QString() << 1 << flukeRoot; + QTest::newRow( "workDir01" ) << QtNetworkSettings::ftpServerName() << (uint)21 << QString() << QString() << QString() << 1 << flukeRoot; + QTest::newRow( "workDir02" ) << QtNetworkSettings::ftpServerName() << (uint)21 << QString("ftptest") << QString("password") << QString() << 1 << flukeRoot; - QTest::newRow( "relPath01" ) << QtNetworkSettings::serverName() << (uint)21 << QString() << QString() << QString("qtest") << 1 << flukeQtest; - QTest::newRow( "relPath02" ) << QtNetworkSettings::serverName() << (uint)21 << QString("ftptest") << QString("password") << QString("qtest") << 1 << flukeQtest; + QTest::newRow( "relPath01" ) << QtNetworkSettings::ftpServerName() << (uint)21 << QString() << QString() << QString("qtest") << 1 << flukeQtest; + QTest::newRow( "relPath02" ) << QtNetworkSettings::ftpServerName() << (uint)21 << QString("ftptest") << QString("password") << QString("qtest") << 1 << flukeQtest; - QTest::newRow( "absPath01" ) << QtNetworkSettings::serverName() << (uint)21 << QString() << QString() << QString("/qtest") << 1 << flukeQtest; - QTest::newRow( "absPath02" ) << QtNetworkSettings::serverName() << (uint)21 << QString("ftptest") << QString("password") << QString("/var/ftp/qtest") << 1 << flukeQtest; + QTest::newRow( "absPath01" ) << QtNetworkSettings::ftpServerName() << (uint)21 << QString() << QString() << QString("/qtest") << 1 << flukeQtest; + QTest::newRow( "absPath02" ) << QtNetworkSettings::ftpServerName() << (uint)21 << QString("ftptest") << QString("password") << QString("/var/ftp/qtest") << 1 << flukeQtest; - QTest::newRow( "nonExist01" ) << QtNetworkSettings::serverName() << (uint)21 << QString() << QString() << QString("foo") << 1 << QStringList(); - QTest::newRow( "nonExist02" ) << QtNetworkSettings::serverName() << (uint)21 << QString() << QString() << QString("/foo") << 1 << QStringList(); + QTest::newRow( "nonExist01" ) << QtNetworkSettings::ftpServerName() << (uint)21 << QString() << QString() << QString("foo") << 1 << QStringList(); + QTest::newRow( "nonExist02" ) << QtNetworkSettings::ftpServerName() << (uint)21 << QString() << QString() << QString("/foo") << 1 << QStringList(); // ### The microsoft server does not seem to work properly at the moment -- // I am also not able to open a data connection with other, non-Qt FTP // clients to it. @@ -542,7 +553,7 @@ void tst_QFtp::list() delete ftp; ftp = 0; if ( QTestEventLoop::instance().timeout() ) - QFAIL( msgTimedOut(host, port) ); + QSKIP( msgTimedOut(host, port) ); ResMapIt it = resultMap.find( QFtp::List ); QVERIFY( it != resultMap.end() ); @@ -573,14 +584,14 @@ void tst_QFtp::cd_data() flukeQtest << "rfc3252.txt"; flukeQtest << "upload"; - QTest::newRow( "relPath01" ) << QtNetworkSettings::serverName() << (uint)21 << QString() << QString() << QString("qtest") << 1 << flukeQtest; - QTest::newRow( "relPath02" ) << QtNetworkSettings::serverName() << (uint)21 << QString("ftptest") << QString("password") << QString("qtest") << 1 << flukeQtest; + QTest::newRow( "relPath01" ) << QtNetworkSettings::ftpServerName() << (uint)21 << QString() << QString() << QString("qtest") << 1 << flukeQtest; + QTest::newRow( "relPath02" ) << QtNetworkSettings::ftpServerName() << (uint)21 << QString("ftptest") << QString("password") << QString("qtest") << 1 << flukeQtest; - QTest::newRow( "absPath01" ) << QtNetworkSettings::serverName() << (uint)21 << QString() << QString() << QString("/qtest") << 1 << flukeQtest; - QTest::newRow( "absPath02" ) << QtNetworkSettings::serverName() << (uint)21 << QString("ftptest") << QString("password") << QString("/var/ftp/qtest") << 1 << flukeQtest; + QTest::newRow( "absPath01" ) << QtNetworkSettings::ftpServerName() << (uint)21 << QString() << QString() << QString("/qtest") << 1 << flukeQtest; + QTest::newRow( "absPath02" ) << QtNetworkSettings::ftpServerName() << (uint)21 << QString("ftptest") << QString("password") << QString("/var/ftp/qtest") << 1 << flukeQtest; - QTest::newRow( "nonExist01" ) << QtNetworkSettings::serverName() << (uint)21 << QString() << QString() << QString("foo") << 0 << QStringList(); - QTest::newRow( "nonExist03" ) << QtNetworkSettings::serverName() << (uint)21 << QString() << QString() << QString("/foo") << 0 << QStringList(); + QTest::newRow( "nonExist01" ) << QtNetworkSettings::ftpServerName() << (uint)21 << QString() << QString() << QString("foo") << 0 << QStringList(); + QTest::newRow( "nonExist03" ) << QtNetworkSettings::ftpServerName() << (uint)21 << QString() << QString() << QString("/foo") << 0 << QStringList(); } void tst_QFtp::cd() @@ -603,7 +614,7 @@ void tst_QFtp::cd() delete ftp; ftp = 0; if ( QTestEventLoop::instance().timeout() ) { - QFAIL( msgTimedOut(host, port) ); + QSKIP( msgTimedOut(host, port) ); } ResMapIt it = resultMap.find( QFtp::Cd ); @@ -635,19 +646,19 @@ void tst_QFtp::get_data() // test the two get() overloads in one routine for ( int i=0; i<2; i++ ) { const QByteArray iB = QByteArray::number(i); - QTest::newRow(("relPath01_" + iB).constData()) << QtNetworkSettings::serverName() << (uint)21 << QString() << QString() + QTest::newRow(("relPath01_" + iB).constData()) << QtNetworkSettings::ftpServerName() << (uint)21 << QString() << QString() << "qtest/rfc3252" << 1 << rfc3252 << (bool)(i==1); - QTest::newRow(("relPath02_" + iB).constData()) << QtNetworkSettings::serverName() << (uint)21 << QString("ftptest") << QString("password") + QTest::newRow(("relPath02_" + iB).constData()) << QtNetworkSettings::ftpServerName() << (uint)21 << QString("ftptest") << QString("password") << "qtest/rfc3252" << 1 << rfc3252 << (bool)(i==1); - QTest::newRow(("absPath01_" + iB).constData()) << QtNetworkSettings::serverName() << (uint)21 << QString() << QString() + QTest::newRow(("absPath01_" + iB).constData()) << QtNetworkSettings::ftpServerName() << (uint)21 << QString() << QString() << "/qtest/rfc3252" << 1 << rfc3252 << (bool)(i==1); - QTest::newRow(("absPath02_" + iB).constData()) << QtNetworkSettings::serverName() << (uint)21 << QString("ftptest") << QString("password") + QTest::newRow(("absPath02_" + iB).constData()) << QtNetworkSettings::ftpServerName() << (uint)21 << QString("ftptest") << QString("password") << "/var/ftp/qtest/rfc3252" << 1 << rfc3252 << (bool)(i==1); - QTest::newRow(("nonExist01_" + iB).constData()) << QtNetworkSettings::serverName() << (uint)21 << QString() << QString() + QTest::newRow(("nonExist01_" + iB).constData()) << QtNetworkSettings::ftpServerName() << (uint)21 << QString() << QString() << QString("foo") << 0 << QByteArray() << (bool)(i==1); - QTest::newRow(("nonExist02_" + iB).constData()) << QtNetworkSettings::serverName() << (uint)21 << QString() << QString() + QTest::newRow(("nonExist02_" + iB).constData()) << QtNetworkSettings::ftpServerName() << (uint)21 << QString() << QString() << QString("/foo") << 0 << QByteArray() << (bool)(i==1); } } @@ -680,7 +691,7 @@ void tst_QFtp::get() delete ftp; ftp = 0; if ( QTestEventLoop::instance().timeout() ) - QFAIL( msgTimedOut(host, port) ); + QSKIP( msgTimedOut(host, port) ); ResMapIt it = resultMap.find( QFtp::Get ); QVERIFY( it != resultMap.end() ); @@ -727,31 +738,31 @@ void tst_QFtp::put_data() // test the two put() overloads in one routine with a file name containing // U+0x00FC (latin small letter u with diaeresis) for QTBUG-52303, testing UTF-8 for ( int i=0; i<2; i++ ) { - QTest::newRow(("relPath01_" + QByteArray::number(i)).constData()) << QtNetworkSettings::serverName() << (uint)21 << QString() << QString() + QTest::newRow(("relPath01_" + QByteArray::number(i)).constData()) << QtNetworkSettings::ftpServerName() << (uint)21 << QString() << QString() << (QLatin1String("qtest/upload/rel01_") + QChar(0xfc) + QLatin1String("%1")) << rfc3252 << (bool)(i==1) << 1; /* - QTest::newRow( QString("relPath02_%1").arg(i).toLatin1().constData() ) << QtNetworkSettings::serverName() << (uint)21 << QString("ftptest") << QString("password") + QTest::newRow( QString("relPath02_%1").arg(i).toLatin1().constData() ) << QtNetworkSettings::ftpServerName() << (uint)21 << QString("ftptest") << QString("password") << QString("qtest/upload/rel02_%1") << rfc3252 << (bool)(i==1) << 1; - QTest::newRow( QString("relPath03_%1").arg(i).toLatin1().constData() ) << QtNetworkSettings::serverName() << (uint)21 << QString("ftptest") << QString("password") + QTest::newRow( QString("relPath03_%1").arg(i).toLatin1().constData() ) << QtNetworkSettings::ftpServerName() << (uint)21 << QString("ftptest") << QString("password") << QString("qtest/upload/rel03_%1") << QByteArray() << (bool)(i==1) << 1; - QTest::newRow( QString("relPath04_%1").arg(i).toLatin1().constData() ) << QtNetworkSettings::serverName() << (uint)21 << QString("ftptest") << QString("password") + QTest::newRow( QString("relPath04_%1").arg(i).toLatin1().constData() ) << QtNetworkSettings::ftpServerName() << (uint)21 << QString("ftptest") << QString("password") << QString("qtest/upload/rel04_%1") << bigData << (bool)(i==1) << 1; - QTest::newRow( QString("absPath01_%1").arg(i).toLatin1().constData() ) << QtNetworkSettings::serverName() << (uint)21 << QString() << QString() + QTest::newRow( QString("absPath01_%1").arg(i).toLatin1().constData() ) << QtNetworkSettings::ftpServerName() << (uint)21 << QString() << QString() << QString("/qtest/upload/abs01_%1") << rfc3252 << (bool)(i==1) << 1; - QTest::newRow( QString("absPath02_%1").arg(i).toLatin1().constData() ) << QtNetworkSettings::serverName() << (uint)21 << QString("ftptest") << QString("password") + QTest::newRow( QString("absPath02_%1").arg(i).toLatin1().constData() ) << QtNetworkSettings::ftpServerName() << (uint)21 << QString("ftptest") << QString("password") << QString("/srv/ftp/qtest/upload/abs02_%1") << rfc3252 << (bool)(i==1) << 1; - QTest::newRow( QString("nonExist01_%1").arg(i).toLatin1().constData() ) << QtNetworkSettings::serverName() << (uint)21 << QString() << QString() + QTest::newRow( QString("nonExist01_%1").arg(i).toLatin1().constData() ) << QtNetworkSettings::ftpServerName() << (uint)21 << QString() << QString() << QString("foo") << QByteArray() << (bool)(i==1) << 0; - QTest::newRow( QString("nonExist02_%1").arg(i).toLatin1().constData() ) << QtNetworkSettings::serverName() << (uint)21 << QString() << QString() + QTest::newRow( QString("nonExist02_%1").arg(i).toLatin1().constData() ) << QtNetworkSettings::ftpServerName() << (uint)21 << QString() << QString() << QString("/foo") << QByteArray() << (bool)(i==1) << 0; */ @@ -807,7 +818,7 @@ void tst_QFtp::put() delete ftp; ftp = 0; if ( QTestEventLoop::instance().timeout() ) - QFAIL( msgTimedOut(host, port) ); + QSKIP( msgTimedOut(host, port) ); it = resultMap.find( QFtp::Put ); QVERIFY( it != resultMap.end() ); @@ -840,7 +851,7 @@ void tst_QFtp::put() delete ftp; ftp = 0; if ( QTestEventLoop::instance().timeout() ) - QFAIL( msgTimedOut(host, port) ); + QSKIP( msgTimedOut(host, port) ); QCOMPARE( done_success, 1 ); QTEST( buf.buffer(), "fileData" ); @@ -858,7 +869,7 @@ void tst_QFtp::put() delete ftp; ftp = 0; if ( QTestEventLoop::instance().timeout() ) - QFAIL( msgTimedOut(host, port) ); + QSKIP( msgTimedOut(host, port) ); it = resultMap.find( QFtp::Remove ); QVERIFY( it != resultMap.end() ); @@ -877,22 +888,22 @@ void tst_QFtp::mkdir_data() QTest::addColumn<QString>("dirToCreate"); QTest::addColumn<int>("success"); - QTest::newRow( "relPath01" ) << QtNetworkSettings::serverName() << (uint)21 << QString() << QString() + QTest::newRow( "relPath01" ) << QtNetworkSettings::ftpServerName() << (uint)21 << QString() << QString() << "qtest/upload" << QString("rel01_%1") << 1; - QTest::newRow( "relPath02" ) << QtNetworkSettings::serverName() << (uint)21 << QString("ftptest") << QString("password") + QTest::newRow( "relPath02" ) << QtNetworkSettings::ftpServerName() << (uint)21 << QString("ftptest") << QString("password") << "qtest/upload" << QString("rel02_%1") << 1; - QTest::newRow( "relPath03" ) << QtNetworkSettings::serverName() << (uint)21 << QString("ftptest") << QString("password") + QTest::newRow( "relPath03" ) << QtNetworkSettings::ftpServerName() << (uint)21 << QString("ftptest") << QString("password") << "qtest/upload" << QString("rel03_%1") << 1; - QTest::newRow( "absPath01" ) << QtNetworkSettings::serverName() << (uint)21 << QString() << QString() + QTest::newRow( "absPath01" ) << QtNetworkSettings::ftpServerName() << (uint)21 << QString() << QString() << "." << QString("/qtest/upload/abs01_%1") << 1; - QTest::newRow( "absPath02" ) << QtNetworkSettings::serverName() << (uint)21 << QString("ftptest") << QString("password") + QTest::newRow( "absPath02" ) << QtNetworkSettings::ftpServerName() << (uint)21 << QString("ftptest") << QString("password") << "." << QString("/var/ftp/qtest/upload/abs02_%1") << 1; - // QTest::newRow( "nonExist01" ) << QtNetworkSettings::serverName() << (uint)21 << QString() << QString() << QString("foo") << 0; - QTest::newRow( "nonExist01" ) << QtNetworkSettings::serverName() << (uint)21 << QString() << QString() + // QTest::newRow( "nonExist01" ) << QtNetworkSettings::ftpServerName() << (uint)21 << QString() << QString() << QString("foo") << 0; + QTest::newRow( "nonExist01" ) << QtNetworkSettings::ftpServerName() << (uint)21 << QString() << QString() << "." << QString("foo") << 0; - QTest::newRow( "nonExist02" ) << QtNetworkSettings::serverName() << (uint)21 << QString() << QString() + QTest::newRow( "nonExist02" ) << QtNetworkSettings::ftpServerName() << (uint)21 << QString() << QString() << "." << QString("/foo") << 0; } @@ -922,7 +933,7 @@ void tst_QFtp::mkdir() delete ftp; ftp = 0; if ( QTestEventLoop::instance().timeout() ) - QFAIL( msgTimedOut(host, port) ); + QSKIP( msgTimedOut(host, port) ); ResMapIt it = resultMap.find( QFtp::Mkdir ); QVERIFY( it != resultMap.end() ); @@ -947,7 +958,7 @@ void tst_QFtp::mkdir() delete ftp; ftp = 0; if ( QTestEventLoop::instance().timeout() ) - QFAIL( msgTimedOut(host, port) ); + QSKIP( msgTimedOut(host, port) ); it = resultMap.find( QFtp::Mkdir ); QVERIFY( it != resultMap.end() ); @@ -967,7 +978,7 @@ void tst_QFtp::mkdir() delete ftp; ftp = 0; if ( QTestEventLoop::instance().timeout() ) - QFAIL( msgTimedOut(host, port) ); + QSKIP( msgTimedOut(host, port) ); it = resultMap.find( QFtp::Rmdir ); QVERIFY( it != resultMap.end() ); @@ -979,7 +990,7 @@ void tst_QFtp::mkdir() void tst_QFtp::mkdir2() { ftp = new QFtp; - ftp->connectToHost(QtNetworkSettings::serverName()); + ftp->connectToHost(QtNetworkSettings::ftpServerName()); ftp->login(); current_id = ftp->cd("kake/test"); @@ -1026,47 +1037,48 @@ void tst_QFtp::rename_data() QTest::addColumn<QString>("renamedFile"); QTest::addColumn<int>("success"); - QTest::newRow("relPath01") << QtNetworkSettings::serverName() << QString() << QString() + QTest::newRow("relPath01") << QtNetworkSettings::ftpServerName() << QString() << QString() << "qtest/upload" << QString("rel_old01_%1") << QString("rel_new01_%1") << QString("qtest/upload/rel_old01_%1") << QString("qtest/upload/rel_new01_%1") << 1; - QTest::newRow("relPath02") << QtNetworkSettings::serverName() << QString("ftptest") << "password" + QTest::newRow("relPath02") << QtNetworkSettings::ftpServerName() << QString("ftptest") << "password" << "qtest/upload" << QString("rel_old02_%1") << QString("rel_new02_%1") << QString("qtest/upload/rel_old02_%1") << QString("qtest/upload/rel_new02_%1") << 1; - QTest::newRow("relPath03") << QtNetworkSettings::serverName() << QString("ftptest") << "password" + QTest::newRow("relPath03") << QtNetworkSettings::ftpServerName() << QString("ftptest") << "password" << "qtest/upload" << QString("rel_old03_%1")<< QString("rel_new03_%1") << QString("qtest/upload/rel_old03_%1") << QString("qtest/upload/rel_new03_%1") << 1; - QTest::newRow("absPath01") << QtNetworkSettings::serverName() << QString() << QString() + QTest::newRow("absPath01") << QtNetworkSettings::ftpServerName() << QString() << QString() << QString() << QString("/qtest/upload/abs_old01_%1") << QString("/qtest/upload/abs_new01_%1") << QString("/qtest/upload/abs_old01_%1") << QString("/qtest/upload/abs_new01_%1") << 1; - QTest::newRow("absPath02") << QtNetworkSettings::serverName() << QString("ftptest") << "password" + QTest::newRow("absPath02") << QtNetworkSettings::ftpServerName() << QString("ftptest") << "password" << QString() << QString("/var/ftp/qtest/upload/abs_old02_%1") << QString("/var/ftp/qtest/upload/abs_new02_%1") << QString("/var/ftp/qtest/upload/abs_old02_%1") << QString("/var/ftp/qtest/upload/abs_new02_%1") << 1; - QTest::newRow("nonExist01") << QtNetworkSettings::serverName() << QString() << QString() + QTest::newRow("nonExist01") << QtNetworkSettings::ftpServerName() << QString() << QString() << QString() << QString("foo") << "new_foo" << QString() << QString() << 0; - QTest::newRow("nonExist02") << QtNetworkSettings::serverName() << QString() << QString() + QTest::newRow("nonExist02") << QtNetworkSettings::ftpServerName() << QString() << QString() << QString() << QString("/foo") << QString("/new_foo") << QString() << QString() << 0; } -void tst_QFtp::renameInit( const QString &host, const QString &user, const QString &password, const QString &createFile ) +void tst_QFtp::renameInit( bool &isSuccess, const QString &host, const QString &user, const QString &password, const QString &createFile ) { + isSuccess = false; if ( !createFile.isNull() ) { // upload the file init(); @@ -1080,7 +1092,7 @@ void tst_QFtp::renameInit( const QString &host, const QString &user, const QStri delete ftp; ftp = 0; if ( QTestEventLoop::instance().timeout() ) - QFAIL( msgTimedOut(host) ); + QSKIP( msgTimedOut(host) ); ResMapIt it = resultMap.find( QFtp::Put ); QVERIFY( it != resultMap.end() ); @@ -1088,10 +1100,12 @@ void tst_QFtp::renameInit( const QString &host, const QString &user, const QStri QVERIFY( fileExists( host, 21, user, password, createFile ) ); } + isSuccess = true; } -void tst_QFtp::renameCleanup( const QString &host, const QString &user, const QString &password, const QString &fileToDelete ) +void tst_QFtp::renameCleanup( bool &isSuccess, const QString &host, const QString &user, const QString &password, const QString &fileToDelete ) { + isSuccess = false; if ( !fileToDelete.isNull() ) { // cleanup (i.e. remove the file) init(); @@ -1105,7 +1119,7 @@ void tst_QFtp::renameCleanup( const QString &host, const QString &user, const QS delete ftp; ftp = 0; if ( QTestEventLoop::instance().timeout() ) - QFAIL( msgTimedOut(host) ); + QSKIP( msgTimedOut(host) ); ResMapIt it = resultMap.find( QFtp::Remove ); QVERIFY( it != resultMap.end() ); @@ -1113,6 +1127,7 @@ void tst_QFtp::renameCleanup( const QString &host, const QString &user, const QS QVERIFY( !fileExists( host, 21, user, password, fileToDelete ) ); } + isSuccess = true; } void tst_QFtp::rename() @@ -1135,7 +1150,10 @@ void tst_QFtp::rename() if(renamedFile.contains('%')) renamedFile = renamedFile.arg(uniqueExtension); - renameInit( host, user, password, createFile ); + bool isSuccess = true; + renameInit(isSuccess, host, user, password, createFile); + if (!isSuccess) + QSKIP("(QTBUG-75549) abort test when there is an error in helper functions"); init(); ftp = newFtp(); @@ -1150,7 +1168,7 @@ void tst_QFtp::rename() delete ftp; ftp = 0; if ( QTestEventLoop::instance().timeout() ) - QFAIL( msgTimedOut(host) ); + QSKIP( msgTimedOut(host) ); ResMapIt it = resultMap.find( QFtp::Rename ); QVERIFY( it != resultMap.end() ); @@ -1165,7 +1183,9 @@ void tst_QFtp::rename() QVERIFY( !fileExists( host, 21, user, password, renamedFile ) ); } - renameCleanup( host, user, password, renamedFile ); + renameCleanup(isSuccess, host, user, password, renamedFile); + if (!isSuccess) + QSKIP("(QTBUG-75549) abort test when there is an error in helper functions"); } /* @@ -1220,7 +1240,7 @@ void tst_QFtp::commandSequence_data() { // some "constants" QStringList argConnectToHost01; - argConnectToHost01 << QtNetworkSettings::serverName() << "21"; + argConnectToHost01 << QtNetworkSettings::ftpServerName() << "21"; QStringList argLogin01, argLogin02, argLogin03, argLogin04; argLogin01 << QString() << QString(); @@ -1339,7 +1359,7 @@ void tst_QFtp::commandSequence() delete ftp; ftp = 0; if ( QTestEventLoop::instance().timeout() ) - QFAIL( msgTimedOut(host) ); + QSKIP( msgTimedOut(host) ); QTEST( commandSequence_success, "success" ); } @@ -1351,13 +1371,13 @@ void tst_QFtp::abort_data() QTest::addColumn<QString>("file"); QTest::addColumn<QByteArray>("uploadData"); - QTest::newRow( "get_fluke01" ) << QtNetworkSettings::serverName() << (uint)21 << QString("qtest/bigfile") << QByteArray(); - QTest::newRow( "get_fluke02" ) << QtNetworkSettings::serverName() << (uint)21 << QString("qtest/rfc3252") << QByteArray(); + QTest::newRow( "get_fluke01" ) << QtNetworkSettings::ftpServerName() << (uint)21 << QString("qtest/bigfile") << QByteArray(); + QTest::newRow( "get_fluke02" ) << QtNetworkSettings::ftpServerName() << (uint)21 << QString("qtest/rfc3252") << QByteArray(); // Qt/CE test environment has too little memory for this test QByteArray bigData( 10*1024*1024, 0 ); bigData.fill( 'B' ); - QTest::newRow( "put_fluke01" ) << QtNetworkSettings::serverName() << (uint)21 << QString("qtest/upload/abort_put") << bigData; + QTest::newRow( "put_fluke01" ) << QtNetworkSettings::ftpServerName() << (uint)21 << QString("qtest/upload/abort_put") << bigData; } void tst_QFtp::abort() @@ -1394,7 +1414,7 @@ void tst_QFtp::abort() delete ftp; ftp = 0; if ( QTestEventLoop::instance().timeout() ) - QFAIL( msgTimedOut(host, port) ); + QSKIP( msgTimedOut(host, port) ); ResMapIt it = resultMap.find( cmd ); QVERIFY( it != resultMap.end() ); @@ -1402,7 +1422,7 @@ void tst_QFtp::abort() if ( it.value().success ) { // The FTP server on fluke is sadly returning a success, even when // the operation was aborted. So we have to use some heuristics. - if ( host == QtNetworkSettings::serverName() ) { + if ( host == QtNetworkSettings::ftpServerName() ) { if ( cmd == QFtp::Get ) { QVERIFY2(bytesDone <= bytesTotal, msgComparison(bytesDone, "<=", bytesTotal)); } else { @@ -1432,7 +1452,7 @@ void tst_QFtp::abort() delete ftp; ftp = 0; if ( QTestEventLoop::instance().timeout() ) - QFAIL( msgTimedOut(host, port) ); + QSKIP( msgTimedOut(host, port) ); it = resultMap.find( QFtp::Remove ); QVERIFY( it != resultMap.end() ); @@ -1449,11 +1469,11 @@ void tst_QFtp::bytesAvailable_data() QTest::addColumn<qlonglong>("bytesAvailFinished"); QTest::addColumn<qlonglong>("bytesAvailDone"); - QTest::newRow( "fluke01" ) << QtNetworkSettings::serverName() << QString("qtest/bigfile") << 0 << (qlonglong)519240 << (qlonglong)519240 << (qlonglong)519240; - QTest::newRow( "fluke02" ) << QtNetworkSettings::serverName() << QString("qtest/rfc3252") << 0 << (qlonglong)25962 << (qlonglong)25962 << (qlonglong)25962; + QTest::newRow( "fluke01" ) << QtNetworkSettings::ftpServerName() << QString("qtest/bigfile") << 0 << (qlonglong)519240 << (qlonglong)519240 << (qlonglong)519240; + QTest::newRow( "fluke02" ) << QtNetworkSettings::ftpServerName() << QString("qtest/rfc3252") << 0 << (qlonglong)25962 << (qlonglong)25962 << (qlonglong)25962; - QTest::newRow( "fluke03" ) << QtNetworkSettings::serverName() << QString("qtest/bigfile") << 1 << (qlonglong)519240 << (qlonglong)0 << (qlonglong)0; - QTest::newRow( "fluke04" ) << QtNetworkSettings::serverName() << QString("qtest/rfc3252") << 1 << (qlonglong)25962 << (qlonglong)0 << (qlonglong)0; + QTest::newRow( "fluke03" ) << QtNetworkSettings::ftpServerName() << QString("qtest/bigfile") << 1 << (qlonglong)519240 << (qlonglong)0 << (qlonglong)0; + QTest::newRow( "fluke04" ) << QtNetworkSettings::ftpServerName() << QString("qtest/rfc3252") << 1 << (qlonglong)25962 << (qlonglong)0 << (qlonglong)0; } void tst_QFtp::bytesAvailable() @@ -1470,8 +1490,11 @@ void tst_QFtp::bytesAvailable() addCommand( QFtp::Close, ftp->close() ); QTestEventLoop::instance().enterLoop( 40 ); - if ( QTestEventLoop::instance().timeout() ) - QFAIL( msgTimedOut(host) ); + if ( QTestEventLoop::instance().timeout() ) { + delete ftp; + ftp = 0; + QSKIP( msgTimedOut(host) ); + } ResMapIt it = resultMap.find( QFtp::Get ); QVERIFY( it != resultMap.end() ); @@ -1498,7 +1521,7 @@ void tst_QFtp::activeMode() file.open(QIODevice::ReadWrite); QFtp ftp; ftp.setTransferMode(QFtp::Active); - ftp.connectToHost(QtNetworkSettings::serverName(), 21); + ftp.connectToHost(QtNetworkSettings::ftpServerName(), 21); ftp.login(); ftp.list(); ftp.get("/qtest/rfc3252.txt", &file); @@ -1534,14 +1557,14 @@ void tst_QFtp::proxy_data() flukeQtest << "rfc3252.txt"; flukeQtest << "upload"; - QTest::newRow( "proxy_relPath01" ) << QtNetworkSettings::serverName() << (uint)21 << QString() << QString() << QString("qtest") << 1 << flukeQtest; - QTest::newRow( "proxy_relPath02" ) << QtNetworkSettings::serverName() << (uint)21 << QString("ftptest") << QString("password") << QString("qtest") << 1 << flukeQtest; + QTest::newRow( "proxy_relPath01" ) << QtNetworkSettings::ftpServerName() << (uint)21 << QString() << QString() << QString("qtest") << 1 << flukeQtest; + QTest::newRow( "proxy_relPath02" ) << QtNetworkSettings::ftpServerName() << (uint)21 << QString("ftptest") << QString("password") << QString("qtest") << 1 << flukeQtest; - QTest::newRow( "proxy_absPath01" ) << QtNetworkSettings::serverName() << (uint)21 << QString() << QString() << QString("/qtest") << 1 << flukeQtest; - QTest::newRow( "proxy_absPath02" ) << QtNetworkSettings::serverName() << (uint)21 << QString("ftptest") << QString("password") << QString("/var/ftp/qtest") << 1 << flukeQtest; + QTest::newRow( "proxy_absPath01" ) << QtNetworkSettings::ftpServerName() << (uint)21 << QString() << QString() << QString("/qtest") << 1 << flukeQtest; + QTest::newRow( "proxy_absPath02" ) << QtNetworkSettings::ftpServerName() << (uint)21 << QString("ftptest") << QString("password") << QString("/var/ftp/qtest") << 1 << flukeQtest; - QTest::newRow( "proxy_nonExist01" ) << QtNetworkSettings::serverName() << (uint)21 << QString() << QString() << QString("foo") << 0 << QStringList(); - QTest::newRow( "proxy_nonExist03" ) << QtNetworkSettings::serverName() << (uint)21 << QString() << QString() << QString("/foo") << 0 << QStringList(); + QTest::newRow( "proxy_nonExist01" ) << QtNetworkSettings::ftpServerName() << (uint)21 << QString() << QString() << QString("foo") << 0 << QStringList(); + QTest::newRow( "proxy_nonExist03" ) << QtNetworkSettings::ftpServerName() << (uint)21 << QString() << QString() << QString("/foo") << 0 << QStringList(); } void tst_QFtp::proxy() @@ -1553,7 +1576,7 @@ void tst_QFtp::proxy() QFETCH( QString, dir ); ftp = newFtp(); - addCommand( QFtp::SetProxy, ftp->setProxy( QtNetworkSettings::serverName(), 2121 ) ); + addCommand( QFtp::SetProxy, ftp->setProxy( QtNetworkSettings::ftpProxyServerName(), 2121 ) ); addCommand( QFtp::ConnectToHost, ftp->connectToHost( host, port ) ); addCommand( QFtp::Login, ftp->login( user, password ) ); addCommand( QFtp::Cd, ftp->cd( dir ) ); @@ -1564,7 +1587,7 @@ void tst_QFtp::proxy() delete ftp; ftp = 0; if ( QTestEventLoop::instance().timeout() ) { - QFAIL( msgTimedOut(host, port) ); + QSKIP( msgTimedOut(host, port) ); } ResMapIt it = resultMap.find( QFtp::Cd ); @@ -1589,7 +1612,7 @@ void tst_QFtp::binaryAscii() init(); ftp = newFtp(); - addCommand(QFtp::ConnectToHost, ftp->connectToHost(QtNetworkSettings::serverName(), 21)); + addCommand(QFtp::ConnectToHost, ftp->connectToHost(QtNetworkSettings::ftpServerName(), 21)); addCommand(QFtp::Login, ftp->login("ftptest", "password")); addCommand(QFtp::Cd, ftp->cd("qtest/upload")); addCommand(QFtp::Put, ftp->put(putData, file, QFtp::Ascii)); @@ -1599,7 +1622,7 @@ void tst_QFtp::binaryAscii() delete ftp; ftp = 0; if ( QTestEventLoop::instance().timeout() ) - QFAIL( msgTimedOut(QtNetworkSettings::serverName()) ); + QSKIP( msgTimedOut(QtNetworkSettings::ftpServerName()) ); ResMapIt it = resultMap.find(QFtp::Put); QVERIFY(it != resultMap.end()); @@ -1611,7 +1634,7 @@ void tst_QFtp::binaryAscii() init(); ftp = newFtp(); - addCommand(QFtp::ConnectToHost, ftp->connectToHost(QtNetworkSettings::serverName(), 21)); + addCommand(QFtp::ConnectToHost, ftp->connectToHost(QtNetworkSettings::ftpServerName(), 21)); addCommand(QFtp::Login, ftp->login("ftptest", "password")); addCommand(QFtp::Cd, ftp->cd("qtest/upload")); addCommand(QFtp::Get, ftp->get(file, &getBuf, QFtp::Binary)); @@ -1621,7 +1644,7 @@ void tst_QFtp::binaryAscii() delete ftp; ftp = 0; if ( QTestEventLoop::instance().timeout() ) - QFAIL( msgTimedOut(QtNetworkSettings::serverName()) ); + QSKIP( msgTimedOut(QtNetworkSettings::ftpServerName()) ); ResMapIt it2 = resultMap.find(QFtp::Get); QVERIFY(it2 != resultMap.end()); @@ -1634,7 +1657,7 @@ void tst_QFtp::binaryAscii() // cleanup (i.e. remove the file) -- this also tests the remove command init(); ftp = newFtp(); - addCommand(QFtp::ConnectToHost, ftp->connectToHost(QtNetworkSettings::serverName(), 21)); + addCommand(QFtp::ConnectToHost, ftp->connectToHost(QtNetworkSettings::ftpServerName(), 21)); addCommand(QFtp::Login, ftp->login("ftptest", "password")); addCommand(QFtp::Cd, ftp->cd("qtest/upload")); addCommand(QFtp::Remove, ftp->remove(file)); @@ -1644,13 +1667,13 @@ void tst_QFtp::binaryAscii() delete ftp; ftp = 0; if ( QTestEventLoop::instance().timeout() ) - QFAIL( msgTimedOut(QtNetworkSettings::serverName()) ); + QSKIP( msgTimedOut(QtNetworkSettings::ftpServerName()) ); it = resultMap.find( QFtp::Remove ); QVERIFY( it != resultMap.end() ); QCOMPARE( it.value().success, 1 ); - QVERIFY(!fileExists(QtNetworkSettings::serverName(), 21, "ftptest", "password", file)); + QVERIFY(!fileExists(QtNetworkSettings::ftpServerName(), 21, "ftptest", "password", file)); } @@ -2067,7 +2090,7 @@ void tst_QFtp::doneSignal() QFtp ftp; QSignalSpy spy(&ftp, SIGNAL(done(bool))); - ftp.connectToHost(QtNetworkSettings::serverName()); + ftp.connectToHost(QtNetworkSettings::ftpServerName()); ftp.login("anonymous"); ftp.list(); ftp.close(); @@ -2076,7 +2099,7 @@ void tst_QFtp::doneSignal() connect(&ftp, SIGNAL(done(bool)), &(QTestEventLoop::instance()), SLOT(exitLoop())); QTestEventLoop::instance().enterLoop(61); if (QTestEventLoop::instance().timeout()) - QFAIL("Network operation timed out"); + QSKIP( msgTimedOut(QtNetworkSettings::ftpServerName()) ); QCOMPARE(spy.count(), 1); QCOMPARE(spy.first().first().toBool(), false); diff --git a/tests/auto/network/access/qhttpnetworkconnection/qhttpnetworkconnection.pro b/tests/auto/network/access/qhttpnetworkconnection/qhttpnetworkconnection.pro index 69a4a50144..84e6f857a1 100644 --- a/tests/auto/network/access/qhttpnetworkconnection/qhttpnetworkconnection.pro +++ b/tests/auto/network/access/qhttpnetworkconnection/qhttpnetworkconnection.pro @@ -5,6 +5,5 @@ requires(qtConfig(private_tests)) QT = core-private network-private testlib +CONFIG += unsupported/testserver QT_TEST_SERVER_LIST = apache2 -include($$dirname(_QMAKE_CONF_)/tests/auto/testserver.pri) - diff --git a/tests/auto/network/access/qnetworkcookiejar/tst_qnetworkcookiejar.cpp b/tests/auto/network/access/qnetworkcookiejar/tst_qnetworkcookiejar.cpp index 45abb6aa05..1ef2c118b9 100644 --- a/tests/auto/network/access/qnetworkcookiejar/tst_qnetworkcookiejar.cpp +++ b/tests/auto/network/access/qnetworkcookiejar/tst_qnetworkcookiejar.cpp @@ -61,10 +61,8 @@ class MyCookieJar: public QNetworkCookieJar { public: ~MyCookieJar() override; - inline QList<QNetworkCookie> allCookies() const - { return QNetworkCookieJar::allCookies(); } - inline void setAllCookies(const QList<QNetworkCookie> &cookieList) - { QNetworkCookieJar::setAllCookies(cookieList); } + using QNetworkCookieJar::allCookies; + using QNetworkCookieJar::setAllCookies; }; MyCookieJar::~MyCookieJar() = default; diff --git a/tests/auto/network/access/qnetworkreply/test/test.pro b/tests/auto/network/access/qnetworkreply/test/test.pro index 9d36352abc..4cc1f6431e 100644 --- a/tests/auto/network/access/qnetworkreply/test/test.pro +++ b/tests/auto/network/access/qnetworkreply/test/test.pro @@ -15,5 +15,5 @@ TESTDATA += ../empty ../rfc3252.txt ../resource ../bigfile ../*.jpg ../certs \ !android:!winrt: TEST_HELPER_INSTALLS = ../echo/echo +CONFIG += unsupported/testserver QT_TEST_SERVER_LIST = vsftpd apache2 ftp-proxy danted squid -include($$dirname(_QMAKE_CONF_)/tests/auto/testserver.pri) diff --git a/tests/auto/network/access/qnetworkreply/tst_qnetworkreply.cpp b/tests/auto/network/access/qnetworkreply/tst_qnetworkreply.cpp index eb956bec30..550d80501e 100644 --- a/tests/auto/network/access/qnetworkreply/tst_qnetworkreply.cpp +++ b/tests/auto/network/access/qnetworkreply/tst_qnetworkreply.cpp @@ -503,6 +503,11 @@ private Q_SLOTS: void putWithServerClosingConnectionImmediately(); #endif + void autoDeleteRepliesAttribute_data(); + void autoDeleteRepliesAttribute(); + void autoDeleteReplies_data(); + void autoDeleteReplies(); + // NOTE: This test must be last! void parentingRepliesToTheApp(); private: @@ -1552,7 +1557,7 @@ void tst_QNetworkReply::initTestCase() QDir::setSearchPaths("testdata", QStringList() << testDataDir); #ifndef QT_NO_SSL - QSslSocket::defaultCaCertificates(); //preload certificates + QSslConfiguration::defaultConfiguration().caCertificates(); //preload certificates #endif #ifndef QT_NO_BEARERMANAGEMENT netConfMan = new QNetworkConfigurationManager(this); @@ -8143,16 +8148,17 @@ void tst_QNetworkReply::backgroundRequest() SLOT(sslErrors(QNetworkReply*,QList<QSslError>))); #endif - const QWeakPointer<const QNetworkSession> session = QNetworkAccessManagerPrivate::getNetworkSession(&manager); - QVERIFY(session); - QNetworkSession::UsagePolicies original = session.data()->usagePolicies(); - QNetworkSessionPrivate::setUsagePolicies(*const_cast<QNetworkSession *>(session.data()), QNetworkSession::UsagePolicies(policy)); + const QWeakPointer<const QNetworkSession> sessionWeakPtr = QNetworkAccessManagerPrivate::getNetworkSession(&manager); + QVERIFY(!sessionWeakPtr.isNull()); + auto session = const_cast<QNetworkSession *>(sessionWeakPtr.toStrongRef().data()); + QNetworkSession::UsagePolicies original = session->usagePolicies(); + QNetworkSessionPrivate::setUsagePolicies(*session, QNetworkSession::UsagePolicies(policy)); QNetworkReplyPtr reply(manager.get(request)); QVERIFY(waitForFinish(reply) != Timeout); if (session) - QNetworkSessionPrivate::setUsagePolicies(*const_cast<QNetworkSession *>(session.data()), original); + QNetworkSessionPrivate::setUsagePolicies(*session, original); QVERIFY(reply->isFinished()); QCOMPARE(reply->error(), error); @@ -8207,10 +8213,11 @@ void tst_QNetworkReply::backgroundRequestInterruption() SLOT(sslErrors(QNetworkReply*,QList<QSslError>))); #endif - const QWeakPointer<const QNetworkSession> session = QNetworkAccessManagerPrivate::getNetworkSession(&manager); - QVERIFY(session); - QNetworkSession::UsagePolicies original = session.data()->usagePolicies(); - QNetworkSessionPrivate::setUsagePolicies(*const_cast<QNetworkSession *>(session.data()), QNetworkSession::NoPolicy); + const QWeakPointer<const QNetworkSession> sessionWeakPtr = QNetworkAccessManagerPrivate::getNetworkSession(&manager); + QVERIFY(!sessionWeakPtr.isNull()); + auto session = const_cast<QNetworkSession *>(sessionWeakPtr.toStrongRef().data()); + QNetworkSession::UsagePolicies original = session->usagePolicies(); + QNetworkSessionPrivate::setUsagePolicies(*session, QNetworkSession::NoPolicy); request.setAttribute(QNetworkRequest::MaximumDownloadBufferSizeAttribute, 8192); QNetworkReplyPtr reply(manager.get(request)); @@ -8219,14 +8226,14 @@ void tst_QNetworkReply::backgroundRequestInterruption() QSignalSpy spy(reply.data(), SIGNAL(readyRead())); QTRY_VERIFY(spy.count() > 0); - QNetworkSessionPrivate::setUsagePolicies(*const_cast<QNetworkSession *>(session.data()), QNetworkSession::NoBackgroundTrafficPolicy); + QNetworkSessionPrivate::setUsagePolicies(*session, QNetworkSession::NoBackgroundTrafficPolicy); // After we have changed the policy we can download at full speed. reply->setReadBufferSize(0); QVERIFY(waitForFinish(reply) != Timeout); if (session) - QNetworkSessionPrivate::setUsagePolicies(*const_cast<QNetworkSession *>(session.data()), original); + QNetworkSessionPrivate::setUsagePolicies(*session, original); QVERIFY(reply->isFinished()); QCOMPARE(reply->error(), error); @@ -8266,8 +8273,8 @@ void tst_QNetworkReply::backgroundRequestConnectInBackground() QWeakPointer<const QNetworkSession> session = QNetworkAccessManagerPrivate::getNetworkSession(&manager); //force QNAM to reopen the session. - if (session && session.data()->isOpen()) { - const_cast<QNetworkSession *>(session.data())->close(); + if (session && session.toStrongRef().data()->isOpen()) { + const_cast<QNetworkSession *>(session.toStrongRef().data())->close(); QCoreApplication::processEvents(); //let signals propagate inside QNAM } @@ -8276,19 +8283,19 @@ void tst_QNetworkReply::backgroundRequestConnectInBackground() session = QNetworkAccessManagerPrivate::getNetworkSession(&manager); QVERIFY(session); - QNetworkSession::UsagePolicies original = session.data()->usagePolicies(); - QNetworkSessionPrivate::setUsagePolicies(*const_cast<QNetworkSession *>(session.data()), QNetworkSession::NoPolicy); + QNetworkSession::UsagePolicies original = session.toStrongRef().data()->usagePolicies(); + QNetworkSessionPrivate::setUsagePolicies(*const_cast<QNetworkSession *>(session.toStrongRef().data()), QNetworkSession::NoPolicy); QNetworkReplyPtr reply(manager.get(request)); QVERIFY(waitForFinish(reply) != Timeout); session = QNetworkAccessManagerPrivate::getNetworkSession(&manager); if (session) { - QVariant cib = session.data()->sessionProperty(QStringLiteral("ConnectInBackground")); + QVariant cib = session.toStrongRef().data()->sessionProperty(QStringLiteral("ConnectInBackground")); if (!cib.isValid()) QSKIP("inconclusive - ConnectInBackground session property not supported by the bearer plugin"); QCOMPARE(cib.toBool(), background); - QNetworkSessionPrivate::setUsagePolicies(*const_cast<QNetworkSession *>(session.data()), original); + QNetworkSessionPrivate::setUsagePolicies(*const_cast<QNetworkSession *>(session.toStrongRef().data()), original); } else { QSKIP("inconclusive - network session has been destroyed"); } @@ -9167,6 +9174,166 @@ void tst_QNetworkReply::putWithServerClosingConnectionImmediately() #endif +void tst_QNetworkReply::autoDeleteRepliesAttribute_data() +{ + QTest::addColumn<QUrl>("destination"); + + QTest::newRow("http") << QUrl("http://QInvalidDomain.qt/test"); + QTest::newRow("https") << QUrl("https://QInvalidDomain.qt/test"); + QTest::newRow("ftp") << QUrl("ftp://QInvalidDomain.qt/test"); + QTest::newRow("file") << QUrl("file:///thisfolderdoesn'texist/probably.txt"); +#ifdef Q_OS_WIN + // Only supported on windows. + QTest::newRow("remote-file") << QUrl("file://QInvalidHost/thisfolderdoesn'texist/probably.txt"); +#endif + QTest::newRow("qrc") << QUrl("qrc:///path/to/nowhere"); + QTest::newRow("data") << QUrl("data:,Some%20plaintext%20data"); +} + +void tst_QNetworkReply::autoDeleteRepliesAttribute() +{ + QFETCH(QUrl, destination); + { + // Get + QNetworkRequest request(destination); + request.setAttribute(QNetworkRequest::AutoDeleteReplyOnFinishAttribute, true); + QNetworkReply *reply = manager.get(request); + QSignalSpy finishedSpy(reply, &QNetworkReply::finished); + QSignalSpy destroyedSpy(reply, &QObject::destroyed); + QVERIFY(finishedSpy.wait()); + QCOMPARE(destroyedSpy.count(), 0); + QVERIFY(destroyedSpy.wait()); + } + { + // Post + QNetworkRequest request(destination); + request.setAttribute(QNetworkRequest::AutoDeleteReplyOnFinishAttribute, true); + QNetworkReply *reply = manager.post(request, QByteArrayLiteral("datastring")); + QSignalSpy finishedSpy(reply, &QNetworkReply::finished); + QSignalSpy destroyedSpy(reply, &QObject::destroyed); + QVERIFY(finishedSpy.wait()); + QCOMPARE(destroyedSpy.count(), 0); + QVERIFY(destroyedSpy.wait()); + } + // Now repeated, but without the attribute to make sure it does not get deleted automatically. + // We need two calls to processEvents to test that the QNetworkReply doesn't get deleted. + // The first call executes a metacall event which adds the deleteLater meta event which + // would be executed in the second call. But that shouldn't happen without the attribute. + { + // Get + QNetworkRequest request(destination); + QScopedPointer<QNetworkReply> reply(manager.get(request)); + QSignalSpy finishedSpy(reply.data(), &QNetworkReply::finished); + QSignalSpy destroyedSpy(reply.data(), &QObject::destroyed); + QVERIFY(finishedSpy.wait()); + QCOMPARE(destroyedSpy.count(), 0); + QCoreApplication::processEvents(); + QCoreApplication::processEvents(); + QCOMPARE(destroyedSpy.count(), 0); + } + { + // Post + QNetworkRequest request(destination); + QScopedPointer<QNetworkReply> reply(manager.post(request, QByteArrayLiteral("datastring"))); + QSignalSpy finishedSpy(reply.data(), &QNetworkReply::finished); + QSignalSpy destroyedSpy(reply.data(), &QObject::destroyed); + QVERIFY(finishedSpy.wait()); + QCOMPARE(destroyedSpy.count(), 0); + QCoreApplication::processEvents(); + QCoreApplication::processEvents(); + QCOMPARE(destroyedSpy.count(), 0); + } +} + +void tst_QNetworkReply::autoDeleteReplies_data() +{ + autoDeleteRepliesAttribute_data(); +} + +void tst_QNetworkReply::autoDeleteReplies() +{ + QFETCH(QUrl, destination); + manager.setAutoDeleteReplies(true); + auto cleanup = qScopeGuard([this] { manager.setAutoDeleteReplies(false); }); + { + // Get + QNetworkRequest request(destination); + QNetworkReply *reply = manager.get(request); + QSignalSpy finishedSpy(reply, &QNetworkReply::finished); + QSignalSpy destroyedSpy(reply, &QObject::destroyed); + QVERIFY(finishedSpy.wait()); + QCOMPARE(destroyedSpy.count(), 0); + QVERIFY(destroyedSpy.wait()); + } + { + // Post + QNetworkRequest request(destination); + QNetworkReply *reply = manager.post(request, QByteArrayLiteral("datastring")); + QSignalSpy finishedSpy(reply, &QNetworkReply::finished); + QSignalSpy destroyedSpy(reply, &QObject::destroyed); + QVERIFY(finishedSpy.wait()); + QCOMPARE(destroyedSpy.count(), 0); + QVERIFY(destroyedSpy.wait()); + } + // Here we repeat the test, but override the auto-deletion in the QNetworkRequest + // We need two calls to processEvents to test that the QNetworkReply doesn't get deleted. + // The first call executes a metacall event which adds the deleteLater meta event which + // would be executed in the second call. But that shouldn't happen in this case. + { + // Get + QNetworkRequest request(destination); + request.setAttribute(QNetworkRequest::AutoDeleteReplyOnFinishAttribute, false); + QScopedPointer<QNetworkReply> reply(manager.get(request)); + QSignalSpy finishedSpy(reply.data(), &QNetworkReply::finished); + QSignalSpy destroyedSpy(reply.data(), &QObject::destroyed); + QVERIFY(finishedSpy.wait()); + QCOMPARE(destroyedSpy.count(), 0); + QCoreApplication::processEvents(); + QCoreApplication::processEvents(); + QCOMPARE(destroyedSpy.count(), 0); + } + { + // Post + QNetworkRequest request(destination); + request.setAttribute(QNetworkRequest::AutoDeleteReplyOnFinishAttribute, false); + QScopedPointer<QNetworkReply> reply(manager.post(request, QByteArrayLiteral("datastring"))); + QSignalSpy finishedSpy(reply.data(), &QNetworkReply::finished); + QSignalSpy destroyedSpy(reply.data(), &QObject::destroyed); + QVERIFY(finishedSpy.wait()); + QCOMPARE(destroyedSpy.count(), 0); + QCoreApplication::processEvents(); + QCoreApplication::processEvents(); + QCOMPARE(destroyedSpy.count(), 0); + } + // Now we repeat the test with autoDeleteReplies set to false + cleanup.dismiss(); + manager.setAutoDeleteReplies(false); + { + // Get + QNetworkRequest request(destination); + QScopedPointer<QNetworkReply> reply(manager.get(request)); + QSignalSpy finishedSpy(reply.data(), &QNetworkReply::finished); + QSignalSpy destroyedSpy(reply.data(), &QObject::destroyed); + QVERIFY(finishedSpy.wait()); + QCOMPARE(destroyedSpy.count(), 0); + QCoreApplication::processEvents(); + QCoreApplication::processEvents(); + QCOMPARE(destroyedSpy.count(), 0); + } + { + // Post + QNetworkRequest request(destination); + QScopedPointer<QNetworkReply> reply(manager.post(request, QByteArrayLiteral("datastring"))); + QSignalSpy finishedSpy(reply.data(), &QNetworkReply::finished); + QSignalSpy destroyedSpy(reply.data(), &QObject::destroyed); + QVERIFY(finishedSpy.wait()); + QCOMPARE(destroyedSpy.count(), 0); + QCoreApplication::processEvents(); + QCoreApplication::processEvents(); + QCOMPARE(destroyedSpy.count(), 0); + } +} + // NOTE: This test must be last testcase in tst_qnetworkreply! void tst_QNetworkReply::parentingRepliesToTheApp() { diff --git a/tests/auto/network/kernel/qhostaddress/qhostaddress.pro b/tests/auto/network/kernel/qhostaddress/qhostaddress.pro index b5d6ea6459..d170d879e6 100644 --- a/tests/auto/network/kernel/qhostaddress/qhostaddress.pro +++ b/tests/auto/network/kernel/qhostaddress/qhostaddress.pro @@ -4,4 +4,4 @@ SOURCES += tst_qhostaddress.cpp QT = core network-private testlib -win32:LIBS += -lws2_32 +win32: QMAKE_USE += ws2_32 diff --git a/tests/auto/network/kernel/qhostinfo/qhostinfo.pro b/tests/auto/network/kernel/qhostinfo/qhostinfo.pro index 3d8457dd46..d358cdf52c 100644 --- a/tests/auto/network/kernel/qhostinfo/qhostinfo.pro +++ b/tests/auto/network/kernel/qhostinfo/qhostinfo.pro @@ -6,6 +6,6 @@ SOURCES += tst_qhostinfo.cpp requires(qtConfig(private_tests)) QT = core-private network-private testlib -win32:LIBS += -lws2_32 +win32: QMAKE_USE += ws2_32 winrt: WINRT_MANIFEST.capabilities += internetClientServer diff --git a/tests/auto/network/socket/platformsocketengine/BLACKLIST b/tests/auto/network/socket/platformsocketengine/BLACKLIST index 8e1a55995e..154c5cc5b2 100644 --- a/tests/auto/network/socket/platformsocketengine/BLACKLIST +++ b/tests/auto/network/socket/platformsocketengine/BLACKLIST @@ -1 +1,8 @@ +[tcpLoopbackPerformance] +windows +[receiveUrgentData] +windows +[serverTest] +windows +[tcpLoopbackPerformance] windows diff --git a/tests/auto/network/socket/platformsocketengine/platformsocketengine.pri b/tests/auto/network/socket/platformsocketengine/platformsocketengine.pri index 46c722deba..868439de6a 100644 --- a/tests/auto/network/socket/platformsocketengine/platformsocketengine.pri +++ b/tests/auto/network/socket/platformsocketengine/platformsocketengine.pri @@ -4,7 +4,7 @@ QNETWORK_SRC = $$QT_SOURCE_TREE/src/network INCLUDEPATH += $$QNETWORK_SRC -win32:LIBS += -lws2_32 +win32: QMAKE_USE += ws2_32 unix:qtConfig(reduce_exports) { SOURCES += $$QNETWORK_SRC/socket/qnativesocketengine_unix.cpp diff --git a/tests/auto/network/socket/qhttpsocketengine/BLACKLIST b/tests/auto/network/socket/qhttpsocketengine/BLACKLIST index 8e1a55995e..991d01dd00 100644 --- a/tests/auto/network/socket/qhttpsocketengine/BLACKLIST +++ b/tests/auto/network/socket/qhttpsocketengine/BLACKLIST @@ -1 +1,6 @@ +[passwordAuth] +windows +[downloadBigFile] +windows +[ensureEofTriggersNotification] windows diff --git a/tests/auto/network/socket/qhttpsocketengine/qhttpsocketengine.pro b/tests/auto/network/socket/qhttpsocketengine/qhttpsocketengine.pro index 492bb6aa8d..63f41f4eb7 100644 --- a/tests/auto/network/socket/qhttpsocketengine/qhttpsocketengine.pro +++ b/tests/auto/network/socket/qhttpsocketengine/qhttpsocketengine.pro @@ -12,6 +12,6 @@ QT = core-private network-private testlib # TODO: For now linux-only, because cyrus is linux-only atm ... linux { + CONFIG += unsupported/testserver QT_TEST_SERVER_LIST = squid danted cyrus apache2 - include($$dirname(_QMAKE_CONF_)/tests/auto/testserver.pri) } diff --git a/tests/auto/network/socket/qlocalsocket/tst_qlocalsocket.cpp b/tests/auto/network/socket/qlocalsocket/tst_qlocalsocket.cpp index 45ab275510..f53c75c6a4 100644 --- a/tests/auto/network/socket/qlocalsocket/tst_qlocalsocket.cpp +++ b/tests/auto/network/socket/qlocalsocket/tst_qlocalsocket.cpp @@ -552,7 +552,7 @@ void tst_QLocalSocket::sendData() QCOMPARE(serverSocket->state(), QLocalSocket::ConnectedState); QTextStream out(serverSocket); QTextStream in(&socket); - out << testLine << endl; + out << testLine << Qt::endl; bool wrote = serverSocket->waitForBytesWritten(3000); if (!socket.canReadLine()) { @@ -877,7 +877,7 @@ public: QLocalSocket *serverSocket = server.nextPendingConnection(); QVERIFY(serverSocket); QTextStream out(serverSocket); - out << testLine << endl; + out << testLine << Qt::endl; QCOMPARE(serverSocket->state(), QLocalSocket::ConnectedState); QVERIFY2(serverSocket->waitForBytesWritten(), serverSocket->errorString().toLatin1().constData()); QCOMPARE(serverSocket->errorString(), QString("Unknown error")); diff --git a/tests/auto/network/socket/qsocks5socketengine/qsocks5socketengine.pro b/tests/auto/network/socket/qsocks5socketengine/qsocks5socketengine.pro index ca9e44873c..243eab9480 100644 --- a/tests/auto/network/socket/qsocks5socketengine/qsocks5socketengine.pro +++ b/tests/auto/network/socket/qsocks5socketengine/qsocks5socketengine.pro @@ -14,6 +14,6 @@ requires(qtConfig(private_tests)) # Only on Linux until cyrus has been added to docker-compose-for-{windows,macOS}.yml and tested linux { + CONFIG += unsupported/testserver QT_TEST_SERVER_LIST = danted apache2 cyrus - include($$dirname(_QMAKE_CONF_)/tests/auto/testserver.pri) } diff --git a/tests/auto/network/socket/qtcpserver/crashingServer/main.cpp b/tests/auto/network/socket/qtcpserver/crashingServer/main.cpp index 1a8e7920d3..5c66ef6520 100644 --- a/tests/auto/network/socket/qtcpserver/crashingServer/main.cpp +++ b/tests/auto/network/socket/qtcpserver/crashingServer/main.cpp @@ -29,14 +29,14 @@ #include <QtCore> #include <QtNetwork> -#if defined(Q_OS_WIN) && !defined(Q_OS_WINCE) && !defined(Q_OS_WINRT) && defined(Q_CC_MSVC) +#if defined(Q_OS_WIN) && !defined(Q_OS_WINRT) && defined(Q_CC_MSVC) # include <crtdbg.h> #endif int main(int argc, char *argv[]) { // Windows: Suppress crash notification dialog. -#if defined(Q_OS_WIN) && !defined(Q_OS_WINCE) && !defined(Q_OS_WINRT) && defined(Q_CC_MSVC) +#if defined(Q_OS_WIN) && !defined(Q_OS_WINRT) && defined(Q_CC_MSVC) _CrtSetReportMode(_CRT_ERROR, _CRTDBG_MODE_DEBUG); #endif QCoreApplication app(argc, argv); diff --git a/tests/auto/network/socket/qtcpserver/test/test.pro b/tests/auto/network/socket/qtcpserver/test/test.pro index ac4ed9a989..7e2e60a1e3 100644 --- a/tests/auto/network/socket/qtcpserver/test/test.pro +++ b/tests/auto/network/socket/qtcpserver/test/test.pro @@ -1,7 +1,7 @@ CONFIG += testcase SOURCES += ../tst_qtcpserver.cpp -win32:LIBS += -lws2_32 +win32: QMAKE_USE += ws2_32 TARGET = ../tst_qtcpserver @@ -19,6 +19,6 @@ MOC_DIR=tmp # Only on Linux until cyrus has been added to docker-compose-for-{windows,macOS}.yml and tested linux { + CONFIG += unsupported/testserver QT_TEST_SERVER_LIST = danted cyrus squid ftp-proxy - include($$dirname(_QMAKE_CONF_)/tests/auto/testserver.pri) } diff --git a/tests/auto/network/socket/qtcpsocket/test/test.pro b/tests/auto/network/socket/qtcpsocket/test/test.pro index 29d9414b03..4c07b1ec66 100644 --- a/tests/auto/network/socket/qtcpsocket/test/test.pro +++ b/tests/auto/network/socket/qtcpsocket/test/test.pro @@ -2,8 +2,8 @@ CONFIG += testcase QT = core-private network-private testlib SOURCES += ../tst_qtcpsocket.cpp -win32:LIBS += -lws2_32 +win32: QMAKE_USE += ws2_32 TARGET = tst_qtcpsocket win32 { @@ -18,6 +18,6 @@ win32 { # Only on Linux until cyrus has been added to docker-compose-for-{windows,macOS}.yml and tested linux { + CONFIG += unsupported/testserver QT_TEST_SERVER_LIST = danted squid apache2 ftp-proxy vsftpd iptables cyrus - include($$dirname(_QMAKE_CONF_)/tests/auto/testserver.pri) } diff --git a/tests/auto/network/socket/qudpsocket/test/test.pro b/tests/auto/network/socket/qudpsocket/test/test.pro index 0fdb97ba27..969e4d72cf 100644 --- a/tests/auto/network/socket/qudpsocket/test/test.pro +++ b/tests/auto/network/socket/qudpsocket/test/test.pro @@ -20,6 +20,6 @@ TARGET = tst_qudpsocket # Only on Linux until 'echo' has been added to docker-compose-for-{windows,macOS}.yml and tested linux { + CONFIG += unsupported/testserver QT_TEST_SERVER_LIST = danted echo - include($$dirname(_QMAKE_CONF_)/tests/auto/testserver.pri) } diff --git a/tests/auto/network/ssl/qsslsocket/BLACKLIST b/tests/auto/network/ssl/qsslsocket/BLACKLIST index 555822d1e6..3ecd3d9dbb 100644 --- a/tests/auto/network/ssl/qsslsocket/BLACKLIST +++ b/tests/auto/network/ssl/qsslsocket/BLACKLIST @@ -1,7 +1,23 @@ +[abortOnSslErrors] +windows +[deprecatedProtocols] +windows +[disabledProtocols] +windows +[protocol] +windows +[qtbug18498_peek] +windows +[setReadBufferSize] +windows +[spontaneousWrite] +windows +[sslErrors] windows [connectToHostEncrypted] osx-10.13 [setSslConfiguration] +windows osx-10.13 [connectToHostEncryptedWithVerificationPeerName] osx-10.13 diff --git a/tests/auto/network/ssl/qsslsocket/qsslsocket.pro b/tests/auto/network/ssl/qsslsocket/qsslsocket.pro index 03fbe89002..51fcff9a8d 100644 --- a/tests/auto/network/ssl/qsslsocket/qsslsocket.pro +++ b/tests/auto/network/ssl/qsslsocket/qsslsocket.pro @@ -22,6 +22,6 @@ requires(qtConfig(private_tests)) # DOCKERTODO: it's 'linux' because it requires cyrus, which # is linux-only for now ... linux { + CONFIG += unsupported/testserver QT_TEST_SERVER_LIST = squid danted cyrus apache2 echo - include($$dirname(_QMAKE_CONF_)/tests/auto/testserver.pri) } diff --git a/tests/auto/network/ssl/qsslsocket_onDemandCertificates_member/qsslsocket_onDemandCertificates_member.pro b/tests/auto/network/ssl/qsslsocket_onDemandCertificates_member/qsslsocket_onDemandCertificates_member.pro index 3e3ebeb358..8585a3c861 100644 --- a/tests/auto/network/ssl/qsslsocket_onDemandCertificates_member/qsslsocket_onDemandCertificates_member.pro +++ b/tests/auto/network/ssl/qsslsocket_onDemandCertificates_member/qsslsocket_onDemandCertificates_member.pro @@ -20,6 +20,6 @@ requires(qtConfig(private_tests)) # DOCKERTODO: linux, docker is disabled on macOS/Windows. linux { + CONFIG += unsupported/testserver QT_TEST_SERVER_LIST = squid danted - include($$dirname(_QMAKE_CONF_)/tests/auto/testserver.pri) } diff --git a/tests/auto/network/ssl/qsslsocket_onDemandCertificates_static/qsslsocket_onDemandCertificates_static.pro b/tests/auto/network/ssl/qsslsocket_onDemandCertificates_static/qsslsocket_onDemandCertificates_static.pro index 1ad42b309e..158ecbee37 100644 --- a/tests/auto/network/ssl/qsslsocket_onDemandCertificates_static/qsslsocket_onDemandCertificates_static.pro +++ b/tests/auto/network/ssl/qsslsocket_onDemandCertificates_static/qsslsocket_onDemandCertificates_static.pro @@ -19,6 +19,6 @@ requires(qtConfig(private_tests)) #DOCKERTODO Linux, docker is disabled on macOS and Windows. linux { + CONFIG += unsupported/testserver QT_TEST_SERVER_LIST = squid danted - include($$dirname(_QMAKE_CONF_)/tests/auto/testserver.pri) } diff --git a/tests/auto/other/lancelot/paintcommands.cpp b/tests/auto/other/lancelot/paintcommands.cpp index 8aa3a035e3..8a2934049e 100644 --- a/tests/auto/other/lancelot/paintcommands.cpp +++ b/tests/auto/other/lancelot/paintcommands.cpp @@ -1200,7 +1200,10 @@ void PaintCommands::command_drawRoundRect(QRegularExpressionMatch re) if (m_verboseMode) printf(" -(lance) drawRoundRect(%d, %d, %d, %d, [%d, %d])\n", x, y, w, h, xs, ys); + QT_WARNING_PUSH + QT_WARNING_DISABLE_DEPRECATED m_painter->drawRoundRect(x, y, w, h, xs, ys); + QT_WARNING_POP } /***************************************************************************************************/ diff --git a/tests/auto/other/lancelot/paintcommands.h b/tests/auto/other/lancelot/paintcommands.h index 79bdab634a..2923502e68 100644 --- a/tests/auto/other/lancelot/paintcommands.h +++ b/tests/auto/other/lancelot/paintcommands.h @@ -37,6 +37,7 @@ #include <qpixmap.h> #include <qbrush.h> #include <qhash.h> +#include <qregexp.h> QT_FORWARD_DECLARE_CLASS(QPainter) #ifndef QT_NO_OPENGL diff --git a/tests/auto/other/lancelot/scripts/thinlines.qps b/tests/auto/other/lancelot/scripts/thinlines.qps new file mode 100644 index 0000000000..dddfff4538 --- /dev/null +++ b/tests/auto/other/lancelot/scripts/thinlines.qps @@ -0,0 +1,79 @@ +# Version: 1 +# CheckVsReference: 5% + +drawRect 0 0 800 800 + +path_addRect p 0 0 75 75 +path_addEllipse p 25 25 75 75 + +translate -500 -500 + +begin_block drawing + save + drawLine 0 0 100 100 + + translate 0 100 + drawPath p + + translate 0 110 + drawRect 0 0 100 100 + + translate 0 110 + drawPolyline [0 0 100 0 50 50] + + drawPoint 40 40 + drawPoint 41 40 + drawPoint 42 40 + drawPoint 43 40 + drawPoint 44 40 + drawPoint 45 40 + drawPoint 46 40 + drawPoint 47 40 + drawPoint 48 40 + drawPoint 49 40 + drawPoint 50 40 + + restore +end_block + +begin_block univsnonuni + save + + save + scale 0.7 0.7 + repeat_block drawing + restore + + translate 100 0 + save + scale 0.7 0.8 + repeat_block drawing + restore + + restore +end_block + +resetMatrix +translate 20.5 20.5 + +begin_block row +save + repeat_block univsnonuni + + translate 240 0 + save + rotate 10 + repeat_block univsnonuni + restore + + translate 220 0 + save + rotate_y 30 + repeat_block univsnonuni + restore +restore +end_block + +translate 0 320 +setRenderHint AntiAliasing +repeat_block row diff --git a/tests/auto/other/qaccessibility/qaccessibility.pro b/tests/auto/other/qaccessibility/qaccessibility.pro index 3587c38e76..6f3740a24f 100644 --- a/tests/auto/other/qaccessibility/qaccessibility.pro +++ b/tests/auto/other/qaccessibility/qaccessibility.pro @@ -11,5 +11,6 @@ win32 { !winrt { QT += windowsuiautomation_support-private } - LIBS += -luuid -loleacc -loleaut32 -lole32 + LIBS += -loleacc -loleaut32 + QMAKE_USE += ole32 uuid } diff --git a/tests/auto/other/qaccessibility/tst_qaccessibility.cpp b/tests/auto/other/qaccessibility/tst_qaccessibility.cpp index 8b24937079..7d7fa6403b 100644 --- a/tests/auto/other/qaccessibility/tst_qaccessibility.cpp +++ b/tests/auto/other/qaccessibility/tst_qaccessibility.cpp @@ -2045,6 +2045,15 @@ void tst_QAccessibility::lineEditTest() QVERIFY(!iface->state().selectable); QVERIFY(iface->state().selectableText); QVERIFY(!iface->state().hasPopup); + QVERIFY(!iface->state().readOnly); + QVERIFY(iface->state().editable); + + le->setReadOnly(true); + QVERIFY(iface->state().editable); + QVERIFY(iface->state().readOnly); + le->setReadOnly(false); + QVERIFY(!iface->state().readOnly); + QCOMPARE(bool(iface->state().focused), le->hasFocus()); QString secret(QLatin1String("secret")); @@ -2571,6 +2580,7 @@ void tst_QAccessibility::dialogButtonBoxTest() case QDialogButtonBox::GnomeLayout: case QDialogButtonBox::KdeLayout: case QDialogButtonBox::MacLayout: + case QDialogButtonBox::AndroidLayout: expectedOrder << QDialogButtonBox::tr("Help") << QDialogButtonBox::tr("Reset") << QDialogButtonBox::tr("OK"); @@ -3640,6 +3650,12 @@ void tst_QAccessibility::labelTest() QVERIFY(acc_label); QCOMPARE(acc_label->text(QAccessible::Name), text); + QCOMPARE(acc_label->state().editable, false); + QCOMPARE(acc_label->state().passwordEdit, false); + QCOMPARE(acc_label->state().disabled, false); + QCOMPARE(acc_label->state().focused, false); + QCOMPARE(acc_label->state().focusable, false); + QCOMPARE(acc_label->state().readOnly, true); QVector<QPair<QAccessibleInterface *, QAccessible::Relation> > rels = acc_label->relations(); QCOMPARE(rels.count(), 1); diff --git a/tests/auto/other/qaccessibilitylinux/qaccessibilitylinux.pro b/tests/auto/other/qaccessibilitylinux/qaccessibilitylinux.pro index 5cb3f5902a..a964df0e24 100644 --- a/tests/auto/other/qaccessibilitylinux/qaccessibilitylinux.pro +++ b/tests/auto/other/qaccessibilitylinux/qaccessibilitylinux.pro @@ -5,3 +5,4 @@ SOURCES += tst_qaccessibilitylinux.cpp QT += gui-private widgets dbus testlib accessibility_support-private linuxaccessibility_support-private +DBUS_INTERFACES = $$PWD/../../../../src/platformsupport/linuxaccessibility/dbusxml/Bus.xml diff --git a/tests/auto/other/qaccessibilitylinux/tst_qaccessibilitylinux.cpp b/tests/auto/other/qaccessibilitylinux/tst_qaccessibilitylinux.cpp index 48594b2fa1..7ba3715e13 100644 --- a/tests/auto/other/qaccessibilitylinux/tst_qaccessibilitylinux.cpp +++ b/tests/auto/other/qaccessibilitylinux/tst_qaccessibilitylinux.cpp @@ -42,12 +42,11 @@ #include <QDBusInterface> #include <QDBusReply> -#include "atspi/atspi-constants.h" +#include <atspi/atspi-constants.h> +#include <private/dbusconnection_p.h> +#include <private/struct_marshallers_p.h> #include "bus_interface.h" -#include "dbusconnection_p.h" -#include "struct_marshallers_p.h" - #define COMPARE3(v1, v2, v3) QCOMPARE(v1, v3); QCOMPARE(v2, v3); class AccessibleTestWindow : public QWidget @@ -251,6 +250,8 @@ void tst_QAccessibilityLinux::testLabel() QCOMPARE(labelInterface->call(QDBus::Block, "GetRoleName").arguments().first().toString(), QLatin1String("label")); QCOMPARE(labelInterface->call(QDBus::Block, "GetRole").arguments().first().toUInt(), 29u); QCOMPARE(getParent(labelInterface), mainWindow->path()); + QVERIFY(!hasState(labelInterface, ATSPI_STATE_EDITABLE)); + QVERIFY(hasState(labelInterface, ATSPI_STATE_READ_ONLY)); l->setText("New text"); QCOMPARE(labelInterface->property("Name").toString(), l->text()); @@ -303,6 +304,12 @@ void tst_QAccessibilityLinux::testLineEdit() QCOMPARE(lineEdit->selectionStart(), -1); QCOMPARE(textInterface->call(QDBus::Block, "GetNSelections").arguments().first().toInt(), 0); + QVERIFY(hasState(accessibleInterface, ATSPI_STATE_EDITABLE)); + QVERIFY(!hasState(accessibleInterface, ATSPI_STATE_READ_ONLY)); + lineEdit->setReadOnly(true); + QVERIFY(hasState(accessibleInterface, ATSPI_STATE_EDITABLE)); + QVERIFY(hasState(accessibleInterface, ATSPI_STATE_READ_ONLY)); + m_window->clearChildren(); delete accessibleInterface; delete textInterface; diff --git a/tests/auto/printsupport/kernel/qprinter/tst_qprinter.cpp b/tests/auto/printsupport/kernel/qprinter/tst_qprinter.cpp index abe4325278..7529bad833 100644 --- a/tests/auto/printsupport/kernel/qprinter/tst_qprinter.cpp +++ b/tests/auto/printsupport/kernel/qprinter/tst_qprinter.cpp @@ -1315,7 +1315,9 @@ void tst_QPrinter::pageSize() // Test set/get QPrinter::PaperSize expected = QPrinter::A4; QPrinterInfo info = QPrinterInfo::printerInfo(native.printerName()); - foreach (QPrinter::PaperSize supported, info.supportedPaperSizes()) { + const auto &pageSizes = info.supportedPageSizes(); + for (const auto &pageSize : pageSizes) { + const QPrinter::PaperSize supported = QPrinter::PaperSize(pageSize.id()); if (supported != QPrinter::Custom && supported != native.paperSize()) { expected = supported; break; @@ -1359,7 +1361,9 @@ void tst_QPrinter::paperSize() // Test set/get QPrinter::PaperSize expected = QPrinter::A4; QPrinterInfo info = QPrinterInfo::printerInfo(native.printerName()); - foreach (QPrinter::PaperSize supported, info.supportedPaperSizes()) { + const auto &pageSizes = info.supportedPageSizes(); + for (const auto &pageSize : pageSizes) { + const QPrinter::PaperSize supported = QPrinter::PaperSize(pageSize.id()); if (supported != QPrinter::Custom && supported != native.paperSize()) { expected = supported; break; diff --git a/tests/auto/printsupport/kernel/qprinterinfo/tst_qprinterinfo.cpp b/tests/auto/printsupport/kernel/qprinterinfo/tst_qprinterinfo.cpp index 92a06cda00..99083242be 100644 --- a/tests/auto/printsupport/kernel/qprinterinfo/tst_qprinterinfo.cpp +++ b/tests/auto/printsupport/kernel/qprinterinfo/tst_qprinterinfo.cpp @@ -300,8 +300,11 @@ void tst_QPrinterInfo::testConstructors() QCOMPARE(copy1.supportsCustomPageSizes(), printers.at(i).supportsCustomPageSizes()); QCOMPARE(copy1.minimumPhysicalPageSize(), printers.at(i).minimumPhysicalPageSize()); QCOMPARE(copy1.maximumPhysicalPageSize(), printers.at(i).maximumPhysicalPageSize()); - QCOMPARE(copy1.supportedPaperSizes(), printers.at(i).supportedPaperSizes()); + QCOMPARE(copy1.supportedPageSizes(), printers.at(i).supportedPageSizes()); +QT_WARNING_PUSH +QT_WARNING_DISABLE_DEPRECATED QCOMPARE(copy1.supportedSizesWithNames(), printers.at(i).supportedSizesWithNames()); +QT_WARNING_POP QCOMPARE(copy1.supportedResolutions(), printers.at(i).supportedResolutions()); QCOMPARE(copy1.defaultDuplexMode(), printers.at(i).defaultDuplexMode()); QCOMPARE(copy1.supportedDuplexModes(), printers.at(i).supportedDuplexModes()); @@ -321,8 +324,11 @@ void tst_QPrinterInfo::testConstructors() QCOMPARE(copy2.supportsCustomPageSizes(), printers.at(i).supportsCustomPageSizes()); QCOMPARE(copy2.minimumPhysicalPageSize(), printers.at(i).minimumPhysicalPageSize()); QCOMPARE(copy2.maximumPhysicalPageSize(), printers.at(i).maximumPhysicalPageSize()); - QCOMPARE(copy2.supportedPaperSizes(), printers.at(i).supportedPaperSizes()); + QCOMPARE(copy2.supportedPageSizes(), printers.at(i).supportedPageSizes()); + QT_WARNING_PUSH + QT_WARNING_DISABLE_DEPRECATED QCOMPARE(copy2.supportedSizesWithNames(), printers.at(i).supportedSizesWithNames()); + QT_WARNING_POP QCOMPARE(copy2.supportedResolutions(), printers.at(i).supportedResolutions()); QCOMPARE(copy2.defaultDuplexMode(), printers.at(i).defaultDuplexMode()); QCOMPARE(copy2.supportedDuplexModes(), printers.at(i).supportedDuplexModes()); diff --git a/tests/auto/testlib/selftests/expected_float.lightxml b/tests/auto/testlib/selftests/expected_float.lightxml index 54d6eabdbd..5f5114bb2e 100644 --- a/tests/auto/testlib/selftests/expected_float.lightxml +++ b/tests/auto/testlib/selftests/expected_float.lightxml @@ -428,21 +428,24 @@ <Duration msecs="0"/> </TestFunction> <TestFunction name="float16Comparisons"> -<Incident type="pass" file="" line="0"> - <DataTag><![CDATA[should SUCCEED 1]]></DataTag> -</Incident> <Incident type="fail" file="qtbase/tests/auto/testlib/selftests/float/tst_float.cpp" line="0"> <DataTag><![CDATA[should FAIL 1]]></DataTag> <Description><![CDATA[Compared qfloat16s are not the same (fuzzy compare) Actual (operandLeft) : 1 Expected (operandRight): 3]]></Description> </Incident> +<Incident type="pass" file="" line="0"> + <DataTag><![CDATA[should PASS 1]]></DataTag> +</Incident> <Incident type="fail" file="qtbase/tests/auto/testlib/selftests/float/tst_float.cpp" line="0"> <DataTag><![CDATA[should FAIL 2]]></DataTag> <Description><![CDATA[Compared qfloat16s are not the same (fuzzy compare) Actual (operandLeft) : 0.0001 Expected (operandRight): 0.0003]]></Description> </Incident> +<Incident type="pass" file="" line="0"> + <DataTag><![CDATA[should PASS 2]]></DataTag> +</Incident> <Incident type="fail" file="qtbase/tests/auto/testlib/selftests/float/tst_float.cpp" line="0"> <DataTag><![CDATA[should FAIL 3]]></DataTag> <Description><![CDATA[Compared qfloat16s are not the same (fuzzy compare) @@ -450,7 +453,187 @@ Expected (operandRight): 99]]></Description> </Incident> <Incident type="pass" file="" line="0"> - <DataTag><![CDATA[should SUCCEED 2]]></DataTag> + <DataTag><![CDATA[should PASS 3]]></DataTag> +</Incident> +<Incident type="fail" file="qtbase/tests/auto/testlib/selftests/float/tst_float.cpp" line="0"> + <DataTag><![CDATA[should FAIL 4]]></DataTag> + <Description><![CDATA[Compared qfloat16s are not the same (fuzzy compare) + Actual (operandLeft) : 5.93e-05 + Expected (operandRight): 5.87e-05]]></Description> +</Incident> +<Incident type="pass" file="" line="0"> + <DataTag><![CDATA[should PASS 4]]></DataTag> +</Incident> +<Incident type="fail" file="qtbase/tests/auto/testlib/selftests/float/tst_float.cpp" line="0"> + <DataTag><![CDATA[should FAIL 5]]></DataTag> + <Description><![CDATA[Compared qfloat16s are not the same (fuzzy compare) + Actual (operandLeft) : 5.94e+04 + Expected (operandRight): 5.88e+04]]></Description> +</Incident> +<Incident type="pass" file="" line="0"> + <DataTag><![CDATA[should PASS: NaN == NaN]]></DataTag> +</Incident> +<Incident type="fail" file="qtbase/tests/auto/testlib/selftests/float/tst_float.cpp" line="0"> + <DataTag><![CDATA[should FAIL: NaN != 0]]></DataTag> + <Description><![CDATA[Compared qfloat16s are not the same (fuzzy compare) + Actual (operandLeft) : nan + Expected (operandRight): 0]]></Description> +</Incident> +<Incident type="fail" file="qtbase/tests/auto/testlib/selftests/float/tst_float.cpp" line="0"> + <DataTag><![CDATA[should FAIL: 0 != NaN]]></DataTag> + <Description><![CDATA[Compared qfloat16s are not the same (fuzzy compare) + Actual (operandLeft) : 0 + Expected (operandRight): nan]]></Description> +</Incident> +<Incident type="fail" file="qtbase/tests/auto/testlib/selftests/float/tst_float.cpp" line="0"> + <DataTag><![CDATA[should FAIL: NaN != 1]]></DataTag> + <Description><![CDATA[Compared qfloat16s are not the same (fuzzy compare) + Actual (operandLeft) : nan + Expected (operandRight): 1]]></Description> +</Incident> +<Incident type="fail" file="qtbase/tests/auto/testlib/selftests/float/tst_float.cpp" line="0"> + <DataTag><![CDATA[should FAIL: 1 != NaN]]></DataTag> + <Description><![CDATA[Compared qfloat16s are not the same (fuzzy compare) + Actual (operandLeft) : 1 + Expected (operandRight): nan]]></Description> +</Incident> +<Incident type="pass" file="" line="0"> + <DataTag><![CDATA[should PASS: inf == inf]]></DataTag> +</Incident> +<Incident type="pass" file="" line="0"> + <DataTag><![CDATA[should PASS: -inf == -inf]]></DataTag> +</Incident> +<Incident type="fail" file="qtbase/tests/auto/testlib/selftests/float/tst_float.cpp" line="0"> + <DataTag><![CDATA[should FAIL: inf != -inf]]></DataTag> + <Description><![CDATA[Compared qfloat16s are not the same (fuzzy compare) + Actual (operandLeft) : inf + Expected (operandRight): -inf]]></Description> +</Incident> +<Incident type="fail" file="qtbase/tests/auto/testlib/selftests/float/tst_float.cpp" line="0"> + <DataTag><![CDATA[should FAIL: -inf != inf]]></DataTag> + <Description><![CDATA[Compared qfloat16s are not the same (fuzzy compare) + Actual (operandLeft) : -inf + Expected (operandRight): inf]]></Description> +</Incident> +<Incident type="fail" file="qtbase/tests/auto/testlib/selftests/float/tst_float.cpp" line="0"> + <DataTag><![CDATA[should FAIL: inf != nan]]></DataTag> + <Description><![CDATA[Compared qfloat16s are not the same (fuzzy compare) + Actual (operandLeft) : inf + Expected (operandRight): nan]]></Description> +</Incident> +<Incident type="fail" file="qtbase/tests/auto/testlib/selftests/float/tst_float.cpp" line="0"> + <DataTag><![CDATA[should FAIL: nan != inf]]></DataTag> + <Description><![CDATA[Compared qfloat16s are not the same (fuzzy compare) + Actual (operandLeft) : nan + Expected (operandRight): inf]]></Description> +</Incident> +<Incident type="fail" file="qtbase/tests/auto/testlib/selftests/float/tst_float.cpp" line="0"> + <DataTag><![CDATA[should FAIL: -inf != nan]]></DataTag> + <Description><![CDATA[Compared qfloat16s are not the same (fuzzy compare) + Actual (operandLeft) : -inf + Expected (operandRight): nan]]></Description> +</Incident> +<Incident type="fail" file="qtbase/tests/auto/testlib/selftests/float/tst_float.cpp" line="0"> + <DataTag><![CDATA[should FAIL: nan != -inf]]></DataTag> + <Description><![CDATA[Compared qfloat16s are not the same (fuzzy compare) + Actual (operandLeft) : nan + Expected (operandRight): -inf]]></Description> +</Incident> +<Incident type="fail" file="qtbase/tests/auto/testlib/selftests/float/tst_float.cpp" line="0"> + <DataTag><![CDATA[should FAIL: inf != 0]]></DataTag> + <Description><![CDATA[Compared qfloat16s are not the same (fuzzy compare) + Actual (operandLeft) : inf + Expected (operandRight): 0]]></Description> +</Incident> +<Incident type="fail" file="qtbase/tests/auto/testlib/selftests/float/tst_float.cpp" line="0"> + <DataTag><![CDATA[should FAIL: 0 != inf]]></DataTag> + <Description><![CDATA[Compared qfloat16s are not the same (fuzzy compare) + Actual (operandLeft) : 0 + Expected (operandRight): inf]]></Description> +</Incident> +<Incident type="fail" file="qtbase/tests/auto/testlib/selftests/float/tst_float.cpp" line="0"> + <DataTag><![CDATA[should FAIL: -inf != 0]]></DataTag> + <Description><![CDATA[Compared qfloat16s are not the same (fuzzy compare) + Actual (operandLeft) : -inf + Expected (operandRight): 0]]></Description> +</Incident> +<Incident type="fail" file="qtbase/tests/auto/testlib/selftests/float/tst_float.cpp" line="0"> + <DataTag><![CDATA[should FAIL: 0 != -inf]]></DataTag> + <Description><![CDATA[Compared qfloat16s are not the same (fuzzy compare) + Actual (operandLeft) : 0 + Expected (operandRight): -inf]]></Description> +</Incident> +<Incident type="fail" file="qtbase/tests/auto/testlib/selftests/float/tst_float.cpp" line="0"> + <DataTag><![CDATA[should FAIL: inf != 1]]></DataTag> + <Description><![CDATA[Compared qfloat16s are not the same (fuzzy compare) + Actual (operandLeft) : inf + Expected (operandRight): 1]]></Description> +</Incident> +<Incident type="fail" file="qtbase/tests/auto/testlib/selftests/float/tst_float.cpp" line="0"> + <DataTag><![CDATA[should FAIL: 1 != inf]]></DataTag> + <Description><![CDATA[Compared qfloat16s are not the same (fuzzy compare) + Actual (operandLeft) : 1 + Expected (operandRight): inf]]></Description> +</Incident> +<Incident type="fail" file="qtbase/tests/auto/testlib/selftests/float/tst_float.cpp" line="0"> + <DataTag><![CDATA[should FAIL: -inf != 1]]></DataTag> + <Description><![CDATA[Compared qfloat16s are not the same (fuzzy compare) + Actual (operandLeft) : -inf + Expected (operandRight): 1]]></Description> +</Incident> +<Incident type="fail" file="qtbase/tests/auto/testlib/selftests/float/tst_float.cpp" line="0"> + <DataTag><![CDATA[should FAIL: 1 != -inf]]></DataTag> + <Description><![CDATA[Compared qfloat16s are not the same (fuzzy compare) + Actual (operandLeft) : 1 + Expected (operandRight): -inf]]></Description> +</Incident> +<Incident type="fail" file="qtbase/tests/auto/testlib/selftests/float/tst_float.cpp" line="0"> + <DataTag><![CDATA[should FAIL: inf != max]]></DataTag> + <Description><![CDATA[Compared qfloat16s are not the same (fuzzy compare) + Actual (operandLeft) : inf + Expected (operandRight): 6.55e+04]]></Description> +</Incident> +<Incident type="fail" file="qtbase/tests/auto/testlib/selftests/float/tst_float.cpp" line="0"> + <DataTag><![CDATA[should FAIL: inf != -max]]></DataTag> + <Description><![CDATA[Compared qfloat16s are not the same (fuzzy compare) + Actual (operandLeft) : inf + Expected (operandRight): -6.55e+04]]></Description> +</Incident> +<Incident type="fail" file="qtbase/tests/auto/testlib/selftests/float/tst_float.cpp" line="0"> + <DataTag><![CDATA[should FAIL: max != inf]]></DataTag> + <Description><![CDATA[Compared qfloat16s are not the same (fuzzy compare) + Actual (operandLeft) : 6.55e+04 + Expected (operandRight): inf]]></Description> +</Incident> +<Incident type="fail" file="qtbase/tests/auto/testlib/selftests/float/tst_float.cpp" line="0"> + <DataTag><![CDATA[should FAIL: -max != inf]]></DataTag> + <Description><![CDATA[Compared qfloat16s are not the same (fuzzy compare) + Actual (operandLeft) : -6.55e+04 + Expected (operandRight): inf]]></Description> +</Incident> +<Incident type="fail" file="qtbase/tests/auto/testlib/selftests/float/tst_float.cpp" line="0"> + <DataTag><![CDATA[should FAIL: -inf != max]]></DataTag> + <Description><![CDATA[Compared qfloat16s are not the same (fuzzy compare) + Actual (operandLeft) : -inf + Expected (operandRight): 6.55e+04]]></Description> +</Incident> +<Incident type="fail" file="qtbase/tests/auto/testlib/selftests/float/tst_float.cpp" line="0"> + <DataTag><![CDATA[should FAIL: -inf != -max]]></DataTag> + <Description><![CDATA[Compared qfloat16s are not the same (fuzzy compare) + Actual (operandLeft) : -inf + Expected (operandRight): -6.55e+04]]></Description> +</Incident> +<Incident type="fail" file="qtbase/tests/auto/testlib/selftests/float/tst_float.cpp" line="0"> + <DataTag><![CDATA[should FAIL: max != -inf]]></DataTag> + <Description><![CDATA[Compared qfloat16s are not the same (fuzzy compare) + Actual (operandLeft) : 6.55e+04 + Expected (operandRight): -inf]]></Description> +</Incident> +<Incident type="fail" file="qtbase/tests/auto/testlib/selftests/float/tst_float.cpp" line="0"> + <DataTag><![CDATA[should FAIL: -max != -inf]]></DataTag> + <Description><![CDATA[Compared qfloat16s are not the same (fuzzy compare) + Actual (operandLeft) : -6.55e+04 + Expected (operandRight): -inf]]></Description> </Incident> <Duration msecs="0"/> </TestFunction> diff --git a/tests/auto/testlib/selftests/expected_float.tap b/tests/auto/testlib/selftests/expected_float.tap index 4a3b3906c2..9da51b93b3 100644 --- a/tests/auto/testlib/selftests/expected_float.tap +++ b/tests/auto/testlib/selftests/expected_float.tap @@ -759,8 +759,7 @@ not ok 77 - floatComparisons(should FAIL: -max != -inf) file: qtbase/tests/auto/testlib/selftests/float/tst_float.cpp line: 137 ... -ok 78 - float16Comparisons(should SUCCEED 1) -not ok 79 - float16Comparisons(should FAIL 1) +not ok 78 - float16Comparisons(should FAIL 1) --- type: QCOMPARE message: Compared qfloat16s are not the same (fuzzy compare) @@ -772,6 +771,7 @@ not ok 79 - float16Comparisons(should FAIL 1) file: qtbase/tests/auto/testlib/selftests/float/tst_float.cpp line: 171 ... +ok 79 - float16Comparisons(should PASS 1) not ok 80 - float16Comparisons(should FAIL 2) --- type: QCOMPARE @@ -784,7 +784,8 @@ not ok 80 - float16Comparisons(should FAIL 2) file: qtbase/tests/auto/testlib/selftests/float/tst_float.cpp line: 171 ... -not ok 81 - float16Comparisons(should FAIL 3) +ok 81 - float16Comparisons(should PASS 2) +not ok 82 - float16Comparisons(should FAIL 3) --- type: QCOMPARE message: Compared qfloat16s are not the same (fuzzy compare) @@ -796,8 +797,348 @@ not ok 81 - float16Comparisons(should FAIL 3) file: qtbase/tests/auto/testlib/selftests/float/tst_float.cpp line: 171 ... -ok 82 - float16Comparisons(should SUCCEED 2) -not ok 83 - compareFloatTests(1e0) +ok 83 - float16Comparisons(should PASS 3) +not ok 84 - float16Comparisons(should FAIL 4) + --- + type: QCOMPARE + message: Compared qfloat16s are not the same (fuzzy compare) + wanted: 5.87e-05 (operandRight) + found: 5.93e-05 (operandLeft) + expected: 5.87e-05 (operandRight) + actual: 5.93e-05 (operandLeft) + at: tst_float::float16Comparisons() (qtbase/tests/auto/testlib/selftests/float/tst_float.cpp:171) + file: qtbase/tests/auto/testlib/selftests/float/tst_float.cpp + line: 171 + ... +ok 85 - float16Comparisons(should PASS 4) +not ok 86 - float16Comparisons(should FAIL 5) + --- + type: QCOMPARE + message: Compared qfloat16s are not the same (fuzzy compare) + wanted: 5.88e+04 (operandRight) + found: 5.94e+04 (operandLeft) + expected: 5.88e+04 (operandRight) + actual: 5.94e+04 (operandLeft) + at: tst_float::float16Comparisons() (qtbase/tests/auto/testlib/selftests/float/tst_float.cpp:171) + file: qtbase/tests/auto/testlib/selftests/float/tst_float.cpp + line: 171 + ... +ok 87 - float16Comparisons(should PASS: NaN == NaN) +not ok 88 - float16Comparisons(should FAIL: NaN != 0) + --- + type: QCOMPARE + message: Compared qfloat16s are not the same (fuzzy compare) + wanted: 0 (operandRight) + found: nan (operandLeft) + expected: 0 (operandRight) + actual: nan (operandLeft) + at: tst_float::float16Comparisons() (qtbase/tests/auto/testlib/selftests/float/tst_float.cpp:171) + file: qtbase/tests/auto/testlib/selftests/float/tst_float.cpp + line: 171 + ... +not ok 89 - float16Comparisons(should FAIL: 0 != NaN) + --- + type: QCOMPARE + message: Compared qfloat16s are not the same (fuzzy compare) + wanted: nan (operandRight) + found: 0 (operandLeft) + expected: nan (operandRight) + actual: 0 (operandLeft) + at: tst_float::float16Comparisons() (qtbase/tests/auto/testlib/selftests/float/tst_float.cpp:171) + file: qtbase/tests/auto/testlib/selftests/float/tst_float.cpp + line: 171 + ... +not ok 90 - float16Comparisons(should FAIL: NaN != 1) + --- + type: QCOMPARE + message: Compared qfloat16s are not the same (fuzzy compare) + wanted: 1 (operandRight) + found: nan (operandLeft) + expected: 1 (operandRight) + actual: nan (operandLeft) + at: tst_float::float16Comparisons() (qtbase/tests/auto/testlib/selftests/float/tst_float.cpp:171) + file: qtbase/tests/auto/testlib/selftests/float/tst_float.cpp + line: 171 + ... +not ok 91 - float16Comparisons(should FAIL: 1 != NaN) + --- + type: QCOMPARE + message: Compared qfloat16s are not the same (fuzzy compare) + wanted: nan (operandRight) + found: 1 (operandLeft) + expected: nan (operandRight) + actual: 1 (operandLeft) + at: tst_float::float16Comparisons() (qtbase/tests/auto/testlib/selftests/float/tst_float.cpp:171) + file: qtbase/tests/auto/testlib/selftests/float/tst_float.cpp + line: 171 + ... +ok 92 - float16Comparisons(should PASS: inf == inf) +ok 93 - float16Comparisons(should PASS: -inf == -inf) +not ok 94 - float16Comparisons(should FAIL: inf != -inf) + --- + type: QCOMPARE + message: Compared qfloat16s are not the same (fuzzy compare) + wanted: -inf (operandRight) + found: inf (operandLeft) + expected: -inf (operandRight) + actual: inf (operandLeft) + at: tst_float::float16Comparisons() (qtbase/tests/auto/testlib/selftests/float/tst_float.cpp:171) + file: qtbase/tests/auto/testlib/selftests/float/tst_float.cpp + line: 171 + ... +not ok 95 - float16Comparisons(should FAIL: -inf != inf) + --- + type: QCOMPARE + message: Compared qfloat16s are not the same (fuzzy compare) + wanted: inf (operandRight) + found: -inf (operandLeft) + expected: inf (operandRight) + actual: -inf (operandLeft) + at: tst_float::float16Comparisons() (qtbase/tests/auto/testlib/selftests/float/tst_float.cpp:171) + file: qtbase/tests/auto/testlib/selftests/float/tst_float.cpp + line: 171 + ... +not ok 96 - float16Comparisons(should FAIL: inf != nan) + --- + type: QCOMPARE + message: Compared qfloat16s are not the same (fuzzy compare) + wanted: nan (operandRight) + found: inf (operandLeft) + expected: nan (operandRight) + actual: inf (operandLeft) + at: tst_float::float16Comparisons() (qtbase/tests/auto/testlib/selftests/float/tst_float.cpp:171) + file: qtbase/tests/auto/testlib/selftests/float/tst_float.cpp + line: 171 + ... +not ok 97 - float16Comparisons(should FAIL: nan != inf) + --- + type: QCOMPARE + message: Compared qfloat16s are not the same (fuzzy compare) + wanted: inf (operandRight) + found: nan (operandLeft) + expected: inf (operandRight) + actual: nan (operandLeft) + at: tst_float::float16Comparisons() (qtbase/tests/auto/testlib/selftests/float/tst_float.cpp:171) + file: qtbase/tests/auto/testlib/selftests/float/tst_float.cpp + line: 171 + ... +not ok 98 - float16Comparisons(should FAIL: -inf != nan) + --- + type: QCOMPARE + message: Compared qfloat16s are not the same (fuzzy compare) + wanted: nan (operandRight) + found: -inf (operandLeft) + expected: nan (operandRight) + actual: -inf (operandLeft) + at: tst_float::float16Comparisons() (qtbase/tests/auto/testlib/selftests/float/tst_float.cpp:171) + file: qtbase/tests/auto/testlib/selftests/float/tst_float.cpp + line: 171 + ... +not ok 99 - float16Comparisons(should FAIL: nan != -inf) + --- + type: QCOMPARE + message: Compared qfloat16s are not the same (fuzzy compare) + wanted: -inf (operandRight) + found: nan (operandLeft) + expected: -inf (operandRight) + actual: nan (operandLeft) + at: tst_float::float16Comparisons() (qtbase/tests/auto/testlib/selftests/float/tst_float.cpp:171) + file: qtbase/tests/auto/testlib/selftests/float/tst_float.cpp + line: 171 + ... +not ok 100 - float16Comparisons(should FAIL: inf != 0) + --- + type: QCOMPARE + message: Compared qfloat16s are not the same (fuzzy compare) + wanted: 0 (operandRight) + found: inf (operandLeft) + expected: 0 (operandRight) + actual: inf (operandLeft) + at: tst_float::float16Comparisons() (qtbase/tests/auto/testlib/selftests/float/tst_float.cpp:171) + file: qtbase/tests/auto/testlib/selftests/float/tst_float.cpp + line: 171 + ... +not ok 101 - float16Comparisons(should FAIL: 0 != inf) + --- + type: QCOMPARE + message: Compared qfloat16s are not the same (fuzzy compare) + wanted: inf (operandRight) + found: 0 (operandLeft) + expected: inf (operandRight) + actual: 0 (operandLeft) + at: tst_float::float16Comparisons() (qtbase/tests/auto/testlib/selftests/float/tst_float.cpp:171) + file: qtbase/tests/auto/testlib/selftests/float/tst_float.cpp + line: 171 + ... +not ok 102 - float16Comparisons(should FAIL: -inf != 0) + --- + type: QCOMPARE + message: Compared qfloat16s are not the same (fuzzy compare) + wanted: 0 (operandRight) + found: -inf (operandLeft) + expected: 0 (operandRight) + actual: -inf (operandLeft) + at: tst_float::float16Comparisons() (qtbase/tests/auto/testlib/selftests/float/tst_float.cpp:171) + file: qtbase/tests/auto/testlib/selftests/float/tst_float.cpp + line: 171 + ... +not ok 103 - float16Comparisons(should FAIL: 0 != -inf) + --- + type: QCOMPARE + message: Compared qfloat16s are not the same (fuzzy compare) + wanted: -inf (operandRight) + found: 0 (operandLeft) + expected: -inf (operandRight) + actual: 0 (operandLeft) + at: tst_float::float16Comparisons() (qtbase/tests/auto/testlib/selftests/float/tst_float.cpp:171) + file: qtbase/tests/auto/testlib/selftests/float/tst_float.cpp + line: 171 + ... +not ok 104 - float16Comparisons(should FAIL: inf != 1) + --- + type: QCOMPARE + message: Compared qfloat16s are not the same (fuzzy compare) + wanted: 1 (operandRight) + found: inf (operandLeft) + expected: 1 (operandRight) + actual: inf (operandLeft) + at: tst_float::float16Comparisons() (qtbase/tests/auto/testlib/selftests/float/tst_float.cpp:171) + file: qtbase/tests/auto/testlib/selftests/float/tst_float.cpp + line: 171 + ... +not ok 105 - float16Comparisons(should FAIL: 1 != inf) + --- + type: QCOMPARE + message: Compared qfloat16s are not the same (fuzzy compare) + wanted: inf (operandRight) + found: 1 (operandLeft) + expected: inf (operandRight) + actual: 1 (operandLeft) + at: tst_float::float16Comparisons() (qtbase/tests/auto/testlib/selftests/float/tst_float.cpp:171) + file: qtbase/tests/auto/testlib/selftests/float/tst_float.cpp + line: 171 + ... +not ok 106 - float16Comparisons(should FAIL: -inf != 1) + --- + type: QCOMPARE + message: Compared qfloat16s are not the same (fuzzy compare) + wanted: 1 (operandRight) + found: -inf (operandLeft) + expected: 1 (operandRight) + actual: -inf (operandLeft) + at: tst_float::float16Comparisons() (qtbase/tests/auto/testlib/selftests/float/tst_float.cpp:171) + file: qtbase/tests/auto/testlib/selftests/float/tst_float.cpp + line: 171 + ... +not ok 107 - float16Comparisons(should FAIL: 1 != -inf) + --- + type: QCOMPARE + message: Compared qfloat16s are not the same (fuzzy compare) + wanted: -inf (operandRight) + found: 1 (operandLeft) + expected: -inf (operandRight) + actual: 1 (operandLeft) + at: tst_float::float16Comparisons() (qtbase/tests/auto/testlib/selftests/float/tst_float.cpp:171) + file: qtbase/tests/auto/testlib/selftests/float/tst_float.cpp + line: 171 + ... +not ok 108 - float16Comparisons(should FAIL: inf != max) + --- + type: QCOMPARE + message: Compared qfloat16s are not the same (fuzzy compare) + wanted: 6.55e+04 (operandRight) + found: inf (operandLeft) + expected: 6.55e+04 (operandRight) + actual: inf (operandLeft) + at: tst_float::float16Comparisons() (qtbase/tests/auto/testlib/selftests/float/tst_float.cpp:171) + file: qtbase/tests/auto/testlib/selftests/float/tst_float.cpp + line: 171 + ... +not ok 109 - float16Comparisons(should FAIL: inf != -max) + --- + type: QCOMPARE + message: Compared qfloat16s are not the same (fuzzy compare) + wanted: -6.55e+04 (operandRight) + found: inf (operandLeft) + expected: -6.55e+04 (operandRight) + actual: inf (operandLeft) + at: tst_float::float16Comparisons() (qtbase/tests/auto/testlib/selftests/float/tst_float.cpp:171) + file: qtbase/tests/auto/testlib/selftests/float/tst_float.cpp + line: 171 + ... +not ok 110 - float16Comparisons(should FAIL: max != inf) + --- + type: QCOMPARE + message: Compared qfloat16s are not the same (fuzzy compare) + wanted: inf (operandRight) + found: 6.55e+04 (operandLeft) + expected: inf (operandRight) + actual: 6.55e+04 (operandLeft) + at: tst_float::float16Comparisons() (qtbase/tests/auto/testlib/selftests/float/tst_float.cpp:171) + file: qtbase/tests/auto/testlib/selftests/float/tst_float.cpp + line: 171 + ... +not ok 111 - float16Comparisons(should FAIL: -max != inf) + --- + type: QCOMPARE + message: Compared qfloat16s are not the same (fuzzy compare) + wanted: inf (operandRight) + found: -6.55e+04 (operandLeft) + expected: inf (operandRight) + actual: -6.55e+04 (operandLeft) + at: tst_float::float16Comparisons() (qtbase/tests/auto/testlib/selftests/float/tst_float.cpp:171) + file: qtbase/tests/auto/testlib/selftests/float/tst_float.cpp + line: 171 + ... +not ok 112 - float16Comparisons(should FAIL: -inf != max) + --- + type: QCOMPARE + message: Compared qfloat16s are not the same (fuzzy compare) + wanted: 6.55e+04 (operandRight) + found: -inf (operandLeft) + expected: 6.55e+04 (operandRight) + actual: -inf (operandLeft) + at: tst_float::float16Comparisons() (qtbase/tests/auto/testlib/selftests/float/tst_float.cpp:171) + file: qtbase/tests/auto/testlib/selftests/float/tst_float.cpp + line: 171 + ... +not ok 113 - float16Comparisons(should FAIL: -inf != -max) + --- + type: QCOMPARE + message: Compared qfloat16s are not the same (fuzzy compare) + wanted: -6.55e+04 (operandRight) + found: -inf (operandLeft) + expected: -6.55e+04 (operandRight) + actual: -inf (operandLeft) + at: tst_float::float16Comparisons() (qtbase/tests/auto/testlib/selftests/float/tst_float.cpp:171) + file: qtbase/tests/auto/testlib/selftests/float/tst_float.cpp + line: 171 + ... +not ok 114 - float16Comparisons(should FAIL: max != -inf) + --- + type: QCOMPARE + message: Compared qfloat16s are not the same (fuzzy compare) + wanted: -inf (operandRight) + found: 6.55e+04 (operandLeft) + expected: -inf (operandRight) + actual: 6.55e+04 (operandLeft) + at: tst_float::float16Comparisons() (qtbase/tests/auto/testlib/selftests/float/tst_float.cpp:171) + file: qtbase/tests/auto/testlib/selftests/float/tst_float.cpp + line: 171 + ... +not ok 115 - float16Comparisons(should FAIL: -max != -inf) + --- + type: QCOMPARE + message: Compared qfloat16s are not the same (fuzzy compare) + wanted: -inf (operandRight) + found: -6.55e+04 (operandLeft) + expected: -inf (operandRight) + actual: -6.55e+04 (operandLeft) + at: tst_float::float16Comparisons() (qtbase/tests/auto/testlib/selftests/float/tst_float.cpp:171) + file: qtbase/tests/auto/testlib/selftests/float/tst_float.cpp + line: 171 + ... +not ok 116 - compareFloatTests(1e0) --- type: QCOMPARE message: Compared floats are not the same (fuzzy compare) @@ -805,11 +1146,11 @@ not ok 83 - compareFloatTests(1e0) found: 1 (t1) expected: 3 (t3) actual: 1 (t1) - at: tst_float::compareFloatTests() (qtbase/tests/auto/testlib/selftests/float/tst_float.cpp:216) + at: tst_float::compareFloatTests() (qtbase/tests/auto/testlib/selftests/float/tst_float.cpp:210) file: qtbase/tests/auto/testlib/selftests/float/tst_float.cpp - line: 216 + line: 210 ... -not ok 84 - compareFloatTests(1e-7) +not ok 117 - compareFloatTests(1e-7) --- type: QCOMPARE message: Compared floats are not the same (fuzzy compare) @@ -817,11 +1158,11 @@ not ok 84 - compareFloatTests(1e-7) found: 1e-07 (t1) expected: 3e-07 (t3) actual: 1e-07 (t1) - at: tst_float::compareFloatTests() (qtbase/tests/auto/testlib/selftests/float/tst_float.cpp:216) + at: tst_float::compareFloatTests() (qtbase/tests/auto/testlib/selftests/float/tst_float.cpp:210) file: qtbase/tests/auto/testlib/selftests/float/tst_float.cpp - line: 216 + line: 210 ... -not ok 85 - compareFloatTests(1e+7) +not ok 118 - compareFloatTests(1e+7) --- type: QCOMPARE message: Compared floats are not the same (fuzzy compare) @@ -829,12 +1170,12 @@ not ok 85 - compareFloatTests(1e+7) found: 1e+07 (t1) expected: 3e+07 (t3) actual: 1e+07 (t1) - at: tst_float::compareFloatTests() (qtbase/tests/auto/testlib/selftests/float/tst_float.cpp:216) + at: tst_float::compareFloatTests() (qtbase/tests/auto/testlib/selftests/float/tst_float.cpp:210) file: qtbase/tests/auto/testlib/selftests/float/tst_float.cpp - line: 216 + line: 210 ... -ok 86 - cleanupTestCase() -1..86 -# tests 86 -# pass 18 -# fail 68 +ok 119 - cleanupTestCase() +1..119 +# tests 119 +# pass 23 +# fail 96 diff --git a/tests/auto/testlib/selftests/expected_float.teamcity b/tests/auto/testlib/selftests/expected_float.teamcity index eb99d3f6ea..af81296c42 100644 --- a/tests/auto/testlib/selftests/expected_float.teamcity +++ b/tests/auto/testlib/selftests/expected_float.teamcity @@ -215,19 +215,113 @@ ##teamcity[testStarted name='floatComparisons(should FAIL: -max != -inf)' flowId='tst_float'] ##teamcity[testFailed name='floatComparisons(should FAIL: -max != -inf)' message='Failure! |[Loc: qtbase/tests/auto/testlib/selftests/float/tst_float.cpp(0)|]' details='Compared floats are not the same (fuzzy compare)|n Actual (operandLeft) : -3.40282e+38|n Expected (operandRight): -inf' flowId='tst_float'] ##teamcity[testFinished name='floatComparisons(should FAIL: -max != -inf)' flowId='tst_float'] -##teamcity[testStarted name='float16Comparisons(should SUCCEED 1)' flowId='tst_float'] -##teamcity[testFinished name='float16Comparisons(should SUCCEED 1)' flowId='tst_float'] ##teamcity[testStarted name='float16Comparisons(should FAIL 1)' flowId='tst_float'] ##teamcity[testFailed name='float16Comparisons(should FAIL 1)' message='Failure! |[Loc: qtbase/tests/auto/testlib/selftests/float/tst_float.cpp(0)|]' details='Compared qfloat16s are not the same (fuzzy compare)|n Actual (operandLeft) : 1|n Expected (operandRight): 3' flowId='tst_float'] ##teamcity[testFinished name='float16Comparisons(should FAIL 1)' flowId='tst_float'] +##teamcity[testStarted name='float16Comparisons(should PASS 1)' flowId='tst_float'] +##teamcity[testFinished name='float16Comparisons(should PASS 1)' flowId='tst_float'] ##teamcity[testStarted name='float16Comparisons(should FAIL 2)' flowId='tst_float'] ##teamcity[testFailed name='float16Comparisons(should FAIL 2)' message='Failure! |[Loc: qtbase/tests/auto/testlib/selftests/float/tst_float.cpp(0)|]' details='Compared qfloat16s are not the same (fuzzy compare)|n Actual (operandLeft) : 0.0001|n Expected (operandRight): 0.0003' flowId='tst_float'] ##teamcity[testFinished name='float16Comparisons(should FAIL 2)' flowId='tst_float'] +##teamcity[testStarted name='float16Comparisons(should PASS 2)' flowId='tst_float'] +##teamcity[testFinished name='float16Comparisons(should PASS 2)' flowId='tst_float'] ##teamcity[testStarted name='float16Comparisons(should FAIL 3)' flowId='tst_float'] ##teamcity[testFailed name='float16Comparisons(should FAIL 3)' message='Failure! |[Loc: qtbase/tests/auto/testlib/selftests/float/tst_float.cpp(0)|]' details='Compared qfloat16s are not the same (fuzzy compare)|n Actual (operandLeft) : 98|n Expected (operandRight): 99' flowId='tst_float'] ##teamcity[testFinished name='float16Comparisons(should FAIL 3)' flowId='tst_float'] -##teamcity[testStarted name='float16Comparisons(should SUCCEED 2)' flowId='tst_float'] -##teamcity[testFinished name='float16Comparisons(should SUCCEED 2)' flowId='tst_float'] +##teamcity[testStarted name='float16Comparisons(should PASS 3)' flowId='tst_float'] +##teamcity[testFinished name='float16Comparisons(should PASS 3)' flowId='tst_float'] +##teamcity[testStarted name='float16Comparisons(should FAIL 4)' flowId='tst_float'] +##teamcity[testFailed name='float16Comparisons(should FAIL 4)' message='Failure! |[Loc: qtbase/tests/auto/testlib/selftests/float/tst_float.cpp(0)|]' details='Compared qfloat16s are not the same (fuzzy compare)|n Actual (operandLeft) : 5.93e-05|n Expected (operandRight): 5.87e-05' flowId='tst_float'] +##teamcity[testFinished name='float16Comparisons(should FAIL 4)' flowId='tst_float'] +##teamcity[testStarted name='float16Comparisons(should PASS 4)' flowId='tst_float'] +##teamcity[testFinished name='float16Comparisons(should PASS 4)' flowId='tst_float'] +##teamcity[testStarted name='float16Comparisons(should FAIL 5)' flowId='tst_float'] +##teamcity[testFailed name='float16Comparisons(should FAIL 5)' message='Failure! |[Loc: qtbase/tests/auto/testlib/selftests/float/tst_float.cpp(0)|]' details='Compared qfloat16s are not the same (fuzzy compare)|n Actual (operandLeft) : 5.94e+04|n Expected (operandRight): 5.88e+04' flowId='tst_float'] +##teamcity[testFinished name='float16Comparisons(should FAIL 5)' flowId='tst_float'] +##teamcity[testStarted name='float16Comparisons(should PASS: NaN == NaN)' flowId='tst_float'] +##teamcity[testFinished name='float16Comparisons(should PASS: NaN == NaN)' flowId='tst_float'] +##teamcity[testStarted name='float16Comparisons(should FAIL: NaN != 0)' flowId='tst_float'] +##teamcity[testFailed name='float16Comparisons(should FAIL: NaN != 0)' message='Failure! |[Loc: qtbase/tests/auto/testlib/selftests/float/tst_float.cpp(0)|]' details='Compared qfloat16s are not the same (fuzzy compare)|n Actual (operandLeft) : nan|n Expected (operandRight): 0' flowId='tst_float'] +##teamcity[testFinished name='float16Comparisons(should FAIL: NaN != 0)' flowId='tst_float'] +##teamcity[testStarted name='float16Comparisons(should FAIL: 0 != NaN)' flowId='tst_float'] +##teamcity[testFailed name='float16Comparisons(should FAIL: 0 != NaN)' message='Failure! |[Loc: qtbase/tests/auto/testlib/selftests/float/tst_float.cpp(0)|]' details='Compared qfloat16s are not the same (fuzzy compare)|n Actual (operandLeft) : 0|n Expected (operandRight): nan' flowId='tst_float'] +##teamcity[testFinished name='float16Comparisons(should FAIL: 0 != NaN)' flowId='tst_float'] +##teamcity[testStarted name='float16Comparisons(should FAIL: NaN != 1)' flowId='tst_float'] +##teamcity[testFailed name='float16Comparisons(should FAIL: NaN != 1)' message='Failure! |[Loc: qtbase/tests/auto/testlib/selftests/float/tst_float.cpp(0)|]' details='Compared qfloat16s are not the same (fuzzy compare)|n Actual (operandLeft) : nan|n Expected (operandRight): 1' flowId='tst_float'] +##teamcity[testFinished name='float16Comparisons(should FAIL: NaN != 1)' flowId='tst_float'] +##teamcity[testStarted name='float16Comparisons(should FAIL: 1 != NaN)' flowId='tst_float'] +##teamcity[testFailed name='float16Comparisons(should FAIL: 1 != NaN)' message='Failure! |[Loc: qtbase/tests/auto/testlib/selftests/float/tst_float.cpp(0)|]' details='Compared qfloat16s are not the same (fuzzy compare)|n Actual (operandLeft) : 1|n Expected (operandRight): nan' flowId='tst_float'] +##teamcity[testFinished name='float16Comparisons(should FAIL: 1 != NaN)' flowId='tst_float'] +##teamcity[testStarted name='float16Comparisons(should PASS: inf == inf)' flowId='tst_float'] +##teamcity[testFinished name='float16Comparisons(should PASS: inf == inf)' flowId='tst_float'] +##teamcity[testStarted name='float16Comparisons(should PASS: -inf == -inf)' flowId='tst_float'] +##teamcity[testFinished name='float16Comparisons(should PASS: -inf == -inf)' flowId='tst_float'] +##teamcity[testStarted name='float16Comparisons(should FAIL: inf != -inf)' flowId='tst_float'] +##teamcity[testFailed name='float16Comparisons(should FAIL: inf != -inf)' message='Failure! |[Loc: qtbase/tests/auto/testlib/selftests/float/tst_float.cpp(0)|]' details='Compared qfloat16s are not the same (fuzzy compare)|n Actual (operandLeft) : inf|n Expected (operandRight): -inf' flowId='tst_float'] +##teamcity[testFinished name='float16Comparisons(should FAIL: inf != -inf)' flowId='tst_float'] +##teamcity[testStarted name='float16Comparisons(should FAIL: -inf != inf)' flowId='tst_float'] +##teamcity[testFailed name='float16Comparisons(should FAIL: -inf != inf)' message='Failure! |[Loc: qtbase/tests/auto/testlib/selftests/float/tst_float.cpp(0)|]' details='Compared qfloat16s are not the same (fuzzy compare)|n Actual (operandLeft) : -inf|n Expected (operandRight): inf' flowId='tst_float'] +##teamcity[testFinished name='float16Comparisons(should FAIL: -inf != inf)' flowId='tst_float'] +##teamcity[testStarted name='float16Comparisons(should FAIL: inf != nan)' flowId='tst_float'] +##teamcity[testFailed name='float16Comparisons(should FAIL: inf != nan)' message='Failure! |[Loc: qtbase/tests/auto/testlib/selftests/float/tst_float.cpp(0)|]' details='Compared qfloat16s are not the same (fuzzy compare)|n Actual (operandLeft) : inf|n Expected (operandRight): nan' flowId='tst_float'] +##teamcity[testFinished name='float16Comparisons(should FAIL: inf != nan)' flowId='tst_float'] +##teamcity[testStarted name='float16Comparisons(should FAIL: nan != inf)' flowId='tst_float'] +##teamcity[testFailed name='float16Comparisons(should FAIL: nan != inf)' message='Failure! |[Loc: qtbase/tests/auto/testlib/selftests/float/tst_float.cpp(0)|]' details='Compared qfloat16s are not the same (fuzzy compare)|n Actual (operandLeft) : nan|n Expected (operandRight): inf' flowId='tst_float'] +##teamcity[testFinished name='float16Comparisons(should FAIL: nan != inf)' flowId='tst_float'] +##teamcity[testStarted name='float16Comparisons(should FAIL: -inf != nan)' flowId='tst_float'] +##teamcity[testFailed name='float16Comparisons(should FAIL: -inf != nan)' message='Failure! |[Loc: qtbase/tests/auto/testlib/selftests/float/tst_float.cpp(0)|]' details='Compared qfloat16s are not the same (fuzzy compare)|n Actual (operandLeft) : -inf|n Expected (operandRight): nan' flowId='tst_float'] +##teamcity[testFinished name='float16Comparisons(should FAIL: -inf != nan)' flowId='tst_float'] +##teamcity[testStarted name='float16Comparisons(should FAIL: nan != -inf)' flowId='tst_float'] +##teamcity[testFailed name='float16Comparisons(should FAIL: nan != -inf)' message='Failure! |[Loc: qtbase/tests/auto/testlib/selftests/float/tst_float.cpp(0)|]' details='Compared qfloat16s are not the same (fuzzy compare)|n Actual (operandLeft) : nan|n Expected (operandRight): -inf' flowId='tst_float'] +##teamcity[testFinished name='float16Comparisons(should FAIL: nan != -inf)' flowId='tst_float'] +##teamcity[testStarted name='float16Comparisons(should FAIL: inf != 0)' flowId='tst_float'] +##teamcity[testFailed name='float16Comparisons(should FAIL: inf != 0)' message='Failure! |[Loc: qtbase/tests/auto/testlib/selftests/float/tst_float.cpp(0)|]' details='Compared qfloat16s are not the same (fuzzy compare)|n Actual (operandLeft) : inf|n Expected (operandRight): 0' flowId='tst_float'] +##teamcity[testFinished name='float16Comparisons(should FAIL: inf != 0)' flowId='tst_float'] +##teamcity[testStarted name='float16Comparisons(should FAIL: 0 != inf)' flowId='tst_float'] +##teamcity[testFailed name='float16Comparisons(should FAIL: 0 != inf)' message='Failure! |[Loc: qtbase/tests/auto/testlib/selftests/float/tst_float.cpp(0)|]' details='Compared qfloat16s are not the same (fuzzy compare)|n Actual (operandLeft) : 0|n Expected (operandRight): inf' flowId='tst_float'] +##teamcity[testFinished name='float16Comparisons(should FAIL: 0 != inf)' flowId='tst_float'] +##teamcity[testStarted name='float16Comparisons(should FAIL: -inf != 0)' flowId='tst_float'] +##teamcity[testFailed name='float16Comparisons(should FAIL: -inf != 0)' message='Failure! |[Loc: qtbase/tests/auto/testlib/selftests/float/tst_float.cpp(0)|]' details='Compared qfloat16s are not the same (fuzzy compare)|n Actual (operandLeft) : -inf|n Expected (operandRight): 0' flowId='tst_float'] +##teamcity[testFinished name='float16Comparisons(should FAIL: -inf != 0)' flowId='tst_float'] +##teamcity[testStarted name='float16Comparisons(should FAIL: 0 != -inf)' flowId='tst_float'] +##teamcity[testFailed name='float16Comparisons(should FAIL: 0 != -inf)' message='Failure! |[Loc: qtbase/tests/auto/testlib/selftests/float/tst_float.cpp(0)|]' details='Compared qfloat16s are not the same (fuzzy compare)|n Actual (operandLeft) : 0|n Expected (operandRight): -inf' flowId='tst_float'] +##teamcity[testFinished name='float16Comparisons(should FAIL: 0 != -inf)' flowId='tst_float'] +##teamcity[testStarted name='float16Comparisons(should FAIL: inf != 1)' flowId='tst_float'] +##teamcity[testFailed name='float16Comparisons(should FAIL: inf != 1)' message='Failure! |[Loc: qtbase/tests/auto/testlib/selftests/float/tst_float.cpp(0)|]' details='Compared qfloat16s are not the same (fuzzy compare)|n Actual (operandLeft) : inf|n Expected (operandRight): 1' flowId='tst_float'] +##teamcity[testFinished name='float16Comparisons(should FAIL: inf != 1)' flowId='tst_float'] +##teamcity[testStarted name='float16Comparisons(should FAIL: 1 != inf)' flowId='tst_float'] +##teamcity[testFailed name='float16Comparisons(should FAIL: 1 != inf)' message='Failure! |[Loc: qtbase/tests/auto/testlib/selftests/float/tst_float.cpp(0)|]' details='Compared qfloat16s are not the same (fuzzy compare)|n Actual (operandLeft) : 1|n Expected (operandRight): inf' flowId='tst_float'] +##teamcity[testFinished name='float16Comparisons(should FAIL: 1 != inf)' flowId='tst_float'] +##teamcity[testStarted name='float16Comparisons(should FAIL: -inf != 1)' flowId='tst_float'] +##teamcity[testFailed name='float16Comparisons(should FAIL: -inf != 1)' message='Failure! |[Loc: qtbase/tests/auto/testlib/selftests/float/tst_float.cpp(0)|]' details='Compared qfloat16s are not the same (fuzzy compare)|n Actual (operandLeft) : -inf|n Expected (operandRight): 1' flowId='tst_float'] +##teamcity[testFinished name='float16Comparisons(should FAIL: -inf != 1)' flowId='tst_float'] +##teamcity[testStarted name='float16Comparisons(should FAIL: 1 != -inf)' flowId='tst_float'] +##teamcity[testFailed name='float16Comparisons(should FAIL: 1 != -inf)' message='Failure! |[Loc: qtbase/tests/auto/testlib/selftests/float/tst_float.cpp(0)|]' details='Compared qfloat16s are not the same (fuzzy compare)|n Actual (operandLeft) : 1|n Expected (operandRight): -inf' flowId='tst_float'] +##teamcity[testFinished name='float16Comparisons(should FAIL: 1 != -inf)' flowId='tst_float'] +##teamcity[testStarted name='float16Comparisons(should FAIL: inf != max)' flowId='tst_float'] +##teamcity[testFailed name='float16Comparisons(should FAIL: inf != max)' message='Failure! |[Loc: qtbase/tests/auto/testlib/selftests/float/tst_float.cpp(0)|]' details='Compared qfloat16s are not the same (fuzzy compare)|n Actual (operandLeft) : inf|n Expected (operandRight): 6.55e+04' flowId='tst_float'] +##teamcity[testFinished name='float16Comparisons(should FAIL: inf != max)' flowId='tst_float'] +##teamcity[testStarted name='float16Comparisons(should FAIL: inf != -max)' flowId='tst_float'] +##teamcity[testFailed name='float16Comparisons(should FAIL: inf != -max)' message='Failure! |[Loc: qtbase/tests/auto/testlib/selftests/float/tst_float.cpp(0)|]' details='Compared qfloat16s are not the same (fuzzy compare)|n Actual (operandLeft) : inf|n Expected (operandRight): -6.55e+04' flowId='tst_float'] +##teamcity[testFinished name='float16Comparisons(should FAIL: inf != -max)' flowId='tst_float'] +##teamcity[testStarted name='float16Comparisons(should FAIL: max != inf)' flowId='tst_float'] +##teamcity[testFailed name='float16Comparisons(should FAIL: max != inf)' message='Failure! |[Loc: qtbase/tests/auto/testlib/selftests/float/tst_float.cpp(0)|]' details='Compared qfloat16s are not the same (fuzzy compare)|n Actual (operandLeft) : 6.55e+04|n Expected (operandRight): inf' flowId='tst_float'] +##teamcity[testFinished name='float16Comparisons(should FAIL: max != inf)' flowId='tst_float'] +##teamcity[testStarted name='float16Comparisons(should FAIL: -max != inf)' flowId='tst_float'] +##teamcity[testFailed name='float16Comparisons(should FAIL: -max != inf)' message='Failure! |[Loc: qtbase/tests/auto/testlib/selftests/float/tst_float.cpp(0)|]' details='Compared qfloat16s are not the same (fuzzy compare)|n Actual (operandLeft) : -6.55e+04|n Expected (operandRight): inf' flowId='tst_float'] +##teamcity[testFinished name='float16Comparisons(should FAIL: -max != inf)' flowId='tst_float'] +##teamcity[testStarted name='float16Comparisons(should FAIL: -inf != max)' flowId='tst_float'] +##teamcity[testFailed name='float16Comparisons(should FAIL: -inf != max)' message='Failure! |[Loc: qtbase/tests/auto/testlib/selftests/float/tst_float.cpp(0)|]' details='Compared qfloat16s are not the same (fuzzy compare)|n Actual (operandLeft) : -inf|n Expected (operandRight): 6.55e+04' flowId='tst_float'] +##teamcity[testFinished name='float16Comparisons(should FAIL: -inf != max)' flowId='tst_float'] +##teamcity[testStarted name='float16Comparisons(should FAIL: -inf != -max)' flowId='tst_float'] +##teamcity[testFailed name='float16Comparisons(should FAIL: -inf != -max)' message='Failure! |[Loc: qtbase/tests/auto/testlib/selftests/float/tst_float.cpp(0)|]' details='Compared qfloat16s are not the same (fuzzy compare)|n Actual (operandLeft) : -inf|n Expected (operandRight): -6.55e+04' flowId='tst_float'] +##teamcity[testFinished name='float16Comparisons(should FAIL: -inf != -max)' flowId='tst_float'] +##teamcity[testStarted name='float16Comparisons(should FAIL: max != -inf)' flowId='tst_float'] +##teamcity[testFailed name='float16Comparisons(should FAIL: max != -inf)' message='Failure! |[Loc: qtbase/tests/auto/testlib/selftests/float/tst_float.cpp(0)|]' details='Compared qfloat16s are not the same (fuzzy compare)|n Actual (operandLeft) : 6.55e+04|n Expected (operandRight): -inf' flowId='tst_float'] +##teamcity[testFinished name='float16Comparisons(should FAIL: max != -inf)' flowId='tst_float'] +##teamcity[testStarted name='float16Comparisons(should FAIL: -max != -inf)' flowId='tst_float'] +##teamcity[testFailed name='float16Comparisons(should FAIL: -max != -inf)' message='Failure! |[Loc: qtbase/tests/auto/testlib/selftests/float/tst_float.cpp(0)|]' details='Compared qfloat16s are not the same (fuzzy compare)|n Actual (operandLeft) : -6.55e+04|n Expected (operandRight): -inf' flowId='tst_float'] +##teamcity[testFinished name='float16Comparisons(should FAIL: -max != -inf)' flowId='tst_float'] ##teamcity[testStarted name='compareFloatTests(1e0)' flowId='tst_float'] ##teamcity[testFailed name='compareFloatTests(1e0)' message='Failure! |[Loc: qtbase/tests/auto/testlib/selftests/float/tst_float.cpp(0)|]' details='Compared floats are not the same (fuzzy compare)|n Actual (t1): 1|n Expected (t3): 3' flowId='tst_float'] ##teamcity[testFinished name='compareFloatTests(1e0)' flowId='tst_float'] diff --git a/tests/auto/testlib/selftests/expected_float.txt b/tests/auto/testlib/selftests/expected_float.txt index 18a5bab628..d22a52a63d 100644 --- a/tests/auto/testlib/selftests/expected_float.txt +++ b/tests/auto/testlib/selftests/expected_float.txt @@ -263,20 +263,137 @@ FAIL! : tst_float::floatComparisons(should FAIL: -max != -inf) Compared floats Actual (operandLeft) : -3.40282e+38 Expected (operandRight): -inf Loc: [qtbase/tests/auto/testlib/selftests/float/tst_float.cpp(0)] -PASS : tst_float::float16Comparisons(should SUCCEED 1) FAIL! : tst_float::float16Comparisons(should FAIL 1) Compared qfloat16s are not the same (fuzzy compare) Actual (operandLeft) : 1 Expected (operandRight): 3 Loc: [qtbase/tests/auto/testlib/selftests/float/tst_float.cpp(0)] +PASS : tst_float::float16Comparisons(should PASS 1) FAIL! : tst_float::float16Comparisons(should FAIL 2) Compared qfloat16s are not the same (fuzzy compare) Actual (operandLeft) : 0.0001 Expected (operandRight): 0.0003 Loc: [qtbase/tests/auto/testlib/selftests/float/tst_float.cpp(0)] +PASS : tst_float::float16Comparisons(should PASS 2) FAIL! : tst_float::float16Comparisons(should FAIL 3) Compared qfloat16s are not the same (fuzzy compare) Actual (operandLeft) : 98 Expected (operandRight): 99 Loc: [qtbase/tests/auto/testlib/selftests/float/tst_float.cpp(0)] -PASS : tst_float::float16Comparisons(should SUCCEED 2) +PASS : tst_float::float16Comparisons(should PASS 3) +FAIL! : tst_float::float16Comparisons(should FAIL 4) Compared qfloat16s are not the same (fuzzy compare) + Actual (operandLeft) : 5.93e-05 + Expected (operandRight): 5.87e-05 + Loc: [qtbase/tests/auto/testlib/selftests/float/tst_float.cpp(0)] +PASS : tst_float::float16Comparisons(should PASS 4) +FAIL! : tst_float::float16Comparisons(should FAIL 5) Compared qfloat16s are not the same (fuzzy compare) + Actual (operandLeft) : 5.94e+04 + Expected (operandRight): 5.88e+04 + Loc: [qtbase/tests/auto/testlib/selftests/float/tst_float.cpp(0)] +PASS : tst_float::float16Comparisons(should PASS: NaN == NaN) +FAIL! : tst_float::float16Comparisons(should FAIL: NaN != 0) Compared qfloat16s are not the same (fuzzy compare) + Actual (operandLeft) : nan + Expected (operandRight): 0 + Loc: [qtbase/tests/auto/testlib/selftests/float/tst_float.cpp(0)] +FAIL! : tst_float::float16Comparisons(should FAIL: 0 != NaN) Compared qfloat16s are not the same (fuzzy compare) + Actual (operandLeft) : 0 + Expected (operandRight): nan + Loc: [qtbase/tests/auto/testlib/selftests/float/tst_float.cpp(0)] +FAIL! : tst_float::float16Comparisons(should FAIL: NaN != 1) Compared qfloat16s are not the same (fuzzy compare) + Actual (operandLeft) : nan + Expected (operandRight): 1 + Loc: [qtbase/tests/auto/testlib/selftests/float/tst_float.cpp(0)] +FAIL! : tst_float::float16Comparisons(should FAIL: 1 != NaN) Compared qfloat16s are not the same (fuzzy compare) + Actual (operandLeft) : 1 + Expected (operandRight): nan + Loc: [qtbase/tests/auto/testlib/selftests/float/tst_float.cpp(0)] +PASS : tst_float::float16Comparisons(should PASS: inf == inf) +PASS : tst_float::float16Comparisons(should PASS: -inf == -inf) +FAIL! : tst_float::float16Comparisons(should FAIL: inf != -inf) Compared qfloat16s are not the same (fuzzy compare) + Actual (operandLeft) : inf + Expected (operandRight): -inf + Loc: [qtbase/tests/auto/testlib/selftests/float/tst_float.cpp(0)] +FAIL! : tst_float::float16Comparisons(should FAIL: -inf != inf) Compared qfloat16s are not the same (fuzzy compare) + Actual (operandLeft) : -inf + Expected (operandRight): inf + Loc: [qtbase/tests/auto/testlib/selftests/float/tst_float.cpp(0)] +FAIL! : tst_float::float16Comparisons(should FAIL: inf != nan) Compared qfloat16s are not the same (fuzzy compare) + Actual (operandLeft) : inf + Expected (operandRight): nan + Loc: [qtbase/tests/auto/testlib/selftests/float/tst_float.cpp(0)] +FAIL! : tst_float::float16Comparisons(should FAIL: nan != inf) Compared qfloat16s are not the same (fuzzy compare) + Actual (operandLeft) : nan + Expected (operandRight): inf + Loc: [qtbase/tests/auto/testlib/selftests/float/tst_float.cpp(0)] +FAIL! : tst_float::float16Comparisons(should FAIL: -inf != nan) Compared qfloat16s are not the same (fuzzy compare) + Actual (operandLeft) : -inf + Expected (operandRight): nan + Loc: [qtbase/tests/auto/testlib/selftests/float/tst_float.cpp(0)] +FAIL! : tst_float::float16Comparisons(should FAIL: nan != -inf) Compared qfloat16s are not the same (fuzzy compare) + Actual (operandLeft) : nan + Expected (operandRight): -inf + Loc: [qtbase/tests/auto/testlib/selftests/float/tst_float.cpp(0)] +FAIL! : tst_float::float16Comparisons(should FAIL: inf != 0) Compared qfloat16s are not the same (fuzzy compare) + Actual (operandLeft) : inf + Expected (operandRight): 0 + Loc: [qtbase/tests/auto/testlib/selftests/float/tst_float.cpp(0)] +FAIL! : tst_float::float16Comparisons(should FAIL: 0 != inf) Compared qfloat16s are not the same (fuzzy compare) + Actual (operandLeft) : 0 + Expected (operandRight): inf + Loc: [qtbase/tests/auto/testlib/selftests/float/tst_float.cpp(0)] +FAIL! : tst_float::float16Comparisons(should FAIL: -inf != 0) Compared qfloat16s are not the same (fuzzy compare) + Actual (operandLeft) : -inf + Expected (operandRight): 0 + Loc: [qtbase/tests/auto/testlib/selftests/float/tst_float.cpp(0)] +FAIL! : tst_float::float16Comparisons(should FAIL: 0 != -inf) Compared qfloat16s are not the same (fuzzy compare) + Actual (operandLeft) : 0 + Expected (operandRight): -inf + Loc: [qtbase/tests/auto/testlib/selftests/float/tst_float.cpp(0)] +FAIL! : tst_float::float16Comparisons(should FAIL: inf != 1) Compared qfloat16s are not the same (fuzzy compare) + Actual (operandLeft) : inf + Expected (operandRight): 1 + Loc: [qtbase/tests/auto/testlib/selftests/float/tst_float.cpp(0)] +FAIL! : tst_float::float16Comparisons(should FAIL: 1 != inf) Compared qfloat16s are not the same (fuzzy compare) + Actual (operandLeft) : 1 + Expected (operandRight): inf + Loc: [qtbase/tests/auto/testlib/selftests/float/tst_float.cpp(0)] +FAIL! : tst_float::float16Comparisons(should FAIL: -inf != 1) Compared qfloat16s are not the same (fuzzy compare) + Actual (operandLeft) : -inf + Expected (operandRight): 1 + Loc: [qtbase/tests/auto/testlib/selftests/float/tst_float.cpp(0)] +FAIL! : tst_float::float16Comparisons(should FAIL: 1 != -inf) Compared qfloat16s are not the same (fuzzy compare) + Actual (operandLeft) : 1 + Expected (operandRight): -inf + Loc: [qtbase/tests/auto/testlib/selftests/float/tst_float.cpp(0)] +FAIL! : tst_float::float16Comparisons(should FAIL: inf != max) Compared qfloat16s are not the same (fuzzy compare) + Actual (operandLeft) : inf + Expected (operandRight): 6.55e+04 + Loc: [qtbase/tests/auto/testlib/selftests/float/tst_float.cpp(0)] +FAIL! : tst_float::float16Comparisons(should FAIL: inf != -max) Compared qfloat16s are not the same (fuzzy compare) + Actual (operandLeft) : inf + Expected (operandRight): -6.55e+04 + Loc: [qtbase/tests/auto/testlib/selftests/float/tst_float.cpp(0)] +FAIL! : tst_float::float16Comparisons(should FAIL: max != inf) Compared qfloat16s are not the same (fuzzy compare) + Actual (operandLeft) : 6.55e+04 + Expected (operandRight): inf + Loc: [qtbase/tests/auto/testlib/selftests/float/tst_float.cpp(0)] +FAIL! : tst_float::float16Comparisons(should FAIL: -max != inf) Compared qfloat16s are not the same (fuzzy compare) + Actual (operandLeft) : -6.55e+04 + Expected (operandRight): inf + Loc: [qtbase/tests/auto/testlib/selftests/float/tst_float.cpp(0)] +FAIL! : tst_float::float16Comparisons(should FAIL: -inf != max) Compared qfloat16s are not the same (fuzzy compare) + Actual (operandLeft) : -inf + Expected (operandRight): 6.55e+04 + Loc: [qtbase/tests/auto/testlib/selftests/float/tst_float.cpp(0)] +FAIL! : tst_float::float16Comparisons(should FAIL: -inf != -max) Compared qfloat16s are not the same (fuzzy compare) + Actual (operandLeft) : -inf + Expected (operandRight): -6.55e+04 + Loc: [qtbase/tests/auto/testlib/selftests/float/tst_float.cpp(0)] +FAIL! : tst_float::float16Comparisons(should FAIL: max != -inf) Compared qfloat16s are not the same (fuzzy compare) + Actual (operandLeft) : 6.55e+04 + Expected (operandRight): -inf + Loc: [qtbase/tests/auto/testlib/selftests/float/tst_float.cpp(0)] +FAIL! : tst_float::float16Comparisons(should FAIL: -max != -inf) Compared qfloat16s are not the same (fuzzy compare) + Actual (operandLeft) : -6.55e+04 + Expected (operandRight): -inf + Loc: [qtbase/tests/auto/testlib/selftests/float/tst_float.cpp(0)] FAIL! : tst_float::compareFloatTests(1e0) Compared floats are not the same (fuzzy compare) Actual (t1): 1 Expected (t3): 3 @@ -290,5 +407,5 @@ FAIL! : tst_float::compareFloatTests(1e+7) Compared floats are not the same (fu Expected (t3): 3e+07 Loc: [qtbase/tests/auto/testlib/selftests/float/tst_float.cpp(0)] PASS : tst_float::cleanupTestCase() -Totals: 18 passed, 68 failed, 0 skipped, 0 blacklisted, 0ms +Totals: 23 passed, 96 failed, 0 skipped, 0 blacklisted, 0ms ********* Finished testing of tst_float ********* diff --git a/tests/auto/testlib/selftests/expected_float.xml b/tests/auto/testlib/selftests/expected_float.xml index b8e1a23616..247bce9577 100644 --- a/tests/auto/testlib/selftests/expected_float.xml +++ b/tests/auto/testlib/selftests/expected_float.xml @@ -430,21 +430,24 @@ <Duration msecs="0"/> </TestFunction> <TestFunction name="float16Comparisons"> -<Incident type="pass" file="" line="0"> - <DataTag><![CDATA[should SUCCEED 1]]></DataTag> -</Incident> <Incident type="fail" file="qtbase/tests/auto/testlib/selftests/float/tst_float.cpp" line="0"> <DataTag><![CDATA[should FAIL 1]]></DataTag> <Description><![CDATA[Compared qfloat16s are not the same (fuzzy compare) Actual (operandLeft) : 1 Expected (operandRight): 3]]></Description> </Incident> +<Incident type="pass" file="" line="0"> + <DataTag><![CDATA[should PASS 1]]></DataTag> +</Incident> <Incident type="fail" file="qtbase/tests/auto/testlib/selftests/float/tst_float.cpp" line="0"> <DataTag><![CDATA[should FAIL 2]]></DataTag> <Description><![CDATA[Compared qfloat16s are not the same (fuzzy compare) Actual (operandLeft) : 0.0001 Expected (operandRight): 0.0003]]></Description> </Incident> +<Incident type="pass" file="" line="0"> + <DataTag><![CDATA[should PASS 2]]></DataTag> +</Incident> <Incident type="fail" file="qtbase/tests/auto/testlib/selftests/float/tst_float.cpp" line="0"> <DataTag><![CDATA[should FAIL 3]]></DataTag> <Description><![CDATA[Compared qfloat16s are not the same (fuzzy compare) @@ -452,7 +455,187 @@ Expected (operandRight): 99]]></Description> </Incident> <Incident type="pass" file="" line="0"> - <DataTag><![CDATA[should SUCCEED 2]]></DataTag> + <DataTag><![CDATA[should PASS 3]]></DataTag> +</Incident> +<Incident type="fail" file="qtbase/tests/auto/testlib/selftests/float/tst_float.cpp" line="0"> + <DataTag><![CDATA[should FAIL 4]]></DataTag> + <Description><![CDATA[Compared qfloat16s are not the same (fuzzy compare) + Actual (operandLeft) : 5.93e-05 + Expected (operandRight): 5.87e-05]]></Description> +</Incident> +<Incident type="pass" file="" line="0"> + <DataTag><![CDATA[should PASS 4]]></DataTag> +</Incident> +<Incident type="fail" file="qtbase/tests/auto/testlib/selftests/float/tst_float.cpp" line="0"> + <DataTag><![CDATA[should FAIL 5]]></DataTag> + <Description><![CDATA[Compared qfloat16s are not the same (fuzzy compare) + Actual (operandLeft) : 5.94e+04 + Expected (operandRight): 5.88e+04]]></Description> +</Incident> +<Incident type="pass" file="" line="0"> + <DataTag><![CDATA[should PASS: NaN == NaN]]></DataTag> +</Incident> +<Incident type="fail" file="qtbase/tests/auto/testlib/selftests/float/tst_float.cpp" line="0"> + <DataTag><![CDATA[should FAIL: NaN != 0]]></DataTag> + <Description><![CDATA[Compared qfloat16s are not the same (fuzzy compare) + Actual (operandLeft) : nan + Expected (operandRight): 0]]></Description> +</Incident> +<Incident type="fail" file="qtbase/tests/auto/testlib/selftests/float/tst_float.cpp" line="0"> + <DataTag><![CDATA[should FAIL: 0 != NaN]]></DataTag> + <Description><![CDATA[Compared qfloat16s are not the same (fuzzy compare) + Actual (operandLeft) : 0 + Expected (operandRight): nan]]></Description> +</Incident> +<Incident type="fail" file="qtbase/tests/auto/testlib/selftests/float/tst_float.cpp" line="0"> + <DataTag><![CDATA[should FAIL: NaN != 1]]></DataTag> + <Description><![CDATA[Compared qfloat16s are not the same (fuzzy compare) + Actual (operandLeft) : nan + Expected (operandRight): 1]]></Description> +</Incident> +<Incident type="fail" file="qtbase/tests/auto/testlib/selftests/float/tst_float.cpp" line="0"> + <DataTag><![CDATA[should FAIL: 1 != NaN]]></DataTag> + <Description><![CDATA[Compared qfloat16s are not the same (fuzzy compare) + Actual (operandLeft) : 1 + Expected (operandRight): nan]]></Description> +</Incident> +<Incident type="pass" file="" line="0"> + <DataTag><![CDATA[should PASS: inf == inf]]></DataTag> +</Incident> +<Incident type="pass" file="" line="0"> + <DataTag><![CDATA[should PASS: -inf == -inf]]></DataTag> +</Incident> +<Incident type="fail" file="qtbase/tests/auto/testlib/selftests/float/tst_float.cpp" line="0"> + <DataTag><![CDATA[should FAIL: inf != -inf]]></DataTag> + <Description><![CDATA[Compared qfloat16s are not the same (fuzzy compare) + Actual (operandLeft) : inf + Expected (operandRight): -inf]]></Description> +</Incident> +<Incident type="fail" file="qtbase/tests/auto/testlib/selftests/float/tst_float.cpp" line="0"> + <DataTag><![CDATA[should FAIL: -inf != inf]]></DataTag> + <Description><![CDATA[Compared qfloat16s are not the same (fuzzy compare) + Actual (operandLeft) : -inf + Expected (operandRight): inf]]></Description> +</Incident> +<Incident type="fail" file="qtbase/tests/auto/testlib/selftests/float/tst_float.cpp" line="0"> + <DataTag><![CDATA[should FAIL: inf != nan]]></DataTag> + <Description><![CDATA[Compared qfloat16s are not the same (fuzzy compare) + Actual (operandLeft) : inf + Expected (operandRight): nan]]></Description> +</Incident> +<Incident type="fail" file="qtbase/tests/auto/testlib/selftests/float/tst_float.cpp" line="0"> + <DataTag><![CDATA[should FAIL: nan != inf]]></DataTag> + <Description><![CDATA[Compared qfloat16s are not the same (fuzzy compare) + Actual (operandLeft) : nan + Expected (operandRight): inf]]></Description> +</Incident> +<Incident type="fail" file="qtbase/tests/auto/testlib/selftests/float/tst_float.cpp" line="0"> + <DataTag><![CDATA[should FAIL: -inf != nan]]></DataTag> + <Description><![CDATA[Compared qfloat16s are not the same (fuzzy compare) + Actual (operandLeft) : -inf + Expected (operandRight): nan]]></Description> +</Incident> +<Incident type="fail" file="qtbase/tests/auto/testlib/selftests/float/tst_float.cpp" line="0"> + <DataTag><![CDATA[should FAIL: nan != -inf]]></DataTag> + <Description><![CDATA[Compared qfloat16s are not the same (fuzzy compare) + Actual (operandLeft) : nan + Expected (operandRight): -inf]]></Description> +</Incident> +<Incident type="fail" file="qtbase/tests/auto/testlib/selftests/float/tst_float.cpp" line="0"> + <DataTag><![CDATA[should FAIL: inf != 0]]></DataTag> + <Description><![CDATA[Compared qfloat16s are not the same (fuzzy compare) + Actual (operandLeft) : inf + Expected (operandRight): 0]]></Description> +</Incident> +<Incident type="fail" file="qtbase/tests/auto/testlib/selftests/float/tst_float.cpp" line="0"> + <DataTag><![CDATA[should FAIL: 0 != inf]]></DataTag> + <Description><![CDATA[Compared qfloat16s are not the same (fuzzy compare) + Actual (operandLeft) : 0 + Expected (operandRight): inf]]></Description> +</Incident> +<Incident type="fail" file="qtbase/tests/auto/testlib/selftests/float/tst_float.cpp" line="0"> + <DataTag><![CDATA[should FAIL: -inf != 0]]></DataTag> + <Description><![CDATA[Compared qfloat16s are not the same (fuzzy compare) + Actual (operandLeft) : -inf + Expected (operandRight): 0]]></Description> +</Incident> +<Incident type="fail" file="qtbase/tests/auto/testlib/selftests/float/tst_float.cpp" line="0"> + <DataTag><![CDATA[should FAIL: 0 != -inf]]></DataTag> + <Description><![CDATA[Compared qfloat16s are not the same (fuzzy compare) + Actual (operandLeft) : 0 + Expected (operandRight): -inf]]></Description> +</Incident> +<Incident type="fail" file="qtbase/tests/auto/testlib/selftests/float/tst_float.cpp" line="0"> + <DataTag><![CDATA[should FAIL: inf != 1]]></DataTag> + <Description><![CDATA[Compared qfloat16s are not the same (fuzzy compare) + Actual (operandLeft) : inf + Expected (operandRight): 1]]></Description> +</Incident> +<Incident type="fail" file="qtbase/tests/auto/testlib/selftests/float/tst_float.cpp" line="0"> + <DataTag><![CDATA[should FAIL: 1 != inf]]></DataTag> + <Description><![CDATA[Compared qfloat16s are not the same (fuzzy compare) + Actual (operandLeft) : 1 + Expected (operandRight): inf]]></Description> +</Incident> +<Incident type="fail" file="qtbase/tests/auto/testlib/selftests/float/tst_float.cpp" line="0"> + <DataTag><![CDATA[should FAIL: -inf != 1]]></DataTag> + <Description><![CDATA[Compared qfloat16s are not the same (fuzzy compare) + Actual (operandLeft) : -inf + Expected (operandRight): 1]]></Description> +</Incident> +<Incident type="fail" file="qtbase/tests/auto/testlib/selftests/float/tst_float.cpp" line="0"> + <DataTag><![CDATA[should FAIL: 1 != -inf]]></DataTag> + <Description><![CDATA[Compared qfloat16s are not the same (fuzzy compare) + Actual (operandLeft) : 1 + Expected (operandRight): -inf]]></Description> +</Incident> +<Incident type="fail" file="qtbase/tests/auto/testlib/selftests/float/tst_float.cpp" line="0"> + <DataTag><![CDATA[should FAIL: inf != max]]></DataTag> + <Description><![CDATA[Compared qfloat16s are not the same (fuzzy compare) + Actual (operandLeft) : inf + Expected (operandRight): 6.55e+04]]></Description> +</Incident> +<Incident type="fail" file="qtbase/tests/auto/testlib/selftests/float/tst_float.cpp" line="0"> + <DataTag><![CDATA[should FAIL: inf != -max]]></DataTag> + <Description><![CDATA[Compared qfloat16s are not the same (fuzzy compare) + Actual (operandLeft) : inf + Expected (operandRight): -6.55e+04]]></Description> +</Incident> +<Incident type="fail" file="qtbase/tests/auto/testlib/selftests/float/tst_float.cpp" line="0"> + <DataTag><![CDATA[should FAIL: max != inf]]></DataTag> + <Description><![CDATA[Compared qfloat16s are not the same (fuzzy compare) + Actual (operandLeft) : 6.55e+04 + Expected (operandRight): inf]]></Description> +</Incident> +<Incident type="fail" file="qtbase/tests/auto/testlib/selftests/float/tst_float.cpp" line="0"> + <DataTag><![CDATA[should FAIL: -max != inf]]></DataTag> + <Description><![CDATA[Compared qfloat16s are not the same (fuzzy compare) + Actual (operandLeft) : -6.55e+04 + Expected (operandRight): inf]]></Description> +</Incident> +<Incident type="fail" file="qtbase/tests/auto/testlib/selftests/float/tst_float.cpp" line="0"> + <DataTag><![CDATA[should FAIL: -inf != max]]></DataTag> + <Description><![CDATA[Compared qfloat16s are not the same (fuzzy compare) + Actual (operandLeft) : -inf + Expected (operandRight): 6.55e+04]]></Description> +</Incident> +<Incident type="fail" file="qtbase/tests/auto/testlib/selftests/float/tst_float.cpp" line="0"> + <DataTag><![CDATA[should FAIL: -inf != -max]]></DataTag> + <Description><![CDATA[Compared qfloat16s are not the same (fuzzy compare) + Actual (operandLeft) : -inf + Expected (operandRight): -6.55e+04]]></Description> +</Incident> +<Incident type="fail" file="qtbase/tests/auto/testlib/selftests/float/tst_float.cpp" line="0"> + <DataTag><![CDATA[should FAIL: max != -inf]]></DataTag> + <Description><![CDATA[Compared qfloat16s are not the same (fuzzy compare) + Actual (operandLeft) : 6.55e+04 + Expected (operandRight): -inf]]></Description> +</Incident> +<Incident type="fail" file="qtbase/tests/auto/testlib/selftests/float/tst_float.cpp" line="0"> + <DataTag><![CDATA[should FAIL: -max != -inf]]></DataTag> + <Description><![CDATA[Compared qfloat16s are not the same (fuzzy compare) + Actual (operandLeft) : -6.55e+04 + Expected (operandRight): -inf]]></Description> </Incident> <Duration msecs="0"/> </TestFunction> diff --git a/tests/auto/testlib/selftests/expected_float.xunitxml b/tests/auto/testlib/selftests/expected_float.xunitxml index 9b2af9b616..602f9252a4 100644 --- a/tests/auto/testlib/selftests/expected_float.xunitxml +++ b/tests/auto/testlib/selftests/expected_float.xunitxml @@ -1,5 +1,5 @@ <?xml version="1.0" encoding="UTF-8" ?> -<testsuite errors="0" failures="68" tests="6" name="tst_float"> +<testsuite errors="0" failures="96" tests="6" name="tst_float"> <properties> <property value="@INSERT_QT_VERSION_HERE@" name="QTestVersion"/> <property value="@INSERT_QT_VERSION_HERE@" name="QtVersion"/> @@ -206,6 +206,90 @@ <failure tag="should FAIL 3" message="Compared qfloat16s are not the same (fuzzy compare) Actual (operandLeft) : 98 Expected (operandRight): 99" result="fail"/> + <failure tag="should FAIL 4" message="Compared qfloat16s are not the same (fuzzy compare) + Actual (operandLeft) : 5.93e-05 + Expected (operandRight): 5.87e-05" result="fail"/> + <failure tag="should FAIL 5" message="Compared qfloat16s are not the same (fuzzy compare) + Actual (operandLeft) : 5.94e+04 + Expected (operandRight): 5.88e+04" result="fail"/> + <failure tag="should FAIL: NaN != 0" message="Compared qfloat16s are not the same (fuzzy compare) + Actual (operandLeft) : nan + Expected (operandRight): 0" result="fail"/> + <failure tag="should FAIL: 0 != NaN" message="Compared qfloat16s are not the same (fuzzy compare) + Actual (operandLeft) : 0 + Expected (operandRight): nan" result="fail"/> + <failure tag="should FAIL: NaN != 1" message="Compared qfloat16s are not the same (fuzzy compare) + Actual (operandLeft) : nan + Expected (operandRight): 1" result="fail"/> + <failure tag="should FAIL: 1 != NaN" message="Compared qfloat16s are not the same (fuzzy compare) + Actual (operandLeft) : 1 + Expected (operandRight): nan" result="fail"/> + <failure tag="should FAIL: inf != -inf" message="Compared qfloat16s are not the same (fuzzy compare) + Actual (operandLeft) : inf + Expected (operandRight): -inf" result="fail"/> + <failure tag="should FAIL: -inf != inf" message="Compared qfloat16s are not the same (fuzzy compare) + Actual (operandLeft) : -inf + Expected (operandRight): inf" result="fail"/> + <failure tag="should FAIL: inf != nan" message="Compared qfloat16s are not the same (fuzzy compare) + Actual (operandLeft) : inf + Expected (operandRight): nan" result="fail"/> + <failure tag="should FAIL: nan != inf" message="Compared qfloat16s are not the same (fuzzy compare) + Actual (operandLeft) : nan + Expected (operandRight): inf" result="fail"/> + <failure tag="should FAIL: -inf != nan" message="Compared qfloat16s are not the same (fuzzy compare) + Actual (operandLeft) : -inf + Expected (operandRight): nan" result="fail"/> + <failure tag="should FAIL: nan != -inf" message="Compared qfloat16s are not the same (fuzzy compare) + Actual (operandLeft) : nan + Expected (operandRight): -inf" result="fail"/> + <failure tag="should FAIL: inf != 0" message="Compared qfloat16s are not the same (fuzzy compare) + Actual (operandLeft) : inf + Expected (operandRight): 0" result="fail"/> + <failure tag="should FAIL: 0 != inf" message="Compared qfloat16s are not the same (fuzzy compare) + Actual (operandLeft) : 0 + Expected (operandRight): inf" result="fail"/> + <failure tag="should FAIL: -inf != 0" message="Compared qfloat16s are not the same (fuzzy compare) + Actual (operandLeft) : -inf + Expected (operandRight): 0" result="fail"/> + <failure tag="should FAIL: 0 != -inf" message="Compared qfloat16s are not the same (fuzzy compare) + Actual (operandLeft) : 0 + Expected (operandRight): -inf" result="fail"/> + <failure tag="should FAIL: inf != 1" message="Compared qfloat16s are not the same (fuzzy compare) + Actual (operandLeft) : inf + Expected (operandRight): 1" result="fail"/> + <failure tag="should FAIL: 1 != inf" message="Compared qfloat16s are not the same (fuzzy compare) + Actual (operandLeft) : 1 + Expected (operandRight): inf" result="fail"/> + <failure tag="should FAIL: -inf != 1" message="Compared qfloat16s are not the same (fuzzy compare) + Actual (operandLeft) : -inf + Expected (operandRight): 1" result="fail"/> + <failure tag="should FAIL: 1 != -inf" message="Compared qfloat16s are not the same (fuzzy compare) + Actual (operandLeft) : 1 + Expected (operandRight): -inf" result="fail"/> + <failure tag="should FAIL: inf != max" message="Compared qfloat16s are not the same (fuzzy compare) + Actual (operandLeft) : inf + Expected (operandRight): 6.55e+04" result="fail"/> + <failure tag="should FAIL: inf != -max" message="Compared qfloat16s are not the same (fuzzy compare) + Actual (operandLeft) : inf + Expected (operandRight): -6.55e+04" result="fail"/> + <failure tag="should FAIL: max != inf" message="Compared qfloat16s are not the same (fuzzy compare) + Actual (operandLeft) : 6.55e+04 + Expected (operandRight): inf" result="fail"/> + <failure tag="should FAIL: -max != inf" message="Compared qfloat16s are not the same (fuzzy compare) + Actual (operandLeft) : -6.55e+04 + Expected (operandRight): inf" result="fail"/> + <failure tag="should FAIL: -inf != max" message="Compared qfloat16s are not the same (fuzzy compare) + Actual (operandLeft) : -inf + Expected (operandRight): 6.55e+04" result="fail"/> + <failure tag="should FAIL: -inf != -max" message="Compared qfloat16s are not the same (fuzzy compare) + Actual (operandLeft) : -inf + Expected (operandRight): -6.55e+04" result="fail"/> + <failure tag="should FAIL: max != -inf" message="Compared qfloat16s are not the same (fuzzy compare) + Actual (operandLeft) : 6.55e+04 + Expected (operandRight): -inf" result="fail"/> + <failure tag="should FAIL: -max != -inf" message="Compared qfloat16s are not the same (fuzzy compare) + Actual (operandLeft) : -6.55e+04 + Expected (operandRight): -inf" result="fail"/> </testcase> <testcase result="fail" name="compareFloatTests"> <failure tag="1e0" message="Compared floats are not the same (fuzzy compare) diff --git a/tests/auto/testlib/selftests/expected_sleep.lightxml b/tests/auto/testlib/selftests/expected_sleep.lightxml index 97b65d1259..78e1c44cf2 100644 --- a/tests/auto/testlib/selftests/expected_sleep.lightxml +++ b/tests/auto/testlib/selftests/expected_sleep.lightxml @@ -11,6 +11,10 @@ <Incident type="pass" file="" line="0" /> <Duration msecs="0"/> </TestFunction> +<TestFunction name="wait"> +<Incident type="pass" file="" line="0" /> + <Duration msecs="0"/> +</TestFunction> <TestFunction name="cleanupTestCase"> <Incident type="pass" file="" line="0" /> <Duration msecs="0"/> diff --git a/tests/auto/testlib/selftests/expected_sleep.tap b/tests/auto/testlib/selftests/expected_sleep.tap index 7caef214d2..65edefb9ba 100644 --- a/tests/auto/testlib/selftests/expected_sleep.tap +++ b/tests/auto/testlib/selftests/expected_sleep.tap @@ -2,8 +2,9 @@ TAP version 13 # tst_Sleep ok 1 - initTestCase() ok 2 - sleep() -ok 3 - cleanupTestCase() -1..3 -# tests 3 -# pass 3 +ok 3 - wait() +ok 4 - cleanupTestCase() +1..4 +# tests 4 +# pass 4 # fail 0 diff --git a/tests/auto/testlib/selftests/expected_sleep.teamcity b/tests/auto/testlib/selftests/expected_sleep.teamcity index 36b2445ccc..45a503bb54 100644 --- a/tests/auto/testlib/selftests/expected_sleep.teamcity +++ b/tests/auto/testlib/selftests/expected_sleep.teamcity @@ -3,6 +3,8 @@ ##teamcity[testFinished name='initTestCase()' flowId='tst_Sleep'] ##teamcity[testStarted name='sleep()' flowId='tst_Sleep'] ##teamcity[testFinished name='sleep()' flowId='tst_Sleep'] +##teamcity[testStarted name='wait()' flowId='tst_Sleep'] +##teamcity[testFinished name='wait()' flowId='tst_Sleep'] ##teamcity[testStarted name='cleanupTestCase()' flowId='tst_Sleep'] ##teamcity[testFinished name='cleanupTestCase()' flowId='tst_Sleep'] ##teamcity[testSuiteFinished name='tst_Sleep' flowId='tst_Sleep'] diff --git a/tests/auto/testlib/selftests/expected_sleep.txt b/tests/auto/testlib/selftests/expected_sleep.txt index d18c3212bb..d1701d2bed 100644 --- a/tests/auto/testlib/selftests/expected_sleep.txt +++ b/tests/auto/testlib/selftests/expected_sleep.txt @@ -2,6 +2,7 @@ Config: Using QtTest library PASS : tst_Sleep::initTestCase() PASS : tst_Sleep::sleep() +PASS : tst_Sleep::wait() PASS : tst_Sleep::cleanupTestCase() -Totals: 3 passed, 0 failed, 0 skipped, 0 blacklisted, 0ms +Totals: 4 passed, 0 failed, 0 skipped, 0 blacklisted, 0ms ********* Finished testing of tst_Sleep ********* diff --git a/tests/auto/testlib/selftests/expected_sleep.xml b/tests/auto/testlib/selftests/expected_sleep.xml index 5729c0ac9d..94bb25ba8d 100644 --- a/tests/auto/testlib/selftests/expected_sleep.xml +++ b/tests/auto/testlib/selftests/expected_sleep.xml @@ -13,6 +13,10 @@ <Incident type="pass" file="" line="0" /> <Duration msecs="0"/> </TestFunction> +<TestFunction name="wait"> +<Incident type="pass" file="" line="0" /> + <Duration msecs="0"/> +</TestFunction> <TestFunction name="cleanupTestCase"> <Incident type="pass" file="" line="0" /> <Duration msecs="0"/> diff --git a/tests/auto/testlib/selftests/expected_sleep.xunitxml b/tests/auto/testlib/selftests/expected_sleep.xunitxml index 138486fc02..e4ed66bcb8 100644 --- a/tests/auto/testlib/selftests/expected_sleep.xunitxml +++ b/tests/auto/testlib/selftests/expected_sleep.xunitxml @@ -1,5 +1,5 @@ <?xml version="1.0" encoding="UTF-8" ?> -<testsuite errors="0" failures="0" tests="3" name="tst_Sleep"> +<testsuite errors="0" failures="0" tests="4" name="tst_Sleep"> <properties> <property value="@INSERT_QT_VERSION_HERE@" name="QTestVersion"/> <property value="@INSERT_QT_VERSION_HERE@" name="QtVersion"/> @@ -7,6 +7,7 @@ </properties> <testcase result="pass" name="initTestCase"/> <testcase result="pass" name="sleep"/> + <testcase result="pass" name="wait"/> <testcase result="pass" name="cleanupTestCase"/> <system-err/> </testsuite> diff --git a/tests/auto/testlib/selftests/float/tst_float.cpp b/tests/auto/testlib/selftests/float/tst_float.cpp index 621dd1ccd9..cefd8a57c4 100644 --- a/tests/auto/testlib/selftests/float/tst_float.cpp +++ b/tests/auto/testlib/selftests/float/tst_float.cpp @@ -175,28 +175,22 @@ void tst_float::float16Comparisons_data() const { QTest::addColumn<qfloat16>("operandLeft"); QTest::addColumn<qfloat16>("operandRight"); + qfloat16 zero(0), one(1); - QTest::newRow("should SUCCEED 1") - << qfloat16(0) - << qfloat16(0); - - QTest::newRow("should FAIL 1") - << qfloat16(1.000) - << qfloat16(3.000); - - QTest::newRow("should FAIL 2") - << qfloat16(1.000e-4f) - << qfloat16(3.000e-4f); + QTest::newRow("should FAIL 1") << one << qfloat16(3); + QTest::newRow("should PASS 1") << zero << zero; + QTest::newRow("should FAIL 2") << qfloat16(1e-4f) << qfloat16(3e-4f); // QCOMPARE for qfloat16s uses qFuzzyCompare() + QTest::newRow("should PASS 2") << qfloat16(1001) << qfloat16(1002); + QTest::newRow("should FAIL 3") << qfloat16(98) << qfloat16(99); + // ... which gets a bit unreliable near to the type's bounds + QTest::newRow("should PASS 3") << qfloat16(6e-5f) + qfloat16(6e-7f) << qfloat16(6e-5f) + qfloat16(11e-7f); + QTest::newRow("should FAIL 4") << qfloat16(6e-5f) - qfloat16(7e-7f) << qfloat16(6e-5f) - qfloat16(13e-7f); + QTest::newRow("should PASS 4") << qfloat16(6e4) + qfloat16(700) << qfloat16(6e4) + qfloat16(1200); + QTest::newRow("should FAIL 5") << qfloat16(6e4) - qfloat16(600) << qfloat16(6e4) - qfloat16(1200); - QTest::newRow("should FAIL 3") - << qfloat16(98) - << qfloat16(99); - - QTest::newRow("should SUCCEED 2") - << qfloat16(1001) - << qfloat16(1002); + nonFinite_data(zero, one); } void tst_float::compareFloatTests() const diff --git a/tests/auto/testlib/selftests/sleep/tst_sleep.cpp b/tests/auto/testlib/selftests/sleep/tst_sleep.cpp index afe6e22120..b7b141afd0 100644 --- a/tests/auto/testlib/selftests/sleep/tst_sleep.cpp +++ b/tests/auto/testlib/selftests/sleep/tst_sleep.cpp @@ -36,6 +36,7 @@ class tst_Sleep: public QObject private slots: void sleep(); + void wait(); }; void tst_Sleep::sleep() @@ -53,6 +54,24 @@ void tst_Sleep::sleep() QVERIFY(t.elapsed() > 1000 * 10); } +void tst_Sleep::wait() +{ + QElapsedTimer t; + t.start(); + + QTest::qWait(1); + QVERIFY(t.elapsed() >= 1); + + QTest::qWait(10); + QVERIFY(t.elapsed() >= 11); + + QTest::qWait(100); + QVERIFY(t.elapsed() >= 111); + + QTest::qWait(1000); + QVERIFY(t.elapsed() >= 1111); +} + QTEST_MAIN(tst_Sleep) #include "tst_sleep.moc" diff --git a/tests/auto/testserver.pri b/tests/auto/testserver.pri deleted file mode 100644 index 455f88fa5d..0000000000 --- a/tests/auto/testserver.pri +++ /dev/null @@ -1,218 +0,0 @@ -# Integrating docker-based test servers into Qt Test framework -# -# This file adds support for docker-based test servers built by testcase -# projects that need them. To enable this feature, any automated test can -# include testserver.pri in its project file. This instructs qmake to insert -# additional targets into the generated Makefile. The 'check' target then brings -# up test servers before running the testcase, and shuts them down afterwards. -# -# TESTSERVER_COMPOSE_FILE -# - Contains the path of docker-compose file -# This configuration file defines the services used for autotests. It tells the -# docker engine how to build up the docker images and containers. In qtbase, a -# shared docker-compose file is located in the tests folder. -# Example: TESTSERVER_COMPOSE_FILE = \ -# $$dirname(_QMAKE_CONF_)/tests/testserver/docker-compose.yml -# -# The user must run the provisioning scripts in advance before attempting to -# build the test servers. The docker_testserver.sh script is used to build up -# the docker images into the docker-cache. It handles the immutable parts of the -# server installation that rarely need adjustment, such as downloading packages. -# Example: qt5/coin/provisioning/.../testserver/docker_testserver.sh -# -# QT_TEST_SERVER_LIST -# - A list of test servers to bring up for this testcase -# These test servers should be defined in $$TESTSERVER_COMPOSE_FILE. Each -# testcase can define the test servers it depends on. -# Example: QT_TEST_SERVER_LIST = apache2 squid vsftpd ftp-proxy danted -# -# Pre-processor defines needed for the application: -# QT_TEST_SERVER -# - A preprocessor macro used for testcase to change testing parameters at -# compile time -# This macro is predefined for docker-based test servers and is passed as a -# compiler option (-DQT_TEST_SERVER). The testcase can then check whether -# docker-based servers are in use and change the testing parameters, such as -# host name or port number, at compile time. An example can be found in -# network-settings.h. -# -# Example: -# #if defined(QT_TEST_SERVER) -# Change the testing parameters at compile time -# #endif -# -# QT_TEST_SERVER_DOMAIN -# - A preprocessor macro that holds the server domain name -# Provided for the helper functions in network-settings.h. Use function -# serverDomainName() in your application instead. -# -# Additional make targets: -# 1. check_network - A renamed target from the check target of testcase feature. -# 2. testserver_clean - Clean up server containers/images and tidy away related -# files. - -# The docker test server should only be integrated in the leaf Makefile. -# If debug_and_release option is in use, skip the meta-Makefile except for -# Makefile.Debug and Makefile.Release. -debug_and_release:!build_pass: return() - -DOCKER_ENABLED = 1 - -equals(QMAKE_HOST.os, Darwin) | equals(QMAKE_HOST.os, Windows) { - DOCKER_ENABLED = 0 - message("Not using docker network test server on macOS and Windows, see QTQAINFRA-2717 and QTQAINFRA-2750") -} - -TESTSERVER_VERSION = "" - -equals(DOCKER_ENABLED, 1) { - TESTSERVER_VERSION = $$system(docker-compose --version) -} - -isEmpty(TESTSERVER_VERSION) { - # Make check with server "qt-test-server.qt-test-net" as a fallback -} else { - # Make check with docker test servers - equals(QMAKE_HOST.os, Linux) { - # For the platform supporting docker bridge network, each container is - # assigned a unique hostname and connected to the same network domain - # to communicate with the others. - DEFINES += QT_TEST_SERVER_NAME - DNSDOMAIN = test-net.qt.local - } else { - # For the others, the containers are deployed into a virtual machine - # using the host network. All the containers share the same hostname of - # the virtual machine, and they are connected to the same network domain. - # NOTE: In Windows, Apple Bonjour only works within a single local domain. - DNSDOMAIN = local - } - - equals(QMAKE_HOST.os, Darwin) { - # There is no docker bridge on macOS. It is impossible to ping a container. - # Docker docs recommends using port mapping to connect to a container; - # but it causes a port conflict if the user is running a service that - # binds the same port on the host. An alternative solution is to deploy - # the docker environment into VirtualBox using docker-machine. - isEmpty(TESTSERVER_COMPOSE_FILE): TESTSERVER_COMPOSE_FILE = \ - $$dirname(_QMAKE_CONF_)/tests/testserver/docker-compose-for-macOS.yml - - # The connection configuration for the target machine - MACHINE_CONFIG = $(shell docker-machine config qt-test-server) - - # The environment variables passed to the docker-compose file - TEST_ENV = 'MACHINE_IP=$(shell docker-machine ip qt-test-server)' - TEST_ENV += 'TEST_DOMAIN=$$DNSDOMAIN' - TEST_CMD = env - } else:equals(QMAKE_HOST.os, Windows) { - # There is no docker bridge on Windows. It is impossible to ping a container. - # Use docker-machine to deploy the docker environment into VirtualBox. - isEmpty(TESTSERVER_COMPOSE_FILE): TESTSERVER_COMPOSE_FILE = \ - $$dirname(_QMAKE_CONF_)/tests/testserver/docker-compose-for-windows.yml - - # The connection configuration for the target machine - MACHINE_CONFIG = (docker-machine config qt-test-server) - - # The environment variables passed to the docker-compose file - TEST_ENV = '\$\$env:MACHINE_IP = docker-machine ip qt-test-server;' - TEST_ENV += '\$\$env:TEST_DOMAIN = $$shell_quote(\"$$DNSDOMAIN\");' - - # Docker-compose CLI environment variables: - # Enable path conversion from Windows-style to Unix-style in volume definitions. - TEST_ENV += '\$\$env:COMPOSE_CONVERT_WINDOWS_PATHS = $$shell_quote(\"true\");' - - TEST_CMD = 'PowerShell -noprofile' - CONFIG += PowerShell - } else { - isEmpty(TESTSERVER_COMPOSE_FILE): TESTSERVER_COMPOSE_FILE = \ - $$dirname(_QMAKE_CONF_)/tests/testserver/docker-compose.yml - # The environment variables passed to the docker-compose file - TEST_ENV = 'TEST_DOMAIN=$$DNSDOMAIN' - TEST_CMD = env - } - !exists($$TESTSERVER_COMPOSE_FILE): error("Invalid TESTSERVER_COMPOSE_FILE specified") - - - # The domain name is relevant to https keycert (qnetworkreply/crts/qt-test-net-cacert.pem). - DEFINES += QT_TEST_SERVER QT_TEST_SERVER_DOMAIN=$$shell_quote(\"$${DNSDOMAIN}\") - - # Ensure that the docker-compose file is provided. It is a configuration - # file which is mandatory for all docker-compose commands. You can get more - # detail from the description of TESTSERVER_COMPOSE_FILE above. There is - # also an example showing how to configure it manually. - FILE_PRETEST_MSG = "Project variable 'TESTSERVER_COMPOSE_FILE' is not set" - PowerShell { - testserver_pretest.commands = echo $$TESTSERVER_VERSION && - testserver_pretest.commands += \ - $$TEST_CMD if ([String]::IsNullOrEmpty($$shell_quote(\"$$TESTSERVER_COMPOSE_FILE\"))) \ - {Write-Error $$shell_quote(\"$$FILE_PRETEST_MSG\")} && - } else { - testserver_pretest.commands = $(info "testserver:" $$TESTSERVER_VERSION) - testserver_pretest.commands += $(if $$TESTSERVER_COMPOSE_FILE,,$(error $$FILE_PRETEST_MSG)) - } - - # Make sure docker-machine is both created and running. The docker_machine - # script is used to deploy the docker environment into VirtualBox. - # Example: qt5/coin/provisioning/common/shared/testserver/docker_machine.sh - !isEmpty(MACHINE_CONFIG) { - MACHINE_LIST_CMD = docker-machine ls -q --filter "Name=^qt-test-server\$\$" - MACHINE_LIST_MSG = "Docker machine qt-test-server not found" - PowerShell { - testserver_pretest.commands += $$TEST_CMD if (!($$MACHINE_LIST_CMD)) \ - {Write-Error $$shell_quote(\"$$MACHINE_LIST_MSG\")} && - } else { - testserver_pretest.commands += \ - $(if $(shell $$MACHINE_LIST_CMD),,$(error $$MACHINE_LIST_MSG)) - } - - MACHINE_STATE_CMD = \ - docker-machine ls -q --filter "State=Running" --filter "Name=^qt-test-server\$\$" - MACHINE_START_CMD = docker-machine start qt-test-server - MACHINE_RECERT = docker-machine regenerate-certs -f qt-test-server - PowerShell { - testserver_pretest.commands += \ - $$TEST_CMD if (!($$MACHINE_STATE_CMD)) {$$MACHINE_START_CMD; $$MACHINE_RECERT} && - } else { - testserver_pretest.commands += \ - $(if $(shell $$MACHINE_STATE_CMD),,\ - $(shell $$MACHINE_START_CMD > /dev/null && $$MACHINE_RECERT > /dev/null)) - } - } - - # Before starting the test servers, it requires the user to run the setup - # script (coin/provisioning/.../testserver/docker_testserver.sh) in advance. - IMAGE_PRETEST_CMD = docker $$MACHINE_CONFIG images -aq "qt-test-server-*" - IMAGE_PRETEST_MSG = "Docker image qt-test-server-* not found" - PowerShell { - testserver_pretest.commands += $$TEST_CMD if (!($$IMAGE_PRETEST_CMD)) \ - {Write-Error $$shell_quote(\"$$IMAGE_PRETEST_MSG\")} - } else { - testserver_pretest.commands += \ - $(if $(shell $$IMAGE_PRETEST_CMD),,$(error $$IMAGE_PRETEST_MSG)) - } - - # Rename the check target of testcase feature - check.target = check_network - testserver_test.target = check - - # Pretesting test servers environment - testserver_test.depends = testserver_pretest - - # Bring up test servers and make sure the services are ready. - !isEmpty(TEST_CMD): testserver_test.commands = $$TEST_CMD $$TEST_ENV - testserver_test.commands += docker-compose $$MACHINE_CONFIG -f $$TESTSERVER_COMPOSE_FILE up \ - --detach --force-recreate --timeout 1 $${QT_TEST_SERVER_LIST} && - - # Check test cases with docker-based test servers. - testserver_test.commands += $(MAKE) -f $(MAKEFILE) check_network && - - # Stop and remove test servers after testing. - !isEmpty(TEST_CMD): testserver_test.commands += $$TEST_CMD $$TEST_ENV - testserver_test.commands += docker-compose $$MACHINE_CONFIG -f $$TESTSERVER_COMPOSE_FILE down \ - --timeout 1 - - # Destroy test servers and tidy away related files. - testserver_clean.commands = docker-compose $$MACHINE_CONFIG -f $$TESTSERVER_COMPOSE_FILE down \ - --rmi all - - QMAKE_EXTRA_TARGETS += testserver_pretest testserver_test testserver_clean -} diff --git a/tests/auto/tools/moc/tst_moc.cpp b/tests/auto/tools/moc/tst_moc.cpp index f12df578f4..ec4a44e672 100644 --- a/tests/auto/tools/moc/tst_moc.cpp +++ b/tests/auto/tools/moc/tst_moc.cpp @@ -525,6 +525,7 @@ private: #ifdef Q_MOC_RUN int xx = 11'11; // digit separator must not confuse moc (QTBUG-59351) + int xx = 0b11'11; // digit separator in a binary literal must not confuse moc (QTBUG-75656) #endif private slots: @@ -1425,6 +1426,16 @@ void tst_Moc::environmentIncludePaths() // plugin_metadata.h contains a plugin which we register here. Since we're not building this // application as a plugin, we need top copy some of the initializer code found in qplugin.h: extern "C" QObject *qt_plugin_instance(); +#if QT_VERSION >= QT_VERSION_CHECK(6, 0, 0) +extern "C" QPluginMetaData qt_plugin_query_metadata(); +class StaticPluginInstance{ +public: + StaticPluginInstance() { + QStaticPlugin plugin(qt_plugin_instance, qt_plugin_query_metadata); + qRegisterStaticPluginFunction(plugin); + } +}; +#else extern "C" const char *qt_plugin_query_metadata(); class StaticPluginInstance{ public: @@ -1433,6 +1444,7 @@ public: qRegisterStaticPluginFunction(plugin); } }; +#endif static StaticPluginInstance staticInstance; void tst_Moc::specifyMetaTagsFromCmdline() { diff --git a/tests/auto/tools/qmakelib/qmakelib.pro b/tests/auto/tools/qmakelib/qmakelib.pro index 29f17f6a14..5e9e9fe637 100644 --- a/tests/auto/tools/qmakelib/qmakelib.pro +++ b/tests/auto/tools/qmakelib/qmakelib.pro @@ -1,7 +1,7 @@ CONFIG += testcase TARGET = tst_qmakelib QT = core testlib -win32: LIBS += -ladvapi32 +win32: QMAKE_USE += advapi32 INCLUDEPATH += ../../../../qmake/library VPATH += ../../../../qmake/library diff --git a/tests/auto/widgets/dialogs/qfilesystemmodel/BLACKLIST b/tests/auto/widgets/dialogs/qfilesystemmodel/BLACKLIST index 01679eb6ee..f78d23c6b1 100644 --- a/tests/auto/widgets/dialogs/qfilesystemmodel/BLACKLIST +++ b/tests/auto/widgets/dialogs/qfilesystemmodel/BLACKLIST @@ -9,3 +9,5 @@ b2qt ubuntu b2qt windows +rhel +suse-leap diff --git a/tests/auto/widgets/graphicsview/qgraphicsitem/qgraphicsitem.pro b/tests/auto/widgets/graphicsview/qgraphicsitem/qgraphicsitem.pro index ae6de48195..16818a98f9 100644 --- a/tests/auto/widgets/graphicsview/qgraphicsitem/qgraphicsitem.pro +++ b/tests/auto/widgets/graphicsview/qgraphicsitem/qgraphicsitem.pro @@ -5,4 +5,4 @@ QT += core-private gui-private SOURCES += tst_qgraphicsitem.cpp DEFINES += QT_NO_CAST_TO_ASCII -win32:!winrt: LIBS += -luser32 +win32:!winrt: QMAKE_USE += user32 diff --git a/tests/auto/widgets/graphicsview/qgraphicsitem/tst_qgraphicsitem.cpp b/tests/auto/widgets/graphicsview/qgraphicsitem/tst_qgraphicsitem.cpp index bca664c05b..0cfdecbcab 100644 --- a/tests/auto/widgets/graphicsview/qgraphicsitem/tst_qgraphicsitem.cpp +++ b/tests/auto/widgets/graphicsview/qgraphicsitem/tst_qgraphicsitem.cpp @@ -8386,7 +8386,7 @@ void tst_QGraphicsItem::focusProxy() QString err; QTextStream stream(&err); stream << "QGraphicsItem::setFocusProxy: " - << (void*)item << " is already in the focus proxy chain" << flush; + << (void*)item << " is already in the focus proxy chain" << Qt::flush; QTest::ignoreMessage(QtWarningMsg, err.toLatin1().constData()); item2->setFocusProxy(item); // fails QCOMPARE(item->focusProxy(), (QGraphicsItem *)item2); diff --git a/tests/auto/widgets/graphicsview/qgraphicsscene/qgraphicsscene.pro b/tests/auto/widgets/graphicsview/qgraphicsscene/qgraphicsscene.pro index 351cecd92e..2f648a2212 100644 --- a/tests/auto/widgets/graphicsview/qgraphicsscene/qgraphicsscene.pro +++ b/tests/auto/widgets/graphicsview/qgraphicsscene/qgraphicsscene.pro @@ -4,7 +4,7 @@ QT += widgets widgets-private testlib QT += core-private gui-private SOURCES += tst_qgraphicsscene.cpp RESOURCES += images.qrc -win32:!winrt: LIBS += -luser32 +win32:!winrt: QMAKE_USE += user32 DEFINES += SRCDIR=\\\"$$PWD\\\" DEFINES += QT_NO_CAST_TO_ASCII diff --git a/tests/auto/widgets/graphicsview/qgraphicsview/tst_qgraphicsview.cpp b/tests/auto/widgets/graphicsview/qgraphicsview/tst_qgraphicsview.cpp index 28df3a3c38..efee901227 100644 --- a/tests/auto/widgets/graphicsview/qgraphicsview/tst_qgraphicsview.cpp +++ b/tests/auto/widgets/graphicsview/qgraphicsview/tst_qgraphicsview.cpp @@ -4857,7 +4857,7 @@ void tst_QGraphicsView::QTBUG_16063_microFocusRect() scene.setFocusItem(item); view.setFocus(); - QRectF mfv = view.inputMethodQuery(Qt::ImMicroFocus).toRectF(); + QRectF mfv = view.inputMethodQuery(Qt::ImCursorRectangle).toRectF(); QCOMPARE(mfv, IMItem::mf.translated(-view.mapToScene(view.sceneRect().toRect()).boundingRect().topLeft())); } diff --git a/tests/auto/widgets/itemviews/qheaderview/tst_qheaderview.cpp b/tests/auto/widgets/itemviews/qheaderview/tst_qheaderview.cpp index 42258c85b9..f247889d55 100644 --- a/tests/auto/widgets/itemviews/qheaderview/tst_qheaderview.cpp +++ b/tests/auto/widgets/itemviews/qheaderview/tst_qheaderview.cpp @@ -248,6 +248,7 @@ private slots: void sizeHintCrash(); void testResetCachedSizeHint(); void statusTips(); + void testRemovingColumnsViaLayoutChanged(); protected: void setupTestData(bool use_reset_model = false); @@ -353,6 +354,7 @@ public: void cleanup() { + emit layoutAboutToBeChanged(); cols = 3; rows = 3; emit layoutChanged(); @@ -3489,5 +3491,20 @@ void tst_QHeaderView::statusTips() QCOMPARE(headerView.statusTipText, QLatin1String("[0,1,0] -- Header")); } +void tst_QHeaderView::testRemovingColumnsViaLayoutChanged() +{ + const int persistentSectionSize = 101; + + QtTestModel model; + model.rows = model.cols = 5; + view->setModel(&model); + for (int i = 0; i < model.cols; ++i) + view->resizeSection(i, persistentSectionSize + i); + model.cleanup(); // down to 3 via layoutChanged (not columnsRemoved) + for (int j = 0; j < model.cols; ++j) + QCOMPARE(view->sectionSize(j), persistentSectionSize + j); + // The main point of this test is that the section-size restoring code didn't go out of bounds. +} + QTEST_MAIN(tst_QHeaderView) #include "tst_qheaderview.moc" diff --git a/tests/auto/widgets/itemviews/qitemdelegate/qitemdelegate.pro b/tests/auto/widgets/itemviews/qitemdelegate/qitemdelegate.pro index 10cd1dcc54..916694fd0f 100644 --- a/tests/auto/widgets/itemviews/qitemdelegate/qitemdelegate.pro +++ b/tests/auto/widgets/itemviews/qitemdelegate/qitemdelegate.pro @@ -3,4 +3,4 @@ TARGET = tst_qitemdelegate QT += widgets widgets-private testlib SOURCES += tst_qitemdelegate.cpp -win32:!winrt: LIBS += -luser32 +win32:!winrt: QMAKE_USE += user32 diff --git a/tests/auto/widgets/itemviews/qlistview/qlistview.pro b/tests/auto/widgets/itemviews/qlistview/qlistview.pro index 75f45ab432..c3e19adc81 100644 --- a/tests/auto/widgets/itemviews/qlistview/qlistview.pro +++ b/tests/auto/widgets/itemviews/qlistview/qlistview.pro @@ -2,4 +2,4 @@ CONFIG += testcase TARGET = tst_qlistview QT += widgets gui-private widgets-private core-private testlib testlib-private SOURCES += tst_qlistview.cpp -win32:!winrt: LIBS += -luser32 +win32:!winrt: QMAKE_USE += user32 diff --git a/tests/auto/widgets/itemviews/qlistwidget/tst_qlistwidget.cpp b/tests/auto/widgets/itemviews/qlistwidget/tst_qlistwidget.cpp index 30afa69c31..fe2ede4183 100644 --- a/tests/auto/widgets/itemviews/qlistwidget/tst_qlistwidget.cpp +++ b/tests/auto/widgets/itemviews/qlistwidget/tst_qlistwidget.cpp @@ -267,6 +267,7 @@ tst_QListWidget::tst_QListWidget(): testWidget(0), rcParent(8), rcFirst(8,0), rc void tst_QListWidget::initTestCase() { + qRegisterMetaType<QListWidgetItem*>("QListWidgetItem*"); testWidget = new QListWidget(); testWidget->show(); @@ -663,6 +664,9 @@ void tst_QListWidget::insertItems() QFETCH(int, rowCount); QFETCH(int, insertType); + QSignalSpy itemChangedSpy(testWidget, &QListWidget::itemChanged); + QSignalSpy dataChangedSpy(testWidget->model(), &QAbstractItemModel::dataChanged); + if (insertType == 3) { QStringList strings; for (int i=0; i<rowCount; ++i) @@ -700,6 +704,9 @@ void tst_QListWidget::insertItems() // make sure all items have view set correctly for (int i=0; i<testWidget->count(); ++i) QCOMPARE(testWidget->item(i)->listWidget(), testWidget); + + QCOMPARE(itemChangedSpy.count(), 0); + QCOMPARE(dataChangedSpy.count(), 0); } void tst_QListWidget::itemAssignment() @@ -1257,7 +1264,6 @@ void tst_QListWidget::setData() QFETCH(IntList, roles); QFETCH(QVariantList, values); QFETCH(int, expectedSignalCount); - qRegisterMetaType<QListWidgetItem *>("QListWidgetItem*"); QCOMPARE(roles.count(), values.count()); @@ -1519,11 +1525,11 @@ void tst_QListWidget::itemData() item.setData(Qt::DisplayRole, QString("0")); QCOMPARE(widget.currentRoles, QVector<int>({Qt::DisplayRole, Qt::EditRole})); item.setData(Qt::CheckStateRole, Qt::PartiallyChecked); - QCOMPARE(widget.currentRoles, {Qt::CheckStateRole}); + QCOMPARE(widget.currentRoles, QVector<int>{Qt::CheckStateRole}); for (int i = 0; i < 4; ++i) { item.setData(Qt::UserRole + i, QString::number(i + 1)); - QCOMPARE(widget.currentRoles, {Qt::UserRole + i}); + QCOMPARE(widget.currentRoles, QVector<int>{Qt::UserRole + i}); } QMap<int, QVariant> flags = widget.model()->itemData(widget.model()->index(0, 0)); QCOMPARE(flags.count(), 6); @@ -1715,7 +1721,6 @@ void tst_QListWidget::task258949_keypressHangup() void tst_QListWidget::QTBUG8086_currentItemChangedOnClick() { - qRegisterMetaType<QListWidgetItem*>("QListWidgetItem*"); QWidget win; QHBoxLayout layout(&win); QListWidget list; @@ -1837,7 +1842,6 @@ void tst_QListWidget::mimeData() void tst_QListWidget::QTBUG50891_ensureSelectionModelSignalConnectionsAreSet() { - qRegisterMetaType<QListWidgetItem*>("QListWidgetItem*"); QListWidget list; for (int i = 0 ; i < 4; ++i) new QListWidgetItem(QString::number(i), &list); diff --git a/tests/auto/widgets/itemviews/qtableview/tst_qtableview.cpp b/tests/auto/widgets/itemviews/qtableview/tst_qtableview.cpp index b1ddc6e7a2..bf87408056 100644 --- a/tests/auto/widgets/itemviews/qtableview/tst_qtableview.cpp +++ b/tests/auto/widgets/itemviews/qtableview/tst_qtableview.cpp @@ -32,6 +32,9 @@ #include <private/qtablewidget_p.h> #include <QtTest/QtTest> #include "private/qapplication_p.h" +#if QT_CONFIG(textmarkdownwriter) +#include "private/qtextmarkdownwriter_p.h" +#endif #include <algorithm> @@ -196,6 +199,10 @@ private slots: void viewOptions(); void taskQTBUG_7232_AllowUserToControlSingleStep(); + +#if QT_CONFIG(textmarkdownwriter) + void markdownWriter(); +#endif }; // Testing get/set functions @@ -4560,5 +4567,33 @@ void tst_QTableView::taskQTBUG_50171_selectRowAfterSwapColumns() } } +// This has nothing to do with QTableView, but it's convenient to reuse the QtTestTableModel +#if QT_CONFIG(textmarkdownwriter) + +// #define DEBUG_WRITE_OUTPUT + +void tst_QTableView::markdownWriter() +{ + QtTestTableModel model(2, 3); + QString md; + { + QTextStream stream(&md); + QTextMarkdownWriter writer(stream, QTextDocument::MarkdownDialectGitHub); + writer.writeTable(&model); + } + +#ifdef DEBUG_WRITE_OUTPUT + { + QFile out("/tmp/table.md"); + out.open(QFile::WriteOnly); + out.write(md.toUtf8()); + out.close(); + } +#endif + + QCOMPARE(md, QString::fromLatin1("|1 |2 |3 |\n|-------|-------|-------|\n|[0,0,0]|[0,1,0]|[0,2,0]|\n|[1,0,0]|[1,1,0]|[1,2,0]|\n")); +} +#endif + QTEST_MAIN(tst_QTableView) #include "tst_qtableview.moc" diff --git a/tests/auto/widgets/itemviews/qtablewidget/tst_qtablewidget.cpp b/tests/auto/widgets/itemviews/qtablewidget/tst_qtablewidget.cpp index c2de5c2761..6184962d93 100644 --- a/tests/auto/widgets/itemviews/qtablewidget/tst_qtablewidget.cpp +++ b/tests/auto/widgets/itemviews/qtablewidget/tst_qtablewidget.cpp @@ -1383,11 +1383,11 @@ void tst_QTableWidget::itemData() item->setData(Qt::DisplayRole, QString("0")); QCOMPARE(widget.currentRoles, QVector<int>({Qt::DisplayRole, Qt::EditRole})); item->setData(Qt::CheckStateRole, Qt::PartiallyChecked); - QCOMPARE(widget.currentRoles, {Qt::CheckStateRole}); + QCOMPARE(widget.currentRoles, QVector<int>{Qt::CheckStateRole}); for (int i = 0; i < 4; ++i) { item->setData(Qt::UserRole + i, QString::number(i + 1)); - QCOMPARE(widget.currentRoles, {Qt::UserRole + i}); + QCOMPARE(widget.currentRoles, QVector<int>{Qt::UserRole + i}); } QMap<int, QVariant> flags = widget.model()->itemData(widget.model()->index(0, 0)); QCOMPARE(flags.count(), 6); diff --git a/tests/auto/widgets/itemviews/qtreewidget/tst_qtreewidget.cpp b/tests/auto/widgets/itemviews/qtreewidget/tst_qtreewidget.cpp index 33d4f3bf91..0d97974b90 100644 --- a/tests/auto/widgets/itemviews/qtreewidget/tst_qtreewidget.cpp +++ b/tests/auto/widgets/itemviews/qtreewidget/tst_qtreewidget.cpp @@ -1999,10 +1999,10 @@ void tst_QTreeWidget::itemData() item.setData(0, Qt::DisplayRole, QString("0")); QCOMPARE(widget.currentRoles, QVector<int>({Qt::DisplayRole, Qt::EditRole})); item.setData(0, Qt::CheckStateRole, Qt::PartiallyChecked); - QCOMPARE(widget.currentRoles, {Qt::CheckStateRole}); + QCOMPARE(widget.currentRoles, QVector<int>{Qt::CheckStateRole}); for (int i = 0; i < 4; ++i) { item.setData(0, Qt::UserRole + i, QString::number(i + 1)); - QCOMPARE(widget.currentRoles, {Qt::UserRole + i}); + QCOMPARE(widget.currentRoles, QVector<int>{Qt::UserRole + i}); } QMap<int, QVariant> flags = widget.model()->itemData(widget.model()->index(0, 0)); QCOMPARE(flags.count(), 6); diff --git a/tests/auto/widgets/kernel/qactiongroup/tst_qactiongroup.cpp b/tests/auto/widgets/kernel/qactiongroup/tst_qactiongroup.cpp index 52ca10d31f..0ba3cedf16 100644 --- a/tests/auto/widgets/kernel/qactiongroup/tst_qactiongroup.cpp +++ b/tests/auto/widgets/kernel/qactiongroup/tst_qactiongroup.cpp @@ -166,24 +166,22 @@ void tst_QActionGroup::separators() separator->setSeparator(true); actGroup.addAction(separator); - QListIterator<QAction*> it(actGroup.actions()); - while (it.hasNext()) - menu.addAction(it.next()); + menu.addActions(actGroup.actions()); QCOMPARE((int)menu.actions().size(), 2); - it = QListIterator<QAction*>(actGroup.actions()); - while (it.hasNext()) - menu.removeAction(it.next()); + const auto removeActions = [&menu](const QList<QAction *> &actions) { + for (QAction *action : actions) + menu.removeAction(action); + }; + removeActions(actGroup.actions()); QCOMPARE((int)menu.actions().size(), 0); action = new QAction(&actGroup); action->setText("test two"); - it = QListIterator<QAction*>(actGroup.actions()); - while (it.hasNext()) - menu.addAction(it.next()); + menu.addActions(actGroup.actions()); QCOMPARE((int)menu.actions().size(), 3); } diff --git a/tests/auto/widgets/kernel/qapplication/modal/base.cpp b/tests/auto/widgets/kernel/qapplication/modal/base.cpp index 19f8abebbd..249d402f2e 100644 --- a/tests/auto/widgets/kernel/qapplication/modal/base.cpp +++ b/tests/auto/widgets/kernel/qapplication/modal/base.cpp @@ -32,9 +32,8 @@ base::base(QWidget *parent) : QWidget(parent) { m_timer = new QTimer(this); - m_modalStarted = false; m_timer->setSingleShot(false); - connect(m_timer, SIGNAL(timeout()), this, SLOT(periodicTimer())); + connect(m_timer, &QTimer::timeout, this, &base::periodicTimer); m_timer->start(5000); } @@ -43,6 +42,7 @@ void base::periodicTimer() if(m_modalStarted) exit(0); m_modalDialog = new QDialog(this); + m_modalDialog->setWindowTitle(QLatin1String("modal")); m_modalDialog->setModal(true); m_modalDialog->show(); m_modalStarted = true; diff --git a/tests/auto/widgets/kernel/qapplication/modal/base.h b/tests/auto/widgets/kernel/qapplication/modal/base.h index 95eb427e61..153d9ca420 100644 --- a/tests/auto/widgets/kernel/qapplication/modal/base.h +++ b/tests/auto/widgets/kernel/qapplication/modal/base.h @@ -37,12 +37,10 @@ class base : public QWidget { Q_OBJECT QTimer *m_timer; - bool m_modalStarted; - QDialog *m_modalDialog; + bool m_modalStarted = false; + QDialog *m_modalDialog = nullptr; public: - explicit base(QWidget *parent = 0); - -signals: + explicit base(QWidget *parent = nullptr); public slots: void periodicTimer(); diff --git a/tests/auto/widgets/kernel/qapplication/modal/main.cpp b/tests/auto/widgets/kernel/qapplication/modal/main.cpp index 400792637f..9dcb6732fa 100644 --- a/tests/auto/widgets/kernel/qapplication/modal/main.cpp +++ b/tests/auto/widgets/kernel/qapplication/modal/main.cpp @@ -26,8 +26,6 @@ ** ****************************************************************************/ -#include <QtGui> - #include <QApplication> #include "base.h" @@ -35,7 +33,6 @@ int main(int argc, char *argv[]) { QApplication app(argc, argv); QApplication::setAttribute(Qt::AA_NativeWindows); //QTBUG-15774 - base *b = new base(); - Q_UNUSED(b); + base b; return app.exec(); } diff --git a/tests/auto/widgets/kernel/qapplication/tst_qapplication.cpp b/tests/auto/widgets/kernel/qapplication/tst_qapplication.cpp index e57ac77c39..4f94e83c1c 100644 --- a/tests/auto/widgets/kernel/qapplication/tst_qapplication.cpp +++ b/tests/auto/widgets/kernel/qapplication/tst_qapplication.cpp @@ -27,7 +27,6 @@ ****************************************************************************/ -//#define QT_TST_QAPP_DEBUG #include <qdebug.h> #include <QtTest/QtTest> @@ -55,35 +54,14 @@ #include <QtWidgets/QStyle> #include <qpa/qwindowsysteminterface.h> +#include <qpa/qwindowsysteminterface_p.h> #include <private/qhighdpiscaling_p.h> -QT_BEGIN_NAMESPACE -static QWindowSystemInterface::TouchPoint touchPoint(const QTouchEvent::TouchPoint& pt) -{ - QWindowSystemInterface::TouchPoint p; - p.id = pt.id(); - p.flags = pt.flags(); - p.normalPosition = pt.normalizedPos(); - p.area = pt.screenRect(); - p.pressure = pt.pressure(); - p.state = pt.state(); - p.velocity = pt.velocity(); - p.rawPositions = pt.rawScreenPositions(); - return p; -} - -static QList<struct QWindowSystemInterface::TouchPoint> touchPointList(const QList<QTouchEvent::TouchPoint>& pointList) -{ - QList<struct QWindowSystemInterface::TouchPoint> newList; - - Q_FOREACH (QTouchEvent::TouchPoint p, pointList) - { - newList.append(touchPoint(p)); - } - return newList; -} +#include <algorithm> +Q_LOGGING_CATEGORY(lcTests, "qt.widgets.tests") +QT_BEGIN_NAMESPACE extern bool Q_GUI_EXPORT qt_tab_all_widgets(); // from qapplication.cpp QT_END_NAMESPACE @@ -92,9 +70,6 @@ class tst_QApplication : public QObject { Q_OBJECT -public: - tst_QApplication(); - private slots: void cleanup(); void sendEventsOnProcessEvents(); // this must be the first test @@ -165,12 +140,6 @@ private slots: void settableStyleHints_data(); void settableStyleHints(); // Needs to run last as it changes style hints. - -protected slots: - void quitApplication(); - -private: - bool quitApplicationTriggered; }; class EventSpy : public QObject @@ -179,7 +148,7 @@ class EventSpy : public QObject public: QList<int> recordedEvents; - bool eventFilter(QObject *, QEvent *event) + bool eventFilter(QObject *, QEvent *event) override { recordedEvents.append(event->type()); return false; @@ -189,7 +158,7 @@ public: void tst_QApplication::sendEventsOnProcessEvents() { int argc = 0; - QApplication app(argc, 0); + QApplication app(argc, nullptr); EventSpy spy; app.installEventFilter(&spy); @@ -203,14 +172,10 @@ void tst_QApplication::sendEventsOnProcessEvents() class CloseEventTestWindow : public QWidget { public: - CloseEventTestWindow(QWidget *parent = 0) - : QWidget(parent) - { - } - - void closeEvent(QCloseEvent *event) + void closeEvent(QCloseEvent *event) override { QWidget dialog; + dialog.setWindowTitle(QLatin1String("CloseEventTestWindow")); dialog.show(); dialog.close(); @@ -220,11 +185,6 @@ public: static char *argv0; -tst_QApplication::tst_QApplication() - : quitApplicationTriggered(false) -{ -} - void tst_QApplication::cleanup() { // TODO: Add cleanup code here. @@ -260,13 +220,12 @@ void tst_QApplication::staticSetup() class TestApplication : public QApplication { public: - TestApplication( int &argc, char **argv ) - : QApplication( argc, argv) + TestApplication(int &argc, char **argv) : QApplication( argc, argv) { - startTimer( 150 ); + startTimer(150); } - void timerEvent( QTimerEvent * ) + void timerEvent(QTimerEvent *) override { quit(); } @@ -278,24 +237,26 @@ void tst_QApplication::alert() QSKIP("WinRT does not support more than 1 native widget at the same time"); #endif int argc = 0; - QApplication app(argc, 0); - app.alert(0, 0); + QApplication app(argc, nullptr); + QApplication::alert(nullptr, 0); QWidget widget; + widget.setWindowTitle(QLatin1String(QTest::currentTestFunction())); QWidget widget2; - app.alert(&widget, 100); + widget2.setWindowTitle(QLatin1String(QTest::currentTestFunction()) + QLatin1Char('2')); + QApplication::alert(&widget, 100); widget.show(); widget2.show(); QVERIFY(QTest::qWaitForWindowExposed(&widget)); QVERIFY(QTest::qWaitForWindowExposed(&widget2)); - app.alert(&widget, -1); - app.alert(&widget, 250); + QApplication::alert(&widget, -1); + QApplication::alert(&widget, 250); widget2.activateWindow(); QApplication::setActiveWindow(&widget2); - app.alert(&widget, 0); + QApplication::alert(&widget, 0); widget.activateWindow(); QApplication::setActiveWindow(&widget); - app.alert(&widget, 200); + QApplication::alert(&widget, 200); } void tst_QApplication::multiple_data() @@ -316,7 +277,7 @@ void tst_QApplication::multiple() int i = 0; int argc = 0; while (i++ < 5) { - TestApplication app(argc, 0); + TestApplication app(argc, nullptr); if (features.contains("QFont")) { // create font and force loading @@ -332,7 +293,7 @@ void tst_QApplication::multiple() QWidget widget; } - QVERIFY(!app.exec()); + QVERIFY(!QCoreApplication::exec()); } } @@ -344,7 +305,7 @@ void tst_QApplication::nonGui() #endif int argc = 0; - QApplication app(argc, 0, false); + QApplication app(argc, nullptr, false); QCOMPARE(qApp, &app); } @@ -355,36 +316,29 @@ void tst_QApplication::setFont_data() QTest::addColumn<bool>("beforeAppConstructor"); int argc = 0; - QApplication app(argc, 0); // Needed for QFontDatabase + QApplication app(argc, nullptr); // Needed for QFontDatabase - int cnt = 0; QFontDatabase fdb; - QStringList families = fdb.families(); - for (QStringList::const_iterator itr = families.cbegin(); - itr != families.cend(); - ++itr) { - if (cnt < 3) { - QString family = *itr; - QStringList styles = fdb.styles(family); - if (styles.size() > 0) { - QString style = styles.first(); - QList<int> sizes = fdb.pointSizes(family, style); - if (!sizes.size()) - sizes = fdb.standardSizes(); - if (sizes.size() > 0) { - const QByteArray cntB = QByteArray::number(cnt); - QTest::newRow(("data" + cntB + "a").constData()) - << family - << sizes.first() - << false; - QTest::newRow(("data" + cntB + "b").constData()) - << family - << sizes.first() - << true; - } + const QStringList &families = fdb.families(); + for (int i = 0, count = qMin(3, families.size()); i < count; ++i) { + const auto &family = families.at(i); + const QStringList &styles = fdb.styles(family); + if (!styles.isEmpty()) { + QList<int> sizes = fdb.pointSizes(family, styles.constFirst()); + if (sizes.isEmpty()) + sizes = QFontDatabase::standardSizes(); + if (!sizes.isEmpty()) { + const QByteArray name = QByteArrayLiteral("data") + QByteArray::number(i); + QTest::newRow((name + 'a').constData()) + << family + << sizes.constFirst() + << false; + QTest::newRow((name + 'b').constData()) + << family + << sizes.constFirst() + << true; } } - ++cnt; } QTest::newRow("nonexistingfont after") << "nosuchfont_probably_quiteunlikely" @@ -412,7 +366,7 @@ void tst_QApplication::setFont() } int argc = 0; - QApplication app(argc, 0); + QApplication app(argc, nullptr); if (!beforeAppConstructor) QApplication::setFont( font ); @@ -436,31 +390,30 @@ void tst_QApplication::args_data() void tst_QApplication::task109149() { int argc = 0; - QApplication app(argc, 0); + QApplication app(argc, nullptr); QApplication::setFont(QFont("helvetica", 100)); QWidget w; w.setWindowTitle("hello"); w.show(); - app.processEvents(); + QCoreApplication::processEvents(); } -static char ** QString2cstrings( const QString &args ) +static char **QString2cstrings(const QString &args) { - static QList<QByteArray> cache; + static QByteArrayList cache; - int i; - char **argarray = 0; - QStringList list = args.split(' ');; - argarray = new char*[list.count()+1]; + const auto &list = args.splitRef(' '); + auto argarray = new char*[list.count() + 1]; - for (i = 0; i < (int)list.count(); ++i ) { + int i = 0; + for (; i < list.size(); ++i ) { QByteArray l1 = list[i].toLatin1(); argarray[i] = l1.data(); cache.append(l1); } - argarray[i] = 0; + argarray[i] = nullptr; return argarray; } @@ -498,13 +451,13 @@ void tst_QApplication::args() delete [] argv; // Make sure we switch back to native style. - QApplicationPrivate::styleOverride = QString(); + QApplicationPrivate::styleOverride.clear(); } void tst_QApplication::appName() { char argv0[] = "tst_qapplication"; - char *argv[] = { argv0, 0 }; + char *argv[] = { argv0, nullptr }; int argc = 1; QApplication app(argc, argv); QCOMPARE(::qAppName(), QString::fromLatin1("tst_qapplication")); @@ -521,7 +474,7 @@ public: } protected: - void timerEvent(QTimerEvent *) + void timerEvent(QTimerEvent *) override { close(); } @@ -531,22 +484,24 @@ protected: void tst_QApplication::lastWindowClosed() { int argc = 0; - QApplication app(argc, 0); + QApplication app(argc, nullptr); - QSignalSpy spy(&app, SIGNAL(lastWindowClosed())); + QSignalSpy spy(&app, &QGuiApplication::lastWindowClosed); QPointer<QDialog> dialog = new QDialog; + dialog->setWindowTitle(QLatin1String(QTest::currentTestFunction()) + QLatin1String("Dialog")); QVERIFY(dialog->testAttribute(Qt::WA_QuitOnClose)); - QTimer::singleShot(1000, dialog, SLOT(accept())); + QTimer::singleShot(1000, dialog, &QDialog::accept); dialog->exec(); QVERIFY(dialog); QCOMPARE(spy.count(), 0); QPointer<CloseWidget>widget = new CloseWidget; + widget->setWindowTitle(QLatin1String(QTest::currentTestFunction()) + QLatin1String("CloseWidget")); QVERIFY(widget->testAttribute(Qt::WA_QuitOnClose)); widget->show(); - QObject::connect(&app, SIGNAL(lastWindowClosed()), widget, SLOT(deleteLater())); - app.exec(); + QObject::connect(&app, &QGuiApplication::lastWindowClosed, widget.data(), &QObject::deleteLater); + QCoreApplication::exec(); QVERIFY(!widget); QCOMPARE(spy.count(), 1); spy.clear(); @@ -555,14 +510,17 @@ void tst_QApplication::lastWindowClosed() // show 3 windows, close them, should only get lastWindowClosed once QWidget w1; + w1.setWindowTitle(QLatin1String(QTest::currentTestFunction()) + QLatin1Char('1')); QWidget w2; + w1.setWindowTitle(QLatin1String(QTest::currentTestFunction()) + QLatin1Char('2')); QWidget w3; + w1.setWindowTitle(QLatin1String(QTest::currentTestFunction()) + QLatin1Char('3')); w1.show(); w2.show(); w3.show(); - QTimer::singleShot(1000, &app, SLOT(closeAllWindows())); - app.exec(); + QTimer::singleShot(1000, &app, &QApplication::closeAllWindows); + QCoreApplication::exec(); QCOMPARE(spy.count(), 1); } @@ -570,27 +528,27 @@ class QuitOnLastWindowClosedDialog : public QDialog { Q_OBJECT public: - QPushButton *okButton; - QuitOnLastWindowClosedDialog() { QHBoxLayout *hbox = new QHBoxLayout(this); - okButton = new QPushButton("&ok", this); + m_okButton = new QPushButton("&ok", this); - hbox->addWidget(okButton); - connect(okButton, SIGNAL(clicked()), this, SLOT(accept())); - connect(okButton, SIGNAL(clicked()), this, SLOT(ok_clicked())); + hbox->addWidget(m_okButton); + connect(m_okButton, &QAbstractButton::clicked, this, &QDialog::accept); + connect(m_okButton, &QAbstractButton::clicked, this, &QuitOnLastWindowClosedDialog::ok_clicked); } public slots: + void animateOkClick() { m_okButton->animateClick(); } + void ok_clicked() { QDialog other; QTimer timer; - connect(&timer, SIGNAL(timeout()), &other, SLOT(accept())); - QSignalSpy spy(&timer, SIGNAL(timeout())); - QSignalSpy appSpy(qApp, SIGNAL(lastWindowClosed())); + connect(&timer, &QTimer::timeout, &other, &QDialog::accept); + QSignalSpy spy(&timer, &QTimer::timeout); + QSignalSpy appSpy(qApp, &QGuiApplication::lastWindowClosed); timer.start(1000); other.exec(); @@ -599,6 +557,9 @@ public slots: QCOMPARE(spy.count(), 1); QCOMPARE(appSpy.count(), 1); } + +private: + QPushButton *m_okButton; }; class QuitOnLastWindowClosedWindow : public QWidget @@ -606,16 +567,16 @@ class QuitOnLastWindowClosedWindow : public QWidget Q_OBJECT public: - QuitOnLastWindowClosedWindow() - { } + QuitOnLastWindowClosedWindow() = default; public slots: void execDialogThenShow() { QDialog dialog; + dialog.setWindowTitle(QLatin1String("QuitOnLastWindowClosedWindow Dialog")); QTimer timer1; - connect(&timer1, SIGNAL(timeout()), &dialog, SLOT(accept())); - QSignalSpy spy1(&timer1, SIGNAL(timeout())); + connect(&timer1, &QTimer::timeout, &dialog, &QDialog::accept); + QSignalSpy spy1(&timer1, &QTimer::timeout); timer1.setSingleShot(true); timer1.start(1000); dialog.exec(); @@ -629,27 +590,29 @@ void tst_QApplication::quitOnLastWindowClosed() { { int argc = 0; - QApplication app(argc, 0); + QApplication app(argc, nullptr); QuitOnLastWindowClosedDialog d; + d.setWindowTitle(QLatin1String(QTest::currentTestFunction())); d.show(); - QTimer::singleShot(1000, d.okButton, SLOT(animateClick())); + QTimer::singleShot(1000, &d, &QuitOnLastWindowClosedDialog::animateOkClick); - QSignalSpy appSpy(&app, SIGNAL(lastWindowClosed())); - app.exec(); + QSignalSpy appSpy(&app, &QGuiApplication::lastWindowClosed); + QCoreApplication::exec(); // lastWindowClosed() signal should only be sent after the last dialog is closed QCOMPARE(appSpy.count(), 2); } { int argc = 0; - QApplication app(argc, 0); - QSignalSpy appSpy(&app, SIGNAL(lastWindowClosed())); + QApplication app(argc, nullptr); + QSignalSpy appSpy(&app, &QGuiApplication::lastWindowClosed); QDialog dialog; + dialog.setWindowTitle(QLatin1String(QTest::currentTestFunction())); QTimer timer1; - connect(&timer1, SIGNAL(timeout()), &dialog, SLOT(accept())); - QSignalSpy spy1(&timer1, SIGNAL(timeout())); + connect(&timer1, &QTimer::timeout, &dialog, &QDialog::accept); + QSignalSpy spy1(&timer1, &QTimer::timeout); timer1.setSingleShot(true); timer1.start(1000); dialog.exec(); @@ -657,26 +620,28 @@ void tst_QApplication::quitOnLastWindowClosed() QCOMPARE(appSpy.count(), 0); QTimer timer2; - connect(&timer2, SIGNAL(timeout()), &app, SLOT(quit())); - QSignalSpy spy2(&timer2, SIGNAL(timeout())); + connect(&timer2, &QTimer::timeout, &app, &QCoreApplication::quit); + QSignalSpy spy2(&timer2, &QTimer::timeout); timer2.setSingleShot(true); timer2.start(1000); - int returnValue = app.exec(); + int returnValue = QCoreApplication::exec(); QCOMPARE(returnValue, 0); QCOMPARE(spy2.count(), 1); QCOMPARE(appSpy.count(), 0); } { int argc = 0; - QApplication app(argc, 0); + QApplication app(argc, nullptr); QTimer timer; timer.setInterval(100); - QSignalSpy spy(&app, SIGNAL(aboutToQuit())); - QSignalSpy spy2(&timer, SIGNAL(timeout())); + QSignalSpy spy(&app, &QCoreApplication::aboutToQuit); + QSignalSpy spy2(&timer, &QTimer::timeout); QMainWindow mainWindow; + mainWindow.setWindowTitle(QLatin1String(QTest::currentTestFunction())); QDialog *dialog = new QDialog(&mainWindow); + dialog->setWindowTitle(QLatin1String(QTest::currentTestFunction()) + QLatin1String("Dialog")); QVERIFY(app.quitOnLastWindowClosed()); QVERIFY(mainWindow.testAttribute(Qt::WA_QuitOnClose)); @@ -688,21 +653,29 @@ void tst_QApplication::quitOnLastWindowClosed() QVERIFY(QTest::qWaitForWindowExposed(dialog)); timer.start(); - QTimer::singleShot(1000, &mainWindow, SLOT(close())); // This should quit the application - QTimer::singleShot(2000, &app, SLOT(quit())); // This makes sure we quit even if it didn't + QTimer::singleShot(1000, &mainWindow, &QWidget::close); // This should quit the application + QTimer::singleShot(2000, &app, &QCoreApplication::quit); // This makes sure we quit even if it didn't - app.exec(); + QCoreApplication::exec(); QCOMPARE(spy.count(), 1); QVERIFY(spy2.count() < 15); // Should be around 10 if closing caused the quit } + + bool quitApplicationTriggered = false; + auto quitSlot = [&quitApplicationTriggered] () { + quitApplicationTriggered = true; + QCoreApplication::quit(); + }; + { int argc = 0; - QApplication app(argc, 0); + QApplication app(argc, nullptr); - QSignalSpy spy(&app, SIGNAL(aboutToQuit())); + QSignalSpy spy(&app, &QCoreApplication::aboutToQuit); CloseEventTestWindow mainWindow; + mainWindow.setWindowTitle(QLatin1String(QTest::currentTestFunction())); QVERIFY(app.quitOnLastWindowClosed()); QVERIFY(mainWindow.testAttribute(Qt::WA_QuitOnClose)); @@ -710,30 +683,31 @@ void tst_QApplication::quitOnLastWindowClosed() mainWindow.show(); QVERIFY(QTest::qWaitForWindowExposed(&mainWindow)); - QTimer::singleShot(1000, &mainWindow, SLOT(close())); // This should NOT quit the application (see CloseEventTestWindow) + QTimer::singleShot(1000, &mainWindow, &QWidget::close); // This should NOT quit the application (see CloseEventTestWindow) quitApplicationTriggered = false; - QTimer::singleShot(2000, this, SLOT(quitApplication())); // This actually quits the application. + QTimer::singleShot(2000, this, quitSlot); // This actually quits the application. - app.exec(); + QCoreApplication::exec(); QCOMPARE(spy.count(), 1); QVERIFY(quitApplicationTriggered); } { int argc = 0; - QApplication app(argc, 0); - QSignalSpy appSpy(&app, SIGNAL(lastWindowClosed())); + QApplication app(argc, nullptr); + QSignalSpy appSpy(&app, &QApplication::lastWindowClosed); // exec a dialog for 1 second, then show the window QuitOnLastWindowClosedWindow window; - QTimer::singleShot(0, &window, SLOT(execDialogThenShow())); + window.setWindowTitle(QLatin1String(QTest::currentTestFunction())); + QTimer::singleShot(0, &window, &QuitOnLastWindowClosedWindow::execDialogThenShow); QTimer timer; - QSignalSpy timerSpy(&timer, SIGNAL(timeout())); - connect(&timer, SIGNAL(timeout()), &window, SLOT(close())); + QSignalSpy timerSpy(&timer, &QTimer::timeout); + connect(&timer, &QTimer::timeout, &window, &QWidget::close); timer.setSingleShot(true); timer.start(2000); - int returnValue = app.exec(); + int returnValue = QCoreApplication::exec(); QCOMPARE(returnValue, 0); // failure here means the timer above didn't fire, and the // quit was caused the dialog being closed (not the window) @@ -742,34 +716,38 @@ void tst_QApplication::quitOnLastWindowClosed() } { int argc = 0; - QApplication app(argc, 0); + QApplication app(argc, nullptr); QVERIFY(app.quitOnLastWindowClosed()); QWindow w; + w.setTitle(QLatin1String(QTest::currentTestFunction()) + QLatin1String("Window")); w.show(); QWidget wid; + wid.setWindowTitle(QLatin1String(QTest::currentTestFunction()) + QLatin1String("Widget")); wid.show(); - QTimer::singleShot(1000, &wid, SLOT(close())); // This should NOT quit the application because the + QTimer::singleShot(1000, &wid, &QWidget::close); // This should NOT quit the application because the // QWindow is still there. quitApplicationTriggered = false; - QTimer::singleShot(2000, this, SLOT(quitApplication())); // This causes the quit. + QTimer::singleShot(2000, this, quitSlot); // This causes the quit. - app.exec(); + QCoreApplication::exec(); QVERIFY(quitApplicationTriggered); // Should be around 20 if closing did not caused the quit } { // QTBUG-31569: If the last widget with Qt::WA_QuitOnClose set is closed, other // widgets that don't have the attribute set should be closed automatically. int argc = 0; - QApplication app(argc, 0); + QApplication app(argc, nullptr); QVERIFY(app.quitOnLastWindowClosed()); QWidget w1; + w1.setWindowTitle(QLatin1String(QTest::currentTestFunction()) + QLatin1Char('1')); w1.show(); QWidget w2; + w1.setWindowTitle(QLatin1String(QTest::currentTestFunction()) + QLatin1Char('2')); w2.setAttribute(Qt::WA_QuitOnClose, false); w2.show(); @@ -778,19 +756,24 @@ void tst_QApplication::quitOnLastWindowClosed() QTimer timer; timer.setInterval(100); timer.start(); - QSignalSpy timerSpy(&timer, SIGNAL(timeout())); + QSignalSpy timerSpy(&timer, &QTimer::timeout); - QTimer::singleShot(100, &w1, SLOT(close())); - app.exec(); + QTimer::singleShot(100, &w1, &QWidget::close); + QCoreApplication::exec(); QVERIFY(timerSpy.count() < 10); } } +static inline bool isVisible(const QWidget *w) +{ + return w->isVisible(); +} + class PromptOnCloseWidget : public QWidget { public: - void closeEvent(QCloseEvent *event) + void closeEvent(QCloseEvent *event) override { QMessageBox *messageBox = new QMessageBox(this); messageBox->setWindowTitle("Unsaved data"); @@ -802,12 +785,12 @@ public: QVERIFY(QTest::qWaitForWindowExposed(messageBox)); // verify that all windows are visible - foreach (QWidget *w, qApp->topLevelWidgets()) - QVERIFY(w->isVisible()); + const auto &topLevels = QApplication::topLevelWidgets(); + QVERIFY(std::all_of(topLevels.cbegin(), topLevels.cend(), ::isVisible)); // flush event queue - qApp->processEvents(); + QCoreApplication::processEvents(); // close all windows - qApp->closeAllWindows(); + QApplication::closeAllWindows(); if (messageBox->standardButton(messageBox->clickedButton()) == QMessageBox::Cancel) event->ignore(); @@ -824,7 +807,7 @@ void tst_QApplication::closeAllWindows() QSKIP("PromptOnCloseWidget does not work on WinRT - QTBUG-68297"); #endif int argc = 0; - QApplication app(argc, 0); + QApplication app(argc, nullptr); // create some windows new QWidget; @@ -832,39 +815,39 @@ void tst_QApplication::closeAllWindows() new QWidget; // show all windows - foreach (QWidget *w, app.topLevelWidgets()) { + auto topLevels = QApplication::topLevelWidgets(); + for (QWidget *w : qAsConst(topLevels)) { w->show(); QVERIFY(QTest::qWaitForWindowExposed(w)); } // verify that they are visible - foreach (QWidget *w, app.topLevelWidgets()) - QVERIFY(w->isVisible()); + QVERIFY(std::all_of(topLevels.cbegin(), topLevels.cend(), isVisible)); // empty event queue - app.processEvents(); + QCoreApplication::processEvents(); // close all windows - app.closeAllWindows(); + QApplication::closeAllWindows(); // all windows should no longer be visible - foreach (QWidget *w, app.topLevelWidgets()) - QVERIFY(!w->isVisible()); + QVERIFY(std::all_of(topLevels.cbegin(), topLevels.cend(), [] (const QWidget *w) { return !w->isVisible(); })); // add a window that prompts the user when closed PromptOnCloseWidget *promptOnCloseWidget = new PromptOnCloseWidget; // show all windows - foreach (QWidget *w, app.topLevelWidgets()) { + topLevels = QApplication::topLevelWidgets(); + for (QWidget *w : qAsConst(topLevels)) { w->show(); QVERIFY(QTest::qWaitForWindowExposed(w)); } // close the last window to open the prompt (eventloop recurses) promptOnCloseWidget->close(); // all windows should not be visible, except the one that opened the prompt - foreach (QWidget *w, app.topLevelWidgets()) { + for (QWidget *w : qAsConst(topLevels)) { if (w == promptOnCloseWidget) QVERIFY(w->isVisible()); else QVERIFY(!w->isVisible()); } - qDeleteAll(app.topLevelWidgets()); + qDeleteAll(QApplication::topLevelWidgets()); } bool isPathListIncluded(const QStringList &l, const QStringList &r) @@ -888,7 +871,6 @@ bool isPathListIncluded(const QStringList &l, const QStringList &r) } #if QT_CONFIG(library) -#define QT_TST_QAPP_DEBUG void tst_QApplication::libraryPaths() { #ifndef BUILTIN_TESTDATA @@ -904,11 +886,13 @@ void tst_QApplication::libraryPaths() // creating QApplication adds the applicationDirPath to the libraryPath int argc = 1; QApplication app(argc, &argv0); - QString appDirPath = QDir(app.applicationDirPath()).canonicalPath(); + QString appDirPath = QDir(QCoreApplication::applicationDirPath()).canonicalPath(); QStringList actual = QApplication::libraryPaths(); actual.sort(); - QStringList expected = QSet<QString>::fromList((QStringList() << testDir << appDirPath)).toList(); + QStringList expected; + expected << testDir << appDirPath; + expected = QSet<QString>(expected.constBegin(), expected.constEnd()).values(); expected.sort(); QVERIFY2(isPathListIncluded(actual, expected), @@ -919,13 +903,15 @@ void tst_QApplication::libraryPaths() // creating QApplication adds the applicationDirPath and plugin install path to the libraryPath int argc = 1; QApplication app(argc, &argv0); - QString appDirPath = app.applicationDirPath(); + QString appDirPath = QCoreApplication::applicationDirPath(); QString installPathPlugins = QLibraryInfo::location(QLibraryInfo::PluginsPath); QStringList actual = QApplication::libraryPaths(); actual.sort(); - QStringList expected = QSet<QString>::fromList((QStringList() << installPathPlugins << appDirPath)).toList(); + QStringList expected; + expected << installPathPlugins << appDirPath; + expected = QSet<QString>(expected.constBegin(), expected.constEnd()).values(); expected.sort(); #ifdef Q_OS_WINRT @@ -942,9 +928,7 @@ void tst_QApplication::libraryPaths() "\nexpected:\n - " + testDir)); } { -#ifdef QT_TST_QAPP_DEBUG - qDebug() << "Initial library path:" << QApplication::libraryPaths(); -#endif + qCDebug(lcTests) << "Initial library path:" << QApplication::libraryPaths(); int count = QApplication::libraryPaths().count(); #if 0 @@ -953,10 +937,8 @@ void tst_QApplication::libraryPaths() #endif QString installPathPlugins = QLibraryInfo::location(QLibraryInfo::PluginsPath); QApplication::addLibraryPath(installPathPlugins); -#ifdef QT_TST_QAPP_DEBUG - qDebug() << "installPathPlugins" << installPathPlugins; - qDebug() << "After adding plugins path:" << QApplication::libraryPaths(); -#endif + qCDebug(lcTests) << "installPathPlugins" << installPathPlugins; + qCDebug(lcTests) << "After adding plugins path:" << QApplication::libraryPaths(); QCOMPARE(QApplication::libraryPaths().count(), count); QApplication::addLibraryPath(testDir); QCOMPARE(QApplication::libraryPaths().count(), count + 1); @@ -964,8 +946,8 @@ void tst_QApplication::libraryPaths() // creating QApplication adds the applicationDirPath to the libraryPath int argc = 1; QApplication app(argc, &argv0); - QString appDirPath = app.applicationDirPath(); - qDebug() << QApplication::libraryPaths(); + QString appDirPath = QCoreApplication::applicationDirPath(); + qCDebug(lcTests) << QApplication::libraryPaths(); // On Windows CE these are identical and might also be the case for other // systems too if (appDirPath != installPathPlugins) @@ -975,36 +957,28 @@ void tst_QApplication::libraryPaths() int argc = 1; QApplication app(argc, &argv0); -#ifdef QT_TST_QAPP_DEBUG - qDebug() << "Initial library path:" << app.libraryPaths(); -#endif - int count = app.libraryPaths().count(); + qCDebug(lcTests) << "Initial library path:" << QCoreApplication::libraryPaths(); + int count = QCoreApplication::libraryPaths().count(); QString installPathPlugins = QLibraryInfo::location(QLibraryInfo::PluginsPath); - app.addLibraryPath(installPathPlugins); -#ifdef QT_TST_QAPP_DEBUG - qDebug() << "installPathPlugins" << installPathPlugins; - qDebug() << "After adding plugins path:" << app.libraryPaths(); -#endif - QCOMPARE(app.libraryPaths().count(), count); - - QString appDirPath = app.applicationDirPath(); - - app.addLibraryPath(appDirPath); - app.addLibraryPath(appDirPath + "/.."); -#ifdef QT_TST_QAPP_DEBUG - qDebug() << "appDirPath" << appDirPath; - qDebug() << "After adding appDirPath && appDirPath + /..:" << app.libraryPaths(); -#endif - QCOMPARE(app.libraryPaths().count(), count + 1); -#ifdef Q_OS_MAC - app.addLibraryPath(appDirPath + "/../MacOS"); + QCoreApplication::addLibraryPath(installPathPlugins); + qCDebug(lcTests) << "installPathPlugins" << installPathPlugins; + qCDebug(lcTests) << "After adding plugins path:" << QCoreApplication::libraryPaths(); + QCOMPARE(QCoreApplication::libraryPaths().count(), count); + + QString appDirPath = QCoreApplication::applicationDirPath(); + + QCoreApplication::addLibraryPath(appDirPath); + QCoreApplication::addLibraryPath(appDirPath + "/.."); + qCDebug(lcTests) << "appDirPath" << appDirPath; + qCDebug(lcTests) << "After adding appDirPath && appDirPath + /..:" << QCoreApplication::libraryPaths(); + QCOMPARE(QCoreApplication::libraryPaths().count(), count + 1); +#ifdef Q_OS_MACOS + QCoreApplication::addLibraryPath(appDirPath + "/../MacOS"); #else - app.addLibraryPath(appDirPath + "/tmp/.."); -#endif -#ifdef QT_TST_QAPP_DEBUG - qDebug() << "After adding appDirPath + /tmp/..:" << app.libraryPaths(); + QCoreApplication::addLibraryPath(appDirPath + "/tmp/.."); #endif - QCOMPARE(app.libraryPaths().count(), count + 1); + qCDebug(lcTests) << "After adding appDirPath + /tmp/..:" << QCoreApplication::libraryPaths(); + QCOMPARE(QCoreApplication::libraryPaths().count(), count + 1); } } @@ -1013,14 +987,14 @@ void tst_QApplication::libraryPaths_qt_plugin_path() int argc = 1; QApplication app(argc, &argv0); - QString appDirPath = app.applicationDirPath(); + QString appDirPath = QCoreApplication::applicationDirPath(); // Our hook into libraryPaths() initialization: Set the QT_PLUGIN_PATH environment variable QString installPathPluginsDeCanon = appDirPath + QString::fromLatin1("/tmp/.."); QByteArray ascii = QFile::encodeName(installPathPluginsDeCanon); qputenv("QT_PLUGIN_PATH", ascii); - QVERIFY(!app.libraryPaths().contains(appDirPath + QString::fromLatin1("/tmp/.."))); + QVERIFY(!QCoreApplication::libraryPaths().contains(appDirPath + QString::fromLatin1("/tmp/.."))); } void tst_QApplication::libraryPaths_qt_plugin_path_2() @@ -1047,14 +1021,14 @@ void tst_QApplication::libraryPaths_qt_plugin_path_2() QStringList expected = QStringList() << QLibraryInfo::location(QLibraryInfo::PluginsPath) - << QDir(app.applicationDirPath()).canonicalPath() + << QDir(QCoreApplication::applicationDirPath()).canonicalPath() << QDir(QDir::fromNativeSeparators(QString::fromLatin1(validPath))).canonicalPath(); #ifdef Q_OS_WINRT QEXPECT_FAIL("", "On WinRT PluginsPath is outside of sandbox. QTBUG-68297", Abort); #endif - QVERIFY2(isPathListIncluded(app.libraryPaths(), expected), - qPrintable("actual:\n - " + app.libraryPaths().join("\n - ") + + QVERIFY2(isPathListIncluded(QCoreApplication::libraryPaths(), expected), + qPrintable("actual:\n - " + QCoreApplication::libraryPaths().join("\n - ") + "\nexpected:\n - " + expected.join("\n - "))); } @@ -1071,8 +1045,8 @@ void tst_QApplication::libraryPaths_qt_plugin_path_2() QStringList expected = QStringList() << QLibraryInfo::location(QLibraryInfo::PluginsPath) - << app.applicationDirPath(); - QVERIFY(isPathListIncluded(app.libraryPaths(), expected)); + << QCoreApplication::applicationDirPath(); + QVERIFY(isPathListIncluded(QCoreApplication::libraryPaths(), expected)); qputenv("QT_PLUGIN_PATH", QByteArray()); } @@ -1084,7 +1058,7 @@ class SendPostedEventsTester : public QObject Q_OBJECT public: QList<int> eventSpy; - bool event(QEvent *e); + bool event(QEvent *e) override; private slots: void doTest(); }; @@ -1105,7 +1079,7 @@ void SendPostedEventsTester::doTest() QEventLoop eventLoop; QMetaObject::invokeMethod(&eventLoop, "quit", Qt::QueuedConnection); eventLoop.exec(); - QVERIFY(p != 0); + QVERIFY(p != nullptr); QCOMPARE(eventSpy.count(), 2); QCOMPARE(eventSpy.at(0), int(QEvent::MetaCall)); @@ -1116,12 +1090,12 @@ void SendPostedEventsTester::doTest() void tst_QApplication::sendPostedEvents() { int argc = 0; - QApplication app(argc, 0); + QApplication app(argc, nullptr); SendPostedEventsTester *tester = new SendPostedEventsTester; QMetaObject::invokeMethod(tester, "doTest", Qt::QueuedConnection); QMetaObject::invokeMethod(&app, "quit", Qt::QueuedConnection); QPointer<SendPostedEventsTester> p = tester; - (void) app.exec(); + (void) QCoreApplication::exec(); QVERIFY(p.isNull()); } @@ -1129,7 +1103,7 @@ void tst_QApplication::thread() { QThread *currentThread = QThread::currentThread(); // no app, but still have a valid thread - QVERIFY(currentThread != 0); + QVERIFY(currentThread != nullptr); // the thread should be running and not finished QVERIFY(currentThread->isRunning()); @@ -1145,10 +1119,10 @@ void tst_QApplication::thread() { int argc = 0; - QApplication app(argc, 0); + QApplication app(argc, nullptr); // current thread still valid - QVERIFY(QThread::currentThread() != 0); + QVERIFY(QThread::currentThread() != nullptr); // thread should be the same as before QCOMPARE(QThread::currentThread(), currentThread); @@ -1163,7 +1137,7 @@ void tst_QApplication::thread() } // app dead, current thread still valid - QVERIFY(QThread::currentThread() != 0); + QVERIFY(QThread::currentThread() != nullptr); QCOMPARE(QThread::currentThread(), currentThread); // the thread should still be running and not finished @@ -1178,10 +1152,10 @@ void tst_QApplication::thread() // before { int argc = 0; - QApplication app(argc, 0); + QApplication app(argc, nullptr); // current thread still valid - QVERIFY(QThread::currentThread() != 0); + QVERIFY(QThread::currentThread() != nullptr); // thread should be the same as before QCOMPARE(QThread::currentThread(), currentThread); @@ -1200,7 +1174,7 @@ void tst_QApplication::thread() } // app dead, current thread still valid - QVERIFY(QThread::currentThread() != 0); + QVERIFY(QThread::currentThread() != nullptr); QCOMPARE(QThread::currentThread(), currentThread); // the thread should still be running and not finished @@ -1216,10 +1190,10 @@ class DeleteLaterWidget : public QWidget { Q_OBJECT public: - DeleteLaterWidget(QApplication *_app, QWidget *parent = 0) - : QWidget(parent) { app = _app; child_deleted = false; } + explicit DeleteLaterWidget(QApplication *_app, QWidget *parent = nullptr) + : QWidget(parent), app(_app) {} - bool child_deleted; + bool child_deleted = false; QApplication *app; public slots: @@ -1234,22 +1208,22 @@ void DeleteLaterWidget::runTest() QObject *stillAlive = this->findChild<QObject*>("deleteLater"); QWidget *w = new QWidget(this); - connect(w, SIGNAL(destroyed()), this, SLOT(childDeleted())); + connect(w, &QObject::destroyed, this, &DeleteLaterWidget::childDeleted); w->deleteLater(); QVERIFY(!child_deleted); QDialog dlg; - QTimer::singleShot(500, &dlg, SLOT(reject())); + QTimer::singleShot(500, &dlg, &QDialog::reject); dlg.exec(); QVERIFY(!child_deleted); - app->processEvents(); + QCoreApplication::processEvents(); QVERIFY(!child_deleted); - QTimer::singleShot(500, this, SLOT(checkDeleteLater())); + QTimer::singleShot(500, this, &DeleteLaterWidget::checkDeleteLater); - app->processEvents(); + QCoreApplication::processEvents(); QVERIFY(!stillAlive); // verify at the end to make test terminate } @@ -1267,11 +1241,11 @@ void tst_QApplication::testDeleteLater() QSKIP("This test fails and then hangs on OS X, see QTBUG-24318"); #endif int argc = 0; - QApplication app(argc, 0); - connect(&app, SIGNAL(lastWindowClosed()), &app, SLOT(quit())); + QApplication app(argc, nullptr); + connect(&app, &QApplication::lastWindowClosed, &app, &QCoreApplication::quit); DeleteLaterWidget *wgt = new DeleteLaterWidget(&app); - QTimer::singleShot(500, wgt, SLOT(runTest())); + QTimer::singleShot(500, wgt, &DeleteLaterWidget::runTest); QObject *object = new QObject(wgt); object->setObjectName("deleteLater"); @@ -1280,7 +1254,7 @@ void tst_QApplication::testDeleteLater() QObject *stillAlive = wgt->findChild<QObject*>("deleteLater"); QVERIFY(stillAlive); - app.exec(); + QCoreApplication::exec(); delete wgt; @@ -1301,7 +1275,7 @@ public slots: event loop */ QMetaObject::invokeMethod(this, "deleteLater", Qt::QueuedConnection); - QTimer::singleShot(1000, &eventLoop, SLOT(quit())); + QTimer::singleShot(1000, &eventLoop, &QEventLoop::quit); eventLoop.exec(); QVERIFY(p); } @@ -1325,7 +1299,7 @@ public slots: } void sendPostedEventsWithDeferredDelete() { - QApplication::sendPostedEvents(0, QEvent::DeferredDelete); + QApplication::sendPostedEvents(nullptr, QEvent::DeferredDelete); } void deleteLaterAndProcessEvents() @@ -1354,7 +1328,7 @@ public slots: QVERIFY(p); // however, it *will* work with this magic incantation - QApplication::sendPostedEvents(0, QEvent::DeferredDelete); + QApplication::sendPostedEvents(nullptr, QEvent::DeferredDelete); QVERIFY(!p); } }; @@ -1372,16 +1346,16 @@ void tst_QApplication::testDeleteLaterProcessEvents() delete object; { - QApplication app(argc, 0); + QApplication app(argc, nullptr); // If you call processEvents() with an event dispatcher present, but // outside any event loops, deferred deletes are not processed unless // sendPostedEvents(0, DeferredDelete) is called. object = new QObject; p = object; object->deleteLater(); - app.processEvents(); + QCoreApplication::processEvents(); QVERIFY(p); - QApplication::sendPostedEvents(0, QEvent::DeferredDelete); + QCoreApplication::sendPostedEvents(nullptr, QEvent::DeferredDelete); QVERIFY(!p); // If you call deleteLater() on an object when there is no parent @@ -1391,7 +1365,7 @@ void tst_QApplication::testDeleteLaterProcessEvents() p = object; object->deleteLater(); QEventLoop loop; - QTimer::singleShot(1000, &loop, SLOT(quit())); + QTimer::singleShot(1000, &loop, &QEventLoop::quit); loop.exec(); QVERIFY(!p); } @@ -1399,12 +1373,12 @@ void tst_QApplication::testDeleteLaterProcessEvents() // When an object is in an event loop, then calls deleteLater() and enters // an event loop recursively, it should not die until the parent event // loop continues. - QApplication app(argc, 0); + QApplication app(argc, nullptr); QEventLoop loop; EventLoopNester *nester = new EventLoopNester; p = nester; - QTimer::singleShot(3000, &loop, SLOT(quit())); - QTimer::singleShot(0, nester, SLOT(deleteLaterAndEnterLoop())); + QTimer::singleShot(3000, &loop, &QEventLoop::quit); + QTimer::singleShot(0, nester, &EventLoopNester::deleteLaterAndEnterLoop); loop.exec(); QVERIFY(!p); @@ -1414,12 +1388,12 @@ void tst_QApplication::testDeleteLaterProcessEvents() // When the event loop that calls deleteLater() is exited // immediately, the object should die when returning to the // parent event loop - QApplication app(argc, 0); + QApplication app(argc, nullptr); QEventLoop loop; EventLoopNester *nester = new EventLoopNester; p = nester; - QTimer::singleShot(3000, &loop, SLOT(quit())); - QTimer::singleShot(0, nester, SLOT(deleteLaterAndExitLoop())); + QTimer::singleShot(3000, &loop, &QEventLoop::quit); + QTimer::singleShot(0, nester, &EventLoopNester::deleteLaterAndExitLoop); loop.exec(); QVERIFY(!p); @@ -1429,12 +1403,12 @@ void tst_QApplication::testDeleteLaterProcessEvents() // when the event loop that calls deleteLater() also calls // processEvents() immediately afterwards, the object should // not die until the parent loop continues - QApplication app(argc, 0); + QApplication app(argc, nullptr); QEventLoop loop; EventLoopNester *nester = new EventLoopNester(); p = nester; - QTimer::singleShot(3000, &loop, SLOT(quit())); - QTimer::singleShot(0, nester, SLOT(deleteLaterAndProcessEvents())); + QTimer::singleShot(3000, &loop, &QEventLoop::quit); + QTimer::singleShot(0, nester, &EventLoopNester::deleteLaterAndProcessEvents); loop.exec(); QVERIFY(!p); @@ -1460,7 +1434,7 @@ void tst_QApplication::desktopSettingsAware() void tst_QApplication::setActiveWindow() { int argc = 0; - QApplication MyApp(argc, 0); + QApplication MyApp(argc, nullptr); QWidget* w = new QWidget; QVBoxLayout* layout = new QVBoxLayout(w); @@ -1472,7 +1446,7 @@ void tst_QApplication::setActiveWindow() layout->addWidget(pb2); pb2->setFocus(); - pb2->setParent(0); + pb2->setParent(nullptr); delete pb2; w->show(); @@ -1486,13 +1460,14 @@ void tst_QApplication::setActiveWindow() void tst_QApplication::focusChanged() { int argc = 0; - QApplication app(argc, 0); + QApplication app(argc, nullptr); - QSignalSpy spy(&app, SIGNAL(focusChanged(QWidget*,QWidget*))); - QWidget *now = 0; - QWidget *old = 0; + QSignalSpy spy(&app, QOverload<QWidget*,QWidget*>::of(&QApplication::focusChanged)); + QWidget *now = nullptr; + QWidget *old = nullptr; QWidget parent1; + parent1.setWindowTitle(QLatin1String(QTest::currentTestFunction()) + QLatin1Char('1')); QHBoxLayout hbox1(&parent1); QLabel lb1(&parent1); QLineEdit le1(&parent1); @@ -1543,6 +1518,7 @@ void tst_QApplication::focusChanged() spy.clear(); QWidget parent2; + parent2.setWindowTitle(QLatin1String(QTest::currentTestFunction()) + QLatin1Char('1')); QHBoxLayout hbox2(&parent2); QLabel lb2(&parent2); QLineEdit le2(&parent2); @@ -1561,9 +1537,9 @@ void tst_QApplication::focusChanged() QVERIFY(!old); spy.clear(); - QTestKeyEvent tab(QTest::Press, Qt::Key_Tab, 0, 0); - QTestKeyEvent backtab(QTest::Press, Qt::Key_Backtab, 0, 0); - QTestMouseEvent click(QTest::MouseClick, Qt::LeftButton, 0, QPoint(5, 5), 0); + QTestKeyEvent tab(QTest::Press, Qt::Key_Tab, Qt::KeyboardModifiers(), 0); + QTestKeyEvent backtab(QTest::Press, Qt::Key_Backtab, Qt::KeyboardModifiers(), 0); + QTestMouseEvent click(QTest::MouseClick, Qt::LeftButton, Qt::KeyboardModifiers(), QPoint(5, 5), 0); bool tabAllControls = true; #ifdef Q_OS_MAC @@ -1679,16 +1655,18 @@ void tst_QApplication::focusChanged() class LineEdit : public QLineEdit { public: - LineEdit(QWidget *parent = 0) : QLineEdit(parent) { } + using QLineEdit::QLineEdit; protected: - void focusOutEvent(QFocusEvent *e) { + void focusOutEvent(QFocusEvent *e) override + { QLineEdit::focusOutEvent(e); if (objectName() == "le1") setStyleSheet(""); } - void focusInEvent(QFocusEvent *e) { + void focusInEvent(QFocusEvent *e) override + { QLineEdit::focusInEvent(e); if (objectName() == "le2") setStyleSheet(""); @@ -1703,6 +1681,7 @@ void tst_QApplication::focusOut() // Tests the case where the style pointer changes when on focus in/out // (the above is the case when the stylesheet changes) QWidget w; + w.setWindowTitle(QLatin1String(QTest::currentTestFunction())); QLineEdit *le1 = new LineEdit(&w); le1->setObjectName("le1"); le1->setStyleSheet("background: #fee"); @@ -1726,6 +1705,7 @@ void tst_QApplication::focusMouseClick() QApplication app(argc, &argv0); QWidget w; + w.setWindowTitle(QLatin1String(QTest::currentTestFunction())); w.setFocusPolicy(Qt::StrongFocus); QWidget w2(&w); w2.setFocusPolicy(Qt::TabFocus); @@ -1768,7 +1748,7 @@ void tst_QApplication::execAfterExit() QMetaObject::invokeMethod(&app, "quit", Qt::QueuedConnection); // this should be ignored, as exec() will reset the exitCode QApplication::exit(1); - int exitCode = app.exec(); + int exitCode = QCoreApplication::exec(); QCOMPARE(exitCode, 0); // the quitNow flag should have been reset, so we can spin an @@ -1795,15 +1775,15 @@ void tst_QApplication::style() { QApplication app(argc, &argv0); - QPointer<QStyle> style = app.style(); - app.setStyle(QStyleFactory::create(QLatin1String("Windows"))); + QPointer<QStyle> style = QApplication::style(); + QApplication::setStyle(QStyleFactory::create(QLatin1String("Windows"))); QVERIFY(style.isNull()); } QApplication app(argc, &argv0); // qApp style can never be 0 - QVERIFY(QApplication::style() != 0); + QVERIFY(QApplication::style() != nullptr); } void tst_QApplication::allWidgets() @@ -1811,11 +1791,9 @@ void tst_QApplication::allWidgets() int argc = 1; QApplication app(argc, &argv0); QWidget *w = new QWidget; - QVERIFY(app.allWidgets().contains(w)); // uncreate widget test - QVERIFY(app.allWidgets().contains(w)); // created widget test + QVERIFY(QApplication::allWidgets().contains(w)); // uncreate widget test delete w; - w = 0; - QVERIFY(!app.allWidgets().contains(w)); // removal test + QVERIFY(!QApplication::allWidgets().contains(w)); // removal test } void tst_QApplication::topLevelWidgets() @@ -1825,16 +1803,15 @@ void tst_QApplication::topLevelWidgets() QWidget *w = new QWidget; w->show(); #ifndef QT_NO_CLIPBOARD - QClipboard *clipboard = QApplication::clipboard(); - QString originalText = clipboard->text(); - clipboard->setText(QString("newText")); + QClipboard *clipboard = QGuiApplication::clipboard(); + clipboard->setText(QLatin1String("newText")); #endif - app.processEvents(); + QCoreApplication::processEvents(); QVERIFY(QApplication::topLevelWidgets().contains(w)); QCOMPARE(QApplication::topLevelWidgets().count(), 1); delete w; - w = 0; - app.processEvents(); + w = nullptr; + QCoreApplication::processEvents(); QCOMPARE(QApplication::topLevelWidgets().count(), 0); } @@ -1854,7 +1831,7 @@ void tst_QApplication::setAttribute() w = new QWidget; QVERIFY(w->testAttribute(Qt::WA_WState_Created)); QWidget *w2 = new QWidget(w); - w2->setParent(0); + w2->setParent(nullptr); QVERIFY(w2->testAttribute(Qt::WA_WState_Created)); delete w; delete w2; @@ -1871,10 +1848,10 @@ class TouchEventPropagationTestWidget : public QWidget Q_OBJECT public: - bool seenTouchEvent, acceptTouchEvent, seenMouseEvent, acceptMouseEvent; + bool seenTouchEvent = false, acceptTouchEvent = false, seenMouseEvent = false, acceptMouseEvent = false; + - TouchEventPropagationTestWidget(QWidget *parent = 0) - : QWidget(parent), seenTouchEvent(false), acceptTouchEvent(false), seenMouseEvent(false), acceptMouseEvent(false) + explicit TouchEventPropagationTestWidget(QWidget *parent = nullptr) : QWidget(parent) { setAttribute(Qt::WA_TouchPadAcceptSingleTouchEvents); } @@ -1884,7 +1861,7 @@ public: seenTouchEvent = acceptTouchEvent = seenMouseEvent = acceptMouseEvent = false; } - bool event(QEvent *event) + bool event(QEvent *event) override { switch (event->type()) { case QEvent::MouseButtonPress: @@ -1928,11 +1905,13 @@ void tst_QApplication::touchEventPropagation() { // touch event behavior on a window TouchEventPropagationTestWidget window; + window.setWindowTitle(QLatin1String(QTest::currentTestFunction())); window.resize(200, 200); window.setObjectName("1. window"); window.show(); // Must have an explicitly specified QWindow for handleTouchEvent, // passing 0 would result in using topLevelAt() which is not ok in this case // as the screen position in the point is bogus. + auto handle = window.windowHandle(); QVERIFY(QTest::qWaitForWindowExposed(&window)); // QPA always takes screen positions and since we map the TouchPoint back to QPA's structure first, // we must ensure there is a screen position in the TouchPoint that maps to a local 0, 0. @@ -1941,42 +1920,42 @@ void tst_QApplication::touchEventPropagation() pressedTouchPoints[0].setScreenPos(deviceGlobalPos); releasedTouchPoints[0].setScreenPos(deviceGlobalPos); - QWindowSystemInterface::handleTouchEvent(window.windowHandle(), + QWindowSystemInterface::handleTouchEvent(handle, 0, device, - touchPointList(pressedTouchPoints)); - QWindowSystemInterface::handleTouchEvent(window.windowHandle(), + QWindowSystemInterfacePrivate::toNativeTouchPoints(pressedTouchPoints, handle)); + QWindowSystemInterface::handleTouchEvent(handle, 0, device, - touchPointList(releasedTouchPoints)); + QWindowSystemInterfacePrivate::toNativeTouchPoints(releasedTouchPoints, handle)); QCoreApplication::processEvents(); QVERIFY(!window.seenTouchEvent); QVERIFY(window.seenMouseEvent); // QApplication may transform ignored touch events in mouse events window.reset(); window.setAttribute(Qt::WA_AcceptTouchEvents); - QWindowSystemInterface::handleTouchEvent(window.windowHandle(), + QWindowSystemInterface::handleTouchEvent(handle, 0, device, - touchPointList(pressedTouchPoints)); - QWindowSystemInterface::handleTouchEvent(window.windowHandle(), + QWindowSystemInterfacePrivate::toNativeTouchPoints(pressedTouchPoints, handle)); + QWindowSystemInterface::handleTouchEvent(handle, 0, device, - touchPointList(releasedTouchPoints)); + QWindowSystemInterfacePrivate::toNativeTouchPoints(releasedTouchPoints, handle)); QCoreApplication::processEvents(); QVERIFY(window.seenTouchEvent); QVERIFY(window.seenMouseEvent); window.reset(); window.acceptTouchEvent = true; - QWindowSystemInterface::handleTouchEvent(window.windowHandle(), + QWindowSystemInterface::handleTouchEvent(handle, 0, device, - touchPointList(pressedTouchPoints)); - QWindowSystemInterface::handleTouchEvent(window.windowHandle(), + QWindowSystemInterfacePrivate::toNativeTouchPoints(pressedTouchPoints, handle)); + QWindowSystemInterface::handleTouchEvent(handle, 0, device, - touchPointList(releasedTouchPoints)); + QWindowSystemInterfacePrivate::toNativeTouchPoints(releasedTouchPoints, handle)); QCoreApplication::processEvents(); QVERIFY(window.seenTouchEvent); QVERIFY(!window.seenMouseEvent); @@ -1985,26 +1964,28 @@ void tst_QApplication::touchEventPropagation() { // touch event behavior on a window with a child widget TouchEventPropagationTestWidget window; + window.setWindowTitle(QLatin1String(QTest::currentTestFunction())); window.resize(200, 200); window.setObjectName("2. window"); TouchEventPropagationTestWidget widget(&window); widget.resize(200, 200); widget.setObjectName("2. widget"); window.show(); + auto handle = window.windowHandle(); QVERIFY(QTest::qWaitForWindowExposed(&window)); const QPoint deviceGlobalPos = QHighDpi::toNativePixels(window.mapToGlobal(QPoint(50, 150)), window.windowHandle()->screen()); pressedTouchPoints[0].setScreenPos(deviceGlobalPos); releasedTouchPoints[0].setScreenPos(deviceGlobalPos); - QWindowSystemInterface::handleTouchEvent(window.windowHandle(), + QWindowSystemInterface::handleTouchEvent(handle, 0, device, - touchPointList(pressedTouchPoints)); - QWindowSystemInterface::handleTouchEvent(window.windowHandle(), + QWindowSystemInterfacePrivate::toNativeTouchPoints(pressedTouchPoints, handle)); + QWindowSystemInterface::handleTouchEvent(handle, 0, device, - touchPointList(releasedTouchPoints)); + QWindowSystemInterfacePrivate::toNativeTouchPoints(releasedTouchPoints, handle)); QTRY_VERIFY(widget.seenMouseEvent); QVERIFY(!widget.seenTouchEvent); QVERIFY(!window.seenTouchEvent); @@ -2013,14 +1994,14 @@ void tst_QApplication::touchEventPropagation() window.reset(); widget.reset(); widget.setAttribute(Qt::WA_AcceptTouchEvents); - QWindowSystemInterface::handleTouchEvent(window.windowHandle(), + QWindowSystemInterface::handleTouchEvent(handle, 0, device, - touchPointList(pressedTouchPoints)); - QWindowSystemInterface::handleTouchEvent(window.windowHandle(), + QWindowSystemInterfacePrivate::toNativeTouchPoints(pressedTouchPoints, handle)); + QWindowSystemInterface::handleTouchEvent(handle, 0, device, - touchPointList(releasedTouchPoints)); + QWindowSystemInterfacePrivate::toNativeTouchPoints(releasedTouchPoints, handle)); QCoreApplication::processEvents(); QVERIFY(widget.seenTouchEvent); QVERIFY(widget.seenMouseEvent); @@ -2030,14 +2011,14 @@ void tst_QApplication::touchEventPropagation() window.reset(); widget.reset(); widget.acceptMouseEvent = true; - QWindowSystemInterface::handleTouchEvent(window.windowHandle(), + QWindowSystemInterface::handleTouchEvent(handle, 0, device, - touchPointList(pressedTouchPoints)); - QWindowSystemInterface::handleTouchEvent(window.windowHandle(), + QWindowSystemInterfacePrivate::toNativeTouchPoints(pressedTouchPoints, handle)); + QWindowSystemInterface::handleTouchEvent(handle, 0, device, - touchPointList(releasedTouchPoints)); + QWindowSystemInterfacePrivate::toNativeTouchPoints(releasedTouchPoints, handle)); QCoreApplication::processEvents(); QVERIFY(widget.seenTouchEvent); QVERIFY(widget.seenMouseEvent); @@ -2047,14 +2028,14 @@ void tst_QApplication::touchEventPropagation() window.reset(); widget.reset(); widget.acceptTouchEvent = true; - QWindowSystemInterface::handleTouchEvent(window.windowHandle(), + QWindowSystemInterface::handleTouchEvent(handle, 0, device, - touchPointList(pressedTouchPoints)); - QWindowSystemInterface::handleTouchEvent(window.windowHandle(), + QWindowSystemInterfacePrivate::toNativeTouchPoints(pressedTouchPoints, handle)); + QWindowSystemInterface::handleTouchEvent(handle, 0, device, - touchPointList(releasedTouchPoints)); + QWindowSystemInterfacePrivate::toNativeTouchPoints(releasedTouchPoints, handle)); QCoreApplication::processEvents(); QVERIFY(widget.seenTouchEvent); QVERIFY(!widget.seenMouseEvent); @@ -2065,14 +2046,14 @@ void tst_QApplication::touchEventPropagation() widget.reset(); widget.setAttribute(Qt::WA_AcceptTouchEvents, false); window.setAttribute(Qt::WA_AcceptTouchEvents); - QWindowSystemInterface::handleTouchEvent(window.windowHandle(), + QWindowSystemInterface::handleTouchEvent(handle, 0, device, - touchPointList(pressedTouchPoints)); - QWindowSystemInterface::handleTouchEvent(window.windowHandle(), + QWindowSystemInterfacePrivate::toNativeTouchPoints(pressedTouchPoints, handle)); + QWindowSystemInterface::handleTouchEvent(handle, 0, device, - touchPointList(releasedTouchPoints)); + QWindowSystemInterfacePrivate::toNativeTouchPoints(releasedTouchPoints, handle)); QCoreApplication::processEvents(); QVERIFY(!widget.seenTouchEvent); QVERIFY(widget.seenMouseEvent); @@ -2082,14 +2063,14 @@ void tst_QApplication::touchEventPropagation() window.reset(); widget.reset(); window.acceptTouchEvent = true; - QWindowSystemInterface::handleTouchEvent(window.windowHandle(), + QWindowSystemInterface::handleTouchEvent(handle, 0, device, - touchPointList(pressedTouchPoints)); - QWindowSystemInterface::handleTouchEvent(window.windowHandle(), + QWindowSystemInterfacePrivate::toNativeTouchPoints(pressedTouchPoints, handle)); + QWindowSystemInterface::handleTouchEvent(handle, 0, device, - touchPointList(releasedTouchPoints)); + QWindowSystemInterfacePrivate::toNativeTouchPoints(releasedTouchPoints, handle)); QCoreApplication::processEvents(); QVERIFY(!widget.seenTouchEvent); QVERIFY(!widget.seenMouseEvent); @@ -2100,14 +2081,14 @@ void tst_QApplication::touchEventPropagation() widget.reset(); widget.acceptMouseEvent = true; // doesn't matter, touch events are propagated first window.acceptTouchEvent = true; - QWindowSystemInterface::handleTouchEvent(window.windowHandle(), + QWindowSystemInterface::handleTouchEvent(handle, 0, device, - touchPointList(pressedTouchPoints)); - QWindowSystemInterface::handleTouchEvent(window.windowHandle(), + QWindowSystemInterfacePrivate::toNativeTouchPoints(pressedTouchPoints, handle)); + QWindowSystemInterface::handleTouchEvent(handle, 0, device, - touchPointList(releasedTouchPoints)); + QWindowSystemInterfacePrivate::toNativeTouchPoints(releasedTouchPoints, handle)); QCoreApplication::processEvents(); QVERIFY(!widget.seenTouchEvent); QVERIFY(!widget.seenMouseEvent); @@ -2135,37 +2116,33 @@ class NoQuitOnHideWidget : public QWidget { Q_OBJECT public: - explicit NoQuitOnHideWidget(QWidget *parent = 0) + explicit NoQuitOnHideWidget(QWidget *parent = nullptr) : QWidget(parent) { - QTimer::singleShot(0, this, SLOT(hide())); - QTimer::singleShot(500, this, SLOT(exitApp())); - } - -private slots: - void exitApp() { - qApp->exit(1); + QTimer::singleShot(0, this, &QWidget::hide); + QTimer::singleShot(500, this, [] () { QCoreApplication::exit(1); }); } }; void tst_QApplication::noQuitOnHide() { int argc = 0; - QApplication app(argc, 0); + QApplication app(argc, nullptr); NoQuitOnHideWidget window1; + window1.setWindowTitle(QLatin1String(QTest::currentTestFunction())); window1.show(); - QCOMPARE(app.exec(), 1); + QCOMPARE(QCoreApplication::exec(), 1); } class ShowCloseShowWidget : public QWidget { Q_OBJECT public: - ShowCloseShowWidget(bool showAgain, QWidget *parent = 0) - : QWidget(parent), showAgain(showAgain) + explicit ShowCloseShowWidget(bool showAgain, QWidget *parent = nullptr) + : QWidget(parent), showAgain(showAgain) { - QTimer::singleShot(0, this, SLOT(doClose())); - QTimer::singleShot(500, this, SLOT(exitApp())); + QTimer::singleShot(0, this, &ShowCloseShowWidget::doClose); + QTimer::singleShot(500, this, [] () { QCoreApplication::exit(1); }); } private slots: @@ -2175,25 +2152,23 @@ private slots: show(); } - void exitApp() { - qApp->exit(1); - } - private: - bool showAgain; + const bool showAgain; }; void tst_QApplication::abortQuitOnShow() { int argc = 0; - QApplication app(argc, 0); + QApplication app(argc, nullptr); ShowCloseShowWidget window1(false); + window1.setWindowTitle(QLatin1String(QTest::currentTestFunction())); window1.show(); - QCOMPARE(app.exec(), 0); + QCOMPARE(QCoreApplication::exec(), 0); ShowCloseShowWidget window2(true); + window2.setWindowTitle(QLatin1String(QTest::currentTestFunction())); window2.show(); - QCOMPARE(app.exec(), 1); + QCOMPARE(QCoreApplication::exec(), 1); } // Test that static functions do not crash if there is no application instance. @@ -2229,7 +2204,7 @@ void tst_QApplication::settableStyleHints() int argc = 0; QScopedPointer<QApplication> app; if (appInstance) - app.reset(new QApplication(argc, 0)); + app.reset(new QApplication(argc, nullptr)); QApplication::setCursorFlashTime(437); QCOMPARE(QApplication::cursorFlashTime(), 437); @@ -2295,12 +2270,6 @@ void tst_QApplication::globalStaticObjectDestruction() #endif } -void tst_QApplication::quitApplication() -{ - quitApplicationTriggered = true; - qApp->quit(); -} - //QTEST_APPLESS_MAIN(tst_QApplication) int main(int argc, char *argv[]) { diff --git a/tests/auto/widgets/kernel/qboxlayout/tst_qboxlayout.cpp b/tests/auto/widgets/kernel/qboxlayout/tst_qboxlayout.cpp index fa9769a002..8dd9d7c428 100644 --- a/tests/auto/widgets/kernel/qboxlayout/tst_qboxlayout.cpp +++ b/tests/auto/widgets/kernel/qboxlayout/tst_qboxlayout.cpp @@ -571,6 +571,10 @@ void tst_QBoxLayout::replaceWidget() QCOMPARE(boxLayout->indexOf(replaceFrom), 1); QCOMPARE(boxLayout->indexOf(replaceTo), -1); + QCOMPARE(boxLayout->count(), 3); + boxLayout->replaceWidget(replaceFrom, replaceFrom); + QCOMPARE(boxLayout->count(), 3); + delete boxLayout->replaceWidget(replaceFrom, replaceTo); QCOMPARE(boxLayout->indexOf(replaceFrom), -1); diff --git a/tests/auto/widgets/kernel/qwidget/BLACKLIST b/tests/auto/widgets/kernel/qwidget/BLACKLIST index 3287d67875..03bec4286b 100644 --- a/tests/auto/widgets/kernel/qwidget/BLACKLIST +++ b/tests/auto/widgets/kernel/qwidget/BLACKLIST @@ -46,3 +46,6 @@ osx osx-10.12 ci [multipleToplevelFocusCheck] linux +[windowState] +# QTBUG-75270 +winrt diff --git a/tests/auto/widgets/kernel/qwidget/qwidget.pro b/tests/auto/widgets/kernel/qwidget/qwidget.pro index c1908af2a2..d3fbd6d0d9 100644 --- a/tests/auto/widgets/kernel/qwidget/qwidget.pro +++ b/tests/auto/widgets/kernel/qwidget/qwidget.pro @@ -16,4 +16,4 @@ mac { OBJECTIVE_SOURCES += tst_qwidget_mac_helpers.mm } -win32:!winrt: LIBS += -luser32 -lgdi32 +win32:!winrt: QMAKE_USE += user32 gdi32 diff --git a/tests/auto/widgets/kernel/qwidget/tst_qwidget.cpp b/tests/auto/widgets/kernel/qwidget/tst_qwidget.cpp index 9e30f17fa9..7203e7b170 100644 --- a/tests/auto/widgets/kernel/qwidget/tst_qwidget.cpp +++ b/tests/auto/widgets/kernel/qwidget/tst_qwidget.cpp @@ -83,14 +83,16 @@ using namespace QTestPrivate; #include <qpa/qplatformnativeinterface.h> #include <qpa/qplatformintegration.h> +#include <algorithm> + static HWND winHandleOf(const QWidget *w) { static QPlatformNativeInterface *nativeInterface - = QGuiApplicationPrivate::instance()->platformIntegration()->nativeInterface(); + = QGuiApplicationPrivate::platformIntegration()->nativeInterface(); if (void *handle = nativeInterface->nativeResourceForWindow("handle", w->window()->windowHandle())) return reinterpret_cast<HWND>(handle); qWarning() << "Cannot obtain native handle for " << w; - return 0; + return nullptr; } # define Q_CHECK_PAINTEVENTS \ @@ -434,9 +436,9 @@ void tst_QWidget::getSetCheck() QScopedPointer<QStyle> var1(QStyleFactory::create(QLatin1String("Windows"))); obj1.setStyle(var1.data()); QCOMPARE(static_cast<QStyle *>(var1.data()), obj1.style()); - obj1.setStyle((QStyle *)0); + obj1.setStyle(nullptr); QVERIFY(var1.data() != obj1.style()); - QVERIFY(0 != obj1.style()); // style can never be 0 for a widget + QVERIFY(obj1.style() != nullptr); // style can never be 0 for a widget // int QWidget::minimumWidth() // void QWidget::setMinimumWidth(int) @@ -512,7 +514,7 @@ void tst_QWidget::getSetCheck() // void QWidget::setWindowOpacity(qreal) obj1.setWindowOpacity(0.0); QCOMPARE(0.0, obj1.windowOpacity()); - obj1.setWindowOpacity(1.1f); + obj1.setWindowOpacity(1.1); QCOMPARE(1.0, obj1.windowOpacity()); // 1.0 is the fullest opacity possible // QWidget * QWidget::focusProxy() @@ -521,16 +523,16 @@ void tst_QWidget::getSetCheck() QScopedPointer<QWidget> var9(new QWidget()); obj1.setFocusProxy(var9.data()); QCOMPARE(var9.data(), obj1.focusProxy()); - obj1.setFocusProxy((QWidget *)0); - QCOMPARE((QWidget *)0, obj1.focusProxy()); + obj1.setFocusProxy(nullptr); + QCOMPARE(nullptr, obj1.focusProxy()); } // const QRect & QWidget::geometry() // void QWidget::setGeometry(const QRect &) - qApp->processEvents(); + QCoreApplication::processEvents(); QRect var10(10, 10, 100, 100); obj1.setGeometry(var10); - qApp->processEvents(); + QCoreApplication::processEvents(); qDebug() << obj1.geometry(); QCOMPARE(var10, obj1.geometry()); obj1.setGeometry(QRect(0,0,0,0)); @@ -542,10 +544,10 @@ void tst_QWidget::getSetCheck() QBoxLayout *var11 = new QBoxLayout(QBoxLayout::LeftToRight); obj1.setLayout(var11); QCOMPARE(static_cast<QLayout *>(var11), obj1.layout()); - obj1.setLayout((QLayout *)0); + obj1.setLayout(nullptr); QCOMPARE(static_cast<QLayout *>(var11), obj1.layout()); // You cannot set a 0-pointer layout, that keeps the current delete var11; // This will remove the layout from the widget - QCOMPARE((QLayout *)0, obj1.layout()); + QCOMPARE(nullptr, obj1.layout()); // bool QWidget::acceptDrops() // void QWidget::setAcceptDrops(bool) @@ -565,7 +567,7 @@ void tst_QWidget::getSetCheck() #if defined (Q_OS_WIN) && !defined(Q_OS_WINRT) obj1.setWindowFlags(Qt::FramelessWindowHint | Qt::WindowSystemMenuHint); const HWND handle = reinterpret_cast<HWND>(obj1.winId()); // explicitly create window handle - QVERIFY(GetWindowLong(handle, GWL_STYLE) & WS_POPUP); + QVERIFY(GetWindowLong(handle, GWL_STYLE) & LONG(WS_POPUP)); #endif } @@ -580,12 +582,12 @@ tst_QWidget::tst_QWidget() QFont font; font.setBold(true); font.setPointSize(42); - qApp->setFont(font, "QPropagationTestWidget"); + QApplication::setFont(font, "QPropagationTestWidget"); QPalette palette; palette.setColor(QPalette::ToolTipBase, QColor(12, 13, 14)); palette.setColor(QPalette::Text, QColor(21, 22, 23)); - qApp->setPalette(palette, "QPropagationTestWidget"); + QApplication::setPalette(palette, "QPropagationTestWidget"); } tst_QWidget::~tst_QWidget() @@ -594,16 +596,6 @@ tst_QWidget::~tst_QWidget() setWindowsAnimationsEnabled(m_windowsAnimationsEnabled); } -class BezierViewer : public QWidget { -public: - explicit BezierViewer(QWidget* parent = 0); - void paintEvent( QPaintEvent* ); - void setPoints( const QPolygonF& poly ); -private: - QPolygonF points; - -}; - void tst_QWidget::initTestCase() { // Size of reference widget, 200 for < 2000, scale up for larger screens @@ -730,9 +722,7 @@ class QPropagationTestWidget : public QWidget { Q_OBJECT public: - QPropagationTestWidget(QWidget *parent = 0) - : QWidget(parent) - { } + using QWidget::QWidget; }; void tst_QWidget::fontPropagation2() @@ -741,7 +731,7 @@ void tst_QWidget::fontPropagation2() // QFont font; // font.setBold(true); // font.setPointSize(42); - // qApp->setFont(font, "QPropagationTestWidget"); + // QApplication::setFont(font, "QPropagationTestWidget"); QScopedPointer<QWidget> root(new QWidget); root->setObjectName(QLatin1String("fontPropagation2")); @@ -798,7 +788,7 @@ void tst_QWidget::fontPropagation2() QFont italicSizeFont; italicSizeFont.setItalic(true); italicSizeFont.setPointSize(33); - qApp->setFont(italicSizeFont, "QPropagationTestWidget"); + QApplication::setFont(italicSizeFont, "QPropagationTestWidget"); // Check that this propagates correctly. QCOMPARE(root->font(), QApplication::font()); @@ -951,7 +941,7 @@ void tst_QWidget::palettePropagation2() // should still be ignored. The previous ToolTipBase setting is gone. QPalette buttonPalette; buttonPalette.setColor(QPalette::ToolTipText, sysPalButton); - qApp->setPalette(buttonPalette, "QPropagationTestWidget"); + QApplication::setPalette(buttonPalette, "QPropagationTestWidget"); // Check that the above settings propagate correctly. QCOMPARE(root->palette(), appPal); @@ -1138,7 +1128,7 @@ void tst_QWidget::isEnabledTo() QScopedPointer<QMainWindow> childDialog(new QMainWindow(&testWidget)); testWidget.setEnabled(false); QVERIFY(!childDialog->isEnabled()); - QVERIFY(childDialog->isEnabledTo(0)); + QVERIFY(childDialog->isEnabledTo(nullptr)); } void tst_QWidget::visible() @@ -1583,8 +1573,8 @@ void tst_QWidget::focusChainOnReparent() QWidget *expectedOriginalChain[8] = {&window, child1, child2, child3, child21, child22, child4, &window}; QWidget *w = &window; - for (int i = 0; i <8; ++i) { - QCOMPARE(w, expectedOriginalChain[i]); + for (auto expectedOriginal : expectedOriginalChain) { + QCOMPARE(w, expectedOriginal); w = w->nextInFocusChain(); } for (int i = 7; i >= 0; --i) { @@ -1597,8 +1587,8 @@ void tst_QWidget::focusChainOnReparent() QWidget *expectedNewChain[5] = {&window2, child2, child21, child22, &window2}; w = &window2; - for (int i = 0; i <5; ++i) { - QCOMPARE(w, expectedNewChain[i]); + for (auto expectedNew : expectedNewChain) { + QCOMPARE(w, expectedNew); w = w->nextInFocusChain(); } for (int i = 4; i >= 0; --i) { @@ -1608,8 +1598,8 @@ void tst_QWidget::focusChainOnReparent() QWidget *expectedOldChain[5] = {&window, child1, child3, child4, &window}; w = &window; - for (int i = 0; i <5; ++i) { - QCOMPARE(w, expectedOldChain[i]); + for (auto expectedOld : expectedOldChain) { + QCOMPARE(w, expectedOld); w = w->nextInFocusChain(); } for (int i = 4; i >= 0; --i) { @@ -1633,7 +1623,7 @@ void tst_QWidget::focusChainOnHide() QWidget::setTabOrder(child, parent.data()); parent->show(); - qApp->setActiveWindow(parent->window()); + QApplication::setActiveWindow(parent->window()); child->activateWindow(); child->setFocus(); @@ -1641,7 +1631,7 @@ void tst_QWidget::focusChainOnHide() child->hide(); QTRY_VERIFY(parent->hasFocus()); - QCOMPARE(parent.data(), qApp->focusWidget()); + QCOMPARE(parent.data(), QApplication::focusWidget()); } class Container : public QWidget @@ -1669,7 +1659,7 @@ public: class Composite : public QFrame { public: - Composite(QWidget* parent = 0, const QString &name = 0) + explicit Composite(QWidget *parent = nullptr, const QString &name = QString()) : QFrame(parent) { setObjectName(name); @@ -1708,9 +1698,10 @@ void tst_QWidget::defaultTabOrder() QLineEdit *lastEdit = new QLineEdit(); container.box->addWidget(lastEdit); + container.setWindowTitle(QLatin1String(QTest::currentTestFunction())); container.show(); container.activateWindow(); - qApp->setActiveWindow(&container); + QApplication::setActiveWindow(&container); QVERIFY(QTest::qWaitForWindowActive(&container)); QTRY_VERIFY(firstEdit->hasFocus()); @@ -1748,6 +1739,7 @@ void tst_QWidget::reverseTabOrder() { const int compositeCount = 2; Container container; + container.setWindowTitle(QLatin1String(QTest::currentTestFunction())); Composite* composite[compositeCount]; QLineEdit *firstEdit = new QLineEdit(); @@ -1767,7 +1759,7 @@ void tst_QWidget::reverseTabOrder() container.show(); container.activateWindow(); - qApp->setActiveWindow(&container); + QApplication::setActiveWindow(&container); QVERIFY(QTest::qWaitForWindowActive(&container)); QTRY_VERIFY(firstEdit->hasFocus()); @@ -1806,6 +1798,7 @@ void tst_QWidget::tabOrderWithProxy() { const int compositeCount = 2; Container container; + container.setWindowTitle(QLatin1String(QTest::currentTestFunction())); Composite* composite[compositeCount]; QLineEdit *firstEdit = new QLineEdit(); @@ -1825,7 +1818,7 @@ void tst_QWidget::tabOrderWithProxy() container.show(); container.activateWindow(); - qApp->setActiveWindow(&container); + QApplication::setActiveWindow(&container); QVERIFY(QTest::qWaitForWindowActive(&container)); QTRY_VERIFY(firstEdit->hasFocus()); @@ -1863,13 +1856,14 @@ void tst_QWidget::tabOrderWithCompoundWidgets() { const int compositeCount = 4; Container container; + container.setWindowTitle(QLatin1String(QTest::currentTestFunction())); Composite *composite[compositeCount]; QLineEdit *firstEdit = new QLineEdit(); container.box->addWidget(firstEdit); for (int i = 0; i < compositeCount; i++) { - composite[i] = new Composite(0, QStringLiteral("Composite: ") + QString::number(i)); + composite[i] = new Composite(nullptr, QStringLiteral("Composite: ") + QString::number(i)); container.box->addWidget(composite[i]); // Let the composite handle focus, and set a child as focus proxy (use the second child, just @@ -1895,7 +1889,7 @@ void tst_QWidget::tabOrderWithCompoundWidgets() container.show(); container.activateWindow(); - qApp->setActiveWindow(&container); + QApplication::setActiveWindow(&container); QVERIFY(QTest::qWaitForWindowActive(&container)); lastEdit->setFocus(); @@ -2308,26 +2302,27 @@ void tst_QWidget::showFullScreen() class ResizeWidget : public QWidget { public: - ResizeWidget(QWidget *p = 0) : QWidget(p) + explicit ResizeWidget(QWidget *p = nullptr) : QWidget(p) { setObjectName(QLatin1String("ResizeWidget")); setWindowTitle(objectName()); - m_resizeEventCount = 0; } protected: - void resizeEvent(QResizeEvent *e){ + void resizeEvent(QResizeEvent *e) override + { QCOMPARE(size(), e->size()); ++m_resizeEventCount; } public: - int m_resizeEventCount; + int m_resizeEventCount = 0; }; void tst_QWidget::resizeEvent() { { QWidget wParent; + wParent.setWindowTitle(QLatin1String(QTest::currentTestFunction())); wParent.resize(200, 200); ResizeWidget wChild(&wParent); wParent.show(); @@ -2345,6 +2340,7 @@ void tst_QWidget::resizeEvent() { ResizeWidget wTopLevel; + wTopLevel.setWindowTitle(QLatin1String(QTest::currentTestFunction())); wTopLevel.resize(200, 200); wTopLevel.show(); QVERIFY(QTest::qWaitForWindowExposed(&wTopLevel)); @@ -2372,6 +2368,7 @@ void tst_QWidget::showMinimized() } QWidget plain; + plain.setWindowTitle(QLatin1String(QTest::currentTestFunction())); plain.move(100, 100); plain.resize(200, 200); QPoint pos = plain.pos(); @@ -2426,17 +2423,18 @@ void tst_QWidget::showMinimizedKeepsFocus() //here we test that minimizing a widget and restoring it doesn't change the focus inside of it { QWidget window; + window.setWindowTitle(QLatin1String(QTest::currentTestFunction())); window.resize(200, 200); QWidget child1(&window), child2(&window); child1.setFocusPolicy(Qt::StrongFocus); child2.setFocusPolicy(Qt::StrongFocus); window.show(); - qApp->setActiveWindow(&window); + QApplication::setActiveWindow(&window); QVERIFY(QTest::qWaitForWindowActive(&window)); child2.setFocus(); QTRY_COMPARE(window.focusWidget(), &child2); - QTRY_COMPARE(qApp->focusWidget(), &child2); + QTRY_COMPARE(QApplication::focusWidget(), &child2); window.showMinimized(); QTRY_VERIFY(window.isMinimized()); @@ -2450,15 +2448,16 @@ void tst_QWidget::showMinimizedKeepsFocus() //testing deletion of the focusWidget { QWidget window; + window.setWindowTitle(QLatin1String(QTest::currentTestFunction())); window.resize(200, 200); QWidget *child = new QWidget(&window); child->setFocusPolicy(Qt::StrongFocus); window.show(); - qApp->setActiveWindow(&window); + QApplication::setActiveWindow(&window); QVERIFY(QTest::qWaitForWindowActive(&window)); child->setFocus(); QTRY_COMPARE(window.focusWidget(), child); - QTRY_COMPARE(qApp->focusWidget(), child); + QTRY_COMPARE(QApplication::focusWidget(), child); delete child; QCOMPARE(window.focusWidget(), nullptr); @@ -2468,17 +2467,18 @@ void tst_QWidget::showMinimizedKeepsFocus() //testing reparenting the focus widget { QWidget window; + window.setWindowTitle(QLatin1String(QTest::currentTestFunction())); window.resize(200, 200); QWidget *child = new QWidget(&window); child->setFocusPolicy(Qt::StrongFocus); window.show(); - qApp->setActiveWindow(&window); + QApplication::setActiveWindow(&window); QVERIFY(QTest::qWaitForWindowActive(&window)); child->setFocus(); QTRY_COMPARE(window.focusWidget(), child); - QTRY_COMPARE(qApp->focusWidget(), child); + QTRY_COMPARE(QApplication::focusWidget(), child); - child->setParent(0); + child->setParent(nullptr); QScopedPointer<QWidget> childGuard(child); QCOMPARE(window.focusWidget(), nullptr); QCOMPARE(QApplication::focusWidget(), nullptr); @@ -2487,15 +2487,16 @@ void tst_QWidget::showMinimizedKeepsFocus() //testing setEnabled(false) { QWidget window; + window.setWindowTitle(QLatin1String(QTest::currentTestFunction())); window.resize(200, 200); QWidget *child = new QWidget(&window); child->setFocusPolicy(Qt::StrongFocus); window.show(); - qApp->setActiveWindow(&window); + QApplication::setActiveWindow(&window); QVERIFY(QTest::qWaitForWindowActive(&window)); child->setFocus(); QTRY_COMPARE(window.focusWidget(), child); - QTRY_COMPARE(qApp->focusWidget(), child); + QTRY_COMPARE(QApplication::focusWidget(), child); child->setEnabled(false); QCOMPARE(window.focusWidget(), nullptr); @@ -2505,17 +2506,18 @@ void tst_QWidget::showMinimizedKeepsFocus() //testing clearFocus { QWidget window; + window.setWindowTitle(QLatin1String(QTest::currentTestFunction())); window.resize(200, 200); QWidget *firstchild = new QWidget(&window); firstchild->setFocusPolicy(Qt::StrongFocus); QWidget *child = new QWidget(&window); child->setFocusPolicy(Qt::StrongFocus); window.show(); - qApp->setActiveWindow(&window); + QApplication::setActiveWindow(&window); QVERIFY(QTest::qWaitForWindowActive(&window)); child->setFocus(); QTRY_COMPARE(window.focusWidget(), child); - QTRY_COMPARE(qApp->focusWidget(), child); + QTRY_COMPARE(QApplication::focusWidget(), child); child->clearFocus(); QCOMPARE(window.focusWidget(), nullptr); @@ -2528,7 +2530,7 @@ void tst_QWidget::showMinimizedKeepsFocus() QTRY_COMPARE(QApplication::focusWidget(), nullptr); window.showNormal(); - qApp->setActiveWindow(&window); + QApplication::setActiveWindow(&window); QVERIFY(QTest::qWaitForWindowActive(&window)); #ifdef Q_OS_OSX if (!macHasAccessToWindowsServer()) @@ -2543,7 +2545,7 @@ void tst_QWidget::showMinimizedKeepsFocus() #elif defined(Q_OS_WINRT) QEXPECT_FAIL("", "Winrt fails here - QTBUG-68297", Continue); #endif - QTRY_COMPARE(qApp->focusWidget(), firstchild); + QTRY_COMPARE(QApplication::focusWidget(), firstchild); } } @@ -2555,7 +2557,7 @@ void tst_QWidget::reparent() const QPoint parentPosition = m_availableTopLeft + QPoint(300, 300); parent.setGeometry(QRect(parentPosition, m_testWidgetSize)); - QWidget child(0); + QWidget child; child.setObjectName("child"); child.setGeometry(10, 10, 180, 130); QPalette pal1; @@ -2582,7 +2584,7 @@ void tst_QWidget::reparent() QPoint childPos = parent.mapToGlobal(child.pos()); QPoint tlwPos = childTLW.pos(); - child.setParent(0, child.windowFlags() & ~Qt::WindowType_Mask); + child.setParent(nullptr, child.windowFlags() & ~Qt::WindowType_Mask); child.setGeometry(childPos.x(), childPos.y(), child.width(), child.height()); child.show(); @@ -2649,17 +2651,17 @@ void tst_QWidget::hideWhenFocusWidgetIsChild() QVERIFY(QTest::qWaitForWindowActive(testWidget.data())); QString actualFocusWidget, expectedFocusWidget; - if (!qApp->focusWidget() && m_platform == QStringLiteral("xcb")) + if (!QApplication::focusWidget() && m_platform == QStringLiteral("xcb")) QSKIP("X11: Your window manager is too broken for this test"); - QVERIFY(qApp->focusWidget()); - actualFocusWidget = QString::asprintf("%p %s %s", qApp->focusWidget(), qApp->focusWidget()->objectName().toLatin1().constData(), qApp->focusWidget()->metaObject()->className()); + QVERIFY(QApplication::focusWidget()); + actualFocusWidget = QString::asprintf("%p %s %s", QApplication::focusWidget(), QApplication::focusWidget()->objectName().toLatin1().constData(), QApplication::focusWidget()->metaObject()->className()); expectedFocusWidget = QString::asprintf("%p %s %s", edit, edit->objectName().toLatin1().constData(), edit->metaObject()->className()); QCOMPARE(actualFocusWidget, expectedFocusWidget); parentWidget->hide(); - qApp->processEvents(); - actualFocusWidget = QString::asprintf("%p %s %s", qApp->focusWidget(), qApp->focusWidget()->objectName().toLatin1().constData(), qApp->focusWidget()->metaObject()->className()); + QCoreApplication::processEvents(); + actualFocusWidget = QString::asprintf("%p %s %s", QApplication::focusWidget(), QApplication::focusWidget()->objectName().toLatin1().constData(), QApplication::focusWidget()->metaObject()->className()); expectedFocusWidget = QString::asprintf("%p %s %s", edit2, edit2->objectName().toLatin1().constData(), edit2->metaObject()->className()); QCOMPARE(actualFocusWidget, expectedFocusWidget); } @@ -2776,6 +2778,7 @@ void tst_QWidget::normalGeometry() void tst_QWidget::setGeometry() { QWidget tlw; + tlw.setWindowTitle(QLatin1String(QTest::currentTestFunction())); QWidget child(&tlw); QRect tr(100,100,200,200); @@ -2788,7 +2791,7 @@ void tst_QWidget::setGeometry() QTRY_COMPARE(tlw.geometry().size(), tr.size()); QCOMPARE(child.geometry(), cr); - tlw.setParent(0, Qt::Window|Qt::FramelessWindowHint); + tlw.setParent(nullptr, Qt::Window|Qt::FramelessWindowHint); tr = QRect(0,0,100,100); tr.moveTopLeft(QGuiApplication::primaryScreen()->availableGeometry().topLeft()); tlw.setGeometry(tr); @@ -2836,13 +2839,14 @@ void tst_QWidget::windowOpacity() class UpdateWidget : public QWidget { public: - UpdateWidget(QWidget *parent = 0) : QWidget(parent) { + explicit UpdateWidget(QWidget *parent = nullptr) : QWidget(parent) + { setObjectName(QLatin1String("UpdateWidget")); - setWindowTitle(objectName()); reset(); } - void paintEvent(QPaintEvent *e) { + void paintEvent(QPaintEvent *e) override + { paintedRegion += e->region(); ++numPaintEvents; if (resizeInPaintEvent) { @@ -2851,7 +2855,7 @@ public: } } - bool event(QEvent *event) + bool event(QEvent *event) override { switch (event->type()) { case QEvent::ZOrderChange: @@ -2874,12 +2878,10 @@ public: return QWidget::event(event); } - void reset() { - numPaintEvents = 0; - numZOrderChangeEvents = 0; - numUpdateRequestEvents = 0; - updateOnActivationChangeAndFocusIn = false; - resizeInPaintEvent = false; + void reset() + { + numPaintEvents = numZOrderChangeEvents = numUpdateRequestEvents = 0; + updateOnActivationChangeAndFocusIn = resizeInPaintEvent = false; paintedRegion = QRegion(); } @@ -2896,6 +2898,7 @@ void tst_QWidget::lostUpdatesOnHide() #ifndef Q_OS_OSX UpdateWidget widget; widget.setAttribute(Qt::WA_DontShowOnScreen); + widget.setWindowTitle(QLatin1String(QTest::currentTestFunction())); widget.show(); widget.hide(); QTest::qWait(50); @@ -2939,12 +2942,11 @@ void tst_QWidget::raise() } #endif - QList<QObject *> list1; - list1 << child1 << child2 << child3 << child4; + QObjectList list1{child1, child2, child3, child4}; QCOMPARE(parentPtr->children(), list1); QCOMPARE(allChildren.count(), list1.count()); - foreach (UpdateWidget *child, allChildren) { + for (UpdateWidget *child : qAsConst(allChildren)) { int expectedPaintEvents = child == child4 ? 1 : 0; if (expectedPaintEvents == 0) { QCOMPARE(child->numPaintEvents, 0); @@ -2960,7 +2962,7 @@ void tst_QWidget::raise() child2->raise(); QTest::qWait(50); - foreach (UpdateWidget *child, allChildren) { + for (UpdateWidget *child : qAsConst(allChildren)) { int expectedPaintEvents = child == child2 ? 1 : 0; int expectedZOrderChangeEvents = child == child2 ? 1 : 0; QTRY_COMPARE(child->numPaintEvents, expectedPaintEvents); @@ -2975,6 +2977,7 @@ void tst_QWidget::raise() // Creates a widget on top of all the children and checks that raising one of // the children underneath doesn't trigger a repaint on the covering widget. QWidget topLevel; + topLevel.setWindowTitle(QLatin1String(QTest::currentTestFunction())); QWidget *parent = parentPtr.take(); parent->setParent(&topLevel); topLevel.show(); @@ -2989,7 +2992,7 @@ void tst_QWidget::raise() onTop->reset(); // Reset all the children. - foreach (UpdateWidget *child, allChildren) + for (UpdateWidget *child : qAsConst(allChildren)) child->reset(); for (int i = 0; i < 5; ++i) @@ -2999,11 +3002,10 @@ void tst_QWidget::raise() QCOMPARE(onTop->numPaintEvents, 0); QCOMPARE(onTop->numZOrderChangeEvents, 0); - QList<QObject *> list3; - list3 << child1 << child4 << child2 << child3; + QObjectList list3{child1, child4, child2, child3}; QCOMPARE(parent->children(), list3); - foreach (UpdateWidget *child, allChildren) { + for (UpdateWidget *child : qAsConst(allChildren)) { int expectedPaintEvents = 0; int expectedZOrderChangeEvents = child == child3 ? 1 : 0; QTRY_COMPARE(child->numPaintEvents, expectedPaintEvents); @@ -3039,12 +3041,11 @@ void tst_QWidget::lower() parent->show(); QVERIFY(QTest::qWaitForWindowExposed(parent.data())); - QList<QObject *> list1; - list1 << child1 << child2 << child3 << child4; + QObjectList list1{child1, child2, child3, child4}; QCOMPARE(parent->children(), list1); QCOMPARE(allChildren.count(), list1.count()); - foreach (UpdateWidget *child, allChildren) { + for (UpdateWidget *child : qAsConst(allChildren)) { int expectedPaintEvents = child == child4 ? 1 : 0; if (expectedPaintEvents == 0) { QCOMPARE(child->numPaintEvents, 0); @@ -3061,7 +3062,7 @@ void tst_QWidget::lower() QTest::qWait(100); - foreach (UpdateWidget *child, allChildren) { + for (UpdateWidget *child : qAsConst(allChildren)) { int expectedPaintEvents = child == child3 ? 1 : 0; int expectedZOrderChangeEvents = child == child4 ? 1 : 0; QTRY_COMPARE(child->numZOrderChangeEvents, expectedZOrderChangeEvents); @@ -3104,11 +3105,10 @@ void tst_QWidget::stackUnder() parent->show(); QVERIFY(QTest::qWaitForWindowExposed(parent.data())); - QList<QObject *> list1; - list1 << child1 << child2 << child3 << child4; + QObjectList list1{child1, child2, child3, child4}; QCOMPARE(parent->children(), list1); - foreach (UpdateWidget *child, allChildren) { + for (UpdateWidget *child : qAsConst(allChildren)) { int expectedPaintEvents = child == child4 ? 1 : 0; #if defined(Q_OS_WIN) || defined(Q_OS_OSX) if (expectedPaintEvents == 1 && child->numPaintEvents == 2) @@ -3123,11 +3123,10 @@ void tst_QWidget::stackUnder() child4->stackUnder(child2); QTest::qWait(10); - QList<QObject *> list2; - list2 << child1 << child4 << child2 << child3; + QObjectList list2{child1, child4, child2, child3}; QCOMPARE(parent->children(), list2); - foreach (UpdateWidget *child, allChildren) { + for (UpdateWidget *child : qAsConst(allChildren)) { int expectedPaintEvents = child == child3 ? 1 : 0; int expectedZOrderChangeEvents = child == child4 ? 1 : 0; QTRY_COMPARE(child->numPaintEvents, expectedPaintEvents); @@ -3139,11 +3138,10 @@ void tst_QWidget::stackUnder() child1->stackUnder(child3); QTest::qWait(10); - QList<QObject *> list3; - list3 << child4 << child2 << child1 << child3; + QObjectList list3{child4, child2, child1, child3}; QCOMPARE(parent->children(), list3); - foreach (UpdateWidget *child, allChildren) { + for (UpdateWidget *child : qAsConst(allChildren)) { int expectedZOrderChangeEvents = child == child1 ? 1 : 0; if (child == child3) { #ifndef Q_OS_OSX @@ -3176,30 +3174,31 @@ class ContentsPropagationWidget : public QWidget { Q_OBJECT public: - ContentsPropagationWidget(QWidget *parent = 0) : QWidget(parent) + explicit ContentsPropagationWidget(QWidget *parent = nullptr) : QWidget(parent) { setObjectName(QLatin1String("ContentsPropagationWidget")); setWindowTitle(objectName()); QWidget *child = this; - for (int i=0; i<32; ++i) { + for (int i = 0; i < 32; ++i) { child = new QWidget(child); - child->setGeometry(i, i, 400 - i*2, 400 - i*2); + child->setGeometry(i, i, 400 - i * 2, 400 - i * 2); } } - void setContentsPropagation(bool enable) { - foreach (QObject *child, children()) + void setContentsPropagation(bool enable) + { + for (QObject *child : children()) qobject_cast<QWidget *>(child)->setAutoFillBackground(!enable); } protected: - void paintEvent(QPaintEvent *) + void paintEvent(QPaintEvent *) override { int w = width(), h = height(); drawPolygon(this, w, h); } - QSize sizeHint() const { return QSize(500, 500); } + QSize sizeHint() const override { return {500, 500}; } }; // Scale to remove devicePixelRatio should scaling be active. @@ -3273,6 +3272,7 @@ void tst_QWidget::saveRestoreGeometry() { QWidget widget; + widget.setWindowTitle(QLatin1String(QTest::currentTestFunction())); const QByteArray empty; const QByteArray one("a"); @@ -3384,7 +3384,7 @@ void tst_QWidget::restoreVersion1Geometry_data() if (m_platform == QStringLiteral("wayland")) QSKIP("Wayland: This fails. Figure out why."); QTest::addColumn<QString>("fileName"); - QTest::addColumn<uint>("expectedWindowState"); + QTest::addColumn<Qt::WindowState>("expectedWindowState"); QTest::addColumn<QPoint>("expectedPosition"); QTest::addColumn<QSize>("expectedSize"); QTest::addColumn<QRect>("expectedNormalGeometry"); @@ -3392,9 +3392,9 @@ void tst_QWidget::restoreVersion1Geometry_data() const QSize size(200, 200); const QRect normalGeometry(102, 124, 200, 200); - QTest::newRow("geometry.dat") << ":geometry.dat" << uint(Qt::WindowNoState) << position << size << normalGeometry; - QTest::newRow("geometry-maximized.dat") << ":geometry-maximized.dat" << uint(Qt::WindowMaximized) << position << size << normalGeometry; - QTest::newRow("geometry-fullscreen.dat") << ":geometry-fullscreen.dat" << uint(Qt::WindowFullScreen) << position << size << normalGeometry; + QTest::newRow("geometry.dat") << ":geometry.dat" << Qt::WindowNoState << position << size << normalGeometry; + QTest::newRow("geometry-maximized.dat") << ":geometry-maximized.dat" << Qt::WindowMaximized << position << size << normalGeometry; + QTest::newRow("geometry-fullscreen.dat") << ":geometry-fullscreen.dat" << Qt::WindowFullScreen << position << size << normalGeometry; } /* @@ -3404,14 +3404,14 @@ void tst_QWidget::restoreVersion1Geometry_data() void tst_QWidget::restoreVersion1Geometry() { QFETCH(QString, fileName); - QFETCH(uint, expectedWindowState); + QFETCH(Qt::WindowState, expectedWindowState); QFETCH(QPoint, expectedPosition); Q_UNUSED(expectedPosition); QFETCH(QSize, expectedSize); QFETCH(QRect, expectedNormalGeometry); // WindowActive is uninteresting for this test - const uint WindowStateMask = Qt::WindowFullScreen | Qt::WindowMaximized | Qt::WindowMinimized; + const Qt::WindowStates WindowStateMask = Qt::WindowFullScreen | Qt::WindowMaximized | Qt::WindowMinimized; QFile f(fileName); QVERIFY(f.exists()); @@ -3421,10 +3421,12 @@ void tst_QWidget::restoreVersion1Geometry() f.close(); QWidget widget; + widget.setWindowTitle(QLatin1String(QTest::currentTestFunction()) + QLatin1String("::") + + QLatin1String(QTest::currentDataTag())); QVERIFY(widget.restoreGeometry(savedGeometry)); - QCOMPARE(uint(widget.windowState() & WindowStateMask), expectedWindowState); + QCOMPARE(widget.windowState() & WindowStateMask, expectedWindowState); if (expectedWindowState == Qt::WindowNoState) { QTRY_COMPARE(widget.geometry(), expectedNormalGeometry); QCOMPARE(widget.size(), expectedSize); @@ -3488,11 +3490,11 @@ void tst_QWidget::widgetAt() Q_CHECK_PAINTEVENTS const QPoint referencePos = m_availableTopLeft + QPoint(100, 100); - QScopedPointer<QWidget> w1(new QWidget(0, Qt::X11BypassWindowManagerHint)); + QScopedPointer<QWidget> w1(new QWidget(nullptr, Qt::X11BypassWindowManagerHint)); w1->setGeometry(QRect(referencePos, QSize(m_testWidgetSize.width(), 150))); w1->setObjectName(QLatin1String("w1")); w1->setWindowTitle(w1->objectName()); - QScopedPointer<QWidget> w2(new QWidget(0, Qt::X11BypassWindowManagerHint | Qt::FramelessWindowHint)); + QScopedPointer<QWidget> w2(new QWidget(nullptr, Qt::X11BypassWindowManagerHint | Qt::FramelessWindowHint)); w2->setGeometry(QRect(referencePos + QPoint(50, 50), QSize(m_testWidgetSize.width(), 100))); w2->setObjectName(QLatin1String("w2")); w2->setWindowTitle(w2->objectName()); @@ -3552,6 +3554,7 @@ void tst_QWidget::widgetAt() void tst_QWidget::task110173() { QWidget w; + w.setWindowTitle(QLatin1String(QTest::currentTestFunction())); QPushButton *pb1 = new QPushButton("click", &w); pb1->setFocusPolicy(Qt::ClickFocus); @@ -3569,20 +3572,20 @@ void tst_QWidget::task110173() class Widget : public QWidget { public: - Widget() : deleteThis(false) { setFocusPolicy(Qt::StrongFocus); } - void actionEvent(QActionEvent *) { if (deleteThis) delete this; } - void changeEvent(QEvent *) { if (deleteThis) delete this; } - void closeEvent(QCloseEvent *) { if (deleteThis) delete this; } - void hideEvent(QHideEvent *) { if (deleteThis) delete this; } - void focusOutEvent(QFocusEvent *) { if (deleteThis) delete this; } - void keyPressEvent(QKeyEvent *) { if (deleteThis) delete this; } - void keyReleaseEvent(QKeyEvent *) { if (deleteThis) delete this; } - void mouseDoubleClickEvent(QMouseEvent *) { if (deleteThis) delete this; } - void mousePressEvent(QMouseEvent *) { if (deleteThis) delete this; } - void mouseReleaseEvent(QMouseEvent *) { if (deleteThis) delete this; } - void mouseMoveEvent(QMouseEvent *) { if (deleteThis) delete this; } - - bool deleteThis; + Widget() { setFocusPolicy(Qt::StrongFocus); } + void actionEvent(QActionEvent *) override { if (deleteThis) delete this; } + void changeEvent(QEvent *) override { if (deleteThis) delete this; } + void closeEvent(QCloseEvent *) override { if (deleteThis) delete this; } + void hideEvent(QHideEvent *) override { if (deleteThis) delete this; } + void focusOutEvent(QFocusEvent *) override { if (deleteThis) delete this; } + void keyPressEvent(QKeyEvent *) override { if (deleteThis) delete this; } + void keyReleaseEvent(QKeyEvent *) override { if (deleteThis) delete this; } + void mouseDoubleClickEvent(QMouseEvent *) override { if (deleteThis) delete this; } + void mousePressEvent(QMouseEvent *) override { if (deleteThis) delete this; } + void mouseReleaseEvent(QMouseEvent *) override { if (deleteThis) delete this; } + void mouseMoveEvent(QMouseEvent *) override { if (deleteThis) delete this; } + + bool deleteThis = false; }; void tst_QWidget::testDeletionInEventHandlers() @@ -3631,7 +3634,7 @@ void tst_QWidget::testDeletionInEventHandlers() w = new Widget; w->show(); w->deleteThis = true; - QMouseEvent me(QEvent::MouseButtonRelease, QPoint(1, 1), Qt::LeftButton, Qt::LeftButton, 0); + QMouseEvent me(QEvent::MouseButtonRelease, QPoint(1, 1), Qt::LeftButton, Qt::LeftButton, Qt::KeyboardModifiers()); qApp->notify(w, &me); QVERIFY(w.isNull()); delete w; @@ -3735,21 +3738,19 @@ class StaticWidget : public QWidget { Q_OBJECT public: - bool partial; - bool gotPaintEvent; + bool partial = false; + bool gotPaintEvent = false; QRegion paintedRegion; - StaticWidget(QWidget *parent = 0) - :QWidget(parent) + explicit StaticWidget(QWidget *parent = nullptr) : QWidget(parent) { setAttribute(Qt::WA_StaticContents); setAttribute(Qt::WA_OpaquePaintEvent); setPalette(Qt::red); // Make sure we have an opaque palette. setAutoFillBackground(true); - gotPaintEvent = false; } - void paintEvent(QPaintEvent *e) + void paintEvent(QPaintEvent *e) override { paintedRegion += e->region(); gotPaintEvent = true; @@ -3757,7 +3758,7 @@ public: // Look for a full update, set partial to false if found. for (QRect r : e->region()) { partial = (r != rect()); - if (partial == false) + if (!partial) break; } } @@ -3772,6 +3773,7 @@ void tst_QWidget::optimizedResizeMove() if (m_platform == QStringLiteral("wayland")) QSKIP("Wayland: This fails. Figure out why."); QWidget parent; + parent.setWindowTitle(QLatin1String(QTest::currentTestFunction())); parent.resize(400, 400); StaticWidget staticWidget(&parent); @@ -3853,6 +3855,7 @@ void tst_QWidget::optimizedResize_topLevel() if (QHighDpiScaling::isActive()) QSKIP("Skip due to rounding errors in the regions."); StaticWidget topLevel; + topLevel.setWindowTitle(QLatin1String(QTest::currentTestFunction())); topLevel.gotPaintEvent = false; topLevel.show(); QVERIFY(QTest::qWaitForWindowExposed(&topLevel)); @@ -3897,7 +3900,7 @@ class SiblingDeleter : public QWidget public: inline SiblingDeleter(QWidget *sibling, QWidget *parent) : QWidget(parent), sibling(sibling) {} - inline virtual ~SiblingDeleter() { delete sibling; } + inline ~SiblingDeleter() { delete sibling; } private: QPointer<QWidget> sibling; @@ -3906,8 +3909,8 @@ private: void tst_QWidget::childDeletesItsSibling() { - QWidget *commonParent = new QWidget(0); - QPointer<QWidget> child = new QWidget(0); + auto commonParent = new QWidget(nullptr); + QPointer<QWidget> child(new QWidget(nullptr)); QPointer<QWidget> siblingDeleter = new SiblingDeleter(child, commonParent); child->setParent(commonParent); delete commonParent; // don't crash @@ -4042,15 +4045,12 @@ void tst_QWidget::ensureCreated() } } -class WinIdChangeWidget : public QWidget { +class WinIdChangeWidget : public QWidget +{ public: - WinIdChangeWidget(QWidget *p = 0) - : QWidget(p) - { - - } + using QWidget::QWidget; protected: - bool event(QEvent *e) + bool event(QEvent *e) override { if (e->type() == QEvent::WinIdChange) { m_winIdList.append(internalWinId()); @@ -4144,7 +4144,7 @@ void tst_QWidget::persistentWinId() WId winId3 = w3->winId(); // reparenting should preserve the winId of the widget being reparented and of its children - w1->setParent(0); + w1->setParent(nullptr); QCOMPARE(w1->winId(), winId1); QCOMPARE(w2->winId(), winId2); QCOMPARE(w3->winId(), winId3); @@ -4154,7 +4154,7 @@ void tst_QWidget::persistentWinId() QCOMPARE(w2->winId(), winId2); QCOMPARE(w3->winId(), winId3); - w2->setParent(0); + w2->setParent(nullptr); QCOMPARE(w2->winId(), winId2); QCOMPARE(w3->winId(), winId3); @@ -4166,7 +4166,7 @@ void tst_QWidget::persistentWinId() QCOMPARE(w2->winId(), winId2); QCOMPARE(w3->winId(), winId3); - w3->setParent(0); + w3->setParent(nullptr); QCOMPARE(w3->winId(), winId3); w3->setParent(w1); @@ -4207,26 +4207,20 @@ void tst_QWidget::showNativeChild() class ShowHideEventWidget : public QWidget { public: - int numberOfShowEvents, numberOfHideEvents; - int numberOfSpontaneousShowEvents, numberOfSpontaneousHideEvents; - - ShowHideEventWidget(QWidget *parent = 0) - : QWidget(parent) - , numberOfShowEvents(0), numberOfHideEvents(0) - , numberOfSpontaneousShowEvents(0), numberOfSpontaneousHideEvents(0) - { } + int numberOfShowEvents = 0, numberOfHideEvents = 0; + int numberOfSpontaneousShowEvents = 0, numberOfSpontaneousHideEvents = 0; - void create() - { QWidget::create(); } + using QWidget::QWidget; + using QWidget::create; - void showEvent(QShowEvent *e) + void showEvent(QShowEvent *e) override { ++numberOfShowEvents; if (e->spontaneous()) ++numberOfSpontaneousShowEvents; } - void hideEvent(QHideEvent *e) + void hideEvent(QHideEvent *e) override { ++numberOfHideEvents; if (e->spontaneous()) @@ -4289,6 +4283,7 @@ void tst_QWidget::showHideEvent() QFETCH(int, expectedHideEvents); ShowHideEventWidget widget; + widget.setWindowTitle(QLatin1String(QTest::currentTestFunction())); if (show) widget.show(); if (hide) @@ -4351,13 +4346,14 @@ void tst_QWidget::showHideChildrenWhileMinimize_QTBUG50589() void tst_QWidget::update() { -#ifdef Q_OS_OSX +#ifdef Q_OS_MACOS QSKIP("QTBUG-52974"); #endif Q_CHECK_PAINTEVENTS UpdateWidget w; + w.setWindowTitle(QLatin1String(QTest::currentTestFunction())); w.resize(100, 100); centerOnScreen(&w); w.show(); @@ -4609,14 +4605,14 @@ void tst_QWidget::scroll() updateWidget.reset(); updateWidget.move(QGuiApplication::primaryScreen()->geometry().center() - QPoint(250, 250)); updateWidget.showNormal(); - qApp->setActiveWindow(&updateWidget); + QApplication::setActiveWindow(&updateWidget); QVERIFY(QTest::qWaitForWindowActive(&updateWidget)); QVERIFY(updateWidget.numPaintEvents > 0); { updateWidget.reset(); updateWidget.scroll(10, 10); - qApp->processEvents(); + QCoreApplication::processEvents(); QRegion dirty(QRect(0, 0, w, 10)); dirty += QRegion(QRect(0, 10, 10, h - 10)); if (m_platform == QStringLiteral("winrt")) @@ -4628,7 +4624,7 @@ void tst_QWidget::scroll() updateWidget.reset(); updateWidget.update(0, 0, 10, 10); updateWidget.scroll(0, 10); - qApp->processEvents(); + QCoreApplication::processEvents(); QRegion dirty(QRect(0, 0, w, 10)); dirty += QRegion(QRect(0, 10, 10, 10)); QTRY_COMPARE(updateWidget.paintedRegion, dirty); @@ -4641,7 +4637,7 @@ void tst_QWidget::scroll() updateWidget.reset(); updateWidget.update(0, 0, 100, 100); updateWidget.scroll(10, 10, QRect(50, 50, 100, 100)); - qApp->processEvents(); + QCoreApplication::processEvents(); QRegion dirty(QRect(0, 0, 100, 50)); dirty += QRegion(QRect(0, 50, 150, 10)); dirty += QRegion(QRect(0, 60, 110, 40)); @@ -4654,7 +4650,7 @@ void tst_QWidget::scroll() updateWidget.reset(); updateWidget.update(0, 0, 100, 100); updateWidget.scroll(10, 10, QRect(100, 100, 100, 100)); - qApp->processEvents(); + QCoreApplication::processEvents(); QRegion dirty(QRect(0, 0, 100, 100)); dirty += QRegion(QRect(100, 100, 100, 10)); dirty += QRegion(QRect(100, 110, 10, 90)); @@ -4691,17 +4687,12 @@ class DestroyedSlotChecker : public QObject Q_OBJECT public: - bool wasQWidget; - - DestroyedSlotChecker() - : wasQWidget(false) - { - } + bool wasQWidget = false; public slots: void destroyedSlot(QObject *object) { - wasQWidget = (qobject_cast<QWidget *>(object) != 0 || object->isWidgetType()); + wasQWidget = (qobject_cast<QWidget *>(object) != nullptr || object->isWidgetType()); } }; @@ -4715,7 +4706,7 @@ void tst_QWidget::qobject_castInDestroyedSlot() QWidget *widget = new QWidget(); - QObject::connect(widget, SIGNAL(destroyed(QObject*)), &checker, SLOT(destroyedSlot(QObject*))); + QObject::connect(widget, &QObject::destroyed, &checker, &DestroyedSlotChecker::destroyedSlot); delete widget; QVERIFY(checker.wasQWidget); @@ -4724,62 +4715,53 @@ void tst_QWidget::qobject_castInDestroyedSlot() // Since X11 WindowManager operations are all async, and we have no way to know if the window // manager has finished playing with the window geometry, this test can't be reliable on X11. +using Rects = QVector<QRect>; + void tst_QWidget::setWindowGeometry_data() { - QTest::addColumn<QList<QRect> >("rects"); + QTest::addColumn<Rects>("rects"); QTest::addColumn<int>("windowFlags"); - QList<QList<QRect> > rects; + QVector<Rects> rects; const int width = m_testWidgetSize.width(); const int height = m_testWidgetSize.height(); const QRect availableAdjusted = QGuiApplication::primaryScreen()->availableGeometry().adjusted(100, 100, -100, -100); - rects << (QList<QRect>() - << QRect(m_availableTopLeft + QPoint(100, 100), m_testWidgetSize) - << availableAdjusted - << QRect(m_availableTopLeft + QPoint(130, 100), QSize(0, height)) - << QRect(m_availableTopLeft + QPoint(100, 50), QSize(width, 0)) - << QRect(m_availableTopLeft + QPoint(130, 50), QSize(0, 0))) - << (QList<QRect>() - << availableAdjusted - << QRect(m_availableTopLeft + QPoint(130, 100), QSize(0, height)) - << QRect(m_availableTopLeft + QPoint(100, 50), QSize(width, 0)) - << QRect(m_availableTopLeft + QPoint(130, 50), QSize(0, 0)) - << QRect(m_availableTopLeft + QPoint(100, 100), QSize(width, height))) - << (QList<QRect>() - << QRect(m_availableTopLeft + QPoint(130, 100), QSize(0, height)) - << QRect(m_availableTopLeft + QPoint(100, 50), QSize(width, 0)) - << QRect(m_availableTopLeft + QPoint(130, 50), QSize(0, 0)) - << QRect(m_availableTopLeft + QPoint(100, 100), QSize(width, height)) - << availableAdjusted) - << (QList<QRect>() - << QRect(m_availableTopLeft + QPoint(100, 50), QSize(width, 0)) - << QRect(m_availableTopLeft + QPoint(130, 50), QSize(0, 0)) - << QRect(m_availableTopLeft + QPoint(100, 100), QSize(width, height)) - << availableAdjusted - << QRect(m_availableTopLeft + QPoint(130, 100), QSize(0, height))) - << (QList<QRect>() - << QRect(m_availableTopLeft + QPoint(130, 50), QSize(0, 0)) - << QRect(m_availableTopLeft + QPoint(100, 100), QSize(width, height)) - << availableAdjusted - << QRect(m_availableTopLeft + QPoint(130, 100), QSize(0, height)) - << QRect(m_availableTopLeft + QPoint(100, 50), QSize(width, 0))); - - QList<int> windowFlags; - windowFlags << 0 << Qt::FramelessWindowHint; + rects << Rects{QRect(m_availableTopLeft + QPoint(100, 100), m_testWidgetSize), + availableAdjusted, + QRect(m_availableTopLeft + QPoint(130, 100), QSize(0, height)), + QRect(m_availableTopLeft + QPoint(100, 50), QSize(width, 0)), + QRect(m_availableTopLeft + QPoint(130, 50), QSize(0, 0))} + << Rects{availableAdjusted, + QRect(m_availableTopLeft + QPoint(130, 100), QSize(0, height)), + QRect(m_availableTopLeft + QPoint(100, 50), QSize(width, 0)), + QRect(m_availableTopLeft + QPoint(130, 50), QSize(0, 0)), + QRect(m_availableTopLeft + QPoint(100, 100), QSize(width, height))} + << Rects{QRect(m_availableTopLeft + QPoint(130, 100), QSize(0, height)), + QRect(m_availableTopLeft + QPoint(100, 50), QSize(width, 0)), + QRect(m_availableTopLeft + QPoint(130, 50), QSize(0, 0)), + QRect(m_availableTopLeft + QPoint(100, 100), QSize(width, height)), + availableAdjusted} + << Rects{QRect(m_availableTopLeft + QPoint(100, 50), QSize(width, 0)), + QRect(m_availableTopLeft + QPoint(130, 50), QSize(0, 0)), + QRect(m_availableTopLeft + QPoint(100, 100), QSize(width, height)), + availableAdjusted, + QRect(m_availableTopLeft + QPoint(130, 100), QSize(0, height))} + << Rects{QRect(m_availableTopLeft + QPoint(130, 50), QSize(0, 0)), + QRect(m_availableTopLeft + QPoint(100, 100), QSize(width, height)), + availableAdjusted, + QRect(m_availableTopLeft + QPoint(130, 100), QSize(0, height)), + QRect(m_availableTopLeft + QPoint(100, 50), QSize(width, 0))}; + + const Qt::WindowFlags windowFlags[] = {Qt::WindowFlags(), Qt::FramelessWindowHint}; const bool skipEmptyRects = (m_platform == QStringLiteral("windows")); - foreach (QList<QRect> l, rects) { - QRect rect = l.first(); + for (Rects l : qAsConst(rects)) { if (skipEmptyRects) { - QList<QRect>::iterator it = l.begin(); - while (it != l.end()) { - if (it->isEmpty()) - it = l.erase(it); - else - ++it; - } + l.erase(std::remove_if(l.begin(), l.end(), [] (const QRect &r) { return r.isEmpty(); }), + l.end()); } - foreach (int windowFlag, windowFlags) { + const QRect &rect = l.constFirst(); + for (int windowFlag : windowFlags) { QTest::newRow(QString("%1,%2 %3x%4, flags %5") .arg(rect.x()) .arg(rect.y()) @@ -4799,7 +4781,7 @@ void tst_QWidget::setWindowGeometry() else if (m_platform == QStringLiteral("winrt")) QSKIP("WinRT does not support setWindowGeometry"); - QFETCH(QList<QRect>, rects); + QFETCH(Rects, rects); QFETCH(int, windowFlags); QRect rect = rects.takeFirst(); @@ -4814,7 +4796,7 @@ void tst_QWidget::setWindowGeometry() QCOMPARE(widget.geometry(), rect); // setGeometry() without showing - foreach (QRect r, rects) { + for (const QRect &r : qAsConst(rects)) { widget.setGeometry(r); QTest::qWait(100); QCOMPARE(widget.geometry(), r); @@ -4824,6 +4806,7 @@ void tst_QWidget::setWindowGeometry() { // setGeometry() first, then show() QWidget widget; + widget.setWindowTitle(QLatin1String(QTest::currentTestFunction())); if (windowFlags != 0) widget.setWindowFlags(Qt::WindowFlags(windowFlags)); @@ -4839,7 +4822,7 @@ void tst_QWidget::setWindowGeometry() QTRY_COMPARE(widget.geometry(), rect); // setGeometry() while shown - foreach (QRect r, rects) { + for (const QRect &r : qAsConst(rects)) { widget.setGeometry(r); QTest::qWait(10); QTRY_COMPARE(widget.geometry(), r); @@ -4854,7 +4837,7 @@ void tst_QWidget::setWindowGeometry() QTRY_COMPARE(widget.geometry(), rect); // setGeometry() after hide() - foreach (QRect r, rects) { + for (const QRect &r : qAsConst(rects)) { widget.setGeometry(r); QTest::qWait(10); QTRY_COMPARE(widget.geometry(), r); @@ -4878,6 +4861,7 @@ void tst_QWidget::setWindowGeometry() { // show() first, then setGeometry() QWidget widget; + widget.setWindowTitle(QLatin1String(QTest::currentTestFunction())); if (windowFlags != 0) widget.setWindowFlags(Qt::WindowFlags(windowFlags)); @@ -4889,7 +4873,7 @@ void tst_QWidget::setWindowGeometry() QTRY_COMPARE(widget.geometry(), rect); // setGeometry() while shown - foreach (QRect r, rects) { + for (const QRect &r : qAsConst(rects)) { widget.setGeometry(r); QTest::qWait(10); QTRY_COMPARE(widget.geometry(), r); @@ -4904,7 +4888,7 @@ void tst_QWidget::setWindowGeometry() QTRY_COMPARE(widget.geometry(), rect); // setGeometry() after hide() - foreach (QRect r, rects) { + for (const QRect &r : qAsConst(rects)) { widget.setGeometry(r); QTest::qWait(10); QTRY_COMPARE(widget.geometry(), r); @@ -4967,7 +4951,7 @@ void tst_QWidget::windowMoveResize() if (m_platform == QStringLiteral("winrt")) QSKIP("WinRT does not support move/resize"); - QFETCH(QList<QRect>, rects); + QFETCH(Rects, rects); QFETCH(int, windowFlags); QRect rect = rects.takeFirst(); @@ -4985,7 +4969,7 @@ void tst_QWidget::windowMoveResize() QTRY_COMPARE(widget.size(), rect.size()); // move() without showing - foreach (QRect r, rects) { + for (const QRect &r : qAsConst(rects)) { widget.move(r.topLeft()); widget.resize(r.size()); QApplication::processEvents(); @@ -4997,6 +4981,7 @@ void tst_QWidget::windowMoveResize() { // move() first, then show() QWidget widget; + widget.setWindowTitle(QLatin1String(QTest::currentTestFunction())); if (windowFlags != 0) widget.setWindowFlags(Qt::WindowFlags(windowFlags)); @@ -5013,7 +4998,7 @@ void tst_QWidget::windowMoveResize() QTRY_COMPARE(widget.size(), rect.size()); // move() while shown - foreach (const QRect &r, rects) { + for (const QRect &r : qAsConst(rects)) { // XCB: First resize after show of zero-sized gets wrong win_gravity. const bool expectMoveFail = !windowFlags && ((widget.width() == 0 || widget.height() == 0) && r.width() != 0 && r.height() != 0) @@ -5042,7 +5027,7 @@ void tst_QWidget::windowMoveResize() QTRY_COMPARE(widget.size(), rect.size()); // move() after hide() - foreach (QRect r, rects) { + for (const QRect &r : qAsConst(rects)) { widget.move(r.topLeft()); widget.resize(r.size()); QApplication::processEvents(); @@ -5093,7 +5078,7 @@ void tst_QWidget::windowMoveResize() QTRY_COMPARE(widget.size(), rect.size()); // move() while shown - foreach (QRect r, rects) { + for (const QRect &r : qAsConst(rects)) { widget.move(r.topLeft()); widget.resize(r.size()); QApplication::processEvents(); @@ -5113,7 +5098,7 @@ void tst_QWidget::windowMoveResize() QTRY_COMPARE(widget.size(), rect.size()); // move() after hide() - foreach (QRect r, rects) { + for (const QRect &r : qAsConst(rects)) { widget.move(r.topLeft()); widget.resize(r.size()); QApplication::processEvents(); @@ -5151,8 +5136,9 @@ void tst_QWidget::windowMoveResize() class ColorWidget : public QWidget { public: - ColorWidget(QWidget *parent = 0, Qt::WindowFlags f = 0, const QColor &c = QColor(Qt::red)) - : QWidget(parent, f), color(c), enters(0), leaves(0) + explicit ColorWidget(QWidget *parent = nullptr, Qt::WindowFlags f = Qt::WindowFlags(), + const QColor &c = QColor(Qt::red)) + : QWidget(parent, f), color(c) { QPalette opaquePalette = palette(); opaquePalette.setColor(backgroundRole(), color); @@ -5160,16 +5146,18 @@ public: setAutoFillBackground(true); } - void paintEvent(QPaintEvent *e) { + void paintEvent(QPaintEvent *e) override + { r += e->region(); } - void reset() { + void reset() + { r = QRegion(); } - void enterEvent(QEvent *) { ++enters; } - void leaveEvent(QEvent *) { ++leaves; } + void enterEvent(QEvent *) override { ++enters; } + void leaveEvent(QEvent *) override { ++leaves; } void resetCounts() { @@ -5179,8 +5167,8 @@ public: QColor color; QRegion r; - int enters; - int leaves; + int enters = 0; + int leaves = 0; }; static inline QByteArray msgRgbMismatch(unsigned actual, unsigned expected) @@ -5198,7 +5186,7 @@ static QPixmap grabWindow(QWindow *window, int x, int y, int width, int height) #define VERIFY_COLOR(child, region, color) verifyColor(child, region, color, __LINE__) -bool verifyColor(QWidget &child, const QRegion ®ion, const QColor &color, unsigned int callerLine) +bool verifyColor(QWidget &child, const QRegion ®ion, const QColor &color, int callerLine) { QWindow *window = child.window()->windowHandle(); Q_ASSERT(window); @@ -5224,16 +5212,13 @@ bool verifyColor(QWidget &child, const QRegion ®ion, const QColor &color, uns If it succeeds: return success If it fails: do not return, but wait a bit and reiterate (retry) */ - if (firstPixel == QColor(color).rgb() - && image == expectedPixmap.toImage()) { + if (firstPixel == QColor(color).rgb() && image == expectedPixmap.toImage()) return true; + if (t == 4) { + grabBackingStore = true; + rect = r; } else { - if (t == 4) { - grabBackingStore = true; - rect = r; - } else { - QTest::qWait(200); - } + QTest::qWait(200); } } else { // Last run, report failure if it still fails @@ -5269,7 +5254,7 @@ void tst_QWidget::moveChild() QSKIP("Wayland: This fails. Figure out why."); QFETCH(QPoint, offset); - ColorWidget parent(0, Qt::Window | Qt::WindowStaysOnTopHint); + ColorWidget parent(nullptr, Qt::Window | Qt::WindowStaysOnTopHint); // prevent custom styles const QScopedPointer<QStyle> style(QStyleFactory::create(QLatin1String("Windows"))); parent.setStyle(style.data()); @@ -5316,7 +5301,8 @@ void tst_QWidget::showAndMoveChild() { if (m_platform == QStringLiteral("wayland")) QSKIP("Wayland: This fails. Figure out why."); - QWidget parent(0, Qt::Window | Qt::WindowStaysOnTopHint); + QWidget parent(nullptr, Qt::Window | Qt::WindowStaysOnTopHint); + parent.setWindowTitle(QLatin1String(QTest::currentTestFunction())); // prevent custom styles const QScopedPointer<QStyle> style(QStyleFactory::create(QLatin1String("Windows"))); parent.setStyle(style.data()); @@ -5331,7 +5317,7 @@ void tst_QWidget::showAndMoveChild() parent.setGeometry(desktopDimensions); parent.setPalette(Qt::red); parent.show(); - qApp->setActiveWindow(&parent); + QApplication::setActiveWindow(&parent); QVERIFY(QTest::qWaitForWindowActive(&parent)); QWidget child(&parent); @@ -5343,7 +5329,7 @@ void tst_QWidget::showAndMoveChild() // NB! Do NOT processEvents() (or qWait()) in between show() and move(). child.show(); child.move(desktopDimensions.width()/2, desktopDimensions.height()/2); - qApp->processEvents(); + QCoreApplication::processEvents(); if (m_platform == QStringLiteral("winrt")) QSKIP("WinRT does not support setGeometry (and we cannot use QEXPECT_FAIL because of VERIFY_COLOR)"); @@ -5359,6 +5345,7 @@ void tst_QWidget::subtractOpaqueSiblings() #endif QWidget w; + w.setWindowTitle(QLatin1String(QTest::currentTestFunction())); w.setGeometry(50, 50, 300, 300); ColorWidget *large = new ColorWidget(&w, Qt::Widget, Qt::red); @@ -5392,10 +5379,11 @@ void tst_QWidget::subtractOpaqueSiblings() void tst_QWidget::deleteStyle() { QWidget widget; + widget.setWindowTitle(QLatin1String(QTest::currentTestFunction())); widget.setStyle(QStyleFactory::create(QLatin1String("Windows"))); widget.show(); delete widget.style(); - qApp->processEvents(); + QCoreApplication::processEvents(); } class TopLevelFocusCheck: public QWidget @@ -5403,21 +5391,21 @@ class TopLevelFocusCheck: public QWidget Q_OBJECT public: QLineEdit* edit; - TopLevelFocusCheck(QWidget* parent = 0) : QWidget(parent) + explicit TopLevelFocusCheck(QWidget *parent = nullptr) + : QWidget(parent), edit(new QLineEdit(this)) { - edit = new QLineEdit(this); edit->hide(); edit->installEventFilter(this); } public slots: - void mouseDoubleClickEvent ( QMouseEvent * /*event*/ ) + void mouseDoubleClickEvent ( QMouseEvent * /*event*/ ) override { edit->show(); edit->setFocus(Qt::OtherFocusReason); - qApp->processEvents(); + QCoreApplication::processEvents(); } - bool eventFilter(QObject *obj, QEvent *event) + bool eventFilter(QObject *obj, QEvent *event) override { if (obj == edit && event->type()== QEvent::FocusOut) { edit->hide(); @@ -5464,7 +5452,7 @@ void tst_QWidget::multipleToplevelFocusCheck() QVERIFY(QTest::qWaitForWindowActive(&w2)); QCOMPARE(QApplication::activeWindow(), static_cast<QWidget *>(&w2)); QTest::mouseClick(&w2, Qt::LeftButton); - QTRY_COMPARE(QApplication::focusWidget(), (QWidget *)0); + QTRY_COMPARE(QApplication::focusWidget(), nullptr); QTest::mouseDClick(&w2, Qt::LeftButton); QTRY_COMPARE(QApplication::focusWidget(), static_cast<QWidget *>(w2.edit)); @@ -5481,28 +5469,28 @@ void tst_QWidget::multipleToplevelFocusCheck() QVERIFY(QTest::qWaitForWindowActive(&w2)); QCOMPARE(QApplication::activeWindow(), static_cast<QWidget *>(&w2)); QTest::mouseClick(&w2, Qt::LeftButton); - QTRY_COMPARE(QApplication::focusWidget(), (QWidget *)0); + QTRY_COMPARE(QApplication::focusWidget(), nullptr); } class FocusWidget: public QWidget { protected: - virtual bool event(QEvent *ev) + bool event(QEvent *ev) override { if (ev->type() == QEvent::FocusAboutToChange) - widgetDuringFocusAboutToChange = qApp->focusWidget(); + widgetDuringFocusAboutToChange = QApplication::focusWidget(); return QWidget::event(ev); } - virtual void focusInEvent(QFocusEvent *) + void focusInEvent(QFocusEvent *) override { - foucsObjectDuringFocusIn = qApp->focusObject(); - detectedBadEventOrdering = foucsObjectDuringFocusIn != mostRecentFocusObjectChange; + focusObjectDuringFocusIn = QGuiApplication::focusObject(); + detectedBadEventOrdering = focusObjectDuringFocusIn != mostRecentFocusObjectChange; } - virtual void focusOutEvent(QFocusEvent *) + void focusOutEvent(QFocusEvent *) override { - foucsObjectDuringFocusOut = qApp->focusObject(); - widgetDuringFocusOut = qApp->focusWidget(); - detectedBadEventOrdering = foucsObjectDuringFocusOut != mostRecentFocusObjectChange; + focusObjectDuringFocusOut = QGuiApplication::focusObject(); + widgetDuringFocusOut = QApplication::focusWidget(); + detectedBadEventOrdering = focusObjectDuringFocusOut != mostRecentFocusObjectChange; } void focusObjectChanged(QObject *focusObject) @@ -5511,22 +5499,19 @@ protected: } public: - FocusWidget(QWidget *parent) : QWidget(parent), - widgetDuringFocusAboutToChange(0), widgetDuringFocusOut(0), - foucsObjectDuringFocusIn(0), foucsObjectDuringFocusOut(0), - mostRecentFocusObjectChange(0), detectedBadEventOrdering(false) + explicit FocusWidget(QWidget *parent) : QWidget(parent) { connect(qGuiApp, &QGuiApplication::focusObjectChanged, this, &FocusWidget::focusObjectChanged); } - QWidget *widgetDuringFocusAboutToChange; - QWidget *widgetDuringFocusOut; + QWidget *widgetDuringFocusAboutToChange = nullptr; + QWidget *widgetDuringFocusOut = nullptr; - QObject *foucsObjectDuringFocusIn; - QObject *foucsObjectDuringFocusOut; + QObject *focusObjectDuringFocusIn = nullptr; + QObject *focusObjectDuringFocusOut = nullptr; - QObject *mostRecentFocusObjectChange; - bool detectedBadEventOrdering; + QObject *mostRecentFocusObjectChange = nullptr; + bool detectedBadEventOrdering = false; }; void tst_QWidget::setFocus() @@ -5623,7 +5608,7 @@ void tst_QWidget::setFocus() window.show(); window.activateWindow(); QVERIFY(QTest::qWaitForWindowExposed(&window)); - QTRY_VERIFY(qGuiApp->focusWindow()); + QTRY_VERIFY(QGuiApplication::focusWindow()); child1.setFocus(); QTRY_VERIFY(child1.hasFocus()); @@ -5650,7 +5635,7 @@ void tst_QWidget::setFocus() window.show(); window.activateWindow(); QVERIFY(QTest::qWaitForWindowExposed(&window)); - QTRY_VERIFY(qGuiApp->focusWindow()); + QTRY_VERIFY(QGuiApplication::focusWindow()); QWidget child1(&window); child1.setFocusPolicy(Qt::StrongFocus); @@ -5691,7 +5676,7 @@ void tst_QWidget::setFocus() window.show(); window.activateWindow(); QVERIFY(QTest::qWaitForWindowExposed(&window)); - QTRY_VERIFY(qGuiApp->focusWindow()); + QTRY_VERIFY(QGuiApplication::focusWindow()); QWidget child1(&window); child1.setFocusPolicy(Qt::StrongFocus); @@ -5732,6 +5717,7 @@ void tst_QWidget::setFocus() { QWidget window; + window.setWindowTitle(QLatin1String(QTest::currentTestFunction())); window.resize(m_testWidgetSize); window.move(windowPos); @@ -5750,7 +5736,7 @@ void tst_QWidget::setFocus() QCOMPARE(window.focusWidget(), &child1); QCOMPARE(QApplication::focusWidget(), &child1); QCOMPARE(QApplication::focusObject(), &child1); - QCOMPARE(child1.foucsObjectDuringFocusIn, &child1); + QCOMPARE(child1.focusObjectDuringFocusIn, &child1); QVERIFY2(!child1.detectedBadEventOrdering, "focusObjectChanged should be delivered before widget focus events on setFocus"); @@ -5759,7 +5745,7 @@ void tst_QWidget::setFocus() QCOMPARE(window.focusWidget(), nullptr); QCOMPARE(QApplication::focusWidget(), nullptr); QCOMPARE(QApplication::focusObject(), &window); - QVERIFY(child1.foucsObjectDuringFocusOut != &child1); + QVERIFY(child1.focusObjectDuringFocusOut != &child1); QVERIFY2(!child1.detectedBadEventOrdering, "focusObjectChanged should be delivered before widget focus events on clearFocus"); } @@ -5769,7 +5755,7 @@ template<class T> class EventSpy : public QObject { public: EventSpy(T *widget, QEvent::Type event) - : m_widget(widget), eventToSpy(event), m_count(0) + : m_widget(widget), eventToSpy(event) { if (m_widget) m_widget->installEventFilter(this); @@ -5780,7 +5766,7 @@ public: void clear() { m_count = 0; } protected: - bool eventFilter(QObject *object, QEvent *event) + bool eventFilter(QObject *object, QEvent *event) override { if (event->type() == eventToSpy) ++m_count; @@ -5789,8 +5775,8 @@ protected: private: T *m_widget; - QEvent::Type eventToSpy; - int m_count; + const QEvent::Type eventToSpy; + int m_count = 0; }; #ifndef QT_NO_CURSOR @@ -5813,6 +5799,7 @@ void tst_QWidget::setCursor() // do it again, but with window show()n { QWidget window; + window.setWindowTitle(QLatin1String(QTest::currentTestFunction())); window.resize(200, 200); QWidget child(&window); window.show(); @@ -5841,6 +5828,7 @@ void tst_QWidget::setCursor() // same thing again, just with window show()n { QWidget window; + window.setWindowTitle(QLatin1String(QTest::currentTestFunction())); window.resize(200, 200); QWidget child(&window); @@ -5862,7 +5850,7 @@ void tst_QWidget::setCursor() window.setCursor(Qt::WaitCursor); - child.setParent(0); + child.setParent(nullptr); QVERIFY(!child.testAttribute(Qt::WA_SetCursor)); QCOMPARE(child.cursor().shape(), QCursor().shape()); @@ -5878,6 +5866,7 @@ void tst_QWidget::setCursor() // again, with windows show()n { QWidget window; + window.setWindowTitle(QLatin1String(QTest::currentTestFunction())); window.resize(200, 200); QWidget window2; window2.resize(200, 200); @@ -5886,7 +5875,7 @@ void tst_QWidget::setCursor() window.setCursor(Qt::WaitCursor); window.show(); - child.setParent(0); + child.setParent(nullptr); QVERIFY(!child.testAttribute(Qt::WA_SetCursor)); QCOMPARE(child.cursor().shape(), QCursor().shape()); @@ -5938,7 +5927,7 @@ void tst_QWidget::setToolTip() for (int pass = 0; pass < 2; ++pass) { QCursor::setPos(m_safeCursorPos); - QScopedPointer<QWidget> popup(new QWidget(0, Qt::Popup)); + QScopedPointer<QWidget> popup(new QWidget(nullptr, Qt::Popup)); popup->setObjectName(QLatin1String("tst_qwidget setToolTip #") + QString::number(pass)); popup->setWindowTitle(popup->objectName()); popup->setGeometry(50, 50, 150, 50); @@ -5947,7 +5936,7 @@ void tst_QWidget::setToolTip() frame->setFrameStyle(QFrame::Box | QFrame::Plain); EventSpy<QWidget> spy1(frame, QEvent::ToolTip); EventSpy<QWidget> spy2(popup.data(), QEvent::ToolTip); - frame->setMouseTracking(pass == 0 ? false : true); + frame->setMouseTracking(pass != 0); frame->setToolTip(QLatin1String("TOOLTIP FRAME")); popup->setToolTip(QLatin1String("TOOLTIP POPUP")); popup->show(); @@ -6001,13 +5990,13 @@ void tst_QWidget::testWindowIconChangeEventPropagation() // Create spy lists. QList <EventSpyPtr> applicationEventSpies; QList <EventSpyPtr> widgetEventSpies; - foreach (QWidget *widget, widgets) { + for (QWidget *widget : qAsConst(widgets)) { applicationEventSpies.append(EventSpyPtr::create(widget, QEvent::ApplicationWindowIconChange)); widgetEventSpies.append(EventSpyPtr::create(widget, QEvent::WindowIconChange)); } QList <WindowEventSpyPtr> appWindowEventSpies; QList <WindowEventSpyPtr> windowEventSpies; - foreach (QWindow *window, windows) { + for (QWindow *window : qAsConst(windows)) { appWindowEventSpies.append(WindowEventSpyPtr::create(window, QEvent::ApplicationWindowIconChange)); windowEventSpies.append(WindowEventSpyPtr::create(window, QEvent::WindowIconChange)); } @@ -6084,7 +6073,8 @@ void tst_QWidget::minAndMaxSizeWithX11BypassWindowManagerHint() const QSize originalSize(desktopSize.width() / 2, desktopSize.height() * 4 / 10); { // Maximum size. - QWidget widget(0, Qt::X11BypassWindowManagerHint); + QWidget widget(nullptr, Qt::X11BypassWindowManagerHint); + widget.setWindowTitle(QLatin1String(QTest::currentTestFunction())); const QSize newMaximumSize = widget.size().boundedTo(originalSize) - QSize(10, 10); widget.setMaximumSize(newMaximumSize); @@ -6096,7 +6086,8 @@ void tst_QWidget::minAndMaxSizeWithX11BypassWindowManagerHint() } { // Minimum size. - QWidget widget(0, Qt::X11BypassWindowManagerHint); + QWidget widget(nullptr, Qt::X11BypassWindowManagerHint); + widget.setWindowTitle(QLatin1String(QTest::currentTestFunction())); const QSize newMinimumSize = widget.size().expandedTo(originalSize) + QSize(10, 10); widget.setMinimumSize(newMinimumSize); @@ -6112,13 +6103,12 @@ class ShowHideShowWidget : public QWidget, public QAbstractNativeEventFilter { Q_OBJECT - int state; + int state = 0; public: - bool gotExpectedMapNotify; - bool gotExpectedGlobalEvent; + bool gotExpectedMapNotify = false; + bool gotExpectedGlobalEvent = false; ShowHideShowWidget() - : state(0), gotExpectedMapNotify(false), gotExpectedGlobalEvent(false) { startTimer(1000); } @@ -6140,7 +6130,7 @@ public: enum { XCB_MAP_NOTIFY = 19 }; if (state == 1 && eventType == QByteArrayLiteral("xcb_generic_event_t")) { // XCB events have a uint8 response_type member at the beginning. - const unsigned char responseType = *(const unsigned char *)(message); + const auto responseType = *reinterpret_cast<const unsigned char *>(message); return ((responseType & ~0x80) == XCB_MAP_NOTIFY); } return false; @@ -6179,6 +6169,7 @@ void tst_QWidget::showHideShowX11() QSKIP("This test is for X11 only."); ShowHideShowWidget w; + w.setWindowTitle(QLatin1String(QTest::currentTestFunction())); qApp->installNativeEventFilter(&w); w.show(); @@ -6186,7 +6177,7 @@ void tst_QWidget::showHideShowX11() w.hide(); QEventLoop eventLoop; - connect(&w, SIGNAL(done()), &eventLoop, SLOT(quit())); + connect(&w, &ShowHideShowWidget::done, &eventLoop, &QEventLoop::quit); eventLoop.exec(); QVERIFY(w.gotExpectedGlobalEvent); @@ -6200,6 +6191,7 @@ void tst_QWidget::clean_qt_x11_enforce_cursor() { QWidget window; + window.setWindowTitle(QLatin1String(QTest::currentTestFunction())); QWidget *w = new QWidget(&window); QWidget *child = new QWidget(w); child->setAttribute(Qt::WA_SetCursor, true); @@ -6233,11 +6225,9 @@ public: typedef QPair<QWidget *, QEvent::Type> WidgetEventTypePair; typedef QList<WidgetEventTypePair> EventList; - EventRecorder(QObject *parent = 0) - : QObject(parent) - { } + using QObject::QObject; - EventList eventList() + EventList eventList() const { return events; } @@ -6247,7 +6237,7 @@ public: events.clear(); } - bool eventFilter(QObject *object, QEvent *event) + bool eventFilter(QObject *object, QEvent *event) override { QWidget *widget = qobject_cast<QWidget *>(object); if (widget && !event->spontaneous()) @@ -6267,8 +6257,8 @@ private: void EventRecorder::formatEventList(const EventList &l, QDebug &d) { - QWidget *lastWidget = 0; - foreach (const WidgetEventTypePair &p, l) { + QWidget *lastWidget = nullptr; + for (const WidgetEventTypePair &p : l) { if (p.first != lastWidget) { d << p.first << ':'; lastWidget = p.first; @@ -6460,7 +6450,7 @@ void tst_QWidget::childEvents() QWidget child1(&widget); QWidget child2; child2.setParent(&widget); - child2.setParent(0); + child2.setParent(nullptr); QCoreApplication::postEvent(&widget, new QEvent(QEvent::Type(QEvent::User + 2))); @@ -6497,7 +6487,7 @@ void tst_QWidget::childEvents() QWidget child1(&widget); QWidget child2; child2.setParent(&widget); - child2.setParent(0); + child2.setParent(nullptr); QCoreApplication::postEvent(&widget, new QEvent(QEvent::Type(QEvent::User + 2))); @@ -6577,6 +6567,7 @@ void tst_QWidget::render() { return; QCalendarWidget source; + source.setWindowTitle(QLatin1String(QTest::currentTestFunction())); // disable anti-aliasing to eliminate potential differences when subpixel antialiasing // is enabled on the screen QFont f; @@ -6590,22 +6581,22 @@ void tst_QWidget::render() target.resize(source.size()); target.show(); - qApp->processEvents(); - qApp->sendPostedEvents(); + QCoreApplication::processEvents(); + QCoreApplication::sendPostedEvents(); QTest::qWait(250); const QImage sourceImage = source.grab(QRect(QPoint(0, 0), QSize(-1, -1))).toImage(); - qApp->processEvents(); + QCoreApplication::processEvents(); QImage targetImage = target.grab(QRect(QPoint(0, 0), QSize(-1, -1))).toImage(); - qApp->processEvents(); + QCoreApplication::processEvents(); QCOMPARE(sourceImage, targetImage); // Fill target.rect() will Qt::red and render // QRegion(0, 0, source->width(), source->height() / 2, QRegion::Ellipse) // of source into target with offset (0, 30). target.setEllipseEnabled(); - qApp->processEvents(); - qApp->sendPostedEvents(); + QCoreApplication::processEvents(); + QCoreApplication::sendPostedEvents(); targetImage = target.grab(QRect(QPoint(0, 0), QSize(-1, -1))).toImage(); QVERIFY(sourceImage != targetImage); @@ -6616,6 +6607,7 @@ void tst_QWidget::render() // Test that a child widget properly fills its background { QWidget window; + window.setWindowTitle(QLatin1String(QTest::currentTestFunction())); window.resize(100, 100); // prevent custom styles window.setStyle(QStyleFactory::create(QLatin1String("Windows"))); @@ -6625,7 +6617,7 @@ void tst_QWidget::render() child.resize(window.size()); child.show(); - qApp->processEvents(); + QCoreApplication::processEvents(); const QPixmap childPixmap = child.grab(QRect(QPoint(0, 0), QSize(-1, -1))); const QPixmap windowPixmap = window.grab(QRect(QPoint(0, 0), QSize(-1, -1))); QCOMPARE(childPixmap, windowPixmap); @@ -6633,6 +6625,7 @@ void tst_QWidget::render() { // Check that the target offset is correct. QWidget widget; + widget.setWindowTitle(QLatin1String(QTest::currentTestFunction())); widget.resize(200, 200); widget.setAutoFillBackground(true); widget.setPalette(Qt::red); @@ -6693,6 +6686,7 @@ void tst_QWidget::renderInvisible() QScopedPointer<QCalendarWidget> calendar(new QCalendarWidget); calendar->move(m_availableTopLeft + QPoint(100, 100)); + calendar->setWindowTitle(QLatin1String(QTest::currentTestFunction())); // disable anti-aliasing to eliminate potential differences when subpixel antialiasing // is enabled on the screen QFont f; @@ -6707,7 +6701,7 @@ void tst_QWidget::renderInvisible() dummyFocusWidget.move(calendar->geometry().bottomLeft() + QPoint(0, 100)); dummyFocusWidget.show(); QVERIFY(QTest::qWaitForWindowExposed(&dummyFocusWidget)); - qApp->processEvents(); + QCoreApplication::processEvents(); QTest::qWait(120); // Create normal reference image. @@ -6722,7 +6716,7 @@ void tst_QWidget::renderInvisible() // Create resized reference image. const QSize calendarSizeResized = calendar->size() + QSize(50, 50); calendar->resize(calendarSizeResized); - qApp->processEvents(); + QCoreApplication::processEvents(); QTest::qWait(30); QImage referenceImageResized(calendarSizeResized, QImage::Format_ARGB32); calendar->render(&referenceImageResized); @@ -6733,7 +6727,7 @@ void tst_QWidget::renderInvisible() // Explicitly hide the calendar. calendar->hide(); - qApp->processEvents(); + QCoreApplication::processEvents(); QTest::qWait(30); workaroundPaletteIssue(calendar.data()); @@ -6763,7 +6757,7 @@ void tst_QWidget::renderInvisible() } calendar->hide(); - qApp->processEvents(); + QCoreApplication::processEvents(); QTest::qWait(30); { // Calendar explicitly hidden. @@ -6831,7 +6825,7 @@ void tst_QWidget::renderInvisible() // Navigation bar isn't explicitly hidden anymore. navigationBar->show(); - qApp->processEvents(); + QCoreApplication::processEvents(); QTest::qWait(30); QVERIFY(!calendar->isVisible()); @@ -6840,7 +6834,7 @@ void tst_QWidget::renderInvisible() // make sure the layout is activated before rendering. QVERIFY(!calendar->isVisible()); calendar->resize(calendarSizeResized); - qApp->processEvents(); + QCoreApplication::processEvents(); { // Make sure we get an image equal to the resized reference image. QImage testImage(calendarSizeResized, QImage::Format_ARGB32); @@ -6893,7 +6887,7 @@ void tst_QWidget::renderInvisible() void tst_QWidget::renderWithPainter() { - QWidget widget(0, Qt::Tool); + QWidget widget(nullptr, Qt::Tool); // prevent custom styles const QScopedPointer<QStyle> style(QStyleFactory::create(QLatin1String("Windows"))); @@ -7009,7 +7003,7 @@ void tst_QWidget::render_task211796() { class MyWidget : public QWidget { - void resizeEvent(QResizeEvent *) + void resizeEvent(QResizeEvent *) override { QPixmap pixmap(size()); render(&pixmap); @@ -7018,6 +7012,7 @@ void tst_QWidget::render_task211796() { // Please don't die in a resize recursion. MyWidget widget; + widget.setWindowTitle(QLatin1String(QTest::currentTestFunction())); widget.resize(m_testWidgetSize); centerOnScreen(&widget); widget.show(); @@ -7025,6 +7020,7 @@ void tst_QWidget::render_task211796() { // Same check with a deeper hierarchy. QWidget widget; + widget.setWindowTitle(QLatin1String(QTest::currentTestFunction())); widget.resize(m_testWidgetSize); centerOnScreen(&widget); widget.show(); @@ -7093,19 +7089,19 @@ void tst_QWidget::render_windowOpacity() class MyWidget : public QWidget { public: - void paintEvent(QPaintEvent *) + explicit MyWidget(qreal opacityIn) : opacity(opacityIn) {} + void paintEvent(QPaintEvent *) override { QPainter painter(this); painter.setOpacity(opacity); QCOMPARE(painter.opacity(), opacity); painter.fillRect(rect(), Qt::red); } - qreal opacity; + const qreal opacity; }; - MyWidget widget; + MyWidget widget(opacity); widget.resize(50, 50); - widget.opacity = opacity; widget.setPalette(Qt::blue); widget.setAutoFillBackground(true); @@ -7242,16 +7238,16 @@ void tst_QWidget::render_systemClip2() class MyWidget : public QWidget { public: - bool usePaintEvent; - void paintEvent(QPaintEvent *) + explicit MyWidget(bool usePaintEventIn) : usePaintEvent(usePaintEventIn) {} + const bool usePaintEvent; + void paintEvent(QPaintEvent *) override { if (usePaintEvent) QPainter(this).fillRect(rect(), Qt::green); } }; - MyWidget widget; - widget.usePaintEvent = usePaintEvent; + MyWidget widget(usePaintEvent); widget.setPalette(Qt::blue); // NB! widget.setAutoFillBackground(autoFillBackground) won't do the // trick here since the widget is a top-level. The background is filled @@ -7347,7 +7343,6 @@ void tst_QWidget::render_systemClip3() const QRegion redArea(QRegion(0, 0, size.width(), size.height()) - outerCross); const QRegion whiteArea(outerCross - innerCross); - const QRegion blueArea(innerCross); QRegion systemClip; // Okay, here's the image that should look like a Norwegian civil/war flag in the end. @@ -7373,8 +7368,9 @@ void tst_QWidget::render_systemClip3() // The outer cross (white) should be drawn when the background is auto-filled, and // the inner cross (blue) should be drawn in the paintEvent. class MyWidget : public QWidget - { public: - void paintEvent(QPaintEvent *) + { + public: + void paintEvent(QPaintEvent *) override { QPainter painter(this); // Be evil and try to paint outside the outer cross. This should not be @@ -7429,8 +7425,9 @@ void tst_QWidget::render_task252837() void tst_QWidget::render_worldTransform() { class MyWidget : public QWidget - { public: - void paintEvent(QPaintEvent *) + { + public: + void paintEvent(QPaintEvent *) override { QPainter painter(this); // Make sure world transform is identity. @@ -7524,6 +7521,7 @@ void tst_QWidget::setContentsMargins() QVERIFY2(oldSize != newSize, msgComparisonFailed(oldSize, "!=", newSize)); QLabel label2("why does it always rain on me?"); + label2.setWindowTitle(QLatin1String(QTest::currentTestFunction())); label2.show(); label2.setFrameStyle(QFrame::Sunken | QFrame::Box); QCOMPARE(newSize, label2.sizeHint()); @@ -7556,7 +7554,7 @@ void tst_QWidget::moveWindowInShowEvent() { public: QPoint position; - void showEvent(QShowEvent *) + void showEvent(QShowEvent *) override { move(position); } @@ -7587,7 +7585,8 @@ void tst_QWidget::repaintWhenChildDeleted() QTest::qWait(1000); } #endif - ColorWidget w(0, Qt::FramelessWindowHint, Qt::red); + ColorWidget w(nullptr, Qt::FramelessWindowHint, Qt::red); + w.setWindowTitle(QLatin1String(QTest::currentTestFunction())); QPoint startPoint = QApplication::desktop()->availableGeometry(&w).topLeft(); startPoint.rx() += 50; startPoint.ry() += 50; @@ -7611,7 +7610,8 @@ void tst_QWidget::repaintWhenChildDeleted() // task 175114 void tst_QWidget::hideOpaqueChildWhileHidden() { - ColorWidget w(0, Qt::FramelessWindowHint, Qt::red); + ColorWidget w(nullptr, Qt::FramelessWindowHint, Qt::red); + w.setWindowTitle(QLatin1String(QTest::currentTestFunction())); QPoint startPoint = QApplication::desktop()->availableGeometry(&w).topLeft(); startPoint.rx() += 50; startPoint.ry() += 50; @@ -7654,6 +7654,7 @@ void tst_QWidget::updateWhileMinimized() QSKIP("Platform does not support showMinimized()"); #endif UpdateWidget widget; + widget.setWindowTitle(QLatin1String(QTest::currentTestFunction())); // Filter out activation change and focus events to avoid update() calls in QWidget. widget.updateOnActivationChangeAndFocusIn = false; widget.reset(); @@ -7685,13 +7686,10 @@ void tst_QWidget::updateWhileMinimized() class PaintOnScreenWidget: public QWidget { public: - PaintOnScreenWidget(QWidget *parent = 0, Qt::WindowFlags f = 0) - :QWidget(parent, f) - { - } + using QWidget::QWidget; #if defined(Q_OS_WIN) // This is the only way to enable PaintOnScreen on Windows. - QPaintEngine * paintEngine () const {return 0;} + QPaintEngine *paintEngine() const override { return nullptr; } #endif }; @@ -7702,6 +7700,7 @@ void tst_QWidget::alienWidgets() qApp->setAttribute(Qt::AA_DontCreateNativeWidgetSiblings); QWidget parent; + parent.setWindowTitle(QLatin1String(QTest::currentTestFunction())); parent.resize(m_testWidgetSize); QWidget child(&parent); QWidget grandChild(&child); @@ -7736,6 +7735,7 @@ void tst_QWidget::alienWidgets() // Ensure that hide() on an ancestor of a widget with // Qt::WA_DontCreateNativeAncestors still gets unmapped QWidget window; + window.setWindowTitle(QLatin1String(QTest::currentTestFunction())); window.resize(m_testWidgetSize); QWidget widget(&window); QWidget child(&widget); @@ -7779,6 +7779,7 @@ void tst_QWidget::alienWidgets() // Check that widgets with the Qt::MSWindowsOwnDC attribute set // are native. QWidget msWindowsOwnDC(&parent, Qt::MSWindowsOwnDC); + msWindowsOwnDC.setWindowTitle(QLatin1String(QTest::currentTestFunction())); msWindowsOwnDC.show(); QVERIFY(msWindowsOwnDC.testAttribute(Qt::WA_WState_Created)); QVERIFY(msWindowsOwnDC.testAttribute(Qt::WA_NativeWindow)); @@ -7807,6 +7808,7 @@ void tst_QWidget::alienWidgets() { // Make sure we create native ancestors when setting Qt::WA_PaintOnScreen before show(). QWidget topLevel; + topLevel.setWindowTitle(QLatin1String(QTest::currentTestFunction())); topLevel.resize(m_testWidgetSize); QWidget child(&topLevel); QWidget grandChild(&child); @@ -7831,6 +7833,7 @@ void tst_QWidget::alienWidgets() { // Ensure that widgets reparented into Qt::WA_PaintOnScreen widgets become native. QWidget topLevel; + topLevel.setWindowTitle(QLatin1String(QTest::currentTestFunction())); topLevel.resize(m_testWidgetSize); QWidget *widget = new PaintOnScreenWidget(&topLevel); widget->setAttribute(Qt::WA_PaintOnScreen); @@ -7864,6 +7867,7 @@ void tst_QWidget::alienWidgets() { // Ensure that ancestors of a Qt::WA_PaintOnScreen widget stay native // if they are re-created (typically in QWidgetPrivate::setParent_sys) (task 210822). QWidget window; + window.setWindowTitle(QLatin1String(QTest::currentTestFunction())); window.resize(m_testWidgetSize); QWidget child(&window); @@ -7902,6 +7906,7 @@ void tst_QWidget::alienWidgets() { // Ensure that all siblings are native unless Qt::AA_DontCreateNativeWidgetSiblings is set. qApp->setAttribute(Qt::AA_DontCreateNativeWidgetSiblings, false); QWidget mainWindow; + mainWindow.setWindowTitle(QLatin1String(QTest::currentTestFunction())); QWidget *toolBar = new QWidget(&mainWindow); QWidget *dockWidget = new QWidget(&mainWindow); QWidget *centralWidget = new QWidget(&mainWindow); @@ -7936,7 +7941,7 @@ void tst_QWidget::alienWidgets() class ASWidget : public QWidget { public: - ASWidget(QSize sizeHint, QSizePolicy sizePolicy, bool layout, bool hfwLayout, QWidget *parent = 0) + ASWidget(QSize sizeHint, QSizePolicy sizePolicy, bool layout, bool hfwLayout, QWidget *parent = nullptr) : QWidget(parent), mySizeHint(sizeHint) { setObjectName(QStringLiteral("ASWidget")); @@ -7953,17 +7958,15 @@ public: } } - QSize sizeHint() const { + QSize sizeHint() const override + { if (layout()) return layout()->totalSizeHint(); return mySizeHint; } - int heightForWidth(int width) const { - if (sizePolicy().hasHeightForWidth()) { - return width * 2; - } else { - return -1; - } + int heightForWidth(int width) const override + { + return sizePolicy().hasHeightForWidth() ? width * 2 : -1; } QSize mySizeHint; @@ -8038,7 +8041,7 @@ void tst_QWidget::adjustSize() QSizePolicy sp = QSizePolicy(QSizePolicy::Policy(hPolicy), QSizePolicy::Policy(vPolicy)); sp.setHeightForWidth(hfwSP); - QWidget *child = new ASWidget(sizeHint, sp, layout, hfwLayout, haveParent ? parent.data() : 0); + QWidget *child = new ASWidget(sizeHint, sp, layout, hfwLayout, haveParent ? parent.data() : nullptr); child->resize(123, 456); child->adjustSize(); if (expectedSize == QSize(100000, 100000)) { @@ -8057,17 +8060,14 @@ class TestLayout : public QVBoxLayout { Q_OBJECT public: - TestLayout(QWidget *w = 0) : QVBoxLayout(w) - { - invalidated = false; - } + using QVBoxLayout::QVBoxLayout; - void invalidate() + void invalidate() override { invalidated = true; } - bool invalidated; + bool invalidated = false; }; void tst_QWidget::updateGeometry_data() @@ -8076,7 +8076,7 @@ void tst_QWidget::updateGeometry_data() QTest::addColumn<bool>("shouldInvalidate"); QTest::addColumn<QSize>("maxSize"); QTest::addColumn<bool>("shouldInvalidate2"); - QTest::addColumn<int>("verticalSizePolicy"); + QTest::addColumn<QSizePolicy::Policy>("verticalSizePolicy"); QTest::addColumn<bool>("shouldInvalidate3"); QTest::addColumn<bool>("setVisible"); QTest::addColumn<bool>("shouldInvalidate4"); @@ -8084,32 +8084,32 @@ void tst_QWidget::updateGeometry_data() QTest::newRow("setMinimumSize") << QSize(100, 100) << true << QSize() << false - << int(QSizePolicy::Preferred) << false + << QSizePolicy::Preferred << false << true << false; QTest::newRow("setMaximumSize") << QSize() << false << QSize(100, 100) << true - << int(QSizePolicy::Preferred) << false + << QSizePolicy::Preferred << false << true << false; QTest::newRow("setMinimumSize, then maximumSize to a different size") << QSize(100, 100) << true << QSize(300, 300) << true - << int(QSizePolicy::Preferred) << false + << QSizePolicy::Preferred << false << true << false; QTest::newRow("setMinimumSize, then maximumSize to the same size") << QSize(100, 100) << true << QSize(100, 100) << true - << int(QSizePolicy::Preferred) << false + << QSizePolicy::Preferred << false << true << false; QTest::newRow("setMinimumSize, then maximumSize to the same size and then hide it") << QSize(100, 100) << true << QSize(100, 100) << true - << int(QSizePolicy::Preferred) << false + << QSizePolicy::Preferred << false << false << true; QTest::newRow("Change sizePolicy") << QSize() << false << QSize() << false - << int(QSizePolicy::Minimum) << true + << QSizePolicy::Minimum << true << true << false; } @@ -8120,11 +8120,13 @@ void tst_QWidget::updateGeometry() QFETCH(bool, shouldInvalidate); QFETCH(QSize, maxSize); QFETCH(bool, shouldInvalidate2); - QFETCH(int, verticalSizePolicy); + QFETCH(QSizePolicy::Policy, verticalSizePolicy); QFETCH(bool, shouldInvalidate3); QFETCH(bool, setVisible); QFETCH(bool, shouldInvalidate4); QWidget parent; + parent.setWindowTitle(QLatin1String(QTest::currentTestFunction()) + QLatin1String("::") + + QLatin1String(QTest::currentDataTag())); parent.resize(200, 200); TestLayout *lout = new TestLayout(); parent.setLayout(lout); @@ -8144,7 +8146,7 @@ void tst_QWidget::updateGeometry() QCOMPARE(lout->invalidated, shouldInvalidate2); lout->invalidated = false; - child->setSizePolicy(QSizePolicy(QSizePolicy::Preferred, (QSizePolicy::Policy)verticalSizePolicy)); + child->setSizePolicy(QSizePolicy(QSizePolicy::Preferred, verticalSizePolicy)); if (shouldInvalidate3) QCOMPARE(lout->invalidated, true); @@ -8157,11 +8159,12 @@ void tst_QWidget::updateGeometry() void tst_QWidget::sendUpdateRequestImmediately() { UpdateWidget updateWidget; + updateWidget.setWindowTitle(QLatin1String(QTest::currentTestFunction())); updateWidget.show(); QVERIFY(QTest::qWaitForWindowExposed(&updateWidget)); - qApp->processEvents(); + QCoreApplication::processEvents(); updateWidget.reset(); QCOMPARE(updateWidget.numUpdateRequestEvents, 0); @@ -8180,6 +8183,7 @@ void tst_QWidget::doubleRepaint() QSKIP("Not having window server access causes the wrong number of repaints to be issues"); #endif UpdateWidget widget; + widget.setWindowTitle(QLatin1String(QTest::currentTestFunction())); centerOnScreen(&widget); widget.setFocusPolicy(Qt::StrongFocus); // Filter out activation change and focus events to avoid update() calls in QWidget. @@ -8213,10 +8217,11 @@ void tst_QWidget::doubleRepaint() void tst_QWidget::resizeInPaintEvent() { QWidget window; + window.setWindowTitle(QLatin1String(QTest::currentTestFunction())); UpdateWidget widget(&window); window.resize(200, 200); window.show(); - qApp->setActiveWindow(&window); + QApplication::setActiveWindow(&window); QVERIFY(QTest::qWaitForWindowExposed(&window)); QTRY_VERIFY(widget.numPaintEvents > 0); @@ -8237,6 +8242,7 @@ void tst_QWidget::resizeInPaintEvent() void tst_QWidget::opaqueChildren() { QWidget widget; + widget.setWindowTitle(QLatin1String(QTest::currentTestFunction())); widget.resize(200, 200); QWidget child(&widget); @@ -8277,10 +8283,10 @@ class MaskSetWidget : public QWidget { Q_OBJECT public: - MaskSetWidget(QWidget* p =0) - : QWidget(p) {} + using QWidget::QWidget; - void paintEvent(QPaintEvent* event) { + void paintEvent(QPaintEvent *event) override + { QPainter p(this); paintedRegion += event->region(); @@ -8288,26 +8294,22 @@ public: p.fillRect(r, Qt::red); } - void resizeEvent(QResizeEvent*) { + void resizeEvent(QResizeEvent *) override + { setMask(QRegion(QRect(0, 0, width(), 10).normalized())); } QRegion paintedRegion; public slots: - void resizeDown() { - setGeometry(QRect(0, 50, 50, 50)); - } - - void resizeUp() { - setGeometry(QRect(0, 50, 150, 50)); - } - + void resizeDown() { setGeometry(QRect(0, 50, 50, 50)); } + void resizeUp() { setGeometry(QRect(0, 50, 150, 50)); } }; void tst_QWidget::setMaskInResizeEvent() { UpdateWidget w; + w.setWindowTitle(QLatin1String(QTest::currentTestFunction())); w.reset(); w.resize(200, 200); centerOnScreen(&w); @@ -8346,19 +8348,19 @@ class MoveInResizeWidget : public QWidget { Q_OBJECT public: - MoveInResizeWidget(QWidget* p = 0) + explicit MoveInResizeWidget(QWidget *p = nullptr) : QWidget(p) { setWindowFlags(Qt::FramelessWindowHint); } - void resizeEvent(QResizeEvent*) { - + void resizeEvent(QResizeEvent *) override + { move(QPoint(100,100)); static bool firstTime = true; if (firstTime) - QTimer::singleShot(250, this, SLOT(resizeMe())); + QTimer::singleShot(250, this, &MoveInResizeWidget::resizeMe); firstTime = false; } @@ -8372,6 +8374,7 @@ public slots: void tst_QWidget::moveInResizeEvent() { MoveInResizeWidget testWidget; + testWidget.setWindowTitle(QLatin1String(QTest::currentTestFunction())); testWidget.setGeometry(50, 50, 200, 200); testWidget.show(); QVERIFY(QTest::qWaitForWindowExposed(&testWidget)); @@ -8387,6 +8390,7 @@ void tst_QWidget::immediateRepaintAfterInvalidateBackingStore() QSKIP("We don't support immediate repaint right after show on other platforms."); QScopedPointer<UpdateWidget> widget(new UpdateWidget); + widget->setWindowTitle(QLatin1String(QTest::currentTestFunction())); centerOnScreen(widget.data()); widget->show(); QVERIFY(QTest::qWaitForWindowExposed(widget.data())); @@ -8409,6 +8413,7 @@ void tst_QWidget::immediateRepaintAfterInvalidateBackingStore() void tst_QWidget::effectiveWinId() { QWidget parent; + parent.setWindowTitle(QLatin1String(QTest::currentTestFunction())); parent.resize(200, 200); QWidget child(&parent); @@ -8426,8 +8431,9 @@ void tst_QWidget::effectiveWinId2() { QWidget parent; - class MyWidget : public QWidget { - bool event(QEvent *e) + class MyWidget : public QWidget + { + bool event(QEvent *e) override { if (e->type() == QEvent::WinIdChange) { // Shouldn't crash. @@ -8442,18 +8448,19 @@ void tst_QWidget::effectiveWinId2() child.setParent(&parent); parent.show(); - child.setParent(0); + child.setParent(nullptr); child.setParent(&parent); } class CustomWidget : public QWidget { public: - mutable int metricCallCount; + mutable int metricCallCount = 0; - CustomWidget(QWidget *parent = 0) : QWidget(parent), metricCallCount(0) {} + using QWidget::QWidget; - virtual int metric(PaintDeviceMetric metric) const { + int metric(PaintDeviceMetric metric) const override + { ++metricCallCount; return QWidget::metric(metric); } @@ -8547,6 +8554,7 @@ void tst_QWidget::quitOnCloseAttribute() void tst_QWidget::moveRect() { QWidget widget; + widget.setWindowTitle(QLatin1String(QTest::currentTestFunction())); widget.resize(200, 200); widget.setUpdatesEnabled(false); QWidget child(&widget); @@ -8567,11 +8575,12 @@ public: timer.setSingleShot(true); timer.setInterval(0); } - QPaintEngine *paintEngine() const { return 0; } + QPaintEngine *paintEngine() const override { return nullptr; } - void paintEvent(QPaintEvent *) { + void paintEvent(QPaintEvent *) override + { QPlatformNativeInterface *ni = QGuiApplication::platformNativeInterface(); - const HDC hdc = (HDC)ni->nativeResourceForWindow(QByteArrayLiteral("getDC"), windowHandle()); + const auto hdc = reinterpret_cast<HDC>(ni->nativeResourceForWindow(QByteArrayLiteral("getDC"), windowHandle())); if (hdc) { const HBRUSH brush = CreateSolidBrush(RGB(255, 0, 0)); SelectObject(hdc, brush); @@ -8588,9 +8597,7 @@ public: } } - QSize sizeHint() const { - return QSize(400, 300); - } + QSize sizeHint() const override { return {400, 300}; }; private slots: void slotTimer() { @@ -8617,6 +8624,7 @@ void tst_QWidget::gdiPainting() void tst_QWidget::paintOnScreenPossible() { QWidget w1; + w1.setWindowTitle(QLatin1String(QTest::currentTestFunction())); w1.setAttribute(Qt::WA_PaintOnScreen); QVERIFY(!w1.testAttribute(Qt::WA_PaintOnScreen)); @@ -8673,7 +8681,7 @@ void tst_QWidget::reparentStaticWidget() window2.resize(window2.size() + QSize(2, 2)); QTest::qWait(20); - child->setParent(0); + child->setParent(nullptr); child->show(); QTest::qWait(20); @@ -8743,12 +8751,13 @@ void tst_QWidget::QTBUG6883_reparentStaticWidget2() class ColorRedWidget : public QWidget { public: - ColorRedWidget(QWidget *parent = 0) + explicit ColorRedWidget(QWidget *parent = nullptr) : QWidget(parent, Qt::FramelessWindowHint | Qt::WindowStaysOnTopHint | Qt::ToolTip) { } - void paintEvent(QPaintEvent *) { + void paintEvent(QPaintEvent *) override + { QPainter p(this); p.fillRect(rect(),Qt::red); } @@ -8759,6 +8768,7 @@ void tst_QWidget::translucentWidget() QPixmap pm(16,16); pm.fill(Qt::red); ColorRedWidget label; + label.setWindowTitle(QLatin1String(QTest::currentTestFunction())); label.setFixedSize(16,16); label.setAttribute(Qt::WA_TranslucentBackground); const QPoint labelPos = QGuiApplication::primaryScreen()->availableGeometry().topLeft(); @@ -8787,12 +8797,13 @@ class MaskResizeTestWidget : public QWidget { Q_OBJECT public: - MaskResizeTestWidget(QWidget* p =0) - : QWidget(p) { + explicit MaskResizeTestWidget(QWidget* p = nullptr) : QWidget(p) + { setMask(QRegion(QRect(0, 0, 100, 100).normalized())); } - void paintEvent(QPaintEvent* event) { + void paintEvent(QPaintEvent* event) override + { QPainter p(this); paintedRegion += event->region(); @@ -8818,10 +8829,11 @@ public slots: void tst_QWidget::setClearAndResizeMask() { UpdateWidget topLevel; + topLevel.setWindowTitle(QLatin1String(QTest::currentTestFunction())); topLevel.resize(160, 160); centerOnScreen(&topLevel); topLevel.show(); - qApp->setActiveWindow(&topLevel); + QApplication::setActiveWindow(&topLevel); QVERIFY(QTest::qWaitForWindowExposed(&topLevel)); QTRY_VERIFY(topLevel.numPaintEvents > 0); topLevel.reset(); @@ -8968,6 +8980,7 @@ void tst_QWidget::setClearAndResizeMask() void tst_QWidget::maskedUpdate() { UpdateWidget topLevel; + topLevel.setWindowTitle(QLatin1String(QTest::currentTestFunction())); topLevel.resize(200, 200); centerOnScreen(&topLevel); const QRegion topLevelMask(50, 50, 70, 70); @@ -9121,16 +9134,17 @@ void tst_QWidget::syntheticEnterLeave() class MyWidget : public QWidget { public: - MyWidget(QWidget *parent = 0) : QWidget(parent), numEnterEvents(0), numLeaveEvents(0) {} - void enterEvent(QEvent *) { ++numEnterEvents; } - void leaveEvent(QEvent *) { ++numLeaveEvents; } - int numEnterEvents; - int numLeaveEvents; + using QWidget::QWidget; + void enterEvent(QEvent *) override { ++numEnterEvents; } + void leaveEvent(QEvent *) override { ++numLeaveEvents; } + int numEnterEvents = 0; + int numLeaveEvents = 0; }; QCursor::setPos(m_safeCursorPos); MyWidget window; + window.setWindowTitle(QLatin1String(QTest::currentTestFunction())); window.setWindowFlags(Qt::WindowStaysOnTopHint); window.move(200, 200); window.resize(200, 200); @@ -9226,31 +9240,32 @@ void tst_QWidget::taskQTBUG_4055_sendSyntheticEnterLeave() class SELParent : public QWidget { public: - SELParent(QWidget *parent = 0): QWidget(parent) { } + using QWidget::QWidget; - void mousePressEvent(QMouseEvent *) { child->show(); } - QWidget *child; + void mousePressEvent(QMouseEvent *) override { child->show(); } + QWidget *child = nullptr; }; class SELChild : public QWidget - { - public: - SELChild(QWidget *parent = 0) : QWidget(parent), numEnterEvents(0), numMouseMoveEvents(0) {} - void enterEvent(QEvent *) { ++numEnterEvents; } - void mouseMoveEvent(QMouseEvent *event) - { - QCOMPARE(event->button(), Qt::NoButton); - QCOMPARE(event->buttons(), QApplication::mouseButtons()); - QCOMPARE(event->modifiers(), QApplication::keyboardModifiers()); - ++numMouseMoveEvents; - } - void reset() { numEnterEvents = numMouseMoveEvents = 0; } - int numEnterEvents, numMouseMoveEvents; - }; + { + public: + using QWidget::QWidget; + void enterEvent(QEvent *) override { ++numEnterEvents; } + void mouseMoveEvent(QMouseEvent *event) override + { + QCOMPARE(event->button(), Qt::NoButton); + QCOMPARE(event->buttons(), QApplication::mouseButtons()); + QCOMPARE(event->modifiers(), QApplication::keyboardModifiers()); + ++numMouseMoveEvents; + } + void reset() { numEnterEvents = numMouseMoveEvents = 0; } + int numEnterEvents = 0, numMouseMoveEvents = 0; + }; QCursor::setPos(m_safeCursorPos); SELParent parent; + parent.setWindowTitle(QLatin1String(QTest::currentTestFunction())); parent.move(200, 200); parent.resize(200, 200); SELChild child(&parent); @@ -9350,9 +9365,9 @@ class MyEvilObject : public QObject { Q_OBJECT public: - MyEvilObject(QWidget *widgetToCrash) : QObject(), widget(widgetToCrash) + explicit MyEvilObject(QWidget *widgetToCrash) : QObject(), widget(widgetToCrash) { - connect(widget, SIGNAL(destroyed(QObject*)), this, SLOT(beEvil(QObject*))); + connect(widget, &QObject::destroyed, this, &MyEvilObject::beEvil); delete widget; } QWidget *widget; @@ -9364,6 +9379,7 @@ private slots: void tst_QWidget::updateOnDestroyedSignal() { QWidget widget; + widget.setWindowTitle(QLatin1String(QTest::currentTestFunction())); QWidget *child = new QWidget(&widget); child->resize(m_testWidgetSize); @@ -9381,18 +9397,20 @@ void tst_QWidget::updateOnDestroyedSignal() void tst_QWidget::toplevelLineEditFocus() { QLineEdit w; + w.setWindowTitle(QLatin1String(QTest::currentTestFunction())); w.setMinimumWidth(m_testWidgetSize.width()); w.show(); QVERIFY(QTest::qWaitForWindowExposed(&w)); - QTRY_COMPARE(QApplication::activeWindow(), (QWidget*)&w); - QTRY_COMPARE(QApplication::focusWidget(), (QWidget*)&w); + QTRY_COMPARE(QApplication::activeWindow(), static_cast<const QWidget *>(&w)); + QTRY_COMPARE(QApplication::focusWidget(), static_cast<const QWidget *>(&w)); } void tst_QWidget::focusWidget_task254563() { //having different visibility for widget is important QWidget top; + top.setWindowTitle(QLatin1String(QTest::currentTestFunction())); top.show(); QWidget container(&top); QWidget *widget = new QWidget(&container); @@ -9409,6 +9427,7 @@ void tst_QWidget::focusWidget_task254563() void tst_QWidget::destroyBackingStore() { UpdateWidget w; + w.setWindowTitle(QLatin1String(QTest::currentTestFunction())); centerOnScreen(&w); w.reset(); w.show(); @@ -9435,7 +9454,7 @@ void tst_QWidget::destroyBackingStore() // Helper function QWidgetBackingStore* backingStore(QWidget &widget) { - QWidgetBackingStore *backingStore = 0; + QWidgetBackingStore *backingStore = nullptr; #ifdef QT_BUILD_INTERNAL if (QTLWExtra *topExtra = qt_widget_private(&widget)->maybeTopData()) backingStore = topExtra->backingStoreTracker.data(); @@ -9449,7 +9468,8 @@ void tst_QWidget::rectOutsideCoordinatesLimit_task144779() #ifndef QT_NO_CURSOR QGuiApplication::setOverrideCursor(Qt::BlankCursor); //keep the cursor out of screen grabs #endif - QWidget main(0,Qt::FramelessWindowHint); //don't get confused by the size of the window frame + QWidget main(nullptr, Qt::FramelessWindowHint); //don't get confused by the size of the window frame + main.setWindowTitle(QLatin1String(QTest::currentTestFunction())); QPalette palette; palette.setColor(QPalette::Window, Qt::red); main.setPalette(palette); @@ -9492,6 +9512,7 @@ void tst_QWidget::setGraphicsEffect() { // Check that we don't have any effect by default. QScopedPointer<QWidget> widget(new QWidget); + widget->setWindowTitle(QLatin1String(QTest::currentTestFunction())); QVERIFY(!widget->graphicsEffect()); // SetGet check. @@ -9528,7 +9549,7 @@ void tst_QWidget::setGraphicsEffect() // Ensure the existing effect is uninstalled and deleted when setting a null effect blurEffect = new QGraphicsBlurEffect; widget->setGraphicsEffect(blurEffect); - widget->setGraphicsEffect(0); + widget->setGraphicsEffect(nullptr); QVERIFY(!widget->graphicsEffect()); QVERIFY(!blurEffect); } @@ -9542,6 +9563,7 @@ void tst_QWidget::activateWindow() // Create first mainwindow and set it active QScopedPointer<QMainWindow> mainwindow(new QMainWindow); + mainwindow->setWindowTitle(QLatin1String(QTest::currentTestFunction())); QLabel* label = new QLabel(mainwindow.data()); label->setMinimumWidth(m_testWidgetSize.width()); mainwindow->setWindowTitle(QStringLiteral("#1 ") + __FUNCTION__); @@ -9561,7 +9583,7 @@ void tst_QWidget::activateWindow() mainwindow2->move(mainwindow->geometry().bottomLeft() + QPoint(0, 50)); mainwindow2->setVisible(true); mainwindow2->activateWindow(); - qApp->processEvents(); + QCoreApplication::processEvents(); QTRY_VERIFY(!mainwindow->isActiveWindow()); QTRY_VERIFY(mainwindow2->isActiveWindow()); @@ -9569,7 +9591,7 @@ void tst_QWidget::activateWindow() // Revert first mainwindow back to visible active mainwindow->setVisible(true); mainwindow->activateWindow(); - qApp->processEvents(); + QCoreApplication::processEvents(); QTRY_VERIFY(mainwindow->isActiveWindow()); if (m_platform == QStringLiteral("winrt")) @@ -9605,7 +9627,8 @@ void tst_QWidget::focusProxyAndInputMethods() { if (!QGuiApplicationPrivate::platformIntegration()->hasCapability(QPlatformIntegration::WindowActivation)) QSKIP("Window activation is not supported."); - QScopedPointer<QWidget> toplevel(new QWidget(0, Qt::X11BypassWindowManagerHint)); + QScopedPointer<QWidget> toplevel(new QWidget(nullptr, Qt::X11BypassWindowManagerHint)); + toplevel->setWindowTitle(QLatin1String(QTest::currentTestFunction())); toplevel->resize(200, 200); toplevel->setAttribute(Qt::WA_InputMethodEnabled, true); @@ -9652,6 +9675,7 @@ public: void tst_QWidget::scrollWithoutBackingStore() { scrollWidgetWBS scrollable; + scrollable.setWindowTitle(QLatin1String(QTest::currentTestFunction())); scrollable.resize(200, 200); QLabel child(QString("@"),&scrollable); child.resize(50,50); @@ -9670,6 +9694,7 @@ void tst_QWidget::scrollWithoutBackingStore() void tst_QWidget::taskQTBUG_7532_tabOrderWithFocusProxy() { QWidget w; + w.setWindowTitle(QLatin1String(QTest::currentTestFunction())); w.setFocusPolicy(Qt::TabFocus); QWidget *fp = new QWidget(&w); fp->setFocusPolicy(Qt::TabFocus); @@ -9682,7 +9707,8 @@ void tst_QWidget::taskQTBUG_7532_tabOrderWithFocusProxy() void tst_QWidget::movedAndResizedAttributes() { // Use Qt::Tool as fully decorated windows have a minimum width of 160 on - QWidget w(0, Qt::Tool); + QWidget w(nullptr, Qt::Tool); + w.setWindowTitle(QLatin1String(QTest::currentTestFunction())); w.show(); QVERIFY(!w.testAttribute(Qt::WA_Moved)); @@ -9730,7 +9756,8 @@ void tst_QWidget::movedAndResizedAttributes() void tst_QWidget::childAt() { - QWidget parent(0, Qt::FramelessWindowHint); + QWidget parent(nullptr, Qt::FramelessWindowHint); + parent.setWindowTitle(QLatin1String(QTest::currentTestFunction())); parent.resize(200, 200); QWidget *child = new QWidget(&parent); @@ -9810,6 +9837,7 @@ void tst_QWidget::taskQTBUG_11373() void tst_QWidget::taskQTBUG_17333_ResizeInfiniteRecursion() { QTableView tb; + tb.setWindowTitle(QLatin1String(QTest::currentTestFunction())); const char *s = "border: 1px solid;"; tb.setStyleSheet(s); tb.show(); @@ -9822,6 +9850,7 @@ void tst_QWidget::taskQTBUG_17333_ResizeInfiniteRecursion() void tst_QWidget::nativeChildFocus() { QWidget w; + w.setWindowTitle(QLatin1String(QTest::currentTestFunction())); w.setMinimumWidth(m_testWidgetSize.width()); w.setWindowTitle(__FUNCTION__); QLayout *layout = new QVBoxLayout; @@ -9859,8 +9888,8 @@ static bool lenientCompare(const QPixmap &actual, const QPixmap &expected) const int size = actual.width() * actual.height(); const int threshold = QPixmap::defaultDepth() == 16 ? 10 : 2; - QRgb *a = (QRgb *)actualImage.bits(); - QRgb *e = (QRgb *)expectedImage.bits(); + auto a = reinterpret_cast<const QRgb *>(actualImage.bits()); + auto e = reinterpret_cast<const QRgb *>(expectedImage.bits()); for (int i = 0; i < size; ++i) { const QColor ca(a[i]); const QColor ce(e[i]); @@ -9880,6 +9909,7 @@ void tst_QWidget::grab() { for (int opaque = 0; opaque < 2; ++opaque) { QWidget widget; + widget.setWindowTitle(QLatin1String(QTest::currentTestFunction())); QImage image(128, 128, opaque ? QImage::Format_RGB32 : QImage::Format_ARGB32_Premultiplied); for (int row = 0; row < image.height(); ++row) { QRgb *line = reinterpret_cast<QRgb *>(image.scanLine(row)); @@ -9929,12 +9959,13 @@ static inline QString mouseEventLogEntry(const QString &objectName, QEvent::Type return result; } -class GrabLoggerWidget : public QWidget { +class GrabLoggerWidget : public QWidget +{ public: - explicit GrabLoggerWidget(QStringList *log, QWidget *parent = 0) : QWidget(parent), m_log(log) {} + explicit GrabLoggerWidget(QStringList *log, QWidget *parent = nullptr) : QWidget(parent), m_log(log) {} protected: - bool event(QEvent *e) + bool event(QEvent *e) override { switch (e->type()) { case QEvent::MouseButtonPress: @@ -9958,6 +9989,7 @@ void tst_QWidget::grabMouse() { QStringList log; GrabLoggerWidget w(&log); + w.setWindowTitle(QLatin1String(QTest::currentTestFunction())); w.setObjectName(QLatin1String("tst_qwidget_grabMouse")); w.setWindowTitle(w.objectName()); QLayout *layout = new QVBoxLayout(&w); @@ -9969,7 +10001,7 @@ void tst_QWidget::grabMouse() layout->addWidget(grabber); centerOnScreen(&w); w.show(); - qApp->setActiveWindow(&w); + QApplication::setActiveWindow(&w); QVERIFY(QTest::qWaitForWindowActive(&w)); QStringList expectedLog; @@ -9978,7 +10010,7 @@ void tst_QWidget::grabMouse() grabber->grabMouse(); const int step = w.height() / 5; for ( ; mousePos.y() < w.height() ; mousePos.ry() += step) { - QTest::mouseClick(w.windowHandle(), Qt::LeftButton, 0, mousePos); + QTest::mouseClick(w.windowHandle(), Qt::LeftButton, Qt::KeyboardModifiers(), mousePos); // Events should go to the grabber child using its coordinates. const QPoint expectedPos = grabber->mapFromParent(mousePos); expectedLog.push_back(mouseEventLogEntry(grabberObjectName, QEvent::MouseButtonPress, expectedPos, Qt::LeftButton)); @@ -9991,6 +10023,7 @@ void tst_QWidget::grabMouse() void tst_QWidget::grabKeyboard() { QWidget w; + w.setWindowTitle(QLatin1String(QTest::currentTestFunction())); w.setObjectName(QLatin1String("tst_qwidget_grabKeyboard")); w.setWindowTitle(w.objectName()); QLayout *layout = new QVBoxLayout(&w); @@ -10002,7 +10035,7 @@ void tst_QWidget::grabKeyboard() layout->addWidget(nonGrabber); centerOnScreen(&w); w.show(); - qApp->setActiveWindow(&w); + QApplication::setActiveWindow(&w); QVERIFY(QTest::qWaitForWindowActive(&w)); nonGrabber->setFocus(); grabber->grabKeyboard(); @@ -10014,16 +10047,7 @@ void tst_QWidget::grabKeyboard() class TouchMouseWidget : public QWidget { public: - explicit TouchMouseWidget(QWidget *parent = 0) - : QWidget(parent), - m_touchBeginCount(0), - m_touchUpdateCount(0), - m_touchEndCount(0), - m_touchEventCount(0), - m_gestureEventCount(0), - m_acceptTouch(false), - m_mouseEventCount(0), - m_acceptMouse(true) + explicit TouchMouseWidget(QWidget *parent = nullptr) : QWidget(parent) { resize(200, 200); } @@ -10040,7 +10064,7 @@ public: } protected: - bool event(QEvent *e) + bool event(QEvent *e) override { switch (e->type()) { case QEvent::TouchBegin: @@ -10079,14 +10103,14 @@ protected: } public: - int m_touchBeginCount; - int m_touchUpdateCount; - int m_touchEndCount; - int m_touchEventCount; - int m_gestureEventCount; - bool m_acceptTouch; - int m_mouseEventCount; - bool m_acceptMouse; + int m_touchBeginCount = 0; + int m_touchUpdateCount = 0; + int m_touchEndCount = 0; + int m_touchEventCount = 0; + int m_gestureEventCount = 0; + bool m_acceptTouch = false; + int m_mouseEventCount = 0; + bool m_acceptMouse = true; QPointF m_lastMouseEventPos; }; @@ -10095,6 +10119,7 @@ void tst_QWidget::touchEventSynthesizedMouseEvent() { // Simple case, we ignore the touch events, we get mouse events instead TouchMouseWidget widget; + widget.setWindowTitle(QLatin1String(QTest::currentTestFunction())); widget.show(); QVERIFY(QTest::qWaitForWindowExposed(widget.windowHandle())); QCOMPARE(widget.m_touchEventCount, 0); @@ -10117,6 +10142,7 @@ void tst_QWidget::touchEventSynthesizedMouseEvent() { // We accept the touch events, no mouse event is generated TouchMouseWidget widget; + widget.setWindowTitle(QLatin1String(QTest::currentTestFunction())); widget.setAcceptTouch(true); widget.show(); QVERIFY(QTest::qWaitForWindowExposed(widget.windowHandle())); @@ -10138,6 +10164,7 @@ void tst_QWidget::touchEventSynthesizedMouseEvent() // Parent accepts touch events, child ignore both mouse and touch // We should see propagation of the TouchBegin TouchMouseWidget parent; + parent.setWindowTitle(QLatin1String(QTest::currentTestFunction())); parent.setAcceptTouch(true); TouchMouseWidget child(&parent); child.move(5, 5); @@ -10160,8 +10187,10 @@ void tst_QWidget::touchEventSynthesizedMouseEvent() // Parent accepts mouse events, child ignore both mouse and touch // We should see propagation of the TouchBegin into a MouseButtonPress TouchMouseWidget parent; + parent.setWindowTitle(QLatin1String(QTest::currentTestFunction())); TouchMouseWidget child(&parent); - child.move(5, 5); + const QPoint childPos(5, 5); + child.move(childPos); child.setAcceptMouse(false); parent.show(); QVERIFY(QTest::qWaitForWindowExposed(parent.windowHandle())); @@ -10170,19 +10199,21 @@ void tst_QWidget::touchEventSynthesizedMouseEvent() QCOMPARE(child.m_touchEventCount, 0); QCOMPARE(child.m_mouseEventCount, 0); - QTest::touchEvent(parent.window(), m_touchScreen).press(0, QPoint(10, 10), &child); + const QPoint touchPos(20, 20); + QTest::touchEvent(parent.window(), m_touchScreen).press(0, touchPos, &child); QCOMPARE(parent.m_touchEventCount, 0); QCOMPARE(parent.m_mouseEventCount, 1); - QCOMPARE(parent.m_lastMouseEventPos, QPointF(15, 15)); + QCOMPARE(parent.m_lastMouseEventPos, childPos + touchPos); QCOMPARE(child.m_touchEventCount, 0); QCOMPARE(child.m_mouseEventCount, 1); // Attempt at mouse event before propagation - QCOMPARE(child.m_lastMouseEventPos, QPointF(10, 10)); + QCOMPARE(child.m_lastMouseEventPos, touchPos); } } void tst_QWidget::touchUpdateOnNewTouch() { TouchMouseWidget widget; + widget.setWindowTitle(QLatin1String(QTest::currentTestFunction())); widget.setAcceptTouch(true); QVBoxLayout *layout = new QVBoxLayout; layout->addWidget(new QWidget); @@ -10219,6 +10250,7 @@ void tst_QWidget::touchUpdateOnNewTouch() void tst_QWidget::touchEventsForGesturePendingWidgets() { TouchMouseWidget parent; + parent.setWindowTitle(QLatin1String(QTest::currentTestFunction())); TouchMouseWidget child(&parent); parent.grabGesture(Qt::TapAndHoldGesture); parent.show(); @@ -10257,8 +10289,9 @@ void tst_QWidget::touchEventsForGesturePendingWidgets() void tst_QWidget::styleSheetPropagation() { QTableView tw; + tw.setWindowTitle(QLatin1String(QTest::currentTestFunction())); tw.setStyleSheet("background-color: red;"); - foreach (QObject *child, tw.children()) { + for (QObject *child : tw.children()) { if (QWidget *w = qobject_cast<QWidget *>(child)) QCOMPARE(w->style(), tw.style()); } @@ -10268,7 +10301,7 @@ class DestroyTester : public QObject { Q_OBJECT public: - DestroyTester(QObject *parent) : QObject(parent) { parentDestroyed = 0; } + explicit DestroyTester(QObject *parent = nullptr) : QObject(parent) { parentDestroyed = 0; } static int parentDestroyed; public slots: void parentDestroyedSlot() { @@ -10283,7 +10316,7 @@ void tst_QWidget::destroyedSignal() { QWidget *w = new QWidget; DestroyTester *t = new DestroyTester(w); - connect(w, SIGNAL(destroyed()), t, SLOT(parentDestroyedSlot())); + connect(w, &QObject::destroyed, t, &DestroyTester::parentDestroyedSlot); QCOMPARE(DestroyTester::parentDestroyed, 0); delete w; QCOMPARE(DestroyTester::parentDestroyed, 1); @@ -10292,7 +10325,7 @@ void tst_QWidget::destroyedSignal() { QWidget *w = new QWidget; DestroyTester *t = new DestroyTester(w); - connect(w, SIGNAL(destroyed()), t, SLOT(parentDestroyedSlot())); + connect(w, &QObject::destroyed, t, &DestroyTester::parentDestroyedSlot); w->blockSignals(true); QCOMPARE(DestroyTester::parentDestroyed, 0); delete w; @@ -10302,7 +10335,7 @@ void tst_QWidget::destroyedSignal() { QObject *o = new QWidget; DestroyTester *t = new DestroyTester(o); - connect(o, SIGNAL(destroyed()), t, SLOT(parentDestroyedSlot())); + connect(o, &QObject::destroyed, t, &DestroyTester::parentDestroyedSlot); QCOMPARE(DestroyTester::parentDestroyed, 0); delete o; QCOMPARE(DestroyTester::parentDestroyed, 1); @@ -10310,8 +10343,8 @@ void tst_QWidget::destroyedSignal() { QObject *o = new QWidget; - DestroyTester *t = new DestroyTester(o); - connect(o, SIGNAL(destroyed()), t, SLOT(parentDestroyedSlot())); + auto t = new DestroyTester; + connect(o, &QObject::destroyed, t, &DestroyTester::parentDestroyedSlot); o->blockSignals(true); QCOMPARE(DestroyTester::parentDestroyed, 0); delete o; @@ -10320,8 +10353,8 @@ void tst_QWidget::destroyedSignal() { QWidget *w = new QWidget; - DestroyTester *t = new DestroyTester(0); - connect(w, SIGNAL(destroyed()), t, SLOT(parentDestroyedSlot())); + auto t = new DestroyTester; + connect(w, &QObject::destroyed, t, &DestroyTester::parentDestroyedSlot); QCOMPARE(DestroyTester::parentDestroyed, 0); delete w; QCOMPARE(DestroyTester::parentDestroyed, 1); @@ -10330,8 +10363,8 @@ void tst_QWidget::destroyedSignal() { QWidget *w = new QWidget; - DestroyTester *t = new DestroyTester(0); - connect(w, SIGNAL(destroyed()), t, SLOT(parentDestroyedSlot())); + auto t = new DestroyTester; + connect(w, &QObject::destroyed, t, &DestroyTester::parentDestroyedSlot); w->blockSignals(true); QCOMPARE(DestroyTester::parentDestroyed, 0); delete w; @@ -10341,8 +10374,8 @@ void tst_QWidget::destroyedSignal() { QObject *o = new QWidget; - DestroyTester *t = new DestroyTester(0); - connect(o, SIGNAL(destroyed()), t, SLOT(parentDestroyedSlot())); + auto t = new DestroyTester; + connect(o, &QObject::destroyed, t, &DestroyTester::parentDestroyedSlot); QCOMPARE(DestroyTester::parentDestroyed, 0); delete o; QCOMPARE(DestroyTester::parentDestroyed, 1); @@ -10351,8 +10384,8 @@ void tst_QWidget::destroyedSignal() { QObject *o = new QWidget; - DestroyTester *t = new DestroyTester(0); - connect(o, SIGNAL(destroyed()), t, SLOT(parentDestroyedSlot())); + auto t = new DestroyTester; + connect(o, &QObject::destroyed, t, &DestroyTester::parentDestroyedSlot); o->blockSignals(true); QCOMPARE(DestroyTester::parentDestroyed, 0); delete o; @@ -10368,10 +10401,11 @@ void tst_QWidget::underMouse() // Move the mouse cursor to a safe location QCursor::setPos(m_safeCursorPos); - ColorWidget topLevelWidget(0, Qt::FramelessWindowHint, Qt::blue); + ColorWidget topLevelWidget(nullptr, Qt::FramelessWindowHint, Qt::blue); + topLevelWidget.setWindowTitle(QLatin1String(QTest::currentTestFunction())); ColorWidget childWidget1(&topLevelWidget, Qt::Widget, Qt::yellow); ColorWidget childWidget2(&topLevelWidget, Qt::Widget, Qt::black); - ColorWidget popupWidget(0, Qt::Popup, Qt::green); + ColorWidget popupWidget(nullptr, Qt::Popup, Qt::green); topLevelWidget.setObjectName("topLevelWidget"); childWidget1.setObjectName("childWidget1"); @@ -10560,7 +10594,7 @@ class EnterTestModalDialog : public QDialog { Q_OBJECT public: - EnterTestModalDialog() : QDialog(), button(0) + EnterTestModalDialog() { setGeometry(100, 300, 150, 100); button = new QPushButton(this); @@ -10574,7 +10608,6 @@ class EnterTestMainDialog : public QDialog { Q_OBJECT public: - EnterTestMainDialog() : QDialog(), modal(0), enters(0) {} public slots: void buttonPressed() @@ -10602,7 +10635,7 @@ public slots: modal->close(); } - bool eventFilter(QObject *o, QEvent *e) + bool eventFilter(QObject *o, QEvent *e) override { switch (e->type()) { case QEvent::Enter: @@ -10616,8 +10649,8 @@ public slots: } public: - EnterTestModalDialog *modal; - int enters; + EnterTestModalDialog *modal = nullptr; + int enters = 0; }; // A modal dialog launched by clicking a button should not trigger excess enter events @@ -10631,9 +10664,10 @@ void tst_QWidget::taskQTBUG_27643_enterEvents() QCursor::setPos(m_safeCursorPos); EnterTestMainDialog dialog; + dialog.setWindowTitle(QLatin1String(QTest::currentTestFunction())); QPushButton button(&dialog); - connect(&button, SIGNAL(clicked()), &dialog, SLOT(buttonPressed())); + connect(&button, &QAbstractButton::clicked, &dialog, &EnterTestMainDialog::buttonPressed); dialog.setGeometry(100, 100, 150, 100); button.setGeometry(10, 10, 100, 50); @@ -10645,7 +10679,7 @@ void tst_QWidget::taskQTBUG_27643_enterEvents() QWindowSystemInterface::handleEnterEvent(window, overButton, window->mapToGlobal(overButton)); QTest::mouseMove(window, overButton); - QTest::mouseClick(window, Qt::LeftButton, 0, overButton, 0); + QTest::mouseClick(window, Qt::LeftButton, Qt::KeyboardModifiers(), overButton, 0); // Modal dialog opened in EnterTestMainDialog::buttonPressed()... @@ -10657,20 +10691,22 @@ void tst_QWidget::taskQTBUG_27643_enterEvents() class KeyboardWidget : public QWidget { public: - KeyboardWidget(QWidget* parent = 0) : QWidget(parent), m_eventCounter(0) {} - virtual void mousePressEvent(QMouseEvent* ev) override { + using QWidget::QWidget; + void mousePressEvent(QMouseEvent* ev) override + { m_modifiers = ev->modifiers(); m_appModifiers = QApplication::keyboardModifiers(); ++m_eventCounter; } Qt::KeyboardModifiers m_modifiers; Qt::KeyboardModifiers m_appModifiers; - int m_eventCounter; + int m_eventCounter = 0; }; void tst_QWidget::keyboardModifiers() { KeyboardWidget w; + w.setWindowTitle(QLatin1String(QTest::currentTestFunction())); w.resize(300, 300); w.show(); QVERIFY(QTest::qWaitForWindowExposed(&w)); @@ -10683,17 +10719,17 @@ void tst_QWidget::keyboardModifiers() class DClickWidget : public QWidget { public: - DClickWidget() : triggered(false) {} - void mouseDoubleClickEvent(QMouseEvent *) + void mouseDoubleClickEvent(QMouseEvent *) override { triggered = true; } - bool triggered; + bool triggered = false; }; void tst_QWidget::mouseDoubleClickBubbling_QTBUG29680() { DClickWidget parent; + parent.setWindowTitle(QLatin1String(QTest::currentTestFunction())); QWidget child(&parent); parent.resize(200, 200); child.resize(200, 200); @@ -10708,6 +10744,7 @@ void tst_QWidget::mouseDoubleClickBubbling_QTBUG29680() void tst_QWidget::largerThanScreen_QTBUG30142() { QWidget widget; + widget.setWindowTitle(QLatin1String(QTest::currentTestFunction())); widget.resize(200, 4000); widget.show(); QVERIFY(QTest::qWaitForWindowExposed(&widget)); @@ -10725,6 +10762,7 @@ void tst_QWidget::largerThanScreen_QTBUG30142() void tst_QWidget::resizeStaticContentsChildWidget_QTBUG35282() { QWidget widget; + widget.setWindowTitle(QLatin1String(QTest::currentTestFunction())); widget.resize(200,200); UpdateWidget childWidget(&widget); @@ -10750,11 +10788,12 @@ void tst_QWidget::qmlSetParentHelper() { #ifdef QT_BUILD_INTERNAL QWidget parent; + parent.setWindowTitle(QLatin1String(QTest::currentTestFunction())); QWidget child; QVERIFY(QAbstractDeclarativeData::setWidgetParent); QAbstractDeclarativeData::setWidgetParent(&child, &parent); QCOMPARE(child.parentWidget(), &parent); - QAbstractDeclarativeData::setWidgetParent(&child, 0); + QAbstractDeclarativeData::setWidgetParent(&child, nullptr); QVERIFY(!child.parentWidget()); #else QSKIP("Needs QT_BUILD_INTERNAL"); @@ -10868,6 +10907,7 @@ protected: void tst_QWidget::tabletTracking() { QWidget parent; + parent.setWindowTitle(QLatin1String(QTest::currentTestFunction())); parent.resize(200,200); // QWidgetWindow::handleTabletEvent doesn't deliver tablet events to the window's widget, only to a child. // So it doesn't do any good to show a TabletWidget directly: it needs a parent. @@ -10886,7 +10926,7 @@ void tst_QWidget::tabletTracking() QPointF deviceGlobal = QHighDpi::toNativePixels(global, window->screen()); qint64 uid = 1234UL; - QWindowSystemInterface::handleTabletEvent(window, QDateTime::currentMSecsSinceEpoch(), deviceLocal, deviceGlobal, + QWindowSystemInterface::handleTabletEvent(window, ulong(QDateTime::currentMSecsSinceEpoch()), deviceLocal, deviceGlobal, QTabletEvent::Stylus, QTabletEvent::Pen, Qt::NoButton, 0, 0, 0, 0, 0, 0, uid, Qt::NoModifier); QCoreApplication::processEvents(); QTRY_COMPARE(widget.moveEventCount, 1); @@ -10895,7 +10935,7 @@ void tst_QWidget::tabletTracking() local += QPoint(10, 10); deviceLocal += QPoint(10, 10); deviceGlobal += QPoint(10, 10); - QWindowSystemInterface::handleTabletEvent(window, QDateTime::currentMSecsSinceEpoch(), deviceLocal, deviceGlobal, + QWindowSystemInterface::handleTabletEvent(window, ulong(QDateTime::currentMSecsSinceEpoch()), deviceLocal, deviceGlobal, QTabletEvent::Stylus, QTabletEvent::Pen, Qt::NoButton, 0, 0, 0, 0, 0, 0, uid, Qt::NoModifier); QCoreApplication::processEvents(); QTRY_COMPARE(widget.moveEventCount, 2); @@ -10904,7 +10944,7 @@ void tst_QWidget::tabletTracking() QCoreApplication::processEvents(); QTRY_COMPARE(widget.trackingChangeEventCount, 2); - QWindowSystemInterface::handleTabletEvent(window, QDateTime::currentMSecsSinceEpoch(), deviceLocal, deviceGlobal, + QWindowSystemInterface::handleTabletEvent(window, ulong(QDateTime::currentMSecsSinceEpoch()), deviceLocal, deviceGlobal, QTabletEvent::Stylus, QTabletEvent::Pen, Qt::LeftButton, 0, 0, 0, 0, 0, 0, uid, Qt::NoModifier); QCoreApplication::processEvents(); QTRY_COMPARE(widget.pressEventCount, 1); @@ -10912,12 +10952,12 @@ void tst_QWidget::tabletTracking() local += QPoint(10, 10); deviceLocal += QPoint(10, 10); deviceGlobal += QPoint(10, 10); - QWindowSystemInterface::handleTabletEvent(window, QDateTime::currentMSecsSinceEpoch(), deviceLocal, deviceGlobal, + QWindowSystemInterface::handleTabletEvent(window, ulong(QDateTime::currentMSecsSinceEpoch()), deviceLocal, deviceGlobal, QTabletEvent::Stylus, QTabletEvent::Pen, Qt::LeftButton, 0, 0, 0, 0, 0, 0, uid, Qt::NoModifier); QCoreApplication::processEvents(); QTRY_COMPARE(widget.moveEventCount, 3); - QWindowSystemInterface::handleTabletEvent(window, QDateTime::currentMSecsSinceEpoch(), deviceLocal, deviceGlobal, + QWindowSystemInterface::handleTabletEvent(window, ulong(QDateTime::currentMSecsSinceEpoch()), deviceLocal, deviceGlobal, QTabletEvent::Stylus, QTabletEvent::Pen, Qt::NoButton, 0, 0, 0, 0, 0, 0, uid, Qt::NoModifier); QCoreApplication::processEvents(); QTRY_COMPARE(widget.releaseEventCount, 1); @@ -10925,7 +10965,7 @@ void tst_QWidget::tabletTracking() local += QPoint(10, 10); deviceLocal += QPoint(10, 10); deviceGlobal += QPoint(10, 10); - QWindowSystemInterface::handleTabletEvent(window, QDateTime::currentMSecsSinceEpoch(), deviceLocal, deviceGlobal, + QWindowSystemInterface::handleTabletEvent(window, ulong(QDateTime::currentMSecsSinceEpoch()), deviceLocal, deviceGlobal, QTabletEvent::Stylus, QTabletEvent::Pen, Qt::NoButton, 0, 0, 0, 0, 0, 0, uid, Qt::NoModifier); QCoreApplication::processEvents(); QTRY_COMPARE(widget.moveEventCount, 3); diff --git a/tests/auto/widgets/kernel/qwidget_window/BLACKLIST b/tests/auto/widgets/kernel/qwidget_window/BLACKLIST index c980325d9a..381cf76c46 100644 --- a/tests/auto/widgets/kernel/qwidget_window/BLACKLIST +++ b/tests/auto/widgets/kernel/qwidget_window/BLACKLIST @@ -2,6 +2,6 @@ # QTBUG-66345 opensuse-42.3 ubuntu-16.04 -ubuntu-18.04 [setWindowState] ubuntu-18.04 +rhel diff --git a/tests/auto/widgets/kernel/qwidget_window/tst_qwidget_window.cpp b/tests/auto/widgets/kernel/qwidget_window/tst_qwidget_window.cpp index 8b558aa56f..c6b5669965 100644 --- a/tests/auto/widgets/kernel/qwidget_window/tst_qwidget_window.cpp +++ b/tests/auto/widgets/kernel/qwidget_window/tst_qwidget_window.cpp @@ -54,12 +54,25 @@ using namespace QTestPrivate; +// Compare a window position that may go through scaling in the platform plugin with fuzz. +static inline bool qFuzzyCompareWindowPosition(const QPoint &p1, const QPoint p2, int fuzz) +{ + return (p1 - p2).manhattanLength() <= fuzz; +} + +static QString msgPointMismatch(const QPoint &p1, const QPoint p2) +{ + QString result; + QDebug(&result) << p1 << "!=" << p2 << ", manhattanLength=" << (p1 - p2).manhattanLength(); + return result; +} + class tst_QWidget_window : public QObject { Q_OBJECT public: - tst_QWidget_window(){}; + tst_QWidget_window(); public slots: void initTestCase(); @@ -110,8 +123,20 @@ private slots: void nativeShow(); void QTBUG_56277_resize_on_showEvent(); + +private: + QSize m_testWidgetSize; + const int m_fuzz; }; +tst_QWidget_window::tst_QWidget_window() : + m_fuzz(int(QHighDpiScaling::factor(QGuiApplication::primaryScreen()))) +{ + const int screenWidth = QGuiApplication::primaryScreen()->geometry().width(); + const int width = qMax(200, 100 * ((screenWidth + 500) / 1000)); + m_testWidgetSize = QSize(width, width); +} + void tst_QWidget_window::initTestCase() { } @@ -162,65 +187,65 @@ void tst_QWidget_window::tst_min_max_size() void tst_QWidget_window::tst_move_show() { QWidget w; - w.move(100, 100); + const QPoint pos(100, 100); + w.move(pos); w.show(); #ifdef Q_OS_WINRT QEXPECT_FAIL("", "Winrt does not support move", Abort); #endif - QCOMPARE(w.pos(), QPoint(100, 100)); -// QCoreApplication::processEvents(QEventLoop::AllEvents, 3000); + QVERIFY2(qFuzzyCompareWindowPosition(w.pos(), pos, m_fuzz), + qPrintable(msgPointMismatch(w.pos(), pos))); } void tst_QWidget_window::tst_show_move() { QWidget w; w.show(); - w.move(100, 100); - QCOMPARE(w.pos(), QPoint(100, 100)); -// QCoreApplication::processEvents(QEventLoop::AllEvents, 1000); + const QPoint pos(100, 100); + w.move(pos); + QVERIFY2(qFuzzyCompareWindowPosition(w.pos(), pos, m_fuzz), + qPrintable(msgPointMismatch(w.pos(), pos))); } void tst_QWidget_window::tst_show_move_hide_show() { QWidget w; w.show(); - w.move(100, 100); + const QPoint pos(100, 100); + w.move(pos); w.hide(); w.show(); - QCOMPARE(w.pos(), QPoint(100, 100)); -// QCoreApplication::processEvents(QEventLoop::AllEvents, 1000); + QVERIFY2(qFuzzyCompareWindowPosition(w.pos(), pos, m_fuzz), + qPrintable(msgPointMismatch(w.pos(), pos))); } void tst_QWidget_window::tst_resize_show() { QWidget w; - w.resize(200, 200); + w.resize(m_testWidgetSize); w.show(); #ifdef Q_OS_WINRT QEXPECT_FAIL("", "Winrt does not support resize", Abort); #endif - QCOMPARE(w.size(), QSize(200, 200)); -// QCoreApplication::processEvents(QEventLoop::AllEvents, 1000); + QCOMPARE(w.size(), m_testWidgetSize); } void tst_QWidget_window::tst_show_resize() { QWidget w; w.show(); - w.resize(200, 200); - QCOMPARE(w.size(), QSize(200, 200)); -// QCoreApplication::processEvents(QEventLoop::AllEvents, 1000); + w.resize(m_testWidgetSize); + QCOMPARE(w.size(), m_testWidgetSize); } void tst_QWidget_window::tst_show_resize_hide_show() { QWidget w; w.show(); - w.resize(200, 200); + w.resize(m_testWidgetSize); w.hide(); w.show(); - QCOMPARE(w.size(), QSize(200, 200)); -// QCoreApplication::processEvents(QEventLoop::AllEvents, 1000); + QCOMPARE(w.size(), m_testWidgetSize); } class PaintTestWidget : public QWidget @@ -857,7 +882,7 @@ void tst_QWidget_window::tst_updateWinId_QTBUG40681() lbl->setAttribute(Qt::WA_NativeWindow); lbl->setObjectName("label1"); vl->addWidget(lbl); - w.setMinimumWidth(200); + w.setMinimumWidth(m_testWidgetSize.width()); w.show(); @@ -880,6 +905,7 @@ void tst_QWidget_window::tst_updateWinId_QTBUG40681() void tst_QWidget_window::tst_recreateWindow_QTBUG40817() { QTabWidget tab; + tab.setMinimumWidth(m_testWidgetSize.width()); QWidget *w = new QWidget; tab.addTab(w, "Tab1"); @@ -946,7 +972,7 @@ void tst_QWidget_window::tst_resize_count() resize.resizeCount = 0; ResizeWidget child(&resize); - child.resize(200,200); + child.resize(m_testWidgetSize); child.winId(); child.show(); QVERIFY(QTest::qWaitForWindowExposed(&child)); @@ -963,7 +989,7 @@ void tst_QWidget_window::tst_resize_count() { ResizeWidget parent; ResizeWidget child(&parent); - child.resize(200,200); + child.resize(m_testWidgetSize); child.winId(); parent.show(); QVERIFY(QTest::qWaitForWindowExposed(&parent)); @@ -1076,6 +1102,7 @@ void tst_QWidget_window::QTBUG_50561_QCocoaBackingStore_paintDevice_crash() ApplicationStateSaver as; QMainWindow w; + w.setMinimumWidth(m_testWidgetSize.width()); w.addToolBar(new QToolBar(&w)); w.show(); QVERIFY(QTest::qWaitForWindowExposed(&w)); diff --git a/tests/auto/widgets/styles/qstylesheetstyle/tst_qstylesheetstyle.cpp b/tests/auto/widgets/styles/qstylesheetstyle/tst_qstylesheetstyle.cpp index 61b1fed1f8..a671a6c4d8 100644 --- a/tests/auto/widgets/styles/qstylesheetstyle/tst_qstylesheetstyle.cpp +++ b/tests/auto/widgets/styles/qstylesheetstyle/tst_qstylesheetstyle.cpp @@ -48,6 +48,7 @@ public: private slots: void init(); void repolish(); + void repolish_without_crashing(); void numinstances(); void widgetsBeforeAppStyleSheet(); void widgetsAfterAppStyleSheet(); @@ -367,6 +368,26 @@ void tst_QStyleSheetStyle::repolish() QCOMPARE(BACKGROUND(p1), APPBACKGROUND(p1)); } +void tst_QStyleSheetStyle::repolish_without_crashing() +{ + // This used to crash, QTBUG-69204 + QMainWindow w; + QScopedPointer<QSplitter> splitter1(new QSplitter(w.centralWidget())); + QScopedPointer<QSplitter> splitter2(new QSplitter); + QScopedPointer<QSplitter> splitter3(new QSplitter); + splitter2->addWidget(splitter3.data()); + + splitter2->setStyleSheet("color: red"); + QScopedPointer<QLabel> label(new QLabel); + label->setTextFormat(Qt::RichText); + splitter3->addWidget(label.data()); + label->setText("hey"); + + splitter1->addWidget(splitter2.data()); + w.show(); + QCOMPARE(COLOR(*label), QColor(Qt::red)); +} + void tst_QStyleSheetStyle::widgetStyle() { qApp->setStyleSheet(QString()); diff --git a/tests/auto/widgets/widgets/qabstractscrollarea/tst_qabstractscrollarea.cpp b/tests/auto/widgets/widgets/qabstractscrollarea/tst_qabstractscrollarea.cpp index 007825d39c..a17a9f6c33 100644 --- a/tests/auto/widgets/widgets/qabstractscrollarea/tst_qabstractscrollarea.cpp +++ b/tests/auto/widgets/widgets/qabstractscrollarea/tst_qabstractscrollarea.cpp @@ -124,13 +124,19 @@ void tst_QAbstractScrollArea::scrollBarWidgets() QCOMPARE(area.scrollBarWidgets(Qt::AlignTop), QWidgetList()); QCOMPARE(area.scrollBarWidgets(Qt::AlignBottom), w2List); + auto sort = [](const QWidgetList l) { + QWidgetList list = l; + std::sort(list.begin(), list.end()); + return list; + }; + // two widgets at Bottom. area.addScrollBarWidget(w3, Qt::AlignBottom); - QCOMPARE(area.scrollBarWidgets(all).toSet(), allList.toSet()); + QCOMPARE(sort(area.scrollBarWidgets(all)), sort(allList)); QCOMPARE(area.scrollBarWidgets(Qt::AlignLeft), w1List); QCOMPARE(area.scrollBarWidgets(Qt::AlignRight), QWidgetList()); QCOMPARE(area.scrollBarWidgets(Qt::AlignTop), QWidgetList()); - QCOMPARE(area.scrollBarWidgets(Qt::AlignBottom).toSet(), (w2List + w3List).toSet()); + QCOMPARE(sort(area.scrollBarWidgets(Qt::AlignBottom)), sort(w2List + w3List)); //delete delete w1; diff --git a/tests/auto/widgets/widgets/qdockwidget/tst_qdockwidget.cpp b/tests/auto/widgets/widgets/qdockwidget/tst_qdockwidget.cpp index f8ce6a2c0a..625116654d 100644 --- a/tests/auto/widgets/widgets/qdockwidget/tst_qdockwidget.cpp +++ b/tests/auto/widgets/widgets/qdockwidget/tst_qdockwidget.cpp @@ -670,7 +670,11 @@ void tst_QDockWidget::dockLocationChanged() spy.clear(); dw.setFloating(true); - QTest::qWait(100); + QTRY_COMPARE(spy.count(), 1); + QCOMPARE(qvariant_cast<Qt::DockWidgetArea>(spy.at(0).at(0)), + Qt::NoDockWidgetArea); + spy.clear(); + dw.setFloating(false); QTRY_COMPARE(spy.count(), 1); QCOMPARE(qvariant_cast<Qt::DockWidgetArea>(spy.at(0).at(0)), diff --git a/tests/auto/widgets/widgets/qdoublespinbox/tst_qdoublespinbox.cpp b/tests/auto/widgets/widgets/qdoublespinbox/tst_qdoublespinbox.cpp index b101f47bcd..954ee6471d 100644 --- a/tests/auto/widgets/widgets/qdoublespinbox/tst_qdoublespinbox.cpp +++ b/tests/auto/widgets/widgets/qdoublespinbox/tst_qdoublespinbox.cpp @@ -324,7 +324,9 @@ void tst_QDoubleSpinBox::setPrefixSuffix() QFETCH(QString, expectedCleanText); QFETCH(bool, show); - QDoubleSpinBox spin(0); + QDoubleSpinBox spin; + if (show) + spin.show(); spin.setDecimals(decimals); const QSize size1 = spin.sizeHint(); spin.setPrefix(prefix); @@ -332,17 +334,17 @@ void tst_QDoubleSpinBox::setPrefixSuffix() spin.setSuffix(suffix); const QSize size3 = spin.sizeHint(); spin.setValue(value); - if (show) - spin.show(); QCOMPARE(spin.text(), expectedText); QCOMPARE(spin.cleanText(), expectedCleanText); - if (!prefix.isEmpty() && !suffix.isEmpty()) { - QVERIFY(size1.width() < size2.width()); + if (!suffix.isEmpty()) { QVERIFY(size2.width() < size3.width()); spin.setSuffix(QString()); QCOMPARE(spin.sizeHint(), size2); + } + if (!prefix.isEmpty()) { + QVERIFY(size1.width() < size2.width()); spin.setPrefix(QString()); QCOMPARE(spin.sizeHint(), size1); } diff --git a/tests/auto/widgets/widgets/qlineedit/tst_qlineedit.cpp b/tests/auto/widgets/widgets/qlineedit/tst_qlineedit.cpp index 7861065de9..f1bc3e8dd4 100644 --- a/tests/auto/widgets/widgets/qlineedit/tst_qlineedit.cpp +++ b/tests/auto/widgets/widgets/qlineedit/tst_qlineedit.cpp @@ -3996,7 +3996,7 @@ void tst_QLineEdit::QTBUG7174_inputMaskCursorBlink() edit.setFocus(); edit.setText(QLatin1String("AAAA")); edit.show(); - QRect cursorRect = edit.inputMethodQuery(Qt::ImMicroFocus).toRect(); + QRect cursorRect = edit.inputMethodQuery(Qt::ImCursorRectangle).toRect(); QVERIFY(QTest::qWaitForWindowExposed(&edit)); edit.updateRegion = QRegion(); QTest::qWait(QApplication::cursorFlashTime()); diff --git a/tests/auto/widgets/widgets/qmdisubwindow/tst_qmdisubwindow.cpp b/tests/auto/widgets/widgets/qmdisubwindow/tst_qmdisubwindow.cpp index 8b2f032172..2b59a227b3 100644 --- a/tests/auto/widgets/widgets/qmdisubwindow/tst_qmdisubwindow.cpp +++ b/tests/auto/widgets/widgets/qmdisubwindow/tst_qmdisubwindow.cpp @@ -1,6 +1,6 @@ /**************************************************************************** ** -** Copyright (C) 2016 The Qt Company Ltd. +** Copyright (C) 2019 The Qt Company Ltd. ** Contact: https://www.qt.io/licensing/ ** ** This file is part of the test suite of the Qt Toolkit. @@ -49,6 +49,8 @@ #include <QScreen> #include <QSizeGrip> +#include <QVector> + QT_BEGIN_NAMESPACE #if 1 // Used to be excluded in Qt4 for Q_WS_WIN extern bool qt_tab_all_widgets(); @@ -58,7 +60,7 @@ QT_END_NAMESPACE static inline bool tabAllWidgets() { #if !defined(Q_OS_WIN) - if (qApp->style()->inherits("QMacStyle")) + if (QApplication::style()->inherits("QMacStyle")) return qt_tab_all_widgets(); #endif return true; @@ -69,17 +71,17 @@ static inline void triggerSignal(QMdiSubWindow *window, QMdiArea *workspace, { if (signal == SIGNAL(windowMaximized())) { window->showMaximized(); - qApp->processEvents(); + QCoreApplication::processEvents(); if (window->parent()) QVERIFY(window->isMaximized()); } else if (signal == SIGNAL(windowMinimized())) { window->showMinimized(); - qApp->processEvents(); + QCoreApplication::processEvents(); if (window->parent()) QVERIFY(window->isMinimized()); } else if (signal == SIGNAL(windowRestored())) { window->showMaximized(); - qApp->processEvents(); + QCoreApplication::processEvents(); window->showNormal(); QTRY_VERIFY(!window->isMinimized()); QTRY_VERIFY(!window->isMaximized()); @@ -87,39 +89,39 @@ static inline void triggerSignal(QMdiSubWindow *window, QMdiArea *workspace, } else if (signal == SIGNAL(aboutToActivate())) { if (window->parent()) { workspace->setActiveSubWindow(window); - qApp->processEvents(); + QCoreApplication::processEvents(); } } else if (signal == SIGNAL(windowActivated())) { if (window->parent()) { workspace->setActiveSubWindow(window); - qApp->processEvents(); + QCoreApplication::processEvents(); } } else if (signal == SIGNAL(windowDeactivated())) { if (!window->parent()) return; workspace->setActiveSubWindow(window); - qApp->processEvents(); - workspace->setActiveSubWindow(0); - qApp->processEvents(); + QCoreApplication::processEvents(); + workspace->setActiveSubWindow(nullptr); + QCoreApplication::processEvents(); } } // --- from tst_qgraphicsview.cpp --- static void sendMousePress(QWidget *widget, const QPoint &point, Qt::MouseButton button = Qt::LeftButton) { - QMouseEvent event(QEvent::MouseButtonPress, point, widget->mapToGlobal(point), button, 0, 0); + QMouseEvent event(QEvent::MouseButtonPress, point, widget->mapToGlobal(point), button, {}, {}); QApplication::sendEvent(widget, &event); } static void sendMouseMove(QWidget *widget, const QPoint &point, Qt::MouseButton button = Qt::LeftButton) { - QMouseEvent event(QEvent::MouseMove, point, widget->mapToGlobal(point), button, button, 0); + QMouseEvent event(QEvent::MouseMove, point, widget->mapToGlobal(point), button, button, {}); QApplication::sendEvent(widget, &event); } static void sendMouseRelease(QWidget *widget, const QPoint &point, Qt::MouseButton button = Qt::LeftButton) { - QMouseEvent event(QEvent::MouseButtonRelease, point, widget->mapToGlobal(point), button, 0, 0); + QMouseEvent event(QEvent::MouseButtonRelease, point, widget->mapToGlobal(point), button, {}, {}); QApplication::sendEvent(widget, &event); } // --- @@ -128,7 +130,7 @@ static void sendMouseDoubleClick(QWidget *widget, const QPoint &point, Qt::Mouse { sendMousePress(widget, point, button); sendMouseRelease(widget, point, button); - QMouseEvent event(QEvent::MouseButtonDblClick, point, widget->mapToGlobal(point), button, 0, 0); + QMouseEvent event(QEvent::MouseButtonDblClick, point, widget->mapToGlobal(point), button, {}, {}); QApplication::sendEvent(widget, &event); } @@ -137,6 +139,15 @@ static const Qt::WindowFlags StandardWindowFlags static const Qt::WindowFlags DialogWindowFlags = Qt::WindowTitleHint | Qt::WindowSystemMenuHint; +class LayoutDirectionGuard +{ +public: + Q_DISABLE_COPY(LayoutDirectionGuard); + + LayoutDirectionGuard() = default; + ~LayoutDirectionGuard() { QApplication::setLayoutDirection(Qt::LeftToRight); } +}; + Q_DECLARE_METATYPE(Qt::WindowState); Q_DECLARE_METATYPE(Qt::WindowStates); Q_DECLARE_METATYPE(Qt::WindowType); @@ -148,6 +159,7 @@ class tst_QMdiSubWindow : public QObject Q_OBJECT private slots: void initTestCase(); + void cleanup(); void sizeHint(); void minimumSizeHint(); void minimumSize(); @@ -202,6 +214,14 @@ private slots: void tst_QMdiSubWindow::initTestCase() { qRegisterMetaType<Qt::WindowStates>("Qt::WindowStates"); + // Avoid unnecessary waits for empty top level widget lists when + // testing menus. + QApplication::setEffectEnabled(Qt::UI_AnimateMenu, false); +} + +void tst_QMdiSubWindow::cleanup() +{ + QVERIFY(QApplication::topLevelWidgets().isEmpty()); } void tst_QMdiSubWindow::sizeHint() @@ -211,34 +231,38 @@ void tst_QMdiSubWindow::sizeHint() window->show(); QCOMPARE(window->sizeHint(), window->minimumSizeHint()); QMdiArea workspace; + workspace.setWindowTitle(QLatin1String(QTest::currentTestFunction())); workspace.addSubWindow(window); QCOMPARE(window->sizeHint(), window->minimumSizeHint()); } void tst_QMdiSubWindow::minimumSizeHint() { + const auto globalStrut = QApplication::globalStrut(); QMdiSubWindow window; + window.setWindowTitle(QLatin1String(QTest::currentTestFunction())); window.show(); - QCOMPARE(window.minimumSizeHint(), qApp->globalStrut()); + QCOMPARE(window.minimumSizeHint(), globalStrut); window.setWidget(new QWidget); QCOMPARE(window.minimumSizeHint(), window.layout()->minimumSize() - .expandedTo(qApp->globalStrut())); + .expandedTo(globalStrut)); delete window.widget(); delete window.layout(); window.setWidget(new QWidget); - QCOMPARE(window.minimumSizeHint(), qApp->globalStrut()); + QCOMPARE(window.minimumSizeHint(), globalStrut); window.widget()->show(); QCOMPARE(window.minimumSizeHint(), window.widget()->minimumSizeHint() - .expandedTo(qApp->globalStrut())); + .expandedTo(globalStrut)); } void tst_QMdiSubWindow::minimumSize() { QMdiArea mdiArea; + mdiArea.setWindowTitle(QLatin1String(QTest::currentTestFunction())); mdiArea.resize(200, 200); // Check that we respect the minimum size set on the sub-window itself. @@ -278,7 +302,7 @@ void tst_QMdiSubWindow::setWidget() QCOMPARE(window.widget(), static_cast<QWidget *>(widget)); QCOMPARE(widget->parentWidget(), static_cast<QWidget *>(&window)); - window.setWidget(0); + window.setWidget(nullptr); QVERIFY(widget); QVERIFY(!widget->parent()); QVERIFY(!window.widget()); @@ -308,12 +332,13 @@ void tst_QMdiSubWindow::setWindowState() { QFETCH(Qt::WindowState, windowState); QMdiArea workspace; + workspace.setWindowTitle(QLatin1String(QTest::currentTestFunction())); QMdiSubWindow *window = qobject_cast<QMdiSubWindow *>(workspace.addSubWindow(new QLineEdit)); window->show(); workspace.show(); QVERIFY(QTest::qWaitForWindowExposed(&workspace)); - QWidget *testWidget = 0; + QWidget *testWidget = nullptr; for (int iteration = 0; iteration < 2; ++iteration) { if (iteration == 0) testWidget = window; @@ -351,13 +376,13 @@ void tst_QMdiSubWindow::setWindowState() void tst_QMdiSubWindow::mainWindowSupport() { - QList<QMdiSubWindow *> windows; + QVector<QMdiSubWindow *> windows; QMdiArea *workspace = new QMdiArea; QMainWindow mainWindow; mainWindow.setCentralWidget(workspace); mainWindow.show(); mainWindow.menuBar()->setVisible(true); - qApp->setActiveWindow(&mainWindow); + QApplication::setActiveWindow(&mainWindow); bool nativeMenuBar = mainWindow.menuBar()->isNativeMenuBar(); // QMainWindow's window title is empty, so on a platform which does NOT have a native menubar, @@ -400,7 +425,7 @@ void tst_QMdiSubWindow::mainWindowSupport() // mainWindow.menuBar() is not visible window->showMaximized(); - qApp->processEvents(); + QCoreApplication::processEvents(); QVERIFY(window->isMaximized()); QVERIFY(!window->maximizedButtonsWidget()); QVERIFY(!window->maximizedSystemMenuIconWidget()); @@ -410,7 +435,7 @@ void tst_QMdiSubWindow::mainWindowSupport() mainWindow.menuBar()->setVisible(true); window->showMaximized(); - qApp->processEvents(); + QCoreApplication::processEvents(); QVERIFY(window->isMaximized()); if (!nativeMenuBar) { QVERIFY(window->maximizedButtonsWidget()); @@ -430,7 +455,7 @@ void tst_QMdiSubWindow::mainWindowSupport() nestedWorkspace->addSubWindow(nestedWindow); nestedWindow->widget()->setWindowTitle(QLatin1String("NestedWindow ") + QString::number(i)); nestedWindow->showMaximized(); - qApp->processEvents(); + QCoreApplication::processEvents(); QVERIFY(nestedWindow->isMaximized()); QVERIFY(!nestedWindow->maximizedButtonsWidget()); QVERIFY(!nestedWindow->maximizedSystemMenuIconWidget()); @@ -445,8 +470,8 @@ void tst_QMdiSubWindow::mainWindowSupport() return; workspace->activateNextSubWindow(); - qApp->processEvents(); - foreach (QMdiSubWindow *window, windows) { + QCoreApplication::processEvents(); + for (QMdiSubWindow *window : qAsConst(windows)) { QCOMPARE(workspace->activeSubWindow(), window); QVERIFY(window->isMaximized()); QVERIFY(window->maximizedButtonsWidget()); @@ -457,7 +482,7 @@ void tst_QMdiSubWindow::mainWindowSupport() QCOMPARE(mainWindow.windowTitle(), QString::fromLatin1("%1 - [%2]") .arg(originalWindowTitle, window->widget()->windowTitle())); workspace->activateNextSubWindow(); - qApp->processEvents(); + QCoreApplication::processEvents(); } } @@ -480,15 +505,16 @@ void tst_QMdiSubWindow::emittingOfSignals() QFETCH(QByteArray, signal); QFETCH(Qt::WindowState, watchedState); QMdiArea workspace; + workspace.setWindowTitle(QLatin1String(QTest::currentTestFunction())); workspace.show(); - qApp->processEvents(); - qApp->setActiveWindow(&workspace); + QCoreApplication::processEvents(); + QApplication::setActiveWindow(&workspace); QMdiSubWindow *window = qobject_cast<QMdiSubWindow *>(workspace.addSubWindow(new QWidget)); - qApp->processEvents(); + QCoreApplication::processEvents(); window->show(); if (signal != SIGNAL(windowRestored())) - workspace.setActiveSubWindow(0); - qApp->processEvents(); + workspace.setActiveSubWindow(nullptr); + QCoreApplication::processEvents(); QSignalSpy spy(window, signal == SIGNAL(aboutToActivate()) ? signal.data() @@ -523,25 +549,26 @@ void tst_QMdiSubWindow::emittingOfSignals() #endif QCOMPARE(count, 1); - window->setParent(0); + window->setParent(nullptr); window->showNormal(); QVERIFY(QTest::qWaitForWindowExposed(window)); - qApp->processEvents(); + QCoreApplication::processEvents(); spy.clear(); triggerSignal(window, &workspace, signal); QCOMPARE(spy.count(), 0); delete window; - window = 0; + window = nullptr; } void tst_QMdiSubWindow::showShaded() { QMdiArea workspace; + workspace.setWindowTitle(QLatin1String(QTest::currentTestFunction())); QMdiSubWindow *window = workspace.addSubWindow(new QLineEdit); window->resize(300, 300); - qApp->processEvents(); + QCoreApplication::processEvents(); workspace.show(); QVERIFY(QTest::qWaitForWindowExposed(&workspace)); @@ -588,7 +615,7 @@ void tst_QMdiSubWindow::showShaded() // vertical resize with the mouse. int offset = window->style()->pixelMetric(QStyle::PM_MDIFrameWidth) / 2; QPoint mousePosition(window->width() - qMax(offset, 2), window->height() - qMax(offset, 2)); - QWidget *mouseReceiver = 0; + QWidget *mouseReceiver = nullptr; #ifdef Q_OS_MAC if (window->style()->inherits("QMacStyle")) mouseReceiver = window->findChild<QSizeGrip *>(); @@ -609,7 +636,7 @@ void tst_QMdiSubWindow::showShaded() QCOMPARE(window->height(), minimumSizeHint.height()); window->showShaded(); - window->setParent(0); + window->setParent(nullptr); window->show(); QVERIFY(!window->isShaded()); @@ -630,17 +657,18 @@ void tst_QMdiSubWindow::showNormal() QFETCH(QByteArray, slot); QMdiArea workspace; + workspace.setWindowTitle(QLatin1String(QTest::currentTestFunction())); QWidget *window = workspace.addSubWindow(new QWidget); - qApp->processEvents(); + QCoreApplication::processEvents(); workspace.show(); window->show(); QVERIFY(QTest::qWaitForWindowExposed(&workspace)); QRect originalGeometry = window->geometry(); QVERIFY(QMetaObject::invokeMethod(window, slot.data())); - qApp->processEvents(); + QCoreApplication::processEvents(); window->showNormal(); - qApp->processEvents(); + QCoreApplication::processEvents(); #ifdef Q_OS_WINRT QEXPECT_FAIL("showMinimized", "Windows are maximized per default on WinRt ", Abort); QEXPECT_FAIL("showMaximized", "Windows are maximized per default on WinRt ", Abort); @@ -651,8 +679,8 @@ void tst_QMdiSubWindow::showNormal() class EventSpy : public QObject { public: - EventSpy(QObject *object, QEvent::Type event) - : eventToSpy(event), _count(0) + explicit EventSpy(QObject *object, QEvent::Type event) + : eventToSpy(event) { if (object) object->installEventFilter(this); @@ -662,7 +690,7 @@ public: void clear() { _count = 0; } protected: - bool eventFilter(QObject *object, QEvent *event) + bool eventFilter(QObject *object, QEvent *event) override { if (event->type() == eventToSpy) ++_count; @@ -670,8 +698,8 @@ protected: } private: - QEvent::Type eventToSpy; - int _count; + const QEvent::Type eventToSpy; + int _count = 0; }; #ifndef QT_NO_CURSOR @@ -696,13 +724,15 @@ void tst_QMdiSubWindow::setOpaqueResizeAndMove() QFETCH(QSize, windowSize); QMdiArea workspace; + workspace.setWindowTitle(QLatin1String(QTest::currentTestFunction()) + + QLatin1String("::") + QLatin1String(QTest::currentDataTag())); QMdiSubWindow *window = qobject_cast<QMdiSubWindow *>(workspace.addSubWindow(new QWidget)); - qApp->processEvents(); + QCoreApplication::processEvents(); workspace.resize(workspaceSize); workspace.show(); QVERIFY(QTest::qWaitForWindowExposed(&workspace)); - QWidget *mouseReceiver = 0; + QWidget *mouseReceiver = nullptr; if (window->style()->inherits("QMacStyle")) mouseReceiver = window->findChild<QSizeGrip *>(); else @@ -811,81 +841,81 @@ void tst_QMdiSubWindow::setWindowFlags_data() // Standard window types with no custom flags set. QTest::newRow("Qt::Widget") << Qt::Widget << Qt::SubWindow - << Qt::WindowFlags(0) << StandardWindowFlags; + << Qt::WindowFlags{} << StandardWindowFlags; QTest::newRow("Qt::Window") << Qt::Window << Qt::SubWindow - << Qt::WindowFlags(0) << StandardWindowFlags; + << Qt::WindowFlags{} << StandardWindowFlags; QTest::newRow("Qt::Dialog") << Qt::Dialog << Qt::SubWindow - << Qt::WindowFlags(0) << DialogWindowFlags; + << Qt::WindowFlags{} << DialogWindowFlags; QTest::newRow("Qt::Sheet") << Qt::Sheet << Qt::SubWindow - << Qt::WindowFlags(0) << StandardWindowFlags; + << Qt::WindowFlags{} << StandardWindowFlags; QTest::newRow("Qt::Drawer") << Qt::Drawer << Qt::SubWindow - << Qt::WindowFlags(0) << StandardWindowFlags; + << Qt::WindowFlags{} << StandardWindowFlags; QTest::newRow("Qt::Popup") << Qt::Popup << Qt::SubWindow - << Qt::WindowFlags(0) << StandardWindowFlags; + << Qt::WindowFlags{} << StandardWindowFlags; QTest::newRow("Qt::Tool") << Qt::Tool << Qt::SubWindow - << Qt::WindowFlags(0) << StandardWindowFlags; + << Qt::WindowFlags{} << StandardWindowFlags; QTest::newRow("Qt::ToolTip") << Qt::ToolTip << Qt::SubWindow - << Qt::WindowFlags(0) << StandardWindowFlags; + << Qt::WindowFlags{} << StandardWindowFlags; QTest::newRow("Qt::SplashScreen") << Qt::SplashScreen << Qt::SubWindow - << Qt::WindowFlags(0) << StandardWindowFlags; + << Qt::WindowFlags{} << StandardWindowFlags; QTest::newRow("Qt::Desktop") << Qt::Desktop << Qt::SubWindow - << Qt::WindowFlags(0) << StandardWindowFlags; + << Qt::WindowFlags{} << StandardWindowFlags; QTest::newRow("Qt::SubWindow") << Qt::SubWindow << Qt::SubWindow - << Qt::WindowFlags(0) << StandardWindowFlags; + << Qt::WindowFlags{} << StandardWindowFlags; // Custom flags QTest::newRow("Title") << Qt::SubWindow << Qt::SubWindow - << (Qt::WindowTitleHint | Qt::WindowFlags(0)) - << Qt::WindowFlags(0); + << (Qt::WindowTitleHint | Qt::WindowFlags{}) + << Qt::WindowFlags{}; QTest::newRow("TitleAndMin") << Qt::SubWindow << Qt::SubWindow << (Qt::WindowTitleHint | Qt::WindowMinimizeButtonHint) - << Qt::WindowFlags(0); + << Qt::WindowFlags{}; QTest::newRow("TitleAndMax") << Qt::SubWindow << Qt::SubWindow << (Qt::WindowTitleHint | Qt::WindowMaximizeButtonHint) - << Qt::WindowFlags(0); + << Qt::WindowFlags{}; QTest::newRow("TitleAndMinMax") << Qt::SubWindow << Qt::SubWindow << (Qt::WindowTitleHint | Qt::WindowMinMaxButtonsHint) - << Qt::WindowFlags(0); + << Qt::WindowFlags{}; QTest::newRow("Standard") << Qt::SubWindow << Qt::SubWindow << StandardWindowFlags - << Qt::WindowFlags(0); + << Qt::WindowFlags{}; QTest::newRow("StandardAndShade") << Qt::SubWindow << Qt::SubWindow << (StandardWindowFlags | Qt::WindowShadeButtonHint) - << Qt::WindowFlags(0); + << Qt::WindowFlags{}; QTest::newRow("StandardAndContext") << Qt::SubWindow << Qt::SubWindow << (StandardWindowFlags | Qt::WindowContextHelpButtonHint) - << Qt::WindowFlags(0); + << Qt::WindowFlags{}; QTest::newRow("StandardAndStaysOnTop") << Qt::SubWindow << Qt::SubWindow << (StandardWindowFlags | Qt::WindowStaysOnTopHint) - << Qt::WindowFlags(0); + << Qt::WindowFlags{}; QTest::newRow("StandardAndFrameless") << Qt::SubWindow << Qt::SubWindow << (StandardWindowFlags | Qt::FramelessWindowHint) - << (Qt::FramelessWindowHint | Qt::WindowFlags(0)); + << Qt::WindowFlags(Qt::FramelessWindowHint); QTest::newRow("StandardAndFramelessAndStaysOnTop") << Qt::SubWindow << Qt::SubWindow << (StandardWindowFlags | Qt::FramelessWindowHint | Qt::WindowStaysOnTopHint) << (Qt::FramelessWindowHint | Qt::WindowStaysOnTopHint); QTest::newRow("Shade") << Qt::SubWindow << Qt::SubWindow - << (Qt::WindowShadeButtonHint | Qt::WindowFlags(0)) + << (Qt::WindowShadeButtonHint | Qt::WindowFlags{}) << (StandardWindowFlags | Qt::WindowShadeButtonHint); QTest::newRow("ShadeAndCustomize") << Qt::SubWindow << Qt::SubWindow << (Qt::WindowShadeButtonHint | Qt::CustomizeWindowHint) - << Qt::WindowFlags(0); + << Qt::WindowFlags{}; QTest::newRow("Context") << Qt::SubWindow << Qt::SubWindow - << (Qt::WindowContextHelpButtonHint | Qt::WindowFlags(0)) + << (Qt::WindowContextHelpButtonHint | Qt::WindowFlags{}) << (StandardWindowFlags | Qt::WindowContextHelpButtonHint); QTest::newRow("ContextAndCustomize") << Qt::SubWindow << Qt::SubWindow << (Qt::WindowContextHelpButtonHint | Qt::CustomizeWindowHint) - << Qt::WindowFlags(0); + << Qt::WindowFlags{}; QTest::newRow("ShadeAndContext") << Qt::SubWindow << Qt::SubWindow << (Qt::WindowShadeButtonHint | Qt::WindowContextHelpButtonHint) << (StandardWindowFlags | Qt::WindowShadeButtonHint | Qt::WindowContextHelpButtonHint); QTest::newRow("ShadeAndContextAndCustomize") << Qt::SubWindow << Qt::SubWindow << (Qt::WindowShadeButtonHint | Qt::WindowContextHelpButtonHint | Qt::CustomizeWindowHint) - << Qt::WindowFlags(0); + << Qt::WindowFlags{}; QTest::newRow("OnlyCustomize") << Qt::SubWindow << Qt::SubWindow - << (Qt::CustomizeWindowHint | Qt::WindowFlags(0)) - << Qt::WindowFlags(0); + << (Qt::CustomizeWindowHint | Qt::WindowFlags{}) + << Qt::WindowFlags{}; } void tst_QMdiSubWindow::setWindowFlags() @@ -896,8 +926,10 @@ void tst_QMdiSubWindow::setWindowFlags() QFETCH(Qt::WindowFlags, expectedCustomFlags); QMdiArea workspace; + workspace.setWindowTitle(QLatin1String(QTest::currentTestFunction()) + + QLatin1String("::") + QLatin1String(QTest::currentDataTag())); QMdiSubWindow *window = qobject_cast<QMdiSubWindow *>(workspace.addSubWindow(new QWidget)); - qApp->processEvents(); + QCoreApplication::processEvents(); workspace.show(); window->show(); QVERIFY(QTest::qWaitForWindowExposed(&workspace)); @@ -914,8 +946,9 @@ void tst_QMdiSubWindow::setWindowFlags() void tst_QMdiSubWindow::mouseDoubleClick() { QMdiArea workspace; + workspace.setWindowTitle(QLatin1String(QTest::currentTestFunction())); QMdiSubWindow *window = qobject_cast<QMdiSubWindow *>(workspace.addSubWindow(new QWidget)); - qApp->processEvents(); + QCoreApplication::processEvents(); workspace.show(); window->show(); @@ -939,11 +972,11 @@ void tst_QMdiSubWindow::mouseDoubleClick() // Without Qt::WindowShadeButtonHint flag set sendMouseDoubleClick(window, mousePosition); - qApp->processEvents(); + QCoreApplication::processEvents(); QVERIFY(window->isMaximized()); sendMouseDoubleClick(window, mousePosition); - qApp->processEvents(); + QCoreApplication::processEvents(); QVERIFY(!window->isMaximized()); QCOMPARE(window->geometry(), originalGeometry); @@ -952,11 +985,11 @@ void tst_QMdiSubWindow::mouseDoubleClick() QVERIFY(window->windowFlags() & Qt::WindowShadeButtonHint); originalGeometry = window->geometry(); sendMouseDoubleClick(window, mousePosition); - qApp->processEvents(); + QCoreApplication::processEvents(); QVERIFY(window->isShaded()); sendMouseDoubleClick(window, mousePosition); - qApp->processEvents(); + QCoreApplication::processEvents(); QVERIFY(!window->isShaded()); QCOMPARE(window->geometry(), originalGeometry); @@ -976,20 +1009,25 @@ void tst_QMdiSubWindow::setSystemMenu() QCOMPARE(subWindow->actions(), systemMenu->actions()); QMainWindow mainWindow; + mainWindow.setWindowTitle(QLatin1String(QTest::currentTestFunction())); QMdiArea *mdiArea = new QMdiArea; mdiArea->addSubWindow(subWindow); mainWindow.setCentralWidget(mdiArea); mainWindow.menuBar()->setNativeMenuBar(false); - mainWindow.show(); + // Prevent the window from spanning screens + if (QGuiApplication::screens().size() > 1) + mainWindow.showMaximized(); + else + mainWindow.show(); QVERIFY(QTest::qWaitForWindowExposed(&mainWindow)); QTRY_VERIFY(subWindow->isVisible()); QPoint globalPopupPos; // Show system menu - QVERIFY(!qApp->activePopupWidget()); + QVERIFY(!QApplication::activePopupWidget()); subWindow->showSystemMenu(); - QTRY_COMPARE(qApp->activePopupWidget(), qobject_cast<QWidget *>(systemMenu)); + QTRY_COMPARE(QApplication::activePopupWidget(), qobject_cast<QWidget *>(systemMenu)); #ifdef Q_OS_WINRT QEXPECT_FAIL("", "Broken on WinRT - QTBUG-68297", Abort); #endif @@ -997,12 +1035,12 @@ void tst_QMdiSubWindow::setSystemMenu() (globalPopupPos = subWindow->mapToGlobal(subWindow->contentsRect().topLeft())) ); systemMenu->hide(); - QVERIFY(!qApp->activePopupWidget()); + QVERIFY(!QApplication::activePopupWidget()); QTest::ignoreMessage(QtWarningMsg, "QMdiSubWindow::setSystemMenu: system menu is already set"); subWindow->setSystemMenu(systemMenu); - subWindow->setSystemMenu(0); + subWindow->setSystemMenu(nullptr); QVERIFY(!systemMenu); // systemMenu is QPointer systemMenu = new QMenu(subWindow); @@ -1014,13 +1052,13 @@ void tst_QMdiSubWindow::setSystemMenu() QCOMPARE(subWindow->systemMenu()->actions().count(), 1); // Show the new system menu - QVERIFY(!qApp->activePopupWidget()); + QVERIFY(!QApplication::activePopupWidget()); subWindow->showSystemMenu(); - QTRY_COMPARE(qApp->activePopupWidget(), qobject_cast<QWidget *>(systemMenu)); + QTRY_COMPARE(QApplication::activePopupWidget(), qobject_cast<QWidget *>(systemMenu)); QTRY_COMPARE(systemMenu->mapToGlobal(QPoint(0, 0)), globalPopupPos); systemMenu->hide(); - QVERIFY(!qApp->activePopupWidget()); + QVERIFY(!QApplication::activePopupWidget()); #if !defined (Q_OS_DARWIN) // System menu in menu bar. @@ -1029,29 +1067,30 @@ void tst_QMdiSubWindow::setSystemMenu() QWidget *menuLabel = subWindow->maximizedSystemMenuIconWidget(); QVERIFY(menuLabel); subWindow->showSystemMenu(); - QTRY_COMPARE(qApp->activePopupWidget(), qobject_cast<QWidget *>(systemMenu)); + QTRY_COMPARE(QApplication::activePopupWidget(), qobject_cast<QWidget *>(systemMenu)); QCOMPARE(systemMenu->mapToGlobal(QPoint(0, 0)), (globalPopupPos = menuLabel->mapToGlobal(QPoint(0, menuLabel->y() + menuLabel->height())))); systemMenu->hide(); - QTRY_VERIFY(!qApp->activePopupWidget()); + QTRY_VERIFY(!QApplication::activePopupWidget()); subWindow->showNormal(); #endif // Reverse - qApp->setLayoutDirection(Qt::RightToLeft); - qApp->processEvents(); + LayoutDirectionGuard guard; + QApplication::setLayoutDirection(Qt::RightToLeft); + QCoreApplication::processEvents(); mainWindow.updateGeometry(); QTest::qWait(150); subWindow->showSystemMenu(); - QTRY_COMPARE(qApp->activePopupWidget(), qobject_cast<QWidget *>(systemMenu)); + QTRY_COMPARE(QApplication::activePopupWidget(), qobject_cast<QWidget *>(systemMenu)); // + QPoint(1, 0) because topRight() == QPoint(left() + width() -1, top()) globalPopupPos = subWindow->mapToGlobal(subWindow->contentsRect().topRight()) + QPoint(1, 0); globalPopupPos -= QPoint(systemMenu->sizeHint().width(), 0); QTRY_COMPARE(systemMenu->mapToGlobal(QPoint(0, 0)), globalPopupPos); systemMenu->hide(); - QVERIFY(!qApp->activePopupWidget()); + QVERIFY(!QApplication::activePopupWidget()); #if !defined (Q_OS_DARWIN) // System menu in menu bar in reverse mode. @@ -1060,18 +1099,15 @@ void tst_QMdiSubWindow::setSystemMenu() menuLabel = subWindow->maximizedSystemMenuIconWidget(); QVERIFY(menuLabel); subWindow->showSystemMenu(); - QTRY_COMPARE(qApp->activePopupWidget(), qobject_cast<QWidget *>(systemMenu)); + QTRY_COMPARE(QApplication::activePopupWidget(), qobject_cast<QWidget *>(systemMenu)); globalPopupPos = menuLabel->mapToGlobal(QPoint(menuLabel->width(), menuLabel->y() + menuLabel->height())); globalPopupPos -= QPoint(systemMenu->sizeHint().width(), 0); QTRY_COMPARE(systemMenu->mapToGlobal(QPoint(0, 0)), globalPopupPos); #endif delete systemMenu; - QVERIFY(!qApp->activePopupWidget()); + QVERIFY(!QApplication::activePopupWidget()); QVERIFY(!subWindow->systemMenu()); - - // Restore layout direction. - qApp->setLayoutDirection(Qt::LeftToRight); } void tst_QMdiSubWindow::restoreFocus() @@ -1097,7 +1133,7 @@ void tst_QMdiSubWindow::restoreFocus() QMdiArea *nestedWorkspace = new QMdiArea; for (int i = 0; i < 4; ++i) nestedWorkspace->addSubWindow(new QTextEdit)->show(); - qApp->processEvents(); + QCoreApplication::processEvents(); nestedWorkspace->setHorizontalScrollBarPolicy(Qt::ScrollBarAsNeeded); nestedWorkspace->setVerticalScrollBarPolicy(Qt::ScrollBarAsNeeded); box4->layout()->addWidget(nestedWorkspace); @@ -1112,76 +1148,76 @@ void tst_QMdiSubWindow::restoreFocus() // Add complex widget to workspace. QMdiArea topArea; + topArea.setWindowTitle(QLatin1String(QTest::currentTestFunction())); QMdiSubWindow *complexWindow = topArea.addSubWindow(box); topArea.show(); box->show(); - qApp->setActiveWindow(&topArea); + QApplication::setActiveWindow(&topArea); QMdiSubWindow *expectedFocusWindow = nestedWorkspace->subWindowList().last(); QVERIFY(expectedFocusWindow); QVERIFY(expectedFocusWindow->widget()); - QCOMPARE(qApp->focusWidget(), expectedFocusWindow->widget()); + QCOMPARE(QApplication::focusWidget(), expectedFocusWindow->widget()); // Normal -> minimized expectedFocusWindow->showMinimized(); - qApp->processEvents(); + QCoreApplication::processEvents(); QVERIFY(expectedFocusWindow->isMinimized()); - qDebug() << expectedFocusWindow<< qApp->focusWidget(); - QCOMPARE(qApp->focusWidget(), static_cast<QWidget *>(expectedFocusWindow)); + QCOMPARE(QApplication::focusWidget(), static_cast<QWidget *>(expectedFocusWindow)); // Minimized -> normal expectedFocusWindow->showNormal(); - qApp->processEvents(); + QCoreApplication::processEvents(); QVERIFY(!expectedFocusWindow->isMinimized()); - QCOMPARE(qApp->focusWidget(), expectedFocusWindow->widget()); + QCOMPARE(QApplication::focusWidget(), expectedFocusWindow->widget()); // Normal -> maximized expectedFocusWindow->showMaximized(); - qApp->processEvents(); + QCoreApplication::processEvents(); QVERIFY(expectedFocusWindow->isMaximized()); - QCOMPARE(qApp->focusWidget(), expectedFocusWindow->widget()); + QCOMPARE(QApplication::focusWidget(), expectedFocusWindow->widget()); // Maximized -> normal expectedFocusWindow->showNormal(); - qApp->processEvents(); + QCoreApplication::processEvents(); QVERIFY(!expectedFocusWindow->isMaximized()); - QCOMPARE(qApp->focusWidget(), expectedFocusWindow->widget()); + QCOMPARE(QApplication::focusWidget(), expectedFocusWindow->widget()); // Minimized -> maximized expectedFocusWindow->showMinimized(); - qApp->processEvents(); + QCoreApplication::processEvents(); QVERIFY(expectedFocusWindow->isMinimized()); expectedFocusWindow->showMaximized(); - qApp->processEvents(); + QCoreApplication::processEvents(); QVERIFY(expectedFocusWindow->isMaximized()); - QCOMPARE(qApp->focusWidget(), expectedFocusWindow->widget()); + QCOMPARE(QApplication::focusWidget(), expectedFocusWindow->widget()); // Maximized -> minimized expectedFocusWindow->showNormal(); - qApp->processEvents(); + QCoreApplication::processEvents(); QVERIFY(!expectedFocusWindow->isMaximized()); expectedFocusWindow->showMaximized(); - qApp->processEvents(); + QCoreApplication::processEvents(); QVERIFY(expectedFocusWindow->isMaximized()); expectedFocusWindow->showMinimized(); - qApp->processEvents(); + QCoreApplication::processEvents(); QVERIFY(expectedFocusWindow->isMinimized()); - QCOMPARE(qApp->focusWidget(), static_cast<QWidget *>(expectedFocusWindow)); + QCOMPARE(QApplication::focusWidget(), static_cast<QWidget *>(expectedFocusWindow)); complexWindow->showMinimized(); - qApp->processEvents(); + QCoreApplication::processEvents(); QVERIFY(complexWindow->isMinimized()); - QCOMPARE(qApp->focusWidget(), static_cast<QWidget *>(complexWindow)); + QCOMPARE(QApplication::focusWidget(), static_cast<QWidget *>(complexWindow)); complexWindow->showNormal(); - qApp->processEvents(); + QCoreApplication::processEvents(); QVERIFY(!complexWindow->isMinimized()); - QCOMPARE(qApp->focusWidget(), static_cast<QWidget *>(expectedFocusWindow)); + QCOMPARE(QApplication::focusWidget(), static_cast<QWidget *>(expectedFocusWindow)); } class MultiWidget : public QWidget { public: - explicit MultiWidget(QWidget *parent = 0) : QWidget(parent) + explicit MultiWidget(QWidget *parent = nullptr) : QWidget(parent) , m_lineEdit1(new QLineEdit(this)), m_lineEdit2(new QLineEdit(this)) { QVBoxLayout *lt = new QVBoxLayout(this); @@ -1237,28 +1273,29 @@ void tst_QMdiSubWindow::changeFocusWithTab() widget->layout()->addWidget(thirdLineEdit); QMdiArea mdiArea; + mdiArea.setWindowTitle(QLatin1String(QTest::currentTestFunction())); mdiArea.addSubWindow(widget); mdiArea.show(); QCOMPARE(mdiArea.subWindowList().count(), 1); - qApp->setActiveWindow(&mdiArea); - QCOMPARE(qApp->focusWidget(), static_cast<QWidget *>(firstLineEdit)); + QApplication::setActiveWindow(&mdiArea); + QCOMPARE(QApplication::focusWidget(), static_cast<QWidget *>(firstLineEdit)); // Next QTest::keyPress(widget, Qt::Key_Tab); - QCOMPARE(qApp->focusWidget(), static_cast<QWidget *>(secondLineEdit)); + QCOMPARE(QApplication::focusWidget(), static_cast<QWidget *>(secondLineEdit)); // Next QTest::keyPress(widget, Qt::Key_Tab); - QCOMPARE(qApp->focusWidget(), static_cast<QWidget *>(thirdLineEdit)); + QCOMPARE(QApplication::focusWidget(), static_cast<QWidget *>(thirdLineEdit)); // Previous QTest::keyPress(widget, Qt::Key_Backtab); - QCOMPARE(qApp->focusWidget(), static_cast<QWidget *>(secondLineEdit)); + QCOMPARE(QApplication::focusWidget(), static_cast<QWidget *>(secondLineEdit)); // Previous QTest::keyPress(widget, Qt::Key_Backtab); - QCOMPARE(qApp->focusWidget(), static_cast<QWidget *>(firstLineEdit)); + QCOMPARE(QApplication::focusWidget(), static_cast<QWidget *>(firstLineEdit)); QMdiSubWindow *window = mdiArea.addSubWindow(new QPushButton); window->show(); @@ -1269,31 +1306,32 @@ void tst_QMdiSubWindow::changeFocusWithTab() // focus (which is the case for a QPushButton). QTest::keyPress(window, Qt::Key_Tab); QCOMPARE(mdiArea.activeSubWindow(), window); - QCOMPARE(qApp->focusWidget(), tabAllWidgets() ? window->widget() : window); + QCOMPARE(QApplication::focusWidget(), tabAllWidgets() ? window->widget() : window); QTest::keyPress(window, Qt::Key_Tab); QCOMPARE(mdiArea.activeSubWindow(), window); - QCOMPARE(qApp->focusWidget(), tabAllWidgets() ? window->widget() : window); + QCOMPARE(QApplication::focusWidget(), tabAllWidgets() ? window->widget() : window); } class MyTextEdit : public QTextEdit { public: - MyTextEdit(QWidget *parent = 0) : QTextEdit(parent), acceptClose(false) {} + using QTextEdit::QTextEdit; void setAcceptClose(bool enable = true) { acceptClose = enable; } protected: - void closeEvent(QCloseEvent *closeEvent) + void closeEvent(QCloseEvent *closeEvent) override { if (!acceptClose) closeEvent->ignore(); } private: - bool acceptClose; + bool acceptClose = false; }; void tst_QMdiSubWindow::closeEvent() { QMdiArea mdiArea; + mdiArea.setWindowTitle(QLatin1String(QTest::currentTestFunction())); mdiArea.show(); MyTextEdit *textEdit = new MyTextEdit; @@ -1379,7 +1417,7 @@ void tst_QMdiSubWindow::setWindowTitle() textEdit->setWindowModified(true); QVERIFY(window->isWindowModified()); - window->setWidget(0); + window->setWidget(nullptr); QCOMPARE(window->windowTitle(), QString()); QVERIFY(!window->isWindowModified()); delete textEdit; @@ -1405,6 +1443,8 @@ void tst_QMdiSubWindow::resizeEvents() QFETCH(bool, isShadeMode); QMainWindow mainWindow; + mainWindow.setWindowTitle(QLatin1String(QTest::currentTestFunction()) + + QLatin1String("::") + QLatin1String(QTest::currentDataTag())); QMdiArea *mdiArea = new QMdiArea; mainWindow.setCentralWidget(mdiArea); mainWindow.show(); @@ -1483,6 +1523,7 @@ void tst_QMdiSubWindow::hideAndShow() // Set the tab widget as the central widget in QMainWindow. QMainWindow mainWindow; + mainWindow.setWindowTitle(QLatin1String(QTest::currentTestFunction())); mainWindow.setGeometry(0, 0, 640, 480); QMenuBar *menuBar = mainWindow.menuBar(); menuBar->setNativeMenuBar(false); @@ -1524,7 +1565,7 @@ void tst_QMdiSubWindow::hideAndShow() // Show QMdiArea. tabWidget->setCurrentIndex(0); - qApp->processEvents(); + QCoreApplication::processEvents(); subWindow = mdiArea->subWindowList().back(); QVERIFY(subWindow); @@ -1544,7 +1585,8 @@ void tst_QMdiSubWindow::hideAndShow() QVERIFY(!menuBar->cornerWidget(Qt::TopRightCorner)); // Check that newly added windows got right sizes. - foreach (QMdiSubWindow *window, mdiArea->subWindowList()) + const auto subWindowList = mdiArea->subWindowList(); + for (QMdiSubWindow *window : subWindowList) QCOMPARE(window->size(), window->sizeHint()); subWindow->showMaximized(); @@ -1582,6 +1624,7 @@ void tst_QMdiSubWindow::hideAndShow() void tst_QMdiSubWindow::keepWindowMaximizedState() { QMdiArea mdiArea; + mdiArea.setWindowTitle(QLatin1String(QTest::currentTestFunction())); QMdiSubWindow *subWindow = mdiArea.addSubWindow(new QTextEdit); mdiArea.show(); QVERIFY(QTest::qWaitForWindowExposed(&mdiArea)); @@ -1619,6 +1662,7 @@ void tst_QMdiSubWindow::keepWindowMaximizedState() void tst_QMdiSubWindow::explicitlyHiddenWidget() { QMdiArea mdiArea; + mdiArea.setWindowTitle(QLatin1String(QTest::currentTestFunction())); QTextEdit *textEdit = new QTextEdit; textEdit->hide(); QMdiSubWindow *subWindow = mdiArea.addSubWindow(textEdit); @@ -1657,7 +1701,7 @@ void tst_QMdiSubWindow::explicitlyHiddenWidget() textEdit->show(); subWindow->showMinimized(); - subWindow->setWidget(0); + subWindow->setWidget(nullptr); delete textEdit; textEdit = new QTextEdit; textEdit->hide(); @@ -1670,6 +1714,7 @@ void tst_QMdiSubWindow::explicitlyHiddenWidget() void tst_QMdiSubWindow::resizeTimer() { QMdiArea mdiArea; + mdiArea.setWindowTitle(QLatin1String(QTest::currentTestFunction())); QMdiSubWindow *subWindow = mdiArea.addSubWindow(new QWidget); mdiArea.show(); QVERIFY(QTest::qWaitForWindowExposed(&mdiArea)); @@ -1679,7 +1724,7 @@ void tst_QMdiSubWindow::resizeTimer() for (int i = 0; i < 20; ++i) { subWindow->resize(subWindow->size() + QSize(2, 2)); - qApp->processEvents(); + QCoreApplication::processEvents(); } QTest::qWait(500); // Wait for timer events to occur. @@ -1690,6 +1735,7 @@ void tst_QMdiSubWindow::resizeTimer() void tst_QMdiSubWindow::fixedMinMaxSize() { QMdiArea mdiArea; + mdiArea.setWindowTitle(QLatin1String(QTest::currentTestFunction())); mdiArea.setGeometry(0, 0, 640, 480); mdiArea.show(); QVERIFY(QTest::qWaitForWindowExposed(&mdiArea)); @@ -1748,49 +1794,51 @@ void tst_QMdiSubWindow::replaceMenuBarWhileMaximized() { QMainWindow mainWindow; + mainWindow.setWindowTitle(QLatin1String(QTest::currentTestFunction())); QMdiArea *mdiArea = new QMdiArea; QMdiSubWindow *subWindow = mdiArea->addSubWindow(new QTextEdit); subWindow->showMaximized(); mainWindow.setCentralWidget(mdiArea); - QMenuBar *menuBar = mainWindow.menuBar(); - menuBar->setNativeMenuBar(false); + QMenuBar *menuBar1 = mainWindow.menuBar(); + menuBar1->setNativeMenuBar(false); mainWindow.show(); QVERIFY(QTest::qWaitForWindowExposed(&mainWindow)); - qApp->processEvents(); + QCoreApplication::processEvents(); #if defined Q_OS_QNX QEXPECT_FAIL("", "QTBUG-38231", Abort); #endif QVERIFY(subWindow->maximizedButtonsWidget()); QVERIFY(subWindow->maximizedSystemMenuIconWidget()); - QCOMPARE(menuBar->cornerWidget(Qt::TopLeftCorner), subWindow->maximizedSystemMenuIconWidget()); - QCOMPARE(menuBar->cornerWidget(Qt::TopRightCorner), subWindow->maximizedButtonsWidget()); + QCOMPARE(menuBar1->cornerWidget(Qt::TopLeftCorner), subWindow->maximizedSystemMenuIconWidget()); + QCOMPARE(menuBar1->cornerWidget(Qt::TopRightCorner), subWindow->maximizedButtonsWidget()); // Replace. - mainWindow.setMenuBar(new QMenuBar); - menuBar = mainWindow.menuBar(); - menuBar->setNativeMenuBar(false); - qApp->processEvents(); + auto menuBar2 = new QMenuBar; + mainWindow.setMenuBar(menuBar2); + menuBar2->setNativeMenuBar(false); + QCoreApplication::processEvents(); QVERIFY(subWindow->maximizedButtonsWidget()); QVERIFY(subWindow->maximizedSystemMenuIconWidget()); - QCOMPARE(menuBar->cornerWidget(Qt::TopLeftCorner), subWindow->maximizedSystemMenuIconWidget()); - QCOMPARE(menuBar->cornerWidget(Qt::TopRightCorner), subWindow->maximizedButtonsWidget()); + QCOMPARE(menuBar2->cornerWidget(Qt::TopLeftCorner), subWindow->maximizedSystemMenuIconWidget()); + QCOMPARE(menuBar2->cornerWidget(Qt::TopRightCorner), subWindow->maximizedButtonsWidget()); subWindow->showNormal(); QVERIFY(!subWindow->maximizedButtonsWidget()); QVERIFY(!subWindow->maximizedSystemMenuIconWidget()); - QVERIFY(!menuBar->cornerWidget(Qt::TopLeftCorner)); - QVERIFY(!menuBar->cornerWidget(Qt::TopRightCorner)); + QVERIFY(!menuBar2->cornerWidget(Qt::TopLeftCorner)); + QVERIFY(!menuBar2->cornerWidget(Qt::TopRightCorner)); // Delete and replace. subWindow->showMaximized(); - delete menuBar; - mainWindow.setMenuBar(new QMenuBar); - qApp->processEvents(); + delete menuBar2; + auto menuBar3 = new QMenuBar; + mainWindow.setMenuBar(menuBar3); + QCoreApplication::processEvents(); QVERIFY(!subWindow->maximizedButtonsWidget()); QVERIFY(!subWindow->maximizedSystemMenuIconWidget()); @@ -1801,8 +1849,8 @@ void tst_QMdiSubWindow::replaceMenuBarWhileMaximized() // Delete. subWindow->showMaximized(); - mainWindow.setMenuBar(0); - qApp->processEvents(); + mainWindow.setMenuBar(nullptr); + QCoreApplication::processEvents(); QVERIFY(!mainWindow.menuWidget()); QVERIFY(!subWindow->maximizedButtonsWidget()); @@ -1811,6 +1859,8 @@ void tst_QMdiSubWindow::replaceMenuBarWhileMaximized() subWindow->showNormal(); QVERIFY(!subWindow->maximizedButtonsWidget()); QVERIFY(!subWindow->maximizedSystemMenuIconWidget()); + delete menuBar1; + delete menuBar3; } void tst_QMdiSubWindow::closeOnDoubleClick_data() @@ -1842,9 +1892,9 @@ void tst_QMdiSubWindow::closeOnDoubleClick() const QRect actionGeometry = systemMenu->actionGeometry(systemMenu->actions().at(actionIndex)); sendMouseDoubleClick(systemMenu, actionGeometry.center()); - if (qApp->activePopupWidget() == static_cast<QWidget *>(systemMenu)) + if (QApplication::activePopupWidget() == static_cast<QWidget *>(systemMenu)) systemMenu->hide(); - qApp->processEvents(); + QCoreApplication::processEvents(); QVERIFY(!systemMenu || !systemMenu->isVisible()); QCOMPARE(subWindow.isNull() || !subWindow->isVisible(), expectClosed); } @@ -1854,6 +1904,7 @@ void tst_QMdiSubWindow::setFont() { QSKIP("This test function is unstable in CI, please see QTBUG-22544"); QMdiArea mdiArea; + mdiArea.setWindowTitle(QLatin1String(QTest::currentTestFunction())); QMdiSubWindow *subWindow = mdiArea.addSubWindow(new QPushButton(QLatin1String("test"))); subWindow->resize(300, 100); subWindow->setWindowTitle(QLatin1String("Window title")); @@ -1871,7 +1922,7 @@ void tst_QMdiSubWindow::setFont() QFont newFont(QLatin1String("Helvetica"), 16); newFont.setBold(true); subWindow->setFont(newFont); - qApp->processEvents(); + QCoreApplication::processEvents(); const QFont &swFont = subWindow->font(); QCOMPARE(swFont.family(), newFont.family()); QCOMPARE(swFont.pointSize(), newFont.pointSize()); @@ -1880,7 +1931,7 @@ void tst_QMdiSubWindow::setFont() QVERIFY(newTitleBar != originalTitleBar); subWindow->setFont(originalFont); - qApp->processEvents(); + QCoreApplication::processEvents(); QCOMPARE(subWindow->font(), originalFont); newTitleBar = subWindow->grab(titleBarRect).toImage(); QCOMPARE(newTitleBar, originalTitleBar); @@ -1889,6 +1940,7 @@ void tst_QMdiSubWindow::setFont() void tst_QMdiSubWindow::task_188849() { QMainWindow mainWindow; + mainWindow.setWindowTitle(QLatin1String(QTest::currentTestFunction())); // Sets a regular QWidget (and NOT a QMenuBar) as the menu bar. mainWindow.setMenuWidget(new QWidget); @@ -1907,10 +1959,11 @@ void tst_QMdiSubWindow::task_188849() void tst_QMdiSubWindow::mdiArea() { QMdiArea mdiArea; + mdiArea.setWindowTitle(QLatin1String(QTest::currentTestFunction())); QMdiSubWindow *subWindow = mdiArea.addSubWindow(new QWidget); QCOMPARE(subWindow->mdiArea(), &mdiArea); - subWindow->setParent(0); + subWindow->setParent(nullptr); QVERIFY(!subWindow->mdiArea()); // Child of the area's corner widget. @@ -1931,10 +1984,11 @@ void tst_QMdiSubWindow::task_182852() { QMdiArea *workspace = new QMdiArea; QMainWindow mainWindow; + mainWindow.setWindowTitle(QLatin1String(QTest::currentTestFunction())); mainWindow.setCentralWidget(workspace); mainWindow.show(); mainWindow.menuBar()->setVisible(true); - qApp->setActiveWindow(&mainWindow); + QApplication::setActiveWindow(&mainWindow); if (mainWindow.menuBar()->isNativeMenuBar()) return; // The main window's title is not overwritten if we have a native menubar (macOS, Unity etc.) @@ -1950,7 +2004,7 @@ void tst_QMdiSubWindow::task_182852() workspace->addSubWindow(window); window->showMaximized(); - qApp->processEvents(); + QCoreApplication::processEvents(); QVERIFY(window->isMaximized()); QCOMPARE(mainWindow.windowTitle(), QString::fromLatin1("%1 - [%2]") @@ -1977,6 +2031,7 @@ void tst_QMdiSubWindow::task_182852() void tst_QMdiSubWindow::task_233197() { QMainWindow *mainWindow = new QMainWindow; + mainWindow->setWindowTitle(QLatin1String(QTest::currentTestFunction())); mainWindow->setAttribute(Qt::WA_DeleteOnClose); mainWindow->resize(500, 200); mainWindow->show(); @@ -2001,17 +2056,19 @@ void tst_QMdiSubWindow::task_233197() Q_UNUSED(menuBar); QPushButton *focus1 = new QPushButton(QLatin1String("Focus 1"), mainWindow); - QObject::connect(focus1, SIGNAL(clicked()), subWindow1, SLOT(setFocus())); + QObject::connect(focus1, &QAbstractButton::clicked, subWindow1, + QOverload<>::of(&QWidget::setFocus)); focus1->move(5, 30); focus1->show(); QPushButton *focus2 = new QPushButton(QLatin1String("Focus 2"), mainWindow); - QObject::connect(focus2, SIGNAL(clicked()), subWindow2, SLOT(setFocus())); + QObject::connect(focus2, &QAbstractButton::clicked, subWindow2, + QOverload<>::of(&QWidget::setFocus)); focus2->move(5, 60); focus2->show(); QPushButton *close = new QPushButton(QLatin1String("Close"), mainWindow); - QObject::connect(close, SIGNAL(clicked()), mainWindow, SLOT(close())); + QObject::connect(close, &QAbstractButton::clicked, mainWindow, &QWidget::close); close->move(5, 90); close->show(); @@ -2035,6 +2092,7 @@ void tst_QMdiSubWindow::task_233197() void tst_QMdiSubWindow::task_226929() { QMdiArea mdiArea; + mdiArea.setWindowTitle(QLatin1String(QTest::currentTestFunction())); mdiArea.show(); QVERIFY(QTest::qWaitForWindowExposed(&mdiArea)); @@ -2056,6 +2114,7 @@ void tst_QMdiSubWindow::task_226929() void tst_QMdiSubWindow::styleChange() { QMdiArea mdiArea; + mdiArea.setWindowTitle(QLatin1String(QTest::currentTestFunction())); mdiArea.show(); QVERIFY(QTest::qWaitForWindowExposed(&mdiArea)); @@ -2070,7 +2129,7 @@ void tst_QMdiSubWindow::styleChange() QTest::qWait(100); qRegisterMetaType<QMdiSubWindow *>(); - QSignalSpy spy(&mdiArea, SIGNAL(subWindowActivated(QMdiSubWindow*))); + QSignalSpy spy(&mdiArea, &QMdiArea::subWindowActivated); QVERIFY(spy.isValid()); QEvent event(QEvent::StyleChange); @@ -2085,6 +2144,7 @@ void tst_QMdiSubWindow::styleChange() void tst_QMdiSubWindow::testFullScreenState() { QMdiArea mdiArea; + mdiArea.setWindowTitle(QLatin1String(QTest::currentTestFunction())); mdiArea.showMaximized(); QMdiSubWindow *subWindow = mdiArea.addSubWindow(new QWidget); @@ -2101,6 +2161,7 @@ void tst_QMdiSubWindow::testFullScreenState() void tst_QMdiSubWindow::testRemoveBaseWidget() { QMdiArea mdiArea; + mdiArea.setWindowTitle(QLatin1String(QTest::currentTestFunction())); mdiArea.show(); QWidget *widget1 = new QWidget; diff --git a/tests/auto/widgets/widgets/qmenubar/tst_qmenubar.cpp b/tests/auto/widgets/widgets/qmenubar/tst_qmenubar.cpp index cb829c81a6..d6ba85d61f 100644 --- a/tests/auto/widgets/widgets/qmenubar/tst_qmenubar.cpp +++ b/tests/auto/widgets/widgets/qmenubar/tst_qmenubar.cpp @@ -113,10 +113,7 @@ private slots: void check_escKey(); #endif -#ifndef Q_OS_WINCE void allowActiveAndDisabled(); -#endif - void taskQTBUG56860_focus(); void check_endKey(); void check_homeKey(); diff --git a/tests/auto/widgets/widgets/qscrollarea/tst_qscrollarea.cpp b/tests/auto/widgets/widgets/qscrollarea/tst_qscrollarea.cpp index d1923e4bb0..9f08bd337b 100644 --- a/tests/auto/widgets/widgets/qscrollarea/tst_qscrollarea.cpp +++ b/tests/auto/widgets/widgets/qscrollarea/tst_qscrollarea.cpp @@ -87,7 +87,7 @@ public: protected: QVariant inputMethodQuery(Qt::InputMethodQuery query) const { - if (query == Qt::ImMicroFocus) + if (query == Qt::ImCursorRectangle) return QRect(width() / 2, height() / 2, 5, 5); return QWidget::inputMethodQuery(query); } @@ -110,7 +110,7 @@ void tst_QScrollArea::ensureMicroFocusVisible_Task_167838() parent->resize(300, 300); scrollArea.setWidget(parent); scrollArea.ensureWidgetVisible(child, 10, 10); - QRect microFocus = child->inputMethodQuery(Qt::ImMicroFocus).toRect(); + QRect microFocus = child->inputMethodQuery(Qt::ImCursorRectangle).toRect(); QPoint p = child->mapTo(scrollArea.viewport(), microFocus.topLeft()); microFocus.translate(p - microFocus.topLeft()); QVERIFY(scrollArea.viewport()->rect().contains(microFocus)); diff --git a/tests/auto/widgets/widgets/qspinbox/tst_qspinbox.cpp b/tests/auto/widgets/widgets/qspinbox/tst_qspinbox.cpp index b9d6888263..7bce23af26 100644 --- a/tests/auto/widgets/widgets/qspinbox/tst_qspinbox.cpp +++ b/tests/auto/widgets/widgets/qspinbox/tst_qspinbox.cpp @@ -461,26 +461,30 @@ void tst_QSpinBox::setPrefixSuffix() QFETCH(QString, expectedCleanText); QFETCH(bool, show); - QSpinBox spin(0); + QSpinBox spin; + if (show) { + spin.show(); + spin.setPrefix(QString()); // trigger a recalc of sizeHint + } const QSize size1 = spin.sizeHint(); spin.setPrefix(prefix); const QSize size2 = spin.sizeHint(); spin.setSuffix(suffix); const QSize size3 = spin.sizeHint(); spin.setValue(value); - if (show) - spin.show(); QCOMPARE(spin.prefix(), prefix); QCOMPARE(spin.suffix(), suffix); QCOMPARE(spin.text(), expectedText); QCOMPARE(spin.cleanText(), expectedCleanText); - if (!prefix.isEmpty() && !suffix.isEmpty()) { - QVERIFY(size1.width() < size2.width()); + if (!suffix.isEmpty()) { QVERIFY(size2.width() < size3.width()); spin.setSuffix(QString()); QCOMPARE(spin.sizeHint(), size2); + } + if (!prefix.isEmpty()) { + QVERIFY(size1.width() < size2.width()); spin.setPrefix(QString()); QCOMPARE(spin.sizeHint(), size1); } diff --git a/tests/auto/widgets/widgets/qtabwidget/qtabwidget.pro b/tests/auto/widgets/widgets/qtabwidget/qtabwidget.pro index 6523209c32..b61cc8fa13 100644 --- a/tests/auto/widgets/widgets/qtabwidget/qtabwidget.pro +++ b/tests/auto/widgets/widgets/qtabwidget/qtabwidget.pro @@ -8,4 +8,4 @@ INCLUDEPATH += ../ HEADERS += SOURCES += tst_qtabwidget.cpp -win32:!winrt: LIBS += -luser32 +win32:!winrt: QMAKE_USE += user32 diff --git a/tests/auto/widgets/widgets/qtextbrowser/tst_qtextbrowser.cpp b/tests/auto/widgets/widgets/qtextbrowser/tst_qtextbrowser.cpp index 8a1b228c71..1f95032165 100644 --- a/tests/auto/widgets/widgets/qtextbrowser/tst_qtextbrowser.cpp +++ b/tests/auto/widgets/widgets/qtextbrowser/tst_qtextbrowser.cpp @@ -1,6 +1,6 @@ /**************************************************************************** ** -** Copyright (C) 2016 The Qt Company Ltd. +** Copyright (C) 2019 The Qt Company Ltd. ** Contact: https://www.qt.io/licensing/ ** ** This file is part of the test suite of the Qt Toolkit. @@ -38,7 +38,7 @@ class TestBrowser : public QTextBrowser { public: - inline TestBrowser() : htmlLoadAttempts(0) { + inline TestBrowser() { show(); QApplication::setActiveWindow(this); activateWindow(); @@ -47,11 +47,12 @@ public: QVERIFY(hasFocus()); } - virtual QVariant loadResource(int type, const QUrl &name); + QVariant loadResource(int type, const QUrl &name) override; - int htmlLoadAttempts; + int htmlLoadAttempts = 0; QUrl lastResource; QUrl sourceInsideLoadResource; + QUrl baseInsideLoadResource; }; QVariant TestBrowser::loadResource(int type, const QUrl &name) @@ -60,6 +61,7 @@ QVariant TestBrowser::loadResource(int type, const QUrl &name) htmlLoadAttempts++; lastResource = name; sourceInsideLoadResource = source(); + baseInsideLoadResource = document()->baseUrl(); return QTextBrowser::loadResource(type, name); } @@ -108,7 +110,7 @@ void tst_QTextBrowser::init() void tst_QTextBrowser::cleanup() { delete browser; - browser = 0; + browser = nullptr; } void tst_QTextBrowser::noReloadOnAnchorJump() @@ -428,11 +430,18 @@ void tst_QTextBrowser::sourceInsideLoadResource() #ifdef Q_OS_WINRT QSKIP("Paths cannot be compared if applications are sandboxed."); #endif - QUrl url = QUrl::fromLocalFile("pagewithimage.html"); + QUrl url = QUrl::fromLocalFile("pagewithimage.html"); // "file://pagewithimage.html" browser->setSource(url); QCOMPARE(browser->lastResource, QUrl::fromLocalFile(QDir::current().filePath("foobar.png"))); + // baseUrl was not set because the source URL was a relative one + QCOMPARE(browser->baseInsideLoadResource, QUrl()); QEXPECT_FAIL("", "This is currently not supported", Continue); QCOMPARE(browser->sourceInsideLoadResource.toString(), url.toString()); + url = QUrl::fromLocalFile(QDir::current().filePath("pagewithimage.html")); // "file:///home/user/path/to/pagewithimage.html" + browser->setSource(url); + QCOMPARE(browser->lastResource, QUrl::fromLocalFile(QDir::current().filePath("foobar.png"))); + // baseUrl has the full path, and that's where relative-path resources come from + QCOMPARE(browser->baseInsideLoadResource, QUrl::fromLocalFile(QDir::currentPath() + QLatin1Char('/'))); } void tst_QTextBrowser::textInteractionFlags_vs_readOnly() diff --git a/tests/auto/xml/sax/qxmlsimplereader/parser/main.cpp b/tests/auto/xml/sax/qxmlsimplereader/parser/main.cpp index 15f10232bd..b5d9fea315 100644 --- a/tests/auto/xml/sax/qxmlsimplereader/parser/main.cpp +++ b/tests/auto/xml/sax/qxmlsimplereader/parser/main.cpp @@ -72,7 +72,7 @@ int main(int argc, const char *argv[]) QFile in_file(file_name); if (!in_file.open(QIODevice::ReadOnly)) { - qerr << "Could not open " << file_name << ": " << strerror(errno) << endl; + qerr << "Could not open " << file_name << ": " << strerror(errno) << Qt::endl; return 1; } @@ -87,7 +87,7 @@ int main(int argc, const char *argv[]) } else { _out_file.setFileName(out_file_name); if (!_out_file.open(QIODevice::WriteOnly | QIODevice::Truncate)) { - qerr << "Could not open " << out_file_name << ": " << strerror(errno) << endl; + qerr << "Could not open " << out_file_name << ": " << strerror(errno) << Qt::endl; return 1; } _out_stream.setDevice(&_out_file); diff --git a/tests/auto/xml/sax/qxmlsimplereader/xmldocs/valid/sa/089.xml.bak b/tests/auto/xml/sax/qxmlsimplereader/xmldocs/valid/sa/089.xml.bak deleted file mode 100644 index 2d80c8f3fb..0000000000 --- a/tests/auto/xml/sax/qxmlsimplereader/xmldocs/valid/sa/089.xml.bak +++ /dev/null @@ -1,5 +0,0 @@ -<!DOCTYPE doc [
-<!ENTITY e "𐀀􏿽">
-<!ELEMENT doc (#PCDATA)>
-]>
-<doc>&e;</doc>
diff --git a/tests/baselineserver/shared/baselineprotocol.cpp b/tests/baselineserver/shared/baselineprotocol.cpp index c9f9cd9bd2..aa496d6c54 100644 --- a/tests/baselineserver/shared/baselineprotocol.cpp +++ b/tests/baselineserver/shared/baselineprotocol.cpp @@ -38,6 +38,7 @@ #include <QDir> #include <QTime> #include <QPointer> +#include <QRegExp> const QString PI_Project(QLS("Project")); const QString PI_TestCase(QLS("TestCase")); @@ -291,7 +292,8 @@ void ImageItem::writeImageToStream(QDataStream &out) const out << quint8('Q') << quint8(image.format()); out << quint8(QSysInfo::ByteOrder) << quint8(0); // pad to multiple of 4 bytes out << quint32(image.width()) << quint32(image.height()) << quint32(image.bytesPerLine()); - out << qCompress((const uchar *)image.constBits(), image.byteCount()); + out << qCompress(reinterpret_cast<const uchar *>(image.constBits()), + int(image.sizeInBytes())); //# can be followed by colormap for formats that use it } diff --git a/tests/benchmarks/corelib/tools/qdate/qdate.pro b/tests/benchmarks/corelib/tools/qdate/qdate.pro new file mode 100644 index 0000000000..a655917135 --- /dev/null +++ b/tests/benchmarks/corelib/tools/qdate/qdate.pro @@ -0,0 +1,4 @@ +TARGET = tst_bench_qdate +QT = core testlib + +SOURCES += tst_bench_qdate.cpp diff --git a/tests/benchmarks/corelib/tools/qdate/tst_bench_qdate.cpp b/tests/benchmarks/corelib/tools/qdate/tst_bench_qdate.cpp new file mode 100644 index 0000000000..399ac44065 --- /dev/null +++ b/tests/benchmarks/corelib/tools/qdate/tst_bench_qdate.cpp @@ -0,0 +1,53 @@ +/**************************************************************************** +** +** Copyright (C) 2019 The Qt Company Ltd. +** Contact: https://www.qt.io/licensing/ +** +** This file is part of the QtCore module of the Qt Toolkit. +** +** $QT_BEGIN_LICENSE:GPL-EXCEPT$ +** Commercial License Usage +** Licensees holding valid commercial Qt licenses may use this file in +** accordance with the commercial license agreement provided with the +** Software or, alternatively, in accordance with the terms contained in +** a written agreement between you and The Qt Company. For licensing terms +** and conditions see https://www.qt.io/terms-conditions. For further +** information use the contact form at https://www.qt.io/contact-us. +** +** GNU General Public License Usage +** Alternatively, this file may be used under the terms of the GNU +** General Public License version 3 as published by the Free Software +** Foundation with exceptions as appearing in the file LICENSE.GPL3-EXCEPT +** included in the packaging of this file. Please review the following +** information to ensure the GNU General Public License requirements will +** be met: https://www.gnu.org/licenses/gpl-3.0.html. +** +** $QT_END_LICENSE$ +** +****************************************************************************/ + +#include <QDateTime> +#include <QTest> + +class tst_QDate : public QObject +{ + Q_OBJECT + +private Q_SLOTS: + void monthLengths(); +}; + +void tst_QDate::monthLengths() +{ + QBENCHMARK { + for (int year = 1900; year <= 2100; year++) { + bool check = true; + for (int month = 1; month <= 12; month++) + check &= QDate::isValid(year, month, QDate(year, month, 1).daysInMonth()); + Q_UNUSED(check); + } + } +} + +QTEST_MAIN(tst_QDate) +#include "tst_bench_qdate.moc" diff --git a/tests/benchmarks/widgets/graphicsview/functional/GraphicsViewBenchmark/widgets/mainview.cpp b/tests/benchmarks/widgets/graphicsview/functional/GraphicsViewBenchmark/widgets/mainview.cpp index c8ccb60dbb..8f7736010d 100644 --- a/tests/benchmarks/widgets/graphicsview/functional/GraphicsViewBenchmark/widgets/mainview.cpp +++ b/tests/benchmarks/widgets/graphicsview/functional/GraphicsViewBenchmark/widgets/mainview.cpp @@ -270,7 +270,6 @@ void MainView::construct() // Turn off automatic background setAttribute(Qt::WA_OpaquePaintEvent); - setAttribute(Qt::WA_NoBackground); setAttribute(Qt::WA_NoSystemBackground); setAutoFillBackground(false); diff --git a/tests/manual/cocoa/noclickthrough/main.cpp b/tests/manual/cocoa/noclickthrough/main.cpp deleted file mode 100644 index eee7729999..0000000000 --- a/tests/manual/cocoa/noclickthrough/main.cpp +++ /dev/null @@ -1,48 +0,0 @@ -/**************************************************************************** - ** - ** Copyright (C) 2019 The Qt Company Ltd. - ** Contact: https://www.qt.io/licensing/ - ** - ** This file is part of the test suite of the Qt Toolkit. - ** - ** $QT_BEGIN_LICENSE:GPL-EXCEPT$ - ** Commercial License Usage - ** Licensees holding valid commercial Qt licenses may use this file in - ** accordance with the commercial license agreement provided with the - ** Software or, alternatively, in accordance with the terms contained in - ** a written agreement between you and The Qt Company. For licensing terms - ** and conditions see https://www.qt.io/terms-conditions. For further - ** information use the contact form at https://www.qt.io/contact-us. - ** - ** GNU General Public License Usage - ** Alternatively, this file may be used under the terms of the GNU - ** General Public License version 3 as published by the Free Software - ** Foundation with exceptions as appearing in the file LICENSE.GPL3-EXCEPT - ** included in the packaging of this file. Please review the following - ** information to ensure the GNU General Public License requirements will - ** be met: https://www.gnu.org/licenses/gpl-3.0.html. - ** - ** $QT_END_LICENSE$ - ** - ****************************************************************************/ - -#include <QtWidgets> - -int main(int argc, char **argv) -{ - QApplication a(argc, argv); - QWidget w; - QVBoxLayout *vbox = new QVBoxLayout; - QLabel *label = new QLabel("Make the window inactive, but visible.\n" - "Then click on the Two item.\n" - "The item should not be selected, but the window should be active."); - vbox->addWidget(label); - QListWidget *list = new QListWidget; - list->addItems(QStringList() << "One" << "Two" << "Three"); - list->selectionModel()->select(list->model()->index(0, 0), QItemSelectionModel::Select); - list->viewport()->setAttribute(Qt::WA_MacNoClickThrough); - vbox->addWidget(list); - w.setLayout(vbox); - w.show(); - return a.exec(); -} diff --git a/tests/manual/cocoa/noclickthrough/noclickthrough.pro b/tests/manual/cocoa/noclickthrough/noclickthrough.pro deleted file mode 100644 index a8e30cb146..0000000000 --- a/tests/manual/cocoa/noclickthrough/noclickthrough.pro +++ /dev/null @@ -1,4 +0,0 @@ -QT += widgets -TEMPLATE = app -TARGET = noclickthrough -SOURCES += main.cpp diff --git a/tests/manual/diaglib/diaglib.pri b/tests/manual/diaglib/diaglib.pri index 9f10167136..b57ee75841 100644 --- a/tests/manual/diaglib/diaglib.pri +++ b/tests/manual/diaglib/diaglib.pri @@ -12,7 +12,7 @@ HEADERS += \ win32:!winrt: { SOURCES += $$PWD/nativewindowdump_win.cpp - LIBS *= -luser32 + QMAKE_USE += user32 } else { SOURCES += $$PWD/nativewindowdump.cpp } diff --git a/tests/manual/lance/interactivewidget.cpp b/tests/manual/lance/interactivewidget.cpp index 8ac3881af7..d172fac900 100644 --- a/tests/manual/lance/interactivewidget.cpp +++ b/tests/manual/lance/interactivewidget.cpp @@ -45,7 +45,7 @@ InteractiveWidget::InteractiveWidget() // create and populate the command toolbox m_commandsToolBox = new QToolBox(); - QListWidget *currentListWidget = 0; + QListWidget *currentListWidget = nullptr; foreach (PaintCommands::PaintCommandInfos paintCommandInfo, PaintCommands::s_commandInfoTable) { if (paintCommandInfo.isSectionHeader()) { currentListWidget = new QListWidget(); diff --git a/tests/manual/lance/main.cpp b/tests/manual/lance/main.cpp index 749a4b1943..7f5af2d908 100644 --- a/tests/manual/lance/main.cpp +++ b/tests/manual/lance/main.cpp @@ -185,7 +185,7 @@ static void displayCommands() " pixmap_load filename name_in_script\n" " image_load filename name_in_script\n"); } -static InteractiveWidget *interactive_widget = 0; +static InteractiveWidget *interactive_widget = nullptr; static void runInteractive() { @@ -350,15 +350,15 @@ int main(int argc, char **argv) #endif } } - scaledWidth = width * scalefactor; - scaledHeight = height * scalefactor; + scaledWidth = int(width * scalefactor); + scaledHeight = int(height * scalefactor); PaintCommands pcmd(QStringList(), 800, 800, imageFormat); pcmd.setVerboseMode(verboseMode); pcmd.setType(type); pcmd.setCheckersBackground(checkers_background); - QWidget *activeWidget = 0; + QWidget *activeWidget = nullptr; if (interactive) { runInteractive(); @@ -610,7 +610,7 @@ int main(int argc, char **argv) QPrinter p(highres ? QPrinter::HighResolution : QPrinter::ScreenResolution); if (printdlg) { - QPrintDialog printDialog(&p, 0); + QPrintDialog printDialog(&p, nullptr); if (printDialog.exec() != QDialog::Accepted) break; } else { diff --git a/tests/manual/lance/widgets.h b/tests/manual/lance/widgets.h index 583d9e2455..46c55f4c16 100644 --- a/tests/manual/lance/widgets.h +++ b/tests/manual/lance/widgets.h @@ -45,31 +45,12 @@ #include <QPaintEngine> #include <QSignalMapper> #include <QAction> +#include <QDebug> #include <qmath.h> const int CP_RADIUS = 10; -class StupidWorkaround : public QObject -{ - Q_OBJECT -public: - StupidWorkaround(QWidget *widget, int *value) - : QObject(widget), w(widget), mode(value) - { - } - -public slots: - void setViewMode(int m) { - *mode = m; - w->update(); - } - -private: - QWidget *w; - int *mode; -}; - template <class T> class OnScreenWidget : public T { @@ -81,7 +62,7 @@ public: DifferenceView }; - OnScreenWidget(const QString &file, QWidget *parent = 0) + OnScreenWidget(const QString &file, QWidget *parent = nullptr) : T(parent), m_filename(file), m_view_mode(RenderView) @@ -108,33 +89,20 @@ public: } else { T::setWindowTitle("Rendering: '" + file + "'. Shortcuts: 1=render, 2=baseline, 3=difference"); - StupidWorkaround *workaround = new StupidWorkaround(this, &m_view_mode); - - QSignalMapper *mapper = new QSignalMapper(this); - T::connect(mapper, SIGNAL(mapped(int)), workaround, SLOT(setViewMode(int))); - T::connect(mapper, SIGNAL(mapped(QString)), this, SLOT(setWindowTitle(QString))); - QAction *renderViewAction = new QAction("Render View", this); renderViewAction->setShortcut(Qt::Key_1); - T::connect(renderViewAction, SIGNAL(triggered()), mapper, SLOT(map())); - mapper->setMapping(renderViewAction, RenderView); - mapper->setMapping(renderViewAction, "Render View: " + file); + T::connect(renderViewAction, &QAction::triggered, [&] { setMode(RenderView); }); T::addAction(renderViewAction); QAction *baselineAction = new QAction("Baseline", this); baselineAction->setShortcut(Qt::Key_2); - T::connect(baselineAction, SIGNAL(triggered()), mapper, SLOT(map())); - mapper->setMapping(baselineAction, BaselineView); - mapper->setMapping(baselineAction, "Baseline View: " + file); + T::connect(baselineAction, &QAction::triggered, [&] { setMode(BaselineView); }); T::addAction(baselineAction); - QAction *differenceAction = new QAction("Differenfe View", this); + QAction *differenceAction = new QAction("Difference View", this); differenceAction->setShortcut(Qt::Key_3); - T::connect(differenceAction, SIGNAL(triggered()), mapper, SLOT(map())); - mapper->setMapping(differenceAction, DifferenceView); - mapper->setMapping(differenceAction, "Difference View" + file); + T::connect(differenceAction, &QAction::triggered, [&] { setMode(DifferenceView); }); T::addAction(differenceAction); - } } @@ -148,6 +116,18 @@ public: settings.sync(); } + void setMode(ViewMode mode) { + m_view_mode = mode; + QString title; + switch (m_view_mode) { + case RenderView: title = "Render"; break; + case BaselineView: title = "Baseline"; break; + case DifferenceView: title = "Difference"; break; + } + T::setWindowTitle(title + " View: " + m_filename); + T::update(); + } + void setVerboseMode(bool v) { m_verboseMode = v; } void setCheckersBackground(bool b) { m_checkersBackground = b; } void setType(DeviceType t) { m_deviceType = t; } @@ -205,7 +185,7 @@ public: pt.begin(this); pt.setRenderHint(QPainter::Antialiasing); pt.setFont(this->font()); - pt.resetMatrix(); + pt.resetTransform(); pt.setPen(QColor(127, 127, 127, 191)); pt.setBrush(QColor(191, 191, 255, 63)); for (int i=0; i<m_controlPoints.size(); ++i) { @@ -239,7 +219,7 @@ public: p.drawPixmap(0, 0, m_baseline); - p.setPen(QColor::fromRgb(0, 0, 0, 0.1)); + p.setPen(QColor::fromRgbF(0, 0, 0, 0.1)); p.setFont(QFont("Arial", 128)); p.rotate(45); p.drawText(100, 0, "BASELINE"); @@ -251,7 +231,7 @@ public: img.fill(0); QPainter p(&img); - p.drawPixmap(0, 0, m_render_view); + p.drawImage(0, 0, m_image); p.setCompositionMode(QPainter::RasterOp_SourceXorDestination); p.drawPixmap(0, 0, m_baseline); diff --git a/tests/manual/markdown/html2md.cpp b/tests/manual/markdown/html2md.cpp new file mode 100644 index 0000000000..19d6ff06af --- /dev/null +++ b/tests/manual/markdown/html2md.cpp @@ -0,0 +1,64 @@ +/**************************************************************************** + ** + ** Copyright (C) 2019 The Qt Company Ltd. + ** Contact: https://www.qt.io/licensing/ + ** + ** This file is part of the test suite of the Qt Toolkit. + ** + ** $QT_BEGIN_LICENSE:GPL-EXCEPT$ + ** Commercial License Usage + ** Licensees holding valid commercial Qt licenses may use this file in + ** accordance with the commercial license agreement provided with the + ** Software or, alternatively, in accordance with the terms contained in + ** a written agreement between you and The Qt Company. For licensing terms + ** and conditions see https://www.qt.io/terms-conditions. For further + ** information use the contact form at https://www.qt.io/contact-us. + ** + ** GNU General Public License Usage + ** Alternatively, this file may be used under the terms of the GNU + ** General Public License version 3 as published by the Free Software + ** Foundation with exceptions as appearing in the file LICENSE.GPL3-EXCEPT + ** included in the packaging of this file. Please review the following + ** information to ensure the GNU General Public License requirements will + ** be met: https://www.gnu.org/licenses/gpl-3.0.html. + ** + ** $QT_END_LICENSE$ + ** + ****************************************************************************/ + +#include <QCommandLineParser> +#include <QDebug> +#include <QFile> +#include <QGuiApplication> +#include <QTextDocument> + +int main(int argc, char **argv) +{ + QGuiApplication app(argc, argv); + QGuiApplication::setApplicationVersion(QT_VERSION_STR); + QCommandLineParser parser; + parser.setApplicationDescription("Converts the Qt-supported subset of HTML to Markdown."); + parser.addHelpOption(); + parser.addVersionOption(); + parser.addPositionalArgument(QGuiApplication::translate("main", "input"), + QGuiApplication::translate("main", "input file")); + parser.addPositionalArgument(QGuiApplication::translate("main", "output"), + QGuiApplication::translate("main", "output file")); + parser.process(app); + if (parser.positionalArguments().count() != 2) + parser.showHelp(1); + + QFile inFile(parser.positionalArguments().first()); + if (!inFile.open(QIODevice::ReadOnly)) { + qFatal("failed to open %s for reading", parser.positionalArguments().first().toLocal8Bit().data()); + exit(2); + } + QFile outFile(parser.positionalArguments().at(1)); + if (!outFile.open(QIODevice::WriteOnly)) { + qFatal("failed to open %s for writing", parser.positionalArguments().at(1).toLocal8Bit().data()); + exit(2); + } + QTextDocument doc; + doc.setHtml(QString::fromUtf8(inFile.readAll())); + outFile.write(doc.toMarkdown().toUtf8()); +} diff --git a/tests/manual/markdown/html2md.pro b/tests/manual/markdown/html2md.pro new file mode 100644 index 0000000000..4d6254e5a0 --- /dev/null +++ b/tests/manual/markdown/html2md.pro @@ -0,0 +1,6 @@ +TEMPLATE = app +TARGET = html2md +INCLUDEPATH += . +#QT += gui-private +SOURCES += html2md.cpp + diff --git a/tests/manual/shortcuts/main.cpp b/tests/manual/shortcuts/main.cpp index acc2a2525c..289e8526f0 100644 --- a/tests/manual/shortcuts/main.cpp +++ b/tests/manual/shortcuts/main.cpp @@ -108,6 +108,7 @@ void ShortcutTester::setupLayout() Qt::ControlModifier + Qt::Key_5, Qt::AltModifier + Qt::Key_5, Qt::ControlModifier + Qt::Key_Plus, Qt::ControlModifier + Qt::ShiftModifier + Qt::Key_Plus, + Qt::ControlModifier + Qt::ShiftModifier + Qt::Key_Equal, Qt::ControlModifier + Qt::Key_Y, Qt::ShiftModifier + Qt::Key_Comma, Qt::ControlModifier + Qt::Key_Comma, Qt::ControlModifier + Qt::Key_Slash, Qt::ControlModifier + Qt::Key_Backslash @@ -121,6 +122,8 @@ void ShortcutTester::setupLayout() const int keys3[] = { Qt::MetaModifier + Qt::ShiftModifier + Qt::Key_A, + Qt::MetaModifier + Qt::Key_A, + Qt::MetaModifier + Qt::Key_Q, Qt::MetaModifier + Qt::ShiftModifier + Qt::Key_5, Qt::ControlModifier + Qt::Key_BracketRight, Qt::ShiftModifier + Qt::Key_F3, diff --git a/tests/shared/filesystem.h b/tests/shared/filesystem.h index 9f4527a992..0e7e6ba867 100644 --- a/tests/shared/filesystem.h +++ b/tests/shared/filesystem.h @@ -79,7 +79,7 @@ public: return file.isNull() ? qint64(-1) : file->write(relativeFileName.toUtf8()); } -#if defined(Q_OS_WIN) && !defined(Q_OS_WINCE) && !defined(Q_OS_WINRT) +#if defined(Q_OS_WIN) && !defined(Q_OS_WINRT) static DWORD createNtfsJunction(QString target, QString linkName, QString *errorMessage) { typedef struct { diff --git a/tests/testserver/common/startup.sh b/tests/testserver/common/startup.sh index 74990a47f6..1386314e38 100755 --- a/tests/testserver/common/startup.sh +++ b/tests/testserver/common/startup.sh @@ -34,7 +34,7 @@ set -ex # export variables export USER=qt-test-server export PASS=password -export CONFIG=common/testdata +export CONFIG=service/testdata export TESTDATA=service/testdata # add users @@ -43,17 +43,4 @@ useradd -m -s /bin/bash $USER; echo "$USER:$PASS" | chpasswd # install configurations and test data su $USER -c "cp $CONFIG/system/passwords ~/" -# modules initialization (apache2.sh, ftp-proxy.sh ...) -for RUN_CMD -do $RUN_CMD -done - -# start multicast DNS service discovery (mDNS) -sed -i -e "s,#domain-name=local,domain-name=${test_domain:-test-net.qt.local}," \ - -e "s,#publish-aaaa-on-ipv4=yes,publish-aaaa-on-ipv4=no," \ - /etc/avahi/avahi-daemon.conf -service dbus restart -service avahi-daemon restart - -# keep-alive in docker detach mode -sleep infinity +./startup.sh "$@" diff --git a/tests/testserver/docker-compose-for-macOS.yml b/tests/testserver/docker-compose-for-macOS.yml index aa610dfb88..c5348e27b6 100644 --- a/tests/testserver/docker-compose-for-macOS.yml +++ b/tests/testserver/docker-compose-for-macOS.yml @@ -12,82 +12,95 @@ version: '3.4' services: apache2: - image: qt-test-server-apache2:537fe302f61851d1663f41495230d8e3554a4a13 container_name: qt-test-server-apache2 domainname: ${TEST_DOMAIN} - volumes: - - ./common:/common:ro - - ./apache2:/service:ro - entrypoint: common/startup.sh - command: [common/ssl.sh, service/apache2.sh] + build: + context: . + dockerfile: ${SHARED_DATA}/Dockerfile + args: + provisioningImage: qt-test-server-apache2:537fe302f61851d1663f41495230d8e3554a4a13 + shareDir: ./common + serviceDir: ./apache2 + test_domain: ${TEST_DOMAIN} + entrypoint: service/startup.sh + command: [service/ssl.sh, service/apache2.sh] network_mode: "host" extra_hosts: - "qt-test-server.${TEST_DOMAIN}:${MACHINE_IP}" environment: - - test_domain=${TEST_DOMAIN} - test_cert="qt-test-server-host-network-cacert.pem" squid: - image: qt-test-server-squid:9c32f41b19aca3d778733c4d8fb0ecc5955e893c container_name: qt-test-server-squid domainname: ${TEST_DOMAIN} depends_on: - apache2 - volumes: - - ./common:/common:ro - - ./squid:/service:ro - entrypoint: common/startup.sh + build: + context: . + dockerfile: ${SHARED_DATA}/Dockerfile + args: + provisioningImage: qt-test-server-squid:9c32f41b19aca3d778733c4d8fb0ecc5955e893c + shareDir: ./common + serviceDir: ./squid + test_domain: ${TEST_DOMAIN} + entrypoint: service/startup.sh command: service/squid.sh network_mode: "host" extra_hosts: - "qt-test-server.${TEST_DOMAIN}:${MACHINE_IP}" - environment: - - test_domain=${TEST_DOMAIN} vsftpd: - image: qt-test-server-vsftpd:f3a9c8d793a77cc007c0e4e481bec01f9e3eeb7e container_name: qt-test-server-vsftpd domainname: ${TEST_DOMAIN} - volumes: - - ./common:/common:ro - - ./vsftpd:/service:ro - entrypoint: common/startup.sh + build: + context: . + dockerfile: ${SHARED_DATA}/Dockerfile + args: + provisioningImage: qt-test-server-vsftpd:f3a9c8d793a77cc007c0e4e481bec01f9e3eeb7e + shareDir: ./common + serviceDir: ./vsftpd + test_domain: ${TEST_DOMAIN} + entrypoint: service/startup.sh command: service/vsftpd.sh network_mode: "host" extra_hosts: - "qt-test-server.${TEST_DOMAIN}:${MACHINE_IP}" - environment: - - test_domain=${TEST_DOMAIN} ftp-proxy: - image: qt-test-server-ftp-proxy:d7de8b28392d173db512a558ccc84ead8bece2ae container_name: qt-test-server-ftp-proxy domainname: ${TEST_DOMAIN} depends_on: - vsftpd - volumes: - - ./common:/common:ro - - ./ftp-proxy:/service:ro - entrypoint: common/startup.sh + build: + context: . + dockerfile: ${SHARED_DATA}/Dockerfile + args: + provisioningImage: qt-test-server-ftp-proxy:d7de8b28392d173db512a558ccc84ead8bece2ae + shareDir: ./common + serviceDir: ./ftp-proxy + test_domain: ${TEST_DOMAIN} + entrypoint: service/startup.sh command: service/ftp-proxy.sh network_mode: "host" extra_hosts: - "qt-test-server.${TEST_DOMAIN}:${MACHINE_IP}" - environment: - - test_domain=${TEST_DOMAIN} danted: - image: qt-test-server-danted:35607f9b790524cf9690c7d12a9a401696b7b6b5 container_name: qt-test-server-danted domainname: ${TEST_DOMAIN} depends_on: - apache2 - vsftpd - ftp-proxy - volumes: - - ./common:/common:ro - - ./danted:/service:ro - entrypoint: common/startup.sh + build: + context: . + dockerfile: ${SHARED_DATA}/Dockerfile + args: + provisioningImage: qt-test-server-danted:35607f9b790524cf9690c7d12a9a401696b7b6b5 + shareDir: ./common + serviceDir: ./danted + test_domain: ${TEST_DOMAIN} + entrypoint: service/startup.sh command: service/danted.sh network_mode: "host" extra_hosts: @@ -97,4 +110,4 @@ services: - danted_external=${MACHINE_IP} - danted_auth_internal=${MACHINE_IP} - danted_auth_external=${MACHINE_IP} - - test_domain=${TEST_DOMAIN} + diff --git a/tests/testserver/docker-compose-for-windows.yml b/tests/testserver/docker-compose-for-windows.yml index aa610dfb88..c5348e27b6 100644 --- a/tests/testserver/docker-compose-for-windows.yml +++ b/tests/testserver/docker-compose-for-windows.yml @@ -12,82 +12,95 @@ version: '3.4' services: apache2: - image: qt-test-server-apache2:537fe302f61851d1663f41495230d8e3554a4a13 container_name: qt-test-server-apache2 domainname: ${TEST_DOMAIN} - volumes: - - ./common:/common:ro - - ./apache2:/service:ro - entrypoint: common/startup.sh - command: [common/ssl.sh, service/apache2.sh] + build: + context: . + dockerfile: ${SHARED_DATA}/Dockerfile + args: + provisioningImage: qt-test-server-apache2:537fe302f61851d1663f41495230d8e3554a4a13 + shareDir: ./common + serviceDir: ./apache2 + test_domain: ${TEST_DOMAIN} + entrypoint: service/startup.sh + command: [service/ssl.sh, service/apache2.sh] network_mode: "host" extra_hosts: - "qt-test-server.${TEST_DOMAIN}:${MACHINE_IP}" environment: - - test_domain=${TEST_DOMAIN} - test_cert="qt-test-server-host-network-cacert.pem" squid: - image: qt-test-server-squid:9c32f41b19aca3d778733c4d8fb0ecc5955e893c container_name: qt-test-server-squid domainname: ${TEST_DOMAIN} depends_on: - apache2 - volumes: - - ./common:/common:ro - - ./squid:/service:ro - entrypoint: common/startup.sh + build: + context: . + dockerfile: ${SHARED_DATA}/Dockerfile + args: + provisioningImage: qt-test-server-squid:9c32f41b19aca3d778733c4d8fb0ecc5955e893c + shareDir: ./common + serviceDir: ./squid + test_domain: ${TEST_DOMAIN} + entrypoint: service/startup.sh command: service/squid.sh network_mode: "host" extra_hosts: - "qt-test-server.${TEST_DOMAIN}:${MACHINE_IP}" - environment: - - test_domain=${TEST_DOMAIN} vsftpd: - image: qt-test-server-vsftpd:f3a9c8d793a77cc007c0e4e481bec01f9e3eeb7e container_name: qt-test-server-vsftpd domainname: ${TEST_DOMAIN} - volumes: - - ./common:/common:ro - - ./vsftpd:/service:ro - entrypoint: common/startup.sh + build: + context: . + dockerfile: ${SHARED_DATA}/Dockerfile + args: + provisioningImage: qt-test-server-vsftpd:f3a9c8d793a77cc007c0e4e481bec01f9e3eeb7e + shareDir: ./common + serviceDir: ./vsftpd + test_domain: ${TEST_DOMAIN} + entrypoint: service/startup.sh command: service/vsftpd.sh network_mode: "host" extra_hosts: - "qt-test-server.${TEST_DOMAIN}:${MACHINE_IP}" - environment: - - test_domain=${TEST_DOMAIN} ftp-proxy: - image: qt-test-server-ftp-proxy:d7de8b28392d173db512a558ccc84ead8bece2ae container_name: qt-test-server-ftp-proxy domainname: ${TEST_DOMAIN} depends_on: - vsftpd - volumes: - - ./common:/common:ro - - ./ftp-proxy:/service:ro - entrypoint: common/startup.sh + build: + context: . + dockerfile: ${SHARED_DATA}/Dockerfile + args: + provisioningImage: qt-test-server-ftp-proxy:d7de8b28392d173db512a558ccc84ead8bece2ae + shareDir: ./common + serviceDir: ./ftp-proxy + test_domain: ${TEST_DOMAIN} + entrypoint: service/startup.sh command: service/ftp-proxy.sh network_mode: "host" extra_hosts: - "qt-test-server.${TEST_DOMAIN}:${MACHINE_IP}" - environment: - - test_domain=${TEST_DOMAIN} danted: - image: qt-test-server-danted:35607f9b790524cf9690c7d12a9a401696b7b6b5 container_name: qt-test-server-danted domainname: ${TEST_DOMAIN} depends_on: - apache2 - vsftpd - ftp-proxy - volumes: - - ./common:/common:ro - - ./danted:/service:ro - entrypoint: common/startup.sh + build: + context: . + dockerfile: ${SHARED_DATA}/Dockerfile + args: + provisioningImage: qt-test-server-danted:35607f9b790524cf9690c7d12a9a401696b7b6b5 + shareDir: ./common + serviceDir: ./danted + test_domain: ${TEST_DOMAIN} + entrypoint: service/startup.sh command: service/danted.sh network_mode: "host" extra_hosts: @@ -97,4 +110,4 @@ services: - danted_external=${MACHINE_IP} - danted_auth_internal=${MACHINE_IP} - danted_auth_external=${MACHINE_IP} - - test_domain=${TEST_DOMAIN} + diff --git a/tests/testserver/docker-compose.yml b/tests/testserver/docker-compose.yml index 962daad3c9..75e8a0fea2 100644 --- a/tests/testserver/docker-compose.yml +++ b/tests/testserver/docker-compose.yml @@ -12,18 +12,21 @@ version: '3.4' services: apache2: - image: qt-test-server-apache2:537fe302f61851d1663f41495230d8e3554a4a13 container_name: qt-test-server-apache2 domainname: ${TEST_DOMAIN} hostname: apache2 - volumes: - - ./common:/common:ro - - ./apache2:/service:ro - entrypoint: common/startup.sh - command: [common/ssl.sh, service/apache2.sh] + build: + context: . + dockerfile: ${SHARED_DATA}/Dockerfile + args: + provisioningImage: qt-test-server-apache2:537fe302f61851d1663f41495230d8e3554a4a13 + shareDir: ./common + serviceDir: ./apache2 + test_domain: ${TEST_DOMAIN} + entrypoint: service/startup.sh + command: [service/ssl.sh, service/apache2.sh] squid: - image: qt-test-server-squid:9c32f41b19aca3d778733c4d8fb0ecc5955e893c container_name: qt-test-server-squid domainname: ${TEST_DOMAIN} hostname: squid @@ -35,25 +38,33 @@ services: - iptables:iptables.${TEST_DOMAIN} - vsftpd:vsftpd.${TEST_DOMAIN} - echo:echo.${TEST_DOMAIN} - volumes: - - ./common:/common:ro - - ./squid:/service:ro - entrypoint: common/startup.sh + build: + context: . + dockerfile: ${SHARED_DATA}/Dockerfile + args: + provisioningImage: qt-test-server-squid:9c32f41b19aca3d778733c4d8fb0ecc5955e893c + shareDir: ./common + serviceDir: ./squid + test_domain: ${TEST_DOMAIN} + entrypoint: service/startup.sh command: service/squid.sh vsftpd: - image: qt-test-server-vsftpd:f3a9c8d793a77cc007c0e4e481bec01f9e3eeb7e container_name: qt-test-server-vsftpd domainname: ${TEST_DOMAIN} hostname: vsftpd - volumes: - - ./common:/common:ro - - ./vsftpd:/service:ro - entrypoint: common/startup.sh + build: + context: . + dockerfile: ${SHARED_DATA}/Dockerfile + args: + provisioningImage: qt-test-server-vsftpd:f3a9c8d793a77cc007c0e4e481bec01f9e3eeb7e + shareDir: ./common + serviceDir: ./vsftpd + test_domain: ${TEST_DOMAIN} + entrypoint: service/startup.sh command: service/vsftpd.sh ftp-proxy: - image: qt-test-server-ftp-proxy:d7de8b28392d173db512a558ccc84ead8bece2ae container_name: qt-test-server-ftp-proxy domainname: ${TEST_DOMAIN} hostname: ftp-proxy @@ -61,14 +72,18 @@ services: - vsftpd external_links: - vsftpd:vsftpd.${TEST_DOMAIN} - volumes: - - ./common:/common:ro - - ./ftp-proxy:/service:ro - entrypoint: common/startup.sh + build: + context: . + dockerfile: ${SHARED_DATA}/Dockerfile + args: + provisioningImage: qt-test-server-ftp-proxy:d7de8b28392d173db512a558ccc84ead8bece2ae + shareDir: ./common + serviceDir: ./ftp-proxy + test_domain: ${TEST_DOMAIN} + entrypoint: service/startup.sh command: service/ftp-proxy.sh danted: - image: qt-test-server-danted:35607f9b790524cf9690c7d12a9a401696b7b6b5 container_name: qt-test-server-danted domainname: ${TEST_DOMAIN} hostname: danted @@ -82,44 +97,61 @@ services: - ftp-proxy:ftp-proxy.${TEST_DOMAIN} - cyrus:cyrus.${TEST_DOMAIN} - echo:echo.${TEST_DOMAIN} - volumes: - - ./common:/common:ro - - ./danted:/service:ro - entrypoint: common/startup.sh + build: + context: . + dockerfile: ${SHARED_DATA}/Dockerfile + args: + provisioningImage: qt-test-server-danted:35607f9b790524cf9690c7d12a9a401696b7b6b5 + shareDir: ./common + serviceDir: ./danted + test_domain: ${TEST_DOMAIN} + entrypoint: service/startup.sh command: service/danted.sh cyrus: - image: qt-test-server-cyrus:c8d72754abc0e501afd624ce838e4df35505abc9 container_name: qt-test-server-cyrus domainname: ${TEST_DOMAIN} hostname: cyrus - volumes: - - ./common:/common:ro - - ./cyrus:/service:ro - entrypoint: common/startup.sh - command: [common/ssl.sh, service/cyrus.sh] + build: + context: . + dockerfile: ${SHARED_DATA}/Dockerfile + args: + provisioningImage: qt-test-server-cyrus:c8d72754abc0e501afd624ce838e4df35505abc9 + shareDir: ./common + serviceDir: ./cyrus + test_domain: ${TEST_DOMAIN} + entrypoint: service/startup.sh + command: [service/ssl.sh, service/cyrus.sh] iptables: - image: qt-test-server-iptables:cb7a8bd6d28602085a88c8ced7d67e28e75781e2 container_name: qt-test-server-iptables domainname: ${TEST_DOMAIN} hostname: iptables - volumes: - - ./common:/common:ro - - ./iptables:/service:ro - entrypoint: common/startup.sh + build: + context: . + dockerfile: ${SHARED_DATA}/Dockerfile + args: + provisioningImage: qt-test-server-iptables:cb7a8bd6d28602085a88c8ced7d67e28e75781e2 + shareDir: ./common + serviceDir: ./iptables + test_domain: ${TEST_DOMAIN} + entrypoint: service/startup.sh command: service/iptables.sh cap_add: - NET_ADMIN - NET_RAW echo: - image: qt-test-server-echo:b29ad409e746a834c1055fd0f7a55fd5056da6ea - container_name: qt-test-server-echo - domainname: ${TEST_DOMAIN} - hostname: echo - volumes: - - ./common:/common:ro - - ./echo:/service:ro - entrypoint: common/startup.sh - command: service/echo.sh + container_name: qt-test-server-echo + domainname: ${TEST_DOMAIN} + hostname: echo + build: + context: . + dockerfile: ${SHARED_DATA}/Dockerfile + args: + provisioningImage: qt-test-server-echo:b29ad409e746a834c1055fd0f7a55fd5056da6ea + shareDir: ./common + serviceDir: ./echo + test_domain: ${TEST_DOMAIN} + entrypoint: service/startup.sh + command: service/echo.sh diff --git a/tests/testserver/ftp-proxy/ftp-proxy.sh b/tests/testserver/ftp-proxy/ftp-proxy.sh index 087a7b7bcc..e5b9631bbb 100755 --- a/tests/testserver/ftp-proxy/ftp-proxy.sh +++ b/tests/testserver/ftp-proxy/ftp-proxy.sh @@ -34,7 +34,9 @@ set -ex # package ftp-proxy # install configurations and test data -sed -i 's/# AllowMagicUser\tno/AllowMagicUser\tyes/' /etc/proxy-suite/ftp-proxy.conf +sed -i -e 's/# AllowMagicUser\tno/AllowMagicUser\tyes/' \ + -e 's/# ForkLimit\t\t40/ForkLimit\t\t2000/' \ + /etc/proxy-suite/ftp-proxy.conf # enable service with installed configurations ftp-proxy -d diff --git a/tests/testserver/vsftpd/testdata/vsftpd.conf b/tests/testserver/vsftpd/testdata/vsftpd.conf index 6bdb186c9f..e67cccefcc 100644 --- a/tests/testserver/vsftpd/testdata/vsftpd.conf +++ b/tests/testserver/vsftpd/testdata/vsftpd.conf @@ -101,6 +101,10 @@ userlist_enable=YES listen=YES tcp_wrappers=YES +# An internal setting used for testing the relative benefit of using the +# sendfile() system call on your platform. +use_sendfile=NO + # Enabling SFTP #ssl_enable=YES #allow_anon_ssl=YES diff --git a/tests/testserver/vsftpd/vsftpd.sh b/tests/testserver/vsftpd/vsftpd.sh index 14364f94c2..bd09ad3902 100755 --- a/tests/testserver/vsftpd/vsftpd.sh +++ b/tests/testserver/vsftpd/vsftpd.sh @@ -54,6 +54,10 @@ ln -s /home/$USER/ftp /var/ftp su $USER -c "mkdir -p ~/ftp/qtest/" su $USER -c "cp rfc3252.txt ~/ftp/qtest/"; rm rfc3252.txt +# tst_QNetworkReply::proxy_data() +su $USER -c "ln ~/ftp/qtest/rfc3252.txt ~/ftp/qtest/rfc3252" +su $USER -c "mkdir -p ~/ftp/qtest/nonASCII/" + # Duplicate rfc3252.txt 20 times for bigfile tests: su $USER -c "seq 20 | xargs -i cat ~/ftp/qtest/rfc3252.txt >> ~/ftp/qtest/bigfile" |