2 // Copyright (c) 2014 Samsung Electronics Co., Ltd.
4 // Licensed under the Flora License, Version 1.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://floralicense.org/license/
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.
20 #include <dali/dali.h>
21 #include <dali/integration-api/events/touch-event-integ.h>
22 #include <dali/integration-api/events/tap-gesture-event.h>
23 #include <dali/integration-api/system-overlay.h>
24 #include <dali-test-suite-utils.h>
28 void utc_dali_tap_gesture_detector_startup(void)
30 test_return_value = TET_UNDEF;
33 void utc_dali_tap_gesture_detector_cleanup(void)
35 test_return_value = TET_PASS;
38 ///////////////////////////////////////////////////////////////////////////////
42 // Stores data that is populated in the callback and will be read by the TET cases
46 : functorCalled(false),
47 voidFunctorCalled(false)
52 functorCalled = false;
53 voidFunctorCalled = false;
55 receivedGesture.numberOfTaps = 0u;
56 receivedGesture.numberOfTouches = 0u;
57 receivedGesture.screenPoint = Vector2(0.0f, 0.0f);
58 receivedGesture.localPoint = Vector2(0.0f, 0.0f);
64 bool voidFunctorCalled;
65 TapGesture receivedGesture;
69 // Functor that sets the data when called
70 struct GestureReceivedFunctor
72 GestureReceivedFunctor(SignalData& data) : signalData(data) { }
74 void operator()(Actor actor, TapGesture tap)
76 signalData.functorCalled = true;
77 signalData.receivedGesture = tap;
78 signalData.tappedActor = actor;
83 signalData.voidFunctorCalled = true;
86 SignalData& signalData;
89 // Functor that removes the gestured actor from stage
90 struct UnstageActorFunctor : public GestureReceivedFunctor
92 UnstageActorFunctor( SignalData& data ) : GestureReceivedFunctor( data ) { }
94 void operator()(Actor actor, TapGesture tap)
96 GestureReceivedFunctor::operator()( actor, tap );
97 Stage::GetCurrent().Remove( actor );
101 // Functor for receiving a touch event
102 struct TouchEventFunctor
104 bool operator()(Actor actor, const TouchEvent& touch)
107 unsigned int points = touch.GetPointCount();
110 const TouchPoint& touchPoint = touch.GetPoint(0);
111 tet_printf("Touch Point state = %d\n", touchPoint.state);
117 // Generate a TapGestureEvent to send to Core
118 Integration::TapGestureEvent GenerateTap(
119 Gesture::State state,
120 unsigned int numberOfTaps,
121 unsigned int numberOfTouches,
124 Integration::TapGestureEvent tap( state );
126 tap.numberOfTaps = numberOfTaps;
127 tap.numberOfTouches = numberOfTouches;
135 ///////////////////////////////////////////////////////////////////////////////
138 // Positive test case for a method
139 int UtcDaliTapGestureDetectorConstructor(void)
141 TestApplication application;
143 TapGestureDetector detector;
144 DALI_TEST_CHECK(!detector);
149 int UtcDaliTapGestureDetectorNew(void)
151 TestApplication application;
153 TapGestureDetector detector = TapGestureDetector::New();
154 DALI_TEST_CHECK(detector);
155 DALI_TEST_EQUALS(1u, detector.GetTapsRequired(), TEST_LOCATION);
156 DALI_TEST_EQUALS(1u, detector.GetTouchesRequired(), TEST_LOCATION);
158 TapGestureDetector detector2 = TapGestureDetector::New(5u, 5u);
159 DALI_TEST_CHECK(detector2);
160 DALI_TEST_EQUALS(5u, detector2.GetTapsRequired(), TEST_LOCATION);
161 DALI_TEST_EQUALS(5u, detector2.GetTouchesRequired(), TEST_LOCATION);
163 //Scoped test to test destructor
165 TapGestureDetector detector3 = TapGestureDetector::New();
166 DALI_TEST_CHECK(detector3);
169 // Attach an actor and emit a touch event on the actor to ensure complete line coverage
170 Actor actor = Actor::New();
171 actor.SetSize(100.0f, 100.0f);
172 actor.SetAnchorPoint(AnchorPoint::TOP_LEFT);
173 Stage::GetCurrent().Add(actor);
176 application.SendNotification();
177 application.Render();
179 detector.Attach(actor);
181 TouchEventFunctor touchFunctor;
182 actor.TouchedSignal().Connect( &application, touchFunctor );
184 Integration::TouchEvent touchEvent(1);
185 TouchPoint point(1, TouchPoint::Down, 20.0f, 20.0f);
186 touchEvent.AddPoint(point);
187 application.ProcessEvent(touchEvent);
190 application.SendNotification();
191 application.Render();
193 // For line coverage, Initialise default constructor
194 TouchEvent touchEvent2;
198 int UtcDaliTapGestureDetectorDownCast(void)
200 TestApplication application;
201 tet_infoline("Testing Dali::TapGestureDetector::DownCast()");
203 TapGestureDetector detector = TapGestureDetector::New();
205 BaseHandle object(detector);
207 TapGestureDetector detector2 = TapGestureDetector::DownCast(object);
208 DALI_TEST_CHECK(detector2);
210 TapGestureDetector detector3 = DownCast< TapGestureDetector >(object);
211 DALI_TEST_CHECK(detector3);
213 BaseHandle unInitializedObject;
214 TapGestureDetector detector4 = TapGestureDetector::DownCast(unInitializedObject);
215 DALI_TEST_CHECK(!detector4);
217 TapGestureDetector detector5 = DownCast< TapGestureDetector >(unInitializedObject);
218 DALI_TEST_CHECK(!detector5);
220 GestureDetector detector6 = TapGestureDetector::New();
221 TapGestureDetector detector7 = TapGestureDetector::DownCast(detector6);
222 DALI_TEST_CHECK(detector7);
226 int UtcDaliTapGestureSetTapsRequired(void)
228 TestApplication application;
230 TapGestureDetector detector = TapGestureDetector::New();
232 unsigned int taps = 3;
234 DALI_TEST_CHECK(taps != detector.GetTapsRequired());
236 detector.SetTapsRequired(taps);
238 DALI_TEST_EQUALS(taps, detector.GetTapsRequired(), TEST_LOCATION);
240 // Attach an actor and change the required touches
242 Actor actor = Actor::New();
243 actor.SetSize(100.0f, 100.0f);
244 actor.SetAnchorPoint(AnchorPoint::TOP_LEFT);
245 Stage::GetCurrent().Add(actor);
248 application.SendNotification();
249 application.Render();
252 GestureReceivedFunctor functor(data);
254 detector.Attach(actor);
255 detector.DetectedSignal().Connect( &application, functor );
257 TestGestureManager& gestureManager = application.GetGestureManager();
258 gestureManager.Initialize();
260 detector.SetTapsRequired(4);
262 // Gesture detection should have been updated only
263 DALI_TEST_EQUALS(true, gestureManager.WasCalled(TestGestureManager::UpdateType), TEST_LOCATION);
264 DALI_TEST_EQUALS(false, gestureManager.WasCalled(TestGestureManager::RegisterType), TEST_LOCATION);
265 DALI_TEST_EQUALS(false, gestureManager.WasCalled(TestGestureManager::UnregisterType), TEST_LOCATION);
268 gestureManager.Initialize();
270 // Create a second gesture detector that requires even less maximum touches
271 TapGestureDetector secondDetector = TapGestureDetector::New();
272 secondDetector.Attach(actor);
274 // Gesture detection should have been updated
275 DALI_TEST_EQUALS(true, gestureManager.WasCalled(TestGestureManager::UpdateType), TEST_LOCATION);
276 DALI_TEST_EQUALS(false, gestureManager.WasCalled(TestGestureManager::RegisterType), TEST_LOCATION);
277 DALI_TEST_EQUALS(false, gestureManager.WasCalled(TestGestureManager::UnregisterType), TEST_LOCATION);
281 int UtcDaliTapGestureGetTapsRequired(void)
283 TestApplication application;
285 TapGestureDetector detector = TapGestureDetector::New();
286 DALI_TEST_EQUALS(1u, detector.GetTapsRequired(), TEST_LOCATION);
290 int UtcDaliTapGestureSetTouchesRequired(void)
292 TestApplication application;
294 TapGestureDetector detector = TapGestureDetector::New();
296 unsigned int max = 3;
298 DALI_TEST_CHECK(max != detector.GetTouchesRequired());
300 detector.SetTouchesRequired(max);
302 DALI_TEST_EQUALS(max, detector.GetTouchesRequired(), TEST_LOCATION);
304 // Attach an actor and change the maximum touches
306 Actor actor = Actor::New();
307 actor.SetSize(100.0f, 100.0f);
308 actor.SetAnchorPoint(AnchorPoint::TOP_LEFT);
309 Stage::GetCurrent().Add(actor);
312 application.SendNotification();
313 application.Render();
316 GestureReceivedFunctor functor(data);
318 detector.Attach(actor);
319 detector.DetectedSignal().Connect( &application, functor );
321 TestGestureManager& gestureManager = application.GetGestureManager();
322 gestureManager.Initialize();
324 detector.SetTouchesRequired(4);
326 // Gesture detection should have been updated only
327 DALI_TEST_EQUALS(true, gestureManager.WasCalled(TestGestureManager::UpdateType), TEST_LOCATION);
328 DALI_TEST_EQUALS(false, gestureManager.WasCalled(TestGestureManager::RegisterType), TEST_LOCATION);
329 DALI_TEST_EQUALS(false, gestureManager.WasCalled(TestGestureManager::UnregisterType), TEST_LOCATION);
332 gestureManager.Initialize();
334 // Create a second gesture detector that requires even less maximum touches
335 TapGestureDetector secondDetector = TapGestureDetector::New();
336 secondDetector.Attach(actor);
338 // Gesture detection should have been updated
339 DALI_TEST_EQUALS(true, gestureManager.WasCalled(TestGestureManager::UpdateType), TEST_LOCATION);
340 DALI_TEST_EQUALS(false, gestureManager.WasCalled(TestGestureManager::RegisterType), TEST_LOCATION);
341 DALI_TEST_EQUALS(false, gestureManager.WasCalled(TestGestureManager::UnregisterType), TEST_LOCATION);
345 int UtcDaliTapGestureGetTouchesRequired(void)
347 TestApplication application;
349 TapGestureDetector detector = TapGestureDetector::New();
350 DALI_TEST_EQUALS(1u, detector.GetTouchesRequired(), TEST_LOCATION);
354 int UtcDaliTapGestureSignalReceptionNegative(void)
356 TestApplication application;
358 Actor actor = Actor::New();
359 actor.SetSize(100.0f, 100.0f);
360 actor.SetAnchorPoint(AnchorPoint::TOP_LEFT);
361 Stage::GetCurrent().Add(actor);
364 application.SendNotification();
365 application.Render();
368 GestureReceivedFunctor functor(data);
370 TapGestureDetector detector = TapGestureDetector::New();
371 detector.Attach(actor);
372 detector.DetectedSignal().Connect( &application, functor );
374 // Do a tap outside actor's area
375 application.ProcessEvent(GenerateTap(Gesture::Possible, 1u, 1u, Vector2(112.0f, 112.0f)));
376 application.ProcessEvent(GenerateTap(Gesture::Started, 1u, 1u, Vector2(112.0f, 112.0f)));
377 DALI_TEST_EQUALS(false, data.functorCalled, TEST_LOCATION);
381 int UtcDaliTapGestureSignalReceptionPositive(void)
383 TestApplication application;
385 Actor actor = Actor::New();
386 actor.SetSize(100.0f, 100.0f);
387 actor.SetAnchorPoint(AnchorPoint::TOP_LEFT);
388 Stage::GetCurrent().Add(actor);
391 application.SendNotification();
392 application.Render();
395 GestureReceivedFunctor functor(data);
397 TapGestureDetector detector = TapGestureDetector::New();
398 detector.Attach(actor);
399 detector.DetectedSignal().Connect( &application, functor );
401 // Do a tap inside actor's area
402 application.ProcessEvent(GenerateTap(Gesture::Possible, 1u, 1u, Vector2(50.0f, 50.0f)));
403 application.ProcessEvent(GenerateTap(Gesture::Started, 1u, 1u, Vector2(50.0f, 50.0f)));
404 DALI_TEST_EQUALS(true, data.functorCalled, TEST_LOCATION);
405 DALI_TEST_EQUALS(1u, data.receivedGesture.numberOfTaps, TEST_LOCATION);
406 DALI_TEST_EQUALS(1u, data.receivedGesture.numberOfTouches, TEST_LOCATION);
407 DALI_TEST_EQUALS( Vector2(50.0f, 50.0f), data.receivedGesture.localPoint, 0.1, TEST_LOCATION);
411 int UtcDaliTapGestureSignalReceptionDetach(void)
413 TestApplication application;
415 Actor actor = Actor::New();
416 actor.SetSize(100.0f, 100.0f);
417 actor.SetAnchorPoint(AnchorPoint::TOP_LEFT);
418 Stage::GetCurrent().Add(actor);
421 application.SendNotification();
422 application.Render();
425 GestureReceivedFunctor functor(data);
427 TapGestureDetector detector = TapGestureDetector::New();
428 detector.Attach(actor);
429 detector.DetectedSignal().Connect(&application, functor);
431 // Start tap within the actor's area
432 application.ProcessEvent(GenerateTap(Gesture::Possible, 1u, 1u, Vector2(20.0f, 20.0f)));
433 application.ProcessEvent(GenerateTap(Gesture::Started, 1u, 1u, Vector2(20.0f, 20.0f)));
434 DALI_TEST_EQUALS(true, data.functorCalled, TEST_LOCATION);
435 DALI_TEST_EQUALS(1u, data.receivedGesture.numberOfTaps, TEST_LOCATION);
436 DALI_TEST_EQUALS(1u, data.receivedGesture.numberOfTouches, TEST_LOCATION);
437 DALI_TEST_EQUALS( Vector2(20.0f, 20.0f), data.receivedGesture.localPoint, 0.1, TEST_LOCATION);
439 // repeat the tap within the actor's area - we should still receive the signal
441 application.ProcessEvent(GenerateTap(Gesture::Possible, 1u, 1u, Vector2(50.0f, 50.0f)));
442 application.ProcessEvent(GenerateTap(Gesture::Started, 1u, 1u, Vector2(50.0f, 50.0f)));
443 DALI_TEST_EQUALS(true, data.functorCalled, TEST_LOCATION);
444 DALI_TEST_EQUALS(1u, data.receivedGesture.numberOfTaps, TEST_LOCATION);
445 DALI_TEST_EQUALS(1u, data.receivedGesture.numberOfTouches, TEST_LOCATION);
446 DALI_TEST_EQUALS( Vector2(50.0f, 50.0f), data.receivedGesture.localPoint, 0.1, TEST_LOCATION);
449 detector.DetachAll();
451 // Ensure we are no longer signalled
453 application.ProcessEvent(GenerateTap(Gesture::Possible, 1u, 1u, Vector2(20.0f, 20.0f)));
454 application.ProcessEvent(GenerateTap(Gesture::Started, 1u, 1u, Vector2(20.0f, 20.0f)));
455 DALI_TEST_EQUALS(false, data.functorCalled, TEST_LOCATION);
456 application.ProcessEvent(GenerateTap(Gesture::Possible, 1u, 1u, Vector2(50.0f, 50.0f)));
457 application.ProcessEvent(GenerateTap(Gesture::Started, 1u, 1u, Vector2(50.0f, 50.0f)));
458 DALI_TEST_EQUALS(false, data.functorCalled, TEST_LOCATION);
462 int UtcDaliTapGestureSignalReceptionActorDestroyedWhileTapping(void)
464 TestApplication application;
467 GestureReceivedFunctor functor(data);
469 TapGestureDetector detector = TapGestureDetector::New();
470 detector.DetectedSignal().Connect(&application, functor);
472 // Actor lifetime is scoped
474 Actor actor = Actor::New();
475 actor.SetSize(100.0f, 100.0f);
476 actor.SetAnchorPoint(AnchorPoint::TOP_LEFT);
477 Stage::GetCurrent().Add(actor);
480 application.SendNotification();
481 application.Render();
483 detector.Attach(actor);
485 // Start tap within the actor's area
486 application.ProcessEvent(GenerateTap(Gesture::Possible, 1u, 1u, Vector2(20.0f, 20.0f)));
487 application.ProcessEvent(GenerateTap(Gesture::Started, 1u, 1u, Vector2(20.0f, 20.0f)));
488 DALI_TEST_EQUALS(true, data.functorCalled, TEST_LOCATION);
490 // Remove the actor from stage and reset the data
491 Stage::GetCurrent().Remove(actor);
494 application.SendNotification();
495 application.Render();
498 // Actor should now have been destroyed
501 application.ProcessEvent(GenerateTap(Gesture::Possible, 1u, 1u, Vector2(20.0f, 20.0f)));
502 application.ProcessEvent(GenerateTap(Gesture::Started, 1u, 1u, Vector2(20.0f, 20.0f)));
503 DALI_TEST_EQUALS(false, data.functorCalled, TEST_LOCATION);
507 int UtcDaliTapGestureSignalReceptionRotatedActor(void)
509 TestApplication application;
511 Actor actor = Actor::New();
512 actor.SetSize(100.0f, 100.0f);
513 actor.SetRotation(Dali::Degree(90.0f), Vector3::ZAXIS);
514 Stage::GetCurrent().Add(actor);
517 application.SendNotification();
518 application.Render();
521 GestureReceivedFunctor functor(data);
523 TapGestureDetector detector = TapGestureDetector::New();
524 detector.Attach(actor);
525 detector.DetectedSignal().Connect(&application, functor);
527 // Do tap, only check finished value
528 application.ProcessEvent(GenerateTap(Gesture::Possible, 1u, 1u, Vector2(5.0f, 5.0f)));
529 application.ProcessEvent(GenerateTap(Gesture::Started, 1u, 1u, Vector2(5.0f, 5.0f)));
530 DALI_TEST_EQUALS(true, data.functorCalled, TEST_LOCATION);
531 DALI_TEST_EQUALS(1u, data.receivedGesture.numberOfTaps, TEST_LOCATION);
532 DALI_TEST_EQUALS(1u, data.receivedGesture.numberOfTouches, TEST_LOCATION);
533 DALI_TEST_EQUALS( Vector2(5.0f, 5.0f), data.receivedGesture.screenPoint, 0.1, TEST_LOCATION);
535 // Rotate actor again and render
536 actor.SetRotation(Dali::Degree(180.0f), Vector3::ZAXIS);
537 application.SendNotification();
538 application.Render();
540 // Do tap, should still receive event
542 application.ProcessEvent(GenerateTap(Gesture::Possible, 1u, 1u, Vector2(5.0f, 5.0f)));
543 application.ProcessEvent(GenerateTap(Gesture::Started, 1u, 1u, Vector2(5.0f, 5.0f)));
544 DALI_TEST_EQUALS(true, data.functorCalled, TEST_LOCATION);
545 DALI_TEST_EQUALS(1u, data.receivedGesture.numberOfTaps, TEST_LOCATION);
546 DALI_TEST_EQUALS(1u, data.receivedGesture.numberOfTouches, TEST_LOCATION);
547 DALI_TEST_EQUALS( Vector2(5.0f, 5.0f), data.receivedGesture.screenPoint, 0.1, TEST_LOCATION);
549 // Rotate actor again and render
550 actor.SetRotation(Dali::Degree(90.0f), Vector3::YAXIS);
551 application.SendNotification();
552 application.Render();
554 // Do tap, inside the actor's area (area if it is not rotated), Should not receive the event
556 application.ProcessEvent(GenerateTap(Gesture::Possible, 1u, 1u, Vector2(70.0f, 70.0f)));
557 application.ProcessEvent(GenerateTap(Gesture::Started, 1u, 1u, Vector2(70.0f, 70.0f)));
558 DALI_TEST_EQUALS(false, data.functorCalled, TEST_LOCATION);
562 int UtcDaliTapGestureSignalReceptionChildHit(void)
564 TestApplication application;
566 Actor parent = Actor::New();
567 parent.SetSize(100.0f, 100.0f);
568 parent.SetAnchorPoint(AnchorPoint::TOP_LEFT);
569 Stage::GetCurrent().Add(parent);
571 // Set child to completely cover parent.
572 // Change rotation of child to be different from parent so that we can check if our local coordinate
573 // conversion of the parent actor is correct.
574 Actor child = Actor::New();
575 child.SetSize(100.0f, 100.0f);
576 child.SetAnchorPoint(AnchorPoint::CENTER);
577 child.SetParentOrigin(ParentOrigin::CENTER);
578 child.SetRotation(Dali::Degree(90.0f), Vector3::ZAXIS);
581 TouchEventFunctor touchFunctor;
582 child.TouchedSignal().Connect(&application, touchFunctor);
585 application.SendNotification();
586 application.Render();
589 GestureReceivedFunctor functor(data);
591 TapGestureDetector detector = TapGestureDetector::New();
592 detector.Attach(parent);
593 detector.DetectedSignal().Connect(&application, functor);
595 // Do tap - hits child area but parent should still receive it
596 application.ProcessEvent(GenerateTap(Gesture::Possible, 1u, 1u, Vector2(50.0f, 50.0f)));
597 application.ProcessEvent(GenerateTap(Gesture::Started, 1u, 1u, Vector2(50.0f, 50.0f)));
598 DALI_TEST_EQUALS(true, data.functorCalled, TEST_LOCATION);
599 DALI_TEST_EQUALS(true, parent == data.tappedActor, TEST_LOCATION);
600 DALI_TEST_EQUALS(Vector2(50.0f, 50.0f), data.receivedGesture.screenPoint, 0.01f, TEST_LOCATION);
602 // Attach child and generate same touch points
603 // (Also proves that you can detach and then re-attach another actor)
604 detector.Attach(child);
605 detector.Detach(parent);
607 // Do an entire tap, only check finished value
609 application.ProcessEvent(GenerateTap(Gesture::Possible, 1u, 1u, Vector2(51.0f, 51.0f)));
610 application.ProcessEvent(GenerateTap(Gesture::Started, 1u, 1u, Vector2(51.0f, 51.0f)));
611 DALI_TEST_EQUALS(true, data.functorCalled, TEST_LOCATION);
612 DALI_TEST_EQUALS(true, child == data.tappedActor, TEST_LOCATION);
613 DALI_TEST_EQUALS(Vector2(51.0f, 51.0f), data.receivedGesture.screenPoint, 0.01f, TEST_LOCATION);
617 int UtcDaliTapGestureSignalReceptionAttachDetachMany(void)
619 TestApplication application;
621 Actor first = Actor::New();
622 first.SetSize(100.0f, 100.0f);
623 first.SetAnchorPoint(AnchorPoint::TOP_LEFT);
624 Stage::GetCurrent().Add(first);
626 Actor second = Actor::New();
627 second.SetSize(100.0f, 100.0f);
629 second.SetAnchorPoint(AnchorPoint::TOP_LEFT);
630 Stage::GetCurrent().Add(second);
633 application.SendNotification();
634 application.Render();
637 GestureReceivedFunctor functor(data);
639 TapGestureDetector detector = TapGestureDetector::New();
640 detector.Attach(first);
641 detector.Attach(second);
642 detector.DetectedSignal().Connect(&application, functor);
644 // Tap within second actor's area
645 application.ProcessEvent(GenerateTap(Gesture::Possible, 1u, 1u, Vector2(120.0f, 10.0f)));
646 application.ProcessEvent(GenerateTap(Gesture::Started, 1u, 1u, Vector2(120.0f, 10.0f)));
647 DALI_TEST_EQUALS(true, data.functorCalled, TEST_LOCATION);
648 DALI_TEST_EQUALS(true, second == data.tappedActor, TEST_LOCATION);
650 // Tap within first actor's area
652 application.ProcessEvent(GenerateTap(Gesture::Possible, 1u, 1u, Vector2(20.0f, 10.0f)));
653 application.ProcessEvent(GenerateTap(Gesture::Started, 1u, 1u, Vector2(20.0f, 10.0f)));
654 DALI_TEST_EQUALS(true, data.functorCalled, TEST_LOCATION);
655 DALI_TEST_EQUALS(true, first == data.tappedActor, TEST_LOCATION);
657 // Detach the second actor
658 detector.Detach(second);
660 // second actor shouldn't receive event
662 application.ProcessEvent(GenerateTap(Gesture::Possible, 1u, 1u, Vector2(120.0f, 10.0f)));
663 application.ProcessEvent(GenerateTap(Gesture::Started, 1u, 1u, Vector2(120.0f, 10.0f)));
664 DALI_TEST_EQUALS(false, data.functorCalled, TEST_LOCATION);
666 // first actor should continue receiving event
668 application.ProcessEvent(GenerateTap(Gesture::Possible, 1u, 1u, Vector2(20.0f, 10.0f)));
669 application.ProcessEvent(GenerateTap(Gesture::Started, 1u, 1u, Vector2(20.0f, 10.0f)));
670 DALI_TEST_EQUALS(true, data.functorCalled, TEST_LOCATION);
674 int UtcDaliTapGestureSignalReceptionActorBecomesUntouchable(void)
676 TestApplication application;
678 Actor actor = Actor::New();
679 actor.SetSize(100.0f, 100.0f);
680 actor.SetAnchorPoint(AnchorPoint::TOP_LEFT);
681 Stage::GetCurrent().Add(actor);
684 application.SendNotification();
685 application.Render();
688 GestureReceivedFunctor functor(data);
690 TapGestureDetector detector = TapGestureDetector::New();
691 detector.Attach(actor);
692 detector.DetectedSignal().Connect(&application, functor);
694 // Tap in actor's area
695 application.ProcessEvent(GenerateTap(Gesture::Possible, 1u, 1u, Vector2(50.0f, 10.0f)));
696 application.ProcessEvent(GenerateTap(Gesture::Started, 1u, 1u, Vector2(50.0f, 10.0f)));
697 DALI_TEST_EQUALS(true, data.functorCalled, TEST_LOCATION);
699 // Actor become invisible - actor should not receive the next pan
700 actor.SetVisible(false);
703 application.SendNotification();
704 application.Render();
706 // Tap in the same area, shouldn't receive event
708 application.ProcessEvent(GenerateTap(Gesture::Possible, 1u, 1u, Vector2(50.0f, 10.0f)));
709 application.ProcessEvent(GenerateTap(Gesture::Started, 1u, 1u, Vector2(50.0f, 10.0f)));
710 DALI_TEST_EQUALS(false, data.functorCalled, TEST_LOCATION);
714 int UtcDaliTapGestureSignalReceptionMultipleGestureDetectors(void)
716 TestApplication application;
717 Dali::TestGestureManager& gestureManager = application.GetGestureManager();
719 Actor first = Actor::New();
720 first.SetSize(100.0f, 100.0f);
721 first.SetAnchorPoint(AnchorPoint::TOP_LEFT);
722 Stage::GetCurrent().Add(first);
724 Actor second = Actor::New();
725 second.SetSize(100.0f, 100.0f);
726 second.SetAnchorPoint(AnchorPoint::TOP_LEFT);
731 application.SendNotification();
732 application.Render();
735 GestureReceivedFunctor functor(data);
737 TapGestureDetector firstDetector = TapGestureDetector::New();
738 firstDetector.Attach(first);
739 firstDetector.DetectedSignal().Connect(&application, functor);
741 // secondDetector is scoped
743 // Reset gestureManager statistics
744 gestureManager.Initialize();
746 TapGestureDetector secondDetector = TapGestureDetector::New();
747 secondDetector.SetTapsRequired(2);
748 secondDetector.SetTouchesRequired(2);
749 secondDetector.Attach(second);
750 secondDetector.DetectedSignal().Connect(&application, functor);
752 DALI_TEST_EQUALS(true, gestureManager.WasCalled(TestGestureManager::UpdateType), TEST_LOCATION);
753 DALI_TEST_EQUALS(false, gestureManager.WasCalled(TestGestureManager::RegisterType), TEST_LOCATION);
754 DALI_TEST_EQUALS(false, gestureManager.WasCalled(TestGestureManager::UnregisterType), TEST_LOCATION);
756 // Tap within second actor's area
757 application.ProcessEvent(GenerateTap(Gesture::Possible, 2u, 2u, Vector2(150.0f, 10.0f)));
758 application.ProcessEvent(GenerateTap(Gesture::Started, 2u, 2u, Vector2(150.0f, 10.0f)));
759 DALI_TEST_EQUALS(true, data.functorCalled, TEST_LOCATION);
760 DALI_TEST_EQUALS(true, second == data.tappedActor, TEST_LOCATION);
762 // Tap continues as single touch gesture - we should not receive any gesture
764 application.ProcessEvent(GenerateTap(Gesture::Possible, 1u, 1u, Vector2(150.0f, 10.0f)));
765 application.ProcessEvent(GenerateTap(Gesture::Started, 1u, 1u, Vector2(150.0f, 10.0f)));
766 DALI_TEST_EQUALS(false, data.functorCalled, TEST_LOCATION);
768 // Single touch tap starts - first actor should be panned
770 application.ProcessEvent(GenerateTap(Gesture::Possible, 1u, 1u, Vector2(50.0f, 10.0f)));
771 application.ProcessEvent(GenerateTap(Gesture::Started, 1u, 1u, Vector2(50.0f, 10.0f)));
772 DALI_TEST_EQUALS(true, data.functorCalled, TEST_LOCATION);
773 DALI_TEST_EQUALS(true, first == data.tappedActor, TEST_LOCATION);
775 // Pan changes to double-touch - we shouldn't receive event
777 application.ProcessEvent(GenerateTap(Gesture::Possible, 2u, 2u, Vector2(50.0f, 10.0f)));
778 application.ProcessEvent(GenerateTap(Gesture::Started, 2u, 2u, Vector2(50.0f, 10.0f)));
779 DALI_TEST_EQUALS(false, data.functorCalled, TEST_LOCATION);
781 // Reset gesture manager statistics
782 gestureManager.Initialize();
785 // secondDetector has now been deleted. Gesture detection should have been updated only
786 DALI_TEST_EQUALS(true, gestureManager.WasCalled(TestGestureManager::UpdateType), TEST_LOCATION);
787 DALI_TEST_EQUALS(false, gestureManager.WasCalled(TestGestureManager::RegisterType), TEST_LOCATION);
788 DALI_TEST_EQUALS(false, gestureManager.WasCalled(TestGestureManager::UnregisterType), TEST_LOCATION);
792 int UtcDaliTapGestureSignalReceptionMultipleDetectorsOnActor(void)
794 TestApplication application;
796 Actor actor = Actor::New();
797 actor.SetSize(100.0f, 100.0f);
798 actor.SetAnchorPoint(AnchorPoint::TOP_LEFT);
799 Stage::GetCurrent().Add(actor);
802 application.SendNotification();
803 application.Render();
805 // Attach actor to one detector
806 SignalData firstData;
807 GestureReceivedFunctor firstFunctor(firstData);
808 TapGestureDetector firstDetector = TapGestureDetector::New();
809 firstDetector.Attach(actor);
810 firstDetector.DetectedSignal().Connect(&application, firstFunctor);
812 // Attach actor to another detector
813 SignalData secondData;
814 GestureReceivedFunctor secondFunctor(secondData);
815 TapGestureDetector secondDetector = TapGestureDetector::New();
816 secondDetector.Attach(actor);
817 secondDetector.DetectedSignal().Connect(&application, secondFunctor);
819 // Tap in actor's area - both detector's functors should be called
820 application.ProcessEvent(GenerateTap(Gesture::Possible, 1u, 1u, Vector2(50.0f, 10.0f)));
821 application.ProcessEvent(GenerateTap(Gesture::Started, 1u, 1u, Vector2(50.0f, 10.0f)));
822 DALI_TEST_EQUALS(true, firstData.functorCalled, TEST_LOCATION);
823 DALI_TEST_EQUALS(true, secondData.functorCalled, TEST_LOCATION);
827 int UtcDaliTapGestureSignalReceptionDifferentPossible(void)
829 TestApplication application;
831 Actor actor = Actor::New();
832 actor.SetSize(100.0f, 100.0f);
833 actor.SetAnchorPoint(AnchorPoint::TOP_LEFT);
834 Stage::GetCurrent().Add(actor);
837 application.SendNotification();
838 application.Render();
840 // Attach actor to detector
842 GestureReceivedFunctor functor( data );
843 TapGestureDetector detector = TapGestureDetector::New();
844 detector.Attach(actor);
845 detector.DetectedSignal().Connect( &application, functor );
847 // Gesture possible in actor's area.
848 application.ProcessEvent(GenerateTap(Gesture::Possible, 1u, 1u, Vector2(50.0f, 10.0f)));
849 DALI_TEST_EQUALS(false, data.functorCalled, TEST_LOCATION);
851 // Move actor somewhere else
852 actor.SetPosition( 100.0f, 100.0f );
855 application.SendNotification();
856 application.Render();
858 // Emit Started event, we should not receive the long press.
859 application.ProcessEvent(GenerateTap(Gesture::Started, 1u, 1u, Vector2(50.0f, 10.0f)));
860 DALI_TEST_EQUALS(false, data.functorCalled, TEST_LOCATION);
862 // LongPress possible in empty area.
863 application.ProcessEvent(GenerateTap(Gesture::Possible, 1u, 1u, Vector2(50.0f, 10.0f)));
864 DALI_TEST_EQUALS(false, data.functorCalled, TEST_LOCATION);
866 // Move actor in to the long press position.
867 actor.SetPosition( 0.0f, 0.0f );
870 application.SendNotification();
871 application.Render();
873 // Emit Started event, we should not receive the long press.
874 application.ProcessEvent(GenerateTap(Gesture::Started, 1u, 1u, Vector2(50.0f, 10.0f)));
875 DALI_TEST_EQUALS(false, data.functorCalled, TEST_LOCATION);
877 // Normal long press in actor's area for completeness.
878 application.ProcessEvent(GenerateTap(Gesture::Possible, 1u, 1u, Vector2(50.0f, 10.0f)));
879 application.ProcessEvent(GenerateTap(Gesture::Started, 1u, 1u, Vector2(50.0f, 10.0f)));
880 DALI_TEST_EQUALS(true, data.functorCalled, TEST_LOCATION);
884 int UtcDaliTapGestureEmitIncorrectStateClear(void)
886 TestApplication application;
888 Actor actor = Actor::New();
889 actor.SetSize(100.0f, 100.0f);
890 actor.SetAnchorPoint(AnchorPoint::TOP_LEFT);
891 Stage::GetCurrent().Add(actor);
894 application.SendNotification();
895 application.Render();
897 // Attach actor to detector
899 GestureReceivedFunctor functor( data );
900 TapGestureDetector detector = TapGestureDetector::New();
901 detector.Attach(actor);
902 detector.DetectedSignal().Connect( &application, functor );
907 application.ProcessEvent(GenerateTap(Gesture::Clear, 1u, 1u, Vector2(50.0f, 10.0f)));
908 tet_result(TET_FAIL);
910 catch ( Dali::DaliException& e )
912 DALI_TEST_ASSERT( e, "false", TEST_LOCATION );
917 int UtcDaliTapGestureEmitIncorrectStateContinuing(void)
919 TestApplication application;
921 Actor actor = Actor::New();
922 actor.SetSize(100.0f, 100.0f);
923 actor.SetAnchorPoint(AnchorPoint::TOP_LEFT);
924 Stage::GetCurrent().Add(actor);
927 application.SendNotification();
928 application.Render();
930 // Attach actor to detector
932 GestureReceivedFunctor functor( data );
933 TapGestureDetector detector = TapGestureDetector::New();
934 detector.Attach(actor);
935 detector.DetectedSignal().Connect( &application, functor );
937 // Try a Continuing state
940 application.ProcessEvent(GenerateTap(Gesture::Continuing, 1u, 1u, Vector2(50.0f, 10.0f)));
941 tet_result(TET_FAIL);
943 catch ( Dali::DaliException& e )
945 DALI_TEST_ASSERT( e, "false", TEST_LOCATION );
950 int UtcDaliTapGestureEmitIncorrectStateFinished(void)
952 TestApplication application;
954 Actor actor = Actor::New();
955 actor.SetSize(100.0f, 100.0f);
956 actor.SetAnchorPoint(AnchorPoint::TOP_LEFT);
957 Stage::GetCurrent().Add(actor);
960 application.SendNotification();
961 application.Render();
963 // Attach actor to detector
965 GestureReceivedFunctor functor( data );
966 TapGestureDetector detector = TapGestureDetector::New();
967 detector.Attach(actor);
968 detector.DetectedSignal().Connect( &application, functor );
970 // Try a Finished state
973 application.ProcessEvent(GenerateTap(Gesture::Finished, 1u, 1u, Vector2(50.0f, 10.0f)));
974 tet_result(TET_FAIL);
976 catch ( Dali::DaliException& e )
978 DALI_TEST_ASSERT( e, "false", TEST_LOCATION );
983 int UtcDaliTapGestureActorUnstaged(void)
985 TestApplication application;
987 Actor actor = Actor::New();
988 actor.SetSize(100.0f, 100.0f);
989 actor.SetAnchorPoint(AnchorPoint::TOP_LEFT);
990 Stage::GetCurrent().Add(actor);
993 application.SendNotification();
994 application.Render();
996 // Attach actor to detector
998 UnstageActorFunctor functor( data );
999 TapGestureDetector detector = TapGestureDetector::New();
1000 detector.Attach(actor);
1001 detector.DetectedSignal().Connect( &application, functor );
1003 // Tap in Actor's area, actor removed in signal handler, should be handled gracefully.
1004 application.ProcessEvent(GenerateTap(Gesture::Possible, 1u, 1u, Vector2(50.0f, 10.0f)));
1005 application.ProcessEvent(GenerateTap(Gesture::Started, 1u, 1u, Vector2(50.0f, 10.0f)));
1006 DALI_TEST_EQUALS( true, data.functorCalled, TEST_LOCATION );
1007 tet_result( TET_PASS ); // If we get here, then the actor removal on signal handler was handled gracefully.
1011 int UtcDaliTapGestureRepeatedState(void)
1013 TestApplication application;
1015 Actor actor = Actor::New();
1016 actor.SetSize(100.0f, 100.0f);
1017 actor.SetAnchorPoint(AnchorPoint::TOP_LEFT);
1018 Stage::GetCurrent().Add(actor);
1020 // Render and notify
1021 application.SendNotification();
1022 application.Render();
1024 // Attach actor to detector
1026 GestureReceivedFunctor functor( data );
1027 TapGestureDetector detector = TapGestureDetector::New();
1028 detector.Attach(actor);
1029 detector.DetectedSignal().Connect( &application, functor );
1031 // Emit two possibles
1032 application.ProcessEvent(GenerateTap(Gesture::Possible, 1u, 1u, Vector2(50.0f, 10.0f)));
1033 application.ProcessEvent(GenerateTap(Gesture::Possible, 1u, 1u, Vector2(50.0f, 10.0f)));
1034 DALI_TEST_EQUALS(false, data.functorCalled, TEST_LOCATION);
1036 // Send a couple of Started states, only first one should be received.
1037 application.ProcessEvent(GenerateTap(Gesture::Started, 1u, 1u, Vector2(50.0f, 10.0f)));
1038 DALI_TEST_EQUALS(true, data.functorCalled, TEST_LOCATION);
1040 application.ProcessEvent(GenerateTap(Gesture::Started, 1u, 1u, Vector2(50.0f, 10.0f)));
1041 DALI_TEST_EQUALS(false, data.functorCalled, TEST_LOCATION);
1043 // Send a couple of cancelled states, no reception
1044 application.ProcessEvent(GenerateTap(Gesture::Cancelled, 1u, 1u, Vector2(50.0f, 10.0f)));
1045 application.ProcessEvent(GenerateTap(Gesture::Cancelled, 1u, 1u, Vector2(50.0f, 10.0f)));
1046 DALI_TEST_EQUALS(false, data.functorCalled, TEST_LOCATION);
1050 int UtcDaliTapGesturePossibleCancelled(void)
1052 TestApplication application;
1054 Actor actor = Actor::New();
1055 actor.SetSize(100.0f, 100.0f);
1056 actor.SetAnchorPoint(AnchorPoint::TOP_LEFT);
1057 Stage::GetCurrent().Add(actor);
1059 // Render and notify
1060 application.SendNotification();
1061 application.Render();
1063 // Attach actor to detector
1065 GestureReceivedFunctor functor( data );
1066 TapGestureDetector detector = TapGestureDetector::New();
1067 detector.Attach(actor);
1068 detector.DetectedSignal().Connect( &application, functor );
1070 // Emit a possible and then a cancelled, no reception
1071 application.ProcessEvent(GenerateTap(Gesture::Possible, 1u, 1u, Vector2(50.0f, 10.0f)));
1072 application.ProcessEvent(GenerateTap(Gesture::Cancelled, 1u, 1u, Vector2(50.0f, 10.0f)));
1073 DALI_TEST_EQUALS(false, data.functorCalled, TEST_LOCATION);
1077 int UtcDaliTapGestureDetectorRemovedWhilePossible(void)
1079 TestApplication application;
1081 Actor actor = Actor::New();
1082 actor.SetSize(100.0f, 100.0f);
1083 actor.SetAnchorPoint(AnchorPoint::TOP_LEFT);
1084 Stage::GetCurrent().Add(actor);
1086 // Render and notify
1087 application.SendNotification();
1088 application.Render();
1090 // Attach actor to detector
1092 GestureReceivedFunctor functor( data );
1093 TapGestureDetector detector = TapGestureDetector::New();
1094 detector.Attach(actor);
1095 detector.DetectedSignal().Connect( &application, functor );
1098 application.ProcessEvent(GenerateTap(Gesture::Possible, 1u, 1u, Vector2(50.0f, 10.0f)));
1100 // Detach actor and send a Started state, no signal.
1101 detector.DetachAll();
1102 application.ProcessEvent(GenerateTap(Gesture::Started, 1u, 1u, Vector2(50.0f, 10.0f)));
1103 DALI_TEST_EQUALS(false, data.functorCalled, TEST_LOCATION);
1107 int UtcDaliTapGestureActorRemovedWhilePossible(void)
1109 TestApplication application;
1111 Actor actor = Actor::New();
1112 actor.SetSize(100.0f, 100.0f);
1113 actor.SetAnchorPoint(AnchorPoint::TOP_LEFT);
1114 Stage::GetCurrent().Add(actor);
1116 // Render and notify
1117 application.SendNotification();
1118 application.Render();
1120 // Attach actor to detector
1122 GestureReceivedFunctor functor( data );
1123 TapGestureDetector detector = TapGestureDetector::New();
1124 detector.Attach(actor);
1125 detector.DetectedSignal().Connect( &application, functor );
1128 application.ProcessEvent(GenerateTap(Gesture::Possible, 1u, 1u, Vector2(50.0f, 10.0f)));
1130 // Remove, render and delete actor
1131 Stage::GetCurrent().Remove(actor);
1132 application.SendNotification();
1133 application.Render();
1136 // Send a Started state, no signal.
1137 application.ProcessEvent(GenerateTap(Gesture::Started, 1u, 1u, Vector2(50.0f, 10.0f)));
1138 DALI_TEST_EQUALS(false, data.functorCalled, TEST_LOCATION);
1142 int UtcDaliTapGestureSystemOverlay(void)
1144 TestApplication application;
1145 Dali::Integration::Core& core = application.GetCore();
1146 Dali::Integration::SystemOverlay& systemOverlay( core.GetSystemOverlay() );
1147 systemOverlay.GetOverlayRenderTasks().CreateTask();
1149 Actor actor = Actor::New();
1150 actor.SetSize(100.0f, 100.0f);
1151 actor.SetAnchorPoint(AnchorPoint::TOP_LEFT);
1152 systemOverlay.Add(actor);
1154 // Render and notify
1155 application.SendNotification();
1156 application.Render();
1159 GestureReceivedFunctor functor(data);
1161 TapGestureDetector detector = TapGestureDetector::New();
1162 detector.Attach(actor);
1163 detector.DetectedSignal().Connect(&application, functor);
1165 Vector2 screenCoords( 50.0f, 50.0f );
1167 // Do a tap inside actor's area
1168 application.ProcessEvent( GenerateTap( Gesture::Possible, 1u, 1u, screenCoords ) );
1169 application.ProcessEvent( GenerateTap( Gesture::Started, 1u, 1u, screenCoords ) );
1170 DALI_TEST_EQUALS( false, data.functorCalled, TEST_LOCATION );