diff options
Diffstat (limited to 'tests/auto')
18 files changed, 425 insertions, 208 deletions
diff --git a/tests/auto/cmake/CMakeLists.txt b/tests/auto/cmake/CMakeLists.txt index 51d0d2879e..5b10a74d3f 100644 --- a/tests/auto/cmake/CMakeLists.txt +++ b/tests/auto/cmake/CMakeLists.txt @@ -146,7 +146,12 @@ endif() expect_pass(test_interface_link_libraries) expect_pass(test_moc_macro_target) -expect_pass(test_add_big_resource) + +if (NOT CMAKE_VERSION VERSION_LESS 3.9) + # The modification of TARGET_OBJECTS needs the following change in cmake + # https://gitlab.kitware.com/cmake/cmake/commit/93c89bc75ceee599ba7c08b8fe1ac5104942054f + expect_pass(test_add_big_resource) +endif() if (NOT CMAKE_VERSION VERSION_LESS 3.8) # With earlier CMake versions, this test would simply run moc multiple times and lead to: diff --git a/tests/auto/cmake/test_add_big_resource/CMakeLists.txt b/tests/auto/cmake/test_add_big_resource/CMakeLists.txt index f928b11278..45ed2c79d5 100644 --- a/tests/auto/cmake/test_add_big_resource/CMakeLists.txt +++ b/tests/auto/cmake/test_add_big_resource/CMakeLists.txt @@ -1,5 +1,5 @@ -cmake_minimum_required(VERSION 2.8) +cmake_minimum_required(VERSION 3.9) project(test_add_big_resource) diff --git a/tests/auto/corelib/global/qfloat16/tst_qfloat16.cpp b/tests/auto/corelib/global/qfloat16/tst_qfloat16.cpp index 0848a4160f..5c7737085e 100644 --- a/tests/auto/corelib/global/qfloat16/tst_qfloat16.cpp +++ b/tests/auto/corelib/global/qfloat16/tst_qfloat16.cpp @@ -174,9 +174,9 @@ void tst_qfloat16::qNan() QVERIFY(qIsInf(-inf)); QVERIFY(qIsInf(2.f*inf)); QVERIFY(qIsInf(inf*2.f)); - // QTBUG-75812: QEMU's over-optimized arm64 flakily fails 1/inf == 0 :-( + // QTBUG-75812: QEMU/arm64 compiler over-optimizes, so flakily fails 1/inf == 0 :-( if (qfloat16(9.785e-4f) == qfloat16(9.794e-4f)) - QCOMPARE(qfloat16(1.f/inf), qfloat16(0.f)); + QCOMPARE(qfloat16(1.f) / inf, qfloat16(0.f)); #ifdef Q_CC_INTEL QEXPECT_FAIL("", "ICC optimizes zero * anything to zero", Continue); #endif diff --git a/tests/auto/corelib/io/qfileselector/tst_qfileselector.cpp b/tests/auto/corelib/io/qfileselector/tst_qfileselector.cpp index c9f1e3d9f6..11b1fdaeeb 100644 --- a/tests/auto/corelib/io/qfileselector/tst_qfileselector.cpp +++ b/tests/auto/corelib/io/qfileselector/tst_qfileselector.cpp @@ -205,15 +205,23 @@ void tst_QFileSelector::urlConvenience_data() QString test("/test");// '/' is here so dir string can also be selector string QString custom1("custom1"); + QString testWithQueryAndFragment("/test?query#Fragment"); QTest::newRow("qrc") << QUrl("qrc:///extras/test") << (QStringList() << custom1) << QUrl(QString("qrc:///extras/") + QLatin1Char(selectorIndicator) + custom1 + test); + QTest::newRow("qrc with query and fragment") << QUrl(QString::fromLatin1("qrc:///extras%1").arg(testWithQueryAndFragment)) << (QStringList() << custom1) + << QUrl(QString("qrc:///extras/") + QLatin1Char(selectorIndicator) + custom1 + testWithQueryAndFragment); QString fileBasePath = QFINDTESTDATA("extras/test"); QString fileSelectedPath = QFINDTESTDATA(QString("extras/") + QLatin1Char(selectorIndicator) + custom1 + QString("/test")); QTest::newRow("file") << QUrl::fromLocalFile(fileBasePath) << (QStringList() << custom1) << QUrl::fromLocalFile(fileSelectedPath); + // do not strip off the query and fragment + QString strUrlWithFragment = QString("file://") + testWithQueryAndFragment; + QTest::newRow("file with query and fragment") << QUrl(strUrlWithFragment) << (QStringList()) << QUrl(strUrlWithFragment); + strUrlWithFragment = QString("file:") + testWithQueryAndFragment; + QTest::newRow("file with query and fragment too") << QUrl(strUrlWithFragment) << (QStringList()) << QUrl(strUrlWithFragment); // http://qt-project.org/images/qtdn/sprites-combined-latest.png is chosen as a representative real world URL // But note that this test is checking that http urls are NOT selected so it shouldn't be checked diff --git a/tests/auto/corelib/serialization/qdatastream/tst_qdatastream.cpp b/tests/auto/corelib/serialization/qdatastream/tst_qdatastream.cpp index 19cdd42a74..c80f4f47b2 100644 --- a/tests/auto/corelib/serialization/qdatastream/tst_qdatastream.cpp +++ b/tests/auto/corelib/serialization/qdatastream/tst_qdatastream.cpp @@ -185,6 +185,7 @@ private slots: void floatingPointPrecision(); + void compatibility_Qt5(); void compatibility_Qt3(); void compatibility_Qt2(); @@ -271,17 +272,17 @@ static int NColorRoles[] = { QPalette::HighlightedText + 1, // Qt_4_0, Qt_4_1 QPalette::HighlightedText + 1, // Qt_4_2 QPalette::AlternateBase + 1, // Qt_4_3 - QPalette::PlaceholderText + 1, // Qt_4_4 - QPalette::PlaceholderText + 1, // Qt_4_5 - QPalette::PlaceholderText + 1, // Qt_4_6 - QPalette::PlaceholderText + 1, // Qt_5_0 - QPalette::PlaceholderText + 1, // Qt_5_1 - QPalette::PlaceholderText + 1, // Qt_5_2 - QPalette::PlaceholderText + 1, // Qt_5_3 - QPalette::PlaceholderText + 1, // Qt_5_4 - QPalette::PlaceholderText + 1, // Qt_5_5 - QPalette::PlaceholderText + 1, // Qt_5_6 - 0 // add the correct value for Qt_5_7 here later + QPalette::ToolTipText + 1, // Qt_4_4 + QPalette::ToolTipText + 1, // Qt_4_5 + QPalette::ToolTipText + 1, // Qt_4_6, Qt_4_7, Qt_4_8, Qt_4_9 + QPalette::ToolTipText + 1, // Qt_5_0 + QPalette::ToolTipText + 1, // Qt_5_1 + QPalette::ToolTipText + 1, // Qt_5_2, Qt_5_3 + QPalette::ToolTipText + 1, // Qt_5_4, Qt_5_5 + QPalette::ToolTipText + 1, // Qt_5_6, Qt_5_7, Qt_5_8, Qt_5_9, Qt_5_10, Qt_5_11 + QPalette::PlaceholderText + 1, // Qt_5_12 + QPalette::PlaceholderText + 1, // Qt_5_13 + 0 // add the correct value for Qt_5_14 here later }; // Testing get/set functions @@ -3245,6 +3246,37 @@ void tst_QDataStream::streamRealDataTypes() } } +void tst_QDataStream::compatibility_Qt5() +{ + QLinearGradient gradient(QPointF(0,0), QPointF(1,1)); + gradient.setColorAt(0, Qt::red); + gradient.setColorAt(1, Qt::blue); + + QBrush brush(gradient); + QPalette palette; + palette.setBrush(QPalette::Button, brush); + palette.setColor(QPalette::Light, Qt::green); + + QByteArray stream; + { + QDataStream out(&stream, QIODevice::WriteOnly); + out.setVersion(QDataStream::Qt_5_7); + out << palette; + out << brush; + } + QBrush in_brush; + QPalette in_palette; + { + QDataStream in(stream); + in.setVersion(QDataStream::Qt_5_7); + in >> in_palette; + in >> in_brush; + } + QCOMPARE(in_brush.style(), Qt::LinearGradientPattern); + QCOMPARE(in_palette.brush(QPalette::Button).style(), Qt::LinearGradientPattern); + QCOMPARE(in_palette.color(QPalette::Light), QColor(Qt::green)); +} + void tst_QDataStream::compatibility_Qt3() { QByteArray ba("hello"); diff --git a/tests/auto/corelib/tools/qregexp/tst_qregexp.cpp b/tests/auto/corelib/tools/qregexp/tst_qregexp.cpp index a98d37d733..a8111af6c1 100644 --- a/tests/auto/corelib/tools/qregexp/tst_qregexp.cpp +++ b/tests/auto/corelib/tools/qregexp/tst_qregexp.cpp @@ -834,6 +834,13 @@ void tst_QRegExp::testEscapingWildcard_data(){ QTest::newRow("a true '\\' in input") << "\\Qt;" << "\\Qt;" << true; QTest::newRow("two true '\\' in input") << "\\\\Qt;" << "\\\\Qt;" << true; QTest::newRow("a '\\' at the end") << "\\\\Qt;\\" << "\\\\Qt;\\" << true; + + QTest::newRow("[]\\] matches ]") << "[]\\]" << "]" << true; + QTest::newRow("[]\\] matches \\") << "[]\\]" << "\\" << true; + QTest::newRow("[]\\] does not match [") << "[]\\]" << "[" << false; + QTest::newRow("[]\\]a matches ]a") << "[]\\]a" << "]a" << true; + QTest::newRow("[]\\]a matches \\a") << "[]\\]a" << "\\a" << true; + QTest::newRow("[]\\]a does not match [a") << "[]\\]a" << "[a" << false; } void tst_QRegExp::testEscapingWildcard(){ diff --git a/tests/auto/corelib/tools/qsharedpointer/tst_qsharedpointer.cpp b/tests/auto/corelib/tools/qsharedpointer/tst_qsharedpointer.cpp index 42792b5310..d0bc237a5d 100644 --- a/tests/auto/corelib/tools/qsharedpointer/tst_qsharedpointer.cpp +++ b/tests/auto/corelib/tools/qsharedpointer/tst_qsharedpointer.cpp @@ -40,6 +40,7 @@ #include "nontracked.h" #include "wrapper.h" +#include <memory> #include <stdlib.h> #include <time.h> @@ -231,6 +232,12 @@ struct NoDefaultConstructorRRef1 NoDefaultConstructorRRef1(int &&i) : i(i) {} }; +struct NoDefaultConstructorRRef2 +{ + std::unique_ptr<int> i; + NoDefaultConstructorRRef2(std::unique_ptr<int> &&i) : i(std::move(i)) {} +}; + void tst_QSharedPointer::basics_data() { QTest::addColumn<bool>("isNull"); @@ -1865,15 +1872,20 @@ void tst_QSharedPointer::creatingVariadic() QCOMPARE(&ptr->i, &i); } { - NoDefaultConstructorRRef1(1); // control check - QSharedPointer<NoDefaultConstructorRRef1> ptr = QSharedPointer<NoDefaultConstructorRRef1>::create(1); - QCOMPARE(ptr->i, 1); - NoDefaultConstructorRRef1(std::move(i)); // control check - ptr = QSharedPointer<NoDefaultConstructorRRef1>::create(std::move(i)); + QSharedPointer<NoDefaultConstructorRRef1> ptr = QSharedPointer<NoDefaultConstructorRRef1>::create(std::move(i)); QCOMPARE(ptr->i, i); } { + NoDefaultConstructorRRef2(std::unique_ptr<int>(new int(1))); // control check + QSharedPointer<NoDefaultConstructorRRef2> ptr = QSharedPointer<NoDefaultConstructorRRef2>::create(std::unique_ptr<int>(new int(1))); + QCOMPARE(*ptr->i, 1); + + std::unique_ptr<int> p(new int(i)); + ptr = QSharedPointer<NoDefaultConstructorRRef2>::create(std::move(p)); + QCOMPARE(*ptr->i, i); + } + { QString text("Hello, World"); NoDefaultConstructorRef2(text, 1); // control check QSharedPointer<NoDefaultConstructorRef2> ptr = QSharedPointer<NoDefaultConstructorRef2>::create(text, 1); diff --git a/tests/auto/gui/text/qtextdocument/tst_qtextdocument.cpp b/tests/auto/gui/text/qtextdocument/tst_qtextdocument.cpp index 97546c34fd..a07181c199 100644 --- a/tests/auto/gui/text/qtextdocument/tst_qtextdocument.cpp +++ b/tests/auto/gui/text/qtextdocument/tst_qtextdocument.cpp @@ -319,6 +319,15 @@ void tst_QTextDocument::find_data() QTest::newRow("nbsp") << "Hello" + QString(QChar(QChar::Nbsp)) +"World" << " " << int(QTextDocument::FindCaseSensitively) << 0 << 5 << 6; QTest::newRow("from-the-end") << "Hello World" << "Hello World" << int(QTextDocument::FindCaseSensitively| QTextDocument::FindBackward) << 11 << 0 << 11; + + QTest::newRow("bw-cross-paras-1") << "a1\na2\nb1" << "a" << int(QTextDocument::FindBackward) << 7 << 3 << 4; + QTest::newRow("bw-cross-paras-2") << "a1\na2\nb1" << "a" << int(QTextDocument::FindBackward) << 6 << 3 << 4; + QTest::newRow("bw-cross-paras-3") << "a1\na2\nb1" << "a" << int(QTextDocument::FindBackward) << 5 << 3 << 4; + QTest::newRow("bw-cross-paras-4") << "a1\na2\nb1" << "a" << int(QTextDocument::FindBackward) << 3 << 0 << 1; + QTest::newRow("bw-cross-paras-5") << "xa\n\nb1" << "a" << int(QTextDocument::FindBackward) << 5 << 1 << 2; + QTest::newRow("bw-cross-paras-6") << "xa\n\nb1" << "a" << int(QTextDocument::FindBackward) << 4 << 1 << 2; + QTest::newRow("bw-cross-paras-7") << "xa\n\nb1" << "a" << int(QTextDocument::FindBackward) << 3 << 1 << 2; + QTest::newRow("bw-cross-paras-8") << "xa\n\nb1" << "a" << int(QTextDocument::FindBackward) << 2 << 1 << 2; } void tst_QTextDocument::find() diff --git a/tests/auto/network/access/qnetworkreply/tst_qnetworkreply.cpp b/tests/auto/network/access/qnetworkreply/tst_qnetworkreply.cpp index 3e5f38d4bc..ca870f1cbb 100644 --- a/tests/auto/network/access/qnetworkreply/tst_qnetworkreply.cpp +++ b/tests/auto/network/access/qnetworkreply/tst_qnetworkreply.cpp @@ -5036,6 +5036,9 @@ public: // very similar to ioPostToHttpUploadProgress but for SSL void tst_QNetworkReply::ioPostToHttpsUploadProgress() { +#ifdef Q_OS_WIN + QSKIP("QTBUG-76157: get rid of locking in TLS handshake (QSslSocket)"); +#endif //QFile sourceFile(testDataDir + "/bigfile"); //QVERIFY(sourceFile.open(QIODevice::ReadOnly)); qint64 wantedSize = 2*1024*1024; // 2 MB @@ -6417,6 +6420,10 @@ void tst_QNetworkReply::encrypted() void tst_QNetworkReply::abortOnEncrypted() { +#ifdef Q_OS_WIN + QSKIP("QTBUG-76157: get rid of locking in TLS handshake (QSslSocket)"); +#endif + SslServer server; server.listen(); if (!server.isListening()) @@ -8496,7 +8503,9 @@ void tst_QNetworkReply::ioHttpRedirectErrors_data() QTest::newRow("too-many-redirects") << "http://localhost" << tempRedirectReply << QNetworkReply::TooManyRedirectsError; #if QT_CONFIG(ssl) +#ifndef Q_OS_WIN // QTBUG-76157 QTest::newRow("insecure-redirect") << "https://localhost" << tempRedirectReply << QNetworkReply::InsecureRedirectError; +#endif // Q_OS_WIN #endif QTest::newRow("unknown-redirect") << "http://localhost"<< tempRedirectReply.replace("http", "bad_protocol") << QNetworkReply::ProtocolUnknownError; } @@ -8573,9 +8582,11 @@ void tst_QNetworkReply::ioHttpRedirectPolicy_data() QTest::newRow("nolesssafe-nossl") << QNetworkRequest::NoLessSafeRedirectPolicy << false << 1 << 200; QTest::newRow("same-origin-nossl") << QNetworkRequest::SameOriginRedirectPolicy << false << 1 << 200; #if QT_CONFIG(ssl) +#ifndef Q_OS_WIN // QTBUG-76157 QTest::newRow("manual-ssl") << QNetworkRequest::ManualRedirectPolicy << true << 0 << 307; QTest::newRow("nolesssafe-ssl") << QNetworkRequest::NoLessSafeRedirectPolicy << true << 1 << 200; QTest::newRow("same-origin-ssl") << QNetworkRequest::SameOriginRedirectPolicy << true << 1 << 200; +#endif // Q_OS_WIN #endif } @@ -8629,33 +8640,41 @@ void tst_QNetworkReply::ioHttpRedirectPolicyErrors_data() QTest::newRow("nolesssafe-nossl-nossl-too-many") << QNetworkRequest::NoLessSafeRedirectPolicy << false << QString("http://localhost:%1") << 0 << QNetworkReply::TooManyRedirectsError; #if QT_CONFIG(ssl) +#ifndef Q_OS_WIN // QTBUG-76157 QTest::newRow("nolesssafe-ssl-ssl-too-many") << QNetworkRequest::NoLessSafeRedirectPolicy << true << QString("https:/localhost:%1") << 0 << QNetworkReply::TooManyRedirectsError; QTest::newRow("nolesssafe-ssl-nossl-insecure-redirect") << QNetworkRequest::NoLessSafeRedirectPolicy << true << QString("http://localhost:%1") << 50 << QNetworkReply::InsecureRedirectError; +#endif // Q_OS_WIN #endif // 2. SameOriginRedirectsPolicy QTest::newRow("same-origin-nossl-nossl-too-many") << QNetworkRequest::SameOriginRedirectPolicy << false << QString("http://localhost:%1") << 0 << QNetworkReply::TooManyRedirectsError; #if QT_CONFIG(ssl) +#ifndef Q_OS_WIN // QTBUG-76157 QTest::newRow("same-origin-ssl-ssl-too-many") << QNetworkRequest::SameOriginRedirectPolicy << true << QString("https://localhost:%1") << 0 << QNetworkReply::TooManyRedirectsError; QTest::newRow("same-origin-https-http-wrong-protocol") << QNetworkRequest::SameOriginRedirectPolicy << true << QString("http://localhost:%1") << 50 << QNetworkReply::InsecureRedirectError; +#endif // Q_OS_WIN #endif QTest::newRow("same-origin-http-https-wrong-protocol") << QNetworkRequest::SameOriginRedirectPolicy << false << QString("https://localhost:%1") << 50 << QNetworkReply::InsecureRedirectError; QTest::newRow("same-origin-http-http-wrong-host") << QNetworkRequest::SameOriginRedirectPolicy << false << QString("http://not-so-localhost:%1") << 50 << QNetworkReply::InsecureRedirectError; #if QT_CONFIG(ssl) +#ifndef Q_OS_WIN // QTBUG-76157 QTest::newRow("same-origin-https-https-wrong-host") << QNetworkRequest::SameOriginRedirectPolicy << true << QString("https://not-so-localhost:%1") << 50 << QNetworkReply::InsecureRedirectError; +#endif // Q_OS_WIN #endif QTest::newRow("same-origin-http-http-wrong-port") << QNetworkRequest::SameOriginRedirectPolicy << false << QString("http://localhost/%1") << 50 << QNetworkReply::InsecureRedirectError; #if QT_CONFIG(ssl) +#ifndef Q_OS_WIN // QTBUG-76157 QTest::newRow("same-origin-https-https-wrong-port") << QNetworkRequest::SameOriginRedirectPolicy << true << QString("https://localhost/%1") << 50 << QNetworkReply::InsecureRedirectError; +#endif // Q_OS_WIN #endif } @@ -9130,6 +9149,10 @@ void tst_QNetworkReply::putWithServerClosingConnectionImmediately() for (int s = 0; s <= 1; s++) { withSsl = (s == 1); +#ifdef Q_OS_WIN + if (withSsl) + QSKIP("QTBUG-76157: get rid of locking in TLS handshake (QSslSocket)"); +#endif // Q_OS_WIN // Test also needs to run several times because of 9c2ecf89 for (int j = 0; j < 20; j++) { // emulate a minimal https server diff --git a/tests/auto/shared/highdpi.h b/tests/auto/shared/highdpi.h new file mode 100644 index 0000000000..f0c34bea25 --- /dev/null +++ b/tests/auto/shared/highdpi.h @@ -0,0 +1,109 @@ +/**************************************************************************** +** +** 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$ +** +****************************************************************************/ + +#ifndef HIGHDPI_H +#define HIGHDPI_H + +#include <QtCore/qbytearray.h> +#include <QtCore/qpoint.h> +#include <QtCore/qrect.h> +#include <QtCore/qsize.h> + +// Helpers for comparing geometries a that may go through scaling in the +// platform plugin with fuzz (pass rounded-down device pixel ratios or +// scaling factors). Error message for use with QVERIFY2() are also provided. + +class HighDpi +{ +public: + HighDpi() = delete; + HighDpi(const HighDpi &) = delete; + HighDpi &operator=(const HighDpi &) = delete; + HighDpi(HighDpi &&) = delete; + HighDpi &operator=(HighDpi &&) = delete; + ~HighDpi() = delete; + + static int manhattanDelta(const QPoint &p1, const QPoint p2) + { + return (p1 - p2).manhattanLength(); + } + + static bool fuzzyCompare(const QPoint &p1, const QPoint p2, int fuzz) + { + return manhattanDelta(p1, p2) <= fuzz; + } + + static QByteArray msgPointMismatch(const QPoint &p1, const QPoint p2) + { + return QByteArray::number(p1.x()) + ',' + QByteArray::number(p1.y()) + + " != " + QByteArray::number(p2.x()) + ',' + QByteArray::number(p2.y()) + + ", manhattanLength=" + QByteArray::number(manhattanDelta(p1, p2)); + } + + // Compare a size that may go through scaling in the platform plugin with fuzz. + + static inline int manhattanDelta(const QSize &s1, const QSize &s2) + { + return qAbs(s1.width() - s2.width()) + qAbs(s1.height() - s2.height()); + } + + static inline bool fuzzyCompare(const QSize &s1, const QSize &s2, int fuzz) + { + return manhattanDelta(s1, s2) <= fuzz; + } + + static QByteArray msgSizeMismatch(const QSize &s1, const QSize &s2) + { + return QByteArray::number(s1.width()) + 'x' + QByteArray::number(s1.height()) + + " != " + QByteArray::number(s2.width()) + 'x' + QByteArray::number(s2.height()) + + ", manhattanLength=" + QByteArray::number(manhattanDelta(s1, s2)); + } + + // Compare a geometry that may go through scaling in the platform plugin with fuzz. + + static inline bool fuzzyCompare(const QRect &r1, const QRect &r2, int fuzz) + { + return manhattanDelta(r1.topLeft(), r2.topLeft()) <= fuzz + && manhattanDelta(r1.size(), r2.size()) <= fuzz; + } + + static QByteArray msgRectMismatch(const QRect &r1, const QRect &r2) + { + return formatRect(r1) + " != " + formatRect(r2); + } + +private: + static QByteArray formatRect(const QRect &r) + { + return QByteArray::number(r.width()) + 'x' + QByteArray::number(r.height()) + + (r.left() < 0 ? '-' : '+') + QByteArray::number(r.left()) + + (r.top() < 0 ? '-' : '+') + QByteArray::number(r.top()); + } +}; + +#endif // HIGHDPI_H diff --git a/tests/auto/widgets/dialogs/qdialog/tst_qdialog.cpp b/tests/auto/widgets/dialogs/qdialog/tst_qdialog.cpp index afe49368ae..c840dabc1a 100644 --- a/tests/auto/widgets/dialogs/qdialog/tst_qdialog.cpp +++ b/tests/auto/widgets/dialogs/qdialog/tst_qdialog.cpp @@ -26,6 +26,7 @@ ** ****************************************************************************/ +#include "../../../shared/highdpi.h" #include <QtTest/QtTest> @@ -388,8 +389,10 @@ void tst_QDialog::toolDialogPosition() dialog.move(QPoint(100,100)); const QPoint beforeShowPosition = dialog.pos(); dialog.show(); + const int fuzz = int(dialog.devicePixelRatioF()); const QPoint afterShowPosition = dialog.pos(); - QCOMPARE(afterShowPosition, beforeShowPosition); + QVERIFY2(HighDpi::fuzzyCompare(afterShowPosition, beforeShowPosition, fuzz), + HighDpi::msgPointMismatch(afterShowPosition, beforeShowPosition).constData()); } class Dialog : public QDialog diff --git a/tests/auto/widgets/dialogs/qwizard/tst_qwizard.cpp b/tests/auto/widgets/dialogs/qwizard/tst_qwizard.cpp index a5b8646d40..63f6e67a3e 100644 --- a/tests/auto/widgets/dialogs/qwizard/tst_qwizard.cpp +++ b/tests/auto/widgets/dialogs/qwizard/tst_qwizard.cpp @@ -2551,7 +2551,7 @@ void tst_QWizard::task183550_stretchFactor() page2->enableVerticalExpansion(); wizard.next(); QCOMPARE(wizard.currentPage(), static_cast<QWizardPage*>(page2)); - QVERIFY(page2->treeWidgetHeight() > page2->treeWidgetSizeHintHeight()); + QVERIFY(page2->treeWidgetHeight() >= page2->treeWidgetSizeHintHeight()); wizard.back(); QCOMPARE(wizard.currentPage(), static_cast<QWizardPage*>(page1)); diff --git a/tests/auto/widgets/graphicsview/qgraphicsview/BLACKLIST b/tests/auto/widgets/graphicsview/qgraphicsview/BLACKLIST index e3d968b4f2..ee13a37212 100644 --- a/tests/auto/widgets/graphicsview/qgraphicsview/BLACKLIST +++ b/tests/auto/widgets/graphicsview/qgraphicsview/BLACKLIST @@ -4,6 +4,7 @@ xcb xcb [cursor2] xcb +windows [rubberBandExtendSelection] xcb [rotated_rubberBand] diff --git a/tests/auto/widgets/graphicsview/qgraphicsview/tst_qgraphicsview.cpp b/tests/auto/widgets/graphicsview/qgraphicsview/tst_qgraphicsview.cpp index efee901227..6e42758122 100644 --- a/tests/auto/widgets/graphicsview/qgraphicsview/tst_qgraphicsview.cpp +++ b/tests/auto/widgets/graphicsview/qgraphicsview/tst_qgraphicsview.cpp @@ -2280,53 +2280,53 @@ void tst_QGraphicsView::cursor2() QVERIFY(QTest::qWaitForWindowExposed(&view)); sendMouseMove(view.viewport(), view.mapFromScene(-30, -30)); - QCOMPARE(view.viewport()->cursor().shape(), Qt::PointingHandCursor); + QTRY_COMPARE(view.viewport()->cursor().shape(), Qt::PointingHandCursor); sendMouseMove(view.viewport(), view.mapFromScene(0, 0)); - QCOMPARE(view.viewport()->cursor().shape(), Qt::IBeamCursor); + QTRY_COMPARE(view.viewport()->cursor().shape(), Qt::IBeamCursor); sendMouseMove(view.viewport(), view.mapFromScene(-30, -30)); - QCOMPARE(view.viewport()->cursor().shape(), Qt::PointingHandCursor); + QTRY_COMPARE(view.viewport()->cursor().shape(), Qt::PointingHandCursor); sendMouseMove(view.viewport(), view.mapFromScene(0, 0)); - QCOMPARE(view.viewport()->cursor().shape(), Qt::IBeamCursor); + QTRY_COMPARE(view.viewport()->cursor().shape(), Qt::IBeamCursor); sendMouseMove(view.viewport(), view.mapFromScene(-15, 0)); - QCOMPARE(view.viewport()->cursor().shape(), Qt::PointingHandCursor); + QTRY_COMPARE(view.viewport()->cursor().shape(), Qt::PointingHandCursor); view.setDragMode(QGraphicsView::ScrollHandDrag); sendMouseMove(view.viewport(), view.mapFromScene(-30, -30)); - QCOMPARE(view.viewport()->cursor().shape(), Qt::OpenHandCursor); + QTRY_COMPARE(view.viewport()->cursor().shape(), Qt::OpenHandCursor); sendMouseMove(view.viewport(), view.mapFromScene(0, 0)); - QCOMPARE(view.viewport()->cursor().shape(), Qt::IBeamCursor); + QTRY_COMPARE(view.viewport()->cursor().shape(), Qt::IBeamCursor); sendMouseMove(view.viewport(), view.mapFromScene(-15, -15)); - QCOMPARE(view.viewport()->cursor().shape(), Qt::OpenHandCursor); + QTRY_COMPARE(view.viewport()->cursor().shape(), Qt::OpenHandCursor); view.setDragMode(QGraphicsView::NoDrag); - QCOMPARE(view.viewport()->cursor().shape(), Qt::ArrowCursor); + QTRY_COMPARE(view.viewport()->cursor().shape(), Qt::ArrowCursor); view.viewport()->setCursor(Qt::PointingHandCursor); - QCOMPARE(view.viewport()->cursor().shape(), Qt::PointingHandCursor); + QTRY_COMPARE(view.viewport()->cursor().shape(), Qt::PointingHandCursor); item2->setCursor(Qt::SizeAllCursor); sendMouseMove(view.viewport(), view.mapFromScene(-30, -30)); - QCOMPARE(view.viewport()->cursor().shape(), Qt::PointingHandCursor); + QTRY_COMPARE(view.viewport()->cursor().shape(), Qt::PointingHandCursor); sendMouseMove(view.viewport(), view.mapFromScene(-15, -15)); - QCOMPARE(view.viewport()->cursor().shape(), Qt::SizeAllCursor); + QTRY_COMPARE(view.viewport()->cursor().shape(), Qt::SizeAllCursor); sendMouseMove(view.viewport(), view.mapFromScene(0, 0)); - QCOMPARE(view.viewport()->cursor().shape(), Qt::IBeamCursor); + QTRY_COMPARE(view.viewport()->cursor().shape(), Qt::IBeamCursor); sendMouseMove(view.viewport(), view.mapFromScene(-15, -15)); - QCOMPARE(view.viewport()->cursor().shape(), Qt::SizeAllCursor); + QTRY_COMPARE(view.viewport()->cursor().shape(), Qt::SizeAllCursor); sendMouseMove(view.viewport(), view.mapFromScene(0, 0)); - QCOMPARE(view.viewport()->cursor().shape(), Qt::IBeamCursor); + QTRY_COMPARE(view.viewport()->cursor().shape(), Qt::IBeamCursor); sendMouseMove(view.viewport(), view.mapFromScene(-30, -30)); - QCOMPARE(view.viewport()->cursor().shape(), Qt::PointingHandCursor); + QTRY_COMPARE(view.viewport()->cursor().shape(), Qt::PointingHandCursor); view.setDragMode(QGraphicsView::ScrollHandDrag); sendMouseMove(view.viewport(), view.mapFromScene(-30, -30)); - QCOMPARE(view.viewport()->cursor().shape(), Qt::OpenHandCursor); + QTRY_COMPARE(view.viewport()->cursor().shape(), Qt::OpenHandCursor); sendMouseMove(view.viewport(), view.mapFromScene(0, 0)); - QCOMPARE(view.viewport()->cursor().shape(), Qt::IBeamCursor); + QTRY_COMPARE(view.viewport()->cursor().shape(), Qt::IBeamCursor); sendMouseMove(view.viewport(), view.mapFromScene(-15, -15)); - QCOMPARE(view.viewport()->cursor().shape(), Qt::SizeAllCursor); + QTRY_COMPARE(view.viewport()->cursor().shape(), Qt::SizeAllCursor); } #endif diff --git a/tests/auto/widgets/itemviews/qitemdelegate/tst_qitemdelegate.cpp b/tests/auto/widgets/itemviews/qitemdelegate/tst_qitemdelegate.cpp index 7fd1822295..dc246c0ebf 100644 --- a/tests/auto/widgets/itemviews/qitemdelegate/tst_qitemdelegate.cpp +++ b/tests/auto/widgets/itemviews/qitemdelegate/tst_qitemdelegate.cpp @@ -26,6 +26,7 @@ ** ****************************************************************************/ +#include "../../../shared/highdpi.h" #include <QtTest/QtTest> @@ -51,6 +52,8 @@ #include <QPlainTextEdit> #include <QDialog> +#include <qscreen.h> + #include <QtWidgets/private/qabstractitemdelegate_p.h> Q_DECLARE_METATYPE(QAbstractItemDelegate::EndEditHint) @@ -223,8 +226,8 @@ private slots: void dateTextForRole_data(); void dateTextForRole(); -#ifdef QT_BUILD_INTERNAL private: +#ifdef QT_BUILD_INTERNAL struct RoleDelegate : public QItemDelegate { QString textForRole(Qt::ItemDataRole role, const QVariant &value, const QLocale &locale) @@ -234,6 +237,8 @@ private: } }; #endif + + const int m_fuzz = int(QGuiApplication::primaryScreen()->devicePixelRatio()); }; @@ -286,8 +291,8 @@ void tst_QItemDelegate::textRectangle() QFont font; TestItemDelegate delegate; QRect result = delegate.textRectangle(0, rect, font, text); - - QCOMPARE(result, expected); + QVERIFY2(HighDpi::fuzzyCompare(result, expected, m_fuzz), + HighDpi::msgRectMismatch(result, expected).constData()); } void tst_QItemDelegate::sizeHint_data() diff --git a/tests/auto/widgets/kernel/qwidget/tst_qwidget.cpp b/tests/auto/widgets/kernel/qwidget/tst_qwidget.cpp index 7203e7b170..3aece8746e 100644 --- a/tests/auto/widgets/kernel/qwidget/tst_qwidget.cpp +++ b/tests/auto/widgets/kernel/qwidget/tst_qwidget.cpp @@ -26,6 +26,7 @@ ** ****************************************************************************/ +#include "../../../shared/highdpi.h" #include <qboxlayout.h> #include <qapplication.h> @@ -140,19 +141,6 @@ static QByteArray msgComparisonFailed(T v1, const char *op, T v2) return s.toLocal8Bit(); } -// 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 : public QObject { Q_OBJECT @@ -418,6 +406,7 @@ private: QPoint m_safeCursorPos; const bool m_windowsAnimationsEnabled; QTouchDevice *m_touchScreen; + const int m_fuzz; }; bool tst_QWidget::ensureScreenSize(int width, int height) @@ -576,6 +565,7 @@ tst_QWidget::tst_QWidget() , m_safeCursorPos(0, 0) , m_windowsAnimationsEnabled(windowsAnimationsEnabled()) , m_touchScreen(QTest::createTouchDevice()) + , m_fuzz(int(QGuiApplication::primaryScreen()->devicePixelRatio())) { if (m_windowsAnimationsEnabled) // Disable animations which can interfere with screen grabbing in moveChild(), showAndMoveChild() setWindowsAnimationsEnabled(false); @@ -2049,10 +2039,9 @@ void tst_QWidget::windowState() widget1.setWindowState(widget1.windowState() ^ Qt::WindowMaximized); QTest::qWait(100); - const int fuzz = int(QHighDpiScaling::factor(widget1.windowHandle())); QVERIFY(!(widget1.windowState() & Qt::WindowMaximized)); - QTRY_VERIFY2(qFuzzyCompareWindowPosition(widget1.pos(), pos, fuzz), - qPrintable(msgPointMismatch(widget1.pos(), pos))); + QTRY_VERIFY2(HighDpi::fuzzyCompare(widget1.pos(), pos, m_fuzz), + qPrintable(HighDpi::msgPointMismatch(widget1.pos(), pos))); QCOMPARE(widget1.windowHandle()->windowState(), Qt::WindowNoState); widget1.setWindowState(Qt::WindowMinimized); @@ -2073,8 +2062,8 @@ void tst_QWidget::windowState() widget1.setWindowState(widget1.windowState() ^ Qt::WindowMaximized); QTest::qWait(100); QVERIFY(!(widget1.windowState() & (Qt::WindowMinimized|Qt::WindowMaximized))); - QTRY_VERIFY2(qFuzzyCompareWindowPosition(widget1.pos(), pos, fuzz), - qPrintable(msgPointMismatch(widget1.pos(), pos))); + QTRY_VERIFY2(HighDpi::fuzzyCompare(widget1.pos(), pos, m_fuzz), + qPrintable(HighDpi::msgPointMismatch(widget1.pos(), pos))); QCOMPARE(widget1.windowHandle()->windowState(), Qt::WindowNoState); widget1.setWindowState(Qt::WindowFullScreen); @@ -2095,8 +2084,8 @@ void tst_QWidget::windowState() widget1.setWindowState(Qt::WindowNoState); QTest::qWait(100); VERIFY_STATE(Qt::WindowNoState); - QTRY_VERIFY2(qFuzzyCompareWindowPosition(widget1.pos(), pos, fuzz), - qPrintable(msgPointMismatch(widget1.pos(), pos))); + QTRY_VERIFY2(HighDpi::fuzzyCompare(widget1.pos(), pos, m_fuzz), + qPrintable(HighDpi::msgPointMismatch(widget1.pos(), pos))); QCOMPARE(widget1.windowHandle()->windowState(), Qt::WindowNoState); widget1.setWindowState(Qt::WindowFullScreen); @@ -2129,8 +2118,8 @@ void tst_QWidget::windowState() QVERIFY(!(widget1.windowState() & stateMask)); QCOMPARE(widget1.windowHandle()->windowState(), Qt::WindowNoState); - QTRY_VERIFY2(qFuzzyCompareWindowPosition(widget1.pos(), pos, fuzz), - qPrintable(msgPointMismatch(widget1.pos(), pos))); + QTRY_VERIFY2(HighDpi::fuzzyCompare(widget1.pos(), pos, m_fuzz), + qPrintable(HighDpi::msgPointMismatch(widget1.pos(), pos))); QTRY_COMPARE(widget1.size(), size); } @@ -2323,7 +2312,7 @@ void tst_QWidget::resizeEvent() { QWidget wParent; wParent.setWindowTitle(QLatin1String(QTest::currentTestFunction())); - wParent.resize(200, 200); + wParent.resize(m_testWidgetSize); ResizeWidget wChild(&wParent); wParent.show(); QVERIFY(QTest::qWaitForWindowExposed(&wParent)); @@ -2341,7 +2330,7 @@ void tst_QWidget::resizeEvent() { ResizeWidget wTopLevel; wTopLevel.setWindowTitle(QLatin1String(QTest::currentTestFunction())); - wTopLevel.resize(200, 200); + wTopLevel.resize(m_testWidgetSize); wTopLevel.show(); QVERIFY(QTest::qWaitForWindowExposed(&wTopLevel)); if (m_platform == QStringLiteral("winrt")) @@ -2379,17 +2368,20 @@ void tst_QWidget::showMinimized() #ifdef Q_OS_WINRT QEXPECT_FAIL("", "Winrt does not support move and resize", Abort); #endif - QCOMPARE(plain.pos(), pos); + QVERIFY2(HighDpi::fuzzyCompare(plain.pos(), pos, m_fuzz), + qPrintable(HighDpi::msgPointMismatch(plain.pos(), pos))); plain.showNormal(); QVERIFY(!plain.isMinimized()); QVERIFY(plain.isVisible()); - QCOMPARE(plain.pos(), pos); + QVERIFY2(HighDpi::fuzzyCompare(plain.pos(), pos, m_fuzz), + qPrintable(HighDpi::msgPointMismatch(plain.pos(), pos))); plain.showMinimized(); QVERIFY(plain.isMinimized()); QVERIFY(plain.isVisible()); - QCOMPARE(plain.pos(), pos); + QVERIFY2(HighDpi::fuzzyCompare(plain.pos(), pos, m_fuzz), + qPrintable(HighDpi::msgPointMismatch(plain.pos(), pos))); plain.hide(); QVERIFY(plain.isMinimized()); @@ -2781,7 +2773,9 @@ void tst_QWidget::setGeometry() tlw.setWindowTitle(QLatin1String(QTest::currentTestFunction())); QWidget child(&tlw); - QRect tr(100,100,200,200); + const QPoint topLeft = QGuiApplication::primaryScreen()->availableGeometry().topLeft(); + const QSize initialSize = 2 * m_testWidgetSize; + QRect tr(topLeft + QPoint(100,100), initialSize); QRect cr(50,50,50,50); tlw.setGeometry(tr); child.setGeometry(cr); @@ -2792,8 +2786,7 @@ void tst_QWidget::setGeometry() QCOMPARE(child.geometry(), cr); tlw.setParent(nullptr, Qt::Window|Qt::FramelessWindowHint); - tr = QRect(0,0,100,100); - tr.moveTopLeft(QGuiApplication::primaryScreen()->availableGeometry().topLeft()); + tr = QRect(topLeft, initialSize / 2); tlw.setGeometry(tr); QCOMPARE(tlw.geometry(), tr); tlw.showNormal(); @@ -3265,7 +3258,8 @@ void tst_QWidget::saveRestoreGeometry() if (m_platform == QStringLiteral("winrt")) QEXPECT_FAIL("", "WinRT does not support move/resize", Abort); - QTRY_COMPARE(widget.pos(), position); + QTRY_VERIFY2(HighDpi::fuzzyCompare(widget.pos(), position, m_fuzz), + qPrintable(HighDpi::msgPointMismatch(widget.pos(), position))); QCOMPARE(widget.size(), size); savedGeometry = widget.saveGeometry(); } @@ -3293,10 +3287,12 @@ void tst_QWidget::saveRestoreGeometry() QVERIFY(QTest::qWaitForWindowExposed(&widget)); QApplication::processEvents(); - QTRY_COMPARE(widget.pos(), position); + QVERIFY2(HighDpi::fuzzyCompare(widget.pos(), position, m_fuzz), + qPrintable(HighDpi::msgPointMismatch(widget.pos(), position))); QCOMPARE(widget.size(), size); widget.show(); - QCOMPARE(widget.pos(), position); + QVERIFY2(HighDpi::fuzzyCompare(widget.pos(), position, m_fuzz), + qPrintable(HighDpi::msgPointMismatch(widget.pos(), position))); QCOMPARE(widget.size(), size); } @@ -3410,6 +3406,9 @@ void tst_QWidget::restoreVersion1Geometry() QFETCH(QSize, expectedSize); QFETCH(QRect, expectedNormalGeometry); + if (m_platform == QLatin1String("windows") && QGuiApplication::primaryScreen()->geometry().width() > 2000) + QSKIP("Skipping due to minimum decorated window size on Windows"); + // WindowActive is uninteresting for this test const Qt::WindowStates WindowStateMask = Qt::WindowFullScreen | Qt::WindowMaximized | Qt::WindowMinimized; @@ -4990,7 +4989,8 @@ void tst_QWidget::windowMoveResize() widget.showNormal(); QTest::qWait(10); - QTRY_COMPARE(widget.pos(), rect.topLeft()); + QTRY_VERIFY2(HighDpi::fuzzyCompare(widget.pos(), rect.topLeft(), m_fuzz), + qPrintable(HighDpi::msgPointMismatch(widget.pos(), rect.topLeft()))); // Windows: Minimum size of decorated windows. const bool expectResizeFail = (!windowFlags && (rect.width() < 160 || rect.height() < 40)) && m_platform == QStringLiteral("windows"); diff --git a/tests/auto/widgets/util/qcompleter/tst_qcompleter.cpp b/tests/auto/widgets/util/qcompleter/tst_qcompleter.cpp index 8bb16cc9d1..5a51f15008 100644 --- a/tests/auto/widgets/util/qcompleter/tst_qcompleter.cpp +++ b/tests/auto/widgets/util/qcompleter/tst_qcompleter.cpp @@ -38,47 +38,50 @@ #include "../../../../shared/filesystem.h" +#include <memory> + +Q_DECLARE_METATYPE(QCompleter::CompletionMode) + using namespace QTestPrivate; class CsvCompleter : public QCompleter { Q_OBJECT public: - CsvCompleter(QObject *parent = 0) : QCompleter(parent), csv(true) { } + using QCompleter::QCompleter; - QString pathFromIndex(const QModelIndex& sourceIndex) const; + QString pathFromIndex(const QModelIndex& sourceIndex) const override; void setCsvCompletion(bool set) { csv = set; } protected: - QStringList splitPath(const QString &path) const { + QStringList splitPath(const QString &path) const override + { return csv ? path.split(QLatin1Char(',')) : QCompleter::splitPath(path); } private: - bool csv; + bool csv = true; }; -QString CsvCompleter::pathFromIndex(const QModelIndex& si) const +QString CsvCompleter::pathFromIndex(const QModelIndex &sourceIndex) const { if (!csv) - return QCompleter::pathFromIndex(si); + return QCompleter::pathFromIndex(sourceIndex); - if (!si.isValid()) + if (!sourceIndex.isValid()) return QString(); - QModelIndex idx = si; + QModelIndex idx = sourceIndex; QStringList list; do { QString t = model()->data(idx, completionRole()).toString(); list.prepend(t); QModelIndex parent = idx.parent(); - idx = parent.sibling(parent.row(), si.column()); + idx = parent.sibling(parent.row(), sourceIndex.column()); } while (idx.isValid()); - if (list.count() == 1) - return list[0]; - return list.join(','); + return list.count() == 1 ? list.constFirst() : list.join(QLatin1Char(',')); } class tst_QCompleter : public QObject @@ -154,15 +157,14 @@ private: }; void setSourceModel(ModelType); - CsvCompleter *completer; + CsvCompleter *completer = nullptr; QTreeWidget *treeWidget; - const int completionColumn; - const int columnCount; + const int completionColumn = 0; + const int columnCount = 3; }; -tst_QCompleter::tst_QCompleter() : completer(0), completionColumn(0), columnCount(3) +tst_QCompleter::tst_QCompleter() : treeWidget(new QTreeWidget) { - treeWidget = new QTreeWidget; treeWidget->move(100, 100); treeWidget->setColumnCount(columnCount); } @@ -184,11 +186,11 @@ void tst_QCompleter::setSourceModel(ModelType type) for (int i = 0; i < 2; i++) { for (int j = 0; j < 5; j++) { parent = new QTreeWidgetItem(treeWidget); - const QString text = QString::asprintf("%c%i", i == 0 ? 'P' : 'p', j); + const QString text = QLatin1Char(i == 0 ? 'P' : 'p') + QString::number(j); parent->setText(completionColumn, text); for (int k = 0; k < 5; k++) { child = new QTreeWidgetItem(parent); - QString t = QString::asprintf("c%i", k) + text; + QString t = QLatin1Char('c') + QString::number(k) + text; child->setText(completionColumn, t); } } @@ -203,11 +205,11 @@ void tst_QCompleter::setSourceModel(ModelType type) for (int i = 0; i < 5; i++) { for (int j = 0; j < 2; j++) { parent = new QTreeWidgetItem(treeWidget); - const QString text = QString::asprintf("%c%i", j == 0 ? 'P' : 'p', i); + const QString text = QLatin1Char(j == 0 ? 'P' : 'p') + QString::number(i); parent->setText(completionColumn, text); for (int k = 0; k < 5; k++) { child = new QTreeWidgetItem(parent); - QString t = QString::asprintf("c%i", k) + text; + QString t = QLatin1Char('c') + QString::number(k) + text; child->setText(completionColumn, t); } } @@ -229,7 +231,7 @@ void tst_QCompleter::setSourceModel(ModelType type) case FILESYSTEM_MODEL: completer->setCsvCompletion(false); { - QFileSystemModel *m = new QFileSystemModel(completer); + auto m = new QFileSystemModel(completer); m->setRootPath("/"); completer->setModel(m); } @@ -237,13 +239,14 @@ void tst_QCompleter::setSourceModel(ModelType type) break; default: qDebug() << "Invalid type"; + break; } } void tst_QCompleter::filter(bool assync) { QFETCH(QString, filterText); - QFETCH(QString, step); + QFETCH(const QString, step); QFETCH(QString, completion); QFETCH(QString, completionText); @@ -252,33 +255,43 @@ void tst_QCompleter::filter(bool assync) return; } - int times = 0; -retry: - - completer->setCompletionPrefix(filterText); - - for (int i = 0; i < step.length(); i++) { - int row = completer->currentRow(); - switch (step[i].toUpper().toLatin1()) { - case 'P': --row; break; - case 'N': ++row; break; - case 'L': row = completer->completionCount() - 1; break; - case 'F': row = 0; break; - default: - QFAIL(qPrintable(QString( - "Problem with 'step' value in test data: %1 (only P, N, L and F are allowed)." - ).arg(step[i]))); + int result = -1; + const int attempts = assync ? 10 : 1; + for (int times = 0; times < attempts; ++times) { + completer->setCompletionPrefix(filterText); + + for (QChar s : step) { + int row = completer->currentRow(); + switch (s.toUpper().toLatin1()) { + case 'P': + --row; + break; + case 'N': + ++row; + break; + case 'L': + row = completer->completionCount() - 1; + break; + case 'F': + row = 0; + break; + default: + QFAIL(qPrintable(QString( + "Problem with 'step' value in test data: %1 (only P, N, L and F are allowed)." + ).arg(s))); + } + completer->setCurrentRow(row); } - completer->setCurrentRow(row); - } - int r = QString::compare(completer->currentCompletion(), completionText, completer->caseSensitivity()); - if (assync && r && times < 10) { - times++; - QTest::qWait(50*times); - goto retry; + result = QString::compare(completer->currentCompletion(), completionText, + completer->caseSensitivity()); + if (result == 0) + break; + if (assync) + QTest::qWait(50 * times); } - QVERIFY(!r); + + QCOMPARE(result, 0); } // Testing get/set functions @@ -844,8 +857,7 @@ void tst_QCompleter::sortedEngineMapFromSource() QModelIndex si1, si2, pi; QAbstractItemModel *sourceModel = completer->model(); - const QAbstractProxyModel *completionModel = - qobject_cast<const QAbstractProxyModel *>(completer->completionModel()); + auto completionModel = qobject_cast<const QAbstractProxyModel *>(completer->completionModel()); // Fitering ON // empty @@ -915,8 +927,7 @@ void tst_QCompleter::unsortedEngineMapFromSource() QModelIndex si, si2, si3, pi; QAbstractItemModel *sourceModel = completer->model(); - const QAbstractProxyModel *completionModel = - qobject_cast<const QAbstractProxyModel *>(completer->completionModel()); + auto completionModel = qobject_cast<const QAbstractProxyModel *>(completer->completionModel()); si = sourceModel->index(6, completionColumn); // "P3" QCOMPARE(si.data().toString(), QLatin1String("P3")); @@ -997,8 +1008,7 @@ void tst_QCompleter::historySearch() completer->setCaseSensitivity(Qt::CaseSensitive); setSourceModel(HISTORY_MODEL); - const QAbstractProxyModel *completionModel = - qobject_cast<const QAbstractProxyModel *>(completer->completionModel()); + auto completionModel = qobject_cast<const QAbstractProxyModel *>(completer->completionModel()); // "p3,c3p3" and "p2,c4p2" are added in the tree root @@ -1046,7 +1056,7 @@ void tst_QCompleter::setters() { delete completer; completer = new CsvCompleter; - QVERIFY(completer->popup() != 0); + QVERIFY(completer->popup() != nullptr); QPointer<QDirModel> dirModel = new QDirModel(completer); QAbstractItemModel *oldModel = completer->model(); completer->setModel(dirModel); @@ -1055,28 +1065,28 @@ void tst_QCompleter::setters() completer->setPopup(new QListView); QCOMPARE(completer->popup()->model(), completer->completionModel()); completer->setModel(new QStringListModel(completer)); - QVERIFY(dirModel == 0); // must have been deleted + QVERIFY(dirModel == nullptr); // must have been deleted - completer->setModel(0); - completer->setWidget(0); + completer->setModel(nullptr); + completer->setWidget(nullptr); } void tst_QCompleter::modelDeletion() { delete completer; completer = new CsvCompleter; - QStringList list; - list << "item1" << "item2" << "item3"; - QStringListModel *listModel = new QStringListModel(list); + const QStringList list = {"item1", "item2", "item3"}; + std::unique_ptr<QStringListModel> listModel(new QStringListModel(list)); completer->setCompletionPrefix("i"); - completer->setModel(listModel); + completer->setModel(listModel.get()); QCOMPARE(completer->completionCount(), 3); - QScopedPointer<QListView> view(new QListView); + std::unique_ptr<QListView> view(new QListView); + view->setWindowTitle(QLatin1String(QTest::currentTestFunction())); view->setModel(completer->completionModel()); - delete listModel; + listModel.reset(); view->move(200, 200); view->show(); - qApp->processEvents(); + QCoreApplication::processEvents(); view.reset(); QCOMPARE(completer->completionCount(), 0); QCOMPARE(completer->currentRow(), -1); @@ -1090,6 +1100,7 @@ void tst_QCompleter::multipleWidgets() completer.setCompletionMode(QCompleter::InlineCompletion); QWidget window; + window.setWindowTitle(QLatin1String(QTest::currentTestFunction())); window.move(200, 200); window.show(); QApplication::setActiveWindow(&window); @@ -1098,7 +1109,7 @@ void tst_QCompleter::multipleWidgets() QFocusEvent focusIn(QEvent::FocusIn); QFocusEvent focusOut(QEvent::FocusOut); - QComboBox *comboBox = new QComboBox(&window); + auto comboBox = new QComboBox(&window); comboBox->setEditable(true); comboBox->setCompleter(&completer); comboBox->setFocus(); @@ -1114,7 +1125,7 @@ void tst_QCompleter::multipleWidgets() comboBox->clearEditText(); QCOMPARE(comboBox->currentText(), QString("")); // combo box text must not change! - QLineEdit *lineEdit = new QLineEdit(&window); + auto lineEdit = new QLineEdit(&window); lineEdit->setCompleter(&completer); lineEdit->show(); lineEdit->setFocus(); @@ -1129,29 +1140,28 @@ void tst_QCompleter::multipleWidgets() void tst_QCompleter::focusIn() { - QStringList list; - list << "item1" << "item2" << "item2"; - QCompleter completer(list); + QCompleter completer({"item1", "item2", "item2"}); QWidget window; + window.setWindowTitle(QLatin1String(QTest::currentTestFunction())); window.move(200, 200); window.show(); window.activateWindow(); QApplication::setActiveWindow(&window); QVERIFY(QTest::qWaitForWindowActive(&window)); - QComboBox *comboBox = new QComboBox(&window); + auto comboBox = new QComboBox(&window); comboBox->setEditable(true); comboBox->setCompleter(&completer); comboBox->show(); comboBox->lineEdit()->setText("it"); - QLineEdit *lineEdit = new QLineEdit(&window); + auto lineEdit = new QLineEdit(&window); lineEdit->setCompleter(&completer); lineEdit->setText("it"); lineEdit->show(); - QLineEdit *lineEdit2 = new QLineEdit(&window); // has no completer! + auto lineEdit2 = new QLineEdit(&window); // has no completer! lineEdit2->show(); comboBox->setFocus(); @@ -1190,12 +1200,13 @@ void tst_QCompleter::dynamicSortOrder() void tst_QCompleter::disabledItems() { QLineEdit lineEdit; - QStandardItemModel *model = new QStandardItemModel(&lineEdit); + lineEdit.setWindowTitle(QLatin1String(QTest::currentTestFunction())); + auto model = new QStandardItemModel(&lineEdit); QStandardItem *suggestions = new QStandardItem("suggestions"); suggestions->setEnabled(false); model->appendRow(suggestions); model->appendRow(new QStandardItem("suggestions Enabled")); - QCompleter *completer = new QCompleter(model, &lineEdit); + auto completer = new QCompleter(model, &lineEdit); QSignalSpy spy(completer, QOverload<const QString &>::of(&QCompleter::activated)); lineEdit.setCompleter(completer); lineEdit.move(200, 200); @@ -1206,42 +1217,40 @@ void tst_QCompleter::disabledItems() QTest::keyPress(&lineEdit, Qt::Key_U); QAbstractItemView *view = lineEdit.completer()->popup(); QVERIFY(view->isVisible()); - QTest::mouseClick(view->viewport(), Qt::LeftButton, 0, view->visualRect(view->model()->index(0, 0)).center()); + QTest::mouseClick(view->viewport(), Qt::LeftButton, {}, view->visualRect(view->model()->index(0, 0)).center()); QCOMPARE(spy.count(), 0); QVERIFY(view->isVisible()); - QTest::mouseClick(view->viewport(), Qt::LeftButton, 0, view->visualRect(view->model()->index(1, 0)).center()); + QTest::mouseClick(view->viewport(), Qt::LeftButton, {}, view->visualRect(view->model()->index(1, 0)).center()); QCOMPARE(spy.count(), 1); QVERIFY(!view->isVisible()); } void tst_QCompleter::task178797_activatedOnReturn() { - QStringList words; - words << "foobar1" << "foobar2"; QLineEdit ledit; setFrameless(&ledit); - QCompleter *completer = new QCompleter(words, &ledit); + auto completer = new QCompleter({"foobar1", "foobar2"}, &ledit); ledit.setCompleter(completer); QSignalSpy spy(completer, QOverload<const QString &>::of(&QCompleter::activated)); QCOMPARE(spy.count(), 0); ledit.move(200, 200); ledit.show(); - qApp->setActiveWindow(&ledit); + QApplication::setActiveWindow(&ledit); QVERIFY(QTest::qWaitForWindowActive(&ledit)); QTest::keyClick(&ledit, Qt::Key_F); - qApp->processEvents(); - QTRY_VERIFY(qApp->activePopupWidget()); - QTest::keyClick(qApp->activePopupWidget(), Qt::Key_Down); - qApp->processEvents(); - QTest::keyClick(qApp->activePopupWidget(), Qt::Key_Return); - qApp->processEvents(); + QCoreApplication::processEvents(); + QTRY_VERIFY(QApplication::activePopupWidget()); + QTest::keyClick(QApplication::activePopupWidget(), Qt::Key_Down); + QCoreApplication::processEvents(); + QTest::keyClick(QApplication::activePopupWidget(), Qt::Key_Return); + QCoreApplication::processEvents(); QCOMPARE(spy.count(), 1); } class task189564_StringListModel : public QStringListModel { const QString omitString; - Qt::ItemFlags flags(const QModelIndex &index) const + Qt::ItemFlags flags(const QModelIndex &index) const override { Qt::ItemFlags flags = Qt::ItemIsEnabled; if (data(index, Qt::DisplayRole).toString() != omitString) @@ -1249,7 +1258,7 @@ class task189564_StringListModel : public QStringListModel return flags; } public: - task189564_StringListModel(const QString &omitString, QObject *parent = 0) + explicit task189564_StringListModel(const QString &omitString, QObject *parent = nullptr) : QStringListModel(parent) , omitString(omitString) { @@ -1315,8 +1324,7 @@ void tst_QCompleter::task246056_setCompletionPrefix() QTest::keyPress(comboBox.completer()->popup(), Qt::Key_Down); QTest::keyPress(comboBox.completer()->popup(), Qt::Key_Enter); // don't crash! QCOMPARE(spy.count(), 1); - QList<QVariant> arguments = spy.at(0); - QModelIndex index = arguments.at(0).value<QModelIndex>(); + const auto index = spy.at(0).constFirst().toModelIndex(); QVERIFY(!index.isValid()); } @@ -1331,7 +1339,7 @@ public: completer->setWidget(this); } - void keyPressEvent (QKeyEvent *e) + void keyPressEvent (QKeyEvent *e) override { completer->popup(); QTextEdit::keyPressEvent(e); @@ -1344,11 +1352,11 @@ class task250064_Widget : public QWidget public: task250064_Widget() : m_textEdit(new task250064_TextEdit) { - QTabWidget *tabWidget = new QTabWidget; + auto tabWidget = new QTabWidget; tabWidget->setFocusPolicy(Qt::ClickFocus); tabWidget->addTab(m_textEdit, "untitled"); - QVBoxLayout *layout = new QVBoxLayout(this); + auto layout = new QVBoxLayout(this); layout->addWidget(tabWidget); m_textEdit->setPlainText("bla bla bla"); @@ -1357,7 +1365,7 @@ public: void setCompletionModel() { - m_textEdit->completer->setModel(0); + m_textEdit->completer->setModel(nullptr); } QTextEdit *textEdit() const { return m_textEdit; } @@ -1369,6 +1377,7 @@ private: void tst_QCompleter::task250064_lostFocus() { task250064_Widget widget; + widget.setWindowTitle(QLatin1String(QTest::currentTestFunction())); widget.show(); QApplication::setActiveWindow(&widget); QVERIFY(QTest::qWaitForWindowActive(&widget)); @@ -1382,33 +1391,33 @@ void tst_QCompleter::task250064_lostFocus() void tst_QCompleter::task253125_lineEditCompletion_data() { QTest::addColumn<QStringList>("list"); - QTest::addColumn<int>("completionMode"); + QTest::addColumn<QCompleter::CompletionMode>("completionMode"); - QStringList list = QStringList() - << "alpha" << "beta" << "gamma" << "delta" << "epsilon" << "zeta" - << "eta" << "theta" << "iota" << "kappa" << "lambda" << "mu" - << "nu" << "xi" << "omicron" << "pi" << "rho" << "sigma" - << "tau" << "upsilon" << "phi" << "chi" << "psi" << "omega"; + QStringList list = {"alpha", "beta", "gamma", "delta", "epsilon", "zeta", + "eta", "theta", "iota", "kappa", "lambda", "mu", + "nu", "xi", "omicron", "pi", "rho", "sigma", + "tau", "upsilon", "phi", "chi", "psi", "omega"}; - QTest::newRow("Inline") << list << (int)QCompleter::InlineCompletion; - QTest::newRow("Filtered") << list << (int)QCompleter::PopupCompletion; - QTest::newRow("Unfiltered") << list << (int)QCompleter::UnfilteredPopupCompletion; + QTest::newRow("Inline") << list << QCompleter::InlineCompletion; + QTest::newRow("Filtered") << list << QCompleter::PopupCompletion; + QTest::newRow("Unfiltered") << list << QCompleter::UnfilteredPopupCompletion; } void tst_QCompleter::task253125_lineEditCompletion() { QFETCH(QStringList, list); - QFETCH(int, completionMode); + QFETCH(QCompleter::CompletionMode, completionMode); - QStringListModel *model = new QStringListModel; - model->setStringList(list); + std::unique_ptr<QStringListModel> model(new QStringListModel(list)); - QCompleter *completer = new QCompleter(list); - completer->setModel(model); - completer->setCompletionMode((QCompleter::CompletionMode)completionMode); + std::unique_ptr<QCompleter> completer(new QCompleter(list)); + completer->setModel(model.get()); + completer->setCompletionMode(completionMode); QLineEdit edit; - edit.setCompleter(completer); + edit.setWindowTitle(QLatin1String(QTest::currentTestFunction()) + QLatin1String("::") + + QLatin1String(QTest::currentDataTag())); + edit.setCompleter(completer.get()); edit.move(200, 200); edit.show(); edit.setFocus(); @@ -1550,9 +1559,6 @@ void tst_QCompleter::task253125_lineEditCompletion() QTest::keyClick(edit.completer()->popup(), Qt::Key_Enter); QCOMPARE(edit.text(), QString("zz")); - - delete completer; - delete model; } void tst_QCompleter::task247560_keyboardNavigation() @@ -1570,6 +1576,7 @@ void tst_QCompleter::task247560_keyboardNavigation() completer.setCompletionColumn(1); QLineEdit edit; + edit.setWindowTitle(QLatin1String(QTest::currentTestFunction())); edit.setCompleter(&completer); edit.move(200, 200); edit.show(); @@ -1677,6 +1684,7 @@ void tst_QCompleter::QTBUG_14292_filesystem() QVERIFY(fs.createDirectory(QLatin1String(testDir2))); QLineEdit edit; + edit.setWindowTitle(QLatin1String(QTest::currentTestFunction())); QCompleter comp; comp.setModel(&model); edit.setCompleter(&comp); @@ -1739,16 +1747,14 @@ void tst_QCompleter::QTBUG_14292_filesystem() void tst_QCompleter::QTBUG_52028_tabAutoCompletes() { - QStringList words; - words << "foobar1" << "foobar2" << "hux"; - QWidget w; + w.setWindowTitle(QLatin1String(QTest::currentTestFunction())); w.setLayout(new QVBoxLayout); QComboBox cbox; cbox.setEditable(true); cbox.setInsertPolicy(QComboBox::NoInsert); - cbox.addItems(words); + cbox.addItems({"foobar1", "foobar2", "hux"}); cbox.completer()->setCaseSensitivity(Qt::CaseInsensitive); cbox.completer()->setCompletionMode(QCompleter::PopupCompletion); @@ -1756,8 +1762,8 @@ void tst_QCompleter::QTBUG_52028_tabAutoCompletes() w.layout()->addWidget(&cbox); // Adding a line edit is a good reason for tab to do something unrelated - QLineEdit le; - w.layout()->addWidget(&le); + auto le = new QLineEdit; + w.layout()->addWidget(le); const auto pos = QApplication::desktop()->availableGeometry(&w).topLeft() + QPoint(200,200); w.move(pos); @@ -1778,30 +1784,27 @@ void tst_QCompleter::QTBUG_52028_tabAutoCompletes() QEXPECT_FAIL("", "QTBUG-52028 will not be fixed today.", Abort); QCOMPARE(cbox.currentText(), QLatin1String("hux")); QCOMPARE(activatedSpy.count(), 0); - QVERIFY(!le.hasFocus()); + QVERIFY(!le->hasFocus()); } void tst_QCompleter::QTBUG_51889_activatedSentTwice() { - QStringList words; - words << "foobar1" << "foobar2" << "bar" <<"hux"; - QWidget w; + w.setWindowTitle(QLatin1String(QTest::currentTestFunction())); w.setLayout(new QVBoxLayout); QComboBox cbox; setFrameless(&cbox); cbox.setEditable(true); cbox.setInsertPolicy(QComboBox::NoInsert); - cbox.addItems(words); + cbox.addItems({"foobar1", "foobar2", "bar", "hux"}); cbox.completer()->setCaseSensitivity(Qt::CaseInsensitive); cbox.completer()->setCompletionMode(QCompleter::PopupCompletion); w.layout()->addWidget(&cbox); - QLineEdit le; - w.layout()->addWidget(&le); + w.layout()->addWidget(new QLineEdit); const auto pos = QApplication::desktop()->availableGeometry(&w).topLeft() + QPoint(200,200); w.move(pos); diff --git a/tests/auto/widgets/widgets/qcombobox/tst_qcombobox.cpp b/tests/auto/widgets/widgets/qcombobox/tst_qcombobox.cpp index 5b4761ba87..a576770811 100644 --- a/tests/auto/widgets/widgets/qcombobox/tst_qcombobox.cpp +++ b/tests/auto/widgets/widgets/qcombobox/tst_qcombobox.cpp @@ -852,8 +852,8 @@ void tst_QComboBox::autoCompletionCaseSensitivity() // case insensitive testWidget->clearEditText(); QSignalSpy spyReturn(testWidget, SIGNAL(activated(int))); - testWidget->setAutoCompletionCaseSensitivity(Qt::CaseInsensitive); - QCOMPARE(testWidget->autoCompletionCaseSensitivity(), Qt::CaseInsensitive); + testWidget->completer()->setCaseSensitivity(Qt::CaseInsensitive); + QCOMPARE(testWidget->completer()->caseSensitivity(), Qt::CaseInsensitive); QTest::keyClick(testWidget->lineEdit(), Qt::Key_A); qApp->processEvents(); @@ -886,8 +886,8 @@ void tst_QComboBox::autoCompletionCaseSensitivity() // case sensitive testWidget->clearEditText(); - testWidget->setAutoCompletionCaseSensitivity(Qt::CaseSensitive); - QCOMPARE(testWidget->autoCompletionCaseSensitivity(), Qt::CaseSensitive); + testWidget->completer()->setCaseSensitivity(Qt::CaseSensitive); + QCOMPARE(testWidget->completer()->caseSensitivity(), Qt::CaseSensitive); QTest::keyClick(testWidget->lineEdit(), Qt::Key_A); qApp->processEvents(); QCOMPARE(testWidget->currentText(), QString("aww")); |