on xenial help sign in
Make qmluittests pass with Qt 5.4

Changes:  * Make PinchArea not be a child of Flickable, otherwise when zooming out the Flickable was stealing the events from the PinchArea  * Flush touch events in some tests. Since https://qt.gitorious.org/qt/qtdeclarative/commit/6dc8f47bb05a8acb3cbcc697e0dc05356a01d4cf touch events are aggregated and only sent once per frame, that breaks tests that are expecting things to happen immediately, hence the flush  * Change a verify() to check for !== invalid instead of letting verify() do the cast to boolean by itself  * Make sure the pin lock buttons are enabled before tapping into them Approved by: Andrea Cimitan, Daniel d'Andrada

commit41e34e21339c7df38d04143200134f9a6178581c authorAlbert Astals Cid <albert.astals@canonical.com> dateTue 24 Feb 2015, 10:16 (12 years ago) parent286d0829e00d4f
10 files changed+60−31
qml/Components/ZoomableImage.qml+14−14 tests/plugins/Ubuntu/Gestures/tst_DirectionalDragArea.cpp+9 tests/plugins/Ubuntu/Gestures/tst_TouchGate.cpp+7 tests/qmltests/Dash/Previews/tst_PreviewRatingInput.qml+1−1 tests/utils/modules/Unity/Test/CMakeLists.txt+1 tests/utils/modules/Unity/Test/TouchEventSequenceWrapper.cpp+10−1 tests/utils/modules/Unity/Test/TouchEventSequenceWrapper.h+4−1 tests/utils/modules/Unity/Test/UnityTestCase.qml+11−11 tests/utils/modules/Unity/Test/testutil.cpp+2−2 tests/utils/modules/Unity/Test/testutil.h+1−1
qml/Components/ZoomableImage.qml+14−14
@@ -107,20 +107,6 @@ Item {
107107 }
108108 }
109109
110− PinchArea {
111− id: pinchArea
112− objectName: "pinchArea"
113− property real minScale: 1.0
114− anchors.fill: parent
115− enabled: zoomable ? zoomable : false
116−
117− pinch.target: image
118− pinch.minimumScale: minScale
119− pinch.maximumScale: 10
120−
121− onPinchFinished: flickable.returnToBounds()
122− }
123−
124110 MouseArea {
125111 id: mouseArea
126112 objectName: "mouseArea"
@@ -153,4 +139,18 @@ Item {
153139 }
154140 }
155141 }
142+
143+ PinchArea {
144+ id: pinchArea
145+ objectName: "pinchArea"
146+ property real minScale: 1.0
147+ anchors.fill: flickable
148+ enabled: zoomable ? zoomable : false
149+
150+ pinch.target: image
151+ pinch.minimumScale: minScale
152+ pinch.maximumScale: 10
153+
154+ onPinchFinished: flickable.returnToBounds()
155+ }
156156}
tests/plugins/Ubuntu/Gestures/tst_DirectionalDragArea.cpp+9
@@ -20,6 +20,9 @@
2020#include <QtQml/QQmlEngine>
2121#include <QPointer>
2222#include <private/qquickmousearea_p.h>
23+#if (QT_VERSION >= QT_VERSION_CHECK(5, 4, 0))
24+ #include <private/qquickwindow_p.h>
25+#endif
2326
2427
2528#include <DirectionalDragArea.h>
@@ -814,10 +817,16 @@ void tst_DirectionalDragArea::sceneDistance()
814817
815818 QTest::touchEvent(m_view, m_device).press(0, touchPoint.toPoint());
816819
820+#if (QT_VERSION >= QT_VERSION_CHECK(5, 4, 0))
821+ QQuickWindowPrivate *wp = QQuickWindowPrivate::get(m_view);
822+#endif
817823 for (int i = 0; i < totalMovementSteps; ++i) {
818824 touchPoint += touchMovement;
819825 passTime(movementTimeStepMs);
820826 QTest::touchEvent(m_view, m_device).move(0, touchPoint.toPoint());
827+#if (QT_VERSION >= QT_VERSION_CHECK(5, 4, 0))
828+ wp->flushDelayedTouchEvent();
829+#endif
821830 }
822831
823832 qreal actualDragDistance = ((qreal)totalMovementSteps) * movementStepDistance;
tests/plugins/Ubuntu/Gestures/tst_TouchGate.cpp+7
@@ -19,6 +19,9 @@
1919#include <QQmlEngine>
2020#include <QQuickView>
2121#include <QSharedPointer>
22+#if (QT_VERSION >= QT_VERSION_CHECK(5, 4, 0))
23+ #include <private/qquickwindow_p.h>
24+#endif
2225
2326// C++ std lib
2427#include <functional>
@@ -192,6 +195,10 @@ void tst_TouchGate::holdsEventsUntilGainsOwnership()
192195
193196 if (!ownershipAfterTouchEnd) {
194197 touchRegistry->removeCandidateOwnerForTouch(0, candidateItem);
198+#if (QT_VERSION >= QT_VERSION_CHECK(5, 4, 0))
199+ QQuickWindowPrivate *wp = QQuickWindowPrivate::get(testItem->window());
200+ wp->flushDelayedTouchEvent();
201+#endif
195202 // TouchGate should now open its flood gates and let testItem get all
196203 // events from touch 0 produced so far
197204 QCOMPARE(testItem->touchEventsReceived.count(), 2);
tests/qmltests/Dash/Previews/tst_PreviewRatingInput.qml+1−1
@@ -196,7 +196,7 @@ Rectangle {
196196 compare(args[1], "rated");
197197 compare(args[2]["rating"], data.triggeredData["rating"]);
198198 compare(args[2]["review"], data.triggeredData["review"]);
199− verify(args[2]["author"]); // Just verifying it exists now
199+ verify(args[2]["author"] !== undefined); // Just verifying it exists now
200200 }
201201 }
202202}
tests/utils/modules/Unity/Test/CMakeLists.txt+1
@@ -4,6 +4,7 @@ add_definitions(-DQT_NO_KEYWORDS)
44
55include_directories(
66 ${Qt5Gui_PRIVATE_INCLUDE_DIRS}
7+ ${Qt5Quick_PRIVATE_INCLUDE_DIRS}
78 ${CMAKE_SOURCE_DIR}/libs/UbuntuGestures
89)
910
tests/utils/modules/Unity/Test/TouchEventSequenceWrapper.cpp+10−1
@@ -15,15 +15,24 @@
1515 */
1616
1717#include "TouchEventSequenceWrapper.h"
18−TouchEventSequenceWrapper::TouchEventSequenceWrapper(QTest::QTouchEventSequence eventSequence)
18+#include <private/qquickwindow_p.h>
19+
20+TouchEventSequenceWrapper::TouchEventSequenceWrapper(QTest::QTouchEventSequence eventSequence, QQuickItem *item)
1921 : QObject(0)
2022 , m_eventSequence(eventSequence)
23+ , m_item(item)
2124{
2225}
2326
2427void TouchEventSequenceWrapper::commit(bool processEvents)
2528{
2629 m_eventSequence.commit(processEvents);
30+#if (QT_VERSION >= QT_VERSION_CHECK(5, 4, 0))
31+ if (m_item->window()) {
32+ QQuickWindowPrivate *wp = QQuickWindowPrivate::get(m_item->window());
33+ wp->flushDelayedTouchEvent();
34+ }
35+#endif
2736}
2837
2938void TouchEventSequenceWrapper::move(int touchId, int x, int y)
tests/utils/modules/Unity/Test/TouchEventSequenceWrapper.h+4−1
@@ -21,11 +21,13 @@
2121#include <QtTest/QTest>
2222#include <QtQml/qqml.h>
2323
24+class QQuickItem;
25+
2426class TouchEventSequenceWrapper : public QObject
2527{
2628 Q_OBJECT
2729public:
28− TouchEventSequenceWrapper(QTest::QTouchEventSequence eventSequence);
30+ TouchEventSequenceWrapper(QTest::QTouchEventSequence eventSequence, QQuickItem *item);
2931
3032 Q_INVOKABLE void commit(bool processEvents = true);
3133 Q_INVOKABLE void move(int touchId, int x, int y);
@@ -35,6 +37,7 @@ public:
3537
3638private:
3739 QTest::QTouchEventSequence m_eventSequence;
40+ QQuickItem *m_item;
3841};
3942
4043QML_DECLARE_TYPE(TouchEventSequenceWrapper)
tests/utils/modules/Unity/Test/UnityTestCase.qml+11−11
@@ -221,8 +221,8 @@ TestCase {
221221 }
222222 }
223223
224− function touchEvent() {
225− return UT.Util.touchEvent()
224+ function touchEvent(item) {
225+ return UT.Util.touchEvent(item)
226226 }
227227
228228 // speed is in pixels/second
@@ -255,7 +255,7 @@ TestCase {
255255 if (beginTouch) {
256256 fakeDateTime.currentTimeMs += timeStep
257257
258− var event = touchEvent()
258+ var event = touchEvent(item)
259259 event.press(0 /* touchId */, rootFrom.x, rootFrom.y)
260260 event.commit()
261261 }
@@ -265,19 +265,19 @@ TestCase {
265265 // Avoid any rounding errors by making the last move be at precisely
266266 // the point specified
267267 wait(iterations / speed)
268− var event = touchEvent()
268+ var event = touchEvent(item)
269269 event.move(0 /* touchId */, rootTo.x, rootTo.y)
270270 event.commit()
271271 } else {
272272 wait(iterations / speed)
273− var event = touchEvent()
273+ var event = touchEvent(item)
274274 event.move(0 /* touchId */, rootFrom.x + (i + 1) * diffX, rootFrom.y + (i + 1) * diffY)
275275 event.commit()
276276 }
277277 }
278278 if (endTouch) {
279279 fakeDateTime.currentTimeMs += timeStep
280− var event = touchEvent()
280+ var event = touchEvent(item)
281281 event.release(0 /* touchId */, rootTo.x, rootTo.y)
282282 event.commit()
283283 }
@@ -287,7 +287,7 @@ TestCase {
287287 // Make sure the item is rendered
288288 waitForRendering(item);
289289
290− var event1 = touchEvent();
290+ var event1 = touchEvent(item);
291291 // first finger
292292 event1.press(0, x1Start, y1Start);
293293 event1.commit();
@@ -320,7 +320,7 @@ TestCase {
320320 var root = fetchRootItem(item)
321321 var rootPoint = item.mapToItem(root, x, y)
322322
323− var event = touchEvent()
323+ var event = touchEvent(item)
324324 event.press(0 /* touchId */, rootPoint.x, rootPoint.y)
325325 event.commit()
326326 }
@@ -329,7 +329,7 @@ TestCase {
329329 var root = fetchRootItem(item)
330330 var rootPoint = item.mapToItem(root, x, y)
331331
332− var event = touchEvent()
332+ var event = touchEvent(item)
333333 event.release(0 /* touchId */, rootPoint.x, rootPoint.y)
334334 event.commit()
335335 }
@@ -347,11 +347,11 @@ TestCase {
347347 var root = fetchRootItem(item)
348348 var rootPoint = item.mapToItem(root, x, y)
349349
350− var event = touchEvent()
350+ var event = touchEvent(item)
351351 event.press(0 /* touchId */, rootPoint.x, rootPoint.y)
352352 event.commit()
353353
354− event = touchEvent()
354+ event = touchEvent(item)
355355 event.release(0 /* touchId */, rootPoint.x, rootPoint.y)
356356 event.commit()
357357 }
tests/utils/modules/Unity/Test/testutil.cpp+2−2
@@ -55,14 +55,14 @@ TestUtil::isInstanceOf(QObject *obj, QString name)
5555 return result;
5656}
5757
58−TouchEventSequenceWrapper *TestUtil::touchEvent()
58+TouchEventSequenceWrapper *TestUtil::touchEvent(QQuickItem *item)
5959{
6060 ensureTargetWindow();
6161 ensureTouchDevice();
6262 ensureTouchRegistryInstalled();
6363
6464 return new TouchEventSequenceWrapper(
65− QTest::touchEvent(m_targetWindow, m_touchDevice, /* autoCommit */ false));
65+ QTest::touchEvent(m_targetWindow, m_touchDevice, /* autoCommit */ false), item);
6666}
6767
6868void TestUtil::ensureTargetWindow()
tests/utils/modules/Unity/Test/testutil.h+1−1
@@ -33,7 +33,7 @@ public:
3333 ~TestUtil();
3434
3535 Q_INVOKABLE bool isInstanceOf(QObject*, QString);
36− Q_INVOKABLE TouchEventSequenceWrapper *touchEvent();
36+ Q_INVOKABLE TouchEventSequenceWrapper *touchEvent(QQuickItem *item);
3737 Q_INVOKABLE void ensureTouchRegistryInstalled();
3838
3939private: