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