2 * Copyright (c) 2014 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/dali.h>
22 #include <dali/integration-api/events/touch-event-integ.h>
23 #include <dali/integration-api/events/tap-gesture-event.h>
24 #include <dali/integration-api/system-overlay.h>
25 #include <dali-test-suite-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, 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 ) : GestureReceivedFunctor( data ) { }
95 void operator()(Actor actor, TapGesture tap)
97 GestureReceivedFunctor::operator()( actor, tap );
98 Stage::GetCurrent().Remove( actor );
102 // Functor for receiving a touch event
103 struct TouchEventFunctor
105 bool operator()(Actor actor, const TouchEvent& touch)
108 unsigned int points = touch.GetPointCount();
111 const TouchPoint& touchPoint = touch.GetPoint(0);
112 tet_printf("Touch Point state = %d\n", touchPoint.state);
118 // Generate a TapGestureEvent to send to Core
119 Integration::TapGestureEvent GenerateTap(
120 Gesture::State state,
121 unsigned int numberOfTaps,
122 unsigned int numberOfTouches,
125 Integration::TapGestureEvent tap( state );
127 tap.numberOfTaps = numberOfTaps;
128 tap.numberOfTouches = numberOfTouches;
136 ///////////////////////////////////////////////////////////////////////////////
139 // Positive test case for a method
140 int UtcDaliTapGestureDetectorConstructor(void)
142 TestApplication application;
144 TapGestureDetector detector;
145 DALI_TEST_CHECK(!detector);
150 int UtcDaliTapGestureDetectorNew(void)
152 TestApplication application;
154 TapGestureDetector detector = TapGestureDetector::New();
155 DALI_TEST_CHECK(detector);
156 DALI_TEST_EQUALS(1u, detector.GetTapsRequired(), TEST_LOCATION);
157 DALI_TEST_EQUALS(1u, detector.GetTouchesRequired(), TEST_LOCATION);
159 TapGestureDetector detector2 = TapGestureDetector::New(5u, 5u);
160 DALI_TEST_CHECK(detector2);
161 DALI_TEST_EQUALS(5u, detector2.GetTapsRequired(), TEST_LOCATION);
162 DALI_TEST_EQUALS(5u, detector2.GetTouchesRequired(), TEST_LOCATION);
164 //Scoped test to test destructor
166 TapGestureDetector detector3 = TapGestureDetector::New();
167 DALI_TEST_CHECK(detector3);
170 // Attach an actor and emit a touch event on the actor to ensure complete line coverage
171 Actor actor = Actor::New();
172 actor.SetSize(100.0f, 100.0f);
173 actor.SetAnchorPoint(AnchorPoint::TOP_LEFT);
174 Stage::GetCurrent().Add(actor);
177 application.SendNotification();
178 application.Render();
180 detector.Attach(actor);
182 TouchEventFunctor touchFunctor;
183 actor.TouchedSignal().Connect( &application, touchFunctor );
185 Integration::TouchEvent touchEvent(1);
186 TouchPoint point(1, TouchPoint::Down, 20.0f, 20.0f);
187 touchEvent.AddPoint(point);
188 application.ProcessEvent(touchEvent);
191 application.SendNotification();
192 application.Render();
194 // For line coverage, Initialise default constructor
195 TouchEvent touchEvent2;
199 int UtcDaliTapGestureDetectorDownCast(void)
201 TestApplication application;
202 tet_infoline("Testing Dali::TapGestureDetector::DownCast()");
204 TapGestureDetector detector = TapGestureDetector::New();
206 BaseHandle object(detector);
208 TapGestureDetector detector2 = TapGestureDetector::DownCast(object);
209 DALI_TEST_CHECK(detector2);
211 TapGestureDetector detector3 = DownCast< TapGestureDetector >(object);
212 DALI_TEST_CHECK(detector3);
214 BaseHandle unInitializedObject;
215 TapGestureDetector detector4 = TapGestureDetector::DownCast(unInitializedObject);
216 DALI_TEST_CHECK(!detector4);
218 TapGestureDetector detector5 = DownCast< TapGestureDetector >(unInitializedObject);
219 DALI_TEST_CHECK(!detector5);
221 GestureDetector detector6 = TapGestureDetector::New();
222 TapGestureDetector detector7 = TapGestureDetector::DownCast(detector6);
223 DALI_TEST_CHECK(detector7);
227 int UtcDaliTapGestureSetTapsRequired(void)
229 TestApplication application;
231 TapGestureDetector detector = TapGestureDetector::New();
233 unsigned int taps = 3;
235 DALI_TEST_CHECK(taps != detector.GetTapsRequired());
237 detector.SetTapsRequired(taps);
239 DALI_TEST_EQUALS(taps, detector.GetTapsRequired(), TEST_LOCATION);
241 // Attach an actor and change the required touches
243 Actor actor = Actor::New();
244 actor.SetSize(100.0f, 100.0f);
245 actor.SetAnchorPoint(AnchorPoint::TOP_LEFT);
246 Stage::GetCurrent().Add(actor);
249 application.SendNotification();
250 application.Render();
253 GestureReceivedFunctor functor(data);
255 detector.Attach(actor);
256 detector.DetectedSignal().Connect( &application, functor );
258 TestGestureManager& gestureManager = application.GetGestureManager();
259 gestureManager.Initialize();
261 detector.SetTapsRequired(4);
263 // Gesture detection should have been updated only
264 DALI_TEST_EQUALS(true, gestureManager.WasCalled(TestGestureManager::UpdateType), TEST_LOCATION);
265 DALI_TEST_EQUALS(false, gestureManager.WasCalled(TestGestureManager::RegisterType), TEST_LOCATION);
266 DALI_TEST_EQUALS(false, gestureManager.WasCalled(TestGestureManager::UnregisterType), TEST_LOCATION);
269 gestureManager.Initialize();
271 // Create a second gesture detector that requires even less maximum touches
272 TapGestureDetector secondDetector = TapGestureDetector::New();
273 secondDetector.Attach(actor);
275 // Gesture detection should have been updated
276 DALI_TEST_EQUALS(true, gestureManager.WasCalled(TestGestureManager::UpdateType), TEST_LOCATION);
277 DALI_TEST_EQUALS(false, gestureManager.WasCalled(TestGestureManager::RegisterType), TEST_LOCATION);
278 DALI_TEST_EQUALS(false, gestureManager.WasCalled(TestGestureManager::UnregisterType), TEST_LOCATION);
282 int UtcDaliTapGestureGetTapsRequired(void)
284 TestApplication application;
286 TapGestureDetector detector = TapGestureDetector::New();
287 DALI_TEST_EQUALS(1u, detector.GetTapsRequired(), TEST_LOCATION);
291 int UtcDaliTapGestureSetTouchesRequired(void)
293 TestApplication application;
295 TapGestureDetector detector = TapGestureDetector::New();
297 unsigned int max = 3;
299 DALI_TEST_CHECK(max != detector.GetTouchesRequired());
301 detector.SetTouchesRequired(max);
303 DALI_TEST_EQUALS(max, detector.GetTouchesRequired(), TEST_LOCATION);
305 // Attach an actor and change the maximum touches
307 Actor actor = Actor::New();
308 actor.SetSize(100.0f, 100.0f);
309 actor.SetAnchorPoint(AnchorPoint::TOP_LEFT);
310 Stage::GetCurrent().Add(actor);
313 application.SendNotification();
314 application.Render();
317 GestureReceivedFunctor functor(data);
319 detector.Attach(actor);
320 detector.DetectedSignal().Connect( &application, functor );
322 TestGestureManager& gestureManager = application.GetGestureManager();
323 gestureManager.Initialize();
325 detector.SetTouchesRequired(4);
327 // Gesture detection should have been updated only
328 DALI_TEST_EQUALS(true, gestureManager.WasCalled(TestGestureManager::UpdateType), TEST_LOCATION);
329 DALI_TEST_EQUALS(false, gestureManager.WasCalled(TestGestureManager::RegisterType), TEST_LOCATION);
330 DALI_TEST_EQUALS(false, gestureManager.WasCalled(TestGestureManager::UnregisterType), TEST_LOCATION);
333 gestureManager.Initialize();
335 // Create a second gesture detector that requires even less maximum touches
336 TapGestureDetector secondDetector = TapGestureDetector::New();
337 secondDetector.Attach(actor);
339 // Gesture detection should have been updated
340 DALI_TEST_EQUALS(true, gestureManager.WasCalled(TestGestureManager::UpdateType), TEST_LOCATION);
341 DALI_TEST_EQUALS(false, gestureManager.WasCalled(TestGestureManager::RegisterType), TEST_LOCATION);
342 DALI_TEST_EQUALS(false, gestureManager.WasCalled(TestGestureManager::UnregisterType), TEST_LOCATION);
346 int UtcDaliTapGestureGetTouchesRequired(void)
348 TestApplication application;
350 TapGestureDetector detector = TapGestureDetector::New();
351 DALI_TEST_EQUALS(1u, detector.GetTouchesRequired(), TEST_LOCATION);
355 int UtcDaliTapGestureSignalReceptionNegative(void)
357 TestApplication application;
359 Actor actor = Actor::New();
360 actor.SetSize(100.0f, 100.0f);
361 actor.SetAnchorPoint(AnchorPoint::TOP_LEFT);
362 Stage::GetCurrent().Add(actor);
365 application.SendNotification();
366 application.Render();
369 GestureReceivedFunctor functor(data);
371 TapGestureDetector detector = TapGestureDetector::New();
372 detector.Attach(actor);
373 detector.DetectedSignal().Connect( &application, functor );
375 // Do a tap outside actor's area
376 application.ProcessEvent(GenerateTap(Gesture::Possible, 1u, 1u, Vector2(112.0f, 112.0f)));
377 application.ProcessEvent(GenerateTap(Gesture::Started, 1u, 1u, Vector2(112.0f, 112.0f)));
378 DALI_TEST_EQUALS(false, data.functorCalled, TEST_LOCATION);
382 int UtcDaliTapGestureSignalReceptionPositive(void)
384 TestApplication application;
386 Actor actor = Actor::New();
387 actor.SetSize(100.0f, 100.0f);
388 actor.SetAnchorPoint(AnchorPoint::TOP_LEFT);
389 Stage::GetCurrent().Add(actor);
392 application.SendNotification();
393 application.Render();
396 GestureReceivedFunctor functor(data);
398 TapGestureDetector detector = TapGestureDetector::New();
399 detector.Attach(actor);
400 detector.DetectedSignal().Connect( &application, functor );
402 // Do a tap inside actor's area
403 application.ProcessEvent(GenerateTap(Gesture::Possible, 1u, 1u, Vector2(50.0f, 50.0f)));
404 application.ProcessEvent(GenerateTap(Gesture::Started, 1u, 1u, Vector2(50.0f, 50.0f)));
405 DALI_TEST_EQUALS(true, data.functorCalled, TEST_LOCATION);
406 DALI_TEST_EQUALS(1u, data.receivedGesture.numberOfTaps, TEST_LOCATION);
407 DALI_TEST_EQUALS(1u, data.receivedGesture.numberOfTouches, TEST_LOCATION);
408 DALI_TEST_EQUALS( Vector2(50.0f, 50.0f), data.receivedGesture.localPoint, 0.1, TEST_LOCATION);
412 int UtcDaliTapGestureSignalReceptionDetach(void)
414 TestApplication application;
416 Actor actor = Actor::New();
417 actor.SetSize(100.0f, 100.0f);
418 actor.SetAnchorPoint(AnchorPoint::TOP_LEFT);
419 Stage::GetCurrent().Add(actor);
422 application.SendNotification();
423 application.Render();
426 GestureReceivedFunctor functor(data);
428 TapGestureDetector detector = TapGestureDetector::New();
429 detector.Attach(actor);
430 detector.DetectedSignal().Connect(&application, functor);
432 // Start tap within the actor's area
433 application.ProcessEvent(GenerateTap(Gesture::Possible, 1u, 1u, Vector2(20.0f, 20.0f)));
434 application.ProcessEvent(GenerateTap(Gesture::Started, 1u, 1u, Vector2(20.0f, 20.0f)));
435 DALI_TEST_EQUALS(true, data.functorCalled, TEST_LOCATION);
436 DALI_TEST_EQUALS(1u, data.receivedGesture.numberOfTaps, TEST_LOCATION);
437 DALI_TEST_EQUALS(1u, data.receivedGesture.numberOfTouches, TEST_LOCATION);
438 DALI_TEST_EQUALS( Vector2(20.0f, 20.0f), data.receivedGesture.localPoint, 0.1, TEST_LOCATION);
440 // repeat the tap within the actor's area - we should still receive the signal
442 application.ProcessEvent(GenerateTap(Gesture::Possible, 1u, 1u, Vector2(50.0f, 50.0f)));
443 application.ProcessEvent(GenerateTap(Gesture::Started, 1u, 1u, Vector2(50.0f, 50.0f)));
444 DALI_TEST_EQUALS(true, data.functorCalled, TEST_LOCATION);
445 DALI_TEST_EQUALS(1u, data.receivedGesture.numberOfTaps, TEST_LOCATION);
446 DALI_TEST_EQUALS(1u, data.receivedGesture.numberOfTouches, TEST_LOCATION);
447 DALI_TEST_EQUALS( Vector2(50.0f, 50.0f), data.receivedGesture.localPoint, 0.1, TEST_LOCATION);
450 detector.DetachAll();
452 // Ensure we are no longer signalled
454 application.ProcessEvent(GenerateTap(Gesture::Possible, 1u, 1u, Vector2(20.0f, 20.0f)));
455 application.ProcessEvent(GenerateTap(Gesture::Started, 1u, 1u, Vector2(20.0f, 20.0f)));
456 DALI_TEST_EQUALS(false, data.functorCalled, TEST_LOCATION);
457 application.ProcessEvent(GenerateTap(Gesture::Possible, 1u, 1u, Vector2(50.0f, 50.0f)));
458 application.ProcessEvent(GenerateTap(Gesture::Started, 1u, 1u, Vector2(50.0f, 50.0f)));
459 DALI_TEST_EQUALS(false, data.functorCalled, TEST_LOCATION);
463 int UtcDaliTapGestureSignalReceptionActorDestroyedWhileTapping(void)
465 TestApplication application;
468 GestureReceivedFunctor functor(data);
470 TapGestureDetector detector = TapGestureDetector::New();
471 detector.DetectedSignal().Connect(&application, functor);
473 // Actor lifetime is scoped
475 Actor actor = Actor::New();
476 actor.SetSize(100.0f, 100.0f);
477 actor.SetAnchorPoint(AnchorPoint::TOP_LEFT);
478 Stage::GetCurrent().Add(actor);
481 application.SendNotification();
482 application.Render();
484 detector.Attach(actor);
486 // Start tap within the actor's area
487 application.ProcessEvent(GenerateTap(Gesture::Possible, 1u, 1u, Vector2(20.0f, 20.0f)));
488 application.ProcessEvent(GenerateTap(Gesture::Started, 1u, 1u, Vector2(20.0f, 20.0f)));
489 DALI_TEST_EQUALS(true, data.functorCalled, TEST_LOCATION);
491 // Remove the actor from stage and reset the data
492 Stage::GetCurrent().Remove(actor);
495 application.SendNotification();
496 application.Render();
499 // Actor should now have been destroyed
502 application.ProcessEvent(GenerateTap(Gesture::Possible, 1u, 1u, Vector2(20.0f, 20.0f)));
503 application.ProcessEvent(GenerateTap(Gesture::Started, 1u, 1u, Vector2(20.0f, 20.0f)));
504 DALI_TEST_EQUALS(false, data.functorCalled, TEST_LOCATION);
508 int UtcDaliTapGestureSignalReceptionRotatedActor(void)
510 TestApplication application;
512 Actor actor = Actor::New();
513 actor.SetSize(100.0f, 100.0f);
514 actor.SetRotation(Dali::Degree(90.0f), Vector3::ZAXIS);
515 Stage::GetCurrent().Add(actor);
518 application.SendNotification();
519 application.Render();
522 GestureReceivedFunctor functor(data);
524 TapGestureDetector detector = TapGestureDetector::New();
525 detector.Attach(actor);
526 detector.DetectedSignal().Connect(&application, functor);
528 // Do tap, only check finished value
529 application.ProcessEvent(GenerateTap(Gesture::Possible, 1u, 1u, Vector2(5.0f, 5.0f)));
530 application.ProcessEvent(GenerateTap(Gesture::Started, 1u, 1u, Vector2(5.0f, 5.0f)));
531 DALI_TEST_EQUALS(true, data.functorCalled, TEST_LOCATION);
532 DALI_TEST_EQUALS(1u, data.receivedGesture.numberOfTaps, TEST_LOCATION);
533 DALI_TEST_EQUALS(1u, data.receivedGesture.numberOfTouches, TEST_LOCATION);
534 DALI_TEST_EQUALS( Vector2(5.0f, 5.0f), data.receivedGesture.screenPoint, 0.1, TEST_LOCATION);
536 // Rotate actor again and render
537 actor.SetRotation(Dali::Degree(180.0f), Vector3::ZAXIS);
538 application.SendNotification();
539 application.Render();
541 // Do tap, should still receive event
543 application.ProcessEvent(GenerateTap(Gesture::Possible, 1u, 1u, Vector2(5.0f, 5.0f)));
544 application.ProcessEvent(GenerateTap(Gesture::Started, 1u, 1u, Vector2(5.0f, 5.0f)));
545 DALI_TEST_EQUALS(true, data.functorCalled, TEST_LOCATION);
546 DALI_TEST_EQUALS(1u, data.receivedGesture.numberOfTaps, TEST_LOCATION);
547 DALI_TEST_EQUALS(1u, data.receivedGesture.numberOfTouches, TEST_LOCATION);
548 DALI_TEST_EQUALS( Vector2(5.0f, 5.0f), data.receivedGesture.screenPoint, 0.1, TEST_LOCATION);
550 // Rotate actor again and render
551 actor.SetRotation(Dali::Degree(90.0f), Vector3::YAXIS);
552 application.SendNotification();
553 application.Render();
555 // Do tap, inside the actor's area (area if it is not rotated), Should not receive the event
557 application.ProcessEvent(GenerateTap(Gesture::Possible, 1u, 1u, Vector2(70.0f, 70.0f)));
558 application.ProcessEvent(GenerateTap(Gesture::Started, 1u, 1u, Vector2(70.0f, 70.0f)));
559 DALI_TEST_EQUALS(false, data.functorCalled, TEST_LOCATION);
563 int UtcDaliTapGestureSignalReceptionChildHit(void)
565 TestApplication application;
567 Actor parent = Actor::New();
568 parent.SetSize(100.0f, 100.0f);
569 parent.SetAnchorPoint(AnchorPoint::TOP_LEFT);
570 Stage::GetCurrent().Add(parent);
572 // Set child to completely cover parent.
573 // Change rotation of child to be different from parent so that we can check if our local coordinate
574 // conversion of the parent actor is correct.
575 Actor child = Actor::New();
576 child.SetSize(100.0f, 100.0f);
577 child.SetAnchorPoint(AnchorPoint::CENTER);
578 child.SetParentOrigin(ParentOrigin::CENTER);
579 child.SetRotation(Dali::Degree(90.0f), Vector3::ZAXIS);
582 TouchEventFunctor touchFunctor;
583 child.TouchedSignal().Connect(&application, touchFunctor);
586 application.SendNotification();
587 application.Render();
590 GestureReceivedFunctor functor(data);
592 TapGestureDetector detector = TapGestureDetector::New();
593 detector.Attach(parent);
594 detector.DetectedSignal().Connect(&application, functor);
596 // Do tap - hits child area but parent should still receive it
597 application.ProcessEvent(GenerateTap(Gesture::Possible, 1u, 1u, Vector2(50.0f, 50.0f)));
598 application.ProcessEvent(GenerateTap(Gesture::Started, 1u, 1u, Vector2(50.0f, 50.0f)));
599 DALI_TEST_EQUALS(true, data.functorCalled, TEST_LOCATION);
600 DALI_TEST_EQUALS(true, parent == data.tappedActor, TEST_LOCATION);
601 DALI_TEST_EQUALS(Vector2(50.0f, 50.0f), data.receivedGesture.screenPoint, 0.01f, TEST_LOCATION);
603 // Attach child and generate same touch points
604 // (Also proves that you can detach and then re-attach another actor)
605 detector.Attach(child);
606 detector.Detach(parent);
608 // Do an entire tap, only check finished value
610 application.ProcessEvent(GenerateTap(Gesture::Possible, 1u, 1u, Vector2(51.0f, 51.0f)));
611 application.ProcessEvent(GenerateTap(Gesture::Started, 1u, 1u, Vector2(51.0f, 51.0f)));
612 DALI_TEST_EQUALS(true, data.functorCalled, TEST_LOCATION);
613 DALI_TEST_EQUALS(true, child == data.tappedActor, TEST_LOCATION);
614 DALI_TEST_EQUALS(Vector2(51.0f, 51.0f), data.receivedGesture.screenPoint, 0.01f, TEST_LOCATION);
618 int UtcDaliTapGestureSignalReceptionAttachDetachMany(void)
620 TestApplication application;
622 Actor first = Actor::New();
623 first.SetSize(100.0f, 100.0f);
624 first.SetAnchorPoint(AnchorPoint::TOP_LEFT);
625 Stage::GetCurrent().Add(first);
627 Actor second = Actor::New();
628 second.SetSize(100.0f, 100.0f);
630 second.SetAnchorPoint(AnchorPoint::TOP_LEFT);
631 Stage::GetCurrent().Add(second);
634 application.SendNotification();
635 application.Render();
638 GestureReceivedFunctor functor(data);
640 TapGestureDetector detector = TapGestureDetector::New();
641 detector.Attach(first);
642 detector.Attach(second);
643 detector.DetectedSignal().Connect(&application, functor);
645 // Tap within second actor's area
646 application.ProcessEvent(GenerateTap(Gesture::Possible, 1u, 1u, Vector2(120.0f, 10.0f)));
647 application.ProcessEvent(GenerateTap(Gesture::Started, 1u, 1u, Vector2(120.0f, 10.0f)));
648 DALI_TEST_EQUALS(true, data.functorCalled, TEST_LOCATION);
649 DALI_TEST_EQUALS(true, second == data.tappedActor, TEST_LOCATION);
651 // Tap within first actor's area
653 application.ProcessEvent(GenerateTap(Gesture::Possible, 1u, 1u, Vector2(20.0f, 10.0f)));
654 application.ProcessEvent(GenerateTap(Gesture::Started, 1u, 1u, Vector2(20.0f, 10.0f)));
655 DALI_TEST_EQUALS(true, data.functorCalled, TEST_LOCATION);
656 DALI_TEST_EQUALS(true, first == data.tappedActor, TEST_LOCATION);
658 // Detach the second actor
659 detector.Detach(second);
661 // second actor shouldn't receive event
663 application.ProcessEvent(GenerateTap(Gesture::Possible, 1u, 1u, Vector2(120.0f, 10.0f)));
664 application.ProcessEvent(GenerateTap(Gesture::Started, 1u, 1u, Vector2(120.0f, 10.0f)));
665 DALI_TEST_EQUALS(false, data.functorCalled, TEST_LOCATION);
667 // first actor should continue receiving event
669 application.ProcessEvent(GenerateTap(Gesture::Possible, 1u, 1u, Vector2(20.0f, 10.0f)));
670 application.ProcessEvent(GenerateTap(Gesture::Started, 1u, 1u, Vector2(20.0f, 10.0f)));
671 DALI_TEST_EQUALS(true, data.functorCalled, TEST_LOCATION);
675 int UtcDaliTapGestureSignalReceptionActorBecomesUntouchable(void)
677 TestApplication application;
679 Actor actor = Actor::New();
680 actor.SetSize(100.0f, 100.0f);
681 actor.SetAnchorPoint(AnchorPoint::TOP_LEFT);
682 Stage::GetCurrent().Add(actor);
685 application.SendNotification();
686 application.Render();
689 GestureReceivedFunctor functor(data);
691 TapGestureDetector detector = TapGestureDetector::New();
692 detector.Attach(actor);
693 detector.DetectedSignal().Connect(&application, functor);
695 // Tap in actor's area
696 application.ProcessEvent(GenerateTap(Gesture::Possible, 1u, 1u, Vector2(50.0f, 10.0f)));
697 application.ProcessEvent(GenerateTap(Gesture::Started, 1u, 1u, Vector2(50.0f, 10.0f)));
698 DALI_TEST_EQUALS(true, data.functorCalled, TEST_LOCATION);
700 // Actor become invisible - actor should not receive the next pan
701 actor.SetVisible(false);
704 application.SendNotification();
705 application.Render();
707 // Tap in the same area, shouldn't receive event
709 application.ProcessEvent(GenerateTap(Gesture::Possible, 1u, 1u, Vector2(50.0f, 10.0f)));
710 application.ProcessEvent(GenerateTap(Gesture::Started, 1u, 1u, Vector2(50.0f, 10.0f)));
711 DALI_TEST_EQUALS(false, data.functorCalled, TEST_LOCATION);
715 int UtcDaliTapGestureSignalReceptionMultipleGestureDetectors(void)
717 TestApplication application;
718 Dali::TestGestureManager& gestureManager = application.GetGestureManager();
720 Actor first = Actor::New();
721 first.SetSize(100.0f, 100.0f);
722 first.SetAnchorPoint(AnchorPoint::TOP_LEFT);
723 Stage::GetCurrent().Add(first);
725 Actor second = Actor::New();
726 second.SetSize(100.0f, 100.0f);
727 second.SetAnchorPoint(AnchorPoint::TOP_LEFT);
732 application.SendNotification();
733 application.Render();
736 GestureReceivedFunctor functor(data);
738 TapGestureDetector firstDetector = TapGestureDetector::New();
739 firstDetector.Attach(first);
740 firstDetector.DetectedSignal().Connect(&application, functor);
742 // secondDetector is scoped
744 // Reset gestureManager statistics
745 gestureManager.Initialize();
747 TapGestureDetector secondDetector = TapGestureDetector::New();
748 secondDetector.SetTapsRequired(2);
749 secondDetector.SetTouchesRequired(2);
750 secondDetector.Attach(second);
751 secondDetector.DetectedSignal().Connect(&application, functor);
753 DALI_TEST_EQUALS(true, gestureManager.WasCalled(TestGestureManager::UpdateType), TEST_LOCATION);
754 DALI_TEST_EQUALS(false, gestureManager.WasCalled(TestGestureManager::RegisterType), TEST_LOCATION);
755 DALI_TEST_EQUALS(false, gestureManager.WasCalled(TestGestureManager::UnregisterType), TEST_LOCATION);
757 // Tap within second actor's area
758 application.ProcessEvent(GenerateTap(Gesture::Possible, 2u, 2u, Vector2(150.0f, 10.0f)));
759 application.ProcessEvent(GenerateTap(Gesture::Started, 2u, 2u, Vector2(150.0f, 10.0f)));
760 DALI_TEST_EQUALS(true, data.functorCalled, TEST_LOCATION);
761 DALI_TEST_EQUALS(true, second == data.tappedActor, TEST_LOCATION);
763 // Tap continues as single touch gesture - we should not receive any gesture
765 application.ProcessEvent(GenerateTap(Gesture::Possible, 1u, 1u, Vector2(150.0f, 10.0f)));
766 application.ProcessEvent(GenerateTap(Gesture::Started, 1u, 1u, Vector2(150.0f, 10.0f)));
767 DALI_TEST_EQUALS(false, data.functorCalled, TEST_LOCATION);
769 // Single touch tap starts - first actor should be panned
771 application.ProcessEvent(GenerateTap(Gesture::Possible, 1u, 1u, Vector2(50.0f, 10.0f)));
772 application.ProcessEvent(GenerateTap(Gesture::Started, 1u, 1u, Vector2(50.0f, 10.0f)));
773 DALI_TEST_EQUALS(true, data.functorCalled, TEST_LOCATION);
774 DALI_TEST_EQUALS(true, first == data.tappedActor, TEST_LOCATION);
776 // Pan changes to double-touch - we shouldn't receive event
778 application.ProcessEvent(GenerateTap(Gesture::Possible, 2u, 2u, Vector2(50.0f, 10.0f)));
779 application.ProcessEvent(GenerateTap(Gesture::Started, 2u, 2u, Vector2(50.0f, 10.0f)));
780 DALI_TEST_EQUALS(false, data.functorCalled, TEST_LOCATION);
782 // Reset gesture manager statistics
783 gestureManager.Initialize();
786 // secondDetector has now been deleted. Gesture detection should have been updated only
787 DALI_TEST_EQUALS(true, gestureManager.WasCalled(TestGestureManager::UpdateType), TEST_LOCATION);
788 DALI_TEST_EQUALS(false, gestureManager.WasCalled(TestGestureManager::RegisterType), TEST_LOCATION);
789 DALI_TEST_EQUALS(false, gestureManager.WasCalled(TestGestureManager::UnregisterType), TEST_LOCATION);
793 int UtcDaliTapGestureSignalReceptionMultipleDetectorsOnActor(void)
795 TestApplication application;
797 Actor actor = Actor::New();
798 actor.SetSize(100.0f, 100.0f);
799 actor.SetAnchorPoint(AnchorPoint::TOP_LEFT);
800 Stage::GetCurrent().Add(actor);
803 application.SendNotification();
804 application.Render();
806 // Attach actor to one detector
807 SignalData firstData;
808 GestureReceivedFunctor firstFunctor(firstData);
809 TapGestureDetector firstDetector = TapGestureDetector::New();
810 firstDetector.Attach(actor);
811 firstDetector.DetectedSignal().Connect(&application, firstFunctor);
813 // Attach actor to another detector
814 SignalData secondData;
815 GestureReceivedFunctor secondFunctor(secondData);
816 TapGestureDetector secondDetector = TapGestureDetector::New();
817 secondDetector.Attach(actor);
818 secondDetector.DetectedSignal().Connect(&application, secondFunctor);
820 // Tap in actor's area - both detector's functors should be called
821 application.ProcessEvent(GenerateTap(Gesture::Possible, 1u, 1u, Vector2(50.0f, 10.0f)));
822 application.ProcessEvent(GenerateTap(Gesture::Started, 1u, 1u, Vector2(50.0f, 10.0f)));
823 DALI_TEST_EQUALS(true, firstData.functorCalled, TEST_LOCATION);
824 DALI_TEST_EQUALS(true, secondData.functorCalled, TEST_LOCATION);
828 int UtcDaliTapGestureSignalReceptionDifferentPossible(void)
830 TestApplication application;
832 Actor actor = Actor::New();
833 actor.SetSize(100.0f, 100.0f);
834 actor.SetAnchorPoint(AnchorPoint::TOP_LEFT);
835 Stage::GetCurrent().Add(actor);
838 application.SendNotification();
839 application.Render();
841 // Attach actor to detector
843 GestureReceivedFunctor functor( data );
844 TapGestureDetector detector = TapGestureDetector::New();
845 detector.Attach(actor);
846 detector.DetectedSignal().Connect( &application, functor );
848 // Gesture possible in actor's area.
849 application.ProcessEvent(GenerateTap(Gesture::Possible, 1u, 1u, Vector2(50.0f, 10.0f)));
850 DALI_TEST_EQUALS(false, data.functorCalled, TEST_LOCATION);
852 // Move actor somewhere else
853 actor.SetPosition( 100.0f, 100.0f );
856 application.SendNotification();
857 application.Render();
859 // Emit Started event, we should not receive the long press.
860 application.ProcessEvent(GenerateTap(Gesture::Started, 1u, 1u, Vector2(50.0f, 10.0f)));
861 DALI_TEST_EQUALS(false, data.functorCalled, TEST_LOCATION);
863 // LongPress possible in empty area.
864 application.ProcessEvent(GenerateTap(Gesture::Possible, 1u, 1u, Vector2(50.0f, 10.0f)));
865 DALI_TEST_EQUALS(false, data.functorCalled, TEST_LOCATION);
867 // Move actor in to the long press position.
868 actor.SetPosition( 0.0f, 0.0f );
871 application.SendNotification();
872 application.Render();
874 // Emit Started event, we should not receive the long press.
875 application.ProcessEvent(GenerateTap(Gesture::Started, 1u, 1u, Vector2(50.0f, 10.0f)));
876 DALI_TEST_EQUALS(false, data.functorCalled, TEST_LOCATION);
878 // Normal long press in actor's area for completeness.
879 application.ProcessEvent(GenerateTap(Gesture::Possible, 1u, 1u, Vector2(50.0f, 10.0f)));
880 application.ProcessEvent(GenerateTap(Gesture::Started, 1u, 1u, Vector2(50.0f, 10.0f)));
881 DALI_TEST_EQUALS(true, data.functorCalled, TEST_LOCATION);
885 int UtcDaliTapGestureEmitIncorrectStateClear(void)
887 TestApplication application;
889 Actor actor = Actor::New();
890 actor.SetSize(100.0f, 100.0f);
891 actor.SetAnchorPoint(AnchorPoint::TOP_LEFT);
892 Stage::GetCurrent().Add(actor);
895 application.SendNotification();
896 application.Render();
898 // Attach actor to detector
900 GestureReceivedFunctor functor( data );
901 TapGestureDetector detector = TapGestureDetector::New();
902 detector.Attach(actor);
903 detector.DetectedSignal().Connect( &application, functor );
908 application.ProcessEvent(GenerateTap(Gesture::Clear, 1u, 1u, Vector2(50.0f, 10.0f)));
909 tet_result(TET_FAIL);
911 catch ( Dali::DaliException& e )
913 DALI_TEST_ASSERT( e, "false", TEST_LOCATION );
918 int UtcDaliTapGestureEmitIncorrectStateContinuing(void)
920 TestApplication application;
922 Actor actor = Actor::New();
923 actor.SetSize(100.0f, 100.0f);
924 actor.SetAnchorPoint(AnchorPoint::TOP_LEFT);
925 Stage::GetCurrent().Add(actor);
928 application.SendNotification();
929 application.Render();
931 // Attach actor to detector
933 GestureReceivedFunctor functor( data );
934 TapGestureDetector detector = TapGestureDetector::New();
935 detector.Attach(actor);
936 detector.DetectedSignal().Connect( &application, functor );
938 // Try a Continuing state
941 application.ProcessEvent(GenerateTap(Gesture::Continuing, 1u, 1u, Vector2(50.0f, 10.0f)));
942 tet_result(TET_FAIL);
944 catch ( Dali::DaliException& e )
946 DALI_TEST_ASSERT( e, "false", TEST_LOCATION );
951 int UtcDaliTapGestureEmitIncorrectStateFinished(void)
953 TestApplication application;
955 Actor actor = Actor::New();
956 actor.SetSize(100.0f, 100.0f);
957 actor.SetAnchorPoint(AnchorPoint::TOP_LEFT);
958 Stage::GetCurrent().Add(actor);
961 application.SendNotification();
962 application.Render();
964 // Attach actor to detector
966 GestureReceivedFunctor functor( data );
967 TapGestureDetector detector = TapGestureDetector::New();
968 detector.Attach(actor);
969 detector.DetectedSignal().Connect( &application, functor );
971 // Try a Finished state
974 application.ProcessEvent(GenerateTap(Gesture::Finished, 1u, 1u, Vector2(50.0f, 10.0f)));
975 tet_result(TET_FAIL);
977 catch ( Dali::DaliException& e )
979 DALI_TEST_ASSERT( e, "false", TEST_LOCATION );
984 int UtcDaliTapGestureActorUnstaged(void)
986 TestApplication application;
988 Actor actor = Actor::New();
989 actor.SetSize(100.0f, 100.0f);
990 actor.SetAnchorPoint(AnchorPoint::TOP_LEFT);
991 Stage::GetCurrent().Add(actor);
994 application.SendNotification();
995 application.Render();
997 // Attach actor to detector
999 UnstageActorFunctor functor( data );
1000 TapGestureDetector detector = TapGestureDetector::New();
1001 detector.Attach(actor);
1002 detector.DetectedSignal().Connect( &application, functor );
1004 // Tap in Actor's area, actor removed in signal handler, should be handled gracefully.
1005 application.ProcessEvent(GenerateTap(Gesture::Possible, 1u, 1u, Vector2(50.0f, 10.0f)));
1006 application.ProcessEvent(GenerateTap(Gesture::Started, 1u, 1u, Vector2(50.0f, 10.0f)));
1007 DALI_TEST_EQUALS( true, data.functorCalled, TEST_LOCATION );
1008 tet_result( TET_PASS ); // If we get here, then the actor removal on signal handler was handled gracefully.
1012 int UtcDaliTapGestureRepeatedState(void)
1014 TestApplication application;
1016 Actor actor = Actor::New();
1017 actor.SetSize(100.0f, 100.0f);
1018 actor.SetAnchorPoint(AnchorPoint::TOP_LEFT);
1019 Stage::GetCurrent().Add(actor);
1021 // Render and notify
1022 application.SendNotification();
1023 application.Render();
1025 // Attach actor to detector
1027 GestureReceivedFunctor functor( data );
1028 TapGestureDetector detector = TapGestureDetector::New();
1029 detector.Attach(actor);
1030 detector.DetectedSignal().Connect( &application, functor );
1032 // Emit two possibles
1033 application.ProcessEvent(GenerateTap(Gesture::Possible, 1u, 1u, Vector2(50.0f, 10.0f)));
1034 application.ProcessEvent(GenerateTap(Gesture::Possible, 1u, 1u, Vector2(50.0f, 10.0f)));
1035 DALI_TEST_EQUALS(false, data.functorCalled, TEST_LOCATION);
1037 // Send a couple of Started states, only first one should be received.
1038 application.ProcessEvent(GenerateTap(Gesture::Started, 1u, 1u, Vector2(50.0f, 10.0f)));
1039 DALI_TEST_EQUALS(true, data.functorCalled, TEST_LOCATION);
1041 application.ProcessEvent(GenerateTap(Gesture::Started, 1u, 1u, Vector2(50.0f, 10.0f)));
1042 DALI_TEST_EQUALS(false, data.functorCalled, TEST_LOCATION);
1044 // Send a couple of cancelled states, no reception
1045 application.ProcessEvent(GenerateTap(Gesture::Cancelled, 1u, 1u, Vector2(50.0f, 10.0f)));
1046 application.ProcessEvent(GenerateTap(Gesture::Cancelled, 1u, 1u, Vector2(50.0f, 10.0f)));
1047 DALI_TEST_EQUALS(false, data.functorCalled, TEST_LOCATION);
1051 int UtcDaliTapGesturePossibleCancelled(void)
1053 TestApplication application;
1055 Actor actor = Actor::New();
1056 actor.SetSize(100.0f, 100.0f);
1057 actor.SetAnchorPoint(AnchorPoint::TOP_LEFT);
1058 Stage::GetCurrent().Add(actor);
1060 // Render and notify
1061 application.SendNotification();
1062 application.Render();
1064 // Attach actor to detector
1066 GestureReceivedFunctor functor( data );
1067 TapGestureDetector detector = TapGestureDetector::New();
1068 detector.Attach(actor);
1069 detector.DetectedSignal().Connect( &application, functor );
1071 // Emit a possible and then a cancelled, no reception
1072 application.ProcessEvent(GenerateTap(Gesture::Possible, 1u, 1u, Vector2(50.0f, 10.0f)));
1073 application.ProcessEvent(GenerateTap(Gesture::Cancelled, 1u, 1u, Vector2(50.0f, 10.0f)));
1074 DALI_TEST_EQUALS(false, data.functorCalled, TEST_LOCATION);
1078 int UtcDaliTapGestureDetectorRemovedWhilePossible(void)
1080 TestApplication application;
1082 Actor actor = Actor::New();
1083 actor.SetSize(100.0f, 100.0f);
1084 actor.SetAnchorPoint(AnchorPoint::TOP_LEFT);
1085 Stage::GetCurrent().Add(actor);
1087 // Render and notify
1088 application.SendNotification();
1089 application.Render();
1091 // Attach actor to detector
1093 GestureReceivedFunctor functor( data );
1094 TapGestureDetector detector = TapGestureDetector::New();
1095 detector.Attach(actor);
1096 detector.DetectedSignal().Connect( &application, functor );
1099 application.ProcessEvent(GenerateTap(Gesture::Possible, 1u, 1u, Vector2(50.0f, 10.0f)));
1101 // Detach actor and send a Started state, no signal.
1102 detector.DetachAll();
1103 application.ProcessEvent(GenerateTap(Gesture::Started, 1u, 1u, Vector2(50.0f, 10.0f)));
1104 DALI_TEST_EQUALS(false, data.functorCalled, TEST_LOCATION);
1108 int UtcDaliTapGestureActorRemovedWhilePossible(void)
1110 TestApplication application;
1112 Actor actor = Actor::New();
1113 actor.SetSize(100.0f, 100.0f);
1114 actor.SetAnchorPoint(AnchorPoint::TOP_LEFT);
1115 Stage::GetCurrent().Add(actor);
1117 // Render and notify
1118 application.SendNotification();
1119 application.Render();
1121 // Attach actor to detector
1123 GestureReceivedFunctor functor( data );
1124 TapGestureDetector detector = TapGestureDetector::New();
1125 detector.Attach(actor);
1126 detector.DetectedSignal().Connect( &application, functor );
1129 application.ProcessEvent(GenerateTap(Gesture::Possible, 1u, 1u, Vector2(50.0f, 10.0f)));
1131 // Remove, render and delete actor
1132 Stage::GetCurrent().Remove(actor);
1133 application.SendNotification();
1134 application.Render();
1137 // Send a Started state, no signal.
1138 application.ProcessEvent(GenerateTap(Gesture::Started, 1u, 1u, Vector2(50.0f, 10.0f)));
1139 DALI_TEST_EQUALS(false, data.functorCalled, TEST_LOCATION);
1143 int UtcDaliTapGestureSystemOverlay(void)
1145 TestApplication application;
1146 Dali::Integration::Core& core = application.GetCore();
1147 Dali::Integration::SystemOverlay& systemOverlay( core.GetSystemOverlay() );
1148 systemOverlay.GetOverlayRenderTasks().CreateTask();
1150 Actor actor = Actor::New();
1151 actor.SetSize(100.0f, 100.0f);
1152 actor.SetAnchorPoint(AnchorPoint::TOP_LEFT);
1153 systemOverlay.Add(actor);
1155 // Render and notify
1156 application.SendNotification();
1157 application.Render();
1160 GestureReceivedFunctor functor(data);
1162 TapGestureDetector detector = TapGestureDetector::New();
1163 detector.Attach(actor);
1164 detector.DetectedSignal().Connect(&application, functor);
1166 Vector2 screenCoords( 50.0f, 50.0f );
1168 // Do a tap inside actor's area
1169 application.ProcessEvent( GenerateTap( Gesture::Possible, 1u, 1u, screenCoords ) );
1170 application.ProcessEvent( GenerateTap( Gesture::Started, 1u, 1u, screenCoords ) );
1171 DALI_TEST_EQUALS( false, data.functorCalled, TEST_LOCATION );