diff options
Diffstat (limited to 'tests/auto/quick/qquickwindow/tst_qquickwindow.cpp')
-rw-r--r-- | tests/auto/quick/qquickwindow/tst_qquickwindow.cpp | 156 |
1 files changed, 138 insertions, 18 deletions
diff --git a/tests/auto/quick/qquickwindow/tst_qquickwindow.cpp b/tests/auto/quick/qquickwindow/tst_qquickwindow.cpp index b8f9102775..17773fcfc4 100644 --- a/tests/auto/quick/qquickwindow/tst_qquickwindow.cpp +++ b/tests/auto/quick/qquickwindow/tst_qquickwindow.cpp @@ -50,6 +50,7 @@ #include <QtQuick/private/qquickloader_p.h> #include "../../shared/util.h" #include "../shared/visualtestutil.h" +#include "../shared/viewtestutil.h" #include <QSignalSpy> #include <qpa/qwindowsysteminterface.h> #include <private/qquickwindow_p.h> @@ -328,6 +329,7 @@ private slots: void animationsWhileHidden(); void focusObject(); + void focusReason(); void ignoreUnhandledMouseEvents(); @@ -362,6 +364,9 @@ private slots: void contentItemSize(); + void defaultSurfaceFormat(); + void glslVersion(); + private: QTouchDevice *touchDevice; QTouchDevice *touchDeviceWithVelocity; @@ -395,7 +400,7 @@ void tst_qquickwindow::aboutToStopSignal() window.hide(); - QVERIFY(spy.count() > 0); + QTRY_VERIFY(spy.count() > 0); } //If the item calls update inside updatePaintNode, it should schedule another sync pass @@ -522,7 +527,7 @@ void tst_qquickwindow::touchEvent_basic() // press multiple points QTest::touchEvent(window, touchDevice).press(0, topItem->mapToScene(pos).toPoint(),window) .press(1, bottomItem->mapToScene(pos).toPoint(), window); - QTest::qWait(50); + QQuickTouchUtils::flush(window); QCOMPARE(topItem->lastEvent.touchPoints.count(), 1); QVERIFY(middleItem->lastEvent.touchPoints.isEmpty()); QCOMPARE(bottomItem->lastEvent.touchPoints.count(), 1); @@ -533,9 +538,9 @@ void tst_qquickwindow::touchEvent_basic() // touch point on top item moves to bottom item, but top item should still receive the event QTest::touchEvent(window, touchDevice).press(0, topItem->mapToScene(pos).toPoint(), window); - QTest::qWait(50); + QQuickTouchUtils::flush(window); QTest::touchEvent(window, touchDevice).move(0, bottomItem->mapToScene(pos).toPoint(), window); - QTest::qWait(50); + QQuickTouchUtils::flush(window); QCOMPARE(topItem->lastEvent.touchPoints.count(), 1); COMPARE_TOUCH_DATA(topItem->lastEvent, makeTouchData(QEvent::TouchUpdate, window, Qt::TouchPointMoved, makeTouchPoint(topItem, topItem->mapFromItem(bottomItem, pos), pos))); @@ -543,9 +548,9 @@ void tst_qquickwindow::touchEvent_basic() // touch point on bottom item moves to top item, but bottom item should still receive the event QTest::touchEvent(window, touchDevice).press(0, bottomItem->mapToScene(pos).toPoint(), window); - QTest::qWait(50); + QQuickTouchUtils::flush(window); QTest::touchEvent(window, touchDevice).move(0, topItem->mapToScene(pos).toPoint(), window); - QTest::qWait(50); + QQuickTouchUtils::flush(window); QCOMPARE(bottomItem->lastEvent.touchPoints.count(), 1); COMPARE_TOUCH_DATA(bottomItem->lastEvent, makeTouchData(QEvent::TouchUpdate, window, Qt::TouchPointMoved, makeTouchPoint(bottomItem, bottomItem->mapFromItem(topItem, pos), pos))); @@ -553,10 +558,10 @@ void tst_qquickwindow::touchEvent_basic() // a single stationary press on an item shouldn't cause an event QTest::touchEvent(window, touchDevice).press(0, topItem->mapToScene(pos).toPoint(), window); - QTest::qWait(50); + QQuickTouchUtils::flush(window); QTest::touchEvent(window, touchDevice).stationary(0) .press(1, bottomItem->mapToScene(pos).toPoint(), window); - QTest::qWait(50); + QQuickTouchUtils::flush(window); QCOMPARE(topItem->lastEvent.touchPoints.count(), 1); // received press only, not stationary QVERIFY(middleItem->lastEvent.touchPoints.isEmpty()); QCOMPARE(bottomItem->lastEvent.touchPoints.count(), 1); @@ -568,12 +573,13 @@ void tst_qquickwindow::touchEvent_basic() // Otherwise you will get an assertion failure: // ASSERT: "itemForTouchPointId.isEmpty()" in file items/qquickwindow.cpp QTest::touchEvent(window, touchDevice).release(0, pos.toPoint(), window).release(1, pos.toPoint(), window); + QQuickTouchUtils::flush(window); // move touch point from top item to bottom, and release QTest::touchEvent(window, touchDevice).press(0, topItem->mapToScene(pos).toPoint(),window); - QTest::qWait(50); + QQuickTouchUtils::flush(window); QTest::touchEvent(window, touchDevice).release(0, bottomItem->mapToScene(pos).toPoint(),window); - QTest::qWait(50); + QQuickTouchUtils::flush(window); QCOMPARE(topItem->lastEvent.touchPoints.count(), 1); COMPARE_TOUCH_DATA(topItem->lastEvent, makeTouchData(QEvent::TouchEnd, window, Qt::TouchPointReleased, makeTouchPoint(topItem, topItem->mapFromItem(bottomItem, pos), pos))); @@ -582,12 +588,12 @@ void tst_qquickwindow::touchEvent_basic() // release while another point is pressed QTest::touchEvent(window, touchDevice).press(0, topItem->mapToScene(pos).toPoint(),window) .press(1, bottomItem->mapToScene(pos).toPoint(), window); - QTest::qWait(50); + QQuickTouchUtils::flush(window); QTest::touchEvent(window, touchDevice).move(0, bottomItem->mapToScene(pos).toPoint(), window); - QTest::qWait(50); + QQuickTouchUtils::flush(window); QTest::touchEvent(window, touchDevice).release(0, bottomItem->mapToScene(pos).toPoint(), window) .stationary(1); - QTest::qWait(50); + QQuickTouchUtils::flush(window); QCOMPARE(topItem->lastEvent.touchPoints.count(), 1); QVERIFY(middleItem->lastEvent.touchPoints.isEmpty()); QCOMPARE(bottomItem->lastEvent.touchPoints.count(), 1); @@ -835,12 +841,15 @@ void tst_qquickwindow::touchEvent_velocity() tp.area = QRectF(pos, QSizeF(4, 4)); points << tp; QWindowSystemInterface::handleTouchEvent(window, touchDeviceWithVelocity, points); + QGuiApplication::processEvents(); + QQuickTouchUtils::flush(window); points[0].state = Qt::TouchPointMoved; points[0].area.adjust(5, 5, 5, 5); QVector2D velocity(1.5, 2.5); points[0].velocity = velocity; QWindowSystemInterface::handleTouchEvent(window, touchDeviceWithVelocity, points); - QCoreApplication::processEvents(); + QGuiApplication::processEvents(); + QQuickTouchUtils::flush(window); QCOMPARE(item->touchEventCount, 2); QCOMPARE(item->lastEvent.touchPoints.count(), 1); QCOMPARE(item->lastVelocity, velocity); @@ -852,7 +861,8 @@ void tst_qquickwindow::touchEvent_velocity() QVector2D transformedVelocity = transformMatrix.mapVector(velocity).toVector2D(); points[0].area.adjust(5, 5, 5, 5); QWindowSystemInterface::handleTouchEvent(window, touchDeviceWithVelocity, points); - QCoreApplication::processEvents(); + QGuiApplication::processEvents(); + QQuickTouchUtils::flush(window); QCOMPARE(item->lastVelocity, transformedVelocity); QPoint itemLocalPos = item->mapFromScene(window->mapFromGlobal(points[0].area.center().toPoint())).toPoint(); QPoint itemLocalPosFromEvent = item->lastEvent.touchPoints[0].pos().toPoint(); @@ -860,7 +870,8 @@ void tst_qquickwindow::touchEvent_velocity() points[0].state = Qt::TouchPointReleased; QWindowSystemInterface::handleTouchEvent(window, touchDeviceWithVelocity, points); - QCoreApplication::processEvents(); + QGuiApplication::processEvents(); + QQuickTouchUtils::flush(window); delete item; } @@ -892,14 +903,19 @@ void tst_qquickwindow::mouseFromTouch_basic() tp.area = QRectF(pos, QSizeF(4, 4)); points << tp; QWindowSystemInterface::handleTouchEvent(window, touchDeviceWithVelocity, points); + QGuiApplication::processEvents(); + QQuickTouchUtils::flush(window); points[0].state = Qt::TouchPointMoved; points[0].area.adjust(5, 5, 5, 5); QVector2D velocity(1.5, 2.5); points[0].velocity = velocity; QWindowSystemInterface::handleTouchEvent(window, touchDeviceWithVelocity, points); + QGuiApplication::processEvents(); + QQuickTouchUtils::flush(window); points[0].state = Qt::TouchPointReleased; QWindowSystemInterface::handleTouchEvent(window, touchDeviceWithVelocity, points); - QCoreApplication::processEvents(); + QGuiApplication::processEvents(); + QQuickTouchUtils::flush(window); // The item should have received a mouse press, move, and release. QCOMPARE(item->mousePressNum, 1); @@ -918,16 +934,20 @@ void tst_qquickwindow::mouseFromTouch_basic() points[0].velocity = velocity; points[0].area = QRectF(pos, QSizeF(4, 4)); QWindowSystemInterface::handleTouchEvent(window, touchDeviceWithVelocity, points); + QGuiApplication::processEvents(); + QQuickTouchUtils::flush(window); points[0].state = Qt::TouchPointMoved; points[0].area.adjust(5, 5, 5, 5); QWindowSystemInterface::handleTouchEvent(window, touchDeviceWithVelocity, points); - QCoreApplication::processEvents(); + QGuiApplication::processEvents(); + QQuickTouchUtils::flush(window); QCOMPARE(item->lastMousePos.toPoint(), item->mapFromScene(window->mapFromGlobal(points[0].area.center().toPoint())).toPoint()); QCOMPARE(item->lastVelocityFromMouseMove, transformedVelocity); points[0].state = Qt::TouchPointReleased; QWindowSystemInterface::handleTouchEvent(window, touchDeviceWithVelocity, points); QCoreApplication::processEvents(); + QQuickTouchUtils::flush(window); delete item; } @@ -1275,6 +1295,33 @@ void tst_qquickwindow::focusObject() QCOMPARE(focusObjectSpy.count(), 3); } +void tst_qquickwindow::focusReason() +{ + QQuickWindow *window = new QQuickWindow; + QScopedPointer<QQuickWindow> cleanup(window); + window->resize(200, 200); + window->show(); + QVERIFY(QTest::qWaitForWindowExposed(window)); + + QQuickItem *firstItem = new QQuickItem; + firstItem->setSize(QSizeF(100, 100)); + firstItem->setParentItem(window->contentItem()); + + QQuickItem *secondItem = new QQuickItem; + secondItem->setSize(QSizeF(100, 100)); + secondItem->setParentItem(window->contentItem()); + + firstItem->forceActiveFocus(Qt::OtherFocusReason); + QCOMPARE(QQuickWindowPrivate::get(window)->lastFocusReason, Qt::OtherFocusReason); + + secondItem->forceActiveFocus(Qt::TabFocusReason); + QCOMPARE(QQuickWindowPrivate::get(window)->lastFocusReason, Qt::TabFocusReason); + + firstItem->forceActiveFocus(Qt::BacktabFocusReason); + QCOMPARE(QQuickWindowPrivate::get(window)->lastFocusReason, Qt::BacktabFocusReason); + +} + void tst_qquickwindow::ignoreUnhandledMouseEvents() { QQuickWindow *window = new QQuickWindow; @@ -1851,6 +1898,79 @@ void tst_qquickwindow::contentItemSize() QCOMPARE(QSizeF(rect->width(), rect->height()), size); } +void tst_qquickwindow::defaultSurfaceFormat() +{ + // It is quite difficult to verify anything for real since the resulting format after + // surface/context creation can be anything, depending on the platform and drivers, + // and many options and settings may fail in various configurations, but test at + // least using some harmless settings to check that the global, static format is + // taken into account in the requested format. + + QSurfaceFormat savedDefaultFormat = QQuickWindow::defaultFormat(); + + // Verify that depth and stencil are set, as they should be, unless they are disabled + // via environment variables. + QVERIFY(savedDefaultFormat.depthBufferSize() >= 16); + QVERIFY(savedDefaultFormat.stencilBufferSize() >= 8); + + QSurfaceFormat format = savedDefaultFormat; + format.setSwapInterval(0); + format.setRedBufferSize(8); + format.setGreenBufferSize(8); + format.setBlueBufferSize(8); + format.setProfile(QSurfaceFormat::CompatibilityProfile); + format.setOption(QSurfaceFormat::DebugContext); + QQuickWindow::setDefaultFormat(format); + + QQuickWindow window; + window.show(); + QVERIFY(QTest::qWaitForWindowExposed(&window)); + + const QSurfaceFormat reqFmt = window.requestedFormat(); + QCOMPARE(format.swapInterval(), reqFmt.swapInterval()); + QCOMPARE(format.redBufferSize(), reqFmt.redBufferSize()); + QCOMPARE(format.greenBufferSize(), reqFmt.greenBufferSize()); + QCOMPARE(format.blueBufferSize(), reqFmt.blueBufferSize()); + QCOMPARE(format.profile(), reqFmt.profile()); + QCOMPARE(int(format.options()), int(reqFmt.options())); + + QQuickWindow::setDefaultFormat(savedDefaultFormat); +} + +void tst_qquickwindow::glslVersion() +{ + QQuickWindow window; + window.show(); + QVERIFY(QTest::qWaitForWindowExposed(&window)); + + // Core profile is never requested by default. + QVERIFY(!window.glslIsCoreProfile()); + + // Get the format from the context, not the window. The actual OpenGL version and + // related settings are associated with the context and are only written back to the + // context's format. + QSurfaceFormat format = window.openglContext()->format(); + + if (format.renderableType() == QSurfaceFormat::OpenGL) { + if (format.majorVersion() == 2) + QCOMPARE(window.glslVersion(), QString()); + else if (format.majorVersion() == 3) + QVERIFY(window.glslVersion().startsWith('3') + || window.glslVersion() == QStringLiteral("130") + || window.glslVersion() == QStringLiteral("140") + || window.glslVersion() == QStringLiteral("150")); + else if (format.majorVersion() == 4) + QVERIFY(window.glslVersion().startsWith('4')); + QVERIFY(!window.glslVersion().contains(QStringLiteral("core"))); + QVERIFY(!window.glslVersion().contains(QStringLiteral("es"))); + } else if (format.renderableType() == QSurfaceFormat::OpenGLES) { + if (format.majorVersion() == 2) + QCOMPARE(window.glslVersion(), QString()); + else + QVERIFY(window.glslVersion().contains(QStringLiteral("es"))); + } +} + QTEST_MAIN(tst_qquickwindow) #include "tst_qquickwindow.moc" |