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 TouchPoint point(1, TouchPoint::Down, 20.0f, 20.0f);
227 touchEvent.AddPoint(point);
228 application.ProcessEvent(touchEvent);
231 application.SendNotification();
232 application.Render();
234 // For line coverage, Initialise default constructor
235 TouchEvent touchEvent2;
239 int UtcDaliLongPressGestureDetectorDownCast(void)
241 TestApplication application;
242 tet_infoline("Testing Dali::LongPressGestureDetector::DownCast()");
244 LongPressGestureDetector detector = LongPressGestureDetector::New();
246 BaseHandle object(detector);
248 LongPressGestureDetector detector2 = LongPressGestureDetector::DownCast(object);
249 DALI_TEST_CHECK(detector2);
251 LongPressGestureDetector detector3 = DownCast< LongPressGestureDetector >(object);
252 DALI_TEST_CHECK(detector3);
254 BaseHandle unInitializedObject;
255 LongPressGestureDetector detector4 = LongPressGestureDetector::DownCast(unInitializedObject);
256 DALI_TEST_CHECK(!detector4);
258 LongPressGestureDetector detector5 = DownCast< LongPressGestureDetector >(unInitializedObject);
259 DALI_TEST_CHECK(!detector5);
261 GestureDetector detector6 = LongPressGestureDetector::New();
262 LongPressGestureDetector detector7 = LongPressGestureDetector::DownCast(detector6);
263 DALI_TEST_CHECK(detector7);
267 int UtcDaliLongPressGestureSetTouchesRequired01(void)
269 TestApplication application;
271 LongPressGestureDetector detector = LongPressGestureDetector::New();
273 unsigned int touches = 3;
275 DALI_TEST_CHECK(touches != detector.GetMinimumTouchesRequired());
276 DALI_TEST_CHECK(touches != detector.GetMaximumTouchesRequired());
278 detector.SetTouchesRequired(touches);
280 DALI_TEST_EQUALS(touches, detector.GetMinimumTouchesRequired(), TEST_LOCATION);
281 DALI_TEST_EQUALS(touches, detector.GetMaximumTouchesRequired(), TEST_LOCATION);
283 // Attach an actor and change the required touches
285 Actor actor = Actor::New();
286 actor.SetSize(100.0f, 100.0f);
287 actor.SetAnchorPoint(AnchorPoint::TOP_LEFT);
288 Stage::GetCurrent().Add(actor);
291 application.SendNotification();
292 application.Render();
295 GestureReceivedFunctor functor(data);
297 detector.Attach(actor);
298 detector.DetectedSignal().Connect(&application, functor);
300 TestGestureManager& gestureManager = application.GetGestureManager();
301 gestureManager.Initialize();
303 detector.SetTouchesRequired(4);
305 // Gesture detection should have been updated only
306 DALI_TEST_EQUALS(true, gestureManager.WasCalled(TestGestureManager::UpdateType), TEST_LOCATION);
307 DALI_TEST_EQUALS(false, gestureManager.WasCalled(TestGestureManager::RegisterType), TEST_LOCATION);
308 DALI_TEST_EQUALS(false, gestureManager.WasCalled(TestGestureManager::UnregisterType), TEST_LOCATION);
311 gestureManager.Initialize();
313 // Create a second gesture detector that requires even less maximum touches
314 LongPressGestureDetector secondDetector = LongPressGestureDetector::New();
315 secondDetector.Attach(actor);
317 // Gesture detection should have been updated
318 DALI_TEST_EQUALS(true, gestureManager.WasCalled(TestGestureManager::UpdateType), TEST_LOCATION);
319 DALI_TEST_EQUALS(false, gestureManager.WasCalled(TestGestureManager::RegisterType), TEST_LOCATION);
320 DALI_TEST_EQUALS(false, gestureManager.WasCalled(TestGestureManager::UnregisterType), TEST_LOCATION);
324 int UtcDaliLongPressGestureSetTouchesRequired02(void)
326 TestApplication application;
328 LongPressGestureDetector detector = LongPressGestureDetector::New();
330 unsigned int min = 3;
331 unsigned int max = 5;
333 DALI_TEST_CHECK(min != detector.GetMinimumTouchesRequired());
334 DALI_TEST_CHECK(max != detector.GetMaximumTouchesRequired());
336 detector.SetTouchesRequired(min, max);
338 DALI_TEST_EQUALS(min, detector.GetMinimumTouchesRequired(), TEST_LOCATION);
339 DALI_TEST_EQUALS(max, detector.GetMaximumTouchesRequired(), TEST_LOCATION);
341 // Attach an actor and change the maximum touches
343 Actor actor = Actor::New();
344 actor.SetSize(100.0f, 100.0f);
345 actor.SetAnchorPoint(AnchorPoint::TOP_LEFT);
346 Stage::GetCurrent().Add(actor);
349 application.SendNotification();
350 application.Render();
353 GestureReceivedFunctor functor(data);
355 detector.Attach(actor);
356 detector.DetectedSignal().Connect(&application, functor);
358 TestGestureManager& gestureManager = application.GetGestureManager();
359 gestureManager.Initialize();
361 detector.SetTouchesRequired(4, 5);
363 // Gesture detection should have been updated only
364 DALI_TEST_EQUALS(true, gestureManager.WasCalled(TestGestureManager::UpdateType), TEST_LOCATION);
365 DALI_TEST_EQUALS(false, gestureManager.WasCalled(TestGestureManager::RegisterType), TEST_LOCATION);
366 DALI_TEST_EQUALS(false, gestureManager.WasCalled(TestGestureManager::UnregisterType), TEST_LOCATION);
369 gestureManager.Initialize();
371 // Create a second gesture detector that requires even less maximum touches
372 LongPressGestureDetector secondDetector = LongPressGestureDetector::New();
373 secondDetector.Attach(actor);
375 // Gesture detection should have been updated
376 DALI_TEST_EQUALS(true, gestureManager.WasCalled(TestGestureManager::UpdateType), TEST_LOCATION);
377 DALI_TEST_EQUALS(false, gestureManager.WasCalled(TestGestureManager::RegisterType), TEST_LOCATION);
378 DALI_TEST_EQUALS(false, gestureManager.WasCalled(TestGestureManager::UnregisterType), TEST_LOCATION);
382 int UtcDaliLongPressGestureGetMinimumTouchesRequired(void)
384 TestApplication application;
386 LongPressGestureDetector detector = LongPressGestureDetector::New();
387 DALI_TEST_EQUALS(1u, detector.GetMinimumTouchesRequired(), TEST_LOCATION);
391 int UtcDaliLongPressGestureGetMaximumTouchesRequired(void)
393 TestApplication application;
395 LongPressGestureDetector detector = LongPressGestureDetector::New();
396 DALI_TEST_EQUALS(1u, detector.GetMaximumTouchesRequired(), TEST_LOCATION);
400 int UtcDaliLongPressGestureSignalReceptionNegative(void)
402 TestApplication application;
404 Actor actor = Actor::New();
405 actor.SetSize(100.0f, 100.0f);
406 actor.SetAnchorPoint(AnchorPoint::TOP_LEFT);
407 Stage::GetCurrent().Add(actor);
410 application.SendNotification();
411 application.Render();
414 GestureReceivedFunctor functor(data);
416 LongPressGestureDetector detector = LongPressGestureDetector::New();
417 detector.Attach(actor);
418 detector.DetectedSignal().Connect(&application, functor);
420 // Do a long press outside actor's area
421 application.ProcessEvent( GenerateLongPress( Gesture::Possible, 1u, Vector2(112.0f, 112.0f ) ) );
422 application.ProcessEvent( GenerateLongPress( Gesture::Started, 1u, Vector2(112.0f, 112.0f ) ) );
423 application.ProcessEvent( GenerateLongPress( Gesture::Finished, 1u, Vector2(112.0f, 112.0f ) ) );
424 DALI_TEST_EQUALS(false, data.functorCalled, TEST_LOCATION);
428 int UtcDaliLongPressGestureSignalReceptionPositive(void)
430 TestApplication application;
432 Actor actor = Actor::New();
433 actor.SetSize(100.0f, 100.0f);
434 actor.SetAnchorPoint(AnchorPoint::TOP_LEFT);
435 Stage::GetCurrent().Add(actor);
438 application.SendNotification();
439 application.Render();
442 GestureReceivedFunctor functor(data);
444 LongPressGestureDetector detector = LongPressGestureDetector::New();
445 detector.Attach(actor);
446 detector.DetectedSignal().Connect(&application, functor);
448 // Do a long press inside actor's area
449 application.ProcessEvent(GenerateLongPress(Gesture::Possible, 1u, Vector2(50.0f, 50.0f)));
450 application.ProcessEvent(GenerateLongPress(Gesture::Started, 1u, Vector2(50.0f, 50.0f)));
451 DALI_TEST_EQUALS(true, data.functorCalled, TEST_LOCATION);
452 DALI_TEST_EQUALS(1u, data.receivedGesture.numberOfTouches, TEST_LOCATION);
453 DALI_TEST_EQUALS( Vector2(50.0f, 50.0f), data.receivedGesture.localPoint, 0.1, TEST_LOCATION);
454 application.ProcessEvent(GenerateLongPress(Gesture::Finished, 1u, Vector2(50.0f, 50.0f)));
458 int UtcDaliLongPressGestureSignalReceptionDetach(void)
460 TestApplication application;
462 Actor actor = Actor::New();
463 actor.SetSize(100.0f, 100.0f);
464 actor.SetAnchorPoint(AnchorPoint::TOP_LEFT);
465 Stage::GetCurrent().Add(actor);
468 application.SendNotification();
469 application.Render();
472 GestureReceivedFunctor functor(data);
474 LongPressGestureDetector detector = LongPressGestureDetector::New();
475 detector.Attach(actor);
476 detector.DetectedSignal().Connect(&application, functor);
478 // Start long press within the actor's area
479 application.ProcessEvent(GenerateLongPress(Gesture::Possible, 1u, Vector2(20.0f, 20.0f)));
480 application.ProcessEvent(GenerateLongPress(Gesture::Started, 1u, Vector2(20.0f, 20.0f)));
481 DALI_TEST_EQUALS(true, data.functorCalled, TEST_LOCATION);
482 DALI_TEST_EQUALS(1u, data.receivedGesture.numberOfTouches, TEST_LOCATION);
483 DALI_TEST_EQUALS( Vector2(20.0f, 20.0f), data.receivedGesture.localPoint, 0.1, TEST_LOCATION);
484 application.ProcessEvent(GenerateLongPress(Gesture::Finished, 1u, Vector2(20.0f, 20.0f)));
486 // repeat the long press within the actor's area - we should still receive the signal
488 application.ProcessEvent(GenerateLongPress(Gesture::Possible, 1u, Vector2(50.0f, 50.0f)));
489 application.ProcessEvent(GenerateLongPress(Gesture::Started, 1u, Vector2(50.0f, 50.0f)));
490 DALI_TEST_EQUALS(true, data.functorCalled, TEST_LOCATION);
491 DALI_TEST_EQUALS(1u, data.receivedGesture.numberOfTouches, TEST_LOCATION);
492 DALI_TEST_EQUALS( Vector2(50.0f, 50.0f), data.receivedGesture.localPoint, 0.1, TEST_LOCATION);
493 application.ProcessEvent(GenerateLongPress(Gesture::Finished, 1u, Vector2(50.0f, 50.0f)));
496 detector.DetachAll();
498 // Ensure we are no longer signalled
500 application.ProcessEvent(GenerateLongPress(Gesture::Possible, 1u, Vector2(20.0f, 20.0f)));
501 application.ProcessEvent(GenerateLongPress(Gesture::Started, 1u, Vector2(20.0f, 20.0f)));
502 DALI_TEST_EQUALS(false, data.functorCalled, TEST_LOCATION);
503 application.ProcessEvent(GenerateLongPress(Gesture::Finished, 1u, Vector2(50.0f, 50.0f)));
504 DALI_TEST_EQUALS(false, data.functorCalled, TEST_LOCATION);
508 int UtcDaliLongPressGestureSignalReceptionActorDestroyedDuringLongPress(void)
510 TestApplication application;
513 GestureReceivedFunctor functor(data);
515 LongPressGestureDetector detector = LongPressGestureDetector::New();
516 detector.DetectedSignal().Connect(&application, functor);
518 // Actor lifetime is scoped
520 Actor actor = Actor::New();
521 actor.SetSize(100.0f, 100.0f);
522 actor.SetAnchorPoint(AnchorPoint::TOP_LEFT);
523 Stage::GetCurrent().Add(actor);
526 application.SendNotification();
527 application.Render();
529 detector.Attach(actor);
531 // Start long press within the actor's area
532 application.ProcessEvent(GenerateLongPress(Gesture::Possible, 1u, Vector2(20.0f, 20.0f)));
533 application.ProcessEvent(GenerateLongPress(Gesture::Started, 1u, Vector2(20.0f, 20.0f)));
534 DALI_TEST_EQUALS(true, data.functorCalled, TEST_LOCATION);
536 // Remove the actor from stage and reset the data
537 Stage::GetCurrent().Remove(actor);
540 application.SendNotification();
541 application.Render();
544 // Actor should now have been destroyed
547 application.ProcessEvent(GenerateLongPress(Gesture::Finished, 1u, Vector2(20.0f, 20.0f)));
548 DALI_TEST_EQUALS(false, data.functorCalled, TEST_LOCATION);
552 int UtcDaliLongPressGestureSignalReceptionRotatedActor(void)
554 TestApplication application;
556 Actor actor = Actor::New();
557 actor.SetSize(100.0f, 100.0f);
558 actor.SetOrientation(Dali::Degree(90.0f), Vector3::ZAXIS);
559 Stage::GetCurrent().Add(actor);
562 application.SendNotification();
563 application.Render();
566 GestureReceivedFunctor functor(data);
568 LongPressGestureDetector detector = LongPressGestureDetector::New();
569 detector.Attach(actor);
570 detector.DetectedSignal().Connect(&application, functor);
573 application.ProcessEvent(GenerateLongPress(Gesture::Possible, 1u, Vector2(5.0f, 5.0f)));
574 application.ProcessEvent(GenerateLongPress(Gesture::Started, 1u, Vector2(5.0f, 5.0f)));
575 application.ProcessEvent(GenerateLongPress(Gesture::Finished, 1u, Vector2(5.0f, 5.0f)));
576 DALI_TEST_EQUALS(true, data.functorCalled, TEST_LOCATION);
577 DALI_TEST_EQUALS(1u, data.receivedGesture.numberOfTouches, TEST_LOCATION);
578 DALI_TEST_EQUALS( Vector2(5.0f, 5.0f), data.receivedGesture.screenPoint, 0.1, TEST_LOCATION);
580 // Rotate actor again and render
581 actor.SetOrientation(Dali::Degree(180.0f), Vector3::ZAXIS);
582 application.SendNotification();
583 application.Render();
585 // Do another long press, should still receive event
587 application.ProcessEvent(GenerateLongPress(Gesture::Possible, 1u, Vector2(5.0f, 5.0f)));
588 application.ProcessEvent(GenerateLongPress(Gesture::Started, 1u, Vector2(5.0f, 5.0f)));
589 application.ProcessEvent(GenerateLongPress(Gesture::Finished, 1u, Vector2(5.0f, 5.0f)));
590 DALI_TEST_EQUALS(true, data.functorCalled, TEST_LOCATION);
591 DALI_TEST_EQUALS(1u, data.receivedGesture.numberOfTouches, TEST_LOCATION);
592 DALI_TEST_EQUALS( Vector2(5.0f, 5.0f), data.receivedGesture.screenPoint, 0.1, TEST_LOCATION);
594 // Rotate actor again and render
595 actor.SetOrientation(Dali::Degree(90.0f), Vector3::YAXIS);
596 application.SendNotification();
597 application.Render();
599 // Do a long press, inside where the actor used to be, Should not receive the event
601 application.ProcessEvent(GenerateLongPress(Gesture::Possible, 1u, Vector2(70.0f, 70.0f)));
602 application.ProcessEvent(GenerateLongPress(Gesture::Started, 1u, Vector2(70.0f, 70.0f)));
603 application.ProcessEvent(GenerateLongPress(Gesture::Finished, 1u, Vector2(70.0f, 70.0f)));
604 DALI_TEST_EQUALS(false, data.functorCalled, TEST_LOCATION);
608 int UtcDaliLongPressGestureSignalReceptionChildHit(void)
610 TestApplication application;
612 Actor parent = Actor::New();
613 parent.SetSize(100.0f, 100.0f);
614 parent.SetAnchorPoint(AnchorPoint::TOP_LEFT);
615 Stage::GetCurrent().Add(parent);
617 // Set child to completely cover parent.
618 // Change rotation of child to be different from parent so that we can check if our local coordinate
619 // conversion of the parent actor is correct.
620 Actor child = Actor::New();
621 child.SetSize(100.0f, 100.0f);
622 child.SetAnchorPoint(AnchorPoint::CENTER);
623 child.SetParentOrigin(ParentOrigin::CENTER);
624 child.SetOrientation(Dali::Degree(90.0f), Vector3::ZAXIS);
627 TouchEventFunctor touchFunctor;
628 child.TouchedSignal().Connect(&application, touchFunctor);
631 application.SendNotification();
632 application.Render();
635 GestureReceivedFunctor functor(data);
637 LongPressGestureDetector detector = LongPressGestureDetector::New();
638 detector.Attach(parent);
639 detector.DetectedSignal().Connect(&application, functor);
641 // Do long press - hits child area but parent should still receive it
642 application.ProcessEvent(GenerateLongPress(Gesture::Possible, 1u, Vector2(50.0f, 50.0f)));
643 application.ProcessEvent(GenerateLongPress(Gesture::Started, 1u, Vector2(50.0f, 50.0f)));
644 application.ProcessEvent(GenerateLongPress(Gesture::Finished, 1u, Vector2(50.0f, 50.0f)));
645 DALI_TEST_EQUALS(true, data.functorCalled, TEST_LOCATION);
646 DALI_TEST_EQUALS(true, parent == data.pressedActor, TEST_LOCATION);
647 DALI_TEST_EQUALS(Vector2(50.0f, 50.0f), data.receivedGesture.screenPoint, 0.01f, TEST_LOCATION);
649 // Attach child and generate same touch points
650 // (Also proves that you can detach and then re-attach another actor)
651 detector.Attach(child);
652 detector.Detach(parent);
654 // Do an entire long press, only check finished value
656 application.ProcessEvent(GenerateLongPress(Gesture::Possible, 1u, Vector2(51.0f, 51.0f)));
657 application.ProcessEvent(GenerateLongPress(Gesture::Started, 1u, Vector2(51.0f, 51.0f)));
658 application.ProcessEvent(GenerateLongPress(Gesture::Finished, 1u, Vector2(51.0f, 51.0f)));
659 DALI_TEST_EQUALS(true, data.functorCalled, TEST_LOCATION);
660 DALI_TEST_EQUALS(true, child == data.pressedActor, TEST_LOCATION);
661 DALI_TEST_EQUALS(Vector2(51.0f, 51.0f), data.receivedGesture.screenPoint, 0.01f, TEST_LOCATION);
665 int UtcDaliLongPressGestureSignalReceptionAttachDetachMany(void)
667 TestApplication application;
669 Actor first = Actor::New();
670 first.SetSize(100.0f, 100.0f);
671 first.SetAnchorPoint(AnchorPoint::TOP_LEFT);
672 Stage::GetCurrent().Add(first);
674 Actor second = Actor::New();
675 second.SetSize(100.0f, 100.0f);
677 second.SetAnchorPoint(AnchorPoint::TOP_LEFT);
678 Stage::GetCurrent().Add(second);
681 application.SendNotification();
682 application.Render();
685 GestureReceivedFunctor functor(data);
687 LongPressGestureDetector detector = LongPressGestureDetector::New();
688 detector.Attach(first);
689 detector.Attach(second);
690 detector.DetectedSignal().Connect(&application, functor);
692 // LongPress within second actor's area
693 application.ProcessEvent(GenerateLongPress(Gesture::Possible, 1u, Vector2(120.0f, 10.0f)));
694 application.ProcessEvent(GenerateLongPress(Gesture::Started, 1u, Vector2(120.0f, 10.0f)));
695 application.ProcessEvent(GenerateLongPress(Gesture::Finished, 1u, Vector2(120.0f, 10.0f)));
696 DALI_TEST_EQUALS(true, data.functorCalled, TEST_LOCATION);
697 DALI_TEST_EQUALS(true, second == data.pressedActor, TEST_LOCATION);
699 // LongPress within first actor's area
701 application.ProcessEvent(GenerateLongPress(Gesture::Possible, 1u, Vector2(20.0f, 10.0f)));
702 application.ProcessEvent(GenerateLongPress(Gesture::Started, 1u, Vector2(20.0f, 10.0f)));
703 application.ProcessEvent(GenerateLongPress(Gesture::Finished, 1u, Vector2(20.0f, 10.0f)));
704 DALI_TEST_EQUALS(true, data.functorCalled, TEST_LOCATION);
705 DALI_TEST_EQUALS(true, first == data.pressedActor, TEST_LOCATION);
707 // Detach the second actor
708 detector.Detach(second);
710 // second actor shouldn't receive event
712 application.ProcessEvent(GenerateLongPress(Gesture::Possible, 1u, Vector2(120.0f, 10.0f)));
713 application.ProcessEvent(GenerateLongPress(Gesture::Started, 1u, Vector2(120.0f, 10.0f)));
714 application.ProcessEvent(GenerateLongPress(Gesture::Finished, 1u, Vector2(120.0f, 10.0f)));
715 DALI_TEST_EQUALS(false, data.functorCalled, TEST_LOCATION);
717 // first actor should continue receiving event
719 application.ProcessEvent(GenerateLongPress(Gesture::Possible, 1u, Vector2(20.0f, 10.0f)));
720 application.ProcessEvent(GenerateLongPress(Gesture::Started, 1u, Vector2(20.0f, 10.0f)));
721 application.ProcessEvent(GenerateLongPress(Gesture::Finished, 1u, Vector2(20.0f, 10.0f)));
722 DALI_TEST_EQUALS(true, data.functorCalled, TEST_LOCATION);
726 int UtcDaliLongPressGestureSignalReceptionActorBecomesUntouchable(void)
728 TestApplication application;
730 Actor actor = Actor::New();
731 actor.SetSize(100.0f, 100.0f);
732 actor.SetAnchorPoint(AnchorPoint::TOP_LEFT);
733 Stage::GetCurrent().Add(actor);
736 application.SendNotification();
737 application.Render();
740 GestureReceivedFunctor functor(data);
742 LongPressGestureDetector detector = LongPressGestureDetector::New();
743 detector.Attach(actor);
744 detector.DetectedSignal().Connect(&application, functor);
746 // LongPress in actor's area
747 application.ProcessEvent(GenerateLongPress(Gesture::Possible, 1u, Vector2(50.0f, 10.0f)));
748 application.ProcessEvent(GenerateLongPress(Gesture::Started, 1u, Vector2(50.0f, 10.0f)));
749 application.ProcessEvent(GenerateLongPress(Gesture::Finished, 1u, Vector2(50.0f, 10.0f)));
750 DALI_TEST_EQUALS(true, data.functorCalled, TEST_LOCATION);
752 // Actor becomes invisible - actor should not receive the next long press
753 actor.SetVisible(false);
756 application.SendNotification();
757 application.Render();
759 // LongPress in the same area, shouldn't receive event
761 application.ProcessEvent(GenerateLongPress(Gesture::Possible, 1u, Vector2(50.0f, 10.0f)));
762 application.ProcessEvent(GenerateLongPress(Gesture::Started, 1u, Vector2(50.0f, 10.0f)));
763 application.ProcessEvent(GenerateLongPress(Gesture::Finished, 1u, Vector2(50.0f, 10.0f)));
764 DALI_TEST_EQUALS(false, data.functorCalled, TEST_LOCATION);
768 int UtcDaliLongPressGestureSignalReceptionMultipleGestureDetectors(void)
770 TestApplication application;
771 Dali::TestGestureManager& gestureManager = application.GetGestureManager();
773 Actor first = Actor::New();
774 first.SetSize(100.0f, 100.0f);
775 first.SetAnchorPoint(AnchorPoint::TOP_LEFT);
776 Stage::GetCurrent().Add(first);
778 Actor second = Actor::New();
779 second.SetSize(100.0f, 100.0f);
780 second.SetAnchorPoint(AnchorPoint::TOP_LEFT);
785 application.SendNotification();
786 application.Render();
789 GestureReceivedFunctor functor(data);
791 LongPressGestureDetector firstDetector = LongPressGestureDetector::New();
792 firstDetector.Attach(first);
793 firstDetector.DetectedSignal().Connect(&application, functor);
795 // secondDetector is scoped
797 // Reset gestureManager statistics
798 gestureManager.Initialize();
800 LongPressGestureDetector secondDetector = LongPressGestureDetector::New();
801 secondDetector.SetTouchesRequired(2);
802 secondDetector.Attach(second);
803 secondDetector.DetectedSignal().Connect(&application, functor);
805 DALI_TEST_EQUALS(true, gestureManager.WasCalled(TestGestureManager::UpdateType), TEST_LOCATION);
806 DALI_TEST_EQUALS(false, gestureManager.WasCalled(TestGestureManager::RegisterType), TEST_LOCATION);
807 DALI_TEST_EQUALS(false, gestureManager.WasCalled(TestGestureManager::UnregisterType), TEST_LOCATION);
809 // LongPress within second actor's area
810 application.ProcessEvent(GenerateLongPress(Gesture::Possible, 2u, Vector2(150.0f, 10.0f)));
811 application.ProcessEvent(GenerateLongPress(Gesture::Started, 2u, Vector2(150.0f, 10.0f)));
812 application.ProcessEvent(GenerateLongPress(Gesture::Finished, 2u, Vector2(150.0f, 10.0f)));
813 DALI_TEST_EQUALS(true, data.functorCalled, TEST_LOCATION);
814 DALI_TEST_EQUALS(true, second == data.pressedActor, TEST_LOCATION);
816 // LongPress continues as single touch gesture - we should not receive any gesture
818 application.ProcessEvent(GenerateLongPress(Gesture::Possible, 1u, Vector2(150.0f, 10.0f)));
819 application.ProcessEvent(GenerateLongPress(Gesture::Started, 1u, Vector2(150.0f, 10.0f)));
820 application.ProcessEvent(GenerateLongPress(Gesture::Finished, 1u, Vector2(150.0f, 10.0f)));
821 DALI_TEST_EQUALS(false, data.functorCalled, TEST_LOCATION);
823 // Single touch long press starts - first actor should receive gesture
825 application.ProcessEvent(GenerateLongPress(Gesture::Possible, 1u, Vector2(50.0f, 10.0f)));
826 application.ProcessEvent(GenerateLongPress(Gesture::Started, 1u, Vector2(50.0f, 10.0f)));
827 application.ProcessEvent(GenerateLongPress(Gesture::Finished, 1u, Vector2(50.0f, 10.0f)));
828 DALI_TEST_EQUALS(true, data.functorCalled, TEST_LOCATION);
829 DALI_TEST_EQUALS(true, first == data.pressedActor, TEST_LOCATION);
831 // long press changes to double-touch - we shouldn't receive event
833 application.ProcessEvent(GenerateLongPress(Gesture::Possible, 2u, Vector2(50.0f, 10.0f)));
834 application.ProcessEvent(GenerateLongPress(Gesture::Started, 2u, Vector2(50.0f, 10.0f)));
835 application.ProcessEvent(GenerateLongPress(Gesture::Finished, 2u, Vector2(50.0f, 10.0f)));
836 DALI_TEST_EQUALS(false, data.functorCalled, TEST_LOCATION);
838 // Reset gesture manager statistics
839 gestureManager.Initialize();
842 // secondDetector has now been deleted. Gesture detection should have been updated only
843 DALI_TEST_EQUALS(true, gestureManager.WasCalled(TestGestureManager::UpdateType), TEST_LOCATION);
844 DALI_TEST_EQUALS(false, gestureManager.WasCalled(TestGestureManager::RegisterType), TEST_LOCATION);
845 DALI_TEST_EQUALS(false, gestureManager.WasCalled(TestGestureManager::UnregisterType), TEST_LOCATION);
849 int UtcDaliLongPressGestureSignalReceptionMultipleDetectorsOnActor(void)
851 TestApplication application;
853 Actor actor = Actor::New();
854 actor.SetSize(100.0f, 100.0f);
855 actor.SetAnchorPoint(AnchorPoint::TOP_LEFT);
856 Stage::GetCurrent().Add(actor);
859 application.SendNotification();
860 application.Render();
862 // Attach actor to one detector
863 SignalData firstData;
864 GestureReceivedFunctor firstFunctor(firstData);
865 LongPressGestureDetector firstDetector = LongPressGestureDetector::New();
866 firstDetector.Attach(actor);
867 firstDetector.DetectedSignal().Connect(&application, firstFunctor);
869 // Attach actor to another detector
870 SignalData secondData;
871 GestureReceivedFunctor secondFunctor(secondData);
872 LongPressGestureDetector secondDetector = LongPressGestureDetector::New();
873 secondDetector.Attach(actor);
874 secondDetector.DetectedSignal().Connect(&application, secondFunctor);
876 // LongPress in actor's area - both detector's functors should be called
877 application.ProcessEvent(GenerateLongPress(Gesture::Possible, 1u, Vector2(50.0f, 10.0f)));
878 application.ProcessEvent(GenerateLongPress(Gesture::Started, 1u, Vector2(50.0f, 10.0f)));
879 DALI_TEST_EQUALS(true, firstData.functorCalled, TEST_LOCATION);
880 DALI_TEST_EQUALS(true, secondData.functorCalled, TEST_LOCATION);
884 int UtcDaliLongPressGestureSignalReceptionDifferentPossible(void)
886 TestApplication application;
888 Actor actor = Actor::New();
889 actor.SetSize(100.0f, 100.0f);
890 actor.SetAnchorPoint(AnchorPoint::TOP_LEFT);
891 Stage::GetCurrent().Add(actor);
894 application.SendNotification();
895 application.Render();
897 // Attach actor to detector
899 GestureReceivedFunctor functor( data );
900 LongPressGestureDetector detector = LongPressGestureDetector::New();
901 detector.Attach(actor);
902 detector.DetectedSignal().Connect( &application, functor );
904 // LongPress possible in actor's area.
905 application.ProcessEvent(GenerateLongPress(Gesture::Possible, 1u, Vector2(50.0f, 10.0f)));
906 DALI_TEST_EQUALS(false, data.functorCalled, TEST_LOCATION);
908 // Move actor somewhere else
909 actor.SetPosition( 100.0f, 100.0f );
912 application.SendNotification();
913 application.Render();
915 // Emit Started event, we should not receive the long press.
916 application.ProcessEvent(GenerateLongPress(Gesture::Started, 1u, Vector2(50.0f, 10.0f)));
917 application.ProcessEvent(GenerateLongPress(Gesture::Finished, 1u, Vector2(50.0f, 10.0f)));
918 DALI_TEST_EQUALS(false, data.functorCalled, TEST_LOCATION);
920 // LongPress possible in empty area.
921 application.ProcessEvent(GenerateLongPress(Gesture::Possible, 1u, Vector2(50.0f, 10.0f)));
922 DALI_TEST_EQUALS(false, data.functorCalled, TEST_LOCATION);
924 // Move actor in to the long press position.
925 actor.SetPosition( 0.0f, 0.0f );
928 application.SendNotification();
929 application.Render();
931 // Emit Started event, we should not receive the long press.
932 application.ProcessEvent(GenerateLongPress(Gesture::Started, 1u, Vector2(50.0f, 10.0f)));
933 application.ProcessEvent(GenerateLongPress(Gesture::Finished, 1u, Vector2(50.0f, 10.0f)));
934 DALI_TEST_EQUALS(false, data.functorCalled, TEST_LOCATION);
936 // Normal long press in actor's area for completeness.
937 application.ProcessEvent(GenerateLongPress(Gesture::Possible, 1u, Vector2(50.0f, 10.0f)));
938 application.ProcessEvent(GenerateLongPress(Gesture::Started, 1u, Vector2(50.0f, 10.0f)));
939 application.ProcessEvent(GenerateLongPress(Gesture::Finished, 1u, Vector2(50.0f, 10.0f)));
940 DALI_TEST_EQUALS(true, data.functorCalled, TEST_LOCATION);
944 int UtcDaliLongPressGestureEmitIncorrectStateClear(void)
946 TestApplication application;
948 Actor actor = Actor::New();
949 actor.SetSize(100.0f, 100.0f);
950 actor.SetAnchorPoint(AnchorPoint::TOP_LEFT);
951 Stage::GetCurrent().Add(actor);
954 application.SendNotification();
955 application.Render();
957 // Attach actor to detector
959 GestureReceivedFunctor functor( data );
960 LongPressGestureDetector detector = LongPressGestureDetector::New();
961 detector.Attach(actor);
962 detector.DetectedSignal().Connect( &application, functor );
967 application.ProcessEvent(GenerateLongPress(Gesture::Clear, 1u, Vector2(50.0f, 10.0f)));
968 tet_result(TET_FAIL);
970 catch ( Dali::DaliException& e )
972 DALI_TEST_ASSERT( e, "false", TEST_LOCATION );
977 int UtcDaliLongPressGestureEmitIncorrectStateContinuing(void)
979 TestApplication application;
981 Actor actor = Actor::New();
982 actor.SetSize(100.0f, 100.0f);
983 actor.SetAnchorPoint(AnchorPoint::TOP_LEFT);
984 Stage::GetCurrent().Add(actor);
987 application.SendNotification();
988 application.Render();
990 // Attach actor to detector
992 GestureReceivedFunctor functor( data );
993 LongPressGestureDetector detector = LongPressGestureDetector::New();
994 detector.Attach(actor);
995 detector.DetectedSignal().Connect( &application, functor );
997 // Try a Continuing state
1000 application.ProcessEvent(GenerateLongPress(Gesture::Continuing, 1u, Vector2(50.0f, 10.0f)));
1001 tet_result(TET_FAIL);
1003 catch ( Dali::DaliException& e )
1005 DALI_TEST_ASSERT( e, "false", TEST_LOCATION );
1010 int UtcDaliLongPressGestureRepeatedState(void)
1012 TestApplication application;
1014 Actor actor = Actor::New();
1015 actor.SetSize(100.0f, 100.0f);
1016 actor.SetAnchorPoint(AnchorPoint::TOP_LEFT);
1017 Stage::GetCurrent().Add(actor);
1019 // Render and notify
1020 application.SendNotification();
1021 application.Render();
1023 // Attach actor to detector
1025 GestureReceivedFunctor functor( data );
1026 LongPressGestureDetector detector = LongPressGestureDetector::New();
1027 detector.Attach(actor);
1028 detector.DetectedSignal().Connect( &application, functor );
1031 application.ProcessEvent(GenerateLongPress(Gesture::Possible, 1u, Vector2(50.0f, 10.0f)));
1032 DALI_TEST_EQUALS(false, data.functorCalled, TEST_LOCATION);
1033 application.ProcessEvent(GenerateLongPress(Gesture::Possible, 1u, Vector2(50.0f, 10.0f)));
1034 DALI_TEST_EQUALS(false, data.functorCalled, TEST_LOCATION);
1036 // ... Send some finished states, still no signal
1037 application.ProcessEvent(GenerateLongPress(Gesture::Finished, 1u, Vector2(50.0f, 10.0f)));
1038 DALI_TEST_EQUALS(false, data.functorCalled, TEST_LOCATION);
1039 application.ProcessEvent(GenerateLongPress(Gesture::Finished, 1u, Vector2(50.0f, 10.0f)));
1040 DALI_TEST_EQUALS(false, data.functorCalled, TEST_LOCATION);
1042 // Send two Started states, should be signalled
1043 application.ProcessEvent(GenerateLongPress(Gesture::Possible, 1u, Vector2(50.0f, 10.0f)));
1044 DALI_TEST_EQUALS(false, data.functorCalled, TEST_LOCATION);
1045 application.ProcessEvent(GenerateLongPress(Gesture::Started, 1u, Vector2(50.0f, 10.0f)));
1046 DALI_TEST_EQUALS(true, 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::Finished, 1u, Vector2(50.0f, 10.0f)));
1052 DALI_TEST_EQUALS(true, data.functorCalled, TEST_LOCATION);
1055 // Send two cancelled states, should not be signalled
1056 application.ProcessEvent(GenerateLongPress(Gesture::Cancelled, 1u, Vector2(50.0f, 10.0f)));
1057 DALI_TEST_EQUALS(false, data.functorCalled, TEST_LOCATION);
1058 application.ProcessEvent(GenerateLongPress(Gesture::Cancelled, 1u, Vector2(50.0f, 10.0f)));
1059 DALI_TEST_EQUALS(false, data.functorCalled, TEST_LOCATION);
1063 int UtcDaliLongPressGesturePossibleCancelled(void)
1065 TestApplication application;
1067 Actor actor = Actor::New();
1068 actor.SetSize(100.0f, 100.0f);
1069 actor.SetAnchorPoint(AnchorPoint::TOP_LEFT);
1070 Stage::GetCurrent().Add(actor);
1072 // Render and notify
1073 application.SendNotification();
1074 application.Render();
1076 // Attach actor to detector
1078 GestureReceivedFunctor functor( data );
1079 LongPressGestureDetector detector = LongPressGestureDetector::New();
1080 detector.Attach(actor);
1081 detector.DetectedSignal().Connect( &application, functor );
1083 // Send a possible followed by a cancel, we should not be signalled
1084 application.ProcessEvent(GenerateLongPress(Gesture::Possible, 1u, Vector2(50.0f, 10.0f)));
1085 DALI_TEST_EQUALS(false, data.functorCalled, TEST_LOCATION);
1086 application.ProcessEvent(GenerateLongPress(Gesture::Cancelled, 1u, Vector2(50.0f, 10.0f)));
1087 DALI_TEST_EQUALS(false, data.functorCalled, TEST_LOCATION);
1091 int UtcDaliLongPressGestureDetachAfterStarted(void)
1093 TestApplication application;
1095 Actor actor = Actor::New();
1096 actor.SetSize(100.0f, 100.0f);
1097 actor.SetAnchorPoint(AnchorPoint::TOP_LEFT);
1098 Stage::GetCurrent().Add(actor);
1100 // Render and notify
1101 application.SendNotification();
1102 application.Render();
1104 // Attach actor to detector
1106 GestureReceivedFunctor functor( data );
1107 LongPressGestureDetector detector = LongPressGestureDetector::New();
1108 detector.Attach(actor);
1109 detector.DetectedSignal().Connect( &application, functor );
1111 // Emit initial signal
1112 application.ProcessEvent(GenerateLongPress(Gesture::Possible, 1u, Vector2(50.0f, 10.0f)));
1113 application.ProcessEvent(GenerateLongPress(Gesture::Started, 1u, Vector2(50.0f, 10.0f)));
1114 DALI_TEST_EQUALS(true, data.functorCalled, TEST_LOCATION);
1118 detector.Detach(actor);
1120 // Emit Finished, no signal
1121 application.ProcessEvent(GenerateLongPress(Gesture::Finished, 1u, Vector2(50.0f, 10.0f)));
1122 DALI_TEST_EQUALS(false, data.functorCalled, TEST_LOCATION);
1126 int UtcDaliLongPressGestureActorUnstaged(void)
1128 TestApplication application;
1130 Actor actor = Actor::New();
1131 actor.SetSize(100.0f, 100.0f);
1132 actor.SetAnchorPoint(AnchorPoint::TOP_LEFT);
1133 Stage::GetCurrent().Add(actor);
1135 // Render and notify
1136 application.SendNotification();
1137 application.Render();
1139 // State to remove actor in.
1140 Gesture::State stateToUnstage( Gesture::Started );
1142 // Attach actor to detector
1144 UnstageActorFunctor functor( data, stateToUnstage );
1145 LongPressGestureDetector detector = LongPressGestureDetector::New();
1146 detector.Attach(actor);
1147 detector.DetectedSignal().Connect( &application, functor );
1150 application.ProcessEvent(GenerateLongPress(Gesture::Possible, 1u, Vector2(50.0f, 10.0f)));
1151 application.ProcessEvent(GenerateLongPress(Gesture::Started, 1u, Vector2(50.0f, 10.0f)));
1152 DALI_TEST_EQUALS(true, data.functorCalled, TEST_LOCATION);
1154 application.ProcessEvent(GenerateLongPress(Gesture::Finished, 1u, Vector2(50.0f, 10.0f)));
1155 DALI_TEST_EQUALS(false, data.functorCalled, TEST_LOCATION);
1157 // Render and notify
1158 application.SendNotification();
1159 application.Render();
1161 // Re-add actor to stage
1162 Stage::GetCurrent().Add(actor);
1164 // Render and notify
1165 application.SendNotification();
1166 application.Render();
1168 // Change state to Gesture::Continuing to remove
1169 stateToUnstage = Gesture::Finished;
1172 application.ProcessEvent(GenerateLongPress(Gesture::Possible, 1u, Vector2(50.0f, 10.0f)));
1173 application.ProcessEvent(GenerateLongPress(Gesture::Started, 1u, Vector2(50.0f, 10.0f)));
1174 DALI_TEST_EQUALS(true, data.functorCalled, TEST_LOCATION);
1176 application.ProcessEvent(GenerateLongPress(Gesture::Finished, 1u, Vector2(50.0f, 10.0f)));
1177 DALI_TEST_EQUALS(true, data.functorCalled, TEST_LOCATION);
1178 tet_result( TET_PASS ); // If we get here then we have handled actor stage removal gracefully.
1182 int UtcDaliLongPressGestureActorStagedAndDestroyed(void)
1184 TestApplication application;
1186 Actor actor = Actor::New();
1187 actor.SetSize(100.0f, 100.0f);
1188 actor.SetAnchorPoint(AnchorPoint::TOP_LEFT);
1189 Stage::GetCurrent().Add(actor);
1191 // Create and add a second actor so that GestureDetector destruction does not come into play.
1192 Actor dummyActor( Actor::New() );
1193 dummyActor.SetSize( 100.0f, 100.0f );
1194 dummyActor.SetPosition( 100.0f, 100.0f );
1195 dummyActor.SetAnchorPoint(AnchorPoint::TOP_LEFT);
1196 Stage::GetCurrent().Add(dummyActor);
1198 // Render and notify
1199 application.SendNotification();
1200 application.Render();
1202 // State to remove actor in.
1203 Gesture::State stateToUnstage( Gesture::Started );
1205 // Attach actor to detector
1207 UnstageActorFunctor functor( data, stateToUnstage );
1208 LongPressGestureDetector detector = LongPressGestureDetector::New();
1209 detector.Attach(actor);
1210 detector.Attach(dummyActor);
1211 detector.DetectedSignal().Connect( &application, functor );
1213 // Here we are testing a Started actor which is removed in the Started callback, but then added back
1214 // before we get a finished state. As we were removed from the stage, even if we're at the same
1215 // position, we should still not be signalled.
1218 application.ProcessEvent(GenerateLongPress(Gesture::Possible, 1u, Vector2(50.0f, 10.0f)));
1219 application.ProcessEvent(GenerateLongPress(Gesture::Started, 1u, Vector2(50.0f, 10.0f)));
1220 DALI_TEST_EQUALS(true, data.functorCalled, TEST_LOCATION);
1223 // Render and notify
1224 application.SendNotification();
1225 application.Render();
1227 // Re add to the stage, we should not be signalled
1228 Stage::GetCurrent().Add(actor);
1230 // Render and notify
1231 application.SendNotification();
1232 application.Render();
1234 // Continue signal emission
1235 application.ProcessEvent(GenerateLongPress(Gesture::Finished, 1u, Vector2(50.0f, 10.0f)));
1236 DALI_TEST_EQUALS(false, data.functorCalled, TEST_LOCATION);
1239 // Here we delete an actor in started, we should not receive any subsequent signalling.
1242 application.ProcessEvent(GenerateLongPress(Gesture::Possible, 1u, Vector2(50.0f, 10.0f)));
1243 application.ProcessEvent(GenerateLongPress(Gesture::Started, 1u, Vector2(50.0f, 10.0f)));
1244 DALI_TEST_EQUALS(true, data.functorCalled, TEST_LOCATION);
1247 // Render and notify
1248 application.SendNotification();
1249 application.Render();
1251 // Delete actor as well
1254 // Render and notify
1255 application.SendNotification();
1256 application.Render();
1258 // Continue signal emission
1259 application.ProcessEvent(GenerateLongPress(Gesture::Finished, 1u, Vector2(50.0f, 10.0f)));
1260 DALI_TEST_EQUALS(false, data.functorCalled, TEST_LOCATION);
1264 int UtcDaliLongPressGestureSystemOverlay(void)
1266 TestApplication application;
1267 Dali::Integration::Core& core = application.GetCore();
1268 Dali::Integration::SystemOverlay& systemOverlay( core.GetSystemOverlay() );
1269 systemOverlay.GetOverlayRenderTasks().CreateTask();
1271 Actor actor = Actor::New();
1272 actor.SetSize(100.0f, 100.0f);
1273 actor.SetAnchorPoint(AnchorPoint::TOP_LEFT);
1274 systemOverlay.Add(actor);
1276 // Render and notify
1277 application.SendNotification();
1278 application.Render();
1281 GestureReceivedFunctor functor(data);
1283 LongPressGestureDetector detector = LongPressGestureDetector::New();
1284 detector.Attach(actor);
1285 detector.DetectedSignal().Connect(&application, functor);
1287 // Do a long press inside actor's area
1288 Vector2 screenCoords( 50.0f, 50.0f );
1289 application.ProcessEvent( GenerateLongPress( Gesture::Possible, 1u, screenCoords ) );
1290 application.ProcessEvent( GenerateLongPress( Gesture::Started, 1u, screenCoords ) );
1291 DALI_TEST_EQUALS( true, data.functorCalled, TEST_LOCATION );
1295 int UtcDaliLongPressGestureBehindTouchableSystemOverlay(void)
1297 TestApplication application;
1298 Dali::Integration::Core& core = application.GetCore();
1299 Dali::Integration::SystemOverlay& systemOverlay( core.GetSystemOverlay() );
1300 systemOverlay.GetOverlayRenderTasks().CreateTask();
1302 // SystemOverlay actor
1303 Actor systemOverlayActor = Actor::New();
1304 systemOverlayActor.SetSize(100.0f, 100.0f);
1305 systemOverlayActor.SetAnchorPoint(AnchorPoint::TOP_LEFT);
1306 systemOverlay.Add(systemOverlayActor);
1309 Actor stageActor = Actor::New();
1310 stageActor.SetSize(100.0f, 100.0f);
1311 stageActor.SetAnchorPoint(AnchorPoint::TOP_LEFT);
1312 Stage::GetCurrent().Add(stageActor);
1314 // Render and notify
1315 application.SendNotification();
1316 application.Render();
1318 // Set system-overlay actor to touchable
1319 TouchEventData touchData;
1320 TouchEventDataFunctor touchFunctor( touchData );
1321 systemOverlayActor.TouchedSignal().Connect(&application, touchFunctor);
1323 // Set stage actor to receive the gesture
1325 GestureReceivedFunctor functor(data);
1327 LongPressGestureDetector detector = LongPressGestureDetector::New();
1328 detector.Attach(stageActor);
1329 detector.DetectedSignal().Connect(&application, functor);
1331 // Start long press within the two actors' area
1332 Vector2 screenCoords( 50.0f, 50.0f );
1333 application.ProcessEvent( GenerateLongPress( Gesture::Possible, 1u, screenCoords ) );
1334 application.ProcessEvent( GenerateLongPress( Gesture::Started, 1u, screenCoords ) );
1335 DALI_TEST_EQUALS( true, data.functorCalled, TEST_LOCATION );
1336 DALI_TEST_EQUALS( false, touchData.functorCalled, TEST_LOCATION );
1341 // Do touch in the same area
1342 application.ProcessEvent( touchFunctor.GenerateSingleTouch( TouchPoint::Down, screenCoords ) );
1343 DALI_TEST_EQUALS( false, data.functorCalled, TEST_LOCATION );
1344 DALI_TEST_EQUALS( true, touchData.functorCalled, TEST_LOCATION );
1349 int UtcDaliLongPressGestureTouchBehindGesturedSystemOverlay(void)
1351 TestApplication application;
1352 Dali::Integration::Core& core = application.GetCore();
1353 Dali::Integration::SystemOverlay& systemOverlay( core.GetSystemOverlay() );
1354 systemOverlay.GetOverlayRenderTasks().CreateTask();
1356 // SystemOverlay actor
1357 Actor systemOverlayActor = Actor::New();
1358 systemOverlayActor.SetSize(100.0f, 100.0f);
1359 systemOverlayActor.SetAnchorPoint(AnchorPoint::TOP_LEFT);
1360 systemOverlay.Add(systemOverlayActor);
1363 Actor stageActor = Actor::New();
1364 stageActor.SetSize(100.0f, 100.0f);
1365 stageActor.SetAnchorPoint(AnchorPoint::TOP_LEFT);
1366 Stage::GetCurrent().Add(stageActor);
1368 // Render and notify
1369 application.SendNotification();
1370 application.Render();
1372 // Set stage actor to touchable
1373 TouchEventData touchData;
1374 TouchEventDataFunctor touchFunctor( touchData );
1375 stageActor.TouchedSignal().Connect(&application, touchFunctor);
1377 // Set system-overlay actor to have the gesture
1379 GestureReceivedFunctor functor(data);
1381 LongPressGestureDetector detector = LongPressGestureDetector::New();
1382 detector.Attach(systemOverlayActor);
1383 detector.DetectedSignal().Connect(&application, functor);
1385 // Start long press within the two actors' area
1386 Vector2 screenCoords( 50.0f, 50.0f );
1387 application.ProcessEvent( GenerateLongPress( Gesture::Possible, 1u, screenCoords ) );
1388 application.ProcessEvent( GenerateLongPress( Gesture::Started, 1u, screenCoords ) );
1389 DALI_TEST_EQUALS( true, data.functorCalled, TEST_LOCATION );
1390 DALI_TEST_EQUALS( false, touchData.functorCalled, TEST_LOCATION );
1395 // Do touch in the same area
1396 application.ProcessEvent( touchFunctor.GenerateSingleTouch( TouchPoint::Down, screenCoords ) );
1397 DALI_TEST_EQUALS( false, data.functorCalled, TEST_LOCATION );
1398 DALI_TEST_EQUALS( true, touchData.functorCalled, TEST_LOCATION );
1403 int UtcDaliLongPressGestureLayerConsumesTouch(void)
1405 TestApplication application;
1407 Actor actor = Actor::New();
1408 actor.SetSize(100.0f, 100.0f);
1409 actor.SetAnchorPoint(AnchorPoint::TOP_LEFT);
1410 Stage::GetCurrent().Add(actor);
1414 GestureReceivedFunctor functor(data);
1415 LongPressGestureDetector detector = LongPressGestureDetector::New();
1416 detector.Attach(actor);
1417 detector.DetectedSignal().Connect( &application, functor );
1419 // Add a layer to overlap the actor
1420 Layer layer = Layer::New();
1421 layer.SetSize(100.0f, 100.0f);
1422 layer.SetAnchorPoint(AnchorPoint::TOP_LEFT);
1423 Stage::GetCurrent().Add( layer );
1426 // Render and notify
1427 application.SendNotification();
1428 application.Render();
1430 Vector2 screenCoords( 50.0f, 50.0f );
1432 // Emit signals, should receive
1433 application.ProcessEvent( GenerateLongPress( Gesture::Possible, 1u, screenCoords ) );
1434 application.ProcessEvent( GenerateLongPress( Gesture::Started, 1u, screenCoords ) );
1435 application.ProcessEvent( GenerateLongPress( Gesture::Finished, 1u, screenCoords ) );
1436 DALI_TEST_EQUALS(true, data.functorCalled, TEST_LOCATION);
1439 // Set layer to consume all touch
1440 layer.SetTouchConsumed( true );
1442 // Render and notify
1443 application.SendNotification();
1444 application.Render();
1446 // Emit the same signals again, should not receive
1447 application.ProcessEvent( GenerateLongPress( Gesture::Possible, 1u, screenCoords ) );
1448 application.ProcessEvent( GenerateLongPress( Gesture::Started, 1u, screenCoords ) );
1449 application.ProcessEvent( GenerateLongPress( Gesture::Finished, 1u, screenCoords ) );
1450 DALI_TEST_EQUALS(false, data.functorCalled, TEST_LOCATION);