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/events/touch-integ.h>
23 #include <dali/integration-api/input-options.h>
24 #include <dali/integration-api/render-task-list-integ.h>
25 #include <dali/internal/event/events/touch-event-impl.h>
26 #include <dali/internal/event/render-tasks/render-task-impl.h>
27 #include <dali/public-api/dali-core.h>
29 #include <test-touch-event-utils.h>
35 void utc_dali_long_press_gesture_detector_startup(void)
37 test_return_value = TET_UNDEF;
40 void utc_dali_long_press_gesture_detector_cleanup(void)
42 test_return_value = TET_PASS;
45 ///////////////////////////////////////////////////////////////////////////////
48 // Stores data that is populated in the callback and will be read by the TET cases
52 : functorCalled(false),
53 voidFunctorCalled(false),
61 functorCalled = false;
62 voidFunctorCalled = false;
64 receivedGesture.Reset();
70 bool voidFunctorCalled;
71 LongPressGesture receivedGesture;
75 // Functor that sets the data when called
76 struct GestureReceivedFunctor
78 GestureReceivedFunctor(SignalData& data)
83 void operator()(Actor actor, const LongPressGesture& longPress)
85 signalData.functorCalled = true;
86 signalData.receivedGesture = longPress;
87 signalData.pressedActor = actor;
92 signalData.voidFunctorCalled = true;
95 SignalData& signalData;
98 // Functor that removes the gestured actor from stage
99 struct UnstageActorFunctor : public GestureReceivedFunctor
101 UnstageActorFunctor(SignalData& data, GestureState& stateToUnstage, Integration::Scene scene)
102 : GestureReceivedFunctor(data),
103 stateToUnstage(stateToUnstage),
108 void operator()(Actor actor, const LongPressGesture& longPress)
110 GestureReceivedFunctor::operator()(actor, longPress);
112 if(longPress.GetState() == stateToUnstage)
118 GestureState& stateToUnstage;
119 Integration::Scene scene;
122 // Functor for receiving a touch event
123 struct TouchEventFunctor
125 bool operator()(Actor actor, Dali::TouchEvent touch)
128 unsigned int points = touch.GetPointCount();
131 tet_printf("Touch Point state = %d\n", touch.GetState(0));
137 Integration::TouchEvent GenerateSingleTouch(PointState::Type state, const Vector2& screenPosition, uint32_t time)
139 Integration::TouchEvent touchEvent;
140 Integration::Point point;
141 point.SetState(state);
142 point.SetDeviceId(4);
143 point.SetScreenPosition(screenPosition);
144 point.SetDeviceClass(Device::Class::TOUCH);
145 point.SetDeviceSubclass(Device::Subclass::NONE);
146 touchEvent.points.push_back(point);
147 touchEvent.time = time;
152 ///////////////////////////////////////////////////////////////////////////////
154 // Positive test case for a method
155 int UtcDaliLongPressGestureDetectorConstructorP(void)
157 TestApplication application;
159 LongPressGestureDetector detector;
160 DALI_TEST_CHECK(!detector);
164 int UtcDaliLongPressGestureDetectorCopyConstructorP(void)
166 TestApplication application;
168 LongPressGestureDetector detector = LongPressGestureDetector::New();
170 LongPressGestureDetector copy(detector);
171 DALI_TEST_CHECK(detector);
175 int UtcDaliLongPressGestureDetectorAssignmentOperatorP(void)
177 TestApplication application;
179 LongPressGestureDetector detector;
180 detector = LongPressGestureDetector::New();
182 LongPressGestureDetector copy;
184 DALI_TEST_CHECK(detector);
186 DALI_TEST_CHECK(detector == copy);
190 int UtcDaliLongPressGestureDetectorMoveConstructorP(void)
192 TestApplication application;
194 LongPressGestureDetector detector = LongPressGestureDetector::New();
195 DALI_TEST_CHECK(detector);
197 LongPressGestureDetector moved = std::move(detector);
198 DALI_TEST_CHECK(moved);
199 DALI_TEST_CHECK(!detector);
203 int UtcDaliLongPressGestureDetectorMoveAssignmentOperatorP(void)
205 TestApplication application;
207 LongPressGestureDetector detector;
208 detector = LongPressGestureDetector::New();
209 DALI_TEST_CHECK(detector);
211 LongPressGestureDetector moved;
212 moved = std::move(detector);
213 DALI_TEST_CHECK(moved);
214 DALI_TEST_CHECK(!detector);
218 int UtcDaliLongPressGestureDetectorNew(void)
220 TestApplication application;
222 LongPressGestureDetector detector = LongPressGestureDetector::New();
223 DALI_TEST_CHECK(detector);
224 DALI_TEST_EQUALS(1u, detector.GetMinimumTouchesRequired(), TEST_LOCATION);
225 DALI_TEST_EQUALS(1u, detector.GetMaximumTouchesRequired(), TEST_LOCATION);
227 LongPressGestureDetector detector2 = LongPressGestureDetector::New(5u);
228 DALI_TEST_CHECK(detector2);
229 DALI_TEST_EQUALS(5u, detector2.GetMinimumTouchesRequired(), TEST_LOCATION);
230 DALI_TEST_EQUALS(5u, detector2.GetMaximumTouchesRequired(), TEST_LOCATION);
232 LongPressGestureDetector detector3 = LongPressGestureDetector::New(5u, 7u);
233 DALI_TEST_CHECK(detector2);
234 DALI_TEST_EQUALS(5u, detector3.GetMinimumTouchesRequired(), TEST_LOCATION);
235 DALI_TEST_EQUALS(7u, detector3.GetMaximumTouchesRequired(), TEST_LOCATION);
237 //Scoped test to test destructor
239 LongPressGestureDetector detector4 = LongPressGestureDetector::New();
240 DALI_TEST_CHECK(detector4);
243 // Attach an actor and emit a touch event on the actor to ensure complete line coverage
244 Actor actor = Actor::New();
245 actor.SetProperty(Actor::Property::SIZE, Vector2(100.0f, 100.0f));
246 actor.SetProperty(Actor::Property::ANCHOR_POINT, AnchorPoint::TOP_LEFT);
247 application.GetScene().Add(actor);
250 application.SendNotification();
251 application.Render();
253 detector.Attach(actor);
255 TouchEventFunctor touchFunctor;
256 actor.TouchedSignal().Connect(&application, touchFunctor);
258 Integration::TouchEvent touchEvent(1);
259 Integration::Point point;
260 point.SetDeviceId(1);
261 point.SetState(PointState::DOWN);
262 point.SetScreenPosition(Vector2(20.0f, 20.0f));
263 touchEvent.AddPoint(point);
264 application.ProcessEvent(touchEvent);
267 application.SendNotification();
268 application.Render();
273 int UtcDaliLongPressGestureDetectorDownCast(void)
275 TestApplication application;
276 tet_infoline("Testing Dali::LongPressGestureDetector::DownCast()");
278 LongPressGestureDetector detector = LongPressGestureDetector::New();
280 BaseHandle object(detector);
282 LongPressGestureDetector detector2 = LongPressGestureDetector::DownCast(object);
283 DALI_TEST_CHECK(detector2);
285 LongPressGestureDetector detector3 = DownCast<LongPressGestureDetector>(object);
286 DALI_TEST_CHECK(detector3);
288 BaseHandle unInitializedObject;
289 LongPressGestureDetector detector4 = LongPressGestureDetector::DownCast(unInitializedObject);
290 DALI_TEST_CHECK(!detector4);
292 LongPressGestureDetector detector5 = DownCast<LongPressGestureDetector>(unInitializedObject);
293 DALI_TEST_CHECK(!detector5);
295 GestureDetector detector6 = LongPressGestureDetector::New();
296 LongPressGestureDetector detector7 = LongPressGestureDetector::DownCast(detector6);
297 DALI_TEST_CHECK(detector7);
301 int UtcDaliLongPressGestureGetMinimumTouchesRequired(void)
303 TestApplication application;
305 LongPressGestureDetector detector = LongPressGestureDetector::New();
306 DALI_TEST_EQUALS(1u, detector.GetMinimumTouchesRequired(), TEST_LOCATION);
310 int UtcDaliLongPressGestureGetMaximumTouchesRequired(void)
312 TestApplication application;
314 LongPressGestureDetector detector = LongPressGestureDetector::New();
315 DALI_TEST_EQUALS(1u, detector.GetMaximumTouchesRequired(), TEST_LOCATION);
319 int UtcDaliLongPressGestureSignalReceptionNegative(void)
321 TestApplication application;
323 Actor actor = Actor::New();
324 actor.SetProperty(Actor::Property::SIZE, Vector2(100.0f, 100.0f));
325 actor.SetProperty(Actor::Property::ANCHOR_POINT, AnchorPoint::TOP_LEFT);
326 application.GetScene().Add(actor);
329 application.SendNotification();
330 application.Render();
333 GestureReceivedFunctor functor(data);
335 LongPressGestureDetector detector = LongPressGestureDetector::New();
336 detector.Attach(actor);
337 detector.DetectedSignal().Connect(&application, functor);
339 // Do a long press outside actor's area
340 TestGenerateLongPress(application, 112.0f, 112.0f);
341 TestEndLongPress(application, 112.0f, 112.0f);
343 DALI_TEST_EQUALS(false, data.functorCalled, TEST_LOCATION);
347 int UtcDaliLongPressGestureSignalReceptionPositive(void)
349 TestApplication application;
351 Actor actor = Actor::New();
352 actor.SetProperty(Actor::Property::SIZE, Vector2(100.0f, 100.0f));
353 actor.SetProperty(Actor::Property::ANCHOR_POINT, AnchorPoint::TOP_LEFT);
354 application.GetScene().Add(actor);
357 application.SendNotification();
358 application.Render();
361 GestureReceivedFunctor functor(data);
363 LongPressGestureDetector detector = LongPressGestureDetector::New();
364 detector.Attach(actor);
365 detector.DetectedSignal().Connect(&application, functor);
367 // Do a long press inside actor's area
368 TestGenerateLongPress(application, 50.0f, 50.0f);
369 DALI_TEST_EQUALS(true, data.functorCalled, TEST_LOCATION);
370 DALI_TEST_EQUALS(1u, data.receivedGesture.GetNumberOfTouches(), TEST_LOCATION);
371 DALI_TEST_EQUALS(Vector2(50.0f, 50.0f), data.receivedGesture.GetLocalPoint(), 0.1, TEST_LOCATION);
372 TestEndLongPress(application, 50.0f, 50.0f);
376 int UtcDaliLongPressGestureSignalReceptionDetach(void)
378 TestApplication application;
380 Actor actor = Actor::New();
381 actor.SetProperty(Actor::Property::SIZE, Vector2(100.0f, 100.0f));
382 actor.SetProperty(Actor::Property::ANCHOR_POINT, AnchorPoint::TOP_LEFT);
383 application.GetScene().Add(actor);
386 application.SendNotification();
387 application.Render();
390 GestureReceivedFunctor functor(data);
392 LongPressGestureDetector detector = LongPressGestureDetector::New();
393 detector.Attach(actor);
394 detector.DetectedSignal().Connect(&application, functor);
396 // Start long press within the actor's area
397 TestGenerateLongPress(application, 20.0f, 20.0f);
398 DALI_TEST_EQUALS(true, data.functorCalled, TEST_LOCATION);
399 DALI_TEST_EQUALS(1u, data.receivedGesture.GetNumberOfTouches(), TEST_LOCATION);
400 DALI_TEST_EQUALS(Vector2(20.0f, 20.0f), data.receivedGesture.GetLocalPoint(), 0.1, TEST_LOCATION);
401 TestEndLongPress(application, 20.0f, 20.0f);
403 // repeat the long press within the actor's area - we should still receive the signal
405 TestGenerateLongPress(application, 50.0f, 50.0f);
406 DALI_TEST_EQUALS(true, data.functorCalled, TEST_LOCATION);
407 DALI_TEST_EQUALS(1u, data.receivedGesture.GetNumberOfTouches(), TEST_LOCATION);
408 DALI_TEST_EQUALS(Vector2(50.0f, 50.0f), data.receivedGesture.GetLocalPoint(), 0.1, TEST_LOCATION);
409 TestEndLongPress(application, 50.0f, 50.0f);
412 detector.DetachAll();
414 // Ensure we are no longer signalled
416 TestGenerateLongPress(application, 20.0f, 20.0f);
417 DALI_TEST_EQUALS(false, data.functorCalled, TEST_LOCATION);
418 TestEndLongPress(application, 50.0f, 50.0f);
419 DALI_TEST_EQUALS(false, data.functorCalled, TEST_LOCATION);
423 int UtcDaliLongPressGestureSignalReceptionActorDestroyedDuringLongPress(void)
425 TestApplication application;
428 GestureReceivedFunctor functor(data);
430 LongPressGestureDetector detector = LongPressGestureDetector::New();
431 detector.DetectedSignal().Connect(&application, functor);
433 // Actor lifetime is scoped
435 Actor actor = Actor::New();
436 actor.SetProperty(Actor::Property::SIZE, Vector2(100.0f, 100.0f));
437 actor.SetProperty(Actor::Property::ANCHOR_POINT, AnchorPoint::TOP_LEFT);
438 application.GetScene().Add(actor);
441 application.SendNotification();
442 application.Render();
444 detector.Attach(actor);
446 // Start long press within the actor's area
447 TestGenerateLongPress(application, 20.0f, 20.0f);
448 DALI_TEST_EQUALS(true, data.functorCalled, TEST_LOCATION);
450 // Remove the actor from stage and reset the data
451 application.GetScene().Remove(actor);
454 application.SendNotification();
455 application.Render();
458 // Actor should now have been destroyed
461 TestEndLongPress(application, 20.0f, 20.0f);
462 DALI_TEST_EQUALS(false, data.functorCalled, TEST_LOCATION);
466 int UtcDaliLongPressGestureSignalReceptionRotatedActor(void)
468 TestApplication application;
470 Actor actor = Actor::New();
471 actor.SetProperty(Actor::Property::SIZE, Vector2(100.0f, 100.0f));
472 actor.SetProperty(Actor::Property::ORIENTATION, Quaternion(Dali::Degree(90.0f), Vector3::ZAXIS));
473 application.GetScene().Add(actor);
476 application.SendNotification();
477 application.Render();
480 GestureReceivedFunctor functor(data);
482 LongPressGestureDetector detector = LongPressGestureDetector::New();
483 detector.Attach(actor);
484 detector.DetectedSignal().Connect(&application, functor);
487 TestGenerateLongPress(application, 5.0f, 5.0f);
488 TestEndLongPress(application, 5.0f, 5.0f);
489 DALI_TEST_EQUALS(true, data.functorCalled, TEST_LOCATION);
490 DALI_TEST_EQUALS(1u, data.receivedGesture.GetNumberOfTouches(), TEST_LOCATION);
491 DALI_TEST_EQUALS(Vector2(5.0f, 5.0f), data.receivedGesture.GetScreenPoint(), 0.1, TEST_LOCATION);
493 // Rotate actor again and render
494 actor.SetProperty(Actor::Property::ORIENTATION, Quaternion(Dali::Degree(180.0f), Vector3::ZAXIS));
495 application.SendNotification();
496 application.Render();
498 // Do another long press, should still receive event
500 TestGenerateLongPress(application, 5.0f, 5.0f);
501 TestEndLongPress(application, 5.0f, 5.0f);
502 DALI_TEST_EQUALS(true, data.functorCalled, TEST_LOCATION);
503 DALI_TEST_EQUALS(1u, data.receivedGesture.GetNumberOfTouches(), TEST_LOCATION);
504 DALI_TEST_EQUALS(Vector2(5.0f, 5.0f), data.receivedGesture.GetScreenPoint(), 0.1, TEST_LOCATION);
506 // Rotate actor again and render
507 actor.SetProperty(Actor::Property::ORIENTATION, Quaternion(Dali::Degree(90.0f), Vector3::YAXIS));
508 application.SendNotification();
509 application.Render();
511 // Do a long press, inside where the actor used to be, Should not receive the event
513 TestGenerateLongPress(application, 70.0f, 70.0f);
514 TestEndLongPress(application, 70.0f, 70.0f);
515 DALI_TEST_EQUALS(false, data.functorCalled, TEST_LOCATION);
519 int UtcDaliLongPressGestureSignalReceptionChildHit(void)
521 TestApplication application;
523 Actor parent = Actor::New();
524 parent.SetProperty(Actor::Property::SIZE, Vector2(100.0f, 100.0f));
525 parent.SetProperty(Actor::Property::ANCHOR_POINT, AnchorPoint::TOP_LEFT);
526 application.GetScene().Add(parent);
528 // Set child to completely cover parent.
529 // Change rotation of child to be different from parent so that we can check if our local coordinate
530 // conversion of the parent actor is correct.
531 Actor child = Actor::New();
532 child.SetProperty(Actor::Property::SIZE, Vector2(100.0f, 100.0f));
533 child.SetProperty(Actor::Property::ANCHOR_POINT, AnchorPoint::CENTER);
534 child.SetProperty(Actor::Property::PARENT_ORIGIN, ParentOrigin::CENTER);
535 child.SetProperty(Actor::Property::ORIENTATION, Quaternion(Dali::Degree(90.0f), Vector3::ZAXIS));
539 application.SendNotification();
540 application.Render();
543 GestureReceivedFunctor functor(data);
545 LongPressGestureDetector detector = LongPressGestureDetector::New();
546 detector.Attach(parent);
547 detector.DetectedSignal().Connect(&application, functor);
549 // Do long press - hits child area but parent should still receive it
550 TestGenerateLongPress(application, 50.0f, 50.0f);
551 TestEndLongPress(application, 50.0f, 50.0f);
552 DALI_TEST_EQUALS(true, data.functorCalled, TEST_LOCATION);
553 DALI_TEST_EQUALS(true, parent == data.pressedActor, TEST_LOCATION);
554 DALI_TEST_EQUALS(Vector2(50.0f, 50.0f), data.receivedGesture.GetScreenPoint(), 0.01f, TEST_LOCATION);
556 // Attach child and generate same touch points
557 // (Also proves that you can detach and then re-attach another actor)
558 detector.Attach(child);
559 detector.Detach(parent);
561 // Do an entire long press, only check finished value
563 TestGenerateLongPress(application, 51.0f, 51.0f);
564 TestEndLongPress(application, 51.0f, 51.0f);
565 DALI_TEST_EQUALS(true, data.functorCalled, TEST_LOCATION);
566 DALI_TEST_EQUALS(true, child == data.pressedActor, TEST_LOCATION);
567 DALI_TEST_EQUALS(Vector2(51.0f, 51.0f), data.receivedGesture.GetScreenPoint(), 0.01f, TEST_LOCATION);
571 int UtcDaliLongPressGestureSignalReceptionAttachDetachMany(void)
573 TestApplication application;
575 Actor first = Actor::New();
576 first.SetProperty(Actor::Property::SIZE, Vector2(100.0f, 100.0f));
577 first.SetProperty(Actor::Property::ANCHOR_POINT, AnchorPoint::TOP_LEFT);
578 application.GetScene().Add(first);
580 Actor second = Actor::New();
581 second.SetProperty(Actor::Property::SIZE, Vector2(100.0f, 100.0f));
582 second.SetProperty(Actor::Property::POSITION_X, 100.0f);
583 second.SetProperty(Actor::Property::ANCHOR_POINT, AnchorPoint::TOP_LEFT);
584 application.GetScene().Add(second);
587 application.SendNotification();
588 application.Render();
591 GestureReceivedFunctor functor(data);
593 LongPressGestureDetector detector = LongPressGestureDetector::New();
594 detector.Attach(first);
595 detector.Attach(second);
596 detector.DetectedSignal().Connect(&application, functor);
598 // LongPress within second actor's area
599 TestGenerateLongPress(application, 120.0f, 10.0f);
600 TestEndLongPress(application, 120.0f, 10.0f);
601 DALI_TEST_EQUALS(true, data.functorCalled, TEST_LOCATION);
602 DALI_TEST_EQUALS(true, second == data.pressedActor, TEST_LOCATION);
604 // LongPress within first actor's area
606 TestGenerateLongPress(application, 20.0f, 10.0f);
607 TestEndLongPress(application, 20.0f, 10.0f);
608 DALI_TEST_EQUALS(true, data.functorCalled, TEST_LOCATION);
609 DALI_TEST_EQUALS(true, first == data.pressedActor, TEST_LOCATION);
611 // Detach the second actor
612 detector.Detach(second);
614 // second actor shouldn't receive event
616 TestGenerateLongPress(application, 120.0f, 10.0f);
617 TestEndLongPress(application, 120.0f, 10.0f);
618 DALI_TEST_EQUALS(false, data.functorCalled, TEST_LOCATION);
620 // first actor should continue receiving event
622 TestGenerateLongPress(application, 20.0f, 10.0f);
623 TestEndLongPress(application, 20.0f, 10.0f);
624 DALI_TEST_EQUALS(true, data.functorCalled, TEST_LOCATION);
628 int UtcDaliLongPressGestureSignalReceptionActorBecomesUntouchable(void)
630 TestApplication application;
632 Actor actor = Actor::New();
633 actor.SetProperty(Actor::Property::SIZE, Vector2(100.0f, 100.0f));
634 actor.SetProperty(Actor::Property::ANCHOR_POINT, AnchorPoint::TOP_LEFT);
635 application.GetScene().Add(actor);
638 application.SendNotification();
639 application.Render();
642 GestureReceivedFunctor functor(data);
644 LongPressGestureDetector detector = LongPressGestureDetector::New();
645 detector.Attach(actor);
646 detector.DetectedSignal().Connect(&application, functor);
648 // LongPress in actor's area
649 TestGenerateLongPress(application, 50.0f, 10.0f);
650 TestEndLongPress(application, 50.0f, 10.0f);
651 DALI_TEST_EQUALS(true, data.functorCalled, TEST_LOCATION);
653 // Actor becomes invisible - actor should not receive the next long press
654 actor.SetProperty(Actor::Property::VISIBLE, false);
657 application.SendNotification();
658 application.Render();
660 // LongPress in the same area, shouldn't receive event
662 TestGenerateLongPress(application, 50.0f, 10.0f);
663 TestEndLongPress(application, 50.0f, 10.0f);
664 DALI_TEST_EQUALS(false, data.functorCalled, TEST_LOCATION);
668 int UtcDaliLongPressGestureSignalReceptionMultipleDetectorsOnActor(void)
670 TestApplication application;
672 Actor actor = Actor::New();
673 actor.SetProperty(Actor::Property::SIZE, Vector2(100.0f, 100.0f));
674 actor.SetProperty(Actor::Property::ANCHOR_POINT, AnchorPoint::TOP_LEFT);
675 application.GetScene().Add(actor);
678 application.SendNotification();
679 application.Render();
681 // Attach actor to one detector
682 SignalData firstData;
683 GestureReceivedFunctor firstFunctor(firstData);
684 LongPressGestureDetector firstDetector = LongPressGestureDetector::New();
685 firstDetector.Attach(actor);
686 firstDetector.DetectedSignal().Connect(&application, firstFunctor);
688 // Attach actor to another detector
689 SignalData secondData;
690 GestureReceivedFunctor secondFunctor(secondData);
691 LongPressGestureDetector secondDetector = LongPressGestureDetector::New();
692 secondDetector.Attach(actor);
693 secondDetector.DetectedSignal().Connect(&application, secondFunctor);
695 // LongPress in actor's area - both detector's functors should be called
696 TestGenerateLongPress(application, 50.0f, 10.0f);
697 DALI_TEST_EQUALS(true, firstData.functorCalled, TEST_LOCATION);
698 DALI_TEST_EQUALS(true, secondData.functorCalled, TEST_LOCATION);
702 int UtcDaliLongPressGestureSignalReceptionDifferentPossible(void)
704 TestApplication application;
706 Actor actor = Actor::New();
707 actor.SetProperty(Actor::Property::SIZE, Vector2(100.0f, 100.0f));
708 actor.SetProperty(Actor::Property::ANCHOR_POINT, AnchorPoint::TOP_LEFT);
709 application.GetScene().Add(actor);
712 application.SendNotification();
713 application.Render();
715 // Attach actor to detector
717 GestureReceivedFunctor functor(data);
718 LongPressGestureDetector detector = LongPressGestureDetector::New();
719 detector.Attach(actor);
720 detector.DetectedSignal().Connect(&application, functor);
722 // LongPress possible in actor's area.
723 TestStartLongPress(application, 50.0f, 10.0f);
724 DALI_TEST_EQUALS(false, data.functorCalled, TEST_LOCATION);
726 // Move actor somewhere else
727 actor.SetProperty(Actor::Property::POSITION, Vector2(100.0f, 100.0f));
730 application.SendNotification();
731 application.Render();
733 // Emit Started event, we should not receive the long press.
734 TestTriggerLongPress(application);
735 TestGenerateLongPress(application, 50.0f, 10.0f);
736 DALI_TEST_EQUALS(false, data.functorCalled, TEST_LOCATION);
738 // LongPress possible in empty area.
739 TestStartLongPress(application, 50.0f, 10.0f);
740 DALI_TEST_EQUALS(false, data.functorCalled, TEST_LOCATION);
742 // Move actor in to the long press position.
743 actor.SetProperty(Actor::Property::POSITION, Vector2(0.0f, 0.0f));
746 application.SendNotification();
747 application.Render();
749 // Emit STARTED event, we should not receive the long press.
750 TestTriggerLongPress(application);
751 TestEndLongPress(application, 50.0f, 10.0f);
752 DALI_TEST_EQUALS(false, data.functorCalled, TEST_LOCATION);
754 // Normal long press in actor's area for completeness.
755 TestGenerateLongPress(application, 50.0f, 10.0f);
756 TestEndLongPress(application, 50.0f, 10.0f);
757 DALI_TEST_EQUALS(true, data.functorCalled, TEST_LOCATION);
761 int UtcDaliLongPressGesturePossibleCancelled(void)
763 TestApplication application;
765 Actor actor = Actor::New();
766 actor.SetProperty(Actor::Property::SIZE, Vector2(100.0f, 100.0f));
767 actor.SetProperty(Actor::Property::ANCHOR_POINT, AnchorPoint::TOP_LEFT);
768 application.GetScene().Add(actor);
771 application.SendNotification();
772 application.Render();
774 // Attach actor to detector
776 GestureReceivedFunctor functor(data);
777 LongPressGestureDetector detector = LongPressGestureDetector::New();
778 detector.Attach(actor);
779 detector.DetectedSignal().Connect(&application, functor);
781 // Send a possible followed by a cancel, we should not be signalled
782 TestStartLongPress(application, 50.0f, 10.0f);
783 DALI_TEST_EQUALS(false, data.functorCalled, TEST_LOCATION);
784 TestMovePan(application, Vector2(50.0f, 10.0f));
785 DALI_TEST_EQUALS(false, data.functorCalled, TEST_LOCATION);
789 int UtcDaliLongPressGestureDetachAfterStarted(void)
791 TestApplication application;
793 Actor actor = Actor::New();
794 actor.SetProperty(Actor::Property::SIZE, Vector2(100.0f, 100.0f));
795 actor.SetProperty(Actor::Property::ANCHOR_POINT, AnchorPoint::TOP_LEFT);
796 application.GetScene().Add(actor);
799 application.SendNotification();
800 application.Render();
802 // Attach actor to detector
804 GestureReceivedFunctor functor(data);
805 LongPressGestureDetector detector = LongPressGestureDetector::New();
806 detector.Attach(actor);
807 detector.DetectedSignal().Connect(&application, functor);
809 // Emit initial signal
810 TestGenerateLongPress(application, 50.0f, 10.0f);
811 DALI_TEST_EQUALS(true, data.functorCalled, TEST_LOCATION);
815 detector.Detach(actor);
817 // Emit FINISHED, no signal
818 TestEndLongPress(application, 50.0f, 10.0f);
819 DALI_TEST_EQUALS(false, data.functorCalled, TEST_LOCATION);
823 int UtcDaliLongPressGestureActorUnstaged(void)
825 TestApplication application;
827 Actor actor = Actor::New();
828 actor.SetProperty(Actor::Property::SIZE, Vector2(100.0f, 100.0f));
829 actor.SetProperty(Actor::Property::ANCHOR_POINT, AnchorPoint::TOP_LEFT);
830 application.GetScene().Add(actor);
833 application.SendNotification();
834 application.Render();
836 // State to remove actor in.
837 GestureState stateToUnstage(GestureState::STARTED);
839 // Attach actor to detector
841 UnstageActorFunctor functor(data, stateToUnstage, application.GetScene());
842 LongPressGestureDetector detector = LongPressGestureDetector::New();
843 detector.Attach(actor);
844 detector.DetectedSignal().Connect(&application, functor);
847 TestGenerateLongPress(application, 50.0f, 10.0f);
848 DALI_TEST_EQUALS(true, data.functorCalled, TEST_LOCATION);
850 TestEndLongPress(application, 50.0f, 10.0f);
851 DALI_TEST_EQUALS(false, data.functorCalled, TEST_LOCATION);
854 application.SendNotification();
855 application.Render();
857 // Re-add actor to stage
858 application.GetScene().Add(actor);
861 application.SendNotification();
862 application.Render();
864 // Change state to GestureState::CONTINUING to remove
865 stateToUnstage = GestureState::FINISHED;
868 TestGenerateLongPress(application, 50.0f, 10.0f);
869 DALI_TEST_EQUALS(true, data.functorCalled, TEST_LOCATION);
871 TestEndLongPress(application, 50.0f, 10.0f);
872 DALI_TEST_EQUALS(true, data.functorCalled, TEST_LOCATION);
873 tet_result(TET_PASS); // If we get here then we have handled actor stage removal gracefully.
877 int UtcDaliLongPressGestureActorStagedAndDestroyed(void)
879 TestApplication application;
881 Actor actor = Actor::New();
882 actor.SetProperty(Actor::Property::SIZE, Vector2(100.0f, 100.0f));
883 actor.SetProperty(Actor::Property::ANCHOR_POINT, AnchorPoint::TOP_LEFT);
884 application.GetScene().Add(actor);
886 // Create and add a second actor so that GestureDetector destruction does not come into play.
887 Actor dummyActor(Actor::New());
888 dummyActor.SetProperty(Actor::Property::SIZE, Vector2(100.0f, 100.0f));
889 dummyActor.SetProperty(Actor::Property::POSITION, Vector2(100.0f, 100.0f));
890 dummyActor.SetProperty(Actor::Property::ANCHOR_POINT, AnchorPoint::TOP_LEFT);
891 application.GetScene().Add(dummyActor);
894 application.SendNotification();
895 application.Render();
897 // State to remove actor in.
898 GestureState stateToUnstage(GestureState::STARTED);
900 // Attach actor to detector
902 UnstageActorFunctor functor(data, stateToUnstage, application.GetScene());
903 LongPressGestureDetector detector = LongPressGestureDetector::New();
904 detector.Attach(actor);
905 detector.Attach(dummyActor);
906 detector.DetectedSignal().Connect(&application, functor);
908 // Here we are testing a STARTED actor which is removed in the STARTED callback, but then added back
909 // before we get a finished state. As we were removed from the stage, even if we're at the same
910 // position, we should still not be signalled.
913 TestGenerateLongPress(application, 50.0f, 10.0f);
914 DALI_TEST_EQUALS(true, data.functorCalled, TEST_LOCATION);
918 application.SendNotification();
919 application.Render();
921 // Re add to the stage, we should not be signalled
922 application.GetScene().Add(actor);
925 application.SendNotification();
926 application.Render();
928 // Continue signal emission
929 TestEndLongPress(application, 50.0f, 10.0f);
930 DALI_TEST_EQUALS(false, data.functorCalled, TEST_LOCATION);
933 // Here we delete an actor in started, we should not receive any subsequent signalling.
936 TestGenerateLongPress(application, 50.0f, 10.0f);
937 DALI_TEST_EQUALS(true, data.functorCalled, TEST_LOCATION);
941 application.SendNotification();
942 application.Render();
944 // Delete actor as well
948 application.SendNotification();
949 application.Render();
951 // Continue signal emission
952 TestEndLongPress(application, 50.0f, 10.0f);
953 DALI_TEST_EQUALS(false, data.functorCalled, TEST_LOCATION);
957 int UtcDaliLongPressGestureLayerConsumesTouch(void)
959 TestApplication application;
961 Actor actor = Actor::New();
962 actor.SetProperty(Actor::Property::SIZE, Vector2(100.0f, 100.0f));
963 actor.SetProperty(Actor::Property::ANCHOR_POINT, AnchorPoint::TOP_LEFT);
964 application.GetScene().Add(actor);
968 GestureReceivedFunctor functor(data);
969 LongPressGestureDetector detector = LongPressGestureDetector::New();
970 detector.Attach(actor);
971 detector.DetectedSignal().Connect(&application, functor);
973 // Add a layer to overlap the actor
974 Layer layer = Layer::New();
975 layer.SetProperty(Actor::Property::SIZE, Vector2(100.0f, 100.0f));
976 layer.SetProperty(Actor::Property::ANCHOR_POINT, AnchorPoint::TOP_LEFT);
977 application.GetScene().Add(layer);
981 application.SendNotification();
982 application.Render();
984 // Emit signals, should receive
985 TestGenerateLongPress(application, 50.0f, 50.0f);
986 TestEndLongPress(application, 50.0f, 50.0f);
987 DALI_TEST_EQUALS(true, data.functorCalled, TEST_LOCATION);
990 // Set layer to consume all touch
991 layer.SetProperty(Layer::Property::CONSUMES_TOUCH, true);
994 application.SendNotification();
995 application.Render();
997 // Emit the same signals again, should not receive
998 TestGenerateLongPress(application, 50.0f, 50.0f);
999 TestEndLongPress(application, 50.0f, 50.0f);
1000 DALI_TEST_EQUALS(false, data.functorCalled, TEST_LOCATION);
1006 int UtcDaliLongPressGestureSetMinimumHoldingTime(void)
1008 TestApplication application;
1010 const uint32_t kMinumumHolding1 = 5000;
1011 const uint32_t kMinumumHolding2 = 3000;
1013 Integration::SetLongPressMinimumHoldingTime(kMinumumHolding1);
1015 Actor actor = Actor::New();
1016 actor.SetProperty(Actor::Property::SIZE, Vector2(100.0f, 100.0f));
1017 actor.SetProperty(Actor::Property::ANCHOR_POINT, AnchorPoint::TOP_LEFT);
1018 application.GetScene().Add(actor);
1020 // Render and notify
1021 application.SendNotification();
1022 application.Render();
1025 GestureReceivedFunctor functor(data);
1027 LongPressGestureDetector detector = LongPressGestureDetector::New();
1028 detector.Attach(actor);
1029 detector.DetectedSignal().Connect(&application, functor);
1031 DALI_TEST_EQUALS(DevelLongPressGestureDetector::GetMinimumHoldingTime(detector), kMinumumHolding1, TEST_LOCATION);
1033 Integration::SetLongPressMinimumHoldingTime(kMinumumHolding2);
1034 DALI_TEST_EQUALS(DevelLongPressGestureDetector::GetMinimumHoldingTime(detector), kMinumumHolding2, TEST_LOCATION);
1039 int UtcDaliLongPressGestureDisableDetectionDuringLongPressN(void)
1041 // Crash occurred when gesture-recognizer was deleted internally during a signal when the attached actor was detached
1043 TestApplication application;
1045 Actor actor = Actor::New();
1046 actor.SetProperty(Actor::Property::SIZE, Vector2(100.0f, 100.0f));
1047 actor.SetProperty(Actor::Property::ANCHOR_POINT, AnchorPoint::TOP_LEFT);
1048 application.GetScene().Add(actor);
1051 LongPressGestureDetector detector = LongPressGestureDetector::New();
1052 bool functorCalled = false;
1053 detector.Attach(actor);
1054 detector.DetectedSignal().Connect(
1056 [&detector, &functorCalled](Actor actor, const LongPressGesture& gesture) {
1057 if(gesture.GetState() == GestureState::FINISHED)
1059 detector.Detach(actor);
1060 functorCalled = true;
1064 // Render and notify
1065 application.SendNotification();
1066 application.Render();
1068 // Try the gesture, should not crash
1071 TestGenerateLongPress(application, 50.0f, 10.0f);
1072 TestEndLongPress(application, 50.0f, 10.0f);
1074 DALI_TEST_CHECK(true); // No crash, test has passed
1075 DALI_TEST_EQUALS(functorCalled, true, TEST_LOCATION);
1079 DALI_TEST_CHECK(false); // If we crash, the test has failed
1085 int UtcDaliLongPressGestureWhenGesturePropargation(void)
1087 TestApplication application;
1089 Actor parentActor = Actor::New();
1090 parentActor.SetProperty(Actor::Property::SIZE, Vector2(100.0f, 100.0f));
1091 parentActor.SetProperty(Actor::Property::ANCHOR_POINT, AnchorPoint::TOP_LEFT);
1093 Actor childActor = Actor::New();
1094 childActor.SetProperty(Actor::Property::SIZE, Vector2(100.0f, 100.0f));
1095 childActor.SetProperty(Actor::Property::ANCHOR_POINT, AnchorPoint::TOP_LEFT);
1097 parentActor.Add(childActor);
1098 application.GetScene().Add(parentActor);
1100 // Render and notify
1101 application.SendNotification();
1102 application.Render();
1105 GestureReceivedFunctor pFunctor(pData);
1107 LongPressGestureDetector parentDetector = LongPressGestureDetector::New();
1108 parentDetector.Attach(parentActor);
1109 parentDetector.DetectedSignal().Connect(&application, pFunctor);
1112 GestureReceivedFunctor cFunctor(cData);
1114 LongPressGestureDetector childDetector = LongPressGestureDetector::New();
1115 childDetector.Attach(childActor);
1116 childDetector.DetectedSignal().Connect(&application, cFunctor);
1118 // Start gesture within the actor's area, we receive the gesture not parent actor but child actor.
1119 TestGenerateLongPress(application, 50.0f, 50.0f);
1120 TestEndLongPress(application, 50.0f, 50.0f);
1122 DALI_TEST_EQUALS(true, cData.functorCalled, TEST_LOCATION);
1123 DALI_TEST_EQUALS(false, pData.functorCalled, TEST_LOCATION);
1127 // If GesturePropargation is set, a gesture event is to pass over to the parent.
1128 Dali::DevelActor::SetNeedGesturePropagation(childActor, true);
1130 // So now the parent got the gesture event.
1131 TestGenerateLongPress(application, 50.0f, 50.0f);
1132 TestEndLongPress(application, 50.0f, 50.0f);
1133 DALI_TEST_EQUALS(true, cData.functorCalled, TEST_LOCATION);
1134 DALI_TEST_EQUALS(true, pData.functorCalled, TEST_LOCATION);
1141 int UtcDaliLongPressGestureSignalWithGeometryHittest(void)
1143 TestApplication application;
1144 application.GetScene().SetGeometryHittestEnabled(true);
1146 Actor actor = Actor::New();
1147 actor.SetProperty(Actor::Property::SIZE, Vector2(100.0f, 100.0f));
1148 actor.SetProperty(Actor::Property::ANCHOR_POINT, AnchorPoint::TOP_LEFT);
1149 application.GetScene().Add(actor);
1151 // Render and notify
1152 application.SendNotification();
1153 application.Render();
1156 GestureReceivedFunctor functor(data);
1158 LongPressGestureDetector detector = LongPressGestureDetector::New();
1159 detector.Attach(actor);
1160 detector.DetectedSignal().Connect(&application, functor);
1162 // Do a long press inside actor's area
1163 TestGenerateLongPress(application, 50.0f, 50.0f);
1164 DALI_TEST_EQUALS(true, data.functorCalled, TEST_LOCATION);
1165 DALI_TEST_EQUALS(1u, data.receivedGesture.GetNumberOfTouches(), TEST_LOCATION);
1166 DALI_TEST_EQUALS(Vector2(50.0f, 50.0f), data.receivedGesture.GetLocalPoint(), 0.1, TEST_LOCATION);
1167 TestEndLongPress(application, 50.0f, 50.0f);
1170 detector.DetachAll();
1172 // Ensure we are no longer signalled
1174 TestGenerateLongPress(application, 20.0f, 20.0f);
1175 DALI_TEST_EQUALS(false, data.functorCalled, TEST_LOCATION);
1176 TestEndLongPress(application, 50.0f, 50.0f);
1177 DALI_TEST_EQUALS(false, data.functorCalled, TEST_LOCATION);
1181 int UtcDaliLongPressGestureHandleEvent(void)
1183 TestApplication application;
1184 Integration::Scene scene = application.GetScene();
1185 RenderTaskList taskList = scene.GetRenderTaskList();
1186 Dali::RenderTask task = taskList.GetTask(0);
1188 Actor parentActor = Actor::New();
1189 parentActor.SetProperty(Actor::Property::SIZE, Vector2(100.0f, 100.0f));
1190 parentActor.SetProperty(Actor::Property::ANCHOR_POINT, AnchorPoint::TOP_LEFT);
1192 Actor childActor = Actor::New();
1193 childActor.SetProperty(Actor::Property::SIZE, Vector2(100.0f, 100.0f));
1194 childActor.SetProperty(Actor::Property::ANCHOR_POINT, AnchorPoint::TOP_LEFT);
1196 parentActor.Add(childActor);
1197 application.GetScene().Add(parentActor);
1199 // Render and notify
1200 application.SendNotification();
1201 application.Render();
1204 GestureReceivedFunctor pFunctor(pData);
1206 LongPressGestureDetector parentDetector = LongPressGestureDetector::New();
1207 parentDetector.DetectedSignal().Connect(&application, pFunctor);
1209 Integration::TouchEvent tp = GenerateSingleTouch(PointState::DOWN, Vector2(50.0f, 50.0f), 100);
1210 Internal::TouchEventPtr touchEventImpl(new Internal::TouchEvent(100));
1211 touchEventImpl->AddPoint(tp.GetPoint(0));
1212 touchEventImpl->SetRenderTask(task);
1213 Dali::TouchEvent touchEventHandle(touchEventImpl.Get());
1214 parentDetector.HandleEvent(parentActor, touchEventHandle);
1216 TestTriggerLongPress(application);
1218 tp = GenerateSingleTouch(PointState::UP, Vector2(50.0f, 50.0f), 150);
1219 touchEventImpl = new Internal::TouchEvent(150);
1220 touchEventImpl->AddPoint(tp.GetPoint(0));
1221 touchEventImpl->SetRenderTask(task);
1222 touchEventHandle = Dali::TouchEvent(touchEventImpl.Get());
1223 parentDetector.HandleEvent(parentActor, touchEventHandle);
1225 DALI_TEST_EQUALS(true, pData.functorCalled, TEST_LOCATION);