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