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