From 6324873543afd7b76d476bd43e3b85e84ea70c00 Mon Sep 17 00:00:00 2001 From: Volker Hilsheimer Date: Tue, 25 Feb 2020 16:20:42 +0100 Subject: Stabilize task255529_transformationAnchorMouseAndViewportMargins MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit This test doesn't test whether window activation works, so there is no reason to fail the test if it doesn't. Instead, abort the test, so that we can record it as a skipped test. Change-Id: Ia44308ef17f110d40c6455d7ee85d90914face4f Fixes: QTBUG-22455 Reviewed-by: Jan Arve Sæther Reviewed-by: Levon Sargsyan --- tests/auto/widgets/graphicsview/qgraphicsview/tst_qgraphicsview.cpp | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) (limited to 'tests') diff --git a/tests/auto/widgets/graphicsview/qgraphicsview/tst_qgraphicsview.cpp b/tests/auto/widgets/graphicsview/qgraphicsview/tst_qgraphicsview.cpp index e21b1b889a..f02835aa90 100644 --- a/tests/auto/widgets/graphicsview/qgraphicsview/tst_qgraphicsview.cpp +++ b/tests/auto/widgets/graphicsview/qgraphicsview/tst_qgraphicsview.cpp @@ -4553,7 +4553,9 @@ void tst_QGraphicsView::task255529_transformationAnchorMouseAndViewportMargins() view.show(); qApp->setActiveWindow(&view); QVERIFY(QTest::qWaitForWindowExposed(&view)); - QVERIFY(QTest::qWaitForWindowActive(&view)); + const bool isActiveWindow = QTest::qWaitForWindowActive(&view); + if (!isActiveWindow) + QSKIP("Window activation failed, skipping test", Abort); // This is highly unstable (observed to pass on Windows and some Linux configurations). #ifndef Q_OS_MAC for (int i = 0; i < 4; ++i) { -- cgit v1.2.3 From 715468df40e4ce97da04f327b6e34d535ff9b97d Mon Sep 17 00:00:00 2001 From: Volker Hilsheimer Date: Thu, 27 Feb 2020 09:53:49 +0100 Subject: Fix flaky QElapsedTimer::elapsed test case Much of this test case was testing that the machine it runs on didn't take more than an expected amount of time, which is an assumption that won't hold in a virtual environment where the hypervisor might decide to not allocate any CPU time to the machine at certain times. Instead, take the samples that we want to compare with once, then use them as reference for further comparisons. Also, split the test in two, with the comparison operators and msecsTo test moved into a separate test function. Change-Id: I7db12b8e02552f4d63af933c1b0fee9d62b591eb Fixes: QTBUG-58713 Reviewed-by: Lars Knoll --- .../kernel/qelapsedtimer/tst_qelapsedtimer.cpp | 47 ++++++++++++++-------- 1 file changed, 30 insertions(+), 17 deletions(-) (limited to 'tests') diff --git a/tests/auto/corelib/kernel/qelapsedtimer/tst_qelapsedtimer.cpp b/tests/auto/corelib/kernel/qelapsedtimer/tst_qelapsedtimer.cpp index 4ee3ca361f..bfc4f2ca36 100644 --- a/tests/auto/corelib/kernel/qelapsedtimer/tst_qelapsedtimer.cpp +++ b/tests/auto/corelib/kernel/qelapsedtimer/tst_qelapsedtimer.cpp @@ -48,6 +48,7 @@ private Q_SLOTS: void validity(); void basics(); void elapsed(); + void msecsTo(); }; void tst_QElapsedTimer::statics() @@ -108,30 +109,42 @@ void tst_QElapsedTimer::elapsed() t1.start(); QTest::qSleep(2*minResolution); - QElapsedTimer t2; - t2.start(); - - QVERIFY(t1 != t2); - QVERIFY(!(t1 == t2)); - QVERIFY(t1 < t2); - QVERIFY(t1.msecsTo(t2) > 0); - QVERIFY(t1.nsecsElapsed() > 0); - QVERIFY(t1.elapsed() > 0); + auto nsecs = t1.nsecsElapsed(); + auto msecs = t1.elapsed(); + QVERIFY(nsecs > 0); + QVERIFY(msecs > 0); // the number of elapsed nanoseconds and milliseconds should match - QVERIFY(t1.nsecsElapsed() - t1.elapsed() * 1000000 < 1000000); + QVERIFY(nsecs - msecs * 1000000 < 1000000); + + if (msecs > 8 * minResolution) + QSKIP("Sampling timer took too long, aborting test"); + QVERIFY(t1.hasExpired(minResolution)); QVERIFY(!t1.hasExpired(8*minResolution)); - QVERIFY(!t2.hasExpired(minResolution)); - QVERIFY(!t1.hasExpired(-1)); - QVERIFY(!t2.hasExpired(-1)); qint64 elapsed = t1.restart(); - QVERIFY(elapsed > minResolution); - QVERIFY(elapsed < 3*minResolution); - qint64 diff = t2.msecsTo(t1); - QVERIFY(diff < minResolution); + QVERIFY(elapsed >= msecs); + QVERIFY(elapsed < msecs + 3*minResolution); +} + +void tst_QElapsedTimer::msecsTo() +{ + QElapsedTimer t1; + t1.start(); + QTest::qSleep(minResolution); + QElapsedTimer t2; + t2.start(); + + QVERIFY(t1 != t2); + QVERIFY(!(t1 == t2)); + QVERIFY(t1 < t2); + + auto diff = t1.msecsTo(t2); + QVERIFY2(diff > 0, QString("difference t1 and t2 is %1").arg(diff).toLatin1()); + diff = t2.msecsTo(t1); + QVERIFY2(diff < 0, QString("difference t2 and t1 is %1").arg(diff).toLatin1()); } QTEST_MAIN(tst_QElapsedTimer); -- cgit v1.2.3 From 7447e2b337f12b4d04935d0f30fc673e4327d5a0 Mon Sep 17 00:00:00 2001 From: Shawn Rutledge Date: Mon, 24 Feb 2020 16:23:27 +0100 Subject: QTextMarkdownImporter: fix use after free; add fuzz-generated tests It was possible to end up with a dangling pointer in m_listStack. This is now avoided by using QPointer and doing nullptr checks before accessing any QTextList pointer stored there. We have 2 specimens of garbage that caused crashes before; now they don't. But only fuzz20450 triggered the dangling pointer in the list stack. The crash caused by fuzz20580 was fixed by updating md4c from upstream: 4b0fc030777cd541604f5ebaaad47a2b76d61ff9 Change-Id: I8e1eca23b281256a03aea0f55e9ae20f1bdd2a38 Reviewed-by: Robert Loehning --- .../text/qtextmarkdownimporter/data/fuzz20450.md | 5 +++++ .../text/qtextmarkdownimporter/data/fuzz20580.md | 1 + .../qtextmarkdownimporter.pro | 2 ++ .../tst_qtextmarkdownimporter.cpp | 24 ++++++++++++++++++++++ 4 files changed, 32 insertions(+) create mode 100644 tests/auto/gui/text/qtextmarkdownimporter/data/fuzz20450.md create mode 100644 tests/auto/gui/text/qtextmarkdownimporter/data/fuzz20580.md (limited to 'tests') diff --git a/tests/auto/gui/text/qtextmarkdownimporter/data/fuzz20450.md b/tests/auto/gui/text/qtextmarkdownimporter/data/fuzz20450.md new file mode 100644 index 0000000000..d7005cb01e --- /dev/null +++ b/tests/auto/gui/text/qtextmarkdownimporter/data/fuzz20450.md @@ -0,0 +1,5 @@ +˙ +* ˙ + + ˙ +* ˙ \ No newline at end of file diff --git a/tests/auto/gui/text/qtextmarkdownimporter/data/fuzz20580.md b/tests/auto/gui/text/qtextmarkdownimporter/data/fuzz20580.md new file mode 100644 index 0000000000..22006f5876 --- /dev/null +++ b/tests/auto/gui/text/qtextmarkdownimporter/data/fuzz20580.md @@ -0,0 +1 @@ +| --:| ("warning"); + QTest::newRow("fuzz20450") << "attempted to insert into a list that no longer exists"; + QTest::newRow("fuzz20580") << ""; +} + +void tst_QTextMarkdownImporter::pathological() // avoid crashing on crazy input +{ + QFETCH(QString, warning); + QString filename = QLatin1String("data/") + QTest::currentDataTag() + QLatin1String(".md"); + QFile f(QFINDTESTDATA(filename)); + QVERIFY(f.open(QFile::ReadOnly)); +#ifdef QT_NO_DEBUG + Q_UNUSED(warning) +#else + if (!warning.isEmpty()) + QTest::ignoreMessage(QtWarningMsg, warning.toLatin1()); +#endif + QTextDocument().setMarkdown(f.readAll()); +} + QTEST_MAIN(tst_QTextMarkdownImporter) #include "tst_qtextmarkdownimporter.moc" -- cgit v1.2.3 From 4a1de178c9cc891560f38d64d89074799b0fa0e1 Mon Sep 17 00:00:00 2001 From: Volker Hilsheimer Date: Fri, 28 Feb 2020 12:33:35 +0100 Subject: Try again to make QDeadlineTimer test robust against context switches Instead of comparing to absolute values, compare the result from QDeadlineTimer with the reference clock types from std::chrono. Pass the test as long as we are within 10% of that reference. In addition, handle the case where QTest::qSleep sleeps for more than 10% longer or shorter than what is requested, and if so, abort the test. Change-Id: If8b77aea55a8c5c53e96427b2fff2f78281d0f82 Reviewed-by: Lars Knoll --- .../kernel/qdeadlinetimer/tst_qdeadlinetimer.cpp | 50 +++++++++++++++------- 1 file changed, 34 insertions(+), 16 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 35c5e7cb75..db53c3f20c 100644 --- a/tests/auto/corelib/kernel/qdeadlinetimer/tst_qdeadlinetimer.cpp +++ b/tests/auto/corelib/kernel/qdeadlinetimer/tst_qdeadlinetimer.cpp @@ -573,12 +573,32 @@ void tst_QDeadlineTimer::stdchrono() QCOMPARE(deadline.remainingTimeAsDuration(), nanoseconds::zero()); + /* + Call QTest::qSleep, and return true if the time actually slept is + within \a deviationPercent percent of the requested sleep time. + Otherwise, return false, in which case the test should to abort. + */ + auto sleepHelper = [](int ms, int deviationPercent = 10) -> bool { + auto before = steady_clock::now(); + QTest::qSleep(ms); + auto after = steady_clock::now(); + auto diff = duration_cast(after - before).count(); + bool inRange = qAbs(diff - ms) < ms * deviationPercent/100.0; + if (!inRange) + qWarning() << "sleeping" << diff << "instead of" << ms << inRange; + return inRange; + }; + auto steady_before = steady_clock::now(); auto system_before = system_clock::now(); - QTest::qSleep(minResolution); + if (!sleepHelper(minResolution)) + QSKIP("Slept too long"); auto now = QDeadlineTimer::current(timerType); - QTest::qSleep(minResolution); + auto steady_reference = steady_clock::now(); + auto system_reference = system_clock::now(); + if (!sleepHelper(minResolution)) + QSKIP("Slept too long"); auto sampling_start = steady_clock::now(); auto steady_deadline = now.deadline(); @@ -599,35 +619,33 @@ void tst_QDeadlineTimer::stdchrono() } { - auto diff = duration_cast(steady_after - steady_deadline); - QVERIFY2(diff.count() > minResolution/2, QByteArray::number(qint64(diff.count()))); - QVERIFY2(diff.count() < 3*minResolution/2, QByteArray::number(qint64(diff.count()))); + auto reference = duration_cast(steady_after - steady_reference).count(); + auto diff = duration_cast(steady_after - steady_deadline).count(); + QVERIFY2(diff > reference * 0.9 && diff < reference*1.1, QByteArray::number(qint64(diff))); QDeadlineTimer dt_after(steady_after, timerType); QVERIFY2(now < dt_after, ("now = " + QLocale().toString(now.deadlineNSecs()) + "; after = " + QLocale().toString(dt_after.deadlineNSecs())).toLatin1()); - diff = duration_cast(steady_deadline - steady_before); - QVERIFY2(diff.count() > minResolution/2, QByteArray::number(qint64(diff.count()))); - QVERIFY2(diff.count() < 3*minResolution/2, QByteArray::number(qint64(diff.count()))); + reference = duration_cast(steady_reference - steady_before).count(); + diff = duration_cast(steady_deadline - steady_before).count(); + QVERIFY2(diff > reference * 0.9 && diff < reference*1.1, QByteArray::number(qint64(diff))); QDeadlineTimer dt_before(steady_before, timerType); QVERIFY2(now > dt_before, ("now = " + QLocale().toString(now.deadlineNSecs()) + "; before = " + QLocale().toString(dt_before.deadlineNSecs())).toLatin1()); } { - auto diff = duration_cast(system_after - system_deadline); - QVERIFY2(diff.count() > minResolution/2, QByteArray::number(qint64(diff.count()))); - QVERIFY2(diff.count() < 3*minResolution/2, QByteArray::number(qint64(diff.count()))); - QDeadlineTimer dt_after(system_after, timerType); + auto reference = duration_cast(system_after - system_reference).count(); + auto diff = duration_cast(system_after - system_deadline).count(); + QVERIFY2(diff > reference * 0.9 && diff < reference*1.1, QByteArray::number(qint64(diff))); QDeadlineTimer dt_after(system_after, timerType); QVERIFY2(now < dt_after, ("now = " + QLocale().toString(now.deadlineNSecs()) + "; after = " + QLocale().toString(dt_after.deadlineNSecs())).toLatin1()); - diff = duration_cast(system_deadline - system_before); - QVERIFY2(diff.count() > minResolution/2, QByteArray::number(qint64(diff.count()))); - QVERIFY2(diff.count() < 3*minResolution/2, QByteArray::number(qint64(diff.count()))); - QDeadlineTimer dt_before(system_before, timerType); + reference = duration_cast(system_reference - system_before).count(); + diff = duration_cast(steady_deadline - steady_before).count(); + QVERIFY2(diff > reference * 0.9 && diff < reference*1.1, QByteArray::number(qint64(diff))); QDeadlineTimer dt_before(system_before, timerType); QVERIFY2(now > dt_before, ("now = " + QLocale().toString(now.deadlineNSecs()) + "; before = " + QLocale().toString(dt_before.deadlineNSecs())).toLatin1()); -- cgit v1.2.3 From 0378332bc1a6cf3592a4bf5f7e73fe10963168ca Mon Sep 17 00:00:00 2001 From: Laszlo Agocs Date: Tue, 3 Mar 2020 11:19:14 +0100 Subject: rhi: Use versioning in QShaderDescription serialization as well MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit This is the first time that we add something to QShaderDescription after migrating to the non-JSON based serialization system. This now involves checking the "qsb version" when deserializing. Task-number: QTBUG-82624 Change-Id: I2bd875ef21e461559b878dccc5537cdfa43feaa2 Reviewed-by: Christian Strømme --- tests/auto/gui/rhi/qshader/tst_qshader.cpp | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'tests') diff --git a/tests/auto/gui/rhi/qshader/tst_qshader.cpp b/tests/auto/gui/rhi/qshader/tst_qshader.cpp index ab7115b74a..378d1e85e7 100644 --- a/tests/auto/gui/rhi/qshader/tst_qshader.cpp +++ b/tests/auto/gui/rhi/qshader/tst_qshader.cpp @@ -368,7 +368,7 @@ void tst_QShader::serializeShaderDesc() QBuffer buf(&data); QDataStream ds(&buf); QVERIFY(buf.open(QIODevice::ReadOnly)); - QShaderDescription desc2 = QShaderDescription::deserialize(&ds); + QShaderDescription desc2 = QShaderDescription::deserialize(&ds, QShaderPrivate::QSB_VERSION); QVERIFY(!desc2.isValid()); } } @@ -400,7 +400,7 @@ void tst_QShader::serializeShaderDesc() QBuffer buf(&data); QDataStream ds(&buf); QVERIFY(buf.open(QIODevice::ReadOnly)); - QShaderDescription desc2 = QShaderDescription::deserialize(&ds); + QShaderDescription desc2 = QShaderDescription::deserialize(&ds, QShaderPrivate::QSB_VERSION); QVERIFY(desc2.isValid()); QCOMPARE(desc, desc2); } -- cgit v1.2.3 From 8f8eb99991216c0833c23a0f068e036a70e3b060 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?M=C3=A5rten=20Nordheim?= Date: Sat, 29 Feb 2020 11:39:58 +0100 Subject: QNetworkReply: Deprecate 'error' signal, use 'errorOccurred' instead MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit [ChangeLog][Deprecation Notice] QNetworkReply::error() (the signal) is deprecated; superseded by errorOccurred() Change-Id: I4f1ef410fd22d34ddf87e89cc5709cc60703af95 Reviewed-by: MĂĄrten Nordheim --- tests/auto/network/access/http2/tst_http2.cpp | 2 +- .../tst_qhttpnetworkconnection.cpp | 6 ++-- .../tst_qnetworkaccessmanager.cpp | 2 +- .../access/qnetworkreply/tst_qnetworkreply.cpp | 42 +++++++++++----------- tests/auto/network/access/spdy/tst_spdy.cpp | 2 +- 5 files changed, 26 insertions(+), 28 deletions(-) (limited to 'tests') diff --git a/tests/auto/network/access/http2/tst_http2.cpp b/tests/auto/network/access/http2/tst_http2.cpp index 6f94692cb1..6a07ae78fb 100644 --- a/tests/auto/network/access/http2/tst_http2.cpp +++ b/tests/auto/network/access/http2/tst_http2.cpp @@ -513,7 +513,7 @@ void tst_Http2::goaway() replies[i] = manager->get(request); QCOMPARE(replies[i]->error(), QNetworkReply::NoError); void (QNetworkReply::*errorSignal)(QNetworkReply::NetworkError) = - &QNetworkReply::error; + &QNetworkReply::errorOccurred; connect(replies[i], errorSignal, this, &tst_Http2::replyFinishedWithError); // Since we're using self-signed certificates, ignore SSL errors: replies[i]->ignoreSslErrors(); diff --git a/tests/auto/network/access/qhttpnetworkconnection/tst_qhttpnetworkconnection.cpp b/tests/auto/network/access/qhttpnetworkconnection/tst_qhttpnetworkconnection.cpp index 57fa5a613c..e8d4c773f0 100644 --- a/tests/auto/network/access/qhttpnetworkconnection/tst_qhttpnetworkconnection.cpp +++ b/tests/auto/network/access/qhttpnetworkconnection/tst_qhttpnetworkconnection.cpp @@ -1005,10 +1005,8 @@ void tst_QHttpNetworkConnection::overlappingCloseAndWrite() for (int i = 0; i < 10; ++i) { QNetworkRequest request(url); QNetworkReply *reply = accessManager.get(request); - // Not using Qt5 connection syntax here because of overly baroque syntax to discern between - // different error() methods. - QObject::connect(reply, SIGNAL(error(QNetworkReply::NetworkError)), - &server, SLOT(onReply(QNetworkReply::NetworkError))); + QObject::connect(reply, &QNetworkReply::errorOccurred, + &server, &TestTcpServer::onReply); } QTRY_COMPARE(server.errorCodeReports, 10); diff --git a/tests/auto/network/access/qnetworkaccessmanager/tst_qnetworkaccessmanager.cpp b/tests/auto/network/access/qnetworkaccessmanager/tst_qnetworkaccessmanager.cpp index 752655ee94..b5ded86d58 100644 --- a/tests/auto/network/access/qnetworkaccessmanager/tst_qnetworkaccessmanager.cpp +++ b/tests/auto/network/access/qnetworkaccessmanager/tst_qnetworkaccessmanager.cpp @@ -87,7 +87,7 @@ void tst_QNetworkAccessManager::networkAccessible() // When network is not accessible, all requests fail QNetworkReply *reply = manager.get(QNetworkRequest(QUrl("http://www.example.org"))); QSignalSpy finishedSpy(reply, &QNetworkReply::finished); - QSignalSpy errorSpy(reply, QOverload::of(&QNetworkReply::error)); + QSignalSpy errorSpy(reply, &QNetworkReply::errorOccurred); QVERIFY(finishedSpy.wait()); QCOMPARE(reply->isFinished(), true); QCOMPARE(reply->errorString(), QStringLiteral("Network access is disabled.")); diff --git a/tests/auto/network/access/qnetworkreply/tst_qnetworkreply.cpp b/tests/auto/network/access/qnetworkreply/tst_qnetworkreply.cpp index 65f355ca25..7d065f1248 100644 --- a/tests/auto/network/access/qnetworkreply/tst_qnetworkreply.cpp +++ b/tests/auto/network/access/qnetworkreply/tst_qnetworkreply.cpp @@ -1371,7 +1371,7 @@ QString tst_QNetworkReply::runMultipartRequest(const QNetworkRequest &request, // the code below is copied from tst_QNetworkReply::runSimpleRequest, see below reply->setParent(this); connect(reply, SIGNAL(finished()), SLOT(finished())); - connect(reply, SIGNAL(error(QNetworkReply::NetworkError)), SLOT(gotError())); + connect(reply, SIGNAL(errorOccurred(QNetworkReply::NetworkError)), SLOT(gotError())); multiPart->setParent(reply.data()); returnCode = Timeout; @@ -1431,7 +1431,7 @@ QString tst_QNetworkReply::runSimpleRequest(QNetworkAccessManager::Operation op, code = Failure; } else { connect(reply, SIGNAL(finished()), SLOT(finished())); - connect(reply, SIGNAL(error(QNetworkReply::NetworkError)), SLOT(gotError())); + connect(reply, SIGNAL(errorOccurred(QNetworkReply::NetworkError)), SLOT(gotError())); int count = 0; loop = new QEventLoop; @@ -1466,7 +1466,7 @@ QString tst_QNetworkReply::runCustomRequest(const QNetworkRequest &request, reply.reset(manager.sendCustomRequest(request, verb, data)); reply->setParent(this); connect(reply, SIGNAL(finished()), SLOT(finished())); - connect(reply, SIGNAL(error(QNetworkReply::NetworkError)), SLOT(gotError())); + connect(reply, SIGNAL(errorOccurred(QNetworkReply::NetworkError)), SLOT(gotError())); returnCode = Timeout; loop = new QEventLoop; @@ -1503,7 +1503,7 @@ int tst_QNetworkReply::waitForFinish(QNetworkReplyPtr &reply) int count = 0; connect(reply, SIGNAL(finished()), SLOT(finished())); - connect(reply, SIGNAL(error(QNetworkReply::NetworkError)), SLOT(gotError())); + connect(reply, SIGNAL(errorOccurred(QNetworkReply::NetworkError)), SLOT(gotError())); returnCode = Success; loop = new QEventLoop; QSignalSpy spy(reply.data(), SIGNAL(downloadProgress(qint64,qint64))); @@ -1890,7 +1890,7 @@ void tst_QNetworkReply::getFromFtpAfterError() QNetworkRequest invalidRequest(QUrl("ftp://" + QtNetworkSettings::ftpServerName() + "/qtest/invalid.txt")); QNetworkReplyPtr invalidReply; invalidReply.reset(manager.get(invalidRequest)); - QSignalSpy spy(invalidReply.data(), SIGNAL(error(QNetworkReply::NetworkError))); + QSignalSpy spy(invalidReply.data(), SIGNAL(errorOccurred(QNetworkReply::NetworkError))); QVERIFY(spy.wait()); QCOMPARE(invalidReply->error(), QNetworkReply::ContentNotFoundError); @@ -3911,7 +3911,7 @@ void tst_QNetworkReply::ioGetFromHttpBrokenServer() QNetworkRequest request(QUrl("http://localhost:" + QString::number(server.serverPort()))); QNetworkReplyPtr reply(manager.get(request)); - QSignalSpy spy(reply.data(), SIGNAL(error(QNetworkReply::NetworkError))); + QSignalSpy spy(reply.data(), SIGNAL(errorOccurred(QNetworkReply::NetworkError))); QCOMPARE(waitForFinish(reply), int(Failure)); @@ -5447,7 +5447,7 @@ void tst_QNetworkReply::rateControl() QNetworkRequest request("debugpipe://localhost:" + QString::number(sender.serverPort())); QNetworkReplyPtr reply(manager.get(request)); reply->setReadBufferSize(32768); - QSignalSpy errorSpy(reply.data(), SIGNAL(error(QNetworkReply::NetworkError))); + QSignalSpy errorSpy(reply.data(), SIGNAL(errorOccurred(QNetworkReply::NetworkError))); RateControlledReader reader(sender, reply.data(), rate, 20); @@ -5861,7 +5861,7 @@ void tst_QNetworkReply::nestedEventLoops() QNetworkReplyPtr reply(manager.get(request)); QSignalSpy finishedspy(reply.data(), SIGNAL(finished())); - QSignalSpy errorspy(reply.data(), SIGNAL(error(QNetworkReply::NetworkError))); + QSignalSpy errorspy(reply.data(), SIGNAL(errorOccurred(QNetworkReply::NetworkError))); connect(reply, SIGNAL(finished()), SLOT(nestedEventLoops_slot())); QTestEventLoop::instance().enterLoop(20); @@ -6094,7 +6094,7 @@ void tst_QNetworkReply::authorizationError() QCOMPARE(reply->error(), QNetworkReply::NoError); - QSignalSpy errorSpy(reply.data(), SIGNAL(error(QNetworkReply::NetworkError))); + QSignalSpy errorSpy(reply.data(), SIGNAL(errorOccurred(QNetworkReply::NetworkError))); QSignalSpy finishedSpy(reply.data(), SIGNAL(finished())); // now run the request: QCOMPARE(waitForFinish(reply), int(Failure)); @@ -7050,7 +7050,7 @@ void tst_QNetworkReply::qtbug4121unknownAuthentication() QSignalSpy authSpy(&manager, SIGNAL(authenticationRequired(QNetworkReply*,QAuthenticator*))); QSignalSpy finishedSpy(&manager, SIGNAL(finished(QNetworkReply*))); - QSignalSpy errorSpy(reply.data(), SIGNAL(error(QNetworkReply::NetworkError))); + QSignalSpy errorSpy(reply.data(), SIGNAL(errorOccurred(QNetworkReply::NetworkError))); connect(reply, SIGNAL(finished()), &QTestEventLoop::instance(), SLOT(exitLoop()), Qt::QueuedConnection); QTestEventLoop::instance().enterLoop(10); @@ -7371,7 +7371,7 @@ void tst_QNetworkReply::httpWithNoCredentialUsage() request.setAttribute(QNetworkRequest::AuthenticationReuseAttribute, QNetworkRequest::Manual); QNetworkReplyPtr reply(manager.get(request)); - QSignalSpy errorSpy(reply.data(), SIGNAL(error(QNetworkReply::NetworkError))); + QSignalSpy errorSpy(reply.data(), SIGNAL(errorOccurred(QNetworkReply::NetworkError))); connect(reply, SIGNAL(finished()), &QTestEventLoop::instance(), SLOT(exitLoop()), Qt::QueuedConnection); QTestEventLoop::instance().enterLoop(10); @@ -8083,7 +8083,7 @@ void tst_QNetworkReply::emitErrorForAllReplies() // QTBUG-36890 QNetworkRequest request(urls.at(a)); QNetworkReply *reply = manager.get(request); replies.append(reply); - QSignalSpy *errorSpy = new QSignalSpy(reply, SIGNAL(error(QNetworkReply::NetworkError))); + QSignalSpy *errorSpy = new QSignalSpy(reply, SIGNAL(errorOccurred(QNetworkReply::NetworkError))); errorSpies.append(errorSpy); QSignalSpy *finishedSpy = new QSignalSpy(reply, SIGNAL(finished())); finishedSpies.append(finishedSpy); @@ -8474,7 +8474,7 @@ void tst_QNetworkReply::ioHttpChangeMaxRedirects() QNetworkReplyPtr reply(manager.get(request)); QSignalSpy redSpy(reply.data(), SIGNAL(redirected(QUrl))); - QSignalSpy spy(reply.data(), SIGNAL(error(QNetworkReply::NetworkError))); + QSignalSpy spy(reply.data(), SIGNAL(errorOccurred(QNetworkReply::NetworkError))); QCOMPARE(waitForFinish(reply), int(Failure)); @@ -8538,7 +8538,7 @@ void tst_QNetworkReply::ioHttpRedirectErrors() QTimer watchDog; watchDog.setSingleShot(true); - reply->connect(reply.data(), QOverload().of(&QNetworkReply::error), + reply->connect(reply.data(), &QNetworkReply::errorOccurred, [&eventLoop](QNetworkReply::NetworkError){ eventLoop.exit(Failure); }); @@ -8704,7 +8704,7 @@ void tst_QNetworkReply::ioHttpRedirectPolicyErrors() if (ssl) reply->ignoreSslErrors(); - QSignalSpy spy(reply.data(), SIGNAL(error(QNetworkReply::NetworkError))); + QSignalSpy spy(reply.data(), SIGNAL(errorOccurred(QNetworkReply::NetworkError))); QCOMPARE(waitForFinish(reply), int(Failure)); QCOMPARE(spy.count(), 1); @@ -9352,7 +9352,7 @@ void tst_QNetworkReply::getWithTimeout() QNetworkRequest request(QUrl("http://localhost:" + QString::number(server.serverPort()))); QNetworkReplyPtr reply(manager.get(request)); - QSignalSpy spy(reply.data(), SIGNAL(error(QNetworkReply::NetworkError))); + QSignalSpy spy(reply.data(), SIGNAL(errorOccurred(QNetworkReply::NetworkError))); QCOMPARE(waitForFinish(reply), int(Success)); @@ -9363,7 +9363,7 @@ void tst_QNetworkReply::getWithTimeout() server.stopTransfer = true; QNetworkReplyPtr reply2(manager.get(request)); - QSignalSpy spy2(reply2.data(), SIGNAL(error(QNetworkReply::NetworkError))); + QSignalSpy spy2(reply2.data(), SIGNAL(errorOccurred(QNetworkReply::NetworkError))); QCOMPARE(waitForFinish(reply2), int(Failure)); @@ -9374,7 +9374,7 @@ void tst_QNetworkReply::getWithTimeout() manager.setTransferTimeout(1000); QNetworkReplyPtr reply3(manager.get(request)); - QSignalSpy spy3(reply3.data(), SIGNAL(error(QNetworkReply::NetworkError))); + QSignalSpy spy3(reply3.data(), SIGNAL(errorOccurred(QNetworkReply::NetworkError))); QCOMPARE(waitForFinish(reply3), int(Failure)); @@ -9392,7 +9392,7 @@ void tst_QNetworkReply::postWithTimeout() request.setRawHeader("Content-Type", "application/octet-stream"); QByteArray postData("Just some nonsense"); QNetworkReplyPtr reply(manager.post(request, postData)); - QSignalSpy spy(reply.data(), SIGNAL(error(QNetworkReply::NetworkError))); + QSignalSpy spy(reply.data(), SIGNAL(errorOccurred(QNetworkReply::NetworkError))); QCOMPARE(waitForFinish(reply), int(Success)); @@ -9403,7 +9403,7 @@ void tst_QNetworkReply::postWithTimeout() server.stopTransfer = true; QNetworkReplyPtr reply2(manager.post(request, postData)); - QSignalSpy spy2(reply2.data(), SIGNAL(error(QNetworkReply::NetworkError))); + QSignalSpy spy2(reply2.data(), SIGNAL(errorOccurred(QNetworkReply::NetworkError))); QCOMPARE(waitForFinish(reply2), int(Failure)); @@ -9414,7 +9414,7 @@ void tst_QNetworkReply::postWithTimeout() manager.setTransferTimeout(1000); QNetworkReplyPtr reply3(manager.post(request, postData)); - QSignalSpy spy3(reply3.data(), SIGNAL(error(QNetworkReply::NetworkError))); + QSignalSpy spy3(reply3.data(), SIGNAL(errorOccurred(QNetworkReply::NetworkError))); QCOMPARE(waitForFinish(reply3), int(Failure)); diff --git a/tests/auto/network/access/spdy/tst_spdy.cpp b/tests/auto/network/access/spdy/tst_spdy.cpp index 5701f4911c..1b0b3aec6b 100644 --- a/tests/auto/network/access/spdy/tst_spdy.cpp +++ b/tests/auto/network/access/spdy/tst_spdy.cpp @@ -581,7 +581,7 @@ void tst_Spdy::errors() if (ignoreSslErrors) reply->ignoreSslErrors(); QSignalSpy finishedSpy(reply, SIGNAL(finished())); - QSignalSpy errorSpy(reply, SIGNAL(error(QNetworkReply::NetworkError))); + QSignalSpy errorSpy(reply, SIGNAL(errorOccurred(QNetworkReply::NetworkError))); QObject::connect(reply, SIGNAL(finished()), &QTestEventLoop::instance(), SLOT(exitLoop())); -- cgit v1.2.3 From 466d32160a23e6848fe0a42e74085c79071d7dec Mon Sep 17 00:00:00 2001 From: Edward Welbourne Date: Tue, 3 Mar 2020 08:01:05 +0100 Subject: Suppress warnings where QString and its tests use SplitBehavior This is a follow-up to commit 895939c7f91d0c8424a0638c42d05cb42293a142 to fix deprecation warnings it added. Change-Id: I3d86655ec2c84c1bdcac9c70436075fc78f2f781 Reviewed-by: Volker Hilsheimer --- tests/auto/corelib/text/qstring/tst_qstring.cpp | 3 +++ 1 file changed, 3 insertions(+) (limited to 'tests') diff --git a/tests/auto/corelib/text/qstring/tst_qstring.cpp b/tests/auto/corelib/text/qstring/tst_qstring.cpp index 7072cb9516..bc2b19125a 100644 --- a/tests/auto/corelib/text/qstring/tst_qstring.cpp +++ b/tests/auto/corelib/text/qstring/tst_qstring.cpp @@ -5824,6 +5824,8 @@ void tst_QString::split(const QString &string, const QString &sep, QStringList r QVERIFY(list == result); } +QT_WARNING_PUSH +QT_WARNING_DISABLE_DEPRECATED list = str.split(sep, QString::KeepEmptyParts); QVERIFY(list == result); list = str.split(rx, QString::KeepEmptyParts); @@ -5846,6 +5848,7 @@ void tst_QString::split(const QString &string, const QString &sep, QStringList r list = str.split(sep.at(0), QString::SkipEmptyParts); QVERIFY(list == result); } +QT_WARNING_POP } void tst_QString::split() -- cgit v1.2.3 From b4669b919048c1dbdac2b3e9b2e79f3d023aa078 Mon Sep 17 00:00:00 2001 From: Volker Hilsheimer Date: Wed, 26 Feb 2020 16:59:52 +0100 Subject: QMenu: hide when a QWidgetAction fires the trigged signal QMenu hides regularly when the user interacts with it, and manages the firing of signals based on that. It ignores if a QAction that is added to it fires the triggered() signal programmatically. With QWidgetActions added to the menu, the menu usually doesn't get interacted with directly, as the widget gets the input events. Since the action can be added to multiple menus, neither widget nor action can interact with the menus programmatically. Instead, the menu needs to hide when the widget action triggers. Test included that covers the case where a QWidgetAction is added to multiple menus that are visible. Documentation updated, and removed a redudant paragraph as a drive-by change. [ChangeLog][QtWidgets][QMenu] a popup menu hides when a QWidgetAction added to it fires the triggered signal. Change-Id: I69f378426a45c2e46cebdaa5e6f1b21c8fb03633 Fixes: QTBUG-10427 Reviewed-by: Richard Moe Gustavsen --- tests/auto/widgets/widgets/qmenu/tst_qmenu.cpp | 79 ++++++++++++++++++++++++++ 1 file changed, 79 insertions(+) (limited to 'tests') diff --git a/tests/auto/widgets/widgets/qmenu/tst_qmenu.cpp b/tests/auto/widgets/widgets/qmenu/tst_qmenu.cpp index d7d3a934f8..7e39138473 100644 --- a/tests/auto/widgets/widgets/qmenu/tst_qmenu.cpp +++ b/tests/auto/widgets/widgets/qmenu/tst_qmenu.cpp @@ -116,6 +116,7 @@ private slots: void QTBUG20403_nested_popup_on_shortcut_trigger(); void QTBUG47515_widgetActionEnterLeave(); void QTBUG8122_widgetActionCrashOnClose(); + void widgetActionTriggerClosesMenu(); void QTBUG_10735_crashWithDialog(); #ifdef Q_OS_MAC @@ -1407,6 +1408,84 @@ void tst_QMenu::QTBUG8122_widgetActionCrashOnClose() QTRY_VERIFY(menu->isHidden()); } +/*! + Test that a QWidgetAction that fires closes the menus that it is in. +*/ +void tst_QMenu::widgetActionTriggerClosesMenu() +{ + class ButtonAction : public QWidgetAction + { + public: + ButtonAction() + : QWidgetAction(nullptr) + {} + + void click() + { + if (pushButton) + pushButton->click(); + } + + protected: + QWidget *createWidget(QWidget *parent) + { + QPushButton *button = new QPushButton(QLatin1String("Button"), parent); + connect(button, &QPushButton::clicked, this, &QAction::trigger); + + if (!pushButton) + pushButton = button; + return button; + } + + private: + QPointer pushButton; + }; + + QMenu menu; + QMenu submenu; + + int menuTriggeredCount = 0; + int menuAboutToHideCount = 0; + QAction *actionTriggered = nullptr; + + connect(&menu, &QMenu::triggered, this, [&](QAction *action){ + ++menuTriggeredCount; + actionTriggered = action; + }); + connect (&menu, &QMenu::aboutToHide, this, [&](){ + ++menuAboutToHideCount; + }); + + QAction regularAction(QLatin1String("Action")); + ButtonAction widgetAction; + + submenu.addAction(®ularAction); + submenu.addAction(&widgetAction); + + menu.addMenu(&submenu); + menu.addAction(®ularAction); + menu.addAction(&widgetAction); + + menu.popup(QPoint(200,200)); + submenu.popup(QPoint(250,250)); + if (!QTest::qWaitForWindowExposed(&menu) || !QTest::qWaitForWindowExposed(&submenu)) + QSKIP("Failed to show menus, aborting test"); + + regularAction.trigger(); + QVERIFY(menu.isVisible()); + QVERIFY(submenu.isVisible()); + QCOMPARE(menuTriggeredCount, 1); + QCOMPARE(actionTriggered, ®ularAction); + menuTriggeredCount = 0; + actionTriggered = nullptr; + + widgetAction.click(); + QVERIFY(!menu.isVisible()); + QVERIFY(!submenu.isVisible()); + QCOMPARE(menuTriggeredCount, 1); + QCOMPARE(menuAboutToHideCount, 1); + QCOMPARE(actionTriggered, &widgetAction); +} class MyMenu : public QMenu { -- cgit v1.2.3 From 14420b359b2d14d202df8df841af5e88f16352a7 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ivan=20=C4=8Cuki=C4=87?= Date: Fri, 10 Jan 2020 18:13:41 +0100 Subject: Add operator-> to the key-value iterator for QHash and QMap This patch adds the arrow operator to the stl-like key-value iterator (QKeyValueIterator) for QMap and QHash. This allows using normal member access syntax it->first and it->second instead of having to use (*it).first and (*it).second. [ChangeLog][QtCore][Containers] Added operator-> to the key-value iterator for QHash/QMap. Change-Id: I9cfa6480784ebce147fcfbf37fec5ad0080e2899 Reviewed-by: Vitaly Fanaskov --- tests/auto/corelib/tools/qhash/tst_qhash.cpp | 6 ++++++ tests/auto/corelib/tools/qmap/tst_qmap.cpp | 6 ++++++ 2 files changed, 12 insertions(+) (limited to 'tests') diff --git a/tests/auto/corelib/tools/qhash/tst_qhash.cpp b/tests/auto/corelib/tools/qhash/tst_qhash.cpp index b98ac38288..134b3ff4c0 100644 --- a/tests/auto/corelib/tools/qhash/tst_qhash.cpp +++ b/tests/auto/corelib/tools/qhash/tst_qhash.cpp @@ -1144,6 +1144,12 @@ void tst_QHash::keyValueIterator() entry_type pair(it.key(), it.value()); QCOMPARE(*key_value_it, pair); + QCOMPARE(key_value_it->first, pair.first); + QCOMPARE(key_value_it->second, pair.second); + QCOMPARE(&(*key_value_it).first, &it.key()); + QCOMPARE(&key_value_it->first, &it.key()); + QCOMPARE(&(*key_value_it).second, &it.value()); + QCOMPARE(&key_value_it->second, &it.value()); ++key_value_it; ++it; } diff --git a/tests/auto/corelib/tools/qmap/tst_qmap.cpp b/tests/auto/corelib/tools/qmap/tst_qmap.cpp index c3a8a88f0c..ba4b190f06 100644 --- a/tests/auto/corelib/tools/qmap/tst_qmap.cpp +++ b/tests/auto/corelib/tools/qmap/tst_qmap.cpp @@ -882,6 +882,12 @@ void tst_QMap::keyValueIterator() entry_type pair(it.key(), it.value()); QCOMPARE(*key_value_it, pair); + QCOMPARE(key_value_it->first, pair.first); + QCOMPARE(key_value_it->second, pair.second); + QCOMPARE(&(*key_value_it).first, &it.key()); + QCOMPARE(&key_value_it->first, &it.key()); + QCOMPARE(&(*key_value_it).second, &it.value()); + QCOMPARE(&key_value_it->second, &it.value()); ++key_value_it; ++it; } -- cgit v1.2.3