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-utils.h>
26 #include <test-touch-data-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 ///////////////////////////////////////////////////////////////////////////////
44 // Stores data that is populated in the callback and will be read by the TET cases
48 : functorCalled(false),
49 voidFunctorCalled(false)
54 functorCalled = false;
55 voidFunctorCalled = false;
57 receivedGesture.numberOfTaps = 0u;
58 receivedGesture.numberOfTouches = 0u;
59 receivedGesture.screenPoint = Vector2(0.0f, 0.0f);
60 receivedGesture.localPoint = Vector2(0.0f, 0.0f);
66 bool voidFunctorCalled;
67 TapGesture receivedGesture;
71 // Functor that sets the data when called
72 struct GestureReceivedFunctor
74 GestureReceivedFunctor(SignalData& data) : 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 );
103 scene.Remove( actor );
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 const TouchPoint& touchPoint = touch.GetPoint(0);
119 tet_printf("Touch Point state = %d\n", touchPoint.state);
127 ///////////////////////////////////////////////////////////////////////////////
130 // Positive test case for a method
131 int UtcDaliTapGestureDetectorConstructor(void)
133 TestApplication application;
135 TapGestureDetector detector;
136 DALI_TEST_CHECK(!detector);
140 int UtcDaliTapGestureDetectorCopyConstructorP(void)
142 TestApplication application;
144 TapGestureDetector detector = TapGestureDetector::New();
146 TapGestureDetector copy( detector );
147 DALI_TEST_CHECK( detector );
151 int UtcDaliTapGestureDetectorAssignmentOperatorP(void)
153 TestApplication application;
155 TapGestureDetector detector = TapGestureDetector::New();;
157 TapGestureDetector assign;
159 DALI_TEST_CHECK( detector );
161 DALI_TEST_CHECK( detector == assign );
165 int UtcDaliTapGestureDetectorNew(void)
167 TestApplication application;
169 TapGestureDetector detector = TapGestureDetector::New();
170 DALI_TEST_CHECK(detector);
171 DALI_TEST_EQUALS(1u, detector.GetMinimumTapsRequired(), TEST_LOCATION);
172 DALI_TEST_EQUALS(1u, detector.GetMaximumTapsRequired(), TEST_LOCATION);
174 TapGestureDetector detector2 = TapGestureDetector::New( 5u );
175 DALI_TEST_CHECK(detector2);
176 DALI_TEST_EQUALS(5u, detector2.GetMinimumTapsRequired(), TEST_LOCATION);
177 DALI_TEST_EQUALS(5u, detector2.GetMaximumTapsRequired(), TEST_LOCATION);
179 //Scoped test to test destructor
181 TapGestureDetector detector3 = TapGestureDetector::New();
182 DALI_TEST_CHECK(detector3);
185 // Attach an actor and emit a touch event on the actor to ensure complete line coverage
186 Actor actor = Actor::New();
187 actor.SetProperty( Actor::Property::SIZE, Vector2( 100.0f, 100.0f ) );
188 actor.SetProperty( Actor::Property::ANCHOR_POINT,AnchorPoint::TOP_LEFT);
189 application.GetScene().Add(actor);
192 application.SendNotification();
193 application.Render();
195 detector.Attach(actor);
197 TouchEventFunctor touchFunctor;
198 actor.TouchedSignal().Connect( &application, touchFunctor );
200 Integration::TouchEvent touchEvent(1);
201 Integration::Point point;
202 point.SetDeviceId( 1 );
203 point.SetState( PointState::DOWN );
204 point.SetScreenPosition( Vector2( 20.0f, 20.0f ) );
205 touchEvent.AddPoint(point);
206 application.ProcessEvent(touchEvent);
209 application.SendNotification();
210 application.Render();
212 // For line coverage, Initialise default constructor
213 TouchEvent touchEvent2;
217 int UtcDaliTapGestureDetectorDownCast(void)
219 TestApplication application;
220 tet_infoline("Testing Dali::TapGestureDetector::DownCast()");
222 TapGestureDetector detector = TapGestureDetector::New();
224 BaseHandle object(detector);
226 TapGestureDetector detector2 = TapGestureDetector::DownCast(object);
227 DALI_TEST_CHECK(detector2);
229 TapGestureDetector detector3 = DownCast< TapGestureDetector >(object);
230 DALI_TEST_CHECK(detector3);
232 BaseHandle unInitializedObject;
233 TapGestureDetector detector4 = TapGestureDetector::DownCast(unInitializedObject);
234 DALI_TEST_CHECK(!detector4);
236 TapGestureDetector detector5 = DownCast< TapGestureDetector >(unInitializedObject);
237 DALI_TEST_CHECK(!detector5);
239 GestureDetector detector6 = TapGestureDetector::New();
240 TapGestureDetector detector7 = TapGestureDetector::DownCast(detector6);
241 DALI_TEST_CHECK(detector7);
245 int UtcDaliTapGestureSetTapsRequiredMinMaxCheck(void)
247 TestApplication application;
249 // Attach an actor and change the required touches
251 Actor actor = Actor::New();
252 actor.SetProperty( Actor::Property::SIZE, Vector2( 100.0f, 100.0f ) );
253 actor.SetProperty( Actor::Property::ANCHOR_POINT,AnchorPoint::TOP_LEFT);
254 application.GetScene().Add(actor);
257 application.SendNotification();
258 application.Render();
260 // Set the minimum to be greater than the maximum, should Assert
264 TapGestureDetector detector = TapGestureDetector::New();
265 detector.SetMinimumTapsRequired( 7u );
266 detector.SetMaximumTapsRequired( 3u );
267 detector.Attach(actor);
268 DALI_TEST_CHECK( false ); // Should not get here
270 catch ( DaliException& e )
272 DALI_TEST_CHECK( true );
278 int UtcDaliTapGestureGetTapsRequired(void)
280 TestApplication application;
282 TapGestureDetector detector = TapGestureDetector::New();
283 DALI_TEST_EQUALS(1u, detector.GetMinimumTapsRequired(), TEST_LOCATION);
284 DALI_TEST_EQUALS(1u, detector.GetMaximumTapsRequired(), TEST_LOCATION);
288 int UtcDaliTapGestureSignalReceptionNegative(void)
290 TestApplication application;
292 Actor actor = Actor::New();
293 actor.SetProperty( Actor::Property::SIZE, Vector2( 100.0f, 100.0f ) );
294 actor.SetProperty( Actor::Property::ANCHOR_POINT,AnchorPoint::TOP_LEFT);
295 application.GetScene().Add(actor);
298 application.SendNotification();
299 application.Render();
302 GestureReceivedFunctor functor(data);
304 TapGestureDetector detector = TapGestureDetector::New();
305 detector.Attach(actor);
306 detector.DetectedSignal().Connect( &application, functor );
308 // Do a tap outside actor's area
309 TestGenerateTap( application, 112.0f, 112.0f, 100 );
310 DALI_TEST_EQUALS(false, data.functorCalled, TEST_LOCATION);
314 int UtcDaliTapGestureSignalReceptionPositive(void)
316 TestApplication application;
318 Actor actor = Actor::New();
319 actor.SetProperty( Actor::Property::SIZE, Vector2( 100.0f, 100.0f ) );
320 actor.SetProperty( Actor::Property::ANCHOR_POINT,AnchorPoint::TOP_LEFT);
321 application.GetScene().Add(actor);
324 application.SendNotification();
325 application.Render();
328 GestureReceivedFunctor functor(data);
330 TapGestureDetector detector = TapGestureDetector::New();
331 detector.Attach(actor);
332 detector.DetectedSignal().Connect( &application, functor );
334 // Do a tap inside actor's area
335 TestGenerateTap( application, 50.0f, 50.0f, 100 );
336 DALI_TEST_EQUALS(true, data.functorCalled, TEST_LOCATION);
337 DALI_TEST_EQUALS(1u, data.receivedGesture.numberOfTaps, TEST_LOCATION);
338 DALI_TEST_EQUALS(1u, data.receivedGesture.numberOfTouches, TEST_LOCATION);
339 DALI_TEST_EQUALS( Vector2(50.0f, 50.0f), data.receivedGesture.localPoint, 0.1, TEST_LOCATION);
343 int UtcDaliTapGestureSignalReceptionDetach(void)
345 TestApplication application;
347 Actor actor = Actor::New();
348 actor.SetProperty( Actor::Property::SIZE, Vector2( 100.0f, 100.0f ) );
349 actor.SetProperty( Actor::Property::ANCHOR_POINT,AnchorPoint::TOP_LEFT);
350 application.GetScene().Add(actor);
353 application.SendNotification();
354 application.Render();
357 GestureReceivedFunctor functor(data);
359 TapGestureDetector detector = TapGestureDetector::New();
360 detector.Attach(actor);
361 detector.DetectedSignal().Connect(&application, functor);
363 // Start tap within the actor's area
364 TestGenerateTap( application, 20.0f, 20.0f, 100 );
365 DALI_TEST_EQUALS(true, data.functorCalled, TEST_LOCATION);
366 DALI_TEST_EQUALS(1u, data.receivedGesture.numberOfTaps, TEST_LOCATION);
367 DALI_TEST_EQUALS(1u, data.receivedGesture.numberOfTouches, TEST_LOCATION);
368 DALI_TEST_EQUALS( Vector2(20.0f, 20.0f), data.receivedGesture.localPoint, 0.1, TEST_LOCATION);
370 // repeat the tap within the actor's area - we should still receive the signal
372 TestGenerateTap( application, 50.0f, 50.0f, 700 );
373 DALI_TEST_EQUALS(true, data.functorCalled, TEST_LOCATION);
374 DALI_TEST_EQUALS(1u, data.receivedGesture.numberOfTaps, TEST_LOCATION);
375 DALI_TEST_EQUALS(1u, data.receivedGesture.numberOfTouches, TEST_LOCATION);
376 DALI_TEST_EQUALS( Vector2(50.0f, 50.0f), data.receivedGesture.localPoint, 0.1, TEST_LOCATION);
379 detector.DetachAll();
381 // Ensure we are no longer signalled
383 TestGenerateTap( application, 20.0f, 20.0f, 1300 );
384 DALI_TEST_EQUALS(false, data.functorCalled, TEST_LOCATION);
385 TestGenerateTap( application, 50.0f, 50.0f, 1900 );
386 DALI_TEST_EQUALS(false, data.functorCalled, TEST_LOCATION);
390 int UtcDaliTapGestureSignalReceptionActorDestroyedWhileTapping(void)
392 TestApplication application;
395 GestureReceivedFunctor functor(data);
397 TapGestureDetector detector = TapGestureDetector::New();
398 detector.DetectedSignal().Connect(&application, functor);
400 // Actor lifetime is scoped
402 Actor actor = Actor::New();
403 actor.SetProperty( Actor::Property::SIZE, Vector2( 100.0f, 100.0f ) );
404 actor.SetProperty( Actor::Property::ANCHOR_POINT,AnchorPoint::TOP_LEFT);
405 application.GetScene().Add(actor);
408 application.SendNotification();
409 application.Render();
411 detector.Attach(actor);
413 // Start tap within the actor's area
414 TestGenerateTap( application, 20.0f, 20.0f, 100 );
415 DALI_TEST_EQUALS(true, data.functorCalled, TEST_LOCATION);
417 // Remove the actor from stage and reset the data
418 application.GetScene().Remove(actor);
421 application.SendNotification();
422 application.Render();
425 // Actor should now have been destroyed
428 TestGenerateTap( application, 20.0f, 20.0f, 700 );
429 DALI_TEST_EQUALS(false, data.functorCalled, TEST_LOCATION);
433 int UtcDaliTapGestureSignalReceptionRotatedActor(void)
435 TestApplication application;
437 Actor actor = Actor::New();
438 actor.SetProperty( Actor::Property::SIZE, Vector2( 100.0f, 100.0f ) );
439 actor.SetProperty( Actor::Property::ORIENTATION, Quaternion(Dali::Degree(90.0f), Vector3::ZAXIS) );
440 application.GetScene().Add(actor);
443 application.SendNotification();
444 application.Render();
447 GestureReceivedFunctor functor(data);
449 TapGestureDetector detector = TapGestureDetector::New();
450 detector.Attach(actor);
451 detector.DetectedSignal().Connect(&application, functor);
453 // Do tap, only check finished value
454 TestGenerateTap( application, 5.0f, 5.0f, 100 );
455 DALI_TEST_EQUALS(true, data.functorCalled, TEST_LOCATION);
456 DALI_TEST_EQUALS(1u, data.receivedGesture.numberOfTaps, TEST_LOCATION);
457 DALI_TEST_EQUALS(1u, data.receivedGesture.numberOfTouches, TEST_LOCATION);
458 DALI_TEST_EQUALS( Vector2(5.0f, 5.0f), data.receivedGesture.screenPoint, 0.1, TEST_LOCATION);
460 // Rotate actor again and render
461 actor.SetProperty( Actor::Property::ORIENTATION, Quaternion(Dali::Degree(180.0f), Vector3::ZAXIS) );
462 application.SendNotification();
463 application.Render();
465 // Do tap, should still receive event
467 TestGenerateTap( application, 5.0f, 5.0f, 700 );
468 DALI_TEST_EQUALS(true, data.functorCalled, TEST_LOCATION);
469 DALI_TEST_EQUALS(1u, data.receivedGesture.numberOfTaps, TEST_LOCATION);
470 DALI_TEST_EQUALS(1u, data.receivedGesture.numberOfTouches, TEST_LOCATION);
471 DALI_TEST_EQUALS( Vector2(5.0f, 5.0f), data.receivedGesture.screenPoint, 0.1, TEST_LOCATION);
473 // Rotate actor again and render
474 actor.SetProperty( Actor::Property::ORIENTATION, Quaternion(Dali::Degree(90.0f), Vector3::YAXIS) );
475 application.SendNotification();
476 application.Render();
478 // Do tap, inside the actor's area (area if it is not rotated), Should not receive the event
480 TestGenerateTap( application, 70.0f, 70.0f, 1300 );
481 DALI_TEST_EQUALS(false, data.functorCalled, TEST_LOCATION);
485 int UtcDaliTapGestureSignalReceptionChildHit(void)
487 TestApplication application;
489 Actor parent = Actor::New();
490 parent.SetProperty( Actor::Property::SIZE, Vector2( 100.0f, 100.0f ) );
491 parent.SetProperty( Actor::Property::ANCHOR_POINT,AnchorPoint::TOP_LEFT);
492 application.GetScene().Add(parent);
494 // Set child to completely cover parent.
495 // Change rotation of child to be different from parent so that we can check if our local coordinate
496 // conversion of the parent actor is correct.
497 Actor child = Actor::New();
498 child.SetProperty( Actor::Property::SIZE, Vector2( 100.0f, 100.0f ) );
499 child.SetProperty( Actor::Property::ANCHOR_POINT,AnchorPoint::CENTER);
500 child.SetProperty( Actor::Property::PARENT_ORIGIN,ParentOrigin::CENTER);
501 child.SetProperty( Actor::Property::ORIENTATION, Quaternion(Dali::Degree(90.0f), Vector3::ZAXIS) );
504 TouchEventFunctor touchFunctor;
505 child.TouchedSignal().Connect(&application, touchFunctor);
508 application.SendNotification();
509 application.Render();
512 GestureReceivedFunctor functor(data);
514 TapGestureDetector detector = TapGestureDetector::New();
515 detector.Attach(parent);
516 detector.DetectedSignal().Connect(&application, functor);
518 // Do tap - hits child area but parent should still receive it
519 TestGenerateTap( application, 50.0f, 50.0f, 100 );
520 DALI_TEST_EQUALS(true, data.functorCalled, TEST_LOCATION);
521 DALI_TEST_EQUALS(true, parent == data.tappedActor, TEST_LOCATION);
522 DALI_TEST_EQUALS(Vector2(50.0f, 50.0f), data.receivedGesture.screenPoint, 0.01f, TEST_LOCATION);
524 // Attach child and generate same touch points
525 // (Also proves that you can detach and then re-attach another actor)
526 detector.Attach(child);
527 detector.Detach(parent);
529 // Do an entire tap, only check finished value
531 TestGenerateTap( application, 51.0f, 51.0f, 700 );
532 DALI_TEST_EQUALS(true, data.functorCalled, TEST_LOCATION);
533 DALI_TEST_EQUALS(true, child == data.tappedActor, TEST_LOCATION);
534 DALI_TEST_EQUALS(Vector2(51.0f, 51.0f), data.receivedGesture.screenPoint, 0.01f, TEST_LOCATION);
538 int UtcDaliTapGestureSignalReceptionAttachDetachMany(void)
540 TestApplication application;
542 Actor first = Actor::New();
543 first.SetProperty( Actor::Property::SIZE, Vector2( 100.0f, 100.0f ) );
544 first.SetProperty( Actor::Property::ANCHOR_POINT,AnchorPoint::TOP_LEFT);
545 application.GetScene().Add(first);
547 Actor second = Actor::New();
548 second.SetProperty( Actor::Property::SIZE, Vector2( 100.0f, 100.0f ) );
549 second.SetProperty( Actor::Property::POSITION_X, 100.0f);
550 second.SetProperty( Actor::Property::ANCHOR_POINT,AnchorPoint::TOP_LEFT);
551 application.GetScene().Add(second);
554 application.SendNotification();
555 application.Render();
558 GestureReceivedFunctor functor(data);
560 TapGestureDetector detector = TapGestureDetector::New();
561 detector.Attach(first);
562 detector.Attach(second);
563 detector.DetectedSignal().Connect(&application, functor);
565 // Tap within second actor's area
566 TestGenerateTap( application, 120.0f, 10.0f, 100 );
567 DALI_TEST_EQUALS(true, data.functorCalled, TEST_LOCATION);
568 DALI_TEST_EQUALS(true, second == data.tappedActor, TEST_LOCATION);
570 // Tap within first actor's area
572 TestGenerateTap( application, 20.0f, 10.0f, 700 );
573 DALI_TEST_EQUALS(true, data.functorCalled, TEST_LOCATION);
574 DALI_TEST_EQUALS(true, first == data.tappedActor, TEST_LOCATION);
576 // Detach the second actor
577 detector.Detach(second);
579 // second actor shouldn't receive event
581 TestGenerateTap( application, 120.0f, 10.0f, 1300 );
582 DALI_TEST_EQUALS(false, data.functorCalled, TEST_LOCATION);
584 // first actor should continue receiving event
586 TestGenerateTap( application, 20.0f, 10.0f, 1900 );
587 DALI_TEST_EQUALS(true, data.functorCalled, TEST_LOCATION);
591 int UtcDaliTapGestureSignalReceptionActorBecomesUntouchable(void)
593 TestApplication application;
595 Actor actor = Actor::New();
596 actor.SetProperty( Actor::Property::SIZE, Vector2( 100.0f, 100.0f ) );
597 actor.SetProperty( Actor::Property::ANCHOR_POINT,AnchorPoint::TOP_LEFT);
598 application.GetScene().Add(actor);
601 application.SendNotification();
602 application.Render();
605 GestureReceivedFunctor functor(data);
607 TapGestureDetector detector = TapGestureDetector::New();
608 detector.Attach(actor);
609 detector.DetectedSignal().Connect(&application, functor);
611 // Tap in actor's area
612 TestGenerateTap( application, 50.0f, 10.0f, 100 );
613 DALI_TEST_EQUALS(true, data.functorCalled, TEST_LOCATION);
615 // Actor become invisible - actor should not receive the next pan
616 actor.SetProperty( Actor::Property::VISIBLE,false);
619 application.SendNotification();
620 application.Render();
622 // Tap in the same area, shouldn't receive event
624 TestGenerateTap( application, 50.0f, 10.0f, 700 );
625 DALI_TEST_EQUALS(false, data.functorCalled, TEST_LOCATION);
629 int UtcDaliTapGestureSignalReceptionMultipleGestureDetectors(void)
631 TestApplication application;
633 Actor first = Actor::New();
634 first.SetProperty( Actor::Property::SIZE, Vector2( 100.0f, 100.0f ) );
635 first.SetProperty( Actor::Property::ANCHOR_POINT,AnchorPoint::TOP_LEFT);
636 application.GetScene().Add(first);
638 Actor second = Actor::New();
639 second.SetProperty( Actor::Property::SIZE, Vector2( 100.0f, 100.0f ) );
640 second.SetProperty( Actor::Property::ANCHOR_POINT,AnchorPoint::TOP_LEFT);
641 second.SetProperty( Actor::Property::POSITION_X, 100.0f);
645 application.SendNotification();
646 application.Render();
649 GestureReceivedFunctor functor(data);
651 TapGestureDetector firstDetector = TapGestureDetector::New();
652 firstDetector.Attach(first);
653 firstDetector.DetectedSignal().Connect(&application, functor);
655 // secondDetector is scoped
657 TapGestureDetector secondDetector = TapGestureDetector::New( 2 );
658 secondDetector.Attach(second);
659 secondDetector.DetectedSignal().Connect(&application, functor);
661 // Tap within second actor's area
662 TestGenerateTap( application, 150.0f, 10.0f, 100 );
663 TestGenerateTap( application, 150.0f, 10.0f, 200 );
665 DALI_TEST_EQUALS(true, data.functorCalled, TEST_LOCATION);
666 DALI_TEST_EQUALS(true, second == data.tappedActor, TEST_LOCATION);
668 // Tap continues as single touch gesture - we should not receive any gesture
670 TestGenerateTap( application, 150.0f, 10.0f, 800 );
671 DALI_TEST_EQUALS(false, data.functorCalled, TEST_LOCATION);
673 // Single touch tap starts - first actor should be panned
675 TestGenerateTap( application, 50.0f, 10.0f, 1400 );
676 DALI_TEST_EQUALS(true, data.functorCalled, TEST_LOCATION);
677 DALI_TEST_EQUALS(true, first == data.tappedActor, TEST_LOCATION);
679 // Pan changes to double-touch - we shouldn't receive event
682 TestGenerateTwoPointTap( application, 50.0f, 10.0f, 60.0f, 20.0f, 2000 );
684 DALI_TEST_EQUALS(false, data.functorCalled, TEST_LOCATION);
690 int UtcDaliTapGestureSignalReceptionMultipleDetectorsOnActor(void)
692 TestApplication application;
694 Actor actor = Actor::New();
695 actor.SetProperty( Actor::Property::SIZE, Vector2( 100.0f, 100.0f ) );
696 actor.SetProperty( Actor::Property::ANCHOR_POINT,AnchorPoint::TOP_LEFT);
697 application.GetScene().Add(actor);
700 application.SendNotification();
701 application.Render();
703 // Attach actor to one detector
704 SignalData firstData;
705 GestureReceivedFunctor firstFunctor(firstData);
706 TapGestureDetector firstDetector = TapGestureDetector::New();
707 firstDetector.Attach(actor);
708 firstDetector.DetectedSignal().Connect(&application, firstFunctor);
710 // Attach actor to another detector
711 SignalData secondData;
712 GestureReceivedFunctor secondFunctor(secondData);
713 TapGestureDetector secondDetector = TapGestureDetector::New();
714 secondDetector.Attach(actor);
715 secondDetector.DetectedSignal().Connect(&application, secondFunctor);
717 // Tap in actor's area - both detector's functors should be called
718 TestGenerateTap( application, 50.0f, 10.0f, 100 );
719 DALI_TEST_EQUALS(true, firstData.functorCalled, TEST_LOCATION);
720 DALI_TEST_EQUALS(true, secondData.functorCalled, TEST_LOCATION);
724 int UtcDaliTapGestureSignalReceptionDifferentPossible(void)
726 TestApplication application;
728 Actor actor = Actor::New();
729 actor.SetProperty( Actor::Property::SIZE, Vector2( 100.0f, 100.0f ) );
730 actor.SetProperty( Actor::Property::ANCHOR_POINT,AnchorPoint::TOP_LEFT);
731 application.GetScene().Add(actor);
734 application.SendNotification();
735 application.Render();
737 // Attach actor to detector
739 GestureReceivedFunctor functor( data );
740 TapGestureDetector detector = TapGestureDetector::New();
741 detector.Attach(actor);
742 detector.DetectedSignal().Connect( &application, functor );
744 // Gesture possible in actor's area.
745 TestStartLongPress( application, 50.0f, 10.0f, 100 );
746 DALI_TEST_EQUALS(false, data.functorCalled, TEST_LOCATION);
748 // Move actor somewhere else
749 actor.SetProperty( Actor::Property::POSITION, Vector2( 100.0f, 100.0f ));
752 application.SendNotification();
753 application.Render();
755 // Emit Started event, we should not receive the tap.
756 TestEndPan( application, Vector2(50.0f, 10.0f), 120 );
757 DALI_TEST_EQUALS(false, data.functorCalled, TEST_LOCATION);
759 // Tap possible in empty area.
760 TestStartLongPress( application, 50.0f, 10.0f, 700 );
761 DALI_TEST_EQUALS(false, data.functorCalled, TEST_LOCATION);
763 // Move actor in to the tap position.
764 actor.SetProperty( Actor::Property::POSITION, Vector2( 0.0f, 0.0f ));
767 application.SendNotification();
768 application.Render();
770 // Emit Started event, we should not receive the tap.
771 TestEndPan( application, Vector2(50.0f, 10.0f), 720 );
772 DALI_TEST_EQUALS(false, data.functorCalled, TEST_LOCATION);
774 // Normal tap in actor's area for completeness.
775 TestGenerateTap( application, 50.0f, 10.0f, 1300 );
776 DALI_TEST_EQUALS(true, data.functorCalled, TEST_LOCATION);
780 int UtcDaliTapGestureActorUnstaged(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 // Attach actor to detector
795 UnstageActorFunctor functor( data, application.GetScene() );
796 TapGestureDetector detector = TapGestureDetector::New();
797 detector.Attach(actor);
798 detector.DetectedSignal().Connect( &application, functor );
800 TestGenerateTap( application, 50.0f, 10.0f, 100 );
801 DALI_TEST_EQUALS( true, data.functorCalled, TEST_LOCATION );
802 tet_result( TET_PASS ); // If we get here, then the actor removal on signal handler was handled gracefully.
806 int UtcDaliTapGestureDetectorRemovedWhilePossible(void)
808 TestApplication application;
810 Actor actor = Actor::New();
811 actor.SetProperty( Actor::Property::SIZE, Vector2( 100.0f, 100.0f ) );
812 actor.SetProperty( Actor::Property::ANCHOR_POINT,AnchorPoint::TOP_LEFT);
813 application.GetScene().Add(actor);
816 application.SendNotification();
817 application.Render();
819 // Attach actor to detector
821 GestureReceivedFunctor functor( data );
822 TapGestureDetector detector = TapGestureDetector::New();
823 detector.Attach(actor);
824 detector.DetectedSignal().Connect( &application, functor );
826 // Emit a possible - Down press, as emitted by long press function
827 TestStartLongPress( application, 50.0f, 10.0f, 100 );
829 // Detach actor and send a Started state, no signal.
830 detector.DetachAll();
831 TestEndPan( application, Vector2(50.0f, 10.0f), 120 );
832 DALI_TEST_EQUALS(false, data.functorCalled, TEST_LOCATION);
836 int UtcDaliTapGestureActorRemovedWhilePossible(void)
838 TestApplication application;
840 Actor actor = Actor::New();
841 actor.SetProperty( Actor::Property::SIZE, Vector2( 100.0f, 100.0f ) );
842 actor.SetProperty( Actor::Property::ANCHOR_POINT,AnchorPoint::TOP_LEFT);
843 application.GetScene().Add(actor);
846 application.SendNotification();
847 application.Render();
849 // Attach actor to detector
851 GestureReceivedFunctor functor( data );
852 TapGestureDetector detector = TapGestureDetector::New();
853 detector.Attach(actor);
854 detector.DetectedSignal().Connect( &application, functor );
856 // Emit a possible - Down press, as emitted by long press function
857 TestStartLongPress( application, 50.0f, 10.0f, 100 );
859 // Remove, render and delete actor
860 application.GetScene().Remove(actor);
861 application.SendNotification();
862 application.Render();
865 // Send a Started state, no signal - Up motion as provided by end pan function
866 TestEndPan( application, Vector2(50.0f, 10.0f), 120 );
867 DALI_TEST_EQUALS(false, data.functorCalled, TEST_LOCATION);
871 int UtcDaliTapGestureLayerConsumesTouch(void)
873 TestApplication application;
875 Actor actor = Actor::New();
876 actor.SetProperty( Actor::Property::SIZE, Vector2( 100.0f, 100.0f ) );
877 actor.SetProperty( Actor::Property::ANCHOR_POINT,AnchorPoint::TOP_LEFT);
878 application.GetScene().Add(actor);
882 GestureReceivedFunctor functor(data);
883 TapGestureDetector detector = TapGestureDetector::New();
884 detector.Attach(actor);
885 detector.DetectedSignal().Connect( &application, functor );
887 // Add a layer to overlap the actor
888 Layer layer = Layer::New();
889 layer.SetProperty( Actor::Property::SIZE, Vector2( 100.0f, 100.0f ) );
890 layer.SetProperty( Actor::Property::ANCHOR_POINT,AnchorPoint::TOP_LEFT);
891 application.GetScene().Add( layer );
895 application.SendNotification();
896 application.Render();
898 // Emit signals, should receive
899 TestGenerateTap( application, 50.0f, 50.0f, 100 );
900 DALI_TEST_EQUALS(true, data.functorCalled, TEST_LOCATION);
903 // Set layer to consume all touch
904 layer.SetProperty( Layer::Property::CONSUMES_TOUCH, true );
907 application.SendNotification();
908 application.Render();
910 // Emit the same signals again, should not receive
911 TestGenerateTap( application, 50.0f, 50.0f, 700 );
912 DALI_TEST_EQUALS(false, data.functorCalled, TEST_LOCATION);
918 int UtcDaliTapGestureInterruptedWhenTouchConsumed(void)
920 TestApplication application;
922 Actor actor = Actor::New();
923 actor.SetProperty( Actor::Property::SIZE, Vector2( 100.0f, 100.0f ) );
924 actor.SetProperty( Actor::Property::ANCHOR_POINT,AnchorPoint::TOP_LEFT);
925 application.GetScene().Add(actor);
927 bool consume = false;
928 TouchDataFunctorConsumeSetter touchFunctor(consume);
929 actor.TouchSignal().Connect(&application,touchFunctor);
932 application.SendNotification();
933 application.Render();
936 GestureReceivedFunctor functor(data);
938 TapGestureDetector detector = TapGestureDetector::New();
939 detector.Attach(actor);
940 detector.DetectedSignal().Connect(&application, functor);
942 // Start gesture within the actor's area, we should receive the gesture as the touch is NOT being consumed
943 TestGenerateTap( application, 50.0f, 50.0f );
944 DALI_TEST_EQUALS(true, data.functorCalled, TEST_LOCATION);
947 // Another gesture in the same location, this time we will not receive it as touch is being consumed
949 TestGenerateTap( application, 50.0f, 50.0f );
950 DALI_TEST_EQUALS(false, data.functorCalled, TEST_LOCATION);