on xenial help sign in
Refactor Ubuntu.Gesture tests to share common logic
36f751dDaniel d'Andrada
tests/plugins/Ubuntu/Gestures/CMakeLists.txt+20−18
@@ -1,33 +1,34 @@
1−########## tst_DirectionalDragArea
1+include(QmlTest)
2
2
3include_directories(
3include_directories(
4 ${CMAKE_SOURCE_DIR}/plugins/Ubuntu/Gestures
4 ${CMAKE_SOURCE_DIR}/plugins/Ubuntu/Gestures
5 ${CMAKE_CURRENT_BINARY_DIR}
5 ${CMAKE_CURRENT_BINARY_DIR}
6 )
6 )
7
7
8−set(testCommand
9− LD_LIBRARY_PATH=${CMAKE_BINARY_DIR}/plugins/Ubuntu/Gestures
10− ${CMAKE_CURRENT_BINARY_DIR}/DirectionalDragAreaTestExec
11− -o ${CMAKE_BINARY_DIR}/DirectionalDragAreaTest.xml,xunitxml
12− -o -,txt)
13−
14−add_custom_target(testDirectionalDragArea ${testCommand})
15−add_dependencies(qmluitests testDirectionalDragArea)
16−add_dependencies(testDirectionalDragArea DirectionalDragAreaTestExec UbutunGesturesTestQmlFiles)
17−
18−add_executable(DirectionalDragAreaTestExec tst_DirectionalDragArea.cpp)
19−qt5_use_modules(DirectionalDragAreaTestExec Test Core Qml Gui Quick)
20−target_link_libraries(DirectionalDragAreaTestExec UbuntuGestureQml)
21−
22−add_definitions(-DUBUNTU_GESTURES_PLUGIN_DIR="${CMAKE_BINARY_DIR}/plugins")
23−
24file(GLOB qmlFiles *.qml)
8file(GLOB qmlFiles *.qml)
25add_custom_target(UbuntuGesturesTestQmlFiles ALL
9add_custom_target(UbuntuGesturesTestQmlFiles ALL
26 COMMAND cp ${qmlFiles} ${CMAKE_CURRENT_BINARY_DIR}
10 COMMAND cp ${qmlFiles} ${CMAKE_CURRENT_BINARY_DIR}
27 DEPENDS ${qmlFiles}
11 DEPENDS ${qmlFiles}
28)
12)
29
13
30−########## other tests
14+add_definitions(-DUBUNTU_GESTURES_PLUGIN_DIR="${CMAKE_BINARY_DIR}/plugins")
15+
16+macro(add_gesture_ui_test CLASSNAME)
17+ set(testCommand
18+ LD_LIBRARY_PATH=${CMAKE_BINARY_DIR}/plugins/Ubuntu/Gestures
19+ ${CMAKE_CURRENT_BINARY_DIR}/${CLASSNAME}TestExec
20+ -o ${CMAKE_BINARY_DIR}/${CLASSNAME}Test.xml,xunitxml
21+ -o -,txt)
22+
23+ add_custom_target(test${CLASSNAME} ${testCommand})
24+ add_dependencies(qmluitests test${CLASSNAME})
25+ add_dependencies(test${CLASSNAME} ${CLASSNAME}TestExec UbuntuGesturesTestQmlFiles)
26+
27+ add_executable(${CLASSNAME}TestExec tst_${CLASSNAME}.cpp GestureTest.cpp)
28+ qt5_use_modules(${CLASSNAME}TestExec Test Core Qml Gui Quick)
29+ target_link_libraries(${CLASSNAME}TestExec UbuntuGestureQml)
30+ add_manual_qml_test(. ${CLASSNAME} IMPORT_PATHS ${CMAKE_BINARY_DIR}/plugins)
31+endmacro(add_gesture_ui_test)
31
32
32macro(add_gesture_test CLASSNAME)
33macro(add_gesture_test CLASSNAME)
33 set(testCommand
34 set(testCommand
@@ -43,5 +44,6 @@ macro(add_gesture_test CLASSNAME)
43 target_link_libraries(${CLASSNAME}TestExec UbuntuGestureQml)
44 target_link_libraries(${CLASSNAME}TestExec UbuntuGestureQml)
44endmacro(add_gesture_test)
45endmacro(add_gesture_test)
45
46
47+add_gesture_ui_test(DirectionalDragArea)
46add_gesture_test(Damper)
48add_gesture_test(Damper)
47add_gesture_test(AxisVelocityCalculator)
49add_gesture_test(AxisVelocityCalculator)
tests/plugins/Ubuntu/Gestures/GestureTest.cppnew file+54
@@ -0,0 +1,54 @@
1+/*
2+ * Copyright (C) 2013 Canonical, Ltd.
3+ *
4+ * This program is free software; you can redistribute it and/or modify
5+ * it under the terms of the GNU General Public License as published by
6+ * the Free Software Foundation; version 3.
7+ *
8+ * This program is distributed in the hope that it will be useful,
9+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
10+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11+ * GNU General Public License for more details.
12+ *
13+ * You should have received a copy of the GNU General Public License
14+ * along with this program. If not, see <http://www.gnu.org/licenses/>.
15+ */
16+
17+#include "GestureTest.h"
18+
19+#include <qpa/qwindowsysteminterface.h>
20+#include <QQmlEngine>
21+#include <QQuickView>
22+#include <QtTest>
23+
24+GestureTest::GestureTest(const QString &qmlFilename)
25+ : QObject(), m_device(nullptr), m_view(nullptr), m_qmlFilename(qmlFilename)
26+{
27+}
28+
29+void GestureTest::initTestCase()
30+{
31+ if (!m_device) {
32+ m_device = new QTouchDevice;
33+ m_device->setType(QTouchDevice::TouchScreen);
34+ QWindowSystemInterface::registerTouchDevice(m_device);
35+ }
36+}
37+
38+void GestureTest::init()
39+{
40+ m_view = new QQuickView;
41+ m_view->setResizeMode(QQuickView::SizeViewToRootObject);
42+ m_view->engine()->addImportPath(QStringLiteral(UBUNTU_GESTURES_PLUGIN_DIR));
43+ m_view->setSource(QUrl::fromLocalFile(m_qmlFilename));
44+ m_view->show();
45+ QVERIFY(QTest::qWaitForWindowExposed(m_view));
46+ QVERIFY(m_view->rootObject() != 0);
47+ qApp->processEvents();
48+}
49+
50+void GestureTest::cleanup()
51+{
52+ delete m_view;
53+ m_view = nullptr;
54+}
tests/plugins/Ubuntu/Gestures/GestureTest.hnew file+46
@@ -0,0 +1,46 @@
1+/*
2+ * Copyright (C) 2013 Canonical, Ltd.
3+ *
4+ * This program is free software; you can redistribute it and/or modify
5+ * it under the terms of the GNU General Public License as published by
6+ * the Free Software Foundation; version 3.
7+ *
8+ * This program is distributed in the hope that it will be useful,
9+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
10+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11+ * GNU General Public License for more details.
12+ *
13+ * You should have received a copy of the GNU General Public License
14+ * along with this program. If not, see <http://www.gnu.org/licenses/>.
15+ */
16+
17+#ifndef GESTURETEST_H
18+#endif // GESTURETEST_H
19+
20+#include <QObject>
21+
22+class QQuickView;
23+class QTouchDevice;
24+
25+/*
26+ The common stuff among tests come here
27+ */
28+class GestureTest : public QObject
29+{
30+ Q_OBJECT
31+public:
32+ // \param qmlFilename name of the qml file to be loaded by the QQuickView
33+ GestureTest(const QString &qmlFilename);
34+
35+protected Q_SLOTS:
36+ void initTestCase(); // will be called before the first test function is executed
37+ virtual void init(); // called right before each and every test function is executed
38+ virtual void cleanup(); // called right after each and every test function is executed
39+
40+protected:
41+ QTouchDevice *m_device;
42+ QQuickView *m_view;
43+ QString m_qmlFilename;
44+};
45+
46+#define GESTURETEST_H
tests/plugins/Ubuntu/Gestures/tst_DirectionalDragArea.cpp+65−96
@@ -16,13 +16,14 @@
16
16
17#include <QtTest/QtTest>
17#include <QtTest/QtTest>
18#include <QtCore/QObject>
18#include <QtCore/QObject>
19−#include <qpa/qwindowsysteminterface.h>
20#include <QtQuick/QQuickView>
19#include <QtQuick/QQuickView>
21#include <QtQml/QQmlEngine>
20#include <QtQml/QQmlEngine>
22#include <QPointer>
21#include <QPointer>
23
22
24#include <DirectionalDragArea.h>
23#include <DirectionalDragArea.h>
25
24
25+#include "GestureTest.h"
26+
26using namespace UbuntuGestures;
27using namespace UbuntuGestures;
27
28
28class FakeTimer : public AbstractTimer
29class FakeTimer : public AbstractTimer
@@ -61,15 +62,12 @@ public:
61 qint64 m_msecsSinceReference;
62 qint64 m_msecsSinceReference;
62};
63};
63
64
64−class tst_DirectionalDragArea: public QObject
65+class tst_DirectionalDragArea: public GestureTest
65{
66{
66 Q_OBJECT
67 Q_OBJECT
67public:
68public:
68− tst_DirectionalDragArea() : device(0) { }
69+ tst_DirectionalDragArea();
69private Q_SLOTS:
70private Q_SLOTS:
70− void initTestCase(); // will be called before the first test function is executed
71− void cleanupTestCase(); // will be called after the last test function was executed.
72−
73 void init(); // called right before each and every test function is executed
71 void init(); // called right before each and every test function is executed
74 void cleanup(); // called right after each and every test function is executed
72 void cleanup(); // called right after each and every test function is executed
75
73
@@ -87,37 +85,19 @@ private Q_SLOTS:
87 void ignoreOldFinger();
85 void ignoreOldFinger();
88
86
89private:
87private:
90− QQuickView *createView();
91 void passTime(qint64 timeSpan);
88 void passTime(qint64 timeSpan);
92− QQuickView *view;
93− QTouchDevice *device;
94 FakeTimer *fakeTimer;
89 FakeTimer *fakeTimer;
95 QSharedPointer<FakeTimeSource> fakeTimeSource;
90 QSharedPointer<FakeTimeSource> fakeTimeSource;
96};
91};
97
92
98−void tst_DirectionalDragArea::initTestCase()
93+tst_DirectionalDragArea::tst_DirectionalDragArea()
99−{
94+ : GestureTest(QStringLiteral("tst_DirectionalDragArea.qml"))
100− if (!device) {
101− device = new QTouchDevice;
102− device->setType(QTouchDevice::TouchScreen);
103− QWindowSystemInterface::registerTouchDevice(device);
104− }
105−
106− view = 0;
107−}
108−
109−void tst_DirectionalDragArea::cleanupTestCase()
110{
95{
111}
96}
112
97
113void tst_DirectionalDragArea::init()
98void tst_DirectionalDragArea::init()
114{
99{
115− view = createView();
100+ GestureTest::init();
116− view->setSource(QUrl::fromLocalFile("edgeDragExample.qml"));
117− view->show();
118− QVERIFY(QTest::qWaitForWindowExposed(view));
119− QVERIFY(view->rootObject() != 0);
120− qApp->processEvents();
121
101
122 fakeTimeSource.reset(new FakeTimeSource);
102 fakeTimeSource.reset(new FakeTimeSource);
123 fakeTimer = new FakeTimer(fakeTimeSource);
103 fakeTimer = new FakeTimer(fakeTimeSource);
@@ -125,23 +105,12 @@ void tst_DirectionalDragArea::init()
125
105
126void tst_DirectionalDragArea::cleanup()
106void tst_DirectionalDragArea::cleanup()
127{
107{
128− delete view;
129− view = 0;
130−
131 delete fakeTimer;
108 delete fakeTimer;
132 fakeTimer = 0;
109 fakeTimer = 0;
133
110
134 fakeTimeSource.reset();
111 fakeTimeSource.reset();
135−}
136−
137−QQuickView *tst_DirectionalDragArea::createView()
138−{
139− QQuickView *window = new QQuickView(0);
140− window->setResizeMode(QQuickView::SizeRootObjectToView);
141− window->resize(600, 600);
142− window->engine()->addImportPath(QLatin1String(UBUNTU_GESTURES_PLUGIN_DIR));
143
112
144− return window;
113+ GestureTest::cleanup();
145}
114}
146
115
147void tst_DirectionalDragArea::passTime(qint64 timeSpan)
116void tst_DirectionalDragArea::passTime(qint64 timeSpan)
@@ -217,14 +186,14 @@ void tst_DirectionalDragArea::edgeDrag()
217 QFETCH(bool, expectGestureRecognition);
186 QFETCH(bool, expectGestureRecognition);
218
187
219 DirectionalDragArea *edgeDragArea =
188 DirectionalDragArea *edgeDragArea =
220− view->rootObject()->findChild<DirectionalDragArea*>(dragAreaObjectName);
189+ m_view->rootObject()->findChild<DirectionalDragArea*>(dragAreaObjectName);
221 QVERIFY(edgeDragArea != 0);
190 QVERIFY(edgeDragArea != 0);
222 edgeDragArea->setRecognitionTimer(fakeTimer);
191 edgeDragArea->setRecognitionTimer(fakeTimer);
223 edgeDragArea->setTimeSource(fakeTimeSource);
192 edgeDragArea->setTimeSource(fakeTimeSource);
224
193
225 QSignalSpy draggingSpy(edgeDragArea, SIGNAL(draggingChanged(bool)));
194 QSignalSpy draggingSpy(edgeDragArea, SIGNAL(draggingChanged(bool)));
226
195
227− QPointF initialTouchPos = calculateInitialTouchPos(edgeDragArea, view);
196+ QPointF initialTouchPos = calculateInitialTouchPos(edgeDragArea, m_view);
228 QPointF touchPoint = initialTouchPos;
197 QPointF touchPoint = initialTouchPos;
229
198
230 qreal desiredDragDistance = edgeDragArea->distanceThreshold()*dragDistanceFactor;
199 qreal desiredDragDistance = edgeDragArea->distanceThreshold()*dragDistanceFactor;
@@ -235,7 +204,7 @@ void tst_DirectionalDragArea::edgeDrag()
235 int totalMovementSteps = qCeil(desiredDragDistance / movementStepDistance);
204 int totalMovementSteps = qCeil(desiredDragDistance / movementStepDistance);
236 int movementTimeStepMs = (edgeDragArea->compositionTime() * 1.5f) / totalMovementSteps;
205 int movementTimeStepMs = (edgeDragArea->compositionTime() * 1.5f) / totalMovementSteps;
237
206
238− QTest::touchEvent(view, device).press(0, touchPoint.toPoint());
207+ QTest::touchEvent(m_view, m_device).press(0, touchPoint.toPoint());
239
208
240 QCOMPARE(draggingSpy.count(), 1);
209 QCOMPARE(draggingSpy.count(), 1);
241 QCOMPARE(edgeDragArea->dragging(), true);
210 QCOMPARE(edgeDragArea->dragging(), true);
@@ -245,13 +214,13 @@ void tst_DirectionalDragArea::edgeDrag()
245 // in order to make it easier to leave it by dragging at an angle
214 // in order to make it easier to leave it by dragging at an angle
246 // slightly bigger than the widening angle
215 // slightly bigger than the widening angle
247 touchPoint += createTouchDeviation(edgeDragArea);
216 touchPoint += createTouchDeviation(edgeDragArea);
248− QTest::touchEvent(view, device).move(0, touchPoint.toPoint());
217+ QTest::touchEvent(m_view, m_device).move(0, touchPoint.toPoint());
249 }
218 }
250
219
251 for (int i = 0; i < totalMovementSteps; ++i) {
220 for (int i = 0; i < totalMovementSteps; ++i) {
252 touchPoint += touchMovement;
221 touchPoint += touchMovement;
253 passTime(movementTimeStepMs);
222 passTime(movementTimeStepMs);
254− QTest::touchEvent(view, device).move(0, touchPoint.toPoint());
223+ QTest::touchEvent(m_view, m_device).move(0, touchPoint.toPoint());
255 }
224 }
256
225
257 if (expectGestureRecognition)
226 if (expectGestureRecognition)
@@ -262,7 +231,7 @@ void tst_DirectionalDragArea::edgeDrag()
262 QCOMPARE(draggingSpy.count(), 2);
231 QCOMPARE(draggingSpy.count(), 2);
263 }
232 }
264
233
265− QTest::touchEvent(view, device).release(0, touchPoint.toPoint());
234+ QTest::touchEvent(m_view, m_device).release(0, touchPoint.toPoint());
266
235
267 QCOMPARE(draggingSpy.count(), 2);
236 QCOMPARE(draggingSpy.count(), 2);
268 QCOMPARE(edgeDragArea->dragging(), false);
237 QCOMPARE(edgeDragArea->dragging(), false);
@@ -326,12 +295,12 @@ void tst_DirectionalDragArea::edgeDrag_data()
326void tst_DirectionalDragArea::dragWithShortDirectionChange()
295void tst_DirectionalDragArea::dragWithShortDirectionChange()
327{
296{
328 DirectionalDragArea *edgeDragArea =
297 DirectionalDragArea *edgeDragArea =
329− view->rootObject()->findChild<DirectionalDragArea*>("hpDragArea");
298+ m_view->rootObject()->findChild<DirectionalDragArea*>("hpDragArea");
330 QVERIFY(edgeDragArea != 0);
299 QVERIFY(edgeDragArea != 0);
331 edgeDragArea->setRecognitionTimer(fakeTimer);
300 edgeDragArea->setRecognitionTimer(fakeTimer);
332 edgeDragArea->setTimeSource(fakeTimeSource);
301 edgeDragArea->setTimeSource(fakeTimeSource);
333
302
334− QPointF initialTouchPos = calculateInitialTouchPos(edgeDragArea, view);
303+ QPointF initialTouchPos = calculateInitialTouchPos(edgeDragArea, m_view);
335 QPointF touchPoint = initialTouchPos;
304 QPointF touchPoint = initialTouchPos;
336
305
337 qreal desiredDragDistance = edgeDragArea->distanceThreshold()*2.0;
306 qreal desiredDragDistance = edgeDragArea->distanceThreshold()*2.0;
@@ -341,32 +310,32 @@ void tst_DirectionalDragArea::dragWithShortDirectionChange()
341 int touchStepTimeMs = (touchStepDistance / (edgeDragArea->minSpeed() * 5.0f)) * 1000.0f;
310 int touchStepTimeMs = (touchStepDistance / (edgeDragArea->minSpeed() * 5.0f)) * 1000.0f;
342 QPointF touchMovement = dragDirectionVector * touchStepDistance;
311 QPointF touchMovement = dragDirectionVector * touchStepDistance;
343
312
344− QTest::touchEvent(view, device).press(0, touchPoint.toPoint());
313+ QTest::touchEvent(m_view, m_device).press(0, touchPoint.toPoint());
345
314
346 // Move a bit in the proper direction
315 // Move a bit in the proper direction
347 for (int i=0; i < 3; ++i) {
316 for (int i=0; i < 3; ++i) {
348 touchPoint += touchMovement;
317 touchPoint += touchMovement;
349 passTime(touchStepTimeMs);
318 passTime(touchStepTimeMs);
350− QTest::touchEvent(view, device).move(0, touchPoint.toPoint());
319+ QTest::touchEvent(m_view, m_device).move(0, touchPoint.toPoint());
351 }
320 }
352
321
353 // Then a sudden and small movement to the opposite direction
322 // Then a sudden and small movement to the opposite direction
354 touchPoint -= touchMovement*0.2;
323 touchPoint -= touchMovement*0.2;
355 passTime(touchStepTimeMs*0.2);
324 passTime(touchStepTimeMs*0.2);
356− QTest::touchEvent(view, device).move(0, touchPoint.toPoint());
325+ QTest::touchEvent(m_view, m_device).move(0, touchPoint.toPoint());
357
326
358 // And then resume movment in the correct direction until it crosses the distance and time
327 // And then resume movment in the correct direction until it crosses the distance and time
359 // thresholds.
328 // thresholds.
360 do {
329 do {
361 touchPoint += touchMovement;
330 touchPoint += touchMovement;
362 passTime(touchStepTimeMs);
331 passTime(touchStepTimeMs);
363− QTest::touchEvent(view, device).move(0, touchPoint.toPoint());
332+ QTest::touchEvent(m_view, m_device).move(0, touchPoint.toPoint());
364 } while ((touchPoint - initialTouchPos).manhattanLength() < desiredDragDistance
333 } while ((touchPoint - initialTouchPos).manhattanLength() < desiredDragDistance
365 || fakeTimeSource->m_msecsSinceReference < (edgeDragArea->compositionTime() * 1.5f));
334 || fakeTimeSource->m_msecsSinceReference < (edgeDragArea->compositionTime() * 1.5f));
366
335
367 QCOMPARE((int)edgeDragArea->status(), (int)DirectionalDragArea::Recognized);
336 QCOMPARE((int)edgeDragArea->status(), (int)DirectionalDragArea::Recognized);
368
337
369− QTest::touchEvent(view, device).release(0, touchPoint.toPoint());
338+ QTest::touchEvent(m_view, m_device).release(0, touchPoint.toPoint());
370}
339}
371
340
372/*
341/*
@@ -380,7 +349,7 @@ void tst_DirectionalDragArea::minSpeed()
380 QFETCH(int, expectedStatusAfterSpeedCheck);
349 QFETCH(int, expectedStatusAfterSpeedCheck);
381
350
382 DirectionalDragArea *edgeDragArea =
351 DirectionalDragArea *edgeDragArea =
383− view->rootObject()->findChild<DirectionalDragArea*>("hpDragArea");
352+ m_view->rootObject()->findChild<DirectionalDragArea*>("hpDragArea");
384 QVERIFY(edgeDragArea != 0);
353 QVERIFY(edgeDragArea != 0);
385 edgeDragArea->setRecognitionTimer(fakeTimer);
354 edgeDragArea->setRecognitionTimer(fakeTimer);
386 edgeDragArea->setTimeSource(fakeTimeSource);
355 edgeDragArea->setTimeSource(fakeTimeSource);
@@ -391,7 +360,7 @@ void tst_DirectionalDragArea::minSpeed()
391
360
392 edgeDragArea->setMinSpeed(minSpeed);
361 edgeDragArea->setMinSpeed(minSpeed);
393
362
394− QPointF initialTouchPos = calculateInitialTouchPos(edgeDragArea, view);
363+ QPointF initialTouchPos = calculateInitialTouchPos(edgeDragArea, m_view);
395 QPointF touchPoint = initialTouchPos;
364 QPointF touchPoint = initialTouchPos;
396
365
397 QPointF dragDirectionVector(1.0, 0.0);
366 QPointF dragDirectionVector(1.0, 0.0);
@@ -399,13 +368,13 @@ void tst_DirectionalDragArea::minSpeed()
399 qreal distanceStep = (speed / 1000.0f) * timeStepMsecs;
368 qreal distanceStep = (speed / 1000.0f) * timeStepMsecs;
400 QPointF touchMovement = dragDirectionVector * distanceStep;
369 QPointF touchMovement = dragDirectionVector * distanceStep;
401
370
402− QTest::touchEvent(view, device).press(0, touchPoint.toPoint());
371+ QTest::touchEvent(m_view, m_device).press(0, touchPoint.toPoint());
403
372
404 // Move for a while to ensure our speed check is performed a couple of times
373 // Move for a while to ensure our speed check is performed a couple of times
405 for (int i=0; i < 20; ++i) {
374 for (int i=0; i < 20; ++i) {
406 touchPoint += touchMovement;
375 touchPoint += touchMovement;
407 passTime(timeStepMsecs);
376 passTime(timeStepMsecs);
408− QTest::touchEvent(view, device).move(0, touchPoint.toPoint());
377+ QTest::touchEvent(m_view, m_device).move(0, touchPoint.toPoint());
409 }
378 }
410
379
411 QCOMPARE((int)edgeDragArea->status(), expectedStatusAfterSpeedCheck);
380 QCOMPARE((int)edgeDragArea->status(), expectedStatusAfterSpeedCheck);
@@ -429,7 +398,7 @@ void tst_DirectionalDragArea::minSpeed_data()
429void tst_DirectionalDragArea::recognitionTimerUsage()
398void tst_DirectionalDragArea::recognitionTimerUsage()
430{
399{
431 DirectionalDragArea *edgeDragArea =
400 DirectionalDragArea *edgeDragArea =
432− view->rootObject()->findChild<DirectionalDragArea*>("hpDragArea");
401+ m_view->rootObject()->findChild<DirectionalDragArea*>("hpDragArea");
433 QVERIFY(edgeDragArea != 0);
402 QVERIFY(edgeDragArea != 0);
434 edgeDragArea->setRecognitionTimer(fakeTimer);
403 edgeDragArea->setRecognitionTimer(fakeTimer);
435 edgeDragArea->setTimeSource(fakeTimeSource);
404 edgeDragArea->setTimeSource(fakeTimeSource);
@@ -439,7 +408,7 @@ void tst_DirectionalDragArea::recognitionTimerUsage()
439
408
440 int timeStepMs = 5; // some arbitrary small value.
409 int timeStepMs = 5; // some arbitrary small value.
441
410
442− QPointF initialTouchPos = calculateInitialTouchPos(edgeDragArea, view);
411+ QPointF initialTouchPos = calculateInitialTouchPos(edgeDragArea, m_view);
443 QPointF touchPoint = initialTouchPos;
412 QPointF touchPoint = initialTouchPos;
444
413
445 QPointF dragDirectionVector(1.0, 0.0);
414 QPointF dragDirectionVector(1.0, 0.0);
@@ -448,7 +417,7 @@ void tst_DirectionalDragArea::recognitionTimerUsage()
448 QCOMPARE((int)edgeDragArea->status(), (int)DirectionalDragArea::WaitingForTouch);
417 QCOMPARE((int)edgeDragArea->status(), (int)DirectionalDragArea::WaitingForTouch);
449 QVERIFY(!fakeTimer->isRunning());
418 QVERIFY(!fakeTimer->isRunning());
450
419
451− QTest::touchEvent(view, device).press(0, touchPoint.toPoint());
420+ QTest::touchEvent(m_view, m_device).press(0, touchPoint.toPoint());
452
421
453 QCOMPARE((int)edgeDragArea->status(), (int)DirectionalDragArea::Undecided);
422 QCOMPARE((int)edgeDragArea->status(), (int)DirectionalDragArea::Undecided);
454 QVERIFY(fakeTimer->isRunning());
423 QVERIFY(fakeTimer->isRunning());
@@ -461,7 +430,7 @@ void tst_DirectionalDragArea::recognitionTimerUsage()
461
430
462 touchPoint += touchMovement;
431 touchPoint += touchMovement;
463 passTime(timeStepMs);
432 passTime(timeStepMs);
464− QTest::touchEvent(view, device).move(0, touchPoint.toPoint());
433+ QTest::touchEvent(m_view, m_device).move(0, touchPoint.toPoint());
465 }
434 }
466
435
467 QCOMPARE((int)edgeDragArea->status(), (int)DirectionalDragArea::Recognized);
436 QCOMPARE((int)edgeDragArea->status(), (int)DirectionalDragArea::Recognized);
@@ -475,7 +444,7 @@ void tst_DirectionalDragArea::recognitionTimerUsage()
475void tst_DirectionalDragArea::maxSilenceTime()
444void tst_DirectionalDragArea::maxSilenceTime()
476{
445{
477 DirectionalDragArea *edgeDragArea =
446 DirectionalDragArea *edgeDragArea =
478− view->rootObject()->findChild<DirectionalDragArea*>("hpDragArea");
447+ m_view->rootObject()->findChild<DirectionalDragArea*>("hpDragArea");
479 QVERIFY(edgeDragArea != 0);
448 QVERIFY(edgeDragArea != 0);
480 edgeDragArea->setRecognitionTimer(fakeTimer);
449 edgeDragArea->setRecognitionTimer(fakeTimer);
481 edgeDragArea->setTimeSource(fakeTimeSource);
450 edgeDragArea->setTimeSource(fakeTimeSource);
@@ -483,10 +452,10 @@ void tst_DirectionalDragArea::maxSilenceTime()
483 // Make sure this property is not disabled
452 // Make sure this property is not disabled
484 edgeDragArea->setMaxSilenceTime(100);
453 edgeDragArea->setMaxSilenceTime(100);
485
454
486− QPointF initialTouchPos = calculateInitialTouchPos(edgeDragArea, view);
455+ QPointF initialTouchPos = calculateInitialTouchPos(edgeDragArea, m_view);
487 QPointF touchPoint = initialTouchPos;
456 QPointF touchPoint = initialTouchPos;
488
457
489− QTest::touchEvent(view, device).press(0, touchPoint.toPoint());
458+ QTest::touchEvent(m_view, m_device).press(0, touchPoint.toPoint());
490
459
491 QCOMPARE((int)edgeDragArea->status(), (int)DirectionalDragArea::Undecided);
460 QCOMPARE((int)edgeDragArea->status(), (int)DirectionalDragArea::Undecided);
492 QVERIFY(fakeTimer->isRunning());
461 QVERIFY(fakeTimer->isRunning());
@@ -506,20 +475,20 @@ void tst_DirectionalDragArea::maxSilenceTime()
506void tst_DirectionalDragArea::sceneXAndX()
475void tst_DirectionalDragArea::sceneXAndX()
507{
476{
508 DirectionalDragArea *edgeDragArea =
477 DirectionalDragArea *edgeDragArea =
509− view->rootObject()->findChild<DirectionalDragArea*>("hnDragArea");
478+ m_view->rootObject()->findChild<DirectionalDragArea*>("hnDragArea");
510 QVERIFY(edgeDragArea != 0);
479 QVERIFY(edgeDragArea != 0);
511 edgeDragArea->setRecognitionTimer(fakeTimer);
480 edgeDragArea->setRecognitionTimer(fakeTimer);
512 edgeDragArea->setTimeSource(fakeTimeSource);
481 edgeDragArea->setTimeSource(fakeTimeSource);
513
482
514− QPointF touchScenePos(view->width() - (edgeDragArea->width()/2.0f), view->height()/2.0f);
483+ QPointF touchScenePos(m_view->width() - (edgeDragArea->width()/2.0f), m_view->height()/2.0f);
515
484
516− QTest::touchEvent(view, device).press(0, touchScenePos.toPoint());
485+ QTest::touchEvent(m_view, m_device).press(0, touchScenePos.toPoint());
517
486
518 QSignalSpy touchXSpy(edgeDragArea, SIGNAL(touchXChanged(qreal)));
487 QSignalSpy touchXSpy(edgeDragArea, SIGNAL(touchXChanged(qreal)));
519 QSignalSpy touchSceneXSpy(edgeDragArea, SIGNAL(touchSceneXChanged(qreal)));
488 QSignalSpy touchSceneXSpy(edgeDragArea, SIGNAL(touchSceneXChanged(qreal)));
520
489
521− touchScenePos.rx() = view->width() / 2;
490+ touchScenePos.rx() = m_view->width() / 2;
522− QTest::touchEvent(view, device).move(0, touchScenePos.toPoint());
491+ QTest::touchEvent(m_view, m_device).move(0, touchScenePos.toPoint());
523
492
524 QCOMPARE(touchXSpy.count(), 1);
493 QCOMPARE(touchXSpy.count(), 1);
525 QCOMPARE(touchSceneXSpy.count(), 1);
494 QCOMPARE(touchSceneXSpy.count(), 1);
@@ -534,20 +503,20 @@ void tst_DirectionalDragArea::sceneXAndX()
534void tst_DirectionalDragArea::sceneYAndY()
503void tst_DirectionalDragArea::sceneYAndY()
535{
504{
536 DirectionalDragArea *edgeDragArea =
505 DirectionalDragArea *edgeDragArea =
537− view->rootObject()->findChild<DirectionalDragArea*>("vnDragArea");
506+ m_view->rootObject()->findChild<DirectionalDragArea*>("vnDragArea");
538 QVERIFY(edgeDragArea != 0);
507 QVERIFY(edgeDragArea != 0);
539 edgeDragArea->setRecognitionTimer(fakeTimer);
508 edgeDragArea->setRecognitionTimer(fakeTimer);
540 edgeDragArea->setTimeSource(fakeTimeSource);
509 edgeDragArea->setTimeSource(fakeTimeSource);
541
510
542− QPointF touchScenePos(view->width()/2.0f, view->height() - (edgeDragArea->height()/2.0f));
511+ QPointF touchScenePos(m_view->width()/2.0f, m_view->height() - (edgeDragArea->height()/2.0f));
543
512
544− QTest::touchEvent(view, device).press(0, touchScenePos.toPoint());
513+ QTest::touchEvent(m_view, m_device).press(0, touchScenePos.toPoint());
545
514
546 QSignalSpy touchYSpy(edgeDragArea, SIGNAL(touchYChanged(qreal)));
515 QSignalSpy touchYSpy(edgeDragArea, SIGNAL(touchYChanged(qreal)));
547 QSignalSpy touchSceneYSpy(edgeDragArea, SIGNAL(touchSceneYChanged(qreal)));
516 QSignalSpy touchSceneYSpy(edgeDragArea, SIGNAL(touchSceneYChanged(qreal)));
548
517
549− touchScenePos.ry() = view->height() / 2;
518+ touchScenePos.ry() = m_view->height() / 2;
550− QTest::touchEvent(view, device).move(0, touchScenePos.toPoint());
519+ QTest::touchEvent(m_view, m_device).move(0, touchScenePos.toPoint());
551
520
552 QCOMPARE(touchYSpy.count(), 1);
521 QCOMPARE(touchYSpy.count(), 1);
553 QCOMPARE(touchSceneYSpy.count(), 1);
522 QCOMPARE(touchSceneYSpy.count(), 1);
@@ -564,27 +533,27 @@ void tst_DirectionalDragArea::sceneYAndY()
564void tst_DirectionalDragArea::twoFingerTap()
533void tst_DirectionalDragArea::twoFingerTap()
565{
534{
566 DirectionalDragArea *edgeDragArea =
535 DirectionalDragArea *edgeDragArea =
567− view->rootObject()->findChild<DirectionalDragArea*>("hpDragArea");
536+ m_view->rootObject()->findChild<DirectionalDragArea*>("hpDragArea");
568 QVERIFY(edgeDragArea != 0);
537 QVERIFY(edgeDragArea != 0);
569 edgeDragArea->setRecognitionTimer(fakeTimer);
538 edgeDragArea->setRecognitionTimer(fakeTimer);
570 edgeDragArea->setTimeSource(fakeTimeSource);
539 edgeDragArea->setTimeSource(fakeTimeSource);
571
540
572 // Make touches evenly spaced along the edgeDragArea
541 // Make touches evenly spaced along the edgeDragArea
573− QPoint touchAPos(edgeDragArea->width()/2.0f, view->height()*0.33f);
542+ QPoint touchAPos(edgeDragArea->width()/2.0f, m_view->height()*0.33f);
574− QPoint touchBPos(edgeDragArea->width()/2.0f, view->height()*0.66f);
543+ QPoint touchBPos(edgeDragArea->width()/2.0f, m_view->height()*0.66f);
575
544
576 qint64 timeStepMsecs = 5; // some arbitrary, small value
545 qint64 timeStepMsecs = 5; // some arbitrary, small value
577
546
578 // Perform the first two-finger tap
547 // Perform the first two-finger tap
579 // NB: using move() instead of stationary() becasue in the latter you cannot provide
548 // NB: using move() instead of stationary() becasue in the latter you cannot provide
580 // the touch position and therefore it's left with some garbage numbers.
549 // the touch position and therefore it's left with some garbage numbers.
581− QTest::touchEvent(view, device)
550+ QTest::touchEvent(m_view, m_device)
582 .press(0, touchAPos);
551 .press(0, touchAPos);
583
552
584 QCOMPARE((int)edgeDragArea->status(), (int)DirectionalDragArea::Undecided);
553 QCOMPARE((int)edgeDragArea->status(), (int)DirectionalDragArea::Undecided);
585
554
586 passTime(timeStepMsecs);
555 passTime(timeStepMsecs);
587− QTest::touchEvent(view, device)
556+ QTest::touchEvent(m_view, m_device)
588 .move(0, touchAPos)
557 .move(0, touchAPos)
589 .press(1, touchBPos);
558 .press(1, touchBPos);
590
559
@@ -593,14 +562,14 @@ void tst_DirectionalDragArea::twoFingerTap()
593 QCOMPARE((int)edgeDragArea->status(), (int)DirectionalDragArea::WaitingForTouch);
562 QCOMPARE((int)edgeDragArea->status(), (int)DirectionalDragArea::WaitingForTouch);
594
563
595 passTime(timeStepMsecs);
564 passTime(timeStepMsecs);
596− QTest::touchEvent(view, device)
565+ QTest::touchEvent(m_view, m_device)
597 .release(0, touchAPos)
566 .release(0, touchAPos)
598 .move(1, touchBPos);
567 .move(1, touchBPos);
599
568
600 QCOMPARE((int)edgeDragArea->status(), (int)DirectionalDragArea::WaitingForTouch);
569 QCOMPARE((int)edgeDragArea->status(), (int)DirectionalDragArea::WaitingForTouch);
601
570
602 passTime(timeStepMsecs);
571 passTime(timeStepMsecs);
603− QTest::touchEvent(view, device)
572+ QTest::touchEvent(m_view, m_device)
604 .release(1, touchBPos);
573 .release(1, touchBPos);
605
574
606 QCOMPARE((int)edgeDragArea->status(), (int)DirectionalDragArea::WaitingForTouch);
575 QCOMPARE((int)edgeDragArea->status(), (int)DirectionalDragArea::WaitingForTouch);
@@ -608,27 +577,27 @@ void tst_DirectionalDragArea::twoFingerTap()
608 // Perform the second two-finger tap
577 // Perform the second two-finger tap
609
578
610 passTime(timeStepMsecs);
579 passTime(timeStepMsecs);
611− QTest::touchEvent(view, device)
580+ QTest::touchEvent(m_view, m_device)
612 .press(0, touchAPos);
581 .press(0, touchAPos);
613
582
614 QCOMPARE((int)edgeDragArea->status(), (int)DirectionalDragArea::Undecided);
583 QCOMPARE((int)edgeDragArea->status(), (int)DirectionalDragArea::Undecided);
615
584
616 passTime(timeStepMsecs);
585 passTime(timeStepMsecs);
617− QTest::touchEvent(view, device)
586+ QTest::touchEvent(m_view, m_device)
618 .move(0, touchAPos)
587 .move(0, touchAPos)
619 .press(1, touchBPos);
588 .press(1, touchBPos);
620
589
621 QCOMPARE((int)edgeDragArea->status(), (int)DirectionalDragArea::WaitingForTouch);
590 QCOMPARE((int)edgeDragArea->status(), (int)DirectionalDragArea::WaitingForTouch);
622
591
623 passTime(timeStepMsecs);
592 passTime(timeStepMsecs);
624− QTest::touchEvent(view, device)
593+ QTest::touchEvent(m_view, m_device)
625 .release(0, touchAPos)
594 .release(0, touchAPos)
626 .move(1, touchBPos);
595 .move(1, touchBPos);
627
596
628 QCOMPARE((int)edgeDragArea->status(), (int)DirectionalDragArea::WaitingForTouch);
597 QCOMPARE((int)edgeDragArea->status(), (int)DirectionalDragArea::WaitingForTouch);
629
598
630 passTime(timeStepMsecs);
599 passTime(timeStepMsecs);
631− QTest::touchEvent(view, device)
600+ QTest::touchEvent(m_view, m_device)
632 .release(1, touchBPos);
601 .release(1, touchBPos);
633
602
634 QCOMPARE((int)edgeDragArea->status(), (int)DirectionalDragArea::WaitingForTouch);
603 QCOMPARE((int)edgeDragArea->status(), (int)DirectionalDragArea::WaitingForTouch);
@@ -642,7 +611,7 @@ void tst_DirectionalDragArea::twoFingerTap()
642 */
611 */
643void tst_DirectionalDragArea::movingDDA()
612void tst_DirectionalDragArea::movingDDA()
644{
613{
645− QQuickItem *rightwardsLauncher = view->rootObject()->findChild<QQuickItem*>("rightwardsLauncher");
614+ QQuickItem *rightwardsLauncher = m_view->rootObject()->findChild<QQuickItem*>("rightwardsLauncher");
646 Q_ASSERT(rightwardsLauncher != 0);
615 Q_ASSERT(rightwardsLauncher != 0);
647
616
648 DirectionalDragArea *edgeDragArea =
617 DirectionalDragArea *edgeDragArea =
@@ -651,7 +620,7 @@ void tst_DirectionalDragArea::movingDDA()
651 edgeDragArea->setRecognitionTimer(fakeTimer);
620 edgeDragArea->setRecognitionTimer(fakeTimer);
652 edgeDragArea->setTimeSource(fakeTimeSource);
621 edgeDragArea->setTimeSource(fakeTimeSource);
653
622
654− QPointF initialTouchPos = calculateInitialTouchPos(edgeDragArea, view);
623+ QPointF initialTouchPos = calculateInitialTouchPos(edgeDragArea, m_view);
655 QPointF touchPoint = initialTouchPos;
624 QPointF touchPoint = initialTouchPos;
656
625
657 qreal desiredDragDistance = edgeDragArea->distanceThreshold()*2.0f;
626 qreal desiredDragDistance = edgeDragArea->distanceThreshold()*2.0f;
@@ -662,7 +631,7 @@ void tst_DirectionalDragArea::movingDDA()
662 int totalMovementSteps = qCeil(desiredDragDistance / movementStepDistance);
631 int totalMovementSteps = qCeil(desiredDragDistance / movementStepDistance);
663 int movementTimeStepMs = (edgeDragArea->compositionTime() * 1.5f) / totalMovementSteps;
632 int movementTimeStepMs = (edgeDragArea->compositionTime() * 1.5f) / totalMovementSteps;
664
633
665− QTest::touchEvent(view, device).press(0, touchPoint.toPoint());
634+ QTest::touchEvent(m_view, m_device).press(0, touchPoint.toPoint());
666
635
667 // Move it far ahead along the direction of the gesture
636 // Move it far ahead along the direction of the gesture
668 // rightwardsLauncher is a parent of our DirectionalDragArea. So moving it will move our DDA
637 // rightwardsLauncher is a parent of our DirectionalDragArea. So moving it will move our DDA
@@ -671,12 +640,12 @@ void tst_DirectionalDragArea::movingDDA()
671 for (int i = 0; i < totalMovementSteps; ++i) {
640 for (int i = 0; i < totalMovementSteps; ++i) {
672 touchPoint += touchMovement;
641 touchPoint += touchMovement;
673 passTime(movementTimeStepMs);
642 passTime(movementTimeStepMs);
674− QTest::touchEvent(view, device).move(0, touchPoint.toPoint());
643+ QTest::touchEvent(m_view, m_device).move(0, touchPoint.toPoint());
675 }
644 }
676
645
677 QCOMPARE((int)edgeDragArea->status(), (int)DirectionalDragArea::Recognized);
646 QCOMPARE((int)edgeDragArea->status(), (int)DirectionalDragArea::Recognized);
678
647
679− QTest::touchEvent(view, device).release(0, touchPoint.toPoint());
648+ QTest::touchEvent(m_view, m_device).release(0, touchPoint.toPoint());
680}
649}
681
650
682/*
651/*
@@ -686,16 +655,16 @@ void tst_DirectionalDragArea::movingDDA()
686void tst_DirectionalDragArea::ignoreOldFinger()
655void tst_DirectionalDragArea::ignoreOldFinger()
687{
656{
688 DirectionalDragArea *edgeDragArea =
657 DirectionalDragArea *edgeDragArea =
689− view->rootObject()->findChild<DirectionalDragArea*>("hpDragArea");
658+ m_view->rootObject()->findChild<DirectionalDragArea*>("hpDragArea");
690 Q_ASSERT(edgeDragArea != 0);
659 Q_ASSERT(edgeDragArea != 0);
691 edgeDragArea->setRecognitionTimer(fakeTimer);
660 edgeDragArea->setRecognitionTimer(fakeTimer);
692 edgeDragArea->setTimeSource(fakeTimeSource);
661 edgeDragArea->setTimeSource(fakeTimeSource);
693
662
694 // Make touches evenly spaced along the edgeDragArea
663 // Make touches evenly spaced along the edgeDragArea
695− QPoint touch0Pos(edgeDragArea->width()/2.0f, view->height()*0.33f);
664+ QPoint touch0Pos(edgeDragArea->width()/2.0f, m_view->height()*0.33f);
696− QPoint touch1Pos(edgeDragArea->width()/2.0f, view->height()*0.66f);
665+ QPoint touch1Pos(edgeDragArea->width()/2.0f, m_view->height()*0.66f);
697
666
698− QTest::touchEvent(view, device).press(0, touch0Pos);
667+ QTest::touchEvent(m_view, m_device).press(0, touch0Pos);
699
668
700 QCOMPARE((int)edgeDragArea->status(), (int)DirectionalDragArea::Undecided);
669 QCOMPARE((int)edgeDragArea->status(), (int)DirectionalDragArea::Undecided);
701
670
@@ -712,7 +681,7 @@ void tst_DirectionalDragArea::ignoreOldFinger()
712 int totalMovementSteps = qCeil(desiredDragDistance / movementStepDistance);
681 int totalMovementSteps = qCeil(desiredDragDistance / movementStepDistance);
713 int movementTimeStepMs = (edgeDragArea->compositionTime() * 1.5f) / totalMovementSteps;
682 int movementTimeStepMs = (edgeDragArea->compositionTime() * 1.5f) / totalMovementSteps;
714
683
715− QTest::touchEvent(view, device)
684+ QTest::touchEvent(m_view, m_device)
716 .move(0, touch0Pos)
685 .move(0, touch0Pos)
717 .press(1, touch1Pos);
686 .press(1, touch1Pos);
718
687
@@ -721,14 +690,14 @@ void tst_DirectionalDragArea::ignoreOldFinger()
721 for (int i = 0; i < totalMovementSteps; ++i) {
690 for (int i = 0; i < totalMovementSteps; ++i) {
722 touch1Pos += touchMovement.toPoint();
691 touch1Pos += touchMovement.toPoint();
723 passTime(movementTimeStepMs);
692 passTime(movementTimeStepMs);
724− QTest::touchEvent(view, device)
693+ QTest::touchEvent(m_view, m_device)
725 .move(0, touch0Pos)
694 .move(0, touch0Pos)
726 .move(1, touch1Pos);
695 .move(1, touch1Pos);
727 }
696 }
728
697
729 QCOMPARE((int)edgeDragArea->status(), (int)DirectionalDragArea::Recognized);
698 QCOMPARE((int)edgeDragArea->status(), (int)DirectionalDragArea::Recognized);
730
699
731− QTest::touchEvent(view, device)
700+ QTest::touchEvent(m_view, m_device)
732 .move(0, touch0Pos)
701 .move(0, touch0Pos)
733 .release(1, touch1Pos);
702 .release(1, touch1Pos);
734
703
tests/plugins/Ubuntu/Gestures/edgeDragExample.qml → tests/plugins/Ubuntu/Gestures/tst_DirectionalDragArea.qmlrenamed+2−2
@@ -18,8 +18,8 @@ import QtQuick 2.0
18import Ubuntu.Components 0.1
18import Ubuntu.Components 0.1
19
19
20Rectangle {
20Rectangle {
21− //width: units.gu(40)
21+ width: units.gu(40)
22− //height: units.gu(71)
22+ height: units.gu(71)
23 color: "white"
23 color: "white"
24
24
25 MouseArea {
25 MouseArea {