2020-08-02 22:22:19 +00:00
|
|
|
/*
|
|
|
|
KWin - the KDE window manager
|
|
|
|
This file is part of the KDE project.
|
2017-03-18 10:00:30 +00:00
|
|
|
|
2020-08-02 22:22:19 +00:00
|
|
|
SPDX-FileCopyrightText: 2017 Martin Gräßlin <mgraesslin@kde.org>
|
2017-03-18 10:00:30 +00:00
|
|
|
|
2020-08-02 22:22:19 +00:00
|
|
|
SPDX-License-Identifier: GPL-2.0-or-later
|
|
|
|
*/
|
2021-02-09 18:18:36 +00:00
|
|
|
#include "gestures.h"
|
2017-03-18 10:00:30 +00:00
|
|
|
|
|
|
|
#include <QSignalSpy>
|
2022-03-23 10:13:38 +00:00
|
|
|
#include <QTest>
|
2022-02-02 21:51:39 +00:00
|
|
|
#include <QtWidgets/qaction.h>
|
|
|
|
#include <iostream>
|
2017-03-18 10:00:30 +00:00
|
|
|
|
|
|
|
using namespace KWin;
|
|
|
|
|
|
|
|
class GestureTest : public QObject
|
|
|
|
{
|
|
|
|
Q_OBJECT
|
|
|
|
private Q_SLOTS:
|
|
|
|
void testSwipeMinFinger_data();
|
|
|
|
void testSwipeMinFinger();
|
2022-02-02 21:51:39 +00:00
|
|
|
void testPinchMinFinger_data();
|
|
|
|
void testPinchMinFinger();
|
|
|
|
|
2017-03-18 10:00:30 +00:00
|
|
|
void testSwipeMaxFinger_data();
|
|
|
|
void testSwipeMaxFinger();
|
2022-02-02 21:51:39 +00:00
|
|
|
void testPinchMaxFinger_data();
|
|
|
|
void testPinchMaxFinger();
|
|
|
|
|
|
|
|
void testSwipeDirection_data();
|
|
|
|
void testSwipeDirection();
|
|
|
|
void testPinchDirection_data();
|
|
|
|
void testPinchDirection();
|
|
|
|
|
2022-03-23 10:13:38 +00:00
|
|
|
// swipe only
|
2017-03-19 10:40:03 +00:00
|
|
|
void testMinimumX_data();
|
|
|
|
void testMinimumX();
|
|
|
|
void testMinimumY_data();
|
|
|
|
void testMinimumY();
|
|
|
|
void testMaximumX_data();
|
|
|
|
void testMaximumX();
|
|
|
|
void testMaximumY_data();
|
|
|
|
void testMaximumY();
|
|
|
|
void testStartGeometry();
|
2022-02-02 21:51:39 +00:00
|
|
|
|
2022-03-23 10:13:38 +00:00
|
|
|
// swipe and pinch
|
2017-03-19 10:40:03 +00:00
|
|
|
void testSetMinimumDelta();
|
|
|
|
void testMinimumDeltaReached_data();
|
|
|
|
void testMinimumDeltaReached();
|
2022-02-02 21:51:39 +00:00
|
|
|
void testMinimumScaleDelta();
|
2017-03-18 10:00:30 +00:00
|
|
|
void testUnregisterSwipeCancels();
|
2022-02-02 21:51:39 +00:00
|
|
|
void testUnregisterPinchCancels();
|
2017-03-18 10:00:30 +00:00
|
|
|
void testDeleteSwipeCancels();
|
|
|
|
void testSwipeCancel_data();
|
|
|
|
void testSwipeCancel();
|
|
|
|
void testSwipeUpdateTrigger_data();
|
|
|
|
void testSwipeUpdateTrigger();
|
2022-02-02 21:51:39 +00:00
|
|
|
|
2022-03-23 10:13:38 +00:00
|
|
|
// both
|
2017-03-18 10:00:30 +00:00
|
|
|
void testSwipeMinFingerStart_data();
|
|
|
|
void testSwipeMinFingerStart();
|
|
|
|
void testSwipeMaxFingerStart_data();
|
|
|
|
void testSwipeMaxFingerStart();
|
2022-02-02 21:51:39 +00:00
|
|
|
void testNotEmitCallbacksBeforeDirectionDecided();
|
|
|
|
|
2022-03-23 10:13:38 +00:00
|
|
|
// swipe only
|
2017-03-19 10:40:03 +00:00
|
|
|
void testSwipeGeometryStart_data();
|
|
|
|
void testSwipeGeometryStart();
|
2017-03-18 10:00:30 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
void GestureTest::testSwipeMinFinger_data()
|
|
|
|
{
|
|
|
|
QTest::addColumn<uint>("count");
|
|
|
|
QTest::addColumn<uint>("expectedCount");
|
|
|
|
|
|
|
|
QTest::newRow("0") << 0u << 0u;
|
|
|
|
QTest::newRow("1") << 1u << 1u;
|
|
|
|
QTest::newRow("10") << 10u << 10u;
|
|
|
|
}
|
|
|
|
|
|
|
|
void GestureTest::testSwipeMinFinger()
|
|
|
|
{
|
2022-02-02 21:51:39 +00:00
|
|
|
SwipeGesture swipeGesture;
|
|
|
|
QCOMPARE(swipeGesture.minimumFingerCountIsRelevant(), false);
|
|
|
|
QCOMPARE(swipeGesture.minimumFingerCount(), 0u);
|
2017-03-18 10:00:30 +00:00
|
|
|
QFETCH(uint, count);
|
2022-02-02 21:51:39 +00:00
|
|
|
swipeGesture.setMinimumFingerCount(count);
|
|
|
|
QCOMPARE(swipeGesture.minimumFingerCountIsRelevant(), true);
|
|
|
|
QTEST(swipeGesture.minimumFingerCount(), "expectedCount");
|
|
|
|
swipeGesture.setMinimumFingerCount(0);
|
|
|
|
QCOMPARE(swipeGesture.minimumFingerCountIsRelevant(), true);
|
|
|
|
QCOMPARE(swipeGesture.minimumFingerCount(), 0u);
|
|
|
|
}
|
|
|
|
|
|
|
|
void GestureTest::testPinchMinFinger_data()
|
|
|
|
{
|
|
|
|
QTest::addColumn<uint>("count");
|
|
|
|
QTest::addColumn<uint>("expectedCount");
|
|
|
|
|
|
|
|
QTest::newRow("0") << 0u << 0u;
|
|
|
|
QTest::newRow("1") << 1u << 1u;
|
|
|
|
QTest::newRow("10") << 10u << 10u;
|
|
|
|
}
|
|
|
|
|
|
|
|
void GestureTest::testPinchMinFinger()
|
|
|
|
{
|
|
|
|
PinchGesture pinchGesture;
|
|
|
|
QCOMPARE(pinchGesture.minimumFingerCountIsRelevant(), false);
|
|
|
|
QCOMPARE(pinchGesture.minimumFingerCount(), 0u);
|
|
|
|
QFETCH(uint, count);
|
|
|
|
pinchGesture.setMinimumFingerCount(count);
|
|
|
|
QCOMPARE(pinchGesture.minimumFingerCountIsRelevant(), true);
|
|
|
|
QTEST(pinchGesture.minimumFingerCount(), "expectedCount");
|
|
|
|
pinchGesture.setMinimumFingerCount(0);
|
|
|
|
QCOMPARE(pinchGesture.minimumFingerCountIsRelevant(), true);
|
|
|
|
QCOMPARE(pinchGesture.minimumFingerCount(), 0u);
|
2017-03-18 10:00:30 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void GestureTest::testSwipeMaxFinger_data()
|
|
|
|
{
|
|
|
|
QTest::addColumn<uint>("count");
|
|
|
|
QTest::addColumn<uint>("expectedCount");
|
|
|
|
|
|
|
|
QTest::newRow("0") << 0u << 0u;
|
|
|
|
QTest::newRow("1") << 1u << 1u;
|
|
|
|
QTest::newRow("10") << 10u << 10u;
|
|
|
|
}
|
|
|
|
|
|
|
|
void GestureTest::testSwipeMaxFinger()
|
|
|
|
{
|
|
|
|
SwipeGesture gesture;
|
|
|
|
QCOMPARE(gesture.maximumFingerCountIsRelevant(), false);
|
|
|
|
QCOMPARE(gesture.maximumFingerCount(), 0u);
|
|
|
|
QFETCH(uint, count);
|
|
|
|
gesture.setMaximumFingerCount(count);
|
|
|
|
QCOMPARE(gesture.maximumFingerCountIsRelevant(), true);
|
|
|
|
QTEST(gesture.maximumFingerCount(), "expectedCount");
|
|
|
|
gesture.setMaximumFingerCount(0);
|
|
|
|
QCOMPARE(gesture.maximumFingerCountIsRelevant(), true);
|
|
|
|
QCOMPARE(gesture.maximumFingerCount(), 0u);
|
|
|
|
}
|
|
|
|
|
2022-02-02 21:51:39 +00:00
|
|
|
void GestureTest::testPinchMaxFinger_data()
|
2017-03-18 10:00:30 +00:00
|
|
|
{
|
2022-02-02 21:51:39 +00:00
|
|
|
QTest::addColumn<uint>("count");
|
|
|
|
QTest::addColumn<uint>("expectedCount");
|
|
|
|
|
|
|
|
QTest::newRow("0") << 0u << 0u;
|
|
|
|
QTest::newRow("1") << 1u << 1u;
|
|
|
|
QTest::newRow("10") << 10u << 10u;
|
|
|
|
}
|
|
|
|
|
|
|
|
void GestureTest::testPinchMaxFinger()
|
|
|
|
{
|
|
|
|
PinchGesture gesture;
|
|
|
|
QCOMPARE(gesture.maximumFingerCountIsRelevant(), false);
|
|
|
|
QCOMPARE(gesture.maximumFingerCount(), 0u);
|
|
|
|
QFETCH(uint, count);
|
|
|
|
gesture.setMaximumFingerCount(count);
|
|
|
|
QCOMPARE(gesture.maximumFingerCountIsRelevant(), true);
|
|
|
|
QTEST(gesture.maximumFingerCount(), "expectedCount");
|
|
|
|
gesture.setMaximumFingerCount(0);
|
|
|
|
QCOMPARE(gesture.maximumFingerCountIsRelevant(), true);
|
|
|
|
QCOMPARE(gesture.maximumFingerCount(), 0u);
|
|
|
|
}
|
|
|
|
|
|
|
|
void GestureTest::testSwipeDirection_data()
|
|
|
|
{
|
|
|
|
QTest::addColumn<KWin::SwipeGesture::Direction>("swipe_direction");
|
2017-03-18 10:00:30 +00:00
|
|
|
|
|
|
|
QTest::newRow("Up") << KWin::SwipeGesture::Direction::Up;
|
|
|
|
QTest::newRow("Left") << KWin::SwipeGesture::Direction::Left;
|
|
|
|
QTest::newRow("Right") << KWin::SwipeGesture::Direction::Right;
|
|
|
|
QTest::newRow("Down") << KWin::SwipeGesture::Direction::Down;
|
|
|
|
}
|
|
|
|
|
2022-02-02 21:51:39 +00:00
|
|
|
void GestureTest::testSwipeDirection()
|
2017-03-18 10:00:30 +00:00
|
|
|
{
|
|
|
|
SwipeGesture gesture;
|
|
|
|
QCOMPARE(gesture.direction(), SwipeGesture::Direction::Down);
|
2022-02-02 21:51:39 +00:00
|
|
|
QFETCH(KWin::SwipeGesture::Direction, swipe_direction);
|
|
|
|
gesture.setDirection(swipe_direction);
|
|
|
|
QCOMPARE(gesture.direction(), swipe_direction);
|
2017-03-18 10:00:30 +00:00
|
|
|
// back to down
|
|
|
|
gesture.setDirection(SwipeGesture::Direction::Down);
|
|
|
|
QCOMPARE(gesture.direction(), SwipeGesture::Direction::Down);
|
|
|
|
}
|
|
|
|
|
2022-02-02 21:51:39 +00:00
|
|
|
void GestureTest::testPinchDirection_data()
|
|
|
|
{
|
|
|
|
QTest::addColumn<KWin::PinchGesture::Direction>("pinch_direction");
|
|
|
|
|
|
|
|
QTest::newRow("Contracting") << KWin::PinchGesture::Direction::Contracting;
|
|
|
|
QTest::newRow("Expanding") << KWin::PinchGesture::Direction::Expanding;
|
|
|
|
}
|
|
|
|
|
|
|
|
void GestureTest::testPinchDirection()
|
|
|
|
{
|
|
|
|
PinchGesture gesture;
|
|
|
|
QCOMPARE(gesture.direction(), PinchGesture::Direction::Expanding);
|
|
|
|
QFETCH(KWin::PinchGesture::Direction, pinch_direction);
|
|
|
|
gesture.setDirection(pinch_direction);
|
|
|
|
QCOMPARE(gesture.direction(), pinch_direction);
|
|
|
|
// back to down
|
|
|
|
gesture.setDirection(PinchGesture::Direction::Expanding);
|
|
|
|
QCOMPARE(gesture.direction(), PinchGesture::Direction::Expanding);
|
|
|
|
}
|
|
|
|
|
2017-03-19 10:40:03 +00:00
|
|
|
void GestureTest::testMinimumX_data()
|
|
|
|
{
|
|
|
|
QTest::addColumn<int>("min");
|
|
|
|
|
|
|
|
QTest::newRow("0") << 0;
|
|
|
|
QTest::newRow("-1") << -1;
|
|
|
|
QTest::newRow("1") << 1;
|
|
|
|
}
|
|
|
|
|
|
|
|
void GestureTest::testMinimumX()
|
|
|
|
{
|
|
|
|
SwipeGesture gesture;
|
|
|
|
QCOMPARE(gesture.minimumX(), 0);
|
|
|
|
QCOMPARE(gesture.minimumXIsRelevant(), false);
|
|
|
|
QFETCH(int, min);
|
|
|
|
gesture.setMinimumX(min);
|
|
|
|
QCOMPARE(gesture.minimumX(), min);
|
|
|
|
QCOMPARE(gesture.minimumXIsRelevant(), true);
|
|
|
|
}
|
|
|
|
|
|
|
|
void GestureTest::testMinimumY_data()
|
|
|
|
{
|
|
|
|
QTest::addColumn<int>("min");
|
|
|
|
|
|
|
|
QTest::newRow("0") << 0;
|
|
|
|
QTest::newRow("-1") << -1;
|
|
|
|
QTest::newRow("1") << 1;
|
|
|
|
}
|
|
|
|
|
|
|
|
void GestureTest::testMinimumY()
|
|
|
|
{
|
|
|
|
SwipeGesture gesture;
|
|
|
|
QCOMPARE(gesture.minimumY(), 0);
|
|
|
|
QCOMPARE(gesture.minimumYIsRelevant(), false);
|
|
|
|
QFETCH(int, min);
|
|
|
|
gesture.setMinimumY(min);
|
|
|
|
QCOMPARE(gesture.minimumY(), min);
|
|
|
|
QCOMPARE(gesture.minimumYIsRelevant(), true);
|
|
|
|
}
|
|
|
|
|
|
|
|
void GestureTest::testMaximumX_data()
|
|
|
|
{
|
|
|
|
QTest::addColumn<int>("max");
|
|
|
|
|
|
|
|
QTest::newRow("0") << 0;
|
|
|
|
QTest::newRow("-1") << -1;
|
|
|
|
QTest::newRow("1") << 1;
|
|
|
|
}
|
|
|
|
|
|
|
|
void GestureTest::testMaximumX()
|
|
|
|
{
|
|
|
|
SwipeGesture gesture;
|
|
|
|
QCOMPARE(gesture.maximumX(), 0);
|
|
|
|
QCOMPARE(gesture.maximumXIsRelevant(), false);
|
|
|
|
QFETCH(int, max);
|
|
|
|
gesture.setMaximumX(max);
|
|
|
|
QCOMPARE(gesture.maximumX(), max);
|
|
|
|
QCOMPARE(gesture.maximumXIsRelevant(), true);
|
|
|
|
}
|
|
|
|
|
|
|
|
void GestureTest::testMaximumY_data()
|
|
|
|
{
|
|
|
|
QTest::addColumn<int>("max");
|
|
|
|
|
|
|
|
QTest::newRow("0") << 0;
|
|
|
|
QTest::newRow("-1") << -1;
|
|
|
|
QTest::newRow("1") << 1;
|
|
|
|
}
|
|
|
|
|
|
|
|
void GestureTest::testMaximumY()
|
|
|
|
{
|
|
|
|
SwipeGesture gesture;
|
|
|
|
QCOMPARE(gesture.maximumY(), 0);
|
|
|
|
QCOMPARE(gesture.maximumYIsRelevant(), false);
|
|
|
|
QFETCH(int, max);
|
|
|
|
gesture.setMaximumY(max);
|
|
|
|
QCOMPARE(gesture.maximumY(), max);
|
|
|
|
QCOMPARE(gesture.maximumYIsRelevant(), true);
|
|
|
|
}
|
|
|
|
|
|
|
|
void GestureTest::testStartGeometry()
|
|
|
|
{
|
|
|
|
SwipeGesture gesture;
|
|
|
|
gesture.setStartGeometry(QRect(1, 2, 20, 30));
|
|
|
|
QCOMPARE(gesture.minimumXIsRelevant(), true);
|
|
|
|
QCOMPARE(gesture.minimumYIsRelevant(), true);
|
|
|
|
QCOMPARE(gesture.maximumXIsRelevant(), true);
|
|
|
|
QCOMPARE(gesture.maximumYIsRelevant(), true);
|
|
|
|
QCOMPARE(gesture.minimumX(), 1);
|
|
|
|
QCOMPARE(gesture.minimumY(), 2);
|
|
|
|
QCOMPARE(gesture.maximumX(), 21);
|
|
|
|
QCOMPARE(gesture.maximumY(), 32);
|
|
|
|
}
|
|
|
|
|
|
|
|
void GestureTest::testSetMinimumDelta()
|
|
|
|
{
|
2022-02-02 21:51:39 +00:00
|
|
|
SwipeGesture swipeGesture;
|
|
|
|
QCOMPARE(swipeGesture.isMinimumDeltaRelevant(), false);
|
|
|
|
QCOMPARE(swipeGesture.minimumDelta(), QSizeF());
|
|
|
|
QCOMPARE(swipeGesture.minimumDeltaReached(QSizeF()), true);
|
|
|
|
swipeGesture.setMinimumDelta(QSizeF(2, 3));
|
|
|
|
QCOMPARE(swipeGesture.isMinimumDeltaRelevant(), true);
|
|
|
|
QCOMPARE(swipeGesture.minimumDelta(), QSizeF(2, 3));
|
|
|
|
QCOMPARE(swipeGesture.minimumDeltaReached(QSizeF()), false);
|
|
|
|
QCOMPARE(swipeGesture.minimumDeltaReached(QSizeF(2, 3)), true);
|
|
|
|
|
|
|
|
PinchGesture pinchGesture;
|
|
|
|
QCOMPARE(pinchGesture.isMinimumScaleDeltaRelevant(), false);
|
2022-03-23 09:49:35 +00:00
|
|
|
QCOMPARE(pinchGesture.minimumScaleDelta(), DEFAULT_UNIT_SCALE_DELTA);
|
2022-02-02 21:51:39 +00:00
|
|
|
QCOMPARE(pinchGesture.minimumScaleDeltaReached(1.25), true);
|
|
|
|
pinchGesture.setMinimumScaleDelta(.5);
|
|
|
|
QCOMPARE(pinchGesture.isMinimumScaleDeltaRelevant(), true);
|
|
|
|
QCOMPARE(pinchGesture.minimumScaleDelta(), .5);
|
|
|
|
QCOMPARE(pinchGesture.minimumScaleDeltaReached(1.24), false);
|
|
|
|
QCOMPARE(pinchGesture.minimumScaleDeltaReached(1.5), true);
|
2017-03-19 10:40:03 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void GestureTest::testMinimumDeltaReached_data()
|
|
|
|
{
|
|
|
|
QTest::addColumn<KWin::SwipeGesture::Direction>("direction");
|
|
|
|
QTest::addColumn<QSizeF>("minimumDelta");
|
|
|
|
QTest::addColumn<QSizeF>("delta");
|
|
|
|
QTest::addColumn<bool>("reached");
|
|
|
|
QTest::addColumn<qreal>("progress");
|
|
|
|
|
|
|
|
QTest::newRow("Up (more)") << KWin::SwipeGesture::Direction::Up << QSizeF(0, -30) << QSizeF(0, -40) << true << 1.0;
|
|
|
|
QTest::newRow("Up (exact)") << KWin::SwipeGesture::Direction::Up << QSizeF(0, -30) << QSizeF(0, -30) << true << 1.0;
|
2022-02-02 21:51:39 +00:00
|
|
|
QTest::newRow("Up (less)") << KWin::SwipeGesture::Direction::Up << QSizeF(0, -30) << QSizeF(0, -29) << false << 29.0 / 30.0;
|
2017-03-19 10:40:03 +00:00
|
|
|
QTest::newRow("Left (more)") << KWin::SwipeGesture::Direction::Left << QSizeF(-30, -30) << QSizeF(-40, 20) << true << 1.0;
|
|
|
|
QTest::newRow("Left (exact)") << KWin::SwipeGesture::Direction::Left << QSizeF(-30, -40) << QSizeF(-30, 0) << true << 1.0;
|
2022-02-02 21:51:39 +00:00
|
|
|
QTest::newRow("Left (less)") << KWin::SwipeGesture::Direction::Left << QSizeF(-30, -30) << QSizeF(-29, 0) << false << 29.0 / 30.0;
|
2017-03-19 10:40:03 +00:00
|
|
|
QTest::newRow("Right (more)") << KWin::SwipeGesture::Direction::Right << QSizeF(30, -30) << QSizeF(40, 20) << true << 1.0;
|
|
|
|
QTest::newRow("Right (exact)") << KWin::SwipeGesture::Direction::Right << QSizeF(30, -40) << QSizeF(30, 0) << true << 1.0;
|
2022-02-02 21:51:39 +00:00
|
|
|
QTest::newRow("Right (less)") << KWin::SwipeGesture::Direction::Right << QSizeF(30, -30) << QSizeF(29, 0) << false << 29.0 / 30.0;
|
2017-03-19 10:40:03 +00:00
|
|
|
QTest::newRow("Down (more)") << KWin::SwipeGesture::Direction::Down << QSizeF(0, 30) << QSizeF(0, 40) << true << 1.0;
|
|
|
|
QTest::newRow("Down (exact)") << KWin::SwipeGesture::Direction::Down << QSizeF(0, 30) << QSizeF(0, 30) << true << 1.0;
|
2022-02-02 21:51:39 +00:00
|
|
|
QTest::newRow("Down (less)") << KWin::SwipeGesture::Direction::Down << QSizeF(0, 30) << QSizeF(0, 29) << false << 29.0 / 30.0;
|
2017-03-19 10:40:03 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void GestureTest::testMinimumDeltaReached()
|
|
|
|
{
|
2022-02-02 21:51:39 +00:00
|
|
|
GestureRecognizer recognizer;
|
|
|
|
|
2022-03-23 10:13:38 +00:00
|
|
|
// swipe gesture
|
2017-03-19 10:40:03 +00:00
|
|
|
SwipeGesture gesture;
|
|
|
|
QFETCH(SwipeGesture::Direction, direction);
|
|
|
|
gesture.setDirection(direction);
|
|
|
|
QFETCH(QSizeF, minimumDelta);
|
|
|
|
gesture.setMinimumDelta(minimumDelta);
|
|
|
|
QFETCH(QSizeF, delta);
|
|
|
|
QFETCH(bool, reached);
|
|
|
|
QCOMPARE(gesture.minimumDeltaReached(delta), reached);
|
|
|
|
|
2022-02-02 21:51:39 +00:00
|
|
|
recognizer.registerSwipeGesture(&gesture);
|
2017-03-19 10:40:03 +00:00
|
|
|
|
|
|
|
QSignalSpy startedSpy(&gesture, &SwipeGesture::started);
|
|
|
|
QVERIFY(startedSpy.isValid());
|
|
|
|
QSignalSpy triggeredSpy(&gesture, &SwipeGesture::triggered);
|
|
|
|
QVERIFY(triggeredSpy.isValid());
|
|
|
|
QSignalSpy cancelledSpy(&gesture, &SwipeGesture::cancelled);
|
|
|
|
QVERIFY(cancelledSpy.isValid());
|
|
|
|
QSignalSpy progressSpy(&gesture, &SwipeGesture::progress);
|
|
|
|
QVERIFY(progressSpy.isValid());
|
|
|
|
|
|
|
|
recognizer.startSwipeGesture(1);
|
|
|
|
QCOMPARE(startedSpy.count(), 1);
|
|
|
|
QCOMPARE(triggeredSpy.count(), 0);
|
|
|
|
QCOMPARE(cancelledSpy.count(), 0);
|
|
|
|
QCOMPARE(progressSpy.count(), 0);
|
|
|
|
|
|
|
|
recognizer.updateSwipeGesture(delta);
|
|
|
|
QCOMPARE(startedSpy.count(), 1);
|
|
|
|
QCOMPARE(triggeredSpy.count(), 0);
|
|
|
|
QCOMPARE(cancelledSpy.count(), 0);
|
|
|
|
QCOMPARE(progressSpy.count(), 1);
|
|
|
|
QTEST(progressSpy.first().first().value<qreal>(), "progress");
|
|
|
|
|
|
|
|
recognizer.endSwipeGesture();
|
|
|
|
QCOMPARE(startedSpy.count(), 1);
|
|
|
|
QCOMPARE(progressSpy.count(), 1);
|
|
|
|
QCOMPARE(triggeredSpy.isEmpty(), !reached);
|
|
|
|
QCOMPARE(cancelledSpy.isEmpty(), reached);
|
|
|
|
}
|
|
|
|
|
2022-02-02 21:51:39 +00:00
|
|
|
void GestureTest::testMinimumScaleDelta()
|
|
|
|
{
|
2022-03-23 10:13:38 +00:00
|
|
|
// pinch gesture
|
2022-02-02 21:51:39 +00:00
|
|
|
PinchGesture gesture;
|
|
|
|
gesture.setDirection(PinchGesture::Direction::Contracting);
|
|
|
|
gesture.setMinimumScaleDelta(.5);
|
|
|
|
gesture.setMinimumFingerCount(3);
|
|
|
|
gesture.setMaximumFingerCount(4);
|
|
|
|
|
|
|
|
QCOMPARE(gesture.minimumScaleDeltaReached(1.25), false);
|
|
|
|
QCOMPARE(gesture.minimumScaleDeltaReached(1.5), true);
|
|
|
|
|
|
|
|
GestureRecognizer recognizer;
|
|
|
|
recognizer.registerPinchGesture(&gesture);
|
|
|
|
|
|
|
|
QSignalSpy startedSpy(&gesture, &PinchGesture::started);
|
|
|
|
QVERIFY(startedSpy.isValid());
|
|
|
|
QSignalSpy triggeredSpy(&gesture, &PinchGesture::triggered);
|
|
|
|
QVERIFY(triggeredSpy.isValid());
|
|
|
|
QSignalSpy cancelledSpy(&gesture, &PinchGesture::cancelled);
|
|
|
|
QVERIFY(cancelledSpy.isValid());
|
|
|
|
QSignalSpy progressSpy(&gesture, &PinchGesture::progress);
|
|
|
|
QVERIFY(progressSpy.isValid());
|
|
|
|
|
|
|
|
recognizer.startPinchGesture(4);
|
|
|
|
QCOMPARE(startedSpy.count(), 1);
|
|
|
|
QCOMPARE(triggeredSpy.count(), 0);
|
|
|
|
QCOMPARE(cancelledSpy.count(), 0);
|
|
|
|
QCOMPARE(progressSpy.count(), 0);
|
|
|
|
}
|
|
|
|
|
2017-03-18 10:00:30 +00:00
|
|
|
void GestureTest::testUnregisterSwipeCancels()
|
|
|
|
{
|
|
|
|
GestureRecognizer recognizer;
|
|
|
|
QScopedPointer<SwipeGesture> gesture(new SwipeGesture);
|
|
|
|
QSignalSpy startedSpy(gesture.data(), &SwipeGesture::started);
|
|
|
|
QVERIFY(startedSpy.isValid());
|
|
|
|
QSignalSpy cancelledSpy(gesture.data(), &SwipeGesture::cancelled);
|
|
|
|
QVERIFY(cancelledSpy.isValid());
|
|
|
|
|
2022-02-02 21:51:39 +00:00
|
|
|
recognizer.registerSwipeGesture(gesture.data());
|
2017-03-18 10:00:30 +00:00
|
|
|
recognizer.startSwipeGesture(1);
|
|
|
|
QCOMPARE(startedSpy.count(), 1);
|
|
|
|
QCOMPARE(cancelledSpy.count(), 0);
|
2022-02-02 21:51:39 +00:00
|
|
|
recognizer.unregisterSwipeGesture(gesture.data());
|
|
|
|
QCOMPARE(cancelledSpy.count(), 1);
|
|
|
|
|
|
|
|
// delete the gesture should not trigger cancel
|
|
|
|
gesture.reset();
|
|
|
|
QCOMPARE(cancelledSpy.count(), 1);
|
|
|
|
}
|
|
|
|
|
|
|
|
void GestureTest::testUnregisterPinchCancels()
|
|
|
|
{
|
|
|
|
GestureRecognizer recognizer;
|
|
|
|
QScopedPointer<PinchGesture> gesture(new PinchGesture);
|
|
|
|
QSignalSpy startedSpy(gesture.data(), &PinchGesture::started);
|
|
|
|
QVERIFY(startedSpy.isValid());
|
|
|
|
QSignalSpy cancelledSpy(gesture.data(), &PinchGesture::cancelled);
|
|
|
|
QVERIFY(cancelledSpy.isValid());
|
|
|
|
|
|
|
|
recognizer.registerPinchGesture(gesture.data());
|
|
|
|
recognizer.startPinchGesture(1);
|
|
|
|
QCOMPARE(startedSpy.count(), 1);
|
|
|
|
QCOMPARE(cancelledSpy.count(), 0);
|
|
|
|
recognizer.unregisterPinchGesture(gesture.data());
|
2017-03-18 10:00:30 +00:00
|
|
|
QCOMPARE(cancelledSpy.count(), 1);
|
|
|
|
|
|
|
|
// delete the gesture should not trigger cancel
|
|
|
|
gesture.reset();
|
|
|
|
QCOMPARE(cancelledSpy.count(), 1);
|
|
|
|
}
|
|
|
|
|
|
|
|
void GestureTest::testDeleteSwipeCancels()
|
|
|
|
{
|
|
|
|
GestureRecognizer recognizer;
|
|
|
|
QScopedPointer<SwipeGesture> gesture(new SwipeGesture);
|
|
|
|
QSignalSpy startedSpy(gesture.data(), &SwipeGesture::started);
|
|
|
|
QVERIFY(startedSpy.isValid());
|
|
|
|
QSignalSpy cancelledSpy(gesture.data(), &SwipeGesture::cancelled);
|
|
|
|
QVERIFY(cancelledSpy.isValid());
|
|
|
|
|
2022-02-02 21:51:39 +00:00
|
|
|
recognizer.registerSwipeGesture(gesture.data());
|
2017-03-18 10:00:30 +00:00
|
|
|
recognizer.startSwipeGesture(1);
|
|
|
|
QCOMPARE(startedSpy.count(), 1);
|
|
|
|
QCOMPARE(cancelledSpy.count(), 0);
|
|
|
|
gesture.reset();
|
|
|
|
QCOMPARE(cancelledSpy.count(), 1);
|
|
|
|
}
|
|
|
|
|
|
|
|
void GestureTest::testSwipeCancel_data()
|
|
|
|
{
|
|
|
|
QTest::addColumn<KWin::SwipeGesture::Direction>("direction");
|
|
|
|
|
|
|
|
QTest::newRow("Up") << KWin::SwipeGesture::Direction::Up;
|
|
|
|
QTest::newRow("Left") << KWin::SwipeGesture::Direction::Left;
|
|
|
|
QTest::newRow("Right") << KWin::SwipeGesture::Direction::Right;
|
|
|
|
QTest::newRow("Down") << KWin::SwipeGesture::Direction::Down;
|
|
|
|
}
|
|
|
|
|
|
|
|
void GestureTest::testSwipeCancel()
|
|
|
|
{
|
|
|
|
GestureRecognizer recognizer;
|
|
|
|
QScopedPointer<SwipeGesture> gesture(new SwipeGesture);
|
|
|
|
QFETCH(SwipeGesture::Direction, direction);
|
|
|
|
gesture->setDirection(direction);
|
|
|
|
QSignalSpy startedSpy(gesture.data(), &SwipeGesture::started);
|
|
|
|
QVERIFY(startedSpy.isValid());
|
|
|
|
QSignalSpy cancelledSpy(gesture.data(), &SwipeGesture::cancelled);
|
|
|
|
QVERIFY(cancelledSpy.isValid());
|
|
|
|
QSignalSpy triggeredSpy(gesture.data(), &SwipeGesture::triggered);
|
|
|
|
QVERIFY(triggeredSpy.isValid());
|
|
|
|
|
2022-02-02 21:51:39 +00:00
|
|
|
recognizer.registerSwipeGesture(gesture.data());
|
2017-03-18 10:00:30 +00:00
|
|
|
recognizer.startSwipeGesture(1);
|
|
|
|
QCOMPARE(startedSpy.count(), 1);
|
|
|
|
QCOMPARE(cancelledSpy.count(), 0);
|
|
|
|
recognizer.cancelSwipeGesture();
|
|
|
|
QCOMPARE(cancelledSpy.count(), 1);
|
|
|
|
QCOMPARE(triggeredSpy.count(), 0);
|
|
|
|
}
|
|
|
|
|
|
|
|
void GestureTest::testSwipeUpdateTrigger_data()
|
|
|
|
{
|
|
|
|
QTest::addColumn<KWin::SwipeGesture::Direction>("direction");
|
|
|
|
QTest::addColumn<QSizeF>("delta");
|
|
|
|
|
|
|
|
QTest::newRow("Up") << KWin::SwipeGesture::Direction::Up << QSizeF(2, -3);
|
|
|
|
QTest::newRow("Left") << KWin::SwipeGesture::Direction::Left << QSizeF(-3, 1);
|
|
|
|
QTest::newRow("Right") << KWin::SwipeGesture::Direction::Right << QSizeF(20, -19);
|
|
|
|
QTest::newRow("Down") << KWin::SwipeGesture::Direction::Down << QSizeF(0, 50);
|
|
|
|
}
|
|
|
|
|
|
|
|
void GestureTest::testSwipeUpdateTrigger()
|
|
|
|
{
|
|
|
|
GestureRecognizer recognizer;
|
|
|
|
SwipeGesture gesture;
|
|
|
|
QFETCH(SwipeGesture::Direction, direction);
|
|
|
|
gesture.setDirection(direction);
|
|
|
|
|
|
|
|
QSignalSpy triggeredSpy(&gesture, &SwipeGesture::triggered);
|
|
|
|
QVERIFY(triggeredSpy.isValid());
|
|
|
|
QSignalSpy cancelledSpy(&gesture, &SwipeGesture::cancelled);
|
|
|
|
QVERIFY(cancelledSpy.isValid());
|
|
|
|
|
2022-02-02 21:51:39 +00:00
|
|
|
recognizer.registerSwipeGesture(&gesture);
|
2017-03-18 10:00:30 +00:00
|
|
|
|
|
|
|
recognizer.startSwipeGesture(1);
|
|
|
|
QFETCH(QSizeF, delta);
|
|
|
|
recognizer.updateSwipeGesture(delta);
|
|
|
|
QCOMPARE(cancelledSpy.count(), 0);
|
|
|
|
QCOMPARE(triggeredSpy.count(), 0);
|
|
|
|
|
|
|
|
recognizer.endSwipeGesture();
|
|
|
|
QCOMPARE(cancelledSpy.count(), 0);
|
|
|
|
QCOMPARE(triggeredSpy.count(), 1);
|
|
|
|
}
|
|
|
|
|
|
|
|
void GestureTest::testSwipeMinFingerStart_data()
|
|
|
|
{
|
|
|
|
QTest::addColumn<uint>("min");
|
|
|
|
QTest::addColumn<uint>("count");
|
|
|
|
QTest::addColumn<bool>("started");
|
|
|
|
|
|
|
|
QTest::newRow("same") << 1u << 1u << true;
|
|
|
|
QTest::newRow("less") << 2u << 1u << false;
|
|
|
|
QTest::newRow("more") << 1u << 2u << true;
|
|
|
|
}
|
|
|
|
|
|
|
|
void GestureTest::testSwipeMinFingerStart()
|
|
|
|
{
|
|
|
|
GestureRecognizer recognizer;
|
|
|
|
SwipeGesture gesture;
|
|
|
|
QFETCH(uint, min);
|
|
|
|
gesture.setMinimumFingerCount(min);
|
|
|
|
|
|
|
|
QSignalSpy startedSpy(&gesture, &SwipeGesture::started);
|
|
|
|
QVERIFY(startedSpy.isValid());
|
|
|
|
|
2022-02-02 21:51:39 +00:00
|
|
|
recognizer.registerSwipeGesture(&gesture);
|
2017-03-18 10:00:30 +00:00
|
|
|
QFETCH(uint, count);
|
|
|
|
recognizer.startSwipeGesture(count);
|
|
|
|
QTEST(!startedSpy.isEmpty(), "started");
|
|
|
|
}
|
|
|
|
|
|
|
|
void GestureTest::testSwipeMaxFingerStart_data()
|
|
|
|
{
|
|
|
|
QTest::addColumn<uint>("max");
|
|
|
|
QTest::addColumn<uint>("count");
|
|
|
|
QTest::addColumn<bool>("started");
|
|
|
|
|
|
|
|
QTest::newRow("same") << 1u << 1u << true;
|
|
|
|
QTest::newRow("less") << 2u << 1u << true;
|
|
|
|
QTest::newRow("more") << 1u << 2u << false;
|
|
|
|
}
|
|
|
|
|
|
|
|
void GestureTest::testSwipeMaxFingerStart()
|
|
|
|
{
|
|
|
|
GestureRecognizer recognizer;
|
|
|
|
SwipeGesture gesture;
|
|
|
|
QFETCH(uint, max);
|
|
|
|
gesture.setMaximumFingerCount(max);
|
|
|
|
|
|
|
|
QSignalSpy startedSpy(&gesture, &SwipeGesture::started);
|
|
|
|
QVERIFY(startedSpy.isValid());
|
|
|
|
|
2022-02-02 21:51:39 +00:00
|
|
|
recognizer.registerSwipeGesture(&gesture);
|
2017-03-18 10:00:30 +00:00
|
|
|
QFETCH(uint, count);
|
|
|
|
recognizer.startSwipeGesture(count);
|
|
|
|
QTEST(!startedSpy.isEmpty(), "started");
|
|
|
|
}
|
|
|
|
|
2022-02-02 21:51:39 +00:00
|
|
|
void GestureTest::testNotEmitCallbacksBeforeDirectionDecided()
|
|
|
|
{
|
|
|
|
GestureRecognizer recognizer;
|
|
|
|
SwipeGesture up;
|
|
|
|
SwipeGesture down;
|
|
|
|
SwipeGesture right;
|
|
|
|
PinchGesture expand;
|
|
|
|
PinchGesture contract;
|
|
|
|
up.setDirection(SwipeGesture::Direction::Up);
|
|
|
|
down.setDirection(SwipeGesture::Direction::Down);
|
|
|
|
right.setDirection(SwipeGesture::Direction::Right);
|
|
|
|
expand.setDirection(PinchGesture::Direction::Expanding);
|
|
|
|
contract.setDirection(PinchGesture::Direction::Contracting);
|
|
|
|
recognizer.registerSwipeGesture(&up);
|
|
|
|
recognizer.registerSwipeGesture(&down);
|
|
|
|
recognizer.registerSwipeGesture(&right);
|
|
|
|
recognizer.registerPinchGesture(&expand);
|
|
|
|
recognizer.registerPinchGesture(&contract);
|
|
|
|
|
|
|
|
QSignalSpy upSpy(&up, &SwipeGesture::progress);
|
|
|
|
QSignalSpy downSpy(&down, &SwipeGesture::progress);
|
|
|
|
QSignalSpy rightSpy(&right, &SwipeGesture::progress);
|
|
|
|
QSignalSpy expandSpy(&expand, &PinchGesture::progress);
|
|
|
|
QSignalSpy contractSpy(&contract, &PinchGesture::progress);
|
|
|
|
|
2022-03-23 10:13:38 +00:00
|
|
|
// don't release callback until we know the direction of swipe gesture
|
2022-02-02 21:51:39 +00:00
|
|
|
recognizer.startSwipeGesture(4);
|
|
|
|
QCOMPARE(upSpy.count(), 0);
|
|
|
|
QCOMPARE(downSpy.count(), 0);
|
|
|
|
QCOMPARE(rightSpy.count(), 0);
|
|
|
|
|
2022-03-23 10:13:38 +00:00
|
|
|
// up (negative y)
|
2022-02-02 21:51:39 +00:00
|
|
|
recognizer.updateSwipeGesture(QSizeF(0, -1.5));
|
|
|
|
QCOMPARE(upSpy.count(), 1);
|
|
|
|
QCOMPARE(downSpy.count(), 0);
|
|
|
|
QCOMPARE(rightSpy.count(), 0);
|
|
|
|
|
2022-03-23 10:13:38 +00:00
|
|
|
// down (positive y)
|
|
|
|
// recognizer.updateSwipeGesture(QSizeF(0, 0));
|
2022-02-02 21:51:39 +00:00
|
|
|
recognizer.updateSwipeGesture(QSizeF(0, 3));
|
|
|
|
QCOMPARE(upSpy.count(), 1);
|
|
|
|
QCOMPARE(downSpy.count(), 1);
|
|
|
|
QCOMPARE(rightSpy.count(), 0);
|
|
|
|
|
2022-03-23 10:13:38 +00:00
|
|
|
// right
|
2022-02-02 21:51:39 +00:00
|
|
|
recognizer.cancelSwipeGesture();
|
|
|
|
recognizer.startSwipeGesture(4);
|
|
|
|
recognizer.updateSwipeGesture(QSizeF(1, 0));
|
|
|
|
QCOMPARE(upSpy.count(), 1);
|
|
|
|
QCOMPARE(downSpy.count(), 1);
|
|
|
|
QCOMPARE(rightSpy.count(), 1);
|
|
|
|
|
|
|
|
recognizer.cancelSwipeGesture();
|
|
|
|
|
2022-03-23 10:13:38 +00:00
|
|
|
// same test for pinch gestures
|
2022-02-02 21:51:39 +00:00
|
|
|
recognizer.startPinchGesture(4);
|
|
|
|
QCOMPARE(expandSpy.count(), 0);
|
|
|
|
QCOMPARE(contractSpy.count(), 0);
|
|
|
|
|
2022-03-23 10:13:38 +00:00
|
|
|
// contracting
|
2022-02-02 21:51:39 +00:00
|
|
|
recognizer.updatePinchGesture(.5, 0, QSizeF(0, 0));
|
|
|
|
QCOMPARE(expandSpy.count(), 0);
|
|
|
|
QCOMPARE(contractSpy.count(), 1);
|
|
|
|
|
2022-03-23 10:13:38 +00:00
|
|
|
// expanding
|
2022-02-02 21:51:39 +00:00
|
|
|
recognizer.updatePinchGesture(1.5, 0, QSizeF(0, 0));
|
|
|
|
QCOMPARE(expandSpy.count(), 1);
|
|
|
|
QCOMPARE(contractSpy.count(), 1);
|
|
|
|
}
|
|
|
|
|
2017-03-19 10:40:03 +00:00
|
|
|
void GestureTest::testSwipeGeometryStart_data()
|
|
|
|
{
|
|
|
|
QTest::addColumn<QRect>("geometry");
|
|
|
|
QTest::addColumn<QPointF>("startPos");
|
|
|
|
QTest::addColumn<bool>("started");
|
|
|
|
|
|
|
|
QTest::newRow("top left") << QRect(0, 0, 10, 20) << QPointF(0, 0) << true;
|
|
|
|
QTest::newRow("top right") << QRect(0, 0, 10, 20) << QPointF(10, 0) << true;
|
|
|
|
QTest::newRow("bottom left") << QRect(0, 0, 10, 20) << QPointF(0, 20) << true;
|
|
|
|
QTest::newRow("bottom right") << QRect(0, 0, 10, 20) << QPointF(10, 20) << true;
|
|
|
|
QTest::newRow("x too small") << QRect(10, 20, 30, 40) << QPointF(9, 25) << false;
|
|
|
|
QTest::newRow("y too small") << QRect(10, 20, 30, 40) << QPointF(25, 19) << false;
|
|
|
|
QTest::newRow("x too large") << QRect(10, 20, 30, 40) << QPointF(41, 25) << false;
|
|
|
|
QTest::newRow("y too large") << QRect(10, 20, 30, 40) << QPointF(25, 61) << false;
|
|
|
|
QTest::newRow("inside") << QRect(10, 20, 30, 40) << QPointF(25, 25) << true;
|
|
|
|
}
|
|
|
|
|
|
|
|
void GestureTest::testSwipeGeometryStart()
|
|
|
|
{
|
|
|
|
GestureRecognizer recognizer;
|
|
|
|
SwipeGesture gesture;
|
|
|
|
QFETCH(QRect, geometry);
|
|
|
|
gesture.setStartGeometry(geometry);
|
|
|
|
|
|
|
|
QSignalSpy startedSpy(&gesture, &SwipeGesture::started);
|
|
|
|
QVERIFY(startedSpy.isValid());
|
|
|
|
|
2022-02-02 21:51:39 +00:00
|
|
|
recognizer.registerSwipeGesture(&gesture);
|
2017-03-19 10:40:03 +00:00
|
|
|
QFETCH(QPointF, startPos);
|
|
|
|
recognizer.startSwipeGesture(startPos);
|
|
|
|
QTEST(!startedSpy.isEmpty(), "started");
|
|
|
|
}
|
|
|
|
|
2017-03-18 10:00:30 +00:00
|
|
|
QTEST_MAIN(GestureTest)
|
|
|
|
#include "test_gestures.moc"
|