2 * Copyright (c) 2020 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/input-options.h>
24 #include <dali/integration-api/render-task-list-integ.h>
25 #include <dali/devel-api/events/long-press-gesture-detector-devel.h>
26 #include <dali-test-suite-utils.h>
27 #include <test-touch-data-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, Integration::Scene scene )
97 : GestureReceivedFunctor( data ),
98 stateToUnstage( stateToUnstage ),
103 void operator()( Actor actor, const LongPressGesture& longPress )
105 GestureReceivedFunctor::operator()( actor, longPress );
107 if ( longPress.state == stateToUnstage )
109 scene.Remove( actor );
113 Gesture::State& stateToUnstage;
114 Integration::Scene scene;
117 // Functor for receiving a touch event
118 struct TouchDataFunctor
120 bool operator()(Actor actor, Dali::TouchData touch)
123 unsigned int points = touch.GetPointCount();
126 tet_printf("Touch Point state = %d\n", touch.GetState(0));
134 ///////////////////////////////////////////////////////////////////////////////
137 // Positive test case for a method
138 int UtcDaliLongPressGestureDetectorConstructorP(void)
140 TestApplication application;
142 LongPressGestureDetector detector;
143 DALI_TEST_CHECK(!detector);
147 int UtcDaliLongPressGestureDetectorCopyConstructorP(void)
149 TestApplication application;
151 LongPressGestureDetector detector = LongPressGestureDetector::New();;
153 LongPressGestureDetector copy( detector );
154 DALI_TEST_CHECK( detector );
158 int UtcDaliLongPressGestureDetectorAssignmentOperatorP(void)
160 TestApplication application;
162 LongPressGestureDetector detector;
163 detector = LongPressGestureDetector::New();;
165 LongPressGestureDetector copy;
167 DALI_TEST_CHECK( detector );
169 DALI_TEST_CHECK( detector == copy );
173 int UtcDaliLongPressGestureDetectorNew(void)
175 TestApplication application;
177 LongPressGestureDetector detector = LongPressGestureDetector::New();
178 DALI_TEST_CHECK(detector);
179 DALI_TEST_EQUALS(1u, detector.GetMinimumTouchesRequired(), TEST_LOCATION);
180 DALI_TEST_EQUALS(1u, detector.GetMaximumTouchesRequired(), TEST_LOCATION);
182 LongPressGestureDetector detector2 = LongPressGestureDetector::New(5u);
183 DALI_TEST_CHECK(detector2);
184 DALI_TEST_EQUALS(5u, detector2.GetMinimumTouchesRequired(), TEST_LOCATION);
185 DALI_TEST_EQUALS(5u, detector2.GetMaximumTouchesRequired(), TEST_LOCATION);
187 LongPressGestureDetector detector3 = LongPressGestureDetector::New(5u, 7u);
188 DALI_TEST_CHECK(detector2);
189 DALI_TEST_EQUALS(5u, detector3.GetMinimumTouchesRequired(), TEST_LOCATION);
190 DALI_TEST_EQUALS(7u, detector3.GetMaximumTouchesRequired(), TEST_LOCATION);
192 //Scoped test to test destructor
194 LongPressGestureDetector detector4 = LongPressGestureDetector::New();
195 DALI_TEST_CHECK(detector4);
198 // Attach an actor and emit a touch event on the actor to ensure complete line coverage
199 Actor actor = Actor::New();
200 actor.SetProperty( Actor::Property::SIZE, Vector2( 100.0f, 100.0f ) );
201 actor.SetProperty( Actor::Property::ANCHOR_POINT,AnchorPoint::TOP_LEFT);
202 application.GetScene().Add(actor);
205 application.SendNotification();
206 application.Render();
208 detector.Attach(actor);
210 TouchDataFunctor touchFunctor;
211 actor.TouchSignal().Connect(&application, touchFunctor);
213 Integration::TouchEvent touchEvent(1);
214 Integration::Point point;
215 point.SetDeviceId( 1 );
216 point.SetState( PointState::DOWN );
217 point.SetScreenPosition( Vector2( 20.0f, 20.0f ) );
218 touchEvent.AddPoint(point);
219 application.ProcessEvent(touchEvent);
222 application.SendNotification();
223 application.Render();
228 int UtcDaliLongPressGestureDetectorDownCast(void)
230 TestApplication application;
231 tet_infoline("Testing Dali::LongPressGestureDetector::DownCast()");
233 LongPressGestureDetector detector = LongPressGestureDetector::New();
235 BaseHandle object(detector);
237 LongPressGestureDetector detector2 = LongPressGestureDetector::DownCast(object);
238 DALI_TEST_CHECK(detector2);
240 LongPressGestureDetector detector3 = DownCast< LongPressGestureDetector >(object);
241 DALI_TEST_CHECK(detector3);
243 BaseHandle unInitializedObject;
244 LongPressGestureDetector detector4 = LongPressGestureDetector::DownCast(unInitializedObject);
245 DALI_TEST_CHECK(!detector4);
247 LongPressGestureDetector detector5 = DownCast< LongPressGestureDetector >(unInitializedObject);
248 DALI_TEST_CHECK(!detector5);
250 GestureDetector detector6 = LongPressGestureDetector::New();
251 LongPressGestureDetector detector7 = LongPressGestureDetector::DownCast(detector6);
252 DALI_TEST_CHECK(detector7);
256 int UtcDaliLongPressGestureGetMinimumTouchesRequired(void)
258 TestApplication application;
260 LongPressGestureDetector detector = LongPressGestureDetector::New();
261 DALI_TEST_EQUALS(1u, detector.GetMinimumTouchesRequired(), TEST_LOCATION);
265 int UtcDaliLongPressGestureGetMaximumTouchesRequired(void)
267 TestApplication application;
269 LongPressGestureDetector detector = LongPressGestureDetector::New();
270 DALI_TEST_EQUALS(1u, detector.GetMaximumTouchesRequired(), TEST_LOCATION);
274 int UtcDaliLongPressGestureSignalReceptionNegative(void)
276 TestApplication application;
278 Actor actor = Actor::New();
279 actor.SetProperty( Actor::Property::SIZE, Vector2( 100.0f, 100.0f ) );
280 actor.SetProperty( Actor::Property::ANCHOR_POINT,AnchorPoint::TOP_LEFT);
281 application.GetScene().Add(actor);
284 application.SendNotification();
285 application.Render();
288 GestureReceivedFunctor functor(data);
290 LongPressGestureDetector detector = LongPressGestureDetector::New();
291 detector.Attach(actor);
292 detector.DetectedSignal().Connect(&application, functor);
294 // Do a long press outside actor's area
295 TestGenerateLongPress( application, 112.0f, 112.0f );
296 TestEndLongPress( application, 112.0f, 112.0f);
298 DALI_TEST_EQUALS(false, data.functorCalled, TEST_LOCATION);
302 int UtcDaliLongPressGestureSignalReceptionPositive(void)
304 TestApplication application;
306 Actor actor = Actor::New();
307 actor.SetProperty( Actor::Property::SIZE, Vector2( 100.0f, 100.0f ) );
308 actor.SetProperty( Actor::Property::ANCHOR_POINT,AnchorPoint::TOP_LEFT);
309 application.GetScene().Add(actor);
312 application.SendNotification();
313 application.Render();
316 GestureReceivedFunctor functor(data);
318 LongPressGestureDetector detector = LongPressGestureDetector::New();
319 detector.Attach(actor);
320 detector.DetectedSignal().Connect(&application, functor);
322 // Do a long press inside actor's area
323 TestGenerateLongPress( application, 50.0f, 50.0f );
324 DALI_TEST_EQUALS(true, data.functorCalled, TEST_LOCATION);
325 DALI_TEST_EQUALS(1u, data.receivedGesture.numberOfTouches, TEST_LOCATION);
326 DALI_TEST_EQUALS( Vector2(50.0f, 50.0f), data.receivedGesture.localPoint, 0.1, TEST_LOCATION);
327 TestEndLongPress( application, 50.0f, 50.0f);
331 int UtcDaliLongPressGestureSignalReceptionDetach(void)
333 TestApplication application;
335 Actor actor = Actor::New();
336 actor.SetProperty( Actor::Property::SIZE, Vector2( 100.0f, 100.0f ) );
337 actor.SetProperty( Actor::Property::ANCHOR_POINT,AnchorPoint::TOP_LEFT);
338 application.GetScene().Add(actor);
341 application.SendNotification();
342 application.Render();
345 GestureReceivedFunctor functor(data);
347 LongPressGestureDetector detector = LongPressGestureDetector::New();
348 detector.Attach(actor);
349 detector.DetectedSignal().Connect(&application, functor);
351 // Start long press within the actor's area
352 TestGenerateLongPress( application, 20.0f, 20.0f );
353 DALI_TEST_EQUALS(true, data.functorCalled, TEST_LOCATION);
354 DALI_TEST_EQUALS(1u, data.receivedGesture.numberOfTouches, TEST_LOCATION);
355 DALI_TEST_EQUALS( Vector2(20.0f, 20.0f), data.receivedGesture.localPoint, 0.1, TEST_LOCATION);
356 TestEndLongPress( application, 20.0f, 20.0f);
358 // repeat the long press within the actor's area - we should still receive the signal
360 TestGenerateLongPress( application, 50.0f, 50.0f );
361 DALI_TEST_EQUALS(true, data.functorCalled, TEST_LOCATION);
362 DALI_TEST_EQUALS(1u, data.receivedGesture.numberOfTouches, TEST_LOCATION);
363 DALI_TEST_EQUALS( Vector2(50.0f, 50.0f), data.receivedGesture.localPoint, 0.1, TEST_LOCATION);
364 TestEndLongPress( application, 50.0f, 50.0f);
367 detector.DetachAll();
369 // Ensure we are no longer signalled
371 TestGenerateLongPress( application, 20.0f, 20.0f );
372 DALI_TEST_EQUALS(false, data.functorCalled, TEST_LOCATION);
373 TestEndLongPress( application, 50.0f, 50.0f);
374 DALI_TEST_EQUALS(false, data.functorCalled, TEST_LOCATION);
378 int UtcDaliLongPressGestureSignalReceptionActorDestroyedDuringLongPress(void)
380 TestApplication application;
383 GestureReceivedFunctor functor(data);
385 LongPressGestureDetector detector = LongPressGestureDetector::New();
386 detector.DetectedSignal().Connect(&application, functor);
388 // Actor lifetime is scoped
390 Actor actor = Actor::New();
391 actor.SetProperty( Actor::Property::SIZE, Vector2( 100.0f, 100.0f ) );
392 actor.SetProperty( Actor::Property::ANCHOR_POINT,AnchorPoint::TOP_LEFT);
393 application.GetScene().Add(actor);
396 application.SendNotification();
397 application.Render();
399 detector.Attach(actor);
401 // Start long press within the actor's area
402 TestGenerateLongPress( application, 20.0f, 20.0f );
403 DALI_TEST_EQUALS(true, data.functorCalled, TEST_LOCATION);
405 // Remove the actor from stage and reset the data
406 application.GetScene().Remove(actor);
409 application.SendNotification();
410 application.Render();
413 // Actor should now have been destroyed
416 TestEndLongPress( application, 20.0f, 20.0f);
417 DALI_TEST_EQUALS(false, data.functorCalled, TEST_LOCATION);
421 int UtcDaliLongPressGestureSignalReceptionRotatedActor(void)
423 TestApplication application;
425 Actor actor = Actor::New();
426 actor.SetProperty( Actor::Property::SIZE, Vector2( 100.0f, 100.0f ) );
427 actor.SetProperty( Actor::Property::ORIENTATION, Quaternion( Dali::Degree(90.0f), Vector3::ZAXIS ) );
428 application.GetScene().Add(actor);
431 application.SendNotification();
432 application.Render();
435 GestureReceivedFunctor functor(data);
437 LongPressGestureDetector detector = LongPressGestureDetector::New();
438 detector.Attach(actor);
439 detector.DetectedSignal().Connect(&application, functor);
442 TestGenerateLongPress( application, 5.0f, 5.0f );
443 TestEndLongPress( application, 5.0f, 5.0f);
444 DALI_TEST_EQUALS(true, data.functorCalled, TEST_LOCATION);
445 DALI_TEST_EQUALS(1u, data.receivedGesture.numberOfTouches, TEST_LOCATION);
446 DALI_TEST_EQUALS( Vector2(5.0f, 5.0f), data.receivedGesture.screenPoint, 0.1, TEST_LOCATION);
448 // Rotate actor again and render
449 actor.SetProperty( Actor::Property::ORIENTATION, Quaternion(Dali::Degree(180.0f), Vector3::ZAXIS) );
450 application.SendNotification();
451 application.Render();
453 // Do another long press, should still receive event
455 TestGenerateLongPress( application, 5.0f, 5.0f );
456 TestEndLongPress( application, 5.0f, 5.0f);
457 DALI_TEST_EQUALS(true, data.functorCalled, TEST_LOCATION);
458 DALI_TEST_EQUALS(1u, data.receivedGesture.numberOfTouches, TEST_LOCATION);
459 DALI_TEST_EQUALS( Vector2(5.0f, 5.0f), data.receivedGesture.screenPoint, 0.1, TEST_LOCATION);
461 // Rotate actor again and render
462 actor.SetProperty( Actor::Property::ORIENTATION, Quaternion(Dali::Degree(90.0f), Vector3::YAXIS) );
463 application.SendNotification();
464 application.Render();
466 // Do a long press, inside where the actor used to be, Should not receive the event
468 TestGenerateLongPress( application, 70.0f, 70.0f );
469 TestEndLongPress( application, 70.0f, 70.0f);
470 DALI_TEST_EQUALS(false, data.functorCalled, TEST_LOCATION);
474 int UtcDaliLongPressGestureSignalReceptionChildHit(void)
476 TestApplication application;
478 Actor parent = Actor::New();
479 parent.SetProperty( Actor::Property::SIZE, Vector2( 100.0f, 100.0f ) );
480 parent.SetProperty( Actor::Property::ANCHOR_POINT,AnchorPoint::TOP_LEFT);
481 application.GetScene().Add(parent);
483 // Set child to completely cover parent.
484 // Change rotation of child to be different from parent so that we can check if our local coordinate
485 // conversion of the parent actor is correct.
486 Actor child = Actor::New();
487 child.SetProperty( Actor::Property::SIZE, Vector2( 100.0f, 100.0f ) );
488 child.SetProperty( Actor::Property::ANCHOR_POINT,AnchorPoint::CENTER);
489 child.SetProperty( Actor::Property::PARENT_ORIGIN,ParentOrigin::CENTER);
490 child.SetProperty( Actor::Property::ORIENTATION, Quaternion(Dali::Degree(90.0f), Vector3::ZAXIS) );
494 application.SendNotification();
495 application.Render();
498 GestureReceivedFunctor functor(data);
500 LongPressGestureDetector detector = LongPressGestureDetector::New();
501 detector.Attach(parent);
502 detector.DetectedSignal().Connect(&application, functor);
504 // Do long press - hits child area but parent should still receive it
505 TestGenerateLongPress( application, 50.0f, 50.0f );
506 TestEndLongPress( application, 50.0f, 50.0f);
507 DALI_TEST_EQUALS(true, data.functorCalled, TEST_LOCATION);
508 DALI_TEST_EQUALS(true, parent == data.pressedActor, TEST_LOCATION);
509 DALI_TEST_EQUALS(Vector2(50.0f, 50.0f), data.receivedGesture.screenPoint, 0.01f, TEST_LOCATION);
511 // Attach child and generate same touch points
512 // (Also proves that you can detach and then re-attach another actor)
513 detector.Attach(child);
514 detector.Detach(parent);
516 // Do an entire long press, only check finished value
518 TestGenerateLongPress( application, 51.0f, 51.0f );
519 TestEndLongPress( application, 51.0f, 51.0f);
520 DALI_TEST_EQUALS(true, data.functorCalled, TEST_LOCATION);
521 DALI_TEST_EQUALS(true, child == data.pressedActor, TEST_LOCATION);
522 DALI_TEST_EQUALS(Vector2(51.0f, 51.0f), data.receivedGesture.screenPoint, 0.01f, TEST_LOCATION);
526 int UtcDaliLongPressGestureSignalReceptionAttachDetachMany(void)
528 TestApplication application;
530 Actor first = Actor::New();
531 first.SetProperty( Actor::Property::SIZE, Vector2( 100.0f, 100.0f ) );
532 first.SetProperty( Actor::Property::ANCHOR_POINT,AnchorPoint::TOP_LEFT);
533 application.GetScene().Add(first);
535 Actor second = Actor::New();
536 second.SetProperty( Actor::Property::SIZE, Vector2( 100.0f, 100.0f ) );
537 second.SetProperty( Actor::Property::POSITION_X, 100.0f);
538 second.SetProperty( Actor::Property::ANCHOR_POINT,AnchorPoint::TOP_LEFT);
539 application.GetScene().Add(second);
542 application.SendNotification();
543 application.Render();
546 GestureReceivedFunctor functor(data);
548 LongPressGestureDetector detector = LongPressGestureDetector::New();
549 detector.Attach(first);
550 detector.Attach(second);
551 detector.DetectedSignal().Connect(&application, functor);
553 // LongPress within second actor's area
554 TestGenerateLongPress( application, 120.0f, 10.0f );
555 TestEndLongPress( application, 120.0f, 10.0f);
556 DALI_TEST_EQUALS(true, data.functorCalled, TEST_LOCATION);
557 DALI_TEST_EQUALS(true, second == data.pressedActor, TEST_LOCATION);
559 // LongPress within first actor's area
561 TestGenerateLongPress( application, 20.0f, 10.0f );
562 TestEndLongPress( application, 20.0f, 10.0f);
563 DALI_TEST_EQUALS(true, data.functorCalled, TEST_LOCATION);
564 DALI_TEST_EQUALS(true, first == data.pressedActor, TEST_LOCATION);
566 // Detach the second actor
567 detector.Detach(second);
569 // second actor shouldn't receive event
571 TestGenerateLongPress( application, 120.0f, 10.0f );
572 TestEndLongPress( application, 120.0f, 10.0f);
573 DALI_TEST_EQUALS(false, data.functorCalled, TEST_LOCATION);
575 // first actor should continue receiving event
577 TestGenerateLongPress( application, 20.0f, 10.0f );
578 TestEndLongPress( application, 20.0f, 10.0f);
579 DALI_TEST_EQUALS(true, data.functorCalled, TEST_LOCATION);
583 int UtcDaliLongPressGestureSignalReceptionActorBecomesUntouchable(void)
585 TestApplication application;
587 Actor actor = Actor::New();
588 actor.SetProperty( Actor::Property::SIZE, Vector2( 100.0f, 100.0f ) );
589 actor.SetProperty( Actor::Property::ANCHOR_POINT,AnchorPoint::TOP_LEFT);
590 application.GetScene().Add(actor);
593 application.SendNotification();
594 application.Render();
597 GestureReceivedFunctor functor(data);
599 LongPressGestureDetector detector = LongPressGestureDetector::New();
600 detector.Attach(actor);
601 detector.DetectedSignal().Connect(&application, functor);
603 // LongPress in actor's area
604 TestGenerateLongPress( application, 50.0f, 10.0f );
605 TestEndLongPress( application, 50.0f, 10.0f);
606 DALI_TEST_EQUALS(true, data.functorCalled, TEST_LOCATION);
608 // Actor becomes invisible - actor should not receive the next long press
609 actor.SetProperty( Actor::Property::VISIBLE,false);
612 application.SendNotification();
613 application.Render();
615 // LongPress in the same area, shouldn't receive event
617 TestGenerateLongPress( application, 50.0f, 10.0f );
618 TestEndLongPress( application, 50.0f, 10.0f);
619 DALI_TEST_EQUALS(false, data.functorCalled, TEST_LOCATION);
623 int UtcDaliLongPressGestureSignalReceptionMultipleDetectorsOnActor(void)
625 TestApplication application;
627 Actor actor = Actor::New();
628 actor.SetProperty( Actor::Property::SIZE, Vector2( 100.0f, 100.0f ) );
629 actor.SetProperty( Actor::Property::ANCHOR_POINT,AnchorPoint::TOP_LEFT);
630 application.GetScene().Add(actor);
633 application.SendNotification();
634 application.Render();
636 // Attach actor to one detector
637 SignalData firstData;
638 GestureReceivedFunctor firstFunctor(firstData);
639 LongPressGestureDetector firstDetector = LongPressGestureDetector::New();
640 firstDetector.Attach(actor);
641 firstDetector.DetectedSignal().Connect(&application, firstFunctor);
643 // Attach actor to another detector
644 SignalData secondData;
645 GestureReceivedFunctor secondFunctor(secondData);
646 LongPressGestureDetector secondDetector = LongPressGestureDetector::New();
647 secondDetector.Attach(actor);
648 secondDetector.DetectedSignal().Connect(&application, secondFunctor);
650 // LongPress in actor's area - both detector's functors should be called
651 TestGenerateLongPress( application, 50.0f, 10.0f );
652 DALI_TEST_EQUALS(true, firstData.functorCalled, TEST_LOCATION);
653 DALI_TEST_EQUALS(true, secondData.functorCalled, TEST_LOCATION);
657 int UtcDaliLongPressGestureSignalReceptionDifferentPossible(void)
659 TestApplication application;
661 Actor actor = Actor::New();
662 actor.SetProperty( Actor::Property::SIZE, Vector2( 100.0f, 100.0f ) );
663 actor.SetProperty( Actor::Property::ANCHOR_POINT,AnchorPoint::TOP_LEFT);
664 application.GetScene().Add(actor);
667 application.SendNotification();
668 application.Render();
670 // Attach actor to detector
672 GestureReceivedFunctor functor( data );
673 LongPressGestureDetector detector = LongPressGestureDetector::New();
674 detector.Attach(actor);
675 detector.DetectedSignal().Connect( &application, functor );
677 // LongPress possible in actor's area.
678 TestStartLongPress( application, 50.0f, 10.0f );
679 DALI_TEST_EQUALS(false, data.functorCalled, TEST_LOCATION);
681 // Move actor somewhere else
682 actor.SetProperty( Actor::Property::POSITION, Vector2( 100.0f, 100.0f ));
685 application.SendNotification();
686 application.Render();
688 // Emit Started event, we should not receive the long press.
689 TestTriggerLongPress( application );
690 TestGenerateLongPress( application, 50.0f, 10.0f );
691 DALI_TEST_EQUALS(false, data.functorCalled, TEST_LOCATION);
693 // LongPress possible in empty area.
694 TestStartLongPress( application, 50.0f, 10.0f );
695 DALI_TEST_EQUALS(false, data.functorCalled, TEST_LOCATION);
697 // Move actor in to the long press position.
698 actor.SetProperty( Actor::Property::POSITION, Vector2( 0.0f, 0.0f ));
701 application.SendNotification();
702 application.Render();
704 // Emit Started event, we should not receive the long press.
705 TestTriggerLongPress( application );
706 TestEndLongPress( application, 50.0f, 10.0f );
707 DALI_TEST_EQUALS(false, data.functorCalled, TEST_LOCATION);
709 // Normal long press in actor's area for completeness.
710 TestGenerateLongPress( application, 50.0f, 10.0f );
711 TestEndLongPress( application, 50.0f, 10.0f);
712 DALI_TEST_EQUALS(true, data.functorCalled, TEST_LOCATION);
716 int UtcDaliLongPressGesturePossibleCancelled(void)
718 TestApplication application;
720 Actor actor = Actor::New();
721 actor.SetProperty( Actor::Property::SIZE, Vector2( 100.0f, 100.0f ) );
722 actor.SetProperty( Actor::Property::ANCHOR_POINT,AnchorPoint::TOP_LEFT);
723 application.GetScene().Add(actor);
726 application.SendNotification();
727 application.Render();
729 // Attach actor to detector
731 GestureReceivedFunctor functor( data );
732 LongPressGestureDetector detector = LongPressGestureDetector::New();
733 detector.Attach(actor);
734 detector.DetectedSignal().Connect( &application, functor );
736 // Send a possible followed by a cancel, we should not be signalled
737 TestStartLongPress( application, 50.0f, 10.0f );
738 DALI_TEST_EQUALS(false, data.functorCalled, TEST_LOCATION);
739 TestMovePan( application, Vector2( 50.0f, 10.0f ) );
740 DALI_TEST_EQUALS(false, data.functorCalled, TEST_LOCATION);
744 int UtcDaliLongPressGestureDetachAfterStarted(void)
746 TestApplication application;
748 Actor actor = Actor::New();
749 actor.SetProperty( Actor::Property::SIZE, Vector2( 100.0f, 100.0f ) );
750 actor.SetProperty( Actor::Property::ANCHOR_POINT,AnchorPoint::TOP_LEFT);
751 application.GetScene().Add(actor);
754 application.SendNotification();
755 application.Render();
757 // Attach actor to detector
759 GestureReceivedFunctor functor( data );
760 LongPressGestureDetector detector = LongPressGestureDetector::New();
761 detector.Attach(actor);
762 detector.DetectedSignal().Connect( &application, functor );
764 // Emit initial signal
765 TestGenerateLongPress( application, 50.0f, 10.0f );
766 DALI_TEST_EQUALS(true, data.functorCalled, TEST_LOCATION);
770 detector.Detach(actor);
772 // Emit Finished, no signal
773 TestEndLongPress( application, 50.0f, 10.0f );
774 DALI_TEST_EQUALS(false, data.functorCalled, TEST_LOCATION);
778 int UtcDaliLongPressGestureActorUnstaged(void)
780 TestApplication application;
782 Actor actor = Actor::New();
783 actor.SetProperty( Actor::Property::SIZE, Vector2( 100.0f, 100.0f ) );
784 actor.SetProperty( Actor::Property::ANCHOR_POINT,AnchorPoint::TOP_LEFT);
785 application.GetScene().Add(actor);
788 application.SendNotification();
789 application.Render();
791 // State to remove actor in.
792 Gesture::State stateToUnstage( Gesture::Started );
794 // Attach actor to detector
796 UnstageActorFunctor functor( data, stateToUnstage, application.GetScene() );
797 LongPressGestureDetector detector = LongPressGestureDetector::New();
798 detector.Attach(actor);
799 detector.DetectedSignal().Connect( &application, functor );
802 TestGenerateLongPress( application, 50.0f, 10.0f );
803 DALI_TEST_EQUALS(true, data.functorCalled, TEST_LOCATION);
805 TestEndLongPress( application, 50.0f, 10.0f );
806 DALI_TEST_EQUALS(false, data.functorCalled, TEST_LOCATION);
809 application.SendNotification();
810 application.Render();
812 // Re-add actor to stage
813 application.GetScene().Add(actor);
816 application.SendNotification();
817 application.Render();
819 // Change state to Gesture::Continuing to remove
820 stateToUnstage = Gesture::Finished;
823 TestGenerateLongPress( application, 50.0f, 10.0f );
824 DALI_TEST_EQUALS(true, data.functorCalled, TEST_LOCATION);
826 TestEndLongPress( application, 50.0f, 10.0f );
827 DALI_TEST_EQUALS(true, data.functorCalled, TEST_LOCATION);
828 tet_result( TET_PASS ); // If we get here then we have handled actor stage removal gracefully.
832 int UtcDaliLongPressGestureActorStagedAndDestroyed(void)
834 TestApplication application;
836 Actor actor = Actor::New();
837 actor.SetProperty( Actor::Property::SIZE, Vector2( 100.0f, 100.0f ) );
838 actor.SetProperty( Actor::Property::ANCHOR_POINT,AnchorPoint::TOP_LEFT);
839 application.GetScene().Add(actor);
841 // Create and add a second actor so that GestureDetector destruction does not come into play.
842 Actor dummyActor( Actor::New() );
843 dummyActor.SetProperty( Actor::Property::SIZE, Vector2( 100.0f, 100.0f ) );
844 dummyActor.SetProperty( Actor::Property::POSITION, Vector2( 100.0f, 100.0f ));
845 dummyActor.SetProperty( Actor::Property::ANCHOR_POINT,AnchorPoint::TOP_LEFT);
846 application.GetScene().Add(dummyActor);
849 application.SendNotification();
850 application.Render();
852 // State to remove actor in.
853 Gesture::State stateToUnstage( Gesture::Started );
855 // Attach actor to detector
857 UnstageActorFunctor functor( data, stateToUnstage, application.GetScene() );
858 LongPressGestureDetector detector = LongPressGestureDetector::New();
859 detector.Attach(actor);
860 detector.Attach(dummyActor);
861 detector.DetectedSignal().Connect( &application, functor );
863 // Here we are testing a Started actor which is removed in the Started callback, but then added back
864 // before we get a finished state. As we were removed from the stage, even if we're at the same
865 // position, we should still not be signalled.
868 TestGenerateLongPress( application, 50.0f, 10.0f );
869 DALI_TEST_EQUALS(true, data.functorCalled, TEST_LOCATION);
873 application.SendNotification();
874 application.Render();
876 // Re add to the stage, we should not be signalled
877 application.GetScene().Add(actor);
880 application.SendNotification();
881 application.Render();
883 // Continue signal emission
884 TestEndLongPress( application, 50.0f, 10.0f );
885 DALI_TEST_EQUALS(false, data.functorCalled, TEST_LOCATION);
888 // Here we delete an actor in started, we should not receive any subsequent signalling.
891 TestGenerateLongPress( application, 50.0f, 10.0f );
892 DALI_TEST_EQUALS(true, data.functorCalled, TEST_LOCATION);
896 application.SendNotification();
897 application.Render();
899 // Delete actor as well
903 application.SendNotification();
904 application.Render();
906 // Continue signal emission
907 TestEndLongPress( application, 50.0f, 10.0f );
908 DALI_TEST_EQUALS(false, data.functorCalled, TEST_LOCATION);
912 int UtcDaliLongPressGestureLayerConsumesTouch(void)
914 TestApplication application;
916 Actor actor = Actor::New();
917 actor.SetProperty( Actor::Property::SIZE, Vector2( 100.0f, 100.0f ) );
918 actor.SetProperty( Actor::Property::ANCHOR_POINT,AnchorPoint::TOP_LEFT);
919 application.GetScene().Add(actor);
923 GestureReceivedFunctor functor(data);
924 LongPressGestureDetector detector = LongPressGestureDetector::New();
925 detector.Attach(actor);
926 detector.DetectedSignal().Connect( &application, functor );
928 // Add a layer to overlap the actor
929 Layer layer = Layer::New();
930 layer.SetProperty( Actor::Property::SIZE, Vector2( 100.0f, 100.0f ) );
931 layer.SetProperty( Actor::Property::ANCHOR_POINT,AnchorPoint::TOP_LEFT);
932 application.GetScene().Add( layer );
936 application.SendNotification();
937 application.Render();
939 // Emit signals, should receive
940 TestGenerateLongPress( application, 50.0f, 50.0f );
941 TestEndLongPress( application, 50.0f, 50.0f );
942 DALI_TEST_EQUALS(true, data.functorCalled, TEST_LOCATION);
945 // Set layer to consume all touch
946 layer.SetProperty( Layer::Property::CONSUMES_TOUCH, true );
949 application.SendNotification();
950 application.Render();
952 // Emit the same signals again, should not receive
953 TestGenerateLongPress( application, 50.0f, 50.0f );
954 TestEndLongPress( application, 50.0f, 50.0f );
955 DALI_TEST_EQUALS(false, data.functorCalled, TEST_LOCATION);
961 int UtcDaliLongPressGestureSetMinimumHoldingTime(void)
963 TestApplication application;
965 const uint32_t kMinumumHolding1 = 5000;
966 const uint32_t kMinumumHolding2 = 3000;
968 Integration::SetLongPressMinimumHoldingTime( kMinumumHolding1 );
970 Actor actor = Actor::New();
971 actor.SetProperty( Actor::Property::SIZE, Vector2( 100.0f, 100.0f ) );
972 actor.SetProperty( Actor::Property::ANCHOR_POINT, AnchorPoint::TOP_LEFT );
973 application.GetScene().Add( actor );
976 application.SendNotification();
977 application.Render();
980 GestureReceivedFunctor functor( data );
982 LongPressGestureDetector detector = LongPressGestureDetector::New();
983 detector.Attach(actor);
984 detector.DetectedSignal().Connect(&application, functor);
986 DALI_TEST_EQUALS( DevelLongPressGestureDetector::GetMinimumHoldingTime( detector ), kMinumumHolding1, TEST_LOCATION );
988 Integration::SetLongPressMinimumHoldingTime( kMinumumHolding2 );
989 DALI_TEST_EQUALS( DevelLongPressGestureDetector::GetMinimumHoldingTime( detector ), kMinumumHolding2, TEST_LOCATION );
994 int UtcDaliLongPressGestureInterruptedWhenTouchConsumed(void)
996 TestApplication application;
998 Actor actor = Actor::New();
999 actor.SetProperty( Actor::Property::SIZE, Vector2( 100.0f, 100.0f ) );
1000 actor.SetProperty( Actor::Property::ANCHOR_POINT,AnchorPoint::TOP_LEFT);
1001 application.GetScene().Add(actor);
1003 bool consume = false;
1004 TouchDataFunctorConsumeSetter touchFunctor(consume);
1005 actor.TouchSignal().Connect(&application,touchFunctor);
1007 // Render and notify
1008 application.SendNotification();
1009 application.Render();
1012 GestureReceivedFunctor functor(data);
1014 LongPressGestureDetector detector = LongPressGestureDetector::New();
1015 detector.Attach(actor);
1016 detector.DetectedSignal().Connect(&application, functor);
1018 // Start gesture within the actor's area, we should receive the gesture as the touch is NOT being consumed
1019 TestGenerateLongPress( application, 50.0f, 50.0f );
1020 DALI_TEST_EQUALS(true, data.functorCalled, TEST_LOCATION);
1022 TestEndLongPress(application, 50.0f,50.0f);
1023 DALI_TEST_EQUALS(true, data.functorCalled, TEST_LOCATION);
1026 // Another gesture in the same location, this time we will not receive it as touch is being consumed
1028 TestGenerateLongPress( application, 50.0f, 50.0f );
1029 DALI_TEST_EQUALS(false, data.functorCalled, TEST_LOCATION);
1031 TestEndLongPress(application, 50.0f,50.0f);
1032 DALI_TEST_EQUALS(false, data.functorCalled, TEST_LOCATION);
1037 int UtcDaliLongPressGestureDisableDetectionDuringLongPressN(void)
1039 // Crash occurred when gesture-recognizer was deleted internally during a signal when the attached actor was detached
1041 TestApplication application;
1043 Actor actor = Actor::New();
1044 actor.SetProperty( Actor::Property::SIZE, Vector2( 100.0f, 100.0f ) );
1045 actor.SetProperty( Actor::Property::ANCHOR_POINT,AnchorPoint::TOP_LEFT);
1046 application.GetScene().Add(actor);
1049 LongPressGestureDetector detector = LongPressGestureDetector::New();
1050 bool functorCalled = false;
1051 detector.Attach( actor );
1052 detector.DetectedSignal().Connect(
1054 [&detector, &functorCalled](Actor actor, const LongPressGesture& gesture)
1056 if( gesture.state == Gesture::Finished )
1058 detector.Detach(actor);
1059 functorCalled = true;
1063 // Render and notify
1064 application.SendNotification();
1065 application.Render();
1067 // Try the gesture, should not crash
1070 TestGenerateLongPress( application, 50.0f, 10.0f );
1071 TestEndLongPress( application, 50.0f, 10.0f );
1073 DALI_TEST_CHECK( true ); // No crash, test has passed
1074 DALI_TEST_EQUALS(functorCalled, true, TEST_LOCATION);
1078 DALI_TEST_CHECK( false ); // If we crash, the test has failed