2 * Copyright (c) 2020 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/input-options.h>
24 #include <dali/integration-api/render-task-list-integ.h>
25 #include <dali/devel-api/events/long-press-gesture-detector-devel.h>
26 #include <dali-test-suite-utils.h>
27 #include <test-touch-utils.h>
28 #include <test-touch-data-utils.h>
32 void utc_dali_long_press_gesture_detector_startup(void)
34 test_return_value = TET_UNDEF;
37 void utc_dali_long_press_gesture_detector_cleanup(void)
39 test_return_value = TET_PASS;
42 ///////////////////////////////////////////////////////////////////////////////
46 // Stores data that is populated in the callback and will be read by the TET cases
50 : functorCalled( false ),
51 voidFunctorCalled( false ),
52 receivedGesture( Gesture::Clear ),
58 functorCalled = false;
59 voidFunctorCalled = false;
61 receivedGesture.numberOfTouches = 0u;
62 receivedGesture.screenPoint = Vector2(0.0f, 0.0f);
63 receivedGesture.localPoint = Vector2(0.0f, 0.0f);
69 bool voidFunctorCalled;
70 LongPressGesture receivedGesture;
74 // Functor that sets the data when called
75 struct GestureReceivedFunctor
77 GestureReceivedFunctor(SignalData& data) : signalData(data) { }
79 void operator()(Actor actor, const LongPressGesture& longPress)
81 signalData.functorCalled = true;
82 signalData.receivedGesture = longPress;
83 signalData.pressedActor = actor;
88 signalData.voidFunctorCalled = true;
91 SignalData& signalData;
94 // Functor that removes the gestured actor from stage
95 struct UnstageActorFunctor : public GestureReceivedFunctor
97 UnstageActorFunctor( SignalData& data, Gesture::State& stateToUnstage, Integration::Scene scene )
98 : GestureReceivedFunctor( data ),
99 stateToUnstage( stateToUnstage ),
104 void operator()( Actor actor, const LongPressGesture& longPress )
106 GestureReceivedFunctor::operator()( actor, longPress );
108 if ( longPress.state == stateToUnstage )
110 scene.Remove( actor );
114 Gesture::State& stateToUnstage;
115 Integration::Scene scene;
118 // Functor for receiving a touch event
119 struct TouchEventFunctor
121 bool operator()(Actor actor, const TouchEvent& touch)
124 unsigned int points = touch.GetPointCount();
127 const TouchPoint& touchPoint = touch.GetPoint(0);
128 tet_printf("Touch Point state = %d\n", touchPoint.state);
136 ///////////////////////////////////////////////////////////////////////////////
139 // Positive test case for a method
140 int UtcDaliLongPressGestureDetectorConstructorP(void)
142 TestApplication application;
144 LongPressGestureDetector detector;
145 DALI_TEST_CHECK(!detector);
149 int UtcDaliLongPressGestureDetectorCopyConstructorP(void)
151 TestApplication application;
153 LongPressGestureDetector detector = LongPressGestureDetector::New();;
155 LongPressGestureDetector copy( detector );
156 DALI_TEST_CHECK( detector );
160 int UtcDaliLongPressGestureDetectorAssignmentOperatorP(void)
162 TestApplication application;
164 LongPressGestureDetector detector;
165 detector = LongPressGestureDetector::New();;
167 LongPressGestureDetector copy;
169 DALI_TEST_CHECK( detector );
171 DALI_TEST_CHECK( detector == copy );
175 int UtcDaliLongPressGestureDetectorNew(void)
177 TestApplication application;
179 LongPressGestureDetector detector = LongPressGestureDetector::New();
180 DALI_TEST_CHECK(detector);
181 DALI_TEST_EQUALS(1u, detector.GetMinimumTouchesRequired(), TEST_LOCATION);
182 DALI_TEST_EQUALS(1u, detector.GetMaximumTouchesRequired(), TEST_LOCATION);
184 LongPressGestureDetector detector2 = LongPressGestureDetector::New(5u);
185 DALI_TEST_CHECK(detector2);
186 DALI_TEST_EQUALS(5u, detector2.GetMinimumTouchesRequired(), TEST_LOCATION);
187 DALI_TEST_EQUALS(5u, detector2.GetMaximumTouchesRequired(), TEST_LOCATION);
189 LongPressGestureDetector detector3 = LongPressGestureDetector::New(5u, 7u);
190 DALI_TEST_CHECK(detector2);
191 DALI_TEST_EQUALS(5u, detector3.GetMinimumTouchesRequired(), TEST_LOCATION);
192 DALI_TEST_EQUALS(7u, detector3.GetMaximumTouchesRequired(), TEST_LOCATION);
194 //Scoped test to test destructor
196 LongPressGestureDetector detector4 = LongPressGestureDetector::New();
197 DALI_TEST_CHECK(detector4);
200 // Attach an actor and emit a touch event on the actor to ensure complete line coverage
201 Actor actor = Actor::New();
202 actor.SetProperty( Actor::Property::SIZE, Vector2( 100.0f, 100.0f ) );
203 actor.SetProperty( Actor::Property::ANCHOR_POINT,AnchorPoint::TOP_LEFT);
204 application.GetScene().Add(actor);
207 application.SendNotification();
208 application.Render();
210 detector.Attach(actor);
212 TouchEventFunctor touchFunctor;
213 actor.TouchedSignal().Connect(&application, touchFunctor);
215 Integration::TouchEvent touchEvent(1);
216 Integration::Point point;
217 point.SetDeviceId( 1 );
218 point.SetState( PointState::DOWN );
219 point.SetScreenPosition( Vector2( 20.0f, 20.0f ) );
220 touchEvent.AddPoint(point);
221 application.ProcessEvent(touchEvent);
224 application.SendNotification();
225 application.Render();
227 // For line coverage, Initialise default constructor
228 TouchEvent touchEvent2;
232 int UtcDaliLongPressGestureDetectorDownCast(void)
234 TestApplication application;
235 tet_infoline("Testing Dali::LongPressGestureDetector::DownCast()");
237 LongPressGestureDetector detector = LongPressGestureDetector::New();
239 BaseHandle object(detector);
241 LongPressGestureDetector detector2 = LongPressGestureDetector::DownCast(object);
242 DALI_TEST_CHECK(detector2);
244 LongPressGestureDetector detector3 = DownCast< LongPressGestureDetector >(object);
245 DALI_TEST_CHECK(detector3);
247 BaseHandle unInitializedObject;
248 LongPressGestureDetector detector4 = LongPressGestureDetector::DownCast(unInitializedObject);
249 DALI_TEST_CHECK(!detector4);
251 LongPressGestureDetector detector5 = DownCast< LongPressGestureDetector >(unInitializedObject);
252 DALI_TEST_CHECK(!detector5);
254 GestureDetector detector6 = LongPressGestureDetector::New();
255 LongPressGestureDetector detector7 = LongPressGestureDetector::DownCast(detector6);
256 DALI_TEST_CHECK(detector7);
260 int UtcDaliLongPressGestureGetMinimumTouchesRequired(void)
262 TestApplication application;
264 LongPressGestureDetector detector = LongPressGestureDetector::New();
265 DALI_TEST_EQUALS(1u, detector.GetMinimumTouchesRequired(), TEST_LOCATION);
269 int UtcDaliLongPressGestureGetMaximumTouchesRequired(void)
271 TestApplication application;
273 LongPressGestureDetector detector = LongPressGestureDetector::New();
274 DALI_TEST_EQUALS(1u, detector.GetMaximumTouchesRequired(), TEST_LOCATION);
278 int UtcDaliLongPressGestureSignalReceptionNegative(void)
280 TestApplication application;
282 Actor actor = Actor::New();
283 actor.SetProperty( Actor::Property::SIZE, Vector2( 100.0f, 100.0f ) );
284 actor.SetProperty( Actor::Property::ANCHOR_POINT,AnchorPoint::TOP_LEFT);
285 application.GetScene().Add(actor);
288 application.SendNotification();
289 application.Render();
292 GestureReceivedFunctor functor(data);
294 LongPressGestureDetector detector = LongPressGestureDetector::New();
295 detector.Attach(actor);
296 detector.DetectedSignal().Connect(&application, functor);
298 // Do a long press outside actor's area
299 TestGenerateLongPress( application, 112.0f, 112.0f );
300 TestEndLongPress( application, 112.0f, 112.0f);
302 DALI_TEST_EQUALS(false, data.functorCalled, TEST_LOCATION);
306 int UtcDaliLongPressGestureSignalReceptionPositive(void)
308 TestApplication application;
310 Actor actor = Actor::New();
311 actor.SetProperty( Actor::Property::SIZE, Vector2( 100.0f, 100.0f ) );
312 actor.SetProperty( Actor::Property::ANCHOR_POINT,AnchorPoint::TOP_LEFT);
313 application.GetScene().Add(actor);
316 application.SendNotification();
317 application.Render();
320 GestureReceivedFunctor functor(data);
322 LongPressGestureDetector detector = LongPressGestureDetector::New();
323 detector.Attach(actor);
324 detector.DetectedSignal().Connect(&application, functor);
326 // Do a long press inside actor's area
327 TestGenerateLongPress( application, 50.0f, 50.0f );
328 DALI_TEST_EQUALS(true, data.functorCalled, TEST_LOCATION);
329 DALI_TEST_EQUALS(1u, data.receivedGesture.numberOfTouches, TEST_LOCATION);
330 DALI_TEST_EQUALS( Vector2(50.0f, 50.0f), data.receivedGesture.localPoint, 0.1, TEST_LOCATION);
331 TestEndLongPress( application, 50.0f, 50.0f);
335 int UtcDaliLongPressGestureSignalReceptionDetach(void)
337 TestApplication application;
339 Actor actor = Actor::New();
340 actor.SetProperty( Actor::Property::SIZE, Vector2( 100.0f, 100.0f ) );
341 actor.SetProperty( Actor::Property::ANCHOR_POINT,AnchorPoint::TOP_LEFT);
342 application.GetScene().Add(actor);
345 application.SendNotification();
346 application.Render();
349 GestureReceivedFunctor functor(data);
351 LongPressGestureDetector detector = LongPressGestureDetector::New();
352 detector.Attach(actor);
353 detector.DetectedSignal().Connect(&application, functor);
355 // Start long press within the actor's area
356 TestGenerateLongPress( application, 20.0f, 20.0f );
357 DALI_TEST_EQUALS(true, data.functorCalled, TEST_LOCATION);
358 DALI_TEST_EQUALS(1u, data.receivedGesture.numberOfTouches, TEST_LOCATION);
359 DALI_TEST_EQUALS( Vector2(20.0f, 20.0f), data.receivedGesture.localPoint, 0.1, TEST_LOCATION);
360 TestEndLongPress( application, 20.0f, 20.0f);
362 // repeat the long press within the actor's area - we should still receive the signal
364 TestGenerateLongPress( application, 50.0f, 50.0f );
365 DALI_TEST_EQUALS(true, data.functorCalled, TEST_LOCATION);
366 DALI_TEST_EQUALS(1u, data.receivedGesture.numberOfTouches, TEST_LOCATION);
367 DALI_TEST_EQUALS( Vector2(50.0f, 50.0f), data.receivedGesture.localPoint, 0.1, TEST_LOCATION);
368 TestEndLongPress( application, 50.0f, 50.0f);
371 detector.DetachAll();
373 // Ensure we are no longer signalled
375 TestGenerateLongPress( application, 20.0f, 20.0f );
376 DALI_TEST_EQUALS(false, data.functorCalled, TEST_LOCATION);
377 TestEndLongPress( application, 50.0f, 50.0f);
378 DALI_TEST_EQUALS(false, data.functorCalled, TEST_LOCATION);
382 int UtcDaliLongPressGestureSignalReceptionActorDestroyedDuringLongPress(void)
384 TestApplication application;
387 GestureReceivedFunctor functor(data);
389 LongPressGestureDetector detector = LongPressGestureDetector::New();
390 detector.DetectedSignal().Connect(&application, functor);
392 // Actor lifetime is scoped
394 Actor actor = Actor::New();
395 actor.SetProperty( Actor::Property::SIZE, Vector2( 100.0f, 100.0f ) );
396 actor.SetProperty( Actor::Property::ANCHOR_POINT,AnchorPoint::TOP_LEFT);
397 application.GetScene().Add(actor);
400 application.SendNotification();
401 application.Render();
403 detector.Attach(actor);
405 // Start long press within the actor's area
406 TestGenerateLongPress( application, 20.0f, 20.0f );
407 DALI_TEST_EQUALS(true, data.functorCalled, TEST_LOCATION);
409 // Remove the actor from stage and reset the data
410 application.GetScene().Remove(actor);
413 application.SendNotification();
414 application.Render();
417 // Actor should now have been destroyed
420 TestEndLongPress( application, 20.0f, 20.0f);
421 DALI_TEST_EQUALS(false, data.functorCalled, TEST_LOCATION);
425 int UtcDaliLongPressGestureSignalReceptionRotatedActor(void)
427 TestApplication application;
429 Actor actor = Actor::New();
430 actor.SetProperty( Actor::Property::SIZE, Vector2( 100.0f, 100.0f ) );
431 actor.SetProperty( Actor::Property::ORIENTATION, Quaternion( Dali::Degree(90.0f), Vector3::ZAXIS ) );
432 application.GetScene().Add(actor);
435 application.SendNotification();
436 application.Render();
439 GestureReceivedFunctor functor(data);
441 LongPressGestureDetector detector = LongPressGestureDetector::New();
442 detector.Attach(actor);
443 detector.DetectedSignal().Connect(&application, functor);
446 TestGenerateLongPress( application, 5.0f, 5.0f );
447 TestEndLongPress( application, 5.0f, 5.0f);
448 DALI_TEST_EQUALS(true, data.functorCalled, TEST_LOCATION);
449 DALI_TEST_EQUALS(1u, data.receivedGesture.numberOfTouches, TEST_LOCATION);
450 DALI_TEST_EQUALS( Vector2(5.0f, 5.0f), data.receivedGesture.screenPoint, 0.1, TEST_LOCATION);
452 // Rotate actor again and render
453 actor.SetProperty( Actor::Property::ORIENTATION, Quaternion(Dali::Degree(180.0f), Vector3::ZAXIS) );
454 application.SendNotification();
455 application.Render();
457 // Do another long press, should still receive event
459 TestGenerateLongPress( application, 5.0f, 5.0f );
460 TestEndLongPress( application, 5.0f, 5.0f);
461 DALI_TEST_EQUALS(true, data.functorCalled, TEST_LOCATION);
462 DALI_TEST_EQUALS(1u, data.receivedGesture.numberOfTouches, TEST_LOCATION);
463 DALI_TEST_EQUALS( Vector2(5.0f, 5.0f), data.receivedGesture.screenPoint, 0.1, TEST_LOCATION);
465 // Rotate actor again and render
466 actor.SetProperty( Actor::Property::ORIENTATION, Quaternion(Dali::Degree(90.0f), Vector3::YAXIS) );
467 application.SendNotification();
468 application.Render();
470 // Do a long press, inside where the actor used to be, Should not receive the event
472 TestGenerateLongPress( application, 70.0f, 70.0f );
473 TestEndLongPress( application, 70.0f, 70.0f);
474 DALI_TEST_EQUALS(false, data.functorCalled, TEST_LOCATION);
478 int UtcDaliLongPressGestureSignalReceptionChildHit(void)
480 TestApplication application;
482 Actor parent = Actor::New();
483 parent.SetProperty( Actor::Property::SIZE, Vector2( 100.0f, 100.0f ) );
484 parent.SetProperty( Actor::Property::ANCHOR_POINT,AnchorPoint::TOP_LEFT);
485 application.GetScene().Add(parent);
487 // Set child to completely cover parent.
488 // Change rotation of child to be different from parent so that we can check if our local coordinate
489 // conversion of the parent actor is correct.
490 Actor child = Actor::New();
491 child.SetProperty( Actor::Property::SIZE, Vector2( 100.0f, 100.0f ) );
492 child.SetProperty( Actor::Property::ANCHOR_POINT,AnchorPoint::CENTER);
493 child.SetProperty( Actor::Property::PARENT_ORIGIN,ParentOrigin::CENTER);
494 child.SetProperty( Actor::Property::ORIENTATION, Quaternion(Dali::Degree(90.0f), Vector3::ZAXIS) );
497 TouchEventFunctor touchFunctor;
498 child.TouchedSignal().Connect(&application, touchFunctor);
501 application.SendNotification();
502 application.Render();
505 GestureReceivedFunctor functor(data);
507 LongPressGestureDetector detector = LongPressGestureDetector::New();
508 detector.Attach(parent);
509 detector.DetectedSignal().Connect(&application, functor);
511 // Do long press - hits child area but parent should still receive it
512 TestGenerateLongPress( application, 50.0f, 50.0f );
513 TestEndLongPress( application, 50.0f, 50.0f);
514 DALI_TEST_EQUALS(true, data.functorCalled, TEST_LOCATION);
515 DALI_TEST_EQUALS(true, parent == data.pressedActor, TEST_LOCATION);
516 DALI_TEST_EQUALS(Vector2(50.0f, 50.0f), data.receivedGesture.screenPoint, 0.01f, TEST_LOCATION);
518 // Attach child and generate same touch points
519 // (Also proves that you can detach and then re-attach another actor)
520 detector.Attach(child);
521 detector.Detach(parent);
523 // Do an entire long press, only check finished value
525 TestGenerateLongPress( application, 51.0f, 51.0f );
526 TestEndLongPress( application, 51.0f, 51.0f);
527 DALI_TEST_EQUALS(true, data.functorCalled, TEST_LOCATION);
528 DALI_TEST_EQUALS(true, child == data.pressedActor, TEST_LOCATION);
529 DALI_TEST_EQUALS(Vector2(51.0f, 51.0f), data.receivedGesture.screenPoint, 0.01f, TEST_LOCATION);
533 int UtcDaliLongPressGestureSignalReceptionAttachDetachMany(void)
535 TestApplication application;
537 Actor first = Actor::New();
538 first.SetProperty( Actor::Property::SIZE, Vector2( 100.0f, 100.0f ) );
539 first.SetProperty( Actor::Property::ANCHOR_POINT,AnchorPoint::TOP_LEFT);
540 application.GetScene().Add(first);
542 Actor second = Actor::New();
543 second.SetProperty( Actor::Property::SIZE, Vector2( 100.0f, 100.0f ) );
544 second.SetProperty( Actor::Property::POSITION_X, 100.0f);
545 second.SetProperty( Actor::Property::ANCHOR_POINT,AnchorPoint::TOP_LEFT);
546 application.GetScene().Add(second);
549 application.SendNotification();
550 application.Render();
553 GestureReceivedFunctor functor(data);
555 LongPressGestureDetector detector = LongPressGestureDetector::New();
556 detector.Attach(first);
557 detector.Attach(second);
558 detector.DetectedSignal().Connect(&application, functor);
560 // LongPress within second actor's area
561 TestGenerateLongPress( application, 120.0f, 10.0f );
562 TestEndLongPress( application, 120.0f, 10.0f);
563 DALI_TEST_EQUALS(true, data.functorCalled, TEST_LOCATION);
564 DALI_TEST_EQUALS(true, second == data.pressedActor, TEST_LOCATION);
566 // LongPress within first actor's area
568 TestGenerateLongPress( application, 20.0f, 10.0f );
569 TestEndLongPress( application, 20.0f, 10.0f);
570 DALI_TEST_EQUALS(true, data.functorCalled, TEST_LOCATION);
571 DALI_TEST_EQUALS(true, first == data.pressedActor, TEST_LOCATION);
573 // Detach the second actor
574 detector.Detach(second);
576 // second actor shouldn't receive event
578 TestGenerateLongPress( application, 120.0f, 10.0f );
579 TestEndLongPress( application, 120.0f, 10.0f);
580 DALI_TEST_EQUALS(false, data.functorCalled, TEST_LOCATION);
582 // first actor should continue receiving event
584 TestGenerateLongPress( application, 20.0f, 10.0f );
585 TestEndLongPress( application, 20.0f, 10.0f);
586 DALI_TEST_EQUALS(true, data.functorCalled, TEST_LOCATION);
590 int UtcDaliLongPressGestureSignalReceptionActorBecomesUntouchable(void)
592 TestApplication application;
594 Actor actor = Actor::New();
595 actor.SetProperty( Actor::Property::SIZE, Vector2( 100.0f, 100.0f ) );
596 actor.SetProperty( Actor::Property::ANCHOR_POINT,AnchorPoint::TOP_LEFT);
597 application.GetScene().Add(actor);
600 application.SendNotification();
601 application.Render();
604 GestureReceivedFunctor functor(data);
606 LongPressGestureDetector detector = LongPressGestureDetector::New();
607 detector.Attach(actor);
608 detector.DetectedSignal().Connect(&application, functor);
610 // LongPress in actor's area
611 TestGenerateLongPress( application, 50.0f, 10.0f );
612 TestEndLongPress( application, 50.0f, 10.0f);
613 DALI_TEST_EQUALS(true, data.functorCalled, TEST_LOCATION);
615 // Actor becomes invisible - actor should not receive the next long press
616 actor.SetProperty( Actor::Property::VISIBLE,false);
619 application.SendNotification();
620 application.Render();
622 // LongPress in the same area, shouldn't receive event
624 TestGenerateLongPress( application, 50.0f, 10.0f );
625 TestEndLongPress( application, 50.0f, 10.0f);
626 DALI_TEST_EQUALS(false, data.functorCalled, TEST_LOCATION);
630 int UtcDaliLongPressGestureSignalReceptionMultipleDetectorsOnActor(void)
632 TestApplication application;
634 Actor actor = Actor::New();
635 actor.SetProperty( Actor::Property::SIZE, Vector2( 100.0f, 100.0f ) );
636 actor.SetProperty( Actor::Property::ANCHOR_POINT,AnchorPoint::TOP_LEFT);
637 application.GetScene().Add(actor);
640 application.SendNotification();
641 application.Render();
643 // Attach actor to one detector
644 SignalData firstData;
645 GestureReceivedFunctor firstFunctor(firstData);
646 LongPressGestureDetector firstDetector = LongPressGestureDetector::New();
647 firstDetector.Attach(actor);
648 firstDetector.DetectedSignal().Connect(&application, firstFunctor);
650 // Attach actor to another detector
651 SignalData secondData;
652 GestureReceivedFunctor secondFunctor(secondData);
653 LongPressGestureDetector secondDetector = LongPressGestureDetector::New();
654 secondDetector.Attach(actor);
655 secondDetector.DetectedSignal().Connect(&application, secondFunctor);
657 // LongPress in actor's area - both detector's functors should be called
658 TestGenerateLongPress( application, 50.0f, 10.0f );
659 DALI_TEST_EQUALS(true, firstData.functorCalled, TEST_LOCATION);
660 DALI_TEST_EQUALS(true, secondData.functorCalled, TEST_LOCATION);
664 int UtcDaliLongPressGestureSignalReceptionDifferentPossible(void)
666 TestApplication application;
668 Actor actor = Actor::New();
669 actor.SetProperty( Actor::Property::SIZE, Vector2( 100.0f, 100.0f ) );
670 actor.SetProperty( Actor::Property::ANCHOR_POINT,AnchorPoint::TOP_LEFT);
671 application.GetScene().Add(actor);
674 application.SendNotification();
675 application.Render();
677 // Attach actor to detector
679 GestureReceivedFunctor functor( data );
680 LongPressGestureDetector detector = LongPressGestureDetector::New();
681 detector.Attach(actor);
682 detector.DetectedSignal().Connect( &application, functor );
684 // LongPress possible in actor's area.
685 TestStartLongPress( application, 50.0f, 10.0f );
686 DALI_TEST_EQUALS(false, data.functorCalled, TEST_LOCATION);
688 // Move actor somewhere else
689 actor.SetProperty( Actor::Property::POSITION, Vector2( 100.0f, 100.0f ));
692 application.SendNotification();
693 application.Render();
695 // Emit Started event, we should not receive the long press.
696 TestTriggerLongPress( application );
697 TestGenerateLongPress( application, 50.0f, 10.0f );
698 DALI_TEST_EQUALS(false, data.functorCalled, TEST_LOCATION);
700 // LongPress possible in empty area.
701 TestStartLongPress( application, 50.0f, 10.0f );
702 DALI_TEST_EQUALS(false, data.functorCalled, TEST_LOCATION);
704 // Move actor in to the long press position.
705 actor.SetProperty( Actor::Property::POSITION, Vector2( 0.0f, 0.0f ));
708 application.SendNotification();
709 application.Render();
711 // Emit Started event, we should not receive the long press.
712 TestTriggerLongPress( application );
713 TestEndLongPress( application, 50.0f, 10.0f );
714 DALI_TEST_EQUALS(false, data.functorCalled, TEST_LOCATION);
716 // Normal long press in actor's area for completeness.
717 TestGenerateLongPress( application, 50.0f, 10.0f );
718 TestEndLongPress( application, 50.0f, 10.0f);
719 DALI_TEST_EQUALS(true, data.functorCalled, TEST_LOCATION);
723 int UtcDaliLongPressGesturePossibleCancelled(void)
725 TestApplication application;
727 Actor actor = Actor::New();
728 actor.SetProperty( Actor::Property::SIZE, Vector2( 100.0f, 100.0f ) );
729 actor.SetProperty( Actor::Property::ANCHOR_POINT,AnchorPoint::TOP_LEFT);
730 application.GetScene().Add(actor);
733 application.SendNotification();
734 application.Render();
736 // Attach actor to detector
738 GestureReceivedFunctor functor( data );
739 LongPressGestureDetector detector = LongPressGestureDetector::New();
740 detector.Attach(actor);
741 detector.DetectedSignal().Connect( &application, functor );
743 // Send a possible followed by a cancel, we should not be signalled
744 TestStartLongPress( application, 50.0f, 10.0f );
745 DALI_TEST_EQUALS(false, data.functorCalled, TEST_LOCATION);
746 TestMovePan( application, Vector2( 50.0f, 10.0f ) );
747 DALI_TEST_EQUALS(false, data.functorCalled, TEST_LOCATION);
751 int UtcDaliLongPressGestureDetachAfterStarted(void)
753 TestApplication application;
755 Actor actor = Actor::New();
756 actor.SetProperty( Actor::Property::SIZE, Vector2( 100.0f, 100.0f ) );
757 actor.SetProperty( Actor::Property::ANCHOR_POINT,AnchorPoint::TOP_LEFT);
758 application.GetScene().Add(actor);
761 application.SendNotification();
762 application.Render();
764 // Attach actor to detector
766 GestureReceivedFunctor functor( data );
767 LongPressGestureDetector detector = LongPressGestureDetector::New();
768 detector.Attach(actor);
769 detector.DetectedSignal().Connect( &application, functor );
771 // Emit initial signal
772 TestGenerateLongPress( application, 50.0f, 10.0f );
773 DALI_TEST_EQUALS(true, data.functorCalled, TEST_LOCATION);
777 detector.Detach(actor);
779 // Emit Finished, no signal
780 TestEndLongPress( application, 50.0f, 10.0f );
781 DALI_TEST_EQUALS(false, data.functorCalled, TEST_LOCATION);
785 int UtcDaliLongPressGestureActorUnstaged(void)
787 TestApplication application;
789 Actor actor = Actor::New();
790 actor.SetProperty( Actor::Property::SIZE, Vector2( 100.0f, 100.0f ) );
791 actor.SetProperty( Actor::Property::ANCHOR_POINT,AnchorPoint::TOP_LEFT);
792 application.GetScene().Add(actor);
795 application.SendNotification();
796 application.Render();
798 // State to remove actor in.
799 Gesture::State stateToUnstage( Gesture::Started );
801 // Attach actor to detector
803 UnstageActorFunctor functor( data, stateToUnstage, application.GetScene() );
804 LongPressGestureDetector detector = LongPressGestureDetector::New();
805 detector.Attach(actor);
806 detector.DetectedSignal().Connect( &application, functor );
809 TestGenerateLongPress( application, 50.0f, 10.0f );
810 DALI_TEST_EQUALS(true, data.functorCalled, TEST_LOCATION);
812 TestEndLongPress( application, 50.0f, 10.0f );
813 DALI_TEST_EQUALS(false, data.functorCalled, TEST_LOCATION);
816 application.SendNotification();
817 application.Render();
819 // Re-add actor to stage
820 application.GetScene().Add(actor);
823 application.SendNotification();
824 application.Render();
826 // Change state to Gesture::Continuing to remove
827 stateToUnstage = Gesture::Finished;
830 TestGenerateLongPress( application, 50.0f, 10.0f );
831 DALI_TEST_EQUALS(true, data.functorCalled, TEST_LOCATION);
833 TestEndLongPress( application, 50.0f, 10.0f );
834 DALI_TEST_EQUALS(true, data.functorCalled, TEST_LOCATION);
835 tet_result( TET_PASS ); // If we get here then we have handled actor stage removal gracefully.
839 int UtcDaliLongPressGestureActorStagedAndDestroyed(void)
841 TestApplication application;
843 Actor actor = Actor::New();
844 actor.SetProperty( Actor::Property::SIZE, Vector2( 100.0f, 100.0f ) );
845 actor.SetProperty( Actor::Property::ANCHOR_POINT,AnchorPoint::TOP_LEFT);
846 application.GetScene().Add(actor);
848 // Create and add a second actor so that GestureDetector destruction does not come into play.
849 Actor dummyActor( Actor::New() );
850 dummyActor.SetProperty( Actor::Property::SIZE, Vector2( 100.0f, 100.0f ) );
851 dummyActor.SetProperty( Actor::Property::POSITION, Vector2( 100.0f, 100.0f ));
852 dummyActor.SetProperty( Actor::Property::ANCHOR_POINT,AnchorPoint::TOP_LEFT);
853 application.GetScene().Add(dummyActor);
856 application.SendNotification();
857 application.Render();
859 // State to remove actor in.
860 Gesture::State stateToUnstage( Gesture::Started );
862 // Attach actor to detector
864 UnstageActorFunctor functor( data, stateToUnstage, application.GetScene() );
865 LongPressGestureDetector detector = LongPressGestureDetector::New();
866 detector.Attach(actor);
867 detector.Attach(dummyActor);
868 detector.DetectedSignal().Connect( &application, functor );
870 // Here we are testing a Started actor which is removed in the Started callback, but then added back
871 // before we get a finished state. As we were removed from the stage, even if we're at the same
872 // position, we should still not be signalled.
875 TestGenerateLongPress( application, 50.0f, 10.0f );
876 DALI_TEST_EQUALS(true, data.functorCalled, TEST_LOCATION);
880 application.SendNotification();
881 application.Render();
883 // Re add to the stage, we should not be signalled
884 application.GetScene().Add(actor);
887 application.SendNotification();
888 application.Render();
890 // Continue signal emission
891 TestEndLongPress( application, 50.0f, 10.0f );
892 DALI_TEST_EQUALS(false, data.functorCalled, TEST_LOCATION);
895 // Here we delete an actor in started, we should not receive any subsequent signalling.
898 TestGenerateLongPress( application, 50.0f, 10.0f );
899 DALI_TEST_EQUALS(true, data.functorCalled, TEST_LOCATION);
903 application.SendNotification();
904 application.Render();
906 // Delete actor as well
910 application.SendNotification();
911 application.Render();
913 // Continue signal emission
914 TestEndLongPress( application, 50.0f, 10.0f );
915 DALI_TEST_EQUALS(false, data.functorCalled, TEST_LOCATION);
919 int UtcDaliLongPressGestureLayerConsumesTouch(void)
921 TestApplication application;
923 Actor actor = Actor::New();
924 actor.SetProperty( Actor::Property::SIZE, Vector2( 100.0f, 100.0f ) );
925 actor.SetProperty( Actor::Property::ANCHOR_POINT,AnchorPoint::TOP_LEFT);
926 application.GetScene().Add(actor);
930 GestureReceivedFunctor functor(data);
931 LongPressGestureDetector detector = LongPressGestureDetector::New();
932 detector.Attach(actor);
933 detector.DetectedSignal().Connect( &application, functor );
935 // Add a layer to overlap the actor
936 Layer layer = Layer::New();
937 layer.SetProperty( Actor::Property::SIZE, Vector2( 100.0f, 100.0f ) );
938 layer.SetProperty( Actor::Property::ANCHOR_POINT,AnchorPoint::TOP_LEFT);
939 application.GetScene().Add( layer );
943 application.SendNotification();
944 application.Render();
946 // Emit signals, should receive
947 TestGenerateLongPress( application, 50.0f, 50.0f );
948 TestEndLongPress( application, 50.0f, 50.0f );
949 DALI_TEST_EQUALS(true, data.functorCalled, TEST_LOCATION);
952 // Set layer to consume all touch
953 layer.SetProperty( Layer::Property::CONSUMES_TOUCH, true );
956 application.SendNotification();
957 application.Render();
959 // Emit the same signals again, should not receive
960 TestGenerateLongPress( application, 50.0f, 50.0f );
961 TestEndLongPress( application, 50.0f, 50.0f );
962 DALI_TEST_EQUALS(false, data.functorCalled, TEST_LOCATION);
968 int UtcDaliLongPressGestureSetMinimumHoldingTime(void)
970 TestApplication application;
972 const uint32_t kMinumumHolding1 = 5000;
973 const uint32_t kMinumumHolding2 = 3000;
975 Integration::SetLongPressMinimumHoldingTime( kMinumumHolding1 );
977 Actor actor = Actor::New();
978 actor.SetProperty( Actor::Property::SIZE, Vector2( 100.0f, 100.0f ) );
979 actor.SetProperty( Actor::Property::ANCHOR_POINT, AnchorPoint::TOP_LEFT );
980 application.GetScene().Add( actor );
983 application.SendNotification();
984 application.Render();
987 GestureReceivedFunctor functor( data );
989 LongPressGestureDetector detector = LongPressGestureDetector::New();
990 detector.Attach(actor);
991 detector.DetectedSignal().Connect(&application, functor);
993 DALI_TEST_EQUALS( DevelLongPressGestureDetector::GetMinimumHoldingTime( detector ), kMinumumHolding1, TEST_LOCATION );
995 Integration::SetLongPressMinimumHoldingTime( kMinumumHolding2 );
996 DALI_TEST_EQUALS( DevelLongPressGestureDetector::GetMinimumHoldingTime( detector ), kMinumumHolding2, TEST_LOCATION );
1001 int UtcDaliLongPressGestureInterruptedWhenTouchConsumed(void)
1003 TestApplication application;
1005 Actor actor = Actor::New();
1006 actor.SetProperty( Actor::Property::SIZE, Vector2( 100.0f, 100.0f ) );
1007 actor.SetProperty( Actor::Property::ANCHOR_POINT,AnchorPoint::TOP_LEFT);
1008 application.GetScene().Add(actor);
1010 bool consume = false;
1011 TouchDataFunctorConsumeSetter touchFunctor(consume);
1012 actor.TouchSignal().Connect(&application,touchFunctor);
1014 // Render and notify
1015 application.SendNotification();
1016 application.Render();
1019 GestureReceivedFunctor functor(data);
1021 LongPressGestureDetector detector = LongPressGestureDetector::New();
1022 detector.Attach(actor);
1023 detector.DetectedSignal().Connect(&application, functor);
1025 // Start gesture within the actor's area, we should receive the gesture as the touch is NOT being consumed
1026 TestGenerateLongPress( application, 50.0f, 50.0f );
1027 DALI_TEST_EQUALS(true, data.functorCalled, TEST_LOCATION);
1029 TestEndLongPress(application, 50.0f,50.0f);
1030 DALI_TEST_EQUALS(true, data.functorCalled, TEST_LOCATION);
1033 // Another gesture in the same location, this time we will not receive it as touch is being consumed
1035 TestGenerateLongPress( application, 50.0f, 50.0f );
1036 DALI_TEST_EQUALS(false, data.functorCalled, TEST_LOCATION);
1038 TestEndLongPress(application, 50.0f,50.0f);
1039 DALI_TEST_EQUALS(false, data.functorCalled, TEST_LOCATION);