2 * Copyright (c) 2021 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.
18 #include <dali-test-suite-utils.h>
19 #include <dali/devel-api/actors/actor-devel.h>
20 #include <dali/devel-api/events/long-press-gesture-detector-devel.h>
21 #include <dali/integration-api/events/touch-event-integ.h>
22 #include <dali/integration-api/input-options.h>
23 #include <dali/integration-api/render-task-list-integ.h>
24 #include <dali/public-api/dali-core.h>
26 #include <test-touch-event-utils.h>
32 void utc_dali_long_press_gesture_detector_startup(void)
34 test_return_value = TET_UNDEF;
37 void utc_dali_long_press_gesture_detector_cleanup(void)
39 test_return_value = TET_PASS;
42 ///////////////////////////////////////////////////////////////////////////////
45 // Stores data that is populated in the callback and will be read by the TET cases
49 : functorCalled(false),
50 voidFunctorCalled(false),
58 functorCalled = false;
59 voidFunctorCalled = false;
61 receivedGesture.Reset();
67 bool voidFunctorCalled;
68 LongPressGesture receivedGesture;
72 // Functor that sets the data when called
73 struct GestureReceivedFunctor
75 GestureReceivedFunctor(SignalData& data)
80 void operator()(Actor actor, const LongPressGesture& longPress)
82 signalData.functorCalled = true;
83 signalData.receivedGesture = longPress;
84 signalData.pressedActor = actor;
89 signalData.voidFunctorCalled = true;
92 SignalData& signalData;
95 // Functor that removes the gestured actor from stage
96 struct UnstageActorFunctor : public GestureReceivedFunctor
98 UnstageActorFunctor(SignalData& data, GestureState& stateToUnstage, Integration::Scene scene)
99 : GestureReceivedFunctor(data),
100 stateToUnstage(stateToUnstage),
105 void operator()(Actor actor, const LongPressGesture& longPress)
107 GestureReceivedFunctor::operator()(actor, longPress);
109 if(longPress.GetState() == stateToUnstage)
115 GestureState& stateToUnstage;
116 Integration::Scene scene;
119 // Functor for receiving a touch event
120 struct TouchEventFunctor
122 bool operator()(Actor actor, Dali::TouchEvent touch)
125 unsigned int points = touch.GetPointCount();
128 tet_printf("Touch Point state = %d\n", touch.GetState(0));
136 ///////////////////////////////////////////////////////////////////////////////
138 // Positive test case for a method
139 int UtcDaliLongPressGestureDetectorConstructorP(void)
141 TestApplication application;
143 LongPressGestureDetector detector;
144 DALI_TEST_CHECK(!detector);
148 int UtcDaliLongPressGestureDetectorCopyConstructorP(void)
150 TestApplication application;
152 LongPressGestureDetector detector = LongPressGestureDetector::New();
155 LongPressGestureDetector copy(detector);
156 DALI_TEST_CHECK(detector);
160 int UtcDaliLongPressGestureDetectorAssignmentOperatorP(void)
162 TestApplication application;
164 LongPressGestureDetector detector;
165 detector = LongPressGestureDetector::New();
168 LongPressGestureDetector copy;
170 DALI_TEST_CHECK(detector);
172 DALI_TEST_CHECK(detector == copy);
176 int UtcDaliLongPressGestureDetectorNew(void)
178 TestApplication application;
180 LongPressGestureDetector detector = LongPressGestureDetector::New();
181 DALI_TEST_CHECK(detector);
182 DALI_TEST_EQUALS(1u, detector.GetMinimumTouchesRequired(), TEST_LOCATION);
183 DALI_TEST_EQUALS(1u, detector.GetMaximumTouchesRequired(), TEST_LOCATION);
185 LongPressGestureDetector detector2 = LongPressGestureDetector::New(5u);
186 DALI_TEST_CHECK(detector2);
187 DALI_TEST_EQUALS(5u, detector2.GetMinimumTouchesRequired(), TEST_LOCATION);
188 DALI_TEST_EQUALS(5u, detector2.GetMaximumTouchesRequired(), TEST_LOCATION);
190 LongPressGestureDetector detector3 = LongPressGestureDetector::New(5u, 7u);
191 DALI_TEST_CHECK(detector2);
192 DALI_TEST_EQUALS(5u, detector3.GetMinimumTouchesRequired(), TEST_LOCATION);
193 DALI_TEST_EQUALS(7u, detector3.GetMaximumTouchesRequired(), TEST_LOCATION);
195 //Scoped test to test destructor
197 LongPressGestureDetector detector4 = LongPressGestureDetector::New();
198 DALI_TEST_CHECK(detector4);
201 // Attach an actor and emit a touch event on the actor to ensure complete line coverage
202 Actor actor = Actor::New();
203 actor.SetProperty(Actor::Property::SIZE, Vector2(100.0f, 100.0f));
204 actor.SetProperty(Actor::Property::ANCHOR_POINT, AnchorPoint::TOP_LEFT);
205 application.GetScene().Add(actor);
208 application.SendNotification();
209 application.Render();
211 detector.Attach(actor);
213 TouchEventFunctor touchFunctor;
214 actor.TouchedSignal().Connect(&application, touchFunctor);
216 Integration::TouchEvent touchEvent(1);
217 Integration::Point point;
218 point.SetDeviceId(1);
219 point.SetState(PointState::DOWN);
220 point.SetScreenPosition(Vector2(20.0f, 20.0f));
221 touchEvent.AddPoint(point);
222 application.ProcessEvent(touchEvent);
225 application.SendNotification();
226 application.Render();
231 int UtcDaliLongPressGestureDetectorDownCast(void)
233 TestApplication application;
234 tet_infoline("Testing Dali::LongPressGestureDetector::DownCast()");
236 LongPressGestureDetector detector = LongPressGestureDetector::New();
238 BaseHandle object(detector);
240 LongPressGestureDetector detector2 = LongPressGestureDetector::DownCast(object);
241 DALI_TEST_CHECK(detector2);
243 LongPressGestureDetector detector3 = DownCast<LongPressGestureDetector>(object);
244 DALI_TEST_CHECK(detector3);
246 BaseHandle unInitializedObject;
247 LongPressGestureDetector detector4 = LongPressGestureDetector::DownCast(unInitializedObject);
248 DALI_TEST_CHECK(!detector4);
250 LongPressGestureDetector detector5 = DownCast<LongPressGestureDetector>(unInitializedObject);
251 DALI_TEST_CHECK(!detector5);
253 GestureDetector detector6 = LongPressGestureDetector::New();
254 LongPressGestureDetector detector7 = LongPressGestureDetector::DownCast(detector6);
255 DALI_TEST_CHECK(detector7);
259 int UtcDaliLongPressGestureGetMinimumTouchesRequired(void)
261 TestApplication application;
263 LongPressGestureDetector detector = LongPressGestureDetector::New();
264 DALI_TEST_EQUALS(1u, detector.GetMinimumTouchesRequired(), TEST_LOCATION);
268 int UtcDaliLongPressGestureGetMaximumTouchesRequired(void)
270 TestApplication application;
272 LongPressGestureDetector detector = LongPressGestureDetector::New();
273 DALI_TEST_EQUALS(1u, detector.GetMaximumTouchesRequired(), TEST_LOCATION);
277 int UtcDaliLongPressGestureSignalReceptionNegative(void)
279 TestApplication application;
281 Actor actor = Actor::New();
282 actor.SetProperty(Actor::Property::SIZE, Vector2(100.0f, 100.0f));
283 actor.SetProperty(Actor::Property::ANCHOR_POINT, AnchorPoint::TOP_LEFT);
284 application.GetScene().Add(actor);
287 application.SendNotification();
288 application.Render();
291 GestureReceivedFunctor functor(data);
293 LongPressGestureDetector detector = LongPressGestureDetector::New();
294 detector.Attach(actor);
295 detector.DetectedSignal().Connect(&application, functor);
297 // Do a long press outside actor's area
298 TestGenerateLongPress(application, 112.0f, 112.0f);
299 TestEndLongPress(application, 112.0f, 112.0f);
301 DALI_TEST_EQUALS(false, data.functorCalled, TEST_LOCATION);
305 int UtcDaliLongPressGestureSignalReceptionPositive(void)
307 TestApplication application;
309 Actor actor = Actor::New();
310 actor.SetProperty(Actor::Property::SIZE, Vector2(100.0f, 100.0f));
311 actor.SetProperty(Actor::Property::ANCHOR_POINT, AnchorPoint::TOP_LEFT);
312 application.GetScene().Add(actor);
315 application.SendNotification();
316 application.Render();
319 GestureReceivedFunctor functor(data);
321 LongPressGestureDetector detector = LongPressGestureDetector::New();
322 detector.Attach(actor);
323 detector.DetectedSignal().Connect(&application, functor);
325 // Do a long press inside actor's area
326 TestGenerateLongPress(application, 50.0f, 50.0f);
327 DALI_TEST_EQUALS(true, data.functorCalled, TEST_LOCATION);
328 DALI_TEST_EQUALS(1u, data.receivedGesture.GetNumberOfTouches(), TEST_LOCATION);
329 DALI_TEST_EQUALS(Vector2(50.0f, 50.0f), data.receivedGesture.GetLocalPoint(), 0.1, TEST_LOCATION);
330 TestEndLongPress(application, 50.0f, 50.0f);
334 int UtcDaliLongPressGestureSignalReceptionDetach(void)
336 TestApplication application;
338 Actor actor = Actor::New();
339 actor.SetProperty(Actor::Property::SIZE, Vector2(100.0f, 100.0f));
340 actor.SetProperty(Actor::Property::ANCHOR_POINT, AnchorPoint::TOP_LEFT);
341 application.GetScene().Add(actor);
344 application.SendNotification();
345 application.Render();
348 GestureReceivedFunctor functor(data);
350 LongPressGestureDetector detector = LongPressGestureDetector::New();
351 detector.Attach(actor);
352 detector.DetectedSignal().Connect(&application, functor);
354 // Start long press within the actor's area
355 TestGenerateLongPress(application, 20.0f, 20.0f);
356 DALI_TEST_EQUALS(true, data.functorCalled, TEST_LOCATION);
357 DALI_TEST_EQUALS(1u, data.receivedGesture.GetNumberOfTouches(), TEST_LOCATION);
358 DALI_TEST_EQUALS(Vector2(20.0f, 20.0f), data.receivedGesture.GetLocalPoint(), 0.1, TEST_LOCATION);
359 TestEndLongPress(application, 20.0f, 20.0f);
361 // repeat the long press within the actor's area - we should still receive the signal
363 TestGenerateLongPress(application, 50.0f, 50.0f);
364 DALI_TEST_EQUALS(true, data.functorCalled, TEST_LOCATION);
365 DALI_TEST_EQUALS(1u, data.receivedGesture.GetNumberOfTouches(), TEST_LOCATION);
366 DALI_TEST_EQUALS(Vector2(50.0f, 50.0f), data.receivedGesture.GetLocalPoint(), 0.1, TEST_LOCATION);
367 TestEndLongPress(application, 50.0f, 50.0f);
370 detector.DetachAll();
372 // Ensure we are no longer signalled
374 TestGenerateLongPress(application, 20.0f, 20.0f);
375 DALI_TEST_EQUALS(false, data.functorCalled, TEST_LOCATION);
376 TestEndLongPress(application, 50.0f, 50.0f);
377 DALI_TEST_EQUALS(false, data.functorCalled, TEST_LOCATION);
381 int UtcDaliLongPressGestureSignalReceptionActorDestroyedDuringLongPress(void)
383 TestApplication application;
386 GestureReceivedFunctor functor(data);
388 LongPressGestureDetector detector = LongPressGestureDetector::New();
389 detector.DetectedSignal().Connect(&application, functor);
391 // Actor lifetime is scoped
393 Actor actor = Actor::New();
394 actor.SetProperty(Actor::Property::SIZE, Vector2(100.0f, 100.0f));
395 actor.SetProperty(Actor::Property::ANCHOR_POINT, AnchorPoint::TOP_LEFT);
396 application.GetScene().Add(actor);
399 application.SendNotification();
400 application.Render();
402 detector.Attach(actor);
404 // Start long press within the actor's area
405 TestGenerateLongPress(application, 20.0f, 20.0f);
406 DALI_TEST_EQUALS(true, data.functorCalled, TEST_LOCATION);
408 // Remove the actor from stage and reset the data
409 application.GetScene().Remove(actor);
412 application.SendNotification();
413 application.Render();
416 // Actor should now have been destroyed
419 TestEndLongPress(application, 20.0f, 20.0f);
420 DALI_TEST_EQUALS(false, data.functorCalled, TEST_LOCATION);
424 int UtcDaliLongPressGestureSignalReceptionRotatedActor(void)
426 TestApplication application;
428 Actor actor = Actor::New();
429 actor.SetProperty(Actor::Property::SIZE, Vector2(100.0f, 100.0f));
430 actor.SetProperty(Actor::Property::ORIENTATION, Quaternion(Dali::Degree(90.0f), Vector3::ZAXIS));
431 application.GetScene().Add(actor);
434 application.SendNotification();
435 application.Render();
438 GestureReceivedFunctor functor(data);
440 LongPressGestureDetector detector = LongPressGestureDetector::New();
441 detector.Attach(actor);
442 detector.DetectedSignal().Connect(&application, functor);
445 TestGenerateLongPress(application, 5.0f, 5.0f);
446 TestEndLongPress(application, 5.0f, 5.0f);
447 DALI_TEST_EQUALS(true, data.functorCalled, TEST_LOCATION);
448 DALI_TEST_EQUALS(1u, data.receivedGesture.GetNumberOfTouches(), TEST_LOCATION);
449 DALI_TEST_EQUALS(Vector2(5.0f, 5.0f), data.receivedGesture.GetScreenPoint(), 0.1, TEST_LOCATION);
451 // Rotate actor again and render
452 actor.SetProperty(Actor::Property::ORIENTATION, Quaternion(Dali::Degree(180.0f), Vector3::ZAXIS));
453 application.SendNotification();
454 application.Render();
456 // Do another long press, should still receive event
458 TestGenerateLongPress(application, 5.0f, 5.0f);
459 TestEndLongPress(application, 5.0f, 5.0f);
460 DALI_TEST_EQUALS(true, data.functorCalled, TEST_LOCATION);
461 DALI_TEST_EQUALS(1u, data.receivedGesture.GetNumberOfTouches(), TEST_LOCATION);
462 DALI_TEST_EQUALS(Vector2(5.0f, 5.0f), data.receivedGesture.GetScreenPoint(), 0.1, TEST_LOCATION);
464 // Rotate actor again and render
465 actor.SetProperty(Actor::Property::ORIENTATION, Quaternion(Dali::Degree(90.0f), Vector3::YAXIS));
466 application.SendNotification();
467 application.Render();
469 // Do a long press, inside where the actor used to be, Should not receive the event
471 TestGenerateLongPress(application, 70.0f, 70.0f);
472 TestEndLongPress(application, 70.0f, 70.0f);
473 DALI_TEST_EQUALS(false, data.functorCalled, TEST_LOCATION);
477 int UtcDaliLongPressGestureSignalReceptionChildHit(void)
479 TestApplication application;
481 Actor parent = Actor::New();
482 parent.SetProperty(Actor::Property::SIZE, Vector2(100.0f, 100.0f));
483 parent.SetProperty(Actor::Property::ANCHOR_POINT, AnchorPoint::TOP_LEFT);
484 application.GetScene().Add(parent);
486 // Set child to completely cover parent.
487 // Change rotation of child to be different from parent so that we can check if our local coordinate
488 // conversion of the parent actor is correct.
489 Actor child = Actor::New();
490 child.SetProperty(Actor::Property::SIZE, Vector2(100.0f, 100.0f));
491 child.SetProperty(Actor::Property::ANCHOR_POINT, AnchorPoint::CENTER);
492 child.SetProperty(Actor::Property::PARENT_ORIGIN, ParentOrigin::CENTER);
493 child.SetProperty(Actor::Property::ORIENTATION, Quaternion(Dali::Degree(90.0f), Vector3::ZAXIS));
497 application.SendNotification();
498 application.Render();
501 GestureReceivedFunctor functor(data);
503 LongPressGestureDetector detector = LongPressGestureDetector::New();
504 detector.Attach(parent);
505 detector.DetectedSignal().Connect(&application, functor);
507 // Do long press - hits child area but parent should still receive it
508 TestGenerateLongPress(application, 50.0f, 50.0f);
509 TestEndLongPress(application, 50.0f, 50.0f);
510 DALI_TEST_EQUALS(true, data.functorCalled, TEST_LOCATION);
511 DALI_TEST_EQUALS(true, parent == data.pressedActor, TEST_LOCATION);
512 DALI_TEST_EQUALS(Vector2(50.0f, 50.0f), data.receivedGesture.GetScreenPoint(), 0.01f, TEST_LOCATION);
514 // Attach child and generate same touch points
515 // (Also proves that you can detach and then re-attach another actor)
516 detector.Attach(child);
517 detector.Detach(parent);
519 // Do an entire long press, only check finished value
521 TestGenerateLongPress(application, 51.0f, 51.0f);
522 TestEndLongPress(application, 51.0f, 51.0f);
523 DALI_TEST_EQUALS(true, data.functorCalled, TEST_LOCATION);
524 DALI_TEST_EQUALS(true, child == data.pressedActor, TEST_LOCATION);
525 DALI_TEST_EQUALS(Vector2(51.0f, 51.0f), data.receivedGesture.GetScreenPoint(), 0.01f, TEST_LOCATION);
529 int UtcDaliLongPressGestureSignalReceptionAttachDetachMany(void)
531 TestApplication application;
533 Actor first = Actor::New();
534 first.SetProperty(Actor::Property::SIZE, Vector2(100.0f, 100.0f));
535 first.SetProperty(Actor::Property::ANCHOR_POINT, AnchorPoint::TOP_LEFT);
536 application.GetScene().Add(first);
538 Actor second = Actor::New();
539 second.SetProperty(Actor::Property::SIZE, Vector2(100.0f, 100.0f));
540 second.SetProperty(Actor::Property::POSITION_X, 100.0f);
541 second.SetProperty(Actor::Property::ANCHOR_POINT, AnchorPoint::TOP_LEFT);
542 application.GetScene().Add(second);
545 application.SendNotification();
546 application.Render();
549 GestureReceivedFunctor functor(data);
551 LongPressGestureDetector detector = LongPressGestureDetector::New();
552 detector.Attach(first);
553 detector.Attach(second);
554 detector.DetectedSignal().Connect(&application, functor);
556 // LongPress within second actor's area
557 TestGenerateLongPress(application, 120.0f, 10.0f);
558 TestEndLongPress(application, 120.0f, 10.0f);
559 DALI_TEST_EQUALS(true, data.functorCalled, TEST_LOCATION);
560 DALI_TEST_EQUALS(true, second == data.pressedActor, TEST_LOCATION);
562 // LongPress within first actor's area
564 TestGenerateLongPress(application, 20.0f, 10.0f);
565 TestEndLongPress(application, 20.0f, 10.0f);
566 DALI_TEST_EQUALS(true, data.functorCalled, TEST_LOCATION);
567 DALI_TEST_EQUALS(true, first == data.pressedActor, TEST_LOCATION);
569 // Detach the second actor
570 detector.Detach(second);
572 // second actor shouldn't receive event
574 TestGenerateLongPress(application, 120.0f, 10.0f);
575 TestEndLongPress(application, 120.0f, 10.0f);
576 DALI_TEST_EQUALS(false, data.functorCalled, TEST_LOCATION);
578 // first actor should continue receiving event
580 TestGenerateLongPress(application, 20.0f, 10.0f);
581 TestEndLongPress(application, 20.0f, 10.0f);
582 DALI_TEST_EQUALS(true, data.functorCalled, TEST_LOCATION);
586 int UtcDaliLongPressGestureSignalReceptionActorBecomesUntouchable(void)
588 TestApplication application;
590 Actor actor = Actor::New();
591 actor.SetProperty(Actor::Property::SIZE, Vector2(100.0f, 100.0f));
592 actor.SetProperty(Actor::Property::ANCHOR_POINT, AnchorPoint::TOP_LEFT);
593 application.GetScene().Add(actor);
596 application.SendNotification();
597 application.Render();
600 GestureReceivedFunctor functor(data);
602 LongPressGestureDetector detector = LongPressGestureDetector::New();
603 detector.Attach(actor);
604 detector.DetectedSignal().Connect(&application, functor);
606 // LongPress in actor's area
607 TestGenerateLongPress(application, 50.0f, 10.0f);
608 TestEndLongPress(application, 50.0f, 10.0f);
609 DALI_TEST_EQUALS(true, data.functorCalled, TEST_LOCATION);
611 // Actor becomes invisible - actor should not receive the next long press
612 actor.SetProperty(Actor::Property::VISIBLE, false);
615 application.SendNotification();
616 application.Render();
618 // LongPress in the same area, shouldn't receive event
620 TestGenerateLongPress(application, 50.0f, 10.0f);
621 TestEndLongPress(application, 50.0f, 10.0f);
622 DALI_TEST_EQUALS(false, data.functorCalled, TEST_LOCATION);
626 int UtcDaliLongPressGestureSignalReceptionMultipleDetectorsOnActor(void)
628 TestApplication application;
630 Actor actor = Actor::New();
631 actor.SetProperty(Actor::Property::SIZE, Vector2(100.0f, 100.0f));
632 actor.SetProperty(Actor::Property::ANCHOR_POINT, AnchorPoint::TOP_LEFT);
633 application.GetScene().Add(actor);
636 application.SendNotification();
637 application.Render();
639 // Attach actor to one detector
640 SignalData firstData;
641 GestureReceivedFunctor firstFunctor(firstData);
642 LongPressGestureDetector firstDetector = LongPressGestureDetector::New();
643 firstDetector.Attach(actor);
644 firstDetector.DetectedSignal().Connect(&application, firstFunctor);
646 // Attach actor to another detector
647 SignalData secondData;
648 GestureReceivedFunctor secondFunctor(secondData);
649 LongPressGestureDetector secondDetector = LongPressGestureDetector::New();
650 secondDetector.Attach(actor);
651 secondDetector.DetectedSignal().Connect(&application, secondFunctor);
653 // LongPress in actor's area - both detector's functors should be called
654 TestGenerateLongPress(application, 50.0f, 10.0f);
655 DALI_TEST_EQUALS(true, firstData.functorCalled, TEST_LOCATION);
656 DALI_TEST_EQUALS(true, secondData.functorCalled, TEST_LOCATION);
660 int UtcDaliLongPressGestureSignalReceptionDifferentPossible(void)
662 TestApplication application;
664 Actor actor = Actor::New();
665 actor.SetProperty(Actor::Property::SIZE, Vector2(100.0f, 100.0f));
666 actor.SetProperty(Actor::Property::ANCHOR_POINT, AnchorPoint::TOP_LEFT);
667 application.GetScene().Add(actor);
670 application.SendNotification();
671 application.Render();
673 // Attach actor to detector
675 GestureReceivedFunctor functor(data);
676 LongPressGestureDetector detector = LongPressGestureDetector::New();
677 detector.Attach(actor);
678 detector.DetectedSignal().Connect(&application, functor);
680 // LongPress possible in actor's area.
681 TestStartLongPress(application, 50.0f, 10.0f);
682 DALI_TEST_EQUALS(false, data.functorCalled, TEST_LOCATION);
684 // Move actor somewhere else
685 actor.SetProperty(Actor::Property::POSITION, Vector2(100.0f, 100.0f));
688 application.SendNotification();
689 application.Render();
691 // Emit Started event, we should not receive the long press.
692 TestTriggerLongPress(application);
693 TestGenerateLongPress(application, 50.0f, 10.0f);
694 DALI_TEST_EQUALS(false, data.functorCalled, TEST_LOCATION);
696 // LongPress possible in empty area.
697 TestStartLongPress(application, 50.0f, 10.0f);
698 DALI_TEST_EQUALS(false, data.functorCalled, TEST_LOCATION);
700 // Move actor in to the long press position.
701 actor.SetProperty(Actor::Property::POSITION, Vector2(0.0f, 0.0f));
704 application.SendNotification();
705 application.Render();
707 // Emit STARTED event, we should not receive the long press.
708 TestTriggerLongPress(application);
709 TestEndLongPress(application, 50.0f, 10.0f);
710 DALI_TEST_EQUALS(false, data.functorCalled, TEST_LOCATION);
712 // Normal long press in actor's area for completeness.
713 TestGenerateLongPress(application, 50.0f, 10.0f);
714 TestEndLongPress(application, 50.0f, 10.0f);
715 DALI_TEST_EQUALS(true, data.functorCalled, TEST_LOCATION);
719 int UtcDaliLongPressGesturePossibleCancelled(void)
721 TestApplication application;
723 Actor actor = Actor::New();
724 actor.SetProperty(Actor::Property::SIZE, Vector2(100.0f, 100.0f));
725 actor.SetProperty(Actor::Property::ANCHOR_POINT, AnchorPoint::TOP_LEFT);
726 application.GetScene().Add(actor);
729 application.SendNotification();
730 application.Render();
732 // Attach actor to detector
734 GestureReceivedFunctor functor(data);
735 LongPressGestureDetector detector = LongPressGestureDetector::New();
736 detector.Attach(actor);
737 detector.DetectedSignal().Connect(&application, functor);
739 // Send a possible followed by a cancel, we should not be signalled
740 TestStartLongPress(application, 50.0f, 10.0f);
741 DALI_TEST_EQUALS(false, data.functorCalled, TEST_LOCATION);
742 TestMovePan(application, Vector2(50.0f, 10.0f));
743 DALI_TEST_EQUALS(false, data.functorCalled, TEST_LOCATION);
747 int UtcDaliLongPressGestureDetachAfterStarted(void)
749 TestApplication application;
751 Actor actor = Actor::New();
752 actor.SetProperty(Actor::Property::SIZE, Vector2(100.0f, 100.0f));
753 actor.SetProperty(Actor::Property::ANCHOR_POINT, AnchorPoint::TOP_LEFT);
754 application.GetScene().Add(actor);
757 application.SendNotification();
758 application.Render();
760 // Attach actor to detector
762 GestureReceivedFunctor functor(data);
763 LongPressGestureDetector detector = LongPressGestureDetector::New();
764 detector.Attach(actor);
765 detector.DetectedSignal().Connect(&application, functor);
767 // Emit initial signal
768 TestGenerateLongPress(application, 50.0f, 10.0f);
769 DALI_TEST_EQUALS(true, data.functorCalled, TEST_LOCATION);
773 detector.Detach(actor);
775 // Emit FINISHED, no signal
776 TestEndLongPress(application, 50.0f, 10.0f);
777 DALI_TEST_EQUALS(false, data.functorCalled, TEST_LOCATION);
781 int UtcDaliLongPressGestureActorUnstaged(void)
783 TestApplication application;
785 Actor actor = Actor::New();
786 actor.SetProperty(Actor::Property::SIZE, Vector2(100.0f, 100.0f));
787 actor.SetProperty(Actor::Property::ANCHOR_POINT, AnchorPoint::TOP_LEFT);
788 application.GetScene().Add(actor);
791 application.SendNotification();
792 application.Render();
794 // State to remove actor in.
795 GestureState stateToUnstage(GestureState::STARTED);
797 // Attach actor to detector
799 UnstageActorFunctor functor(data, stateToUnstage, application.GetScene());
800 LongPressGestureDetector detector = LongPressGestureDetector::New();
801 detector.Attach(actor);
802 detector.DetectedSignal().Connect(&application, functor);
805 TestGenerateLongPress(application, 50.0f, 10.0f);
806 DALI_TEST_EQUALS(true, data.functorCalled, TEST_LOCATION);
808 TestEndLongPress(application, 50.0f, 10.0f);
809 DALI_TEST_EQUALS(false, data.functorCalled, TEST_LOCATION);
812 application.SendNotification();
813 application.Render();
815 // Re-add actor to stage
816 application.GetScene().Add(actor);
819 application.SendNotification();
820 application.Render();
822 // Change state to GestureState::CONTINUING to remove
823 stateToUnstage = GestureState::FINISHED;
826 TestGenerateLongPress(application, 50.0f, 10.0f);
827 DALI_TEST_EQUALS(true, data.functorCalled, TEST_LOCATION);
829 TestEndLongPress(application, 50.0f, 10.0f);
830 DALI_TEST_EQUALS(true, data.functorCalled, TEST_LOCATION);
831 tet_result(TET_PASS); // If we get here then we have handled actor stage removal gracefully.
835 int UtcDaliLongPressGestureActorStagedAndDestroyed(void)
837 TestApplication application;
839 Actor actor = Actor::New();
840 actor.SetProperty(Actor::Property::SIZE, Vector2(100.0f, 100.0f));
841 actor.SetProperty(Actor::Property::ANCHOR_POINT, AnchorPoint::TOP_LEFT);
842 application.GetScene().Add(actor);
844 // Create and add a second actor so that GestureDetector destruction does not come into play.
845 Actor dummyActor(Actor::New());
846 dummyActor.SetProperty(Actor::Property::SIZE, Vector2(100.0f, 100.0f));
847 dummyActor.SetProperty(Actor::Property::POSITION, Vector2(100.0f, 100.0f));
848 dummyActor.SetProperty(Actor::Property::ANCHOR_POINT, AnchorPoint::TOP_LEFT);
849 application.GetScene().Add(dummyActor);
852 application.SendNotification();
853 application.Render();
855 // State to remove actor in.
856 GestureState stateToUnstage(GestureState::STARTED);
858 // Attach actor to detector
860 UnstageActorFunctor functor(data, stateToUnstage, application.GetScene());
861 LongPressGestureDetector detector = LongPressGestureDetector::New();
862 detector.Attach(actor);
863 detector.Attach(dummyActor);
864 detector.DetectedSignal().Connect(&application, functor);
866 // Here we are testing a STARTED actor which is removed in the STARTED callback, but then added back
867 // before we get a finished state. As we were removed from the stage, even if we're at the same
868 // position, we should still not be signalled.
871 TestGenerateLongPress(application, 50.0f, 10.0f);
872 DALI_TEST_EQUALS(true, data.functorCalled, TEST_LOCATION);
876 application.SendNotification();
877 application.Render();
879 // Re add to the stage, we should not be signalled
880 application.GetScene().Add(actor);
883 application.SendNotification();
884 application.Render();
886 // Continue signal emission
887 TestEndLongPress(application, 50.0f, 10.0f);
888 DALI_TEST_EQUALS(false, data.functorCalled, TEST_LOCATION);
891 // Here we delete an actor in started, we should not receive any subsequent signalling.
894 TestGenerateLongPress(application, 50.0f, 10.0f);
895 DALI_TEST_EQUALS(true, data.functorCalled, TEST_LOCATION);
899 application.SendNotification();
900 application.Render();
902 // Delete actor as well
906 application.SendNotification();
907 application.Render();
909 // Continue signal emission
910 TestEndLongPress(application, 50.0f, 10.0f);
911 DALI_TEST_EQUALS(false, data.functorCalled, TEST_LOCATION);
915 int UtcDaliLongPressGestureLayerConsumesTouch(void)
917 TestApplication application;
919 Actor actor = Actor::New();
920 actor.SetProperty(Actor::Property::SIZE, Vector2(100.0f, 100.0f));
921 actor.SetProperty(Actor::Property::ANCHOR_POINT, AnchorPoint::TOP_LEFT);
922 application.GetScene().Add(actor);
926 GestureReceivedFunctor functor(data);
927 LongPressGestureDetector detector = LongPressGestureDetector::New();
928 detector.Attach(actor);
929 detector.DetectedSignal().Connect(&application, functor);
931 // Add a layer to overlap the actor
932 Layer layer = Layer::New();
933 layer.SetProperty(Actor::Property::SIZE, Vector2(100.0f, 100.0f));
934 layer.SetProperty(Actor::Property::ANCHOR_POINT, AnchorPoint::TOP_LEFT);
935 application.GetScene().Add(layer);
939 application.SendNotification();
940 application.Render();
942 // Emit signals, should receive
943 TestGenerateLongPress(application, 50.0f, 50.0f);
944 TestEndLongPress(application, 50.0f, 50.0f);
945 DALI_TEST_EQUALS(true, data.functorCalled, TEST_LOCATION);
948 // Set layer to consume all touch
949 layer.SetProperty(Layer::Property::CONSUMES_TOUCH, true);
952 application.SendNotification();
953 application.Render();
955 // Emit the same signals again, should not receive
956 TestGenerateLongPress(application, 50.0f, 50.0f);
957 TestEndLongPress(application, 50.0f, 50.0f);
958 DALI_TEST_EQUALS(false, data.functorCalled, TEST_LOCATION);
964 int UtcDaliLongPressGestureSetMinimumHoldingTime(void)
966 TestApplication application;
968 const uint32_t kMinumumHolding1 = 5000;
969 const uint32_t kMinumumHolding2 = 3000;
971 Integration::SetLongPressMinimumHoldingTime(kMinumumHolding1);
973 Actor actor = Actor::New();
974 actor.SetProperty(Actor::Property::SIZE, Vector2(100.0f, 100.0f));
975 actor.SetProperty(Actor::Property::ANCHOR_POINT, AnchorPoint::TOP_LEFT);
976 application.GetScene().Add(actor);
979 application.SendNotification();
980 application.Render();
983 GestureReceivedFunctor functor(data);
985 LongPressGestureDetector detector = LongPressGestureDetector::New();
986 detector.Attach(actor);
987 detector.DetectedSignal().Connect(&application, functor);
989 DALI_TEST_EQUALS(DevelLongPressGestureDetector::GetMinimumHoldingTime(detector), kMinumumHolding1, TEST_LOCATION);
991 Integration::SetLongPressMinimumHoldingTime(kMinumumHolding2);
992 DALI_TEST_EQUALS(DevelLongPressGestureDetector::GetMinimumHoldingTime(detector), kMinumumHolding2, TEST_LOCATION);
997 int UtcDaliLongPressGestureDisableDetectionDuringLongPressN(void)
999 // Crash occurred when gesture-recognizer was deleted internally during a signal when the attached actor was detached
1001 TestApplication application;
1003 Actor actor = Actor::New();
1004 actor.SetProperty(Actor::Property::SIZE, Vector2(100.0f, 100.0f));
1005 actor.SetProperty(Actor::Property::ANCHOR_POINT, AnchorPoint::TOP_LEFT);
1006 application.GetScene().Add(actor);
1009 LongPressGestureDetector detector = LongPressGestureDetector::New();
1010 bool functorCalled = false;
1011 detector.Attach(actor);
1012 detector.DetectedSignal().Connect(
1014 [&detector, &functorCalled](Actor actor, const LongPressGesture& gesture) {
1015 if(gesture.GetState() == GestureState::FINISHED)
1017 detector.Detach(actor);
1018 functorCalled = true;
1022 // Render and notify
1023 application.SendNotification();
1024 application.Render();
1026 // Try the gesture, should not crash
1029 TestGenerateLongPress(application, 50.0f, 10.0f);
1030 TestEndLongPress(application, 50.0f, 10.0f);
1032 DALI_TEST_CHECK(true); // No crash, test has passed
1033 DALI_TEST_EQUALS(functorCalled, true, TEST_LOCATION);
1037 DALI_TEST_CHECK(false); // If we crash, the test has failed
1043 int UtcDaliLongPressGestureWhenGesturePropargation(void)
1045 TestApplication application;
1047 Actor parentActor = Actor::New();
1048 parentActor.SetProperty(Actor::Property::SIZE, Vector2(100.0f, 100.0f));
1049 parentActor.SetProperty(Actor::Property::ANCHOR_POINT, AnchorPoint::TOP_LEFT);
1051 Actor childActor = Actor::New();
1052 childActor.SetProperty(Actor::Property::SIZE, Vector2(100.0f, 100.0f));
1053 childActor.SetProperty(Actor::Property::ANCHOR_POINT, AnchorPoint::TOP_LEFT);
1055 parentActor.Add(childActor);
1056 application.GetScene().Add(parentActor);
1058 // Render and notify
1059 application.SendNotification();
1060 application.Render();
1063 GestureReceivedFunctor pFunctor(pData);
1065 LongPressGestureDetector parentDetector = LongPressGestureDetector::New();
1066 parentDetector.Attach(parentActor);
1067 parentDetector.DetectedSignal().Connect(&application, pFunctor);
1070 GestureReceivedFunctor cFunctor(cData);
1072 LongPressGestureDetector childDetector = LongPressGestureDetector::New();
1073 childDetector.Attach(childActor);
1074 childDetector.DetectedSignal().Connect(&application, cFunctor);
1076 // Start gesture within the actor's area, we receive the gesture not parent actor but child actor.
1077 TestGenerateLongPress(application, 50.0f, 50.0f);
1078 TestEndLongPress(application, 50.0f, 50.0f);
1080 DALI_TEST_EQUALS(true, cData.functorCalled, TEST_LOCATION);
1081 DALI_TEST_EQUALS(false, pData.functorCalled, TEST_LOCATION);
1085 // If GesturePropargation is set, a gesture event is to pass over to the parent.
1086 Dali::DevelActor::SetNeedGesturePropagation(childActor, true);
1088 // So now the parent got the gesture event.
1089 TestGenerateLongPress(application, 50.0f, 50.0f);
1090 TestEndLongPress(application, 50.0f, 50.0f);
1091 DALI_TEST_EQUALS(true, cData.functorCalled, TEST_LOCATION);
1092 DALI_TEST_EQUALS(true, pData.functorCalled, TEST_LOCATION);