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