2 * Copyright (c) 2019 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/render-task-list-integ.h>
24 #include <dali-test-suite-utils.h>
25 #include <test-touch-utils.h>
29 void utc_dali_long_press_gesture_detector_startup(void)
31 test_return_value = TET_UNDEF;
34 void utc_dali_long_press_gesture_detector_cleanup(void)
36 test_return_value = TET_PASS;
39 ///////////////////////////////////////////////////////////////////////////////
43 // Stores data that is populated in the callback and will be read by the TET cases
47 : functorCalled( false ),
48 voidFunctorCalled( false ),
49 receivedGesture( Gesture::Clear ),
55 functorCalled = false;
56 voidFunctorCalled = false;
58 receivedGesture.numberOfTouches = 0u;
59 receivedGesture.screenPoint = Vector2(0.0f, 0.0f);
60 receivedGesture.localPoint = Vector2(0.0f, 0.0f);
66 bool voidFunctorCalled;
67 LongPressGesture receivedGesture;
71 // Functor that sets the data when called
72 struct GestureReceivedFunctor
74 GestureReceivedFunctor(SignalData& data) : signalData(data) { }
76 void operator()(Actor actor, const LongPressGesture& longPress)
78 signalData.functorCalled = true;
79 signalData.receivedGesture = longPress;
80 signalData.pressedActor = actor;
85 signalData.voidFunctorCalled = true;
88 SignalData& signalData;
91 // Functor that removes the gestured actor from stage
92 struct UnstageActorFunctor : public GestureReceivedFunctor
94 UnstageActorFunctor( SignalData& data, Gesture::State& stateToUnstage )
95 : GestureReceivedFunctor( data ),
96 stateToUnstage( stateToUnstage )
100 void operator()( Actor actor, const LongPressGesture& longPress )
102 GestureReceivedFunctor::operator()( actor, longPress );
104 if ( longPress.state == stateToUnstage )
106 Stage::GetCurrent().Remove( actor );
110 Gesture::State& stateToUnstage;
113 // Functor for receiving a touch event
114 struct TouchEventFunctor
116 bool operator()(Actor actor, const TouchEvent& touch)
119 unsigned int points = touch.GetPointCount();
122 const TouchPoint& touchPoint = touch.GetPoint(0);
123 tet_printf("Touch Point state = %d\n", touchPoint.state);
131 ///////////////////////////////////////////////////////////////////////////////
134 // Positive test case for a method
135 int UtcDaliLongPressGestureDetectorConstructorP(void)
137 TestApplication application;
139 LongPressGestureDetector detector;
140 DALI_TEST_CHECK(!detector);
144 int UtcDaliLongPressGestureDetectorCopyConstructorP(void)
146 TestApplication application;
148 LongPressGestureDetector detector = LongPressGestureDetector::New();;
150 LongPressGestureDetector copy( detector );
151 DALI_TEST_CHECK( detector );
155 int UtcDaliLongPressGestureDetectorAssignmentOperatorP(void)
157 TestApplication application;
159 LongPressGestureDetector detector;
160 detector = LongPressGestureDetector::New();;
162 LongPressGestureDetector copy;
164 DALI_TEST_CHECK( detector );
166 DALI_TEST_CHECK( detector == copy );
170 int UtcDaliLongPressGestureDetectorNew(void)
172 TestApplication application;
174 LongPressGestureDetector detector = LongPressGestureDetector::New();
175 DALI_TEST_CHECK(detector);
176 DALI_TEST_EQUALS(1u, detector.GetMinimumTouchesRequired(), TEST_LOCATION);
177 DALI_TEST_EQUALS(1u, detector.GetMaximumTouchesRequired(), TEST_LOCATION);
179 LongPressGestureDetector detector2 = LongPressGestureDetector::New(5u);
180 DALI_TEST_CHECK(detector2);
181 DALI_TEST_EQUALS(5u, detector2.GetMinimumTouchesRequired(), TEST_LOCATION);
182 DALI_TEST_EQUALS(5u, detector2.GetMaximumTouchesRequired(), TEST_LOCATION);
184 LongPressGestureDetector detector3 = LongPressGestureDetector::New(5u, 7u);
185 DALI_TEST_CHECK(detector2);
186 DALI_TEST_EQUALS(5u, detector3.GetMinimumTouchesRequired(), TEST_LOCATION);
187 DALI_TEST_EQUALS(7u, detector3.GetMaximumTouchesRequired(), TEST_LOCATION);
189 //Scoped test to test destructor
191 LongPressGestureDetector detector4 = LongPressGestureDetector::New();
192 DALI_TEST_CHECK(detector4);
195 // Attach an actor and emit a touch event on the actor to ensure complete line coverage
196 Actor actor = Actor::New();
197 actor.SetSize(100.0f, 100.0f);
198 actor.SetAnchorPoint(AnchorPoint::TOP_LEFT);
199 Stage::GetCurrent().Add(actor);
202 application.SendNotification();
203 application.Render();
205 detector.Attach(actor);
207 TouchEventFunctor touchFunctor;
208 actor.TouchedSignal().Connect(&application, touchFunctor);
210 Integration::TouchEvent touchEvent(1);
211 Integration::Point point;
212 point.SetDeviceId( 1 );
213 point.SetState( PointState::DOWN );
214 point.SetScreenPosition( Vector2( 20.0f, 20.0f ) );
215 touchEvent.AddPoint(point);
216 application.ProcessEvent(touchEvent);
219 application.SendNotification();
220 application.Render();
222 // For line coverage, Initialise default constructor
223 TouchEvent touchEvent2;
227 int UtcDaliLongPressGestureDetectorDownCast(void)
229 TestApplication application;
230 tet_infoline("Testing Dali::LongPressGestureDetector::DownCast()");
232 LongPressGestureDetector detector = LongPressGestureDetector::New();
234 BaseHandle object(detector);
236 LongPressGestureDetector detector2 = LongPressGestureDetector::DownCast(object);
237 DALI_TEST_CHECK(detector2);
239 LongPressGestureDetector detector3 = DownCast< LongPressGestureDetector >(object);
240 DALI_TEST_CHECK(detector3);
242 BaseHandle unInitializedObject;
243 LongPressGestureDetector detector4 = LongPressGestureDetector::DownCast(unInitializedObject);
244 DALI_TEST_CHECK(!detector4);
246 LongPressGestureDetector detector5 = DownCast< LongPressGestureDetector >(unInitializedObject);
247 DALI_TEST_CHECK(!detector5);
249 GestureDetector detector6 = LongPressGestureDetector::New();
250 LongPressGestureDetector detector7 = LongPressGestureDetector::DownCast(detector6);
251 DALI_TEST_CHECK(detector7);
255 int UtcDaliLongPressGestureGetMinimumTouchesRequired(void)
257 TestApplication application;
259 LongPressGestureDetector detector = LongPressGestureDetector::New();
260 DALI_TEST_EQUALS(1u, detector.GetMinimumTouchesRequired(), TEST_LOCATION);
264 int UtcDaliLongPressGestureGetMaximumTouchesRequired(void)
266 TestApplication application;
268 LongPressGestureDetector detector = LongPressGestureDetector::New();
269 DALI_TEST_EQUALS(1u, detector.GetMaximumTouchesRequired(), TEST_LOCATION);
273 int UtcDaliLongPressGestureSignalReceptionNegative(void)
275 TestApplication application;
277 Actor actor = Actor::New();
278 actor.SetSize(100.0f, 100.0f);
279 actor.SetAnchorPoint(AnchorPoint::TOP_LEFT);
280 Stage::GetCurrent().Add(actor);
283 application.SendNotification();
284 application.Render();
287 GestureReceivedFunctor functor(data);
289 LongPressGestureDetector detector = LongPressGestureDetector::New();
290 detector.Attach(actor);
291 detector.DetectedSignal().Connect(&application, functor);
293 // Do a long press outside actor's area
294 TestGenerateLongPress( application, 112.0f, 112.0f );
295 TestEndLongPress( application, 112.0f, 112.0f);
297 DALI_TEST_EQUALS(false, data.functorCalled, TEST_LOCATION);
301 int UtcDaliLongPressGestureSignalReceptionPositive(void)
303 TestApplication application;
305 Actor actor = Actor::New();
306 actor.SetSize(100.0f, 100.0f);
307 actor.SetAnchorPoint(AnchorPoint::TOP_LEFT);
308 Stage::GetCurrent().Add(actor);
311 application.SendNotification();
312 application.Render();
315 GestureReceivedFunctor functor(data);
317 LongPressGestureDetector detector = LongPressGestureDetector::New();
318 detector.Attach(actor);
319 detector.DetectedSignal().Connect(&application, functor);
321 // Do a long press inside actor's area
322 TestGenerateLongPress( application, 50.0f, 50.0f );
323 DALI_TEST_EQUALS(true, data.functorCalled, TEST_LOCATION);
324 DALI_TEST_EQUALS(1u, data.receivedGesture.numberOfTouches, TEST_LOCATION);
325 DALI_TEST_EQUALS( Vector2(50.0f, 50.0f), data.receivedGesture.localPoint, 0.1, TEST_LOCATION);
326 TestEndLongPress( application, 50.0f, 50.0f);
330 int UtcDaliLongPressGestureSignalReceptionDetach(void)
332 TestApplication application;
334 Actor actor = Actor::New();
335 actor.SetSize(100.0f, 100.0f);
336 actor.SetAnchorPoint(AnchorPoint::TOP_LEFT);
337 Stage::GetCurrent().Add(actor);
340 application.SendNotification();
341 application.Render();
344 GestureReceivedFunctor functor(data);
346 LongPressGestureDetector detector = LongPressGestureDetector::New();
347 detector.Attach(actor);
348 detector.DetectedSignal().Connect(&application, functor);
350 // Start long press within the actor's area
351 TestGenerateLongPress( application, 20.0f, 20.0f );
352 DALI_TEST_EQUALS(true, data.functorCalled, TEST_LOCATION);
353 DALI_TEST_EQUALS(1u, data.receivedGesture.numberOfTouches, TEST_LOCATION);
354 DALI_TEST_EQUALS( Vector2(20.0f, 20.0f), data.receivedGesture.localPoint, 0.1, TEST_LOCATION);
355 TestEndLongPress( application, 20.0f, 20.0f);
357 // repeat the long press within the actor's area - we should still receive the signal
359 TestGenerateLongPress( application, 50.0f, 50.0f );
360 DALI_TEST_EQUALS(true, data.functorCalled, TEST_LOCATION);
361 DALI_TEST_EQUALS(1u, data.receivedGesture.numberOfTouches, TEST_LOCATION);
362 DALI_TEST_EQUALS( Vector2(50.0f, 50.0f), data.receivedGesture.localPoint, 0.1, TEST_LOCATION);
363 TestEndLongPress( application, 50.0f, 50.0f);
366 detector.DetachAll();
368 // Ensure we are no longer signalled
370 TestGenerateLongPress( application, 20.0f, 20.0f );
371 DALI_TEST_EQUALS(false, data.functorCalled, TEST_LOCATION);
372 TestEndLongPress( application, 50.0f, 50.0f);
373 DALI_TEST_EQUALS(false, data.functorCalled, TEST_LOCATION);
377 int UtcDaliLongPressGestureSignalReceptionActorDestroyedDuringLongPress(void)
379 TestApplication application;
382 GestureReceivedFunctor functor(data);
384 LongPressGestureDetector detector = LongPressGestureDetector::New();
385 detector.DetectedSignal().Connect(&application, functor);
387 // Actor lifetime is scoped
389 Actor actor = Actor::New();
390 actor.SetSize(100.0f, 100.0f);
391 actor.SetAnchorPoint(AnchorPoint::TOP_LEFT);
392 Stage::GetCurrent().Add(actor);
395 application.SendNotification();
396 application.Render();
398 detector.Attach(actor);
400 // Start long press within the actor's area
401 TestGenerateLongPress( application, 20.0f, 20.0f );
402 DALI_TEST_EQUALS(true, data.functorCalled, TEST_LOCATION);
404 // Remove the actor from stage and reset the data
405 Stage::GetCurrent().Remove(actor);
408 application.SendNotification();
409 application.Render();
412 // Actor should now have been destroyed
415 TestEndLongPress( application, 20.0f, 20.0f);
416 DALI_TEST_EQUALS(false, data.functorCalled, TEST_LOCATION);
420 int UtcDaliLongPressGestureSignalReceptionRotatedActor(void)
422 TestApplication application;
424 Actor actor = Actor::New();
425 actor.SetSize(100.0f, 100.0f);
426 actor.SetOrientation(Dali::Degree(90.0f), Vector3::ZAXIS);
427 Stage::GetCurrent().Add(actor);
430 application.SendNotification();
431 application.Render();
434 GestureReceivedFunctor functor(data);
436 LongPressGestureDetector detector = LongPressGestureDetector::New();
437 detector.Attach(actor);
438 detector.DetectedSignal().Connect(&application, functor);
441 TestGenerateLongPress( application, 5.0f, 5.0f );
442 TestEndLongPress( application, 5.0f, 5.0f);
443 DALI_TEST_EQUALS(true, data.functorCalled, TEST_LOCATION);
444 DALI_TEST_EQUALS(1u, data.receivedGesture.numberOfTouches, TEST_LOCATION);
445 DALI_TEST_EQUALS( Vector2(5.0f, 5.0f), data.receivedGesture.screenPoint, 0.1, TEST_LOCATION);
447 // Rotate actor again and render
448 actor.SetOrientation(Dali::Degree(180.0f), Vector3::ZAXIS);
449 application.SendNotification();
450 application.Render();
452 // Do another long press, should still receive event
454 TestGenerateLongPress( application, 5.0f, 5.0f );
455 TestEndLongPress( application, 5.0f, 5.0f);
456 DALI_TEST_EQUALS(true, data.functorCalled, TEST_LOCATION);
457 DALI_TEST_EQUALS(1u, data.receivedGesture.numberOfTouches, TEST_LOCATION);
458 DALI_TEST_EQUALS( Vector2(5.0f, 5.0f), data.receivedGesture.screenPoint, 0.1, TEST_LOCATION);
460 // Rotate actor again and render
461 actor.SetOrientation(Dali::Degree(90.0f), Vector3::YAXIS);
462 application.SendNotification();
463 application.Render();
465 // Do a long press, inside where the actor used to be, Should not receive the event
467 TestGenerateLongPress( application, 70.0f, 70.0f );
468 TestEndLongPress( application, 70.0f, 70.0f);
469 DALI_TEST_EQUALS(false, data.functorCalled, TEST_LOCATION);
473 int UtcDaliLongPressGestureSignalReceptionChildHit(void)
475 TestApplication application;
477 Actor parent = Actor::New();
478 parent.SetSize(100.0f, 100.0f);
479 parent.SetAnchorPoint(AnchorPoint::TOP_LEFT);
480 Stage::GetCurrent().Add(parent);
482 // Set child to completely cover parent.
483 // Change rotation of child to be different from parent so that we can check if our local coordinate
484 // conversion of the parent actor is correct.
485 Actor child = Actor::New();
486 child.SetSize(100.0f, 100.0f);
487 child.SetAnchorPoint(AnchorPoint::CENTER);
488 child.SetParentOrigin(ParentOrigin::CENTER);
489 child.SetOrientation(Dali::Degree(90.0f), Vector3::ZAXIS);
492 TouchEventFunctor touchFunctor;
493 child.TouchedSignal().Connect(&application, touchFunctor);
496 application.SendNotification();
497 application.Render();
500 GestureReceivedFunctor functor(data);
502 LongPressGestureDetector detector = LongPressGestureDetector::New();
503 detector.Attach(parent);
504 detector.DetectedSignal().Connect(&application, functor);
506 // Do long press - hits child area but parent should still receive it
507 TestGenerateLongPress( application, 50.0f, 50.0f );
508 TestEndLongPress( application, 50.0f, 50.0f);
509 DALI_TEST_EQUALS(true, data.functorCalled, TEST_LOCATION);
510 DALI_TEST_EQUALS(true, parent == data.pressedActor, TEST_LOCATION);
511 DALI_TEST_EQUALS(Vector2(50.0f, 50.0f), data.receivedGesture.screenPoint, 0.01f, TEST_LOCATION);
513 // Attach child and generate same touch points
514 // (Also proves that you can detach and then re-attach another actor)
515 detector.Attach(child);
516 detector.Detach(parent);
518 // Do an entire long press, only check finished value
520 TestGenerateLongPress( application, 51.0f, 51.0f );
521 TestEndLongPress( application, 51.0f, 51.0f);
522 DALI_TEST_EQUALS(true, data.functorCalled, TEST_LOCATION);
523 DALI_TEST_EQUALS(true, child == data.pressedActor, TEST_LOCATION);
524 DALI_TEST_EQUALS(Vector2(51.0f, 51.0f), data.receivedGesture.screenPoint, 0.01f, TEST_LOCATION);
528 int UtcDaliLongPressGestureSignalReceptionAttachDetachMany(void)
530 TestApplication application;
532 Actor first = Actor::New();
533 first.SetSize(100.0f, 100.0f);
534 first.SetAnchorPoint(AnchorPoint::TOP_LEFT);
535 Stage::GetCurrent().Add(first);
537 Actor second = Actor::New();
538 second.SetSize(100.0f, 100.0f);
540 second.SetAnchorPoint(AnchorPoint::TOP_LEFT);
541 Stage::GetCurrent().Add(second);
544 application.SendNotification();
545 application.Render();
548 GestureReceivedFunctor functor(data);
550 LongPressGestureDetector detector = LongPressGestureDetector::New();
551 detector.Attach(first);
552 detector.Attach(second);
553 detector.DetectedSignal().Connect(&application, functor);
555 // LongPress within second actor's area
556 TestGenerateLongPress( application, 120.0f, 10.0f );
557 TestEndLongPress( application, 120.0f, 10.0f);
558 DALI_TEST_EQUALS(true, data.functorCalled, TEST_LOCATION);
559 DALI_TEST_EQUALS(true, second == data.pressedActor, TEST_LOCATION);
561 // LongPress within first actor's area
563 TestGenerateLongPress( application, 20.0f, 10.0f );
564 TestEndLongPress( application, 20.0f, 10.0f);
565 DALI_TEST_EQUALS(true, data.functorCalled, TEST_LOCATION);
566 DALI_TEST_EQUALS(true, first == data.pressedActor, TEST_LOCATION);
568 // Detach the second actor
569 detector.Detach(second);
571 // second actor shouldn't receive event
573 TestGenerateLongPress( application, 120.0f, 10.0f );
574 TestEndLongPress( application, 120.0f, 10.0f);
575 DALI_TEST_EQUALS(false, data.functorCalled, TEST_LOCATION);
577 // first actor should continue receiving event
579 TestGenerateLongPress( application, 20.0f, 10.0f );
580 TestEndLongPress( application, 20.0f, 10.0f);
581 DALI_TEST_EQUALS(true, data.functorCalled, TEST_LOCATION);
585 int UtcDaliLongPressGestureSignalReceptionActorBecomesUntouchable(void)
587 TestApplication application;
589 Actor actor = Actor::New();
590 actor.SetSize(100.0f, 100.0f);
591 actor.SetAnchorPoint(AnchorPoint::TOP_LEFT);
592 Stage::GetCurrent().Add(actor);
595 application.SendNotification();
596 application.Render();
599 GestureReceivedFunctor functor(data);
601 LongPressGestureDetector detector = LongPressGestureDetector::New();
602 detector.Attach(actor);
603 detector.DetectedSignal().Connect(&application, functor);
605 // LongPress in actor's area
606 TestGenerateLongPress( application, 50.0f, 10.0f );
607 TestEndLongPress( application, 50.0f, 10.0f);
608 DALI_TEST_EQUALS(true, data.functorCalled, TEST_LOCATION);
610 // Actor becomes invisible - actor should not receive the next long press
611 actor.SetVisible(false);
614 application.SendNotification();
615 application.Render();
617 // LongPress in the same area, shouldn't receive event
619 TestGenerateLongPress( application, 50.0f, 10.0f );
620 TestEndLongPress( application, 50.0f, 10.0f);
621 DALI_TEST_EQUALS(false, data.functorCalled, TEST_LOCATION);
625 int UtcDaliLongPressGestureSignalReceptionMultipleDetectorsOnActor(void)
627 TestApplication application;
629 Actor actor = Actor::New();
630 actor.SetSize(100.0f, 100.0f);
631 actor.SetAnchorPoint(AnchorPoint::TOP_LEFT);
632 Stage::GetCurrent().Add(actor);
635 application.SendNotification();
636 application.Render();
638 // Attach actor to one detector
639 SignalData firstData;
640 GestureReceivedFunctor firstFunctor(firstData);
641 LongPressGestureDetector firstDetector = LongPressGestureDetector::New();
642 firstDetector.Attach(actor);
643 firstDetector.DetectedSignal().Connect(&application, firstFunctor);
645 // Attach actor to another detector
646 SignalData secondData;
647 GestureReceivedFunctor secondFunctor(secondData);
648 LongPressGestureDetector secondDetector = LongPressGestureDetector::New();
649 secondDetector.Attach(actor);
650 secondDetector.DetectedSignal().Connect(&application, secondFunctor);
652 // LongPress in actor's area - both detector's functors should be called
653 TestGenerateLongPress( application, 50.0f, 10.0f );
654 DALI_TEST_EQUALS(true, firstData.functorCalled, TEST_LOCATION);
655 DALI_TEST_EQUALS(true, secondData.functorCalled, TEST_LOCATION);
659 int UtcDaliLongPressGestureSignalReceptionDifferentPossible(void)
661 TestApplication application;
663 Actor actor = Actor::New();
664 actor.SetSize(100.0f, 100.0f);
665 actor.SetAnchorPoint(AnchorPoint::TOP_LEFT);
666 Stage::GetCurrent().Add(actor);
669 application.SendNotification();
670 application.Render();
672 // Attach actor to detector
674 GestureReceivedFunctor functor( data );
675 LongPressGestureDetector detector = LongPressGestureDetector::New();
676 detector.Attach(actor);
677 detector.DetectedSignal().Connect( &application, functor );
679 // LongPress possible in actor's area.
680 TestStartLongPress( application, 50.0f, 10.0f );
681 DALI_TEST_EQUALS(false, data.functorCalled, TEST_LOCATION);
683 // Move actor somewhere else
684 actor.SetPosition( 100.0f, 100.0f );
687 application.SendNotification();
688 application.Render();
690 // Emit Started event, we should not receive the long press.
691 TestTriggerLongPress( application );
692 TestGenerateLongPress( application, 50.0f, 10.0f );
693 DALI_TEST_EQUALS(false, data.functorCalled, TEST_LOCATION);
695 // LongPress possible in empty area.
696 TestStartLongPress( application, 50.0f, 10.0f );
697 DALI_TEST_EQUALS(false, data.functorCalled, TEST_LOCATION);
699 // Move actor in to the long press position.
700 actor.SetPosition( 0.0f, 0.0f );
703 application.SendNotification();
704 application.Render();
706 // Emit Started event, we should not receive the long press.
707 TestTriggerLongPress( application );
708 TestEndLongPress( application, 50.0f, 10.0f );
709 DALI_TEST_EQUALS(false, data.functorCalled, TEST_LOCATION);
711 // Normal long press in actor's area for completeness.
712 TestGenerateLongPress( application, 50.0f, 10.0f );
713 TestEndLongPress( application, 50.0f, 10.0f);
714 DALI_TEST_EQUALS(true, data.functorCalled, TEST_LOCATION);
718 int UtcDaliLongPressGesturePossibleCancelled(void)
720 TestApplication application;
722 Actor actor = Actor::New();
723 actor.SetSize(100.0f, 100.0f);
724 actor.SetAnchorPoint(AnchorPoint::TOP_LEFT);
725 Stage::GetCurrent().Add(actor);
728 application.SendNotification();
729 application.Render();
731 // Attach actor to detector
733 GestureReceivedFunctor functor( data );
734 LongPressGestureDetector detector = LongPressGestureDetector::New();
735 detector.Attach(actor);
736 detector.DetectedSignal().Connect( &application, functor );
738 // Send a possible followed by a cancel, we should not be signalled
739 TestStartLongPress( application, 50.0f, 10.0f );
740 DALI_TEST_EQUALS(false, data.functorCalled, TEST_LOCATION);
741 TestMovePan( application, Vector2( 50.0f, 10.0f ) );
742 DALI_TEST_EQUALS(false, data.functorCalled, TEST_LOCATION);
746 int UtcDaliLongPressGestureDetachAfterStarted(void)
748 TestApplication application;
750 Actor actor = Actor::New();
751 actor.SetSize(100.0f, 100.0f);
752 actor.SetAnchorPoint(AnchorPoint::TOP_LEFT);
753 Stage::GetCurrent().Add(actor);
756 application.SendNotification();
757 application.Render();
759 // Attach actor to detector
761 GestureReceivedFunctor functor( data );
762 LongPressGestureDetector detector = LongPressGestureDetector::New();
763 detector.Attach(actor);
764 detector.DetectedSignal().Connect( &application, functor );
766 // Emit initial signal
767 TestGenerateLongPress( application, 50.0f, 10.0f );
768 DALI_TEST_EQUALS(true, data.functorCalled, TEST_LOCATION);
772 detector.Detach(actor);
774 // Emit Finished, no signal
775 TestEndLongPress( application, 50.0f, 10.0f );
776 DALI_TEST_EQUALS(false, data.functorCalled, TEST_LOCATION);
780 int UtcDaliLongPressGestureActorUnstaged(void)
782 TestApplication application;
784 Actor actor = Actor::New();
785 actor.SetSize(100.0f, 100.0f);
786 actor.SetAnchorPoint(AnchorPoint::TOP_LEFT);
787 Stage::GetCurrent().Add(actor);
790 application.SendNotification();
791 application.Render();
793 // State to remove actor in.
794 Gesture::State stateToUnstage( Gesture::Started );
796 // Attach actor to detector
798 UnstageActorFunctor functor( data, stateToUnstage );
799 LongPressGestureDetector detector = LongPressGestureDetector::New();
800 detector.Attach(actor);
801 detector.DetectedSignal().Connect( &application, functor );
804 TestGenerateLongPress( application, 50.0f, 10.0f );
805 DALI_TEST_EQUALS(true, data.functorCalled, TEST_LOCATION);
807 TestEndLongPress( application, 50.0f, 10.0f );
808 DALI_TEST_EQUALS(false, data.functorCalled, TEST_LOCATION);
811 application.SendNotification();
812 application.Render();
814 // Re-add actor to stage
815 Stage::GetCurrent().Add(actor);
818 application.SendNotification();
819 application.Render();
821 // Change state to Gesture::Continuing to remove
822 stateToUnstage = Gesture::Finished;
825 TestGenerateLongPress( application, 50.0f, 10.0f );
826 DALI_TEST_EQUALS(true, data.functorCalled, TEST_LOCATION);
828 TestEndLongPress( application, 50.0f, 10.0f );
829 DALI_TEST_EQUALS(true, data.functorCalled, TEST_LOCATION);
830 tet_result( TET_PASS ); // If we get here then we have handled actor stage removal gracefully.
834 int UtcDaliLongPressGestureActorStagedAndDestroyed(void)
836 TestApplication application;
838 Actor actor = Actor::New();
839 actor.SetSize(100.0f, 100.0f);
840 actor.SetAnchorPoint(AnchorPoint::TOP_LEFT);
841 Stage::GetCurrent().Add(actor);
843 // Create and add a second actor so that GestureDetector destruction does not come into play.
844 Actor dummyActor( Actor::New() );
845 dummyActor.SetSize( 100.0f, 100.0f );
846 dummyActor.SetPosition( 100.0f, 100.0f );
847 dummyActor.SetAnchorPoint(AnchorPoint::TOP_LEFT);
848 Stage::GetCurrent().Add(dummyActor);
851 application.SendNotification();
852 application.Render();
854 // State to remove actor in.
855 Gesture::State stateToUnstage( Gesture::Started );
857 // Attach actor to detector
859 UnstageActorFunctor functor( data, stateToUnstage );
860 LongPressGestureDetector detector = LongPressGestureDetector::New();
861 detector.Attach(actor);
862 detector.Attach(dummyActor);
863 detector.DetectedSignal().Connect( &application, functor );
865 // Here we are testing a Started actor which is removed in the Started callback, but then added back
866 // before we get a finished state. As we were removed from the stage, even if we're at the same
867 // position, we should still not be signalled.
870 TestGenerateLongPress( application, 50.0f, 10.0f );
871 DALI_TEST_EQUALS(true, data.functorCalled, TEST_LOCATION);
875 application.SendNotification();
876 application.Render();
878 // Re add to the stage, we should not be signalled
879 Stage::GetCurrent().Add(actor);
882 application.SendNotification();
883 application.Render();
885 // Continue signal emission
886 TestEndLongPress( application, 50.0f, 10.0f );
887 DALI_TEST_EQUALS(false, data.functorCalled, TEST_LOCATION);
890 // Here we delete an actor in started, we should not receive any subsequent signalling.
893 TestGenerateLongPress( application, 50.0f, 10.0f );
894 DALI_TEST_EQUALS(true, data.functorCalled, TEST_LOCATION);
898 application.SendNotification();
899 application.Render();
901 // Delete actor as well
905 application.SendNotification();
906 application.Render();
908 // Continue signal emission
909 TestEndLongPress( application, 50.0f, 10.0f );
910 DALI_TEST_EQUALS(false, data.functorCalled, TEST_LOCATION);
914 int UtcDaliLongPressGestureLayerConsumesTouch(void)
916 TestApplication application;
918 Actor actor = Actor::New();
919 actor.SetSize(100.0f, 100.0f);
920 actor.SetAnchorPoint(AnchorPoint::TOP_LEFT);
921 Stage::GetCurrent().Add(actor);
925 GestureReceivedFunctor functor(data);
926 LongPressGestureDetector detector = LongPressGestureDetector::New();
927 detector.Attach(actor);
928 detector.DetectedSignal().Connect( &application, functor );
930 // Add a layer to overlap the actor
931 Layer layer = Layer::New();
932 layer.SetSize(100.0f, 100.0f);
933 layer.SetAnchorPoint(AnchorPoint::TOP_LEFT);
934 Stage::GetCurrent().Add( layer );
938 application.SendNotification();
939 application.Render();
941 // Emit signals, should receive
942 TestGenerateLongPress( application, 50.0f, 50.0f );
943 TestEndLongPress( application, 50.0f, 50.0f );
944 DALI_TEST_EQUALS(true, data.functorCalled, TEST_LOCATION);
947 // Set layer to consume all touch
948 layer.SetTouchConsumed( true );
951 application.SendNotification();
952 application.Render();
954 // Emit the same signals again, should not receive
955 TestGenerateLongPress( application, 50.0f, 50.0f );
956 TestEndLongPress( application, 50.0f, 50.0f );
957 DALI_TEST_EQUALS(false, data.functorCalled, TEST_LOCATION);