diff options
Diffstat (limited to 'tests/auto/widgets/kernel')
6 files changed, 169 insertions, 18 deletions
diff --git a/tests/auto/widgets/kernel/qboxlayout/tst_qboxlayout.cpp b/tests/auto/widgets/kernel/qboxlayout/tst_qboxlayout.cpp index 00bde3cb25..cbfbefaf3c 100644 --- a/tests/auto/widgets/kernel/qboxlayout/tst_qboxlayout.cpp +++ b/tests/auto/widgets/kernel/qboxlayout/tst_qboxlayout.cpp @@ -415,7 +415,7 @@ public: QSize minimumSize() const { return QSize(m_descr.minimumSize, 0); } QSize maximumSize() const { return QSize(m_descr.maximumSize, QLAYOUTSIZE_MAX); } Qt::Orientations expandingDirections() const - { return m_descr.expanding ? Qt::Horizontal : Qt::Orientations(0); } + { return m_descr.expanding ? Qt::Horizontal : Qt::Orientations{}; } void setGeometry(const QRect &r) { m_pos = r.x(); m_size = r.width();} QRect geometry() const { return QRect(m_pos, 0, m_size, 100); } bool isEmpty() const { return m_descr.empty; } diff --git a/tests/auto/widgets/kernel/qlayout/tst_qlayout.cpp b/tests/auto/widgets/kernel/qlayout/tst_qlayout.cpp index 140a367afe..c8fe1841c8 100644 --- a/tests/auto/widgets/kernel/qlayout/tst_qlayout.cpp +++ b/tests/auto/widgets/kernel/qlayout/tst_qlayout.cpp @@ -163,7 +163,7 @@ void tst_QLayout::smartMaxSize() QSizePolicy::MinimumExpanding, QSizePolicy::Ignored }; - Qt::Alignment alignments[] = { 0, + Qt::Alignment alignments[] = { Qt::Alignment{}, Qt::AlignLeft, Qt::AlignRight, Qt::AlignHCenter diff --git a/tests/auto/widgets/kernel/qshortcut/tst_qshortcut.cpp b/tests/auto/widgets/kernel/qshortcut/tst_qshortcut.cpp index 82ab9c9c3b..aa687cfc3c 100644 --- a/tests/auto/widgets/kernel/qshortcut/tst_qshortcut.cpp +++ b/tests/auto/widgets/kernel/qshortcut/tst_qshortcut.cpp @@ -103,6 +103,7 @@ public slots: private slots: void cleanup(); + void pmf_connect(); void number_data(); void number(); void text_data(); @@ -203,6 +204,45 @@ void tst_QShortcut::cleanup() QVERIFY(QApplication::topLevelWidgets().size() <= 1); // The data driven tests keep a widget around } +void tst_QShortcut::pmf_connect() +{ + class MyObject : public QObject + { + public: + using QObject::QObject; + void onActivated() { ++activated; } + void onAmbiguous() { ++ambiguous; } + void reset() { activated = 0; ambiguous = 0; } + int activated = 0; + int ambiguous = 0; + } myObject; + QWidget parent; + + auto runCheck = [&myObject](QShortcut *sc, int activated, int ambiguous) + { + myObject.reset(); + sc->activated(); + sc->activatedAmbiguously(); + delete sc; + QCOMPARE(myObject.activated, activated); + QCOMPARE(myObject.ambiguous, ambiguous); + }; + + runCheck(new QShortcut(QKeySequence(), &parent, + [&myObject]() { ++myObject.activated; }), + 1, 0); + runCheck(new QShortcut(QKeySequence(), &parent, + &myObject, &MyObject::onActivated), + 1, 0); + runCheck(new QShortcut(QKeySequence(), &parent, + &myObject, &MyObject::onActivated, &MyObject::onAmbiguous), + 1, 1); + runCheck(new QShortcut(QKeySequence(), &parent, &myObject, + &MyObject::onActivated, &myObject, &MyObject::onAmbiguous), + 1, 1); +} + + Qt::KeyboardModifiers tst_QShortcut::toButtons( int key ) { Qt::KeyboardModifiers result = Qt::NoModifier; diff --git a/tests/auto/widgets/kernel/qwidget/BLACKLIST b/tests/auto/widgets/kernel/qwidget/BLACKLIST index 26f9ce1b85..be19d8fd0b 100644 --- a/tests/auto/widgets/kernel/qwidget/BLACKLIST +++ b/tests/auto/widgets/kernel/qwidget/BLACKLIST @@ -22,7 +22,7 @@ opensuse-leap # QTBUG-68175 opensuse-42.3 [childEvents] -osx ci +macos [renderInvisible] osx-10.12 osx-10.11 @@ -34,8 +34,7 @@ osx [render_systemClip] osx [showMinimizedKeepsFocus] -osx-10.12 ci -osx-10.13 ci +macos [maskedUpdate] opensuse opensuse-leap @@ -49,3 +48,7 @@ ubuntu # QTBUG-75270 winrt +[syntheticEnterLeave] +macos # Can't move cursor (QTBUG-76312) +[taskQTBUG_4055_sendSyntheticEnterLeave] +macos # Can't move cursor (QTBUG-76312) diff --git a/tests/auto/widgets/kernel/qwidget/tst_qwidget.cpp b/tests/auto/widgets/kernel/qwidget/tst_qwidget.cpp index c29d1bbe04..dd747a8616 100644 --- a/tests/auto/widgets/kernel/qwidget/tst_qwidget.cpp +++ b/tests/auto/widgets/kernel/qwidget/tst_qwidget.cpp @@ -53,12 +53,14 @@ #include <qmainwindow.h> #include <qdockwidget.h> #include <qrandom.h> +#include <qstylehints.h> #include <qtoolbar.h> #include <qtoolbutton.h> #include <QtCore/qoperatingsystemversion.h> #include <QtGui/qpaintengine.h> #include <QtGui/qbackingstore.h> #include <QtGui/qguiapplication.h> +#include <QtGui/qpa/qplatformwindow.h> #include <QtGui/qscreen.h> #include <qmenubar.h> #include <qcompleter.h> @@ -198,6 +200,7 @@ private slots: void hideWhenFocusWidgetIsChild(); void normalGeometry(); void setGeometry(); + void setGeometryHidden(); void windowOpacity(); void raise(); void lower(); @@ -225,6 +228,7 @@ private slots: void setFixedSize(); void ensureCreated(); + void createAndDestroy(); void winIdChangeEvent(); void persistentWinId(); void showNativeChild(); @@ -401,6 +405,7 @@ private slots: void tabletTracking(); void closeEvent(); + void closeWithChildWindow(); private: bool ensureScreenSize(int width, int height); @@ -2945,6 +2950,38 @@ void tst_QWidget::setGeometry() QCOMPARE(tlw.geometry(), tr); } +void tst_QWidget::setGeometryHidden() +{ + if (QGuiApplication::styleHints()->showIsMaximized()) + QSKIP("Platform does not support QWidget::setGeometry() - skipping"); + + QWidget tlw; + tlw.setWindowTitle(QLatin1String(QTest::currentTestFunction())); + QWidget child(&tlw); + + const QRect tr(m_availableTopLeft + QPoint(100, 100), 2 * m_testWidgetSize); + const QRect cr(QPoint(50, 50), m_testWidgetSize); + tlw.setGeometry(tr); + child.setGeometry(cr); + tlw.showNormal(); + + tlw.hide(); + QTRY_VERIFY(tlw.isHidden()); + tlw.setGeometry(cr); + QVERIFY(tlw.testAttribute(Qt::WA_PendingMoveEvent)); + QVERIFY(tlw.testAttribute(Qt::WA_PendingResizeEvent)); + QImage img(tlw.size(), QImage::Format_ARGB32); // just needed to call QWidget::render() + tlw.render(&img); + QVERIFY(!tlw.testAttribute(Qt::WA_PendingMoveEvent)); + QVERIFY(!tlw.testAttribute(Qt::WA_PendingResizeEvent)); + tlw.setGeometry(cr); + QVERIFY(!tlw.testAttribute(Qt::WA_PendingMoveEvent)); + QVERIFY(!tlw.testAttribute(Qt::WA_PendingResizeEvent)); + tlw.resize(cr.size()); + QVERIFY(!tlw.testAttribute(Qt::WA_PendingMoveEvent)); + QVERIFY(!tlw.testAttribute(Qt::WA_PendingResizeEvent)); +} + void tst_QWidget::windowOpacity() { QWidget widget; @@ -4215,6 +4252,58 @@ public: int winIdChangeEventCount() const { return m_winIdList.count(); } }; +class CreateDestroyWidget : public WinIdChangeWidget +{ +public: + void create() { QWidget::create(); } + void destroy() { QWidget::destroy(); } +}; + +void tst_QWidget::createAndDestroy() +{ + CreateDestroyWidget widget; + + // Create and destroy via QWidget + widget.create(); + QVERIFY(widget.testAttribute(Qt::WA_WState_Created)); + QCOMPARE(widget.winIdChangeEventCount(), 1); + QVERIFY(widget.internalWinId()); + + widget.destroy(); + QVERIFY(!widget.testAttribute(Qt::WA_WState_Created)); + QCOMPARE(widget.winIdChangeEventCount(), 2); + QVERIFY(!widget.internalWinId()); + + // Create via QWidget, destroy via QWindow + widget.create(); + QVERIFY(widget.testAttribute(Qt::WA_WState_Created)); + QCOMPARE(widget.winIdChangeEventCount(), 3); + QVERIFY(widget.internalWinId()); + + widget.windowHandle()->destroy(); + QVERIFY(!widget.testAttribute(Qt::WA_WState_Created)); + QCOMPARE(widget.winIdChangeEventCount(), 4); + QVERIFY(!widget.internalWinId()); + + // Create via QWidget again + widget.create(); + QVERIFY(widget.testAttribute(Qt::WA_WState_Created)); + QCOMPARE(widget.winIdChangeEventCount(), 5); + QVERIFY(widget.internalWinId()); + + // Destroy via QWindow, create via QWindow + widget.windowHandle()->destroy(); + QVERIFY(widget.windowHandle()); + QVERIFY(!widget.testAttribute(Qt::WA_WState_Created)); + QCOMPARE(widget.winIdChangeEventCount(), 6); + QVERIFY(!widget.internalWinId()); + + widget.windowHandle()->create(); + QVERIFY(widget.testAttribute(Qt::WA_WState_Created)); + QCOMPARE(widget.winIdChangeEventCount(), 7); + QVERIFY(widget.internalWinId()); +} + void tst_QWidget::winIdChangeEvent() { { @@ -8384,12 +8473,9 @@ void tst_QWidget::resizeInPaintEvent() widget.resizeInPaintEvent = true; // This will call resize in the paintEvent, which in turn will call // invalidateBackingStore() and a new update request should be posted. - widget.repaint(); - QCOMPARE(widget.numPaintEvents, 1); - widget.numPaintEvents = 0; - - // Make sure the resize triggers another update. - QTRY_COMPARE(widget.numPaintEvents, 1); + // the resize triggers another update. + widget.update(); + QTRY_COMPARE(widget.numPaintEvents, 2); } void tst_QWidget::opaqueChildren() @@ -8558,8 +8644,8 @@ void tst_QWidget::immediateRepaintAfterInvalidateBackingStore() // The entire widget is already dirty, but this time we want to update immediately // by calling repaint(), and thus we have to repaint the widget and not wait for // the UpdateRequest to be sent when we get back to the event loop. - widget->repaint(); - QCOMPARE(widget->numPaintEvents, 1); + widget->update(); + QTRY_COMPARE(widget->numPaintEvents, 1); } #endif @@ -9831,7 +9917,7 @@ public: if (!static_cast<QWidgetPrivate*>(d_ptr.data())->maybeRepaintManager()) { static_cast<QWidgetPrivate*>(d_ptr.data())->topData()->repaintManager.reset(new QWidgetRepaintManager(this)); static_cast<QWidgetPrivate*>(d_ptr.data())->invalidateBackingStore(this->rect()); - repaint(); + update(); } } }; @@ -9854,7 +9940,7 @@ void tst_QWidget::scrollWithoutBackingStore() scrollable.scroll(-25,-25); QCOMPARE(child.pos(),QPoint(25,25)); scrollable.enableBackingStore(); - QCOMPARE(child.pos(),QPoint(25,25)); + QTRY_COMPARE(child.pos(),QPoint(25,25)); } #endif @@ -11173,5 +11259,27 @@ void tst_QWidget::closeEvent() QCOMPARE(widget.closeCount, 1); } +void tst_QWidget::closeWithChildWindow() +{ + QWidget widget; + auto childWidget = new QWidget(&widget); + childWidget->setAttribute(Qt::WA_NativeWindow); + childWidget->windowHandle()->create(); + widget.show(); + QVERIFY(QTest::qWaitForWindowExposed(&widget)); + widget.windowHandle()->close(); + widget.show(); + QVERIFY(QTest::qWaitForWindowExposed(&widget)); + // Check that the child window inside the window is now visible + QVERIFY(childWidget->isVisible()); + + // Now explicitly hide the childWidget + childWidget->hide(); + widget.windowHandle()->close(); + widget.show(); + QVERIFY(QTest::qWaitForWindowExposed(&widget)); + QVERIFY(!childWidget->isVisible()); +} + QTEST_MAIN(tst_QWidget) #include "tst_qwidget.moc" diff --git a/tests/auto/widgets/kernel/qwidget_window/tst_qwidget_window.cpp b/tests/auto/widgets/kernel/qwidget_window/tst_qwidget_window.cpp index 7d114fde56..dd3e2f844b 100644 --- a/tests/auto/widgets/kernel/qwidget_window/tst_qwidget_window.cpp +++ b/tests/auto/widgets/kernel/qwidget_window/tst_qwidget_window.cpp @@ -845,12 +845,12 @@ void tst_QWidget_window::tst_dnd_propagation() auto posInsideLabel = QHighDpi::toNativePixels(QPoint(60, 60), window->screen()); // Enter DropTarget. - QWindowSystemInterface::handleDrag(window, &mimeData, posInsideDropTarget, supportedActions, 0, 0); + QWindowSystemInterface::handleDrag(window, &mimeData, posInsideDropTarget, supportedActions, {}, {}); // Enter QLabel. This will propagate because default QLabel does // not accept the drop event in dragEnterEvent(). - QWindowSystemInterface::handleDrag(window, &mimeData, posInsideLabel, supportedActions, 0, 0); + QWindowSystemInterface::handleDrag(window, &mimeData, posInsideLabel, supportedActions, {}, {}); // Drop on QLabel. DropTarget will get dropEvent(), because it accepted the event. - QWindowSystemInterface::handleDrop(window, &mimeData, posInsideLabel, supportedActions, 0, 0); + QWindowSystemInterface::handleDrop(window, &mimeData, posInsideLabel, supportedActions, {}, {}); QGuiApplication::processEvents(); |