From 2b7edd053404f4819abf0203bb9c762799849638 Mon Sep 17 00:00:00 2001 From: Jan Arve Saether Date: Fri, 3 May 2019 15:47:57 +0200 Subject: Fix bug with QLayout::replaceWidget(a, a) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit It should effectively leave the layout untouched Fixes: QTBUG-69706 Change-Id: I4d8232895bf1d1ae0d1b73156ef6ec6001d8968a Reviewed-by: Thorbjørn Lund Martsum --- tests/auto/widgets/kernel/qboxlayout/tst_qboxlayout.cpp | 4 ++++ 1 file changed, 4 insertions(+) (limited to 'tests') 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); -- cgit v1.2.3 From 681bd76e671939b6717f1a35ec9b8383f48fb294 Mon Sep 17 00:00:00 2001 From: Anton Kudryavtsev Date: Mon, 25 Mar 2019 14:42:19 +0300 Subject: QStringView, QLatin1String: add indexOf methods [ChangeLog][QtCore][QLatin1String] Added indexOf(). [ChangeLog][QtCore][QStringView] Added indexOf(). Change-Id: I9f56e5b40030e39b29e50914a46beb58013b537b Reviewed-by: Edward Welbourne Reviewed-by: Thiago Macieira --- .../qstringapisymmetry/tst_qstringapisymmetry.cpp | 145 +++++++++++++++++++++ 1 file changed, 145 insertions(+) (limited to 'tests') diff --git a/tests/auto/corelib/tools/qstringapisymmetry/tst_qstringapisymmetry.cpp b/tests/auto/corelib/tools/qstringapisymmetry/tst_qstringapisymmetry.cpp index cb1fd9eb7d..b52c15fd73 100644 --- a/tests/auto/corelib/tools/qstringapisymmetry/tst_qstringapisymmetry.cpp +++ b/tests/auto/corelib/tools/qstringapisymmetry/tst_qstringapisymmetry.cpp @@ -416,6 +416,47 @@ private Q_SLOTS: void toUcs4_QStringRef() { toUcs4_impl(); } void toUcs4_QStringView_data() { toUcs4_data(); } void toUcs4_QStringView() { toUcs4_impl(); } + +private: + template void indexOf_impl() const; + void indexOf_data(); + +private Q_SLOTS: + void indexOf_QString_QString_data() { indexOf_data(); } + void indexOf_QString_QString() { indexOf_impl(); } + void indexOf_QString_QLatin1String_data() { indexOf_data(); } + void indexOf_QString_QLatin1String() { indexOf_impl(); } + void indexOf_QString_QStringRef_data() { indexOf_data(); } + void indexOf_QString_QStringRef() { indexOf_impl(); } + void indexOf_QString_QStringView_data() { indexOf_data(); } + void indexOf_QString_QStringView() { indexOf_impl(); } + + void indexOf_QLatin1String_QString_data() { indexOf_data(); } + void indexOf_QLatin1String_QString() { indexOf_impl(); } + void indexOf_QLatin1String_QLatin1String_data() { indexOf_data(); } + void indexOf_QLatin1String_QLatin1String() { indexOf_impl(); } + void indexOf_QLatin1String_QStringRef_data() { indexOf_data(); } + void indexOf_QLatin1String_QStringRef() { indexOf_impl(); } + void indexOf_QLatin1String_QStringView_data() { indexOf_data(); } + void indexOf_QLatin1String_QStringView() { indexOf_impl(); } + + void indexOf_QStringRef_QString_data() { indexOf_data(); } + void indexOf_QStringRef_QString() { indexOf_impl(); } + void indexOf_QStringRef_QLatin1String_data() { indexOf_data(); } + void indexOf_QStringRef_QLatin1String() { indexOf_impl(); } + void indexOf_QStringRef_QStringRef_data() { indexOf_data(); } + void indexOf_QStringRef_QStringRef() { indexOf_impl(); } + void indexOf_QStringRef_QStringView_data() { indexOf_data(); } + void indexOf_QStringRef_QStringView() { indexOf_impl(); } + + void indexOf_QStringView_QString_data() { indexOf_data(); } + void indexOf_QStringView_QString() { indexOf_impl(); } + void indexOf_QStringView_QLatin1String_data() { indexOf_data(); } + void indexOf_QStringView_QLatin1String() { indexOf_impl(); } + void indexOf_QStringView_QStringRef_data() { indexOf_data(); } + void indexOf_QStringView_QStringRef() { indexOf_impl(); } + void indexOf_QStringView_QStringView_data() { indexOf_data(); } + void indexOf_QStringView_QStringView() { indexOf_impl(); } }; void tst_QStringApiSymmetry::compare_data(bool hasConceptOfNullAndEmpty) @@ -540,6 +581,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"); @@ -1216,6 +1258,109 @@ void tst_QStringApiSymmetry::toUcs4_impl() QCOMPARE(unicode.isEmpty(), ucs4.isEmpty()); } +void tst_QStringApiSymmetry::indexOf_data() +{ + QTest::addColumn("haystackU16"); + QTest::addColumn("haystackL1"); + QTest::addColumn("needleU16"); + QTest::addColumn("needleL1"); + QTest::addColumn("startpos"); + QTest::addColumn("resultCS"); + QTest::addColumn("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 +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(QStringRef(&haystackU16), haystackL1, haystackU8); + const auto needle = make(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" -- cgit v1.2.3 From 1503265eb1bb5f96a4dd5014f08c32794bd1ce39 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?M=C3=A5rten=20Nordheim?= Date: Thu, 9 May 2019 15:52:16 +0200 Subject: Granularize blacklist of platformsocketengine for Windows Using the information from grafana we can unblacklist all the things which are consistently passing. Change-Id: If04963cd5f9a53ee2293d596f9111ebcb1add532 Reviewed-by: Timur Pocheptsov --- tests/auto/network/socket/platformsocketengine/BLACKLIST | 7 +++++++ 1 file changed, 7 insertions(+) (limited to 'tests') 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 -- cgit v1.2.3 From fa6859c119eab84d9d7de149eeb6b631f36f3d27 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?M=C3=A5rten=20Nordheim?= Date: Thu, 9 May 2019 15:53:16 +0200 Subject: Granularize blacklist of qhttpsocketengine for Windows Using the information from grafana we can unblacklist all the things which are consistently passing. Change-Id: I3676d9cb5f9167039c3d1963521fa85785210f7c Reviewed-by: Timur Pocheptsov --- tests/auto/network/socket/qhttpsocketengine/BLACKLIST | 5 +++++ 1 file changed, 5 insertions(+) (limited to 'tests') 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 -- cgit v1.2.3 From b29cc512f8062d69d573fd95907b3d05298a8c23 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?M=C3=A5rten=20Nordheim?= Date: Thu, 9 May 2019 15:54:43 +0200 Subject: Granularize blacklist of qsslsocket for Windows Using the information from grafana we can unblacklist all the things which are consistently passing. Change-Id: I79917ca9c40e1df2dab46bb54cc0a2bd4a1a4621 Reviewed-by: Timur Pocheptsov --- tests/auto/network/ssl/qsslsocket/BLACKLIST | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) (limited to 'tests') 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 -- cgit v1.2.3 From ab2655c559f42e382c13e21a3bea65fb21af95eb Mon Sep 17 00:00:00 2001 From: Edward Welbourne Date: Fri, 3 May 2019 16:24:51 +0200 Subject: Support POSIX rules as $TZ values The TZ environment variable can validly contain a POSIX rule, rather than an IANA ID, as described here: http://pubs.opengroup.org/onlinepubs/9699919799/basedefs/V1_chap08.html#tag_08_03 However, if TZ were set to such a value, leading to it being used as systemTimeZoneId(), it would be passed to QTzTimeZonePrivate::init(), which is a no-op unless it manages to open a zoneinfo/ file with the given ianaId as name. When the environment variable doesn't name a zoneinfo/ file, we would thus get an invalid time-zone. We can, instead, check whether the ianaId looks like a valid POSIX rule and, if it does, use it as m_posixRule, enabling us to correctly handle this case. Tweak parsing of POSIX rules so that a zone using name "UTC" or "GMT" with an offset other than 0 will be rejected as invalid. This avoids parsing a zone name such as "GMT+17" or "UTC+00:01" as a POSIX rule, where it should be understood as an offset from UTC (and only certain well-established offsets are supported). Added two test-cases to tst_QTimeZone::tzTest() for validity of a POSIX zone value - a simple one constructed during discussion of the bug, the other taken from an example in: http://leaf.sourceforge.net/doc/buci-tz3.html Task-number: QTBUG-75565 Change-Id: Ia5cb1cc56b13b0f6b56258e48be98d04d909e32a Reviewed-by: Thiago Macieira --- tests/auto/corelib/tools/qtimezone/tst_qtimezone.cpp | 8 ++++++++ 1 file changed, 8 insertions(+) (limited to 'tests') 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 -- cgit v1.2.3 From ac4cf6e2b2dfc6ee37b0c64e1dd201e2b2452c31 Mon Sep 17 00:00:00 2001 From: Frederik Gladhorn Date: Tue, 20 Nov 2018 15:49:56 +0100 Subject: Handle missing enum value in test MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Change-Id: I39ad53686b45a79105ccfd9938d79518e26dd5d5 Reviewed-by: Morten Johan Sørvig --- tests/auto/other/qaccessibility/tst_qaccessibility.cpp | 1 + 1 file changed, 1 insertion(+) (limited to 'tests') diff --git a/tests/auto/other/qaccessibility/tst_qaccessibility.cpp b/tests/auto/other/qaccessibility/tst_qaccessibility.cpp index bc45487599..7d7fa6403b 100644 --- a/tests/auto/other/qaccessibility/tst_qaccessibility.cpp +++ b/tests/auto/other/qaccessibility/tst_qaccessibility.cpp @@ -2580,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"); -- cgit v1.2.3 From ac83032c60094c500ecc879dd9eb9a5eb9ac876d Mon Sep 17 00:00:00 2001 From: Marc Mutz Date: Thu, 2 May 2019 19:34:48 +0200 Subject: tst_qrandomgenerator: replace QLinkedList with a std::list In preparation of deprecating QLinkedList. This actually simplifies the code, since std::list has a ctor from size, which QLinkedList lacks, and which the code worked around by using initializer_list. Change-Id: I07f9d590f863d9e4e00de73339cdfa27079f6e03 Reviewed-by: Thiago Macieira --- tests/auto/corelib/global/qrandomgenerator/tst_qrandomgenerator.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'tests') 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 list = { 0, 0, 0, 0, 0, 0, 0, 0 }; + std::list list(8); auto longerArrayCheck = [&] { QRandomGenerator().generate(list.begin(), list.end()); return find_if(list.begin(), list.end(), [&](quint64 cur) { -- cgit v1.2.3 From dfe497a14e9dcd5680c732504d6dd4f9e7dce28c Mon Sep 17 00:00:00 2001 From: Volker Hilsheimer Date: Tue, 4 Dec 2018 07:18:39 -0800 Subject: Migrate QFtp test to new test server Use docker test server to run test, following instructions on https://wiki.qt.io/Network_Testing. Verified on Ubunutu 18.04. Several test failures due to network timeouts and inconsistent configuration of FTP server and assumptions made in the tests. However, the test is either way blacklisted, and the docker test server is not in use yet. Done-with: Ryan Chu Fixes: QTQAINFRA-2275 Change-Id: I4cbd0109ce3f4cfb23ba2303a85796681d12febc Reviewed-by: Volker Hilsheimer Reviewed-by: Edward Welbourne --- tests/auto/network/access/qftp/qftp.pro | 3 + tests/auto/network/access/qftp/tst_qftp.cpp | 175 +++++++++++++++------------- 2 files changed, 94 insertions(+), 84 deletions(-) (limited to 'tests') 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..ec7bcd25e2 100644 --- a/tests/auto/network/access/qftp/tst_qftp.cpp +++ b/tests/auto/network/access/qftp/tst_qftp.cpp @@ -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::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("port"); QTest::addColumn("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; } @@ -402,13 +409,13 @@ void tst_QFtp::login_data() QTest::addColumn("password"); QTest::addColumn("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() @@ -448,12 +455,12 @@ void tst_QFtp::close_data() QTest::addColumn("password"); QTest::addColumn("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() @@ -503,17 +510,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. @@ -573,14 +580,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() @@ -635,19 +642,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); } } @@ -727,31 +734,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; */ @@ -877,22 +884,22 @@ void tst_QFtp::mkdir_data() QTest::addColumn("dirToCreate"); QTest::addColumn("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; } @@ -979,7 +986,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,39 +1033,39 @@ void tst_QFtp::rename_data() QTest::addColumn("renamedFile"); QTest::addColumn("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() @@ -1220,7 +1227,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(); @@ -1351,13 +1358,13 @@ void tst_QFtp::abort_data() QTest::addColumn("file"); QTest::addColumn("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() @@ -1402,7 +1409,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 { @@ -1449,11 +1456,11 @@ void tst_QFtp::bytesAvailable_data() QTest::addColumn("bytesAvailFinished"); QTest::addColumn("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() @@ -1498,7 +1505,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 +1541,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 +1560,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 ) ); @@ -1589,7 +1596,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 +1606,7 @@ void tst_QFtp::binaryAscii() delete ftp; ftp = 0; if ( QTestEventLoop::instance().timeout() ) - QFAIL( msgTimedOut(QtNetworkSettings::serverName()) ); + QFAIL( msgTimedOut(QtNetworkSettings::ftpServerName()) ); ResMapIt it = resultMap.find(QFtp::Put); QVERIFY(it != resultMap.end()); @@ -1611,7 +1618,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 +1628,7 @@ void tst_QFtp::binaryAscii() delete ftp; ftp = 0; if ( QTestEventLoop::instance().timeout() ) - QFAIL( msgTimedOut(QtNetworkSettings::serverName()) ); + QFAIL( msgTimedOut(QtNetworkSettings::ftpServerName()) ); ResMapIt it2 = resultMap.find(QFtp::Get); QVERIFY(it2 != resultMap.end()); @@ -1634,7 +1641,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 +1651,13 @@ void tst_QFtp::binaryAscii() delete ftp; ftp = 0; if ( QTestEventLoop::instance().timeout() ) - QFAIL( msgTimedOut(QtNetworkSettings::serverName()) ); + QFAIL( 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 +2074,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(); -- cgit v1.2.3 From a7ed7c1230a16d4451b860e0b5f434f28235b3e5 Mon Sep 17 00:00:00 2001 From: Ryan Chu Date: Tue, 12 Mar 2019 12:24:17 +0100 Subject: Rework QFtp test and resolve the unresolved items MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit The proxy_data() defined in tst_qftp.cpp expects five items (bigfile, nonASCII, rfc3252, rfc3252.txt, and upload) in the server folder (ftp/qtest). The file rfc3252 and nonASCII folder were missing. Change-Id: I995d6e254875ade22a1def53187077f1cc8d4c98 Reviewed-by: Volker Hilsheimer Reviewed-by: Timur Pocheptsov Reviewed-by: Mårten Nordheim Reviewed-by: Edward Welbourne --- tests/testserver/vsftpd/vsftpd.sh | 4 ++++ 1 file changed, 4 insertions(+) (limited to 'tests') 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" -- cgit v1.2.3 From 835d83b134c9cf2ff9553c5dbc65901ea3b33f05 Mon Sep 17 00:00:00 2001 From: Ryan Chu Date: Thu, 21 Mar 2019 14:37:45 +0100 Subject: Fix the timing issue of QFtp tests when using Docker servers Sometimes, it fails in tst_QFtp::proxy or tst_QFtp::activeMode under the stress test. It complains about "Network operation timed out" on vsftpd.test-net.qt.local. When this issue happens in tst_QFtp::proxy, it shows "USER-ERR reject: 172.18.0.5 (ForkLimit 40)" in the log of ftp-proxy. By default, the ftp-proxy only supports 40 incoming client connections per minute. To make the ftp-proxy more powerful, this change extends the limits from 40 to 2000. When this issue happens in tst_QFtp:activeMode, vsftpd shows 426 Failure writing network stream error. It is a known issue of vsftpd. A quick fix is turning use_sendfile off. Change-Id: Iad50469654041bf30f92ef00805034f0d4aa9c3f Reviewed-by: Edward Welbourne Reviewed-by: Timur Pocheptsov Reviewed-by: Qt CI Bot Reviewed-by: Volker Hilsheimer --- tests/testserver/ftp-proxy/ftp-proxy.sh | 4 +++- tests/testserver/vsftpd/testdata/vsftpd.conf | 4 ++++ 2 files changed, 7 insertions(+), 1 deletion(-) (limited to 'tests') 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 -- cgit v1.2.3 From 33d2715dd34d39a3250d7b66b785f421c7e07719 Mon Sep 17 00:00:00 2001 From: Ryan Chu Date: Thu, 2 May 2019 21:50:40 +0200 Subject: QFtp: Skip the flaky QTestEventLoop::timeout in Coin network When migrating QFtp test to docker server, it seems it is easy to get "QTestEventLoop::instance().timeout()" during the test in Coin network. To move the task of migration forward, those flaky timeout errors will be ignored for short-term. Task-number: QTBUG-75549 Change-Id: I797952b82c0ceb637f40c77fac2a88ca2a9a0eae Reviewed-by: Volker Hilsheimer Reviewed-by: Qt CI Bot --- tests/auto/network/access/qftp/tst_qftp.cpp | 80 +++++++++++++++++------------ 1 file changed, 48 insertions(+), 32 deletions(-) (limited to 'tests') diff --git a/tests/auto/network/access/qftp/tst_qftp.cpp b/tests/auto/network/access/qftp/tst_qftp.cpp index ec7bcd25e2..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 @@ -335,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() @@ -350,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" ); @@ -433,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() ); @@ -481,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 ); @@ -549,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() ); @@ -610,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 ); @@ -687,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() ); @@ -814,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() ); @@ -847,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" ); @@ -865,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() ); @@ -929,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() ); @@ -954,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() ); @@ -974,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() ); @@ -1072,8 +1076,9 @@ void tst_QFtp::rename_data() << 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(); @@ -1087,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() ); @@ -1095,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(); @@ -1112,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() ); @@ -1120,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() @@ -1142,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(); @@ -1157,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() ); @@ -1172,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"); } /* @@ -1346,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" ); } @@ -1401,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() ); @@ -1439,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() ); @@ -1477,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() ); @@ -1571,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 ); @@ -1606,7 +1622,7 @@ void tst_QFtp::binaryAscii() delete ftp; ftp = 0; if ( QTestEventLoop::instance().timeout() ) - QFAIL( msgTimedOut(QtNetworkSettings::ftpServerName()) ); + QSKIP( msgTimedOut(QtNetworkSettings::ftpServerName()) ); ResMapIt it = resultMap.find(QFtp::Put); QVERIFY(it != resultMap.end()); @@ -1628,7 +1644,7 @@ void tst_QFtp::binaryAscii() delete ftp; ftp = 0; if ( QTestEventLoop::instance().timeout() ) - QFAIL( msgTimedOut(QtNetworkSettings::ftpServerName()) ); + QSKIP( msgTimedOut(QtNetworkSettings::ftpServerName()) ); ResMapIt it2 = resultMap.find(QFtp::Get); QVERIFY(it2 != resultMap.end()); @@ -1651,7 +1667,7 @@ void tst_QFtp::binaryAscii() delete ftp; ftp = 0; if ( QTestEventLoop::instance().timeout() ) - QFAIL( msgTimedOut(QtNetworkSettings::ftpServerName()) ); + QSKIP( msgTimedOut(QtNetworkSettings::ftpServerName()) ); it = resultMap.find( QFtp::Remove ); QVERIFY( it != resultMap.end() ); @@ -2083,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); -- cgit v1.2.3 From 927eba344c2dbabc7275a4f561dd97f0e30760a2 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?M=C3=A5rten=20Nordheim?= Date: Thu, 25 Apr 2019 17:25:22 +0200 Subject: Introduce AutoDeleteReplyOnFinishAttribute for QNetworkRequest [ChangeLog][QtNetwork][QNetworkRequest] Added the AutoDeleteReplyOnFinishAttribute attribute to QNetworkRequest, which makes QNetworkAccessManager delete the QNetworkReply after it has emitted the "finished" signal. Change-Id: I03d4ac0830137882e51dd28795a8ec817762a300 Reviewed-by: Edward Welbourne Reviewed-by: Timur Pocheptsov --- .../access/qnetworkreply/tst_qnetworkreply.cpp | 74 ++++++++++++++++++++++ 1 file changed, 74 insertions(+) (limited to 'tests') diff --git a/tests/auto/network/access/qnetworkreply/tst_qnetworkreply.cpp b/tests/auto/network/access/qnetworkreply/tst_qnetworkreply.cpp index eb956bec30..5e3018366c 100644 --- a/tests/auto/network/access/qnetworkreply/tst_qnetworkreply.cpp +++ b/tests/auto/network/access/qnetworkreply/tst_qnetworkreply.cpp @@ -503,6 +503,9 @@ private Q_SLOTS: void putWithServerClosingConnectionImmediately(); #endif + void autoDeleteRepliesAttribute_data(); + void autoDeleteRepliesAttribute(); + // NOTE: This test must be last! void parentingRepliesToTheApp(); private: @@ -9167,6 +9170,77 @@ void tst_QNetworkReply::putWithServerClosingConnectionImmediately() #endif +void tst_QNetworkReply::autoDeleteRepliesAttribute_data() +{ + QTest::addColumn("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 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 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() { -- cgit v1.2.3 From cd816d4b6ac4358a92dbda906288ba6d969fc1cd Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?M=C3=A5rten=20Nordheim?= Date: Fri, 26 Apr 2019 12:56:23 +0200 Subject: Add setAutoDeleteReplies to QNetworkAccessManager Following the introduction of AutoDeleteReplyOnFinishAttribute to QNetworkRequest it seems natural to make it easy to enable for all replies created with the current QNetworkAccessManager. [ChangeLog][QtNetwork][QNetworkAccessManager] Added setAutoDeleteReplies to QNetworkAccessManager to enable the AutoDeleteReplyOnFinishAttribute attribute for all QNetworkRequests that are passed to QNetworkAccessManager. Change-Id: I7f96dd1fc9a899328e89732be17780b4e710c2a2 Reviewed-by: Edward Welbourne Reviewed-by: Markus Goetz (Woboq GmbH) Reviewed-by: Timur Pocheptsov --- .../access/qnetworkreply/tst_qnetworkreply.cpp | 91 ++++++++++++++++++++++ 1 file changed, 91 insertions(+) (limited to 'tests') diff --git a/tests/auto/network/access/qnetworkreply/tst_qnetworkreply.cpp b/tests/auto/network/access/qnetworkreply/tst_qnetworkreply.cpp index 5e3018366c..43739be4a3 100644 --- a/tests/auto/network/access/qnetworkreply/tst_qnetworkreply.cpp +++ b/tests/auto/network/access/qnetworkreply/tst_qnetworkreply.cpp @@ -505,6 +505,8 @@ private Q_SLOTS: void autoDeleteRepliesAttribute_data(); void autoDeleteRepliesAttribute(); + void autoDeleteReplies_data(); + void autoDeleteReplies(); // NOTE: This test must be last! void parentingRepliesToTheApp(); @@ -9241,6 +9243,95 @@ void tst_QNetworkReply::autoDeleteRepliesAttribute() } } +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 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 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 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 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() { -- cgit v1.2.3 From 77ad8dcfcce72a7cf9256b1522c5c1b57e956fa1 Mon Sep 17 00:00:00 2001 From: Frederik Gladhorn Date: Wed, 17 Oct 2018 10:24:13 +0200 Subject: Enable tst_QWidget_window::tst_resize_count on Ubuntu 18.04 This test passes, according to our metrics it kept on failing on 16.04 and on OpenSuse. This reverts commit d2015b4d06d89cb760d686876d639452f73d80fe. Change-Id: Ibe81f848238d9df651a74f9fd82ac636c2c249f1 Reviewed-by: Qt CI Bot Reviewed-by: Friedemann Kleint --- tests/auto/widgets/kernel/qwidget_window/BLACKLIST | 1 - 1 file changed, 1 deletion(-) (limited to 'tests') diff --git a/tests/auto/widgets/kernel/qwidget_window/BLACKLIST b/tests/auto/widgets/kernel/qwidget_window/BLACKLIST index 934f2e8025..381cf76c46 100644 --- a/tests/auto/widgets/kernel/qwidget_window/BLACKLIST +++ b/tests/auto/widgets/kernel/qwidget_window/BLACKLIST @@ -2,7 +2,6 @@ # QTBUG-66345 opensuse-42.3 ubuntu-16.04 -ubuntu-18.04 [setWindowState] ubuntu-18.04 rhel -- cgit v1.2.3 From 4f6eb43898aa14fef5f3a54966b340188271d85e Mon Sep 17 00:00:00 2001 From: Christian Ehrlicher Date: Sun, 12 May 2019 21:30:10 +0200 Subject: QtCore: mark obsolete enumerations as deprecated The following enumerations were obsolete for a log time but not marked as deprecated: - WA_NoBackground - WA_MacNoClickThrough - WA_MacBrushedMetal - WA_MacMetalStyle - WA_MSWindowsUseDirect3D - WA_MacFrameworkScaled - AA_MSWindowsUseDirect3DByDefault - AA_X11InitThreads - ImMicroFocus mark them as deprecated and remove the usage inside QtBase so they can be removed with Qt6 Change-Id: Ia087a7e1d0ff1945286895be6425a6cceaa483fb Reviewed-by: Friedemann Kleint Reviewed-by: Richard Moe Gustavsen --- .../qgraphicsview/tst_qgraphicsview.cpp | 2 +- .../widgets/widgets/qlineedit/tst_qlineedit.cpp | 2 +- .../widgets/qscrollarea/tst_qscrollarea.cpp | 4 +- .../GraphicsViewBenchmark/widgets/mainview.cpp | 1 - tests/manual/cocoa/noclickthrough/main.cpp | 48 ---------------------- .../manual/cocoa/noclickthrough/noclickthrough.pro | 4 -- 6 files changed, 4 insertions(+), 57 deletions(-) delete mode 100644 tests/manual/cocoa/noclickthrough/main.cpp delete mode 100644 tests/manual/cocoa/noclickthrough/noclickthrough.pro (limited to 'tests') 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/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/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/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 - -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 -- cgit v1.2.3 From 6afdbfdaafcc4d24e08357dfea96b85787efb1f7 Mon Sep 17 00:00:00 2001 From: Shawn Rutledge Date: Mon, 29 Apr 2019 22:45:14 +0200 Subject: Use "monospace" as fallback system FixedFont in KDE theme; logging Also de-duplicate the "monospace" string in qgenericunixthemes.cpp, and add tst_QFontDatabase::systemFixedFont() to verify that QFontDatabase::systemFont(QFontDatabase::FixedFont) really returns a monospace font across platforms. Replace commented-out qDebug()s with qt.text.font.match and qt.text.font.db logging categories to troubleshoot when the test fails (among other uses). Add qt.qpa.fonts logging category to unix themes to show default system and fixed fonts (font engines on other platforms are already using this category). Fixes: QTBUG-54623 Change-Id: I2aa62b8c783d9ddb591a5e06e8df85c4af5bcb0c Reviewed-by: Friedemann Kleint --- tests/auto/gui/text/qfontdatabase/BLACKLIST | 3 +++ tests/auto/gui/text/qfontdatabase/tst_qfontdatabase.cpp | 13 +++++++++++++ 2 files changed, 16 insertions(+) create mode 100644 tests/auto/gui/text/qfontdatabase/BLACKLIST (limited to 'tests') diff --git a/tests/auto/gui/text/qfontdatabase/BLACKLIST b/tests/auto/gui/text/qfontdatabase/BLACKLIST new file mode 100644 index 0000000000..7f479e4b0e --- /dev/null +++ b/tests/auto/gui/text/qfontdatabase/BLACKLIST @@ -0,0 +1,3 @@ +[systemFixedFont] # QTBUG-54623 +winrt +b2qt diff --git a/tests/auto/gui/text/qfontdatabase/tst_qfontdatabase.cpp b/tests/auto/gui/text/qfontdatabase/tst_qfontdatabase.cpp index 68664cdd2f..064e37f73c 100644 --- a/tests/auto/gui/text/qfontdatabase/tst_qfontdatabase.cpp +++ b/tests/auto/gui/text/qfontdatabase/tst_qfontdatabase.cpp @@ -35,6 +35,8 @@ #include #include +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() { -- cgit v1.2.3 From 43abe86e2f036bff9613ba4e10758213faa34ea9 Mon Sep 17 00:00:00 2001 From: Edward Welbourne Date: Thu, 2 May 2019 17:00:31 +0200 Subject: Update locale data to CLDR v35.1 The formatting of times in Norwegian has reverted to using dots in place of colons, as it did before v31 (commit 82deb0ad1), so reverted the tests to their state before that. Change-Id: I8a09ce253731bb0f0f3caca117f06ad568940a81 Reviewed-by: Thiago Macieira Reviewed-by: Lars Knoll --- tests/auto/corelib/tools/qlocale/tst_qlocale.cpp | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) (limited to 'tests') diff --git a/tests/auto/corelib/tools/qlocale/tst_qlocale.cpp b/tests/auto/corelib/tools/qlocale/tst_qlocale.cpp index 279ee2e8a0..230ae4d8aa 100644 --- a/tests/auto/corelib/tools/qlocale/tst_qlocale.cpp +++ b/tests/auto/corelib/tools/qlocale/tst_qlocale.cpp @@ -2458,9 +2458,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 +2482,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() -- cgit v1.2.3 From eba3b567d639ab40c939e27900029f93e351d77a Mon Sep 17 00:00:00 2001 From: Frederik Gladhorn Date: Mon, 6 May 2019 13:02:57 +0200 Subject: Accessibility: Improve handling of read-only state MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit We have been rather sloppy in how read-only versus editable is handled. According to the definition, editable signifies that in principle a widget allows the user to change its text. Read-only means that this ability is (currently) disabled. Task-number: QTBUG-75002 Change-Id: I5d71843abcdaac52f4a60a1abcac2604341f6c96 Reviewed-by: Jan Arve Sæther --- tests/auto/other/qaccessibility/tst_qaccessibility.cpp | 15 +++++++++++++++ .../other/qaccessibilitylinux/tst_qaccessibilitylinux.cpp | 8 ++++++++ 2 files changed, 23 insertions(+) (limited to 'tests') diff --git a/tests/auto/other/qaccessibility/tst_qaccessibility.cpp b/tests/auto/other/qaccessibility/tst_qaccessibility.cpp index 8b24937079..bc45487599 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")); @@ -3640,6 +3649,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 > rels = acc_label->relations(); QCOMPARE(rels.count(), 1); diff --git a/tests/auto/other/qaccessibilitylinux/tst_qaccessibilitylinux.cpp b/tests/auto/other/qaccessibilitylinux/tst_qaccessibilitylinux.cpp index 48594b2fa1..2b82b03998 100644 --- a/tests/auto/other/qaccessibilitylinux/tst_qaccessibilitylinux.cpp +++ b/tests/auto/other/qaccessibilitylinux/tst_qaccessibilitylinux.cpp @@ -251,6 +251,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 +305,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; -- cgit v1.2.3 From 490ee4c5e6d296d975980c8be65d9b6f661d2603 Mon Sep 17 00:00:00 2001 From: Frederik Gladhorn Date: Thu, 18 Oct 2018 15:25:14 +0200 Subject: Fix compilation of tst_qaccessibilitylinux MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Note that the test is still disabled, but this is needed in any case. Change-Id: Ib7523ba800b94c32690c1bd09b23fc2078c71d4e Reviewed-by: Jan Arve Sæther --- tests/auto/other/qaccessibilitylinux/qaccessibilitylinux.pro | 1 + tests/auto/other/qaccessibilitylinux/tst_qaccessibilitylinux.cpp | 7 +++---- 2 files changed, 4 insertions(+), 4 deletions(-) (limited to 'tests') 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 2b82b03998..7ba3715e13 100644 --- a/tests/auto/other/qaccessibilitylinux/tst_qaccessibilitylinux.cpp +++ b/tests/auto/other/qaccessibilitylinux/tst_qaccessibilitylinux.cpp @@ -42,12 +42,11 @@ #include #include -#include "atspi/atspi-constants.h" +#include +#include +#include #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 -- cgit v1.2.3 From cfdbfcebbda5f26b89c70df6b191b17ef242e9d7 Mon Sep 17 00:00:00 2001 From: Erik Verbruggen Date: Tue, 16 Apr 2019 13:30:31 +0200 Subject: QStateMachine: handle parallel child mode for state machines Setting the childMode property to ParallelStates will result in an invalid state machine. This is never checked (worse, we explicitly allow it and have a constructor to set it), but it results in findLCCA failing, which then results in a failing assert or crash. This fix in this patch is to handle this case separately. The proper fix would be to remove completely the ability to set the childMode on a QStateMachine, but that will have to wait until Qt6. Fixes: QTBUG-49975 Change-Id: I43692309c4d438ee1a9bc55fa4f65f8bce8e0a59 Reviewed-by: Ulf Hermann --- .../statemachine/qstatemachine/tst_qstatemachine.cpp | 14 ++++++++++---- 1 file changed, 10 insertions(+), 4 deletions(-) (limited to 'tests') 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() -- cgit v1.2.3 From ed19fc05313d338059a34304522d8e3a1932dc03 Mon Sep 17 00:00:00 2001 From: Marc Mutz Date: Sun, 19 May 2019 09:59:24 +0200 Subject: QFileSystemWatcher: lock autotest code away into a cold section MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit The code contained a sizeable chunk of string parsing along with qDebug()s in the normal path of execution. That code, however, was only used for Qt's own autotests. The idea of this patch is, then, to not only move the autotest case into the cold text section (using Q_UNLIKELY), but also to completely exclude it, when QT_BUILD_INTERNAL is not set. Unfortunately, the structure of the function did not really lend itself to #ifdefing that part of the code out (production code was in the middle of non-production code), so I transformed the engine selection code into a lambda, replacing assignment with returns, and swapping the branches of the central if around to yield a single block of code that can be excluded from compilation with just one #ifdef. As a consequence, the runtime code is almost unaffected, and the function is much easier to read now. Since the test-specific code is only compiled into Qt now in developer builds, guard the tests that rely on this behavior with the same macro. Change-Id: I9fd1c57020a13cef4cd1b1674ed2d3ab9424d7cd Reviewed-by: Mårten Nordheim --- .../corelib/io/qfilesystemwatcher/tst_qfilesystemwatcher.cpp | 12 ++++++++++++ 1 file changed, 12 insertions(+) (limited to 'tests') 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("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 { -- cgit v1.2.3 From 26a0db4b441a74cb65410635c3e8608a6360c793 Mon Sep 17 00:00:00 2001 From: Marc Mutz Date: Tue, 28 Nov 2017 13:22:22 +0100 Subject: Long live Qt::SplitBehavior! The is a copy of the QString::SplitBehavior enum, but scoped in the Qt namespace instead of inside QString, where it creates problems using it elsewhere (QStringView, in particular). Overload all QString{,Ref} functions taking QString::SplitBehavior with Qt::SplitBehavior. Make Qt::SplitBehavior a QFlags for easier future extensions (e.g. a hint to use Boyer-Moore searching). Added tests in QStringApiSymmetry. [ChangeLog][QtCore] Added new Qt::SplitBehavior. [ChangeLog][QtCore][QString/QStringRef] The split functions now optionally take Qt::SplitBehavior. Change-Id: I43a1f8d6b22f09af3709a0b4fb46fca61f9d1d1f Reviewed-by: Thiago Macieira --- .../qstringapisymmetry/tst_qstringapisymmetry.cpp | 141 +++++++++++++++++++++ 1 file changed, 141 insertions(+) (limited to 'tests') diff --git a/tests/auto/corelib/tools/qstringapisymmetry/tst_qstringapisymmetry.cpp b/tests/auto/corelib/tools/qstringapisymmetry/tst_qstringapisymmetry.cpp index b52c15fd73..3062c09db3 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 +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) \ @@ -292,6 +300,26 @@ private Q_SLOTS: void endsWith_QLatin1String_QChar_data() { endsWith_data(false); } void endsWith_QLatin1String_QChar() { endsWith_impl(); } +private: + void split_data(bool rhsHasVariableLength = true); + template 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(); } + void split_QString_QLatin1String_data() { split_data(); } + void split_QString_QLatin1String() { split_impl(); } + void split_QString_QChar_data() { split_data(false); } + void split_QString_QChar() { split_impl(); } + + void split_QStringRef_QString_data() { split_data(); } + void split_QStringRef_QString() { split_impl(); } + void split_QStringRef_QLatin1String_data() { split_data(); } + void split_QStringRef_QLatin1String() { split_impl(); } + void split_QStringRef_QChar_data() { split_data(false); } + void split_QStringRef_QChar() { split_impl(); } + private: void mid_data(); template void mid_impl(); @@ -780,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("haystackU16"); + QTest::addColumn("haystackL1"); + QTest::addColumn("needleU16"); + QTest::addColumn("needleL1"); + QTest::addColumn("resultCS"); + QTest::addColumn("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 +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(haystackU16, haystackL1, haystackU8); + const auto needle = make(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("unicode"); -- cgit v1.2.3 From ef3b585ddf0b5bb81c05eb034830d114843ba536 Mon Sep 17 00:00:00 2001 From: Friedemann Kleint Date: Fri, 10 May 2019 11:08:11 +0200 Subject: Brush up tst_QApplication - Use nullptr - Fix C-style casts - Use range-based for - Use correct static invocation - Set a title on shown windows to make it possible to identify slow tests - Fix the class declarations, use override, member initializations - Use Qt 5 connection syntax; use lambdas where applicable to remove helper slots - Streamline code in some cases - Replace helper function to convert touch points by the one in QWindowSystemInterfacePrivate - Use a logging category for the debug outpt, silencing some output Change-Id: Ia46c7ad7c08f3afc8e5869ea99b66e406de97781 Reviewed-by: Frederik Gladhorn --- .../widgets/kernel/qapplication/modal/base.cpp | 4 +- .../auto/widgets/kernel/qapplication/modal/base.h | 8 +- .../widgets/kernel/qapplication/modal/main.cpp | 5 +- .../kernel/qapplication/tst_qapplication.cpp | 685 ++++++++++----------- 4 files changed, 331 insertions(+), 371 deletions(-) (limited to 'tests') 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 - #include #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 d2a244b762..5b4a5d30a5 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 #include @@ -55,35 +54,14 @@ #include #include +#include #include -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 touchPointList(const QList& pointList) -{ - QList newList; - - Q_FOREACH (QTouchEvent::TouchPoint p, pointList) - { - newList.append(touchPoint(p)); - } - return newList; -} +#include +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 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. @@ -247,7 +207,7 @@ void tst_QApplication::staticSetup() QApplication::setFont(font);*/ int argc = 0; - QApplication app(argc, 0); + QApplication app(argc, nullptr); } @@ -255,13 +215,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(); } @@ -273,24 +232,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() @@ -311,7 +272,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 @@ -327,7 +288,7 @@ void tst_QApplication::multiple() QWidget widget; } - QVERIFY(!app.exec()); + QVERIFY(!QCoreApplication::exec()); } } @@ -339,7 +300,7 @@ void tst_QApplication::nonGui() #endif int argc = 0; - QApplication app(argc, 0, false); + QApplication app(argc, nullptr, false); QCOMPARE(qApp, &app); } @@ -350,36 +311,29 @@ void tst_QApplication::setFont_data() QTest::addColumn("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.begin(); - itr != families.end(); - ++itr) { - if (cnt < 3) { - QString family = *itr; - QStringList styles = fdb.styles(family); - if (styles.size() > 0) { - QString style = styles.first(); - QList 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 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" @@ -407,7 +361,7 @@ void tst_QApplication::setFont() } int argc = 0; - QApplication app(argc, 0); + QApplication app(argc, nullptr); if (!beforeAppConstructor) QApplication::setFont( font ); @@ -431,31 +385,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 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; } @@ -493,13 +446,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")); @@ -516,7 +469,7 @@ public: } protected: - void timerEvent(QTimerEvent *) + void timerEvent(QTimerEvent *) override { close(); } @@ -526,22 +479,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 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); QPointerwidget = 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(); @@ -550,14 +505,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); } @@ -565,27 +523,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(); @@ -594,6 +552,9 @@ public slots: QCOMPARE(spy.count(), 1); QCOMPARE(appSpy.count(), 1); } + +private: + QPushButton *m_okButton; }; class QuitOnLastWindowClosedWindow : public QWidget @@ -601,16 +562,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(); @@ -624,27 +585,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(); @@ -652,26 +615,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)); @@ -683,21 +648,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)); @@ -705,30 +678,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) @@ -737,34 +711,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(); @@ -773,19 +751,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"); @@ -797,12 +780,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(); @@ -819,7 +802,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; @@ -827,39 +810,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) @@ -883,7 +866,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 @@ -899,7 +881,7 @@ 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(); @@ -914,7 +896,7 @@ 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(); @@ -937,9 +919,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 @@ -948,10 +928,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); @@ -959,8 +937,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) @@ -970,36 +948,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/.."); + QCoreApplication::addLibraryPath(appDirPath + "/tmp/.."); #endif -#ifdef QT_TST_QAPP_DEBUG - qDebug() << "After adding appDirPath + /tmp/..:" << app.libraryPaths(); -#endif - QCOMPARE(app.libraryPaths().count(), count + 1); + qCDebug(lcTests) << "After adding appDirPath + /tmp/..:" << QCoreApplication::libraryPaths(); + QCOMPARE(QCoreApplication::libraryPaths().count(), count + 1); } } @@ -1008,14 +978,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() @@ -1042,14 +1012,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 - "))); } @@ -1066,8 +1036,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()); } @@ -1079,7 +1049,7 @@ class SendPostedEventsTester : public QObject Q_OBJECT public: QList eventSpy; - bool event(QEvent *e); + bool event(QEvent *e) override; private slots: void doTest(); }; @@ -1100,7 +1070,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)); @@ -1111,12 +1081,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 p = tester; - (void) app.exec(); + (void) QCoreApplication::exec(); QVERIFY(p.isNull()); } @@ -1124,7 +1094,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()); @@ -1140,10 +1110,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); @@ -1158,7 +1128,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 @@ -1173,10 +1143,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); @@ -1195,7 +1165,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 @@ -1211,10 +1181,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: @@ -1229,22 +1199,22 @@ void DeleteLaterWidget::runTest() QObject *stillAlive = this->findChild("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 } @@ -1262,11 +1232,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"); @@ -1275,7 +1245,7 @@ void tst_QApplication::testDeleteLater() QObject *stillAlive = wgt->findChild("deleteLater"); QVERIFY(stillAlive); - app.exec(); + QCoreApplication::exec(); delete wgt; @@ -1296,7 +1266,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); } @@ -1320,7 +1290,7 @@ public slots: } void sendPostedEventsWithDeferredDelete() { - QApplication::sendPostedEvents(0, QEvent::DeferredDelete); + QApplication::sendPostedEvents(nullptr, QEvent::DeferredDelete); } void deleteLaterAndProcessEvents() @@ -1349,7 +1319,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); } }; @@ -1367,16 +1337,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 @@ -1386,7 +1356,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); } @@ -1394,12 +1364,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); @@ -1409,12 +1379,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); @@ -1424,12 +1394,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); @@ -1455,7 +1425,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); @@ -1467,7 +1437,7 @@ void tst_QApplication::setActiveWindow() layout->addWidget(pb2); pb2->setFocus(); - pb2->setParent(0); + pb2->setParent(nullptr); delete pb2; w->show(); @@ -1481,13 +1451,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::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); @@ -1538,6 +1509,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); @@ -1556,9 +1528,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 @@ -1674,16 +1646,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(""); @@ -1698,6 +1672,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"); @@ -1721,6 +1696,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); @@ -1763,7 +1739,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 @@ -1790,15 +1766,15 @@ void tst_QApplication::style() { QApplication app(argc, &argv0); - QPointer style = app.style(); - app.setStyle(QStyleFactory::create(QLatin1String("Windows"))); + QPointer 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() @@ -1806,11 +1782,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() @@ -1820,16 +1794,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); } @@ -1849,7 +1822,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; @@ -1866,10 +1839,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); } @@ -1879,7 +1852,7 @@ public: seenTouchEvent = acceptTouchEvent = seenMouseEvent = acceptMouseEvent = false; } - bool event(QEvent *event) + bool event(QEvent *event) override { switch (event->type()) { case QEvent::MouseButtonPress: @@ -1923,11 +1896,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. @@ -1936,42 +1911,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); @@ -1980,26 +1955,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); @@ -2008,14 +1985,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); @@ -2025,14 +2002,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); @@ -2042,14 +2019,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); @@ -2060,14 +2037,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); @@ -2077,14 +2054,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); @@ -2095,14 +2072,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); @@ -2130,37 +2107,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: @@ -2170,25 +2143,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. @@ -2226,7 +2197,7 @@ void tst_QApplication::settableStyleHints() int argc = 0; QScopedPointer app; if (appInstance) - app.reset(new QApplication(argc, 0)); + app.reset(new QApplication(argc, nullptr)); QApplication::setCursorFlashTime(437); QCOMPARE(QApplication::cursorFlashTime(), 437); @@ -2292,12 +2263,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[]) { -- cgit v1.2.3 From 909f793de1d541dc51b2f26b327d5f7bc4ff88b0 Mon Sep 17 00:00:00 2001 From: Friedemann Kleint Date: Fri, 10 May 2019 09:10:27 +0200 Subject: Brush up tst_QWindow - Use nullptr - Fix C-style casts - Remove unnecessary casts to int from registered enums - Fix most signedness-related warnings - Use range-based for - Use correct static invocation - Set a title on shown windows to make it possible to identify slow tests - Fix the class declarations, use override, member initializations - Streamline code in some cases Change-Id: I4c9b99126cff02136def0e03accdf1129fe6d72b Reviewed-by: Frederik Gladhorn --- tests/auto/gui/kernel/qwindow/tst_qwindow.cpp | 209 ++++++++++++++------------ 1 file changed, 115 insertions(+), 94 deletions(-) (limited to 'tests') 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 #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("windowflags"); + QTest::addColumn("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(); -- cgit v1.2.3 From e72e5aa83a0a287ea7e19158b39917eb3daef1d9 Mon Sep 17 00:00:00 2001 From: Friedemann Kleint Date: Thu, 9 May 2019 10:20:57 +0200 Subject: Brush up tst_QWidget - Use nullptr - Fix C-style casts - Fix redundant bool expressions - Fix else after return - Remove unnecessary casts to int from registered enums - Fix most signedness-related warnings - Use range-based for - Use correct static invocation - Set a title on shown windows to make it possible to identify slow tests - Fix the class declarations, use override, member initializations - Use Qt 5 connection syntax - Remove unused variables - Streamline code in some cases Change-Id: I1350b382b0b7d0f3198039fdc78892cfa1dd498d Reviewed-by: Oliver Wolff Reviewed-by: Edward Welbourne --- tests/auto/widgets/kernel/qwidget/tst_qwidget.cpp | 1058 +++++++++++---------- 1 file changed, 548 insertions(+), 510 deletions(-) (limited to 'tests') diff --git a/tests/auto/widgets/kernel/qwidget/tst_qwidget.cpp b/tests/auto/widgets/kernel/qwidget/tst_qwidget.cpp index 780cb01e40..bbaed67a36 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 #include +#include + 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(handle); qWarning() << "Cannot obtain native handle for " << w; - return 0; + return nullptr; } # define Q_CHECK_PAINTEVENTS \ @@ -432,9 +434,9 @@ void tst_QWidget::getSetCheck() QScopedPointer var1(QStyleFactory::create(QLatin1String("Windows"))); obj1.setStyle(var1.data()); QCOMPARE(static_cast(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) @@ -510,7 +512,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() @@ -519,16 +521,16 @@ void tst_QWidget::getSetCheck() QScopedPointer 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)); @@ -540,10 +542,10 @@ void tst_QWidget::getSetCheck() QBoxLayout *var11 = new QBoxLayout(QBoxLayout::LeftToRight); obj1.setLayout(var11); QCOMPARE(static_cast(var11), obj1.layout()); - obj1.setLayout((QLayout *)0); + obj1.setLayout(nullptr); QCOMPARE(static_cast(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) @@ -563,7 +565,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(obj1.winId()); // explicitly create window handle - QVERIFY(GetWindowLong(handle, GWL_STYLE) & WS_POPUP); + QVERIFY(GetWindowLong(handle, GWL_STYLE) & LONG(WS_POPUP)); #endif } @@ -578,12 +580,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() @@ -592,16 +594,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 @@ -728,9 +720,7 @@ class QPropagationTestWidget : public QWidget { Q_OBJECT public: - QPropagationTestWidget(QWidget *parent = 0) - : QWidget(parent) - { } + using QWidget::QWidget; }; void tst_QWidget::fontPropagation2() @@ -739,7 +729,7 @@ void tst_QWidget::fontPropagation2() // QFont font; // font.setBold(true); // font.setPointSize(42); - // qApp->setFont(font, "QPropagationTestWidget"); + // QApplication::setFont(font, "QPropagationTestWidget"); QScopedPointer root(new QWidget); root->setObjectName(QLatin1String("fontPropagation2")); @@ -796,7 +786,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()); @@ -949,7 +939,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); @@ -1136,7 +1126,7 @@ void tst_QWidget::isEnabledTo() QScopedPointer childDialog(new QMainWindow(&testWidget)); testWidget.setEnabled(false); QVERIFY(!childDialog->isEnabled()); - QVERIFY(childDialog->isEnabledTo(0)); + QVERIFY(childDialog->isEnabledTo(nullptr)); } void tst_QWidget::visible() @@ -1581,8 +1571,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) { @@ -1595,8 +1585,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) { @@ -1606,8 +1596,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) { @@ -1631,7 +1621,7 @@ void tst_QWidget::focusChainOnHide() QWidget::setTabOrder(child, parent.data()); parent->show(); - qApp->setActiveWindow(parent->window()); + QApplication::setActiveWindow(parent->window()); child->activateWindow(); child->setFocus(); @@ -1639,7 +1629,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 @@ -1667,7 +1657,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); @@ -1706,9 +1696,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()); @@ -1746,6 +1737,7 @@ void tst_QWidget::reverseTabOrder() { const int compositeCount = 2; Container container; + container.setWindowTitle(QLatin1String(QTest::currentTestFunction())); Composite* composite[compositeCount]; QLineEdit *firstEdit = new QLineEdit(); @@ -1765,7 +1757,7 @@ void tst_QWidget::reverseTabOrder() container.show(); container.activateWindow(); - qApp->setActiveWindow(&container); + QApplication::setActiveWindow(&container); QVERIFY(QTest::qWaitForWindowActive(&container)); QTRY_VERIFY(firstEdit->hasFocus()); @@ -1804,6 +1796,7 @@ void tst_QWidget::tabOrderWithProxy() { const int compositeCount = 2; Container container; + container.setWindowTitle(QLatin1String(QTest::currentTestFunction())); Composite* composite[compositeCount]; QLineEdit *firstEdit = new QLineEdit(); @@ -1823,7 +1816,7 @@ void tst_QWidget::tabOrderWithProxy() container.show(); container.activateWindow(); - qApp->setActiveWindow(&container); + QApplication::setActiveWindow(&container); QVERIFY(QTest::qWaitForWindowActive(&container)); QTRY_VERIFY(firstEdit->hasFocus()); @@ -1861,13 +1854,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 @@ -1893,7 +1887,7 @@ void tst_QWidget::tabOrderWithCompoundWidgets() container.show(); container.activateWindow(); - qApp->setActiveWindow(&container); + QApplication::setActiveWindow(&container); QVERIFY(QTest::qWaitForWindowActive(&container)); lastEdit->setFocus(); @@ -2306,26 +2300,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(); @@ -2343,6 +2338,7 @@ void tst_QWidget::resizeEvent() { ResizeWidget wTopLevel; + wTopLevel.setWindowTitle(QLatin1String(QTest::currentTestFunction())); wTopLevel.resize(200, 200); wTopLevel.show(); QVERIFY(QTest::qWaitForWindowExposed(&wTopLevel)); @@ -2370,6 +2366,7 @@ void tst_QWidget::showMinimized() } QWidget plain; + plain.setWindowTitle(QLatin1String(QTest::currentTestFunction())); plain.move(100, 100); plain.resize(200, 200); QPoint pos = plain.pos(); @@ -2424,17 +2421,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()); @@ -2448,15 +2446,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); @@ -2466,17 +2465,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 childGuard(child); QCOMPARE(window.focusWidget(), nullptr); QCOMPARE(QApplication::focusWidget(), nullptr); @@ -2485,15 +2485,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); @@ -2503,17 +2504,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); @@ -2526,7 +2528,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()) @@ -2541,7 +2543,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); } } @@ -2553,7 +2555,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; @@ -2580,7 +2582,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(); @@ -2647,17 +2649,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); } @@ -2774,6 +2776,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); @@ -2786,7 +2789,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); @@ -2834,13 +2837,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) { @@ -2849,7 +2853,7 @@ public: } } - bool event(QEvent *event) + bool event(QEvent *event) override { switch (event->type()) { case QEvent::ZOrderChange: @@ -2872,12 +2876,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(); } @@ -2894,6 +2896,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); @@ -2937,12 +2940,11 @@ void tst_QWidget::raise() } #endif - QList 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); @@ -2958,7 +2960,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); @@ -2973,6 +2975,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(); @@ -2987,7 +2990,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) @@ -2997,11 +3000,10 @@ void tst_QWidget::raise() QCOMPARE(onTop->numPaintEvents, 0); QCOMPARE(onTop->numZOrderChangeEvents, 0); - QList 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); @@ -3037,12 +3039,11 @@ void tst_QWidget::lower() parent->show(); QVERIFY(QTest::qWaitForWindowExposed(parent.data())); - QList 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); @@ -3059,7 +3060,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); @@ -3102,11 +3103,10 @@ void tst_QWidget::stackUnder() parent->show(); QVERIFY(QTest::qWaitForWindowExposed(parent.data())); - QList 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) @@ -3121,11 +3121,10 @@ void tst_QWidget::stackUnder() child4->stackUnder(child2); QTest::qWait(10); - QList 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); @@ -3137,11 +3136,10 @@ void tst_QWidget::stackUnder() child1->stackUnder(child3); QTest::qWait(10); - QList 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 @@ -3174,30 +3172,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(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. @@ -3271,6 +3270,7 @@ void tst_QWidget::saveRestoreGeometry() { QWidget widget; + widget.setWindowTitle(QLatin1String(QTest::currentTestFunction())); const QByteArray empty; const QByteArray one("a"); @@ -3382,7 +3382,7 @@ void tst_QWidget::restoreVersion1Geometry_data() if (m_platform == QStringLiteral("wayland")) QSKIP("Wayland: This fails. Figure out why."); QTest::addColumn("fileName"); - QTest::addColumn("expectedWindowState"); + QTest::addColumn("expectedWindowState"); QTest::addColumn("expectedPosition"); QTest::addColumn("expectedSize"); QTest::addColumn("expectedNormalGeometry"); @@ -3390,9 +3390,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; } /* @@ -3402,14 +3402,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()); @@ -3419,10 +3419,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); @@ -3486,11 +3488,11 @@ void tst_QWidget::widgetAt() Q_CHECK_PAINTEVENTS const QPoint referencePos = m_availableTopLeft + QPoint(100, 100); - QScopedPointer w1(new QWidget(0, Qt::X11BypassWindowManagerHint)); + QScopedPointer w1(new QWidget(nullptr, Qt::X11BypassWindowManagerHint)); w1->setGeometry(QRect(referencePos, QSize(m_testWidgetSize.width(), 150))); w1->setObjectName(QLatin1String("w1")); w1->setWindowTitle(w1->objectName()); - QScopedPointer w2(new QWidget(0, Qt::X11BypassWindowManagerHint | Qt::FramelessWindowHint)); + QScopedPointer 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()); @@ -3550,6 +3552,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); @@ -3567,20 +3570,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() @@ -3629,7 +3632,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; @@ -3733,21 +3736,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; @@ -3755,7 +3756,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; } } @@ -3770,6 +3771,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); @@ -3851,6 +3853,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)); @@ -3895,7 +3898,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 sibling; @@ -3904,8 +3907,8 @@ private: void tst_QWidget::childDeletesItsSibling() { - QWidget *commonParent = new QWidget(0); - QPointer child = new QWidget(0); + auto commonParent = new QWidget(nullptr); + QPointer child(new QWidget(nullptr)); QPointer siblingDeleter = new SiblingDeleter(child, commonParent); child->setParent(commonParent); delete commonParent; // don't crash @@ -4040,15 +4043,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()); @@ -4142,7 +4142,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); @@ -4152,7 +4152,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); @@ -4164,7 +4164,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); @@ -4205,26 +4205,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()) @@ -4287,6 +4281,7 @@ void tst_QWidget::showHideEvent() QFETCH(int, expectedHideEvents); ShowHideEventWidget widget; + widget.setWindowTitle(QLatin1String(QTest::currentTestFunction())); if (show) widget.show(); if (hide) @@ -4349,13 +4344,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(); @@ -4607,14 +4603,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")) @@ -4626,7 +4622,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); @@ -4639,7 +4635,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)); @@ -4652,7 +4648,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)); @@ -4689,17 +4685,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(object) != 0 || object->isWidgetType()); + wasQWidget = (qobject_cast(object) != nullptr || object->isWidgetType()); } }; @@ -4713,7 +4704,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); @@ -4722,62 +4713,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; + void tst_QWidget::setWindowGeometry_data() { - QTest::addColumn >("rects"); + QTest::addColumn("rects"); QTest::addColumn("windowFlags"); - QList > rects; + QVector 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(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() - << 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(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(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(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 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 l, rects) { - QRect rect = l.first(); + for (Rects l : qAsConst(rects)) { if (skipEmptyRects) { - QList::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()) @@ -4797,7 +4779,7 @@ void tst_QWidget::setWindowGeometry() else if (m_platform == QStringLiteral("winrt")) QSKIP("WinRT does not support setWindowGeometry"); - QFETCH(QList, rects); + QFETCH(Rects, rects); QFETCH(int, windowFlags); QRect rect = rects.takeFirst(); @@ -4812,7 +4794,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); @@ -4822,6 +4804,7 @@ void tst_QWidget::setWindowGeometry() { // setGeometry() first, then show() QWidget widget; + widget.setWindowTitle(QLatin1String(QTest::currentTestFunction())); if (windowFlags != 0) widget.setWindowFlags(Qt::WindowFlags(windowFlags)); @@ -4837,7 +4820,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); @@ -4852,7 +4835,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); @@ -4876,6 +4859,7 @@ void tst_QWidget::setWindowGeometry() { // show() first, then setGeometry() QWidget widget; + widget.setWindowTitle(QLatin1String(QTest::currentTestFunction())); if (windowFlags != 0) widget.setWindowFlags(Qt::WindowFlags(windowFlags)); @@ -4887,7 +4871,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); @@ -4902,7 +4886,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); @@ -4965,7 +4949,7 @@ void tst_QWidget::windowMoveResize() if (m_platform == QStringLiteral("winrt")) QSKIP("WinRT does not support move/resize"); - QFETCH(QList, rects); + QFETCH(Rects, rects); QFETCH(int, windowFlags); QRect rect = rects.takeFirst(); @@ -4983,7 +4967,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(); @@ -4995,6 +4979,7 @@ void tst_QWidget::windowMoveResize() { // move() first, then show() QWidget widget; + widget.setWindowTitle(QLatin1String(QTest::currentTestFunction())); if (windowFlags != 0) widget.setWindowFlags(Qt::WindowFlags(windowFlags)); @@ -5011,7 +4996,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) @@ -5040,7 +5025,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(); @@ -5091,7 +5076,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(); @@ -5111,7 +5096,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(); @@ -5149,8 +5134,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); @@ -5158,16 +5144,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() { @@ -5177,8 +5165,8 @@ public: QColor color; QRegion r; - int enters; - int leaves; + int enters = 0; + int leaves = 0; }; static inline QByteArray msgRgbMismatch(unsigned actual, unsigned expected) @@ -5196,7 +5184,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); @@ -5222,16 +5210,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 @@ -5267,7 +5252,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 style(QStyleFactory::create(QLatin1String("Windows"))); parent.setStyle(style.data()); @@ -5314,7 +5299,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 style(QStyleFactory::create(QLatin1String("Windows"))); parent.setStyle(style.data()); @@ -5329,7 +5315,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); @@ -5341,7 +5327,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)"); @@ -5357,6 +5343,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); @@ -5390,10 +5377,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 @@ -5401,21 +5389,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(); @@ -5462,7 +5450,7 @@ void tst_QWidget::multipleToplevelFocusCheck() QVERIFY(QTest::qWaitForWindowActive(&w2)); QCOMPARE(QApplication::activeWindow(), static_cast(&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(w2.edit)); @@ -5479,28 +5467,28 @@ void tst_QWidget::multipleToplevelFocusCheck() QVERIFY(QTest::qWaitForWindowActive(&w2)); QCOMPARE(QApplication::activeWindow(), static_cast(&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) @@ -5509,22 +5497,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() @@ -5621,7 +5606,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()); @@ -5648,7 +5633,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); @@ -5689,7 +5674,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); @@ -5730,6 +5715,7 @@ void tst_QWidget::setFocus() { QWidget window; + window.setWindowTitle(QLatin1String(QTest::currentTestFunction())); window.resize(m_testWidgetSize); window.move(windowPos); @@ -5748,7 +5734,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"); @@ -5757,7 +5743,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"); } @@ -5767,7 +5753,7 @@ template 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); @@ -5778,7 +5764,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; @@ -5787,8 +5773,8 @@ protected: private: T *m_widget; - QEvent::Type eventToSpy; - int m_count; + const QEvent::Type eventToSpy; + int m_count = 0; }; #ifndef QT_NO_CURSOR @@ -5811,6 +5797,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(); @@ -5839,6 +5826,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); @@ -5860,7 +5848,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()); @@ -5876,6 +5864,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); @@ -5884,7 +5873,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()); @@ -5936,7 +5925,7 @@ void tst_QWidget::setToolTip() for (int pass = 0; pass < 2; ++pass) { QCursor::setPos(m_safeCursorPos); - QScopedPointer popup(new QWidget(0, Qt::Popup)); + QScopedPointer 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); @@ -5945,7 +5934,7 @@ void tst_QWidget::setToolTip() frame->setFrameStyle(QFrame::Box | QFrame::Plain); EventSpy spy1(frame, QEvent::ToolTip); EventSpy 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(); @@ -5999,13 +5988,13 @@ void tst_QWidget::testWindowIconChangeEventPropagation() // Create spy lists. QList applicationEventSpies; QList 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 appWindowEventSpies; QList windowEventSpies; - foreach (QWindow *window, windows) { + for (QWindow *window : qAsConst(windows)) { appWindowEventSpies.append(WindowEventSpyPtr::create(window, QEvent::ApplicationWindowIconChange)); windowEventSpies.append(WindowEventSpyPtr::create(window, QEvent::WindowIconChange)); } @@ -6082,7 +6071,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); @@ -6094,7 +6084,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); @@ -6110,13 +6101,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); } @@ -6138,7 +6128,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(message); return ((responseType & ~0x80) == XCB_MAP_NOTIFY); } return false; @@ -6169,6 +6159,7 @@ void tst_QWidget::showHideShowX11() QSKIP("This test is for X11 only."); ShowHideShowWidget w; + w.setWindowTitle(QLatin1String(QTest::currentTestFunction())); qApp->installNativeEventFilter(&w); w.show(); @@ -6176,7 +6167,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); @@ -6190,6 +6181,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); @@ -6223,11 +6215,9 @@ public: typedef QPair WidgetEventTypePair; typedef QList EventList; - EventRecorder(QObject *parent = 0) - : QObject(parent) - { } + using QObject::QObject; - EventList eventList() + EventList eventList() const { return events; } @@ -6237,7 +6227,7 @@ public: events.clear(); } - bool eventFilter(QObject *object, QEvent *event) + bool eventFilter(QObject *object, QEvent *event) override { QWidget *widget = qobject_cast(object); if (widget && !event->spontaneous()) @@ -6257,8 +6247,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; @@ -6450,7 +6440,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))); @@ -6487,7 +6477,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))); @@ -6567,6 +6557,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; @@ -6580,22 +6571,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); @@ -6606,6 +6597,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"))); @@ -6615,7 +6607,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); @@ -6623,6 +6615,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); @@ -6683,6 +6676,7 @@ void tst_QWidget::renderInvisible() QScopedPointer 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; @@ -6697,7 +6691,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. @@ -6712,7 +6706,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); @@ -6723,7 +6717,7 @@ void tst_QWidget::renderInvisible() // Explicitly hide the calendar. calendar->hide(); - qApp->processEvents(); + QCoreApplication::processEvents(); QTest::qWait(30); workaroundPaletteIssue(calendar.data()); @@ -6753,7 +6747,7 @@ void tst_QWidget::renderInvisible() } calendar->hide(); - qApp->processEvents(); + QCoreApplication::processEvents(); QTest::qWait(30); { // Calendar explicitly hidden. @@ -6821,7 +6815,7 @@ void tst_QWidget::renderInvisible() // Navigation bar isn't explicitly hidden anymore. navigationBar->show(); - qApp->processEvents(); + QCoreApplication::processEvents(); QTest::qWait(30); QVERIFY(!calendar->isVisible()); @@ -6830,7 +6824,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); @@ -6883,7 +6877,7 @@ void tst_QWidget::renderInvisible() void tst_QWidget::renderWithPainter() { - QWidget widget(0, Qt::Tool); + QWidget widget(nullptr, Qt::Tool); // prevent custom styles const QScopedPointer style(QStyleFactory::create(QLatin1String("Windows"))); @@ -6999,7 +6993,7 @@ void tst_QWidget::render_task211796() { class MyWidget : public QWidget { - void resizeEvent(QResizeEvent *) + void resizeEvent(QResizeEvent *) override { QPixmap pixmap(size()); render(&pixmap); @@ -7008,6 +7002,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(); @@ -7015,6 +7010,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(); @@ -7083,19 +7079,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); @@ -7232,16 +7228,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 @@ -7337,7 +7333,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. @@ -7363,8 +7358,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 @@ -7419,8 +7415,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. @@ -7514,6 +7511,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()); @@ -7546,7 +7544,7 @@ void tst_QWidget::moveWindowInShowEvent() { public: QPoint position; - void showEvent(QShowEvent *) + void showEvent(QShowEvent *) override { move(position); } @@ -7577,7 +7575,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; @@ -7601,7 +7600,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; @@ -7644,6 +7644,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(); @@ -7678,13 +7679,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 }; @@ -7695,6 +7693,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); @@ -7729,6 +7728,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); @@ -7772,6 +7772,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)); @@ -7800,6 +7801,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); @@ -7824,6 +7826,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); @@ -7857,6 +7860,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); @@ -7895,6 +7899,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); @@ -7929,7 +7934,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")); @@ -7946,17 +7951,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; @@ -8031,7 +8034,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)) { @@ -8050,17 +8053,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() @@ -8069,7 +8069,7 @@ void tst_QWidget::updateGeometry_data() QTest::addColumn("shouldInvalidate"); QTest::addColumn("maxSize"); QTest::addColumn("shouldInvalidate2"); - QTest::addColumn("verticalSizePolicy"); + QTest::addColumn("verticalSizePolicy"); QTest::addColumn("shouldInvalidate3"); QTest::addColumn("setVisible"); QTest::addColumn("shouldInvalidate4"); @@ -8077,32 +8077,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; } @@ -8113,11 +8113,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); @@ -8137,7 +8139,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); @@ -8150,11 +8152,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); @@ -8173,6 +8176,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. @@ -8206,10 +8210,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); @@ -8230,6 +8235,7 @@ void tst_QWidget::resizeInPaintEvent() void tst_QWidget::opaqueChildren() { QWidget widget; + widget.setWindowTitle(QLatin1String(QTest::currentTestFunction())); widget.resize(200, 200); QWidget child(&widget); @@ -8270,10 +8276,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(); @@ -8281,26 +8287,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); @@ -8339,19 +8341,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; } @@ -8365,6 +8367,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)); @@ -8379,6 +8382,7 @@ void tst_QWidget::immediateRepaintAfterInvalidateBuffer() QSKIP("We don't support immediate repaint right after show on other platforms."); QScopedPointer widget(new UpdateWidget); + widget->setWindowTitle(QLatin1String(QTest::currentTestFunction())); centerOnScreen(widget.data()); widget->show(); QVERIFY(QTest::qWaitForWindowExposed(widget.data())); @@ -8400,6 +8404,7 @@ void tst_QWidget::immediateRepaintAfterInvalidateBuffer() void tst_QWidget::effectiveWinId() { QWidget parent; + parent.setWindowTitle(QLatin1String(QTest::currentTestFunction())); parent.resize(200, 200); QWidget child(&parent); @@ -8417,8 +8422,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. @@ -8433,18 +8439,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); } @@ -8538,6 +8545,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); @@ -8558,11 +8566,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(ni->nativeResourceForWindow(QByteArrayLiteral("getDC"), windowHandle())); if (hdc) { const HBRUSH brush = CreateSolidBrush(RGB(255, 0, 0)); SelectObject(hdc, brush); @@ -8579,9 +8588,7 @@ public: } } - QSize sizeHint() const { - return QSize(400, 300); - } + QSize sizeHint() const override { return {400, 300}; }; private slots: void slotTimer() { @@ -8608,6 +8615,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)); @@ -8664,7 +8672,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); @@ -8734,12 +8742,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); } @@ -8750,6 +8759,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(); @@ -8778,12 +8788,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(); @@ -8809,10 +8820,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(); @@ -8959,6 +8971,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); @@ -9112,16 +9125,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); @@ -9217,31 +9231,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); @@ -9341,9 +9356,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; @@ -9355,6 +9370,7 @@ private slots: void tst_QWidget::updateOnDestroyedSignal() { QWidget widget; + widget.setWindowTitle(QLatin1String(QTest::currentTestFunction())); QWidget *child = new QWidget(&widget); child->resize(m_testWidgetSize); @@ -9372,18 +9388,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(&w)); + QTRY_COMPARE(QApplication::focusWidget(), static_cast(&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); @@ -9400,6 +9418,7 @@ void tst_QWidget::focusWidget_task254563() void tst_QWidget::destroyBackingStore() { UpdateWidget w; + w.setWindowTitle(QLatin1String(QTest::currentTestFunction())); centerOnScreen(&w); w.reset(); w.show(); @@ -9426,7 +9445,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(); @@ -9440,7 +9459,8 @@ void tst_QWidget::rectOutsideCoordinatesLimit_task144779() #ifndef QT_NO_CURSOR QApplication::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); @@ -9483,6 +9503,7 @@ void tst_QWidget::setGraphicsEffect() { // Check that we don't have any effect by default. QScopedPointer widget(new QWidget); + widget->setWindowTitle(QLatin1String(QTest::currentTestFunction())); QVERIFY(!widget->graphicsEffect()); // SetGet check. @@ -9519,7 +9540,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); } @@ -9533,6 +9554,7 @@ void tst_QWidget::activateWindow() // Create first mainwindow and set it active QScopedPointer mainwindow(new QMainWindow); + mainwindow->setWindowTitle(QLatin1String(QTest::currentTestFunction())); QLabel* label = new QLabel(mainwindow.data()); label->setMinimumWidth(m_testWidgetSize.width()); mainwindow->setWindowTitle(QStringLiteral("#1 ") + __FUNCTION__); @@ -9552,7 +9574,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()); @@ -9560,7 +9582,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")) @@ -9596,7 +9618,8 @@ void tst_QWidget::focusProxyAndInputMethods() { if (m_platform == QStringLiteral("wayland")) QSKIP("Wayland: This fails. Figure out why."); - QScopedPointer toplevel(new QWidget(0, Qt::X11BypassWindowManagerHint)); + QScopedPointer toplevel(new QWidget(nullptr, Qt::X11BypassWindowManagerHint)); + toplevel->setWindowTitle(QLatin1String(QTest::currentTestFunction())); toplevel->resize(200, 200); toplevel->setAttribute(Qt::WA_InputMethodEnabled, true); @@ -9643,6 +9666,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); @@ -9661,6 +9685,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); @@ -9673,7 +9698,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)); @@ -9721,7 +9747,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); @@ -9801,6 +9828,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(); @@ -9813,6 +9841,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; @@ -9850,8 +9879,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(actualImage.bits()); + auto e = reinterpret_cast(expectedImage.bits()); for (int i = 0; i < size; ++i) { const QColor ca(a[i]); const QColor ce(e[i]); @@ -9871,6 +9900,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(image.scanLine(row)); @@ -9920,12 +9950,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: @@ -9949,6 +9980,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); @@ -9960,7 +9992,7 @@ void tst_QWidget::grabMouse() layout->addWidget(grabber); centerOnScreen(&w); w.show(); - qApp->setActiveWindow(&w); + QApplication::setActiveWindow(&w); QVERIFY(QTest::qWaitForWindowActive(&w)); QStringList expectedLog; @@ -9969,7 +10001,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)); @@ -9982,6 +10014,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); @@ -9993,7 +10026,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(); @@ -10005,16 +10038,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); } @@ -10031,7 +10055,7 @@ public: } protected: - bool event(QEvent *e) + bool event(QEvent *e) override { switch (e->type()) { case QEvent::TouchBegin: @@ -10070,14 +10094,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; }; @@ -10086,6 +10110,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); @@ -10108,6 +10133,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())); @@ -10129,6 +10155,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); @@ -10151,6 +10178,7 @@ 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); const QPoint childPos(5, 5); child.move(childPos); @@ -10176,6 +10204,7 @@ void tst_QWidget::touchEventSynthesizedMouseEvent() void tst_QWidget::touchUpdateOnNewTouch() { TouchMouseWidget widget; + widget.setWindowTitle(QLatin1String(QTest::currentTestFunction())); widget.setAcceptTouch(true); QVBoxLayout *layout = new QVBoxLayout; layout->addWidget(new QWidget); @@ -10212,6 +10241,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(); @@ -10250,8 +10280,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(child)) QCOMPARE(w->style(), tw.style()); } @@ -10261,7 +10292,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() { @@ -10276,7 +10307,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); @@ -10285,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); w->blockSignals(true); QCOMPARE(DestroyTester::parentDestroyed, 0); delete w; @@ -10295,7 +10326,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); @@ -10303,8 +10334,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; @@ -10313,8 +10344,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); @@ -10323,8 +10354,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; @@ -10334,8 +10365,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); @@ -10344,8 +10375,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; @@ -10361,10 +10392,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"); @@ -10553,7 +10585,7 @@ class EnterTestModalDialog : public QDialog { Q_OBJECT public: - EnterTestModalDialog() : QDialog(), button(0) + EnterTestModalDialog() { setGeometry(100, 300, 150, 100); button = new QPushButton(this); @@ -10567,7 +10599,6 @@ class EnterTestMainDialog : public QDialog { Q_OBJECT public: - EnterTestMainDialog() : QDialog(), modal(0), enters(0) {} public slots: void buttonPressed() @@ -10595,7 +10626,7 @@ public slots: modal->close(); } - bool eventFilter(QObject *o, QEvent *e) + bool eventFilter(QObject *o, QEvent *e) override { switch (e->type()) { case QEvent::Enter: @@ -10609,8 +10640,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 @@ -10624,9 +10655,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); @@ -10638,7 +10670,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()... @@ -10650,20 +10682,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)); @@ -10676,17 +10710,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); @@ -10701,6 +10735,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)); @@ -10718,6 +10753,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); @@ -10743,11 +10779,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"); @@ -10861,6 +10898,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. @@ -10879,7 +10917,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); @@ -10888,7 +10926,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); @@ -10897,7 +10935,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); @@ -10905,12 +10943,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); @@ -10918,7 +10956,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); -- cgit v1.2.3 From b88be0451972b5e9858298923a0b2dca1c4f04cd Mon Sep 17 00:00:00 2001 From: Friedemann Kleint Date: Thu, 9 May 2019 15:48:37 +0200 Subject: Make tst_qwidget_window pass on High-DPI screens (Windows) Use a fuzz check (cf 63090627220a6209652d236cf991305fbeb188b8) and a minimum size similar to tst_qwidget to make the test pass on large monitors with or without active scaling. Change-Id: I5a9e28e38e1d007057894c349c94f0e6fe12009c Reviewed-by: Richard Moe Gustavsen --- .../kernel/qwidget_window/tst_qwidget_window.cpp | 71 +++++++++++++++------- 1 file changed, 49 insertions(+), 22 deletions(-) (limited to 'tests') 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)); -- cgit v1.2.3 From 18b336990f39d849be52b981c6d8a43274c84487 Mon Sep 17 00:00:00 2001 From: Friedemann Kleint Date: Mon, 20 May 2019 09:15:17 +0200 Subject: Brush up tst_QMdiSubWindow - Use nullptr - Use range-based for - Use correct static invocation - Set a title on shown windows to make it possible to identify slow tests - Fix the class declarations, use override, member initializations - Use Qt 5 connection syntax where possible - Ensure top level widget list is empty after each test, delete left-over menu bars and disable menu animations Change-Id: Ieeb943ea669cd139f1835088b816802e777a9676 Reviewed-by: Richard Moe Gustavsen --- .../widgets/qmdisubwindow/tst_qmdisubwindow.cpp | 397 ++++++++++++--------- 1 file changed, 227 insertions(+), 170 deletions(-) (limited to 'tests') diff --git a/tests/auto/widgets/widgets/qmdisubwindow/tst_qmdisubwindow.cpp b/tests/auto/widgets/widgets/qmdisubwindow/tst_qmdisubwindow.cpp index 8b2f032172..f69b65bdbe 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 #include +#include + 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"); + // 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(widget)); QCOMPARE(widget->parentWidget(), static_cast(&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(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 windows; + QVector 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(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(); @@ -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(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(); 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(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(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,6 +1009,7 @@ 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); @@ -987,9 +1021,9 @@ void tst_QMdiSubWindow::setSystemMenu() QPoint globalPopupPos; // Show system menu - QVERIFY(!qApp->activePopupWidget()); + QVERIFY(!QApplication::activePopupWidget()); subWindow->showSystemMenu(); - QTRY_COMPARE(qApp->activePopupWidget(), qobject_cast(systemMenu)); + QTRY_COMPARE(QApplication::activePopupWidget(), qobject_cast(systemMenu)); #ifdef Q_OS_WINRT QEXPECT_FAIL("", "Broken on WinRT - QTBUG-68297", Abort); #endif @@ -997,12 +1031,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 +1048,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(systemMenu)); + QTRY_COMPARE(QApplication::activePopupWidget(), qobject_cast(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 +1063,30 @@ void tst_QMdiSubWindow::setSystemMenu() QWidget *menuLabel = subWindow->maximizedSystemMenuIconWidget(); QVERIFY(menuLabel); subWindow->showSystemMenu(); - QTRY_COMPARE(qApp->activePopupWidget(), qobject_cast(systemMenu)); + QTRY_COMPARE(QApplication::activePopupWidget(), qobject_cast(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(systemMenu)); + QTRY_COMPARE(QApplication::activePopupWidget(), qobject_cast(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 +1095,15 @@ void tst_QMdiSubWindow::setSystemMenu() menuLabel = subWindow->maximizedSystemMenuIconWidget(); QVERIFY(menuLabel); subWindow->showSystemMenu(); - QTRY_COMPARE(qApp->activePopupWidget(), qobject_cast(systemMenu)); + QTRY_COMPARE(QApplication::activePopupWidget(), qobject_cast(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 +1129,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 +1144,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(expectedFocusWindow)); + QCOMPARE(QApplication::focusWidget(), static_cast(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(expectedFocusWindow)); + QCOMPARE(QApplication::focusWidget(), static_cast(expectedFocusWindow)); complexWindow->showMinimized(); - qApp->processEvents(); + QCoreApplication::processEvents(); QVERIFY(complexWindow->isMinimized()); - QCOMPARE(qApp->focusWidget(), static_cast(complexWindow)); + QCOMPARE(QApplication::focusWidget(), static_cast(complexWindow)); complexWindow->showNormal(); - qApp->processEvents(); + QCoreApplication::processEvents(); QVERIFY(!complexWindow->isMinimized()); - QCOMPARE(qApp->focusWidget(), static_cast(expectedFocusWindow)); + QCOMPARE(QApplication::focusWidget(), static_cast(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 +1269,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(firstLineEdit)); + QApplication::setActiveWindow(&mdiArea); + QCOMPARE(QApplication::focusWidget(), static_cast(firstLineEdit)); // Next QTest::keyPress(widget, Qt::Key_Tab); - QCOMPARE(qApp->focusWidget(), static_cast(secondLineEdit)); + QCOMPARE(QApplication::focusWidget(), static_cast(secondLineEdit)); // Next QTest::keyPress(widget, Qt::Key_Tab); - QCOMPARE(qApp->focusWidget(), static_cast(thirdLineEdit)); + QCOMPARE(QApplication::focusWidget(), static_cast(thirdLineEdit)); // Previous QTest::keyPress(widget, Qt::Key_Backtab); - QCOMPARE(qApp->focusWidget(), static_cast(secondLineEdit)); + QCOMPARE(QApplication::focusWidget(), static_cast(secondLineEdit)); // Previous QTest::keyPress(widget, Qt::Key_Backtab); - QCOMPARE(qApp->focusWidget(), static_cast(firstLineEdit)); + QCOMPARE(QApplication::focusWidget(), static_cast(firstLineEdit)); QMdiSubWindow *window = mdiArea.addSubWindow(new QPushButton); window->show(); @@ -1269,31 +1302,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 +1413,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 +1439,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 +1519,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 +1561,7 @@ void tst_QMdiSubWindow::hideAndShow() // Show QMdiArea. tabWidget->setCurrentIndex(0); - qApp->processEvents(); + QCoreApplication::processEvents(); subWindow = mdiArea->subWindowList().back(); QVERIFY(subWindow); @@ -1544,7 +1581,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 +1620,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 +1658,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 +1697,7 @@ void tst_QMdiSubWindow::explicitlyHiddenWidget() textEdit->show(); subWindow->showMinimized(); - subWindow->setWidget(0); + subWindow->setWidget(nullptr); delete textEdit; textEdit = new QTextEdit; textEdit->hide(); @@ -1670,6 +1710,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 +1720,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 +1731,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 +1790,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 +1845,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 +1855,8 @@ void tst_QMdiSubWindow::replaceMenuBarWhileMaximized() subWindow->showNormal(); QVERIFY(!subWindow->maximizedButtonsWidget()); QVERIFY(!subWindow->maximizedSystemMenuIconWidget()); + delete menuBar1; + delete menuBar3; } void tst_QMdiSubWindow::closeOnDoubleClick_data() @@ -1842,9 +1888,9 @@ void tst_QMdiSubWindow::closeOnDoubleClick() const QRect actionGeometry = systemMenu->actionGeometry(systemMenu->actions().at(actionIndex)); sendMouseDoubleClick(systemMenu, actionGeometry.center()); - if (qApp->activePopupWidget() == static_cast(systemMenu)) + if (QApplication::activePopupWidget() == static_cast(systemMenu)) systemMenu->hide(); - qApp->processEvents(); + QCoreApplication::processEvents(); QVERIFY(!systemMenu || !systemMenu->isVisible()); QCOMPARE(subWindow.isNull() || !subWindow->isVisible(), expectClosed); } @@ -1854,6 +1900,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 +1918,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 +1927,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 +1936,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 +1955,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 +1980,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 +2000,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 +2027,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 +2052,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 +2088,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 +2110,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 +2125,7 @@ void tst_QMdiSubWindow::styleChange() QTest::qWait(100); qRegisterMetaType(); - QSignalSpy spy(&mdiArea, SIGNAL(subWindowActivated(QMdiSubWindow*))); + QSignalSpy spy(&mdiArea, &QMdiArea::subWindowActivated); QVERIFY(spy.isValid()); QEvent event(QEvent::StyleChange); @@ -2085,6 +2140,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 +2157,7 @@ void tst_QMdiSubWindow::testFullScreenState() void tst_QMdiSubWindow::testRemoveBaseWidget() { QMdiArea mdiArea; + mdiArea.setWindowTitle(QLatin1String(QTest::currentTestFunction())); mdiArea.show(); QWidget *widget1 = new QWidget; -- cgit v1.2.3 From 299675e6652e0f5c36c441ba727c68d0f73576b4 Mon Sep 17 00:00:00 2001 From: Friedemann Kleint Date: Mon, 20 May 2019 10:44:06 +0200 Subject: tst_QMdiSubWindow::setSystemMenu(): Pass in High DPI/multi-screen setups The window tends to grow to span screens in multi-screen setups; force it to be on the primary screen by showing it maximized in that case. Change-Id: I984ba7a4cd4abd1f862c59c8dca0e2275f44c724 Reviewed-by: Frederik Gladhorn --- tests/auto/widgets/widgets/qmdisubwindow/tst_qmdisubwindow.cpp | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) (limited to 'tests') diff --git a/tests/auto/widgets/widgets/qmdisubwindow/tst_qmdisubwindow.cpp b/tests/auto/widgets/widgets/qmdisubwindow/tst_qmdisubwindow.cpp index f69b65bdbe..2b59a227b3 100644 --- a/tests/auto/widgets/widgets/qmdisubwindow/tst_qmdisubwindow.cpp +++ b/tests/auto/widgets/widgets/qmdisubwindow/tst_qmdisubwindow.cpp @@ -1014,7 +1014,11 @@ void tst_QMdiSubWindow::setSystemMenu() 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()); -- cgit v1.2.3 From c6bee8e4b2c48775247c67ef8e7569f623655c61 Mon Sep 17 00:00:00 2001 From: Konstantin Shegunov Date: Wed, 1 Aug 2018 00:50:14 +0300 Subject: Fix integer overflows in QDeadlineTimer If the deadline is far in the future, the conversions to nanoseconds or internal arithmetic may overflow and give an invalid object, thus the deadline may end up in the past. Added a test to the testlib selftest for sleep. [ChangeLog][QtCore][QDeadlineTimer] Fixed integer overflows leading to immediate timeouts. Task-number: QTBUG-69750 Change-Id: I9814eccdf9f9b3add9ca66ec3e27e10cd5ad54a8 Reviewed-by: Thiago Macieira --- .../kernel/qdeadlinetimer/tst_qdeadlinetimer.cpp | 79 ++++++++++++++++++++++ .../auto/testlib/selftests/expected_sleep.lightxml | 4 ++ tests/auto/testlib/selftests/expected_sleep.tap | 9 +-- .../auto/testlib/selftests/expected_sleep.teamcity | 2 + tests/auto/testlib/selftests/expected_sleep.txt | 3 +- tests/auto/testlib/selftests/expected_sleep.xml | 4 ++ .../auto/testlib/selftests/expected_sleep.xunitxml | 3 +- tests/auto/testlib/selftests/sleep/tst_sleep.cpp | 19 ++++++ 8 files changed, 117 insertions(+), 6 deletions(-) (limited to 'tests') 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 #include #include +#include #include #if QT_HAS_INCLUDE() @@ -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::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::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::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::max() - 1, std::numeric_limits::max() - 1, timerType); + QCOMPARE(deadline.deadline(), std::numeric_limits::max()); + QVERIFY(deadline.isForever()); + + // Check that remainingTime gets saturated if we overflow + deadline.setPreciseRemainingTime(std::numeric_limits::max() - 1, std::numeric_limits::max() - 1, timerType); + QCOMPARE(deadline.remainingTime(), qint64(-1)); + QVERIFY(deadline.isForever()); + + // Check that we saturate the getter for nanoseconds + deadline.setPreciseDeadline(std::numeric_limits::max() - 1, 0, timerType); + QCOMPARE(deadline.deadlineNSecs(), std::numeric_limits::max()); + + // Check that adding nanoseconds and overflowing is consistent and saturates the timer + deadline = QDeadlineTimer::addNSecs(deadline, std::numeric_limits::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::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::min()); + + // Check that the conversion to milliseconds and nanoseconds underflows gracefully + deadline.setPreciseDeadline(std::numeric_limits::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::min()); + QVERIFY(deadline.deadlineNSecs() == std::numeric_limits::min()); +} + void tst_QDeadlineTimer::expire() { QFETCH_GLOBAL(Qt::TimerType, timerType); 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 @@ + + + + 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 @@ + + + + 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 @@ - + @@ -7,6 +7,7 @@ + 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" -- cgit v1.2.3 From eea6c920c977bd6e506b9983feb5cad854c51695 Mon Sep 17 00:00:00 2001 From: Friedemann Kleint Date: Mon, 20 May 2019 11:11:16 +0200 Subject: Blacklist tst_qwindow::spuriousMouseMove() on Windows MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit The test is failing in 5.13 for unknown reasons. Task-number: QTBUG-72296 Task-number: QTBUG-72344 Change-Id: I24c1ad1b6def3096de99caeeebeee6e204cc75ca Reviewed-by: André de la Rocha Reviewed-by: Oliver Wolff --- tests/auto/gui/kernel/qwindow/BLACKLIST | 2 ++ 1 file changed, 2 insertions(+) (limited to 'tests') 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] -- cgit v1.2.3 From 2a1651cc164b270dac81f4caa1fb8ded4fab6e4b Mon Sep 17 00:00:00 2001 From: Ville Voutilainen Date: Fri, 10 May 2019 16:45:56 +0300 Subject: Make moc grok binary literals with digit separators Task-number: QTBUG-75656 Change-Id: I6011ef2fb07497cc2a055d6828a1b6356927c281 Reviewed-by: Lars Knoll --- tests/auto/tools/moc/tst_moc.cpp | 1 + 1 file changed, 1 insertion(+) (limited to 'tests') diff --git a/tests/auto/tools/moc/tst_moc.cpp b/tests/auto/tools/moc/tst_moc.cpp index 293cbd8323..41bc4bc73b 100644 --- a/tests/auto/tools/moc/tst_moc.cpp +++ b/tests/auto/tools/moc/tst_moc.cpp @@ -524,6 +524,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: -- cgit v1.2.3 From 1e5deb06416b6efc33a2009d9678fd8f743c5ce7 Mon Sep 17 00:00:00 2001 From: Michal Klocek Date: Thu, 2 May 2019 18:02:45 +0200 Subject: Add 'well-formated' JSON string values Add support for surrogate code points U+D800 through U+DFFF, represent them with JSON escape sequences. https://github.com/tc39/proposal-well-formed-stringify Change-Id: I84fea53a8ef400beebefdba10ea82dc510fe7dda Reviewed-by: Thiago Macieira --- .../auto/corelib/serialization/json/tst_qtjson.cpp | 27 +++++++++++++++++++++- 1 file changed, 26 insertions(+), 1 deletion(-) (limited to 'tests') diff --git a/tests/auto/corelib/serialization/json/tst_qtjson.cpp b/tests/auto/corelib/serialization/json/tst_qtjson.cpp index 083e78375a..8907704a33 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; }; @@ -3093,6 +3094,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 +3185,26 @@ void tst_QtJson::streamVariantSerialization() } } +void tst_QtJson::escapeSurrogateCodePoints_data() +{ + QTest::addColumn("str"); + QTest::addColumn("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" -- cgit v1.2.3 From 3b380c8481b134fa80948d1a7af4560744303cbc Mon Sep 17 00:00:00 2001 From: Oliver Wolff Date: Wed, 15 May 2019 10:40:12 +0200 Subject: winrt: Return monospace font for QFontDatabase::systemFont(QFontDatabase::FixedFont) Fixes: QTBUG-75648 Change-Id: I0e5e5e012d3cd5985d1e9a63e776e73ce2d7bf98 Reviewed-by: Friedemann Kleint Reviewed-by: Shawn Rutledge --- tests/auto/gui/text/qfontdatabase/BLACKLIST | 1 - 1 file changed, 1 deletion(-) (limited to 'tests') diff --git a/tests/auto/gui/text/qfontdatabase/BLACKLIST b/tests/auto/gui/text/qfontdatabase/BLACKLIST index 7f479e4b0e..0870ca11d7 100644 --- a/tests/auto/gui/text/qfontdatabase/BLACKLIST +++ b/tests/auto/gui/text/qfontdatabase/BLACKLIST @@ -1,3 +1,2 @@ [systemFixedFont] # QTBUG-54623 -winrt b2qt -- cgit v1.2.3 From d441f6bba7b2aaf1e11b95c1ad4c785e6939f6ba Mon Sep 17 00:00:00 2001 From: Edward Welbourne Date: Tue, 14 May 2019 14:09:59 +0200 Subject: Skip flaky qfloat16 1/inf == 0 test on QEMU/Arm64 It's not clear why this test fails - and only does so sometimes - but fail it does, so we ned to skip it to let development keep going. As it happens, the same platform over-optimizes various computations using qfloat16; which can at least be used to test for this platform, since it wrongly distinguishes two qfloat16 values that theory and all other platfomrs agree should coincide. Fixes: QTBUG-75812 Change-Id: Ie9463d7dc21bca679337b475d13417b9f42bbf9b Reviewed-by: Friedemann Kleint Reviewed-by: Qt CI Bot --- tests/auto/corelib/global/qfloat16/tst_qfloat16.cpp | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) (limited to 'tests') diff --git a/tests/auto/corelib/global/qfloat16/tst_qfloat16.cpp b/tests/auto/corelib/global/qfloat16/tst_qfloat16.cpp index 241dccb90e..aa6f0935e8 100644 --- a/tests/auto/corelib/global/qfloat16/tst_qfloat16.cpp +++ b/tests/auto/corelib/global/qfloat16/tst_qfloat16.cpp @@ -172,7 +172,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 -- cgit v1.2.3 From bd55a9d91227d1ac38f51b21ca23dec7fa5e82af Mon Sep 17 00:00:00 2001 From: Volker Hilsheimer Date: Wed, 11 Mar 2015 14:38:59 +0100 Subject: Fix canonicalFilePath() for files with trailing slashes Such files do not exist (as per QFileInfo::exists), but on some platforms that rely on realpath(), QFileInfo::canonicalFilePath did not return the empty string. Use the same logic on macOS as we already did on Android, and include a test case. Remove the unnecessary dynamic memory allocation and use a stack-allocated array instead, unless we use modern POSIX in which case realpath() will alloc the memory for the result for us. Change-Id: Ide987c68ebf00cbb7b1a66c2e9245a12c7807128 Fixes: QTBUG-44242 Reviewed-by: Lars Knoll --- tests/auto/corelib/io/qfileinfo/tst_qfileinfo.cpp | 2 ++ 1 file changed, 2 insertions(+) (limited to 'tests') diff --git a/tests/auto/corelib/io/qfileinfo/tst_qfileinfo.cpp b/tests/auto/corelib/io/qfileinfo/tst_qfileinfo.cpp index a92b4bd1cb..646fb2078a 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. -- cgit v1.2.3 From 12ebdf0281b341726a01c41bac8e8a960f4b07ce Mon Sep 17 00:00:00 2001 From: Allan Sandfeld Jensen Date: Wed, 15 May 2019 11:13:14 +0200 Subject: Fix new[] delete mismatch in test QScopedPointer uses normal delete, but we need delete[]. Change-Id: Id62a2c55f75ef4aa60580f5e04c4bf306a6dd3c9 Reviewed-by: Thiago Macieira --- tests/auto/corelib/tools/qstringapisymmetry/tst_qstringapisymmetry.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'tests') diff --git a/tests/auto/corelib/tools/qstringapisymmetry/tst_qstringapisymmetry.cpp b/tests/auto/corelib/tools/qstringapisymmetry/tst_qstringapisymmetry.cpp index cb1fd9eb7d..82d58becfe 100644 --- a/tests/auto/corelib/tools/qstringapisymmetry/tst_qstringapisymmetry.cpp +++ b/tests/auto/corelib/tools/qstringapisymmetry/tst_qstringapisymmetry.cpp @@ -1020,7 +1020,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 escaped(QTest::toString(unicode)); + const QScopedArrayPointer escaped(QTest::toString(unicode)); QTest::addRow("%s", escaped.data()) << unicode << QStringRef(&str); } } -- cgit v1.2.3 From aa8d3f90a440575deef914916299b792105d7209 Mon Sep 17 00:00:00 2001 From: Christian Ehrlicher Date: Sun, 21 Apr 2019 13:09:07 +0200 Subject: QAbstractSpinBox: fix some ui glitches Fix some ui glitches for QAbstractSpinBox: - update geometry when buttons are toggled on/off - calc button size with subControlRect instead hardcoded 20px - when buttons are not shown, don't add the button size in sizeFromContents for common and macOS style Fixes: QTBUG-39713 Fixes: QTBUG-75303 Task-number: QTBUG-67126 Change-Id: Ibf330c76deb16358a481bba6bd429fff6a5d57ae Reviewed-by: Richard Moe Gustavsen --- .../widgets/widgets/qdoublespinbox/tst_qdoublespinbox.cpp | 12 +++++++----- tests/auto/widgets/widgets/qspinbox/tst_qspinbox.cpp | 14 +++++++++----- 2 files changed, 16 insertions(+), 10 deletions(-) (limited to 'tests') 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/qspinbox/tst_qspinbox.cpp b/tests/auto/widgets/widgets/qspinbox/tst_qspinbox.cpp index 803b72f36e..52d7dad7cf 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); } -- cgit v1.2.3 From 923e08132cfd0c9140e705a7f0f27b3432f94695 Mon Sep 17 00:00:00 2001 From: Marc Mutz Date: Sun, 17 Dec 2017 01:05:14 +0100 Subject: tst_QActionGroup: avoid Java-style iterators They are going to be deprecated soon. Use a lambda to mimic the adjacent addActions() calls. Also, I didn't want to add a scope or extend the lifetime of the return value of actions() until the end of the function, and for (QAction *action : actGroup.action()) would detach. I'd've made it a helper function, but it's used only once, so... a lambda. Change-Id: I2b3aae463036fd61a9cca7b4ef991b8752869bf3 Reviewed-by: Giuseppe D'Angelo --- .../widgets/kernel/qactiongroup/tst_qactiongroup.cpp | 16 +++++++--------- 1 file changed, 7 insertions(+), 9 deletions(-) (limited to 'tests') 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 it(actGroup.actions()); - while (it.hasNext()) - menu.addAction(it.next()); + menu.addActions(actGroup.actions()); QCOMPARE((int)menu.actions().size(), 2); - it = QListIterator(actGroup.actions()); - while (it.hasNext()) - menu.removeAction(it.next()); + const auto removeActions = [&menu](const QList &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(actGroup.actions()); - while (it.hasNext()) - menu.addAction(it.next()); + menu.addActions(actGroup.actions()); QCOMPARE((int)menu.actions().size(), 3); } -- cgit v1.2.3 From 90243aebb653f67a3898fff2f9feec9dca2ded5d Mon Sep 17 00:00:00 2001 From: Shawn Rutledge Date: Sun, 19 May 2019 13:33:27 +0200 Subject: QTextBrowser: set base URL and document URL before loading content setHtml() or setMarkdown() can result in attempting to load resources such as images that are needed to render the page. Whenever the resource has a relative URL, loading depends on the baseURL having already been set so that a complete URL can be constructed. QTextDocument::resource() is called to load images, and uses baseUrl(). A little later, QTextBrowserPrivate::resolveUrl() is given an URL that already has been extended with the baseURL if known; but it has its own logic to resolve the resource URL against currentURL, or else to treat it as a local file path if a file exists at that location. The autotest was relying on this fallback to the local relative file path before; but now it tests both with a local filename in the current directory for the source HTML and also with a fully resolved source URL containing the complete file path. Also made minor style improvements in tst_QTextBrowser's TestBrowser class. Change-Id: I46a850015d0e9c5bc5f13b9e37179a9323ab1980 Reviewed-by: Simon Hausmann --- .../widgets/qtextbrowser/tst_qtextbrowser.cpp | 21 +++++++++++++++------ 1 file changed, 15 insertions(+), 6 deletions(-) (limited to 'tests') 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() -- cgit v1.2.3 From c9b7cc349a13b722ecd636ec4eb8e21f9f712add Mon Sep 17 00:00:00 2001 From: Joerg Bornemann Date: Thu, 23 May 2019 13:51:05 +0200 Subject: Remove usages of Q_OS_WINCE This platform is history. Change-Id: Iddfab008a509f4828c321730414c8204055cf7af Reviewed-by: Maurice Kalinowski --- tests/auto/corelib/io/qstandardpaths/tst_qstandardpaths.cpp | 6 +++--- tests/auto/network/socket/qtcpserver/crashingServer/main.cpp | 4 ++-- tests/auto/widgets/widgets/qmenubar/tst_qmenubar.cpp | 3 --- tests/shared/filesystem.h | 2 +- 4 files changed, 6 insertions(+), 9 deletions(-) (limited to 'tests') 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 #include #include -#if defined(Q_OS_WIN) && !defined(Q_OS_WINRT) && !defined(Q_OS_WINCE) +#if defined(Q_OS_WIN) && !defined(Q_OS_WINRT) # include #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/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 #include -#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 #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/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/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 { -- cgit v1.2.3 From cf909f0ef609c4581ebbe2f81c7ae0c5e43d653f Mon Sep 17 00:00:00 2001 From: Edward Welbourne Date: Wed, 22 May 2019 15:30:27 +0200 Subject: Tidy up in tst_QDateTime Use QCOMPARE rather than QVERIFY an equality; ditch a stray blank line. Change-Id: Ie828837919fb9d3cc774d82d0eebcf7728fed645 Reviewed-by: Thiago Macieira --- tests/auto/corelib/tools/qdatetime/tst_qdatetime.cpp | 15 +++++++-------- 1 file changed, 7 insertions(+), 8 deletions(-) (limited to 'tests') diff --git a/tests/auto/corelib/tools/qdatetime/tst_qdatetime.cpp b/tests/auto/corelib/tools/qdatetime/tst_qdatetime.cpp index 38b72ab91f..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/ ** @@ -1005,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 @@ -2776,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); } @@ -2790,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); } } -- cgit v1.2.3 From 7efce5d5100dc0fddba36fba2ecb5a6c5e9cae37 Mon Sep 17 00:00:00 2001 From: Edward Welbourne Date: Wed, 22 May 2019 15:00:58 +0200 Subject: Add a bench-mark for QDate's isValid() and daysInMonth() The two perform related calculations, so test them together. RESULT : tst_QDate::monthLengths(): 0.33 msecs per iteration (total: 87, iterations: 256) Change-Id: I86b36a9182b00c0a1f40e858ed3e7812434974c4 Reviewed-by: Volker Hilsheimer Reviewed-by: Thiago Macieira --- tests/benchmarks/corelib/tools/qdate/qdate.pro | 4 ++ .../corelib/tools/qdate/tst_bench_qdate.cpp | 53 ++++++++++++++++++++++ 2 files changed, 57 insertions(+) create mode 100644 tests/benchmarks/corelib/tools/qdate/qdate.pro create mode 100644 tests/benchmarks/corelib/tools/qdate/tst_bench_qdate.cpp (limited to 'tests') 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 +#include + +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" -- cgit v1.2.3 From d2c478243264296824d4713c71a9e2633186b5df Mon Sep 17 00:00:00 2001 From: Friedemann Kleint Date: Fri, 24 May 2019 10:07:29 +0200 Subject: =?UTF-8?q?tst=5FQVariant:=20Fix=20warnings=20about=20deprecated?= =?UTF-8?q?=20functions=20not=20under=20test=20=E2=80=94?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Silence a warnings flood about qVariantFromValue(), QString::null and QWeakPointer::data(). Change-Id: I73347190c0fa396b39b9efd00447cf24e48259a0 Reviewed-by: Volker Hilsheimer --- .../auto/corelib/kernel/qvariant/tst_qvariant.cpp | 505 +++++++++++---------- 1 file changed, 258 insertions(+), 247 deletions(-) (limited to 'tests') 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::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::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::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 sp(f); +QT_WARNING_POP QVariant spVar = QVariant::fromValue(sp); QVERIFY(spVar.canConvert()); QCOMPARE(f, spVar.value()); @@ -3945,7 +3956,7 @@ void tst_QVariant::userConversion() QVERIFY(!(QMetaType::hasRegisteredConverterFunction())); 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())); BigConvertible c = { 123, 0, 0 }; - QVariant v = qVariantFromValue(c); + QVariant v = QVariant::fromValue(c); bool ok; v.toInt(&ok); -- cgit v1.2.3 From bf207acb3440da36ef972992dc105691c8c4cb79 Mon Sep 17 00:00:00 2001 From: Friedemann Kleint Date: Thu, 23 May 2019 13:55:23 +0200 Subject: Tests: Fix some warnings about deprecated functions not under test MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Fix warnings like: baselineserver/shared/baselineprotocol.cpp:295:72: warning: ‘int QImage::byteCount() const’ is deprecated: Use sizeInBytes [-Wdeprecated-declarations] tst_qnetworkreply.cpp:1560:17: warning: ‘static QList QSslSocket::defaultCaCertificates()’ is deprecated [-Wdeprecated-declarations] tst_qnetworkreply.cpp:1560:39: warning: ‘static QList QSslSocket::defaultCaCertificates()’ is deprecated [-Wdeprecated-declarations] tst_qnetworkreply.cpp:8153:60: warning: ‘T* QWeakPointer::data() const [with T = const QNetworkSession]’ is deprecated: Use toStrongRef() instead, and data() on the returned QSharedPointer [-Wdeprecated-declarations]. ... st_qprinter.cpp:1318:74: warning: ‘QList QPrinterInfo::supportedPaperSizes() const’ is deprecated [-Wdeprecated-declarations] tst_qprinter.cpp:1362:74: warning: ‘QList QPrinterInfo::supportedPaperSizes() const’ is deprecated [-Wdeprecated-declarations] tst_largefile.cpp:492:85: warning: ‘bool qEqual(InputIterator1, InputIterator1, InputIterator2) [with InputIterator1 = char*; InputIterator2 = char*]’ is deprecated: Use std::equal [-Wdeprecated-declarations] tst_largefile.cpp:498:91: warning: ‘bool qEqual(InputIterator1, InputIterator1, InputIterator2) [with InputIterator1 = char*; InputIterator2 = char*]’ is deprecated: Use std::equal [-Wdeprecated-declarations] tst_qabstractitemmodel.cpp:312:25: warning: ‘void QAbstractItemModel::reset()’ is deprecated [-Wdeprecated-declarations] ... tst_qabstractitemmodel.cpp:1793:28: warning: ‘void QAbstractItemModel::setRoleNames(const QHash&)’ is deprecated [-Wdeprecated-declarations] ... tst_qcolor.cpp:1425:33: warning: ‘QColor QColor::light(int) const’ is deprecated: Use QColor::lighter() instead [-Wdeprecated-declarations] tst_qcolor.cpp:1432:31: warning: ‘QColor QColor::dark(int) const’ is deprecated: Use QColor::darker() instead [-Wdeprecated-declarations] tst_qprinterinfo.cpp:303:61: warning: 'QList QPrinterInfo::supportedPaperSizes() const' is deprecated [-Wdeprecated-declarations] tst_qprinterinfo.cpp:304:65: warning: 'QList > QPrinterInfo::supportedSizesWithNames() const' is deprecated [-Wdeprecated-declarations] tst_qtextdocumentfragment.cpp:947:52: warning: ‘QString QTextCharFormat::anchorName() const’ is deprecated: Use anchorNames() instead [-Wdeprecated-declarations] tst_qtextlayout.cpp:2261:61: warning: ‘void QTextLayout::setAdditionalFormats(const QList&)’ is deprecated: Use setFormats() [-Wdeprecated-declarations] tst_qtextlayout.cpp:2330:42: warning: ‘int QFontMetrics::width(const QString&, int) const’ is deprecated: Use QFontMetrics::horizontalAdvance [-Wdeprecated-declarations] tst_qitemselectionmodel.cpp:2214:37: warning: ‘QModelIndex QModelIndex::child(int, int) const’ is deprecated: Use QAbstractItemModel::index [-Wdeprecated-declarations] ... tst_qtextlist.cpp:317:68: warning: 'bool QTextList::isEmpty() const' is deprecated: Use count() instead [-Wdeprecated-declarations] tst_qpainter.cpp:373:32: warning: ‘void QPainter::setMatrixEnabled(bool)’ is deprecated: Use setWorldMatrixEnabled() instead [-Wdeprecated-declarations] tst_qpainter.cpp:374:40: warning: ‘bool QPainter::matrixEnabled() const’ is deprecated: Use worldMatrixEnabled() instead [-Wdeprecated-declarations] tst_qpainter.cpp:702:45: warning: ‘const QBrush& QPalette::background() const’ is deprecated: Use QPalette::window() instead [-Wdeprecated-declarations] tst_qpainter.cpp:1573:29: warning: ‘void QPainter::drawRoundRect(const QRect&, int, int)’ is deprecated: Use drawRoundedRect(..., Qt::RelativeSize) instead [-Wdeprecated-declarations] tst_qpdfwriter.cpp:76:38: warning: ‘virtual void QPdfWriter::setPageSize(QPagedPaintDevice::PageSize)’ is deprecated: Use setPageSize(QPageSize(id)) instead [-Wdeprecated-declarations] tst_qpdfwriter.cpp:81:41: warning: ‘virtual void QPdfWriter::setPageSizeMM(const QSizeF&)’ is deprecated: Use setPageSize(QPageSize(size, QPageSize::Millimeter)) instead [-Wdeprecated-declarations] tst_qpdfwriter.cpp:105:30: warning: ‘virtual void QPdfWriter::setMargins(const QPagedPaintDevice::Margins&)’ is deprecated: Use setPageMargins(QMarginsF(l, t, r, b), QPageLayout::Millimeter) instead [-Wdeprecated-declarations] tst_qpdfwriter.cpp:172:37: warning: ‘virtual void QPdfWriter::setPageSizeMM(const QSizeF&)’ is deprecated: Use setPageSize(QPageSize(size, QPageSize::Millimeter)) instead [-Wdeprecated-declarations] tst_qpdfwriter.cpp:258:38: warning: ‘virtual void QPdfWriter::setPageSize(QPagedPaintDevice::PageSize)’ is deprecated: Use setPageSize(QPageSize(id)) instead [-Wdeprecated-declarations] qsortfilterproxymodel_common/tst_qsortfilterproxymodel.cpp:3980:54: warning: ‘QModelIndex QModelIndex::child(int, int) const’ is deprecated: Use QAbstractItemModel::index [-Wdeprecated-declarations] tst_qlocale.cpp:434:26: warning: 'QString::null' is deprecated: use QString() [-Wdeprecated-declarations] ... Change-Id: I77c1a934b27119eedeb26a77c913686314a2a5c7 Reviewed-by: David Faure --- tests/auto/corelib/io/largefile/tst_largefile.cpp | 5 +-- .../qabstractitemmodel/tst_qabstractitemmodel.cpp | 16 ++++----- .../tst_qabstractproxymodel.cpp | 20 ++++++------ .../tst_qitemselectionmodel.cpp | 8 ++--- .../tst_qsortfilterproxymodel.cpp | 2 +- tests/auto/corelib/tools/qlocale/tst_qlocale.cpp | 3 +- tests/auto/gui/painting/qcolor/tst_qcolor.cpp | 12 +++---- tests/auto/gui/painting/qpainter/tst_qpainter.cpp | 12 +++---- .../gui/painting/qpdfwriter/tst_qpdfwriter.cpp | 13 +++----- .../tst_qtextdocumentfragment.cpp | 2 +- .../auto/gui/text/qtextlayout/tst_qtextlayout.cpp | 11 ++----- tests/auto/gui/text/qtextlist/tst_qtextlist.cpp | 2 +- .../access/qnetworkreply/tst_qnetworkreply.cpp | 38 ++++++++++++---------- .../printsupport/kernel/qprinter/tst_qprinter.cpp | 8 +++-- .../kernel/qprinterinfo/tst_qprinterinfo.cpp | 10 ++++-- tests/baselineserver/shared/baselineprotocol.cpp | 3 +- 16 files changed, 85 insertions(+), 80 deletions(-) (limited to 'tests') 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 +#include #include #include @@ -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(baseAddress)) ); + QVERIFY( std::equal(block.begin(), block.end(), reinterpret_cast(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(address)) ) { + if ( !std::equal(block.begin() + offset, block.end(), reinterpret_cast(address)) ) { qDebug() << "Expected:" << block.toHex(); qDebug() << "Actual :" << QByteArray(reinterpret_cast(address), blockSize).toHex(); QVERIFY(false); 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 roleNames_ = roleNames(); - roleNames_.insert(Qt::UserRole + 1, "custom"); - setRoleNames(roleNames_); - } + using QStringListModel::QStringListModel; + + QHash 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 _roleNames = roleNames(); - _roleNames.insert(CustomRole1, "custom1"); - _roleNames.insert(CustomRole2, "custom2"); - setRoleNames(_roleNames); + QHash 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 _roleNames = roleNames(); - _roleNames.insert(AnotherCustomRole1, "another_custom1"); - _roleNames.insert(AnotherCustomRole2, "another_custom2"); - setRoleNames(_roleNames); + QHash 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/tools/qlocale/tst_qlocale.cpp b/tests/auto/corelib/tools/qlocale/tst_qlocale.cpp index be2e2a2e08..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) 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/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/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/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 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 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/network/access/qnetworkreply/tst_qnetworkreply.cpp b/tests/auto/network/access/qnetworkreply/tst_qnetworkreply.cpp index 43739be4a3..550d80501e 100644 --- a/tests/auto/network/access/qnetworkreply/tst_qnetworkreply.cpp +++ b/tests/auto/network/access/qnetworkreply/tst_qnetworkreply.cpp @@ -1557,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); @@ -8148,16 +8148,17 @@ void tst_QNetworkReply::backgroundRequest() SLOT(sslErrors(QNetworkReply*,QList))); #endif - const QWeakPointer session = QNetworkAccessManagerPrivate::getNetworkSession(&manager); - QVERIFY(session); - QNetworkSession::UsagePolicies original = session.data()->usagePolicies(); - QNetworkSessionPrivate::setUsagePolicies(*const_cast(session.data()), QNetworkSession::UsagePolicies(policy)); + const QWeakPointer sessionWeakPtr = QNetworkAccessManagerPrivate::getNetworkSession(&manager); + QVERIFY(!sessionWeakPtr.isNull()); + auto session = const_cast(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(session.data()), original); + QNetworkSessionPrivate::setUsagePolicies(*session, original); QVERIFY(reply->isFinished()); QCOMPARE(reply->error(), error); @@ -8212,10 +8213,11 @@ void tst_QNetworkReply::backgroundRequestInterruption() SLOT(sslErrors(QNetworkReply*,QList))); #endif - const QWeakPointer session = QNetworkAccessManagerPrivate::getNetworkSession(&manager); - QVERIFY(session); - QNetworkSession::UsagePolicies original = session.data()->usagePolicies(); - QNetworkSessionPrivate::setUsagePolicies(*const_cast(session.data()), QNetworkSession::NoPolicy); + const QWeakPointer sessionWeakPtr = QNetworkAccessManagerPrivate::getNetworkSession(&manager); + QVERIFY(!sessionWeakPtr.isNull()); + auto session = const_cast(sessionWeakPtr.toStrongRef().data()); + QNetworkSession::UsagePolicies original = session->usagePolicies(); + QNetworkSessionPrivate::setUsagePolicies(*session, QNetworkSession::NoPolicy); request.setAttribute(QNetworkRequest::MaximumDownloadBufferSizeAttribute, 8192); QNetworkReplyPtr reply(manager.get(request)); @@ -8224,14 +8226,14 @@ void tst_QNetworkReply::backgroundRequestInterruption() QSignalSpy spy(reply.data(), SIGNAL(readyRead())); QTRY_VERIFY(spy.count() > 0); - QNetworkSessionPrivate::setUsagePolicies(*const_cast(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(session.data()), original); + QNetworkSessionPrivate::setUsagePolicies(*session, original); QVERIFY(reply->isFinished()); QCOMPARE(reply->error(), error); @@ -8271,8 +8273,8 @@ void tst_QNetworkReply::backgroundRequestConnectInBackground() QWeakPointer session = QNetworkAccessManagerPrivate::getNetworkSession(&manager); //force QNAM to reopen the session. - if (session && session.data()->isOpen()) { - const_cast(session.data())->close(); + if (session && session.toStrongRef().data()->isOpen()) { + const_cast(session.toStrongRef().data())->close(); QCoreApplication::processEvents(); //let signals propagate inside QNAM } @@ -8281,19 +8283,19 @@ void tst_QNetworkReply::backgroundRequestConnectInBackground() session = QNetworkAccessManagerPrivate::getNetworkSession(&manager); QVERIFY(session); - QNetworkSession::UsagePolicies original = session.data()->usagePolicies(); - QNetworkSessionPrivate::setUsagePolicies(*const_cast(session.data()), QNetworkSession::NoPolicy); + QNetworkSession::UsagePolicies original = session.toStrongRef().data()->usagePolicies(); + QNetworkSessionPrivate::setUsagePolicies(*const_cast(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(session.data()), original); + QNetworkSessionPrivate::setUsagePolicies(*const_cast(session.toStrongRef().data()), original); } else { QSKIP("inconclusive - network session has been destroyed"); } 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/baselineserver/shared/baselineprotocol.cpp b/tests/baselineserver/shared/baselineprotocol.cpp index 6357024341..aa496d6c54 100644 --- a/tests/baselineserver/shared/baselineprotocol.cpp +++ b/tests/baselineserver/shared/baselineprotocol.cpp @@ -292,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(image.constBits()), + int(image.sizeInBytes())); //# can be followed by colormap for formats that use it } -- cgit v1.2.3 From 7224d0e427d71e559b928c44634839b4791c1416 Mon Sep 17 00:00:00 2001 From: Shawn Rutledge Date: Mon, 13 May 2019 12:58:37 +0200 Subject: QTextMarkdownImporter: don't keep heading level on following list item When reading a document like # heading - list item and then re-writing it, it turned into # heading - # list item because QTextCursor::insertList() simply calls QTextCursor::insertBlock(), thus inheriting block format from the previous block, without an opportunity to explicitly define the block format. So be more consistent: use QTextMarkdownImporter::insertBlock() for blocks inside list items too. Now it fully defines blockFormat first, then inserts the block, and then adds it to the current list only when the "paragraph" is actually the list item's text (but not when it's a continuation paragraph). Also, be prepared for applying and removing block markers to arbitrary blocks, just in case (they might be useful for block quotes, for example). Change-Id: I391820af9b65e75abce12abab45d2477c49c86ac Reviewed-by: Gatis Paeglis --- .../gui/text/qtextmarkdownwriter/data/headingsAndLists.md | 12 ++++++++++++ .../gui/text/qtextmarkdownwriter/tst_qtextmarkdownwriter.cpp | 1 + 2 files changed, 13 insertions(+) create mode 100644 tests/auto/gui/text/qtextmarkdownwriter/data/headingsAndLists.md (limited to 'tests') diff --git a/tests/auto/gui/text/qtextmarkdownwriter/data/headingsAndLists.md b/tests/auto/gui/text/qtextmarkdownwriter/data/headingsAndLists.md new file mode 100644 index 0000000000..d5d14fb168 --- /dev/null +++ b/tests/auto/gui/text/qtextmarkdownwriter/data/headingsAndLists.md @@ -0,0 +1,12 @@ +# heading 1 + +- list item 1 +- list item 2 + +## heading 2 + +1) list item 1 +2) list item 2 + +the end paragraph + diff --git a/tests/auto/gui/text/qtextmarkdownwriter/tst_qtextmarkdownwriter.cpp b/tests/auto/gui/text/qtextmarkdownwriter/tst_qtextmarkdownwriter.cpp index 9998794762..b14e810430 100644 --- a/tests/auto/gui/text/qtextmarkdownwriter/tst_qtextmarkdownwriter.cpp +++ b/tests/auto/gui/text/qtextmarkdownwriter/tst_qtextmarkdownwriter.cpp @@ -357,6 +357,7 @@ void tst_QTextMarkdownWriter::rewriteDocument_data() QTest::newRow("block quotes") << "blockquotes.md"; QTest::newRow("example") << "example.md"; + QTest::newRow("list items after headings") << "headingsAndLists.md"; } void tst_QTextMarkdownWriter::rewriteDocument() -- cgit v1.2.3 From 280d679c556ab8ead4748a627d7cd4c1950027fb Mon Sep 17 00:00:00 2001 From: Shawn Rutledge Date: Mon, 20 May 2019 11:50:26 +0200 Subject: QTextMarkdownWriter: fix some bad cases with word wrap If any non-breakable content (such as a link) already went past 80 columns, or if a word ended on column 80, it didn't wrap the rest of the paragraph following. Change-Id: I27dc0474f18892c34ee2514ea6d5070dae29424f Reviewed-by: Gatis Paeglis --- tests/auto/gui/text/qtextmarkdownwriter/data/blockquotes.md | 3 ++- tests/auto/gui/text/qtextmarkdownwriter/data/wordWrap.md | 13 +++++++++++++ .../text/qtextmarkdownwriter/tst_qtextmarkdownwriter.cpp | 1 + 3 files changed, 16 insertions(+), 1 deletion(-) create mode 100644 tests/auto/gui/text/qtextmarkdownwriter/data/wordWrap.md (limited to 'tests') diff --git a/tests/auto/gui/text/qtextmarkdownwriter/data/blockquotes.md b/tests/auto/gui/text/qtextmarkdownwriter/data/blockquotes.md index f429fcc21b..44c198fdc5 100644 --- a/tests/auto/gui/text/qtextmarkdownwriter/data/blockquotes.md +++ b/tests/auto/gui/text/qtextmarkdownwriter/data/blockquotes.md @@ -13,7 +13,8 @@ MacFarlane writes: > > 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/)) +> > [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 diff --git a/tests/auto/gui/text/qtextmarkdownwriter/data/wordWrap.md b/tests/auto/gui/text/qtextmarkdownwriter/data/wordWrap.md new file mode 100644 index 0000000000..dacb0acf77 --- /dev/null +++ b/tests/auto/gui/text/qtextmarkdownwriter/data/wordWrap.md @@ -0,0 +1,13 @@ +[The CommonMark Specification](https://spec.commonmark.org/0.29/) is the +conservative formal specification of the Markdown format, while +[GitHub Flavored Markdown](https://guides.github.com/features/mastering-markdown/#GitHub-flavored-markdown) +adds extra features such as task lists and tables. + +Qt owes thanks to the authors of the [MD4C parser](https://github.com/mity/md4c) +for making markdown import possible. The QTextMarkdownWriter class does not +have such dependencies, and also has not yet been tested as extensively, so we +do not yet guarantee that we are able to rewrite every Markdown document that +you are able to read and display with Text or QTextEdit. But you are free to +write [bugs](https://bugreports.qt.io) about any troublesome cases that you +encounter. + diff --git a/tests/auto/gui/text/qtextmarkdownwriter/tst_qtextmarkdownwriter.cpp b/tests/auto/gui/text/qtextmarkdownwriter/tst_qtextmarkdownwriter.cpp index b14e810430..acc74a9060 100644 --- a/tests/auto/gui/text/qtextmarkdownwriter/tst_qtextmarkdownwriter.cpp +++ b/tests/auto/gui/text/qtextmarkdownwriter/tst_qtextmarkdownwriter.cpp @@ -358,6 +358,7 @@ void tst_QTextMarkdownWriter::rewriteDocument_data() QTest::newRow("block quotes") << "blockquotes.md"; QTest::newRow("example") << "example.md"; QTest::newRow("list items after headings") << "headingsAndLists.md"; + QTest::newRow("word wrap") << "wordWrap.md"; } void tst_QTextMarkdownWriter::rewriteDocument() -- cgit v1.2.3 From 4469e36d7203a55a4e158a50f0e9effc3f2fa3c2 Mon Sep 17 00:00:00 2001 From: Marc Mutz Date: Wed, 15 May 2019 14:04:11 +0200 Subject: qhashfunctions.h: add specializations of std::hash for some Qt types MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit We have a problem. Our types don't play well with the std unordered containers, because they do not specialize std::hash. We therefore force our users to come up with an implementation, hindering interoperability, since any two developers are unlikely to come up with compatible implementations. So combining libraries written by different developers will result in ODR violations. Now that we depend on C++11, and thus the presence of std::hash, we still face the problem that the standard does not provide us with a means to compose new hash functions out of old ones. In particular, we cannot, yet, depend on C++17's std::hash to implement std::hash, say. There's also no std::hash for std::tuple, which would allow easy composition by using std::tie(). So piggy-back on the work we have done over the years on qHash() functions, and implement the std::hash specializations for Qt types using the existing qHash() functions, with a twist: The standard allows implementations to provide means against predictable hash values. Qt has this, too, but the seed is managed by the container and passed to the qHash() function as a separate argument. The standard does not have this explicit seed, so any protection must be implicit in the normal use of std::hash. To reap whatever protection that std library has on offer, if any, we calculate a seed value by hashing int(0). This will be subject to constant folding if there's no actual seed, but will produce a value dependent on the seed if there is one. Add some tests. A question that remains is how to document the specialization. Can we have a \stdhashable QDoc macro that does everything for us? Task-number: QTBUG-33428 Change-Id: Idfe775f1661f8489587353c4b148d76611ac76f3 Reviewed-by: Mårten Nordheim Reviewed-by: Qt CI Bot --- .../tools/qhashfunctions/tst_qhashfunctions.cpp | 36 ++++++++++++++++++++++ 1 file changed, 36 insertions(+) (limited to 'tests') diff --git a/tests/auto/corelib/tools/qhashfunctions/tst_qhashfunctions.cpp b/tests/auto/corelib/tools/qhashfunctions/tst_qhashfunctions.cpp index 124e3cdf00..f76f3aa0c6 100644 --- a/tests/auto/corelib/tools/qhashfunctions/tst_qhashfunctions.cpp +++ b/tests/auto/corelib/tools/qhashfunctions/tst_qhashfunctions.cpp @@ -34,6 +34,8 @@ #include #include +#include + class tst_QHashFunctions : public QObject { Q_OBJECT @@ -59,6 +61,8 @@ private Q_SLOTS: void range(); void rangeCommutative(); + void stdHash(); + void setGlobalQHashSeed(); }; @@ -281,6 +285,38 @@ void tst_QHashFunctions::rangeCommutative() (void)qHashRangeCommutative(hashables, hashables + numHashables, seed); } +void tst_QHashFunctions::stdHash() +{ + { + std::unordered_set s = {QStringLiteral("Hello"), QStringLiteral("World")}; + QCOMPARE(s.size(), 2UL); + s.insert(QStringLiteral("Hello")); + QCOMPARE(s.size(), 2UL); + } + + { + std::unordered_set s = {QStringLiteral("Hello"), QStringLiteral("World")}; + QCOMPARE(s.size(), 2UL); + s.insert(QStringLiteral("Hello")); + QCOMPARE(s.size(), 2UL); + } + + { + std::unordered_set s = {QLatin1String("Hello"), QLatin1String("World")}; + QCOMPARE(s.size(), 2UL); + s.insert(QLatin1String("Hello")); + QCOMPARE(s.size(), 2UL); + } + + { + std::unordered_set s = {QByteArrayLiteral("Hello"), QByteArrayLiteral("World")}; + QCOMPARE(s.size(), 2UL); + s.insert(QByteArray("Hello")); + QCOMPARE(s.size(), 2UL); + } + +} + void tst_QHashFunctions::setGlobalQHashSeed() { // Setter works as advertised -- cgit v1.2.3 From 341c8b9cd08c1cd863cf8581a825561a2862fce2 Mon Sep 17 00:00:00 2001 From: David Faure Date: Wed, 15 May 2019 15:28:18 +0200 Subject: QCommandLineParser: add --help-all, to show Qt options as well MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Sample output at http://www.kdab.com/~dfaure/2019/help-all-example.txt Fixes: QTBUG-41802 Change-Id: I7a3350200761d41481fcb10ec4328e96e548d246 Reviewed-by: André Hartmann Reviewed-by: Thiago Macieira --- .../qcommandlineparser/tst_qcommandlineparser.cpp | 67 ++++++++++++++++++++-- 1 file changed, 62 insertions(+), 5 deletions(-) (limited to 'tests') diff --git a/tests/auto/corelib/tools/qcommandlineparser/tst_qcommandlineparser.cpp b/tests/auto/corelib/tools/qcommandlineparser/tst_qcommandlineparser.cpp index de51c866e1..1e87c76d2f 100644 --- a/tests/auto/corelib/tools/qcommandlineparser/tst_qcommandlineparser.cpp +++ b/tests/auto/corelib/tools/qcommandlineparser/tst_qcommandlineparser.cpp @@ -76,6 +76,8 @@ private slots: void testHelpOption(); void testQuoteEscaping(); void testUnknownOption(); + void testHelpAll_data(); + void testHelpAll(); }; static char *empty_argv[] = { 0 }; @@ -542,7 +544,8 @@ void tst_QCommandLineParser::testVersionOption() static const char expectedOptionsHelp[] = "Options:\n" - " -h, --help Displays this help.\n" + " -h, --help Displays help on commandline options.\n" + " --help-all Displays help including Qt specific options.\n" " -v, --version Displays version information.\n" " --load Load file from URL.\n" " -o, --output Set output file.\n" @@ -576,8 +579,8 @@ void tst_QCommandLineParser::testHelpOption_data() " parsingMode The parsing mode to test.\n" " command The command to execute.\n"); #ifdef Q_OS_WIN - expectedOutput.replace(" -h, --help Displays this help.\n", - " -?, -h, --help Displays this help.\n"); + expectedOutput.replace(" -h, --help Displays help on commandline options.\n", + " -?, -h, --help Displays help on commandline options.\n"); expectedOutput.replace("testhelper/", "testhelper\\"); #endif @@ -625,8 +628,8 @@ void tst_QCommandLineParser::testHelpOption() "Arguments:\n" " resize Resize the object to a new size.\n"; #ifdef Q_OS_WIN - expectedResizeHelp.replace(" -h, --help Displays this help.\n", - " -?, -h, --help Displays this help.\n"); + expectedResizeHelp.replace(" -h, --help Displays help on commandline options.\n", + " -?, -h, --help Displays help on commandline options.\n"); expectedResizeHelp.replace("testhelper/", "testhelper\\"); #endif QCOMPARE(output, QString(expectedResizeHelp)); @@ -680,6 +683,60 @@ void tst_QCommandLineParser::testUnknownOption() #endif // QT_CONFIG(process) } +void tst_QCommandLineParser::testHelpAll_data() +{ + QTest::addColumn("parsingMode"); + QTest::addColumn("expectedHelpOutput"); + + QString expectedOutput = QString::fromLatin1( + "Usage: testhelper/qcommandlineparser_test_helper [options] parsingMode command\n" + "Test helper\n" + "\n") + + QString::fromLatin1(expectedOptionsHelp) + + QString::fromLatin1( + " --qmljsdebugger Activates the QML/JS debugger with a specified\n" + " port. The value must be of format\n" + " port:1234[,block]. \"block\" makes the application\n" + " wait for a connection.\n" + "\n" + "Arguments:\n" + " parsingMode The parsing mode to test.\n" + " command The command to execute.\n"); +#ifdef Q_OS_WIN + expectedOutput.replace(" -h, --help Displays help on commandline options.\n", + " -?, -h, --help Displays help on commandline options.\n"); + expectedOutput.replace("testhelper/", "testhelper\\"); +#endif + + QTest::newRow("collapsed") << QCommandLineParser::ParseAsCompactedShortOptions << expectedOutput; + QTest::newRow("long") << QCommandLineParser::ParseAsLongOptions << expectedOutput; +} + +void tst_QCommandLineParser::testHelpAll() +{ +#if !QT_CONFIG(process) + QSKIP("This test requires QProcess support"); +#else +#if defined(Q_OS_ANDROID) && !defined(Q_OS_ANDROID_EMBEDDED) + QSKIP("Deploying executable applications to file system on Android not supported."); +#endif + + QFETCH(QCommandLineParser::SingleDashWordOptionMode, parsingMode); + QFETCH(QString, expectedHelpOutput); + QCoreApplication app(empty_argc, empty_argv); + QProcess process; + process.start("testhelper/qcommandlineparser_test_helper", QStringList() << QString::number(parsingMode) << "--help-all"); + QVERIFY(process.waitForFinished(5000)); + QCOMPARE(process.exitStatus(), QProcess::NormalExit); + QString output = process.readAll(); +#ifdef Q_OS_WIN + output.replace(QStringLiteral("\r\n"), QStringLiteral("\n")); +#endif + QCOMPARE(output.split('\n'), expectedHelpOutput.split('\n')); // easier to debug than the next line, on failure + QCOMPARE(output, expectedHelpOutput); +#endif // QT_CONFIG(process) +} + QTEST_APPLESS_MAIN(tst_QCommandLineParser) #include "tst_qcommandlineparser.moc" -- cgit v1.2.3 From a5b373e0db45a28c133bf413e00f15271aa20200 Mon Sep 17 00:00:00 2001 From: Shawn Rutledge Date: Sat, 1 Jun 2019 17:11:42 +0200 Subject: tst_qtextbrowser: add markdown test data to TESTDATA It's necessary to make the test pass on certain platforms. Change-Id: I717d492df437c0ffb75b21d9ef23ce602160fad1 Reviewed-by: Shawn Rutledge --- tests/auto/widgets/widgets/qtextbrowser/qtextbrowser.pro | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'tests') diff --git a/tests/auto/widgets/widgets/qtextbrowser/qtextbrowser.pro b/tests/auto/widgets/widgets/qtextbrowser/qtextbrowser.pro index 9680ffd871..05c156bf59 100644 --- a/tests/auto/widgets/widgets/qtextbrowser/qtextbrowser.pro +++ b/tests/auto/widgets/widgets/qtextbrowser/qtextbrowser.pro @@ -4,6 +4,6 @@ SOURCES += tst_qtextbrowser.cpp QT += widgets testlib -TESTDATA += *.html subdir/* +TESTDATA += *.html *.md subdir/* builtin_testdata: DEFINES += BUILTIN_TESTDATA -- cgit v1.2.3 From 0eb26c144346dcb12008e5b3e9441073f09668a8 Mon Sep 17 00:00:00 2001 From: Shawn Rutledge Date: Sun, 19 May 2019 13:06:05 +0200 Subject: QTextBrowser: detect and load markdown rather than assuming HTML So we add the QTextDocument::ResourceType::MarkdownResource enum value to indicate the type. QMimeDatabase is generally unable to detect markdown by "magic", so we need to use the common file extensions to detect it (the same extensions as declared in the mime database XML). Change-Id: Ib71f03abd535c17e5a8c99bd92d0a6062e972837 Reviewed-by: Simon Hausmann --- tests/auto/widgets/widgets/qtextbrowser/markdown.md | 2 ++ .../widgets/widgets/qtextbrowser/tst_qtextbrowser.cpp | 16 ++++++++++++++++ 2 files changed, 18 insertions(+) create mode 100644 tests/auto/widgets/widgets/qtextbrowser/markdown.md (limited to 'tests') diff --git a/tests/auto/widgets/widgets/qtextbrowser/markdown.md b/tests/auto/widgets/widgets/qtextbrowser/markdown.md new file mode 100644 index 0000000000..be56aef234 --- /dev/null +++ b/tests/auto/widgets/widgets/qtextbrowser/markdown.md @@ -0,0 +1,2 @@ +### this is a heading +this is a paragraph diff --git a/tests/auto/widgets/widgets/qtextbrowser/tst_qtextbrowser.cpp b/tests/auto/widgets/widgets/qtextbrowser/tst_qtextbrowser.cpp index 1f95032165..22cd3b46c6 100644 --- a/tests/auto/widgets/widgets/qtextbrowser/tst_qtextbrowser.cpp +++ b/tests/auto/widgets/widgets/qtextbrowser/tst_qtextbrowser.cpp @@ -92,6 +92,7 @@ private slots: void focusIndicator(); void focusHistory(); void urlEncoding(); + void markdown(); private: TestBrowser *browser; @@ -678,5 +679,20 @@ void tst_QTextBrowser::urlEncoding() delete browser; } +void tst_QTextBrowser::markdown() +{ + browser->setSource(QUrl::fromLocalFile(QFINDTESTDATA("markdown.md"))); + QTextFrame::iterator iterator = browser->document()->rootFrame()->begin(); + int maxHeadingLevel = -1; + while (!iterator.atEnd()) + maxHeadingLevel = qMax(iterator++.currentBlock().blockFormat().intProperty(QTextFormat::HeadingLevel), maxHeadingLevel); +#if QT_CONFIG(textmarkdownreader) + QCOMPARE(maxHeadingLevel, 3); +#else + // If Qt doesn't support markdown, this document will be misidentified as HTML, so it won't have any H3's. + QCOMPARE(maxHeadingLevel, 0); +#endif +} + QTEST_MAIN(tst_QTextBrowser) #include "tst_qtextbrowser.moc" -- cgit v1.2.3 From 237fa21feef63884043bd6cf32682b2b08c78454 Mon Sep 17 00:00:00 2001 From: Shawn Rutledge Date: Mon, 20 May 2019 12:58:36 +0200 Subject: Markdown and HTML: support image alt text and title It's a required CommonMark feature: https://spec.commonmark.org/0.29/#images and alt text is also required in HTML: https://www.w3.org/wiki/Html/Elements/img#Requirements_for_providing_text_to_act_as_an_alternative_for_images Now we are able to read these attributes from either html or markdown and rewrite either an html or markdown document that preserves them. This patch does not add viewing or editing support in QTextEdit etc. Change-Id: I51307389f8f9fc00809808390e583a83111a7b33 Reviewed-by: Gatis Paeglis --- tests/auto/gui/text/qtextmarkdownwriter/tst_qtextmarkdownwriter.cpp | 3 +++ 1 file changed, 3 insertions(+) (limited to 'tests') diff --git a/tests/auto/gui/text/qtextmarkdownwriter/tst_qtextmarkdownwriter.cpp b/tests/auto/gui/text/qtextmarkdownwriter/tst_qtextmarkdownwriter.cpp index acc74a9060..1935e58dec 100644 --- a/tests/auto/gui/text/qtextmarkdownwriter/tst_qtextmarkdownwriter.cpp +++ b/tests/auto/gui/text/qtextmarkdownwriter/tst_qtextmarkdownwriter.cpp @@ -416,6 +416,9 @@ void tst_QTextMarkdownWriter::fromHtml_data() QTest::newRow("block quote") << "

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 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"; + QTest::newRow("image") << + "\"foo\"" << + "![foo](/url \"title\")\n\n"; // TODO // QTest::newRow("escaped number and paren after double newline") << // "

(The first sentence of this paragraph is a line, the next paragraph has a number

13) but that's not part of an ordered list" << -- cgit v1.2.3 From 638f2749a052a22622de5ab01dfe3913644c2c25 Mon Sep 17 00:00:00 2001 From: Anton Kudryavtsev Date: Thu, 11 Apr 2019 15:57:59 +0300 Subject: QLatin1String, QStringView: add contains [ChangeLog][QtCore][QLatin1String] Added contains(). [ChangeLog][QtCore][QStringView] Added contains(). Change-Id: I19fd2e155180edd8620c520f4e60a1f86f0603ac Reviewed-by: Marc Mutz --- .../qstringapisymmetry/tst_qstringapisymmetry.cpp | 124 +++++++++++++++++++++ 1 file changed, 124 insertions(+) (limited to 'tests') diff --git a/tests/auto/corelib/tools/qstringapisymmetry/tst_qstringapisymmetry.cpp b/tests/auto/corelib/tools/qstringapisymmetry/tst_qstringapisymmetry.cpp index 7e5a855552..a74ae2eb71 100644 --- a/tests/auto/corelib/tools/qstringapisymmetry/tst_qstringapisymmetry.cpp +++ b/tests/auto/corelib/tools/qstringapisymmetry/tst_qstringapisymmetry.cpp @@ -485,6 +485,47 @@ private Q_SLOTS: void indexOf_QStringView_QStringRef() { indexOf_impl(); } void indexOf_QStringView_QStringView_data() { indexOf_data(); } void indexOf_QStringView_QStringView() { indexOf_impl(); } + +private: + template void contains_impl() const; + void contains_data(); + +private Q_SLOTS: + void contains_QString_QString_data() { contains_data(); } + void contains_QString_QString() { contains_impl(); } + void contains_QString_QLatin1String_data() { contains_data(); } + void contains_QString_QLatin1String() { contains_impl(); } + void contains_QString_QStringRef_data() { contains_data(); } + void contains_QString_QStringRef() { contains_impl(); } + void contains_QString_QStringView_data() { contains_data(); } + void contains_QString_QStringView() { contains_impl(); } + + void contains_QLatin1String_QString_data() { contains_data(); } + void contains_QLatin1String_QString() { contains_impl(); } + void contains_QLatin1String_QLatin1String_data() { contains_data(); } + void contains_QLatin1String_QLatin1String() { contains_impl(); } + void contains_QLatin1String_QStringRef_data() { contains_data(); } + void contains_QLatin1String_QStringRef() { contains_impl(); } + void contains_QLatin1String_QStringView_data() { contains_data(); } + void contains_QLatin1String_QStringView() { contains_impl(); } + + void contains_QStringRef_QString_data() { contains_data(); } + void contains_QStringRef_QString() { contains_impl(); } + void contains_QStringRef_QLatin1String_data() { contains_data(); } + void contains_QStringRef_QLatin1String() { contains_impl(); } + void contains_QStringRef_QStringRef_data() { contains_data(); } + void contains_QStringRef_QStringRef() { contains_impl(); } + void contains_QStringRef_QStringView_data() { contains_data(); } + void contains_QStringRef_QStringView() { contains_impl(); } + + void contains_QStringView_QString_data() { contains_data(); } + void contains_QStringView_QString() { contains_impl(); } + void contains_QStringView_QLatin1String_data() { contains_data(); } + void contains_QStringView_QLatin1String() { contains_impl(); } + void contains_QStringView_QStringRef_data() { contains_data(); } + void contains_QStringView_QStringRef() { contains_impl(); } + void contains_QStringView_QStringView_data() { contains_data(); } + void contains_QStringView_QStringView() { contains_impl(); } }; void tst_QStringApiSymmetry::compare_data(bool hasConceptOfNullAndEmpty) @@ -617,6 +658,14 @@ static QString b = QStringLiteral("b"); static QString B = QStringLiteral("B"); static QString c = QStringLiteral("c"); static QString C = QStringLiteral("C"); +static QString d = QStringLiteral("d"); +static QString D = QStringLiteral("D"); +static QString e = QStringLiteral("e"); +static QString E = QStringLiteral("E"); +static QString f = QStringLiteral("f"); +static QString F = QStringLiteral("F"); +static QString g = QStringLiteral("g"); +static QString G = QStringLiteral("G"); static QString ab = QStringLiteral("ab"); static QString aB = QStringLiteral("aB"); static QString Ab = QStringLiteral("Ab"); @@ -1501,6 +1550,81 @@ void tst_QStringApiSymmetry::indexOf_impl() const } } +static QString ABCDEFGHIEfGEFG = QStringLiteral("ABCDEFGHIEfGEFG"); +static QString EFG = QStringLiteral("EFG"); +static QString efg = QStringLiteral("efg"); +static QString asd = QStringLiteral("asd"); +static QString asdf = QStringLiteral("asdf"); +static QString Z = QStringLiteral("Z"); + +void tst_QStringApiSymmetry::contains_data() +{ + QTest::addColumn("haystackU16"); + QTest::addColumn("haystackL1"); + QTest::addColumn("needleU16"); + QTest::addColumn("needleL1"); + QTest::addColumn("resultCS"); + QTest::addColumn("resultCIS"); + + QTest::addRow("haystack: null, needle: null") << null << QLatin1String() + << null << QLatin1String() << true << true; + QTest::addRow("haystack: empty, needle: null") << empty << QLatin1String("") + << null << QLatin1String() << true << true; + QTest::addRow("haystack: a, needle: null") << a << QLatin1String("a") + << null << QLatin1String() << true << true; + QTest::addRow("haystack: null, needle: empty") << null << QLatin1String() + << empty << QLatin1String("") << true << true; + QTest::addRow("haystack: a, needle: empty") << a << QLatin1String("a") + << empty << QLatin1String("") << true << true;; + QTest::addRow("haystack: empty, needle: empty") << empty << QLatin1String("") + << empty << QLatin1String("") << true << true; + QTest::addRow("haystack: empty, needle: a") << empty << QLatin1String("") + << a << QLatin1String("a") << false << false; + QTest::addRow("haystack: null, needle: a") << null << QLatin1String() + << a << QLatin1String("a") << false << false; + +#define ROW(h, n, cs, cis) \ + QTest::addRow("haystack: %s, needle: %s", #h, #n) << h << QLatin1String(#h) \ + << n << QLatin1String(#n) \ + << cs << cis + + ROW(ABCDEFGHIEfGEFG, A, true, true); + ROW(ABCDEFGHIEfGEFG, a, false, true); + ROW(ABCDEFGHIEfGEFG, Z, false, false); + ROW(ABCDEFGHIEfGEFG, EFG, true, true); + ROW(ABCDEFGHIEfGEFG, efg, false, true); + ROW(ABCDEFGHIEfGEFG, E, true, true); + ROW(ABCDEFGHIEfGEFG, e, false, true); +#undef ROW +} + +template +void tst_QStringApiSymmetry::contains_impl() const +{ + QFETCH(const QString, haystackU16); + QFETCH(const QLatin1String, haystackL1); + QFETCH(const QString, needleU16); + QFETCH(const QLatin1String, needleL1); + QFETCH(const bool, resultCS); + QFETCH(const bool, resultCIS); + + const auto haystackU8 = haystackU16.toUtf8(); + const auto needleU8 = needleU16.toUtf8(); + + const auto haystack = make(QStringRef(&haystackU16), haystackL1, haystackU8); + const auto needle = make(QStringRef(&needleU16), needleL1, needleU8); + + QCOMPARE(haystack.contains(needle), resultCS); + QCOMPARE(haystack.contains(needle, Qt::CaseSensitive), resultCS); + QCOMPARE(haystack.contains(needle, Qt::CaseInsensitive), resultCIS); + + if (needle.size() == 1) + { + QCOMPARE(haystack.contains(needle[0]), resultCS); + QCOMPARE(haystack.contains(needle[0], Qt::CaseSensitive), resultCS); + QCOMPARE(haystack.contains(needle[0], Qt::CaseInsensitive), resultCIS); + } +} QTEST_APPLESS_MAIN(tst_QStringApiSymmetry) -- cgit v1.2.3