2 * Copyright (c) 2014 Samsung Electronics Co., Ltd.
4 * Licensed under the Apache License, Version 2.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://www.apache.org/licenses/LICENSE-2.0
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.
21 #include <dali/public-api/dali-core.h>
22 #include <dali/integration-api/events/touch-event-integ.h>
23 #include <dali/integration-api/events/long-press-gesture-event.h>
24 #include <dali/integration-api/system-overlay.h>
25 #include <dali/integration-api/render-task-list-integ.h>
26 #include <dali-test-suite-utils.h>
27 #include <test-touch-utils.h>
31 void utc_dali_long_press_gesture_detector_startup(void)
33 test_return_value = TET_UNDEF;
36 void utc_dali_long_press_gesture_detector_cleanup(void)
38 test_return_value = TET_PASS;
41 ///////////////////////////////////////////////////////////////////////////////
45 // Stores data that is populated in the callback and will be read by the TET cases
49 : functorCalled( false ),
50 voidFunctorCalled( false ),
51 receivedGesture( Gesture::Clear ),
57 functorCalled = false;
58 voidFunctorCalled = false;
60 receivedGesture.numberOfTouches = 0u;
61 receivedGesture.screenPoint = Vector2(0.0f, 0.0f);
62 receivedGesture.localPoint = Vector2(0.0f, 0.0f);
68 bool voidFunctorCalled;
69 LongPressGesture receivedGesture;
73 // Functor that sets the data when called
74 struct GestureReceivedFunctor
76 GestureReceivedFunctor(SignalData& data) : signalData(data) { }
78 void operator()(Actor actor, const LongPressGesture& longPress)
80 signalData.functorCalled = true;
81 signalData.receivedGesture = longPress;
82 signalData.pressedActor = actor;
87 signalData.voidFunctorCalled = true;
90 SignalData& signalData;
93 // Functor that removes the gestured actor from stage
94 struct UnstageActorFunctor : public GestureReceivedFunctor
96 UnstageActorFunctor( SignalData& data, Gesture::State& stateToUnstage )
97 : GestureReceivedFunctor( data ),
98 stateToUnstage( stateToUnstage )
102 void operator()( Actor actor, const LongPressGesture& longPress )
104 GestureReceivedFunctor::operator()( actor, longPress );
106 if ( longPress.state == stateToUnstage )
108 Stage::GetCurrent().Remove( actor );
112 Gesture::State& stateToUnstage;
115 // Functor for receiving a touch event
116 struct TouchEventFunctor
118 bool operator()(Actor actor, const TouchEvent& touch)
121 unsigned int points = touch.GetPointCount();
124 const TouchPoint& touchPoint = touch.GetPoint(0);
125 tet_printf("Touch Point state = %d\n", touchPoint.state);
131 // Generate a LongPressGestureEvent to send to Core
132 Integration::LongPressGestureEvent GenerateLongPress(
133 Gesture::State state,
134 unsigned int numberOfTouches,
137 Integration::LongPressGestureEvent longPress( state );
139 longPress.numberOfTouches = numberOfTouches;
140 longPress.point = point;
147 ///////////////////////////////////////////////////////////////////////////////
150 // Positive test case for a method
151 int UtcDaliLongPressGestureDetectorConstructorP(void)
153 TestApplication application;
155 LongPressGestureDetector detector;
156 DALI_TEST_CHECK(!detector);
160 int UtcDaliLongPressGestureDetectorCopyConstructorP(void)
162 TestApplication application;
164 LongPressGestureDetector detector = LongPressGestureDetector::New();;
166 LongPressGestureDetector copy( detector );
167 DALI_TEST_CHECK( detector );
171 int UtcDaliLongPressGestureDetectorAssignmentOperatorP(void)
173 TestApplication application;
175 LongPressGestureDetector detector;
176 detector = LongPressGestureDetector::New();;
178 LongPressGestureDetector copy;
180 DALI_TEST_CHECK( detector );
182 DALI_TEST_CHECK( detector == copy );
186 int UtcDaliLongPressGestureDetectorNew(void)
188 TestApplication application;
190 LongPressGestureDetector detector = LongPressGestureDetector::New();
191 DALI_TEST_CHECK(detector);
192 DALI_TEST_EQUALS(1u, detector.GetMinimumTouchesRequired(), TEST_LOCATION);
193 DALI_TEST_EQUALS(1u, detector.GetMaximumTouchesRequired(), TEST_LOCATION);
195 LongPressGestureDetector detector2 = LongPressGestureDetector::New(5u);
196 DALI_TEST_CHECK(detector2);
197 DALI_TEST_EQUALS(5u, detector2.GetMinimumTouchesRequired(), TEST_LOCATION);
198 DALI_TEST_EQUALS(5u, detector2.GetMaximumTouchesRequired(), TEST_LOCATION);
200 LongPressGestureDetector detector3 = LongPressGestureDetector::New(5u, 7u);
201 DALI_TEST_CHECK(detector2);
202 DALI_TEST_EQUALS(5u, detector3.GetMinimumTouchesRequired(), TEST_LOCATION);
203 DALI_TEST_EQUALS(7u, detector3.GetMaximumTouchesRequired(), TEST_LOCATION);
205 //Scoped test to test destructor
207 LongPressGestureDetector detector4 = LongPressGestureDetector::New();
208 DALI_TEST_CHECK(detector4);
211 // Attach an actor and emit a touch event on the actor to ensure complete line coverage
212 Actor actor = Actor::New();
213 actor.SetSize(100.0f, 100.0f);
214 actor.SetAnchorPoint(AnchorPoint::TOP_LEFT);
215 Stage::GetCurrent().Add(actor);
218 application.SendNotification();
219 application.Render();
221 detector.Attach(actor);
223 TouchEventFunctor touchFunctor;
224 actor.TouchedSignal().Connect(&application, touchFunctor);
226 Integration::TouchEvent touchEvent(1);
227 Integration::Point point;
228 point.SetDeviceId( 1 );
229 point.SetState( PointState::DOWN );
230 point.SetScreenPosition( Vector2( 20.0f, 20.0f ) );
231 touchEvent.AddPoint(point);
232 application.ProcessEvent(touchEvent);
235 application.SendNotification();
236 application.Render();
238 // For line coverage, Initialise default constructor
239 TouchEvent touchEvent2;
243 int UtcDaliLongPressGestureDetectorDownCast(void)
245 TestApplication application;
246 tet_infoline("Testing Dali::LongPressGestureDetector::DownCast()");
248 LongPressGestureDetector detector = LongPressGestureDetector::New();
250 BaseHandle object(detector);
252 LongPressGestureDetector detector2 = LongPressGestureDetector::DownCast(object);
253 DALI_TEST_CHECK(detector2);
255 LongPressGestureDetector detector3 = DownCast< LongPressGestureDetector >(object);
256 DALI_TEST_CHECK(detector3);
258 BaseHandle unInitializedObject;
259 LongPressGestureDetector detector4 = LongPressGestureDetector::DownCast(unInitializedObject);
260 DALI_TEST_CHECK(!detector4);
262 LongPressGestureDetector detector5 = DownCast< LongPressGestureDetector >(unInitializedObject);
263 DALI_TEST_CHECK(!detector5);
265 GestureDetector detector6 = LongPressGestureDetector::New();
266 LongPressGestureDetector detector7 = LongPressGestureDetector::DownCast(detector6);
267 DALI_TEST_CHECK(detector7);
271 int UtcDaliLongPressGestureSetTouchesRequired01(void)
273 TestApplication application;
275 LongPressGestureDetector detector = LongPressGestureDetector::New();
277 unsigned int touches = 3;
279 DALI_TEST_CHECK(touches != detector.GetMinimumTouchesRequired());
280 DALI_TEST_CHECK(touches != detector.GetMaximumTouchesRequired());
282 detector.SetTouchesRequired(touches);
284 DALI_TEST_EQUALS(touches, detector.GetMinimumTouchesRequired(), TEST_LOCATION);
285 DALI_TEST_EQUALS(touches, detector.GetMaximumTouchesRequired(), TEST_LOCATION);
287 // Attach an actor and change the required touches
289 Actor actor = Actor::New();
290 actor.SetSize(100.0f, 100.0f);
291 actor.SetAnchorPoint(AnchorPoint::TOP_LEFT);
292 Stage::GetCurrent().Add(actor);
295 application.SendNotification();
296 application.Render();
299 GestureReceivedFunctor functor(data);
301 detector.Attach(actor);
302 detector.DetectedSignal().Connect(&application, functor);
304 TestGestureManager& gestureManager = application.GetGestureManager();
305 gestureManager.Initialize();
307 detector.SetTouchesRequired(4);
309 // Gesture detection should have been updated only
310 DALI_TEST_EQUALS(true, gestureManager.WasCalled(TestGestureManager::UpdateType), TEST_LOCATION);
311 DALI_TEST_EQUALS(false, gestureManager.WasCalled(TestGestureManager::RegisterType), TEST_LOCATION);
312 DALI_TEST_EQUALS(false, gestureManager.WasCalled(TestGestureManager::UnregisterType), TEST_LOCATION);
315 gestureManager.Initialize();
317 // Create a second gesture detector that requires even less maximum touches
318 LongPressGestureDetector secondDetector = LongPressGestureDetector::New();
319 secondDetector.Attach(actor);
321 // Gesture detection should have been updated
322 DALI_TEST_EQUALS(true, gestureManager.WasCalled(TestGestureManager::UpdateType), TEST_LOCATION);
323 DALI_TEST_EQUALS(false, gestureManager.WasCalled(TestGestureManager::RegisterType), TEST_LOCATION);
324 DALI_TEST_EQUALS(false, gestureManager.WasCalled(TestGestureManager::UnregisterType), TEST_LOCATION);
328 int UtcDaliLongPressGestureSetTouchesRequired02(void)
330 TestApplication application;
332 LongPressGestureDetector detector = LongPressGestureDetector::New();
334 unsigned int min = 3;
335 unsigned int max = 5;
337 DALI_TEST_CHECK(min != detector.GetMinimumTouchesRequired());
338 DALI_TEST_CHECK(max != detector.GetMaximumTouchesRequired());
340 detector.SetTouchesRequired(min, max);
342 DALI_TEST_EQUALS(min, detector.GetMinimumTouchesRequired(), TEST_LOCATION);
343 DALI_TEST_EQUALS(max, detector.GetMaximumTouchesRequired(), TEST_LOCATION);
345 // Attach an actor and change the maximum touches
347 Actor actor = Actor::New();
348 actor.SetSize(100.0f, 100.0f);
349 actor.SetAnchorPoint(AnchorPoint::TOP_LEFT);
350 Stage::GetCurrent().Add(actor);
353 application.SendNotification();
354 application.Render();
357 GestureReceivedFunctor functor(data);
359 detector.Attach(actor);
360 detector.DetectedSignal().Connect(&application, functor);
362 TestGestureManager& gestureManager = application.GetGestureManager();
363 gestureManager.Initialize();
365 detector.SetTouchesRequired(4, 5);
367 // Gesture detection should have been updated only
368 DALI_TEST_EQUALS(true, gestureManager.WasCalled(TestGestureManager::UpdateType), TEST_LOCATION);
369 DALI_TEST_EQUALS(false, gestureManager.WasCalled(TestGestureManager::RegisterType), TEST_LOCATION);
370 DALI_TEST_EQUALS(false, gestureManager.WasCalled(TestGestureManager::UnregisterType), TEST_LOCATION);
373 gestureManager.Initialize();
375 // Create a second gesture detector that requires even less maximum touches
376 LongPressGestureDetector secondDetector = LongPressGestureDetector::New();
377 secondDetector.Attach(actor);
379 // Gesture detection should have been updated
380 DALI_TEST_EQUALS(true, gestureManager.WasCalled(TestGestureManager::UpdateType), TEST_LOCATION);
381 DALI_TEST_EQUALS(false, gestureManager.WasCalled(TestGestureManager::RegisterType), TEST_LOCATION);
382 DALI_TEST_EQUALS(false, gestureManager.WasCalled(TestGestureManager::UnregisterType), TEST_LOCATION);
386 int UtcDaliLongPressGestureGetMinimumTouchesRequired(void)
388 TestApplication application;
390 LongPressGestureDetector detector = LongPressGestureDetector::New();
391 DALI_TEST_EQUALS(1u, detector.GetMinimumTouchesRequired(), TEST_LOCATION);
395 int UtcDaliLongPressGestureGetMaximumTouchesRequired(void)
397 TestApplication application;
399 LongPressGestureDetector detector = LongPressGestureDetector::New();
400 DALI_TEST_EQUALS(1u, detector.GetMaximumTouchesRequired(), TEST_LOCATION);
404 int UtcDaliLongPressGestureSignalReceptionNegative(void)
406 TestApplication application;
408 Actor actor = Actor::New();
409 actor.SetSize(100.0f, 100.0f);
410 actor.SetAnchorPoint(AnchorPoint::TOP_LEFT);
411 Stage::GetCurrent().Add(actor);
414 application.SendNotification();
415 application.Render();
418 GestureReceivedFunctor functor(data);
420 LongPressGestureDetector detector = LongPressGestureDetector::New();
421 detector.Attach(actor);
422 detector.DetectedSignal().Connect(&application, functor);
424 // Do a long press outside actor's area
425 application.ProcessEvent( GenerateLongPress( Gesture::Possible, 1u, Vector2(112.0f, 112.0f ) ) );
426 application.ProcessEvent( GenerateLongPress( Gesture::Started, 1u, Vector2(112.0f, 112.0f ) ) );
427 application.ProcessEvent( GenerateLongPress( Gesture::Finished, 1u, Vector2(112.0f, 112.0f ) ) );
428 DALI_TEST_EQUALS(false, data.functorCalled, TEST_LOCATION);
432 int UtcDaliLongPressGestureSignalReceptionPositive(void)
434 TestApplication application;
436 Actor actor = Actor::New();
437 actor.SetSize(100.0f, 100.0f);
438 actor.SetAnchorPoint(AnchorPoint::TOP_LEFT);
439 Stage::GetCurrent().Add(actor);
442 application.SendNotification();
443 application.Render();
446 GestureReceivedFunctor functor(data);
448 LongPressGestureDetector detector = LongPressGestureDetector::New();
449 detector.Attach(actor);
450 detector.DetectedSignal().Connect(&application, functor);
452 // Do a long press inside actor's area
453 application.ProcessEvent(GenerateLongPress(Gesture::Possible, 1u, Vector2(50.0f, 50.0f)));
454 application.ProcessEvent(GenerateLongPress(Gesture::Started, 1u, Vector2(50.0f, 50.0f)));
455 DALI_TEST_EQUALS(true, data.functorCalled, TEST_LOCATION);
456 DALI_TEST_EQUALS(1u, data.receivedGesture.numberOfTouches, TEST_LOCATION);
457 DALI_TEST_EQUALS( Vector2(50.0f, 50.0f), data.receivedGesture.localPoint, 0.1, TEST_LOCATION);
458 application.ProcessEvent(GenerateLongPress(Gesture::Finished, 1u, Vector2(50.0f, 50.0f)));
462 int UtcDaliLongPressGestureSignalReceptionDetach(void)
464 TestApplication application;
466 Actor actor = Actor::New();
467 actor.SetSize(100.0f, 100.0f);
468 actor.SetAnchorPoint(AnchorPoint::TOP_LEFT);
469 Stage::GetCurrent().Add(actor);
472 application.SendNotification();
473 application.Render();
476 GestureReceivedFunctor functor(data);
478 LongPressGestureDetector detector = LongPressGestureDetector::New();
479 detector.Attach(actor);
480 detector.DetectedSignal().Connect(&application, functor);
482 // Start long press within the actor's area
483 application.ProcessEvent(GenerateLongPress(Gesture::Possible, 1u, Vector2(20.0f, 20.0f)));
484 application.ProcessEvent(GenerateLongPress(Gesture::Started, 1u, Vector2(20.0f, 20.0f)));
485 DALI_TEST_EQUALS(true, data.functorCalled, TEST_LOCATION);
486 DALI_TEST_EQUALS(1u, data.receivedGesture.numberOfTouches, TEST_LOCATION);
487 DALI_TEST_EQUALS( Vector2(20.0f, 20.0f), data.receivedGesture.localPoint, 0.1, TEST_LOCATION);
488 application.ProcessEvent(GenerateLongPress(Gesture::Finished, 1u, Vector2(20.0f, 20.0f)));
490 // repeat the long press within the actor's area - we should still receive the signal
492 application.ProcessEvent(GenerateLongPress(Gesture::Possible, 1u, Vector2(50.0f, 50.0f)));
493 application.ProcessEvent(GenerateLongPress(Gesture::Started, 1u, Vector2(50.0f, 50.0f)));
494 DALI_TEST_EQUALS(true, data.functorCalled, TEST_LOCATION);
495 DALI_TEST_EQUALS(1u, data.receivedGesture.numberOfTouches, TEST_LOCATION);
496 DALI_TEST_EQUALS( Vector2(50.0f, 50.0f), data.receivedGesture.localPoint, 0.1, TEST_LOCATION);
497 application.ProcessEvent(GenerateLongPress(Gesture::Finished, 1u, Vector2(50.0f, 50.0f)));
500 detector.DetachAll();
502 // Ensure we are no longer signalled
504 application.ProcessEvent(GenerateLongPress(Gesture::Possible, 1u, Vector2(20.0f, 20.0f)));
505 application.ProcessEvent(GenerateLongPress(Gesture::Started, 1u, Vector2(20.0f, 20.0f)));
506 DALI_TEST_EQUALS(false, data.functorCalled, TEST_LOCATION);
507 application.ProcessEvent(GenerateLongPress(Gesture::Finished, 1u, Vector2(50.0f, 50.0f)));
508 DALI_TEST_EQUALS(false, data.functorCalled, TEST_LOCATION);
512 int UtcDaliLongPressGestureSignalReceptionActorDestroyedDuringLongPress(void)
514 TestApplication application;
517 GestureReceivedFunctor functor(data);
519 LongPressGestureDetector detector = LongPressGestureDetector::New();
520 detector.DetectedSignal().Connect(&application, functor);
522 // Actor lifetime is scoped
524 Actor actor = Actor::New();
525 actor.SetSize(100.0f, 100.0f);
526 actor.SetAnchorPoint(AnchorPoint::TOP_LEFT);
527 Stage::GetCurrent().Add(actor);
530 application.SendNotification();
531 application.Render();
533 detector.Attach(actor);
535 // Start long press within the actor's area
536 application.ProcessEvent(GenerateLongPress(Gesture::Possible, 1u, Vector2(20.0f, 20.0f)));
537 application.ProcessEvent(GenerateLongPress(Gesture::Started, 1u, Vector2(20.0f, 20.0f)));
538 DALI_TEST_EQUALS(true, data.functorCalled, TEST_LOCATION);
540 // Remove the actor from stage and reset the data
541 Stage::GetCurrent().Remove(actor);
544 application.SendNotification();
545 application.Render();
548 // Actor should now have been destroyed
551 application.ProcessEvent(GenerateLongPress(Gesture::Finished, 1u, Vector2(20.0f, 20.0f)));
552 DALI_TEST_EQUALS(false, data.functorCalled, TEST_LOCATION);
556 int UtcDaliLongPressGestureSignalReceptionRotatedActor(void)
558 TestApplication application;
560 Actor actor = Actor::New();
561 actor.SetSize(100.0f, 100.0f);
562 actor.SetOrientation(Dali::Degree(90.0f), Vector3::ZAXIS);
563 Stage::GetCurrent().Add(actor);
566 application.SendNotification();
567 application.Render();
570 GestureReceivedFunctor functor(data);
572 LongPressGestureDetector detector = LongPressGestureDetector::New();
573 detector.Attach(actor);
574 detector.DetectedSignal().Connect(&application, functor);
577 application.ProcessEvent(GenerateLongPress(Gesture::Possible, 1u, Vector2(5.0f, 5.0f)));
578 application.ProcessEvent(GenerateLongPress(Gesture::Started, 1u, Vector2(5.0f, 5.0f)));
579 application.ProcessEvent(GenerateLongPress(Gesture::Finished, 1u, Vector2(5.0f, 5.0f)));
580 DALI_TEST_EQUALS(true, data.functorCalled, TEST_LOCATION);
581 DALI_TEST_EQUALS(1u, data.receivedGesture.numberOfTouches, TEST_LOCATION);
582 DALI_TEST_EQUALS( Vector2(5.0f, 5.0f), data.receivedGesture.screenPoint, 0.1, TEST_LOCATION);
584 // Rotate actor again and render
585 actor.SetOrientation(Dali::Degree(180.0f), Vector3::ZAXIS);
586 application.SendNotification();
587 application.Render();
589 // Do another long press, should still receive event
591 application.ProcessEvent(GenerateLongPress(Gesture::Possible, 1u, Vector2(5.0f, 5.0f)));
592 application.ProcessEvent(GenerateLongPress(Gesture::Started, 1u, Vector2(5.0f, 5.0f)));
593 application.ProcessEvent(GenerateLongPress(Gesture::Finished, 1u, Vector2(5.0f, 5.0f)));
594 DALI_TEST_EQUALS(true, data.functorCalled, TEST_LOCATION);
595 DALI_TEST_EQUALS(1u, data.receivedGesture.numberOfTouches, TEST_LOCATION);
596 DALI_TEST_EQUALS( Vector2(5.0f, 5.0f), data.receivedGesture.screenPoint, 0.1, TEST_LOCATION);
598 // Rotate actor again and render
599 actor.SetOrientation(Dali::Degree(90.0f), Vector3::YAXIS);
600 application.SendNotification();
601 application.Render();
603 // Do a long press, inside where the actor used to be, Should not receive the event
605 application.ProcessEvent(GenerateLongPress(Gesture::Possible, 1u, Vector2(70.0f, 70.0f)));
606 application.ProcessEvent(GenerateLongPress(Gesture::Started, 1u, Vector2(70.0f, 70.0f)));
607 application.ProcessEvent(GenerateLongPress(Gesture::Finished, 1u, Vector2(70.0f, 70.0f)));
608 DALI_TEST_EQUALS(false, data.functorCalled, TEST_LOCATION);
612 int UtcDaliLongPressGestureSignalReceptionChildHit(void)
614 TestApplication application;
616 Actor parent = Actor::New();
617 parent.SetSize(100.0f, 100.0f);
618 parent.SetAnchorPoint(AnchorPoint::TOP_LEFT);
619 Stage::GetCurrent().Add(parent);
621 // Set child to completely cover parent.
622 // Change rotation of child to be different from parent so that we can check if our local coordinate
623 // conversion of the parent actor is correct.
624 Actor child = Actor::New();
625 child.SetSize(100.0f, 100.0f);
626 child.SetAnchorPoint(AnchorPoint::CENTER);
627 child.SetParentOrigin(ParentOrigin::CENTER);
628 child.SetOrientation(Dali::Degree(90.0f), Vector3::ZAXIS);
631 TouchEventFunctor touchFunctor;
632 child.TouchedSignal().Connect(&application, touchFunctor);
635 application.SendNotification();
636 application.Render();
639 GestureReceivedFunctor functor(data);
641 LongPressGestureDetector detector = LongPressGestureDetector::New();
642 detector.Attach(parent);
643 detector.DetectedSignal().Connect(&application, functor);
645 // Do long press - hits child area but parent should still receive it
646 application.ProcessEvent(GenerateLongPress(Gesture::Possible, 1u, Vector2(50.0f, 50.0f)));
647 application.ProcessEvent(GenerateLongPress(Gesture::Started, 1u, Vector2(50.0f, 50.0f)));
648 application.ProcessEvent(GenerateLongPress(Gesture::Finished, 1u, Vector2(50.0f, 50.0f)));
649 DALI_TEST_EQUALS(true, data.functorCalled, TEST_LOCATION);
650 DALI_TEST_EQUALS(true, parent == data.pressedActor, TEST_LOCATION);
651 DALI_TEST_EQUALS(Vector2(50.0f, 50.0f), data.receivedGesture.screenPoint, 0.01f, TEST_LOCATION);
653 // Attach child and generate same touch points
654 // (Also proves that you can detach and then re-attach another actor)
655 detector.Attach(child);
656 detector.Detach(parent);
658 // Do an entire long press, only check finished value
660 application.ProcessEvent(GenerateLongPress(Gesture::Possible, 1u, Vector2(51.0f, 51.0f)));
661 application.ProcessEvent(GenerateLongPress(Gesture::Started, 1u, Vector2(51.0f, 51.0f)));
662 application.ProcessEvent(GenerateLongPress(Gesture::Finished, 1u, Vector2(51.0f, 51.0f)));
663 DALI_TEST_EQUALS(true, data.functorCalled, TEST_LOCATION);
664 DALI_TEST_EQUALS(true, child == data.pressedActor, TEST_LOCATION);
665 DALI_TEST_EQUALS(Vector2(51.0f, 51.0f), data.receivedGesture.screenPoint, 0.01f, TEST_LOCATION);
669 int UtcDaliLongPressGestureSignalReceptionAttachDetachMany(void)
671 TestApplication application;
673 Actor first = Actor::New();
674 first.SetSize(100.0f, 100.0f);
675 first.SetAnchorPoint(AnchorPoint::TOP_LEFT);
676 Stage::GetCurrent().Add(first);
678 Actor second = Actor::New();
679 second.SetSize(100.0f, 100.0f);
681 second.SetAnchorPoint(AnchorPoint::TOP_LEFT);
682 Stage::GetCurrent().Add(second);
685 application.SendNotification();
686 application.Render();
689 GestureReceivedFunctor functor(data);
691 LongPressGestureDetector detector = LongPressGestureDetector::New();
692 detector.Attach(first);
693 detector.Attach(second);
694 detector.DetectedSignal().Connect(&application, functor);
696 // LongPress within second actor's area
697 application.ProcessEvent(GenerateLongPress(Gesture::Possible, 1u, Vector2(120.0f, 10.0f)));
698 application.ProcessEvent(GenerateLongPress(Gesture::Started, 1u, Vector2(120.0f, 10.0f)));
699 application.ProcessEvent(GenerateLongPress(Gesture::Finished, 1u, Vector2(120.0f, 10.0f)));
700 DALI_TEST_EQUALS(true, data.functorCalled, TEST_LOCATION);
701 DALI_TEST_EQUALS(true, second == data.pressedActor, TEST_LOCATION);
703 // LongPress within first actor's area
705 application.ProcessEvent(GenerateLongPress(Gesture::Possible, 1u, Vector2(20.0f, 10.0f)));
706 application.ProcessEvent(GenerateLongPress(Gesture::Started, 1u, Vector2(20.0f, 10.0f)));
707 application.ProcessEvent(GenerateLongPress(Gesture::Finished, 1u, Vector2(20.0f, 10.0f)));
708 DALI_TEST_EQUALS(true, data.functorCalled, TEST_LOCATION);
709 DALI_TEST_EQUALS(true, first == data.pressedActor, TEST_LOCATION);
711 // Detach the second actor
712 detector.Detach(second);
714 // second actor shouldn't receive event
716 application.ProcessEvent(GenerateLongPress(Gesture::Possible, 1u, Vector2(120.0f, 10.0f)));
717 application.ProcessEvent(GenerateLongPress(Gesture::Started, 1u, Vector2(120.0f, 10.0f)));
718 application.ProcessEvent(GenerateLongPress(Gesture::Finished, 1u, Vector2(120.0f, 10.0f)));
719 DALI_TEST_EQUALS(false, data.functorCalled, TEST_LOCATION);
721 // first actor should continue receiving event
723 application.ProcessEvent(GenerateLongPress(Gesture::Possible, 1u, Vector2(20.0f, 10.0f)));
724 application.ProcessEvent(GenerateLongPress(Gesture::Started, 1u, Vector2(20.0f, 10.0f)));
725 application.ProcessEvent(GenerateLongPress(Gesture::Finished, 1u, Vector2(20.0f, 10.0f)));
726 DALI_TEST_EQUALS(true, data.functorCalled, TEST_LOCATION);
730 int UtcDaliLongPressGestureSignalReceptionActorBecomesUntouchable(void)
732 TestApplication application;
734 Actor actor = Actor::New();
735 actor.SetSize(100.0f, 100.0f);
736 actor.SetAnchorPoint(AnchorPoint::TOP_LEFT);
737 Stage::GetCurrent().Add(actor);
740 application.SendNotification();
741 application.Render();
744 GestureReceivedFunctor functor(data);
746 LongPressGestureDetector detector = LongPressGestureDetector::New();
747 detector.Attach(actor);
748 detector.DetectedSignal().Connect(&application, functor);
750 // LongPress in actor's area
751 application.ProcessEvent(GenerateLongPress(Gesture::Possible, 1u, Vector2(50.0f, 10.0f)));
752 application.ProcessEvent(GenerateLongPress(Gesture::Started, 1u, Vector2(50.0f, 10.0f)));
753 application.ProcessEvent(GenerateLongPress(Gesture::Finished, 1u, Vector2(50.0f, 10.0f)));
754 DALI_TEST_EQUALS(true, data.functorCalled, TEST_LOCATION);
756 // Actor becomes invisible - actor should not receive the next long press
757 actor.SetVisible(false);
760 application.SendNotification();
761 application.Render();
763 // LongPress in the same area, shouldn't receive event
765 application.ProcessEvent(GenerateLongPress(Gesture::Possible, 1u, Vector2(50.0f, 10.0f)));
766 application.ProcessEvent(GenerateLongPress(Gesture::Started, 1u, Vector2(50.0f, 10.0f)));
767 application.ProcessEvent(GenerateLongPress(Gesture::Finished, 1u, Vector2(50.0f, 10.0f)));
768 DALI_TEST_EQUALS(false, data.functorCalled, TEST_LOCATION);
772 int UtcDaliLongPressGestureSignalReceptionMultipleGestureDetectors(void)
774 TestApplication application;
775 Dali::TestGestureManager& gestureManager = application.GetGestureManager();
777 Actor first = Actor::New();
778 first.SetSize(100.0f, 100.0f);
779 first.SetAnchorPoint(AnchorPoint::TOP_LEFT);
780 Stage::GetCurrent().Add(first);
782 Actor second = Actor::New();
783 second.SetSize(100.0f, 100.0f);
784 second.SetAnchorPoint(AnchorPoint::TOP_LEFT);
789 application.SendNotification();
790 application.Render();
793 GestureReceivedFunctor functor(data);
795 LongPressGestureDetector firstDetector = LongPressGestureDetector::New();
796 firstDetector.Attach(first);
797 firstDetector.DetectedSignal().Connect(&application, functor);
799 // secondDetector is scoped
801 // Reset gestureManager statistics
802 gestureManager.Initialize();
804 LongPressGestureDetector secondDetector = LongPressGestureDetector::New();
805 secondDetector.SetTouchesRequired(2);
806 secondDetector.Attach(second);
807 secondDetector.DetectedSignal().Connect(&application, functor);
809 DALI_TEST_EQUALS(true, gestureManager.WasCalled(TestGestureManager::UpdateType), TEST_LOCATION);
810 DALI_TEST_EQUALS(false, gestureManager.WasCalled(TestGestureManager::RegisterType), TEST_LOCATION);
811 DALI_TEST_EQUALS(false, gestureManager.WasCalled(TestGestureManager::UnregisterType), TEST_LOCATION);
813 // LongPress within second actor's area
814 application.ProcessEvent(GenerateLongPress(Gesture::Possible, 2u, Vector2(150.0f, 10.0f)));
815 application.ProcessEvent(GenerateLongPress(Gesture::Started, 2u, Vector2(150.0f, 10.0f)));
816 application.ProcessEvent(GenerateLongPress(Gesture::Finished, 2u, Vector2(150.0f, 10.0f)));
817 DALI_TEST_EQUALS(true, data.functorCalled, TEST_LOCATION);
818 DALI_TEST_EQUALS(true, second == data.pressedActor, TEST_LOCATION);
820 // LongPress continues as single touch gesture - we should not receive any gesture
822 application.ProcessEvent(GenerateLongPress(Gesture::Possible, 1u, Vector2(150.0f, 10.0f)));
823 application.ProcessEvent(GenerateLongPress(Gesture::Started, 1u, Vector2(150.0f, 10.0f)));
824 application.ProcessEvent(GenerateLongPress(Gesture::Finished, 1u, Vector2(150.0f, 10.0f)));
825 DALI_TEST_EQUALS(false, data.functorCalled, TEST_LOCATION);
827 // Single touch long press starts - first actor should receive gesture
829 application.ProcessEvent(GenerateLongPress(Gesture::Possible, 1u, Vector2(50.0f, 10.0f)));
830 application.ProcessEvent(GenerateLongPress(Gesture::Started, 1u, Vector2(50.0f, 10.0f)));
831 application.ProcessEvent(GenerateLongPress(Gesture::Finished, 1u, Vector2(50.0f, 10.0f)));
832 DALI_TEST_EQUALS(true, data.functorCalled, TEST_LOCATION);
833 DALI_TEST_EQUALS(true, first == data.pressedActor, TEST_LOCATION);
835 // long press changes to double-touch - we shouldn't receive event
837 application.ProcessEvent(GenerateLongPress(Gesture::Possible, 2u, Vector2(50.0f, 10.0f)));
838 application.ProcessEvent(GenerateLongPress(Gesture::Started, 2u, Vector2(50.0f, 10.0f)));
839 application.ProcessEvent(GenerateLongPress(Gesture::Finished, 2u, Vector2(50.0f, 10.0f)));
840 DALI_TEST_EQUALS(false, data.functorCalled, TEST_LOCATION);
842 // Reset gesture manager statistics
843 gestureManager.Initialize();
846 // secondDetector has now been deleted. Gesture detection should have been updated only
847 DALI_TEST_EQUALS(true, gestureManager.WasCalled(TestGestureManager::UpdateType), TEST_LOCATION);
848 DALI_TEST_EQUALS(false, gestureManager.WasCalled(TestGestureManager::RegisterType), TEST_LOCATION);
849 DALI_TEST_EQUALS(false, gestureManager.WasCalled(TestGestureManager::UnregisterType), TEST_LOCATION);
853 int UtcDaliLongPressGestureSignalReceptionMultipleDetectorsOnActor(void)
855 TestApplication application;
857 Actor actor = Actor::New();
858 actor.SetSize(100.0f, 100.0f);
859 actor.SetAnchorPoint(AnchorPoint::TOP_LEFT);
860 Stage::GetCurrent().Add(actor);
863 application.SendNotification();
864 application.Render();
866 // Attach actor to one detector
867 SignalData firstData;
868 GestureReceivedFunctor firstFunctor(firstData);
869 LongPressGestureDetector firstDetector = LongPressGestureDetector::New();
870 firstDetector.Attach(actor);
871 firstDetector.DetectedSignal().Connect(&application, firstFunctor);
873 // Attach actor to another detector
874 SignalData secondData;
875 GestureReceivedFunctor secondFunctor(secondData);
876 LongPressGestureDetector secondDetector = LongPressGestureDetector::New();
877 secondDetector.Attach(actor);
878 secondDetector.DetectedSignal().Connect(&application, secondFunctor);
880 // LongPress in actor's area - both detector's functors should be called
881 application.ProcessEvent(GenerateLongPress(Gesture::Possible, 1u, Vector2(50.0f, 10.0f)));
882 application.ProcessEvent(GenerateLongPress(Gesture::Started, 1u, Vector2(50.0f, 10.0f)));
883 DALI_TEST_EQUALS(true, firstData.functorCalled, TEST_LOCATION);
884 DALI_TEST_EQUALS(true, secondData.functorCalled, TEST_LOCATION);
888 int UtcDaliLongPressGestureSignalReceptionDifferentPossible(void)
890 TestApplication application;
892 Actor actor = Actor::New();
893 actor.SetSize(100.0f, 100.0f);
894 actor.SetAnchorPoint(AnchorPoint::TOP_LEFT);
895 Stage::GetCurrent().Add(actor);
898 application.SendNotification();
899 application.Render();
901 // Attach actor to detector
903 GestureReceivedFunctor functor( data );
904 LongPressGestureDetector detector = LongPressGestureDetector::New();
905 detector.Attach(actor);
906 detector.DetectedSignal().Connect( &application, functor );
908 // LongPress possible in actor's area.
909 application.ProcessEvent(GenerateLongPress(Gesture::Possible, 1u, Vector2(50.0f, 10.0f)));
910 DALI_TEST_EQUALS(false, data.functorCalled, TEST_LOCATION);
912 // Move actor somewhere else
913 actor.SetPosition( 100.0f, 100.0f );
916 application.SendNotification();
917 application.Render();
919 // Emit Started event, we should not receive the long press.
920 application.ProcessEvent(GenerateLongPress(Gesture::Started, 1u, Vector2(50.0f, 10.0f)));
921 application.ProcessEvent(GenerateLongPress(Gesture::Finished, 1u, Vector2(50.0f, 10.0f)));
922 DALI_TEST_EQUALS(false, data.functorCalled, TEST_LOCATION);
924 // LongPress possible in empty area.
925 application.ProcessEvent(GenerateLongPress(Gesture::Possible, 1u, Vector2(50.0f, 10.0f)));
926 DALI_TEST_EQUALS(false, data.functorCalled, TEST_LOCATION);
928 // Move actor in to the long press position.
929 actor.SetPosition( 0.0f, 0.0f );
932 application.SendNotification();
933 application.Render();
935 // Emit Started event, we should not receive the long press.
936 application.ProcessEvent(GenerateLongPress(Gesture::Started, 1u, Vector2(50.0f, 10.0f)));
937 application.ProcessEvent(GenerateLongPress(Gesture::Finished, 1u, Vector2(50.0f, 10.0f)));
938 DALI_TEST_EQUALS(false, data.functorCalled, TEST_LOCATION);
940 // Normal long press in actor's area for completeness.
941 application.ProcessEvent(GenerateLongPress(Gesture::Possible, 1u, Vector2(50.0f, 10.0f)));
942 application.ProcessEvent(GenerateLongPress(Gesture::Started, 1u, Vector2(50.0f, 10.0f)));
943 application.ProcessEvent(GenerateLongPress(Gesture::Finished, 1u, Vector2(50.0f, 10.0f)));
944 DALI_TEST_EQUALS(true, data.functorCalled, TEST_LOCATION);
948 int UtcDaliLongPressGestureEmitIncorrectStateClear(void)
950 TestApplication application;
952 Actor actor = Actor::New();
953 actor.SetSize(100.0f, 100.0f);
954 actor.SetAnchorPoint(AnchorPoint::TOP_LEFT);
955 Stage::GetCurrent().Add(actor);
958 application.SendNotification();
959 application.Render();
961 // Attach actor to detector
963 GestureReceivedFunctor functor( data );
964 LongPressGestureDetector detector = LongPressGestureDetector::New();
965 detector.Attach(actor);
966 detector.DetectedSignal().Connect( &application, functor );
971 application.ProcessEvent(GenerateLongPress(Gesture::Clear, 1u, Vector2(50.0f, 10.0f)));
972 tet_result(TET_FAIL);
974 catch ( Dali::DaliException& e )
976 DALI_TEST_ASSERT( e, "Incorrect state", TEST_LOCATION );
981 int UtcDaliLongPressGestureEmitIncorrectStateContinuing(void)
983 TestApplication application;
985 Actor actor = Actor::New();
986 actor.SetSize(100.0f, 100.0f);
987 actor.SetAnchorPoint(AnchorPoint::TOP_LEFT);
988 Stage::GetCurrent().Add(actor);
991 application.SendNotification();
992 application.Render();
994 // Attach actor to detector
996 GestureReceivedFunctor functor( data );
997 LongPressGestureDetector detector = LongPressGestureDetector::New();
998 detector.Attach(actor);
999 detector.DetectedSignal().Connect( &application, functor );
1001 // Try a Continuing state
1004 application.ProcessEvent(GenerateLongPress(Gesture::Continuing, 1u, Vector2(50.0f, 10.0f)));
1005 tet_result(TET_FAIL);
1007 catch ( Dali::DaliException& e )
1009 DALI_TEST_ASSERT( e, "Incorrect state", TEST_LOCATION );
1014 int UtcDaliLongPressGestureRepeatedState(void)
1016 TestApplication application;
1018 Actor actor = Actor::New();
1019 actor.SetSize(100.0f, 100.0f);
1020 actor.SetAnchorPoint(AnchorPoint::TOP_LEFT);
1021 Stage::GetCurrent().Add(actor);
1023 // Render and notify
1024 application.SendNotification();
1025 application.Render();
1027 // Attach actor to detector
1029 GestureReceivedFunctor functor( data );
1030 LongPressGestureDetector detector = LongPressGestureDetector::New();
1031 detector.Attach(actor);
1032 detector.DetectedSignal().Connect( &application, functor );
1035 application.ProcessEvent(GenerateLongPress(Gesture::Possible, 1u, Vector2(50.0f, 10.0f)));
1036 DALI_TEST_EQUALS(false, data.functorCalled, TEST_LOCATION);
1037 application.ProcessEvent(GenerateLongPress(Gesture::Possible, 1u, Vector2(50.0f, 10.0f)));
1038 DALI_TEST_EQUALS(false, data.functorCalled, TEST_LOCATION);
1040 // ... Send some finished states, still no signal
1041 application.ProcessEvent(GenerateLongPress(Gesture::Finished, 1u, Vector2(50.0f, 10.0f)));
1042 DALI_TEST_EQUALS(false, data.functorCalled, TEST_LOCATION);
1043 application.ProcessEvent(GenerateLongPress(Gesture::Finished, 1u, Vector2(50.0f, 10.0f)));
1044 DALI_TEST_EQUALS(false, data.functorCalled, TEST_LOCATION);
1046 // Send two Started states, should be signalled
1047 application.ProcessEvent(GenerateLongPress(Gesture::Possible, 1u, Vector2(50.0f, 10.0f)));
1048 DALI_TEST_EQUALS(false, data.functorCalled, TEST_LOCATION);
1049 application.ProcessEvent(GenerateLongPress(Gesture::Started, 1u, Vector2(50.0f, 10.0f)));
1050 DALI_TEST_EQUALS(true, data.functorCalled, TEST_LOCATION);
1052 application.ProcessEvent(GenerateLongPress(Gesture::Started, 1u, Vector2(50.0f, 10.0f)));
1053 DALI_TEST_EQUALS(true, data.functorCalled, TEST_LOCATION);
1055 application.ProcessEvent(GenerateLongPress(Gesture::Finished, 1u, Vector2(50.0f, 10.0f)));
1056 DALI_TEST_EQUALS(true, data.functorCalled, TEST_LOCATION);
1059 // Send two cancelled states, should not be signalled
1060 application.ProcessEvent(GenerateLongPress(Gesture::Cancelled, 1u, Vector2(50.0f, 10.0f)));
1061 DALI_TEST_EQUALS(false, data.functorCalled, TEST_LOCATION);
1062 application.ProcessEvent(GenerateLongPress(Gesture::Cancelled, 1u, Vector2(50.0f, 10.0f)));
1063 DALI_TEST_EQUALS(false, data.functorCalled, TEST_LOCATION);
1067 int UtcDaliLongPressGesturePossibleCancelled(void)
1069 TestApplication application;
1071 Actor actor = Actor::New();
1072 actor.SetSize(100.0f, 100.0f);
1073 actor.SetAnchorPoint(AnchorPoint::TOP_LEFT);
1074 Stage::GetCurrent().Add(actor);
1076 // Render and notify
1077 application.SendNotification();
1078 application.Render();
1080 // Attach actor to detector
1082 GestureReceivedFunctor functor( data );
1083 LongPressGestureDetector detector = LongPressGestureDetector::New();
1084 detector.Attach(actor);
1085 detector.DetectedSignal().Connect( &application, functor );
1087 // Send a possible followed by a cancel, we should not be signalled
1088 application.ProcessEvent(GenerateLongPress(Gesture::Possible, 1u, Vector2(50.0f, 10.0f)));
1089 DALI_TEST_EQUALS(false, data.functorCalled, TEST_LOCATION);
1090 application.ProcessEvent(GenerateLongPress(Gesture::Cancelled, 1u, Vector2(50.0f, 10.0f)));
1091 DALI_TEST_EQUALS(false, data.functorCalled, TEST_LOCATION);
1095 int UtcDaliLongPressGestureDetachAfterStarted(void)
1097 TestApplication application;
1099 Actor actor = Actor::New();
1100 actor.SetSize(100.0f, 100.0f);
1101 actor.SetAnchorPoint(AnchorPoint::TOP_LEFT);
1102 Stage::GetCurrent().Add(actor);
1104 // Render and notify
1105 application.SendNotification();
1106 application.Render();
1108 // Attach actor to detector
1110 GestureReceivedFunctor functor( data );
1111 LongPressGestureDetector detector = LongPressGestureDetector::New();
1112 detector.Attach(actor);
1113 detector.DetectedSignal().Connect( &application, functor );
1115 // Emit initial signal
1116 application.ProcessEvent(GenerateLongPress(Gesture::Possible, 1u, Vector2(50.0f, 10.0f)));
1117 application.ProcessEvent(GenerateLongPress(Gesture::Started, 1u, Vector2(50.0f, 10.0f)));
1118 DALI_TEST_EQUALS(true, data.functorCalled, TEST_LOCATION);
1122 detector.Detach(actor);
1124 // Emit Finished, no signal
1125 application.ProcessEvent(GenerateLongPress(Gesture::Finished, 1u, Vector2(50.0f, 10.0f)));
1126 DALI_TEST_EQUALS(false, data.functorCalled, TEST_LOCATION);
1130 int UtcDaliLongPressGestureActorUnstaged(void)
1132 TestApplication application;
1134 Actor actor = Actor::New();
1135 actor.SetSize(100.0f, 100.0f);
1136 actor.SetAnchorPoint(AnchorPoint::TOP_LEFT);
1137 Stage::GetCurrent().Add(actor);
1139 // Render and notify
1140 application.SendNotification();
1141 application.Render();
1143 // State to remove actor in.
1144 Gesture::State stateToUnstage( Gesture::Started );
1146 // Attach actor to detector
1148 UnstageActorFunctor functor( data, stateToUnstage );
1149 LongPressGestureDetector detector = LongPressGestureDetector::New();
1150 detector.Attach(actor);
1151 detector.DetectedSignal().Connect( &application, functor );
1154 application.ProcessEvent(GenerateLongPress(Gesture::Possible, 1u, Vector2(50.0f, 10.0f)));
1155 application.ProcessEvent(GenerateLongPress(Gesture::Started, 1u, Vector2(50.0f, 10.0f)));
1156 DALI_TEST_EQUALS(true, data.functorCalled, TEST_LOCATION);
1158 application.ProcessEvent(GenerateLongPress(Gesture::Finished, 1u, Vector2(50.0f, 10.0f)));
1159 DALI_TEST_EQUALS(false, data.functorCalled, TEST_LOCATION);
1161 // Render and notify
1162 application.SendNotification();
1163 application.Render();
1165 // Re-add actor to stage
1166 Stage::GetCurrent().Add(actor);
1168 // Render and notify
1169 application.SendNotification();
1170 application.Render();
1172 // Change state to Gesture::Continuing to remove
1173 stateToUnstage = Gesture::Finished;
1176 application.ProcessEvent(GenerateLongPress(Gesture::Possible, 1u, Vector2(50.0f, 10.0f)));
1177 application.ProcessEvent(GenerateLongPress(Gesture::Started, 1u, Vector2(50.0f, 10.0f)));
1178 DALI_TEST_EQUALS(true, data.functorCalled, TEST_LOCATION);
1180 application.ProcessEvent(GenerateLongPress(Gesture::Finished, 1u, Vector2(50.0f, 10.0f)));
1181 DALI_TEST_EQUALS(true, data.functorCalled, TEST_LOCATION);
1182 tet_result( TET_PASS ); // If we get here then we have handled actor stage removal gracefully.
1186 int UtcDaliLongPressGestureActorStagedAndDestroyed(void)
1188 TestApplication application;
1190 Actor actor = Actor::New();
1191 actor.SetSize(100.0f, 100.0f);
1192 actor.SetAnchorPoint(AnchorPoint::TOP_LEFT);
1193 Stage::GetCurrent().Add(actor);
1195 // Create and add a second actor so that GestureDetector destruction does not come into play.
1196 Actor dummyActor( Actor::New() );
1197 dummyActor.SetSize( 100.0f, 100.0f );
1198 dummyActor.SetPosition( 100.0f, 100.0f );
1199 dummyActor.SetAnchorPoint(AnchorPoint::TOP_LEFT);
1200 Stage::GetCurrent().Add(dummyActor);
1202 // Render and notify
1203 application.SendNotification();
1204 application.Render();
1206 // State to remove actor in.
1207 Gesture::State stateToUnstage( Gesture::Started );
1209 // Attach actor to detector
1211 UnstageActorFunctor functor( data, stateToUnstage );
1212 LongPressGestureDetector detector = LongPressGestureDetector::New();
1213 detector.Attach(actor);
1214 detector.Attach(dummyActor);
1215 detector.DetectedSignal().Connect( &application, functor );
1217 // Here we are testing a Started actor which is removed in the Started callback, but then added back
1218 // before we get a finished state. As we were removed from the stage, even if we're at the same
1219 // position, we should still not be signalled.
1222 application.ProcessEvent(GenerateLongPress(Gesture::Possible, 1u, Vector2(50.0f, 10.0f)));
1223 application.ProcessEvent(GenerateLongPress(Gesture::Started, 1u, Vector2(50.0f, 10.0f)));
1224 DALI_TEST_EQUALS(true, data.functorCalled, TEST_LOCATION);
1227 // Render and notify
1228 application.SendNotification();
1229 application.Render();
1231 // Re add to the stage, we should not be signalled
1232 Stage::GetCurrent().Add(actor);
1234 // Render and notify
1235 application.SendNotification();
1236 application.Render();
1238 // Continue signal emission
1239 application.ProcessEvent(GenerateLongPress(Gesture::Finished, 1u, Vector2(50.0f, 10.0f)));
1240 DALI_TEST_EQUALS(false, data.functorCalled, TEST_LOCATION);
1243 // Here we delete an actor in started, we should not receive any subsequent signalling.
1246 application.ProcessEvent(GenerateLongPress(Gesture::Possible, 1u, Vector2(50.0f, 10.0f)));
1247 application.ProcessEvent(GenerateLongPress(Gesture::Started, 1u, Vector2(50.0f, 10.0f)));
1248 DALI_TEST_EQUALS(true, data.functorCalled, TEST_LOCATION);
1251 // Render and notify
1252 application.SendNotification();
1253 application.Render();
1255 // Delete actor as well
1258 // Render and notify
1259 application.SendNotification();
1260 application.Render();
1262 // Continue signal emission
1263 application.ProcessEvent(GenerateLongPress(Gesture::Finished, 1u, Vector2(50.0f, 10.0f)));
1264 DALI_TEST_EQUALS(false, data.functorCalled, TEST_LOCATION);
1268 int UtcDaliLongPressGestureSystemOverlay(void)
1270 TestApplication application;
1271 Dali::Integration::Core& core = application.GetCore();
1272 Dali::Integration::SystemOverlay& systemOverlay( core.GetSystemOverlay() );
1274 Dali::RenderTaskList overlayRenderTaskList = Integration::RenderTaskList::New();
1275 Dali::Actor overlayRootActor = systemOverlay.GetDefaultRootActor();
1276 Dali::CameraActor overlayCameraActor = systemOverlay.GetDefaultCameraActor();
1277 Integration::RenderTaskList::CreateTask( overlayRenderTaskList, overlayRootActor, overlayCameraActor );
1278 systemOverlay.SetOverlayRenderTasks( overlayRenderTaskList );
1280 Actor actor = Actor::New();
1281 actor.SetSize(100.0f, 100.0f);
1282 actor.SetAnchorPoint(AnchorPoint::TOP_LEFT);
1283 systemOverlay.Add(actor);
1285 // Render and notify
1286 application.SendNotification();
1287 application.Render();
1290 GestureReceivedFunctor functor(data);
1292 LongPressGestureDetector detector = LongPressGestureDetector::New();
1293 detector.Attach(actor);
1294 detector.DetectedSignal().Connect(&application, functor);
1296 // Do a long press inside actor's area
1297 Vector2 screenCoords( 50.0f, 50.0f );
1298 application.ProcessEvent( GenerateLongPress( Gesture::Possible, 1u, screenCoords ) );
1299 application.ProcessEvent( GenerateLongPress( Gesture::Started, 1u, screenCoords ) );
1300 DALI_TEST_EQUALS( true, data.functorCalled, TEST_LOCATION );
1304 int UtcDaliLongPressGestureBehindTouchableSystemOverlay(void)
1306 TestApplication application;
1307 Dali::Integration::Core& core = application.GetCore();
1308 Dali::Integration::SystemOverlay& systemOverlay( core.GetSystemOverlay() );
1310 Dali::RenderTaskList overlayRenderTaskList = Integration::RenderTaskList::New();
1311 Dali::Actor overlayRootActor = systemOverlay.GetDefaultRootActor();
1312 Dali::CameraActor overlayCameraActor = systemOverlay.GetDefaultCameraActor();
1313 Integration::RenderTaskList::CreateTask( overlayRenderTaskList, overlayRootActor, overlayCameraActor );
1314 systemOverlay.SetOverlayRenderTasks( overlayRenderTaskList );
1316 // SystemOverlay actor
1317 Actor systemOverlayActor = Actor::New();
1318 systemOverlayActor.SetSize(100.0f, 100.0f);
1319 systemOverlayActor.SetAnchorPoint(AnchorPoint::TOP_LEFT);
1320 systemOverlay.Add(systemOverlayActor);
1323 Actor stageActor = Actor::New();
1324 stageActor.SetSize(100.0f, 100.0f);
1325 stageActor.SetAnchorPoint(AnchorPoint::TOP_LEFT);
1326 Stage::GetCurrent().Add(stageActor);
1328 // Render and notify
1329 application.SendNotification();
1330 application.Render();
1332 // Set system-overlay actor to touchable
1333 TouchEventData touchData;
1334 TouchEventDataFunctor touchFunctor( touchData );
1335 systemOverlayActor.TouchedSignal().Connect(&application, touchFunctor);
1337 // Set stage actor to receive the gesture
1339 GestureReceivedFunctor functor(data);
1341 LongPressGestureDetector detector = LongPressGestureDetector::New();
1342 detector.Attach(stageActor);
1343 detector.DetectedSignal().Connect(&application, functor);
1345 // Start long press within the two actors' area
1346 Vector2 screenCoords( 50.0f, 50.0f );
1347 application.ProcessEvent( GenerateLongPress( Gesture::Possible, 1u, screenCoords ) );
1348 application.ProcessEvent( GenerateLongPress( Gesture::Started, 1u, screenCoords ) );
1349 DALI_TEST_EQUALS( true, data.functorCalled, TEST_LOCATION );
1350 DALI_TEST_EQUALS( false, touchData.functorCalled, TEST_LOCATION );
1355 // Do touch in the same area
1356 application.ProcessEvent( touchFunctor.GenerateSingleTouch( PointState::DOWN, screenCoords ) );
1357 DALI_TEST_EQUALS( false, data.functorCalled, TEST_LOCATION );
1358 DALI_TEST_EQUALS( true, touchData.functorCalled, TEST_LOCATION );
1363 int UtcDaliLongPressGestureTouchBehindGesturedSystemOverlay(void)
1365 TestApplication application;
1366 Dali::Integration::Core& core = application.GetCore();
1367 Dali::Integration::SystemOverlay& systemOverlay( core.GetSystemOverlay() );
1369 Dali::RenderTaskList overlayRenderTaskList = Integration::RenderTaskList::New();
1370 Dali::Actor overlayRootActor = systemOverlay.GetDefaultRootActor();
1371 Dali::CameraActor overlayCameraActor = systemOverlay.GetDefaultCameraActor();
1372 Integration::RenderTaskList::CreateTask( overlayRenderTaskList, overlayRootActor, overlayCameraActor );
1373 systemOverlay.SetOverlayRenderTasks( overlayRenderTaskList );
1375 // SystemOverlay actor
1376 Actor systemOverlayActor = Actor::New();
1377 systemOverlayActor.SetSize(100.0f, 100.0f);
1378 systemOverlayActor.SetAnchorPoint(AnchorPoint::TOP_LEFT);
1379 systemOverlay.Add(systemOverlayActor);
1382 Actor stageActor = Actor::New();
1383 stageActor.SetSize(100.0f, 100.0f);
1384 stageActor.SetAnchorPoint(AnchorPoint::TOP_LEFT);
1385 Stage::GetCurrent().Add(stageActor);
1387 // Render and notify
1388 application.SendNotification();
1389 application.Render();
1391 // Set stage actor to touchable
1392 TouchEventData touchData;
1393 TouchEventDataFunctor touchFunctor( touchData );
1394 stageActor.TouchedSignal().Connect(&application, touchFunctor);
1396 // Set system-overlay actor to have the gesture
1398 GestureReceivedFunctor functor(data);
1400 LongPressGestureDetector detector = LongPressGestureDetector::New();
1401 detector.Attach(systemOverlayActor);
1402 detector.DetectedSignal().Connect(&application, functor);
1404 // Start long press within the two actors' area
1405 Vector2 screenCoords( 50.0f, 50.0f );
1406 application.ProcessEvent( GenerateLongPress( Gesture::Possible, 1u, screenCoords ) );
1407 application.ProcessEvent( GenerateLongPress( Gesture::Started, 1u, screenCoords ) );
1408 DALI_TEST_EQUALS( true, data.functorCalled, TEST_LOCATION );
1409 DALI_TEST_EQUALS( false, touchData.functorCalled, TEST_LOCATION );
1414 // Do touch in the same area
1415 application.ProcessEvent( touchFunctor.GenerateSingleTouch( PointState::DOWN, screenCoords ) );
1416 DALI_TEST_EQUALS( false, data.functorCalled, TEST_LOCATION );
1417 DALI_TEST_EQUALS( true, touchData.functorCalled, TEST_LOCATION );
1422 int UtcDaliLongPressGestureLayerConsumesTouch(void)
1424 TestApplication application;
1426 Actor actor = Actor::New();
1427 actor.SetSize(100.0f, 100.0f);
1428 actor.SetAnchorPoint(AnchorPoint::TOP_LEFT);
1429 Stage::GetCurrent().Add(actor);
1433 GestureReceivedFunctor functor(data);
1434 LongPressGestureDetector detector = LongPressGestureDetector::New();
1435 detector.Attach(actor);
1436 detector.DetectedSignal().Connect( &application, functor );
1438 // Add a layer to overlap the actor
1439 Layer layer = Layer::New();
1440 layer.SetSize(100.0f, 100.0f);
1441 layer.SetAnchorPoint(AnchorPoint::TOP_LEFT);
1442 Stage::GetCurrent().Add( layer );
1445 // Render and notify
1446 application.SendNotification();
1447 application.Render();
1449 Vector2 screenCoords( 50.0f, 50.0f );
1451 // Emit signals, should receive
1452 application.ProcessEvent( GenerateLongPress( Gesture::Possible, 1u, screenCoords ) );
1453 application.ProcessEvent( GenerateLongPress( Gesture::Started, 1u, screenCoords ) );
1454 application.ProcessEvent( GenerateLongPress( Gesture::Finished, 1u, screenCoords ) );
1455 DALI_TEST_EQUALS(true, data.functorCalled, TEST_LOCATION);
1458 // Set layer to consume all touch
1459 layer.SetTouchConsumed( true );
1461 // Render and notify
1462 application.SendNotification();
1463 application.Render();
1465 // Emit the same signals again, should not receive
1466 application.ProcessEvent( GenerateLongPress( Gesture::Possible, 1u, screenCoords ) );
1467 application.ProcessEvent( GenerateLongPress( Gesture::Started, 1u, screenCoords ) );
1468 application.ProcessEvent( GenerateLongPress( Gesture::Finished, 1u, screenCoords ) );
1469 DALI_TEST_EQUALS(false, data.functorCalled, TEST_LOCATION);