Revert "Revert "HoverEvent class pimpling""
[platform/core/uifw/dali-core.git] / automated-tests / src / dali / utc-Dali-LongPressGestureDetector.cpp
1 /*
2  * Copyright (c) 2020 Samsung Electronics Co., Ltd.
3  *
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
7  *
8  * http://www.apache.org/licenses/LICENSE-2.0
9  *
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.
15  *
16  */
17
18 #include <iostream>
19
20 #include <stdlib.h>
21 #include <dali/public-api/dali-core.h>
22 #include <dali/integration-api/events/touch-event-integ.h>
23 #include <dali/integration-api/input-options.h>
24 #include <dali/integration-api/render-task-list-integ.h>
25 #include <dali/devel-api/events/long-press-gesture-detector-devel.h>
26 #include <dali-test-suite-utils.h>
27 #include <test-touch-utils.h>
28 #include <test-touch-data-utils.h>
29
30 using namespace Dali;
31
32 void utc_dali_long_press_gesture_detector_startup(void)
33 {
34   test_return_value = TET_UNDEF;
35 }
36
37 void utc_dali_long_press_gesture_detector_cleanup(void)
38 {
39   test_return_value = TET_PASS;
40 }
41
42 ///////////////////////////////////////////////////////////////////////////////
43 namespace
44 {
45
46 // Stores data that is populated in the callback and will be read by the TET cases
47 struct SignalData
48 {
49   SignalData()
50   : functorCalled( false ),
51     voidFunctorCalled( false ),
52     receivedGesture( Gesture::Clear ),
53     pressedActor()
54   {}
55
56   void Reset()
57   {
58     functorCalled = false;
59     voidFunctorCalled = false;
60
61     receivedGesture.numberOfTouches = 0u;
62     receivedGesture.screenPoint = Vector2(0.0f, 0.0f);
63     receivedGesture.localPoint = Vector2(0.0f, 0.0f);
64
65     pressedActor.Reset();
66   }
67
68   bool functorCalled;
69   bool voidFunctorCalled;
70   LongPressGesture receivedGesture;
71   Actor pressedActor;
72 };
73
74 // Functor that sets the data when called
75 struct GestureReceivedFunctor
76 {
77   GestureReceivedFunctor(SignalData& data) : signalData(data) { }
78
79   void operator()(Actor actor, const LongPressGesture& longPress)
80   {
81     signalData.functorCalled = true;
82     signalData.receivedGesture = longPress;
83     signalData.pressedActor = actor;
84   }
85
86   void operator()()
87   {
88     signalData.voidFunctorCalled = true;
89   }
90
91   SignalData& signalData;
92 };
93
94 // Functor that removes the gestured actor from stage
95 struct UnstageActorFunctor : public GestureReceivedFunctor
96 {
97   UnstageActorFunctor( SignalData& data, Gesture::State& stateToUnstage, Integration::Scene scene )
98   : GestureReceivedFunctor( data ),
99     stateToUnstage( stateToUnstage ),
100     scene( scene )
101   {
102   }
103
104   void operator()( Actor actor, const LongPressGesture& longPress )
105   {
106     GestureReceivedFunctor::operator()( actor, longPress );
107
108     if ( longPress.state == stateToUnstage )
109     {
110       scene.Remove( actor );
111     }
112   }
113
114   Gesture::State& stateToUnstage;
115   Integration::Scene scene;
116 };
117
118 // Functor for receiving a touch event
119 struct TouchEventFunctor
120 {
121   bool operator()(Actor actor, const TouchEvent& touch)
122   {
123     //For line coverage
124     unsigned int points = touch.GetPointCount();
125     if( points > 0)
126     {
127       const TouchPoint& touchPoint = touch.GetPoint(0);
128       tet_printf("Touch Point state = %d\n", touchPoint.state);
129     }
130     return false;
131   }
132 };
133
134 } // anon namespace
135
136 ///////////////////////////////////////////////////////////////////////////////
137
138
139 // Positive test case for a method
140 int UtcDaliLongPressGestureDetectorConstructorP(void)
141 {
142   TestApplication application;
143
144   LongPressGestureDetector detector;
145   DALI_TEST_CHECK(!detector);
146   END_TEST;
147 }
148
149 int UtcDaliLongPressGestureDetectorCopyConstructorP(void)
150 {
151   TestApplication application;
152
153   LongPressGestureDetector detector = LongPressGestureDetector::New();;
154
155   LongPressGestureDetector copy( detector );
156   DALI_TEST_CHECK( detector );
157   END_TEST;
158 }
159
160 int UtcDaliLongPressGestureDetectorAssignmentOperatorP(void)
161 {
162   TestApplication application;
163
164   LongPressGestureDetector detector;
165   detector = LongPressGestureDetector::New();;
166
167   LongPressGestureDetector copy;
168   copy = detector;
169   DALI_TEST_CHECK( detector );
170
171   DALI_TEST_CHECK( detector == copy );
172   END_TEST;
173 }
174
175 int UtcDaliLongPressGestureDetectorNew(void)
176 {
177   TestApplication application;
178
179   LongPressGestureDetector detector = LongPressGestureDetector::New();
180   DALI_TEST_CHECK(detector);
181   DALI_TEST_EQUALS(1u, detector.GetMinimumTouchesRequired(), TEST_LOCATION);
182   DALI_TEST_EQUALS(1u, detector.GetMaximumTouchesRequired(), TEST_LOCATION);
183
184   LongPressGestureDetector detector2 = LongPressGestureDetector::New(5u);
185   DALI_TEST_CHECK(detector2);
186   DALI_TEST_EQUALS(5u, detector2.GetMinimumTouchesRequired(), TEST_LOCATION);
187   DALI_TEST_EQUALS(5u, detector2.GetMaximumTouchesRequired(), TEST_LOCATION);
188
189   LongPressGestureDetector detector3 = LongPressGestureDetector::New(5u, 7u);
190   DALI_TEST_CHECK(detector2);
191   DALI_TEST_EQUALS(5u, detector3.GetMinimumTouchesRequired(), TEST_LOCATION);
192   DALI_TEST_EQUALS(7u, detector3.GetMaximumTouchesRequired(), TEST_LOCATION);
193
194   //Scoped test to test destructor
195   {
196     LongPressGestureDetector detector4 = LongPressGestureDetector::New();
197     DALI_TEST_CHECK(detector4);
198   }
199
200   // Attach an actor and emit a touch event on the actor to ensure complete line coverage
201   Actor actor = Actor::New();
202   actor.SetProperty( Actor::Property::SIZE, Vector2( 100.0f, 100.0f ) );
203   actor.SetProperty( Actor::Property::ANCHOR_POINT,AnchorPoint::TOP_LEFT);
204   application.GetScene().Add(actor);
205
206   // Render and notify
207   application.SendNotification();
208   application.Render();
209
210   detector.Attach(actor);
211
212   TouchEventFunctor touchFunctor;
213   actor.TouchedSignal().Connect(&application, touchFunctor);
214
215   Integration::TouchEvent touchEvent(1);
216   Integration::Point point;
217   point.SetDeviceId( 1 );
218   point.SetState( PointState::DOWN );
219   point.SetScreenPosition( Vector2( 20.0f, 20.0f ) );
220   touchEvent.AddPoint(point);
221   application.ProcessEvent(touchEvent);
222
223   // Render and notify
224   application.SendNotification();
225   application.Render();
226
227   // For line coverage, Initialise default constructor
228   TouchEvent touchEvent2;
229   END_TEST;
230 }
231
232 int UtcDaliLongPressGestureDetectorDownCast(void)
233 {
234   TestApplication application;
235   tet_infoline("Testing Dali::LongPressGestureDetector::DownCast()");
236
237   LongPressGestureDetector detector = LongPressGestureDetector::New();
238
239   BaseHandle object(detector);
240
241   LongPressGestureDetector detector2 = LongPressGestureDetector::DownCast(object);
242   DALI_TEST_CHECK(detector2);
243
244   LongPressGestureDetector detector3 = DownCast< LongPressGestureDetector >(object);
245   DALI_TEST_CHECK(detector3);
246
247   BaseHandle unInitializedObject;
248   LongPressGestureDetector detector4 = LongPressGestureDetector::DownCast(unInitializedObject);
249   DALI_TEST_CHECK(!detector4);
250
251   LongPressGestureDetector detector5 = DownCast< LongPressGestureDetector >(unInitializedObject);
252   DALI_TEST_CHECK(!detector5);
253
254   GestureDetector detector6 = LongPressGestureDetector::New();
255   LongPressGestureDetector detector7 = LongPressGestureDetector::DownCast(detector6);
256   DALI_TEST_CHECK(detector7);
257   END_TEST;
258 }
259
260 int UtcDaliLongPressGestureGetMinimumTouchesRequired(void)
261 {
262   TestApplication application;
263
264   LongPressGestureDetector detector = LongPressGestureDetector::New();
265   DALI_TEST_EQUALS(1u, detector.GetMinimumTouchesRequired(), TEST_LOCATION);
266   END_TEST;
267 }
268
269 int UtcDaliLongPressGestureGetMaximumTouchesRequired(void)
270 {
271   TestApplication application;
272
273   LongPressGestureDetector detector = LongPressGestureDetector::New();
274   DALI_TEST_EQUALS(1u, detector.GetMaximumTouchesRequired(), TEST_LOCATION);
275   END_TEST;
276 }
277
278 int UtcDaliLongPressGestureSignalReceptionNegative(void)
279 {
280   TestApplication application;
281
282   Actor actor = Actor::New();
283   actor.SetProperty( Actor::Property::SIZE, Vector2( 100.0f, 100.0f ) );
284   actor.SetProperty( Actor::Property::ANCHOR_POINT,AnchorPoint::TOP_LEFT);
285   application.GetScene().Add(actor);
286
287   // Render and notify
288   application.SendNotification();
289   application.Render();
290
291   SignalData data;
292   GestureReceivedFunctor functor(data);
293
294   LongPressGestureDetector detector = LongPressGestureDetector::New();
295   detector.Attach(actor);
296   detector.DetectedSignal().Connect(&application, functor);
297
298   // Do a long press outside actor's area
299   TestGenerateLongPress( application, 112.0f, 112.0f );
300   TestEndLongPress( application, 112.0f, 112.0f);
301
302   DALI_TEST_EQUALS(false, data.functorCalled, TEST_LOCATION);
303   END_TEST;
304 }
305
306 int UtcDaliLongPressGestureSignalReceptionPositive(void)
307 {
308   TestApplication application;
309
310   Actor actor = Actor::New();
311   actor.SetProperty( Actor::Property::SIZE, Vector2( 100.0f, 100.0f ) );
312   actor.SetProperty( Actor::Property::ANCHOR_POINT,AnchorPoint::TOP_LEFT);
313   application.GetScene().Add(actor);
314
315   // Render and notify
316   application.SendNotification();
317   application.Render();
318
319   SignalData data;
320   GestureReceivedFunctor functor(data);
321
322   LongPressGestureDetector detector = LongPressGestureDetector::New();
323   detector.Attach(actor);
324   detector.DetectedSignal().Connect(&application, functor);
325
326   // Do a long press inside actor's area
327   TestGenerateLongPress( application, 50.0f, 50.0f );
328   DALI_TEST_EQUALS(true, data.functorCalled, TEST_LOCATION);
329   DALI_TEST_EQUALS(1u, data.receivedGesture.numberOfTouches, TEST_LOCATION);
330   DALI_TEST_EQUALS( Vector2(50.0f, 50.0f), data.receivedGesture.localPoint, 0.1, TEST_LOCATION);
331   TestEndLongPress( application, 50.0f, 50.0f);
332   END_TEST;
333 }
334
335 int UtcDaliLongPressGestureSignalReceptionDetach(void)
336 {
337   TestApplication application;
338
339   Actor actor = Actor::New();
340   actor.SetProperty( Actor::Property::SIZE, Vector2( 100.0f, 100.0f ) );
341   actor.SetProperty( Actor::Property::ANCHOR_POINT,AnchorPoint::TOP_LEFT);
342   application.GetScene().Add(actor);
343
344   // Render and notify
345   application.SendNotification();
346   application.Render();
347
348   SignalData data;
349   GestureReceivedFunctor functor(data);
350
351   LongPressGestureDetector detector = LongPressGestureDetector::New();
352   detector.Attach(actor);
353   detector.DetectedSignal().Connect(&application, functor);
354
355   // Start long press within the actor's area
356   TestGenerateLongPress( application, 20.0f, 20.0f );
357   DALI_TEST_EQUALS(true, data.functorCalled, TEST_LOCATION);
358   DALI_TEST_EQUALS(1u, data.receivedGesture.numberOfTouches, TEST_LOCATION);
359   DALI_TEST_EQUALS( Vector2(20.0f, 20.0f), data.receivedGesture.localPoint, 0.1, TEST_LOCATION);
360   TestEndLongPress( application, 20.0f, 20.0f);
361
362   // repeat the long press within the actor's area - we should still receive the signal
363   data.Reset();
364   TestGenerateLongPress( application, 50.0f, 50.0f );
365   DALI_TEST_EQUALS(true, data.functorCalled, TEST_LOCATION);
366   DALI_TEST_EQUALS(1u, data.receivedGesture.numberOfTouches, TEST_LOCATION);
367   DALI_TEST_EQUALS( Vector2(50.0f, 50.0f), data.receivedGesture.localPoint, 0.1, TEST_LOCATION);
368   TestEndLongPress( application, 50.0f, 50.0f);
369
370   // Detach actor
371   detector.DetachAll();
372
373   // Ensure we are no longer signalled
374   data.Reset();
375   TestGenerateLongPress( application, 20.0f, 20.0f );
376   DALI_TEST_EQUALS(false, data.functorCalled, TEST_LOCATION);
377   TestEndLongPress( application, 50.0f, 50.0f);
378   DALI_TEST_EQUALS(false, data.functorCalled, TEST_LOCATION);
379   END_TEST;
380 }
381
382 int UtcDaliLongPressGestureSignalReceptionActorDestroyedDuringLongPress(void)
383 {
384   TestApplication application;
385
386   SignalData data;
387   GestureReceivedFunctor functor(data);
388
389   LongPressGestureDetector detector = LongPressGestureDetector::New();
390   detector.DetectedSignal().Connect(&application, functor);
391
392   // Actor lifetime is scoped
393   {
394     Actor actor = Actor::New();
395     actor.SetProperty( Actor::Property::SIZE, Vector2( 100.0f, 100.0f ) );
396     actor.SetProperty( Actor::Property::ANCHOR_POINT,AnchorPoint::TOP_LEFT);
397     application.GetScene().Add(actor);
398
399     // Render and notify
400     application.SendNotification();
401     application.Render();
402
403     detector.Attach(actor);
404
405     // Start long press within the actor's area
406     TestGenerateLongPress( application, 20.0f, 20.0f );
407     DALI_TEST_EQUALS(true, data.functorCalled, TEST_LOCATION);
408
409     // Remove the actor from stage and reset the data
410     application.GetScene().Remove(actor);
411
412     // Render and notify
413     application.SendNotification();
414     application.Render();
415   }
416
417   // Actor should now have been destroyed
418
419   data.Reset();
420   TestEndLongPress( application, 20.0f, 20.0f);
421   DALI_TEST_EQUALS(false, data.functorCalled, TEST_LOCATION);
422   END_TEST;
423 }
424
425 int UtcDaliLongPressGestureSignalReceptionRotatedActor(void)
426 {
427   TestApplication application;
428
429   Actor actor = Actor::New();
430   actor.SetProperty( Actor::Property::SIZE, Vector2( 100.0f, 100.0f ) );
431   actor.SetProperty( Actor::Property::ORIENTATION, Quaternion( Dali::Degree(90.0f), Vector3::ZAXIS ) );
432   application.GetScene().Add(actor);
433
434   // Render and notify
435   application.SendNotification();
436   application.Render();
437
438   SignalData data;
439   GestureReceivedFunctor functor(data);
440
441   LongPressGestureDetector detector = LongPressGestureDetector::New();
442   detector.Attach(actor);
443   detector.DetectedSignal().Connect(&application, functor);
444
445   // Do a long press
446   TestGenerateLongPress( application, 5.0f, 5.0f );
447   TestEndLongPress( application, 5.0f, 5.0f);
448   DALI_TEST_EQUALS(true, data.functorCalled, TEST_LOCATION);
449   DALI_TEST_EQUALS(1u, data.receivedGesture.numberOfTouches, TEST_LOCATION);
450   DALI_TEST_EQUALS( Vector2(5.0f, 5.0f), data.receivedGesture.screenPoint, 0.1, TEST_LOCATION);
451
452   // Rotate actor again and render
453   actor.SetProperty( Actor::Property::ORIENTATION, Quaternion(Dali::Degree(180.0f), Vector3::ZAXIS) );
454   application.SendNotification();
455   application.Render();
456
457   // Do another long press, should still receive event
458   data.Reset();
459   TestGenerateLongPress( application, 5.0f, 5.0f );
460   TestEndLongPress( application, 5.0f, 5.0f);
461   DALI_TEST_EQUALS(true, data.functorCalled, TEST_LOCATION);
462   DALI_TEST_EQUALS(1u, data.receivedGesture.numberOfTouches, TEST_LOCATION);
463   DALI_TEST_EQUALS( Vector2(5.0f, 5.0f), data.receivedGesture.screenPoint, 0.1, TEST_LOCATION);
464
465   // Rotate actor again and render
466   actor.SetProperty( Actor::Property::ORIENTATION, Quaternion(Dali::Degree(90.0f), Vector3::YAXIS) );
467   application.SendNotification();
468   application.Render();
469
470   // Do a long press, inside where the actor used to be, Should not receive the event
471   data.Reset();
472   TestGenerateLongPress( application, 70.0f, 70.0f );
473   TestEndLongPress( application, 70.0f, 70.0f);
474   DALI_TEST_EQUALS(false, data.functorCalled, TEST_LOCATION);
475   END_TEST;
476 }
477
478 int UtcDaliLongPressGestureSignalReceptionChildHit(void)
479 {
480   TestApplication application;
481
482   Actor parent = Actor::New();
483   parent.SetProperty( Actor::Property::SIZE, Vector2( 100.0f, 100.0f ) );
484   parent.SetProperty( Actor::Property::ANCHOR_POINT,AnchorPoint::TOP_LEFT);
485   application.GetScene().Add(parent);
486
487   // Set child to completely cover parent.
488   // Change rotation of child to be different from parent so that we can check if our local coordinate
489   // conversion of the parent actor is correct.
490   Actor child = Actor::New();
491   child.SetProperty( Actor::Property::SIZE, Vector2( 100.0f, 100.0f ) );
492   child.SetProperty( Actor::Property::ANCHOR_POINT,AnchorPoint::CENTER);
493   child.SetProperty( Actor::Property::PARENT_ORIGIN,ParentOrigin::CENTER);
494   child.SetProperty( Actor::Property::ORIENTATION, Quaternion(Dali::Degree(90.0f), Vector3::ZAXIS) );
495   parent.Add(child);
496
497   TouchEventFunctor touchFunctor;
498   child.TouchedSignal().Connect(&application, touchFunctor);
499
500   // Render and notify
501   application.SendNotification();
502   application.Render();
503
504   SignalData data;
505   GestureReceivedFunctor functor(data);
506
507   LongPressGestureDetector detector = LongPressGestureDetector::New();
508   detector.Attach(parent);
509   detector.DetectedSignal().Connect(&application, functor);
510
511   // Do long press - hits child area but parent should still receive it
512   TestGenerateLongPress( application, 50.0f, 50.0f );
513   TestEndLongPress( application, 50.0f, 50.0f);
514   DALI_TEST_EQUALS(true, data.functorCalled, TEST_LOCATION);
515   DALI_TEST_EQUALS(true, parent == data.pressedActor, TEST_LOCATION);
516   DALI_TEST_EQUALS(Vector2(50.0f, 50.0f), data.receivedGesture.screenPoint, 0.01f, TEST_LOCATION);
517
518   // Attach child and generate same touch points
519   // (Also proves that you can detach and then re-attach another actor)
520   detector.Attach(child);
521   detector.Detach(parent);
522
523   // Do an entire long press, only check finished value
524   data.Reset();
525   TestGenerateLongPress( application, 51.0f, 51.0f );
526   TestEndLongPress( application, 51.0f, 51.0f);
527   DALI_TEST_EQUALS(true, data.functorCalled, TEST_LOCATION);
528   DALI_TEST_EQUALS(true, child == data.pressedActor, TEST_LOCATION);
529   DALI_TEST_EQUALS(Vector2(51.0f, 51.0f), data.receivedGesture.screenPoint, 0.01f, TEST_LOCATION);
530   END_TEST;
531 }
532
533 int UtcDaliLongPressGestureSignalReceptionAttachDetachMany(void)
534 {
535   TestApplication application;
536
537   Actor first = Actor::New();
538   first.SetProperty( Actor::Property::SIZE, Vector2( 100.0f, 100.0f ) );
539   first.SetProperty( Actor::Property::ANCHOR_POINT,AnchorPoint::TOP_LEFT);
540   application.GetScene().Add(first);
541
542   Actor second = Actor::New();
543   second.SetProperty( Actor::Property::SIZE, Vector2( 100.0f, 100.0f ) );
544   second.SetProperty( Actor::Property::POSITION_X, 100.0f);
545   second.SetProperty( Actor::Property::ANCHOR_POINT,AnchorPoint::TOP_LEFT);
546   application.GetScene().Add(second);
547
548   // Render and notify
549   application.SendNotification();
550   application.Render();
551
552   SignalData data;
553   GestureReceivedFunctor functor(data);
554
555   LongPressGestureDetector detector = LongPressGestureDetector::New();
556   detector.Attach(first);
557   detector.Attach(second);
558   detector.DetectedSignal().Connect(&application, functor);
559
560   // LongPress within second actor's area
561   TestGenerateLongPress( application, 120.0f, 10.0f );
562   TestEndLongPress( application, 120.0f, 10.0f);
563   DALI_TEST_EQUALS(true, data.functorCalled, TEST_LOCATION);
564   DALI_TEST_EQUALS(true, second == data.pressedActor, TEST_LOCATION);
565
566   // LongPress within first actor's area
567   data.Reset();
568   TestGenerateLongPress( application, 20.0f, 10.0f );
569   TestEndLongPress( application, 20.0f, 10.0f);
570   DALI_TEST_EQUALS(true, data.functorCalled, TEST_LOCATION);
571   DALI_TEST_EQUALS(true, first == data.pressedActor, TEST_LOCATION);
572
573   // Detach the second actor
574   detector.Detach(second);
575
576   // second actor shouldn't receive event
577   data.Reset();
578   TestGenerateLongPress( application, 120.0f, 10.0f );
579   TestEndLongPress( application, 120.0f, 10.0f);
580   DALI_TEST_EQUALS(false, data.functorCalled, TEST_LOCATION);
581
582   // first actor should continue receiving event
583   data.Reset();
584   TestGenerateLongPress( application, 20.0f, 10.0f );
585   TestEndLongPress( application, 20.0f, 10.0f);
586   DALI_TEST_EQUALS(true, data.functorCalled, TEST_LOCATION);
587   END_TEST;
588 }
589
590 int UtcDaliLongPressGestureSignalReceptionActorBecomesUntouchable(void)
591 {
592   TestApplication application;
593
594   Actor actor = Actor::New();
595   actor.SetProperty( Actor::Property::SIZE, Vector2( 100.0f, 100.0f ) );
596   actor.SetProperty( Actor::Property::ANCHOR_POINT,AnchorPoint::TOP_LEFT);
597   application.GetScene().Add(actor);
598
599   // Render and notify
600   application.SendNotification();
601   application.Render();
602
603   SignalData data;
604   GestureReceivedFunctor functor(data);
605
606   LongPressGestureDetector detector = LongPressGestureDetector::New();
607   detector.Attach(actor);
608   detector.DetectedSignal().Connect(&application, functor);
609
610   // LongPress in actor's area
611   TestGenerateLongPress( application, 50.0f, 10.0f );
612   TestEndLongPress( application, 50.0f, 10.0f);
613   DALI_TEST_EQUALS(true, data.functorCalled, TEST_LOCATION);
614
615   // Actor becomes invisible - actor should not receive the next long press
616   actor.SetProperty( Actor::Property::VISIBLE,false);
617
618   // Render and notify
619   application.SendNotification();
620   application.Render();
621
622   // LongPress in the same area, shouldn't receive event
623   data.Reset();
624   TestGenerateLongPress( application, 50.0f, 10.0f );
625   TestEndLongPress( application, 50.0f, 10.0f);
626   DALI_TEST_EQUALS(false, data.functorCalled, TEST_LOCATION);
627   END_TEST;
628 }
629
630 int UtcDaliLongPressGestureSignalReceptionMultipleDetectorsOnActor(void)
631 {
632   TestApplication application;
633
634   Actor actor = Actor::New();
635   actor.SetProperty( Actor::Property::SIZE, Vector2( 100.0f, 100.0f ) );
636   actor.SetProperty( Actor::Property::ANCHOR_POINT,AnchorPoint::TOP_LEFT);
637   application.GetScene().Add(actor);
638
639   // Render and notify
640   application.SendNotification();
641   application.Render();
642
643   // Attach actor to one detector
644   SignalData firstData;
645   GestureReceivedFunctor firstFunctor(firstData);
646   LongPressGestureDetector firstDetector = LongPressGestureDetector::New();
647   firstDetector.Attach(actor);
648   firstDetector.DetectedSignal().Connect(&application, firstFunctor);
649
650   // Attach actor to another detector
651   SignalData secondData;
652   GestureReceivedFunctor secondFunctor(secondData);
653   LongPressGestureDetector secondDetector = LongPressGestureDetector::New();
654   secondDetector.Attach(actor);
655   secondDetector.DetectedSignal().Connect(&application, secondFunctor);
656
657   // LongPress in actor's area - both detector's functors should be called
658   TestGenerateLongPress( application, 50.0f, 10.0f );
659   DALI_TEST_EQUALS(true, firstData.functorCalled, TEST_LOCATION);
660   DALI_TEST_EQUALS(true, secondData.functorCalled, TEST_LOCATION);
661   END_TEST;
662 }
663
664 int UtcDaliLongPressGestureSignalReceptionDifferentPossible(void)
665 {
666   TestApplication application;
667
668   Actor actor = Actor::New();
669   actor.SetProperty( Actor::Property::SIZE, Vector2( 100.0f, 100.0f ) );
670   actor.SetProperty( Actor::Property::ANCHOR_POINT,AnchorPoint::TOP_LEFT);
671   application.GetScene().Add(actor);
672
673   // Render and notify
674   application.SendNotification();
675   application.Render();
676
677   // Attach actor to detector
678   SignalData data;
679   GestureReceivedFunctor functor( data );
680   LongPressGestureDetector detector = LongPressGestureDetector::New();
681   detector.Attach(actor);
682   detector.DetectedSignal().Connect( &application, functor );
683
684   // LongPress possible in actor's area.
685   TestStartLongPress( application, 50.0f, 10.0f );
686   DALI_TEST_EQUALS(false, data.functorCalled, TEST_LOCATION);
687
688   // Move actor somewhere else
689   actor.SetProperty( Actor::Property::POSITION, Vector2( 100.0f, 100.0f ));
690
691   // Render and notify
692   application.SendNotification();
693   application.Render();
694
695   // Emit Started event, we should not receive the long press.
696   TestTriggerLongPress( application );
697   TestGenerateLongPress( application, 50.0f, 10.0f );
698   DALI_TEST_EQUALS(false, data.functorCalled, TEST_LOCATION);
699
700   // LongPress possible in empty area.
701   TestStartLongPress( application, 50.0f, 10.0f );
702   DALI_TEST_EQUALS(false, data.functorCalled, TEST_LOCATION);
703
704   // Move actor in to the long press position.
705   actor.SetProperty( Actor::Property::POSITION, Vector2( 0.0f, 0.0f ));
706
707   // Render and notify
708   application.SendNotification();
709   application.Render();
710
711   // Emit Started event, we should not receive the long press.
712   TestTriggerLongPress( application );
713   TestEndLongPress( application, 50.0f, 10.0f );
714   DALI_TEST_EQUALS(false, data.functorCalled, TEST_LOCATION);
715
716   // Normal long press in actor's area for completeness.
717   TestGenerateLongPress( application, 50.0f, 10.0f );
718   TestEndLongPress( application, 50.0f, 10.0f);
719   DALI_TEST_EQUALS(true, data.functorCalled, TEST_LOCATION);
720   END_TEST;
721 }
722
723 int UtcDaliLongPressGesturePossibleCancelled(void)
724 {
725   TestApplication application;
726
727   Actor actor = Actor::New();
728   actor.SetProperty( Actor::Property::SIZE, Vector2( 100.0f, 100.0f ) );
729   actor.SetProperty( Actor::Property::ANCHOR_POINT,AnchorPoint::TOP_LEFT);
730   application.GetScene().Add(actor);
731
732   // Render and notify
733   application.SendNotification();
734   application.Render();
735
736   // Attach actor to detector
737   SignalData data;
738   GestureReceivedFunctor functor( data );
739   LongPressGestureDetector detector = LongPressGestureDetector::New();
740   detector.Attach(actor);
741   detector.DetectedSignal().Connect( &application, functor );
742
743   // Send a possible followed by a cancel, we should not be signalled
744   TestStartLongPress( application, 50.0f, 10.0f );
745   DALI_TEST_EQUALS(false, data.functorCalled, TEST_LOCATION);
746   TestMovePan( application, Vector2( 50.0f, 10.0f ) );
747   DALI_TEST_EQUALS(false, data.functorCalled, TEST_LOCATION);
748   END_TEST;
749 }
750
751 int UtcDaliLongPressGestureDetachAfterStarted(void)
752 {
753   TestApplication application;
754
755   Actor actor = Actor::New();
756   actor.SetProperty( Actor::Property::SIZE, Vector2( 100.0f, 100.0f ) );
757   actor.SetProperty( Actor::Property::ANCHOR_POINT,AnchorPoint::TOP_LEFT);
758   application.GetScene().Add(actor);
759
760   // Render and notify
761   application.SendNotification();
762   application.Render();
763
764   // Attach actor to detector
765   SignalData data;
766   GestureReceivedFunctor functor( data );
767   LongPressGestureDetector detector = LongPressGestureDetector::New();
768   detector.Attach(actor);
769   detector.DetectedSignal().Connect( &application, functor );
770
771   // Emit initial signal
772   TestGenerateLongPress( application, 50.0f, 10.0f );
773   DALI_TEST_EQUALS(true, data.functorCalled, TEST_LOCATION);
774   data.Reset();
775
776   // Detach actor
777   detector.Detach(actor);
778
779   // Emit Finished, no signal
780   TestEndLongPress( application, 50.0f, 10.0f );
781   DALI_TEST_EQUALS(false, data.functorCalled, TEST_LOCATION);
782   END_TEST;
783 }
784
785 int UtcDaliLongPressGestureActorUnstaged(void)
786 {
787   TestApplication application;
788
789   Actor actor = Actor::New();
790   actor.SetProperty( Actor::Property::SIZE, Vector2( 100.0f, 100.0f ) );
791   actor.SetProperty( Actor::Property::ANCHOR_POINT,AnchorPoint::TOP_LEFT);
792   application.GetScene().Add(actor);
793
794   // Render and notify
795   application.SendNotification();
796   application.Render();
797
798   // State to remove actor in.
799   Gesture::State stateToUnstage( Gesture::Started );
800
801   // Attach actor to detector
802   SignalData data;
803   UnstageActorFunctor functor( data, stateToUnstage, application.GetScene() );
804   LongPressGestureDetector detector = LongPressGestureDetector::New();
805   detector.Attach(actor);
806   detector.DetectedSignal().Connect( &application, functor );
807
808   // Emit signals
809   TestGenerateLongPress( application, 50.0f, 10.0f );
810   DALI_TEST_EQUALS(true, data.functorCalled, TEST_LOCATION);
811   data.Reset();
812   TestEndLongPress( application, 50.0f, 10.0f );
813   DALI_TEST_EQUALS(false, data.functorCalled, TEST_LOCATION);
814
815   // Render and notify
816   application.SendNotification();
817   application.Render();
818
819   // Re-add actor to stage
820   application.GetScene().Add(actor);
821
822   // Render and notify
823   application.SendNotification();
824   application.Render();
825
826   // Change state to Gesture::Continuing to remove
827   stateToUnstage = Gesture::Finished;
828
829   // Emit signals
830   TestGenerateLongPress( application, 50.0f, 10.0f );
831   DALI_TEST_EQUALS(true, data.functorCalled, TEST_LOCATION);
832   data.Reset();
833   TestEndLongPress( application, 50.0f, 10.0f );
834   DALI_TEST_EQUALS(true, data.functorCalled, TEST_LOCATION);
835   tet_result( TET_PASS ); // If we get here then we have handled actor stage removal gracefully.
836   END_TEST;
837 }
838
839 int UtcDaliLongPressGestureActorStagedAndDestroyed(void)
840 {
841   TestApplication application;
842
843   Actor actor = Actor::New();
844   actor.SetProperty( Actor::Property::SIZE, Vector2( 100.0f, 100.0f ) );
845   actor.SetProperty( Actor::Property::ANCHOR_POINT,AnchorPoint::TOP_LEFT);
846   application.GetScene().Add(actor);
847
848   // Create and add a second actor so that GestureDetector destruction does not come into play.
849   Actor dummyActor( Actor::New() );
850   dummyActor.SetProperty( Actor::Property::SIZE, Vector2( 100.0f, 100.0f ) );
851   dummyActor.SetProperty( Actor::Property::POSITION, Vector2( 100.0f, 100.0f ));
852   dummyActor.SetProperty( Actor::Property::ANCHOR_POINT,AnchorPoint::TOP_LEFT);
853   application.GetScene().Add(dummyActor);
854
855   // Render and notify
856   application.SendNotification();
857   application.Render();
858
859   // State to remove actor in.
860   Gesture::State stateToUnstage( Gesture::Started );
861
862   // Attach actor to detector
863   SignalData data;
864   UnstageActorFunctor functor( data, stateToUnstage, application.GetScene() );
865   LongPressGestureDetector detector = LongPressGestureDetector::New();
866   detector.Attach(actor);
867   detector.Attach(dummyActor);
868   detector.DetectedSignal().Connect( &application, functor );
869
870   // Here we are testing a Started actor which is removed in the Started callback, but then added back
871   // before we get a finished state.  As we were removed from the stage, even if we're at the same
872   // position, we should still not be signalled.
873
874   // Emit signals
875   TestGenerateLongPress( application, 50.0f, 10.0f );
876   DALI_TEST_EQUALS(true, data.functorCalled, TEST_LOCATION);
877   data.Reset();
878
879   // Render and notify
880   application.SendNotification();
881   application.Render();
882
883   // Re add to the stage, we should not be signalled
884   application.GetScene().Add(actor);
885
886   // Render and notify
887   application.SendNotification();
888   application.Render();
889
890   // Continue signal emission
891   TestEndLongPress( application, 50.0f, 10.0f );
892   DALI_TEST_EQUALS(false, data.functorCalled, TEST_LOCATION);
893   data.Reset();
894
895   // Here we delete an actor in started, we should not receive any subsequent signalling.
896
897   // Emit signals
898   TestGenerateLongPress( application, 50.0f, 10.0f );
899   DALI_TEST_EQUALS(true, data.functorCalled, TEST_LOCATION);
900   data.Reset();
901
902   // Render and notify
903   application.SendNotification();
904   application.Render();
905
906   // Delete actor as well
907   actor.Reset();
908
909   // Render and notify
910   application.SendNotification();
911   application.Render();
912
913   // Continue signal emission
914   TestEndLongPress( application, 50.0f, 10.0f );
915   DALI_TEST_EQUALS(false, data.functorCalled, TEST_LOCATION);
916   END_TEST;
917 }
918
919 int UtcDaliLongPressGestureLayerConsumesTouch(void)
920 {
921   TestApplication application;
922
923   Actor actor = Actor::New();
924   actor.SetProperty( Actor::Property::SIZE, Vector2( 100.0f, 100.0f ) );
925   actor.SetProperty( Actor::Property::ANCHOR_POINT,AnchorPoint::TOP_LEFT);
926   application.GetScene().Add(actor);
927
928   // Add a detector
929   SignalData data;
930   GestureReceivedFunctor functor(data);
931   LongPressGestureDetector detector = LongPressGestureDetector::New();
932   detector.Attach(actor);
933   detector.DetectedSignal().Connect( &application, functor );
934
935   // Add a layer to overlap the actor
936   Layer layer = Layer::New();
937   layer.SetProperty( Actor::Property::SIZE, Vector2( 100.0f, 100.0f ) );
938   layer.SetProperty( Actor::Property::ANCHOR_POINT,AnchorPoint::TOP_LEFT);
939   application.GetScene().Add( layer );
940   layer.RaiseToTop();
941
942   // Render and notify
943   application.SendNotification();
944   application.Render();
945
946   // Emit signals, should receive
947   TestGenerateLongPress( application, 50.0f, 50.0f );
948   TestEndLongPress( application, 50.0f, 50.0f );
949   DALI_TEST_EQUALS(true, data.functorCalled, TEST_LOCATION);
950   data.Reset();
951
952   // Set layer to consume all touch
953   layer.SetProperty( Layer::Property::CONSUMES_TOUCH, true );
954
955   // Render and notify
956   application.SendNotification();
957   application.Render();
958
959   // Emit the same signals again, should not receive
960   TestGenerateLongPress( application, 50.0f, 50.0f );
961   TestEndLongPress( application, 50.0f, 50.0f );
962   DALI_TEST_EQUALS(false, data.functorCalled, TEST_LOCATION);
963   data.Reset();
964
965   END_TEST;
966 }
967
968 int UtcDaliLongPressGestureSetMinimumHoldingTime(void)
969 {
970   TestApplication application;
971
972   const uint32_t kMinumumHolding1 = 5000;
973   const uint32_t kMinumumHolding2 = 3000;
974
975   Integration::SetLongPressMinimumHoldingTime( kMinumumHolding1 );
976
977   Actor actor = Actor::New();
978   actor.SetProperty( Actor::Property::SIZE, Vector2( 100.0f, 100.0f ) );
979   actor.SetProperty( Actor::Property::ANCHOR_POINT, AnchorPoint::TOP_LEFT );
980   application.GetScene().Add( actor );
981
982   // Render and notify
983   application.SendNotification();
984   application.Render();
985
986   SignalData data;
987   GestureReceivedFunctor functor( data );
988
989   LongPressGestureDetector detector = LongPressGestureDetector::New();
990   detector.Attach(actor);
991   detector.DetectedSignal().Connect(&application, functor);
992
993   DALI_TEST_EQUALS( DevelLongPressGestureDetector::GetMinimumHoldingTime( detector ), kMinumumHolding1, TEST_LOCATION );
994
995   Integration::SetLongPressMinimumHoldingTime( kMinumumHolding2 );
996   DALI_TEST_EQUALS( DevelLongPressGestureDetector::GetMinimumHoldingTime( detector ), kMinumumHolding2, TEST_LOCATION );
997
998   END_TEST;
999 }
1000
1001 int UtcDaliLongPressGestureInterruptedWhenTouchConsumed(void)
1002 {
1003   TestApplication application;
1004
1005   Actor actor = Actor::New();
1006   actor.SetProperty( Actor::Property::SIZE, Vector2( 100.0f, 100.0f ) );
1007   actor.SetProperty( Actor::Property::ANCHOR_POINT,AnchorPoint::TOP_LEFT);
1008   application.GetScene().Add(actor);
1009
1010   bool consume = false;
1011   TouchDataFunctorConsumeSetter touchFunctor(consume);
1012   actor.TouchSignal().Connect(&application,touchFunctor);
1013
1014   // Render and notify
1015   application.SendNotification();
1016   application.Render();
1017
1018   SignalData data;
1019   GestureReceivedFunctor functor(data);
1020
1021   LongPressGestureDetector detector = LongPressGestureDetector::New();
1022   detector.Attach(actor);
1023   detector.DetectedSignal().Connect(&application, functor);
1024
1025   // Start gesture within the actor's area, we should receive the gesture as the touch is NOT being consumed
1026   TestGenerateLongPress( application, 50.0f, 50.0f );
1027   DALI_TEST_EQUALS(true, data.functorCalled, TEST_LOCATION);
1028   data.Reset();
1029   TestEndLongPress(application, 50.0f,50.0f);
1030   DALI_TEST_EQUALS(true, data.functorCalled, TEST_LOCATION);
1031   data.Reset();
1032
1033   // Another gesture in the same location, this time we will not receive it as touch is being consumed
1034   consume = true;
1035   TestGenerateLongPress( application, 50.0f, 50.0f );
1036   DALI_TEST_EQUALS(false, data.functorCalled, TEST_LOCATION);
1037   data.Reset();
1038   TestEndLongPress(application, 50.0f,50.0f);
1039   DALI_TEST_EQUALS(false, data.functorCalled, TEST_LOCATION);
1040
1041   END_TEST;
1042 }
1043
1044 int UtcDaliLongPressGestureDisableDetectionDuringLongPressN(void)
1045 {
1046   // Crash occurred when gesture-recognizer was deleted internally during a signal when the attached actor was detached
1047
1048   TestApplication application;
1049
1050   Actor actor = Actor::New();
1051   actor.SetProperty( Actor::Property::SIZE, Vector2( 100.0f, 100.0f ) );
1052   actor.SetProperty( Actor::Property::ANCHOR_POINT,AnchorPoint::TOP_LEFT);
1053   application.GetScene().Add(actor);
1054
1055   // Add a detector
1056   LongPressGestureDetector detector = LongPressGestureDetector::New();
1057   bool functorCalled = false;
1058   detector.Attach( actor );
1059   detector.DetectedSignal().Connect(
1060       &application,
1061       [&detector, &functorCalled](Actor actor, const LongPressGesture& gesture)
1062       {
1063         if( gesture.state == Gesture::Finished )
1064         {
1065           detector.Detach(actor);
1066           functorCalled = true;
1067         }
1068       });
1069
1070   // Render and notify
1071   application.SendNotification();
1072   application.Render();
1073
1074   // Try the gesture, should not crash
1075   try
1076   {
1077     TestGenerateLongPress( application, 50.0f, 10.0f );
1078     TestEndLongPress( application, 50.0f, 10.0f );
1079
1080     DALI_TEST_CHECK( true ); // No crash, test has passed
1081     DALI_TEST_EQUALS(functorCalled, true, TEST_LOCATION);
1082   }
1083   catch(...)
1084   {
1085     DALI_TEST_CHECK( false ); // If we crash, the test has failed
1086   }
1087
1088   END_TEST;
1089 }
1090
1091