diff options
Diffstat (limited to 'tests/auto/gui')
-rw-r--r-- | tests/auto/gui/image/qiconhighdpi/qiconhighdpi.pro | 2 | ||||
-rw-r--r-- | tests/auto/gui/kernel/qwindow/tst_qwindow.cpp | 104 | ||||
-rw-r--r-- | tests/auto/gui/painting/qpdfwriter/tst_qpdfwriter.cpp | 70 |
3 files changed, 84 insertions, 92 deletions
diff --git a/tests/auto/gui/image/qiconhighdpi/qiconhighdpi.pro b/tests/auto/gui/image/qiconhighdpi/qiconhighdpi.pro index 17553158bc..49c615721b 100644 --- a/tests/auto/gui/image/qiconhighdpi/qiconhighdpi.pro +++ b/tests/auto/gui/image/qiconhighdpi/qiconhighdpi.pro @@ -1,5 +1,5 @@ CONFIG += testcase -TARGET = tst_qicon +TARGET = tst_qiconhighdpi QT += testlib SOURCES += tst_qiconhighdpi.cpp diff --git a/tests/auto/gui/kernel/qwindow/tst_qwindow.cpp b/tests/auto/gui/kernel/qwindow/tst_qwindow.cpp index 60f89fcb4e..34de756ab5 100644 --- a/tests/auto/gui/kernel/qwindow/tst_qwindow.cpp +++ b/tests/auto/gui/kernel/qwindow/tst_qwindow.cpp @@ -1031,6 +1031,23 @@ public: Qt::MouseButtons buttonStateInGeneratedMove; }; +static void simulateMouseClick(QWindow *target, const QPointF &local, const QPointF &global) +{ + QWindowSystemInterface::handleMouseEvent(target, local, global, + {}, Qt::LeftButton, QEvent::MouseButtonPress); + QWindowSystemInterface::handleMouseEvent(target, local, global, + Qt::LeftButton, Qt::LeftButton, QEvent::MouseButtonRelease); +} + +static void simulateMouseClick(QWindow *target, ulong &timeStamp, + const QPointF &local, const QPointF &global) +{ + QWindowSystemInterface::handleMouseEvent(target, timeStamp++, local, global, + {}, Qt::LeftButton, QEvent::MouseButtonPress); + QWindowSystemInterface::handleMouseEvent(target, timeStamp++, local, global, + Qt::LeftButton, Qt::LeftButton, QEvent::MouseButtonRelease); +} + void tst_QWindow::testInputEvents() { InputTestWindow window; @@ -1072,15 +1089,13 @@ void tst_QWindow::testInputEvents() window.mousePressButton = window.mouseReleaseButton = 0; const QPointF nonWindowGlobal(window.geometry().topRight() + QPoint(200, 50)); // not inside the window const QPointF deviceNonWindowGlobal = QHighDpi::toNativePixels(nonWindowGlobal, window.screen()); - QWindowSystemInterface::handleMouseEvent(nullptr, deviceNonWindowGlobal, deviceNonWindowGlobal, Qt::LeftButton); - QWindowSystemInterface::handleMouseEvent(nullptr, deviceNonWindowGlobal, deviceNonWindowGlobal, Qt::NoButton); + simulateMouseClick(nullptr, deviceNonWindowGlobal, deviceNonWindowGlobal); QCoreApplication::processEvents(); QCOMPARE(window.mousePressButton, 0); QCOMPARE(window.mouseReleaseButton, 0); const QPointF windowGlobal = window.mapToGlobal(local.toPoint()); const QPointF deviceWindowGlobal = QHighDpi::toNativePixels(windowGlobal, window.screen()); - QWindowSystemInterface::handleMouseEvent(nullptr, deviceWindowGlobal, deviceWindowGlobal, Qt::LeftButton); - QWindowSystemInterface::handleMouseEvent(nullptr, deviceWindowGlobal, deviceWindowGlobal, Qt::NoButton); + simulateMouseClick(nullptr, deviceWindowGlobal, deviceWindowGlobal); QCoreApplication::processEvents(); QCOMPARE(window.mousePressButton, int(Qt::LeftButton)); QCOMPARE(window.mouseReleaseButton, int(Qt::LeftButton)); @@ -1204,8 +1219,7 @@ void tst_QWindow::mouseToTouchTranslation() window.show(); QVERIFY(QTest::qWaitForWindowExposed(&window)); - QWindowSystemInterface::handleMouseEvent(&window, QPoint(10, 10), window.mapToGlobal(QPoint(10, 10)), Qt::LeftButton); - QWindowSystemInterface::handleMouseEvent(&window, QPoint(10, 10), window.mapToGlobal(QPoint(10, 10)), Qt::NoButton); + QTest::mouseClick(&window, Qt::LeftButton, {}, QPoint(10, 10)); QCoreApplication::processEvents(); QCoreApplication::setAttribute(Qt::AA_SynthesizeTouchForUnhandledMouseEvents, false); @@ -1217,8 +1231,7 @@ void tst_QWindow::mouseToTouchTranslation() window.ignoreMouse = false; - QWindowSystemInterface::handleMouseEvent(&window, QPoint(10, 10), window.mapToGlobal(QPoint(10, 10)), Qt::LeftButton); - QWindowSystemInterface::handleMouseEvent(&window, QPoint(10, 10), window.mapToGlobal(QPoint(10, 10)), Qt::NoButton); + QTest::mouseClick(&window, Qt::LeftButton, {}, QPoint(10, 10)); QCoreApplication::processEvents(); QCoreApplication::setAttribute(Qt::AA_SynthesizeTouchForUnhandledMouseEvents, false); @@ -1229,8 +1242,7 @@ void tst_QWindow::mouseToTouchTranslation() window.ignoreMouse = true; - QWindowSystemInterface::handleMouseEvent(&window, QPoint(10, 10), window.mapToGlobal(QPoint(10, 10)), Qt::LeftButton); - QWindowSystemInterface::handleMouseEvent(&window, QPoint(10, 10), window.mapToGlobal(QPoint(10, 10)), Qt::NoButton); + QTest::mouseClick(&window, Qt::LeftButton, {}, QPoint(10, 10)); QCoreApplication::processEvents(); // touch event synthesis disabled @@ -1255,8 +1267,7 @@ void tst_QWindow::mouseToTouchLoop() window.show(); QVERIFY(QTest::qWaitForWindowExposed(&window)); - QWindowSystemInterface::handleMouseEvent(&window, QPoint(10, 10), window.mapToGlobal(QPoint(10, 10)), Qt::LeftButton); - QWindowSystemInterface::handleMouseEvent(&window, QPoint(10, 10), window.mapToGlobal(QPoint(10, 10)), Qt::NoButton); + QTest::mouseClick(&window, Qt::LeftButton, {}, QPoint(10, 10)); QCoreApplication::processEvents(); QCoreApplication::setAttribute(Qt::AA_SynthesizeTouchForUnhandledMouseEvents, false); @@ -1551,8 +1562,8 @@ void tst_QWindow::mouseEventSequence() ulong timestamp = 0; QPointF local(12, 34); const QPointF deviceLocal = QHighDpi::toNativePixels(local, &window); - QWindowSystemInterface::handleMouseEvent(&window, timestamp++, deviceLocal, deviceLocal, Qt::LeftButton); - QWindowSystemInterface::handleMouseEvent(&window, timestamp++, deviceLocal, deviceLocal, Qt::NoButton); + + simulateMouseClick(&window, timestamp, deviceLocal, deviceLocal); QCoreApplication::processEvents(); QCOMPARE(window.mousePressedCount, 1); QCOMPARE(window.mouseReleasedCount, 1); @@ -1564,10 +1575,8 @@ void tst_QWindow::mouseEventSequence() // A double click must result in press, release, press, doubleclick, release. // Check that no unexpected event suppression occurs and that the order is correct. - QWindowSystemInterface::handleMouseEvent(&window, timestamp++, local, local, Qt::LeftButton); - QWindowSystemInterface::handleMouseEvent(&window, timestamp++, local, local, Qt::NoButton); - QWindowSystemInterface::handleMouseEvent(&window, timestamp++, local, local, Qt::LeftButton); - QWindowSystemInterface::handleMouseEvent(&window, timestamp++, local, local, Qt::NoButton); + simulateMouseClick(&window, timestamp, local, local); + simulateMouseClick(&window, timestamp, local, local); QCoreApplication::processEvents(); QCOMPARE(window.mousePressedCount, 2); QCOMPARE(window.mouseReleasedCount, 2); @@ -1578,12 +1587,9 @@ void tst_QWindow::mouseEventSequence() window.resetCounters(); // Triple click = double + single click - QWindowSystemInterface::handleMouseEvent(&window, timestamp++, local, local, Qt::LeftButton); - QWindowSystemInterface::handleMouseEvent(&window, timestamp++, local, local, Qt::NoButton); - QWindowSystemInterface::handleMouseEvent(&window, timestamp++, local, local, Qt::LeftButton); - QWindowSystemInterface::handleMouseEvent(&window, timestamp++, local, local, Qt::NoButton); - QWindowSystemInterface::handleMouseEvent(&window, timestamp++, local, local, Qt::LeftButton); - QWindowSystemInterface::handleMouseEvent(&window, timestamp++, local, local, Qt::NoButton); + simulateMouseClick(&window, timestamp, local, local); + simulateMouseClick(&window, timestamp, local, local); + simulateMouseClick(&window, timestamp, local, local); QCoreApplication::processEvents(); QCOMPARE(window.mousePressedCount, 3); QCOMPARE(window.mouseReleasedCount, 3); @@ -1594,14 +1600,10 @@ void tst_QWindow::mouseEventSequence() window.resetCounters(); // Two double clicks. - QWindowSystemInterface::handleMouseEvent(&window, timestamp++, local, local, Qt::LeftButton); - QWindowSystemInterface::handleMouseEvent(&window, timestamp++, local, local, Qt::NoButton); - QWindowSystemInterface::handleMouseEvent(&window, timestamp++, local, local, Qt::LeftButton); - QWindowSystemInterface::handleMouseEvent(&window, timestamp++, local, local, Qt::NoButton); - QWindowSystemInterface::handleMouseEvent(&window, timestamp++, local, local, Qt::LeftButton); - QWindowSystemInterface::handleMouseEvent(&window, timestamp++, local, local, Qt::NoButton); - QWindowSystemInterface::handleMouseEvent(&window, timestamp++, local, local, Qt::LeftButton); - QWindowSystemInterface::handleMouseEvent(&window, timestamp++, local, local, Qt::NoButton); + simulateMouseClick(&window, timestamp, local, local); + simulateMouseClick(&window, timestamp, local, local); + simulateMouseClick(&window, timestamp, local, local); + simulateMouseClick(&window, timestamp, local, local); QCoreApplication::processEvents(); QCOMPARE(window.mousePressedCount, 4); QCOMPARE(window.mouseReleasedCount, 4); @@ -1612,17 +1614,13 @@ void tst_QWindow::mouseEventSequence() window.resetCounters(); // Four clicks, none of which qualifies as a double click. - QWindowSystemInterface::handleMouseEvent(&window, timestamp++, local, local, Qt::LeftButton); - QWindowSystemInterface::handleMouseEvent(&window, timestamp++, local, local, Qt::NoButton); + simulateMouseClick(&window, timestamp, local, local); timestamp += doubleClickInterval; - QWindowSystemInterface::handleMouseEvent(&window, timestamp++, local, local, Qt::LeftButton); - QWindowSystemInterface::handleMouseEvent(&window, timestamp++, local, local, Qt::NoButton); + simulateMouseClick(&window, timestamp, local, local); timestamp += doubleClickInterval; - QWindowSystemInterface::handleMouseEvent(&window, timestamp++, local, local, Qt::LeftButton); - QWindowSystemInterface::handleMouseEvent(&window, timestamp++, local, local, Qt::NoButton); + simulateMouseClick(&window, timestamp, local, local); timestamp += doubleClickInterval; - QWindowSystemInterface::handleMouseEvent(&window, timestamp++, local, local, Qt::LeftButton); - QWindowSystemInterface::handleMouseEvent(&window, timestamp++, local, local, Qt::NoButton); + simulateMouseClick(&window, timestamp, local, local); timestamp += doubleClickInterval; QCoreApplication::processEvents(); QCOMPARE(window.mousePressedCount, 4); @@ -1674,10 +1672,13 @@ void tst_QWindow::inputReentrancy() // Queue three events. QPointF local(12, 34); - QWindowSystemInterface::handleMouseEvent(&window, local, local, Qt::LeftButton); + QWindowSystemInterface::handleMouseEvent(&window, local, local, {}, + Qt::LeftButton, QEvent::MouseButtonPress); local += QPointF(2, 2); - QWindowSystemInterface::handleMouseEvent(&window, local, local, Qt::LeftButton); - QWindowSystemInterface::handleMouseEvent(&window, local, local, Qt::NoButton); + QWindowSystemInterface::handleMouseEvent(&window, local, local, + Qt::LeftButton, Qt::LeftButton, QEvent::MouseMove); + QWindowSystemInterface::handleMouseEvent(&window, local, local, Qt::LeftButton, + Qt::LeftButton, QEvent::MouseButtonRelease); // Process them. However, the event handler for the press will also call // processEvents() so the move and release will be delivered before returning // from mousePressEvent(). The point is that no events should get lost. @@ -1747,12 +1748,14 @@ void tst_QWindow::tabletEvents() const QPoint global = window.mapToGlobal(local); const QPoint deviceLocal = QHighDpi::toNativeLocalPosition(local, &window); const QPoint deviceGlobal = QHighDpi::toNativePixels(global, window.screen()); - QWindowSystemInterface::handleTabletEvent(&window, true, deviceLocal, deviceGlobal, 1, 2, 0.5, 1, 2, 0.1, 0, 0, 0); + QWindowSystemInterface::handleTabletEvent(&window, deviceLocal, deviceGlobal, + 1, 2, Qt::LeftButton, 0.5, 1, 2, 0.1, 0, 0, 0); QCoreApplication::processEvents(); QTRY_VERIFY(window.eventType == QEvent::TabletPress); QTRY_COMPARE(window.eventGlobal.toPoint(), global); QTRY_COMPARE(window.eventLocal.toPoint(), local); - QWindowSystemInterface::handleTabletEvent(&window, false, deviceLocal, deviceGlobal, 1, 2, 0.5, 1, 2, 0.1, 0, 0, 0); + QWindowSystemInterface::handleTabletEvent(&window, deviceLocal, deviceGlobal, 1, 2, + {}, 0.5, 1, 2, 0.1, 0, 0, 0); QCoreApplication::processEvents(); QTRY_COMPARE(window.eventType, QEvent::TabletRelease); @@ -1788,11 +1791,9 @@ void tst_QWindow::windowModality_QTBUG27039() modalB.setModality(Qt::ApplicationModal); modalB.show(); - QPointF local(5, 5); - QWindowSystemInterface::handleMouseEvent(&modalA, local, local, Qt::LeftButton); - QWindowSystemInterface::handleMouseEvent(&modalA, local, local, Qt::NoButton); - QWindowSystemInterface::handleMouseEvent(&modalB, local, local, Qt::LeftButton); - QWindowSystemInterface::handleMouseEvent(&modalB, local, local, Qt::NoButton); + QPoint local(5, 5); + QTest::mouseClick(&modalA, Qt::LeftButton, {}, local); + QTest::mouseClick(&modalB, Qt::LeftButton, {}, local); QCoreApplication::processEvents(); // modal A should be blocked since it was shown first, but modal B should not be blocked @@ -1800,8 +1801,7 @@ void tst_QWindow::windowModality_QTBUG27039() QCOMPARE(modalA.mousePressedCount, 0); modalB.hide(); - QWindowSystemInterface::handleMouseEvent(&modalA, local, local, Qt::LeftButton); - QWindowSystemInterface::handleMouseEvent(&modalA, local, local, Qt::NoButton); + QTest::mouseClick(&modalA, Qt::LeftButton, {}, local); QCoreApplication::processEvents(); // modal B has been hidden, modal A should be unblocked again diff --git a/tests/auto/gui/painting/qpdfwriter/tst_qpdfwriter.cpp b/tests/auto/gui/painting/qpdfwriter/tst_qpdfwriter.cpp index 9e9b0db366..b2b2b685ae 100644 --- a/tests/auto/gui/painting/qpdfwriter/tst_qpdfwriter.cpp +++ b/tests/auto/gui/painting/qpdfwriter/tst_qpdfwriter.cpp @@ -73,12 +73,12 @@ void tst_QPdfWriter::basics() QCOMPARE(writer.pageSize(), QPdfWriter::A5); QCOMPARE(writer.pageSizeMM(), QSizeF(148, 210)); - writer.setPageSize(QPdfWriter::A3); + writer.setPageSize(QPageSize(QPageSize::A3)); QCOMPARE(writer.pageLayout().pageSize().id(), QPageSize::A3); QCOMPARE(writer.pageSize(), QPdfWriter::A3); QCOMPARE(writer.pageSizeMM(), QSizeF(297, 420)); - writer.setPageSizeMM(QSize(210, 297)); + writer.setPageSize(QPageSize(QSize(210, 297), QPageSize::Millimeter)); QCOMPARE(writer.pageLayout().pageSize().id(), QPageSize::A4); QCOMPARE(writer.pageSize(), QPdfWriter::A4); QCOMPARE(writer.pageSizeMM(), QSizeF(210, 297)); @@ -101,9 +101,9 @@ void tst_QPdfWriter::basics() QCOMPARE(writer.margins().right, 20.0); QCOMPARE(writer.margins().top, 20.0); QCOMPARE(writer.margins().bottom, 20.0); - QPdfWriter::Margins margins = {50, 50, 50, 50}; - writer.setMargins(margins); - QCOMPARE(writer.pageLayout().margins(), QMarginsF(50, 50, 50, 50)); + const QMarginsF margins = {50, 50, 50, 50}; + writer.setPageMargins(margins, QPageLayout::Millimeter); + QCOMPARE(writer.pageLayout().margins(), margins); QCOMPARE(writer.pageLayout().units(), QPageLayout::Millimeter); QCOMPARE(writer.margins().left, 50.0); QCOMPARE(writer.margins().right, 50.0); @@ -117,7 +117,7 @@ void tst_QPdfWriter::basics() // Test the old page metrics methods, see also QPrinter tests for the same. void tst_QPdfWriter::testPageMetrics_data() { - QTest::addColumn<int>("pageSize"); + QTest::addColumn<QPageSize::PageSizeId>("pageSizeId"); QTest::addColumn<qreal>("widthMMf"); QTest::addColumn<qreal>("heightMMf"); QTest::addColumn<bool>("setMargins"); @@ -126,17 +126,24 @@ void tst_QPdfWriter::testPageMetrics_data() QTest::addColumn<qreal>("topMMf"); QTest::addColumn<qreal>("bottomMMf"); - QTest::newRow("A4") << int(QPdfWriter::A4) << 210.0 << 297.0 << false << 3.53 << 3.53 << 3.53 << 3.53; - QTest::newRow("A4 Margins") << int(QPdfWriter::A4) << 210.0 << 297.0 << true << 20.0 << 30.0 << 40.0 << 50.0; - QTest::newRow("Portrait") << -1 << 345.0 << 678.0 << false << 3.53 << 3.53 << 3.53 << 3.53; - QTest::newRow("Portrait Margins") << -1 << 345.0 << 678.0 << true << 20.0 << 30.0 << 40.0 << 50.0; - QTest::newRow("Landscape") << -1 << 678.0 << 345.0 << false << 3.53 << 3.53 << 3.53 << 3.53; - QTest::newRow("Landscape Margins") << -1 << 678.0 << 345.0 << true << 20.0 << 30.0 << 40.0 << 50.0; + QTest::newRow("A4") << QPageSize::A4 << 210.0 << 297.0 << false + << 3.53 << 3.53 << 3.53 << 3.53; + QTest::newRow("A4 Margins") << QPageSize::A4 << 210.0 << 297.0 << true + << 20.0 << 30.0 << 40.0 << 50.0; + + QTest::newRow("Portrait") << QPageSize::Custom << 345.0 << 678.0 << false + << 3.53 << 3.53 << 3.53 << 3.53; + QTest::newRow("Portrait Margins") << QPageSize::Custom << 345.0 << 678.0 << true + << 20.0 << 30.0 << 40.0 << 50.0; + QTest::newRow("Landscape") << QPageSize::Custom << 678.0 << 345.0 << false + << 3.53 << 3.53 << 3.53 << 3.53; + QTest::newRow("Landscape Margins") << QPageSize::Custom << 678.0 << 345.0 << true + << 20.0 << 30.0 << 40.0 << 50.0; } void tst_QPdfWriter::testPageMetrics() { - QFETCH(int, pageSize); + QFETCH(QPageSize::PageSizeId, pageSizeId); QFETCH(qreal, widthMMf); QFETCH(qreal, heightMMf); QFETCH(bool, setMargins); @@ -161,17 +168,13 @@ void tst_QPdfWriter::testPageMetrics() QCOMPARE(writer.margins().bottom, bottomMMf); } - // Set the given size, in Portrait mode - if (pageSize < 0) { - writer.setPageSize(QPageSize(sizeMMf, QPageSize::Millimeter)); - QCOMPARE(writer.pageSize(), QPdfWriter::Custom); - QCOMPARE(writer.pageLayout().pageSize().id(), QPageSize::Custom); - } else { - writer.setPageSize(QPdfWriter::PageSize(pageSize)); - QCOMPARE(writer.pageSize(), QPdfWriter::PageSize(pageSize)); - QCOMPARE(writer.pageLayout().pageSize().id(), QPageSize::PageSizeId(pageSize)); - } + const QPageSize pageSize = pageSizeId == QPageSize::Custom + ? QPageSize(sizeMMf, QPageSize::Millimeter) : QPageSize(pageSizeId); + writer.setPageSize(pageSize); + QCOMPARE(writer.pageLayout().pageSize().id(), pageSizeId); + QCOMPARE(int(writer.pageSize()), int(pageSizeId)); + QCOMPARE(writer.pageLayout().orientation(), QPageLayout::Portrait); QCOMPARE(writer.margins().left, leftMMf); QCOMPARE(writer.margins().right, rightMMf); @@ -187,13 +190,8 @@ void tst_QPdfWriter::testPageMetrics() // Now switch to Landscape mode, size should be unchanged, but rect and metrics should change writer.setPageOrientation(QPageLayout::Landscape); - if (pageSize < 0) { - QCOMPARE(writer.pageSize(), QPdfWriter::Custom); - QCOMPARE(writer.pageLayout().pageSize().id(), QPageSize::Custom); - } else { - QCOMPARE(writer.pageSize(), QPdfWriter::PageSize(pageSize)); - QCOMPARE(writer.pageLayout().pageSize().id(), QPageSize::PageSizeId(pageSize)); - } + QCOMPARE(writer.pageLayout().pageSize().id(), pageSizeId); + QCOMPARE(int(writer.pageSize()), int(pageSizeId)); QCOMPARE(writer.pageLayout().orientation(), QPageLayout::Landscape); QCOMPARE(writer.margins().left, leftMMf); QCOMPARE(writer.margins().right, rightMMf); @@ -215,15 +213,9 @@ void tst_QPdfWriter::testPageMetrics() // Now while in Landscape mode, set the size again, results should be the same - if (pageSize < 0) { - writer.setPageSize(QPageSize(sizeMMf, QPageSize::Millimeter)); - QCOMPARE(writer.pageSize(), QPdfWriter::Custom); - QCOMPARE(writer.pageLayout().pageSize().id(), QPageSize::Custom); - } else { - writer.setPageSize(QPdfWriter::PageSize(pageSize)); - QCOMPARE(writer.pageSize(), QPdfWriter::PageSize(pageSize)); - QCOMPARE(writer.pageLayout().pageSize().id(), QPageSize::PageSizeId(pageSize)); - } + writer.setPageSize(pageSize); + QCOMPARE(writer.pageLayout().pageSize().id(), pageSizeId); + QCOMPARE(int(writer.pageSize()), int(pageSizeId)); QCOMPARE(writer.pageLayout().orientation(), QPageLayout::Landscape); QCOMPARE(writer.margins().left, leftMMf); QCOMPARE(writer.margins().right, rightMMf); |