2 // Copyright (c) 2014 Samsung Electronics Co., Ltd.
4 // Licensed under the Flora License, Version 1.0 (the License);
5 // you may not use this file except in compliance with the License.
6 // You may obtain a copy of the License at
8 // http://floralicense.org/license/
10 // Unless required by applicable law or agreed to in writing, software
11 // distributed under the License is distributed on an AS IS BASIS,
12 // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 // See the License for the specific language governing permissions and
14 // limitations under the License.
22 #include <dali/public-api/dali-core.h>
23 #include <dali/integration-api/events/touch-event-integ.h>
24 #include <dali/integration-api/events/pan-gesture-event.h>
25 #include <dali/integration-api/system-overlay.h>
27 #include <dali-test-suite-utils.h>
31 static void Startup();
32 static void Cleanup();
35 void (*tet_startup)() = Startup;
36 void (*tet_cleanup)() = Cleanup;
40 POSITIVE_TC_IDX = 0x01,
44 #define MAX_NUMBER_OF_TESTS 10000
46 struct tet_testlist tet_testlist[MAX_NUMBER_OF_TESTS];
49 // Add test functionality for all APIs in the class (Positive and Negative)
50 TEST_FUNCTION( UtcDaliPanGestureDetectorConstructor, POSITIVE_TC_IDX );
51 TEST_FUNCTION( UtcDaliPanGestureDetectorNew, POSITIVE_TC_IDX );
52 TEST_FUNCTION( UtcDaliPanGestureDetectorDownCast, POSITIVE_TC_IDX );
53 TEST_FUNCTION( UtcDaliPanGestureSetMinimumTouchesRequired, POSITIVE_TC_IDX );
54 TEST_FUNCTION( UtcDaliPanGestureSetMaximumTouchesRequired, POSITIVE_TC_IDX );
55 TEST_FUNCTION( UtcDaliPanGestureGetMinimumTouchesRequired, POSITIVE_TC_IDX );
56 TEST_FUNCTION( UtcDaliPanGestureGetMaximumTouchesRequired, POSITIVE_TC_IDX );
57 TEST_FUNCTION( UtcDaliPanGestureSignalReceptionNegative, NEGATIVE_TC_IDX );
58 TEST_FUNCTION( UtcDaliPanGestureSignalReceptionDownMotionLeave, POSITIVE_TC_IDX );
59 TEST_FUNCTION( UtcDaliPanGestureSignalReceptionDownMotionUp, POSITIVE_TC_IDX );
60 TEST_FUNCTION( UtcDaliPanGestureSignalReceptionCancelled, NEGATIVE_TC_IDX );
61 TEST_FUNCTION( UtcDaliPanGestureSignalReceptionDetach, NEGATIVE_TC_IDX );
62 TEST_FUNCTION( UtcDaliPanGestureSignalReceptionDetachWhilePanning, NEGATIVE_TC_IDX );
63 TEST_FUNCTION( UtcDaliPanGestureSignalReceptionActorDestroyedWhilePanning, NEGATIVE_TC_IDX );
64 TEST_FUNCTION( UtcDaliPanGestureSignalReceptionRotatedActor, POSITIVE_TC_IDX );
65 TEST_FUNCTION( UtcDaliPanGestureSignalReceptionChildHit, POSITIVE_TC_IDX );
66 TEST_FUNCTION( UtcDaliPanGestureSignalReceptionAttachDetachMany, POSITIVE_TC_IDX );
67 TEST_FUNCTION( UtcDaliPanGestureSignalReceptionActorBecomesUntouchable, POSITIVE_TC_IDX );
68 TEST_FUNCTION( UtcDaliPanGestureSignalReceptionMultipleGestureDetectors, POSITIVE_TC_IDX );
69 TEST_FUNCTION( UtcDaliPanGestureSignalReceptionMultipleDetectorsOnActor, POSITIVE_TC_IDX );
70 TEST_FUNCTION( UtcDaliPanGestureSignalReceptionMultipleStarted, NEGATIVE_TC_IDX );
71 TEST_FUNCTION( UtcDaliPanGestureSignalReceptionEnsureCorrectSignalling, POSITIVE_TC_IDX );
72 TEST_FUNCTION( UtcDaliPanGestureSignalReceptionDifferentPossible, POSITIVE_TC_IDX );
73 TEST_FUNCTION( UtcDaliPanGestureEmitIncorrectState, NEGATIVE_TC_IDX );
74 TEST_FUNCTION( UtcDaliPanGestureDetectorTypeRegistry, POSITIVE_TC_IDX );
75 TEST_FUNCTION( UtcDaliPanGestureActorUnstaged, NEGATIVE_TC_IDX );
76 TEST_FUNCTION( UtcDaliPanGestureActorStagedAndDestroyed, NEGATIVE_TC_IDX );
77 TEST_FUNCTION( UtcDaliPanGestureSystemOverlay, POSITIVE_TC_IDX );
78 TEST_FUNCTION( UtcDaliPanGestureAngleHandling, POSITIVE_TC_IDX );
79 TEST_FUNCTION( UtcDaliPanGestureAngleOutOfRange, NEGATIVE_TC_IDX );
80 TEST_FUNCTION( UtcDaliPanGestureAngleProcessing, POSITIVE_TC_IDX );
81 TEST_FUNCTION( UtcDaliPanGestureDirectionHandling, POSITIVE_TC_IDX );
82 TEST_FUNCTION( UtcDaliPanGestureDirectionProcessing, POSITIVE_TC_IDX );
83 TEST_FUNCTION( UtcDaliPanGestureSetProperties, POSITIVE_TC_IDX );
84 TEST_FUNCTION( UtcDaliPanGestureSetPropertiesAlreadyPanning, NEGATIVE_TC_IDX );
85 TEST_FUNCTION( UtcDaliPanGesturePropertyIndices, POSITIVE_TC_IDX );
87 // Called only once before first test is run.
92 // Called only once after last test is run
97 typedef Dali::PanGestureDetector::AngleContainer::size_type AngleSizeType;
99 ///////////////////////////////////////////////////////////////////////////////
101 // Stores data that is populated in the callback and will be read by the TET cases
105 : functorCalled(false),
106 voidFunctorCalled(false),
107 receivedGesture(Gesture::Clear)
112 functorCalled = false;
113 voidFunctorCalled = false;
115 receivedGesture.state = Gesture::Clear;
116 receivedGesture.velocity = Vector2(0.0f, 0.0f);
117 receivedGesture.displacement = Vector2(0.0f, 0.0f);
118 receivedGesture.position = Vector2(0.0f, 0.0f);
119 receivedGesture.screenPosition = Vector2(0.0f, 0.0f);
120 receivedGesture.numberOfTouches = 0;
126 bool voidFunctorCalled;
127 PanGesture receivedGesture;
131 // Functor that sets the data when called
132 struct GestureReceivedFunctor
134 GestureReceivedFunctor(SignalData& data) : signalData(data) { }
136 void operator()(Actor actor, PanGesture pan)
138 signalData.functorCalled = true;
139 signalData.receivedGesture = pan;
140 signalData.pannedActor = actor;
145 signalData.voidFunctorCalled = true;
148 SignalData& signalData;
151 // Functor that removes the gestured actor from stage
152 struct UnstageActorFunctor : public GestureReceivedFunctor
154 UnstageActorFunctor( SignalData& data, Gesture::State& stateToUnstage )
155 : GestureReceivedFunctor( data ),
156 stateToUnstage( stateToUnstage )
160 void operator()( Actor actor, PanGesture pan )
162 GestureReceivedFunctor::operator()( actor, pan );
164 if ( pan.state == stateToUnstage )
166 Stage::GetCurrent().Remove( actor );
170 Gesture::State& stateToUnstage;
173 // Functor for receiving a touch event
174 struct TouchEventFunctor
176 bool operator()(Actor actor, const TouchEvent& touch)
182 // Data for constraints
183 struct ConstraintData
190 Vector2 screenPosition;
191 Vector2 screenDisplacement;
192 Vector2 localPosition;
193 Vector2 localDisplacement;
198 screenPosition = screenDisplacement = localPosition = localDisplacement = Vector2::ZERO;
203 // Constraint used with panning properties
206 PanConstraint( ConstraintData& data ) : constraintData(data) { }
208 Vector3 operator()(const Vector3& current,
209 const PropertyInput& screenPositionProperty,
210 const PropertyInput& screenDisplacementProperty,
211 const PropertyInput& localPositionProperty,
212 const PropertyInput& localDisplacementProperty)
214 constraintData.screenPosition = screenPositionProperty.GetVector2();
215 constraintData.screenDisplacement = screenDisplacementProperty.GetVector2();
216 constraintData.localPosition = localPositionProperty.GetVector2();
217 constraintData.localDisplacement = localDisplacementProperty.GetVector2();
218 constraintData.called = true;
219 return Vector3::ZERO;
222 ConstraintData& constraintData;
225 // Generate a PanGestureEvent to send to Core
226 Integration::PanGestureEvent GeneratePan(
227 Gesture::State state,
228 Vector2 previousPosition,
229 Vector2 currentPosition,
230 unsigned long timeDelta,
231 unsigned int numberOfTouches = 1,
232 unsigned int time = 1u)
234 Integration::PanGestureEvent pan(state);
236 pan.previousPosition = previousPosition;
237 pan.currentPosition = currentPosition;
238 pan.timeDelta = timeDelta;
239 pan.numberOfTouches = numberOfTouches;
245 // Generate a PanGesture
246 PanGesture GeneratePan( unsigned int time,
247 Gesture::State state,
248 Vector2 screenPosition,
249 Vector2 localPosition,
250 Vector2 screenDisplacement = Vector2::ONE,
251 Vector2 localDisplacement = Vector2::ONE,
252 Vector2 velocity = Vector2::ONE,
253 unsigned int numberOfTouches = 1 )
255 PanGesture pan( state );
259 pan.screenPosition = screenPosition;
260 pan.position = localPosition;
262 pan.screenDisplacement = screenDisplacement;
263 pan.displacement = localDisplacement;
265 pan.screenVelocity = pan.velocity = velocity;
266 pan.numberOfTouches = numberOfTouches;
271 ///////////////////////////////////////////////////////////////////////////////
273 // Positive test case for a method
274 static void UtcDaliPanGestureDetectorConstructor()
276 TestApplication application;
278 PanGestureDetector detector;
279 DALI_TEST_CHECK(!detector);
283 // Negative test case for a method
284 static void UtcDaliPanGestureDetectorNew()
286 TestApplication application;
288 PanGestureDetector detector = PanGestureDetector::New();
290 DALI_TEST_CHECK(detector);
292 DALI_TEST_EQUALS(1u, detector.GetMinimumTouchesRequired(), TEST_LOCATION);
293 DALI_TEST_EQUALS(1u, detector.GetMaximumTouchesRequired(), TEST_LOCATION);
295 // Attach an actor and emit a touch event on the actor to ensure complete line coverage
296 Actor actor = Actor::New();
297 actor.SetSize(100.0f, 100.0f);
298 actor.SetAnchorPoint(AnchorPoint::TOP_LEFT);
299 detector.Attach(actor);
301 Stage::GetCurrent().Add(actor);
304 application.SendNotification();
305 application.Render();
307 Integration::TouchEvent touchEvent(1);
308 TouchPoint point(1, TouchPoint::Down, 20.0f, 20.0f);
309 touchEvent.AddPoint(point);
310 application.ProcessEvent(touchEvent);
313 static void UtcDaliPanGestureDetectorDownCast()
315 TestApplication application;
316 tet_infoline("Testing Dali::GestureDetector::DownCast()");
318 PanGestureDetector detector = PanGestureDetector::New();
320 BaseHandle object(detector);
322 PanGestureDetector detector2 = PanGestureDetector::DownCast(object);
323 DALI_TEST_CHECK(detector2);
325 PanGestureDetector detector3 = DownCast< PanGestureDetector >(object);
326 DALI_TEST_CHECK(detector3);
328 BaseHandle unInitializedObject;
329 PanGestureDetector detector4 = PanGestureDetector::DownCast(unInitializedObject);
330 DALI_TEST_CHECK(!detector4);
332 PanGestureDetector detector5 = DownCast< PanGestureDetector >(unInitializedObject);
333 DALI_TEST_CHECK(!detector5);
335 GestureDetector detector6 = PanGestureDetector::New();
336 PanGestureDetector detector7 = PanGestureDetector::DownCast(detector6);
337 DALI_TEST_CHECK(detector7);
340 static void UtcDaliPanGestureSetMinimumTouchesRequired()
342 TestApplication application;
344 PanGestureDetector detector = PanGestureDetector::New();
346 unsigned int min = 2;
348 DALI_TEST_CHECK(min != detector.GetMinimumTouchesRequired());
350 detector.SetMinimumTouchesRequired(min);
352 DALI_TEST_EQUALS(min, detector.GetMinimumTouchesRequired(), TEST_LOCATION);
354 // Attach an actor and change the minimum touches
356 Actor actor = Actor::New();
357 actor.SetSize(100.0f, 100.0f);
358 actor.SetAnchorPoint(AnchorPoint::TOP_LEFT);
359 Stage::GetCurrent().Add(actor);
362 application.SendNotification();
363 application.Render();
366 GestureReceivedFunctor functor(data);
368 detector.Attach(actor);
369 detector.DetectedSignal().Connect(&application, functor);
371 TestGestureManager& gestureManager = application.GetGestureManager();
372 gestureManager.Initialize();
374 detector.SetMinimumTouchesRequired(3);
376 // Gesture detection should have been updated only
377 DALI_TEST_EQUALS(true, gestureManager.WasCalled(TestGestureManager::UpdateType), TEST_LOCATION);
378 DALI_TEST_EQUALS(false, gestureManager.WasCalled(TestGestureManager::RegisterType), TEST_LOCATION);
379 DALI_TEST_EQUALS(false, gestureManager.WasCalled(TestGestureManager::UnregisterType), TEST_LOCATION);
382 gestureManager.Initialize();
384 // Create a second gesture detector that requires even less minimum touches
385 PanGestureDetector secondDetector = PanGestureDetector::New();
386 secondDetector.Attach(actor);
388 // Gesture detection should have been updated only
389 DALI_TEST_EQUALS(true, gestureManager.WasCalled(TestGestureManager::UpdateType), TEST_LOCATION);
390 DALI_TEST_EQUALS(false, gestureManager.WasCalled(TestGestureManager::RegisterType), TEST_LOCATION);
391 DALI_TEST_EQUALS(false, gestureManager.WasCalled(TestGestureManager::UnregisterType), TEST_LOCATION);
394 static void UtcDaliPanGestureSetMaximumTouchesRequired()
396 TestApplication application;
398 PanGestureDetector detector = PanGestureDetector::New();
400 unsigned int max = 3;
402 DALI_TEST_CHECK(max != detector.GetMaximumTouchesRequired());
404 detector.SetMaximumTouchesRequired(max);
406 DALI_TEST_EQUALS(max, detector.GetMaximumTouchesRequired(), TEST_LOCATION);
408 // Attach an actor and change the maximum touches
410 Actor actor = Actor::New();
411 actor.SetSize(100.0f, 100.0f);
412 actor.SetAnchorPoint(AnchorPoint::TOP_LEFT);
413 Stage::GetCurrent().Add(actor);
416 application.SendNotification();
417 application.Render();
420 GestureReceivedFunctor functor(data);
422 detector.Attach(actor);
423 detector.DetectedSignal().Connect(&application, functor);
425 TestGestureManager& gestureManager = application.GetGestureManager();
426 gestureManager.Initialize();
428 detector.SetMaximumTouchesRequired(4);
430 // Gesture detection should have been updated only
431 DALI_TEST_EQUALS(true, gestureManager.WasCalled(TestGestureManager::UpdateType), TEST_LOCATION);
432 DALI_TEST_EQUALS(false, gestureManager.WasCalled(TestGestureManager::RegisterType), TEST_LOCATION);
433 DALI_TEST_EQUALS(false, gestureManager.WasCalled(TestGestureManager::UnregisterType), TEST_LOCATION);
436 gestureManager.Initialize();
438 // Create a second gesture detector that requires even less maximum touches
439 PanGestureDetector secondDetector = PanGestureDetector::New();
440 secondDetector.Attach(actor);
442 // Gesture detection should NOT have been updated
443 DALI_TEST_EQUALS(false, gestureManager.WasCalled(TestGestureManager::UpdateType), TEST_LOCATION);
444 DALI_TEST_EQUALS(false, gestureManager.WasCalled(TestGestureManager::RegisterType), TEST_LOCATION);
445 DALI_TEST_EQUALS(false, gestureManager.WasCalled(TestGestureManager::UnregisterType), TEST_LOCATION);
448 static void UtcDaliPanGestureGetMinimumTouchesRequired()
450 TestApplication application;
452 PanGestureDetector detector = PanGestureDetector::New();
453 DALI_TEST_EQUALS(1u, detector.GetMinimumTouchesRequired(), TEST_LOCATION);
456 static void UtcDaliPanGestureGetMaximumTouchesRequired()
458 TestApplication application;
460 PanGestureDetector detector = PanGestureDetector::New();
461 DALI_TEST_EQUALS(1u, detector.GetMaximumTouchesRequired(), TEST_LOCATION);
464 static void UtcDaliPanGestureSignalReceptionNegative()
466 TestApplication application;
468 Actor actor = Actor::New();
469 actor.SetSize(100.0f, 100.0f);
470 actor.SetAnchorPoint(AnchorPoint::TOP_LEFT);
471 Stage::GetCurrent().Add(actor);
474 application.SendNotification();
475 application.Render();
478 GestureReceivedFunctor functor(data);
480 PanGestureDetector detector = PanGestureDetector::New();
481 detector.Attach(actor);
482 detector.DetectedSignal().Connect(&application, functor);
484 // Do a pan outside actor's area
485 application.ProcessEvent(GeneratePan(Gesture::Possible, Vector2(110.0f, 110.0f), Vector2(112.0f, 112.0f), 10));
486 application.ProcessEvent(GeneratePan(Gesture::Started, Vector2(110.0f, 110.0f), Vector2(112.0f, 112.0f), 10));
487 DALI_TEST_EQUALS(false, data.functorCalled, TEST_LOCATION);
489 // Continue pan into actor's area - we should still not receive the signal
491 application.ProcessEvent(GeneratePan(Gesture::Continuing, Vector2(112.0f, 112.0f), Vector2(20.0f, 20.0f), 10));
492 DALI_TEST_EQUALS(false, data.functorCalled, TEST_LOCATION);
494 // Stop panning - we should still not receive the signal
496 application.ProcessEvent(GeneratePan(Gesture::Finished, Vector2(20.0f, 20.0f), Vector2(12.0f, 12.0f), 10));
497 DALI_TEST_EQUALS(false, data.functorCalled, TEST_LOCATION);
500 static void UtcDaliPanGestureSignalReceptionDownMotionLeave()
502 TestApplication application;
504 Actor actor = Actor::New();
505 actor.SetSize(100.0f, 100.0f);
506 actor.SetAnchorPoint(AnchorPoint::TOP_LEFT);
507 Stage::GetCurrent().Add(actor);
510 application.SendNotification();
511 application.Render();
514 GestureReceivedFunctor functor(data);
516 PanGestureDetector detector = PanGestureDetector::New();
517 detector.Attach(actor);
518 detector.DetectedSignal().Connect(&application, functor);
520 // Start pan within the actor's area
521 application.ProcessEvent(GeneratePan(Gesture::Possible, Vector2(10.0f, 20.0f), Vector2(20.0f, 20.0f), 10));
522 application.ProcessEvent(GeneratePan(Gesture::Started, Vector2(10.0f, 20.0f), Vector2(20.0f, 20.0f), 10));
523 DALI_TEST_EQUALS(true, data.functorCalled, TEST_LOCATION);
524 DALI_TEST_EQUALS(Gesture::Started, data.receivedGesture.state, TEST_LOCATION);
525 DALI_TEST_EQUALS(1u, data.receivedGesture.numberOfTouches, TEST_LOCATION);
526 DALI_TEST_EQUALS(Vector2(10.0f, 0.0f), data.receivedGesture.displacement, 0.01f, TEST_LOCATION);
527 DALI_TEST_EQUALS(Vector2(1.0f, 0.0f), data.receivedGesture.velocity, 0.01f, TEST_LOCATION);
528 DALI_TEST_EQUALS(10.0f, data.receivedGesture.GetDistance(), 0.01f, TEST_LOCATION);
529 DALI_TEST_EQUALS(1.0f, data.receivedGesture.GetSpeed(), 0.01f, TEST_LOCATION);
531 // Continue the pan within the actor's area - we should still receive the signal
533 application.ProcessEvent(GeneratePan(Gesture::Continuing, Vector2(20.0f, 20.0f), Vector2(20.0f, 10.0f), 10));
534 DALI_TEST_EQUALS(true, data.functorCalled, TEST_LOCATION);
535 DALI_TEST_EQUALS(Gesture::Continuing, data.receivedGesture.state, TEST_LOCATION);
536 DALI_TEST_EQUALS(1u, data.receivedGesture.numberOfTouches, TEST_LOCATION);
537 DALI_TEST_EQUALS(Vector2(0.0f, -10.0f), data.receivedGesture.displacement, 0.01f, TEST_LOCATION);
538 DALI_TEST_EQUALS(Vector2(0.0f, -1.0f), data.receivedGesture.velocity, 0.01f, TEST_LOCATION);
539 DALI_TEST_EQUALS(10.0f, data.receivedGesture.GetDistance(), 0.01f, TEST_LOCATION);
540 DALI_TEST_EQUALS(1.0f, data.receivedGesture.GetSpeed(), 0.01f, TEST_LOCATION);
542 // Pan Gesture leaves actor's area - we should still receive the signal
544 application.ProcessEvent(GeneratePan(Gesture::Continuing, Vector2(20.0f, 10.0f), Vector2(320.0f, 10.0f), 10));
545 DALI_TEST_EQUALS(true, data.functorCalled, TEST_LOCATION);
546 DALI_TEST_EQUALS(Gesture::Continuing, data.receivedGesture.state, TEST_LOCATION);
547 DALI_TEST_EQUALS(1u, data.receivedGesture.numberOfTouches, TEST_LOCATION);
548 DALI_TEST_EQUALS(Vector2(300.0f, 0.0f), data.receivedGesture.displacement, 0.01f, TEST_LOCATION);
549 DALI_TEST_EQUALS(Vector2(30.0f, 0.0f), data.receivedGesture.velocity, 0.01f, TEST_LOCATION);
550 DALI_TEST_EQUALS(300.0f, data.receivedGesture.GetDistance(), 0.01f, TEST_LOCATION);
551 DALI_TEST_EQUALS(30.0f, data.receivedGesture.GetSpeed(), 0.01f, TEST_LOCATION);
553 // Gesture ends - we would receive a finished state
555 application.ProcessEvent(GeneratePan(Gesture::Finished, Vector2(320.0f, 10.0f), Vector2(310.0f, 10.0f), 10));
556 DALI_TEST_EQUALS(true, data.functorCalled, TEST_LOCATION);
557 DALI_TEST_EQUALS(Gesture::Finished, data.receivedGesture.state, TEST_LOCATION);
558 DALI_TEST_EQUALS(1u, data.receivedGesture.numberOfTouches, TEST_LOCATION);
559 DALI_TEST_EQUALS(Vector2(-10.0f, 0.0f), data.receivedGesture.displacement, 0.01f, TEST_LOCATION);
560 DALI_TEST_EQUALS(Vector2(-1.0f, 0.0f), data.receivedGesture.velocity, 0.01f, TEST_LOCATION);
561 DALI_TEST_EQUALS(10.0f, data.receivedGesture.GetDistance(), 0.01f, TEST_LOCATION);
562 DALI_TEST_EQUALS(1.0f, data.receivedGesture.GetSpeed(), 0.01f, TEST_LOCATION);
565 static void UtcDaliPanGestureSignalReceptionDownMotionUp()
567 TestApplication application;
569 Actor actor = Actor::New();
570 actor.SetSize(100.0f, 100.0f);
571 actor.SetAnchorPoint(AnchorPoint::TOP_LEFT);
572 Stage::GetCurrent().Add(actor);
575 application.SendNotification();
576 application.Render();
579 GestureReceivedFunctor functor(data);
581 PanGestureDetector detector = PanGestureDetector::New();
582 detector.Attach(actor);
583 detector.DetectedSignal().Connect(&application, functor);
585 // Start pan within the actor's area
586 application.ProcessEvent(GeneratePan(Gesture::Possible, Vector2(10.0f, 20.0f), Vector2(20.0f, 20.0f), 10));
587 application.ProcessEvent(GeneratePan(Gesture::Started, Vector2(10.0f, 20.0f), Vector2(20.0f, 20.0f), 10));
588 DALI_TEST_EQUALS(true, data.functorCalled, TEST_LOCATION);
589 DALI_TEST_EQUALS(Gesture::Started, data.receivedGesture.state, TEST_LOCATION);
590 DALI_TEST_EQUALS(1u, data.receivedGesture.numberOfTouches, TEST_LOCATION);
591 DALI_TEST_EQUALS(Vector2(10.0f, 0.0f), data.receivedGesture.displacement, 0.01f, TEST_LOCATION);
592 DALI_TEST_EQUALS(Vector2(1.0f, 0.0f), data.receivedGesture.velocity, 0.01f, TEST_LOCATION);
593 DALI_TEST_EQUALS(10.0f, data.receivedGesture.GetDistance(), 0.01f, TEST_LOCATION);
594 DALI_TEST_EQUALS(1.0f, data.receivedGesture.GetSpeed(), 0.01f, TEST_LOCATION);
596 // Continue the pan within the actor's area - we should still receive the signal
598 application.ProcessEvent(GeneratePan(Gesture::Continuing, Vector2(20.0f, 20.0f), Vector2(20.0f, 10.0f), 10));
599 DALI_TEST_EQUALS(true, data.functorCalled, TEST_LOCATION);
600 DALI_TEST_EQUALS(Gesture::Continuing, data.receivedGesture.state, TEST_LOCATION);
601 DALI_TEST_EQUALS(1u, data.receivedGesture.numberOfTouches, TEST_LOCATION);
602 DALI_TEST_EQUALS(Vector2(0.0f, -10.0f), data.receivedGesture.displacement, 0.01f, TEST_LOCATION);
603 DALI_TEST_EQUALS(Vector2(0.0f, -1.0f), data.receivedGesture.velocity, 0.01f, TEST_LOCATION);
604 DALI_TEST_EQUALS(10.0f, data.receivedGesture.GetDistance(), 0.01f, TEST_LOCATION);
605 DALI_TEST_EQUALS(1.0f, data.receivedGesture.GetSpeed(), 0.01f, TEST_LOCATION);
607 // Gesture ends within actor's area - we would receive a finished state
609 application.ProcessEvent(GeneratePan(Gesture::Finished, Vector2(20.0f, 10.0f), Vector2(10.0f, 10.0f), 10));
610 DALI_TEST_EQUALS(true, data.functorCalled, TEST_LOCATION);
611 DALI_TEST_EQUALS(Gesture::Finished, data.receivedGesture.state, TEST_LOCATION);
612 DALI_TEST_EQUALS(1u, data.receivedGesture.numberOfTouches, TEST_LOCATION);
613 DALI_TEST_EQUALS(Vector2(-10.0f, 0.0f), data.receivedGesture.displacement, 0.01f, TEST_LOCATION);
614 DALI_TEST_EQUALS(Vector2(-1.0f, 0.0f), data.receivedGesture.velocity, 0.01f, TEST_LOCATION);
615 DALI_TEST_EQUALS(10.0f, data.receivedGesture.GetDistance(), 0.01f, TEST_LOCATION);
616 DALI_TEST_EQUALS(1.0f, data.receivedGesture.GetSpeed(), 0.01f, TEST_LOCATION);
619 static void UtcDaliPanGestureSignalReceptionCancelled()
621 TestApplication application;
623 Actor actor = Actor::New();
624 actor.SetSize(100.0f, 100.0f);
625 actor.SetAnchorPoint(AnchorPoint::TOP_LEFT);
626 Stage::GetCurrent().Add(actor);
629 application.SendNotification();
630 application.Render();
633 GestureReceivedFunctor functor(data);
635 PanGestureDetector detector = PanGestureDetector::New();
636 detector.Attach(actor);
637 detector.DetectedSignal().Connect(&application, functor);
639 // Start pan within the actor's area
640 application.ProcessEvent(GeneratePan(Gesture::Possible, Vector2(10.0f, 20.0f), Vector2(20.0f, 20.0f), 10));
641 application.ProcessEvent(GeneratePan(Gesture::Started, Vector2(10.0f, 20.0f), Vector2(20.0f, 20.0f), 10));
642 DALI_TEST_EQUALS(true, data.functorCalled, TEST_LOCATION);
643 DALI_TEST_EQUALS(Gesture::Started, data.receivedGesture.state, TEST_LOCATION);
645 // Continue the pan within the actor's area - we should still receive the signal
647 application.ProcessEvent(GeneratePan(Gesture::Continuing, Vector2(20.0f, 20.0f), Vector2(20.0f, 10.0f), 10));
648 DALI_TEST_EQUALS(true, data.functorCalled, TEST_LOCATION);
649 DALI_TEST_EQUALS(Gesture::Continuing, data.receivedGesture.state, TEST_LOCATION);
651 // The gesture is cancelled
653 application.ProcessEvent(GeneratePan(Gesture::Cancelled, Vector2(20.0f, 10.0f), Vector2(10.0f, 10.0f), 10));
654 DALI_TEST_EQUALS(true, data.functorCalled, TEST_LOCATION);
655 DALI_TEST_EQUALS(Gesture::Cancelled, data.receivedGesture.state, TEST_LOCATION);
658 static void UtcDaliPanGestureSignalReceptionDetach()
660 TestApplication application;
662 Actor actor = Actor::New();
663 actor.SetSize(100.0f, 100.0f);
664 actor.SetAnchorPoint(AnchorPoint::TOP_LEFT);
665 Stage::GetCurrent().Add(actor);
668 application.SendNotification();
669 application.Render();
672 GestureReceivedFunctor functor(data);
674 PanGestureDetector detector = PanGestureDetector::New();
675 detector.Attach(actor);
676 detector.DetectedSignal().Connect(&application, functor);
678 // Start pan within the actor's area
679 application.ProcessEvent(GeneratePan(Gesture::Possible, Vector2(10.0f, 20.0f), Vector2(20.0f, 20.0f), 10));
680 application.ProcessEvent(GeneratePan(Gesture::Started, Vector2(10.0f, 20.0f), Vector2(20.0f, 20.0f), 10));
681 DALI_TEST_EQUALS(true, data.functorCalled, TEST_LOCATION);
683 // Continue the pan within the actor's area - we should still receive the signal
685 application.ProcessEvent(GeneratePan(Gesture::Continuing, Vector2(20.0f, 20.0f), Vector2(20.0f, 10.0f), 10));
686 DALI_TEST_EQUALS(true, data.functorCalled, TEST_LOCATION);
688 // Gesture ends within actor's area
690 application.ProcessEvent(GeneratePan(Gesture::Finished, Vector2(20.0f, 10.0f), Vector2(10.0f, 10.0f), 10));
691 DALI_TEST_EQUALS(true, data.functorCalled, TEST_LOCATION);
694 detector.DetachAll();
696 // Ensure we are no longer signalled
698 application.ProcessEvent(GeneratePan(Gesture::Possible, Vector2(10.0f, 20.0f), Vector2(20.0f, 20.0f), 10));
699 application.ProcessEvent(GeneratePan(Gesture::Started, Vector2(10.0f, 20.0f), Vector2(20.0f, 20.0f), 10));
700 application.ProcessEvent(GeneratePan(Gesture::Continuing, Vector2(20.0f, 20.0f), Vector2(20.0f, 10.0f), 10));
701 application.ProcessEvent(GeneratePan(Gesture::Finished, Vector2(20.0f, 10.0f), Vector2(10.0f, 10.0f), 10));
702 DALI_TEST_EQUALS(false, data.functorCalled, TEST_LOCATION);
705 static void UtcDaliPanGestureSignalReceptionDetachWhilePanning()
707 TestApplication application;
709 Actor actor = Actor::New();
710 actor.SetSize(100.0f, 100.0f);
711 actor.SetAnchorPoint(AnchorPoint::TOP_LEFT);
712 Stage::GetCurrent().Add(actor);
715 application.SendNotification();
716 application.Render();
719 GestureReceivedFunctor functor(data);
721 PanGestureDetector detector = PanGestureDetector::New();
722 detector.Attach(actor);
723 detector.DetectedSignal().Connect(&application, functor);
725 // Start pan within the actor's area
726 application.ProcessEvent(GeneratePan(Gesture::Possible, Vector2(10.0f, 20.0f), Vector2(20.0f, 20.0f), 10));
727 application.ProcessEvent(GeneratePan(Gesture::Started, Vector2(10.0f, 20.0f), Vector2(20.0f, 20.0f), 10));
728 DALI_TEST_EQUALS(true, data.functorCalled, TEST_LOCATION);
730 // Continue the pan within the actor's area - we should still receive the signal
732 application.ProcessEvent(GeneratePan(Gesture::Continuing, Vector2(20.0f, 20.0f), Vector2(20.0f, 10.0f), 10));
733 DALI_TEST_EQUALS(true, data.functorCalled, TEST_LOCATION);
735 // Detach actor during the pan, we should not receive the next event
736 detector.DetachAll();
738 // Gesture ends within actor's area
740 application.ProcessEvent(GeneratePan(Gesture::Finished, Vector2(20.0f, 10.0f), Vector2(10.0f, 10.0f), 10));
741 DALI_TEST_EQUALS(false, data.functorCalled, TEST_LOCATION);
744 static void UtcDaliPanGestureSignalReceptionActorDestroyedWhilePanning()
746 TestApplication application;
749 GestureReceivedFunctor functor(data);
751 PanGestureDetector detector = PanGestureDetector::New();
752 detector.DetectedSignal().Connect(&application, functor);
754 // Attach a temporary actor to stop detector being removed from PanGestureProcessor when main actor
756 Actor tempActor = Actor::New();
757 tempActor.SetSize(100.0f, 100.0f);
758 tempActor.SetAnchorPoint(AnchorPoint::BOTTOM_RIGHT);
759 Stage::GetCurrent().Add(tempActor);
760 detector.Attach(tempActor);
762 // Actor lifetime is scoped
764 Actor actor = Actor::New();
765 actor.SetSize(100.0f, 100.0f);
766 actor.SetAnchorPoint(AnchorPoint::TOP_LEFT);
767 Stage::GetCurrent().Add(actor);
770 application.SendNotification();
771 application.Render();
773 detector.Attach(actor);
775 // Start pan within the actor's area
776 application.ProcessEvent(GeneratePan(Gesture::Possible, Vector2(10.0f, 20.0f), Vector2(20.0f, 20.0f), 10));
777 application.ProcessEvent(GeneratePan(Gesture::Started, Vector2(10.0f, 20.0f), Vector2(20.0f, 20.0f), 10));
778 DALI_TEST_EQUALS(true, data.functorCalled, TEST_LOCATION);
780 // Continue the pan within the actor's area - we should still receive the signal
782 application.ProcessEvent(GeneratePan(Gesture::Continuing, Vector2(20.0f, 20.0f), Vector2(20.0f, 10.0f), 10));
783 DALI_TEST_EQUALS(true, data.functorCalled, TEST_LOCATION);
785 // Remove the actor from stage and reset the data
786 Stage::GetCurrent().Remove(actor);
789 application.SendNotification();
790 application.Render();
793 // Actor should now have been destroyed
795 // Gesture ends within the area where the actor used to be
797 application.ProcessEvent(GeneratePan(Gesture::Finished, Vector2(20.0f, 10.0f), Vector2(10.0f, 10.0f), 10));
798 DALI_TEST_EQUALS(false, data.functorCalled, TEST_LOCATION);
801 static void UtcDaliPanGestureSignalReceptionRotatedActor()
803 TestApplication application;
805 Actor actor = Actor::New();
806 actor.SetSize(100.0f, 100.0f);
807 actor.SetRotation(Dali::Degree(90.0f), Vector3::ZAXIS);
808 Stage::GetCurrent().Add(actor);
811 application.SendNotification();
812 application.Render();
815 GestureReceivedFunctor functor(data);
817 PanGestureDetector detector = PanGestureDetector::New();
818 detector.Attach(actor);
819 detector.DetectedSignal().Connect(&application, functor);
821 // Do an entire pan, only check finished value
822 application.ProcessEvent(GeneratePan(Gesture::Possible, Vector2(11.0f, 12.0f), Vector2(22.0f, 12.0f), 10));
823 application.ProcessEvent(GeneratePan(Gesture::Started, Vector2(11.0f, 12.0f), Vector2(22.0f, 12.0f), 10));
825 application.ProcessEvent(GeneratePan(Gesture::Finished, Vector2(22.0f, 12.0f), Vector2(27.0f, 20.0f), 10));
826 DALI_TEST_EQUALS(true, data.functorCalled, TEST_LOCATION);
827 DALI_TEST_EQUALS(Vector2(8.0f, -5.0f), data.receivedGesture.displacement, 0.01f, TEST_LOCATION); // Actor relative
829 // Rotate actor again and render a couple of times
830 actor.SetRotation(Dali::Degree(180.0f), Vector3::ZAXIS);
831 application.SendNotification();
832 application.Render();
834 // Do an entire pan, only check finished value
835 application.ProcessEvent(GeneratePan(Gesture::Possible, Vector2(11.0f, 12.0f), Vector2(22.0f, 12.0f), 10));
836 application.ProcessEvent(GeneratePan(Gesture::Started, Vector2(11.0f, 12.0f), Vector2(22.0f, 12.0f), 10));
838 application.ProcessEvent(GeneratePan(Gesture::Finished, Vector2(22.0f, 12.0f), Vector2(27.0f, 20.0f), 10));
839 DALI_TEST_EQUALS(true, data.functorCalled, TEST_LOCATION);
840 DALI_TEST_EQUALS(Vector2(-5.0f, -8.0f), data.receivedGesture.displacement, 0.01f, TEST_LOCATION); // Actor relative
842 // Rotate actor again and render a couple of times
843 actor.SetRotation(Dali::Degree(270.0f), Vector3::ZAXIS);
844 application.SendNotification();
845 application.Render();
847 // Do an entire pan, only check finished value
848 application.ProcessEvent(GeneratePan(Gesture::Possible, Vector2(11.0f, 12.0f), Vector2(22.0f, 12.0f), 10));
849 application.ProcessEvent(GeneratePan(Gesture::Started, Vector2(11.0f, 12.0f), Vector2(22.0f, 12.0f), 10));
851 application.ProcessEvent(GeneratePan(Gesture::Finished, Vector2(22.0f, 12.0f), Vector2(27.0f, 20.0f), 10));
852 DALI_TEST_EQUALS(true, data.functorCalled, TEST_LOCATION);
853 DALI_TEST_EQUALS(Vector2(-8.0f, 5.0f), data.receivedGesture.displacement, 0.01f, TEST_LOCATION); // Actor relative
856 static void UtcDaliPanGestureSignalReceptionChildHit()
858 TestApplication application;
860 Actor parent = Actor::New();
861 parent.SetSize(100.0f, 100.0f);
862 parent.SetAnchorPoint(AnchorPoint::TOP_LEFT);
863 Stage::GetCurrent().Add(parent);
865 // Set child to completely cover parent.
866 // Change rotation of child to be different from parent so that we can check if our local coordinate
867 // conversion of the parent actor is correct.
868 Actor child = Actor::New();
869 child.SetSize(100.0f, 100.0f);
870 child.SetAnchorPoint(AnchorPoint::CENTER);
871 child.SetParentOrigin(ParentOrigin::CENTER);
872 child.SetRotation(Dali::Degree(90.0f), Vector3::ZAXIS);
875 TouchEventFunctor touchFunctor;
876 child.TouchedSignal().Connect(&application, touchFunctor);
879 application.SendNotification();
880 application.Render();
883 GestureReceivedFunctor functor(data);
885 PanGestureDetector detector = PanGestureDetector::New();
886 detector.Attach(parent);
887 detector.DetectedSignal().Connect(&application, functor);
889 // Do an entire pan, only check finished value - hits child area but parent should still receive it
890 application.ProcessEvent(GeneratePan(Gesture::Possible, Vector2(11.0f, 12.0f), Vector2(22.0f, 12.0f), 10));
891 application.ProcessEvent(GeneratePan(Gesture::Started, Vector2(11.0f, 12.0f), Vector2(22.0f, 12.0f), 10));
893 application.ProcessEvent(GeneratePan(Gesture::Finished, Vector2(22.0f, 12.0f), Vector2(27.0f, 20.0f), 10));
894 DALI_TEST_EQUALS(true, data.functorCalled, TEST_LOCATION);
895 DALI_TEST_EQUALS(true, parent == data.pannedActor, TEST_LOCATION);
896 DALI_TEST_EQUALS(Vector2(5.0f, 8.0f), data.receivedGesture.displacement, 0.01f, TEST_LOCATION); // Actor relative
898 // Attach child and generate same touch points to yield a different displacement
899 // (Also proves that you can detach and then re-attach another actor)
900 detector.Attach(child);
901 detector.Detach(parent);
903 // Do an entire pan, only check finished value
904 application.ProcessEvent(GeneratePan(Gesture::Possible, Vector2(11.0f, 12.0f), Vector2(22.0f, 12.0f), 10));
905 application.ProcessEvent(GeneratePan(Gesture::Started, Vector2(11.0f, 12.0f), Vector2(22.0f, 12.0f), 10));
907 application.ProcessEvent(GeneratePan(Gesture::Finished, Vector2(22.0f, 12.0f), Vector2(27.0f, 20.0f), 10));
908 DALI_TEST_EQUALS(true, data.functorCalled, TEST_LOCATION);
909 DALI_TEST_EQUALS(true, child == data.pannedActor, TEST_LOCATION);
910 DALI_TEST_EQUALS(Vector2(8.0f, -5.0f), data.receivedGesture.displacement, 0.01f, TEST_LOCATION); // Actor relative
913 static void UtcDaliPanGestureSignalReceptionAttachDetachMany()
915 TestApplication application;
917 Actor first = Actor::New();
918 first.SetSize(100.0f, 100.0f);
919 first.SetAnchorPoint(AnchorPoint::TOP_LEFT);
920 Stage::GetCurrent().Add(first);
922 Actor second = Actor::New();
923 second.SetSize(100.0f, 100.0f);
925 second.SetAnchorPoint(AnchorPoint::TOP_LEFT);
926 Stage::GetCurrent().Add(second);
929 application.SendNotification();
930 application.Render();
933 GestureReceivedFunctor functor(data);
935 PanGestureDetector detector = PanGestureDetector::New();
936 detector.Attach(first);
937 detector.Attach(second);
938 detector.DetectedSignal().Connect(&application, functor);
940 // Start pan within second actor's area
941 application.ProcessEvent(GeneratePan(Gesture::Possible, Vector2(110.0f, 20.0f), Vector2(120.0f, 20.0f), 10));
942 application.ProcessEvent(GeneratePan(Gesture::Started, Vector2(110.0f, 20.0f), Vector2(120.0f, 20.0f), 10));
943 DALI_TEST_EQUALS(true, data.functorCalled, TEST_LOCATION);
944 DALI_TEST_EQUALS(true, second == data.pannedActor, TEST_LOCATION);
946 // Pan moves into first actor's area - second actor should receive the pan
948 application.ProcessEvent(GeneratePan(Gesture::Continuing, Vector2(120.0f, 20.0f), Vector2(20.0f, 10.0f), 10));
949 DALI_TEST_EQUALS(true, data.functorCalled, TEST_LOCATION);
950 DALI_TEST_EQUALS(true, second == data.pannedActor, TEST_LOCATION);
952 // Detach the second actor during the pan, we should not receive the next event
953 detector.Detach(second);
955 // Gesture ends within actor's area
957 application.ProcessEvent(GeneratePan(Gesture::Finished, Vector2(20.0f, 10.0f), Vector2(10.0f, 10.0f), 10));
958 DALI_TEST_EQUALS(false, data.functorCalled, TEST_LOCATION);
961 static void UtcDaliPanGestureSignalReceptionActorBecomesUntouchable()
963 TestApplication application;
965 Actor actor = Actor::New();
966 actor.SetSize(100.0f, 100.0f);
967 actor.SetAnchorPoint(AnchorPoint::TOP_LEFT);
968 Stage::GetCurrent().Add(actor);
971 application.SendNotification();
972 application.Render();
975 GestureReceivedFunctor functor(data);
977 PanGestureDetector detector = PanGestureDetector::New();
978 detector.Attach(actor);
979 detector.DetectedSignal().Connect(&application, functor);
981 // Start pan in actor's area
982 application.ProcessEvent(GeneratePan(Gesture::Possible, Vector2(10.0f, 20.0f), Vector2(20.0f, 20.0f), 10));
983 application.ProcessEvent(GeneratePan(Gesture::Started, Vector2(10.0f, 20.0f), Vector2(20.0f, 20.0f), 10));
984 DALI_TEST_EQUALS(true, data.functorCalled, TEST_LOCATION);
986 // Pan continues within actor's area
988 application.ProcessEvent(GeneratePan(Gesture::Continuing, Vector2(20.0f, 20.0f), Vector2(20.0f, 10.0f), 10));
989 DALI_TEST_EQUALS(true, data.functorCalled, TEST_LOCATION);
991 // Actor become invisible - actor should not receive the next pan
992 actor.SetVisible(false);
995 application.SendNotification();
996 application.Render();
998 // Gesture ends within actor's area
1000 application.ProcessEvent(GeneratePan(Gesture::Finished, Vector2(20.0f, 10.0f), Vector2(10.0f, 10.0f), 10));
1001 DALI_TEST_EQUALS(false, data.functorCalled, TEST_LOCATION);
1004 static void UtcDaliPanGestureSignalReceptionMultipleGestureDetectors()
1006 TestApplication application;
1007 Dali::TestGestureManager& gestureManager = application.GetGestureManager();
1009 Actor first = Actor::New();
1010 first.SetSize(100.0f, 100.0f);
1011 first.SetAnchorPoint(AnchorPoint::TOP_LEFT);
1012 Stage::GetCurrent().Add(first);
1014 Actor second = Actor::New();
1015 second.SetSize(100.0f, 100.0f);
1016 second.SetAnchorPoint(AnchorPoint::TOP_LEFT);
1019 // Render and notify
1020 application.SendNotification();
1021 application.Render();
1024 GestureReceivedFunctor functor(data);
1026 PanGestureDetector firstDetector = PanGestureDetector::New();
1027 firstDetector.Attach(first);
1028 firstDetector.DetectedSignal().Connect(&application, functor);
1030 // secondDetector is scoped
1032 // Reset gestureManager statistics
1033 gestureManager.Initialize();
1035 PanGestureDetector secondDetector = PanGestureDetector::New();
1036 secondDetector.SetMinimumTouchesRequired(2);
1037 secondDetector.SetMaximumTouchesRequired(2);
1038 secondDetector.Attach(second);
1039 secondDetector.DetectedSignal().Connect(&application, functor);
1041 DALI_TEST_EQUALS(true, gestureManager.WasCalled(TestGestureManager::UpdateType), TEST_LOCATION);
1042 DALI_TEST_EQUALS(false, gestureManager.WasCalled(TestGestureManager::RegisterType), TEST_LOCATION);
1043 DALI_TEST_EQUALS(false, gestureManager.WasCalled(TestGestureManager::UnregisterType), TEST_LOCATION);
1045 // Start pan within second actor's area
1046 application.ProcessEvent(GeneratePan(Gesture::Possible, Vector2(10.0f, 20.0f), Vector2(20.0f, 20.0f), 10, 2));
1047 application.ProcessEvent(GeneratePan(Gesture::Started, Vector2(10.0f, 20.0f), Vector2(20.0f, 20.0f), 10, 2));
1048 DALI_TEST_EQUALS(true, data.functorCalled, TEST_LOCATION);
1049 DALI_TEST_EQUALS(true, second == data.pannedActor, TEST_LOCATION);
1051 // Two touch pan changes to single touch - we should receive a finished state
1053 application.ProcessEvent(GeneratePan(Gesture::Continuing, Vector2(20.0f, 20.0f), Vector2(20.0f, 10.0f), 10));
1054 DALI_TEST_EQUALS(true, data.functorCalled, TEST_LOCATION);
1055 DALI_TEST_EQUALS(Gesture::Finished, data.receivedGesture.state, TEST_LOCATION);
1056 DALI_TEST_EQUALS(true, second == data.pannedActor, TEST_LOCATION);
1058 // Pan continues as single touch gesture - we should not receive any gesture
1060 application.ProcessEvent(GeneratePan(Gesture::Continuing, Vector2(20.0f, 10.0f), Vector2(30.0f, 10.0f), 10));
1061 DALI_TEST_EQUALS(false, data.functorCalled, TEST_LOCATION);
1063 // Pan ends - still no signal
1065 application.ProcessEvent(GeneratePan(Gesture::Finished, Vector2(30.0f, 10.0f), Vector2(30.0f, 20.0f), 10));
1066 DALI_TEST_EQUALS(false, data.functorCalled, TEST_LOCATION);
1068 // Single touch pan starts - first actor should be panned
1070 application.ProcessEvent(GeneratePan(Gesture::Possible, Vector2(10.0f, 20.0f), Vector2(20.0f, 20.0f), 10));
1071 application.ProcessEvent(GeneratePan(Gesture::Started, Vector2(10.0f, 20.0f), Vector2(20.0f, 20.0f), 10));
1072 DALI_TEST_EQUALS(true, data.functorCalled, TEST_LOCATION);
1073 DALI_TEST_EQUALS(true, first == data.pannedActor, TEST_LOCATION);
1075 // Pan changes to double-touch - we should receive a finished state
1077 application.ProcessEvent(GeneratePan(Gesture::Continuing, Vector2(20.0f, 20.0f), Vector2(20.0f, 10.0f), 10, 2));
1078 DALI_TEST_EQUALS(true, data.functorCalled, TEST_LOCATION);
1079 DALI_TEST_EQUALS(Gesture::Finished, data.receivedGesture.state, TEST_LOCATION);
1080 DALI_TEST_EQUALS(true, first == data.pannedActor, TEST_LOCATION);
1082 // Pan continues as double touch gesture - we should not receive any gesture
1084 application.ProcessEvent(GeneratePan(Gesture::Continuing, Vector2(20.0f, 10.0f), Vector2(30.0f, 10.0f), 10));
1085 DALI_TEST_EQUALS(false, data.functorCalled, TEST_LOCATION);
1087 // Pan ends - still no signal
1089 application.ProcessEvent(GeneratePan(Gesture::Finished, Vector2(30.0f, 10.0f), Vector2(30.0f, 20.0f), 10));
1090 DALI_TEST_EQUALS(false, data.functorCalled, TEST_LOCATION);
1092 // Reset gesture manager statistics
1093 gestureManager.Initialize();
1096 // secondDetector has now been deleted. Gesture detection should have been updated only
1097 DALI_TEST_EQUALS(true, gestureManager.WasCalled(TestGestureManager::UpdateType), TEST_LOCATION);
1098 DALI_TEST_EQUALS(false, gestureManager.WasCalled(TestGestureManager::RegisterType), TEST_LOCATION);
1099 DALI_TEST_EQUALS(false, gestureManager.WasCalled(TestGestureManager::UnregisterType), TEST_LOCATION);
1102 void UtcDaliPanGestureSignalReceptionMultipleDetectorsOnActor()
1104 TestApplication application;
1106 Actor actor = Actor::New();
1107 actor.SetSize(100.0f, 100.0f);
1108 actor.SetAnchorPoint(AnchorPoint::TOP_LEFT);
1109 Stage::GetCurrent().Add(actor);
1111 Actor actor2 = Actor::New();
1112 actor2.SetSize(100.0f, 100.0f);
1113 actor2.SetAnchorPoint(AnchorPoint::BOTTOM_RIGHT);
1114 Stage::GetCurrent().Add(actor2);
1116 // Render and notify
1117 application.SendNotification();
1118 application.Render();
1120 // Attach actor to one detector
1121 SignalData firstData;
1122 GestureReceivedFunctor firstFunctor(firstData);
1123 PanGestureDetector firstDetector = PanGestureDetector::New();
1124 firstDetector.Attach(actor);
1125 firstDetector.DetectedSignal().Connect(&application, firstFunctor);
1127 // Attach actor to another detector
1128 SignalData secondData;
1129 GestureReceivedFunctor secondFunctor(secondData);
1130 PanGestureDetector secondDetector = PanGestureDetector::New();
1131 secondDetector.Attach(actor);
1132 secondDetector.DetectedSignal().Connect(&application, secondFunctor);
1134 // Add second actor to second detector, when we remove the actor, this will make sure that this
1135 // gesture detector is not removed from the GestureDetectorProcessor. In this scenario, the
1136 // functor should still not be called (which is what we're also testing).
1137 secondDetector.Attach(actor2);
1139 // Pan in actor's area - both detector's functors should be called
1140 application.ProcessEvent(GeneratePan(Gesture::Possible, Vector2(10.0f, 20.0f), Vector2(20.0f, 20.0f), 10));
1141 application.ProcessEvent(GeneratePan(Gesture::Started, Vector2(10.0f, 20.0f), Vector2(20.0f, 20.0f), 10));
1142 DALI_TEST_EQUALS(true, firstData.functorCalled, TEST_LOCATION);
1143 DALI_TEST_EQUALS(true, secondData.functorCalled, TEST_LOCATION);
1145 // Pan continues in actor's area - both detector's functors should be called
1148 application.ProcessEvent(GeneratePan(Gesture::Continuing, Vector2(20.0f, 20.0f), Vector2(10.0f, 20.0f), 10));
1149 DALI_TEST_EQUALS(true, firstData.functorCalled, TEST_LOCATION);
1150 DALI_TEST_EQUALS(true, secondData.functorCalled, TEST_LOCATION);
1152 // Detach actor from firstDetector and emit pan on actor, only secondDetector's functor should be called.
1153 firstDetector.Detach(actor);
1156 application.ProcessEvent(GeneratePan(Gesture::Finished, Vector2(20.0f, 20.0f), Vector2(10.0f, 20.0f), 10));
1157 DALI_TEST_EQUALS(false, firstData.functorCalled, TEST_LOCATION);
1158 DALI_TEST_EQUALS(true, secondData.functorCalled, TEST_LOCATION);
1160 // New pan on actor, only secondDetector has actor attached
1163 application.ProcessEvent(GeneratePan(Gesture::Possible, Vector2(10.0f, 20.0f), Vector2(20.0f, 20.0f), 10));
1164 application.ProcessEvent(GeneratePan(Gesture::Started, Vector2(10.0f, 20.0f), Vector2(20.0f, 20.0f), 10));
1165 DALI_TEST_EQUALS(false, firstData.functorCalled, TEST_LOCATION);
1166 DALI_TEST_EQUALS(true, secondData.functorCalled, TEST_LOCATION);
1168 // Detach actor from secondDetector
1169 secondDetector.Detach(actor);
1172 application.ProcessEvent(GeneratePan(Gesture::Continuing, Vector2(20.0f, 20.0f), Vector2(10.0f, 20.0f), 10));
1173 DALI_TEST_EQUALS(false, firstData.functorCalled, TEST_LOCATION);
1174 DALI_TEST_EQUALS(false, secondData.functorCalled, TEST_LOCATION);
1177 void UtcDaliPanGestureSignalReceptionMultipleStarted()
1179 // Should handle two started events gracefully.
1181 TestApplication application;
1183 Actor actor = Actor::New();
1184 actor.SetSize(100.0f, 100.0f);
1185 actor.SetAnchorPoint(AnchorPoint::TOP_LEFT);
1186 Stage::GetCurrent().Add(actor);
1189 GestureReceivedFunctor functor(data);
1191 PanGestureDetector detector = PanGestureDetector::New();
1192 detector.Attach(actor);
1193 detector.DetectedSignal().Connect(&application, functor);
1195 // Render and notify
1196 application.SendNotification();
1197 application.Render();
1199 // Start pan in actor's area
1200 application.ProcessEvent(GeneratePan(Gesture::Possible, Vector2(10.0f, 20.0f), Vector2(20.0f, 20.0f), 10));
1201 application.ProcessEvent(GeneratePan(Gesture::Started, Vector2(10.0f, 20.0f), Vector2(20.0f, 20.0f), 10));
1202 DALI_TEST_EQUALS(true, data.functorCalled, TEST_LOCATION);
1204 // Send another start in actor's area
1206 application.ProcessEvent(GeneratePan(Gesture::Started, Vector2(10.0f, 20.0f), Vector2(20.0f, 20.0f), 10));
1207 DALI_TEST_EQUALS(true, data.functorCalled, TEST_LOCATION);
1209 // Add a child actor to overlap actor and send another start in actor's area
1210 Actor child = Actor::New();
1211 child.SetSize(100.0f, 100.0f);
1212 child.SetAnchorPoint(AnchorPoint::CENTER);
1213 child.SetParentOrigin(ParentOrigin::CENTER);
1216 TouchEventFunctor touchFunctor;
1217 child.TouchedSignal().Connect(&application, touchFunctor);
1219 // Render and notify
1220 application.SendNotification();
1221 application.Render();
1223 // Send another possible and start in actor's area
1225 application.ProcessEvent(GeneratePan(Gesture::Possible, Vector2(10.0f, 20.0f), Vector2(20.0f, 20.0f), 10));
1226 application.ProcessEvent(GeneratePan(Gesture::Started, Vector2(10.0f, 20.0f), Vector2(20.0f, 20.0f), 10));
1227 DALI_TEST_EQUALS(true, data.functorCalled, TEST_LOCATION);
1229 // Send another start in actor's area
1231 application.ProcessEvent(GeneratePan(Gesture::Possible, Vector2(10.0f, 20.0f), Vector2(20.0f, 20.0f), 10));
1232 application.ProcessEvent(GeneratePan(Gesture::Started, Vector2(10.0f, 20.0f), Vector2(20.0f, 20.0f), 10));
1233 DALI_TEST_EQUALS(true, data.functorCalled, TEST_LOCATION);
1236 void UtcDaliPanGestureSignalReceptionEnsureCorrectSignalling()
1238 TestApplication application;
1240 Actor actor1 = Actor::New();
1241 actor1.SetSize(100.0f, 100.0f);
1242 actor1.SetAnchorPoint(AnchorPoint::TOP_LEFT);
1243 Stage::GetCurrent().Add(actor1);
1245 GestureReceivedFunctor functor1(data1);
1246 PanGestureDetector detector1 = PanGestureDetector::New();
1247 detector1.Attach(actor1);
1248 detector1.DetectedSignal().Connect(&application, functor1);
1250 Actor actor2 = Actor::New();
1251 actor2.SetSize(100.0f, 100.0f);
1252 actor2.SetAnchorPoint(AnchorPoint::BOTTOM_RIGHT);
1253 actor2.SetParentOrigin(ParentOrigin::BOTTOM_RIGHT);
1254 Stage::GetCurrent().Add(actor2);
1256 GestureReceivedFunctor functor2(data2);
1257 PanGestureDetector detector2 = PanGestureDetector::New();
1258 detector2.Attach(actor2);
1259 detector2.DetectedSignal().Connect(&application, functor2);
1261 // Render and notify
1262 application.SendNotification();
1263 application.Render();
1265 // Start pan in actor1's area, only data1 should be set
1266 application.ProcessEvent(GeneratePan(Gesture::Possible, Vector2(10.0f, 20.0f), Vector2(20.0f, 20.0f), 10));
1267 application.ProcessEvent(GeneratePan(Gesture::Started, Vector2(10.0f, 20.0f), Vector2(20.0f, 20.0f), 10));
1268 DALI_TEST_EQUALS(true, data1.functorCalled, TEST_LOCATION);
1269 DALI_TEST_EQUALS(false, data2.functorCalled, TEST_LOCATION);
1272 void UtcDaliPanGestureSignalReceptionDifferentPossible()
1274 TestApplication application;
1276 Actor actor = Actor::New();
1277 actor.SetSize(100.0f, 100.0f);
1278 actor.SetAnchorPoint(AnchorPoint::TOP_LEFT);
1279 Stage::GetCurrent().Add(actor);
1281 // Render and notify
1282 application.SendNotification();
1283 application.Render();
1285 // Attach actor to detector
1287 GestureReceivedFunctor functor( data );
1288 PanGestureDetector detector = PanGestureDetector::New();
1289 detector.Attach(actor);
1290 detector.DetectedSignal().Connect( &application, functor );
1292 // Gesture possible in actor's area.
1293 application.ProcessEvent(GeneratePan(Gesture::Possible, Vector2(10.0f, 20.0f), Vector2(20.0f, 20.0f), 10));
1294 DALI_TEST_EQUALS(false, data.functorCalled, TEST_LOCATION);
1296 // Move actor somewhere else
1297 actor.SetPosition( 100.0f, 100.0f );
1299 // Render and notify
1300 application.SendNotification();
1301 application.Render();
1303 // Emit Started event, we should not receive the long press.
1304 application.ProcessEvent(GeneratePan(Gesture::Started, Vector2(10.0f, 20.0f), Vector2(20.0f, 20.0f), 10));
1305 application.ProcessEvent(GeneratePan(Gesture::Finished, Vector2(10.0f, 20.0f), Vector2(20.0f, 20.0f), 10));
1306 DALI_TEST_EQUALS(false, data.functorCalled, TEST_LOCATION);
1308 // LongPress possible in empty area.
1309 application.ProcessEvent(GeneratePan(Gesture::Possible, Vector2(10.0f, 20.0f), Vector2(20.0f, 20.0f), 10));
1310 DALI_TEST_EQUALS(false, data.functorCalled, TEST_LOCATION);
1312 // Move actor in to the long press position.
1313 actor.SetPosition( 0.0f, 0.0f );
1315 // Render and notify
1316 application.SendNotification();
1317 application.Render();
1319 // Emit Started event, we should not receive the long press.
1320 application.ProcessEvent(GeneratePan(Gesture::Started, Vector2(10.0f, 20.0f), Vector2(20.0f, 20.0f), 10));
1321 application.ProcessEvent(GeneratePan(Gesture::Finished, Vector2(10.0f, 20.0f), Vector2(20.0f, 20.0f), 10));
1322 DALI_TEST_EQUALS(false, data.functorCalled, TEST_LOCATION);
1324 // Normal long press in actor's area for completeness.
1325 application.ProcessEvent(GeneratePan(Gesture::Possible, Vector2(10.0f, 20.0f), Vector2(20.0f, 20.0f), 10));
1326 application.ProcessEvent(GeneratePan(Gesture::Started, Vector2(10.0f, 20.0f), Vector2(20.0f, 20.0f), 10));
1327 application.ProcessEvent(GeneratePan(Gesture::Finished, Vector2(10.0f, 20.0f), Vector2(20.0f, 20.0f), 10));
1328 DALI_TEST_EQUALS(true, data.functorCalled, TEST_LOCATION);
1331 void UtcDaliPanGestureEmitIncorrectState()
1333 TestApplication application;
1335 Actor actor = Actor::New();
1336 actor.SetSize(100.0f, 100.0f);
1337 actor.SetAnchorPoint(AnchorPoint::TOP_LEFT);
1338 Stage::GetCurrent().Add(actor);
1340 // Render and notify
1341 application.SendNotification();
1342 application.Render();
1344 // Attach actor to detector
1346 GestureReceivedFunctor functor( data );
1347 PanGestureDetector detector = PanGestureDetector::New();
1348 detector.Attach(actor);
1349 detector.DetectedSignal().Connect( &application, functor );
1351 // Try a Clear state
1354 application.ProcessEvent(GeneratePan(Gesture::Clear, Vector2(10.0f, 20.0f), Vector2(20.0f, 20.0f), 10));
1355 tet_result(TET_FAIL);
1357 catch ( Dali::DaliException& e )
1359 DALI_TEST_ASSERT( e, "false", TEST_LOCATION );
1363 void UtcDaliPanGestureDetectorTypeRegistry()
1365 TestApplication application;
1367 Actor actor = Actor::New();
1368 actor.SetSize(100.0f, 100.0f);
1369 actor.SetAnchorPoint(AnchorPoint::TOP_LEFT);
1370 Stage::GetCurrent().Add(actor);
1374 type = TypeRegistry::Get().GetTypeInfo( "PanGestureDetector" );
1375 DALI_TEST_CHECK( type );
1376 BaseHandle handle = type.CreateInstance();
1377 DALI_TEST_CHECK( handle );
1378 PanGestureDetector detector = PanGestureDetector::DownCast( handle );
1379 DALI_TEST_CHECK( detector );
1381 // Attach actor to detector
1383 GestureReceivedFunctor functor( data );
1384 detector.Attach(actor);
1386 // Connect to signal through type
1387 handle.ConnectSignal( &application, PanGestureDetector::SIGNAL_PAN_DETECTED, functor );
1389 // Render and notify
1390 application.SendNotification();
1391 application.Render();
1394 application.ProcessEvent(GeneratePan(Gesture::Possible, Vector2(10.0f, 20.0f), Vector2(20.0f, 20.0f), 10));
1395 application.ProcessEvent(GeneratePan(Gesture::Started, Vector2(10.0f, 20.0f), Vector2(20.0f, 20.0f), 10));
1396 application.ProcessEvent(GeneratePan(Gesture::Finished, Vector2(10.0f, 20.0f), Vector2(20.0f, 20.0f), 10));
1397 DALI_TEST_EQUALS(true, data.voidFunctorCalled, TEST_LOCATION);
1400 void UtcDaliPanGestureActorUnstaged()
1402 TestApplication application;
1404 Actor actor = Actor::New();
1405 actor.SetSize(100.0f, 100.0f);
1406 actor.SetAnchorPoint(AnchorPoint::TOP_LEFT);
1407 Stage::GetCurrent().Add(actor);
1409 // Render and notify
1410 application.SendNotification();
1411 application.Render();
1413 // State to remove actor in.
1414 Gesture::State stateToUnstage( Gesture::Started );
1416 // Attach actor to detector
1418 UnstageActorFunctor functor( data, stateToUnstage );
1419 PanGestureDetector detector = PanGestureDetector::New();
1420 detector.Attach(actor);
1421 detector.DetectedSignal().Connect( &application, functor );
1424 application.ProcessEvent(GeneratePan(Gesture::Possible, Vector2(10.0f, 20.0f), Vector2(20.0f, 20.0f), 10));
1425 application.ProcessEvent(GeneratePan(Gesture::Started, Vector2(10.0f, 20.0f), Vector2(20.0f, 20.0f), 10));
1426 DALI_TEST_EQUALS(true, data.functorCalled, TEST_LOCATION);
1428 application.ProcessEvent(GeneratePan(Gesture::Finished, Vector2(10.0f, 20.0f), Vector2(20.0f, 20.0f), 10));
1429 DALI_TEST_EQUALS(false, data.functorCalled, TEST_LOCATION);
1432 // Render and notify
1433 application.SendNotification();
1434 application.Render();
1436 // Re-add actor to stage
1437 Stage::GetCurrent().Add(actor);
1439 // Render and notify
1440 application.SendNotification();
1441 application.Render();
1443 // Change state to Gesture::Continuing to remove
1444 stateToUnstage = Gesture::Continuing;
1447 application.ProcessEvent(GeneratePan(Gesture::Possible, Vector2(10.0f, 20.0f), Vector2(20.0f, 20.0f), 10));
1448 application.ProcessEvent(GeneratePan(Gesture::Started, Vector2(10.0f, 20.0f), Vector2(20.0f, 20.0f), 10));
1449 DALI_TEST_EQUALS(true, data.functorCalled, TEST_LOCATION);
1451 application.ProcessEvent(GeneratePan(Gesture::Continuing, Vector2(10.0f, 20.0f), Vector2(20.0f, 20.0f), 10));
1452 DALI_TEST_EQUALS(true, data.functorCalled, TEST_LOCATION);
1454 application.ProcessEvent(GeneratePan(Gesture::Finished, Vector2(10.0f, 20.0f), Vector2(20.0f, 20.0f), 10));
1455 DALI_TEST_EQUALS(false, data.functorCalled, TEST_LOCATION);
1458 // Render and notify
1459 application.SendNotification();
1460 application.Render();
1462 // Re-add actor to stage
1463 Stage::GetCurrent().Add(actor);
1465 // Render and notify
1466 application.SendNotification();
1467 application.Render();
1469 // Change state to Gesture::Finished to remove
1470 stateToUnstage = Gesture::Finished;
1473 application.ProcessEvent(GeneratePan(Gesture::Possible, Vector2(10.0f, 20.0f), Vector2(20.0f, 20.0f), 10));
1474 application.ProcessEvent(GeneratePan(Gesture::Started, Vector2(10.0f, 20.0f), Vector2(20.0f, 20.0f), 10));
1475 DALI_TEST_EQUALS(true, data.functorCalled, TEST_LOCATION);
1477 application.ProcessEvent(GeneratePan(Gesture::Continuing, Vector2(10.0f, 20.0f), Vector2(20.0f, 20.0f), 10));
1478 DALI_TEST_EQUALS(true, data.functorCalled, TEST_LOCATION);
1480 application.ProcessEvent(GeneratePan(Gesture::Finished, Vector2(10.0f, 20.0f), Vector2(20.0f, 20.0f), 10));
1481 DALI_TEST_EQUALS(true, data.functorCalled, TEST_LOCATION);
1482 tet_result( TET_PASS ); // If we get here then we have handled actor stage removal gracefully.
1485 void UtcDaliPanGestureActorStagedAndDestroyed()
1487 TestApplication application;
1489 Actor actor = Actor::New();
1490 actor.SetSize(100.0f, 100.0f);
1491 actor.SetAnchorPoint(AnchorPoint::TOP_LEFT);
1492 Stage::GetCurrent().Add(actor);
1494 // Create and add a second actor so that GestureDetector destruction does not come into play.
1495 Actor dummyActor( Actor::New() );
1496 dummyActor.SetSize( 100.0f, 100.0f );
1497 dummyActor.SetPosition( 100.0f, 100.0f );
1498 dummyActor.SetAnchorPoint(AnchorPoint::TOP_LEFT);
1499 Stage::GetCurrent().Add(dummyActor);
1501 // Render and notify
1502 application.SendNotification();
1503 application.Render();
1505 // State to remove actor in.
1506 Gesture::State stateToUnstage( Gesture::Started );
1508 // Attach actor to detector
1510 UnstageActorFunctor functor( data, stateToUnstage );
1511 PanGestureDetector detector = PanGestureDetector::New();
1512 detector.Attach(actor);
1513 detector.Attach(dummyActor);
1514 detector.DetectedSignal().Connect( &application, functor );
1516 // Here we are testing a Started actor which is removed in the Started callback, but then added back
1517 // before we get a continuing state. As we were removed from the stage, even if we're at the same
1518 // position, we should still not be signalled.
1521 application.ProcessEvent(GeneratePan(Gesture::Possible, Vector2(10.0f, 20.0f), Vector2(20.0f, 20.0f), 10));
1522 application.ProcessEvent(GeneratePan(Gesture::Started, Vector2(10.0f, 20.0f), Vector2(20.0f, 20.0f), 10));
1523 DALI_TEST_EQUALS(true, data.functorCalled, TEST_LOCATION);
1526 // Render and notify
1527 application.SendNotification();
1528 application.Render();
1530 // Re add to the stage, we should not be signalled
1531 Stage::GetCurrent().Add(actor);
1533 // Render and notify
1534 application.SendNotification();
1535 application.Render();
1537 // Continue signal emission
1538 application.ProcessEvent(GeneratePan(Gesture::Continuing, Vector2(10.0f, 20.0f), Vector2(20.0f, 20.0f), 10));
1539 DALI_TEST_EQUALS(false, data.functorCalled, TEST_LOCATION);
1541 application.ProcessEvent(GeneratePan(Gesture::Finished, Vector2(10.0f, 20.0f), Vector2(20.0f, 20.0f), 10));
1542 DALI_TEST_EQUALS(false, data.functorCalled, TEST_LOCATION);
1545 // Here we delete an actor in started, we should not receive any subsequent signalling.
1548 application.ProcessEvent(GeneratePan(Gesture::Possible, Vector2(10.0f, 20.0f), Vector2(20.0f, 20.0f), 10));
1549 application.ProcessEvent(GeneratePan(Gesture::Started, Vector2(10.0f, 20.0f), Vector2(20.0f, 20.0f), 10));
1550 DALI_TEST_EQUALS(true, data.functorCalled, TEST_LOCATION);
1553 // Render and notify
1554 application.SendNotification();
1555 application.Render();
1557 // Delete actor as well
1560 // Render and notify
1561 application.SendNotification();
1562 application.Render();
1564 // Continue signal emission
1565 application.ProcessEvent(GeneratePan(Gesture::Continuing, Vector2(10.0f, 20.0f), Vector2(20.0f, 20.0f), 10));
1566 DALI_TEST_EQUALS(false, data.functorCalled, TEST_LOCATION);
1568 application.ProcessEvent(GeneratePan(Gesture::Finished, Vector2(10.0f, 20.0f), Vector2(20.0f, 20.0f), 10));
1569 DALI_TEST_EQUALS(false, data.functorCalled, TEST_LOCATION);
1572 void UtcDaliPanGestureSystemOverlay()
1574 TestApplication application;
1575 Dali::Integration::SystemOverlay& systemOverlay( application.GetCore().GetSystemOverlay() );
1576 systemOverlay.GetOverlayRenderTasks().CreateTask();
1578 Actor actor = Actor::New();
1579 actor.SetSize(100.0f, 100.0f);
1580 actor.SetAnchorPoint(AnchorPoint::TOP_LEFT);
1581 systemOverlay.Add(actor);
1583 // Render and notify
1584 application.SendNotification();
1585 application.Render();
1588 GestureReceivedFunctor functor(data);
1590 PanGestureDetector detector = PanGestureDetector::New();
1591 detector.Attach(actor);
1592 detector.DetectedSignal().Connect(&application, functor);
1594 Vector2 screenCoordsStart( 10.0f, 20.0f );
1595 Vector2 screenCoordsEnd( 20.0f, 20.0f );
1597 // Start pan within the actor's area
1598 application.ProcessEvent( GeneratePan( Gesture::Possible, screenCoordsStart, screenCoordsEnd, 10 ) );
1599 application.ProcessEvent( GeneratePan( Gesture::Started, screenCoordsStart, screenCoordsEnd, 10 ) );
1600 DALI_TEST_EQUALS( false, data.functorCalled, TEST_LOCATION );
1603 void UtcDaliPanGestureAngleHandling()
1605 TestApplication application;
1607 PanGestureDetector detector = PanGestureDetector::New();
1608 const PanGestureDetector::AngleContainer& angles( detector.GetAngles() );
1609 DALI_TEST_EQUALS( angles.empty(), true, TEST_LOCATION );
1611 detector.AddAngle( PanGestureDetector::DIRECTION_LEFT, Radian( Math::PI * 0.25 ) );
1612 DALI_TEST_EQUALS( angles.size(), static_cast<AngleSizeType>(1), TEST_LOCATION );
1613 for ( PanGestureDetector::AngleContainer::const_iterator iter = angles.begin(), endIter = angles.end(); iter != endIter; ++iter )
1615 if ( iter->first == PanGestureDetector::DIRECTION_LEFT )
1617 tet_result( TET_PASS );
1621 if ( iter == endIter )
1623 tet_printf("%s, angle not added\n", TEST_LOCATION );
1624 tet_result( TET_FAIL );
1628 detector.AddAngle( PanGestureDetector::DIRECTION_RIGHT, Radian( Math::PI * 0.25 ) );
1629 DALI_TEST_EQUALS( angles.size(), static_cast<AngleSizeType>(2), TEST_LOCATION );
1631 // Remove something not in the container.
1632 detector.RemoveAngle( PanGestureDetector::DIRECTION_UP );
1633 DALI_TEST_EQUALS( angles.size(), static_cast<AngleSizeType>(2), TEST_LOCATION );
1635 detector.RemoveAngle( PanGestureDetector::DIRECTION_RIGHT );
1636 DALI_TEST_EQUALS( angles.size(), static_cast<AngleSizeType>(1), TEST_LOCATION );
1637 for ( PanGestureDetector::AngleContainer::const_iterator iter = angles.begin(), endIter = angles.end(); iter != endIter; ++iter )
1639 if ( iter->first == PanGestureDetector::DIRECTION_RIGHT )
1641 tet_printf("%s, angle not removed\n", TEST_LOCATION );
1642 tet_result( TET_FAIL );
1647 detector.ClearAngles();
1648 DALI_TEST_EQUALS( angles.size(), static_cast<AngleSizeType>(0), TEST_LOCATION );
1651 inline float RadiansToDegrees( float radian )
1653 return radian * 180.0f / Math::PI;
1656 void UtcDaliPanGestureAngleOutOfRange()
1658 TestApplication application;
1660 PanGestureDetector detector = PanGestureDetector::New();
1661 const PanGestureDetector::AngleContainer& angles( detector.GetAngles() );
1662 DALI_TEST_EQUALS( angles.empty(), true, TEST_LOCATION );
1668 detector.AddAngle( Degree(180.0f) );
1669 DALI_TEST_EQUALS( angles.begin()->first, Radian( Degree(-180.0f) ), 0.000001, TEST_LOCATION );
1670 detector.ClearAngles();
1672 detector.AddAngle( Degree(190.0f) );
1673 DALI_TEST_EQUALS( angles.begin()->first, Radian( Degree(-170.0f) ), 0.000001, TEST_LOCATION );
1674 detector.ClearAngles();
1676 detector.AddAngle( Degree(-190.0f) );
1677 DALI_TEST_EQUALS( angles.begin()->first, Radian( Degree(170.0f) ), 0.000001, TEST_LOCATION );
1678 detector.ClearAngles();
1680 detector.AddAngle( Degree(350.0f) );
1681 DALI_TEST_EQUALS( angles.begin()->first, Radian( Degree(-10.0f) ), 0.000001, TEST_LOCATION );
1682 detector.ClearAngles();
1684 detector.AddAngle( Degree(-350.0f) );
1685 DALI_TEST_EQUALS( angles.begin()->first, Radian( Degree(10.0f) ), 0.000001, TEST_LOCATION );
1686 detector.ClearAngles();
1688 detector.AddAngle( Degree(370.0f) );
1689 DALI_TEST_EQUALS( angles.begin()->first, Radian( Degree(10.0f) ), 0.000001, TEST_LOCATION );
1690 detector.ClearAngles();
1692 detector.AddAngle( Degree(-370.0f) );
1693 DALI_TEST_EQUALS( angles.begin()->first, Radian( Degree(-10.0f) ), 0.000001, TEST_LOCATION );
1694 detector.ClearAngles();
1700 detector.AddAngle( PanGestureDetector::DIRECTION_RIGHT, Degree( 0.0f ) );
1701 DALI_TEST_EQUALS( angles.begin()->second, Radian( Degree(0.0f) ), 0.000001, TEST_LOCATION );
1702 detector.ClearAngles();
1704 detector.AddAngle( PanGestureDetector::DIRECTION_RIGHT, Degree( -10.0f ) );
1705 DALI_TEST_EQUALS( angles.begin()->second, Radian( Degree(10.0f) ), 0.000001, TEST_LOCATION );
1706 detector.ClearAngles();
1708 detector.AddAngle( PanGestureDetector::DIRECTION_RIGHT, Degree( -181.0f ) );
1709 DALI_TEST_EQUALS( angles.begin()->second, Radian( Degree(180.0f) ), 0.000001, TEST_LOCATION );
1710 detector.ClearAngles();
1712 detector.AddAngle( PanGestureDetector::DIRECTION_RIGHT, Degree( 181.0f ) );
1713 DALI_TEST_EQUALS( angles.begin()->second, Radian( Degree(180.0f) ), 0.000001, TEST_LOCATION );
1714 detector.ClearAngles();
1717 void UtcDaliPanGestureAngleProcessing()
1719 TestApplication application;
1721 Actor parent = Actor::New();
1722 parent.SetSize(100.0f, 100.0f);
1723 parent.SetAnchorPoint(AnchorPoint::TOP_LEFT);
1724 Stage::GetCurrent().Add(parent);
1726 Actor child = Actor::New();
1727 child.SetSize(100.0f, 100.0f);
1728 child.SetAnchorPoint(AnchorPoint::TOP_LEFT);
1731 // Render and notify
1732 application.SendNotification();
1733 application.Render();
1735 // Parent detector only requires up pans
1736 PanGestureDetector parentDetector = PanGestureDetector::New();
1737 parentDetector.Attach( parent );
1738 parentDetector.AddAngle( PanGestureDetector::DIRECTION_UP, Degree( 30.0f ) );
1739 SignalData parentData;
1740 GestureReceivedFunctor parentFunctor(parentData);
1741 parentDetector.DetectedSignal().Connect(&application, parentFunctor);
1743 // Child detector only requires right pans
1744 PanGestureDetector childDetector = PanGestureDetector::New();
1745 childDetector.Attach( child );
1746 childDetector.AddAngle( PanGestureDetector::DIRECTION_RIGHT, Degree( 30.0f ) );
1747 SignalData childData;
1748 GestureReceivedFunctor childFunctor(childData);
1749 childDetector.DetectedSignal().Connect(&application, childFunctor);
1751 // Generate an Up pan gesture, only parent should receive it.
1752 application.ProcessEvent( GeneratePan( Gesture::Possible, Vector2(20.0f, 20.0f), Vector2(20.0f, 20.0f), 10 ) );
1753 application.ProcessEvent( GeneratePan( Gesture::Started, Vector2(20.0f, 20.0f), Vector2(20.0f, 10.0f), 10 ) );
1754 DALI_TEST_EQUALS( true, parentData.functorCalled, TEST_LOCATION );
1755 DALI_TEST_EQUALS( false, childData.functorCalled, TEST_LOCATION );
1756 application.ProcessEvent( GeneratePan( Gesture::Finished, Vector2(20.0f, 30.0f), Vector2(20.0f, 20.0f), 10 ) );
1760 // Generate a Right pan gesture, only child should receive it.
1761 application.ProcessEvent( GeneratePan( Gesture::Possible, Vector2(20.0f, 20.0f), Vector2(20.0f, 20.0f), 10 ) );
1762 application.ProcessEvent( GeneratePan( Gesture::Started, Vector2(20.0f, 20.0f), Vector2(30.0f, 20.0f), 10 ) );
1763 DALI_TEST_EQUALS( false, parentData.functorCalled, TEST_LOCATION );
1764 DALI_TEST_EQUALS( true, childData.functorCalled, TEST_LOCATION );
1765 application.ProcessEvent( GeneratePan( Gesture::Finished, Vector2(20.0f, 30.0f), Vector2(20.0f, 20.0f), 10 ) );
1769 // Generate a Down pan gesture, no one should receive it.
1770 application.ProcessEvent( GeneratePan( Gesture::Possible, Vector2(20.0f, 20.0f), Vector2(20.0f, 20.0f), 10 ) );
1771 application.ProcessEvent( GeneratePan( Gesture::Started, Vector2(20.0f, 20.0f), Vector2(20.0f, 30.0f), 10 ) );
1772 DALI_TEST_EQUALS( false, parentData.functorCalled, TEST_LOCATION );
1773 DALI_TEST_EQUALS( false, childData.functorCalled, TEST_LOCATION );
1774 application.ProcessEvent( GeneratePan( Gesture::Finished, Vector2(20.0f, 30.0f), Vector2(20.0f, 20.0f), 10 ) );
1778 // Generate a Left pan gesture, no one should receive it.
1779 application.ProcessEvent( GeneratePan( Gesture::Possible, Vector2(20.0f, 20.0f), Vector2(20.0f, 20.0f), 10 ) );
1780 application.ProcessEvent( GeneratePan( Gesture::Started, Vector2(20.0f, 20.0f), Vector2(10.0f, 20.0f), 10 ) );
1781 DALI_TEST_EQUALS( false, parentData.functorCalled, TEST_LOCATION );
1782 DALI_TEST_EQUALS( false, childData.functorCalled, TEST_LOCATION );
1783 application.ProcessEvent( GeneratePan( Gesture::Finished, Vector2(20.0f, 30.0f), Vector2(20.0f, 20.0f), 10 ) );
1788 void UtcDaliPanGestureDirectionHandling()
1790 TestApplication application;
1792 PanGestureDetector detector = PanGestureDetector::New();
1793 const PanGestureDetector::AngleContainer& angles( detector.GetAngles() );
1794 DALI_TEST_EQUALS( angles.empty(), true, TEST_LOCATION );
1796 detector.AddDirection( PanGestureDetector::DIRECTION_LEFT, Radian( Math::PI * 0.25 ) );
1797 DALI_TEST_EQUALS( angles.size(), static_cast<AngleSizeType>(2), TEST_LOCATION );
1798 for ( PanGestureDetector::AngleContainer::const_iterator iter = angles.begin(), endIter = angles.end(); iter != endIter; ++iter )
1800 if ( iter->first == PanGestureDetector::DIRECTION_LEFT )
1802 tet_result( TET_PASS );
1806 if ( iter == endIter )
1808 tet_printf("%s, angle not added\n", TEST_LOCATION );
1809 tet_result( TET_FAIL );
1813 for ( PanGestureDetector::AngleContainer::const_iterator iter = angles.begin(), endIter = angles.end(); iter != endIter; ++iter )
1815 if ( iter->first == PanGestureDetector::DIRECTION_RIGHT )
1817 tet_result( TET_PASS );
1821 if ( iter == endIter )
1823 tet_printf("%s, angle not added\n", TEST_LOCATION );
1824 tet_result( TET_FAIL );
1828 // Remove something not in the container.
1829 detector.RemoveDirection( PanGestureDetector::DIRECTION_UP );
1830 DALI_TEST_EQUALS( angles.size(), static_cast<AngleSizeType>(2), TEST_LOCATION );
1832 detector.RemoveDirection( PanGestureDetector::DIRECTION_RIGHT );
1833 DALI_TEST_EQUALS( angles.size(), static_cast<AngleSizeType>(0), TEST_LOCATION );
1836 void UtcDaliPanGestureDirectionProcessing()
1838 TestApplication application;
1840 Actor parent = Actor::New();
1841 parent.SetSize(100.0f, 100.0f);
1842 parent.SetAnchorPoint(AnchorPoint::TOP_LEFT);
1843 Stage::GetCurrent().Add(parent);
1845 Actor child = Actor::New();
1846 child.SetSize(100.0f, 100.0f);
1847 child.SetAnchorPoint(AnchorPoint::TOP_LEFT);
1850 // Render and notify
1851 application.SendNotification();
1852 application.Render();
1854 // Parent detector only requires vertical panning
1855 PanGestureDetector parentDetector = PanGestureDetector::New();
1856 parentDetector.Attach( parent );
1857 parentDetector.AddDirection( PanGestureDetector::DIRECTION_VERTICAL, Degree( 30.0f ) );
1858 SignalData parentData;
1859 GestureReceivedFunctor parentFunctor(parentData);
1860 parentDetector.DetectedSignal().Connect(&application, parentFunctor);
1862 // Child detector only requires horizontal panning
1863 PanGestureDetector childDetector = PanGestureDetector::New();
1864 childDetector.Attach( child );
1865 childDetector.AddDirection( PanGestureDetector::DIRECTION_HORIZONTAL, Degree( 30.0f ) );
1866 SignalData childData;
1867 GestureReceivedFunctor childFunctor(childData);
1868 childDetector.DetectedSignal().Connect(&application, childFunctor);
1870 // Generate an Up pan gesture, only parent should receive it.
1871 application.ProcessEvent( GeneratePan( Gesture::Possible, Vector2(20.0f, 20.0f), Vector2(20.0f, 20.0f), 10 ) );
1872 application.ProcessEvent( GeneratePan( Gesture::Started, Vector2(20.0f, 20.0f), Vector2(20.0f, 10.0f), 10 ) );
1873 DALI_TEST_EQUALS( true, parentData.functorCalled, TEST_LOCATION );
1874 DALI_TEST_EQUALS( false, childData.functorCalled, TEST_LOCATION );
1875 application.ProcessEvent( GeneratePan( Gesture::Finished, Vector2(20.0f, 30.0f), Vector2(20.0f, 20.0f), 10 ) );
1879 // Generate a Right pan gesture, only child should receive it.
1880 application.ProcessEvent( GeneratePan( Gesture::Possible, Vector2(20.0f, 20.0f), Vector2(20.0f, 20.0f), 10 ) );
1881 application.ProcessEvent( GeneratePan( Gesture::Started, Vector2(20.0f, 20.0f), Vector2(30.0f, 20.0f), 10 ) );
1882 DALI_TEST_EQUALS( false, parentData.functorCalled, TEST_LOCATION );
1883 DALI_TEST_EQUALS( true, childData.functorCalled, TEST_LOCATION );
1884 application.ProcessEvent( GeneratePan( Gesture::Finished, Vector2(20.0f, 30.0f), Vector2(20.0f, 20.0f), 10 ) );
1888 // Generate a Down pan gesture, only parent should receive it.
1889 application.ProcessEvent( GeneratePan( Gesture::Possible, Vector2(20.0f, 20.0f), Vector2(20.0f, 20.0f), 10 ) );
1890 application.ProcessEvent( GeneratePan( Gesture::Started, Vector2(20.0f, 20.0f), Vector2(20.0f, 30.0f), 10 ) );
1891 DALI_TEST_EQUALS( true, parentData.functorCalled, TEST_LOCATION );
1892 DALI_TEST_EQUALS( false, childData.functorCalled, TEST_LOCATION );
1893 application.ProcessEvent( GeneratePan( Gesture::Finished, Vector2(20.0f, 30.0f), Vector2(20.0f, 20.0f), 10 ) );
1897 // Generate a Left pan gesture, only child should receive it.
1898 application.ProcessEvent( GeneratePan( Gesture::Possible, Vector2(20.0f, 20.0f), Vector2(20.0f, 20.0f), 10 ) );
1899 application.ProcessEvent( GeneratePan( Gesture::Started, Vector2(20.0f, 20.0f), Vector2(10.0f, 20.0f), 10 ) );
1900 DALI_TEST_EQUALS( false, parentData.functorCalled, TEST_LOCATION );
1901 DALI_TEST_EQUALS( true, childData.functorCalled, TEST_LOCATION );
1902 application.ProcessEvent( GeneratePan( Gesture::Finished, Vector2(20.0f, 30.0f), Vector2(20.0f, 20.0f), 10 ) );
1906 // Generate a pan at -45 degrees, no one should receive it.
1907 application.ProcessEvent( GeneratePan( Gesture::Possible, Vector2(20.0f, 20.0f), Vector2(20.0f, 20.0f), 10 ) );
1908 application.ProcessEvent( GeneratePan( Gesture::Started, Vector2(20.0f, 20.0f), Vector2(10.0f, 30.0f), 10 ) );
1909 DALI_TEST_EQUALS( false, parentData.functorCalled, TEST_LOCATION );
1910 DALI_TEST_EQUALS( false, childData.functorCalled, TEST_LOCATION );
1911 application.ProcessEvent( GeneratePan( Gesture::Finished, Vector2(20.0f, 30.0f), Vector2(20.0f, 20.0f), 10 ) );
1915 // Generate a pan at 45 degrees, no one should receive it.
1916 application.ProcessEvent( GeneratePan( Gesture::Possible, Vector2(20.0f, 20.0f), Vector2(20.0f, 20.0f), 10 ) );
1917 application.ProcessEvent( GeneratePan( Gesture::Started, Vector2(20.0f, 20.0f), Vector2(30.0f, 30.0f), 10 ) );
1918 DALI_TEST_EQUALS( false, parentData.functorCalled, TEST_LOCATION );
1919 DALI_TEST_EQUALS( false, childData.functorCalled, TEST_LOCATION );
1920 application.ProcessEvent( GeneratePan( Gesture::Finished, Vector2(20.0f, 30.0f), Vector2(20.0f, 20.0f), 10 ) );
1924 // Generate a pan at 135 degrees, no one should receive it.
1925 application.ProcessEvent( GeneratePan( Gesture::Possible, Vector2(20.0f, 20.0f), Vector2(20.0f, 20.0f), 10 ) );
1926 application.ProcessEvent( GeneratePan( Gesture::Started, Vector2(20.0f, 20.0f), Vector2(10.0f, 30.0f), 10 ) );
1927 DALI_TEST_EQUALS( false, parentData.functorCalled, TEST_LOCATION );
1928 DALI_TEST_EQUALS( false, childData.functorCalled, TEST_LOCATION );
1929 application.ProcessEvent( GeneratePan( Gesture::Finished, Vector2(20.0f, 30.0f), Vector2(20.0f, 20.0f), 10 ) );
1933 // Generate a pan at -135 degrees, no one should receive it.
1934 application.ProcessEvent( GeneratePan( Gesture::Possible, Vector2(20.0f, 20.0f), Vector2(20.0f, 20.0f), 10 ) );
1935 application.ProcessEvent( GeneratePan( Gesture::Started, Vector2(20.0f, 20.0f), Vector2(10.0f, 10.0f), 10 ) );
1936 DALI_TEST_EQUALS( false, parentData.functorCalled, TEST_LOCATION );
1937 DALI_TEST_EQUALS( false, childData.functorCalled, TEST_LOCATION );
1938 application.ProcessEvent( GeneratePan( Gesture::Finished, Vector2(20.0f, 30.0f), Vector2(20.0f, 20.0f), 10 ) );
1943 void UtcDaliPanGestureSetProperties()
1945 TestApplication application;
1946 TestRenderController& renderController( application.GetRenderController() );
1948 Actor actor = Actor::New();
1949 actor.SetSize(100.0f, 100.0f);
1950 actor.SetAnchorPoint(AnchorPoint::TOP_LEFT);
1951 Stage::GetCurrent().Add(actor);
1953 // Add a pan detector
1954 PanGestureDetector detector = PanGestureDetector::New();
1955 detector.Attach( actor );
1957 GestureReceivedFunctor functor( data );
1958 detector.DetectedSignal().Connect( &application, functor );
1960 Property::Index property = actor.RegisterProperty( "Dummy Property", Vector3::ZERO );
1962 ConstraintData constraintData;
1963 actor.ApplyConstraint( Constraint::New<Vector3>( property, Source( detector, PanGestureDetector::SCREEN_POSITION ),
1964 Source( detector, PanGestureDetector::SCREEN_DISPLACEMENT ),
1965 Source( detector, PanGestureDetector::LOCAL_POSITION ),
1966 Source( detector, PanGestureDetector::LOCAL_DISPLACEMENT ),
1967 PanConstraint( constraintData ) ) );
1969 // Render and notify
1970 application.SendNotification();
1971 application.Render();
1973 renderController.Initialize();
1974 DALI_TEST_EQUALS( renderController.WasCalled( TestRenderController::RequestUpdateFunc ), false, TEST_LOCATION );
1976 Vector2 screenPosition( 20.0f, 20.0f );
1977 Vector2 screenDisplacement( 1.0f, 1.0f );
1978 Vector2 localPosition( 21.0f, 21.0f );
1979 Vector2 localDisplacement( 0.5f, 0.5f );
1981 PanGestureDetector::SetPanGestureProperties( GeneratePan( 1u, Gesture::Started, screenPosition, localPosition, screenDisplacement, localDisplacement ) );
1982 DALI_TEST_EQUALS( renderController.WasCalled( TestRenderController::RequestUpdateFunc ), true, TEST_LOCATION );
1984 // Render and notify
1985 application.SendNotification();
1986 application.Render();
1988 DALI_TEST_EQUALS( constraintData.called, true, TEST_LOCATION );
1989 DALI_TEST_EQUALS( constraintData.screenPosition, screenPosition, TEST_LOCATION );
1990 DALI_TEST_EQUALS( constraintData.localPosition, localPosition, TEST_LOCATION );
1991 DALI_TEST_EQUALS( constraintData.screenDisplacement, screenDisplacement, TEST_LOCATION );
1992 DALI_TEST_EQUALS( constraintData.localDisplacement, localDisplacement, TEST_LOCATION );
1993 constraintData.Reset();
1996 void UtcDaliPanGestureSetPropertiesAlreadyPanning()
1998 TestApplication application;
2000 Actor actor = Actor::New();
2001 actor.SetSize(100.0f, 100.0f);
2002 actor.SetAnchorPoint(AnchorPoint::TOP_LEFT);
2003 Stage::GetCurrent().Add(actor);
2005 // Add a pan detector
2006 PanGestureDetector detector = PanGestureDetector::New();
2007 detector.Attach( actor );
2009 GestureReceivedFunctor functor( data );
2010 detector.DetectedSignal().Connect( &application, functor );
2012 Property::Index property = actor.RegisterProperty( "Dummy Property", Vector3::ZERO );
2014 ConstraintData constraintData;
2015 actor.ApplyConstraint( Constraint::New<Vector3>( property, Source( detector, PanGestureDetector::SCREEN_POSITION ),
2016 Source( detector, PanGestureDetector::SCREEN_DISPLACEMENT ),
2017 Source( detector, PanGestureDetector::LOCAL_POSITION ),
2018 Source( detector, PanGestureDetector::LOCAL_DISPLACEMENT ),
2019 PanConstraint( constraintData ) ) );
2021 // Render and notify
2022 application.SendNotification();
2023 application.Render();
2025 Vector2 previousPosition( 20.0f, 20.0f );
2026 Vector2 currentPosition( 20.0f, 10.0f );
2027 application.ProcessEvent( GeneratePan( Gesture::Possible, previousPosition, previousPosition, 10 ) );
2028 application.ProcessEvent( GeneratePan( Gesture::Started, previousPosition, currentPosition, 10 ) );
2029 DALI_TEST_EQUALS( true, data.functorCalled, TEST_LOCATION );
2031 Vector2 screenPosition( 100.0f, 20.0f );
2032 Vector2 localPosition( 110.0f, 110.0f );
2034 PanGestureDetector::SetPanGestureProperties( GeneratePan( 1u, Gesture::Started, screenPosition, localPosition ) );
2036 // Render and notify
2037 application.SendNotification();
2038 application.Render();
2040 DALI_TEST_EQUALS( constraintData.called, true, TEST_LOCATION );
2041 DALI_TEST_EQUALS( constraintData.screenPosition, currentPosition, 0.1, TEST_LOCATION );
2042 DALI_TEST_EQUALS( constraintData.localPosition, currentPosition, 0.1f, TEST_LOCATION );
2043 constraintData.Reset();
2046 void UtcDaliPanGesturePropertyIndices()
2048 TestApplication application;
2049 PanGestureDetector detector = PanGestureDetector::New();
2051 Property::IndexContainer indices;
2052 detector.GetPropertyIndices( indices );
2053 DALI_TEST_CHECK( ! indices.empty() );
2054 DALI_TEST_EQUALS( indices.size(), detector.GetPropertyCount(), TEST_LOCATION );