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-test-suite-utils.h>
26 #include <test-touch-utils.h>
30 void utc_dali_long_press_gesture_detector_startup(void)
32 test_return_value = TET_UNDEF;
35 void utc_dali_long_press_gesture_detector_cleanup(void)
37 test_return_value = TET_PASS;
40 ///////////////////////////////////////////////////////////////////////////////
44 // Stores data that is populated in the callback and will be read by the TET cases
48 : functorCalled( false ),
49 voidFunctorCalled( false ),
50 receivedGesture( Gesture::Clear ),
56 functorCalled = false;
57 voidFunctorCalled = false;
59 receivedGesture.numberOfTouches = 0u;
60 receivedGesture.screenPoint = Vector2(0.0f, 0.0f);
61 receivedGesture.localPoint = Vector2(0.0f, 0.0f);
67 bool voidFunctorCalled;
68 LongPressGesture receivedGesture;
72 // Functor that sets the data when called
73 struct GestureReceivedFunctor
75 GestureReceivedFunctor(SignalData& data) : signalData(data) { }
77 void operator()(Actor actor, const LongPressGesture& longPress)
79 signalData.functorCalled = true;
80 signalData.receivedGesture = longPress;
81 signalData.pressedActor = actor;
86 signalData.voidFunctorCalled = true;
89 SignalData& signalData;
92 // Functor that removes the gestured actor from stage
93 struct UnstageActorFunctor : public GestureReceivedFunctor
95 UnstageActorFunctor( SignalData& data, Gesture::State& stateToUnstage )
96 : GestureReceivedFunctor( data ),
97 stateToUnstage( stateToUnstage )
101 void operator()( Actor actor, const LongPressGesture& longPress )
103 GestureReceivedFunctor::operator()( actor, longPress );
105 if ( longPress.state == stateToUnstage )
107 Stage::GetCurrent().Remove( actor );
111 Gesture::State& stateToUnstage;
114 // Functor for receiving a touch event
115 struct TouchEventFunctor
117 bool operator()(Actor actor, const TouchEvent& touch)
120 unsigned int points = touch.GetPointCount();
123 const TouchPoint& touchPoint = touch.GetPoint(0);
124 tet_printf("Touch Point state = %d\n", touchPoint.state);
130 // Generate a LongPressGestureEvent to send to Core
131 Integration::LongPressGestureEvent GenerateLongPress(
132 Gesture::State state,
133 unsigned int numberOfTouches,
136 Integration::LongPressGestureEvent longPress( state );
138 longPress.numberOfTouches = numberOfTouches;
139 longPress.point = point;
146 ///////////////////////////////////////////////////////////////////////////////
149 // Positive test case for a method
150 int UtcDaliLongPressGestureDetectorConstructor(void)
152 TestApplication application;
154 LongPressGestureDetector detector;
155 DALI_TEST_CHECK(!detector);
159 int UtcDaliLongPressGestureDetectorCopyConstructorP(void)
161 TestApplication application;
163 LongPressGestureDetector detector = LongPressGestureDetector::New();;
165 LongPressGestureDetector copy( detector );
166 DALI_TEST_CHECK( detector );
170 int UtcDaliLongPressGestureDetectorAssignmentOperatorP(void)
172 TestApplication application;
174 LongPressGestureDetector detector = LongPressGestureDetector::New();;
176 LongPressGestureDetector copy = detector;
177 DALI_TEST_CHECK( detector );
179 DALI_TEST_CHECK( detector == copy );
183 int UtcDaliLongPressGestureDetectorNew(void)
185 TestApplication application;
187 LongPressGestureDetector detector = LongPressGestureDetector::New();
188 DALI_TEST_CHECK(detector);
189 DALI_TEST_EQUALS(1u, detector.GetMinimumTouchesRequired(), TEST_LOCATION);
190 DALI_TEST_EQUALS(1u, detector.GetMaximumTouchesRequired(), TEST_LOCATION);
192 LongPressGestureDetector detector2 = LongPressGestureDetector::New(5u);
193 DALI_TEST_CHECK(detector2);
194 DALI_TEST_EQUALS(5u, detector2.GetMinimumTouchesRequired(), TEST_LOCATION);
195 DALI_TEST_EQUALS(5u, detector2.GetMaximumTouchesRequired(), TEST_LOCATION);
197 LongPressGestureDetector detector3 = LongPressGestureDetector::New(5u, 7u);
198 DALI_TEST_CHECK(detector2);
199 DALI_TEST_EQUALS(5u, detector3.GetMinimumTouchesRequired(), TEST_LOCATION);
200 DALI_TEST_EQUALS(7u, detector3.GetMaximumTouchesRequired(), TEST_LOCATION);
202 //Scoped test to test destructor
204 LongPressGestureDetector detector4 = LongPressGestureDetector::New();
205 DALI_TEST_CHECK(detector4);
208 // Attach an actor and emit a touch event on the actor to ensure complete line coverage
209 Actor actor = Actor::New();
210 actor.SetSize(100.0f, 100.0f);
211 actor.SetAnchorPoint(AnchorPoint::TOP_LEFT);
212 Stage::GetCurrent().Add(actor);
215 application.SendNotification();
216 application.Render();
218 detector.Attach(actor);
220 TouchEventFunctor touchFunctor;
221 actor.TouchedSignal().Connect(&application, touchFunctor);
223 Integration::TouchEvent touchEvent(1);
224 TouchPoint point(1, TouchPoint::Down, 20.0f, 20.0f);
225 touchEvent.AddPoint(point);
226 application.ProcessEvent(touchEvent);
229 application.SendNotification();
230 application.Render();
232 // For line coverage, Initialise default constructor
233 TouchEvent touchEvent2;
237 int UtcDaliLongPressGestureDetectorDownCast(void)
239 TestApplication application;
240 tet_infoline("Testing Dali::LongPressGestureDetector::DownCast()");
242 LongPressGestureDetector detector = LongPressGestureDetector::New();
244 BaseHandle object(detector);
246 LongPressGestureDetector detector2 = LongPressGestureDetector::DownCast(object);
247 DALI_TEST_CHECK(detector2);
249 LongPressGestureDetector detector3 = DownCast< LongPressGestureDetector >(object);
250 DALI_TEST_CHECK(detector3);
252 BaseHandle unInitializedObject;
253 LongPressGestureDetector detector4 = LongPressGestureDetector::DownCast(unInitializedObject);
254 DALI_TEST_CHECK(!detector4);
256 LongPressGestureDetector detector5 = DownCast< LongPressGestureDetector >(unInitializedObject);
257 DALI_TEST_CHECK(!detector5);
259 GestureDetector detector6 = LongPressGestureDetector::New();
260 LongPressGestureDetector detector7 = LongPressGestureDetector::DownCast(detector6);
261 DALI_TEST_CHECK(detector7);
265 int UtcDaliLongPressGestureSetTouchesRequired01(void)
267 TestApplication application;
269 LongPressGestureDetector detector = LongPressGestureDetector::New();
271 unsigned int touches = 3;
273 DALI_TEST_CHECK(touches != detector.GetMinimumTouchesRequired());
274 DALI_TEST_CHECK(touches != detector.GetMaximumTouchesRequired());
276 detector.SetTouchesRequired(touches);
278 DALI_TEST_EQUALS(touches, detector.GetMinimumTouchesRequired(), TEST_LOCATION);
279 DALI_TEST_EQUALS(touches, detector.GetMaximumTouchesRequired(), TEST_LOCATION);
281 // Attach an actor and change the required touches
283 Actor actor = Actor::New();
284 actor.SetSize(100.0f, 100.0f);
285 actor.SetAnchorPoint(AnchorPoint::TOP_LEFT);
286 Stage::GetCurrent().Add(actor);
289 application.SendNotification();
290 application.Render();
293 GestureReceivedFunctor functor(data);
295 detector.Attach(actor);
296 detector.DetectedSignal().Connect(&application, functor);
298 TestGestureManager& gestureManager = application.GetGestureManager();
299 gestureManager.Initialize();
301 detector.SetTouchesRequired(4);
303 // Gesture detection should have been updated only
304 DALI_TEST_EQUALS(true, gestureManager.WasCalled(TestGestureManager::UpdateType), TEST_LOCATION);
305 DALI_TEST_EQUALS(false, gestureManager.WasCalled(TestGestureManager::RegisterType), TEST_LOCATION);
306 DALI_TEST_EQUALS(false, gestureManager.WasCalled(TestGestureManager::UnregisterType), TEST_LOCATION);
309 gestureManager.Initialize();
311 // Create a second gesture detector that requires even less maximum touches
312 LongPressGestureDetector secondDetector = LongPressGestureDetector::New();
313 secondDetector.Attach(actor);
315 // Gesture detection should have been updated
316 DALI_TEST_EQUALS(true, gestureManager.WasCalled(TestGestureManager::UpdateType), TEST_LOCATION);
317 DALI_TEST_EQUALS(false, gestureManager.WasCalled(TestGestureManager::RegisterType), TEST_LOCATION);
318 DALI_TEST_EQUALS(false, gestureManager.WasCalled(TestGestureManager::UnregisterType), TEST_LOCATION);
322 int UtcDaliLongPressGestureSetTouchesRequired02(void)
324 TestApplication application;
326 LongPressGestureDetector detector = LongPressGestureDetector::New();
328 unsigned int min = 3;
329 unsigned int max = 5;
331 DALI_TEST_CHECK(min != detector.GetMinimumTouchesRequired());
332 DALI_TEST_CHECK(max != detector.GetMaximumTouchesRequired());
334 detector.SetTouchesRequired(min, max);
336 DALI_TEST_EQUALS(min, detector.GetMinimumTouchesRequired(), TEST_LOCATION);
337 DALI_TEST_EQUALS(max, detector.GetMaximumTouchesRequired(), TEST_LOCATION);
339 // Attach an actor and change the maximum touches
341 Actor actor = Actor::New();
342 actor.SetSize(100.0f, 100.0f);
343 actor.SetAnchorPoint(AnchorPoint::TOP_LEFT);
344 Stage::GetCurrent().Add(actor);
347 application.SendNotification();
348 application.Render();
351 GestureReceivedFunctor functor(data);
353 detector.Attach(actor);
354 detector.DetectedSignal().Connect(&application, functor);
356 TestGestureManager& gestureManager = application.GetGestureManager();
357 gestureManager.Initialize();
359 detector.SetTouchesRequired(4, 5);
361 // Gesture detection should have been updated only
362 DALI_TEST_EQUALS(true, gestureManager.WasCalled(TestGestureManager::UpdateType), TEST_LOCATION);
363 DALI_TEST_EQUALS(false, gestureManager.WasCalled(TestGestureManager::RegisterType), TEST_LOCATION);
364 DALI_TEST_EQUALS(false, gestureManager.WasCalled(TestGestureManager::UnregisterType), TEST_LOCATION);
367 gestureManager.Initialize();
369 // Create a second gesture detector that requires even less maximum touches
370 LongPressGestureDetector secondDetector = LongPressGestureDetector::New();
371 secondDetector.Attach(actor);
373 // Gesture detection should have been updated
374 DALI_TEST_EQUALS(true, gestureManager.WasCalled(TestGestureManager::UpdateType), TEST_LOCATION);
375 DALI_TEST_EQUALS(false, gestureManager.WasCalled(TestGestureManager::RegisterType), TEST_LOCATION);
376 DALI_TEST_EQUALS(false, gestureManager.WasCalled(TestGestureManager::UnregisterType), TEST_LOCATION);
380 int UtcDaliLongPressGestureGetMinimumTouchesRequired(void)
382 TestApplication application;
384 LongPressGestureDetector detector = LongPressGestureDetector::New();
385 DALI_TEST_EQUALS(1u, detector.GetMinimumTouchesRequired(), TEST_LOCATION);
389 int UtcDaliLongPressGestureGetMaximumTouchesRequired(void)
391 TestApplication application;
393 LongPressGestureDetector detector = LongPressGestureDetector::New();
394 DALI_TEST_EQUALS(1u, detector.GetMaximumTouchesRequired(), TEST_LOCATION);
398 int UtcDaliLongPressGestureSignalReceptionNegative(void)
400 TestApplication application;
402 Actor actor = Actor::New();
403 actor.SetSize(100.0f, 100.0f);
404 actor.SetAnchorPoint(AnchorPoint::TOP_LEFT);
405 Stage::GetCurrent().Add(actor);
408 application.SendNotification();
409 application.Render();
412 GestureReceivedFunctor functor(data);
414 LongPressGestureDetector detector = LongPressGestureDetector::New();
415 detector.Attach(actor);
416 detector.DetectedSignal().Connect(&application, functor);
418 // Do a long press outside actor's area
419 application.ProcessEvent( GenerateLongPress( Gesture::Possible, 1u, Vector2(112.0f, 112.0f ) ) );
420 application.ProcessEvent( GenerateLongPress( Gesture::Started, 1u, Vector2(112.0f, 112.0f ) ) );
421 application.ProcessEvent( GenerateLongPress( Gesture::Finished, 1u, Vector2(112.0f, 112.0f ) ) );
422 DALI_TEST_EQUALS(false, data.functorCalled, TEST_LOCATION);
426 int UtcDaliLongPressGestureSignalReceptionPositive(void)
428 TestApplication application;
430 Actor actor = Actor::New();
431 actor.SetSize(100.0f, 100.0f);
432 actor.SetAnchorPoint(AnchorPoint::TOP_LEFT);
433 Stage::GetCurrent().Add(actor);
436 application.SendNotification();
437 application.Render();
440 GestureReceivedFunctor functor(data);
442 LongPressGestureDetector detector = LongPressGestureDetector::New();
443 detector.Attach(actor);
444 detector.DetectedSignal().Connect(&application, functor);
446 // Do a long press inside actor's area
447 application.ProcessEvent(GenerateLongPress(Gesture::Possible, 1u, Vector2(50.0f, 50.0f)));
448 application.ProcessEvent(GenerateLongPress(Gesture::Started, 1u, Vector2(50.0f, 50.0f)));
449 DALI_TEST_EQUALS(true, data.functorCalled, TEST_LOCATION);
450 DALI_TEST_EQUALS(1u, data.receivedGesture.numberOfTouches, TEST_LOCATION);
451 DALI_TEST_EQUALS( Vector2(50.0f, 50.0f), data.receivedGesture.localPoint, 0.1, TEST_LOCATION);
452 application.ProcessEvent(GenerateLongPress(Gesture::Finished, 1u, Vector2(50.0f, 50.0f)));
456 int UtcDaliLongPressGestureSignalReceptionDetach(void)
458 TestApplication application;
460 Actor actor = Actor::New();
461 actor.SetSize(100.0f, 100.0f);
462 actor.SetAnchorPoint(AnchorPoint::TOP_LEFT);
463 Stage::GetCurrent().Add(actor);
466 application.SendNotification();
467 application.Render();
470 GestureReceivedFunctor functor(data);
472 LongPressGestureDetector detector = LongPressGestureDetector::New();
473 detector.Attach(actor);
474 detector.DetectedSignal().Connect(&application, functor);
476 // Start long press within the actor's area
477 application.ProcessEvent(GenerateLongPress(Gesture::Possible, 1u, Vector2(20.0f, 20.0f)));
478 application.ProcessEvent(GenerateLongPress(Gesture::Started, 1u, Vector2(20.0f, 20.0f)));
479 DALI_TEST_EQUALS(true, data.functorCalled, TEST_LOCATION);
480 DALI_TEST_EQUALS(1u, data.receivedGesture.numberOfTouches, TEST_LOCATION);
481 DALI_TEST_EQUALS( Vector2(20.0f, 20.0f), data.receivedGesture.localPoint, 0.1, TEST_LOCATION);
482 application.ProcessEvent(GenerateLongPress(Gesture::Finished, 1u, Vector2(20.0f, 20.0f)));
484 // repeat the long press within the actor's area - we should still receive the signal
486 application.ProcessEvent(GenerateLongPress(Gesture::Possible, 1u, Vector2(50.0f, 50.0f)));
487 application.ProcessEvent(GenerateLongPress(Gesture::Started, 1u, Vector2(50.0f, 50.0f)));
488 DALI_TEST_EQUALS(true, data.functorCalled, TEST_LOCATION);
489 DALI_TEST_EQUALS(1u, data.receivedGesture.numberOfTouches, TEST_LOCATION);
490 DALI_TEST_EQUALS( Vector2(50.0f, 50.0f), data.receivedGesture.localPoint, 0.1, TEST_LOCATION);
491 application.ProcessEvent(GenerateLongPress(Gesture::Finished, 1u, Vector2(50.0f, 50.0f)));
494 detector.DetachAll();
496 // Ensure we are no longer signalled
498 application.ProcessEvent(GenerateLongPress(Gesture::Possible, 1u, Vector2(20.0f, 20.0f)));
499 application.ProcessEvent(GenerateLongPress(Gesture::Started, 1u, Vector2(20.0f, 20.0f)));
500 DALI_TEST_EQUALS(false, data.functorCalled, TEST_LOCATION);
501 application.ProcessEvent(GenerateLongPress(Gesture::Finished, 1u, Vector2(50.0f, 50.0f)));
502 DALI_TEST_EQUALS(false, data.functorCalled, TEST_LOCATION);
506 int UtcDaliLongPressGestureSignalReceptionActorDestroyedDuringLongPress(void)
508 TestApplication application;
511 GestureReceivedFunctor functor(data);
513 LongPressGestureDetector detector = LongPressGestureDetector::New();
514 detector.DetectedSignal().Connect(&application, functor);
516 // Actor lifetime is scoped
518 Actor actor = Actor::New();
519 actor.SetSize(100.0f, 100.0f);
520 actor.SetAnchorPoint(AnchorPoint::TOP_LEFT);
521 Stage::GetCurrent().Add(actor);
524 application.SendNotification();
525 application.Render();
527 detector.Attach(actor);
529 // Start long press within the actor's area
530 application.ProcessEvent(GenerateLongPress(Gesture::Possible, 1u, Vector2(20.0f, 20.0f)));
531 application.ProcessEvent(GenerateLongPress(Gesture::Started, 1u, Vector2(20.0f, 20.0f)));
532 DALI_TEST_EQUALS(true, data.functorCalled, TEST_LOCATION);
534 // Remove the actor from stage and reset the data
535 Stage::GetCurrent().Remove(actor);
538 application.SendNotification();
539 application.Render();
542 // Actor should now have been destroyed
545 application.ProcessEvent(GenerateLongPress(Gesture::Finished, 1u, Vector2(20.0f, 20.0f)));
546 DALI_TEST_EQUALS(false, data.functorCalled, TEST_LOCATION);
550 int UtcDaliLongPressGestureSignalReceptionRotatedActor(void)
552 TestApplication application;
554 Actor actor = Actor::New();
555 actor.SetSize(100.0f, 100.0f);
556 actor.SetOrientation(Dali::Degree(90.0f), Vector3::ZAXIS);
557 Stage::GetCurrent().Add(actor);
560 application.SendNotification();
561 application.Render();
564 GestureReceivedFunctor functor(data);
566 LongPressGestureDetector detector = LongPressGestureDetector::New();
567 detector.Attach(actor);
568 detector.DetectedSignal().Connect(&application, functor);
571 application.ProcessEvent(GenerateLongPress(Gesture::Possible, 1u, Vector2(5.0f, 5.0f)));
572 application.ProcessEvent(GenerateLongPress(Gesture::Started, 1u, Vector2(5.0f, 5.0f)));
573 application.ProcessEvent(GenerateLongPress(Gesture::Finished, 1u, Vector2(5.0f, 5.0f)));
574 DALI_TEST_EQUALS(true, data.functorCalled, TEST_LOCATION);
575 DALI_TEST_EQUALS(1u, data.receivedGesture.numberOfTouches, TEST_LOCATION);
576 DALI_TEST_EQUALS( Vector2(5.0f, 5.0f), data.receivedGesture.screenPoint, 0.1, TEST_LOCATION);
578 // Rotate actor again and render
579 actor.SetOrientation(Dali::Degree(180.0f), Vector3::ZAXIS);
580 application.SendNotification();
581 application.Render();
583 // Do another long press, should still receive event
585 application.ProcessEvent(GenerateLongPress(Gesture::Possible, 1u, Vector2(5.0f, 5.0f)));
586 application.ProcessEvent(GenerateLongPress(Gesture::Started, 1u, Vector2(5.0f, 5.0f)));
587 application.ProcessEvent(GenerateLongPress(Gesture::Finished, 1u, Vector2(5.0f, 5.0f)));
588 DALI_TEST_EQUALS(true, data.functorCalled, TEST_LOCATION);
589 DALI_TEST_EQUALS(1u, data.receivedGesture.numberOfTouches, TEST_LOCATION);
590 DALI_TEST_EQUALS( Vector2(5.0f, 5.0f), data.receivedGesture.screenPoint, 0.1, TEST_LOCATION);
592 // Rotate actor again and render
593 actor.SetOrientation(Dali::Degree(90.0f), Vector3::YAXIS);
594 application.SendNotification();
595 application.Render();
597 // Do a long press, inside where the actor used to be, Should not receive the event
599 application.ProcessEvent(GenerateLongPress(Gesture::Possible, 1u, Vector2(70.0f, 70.0f)));
600 application.ProcessEvent(GenerateLongPress(Gesture::Started, 1u, Vector2(70.0f, 70.0f)));
601 application.ProcessEvent(GenerateLongPress(Gesture::Finished, 1u, Vector2(70.0f, 70.0f)));
602 DALI_TEST_EQUALS(false, data.functorCalled, TEST_LOCATION);
606 int UtcDaliLongPressGestureSignalReceptionChildHit(void)
608 TestApplication application;
610 Actor parent = Actor::New();
611 parent.SetSize(100.0f, 100.0f);
612 parent.SetAnchorPoint(AnchorPoint::TOP_LEFT);
613 Stage::GetCurrent().Add(parent);
615 // Set child to completely cover parent.
616 // Change rotation of child to be different from parent so that we can check if our local coordinate
617 // conversion of the parent actor is correct.
618 Actor child = Actor::New();
619 child.SetSize(100.0f, 100.0f);
620 child.SetAnchorPoint(AnchorPoint::CENTER);
621 child.SetParentOrigin(ParentOrigin::CENTER);
622 child.SetOrientation(Dali::Degree(90.0f), Vector3::ZAXIS);
625 TouchEventFunctor touchFunctor;
626 child.TouchedSignal().Connect(&application, touchFunctor);
629 application.SendNotification();
630 application.Render();
633 GestureReceivedFunctor functor(data);
635 LongPressGestureDetector detector = LongPressGestureDetector::New();
636 detector.Attach(parent);
637 detector.DetectedSignal().Connect(&application, functor);
639 // Do long press - hits child area but parent should still receive it
640 application.ProcessEvent(GenerateLongPress(Gesture::Possible, 1u, Vector2(50.0f, 50.0f)));
641 application.ProcessEvent(GenerateLongPress(Gesture::Started, 1u, Vector2(50.0f, 50.0f)));
642 application.ProcessEvent(GenerateLongPress(Gesture::Finished, 1u, Vector2(50.0f, 50.0f)));
643 DALI_TEST_EQUALS(true, data.functorCalled, TEST_LOCATION);
644 DALI_TEST_EQUALS(true, parent == data.pressedActor, TEST_LOCATION);
645 DALI_TEST_EQUALS(Vector2(50.0f, 50.0f), data.receivedGesture.screenPoint, 0.01f, TEST_LOCATION);
647 // Attach child and generate same touch points
648 // (Also proves that you can detach and then re-attach another actor)
649 detector.Attach(child);
650 detector.Detach(parent);
652 // Do an entire long press, only check finished value
654 application.ProcessEvent(GenerateLongPress(Gesture::Possible, 1u, Vector2(51.0f, 51.0f)));
655 application.ProcessEvent(GenerateLongPress(Gesture::Started, 1u, Vector2(51.0f, 51.0f)));
656 application.ProcessEvent(GenerateLongPress(Gesture::Finished, 1u, Vector2(51.0f, 51.0f)));
657 DALI_TEST_EQUALS(true, data.functorCalled, TEST_LOCATION);
658 DALI_TEST_EQUALS(true, child == data.pressedActor, TEST_LOCATION);
659 DALI_TEST_EQUALS(Vector2(51.0f, 51.0f), data.receivedGesture.screenPoint, 0.01f, TEST_LOCATION);
663 int UtcDaliLongPressGestureSignalReceptionAttachDetachMany(void)
665 TestApplication application;
667 Actor first = Actor::New();
668 first.SetSize(100.0f, 100.0f);
669 first.SetAnchorPoint(AnchorPoint::TOP_LEFT);
670 Stage::GetCurrent().Add(first);
672 Actor second = Actor::New();
673 second.SetSize(100.0f, 100.0f);
675 second.SetAnchorPoint(AnchorPoint::TOP_LEFT);
676 Stage::GetCurrent().Add(second);
679 application.SendNotification();
680 application.Render();
683 GestureReceivedFunctor functor(data);
685 LongPressGestureDetector detector = LongPressGestureDetector::New();
686 detector.Attach(first);
687 detector.Attach(second);
688 detector.DetectedSignal().Connect(&application, functor);
690 // LongPress within second actor's area
691 application.ProcessEvent(GenerateLongPress(Gesture::Possible, 1u, Vector2(120.0f, 10.0f)));
692 application.ProcessEvent(GenerateLongPress(Gesture::Started, 1u, Vector2(120.0f, 10.0f)));
693 application.ProcessEvent(GenerateLongPress(Gesture::Finished, 1u, Vector2(120.0f, 10.0f)));
694 DALI_TEST_EQUALS(true, data.functorCalled, TEST_LOCATION);
695 DALI_TEST_EQUALS(true, second == data.pressedActor, TEST_LOCATION);
697 // LongPress within first actor's area
699 application.ProcessEvent(GenerateLongPress(Gesture::Possible, 1u, Vector2(20.0f, 10.0f)));
700 application.ProcessEvent(GenerateLongPress(Gesture::Started, 1u, Vector2(20.0f, 10.0f)));
701 application.ProcessEvent(GenerateLongPress(Gesture::Finished, 1u, Vector2(20.0f, 10.0f)));
702 DALI_TEST_EQUALS(true, data.functorCalled, TEST_LOCATION);
703 DALI_TEST_EQUALS(true, first == data.pressedActor, TEST_LOCATION);
705 // Detach the second actor
706 detector.Detach(second);
708 // second actor shouldn't receive event
710 application.ProcessEvent(GenerateLongPress(Gesture::Possible, 1u, Vector2(120.0f, 10.0f)));
711 application.ProcessEvent(GenerateLongPress(Gesture::Started, 1u, Vector2(120.0f, 10.0f)));
712 application.ProcessEvent(GenerateLongPress(Gesture::Finished, 1u, Vector2(120.0f, 10.0f)));
713 DALI_TEST_EQUALS(false, data.functorCalled, TEST_LOCATION);
715 // first actor should continue receiving event
717 application.ProcessEvent(GenerateLongPress(Gesture::Possible, 1u, Vector2(20.0f, 10.0f)));
718 application.ProcessEvent(GenerateLongPress(Gesture::Started, 1u, Vector2(20.0f, 10.0f)));
719 application.ProcessEvent(GenerateLongPress(Gesture::Finished, 1u, Vector2(20.0f, 10.0f)));
720 DALI_TEST_EQUALS(true, data.functorCalled, TEST_LOCATION);
724 int UtcDaliLongPressGestureSignalReceptionActorBecomesUntouchable(void)
726 TestApplication application;
728 Actor actor = Actor::New();
729 actor.SetSize(100.0f, 100.0f);
730 actor.SetAnchorPoint(AnchorPoint::TOP_LEFT);
731 Stage::GetCurrent().Add(actor);
734 application.SendNotification();
735 application.Render();
738 GestureReceivedFunctor functor(data);
740 LongPressGestureDetector detector = LongPressGestureDetector::New();
741 detector.Attach(actor);
742 detector.DetectedSignal().Connect(&application, functor);
744 // LongPress in actor's area
745 application.ProcessEvent(GenerateLongPress(Gesture::Possible, 1u, Vector2(50.0f, 10.0f)));
746 application.ProcessEvent(GenerateLongPress(Gesture::Started, 1u, Vector2(50.0f, 10.0f)));
747 application.ProcessEvent(GenerateLongPress(Gesture::Finished, 1u, Vector2(50.0f, 10.0f)));
748 DALI_TEST_EQUALS(true, data.functorCalled, TEST_LOCATION);
750 // Actor becomes invisible - actor should not receive the next long press
751 actor.SetVisible(false);
754 application.SendNotification();
755 application.Render();
757 // LongPress in the same area, shouldn't receive event
759 application.ProcessEvent(GenerateLongPress(Gesture::Possible, 1u, Vector2(50.0f, 10.0f)));
760 application.ProcessEvent(GenerateLongPress(Gesture::Started, 1u, Vector2(50.0f, 10.0f)));
761 application.ProcessEvent(GenerateLongPress(Gesture::Finished, 1u, Vector2(50.0f, 10.0f)));
762 DALI_TEST_EQUALS(false, data.functorCalled, TEST_LOCATION);
766 int UtcDaliLongPressGestureSignalReceptionMultipleGestureDetectors(void)
768 TestApplication application;
769 Dali::TestGestureManager& gestureManager = application.GetGestureManager();
771 Actor first = Actor::New();
772 first.SetSize(100.0f, 100.0f);
773 first.SetAnchorPoint(AnchorPoint::TOP_LEFT);
774 Stage::GetCurrent().Add(first);
776 Actor second = Actor::New();
777 second.SetSize(100.0f, 100.0f);
778 second.SetAnchorPoint(AnchorPoint::TOP_LEFT);
783 application.SendNotification();
784 application.Render();
787 GestureReceivedFunctor functor(data);
789 LongPressGestureDetector firstDetector = LongPressGestureDetector::New();
790 firstDetector.Attach(first);
791 firstDetector.DetectedSignal().Connect(&application, functor);
793 // secondDetector is scoped
795 // Reset gestureManager statistics
796 gestureManager.Initialize();
798 LongPressGestureDetector secondDetector = LongPressGestureDetector::New();
799 secondDetector.SetTouchesRequired(2);
800 secondDetector.Attach(second);
801 secondDetector.DetectedSignal().Connect(&application, functor);
803 DALI_TEST_EQUALS(true, gestureManager.WasCalled(TestGestureManager::UpdateType), TEST_LOCATION);
804 DALI_TEST_EQUALS(false, gestureManager.WasCalled(TestGestureManager::RegisterType), TEST_LOCATION);
805 DALI_TEST_EQUALS(false, gestureManager.WasCalled(TestGestureManager::UnregisterType), TEST_LOCATION);
807 // LongPress within second actor's area
808 application.ProcessEvent(GenerateLongPress(Gesture::Possible, 2u, Vector2(150.0f, 10.0f)));
809 application.ProcessEvent(GenerateLongPress(Gesture::Started, 2u, Vector2(150.0f, 10.0f)));
810 application.ProcessEvent(GenerateLongPress(Gesture::Finished, 2u, Vector2(150.0f, 10.0f)));
811 DALI_TEST_EQUALS(true, data.functorCalled, TEST_LOCATION);
812 DALI_TEST_EQUALS(true, second == data.pressedActor, TEST_LOCATION);
814 // LongPress continues as single touch gesture - we should not receive any gesture
816 application.ProcessEvent(GenerateLongPress(Gesture::Possible, 1u, Vector2(150.0f, 10.0f)));
817 application.ProcessEvent(GenerateLongPress(Gesture::Started, 1u, Vector2(150.0f, 10.0f)));
818 application.ProcessEvent(GenerateLongPress(Gesture::Finished, 1u, Vector2(150.0f, 10.0f)));
819 DALI_TEST_EQUALS(false, data.functorCalled, TEST_LOCATION);
821 // Single touch long press starts - first actor should receive gesture
823 application.ProcessEvent(GenerateLongPress(Gesture::Possible, 1u, Vector2(50.0f, 10.0f)));
824 application.ProcessEvent(GenerateLongPress(Gesture::Started, 1u, Vector2(50.0f, 10.0f)));
825 application.ProcessEvent(GenerateLongPress(Gesture::Finished, 1u, Vector2(50.0f, 10.0f)));
826 DALI_TEST_EQUALS(true, data.functorCalled, TEST_LOCATION);
827 DALI_TEST_EQUALS(true, first == data.pressedActor, TEST_LOCATION);
829 // long press changes to double-touch - we shouldn't receive event
831 application.ProcessEvent(GenerateLongPress(Gesture::Possible, 2u, Vector2(50.0f, 10.0f)));
832 application.ProcessEvent(GenerateLongPress(Gesture::Started, 2u, Vector2(50.0f, 10.0f)));
833 application.ProcessEvent(GenerateLongPress(Gesture::Finished, 2u, Vector2(50.0f, 10.0f)));
834 DALI_TEST_EQUALS(false, data.functorCalled, TEST_LOCATION);
836 // Reset gesture manager statistics
837 gestureManager.Initialize();
840 // secondDetector has now been deleted. Gesture detection should have been updated only
841 DALI_TEST_EQUALS(true, gestureManager.WasCalled(TestGestureManager::UpdateType), TEST_LOCATION);
842 DALI_TEST_EQUALS(false, gestureManager.WasCalled(TestGestureManager::RegisterType), TEST_LOCATION);
843 DALI_TEST_EQUALS(false, gestureManager.WasCalled(TestGestureManager::UnregisterType), TEST_LOCATION);
847 int UtcDaliLongPressGestureSignalReceptionMultipleDetectorsOnActor(void)
849 TestApplication application;
851 Actor actor = Actor::New();
852 actor.SetSize(100.0f, 100.0f);
853 actor.SetAnchorPoint(AnchorPoint::TOP_LEFT);
854 Stage::GetCurrent().Add(actor);
857 application.SendNotification();
858 application.Render();
860 // Attach actor to one detector
861 SignalData firstData;
862 GestureReceivedFunctor firstFunctor(firstData);
863 LongPressGestureDetector firstDetector = LongPressGestureDetector::New();
864 firstDetector.Attach(actor);
865 firstDetector.DetectedSignal().Connect(&application, firstFunctor);
867 // Attach actor to another detector
868 SignalData secondData;
869 GestureReceivedFunctor secondFunctor(secondData);
870 LongPressGestureDetector secondDetector = LongPressGestureDetector::New();
871 secondDetector.Attach(actor);
872 secondDetector.DetectedSignal().Connect(&application, secondFunctor);
874 // LongPress in actor's area - both detector's functors should be called
875 application.ProcessEvent(GenerateLongPress(Gesture::Possible, 1u, Vector2(50.0f, 10.0f)));
876 application.ProcessEvent(GenerateLongPress(Gesture::Started, 1u, Vector2(50.0f, 10.0f)));
877 DALI_TEST_EQUALS(true, firstData.functorCalled, TEST_LOCATION);
878 DALI_TEST_EQUALS(true, secondData.functorCalled, TEST_LOCATION);
882 int UtcDaliLongPressGestureSignalReceptionDifferentPossible(void)
884 TestApplication application;
886 Actor actor = Actor::New();
887 actor.SetSize(100.0f, 100.0f);
888 actor.SetAnchorPoint(AnchorPoint::TOP_LEFT);
889 Stage::GetCurrent().Add(actor);
892 application.SendNotification();
893 application.Render();
895 // Attach actor to detector
897 GestureReceivedFunctor functor( data );
898 LongPressGestureDetector detector = LongPressGestureDetector::New();
899 detector.Attach(actor);
900 detector.DetectedSignal().Connect( &application, functor );
902 // LongPress possible in actor's area.
903 application.ProcessEvent(GenerateLongPress(Gesture::Possible, 1u, Vector2(50.0f, 10.0f)));
904 DALI_TEST_EQUALS(false, data.functorCalled, TEST_LOCATION);
906 // Move actor somewhere else
907 actor.SetPosition( 100.0f, 100.0f );
910 application.SendNotification();
911 application.Render();
913 // Emit Started event, we should not receive the long press.
914 application.ProcessEvent(GenerateLongPress(Gesture::Started, 1u, Vector2(50.0f, 10.0f)));
915 application.ProcessEvent(GenerateLongPress(Gesture::Finished, 1u, Vector2(50.0f, 10.0f)));
916 DALI_TEST_EQUALS(false, data.functorCalled, TEST_LOCATION);
918 // LongPress possible in empty area.
919 application.ProcessEvent(GenerateLongPress(Gesture::Possible, 1u, Vector2(50.0f, 10.0f)));
920 DALI_TEST_EQUALS(false, data.functorCalled, TEST_LOCATION);
922 // Move actor in to the long press position.
923 actor.SetPosition( 0.0f, 0.0f );
926 application.SendNotification();
927 application.Render();
929 // Emit Started event, we should not receive the long press.
930 application.ProcessEvent(GenerateLongPress(Gesture::Started, 1u, Vector2(50.0f, 10.0f)));
931 application.ProcessEvent(GenerateLongPress(Gesture::Finished, 1u, Vector2(50.0f, 10.0f)));
932 DALI_TEST_EQUALS(false, data.functorCalled, TEST_LOCATION);
934 // Normal long press in actor's area for completeness.
935 application.ProcessEvent(GenerateLongPress(Gesture::Possible, 1u, Vector2(50.0f, 10.0f)));
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(true, data.functorCalled, TEST_LOCATION);
942 int UtcDaliLongPressGestureEmitIncorrectStateClear(void)
944 TestApplication application;
946 Actor actor = Actor::New();
947 actor.SetSize(100.0f, 100.0f);
948 actor.SetAnchorPoint(AnchorPoint::TOP_LEFT);
949 Stage::GetCurrent().Add(actor);
952 application.SendNotification();
953 application.Render();
955 // Attach actor to detector
957 GestureReceivedFunctor functor( data );
958 LongPressGestureDetector detector = LongPressGestureDetector::New();
959 detector.Attach(actor);
960 detector.DetectedSignal().Connect( &application, functor );
965 application.ProcessEvent(GenerateLongPress(Gesture::Clear, 1u, Vector2(50.0f, 10.0f)));
966 tet_result(TET_FAIL);
968 catch ( Dali::DaliException& e )
970 DALI_TEST_ASSERT( e, "false", TEST_LOCATION );
975 int UtcDaliLongPressGestureEmitIncorrectStateContinuing(void)
977 TestApplication application;
979 Actor actor = Actor::New();
980 actor.SetSize(100.0f, 100.0f);
981 actor.SetAnchorPoint(AnchorPoint::TOP_LEFT);
982 Stage::GetCurrent().Add(actor);
985 application.SendNotification();
986 application.Render();
988 // Attach actor to detector
990 GestureReceivedFunctor functor( data );
991 LongPressGestureDetector detector = LongPressGestureDetector::New();
992 detector.Attach(actor);
993 detector.DetectedSignal().Connect( &application, functor );
995 // Try a Continuing state
998 application.ProcessEvent(GenerateLongPress(Gesture::Continuing, 1u, Vector2(50.0f, 10.0f)));
999 tet_result(TET_FAIL);
1001 catch ( Dali::DaliException& e )
1003 DALI_TEST_ASSERT( e, "false", TEST_LOCATION );
1008 int UtcDaliLongPressGestureRepeatedState(void)
1010 TestApplication application;
1012 Actor actor = Actor::New();
1013 actor.SetSize(100.0f, 100.0f);
1014 actor.SetAnchorPoint(AnchorPoint::TOP_LEFT);
1015 Stage::GetCurrent().Add(actor);
1017 // Render and notify
1018 application.SendNotification();
1019 application.Render();
1021 // Attach actor to detector
1023 GestureReceivedFunctor functor( data );
1024 LongPressGestureDetector detector = LongPressGestureDetector::New();
1025 detector.Attach(actor);
1026 detector.DetectedSignal().Connect( &application, functor );
1029 application.ProcessEvent(GenerateLongPress(Gesture::Possible, 1u, Vector2(50.0f, 10.0f)));
1030 DALI_TEST_EQUALS(false, data.functorCalled, TEST_LOCATION);
1031 application.ProcessEvent(GenerateLongPress(Gesture::Possible, 1u, Vector2(50.0f, 10.0f)));
1032 DALI_TEST_EQUALS(false, data.functorCalled, TEST_LOCATION);
1034 // ... Send some finished states, still no signal
1035 application.ProcessEvent(GenerateLongPress(Gesture::Finished, 1u, Vector2(50.0f, 10.0f)));
1036 DALI_TEST_EQUALS(false, data.functorCalled, TEST_LOCATION);
1037 application.ProcessEvent(GenerateLongPress(Gesture::Finished, 1u, Vector2(50.0f, 10.0f)));
1038 DALI_TEST_EQUALS(false, data.functorCalled, TEST_LOCATION);
1040 // Send two Started states, should be signalled
1041 application.ProcessEvent(GenerateLongPress(Gesture::Possible, 1u, Vector2(50.0f, 10.0f)));
1042 DALI_TEST_EQUALS(false, data.functorCalled, TEST_LOCATION);
1043 application.ProcessEvent(GenerateLongPress(Gesture::Started, 1u, Vector2(50.0f, 10.0f)));
1044 DALI_TEST_EQUALS(true, data.functorCalled, TEST_LOCATION);
1046 application.ProcessEvent(GenerateLongPress(Gesture::Started, 1u, Vector2(50.0f, 10.0f)));
1047 DALI_TEST_EQUALS(true, data.functorCalled, TEST_LOCATION);
1049 application.ProcessEvent(GenerateLongPress(Gesture::Finished, 1u, Vector2(50.0f, 10.0f)));
1050 DALI_TEST_EQUALS(true, data.functorCalled, TEST_LOCATION);
1053 // Send two cancelled states, should not be signalled
1054 application.ProcessEvent(GenerateLongPress(Gesture::Cancelled, 1u, Vector2(50.0f, 10.0f)));
1055 DALI_TEST_EQUALS(false, data.functorCalled, TEST_LOCATION);
1056 application.ProcessEvent(GenerateLongPress(Gesture::Cancelled, 1u, Vector2(50.0f, 10.0f)));
1057 DALI_TEST_EQUALS(false, data.functorCalled, TEST_LOCATION);
1061 int UtcDaliLongPressGesturePossibleCancelled(void)
1063 TestApplication application;
1065 Actor actor = Actor::New();
1066 actor.SetSize(100.0f, 100.0f);
1067 actor.SetAnchorPoint(AnchorPoint::TOP_LEFT);
1068 Stage::GetCurrent().Add(actor);
1070 // Render and notify
1071 application.SendNotification();
1072 application.Render();
1074 // Attach actor to detector
1076 GestureReceivedFunctor functor( data );
1077 LongPressGestureDetector detector = LongPressGestureDetector::New();
1078 detector.Attach(actor);
1079 detector.DetectedSignal().Connect( &application, functor );
1081 // Send a possible followed by a cancel, we should not be signalled
1082 application.ProcessEvent(GenerateLongPress(Gesture::Possible, 1u, Vector2(50.0f, 10.0f)));
1083 DALI_TEST_EQUALS(false, data.functorCalled, TEST_LOCATION);
1084 application.ProcessEvent(GenerateLongPress(Gesture::Cancelled, 1u, Vector2(50.0f, 10.0f)));
1085 DALI_TEST_EQUALS(false, data.functorCalled, TEST_LOCATION);
1089 int UtcDaliLongPressGestureDetachAfterStarted(void)
1091 TestApplication application;
1093 Actor actor = Actor::New();
1094 actor.SetSize(100.0f, 100.0f);
1095 actor.SetAnchorPoint(AnchorPoint::TOP_LEFT);
1096 Stage::GetCurrent().Add(actor);
1098 // Render and notify
1099 application.SendNotification();
1100 application.Render();
1102 // Attach actor to detector
1104 GestureReceivedFunctor functor( data );
1105 LongPressGestureDetector detector = LongPressGestureDetector::New();
1106 detector.Attach(actor);
1107 detector.DetectedSignal().Connect( &application, functor );
1109 // Emit initial signal
1110 application.ProcessEvent(GenerateLongPress(Gesture::Possible, 1u, Vector2(50.0f, 10.0f)));
1111 application.ProcessEvent(GenerateLongPress(Gesture::Started, 1u, Vector2(50.0f, 10.0f)));
1112 DALI_TEST_EQUALS(true, data.functorCalled, TEST_LOCATION);
1116 detector.Detach(actor);
1118 // Emit Finished, no signal
1119 application.ProcessEvent(GenerateLongPress(Gesture::Finished, 1u, Vector2(50.0f, 10.0f)));
1120 DALI_TEST_EQUALS(false, data.functorCalled, TEST_LOCATION);
1124 int UtcDaliLongPressGestureActorUnstaged(void)
1126 TestApplication application;
1128 Actor actor = Actor::New();
1129 actor.SetSize(100.0f, 100.0f);
1130 actor.SetAnchorPoint(AnchorPoint::TOP_LEFT);
1131 Stage::GetCurrent().Add(actor);
1133 // Render and notify
1134 application.SendNotification();
1135 application.Render();
1137 // State to remove actor in.
1138 Gesture::State stateToUnstage( Gesture::Started );
1140 // Attach actor to detector
1142 UnstageActorFunctor functor( data, stateToUnstage );
1143 LongPressGestureDetector detector = LongPressGestureDetector::New();
1144 detector.Attach(actor);
1145 detector.DetectedSignal().Connect( &application, functor );
1148 application.ProcessEvent(GenerateLongPress(Gesture::Possible, 1u, Vector2(50.0f, 10.0f)));
1149 application.ProcessEvent(GenerateLongPress(Gesture::Started, 1u, Vector2(50.0f, 10.0f)));
1150 DALI_TEST_EQUALS(true, data.functorCalled, TEST_LOCATION);
1152 application.ProcessEvent(GenerateLongPress(Gesture::Finished, 1u, Vector2(50.0f, 10.0f)));
1153 DALI_TEST_EQUALS(false, data.functorCalled, TEST_LOCATION);
1155 // Render and notify
1156 application.SendNotification();
1157 application.Render();
1159 // Re-add actor to stage
1160 Stage::GetCurrent().Add(actor);
1162 // Render and notify
1163 application.SendNotification();
1164 application.Render();
1166 // Change state to Gesture::Continuing to remove
1167 stateToUnstage = Gesture::Finished;
1170 application.ProcessEvent(GenerateLongPress(Gesture::Possible, 1u, Vector2(50.0f, 10.0f)));
1171 application.ProcessEvent(GenerateLongPress(Gesture::Started, 1u, Vector2(50.0f, 10.0f)));
1172 DALI_TEST_EQUALS(true, data.functorCalled, TEST_LOCATION);
1174 application.ProcessEvent(GenerateLongPress(Gesture::Finished, 1u, Vector2(50.0f, 10.0f)));
1175 DALI_TEST_EQUALS(true, data.functorCalled, TEST_LOCATION);
1176 tet_result( TET_PASS ); // If we get here then we have handled actor stage removal gracefully.
1180 int UtcDaliLongPressGestureActorStagedAndDestroyed(void)
1182 TestApplication application;
1184 Actor actor = Actor::New();
1185 actor.SetSize(100.0f, 100.0f);
1186 actor.SetAnchorPoint(AnchorPoint::TOP_LEFT);
1187 Stage::GetCurrent().Add(actor);
1189 // Create and add a second actor so that GestureDetector destruction does not come into play.
1190 Actor dummyActor( Actor::New() );
1191 dummyActor.SetSize( 100.0f, 100.0f );
1192 dummyActor.SetPosition( 100.0f, 100.0f );
1193 dummyActor.SetAnchorPoint(AnchorPoint::TOP_LEFT);
1194 Stage::GetCurrent().Add(dummyActor);
1196 // Render and notify
1197 application.SendNotification();
1198 application.Render();
1200 // State to remove actor in.
1201 Gesture::State stateToUnstage( Gesture::Started );
1203 // Attach actor to detector
1205 UnstageActorFunctor functor( data, stateToUnstage );
1206 LongPressGestureDetector detector = LongPressGestureDetector::New();
1207 detector.Attach(actor);
1208 detector.Attach(dummyActor);
1209 detector.DetectedSignal().Connect( &application, functor );
1211 // Here we are testing a Started actor which is removed in the Started callback, but then added back
1212 // before we get a finished state. As we were removed from the stage, even if we're at the same
1213 // position, we should still not be signalled.
1216 application.ProcessEvent(GenerateLongPress(Gesture::Possible, 1u, Vector2(50.0f, 10.0f)));
1217 application.ProcessEvent(GenerateLongPress(Gesture::Started, 1u, Vector2(50.0f, 10.0f)));
1218 DALI_TEST_EQUALS(true, data.functorCalled, TEST_LOCATION);
1221 // Render and notify
1222 application.SendNotification();
1223 application.Render();
1225 // Re add to the stage, we should not be signalled
1226 Stage::GetCurrent().Add(actor);
1228 // Render and notify
1229 application.SendNotification();
1230 application.Render();
1232 // Continue signal emission
1233 application.ProcessEvent(GenerateLongPress(Gesture::Finished, 1u, Vector2(50.0f, 10.0f)));
1234 DALI_TEST_EQUALS(false, data.functorCalled, TEST_LOCATION);
1237 // Here we delete an actor in started, we should not receive any subsequent signalling.
1240 application.ProcessEvent(GenerateLongPress(Gesture::Possible, 1u, Vector2(50.0f, 10.0f)));
1241 application.ProcessEvent(GenerateLongPress(Gesture::Started, 1u, Vector2(50.0f, 10.0f)));
1242 DALI_TEST_EQUALS(true, data.functorCalled, TEST_LOCATION);
1245 // Render and notify
1246 application.SendNotification();
1247 application.Render();
1249 // Delete actor as well
1252 // Render and notify
1253 application.SendNotification();
1254 application.Render();
1256 // Continue signal emission
1257 application.ProcessEvent(GenerateLongPress(Gesture::Finished, 1u, Vector2(50.0f, 10.0f)));
1258 DALI_TEST_EQUALS(false, data.functorCalled, TEST_LOCATION);
1262 int UtcDaliLongPressGestureSystemOverlay(void)
1264 TestApplication application;
1265 Dali::Integration::Core& core = application.GetCore();
1266 Dali::Integration::SystemOverlay& systemOverlay( core.GetSystemOverlay() );
1267 systemOverlay.GetOverlayRenderTasks().CreateTask();
1269 Actor actor = Actor::New();
1270 actor.SetSize(100.0f, 100.0f);
1271 actor.SetAnchorPoint(AnchorPoint::TOP_LEFT);
1272 systemOverlay.Add(actor);
1274 // Render and notify
1275 application.SendNotification();
1276 application.Render();
1279 GestureReceivedFunctor functor(data);
1281 LongPressGestureDetector detector = LongPressGestureDetector::New();
1282 detector.Attach(actor);
1283 detector.DetectedSignal().Connect(&application, functor);
1285 // Do a long press inside actor's area
1286 Vector2 screenCoords( 50.0f, 50.0f );
1287 application.ProcessEvent( GenerateLongPress( Gesture::Possible, 1u, screenCoords ) );
1288 application.ProcessEvent( GenerateLongPress( Gesture::Started, 1u, screenCoords ) );
1289 DALI_TEST_EQUALS( true, data.functorCalled, TEST_LOCATION );
1293 int UtcDaliLongPressGestureBehindTouchableSystemOverlay(void)
1295 TestApplication application;
1296 Dali::Integration::Core& core = application.GetCore();
1297 Dali::Integration::SystemOverlay& systemOverlay( core.GetSystemOverlay() );
1298 systemOverlay.GetOverlayRenderTasks().CreateTask();
1300 // SystemOverlay actor
1301 Actor systemOverlayActor = Actor::New();
1302 systemOverlayActor.SetSize(100.0f, 100.0f);
1303 systemOverlayActor.SetAnchorPoint(AnchorPoint::TOP_LEFT);
1304 systemOverlay.Add(systemOverlayActor);
1307 Actor stageActor = Actor::New();
1308 stageActor.SetSize(100.0f, 100.0f);
1309 stageActor.SetAnchorPoint(AnchorPoint::TOP_LEFT);
1310 Stage::GetCurrent().Add(stageActor);
1312 // Render and notify
1313 application.SendNotification();
1314 application.Render();
1316 // Set system-overlay actor to touchable
1317 TouchEventData touchData;
1318 TouchEventDataFunctor touchFunctor( touchData );
1319 systemOverlayActor.TouchedSignal().Connect(&application, touchFunctor);
1321 // Set stage actor to receive the gesture
1323 GestureReceivedFunctor functor(data);
1325 LongPressGestureDetector detector = LongPressGestureDetector::New();
1326 detector.Attach(stageActor);
1327 detector.DetectedSignal().Connect(&application, functor);
1329 // Start long press within the two actors' area
1330 Vector2 screenCoords( 50.0f, 50.0f );
1331 application.ProcessEvent( GenerateLongPress( Gesture::Possible, 1u, screenCoords ) );
1332 application.ProcessEvent( GenerateLongPress( Gesture::Started, 1u, screenCoords ) );
1333 DALI_TEST_EQUALS( true, data.functorCalled, TEST_LOCATION );
1334 DALI_TEST_EQUALS( false, touchData.functorCalled, TEST_LOCATION );
1339 // Do touch in the same area
1340 application.ProcessEvent( touchFunctor.GenerateSingleTouch( TouchPoint::Down, screenCoords ) );
1341 DALI_TEST_EQUALS( false, data.functorCalled, TEST_LOCATION );
1342 DALI_TEST_EQUALS( true, touchData.functorCalled, TEST_LOCATION );
1347 int UtcDaliLongPressGestureTouchBehindGesturedSystemOverlay(void)
1349 TestApplication application;
1350 Dali::Integration::Core& core = application.GetCore();
1351 Dali::Integration::SystemOverlay& systemOverlay( core.GetSystemOverlay() );
1352 systemOverlay.GetOverlayRenderTasks().CreateTask();
1354 // SystemOverlay actor
1355 Actor systemOverlayActor = Actor::New();
1356 systemOverlayActor.SetSize(100.0f, 100.0f);
1357 systemOverlayActor.SetAnchorPoint(AnchorPoint::TOP_LEFT);
1358 systemOverlay.Add(systemOverlayActor);
1361 Actor stageActor = Actor::New();
1362 stageActor.SetSize(100.0f, 100.0f);
1363 stageActor.SetAnchorPoint(AnchorPoint::TOP_LEFT);
1364 Stage::GetCurrent().Add(stageActor);
1366 // Render and notify
1367 application.SendNotification();
1368 application.Render();
1370 // Set stage actor to touchable
1371 TouchEventData touchData;
1372 TouchEventDataFunctor touchFunctor( touchData );
1373 stageActor.TouchedSignal().Connect(&application, touchFunctor);
1375 // Set system-overlay actor to have the gesture
1377 GestureReceivedFunctor functor(data);
1379 LongPressGestureDetector detector = LongPressGestureDetector::New();
1380 detector.Attach(systemOverlayActor);
1381 detector.DetectedSignal().Connect(&application, functor);
1383 // Start long press within the two actors' area
1384 Vector2 screenCoords( 50.0f, 50.0f );
1385 application.ProcessEvent( GenerateLongPress( Gesture::Possible, 1u, screenCoords ) );
1386 application.ProcessEvent( GenerateLongPress( Gesture::Started, 1u, screenCoords ) );
1387 DALI_TEST_EQUALS( true, data.functorCalled, TEST_LOCATION );
1388 DALI_TEST_EQUALS( false, touchData.functorCalled, TEST_LOCATION );
1393 // Do touch in the same area
1394 application.ProcessEvent( touchFunctor.GenerateSingleTouch( TouchPoint::Down, screenCoords ) );
1395 DALI_TEST_EQUALS( false, data.functorCalled, TEST_LOCATION );
1396 DALI_TEST_EQUALS( true, touchData.functorCalled, TEST_LOCATION );
1401 int UtcDaliLongPressGestureLayerConsumesTouch(void)
1403 TestApplication application;
1405 Actor actor = Actor::New();
1406 actor.SetSize(100.0f, 100.0f);
1407 actor.SetAnchorPoint(AnchorPoint::TOP_LEFT);
1408 Stage::GetCurrent().Add(actor);
1412 GestureReceivedFunctor functor(data);
1413 LongPressGestureDetector detector = LongPressGestureDetector::New();
1414 detector.Attach(actor);
1415 detector.DetectedSignal().Connect( &application, functor );
1417 // Add a layer to overlap the actor
1418 Layer layer = Layer::New();
1419 layer.SetSize(100.0f, 100.0f);
1420 layer.SetAnchorPoint(AnchorPoint::TOP_LEFT);
1421 Stage::GetCurrent().Add( layer );
1424 // Render and notify
1425 application.SendNotification();
1426 application.Render();
1428 Vector2 screenCoords( 50.0f, 50.0f );
1430 // Emit signals, should receive
1431 application.ProcessEvent( GenerateLongPress( Gesture::Possible, 1u, screenCoords ) );
1432 application.ProcessEvent( GenerateLongPress( Gesture::Started, 1u, screenCoords ) );
1433 application.ProcessEvent( GenerateLongPress( Gesture::Finished, 1u, screenCoords ) );
1434 DALI_TEST_EQUALS(true, data.functorCalled, TEST_LOCATION);
1437 // Set layer to consume all touch
1438 layer.SetTouchConsumed( true );
1440 // Render and notify
1441 application.SendNotification();
1442 application.Render();
1444 // Emit the same signals again, should not receive
1445 application.ProcessEvent( GenerateLongPress( Gesture::Possible, 1u, screenCoords ) );
1446 application.ProcessEvent( GenerateLongPress( Gesture::Started, 1u, screenCoords ) );
1447 application.ProcessEvent( GenerateLongPress( Gesture::Finished, 1u, screenCoords ) );
1448 DALI_TEST_EQUALS(false, data.functorCalled, TEST_LOCATION);