Skip to content

Commit

Permalink
tests/gesturerecognizer: extract common tests into another class
Browse files Browse the repository at this point in the history
  • Loading branch information
taj-ny committed Oct 16, 2024
1 parent c90da76 commit 803f2b0
Show file tree
Hide file tree
Showing 11 changed files with 354 additions and 112 deletions.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -114,4 +114,4 @@ Before reporting any issues related to gesture recognition, run ``libinput debug
Depending on the touchpad, 3 or 4-finger pinch gestures may sometimes be incorrectly interpreted as swipe gestures due to the touchpad only being able to track 2 fingers. As a workaround, move only 2 fingers in opposite directions. See https://wayland.freedesktop.org/libinput/doc/1.25.0/gestures.html#gestures-on-two-finger-touchpads for more information.

# Credits
- [KWin](https://invent.kde.org/plasma/kwin) - Gesture recognition, sending keystrokes
- [KWin](https://invent.kde.org/plasma/kwin) - Gesture recognition code in early versions, sending keystrokes
2 changes: 1 addition & 1 deletion tests/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1 +1 @@
add_subdirectory(libgesture)
add_subdirectory(libgestures)
7 changes: 0 additions & 7 deletions tests/libgesture/gestures/CMakeLists.txt

This file was deleted.

99 changes: 0 additions & 99 deletions tests/libgesture/gestures/test_gesturerecognizer_hold.cpp

This file was deleted.

File renamed without changes.
2 changes: 2 additions & 0 deletions tests/libgestures/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
# libgestures
libgestures is a library for recognizing and handling gestures.
11 changes: 11 additions & 0 deletions tests/libgestures/gestures/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
set(testGestureRecognizerHold_SRCS
test_gesturerecognizer_hold.cpp
test_gesturerecognizer_shared.cpp
)
qt_add_executable(testGestureRecognizerHold ${testGestureRecognizerHold_SRCS})
add_test(NAME "gesturerecognizer_hold" COMMAND testGestureRecognizerHold)
target_link_libraries(testGestureRecognizerHold PRIVATE
libgestures
Qt::Core
Qt::Test
)
135 changes: 135 additions & 0 deletions tests/libgestures/gestures/test_gesturerecognizer_hold.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,135 @@
#include "test_gesturerecognizer_shared.h"
#include "test_gesturerecognizer_hold.h"
#include <QSignalSpy>

void TestGestureRecognizerHold::init()
{
m_gestureRecognizer = std::make_shared<GestureRecognizer>();
m_hold2 = std::make_shared<HoldGesture>(false, 2, 2, false, 0);
m_hold2To3 = std::make_shared<HoldGesture>(false, 2, 3, false, 0);
m_hold3To4 = std::make_shared<HoldGesture>(false, 3, 4, false, 0);

m_hold2_2actions_trigger1only = std::make_shared<HoldGesture>(true, 2, 2, true, 1);
m_hold2_2actions_trigger1only->addAction(std::make_shared<GestureAction>(0));
m_hold2_2actions_trigger1only->addAction(std::make_shared<GestureAction>(0));
}

void TestGestureRecognizerHold::holdGestureBegin_gestureConditionsNotSatisfied_hasNoActiveGestures()
{
TestGestureRecognizerShared::gestureBegin_gestureConditionsNotSatisfied_hasNoActiveGestures
(
m_gestureRecognizer,
m_hold2,
[this]()
{
m_gestureRecognizer->holdGestureBegin(3);
},
[this]()
{
return m_gestureRecognizer->m_activeHoldGestures;
}
);
}

void TestGestureRecognizerHold::holdGestureBegin_twoGesturesWithSatisfiedConditions_hasTwoActiveGestures()
{
TestGestureRecognizerShared::gestureBegin_twoGesturesWithSatisfiedConditions_hasTwoActiveGestures
(
m_gestureRecognizer,
{ m_hold2To3, m_hold3To4 },
[this]()
{
m_gestureRecognizer->holdGestureBegin(3);
},
[this]()
{
return m_gestureRecognizer->m_activeHoldGestures;
}
);
}

void TestGestureRecognizerHold::holdGestureUpdate_activeGesture_gestureUpdateSignalEmittedExactlyOneTimeAndDeltaMatchesAndGestureNotEndedPrematurely()
{
TestGestureRecognizerShared::gestureUpdate_activeGesture_gestureUpdateSignalEmittedExactlyOneTimeAndDeltaMatchesAndGestureNotEndedPrematurely<qreal>
(
m_gestureRecognizer,
m_hold2,
[this]() {
m_gestureRecognizer->holdGestureBegin(2);
},
[this](const qreal & delta, bool &endedPrematurely) {
m_gestureRecognizer->holdGestureUpdate(delta, endedPrematurely);
},
1
);
}

void TestGestureRecognizerHold::holdGestureUpdate_twoActiveGesturesAndOneEndsPrematurely_endedPrematurelySetToTrueAndOnlyOneGestureUpdated()
{
const auto delta = 1;
TestGestureRecognizerShared::gestureUpdate_twoActiveGesturesAndOneEndsPrematurely_endedPrematurelySetToTrueAndOnlyOneGestureUpdated
(
m_gestureRecognizer,
m_hold2_2actions_trigger1only,
m_hold2,
[this]()
{
m_gestureRecognizer->holdGestureBegin(2);
},
[this](bool &endedPrematurely)
{
m_gestureRecognizer->holdGestureUpdate(delta, endedPrematurely);
}
);
}

void TestGestureRecognizerHold::holdGestureCancelled_twoActiveGestures_gestureCancelledSignalEmittedForAllGesturesAndActiveHoldGesturesCleared()
{
TestGestureRecognizerShared::gestureCancelled_twoActiveGestures_gestureCancelledSignalEmittedForAllGesturesAndActiveGesturesCleared
(
m_gestureRecognizer,
m_hold2To3,
m_hold3To4,
[this]()
{
m_gestureRecognizer->holdGestureBegin(3);
},
[this]()
{
return m_gestureRecognizer->holdGestureCancelled();
},
[this]()
{
return m_gestureRecognizer->m_activeHoldGestures;
}
);
}

void TestGestureRecognizerHold::holdGestureEnd_noActiveGestures_returnsFalse()
{
QVERIFY(!m_gestureRecognizer->holdGestureEnd());
}

void TestGestureRecognizerHold::holdGestureEnd_activeGesture_gestureEndedSignalEmittedAndActiveHoldGesturesClearedAndReturnsTrue()
{
TestGestureRecognizerShared::gestureEnd_activeGesture_gestureEndedSignalEmittedAndActiveHoldGesturesClearedAndReturnsTrue
(
m_gestureRecognizer,
m_hold2,
[this]()
{
m_gestureRecognizer->holdGestureBegin(2);
},
[this]()
{
return m_gestureRecognizer->holdGestureEnd();
},
[this]()
{
return m_gestureRecognizer->m_activeHoldGestures;
}
);
}

QTEST_MAIN(TestGestureRecognizerHold)
#include "test_gesturerecognizer_hold.moc"
Original file line number Diff line number Diff line change
Expand Up @@ -7,18 +7,18 @@ class TestGestureRecognizerHold : public QObject
private slots:
void init();

void holdGestureBegin_holdGestureConditionsNotSatisfied_hasNoActiveHoldGestures();
void holdGestureBegin_twoHoldGesturesWithSatisfiedConditions_hasTwoActiveHoldGestures();
void holdGestureBegin_gestureConditionsNotSatisfied_hasNoActiveGestures();
void holdGestureBegin_twoGesturesWithSatisfiedConditions_hasTwoActiveGestures();

void holdGestureUpdate_activeGesture_gestureUpdateSignalEmittedExactlyOneTimeAndGestureNotEndedPrematurely();
void holdGestureUpdate_activeGesture_gestureUpdateSignalEmittedExactlyOneTimeAndDeltaMatchesAndGestureNotEndedPrematurely();
void holdGestureUpdate_twoActiveGesturesAndOneEndsPrematurely_endedPrematurelySetToTrueAndOnlyOneGestureUpdated();

void holdGestureCancelled_twoActiveGestures_gestureCancelledSignalEmittedForAllGesturesAndActiveHoldGesturesCleared();

void holdGestureEnd_noActiveGestures_returnsFalse();
void holdGestureEnd_activeGesture_gestureEndedSignalEmittedAndActiveHoldGesturesClearedAndReturnsTrue();
private:
std::unique_ptr<GestureRecognizer> m_gestureRecognizer;
std::shared_ptr<GestureRecognizer> m_gestureRecognizer;

std::shared_ptr<HoldGesture> m_hold2;
std::shared_ptr<HoldGesture> m_hold2To3;
Expand Down
Loading

0 comments on commit 803f2b0

Please sign in to comment.