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>
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.numberOfTaps = 0u;
57 receivedGesture.numberOfTouches = 0u;
58 receivedGesture.screenPoint = Vector2(0.0f, 0.0f);
59 receivedGesture.localPoint = Vector2(0.0f, 0.0f);
65 bool voidFunctorCalled;
66 TapGesture receivedGesture;
70 // Functor that sets the data when called
71 struct GestureReceivedFunctor
73 GestureReceivedFunctor(SignalData& data) : 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 );
102 scene.Remove( actor );
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 const TouchPoint& touchPoint = touch.GetPoint(0);
118 tet_printf("Touch Point state = %d\n", touchPoint.state);
126 ///////////////////////////////////////////////////////////////////////////////
129 // Positive test case for a method
130 int UtcDaliTapGestureDetectorConstructor(void)
132 TestApplication application;
134 TapGestureDetector detector;
135 DALI_TEST_CHECK(!detector);
139 int UtcDaliTapGestureDetectorCopyConstructorP(void)
141 TestApplication application;
143 TapGestureDetector detector = TapGestureDetector::New();
145 TapGestureDetector copy( detector );
146 DALI_TEST_CHECK( detector );
150 int UtcDaliTapGestureDetectorAssignmentOperatorP(void)
152 TestApplication application;
154 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();
211 // For line coverage, Initialise default constructor
212 TouchEvent touchEvent2;
216 int UtcDaliTapGestureDetectorDownCast(void)
218 TestApplication application;
219 tet_infoline("Testing Dali::TapGestureDetector::DownCast()");
221 TapGestureDetector detector = TapGestureDetector::New();
223 BaseHandle object(detector);
225 TapGestureDetector detector2 = TapGestureDetector::DownCast(object);
226 DALI_TEST_CHECK(detector2);
228 TapGestureDetector detector3 = DownCast< TapGestureDetector >(object);
229 DALI_TEST_CHECK(detector3);
231 BaseHandle unInitializedObject;
232 TapGestureDetector detector4 = TapGestureDetector::DownCast(unInitializedObject);
233 DALI_TEST_CHECK(!detector4);
235 TapGestureDetector detector5 = DownCast< TapGestureDetector >(unInitializedObject);
236 DALI_TEST_CHECK(!detector5);
238 GestureDetector detector6 = TapGestureDetector::New();
239 TapGestureDetector detector7 = TapGestureDetector::DownCast(detector6);
240 DALI_TEST_CHECK(detector7);
244 int UtcDaliTapGestureSetTapsRequiredMinMaxCheck(void)
246 TestApplication application;
248 // Attach an actor and change the required touches
250 Actor actor = Actor::New();
251 actor.SetProperty( Actor::Property::SIZE, Vector2( 100.0f, 100.0f ) );
252 actor.SetProperty( Actor::Property::ANCHOR_POINT,AnchorPoint::TOP_LEFT);
253 application.GetScene().Add(actor);
256 application.SendNotification();
257 application.Render();
259 // Set the minimum to be greater than the maximum, should Assert
263 TapGestureDetector detector = TapGestureDetector::New();
264 detector.SetMinimumTapsRequired( 7u );
265 detector.SetMaximumTapsRequired( 3u );
266 detector.Attach(actor);
267 DALI_TEST_CHECK( false ); // Should not get here
269 catch ( DaliException& e )
271 DALI_TEST_CHECK( true );
277 int UtcDaliTapGestureGetTapsRequired(void)
279 TestApplication application;
281 TapGestureDetector detector = TapGestureDetector::New();
282 DALI_TEST_EQUALS(1u, detector.GetMinimumTapsRequired(), TEST_LOCATION);
283 DALI_TEST_EQUALS(1u, detector.GetMaximumTapsRequired(), TEST_LOCATION);
287 int UtcDaliTapGestureSignalReceptionNegative(void)
289 TestApplication application;
291 Actor actor = Actor::New();
292 actor.SetProperty( Actor::Property::SIZE, Vector2( 100.0f, 100.0f ) );
293 actor.SetProperty( Actor::Property::ANCHOR_POINT,AnchorPoint::TOP_LEFT);
294 application.GetScene().Add(actor);
297 application.SendNotification();
298 application.Render();
301 GestureReceivedFunctor functor(data);
303 TapGestureDetector detector = TapGestureDetector::New();
304 detector.Attach(actor);
305 detector.DetectedSignal().Connect( &application, functor );
307 // Do a tap outside actor's area
308 TestGenerateTap( application, 112.0f, 112.0f, 100 );
309 DALI_TEST_EQUALS(false, data.functorCalled, TEST_LOCATION);
313 int UtcDaliTapGestureSignalReceptionPositive(void)
315 TestApplication application;
317 Actor actor = Actor::New();
318 actor.SetProperty( Actor::Property::SIZE, Vector2( 100.0f, 100.0f ) );
319 actor.SetProperty( Actor::Property::ANCHOR_POINT,AnchorPoint::TOP_LEFT);
320 application.GetScene().Add(actor);
323 application.SendNotification();
324 application.Render();
327 GestureReceivedFunctor functor(data);
329 TapGestureDetector detector = TapGestureDetector::New();
330 detector.Attach(actor);
331 detector.DetectedSignal().Connect( &application, functor );
333 // Do a tap inside actor's area
334 TestGenerateTap( application, 50.0f, 50.0f, 100 );
335 DALI_TEST_EQUALS(true, data.functorCalled, TEST_LOCATION);
336 DALI_TEST_EQUALS(1u, data.receivedGesture.numberOfTaps, TEST_LOCATION);
337 DALI_TEST_EQUALS(1u, data.receivedGesture.numberOfTouches, TEST_LOCATION);
338 DALI_TEST_EQUALS( Vector2(50.0f, 50.0f), data.receivedGesture.localPoint, 0.1, TEST_LOCATION);
342 int UtcDaliTapGestureSignalReceptionDetach(void)
344 TestApplication application;
346 Actor actor = Actor::New();
347 actor.SetProperty( Actor::Property::SIZE, Vector2( 100.0f, 100.0f ) );
348 actor.SetProperty( Actor::Property::ANCHOR_POINT,AnchorPoint::TOP_LEFT);
349 application.GetScene().Add(actor);
352 application.SendNotification();
353 application.Render();
356 GestureReceivedFunctor functor(data);
358 TapGestureDetector detector = TapGestureDetector::New();
359 detector.Attach(actor);
360 detector.DetectedSignal().Connect(&application, functor);
362 // Start tap within the actor's area
363 TestGenerateTap( application, 20.0f, 20.0f, 100 );
364 DALI_TEST_EQUALS(true, data.functorCalled, TEST_LOCATION);
365 DALI_TEST_EQUALS(1u, data.receivedGesture.numberOfTaps, TEST_LOCATION);
366 DALI_TEST_EQUALS(1u, data.receivedGesture.numberOfTouches, TEST_LOCATION);
367 DALI_TEST_EQUALS( Vector2(20.0f, 20.0f), data.receivedGesture.localPoint, 0.1, TEST_LOCATION);
369 // repeat the tap within the actor's area - we should still receive the signal
371 TestGenerateTap( application, 50.0f, 50.0f, 700 );
372 DALI_TEST_EQUALS(true, data.functorCalled, TEST_LOCATION);
373 DALI_TEST_EQUALS(1u, data.receivedGesture.numberOfTaps, TEST_LOCATION);
374 DALI_TEST_EQUALS(1u, data.receivedGesture.numberOfTouches, TEST_LOCATION);
375 DALI_TEST_EQUALS( Vector2(50.0f, 50.0f), data.receivedGesture.localPoint, 0.1, TEST_LOCATION);
378 detector.DetachAll();
380 // Ensure we are no longer signalled
382 TestGenerateTap( application, 20.0f, 20.0f, 1300 );
383 DALI_TEST_EQUALS(false, data.functorCalled, TEST_LOCATION);
384 TestGenerateTap( application, 50.0f, 50.0f, 1900 );
385 DALI_TEST_EQUALS(false, data.functorCalled, TEST_LOCATION);
389 int UtcDaliTapGestureSignalReceptionActorDestroyedWhileTapping(void)
391 TestApplication application;
394 GestureReceivedFunctor functor(data);
396 TapGestureDetector detector = TapGestureDetector::New();
397 detector.DetectedSignal().Connect(&application, functor);
399 // Actor lifetime is scoped
401 Actor actor = Actor::New();
402 actor.SetProperty( Actor::Property::SIZE, Vector2( 100.0f, 100.0f ) );
403 actor.SetProperty( Actor::Property::ANCHOR_POINT,AnchorPoint::TOP_LEFT);
404 application.GetScene().Add(actor);
407 application.SendNotification();
408 application.Render();
410 detector.Attach(actor);
412 // Start tap within the actor's area
413 TestGenerateTap( application, 20.0f, 20.0f, 100 );
414 DALI_TEST_EQUALS(true, data.functorCalled, TEST_LOCATION);
416 // Remove the actor from stage and reset the data
417 application.GetScene().Remove(actor);
420 application.SendNotification();
421 application.Render();
424 // Actor should now have been destroyed
427 TestGenerateTap( application, 20.0f, 20.0f, 700 );
428 DALI_TEST_EQUALS(false, data.functorCalled, TEST_LOCATION);
432 int UtcDaliTapGestureSignalReceptionRotatedActor(void)
434 TestApplication application;
436 Actor actor = Actor::New();
437 actor.SetProperty( Actor::Property::SIZE, Vector2( 100.0f, 100.0f ) );
438 actor.SetProperty( Actor::Property::ORIENTATION, Quaternion(Dali::Degree(90.0f), Vector3::ZAXIS) );
439 application.GetScene().Add(actor);
442 application.SendNotification();
443 application.Render();
446 GestureReceivedFunctor functor(data);
448 TapGestureDetector detector = TapGestureDetector::New();
449 detector.Attach(actor);
450 detector.DetectedSignal().Connect(&application, functor);
452 // Do tap, only check finished value
453 TestGenerateTap( application, 5.0f, 5.0f, 100 );
454 DALI_TEST_EQUALS(true, data.functorCalled, TEST_LOCATION);
455 DALI_TEST_EQUALS(1u, data.receivedGesture.numberOfTaps, TEST_LOCATION);
456 DALI_TEST_EQUALS(1u, data.receivedGesture.numberOfTouches, TEST_LOCATION);
457 DALI_TEST_EQUALS( Vector2(5.0f, 5.0f), data.receivedGesture.screenPoint, 0.1, TEST_LOCATION);
459 // Rotate actor again and render
460 actor.SetProperty( Actor::Property::ORIENTATION, Quaternion(Dali::Degree(180.0f), Vector3::ZAXIS) );
461 application.SendNotification();
462 application.Render();
464 // Do tap, should still receive event
466 TestGenerateTap( application, 5.0f, 5.0f, 700 );
467 DALI_TEST_EQUALS(true, data.functorCalled, TEST_LOCATION);
468 DALI_TEST_EQUALS(1u, data.receivedGesture.numberOfTaps, TEST_LOCATION);
469 DALI_TEST_EQUALS(1u, data.receivedGesture.numberOfTouches, TEST_LOCATION);
470 DALI_TEST_EQUALS( Vector2(5.0f, 5.0f), data.receivedGesture.screenPoint, 0.1, TEST_LOCATION);
472 // Rotate actor again and render
473 actor.SetProperty( Actor::Property::ORIENTATION, Quaternion(Dali::Degree(90.0f), Vector3::YAXIS) );
474 application.SendNotification();
475 application.Render();
477 // Do tap, inside the actor's area (area if it is not rotated), Should not receive the event
479 TestGenerateTap( application, 70.0f, 70.0f, 1300 );
480 DALI_TEST_EQUALS(false, data.functorCalled, TEST_LOCATION);
484 int UtcDaliTapGestureSignalReceptionChildHit(void)
486 TestApplication application;
488 Actor parent = Actor::New();
489 parent.SetProperty( Actor::Property::SIZE, Vector2( 100.0f, 100.0f ) );
490 parent.SetProperty( Actor::Property::ANCHOR_POINT,AnchorPoint::TOP_LEFT);
491 application.GetScene().Add(parent);
493 // Set child to completely cover parent.
494 // Change rotation of child to be different from parent so that we can check if our local coordinate
495 // conversion of the parent actor is correct.
496 Actor child = Actor::New();
497 child.SetProperty( Actor::Property::SIZE, Vector2( 100.0f, 100.0f ) );
498 child.SetProperty( Actor::Property::ANCHOR_POINT,AnchorPoint::CENTER);
499 child.SetProperty( Actor::Property::PARENT_ORIGIN,ParentOrigin::CENTER);
500 child.SetProperty( Actor::Property::ORIENTATION, Quaternion(Dali::Degree(90.0f), Vector3::ZAXIS) );
503 TouchEventFunctor touchFunctor;
504 child.TouchedSignal().Connect(&application, touchFunctor);
507 application.SendNotification();
508 application.Render();
511 GestureReceivedFunctor functor(data);
513 TapGestureDetector detector = TapGestureDetector::New();
514 detector.Attach(parent);
515 detector.DetectedSignal().Connect(&application, functor);
517 // Do tap - hits child area but parent should still receive it
518 TestGenerateTap( application, 50.0f, 50.0f, 100 );
519 DALI_TEST_EQUALS(true, data.functorCalled, TEST_LOCATION);
520 DALI_TEST_EQUALS(true, parent == data.tappedActor, TEST_LOCATION);
521 DALI_TEST_EQUALS(Vector2(50.0f, 50.0f), data.receivedGesture.screenPoint, 0.01f, TEST_LOCATION);
523 // Attach child and generate same touch points
524 // (Also proves that you can detach and then re-attach another actor)
525 detector.Attach(child);
526 detector.Detach(parent);
528 // Do an entire tap, only check finished value
530 TestGenerateTap( application, 51.0f, 51.0f, 700 );
531 DALI_TEST_EQUALS(true, data.functorCalled, TEST_LOCATION);
532 DALI_TEST_EQUALS(true, child == data.tappedActor, TEST_LOCATION);
533 DALI_TEST_EQUALS(Vector2(51.0f, 51.0f), data.receivedGesture.screenPoint, 0.01f, TEST_LOCATION);
537 int UtcDaliTapGestureSignalReceptionAttachDetachMany(void)
539 TestApplication application;
541 Actor first = Actor::New();
542 first.SetProperty( Actor::Property::SIZE, Vector2( 100.0f, 100.0f ) );
543 first.SetProperty( Actor::Property::ANCHOR_POINT,AnchorPoint::TOP_LEFT);
544 application.GetScene().Add(first);
546 Actor second = Actor::New();
547 second.SetProperty( Actor::Property::SIZE, Vector2( 100.0f, 100.0f ) );
548 second.SetProperty( Actor::Property::POSITION_X, 100.0f);
549 second.SetProperty( Actor::Property::ANCHOR_POINT,AnchorPoint::TOP_LEFT);
550 application.GetScene().Add(second);
553 application.SendNotification();
554 application.Render();
557 GestureReceivedFunctor functor(data);
559 TapGestureDetector detector = TapGestureDetector::New();
560 detector.Attach(first);
561 detector.Attach(second);
562 detector.DetectedSignal().Connect(&application, functor);
564 // Tap within second actor's area
565 TestGenerateTap( application, 120.0f, 10.0f, 100 );
566 DALI_TEST_EQUALS(true, data.functorCalled, TEST_LOCATION);
567 DALI_TEST_EQUALS(true, second == data.tappedActor, TEST_LOCATION);
569 // Tap within first actor's area
571 TestGenerateTap( application, 20.0f, 10.0f, 700 );
572 DALI_TEST_EQUALS(true, data.functorCalled, TEST_LOCATION);
573 DALI_TEST_EQUALS(true, first == data.tappedActor, TEST_LOCATION);
575 // Detach the second actor
576 detector.Detach(second);
578 // second actor shouldn't receive event
580 TestGenerateTap( application, 120.0f, 10.0f, 1300 );
581 DALI_TEST_EQUALS(false, data.functorCalled, TEST_LOCATION);
583 // first actor should continue receiving event
585 TestGenerateTap( application, 20.0f, 10.0f, 1900 );
586 DALI_TEST_EQUALS(true, data.functorCalled, TEST_LOCATION);
590 int UtcDaliTapGestureSignalReceptionActorBecomesUntouchable(void)
592 TestApplication application;
594 Actor actor = Actor::New();
595 actor.SetProperty( Actor::Property::SIZE, Vector2( 100.0f, 100.0f ) );
596 actor.SetProperty( Actor::Property::ANCHOR_POINT,AnchorPoint::TOP_LEFT);
597 application.GetScene().Add(actor);
600 application.SendNotification();
601 application.Render();
604 GestureReceivedFunctor functor(data);
606 TapGestureDetector detector = TapGestureDetector::New();
607 detector.Attach(actor);
608 detector.DetectedSignal().Connect(&application, functor);
610 // Tap in actor's area
611 TestGenerateTap( application, 50.0f, 10.0f, 100 );
612 DALI_TEST_EQUALS(true, data.functorCalled, TEST_LOCATION);
614 // Actor become invisible - actor should not receive the next pan
615 actor.SetProperty( Actor::Property::VISIBLE,false);
618 application.SendNotification();
619 application.Render();
621 // Tap in the same area, shouldn't receive event
623 TestGenerateTap( application, 50.0f, 10.0f, 700 );
624 DALI_TEST_EQUALS(false, data.functorCalled, TEST_LOCATION);
628 int UtcDaliTapGestureSignalReceptionMultipleGestureDetectors(void)
630 TestApplication application;
632 Actor first = Actor::New();
633 first.SetProperty( Actor::Property::SIZE, Vector2( 100.0f, 100.0f ) );
634 first.SetProperty( Actor::Property::ANCHOR_POINT,AnchorPoint::TOP_LEFT);
635 application.GetScene().Add(first);
637 Actor second = Actor::New();
638 second.SetProperty( Actor::Property::SIZE, Vector2( 100.0f, 100.0f ) );
639 second.SetProperty( Actor::Property::ANCHOR_POINT,AnchorPoint::TOP_LEFT);
640 second.SetProperty( Actor::Property::POSITION_X, 100.0f);
644 application.SendNotification();
645 application.Render();
648 GestureReceivedFunctor functor(data);
650 TapGestureDetector firstDetector = TapGestureDetector::New();
651 firstDetector.Attach(first);
652 firstDetector.DetectedSignal().Connect(&application, functor);
654 // secondDetector is scoped
656 TapGestureDetector secondDetector = TapGestureDetector::New( 2 );
657 secondDetector.Attach(second);
658 secondDetector.DetectedSignal().Connect(&application, functor);
660 // Tap within second actor's area
661 TestGenerateTap( application, 150.0f, 10.0f, 100 );
662 TestGenerateTap( application, 150.0f, 10.0f, 200 );
664 DALI_TEST_EQUALS(true, data.functorCalled, TEST_LOCATION);
665 DALI_TEST_EQUALS(true, second == data.tappedActor, TEST_LOCATION);
667 // Tap continues as single touch gesture - we should not receive any gesture
669 TestGenerateTap( application, 150.0f, 10.0f, 800 );
670 DALI_TEST_EQUALS(false, data.functorCalled, TEST_LOCATION);
672 // Single touch tap starts - first actor should be panned
674 TestGenerateTap( application, 50.0f, 10.0f, 1400 );
675 DALI_TEST_EQUALS(true, data.functorCalled, TEST_LOCATION);
676 DALI_TEST_EQUALS(true, first == data.tappedActor, TEST_LOCATION);
678 // Pan changes to double-touch - we shouldn't receive event
681 TestGenerateTwoPointTap( application, 50.0f, 10.0f, 60.0f, 20.0f, 2000 );
683 DALI_TEST_EQUALS(false, data.functorCalled, TEST_LOCATION);
689 int UtcDaliTapGestureSignalReceptionMultipleDetectorsOnActor(void)
691 TestApplication application;
693 Actor actor = Actor::New();
694 actor.SetProperty( Actor::Property::SIZE, Vector2( 100.0f, 100.0f ) );
695 actor.SetProperty( Actor::Property::ANCHOR_POINT,AnchorPoint::TOP_LEFT);
696 application.GetScene().Add(actor);
699 application.SendNotification();
700 application.Render();
702 // Attach actor to one detector
703 SignalData firstData;
704 GestureReceivedFunctor firstFunctor(firstData);
705 TapGestureDetector firstDetector = TapGestureDetector::New();
706 firstDetector.Attach(actor);
707 firstDetector.DetectedSignal().Connect(&application, firstFunctor);
709 // Attach actor to another detector
710 SignalData secondData;
711 GestureReceivedFunctor secondFunctor(secondData);
712 TapGestureDetector secondDetector = TapGestureDetector::New();
713 secondDetector.Attach(actor);
714 secondDetector.DetectedSignal().Connect(&application, secondFunctor);
716 // Tap in actor's area - both detector's functors should be called
717 TestGenerateTap( application, 50.0f, 10.0f, 100 );
718 DALI_TEST_EQUALS(true, firstData.functorCalled, TEST_LOCATION);
719 DALI_TEST_EQUALS(true, secondData.functorCalled, TEST_LOCATION);
723 int UtcDaliTapGestureSignalReceptionDifferentPossible(void)
725 TestApplication application;
727 Actor actor = Actor::New();
728 actor.SetProperty( Actor::Property::SIZE, Vector2( 100.0f, 100.0f ) );
729 actor.SetProperty( Actor::Property::ANCHOR_POINT,AnchorPoint::TOP_LEFT);
730 application.GetScene().Add(actor);
733 application.SendNotification();
734 application.Render();
736 // Attach actor to detector
738 GestureReceivedFunctor functor( data );
739 TapGestureDetector detector = TapGestureDetector::New();
740 detector.Attach(actor);
741 detector.DetectedSignal().Connect( &application, functor );
743 // Gesture possible in actor's area.
744 TestStartLongPress( application, 50.0f, 10.0f, 100 );
745 DALI_TEST_EQUALS(false, data.functorCalled, TEST_LOCATION);
747 // Move actor somewhere else
748 actor.SetProperty( Actor::Property::POSITION, Vector2( 100.0f, 100.0f ));
751 application.SendNotification();
752 application.Render();
754 // Emit Started event, we should not receive the tap.
755 TestEndPan( application, Vector2(50.0f, 10.0f), 120 );
756 DALI_TEST_EQUALS(false, data.functorCalled, TEST_LOCATION);
758 // Tap possible in empty area.
759 TestStartLongPress( application, 50.0f, 10.0f, 700 );
760 DALI_TEST_EQUALS(false, data.functorCalled, TEST_LOCATION);
762 // Move actor in to the tap position.
763 actor.SetProperty( Actor::Property::POSITION, Vector2( 0.0f, 0.0f ));
766 application.SendNotification();
767 application.Render();
769 // Emit Started event, we should not receive the tap.
770 TestEndPan( application, Vector2(50.0f, 10.0f), 720 );
771 DALI_TEST_EQUALS(false, data.functorCalled, TEST_LOCATION);
773 // Normal tap in actor's area for completeness.
774 TestGenerateTap( application, 50.0f, 10.0f, 1300 );
775 DALI_TEST_EQUALS(true, data.functorCalled, TEST_LOCATION);
779 int UtcDaliTapGestureActorUnstaged(void)
781 TestApplication application;
783 Actor actor = Actor::New();
784 actor.SetProperty( Actor::Property::SIZE, Vector2( 100.0f, 100.0f ) );
785 actor.SetProperty( Actor::Property::ANCHOR_POINT,AnchorPoint::TOP_LEFT);
786 application.GetScene().Add(actor);
789 application.SendNotification();
790 application.Render();
792 // Attach actor to detector
794 UnstageActorFunctor functor( data, application.GetScene() );
795 TapGestureDetector detector = TapGestureDetector::New();
796 detector.Attach(actor);
797 detector.DetectedSignal().Connect( &application, functor );
799 TestGenerateTap( application, 50.0f, 10.0f, 100 );
800 DALI_TEST_EQUALS( true, data.functorCalled, TEST_LOCATION );
801 tet_result( TET_PASS ); // If we get here, then the actor removal on signal handler was handled gracefully.
805 int UtcDaliTapGestureDetectorRemovedWhilePossible(void)
807 TestApplication application;
809 Actor actor = Actor::New();
810 actor.SetProperty( Actor::Property::SIZE, Vector2( 100.0f, 100.0f ) );
811 actor.SetProperty( Actor::Property::ANCHOR_POINT,AnchorPoint::TOP_LEFT);
812 application.GetScene().Add(actor);
815 application.SendNotification();
816 application.Render();
818 // Attach actor to detector
820 GestureReceivedFunctor functor( data );
821 TapGestureDetector detector = TapGestureDetector::New();
822 detector.Attach(actor);
823 detector.DetectedSignal().Connect( &application, functor );
825 // Emit a possible - Down press, as emitted by long press function
826 TestStartLongPress( application, 50.0f, 10.0f, 100 );
828 // Detach actor and send a Started state, no signal.
829 detector.DetachAll();
830 TestEndPan( application, Vector2(50.0f, 10.0f), 120 );
831 DALI_TEST_EQUALS(false, data.functorCalled, TEST_LOCATION);
835 int UtcDaliTapGestureActorRemovedWhilePossible(void)
837 TestApplication application;
839 Actor actor = Actor::New();
840 actor.SetProperty( Actor::Property::SIZE, Vector2( 100.0f, 100.0f ) );
841 actor.SetProperty( Actor::Property::ANCHOR_POINT,AnchorPoint::TOP_LEFT);
842 application.GetScene().Add(actor);
845 application.SendNotification();
846 application.Render();
848 // Attach actor to detector
850 GestureReceivedFunctor functor( data );
851 TapGestureDetector detector = TapGestureDetector::New();
852 detector.Attach(actor);
853 detector.DetectedSignal().Connect( &application, functor );
855 // Emit a possible - Down press, as emitted by long press function
856 TestStartLongPress( application, 50.0f, 10.0f, 100 );
858 // Remove, render and delete actor
859 application.GetScene().Remove(actor);
860 application.SendNotification();
861 application.Render();
864 // Send a Started state, no signal - Up motion as provided by end pan function
865 TestEndPan( application, Vector2(50.0f, 10.0f), 120 );
866 DALI_TEST_EQUALS(false, data.functorCalled, TEST_LOCATION);
870 int UtcDaliTapGestureLayerConsumesTouch(void)
872 TestApplication application;
874 Actor actor = Actor::New();
875 actor.SetProperty( Actor::Property::SIZE, Vector2( 100.0f, 100.0f ) );
876 actor.SetProperty( Actor::Property::ANCHOR_POINT,AnchorPoint::TOP_LEFT);
877 application.GetScene().Add(actor);
881 GestureReceivedFunctor functor(data);
882 TapGestureDetector detector = TapGestureDetector::New();
883 detector.Attach(actor);
884 detector.DetectedSignal().Connect( &application, functor );
886 // Add a layer to overlap the actor
887 Layer layer = Layer::New();
888 layer.SetProperty( Actor::Property::SIZE, Vector2( 100.0f, 100.0f ) );
889 layer.SetProperty( Actor::Property::ANCHOR_POINT,AnchorPoint::TOP_LEFT);
890 application.GetScene().Add( layer );
894 application.SendNotification();
895 application.Render();
897 // Emit signals, should receive
898 TestGenerateTap( application, 50.0f, 50.0f, 100 );
899 DALI_TEST_EQUALS(true, data.functorCalled, TEST_LOCATION);
902 // Set layer to consume all touch
903 layer.SetProperty( Layer::Property::CONSUMES_TOUCH, true );
906 application.SendNotification();
907 application.Render();
909 // Emit the same signals again, should not receive
910 TestGenerateTap( application, 50.0f, 50.0f, 700 );
911 DALI_TEST_EQUALS(false, data.functorCalled, TEST_LOCATION);