Merge "Klockwork: Remove unreachable code" into tizen
[platform/core/uifw/dali-core.git] / automated-tests / src / dali / utc-Dali-LongPressGestureDetector.cpp
1 /*
2  * Copyright (c) 2014 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/events/long-press-gesture-event.h>
24 #include <dali/integration-api/system-overlay.h>
25 #include <dali-test-suite-utils.h>
26 #include <test-touch-utils.h>
27
28 using namespace Dali;
29
30 void utc_dali_long_press_gesture_detector_startup(void)
31 {
32   test_return_value = TET_UNDEF;
33 }
34
35 void utc_dali_long_press_gesture_detector_cleanup(void)
36 {
37   test_return_value = TET_PASS;
38 }
39
40 ///////////////////////////////////////////////////////////////////////////////
41 namespace
42 {
43
44 // Stores data that is populated in the callback and will be read by the TET cases
45 struct SignalData
46 {
47   SignalData()
48   : functorCalled( false ),
49     voidFunctorCalled( false ),
50     receivedGesture( Gesture::Clear ),
51     pressedActor()
52   {}
53
54   void Reset()
55   {
56     functorCalled = false;
57     voidFunctorCalled = false;
58
59     receivedGesture.numberOfTouches = 0u;
60     receivedGesture.screenPoint = Vector2(0.0f, 0.0f);
61     receivedGesture.localPoint = Vector2(0.0f, 0.0f);
62
63     pressedActor.Reset();
64   }
65
66   bool functorCalled;
67   bool voidFunctorCalled;
68   LongPressGesture receivedGesture;
69   Actor pressedActor;
70 };
71
72 // Functor that sets the data when called
73 struct GestureReceivedFunctor
74 {
75   GestureReceivedFunctor(SignalData& data) : signalData(data) { }
76
77   void operator()(Actor actor, const LongPressGesture& longPress)
78   {
79     signalData.functorCalled = true;
80     signalData.receivedGesture = longPress;
81     signalData.pressedActor = actor;
82   }
83
84   void operator()()
85   {
86     signalData.voidFunctorCalled = true;
87   }
88
89   SignalData& signalData;
90 };
91
92 // Functor that removes the gestured actor from stage
93 struct UnstageActorFunctor : public GestureReceivedFunctor
94 {
95   UnstageActorFunctor( SignalData& data, Gesture::State& stateToUnstage )
96   : GestureReceivedFunctor( data ),
97     stateToUnstage( stateToUnstage )
98   {
99   }
100
101   void operator()( Actor actor, const LongPressGesture& longPress )
102   {
103     GestureReceivedFunctor::operator()( actor, longPress );
104
105     if ( longPress.state == stateToUnstage )
106     {
107       Stage::GetCurrent().Remove( actor );
108     }
109   }
110
111   Gesture::State& stateToUnstage;
112 };
113
114 // Functor for receiving a touch event
115 struct TouchEventFunctor
116 {
117   bool operator()(Actor actor, const TouchEvent& touch)
118   {
119     //For line coverage
120     unsigned int points = touch.GetPointCount();
121     if( points > 0)
122     {
123       const TouchPoint& touchPoint = touch.GetPoint(0);
124       tet_printf("Touch Point state = %d\n", touchPoint.state);
125     }
126     return false;
127   }
128 };
129
130 // Generate a LongPressGestureEvent to send to Core
131 Integration::LongPressGestureEvent GenerateLongPress(
132     Gesture::State state,
133     unsigned int numberOfTouches,
134     Vector2 point)
135 {
136   Integration::LongPressGestureEvent longPress( state );
137
138   longPress.numberOfTouches = numberOfTouches;
139   longPress.point = point;
140
141   return longPress;
142 }
143
144 } // anon namespace
145
146 ///////////////////////////////////////////////////////////////////////////////
147
148
149 // Positive test case for a method
150 int UtcDaliLongPressGestureDetectorConstructor(void)
151 {
152   TestApplication application;
153
154   LongPressGestureDetector detector;
155   DALI_TEST_CHECK(!detector);
156   END_TEST;
157 }
158
159
160 int UtcDaliLongPressGestureDetectorNew(void)
161 {
162   TestApplication application;
163
164   LongPressGestureDetector detector = LongPressGestureDetector::New();
165   DALI_TEST_CHECK(detector);
166   DALI_TEST_EQUALS(1u, detector.GetMinimumTouchesRequired(), TEST_LOCATION);
167   DALI_TEST_EQUALS(1u, detector.GetMaximumTouchesRequired(), TEST_LOCATION);
168
169   LongPressGestureDetector detector2 = LongPressGestureDetector::New(5u);
170   DALI_TEST_CHECK(detector2);
171   DALI_TEST_EQUALS(5u, detector2.GetMinimumTouchesRequired(), TEST_LOCATION);
172   DALI_TEST_EQUALS(5u, detector2.GetMaximumTouchesRequired(), TEST_LOCATION);
173
174   LongPressGestureDetector detector3 = LongPressGestureDetector::New(5u, 7u);
175   DALI_TEST_CHECK(detector2);
176   DALI_TEST_EQUALS(5u, detector3.GetMinimumTouchesRequired(), TEST_LOCATION);
177   DALI_TEST_EQUALS(7u, detector3.GetMaximumTouchesRequired(), TEST_LOCATION);
178
179   //Scoped test to test destructor
180   {
181     LongPressGestureDetector detector4 = LongPressGestureDetector::New();
182     DALI_TEST_CHECK(detector4);
183   }
184
185   // Attach an actor and emit a touch event on the actor to ensure complete line coverage
186   Actor actor = Actor::New();
187   actor.SetSize(100.0f, 100.0f);
188   actor.SetAnchorPoint(AnchorPoint::TOP_LEFT);
189   Stage::GetCurrent().Add(actor);
190
191   // Render and notify
192   application.SendNotification();
193   application.Render();
194
195   detector.Attach(actor);
196
197   TouchEventFunctor touchFunctor;
198   actor.TouchedSignal().Connect(&application, touchFunctor);
199
200   Integration::TouchEvent touchEvent(1);
201   TouchPoint point(1, TouchPoint::Down, 20.0f, 20.0f);
202   touchEvent.AddPoint(point);
203   application.ProcessEvent(touchEvent);
204
205   // Render and notify
206   application.SendNotification();
207   application.Render();
208
209   // For line coverage, Initialise default constructor
210   TouchEvent touchEvent2;
211   END_TEST;
212 }
213
214 int UtcDaliLongPressGestureDetectorDownCast(void)
215 {
216   TestApplication application;
217   tet_infoline("Testing Dali::LongPressGestureDetector::DownCast()");
218
219   LongPressGestureDetector detector = LongPressGestureDetector::New();
220
221   BaseHandle object(detector);
222
223   LongPressGestureDetector detector2 = LongPressGestureDetector::DownCast(object);
224   DALI_TEST_CHECK(detector2);
225
226   LongPressGestureDetector detector3 = DownCast< LongPressGestureDetector >(object);
227   DALI_TEST_CHECK(detector3);
228
229   BaseHandle unInitializedObject;
230   LongPressGestureDetector detector4 = LongPressGestureDetector::DownCast(unInitializedObject);
231   DALI_TEST_CHECK(!detector4);
232
233   LongPressGestureDetector detector5 = DownCast< LongPressGestureDetector >(unInitializedObject);
234   DALI_TEST_CHECK(!detector5);
235
236   GestureDetector detector6 = LongPressGestureDetector::New();
237   LongPressGestureDetector detector7 = LongPressGestureDetector::DownCast(detector6);
238   DALI_TEST_CHECK(detector7);
239   END_TEST;
240 }
241
242 int UtcDaliLongPressGestureSetTouchesRequired01(void)
243 {
244   TestApplication application;
245
246   LongPressGestureDetector detector = LongPressGestureDetector::New();
247
248   unsigned int touches = 3;
249
250   DALI_TEST_CHECK(touches != detector.GetMinimumTouchesRequired());
251   DALI_TEST_CHECK(touches != detector.GetMaximumTouchesRequired());
252
253   detector.SetTouchesRequired(touches);
254
255   DALI_TEST_EQUALS(touches, detector.GetMinimumTouchesRequired(), TEST_LOCATION);
256   DALI_TEST_EQUALS(touches, detector.GetMaximumTouchesRequired(), TEST_LOCATION);
257
258   // Attach an actor and change the required touches
259
260   Actor actor = Actor::New();
261   actor.SetSize(100.0f, 100.0f);
262   actor.SetAnchorPoint(AnchorPoint::TOP_LEFT);
263   Stage::GetCurrent().Add(actor);
264
265   // Render and notify
266   application.SendNotification();
267   application.Render();
268
269   SignalData data;
270   GestureReceivedFunctor functor(data);
271
272   detector.Attach(actor);
273   detector.DetectedSignal().Connect(&application, functor);
274
275   TestGestureManager& gestureManager = application.GetGestureManager();
276   gestureManager.Initialize();
277
278   detector.SetTouchesRequired(4);
279
280   // Gesture detection should have been updated only
281   DALI_TEST_EQUALS(true, gestureManager.WasCalled(TestGestureManager::UpdateType), TEST_LOCATION);
282   DALI_TEST_EQUALS(false, gestureManager.WasCalled(TestGestureManager::RegisterType), TEST_LOCATION);
283   DALI_TEST_EQUALS(false, gestureManager.WasCalled(TestGestureManager::UnregisterType), TEST_LOCATION);
284
285   // Reset values
286   gestureManager.Initialize();
287
288   // Create a second gesture detector that requires even less maximum touches
289   LongPressGestureDetector secondDetector = LongPressGestureDetector::New();
290   secondDetector.Attach(actor);
291
292   // Gesture detection should have been updated
293   DALI_TEST_EQUALS(true, gestureManager.WasCalled(TestGestureManager::UpdateType), TEST_LOCATION);
294   DALI_TEST_EQUALS(false, gestureManager.WasCalled(TestGestureManager::RegisterType), TEST_LOCATION);
295   DALI_TEST_EQUALS(false, gestureManager.WasCalled(TestGestureManager::UnregisterType), TEST_LOCATION);
296   END_TEST;
297 }
298
299 int UtcDaliLongPressGestureSetTouchesRequired02(void)
300 {
301   TestApplication application;
302
303   LongPressGestureDetector detector = LongPressGestureDetector::New();
304
305   unsigned int min = 3;
306   unsigned int max = 5;
307
308   DALI_TEST_CHECK(min != detector.GetMinimumTouchesRequired());
309   DALI_TEST_CHECK(max != detector.GetMaximumTouchesRequired());
310
311   detector.SetTouchesRequired(min, max);
312
313   DALI_TEST_EQUALS(min, detector.GetMinimumTouchesRequired(), TEST_LOCATION);
314   DALI_TEST_EQUALS(max, detector.GetMaximumTouchesRequired(), TEST_LOCATION);
315
316   // Attach an actor and change the maximum touches
317
318   Actor actor = Actor::New();
319   actor.SetSize(100.0f, 100.0f);
320   actor.SetAnchorPoint(AnchorPoint::TOP_LEFT);
321   Stage::GetCurrent().Add(actor);
322
323   // Render and notify
324   application.SendNotification();
325   application.Render();
326
327   SignalData data;
328   GestureReceivedFunctor functor(data);
329
330   detector.Attach(actor);
331   detector.DetectedSignal().Connect(&application, functor);
332
333   TestGestureManager& gestureManager = application.GetGestureManager();
334   gestureManager.Initialize();
335
336   detector.SetTouchesRequired(4, 5);
337
338   // Gesture detection should have been updated only
339   DALI_TEST_EQUALS(true, gestureManager.WasCalled(TestGestureManager::UpdateType), TEST_LOCATION);
340   DALI_TEST_EQUALS(false, gestureManager.WasCalled(TestGestureManager::RegisterType), TEST_LOCATION);
341   DALI_TEST_EQUALS(false, gestureManager.WasCalled(TestGestureManager::UnregisterType), TEST_LOCATION);
342
343   // Reset values
344   gestureManager.Initialize();
345
346   // Create a second gesture detector that requires even less maximum touches
347   LongPressGestureDetector secondDetector = LongPressGestureDetector::New();
348   secondDetector.Attach(actor);
349
350   // Gesture detection should have been updated
351   DALI_TEST_EQUALS(true, gestureManager.WasCalled(TestGestureManager::UpdateType), TEST_LOCATION);
352   DALI_TEST_EQUALS(false, gestureManager.WasCalled(TestGestureManager::RegisterType), TEST_LOCATION);
353   DALI_TEST_EQUALS(false, gestureManager.WasCalled(TestGestureManager::UnregisterType), TEST_LOCATION);
354   END_TEST;
355 }
356
357 int UtcDaliLongPressGestureGetMinimumTouchesRequired(void)
358 {
359   TestApplication application;
360
361   LongPressGestureDetector detector = LongPressGestureDetector::New();
362   DALI_TEST_EQUALS(1u, detector.GetMinimumTouchesRequired(), TEST_LOCATION);
363   END_TEST;
364 }
365
366 int UtcDaliLongPressGestureGetMaximumTouchesRequired(void)
367 {
368   TestApplication application;
369
370   LongPressGestureDetector detector = LongPressGestureDetector::New();
371   DALI_TEST_EQUALS(1u, detector.GetMaximumTouchesRequired(), TEST_LOCATION);
372   END_TEST;
373 }
374
375 int UtcDaliLongPressGestureSignalReceptionNegative(void)
376 {
377   TestApplication application;
378
379   Actor actor = Actor::New();
380   actor.SetSize(100.0f, 100.0f);
381   actor.SetAnchorPoint(AnchorPoint::TOP_LEFT);
382   Stage::GetCurrent().Add(actor);
383
384   // Render and notify
385   application.SendNotification();
386   application.Render();
387
388   SignalData data;
389   GestureReceivedFunctor functor(data);
390
391   LongPressGestureDetector detector = LongPressGestureDetector::New();
392   detector.Attach(actor);
393   detector.DetectedSignal().Connect(&application, functor);
394
395   // Do a long press outside actor's area
396   application.ProcessEvent( GenerateLongPress( Gesture::Possible, 1u, Vector2(112.0f, 112.0f ) ) );
397   application.ProcessEvent( GenerateLongPress( Gesture::Started,  1u, Vector2(112.0f, 112.0f ) ) );
398   application.ProcessEvent( GenerateLongPress( Gesture::Finished, 1u, Vector2(112.0f, 112.0f ) ) );
399   DALI_TEST_EQUALS(false, data.functorCalled, TEST_LOCATION);
400   END_TEST;
401 }
402
403 int UtcDaliLongPressGestureSignalReceptionPositive(void)
404 {
405   TestApplication application;
406
407   Actor actor = Actor::New();
408   actor.SetSize(100.0f, 100.0f);
409   actor.SetAnchorPoint(AnchorPoint::TOP_LEFT);
410   Stage::GetCurrent().Add(actor);
411
412   // Render and notify
413   application.SendNotification();
414   application.Render();
415
416   SignalData data;
417   GestureReceivedFunctor functor(data);
418
419   LongPressGestureDetector detector = LongPressGestureDetector::New();
420   detector.Attach(actor);
421   detector.DetectedSignal().Connect(&application, functor);
422
423   // Do a long press inside actor's area
424   application.ProcessEvent(GenerateLongPress(Gesture::Possible, 1u, Vector2(50.0f, 50.0f)));
425   application.ProcessEvent(GenerateLongPress(Gesture::Started,  1u, Vector2(50.0f, 50.0f)));
426   DALI_TEST_EQUALS(true, data.functorCalled, TEST_LOCATION);
427   DALI_TEST_EQUALS(1u, data.receivedGesture.numberOfTouches, TEST_LOCATION);
428   DALI_TEST_EQUALS( Vector2(50.0f, 50.0f), data.receivedGesture.localPoint, 0.1, TEST_LOCATION);
429   application.ProcessEvent(GenerateLongPress(Gesture::Finished,  1u, Vector2(50.0f, 50.0f)));
430   END_TEST;
431 }
432
433 int UtcDaliLongPressGestureSignalReceptionDetach(void)
434 {
435   TestApplication application;
436
437   Actor actor = Actor::New();
438   actor.SetSize(100.0f, 100.0f);
439   actor.SetAnchorPoint(AnchorPoint::TOP_LEFT);
440   Stage::GetCurrent().Add(actor);
441
442   // Render and notify
443   application.SendNotification();
444   application.Render();
445
446   SignalData data;
447   GestureReceivedFunctor functor(data);
448
449   LongPressGestureDetector detector = LongPressGestureDetector::New();
450   detector.Attach(actor);
451   detector.DetectedSignal().Connect(&application, functor);
452
453   // Start long press within the actor's area
454   application.ProcessEvent(GenerateLongPress(Gesture::Possible, 1u, Vector2(20.0f, 20.0f)));
455   application.ProcessEvent(GenerateLongPress(Gesture::Started,  1u, Vector2(20.0f, 20.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(20.0f, 20.0f), data.receivedGesture.localPoint, 0.1, TEST_LOCATION);
459   application.ProcessEvent(GenerateLongPress(Gesture::Finished, 1u, Vector2(20.0f, 20.0f)));
460
461   // repeat the long press within the actor's area - we should still receive the signal
462   data.Reset();
463   application.ProcessEvent(GenerateLongPress(Gesture::Possible, 1u, Vector2(50.0f, 50.0f)));
464   application.ProcessEvent(GenerateLongPress(Gesture::Started,  1u, Vector2(50.0f, 50.0f)));
465   DALI_TEST_EQUALS(true, data.functorCalled, TEST_LOCATION);
466   DALI_TEST_EQUALS(1u, data.receivedGesture.numberOfTouches, TEST_LOCATION);
467   DALI_TEST_EQUALS( Vector2(50.0f, 50.0f), data.receivedGesture.localPoint, 0.1, TEST_LOCATION);
468   application.ProcessEvent(GenerateLongPress(Gesture::Finished, 1u, Vector2(50.0f, 50.0f)));
469
470   // Detach actor
471   detector.DetachAll();
472
473   // Ensure we are no longer signalled
474   data.Reset();
475   application.ProcessEvent(GenerateLongPress(Gesture::Possible, 1u, Vector2(20.0f, 20.0f)));
476   application.ProcessEvent(GenerateLongPress(Gesture::Started,  1u, Vector2(20.0f, 20.0f)));
477   DALI_TEST_EQUALS(false, data.functorCalled, TEST_LOCATION);
478   application.ProcessEvent(GenerateLongPress(Gesture::Finished, 1u, Vector2(50.0f, 50.0f)));
479   DALI_TEST_EQUALS(false, data.functorCalled, TEST_LOCATION);
480   END_TEST;
481 }
482
483 int UtcDaliLongPressGestureSignalReceptionActorDestroyedDuringLongPress(void)
484 {
485   TestApplication application;
486
487   SignalData data;
488   GestureReceivedFunctor functor(data);
489
490   LongPressGestureDetector detector = LongPressGestureDetector::New();
491   detector.DetectedSignal().Connect(&application, functor);
492
493   // Actor lifetime is scoped
494   {
495     Actor actor = Actor::New();
496     actor.SetSize(100.0f, 100.0f);
497     actor.SetAnchorPoint(AnchorPoint::TOP_LEFT);
498     Stage::GetCurrent().Add(actor);
499
500     // Render and notify
501     application.SendNotification();
502     application.Render();
503
504     detector.Attach(actor);
505
506     // Start long press within the actor's area
507     application.ProcessEvent(GenerateLongPress(Gesture::Possible, 1u, Vector2(20.0f, 20.0f)));
508     application.ProcessEvent(GenerateLongPress(Gesture::Started,  1u, Vector2(20.0f, 20.0f)));
509     DALI_TEST_EQUALS(true, data.functorCalled, TEST_LOCATION);
510
511     // Remove the actor from stage and reset the data
512     Stage::GetCurrent().Remove(actor);
513
514     // Render and notify
515     application.SendNotification();
516     application.Render();
517   }
518
519   // Actor should now have been destroyed
520
521   data.Reset();
522   application.ProcessEvent(GenerateLongPress(Gesture::Finished, 1u, Vector2(20.0f, 20.0f)));
523   DALI_TEST_EQUALS(false, data.functorCalled, TEST_LOCATION);
524   END_TEST;
525 }
526
527 int UtcDaliLongPressGestureSignalReceptionRotatedActor(void)
528 {
529   TestApplication application;
530
531   Actor actor = Actor::New();
532   actor.SetSize(100.0f, 100.0f);
533   actor.SetRotation(Dali::Degree(90.0f), Vector3::ZAXIS);
534   Stage::GetCurrent().Add(actor);
535
536   // Render and notify
537   application.SendNotification();
538   application.Render();
539
540   SignalData data;
541   GestureReceivedFunctor functor(data);
542
543   LongPressGestureDetector detector = LongPressGestureDetector::New();
544   detector.Attach(actor);
545   detector.DetectedSignal().Connect(&application, functor);
546
547   // Do a long press
548   application.ProcessEvent(GenerateLongPress(Gesture::Possible, 1u, Vector2(5.0f, 5.0f)));
549   application.ProcessEvent(GenerateLongPress(Gesture::Started,  1u, Vector2(5.0f, 5.0f)));
550   application.ProcessEvent(GenerateLongPress(Gesture::Finished, 1u, Vector2(5.0f, 5.0f)));
551   DALI_TEST_EQUALS(true, data.functorCalled, TEST_LOCATION);
552   DALI_TEST_EQUALS(1u, data.receivedGesture.numberOfTouches, TEST_LOCATION);
553   DALI_TEST_EQUALS( Vector2(5.0f, 5.0f), data.receivedGesture.screenPoint, 0.1, TEST_LOCATION);
554
555   // Rotate actor again and render
556   actor.SetRotation(Dali::Degree(180.0f), Vector3::ZAXIS);
557   application.SendNotification();
558   application.Render();
559
560   // Do another long press, should still receive event
561   data.Reset();
562   application.ProcessEvent(GenerateLongPress(Gesture::Possible, 1u, Vector2(5.0f, 5.0f)));
563   application.ProcessEvent(GenerateLongPress(Gesture::Started,  1u, Vector2(5.0f, 5.0f)));
564   application.ProcessEvent(GenerateLongPress(Gesture::Finished, 1u, Vector2(5.0f, 5.0f)));
565   DALI_TEST_EQUALS(true, data.functorCalled, TEST_LOCATION);
566   DALI_TEST_EQUALS(1u, data.receivedGesture.numberOfTouches, TEST_LOCATION);
567   DALI_TEST_EQUALS( Vector2(5.0f, 5.0f), data.receivedGesture.screenPoint, 0.1, TEST_LOCATION);
568
569   // Rotate actor again and render
570   actor.SetRotation(Dali::Degree(90.0f), Vector3::YAXIS);
571   application.SendNotification();
572   application.Render();
573
574   // Do a long press, inside where the actor used to be, Should not receive the event
575   data.Reset();
576   application.ProcessEvent(GenerateLongPress(Gesture::Possible, 1u, Vector2(70.0f, 70.0f)));
577   application.ProcessEvent(GenerateLongPress(Gesture::Started,  1u, Vector2(70.0f, 70.0f)));
578   application.ProcessEvent(GenerateLongPress(Gesture::Finished, 1u, Vector2(70.0f, 70.0f)));
579   DALI_TEST_EQUALS(false, data.functorCalled, TEST_LOCATION);
580   END_TEST;
581 }
582
583 int UtcDaliLongPressGestureSignalReceptionChildHit(void)
584 {
585   TestApplication application;
586
587   Actor parent = Actor::New();
588   parent.SetSize(100.0f, 100.0f);
589   parent.SetAnchorPoint(AnchorPoint::TOP_LEFT);
590   Stage::GetCurrent().Add(parent);
591
592   // Set child to completely cover parent.
593   // Change rotation of child to be different from parent so that we can check if our local coordinate
594   // conversion of the parent actor is correct.
595   Actor child = Actor::New();
596   child.SetSize(100.0f, 100.0f);
597   child.SetAnchorPoint(AnchorPoint::CENTER);
598   child.SetParentOrigin(ParentOrigin::CENTER);
599   child.SetRotation(Dali::Degree(90.0f), Vector3::ZAXIS);
600   parent.Add(child);
601
602   TouchEventFunctor touchFunctor;
603   child.TouchedSignal().Connect(&application, touchFunctor);
604
605   // Render and notify
606   application.SendNotification();
607   application.Render();
608
609   SignalData data;
610   GestureReceivedFunctor functor(data);
611
612   LongPressGestureDetector detector = LongPressGestureDetector::New();
613   detector.Attach(parent);
614   detector.DetectedSignal().Connect(&application, functor);
615
616   // Do long press - hits child area but parent should still receive it
617   application.ProcessEvent(GenerateLongPress(Gesture::Possible, 1u, Vector2(50.0f, 50.0f)));
618   application.ProcessEvent(GenerateLongPress(Gesture::Started,  1u, Vector2(50.0f, 50.0f)));
619   application.ProcessEvent(GenerateLongPress(Gesture::Finished, 1u, Vector2(50.0f, 50.0f)));
620   DALI_TEST_EQUALS(true, data.functorCalled, TEST_LOCATION);
621   DALI_TEST_EQUALS(true, parent == data.pressedActor, TEST_LOCATION);
622   DALI_TEST_EQUALS(Vector2(50.0f, 50.0f), data.receivedGesture.screenPoint, 0.01f, TEST_LOCATION);
623
624   // Attach child and generate same touch points
625   // (Also proves that you can detach and then re-attach another actor)
626   detector.Attach(child);
627   detector.Detach(parent);
628
629   // Do an entire long press, only check finished value
630   data.Reset();
631   application.ProcessEvent(GenerateLongPress(Gesture::Possible, 1u, Vector2(51.0f, 51.0f)));
632   application.ProcessEvent(GenerateLongPress(Gesture::Started,  1u, Vector2(51.0f, 51.0f)));
633   application.ProcessEvent(GenerateLongPress(Gesture::Finished, 1u, Vector2(51.0f, 51.0f)));
634   DALI_TEST_EQUALS(true, data.functorCalled, TEST_LOCATION);
635   DALI_TEST_EQUALS(true, child == data.pressedActor, TEST_LOCATION);
636   DALI_TEST_EQUALS(Vector2(51.0f, 51.0f), data.receivedGesture.screenPoint, 0.01f, TEST_LOCATION);
637   END_TEST;
638 }
639
640 int UtcDaliLongPressGestureSignalReceptionAttachDetachMany(void)
641 {
642   TestApplication application;
643
644   Actor first = Actor::New();
645   first.SetSize(100.0f, 100.0f);
646   first.SetAnchorPoint(AnchorPoint::TOP_LEFT);
647   Stage::GetCurrent().Add(first);
648
649   Actor second = Actor::New();
650   second.SetSize(100.0f, 100.0f);
651   second.SetX(100.0f);
652   second.SetAnchorPoint(AnchorPoint::TOP_LEFT);
653   Stage::GetCurrent().Add(second);
654
655   // Render and notify
656   application.SendNotification();
657   application.Render();
658
659   SignalData data;
660   GestureReceivedFunctor functor(data);
661
662   LongPressGestureDetector detector = LongPressGestureDetector::New();
663   detector.Attach(first);
664   detector.Attach(second);
665   detector.DetectedSignal().Connect(&application, functor);
666
667   // LongPress within second actor's area
668   application.ProcessEvent(GenerateLongPress(Gesture::Possible, 1u, Vector2(120.0f, 10.0f)));
669   application.ProcessEvent(GenerateLongPress(Gesture::Started,  1u, Vector2(120.0f, 10.0f)));
670   application.ProcessEvent(GenerateLongPress(Gesture::Finished, 1u, Vector2(120.0f, 10.0f)));
671   DALI_TEST_EQUALS(true, data.functorCalled, TEST_LOCATION);
672   DALI_TEST_EQUALS(true, second == data.pressedActor, TEST_LOCATION);
673
674   // LongPress within first actor's area
675   data.Reset();
676   application.ProcessEvent(GenerateLongPress(Gesture::Possible, 1u, Vector2(20.0f, 10.0f)));
677   application.ProcessEvent(GenerateLongPress(Gesture::Started,  1u, Vector2(20.0f, 10.0f)));
678   application.ProcessEvent(GenerateLongPress(Gesture::Finished, 1u, Vector2(20.0f, 10.0f)));
679   DALI_TEST_EQUALS(true, data.functorCalled, TEST_LOCATION);
680   DALI_TEST_EQUALS(true, first == data.pressedActor, TEST_LOCATION);
681
682   // Detach the second actor
683   detector.Detach(second);
684
685   // second actor shouldn't receive event
686   data.Reset();
687   application.ProcessEvent(GenerateLongPress(Gesture::Possible, 1u, Vector2(120.0f, 10.0f)));
688   application.ProcessEvent(GenerateLongPress(Gesture::Started,  1u, Vector2(120.0f, 10.0f)));
689   application.ProcessEvent(GenerateLongPress(Gesture::Finished, 1u, Vector2(120.0f, 10.0f)));
690   DALI_TEST_EQUALS(false, data.functorCalled, TEST_LOCATION);
691
692   // first actor should continue receiving event
693   data.Reset();
694   application.ProcessEvent(GenerateLongPress(Gesture::Possible, 1u, Vector2(20.0f, 10.0f)));
695   application.ProcessEvent(GenerateLongPress(Gesture::Started,  1u, Vector2(20.0f, 10.0f)));
696   application.ProcessEvent(GenerateLongPress(Gesture::Finished, 1u, Vector2(20.0f, 10.0f)));
697   DALI_TEST_EQUALS(true, data.functorCalled, TEST_LOCATION);
698   END_TEST;
699 }
700
701 int UtcDaliLongPressGestureSignalReceptionActorBecomesUntouchable(void)
702 {
703   TestApplication application;
704
705   Actor actor = Actor::New();
706   actor.SetSize(100.0f, 100.0f);
707   actor.SetAnchorPoint(AnchorPoint::TOP_LEFT);
708   Stage::GetCurrent().Add(actor);
709
710   // Render and notify
711   application.SendNotification();
712   application.Render();
713
714   SignalData data;
715   GestureReceivedFunctor functor(data);
716
717   LongPressGestureDetector detector = LongPressGestureDetector::New();
718   detector.Attach(actor);
719   detector.DetectedSignal().Connect(&application, functor);
720
721   // LongPress in actor's area
722   application.ProcessEvent(GenerateLongPress(Gesture::Possible, 1u, Vector2(50.0f, 10.0f)));
723   application.ProcessEvent(GenerateLongPress(Gesture::Started,  1u, Vector2(50.0f, 10.0f)));
724   application.ProcessEvent(GenerateLongPress(Gesture::Finished, 1u, Vector2(50.0f, 10.0f)));
725   DALI_TEST_EQUALS(true, data.functorCalled, TEST_LOCATION);
726
727   // Actor becomes invisible - actor should not receive the next long press
728   actor.SetVisible(false);
729
730   // Render and notify
731   application.SendNotification();
732   application.Render();
733
734   // LongPress in the same area, shouldn't receive event
735   data.Reset();
736   application.ProcessEvent(GenerateLongPress(Gesture::Possible, 1u, Vector2(50.0f, 10.0f)));
737   application.ProcessEvent(GenerateLongPress(Gesture::Started,  1u, Vector2(50.0f, 10.0f)));
738   application.ProcessEvent(GenerateLongPress(Gesture::Finished, 1u, Vector2(50.0f, 10.0f)));
739   DALI_TEST_EQUALS(false, data.functorCalled, TEST_LOCATION);
740   END_TEST;
741 }
742
743 int UtcDaliLongPressGestureSignalReceptionMultipleGestureDetectors(void)
744 {
745   TestApplication application;
746   Dali::TestGestureManager& gestureManager = application.GetGestureManager();
747
748   Actor first = Actor::New();
749   first.SetSize(100.0f, 100.0f);
750   first.SetAnchorPoint(AnchorPoint::TOP_LEFT);
751   Stage::GetCurrent().Add(first);
752
753   Actor second = Actor::New();
754   second.SetSize(100.0f, 100.0f);
755   second.SetAnchorPoint(AnchorPoint::TOP_LEFT);
756   second.SetX(100.0f);
757   first.Add(second);
758
759   // Render and notify
760   application.SendNotification();
761   application.Render();
762
763   SignalData data;
764   GestureReceivedFunctor functor(data);
765
766   LongPressGestureDetector firstDetector = LongPressGestureDetector::New();
767   firstDetector.Attach(first);
768   firstDetector.DetectedSignal().Connect(&application, functor);
769
770   // secondDetector is scoped
771   {
772     // Reset gestureManager statistics
773     gestureManager.Initialize();
774
775     LongPressGestureDetector secondDetector = LongPressGestureDetector::New();
776     secondDetector.SetTouchesRequired(2);
777     secondDetector.Attach(second);
778     secondDetector.DetectedSignal().Connect(&application, functor);
779
780     DALI_TEST_EQUALS(true, gestureManager.WasCalled(TestGestureManager::UpdateType), TEST_LOCATION);
781     DALI_TEST_EQUALS(false, gestureManager.WasCalled(TestGestureManager::RegisterType), TEST_LOCATION);
782     DALI_TEST_EQUALS(false, gestureManager.WasCalled(TestGestureManager::UnregisterType), TEST_LOCATION);
783
784     // LongPress within second actor's area
785     application.ProcessEvent(GenerateLongPress(Gesture::Possible, 2u, Vector2(150.0f, 10.0f)));
786     application.ProcessEvent(GenerateLongPress(Gesture::Started,  2u, Vector2(150.0f, 10.0f)));
787     application.ProcessEvent(GenerateLongPress(Gesture::Finished, 2u, Vector2(150.0f, 10.0f)));
788     DALI_TEST_EQUALS(true, data.functorCalled, TEST_LOCATION);
789     DALI_TEST_EQUALS(true, second == data.pressedActor, TEST_LOCATION);
790
791     // LongPress continues as single touch gesture - we should not receive any gesture
792     data.Reset();
793     application.ProcessEvent(GenerateLongPress(Gesture::Possible, 1u, Vector2(150.0f, 10.0f)));
794     application.ProcessEvent(GenerateLongPress(Gesture::Started, 1u, Vector2(150.0f, 10.0f)));
795     application.ProcessEvent(GenerateLongPress(Gesture::Finished, 1u, Vector2(150.0f, 10.0f)));
796     DALI_TEST_EQUALS(false, data.functorCalled, TEST_LOCATION);
797
798     // Single touch long press starts - first actor should receive gesture
799     data.Reset();
800     application.ProcessEvent(GenerateLongPress(Gesture::Possible, 1u, Vector2(50.0f, 10.0f)));
801     application.ProcessEvent(GenerateLongPress(Gesture::Started,  1u, Vector2(50.0f, 10.0f)));
802     application.ProcessEvent(GenerateLongPress(Gesture::Finished, 1u, Vector2(50.0f, 10.0f)));
803     DALI_TEST_EQUALS(true, data.functorCalled, TEST_LOCATION);
804     DALI_TEST_EQUALS(true, first == data.pressedActor, TEST_LOCATION);
805
806     // long press changes to double-touch - we shouldn't receive event
807     data.Reset();
808     application.ProcessEvent(GenerateLongPress(Gesture::Possible, 2u, Vector2(50.0f, 10.0f)));
809     application.ProcessEvent(GenerateLongPress(Gesture::Started, 2u, Vector2(50.0f, 10.0f)));
810     application.ProcessEvent(GenerateLongPress(Gesture::Finished, 2u, Vector2(50.0f, 10.0f)));
811     DALI_TEST_EQUALS(false, data.functorCalled, TEST_LOCATION);
812
813     // Reset gesture manager statistics
814     gestureManager.Initialize();
815   }
816
817   // secondDetector has now been deleted.  Gesture detection should have been updated only
818   DALI_TEST_EQUALS(true, gestureManager.WasCalled(TestGestureManager::UpdateType), TEST_LOCATION);
819   DALI_TEST_EQUALS(false, gestureManager.WasCalled(TestGestureManager::RegisterType), TEST_LOCATION);
820   DALI_TEST_EQUALS(false, gestureManager.WasCalled(TestGestureManager::UnregisterType), TEST_LOCATION);
821   END_TEST;
822 }
823
824 int UtcDaliLongPressGestureSignalReceptionMultipleDetectorsOnActor(void)
825 {
826   TestApplication application;
827
828   Actor actor = Actor::New();
829   actor.SetSize(100.0f, 100.0f);
830   actor.SetAnchorPoint(AnchorPoint::TOP_LEFT);
831   Stage::GetCurrent().Add(actor);
832
833   // Render and notify
834   application.SendNotification();
835   application.Render();
836
837   // Attach actor to one detector
838   SignalData firstData;
839   GestureReceivedFunctor firstFunctor(firstData);
840   LongPressGestureDetector firstDetector = LongPressGestureDetector::New();
841   firstDetector.Attach(actor);
842   firstDetector.DetectedSignal().Connect(&application, firstFunctor);
843
844   // Attach actor to another detector
845   SignalData secondData;
846   GestureReceivedFunctor secondFunctor(secondData);
847   LongPressGestureDetector secondDetector = LongPressGestureDetector::New();
848   secondDetector.Attach(actor);
849   secondDetector.DetectedSignal().Connect(&application, secondFunctor);
850
851   // LongPress in actor's area - both detector's functors should be called
852   application.ProcessEvent(GenerateLongPress(Gesture::Possible, 1u, Vector2(50.0f, 10.0f)));
853   application.ProcessEvent(GenerateLongPress(Gesture::Started, 1u, Vector2(50.0f, 10.0f)));
854   DALI_TEST_EQUALS(true, firstData.functorCalled, TEST_LOCATION);
855   DALI_TEST_EQUALS(true, secondData.functorCalled, TEST_LOCATION);
856   END_TEST;
857 }
858
859 int UtcDaliLongPressGestureSignalReceptionDifferentPossible(void)
860 {
861   TestApplication application;
862
863   Actor actor = Actor::New();
864   actor.SetSize(100.0f, 100.0f);
865   actor.SetAnchorPoint(AnchorPoint::TOP_LEFT);
866   Stage::GetCurrent().Add(actor);
867
868   // Render and notify
869   application.SendNotification();
870   application.Render();
871
872   // Attach actor to detector
873   SignalData data;
874   GestureReceivedFunctor functor( data );
875   LongPressGestureDetector detector = LongPressGestureDetector::New();
876   detector.Attach(actor);
877   detector.DetectedSignal().Connect( &application, functor );
878
879   // LongPress possible in actor's area.
880   application.ProcessEvent(GenerateLongPress(Gesture::Possible, 1u, Vector2(50.0f, 10.0f)));
881   DALI_TEST_EQUALS(false, data.functorCalled, TEST_LOCATION);
882
883   // Move actor somewhere else
884   actor.SetPosition( 100.0f, 100.0f );
885
886   // Render and notify
887   application.SendNotification();
888   application.Render();
889
890   // Emit Started event, we should not receive the long press.
891   application.ProcessEvent(GenerateLongPress(Gesture::Started, 1u, Vector2(50.0f, 10.0f)));
892   application.ProcessEvent(GenerateLongPress(Gesture::Finished, 1u, Vector2(50.0f, 10.0f)));
893   DALI_TEST_EQUALS(false, data.functorCalled, TEST_LOCATION);
894
895   // LongPress possible in empty area.
896   application.ProcessEvent(GenerateLongPress(Gesture::Possible, 1u, Vector2(50.0f, 10.0f)));
897   DALI_TEST_EQUALS(false, data.functorCalled, TEST_LOCATION);
898
899   // Move actor in to the long press position.
900   actor.SetPosition( 0.0f, 0.0f );
901
902   // Render and notify
903   application.SendNotification();
904   application.Render();
905
906   // Emit Started event, we should not receive the long press.
907   application.ProcessEvent(GenerateLongPress(Gesture::Started, 1u, Vector2(50.0f, 10.0f)));
908   application.ProcessEvent(GenerateLongPress(Gesture::Finished, 1u, Vector2(50.0f, 10.0f)));
909   DALI_TEST_EQUALS(false, data.functorCalled, TEST_LOCATION);
910
911   // Normal long press in actor's area for completeness.
912   application.ProcessEvent(GenerateLongPress(Gesture::Possible, 1u, Vector2(50.0f, 10.0f)));
913   application.ProcessEvent(GenerateLongPress(Gesture::Started, 1u, Vector2(50.0f, 10.0f)));
914   application.ProcessEvent(GenerateLongPress(Gesture::Finished, 1u, Vector2(50.0f, 10.0f)));
915   DALI_TEST_EQUALS(true, data.functorCalled, TEST_LOCATION);
916   END_TEST;
917 }
918
919 int UtcDaliLongPressGestureEmitIncorrectStateClear(void)
920 {
921   TestApplication application;
922
923   Actor actor = Actor::New();
924   actor.SetSize(100.0f, 100.0f);
925   actor.SetAnchorPoint(AnchorPoint::TOP_LEFT);
926   Stage::GetCurrent().Add(actor);
927
928   // Render and notify
929   application.SendNotification();
930   application.Render();
931
932   // Attach actor to detector
933   SignalData data;
934   GestureReceivedFunctor functor( data );
935   LongPressGestureDetector detector = LongPressGestureDetector::New();
936   detector.Attach(actor);
937   detector.DetectedSignal().Connect( &application, functor );
938
939   // Try a Clear state
940   try
941   {
942     application.ProcessEvent(GenerateLongPress(Gesture::Clear, 1u, Vector2(50.0f, 10.0f)));
943     tet_result(TET_FAIL);
944   }
945   catch ( Dali::DaliException& e )
946   {
947     DALI_TEST_ASSERT( e, "false", TEST_LOCATION );
948   }
949   END_TEST;
950 }
951
952 int UtcDaliLongPressGestureEmitIncorrectStateContinuing(void)
953 {
954   TestApplication application;
955
956   Actor actor = Actor::New();
957   actor.SetSize(100.0f, 100.0f);
958   actor.SetAnchorPoint(AnchorPoint::TOP_LEFT);
959   Stage::GetCurrent().Add(actor);
960
961   // Render and notify
962   application.SendNotification();
963   application.Render();
964
965   // Attach actor to detector
966   SignalData data;
967   GestureReceivedFunctor functor( data );
968   LongPressGestureDetector detector = LongPressGestureDetector::New();
969   detector.Attach(actor);
970   detector.DetectedSignal().Connect( &application, functor );
971
972   // Try a Continuing state
973   try
974   {
975     application.ProcessEvent(GenerateLongPress(Gesture::Continuing, 1u, Vector2(50.0f, 10.0f)));
976     tet_result(TET_FAIL);
977   }
978   catch ( Dali::DaliException& e )
979   {
980     DALI_TEST_ASSERT( e, "false", TEST_LOCATION );
981   }
982   END_TEST;
983 }
984
985 int UtcDaliLongPressGestureRepeatedState(void)
986 {
987   TestApplication application;
988
989   Actor actor = Actor::New();
990   actor.SetSize(100.0f, 100.0f);
991   actor.SetAnchorPoint(AnchorPoint::TOP_LEFT);
992   Stage::GetCurrent().Add(actor);
993
994   // Render and notify
995   application.SendNotification();
996   application.Render();
997
998   // Attach actor to detector
999   SignalData data;
1000   GestureReceivedFunctor functor( data );
1001   LongPressGestureDetector detector = LongPressGestureDetector::New();
1002   detector.Attach(actor);
1003   detector.DetectedSignal().Connect( &application, functor );
1004
1005   // Two possibles
1006   application.ProcessEvent(GenerateLongPress(Gesture::Possible, 1u, Vector2(50.0f, 10.0f)));
1007   DALI_TEST_EQUALS(false, data.functorCalled, TEST_LOCATION);
1008   application.ProcessEvent(GenerateLongPress(Gesture::Possible, 1u, Vector2(50.0f, 10.0f)));
1009   DALI_TEST_EQUALS(false, data.functorCalled, TEST_LOCATION);
1010
1011   // ... Send some finished states, still no signal
1012   application.ProcessEvent(GenerateLongPress(Gesture::Finished, 1u, Vector2(50.0f, 10.0f)));
1013   DALI_TEST_EQUALS(false, data.functorCalled, TEST_LOCATION);
1014   application.ProcessEvent(GenerateLongPress(Gesture::Finished, 1u, Vector2(50.0f, 10.0f)));
1015   DALI_TEST_EQUALS(false, data.functorCalled, TEST_LOCATION);
1016
1017   // Send two Started states, should be signalled
1018   application.ProcessEvent(GenerateLongPress(Gesture::Possible, 1u, Vector2(50.0f, 10.0f)));
1019   DALI_TEST_EQUALS(false, data.functorCalled, TEST_LOCATION);
1020   application.ProcessEvent(GenerateLongPress(Gesture::Started, 1u, Vector2(50.0f, 10.0f)));
1021   DALI_TEST_EQUALS(true, data.functorCalled, TEST_LOCATION);
1022   data.Reset();
1023   application.ProcessEvent(GenerateLongPress(Gesture::Started, 1u, Vector2(50.0f, 10.0f)));
1024   DALI_TEST_EQUALS(true, data.functorCalled, TEST_LOCATION);
1025   data.Reset();
1026   application.ProcessEvent(GenerateLongPress(Gesture::Finished, 1u, Vector2(50.0f, 10.0f)));
1027   DALI_TEST_EQUALS(true, data.functorCalled, TEST_LOCATION);
1028   data.Reset();
1029
1030   // Send two cancelled states, should not be signalled
1031   application.ProcessEvent(GenerateLongPress(Gesture::Cancelled, 1u, Vector2(50.0f, 10.0f)));
1032   DALI_TEST_EQUALS(false, data.functorCalled, TEST_LOCATION);
1033   application.ProcessEvent(GenerateLongPress(Gesture::Cancelled, 1u, Vector2(50.0f, 10.0f)));
1034   DALI_TEST_EQUALS(false, data.functorCalled, TEST_LOCATION);
1035   END_TEST;
1036 }
1037
1038 int UtcDaliLongPressGesturePossibleCancelled(void)
1039 {
1040   TestApplication application;
1041
1042   Actor actor = Actor::New();
1043   actor.SetSize(100.0f, 100.0f);
1044   actor.SetAnchorPoint(AnchorPoint::TOP_LEFT);
1045   Stage::GetCurrent().Add(actor);
1046
1047   // Render and notify
1048   application.SendNotification();
1049   application.Render();
1050
1051   // Attach actor to detector
1052   SignalData data;
1053   GestureReceivedFunctor functor( data );
1054   LongPressGestureDetector detector = LongPressGestureDetector::New();
1055   detector.Attach(actor);
1056   detector.DetectedSignal().Connect( &application, functor );
1057
1058   // Send a possible followed by a cancel, we should not be signalled
1059   application.ProcessEvent(GenerateLongPress(Gesture::Possible, 1u, Vector2(50.0f, 10.0f)));
1060   DALI_TEST_EQUALS(false, data.functorCalled, TEST_LOCATION);
1061   application.ProcessEvent(GenerateLongPress(Gesture::Cancelled, 1u, Vector2(50.0f, 10.0f)));
1062   DALI_TEST_EQUALS(false, data.functorCalled, TEST_LOCATION);
1063   END_TEST;
1064 }
1065
1066 int UtcDaliLongPressGestureDetachAfterStarted(void)
1067 {
1068   TestApplication application;
1069
1070   Actor actor = Actor::New();
1071   actor.SetSize(100.0f, 100.0f);
1072   actor.SetAnchorPoint(AnchorPoint::TOP_LEFT);
1073   Stage::GetCurrent().Add(actor);
1074
1075   // Render and notify
1076   application.SendNotification();
1077   application.Render();
1078
1079   // Attach actor to detector
1080   SignalData data;
1081   GestureReceivedFunctor functor( data );
1082   LongPressGestureDetector detector = LongPressGestureDetector::New();
1083   detector.Attach(actor);
1084   detector.DetectedSignal().Connect( &application, functor );
1085
1086   // Emit initial signal
1087   application.ProcessEvent(GenerateLongPress(Gesture::Possible, 1u, Vector2(50.0f, 10.0f)));
1088   application.ProcessEvent(GenerateLongPress(Gesture::Started, 1u, Vector2(50.0f, 10.0f)));
1089   DALI_TEST_EQUALS(true, data.functorCalled, TEST_LOCATION);
1090   data.Reset();
1091
1092   // Detach actor
1093   detector.Detach(actor);
1094
1095   // Emit Finished, no signal
1096   application.ProcessEvent(GenerateLongPress(Gesture::Finished, 1u, Vector2(50.0f, 10.0f)));
1097   DALI_TEST_EQUALS(false, data.functorCalled, TEST_LOCATION);
1098   END_TEST;
1099 }
1100
1101 int UtcDaliLongPressGestureActorUnstaged(void)
1102 {
1103   TestApplication application;
1104
1105   Actor actor = Actor::New();
1106   actor.SetSize(100.0f, 100.0f);
1107   actor.SetAnchorPoint(AnchorPoint::TOP_LEFT);
1108   Stage::GetCurrent().Add(actor);
1109
1110   // Render and notify
1111   application.SendNotification();
1112   application.Render();
1113
1114   // State to remove actor in.
1115   Gesture::State stateToUnstage( Gesture::Started );
1116
1117   // Attach actor to detector
1118   SignalData data;
1119   UnstageActorFunctor functor( data, stateToUnstage );
1120   LongPressGestureDetector detector = LongPressGestureDetector::New();
1121   detector.Attach(actor);
1122   detector.DetectedSignal().Connect( &application, functor );
1123
1124   // Emit signals
1125   application.ProcessEvent(GenerateLongPress(Gesture::Possible, 1u, Vector2(50.0f, 10.0f)));
1126   application.ProcessEvent(GenerateLongPress(Gesture::Started, 1u, Vector2(50.0f, 10.0f)));
1127   DALI_TEST_EQUALS(true, data.functorCalled, TEST_LOCATION);
1128   data.Reset();
1129   application.ProcessEvent(GenerateLongPress(Gesture::Finished, 1u, Vector2(50.0f, 10.0f)));
1130   DALI_TEST_EQUALS(false, data.functorCalled, TEST_LOCATION);
1131
1132   // Render and notify
1133   application.SendNotification();
1134   application.Render();
1135
1136   // Re-add actor to stage
1137   Stage::GetCurrent().Add(actor);
1138
1139   // Render and notify
1140   application.SendNotification();
1141   application.Render();
1142
1143   // Change state to Gesture::Continuing to remove
1144   stateToUnstage = Gesture::Finished;
1145
1146   // Emit signals
1147   application.ProcessEvent(GenerateLongPress(Gesture::Possible, 1u, Vector2(50.0f, 10.0f)));
1148   application.ProcessEvent(GenerateLongPress(Gesture::Started, 1u, Vector2(50.0f, 10.0f)));
1149   DALI_TEST_EQUALS(true, data.functorCalled, TEST_LOCATION);
1150   data.Reset();
1151   application.ProcessEvent(GenerateLongPress(Gesture::Finished, 1u, Vector2(50.0f, 10.0f)));
1152   DALI_TEST_EQUALS(true, data.functorCalled, TEST_LOCATION);
1153   tet_result( TET_PASS ); // If we get here then we have handled actor stage removal gracefully.
1154   END_TEST;
1155 }
1156
1157 int UtcDaliLongPressGestureActorStagedAndDestroyed(void)
1158 {
1159   TestApplication application;
1160
1161   Actor actor = Actor::New();
1162   actor.SetSize(100.0f, 100.0f);
1163   actor.SetAnchorPoint(AnchorPoint::TOP_LEFT);
1164   Stage::GetCurrent().Add(actor);
1165
1166   // Create and add a second actor so that GestureDetector destruction does not come into play.
1167   Actor dummyActor( Actor::New() );
1168   dummyActor.SetSize( 100.0f, 100.0f );
1169   dummyActor.SetPosition( 100.0f, 100.0f );
1170   dummyActor.SetAnchorPoint(AnchorPoint::TOP_LEFT);
1171   Stage::GetCurrent().Add(dummyActor);
1172
1173   // Render and notify
1174   application.SendNotification();
1175   application.Render();
1176
1177   // State to remove actor in.
1178   Gesture::State stateToUnstage( Gesture::Started );
1179
1180   // Attach actor to detector
1181   SignalData data;
1182   UnstageActorFunctor functor( data, stateToUnstage );
1183   LongPressGestureDetector detector = LongPressGestureDetector::New();
1184   detector.Attach(actor);
1185   detector.Attach(dummyActor);
1186   detector.DetectedSignal().Connect( &application, functor );
1187
1188   // Here we are testing a Started actor which is removed in the Started callback, but then added back
1189   // before we get a finished state.  As we were removed from the stage, even if we're at the same
1190   // position, we should still not be signalled.
1191
1192   // Emit signals
1193   application.ProcessEvent(GenerateLongPress(Gesture::Possible, 1u, Vector2(50.0f, 10.0f)));
1194   application.ProcessEvent(GenerateLongPress(Gesture::Started, 1u, Vector2(50.0f, 10.0f)));
1195   DALI_TEST_EQUALS(true, data.functorCalled, TEST_LOCATION);
1196   data.Reset();
1197
1198   // Render and notify
1199   application.SendNotification();
1200   application.Render();
1201
1202   // Re add to the stage, we should not be signalled
1203   Stage::GetCurrent().Add(actor);
1204
1205   // Render and notify
1206   application.SendNotification();
1207   application.Render();
1208
1209   // Continue signal emission
1210   application.ProcessEvent(GenerateLongPress(Gesture::Finished, 1u, Vector2(50.0f, 10.0f)));
1211   DALI_TEST_EQUALS(false, data.functorCalled, TEST_LOCATION);
1212   data.Reset();
1213
1214   // Here we delete an actor in started, we should not receive any subsequent signalling.
1215
1216   // Emit signals
1217   application.ProcessEvent(GenerateLongPress(Gesture::Possible, 1u, Vector2(50.0f, 10.0f)));
1218   application.ProcessEvent(GenerateLongPress(Gesture::Started, 1u, Vector2(50.0f, 10.0f)));
1219   DALI_TEST_EQUALS(true, data.functorCalled, TEST_LOCATION);
1220   data.Reset();
1221
1222   // Render and notify
1223   application.SendNotification();
1224   application.Render();
1225
1226   // Delete actor as well
1227   actor.Reset();
1228
1229   // Render and notify
1230   application.SendNotification();
1231   application.Render();
1232
1233   // Continue signal emission
1234   application.ProcessEvent(GenerateLongPress(Gesture::Finished, 1u, Vector2(50.0f, 10.0f)));
1235   DALI_TEST_EQUALS(false, data.functorCalled, TEST_LOCATION);
1236   END_TEST;
1237 }
1238
1239 int UtcDaliLongPressGestureSystemOverlay(void)
1240 {
1241   TestApplication application;
1242   Dali::Integration::Core& core = application.GetCore();
1243   Dali::Integration::SystemOverlay& systemOverlay( core.GetSystemOverlay() );
1244   systemOverlay.GetOverlayRenderTasks().CreateTask();
1245
1246   Actor actor = Actor::New();
1247   actor.SetSize(100.0f, 100.0f);
1248   actor.SetAnchorPoint(AnchorPoint::TOP_LEFT);
1249   systemOverlay.Add(actor);
1250
1251   // Render and notify
1252   application.SendNotification();
1253   application.Render();
1254
1255   SignalData data;
1256   GestureReceivedFunctor functor(data);
1257
1258   LongPressGestureDetector detector = LongPressGestureDetector::New();
1259   detector.Attach(actor);
1260   detector.DetectedSignal().Connect(&application, functor);
1261
1262   // Do a long press inside actor's area
1263   Vector2 screenCoords( 50.0f, 50.0f );
1264   application.ProcessEvent( GenerateLongPress( Gesture::Possible, 1u, screenCoords ) );
1265   application.ProcessEvent( GenerateLongPress( Gesture::Started, 1u, screenCoords ) );
1266   DALI_TEST_EQUALS( true, data.functorCalled, TEST_LOCATION );
1267   END_TEST;
1268 }
1269
1270 int UtcDaliLongPressGestureBehindTouchableSystemOverlay(void)
1271 {
1272   TestApplication application;
1273   Dali::Integration::Core& core = application.GetCore();
1274   Dali::Integration::SystemOverlay& systemOverlay( core.GetSystemOverlay() );
1275   systemOverlay.GetOverlayRenderTasks().CreateTask();
1276
1277   // SystemOverlay actor
1278   Actor systemOverlayActor = Actor::New();
1279   systemOverlayActor.SetSize(100.0f, 100.0f);
1280   systemOverlayActor.SetAnchorPoint(AnchorPoint::TOP_LEFT);
1281   systemOverlay.Add(systemOverlayActor);
1282
1283   // Stage actor
1284   Actor stageActor = Actor::New();
1285   stageActor.SetSize(100.0f, 100.0f);
1286   stageActor.SetAnchorPoint(AnchorPoint::TOP_LEFT);
1287   Stage::GetCurrent().Add(stageActor);
1288
1289   // Render and notify
1290   application.SendNotification();
1291   application.Render();
1292
1293   // Set system-overlay actor to touchable
1294   TouchEventData touchData;
1295   TouchEventDataFunctor touchFunctor( touchData );
1296   systemOverlayActor.TouchedSignal().Connect(&application, touchFunctor);
1297
1298   // Set stage actor to receive the gesture
1299   SignalData data;
1300   GestureReceivedFunctor functor(data);
1301
1302   LongPressGestureDetector detector = LongPressGestureDetector::New();
1303   detector.Attach(stageActor);
1304   detector.DetectedSignal().Connect(&application, functor);
1305
1306   // Start long press within the two actors' area
1307   Vector2 screenCoords( 50.0f, 50.0f );
1308   application.ProcessEvent( GenerateLongPress( Gesture::Possible, 1u, screenCoords ) );
1309   application.ProcessEvent( GenerateLongPress( Gesture::Started, 1u, screenCoords ) );
1310   DALI_TEST_EQUALS( true, data.functorCalled, TEST_LOCATION );
1311   DALI_TEST_EQUALS( false, touchData.functorCalled, TEST_LOCATION );
1312
1313   data.Reset();
1314   touchData.Reset();
1315
1316   // Do touch in the same area
1317   application.ProcessEvent( touchFunctor.GenerateSingleTouch( TouchPoint::Down, screenCoords ) );
1318   DALI_TEST_EQUALS( false, data.functorCalled, TEST_LOCATION );
1319   DALI_TEST_EQUALS( true, touchData.functorCalled, TEST_LOCATION );
1320
1321   END_TEST;
1322 }
1323
1324 int UtcDaliLongPressGestureTouchBehindGesturedSystemOverlay(void)
1325 {
1326   TestApplication application;
1327   Dali::Integration::Core& core = application.GetCore();
1328   Dali::Integration::SystemOverlay& systemOverlay( core.GetSystemOverlay() );
1329   systemOverlay.GetOverlayRenderTasks().CreateTask();
1330
1331   // SystemOverlay actor
1332   Actor systemOverlayActor = Actor::New();
1333   systemOverlayActor.SetSize(100.0f, 100.0f);
1334   systemOverlayActor.SetAnchorPoint(AnchorPoint::TOP_LEFT);
1335   systemOverlay.Add(systemOverlayActor);
1336
1337   // Stage actor
1338   Actor stageActor = Actor::New();
1339   stageActor.SetSize(100.0f, 100.0f);
1340   stageActor.SetAnchorPoint(AnchorPoint::TOP_LEFT);
1341   Stage::GetCurrent().Add(stageActor);
1342
1343   // Render and notify
1344   application.SendNotification();
1345   application.Render();
1346
1347   // Set stage actor to touchable
1348   TouchEventData touchData;
1349   TouchEventDataFunctor touchFunctor( touchData );
1350   stageActor.TouchedSignal().Connect(&application, touchFunctor);
1351
1352   // Set system-overlay actor to have the gesture
1353   SignalData data;
1354   GestureReceivedFunctor functor(data);
1355
1356   LongPressGestureDetector detector = LongPressGestureDetector::New();
1357   detector.Attach(systemOverlayActor);
1358   detector.DetectedSignal().Connect(&application, functor);
1359
1360   // Start long press within the two actors' area
1361   Vector2 screenCoords( 50.0f, 50.0f );
1362   application.ProcessEvent( GenerateLongPress( Gesture::Possible, 1u, screenCoords ) );
1363   application.ProcessEvent( GenerateLongPress( Gesture::Started, 1u, screenCoords ) );
1364   DALI_TEST_EQUALS( true, data.functorCalled, TEST_LOCATION );
1365   DALI_TEST_EQUALS( false, touchData.functorCalled, TEST_LOCATION );
1366
1367   data.Reset();
1368   touchData.Reset();
1369
1370   // Do touch in the same area
1371   application.ProcessEvent( touchFunctor.GenerateSingleTouch( TouchPoint::Down, screenCoords ) );
1372   DALI_TEST_EQUALS( false, data.functorCalled, TEST_LOCATION );
1373   DALI_TEST_EQUALS( true, touchData.functorCalled, TEST_LOCATION );
1374
1375   END_TEST;
1376 }
1377
1378 int UtcDaliLongPressGestureLayerConsumesTouch(void)
1379 {
1380   TestApplication application;
1381
1382   Actor actor = Actor::New();
1383   actor.SetSize(100.0f, 100.0f);
1384   actor.SetAnchorPoint(AnchorPoint::TOP_LEFT);
1385   Stage::GetCurrent().Add(actor);
1386
1387   // Add a detector
1388   SignalData data;
1389   GestureReceivedFunctor functor(data);
1390   LongPressGestureDetector detector = LongPressGestureDetector::New();
1391   detector.Attach(actor);
1392   detector.DetectedSignal().Connect( &application, functor );
1393
1394   // Add a layer to overlap the actor
1395   Layer layer = Layer::New();
1396   layer.SetSize(100.0f, 100.0f);
1397   layer.SetAnchorPoint(AnchorPoint::TOP_LEFT);
1398   Stage::GetCurrent().Add( layer );
1399   layer.RaiseToTop();
1400
1401   // Render and notify
1402   application.SendNotification();
1403   application.Render();
1404
1405   Vector2 screenCoords( 50.0f, 50.0f );
1406
1407   // Emit signals, should receive
1408   application.ProcessEvent( GenerateLongPress( Gesture::Possible, 1u, screenCoords ) );
1409   application.ProcessEvent( GenerateLongPress( Gesture::Started, 1u, screenCoords ) );
1410   application.ProcessEvent( GenerateLongPress( Gesture::Finished, 1u, screenCoords ) );
1411   DALI_TEST_EQUALS(true, data.functorCalled, TEST_LOCATION);
1412   data.Reset();
1413
1414   // Set layer to consume all touch
1415   layer.SetTouchConsumed( true );
1416
1417   // Render and notify
1418   application.SendNotification();
1419   application.Render();
1420
1421   // Emit the same signals again, should not receive
1422   application.ProcessEvent( GenerateLongPress( Gesture::Possible, 1u, screenCoords ) );
1423   application.ProcessEvent( GenerateLongPress( Gesture::Started, 1u, screenCoords ) );
1424   application.ProcessEvent( GenerateLongPress( Gesture::Finished, 1u, screenCoords ) );
1425   DALI_TEST_EQUALS(false, data.functorCalled, TEST_LOCATION);
1426   data.Reset();
1427
1428   END_TEST;
1429 }