2 * Copyright (c) 2019 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 )
97 : GestureReceivedFunctor( data ),
98 stateToUnstage( stateToUnstage )
102 void operator()( Actor actor, const LongPressGesture& longPress )
104 GestureReceivedFunctor::operator()( actor, longPress );
106 if ( longPress.state == stateToUnstage )
108 Stage::GetCurrent().Remove( actor );
112 Gesture::State& stateToUnstage;
115 // Functor for receiving a touch event
116 struct TouchEventFunctor
118 bool operator()(Actor actor, const TouchEvent& touch)
121 unsigned int points = touch.GetPointCount();
124 const TouchPoint& touchPoint = touch.GetPoint(0);
125 tet_printf("Touch Point state = %d\n", touchPoint.state);
133 ///////////////////////////////////////////////////////////////////////////////
136 // Positive test case for a method
137 int UtcDaliLongPressGestureDetectorConstructorP(void)
139 TestApplication application;
141 LongPressGestureDetector detector;
142 DALI_TEST_CHECK(!detector);
146 int UtcDaliLongPressGestureDetectorCopyConstructorP(void)
148 TestApplication application;
150 LongPressGestureDetector detector = LongPressGestureDetector::New();;
152 LongPressGestureDetector copy( detector );
153 DALI_TEST_CHECK( detector );
157 int UtcDaliLongPressGestureDetectorAssignmentOperatorP(void)
159 TestApplication application;
161 LongPressGestureDetector detector;
162 detector = LongPressGestureDetector::New();;
164 LongPressGestureDetector copy;
166 DALI_TEST_CHECK( detector );
168 DALI_TEST_CHECK( detector == copy );
172 int UtcDaliLongPressGestureDetectorNew(void)
174 TestApplication application;
176 LongPressGestureDetector detector = LongPressGestureDetector::New();
177 DALI_TEST_CHECK(detector);
178 DALI_TEST_EQUALS(1u, detector.GetMinimumTouchesRequired(), TEST_LOCATION);
179 DALI_TEST_EQUALS(1u, detector.GetMaximumTouchesRequired(), TEST_LOCATION);
181 LongPressGestureDetector detector2 = LongPressGestureDetector::New(5u);
182 DALI_TEST_CHECK(detector2);
183 DALI_TEST_EQUALS(5u, detector2.GetMinimumTouchesRequired(), TEST_LOCATION);
184 DALI_TEST_EQUALS(5u, detector2.GetMaximumTouchesRequired(), TEST_LOCATION);
186 LongPressGestureDetector detector3 = LongPressGestureDetector::New(5u, 7u);
187 DALI_TEST_CHECK(detector2);
188 DALI_TEST_EQUALS(5u, detector3.GetMinimumTouchesRequired(), TEST_LOCATION);
189 DALI_TEST_EQUALS(7u, detector3.GetMaximumTouchesRequired(), TEST_LOCATION);
191 //Scoped test to test destructor
193 LongPressGestureDetector detector4 = LongPressGestureDetector::New();
194 DALI_TEST_CHECK(detector4);
197 // Attach an actor and emit a touch event on the actor to ensure complete line coverage
198 Actor actor = Actor::New();
199 actor.SetProperty( Actor::Property::SIZE, Vector2( 100.0f, 100.0f ) );
200 actor.SetProperty( Actor::Property::ANCHOR_POINT,AnchorPoint::TOP_LEFT);
201 Stage::GetCurrent().Add(actor);
204 application.SendNotification();
205 application.Render();
207 detector.Attach(actor);
209 TouchEventFunctor touchFunctor;
210 actor.TouchedSignal().Connect(&application, touchFunctor);
212 Integration::TouchEvent touchEvent(1);
213 Integration::Point point;
214 point.SetDeviceId( 1 );
215 point.SetState( PointState::DOWN );
216 point.SetScreenPosition( Vector2( 20.0f, 20.0f ) );
217 touchEvent.AddPoint(point);
218 application.ProcessEvent(touchEvent);
221 application.SendNotification();
222 application.Render();
224 // For line coverage, Initialise default constructor
225 TouchEvent touchEvent2;
229 int UtcDaliLongPressGestureDetectorDownCast(void)
231 TestApplication application;
232 tet_infoline("Testing Dali::LongPressGestureDetector::DownCast()");
234 LongPressGestureDetector detector = LongPressGestureDetector::New();
236 BaseHandle object(detector);
238 LongPressGestureDetector detector2 = LongPressGestureDetector::DownCast(object);
239 DALI_TEST_CHECK(detector2);
241 LongPressGestureDetector detector3 = DownCast< LongPressGestureDetector >(object);
242 DALI_TEST_CHECK(detector3);
244 BaseHandle unInitializedObject;
245 LongPressGestureDetector detector4 = LongPressGestureDetector::DownCast(unInitializedObject);
246 DALI_TEST_CHECK(!detector4);
248 LongPressGestureDetector detector5 = DownCast< LongPressGestureDetector >(unInitializedObject);
249 DALI_TEST_CHECK(!detector5);
251 GestureDetector detector6 = LongPressGestureDetector::New();
252 LongPressGestureDetector detector7 = LongPressGestureDetector::DownCast(detector6);
253 DALI_TEST_CHECK(detector7);
257 int UtcDaliLongPressGestureGetMinimumTouchesRequired(void)
259 TestApplication application;
261 LongPressGestureDetector detector = LongPressGestureDetector::New();
262 DALI_TEST_EQUALS(1u, detector.GetMinimumTouchesRequired(), TEST_LOCATION);
266 int UtcDaliLongPressGestureGetMaximumTouchesRequired(void)
268 TestApplication application;
270 LongPressGestureDetector detector = LongPressGestureDetector::New();
271 DALI_TEST_EQUALS(1u, detector.GetMaximumTouchesRequired(), TEST_LOCATION);
275 int UtcDaliLongPressGestureSignalReceptionNegative(void)
277 TestApplication application;
279 Actor actor = Actor::New();
280 actor.SetProperty( Actor::Property::SIZE, Vector2( 100.0f, 100.0f ) );
281 actor.SetProperty( Actor::Property::ANCHOR_POINT,AnchorPoint::TOP_LEFT);
282 Stage::GetCurrent().Add(actor);
285 application.SendNotification();
286 application.Render();
289 GestureReceivedFunctor functor(data);
291 LongPressGestureDetector detector = LongPressGestureDetector::New();
292 detector.Attach(actor);
293 detector.DetectedSignal().Connect(&application, functor);
295 // Do a long press outside actor's area
296 TestGenerateLongPress( application, 112.0f, 112.0f );
297 TestEndLongPress( application, 112.0f, 112.0f);
299 DALI_TEST_EQUALS(false, data.functorCalled, TEST_LOCATION);
303 int UtcDaliLongPressGestureSignalReceptionPositive(void)
305 TestApplication application;
307 Actor actor = Actor::New();
308 actor.SetProperty( Actor::Property::SIZE, Vector2( 100.0f, 100.0f ) );
309 actor.SetProperty( Actor::Property::ANCHOR_POINT,AnchorPoint::TOP_LEFT);
310 Stage::GetCurrent().Add(actor);
313 application.SendNotification();
314 application.Render();
317 GestureReceivedFunctor functor(data);
319 LongPressGestureDetector detector = LongPressGestureDetector::New();
320 detector.Attach(actor);
321 detector.DetectedSignal().Connect(&application, functor);
323 // Do a long press inside actor's area
324 TestGenerateLongPress( application, 50.0f, 50.0f );
325 DALI_TEST_EQUALS(true, data.functorCalled, TEST_LOCATION);
326 DALI_TEST_EQUALS(1u, data.receivedGesture.numberOfTouches, TEST_LOCATION);
327 DALI_TEST_EQUALS( Vector2(50.0f, 50.0f), data.receivedGesture.localPoint, 0.1, TEST_LOCATION);
328 TestEndLongPress( application, 50.0f, 50.0f);
332 int UtcDaliLongPressGestureSignalReceptionDetach(void)
334 TestApplication application;
336 Actor actor = Actor::New();
337 actor.SetProperty( Actor::Property::SIZE, Vector2( 100.0f, 100.0f ) );
338 actor.SetProperty( Actor::Property::ANCHOR_POINT,AnchorPoint::TOP_LEFT);
339 Stage::GetCurrent().Add(actor);
342 application.SendNotification();
343 application.Render();
346 GestureReceivedFunctor functor(data);
348 LongPressGestureDetector detector = LongPressGestureDetector::New();
349 detector.Attach(actor);
350 detector.DetectedSignal().Connect(&application, functor);
352 // Start long press within the actor's area
353 TestGenerateLongPress( application, 20.0f, 20.0f );
354 DALI_TEST_EQUALS(true, data.functorCalled, TEST_LOCATION);
355 DALI_TEST_EQUALS(1u, data.receivedGesture.numberOfTouches, TEST_LOCATION);
356 DALI_TEST_EQUALS( Vector2(20.0f, 20.0f), data.receivedGesture.localPoint, 0.1, TEST_LOCATION);
357 TestEndLongPress( application, 20.0f, 20.0f);
359 // repeat the long press within the actor's area - we should still receive the signal
361 TestGenerateLongPress( application, 50.0f, 50.0f );
362 DALI_TEST_EQUALS(true, data.functorCalled, TEST_LOCATION);
363 DALI_TEST_EQUALS(1u, data.receivedGesture.numberOfTouches, TEST_LOCATION);
364 DALI_TEST_EQUALS( Vector2(50.0f, 50.0f), data.receivedGesture.localPoint, 0.1, TEST_LOCATION);
365 TestEndLongPress( application, 50.0f, 50.0f);
368 detector.DetachAll();
370 // Ensure we are no longer signalled
372 TestGenerateLongPress( application, 20.0f, 20.0f );
373 DALI_TEST_EQUALS(false, data.functorCalled, TEST_LOCATION);
374 TestEndLongPress( application, 50.0f, 50.0f);
375 DALI_TEST_EQUALS(false, data.functorCalled, TEST_LOCATION);
379 int UtcDaliLongPressGestureSignalReceptionActorDestroyedDuringLongPress(void)
381 TestApplication application;
384 GestureReceivedFunctor functor(data);
386 LongPressGestureDetector detector = LongPressGestureDetector::New();
387 detector.DetectedSignal().Connect(&application, functor);
389 // Actor lifetime is scoped
391 Actor actor = Actor::New();
392 actor.SetProperty( Actor::Property::SIZE, Vector2( 100.0f, 100.0f ) );
393 actor.SetProperty( Actor::Property::ANCHOR_POINT,AnchorPoint::TOP_LEFT);
394 Stage::GetCurrent().Add(actor);
397 application.SendNotification();
398 application.Render();
400 detector.Attach(actor);
402 // Start long press within the actor's area
403 TestGenerateLongPress( application, 20.0f, 20.0f );
404 DALI_TEST_EQUALS(true, data.functorCalled, TEST_LOCATION);
406 // Remove the actor from stage and reset the data
407 Stage::GetCurrent().Remove(actor);
410 application.SendNotification();
411 application.Render();
414 // Actor should now have been destroyed
417 TestEndLongPress( application, 20.0f, 20.0f);
418 DALI_TEST_EQUALS(false, data.functorCalled, TEST_LOCATION);
422 int UtcDaliLongPressGestureSignalReceptionRotatedActor(void)
424 TestApplication application;
426 Actor actor = Actor::New();
427 actor.SetProperty( Actor::Property::SIZE, Vector2( 100.0f, 100.0f ) );
428 actor.SetProperty( Actor::Property::ORIENTATION, Quaternion( Dali::Degree(90.0f), Vector3::ZAXIS ) );
429 Stage::GetCurrent().Add(actor);
432 application.SendNotification();
433 application.Render();
436 GestureReceivedFunctor functor(data);
438 LongPressGestureDetector detector = LongPressGestureDetector::New();
439 detector.Attach(actor);
440 detector.DetectedSignal().Connect(&application, functor);
443 TestGenerateLongPress( application, 5.0f, 5.0f );
444 TestEndLongPress( application, 5.0f, 5.0f);
445 DALI_TEST_EQUALS(true, data.functorCalled, TEST_LOCATION);
446 DALI_TEST_EQUALS(1u, data.receivedGesture.numberOfTouches, TEST_LOCATION);
447 DALI_TEST_EQUALS( Vector2(5.0f, 5.0f), data.receivedGesture.screenPoint, 0.1, TEST_LOCATION);
449 // Rotate actor again and render
450 actor.SetProperty( Actor::Property::ORIENTATION, Quaternion(Dali::Degree(180.0f), Vector3::ZAXIS) );
451 application.SendNotification();
452 application.Render();
454 // Do another long press, should still receive event
456 TestGenerateLongPress( application, 5.0f, 5.0f );
457 TestEndLongPress( application, 5.0f, 5.0f);
458 DALI_TEST_EQUALS(true, data.functorCalled, TEST_LOCATION);
459 DALI_TEST_EQUALS(1u, data.receivedGesture.numberOfTouches, TEST_LOCATION);
460 DALI_TEST_EQUALS( Vector2(5.0f, 5.0f), data.receivedGesture.screenPoint, 0.1, TEST_LOCATION);
462 // Rotate actor again and render
463 actor.SetProperty( Actor::Property::ORIENTATION, Quaternion(Dali::Degree(90.0f), Vector3::YAXIS) );
464 application.SendNotification();
465 application.Render();
467 // Do a long press, inside where the actor used to be, Should not receive the event
469 TestGenerateLongPress( application, 70.0f, 70.0f );
470 TestEndLongPress( application, 70.0f, 70.0f);
471 DALI_TEST_EQUALS(false, data.functorCalled, TEST_LOCATION);
475 int UtcDaliLongPressGestureSignalReceptionChildHit(void)
477 TestApplication application;
479 Actor parent = Actor::New();
480 parent.SetProperty( Actor::Property::SIZE, Vector2( 100.0f, 100.0f ) );
481 parent.SetProperty( Actor::Property::ANCHOR_POINT,AnchorPoint::TOP_LEFT);
482 Stage::GetCurrent().Add(parent);
484 // Set child to completely cover parent.
485 // Change rotation of child to be different from parent so that we can check if our local coordinate
486 // conversion of the parent actor is correct.
487 Actor child = Actor::New();
488 child.SetProperty( Actor::Property::SIZE, Vector2( 100.0f, 100.0f ) );
489 child.SetProperty( Actor::Property::ANCHOR_POINT,AnchorPoint::CENTER);
490 child.SetProperty( Actor::Property::PARENT_ORIGIN,ParentOrigin::CENTER);
491 child.SetProperty( Actor::Property::ORIENTATION, Quaternion(Dali::Degree(90.0f), Vector3::ZAXIS) );
494 TouchEventFunctor touchFunctor;
495 child.TouchedSignal().Connect(&application, touchFunctor);
498 application.SendNotification();
499 application.Render();
502 GestureReceivedFunctor functor(data);
504 LongPressGestureDetector detector = LongPressGestureDetector::New();
505 detector.Attach(parent);
506 detector.DetectedSignal().Connect(&application, functor);
508 // Do long press - hits child area but parent should still receive it
509 TestGenerateLongPress( application, 50.0f, 50.0f );
510 TestEndLongPress( application, 50.0f, 50.0f);
511 DALI_TEST_EQUALS(true, data.functorCalled, TEST_LOCATION);
512 DALI_TEST_EQUALS(true, parent == data.pressedActor, TEST_LOCATION);
513 DALI_TEST_EQUALS(Vector2(50.0f, 50.0f), data.receivedGesture.screenPoint, 0.01f, TEST_LOCATION);
515 // Attach child and generate same touch points
516 // (Also proves that you can detach and then re-attach another actor)
517 detector.Attach(child);
518 detector.Detach(parent);
520 // Do an entire long press, only check finished value
522 TestGenerateLongPress( application, 51.0f, 51.0f );
523 TestEndLongPress( application, 51.0f, 51.0f);
524 DALI_TEST_EQUALS(true, data.functorCalled, TEST_LOCATION);
525 DALI_TEST_EQUALS(true, child == data.pressedActor, TEST_LOCATION);
526 DALI_TEST_EQUALS(Vector2(51.0f, 51.0f), data.receivedGesture.screenPoint, 0.01f, TEST_LOCATION);
530 int UtcDaliLongPressGestureSignalReceptionAttachDetachMany(void)
532 TestApplication application;
534 Actor first = Actor::New();
535 first.SetProperty( Actor::Property::SIZE, Vector2( 100.0f, 100.0f ) );
536 first.SetProperty( Actor::Property::ANCHOR_POINT,AnchorPoint::TOP_LEFT);
537 Stage::GetCurrent().Add(first);
539 Actor second = Actor::New();
540 second.SetProperty( Actor::Property::SIZE, Vector2( 100.0f, 100.0f ) );
541 second.SetProperty( Actor::Property::POSITION_X, 100.0f);
542 second.SetProperty( Actor::Property::ANCHOR_POINT,AnchorPoint::TOP_LEFT);
543 Stage::GetCurrent().Add(second);
546 application.SendNotification();
547 application.Render();
550 GestureReceivedFunctor functor(data);
552 LongPressGestureDetector detector = LongPressGestureDetector::New();
553 detector.Attach(first);
554 detector.Attach(second);
555 detector.DetectedSignal().Connect(&application, functor);
557 // LongPress within second actor's area
558 TestGenerateLongPress( application, 120.0f, 10.0f );
559 TestEndLongPress( application, 120.0f, 10.0f);
560 DALI_TEST_EQUALS(true, data.functorCalled, TEST_LOCATION);
561 DALI_TEST_EQUALS(true, second == data.pressedActor, TEST_LOCATION);
563 // LongPress within first actor's area
565 TestGenerateLongPress( application, 20.0f, 10.0f );
566 TestEndLongPress( application, 20.0f, 10.0f);
567 DALI_TEST_EQUALS(true, data.functorCalled, TEST_LOCATION);
568 DALI_TEST_EQUALS(true, first == data.pressedActor, TEST_LOCATION);
570 // Detach the second actor
571 detector.Detach(second);
573 // second actor shouldn't receive event
575 TestGenerateLongPress( application, 120.0f, 10.0f );
576 TestEndLongPress( application, 120.0f, 10.0f);
577 DALI_TEST_EQUALS(false, data.functorCalled, TEST_LOCATION);
579 // first actor should continue receiving event
581 TestGenerateLongPress( application, 20.0f, 10.0f );
582 TestEndLongPress( application, 20.0f, 10.0f);
583 DALI_TEST_EQUALS(true, data.functorCalled, TEST_LOCATION);
587 int UtcDaliLongPressGestureSignalReceptionActorBecomesUntouchable(void)
589 TestApplication application;
591 Actor actor = Actor::New();
592 actor.SetProperty( Actor::Property::SIZE, Vector2( 100.0f, 100.0f ) );
593 actor.SetProperty( Actor::Property::ANCHOR_POINT,AnchorPoint::TOP_LEFT);
594 Stage::GetCurrent().Add(actor);
597 application.SendNotification();
598 application.Render();
601 GestureReceivedFunctor functor(data);
603 LongPressGestureDetector detector = LongPressGestureDetector::New();
604 detector.Attach(actor);
605 detector.DetectedSignal().Connect(&application, functor);
607 // LongPress in actor's area
608 TestGenerateLongPress( application, 50.0f, 10.0f );
609 TestEndLongPress( application, 50.0f, 10.0f);
610 DALI_TEST_EQUALS(true, data.functorCalled, TEST_LOCATION);
612 // Actor becomes invisible - actor should not receive the next long press
613 actor.SetProperty( Actor::Property::VISIBLE,false);
616 application.SendNotification();
617 application.Render();
619 // LongPress in the same area, shouldn't receive event
621 TestGenerateLongPress( application, 50.0f, 10.0f );
622 TestEndLongPress( application, 50.0f, 10.0f);
623 DALI_TEST_EQUALS(false, data.functorCalled, TEST_LOCATION);
627 int UtcDaliLongPressGestureSignalReceptionMultipleDetectorsOnActor(void)
629 TestApplication application;
631 Actor actor = Actor::New();
632 actor.SetProperty( Actor::Property::SIZE, Vector2( 100.0f, 100.0f ) );
633 actor.SetProperty( Actor::Property::ANCHOR_POINT,AnchorPoint::TOP_LEFT);
634 Stage::GetCurrent().Add(actor);
637 application.SendNotification();
638 application.Render();
640 // Attach actor to one detector
641 SignalData firstData;
642 GestureReceivedFunctor firstFunctor(firstData);
643 LongPressGestureDetector firstDetector = LongPressGestureDetector::New();
644 firstDetector.Attach(actor);
645 firstDetector.DetectedSignal().Connect(&application, firstFunctor);
647 // Attach actor to another detector
648 SignalData secondData;
649 GestureReceivedFunctor secondFunctor(secondData);
650 LongPressGestureDetector secondDetector = LongPressGestureDetector::New();
651 secondDetector.Attach(actor);
652 secondDetector.DetectedSignal().Connect(&application, secondFunctor);
654 // LongPress in actor's area - both detector's functors should be called
655 TestGenerateLongPress( application, 50.0f, 10.0f );
656 DALI_TEST_EQUALS(true, firstData.functorCalled, TEST_LOCATION);
657 DALI_TEST_EQUALS(true, secondData.functorCalled, TEST_LOCATION);
661 int UtcDaliLongPressGestureSignalReceptionDifferentPossible(void)
663 TestApplication application;
665 Actor actor = Actor::New();
666 actor.SetProperty( Actor::Property::SIZE, Vector2( 100.0f, 100.0f ) );
667 actor.SetProperty( Actor::Property::ANCHOR_POINT,AnchorPoint::TOP_LEFT);
668 Stage::GetCurrent().Add(actor);
671 application.SendNotification();
672 application.Render();
674 // Attach actor to detector
676 GestureReceivedFunctor functor( data );
677 LongPressGestureDetector detector = LongPressGestureDetector::New();
678 detector.Attach(actor);
679 detector.DetectedSignal().Connect( &application, functor );
681 // LongPress possible in actor's area.
682 TestStartLongPress( application, 50.0f, 10.0f );
683 DALI_TEST_EQUALS(false, data.functorCalled, TEST_LOCATION);
685 // Move actor somewhere else
686 actor.SetProperty( Actor::Property::POSITION, Vector2( 100.0f, 100.0f ));
689 application.SendNotification();
690 application.Render();
692 // Emit Started event, we should not receive the long press.
693 TestTriggerLongPress( application );
694 TestGenerateLongPress( application, 50.0f, 10.0f );
695 DALI_TEST_EQUALS(false, data.functorCalled, TEST_LOCATION);
697 // LongPress possible in empty area.
698 TestStartLongPress( application, 50.0f, 10.0f );
699 DALI_TEST_EQUALS(false, data.functorCalled, TEST_LOCATION);
701 // Move actor in to the long press position.
702 actor.SetProperty( Actor::Property::POSITION, Vector2( 0.0f, 0.0f ));
705 application.SendNotification();
706 application.Render();
708 // Emit Started event, we should not receive the long press.
709 TestTriggerLongPress( application );
710 TestEndLongPress( application, 50.0f, 10.0f );
711 DALI_TEST_EQUALS(false, data.functorCalled, TEST_LOCATION);
713 // Normal long press in actor's area for completeness.
714 TestGenerateLongPress( application, 50.0f, 10.0f );
715 TestEndLongPress( application, 50.0f, 10.0f);
716 DALI_TEST_EQUALS(true, data.functorCalled, TEST_LOCATION);
720 int UtcDaliLongPressGesturePossibleCancelled(void)
722 TestApplication application;
724 Actor actor = Actor::New();
725 actor.SetProperty( Actor::Property::SIZE, Vector2( 100.0f, 100.0f ) );
726 actor.SetProperty( Actor::Property::ANCHOR_POINT,AnchorPoint::TOP_LEFT);
727 Stage::GetCurrent().Add(actor);
730 application.SendNotification();
731 application.Render();
733 // Attach actor to detector
735 GestureReceivedFunctor functor( data );
736 LongPressGestureDetector detector = LongPressGestureDetector::New();
737 detector.Attach(actor);
738 detector.DetectedSignal().Connect( &application, functor );
740 // Send a possible followed by a cancel, we should not be signalled
741 TestStartLongPress( application, 50.0f, 10.0f );
742 DALI_TEST_EQUALS(false, data.functorCalled, TEST_LOCATION);
743 TestMovePan( application, Vector2( 50.0f, 10.0f ) );
744 DALI_TEST_EQUALS(false, data.functorCalled, TEST_LOCATION);
748 int UtcDaliLongPressGestureDetachAfterStarted(void)
750 TestApplication application;
752 Actor actor = Actor::New();
753 actor.SetProperty( Actor::Property::SIZE, Vector2( 100.0f, 100.0f ) );
754 actor.SetProperty( Actor::Property::ANCHOR_POINT,AnchorPoint::TOP_LEFT);
755 Stage::GetCurrent().Add(actor);
758 application.SendNotification();
759 application.Render();
761 // Attach actor to detector
763 GestureReceivedFunctor functor( data );
764 LongPressGestureDetector detector = LongPressGestureDetector::New();
765 detector.Attach(actor);
766 detector.DetectedSignal().Connect( &application, functor );
768 // Emit initial signal
769 TestGenerateLongPress( application, 50.0f, 10.0f );
770 DALI_TEST_EQUALS(true, data.functorCalled, TEST_LOCATION);
774 detector.Detach(actor);
776 // Emit Finished, no signal
777 TestEndLongPress( application, 50.0f, 10.0f );
778 DALI_TEST_EQUALS(false, data.functorCalled, TEST_LOCATION);
782 int UtcDaliLongPressGestureActorUnstaged(void)
784 TestApplication application;
786 Actor actor = Actor::New();
787 actor.SetProperty( Actor::Property::SIZE, Vector2( 100.0f, 100.0f ) );
788 actor.SetProperty( Actor::Property::ANCHOR_POINT,AnchorPoint::TOP_LEFT);
789 Stage::GetCurrent().Add(actor);
792 application.SendNotification();
793 application.Render();
795 // State to remove actor in.
796 Gesture::State stateToUnstage( Gesture::Started );
798 // Attach actor to detector
800 UnstageActorFunctor functor( data, stateToUnstage );
801 LongPressGestureDetector detector = LongPressGestureDetector::New();
802 detector.Attach(actor);
803 detector.DetectedSignal().Connect( &application, functor );
806 TestGenerateLongPress( application, 50.0f, 10.0f );
807 DALI_TEST_EQUALS(true, data.functorCalled, TEST_LOCATION);
809 TestEndLongPress( application, 50.0f, 10.0f );
810 DALI_TEST_EQUALS(false, data.functorCalled, TEST_LOCATION);
813 application.SendNotification();
814 application.Render();
816 // Re-add actor to stage
817 Stage::GetCurrent().Add(actor);
820 application.SendNotification();
821 application.Render();
823 // Change state to Gesture::Continuing to remove
824 stateToUnstage = Gesture::Finished;
827 TestGenerateLongPress( application, 50.0f, 10.0f );
828 DALI_TEST_EQUALS(true, data.functorCalled, TEST_LOCATION);
830 TestEndLongPress( application, 50.0f, 10.0f );
831 DALI_TEST_EQUALS(true, data.functorCalled, TEST_LOCATION);
832 tet_result( TET_PASS ); // If we get here then we have handled actor stage removal gracefully.
836 int UtcDaliLongPressGestureActorStagedAndDestroyed(void)
838 TestApplication application;
840 Actor actor = Actor::New();
841 actor.SetProperty( Actor::Property::SIZE, Vector2( 100.0f, 100.0f ) );
842 actor.SetProperty( Actor::Property::ANCHOR_POINT,AnchorPoint::TOP_LEFT);
843 Stage::GetCurrent().Add(actor);
845 // Create and add a second actor so that GestureDetector destruction does not come into play.
846 Actor dummyActor( Actor::New() );
847 dummyActor.SetProperty( Actor::Property::SIZE, Vector2( 100.0f, 100.0f ) );
848 dummyActor.SetProperty( Actor::Property::POSITION, Vector2( 100.0f, 100.0f ));
849 dummyActor.SetProperty( Actor::Property::ANCHOR_POINT,AnchorPoint::TOP_LEFT);
850 Stage::GetCurrent().Add(dummyActor);
853 application.SendNotification();
854 application.Render();
856 // State to remove actor in.
857 Gesture::State stateToUnstage( Gesture::Started );
859 // Attach actor to detector
861 UnstageActorFunctor functor( data, stateToUnstage );
862 LongPressGestureDetector detector = LongPressGestureDetector::New();
863 detector.Attach(actor);
864 detector.Attach(dummyActor);
865 detector.DetectedSignal().Connect( &application, functor );
867 // Here we are testing a Started actor which is removed in the Started callback, but then added back
868 // before we get a finished state. As we were removed from the stage, even if we're at the same
869 // position, we should still not be signalled.
872 TestGenerateLongPress( application, 50.0f, 10.0f );
873 DALI_TEST_EQUALS(true, data.functorCalled, TEST_LOCATION);
877 application.SendNotification();
878 application.Render();
880 // Re add to the stage, we should not be signalled
881 Stage::GetCurrent().Add(actor);
884 application.SendNotification();
885 application.Render();
887 // Continue signal emission
888 TestEndLongPress( application, 50.0f, 10.0f );
889 DALI_TEST_EQUALS(false, data.functorCalled, TEST_LOCATION);
892 // Here we delete an actor in started, we should not receive any subsequent signalling.
895 TestGenerateLongPress( application, 50.0f, 10.0f );
896 DALI_TEST_EQUALS(true, data.functorCalled, TEST_LOCATION);
900 application.SendNotification();
901 application.Render();
903 // Delete actor as well
907 application.SendNotification();
908 application.Render();
910 // Continue signal emission
911 TestEndLongPress( application, 50.0f, 10.0f );
912 DALI_TEST_EQUALS(false, data.functorCalled, TEST_LOCATION);
916 int UtcDaliLongPressGestureLayerConsumesTouch(void)
918 TestApplication application;
920 Actor actor = Actor::New();
921 actor.SetProperty( Actor::Property::SIZE, Vector2( 100.0f, 100.0f ) );
922 actor.SetProperty( Actor::Property::ANCHOR_POINT,AnchorPoint::TOP_LEFT);
923 Stage::GetCurrent().Add(actor);
927 GestureReceivedFunctor functor(data);
928 LongPressGestureDetector detector = LongPressGestureDetector::New();
929 detector.Attach(actor);
930 detector.DetectedSignal().Connect( &application, functor );
932 // Add a layer to overlap the actor
933 Layer layer = Layer::New();
934 layer.SetProperty( Actor::Property::SIZE, Vector2( 100.0f, 100.0f ) );
935 layer.SetProperty( Actor::Property::ANCHOR_POINT,AnchorPoint::TOP_LEFT);
936 Stage::GetCurrent().Add( layer );
940 application.SendNotification();
941 application.Render();
943 // Emit signals, should receive
944 TestGenerateLongPress( application, 50.0f, 50.0f );
945 TestEndLongPress( application, 50.0f, 50.0f );
946 DALI_TEST_EQUALS(true, data.functorCalled, TEST_LOCATION);
949 // Set layer to consume all touch
950 layer.SetProperty( Layer::Property::CONSUMES_TOUCH, true );
953 application.SendNotification();
954 application.Render();
956 // Emit the same signals again, should not receive
957 TestGenerateLongPress( application, 50.0f, 50.0f );
958 TestEndLongPress( application, 50.0f, 50.0f );
959 DALI_TEST_EQUALS(false, data.functorCalled, TEST_LOCATION);
965 int UtcDaliLongPressGestureSetMinimumHoldingTime(void)
967 TestApplication application;
969 const uint32_t kMinumumHolding1 = 5000;
970 const uint32_t kMinumumHolding2 = 3000;
972 Integration::SetLongPressMinimumHoldingTime( kMinumumHolding1 );
974 Actor actor = Actor::New();
975 actor.SetProperty( Actor::Property::SIZE, Vector2( 100.0f, 100.0f ) );
976 actor.SetProperty( Actor::Property::ANCHOR_POINT, AnchorPoint::TOP_LEFT );
977 Stage::GetCurrent().Add( actor );
980 application.SendNotification();
981 application.Render();
984 GestureReceivedFunctor functor( data );
986 LongPressGestureDetector detector = LongPressGestureDetector::New();
987 detector.Attach(actor);
988 detector.DetectedSignal().Connect(&application, functor);
990 DALI_TEST_EQUALS( DevelLongPressGestureDetector::GetMinimumHoldingTime( detector ), kMinumumHolding1, TEST_LOCATION );
992 Integration::SetLongPressMinimumHoldingTime( kMinumumHolding2 );
993 DALI_TEST_EQUALS( DevelLongPressGestureDetector::GetMinimumHoldingTime( detector ), kMinumumHolding2, TEST_LOCATION );