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 UtcDaliLongPressGestureDetectorConstructorP(void)
152 TestApplication application;
154 LongPressGestureDetector detector;
155 DALI_TEST_CHECK(!detector);
159 int UtcDaliLongPressGestureDetectorCopyConstructorP(void)
161 TestApplication application;
163 LongPressGestureDetector detector = LongPressGestureDetector::New();;
165 LongPressGestureDetector copy( detector );
166 DALI_TEST_CHECK( detector );
170 int UtcDaliLongPressGestureDetectorAssignmentOperatorP(void)
172 TestApplication application;
174 LongPressGestureDetector detector;
175 detector = LongPressGestureDetector::New();;
177 LongPressGestureDetector copy;
179 DALI_TEST_CHECK( detector );
181 DALI_TEST_CHECK( detector == copy );
185 int UtcDaliLongPressGestureDetectorNew(void)
187 TestApplication application;
189 LongPressGestureDetector detector = LongPressGestureDetector::New();
190 DALI_TEST_CHECK(detector);
191 DALI_TEST_EQUALS(1u, detector.GetMinimumTouchesRequired(), TEST_LOCATION);
192 DALI_TEST_EQUALS(1u, detector.GetMaximumTouchesRequired(), TEST_LOCATION);
194 LongPressGestureDetector detector2 = LongPressGestureDetector::New(5u);
195 DALI_TEST_CHECK(detector2);
196 DALI_TEST_EQUALS(5u, detector2.GetMinimumTouchesRequired(), TEST_LOCATION);
197 DALI_TEST_EQUALS(5u, detector2.GetMaximumTouchesRequired(), TEST_LOCATION);
199 LongPressGestureDetector detector3 = LongPressGestureDetector::New(5u, 7u);
200 DALI_TEST_CHECK(detector2);
201 DALI_TEST_EQUALS(5u, detector3.GetMinimumTouchesRequired(), TEST_LOCATION);
202 DALI_TEST_EQUALS(7u, detector3.GetMaximumTouchesRequired(), TEST_LOCATION);
204 //Scoped test to test destructor
206 LongPressGestureDetector detector4 = LongPressGestureDetector::New();
207 DALI_TEST_CHECK(detector4);
210 // Attach an actor and emit a touch event on the actor to ensure complete line coverage
211 Actor actor = Actor::New();
212 actor.SetSize(100.0f, 100.0f);
213 actor.SetAnchorPoint(AnchorPoint::TOP_LEFT);
214 Stage::GetCurrent().Add(actor);
217 application.SendNotification();
218 application.Render();
220 detector.Attach(actor);
222 TouchEventFunctor touchFunctor;
223 actor.TouchedSignal().Connect(&application, touchFunctor);
225 Integration::TouchEvent touchEvent(1);
226 Integration::Point point;
227 point.SetDeviceId( 1 );
228 point.SetState( PointState::DOWN );
229 point.SetScreenPosition( Vector2( 20.0f, 20.0f ) );
230 touchEvent.AddPoint(point);
231 application.ProcessEvent(touchEvent);
234 application.SendNotification();
235 application.Render();
237 // For line coverage, Initialise default constructor
238 TouchEvent touchEvent2;
242 int UtcDaliLongPressGestureDetectorDownCast(void)
244 TestApplication application;
245 tet_infoline("Testing Dali::LongPressGestureDetector::DownCast()");
247 LongPressGestureDetector detector = LongPressGestureDetector::New();
249 BaseHandle object(detector);
251 LongPressGestureDetector detector2 = LongPressGestureDetector::DownCast(object);
252 DALI_TEST_CHECK(detector2);
254 LongPressGestureDetector detector3 = DownCast< LongPressGestureDetector >(object);
255 DALI_TEST_CHECK(detector3);
257 BaseHandle unInitializedObject;
258 LongPressGestureDetector detector4 = LongPressGestureDetector::DownCast(unInitializedObject);
259 DALI_TEST_CHECK(!detector4);
261 LongPressGestureDetector detector5 = DownCast< LongPressGestureDetector >(unInitializedObject);
262 DALI_TEST_CHECK(!detector5);
264 GestureDetector detector6 = LongPressGestureDetector::New();
265 LongPressGestureDetector detector7 = LongPressGestureDetector::DownCast(detector6);
266 DALI_TEST_CHECK(detector7);
270 int UtcDaliLongPressGestureSetTouchesRequired01(void)
272 TestApplication application;
274 LongPressGestureDetector detector = LongPressGestureDetector::New();
276 unsigned int touches = 3;
278 DALI_TEST_CHECK(touches != detector.GetMinimumTouchesRequired());
279 DALI_TEST_CHECK(touches != detector.GetMaximumTouchesRequired());
281 detector.SetTouchesRequired(touches);
283 DALI_TEST_EQUALS(touches, detector.GetMinimumTouchesRequired(), TEST_LOCATION);
284 DALI_TEST_EQUALS(touches, detector.GetMaximumTouchesRequired(), TEST_LOCATION);
286 // Attach an actor and change the required touches
288 Actor actor = Actor::New();
289 actor.SetSize(100.0f, 100.0f);
290 actor.SetAnchorPoint(AnchorPoint::TOP_LEFT);
291 Stage::GetCurrent().Add(actor);
294 application.SendNotification();
295 application.Render();
298 GestureReceivedFunctor functor(data);
300 detector.Attach(actor);
301 detector.DetectedSignal().Connect(&application, functor);
303 TestGestureManager& gestureManager = application.GetGestureManager();
304 gestureManager.Initialize();
306 detector.SetTouchesRequired(4);
308 // Gesture detection should have been updated only
309 DALI_TEST_EQUALS(true, gestureManager.WasCalled(TestGestureManager::UpdateType), TEST_LOCATION);
310 DALI_TEST_EQUALS(false, gestureManager.WasCalled(TestGestureManager::RegisterType), TEST_LOCATION);
311 DALI_TEST_EQUALS(false, gestureManager.WasCalled(TestGestureManager::UnregisterType), TEST_LOCATION);
314 gestureManager.Initialize();
316 // Create a second gesture detector that requires even less maximum touches
317 LongPressGestureDetector secondDetector = LongPressGestureDetector::New();
318 secondDetector.Attach(actor);
320 // Gesture detection should have been updated
321 DALI_TEST_EQUALS(true, gestureManager.WasCalled(TestGestureManager::UpdateType), TEST_LOCATION);
322 DALI_TEST_EQUALS(false, gestureManager.WasCalled(TestGestureManager::RegisterType), TEST_LOCATION);
323 DALI_TEST_EQUALS(false, gestureManager.WasCalled(TestGestureManager::UnregisterType), TEST_LOCATION);
327 int UtcDaliLongPressGestureSetTouchesRequired02(void)
329 TestApplication application;
331 LongPressGestureDetector detector = LongPressGestureDetector::New();
333 unsigned int min = 3;
334 unsigned int max = 5;
336 DALI_TEST_CHECK(min != detector.GetMinimumTouchesRequired());
337 DALI_TEST_CHECK(max != detector.GetMaximumTouchesRequired());
339 detector.SetTouchesRequired(min, max);
341 DALI_TEST_EQUALS(min, detector.GetMinimumTouchesRequired(), TEST_LOCATION);
342 DALI_TEST_EQUALS(max, detector.GetMaximumTouchesRequired(), TEST_LOCATION);
344 // Attach an actor and change the maximum touches
346 Actor actor = Actor::New();
347 actor.SetSize(100.0f, 100.0f);
348 actor.SetAnchorPoint(AnchorPoint::TOP_LEFT);
349 Stage::GetCurrent().Add(actor);
352 application.SendNotification();
353 application.Render();
356 GestureReceivedFunctor functor(data);
358 detector.Attach(actor);
359 detector.DetectedSignal().Connect(&application, functor);
361 TestGestureManager& gestureManager = application.GetGestureManager();
362 gestureManager.Initialize();
364 detector.SetTouchesRequired(4, 5);
366 // Gesture detection should have been updated only
367 DALI_TEST_EQUALS(true, gestureManager.WasCalled(TestGestureManager::UpdateType), TEST_LOCATION);
368 DALI_TEST_EQUALS(false, gestureManager.WasCalled(TestGestureManager::RegisterType), TEST_LOCATION);
369 DALI_TEST_EQUALS(false, gestureManager.WasCalled(TestGestureManager::UnregisterType), TEST_LOCATION);
372 gestureManager.Initialize();
374 // Create a second gesture detector that requires even less maximum touches
375 LongPressGestureDetector secondDetector = LongPressGestureDetector::New();
376 secondDetector.Attach(actor);
378 // Gesture detection should have been updated
379 DALI_TEST_EQUALS(true, gestureManager.WasCalled(TestGestureManager::UpdateType), TEST_LOCATION);
380 DALI_TEST_EQUALS(false, gestureManager.WasCalled(TestGestureManager::RegisterType), TEST_LOCATION);
381 DALI_TEST_EQUALS(false, gestureManager.WasCalled(TestGestureManager::UnregisterType), TEST_LOCATION);
385 int UtcDaliLongPressGestureGetMinimumTouchesRequired(void)
387 TestApplication application;
389 LongPressGestureDetector detector = LongPressGestureDetector::New();
390 DALI_TEST_EQUALS(1u, detector.GetMinimumTouchesRequired(), TEST_LOCATION);
394 int UtcDaliLongPressGestureGetMaximumTouchesRequired(void)
396 TestApplication application;
398 LongPressGestureDetector detector = LongPressGestureDetector::New();
399 DALI_TEST_EQUALS(1u, detector.GetMaximumTouchesRequired(), TEST_LOCATION);
403 int UtcDaliLongPressGestureSignalReceptionNegative(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 outside actor's area
424 application.ProcessEvent( GenerateLongPress( Gesture::Possible, 1u, Vector2(112.0f, 112.0f ) ) );
425 application.ProcessEvent( GenerateLongPress( Gesture::Started, 1u, Vector2(112.0f, 112.0f ) ) );
426 application.ProcessEvent( GenerateLongPress( Gesture::Finished, 1u, Vector2(112.0f, 112.0f ) ) );
427 DALI_TEST_EQUALS(false, data.functorCalled, TEST_LOCATION);
431 int UtcDaliLongPressGestureSignalReceptionPositive(void)
433 TestApplication application;
435 Actor actor = Actor::New();
436 actor.SetSize(100.0f, 100.0f);
437 actor.SetAnchorPoint(AnchorPoint::TOP_LEFT);
438 Stage::GetCurrent().Add(actor);
441 application.SendNotification();
442 application.Render();
445 GestureReceivedFunctor functor(data);
447 LongPressGestureDetector detector = LongPressGestureDetector::New();
448 detector.Attach(actor);
449 detector.DetectedSignal().Connect(&application, functor);
451 // Do a long press inside actor's area
452 application.ProcessEvent(GenerateLongPress(Gesture::Possible, 1u, Vector2(50.0f, 50.0f)));
453 application.ProcessEvent(GenerateLongPress(Gesture::Started, 1u, Vector2(50.0f, 50.0f)));
454 DALI_TEST_EQUALS(true, data.functorCalled, TEST_LOCATION);
455 DALI_TEST_EQUALS(1u, data.receivedGesture.numberOfTouches, TEST_LOCATION);
456 DALI_TEST_EQUALS( Vector2(50.0f, 50.0f), data.receivedGesture.localPoint, 0.1, TEST_LOCATION);
457 application.ProcessEvent(GenerateLongPress(Gesture::Finished, 1u, Vector2(50.0f, 50.0f)));
461 int UtcDaliLongPressGestureSignalReceptionDetach(void)
463 TestApplication application;
465 Actor actor = Actor::New();
466 actor.SetSize(100.0f, 100.0f);
467 actor.SetAnchorPoint(AnchorPoint::TOP_LEFT);
468 Stage::GetCurrent().Add(actor);
471 application.SendNotification();
472 application.Render();
475 GestureReceivedFunctor functor(data);
477 LongPressGestureDetector detector = LongPressGestureDetector::New();
478 detector.Attach(actor);
479 detector.DetectedSignal().Connect(&application, functor);
481 // Start long press within the actor's area
482 application.ProcessEvent(GenerateLongPress(Gesture::Possible, 1u, Vector2(20.0f, 20.0f)));
483 application.ProcessEvent(GenerateLongPress(Gesture::Started, 1u, Vector2(20.0f, 20.0f)));
484 DALI_TEST_EQUALS(true, data.functorCalled, TEST_LOCATION);
485 DALI_TEST_EQUALS(1u, data.receivedGesture.numberOfTouches, TEST_LOCATION);
486 DALI_TEST_EQUALS( Vector2(20.0f, 20.0f), data.receivedGesture.localPoint, 0.1, TEST_LOCATION);
487 application.ProcessEvent(GenerateLongPress(Gesture::Finished, 1u, Vector2(20.0f, 20.0f)));
489 // repeat the long press within the actor's area - we should still receive the signal
491 application.ProcessEvent(GenerateLongPress(Gesture::Possible, 1u, Vector2(50.0f, 50.0f)));
492 application.ProcessEvent(GenerateLongPress(Gesture::Started, 1u, Vector2(50.0f, 50.0f)));
493 DALI_TEST_EQUALS(true, data.functorCalled, TEST_LOCATION);
494 DALI_TEST_EQUALS(1u, data.receivedGesture.numberOfTouches, TEST_LOCATION);
495 DALI_TEST_EQUALS( Vector2(50.0f, 50.0f), data.receivedGesture.localPoint, 0.1, TEST_LOCATION);
496 application.ProcessEvent(GenerateLongPress(Gesture::Finished, 1u, Vector2(50.0f, 50.0f)));
499 detector.DetachAll();
501 // Ensure we are no longer signalled
503 application.ProcessEvent(GenerateLongPress(Gesture::Possible, 1u, Vector2(20.0f, 20.0f)));
504 application.ProcessEvent(GenerateLongPress(Gesture::Started, 1u, Vector2(20.0f, 20.0f)));
505 DALI_TEST_EQUALS(false, data.functorCalled, TEST_LOCATION);
506 application.ProcessEvent(GenerateLongPress(Gesture::Finished, 1u, Vector2(50.0f, 50.0f)));
507 DALI_TEST_EQUALS(false, data.functorCalled, TEST_LOCATION);
511 int UtcDaliLongPressGestureSignalReceptionActorDestroyedDuringLongPress(void)
513 TestApplication application;
516 GestureReceivedFunctor functor(data);
518 LongPressGestureDetector detector = LongPressGestureDetector::New();
519 detector.DetectedSignal().Connect(&application, functor);
521 // Actor lifetime is scoped
523 Actor actor = Actor::New();
524 actor.SetSize(100.0f, 100.0f);
525 actor.SetAnchorPoint(AnchorPoint::TOP_LEFT);
526 Stage::GetCurrent().Add(actor);
529 application.SendNotification();
530 application.Render();
532 detector.Attach(actor);
534 // Start long press within the actor's area
535 application.ProcessEvent(GenerateLongPress(Gesture::Possible, 1u, Vector2(20.0f, 20.0f)));
536 application.ProcessEvent(GenerateLongPress(Gesture::Started, 1u, Vector2(20.0f, 20.0f)));
537 DALI_TEST_EQUALS(true, data.functorCalled, TEST_LOCATION);
539 // Remove the actor from stage and reset the data
540 Stage::GetCurrent().Remove(actor);
543 application.SendNotification();
544 application.Render();
547 // Actor should now have been destroyed
550 application.ProcessEvent(GenerateLongPress(Gesture::Finished, 1u, Vector2(20.0f, 20.0f)));
551 DALI_TEST_EQUALS(false, data.functorCalled, TEST_LOCATION);
555 int UtcDaliLongPressGestureSignalReceptionRotatedActor(void)
557 TestApplication application;
559 Actor actor = Actor::New();
560 actor.SetSize(100.0f, 100.0f);
561 actor.SetOrientation(Dali::Degree(90.0f), Vector3::ZAXIS);
562 Stage::GetCurrent().Add(actor);
565 application.SendNotification();
566 application.Render();
569 GestureReceivedFunctor functor(data);
571 LongPressGestureDetector detector = LongPressGestureDetector::New();
572 detector.Attach(actor);
573 detector.DetectedSignal().Connect(&application, functor);
576 application.ProcessEvent(GenerateLongPress(Gesture::Possible, 1u, Vector2(5.0f, 5.0f)));
577 application.ProcessEvent(GenerateLongPress(Gesture::Started, 1u, Vector2(5.0f, 5.0f)));
578 application.ProcessEvent(GenerateLongPress(Gesture::Finished, 1u, Vector2(5.0f, 5.0f)));
579 DALI_TEST_EQUALS(true, data.functorCalled, TEST_LOCATION);
580 DALI_TEST_EQUALS(1u, data.receivedGesture.numberOfTouches, TEST_LOCATION);
581 DALI_TEST_EQUALS( Vector2(5.0f, 5.0f), data.receivedGesture.screenPoint, 0.1, TEST_LOCATION);
583 // Rotate actor again and render
584 actor.SetOrientation(Dali::Degree(180.0f), Vector3::ZAXIS);
585 application.SendNotification();
586 application.Render();
588 // Do another long press, should still receive event
590 application.ProcessEvent(GenerateLongPress(Gesture::Possible, 1u, Vector2(5.0f, 5.0f)));
591 application.ProcessEvent(GenerateLongPress(Gesture::Started, 1u, Vector2(5.0f, 5.0f)));
592 application.ProcessEvent(GenerateLongPress(Gesture::Finished, 1u, Vector2(5.0f, 5.0f)));
593 DALI_TEST_EQUALS(true, data.functorCalled, TEST_LOCATION);
594 DALI_TEST_EQUALS(1u, data.receivedGesture.numberOfTouches, TEST_LOCATION);
595 DALI_TEST_EQUALS( Vector2(5.0f, 5.0f), data.receivedGesture.screenPoint, 0.1, TEST_LOCATION);
597 // Rotate actor again and render
598 actor.SetOrientation(Dali::Degree(90.0f), Vector3::YAXIS);
599 application.SendNotification();
600 application.Render();
602 // Do a long press, inside where the actor used to be, Should not receive the event
604 application.ProcessEvent(GenerateLongPress(Gesture::Possible, 1u, Vector2(70.0f, 70.0f)));
605 application.ProcessEvent(GenerateLongPress(Gesture::Started, 1u, Vector2(70.0f, 70.0f)));
606 application.ProcessEvent(GenerateLongPress(Gesture::Finished, 1u, Vector2(70.0f, 70.0f)));
607 DALI_TEST_EQUALS(false, data.functorCalled, TEST_LOCATION);
611 int UtcDaliLongPressGestureSignalReceptionChildHit(void)
613 TestApplication application;
615 Actor parent = Actor::New();
616 parent.SetSize(100.0f, 100.0f);
617 parent.SetAnchorPoint(AnchorPoint::TOP_LEFT);
618 Stage::GetCurrent().Add(parent);
620 // Set child to completely cover parent.
621 // Change rotation of child to be different from parent so that we can check if our local coordinate
622 // conversion of the parent actor is correct.
623 Actor child = Actor::New();
624 child.SetSize(100.0f, 100.0f);
625 child.SetAnchorPoint(AnchorPoint::CENTER);
626 child.SetParentOrigin(ParentOrigin::CENTER);
627 child.SetOrientation(Dali::Degree(90.0f), Vector3::ZAXIS);
630 TouchEventFunctor touchFunctor;
631 child.TouchedSignal().Connect(&application, touchFunctor);
634 application.SendNotification();
635 application.Render();
638 GestureReceivedFunctor functor(data);
640 LongPressGestureDetector detector = LongPressGestureDetector::New();
641 detector.Attach(parent);
642 detector.DetectedSignal().Connect(&application, functor);
644 // Do long press - hits child area but parent should still receive it
645 application.ProcessEvent(GenerateLongPress(Gesture::Possible, 1u, Vector2(50.0f, 50.0f)));
646 application.ProcessEvent(GenerateLongPress(Gesture::Started, 1u, Vector2(50.0f, 50.0f)));
647 application.ProcessEvent(GenerateLongPress(Gesture::Finished, 1u, Vector2(50.0f, 50.0f)));
648 DALI_TEST_EQUALS(true, data.functorCalled, TEST_LOCATION);
649 DALI_TEST_EQUALS(true, parent == data.pressedActor, TEST_LOCATION);
650 DALI_TEST_EQUALS(Vector2(50.0f, 50.0f), data.receivedGesture.screenPoint, 0.01f, TEST_LOCATION);
652 // Attach child and generate same touch points
653 // (Also proves that you can detach and then re-attach another actor)
654 detector.Attach(child);
655 detector.Detach(parent);
657 // Do an entire long press, only check finished value
659 application.ProcessEvent(GenerateLongPress(Gesture::Possible, 1u, Vector2(51.0f, 51.0f)));
660 application.ProcessEvent(GenerateLongPress(Gesture::Started, 1u, Vector2(51.0f, 51.0f)));
661 application.ProcessEvent(GenerateLongPress(Gesture::Finished, 1u, Vector2(51.0f, 51.0f)));
662 DALI_TEST_EQUALS(true, data.functorCalled, TEST_LOCATION);
663 DALI_TEST_EQUALS(true, child == data.pressedActor, TEST_LOCATION);
664 DALI_TEST_EQUALS(Vector2(51.0f, 51.0f), data.receivedGesture.screenPoint, 0.01f, TEST_LOCATION);
668 int UtcDaliLongPressGestureSignalReceptionAttachDetachMany(void)
670 TestApplication application;
672 Actor first = Actor::New();
673 first.SetSize(100.0f, 100.0f);
674 first.SetAnchorPoint(AnchorPoint::TOP_LEFT);
675 Stage::GetCurrent().Add(first);
677 Actor second = Actor::New();
678 second.SetSize(100.0f, 100.0f);
680 second.SetAnchorPoint(AnchorPoint::TOP_LEFT);
681 Stage::GetCurrent().Add(second);
684 application.SendNotification();
685 application.Render();
688 GestureReceivedFunctor functor(data);
690 LongPressGestureDetector detector = LongPressGestureDetector::New();
691 detector.Attach(first);
692 detector.Attach(second);
693 detector.DetectedSignal().Connect(&application, functor);
695 // LongPress within second actor's area
696 application.ProcessEvent(GenerateLongPress(Gesture::Possible, 1u, Vector2(120.0f, 10.0f)));
697 application.ProcessEvent(GenerateLongPress(Gesture::Started, 1u, Vector2(120.0f, 10.0f)));
698 application.ProcessEvent(GenerateLongPress(Gesture::Finished, 1u, Vector2(120.0f, 10.0f)));
699 DALI_TEST_EQUALS(true, data.functorCalled, TEST_LOCATION);
700 DALI_TEST_EQUALS(true, second == data.pressedActor, TEST_LOCATION);
702 // LongPress within first actor's area
704 application.ProcessEvent(GenerateLongPress(Gesture::Possible, 1u, Vector2(20.0f, 10.0f)));
705 application.ProcessEvent(GenerateLongPress(Gesture::Started, 1u, Vector2(20.0f, 10.0f)));
706 application.ProcessEvent(GenerateLongPress(Gesture::Finished, 1u, Vector2(20.0f, 10.0f)));
707 DALI_TEST_EQUALS(true, data.functorCalled, TEST_LOCATION);
708 DALI_TEST_EQUALS(true, first == data.pressedActor, TEST_LOCATION);
710 // Detach the second actor
711 detector.Detach(second);
713 // second actor shouldn't receive event
715 application.ProcessEvent(GenerateLongPress(Gesture::Possible, 1u, Vector2(120.0f, 10.0f)));
716 application.ProcessEvent(GenerateLongPress(Gesture::Started, 1u, Vector2(120.0f, 10.0f)));
717 application.ProcessEvent(GenerateLongPress(Gesture::Finished, 1u, Vector2(120.0f, 10.0f)));
718 DALI_TEST_EQUALS(false, data.functorCalled, TEST_LOCATION);
720 // first actor should continue receiving event
722 application.ProcessEvent(GenerateLongPress(Gesture::Possible, 1u, Vector2(20.0f, 10.0f)));
723 application.ProcessEvent(GenerateLongPress(Gesture::Started, 1u, Vector2(20.0f, 10.0f)));
724 application.ProcessEvent(GenerateLongPress(Gesture::Finished, 1u, Vector2(20.0f, 10.0f)));
725 DALI_TEST_EQUALS(true, data.functorCalled, TEST_LOCATION);
729 int UtcDaliLongPressGestureSignalReceptionActorBecomesUntouchable(void)
731 TestApplication application;
733 Actor actor = Actor::New();
734 actor.SetSize(100.0f, 100.0f);
735 actor.SetAnchorPoint(AnchorPoint::TOP_LEFT);
736 Stage::GetCurrent().Add(actor);
739 application.SendNotification();
740 application.Render();
743 GestureReceivedFunctor functor(data);
745 LongPressGestureDetector detector = LongPressGestureDetector::New();
746 detector.Attach(actor);
747 detector.DetectedSignal().Connect(&application, functor);
749 // LongPress in actor's area
750 application.ProcessEvent(GenerateLongPress(Gesture::Possible, 1u, Vector2(50.0f, 10.0f)));
751 application.ProcessEvent(GenerateLongPress(Gesture::Started, 1u, Vector2(50.0f, 10.0f)));
752 application.ProcessEvent(GenerateLongPress(Gesture::Finished, 1u, Vector2(50.0f, 10.0f)));
753 DALI_TEST_EQUALS(true, data.functorCalled, TEST_LOCATION);
755 // Actor becomes invisible - actor should not receive the next long press
756 actor.SetVisible(false);
759 application.SendNotification();
760 application.Render();
762 // LongPress in the same area, shouldn't receive event
764 application.ProcessEvent(GenerateLongPress(Gesture::Possible, 1u, Vector2(50.0f, 10.0f)));
765 application.ProcessEvent(GenerateLongPress(Gesture::Started, 1u, Vector2(50.0f, 10.0f)));
766 application.ProcessEvent(GenerateLongPress(Gesture::Finished, 1u, Vector2(50.0f, 10.0f)));
767 DALI_TEST_EQUALS(false, data.functorCalled, TEST_LOCATION);
771 int UtcDaliLongPressGestureSignalReceptionMultipleGestureDetectors(void)
773 TestApplication application;
774 Dali::TestGestureManager& gestureManager = application.GetGestureManager();
776 Actor first = Actor::New();
777 first.SetSize(100.0f, 100.0f);
778 first.SetAnchorPoint(AnchorPoint::TOP_LEFT);
779 Stage::GetCurrent().Add(first);
781 Actor second = Actor::New();
782 second.SetSize(100.0f, 100.0f);
783 second.SetAnchorPoint(AnchorPoint::TOP_LEFT);
788 application.SendNotification();
789 application.Render();
792 GestureReceivedFunctor functor(data);
794 LongPressGestureDetector firstDetector = LongPressGestureDetector::New();
795 firstDetector.Attach(first);
796 firstDetector.DetectedSignal().Connect(&application, functor);
798 // secondDetector is scoped
800 // Reset gestureManager statistics
801 gestureManager.Initialize();
803 LongPressGestureDetector secondDetector = LongPressGestureDetector::New();
804 secondDetector.SetTouchesRequired(2);
805 secondDetector.Attach(second);
806 secondDetector.DetectedSignal().Connect(&application, functor);
808 DALI_TEST_EQUALS(true, gestureManager.WasCalled(TestGestureManager::UpdateType), TEST_LOCATION);
809 DALI_TEST_EQUALS(false, gestureManager.WasCalled(TestGestureManager::RegisterType), TEST_LOCATION);
810 DALI_TEST_EQUALS(false, gestureManager.WasCalled(TestGestureManager::UnregisterType), TEST_LOCATION);
812 // LongPress within second actor's area
813 application.ProcessEvent(GenerateLongPress(Gesture::Possible, 2u, Vector2(150.0f, 10.0f)));
814 application.ProcessEvent(GenerateLongPress(Gesture::Started, 2u, Vector2(150.0f, 10.0f)));
815 application.ProcessEvent(GenerateLongPress(Gesture::Finished, 2u, Vector2(150.0f, 10.0f)));
816 DALI_TEST_EQUALS(true, data.functorCalled, TEST_LOCATION);
817 DALI_TEST_EQUALS(true, second == data.pressedActor, TEST_LOCATION);
819 // LongPress continues as single touch gesture - we should not receive any gesture
821 application.ProcessEvent(GenerateLongPress(Gesture::Possible, 1u, Vector2(150.0f, 10.0f)));
822 application.ProcessEvent(GenerateLongPress(Gesture::Started, 1u, Vector2(150.0f, 10.0f)));
823 application.ProcessEvent(GenerateLongPress(Gesture::Finished, 1u, Vector2(150.0f, 10.0f)));
824 DALI_TEST_EQUALS(false, data.functorCalled, TEST_LOCATION);
826 // Single touch long press starts - first actor should receive gesture
828 application.ProcessEvent(GenerateLongPress(Gesture::Possible, 1u, Vector2(50.0f, 10.0f)));
829 application.ProcessEvent(GenerateLongPress(Gesture::Started, 1u, Vector2(50.0f, 10.0f)));
830 application.ProcessEvent(GenerateLongPress(Gesture::Finished, 1u, Vector2(50.0f, 10.0f)));
831 DALI_TEST_EQUALS(true, data.functorCalled, TEST_LOCATION);
832 DALI_TEST_EQUALS(true, first == data.pressedActor, TEST_LOCATION);
834 // long press changes to double-touch - we shouldn't receive event
836 application.ProcessEvent(GenerateLongPress(Gesture::Possible, 2u, Vector2(50.0f, 10.0f)));
837 application.ProcessEvent(GenerateLongPress(Gesture::Started, 2u, Vector2(50.0f, 10.0f)));
838 application.ProcessEvent(GenerateLongPress(Gesture::Finished, 2u, Vector2(50.0f, 10.0f)));
839 DALI_TEST_EQUALS(false, data.functorCalled, TEST_LOCATION);
841 // Reset gesture manager statistics
842 gestureManager.Initialize();
845 // secondDetector has now been deleted. Gesture detection should have been updated only
846 DALI_TEST_EQUALS(true, gestureManager.WasCalled(TestGestureManager::UpdateType), TEST_LOCATION);
847 DALI_TEST_EQUALS(false, gestureManager.WasCalled(TestGestureManager::RegisterType), TEST_LOCATION);
848 DALI_TEST_EQUALS(false, gestureManager.WasCalled(TestGestureManager::UnregisterType), TEST_LOCATION);
852 int UtcDaliLongPressGestureSignalReceptionMultipleDetectorsOnActor(void)
854 TestApplication application;
856 Actor actor = Actor::New();
857 actor.SetSize(100.0f, 100.0f);
858 actor.SetAnchorPoint(AnchorPoint::TOP_LEFT);
859 Stage::GetCurrent().Add(actor);
862 application.SendNotification();
863 application.Render();
865 // Attach actor to one detector
866 SignalData firstData;
867 GestureReceivedFunctor firstFunctor(firstData);
868 LongPressGestureDetector firstDetector = LongPressGestureDetector::New();
869 firstDetector.Attach(actor);
870 firstDetector.DetectedSignal().Connect(&application, firstFunctor);
872 // Attach actor to another detector
873 SignalData secondData;
874 GestureReceivedFunctor secondFunctor(secondData);
875 LongPressGestureDetector secondDetector = LongPressGestureDetector::New();
876 secondDetector.Attach(actor);
877 secondDetector.DetectedSignal().Connect(&application, secondFunctor);
879 // LongPress in actor's area - both detector's functors should be called
880 application.ProcessEvent(GenerateLongPress(Gesture::Possible, 1u, Vector2(50.0f, 10.0f)));
881 application.ProcessEvent(GenerateLongPress(Gesture::Started, 1u, Vector2(50.0f, 10.0f)));
882 DALI_TEST_EQUALS(true, firstData.functorCalled, TEST_LOCATION);
883 DALI_TEST_EQUALS(true, secondData.functorCalled, TEST_LOCATION);
887 int UtcDaliLongPressGestureSignalReceptionDifferentPossible(void)
889 TestApplication application;
891 Actor actor = Actor::New();
892 actor.SetSize(100.0f, 100.0f);
893 actor.SetAnchorPoint(AnchorPoint::TOP_LEFT);
894 Stage::GetCurrent().Add(actor);
897 application.SendNotification();
898 application.Render();
900 // Attach actor to detector
902 GestureReceivedFunctor functor( data );
903 LongPressGestureDetector detector = LongPressGestureDetector::New();
904 detector.Attach(actor);
905 detector.DetectedSignal().Connect( &application, functor );
907 // LongPress possible in actor's area.
908 application.ProcessEvent(GenerateLongPress(Gesture::Possible, 1u, Vector2(50.0f, 10.0f)));
909 DALI_TEST_EQUALS(false, data.functorCalled, TEST_LOCATION);
911 // Move actor somewhere else
912 actor.SetPosition( 100.0f, 100.0f );
915 application.SendNotification();
916 application.Render();
918 // Emit Started event, we should not receive the long press.
919 application.ProcessEvent(GenerateLongPress(Gesture::Started, 1u, Vector2(50.0f, 10.0f)));
920 application.ProcessEvent(GenerateLongPress(Gesture::Finished, 1u, Vector2(50.0f, 10.0f)));
921 DALI_TEST_EQUALS(false, data.functorCalled, TEST_LOCATION);
923 // LongPress possible in empty area.
924 application.ProcessEvent(GenerateLongPress(Gesture::Possible, 1u, Vector2(50.0f, 10.0f)));
925 DALI_TEST_EQUALS(false, data.functorCalled, TEST_LOCATION);
927 // Move actor in to the long press position.
928 actor.SetPosition( 0.0f, 0.0f );
931 application.SendNotification();
932 application.Render();
934 // Emit Started event, we should not receive the long press.
935 application.ProcessEvent(GenerateLongPress(Gesture::Started, 1u, Vector2(50.0f, 10.0f)));
936 application.ProcessEvent(GenerateLongPress(Gesture::Finished, 1u, Vector2(50.0f, 10.0f)));
937 DALI_TEST_EQUALS(false, data.functorCalled, TEST_LOCATION);
939 // Normal long press in actor's area for completeness.
940 application.ProcessEvent(GenerateLongPress(Gesture::Possible, 1u, Vector2(50.0f, 10.0f)));
941 application.ProcessEvent(GenerateLongPress(Gesture::Started, 1u, Vector2(50.0f, 10.0f)));
942 application.ProcessEvent(GenerateLongPress(Gesture::Finished, 1u, Vector2(50.0f, 10.0f)));
943 DALI_TEST_EQUALS(true, data.functorCalled, TEST_LOCATION);
947 int UtcDaliLongPressGestureEmitIncorrectStateClear(void)
949 TestApplication application;
951 Actor actor = Actor::New();
952 actor.SetSize(100.0f, 100.0f);
953 actor.SetAnchorPoint(AnchorPoint::TOP_LEFT);
954 Stage::GetCurrent().Add(actor);
957 application.SendNotification();
958 application.Render();
960 // Attach actor to detector
962 GestureReceivedFunctor functor( data );
963 LongPressGestureDetector detector = LongPressGestureDetector::New();
964 detector.Attach(actor);
965 detector.DetectedSignal().Connect( &application, functor );
970 application.ProcessEvent(GenerateLongPress(Gesture::Clear, 1u, Vector2(50.0f, 10.0f)));
971 tet_result(TET_FAIL);
973 catch ( Dali::DaliException& e )
975 DALI_TEST_ASSERT( e, "false", TEST_LOCATION );
980 int UtcDaliLongPressGestureEmitIncorrectStateContinuing(void)
982 TestApplication application;
984 Actor actor = Actor::New();
985 actor.SetSize(100.0f, 100.0f);
986 actor.SetAnchorPoint(AnchorPoint::TOP_LEFT);
987 Stage::GetCurrent().Add(actor);
990 application.SendNotification();
991 application.Render();
993 // Attach actor to detector
995 GestureReceivedFunctor functor( data );
996 LongPressGestureDetector detector = LongPressGestureDetector::New();
997 detector.Attach(actor);
998 detector.DetectedSignal().Connect( &application, functor );
1000 // Try a Continuing state
1003 application.ProcessEvent(GenerateLongPress(Gesture::Continuing, 1u, Vector2(50.0f, 10.0f)));
1004 tet_result(TET_FAIL);
1006 catch ( Dali::DaliException& e )
1008 DALI_TEST_ASSERT( e, "false", TEST_LOCATION );
1013 int UtcDaliLongPressGestureRepeatedState(void)
1015 TestApplication application;
1017 Actor actor = Actor::New();
1018 actor.SetSize(100.0f, 100.0f);
1019 actor.SetAnchorPoint(AnchorPoint::TOP_LEFT);
1020 Stage::GetCurrent().Add(actor);
1022 // Render and notify
1023 application.SendNotification();
1024 application.Render();
1026 // Attach actor to detector
1028 GestureReceivedFunctor functor( data );
1029 LongPressGestureDetector detector = LongPressGestureDetector::New();
1030 detector.Attach(actor);
1031 detector.DetectedSignal().Connect( &application, functor );
1034 application.ProcessEvent(GenerateLongPress(Gesture::Possible, 1u, Vector2(50.0f, 10.0f)));
1035 DALI_TEST_EQUALS(false, data.functorCalled, TEST_LOCATION);
1036 application.ProcessEvent(GenerateLongPress(Gesture::Possible, 1u, Vector2(50.0f, 10.0f)));
1037 DALI_TEST_EQUALS(false, data.functorCalled, TEST_LOCATION);
1039 // ... Send some finished states, still no signal
1040 application.ProcessEvent(GenerateLongPress(Gesture::Finished, 1u, Vector2(50.0f, 10.0f)));
1041 DALI_TEST_EQUALS(false, data.functorCalled, TEST_LOCATION);
1042 application.ProcessEvent(GenerateLongPress(Gesture::Finished, 1u, Vector2(50.0f, 10.0f)));
1043 DALI_TEST_EQUALS(false, data.functorCalled, TEST_LOCATION);
1045 // Send two Started states, should be signalled
1046 application.ProcessEvent(GenerateLongPress(Gesture::Possible, 1u, Vector2(50.0f, 10.0f)));
1047 DALI_TEST_EQUALS(false, data.functorCalled, TEST_LOCATION);
1048 application.ProcessEvent(GenerateLongPress(Gesture::Started, 1u, Vector2(50.0f, 10.0f)));
1049 DALI_TEST_EQUALS(true, data.functorCalled, TEST_LOCATION);
1051 application.ProcessEvent(GenerateLongPress(Gesture::Started, 1u, Vector2(50.0f, 10.0f)));
1052 DALI_TEST_EQUALS(true, data.functorCalled, TEST_LOCATION);
1054 application.ProcessEvent(GenerateLongPress(Gesture::Finished, 1u, Vector2(50.0f, 10.0f)));
1055 DALI_TEST_EQUALS(true, data.functorCalled, TEST_LOCATION);
1058 // Send two cancelled states, should not be signalled
1059 application.ProcessEvent(GenerateLongPress(Gesture::Cancelled, 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 UtcDaliLongPressGesturePossibleCancelled(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 // Send a possible followed by a cancel, we should not be signalled
1087 application.ProcessEvent(GenerateLongPress(Gesture::Possible, 1u, Vector2(50.0f, 10.0f)));
1088 DALI_TEST_EQUALS(false, data.functorCalled, TEST_LOCATION);
1089 application.ProcessEvent(GenerateLongPress(Gesture::Cancelled, 1u, Vector2(50.0f, 10.0f)));
1090 DALI_TEST_EQUALS(false, data.functorCalled, TEST_LOCATION);
1094 int UtcDaliLongPressGestureDetachAfterStarted(void)
1096 TestApplication application;
1098 Actor actor = Actor::New();
1099 actor.SetSize(100.0f, 100.0f);
1100 actor.SetAnchorPoint(AnchorPoint::TOP_LEFT);
1101 Stage::GetCurrent().Add(actor);
1103 // Render and notify
1104 application.SendNotification();
1105 application.Render();
1107 // Attach actor to detector
1109 GestureReceivedFunctor functor( data );
1110 LongPressGestureDetector detector = LongPressGestureDetector::New();
1111 detector.Attach(actor);
1112 detector.DetectedSignal().Connect( &application, functor );
1114 // Emit initial signal
1115 application.ProcessEvent(GenerateLongPress(Gesture::Possible, 1u, Vector2(50.0f, 10.0f)));
1116 application.ProcessEvent(GenerateLongPress(Gesture::Started, 1u, Vector2(50.0f, 10.0f)));
1117 DALI_TEST_EQUALS(true, data.functorCalled, TEST_LOCATION);
1121 detector.Detach(actor);
1123 // Emit Finished, no signal
1124 application.ProcessEvent(GenerateLongPress(Gesture::Finished, 1u, Vector2(50.0f, 10.0f)));
1125 DALI_TEST_EQUALS(false, data.functorCalled, TEST_LOCATION);
1129 int UtcDaliLongPressGestureActorUnstaged(void)
1131 TestApplication application;
1133 Actor actor = Actor::New();
1134 actor.SetSize(100.0f, 100.0f);
1135 actor.SetAnchorPoint(AnchorPoint::TOP_LEFT);
1136 Stage::GetCurrent().Add(actor);
1138 // Render and notify
1139 application.SendNotification();
1140 application.Render();
1142 // State to remove actor in.
1143 Gesture::State stateToUnstage( Gesture::Started );
1145 // Attach actor to detector
1147 UnstageActorFunctor functor( data, stateToUnstage );
1148 LongPressGestureDetector detector = LongPressGestureDetector::New();
1149 detector.Attach(actor);
1150 detector.DetectedSignal().Connect( &application, functor );
1153 application.ProcessEvent(GenerateLongPress(Gesture::Possible, 1u, Vector2(50.0f, 10.0f)));
1154 application.ProcessEvent(GenerateLongPress(Gesture::Started, 1u, Vector2(50.0f, 10.0f)));
1155 DALI_TEST_EQUALS(true, data.functorCalled, TEST_LOCATION);
1157 application.ProcessEvent(GenerateLongPress(Gesture::Finished, 1u, Vector2(50.0f, 10.0f)));
1158 DALI_TEST_EQUALS(false, data.functorCalled, TEST_LOCATION);
1160 // Render and notify
1161 application.SendNotification();
1162 application.Render();
1164 // Re-add actor to stage
1165 Stage::GetCurrent().Add(actor);
1167 // Render and notify
1168 application.SendNotification();
1169 application.Render();
1171 // Change state to Gesture::Continuing to remove
1172 stateToUnstage = Gesture::Finished;
1175 application.ProcessEvent(GenerateLongPress(Gesture::Possible, 1u, Vector2(50.0f, 10.0f)));
1176 application.ProcessEvent(GenerateLongPress(Gesture::Started, 1u, Vector2(50.0f, 10.0f)));
1177 DALI_TEST_EQUALS(true, data.functorCalled, TEST_LOCATION);
1179 application.ProcessEvent(GenerateLongPress(Gesture::Finished, 1u, Vector2(50.0f, 10.0f)));
1180 DALI_TEST_EQUALS(true, data.functorCalled, TEST_LOCATION);
1181 tet_result( TET_PASS ); // If we get here then we have handled actor stage removal gracefully.
1185 int UtcDaliLongPressGestureActorStagedAndDestroyed(void)
1187 TestApplication application;
1189 Actor actor = Actor::New();
1190 actor.SetSize(100.0f, 100.0f);
1191 actor.SetAnchorPoint(AnchorPoint::TOP_LEFT);
1192 Stage::GetCurrent().Add(actor);
1194 // Create and add a second actor so that GestureDetector destruction does not come into play.
1195 Actor dummyActor( Actor::New() );
1196 dummyActor.SetSize( 100.0f, 100.0f );
1197 dummyActor.SetPosition( 100.0f, 100.0f );
1198 dummyActor.SetAnchorPoint(AnchorPoint::TOP_LEFT);
1199 Stage::GetCurrent().Add(dummyActor);
1201 // Render and notify
1202 application.SendNotification();
1203 application.Render();
1205 // State to remove actor in.
1206 Gesture::State stateToUnstage( Gesture::Started );
1208 // Attach actor to detector
1210 UnstageActorFunctor functor( data, stateToUnstage );
1211 LongPressGestureDetector detector = LongPressGestureDetector::New();
1212 detector.Attach(actor);
1213 detector.Attach(dummyActor);
1214 detector.DetectedSignal().Connect( &application, functor );
1216 // Here we are testing a Started actor which is removed in the Started callback, but then added back
1217 // before we get a finished state. As we were removed from the stage, even if we're at the same
1218 // position, we should still not be signalled.
1221 application.ProcessEvent(GenerateLongPress(Gesture::Possible, 1u, Vector2(50.0f, 10.0f)));
1222 application.ProcessEvent(GenerateLongPress(Gesture::Started, 1u, Vector2(50.0f, 10.0f)));
1223 DALI_TEST_EQUALS(true, data.functorCalled, TEST_LOCATION);
1226 // Render and notify
1227 application.SendNotification();
1228 application.Render();
1230 // Re add to the stage, we should not be signalled
1231 Stage::GetCurrent().Add(actor);
1233 // Render and notify
1234 application.SendNotification();
1235 application.Render();
1237 // Continue signal emission
1238 application.ProcessEvent(GenerateLongPress(Gesture::Finished, 1u, Vector2(50.0f, 10.0f)));
1239 DALI_TEST_EQUALS(false, data.functorCalled, TEST_LOCATION);
1242 // Here we delete an actor in started, we should not receive any subsequent signalling.
1245 application.ProcessEvent(GenerateLongPress(Gesture::Possible, 1u, Vector2(50.0f, 10.0f)));
1246 application.ProcessEvent(GenerateLongPress(Gesture::Started, 1u, Vector2(50.0f, 10.0f)));
1247 DALI_TEST_EQUALS(true, data.functorCalled, TEST_LOCATION);
1250 // Render and notify
1251 application.SendNotification();
1252 application.Render();
1254 // Delete actor as well
1257 // Render and notify
1258 application.SendNotification();
1259 application.Render();
1261 // Continue signal emission
1262 application.ProcessEvent(GenerateLongPress(Gesture::Finished, 1u, Vector2(50.0f, 10.0f)));
1263 DALI_TEST_EQUALS(false, data.functorCalled, TEST_LOCATION);
1267 int UtcDaliLongPressGestureSystemOverlay(void)
1269 TestApplication application;
1270 Dali::Integration::Core& core = application.GetCore();
1271 Dali::Integration::SystemOverlay& systemOverlay( core.GetSystemOverlay() );
1272 systemOverlay.GetOverlayRenderTasks().CreateTask();
1274 Actor actor = Actor::New();
1275 actor.SetSize(100.0f, 100.0f);
1276 actor.SetAnchorPoint(AnchorPoint::TOP_LEFT);
1277 systemOverlay.Add(actor);
1279 // Render and notify
1280 application.SendNotification();
1281 application.Render();
1284 GestureReceivedFunctor functor(data);
1286 LongPressGestureDetector detector = LongPressGestureDetector::New();
1287 detector.Attach(actor);
1288 detector.DetectedSignal().Connect(&application, functor);
1290 // Do a long press inside actor's area
1291 Vector2 screenCoords( 50.0f, 50.0f );
1292 application.ProcessEvent( GenerateLongPress( Gesture::Possible, 1u, screenCoords ) );
1293 application.ProcessEvent( GenerateLongPress( Gesture::Started, 1u, screenCoords ) );
1294 DALI_TEST_EQUALS( true, data.functorCalled, TEST_LOCATION );
1298 int UtcDaliLongPressGestureBehindTouchableSystemOverlay(void)
1300 TestApplication application;
1301 Dali::Integration::Core& core = application.GetCore();
1302 Dali::Integration::SystemOverlay& systemOverlay( core.GetSystemOverlay() );
1303 systemOverlay.GetOverlayRenderTasks().CreateTask();
1305 // SystemOverlay actor
1306 Actor systemOverlayActor = Actor::New();
1307 systemOverlayActor.SetSize(100.0f, 100.0f);
1308 systemOverlayActor.SetAnchorPoint(AnchorPoint::TOP_LEFT);
1309 systemOverlay.Add(systemOverlayActor);
1312 Actor stageActor = Actor::New();
1313 stageActor.SetSize(100.0f, 100.0f);
1314 stageActor.SetAnchorPoint(AnchorPoint::TOP_LEFT);
1315 Stage::GetCurrent().Add(stageActor);
1317 // Render and notify
1318 application.SendNotification();
1319 application.Render();
1321 // Set system-overlay actor to touchable
1322 TouchEventData touchData;
1323 TouchEventDataFunctor touchFunctor( touchData );
1324 systemOverlayActor.TouchedSignal().Connect(&application, touchFunctor);
1326 // Set stage actor to receive the gesture
1328 GestureReceivedFunctor functor(data);
1330 LongPressGestureDetector detector = LongPressGestureDetector::New();
1331 detector.Attach(stageActor);
1332 detector.DetectedSignal().Connect(&application, functor);
1334 // Start long press within the two actors' area
1335 Vector2 screenCoords( 50.0f, 50.0f );
1336 application.ProcessEvent( GenerateLongPress( Gesture::Possible, 1u, screenCoords ) );
1337 application.ProcessEvent( GenerateLongPress( Gesture::Started, 1u, screenCoords ) );
1338 DALI_TEST_EQUALS( true, data.functorCalled, TEST_LOCATION );
1339 DALI_TEST_EQUALS( false, touchData.functorCalled, TEST_LOCATION );
1344 // Do touch in the same area
1345 application.ProcessEvent( touchFunctor.GenerateSingleTouch( PointState::DOWN, screenCoords ) );
1346 DALI_TEST_EQUALS( false, data.functorCalled, TEST_LOCATION );
1347 DALI_TEST_EQUALS( true, touchData.functorCalled, TEST_LOCATION );
1352 int UtcDaliLongPressGestureTouchBehindGesturedSystemOverlay(void)
1354 TestApplication application;
1355 Dali::Integration::Core& core = application.GetCore();
1356 Dali::Integration::SystemOverlay& systemOverlay( core.GetSystemOverlay() );
1357 systemOverlay.GetOverlayRenderTasks().CreateTask();
1359 // SystemOverlay actor
1360 Actor systemOverlayActor = Actor::New();
1361 systemOverlayActor.SetSize(100.0f, 100.0f);
1362 systemOverlayActor.SetAnchorPoint(AnchorPoint::TOP_LEFT);
1363 systemOverlay.Add(systemOverlayActor);
1366 Actor stageActor = Actor::New();
1367 stageActor.SetSize(100.0f, 100.0f);
1368 stageActor.SetAnchorPoint(AnchorPoint::TOP_LEFT);
1369 Stage::GetCurrent().Add(stageActor);
1371 // Render and notify
1372 application.SendNotification();
1373 application.Render();
1375 // Set stage actor to touchable
1376 TouchEventData touchData;
1377 TouchEventDataFunctor touchFunctor( touchData );
1378 stageActor.TouchedSignal().Connect(&application, touchFunctor);
1380 // Set system-overlay actor to have the gesture
1382 GestureReceivedFunctor functor(data);
1384 LongPressGestureDetector detector = LongPressGestureDetector::New();
1385 detector.Attach(systemOverlayActor);
1386 detector.DetectedSignal().Connect(&application, functor);
1388 // Start long press within the two actors' area
1389 Vector2 screenCoords( 50.0f, 50.0f );
1390 application.ProcessEvent( GenerateLongPress( Gesture::Possible, 1u, screenCoords ) );
1391 application.ProcessEvent( GenerateLongPress( Gesture::Started, 1u, screenCoords ) );
1392 DALI_TEST_EQUALS( true, data.functorCalled, TEST_LOCATION );
1393 DALI_TEST_EQUALS( false, touchData.functorCalled, TEST_LOCATION );
1398 // Do touch in the same area
1399 application.ProcessEvent( touchFunctor.GenerateSingleTouch( PointState::DOWN, screenCoords ) );
1400 DALI_TEST_EQUALS( false, data.functorCalled, TEST_LOCATION );
1401 DALI_TEST_EQUALS( true, touchData.functorCalled, TEST_LOCATION );
1406 int UtcDaliLongPressGestureLayerConsumesTouch(void)
1408 TestApplication application;
1410 Actor actor = Actor::New();
1411 actor.SetSize(100.0f, 100.0f);
1412 actor.SetAnchorPoint(AnchorPoint::TOP_LEFT);
1413 Stage::GetCurrent().Add(actor);
1417 GestureReceivedFunctor functor(data);
1418 LongPressGestureDetector detector = LongPressGestureDetector::New();
1419 detector.Attach(actor);
1420 detector.DetectedSignal().Connect( &application, functor );
1422 // Add a layer to overlap the actor
1423 Layer layer = Layer::New();
1424 layer.SetSize(100.0f, 100.0f);
1425 layer.SetAnchorPoint(AnchorPoint::TOP_LEFT);
1426 Stage::GetCurrent().Add( layer );
1429 // Render and notify
1430 application.SendNotification();
1431 application.Render();
1433 Vector2 screenCoords( 50.0f, 50.0f );
1435 // Emit signals, should receive
1436 application.ProcessEvent( GenerateLongPress( Gesture::Possible, 1u, screenCoords ) );
1437 application.ProcessEvent( GenerateLongPress( Gesture::Started, 1u, screenCoords ) );
1438 application.ProcessEvent( GenerateLongPress( Gesture::Finished, 1u, screenCoords ) );
1439 DALI_TEST_EQUALS(true, data.functorCalled, TEST_LOCATION);
1442 // Set layer to consume all touch
1443 layer.SetTouchConsumed( true );
1445 // Render and notify
1446 application.SendNotification();
1447 application.Render();
1449 // Emit the same signals again, should not receive
1450 application.ProcessEvent( GenerateLongPress( Gesture::Possible, 1u, screenCoords ) );
1451 application.ProcessEvent( GenerateLongPress( Gesture::Started, 1u, screenCoords ) );
1452 application.ProcessEvent( GenerateLongPress( Gesture::Finished, 1u, screenCoords ) );
1453 DALI_TEST_EQUALS(false, data.functorCalled, TEST_LOCATION);