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