2 * Copyright (c) 2021 Samsung Electronics Co., Ltd.
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
8 * http://www.apache.org/licenses/LICENSE-2.0
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
18 #include <dali-test-suite-utils.h>
19 #include <dali/devel-api/actors/actor-devel.h>
20 #include <dali/integration-api/events/touch-event-integ.h>
21 #include <dali/integration-api/render-task-list-integ.h>
22 #include <dali/public-api/dali-core.h>
24 #include <test-touch-event-utils.h>
30 void utc_dali_tap_gesture_detector_startup(void)
32 test_return_value = TET_UNDEF;
35 void utc_dali_tap_gesture_detector_cleanup(void)
37 test_return_value = TET_PASS;
40 ///////////////////////////////////////////////////////////////////////////////
43 // Stores data that is populated in the callback and will be read by the TET cases
47 : functorCalled(false),
48 voidFunctorCalled(false)
54 functorCalled = false;
55 voidFunctorCalled = false;
57 receivedGesture.Reset();
63 bool voidFunctorCalled;
64 TapGesture receivedGesture;
68 // Functor that sets the data when called
69 struct GestureReceivedFunctor
71 GestureReceivedFunctor(SignalData& data)
76 void operator()(Actor actor, const TapGesture& tap)
78 signalData.functorCalled = true;
79 signalData.receivedGesture = tap;
80 signalData.tappedActor = actor;
85 signalData.voidFunctorCalled = true;
88 SignalData& signalData;
91 // Functor that removes the gestured actor from stage
92 struct UnstageActorFunctor : public GestureReceivedFunctor
94 UnstageActorFunctor(SignalData& data, Integration::Scene scene)
95 : GestureReceivedFunctor(data),
100 void operator()(Actor actor, const TapGesture& tap)
102 GestureReceivedFunctor::operator()(actor, tap);
106 Integration::Scene scene;
109 // Functor for receiving a touch event
110 struct TouchEventFunctor
112 bool operator()(Actor actor, const TouchEvent& touch)
115 unsigned int points = touch.GetPointCount();
118 tet_printf("Touch Point state = %d\n", touch.GetState(0));
126 ///////////////////////////////////////////////////////////////////////////////
128 // Positive test case for a method
129 int UtcDaliTapGestureDetectorConstructor(void)
131 TestApplication application;
133 TapGestureDetector detector;
134 DALI_TEST_CHECK(!detector);
138 int UtcDaliTapGestureDetectorCopyConstructorP(void)
140 TestApplication application;
142 TapGestureDetector detector = TapGestureDetector::New();
144 TapGestureDetector copy(detector);
145 DALI_TEST_CHECK(detector);
149 int UtcDaliTapGestureDetectorAssignmentOperatorP(void)
151 TestApplication application;
153 TapGestureDetector detector = TapGestureDetector::New();
156 TapGestureDetector assign;
158 DALI_TEST_CHECK(detector);
160 DALI_TEST_CHECK(detector == assign);
164 int UtcDaliTapGestureDetectorNew(void)
166 TestApplication application;
168 TapGestureDetector detector = TapGestureDetector::New();
169 DALI_TEST_CHECK(detector);
170 DALI_TEST_EQUALS(1u, detector.GetMinimumTapsRequired(), TEST_LOCATION);
171 DALI_TEST_EQUALS(1u, detector.GetMaximumTapsRequired(), TEST_LOCATION);
173 TapGestureDetector detector2 = TapGestureDetector::New(5u);
174 DALI_TEST_CHECK(detector2);
175 DALI_TEST_EQUALS(5u, detector2.GetMinimumTapsRequired(), TEST_LOCATION);
176 DALI_TEST_EQUALS(5u, detector2.GetMaximumTapsRequired(), TEST_LOCATION);
178 //Scoped test to test destructor
180 TapGestureDetector detector3 = TapGestureDetector::New();
181 DALI_TEST_CHECK(detector3);
184 // Attach an actor and emit a touch event on the actor to ensure complete line coverage
185 Actor actor = Actor::New();
186 actor.SetProperty(Actor::Property::SIZE, Vector2(100.0f, 100.0f));
187 actor.SetProperty(Actor::Property::ANCHOR_POINT, AnchorPoint::TOP_LEFT);
188 application.GetScene().Add(actor);
191 application.SendNotification();
192 application.Render();
194 detector.Attach(actor);
196 TouchEventFunctor touchFunctor;
197 actor.TouchedSignal().Connect(&application, touchFunctor);
199 Integration::TouchEvent touchEvent(1);
200 Integration::Point point;
201 point.SetDeviceId(1);
202 point.SetState(PointState::DOWN);
203 point.SetScreenPosition(Vector2(20.0f, 20.0f));
204 touchEvent.AddPoint(point);
205 application.ProcessEvent(touchEvent);
208 application.SendNotification();
209 application.Render();
214 int UtcDaliTapGestureDetectorDownCast(void)
216 TestApplication application;
217 tet_infoline("Testing Dali::TapGestureDetector::DownCast()");
219 TapGestureDetector detector = TapGestureDetector::New();
221 BaseHandle object(detector);
223 TapGestureDetector detector2 = TapGestureDetector::DownCast(object);
224 DALI_TEST_CHECK(detector2);
226 TapGestureDetector detector3 = DownCast<TapGestureDetector>(object);
227 DALI_TEST_CHECK(detector3);
229 BaseHandle unInitializedObject;
230 TapGestureDetector detector4 = TapGestureDetector::DownCast(unInitializedObject);
231 DALI_TEST_CHECK(!detector4);
233 TapGestureDetector detector5 = DownCast<TapGestureDetector>(unInitializedObject);
234 DALI_TEST_CHECK(!detector5);
236 GestureDetector detector6 = TapGestureDetector::New();
237 TapGestureDetector detector7 = TapGestureDetector::DownCast(detector6);
238 DALI_TEST_CHECK(detector7);
242 int UtcDaliTapGestureSetTapsRequiredMinMaxCheck(void)
244 TestApplication application;
246 // Attach an actor and change the required touches
248 Actor actor = Actor::New();
249 actor.SetProperty(Actor::Property::SIZE, Vector2(100.0f, 100.0f));
250 actor.SetProperty(Actor::Property::ANCHOR_POINT, AnchorPoint::TOP_LEFT);
251 application.GetScene().Add(actor);
254 application.SendNotification();
255 application.Render();
257 // Set the minimum to be greater than the maximum, should Assert
261 TapGestureDetector detector = TapGestureDetector::New();
262 detector.SetMinimumTapsRequired(7u);
263 detector.SetMaximumTapsRequired(3u);
264 detector.Attach(actor);
265 DALI_TEST_CHECK(false); // Should not get here
267 catch(DaliException& e)
269 DALI_TEST_CHECK(true);
275 int UtcDaliTapGestureGetTapsRequired(void)
277 TestApplication application;
279 TapGestureDetector detector = TapGestureDetector::New();
280 DALI_TEST_EQUALS(1u, detector.GetMinimumTapsRequired(), TEST_LOCATION);
281 DALI_TEST_EQUALS(1u, detector.GetMaximumTapsRequired(), TEST_LOCATION);
285 int UtcDaliTapGestureSignalReceptionNegative(void)
287 TestApplication application;
289 Actor actor = Actor::New();
290 actor.SetProperty(Actor::Property::SIZE, Vector2(100.0f, 100.0f));
291 actor.SetProperty(Actor::Property::ANCHOR_POINT, AnchorPoint::TOP_LEFT);
292 application.GetScene().Add(actor);
295 application.SendNotification();
296 application.Render();
299 GestureReceivedFunctor functor(data);
301 TapGestureDetector detector = TapGestureDetector::New();
302 detector.Attach(actor);
303 detector.DetectedSignal().Connect(&application, functor);
305 // Do a tap outside actor's area
306 TestGenerateTap(application, 112.0f, 112.0f, 100);
307 DALI_TEST_EQUALS(false, data.functorCalled, TEST_LOCATION);
311 int UtcDaliTapGestureSignalReceptionPositive(void)
313 TestApplication application;
315 Actor actor = Actor::New();
316 actor.SetProperty(Actor::Property::SIZE, Vector2(100.0f, 100.0f));
317 actor.SetProperty(Actor::Property::ANCHOR_POINT, AnchorPoint::TOP_LEFT);
318 application.GetScene().Add(actor);
321 application.SendNotification();
322 application.Render();
325 GestureReceivedFunctor functor(data);
327 TapGestureDetector detector = TapGestureDetector::New();
328 detector.Attach(actor);
329 detector.DetectedSignal().Connect(&application, functor);
331 // Do a tap inside actor's area
332 TestGenerateTap(application, 50.0f, 50.0f, 100);
333 DALI_TEST_EQUALS(true, data.functorCalled, TEST_LOCATION);
334 DALI_TEST_EQUALS(1u, data.receivedGesture.GetNumberOfTaps(), TEST_LOCATION);
335 DALI_TEST_EQUALS(1u, data.receivedGesture.GetNumberOfTouches(), TEST_LOCATION);
336 DALI_TEST_EQUALS(Vector2(50.0f, 50.0f), data.receivedGesture.GetLocalPoint(), 0.1, TEST_LOCATION);
340 int UtcDaliTapGestureSignalReceptionDetach(void)
342 TestApplication application;
344 Actor actor = Actor::New();
345 actor.SetProperty(Actor::Property::SIZE, Vector2(100.0f, 100.0f));
346 actor.SetProperty(Actor::Property::ANCHOR_POINT, AnchorPoint::TOP_LEFT);
347 application.GetScene().Add(actor);
350 application.SendNotification();
351 application.Render();
354 GestureReceivedFunctor functor(data);
356 TapGestureDetector detector = TapGestureDetector::New();
357 detector.Attach(actor);
358 detector.DetectedSignal().Connect(&application, functor);
360 // Start tap within the actor's area
361 TestGenerateTap(application, 20.0f, 20.0f, 100);
362 DALI_TEST_EQUALS(true, data.functorCalled, TEST_LOCATION);
363 DALI_TEST_EQUALS(1u, data.receivedGesture.GetNumberOfTaps(), TEST_LOCATION);
364 DALI_TEST_EQUALS(1u, data.receivedGesture.GetNumberOfTouches(), TEST_LOCATION);
365 DALI_TEST_EQUALS(Vector2(20.0f, 20.0f), data.receivedGesture.GetLocalPoint(), 0.1, TEST_LOCATION);
367 // repeat the tap within the actor's area - we should still receive the signal
369 TestGenerateTap(application, 50.0f, 50.0f, 700);
370 DALI_TEST_EQUALS(true, data.functorCalled, TEST_LOCATION);
371 DALI_TEST_EQUALS(1u, data.receivedGesture.GetNumberOfTaps(), TEST_LOCATION);
372 DALI_TEST_EQUALS(1u, data.receivedGesture.GetNumberOfTouches(), TEST_LOCATION);
373 DALI_TEST_EQUALS(Vector2(50.0f, 50.0f), data.receivedGesture.GetLocalPoint(), 0.1, TEST_LOCATION);
376 detector.DetachAll();
378 // Ensure we are no longer signalled
380 TestGenerateTap(application, 20.0f, 20.0f, 1300);
381 DALI_TEST_EQUALS(false, data.functorCalled, TEST_LOCATION);
382 TestGenerateTap(application, 50.0f, 50.0f, 1900);
383 DALI_TEST_EQUALS(false, data.functorCalled, TEST_LOCATION);
387 int UtcDaliTapGestureSignalReceptionActorDestroyedWhileTapping(void)
389 TestApplication application;
392 GestureReceivedFunctor functor(data);
394 TapGestureDetector detector = TapGestureDetector::New();
395 detector.DetectedSignal().Connect(&application, functor);
397 // Actor lifetime is scoped
399 Actor actor = Actor::New();
400 actor.SetProperty(Actor::Property::SIZE, Vector2(100.0f, 100.0f));
401 actor.SetProperty(Actor::Property::ANCHOR_POINT, AnchorPoint::TOP_LEFT);
402 application.GetScene().Add(actor);
405 application.SendNotification();
406 application.Render();
408 detector.Attach(actor);
410 // Start tap within the actor's area
411 TestGenerateTap(application, 20.0f, 20.0f, 100);
412 DALI_TEST_EQUALS(true, data.functorCalled, TEST_LOCATION);
414 // Remove the actor from stage and reset the data
415 application.GetScene().Remove(actor);
418 application.SendNotification();
419 application.Render();
422 // Actor should now have been destroyed
425 TestGenerateTap(application, 20.0f, 20.0f, 700);
426 DALI_TEST_EQUALS(false, data.functorCalled, TEST_LOCATION);
430 int UtcDaliTapGestureSignalReceptionRotatedActor(void)
432 TestApplication application;
434 Actor actor = Actor::New();
435 actor.SetProperty(Actor::Property::SIZE, Vector2(100.0f, 100.0f));
436 actor.SetProperty(Actor::Property::ORIENTATION, Quaternion(Dali::Degree(90.0f), Vector3::ZAXIS));
437 application.GetScene().Add(actor);
440 application.SendNotification();
441 application.Render();
444 GestureReceivedFunctor functor(data);
446 TapGestureDetector detector = TapGestureDetector::New();
447 detector.Attach(actor);
448 detector.DetectedSignal().Connect(&application, functor);
450 // Do tap, only check finished value
451 TestGenerateTap(application, 5.0f, 5.0f, 100);
452 DALI_TEST_EQUALS(true, data.functorCalled, TEST_LOCATION);
453 DALI_TEST_EQUALS(1u, data.receivedGesture.GetNumberOfTaps(), TEST_LOCATION);
454 DALI_TEST_EQUALS(1u, data.receivedGesture.GetNumberOfTouches(), TEST_LOCATION);
455 DALI_TEST_EQUALS(Vector2(5.0f, 5.0f), data.receivedGesture.GetScreenPoint(), 0.1, TEST_LOCATION);
457 // Rotate actor again and render
458 actor.SetProperty(Actor::Property::ORIENTATION, Quaternion(Dali::Degree(180.0f), Vector3::ZAXIS));
459 application.SendNotification();
460 application.Render();
462 // Do tap, should still receive event
464 TestGenerateTap(application, 5.0f, 5.0f, 700);
465 DALI_TEST_EQUALS(true, data.functorCalled, TEST_LOCATION);
466 DALI_TEST_EQUALS(1u, data.receivedGesture.GetNumberOfTaps(), TEST_LOCATION);
467 DALI_TEST_EQUALS(1u, data.receivedGesture.GetNumberOfTouches(), TEST_LOCATION);
468 DALI_TEST_EQUALS(Vector2(5.0f, 5.0f), data.receivedGesture.GetScreenPoint(), 0.1, TEST_LOCATION);
470 // Rotate actor again and render
471 actor.SetProperty(Actor::Property::ORIENTATION, Quaternion(Dali::Degree(90.0f), Vector3::YAXIS));
472 application.SendNotification();
473 application.Render();
475 // Do tap, inside the actor's area (area if it is not rotated), Should not receive the event
477 TestGenerateTap(application, 70.0f, 70.0f, 1300);
478 DALI_TEST_EQUALS(false, data.functorCalled, TEST_LOCATION);
482 int UtcDaliTapGestureSignalReceptionChildHit(void)
484 TestApplication application;
486 Actor parent = Actor::New();
487 parent.SetProperty(Actor::Property::SIZE, Vector2(100.0f, 100.0f));
488 parent.SetProperty(Actor::Property::ANCHOR_POINT, AnchorPoint::TOP_LEFT);
489 application.GetScene().Add(parent);
491 // Set child to completely cover parent.
492 // Change rotation of child to be different from parent so that we can check if our local coordinate
493 // conversion of the parent actor is correct.
494 Actor child = Actor::New();
495 child.SetProperty(Actor::Property::SIZE, Vector2(100.0f, 100.0f));
496 child.SetProperty(Actor::Property::ANCHOR_POINT, AnchorPoint::CENTER);
497 child.SetProperty(Actor::Property::PARENT_ORIGIN, ParentOrigin::CENTER);
498 child.SetProperty(Actor::Property::ORIENTATION, Quaternion(Dali::Degree(90.0f), Vector3::ZAXIS));
501 TouchEventFunctor touchFunctor;
502 child.TouchedSignal().Connect(&application, touchFunctor);
505 application.SendNotification();
506 application.Render();
509 GestureReceivedFunctor functor(data);
511 TapGestureDetector detector = TapGestureDetector::New();
512 detector.Attach(parent);
513 detector.DetectedSignal().Connect(&application, functor);
515 // Do tap - hits child area but parent should still receive it
516 TestGenerateTap(application, 50.0f, 50.0f, 100);
517 DALI_TEST_EQUALS(true, data.functorCalled, TEST_LOCATION);
518 DALI_TEST_EQUALS(true, parent == data.tappedActor, TEST_LOCATION);
519 DALI_TEST_EQUALS(Vector2(50.0f, 50.0f), data.receivedGesture.GetScreenPoint(), 0.01f, TEST_LOCATION);
521 // Attach child and generate same touch points
522 // (Also proves that you can detach and then re-attach another actor)
523 detector.Attach(child);
524 detector.Detach(parent);
526 // Do an entire tap, only check finished value
528 TestGenerateTap(application, 51.0f, 51.0f, 700);
529 DALI_TEST_EQUALS(true, data.functorCalled, TEST_LOCATION);
530 DALI_TEST_EQUALS(true, child == data.tappedActor, TEST_LOCATION);
531 DALI_TEST_EQUALS(Vector2(51.0f, 51.0f), data.receivedGesture.GetScreenPoint(), 0.01f, TEST_LOCATION);
535 int UtcDaliTapGestureSignalReceptionAttachDetachMany(void)
537 TestApplication application;
539 Actor first = Actor::New();
540 first.SetProperty(Actor::Property::SIZE, Vector2(100.0f, 100.0f));
541 first.SetProperty(Actor::Property::ANCHOR_POINT, AnchorPoint::TOP_LEFT);
542 application.GetScene().Add(first);
544 Actor second = Actor::New();
545 second.SetProperty(Actor::Property::SIZE, Vector2(100.0f, 100.0f));
546 second.SetProperty(Actor::Property::POSITION_X, 100.0f);
547 second.SetProperty(Actor::Property::ANCHOR_POINT, AnchorPoint::TOP_LEFT);
548 application.GetScene().Add(second);
551 application.SendNotification();
552 application.Render();
555 GestureReceivedFunctor functor(data);
557 TapGestureDetector detector = TapGestureDetector::New();
558 detector.Attach(first);
559 detector.Attach(second);
560 detector.DetectedSignal().Connect(&application, functor);
562 // Tap within second actor's area
563 TestGenerateTap(application, 120.0f, 10.0f, 100);
564 DALI_TEST_EQUALS(true, data.functorCalled, TEST_LOCATION);
565 DALI_TEST_EQUALS(true, second == data.tappedActor, TEST_LOCATION);
567 // Tap within first actor's area
569 TestGenerateTap(application, 20.0f, 10.0f, 700);
570 DALI_TEST_EQUALS(true, data.functorCalled, TEST_LOCATION);
571 DALI_TEST_EQUALS(true, first == data.tappedActor, TEST_LOCATION);
573 // Detach the second actor
574 detector.Detach(second);
576 // second actor shouldn't receive event
578 TestGenerateTap(application, 120.0f, 10.0f, 1300);
579 DALI_TEST_EQUALS(false, data.functorCalled, TEST_LOCATION);
581 // first actor should continue receiving event
583 TestGenerateTap(application, 20.0f, 10.0f, 1900);
584 DALI_TEST_EQUALS(true, data.functorCalled, TEST_LOCATION);
588 int UtcDaliTapGestureSignalReceptionActorBecomesUntouchable(void)
590 TestApplication application;
592 Actor actor = Actor::New();
593 actor.SetProperty(Actor::Property::SIZE, Vector2(100.0f, 100.0f));
594 actor.SetProperty(Actor::Property::ANCHOR_POINT, AnchorPoint::TOP_LEFT);
595 application.GetScene().Add(actor);
598 application.SendNotification();
599 application.Render();
602 GestureReceivedFunctor functor(data);
604 TapGestureDetector detector = TapGestureDetector::New();
605 detector.Attach(actor);
606 detector.DetectedSignal().Connect(&application, functor);
608 // Tap in actor's area
609 TestGenerateTap(application, 50.0f, 10.0f, 100);
610 DALI_TEST_EQUALS(true, data.functorCalled, TEST_LOCATION);
612 // Actor become invisible - actor should not receive the next pan
613 actor.SetProperty(Actor::Property::VISIBLE, false);
616 application.SendNotification();
617 application.Render();
619 // Tap in the same area, shouldn't receive event
621 TestGenerateTap(application, 50.0f, 10.0f, 700);
622 DALI_TEST_EQUALS(false, data.functorCalled, TEST_LOCATION);
626 int UtcDaliTapGestureSignalReceptionMultipleGestureDetectors(void)
628 TestApplication application;
630 Actor first = Actor::New();
631 first.SetProperty(Actor::Property::SIZE, Vector2(100.0f, 100.0f));
632 first.SetProperty(Actor::Property::ANCHOR_POINT, AnchorPoint::TOP_LEFT);
633 application.GetScene().Add(first);
635 Actor second = Actor::New();
636 second.SetProperty(Actor::Property::SIZE, Vector2(100.0f, 100.0f));
637 second.SetProperty(Actor::Property::ANCHOR_POINT, AnchorPoint::TOP_LEFT);
638 second.SetProperty(Actor::Property::POSITION_X, 100.0f);
642 application.SendNotification();
643 application.Render();
646 GestureReceivedFunctor functor(data);
648 TapGestureDetector firstDetector = TapGestureDetector::New();
649 firstDetector.Attach(first);
650 firstDetector.DetectedSignal().Connect(&application, functor);
652 // secondDetector is scoped
654 TapGestureDetector secondDetector = TapGestureDetector::New(2);
655 secondDetector.Attach(second);
656 secondDetector.DetectedSignal().Connect(&application, functor);
658 // Tap within second actor's area
659 TestGenerateTap(application, 150.0f, 10.0f, 100);
660 TestGenerateTap(application, 150.0f, 10.0f, 200);
662 DALI_TEST_EQUALS(true, data.functorCalled, TEST_LOCATION);
663 DALI_TEST_EQUALS(true, second == data.tappedActor, TEST_LOCATION);
665 // Tap continues as single touch gesture - we should not receive any gesture
667 TestGenerateTap(application, 150.0f, 10.0f, 800);
668 DALI_TEST_EQUALS(false, data.functorCalled, TEST_LOCATION);
670 // Single touch tap starts - first actor should be panned
672 TestGenerateTap(application, 50.0f, 10.0f, 1400);
673 DALI_TEST_EQUALS(true, data.functorCalled, TEST_LOCATION);
674 DALI_TEST_EQUALS(true, first == data.tappedActor, TEST_LOCATION);
676 // Tap changes to double-touch - we shouldn't receive event
679 TestGenerateTwoPointTap(application, 50.0f, 10.0f, 60.0f, 20.0f, 2000);
681 DALI_TEST_EQUALS(false, data.functorCalled, TEST_LOCATION);
687 int UtcDaliTapGestureSignalReceptionMultipleDetectorsOnActor(void)
689 TestApplication application;
691 Actor actor = Actor::New();
692 actor.SetProperty(Actor::Property::SIZE, Vector2(100.0f, 100.0f));
693 actor.SetProperty(Actor::Property::ANCHOR_POINT, AnchorPoint::TOP_LEFT);
694 application.GetScene().Add(actor);
697 application.SendNotification();
698 application.Render();
700 // Attach actor to one detector
701 SignalData firstData;
702 GestureReceivedFunctor firstFunctor(firstData);
703 TapGestureDetector firstDetector = TapGestureDetector::New();
704 firstDetector.Attach(actor);
705 firstDetector.DetectedSignal().Connect(&application, firstFunctor);
707 // Attach actor to another detector
708 SignalData secondData;
709 GestureReceivedFunctor secondFunctor(secondData);
710 TapGestureDetector secondDetector = TapGestureDetector::New();
711 secondDetector.Attach(actor);
712 secondDetector.DetectedSignal().Connect(&application, secondFunctor);
714 // Tap in actor's area - both detector's functors should be called
715 TestGenerateTap(application, 50.0f, 10.0f, 100);
716 DALI_TEST_EQUALS(true, firstData.functorCalled, TEST_LOCATION);
717 DALI_TEST_EQUALS(true, secondData.functorCalled, TEST_LOCATION);
721 int UtcDaliTapGestureSignalReceptionDifferentPossible(void)
723 TestApplication application;
725 Actor actor = Actor::New();
726 actor.SetProperty(Actor::Property::SIZE, Vector2(100.0f, 100.0f));
727 actor.SetProperty(Actor::Property::ANCHOR_POINT, AnchorPoint::TOP_LEFT);
728 application.GetScene().Add(actor);
731 application.SendNotification();
732 application.Render();
734 // Attach actor to detector
736 GestureReceivedFunctor functor(data);
737 TapGestureDetector detector = TapGestureDetector::New();
738 detector.Attach(actor);
739 detector.DetectedSignal().Connect(&application, functor);
741 // Gesture possible in actor's area.
742 TestStartLongPress(application, 50.0f, 10.0f, 100);
743 DALI_TEST_EQUALS(false, data.functorCalled, TEST_LOCATION);
745 // Move actor somewhere else
746 actor.SetProperty(Actor::Property::POSITION, Vector2(100.0f, 100.0f));
749 application.SendNotification();
750 application.Render();
752 // Emit STARTED event, we should not receive the tap.
753 TestEndPan(application, Vector2(50.0f, 10.0f), 120);
754 DALI_TEST_EQUALS(false, data.functorCalled, TEST_LOCATION);
756 // Tap possible in empty area.
757 TestStartLongPress(application, 50.0f, 10.0f, 700);
758 DALI_TEST_EQUALS(false, data.functorCalled, TEST_LOCATION);
760 // Move actor in to the tap position.
761 actor.SetProperty(Actor::Property::POSITION, Vector2(0.0f, 0.0f));
764 application.SendNotification();
765 application.Render();
767 // Emit STARTED event, we should not receive the tap.
768 TestEndPan(application, Vector2(50.0f, 10.0f), 720);
769 DALI_TEST_EQUALS(false, data.functorCalled, TEST_LOCATION);
771 // Normal tap in actor's area for completeness.
772 TestGenerateTap(application, 50.0f, 10.0f, 1300);
773 DALI_TEST_EQUALS(true, data.functorCalled, TEST_LOCATION);
777 int UtcDaliTapGestureActorUnstaged(void)
779 TestApplication application;
781 Actor actor = Actor::New();
782 actor.SetProperty(Actor::Property::SIZE, Vector2(100.0f, 100.0f));
783 actor.SetProperty(Actor::Property::ANCHOR_POINT, AnchorPoint::TOP_LEFT);
784 application.GetScene().Add(actor);
787 application.SendNotification();
788 application.Render();
790 // Attach actor to detector
792 UnstageActorFunctor functor(data, application.GetScene());
793 TapGestureDetector detector = TapGestureDetector::New();
794 detector.Attach(actor);
795 detector.DetectedSignal().Connect(&application, functor);
797 TestGenerateTap(application, 50.0f, 10.0f, 100);
798 DALI_TEST_EQUALS(true, data.functorCalled, TEST_LOCATION);
799 tet_result(TET_PASS); // If we get here, then the actor removal on signal handler was handled gracefully.
803 int UtcDaliTapGestureDetectorRemovedWhilePossible(void)
805 TestApplication application;
807 Actor actor = Actor::New();
808 actor.SetProperty(Actor::Property::SIZE, Vector2(100.0f, 100.0f));
809 actor.SetProperty(Actor::Property::ANCHOR_POINT, AnchorPoint::TOP_LEFT);
810 application.GetScene().Add(actor);
813 application.SendNotification();
814 application.Render();
816 // Attach actor to detector
818 GestureReceivedFunctor functor(data);
819 TapGestureDetector detector = TapGestureDetector::New();
820 detector.Attach(actor);
821 detector.DetectedSignal().Connect(&application, functor);
823 // Emit a possible - Down press, as emitted by long press function
824 TestStartLongPress(application, 50.0f, 10.0f, 100);
826 // Detach actor and send a STARTED state, no signal.
827 detector.DetachAll();
828 TestEndPan(application, Vector2(50.0f, 10.0f), 120);
829 DALI_TEST_EQUALS(false, data.functorCalled, TEST_LOCATION);
833 int UtcDaliTapGestureActorRemovedWhilePossible(void)
835 TestApplication application;
837 Actor actor = Actor::New();
838 actor.SetProperty(Actor::Property::SIZE, Vector2(100.0f, 100.0f));
839 actor.SetProperty(Actor::Property::ANCHOR_POINT, AnchorPoint::TOP_LEFT);
840 application.GetScene().Add(actor);
843 application.SendNotification();
844 application.Render();
846 // Attach actor to detector
848 GestureReceivedFunctor functor(data);
849 TapGestureDetector detector = TapGestureDetector::New();
850 detector.Attach(actor);
851 detector.DetectedSignal().Connect(&application, functor);
853 // Emit a possible - Down press, as emitted by long press function
854 TestStartLongPress(application, 50.0f, 10.0f, 100);
856 // Remove, render and delete actor
857 application.GetScene().Remove(actor);
858 application.SendNotification();
859 application.Render();
862 // Send a STARTED state, no signal - Up motion as provided by end pan function
863 TestEndPan(application, Vector2(50.0f, 10.0f), 120);
864 DALI_TEST_EQUALS(false, data.functorCalled, TEST_LOCATION);
868 int UtcDaliTapGestureLayerConsumesTouch(void)
870 TestApplication application;
872 Actor actor = Actor::New();
873 actor.SetProperty(Actor::Property::SIZE, Vector2(100.0f, 100.0f));
874 actor.SetProperty(Actor::Property::ANCHOR_POINT, AnchorPoint::TOP_LEFT);
875 application.GetScene().Add(actor);
879 GestureReceivedFunctor functor(data);
880 TapGestureDetector detector = TapGestureDetector::New();
881 detector.Attach(actor);
882 detector.DetectedSignal().Connect(&application, functor);
884 // Add a layer to overlap the actor
885 Layer layer = Layer::New();
886 layer.SetProperty(Actor::Property::SIZE, Vector2(100.0f, 100.0f));
887 layer.SetProperty(Actor::Property::ANCHOR_POINT, AnchorPoint::TOP_LEFT);
888 application.GetScene().Add(layer);
892 application.SendNotification();
893 application.Render();
895 // Emit signals, should receive
896 TestGenerateTap(application, 50.0f, 50.0f, 100);
897 DALI_TEST_EQUALS(true, data.functorCalled, TEST_LOCATION);
900 // Set layer to consume all touch
901 layer.SetProperty(Layer::Property::CONSUMES_TOUCH, true);
904 application.SendNotification();
905 application.Render();
907 // Emit the same signals again, should not receive
908 TestGenerateTap(application, 50.0f, 50.0f, 700);
909 DALI_TEST_EQUALS(false, data.functorCalled, TEST_LOCATION);
915 int UtcDaliTapGestureInterruptedWhenTouchConsumed(void)
917 TestApplication application;
919 Actor actor = Actor::New();
920 actor.SetProperty(Actor::Property::SIZE, Vector2(100.0f, 100.0f));
921 actor.SetProperty(Actor::Property::ANCHOR_POINT, AnchorPoint::TOP_LEFT);
922 application.GetScene().Add(actor);
924 bool consume = false;
925 TouchEventFunctorConsumeSetter touchFunctor(consume);
926 actor.TouchedSignal().Connect(&application, touchFunctor);
929 application.SendNotification();
930 application.Render();
933 GestureReceivedFunctor functor(data);
935 TapGestureDetector detector = TapGestureDetector::New();
936 detector.Attach(actor);
937 detector.DetectedSignal().Connect(&application, functor);
939 // Start gesture within the actor's area, we should receive the gesture as the touch is NOT being consumed
940 TestGenerateTap(application, 50.0f, 50.0f);
941 DALI_TEST_EQUALS(true, data.functorCalled, TEST_LOCATION);
944 // Another gesture in the same location, this time we will not receive it as touch is being consumed
946 TestGenerateTap(application, 50.0f, 50.0f);
947 DALI_TEST_EQUALS(false, data.functorCalled, TEST_LOCATION);
953 int UtcDaliTapGestureDisableDetectionDuringTapN(void)
955 // Crash sometimes occurred when gesture-recognizer was deleted internally during a signal when the attached actor was detached
957 TestApplication application;
959 Actor actor = Actor::New();
960 actor.SetProperty(Actor::Property::SIZE, Vector2(100.0f, 100.0f));
961 actor.SetProperty(Actor::Property::ANCHOR_POINT, AnchorPoint::TOP_LEFT);
962 application.GetScene().Add(actor);
965 TapGestureDetector detector = TapGestureDetector::New();
966 bool functorCalled = false;
967 detector.Attach(actor);
968 detector.DetectedSignal().Connect(
970 [&detector, &functorCalled](Actor actor, const TapGesture& gesture) {
971 detector.Detach(actor);
972 functorCalled = true;
976 application.SendNotification();
977 application.Render();
979 // Try the gesture, should not crash
982 TestGenerateTap(application, 50.0f, 10.0f);
984 DALI_TEST_CHECK(true); // No crash, test has passed
985 DALI_TEST_EQUALS(functorCalled, true, TEST_LOCATION);
989 DALI_TEST_CHECK(false); // If we crash, the test has failed
995 int UtcDaliTapGestureWhenGesturePropargation(void)
997 TestApplication application;
999 Actor parentActor = Actor::New();
1000 parentActor.SetProperty(Actor::Property::SIZE, Vector2(100.0f, 100.0f));
1001 parentActor.SetProperty(Actor::Property::ANCHOR_POINT, AnchorPoint::TOP_LEFT);
1003 Actor childActor = Actor::New();
1004 childActor.SetProperty(Actor::Property::SIZE, Vector2(100.0f, 100.0f));
1005 childActor.SetProperty(Actor::Property::ANCHOR_POINT, AnchorPoint::TOP_LEFT);
1007 parentActor.Add(childActor);
1008 application.GetScene().Add(parentActor);
1010 // Render and notify
1011 application.SendNotification();
1012 application.Render();
1015 GestureReceivedFunctor pFunctor(pData);
1017 TapGestureDetector parentDetector = TapGestureDetector::New();
1018 parentDetector.Attach(parentActor);
1019 parentDetector.DetectedSignal().Connect(&application, pFunctor);
1022 GestureReceivedFunctor cFunctor(cData);
1024 TapGestureDetector childDetector = TapGestureDetector::New();
1025 childDetector.Attach(childActor);
1026 childDetector.DetectedSignal().Connect(&application, cFunctor);
1028 // Start gesture within the actor's area, we receive the gesture not parent actor but child actor.
1029 TestGenerateTap(application, 50.0f, 50.0f, 100);
1030 DALI_TEST_EQUALS(true, cData.functorCalled, TEST_LOCATION);
1031 DALI_TEST_EQUALS(false, pData.functorCalled, TEST_LOCATION);
1035 // If GesturePropargation is set, a gesture event is delivered to the parent.
1036 Dali::DevelActor::SetNeedGesturePropagation(childActor, true);
1038 // So now the parent got the gesture event.
1039 TestGenerateTap(application, 50.0f, 50.0f, 700);
1040 DALI_TEST_EQUALS(true, cData.functorCalled, TEST_LOCATION);
1041 DALI_TEST_EQUALS(true, pData.functorCalled, TEST_LOCATION);