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-event-utils.h>
31 void utc_dali_long_press_gesture_detector_startup(void)
33 test_return_value = TET_UNDEF;
36 void utc_dali_long_press_gesture_detector_cleanup(void)
38 test_return_value = TET_PASS;
41 ///////////////////////////////////////////////////////////////////////////////
45 // Stores data that is populated in the callback and will be read by the TET cases
49 : functorCalled( false ),
50 voidFunctorCalled( false ),
57 functorCalled = false;
58 voidFunctorCalled = false;
60 receivedGesture.Reset();
66 bool voidFunctorCalled;
67 LongPressGesture receivedGesture;
71 // Functor that sets the data when called
72 struct GestureReceivedFunctor
74 GestureReceivedFunctor(SignalData& data) : signalData(data) { }
76 void operator()(Actor actor, const LongPressGesture& longPress)
78 signalData.functorCalled = true;
79 signalData.receivedGesture = longPress;
80 signalData.pressedActor = actor;
85 signalData.voidFunctorCalled = true;
88 SignalData& signalData;
91 // Functor that removes the gestured actor from stage
92 struct UnstageActorFunctor : public GestureReceivedFunctor
94 UnstageActorFunctor( SignalData& data, GestureState& stateToUnstage, Integration::Scene scene )
95 : GestureReceivedFunctor( data ),
96 stateToUnstage( stateToUnstage ),
101 void operator()( Actor actor, const LongPressGesture& longPress )
103 GestureReceivedFunctor::operator()( actor, longPress );
105 if ( longPress.GetState() == stateToUnstage )
107 scene.Remove( actor );
111 GestureState& stateToUnstage;
112 Integration::Scene scene;
115 // Functor for receiving a touch event
116 struct TouchEventFunctor
118 bool operator()(Actor actor, Dali::TouchEvent touch)
121 unsigned int points = touch.GetPointCount();
124 tet_printf("Touch Point state = %d\n", touch.GetState(0));
132 ///////////////////////////////////////////////////////////////////////////////
135 // Positive test case for a method
136 int UtcDaliLongPressGestureDetectorConstructorP(void)
138 TestApplication application;
140 LongPressGestureDetector detector;
141 DALI_TEST_CHECK(!detector);
145 int UtcDaliLongPressGestureDetectorCopyConstructorP(void)
147 TestApplication application;
149 LongPressGestureDetector detector = LongPressGestureDetector::New();;
151 LongPressGestureDetector copy( detector );
152 DALI_TEST_CHECK( detector );
156 int UtcDaliLongPressGestureDetectorAssignmentOperatorP(void)
158 TestApplication application;
160 LongPressGestureDetector detector;
161 detector = LongPressGestureDetector::New();;
163 LongPressGestureDetector copy;
165 DALI_TEST_CHECK( detector );
167 DALI_TEST_CHECK( detector == copy );
171 int UtcDaliLongPressGestureDetectorNew(void)
173 TestApplication application;
175 LongPressGestureDetector detector = LongPressGestureDetector::New();
176 DALI_TEST_CHECK(detector);
177 DALI_TEST_EQUALS(1u, detector.GetMinimumTouchesRequired(), TEST_LOCATION);
178 DALI_TEST_EQUALS(1u, detector.GetMaximumTouchesRequired(), TEST_LOCATION);
180 LongPressGestureDetector detector2 = LongPressGestureDetector::New(5u);
181 DALI_TEST_CHECK(detector2);
182 DALI_TEST_EQUALS(5u, detector2.GetMinimumTouchesRequired(), TEST_LOCATION);
183 DALI_TEST_EQUALS(5u, detector2.GetMaximumTouchesRequired(), TEST_LOCATION);
185 LongPressGestureDetector detector3 = LongPressGestureDetector::New(5u, 7u);
186 DALI_TEST_CHECK(detector2);
187 DALI_TEST_EQUALS(5u, detector3.GetMinimumTouchesRequired(), TEST_LOCATION);
188 DALI_TEST_EQUALS(7u, detector3.GetMaximumTouchesRequired(), TEST_LOCATION);
190 //Scoped test to test destructor
192 LongPressGestureDetector detector4 = LongPressGestureDetector::New();
193 DALI_TEST_CHECK(detector4);
196 // Attach an actor and emit a touch event on the actor to ensure complete line coverage
197 Actor actor = Actor::New();
198 actor.SetProperty( Actor::Property::SIZE, Vector2( 100.0f, 100.0f ) );
199 actor.SetProperty( Actor::Property::ANCHOR_POINT,AnchorPoint::TOP_LEFT);
200 application.GetScene().Add(actor);
203 application.SendNotification();
204 application.Render();
206 detector.Attach(actor);
208 TouchEventFunctor touchFunctor;
209 actor.TouchedSignal().Connect(&application, touchFunctor);
211 Integration::TouchEvent touchEvent(1);
212 Integration::Point point;
213 point.SetDeviceId( 1 );
214 point.SetState( PointState::DOWN );
215 point.SetScreenPosition( Vector2( 20.0f, 20.0f ) );
216 touchEvent.AddPoint(point);
217 application.ProcessEvent(touchEvent);
220 application.SendNotification();
221 application.Render();
226 int UtcDaliLongPressGestureDetectorDownCast(void)
228 TestApplication application;
229 tet_infoline("Testing Dali::LongPressGestureDetector::DownCast()");
231 LongPressGestureDetector detector = LongPressGestureDetector::New();
233 BaseHandle object(detector);
235 LongPressGestureDetector detector2 = LongPressGestureDetector::DownCast(object);
236 DALI_TEST_CHECK(detector2);
238 LongPressGestureDetector detector3 = DownCast< LongPressGestureDetector >(object);
239 DALI_TEST_CHECK(detector3);
241 BaseHandle unInitializedObject;
242 LongPressGestureDetector detector4 = LongPressGestureDetector::DownCast(unInitializedObject);
243 DALI_TEST_CHECK(!detector4);
245 LongPressGestureDetector detector5 = DownCast< LongPressGestureDetector >(unInitializedObject);
246 DALI_TEST_CHECK(!detector5);
248 GestureDetector detector6 = LongPressGestureDetector::New();
249 LongPressGestureDetector detector7 = LongPressGestureDetector::DownCast(detector6);
250 DALI_TEST_CHECK(detector7);
254 int UtcDaliLongPressGestureGetMinimumTouchesRequired(void)
256 TestApplication application;
258 LongPressGestureDetector detector = LongPressGestureDetector::New();
259 DALI_TEST_EQUALS(1u, detector.GetMinimumTouchesRequired(), TEST_LOCATION);
263 int UtcDaliLongPressGestureGetMaximumTouchesRequired(void)
265 TestApplication application;
267 LongPressGestureDetector detector = LongPressGestureDetector::New();
268 DALI_TEST_EQUALS(1u, detector.GetMaximumTouchesRequired(), TEST_LOCATION);
272 int UtcDaliLongPressGestureSignalReceptionNegative(void)
274 TestApplication application;
276 Actor actor = Actor::New();
277 actor.SetProperty( Actor::Property::SIZE, Vector2( 100.0f, 100.0f ) );
278 actor.SetProperty( Actor::Property::ANCHOR_POINT,AnchorPoint::TOP_LEFT);
279 application.GetScene().Add(actor);
282 application.SendNotification();
283 application.Render();
286 GestureReceivedFunctor functor(data);
288 LongPressGestureDetector detector = LongPressGestureDetector::New();
289 detector.Attach(actor);
290 detector.DetectedSignal().Connect(&application, functor);
292 // Do a long press outside actor's area
293 TestGenerateLongPress( application, 112.0f, 112.0f );
294 TestEndLongPress( application, 112.0f, 112.0f);
296 DALI_TEST_EQUALS(false, data.functorCalled, TEST_LOCATION);
300 int UtcDaliLongPressGestureSignalReceptionPositive(void)
302 TestApplication application;
304 Actor actor = Actor::New();
305 actor.SetProperty( Actor::Property::SIZE, Vector2( 100.0f, 100.0f ) );
306 actor.SetProperty( Actor::Property::ANCHOR_POINT,AnchorPoint::TOP_LEFT);
307 application.GetScene().Add(actor);
310 application.SendNotification();
311 application.Render();
314 GestureReceivedFunctor functor(data);
316 LongPressGestureDetector detector = LongPressGestureDetector::New();
317 detector.Attach(actor);
318 detector.DetectedSignal().Connect(&application, functor);
320 // Do a long press inside actor's area
321 TestGenerateLongPress( application, 50.0f, 50.0f );
322 DALI_TEST_EQUALS(true, data.functorCalled, TEST_LOCATION);
323 DALI_TEST_EQUALS(1u, data.receivedGesture.GetNumberOfTouches(), TEST_LOCATION);
324 DALI_TEST_EQUALS( Vector2(50.0f, 50.0f), data.receivedGesture.GetLocalPoint(), 0.1, TEST_LOCATION);
325 TestEndLongPress( application, 50.0f, 50.0f);
329 int UtcDaliLongPressGestureSignalReceptionDetach(void)
331 TestApplication application;
333 Actor actor = Actor::New();
334 actor.SetProperty( Actor::Property::SIZE, Vector2( 100.0f, 100.0f ) );
335 actor.SetProperty( Actor::Property::ANCHOR_POINT,AnchorPoint::TOP_LEFT);
336 application.GetScene().Add(actor);
339 application.SendNotification();
340 application.Render();
343 GestureReceivedFunctor functor(data);
345 LongPressGestureDetector detector = LongPressGestureDetector::New();
346 detector.Attach(actor);
347 detector.DetectedSignal().Connect(&application, functor);
349 // Start long press within the actor's area
350 TestGenerateLongPress( application, 20.0f, 20.0f );
351 DALI_TEST_EQUALS(true, data.functorCalled, TEST_LOCATION);
352 DALI_TEST_EQUALS(1u, data.receivedGesture.GetNumberOfTouches(), TEST_LOCATION);
353 DALI_TEST_EQUALS( Vector2(20.0f, 20.0f), data.receivedGesture.GetLocalPoint(), 0.1, TEST_LOCATION);
354 TestEndLongPress( application, 20.0f, 20.0f);
356 // repeat the long press within the actor's area - we should still receive the signal
358 TestGenerateLongPress( application, 50.0f, 50.0f );
359 DALI_TEST_EQUALS(true, data.functorCalled, TEST_LOCATION);
360 DALI_TEST_EQUALS(1u, data.receivedGesture.GetNumberOfTouches(), TEST_LOCATION);
361 DALI_TEST_EQUALS( Vector2(50.0f, 50.0f), data.receivedGesture.GetLocalPoint(), 0.1, TEST_LOCATION);
362 TestEndLongPress( application, 50.0f, 50.0f);
365 detector.DetachAll();
367 // Ensure we are no longer signalled
369 TestGenerateLongPress( application, 20.0f, 20.0f );
370 DALI_TEST_EQUALS(false, data.functorCalled, TEST_LOCATION);
371 TestEndLongPress( application, 50.0f, 50.0f);
372 DALI_TEST_EQUALS(false, data.functorCalled, TEST_LOCATION);
376 int UtcDaliLongPressGestureSignalReceptionActorDestroyedDuringLongPress(void)
378 TestApplication application;
381 GestureReceivedFunctor functor(data);
383 LongPressGestureDetector detector = LongPressGestureDetector::New();
384 detector.DetectedSignal().Connect(&application, functor);
386 // Actor lifetime is scoped
388 Actor actor = Actor::New();
389 actor.SetProperty( Actor::Property::SIZE, Vector2( 100.0f, 100.0f ) );
390 actor.SetProperty( Actor::Property::ANCHOR_POINT,AnchorPoint::TOP_LEFT);
391 application.GetScene().Add(actor);
394 application.SendNotification();
395 application.Render();
397 detector.Attach(actor);
399 // Start long press within the actor's area
400 TestGenerateLongPress( application, 20.0f, 20.0f );
401 DALI_TEST_EQUALS(true, data.functorCalled, TEST_LOCATION);
403 // Remove the actor from stage and reset the data
404 application.GetScene().Remove(actor);
407 application.SendNotification();
408 application.Render();
411 // Actor should now have been destroyed
414 TestEndLongPress( application, 20.0f, 20.0f);
415 DALI_TEST_EQUALS(false, data.functorCalled, TEST_LOCATION);
419 int UtcDaliLongPressGestureSignalReceptionRotatedActor(void)
421 TestApplication application;
423 Actor actor = Actor::New();
424 actor.SetProperty( Actor::Property::SIZE, Vector2( 100.0f, 100.0f ) );
425 actor.SetProperty( Actor::Property::ORIENTATION, Quaternion( Dali::Degree(90.0f), Vector3::ZAXIS ) );
426 application.GetScene().Add(actor);
429 application.SendNotification();
430 application.Render();
433 GestureReceivedFunctor functor(data);
435 LongPressGestureDetector detector = LongPressGestureDetector::New();
436 detector.Attach(actor);
437 detector.DetectedSignal().Connect(&application, functor);
440 TestGenerateLongPress( application, 5.0f, 5.0f );
441 TestEndLongPress( application, 5.0f, 5.0f);
442 DALI_TEST_EQUALS(true, data.functorCalled, TEST_LOCATION);
443 DALI_TEST_EQUALS(1u, data.receivedGesture.GetNumberOfTouches(), TEST_LOCATION);
444 DALI_TEST_EQUALS( Vector2(5.0f, 5.0f), data.receivedGesture.GetScreenPoint(), 0.1, TEST_LOCATION);
446 // Rotate actor again and render
447 actor.SetProperty( Actor::Property::ORIENTATION, Quaternion(Dali::Degree(180.0f), Vector3::ZAXIS) );
448 application.SendNotification();
449 application.Render();
451 // Do another long press, should still receive event
453 TestGenerateLongPress( application, 5.0f, 5.0f );
454 TestEndLongPress( application, 5.0f, 5.0f);
455 DALI_TEST_EQUALS(true, data.functorCalled, TEST_LOCATION);
456 DALI_TEST_EQUALS(1u, data.receivedGesture.GetNumberOfTouches(), TEST_LOCATION);
457 DALI_TEST_EQUALS( Vector2(5.0f, 5.0f), data.receivedGesture.GetScreenPoint(), 0.1, TEST_LOCATION);
459 // Rotate actor again and render
460 actor.SetProperty( Actor::Property::ORIENTATION, Quaternion(Dali::Degree(90.0f), Vector3::YAXIS) );
461 application.SendNotification();
462 application.Render();
464 // Do a long press, inside where the actor used to be, Should not receive the event
466 TestGenerateLongPress( application, 70.0f, 70.0f );
467 TestEndLongPress( application, 70.0f, 70.0f);
468 DALI_TEST_EQUALS(false, data.functorCalled, TEST_LOCATION);
472 int UtcDaliLongPressGestureSignalReceptionChildHit(void)
474 TestApplication application;
476 Actor parent = Actor::New();
477 parent.SetProperty( Actor::Property::SIZE, Vector2( 100.0f, 100.0f ) );
478 parent.SetProperty( Actor::Property::ANCHOR_POINT,AnchorPoint::TOP_LEFT);
479 application.GetScene().Add(parent);
481 // Set child to completely cover parent.
482 // Change rotation of child to be different from parent so that we can check if our local coordinate
483 // conversion of the parent actor is correct.
484 Actor child = Actor::New();
485 child.SetProperty( Actor::Property::SIZE, Vector2( 100.0f, 100.0f ) );
486 child.SetProperty( Actor::Property::ANCHOR_POINT,AnchorPoint::CENTER);
487 child.SetProperty( Actor::Property::PARENT_ORIGIN,ParentOrigin::CENTER);
488 child.SetProperty( Actor::Property::ORIENTATION, Quaternion(Dali::Degree(90.0f), Vector3::ZAXIS) );
492 application.SendNotification();
493 application.Render();
496 GestureReceivedFunctor functor(data);
498 LongPressGestureDetector detector = LongPressGestureDetector::New();
499 detector.Attach(parent);
500 detector.DetectedSignal().Connect(&application, functor);
502 // Do long press - hits child area but parent should still receive it
503 TestGenerateLongPress( application, 50.0f, 50.0f );
504 TestEndLongPress( application, 50.0f, 50.0f);
505 DALI_TEST_EQUALS(true, data.functorCalled, TEST_LOCATION);
506 DALI_TEST_EQUALS(true, parent == data.pressedActor, TEST_LOCATION);
507 DALI_TEST_EQUALS(Vector2(50.0f, 50.0f), data.receivedGesture.GetScreenPoint(), 0.01f, TEST_LOCATION);
509 // Attach child and generate same touch points
510 // (Also proves that you can detach and then re-attach another actor)
511 detector.Attach(child);
512 detector.Detach(parent);
514 // Do an entire long press, only check finished value
516 TestGenerateLongPress( application, 51.0f, 51.0f );
517 TestEndLongPress( application, 51.0f, 51.0f);
518 DALI_TEST_EQUALS(true, data.functorCalled, TEST_LOCATION);
519 DALI_TEST_EQUALS(true, child == data.pressedActor, TEST_LOCATION);
520 DALI_TEST_EQUALS(Vector2(51.0f, 51.0f), data.receivedGesture.GetScreenPoint(), 0.01f, TEST_LOCATION);
524 int UtcDaliLongPressGestureSignalReceptionAttachDetachMany(void)
526 TestApplication application;
528 Actor first = Actor::New();
529 first.SetProperty( Actor::Property::SIZE, Vector2( 100.0f, 100.0f ) );
530 first.SetProperty( Actor::Property::ANCHOR_POINT,AnchorPoint::TOP_LEFT);
531 application.GetScene().Add(first);
533 Actor second = Actor::New();
534 second.SetProperty( Actor::Property::SIZE, Vector2( 100.0f, 100.0f ) );
535 second.SetProperty( Actor::Property::POSITION_X, 100.0f);
536 second.SetProperty( Actor::Property::ANCHOR_POINT,AnchorPoint::TOP_LEFT);
537 application.GetScene().Add(second);
540 application.SendNotification();
541 application.Render();
544 GestureReceivedFunctor functor(data);
546 LongPressGestureDetector detector = LongPressGestureDetector::New();
547 detector.Attach(first);
548 detector.Attach(second);
549 detector.DetectedSignal().Connect(&application, functor);
551 // LongPress within second actor's area
552 TestGenerateLongPress( application, 120.0f, 10.0f );
553 TestEndLongPress( application, 120.0f, 10.0f);
554 DALI_TEST_EQUALS(true, data.functorCalled, TEST_LOCATION);
555 DALI_TEST_EQUALS(true, second == data.pressedActor, TEST_LOCATION);
557 // LongPress within first actor's area
559 TestGenerateLongPress( application, 20.0f, 10.0f );
560 TestEndLongPress( application, 20.0f, 10.0f);
561 DALI_TEST_EQUALS(true, data.functorCalled, TEST_LOCATION);
562 DALI_TEST_EQUALS(true, first == data.pressedActor, TEST_LOCATION);
564 // Detach the second actor
565 detector.Detach(second);
567 // second actor shouldn't receive event
569 TestGenerateLongPress( application, 120.0f, 10.0f );
570 TestEndLongPress( application, 120.0f, 10.0f);
571 DALI_TEST_EQUALS(false, data.functorCalled, TEST_LOCATION);
573 // first actor should continue receiving event
575 TestGenerateLongPress( application, 20.0f, 10.0f );
576 TestEndLongPress( application, 20.0f, 10.0f);
577 DALI_TEST_EQUALS(true, data.functorCalled, TEST_LOCATION);
581 int UtcDaliLongPressGestureSignalReceptionActorBecomesUntouchable(void)
583 TestApplication application;
585 Actor actor = Actor::New();
586 actor.SetProperty( Actor::Property::SIZE, Vector2( 100.0f, 100.0f ) );
587 actor.SetProperty( Actor::Property::ANCHOR_POINT,AnchorPoint::TOP_LEFT);
588 application.GetScene().Add(actor);
591 application.SendNotification();
592 application.Render();
595 GestureReceivedFunctor functor(data);
597 LongPressGestureDetector detector = LongPressGestureDetector::New();
598 detector.Attach(actor);
599 detector.DetectedSignal().Connect(&application, functor);
601 // LongPress in actor's area
602 TestGenerateLongPress( application, 50.0f, 10.0f );
603 TestEndLongPress( application, 50.0f, 10.0f);
604 DALI_TEST_EQUALS(true, data.functorCalled, TEST_LOCATION);
606 // Actor becomes invisible - actor should not receive the next long press
607 actor.SetProperty( Actor::Property::VISIBLE,false);
610 application.SendNotification();
611 application.Render();
613 // LongPress in the same area, shouldn't receive event
615 TestGenerateLongPress( application, 50.0f, 10.0f );
616 TestEndLongPress( application, 50.0f, 10.0f);
617 DALI_TEST_EQUALS(false, data.functorCalled, TEST_LOCATION);
621 int UtcDaliLongPressGestureSignalReceptionMultipleDetectorsOnActor(void)
623 TestApplication application;
625 Actor actor = Actor::New();
626 actor.SetProperty( Actor::Property::SIZE, Vector2( 100.0f, 100.0f ) );
627 actor.SetProperty( Actor::Property::ANCHOR_POINT,AnchorPoint::TOP_LEFT);
628 application.GetScene().Add(actor);
631 application.SendNotification();
632 application.Render();
634 // Attach actor to one detector
635 SignalData firstData;
636 GestureReceivedFunctor firstFunctor(firstData);
637 LongPressGestureDetector firstDetector = LongPressGestureDetector::New();
638 firstDetector.Attach(actor);
639 firstDetector.DetectedSignal().Connect(&application, firstFunctor);
641 // Attach actor to another detector
642 SignalData secondData;
643 GestureReceivedFunctor secondFunctor(secondData);
644 LongPressGestureDetector secondDetector = LongPressGestureDetector::New();
645 secondDetector.Attach(actor);
646 secondDetector.DetectedSignal().Connect(&application, secondFunctor);
648 // LongPress in actor's area - both detector's functors should be called
649 TestGenerateLongPress( application, 50.0f, 10.0f );
650 DALI_TEST_EQUALS(true, firstData.functorCalled, TEST_LOCATION);
651 DALI_TEST_EQUALS(true, secondData.functorCalled, TEST_LOCATION);
655 int UtcDaliLongPressGestureSignalReceptionDifferentPossible(void)
657 TestApplication application;
659 Actor actor = Actor::New();
660 actor.SetProperty( Actor::Property::SIZE, Vector2( 100.0f, 100.0f ) );
661 actor.SetProperty( Actor::Property::ANCHOR_POINT,AnchorPoint::TOP_LEFT);
662 application.GetScene().Add(actor);
665 application.SendNotification();
666 application.Render();
668 // Attach actor to detector
670 GestureReceivedFunctor functor( data );
671 LongPressGestureDetector detector = LongPressGestureDetector::New();
672 detector.Attach(actor);
673 detector.DetectedSignal().Connect( &application, functor );
675 // LongPress possible in actor's area.
676 TestStartLongPress( application, 50.0f, 10.0f );
677 DALI_TEST_EQUALS(false, data.functorCalled, TEST_LOCATION);
679 // Move actor somewhere else
680 actor.SetProperty( Actor::Property::POSITION, Vector2( 100.0f, 100.0f ));
683 application.SendNotification();
684 application.Render();
686 // Emit Started event, we should not receive the long press.
687 TestTriggerLongPress( application );
688 TestGenerateLongPress( application, 50.0f, 10.0f );
689 DALI_TEST_EQUALS(false, data.functorCalled, TEST_LOCATION);
691 // LongPress possible in empty area.
692 TestStartLongPress( application, 50.0f, 10.0f );
693 DALI_TEST_EQUALS(false, data.functorCalled, TEST_LOCATION);
695 // Move actor in to the long press position.
696 actor.SetProperty( Actor::Property::POSITION, Vector2( 0.0f, 0.0f ));
699 application.SendNotification();
700 application.Render();
702 // Emit STARTED event, we should not receive the long press.
703 TestTriggerLongPress( application );
704 TestEndLongPress( application, 50.0f, 10.0f );
705 DALI_TEST_EQUALS(false, data.functorCalled, TEST_LOCATION);
707 // Normal long press in actor's area for completeness.
708 TestGenerateLongPress( application, 50.0f, 10.0f );
709 TestEndLongPress( application, 50.0f, 10.0f);
710 DALI_TEST_EQUALS(true, data.functorCalled, TEST_LOCATION);
714 int UtcDaliLongPressGesturePossibleCancelled(void)
716 TestApplication application;
718 Actor actor = Actor::New();
719 actor.SetProperty( Actor::Property::SIZE, Vector2( 100.0f, 100.0f ) );
720 actor.SetProperty( Actor::Property::ANCHOR_POINT,AnchorPoint::TOP_LEFT);
721 application.GetScene().Add(actor);
724 application.SendNotification();
725 application.Render();
727 // Attach actor to detector
729 GestureReceivedFunctor functor( data );
730 LongPressGestureDetector detector = LongPressGestureDetector::New();
731 detector.Attach(actor);
732 detector.DetectedSignal().Connect( &application, functor );
734 // Send a possible followed by a cancel, we should not be signalled
735 TestStartLongPress( application, 50.0f, 10.0f );
736 DALI_TEST_EQUALS(false, data.functorCalled, TEST_LOCATION);
737 TestMovePan( application, Vector2( 50.0f, 10.0f ) );
738 DALI_TEST_EQUALS(false, data.functorCalled, TEST_LOCATION);
742 int UtcDaliLongPressGestureDetachAfterStarted(void)
744 TestApplication application;
746 Actor actor = Actor::New();
747 actor.SetProperty( Actor::Property::SIZE, Vector2( 100.0f, 100.0f ) );
748 actor.SetProperty( Actor::Property::ANCHOR_POINT,AnchorPoint::TOP_LEFT);
749 application.GetScene().Add(actor);
752 application.SendNotification();
753 application.Render();
755 // Attach actor to detector
757 GestureReceivedFunctor functor( data );
758 LongPressGestureDetector detector = LongPressGestureDetector::New();
759 detector.Attach(actor);
760 detector.DetectedSignal().Connect( &application, functor );
762 // Emit initial signal
763 TestGenerateLongPress( application, 50.0f, 10.0f );
764 DALI_TEST_EQUALS(true, data.functorCalled, TEST_LOCATION);
768 detector.Detach(actor);
770 // Emit FINISHED, no signal
771 TestEndLongPress( application, 50.0f, 10.0f );
772 DALI_TEST_EQUALS(false, data.functorCalled, TEST_LOCATION);
776 int UtcDaliLongPressGestureActorUnstaged(void)
778 TestApplication application;
780 Actor actor = Actor::New();
781 actor.SetProperty( Actor::Property::SIZE, Vector2( 100.0f, 100.0f ) );
782 actor.SetProperty( Actor::Property::ANCHOR_POINT,AnchorPoint::TOP_LEFT);
783 application.GetScene().Add(actor);
786 application.SendNotification();
787 application.Render();
789 // State to remove actor in.
790 GestureState stateToUnstage( GestureState::STARTED );
792 // Attach actor to detector
794 UnstageActorFunctor functor( data, stateToUnstage, application.GetScene() );
795 LongPressGestureDetector detector = LongPressGestureDetector::New();
796 detector.Attach(actor);
797 detector.DetectedSignal().Connect( &application, functor );
800 TestGenerateLongPress( application, 50.0f, 10.0f );
801 DALI_TEST_EQUALS(true, data.functorCalled, TEST_LOCATION);
803 TestEndLongPress( application, 50.0f, 10.0f );
804 DALI_TEST_EQUALS(false, data.functorCalled, TEST_LOCATION);
807 application.SendNotification();
808 application.Render();
810 // Re-add actor to stage
811 application.GetScene().Add(actor);
814 application.SendNotification();
815 application.Render();
817 // Change state to GestureState::CONTINUING to remove
818 stateToUnstage = GestureState::FINISHED;
821 TestGenerateLongPress( application, 50.0f, 10.0f );
822 DALI_TEST_EQUALS(true, data.functorCalled, TEST_LOCATION);
824 TestEndLongPress( application, 50.0f, 10.0f );
825 DALI_TEST_EQUALS(true, data.functorCalled, TEST_LOCATION);
826 tet_result( TET_PASS ); // If we get here then we have handled actor stage removal gracefully.
830 int UtcDaliLongPressGestureActorStagedAndDestroyed(void)
832 TestApplication application;
834 Actor actor = Actor::New();
835 actor.SetProperty( Actor::Property::SIZE, Vector2( 100.0f, 100.0f ) );
836 actor.SetProperty( Actor::Property::ANCHOR_POINT,AnchorPoint::TOP_LEFT);
837 application.GetScene().Add(actor);
839 // Create and add a second actor so that GestureDetector destruction does not come into play.
840 Actor dummyActor( Actor::New() );
841 dummyActor.SetProperty( Actor::Property::SIZE, Vector2( 100.0f, 100.0f ) );
842 dummyActor.SetProperty( Actor::Property::POSITION, Vector2( 100.0f, 100.0f ));
843 dummyActor.SetProperty( Actor::Property::ANCHOR_POINT,AnchorPoint::TOP_LEFT);
844 application.GetScene().Add(dummyActor);
847 application.SendNotification();
848 application.Render();
850 // State to remove actor in.
851 GestureState stateToUnstage( GestureState::STARTED );
853 // Attach actor to detector
855 UnstageActorFunctor functor( data, stateToUnstage, application.GetScene() );
856 LongPressGestureDetector detector = LongPressGestureDetector::New();
857 detector.Attach(actor);
858 detector.Attach(dummyActor);
859 detector.DetectedSignal().Connect( &application, functor );
861 // Here we are testing a STARTED actor which is removed in the STARTED callback, but then added back
862 // before we get a finished state. As we were removed from the stage, even if we're at the same
863 // position, we should still not be signalled.
866 TestGenerateLongPress( application, 50.0f, 10.0f );
867 DALI_TEST_EQUALS(true, data.functorCalled, TEST_LOCATION);
871 application.SendNotification();
872 application.Render();
874 // Re add to the stage, we should not be signalled
875 application.GetScene().Add(actor);
878 application.SendNotification();
879 application.Render();
881 // Continue signal emission
882 TestEndLongPress( application, 50.0f, 10.0f );
883 DALI_TEST_EQUALS(false, data.functorCalled, TEST_LOCATION);
886 // Here we delete an actor in started, we should not receive any subsequent signalling.
889 TestGenerateLongPress( application, 50.0f, 10.0f );
890 DALI_TEST_EQUALS(true, data.functorCalled, TEST_LOCATION);
894 application.SendNotification();
895 application.Render();
897 // Delete actor as well
901 application.SendNotification();
902 application.Render();
904 // Continue signal emission
905 TestEndLongPress( application, 50.0f, 10.0f );
906 DALI_TEST_EQUALS(false, data.functorCalled, TEST_LOCATION);
910 int UtcDaliLongPressGestureLayerConsumesTouch(void)
912 TestApplication application;
914 Actor actor = Actor::New();
915 actor.SetProperty( Actor::Property::SIZE, Vector2( 100.0f, 100.0f ) );
916 actor.SetProperty( Actor::Property::ANCHOR_POINT,AnchorPoint::TOP_LEFT);
917 application.GetScene().Add(actor);
921 GestureReceivedFunctor functor(data);
922 LongPressGestureDetector detector = LongPressGestureDetector::New();
923 detector.Attach(actor);
924 detector.DetectedSignal().Connect( &application, functor );
926 // Add a layer to overlap the actor
927 Layer layer = Layer::New();
928 layer.SetProperty( Actor::Property::SIZE, Vector2( 100.0f, 100.0f ) );
929 layer.SetProperty( Actor::Property::ANCHOR_POINT,AnchorPoint::TOP_LEFT);
930 application.GetScene().Add( layer );
934 application.SendNotification();
935 application.Render();
937 // Emit signals, should receive
938 TestGenerateLongPress( application, 50.0f, 50.0f );
939 TestEndLongPress( application, 50.0f, 50.0f );
940 DALI_TEST_EQUALS(true, data.functorCalled, TEST_LOCATION);
943 // Set layer to consume all touch
944 layer.SetProperty( Layer::Property::CONSUMES_TOUCH, true );
947 application.SendNotification();
948 application.Render();
950 // Emit the same signals again, should not receive
951 TestGenerateLongPress( application, 50.0f, 50.0f );
952 TestEndLongPress( application, 50.0f, 50.0f );
953 DALI_TEST_EQUALS(false, data.functorCalled, TEST_LOCATION);
959 int UtcDaliLongPressGestureSetMinimumHoldingTime(void)
961 TestApplication application;
963 const uint32_t kMinumumHolding1 = 5000;
964 const uint32_t kMinumumHolding2 = 3000;
966 Integration::SetLongPressMinimumHoldingTime( kMinumumHolding1 );
968 Actor actor = Actor::New();
969 actor.SetProperty( Actor::Property::SIZE, Vector2( 100.0f, 100.0f ) );
970 actor.SetProperty( Actor::Property::ANCHOR_POINT, AnchorPoint::TOP_LEFT );
971 application.GetScene().Add( actor );
974 application.SendNotification();
975 application.Render();
978 GestureReceivedFunctor functor( data );
980 LongPressGestureDetector detector = LongPressGestureDetector::New();
981 detector.Attach(actor);
982 detector.DetectedSignal().Connect(&application, functor);
984 DALI_TEST_EQUALS( DevelLongPressGestureDetector::GetMinimumHoldingTime( detector ), kMinumumHolding1, TEST_LOCATION );
986 Integration::SetLongPressMinimumHoldingTime( kMinumumHolding2 );
987 DALI_TEST_EQUALS( DevelLongPressGestureDetector::GetMinimumHoldingTime( detector ), kMinumumHolding2, TEST_LOCATION );
992 int UtcDaliLongPressGestureInterruptedWhenTouchConsumed(void)
994 TestApplication application;
996 Actor actor = Actor::New();
997 actor.SetProperty( Actor::Property::SIZE, Vector2( 100.0f, 100.0f ) );
998 actor.SetProperty( Actor::Property::ANCHOR_POINT,AnchorPoint::TOP_LEFT);
999 application.GetScene().Add(actor);
1001 bool consume = false;
1002 TouchEventFunctorConsumeSetter touchFunctor(consume);
1003 actor.TouchedSignal().Connect(&application,touchFunctor);
1005 // Render and notify
1006 application.SendNotification();
1007 application.Render();
1010 GestureReceivedFunctor functor(data);
1012 LongPressGestureDetector detector = LongPressGestureDetector::New();
1013 detector.Attach(actor);
1014 detector.DetectedSignal().Connect(&application, functor);
1016 // Start gesture within the actor's area, we should receive the gesture as the touch is NOT being consumed
1017 TestGenerateLongPress( application, 50.0f, 50.0f );
1018 DALI_TEST_EQUALS(true, data.functorCalled, TEST_LOCATION);
1020 TestEndLongPress(application, 50.0f,50.0f);
1021 DALI_TEST_EQUALS(true, data.functorCalled, TEST_LOCATION);
1024 // Another gesture in the same location, this time we will not receive it as touch is being consumed
1026 TestGenerateLongPress( application, 50.0f, 50.0f );
1027 DALI_TEST_EQUALS(false, data.functorCalled, TEST_LOCATION);
1029 TestEndLongPress(application, 50.0f,50.0f);
1030 DALI_TEST_EQUALS(false, data.functorCalled, TEST_LOCATION);
1035 int UtcDaliLongPressGestureDisableDetectionDuringLongPressN(void)
1037 // Crash occurred when gesture-recognizer was deleted internally during a signal when the attached actor was detached
1039 TestApplication application;
1041 Actor actor = Actor::New();
1042 actor.SetProperty( Actor::Property::SIZE, Vector2( 100.0f, 100.0f ) );
1043 actor.SetProperty( Actor::Property::ANCHOR_POINT,AnchorPoint::TOP_LEFT);
1044 application.GetScene().Add(actor);
1047 LongPressGestureDetector detector = LongPressGestureDetector::New();
1048 bool functorCalled = false;
1049 detector.Attach( actor );
1050 detector.DetectedSignal().Connect(
1052 [&detector, &functorCalled](Actor actor, const LongPressGesture& gesture)
1054 if( gesture.GetState() == GestureState::FINISHED )
1056 detector.Detach(actor);
1057 functorCalled = true;
1061 // Render and notify
1062 application.SendNotification();
1063 application.Render();
1065 // Try the gesture, should not crash
1068 TestGenerateLongPress( application, 50.0f, 10.0f );
1069 TestEndLongPress( application, 50.0f, 10.0f );
1071 DALI_TEST_CHECK( true ); // No crash, test has passed
1072 DALI_TEST_EQUALS(functorCalled, true, TEST_LOCATION);
1076 DALI_TEST_CHECK( false ); // If we crash, the test has failed