diff options
Diffstat (limited to 'tests/auto/gui/kernel/qwindow/tst_qwindow.cpp')
-rw-r--r-- | tests/auto/gui/kernel/qwindow/tst_qwindow.cpp | 61 |
1 files changed, 57 insertions, 4 deletions
diff --git a/tests/auto/gui/kernel/qwindow/tst_qwindow.cpp b/tests/auto/gui/kernel/qwindow/tst_qwindow.cpp index 039d095ce6..f2754de929 100644 --- a/tests/auto/gui/kernel/qwindow/tst_qwindow.cpp +++ b/tests/auto/gui/kernel/qwindow/tst_qwindow.cpp @@ -106,6 +106,7 @@ private slots: void flags(); void cleanup(); void testBlockingWindowShownAfterModalDialog(); + void generatedMouseMove(); private: QPoint m_availableTopLeft; @@ -352,7 +353,7 @@ private: class ColoredWindow : public QRasterWindow { public: explicit ColoredWindow(const QColor &color, QWindow *parent = 0) : QRasterWindow(parent), m_color(color) {} - void paintEvent(QPaintEvent *) Q_DECL_OVERRIDE + void paintEvent(QPaintEvent *) override { QPainter p(this); p.fillRect(QRect(QPoint(0, 0), size()), m_color); @@ -702,7 +703,7 @@ class PlatformWindowFilter : public QObject public: PlatformWindowFilter(QObject *parent = 0) : QObject(parent) - , m_window(Q_NULLPTR) + , m_window(nullptr) , m_alwaysExisted(true) {} @@ -714,7 +715,7 @@ public: // If they are, the native platform surface should always exist when we // receive a QPlatformSurfaceEvent if (e->type() == QEvent::PlatformSurface && o == m_window) { - m_alwaysExisted &= (m_window->handle() != Q_NULLPTR); + m_alwaysExisted &= (m_window->handle() != nullptr); } return false; } @@ -741,7 +742,7 @@ void tst_QWindow::platformSurface() QTRY_COMPARE(window.received(QEvent::PlatformSurface), 1); QTRY_COMPARE(window.surfaceEventType(), QPlatformSurfaceEvent::SurfaceCreated); - QTRY_VERIFY(window.handle() != Q_NULLPTR); + QTRY_VERIFY(window.handle() != nullptr); window.destroy(); QTRY_COMPARE(window.received(QEvent::PlatformSurface), 2); @@ -918,6 +919,7 @@ public: } } void mouseMoveEvent(QMouseEvent *event) { + buttonStateInGeneratedMove = event->buttons(); if (ignoreMouse) { event->ignore(); } else { @@ -999,6 +1001,7 @@ public: bool ignoreMouse, ignoreTouch; bool spinLoopWhenPressed; + Qt::MouseButtons buttonStateInGeneratedMove; }; void tst_QWindow::testInputEvents() @@ -2316,6 +2319,56 @@ void tst_QWindow::testBlockingWindowShownAfterModalDialog() QVERIFY(normalWindowAfter.gotBlocked); } +void tst_QWindow::generatedMouseMove() +{ + InputTestWindow w; + w.setGeometry(QRect(m_availableTopLeft + QPoint(100, 100), m_testWindowSize)); + w.show(); + QVERIFY(QTest::qWaitForWindowActive(&w)); + QPoint point(10, 10); + QPoint step(2, 2); + + QVERIFY(w.mouseMovedCount == 0); + QWindowSystemInterface::handleMouseEvent(&w, point, point, Qt::NoButton, Qt::NoButton, QEvent::MouseMove); + QCoreApplication::processEvents(); + QVERIFY(w.mouseMovedCount == 1); + // Press that does not change position should not generate mouse move + QWindowSystemInterface::handleMouseEvent(&w, point, point, Qt::LeftButton, Qt::LeftButton, QEvent::MouseButtonPress); + QWindowSystemInterface::handleMouseEvent(&w, point, point, Qt::LeftButton | Qt::RightButton, Qt::RightButton, QEvent::MouseButtonPress); + QCoreApplication::processEvents(); + QVERIFY(w.mouseMovedCount == 1); + + // Test moves generated for mouse release + point += step; + QWindowSystemInterface::handleMouseEvent(&w, point, point, Qt::RightButton, Qt::LeftButton, QEvent::MouseButtonRelease); + QCoreApplication::processEvents(); + QVERIFY(w.mouseMovedCount == 2); + QVERIFY(w.buttonStateInGeneratedMove == (Qt::LeftButton | Qt::RightButton)); + point += step; + QWindowSystemInterface::handleMouseEvent(&w, point, point, Qt::NoButton, Qt::RightButton, QEvent::MouseButtonRelease); + QCoreApplication::processEvents(); + QVERIFY(w.mouseMovedCount == 3); + QVERIFY(w.buttonStateInGeneratedMove == Qt::RightButton); + + // Test moves generated for mouse press + point += step; + QWindowSystemInterface::handleMouseEvent(&w, point, point, Qt::LeftButton, Qt::LeftButton, QEvent::MouseButtonPress); + QCoreApplication::processEvents(); + QVERIFY(w.mouseMovedCount == 4); + QVERIFY(w.buttonStateInGeneratedMove == Qt::NoButton); + point += step; + QWindowSystemInterface::handleMouseEvent(&w, point, point, Qt::LeftButton | Qt::RightButton, Qt::RightButton, QEvent::MouseButtonPress); + QCoreApplication::processEvents(); + QVERIFY(w.mouseMovedCount == 5); + QVERIFY(w.buttonStateInGeneratedMove == Qt::LeftButton); + + // Release that does not change position should not generate mouse move + QWindowSystemInterface::handleMouseEvent(&w, point, point, Qt::LeftButton, Qt::RightButton, QEvent::MouseButtonRelease); + QWindowSystemInterface::handleMouseEvent(&w, point, point, Qt::NoButton, Qt::LeftButton, QEvent::MouseButtonRelease); + QCoreApplication::processEvents(); + QVERIFY(w.mouseMovedCount == 5); +} + #include <tst_qwindow.moc> QTEST_MAIN(tst_QWindow) |