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