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.
21 #include <dali/public-api/dali-core.h>
22 #include <dali/integration-api/events/touch-event-integ.h>
23 #include <dali/integration-api/render-task-list-integ.h>
24 #include <dali-test-suite-utils.h>
25 #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 ///////////////////////////////////////////////////////////////////////////////
43 // Stores data that is populated in the callback and will be read by the TET cases
47 : functorCalled(false),
48 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) : signalData(data) { }
72 void operator()(Actor actor, const TapGesture& tap)
74 signalData.functorCalled = true;
75 signalData.receivedGesture = tap;
76 signalData.tappedActor = actor;
81 signalData.voidFunctorCalled = true;
84 SignalData& signalData;
87 // Functor that removes the gestured actor from stage
88 struct UnstageActorFunctor : public GestureReceivedFunctor
90 UnstageActorFunctor( SignalData& data, Integration::Scene scene )
91 : GestureReceivedFunctor( data ),
96 void operator()(Actor actor, const TapGesture& tap)
98 GestureReceivedFunctor::operator()( actor, tap );
99 scene.Remove( actor );
102 Integration::Scene scene;
105 // Functor for receiving a touch event
106 struct TouchEventFunctor
108 bool operator()(Actor actor, const TouchEvent& touch)
111 unsigned int points = touch.GetPointCount();
114 tet_printf("Touch Point state = %d\n", touch.GetState(0));
122 ///////////////////////////////////////////////////////////////////////////////
125 // Positive test case for a method
126 int UtcDaliTapGestureDetectorConstructor(void)
128 TestApplication application;
130 TapGestureDetector detector;
131 DALI_TEST_CHECK(!detector);
135 int UtcDaliTapGestureDetectorCopyConstructorP(void)
137 TestApplication application;
139 TapGestureDetector detector = TapGestureDetector::New();
141 TapGestureDetector copy( detector );
142 DALI_TEST_CHECK( detector );
146 int UtcDaliTapGestureDetectorAssignmentOperatorP(void)
148 TestApplication application;
150 TapGestureDetector detector = TapGestureDetector::New();;
152 TapGestureDetector assign;
154 DALI_TEST_CHECK( detector );
156 DALI_TEST_CHECK( detector == assign );
160 int UtcDaliTapGestureDetectorNew(void)
162 TestApplication application;
164 TapGestureDetector detector = TapGestureDetector::New();
165 DALI_TEST_CHECK(detector);
166 DALI_TEST_EQUALS(1u, detector.GetMinimumTapsRequired(), TEST_LOCATION);
167 DALI_TEST_EQUALS(1u, detector.GetMaximumTapsRequired(), TEST_LOCATION);
169 TapGestureDetector detector2 = TapGestureDetector::New( 5u );
170 DALI_TEST_CHECK(detector2);
171 DALI_TEST_EQUALS(5u, detector2.GetMinimumTapsRequired(), TEST_LOCATION);
172 DALI_TEST_EQUALS(5u, detector2.GetMaximumTapsRequired(), TEST_LOCATION);
174 //Scoped test to test destructor
176 TapGestureDetector detector3 = TapGestureDetector::New();
177 DALI_TEST_CHECK(detector3);
180 // Attach an actor and emit a touch event on the actor to ensure complete line coverage
181 Actor actor = Actor::New();
182 actor.SetProperty( Actor::Property::SIZE, Vector2( 100.0f, 100.0f ) );
183 actor.SetProperty( Actor::Property::ANCHOR_POINT,AnchorPoint::TOP_LEFT);
184 application.GetScene().Add(actor);
187 application.SendNotification();
188 application.Render();
190 detector.Attach(actor);
192 TouchEventFunctor touchFunctor;
193 actor.TouchedSignal().Connect( &application, touchFunctor );
195 Integration::TouchEvent touchEvent(1);
196 Integration::Point point;
197 point.SetDeviceId( 1 );
198 point.SetState( PointState::DOWN );
199 point.SetScreenPosition( Vector2( 20.0f, 20.0f ) );
200 touchEvent.AddPoint(point);
201 application.ProcessEvent(touchEvent);
204 application.SendNotification();
205 application.Render();
210 int UtcDaliTapGestureDetectorDownCast(void)
212 TestApplication application;
213 tet_infoline("Testing Dali::TapGestureDetector::DownCast()");
215 TapGestureDetector detector = TapGestureDetector::New();
217 BaseHandle object(detector);
219 TapGestureDetector detector2 = TapGestureDetector::DownCast(object);
220 DALI_TEST_CHECK(detector2);
222 TapGestureDetector detector3 = DownCast< TapGestureDetector >(object);
223 DALI_TEST_CHECK(detector3);
225 BaseHandle unInitializedObject;
226 TapGestureDetector detector4 = TapGestureDetector::DownCast(unInitializedObject);
227 DALI_TEST_CHECK(!detector4);
229 TapGestureDetector detector5 = DownCast< TapGestureDetector >(unInitializedObject);
230 DALI_TEST_CHECK(!detector5);
232 GestureDetector detector6 = TapGestureDetector::New();
233 TapGestureDetector detector7 = TapGestureDetector::DownCast(detector6);
234 DALI_TEST_CHECK(detector7);
238 int UtcDaliTapGestureSetTapsRequiredMinMaxCheck(void)
240 TestApplication application;
242 // Attach an actor and change the required touches
244 Actor actor = Actor::New();
245 actor.SetProperty( Actor::Property::SIZE, Vector2( 100.0f, 100.0f ) );
246 actor.SetProperty( Actor::Property::ANCHOR_POINT,AnchorPoint::TOP_LEFT);
247 application.GetScene().Add(actor);
250 application.SendNotification();
251 application.Render();
253 // Set the minimum to be greater than the maximum, should Assert
257 TapGestureDetector detector = TapGestureDetector::New();
258 detector.SetMinimumTapsRequired( 7u );
259 detector.SetMaximumTapsRequired( 3u );
260 detector.Attach(actor);
261 DALI_TEST_CHECK( false ); // Should not get here
263 catch ( DaliException& e )
265 DALI_TEST_CHECK( true );
271 int UtcDaliTapGestureGetTapsRequired(void)
273 TestApplication application;
275 TapGestureDetector detector = TapGestureDetector::New();
276 DALI_TEST_EQUALS(1u, detector.GetMinimumTapsRequired(), TEST_LOCATION);
277 DALI_TEST_EQUALS(1u, detector.GetMaximumTapsRequired(), TEST_LOCATION);
281 int UtcDaliTapGestureSignalReceptionNegative(void)
283 TestApplication application;
285 Actor actor = Actor::New();
286 actor.SetProperty( Actor::Property::SIZE, Vector2( 100.0f, 100.0f ) );
287 actor.SetProperty( Actor::Property::ANCHOR_POINT,AnchorPoint::TOP_LEFT);
288 application.GetScene().Add(actor);
291 application.SendNotification();
292 application.Render();
295 GestureReceivedFunctor functor(data);
297 TapGestureDetector detector = TapGestureDetector::New();
298 detector.Attach(actor);
299 detector.DetectedSignal().Connect( &application, functor );
301 // Do a tap outside actor's area
302 TestGenerateTap( application, 112.0f, 112.0f, 100 );
303 DALI_TEST_EQUALS(false, data.functorCalled, TEST_LOCATION);
307 int UtcDaliTapGestureSignalReceptionPositive(void)
309 TestApplication application;
311 Actor actor = Actor::New();
312 actor.SetProperty( Actor::Property::SIZE, Vector2( 100.0f, 100.0f ) );
313 actor.SetProperty( Actor::Property::ANCHOR_POINT,AnchorPoint::TOP_LEFT);
314 application.GetScene().Add(actor);
317 application.SendNotification();
318 application.Render();
321 GestureReceivedFunctor functor(data);
323 TapGestureDetector detector = TapGestureDetector::New();
324 detector.Attach(actor);
325 detector.DetectedSignal().Connect( &application, functor );
327 // Do a tap inside actor's area
328 TestGenerateTap( application, 50.0f, 50.0f, 100 );
329 DALI_TEST_EQUALS(true, data.functorCalled, TEST_LOCATION);
330 DALI_TEST_EQUALS(1u, data.receivedGesture.GetNumberOfTaps(), TEST_LOCATION);
331 DALI_TEST_EQUALS(1u, data.receivedGesture.GetNumberOfTouches(), TEST_LOCATION);
332 DALI_TEST_EQUALS( Vector2(50.0f, 50.0f), data.receivedGesture.GetLocalPoint(), 0.1, TEST_LOCATION);
336 int UtcDaliTapGestureSignalReceptionDetach(void)
338 TestApplication application;
340 Actor actor = Actor::New();
341 actor.SetProperty( Actor::Property::SIZE, Vector2( 100.0f, 100.0f ) );
342 actor.SetProperty( Actor::Property::ANCHOR_POINT,AnchorPoint::TOP_LEFT);
343 application.GetScene().Add(actor);
346 application.SendNotification();
347 application.Render();
350 GestureReceivedFunctor functor(data);
352 TapGestureDetector detector = TapGestureDetector::New();
353 detector.Attach(actor);
354 detector.DetectedSignal().Connect(&application, functor);
356 // Start tap within the actor's area
357 TestGenerateTap( application, 20.0f, 20.0f, 100 );
358 DALI_TEST_EQUALS(true, data.functorCalled, TEST_LOCATION);
359 DALI_TEST_EQUALS(1u, data.receivedGesture.GetNumberOfTaps(), TEST_LOCATION);
360 DALI_TEST_EQUALS(1u, data.receivedGesture.GetNumberOfTouches(), TEST_LOCATION);
361 DALI_TEST_EQUALS( Vector2(20.0f, 20.0f), data.receivedGesture.GetLocalPoint(), 0.1, TEST_LOCATION);
363 // repeat the tap within the actor's area - we should still receive the signal
365 TestGenerateTap( application, 50.0f, 50.0f, 700 );
366 DALI_TEST_EQUALS(true, data.functorCalled, TEST_LOCATION);
367 DALI_TEST_EQUALS(1u, data.receivedGesture.GetNumberOfTaps(), TEST_LOCATION);
368 DALI_TEST_EQUALS(1u, data.receivedGesture.GetNumberOfTouches(), TEST_LOCATION);
369 DALI_TEST_EQUALS( Vector2(50.0f, 50.0f), data.receivedGesture.GetLocalPoint(), 0.1, TEST_LOCATION);
372 detector.DetachAll();
374 // Ensure we are no longer signalled
376 TestGenerateTap( application, 20.0f, 20.0f, 1300 );
377 DALI_TEST_EQUALS(false, data.functorCalled, TEST_LOCATION);
378 TestGenerateTap( application, 50.0f, 50.0f, 1900 );
379 DALI_TEST_EQUALS(false, data.functorCalled, TEST_LOCATION);
383 int UtcDaliTapGestureSignalReceptionActorDestroyedWhileTapping(void)
385 TestApplication application;
388 GestureReceivedFunctor functor(data);
390 TapGestureDetector detector = TapGestureDetector::New();
391 detector.DetectedSignal().Connect(&application, functor);
393 // Actor lifetime is scoped
395 Actor actor = Actor::New();
396 actor.SetProperty( Actor::Property::SIZE, Vector2( 100.0f, 100.0f ) );
397 actor.SetProperty( Actor::Property::ANCHOR_POINT,AnchorPoint::TOP_LEFT);
398 application.GetScene().Add(actor);
401 application.SendNotification();
402 application.Render();
404 detector.Attach(actor);
406 // Start tap within the actor's area
407 TestGenerateTap( application, 20.0f, 20.0f, 100 );
408 DALI_TEST_EQUALS(true, data.functorCalled, TEST_LOCATION);
410 // Remove the actor from stage and reset the data
411 application.GetScene().Remove(actor);
414 application.SendNotification();
415 application.Render();
418 // Actor should now have been destroyed
421 TestGenerateTap( application, 20.0f, 20.0f, 700 );
422 DALI_TEST_EQUALS(false, data.functorCalled, TEST_LOCATION);
426 int UtcDaliTapGestureSignalReceptionRotatedActor(void)
428 TestApplication application;
430 Actor actor = Actor::New();
431 actor.SetProperty( Actor::Property::SIZE, Vector2( 100.0f, 100.0f ) );
432 actor.SetProperty( Actor::Property::ORIENTATION, Quaternion(Dali::Degree(90.0f), Vector3::ZAXIS) );
433 application.GetScene().Add(actor);
436 application.SendNotification();
437 application.Render();
440 GestureReceivedFunctor functor(data);
442 TapGestureDetector detector = TapGestureDetector::New();
443 detector.Attach(actor);
444 detector.DetectedSignal().Connect(&application, functor);
446 // Do tap, only check finished value
447 TestGenerateTap( application, 5.0f, 5.0f, 100 );
448 DALI_TEST_EQUALS(true, data.functorCalled, TEST_LOCATION);
449 DALI_TEST_EQUALS(1u, data.receivedGesture.GetNumberOfTaps(), TEST_LOCATION);
450 DALI_TEST_EQUALS(1u, data.receivedGesture.GetNumberOfTouches(), TEST_LOCATION);
451 DALI_TEST_EQUALS( Vector2(5.0f, 5.0f), data.receivedGesture.GetScreenPoint(), 0.1, TEST_LOCATION);
453 // Rotate actor again and render
454 actor.SetProperty( Actor::Property::ORIENTATION, Quaternion(Dali::Degree(180.0f), Vector3::ZAXIS) );
455 application.SendNotification();
456 application.Render();
458 // Do tap, should still receive event
460 TestGenerateTap( application, 5.0f, 5.0f, 700 );
461 DALI_TEST_EQUALS(true, data.functorCalled, TEST_LOCATION);
462 DALI_TEST_EQUALS(1u, data.receivedGesture.GetNumberOfTaps(), TEST_LOCATION);
463 DALI_TEST_EQUALS(1u, data.receivedGesture.GetNumberOfTouches(), TEST_LOCATION);
464 DALI_TEST_EQUALS( Vector2(5.0f, 5.0f), data.receivedGesture.GetScreenPoint(), 0.1, TEST_LOCATION);
466 // Rotate actor again and render
467 actor.SetProperty( Actor::Property::ORIENTATION, Quaternion(Dali::Degree(90.0f), Vector3::YAXIS) );
468 application.SendNotification();
469 application.Render();
471 // Do tap, inside the actor's area (area if it is not rotated), Should not receive the event
473 TestGenerateTap( application, 70.0f, 70.0f, 1300 );
474 DALI_TEST_EQUALS(false, data.functorCalled, TEST_LOCATION);
478 int UtcDaliTapGestureSignalReceptionChildHit(void)
480 TestApplication application;
482 Actor parent = Actor::New();
483 parent.SetProperty( Actor::Property::SIZE, Vector2( 100.0f, 100.0f ) );
484 parent.SetProperty( Actor::Property::ANCHOR_POINT,AnchorPoint::TOP_LEFT);
485 application.GetScene().Add(parent);
487 // Set child to completely cover parent.
488 // Change rotation of child to be different from parent so that we can check if our local coordinate
489 // conversion of the parent actor is correct.
490 Actor child = Actor::New();
491 child.SetProperty( Actor::Property::SIZE, Vector2( 100.0f, 100.0f ) );
492 child.SetProperty( Actor::Property::ANCHOR_POINT,AnchorPoint::CENTER);
493 child.SetProperty( Actor::Property::PARENT_ORIGIN,ParentOrigin::CENTER);
494 child.SetProperty( Actor::Property::ORIENTATION, Quaternion(Dali::Degree(90.0f), Vector3::ZAXIS) );
497 TouchEventFunctor touchFunctor;
498 child.TouchedSignal().Connect(&application, touchFunctor);
501 application.SendNotification();
502 application.Render();
505 GestureReceivedFunctor functor(data);
507 TapGestureDetector detector = TapGestureDetector::New();
508 detector.Attach(parent);
509 detector.DetectedSignal().Connect(&application, functor);
511 // Do tap - hits child area but parent should still receive it
512 TestGenerateTap( application, 50.0f, 50.0f, 100 );
513 DALI_TEST_EQUALS(true, data.functorCalled, TEST_LOCATION);
514 DALI_TEST_EQUALS(true, parent == data.tappedActor, TEST_LOCATION);
515 DALI_TEST_EQUALS(Vector2(50.0f, 50.0f), data.receivedGesture.GetScreenPoint(), 0.01f, TEST_LOCATION);
517 // Attach child and generate same touch points
518 // (Also proves that you can detach and then re-attach another actor)
519 detector.Attach(child);
520 detector.Detach(parent);
522 // Do an entire tap, only check finished value
524 TestGenerateTap( application, 51.0f, 51.0f, 700 );
525 DALI_TEST_EQUALS(true, data.functorCalled, TEST_LOCATION);
526 DALI_TEST_EQUALS(true, child == data.tappedActor, TEST_LOCATION);
527 DALI_TEST_EQUALS(Vector2(51.0f, 51.0f), data.receivedGesture.GetScreenPoint(), 0.01f, TEST_LOCATION);
531 int UtcDaliTapGestureSignalReceptionAttachDetachMany(void)
533 TestApplication application;
535 Actor first = Actor::New();
536 first.SetProperty( Actor::Property::SIZE, Vector2( 100.0f, 100.0f ) );
537 first.SetProperty( Actor::Property::ANCHOR_POINT,AnchorPoint::TOP_LEFT);
538 application.GetScene().Add(first);
540 Actor second = Actor::New();
541 second.SetProperty( Actor::Property::SIZE, Vector2( 100.0f, 100.0f ) );
542 second.SetProperty( Actor::Property::POSITION_X, 100.0f);
543 second.SetProperty( Actor::Property::ANCHOR_POINT,AnchorPoint::TOP_LEFT);
544 application.GetScene().Add(second);
547 application.SendNotification();
548 application.Render();
551 GestureReceivedFunctor functor(data);
553 TapGestureDetector detector = TapGestureDetector::New();
554 detector.Attach(first);
555 detector.Attach(second);
556 detector.DetectedSignal().Connect(&application, functor);
558 // Tap within second actor's area
559 TestGenerateTap( application, 120.0f, 10.0f, 100 );
560 DALI_TEST_EQUALS(true, data.functorCalled, TEST_LOCATION);
561 DALI_TEST_EQUALS(true, second == data.tappedActor, TEST_LOCATION);
563 // Tap within first actor's area
565 TestGenerateTap( application, 20.0f, 10.0f, 700 );
566 DALI_TEST_EQUALS(true, data.functorCalled, TEST_LOCATION);
567 DALI_TEST_EQUALS(true, first == data.tappedActor, TEST_LOCATION);
569 // Detach the second actor
570 detector.Detach(second);
572 // second actor shouldn't receive event
574 TestGenerateTap( application, 120.0f, 10.0f, 1300 );
575 DALI_TEST_EQUALS(false, data.functorCalled, TEST_LOCATION);
577 // first actor should continue receiving event
579 TestGenerateTap( application, 20.0f, 10.0f, 1900 );
580 DALI_TEST_EQUALS(true, data.functorCalled, TEST_LOCATION);
584 int UtcDaliTapGestureSignalReceptionActorBecomesUntouchable(void)
586 TestApplication application;
588 Actor actor = Actor::New();
589 actor.SetProperty( Actor::Property::SIZE, Vector2( 100.0f, 100.0f ) );
590 actor.SetProperty( Actor::Property::ANCHOR_POINT,AnchorPoint::TOP_LEFT);
591 application.GetScene().Add(actor);
594 application.SendNotification();
595 application.Render();
598 GestureReceivedFunctor functor(data);
600 TapGestureDetector detector = TapGestureDetector::New();
601 detector.Attach(actor);
602 detector.DetectedSignal().Connect(&application, functor);
604 // Tap in actor's area
605 TestGenerateTap( application, 50.0f, 10.0f, 100 );
606 DALI_TEST_EQUALS(true, data.functorCalled, TEST_LOCATION);
608 // Actor become invisible - actor should not receive the next pan
609 actor.SetProperty( Actor::Property::VISIBLE,false);
612 application.SendNotification();
613 application.Render();
615 // Tap in the same area, shouldn't receive event
617 TestGenerateTap( application, 50.0f, 10.0f, 700 );
618 DALI_TEST_EQUALS(false, data.functorCalled, TEST_LOCATION);
622 int UtcDaliTapGestureSignalReceptionMultipleGestureDetectors(void)
624 TestApplication application;
626 Actor first = Actor::New();
627 first.SetProperty( Actor::Property::SIZE, Vector2( 100.0f, 100.0f ) );
628 first.SetProperty( Actor::Property::ANCHOR_POINT,AnchorPoint::TOP_LEFT);
629 application.GetScene().Add(first);
631 Actor second = Actor::New();
632 second.SetProperty( Actor::Property::SIZE, Vector2( 100.0f, 100.0f ) );
633 second.SetProperty( Actor::Property::ANCHOR_POINT,AnchorPoint::TOP_LEFT);
634 second.SetProperty( Actor::Property::POSITION_X, 100.0f);
638 application.SendNotification();
639 application.Render();
642 GestureReceivedFunctor functor(data);
644 TapGestureDetector firstDetector = TapGestureDetector::New();
645 firstDetector.Attach(first);
646 firstDetector.DetectedSignal().Connect(&application, functor);
648 // secondDetector is scoped
650 TapGestureDetector secondDetector = TapGestureDetector::New( 2 );
651 secondDetector.Attach(second);
652 secondDetector.DetectedSignal().Connect(&application, functor);
654 // Tap within second actor's area
655 TestGenerateTap( application, 150.0f, 10.0f, 100 );
656 TestGenerateTap( application, 150.0f, 10.0f, 200 );
658 DALI_TEST_EQUALS(true, data.functorCalled, TEST_LOCATION);
659 DALI_TEST_EQUALS(true, second == data.tappedActor, TEST_LOCATION);
661 // Tap continues as single touch gesture - we should not receive any gesture
663 TestGenerateTap( application, 150.0f, 10.0f, 800 );
664 DALI_TEST_EQUALS(false, data.functorCalled, TEST_LOCATION);
666 // Single touch tap starts - first actor should be panned
668 TestGenerateTap( application, 50.0f, 10.0f, 1400 );
669 DALI_TEST_EQUALS(true, data.functorCalled, TEST_LOCATION);
670 DALI_TEST_EQUALS(true, first == data.tappedActor, TEST_LOCATION);
672 // Pan changes to double-touch - we shouldn't receive event
675 TestGenerateTwoPointTap( application, 50.0f, 10.0f, 60.0f, 20.0f, 2000 );
677 DALI_TEST_EQUALS(false, data.functorCalled, TEST_LOCATION);
683 int UtcDaliTapGestureSignalReceptionMultipleDetectorsOnActor(void)
685 TestApplication application;
687 Actor actor = Actor::New();
688 actor.SetProperty( Actor::Property::SIZE, Vector2( 100.0f, 100.0f ) );
689 actor.SetProperty( Actor::Property::ANCHOR_POINT,AnchorPoint::TOP_LEFT);
690 application.GetScene().Add(actor);
693 application.SendNotification();
694 application.Render();
696 // Attach actor to one detector
697 SignalData firstData;
698 GestureReceivedFunctor firstFunctor(firstData);
699 TapGestureDetector firstDetector = TapGestureDetector::New();
700 firstDetector.Attach(actor);
701 firstDetector.DetectedSignal().Connect(&application, firstFunctor);
703 // Attach actor to another detector
704 SignalData secondData;
705 GestureReceivedFunctor secondFunctor(secondData);
706 TapGestureDetector secondDetector = TapGestureDetector::New();
707 secondDetector.Attach(actor);
708 secondDetector.DetectedSignal().Connect(&application, secondFunctor);
710 // Tap in actor's area - both detector's functors should be called
711 TestGenerateTap( application, 50.0f, 10.0f, 100 );
712 DALI_TEST_EQUALS(true, firstData.functorCalled, TEST_LOCATION);
713 DALI_TEST_EQUALS(true, secondData.functorCalled, TEST_LOCATION);
717 int UtcDaliTapGestureSignalReceptionDifferentPossible(void)
719 TestApplication application;
721 Actor actor = Actor::New();
722 actor.SetProperty( Actor::Property::SIZE, Vector2( 100.0f, 100.0f ) );
723 actor.SetProperty( Actor::Property::ANCHOR_POINT,AnchorPoint::TOP_LEFT);
724 application.GetScene().Add(actor);
727 application.SendNotification();
728 application.Render();
730 // Attach actor to detector
732 GestureReceivedFunctor functor( data );
733 TapGestureDetector detector = TapGestureDetector::New();
734 detector.Attach(actor);
735 detector.DetectedSignal().Connect( &application, functor );
737 // Gesture possible in actor's area.
738 TestStartLongPress( application, 50.0f, 10.0f, 100 );
739 DALI_TEST_EQUALS(false, data.functorCalled, TEST_LOCATION);
741 // Move actor somewhere else
742 actor.SetProperty( Actor::Property::POSITION, Vector2( 100.0f, 100.0f ));
745 application.SendNotification();
746 application.Render();
748 // Emit Started event, we should not receive the tap.
749 TestEndPan( application, Vector2(50.0f, 10.0f), 120 );
750 DALI_TEST_EQUALS(false, data.functorCalled, TEST_LOCATION);
752 // Tap possible in empty area.
753 TestStartLongPress( application, 50.0f, 10.0f, 700 );
754 DALI_TEST_EQUALS(false, data.functorCalled, TEST_LOCATION);
756 // Move actor in to the tap position.
757 actor.SetProperty( Actor::Property::POSITION, Vector2( 0.0f, 0.0f ));
760 application.SendNotification();
761 application.Render();
763 // Emit Started event, we should not receive the tap.
764 TestEndPan( application, Vector2(50.0f, 10.0f), 720 );
765 DALI_TEST_EQUALS(false, data.functorCalled, TEST_LOCATION);
767 // Normal tap in actor's area for completeness.
768 TestGenerateTap( application, 50.0f, 10.0f, 1300 );
769 DALI_TEST_EQUALS(true, data.functorCalled, TEST_LOCATION);
773 int UtcDaliTapGestureActorUnstaged(void)
775 TestApplication application;
777 Actor actor = Actor::New();
778 actor.SetProperty( Actor::Property::SIZE, Vector2( 100.0f, 100.0f ) );
779 actor.SetProperty( Actor::Property::ANCHOR_POINT,AnchorPoint::TOP_LEFT);
780 application.GetScene().Add(actor);
783 application.SendNotification();
784 application.Render();
786 // Attach actor to detector
788 UnstageActorFunctor functor( data, application.GetScene() );
789 TapGestureDetector detector = TapGestureDetector::New();
790 detector.Attach(actor);
791 detector.DetectedSignal().Connect( &application, functor );
793 TestGenerateTap( application, 50.0f, 10.0f, 100 );
794 DALI_TEST_EQUALS( true, data.functorCalled, TEST_LOCATION );
795 tet_result( TET_PASS ); // If we get here, then the actor removal on signal handler was handled gracefully.
799 int UtcDaliTapGestureDetectorRemovedWhilePossible(void)
801 TestApplication application;
803 Actor actor = Actor::New();
804 actor.SetProperty( Actor::Property::SIZE, Vector2( 100.0f, 100.0f ) );
805 actor.SetProperty( Actor::Property::ANCHOR_POINT,AnchorPoint::TOP_LEFT);
806 application.GetScene().Add(actor);
809 application.SendNotification();
810 application.Render();
812 // Attach actor to detector
814 GestureReceivedFunctor functor( data );
815 TapGestureDetector detector = TapGestureDetector::New();
816 detector.Attach(actor);
817 detector.DetectedSignal().Connect( &application, functor );
819 // Emit a possible - Down press, as emitted by long press function
820 TestStartLongPress( application, 50.0f, 10.0f, 100 );
822 // Detach actor and send a Started state, no signal.
823 detector.DetachAll();
824 TestEndPan( application, Vector2(50.0f, 10.0f), 120 );
825 DALI_TEST_EQUALS(false, data.functorCalled, TEST_LOCATION);
829 int UtcDaliTapGestureActorRemovedWhilePossible(void)
831 TestApplication application;
833 Actor actor = Actor::New();
834 actor.SetProperty( Actor::Property::SIZE, Vector2( 100.0f, 100.0f ) );
835 actor.SetProperty( Actor::Property::ANCHOR_POINT,AnchorPoint::TOP_LEFT);
836 application.GetScene().Add(actor);
839 application.SendNotification();
840 application.Render();
842 // Attach actor to detector
844 GestureReceivedFunctor functor( data );
845 TapGestureDetector detector = TapGestureDetector::New();
846 detector.Attach(actor);
847 detector.DetectedSignal().Connect( &application, functor );
849 // Emit a possible - Down press, as emitted by long press function
850 TestStartLongPress( application, 50.0f, 10.0f, 100 );
852 // Remove, render and delete actor
853 application.GetScene().Remove(actor);
854 application.SendNotification();
855 application.Render();
858 // Send a Started state, no signal - Up motion as provided by end pan function
859 TestEndPan( application, Vector2(50.0f, 10.0f), 120 );
860 DALI_TEST_EQUALS(false, data.functorCalled, TEST_LOCATION);
864 int UtcDaliTapGestureLayerConsumesTouch(void)
866 TestApplication application;
868 Actor actor = Actor::New();
869 actor.SetProperty( Actor::Property::SIZE, Vector2( 100.0f, 100.0f ) );
870 actor.SetProperty( Actor::Property::ANCHOR_POINT,AnchorPoint::TOP_LEFT);
871 application.GetScene().Add(actor);
875 GestureReceivedFunctor functor(data);
876 TapGestureDetector detector = TapGestureDetector::New();
877 detector.Attach(actor);
878 detector.DetectedSignal().Connect( &application, functor );
880 // Add a layer to overlap the actor
881 Layer layer = Layer::New();
882 layer.SetProperty( Actor::Property::SIZE, Vector2( 100.0f, 100.0f ) );
883 layer.SetProperty( Actor::Property::ANCHOR_POINT,AnchorPoint::TOP_LEFT);
884 application.GetScene().Add( layer );
888 application.SendNotification();
889 application.Render();
891 // Emit signals, should receive
892 TestGenerateTap( application, 50.0f, 50.0f, 100 );
893 DALI_TEST_EQUALS(true, data.functorCalled, TEST_LOCATION);
896 // Set layer to consume all touch
897 layer.SetProperty( Layer::Property::CONSUMES_TOUCH, true );
900 application.SendNotification();
901 application.Render();
903 // Emit the same signals again, should not receive
904 TestGenerateTap( application, 50.0f, 50.0f, 700 );
905 DALI_TEST_EQUALS(false, data.functorCalled, TEST_LOCATION);
911 int UtcDaliTapGestureInterruptedWhenTouchConsumed(void)
913 TestApplication application;
915 Actor actor = Actor::New();
916 actor.SetProperty( Actor::Property::SIZE, Vector2( 100.0f, 100.0f ) );
917 actor.SetProperty( Actor::Property::ANCHOR_POINT,AnchorPoint::TOP_LEFT);
918 application.GetScene().Add(actor);
920 bool consume = false;
921 TouchEventFunctorConsumeSetter touchFunctor(consume);
922 actor.TouchedSignal().Connect(&application,touchFunctor);
925 application.SendNotification();
926 application.Render();
929 GestureReceivedFunctor functor(data);
931 TapGestureDetector detector = TapGestureDetector::New();
932 detector.Attach(actor);
933 detector.DetectedSignal().Connect(&application, functor);
935 // Start gesture within the actor's area, we should receive the gesture as the touch is NOT being consumed
936 TestGenerateTap( application, 50.0f, 50.0f );
937 DALI_TEST_EQUALS(true, data.functorCalled, TEST_LOCATION);
940 // Another gesture in the same location, this time we will not receive it as touch is being consumed
942 TestGenerateTap( application, 50.0f, 50.0f );
943 DALI_TEST_EQUALS(false, data.functorCalled, TEST_LOCATION);
949 int UtcDaliTapGestureDisableDetectionDuringTapN(void)
951 // Crash sometimes occurred when gesture-recognizer was deleted internally during a signal when the attached actor was detached
953 TestApplication application;
955 Actor actor = Actor::New();
956 actor.SetProperty( Actor::Property::SIZE, Vector2( 100.0f, 100.0f ) );
957 actor.SetProperty( Actor::Property::ANCHOR_POINT,AnchorPoint::TOP_LEFT);
958 application.GetScene().Add(actor);
961 TapGestureDetector detector = TapGestureDetector::New();
962 bool functorCalled = false;
963 detector.Attach( actor );
964 detector.DetectedSignal().Connect(
966 [&detector, &functorCalled](Actor actor, const TapGesture& gesture)
968 detector.Detach(actor);
969 functorCalled = true;
973 application.SendNotification();
974 application.Render();
976 // Try the gesture, should not crash
979 TestGenerateTap( application, 50.0f, 10.0f );
981 DALI_TEST_CHECK( true ); // No crash, test has passed
982 DALI_TEST_EQUALS(functorCalled, true, TEST_LOCATION);
986 DALI_TEST_CHECK( false ); // If we crash, the test has failed