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/public-api/dali-core.h>
22 #include <dali/integration-api/events/touch-event-integ.h>
23 #include <dali/integration-api/events/long-press-gesture-event.h>
24 #include <dali/integration-api/system-overlay.h>
25 #include <dali-test-suite-utils.h>
26 #include <test-touch-utils.h>
30 void utc_dali_long_press_gesture_detector_startup(void)
32 test_return_value = TET_UNDEF;
35 void utc_dali_long_press_gesture_detector_cleanup(void)
37 test_return_value = TET_PASS;
40 ///////////////////////////////////////////////////////////////////////////////
44 // Stores data that is populated in the callback and will be read by the TET cases
48 : functorCalled( false ),
49 voidFunctorCalled( false ),
50 receivedGesture( Gesture::Clear ),
56 functorCalled = false;
57 voidFunctorCalled = false;
59 receivedGesture.numberOfTouches = 0u;
60 receivedGesture.screenPoint = Vector2(0.0f, 0.0f);
61 receivedGesture.localPoint = Vector2(0.0f, 0.0f);
67 bool voidFunctorCalled;
68 LongPressGesture receivedGesture;
72 // Functor that sets the data when called
73 struct GestureReceivedFunctor
75 GestureReceivedFunctor(SignalData& data) : signalData(data) { }
77 void operator()(Actor actor, const LongPressGesture& longPress)
79 signalData.functorCalled = true;
80 signalData.receivedGesture = longPress;
81 signalData.pressedActor = actor;
86 signalData.voidFunctorCalled = true;
89 SignalData& signalData;
92 // Functor that removes the gestured actor from stage
93 struct UnstageActorFunctor : public GestureReceivedFunctor
95 UnstageActorFunctor( SignalData& data, Gesture::State& stateToUnstage )
96 : GestureReceivedFunctor( data ),
97 stateToUnstage( stateToUnstage )
101 void operator()( Actor actor, const LongPressGesture& longPress )
103 GestureReceivedFunctor::operator()( actor, longPress );
105 if ( longPress.state == stateToUnstage )
107 Stage::GetCurrent().Remove( actor );
111 Gesture::State& stateToUnstage;
114 // Functor for receiving a touch event
115 struct TouchEventFunctor
117 bool operator()(Actor actor, const TouchEvent& touch)
120 unsigned int points = touch.GetPointCount();
123 const TouchPoint& touchPoint = touch.GetPoint(0);
124 tet_printf("Touch Point state = %d\n", touchPoint.state);
130 // Generate a LongPressGestureEvent to send to Core
131 Integration::LongPressGestureEvent GenerateLongPress(
132 Gesture::State state,
133 unsigned int numberOfTouches,
136 Integration::LongPressGestureEvent longPress( state );
138 longPress.numberOfTouches = numberOfTouches;
139 longPress.point = point;
146 ///////////////////////////////////////////////////////////////////////////////
149 // Positive test case for a method
150 int UtcDaliLongPressGestureDetectorConstructor(void)
152 TestApplication application;
154 LongPressGestureDetector detector;
155 DALI_TEST_CHECK(!detector);
160 int UtcDaliLongPressGestureDetectorNew(void)
162 TestApplication application;
164 LongPressGestureDetector detector = LongPressGestureDetector::New();
165 DALI_TEST_CHECK(detector);
166 DALI_TEST_EQUALS(1u, detector.GetMinimumTouchesRequired(), TEST_LOCATION);
167 DALI_TEST_EQUALS(1u, detector.GetMaximumTouchesRequired(), TEST_LOCATION);
169 LongPressGestureDetector detector2 = LongPressGestureDetector::New(5u);
170 DALI_TEST_CHECK(detector2);
171 DALI_TEST_EQUALS(5u, detector2.GetMinimumTouchesRequired(), TEST_LOCATION);
172 DALI_TEST_EQUALS(5u, detector2.GetMaximumTouchesRequired(), TEST_LOCATION);
174 LongPressGestureDetector detector3 = LongPressGestureDetector::New(5u, 7u);
175 DALI_TEST_CHECK(detector2);
176 DALI_TEST_EQUALS(5u, detector3.GetMinimumTouchesRequired(), TEST_LOCATION);
177 DALI_TEST_EQUALS(7u, detector3.GetMaximumTouchesRequired(), TEST_LOCATION);
179 //Scoped test to test destructor
181 LongPressGestureDetector detector4 = LongPressGestureDetector::New();
182 DALI_TEST_CHECK(detector4);
185 // Attach an actor and emit a touch event on the actor to ensure complete line coverage
186 Actor actor = Actor::New();
187 actor.SetSize(100.0f, 100.0f);
188 actor.SetAnchorPoint(AnchorPoint::TOP_LEFT);
189 Stage::GetCurrent().Add(actor);
192 application.SendNotification();
193 application.Render();
195 detector.Attach(actor);
197 TouchEventFunctor touchFunctor;
198 actor.TouchedSignal().Connect(&application, touchFunctor);
200 Integration::TouchEvent touchEvent(1);
201 TouchPoint point(1, TouchPoint::Down, 20.0f, 20.0f);
202 touchEvent.AddPoint(point);
203 application.ProcessEvent(touchEvent);
206 application.SendNotification();
207 application.Render();
209 // For line coverage, Initialise default constructor
210 TouchEvent touchEvent2;
214 int UtcDaliLongPressGestureDetectorDownCast(void)
216 TestApplication application;
217 tet_infoline("Testing Dali::LongPressGestureDetector::DownCast()");
219 LongPressGestureDetector detector = LongPressGestureDetector::New();
221 BaseHandle object(detector);
223 LongPressGestureDetector detector2 = LongPressGestureDetector::DownCast(object);
224 DALI_TEST_CHECK(detector2);
226 LongPressGestureDetector detector3 = DownCast< LongPressGestureDetector >(object);
227 DALI_TEST_CHECK(detector3);
229 BaseHandle unInitializedObject;
230 LongPressGestureDetector detector4 = LongPressGestureDetector::DownCast(unInitializedObject);
231 DALI_TEST_CHECK(!detector4);
233 LongPressGestureDetector detector5 = DownCast< LongPressGestureDetector >(unInitializedObject);
234 DALI_TEST_CHECK(!detector5);
236 GestureDetector detector6 = LongPressGestureDetector::New();
237 LongPressGestureDetector detector7 = LongPressGestureDetector::DownCast(detector6);
238 DALI_TEST_CHECK(detector7);
242 int UtcDaliLongPressGestureSetTouchesRequired01(void)
244 TestApplication application;
246 LongPressGestureDetector detector = LongPressGestureDetector::New();
248 unsigned int touches = 3;
250 DALI_TEST_CHECK(touches != detector.GetMinimumTouchesRequired());
251 DALI_TEST_CHECK(touches != detector.GetMaximumTouchesRequired());
253 detector.SetTouchesRequired(touches);
255 DALI_TEST_EQUALS(touches, detector.GetMinimumTouchesRequired(), TEST_LOCATION);
256 DALI_TEST_EQUALS(touches, detector.GetMaximumTouchesRequired(), TEST_LOCATION);
258 // Attach an actor and change the required touches
260 Actor actor = Actor::New();
261 actor.SetSize(100.0f, 100.0f);
262 actor.SetAnchorPoint(AnchorPoint::TOP_LEFT);
263 Stage::GetCurrent().Add(actor);
266 application.SendNotification();
267 application.Render();
270 GestureReceivedFunctor functor(data);
272 detector.Attach(actor);
273 detector.DetectedSignal().Connect(&application, functor);
275 TestGestureManager& gestureManager = application.GetGestureManager();
276 gestureManager.Initialize();
278 detector.SetTouchesRequired(4);
280 // Gesture detection should have been updated only
281 DALI_TEST_EQUALS(true, gestureManager.WasCalled(TestGestureManager::UpdateType), TEST_LOCATION);
282 DALI_TEST_EQUALS(false, gestureManager.WasCalled(TestGestureManager::RegisterType), TEST_LOCATION);
283 DALI_TEST_EQUALS(false, gestureManager.WasCalled(TestGestureManager::UnregisterType), TEST_LOCATION);
286 gestureManager.Initialize();
288 // Create a second gesture detector that requires even less maximum touches
289 LongPressGestureDetector secondDetector = LongPressGestureDetector::New();
290 secondDetector.Attach(actor);
292 // Gesture detection should have been updated
293 DALI_TEST_EQUALS(true, gestureManager.WasCalled(TestGestureManager::UpdateType), TEST_LOCATION);
294 DALI_TEST_EQUALS(false, gestureManager.WasCalled(TestGestureManager::RegisterType), TEST_LOCATION);
295 DALI_TEST_EQUALS(false, gestureManager.WasCalled(TestGestureManager::UnregisterType), TEST_LOCATION);
299 int UtcDaliLongPressGestureSetTouchesRequired02(void)
301 TestApplication application;
303 LongPressGestureDetector detector = LongPressGestureDetector::New();
305 unsigned int min = 3;
306 unsigned int max = 5;
308 DALI_TEST_CHECK(min != detector.GetMinimumTouchesRequired());
309 DALI_TEST_CHECK(max != detector.GetMaximumTouchesRequired());
311 detector.SetTouchesRequired(min, max);
313 DALI_TEST_EQUALS(min, detector.GetMinimumTouchesRequired(), TEST_LOCATION);
314 DALI_TEST_EQUALS(max, detector.GetMaximumTouchesRequired(), TEST_LOCATION);
316 // Attach an actor and change the maximum touches
318 Actor actor = Actor::New();
319 actor.SetSize(100.0f, 100.0f);
320 actor.SetAnchorPoint(AnchorPoint::TOP_LEFT);
321 Stage::GetCurrent().Add(actor);
324 application.SendNotification();
325 application.Render();
328 GestureReceivedFunctor functor(data);
330 detector.Attach(actor);
331 detector.DetectedSignal().Connect(&application, functor);
333 TestGestureManager& gestureManager = application.GetGestureManager();
334 gestureManager.Initialize();
336 detector.SetTouchesRequired(4, 5);
338 // Gesture detection should have been updated only
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);
344 gestureManager.Initialize();
346 // Create a second gesture detector that requires even less maximum touches
347 LongPressGestureDetector secondDetector = LongPressGestureDetector::New();
348 secondDetector.Attach(actor);
350 // Gesture detection should have been updated
351 DALI_TEST_EQUALS(true, gestureManager.WasCalled(TestGestureManager::UpdateType), TEST_LOCATION);
352 DALI_TEST_EQUALS(false, gestureManager.WasCalled(TestGestureManager::RegisterType), TEST_LOCATION);
353 DALI_TEST_EQUALS(false, gestureManager.WasCalled(TestGestureManager::UnregisterType), TEST_LOCATION);
357 int UtcDaliLongPressGestureGetMinimumTouchesRequired(void)
359 TestApplication application;
361 LongPressGestureDetector detector = LongPressGestureDetector::New();
362 DALI_TEST_EQUALS(1u, detector.GetMinimumTouchesRequired(), TEST_LOCATION);
366 int UtcDaliLongPressGestureGetMaximumTouchesRequired(void)
368 TestApplication application;
370 LongPressGestureDetector detector = LongPressGestureDetector::New();
371 DALI_TEST_EQUALS(1u, detector.GetMaximumTouchesRequired(), TEST_LOCATION);
375 int UtcDaliLongPressGestureSignalReceptionNegative(void)
377 TestApplication application;
379 Actor actor = Actor::New();
380 actor.SetSize(100.0f, 100.0f);
381 actor.SetAnchorPoint(AnchorPoint::TOP_LEFT);
382 Stage::GetCurrent().Add(actor);
385 application.SendNotification();
386 application.Render();
389 GestureReceivedFunctor functor(data);
391 LongPressGestureDetector detector = LongPressGestureDetector::New();
392 detector.Attach(actor);
393 detector.DetectedSignal().Connect(&application, functor);
395 // Do a long press outside actor's area
396 application.ProcessEvent( GenerateLongPress( Gesture::Possible, 1u, Vector2(112.0f, 112.0f ) ) );
397 application.ProcessEvent( GenerateLongPress( Gesture::Started, 1u, Vector2(112.0f, 112.0f ) ) );
398 application.ProcessEvent( GenerateLongPress( Gesture::Finished, 1u, Vector2(112.0f, 112.0f ) ) );
399 DALI_TEST_EQUALS(false, data.functorCalled, TEST_LOCATION);
403 int UtcDaliLongPressGestureSignalReceptionPositive(void)
405 TestApplication application;
407 Actor actor = Actor::New();
408 actor.SetSize(100.0f, 100.0f);
409 actor.SetAnchorPoint(AnchorPoint::TOP_LEFT);
410 Stage::GetCurrent().Add(actor);
413 application.SendNotification();
414 application.Render();
417 GestureReceivedFunctor functor(data);
419 LongPressGestureDetector detector = LongPressGestureDetector::New();
420 detector.Attach(actor);
421 detector.DetectedSignal().Connect(&application, functor);
423 // Do a long press inside actor's area
424 application.ProcessEvent(GenerateLongPress(Gesture::Possible, 1u, Vector2(50.0f, 50.0f)));
425 application.ProcessEvent(GenerateLongPress(Gesture::Started, 1u, Vector2(50.0f, 50.0f)));
426 DALI_TEST_EQUALS(true, data.functorCalled, TEST_LOCATION);
427 DALI_TEST_EQUALS(1u, data.receivedGesture.numberOfTouches, TEST_LOCATION);
428 DALI_TEST_EQUALS( Vector2(50.0f, 50.0f), data.receivedGesture.localPoint, 0.1, TEST_LOCATION);
429 application.ProcessEvent(GenerateLongPress(Gesture::Finished, 1u, Vector2(50.0f, 50.0f)));
433 int UtcDaliLongPressGestureSignalReceptionDetach(void)
435 TestApplication application;
437 Actor actor = Actor::New();
438 actor.SetSize(100.0f, 100.0f);
439 actor.SetAnchorPoint(AnchorPoint::TOP_LEFT);
440 Stage::GetCurrent().Add(actor);
443 application.SendNotification();
444 application.Render();
447 GestureReceivedFunctor functor(data);
449 LongPressGestureDetector detector = LongPressGestureDetector::New();
450 detector.Attach(actor);
451 detector.DetectedSignal().Connect(&application, functor);
453 // Start long press within the actor's area
454 application.ProcessEvent(GenerateLongPress(Gesture::Possible, 1u, Vector2(20.0f, 20.0f)));
455 application.ProcessEvent(GenerateLongPress(Gesture::Started, 1u, Vector2(20.0f, 20.0f)));
456 DALI_TEST_EQUALS(true, data.functorCalled, TEST_LOCATION);
457 DALI_TEST_EQUALS(1u, data.receivedGesture.numberOfTouches, TEST_LOCATION);
458 DALI_TEST_EQUALS( Vector2(20.0f, 20.0f), data.receivedGesture.localPoint, 0.1, TEST_LOCATION);
459 application.ProcessEvent(GenerateLongPress(Gesture::Finished, 1u, Vector2(20.0f, 20.0f)));
461 // repeat the long press within the actor's area - we should still receive the signal
463 application.ProcessEvent(GenerateLongPress(Gesture::Possible, 1u, Vector2(50.0f, 50.0f)));
464 application.ProcessEvent(GenerateLongPress(Gesture::Started, 1u, Vector2(50.0f, 50.0f)));
465 DALI_TEST_EQUALS(true, data.functorCalled, TEST_LOCATION);
466 DALI_TEST_EQUALS(1u, data.receivedGesture.numberOfTouches, TEST_LOCATION);
467 DALI_TEST_EQUALS( Vector2(50.0f, 50.0f), data.receivedGesture.localPoint, 0.1, TEST_LOCATION);
468 application.ProcessEvent(GenerateLongPress(Gesture::Finished, 1u, Vector2(50.0f, 50.0f)));
471 detector.DetachAll();
473 // Ensure we are no longer signalled
475 application.ProcessEvent(GenerateLongPress(Gesture::Possible, 1u, Vector2(20.0f, 20.0f)));
476 application.ProcessEvent(GenerateLongPress(Gesture::Started, 1u, Vector2(20.0f, 20.0f)));
477 DALI_TEST_EQUALS(false, data.functorCalled, TEST_LOCATION);
478 application.ProcessEvent(GenerateLongPress(Gesture::Finished, 1u, Vector2(50.0f, 50.0f)));
479 DALI_TEST_EQUALS(false, data.functorCalled, TEST_LOCATION);
483 int UtcDaliLongPressGestureSignalReceptionActorDestroyedDuringLongPress(void)
485 TestApplication application;
488 GestureReceivedFunctor functor(data);
490 LongPressGestureDetector detector = LongPressGestureDetector::New();
491 detector.DetectedSignal().Connect(&application, functor);
493 // Actor lifetime is scoped
495 Actor actor = Actor::New();
496 actor.SetSize(100.0f, 100.0f);
497 actor.SetAnchorPoint(AnchorPoint::TOP_LEFT);
498 Stage::GetCurrent().Add(actor);
501 application.SendNotification();
502 application.Render();
504 detector.Attach(actor);
506 // Start long press within the actor's area
507 application.ProcessEvent(GenerateLongPress(Gesture::Possible, 1u, Vector2(20.0f, 20.0f)));
508 application.ProcessEvent(GenerateLongPress(Gesture::Started, 1u, Vector2(20.0f, 20.0f)));
509 DALI_TEST_EQUALS(true, data.functorCalled, TEST_LOCATION);
511 // Remove the actor from stage and reset the data
512 Stage::GetCurrent().Remove(actor);
515 application.SendNotification();
516 application.Render();
519 // Actor should now have been destroyed
522 application.ProcessEvent(GenerateLongPress(Gesture::Finished, 1u, Vector2(20.0f, 20.0f)));
523 DALI_TEST_EQUALS(false, data.functorCalled, TEST_LOCATION);
527 int UtcDaliLongPressGestureSignalReceptionRotatedActor(void)
529 TestApplication application;
531 Actor actor = Actor::New();
532 actor.SetSize(100.0f, 100.0f);
533 actor.SetRotation(Dali::Degree(90.0f), Vector3::ZAXIS);
534 Stage::GetCurrent().Add(actor);
537 application.SendNotification();
538 application.Render();
541 GestureReceivedFunctor functor(data);
543 LongPressGestureDetector detector = LongPressGestureDetector::New();
544 detector.Attach(actor);
545 detector.DetectedSignal().Connect(&application, functor);
548 application.ProcessEvent(GenerateLongPress(Gesture::Possible, 1u, Vector2(5.0f, 5.0f)));
549 application.ProcessEvent(GenerateLongPress(Gesture::Started, 1u, Vector2(5.0f, 5.0f)));
550 application.ProcessEvent(GenerateLongPress(Gesture::Finished, 1u, Vector2(5.0f, 5.0f)));
551 DALI_TEST_EQUALS(true, data.functorCalled, TEST_LOCATION);
552 DALI_TEST_EQUALS(1u, data.receivedGesture.numberOfTouches, TEST_LOCATION);
553 DALI_TEST_EQUALS( Vector2(5.0f, 5.0f), data.receivedGesture.screenPoint, 0.1, TEST_LOCATION);
555 // Rotate actor again and render
556 actor.SetRotation(Dali::Degree(180.0f), Vector3::ZAXIS);
557 application.SendNotification();
558 application.Render();
560 // Do another long press, should still receive event
562 application.ProcessEvent(GenerateLongPress(Gesture::Possible, 1u, Vector2(5.0f, 5.0f)));
563 application.ProcessEvent(GenerateLongPress(Gesture::Started, 1u, Vector2(5.0f, 5.0f)));
564 application.ProcessEvent(GenerateLongPress(Gesture::Finished, 1u, Vector2(5.0f, 5.0f)));
565 DALI_TEST_EQUALS(true, data.functorCalled, TEST_LOCATION);
566 DALI_TEST_EQUALS(1u, data.receivedGesture.numberOfTouches, TEST_LOCATION);
567 DALI_TEST_EQUALS( Vector2(5.0f, 5.0f), data.receivedGesture.screenPoint, 0.1, TEST_LOCATION);
569 // Rotate actor again and render
570 actor.SetRotation(Dali::Degree(90.0f), Vector3::YAXIS);
571 application.SendNotification();
572 application.Render();
574 // Do a long press, inside where the actor used to be, Should not receive the event
576 application.ProcessEvent(GenerateLongPress(Gesture::Possible, 1u, Vector2(70.0f, 70.0f)));
577 application.ProcessEvent(GenerateLongPress(Gesture::Started, 1u, Vector2(70.0f, 70.0f)));
578 application.ProcessEvent(GenerateLongPress(Gesture::Finished, 1u, Vector2(70.0f, 70.0f)));
579 DALI_TEST_EQUALS(false, data.functorCalled, TEST_LOCATION);
583 int UtcDaliLongPressGestureSignalReceptionChildHit(void)
585 TestApplication application;
587 Actor parent = Actor::New();
588 parent.SetSize(100.0f, 100.0f);
589 parent.SetAnchorPoint(AnchorPoint::TOP_LEFT);
590 Stage::GetCurrent().Add(parent);
592 // Set child to completely cover parent.
593 // Change rotation of child to be different from parent so that we can check if our local coordinate
594 // conversion of the parent actor is correct.
595 Actor child = Actor::New();
596 child.SetSize(100.0f, 100.0f);
597 child.SetAnchorPoint(AnchorPoint::CENTER);
598 child.SetParentOrigin(ParentOrigin::CENTER);
599 child.SetRotation(Dali::Degree(90.0f), Vector3::ZAXIS);
602 TouchEventFunctor touchFunctor;
603 child.TouchedSignal().Connect(&application, touchFunctor);
606 application.SendNotification();
607 application.Render();
610 GestureReceivedFunctor functor(data);
612 LongPressGestureDetector detector = LongPressGestureDetector::New();
613 detector.Attach(parent);
614 detector.DetectedSignal().Connect(&application, functor);
616 // Do long press - hits child area but parent should still receive it
617 application.ProcessEvent(GenerateLongPress(Gesture::Possible, 1u, Vector2(50.0f, 50.0f)));
618 application.ProcessEvent(GenerateLongPress(Gesture::Started, 1u, Vector2(50.0f, 50.0f)));
619 application.ProcessEvent(GenerateLongPress(Gesture::Finished, 1u, Vector2(50.0f, 50.0f)));
620 DALI_TEST_EQUALS(true, data.functorCalled, TEST_LOCATION);
621 DALI_TEST_EQUALS(true, parent == data.pressedActor, TEST_LOCATION);
622 DALI_TEST_EQUALS(Vector2(50.0f, 50.0f), data.receivedGesture.screenPoint, 0.01f, TEST_LOCATION);
624 // Attach child and generate same touch points
625 // (Also proves that you can detach and then re-attach another actor)
626 detector.Attach(child);
627 detector.Detach(parent);
629 // Do an entire long press, only check finished value
631 application.ProcessEvent(GenerateLongPress(Gesture::Possible, 1u, Vector2(51.0f, 51.0f)));
632 application.ProcessEvent(GenerateLongPress(Gesture::Started, 1u, Vector2(51.0f, 51.0f)));
633 application.ProcessEvent(GenerateLongPress(Gesture::Finished, 1u, Vector2(51.0f, 51.0f)));
634 DALI_TEST_EQUALS(true, data.functorCalled, TEST_LOCATION);
635 DALI_TEST_EQUALS(true, child == data.pressedActor, TEST_LOCATION);
636 DALI_TEST_EQUALS(Vector2(51.0f, 51.0f), data.receivedGesture.screenPoint, 0.01f, TEST_LOCATION);
640 int UtcDaliLongPressGestureSignalReceptionAttachDetachMany(void)
642 TestApplication application;
644 Actor first = Actor::New();
645 first.SetSize(100.0f, 100.0f);
646 first.SetAnchorPoint(AnchorPoint::TOP_LEFT);
647 Stage::GetCurrent().Add(first);
649 Actor second = Actor::New();
650 second.SetSize(100.0f, 100.0f);
652 second.SetAnchorPoint(AnchorPoint::TOP_LEFT);
653 Stage::GetCurrent().Add(second);
656 application.SendNotification();
657 application.Render();
660 GestureReceivedFunctor functor(data);
662 LongPressGestureDetector detector = LongPressGestureDetector::New();
663 detector.Attach(first);
664 detector.Attach(second);
665 detector.DetectedSignal().Connect(&application, functor);
667 // LongPress within second actor's area
668 application.ProcessEvent(GenerateLongPress(Gesture::Possible, 1u, Vector2(120.0f, 10.0f)));
669 application.ProcessEvent(GenerateLongPress(Gesture::Started, 1u, Vector2(120.0f, 10.0f)));
670 application.ProcessEvent(GenerateLongPress(Gesture::Finished, 1u, Vector2(120.0f, 10.0f)));
671 DALI_TEST_EQUALS(true, data.functorCalled, TEST_LOCATION);
672 DALI_TEST_EQUALS(true, second == data.pressedActor, TEST_LOCATION);
674 // LongPress within first actor's area
676 application.ProcessEvent(GenerateLongPress(Gesture::Possible, 1u, Vector2(20.0f, 10.0f)));
677 application.ProcessEvent(GenerateLongPress(Gesture::Started, 1u, Vector2(20.0f, 10.0f)));
678 application.ProcessEvent(GenerateLongPress(Gesture::Finished, 1u, Vector2(20.0f, 10.0f)));
679 DALI_TEST_EQUALS(true, data.functorCalled, TEST_LOCATION);
680 DALI_TEST_EQUALS(true, first == data.pressedActor, TEST_LOCATION);
682 // Detach the second actor
683 detector.Detach(second);
685 // second actor shouldn't receive event
687 application.ProcessEvent(GenerateLongPress(Gesture::Possible, 1u, Vector2(120.0f, 10.0f)));
688 application.ProcessEvent(GenerateLongPress(Gesture::Started, 1u, Vector2(120.0f, 10.0f)));
689 application.ProcessEvent(GenerateLongPress(Gesture::Finished, 1u, Vector2(120.0f, 10.0f)));
690 DALI_TEST_EQUALS(false, data.functorCalled, TEST_LOCATION);
692 // first actor should continue receiving event
694 application.ProcessEvent(GenerateLongPress(Gesture::Possible, 1u, Vector2(20.0f, 10.0f)));
695 application.ProcessEvent(GenerateLongPress(Gesture::Started, 1u, Vector2(20.0f, 10.0f)));
696 application.ProcessEvent(GenerateLongPress(Gesture::Finished, 1u, Vector2(20.0f, 10.0f)));
697 DALI_TEST_EQUALS(true, data.functorCalled, TEST_LOCATION);
701 int UtcDaliLongPressGestureSignalReceptionActorBecomesUntouchable(void)
703 TestApplication application;
705 Actor actor = Actor::New();
706 actor.SetSize(100.0f, 100.0f);
707 actor.SetAnchorPoint(AnchorPoint::TOP_LEFT);
708 Stage::GetCurrent().Add(actor);
711 application.SendNotification();
712 application.Render();
715 GestureReceivedFunctor functor(data);
717 LongPressGestureDetector detector = LongPressGestureDetector::New();
718 detector.Attach(actor);
719 detector.DetectedSignal().Connect(&application, functor);
721 // LongPress in actor's area
722 application.ProcessEvent(GenerateLongPress(Gesture::Possible, 1u, Vector2(50.0f, 10.0f)));
723 application.ProcessEvent(GenerateLongPress(Gesture::Started, 1u, Vector2(50.0f, 10.0f)));
724 application.ProcessEvent(GenerateLongPress(Gesture::Finished, 1u, Vector2(50.0f, 10.0f)));
725 DALI_TEST_EQUALS(true, data.functorCalled, TEST_LOCATION);
727 // Actor becomes invisible - actor should not receive the next long press
728 actor.SetVisible(false);
731 application.SendNotification();
732 application.Render();
734 // LongPress in the same area, shouldn't receive event
736 application.ProcessEvent(GenerateLongPress(Gesture::Possible, 1u, Vector2(50.0f, 10.0f)));
737 application.ProcessEvent(GenerateLongPress(Gesture::Started, 1u, Vector2(50.0f, 10.0f)));
738 application.ProcessEvent(GenerateLongPress(Gesture::Finished, 1u, Vector2(50.0f, 10.0f)));
739 DALI_TEST_EQUALS(false, data.functorCalled, TEST_LOCATION);
743 int UtcDaliLongPressGestureSignalReceptionMultipleGestureDetectors(void)
745 TestApplication application;
746 Dali::TestGestureManager& gestureManager = application.GetGestureManager();
748 Actor first = Actor::New();
749 first.SetSize(100.0f, 100.0f);
750 first.SetAnchorPoint(AnchorPoint::TOP_LEFT);
751 Stage::GetCurrent().Add(first);
753 Actor second = Actor::New();
754 second.SetSize(100.0f, 100.0f);
755 second.SetAnchorPoint(AnchorPoint::TOP_LEFT);
760 application.SendNotification();
761 application.Render();
764 GestureReceivedFunctor functor(data);
766 LongPressGestureDetector firstDetector = LongPressGestureDetector::New();
767 firstDetector.Attach(first);
768 firstDetector.DetectedSignal().Connect(&application, functor);
770 // secondDetector is scoped
772 // Reset gestureManager statistics
773 gestureManager.Initialize();
775 LongPressGestureDetector secondDetector = LongPressGestureDetector::New();
776 secondDetector.SetTouchesRequired(2);
777 secondDetector.Attach(second);
778 secondDetector.DetectedSignal().Connect(&application, functor);
780 DALI_TEST_EQUALS(true, gestureManager.WasCalled(TestGestureManager::UpdateType), TEST_LOCATION);
781 DALI_TEST_EQUALS(false, gestureManager.WasCalled(TestGestureManager::RegisterType), TEST_LOCATION);
782 DALI_TEST_EQUALS(false, gestureManager.WasCalled(TestGestureManager::UnregisterType), TEST_LOCATION);
784 // LongPress within second actor's area
785 application.ProcessEvent(GenerateLongPress(Gesture::Possible, 2u, Vector2(150.0f, 10.0f)));
786 application.ProcessEvent(GenerateLongPress(Gesture::Started, 2u, Vector2(150.0f, 10.0f)));
787 application.ProcessEvent(GenerateLongPress(Gesture::Finished, 2u, Vector2(150.0f, 10.0f)));
788 DALI_TEST_EQUALS(true, data.functorCalled, TEST_LOCATION);
789 DALI_TEST_EQUALS(true, second == data.pressedActor, TEST_LOCATION);
791 // LongPress continues as single touch gesture - we should not receive any gesture
793 application.ProcessEvent(GenerateLongPress(Gesture::Possible, 1u, Vector2(150.0f, 10.0f)));
794 application.ProcessEvent(GenerateLongPress(Gesture::Started, 1u, Vector2(150.0f, 10.0f)));
795 application.ProcessEvent(GenerateLongPress(Gesture::Finished, 1u, Vector2(150.0f, 10.0f)));
796 DALI_TEST_EQUALS(false, data.functorCalled, TEST_LOCATION);
798 // Single touch long press starts - first actor should receive gesture
800 application.ProcessEvent(GenerateLongPress(Gesture::Possible, 1u, Vector2(50.0f, 10.0f)));
801 application.ProcessEvent(GenerateLongPress(Gesture::Started, 1u, Vector2(50.0f, 10.0f)));
802 application.ProcessEvent(GenerateLongPress(Gesture::Finished, 1u, Vector2(50.0f, 10.0f)));
803 DALI_TEST_EQUALS(true, data.functorCalled, TEST_LOCATION);
804 DALI_TEST_EQUALS(true, first == data.pressedActor, TEST_LOCATION);
806 // long press changes to double-touch - we shouldn't receive event
808 application.ProcessEvent(GenerateLongPress(Gesture::Possible, 2u, Vector2(50.0f, 10.0f)));
809 application.ProcessEvent(GenerateLongPress(Gesture::Started, 2u, Vector2(50.0f, 10.0f)));
810 application.ProcessEvent(GenerateLongPress(Gesture::Finished, 2u, Vector2(50.0f, 10.0f)));
811 DALI_TEST_EQUALS(false, data.functorCalled, TEST_LOCATION);
813 // Reset gesture manager statistics
814 gestureManager.Initialize();
817 // secondDetector has now been deleted. Gesture detection should have been updated only
818 DALI_TEST_EQUALS(true, gestureManager.WasCalled(TestGestureManager::UpdateType), TEST_LOCATION);
819 DALI_TEST_EQUALS(false, gestureManager.WasCalled(TestGestureManager::RegisterType), TEST_LOCATION);
820 DALI_TEST_EQUALS(false, gestureManager.WasCalled(TestGestureManager::UnregisterType), TEST_LOCATION);
824 int UtcDaliLongPressGestureSignalReceptionMultipleDetectorsOnActor(void)
826 TestApplication application;
828 Actor actor = Actor::New();
829 actor.SetSize(100.0f, 100.0f);
830 actor.SetAnchorPoint(AnchorPoint::TOP_LEFT);
831 Stage::GetCurrent().Add(actor);
834 application.SendNotification();
835 application.Render();
837 // Attach actor to one detector
838 SignalData firstData;
839 GestureReceivedFunctor firstFunctor(firstData);
840 LongPressGestureDetector firstDetector = LongPressGestureDetector::New();
841 firstDetector.Attach(actor);
842 firstDetector.DetectedSignal().Connect(&application, firstFunctor);
844 // Attach actor to another detector
845 SignalData secondData;
846 GestureReceivedFunctor secondFunctor(secondData);
847 LongPressGestureDetector secondDetector = LongPressGestureDetector::New();
848 secondDetector.Attach(actor);
849 secondDetector.DetectedSignal().Connect(&application, secondFunctor);
851 // LongPress in actor's area - both detector's functors should be called
852 application.ProcessEvent(GenerateLongPress(Gesture::Possible, 1u, Vector2(50.0f, 10.0f)));
853 application.ProcessEvent(GenerateLongPress(Gesture::Started, 1u, Vector2(50.0f, 10.0f)));
854 DALI_TEST_EQUALS(true, firstData.functorCalled, TEST_LOCATION);
855 DALI_TEST_EQUALS(true, secondData.functorCalled, TEST_LOCATION);
859 int UtcDaliLongPressGestureSignalReceptionDifferentPossible(void)
861 TestApplication application;
863 Actor actor = Actor::New();
864 actor.SetSize(100.0f, 100.0f);
865 actor.SetAnchorPoint(AnchorPoint::TOP_LEFT);
866 Stage::GetCurrent().Add(actor);
869 application.SendNotification();
870 application.Render();
872 // Attach actor to detector
874 GestureReceivedFunctor functor( data );
875 LongPressGestureDetector detector = LongPressGestureDetector::New();
876 detector.Attach(actor);
877 detector.DetectedSignal().Connect( &application, functor );
879 // LongPress possible in actor's area.
880 application.ProcessEvent(GenerateLongPress(Gesture::Possible, 1u, Vector2(50.0f, 10.0f)));
881 DALI_TEST_EQUALS(false, data.functorCalled, TEST_LOCATION);
883 // Move actor somewhere else
884 actor.SetPosition( 100.0f, 100.0f );
887 application.SendNotification();
888 application.Render();
890 // Emit Started event, we should not receive the long press.
891 application.ProcessEvent(GenerateLongPress(Gesture::Started, 1u, Vector2(50.0f, 10.0f)));
892 application.ProcessEvent(GenerateLongPress(Gesture::Finished, 1u, Vector2(50.0f, 10.0f)));
893 DALI_TEST_EQUALS(false, data.functorCalled, TEST_LOCATION);
895 // LongPress possible in empty area.
896 application.ProcessEvent(GenerateLongPress(Gesture::Possible, 1u, Vector2(50.0f, 10.0f)));
897 DALI_TEST_EQUALS(false, data.functorCalled, TEST_LOCATION);
899 // Move actor in to the long press position.
900 actor.SetPosition( 0.0f, 0.0f );
903 application.SendNotification();
904 application.Render();
906 // Emit Started event, we should not receive the long press.
907 application.ProcessEvent(GenerateLongPress(Gesture::Started, 1u, Vector2(50.0f, 10.0f)));
908 application.ProcessEvent(GenerateLongPress(Gesture::Finished, 1u, Vector2(50.0f, 10.0f)));
909 DALI_TEST_EQUALS(false, data.functorCalled, TEST_LOCATION);
911 // Normal long press in actor's area for completeness.
912 application.ProcessEvent(GenerateLongPress(Gesture::Possible, 1u, Vector2(50.0f, 10.0f)));
913 application.ProcessEvent(GenerateLongPress(Gesture::Started, 1u, Vector2(50.0f, 10.0f)));
914 application.ProcessEvent(GenerateLongPress(Gesture::Finished, 1u, Vector2(50.0f, 10.0f)));
915 DALI_TEST_EQUALS(true, data.functorCalled, TEST_LOCATION);
919 int UtcDaliLongPressGestureEmitIncorrectStateClear(void)
921 TestApplication application;
923 Actor actor = Actor::New();
924 actor.SetSize(100.0f, 100.0f);
925 actor.SetAnchorPoint(AnchorPoint::TOP_LEFT);
926 Stage::GetCurrent().Add(actor);
929 application.SendNotification();
930 application.Render();
932 // Attach actor to detector
934 GestureReceivedFunctor functor( data );
935 LongPressGestureDetector detector = LongPressGestureDetector::New();
936 detector.Attach(actor);
937 detector.DetectedSignal().Connect( &application, functor );
942 application.ProcessEvent(GenerateLongPress(Gesture::Clear, 1u, Vector2(50.0f, 10.0f)));
943 tet_result(TET_FAIL);
945 catch ( Dali::DaliException& e )
947 DALI_TEST_ASSERT( e, "false", TEST_LOCATION );
952 int UtcDaliLongPressGestureEmitIncorrectStateContinuing(void)
954 TestApplication application;
956 Actor actor = Actor::New();
957 actor.SetSize(100.0f, 100.0f);
958 actor.SetAnchorPoint(AnchorPoint::TOP_LEFT);
959 Stage::GetCurrent().Add(actor);
962 application.SendNotification();
963 application.Render();
965 // Attach actor to detector
967 GestureReceivedFunctor functor( data );
968 LongPressGestureDetector detector = LongPressGestureDetector::New();
969 detector.Attach(actor);
970 detector.DetectedSignal().Connect( &application, functor );
972 // Try a Continuing state
975 application.ProcessEvent(GenerateLongPress(Gesture::Continuing, 1u, Vector2(50.0f, 10.0f)));
976 tet_result(TET_FAIL);
978 catch ( Dali::DaliException& e )
980 DALI_TEST_ASSERT( e, "false", TEST_LOCATION );
985 int UtcDaliLongPressGestureRepeatedState(void)
987 TestApplication application;
989 Actor actor = Actor::New();
990 actor.SetSize(100.0f, 100.0f);
991 actor.SetAnchorPoint(AnchorPoint::TOP_LEFT);
992 Stage::GetCurrent().Add(actor);
995 application.SendNotification();
996 application.Render();
998 // Attach actor to detector
1000 GestureReceivedFunctor functor( data );
1001 LongPressGestureDetector detector = LongPressGestureDetector::New();
1002 detector.Attach(actor);
1003 detector.DetectedSignal().Connect( &application, functor );
1006 application.ProcessEvent(GenerateLongPress(Gesture::Possible, 1u, Vector2(50.0f, 10.0f)));
1007 DALI_TEST_EQUALS(false, data.functorCalled, TEST_LOCATION);
1008 application.ProcessEvent(GenerateLongPress(Gesture::Possible, 1u, Vector2(50.0f, 10.0f)));
1009 DALI_TEST_EQUALS(false, data.functorCalled, TEST_LOCATION);
1011 // ... Send some finished states, still no signal
1012 application.ProcessEvent(GenerateLongPress(Gesture::Finished, 1u, Vector2(50.0f, 10.0f)));
1013 DALI_TEST_EQUALS(false, data.functorCalled, TEST_LOCATION);
1014 application.ProcessEvent(GenerateLongPress(Gesture::Finished, 1u, Vector2(50.0f, 10.0f)));
1015 DALI_TEST_EQUALS(false, data.functorCalled, TEST_LOCATION);
1017 // Send two Started states, should be signalled
1018 application.ProcessEvent(GenerateLongPress(Gesture::Possible, 1u, Vector2(50.0f, 10.0f)));
1019 DALI_TEST_EQUALS(false, data.functorCalled, TEST_LOCATION);
1020 application.ProcessEvent(GenerateLongPress(Gesture::Started, 1u, Vector2(50.0f, 10.0f)));
1021 DALI_TEST_EQUALS(true, data.functorCalled, TEST_LOCATION);
1023 application.ProcessEvent(GenerateLongPress(Gesture::Started, 1u, Vector2(50.0f, 10.0f)));
1024 DALI_TEST_EQUALS(true, data.functorCalled, TEST_LOCATION);
1026 application.ProcessEvent(GenerateLongPress(Gesture::Finished, 1u, Vector2(50.0f, 10.0f)));
1027 DALI_TEST_EQUALS(true, data.functorCalled, TEST_LOCATION);
1030 // Send two cancelled states, should not be signalled
1031 application.ProcessEvent(GenerateLongPress(Gesture::Cancelled, 1u, Vector2(50.0f, 10.0f)));
1032 DALI_TEST_EQUALS(false, data.functorCalled, TEST_LOCATION);
1033 application.ProcessEvent(GenerateLongPress(Gesture::Cancelled, 1u, Vector2(50.0f, 10.0f)));
1034 DALI_TEST_EQUALS(false, data.functorCalled, TEST_LOCATION);
1038 int UtcDaliLongPressGesturePossibleCancelled(void)
1040 TestApplication application;
1042 Actor actor = Actor::New();
1043 actor.SetSize(100.0f, 100.0f);
1044 actor.SetAnchorPoint(AnchorPoint::TOP_LEFT);
1045 Stage::GetCurrent().Add(actor);
1047 // Render and notify
1048 application.SendNotification();
1049 application.Render();
1051 // Attach actor to detector
1053 GestureReceivedFunctor functor( data );
1054 LongPressGestureDetector detector = LongPressGestureDetector::New();
1055 detector.Attach(actor);
1056 detector.DetectedSignal().Connect( &application, functor );
1058 // Send a possible followed by a cancel, we should not be signalled
1059 application.ProcessEvent(GenerateLongPress(Gesture::Possible, 1u, Vector2(50.0f, 10.0f)));
1060 DALI_TEST_EQUALS(false, data.functorCalled, TEST_LOCATION);
1061 application.ProcessEvent(GenerateLongPress(Gesture::Cancelled, 1u, Vector2(50.0f, 10.0f)));
1062 DALI_TEST_EQUALS(false, data.functorCalled, TEST_LOCATION);
1066 int UtcDaliLongPressGestureDetachAfterStarted(void)
1068 TestApplication application;
1070 Actor actor = Actor::New();
1071 actor.SetSize(100.0f, 100.0f);
1072 actor.SetAnchorPoint(AnchorPoint::TOP_LEFT);
1073 Stage::GetCurrent().Add(actor);
1075 // Render and notify
1076 application.SendNotification();
1077 application.Render();
1079 // Attach actor to detector
1081 GestureReceivedFunctor functor( data );
1082 LongPressGestureDetector detector = LongPressGestureDetector::New();
1083 detector.Attach(actor);
1084 detector.DetectedSignal().Connect( &application, functor );
1086 // Emit initial signal
1087 application.ProcessEvent(GenerateLongPress(Gesture::Possible, 1u, Vector2(50.0f, 10.0f)));
1088 application.ProcessEvent(GenerateLongPress(Gesture::Started, 1u, Vector2(50.0f, 10.0f)));
1089 DALI_TEST_EQUALS(true, data.functorCalled, TEST_LOCATION);
1093 detector.Detach(actor);
1095 // Emit Finished, no signal
1096 application.ProcessEvent(GenerateLongPress(Gesture::Finished, 1u, Vector2(50.0f, 10.0f)));
1097 DALI_TEST_EQUALS(false, data.functorCalled, TEST_LOCATION);
1101 int UtcDaliLongPressGestureActorUnstaged(void)
1103 TestApplication application;
1105 Actor actor = Actor::New();
1106 actor.SetSize(100.0f, 100.0f);
1107 actor.SetAnchorPoint(AnchorPoint::TOP_LEFT);
1108 Stage::GetCurrent().Add(actor);
1110 // Render and notify
1111 application.SendNotification();
1112 application.Render();
1114 // State to remove actor in.
1115 Gesture::State stateToUnstage( Gesture::Started );
1117 // Attach actor to detector
1119 UnstageActorFunctor functor( data, stateToUnstage );
1120 LongPressGestureDetector detector = LongPressGestureDetector::New();
1121 detector.Attach(actor);
1122 detector.DetectedSignal().Connect( &application, functor );
1125 application.ProcessEvent(GenerateLongPress(Gesture::Possible, 1u, Vector2(50.0f, 10.0f)));
1126 application.ProcessEvent(GenerateLongPress(Gesture::Started, 1u, Vector2(50.0f, 10.0f)));
1127 DALI_TEST_EQUALS(true, data.functorCalled, TEST_LOCATION);
1129 application.ProcessEvent(GenerateLongPress(Gesture::Finished, 1u, Vector2(50.0f, 10.0f)));
1130 DALI_TEST_EQUALS(false, data.functorCalled, TEST_LOCATION);
1132 // Render and notify
1133 application.SendNotification();
1134 application.Render();
1136 // Re-add actor to stage
1137 Stage::GetCurrent().Add(actor);
1139 // Render and notify
1140 application.SendNotification();
1141 application.Render();
1143 // Change state to Gesture::Continuing to remove
1144 stateToUnstage = Gesture::Finished;
1147 application.ProcessEvent(GenerateLongPress(Gesture::Possible, 1u, Vector2(50.0f, 10.0f)));
1148 application.ProcessEvent(GenerateLongPress(Gesture::Started, 1u, Vector2(50.0f, 10.0f)));
1149 DALI_TEST_EQUALS(true, data.functorCalled, TEST_LOCATION);
1151 application.ProcessEvent(GenerateLongPress(Gesture::Finished, 1u, Vector2(50.0f, 10.0f)));
1152 DALI_TEST_EQUALS(true, data.functorCalled, TEST_LOCATION);
1153 tet_result( TET_PASS ); // If we get here then we have handled actor stage removal gracefully.
1157 int UtcDaliLongPressGestureActorStagedAndDestroyed(void)
1159 TestApplication application;
1161 Actor actor = Actor::New();
1162 actor.SetSize(100.0f, 100.0f);
1163 actor.SetAnchorPoint(AnchorPoint::TOP_LEFT);
1164 Stage::GetCurrent().Add(actor);
1166 // Create and add a second actor so that GestureDetector destruction does not come into play.
1167 Actor dummyActor( Actor::New() );
1168 dummyActor.SetSize( 100.0f, 100.0f );
1169 dummyActor.SetPosition( 100.0f, 100.0f );
1170 dummyActor.SetAnchorPoint(AnchorPoint::TOP_LEFT);
1171 Stage::GetCurrent().Add(dummyActor);
1173 // Render and notify
1174 application.SendNotification();
1175 application.Render();
1177 // State to remove actor in.
1178 Gesture::State stateToUnstage( Gesture::Started );
1180 // Attach actor to detector
1182 UnstageActorFunctor functor( data, stateToUnstage );
1183 LongPressGestureDetector detector = LongPressGestureDetector::New();
1184 detector.Attach(actor);
1185 detector.Attach(dummyActor);
1186 detector.DetectedSignal().Connect( &application, functor );
1188 // Here we are testing a Started actor which is removed in the Started callback, but then added back
1189 // before we get a finished state. As we were removed from the stage, even if we're at the same
1190 // position, we should still not be signalled.
1193 application.ProcessEvent(GenerateLongPress(Gesture::Possible, 1u, Vector2(50.0f, 10.0f)));
1194 application.ProcessEvent(GenerateLongPress(Gesture::Started, 1u, Vector2(50.0f, 10.0f)));
1195 DALI_TEST_EQUALS(true, data.functorCalled, TEST_LOCATION);
1198 // Render and notify
1199 application.SendNotification();
1200 application.Render();
1202 // Re add to the stage, we should not be signalled
1203 Stage::GetCurrent().Add(actor);
1205 // Render and notify
1206 application.SendNotification();
1207 application.Render();
1209 // Continue signal emission
1210 application.ProcessEvent(GenerateLongPress(Gesture::Finished, 1u, Vector2(50.0f, 10.0f)));
1211 DALI_TEST_EQUALS(false, data.functorCalled, TEST_LOCATION);
1214 // Here we delete an actor in started, we should not receive any subsequent signalling.
1217 application.ProcessEvent(GenerateLongPress(Gesture::Possible, 1u, Vector2(50.0f, 10.0f)));
1218 application.ProcessEvent(GenerateLongPress(Gesture::Started, 1u, Vector2(50.0f, 10.0f)));
1219 DALI_TEST_EQUALS(true, data.functorCalled, TEST_LOCATION);
1222 // Render and notify
1223 application.SendNotification();
1224 application.Render();
1226 // Delete actor as well
1229 // Render and notify
1230 application.SendNotification();
1231 application.Render();
1233 // Continue signal emission
1234 application.ProcessEvent(GenerateLongPress(Gesture::Finished, 1u, Vector2(50.0f, 10.0f)));
1235 DALI_TEST_EQUALS(false, data.functorCalled, TEST_LOCATION);
1239 int UtcDaliLongPressGestureSystemOverlay(void)
1241 TestApplication application;
1242 Dali::Integration::Core& core = application.GetCore();
1243 Dali::Integration::SystemOverlay& systemOverlay( core.GetSystemOverlay() );
1244 systemOverlay.GetOverlayRenderTasks().CreateTask();
1246 Actor actor = Actor::New();
1247 actor.SetSize(100.0f, 100.0f);
1248 actor.SetAnchorPoint(AnchorPoint::TOP_LEFT);
1249 systemOverlay.Add(actor);
1251 // Render and notify
1252 application.SendNotification();
1253 application.Render();
1256 GestureReceivedFunctor functor(data);
1258 LongPressGestureDetector detector = LongPressGestureDetector::New();
1259 detector.Attach(actor);
1260 detector.DetectedSignal().Connect(&application, functor);
1262 // Do a long press inside actor's area
1263 Vector2 screenCoords( 50.0f, 50.0f );
1264 application.ProcessEvent( GenerateLongPress( Gesture::Possible, 1u, screenCoords ) );
1265 application.ProcessEvent( GenerateLongPress( Gesture::Started, 1u, screenCoords ) );
1266 DALI_TEST_EQUALS( true, data.functorCalled, TEST_LOCATION );
1270 int UtcDaliLongPressGestureBehindTouchableSystemOverlay(void)
1272 TestApplication application;
1273 Dali::Integration::Core& core = application.GetCore();
1274 Dali::Integration::SystemOverlay& systemOverlay( core.GetSystemOverlay() );
1275 systemOverlay.GetOverlayRenderTasks().CreateTask();
1277 // SystemOverlay actor
1278 Actor systemOverlayActor = Actor::New();
1279 systemOverlayActor.SetSize(100.0f, 100.0f);
1280 systemOverlayActor.SetAnchorPoint(AnchorPoint::TOP_LEFT);
1281 systemOverlay.Add(systemOverlayActor);
1284 Actor stageActor = Actor::New();
1285 stageActor.SetSize(100.0f, 100.0f);
1286 stageActor.SetAnchorPoint(AnchorPoint::TOP_LEFT);
1287 Stage::GetCurrent().Add(stageActor);
1289 // Render and notify
1290 application.SendNotification();
1291 application.Render();
1293 // Set system-overlay actor to touchable
1294 TouchEventData touchData;
1295 TouchEventDataFunctor touchFunctor( touchData );
1296 systemOverlayActor.TouchedSignal().Connect(&application, touchFunctor);
1298 // Set stage actor to receive the gesture
1300 GestureReceivedFunctor functor(data);
1302 LongPressGestureDetector detector = LongPressGestureDetector::New();
1303 detector.Attach(stageActor);
1304 detector.DetectedSignal().Connect(&application, functor);
1306 // Start long press within the two actors' area
1307 Vector2 screenCoords( 50.0f, 50.0f );
1308 application.ProcessEvent( GenerateLongPress( Gesture::Possible, 1u, screenCoords ) );
1309 application.ProcessEvent( GenerateLongPress( Gesture::Started, 1u, screenCoords ) );
1310 DALI_TEST_EQUALS( true, data.functorCalled, TEST_LOCATION );
1311 DALI_TEST_EQUALS( false, touchData.functorCalled, TEST_LOCATION );
1316 // Do touch in the same area
1317 application.ProcessEvent( touchFunctor.GenerateSingleTouch( TouchPoint::Down, screenCoords ) );
1318 DALI_TEST_EQUALS( false, data.functorCalled, TEST_LOCATION );
1319 DALI_TEST_EQUALS( true, touchData.functorCalled, TEST_LOCATION );
1324 int UtcDaliLongPressGestureTouchBehindGesturedSystemOverlay(void)
1326 TestApplication application;
1327 Dali::Integration::Core& core = application.GetCore();
1328 Dali::Integration::SystemOverlay& systemOverlay( core.GetSystemOverlay() );
1329 systemOverlay.GetOverlayRenderTasks().CreateTask();
1331 // SystemOverlay actor
1332 Actor systemOverlayActor = Actor::New();
1333 systemOverlayActor.SetSize(100.0f, 100.0f);
1334 systemOverlayActor.SetAnchorPoint(AnchorPoint::TOP_LEFT);
1335 systemOverlay.Add(systemOverlayActor);
1338 Actor stageActor = Actor::New();
1339 stageActor.SetSize(100.0f, 100.0f);
1340 stageActor.SetAnchorPoint(AnchorPoint::TOP_LEFT);
1341 Stage::GetCurrent().Add(stageActor);
1343 // Render and notify
1344 application.SendNotification();
1345 application.Render();
1347 // Set stage actor to touchable
1348 TouchEventData touchData;
1349 TouchEventDataFunctor touchFunctor( touchData );
1350 stageActor.TouchedSignal().Connect(&application, touchFunctor);
1352 // Set system-overlay actor to have the gesture
1354 GestureReceivedFunctor functor(data);
1356 LongPressGestureDetector detector = LongPressGestureDetector::New();
1357 detector.Attach(systemOverlayActor);
1358 detector.DetectedSignal().Connect(&application, functor);
1360 // Start long press within the two actors' area
1361 Vector2 screenCoords( 50.0f, 50.0f );
1362 application.ProcessEvent( GenerateLongPress( Gesture::Possible, 1u, screenCoords ) );
1363 application.ProcessEvent( GenerateLongPress( Gesture::Started, 1u, screenCoords ) );
1364 DALI_TEST_EQUALS( true, data.functorCalled, TEST_LOCATION );
1365 DALI_TEST_EQUALS( false, touchData.functorCalled, TEST_LOCATION );
1370 // Do touch in the same area
1371 application.ProcessEvent( touchFunctor.GenerateSingleTouch( TouchPoint::Down, screenCoords ) );
1372 DALI_TEST_EQUALS( false, data.functorCalled, TEST_LOCATION );
1373 DALI_TEST_EQUALS( true, touchData.functorCalled, TEST_LOCATION );
1378 int UtcDaliLongPressGestureLayerConsumesTouch(void)
1380 TestApplication application;
1382 Actor actor = Actor::New();
1383 actor.SetSize(100.0f, 100.0f);
1384 actor.SetAnchorPoint(AnchorPoint::TOP_LEFT);
1385 Stage::GetCurrent().Add(actor);
1389 GestureReceivedFunctor functor(data);
1390 LongPressGestureDetector detector = LongPressGestureDetector::New();
1391 detector.Attach(actor);
1392 detector.DetectedSignal().Connect( &application, functor );
1394 // Add a layer to overlap the actor
1395 Layer layer = Layer::New();
1396 layer.SetSize(100.0f, 100.0f);
1397 layer.SetAnchorPoint(AnchorPoint::TOP_LEFT);
1398 Stage::GetCurrent().Add( layer );
1401 // Render and notify
1402 application.SendNotification();
1403 application.Render();
1405 Vector2 screenCoords( 50.0f, 50.0f );
1407 // Emit signals, should receive
1408 application.ProcessEvent( GenerateLongPress( Gesture::Possible, 1u, screenCoords ) );
1409 application.ProcessEvent( GenerateLongPress( Gesture::Started, 1u, screenCoords ) );
1410 application.ProcessEvent( GenerateLongPress( Gesture::Finished, 1u, screenCoords ) );
1411 DALI_TEST_EQUALS(true, data.functorCalled, TEST_LOCATION);
1414 // Set layer to consume all touch
1415 layer.SetTouchConsumed( true );
1417 // Render and notify
1418 application.SendNotification();
1419 application.Render();
1421 // Emit the same signals again, should not receive
1422 application.ProcessEvent( GenerateLongPress( Gesture::Possible, 1u, screenCoords ) );
1423 application.ProcessEvent( GenerateLongPress( Gesture::Started, 1u, screenCoords ) );
1424 application.ProcessEvent( GenerateLongPress( Gesture::Finished, 1u, screenCoords ) );
1425 DALI_TEST_EQUALS(false, data.functorCalled, TEST_LOCATION);