2 * Copyright (c) 2022 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();
154 LongPressGestureDetector copy(detector);
155 DALI_TEST_CHECK(detector);
159 int UtcDaliLongPressGestureDetectorAssignmentOperatorP(void)
161 TestApplication application;
163 LongPressGestureDetector detector;
164 detector = LongPressGestureDetector::New();
166 LongPressGestureDetector copy;
168 DALI_TEST_CHECK(detector);
170 DALI_TEST_CHECK(detector == copy);
174 int UtcDaliLongPressGestureDetectorMoveConstructorP(void)
176 TestApplication application;
178 LongPressGestureDetector detector = LongPressGestureDetector::New();
179 DALI_TEST_CHECK(detector);
181 LongPressGestureDetector moved = std::move(detector);
182 DALI_TEST_CHECK(moved);
183 DALI_TEST_CHECK(!detector);
187 int UtcDaliLongPressGestureDetectorMoveAssignmentOperatorP(void)
189 TestApplication application;
191 LongPressGestureDetector detector;
192 detector = LongPressGestureDetector::New();
193 DALI_TEST_CHECK(detector);
195 LongPressGestureDetector moved;
196 moved = std::move(detector);
197 DALI_TEST_CHECK(moved);
198 DALI_TEST_CHECK(!detector);
202 int UtcDaliLongPressGestureDetectorNew(void)
204 TestApplication application;
206 LongPressGestureDetector detector = LongPressGestureDetector::New();
207 DALI_TEST_CHECK(detector);
208 DALI_TEST_EQUALS(1u, detector.GetMinimumTouchesRequired(), TEST_LOCATION);
209 DALI_TEST_EQUALS(1u, detector.GetMaximumTouchesRequired(), TEST_LOCATION);
211 LongPressGestureDetector detector2 = LongPressGestureDetector::New(5u);
212 DALI_TEST_CHECK(detector2);
213 DALI_TEST_EQUALS(5u, detector2.GetMinimumTouchesRequired(), TEST_LOCATION);
214 DALI_TEST_EQUALS(5u, detector2.GetMaximumTouchesRequired(), TEST_LOCATION);
216 LongPressGestureDetector detector3 = LongPressGestureDetector::New(5u, 7u);
217 DALI_TEST_CHECK(detector2);
218 DALI_TEST_EQUALS(5u, detector3.GetMinimumTouchesRequired(), TEST_LOCATION);
219 DALI_TEST_EQUALS(7u, detector3.GetMaximumTouchesRequired(), TEST_LOCATION);
221 //Scoped test to test destructor
223 LongPressGestureDetector detector4 = LongPressGestureDetector::New();
224 DALI_TEST_CHECK(detector4);
227 // Attach an actor and emit a touch event on the actor to ensure complete line coverage
228 Actor actor = Actor::New();
229 actor.SetProperty(Actor::Property::SIZE, Vector2(100.0f, 100.0f));
230 actor.SetProperty(Actor::Property::ANCHOR_POINT, AnchorPoint::TOP_LEFT);
231 application.GetScene().Add(actor);
234 application.SendNotification();
235 application.Render();
237 detector.Attach(actor);
239 TouchEventFunctor touchFunctor;
240 actor.TouchedSignal().Connect(&application, touchFunctor);
242 Integration::TouchEvent touchEvent(1);
243 Integration::Point point;
244 point.SetDeviceId(1);
245 point.SetState(PointState::DOWN);
246 point.SetScreenPosition(Vector2(20.0f, 20.0f));
247 touchEvent.AddPoint(point);
248 application.ProcessEvent(touchEvent);
251 application.SendNotification();
252 application.Render();
257 int UtcDaliLongPressGestureDetectorDownCast(void)
259 TestApplication application;
260 tet_infoline("Testing Dali::LongPressGestureDetector::DownCast()");
262 LongPressGestureDetector detector = LongPressGestureDetector::New();
264 BaseHandle object(detector);
266 LongPressGestureDetector detector2 = LongPressGestureDetector::DownCast(object);
267 DALI_TEST_CHECK(detector2);
269 LongPressGestureDetector detector3 = DownCast<LongPressGestureDetector>(object);
270 DALI_TEST_CHECK(detector3);
272 BaseHandle unInitializedObject;
273 LongPressGestureDetector detector4 = LongPressGestureDetector::DownCast(unInitializedObject);
274 DALI_TEST_CHECK(!detector4);
276 LongPressGestureDetector detector5 = DownCast<LongPressGestureDetector>(unInitializedObject);
277 DALI_TEST_CHECK(!detector5);
279 GestureDetector detector6 = LongPressGestureDetector::New();
280 LongPressGestureDetector detector7 = LongPressGestureDetector::DownCast(detector6);
281 DALI_TEST_CHECK(detector7);
285 int UtcDaliLongPressGestureGetMinimumTouchesRequired(void)
287 TestApplication application;
289 LongPressGestureDetector detector = LongPressGestureDetector::New();
290 DALI_TEST_EQUALS(1u, detector.GetMinimumTouchesRequired(), TEST_LOCATION);
294 int UtcDaliLongPressGestureGetMaximumTouchesRequired(void)
296 TestApplication application;
298 LongPressGestureDetector detector = LongPressGestureDetector::New();
299 DALI_TEST_EQUALS(1u, detector.GetMaximumTouchesRequired(), TEST_LOCATION);
303 int UtcDaliLongPressGestureSignalReceptionNegative(void)
305 TestApplication application;
307 Actor actor = Actor::New();
308 actor.SetProperty(Actor::Property::SIZE, Vector2(100.0f, 100.0f));
309 actor.SetProperty(Actor::Property::ANCHOR_POINT, AnchorPoint::TOP_LEFT);
310 application.GetScene().Add(actor);
313 application.SendNotification();
314 application.Render();
317 GestureReceivedFunctor functor(data);
319 LongPressGestureDetector detector = LongPressGestureDetector::New();
320 detector.Attach(actor);
321 detector.DetectedSignal().Connect(&application, functor);
323 // Do a long press outside actor's area
324 TestGenerateLongPress(application, 112.0f, 112.0f);
325 TestEndLongPress(application, 112.0f, 112.0f);
327 DALI_TEST_EQUALS(false, data.functorCalled, TEST_LOCATION);
331 int UtcDaliLongPressGestureSignalReceptionPositive(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 // Do a long press inside actor's area
352 TestGenerateLongPress(application, 50.0f, 50.0f);
353 DALI_TEST_EQUALS(true, data.functorCalled, TEST_LOCATION);
354 DALI_TEST_EQUALS(1u, data.receivedGesture.GetNumberOfTouches(), TEST_LOCATION);
355 DALI_TEST_EQUALS(Vector2(50.0f, 50.0f), data.receivedGesture.GetLocalPoint(), 0.1, TEST_LOCATION);
356 TestEndLongPress(application, 50.0f, 50.0f);
360 int UtcDaliLongPressGestureSignalReceptionDetach(void)
362 TestApplication application;
364 Actor actor = Actor::New();
365 actor.SetProperty(Actor::Property::SIZE, Vector2(100.0f, 100.0f));
366 actor.SetProperty(Actor::Property::ANCHOR_POINT, AnchorPoint::TOP_LEFT);
367 application.GetScene().Add(actor);
370 application.SendNotification();
371 application.Render();
374 GestureReceivedFunctor functor(data);
376 LongPressGestureDetector detector = LongPressGestureDetector::New();
377 detector.Attach(actor);
378 detector.DetectedSignal().Connect(&application, functor);
380 // Start long press within the actor's area
381 TestGenerateLongPress(application, 20.0f, 20.0f);
382 DALI_TEST_EQUALS(true, data.functorCalled, TEST_LOCATION);
383 DALI_TEST_EQUALS(1u, data.receivedGesture.GetNumberOfTouches(), TEST_LOCATION);
384 DALI_TEST_EQUALS(Vector2(20.0f, 20.0f), data.receivedGesture.GetLocalPoint(), 0.1, TEST_LOCATION);
385 TestEndLongPress(application, 20.0f, 20.0f);
387 // repeat the long press within the actor's area - we should still receive the signal
389 TestGenerateLongPress(application, 50.0f, 50.0f);
390 DALI_TEST_EQUALS(true, data.functorCalled, TEST_LOCATION);
391 DALI_TEST_EQUALS(1u, data.receivedGesture.GetNumberOfTouches(), TEST_LOCATION);
392 DALI_TEST_EQUALS(Vector2(50.0f, 50.0f), data.receivedGesture.GetLocalPoint(), 0.1, TEST_LOCATION);
393 TestEndLongPress(application, 50.0f, 50.0f);
396 detector.DetachAll();
398 // Ensure we are no longer signalled
400 TestGenerateLongPress(application, 20.0f, 20.0f);
401 DALI_TEST_EQUALS(false, data.functorCalled, TEST_LOCATION);
402 TestEndLongPress(application, 50.0f, 50.0f);
403 DALI_TEST_EQUALS(false, data.functorCalled, TEST_LOCATION);
407 int UtcDaliLongPressGestureSignalReceptionActorDestroyedDuringLongPress(void)
409 TestApplication application;
412 GestureReceivedFunctor functor(data);
414 LongPressGestureDetector detector = LongPressGestureDetector::New();
415 detector.DetectedSignal().Connect(&application, functor);
417 // Actor lifetime is scoped
419 Actor actor = Actor::New();
420 actor.SetProperty(Actor::Property::SIZE, Vector2(100.0f, 100.0f));
421 actor.SetProperty(Actor::Property::ANCHOR_POINT, AnchorPoint::TOP_LEFT);
422 application.GetScene().Add(actor);
425 application.SendNotification();
426 application.Render();
428 detector.Attach(actor);
430 // Start long press within the actor's area
431 TestGenerateLongPress(application, 20.0f, 20.0f);
432 DALI_TEST_EQUALS(true, data.functorCalled, TEST_LOCATION);
434 // Remove the actor from stage and reset the data
435 application.GetScene().Remove(actor);
438 application.SendNotification();
439 application.Render();
442 // Actor should now have been destroyed
445 TestEndLongPress(application, 20.0f, 20.0f);
446 DALI_TEST_EQUALS(false, data.functorCalled, TEST_LOCATION);
450 int UtcDaliLongPressGestureSignalReceptionRotatedActor(void)
452 TestApplication application;
454 Actor actor = Actor::New();
455 actor.SetProperty(Actor::Property::SIZE, Vector2(100.0f, 100.0f));
456 actor.SetProperty(Actor::Property::ORIENTATION, Quaternion(Dali::Degree(90.0f), Vector3::ZAXIS));
457 application.GetScene().Add(actor);
460 application.SendNotification();
461 application.Render();
464 GestureReceivedFunctor functor(data);
466 LongPressGestureDetector detector = LongPressGestureDetector::New();
467 detector.Attach(actor);
468 detector.DetectedSignal().Connect(&application, functor);
471 TestGenerateLongPress(application, 5.0f, 5.0f);
472 TestEndLongPress(application, 5.0f, 5.0f);
473 DALI_TEST_EQUALS(true, data.functorCalled, TEST_LOCATION);
474 DALI_TEST_EQUALS(1u, data.receivedGesture.GetNumberOfTouches(), TEST_LOCATION);
475 DALI_TEST_EQUALS(Vector2(5.0f, 5.0f), data.receivedGesture.GetScreenPoint(), 0.1, TEST_LOCATION);
477 // Rotate actor again and render
478 actor.SetProperty(Actor::Property::ORIENTATION, Quaternion(Dali::Degree(180.0f), Vector3::ZAXIS));
479 application.SendNotification();
480 application.Render();
482 // Do another long press, should still receive event
484 TestGenerateLongPress(application, 5.0f, 5.0f);
485 TestEndLongPress(application, 5.0f, 5.0f);
486 DALI_TEST_EQUALS(true, data.functorCalled, TEST_LOCATION);
487 DALI_TEST_EQUALS(1u, data.receivedGesture.GetNumberOfTouches(), TEST_LOCATION);
488 DALI_TEST_EQUALS(Vector2(5.0f, 5.0f), data.receivedGesture.GetScreenPoint(), 0.1, TEST_LOCATION);
490 // Rotate actor again and render
491 actor.SetProperty(Actor::Property::ORIENTATION, Quaternion(Dali::Degree(90.0f), Vector3::YAXIS));
492 application.SendNotification();
493 application.Render();
495 // Do a long press, inside where the actor used to be, Should not receive the event
497 TestGenerateLongPress(application, 70.0f, 70.0f);
498 TestEndLongPress(application, 70.0f, 70.0f);
499 DALI_TEST_EQUALS(false, data.functorCalled, TEST_LOCATION);
503 int UtcDaliLongPressGestureSignalReceptionChildHit(void)
505 TestApplication application;
507 Actor parent = Actor::New();
508 parent.SetProperty(Actor::Property::SIZE, Vector2(100.0f, 100.0f));
509 parent.SetProperty(Actor::Property::ANCHOR_POINT, AnchorPoint::TOP_LEFT);
510 application.GetScene().Add(parent);
512 // Set child to completely cover parent.
513 // Change rotation of child to be different from parent so that we can check if our local coordinate
514 // conversion of the parent actor is correct.
515 Actor child = Actor::New();
516 child.SetProperty(Actor::Property::SIZE, Vector2(100.0f, 100.0f));
517 child.SetProperty(Actor::Property::ANCHOR_POINT, AnchorPoint::CENTER);
518 child.SetProperty(Actor::Property::PARENT_ORIGIN, ParentOrigin::CENTER);
519 child.SetProperty(Actor::Property::ORIENTATION, Quaternion(Dali::Degree(90.0f), Vector3::ZAXIS));
523 application.SendNotification();
524 application.Render();
527 GestureReceivedFunctor functor(data);
529 LongPressGestureDetector detector = LongPressGestureDetector::New();
530 detector.Attach(parent);
531 detector.DetectedSignal().Connect(&application, functor);
533 // Do long press - hits child area but parent should still receive it
534 TestGenerateLongPress(application, 50.0f, 50.0f);
535 TestEndLongPress(application, 50.0f, 50.0f);
536 DALI_TEST_EQUALS(true, data.functorCalled, TEST_LOCATION);
537 DALI_TEST_EQUALS(true, parent == data.pressedActor, TEST_LOCATION);
538 DALI_TEST_EQUALS(Vector2(50.0f, 50.0f), data.receivedGesture.GetScreenPoint(), 0.01f, TEST_LOCATION);
540 // Attach child and generate same touch points
541 // (Also proves that you can detach and then re-attach another actor)
542 detector.Attach(child);
543 detector.Detach(parent);
545 // Do an entire long press, only check finished value
547 TestGenerateLongPress(application, 51.0f, 51.0f);
548 TestEndLongPress(application, 51.0f, 51.0f);
549 DALI_TEST_EQUALS(true, data.functorCalled, TEST_LOCATION);
550 DALI_TEST_EQUALS(true, child == data.pressedActor, TEST_LOCATION);
551 DALI_TEST_EQUALS(Vector2(51.0f, 51.0f), data.receivedGesture.GetScreenPoint(), 0.01f, TEST_LOCATION);
555 int UtcDaliLongPressGestureSignalReceptionAttachDetachMany(void)
557 TestApplication application;
559 Actor first = Actor::New();
560 first.SetProperty(Actor::Property::SIZE, Vector2(100.0f, 100.0f));
561 first.SetProperty(Actor::Property::ANCHOR_POINT, AnchorPoint::TOP_LEFT);
562 application.GetScene().Add(first);
564 Actor second = Actor::New();
565 second.SetProperty(Actor::Property::SIZE, Vector2(100.0f, 100.0f));
566 second.SetProperty(Actor::Property::POSITION_X, 100.0f);
567 second.SetProperty(Actor::Property::ANCHOR_POINT, AnchorPoint::TOP_LEFT);
568 application.GetScene().Add(second);
571 application.SendNotification();
572 application.Render();
575 GestureReceivedFunctor functor(data);
577 LongPressGestureDetector detector = LongPressGestureDetector::New();
578 detector.Attach(first);
579 detector.Attach(second);
580 detector.DetectedSignal().Connect(&application, functor);
582 // LongPress within second actor's area
583 TestGenerateLongPress(application, 120.0f, 10.0f);
584 TestEndLongPress(application, 120.0f, 10.0f);
585 DALI_TEST_EQUALS(true, data.functorCalled, TEST_LOCATION);
586 DALI_TEST_EQUALS(true, second == data.pressedActor, TEST_LOCATION);
588 // LongPress within first actor's area
590 TestGenerateLongPress(application, 20.0f, 10.0f);
591 TestEndLongPress(application, 20.0f, 10.0f);
592 DALI_TEST_EQUALS(true, data.functorCalled, TEST_LOCATION);
593 DALI_TEST_EQUALS(true, first == data.pressedActor, TEST_LOCATION);
595 // Detach the second actor
596 detector.Detach(second);
598 // second actor shouldn't receive event
600 TestGenerateLongPress(application, 120.0f, 10.0f);
601 TestEndLongPress(application, 120.0f, 10.0f);
602 DALI_TEST_EQUALS(false, data.functorCalled, TEST_LOCATION);
604 // first actor should continue receiving event
606 TestGenerateLongPress(application, 20.0f, 10.0f);
607 TestEndLongPress(application, 20.0f, 10.0f);
608 DALI_TEST_EQUALS(true, data.functorCalled, TEST_LOCATION);
612 int UtcDaliLongPressGestureSignalReceptionActorBecomesUntouchable(void)
614 TestApplication application;
616 Actor actor = Actor::New();
617 actor.SetProperty(Actor::Property::SIZE, Vector2(100.0f, 100.0f));
618 actor.SetProperty(Actor::Property::ANCHOR_POINT, AnchorPoint::TOP_LEFT);
619 application.GetScene().Add(actor);
622 application.SendNotification();
623 application.Render();
626 GestureReceivedFunctor functor(data);
628 LongPressGestureDetector detector = LongPressGestureDetector::New();
629 detector.Attach(actor);
630 detector.DetectedSignal().Connect(&application, functor);
632 // LongPress in actor's area
633 TestGenerateLongPress(application, 50.0f, 10.0f);
634 TestEndLongPress(application, 50.0f, 10.0f);
635 DALI_TEST_EQUALS(true, data.functorCalled, TEST_LOCATION);
637 // Actor becomes invisible - actor should not receive the next long press
638 actor.SetProperty(Actor::Property::VISIBLE, false);
641 application.SendNotification();
642 application.Render();
644 // LongPress in the same area, shouldn't receive event
646 TestGenerateLongPress(application, 50.0f, 10.0f);
647 TestEndLongPress(application, 50.0f, 10.0f);
648 DALI_TEST_EQUALS(false, data.functorCalled, TEST_LOCATION);
652 int UtcDaliLongPressGestureSignalReceptionMultipleDetectorsOnActor(void)
654 TestApplication application;
656 Actor actor = Actor::New();
657 actor.SetProperty(Actor::Property::SIZE, Vector2(100.0f, 100.0f));
658 actor.SetProperty(Actor::Property::ANCHOR_POINT, AnchorPoint::TOP_LEFT);
659 application.GetScene().Add(actor);
662 application.SendNotification();
663 application.Render();
665 // Attach actor to one detector
666 SignalData firstData;
667 GestureReceivedFunctor firstFunctor(firstData);
668 LongPressGestureDetector firstDetector = LongPressGestureDetector::New();
669 firstDetector.Attach(actor);
670 firstDetector.DetectedSignal().Connect(&application, firstFunctor);
672 // Attach actor to another detector
673 SignalData secondData;
674 GestureReceivedFunctor secondFunctor(secondData);
675 LongPressGestureDetector secondDetector = LongPressGestureDetector::New();
676 secondDetector.Attach(actor);
677 secondDetector.DetectedSignal().Connect(&application, secondFunctor);
679 // LongPress in actor's area - both detector's functors should be called
680 TestGenerateLongPress(application, 50.0f, 10.0f);
681 DALI_TEST_EQUALS(true, firstData.functorCalled, TEST_LOCATION);
682 DALI_TEST_EQUALS(true, secondData.functorCalled, TEST_LOCATION);
686 int UtcDaliLongPressGestureSignalReceptionDifferentPossible(void)
688 TestApplication application;
690 Actor actor = Actor::New();
691 actor.SetProperty(Actor::Property::SIZE, Vector2(100.0f, 100.0f));
692 actor.SetProperty(Actor::Property::ANCHOR_POINT, AnchorPoint::TOP_LEFT);
693 application.GetScene().Add(actor);
696 application.SendNotification();
697 application.Render();
699 // Attach actor to detector
701 GestureReceivedFunctor functor(data);
702 LongPressGestureDetector detector = LongPressGestureDetector::New();
703 detector.Attach(actor);
704 detector.DetectedSignal().Connect(&application, functor);
706 // LongPress possible in actor's area.
707 TestStartLongPress(application, 50.0f, 10.0f);
708 DALI_TEST_EQUALS(false, data.functorCalled, TEST_LOCATION);
710 // Move actor somewhere else
711 actor.SetProperty(Actor::Property::POSITION, Vector2(100.0f, 100.0f));
714 application.SendNotification();
715 application.Render();
717 // Emit Started event, we should not receive the long press.
718 TestTriggerLongPress(application);
719 TestGenerateLongPress(application, 50.0f, 10.0f);
720 DALI_TEST_EQUALS(false, data.functorCalled, TEST_LOCATION);
722 // LongPress possible in empty area.
723 TestStartLongPress(application, 50.0f, 10.0f);
724 DALI_TEST_EQUALS(false, data.functorCalled, TEST_LOCATION);
726 // Move actor in to the long press position.
727 actor.SetProperty(Actor::Property::POSITION, Vector2(0.0f, 0.0f));
730 application.SendNotification();
731 application.Render();
733 // Emit STARTED event, we should not receive the long press.
734 TestTriggerLongPress(application);
735 TestEndLongPress(application, 50.0f, 10.0f);
736 DALI_TEST_EQUALS(false, data.functorCalled, TEST_LOCATION);
738 // Normal long press in actor's area for completeness.
739 TestGenerateLongPress(application, 50.0f, 10.0f);
740 TestEndLongPress(application, 50.0f, 10.0f);
741 DALI_TEST_EQUALS(true, data.functorCalled, TEST_LOCATION);
745 int UtcDaliLongPressGesturePossibleCancelled(void)
747 TestApplication application;
749 Actor actor = Actor::New();
750 actor.SetProperty(Actor::Property::SIZE, Vector2(100.0f, 100.0f));
751 actor.SetProperty(Actor::Property::ANCHOR_POINT, AnchorPoint::TOP_LEFT);
752 application.GetScene().Add(actor);
755 application.SendNotification();
756 application.Render();
758 // Attach actor to detector
760 GestureReceivedFunctor functor(data);
761 LongPressGestureDetector detector = LongPressGestureDetector::New();
762 detector.Attach(actor);
763 detector.DetectedSignal().Connect(&application, functor);
765 // Send a possible followed by a cancel, we should not be signalled
766 TestStartLongPress(application, 50.0f, 10.0f);
767 DALI_TEST_EQUALS(false, data.functorCalled, TEST_LOCATION);
768 TestMovePan(application, Vector2(50.0f, 10.0f));
769 DALI_TEST_EQUALS(false, data.functorCalled, TEST_LOCATION);
773 int UtcDaliLongPressGestureDetachAfterStarted(void)
775 TestApplication application;
777 Actor actor = Actor::New();
778 actor.SetProperty(Actor::Property::SIZE, Vector2(100.0f, 100.0f));
779 actor.SetProperty(Actor::Property::ANCHOR_POINT, AnchorPoint::TOP_LEFT);
780 application.GetScene().Add(actor);
783 application.SendNotification();
784 application.Render();
786 // Attach actor to detector
788 GestureReceivedFunctor functor(data);
789 LongPressGestureDetector detector = LongPressGestureDetector::New();
790 detector.Attach(actor);
791 detector.DetectedSignal().Connect(&application, functor);
793 // Emit initial signal
794 TestGenerateLongPress(application, 50.0f, 10.0f);
795 DALI_TEST_EQUALS(true, data.functorCalled, TEST_LOCATION);
799 detector.Detach(actor);
801 // Emit FINISHED, no signal
802 TestEndLongPress(application, 50.0f, 10.0f);
803 DALI_TEST_EQUALS(false, data.functorCalled, TEST_LOCATION);
807 int UtcDaliLongPressGestureActorUnstaged(void)
809 TestApplication application;
811 Actor actor = Actor::New();
812 actor.SetProperty(Actor::Property::SIZE, Vector2(100.0f, 100.0f));
813 actor.SetProperty(Actor::Property::ANCHOR_POINT, AnchorPoint::TOP_LEFT);
814 application.GetScene().Add(actor);
817 application.SendNotification();
818 application.Render();
820 // State to remove actor in.
821 GestureState stateToUnstage(GestureState::STARTED);
823 // Attach actor to detector
825 UnstageActorFunctor functor(data, stateToUnstage, application.GetScene());
826 LongPressGestureDetector detector = LongPressGestureDetector::New();
827 detector.Attach(actor);
828 detector.DetectedSignal().Connect(&application, functor);
831 TestGenerateLongPress(application, 50.0f, 10.0f);
832 DALI_TEST_EQUALS(true, data.functorCalled, TEST_LOCATION);
834 TestEndLongPress(application, 50.0f, 10.0f);
835 DALI_TEST_EQUALS(false, data.functorCalled, TEST_LOCATION);
838 application.SendNotification();
839 application.Render();
841 // Re-add actor to stage
842 application.GetScene().Add(actor);
845 application.SendNotification();
846 application.Render();
848 // Change state to GestureState::CONTINUING to remove
849 stateToUnstage = GestureState::FINISHED;
852 TestGenerateLongPress(application, 50.0f, 10.0f);
853 DALI_TEST_EQUALS(true, data.functorCalled, TEST_LOCATION);
855 TestEndLongPress(application, 50.0f, 10.0f);
856 DALI_TEST_EQUALS(true, data.functorCalled, TEST_LOCATION);
857 tet_result(TET_PASS); // If we get here then we have handled actor stage removal gracefully.
861 int UtcDaliLongPressGestureActorStagedAndDestroyed(void)
863 TestApplication application;
865 Actor actor = Actor::New();
866 actor.SetProperty(Actor::Property::SIZE, Vector2(100.0f, 100.0f));
867 actor.SetProperty(Actor::Property::ANCHOR_POINT, AnchorPoint::TOP_LEFT);
868 application.GetScene().Add(actor);
870 // Create and add a second actor so that GestureDetector destruction does not come into play.
871 Actor dummyActor(Actor::New());
872 dummyActor.SetProperty(Actor::Property::SIZE, Vector2(100.0f, 100.0f));
873 dummyActor.SetProperty(Actor::Property::POSITION, Vector2(100.0f, 100.0f));
874 dummyActor.SetProperty(Actor::Property::ANCHOR_POINT, AnchorPoint::TOP_LEFT);
875 application.GetScene().Add(dummyActor);
878 application.SendNotification();
879 application.Render();
881 // State to remove actor in.
882 GestureState stateToUnstage(GestureState::STARTED);
884 // Attach actor to detector
886 UnstageActorFunctor functor(data, stateToUnstage, application.GetScene());
887 LongPressGestureDetector detector = LongPressGestureDetector::New();
888 detector.Attach(actor);
889 detector.Attach(dummyActor);
890 detector.DetectedSignal().Connect(&application, functor);
892 // Here we are testing a STARTED actor which is removed in the STARTED callback, but then added back
893 // before we get a finished state. As we were removed from the stage, even if we're at the same
894 // position, we should still not be signalled.
897 TestGenerateLongPress(application, 50.0f, 10.0f);
898 DALI_TEST_EQUALS(true, data.functorCalled, TEST_LOCATION);
902 application.SendNotification();
903 application.Render();
905 // Re add to the stage, we should not be signalled
906 application.GetScene().Add(actor);
909 application.SendNotification();
910 application.Render();
912 // Continue signal emission
913 TestEndLongPress(application, 50.0f, 10.0f);
914 DALI_TEST_EQUALS(false, data.functorCalled, TEST_LOCATION);
917 // Here we delete an actor in started, we should not receive any subsequent signalling.
920 TestGenerateLongPress(application, 50.0f, 10.0f);
921 DALI_TEST_EQUALS(true, data.functorCalled, TEST_LOCATION);
925 application.SendNotification();
926 application.Render();
928 // Delete actor as well
932 application.SendNotification();
933 application.Render();
935 // Continue signal emission
936 TestEndLongPress(application, 50.0f, 10.0f);
937 DALI_TEST_EQUALS(false, data.functorCalled, TEST_LOCATION);
941 int UtcDaliLongPressGestureLayerConsumesTouch(void)
943 TestApplication application;
945 Actor actor = Actor::New();
946 actor.SetProperty(Actor::Property::SIZE, Vector2(100.0f, 100.0f));
947 actor.SetProperty(Actor::Property::ANCHOR_POINT, AnchorPoint::TOP_LEFT);
948 application.GetScene().Add(actor);
952 GestureReceivedFunctor functor(data);
953 LongPressGestureDetector detector = LongPressGestureDetector::New();
954 detector.Attach(actor);
955 detector.DetectedSignal().Connect(&application, functor);
957 // Add a layer to overlap the actor
958 Layer layer = Layer::New();
959 layer.SetProperty(Actor::Property::SIZE, Vector2(100.0f, 100.0f));
960 layer.SetProperty(Actor::Property::ANCHOR_POINT, AnchorPoint::TOP_LEFT);
961 application.GetScene().Add(layer);
965 application.SendNotification();
966 application.Render();
968 // Emit signals, should receive
969 TestGenerateLongPress(application, 50.0f, 50.0f);
970 TestEndLongPress(application, 50.0f, 50.0f);
971 DALI_TEST_EQUALS(true, data.functorCalled, TEST_LOCATION);
974 // Set layer to consume all touch
975 layer.SetProperty(Layer::Property::CONSUMES_TOUCH, true);
978 application.SendNotification();
979 application.Render();
981 // Emit the same signals again, should not receive
982 TestGenerateLongPress(application, 50.0f, 50.0f);
983 TestEndLongPress(application, 50.0f, 50.0f);
984 DALI_TEST_EQUALS(false, data.functorCalled, TEST_LOCATION);
990 int UtcDaliLongPressGestureSetMinimumHoldingTime(void)
992 TestApplication application;
994 const uint32_t kMinumumHolding1 = 5000;
995 const uint32_t kMinumumHolding2 = 3000;
997 Integration::SetLongPressMinimumHoldingTime(kMinumumHolding1);
999 Actor actor = Actor::New();
1000 actor.SetProperty(Actor::Property::SIZE, Vector2(100.0f, 100.0f));
1001 actor.SetProperty(Actor::Property::ANCHOR_POINT, AnchorPoint::TOP_LEFT);
1002 application.GetScene().Add(actor);
1004 // Render and notify
1005 application.SendNotification();
1006 application.Render();
1009 GestureReceivedFunctor functor(data);
1011 LongPressGestureDetector detector = LongPressGestureDetector::New();
1012 detector.Attach(actor);
1013 detector.DetectedSignal().Connect(&application, functor);
1015 DALI_TEST_EQUALS(DevelLongPressGestureDetector::GetMinimumHoldingTime(detector), kMinumumHolding1, TEST_LOCATION);
1017 Integration::SetLongPressMinimumHoldingTime(kMinumumHolding2);
1018 DALI_TEST_EQUALS(DevelLongPressGestureDetector::GetMinimumHoldingTime(detector), kMinumumHolding2, TEST_LOCATION);
1023 int UtcDaliLongPressGestureDisableDetectionDuringLongPressN(void)
1025 // Crash occurred when gesture-recognizer was deleted internally during a signal when the attached actor was detached
1027 TestApplication application;
1029 Actor actor = Actor::New();
1030 actor.SetProperty(Actor::Property::SIZE, Vector2(100.0f, 100.0f));
1031 actor.SetProperty(Actor::Property::ANCHOR_POINT, AnchorPoint::TOP_LEFT);
1032 application.GetScene().Add(actor);
1035 LongPressGestureDetector detector = LongPressGestureDetector::New();
1036 bool functorCalled = false;
1037 detector.Attach(actor);
1038 detector.DetectedSignal().Connect(
1040 [&detector, &functorCalled](Actor actor, const LongPressGesture& gesture) {
1041 if(gesture.GetState() == GestureState::FINISHED)
1043 detector.Detach(actor);
1044 functorCalled = true;
1048 // Render and notify
1049 application.SendNotification();
1050 application.Render();
1052 // Try the gesture, should not crash
1055 TestGenerateLongPress(application, 50.0f, 10.0f);
1056 TestEndLongPress(application, 50.0f, 10.0f);
1058 DALI_TEST_CHECK(true); // No crash, test has passed
1059 DALI_TEST_EQUALS(functorCalled, true, TEST_LOCATION);
1063 DALI_TEST_CHECK(false); // If we crash, the test has failed
1069 int UtcDaliLongPressGestureWhenGesturePropargation(void)
1071 TestApplication application;
1073 Actor parentActor = Actor::New();
1074 parentActor.SetProperty(Actor::Property::SIZE, Vector2(100.0f, 100.0f));
1075 parentActor.SetProperty(Actor::Property::ANCHOR_POINT, AnchorPoint::TOP_LEFT);
1077 Actor childActor = Actor::New();
1078 childActor.SetProperty(Actor::Property::SIZE, Vector2(100.0f, 100.0f));
1079 childActor.SetProperty(Actor::Property::ANCHOR_POINT, AnchorPoint::TOP_LEFT);
1081 parentActor.Add(childActor);
1082 application.GetScene().Add(parentActor);
1084 // Render and notify
1085 application.SendNotification();
1086 application.Render();
1089 GestureReceivedFunctor pFunctor(pData);
1091 LongPressGestureDetector parentDetector = LongPressGestureDetector::New();
1092 parentDetector.Attach(parentActor);
1093 parentDetector.DetectedSignal().Connect(&application, pFunctor);
1096 GestureReceivedFunctor cFunctor(cData);
1098 LongPressGestureDetector childDetector = LongPressGestureDetector::New();
1099 childDetector.Attach(childActor);
1100 childDetector.DetectedSignal().Connect(&application, cFunctor);
1102 // Start gesture within the actor's area, we receive the gesture not parent actor but child actor.
1103 TestGenerateLongPress(application, 50.0f, 50.0f);
1104 TestEndLongPress(application, 50.0f, 50.0f);
1106 DALI_TEST_EQUALS(true, cData.functorCalled, TEST_LOCATION);
1107 DALI_TEST_EQUALS(false, pData.functorCalled, TEST_LOCATION);
1111 // If GesturePropargation is set, a gesture event is to pass over to the parent.
1112 Dali::DevelActor::SetNeedGesturePropagation(childActor, true);
1114 // So now the parent got the gesture event.
1115 TestGenerateLongPress(application, 50.0f, 50.0f);
1116 TestEndLongPress(application, 50.0f, 50.0f);
1117 DALI_TEST_EQUALS(true, cData.functorCalled, TEST_LOCATION);
1118 DALI_TEST_EQUALS(true, pData.functorCalled, TEST_LOCATION);