From: Matthew Cattell Date: Tue, 6 Sep 2011 11:14:37 +0000 (+0200) Subject: qsgcanvas autotest made to work with refactor and added break statement to qsgcanvas... X-Git-Url: http://git.silmor.de/gitweb/?a=commitdiff_plain;h=fa19b6b5b81b44047a1e9ca574fbce13bc38c7a5;p=konrad%2Fqtdeclarative.git qsgcanvas autotest made to work with refactor and added break statement to qsgcanvas.cpp in event processing amended wait times / changed include for private headers Change-Id: I4f790907268be357986e181e4624f8e54efcb2ec Reviewed-on: http://codereview.qt.nokia.com/4256 Reviewed-by: Samuel Rødal --- diff --git a/src/declarative/items/qsgcanvas.cpp b/src/declarative/items/qsgcanvas.cpp index 6339683..4707ad2 100644 --- a/src/declarative/items/qsgcanvas.cpp +++ b/src/declarative/items/qsgcanvas.cpp @@ -860,6 +860,7 @@ bool QSGCanvas::event(QEvent *e) d->deliverTouchEvent(touch); if (!touch->isAccepted()) return false; + break; } case QEvent::Leave: d->clearHover(); diff --git a/tests/auto/declarative/qsgcanvas/tst_qsgcanvas.cpp b/tests/auto/declarative/qsgcanvas/tst_qsgcanvas.cpp index 0791884..c7d3e28 100644 --- a/tests/auto/declarative/qsgcanvas/tst_qsgcanvas.cpp +++ b/tests/auto/declarative/qsgcanvas/tst_qsgcanvas.cpp @@ -42,15 +42,16 @@ #include #include #include - -#include "qsgitem.h" -#include "qsgcanvas.h" -#include "private/qsgrectangle_p.h" +#include +#include +#include #include "../../../shared/util.h" +#include struct TouchEventData { QEvent::Type type; QWidget *widget; + QWindow *window; Qt::TouchPointStates states; QList touchPoints; }; @@ -60,6 +61,7 @@ static QTouchEvent::TouchPoint makeTouchPoint(QSGItem *item, const QPointF &p, c QPointF last = lastPoint.isNull() ? p : lastPoint; QTouchEvent::TouchPoint tp; + tp.setPos(p); tp.setLastPos(last); tp.setScenePos(item->mapToScene(p)); @@ -71,7 +73,7 @@ static QTouchEvent::TouchPoint makeTouchPoint(QSGItem *item, const QPointF &p, c static TouchEventData makeTouchData(QEvent::Type type, QWidget *w, Qt::TouchPointStates states, const QList &touchPoints) { - TouchEventData d = { type, w, states, touchPoints }; + TouchEventData d = { type, w, 0, states, touchPoints }; return d; } @@ -81,6 +83,17 @@ static TouchEventData makeTouchData(QEvent::Type type, QWidget *w, Qt::TouchPoin points << touchPoint; return makeTouchData(type, w, states, points); } +static TouchEventData makeTouchData(QEvent::Type type, QWindow *w, Qt::TouchPointStates states, const QList& touchPoints) +{ + TouchEventData d = { type, 0, w, states, touchPoints }; + return d; +} +static TouchEventData makeTouchData(QEvent::Type type, QWindow *w, Qt::TouchPointStates states, const QTouchEvent::TouchPoint &touchPoint) +{ + QList points; + points << touchPoint; + return makeTouchData(type, w, states, points); +} #define COMPARE_TOUCH_POINTS(tp1, tp2) \ { \ @@ -118,7 +131,7 @@ public: setEnabled(true); setOpacity(1.0); - lastEvent = makeTouchData(QEvent::None, 0, 0, QList()); + lastEvent = makeTouchData(QEvent::None, canvas(), 0, QList());//CHECK_VALID } bool acceptEvents; @@ -195,7 +208,7 @@ void tst_qsgcanvas::touchEvent_basic() { QSGCanvas *canvas = new QSGCanvas; canvas->resize(250, 250); - canvas->window()->move(100, 100); + canvas->move(100, 100); canvas->show(); TestTouchItem *bottomItem = new TestTouchItem(canvas->rootItem()); @@ -215,16 +228,23 @@ void tst_qsgcanvas::touchEvent_basic() QPointF pos(10, 10); // press single point - QTest::touchEvent(canvas).press(0, topItem->mapToScene(pos).toPoint()); + QTest::touchEvent(canvas).press(0, topItem->mapToScene(pos).toPoint(),canvas); + QTest::qWait(50); + + + QCOMPARE(topItem->lastEvent.touchPoints.count(), 1); + QVERIFY(middleItem->lastEvent.touchPoints.isEmpty()); QVERIFY(bottomItem->lastEvent.touchPoints.isEmpty()); + TouchEventData d = makeTouchData(QEvent::TouchBegin, canvas, Qt::TouchPointPressed, makeTouchPoint(topItem,pos)); COMPARE_TOUCH_DATA(topItem->lastEvent, makeTouchData(QEvent::TouchBegin, canvas, Qt::TouchPointPressed, makeTouchPoint(topItem, pos))); topItem->reset(); // press multiple points - QTest::touchEvent(canvas).press(0, topItem->mapToScene(pos).toPoint()) - .press(1, bottomItem->mapToScene(pos).toPoint()); + QTest::touchEvent(canvas).press(0, topItem->mapToScene(pos).toPoint(),canvas) + .press(1, bottomItem->mapToScene(pos).toPoint(), canvas); + QTest::qWait(50); QCOMPARE(topItem->lastEvent.touchPoints.count(), 1); QVERIFY(middleItem->lastEvent.touchPoints.isEmpty()); QCOMPARE(bottomItem->lastEvent.touchPoints.count(), 1); @@ -234,25 +254,31 @@ void tst_qsgcanvas::touchEvent_basic() bottomItem->reset(); // touch point on top item moves to bottom item, but top item should still receive the event - QTest::touchEvent(canvas).press(0, topItem->mapToScene(pos).toPoint()); - QTest::touchEvent(canvas).move(0, bottomItem->mapToScene(pos).toPoint()); + QTest::touchEvent(canvas).press(0, topItem->mapToScene(pos).toPoint(), canvas); + QTest::qWait(50); + QTest::touchEvent(canvas).move(0, bottomItem->mapToScene(pos).toPoint(), canvas); + QTest::qWait(50); QCOMPARE(topItem->lastEvent.touchPoints.count(), 1); COMPARE_TOUCH_DATA(topItem->lastEvent, makeTouchData(QEvent::TouchUpdate, canvas, Qt::TouchPointMoved, makeTouchPoint(topItem, topItem->mapFromItem(bottomItem, pos), pos))); topItem->reset(); // touch point on bottom item moves to top item, but bottom item should still receive the event - QTest::touchEvent(canvas).press(0, bottomItem->mapToScene(pos).toPoint()); - QTest::touchEvent(canvas).move(0, topItem->mapToScene(pos).toPoint()); + QTest::touchEvent(canvas).press(0, bottomItem->mapToScene(pos).toPoint(), canvas); + QTest::qWait(50); + QTest::touchEvent(canvas).move(0, topItem->mapToScene(pos).toPoint(), canvas); + QTest::qWait(50); QCOMPARE(bottomItem->lastEvent.touchPoints.count(), 1); COMPARE_TOUCH_DATA(bottomItem->lastEvent, makeTouchData(QEvent::TouchUpdate, canvas, Qt::TouchPointMoved, makeTouchPoint(bottomItem, bottomItem->mapFromItem(topItem, pos), pos))); bottomItem->reset(); // a single stationary press on an item shouldn't cause an event - QTest::touchEvent(canvas).press(0, topItem->mapToScene(pos).toPoint()); + QTest::touchEvent(canvas).press(0, topItem->mapToScene(pos).toPoint(), canvas); + QTest::qWait(50); QTest::touchEvent(canvas).stationary(0) - .press(1, bottomItem->mapToScene(pos).toPoint()); + .press(1, bottomItem->mapToScene(pos).toPoint(), canvas); + QTest::qWait(50); QCOMPARE(topItem->lastEvent.touchPoints.count(), 1); // received press only, not stationary QVERIFY(middleItem->lastEvent.touchPoints.isEmpty()); QCOMPARE(bottomItem->lastEvent.touchPoints.count(), 1); @@ -262,19 +288,24 @@ void tst_qsgcanvas::touchEvent_basic() bottomItem->reset(); // move touch point from top item to bottom, and release - QTest::touchEvent(canvas).press(0, topItem->mapToScene(pos).toPoint()); - QTest::touchEvent(canvas).release(0, bottomItem->mapToScene(pos).toPoint()); + QTest::touchEvent(canvas).press(0, topItem->mapToScene(pos).toPoint(),canvas); + QTest::qWait(50); + QTest::touchEvent(canvas).release(0, bottomItem->mapToScene(pos).toPoint(),canvas); + QTest::qWait(50); QCOMPARE(topItem->lastEvent.touchPoints.count(), 1); COMPARE_TOUCH_DATA(topItem->lastEvent, makeTouchData(QEvent::TouchEnd, canvas, Qt::TouchPointReleased, makeTouchPoint(topItem, topItem->mapFromItem(bottomItem, pos), pos))); topItem->reset(); // release while another point is pressed - QTest::touchEvent(canvas).press(0, topItem->mapToScene(pos).toPoint()) - .press(1, bottomItem->mapToScene(pos).toPoint()); - QTest::touchEvent(canvas).move(0, bottomItem->mapToScene(pos).toPoint()); - QTest::touchEvent(canvas).release(0, bottomItem->mapToScene(pos).toPoint()) + QTest::touchEvent(canvas).press(0, topItem->mapToScene(pos).toPoint(),canvas) + .press(1, bottomItem->mapToScene(pos).toPoint(), canvas); + QTest::qWait(50); + QTest::touchEvent(canvas).move(0, bottomItem->mapToScene(pos).toPoint(), canvas); + QTest::qWait(50); + QTest::touchEvent(canvas).release(0, bottomItem->mapToScene(pos).toPoint(), canvas) .stationary(1); + QTest::qWait(50); QCOMPARE(topItem->lastEvent.touchPoints.count(), 1); QVERIFY(middleItem->lastEvent.touchPoints.isEmpty()); QCOMPARE(bottomItem->lastEvent.touchPoints.count(), 1); @@ -298,7 +329,7 @@ void tst_qsgcanvas::touchEvent_propagation() QSGCanvas *canvas = new QSGCanvas; canvas->resize(250, 250); - canvas->window()->move(100, 100); + canvas->move(100, 100); canvas->show(); TestTouchItem *bottomItem = new TestTouchItem(canvas->rootItem()); @@ -326,7 +357,8 @@ void tst_qsgcanvas::touchEvent_propagation() topItem->setOpacity(itemOpacity); // single touch to top item, should be received by middle item - QTest::touchEvent(canvas).press(0, pointInTopItem); + QTest::touchEvent(canvas).press(0, pointInTopItem, canvas); + QTest::qWait(50); QVERIFY(topItem->lastEvent.touchPoints.isEmpty()); QCOMPARE(middleItem->lastEvent.touchPoints.count(), 1); QVERIFY(bottomItem->lastEvent.touchPoints.isEmpty()); @@ -334,13 +366,14 @@ void tst_qsgcanvas::touchEvent_propagation() makeTouchPoint(middleItem, middleItem->mapFromItem(topItem, pos)))); // touch top and middle items, middle item should get both events - QTest::touchEvent(canvas).press(0, pointInTopItem) - .press(1, pointInMiddleItem); + QTest::touchEvent(canvas).press(0, pointInTopItem, canvas) + .press(1, pointInMiddleItem, canvas); + QTest::qWait(50); QVERIFY(topItem->lastEvent.touchPoints.isEmpty()); QCOMPARE(middleItem->lastEvent.touchPoints.count(), 2); QVERIFY(bottomItem->lastEvent.touchPoints.isEmpty()); COMPARE_TOUCH_DATA(middleItem->lastEvent, makeTouchData(QEvent::TouchBegin, canvas, Qt::TouchPointPressed, - (QList() << makeTouchPoint(middleItem, middleItem->mapFromItem(topItem, pos)) + (QList() << makeTouchPoint(middleItem, middleItem->mapFromItem(topItem, pos)) << makeTouchPoint(middleItem, pos) ))); middleItem->reset(); @@ -350,8 +383,9 @@ void tst_qsgcanvas::touchEvent_propagation() middleItem->setOpacity(itemOpacity); // touch top and middle items, bottom item should get all events - QTest::touchEvent(canvas).press(0, pointInTopItem) - .press(1, pointInMiddleItem); + QTest::touchEvent(canvas).press(0, pointInTopItem, canvas) + .press(1, pointInMiddleItem, canvas); + QTest::qWait(50); QVERIFY(topItem->lastEvent.touchPoints.isEmpty()); QVERIFY(middleItem->lastEvent.touchPoints.isEmpty()); QCOMPARE(bottomItem->lastEvent.touchPoints.count(), 2); @@ -366,9 +400,10 @@ void tst_qsgcanvas::touchEvent_propagation() bottomItem->setOpacity(itemOpacity); // no events should be received - QTest::touchEvent(canvas).press(0, pointInTopItem) - .press(1, pointInMiddleItem) - .press(2, pointInBottomItem); + QTest::touchEvent(canvas).press(0, pointInTopItem, canvas) + .press(1, pointInMiddleItem, canvas) + .press(2, pointInBottomItem, canvas); + QTest::qWait(50); QVERIFY(topItem->lastEvent.touchPoints.isEmpty()); QVERIFY(middleItem->lastEvent.touchPoints.isEmpty()); QVERIFY(bottomItem->lastEvent.touchPoints.isEmpty()); @@ -381,7 +416,8 @@ void tst_qsgcanvas::touchEvent_propagation() middleItem->acceptEvents = acceptEvents; middleItem->setEnabled(enableItem); middleItem->setOpacity(itemOpacity); - QTest::touchEvent(canvas).press(0, pointInTopItem); + QTest::touchEvent(canvas).press(0, pointInTopItem, canvas); + QTest::qWait(50); if (!enableItem || itemOpacity == 0) { // middle item is disabled or has 0 opacity, bottom item receives the event QVERIFY(topItem->lastEvent.touchPoints.isEmpty());