diff options
author | Shawn Rutledge <shawn.rutledge@theqtcompany.com> | 2016-05-03 18:27:12 +0200 |
---|---|---|
committer | Shawn Rutledge <shawn.rutledge@qt.io> | 2016-06-10 13:07:17 +0000 |
commit | 982b70d37db337b2c57a3cfce0f24c3d00a598d6 (patch) | |
tree | f86dd50fa2cef003b32b77bbe8eab7cbfac2251e /tests/auto/widgets | |
parent | e73e2264ded27ceb9f3af5b548036d33effa0797 (diff) |
autotests: use QTest::createTouchDevice()
Task-number: QTBUG-44030
Change-Id: I514c1294a0ff6587b825982a8bb354104c214120
Reviewed-by: Laszlo Agocs <laszlo.agocs@theqtcompany.com>
Diffstat (limited to 'tests/auto/widgets')
6 files changed, 31 insertions, 66 deletions
diff --git a/tests/auto/widgets/gestures/qgesturerecognizer/tst_qgesturerecognizer.cpp b/tests/auto/widgets/gestures/qgesturerecognizer/tst_qgesturerecognizer.cpp index 6b0c1ecf57..c3ebb838bb 100644 --- a/tests/auto/widgets/gestures/qgesturerecognizer/tst_qgesturerecognizer.cpp +++ b/tests/auto/widgets/gestures/qgesturerecognizer/tst_qgesturerecognizer.cpp @@ -38,8 +38,6 @@ #include <QtCore/QHash> #include <QtCore/QDebug> -#include <qpa/qwindowsysteminterface.h> - class tst_QGestureRecognizer : public QObject { Q_OBJECT @@ -64,15 +62,13 @@ private: tst_QGestureRecognizer::tst_QGestureRecognizer() : m_fingerDistance(qRound(QGuiApplication::primaryScreen()->physicalDotsPerInch() / 2.0)) - , m_touchDevice(new QTouchDevice) + , m_touchDevice(QTest::createTouchDevice()) { qputenv("QT_PAN_TOUCHPOINTS", "2"); // Prevent device detection of pan touch point count. } void tst_QGestureRecognizer::initTestCase() { - m_touchDevice->setType(QTouchDevice::TouchScreen); - QWindowSystemInterface::registerTouchDevice(m_touchDevice); } #ifndef QT_NO_GESTURES diff --git a/tests/auto/widgets/graphicsview/qgraphicsitem/tst_qgraphicsitem.cpp b/tests/auto/widgets/graphicsview/qgraphicsitem/tst_qgraphicsitem.cpp index c1fe012683..46d0b18990 100644 --- a/tests/auto/widgets/graphicsview/qgraphicsitem/tst_qgraphicsitem.cpp +++ b/tests/auto/widgets/graphicsview/qgraphicsitem/tst_qgraphicsitem.cpp @@ -11017,9 +11017,7 @@ void tst_QGraphicsItem::touchEventPropagation() touchPoints << tp; sendMousePress(&scene, tp.scenePos()); - QTouchDevice *device = new QTouchDevice; - device->setType(QTouchDevice::TouchScreen); - QWindowSystemInterface::registerTouchDevice(device); + QTouchDevice *device = QTest::createTouchDevice(); QTouchEvent touchBegin(QEvent::TouchBegin, device, Qt::NoModifier, Qt::TouchPointPressed, touchPoints); qApp->sendEvent(&scene, &touchBegin); diff --git a/tests/auto/widgets/graphicsview/qgraphicsproxywidget/tst_qgraphicsproxywidget.cpp b/tests/auto/widgets/graphicsview/qgraphicsproxywidget/tst_qgraphicsproxywidget.cpp index 8908b83f11..a3aa90168a 100644 --- a/tests/auto/widgets/graphicsview/qgraphicsproxywidget/tst_qgraphicsproxywidget.cpp +++ b/tests/auto/widgets/graphicsview/qgraphicsproxywidget/tst_qgraphicsproxywidget.cpp @@ -3797,9 +3797,7 @@ void tst_QGraphicsProxyWidget::forwardTouchEvent() EventSpy eventSpy(widget); - QTouchDevice *device = new QTouchDevice; - device->setType(QTouchDevice::TouchScreen); - QWindowSystemInterface::registerTouchDevice(device); + QTouchDevice *device = QTest::createTouchDevice(); QCOMPARE(eventSpy.counts[QEvent::TouchBegin], 0); QCOMPARE(eventSpy.counts[QEvent::TouchUpdate], 0); diff --git a/tests/auto/widgets/kernel/qapplication/tst_qapplication.cpp b/tests/auto/widgets/kernel/qapplication/tst_qapplication.cpp index f942f78b1d..eda51e31a9 100644 --- a/tests/auto/widgets/kernel/qapplication/tst_qapplication.cpp +++ b/tests/auto/widgets/kernel/qapplication/tst_qapplication.cpp @@ -1934,9 +1934,7 @@ void tst_QApplication::touchEventPropagation() release.setState(Qt::TouchPointReleased); releasedTouchPoints << release; - QTouchDevice *device = new QTouchDevice; - device->setType(QTouchDevice::TouchScreen); - QWindowSystemInterface::registerTouchDevice(device); + QTouchDevice *device = QTest::createTouchDevice(); { // touch event behavior on a window diff --git a/tests/auto/widgets/kernel/qwidget/tst_qwidget.cpp b/tests/auto/widgets/kernel/qwidget/tst_qwidget.cpp index 78fbae768a..3253d09bb8 100644 --- a/tests/auto/widgets/kernel/qwidget/tst_qwidget.cpp +++ b/tests/auto/widgets/kernel/qwidget/tst_qwidget.cpp @@ -415,6 +415,7 @@ private: QPoint m_availableTopLeft; QPoint m_safeCursorPos; const bool m_windowsAnimationsEnabled; + QTouchDevice *m_touchScreen; }; bool tst_QWidget::ensureScreenSize(int width, int height) @@ -573,6 +574,7 @@ tst_QWidget::tst_QWidget() : m_platform(QGuiApplication::platformName().toLower()) , m_safeCursorPos(0, 0) , m_windowsAnimationsEnabled(windowsAnimationsEnabled()) + , m_touchScreen(QTest::createTouchDevice()) { if (m_windowsAnimationsEnabled) // Disable animations which can interfere with screen grabbing in moveChild(), showAndMoveChild() setWindowsAnimationsEnabled(false); @@ -9712,25 +9714,21 @@ void tst_QWidget::touchEventSynthesizedMouseEvent() { // Simple case, we ignore the touch events, we get mouse events instead - QTouchDevice *device = new QTouchDevice; - device->setType(QTouchDevice::TouchScreen); - QWindowSystemInterface::registerTouchDevice(device); - TouchMouseWidget widget; widget.show(); QVERIFY(QTest::qWaitForWindowExposed(widget.windowHandle())); QCOMPARE(widget.m_touchEventCount, 0); QCOMPARE(widget.m_mouseEventCount, 0); - QTest::touchEvent(&widget, device).press(0, QPoint(10, 10), &widget); + QTest::touchEvent(&widget, m_touchScreen).press(0, QPoint(10, 10), &widget); QCOMPARE(widget.m_touchEventCount, 0); QCOMPARE(widget.m_mouseEventCount, 1); QCOMPARE(widget.m_lastMouseEventPos, QPointF(10, 10)); - QTest::touchEvent(&widget, device).move(0, QPoint(15, 15), &widget); + QTest::touchEvent(&widget, m_touchScreen).move(0, QPoint(15, 15), &widget); QCOMPARE(widget.m_touchEventCount, 0); QCOMPARE(widget.m_mouseEventCount, 2); QCOMPARE(widget.m_lastMouseEventPos, QPointF(15, 15)); - QTest::touchEvent(&widget, device).release(0, QPoint(20, 20), &widget); + QTest::touchEvent(&widget, m_touchScreen).release(0, QPoint(20, 20), &widget); QCOMPARE(widget.m_touchEventCount, 0); QCOMPARE(widget.m_mouseEventCount, 4); // we receive extra mouse move event QCOMPARE(widget.m_lastMouseEventPos, QPointF(20, 20)); @@ -9738,10 +9736,6 @@ void tst_QWidget::touchEventSynthesizedMouseEvent() { // We accept the touch events, no mouse event is generated - QTouchDevice *device = new QTouchDevice; - device->setType(QTouchDevice::TouchScreen); - QWindowSystemInterface::registerTouchDevice(device); - TouchMouseWidget widget; widget.setAcceptTouch(true); widget.show(); @@ -9749,13 +9743,13 @@ void tst_QWidget::touchEventSynthesizedMouseEvent() QCOMPARE(widget.m_touchEventCount, 0); QCOMPARE(widget.m_mouseEventCount, 0); - QTest::touchEvent(&widget, device).press(0, QPoint(10, 10), &widget); + QTest::touchEvent(&widget, m_touchScreen).press(0, QPoint(10, 10), &widget); QCOMPARE(widget.m_touchEventCount, 1); QCOMPARE(widget.m_mouseEventCount, 0); - QTest::touchEvent(&widget, device).move(0, QPoint(15, 15), &widget); + QTest::touchEvent(&widget, m_touchScreen).move(0, QPoint(15, 15), &widget); QCOMPARE(widget.m_touchEventCount, 2); QCOMPARE(widget.m_mouseEventCount, 0); - QTest::touchEvent(&widget, device).release(0, QPoint(20, 20), &widget); + QTest::touchEvent(&widget, m_touchScreen).release(0, QPoint(20, 20), &widget); QCOMPARE(widget.m_touchEventCount, 3); QCOMPARE(widget.m_mouseEventCount, 0); } @@ -9763,10 +9757,6 @@ void tst_QWidget::touchEventSynthesizedMouseEvent() { // Parent accepts touch events, child ignore both mouse and touch // We should see propagation of the TouchBegin - QTouchDevice *device = new QTouchDevice; - device->setType(QTouchDevice::TouchScreen); - QWindowSystemInterface::registerTouchDevice(device); - TouchMouseWidget parent; parent.setAcceptTouch(true); TouchMouseWidget child(&parent); @@ -9779,7 +9769,7 @@ void tst_QWidget::touchEventSynthesizedMouseEvent() QCOMPARE(child.m_touchEventCount, 0); QCOMPARE(child.m_mouseEventCount, 0); - QTest::touchEvent(parent.window(), device).press(0, QPoint(10, 10), &child); + QTest::touchEvent(parent.window(), m_touchScreen).press(0, QPoint(10, 10), &child); QCOMPARE(parent.m_touchEventCount, 1); QCOMPARE(parent.m_mouseEventCount, 0); QCOMPARE(child.m_touchEventCount, 0); @@ -9789,10 +9779,6 @@ void tst_QWidget::touchEventSynthesizedMouseEvent() { // Parent accepts mouse events, child ignore both mouse and touch // We should see propagation of the TouchBegin into a MouseButtonPress - QTouchDevice *device = new QTouchDevice; - device->setType(QTouchDevice::TouchScreen); - QWindowSystemInterface::registerTouchDevice(device); - TouchMouseWidget parent; TouchMouseWidget child(&parent); child.move(5, 5); @@ -9804,7 +9790,7 @@ void tst_QWidget::touchEventSynthesizedMouseEvent() QCOMPARE(child.m_touchEventCount, 0); QCOMPARE(child.m_mouseEventCount, 0); - QTest::touchEvent(parent.window(), device).press(0, QPoint(10, 10), &child); + QTest::touchEvent(parent.window(), m_touchScreen).press(0, QPoint(10, 10), &child); QCOMPARE(parent.m_touchEventCount, 0); QCOMPARE(parent.m_mouseEventCount, 1); QCOMPARE(parent.m_lastMouseEventPos, QPointF(15, 15)); @@ -9816,10 +9802,6 @@ void tst_QWidget::touchEventSynthesizedMouseEvent() void tst_QWidget::touchUpdateOnNewTouch() { - QTouchDevice *device = new QTouchDevice; - device->setType(QTouchDevice::TouchScreen); - QWindowSystemInterface::registerTouchDevice(device); - TouchMouseWidget widget; widget.setAcceptTouch(true); QVBoxLayout *layout = new QVBoxLayout; @@ -9832,23 +9814,23 @@ void tst_QWidget::touchUpdateOnNewTouch() QCOMPARE(widget.m_touchBeginCount, 0); QCOMPARE(widget.m_touchUpdateCount, 0); QCOMPARE(widget.m_touchEndCount, 0); - QTest::touchEvent(window, device).press(0, QPoint(20, 20), window); + QTest::touchEvent(window, m_touchScreen).press(0, QPoint(20, 20), window); QCOMPARE(widget.m_touchBeginCount, 1); QCOMPARE(widget.m_touchUpdateCount, 0); QCOMPARE(widget.m_touchEndCount, 0); - QTest::touchEvent(window, device).move(0, QPoint(25, 25), window); + QTest::touchEvent(window, m_touchScreen).move(0, QPoint(25, 25), window); QCOMPARE(widget.m_touchBeginCount, 1); QCOMPARE(widget.m_touchUpdateCount, 1); QCOMPARE(widget.m_touchEndCount, 0); - QTest::touchEvent(window, device).stationary(0).press(1, QPoint(40, 40), window); + QTest::touchEvent(window, m_touchScreen).stationary(0).press(1, QPoint(40, 40), window); QCOMPARE(widget.m_touchBeginCount, 1); QCOMPARE(widget.m_touchUpdateCount, 2); QCOMPARE(widget.m_touchEndCount, 0); - QTest::touchEvent(window, device).stationary(1).release(0, QPoint(25, 25), window); + QTest::touchEvent(window, m_touchScreen).stationary(1).release(0, QPoint(25, 25), window); QCOMPARE(widget.m_touchBeginCount, 1); QCOMPARE(widget.m_touchUpdateCount, 3); QCOMPARE(widget.m_touchEndCount, 0); - QTest::touchEvent(window, device).release(1, QPoint(40, 40), window); + QTest::touchEvent(window, m_touchScreen).release(1, QPoint(40, 40), window); QCOMPARE(widget.m_touchBeginCount, 1); QCOMPARE(widget.m_touchUpdateCount, 3); QCOMPARE(widget.m_touchEndCount, 1); @@ -9856,10 +9838,6 @@ void tst_QWidget::touchUpdateOnNewTouch() void tst_QWidget::touchEventsForGesturePendingWidgets() { - QTouchDevice *device = new QTouchDevice; - device->setType(QTouchDevice::TouchScreen); - QWindowSystemInterface::registerTouchDevice(device); - TouchMouseWidget parent; TouchMouseWidget child(&parent); parent.grabGesture(Qt::TapAndHoldGesture); @@ -9872,14 +9850,14 @@ void tst_QWidget::touchEventsForGesturePendingWidgets() QCOMPARE(child.m_gestureEventCount, 0); QCOMPARE(parent.m_touchEventCount, 0); QCOMPARE(parent.m_gestureEventCount, 0); - QTest::touchEvent(window, device).press(0, QPoint(20, 20), window); + QTest::touchEvent(window, m_touchScreen).press(0, QPoint(20, 20), window); QCOMPARE(child.m_touchEventCount, 0); QCOMPARE(child.m_gestureEventCount, 0); QCOMPARE(parent.m_touchBeginCount, 1); // QTapAndHoldGestureRecognizer::create() sets Qt::WA_AcceptTouchEvents QCOMPARE(parent.m_touchUpdateCount, 0); QCOMPARE(parent.m_touchEndCount, 0); QCOMPARE(parent.m_gestureEventCount, 0); - QTest::touchEvent(window, device).move(0, QPoint(25, 25), window); + QTest::touchEvent(window, m_touchScreen).move(0, QPoint(25, 25), window); QCOMPARE(child.m_touchEventCount, 0); QCOMPARE(child.m_gestureEventCount, 0); QCOMPARE(parent.m_touchBeginCount, 1); @@ -9887,7 +9865,7 @@ void tst_QWidget::touchEventsForGesturePendingWidgets() QCOMPARE(parent.m_touchEndCount, 0); QCOMPARE(parent.m_gestureEventCount, 0); QTest::qWait(1000); - QTest::touchEvent(window, device).release(0, QPoint(25, 25), window); + QTest::touchEvent(window, m_touchScreen).release(0, QPoint(25, 25), window); QCOMPARE(child.m_touchEventCount, 0); QCOMPARE(child.m_gestureEventCount, 0); QCOMPARE(parent.m_touchBeginCount, 1); diff --git a/tests/auto/widgets/util/qscroller/tst_qscroller.cpp b/tests/auto/widgets/util/qscroller/tst_qscroller.cpp index 2c398e1b2f..67bae43c9d 100644 --- a/tests/auto/widgets/util/qscroller/tst_qscroller.cpp +++ b/tests/auto/widgets/util/qscroller/tst_qscroller.cpp @@ -125,6 +125,9 @@ private slots: void scrollTo(); void scroll(); void overshoot(); + +private: + QTouchDevice *m_touchScreen = QTest::createTouchDevice(); }; /*! \internal @@ -150,11 +153,8 @@ void tst_QScroller::kineticScroll( tst_QScrollerWidget *sw, QPointF from, QPoint touchPoint.setPos(touchStart); touchPoint.setScenePos(touchStart); touchPoint.setScreenPos(touchStart); - QTouchDevice *device = new QTouchDevice; - device->setType(QTouchDevice::TouchScreen); - QWindowSystemInterface::registerTouchDevice(device); QTouchEvent touchEvent1(QEvent::TouchBegin, - device, + m_touchScreen, Qt::NoModifier, Qt::TouchPointPressed, (QList<QTouchEvent::TouchPoint>() << touchPoint)); @@ -168,7 +168,7 @@ void tst_QScroller::kineticScroll( tst_QScrollerWidget *sw, QPointF from, QPoint touchPoint.setScenePos(touchUpdate); touchPoint.setScreenPos(touchUpdate); QTouchEvent touchEvent2(QEvent::TouchUpdate, - device, + m_touchScreen, Qt::NoModifier, Qt::TouchPointMoved, (QList<QTouchEvent::TouchPoint>() << touchPoint)); @@ -192,7 +192,7 @@ void tst_QScroller::kineticScroll( tst_QScrollerWidget *sw, QPointF from, QPoint touchPoint.setScenePos(touchEnd); touchPoint.setScreenPos(touchEnd); QTouchEvent touchEvent5(QEvent::TouchEnd, - device, + m_touchScreen, Qt::NoModifier, Qt::TouchPointReleased, (QList<QTouchEvent::TouchPoint>() << touchPoint)); @@ -223,11 +223,8 @@ void tst_QScroller::kineticScrollNoTest( tst_QScrollerWidget *sw, QPointF from, touchPoint.setPos(touchStart); touchPoint.setScenePos(touchStart); touchPoint.setScreenPos(touchStart); - QTouchDevice *device = new QTouchDevice; - device->setType(QTouchDevice::TouchScreen); - QWindowSystemInterface::registerTouchDevice(device); QTouchEvent touchEvent1(QEvent::TouchBegin, - device, + m_touchScreen, Qt::NoModifier, Qt::TouchPointPressed, (QList<QTouchEvent::TouchPoint>() << touchPoint)); @@ -239,7 +236,7 @@ void tst_QScroller::kineticScrollNoTest( tst_QScrollerWidget *sw, QPointF from, touchPoint.setScenePos(touchUpdate); touchPoint.setScreenPos(touchUpdate); QTouchEvent touchEvent2(QEvent::TouchUpdate, - device, + m_touchScreen, Qt::NoModifier, Qt::TouchPointMoved, (QList<QTouchEvent::TouchPoint>() << touchPoint)); @@ -252,7 +249,7 @@ void tst_QScroller::kineticScrollNoTest( tst_QScrollerWidget *sw, QPointF from, touchPoint.setScenePos(touchEnd); touchPoint.setScreenPos(touchEnd); QTouchEvent touchEvent5(QEvent::TouchEnd, - device, + m_touchScreen, Qt::NoModifier, Qt::TouchPointReleased, (QList<QTouchEvent::TouchPoint>() << touchPoint)); |