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