Skip to content

Commit

Permalink
libgestures/gesturerecognizer/holdGestureBegin: do nothing if has act…
Browse files Browse the repository at this point in the history
…ive gestures, add test
  • Loading branch information
taj-ny committed Oct 16, 2024
1 parent 803f2b0 commit 60ccb92
Show file tree
Hide file tree
Showing 5 changed files with 44 additions and 0 deletions.
3 changes: 3 additions & 0 deletions src/libgestures/gestures/gesturerecognizer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,9 @@ void GestureRecognizer::unregisterGestures()

void GestureRecognizer::holdGestureBegin(const uint8_t &fingerCount)
{
if (!m_activeHoldGestures.empty())
return;

for (std::shared_ptr<Gesture> gesture : m_gestures)
{
std::shared_ptr<HoldGesture> holdGesture = std::dynamic_pointer_cast<HoldGesture>(gesture);
Expand Down
17 changes: 17 additions & 0 deletions tests/libgestures/gestures/test_gesturerecognizer_hold.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,23 @@ void TestGestureRecognizerHold::init()
m_hold2_2actions_trigger1only->addAction(std::make_shared<GestureAction>(0));
}

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

void TestGestureRecognizerHold::holdGestureBegin_gestureConditionsNotSatisfied_hasNoActiveGestures()
{
TestGestureRecognizerShared::gestureBegin_gestureConditionsNotSatisfied_hasNoActiveGestures
Expand Down
1 change: 1 addition & 0 deletions tests/libgestures/gestures/test_gesturerecognizer_hold.h
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ class TestGestureRecognizerHold : public QObject
private slots:
void init();

void holdGestureBegin_calledTwice_hasOneActiveGesture();
void holdGestureBegin_gestureConditionsNotSatisfied_hasNoActiveGestures();
void holdGestureBegin_twoGesturesWithSatisfiedConditions_hasTwoActiveGestures();

Expand Down
16 changes: 16 additions & 0 deletions tests/libgestures/gestures/test_gesturerecognizer_shared.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,22 @@ template void TestGestureRecognizerShared::gestureUpdate_activeGesture_gestureUp
const QPointF &delta
);

void TestGestureRecognizerShared::gestureBegin_calledTwice_hasOneActiveGesture
(
std::shared_ptr<GestureRecognizer> gestureRecognizer,
std::shared_ptr<Gesture> gesture,
std::function<void()> gestureBegin,
std::function<QList<std::shared_ptr<Gesture>>(void)> activeGestures
)
{
gestureRecognizer->registerGesture(gesture);

gestureBegin();
gestureBegin();

QCOMPARE(activeGestures().size(), 1);
}

void TestGestureRecognizerShared::gestureBegin_gestureConditionsNotSatisfied_hasNoActiveGestures
(
std::shared_ptr<GestureRecognizer> gestureRecognizer,
Expand Down
7 changes: 7 additions & 0 deletions tests/libgestures/gestures/test_gesturerecognizer_shared.h
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,13 @@
class TestGestureRecognizerShared
{
public:
static void gestureBegin_calledTwice_hasOneActiveGesture
(
std::shared_ptr<GestureRecognizer> gestureRecognizer,
std::shared_ptr<Gesture> gesture,
std::function<void()> gestureBegin,
std::function<QList<std::shared_ptr<Gesture>>(void)> activeGestures
);
static void gestureBegin_gestureConditionsNotSatisfied_hasNoActiveGestures
(
std::shared_ptr<GestureRecognizer> gestureRecognizer,
Expand Down

0 comments on commit 60ccb92

Please sign in to comment.