13#include <QtWidgets/qaction.h>
25 void testSwipeMinFinger_data();
26 void testSwipeMinFinger();
27 void testPinchMinFinger_data();
28 void testPinchMinFinger();
30 void testSwipeMaxFinger_data();
31 void testSwipeMaxFinger();
32 void testPinchMaxFinger_data();
33 void testPinchMaxFinger();
35 void testSwipeDirection_data();
36 void testSwipeDirection();
37 void testPinchDirection_data();
38 void testPinchDirection();
41 void testMinimumX_data();
43 void testMinimumY_data();
45 void testMaximumX_data();
47 void testMaximumY_data();
49 void testStartGeometry();
52 void testSetMinimumDelta();
53 void testMinimumDeltaReached_data();
54 void testMinimumDeltaReached();
55 void testMinimumScaleDelta();
56 void testUnregisterSwipeCancels();
57 void testUnregisterPinchCancels();
58 void testDeleteSwipeCancels();
59 void testSwipeCancel_data();
60 void testSwipeCancel();
61 void testSwipeUpdateTrigger_data();
62 void testSwipeUpdateTrigger();
65 void testSwipeMinFingerStart_data();
66 void testSwipeMinFingerStart();
67 void testSwipeMaxFingerStart_data();
68 void testSwipeMaxFingerStart();
69 void testNotEmitCallbacksBeforeDirectionDecided();
72 void testSwipeGeometryStart_data();
73 void testSwipeGeometryStart();
76void GestureTest::testSwipeMinFinger_data()
78 QTest::addColumn<uint>(
"count");
79 QTest::addColumn<uint>(
"expectedCount");
81 QTest::newRow(
"0") << 0u << 0u;
82 QTest::newRow(
"1") << 1u << 1u;
83 QTest::newRow(
"10") << 10u << 10u;
86void GestureTest::testSwipeMinFinger()
100void GestureTest::testPinchMinFinger_data()
102 QTest::addColumn<uint>(
"count");
103 QTest::addColumn<uint>(
"expectedCount");
105 QTest::newRow(
"0") << 0u << 0u;
106 QTest::newRow(
"1") << 1u << 1u;
107 QTest::newRow(
"10") << 10u << 10u;
110void GestureTest::testPinchMinFinger()
124void GestureTest::testSwipeMaxFinger_data()
126 QTest::addColumn<uint>(
"count");
127 QTest::addColumn<uint>(
"expectedCount");
129 QTest::newRow(
"0") << 0u << 0u;
130 QTest::newRow(
"1") << 1u << 1u;
131 QTest::newRow(
"10") << 10u << 10u;
134void GestureTest::testSwipeMaxFinger()
148void GestureTest::testPinchMaxFinger_data()
150 QTest::addColumn<uint>(
"count");
151 QTest::addColumn<uint>(
"expectedCount");
153 QTest::newRow(
"0") << 0u << 0u;
154 QTest::newRow(
"1") << 1u << 1u;
155 QTest::newRow(
"10") << 10u << 10u;
158void GestureTest::testPinchMaxFinger()
172void GestureTest::testSwipeDirection_data()
174 QTest::addColumn<SwipeDirection>(
"swipe_direction");
176 QTest::newRow(
"Up") << SwipeDirection::Up;
177 QTest::newRow(
"Left") << SwipeDirection::Left;
178 QTest::newRow(
"Right") << SwipeDirection::Right;
179 QTest::newRow(
"Down") << SwipeDirection::Down;
182void GestureTest::testSwipeDirection()
185 QCOMPARE(gesture.
direction(), SwipeDirection::Down);
188 QCOMPARE(gesture.
direction(), swipe_direction);
191 QCOMPARE(gesture.
direction(), SwipeDirection::Down);
194void GestureTest::testPinchDirection_data()
196 QTest::addColumn<PinchDirection>(
"pinch_direction");
198 QTest::newRow(
"Contracting") << PinchDirection::Contracting;
199 QTest::newRow(
"Expanding") << PinchDirection::Expanding;
202void GestureTest::testPinchDirection()
205 QCOMPARE(gesture.
direction(), PinchDirection::Expanding);
208 QCOMPARE(gesture.
direction(), pinch_direction);
211 QCOMPARE(gesture.
direction(), PinchDirection::Expanding);
214void GestureTest::testMinimumX_data()
216 QTest::addColumn<int>(
"min");
218 QTest::newRow(
"0") << 0;
219 QTest::newRow(
"-1") << -1;
220 QTest::newRow(
"1") << 1;
223void GestureTest::testMinimumX()
234void GestureTest::testMinimumY_data()
236 QTest::addColumn<int>(
"min");
238 QTest::newRow(
"0") << 0;
239 QTest::newRow(
"-1") << -1;
240 QTest::newRow(
"1") << 1;
243void GestureTest::testMinimumY()
254void GestureTest::testMaximumX_data()
256 QTest::addColumn<int>(
"max");
258 QTest::newRow(
"0") << 0;
259 QTest::newRow(
"-1") << -1;
260 QTest::newRow(
"1") << 1;
263void GestureTest::testMaximumX()
274void GestureTest::testMaximumY_data()
276 QTest::addColumn<int>(
"max");
278 QTest::newRow(
"0") << 0;
279 QTest::newRow(
"-1") << -1;
280 QTest::newRow(
"1") << 1;
283void GestureTest::testMaximumY()
294void GestureTest::testStartGeometry()
308void GestureTest::testSetMinimumDelta()
331void GestureTest::testMinimumDeltaReached_data()
333 QTest::addColumn<SwipeDirection>(
"direction");
334 QTest::addColumn<QPointF>(
"minimumDelta");
335 QTest::addColumn<QPointF>(
"delta");
336 QTest::addColumn<bool>(
"reached");
337 QTest::addColumn<qreal>(
"progress");
339 QTest::newRow(
"Up (more)") << SwipeDirection::Up << QPointF(0, -30) << QPointF(0, -40) <<
true << 1.0;
340 QTest::newRow(
"Up (exact)") << SwipeDirection::Up << QPointF(0, -30) << QPointF(0, -30) <<
true << 1.0;
341 QTest::newRow(
"Up (less)") << SwipeDirection::Up << QPointF(0, -30) << QPointF(0, -29) <<
false << 29.0 / 30.0;
342 QTest::newRow(
"Left (more)") << SwipeDirection::Left << QPointF(-30, -30) << QPointF(-40, 20) <<
true << 1.0;
343 QTest::newRow(
"Left (exact)") << SwipeDirection::Left << QPointF(-30, -40) << QPointF(-30, 0) <<
true << 1.0;
344 QTest::newRow(
"Left (less)") << SwipeDirection::Left << QPointF(-30, -30) << QPointF(-29, 0) <<
false << 29.0 / 30.0;
345 QTest::newRow(
"Right (more)") << SwipeDirection::Right << QPointF(30, -30) << QPointF(40, 20) <<
true << 1.0;
346 QTest::newRow(
"Right (exact)") << SwipeDirection::Right << QPointF(30, -40) << QPointF(30, 0) <<
true << 1.0;
347 QTest::newRow(
"Right (less)") << SwipeDirection::Right << QPointF(30, -30) << QPointF(29, 0) <<
false << 29.0 / 30.0;
348 QTest::newRow(
"Down (more)") << SwipeDirection::Down << QPointF(0, 30) << QPointF(0, 40) <<
true << 1.0;
349 QTest::newRow(
"Down (exact)") << SwipeDirection::Down << QPointF(0, 30) << QPointF(0, 30) <<
true << 1.0;
350 QTest::newRow(
"Down (less)") << SwipeDirection::Down << QPointF(0, 30) << QPointF(0, 29) <<
false << 29.0 / 30.0;
353void GestureTest::testMinimumDeltaReached()
361 QFETCH(QPointF, minimumDelta);
363 QFETCH(QPointF, delta);
364 QFETCH(
bool, reached);
369 QSignalSpy startedSpy(&gesture, &SwipeGesture::started);
370 QSignalSpy triggeredSpy(&gesture, &SwipeGesture::triggered);
371 QSignalSpy cancelledSpy(&gesture, &SwipeGesture::cancelled);
375 QCOMPARE(startedSpy.count(), 1);
376 QCOMPARE(triggeredSpy.count(), 0);
377 QCOMPARE(cancelledSpy.count(), 0);
378 QCOMPARE(progressSpy.count(), 0);
381 QCOMPARE(startedSpy.count(), 1);
382 QCOMPARE(triggeredSpy.count(), 0);
383 QCOMPARE(cancelledSpy.count(), 0);
384 QCOMPARE(progressSpy.count(), 1);
385 QTEST(progressSpy.first().first().value<qreal>(),
"progress");
388 QCOMPARE(startedSpy.count(), 1);
389 QCOMPARE(progressSpy.count(), 1);
390 QCOMPARE(triggeredSpy.isEmpty(), !reached);
391 QCOMPARE(cancelledSpy.isEmpty(), reached);
394void GestureTest::testMinimumScaleDelta()
409 QSignalSpy startedSpy(&gesture, &PinchGesture::started);
410 QSignalSpy triggeredSpy(&gesture, &PinchGesture::triggered);
411 QSignalSpy cancelledSpy(&gesture, &PinchGesture::cancelled);
412 QSignalSpy progressSpy(&gesture, &PinchGesture::progress);
415 QCOMPARE(startedSpy.count(), 1);
416 QCOMPARE(triggeredSpy.count(), 0);
417 QCOMPARE(cancelledSpy.count(), 0);
418 QCOMPARE(progressSpy.count(), 0);
421void GestureTest::testUnregisterSwipeCancels()
424 std::unique_ptr<SwipeGesture> gesture(
new SwipeGesture);
425 QSignalSpy startedSpy(gesture.get(), &SwipeGesture::started);
426 QSignalSpy cancelledSpy(gesture.get(), &SwipeGesture::cancelled);
430 QCOMPARE(startedSpy.count(), 1);
431 QCOMPARE(cancelledSpy.count(), 0);
433 QCOMPARE(cancelledSpy.count(), 1);
437 QCOMPARE(cancelledSpy.count(), 1);
440void GestureTest::testUnregisterPinchCancels()
443 std::unique_ptr<PinchGesture> gesture(
new PinchGesture);
444 QSignalSpy startedSpy(gesture.get(), &PinchGesture::started);
445 QSignalSpy cancelledSpy(gesture.get(), &PinchGesture::cancelled);
449 QCOMPARE(startedSpy.count(), 1);
450 QCOMPARE(cancelledSpy.count(), 0);
452 QCOMPARE(cancelledSpy.count(), 1);
456 QCOMPARE(cancelledSpy.count(), 1);
459void GestureTest::testDeleteSwipeCancels()
462 std::unique_ptr<SwipeGesture> gesture(
new SwipeGesture);
463 QSignalSpy startedSpy(gesture.get(), &SwipeGesture::started);
464 QSignalSpy cancelledSpy(gesture.get(), &SwipeGesture::cancelled);
468 QCOMPARE(startedSpy.count(), 1);
469 QCOMPARE(cancelledSpy.count(), 0);
471 QCOMPARE(cancelledSpy.count(), 1);
474void GestureTest::testSwipeCancel_data()
476 QTest::addColumn<SwipeDirection>(
"direction");
478 QTest::newRow(
"Up") << SwipeDirection::Up;
479 QTest::newRow(
"Left") << SwipeDirection::Left;
480 QTest::newRow(
"Right") << SwipeDirection::Right;
481 QTest::newRow(
"Down") << SwipeDirection::Down;
484void GestureTest::testSwipeCancel()
487 std::unique_ptr<SwipeGesture> gesture(
new SwipeGesture);
490 QSignalSpy startedSpy(gesture.get(), &SwipeGesture::started);
491 QSignalSpy cancelledSpy(gesture.get(), &SwipeGesture::cancelled);
492 QSignalSpy triggeredSpy(gesture.get(), &SwipeGesture::triggered);
496 QCOMPARE(startedSpy.count(), 1);
497 QCOMPARE(cancelledSpy.count(), 0);
499 QCOMPARE(cancelledSpy.count(), 1);
500 QCOMPARE(triggeredSpy.count(), 0);
503void GestureTest::testSwipeUpdateTrigger_data()
505 QTest::addColumn<SwipeDirection>(
"direction");
506 QTest::addColumn<QPointF>(
"delta");
508 QTest::newRow(
"Up") << SwipeDirection::Up << QPointF(2, -3);
509 QTest::newRow(
"Left") << SwipeDirection::Left << QPointF(-3, 1);
510 QTest::newRow(
"Right") << SwipeDirection::Right << QPointF(20, -19);
511 QTest::newRow(
"Down") << SwipeDirection::Down << QPointF(0, 50);
514void GestureTest::testSwipeUpdateTrigger()
521 QSignalSpy triggeredSpy(&gesture, &SwipeGesture::triggered);
522 QSignalSpy cancelledSpy(&gesture, &SwipeGesture::cancelled);
527 QFETCH(QPointF, delta);
529 QCOMPARE(cancelledSpy.count(), 0);
530 QCOMPARE(triggeredSpy.count(), 0);
533 QCOMPARE(cancelledSpy.count(), 0);
534 QCOMPARE(triggeredSpy.count(), 1);
537void GestureTest::testSwipeMinFingerStart_data()
539 QTest::addColumn<uint>(
"min");
540 QTest::addColumn<uint>(
"count");
541 QTest::addColumn<bool>(
"started");
543 QTest::newRow(
"same") << 1u << 1u <<
true;
544 QTest::newRow(
"less") << 2u << 1u <<
false;
545 QTest::newRow(
"more") << 1u << 2u <<
true;
548void GestureTest::testSwipeMinFingerStart()
555 QSignalSpy startedSpy(&gesture, &SwipeGesture::started);
560 QTEST(!startedSpy.isEmpty(),
"started");
563void GestureTest::testSwipeMaxFingerStart_data()
565 QTest::addColumn<uint>(
"max");
566 QTest::addColumn<uint>(
"count");
567 QTest::addColumn<bool>(
"started");
569 QTest::newRow(
"same") << 1u << 1u <<
true;
570 QTest::newRow(
"less") << 2u << 1u <<
true;
571 QTest::newRow(
"more") << 1u << 2u <<
false;
574void GestureTest::testSwipeMaxFingerStart()
581 QSignalSpy startedSpy(&gesture, &SwipeGesture::started);
586 QTEST(!startedSpy.isEmpty(),
"started");
589void GestureTest::testNotEmitCallbacksBeforeDirectionDecided()
611 QSignalSpy expandSpy(&expand, &PinchGesture::progress);
612 QSignalSpy contractSpy(&contract, &PinchGesture::progress);
616 QCOMPARE(upSpy.count(), 0);
617 QCOMPARE(downSpy.count(), 0);
618 QCOMPARE(rightSpy.count(), 0);
622 QCOMPARE(upSpy.count(), 1);
623 QCOMPARE(downSpy.count(), 0);
624 QCOMPARE(rightSpy.count(), 0);
629 QCOMPARE(upSpy.count(), 1);
630 QCOMPARE(downSpy.count(), 1);
631 QCOMPARE(rightSpy.count(), 0);
637 QCOMPARE(upSpy.count(), 1);
638 QCOMPARE(downSpy.count(), 1);
639 QCOMPARE(rightSpy.count(), 1);
645 QCOMPARE(expandSpy.count(), 0);
646 QCOMPARE(contractSpy.count(), 0);
650 QCOMPARE(expandSpy.count(), 0);
651 QCOMPARE(contractSpy.count(), 1);
655 QCOMPARE(expandSpy.count(), 1);
656 QCOMPARE(contractSpy.count(), 1);
659void GestureTest::testSwipeGeometryStart_data()
661 QTest::addColumn<QRect>(
"geometry");
662 QTest::addColumn<QPointF>(
"startPos");
663 QTest::addColumn<bool>(
"started");
665 QTest::newRow(
"top left") << QRect(0, 0, 10, 20) << QPointF(0, 0) <<
true;
666 QTest::newRow(
"top right") << QRect(0, 0, 10, 20) << QPointF(10, 0) <<
true;
667 QTest::newRow(
"bottom left") << QRect(0, 0, 10, 20) << QPointF(0, 20) <<
true;
668 QTest::newRow(
"bottom right") << QRect(0, 0, 10, 20) << QPointF(10, 20) <<
true;
669 QTest::newRow(
"x too small") << QRect(10, 20, 30, 40) << QPointF(9, 25) <<
false;
670 QTest::newRow(
"y too small") << QRect(10, 20, 30, 40) << QPointF(25, 19) <<
false;
671 QTest::newRow(
"x too large") << QRect(10, 20, 30, 40) << QPointF(41, 25) <<
false;
672 QTest::newRow(
"y too large") << QRect(10, 20, 30, 40) << QPointF(25, 61) <<
false;
673 QTest::newRow(
"inside") << QRect(10, 20, 30, 40) << QPointF(25, 25) <<
true;
676void GestureTest::testSwipeGeometryStart()
680 QFETCH(QRect, geometry);
683 QSignalSpy startedSpy(&gesture, &SwipeGesture::started);
686 QFETCH(QPointF, startPos);
688 QTEST(!startedSpy.isEmpty(),
"started");
692#include "test_gestures.moc"
int startPinchGesture(uint fingerCount)
void updateSwipeGesture(const QPointF &delta)
void unregisterSwipeGesture(SwipeGesture *gesture)
void registerSwipeGesture(SwipeGesture *gesture)
void updatePinchGesture(qreal scale, qreal angleDelta, const QPointF &posDelta)
void registerPinchGesture(PinchGesture *gesture)
void cancelSwipeGesture()
int startSwipeGesture(uint fingerCount)
void unregisterPinchGesture(PinchGesture *gesture)
void setMinimumScaleDelta(const qreal &scaleDelta)
void setDirection(PinchDirection direction)
uint minimumFingerCount() const
bool minimumScaleDeltaReached(const qreal &scaleDelta) const
bool minimumFingerCountIsRelevant() const
bool isMinimumScaleDeltaRelevant() const
PinchDirection direction() const
void setMinimumFingerCount(uint count)
bool maximumFingerCountIsRelevant() const
void setMaximumFingerCount(uint count)
uint maximumFingerCount() const
qreal minimumScaleDelta() const
void setDirection(SwipeDirection direction)
SwipeDirection direction() const
bool maximumFingerCountIsRelevant() const
bool isMinimumDeltaRelevant() const
bool maximumYIsRelevant() const
uint minimumFingerCount() const
QPointF minimumDelta() const
bool maximumXIsRelevant() const
uint maximumFingerCount() const
void setMinimumFingerCount(uint count)
void setMinimumDelta(const QPointF &delta)
bool minimumDeltaReached(const QPointF &delta) const
void setMaximumFingerCount(uint count)
bool minimumYIsRelevant() const
void setStartGeometry(const QRect &geometry)
bool minimumFingerCountIsRelevant() const
bool minimumXIsRelevant() const
SwipeDirection
Directions for swipe gestures.
QTEST_MAIN(OnScreenNotificationTest)
Q_DECLARE_METATYPE(SwipeDirection)