diff options
author | Simon Hausmann <simon.hausmann@qt.io> | 2019-06-26 11:32:55 +0200 |
---|---|---|
committer | Simon Hausmann <simon.hausmann@qt.io> | 2019-06-26 11:33:19 +0200 |
commit | 7810209ba32fcebfa90b081670595daaa5333a78 (patch) | |
tree | 98410d5cc7d9d762bbde0cb4eae8041aa6e2e542 /tests/auto/widgets | |
parent | 6f2eabb54e3f827ebd2b90f68144b86342933869 (diff) | |
parent | 88625709058b386ee74cca536c6c5556159c99fa (diff) |
Merge remote-tracking branch 'origin/dev' into wip/qt6
Change-Id: I4ea2b77cc201daed94fbe321f146dfd20365a534
Diffstat (limited to 'tests/auto/widgets')
17 files changed, 399 insertions, 204 deletions
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/qactiongroup/tst_qactiongroup.cpp b/tests/auto/widgets/kernel/qactiongroup/tst_qactiongroup.cpp index 0ba3cedf16..64e5b969e7 100644 --- a/tests/auto/widgets/kernel/qactiongroup/tst_qactiongroup.cpp +++ b/tests/auto/widgets/kernel/qactiongroup/tst_qactiongroup.cpp @@ -41,6 +41,7 @@ private slots: void enabledPropagation(); void visiblePropagation(); void exclusive(); + void exclusiveOptional(); void separators(); void testActionInTwoQActionGroup(); void unCheckCurrentAction(); @@ -151,6 +152,52 @@ void tst_QActionGroup::exclusive() QVERIFY( !actThree->isChecked() ); } +void tst_QActionGroup::exclusiveOptional() +{ + QActionGroup group(0); + group.setExclusive(true); + QVERIFY( group.isExclusive() ); + + QAction* actOne = new QAction( &group ); + actOne->setCheckable( true ); + QAction* actTwo = new QAction( &group ); + actTwo->setCheckable( true ); + QAction* actThree = new QAction( &group ); + actThree->setCheckable( true ); + + QVERIFY( !actOne->isChecked() ); + QVERIFY( !actTwo->isChecked() ); + QVERIFY( !actThree->isChecked() ); + + actOne->trigger(); + QVERIFY( actOne->isChecked() ); + QVERIFY( !actTwo->isChecked() ); + QVERIFY( !actThree->isChecked() ); + + actOne->trigger(); + QVERIFY( actOne->isChecked() ); + QVERIFY( !actTwo->isChecked() ); + QVERIFY( !actThree->isChecked() ); + + group.setExclusionPolicy( QActionGroup::ExclusionPolicy::ExclusiveOptional ); + QVERIFY( group.isExclusive() ); + + actOne->trigger(); + QVERIFY( !actOne->isChecked() ); + QVERIFY( !actTwo->isChecked() ); + QVERIFY( !actThree->isChecked() ); + + actTwo->trigger(); + QVERIFY( !actOne->isChecked() ); + QVERIFY( actTwo->isChecked() ); + QVERIFY( !actThree->isChecked() ); + + actTwo->trigger(); + QVERIFY( !actOne->isChecked() ); + QVERIFY( !actTwo->isChecked() ); + QVERIFY( !actThree->isChecked() ); +} + void tst_QActionGroup::separators() { QMainWindow mw; diff --git a/tests/auto/widgets/kernel/qwidget/tst_qwidget.cpp b/tests/auto/widgets/kernel/qwidget/tst_qwidget.cpp index 7203e7b170..fb40674d98 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 @@ -192,6 +180,7 @@ private slots: void tabOrderWithProxy(); void tabOrderWithCompoundWidgets(); void tabOrderNoChange(); + void tabOrderNoChange2(); #if defined(Q_OS_WIN) && !defined(Q_OS_WINRT) void activation(); #endif @@ -418,6 +407,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 +566,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); @@ -1952,6 +1943,24 @@ static QVector<QWidget*> getFocusChain(QWidget *start, bool bForward) return ret; } +//#define DEBUG_FOCUS_CHAIN +static void dumpFocusChain(QWidget *start, bool bForward, const char *desc = nullptr) +{ +#ifdef DEBUG_FOCUS_CHAIN + qDebug() << "Dump focus chain, start:" << start << "isForward:" << bForward << desc; + QWidget *cur = start; + do { + qDebug() << cur; + auto widgetPrivate = static_cast<QWidgetPrivate *>(qt_widget_private(cur)); + cur = bForward ? widgetPrivate->focus_next : widgetPrivate->focus_prev; + } while (cur != start); +#else + Q_UNUSED(start) + Q_UNUSED(bForward) + Q_UNUSED(desc) +#endif +} + void tst_QWidget::tabOrderNoChange() { QWidget w; @@ -1963,7 +1972,61 @@ void tst_QWidget::tabOrderNoChange() const auto focusChainForward = getFocusChain(&w, true); const auto focusChainBackward = getFocusChain(&w, false); + dumpFocusChain(&w, true); QWidget::setTabOrder(tabWidget, tv); + dumpFocusChain(&w, true); + QCOMPARE(focusChainForward, getFocusChain(&w, true)); + QCOMPARE(focusChainBackward, getFocusChain(&w, false)); +} + +void tst_QWidget::tabOrderNoChange2() +{ + QWidget w; + auto *verticalLayout = new QVBoxLayout(&w); + auto *tabWidget = new QTabWidget(&w); + tabWidget->setObjectName("tabWidget"); + verticalLayout->addWidget(tabWidget); + + auto *tab1 = new QWidget(tabWidget); + tab1->setObjectName("tab1"); + auto *vLay1 = new QVBoxLayout(tab1); + auto *le1 = new QLineEdit(tab1); + le1->setObjectName("le1"); + auto *le2 = new QLineEdit(tab1); + le2->setObjectName("le2"); + vLay1->addWidget(le1); + vLay1->addWidget(le2); + tabWidget->addTab(tab1, QStringLiteral("Tab 1")); + + auto *tab2 = new QWidget(tabWidget); + tab2->setObjectName("tab2"); + auto *vLay2 = new QVBoxLayout(tab2); + auto *le3 = new QLineEdit(tab2); + le3->setObjectName("le3"); + auto *le4 = new QLineEdit(tab2); + le4->setObjectName("le4"); + vLay2->addWidget(le3); + vLay2->addWidget(le4); + tabWidget->addTab(tab2, QStringLiteral("Tab 2")); + + const auto focusChainForward = getFocusChain(&w, true); + const auto focusChainBackward = getFocusChain(&w, false); + dumpFocusChain(&w, true); + dumpFocusChain(&w, false); + // this will screw up the focus chain order without visible changes, + // so don't call it here for the simplicity of the test + //QWidget::setTabOrder(tabWidget, le1); + + QWidget::setTabOrder(le1, le2); + dumpFocusChain(&w, true, "QWidget::setTabOrder(le1, le2)"); + QWidget::setTabOrder(le2, le3); + dumpFocusChain(&w, true, "QWidget::setTabOrder(le2, le3)"); + QWidget::setTabOrder(le3, le4); + dumpFocusChain(&w, true, "QWidget::setTabOrder(le3, le4)"); + QWidget::setTabOrder(le4, tabWidget); + dumpFocusChain(&w, true, "QWidget::setTabOrder(le4, tabWidget)"); + dumpFocusChain(&w, false); + QCOMPARE(focusChainForward, getFocusChain(&w, true)); QCOMPARE(focusChainBackward, getFocusChain(&w, false)); } @@ -2049,10 +2112,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 +2135,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 +2157,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 +2191,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 +2385,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 +2403,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 +2441,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 +2846,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 +2859,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 +3331,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 +3360,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 +3479,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 +5062,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/qabstractslider/tst_qabstractslider.cpp b/tests/auto/widgets/widgets/qabstractslider/tst_qabstractslider.cpp index 1a0d7a9289..d8fbb8e041 100644 --- a/tests/auto/widgets/widgets/qabstractslider/tst_qabstractslider.cpp +++ b/tests/auto/widgets/widgets/qabstractslider/tst_qabstractslider.cpp @@ -33,7 +33,7 @@ #include <QSlider> #include <QStyle> #include <QStyleOption> -#include <QTime> +#include <QElapsedTimer> #include <QDebug> #include <QtTest/private/qtesthelpers_p.h> @@ -91,7 +91,7 @@ private slots: void connectedSliders(); private: - void waitUntilTimeElapsed(const QTime& t, int ms); + void waitUntilTimeElapsed(const QElapsedTimer &t, int ms); QWidget *topLevel; Slider *slider; @@ -2053,11 +2053,11 @@ void tst_QAbstractSlider::setValue() QVERIFY(sliderMovedTimeStamp < valueChangedTimeStamp); } -void tst_QAbstractSlider::waitUntilTimeElapsed(const QTime& t, int ms) +void tst_QAbstractSlider::waitUntilTimeElapsed(const QElapsedTimer &t, int ms) { const int eps = 80; while (t.elapsed() < ms + eps) - QTest::qWait(qMax(ms - t.elapsed() + eps, 25)); + QTest::qWait(qMax(int(ms - t.elapsed() + eps), 25)); } void tst_QAbstractSlider::setRepeatAction() @@ -2073,7 +2073,7 @@ void tst_QAbstractSlider::setRepeatAction() QCOMPARE(spy.count(), 0); QCOMPARE(slider->value(), 55); - QTime t; + QElapsedTimer t; t.start(); QTest::qWait(300); QCOMPARE(spy.count(), 0); 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")); diff --git a/tests/auto/widgets/widgets/qfontcombobox/tst_qfontcombobox.cpp b/tests/auto/widgets/widgets/qfontcombobox/tst_qfontcombobox.cpp index 1813e5ad5f..5392d36ae0 100644 --- a/tests/auto/widgets/widgets/qfontcombobox/tst_qfontcombobox.cpp +++ b/tests/auto/widgets/widgets/qfontcombobox/tst_qfontcombobox.cpp @@ -108,7 +108,7 @@ void tst_QFontComboBox::currentFont() QFont oldCurrentFont = box.currentFont(); box.setCurrentFont(currentFont); - QRegExp foundry(" \\[.*\\]"); + QRegularExpression foundry(" \\[.*\\]"); if (!box.currentFont().family().contains(foundry)) { QCOMPARE(box.currentFont(), currentFont); } diff --git a/tests/auto/widgets/widgets/qsplitter/tst_qsplitter.cpp b/tests/auto/widgets/widgets/qsplitter/tst_qsplitter.cpp index d744cece9c..8b45ac20b7 100644 --- a/tests/auto/widgets/widgets/qsplitter/tst_qsplitter.cpp +++ b/tests/auto/widgets/widgets/qsplitter/tst_qsplitter.cpp @@ -735,6 +735,7 @@ void tst_QSplitter::replaceWidget() // Configure splitter QWidget *oldWidget = sp.widget(index); + QTest::qWait(100); // Make sure we record the right original size (after the window manager adds the frame) const QRect oldGeom = oldWidget ? oldWidget->geometry() : QRect(); if (oldWidget) { // Collapse first, then hide, if necessary diff --git a/tests/auto/widgets/widgets/qtextbrowser/heading.html b/tests/auto/widgets/widgets/qtextbrowser/heading.html new file mode 100644 index 0000000000..8b23807f65 --- /dev/null +++ b/tests/auto/widgets/widgets/qtextbrowser/heading.html @@ -0,0 +1,2 @@ +<h3>this is a heading</h3> +<p>this is a paragraph</p> diff --git a/tests/auto/widgets/widgets/qtextbrowser/markdown.really b/tests/auto/widgets/widgets/qtextbrowser/markdown.really new file mode 100644 index 0000000000..be56aef234 --- /dev/null +++ b/tests/auto/widgets/widgets/qtextbrowser/markdown.really @@ -0,0 +1,2 @@ +### this is a heading +this is a paragraph diff --git a/tests/auto/widgets/widgets/qtextbrowser/qtextbrowser.pro b/tests/auto/widgets/widgets/qtextbrowser/qtextbrowser.pro index 05c156bf59..dfdcf26497 100644 --- a/tests/auto/widgets/widgets/qtextbrowser/qtextbrowser.pro +++ b/tests/auto/widgets/widgets/qtextbrowser/qtextbrowser.pro @@ -4,6 +4,6 @@ SOURCES += tst_qtextbrowser.cpp QT += widgets testlib -TESTDATA += *.html *.md subdir/* +TESTDATA += *.html *.md markdown.really subdir/* builtin_testdata: DEFINES += BUILTIN_TESTDATA diff --git a/tests/auto/widgets/widgets/qtextbrowser/tst_qtextbrowser.cpp b/tests/auto/widgets/widgets/qtextbrowser/tst_qtextbrowser.cpp index 22cd3b46c6..083e297941 100644 --- a/tests/auto/widgets/widgets/qtextbrowser/tst_qtextbrowser.cpp +++ b/tests/auto/widgets/widgets/qtextbrowser/tst_qtextbrowser.cpp @@ -92,7 +92,8 @@ private slots: void focusIndicator(); void focusHistory(); void urlEncoding(); - void markdown(); + void sourceType_data(); + void sourceType(); private: TestBrowser *browser; @@ -679,19 +680,45 @@ void tst_QTextBrowser::urlEncoding() delete browser; } -void tst_QTextBrowser::markdown() +void tst_QTextBrowser::sourceType_data() { - browser->setSource(QUrl::fromLocalFile(QFINDTESTDATA("markdown.md"))); + QTest::addColumn<QString>("sourceFile"); + QTest::addColumn<QTextDocument::ResourceType>("sourceType"); + QTest::addColumn<int>("expectedMaxHeadingLevel"); + QTest::addColumn<QTextDocument::ResourceType>("expectedSourceType"); + +#if QT_CONFIG(textmarkdownreader) + const int maxMdHeadingLevel = 3; + const QTextDocument::ResourceType mdExpectedType = QTextDocument::MarkdownResource; +#else + // If Qt doesn't support markdown, and we read a MD document anyway, it won't have any H3's. + const int maxMdHeadingLevel = 0; + const QTextDocument::ResourceType mdExpectedType = QTextDocument::HtmlResource; +#endif + QTest::newRow("markdown detected") << "markdown.md" << QTextDocument::UnknownResource << maxMdHeadingLevel << mdExpectedType; + QTest::newRow("markdown specified") << "markdown.really" << QTextDocument::MarkdownResource << maxMdHeadingLevel << mdExpectedType; + QTest::newRow("markdown not identified") << "markdown.really" << QTextDocument::UnknownResource << 0 << QTextDocument::HtmlResource; + QTest::newRow("html detected") << "heading.html" << QTextDocument::UnknownResource << 3 << QTextDocument::HtmlResource; + QTest::newRow("html specified") << "heading.html" << QTextDocument::HtmlResource << 3 << QTextDocument::HtmlResource; +} + +void tst_QTextBrowser::sourceType() +{ + QFETCH(QString, sourceFile); + QFETCH(QTextDocument::ResourceType, sourceType); + QFETCH(int, expectedMaxHeadingLevel); + QFETCH(QTextDocument::ResourceType, expectedSourceType); + if (sourceType == QTextDocument::UnknownResource) + // verify that the property setter works, with its default parameter for sourceType + browser->setProperty("source", QUrl::fromLocalFile(QFINDTESTDATA(sourceFile))); + else + browser->setSource(QUrl::fromLocalFile(QFINDTESTDATA(sourceFile)), sourceType); + QCOMPARE(browser->sourceType(), expectedSourceType); QTextFrame::iterator iterator = browser->document()->rootFrame()->begin(); int maxHeadingLevel = -1; while (!iterator.atEnd()) maxHeadingLevel = qMax(iterator++.currentBlock().blockFormat().intProperty(QTextFormat::HeadingLevel), maxHeadingLevel); -#if QT_CONFIG(textmarkdownreader) - QCOMPARE(maxHeadingLevel, 3); -#else - // If Qt doesn't support markdown, this document will be misidentified as HTML, so it won't have any H3's. - QCOMPARE(maxHeadingLevel, 0); -#endif + QCOMPARE(maxHeadingLevel, expectedMaxHeadingLevel); } QTEST_MAIN(tst_QTextBrowser) diff --git a/tests/auto/widgets/widgets/qtextedit/tst_qtextedit.cpp b/tests/auto/widgets/widgets/qtextedit/tst_qtextedit.cpp index 3669935823..81682dc027 100644 --- a/tests/auto/widgets/widgets/qtextedit/tst_qtextedit.cpp +++ b/tests/auto/widgets/widgets/qtextedit/tst_qtextedit.cpp @@ -160,6 +160,7 @@ private slots: void selectionChanged(); #ifndef QT_NO_CLIPBOARD void copyPasteBackgroundImage(); + void copyPasteForegroundImage(); #endif void setText(); void cursorRect(); @@ -1904,6 +1905,36 @@ void tst_QTextEdit::copyPasteBackgroundImage() ba.texture().cacheKey() == bb.texture().cacheKey()); QFile::remove(QLatin1String("foo.png")); } + +void tst_QTextEdit::copyPasteForegroundImage() +{ + ed->clear(); + + QPixmap pix(20, 20); + pix.fill(Qt::blue); + + QTextCharFormat fmt; + { + QBrush textureBrush; + { + textureBrush.setTexture(pix); + } + textureBrush.setStyle(Qt::TexturePattern); + fmt.setForeground(textureBrush); + } + ed->textCursor().insertText("Foobar", fmt); + + ed->moveCursor(QTextCursor::Start); + ed->moveCursor(QTextCursor::End, QTextCursor::KeepAnchor); + + ed->copy(); + ed->clear(); + ed->paste(); + + QBrush brush = ed->textCursor().charFormat().foreground(); + QCOMPARE(brush.style(), Qt::TexturePattern); + QCOMPARE(brush.texture().cacheKey(), pix.cacheKey()); +} #endif void tst_QTextEdit::setText() |