-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
tests/gesturerecognizer: extract common tests into another class
- Loading branch information
Showing
11 changed files
with
354 additions
and
112 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1 +1 @@ | ||
add_subdirectory(libgesture) | ||
add_subdirectory(libgestures) |
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
File renamed without changes.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
# libgestures | ||
libgestures is a library for recognizing and handling gestures. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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
135
tests/libgestures/gestures/test_gesturerecognizer_hold.cpp
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.