2 * Copyright (c) 2020 Samsung Electronics Co., Ltd.
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
8 * http://www.apache.org/licenses/LICENSE-2.0
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
18 #include <dali-test-suite-utils.h>
19 #include <dali/devel-api/events/long-press-gesture-detector-devel.h>
20 #include <dali/integration-api/events/touch-event-integ.h>
21 #include <dali/integration-api/input-options.h>
22 #include <dali/integration-api/render-task-list-integ.h>
23 #include <dali/public-api/dali-core.h>
25 #include <test-touch-event-utils.h>
31 void utc_dali_long_press_gesture_detector_startup(void)
33 test_return_value = TET_UNDEF;
36 void utc_dali_long_press_gesture_detector_cleanup(void)
38 test_return_value = TET_PASS;
41 ///////////////////////////////////////////////////////////////////////////////
44 // Stores data that is populated in the callback and will be read by the TET cases
48 : functorCalled(false),
49 voidFunctorCalled(false),
57 functorCalled = false;
58 voidFunctorCalled = false;
60 receivedGesture.Reset();
66 bool voidFunctorCalled;
67 LongPressGesture receivedGesture;
71 // Functor that sets the data when called
72 struct GestureReceivedFunctor
74 GestureReceivedFunctor(SignalData& data)
79 void operator()(Actor actor, const LongPressGesture& longPress)
81 signalData.functorCalled = true;
82 signalData.receivedGesture = longPress;
83 signalData.pressedActor = actor;
88 signalData.voidFunctorCalled = true;
91 SignalData& signalData;
94 // Functor that removes the gestured actor from stage
95 struct UnstageActorFunctor : public GestureReceivedFunctor
97 UnstageActorFunctor(SignalData& data, GestureState& stateToUnstage, Integration::Scene scene)
98 : GestureReceivedFunctor(data),
99 stateToUnstage(stateToUnstage),
104 void operator()(Actor actor, const LongPressGesture& longPress)
106 GestureReceivedFunctor::operator()(actor, longPress);
108 if(longPress.GetState() == stateToUnstage)
114 GestureState& stateToUnstage;
115 Integration::Scene scene;
118 // Functor for receiving a touch event
119 struct TouchEventFunctor
121 bool operator()(Actor actor, Dali::TouchEvent touch)
124 unsigned int points = touch.GetPointCount();
127 tet_printf("Touch Point state = %d\n", touch.GetState(0));
135 ///////////////////////////////////////////////////////////////////////////////
137 // Positive test case for a method
138 int UtcDaliLongPressGestureDetectorConstructorP(void)
140 TestApplication application;
142 LongPressGestureDetector detector;
143 DALI_TEST_CHECK(!detector);
147 int UtcDaliLongPressGestureDetectorCopyConstructorP(void)
149 TestApplication application;
151 LongPressGestureDetector detector = LongPressGestureDetector::New();
154 LongPressGestureDetector copy(detector);
155 DALI_TEST_CHECK(detector);
159 int UtcDaliLongPressGestureDetectorAssignmentOperatorP(void)
161 TestApplication application;
163 LongPressGestureDetector detector;
164 detector = LongPressGestureDetector::New();
167 LongPressGestureDetector copy;
169 DALI_TEST_CHECK(detector);
171 DALI_TEST_CHECK(detector == copy);
175 int UtcDaliLongPressGestureDetectorNew(void)
177 TestApplication application;
179 LongPressGestureDetector detector = LongPressGestureDetector::New();
180 DALI_TEST_CHECK(detector);
181 DALI_TEST_EQUALS(1u, detector.GetMinimumTouchesRequired(), TEST_LOCATION);
182 DALI_TEST_EQUALS(1u, detector.GetMaximumTouchesRequired(), TEST_LOCATION);
184 LongPressGestureDetector detector2 = LongPressGestureDetector::New(5u);
185 DALI_TEST_CHECK(detector2);
186 DALI_TEST_EQUALS(5u, detector2.GetMinimumTouchesRequired(), TEST_LOCATION);
187 DALI_TEST_EQUALS(5u, detector2.GetMaximumTouchesRequired(), TEST_LOCATION);
189 LongPressGestureDetector detector3 = LongPressGestureDetector::New(5u, 7u);
190 DALI_TEST_CHECK(detector2);
191 DALI_TEST_EQUALS(5u, detector3.GetMinimumTouchesRequired(), TEST_LOCATION);
192 DALI_TEST_EQUALS(7u, detector3.GetMaximumTouchesRequired(), TEST_LOCATION);
194 //Scoped test to test destructor
196 LongPressGestureDetector detector4 = LongPressGestureDetector::New();
197 DALI_TEST_CHECK(detector4);
200 // Attach an actor and emit a touch event on the actor to ensure complete line coverage
201 Actor actor = Actor::New();
202 actor.SetProperty(Actor::Property::SIZE, Vector2(100.0f, 100.0f));
203 actor.SetProperty(Actor::Property::ANCHOR_POINT, AnchorPoint::TOP_LEFT);
204 application.GetScene().Add(actor);
207 application.SendNotification();
208 application.Render();
210 detector.Attach(actor);
212 TouchEventFunctor touchFunctor;
213 actor.TouchedSignal().Connect(&application, touchFunctor);
215 Integration::TouchEvent touchEvent(1);
216 Integration::Point point;
217 point.SetDeviceId(1);
218 point.SetState(PointState::DOWN);
219 point.SetScreenPosition(Vector2(20.0f, 20.0f));
220 touchEvent.AddPoint(point);
221 application.ProcessEvent(touchEvent);
224 application.SendNotification();
225 application.Render();
230 int UtcDaliLongPressGestureDetectorDownCast(void)
232 TestApplication application;
233 tet_infoline("Testing Dali::LongPressGestureDetector::DownCast()");
235 LongPressGestureDetector detector = LongPressGestureDetector::New();
237 BaseHandle object(detector);
239 LongPressGestureDetector detector2 = LongPressGestureDetector::DownCast(object);
240 DALI_TEST_CHECK(detector2);
242 LongPressGestureDetector detector3 = DownCast<LongPressGestureDetector>(object);
243 DALI_TEST_CHECK(detector3);
245 BaseHandle unInitializedObject;
246 LongPressGestureDetector detector4 = LongPressGestureDetector::DownCast(unInitializedObject);
247 DALI_TEST_CHECK(!detector4);
249 LongPressGestureDetector detector5 = DownCast<LongPressGestureDetector>(unInitializedObject);
250 DALI_TEST_CHECK(!detector5);
252 GestureDetector detector6 = LongPressGestureDetector::New();
253 LongPressGestureDetector detector7 = LongPressGestureDetector::DownCast(detector6);
254 DALI_TEST_CHECK(detector7);
258 int UtcDaliLongPressGestureGetMinimumTouchesRequired(void)
260 TestApplication application;
262 LongPressGestureDetector detector = LongPressGestureDetector::New();
263 DALI_TEST_EQUALS(1u, detector.GetMinimumTouchesRequired(), TEST_LOCATION);
267 int UtcDaliLongPressGestureGetMaximumTouchesRequired(void)
269 TestApplication application;
271 LongPressGestureDetector detector = LongPressGestureDetector::New();
272 DALI_TEST_EQUALS(1u, detector.GetMaximumTouchesRequired(), TEST_LOCATION);
276 int UtcDaliLongPressGestureSignalReceptionNegative(void)
278 TestApplication application;
280 Actor actor = Actor::New();
281 actor.SetProperty(Actor::Property::SIZE, Vector2(100.0f, 100.0f));
282 actor.SetProperty(Actor::Property::ANCHOR_POINT, AnchorPoint::TOP_LEFT);
283 application.GetScene().Add(actor);
286 application.SendNotification();
287 application.Render();
290 GestureReceivedFunctor functor(data);
292 LongPressGestureDetector detector = LongPressGestureDetector::New();
293 detector.Attach(actor);
294 detector.DetectedSignal().Connect(&application, functor);
296 // Do a long press outside actor's area
297 TestGenerateLongPress(application, 112.0f, 112.0f);
298 TestEndLongPress(application, 112.0f, 112.0f);
300 DALI_TEST_EQUALS(false, data.functorCalled, TEST_LOCATION);
304 int UtcDaliLongPressGestureSignalReceptionPositive(void)
306 TestApplication application;
308 Actor actor = Actor::New();
309 actor.SetProperty(Actor::Property::SIZE, Vector2(100.0f, 100.0f));
310 actor.SetProperty(Actor::Property::ANCHOR_POINT, AnchorPoint::TOP_LEFT);
311 application.GetScene().Add(actor);
314 application.SendNotification();
315 application.Render();
318 GestureReceivedFunctor functor(data);
320 LongPressGestureDetector detector = LongPressGestureDetector::New();
321 detector.Attach(actor);
322 detector.DetectedSignal().Connect(&application, functor);
324 // Do a long press inside actor's area
325 TestGenerateLongPress(application, 50.0f, 50.0f);
326 DALI_TEST_EQUALS(true, data.functorCalled, TEST_LOCATION);
327 DALI_TEST_EQUALS(1u, data.receivedGesture.GetNumberOfTouches(), TEST_LOCATION);
328 DALI_TEST_EQUALS(Vector2(50.0f, 50.0f), data.receivedGesture.GetLocalPoint(), 0.1, TEST_LOCATION);
329 TestEndLongPress(application, 50.0f, 50.0f);
333 int UtcDaliLongPressGestureSignalReceptionDetach(void)
335 TestApplication application;
337 Actor actor = Actor::New();
338 actor.SetProperty(Actor::Property::SIZE, Vector2(100.0f, 100.0f));
339 actor.SetProperty(Actor::Property::ANCHOR_POINT, AnchorPoint::TOP_LEFT);
340 application.GetScene().Add(actor);
343 application.SendNotification();
344 application.Render();
347 GestureReceivedFunctor functor(data);
349 LongPressGestureDetector detector = LongPressGestureDetector::New();
350 detector.Attach(actor);
351 detector.DetectedSignal().Connect(&application, functor);
353 // Start long press within the actor's area
354 TestGenerateLongPress(application, 20.0f, 20.0f);
355 DALI_TEST_EQUALS(true, data.functorCalled, TEST_LOCATION);
356 DALI_TEST_EQUALS(1u, data.receivedGesture.GetNumberOfTouches(), TEST_LOCATION);
357 DALI_TEST_EQUALS(Vector2(20.0f, 20.0f), data.receivedGesture.GetLocalPoint(), 0.1, TEST_LOCATION);
358 TestEndLongPress(application, 20.0f, 20.0f);
360 // repeat the long press within the actor's area - we should still receive the signal
362 TestGenerateLongPress(application, 50.0f, 50.0f);
363 DALI_TEST_EQUALS(true, data.functorCalled, TEST_LOCATION);
364 DALI_TEST_EQUALS(1u, data.receivedGesture.GetNumberOfTouches(), TEST_LOCATION);
365 DALI_TEST_EQUALS(Vector2(50.0f, 50.0f), data.receivedGesture.GetLocalPoint(), 0.1, TEST_LOCATION);
366 TestEndLongPress(application, 50.0f, 50.0f);
369 detector.DetachAll();
371 // Ensure we are no longer signalled
373 TestGenerateLongPress(application, 20.0f, 20.0f);
374 DALI_TEST_EQUALS(false, data.functorCalled, TEST_LOCATION);
375 TestEndLongPress(application, 50.0f, 50.0f);
376 DALI_TEST_EQUALS(false, data.functorCalled, TEST_LOCATION);
380 int UtcDaliLongPressGestureSignalReceptionActorDestroyedDuringLongPress(void)
382 TestApplication application;
385 GestureReceivedFunctor functor(data);
387 LongPressGestureDetector detector = LongPressGestureDetector::New();
388 detector.DetectedSignal().Connect(&application, functor);
390 // Actor lifetime is scoped
392 Actor actor = Actor::New();
393 actor.SetProperty(Actor::Property::SIZE, Vector2(100.0f, 100.0f));
394 actor.SetProperty(Actor::Property::ANCHOR_POINT, AnchorPoint::TOP_LEFT);
395 application.GetScene().Add(actor);
398 application.SendNotification();
399 application.Render();
401 detector.Attach(actor);
403 // Start long press within the actor's area
404 TestGenerateLongPress(application, 20.0f, 20.0f);
405 DALI_TEST_EQUALS(true, data.functorCalled, TEST_LOCATION);
407 // Remove the actor from stage and reset the data
408 application.GetScene().Remove(actor);
411 application.SendNotification();
412 application.Render();
415 // Actor should now have been destroyed
418 TestEndLongPress(application, 20.0f, 20.0f);
419 DALI_TEST_EQUALS(false, data.functorCalled, TEST_LOCATION);
423 int UtcDaliLongPressGestureSignalReceptionRotatedActor(void)
425 TestApplication application;
427 Actor actor = Actor::New();
428 actor.SetProperty(Actor::Property::SIZE, Vector2(100.0f, 100.0f));
429 actor.SetProperty(Actor::Property::ORIENTATION, Quaternion(Dali::Degree(90.0f), Vector3::ZAXIS));
430 application.GetScene().Add(actor);
433 application.SendNotification();
434 application.Render();
437 GestureReceivedFunctor functor(data);
439 LongPressGestureDetector detector = LongPressGestureDetector::New();
440 detector.Attach(actor);
441 detector.DetectedSignal().Connect(&application, functor);
444 TestGenerateLongPress(application, 5.0f, 5.0f);
445 TestEndLongPress(application, 5.0f, 5.0f);
446 DALI_TEST_EQUALS(true, data.functorCalled, TEST_LOCATION);
447 DALI_TEST_EQUALS(1u, data.receivedGesture.GetNumberOfTouches(), TEST_LOCATION);
448 DALI_TEST_EQUALS(Vector2(5.0f, 5.0f), data.receivedGesture.GetScreenPoint(), 0.1, TEST_LOCATION);
450 // Rotate actor again and render
451 actor.SetProperty(Actor::Property::ORIENTATION, Quaternion(Dali::Degree(180.0f), Vector3::ZAXIS));
452 application.SendNotification();
453 application.Render();
455 // Do another long press, should still receive event
457 TestGenerateLongPress(application, 5.0f, 5.0f);
458 TestEndLongPress(application, 5.0f, 5.0f);
459 DALI_TEST_EQUALS(true, data.functorCalled, TEST_LOCATION);
460 DALI_TEST_EQUALS(1u, data.receivedGesture.GetNumberOfTouches(), TEST_LOCATION);
461 DALI_TEST_EQUALS(Vector2(5.0f, 5.0f), data.receivedGesture.GetScreenPoint(), 0.1, TEST_LOCATION);
463 // Rotate actor again and render
464 actor.SetProperty(Actor::Property::ORIENTATION, Quaternion(Dali::Degree(90.0f), Vector3::YAXIS));
465 application.SendNotification();
466 application.Render();
468 // Do a long press, inside where the actor used to be, Should not receive the event
470 TestGenerateLongPress(application, 70.0f, 70.0f);
471 TestEndLongPress(application, 70.0f, 70.0f);
472 DALI_TEST_EQUALS(false, data.functorCalled, TEST_LOCATION);
476 int UtcDaliLongPressGestureSignalReceptionChildHit(void)
478 TestApplication application;
480 Actor parent = Actor::New();
481 parent.SetProperty(Actor::Property::SIZE, Vector2(100.0f, 100.0f));
482 parent.SetProperty(Actor::Property::ANCHOR_POINT, AnchorPoint::TOP_LEFT);
483 application.GetScene().Add(parent);
485 // Set child to completely cover parent.
486 // Change rotation of child to be different from parent so that we can check if our local coordinate
487 // conversion of the parent actor is correct.
488 Actor child = Actor::New();
489 child.SetProperty(Actor::Property::SIZE, Vector2(100.0f, 100.0f));
490 child.SetProperty(Actor::Property::ANCHOR_POINT, AnchorPoint::CENTER);
491 child.SetProperty(Actor::Property::PARENT_ORIGIN, ParentOrigin::CENTER);
492 child.SetProperty(Actor::Property::ORIENTATION, Quaternion(Dali::Degree(90.0f), Vector3::ZAXIS));
496 application.SendNotification();
497 application.Render();
500 GestureReceivedFunctor functor(data);
502 LongPressGestureDetector detector = LongPressGestureDetector::New();
503 detector.Attach(parent);
504 detector.DetectedSignal().Connect(&application, functor);
506 // Do long press - hits child area but parent should still receive it
507 TestGenerateLongPress(application, 50.0f, 50.0f);
508 TestEndLongPress(application, 50.0f, 50.0f);
509 DALI_TEST_EQUALS(true, data.functorCalled, TEST_LOCATION);
510 DALI_TEST_EQUALS(true, parent == data.pressedActor, TEST_LOCATION);
511 DALI_TEST_EQUALS(Vector2(50.0f, 50.0f), data.receivedGesture.GetScreenPoint(), 0.01f, TEST_LOCATION);
513 // Attach child and generate same touch points
514 // (Also proves that you can detach and then re-attach another actor)
515 detector.Attach(child);
516 detector.Detach(parent);
518 // Do an entire long press, only check finished value
520 TestGenerateLongPress(application, 51.0f, 51.0f);
521 TestEndLongPress(application, 51.0f, 51.0f);
522 DALI_TEST_EQUALS(true, data.functorCalled, TEST_LOCATION);
523 DALI_TEST_EQUALS(true, child == data.pressedActor, TEST_LOCATION);
524 DALI_TEST_EQUALS(Vector2(51.0f, 51.0f), data.receivedGesture.GetScreenPoint(), 0.01f, TEST_LOCATION);
528 int UtcDaliLongPressGestureSignalReceptionAttachDetachMany(void)
530 TestApplication application;
532 Actor first = Actor::New();
533 first.SetProperty(Actor::Property::SIZE, Vector2(100.0f, 100.0f));
534 first.SetProperty(Actor::Property::ANCHOR_POINT, AnchorPoint::TOP_LEFT);
535 application.GetScene().Add(first);
537 Actor second = Actor::New();
538 second.SetProperty(Actor::Property::SIZE, Vector2(100.0f, 100.0f));
539 second.SetProperty(Actor::Property::POSITION_X, 100.0f);
540 second.SetProperty(Actor::Property::ANCHOR_POINT, AnchorPoint::TOP_LEFT);
541 application.GetScene().Add(second);
544 application.SendNotification();
545 application.Render();
548 GestureReceivedFunctor functor(data);
550 LongPressGestureDetector detector = LongPressGestureDetector::New();
551 detector.Attach(first);
552 detector.Attach(second);
553 detector.DetectedSignal().Connect(&application, functor);
555 // LongPress within second actor's area
556 TestGenerateLongPress(application, 120.0f, 10.0f);
557 TestEndLongPress(application, 120.0f, 10.0f);
558 DALI_TEST_EQUALS(true, data.functorCalled, TEST_LOCATION);
559 DALI_TEST_EQUALS(true, second == data.pressedActor, TEST_LOCATION);
561 // LongPress within first actor's area
563 TestGenerateLongPress(application, 20.0f, 10.0f);
564 TestEndLongPress(application, 20.0f, 10.0f);
565 DALI_TEST_EQUALS(true, data.functorCalled, TEST_LOCATION);
566 DALI_TEST_EQUALS(true, first == data.pressedActor, TEST_LOCATION);
568 // Detach the second actor
569 detector.Detach(second);
571 // second actor shouldn't receive event
573 TestGenerateLongPress(application, 120.0f, 10.0f);
574 TestEndLongPress(application, 120.0f, 10.0f);
575 DALI_TEST_EQUALS(false, data.functorCalled, TEST_LOCATION);
577 // first actor should continue receiving event
579 TestGenerateLongPress(application, 20.0f, 10.0f);
580 TestEndLongPress(application, 20.0f, 10.0f);
581 DALI_TEST_EQUALS(true, data.functorCalled, TEST_LOCATION);
585 int UtcDaliLongPressGestureSignalReceptionActorBecomesUntouchable(void)
587 TestApplication application;
589 Actor actor = Actor::New();
590 actor.SetProperty(Actor::Property::SIZE, Vector2(100.0f, 100.0f));
591 actor.SetProperty(Actor::Property::ANCHOR_POINT, AnchorPoint::TOP_LEFT);
592 application.GetScene().Add(actor);
595 application.SendNotification();
596 application.Render();
599 GestureReceivedFunctor functor(data);
601 LongPressGestureDetector detector = LongPressGestureDetector::New();
602 detector.Attach(actor);
603 detector.DetectedSignal().Connect(&application, functor);
605 // LongPress in actor's area
606 TestGenerateLongPress(application, 50.0f, 10.0f);
607 TestEndLongPress(application, 50.0f, 10.0f);
608 DALI_TEST_EQUALS(true, data.functorCalled, TEST_LOCATION);
610 // Actor becomes invisible - actor should not receive the next long press
611 actor.SetProperty(Actor::Property::VISIBLE, false);
614 application.SendNotification();
615 application.Render();
617 // LongPress in the same area, shouldn't receive event
619 TestGenerateLongPress(application, 50.0f, 10.0f);
620 TestEndLongPress(application, 50.0f, 10.0f);
621 DALI_TEST_EQUALS(false, data.functorCalled, TEST_LOCATION);
625 int UtcDaliLongPressGestureSignalReceptionMultipleDetectorsOnActor(void)
627 TestApplication application;
629 Actor actor = Actor::New();
630 actor.SetProperty(Actor::Property::SIZE, Vector2(100.0f, 100.0f));
631 actor.SetProperty(Actor::Property::ANCHOR_POINT, AnchorPoint::TOP_LEFT);
632 application.GetScene().Add(actor);
635 application.SendNotification();
636 application.Render();
638 // Attach actor to one detector
639 SignalData firstData;
640 GestureReceivedFunctor firstFunctor(firstData);
641 LongPressGestureDetector firstDetector = LongPressGestureDetector::New();
642 firstDetector.Attach(actor);
643 firstDetector.DetectedSignal().Connect(&application, firstFunctor);
645 // Attach actor to another detector
646 SignalData secondData;
647 GestureReceivedFunctor secondFunctor(secondData);
648 LongPressGestureDetector secondDetector = LongPressGestureDetector::New();
649 secondDetector.Attach(actor);
650 secondDetector.DetectedSignal().Connect(&application, secondFunctor);
652 // LongPress in actor's area - both detector's functors should be called
653 TestGenerateLongPress(application, 50.0f, 10.0f);
654 DALI_TEST_EQUALS(true, firstData.functorCalled, TEST_LOCATION);
655 DALI_TEST_EQUALS(true, secondData.functorCalled, TEST_LOCATION);
659 int UtcDaliLongPressGestureSignalReceptionDifferentPossible(void)
661 TestApplication application;
663 Actor actor = Actor::New();
664 actor.SetProperty(Actor::Property::SIZE, Vector2(100.0f, 100.0f));
665 actor.SetProperty(Actor::Property::ANCHOR_POINT, AnchorPoint::TOP_LEFT);
666 application.GetScene().Add(actor);
669 application.SendNotification();
670 application.Render();
672 // Attach actor to detector
674 GestureReceivedFunctor functor(data);
675 LongPressGestureDetector detector = LongPressGestureDetector::New();
676 detector.Attach(actor);
677 detector.DetectedSignal().Connect(&application, functor);
679 // LongPress possible in actor's area.
680 TestStartLongPress(application, 50.0f, 10.0f);
681 DALI_TEST_EQUALS(false, data.functorCalled, TEST_LOCATION);
683 // Move actor somewhere else
684 actor.SetProperty(Actor::Property::POSITION, Vector2(100.0f, 100.0f));
687 application.SendNotification();
688 application.Render();
690 // Emit Started event, we should not receive the long press.
691 TestTriggerLongPress(application);
692 TestGenerateLongPress(application, 50.0f, 10.0f);
693 DALI_TEST_EQUALS(false, data.functorCalled, TEST_LOCATION);
695 // LongPress possible in empty area.
696 TestStartLongPress(application, 50.0f, 10.0f);
697 DALI_TEST_EQUALS(false, data.functorCalled, TEST_LOCATION);
699 // Move actor in to the long press position.
700 actor.SetProperty(Actor::Property::POSITION, Vector2(0.0f, 0.0f));
703 application.SendNotification();
704 application.Render();
706 // Emit STARTED event, we should not receive the long press.
707 TestTriggerLongPress(application);
708 TestEndLongPress(application, 50.0f, 10.0f);
709 DALI_TEST_EQUALS(false, data.functorCalled, TEST_LOCATION);
711 // Normal long press in actor's area for completeness.
712 TestGenerateLongPress(application, 50.0f, 10.0f);
713 TestEndLongPress(application, 50.0f, 10.0f);
714 DALI_TEST_EQUALS(true, data.functorCalled, TEST_LOCATION);
718 int UtcDaliLongPressGesturePossibleCancelled(void)
720 TestApplication application;
722 Actor actor = Actor::New();
723 actor.SetProperty(Actor::Property::SIZE, Vector2(100.0f, 100.0f));
724 actor.SetProperty(Actor::Property::ANCHOR_POINT, AnchorPoint::TOP_LEFT);
725 application.GetScene().Add(actor);
728 application.SendNotification();
729 application.Render();
731 // Attach actor to detector
733 GestureReceivedFunctor functor(data);
734 LongPressGestureDetector detector = LongPressGestureDetector::New();
735 detector.Attach(actor);
736 detector.DetectedSignal().Connect(&application, functor);
738 // Send a possible followed by a cancel, we should not be signalled
739 TestStartLongPress(application, 50.0f, 10.0f);
740 DALI_TEST_EQUALS(false, data.functorCalled, TEST_LOCATION);
741 TestMovePan(application, Vector2(50.0f, 10.0f));
742 DALI_TEST_EQUALS(false, data.functorCalled, TEST_LOCATION);
746 int UtcDaliLongPressGestureDetachAfterStarted(void)
748 TestApplication application;
750 Actor actor = Actor::New();
751 actor.SetProperty(Actor::Property::SIZE, Vector2(100.0f, 100.0f));
752 actor.SetProperty(Actor::Property::ANCHOR_POINT, AnchorPoint::TOP_LEFT);
753 application.GetScene().Add(actor);
756 application.SendNotification();
757 application.Render();
759 // Attach actor to detector
761 GestureReceivedFunctor functor(data);
762 LongPressGestureDetector detector = LongPressGestureDetector::New();
763 detector.Attach(actor);
764 detector.DetectedSignal().Connect(&application, functor);
766 // Emit initial signal
767 TestGenerateLongPress(application, 50.0f, 10.0f);
768 DALI_TEST_EQUALS(true, data.functorCalled, TEST_LOCATION);
772 detector.Detach(actor);
774 // Emit FINISHED, no signal
775 TestEndLongPress(application, 50.0f, 10.0f);
776 DALI_TEST_EQUALS(false, data.functorCalled, TEST_LOCATION);
780 int UtcDaliLongPressGestureActorUnstaged(void)
782 TestApplication application;
784 Actor actor = Actor::New();
785 actor.SetProperty(Actor::Property::SIZE, Vector2(100.0f, 100.0f));
786 actor.SetProperty(Actor::Property::ANCHOR_POINT, AnchorPoint::TOP_LEFT);
787 application.GetScene().Add(actor);
790 application.SendNotification();
791 application.Render();
793 // State to remove actor in.
794 GestureState stateToUnstage(GestureState::STARTED);
796 // Attach actor to detector
798 UnstageActorFunctor functor(data, stateToUnstage, application.GetScene());
799 LongPressGestureDetector detector = LongPressGestureDetector::New();
800 detector.Attach(actor);
801 detector.DetectedSignal().Connect(&application, functor);
804 TestGenerateLongPress(application, 50.0f, 10.0f);
805 DALI_TEST_EQUALS(true, data.functorCalled, TEST_LOCATION);
807 TestEndLongPress(application, 50.0f, 10.0f);
808 DALI_TEST_EQUALS(false, data.functorCalled, TEST_LOCATION);
811 application.SendNotification();
812 application.Render();
814 // Re-add actor to stage
815 application.GetScene().Add(actor);
818 application.SendNotification();
819 application.Render();
821 // Change state to GestureState::CONTINUING to remove
822 stateToUnstage = GestureState::FINISHED;
825 TestGenerateLongPress(application, 50.0f, 10.0f);
826 DALI_TEST_EQUALS(true, data.functorCalled, TEST_LOCATION);
828 TestEndLongPress(application, 50.0f, 10.0f);
829 DALI_TEST_EQUALS(true, data.functorCalled, TEST_LOCATION);
830 tet_result(TET_PASS); // If we get here then we have handled actor stage removal gracefully.
834 int UtcDaliLongPressGestureActorStagedAndDestroyed(void)
836 TestApplication application;
838 Actor actor = Actor::New();
839 actor.SetProperty(Actor::Property::SIZE, Vector2(100.0f, 100.0f));
840 actor.SetProperty(Actor::Property::ANCHOR_POINT, AnchorPoint::TOP_LEFT);
841 application.GetScene().Add(actor);
843 // Create and add a second actor so that GestureDetector destruction does not come into play.
844 Actor dummyActor(Actor::New());
845 dummyActor.SetProperty(Actor::Property::SIZE, Vector2(100.0f, 100.0f));
846 dummyActor.SetProperty(Actor::Property::POSITION, Vector2(100.0f, 100.0f));
847 dummyActor.SetProperty(Actor::Property::ANCHOR_POINT, AnchorPoint::TOP_LEFT);
848 application.GetScene().Add(dummyActor);
851 application.SendNotification();
852 application.Render();
854 // State to remove actor in.
855 GestureState stateToUnstage(GestureState::STARTED);
857 // Attach actor to detector
859 UnstageActorFunctor functor(data, stateToUnstage, application.GetScene());
860 LongPressGestureDetector detector = LongPressGestureDetector::New();
861 detector.Attach(actor);
862 detector.Attach(dummyActor);
863 detector.DetectedSignal().Connect(&application, functor);
865 // Here we are testing a STARTED actor which is removed in the STARTED callback, but then added back
866 // before we get a finished state. As we were removed from the stage, even if we're at the same
867 // position, we should still not be signalled.
870 TestGenerateLongPress(application, 50.0f, 10.0f);
871 DALI_TEST_EQUALS(true, data.functorCalled, TEST_LOCATION);
875 application.SendNotification();
876 application.Render();
878 // Re add to the stage, we should not be signalled
879 application.GetScene().Add(actor);
882 application.SendNotification();
883 application.Render();
885 // Continue signal emission
886 TestEndLongPress(application, 50.0f, 10.0f);
887 DALI_TEST_EQUALS(false, data.functorCalled, TEST_LOCATION);
890 // Here we delete an actor in started, we should not receive any subsequent signalling.
893 TestGenerateLongPress(application, 50.0f, 10.0f);
894 DALI_TEST_EQUALS(true, data.functorCalled, TEST_LOCATION);
898 application.SendNotification();
899 application.Render();
901 // Delete actor as well
905 application.SendNotification();
906 application.Render();
908 // Continue signal emission
909 TestEndLongPress(application, 50.0f, 10.0f);
910 DALI_TEST_EQUALS(false, data.functorCalled, TEST_LOCATION);
914 int UtcDaliLongPressGestureLayerConsumesTouch(void)
916 TestApplication application;
918 Actor actor = Actor::New();
919 actor.SetProperty(Actor::Property::SIZE, Vector2(100.0f, 100.0f));
920 actor.SetProperty(Actor::Property::ANCHOR_POINT, AnchorPoint::TOP_LEFT);
921 application.GetScene().Add(actor);
925 GestureReceivedFunctor functor(data);
926 LongPressGestureDetector detector = LongPressGestureDetector::New();
927 detector.Attach(actor);
928 detector.DetectedSignal().Connect(&application, functor);
930 // Add a layer to overlap the actor
931 Layer layer = Layer::New();
932 layer.SetProperty(Actor::Property::SIZE, Vector2(100.0f, 100.0f));
933 layer.SetProperty(Actor::Property::ANCHOR_POINT, AnchorPoint::TOP_LEFT);
934 application.GetScene().Add(layer);
938 application.SendNotification();
939 application.Render();
941 // Emit signals, should receive
942 TestGenerateLongPress(application, 50.0f, 50.0f);
943 TestEndLongPress(application, 50.0f, 50.0f);
944 DALI_TEST_EQUALS(true, data.functorCalled, TEST_LOCATION);
947 // Set layer to consume all touch
948 layer.SetProperty(Layer::Property::CONSUMES_TOUCH, true);
951 application.SendNotification();
952 application.Render();
954 // Emit the same signals again, should not receive
955 TestGenerateLongPress(application, 50.0f, 50.0f);
956 TestEndLongPress(application, 50.0f, 50.0f);
957 DALI_TEST_EQUALS(false, data.functorCalled, TEST_LOCATION);
963 int UtcDaliLongPressGestureSetMinimumHoldingTime(void)
965 TestApplication application;
967 const uint32_t kMinumumHolding1 = 5000;
968 const uint32_t kMinumumHolding2 = 3000;
970 Integration::SetLongPressMinimumHoldingTime(kMinumumHolding1);
972 Actor actor = Actor::New();
973 actor.SetProperty(Actor::Property::SIZE, Vector2(100.0f, 100.0f));
974 actor.SetProperty(Actor::Property::ANCHOR_POINT, AnchorPoint::TOP_LEFT);
975 application.GetScene().Add(actor);
978 application.SendNotification();
979 application.Render();
982 GestureReceivedFunctor functor(data);
984 LongPressGestureDetector detector = LongPressGestureDetector::New();
985 detector.Attach(actor);
986 detector.DetectedSignal().Connect(&application, functor);
988 DALI_TEST_EQUALS(DevelLongPressGestureDetector::GetMinimumHoldingTime(detector), kMinumumHolding1, TEST_LOCATION);
990 Integration::SetLongPressMinimumHoldingTime(kMinumumHolding2);
991 DALI_TEST_EQUALS(DevelLongPressGestureDetector::GetMinimumHoldingTime(detector), kMinumumHolding2, TEST_LOCATION);
996 int UtcDaliLongPressGestureInterruptedWhenTouchConsumed(void)
998 TestApplication application;
1000 Actor actor = Actor::New();
1001 actor.SetProperty(Actor::Property::SIZE, Vector2(100.0f, 100.0f));
1002 actor.SetProperty(Actor::Property::ANCHOR_POINT, AnchorPoint::TOP_LEFT);
1003 application.GetScene().Add(actor);
1005 bool consume = false;
1006 TouchEventFunctorConsumeSetter touchFunctor(consume);
1007 actor.TouchedSignal().Connect(&application, touchFunctor);
1009 // Render and notify
1010 application.SendNotification();
1011 application.Render();
1014 GestureReceivedFunctor functor(data);
1016 LongPressGestureDetector detector = LongPressGestureDetector::New();
1017 detector.Attach(actor);
1018 detector.DetectedSignal().Connect(&application, functor);
1020 // Start gesture within the actor's area, we should receive the gesture as the touch is NOT being consumed
1021 TestGenerateLongPress(application, 50.0f, 50.0f);
1022 DALI_TEST_EQUALS(true, data.functorCalled, TEST_LOCATION);
1024 TestEndLongPress(application, 50.0f, 50.0f);
1025 DALI_TEST_EQUALS(true, data.functorCalled, TEST_LOCATION);
1028 // Another gesture in the same location, this time we will not receive it as touch is being consumed
1030 TestGenerateLongPress(application, 50.0f, 50.0f);
1031 DALI_TEST_EQUALS(false, data.functorCalled, TEST_LOCATION);
1033 TestEndLongPress(application, 50.0f, 50.0f);
1034 DALI_TEST_EQUALS(false, data.functorCalled, 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