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