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/integration-api/events/touch-event-integ.h>
20 #include <dali/integration-api/render-task-list-integ.h>
21 #include <dali/public-api/dali-core.h>
23 #include <test-touch-event-utils.h>
29 void utc_dali_tap_gesture_detector_startup(void)
31 test_return_value = TET_UNDEF;
34 void utc_dali_tap_gesture_detector_cleanup(void)
36 test_return_value = TET_PASS;
39 ///////////////////////////////////////////////////////////////////////////////
42 // Stores data that is populated in the callback and will be read by the TET cases
46 : functorCalled(false),
47 voidFunctorCalled(false)
53 functorCalled = false;
54 voidFunctorCalled = false;
56 receivedGesture.Reset();
62 bool voidFunctorCalled;
63 TapGesture receivedGesture;
67 // Functor that sets the data when called
68 struct GestureReceivedFunctor
70 GestureReceivedFunctor(SignalData& data)
75 void operator()(Actor actor, const TapGesture& tap)
77 signalData.functorCalled = true;
78 signalData.receivedGesture = tap;
79 signalData.tappedActor = actor;
84 signalData.voidFunctorCalled = true;
87 SignalData& signalData;
90 // Functor that removes the gestured actor from stage
91 struct UnstageActorFunctor : public GestureReceivedFunctor
93 UnstageActorFunctor(SignalData& data, Integration::Scene scene)
94 : GestureReceivedFunctor(data),
99 void operator()(Actor actor, const TapGesture& tap)
101 GestureReceivedFunctor::operator()(actor, tap);
105 Integration::Scene scene;
108 // Functor for receiving a touch event
109 struct TouchEventFunctor
111 bool operator()(Actor actor, const TouchEvent& touch)
114 unsigned int points = touch.GetPointCount();
117 tet_printf("Touch Point state = %d\n", touch.GetState(0));
125 ///////////////////////////////////////////////////////////////////////////////
127 // Positive test case for a method
128 int UtcDaliTapGestureDetectorConstructor(void)
130 TestApplication application;
132 TapGestureDetector detector;
133 DALI_TEST_CHECK(!detector);
137 int UtcDaliTapGestureDetectorCopyConstructorP(void)
139 TestApplication application;
141 TapGestureDetector detector = TapGestureDetector::New();
143 TapGestureDetector copy(detector);
144 DALI_TEST_CHECK(detector);
148 int UtcDaliTapGestureDetectorAssignmentOperatorP(void)
150 TestApplication application;
152 TapGestureDetector detector = TapGestureDetector::New();
155 TapGestureDetector assign;
157 DALI_TEST_CHECK(detector);
159 DALI_TEST_CHECK(detector == assign);
163 int UtcDaliTapGestureDetectorNew(void)
165 TestApplication application;
167 TapGestureDetector detector = TapGestureDetector::New();
168 DALI_TEST_CHECK(detector);
169 DALI_TEST_EQUALS(1u, detector.GetMinimumTapsRequired(), TEST_LOCATION);
170 DALI_TEST_EQUALS(1u, detector.GetMaximumTapsRequired(), TEST_LOCATION);
172 TapGestureDetector detector2 = TapGestureDetector::New(5u);
173 DALI_TEST_CHECK(detector2);
174 DALI_TEST_EQUALS(5u, detector2.GetMinimumTapsRequired(), TEST_LOCATION);
175 DALI_TEST_EQUALS(5u, detector2.GetMaximumTapsRequired(), TEST_LOCATION);
177 //Scoped test to test destructor
179 TapGestureDetector detector3 = TapGestureDetector::New();
180 DALI_TEST_CHECK(detector3);
183 // Attach an actor and emit a touch event on the actor to ensure complete line coverage
184 Actor actor = Actor::New();
185 actor.SetProperty(Actor::Property::SIZE, Vector2(100.0f, 100.0f));
186 actor.SetProperty(Actor::Property::ANCHOR_POINT, AnchorPoint::TOP_LEFT);
187 application.GetScene().Add(actor);
190 application.SendNotification();
191 application.Render();
193 detector.Attach(actor);
195 TouchEventFunctor touchFunctor;
196 actor.TouchedSignal().Connect(&application, touchFunctor);
198 Integration::TouchEvent touchEvent(1);
199 Integration::Point point;
200 point.SetDeviceId(1);
201 point.SetState(PointState::DOWN);
202 point.SetScreenPosition(Vector2(20.0f, 20.0f));
203 touchEvent.AddPoint(point);
204 application.ProcessEvent(touchEvent);
207 application.SendNotification();
208 application.Render();
213 int UtcDaliTapGestureDetectorDownCast(void)
215 TestApplication application;
216 tet_infoline("Testing Dali::TapGestureDetector::DownCast()");
218 TapGestureDetector detector = TapGestureDetector::New();
220 BaseHandle object(detector);
222 TapGestureDetector detector2 = TapGestureDetector::DownCast(object);
223 DALI_TEST_CHECK(detector2);
225 TapGestureDetector detector3 = DownCast<TapGestureDetector>(object);
226 DALI_TEST_CHECK(detector3);
228 BaseHandle unInitializedObject;
229 TapGestureDetector detector4 = TapGestureDetector::DownCast(unInitializedObject);
230 DALI_TEST_CHECK(!detector4);
232 TapGestureDetector detector5 = DownCast<TapGestureDetector>(unInitializedObject);
233 DALI_TEST_CHECK(!detector5);
235 GestureDetector detector6 = TapGestureDetector::New();
236 TapGestureDetector detector7 = TapGestureDetector::DownCast(detector6);
237 DALI_TEST_CHECK(detector7);
241 int UtcDaliTapGestureSetTapsRequiredMinMaxCheck(void)
243 TestApplication application;
245 // Attach an actor and change the required touches
247 Actor actor = Actor::New();
248 actor.SetProperty(Actor::Property::SIZE, Vector2(100.0f, 100.0f));
249 actor.SetProperty(Actor::Property::ANCHOR_POINT, AnchorPoint::TOP_LEFT);
250 application.GetScene().Add(actor);
253 application.SendNotification();
254 application.Render();
256 // Set the minimum to be greater than the maximum, should Assert
260 TapGestureDetector detector = TapGestureDetector::New();
261 detector.SetMinimumTapsRequired(7u);
262 detector.SetMaximumTapsRequired(3u);
263 detector.Attach(actor);
264 DALI_TEST_CHECK(false); // Should not get here
266 catch(DaliException& e)
268 DALI_TEST_CHECK(true);
274 int UtcDaliTapGestureGetTapsRequired(void)
276 TestApplication application;
278 TapGestureDetector detector = TapGestureDetector::New();
279 DALI_TEST_EQUALS(1u, detector.GetMinimumTapsRequired(), TEST_LOCATION);
280 DALI_TEST_EQUALS(1u, detector.GetMaximumTapsRequired(), TEST_LOCATION);
284 int UtcDaliTapGestureSignalReceptionNegative(void)
286 TestApplication application;
288 Actor actor = Actor::New();
289 actor.SetProperty(Actor::Property::SIZE, Vector2(100.0f, 100.0f));
290 actor.SetProperty(Actor::Property::ANCHOR_POINT, AnchorPoint::TOP_LEFT);
291 application.GetScene().Add(actor);
294 application.SendNotification();
295 application.Render();
298 GestureReceivedFunctor functor(data);
300 TapGestureDetector detector = TapGestureDetector::New();
301 detector.Attach(actor);
302 detector.DetectedSignal().Connect(&application, functor);
304 // Do a tap outside actor's area
305 TestGenerateTap(application, 112.0f, 112.0f, 100);
306 DALI_TEST_EQUALS(false, data.functorCalled, TEST_LOCATION);
310 int UtcDaliTapGestureSignalReceptionPositive(void)
312 TestApplication application;
314 Actor actor = Actor::New();
315 actor.SetProperty(Actor::Property::SIZE, Vector2(100.0f, 100.0f));
316 actor.SetProperty(Actor::Property::ANCHOR_POINT, AnchorPoint::TOP_LEFT);
317 application.GetScene().Add(actor);
320 application.SendNotification();
321 application.Render();
324 GestureReceivedFunctor functor(data);
326 TapGestureDetector detector = TapGestureDetector::New();
327 detector.Attach(actor);
328 detector.DetectedSignal().Connect(&application, functor);
330 // Do a tap inside actor's area
331 TestGenerateTap(application, 50.0f, 50.0f, 100);
332 DALI_TEST_EQUALS(true, data.functorCalled, TEST_LOCATION);
333 DALI_TEST_EQUALS(1u, data.receivedGesture.GetNumberOfTaps(), TEST_LOCATION);
334 DALI_TEST_EQUALS(1u, data.receivedGesture.GetNumberOfTouches(), TEST_LOCATION);
335 DALI_TEST_EQUALS(Vector2(50.0f, 50.0f), data.receivedGesture.GetLocalPoint(), 0.1, TEST_LOCATION);
339 int UtcDaliTapGestureSignalReceptionDetach(void)
341 TestApplication application;
343 Actor actor = Actor::New();
344 actor.SetProperty(Actor::Property::SIZE, Vector2(100.0f, 100.0f));
345 actor.SetProperty(Actor::Property::ANCHOR_POINT, AnchorPoint::TOP_LEFT);
346 application.GetScene().Add(actor);
349 application.SendNotification();
350 application.Render();
353 GestureReceivedFunctor functor(data);
355 TapGestureDetector detector = TapGestureDetector::New();
356 detector.Attach(actor);
357 detector.DetectedSignal().Connect(&application, functor);
359 // Start tap within the actor's area
360 TestGenerateTap(application, 20.0f, 20.0f, 100);
361 DALI_TEST_EQUALS(true, data.functorCalled, TEST_LOCATION);
362 DALI_TEST_EQUALS(1u, data.receivedGesture.GetNumberOfTaps(), TEST_LOCATION);
363 DALI_TEST_EQUALS(1u, data.receivedGesture.GetNumberOfTouches(), TEST_LOCATION);
364 DALI_TEST_EQUALS(Vector2(20.0f, 20.0f), data.receivedGesture.GetLocalPoint(), 0.1, TEST_LOCATION);
366 // repeat the tap within the actor's area - we should still receive the signal
368 TestGenerateTap(application, 50.0f, 50.0f, 700);
369 DALI_TEST_EQUALS(true, data.functorCalled, TEST_LOCATION);
370 DALI_TEST_EQUALS(1u, data.receivedGesture.GetNumberOfTaps(), TEST_LOCATION);
371 DALI_TEST_EQUALS(1u, data.receivedGesture.GetNumberOfTouches(), TEST_LOCATION);
372 DALI_TEST_EQUALS(Vector2(50.0f, 50.0f), data.receivedGesture.GetLocalPoint(), 0.1, TEST_LOCATION);
375 detector.DetachAll();
377 // Ensure we are no longer signalled
379 TestGenerateTap(application, 20.0f, 20.0f, 1300);
380 DALI_TEST_EQUALS(false, data.functorCalled, TEST_LOCATION);
381 TestGenerateTap(application, 50.0f, 50.0f, 1900);
382 DALI_TEST_EQUALS(false, data.functorCalled, TEST_LOCATION);
386 int UtcDaliTapGestureSignalReceptionActorDestroyedWhileTapping(void)
388 TestApplication application;
391 GestureReceivedFunctor functor(data);
393 TapGestureDetector detector = TapGestureDetector::New();
394 detector.DetectedSignal().Connect(&application, functor);
396 // Actor lifetime is scoped
398 Actor actor = Actor::New();
399 actor.SetProperty(Actor::Property::SIZE, Vector2(100.0f, 100.0f));
400 actor.SetProperty(Actor::Property::ANCHOR_POINT, AnchorPoint::TOP_LEFT);
401 application.GetScene().Add(actor);
404 application.SendNotification();
405 application.Render();
407 detector.Attach(actor);
409 // Start tap within the actor's area
410 TestGenerateTap(application, 20.0f, 20.0f, 100);
411 DALI_TEST_EQUALS(true, data.functorCalled, TEST_LOCATION);
413 // Remove the actor from stage and reset the data
414 application.GetScene().Remove(actor);
417 application.SendNotification();
418 application.Render();
421 // Actor should now have been destroyed
424 TestGenerateTap(application, 20.0f, 20.0f, 700);
425 DALI_TEST_EQUALS(false, data.functorCalled, TEST_LOCATION);
429 int UtcDaliTapGestureSignalReceptionRotatedActor(void)
431 TestApplication application;
433 Actor actor = Actor::New();
434 actor.SetProperty(Actor::Property::SIZE, Vector2(100.0f, 100.0f));
435 actor.SetProperty(Actor::Property::ORIENTATION, Quaternion(Dali::Degree(90.0f), Vector3::ZAXIS));
436 application.GetScene().Add(actor);
439 application.SendNotification();
440 application.Render();
443 GestureReceivedFunctor functor(data);
445 TapGestureDetector detector = TapGestureDetector::New();
446 detector.Attach(actor);
447 detector.DetectedSignal().Connect(&application, functor);
449 // Do tap, only check finished value
450 TestGenerateTap(application, 5.0f, 5.0f, 100);
451 DALI_TEST_EQUALS(true, data.functorCalled, TEST_LOCATION);
452 DALI_TEST_EQUALS(1u, data.receivedGesture.GetNumberOfTaps(), TEST_LOCATION);
453 DALI_TEST_EQUALS(1u, data.receivedGesture.GetNumberOfTouches(), TEST_LOCATION);
454 DALI_TEST_EQUALS(Vector2(5.0f, 5.0f), data.receivedGesture.GetScreenPoint(), 0.1, TEST_LOCATION);
456 // Rotate actor again and render
457 actor.SetProperty(Actor::Property::ORIENTATION, Quaternion(Dali::Degree(180.0f), Vector3::ZAXIS));
458 application.SendNotification();
459 application.Render();
461 // Do tap, should still receive event
463 TestGenerateTap(application, 5.0f, 5.0f, 700);
464 DALI_TEST_EQUALS(true, data.functorCalled, TEST_LOCATION);
465 DALI_TEST_EQUALS(1u, data.receivedGesture.GetNumberOfTaps(), TEST_LOCATION);
466 DALI_TEST_EQUALS(1u, data.receivedGesture.GetNumberOfTouches(), TEST_LOCATION);
467 DALI_TEST_EQUALS(Vector2(5.0f, 5.0f), data.receivedGesture.GetScreenPoint(), 0.1, TEST_LOCATION);
469 // Rotate actor again and render
470 actor.SetProperty(Actor::Property::ORIENTATION, Quaternion(Dali::Degree(90.0f), Vector3::YAXIS));
471 application.SendNotification();
472 application.Render();
474 // Do tap, inside the actor's area (area if it is not rotated), Should not receive the event
476 TestGenerateTap(application, 70.0f, 70.0f, 1300);
477 DALI_TEST_EQUALS(false, data.functorCalled, TEST_LOCATION);
481 int UtcDaliTapGestureSignalReceptionChildHit(void)
483 TestApplication application;
485 Actor parent = Actor::New();
486 parent.SetProperty(Actor::Property::SIZE, Vector2(100.0f, 100.0f));
487 parent.SetProperty(Actor::Property::ANCHOR_POINT, AnchorPoint::TOP_LEFT);
488 application.GetScene().Add(parent);
490 // Set child to completely cover parent.
491 // Change rotation of child to be different from parent so that we can check if our local coordinate
492 // conversion of the parent actor is correct.
493 Actor child = Actor::New();
494 child.SetProperty(Actor::Property::SIZE, Vector2(100.0f, 100.0f));
495 child.SetProperty(Actor::Property::ANCHOR_POINT, AnchorPoint::CENTER);
496 child.SetProperty(Actor::Property::PARENT_ORIGIN, ParentOrigin::CENTER);
497 child.SetProperty(Actor::Property::ORIENTATION, Quaternion(Dali::Degree(90.0f), Vector3::ZAXIS));
500 TouchEventFunctor touchFunctor;
501 child.TouchedSignal().Connect(&application, touchFunctor);
504 application.SendNotification();
505 application.Render();
508 GestureReceivedFunctor functor(data);
510 TapGestureDetector detector = TapGestureDetector::New();
511 detector.Attach(parent);
512 detector.DetectedSignal().Connect(&application, functor);
514 // Do tap - hits child area but parent should still receive it
515 TestGenerateTap(application, 50.0f, 50.0f, 100);
516 DALI_TEST_EQUALS(true, data.functorCalled, TEST_LOCATION);
517 DALI_TEST_EQUALS(true, parent == data.tappedActor, TEST_LOCATION);
518 DALI_TEST_EQUALS(Vector2(50.0f, 50.0f), data.receivedGesture.GetScreenPoint(), 0.01f, TEST_LOCATION);
520 // Attach child and generate same touch points
521 // (Also proves that you can detach and then re-attach another actor)
522 detector.Attach(child);
523 detector.Detach(parent);
525 // Do an entire tap, only check finished value
527 TestGenerateTap(application, 51.0f, 51.0f, 700);
528 DALI_TEST_EQUALS(true, data.functorCalled, TEST_LOCATION);
529 DALI_TEST_EQUALS(true, child == data.tappedActor, TEST_LOCATION);
530 DALI_TEST_EQUALS(Vector2(51.0f, 51.0f), data.receivedGesture.GetScreenPoint(), 0.01f, TEST_LOCATION);
534 int UtcDaliTapGestureSignalReceptionAttachDetachMany(void)
536 TestApplication application;
538 Actor first = Actor::New();
539 first.SetProperty(Actor::Property::SIZE, Vector2(100.0f, 100.0f));
540 first.SetProperty(Actor::Property::ANCHOR_POINT, AnchorPoint::TOP_LEFT);
541 application.GetScene().Add(first);
543 Actor second = Actor::New();
544 second.SetProperty(Actor::Property::SIZE, Vector2(100.0f, 100.0f));
545 second.SetProperty(Actor::Property::POSITION_X, 100.0f);
546 second.SetProperty(Actor::Property::ANCHOR_POINT, AnchorPoint::TOP_LEFT);
547 application.GetScene().Add(second);
550 application.SendNotification();
551 application.Render();
554 GestureReceivedFunctor functor(data);
556 TapGestureDetector detector = TapGestureDetector::New();
557 detector.Attach(first);
558 detector.Attach(second);
559 detector.DetectedSignal().Connect(&application, functor);
561 // Tap within second actor's area
562 TestGenerateTap(application, 120.0f, 10.0f, 100);
563 DALI_TEST_EQUALS(true, data.functorCalled, TEST_LOCATION);
564 DALI_TEST_EQUALS(true, second == data.tappedActor, TEST_LOCATION);
566 // Tap within first actor's area
568 TestGenerateTap(application, 20.0f, 10.0f, 700);
569 DALI_TEST_EQUALS(true, data.functorCalled, TEST_LOCATION);
570 DALI_TEST_EQUALS(true, first == data.tappedActor, TEST_LOCATION);
572 // Detach the second actor
573 detector.Detach(second);
575 // second actor shouldn't receive event
577 TestGenerateTap(application, 120.0f, 10.0f, 1300);
578 DALI_TEST_EQUALS(false, data.functorCalled, TEST_LOCATION);
580 // first actor should continue receiving event
582 TestGenerateTap(application, 20.0f, 10.0f, 1900);
583 DALI_TEST_EQUALS(true, data.functorCalled, TEST_LOCATION);
587 int UtcDaliTapGestureSignalReceptionActorBecomesUntouchable(void)
589 TestApplication application;
591 Actor actor = Actor::New();
592 actor.SetProperty(Actor::Property::SIZE, Vector2(100.0f, 100.0f));
593 actor.SetProperty(Actor::Property::ANCHOR_POINT, AnchorPoint::TOP_LEFT);
594 application.GetScene().Add(actor);
597 application.SendNotification();
598 application.Render();
601 GestureReceivedFunctor functor(data);
603 TapGestureDetector detector = TapGestureDetector::New();
604 detector.Attach(actor);
605 detector.DetectedSignal().Connect(&application, functor);
607 // Tap in actor's area
608 TestGenerateTap(application, 50.0f, 10.0f, 100);
609 DALI_TEST_EQUALS(true, data.functorCalled, TEST_LOCATION);
611 // Actor become invisible - actor should not receive the next pan
612 actor.SetProperty(Actor::Property::VISIBLE, false);
615 application.SendNotification();
616 application.Render();
618 // Tap in the same area, shouldn't receive event
620 TestGenerateTap(application, 50.0f, 10.0f, 700);
621 DALI_TEST_EQUALS(false, data.functorCalled, TEST_LOCATION);
625 int UtcDaliTapGestureSignalReceptionMultipleGestureDetectors(void)
627 TestApplication application;
629 Actor first = Actor::New();
630 first.SetProperty(Actor::Property::SIZE, Vector2(100.0f, 100.0f));
631 first.SetProperty(Actor::Property::ANCHOR_POINT, AnchorPoint::TOP_LEFT);
632 application.GetScene().Add(first);
634 Actor second = Actor::New();
635 second.SetProperty(Actor::Property::SIZE, Vector2(100.0f, 100.0f));
636 second.SetProperty(Actor::Property::ANCHOR_POINT, AnchorPoint::TOP_LEFT);
637 second.SetProperty(Actor::Property::POSITION_X, 100.0f);
641 application.SendNotification();
642 application.Render();
645 GestureReceivedFunctor functor(data);
647 TapGestureDetector firstDetector = TapGestureDetector::New();
648 firstDetector.Attach(first);
649 firstDetector.DetectedSignal().Connect(&application, functor);
651 // secondDetector is scoped
653 TapGestureDetector secondDetector = TapGestureDetector::New(2);
654 secondDetector.Attach(second);
655 secondDetector.DetectedSignal().Connect(&application, functor);
657 // Tap within second actor's area
658 TestGenerateTap(application, 150.0f, 10.0f, 100);
659 TestGenerateTap(application, 150.0f, 10.0f, 200);
661 DALI_TEST_EQUALS(true, data.functorCalled, TEST_LOCATION);
662 DALI_TEST_EQUALS(true, second == data.tappedActor, TEST_LOCATION);
664 // Tap continues as single touch gesture - we should not receive any gesture
666 TestGenerateTap(application, 150.0f, 10.0f, 800);
667 DALI_TEST_EQUALS(false, data.functorCalled, TEST_LOCATION);
669 // Single touch tap starts - first actor should be panned
671 TestGenerateTap(application, 50.0f, 10.0f, 1400);
672 DALI_TEST_EQUALS(true, data.functorCalled, TEST_LOCATION);
673 DALI_TEST_EQUALS(true, first == data.tappedActor, TEST_LOCATION);
675 // Tap changes to double-touch - we shouldn't receive event
678 TestGenerateTwoPointTap(application, 50.0f, 10.0f, 60.0f, 20.0f, 2000);
680 DALI_TEST_EQUALS(false, data.functorCalled, TEST_LOCATION);
686 int UtcDaliTapGestureSignalReceptionMultipleDetectorsOnActor(void)
688 TestApplication application;
690 Actor actor = Actor::New();
691 actor.SetProperty(Actor::Property::SIZE, Vector2(100.0f, 100.0f));
692 actor.SetProperty(Actor::Property::ANCHOR_POINT, AnchorPoint::TOP_LEFT);
693 application.GetScene().Add(actor);
696 application.SendNotification();
697 application.Render();
699 // Attach actor to one detector
700 SignalData firstData;
701 GestureReceivedFunctor firstFunctor(firstData);
702 TapGestureDetector firstDetector = TapGestureDetector::New();
703 firstDetector.Attach(actor);
704 firstDetector.DetectedSignal().Connect(&application, firstFunctor);
706 // Attach actor to another detector
707 SignalData secondData;
708 GestureReceivedFunctor secondFunctor(secondData);
709 TapGestureDetector secondDetector = TapGestureDetector::New();
710 secondDetector.Attach(actor);
711 secondDetector.DetectedSignal().Connect(&application, secondFunctor);
713 // Tap in actor's area - both detector's functors should be called
714 TestGenerateTap(application, 50.0f, 10.0f, 100);
715 DALI_TEST_EQUALS(true, firstData.functorCalled, TEST_LOCATION);
716 DALI_TEST_EQUALS(true, secondData.functorCalled, TEST_LOCATION);
720 int UtcDaliTapGestureSignalReceptionDifferentPossible(void)
722 TestApplication application;
724 Actor actor = Actor::New();
725 actor.SetProperty(Actor::Property::SIZE, Vector2(100.0f, 100.0f));
726 actor.SetProperty(Actor::Property::ANCHOR_POINT, AnchorPoint::TOP_LEFT);
727 application.GetScene().Add(actor);
730 application.SendNotification();
731 application.Render();
733 // Attach actor to detector
735 GestureReceivedFunctor functor(data);
736 TapGestureDetector detector = TapGestureDetector::New();
737 detector.Attach(actor);
738 detector.DetectedSignal().Connect(&application, functor);
740 // Gesture possible in actor's area.
741 TestStartLongPress(application, 50.0f, 10.0f, 100);
742 DALI_TEST_EQUALS(false, data.functorCalled, TEST_LOCATION);
744 // Move actor somewhere else
745 actor.SetProperty(Actor::Property::POSITION, Vector2(100.0f, 100.0f));
748 application.SendNotification();
749 application.Render();
751 // Emit STARTED event, we should not receive the tap.
752 TestEndPan(application, Vector2(50.0f, 10.0f), 120);
753 DALI_TEST_EQUALS(false, data.functorCalled, TEST_LOCATION);
755 // Tap possible in empty area.
756 TestStartLongPress(application, 50.0f, 10.0f, 700);
757 DALI_TEST_EQUALS(false, data.functorCalled, TEST_LOCATION);
759 // Move actor in to the tap position.
760 actor.SetProperty(Actor::Property::POSITION, Vector2(0.0f, 0.0f));
763 application.SendNotification();
764 application.Render();
766 // Emit STARTED event, we should not receive the tap.
767 TestEndPan(application, Vector2(50.0f, 10.0f), 720);
768 DALI_TEST_EQUALS(false, data.functorCalled, TEST_LOCATION);
770 // Normal tap in actor's area for completeness.
771 TestGenerateTap(application, 50.0f, 10.0f, 1300);
772 DALI_TEST_EQUALS(true, data.functorCalled, TEST_LOCATION);
776 int UtcDaliTapGestureActorUnstaged(void)
778 TestApplication application;
780 Actor actor = Actor::New();
781 actor.SetProperty(Actor::Property::SIZE, Vector2(100.0f, 100.0f));
782 actor.SetProperty(Actor::Property::ANCHOR_POINT, AnchorPoint::TOP_LEFT);
783 application.GetScene().Add(actor);
786 application.SendNotification();
787 application.Render();
789 // Attach actor to detector
791 UnstageActorFunctor functor(data, application.GetScene());
792 TapGestureDetector detector = TapGestureDetector::New();
793 detector.Attach(actor);
794 detector.DetectedSignal().Connect(&application, functor);
796 TestGenerateTap(application, 50.0f, 10.0f, 100);
797 DALI_TEST_EQUALS(true, data.functorCalled, TEST_LOCATION);
798 tet_result(TET_PASS); // If we get here, then the actor removal on signal handler was handled gracefully.
802 int UtcDaliTapGestureDetectorRemovedWhilePossible(void)
804 TestApplication application;
806 Actor actor = Actor::New();
807 actor.SetProperty(Actor::Property::SIZE, Vector2(100.0f, 100.0f));
808 actor.SetProperty(Actor::Property::ANCHOR_POINT, AnchorPoint::TOP_LEFT);
809 application.GetScene().Add(actor);
812 application.SendNotification();
813 application.Render();
815 // Attach actor to detector
817 GestureReceivedFunctor functor(data);
818 TapGestureDetector detector = TapGestureDetector::New();
819 detector.Attach(actor);
820 detector.DetectedSignal().Connect(&application, functor);
822 // Emit a possible - Down press, as emitted by long press function
823 TestStartLongPress(application, 50.0f, 10.0f, 100);
825 // Detach actor and send a STARTED state, no signal.
826 detector.DetachAll();
827 TestEndPan(application, Vector2(50.0f, 10.0f), 120);
828 DALI_TEST_EQUALS(false, data.functorCalled, TEST_LOCATION);
832 int UtcDaliTapGestureActorRemovedWhilePossible(void)
834 TestApplication application;
836 Actor actor = Actor::New();
837 actor.SetProperty(Actor::Property::SIZE, Vector2(100.0f, 100.0f));
838 actor.SetProperty(Actor::Property::ANCHOR_POINT, AnchorPoint::TOP_LEFT);
839 application.GetScene().Add(actor);
842 application.SendNotification();
843 application.Render();
845 // Attach actor to detector
847 GestureReceivedFunctor functor(data);
848 TapGestureDetector detector = TapGestureDetector::New();
849 detector.Attach(actor);
850 detector.DetectedSignal().Connect(&application, functor);
852 // Emit a possible - Down press, as emitted by long press function
853 TestStartLongPress(application, 50.0f, 10.0f, 100);
855 // Remove, render and delete actor
856 application.GetScene().Remove(actor);
857 application.SendNotification();
858 application.Render();
861 // Send a STARTED state, no signal - Up motion as provided by end pan function
862 TestEndPan(application, Vector2(50.0f, 10.0f), 120);
863 DALI_TEST_EQUALS(false, data.functorCalled, TEST_LOCATION);
867 int UtcDaliTapGestureLayerConsumesTouch(void)
869 TestApplication application;
871 Actor actor = Actor::New();
872 actor.SetProperty(Actor::Property::SIZE, Vector2(100.0f, 100.0f));
873 actor.SetProperty(Actor::Property::ANCHOR_POINT, AnchorPoint::TOP_LEFT);
874 application.GetScene().Add(actor);
878 GestureReceivedFunctor functor(data);
879 TapGestureDetector detector = TapGestureDetector::New();
880 detector.Attach(actor);
881 detector.DetectedSignal().Connect(&application, functor);
883 // Add a layer to overlap the actor
884 Layer layer = Layer::New();
885 layer.SetProperty(Actor::Property::SIZE, Vector2(100.0f, 100.0f));
886 layer.SetProperty(Actor::Property::ANCHOR_POINT, AnchorPoint::TOP_LEFT);
887 application.GetScene().Add(layer);
891 application.SendNotification();
892 application.Render();
894 // Emit signals, should receive
895 TestGenerateTap(application, 50.0f, 50.0f, 100);
896 DALI_TEST_EQUALS(true, data.functorCalled, TEST_LOCATION);
899 // Set layer to consume all touch
900 layer.SetProperty(Layer::Property::CONSUMES_TOUCH, true);
903 application.SendNotification();
904 application.Render();
906 // Emit the same signals again, should not receive
907 TestGenerateTap(application, 50.0f, 50.0f, 700);
908 DALI_TEST_EQUALS(false, data.functorCalled, TEST_LOCATION);
914 int UtcDaliTapGestureInterruptedWhenTouchConsumed(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);
923 bool consume = false;
924 TouchEventFunctorConsumeSetter touchFunctor(consume);
925 actor.TouchedSignal().Connect(&application, touchFunctor);
928 application.SendNotification();
929 application.Render();
932 GestureReceivedFunctor functor(data);
934 TapGestureDetector detector = TapGestureDetector::New();
935 detector.Attach(actor);
936 detector.DetectedSignal().Connect(&application, functor);
938 // Start gesture within the actor's area, we should receive the gesture as the touch is NOT being consumed
939 TestGenerateTap(application, 50.0f, 50.0f);
940 DALI_TEST_EQUALS(true, data.functorCalled, TEST_LOCATION);
943 // Another gesture in the same location, this time we will not receive it as touch is being consumed
945 TestGenerateTap(application, 50.0f, 50.0f);
946 DALI_TEST_EQUALS(false, data.functorCalled, TEST_LOCATION);
952 int UtcDaliTapGestureDisableDetectionDuringTapN(void)
954 // Crash sometimes occurred when gesture-recognizer was deleted internally during a signal when the attached actor was detached
956 TestApplication application;
958 Actor actor = Actor::New();
959 actor.SetProperty(Actor::Property::SIZE, Vector2(100.0f, 100.0f));
960 actor.SetProperty(Actor::Property::ANCHOR_POINT, AnchorPoint::TOP_LEFT);
961 application.GetScene().Add(actor);
964 TapGestureDetector detector = TapGestureDetector::New();
965 bool functorCalled = false;
966 detector.Attach(actor);
967 detector.DetectedSignal().Connect(
969 [&detector, &functorCalled](Actor actor, const TapGesture& gesture) {
970 detector.Detach(actor);
971 functorCalled = true;
975 application.SendNotification();
976 application.Render();
978 // Try the gesture, should not crash
981 TestGenerateTap(application, 50.0f, 10.0f);
983 DALI_TEST_CHECK(true); // No crash, test has passed
984 DALI_TEST_EQUALS(functorCalled, true, TEST_LOCATION);
988 DALI_TEST_CHECK(false); // If we crash, the test has failed