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>
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 ),
51 receivedGesture( Gesture::Clear ),
57 functorCalled = false;
58 voidFunctorCalled = false;
60 receivedGesture.numberOfTouches = 0u;
61 receivedGesture.screenPoint = Vector2(0.0f, 0.0f);
62 receivedGesture.localPoint = Vector2(0.0f, 0.0f);
68 bool voidFunctorCalled;
69 LongPressGesture receivedGesture;
73 // Functor that sets the data when called
74 struct GestureReceivedFunctor
76 GestureReceivedFunctor(SignalData& data) : signalData(data) { }
78 void operator()(Actor actor, const LongPressGesture& longPress)
80 signalData.functorCalled = true;
81 signalData.receivedGesture = longPress;
82 signalData.pressedActor = actor;
87 signalData.voidFunctorCalled = true;
90 SignalData& signalData;
93 // Functor that removes the gestured actor from stage
94 struct UnstageActorFunctor : public GestureReceivedFunctor
96 UnstageActorFunctor( SignalData& data, Gesture::State& stateToUnstage, Integration::Scene scene )
97 : GestureReceivedFunctor( data ),
98 stateToUnstage( stateToUnstage ),
103 void operator()( Actor actor, const LongPressGesture& longPress )
105 GestureReceivedFunctor::operator()( actor, longPress );
107 if ( longPress.state == stateToUnstage )
109 scene.Remove( actor );
113 Gesture::State& stateToUnstage;
114 Integration::Scene scene;
117 // Functor for receiving a touch event
118 struct TouchEventFunctor
120 bool operator()(Actor actor, const TouchEvent& touch)
123 unsigned int points = touch.GetPointCount();
126 const TouchPoint& touchPoint = touch.GetPoint(0);
127 tet_printf("Touch Point state = %d\n", touchPoint.state);
135 ///////////////////////////////////////////////////////////////////////////////
138 // Positive test case for a method
139 int UtcDaliLongPressGestureDetectorConstructorP(void)
141 TestApplication application;
143 LongPressGestureDetector detector;
144 DALI_TEST_CHECK(!detector);
148 int UtcDaliLongPressGestureDetectorCopyConstructorP(void)
150 TestApplication application;
152 LongPressGestureDetector detector = LongPressGestureDetector::New();;
154 LongPressGestureDetector copy( detector );
155 DALI_TEST_CHECK( detector );
159 int UtcDaliLongPressGestureDetectorAssignmentOperatorP(void)
161 TestApplication application;
163 LongPressGestureDetector detector;
164 detector = LongPressGestureDetector::New();;
166 LongPressGestureDetector copy;
168 DALI_TEST_CHECK( detector );
170 DALI_TEST_CHECK( detector == copy );
174 int UtcDaliLongPressGestureDetectorNew(void)
176 TestApplication application;
178 LongPressGestureDetector detector = LongPressGestureDetector::New();
179 DALI_TEST_CHECK(detector);
180 DALI_TEST_EQUALS(1u, detector.GetMinimumTouchesRequired(), TEST_LOCATION);
181 DALI_TEST_EQUALS(1u, detector.GetMaximumTouchesRequired(), TEST_LOCATION);
183 LongPressGestureDetector detector2 = LongPressGestureDetector::New(5u);
184 DALI_TEST_CHECK(detector2);
185 DALI_TEST_EQUALS(5u, detector2.GetMinimumTouchesRequired(), TEST_LOCATION);
186 DALI_TEST_EQUALS(5u, detector2.GetMaximumTouchesRequired(), TEST_LOCATION);
188 LongPressGestureDetector detector3 = LongPressGestureDetector::New(5u, 7u);
189 DALI_TEST_CHECK(detector2);
190 DALI_TEST_EQUALS(5u, detector3.GetMinimumTouchesRequired(), TEST_LOCATION);
191 DALI_TEST_EQUALS(7u, detector3.GetMaximumTouchesRequired(), TEST_LOCATION);
193 //Scoped test to test destructor
195 LongPressGestureDetector detector4 = LongPressGestureDetector::New();
196 DALI_TEST_CHECK(detector4);
199 // Attach an actor and emit a touch event on the actor to ensure complete line coverage
200 Actor actor = Actor::New();
201 actor.SetProperty( Actor::Property::SIZE, Vector2( 100.0f, 100.0f ) );
202 actor.SetProperty( Actor::Property::ANCHOR_POINT,AnchorPoint::TOP_LEFT);
203 application.GetScene().Add(actor);
206 application.SendNotification();
207 application.Render();
209 detector.Attach(actor);
211 TouchEventFunctor touchFunctor;
212 actor.TouchedSignal().Connect(&application, touchFunctor);
214 Integration::TouchEvent touchEvent(1);
215 Integration::Point point;
216 point.SetDeviceId( 1 );
217 point.SetState( PointState::DOWN );
218 point.SetScreenPosition( Vector2( 20.0f, 20.0f ) );
219 touchEvent.AddPoint(point);
220 application.ProcessEvent(touchEvent);
223 application.SendNotification();
224 application.Render();
226 // For line coverage, Initialise default constructor
227 TouchEvent touchEvent2;
231 int UtcDaliLongPressGestureDetectorDownCast(void)
233 TestApplication application;
234 tet_infoline("Testing Dali::LongPressGestureDetector::DownCast()");
236 LongPressGestureDetector detector = LongPressGestureDetector::New();
238 BaseHandle object(detector);
240 LongPressGestureDetector detector2 = LongPressGestureDetector::DownCast(object);
241 DALI_TEST_CHECK(detector2);
243 LongPressGestureDetector detector3 = DownCast< LongPressGestureDetector >(object);
244 DALI_TEST_CHECK(detector3);
246 BaseHandle unInitializedObject;
247 LongPressGestureDetector detector4 = LongPressGestureDetector::DownCast(unInitializedObject);
248 DALI_TEST_CHECK(!detector4);
250 LongPressGestureDetector detector5 = DownCast< LongPressGestureDetector >(unInitializedObject);
251 DALI_TEST_CHECK(!detector5);
253 GestureDetector detector6 = LongPressGestureDetector::New();
254 LongPressGestureDetector detector7 = LongPressGestureDetector::DownCast(detector6);
255 DALI_TEST_CHECK(detector7);
259 int UtcDaliLongPressGestureGetMinimumTouchesRequired(void)
261 TestApplication application;
263 LongPressGestureDetector detector = LongPressGestureDetector::New();
264 DALI_TEST_EQUALS(1u, detector.GetMinimumTouchesRequired(), TEST_LOCATION);
268 int UtcDaliLongPressGestureGetMaximumTouchesRequired(void)
270 TestApplication application;
272 LongPressGestureDetector detector = LongPressGestureDetector::New();
273 DALI_TEST_EQUALS(1u, detector.GetMaximumTouchesRequired(), TEST_LOCATION);
277 int UtcDaliLongPressGestureSignalReceptionNegative(void)
279 TestApplication application;
281 Actor actor = Actor::New();
282 actor.SetProperty( Actor::Property::SIZE, Vector2( 100.0f, 100.0f ) );
283 actor.SetProperty( Actor::Property::ANCHOR_POINT,AnchorPoint::TOP_LEFT);
284 application.GetScene().Add(actor);
287 application.SendNotification();
288 application.Render();
291 GestureReceivedFunctor functor(data);
293 LongPressGestureDetector detector = LongPressGestureDetector::New();
294 detector.Attach(actor);
295 detector.DetectedSignal().Connect(&application, functor);
297 // Do a long press outside actor's area
298 TestGenerateLongPress( application, 112.0f, 112.0f );
299 TestEndLongPress( application, 112.0f, 112.0f);
301 DALI_TEST_EQUALS(false, data.functorCalled, TEST_LOCATION);
305 int UtcDaliLongPressGestureSignalReceptionPositive(void)
307 TestApplication application;
309 Actor actor = Actor::New();
310 actor.SetProperty( Actor::Property::SIZE, Vector2( 100.0f, 100.0f ) );
311 actor.SetProperty( Actor::Property::ANCHOR_POINT,AnchorPoint::TOP_LEFT);
312 application.GetScene().Add(actor);
315 application.SendNotification();
316 application.Render();
319 GestureReceivedFunctor functor(data);
321 LongPressGestureDetector detector = LongPressGestureDetector::New();
322 detector.Attach(actor);
323 detector.DetectedSignal().Connect(&application, functor);
325 // Do a long press inside actor's area
326 TestGenerateLongPress( application, 50.0f, 50.0f );
327 DALI_TEST_EQUALS(true, data.functorCalled, TEST_LOCATION);
328 DALI_TEST_EQUALS(1u, data.receivedGesture.numberOfTouches, TEST_LOCATION);
329 DALI_TEST_EQUALS( Vector2(50.0f, 50.0f), data.receivedGesture.localPoint, 0.1, TEST_LOCATION);
330 TestEndLongPress( application, 50.0f, 50.0f);
334 int UtcDaliLongPressGestureSignalReceptionDetach(void)
336 TestApplication application;
338 Actor actor = Actor::New();
339 actor.SetProperty( Actor::Property::SIZE, Vector2( 100.0f, 100.0f ) );
340 actor.SetProperty( Actor::Property::ANCHOR_POINT,AnchorPoint::TOP_LEFT);
341 application.GetScene().Add(actor);
344 application.SendNotification();
345 application.Render();
348 GestureReceivedFunctor functor(data);
350 LongPressGestureDetector detector = LongPressGestureDetector::New();
351 detector.Attach(actor);
352 detector.DetectedSignal().Connect(&application, functor);
354 // Start long press within the actor's area
355 TestGenerateLongPress( application, 20.0f, 20.0f );
356 DALI_TEST_EQUALS(true, data.functorCalled, TEST_LOCATION);
357 DALI_TEST_EQUALS(1u, data.receivedGesture.numberOfTouches, TEST_LOCATION);
358 DALI_TEST_EQUALS( Vector2(20.0f, 20.0f), data.receivedGesture.localPoint, 0.1, TEST_LOCATION);
359 TestEndLongPress( application, 20.0f, 20.0f);
361 // repeat the long press within the actor's area - we should still receive the signal
363 TestGenerateLongPress( application, 50.0f, 50.0f );
364 DALI_TEST_EQUALS(true, data.functorCalled, TEST_LOCATION);
365 DALI_TEST_EQUALS(1u, data.receivedGesture.numberOfTouches, TEST_LOCATION);
366 DALI_TEST_EQUALS( Vector2(50.0f, 50.0f), data.receivedGesture.localPoint, 0.1, TEST_LOCATION);
367 TestEndLongPress( application, 50.0f, 50.0f);
370 detector.DetachAll();
372 // Ensure we are no longer signalled
374 TestGenerateLongPress( application, 20.0f, 20.0f );
375 DALI_TEST_EQUALS(false, data.functorCalled, TEST_LOCATION);
376 TestEndLongPress( application, 50.0f, 50.0f);
377 DALI_TEST_EQUALS(false, data.functorCalled, TEST_LOCATION);
381 int UtcDaliLongPressGestureSignalReceptionActorDestroyedDuringLongPress(void)
383 TestApplication application;
386 GestureReceivedFunctor functor(data);
388 LongPressGestureDetector detector = LongPressGestureDetector::New();
389 detector.DetectedSignal().Connect(&application, functor);
391 // Actor lifetime is scoped
393 Actor actor = Actor::New();
394 actor.SetProperty( Actor::Property::SIZE, Vector2( 100.0f, 100.0f ) );
395 actor.SetProperty( Actor::Property::ANCHOR_POINT,AnchorPoint::TOP_LEFT);
396 application.GetScene().Add(actor);
399 application.SendNotification();
400 application.Render();
402 detector.Attach(actor);
404 // Start long press within the actor's area
405 TestGenerateLongPress( application, 20.0f, 20.0f );
406 DALI_TEST_EQUALS(true, data.functorCalled, TEST_LOCATION);
408 // Remove the actor from stage and reset the data
409 application.GetScene().Remove(actor);
412 application.SendNotification();
413 application.Render();
416 // Actor should now have been destroyed
419 TestEndLongPress( application, 20.0f, 20.0f);
420 DALI_TEST_EQUALS(false, data.functorCalled, TEST_LOCATION);
424 int UtcDaliLongPressGestureSignalReceptionRotatedActor(void)
426 TestApplication application;
428 Actor actor = Actor::New();
429 actor.SetProperty( Actor::Property::SIZE, Vector2( 100.0f, 100.0f ) );
430 actor.SetProperty( Actor::Property::ORIENTATION, Quaternion( Dali::Degree(90.0f), Vector3::ZAXIS ) );
431 application.GetScene().Add(actor);
434 application.SendNotification();
435 application.Render();
438 GestureReceivedFunctor functor(data);
440 LongPressGestureDetector detector = LongPressGestureDetector::New();
441 detector.Attach(actor);
442 detector.DetectedSignal().Connect(&application, functor);
445 TestGenerateLongPress( application, 5.0f, 5.0f );
446 TestEndLongPress( application, 5.0f, 5.0f);
447 DALI_TEST_EQUALS(true, data.functorCalled, TEST_LOCATION);
448 DALI_TEST_EQUALS(1u, data.receivedGesture.numberOfTouches, TEST_LOCATION);
449 DALI_TEST_EQUALS( Vector2(5.0f, 5.0f), data.receivedGesture.screenPoint, 0.1, TEST_LOCATION);
451 // Rotate actor again and render
452 actor.SetProperty( Actor::Property::ORIENTATION, Quaternion(Dali::Degree(180.0f), Vector3::ZAXIS) );
453 application.SendNotification();
454 application.Render();
456 // Do another long press, should still receive event
458 TestGenerateLongPress( application, 5.0f, 5.0f );
459 TestEndLongPress( application, 5.0f, 5.0f);
460 DALI_TEST_EQUALS(true, data.functorCalled, TEST_LOCATION);
461 DALI_TEST_EQUALS(1u, data.receivedGesture.numberOfTouches, TEST_LOCATION);
462 DALI_TEST_EQUALS( Vector2(5.0f, 5.0f), data.receivedGesture.screenPoint, 0.1, TEST_LOCATION);
464 // Rotate actor again and render
465 actor.SetProperty( Actor::Property::ORIENTATION, Quaternion(Dali::Degree(90.0f), Vector3::YAXIS) );
466 application.SendNotification();
467 application.Render();
469 // Do a long press, inside where the actor used to be, Should not receive the event
471 TestGenerateLongPress( application, 70.0f, 70.0f );
472 TestEndLongPress( application, 70.0f, 70.0f);
473 DALI_TEST_EQUALS(false, data.functorCalled, TEST_LOCATION);
477 int UtcDaliLongPressGestureSignalReceptionChildHit(void)
479 TestApplication application;
481 Actor parent = Actor::New();
482 parent.SetProperty( Actor::Property::SIZE, Vector2( 100.0f, 100.0f ) );
483 parent.SetProperty( Actor::Property::ANCHOR_POINT,AnchorPoint::TOP_LEFT);
484 application.GetScene().Add(parent);
486 // Set child to completely cover parent.
487 // Change rotation of child to be different from parent so that we can check if our local coordinate
488 // conversion of the parent actor is correct.
489 Actor child = Actor::New();
490 child.SetProperty( Actor::Property::SIZE, Vector2( 100.0f, 100.0f ) );
491 child.SetProperty( Actor::Property::ANCHOR_POINT,AnchorPoint::CENTER);
492 child.SetProperty( Actor::Property::PARENT_ORIGIN,ParentOrigin::CENTER);
493 child.SetProperty( Actor::Property::ORIENTATION, Quaternion(Dali::Degree(90.0f), Vector3::ZAXIS) );
496 TouchEventFunctor touchFunctor;
497 child.TouchedSignal().Connect(&application, touchFunctor);
500 application.SendNotification();
501 application.Render();
504 GestureReceivedFunctor functor(data);
506 LongPressGestureDetector detector = LongPressGestureDetector::New();
507 detector.Attach(parent);
508 detector.DetectedSignal().Connect(&application, functor);
510 // Do long press - hits child area but parent should still receive it
511 TestGenerateLongPress( application, 50.0f, 50.0f );
512 TestEndLongPress( application, 50.0f, 50.0f);
513 DALI_TEST_EQUALS(true, data.functorCalled, TEST_LOCATION);
514 DALI_TEST_EQUALS(true, parent == data.pressedActor, TEST_LOCATION);
515 DALI_TEST_EQUALS(Vector2(50.0f, 50.0f), data.receivedGesture.screenPoint, 0.01f, TEST_LOCATION);
517 // Attach child and generate same touch points
518 // (Also proves that you can detach and then re-attach another actor)
519 detector.Attach(child);
520 detector.Detach(parent);
522 // Do an entire long press, only check finished value
524 TestGenerateLongPress( application, 51.0f, 51.0f );
525 TestEndLongPress( application, 51.0f, 51.0f);
526 DALI_TEST_EQUALS(true, data.functorCalled, TEST_LOCATION);
527 DALI_TEST_EQUALS(true, child == data.pressedActor, TEST_LOCATION);
528 DALI_TEST_EQUALS(Vector2(51.0f, 51.0f), data.receivedGesture.screenPoint, 0.01f, TEST_LOCATION);
532 int UtcDaliLongPressGestureSignalReceptionAttachDetachMany(void)
534 TestApplication application;
536 Actor first = Actor::New();
537 first.SetProperty( Actor::Property::SIZE, Vector2( 100.0f, 100.0f ) );
538 first.SetProperty( Actor::Property::ANCHOR_POINT,AnchorPoint::TOP_LEFT);
539 application.GetScene().Add(first);
541 Actor second = Actor::New();
542 second.SetProperty( Actor::Property::SIZE, Vector2( 100.0f, 100.0f ) );
543 second.SetProperty( Actor::Property::POSITION_X, 100.0f);
544 second.SetProperty( Actor::Property::ANCHOR_POINT,AnchorPoint::TOP_LEFT);
545 application.GetScene().Add(second);
548 application.SendNotification();
549 application.Render();
552 GestureReceivedFunctor functor(data);
554 LongPressGestureDetector detector = LongPressGestureDetector::New();
555 detector.Attach(first);
556 detector.Attach(second);
557 detector.DetectedSignal().Connect(&application, functor);
559 // LongPress within second actor's area
560 TestGenerateLongPress( application, 120.0f, 10.0f );
561 TestEndLongPress( application, 120.0f, 10.0f);
562 DALI_TEST_EQUALS(true, data.functorCalled, TEST_LOCATION);
563 DALI_TEST_EQUALS(true, second == data.pressedActor, TEST_LOCATION);
565 // LongPress within first actor's area
567 TestGenerateLongPress( application, 20.0f, 10.0f );
568 TestEndLongPress( application, 20.0f, 10.0f);
569 DALI_TEST_EQUALS(true, data.functorCalled, TEST_LOCATION);
570 DALI_TEST_EQUALS(true, first == data.pressedActor, TEST_LOCATION);
572 // Detach the second actor
573 detector.Detach(second);
575 // second actor shouldn't receive event
577 TestGenerateLongPress( application, 120.0f, 10.0f );
578 TestEndLongPress( application, 120.0f, 10.0f);
579 DALI_TEST_EQUALS(false, data.functorCalled, TEST_LOCATION);
581 // first actor should continue receiving event
583 TestGenerateLongPress( application, 20.0f, 10.0f );
584 TestEndLongPress( application, 20.0f, 10.0f);
585 DALI_TEST_EQUALS(true, data.functorCalled, TEST_LOCATION);
589 int UtcDaliLongPressGestureSignalReceptionActorBecomesUntouchable(void)
591 TestApplication application;
593 Actor actor = Actor::New();
594 actor.SetProperty( Actor::Property::SIZE, Vector2( 100.0f, 100.0f ) );
595 actor.SetProperty( Actor::Property::ANCHOR_POINT,AnchorPoint::TOP_LEFT);
596 application.GetScene().Add(actor);
599 application.SendNotification();
600 application.Render();
603 GestureReceivedFunctor functor(data);
605 LongPressGestureDetector detector = LongPressGestureDetector::New();
606 detector.Attach(actor);
607 detector.DetectedSignal().Connect(&application, functor);
609 // LongPress in actor's area
610 TestGenerateLongPress( application, 50.0f, 10.0f );
611 TestEndLongPress( application, 50.0f, 10.0f);
612 DALI_TEST_EQUALS(true, data.functorCalled, TEST_LOCATION);
614 // Actor becomes invisible - actor should not receive the next long press
615 actor.SetProperty( Actor::Property::VISIBLE,false);
618 application.SendNotification();
619 application.Render();
621 // LongPress in the same area, shouldn't receive event
623 TestGenerateLongPress( application, 50.0f, 10.0f );
624 TestEndLongPress( application, 50.0f, 10.0f);
625 DALI_TEST_EQUALS(false, data.functorCalled, TEST_LOCATION);
629 int UtcDaliLongPressGestureSignalReceptionMultipleDetectorsOnActor(void)
631 TestApplication application;
633 Actor actor = Actor::New();
634 actor.SetProperty( Actor::Property::SIZE, Vector2( 100.0f, 100.0f ) );
635 actor.SetProperty( Actor::Property::ANCHOR_POINT,AnchorPoint::TOP_LEFT);
636 application.GetScene().Add(actor);
639 application.SendNotification();
640 application.Render();
642 // Attach actor to one detector
643 SignalData firstData;
644 GestureReceivedFunctor firstFunctor(firstData);
645 LongPressGestureDetector firstDetector = LongPressGestureDetector::New();
646 firstDetector.Attach(actor);
647 firstDetector.DetectedSignal().Connect(&application, firstFunctor);
649 // Attach actor to another detector
650 SignalData secondData;
651 GestureReceivedFunctor secondFunctor(secondData);
652 LongPressGestureDetector secondDetector = LongPressGestureDetector::New();
653 secondDetector.Attach(actor);
654 secondDetector.DetectedSignal().Connect(&application, secondFunctor);
656 // LongPress in actor's area - both detector's functors should be called
657 TestGenerateLongPress( application, 50.0f, 10.0f );
658 DALI_TEST_EQUALS(true, firstData.functorCalled, TEST_LOCATION);
659 DALI_TEST_EQUALS(true, secondData.functorCalled, TEST_LOCATION);
663 int UtcDaliLongPressGestureSignalReceptionDifferentPossible(void)
665 TestApplication application;
667 Actor actor = Actor::New();
668 actor.SetProperty( Actor::Property::SIZE, Vector2( 100.0f, 100.0f ) );
669 actor.SetProperty( Actor::Property::ANCHOR_POINT,AnchorPoint::TOP_LEFT);
670 application.GetScene().Add(actor);
673 application.SendNotification();
674 application.Render();
676 // Attach actor to detector
678 GestureReceivedFunctor functor( data );
679 LongPressGestureDetector detector = LongPressGestureDetector::New();
680 detector.Attach(actor);
681 detector.DetectedSignal().Connect( &application, functor );
683 // LongPress possible in actor's area.
684 TestStartLongPress( application, 50.0f, 10.0f );
685 DALI_TEST_EQUALS(false, data.functorCalled, TEST_LOCATION);
687 // Move actor somewhere else
688 actor.SetProperty( Actor::Property::POSITION, Vector2( 100.0f, 100.0f ));
691 application.SendNotification();
692 application.Render();
694 // Emit Started event, we should not receive the long press.
695 TestTriggerLongPress( application );
696 TestGenerateLongPress( application, 50.0f, 10.0f );
697 DALI_TEST_EQUALS(false, data.functorCalled, TEST_LOCATION);
699 // LongPress possible in empty area.
700 TestStartLongPress( application, 50.0f, 10.0f );
701 DALI_TEST_EQUALS(false, data.functorCalled, TEST_LOCATION);
703 // Move actor in to the long press position.
704 actor.SetProperty( Actor::Property::POSITION, Vector2( 0.0f, 0.0f ));
707 application.SendNotification();
708 application.Render();
710 // Emit Started event, we should not receive the long press.
711 TestTriggerLongPress( application );
712 TestEndLongPress( application, 50.0f, 10.0f );
713 DALI_TEST_EQUALS(false, data.functorCalled, TEST_LOCATION);
715 // Normal long press in actor's area for completeness.
716 TestGenerateLongPress( application, 50.0f, 10.0f );
717 TestEndLongPress( application, 50.0f, 10.0f);
718 DALI_TEST_EQUALS(true, data.functorCalled, TEST_LOCATION);
722 int UtcDaliLongPressGesturePossibleCancelled(void)
724 TestApplication application;
726 Actor actor = Actor::New();
727 actor.SetProperty( Actor::Property::SIZE, Vector2( 100.0f, 100.0f ) );
728 actor.SetProperty( Actor::Property::ANCHOR_POINT,AnchorPoint::TOP_LEFT);
729 application.GetScene().Add(actor);
732 application.SendNotification();
733 application.Render();
735 // Attach actor to detector
737 GestureReceivedFunctor functor( data );
738 LongPressGestureDetector detector = LongPressGestureDetector::New();
739 detector.Attach(actor);
740 detector.DetectedSignal().Connect( &application, functor );
742 // Send a possible followed by a cancel, we should not be signalled
743 TestStartLongPress( application, 50.0f, 10.0f );
744 DALI_TEST_EQUALS(false, data.functorCalled, TEST_LOCATION);
745 TestMovePan( application, Vector2( 50.0f, 10.0f ) );
746 DALI_TEST_EQUALS(false, data.functorCalled, TEST_LOCATION);
750 int UtcDaliLongPressGestureDetachAfterStarted(void)
752 TestApplication application;
754 Actor actor = Actor::New();
755 actor.SetProperty( Actor::Property::SIZE, Vector2( 100.0f, 100.0f ) );
756 actor.SetProperty( Actor::Property::ANCHOR_POINT,AnchorPoint::TOP_LEFT);
757 application.GetScene().Add(actor);
760 application.SendNotification();
761 application.Render();
763 // Attach actor to detector
765 GestureReceivedFunctor functor( data );
766 LongPressGestureDetector detector = LongPressGestureDetector::New();
767 detector.Attach(actor);
768 detector.DetectedSignal().Connect( &application, functor );
770 // Emit initial signal
771 TestGenerateLongPress( application, 50.0f, 10.0f );
772 DALI_TEST_EQUALS(true, data.functorCalled, TEST_LOCATION);
776 detector.Detach(actor);
778 // Emit Finished, no signal
779 TestEndLongPress( application, 50.0f, 10.0f );
780 DALI_TEST_EQUALS(false, data.functorCalled, TEST_LOCATION);
784 int UtcDaliLongPressGestureActorUnstaged(void)
786 TestApplication application;
788 Actor actor = Actor::New();
789 actor.SetProperty( Actor::Property::SIZE, Vector2( 100.0f, 100.0f ) );
790 actor.SetProperty( Actor::Property::ANCHOR_POINT,AnchorPoint::TOP_LEFT);
791 application.GetScene().Add(actor);
794 application.SendNotification();
795 application.Render();
797 // State to remove actor in.
798 Gesture::State stateToUnstage( Gesture::Started );
800 // Attach actor to detector
802 UnstageActorFunctor functor( data, stateToUnstage, application.GetScene() );
803 LongPressGestureDetector detector = LongPressGestureDetector::New();
804 detector.Attach(actor);
805 detector.DetectedSignal().Connect( &application, functor );
808 TestGenerateLongPress( application, 50.0f, 10.0f );
809 DALI_TEST_EQUALS(true, data.functorCalled, TEST_LOCATION);
811 TestEndLongPress( application, 50.0f, 10.0f );
812 DALI_TEST_EQUALS(false, data.functorCalled, TEST_LOCATION);
815 application.SendNotification();
816 application.Render();
818 // Re-add actor to stage
819 application.GetScene().Add(actor);
822 application.SendNotification();
823 application.Render();
825 // Change state to Gesture::Continuing to remove
826 stateToUnstage = Gesture::Finished;
829 TestGenerateLongPress( application, 50.0f, 10.0f );
830 DALI_TEST_EQUALS(true, data.functorCalled, TEST_LOCATION);
832 TestEndLongPress( application, 50.0f, 10.0f );
833 DALI_TEST_EQUALS(true, data.functorCalled, TEST_LOCATION);
834 tet_result( TET_PASS ); // If we get here then we have handled actor stage removal gracefully.
838 int UtcDaliLongPressGestureActorStagedAndDestroyed(void)
840 TestApplication application;
842 Actor actor = Actor::New();
843 actor.SetProperty( Actor::Property::SIZE, Vector2( 100.0f, 100.0f ) );
844 actor.SetProperty( Actor::Property::ANCHOR_POINT,AnchorPoint::TOP_LEFT);
845 application.GetScene().Add(actor);
847 // Create and add a second actor so that GestureDetector destruction does not come into play.
848 Actor dummyActor( Actor::New() );
849 dummyActor.SetProperty( Actor::Property::SIZE, Vector2( 100.0f, 100.0f ) );
850 dummyActor.SetProperty( Actor::Property::POSITION, Vector2( 100.0f, 100.0f ));
851 dummyActor.SetProperty( Actor::Property::ANCHOR_POINT,AnchorPoint::TOP_LEFT);
852 application.GetScene().Add(dummyActor);
855 application.SendNotification();
856 application.Render();
858 // State to remove actor in.
859 Gesture::State stateToUnstage( Gesture::Started );
861 // Attach actor to detector
863 UnstageActorFunctor functor( data, stateToUnstage, application.GetScene() );
864 LongPressGestureDetector detector = LongPressGestureDetector::New();
865 detector.Attach(actor);
866 detector.Attach(dummyActor);
867 detector.DetectedSignal().Connect( &application, functor );
869 // Here we are testing a Started actor which is removed in the Started callback, but then added back
870 // before we get a finished state. As we were removed from the stage, even if we're at the same
871 // position, we should still not be signalled.
874 TestGenerateLongPress( application, 50.0f, 10.0f );
875 DALI_TEST_EQUALS(true, data.functorCalled, TEST_LOCATION);
879 application.SendNotification();
880 application.Render();
882 // Re add to the stage, we should not be signalled
883 application.GetScene().Add(actor);
886 application.SendNotification();
887 application.Render();
889 // Continue signal emission
890 TestEndLongPress( application, 50.0f, 10.0f );
891 DALI_TEST_EQUALS(false, data.functorCalled, TEST_LOCATION);
894 // Here we delete an actor in started, we should not receive any subsequent signalling.
897 TestGenerateLongPress( application, 50.0f, 10.0f );
898 DALI_TEST_EQUALS(true, data.functorCalled, TEST_LOCATION);
902 application.SendNotification();
903 application.Render();
905 // Delete actor as well
909 application.SendNotification();
910 application.Render();
912 // Continue signal emission
913 TestEndLongPress( application, 50.0f, 10.0f );
914 DALI_TEST_EQUALS(false, data.functorCalled, TEST_LOCATION);
918 int UtcDaliLongPressGestureLayerConsumesTouch(void)
920 TestApplication application;
922 Actor actor = Actor::New();
923 actor.SetProperty( Actor::Property::SIZE, Vector2( 100.0f, 100.0f ) );
924 actor.SetProperty( Actor::Property::ANCHOR_POINT,AnchorPoint::TOP_LEFT);
925 application.GetScene().Add(actor);
929 GestureReceivedFunctor functor(data);
930 LongPressGestureDetector detector = LongPressGestureDetector::New();
931 detector.Attach(actor);
932 detector.DetectedSignal().Connect( &application, functor );
934 // Add a layer to overlap the actor
935 Layer layer = Layer::New();
936 layer.SetProperty( Actor::Property::SIZE, Vector2( 100.0f, 100.0f ) );
937 layer.SetProperty( Actor::Property::ANCHOR_POINT,AnchorPoint::TOP_LEFT);
938 application.GetScene().Add( layer );
942 application.SendNotification();
943 application.Render();
945 // Emit signals, should receive
946 TestGenerateLongPress( application, 50.0f, 50.0f );
947 TestEndLongPress( application, 50.0f, 50.0f );
948 DALI_TEST_EQUALS(true, data.functorCalled, TEST_LOCATION);
951 // Set layer to consume all touch
952 layer.SetProperty( Layer::Property::CONSUMES_TOUCH, true );
955 application.SendNotification();
956 application.Render();
958 // Emit the same signals again, should not receive
959 TestGenerateLongPress( application, 50.0f, 50.0f );
960 TestEndLongPress( application, 50.0f, 50.0f );
961 DALI_TEST_EQUALS(false, data.functorCalled, TEST_LOCATION);
967 int UtcDaliLongPressGestureSetMinimumHoldingTime(void)
969 TestApplication application;
971 const uint32_t kMinumumHolding1 = 5000;
972 const uint32_t kMinumumHolding2 = 3000;
974 Integration::SetLongPressMinimumHoldingTime( kMinumumHolding1 );
976 Actor actor = Actor::New();
977 actor.SetProperty( Actor::Property::SIZE, Vector2( 100.0f, 100.0f ) );
978 actor.SetProperty( Actor::Property::ANCHOR_POINT, AnchorPoint::TOP_LEFT );
979 application.GetScene().Add( actor );
982 application.SendNotification();
983 application.Render();
986 GestureReceivedFunctor functor( data );
988 LongPressGestureDetector detector = LongPressGestureDetector::New();
989 detector.Attach(actor);
990 detector.DetectedSignal().Connect(&application, functor);
992 DALI_TEST_EQUALS( DevelLongPressGestureDetector::GetMinimumHoldingTime( detector ), kMinumumHolding1, TEST_LOCATION );
994 Integration::SetLongPressMinimumHoldingTime( kMinumumHolding2 );
995 DALI_TEST_EQUALS( DevelLongPressGestureDetector::GetMinimumHoldingTime( detector ), kMinumumHolding2, TEST_LOCATION );