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