summaryrefslogtreecommitdiffstats
path: root/tests
diff options
context:
space:
mode:
Diffstat (limited to 'tests')
-rw-r--r--tests/auto/cmake/CMakeLists.txt7
-rw-r--r--tests/auto/cmake/test_add_big_resource/CMakeLists.txt2
-rw-r--r--tests/auto/corelib/global/qfloat16/tst_qfloat16.cpp4
-rw-r--r--tests/auto/corelib/io/qfileselector/tst_qfileselector.cpp8
-rw-r--r--tests/auto/corelib/tools/qregexp/tst_qregexp.cpp7
-rw-r--r--tests/auto/gui/image/qimagereader/images/qticon16.pngbin0 -> 1884 bytes
-rw-r--r--tests/auto/gui/image/qimagereader/images/qticon16@2x.pngbin0 -> 3187 bytes
-rw-r--r--tests/auto/gui/image/qimagereader/images/qticon16@3x.pngbin0 -> 5307 bytes
-rw-r--r--tests/auto/gui/image/qimagereader/tst_qimagereader.cpp25
-rw-r--r--tests/auto/gui/text/qtextdocument/tst_qtextdocument.cpp9
-rw-r--r--tests/auto/network/access/qftp/tst_qftp.cpp4
-rw-r--r--tests/auto/other/lancelot/scripts/degeneratebeziers.qps11
-rw-r--r--tests/auto/shared/highdpi.h109
-rw-r--r--tests/auto/widgets/dialogs/qdialog/tst_qdialog.cpp5
-rw-r--r--tests/auto/widgets/dialogs/qwizard/tst_qwizard.cpp2
-rw-r--r--tests/auto/widgets/itemviews/qitemdelegate/tst_qitemdelegate.cpp11
-rw-r--r--tests/auto/widgets/kernel/qwidget/tst_qwidget.cpp68
-rw-r--r--tests/auto/widgets/util/qcompleter/tst_qcompleter.cpp255
-rw-r--r--tests/manual/diaglib/debugproxystyle.cpp23
-rw-r--r--tests/manual/diaglib/eventfilter.cpp32
-rw-r--r--tests/manual/diaglib/eventfilter.h13
21 files changed, 398 insertions, 197 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 aa6f0935e8..b73a297245 100644
--- a/tests/auto/corelib/global/qfloat16/tst_qfloat16.cpp
+++ b/tests/auto/corelib/global/qfloat16/tst_qfloat16.cpp
@@ -172,9 +172,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/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/gui/image/qimagereader/images/qticon16.png b/tests/auto/gui/image/qimagereader/images/qticon16.png
new file mode 100644
index 0000000000..b6b01a4d64
--- /dev/null
+++ b/tests/auto/gui/image/qimagereader/images/qticon16.png
Binary files differ
diff --git a/tests/auto/gui/image/qimagereader/images/qticon16@2x.png b/tests/auto/gui/image/qimagereader/images/qticon16@2x.png
new file mode 100644
index 0000000000..205461daf0
--- /dev/null
+++ b/tests/auto/gui/image/qimagereader/images/qticon16@2x.png
Binary files differ
diff --git a/tests/auto/gui/image/qimagereader/images/qticon16@3x.png b/tests/auto/gui/image/qimagereader/images/qticon16@3x.png
new file mode 100644
index 0000000000..de92658241
--- /dev/null
+++ b/tests/auto/gui/image/qimagereader/images/qticon16@3x.png
Binary files differ
diff --git a/tests/auto/gui/image/qimagereader/tst_qimagereader.cpp b/tests/auto/gui/image/qimagereader/tst_qimagereader.cpp
index c2ec5b8925..1eee2f273e 100644
--- a/tests/auto/gui/image/qimagereader/tst_qimagereader.cpp
+++ b/tests/auto/gui/image/qimagereader/tst_qimagereader.cpp
@@ -164,6 +164,9 @@ private slots:
void preserveTexts_data();
void preserveTexts();
+ void devicePixelRatio_data();
+ void devicePixelRatio();
+
private:
QString prefix;
QTemporaryDir m_temporaryDir;
@@ -1976,6 +1979,28 @@ void tst_QImageReader::preserveTexts()
QCOMPARE(r.text(key3), text3.simplified());
}
+void tst_QImageReader::devicePixelRatio_data()
+{
+ QTest::addColumn<QString>("fileName");
+ QTest::addColumn<QSize>("size");
+ QTest::addColumn<qreal>("dpr");
+
+ QTest::newRow("1x") << "qticon16.png" << QSize(16, 16) << 1.0;
+ QTest::newRow("2x") << "qticon16@2x.png" << QSize(32, 32) << 2.0;
+ QTest::newRow("3x") << "qticon16@3x.png" << QSize(48, 48) << 3.0;
+}
+
+void tst_QImageReader::devicePixelRatio()
+{
+ QFETCH(QString, fileName);
+ QFETCH(QSize, size);
+ QFETCH(qreal, dpr);
+
+ QImageReader r(":/images/" + fileName);
+ QImage img = r.read();
+ QCOMPARE(img.size(), size);
+ QCOMPARE(img.devicePixelRatio(), dpr);
+}
QTEST_MAIN(tst_QImageReader)
#include "tst_qimagereader.moc"
diff --git a/tests/auto/gui/text/qtextdocument/tst_qtextdocument.cpp b/tests/auto/gui/text/qtextdocument/tst_qtextdocument.cpp
index 3f602f5aae..32131352c3 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/qftp/tst_qftp.cpp b/tests/auto/network/access/qftp/tst_qftp.cpp
index 6e18e1a663..1a8f264c28 100644
--- a/tests/auto/network/access/qftp/tst_qftp.cpp
+++ b/tests/auto/network/access/qftp/tst_qftp.cpp
@@ -2342,7 +2342,7 @@ void tst_QFtp::loginURL()
ftp = newFtp();
addCommand(QFtp::ConnectToHost,
- ftp->connectToHost(QHostInfo::localHostName(), port));
+ ftp->connectToHost("127.0.0.1", port));
addCommand(QFtp::Login, ftp->login(user, password));
QTestEventLoop::instance().enterLoop(5);
@@ -2350,7 +2350,7 @@ void tst_QFtp::loginURL()
ftp = nullptr;
server.stopServer();
if (QTestEventLoop::instance().timeout())
- QFAIL(msgTimedOut(QHostInfo::localHostName(), port));
+ QFAIL(msgTimedOut("127.0.0.1", port));
QCOMPARE(server.getRawUser(), rawUser);
QCOMPARE(server.getRawPassword(), rawPass);
diff --git a/tests/auto/other/lancelot/scripts/degeneratebeziers.qps b/tests/auto/other/lancelot/scripts/degeneratebeziers.qps
index 6c069fd82f..948968b0cd 100644
--- a/tests/auto/other/lancelot/scripts/degeneratebeziers.qps
+++ b/tests/auto/other/lancelot/scripts/degeneratebeziers.qps
@@ -34,3 +34,14 @@ setPen blue 40 solidline roundcap
drawPath revbez
setPen red 0
drawPath revbez
+
+resetMatrix
+path_lineTo tightJoin 60 10
+path_cubicTo tightJoin 50 0 100 0 100 50
+
+translate 50 500
+
+setPen green 40 solidline roundcap roundjoin
+drawPath tightJoin
+setPen red 0
+drawPath tightJoin
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/itemviews/qitemdelegate/tst_qitemdelegate.cpp b/tests/auto/widgets/itemviews/qitemdelegate/tst_qitemdelegate.cpp
index aa11ed709f..961c8aa4ad 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 bbaed67a36..c0dfaf80a3 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
@@ -416,6 +404,7 @@ private:
QPoint m_safeCursorPos;
const bool m_windowsAnimationsEnabled;
QTouchDevice *m_touchScreen;
+ const int m_fuzz;
};
bool tst_QWidget::ensureScreenSize(int width, int height)
@@ -574,6 +563,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);
@@ -2047,10 +2037,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);
@@ -2071,8 +2060,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);
@@ -2093,8 +2082,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);
@@ -2127,8 +2116,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);
}
@@ -2321,7 +2310,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));
@@ -2339,7 +2328,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"))
@@ -2377,17 +2366,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());
@@ -2779,7 +2771,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);
@@ -2790,8 +2784,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();
@@ -3263,7 +3256,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();
}
@@ -3291,10 +3285,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);
}
@@ -3408,6 +3404,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;
@@ -4988,7 +4987,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 ad64f1aef7..22f29a5e29 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();
@@ -1688,6 +1695,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);
@@ -1750,16 +1758,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);
@@ -1767,8 +1773,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);
@@ -1789,30 +1795,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/manual/diaglib/debugproxystyle.cpp b/tests/manual/diaglib/debugproxystyle.cpp
index d4e62f5dd6..ed35af5962 100644
--- a/tests/manual/diaglib/debugproxystyle.cpp
+++ b/tests/manual/diaglib/debugproxystyle.cpp
@@ -27,6 +27,7 @@
****************************************************************************/
#include "debugproxystyle.h"
+#include "eventfilter.h"
#include <QDebug>
#include <QWidget>
@@ -73,7 +74,7 @@ QDebug operator<<(QDebug debug, const QStyleOption *option)
debug << ", state=" << option->state;
#if QT_VERSION >= 0x050000
if (option->styleObject && !option->styleObject->isWidgetType())
- debug << ", styleObject=" << option->styleObject;
+ debug << ", styleObject=" << QtDiag::formatQObject(option->styleObject);
#endif
debug << ')';
return debug;
@@ -97,19 +98,19 @@ DebugProxyStyle::DebugProxyStyle(QStyle *style) : QProxyStyle(style)
void DebugProxyStyle::drawPrimitive(QStyle::PrimitiveElement element, const QStyleOption *option, QPainter *painter, const QWidget *widget) const
{
- qDebug() << __FUNCTION__ << "element=" << element << option << widget;
+ qDebug() << __FUNCTION__ << "element=" << element << option << QtDiag::formatQObject(widget);
QProxyStyle::drawPrimitive( element, option, painter, widget);
}
void DebugProxyStyle::drawControl(QStyle::ControlElement element, const QStyleOption *option, QPainter *painter, const QWidget *widget) const
{
- qDebug() << __FUNCTION__ << "element=" << element << option << widget;
+ qDebug() << __FUNCTION__ << "element=" << element << option << QtDiag::formatQObject(widget);
QProxyStyle::drawControl(element, option, painter, widget);
}
void DebugProxyStyle::drawComplexControl(QStyle::ComplexControl control, const QStyleOptionComplex *option, QPainter *painter, const QWidget *widget) const
{
- qDebug() << __FUNCTION__ << "control=" << control << option << widget;
+ qDebug() << __FUNCTION__ << "control=" << control << option << QtDiag::formatQObject(widget);
QProxyStyle::drawComplexControl(control, option, painter, widget);
}
@@ -122,21 +123,24 @@ void DebugProxyStyle::drawItemPixmap(QPainter *painter, const QRect &rect, int a
QSize DebugProxyStyle::sizeFromContents(QStyle::ContentsType type, const QStyleOption *option, const QSize &size, const QWidget *widget) const
{
const QSize result = QProxyStyle::sizeFromContents(type, option, size, widget);
- qDebug() << __FUNCTION__ << size << "type=" << type << option << widget << "returns" << result;
+ qDebug() << __FUNCTION__ << size << "type=" << type << option
+ << QtDiag::formatQObject(widget) << "returns" << result;
return result;
}
QRect DebugProxyStyle::subElementRect(QStyle::SubElement element, const QStyleOption *option, const QWidget *widget) const
{
const QRect result = QProxyStyle::subElementRect(element, option, widget);
- qDebug() << __FUNCTION__ << "element=" << element << option << widget << "returns" << result;
+ qDebug() << __FUNCTION__ << "element=" << element << option
+ << QtDiag::formatQObject(widget) << "returns" << result;
return result;
}
QRect DebugProxyStyle::subControlRect(QStyle::ComplexControl cc, const QStyleOptionComplex *opt, QStyle::SubControl sc, const QWidget *widget) const
{
const QRect result = QProxyStyle::subControlRect(cc, opt, sc, widget);
- qDebug() << __FUNCTION__ << "cc=" << cc << "sc=" << sc << opt << widget << "returns" << result;
+ qDebug() << __FUNCTION__ << "cc=" << cc << "sc=" << sc << opt
+ << QtDiag::formatQObject(widget) << "returns" << result;
return result;
}
@@ -159,7 +163,7 @@ int DebugProxyStyle::styleHint(StyleHint hint, const QStyleOption *option, const
QStyleHintReturn *returnData) const
{
const int result = QProxyStyle::styleHint(hint, option, widget, returnData);
- qDebug() << __FUNCTION__ << hint << option << widget << "returnData="
+ qDebug() << __FUNCTION__ << hint << option << QtDiag::formatQObject(widget) << "returnData="
<< returnData << "returns" << result;
return result;
}
@@ -167,7 +171,8 @@ int DebugProxyStyle::styleHint(StyleHint hint, const QStyleOption *option, const
int DebugProxyStyle::pixelMetric(QStyle::PixelMetric metric, const QStyleOption *option, const QWidget *widget) const
{
const int result = QProxyStyle::pixelMetric(metric, option, widget);
- qDebug() << __FUNCTION__ << "metric=" << metric << option << widget << "returns" << result;
+ qDebug() << __FUNCTION__ << "metric=" << metric << option
+ << QtDiag::formatQObject(widget) << "returns" << result;
return result;
}
diff --git a/tests/manual/diaglib/eventfilter.cpp b/tests/manual/diaglib/eventfilter.cpp
index 0646964b4a..39898f0781 100644
--- a/tests/manual/diaglib/eventfilter.cpp
+++ b/tests/manual/diaglib/eventfilter.cpp
@@ -154,7 +154,7 @@ static inline bool matchesType(const QObject *o, EventFilter::ObjectTypes types)
return types & EventFilter::OtherType;
}
-static void formatObject(const QObject *o, QDebug debug)
+void EventFilter::formatObject(const QObject *o, QDebug debug)
{
if (o) {
debug << o->metaObject()->className();
@@ -166,32 +166,30 @@ static void formatObject(const QObject *o, QDebug debug)
}
}
+QDebug operator<<(QDebug d, const formatQObject &fo)
+{
+ EventFilter::formatObject(fo.m_object, d);
+ return d;
+}
+
static void formatApplicationState(QDebug debug)
{
#if defined(HAVE_APPLICATION)
- if (const QWidget *mw = QApplication::activeModalWidget()) {
- debug << "\n QApplication::activeModalWidget = ";
- formatObject(mw, debug);
- }
- if (const QWidget *pw = QApplication::activePopupWidget()) {
- debug << "\n QApplication::activePopupWidget = ";
- formatObject(pw, debug);
- }
- debug << "\n QApplication::activeWindow = ";
- formatObject(QApplication::activeWindow(), debug);
+ if (const QWidget *mw = QApplication::activeModalWidget())
+ debug << "\n QApplication::activeModalWidget = " << formatQObject(mw);
+ if (const QWidget *pw = QApplication::activePopupWidget())
+ debug << "\n QApplication::activePopupWidget = " << formatQObject(pw);
+ debug << "\n QApplication::activeWindow = " << formatQObject(QApplication::activeWindow());
#endif // HAVE_APPLICATION
#if defined(HAVE_GUI_APPLICATION)
if (const QWindow *mw = QGuiApplication::modalWindow()) {
- debug << "\n QGuiApplication::modalWindow = ";
- formatObject(mw, debug);
+ debug << "\n QGuiApplication::modalWindow = " << formatQObject(mw);
}
const QObject *focusObject = QGuiApplication::focusObject();
const QObject *focusWindow = QGuiApplication::focusWindow();
- debug << "\n QGuiApplication::focusObject = ";
- formatObject(focusObject, debug);
+ debug << "\n QGuiApplication::focusObject = " << formatQObject(focusObject);
if (focusWindow && focusWindow != focusObject)
- debug << "\n QGuiApplication::focusWindow = ";
- formatObject(focusWindow, debug);
+ debug << "\n QGuiApplication::focusWindow = " << formatQObject(focusWindow);
#endif // HAVE_GUI_APPLICATION
}
diff --git a/tests/manual/diaglib/eventfilter.h b/tests/manual/diaglib/eventfilter.h
index a65cd9f17d..1f57fbeb8b 100644
--- a/tests/manual/diaglib/eventfilter.h
+++ b/tests/manual/diaglib/eventfilter.h
@@ -33,6 +33,8 @@
#include <QtCore/QEvent>
#include <QtCore/QList>
+QT_FORWARD_DECLARE_CLASS(QDebug)
+
namespace QtDiag {
// Event filter that can for example be installed on QApplication
@@ -74,6 +76,8 @@ public:
ObjectTypes objectTypes() const { return m_objectTypes; }
void setObjectTypes(ObjectTypes objectTypes) { m_objectTypes = objectTypes; }
+ static void formatObject(const QObject *o, QDebug debug);
+
private:
void init(EventCategories eventCategories);
@@ -84,6 +88,15 @@ private:
Q_DECLARE_OPERATORS_FOR_FLAGS(EventFilter::EventCategories)
Q_DECLARE_OPERATORS_FOR_FLAGS(EventFilter::ObjectTypes)
+struct formatQObject
+{
+ explicit formatQObject(const QObject *o) : m_object(o) {}
+
+ const QObject *m_object;
+};
+
+QDebug operator<<(QDebug d, const formatQObject &fo);
+
} // namespace QtDiag
#endif