Merge "Add utc test cases" into tizen
[platform/core/uifw/dali-core.git] / automated-tests / src / dali / utc-Dali-PanGestureDetector.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 <cmath>
22 #include <dali/public-api/dali-core.h>
23 #include <dali/integration-api/events/touch-event-integ.h>
24 #include <dali/integration-api/events/pan-gesture-event.h>
25 #include <dali/integration-api/system-overlay.h>
26 #include <dali/integration-api/profiling.h>
27 #include <dali/integration-api/input-options.h>
28 #include <dali-test-suite-utils.h>
29 #include <test-touch-utils.h>
30
31 using namespace Dali;
32
33 void utc_dali_pan_gesture_detector_startup(void)
34 {
35   test_return_value = TET_UNDEF;
36 }
37
38 void utc_dali_pan_gesture_detector_cleanup(void)
39 {
40   test_return_value = TET_PASS;
41 }
42
43 ///////////////////////////////////////////////////////////////////////////////
44 namespace
45 {
46 typedef Dali::PanGestureDetector::AngleContainer::size_type AngleSizeType;
47
48 const int PAN_EVENT_TIME_DELTA = 8;
49 const int PAN_GESTURE_UPDATE_COUNT = 50;
50
51 // Stores data that is populated in the callback and will be read by the test cases
52 struct SignalData
53 {
54   SignalData()
55   : functorCalled(false),
56     voidFunctorCalled(false),
57     receivedGesture(Gesture::Clear)
58   {}
59
60   void Reset()
61   {
62     functorCalled = false;
63     voidFunctorCalled = false;
64
65     receivedGesture.state = Gesture::Clear;
66     receivedGesture.velocity = Vector2(0.0f, 0.0f);
67     receivedGesture.displacement = Vector2(0.0f, 0.0f);
68     receivedGesture.position = Vector2(0.0f, 0.0f);
69     receivedGesture.screenPosition = Vector2(0.0f, 0.0f);
70     receivedGesture.numberOfTouches = 0;
71
72     pannedActor.Reset();
73   }
74
75   bool functorCalled;
76   bool voidFunctorCalled;
77   PanGesture receivedGesture;
78   Actor pannedActor;
79 };
80
81 // Functor that sets the data when called
82 struct GestureReceivedFunctor
83 {
84   GestureReceivedFunctor(SignalData& data) : signalData(data) { }
85
86   void operator()(Actor actor, const PanGesture& pan)
87   {
88     signalData.functorCalled = true;
89     signalData.receivedGesture = pan;
90     signalData.pannedActor = actor;
91   }
92
93   void operator()()
94   {
95     signalData.voidFunctorCalled = true;
96   }
97
98   SignalData& signalData;
99 };
100
101 // Functor that removes the gestured actor from stage
102 struct UnstageActorFunctor : public GestureReceivedFunctor
103 {
104   UnstageActorFunctor( SignalData& data, Gesture::State& stateToUnstage )
105   : GestureReceivedFunctor( data ),
106     stateToUnstage( stateToUnstage )
107   {
108   }
109
110   void operator()( Actor actor, const PanGesture& pan )
111   {
112     GestureReceivedFunctor::operator()( actor, pan );
113
114     if ( pan.state == stateToUnstage )
115     {
116       Stage::GetCurrent().Remove( actor );
117     }
118   }
119
120   Gesture::State& stateToUnstage;
121 };
122
123 // Functor for receiving a touch event
124 struct TouchEventFunctor
125 {
126   bool operator()(Actor actor, const TouchEvent& touch)
127   {
128     return false;
129   }
130 };
131
132 // Data for constraints
133 struct ConstraintData
134 {
135   ConstraintData()
136   : called(false)
137   {
138   }
139
140   Vector2 screenPosition;
141   Vector2 screenDisplacement;
142   Vector2 screenVelocity;
143   Vector2 localPosition;
144   Vector2 localDisplacement;
145   Vector2 localVelocity;
146   bool called;
147
148   void Reset()
149   {
150     screenPosition = screenDisplacement = screenVelocity = localPosition = localDisplacement = localVelocity = Vector2::ZERO;
151     called = false;
152   }
153 };
154
155 // Constraint used with panning properties
156 struct PanConstraint
157 {
158   PanConstraint( ConstraintData& data ) : constraintData(data) { }
159
160   void operator()( Vector3& current, const PropertyInputContainer& inputs )
161   {
162     constraintData.screenPosition = inputs[0]->GetVector2();
163     constraintData.screenDisplacement = inputs[1]->GetVector2();
164     constraintData.screenVelocity = inputs[2]->GetVector2();
165     constraintData.localPosition = inputs[3]->GetVector2();
166     constraintData.localDisplacement = inputs[4]->GetVector2();
167     constraintData.localVelocity = inputs[5]->GetVector2();
168     constraintData.called = true;
169     current = Vector3::ZERO;
170   }
171
172   ConstraintData& constraintData;
173 };
174
175 // Generate a PanGestureEvent to send to Core
176 Integration::PanGestureEvent GeneratePan(
177     Gesture::State state,
178     Vector2 previousPosition,
179     Vector2 currentPosition,
180     unsigned long timeDelta,
181     unsigned int numberOfTouches = 1,
182     unsigned int time = 1u)
183 {
184   Integration::PanGestureEvent pan(state);
185
186   pan.previousPosition = previousPosition;
187   pan.currentPosition = currentPosition;
188   pan.timeDelta = timeDelta;
189   pan.numberOfTouches = numberOfTouches;
190   pan.time = time;
191
192   return pan;
193 }
194
195 // Generate a PanGesture
196 PanGesture GeneratePan( unsigned int time,
197                         Gesture::State state,
198                         Vector2 screenPosition,
199                         Vector2 localPosition,
200                         Vector2 screenDisplacement = Vector2::ONE,
201                         Vector2 localDisplacement = Vector2::ONE,
202                         Vector2 screenVelocity = Vector2::ONE,
203                         Vector2 localVelocity = Vector2::ONE,
204                         unsigned int numberOfTouches = 1 )
205 {
206   PanGesture pan( state );
207
208   pan.time = time;
209
210   pan.screenPosition = screenPosition;
211   pan.position = localPosition;
212
213   pan.screenDisplacement = screenDisplacement;
214   pan.displacement = localDisplacement;
215
216   pan.screenVelocity = screenVelocity;
217   pan.velocity = localVelocity;
218
219   pan.numberOfTouches = numberOfTouches;
220
221   return pan;
222 }
223
224 /**
225  * Helper to generate PanGestureEvent
226  *
227  * @param[in] application Application instance
228  * @param[in] state The Gesture State
229  * @param[in] pos The current position of touch.
230  */
231 static void SendPan(TestApplication& application, Gesture::State state, const Vector2& pos)
232 {
233   static Vector2 last;
234   static int LastTime = 0;
235
236   if( (state == Gesture::Started) ||
237       (state == Gesture::Possible) )
238   {
239     last.x = pos.x;
240     last.y = pos.y;
241   }
242
243   application.ProcessEvent(GeneratePan(state, last, pos, PAN_EVENT_TIME_DELTA));
244
245   last.x = pos.x;
246   last.y = pos.y;
247   LastTime += PAN_EVENT_TIME_DELTA;
248 }
249
250 static Vector2 PerformSwipeGestureSwipe(TestApplication& application, Vector2 start, Vector2 direction, int frames, bool finish = true)
251 {
252   // Now do a pan starting from (start) and heading (direction)
253   Vector2 pos(start);
254   SendPan(application, Gesture::Possible, pos);
255   SendPan(application, Gesture::Started, pos);
256   application.SendNotification();
257   application.Render();
258
259   for(int i = 0;i<frames;i++)
260   {
261     pos += direction; // Move in this direction
262     SendPan(application, Gesture::Continuing, pos);
263     application.SendNotification();
264     application.Render();
265   }
266
267   if(finish)
268   {
269     SendPan(application, Gesture::Finished, pos);
270     application.SendNotification();
271     application.Render();
272   }
273
274   return pos;
275 }
276
277 } // anon namespace
278
279 ///////////////////////////////////////////////////////////////////////////////
280
281 // Positive test case for a method
282 int UtcDaliPanGestureDetectorConstructor(void)
283 {
284   TestApplication application;
285
286   PanGestureDetector detector;
287   DALI_TEST_CHECK(!detector);
288   END_TEST;
289 }
290
291 int UtcDaliPanGestureDetectorCopyConstructorP(void)
292 {
293   TestApplication application;
294
295   PanGestureDetector detector = PanGestureDetector::New();;
296
297   PanGestureDetector copy( detector );
298   DALI_TEST_CHECK( detector );
299   END_TEST;
300 }
301
302 int UtcDaliPanGestureDetectorAssignmentOperatorP(void)
303 {
304   TestApplication application;
305
306   PanGestureDetector detector = PanGestureDetector::New();;
307
308   PanGestureDetector copy = detector;
309   DALI_TEST_CHECK( detector );
310
311   DALI_TEST_CHECK( detector == copy );
312   END_TEST;
313 }
314
315 // Negative test case for a method
316 int UtcDaliPanGestureDetectorNew(void)
317 {
318   TestApplication application;
319
320   PanGestureDetector detector = PanGestureDetector::New();
321
322   DALI_TEST_CHECK(detector);
323
324   DALI_TEST_EQUALS(1u, detector.GetMinimumTouchesRequired(), TEST_LOCATION);
325   DALI_TEST_EQUALS(1u, detector.GetMaximumTouchesRequired(), TEST_LOCATION);
326
327   // Attach an actor and emit a touch event on the actor to ensure complete line coverage
328   Actor actor = Actor::New();
329   actor.SetSize(100.0f, 100.0f);
330   actor.SetAnchorPoint(AnchorPoint::TOP_LEFT);
331   detector.Attach(actor);
332
333   Stage::GetCurrent().Add(actor);
334
335   // Render and notify
336   application.SendNotification();
337   application.Render();
338
339   Integration::TouchEvent touchEvent(1);
340   TouchPoint point(1, TouchPoint::Down, 20.0f, 20.0f);
341   touchEvent.AddPoint(point);
342   application.ProcessEvent(touchEvent);
343   END_TEST;
344 }
345
346 int UtcDaliPanGestureDetectorDownCast(void)
347 {
348   TestApplication application;
349   tet_infoline("Testing Dali::GestureDetector::DownCast()");
350
351   PanGestureDetector detector = PanGestureDetector::New();
352
353   BaseHandle object(detector);
354
355   PanGestureDetector detector2 = PanGestureDetector::DownCast(object);
356   DALI_TEST_CHECK(detector2);
357
358   PanGestureDetector detector3 = DownCast< PanGestureDetector >(object);
359   DALI_TEST_CHECK(detector3);
360
361   BaseHandle unInitializedObject;
362   PanGestureDetector detector4 = PanGestureDetector::DownCast(unInitializedObject);
363   DALI_TEST_CHECK(!detector4);
364
365   PanGestureDetector detector5 = DownCast< PanGestureDetector >(unInitializedObject);
366   DALI_TEST_CHECK(!detector5);
367
368   GestureDetector detector6 = PanGestureDetector::New();
369   PanGestureDetector detector7 = PanGestureDetector::DownCast(detector6);
370   DALI_TEST_CHECK(detector7);
371   END_TEST;
372 }
373
374 int UtcDaliPanGestureSetMinimumTouchesRequired(void)
375 {
376   TestApplication application;
377
378   PanGestureDetector detector = PanGestureDetector::New();
379
380   unsigned int min = 2;
381
382   DALI_TEST_CHECK(min != detector.GetMinimumTouchesRequired());
383
384   detector.SetMinimumTouchesRequired(min);
385
386   DALI_TEST_EQUALS(min, detector.GetMinimumTouchesRequired(), TEST_LOCATION);
387
388   // Attach an actor and change the minimum touches
389
390   Actor actor = Actor::New();
391   actor.SetSize(100.0f, 100.0f);
392   actor.SetAnchorPoint(AnchorPoint::TOP_LEFT);
393   Stage::GetCurrent().Add(actor);
394
395   // Render and notify
396   application.SendNotification();
397   application.Render();
398
399   SignalData data;
400   GestureReceivedFunctor functor(data);
401
402   detector.Attach(actor);
403   detector.DetectedSignal().Connect(&application, functor);
404
405   TestGestureManager& gestureManager = application.GetGestureManager();
406   gestureManager.Initialize();
407
408   detector.SetMinimumTouchesRequired(3);
409
410   // Gesture detection should have been updated only
411   DALI_TEST_EQUALS(true, gestureManager.WasCalled(TestGestureManager::UpdateType), TEST_LOCATION);
412   DALI_TEST_EQUALS(false, gestureManager.WasCalled(TestGestureManager::RegisterType), TEST_LOCATION);
413   DALI_TEST_EQUALS(false, gestureManager.WasCalled(TestGestureManager::UnregisterType), TEST_LOCATION);
414
415   // Reset values
416   gestureManager.Initialize();
417
418   // Create a second gesture detector that requires even less minimum touches
419   PanGestureDetector secondDetector = PanGestureDetector::New();
420   secondDetector.Attach(actor);
421
422   // Gesture detection should have been updated only
423   DALI_TEST_EQUALS(true, gestureManager.WasCalled(TestGestureManager::UpdateType), TEST_LOCATION);
424   DALI_TEST_EQUALS(false, gestureManager.WasCalled(TestGestureManager::RegisterType), TEST_LOCATION);
425   DALI_TEST_EQUALS(false, gestureManager.WasCalled(TestGestureManager::UnregisterType), TEST_LOCATION);
426   END_TEST;
427 }
428
429 int UtcDaliPanGestureSetMaximumTouchesRequired(void)
430 {
431   TestApplication application;
432
433   PanGestureDetector detector = PanGestureDetector::New();
434
435   unsigned int max = 3;
436
437   DALI_TEST_CHECK(max != detector.GetMaximumTouchesRequired());
438
439   detector.SetMaximumTouchesRequired(max);
440
441   DALI_TEST_EQUALS(max, detector.GetMaximumTouchesRequired(), TEST_LOCATION);
442
443   // Attach an actor and change the maximum touches
444
445   Actor actor = Actor::New();
446   actor.SetSize(100.0f, 100.0f);
447   actor.SetAnchorPoint(AnchorPoint::TOP_LEFT);
448   Stage::GetCurrent().Add(actor);
449
450   // Render and notify
451   application.SendNotification();
452   application.Render();
453
454   SignalData data;
455   GestureReceivedFunctor functor(data);
456
457   detector.Attach(actor);
458   detector.DetectedSignal().Connect(&application, functor);
459
460   TestGestureManager& gestureManager = application.GetGestureManager();
461   gestureManager.Initialize();
462
463   detector.SetMaximumTouchesRequired(4);
464
465   // Gesture detection should have been updated only
466   DALI_TEST_EQUALS(true, gestureManager.WasCalled(TestGestureManager::UpdateType), TEST_LOCATION);
467   DALI_TEST_EQUALS(false, gestureManager.WasCalled(TestGestureManager::RegisterType), TEST_LOCATION);
468   DALI_TEST_EQUALS(false, gestureManager.WasCalled(TestGestureManager::UnregisterType), TEST_LOCATION);
469
470   // Reset values
471   gestureManager.Initialize();
472
473   // Create a second gesture detector that requires even less maximum touches
474   PanGestureDetector secondDetector = PanGestureDetector::New();
475   secondDetector.Attach(actor);
476
477   // Gesture detection should NOT have been updated
478   DALI_TEST_EQUALS(false, gestureManager.WasCalled(TestGestureManager::UpdateType), TEST_LOCATION);
479   DALI_TEST_EQUALS(false, gestureManager.WasCalled(TestGestureManager::RegisterType), TEST_LOCATION);
480   DALI_TEST_EQUALS(false, gestureManager.WasCalled(TestGestureManager::UnregisterType), TEST_LOCATION);
481   END_TEST;
482 }
483
484 int UtcDaliPanGestureGetMinimumTouchesRequired(void)
485 {
486   TestApplication application;
487
488   PanGestureDetector detector = PanGestureDetector::New();
489   DALI_TEST_EQUALS(1u, detector.GetMinimumTouchesRequired(), TEST_LOCATION);
490   END_TEST;
491 }
492
493 int UtcDaliPanGestureGetMaximumTouchesRequired(void)
494 {
495   TestApplication application;
496
497   PanGestureDetector detector = PanGestureDetector::New();
498   DALI_TEST_EQUALS(1u, detector.GetMaximumTouchesRequired(), TEST_LOCATION);
499   END_TEST;
500 }
501
502 int UtcDaliPanGestureSignalReceptionNegative(void)
503 {
504   TestApplication application;
505
506   Actor actor = Actor::New();
507   actor.SetSize(100.0f, 100.0f);
508   actor.SetAnchorPoint(AnchorPoint::TOP_LEFT);
509   Stage::GetCurrent().Add(actor);
510
511   // Render and notify
512   application.SendNotification();
513   application.Render();
514
515   SignalData data;
516   GestureReceivedFunctor functor(data);
517
518   PanGestureDetector detector = PanGestureDetector::New();
519   detector.Attach(actor);
520   detector.DetectedSignal().Connect(&application, functor);
521
522   // Do a pan outside actor's area
523   application.ProcessEvent(GeneratePan(Gesture::Possible, Vector2(110.0f, 110.0f), Vector2(112.0f, 112.0f), 10));
524   application.ProcessEvent(GeneratePan(Gesture::Started, Vector2(110.0f, 110.0f), Vector2(112.0f, 112.0f), 10));
525   DALI_TEST_EQUALS(false, data.functorCalled, TEST_LOCATION);
526
527   // Continue pan into actor's area - we should still not receive the signal
528   data.Reset();
529   application.ProcessEvent(GeneratePan(Gesture::Continuing, Vector2(112.0f, 112.0f), Vector2(20.0f, 20.0f), 10));
530   DALI_TEST_EQUALS(false, data.functorCalled, TEST_LOCATION);
531
532   // Stop panning - we should still not receive the signal
533   data.Reset();
534   application.ProcessEvent(GeneratePan(Gesture::Finished, Vector2(20.0f, 20.0f), Vector2(12.0f, 12.0f), 10));
535   DALI_TEST_EQUALS(false, data.functorCalled, TEST_LOCATION);
536   END_TEST;
537 }
538
539 int UtcDaliPanGestureSignalReceptionDownMotionLeave(void)
540 {
541   TestApplication application;
542
543   Actor actor = Actor::New();
544   actor.SetSize(100.0f, 100.0f);
545   actor.SetAnchorPoint(AnchorPoint::TOP_LEFT);
546   Stage::GetCurrent().Add(actor);
547
548   // Render and notify
549   application.SendNotification();
550   application.Render();
551
552   SignalData data;
553   GestureReceivedFunctor functor(data);
554
555   PanGestureDetector detector = PanGestureDetector::New();
556   detector.Attach(actor);
557   detector.DetectedSignal().Connect(&application, functor);
558
559   // Start pan within the actor's area
560   application.ProcessEvent(GeneratePan(Gesture::Possible, Vector2(10.0f, 20.0f), Vector2(20.0f, 20.0f), 10));
561   application.ProcessEvent(GeneratePan(Gesture::Started, Vector2(10.0f, 20.0f), Vector2(20.0f, 20.0f), 10));
562   DALI_TEST_EQUALS(true, data.functorCalled, TEST_LOCATION);
563   DALI_TEST_EQUALS(Gesture::Started, data.receivedGesture.state, TEST_LOCATION);
564   DALI_TEST_EQUALS(1u, data.receivedGesture.numberOfTouches, TEST_LOCATION);
565   DALI_TEST_EQUALS(Vector2(10.0f, 0.0f), data.receivedGesture.displacement, 0.01f, TEST_LOCATION);
566   DALI_TEST_EQUALS(Vector2(1.0f, 0.0f), data.receivedGesture.velocity, 0.01f, TEST_LOCATION);
567   DALI_TEST_EQUALS(10.0f, data.receivedGesture.GetDistance(), 0.01f, TEST_LOCATION);
568   DALI_TEST_EQUALS(1.0f, data.receivedGesture.GetSpeed(), 0.01f, TEST_LOCATION);
569
570   // Continue the pan within the actor's area - we should still receive the signal
571   data.Reset();
572   application.ProcessEvent(GeneratePan(Gesture::Continuing, Vector2(20.0f, 20.0f), Vector2(20.0f, 10.0f), 10));
573   DALI_TEST_EQUALS(true, data.functorCalled, TEST_LOCATION);
574   DALI_TEST_EQUALS(Gesture::Continuing, data.receivedGesture.state, TEST_LOCATION);
575   DALI_TEST_EQUALS(1u, data.receivedGesture.numberOfTouches, TEST_LOCATION);
576   DALI_TEST_EQUALS(Vector2(0.0f, -10.0f), data.receivedGesture.displacement, 0.01f, TEST_LOCATION);
577   DALI_TEST_EQUALS(Vector2(0.0f, -1.0f), data.receivedGesture.velocity, 0.01f, TEST_LOCATION);
578   DALI_TEST_EQUALS(10.0f, data.receivedGesture.GetDistance(), 0.01f, TEST_LOCATION);
579   DALI_TEST_EQUALS(1.0f, data.receivedGesture.GetSpeed(), 0.01f, TEST_LOCATION);
580
581   // Pan Gesture leaves actor's area - we should still receive the signal
582   data.Reset();
583   application.ProcessEvent(GeneratePan(Gesture::Continuing, Vector2(20.0f, 10.0f), Vector2(320.0f, 10.0f), 10));
584   DALI_TEST_EQUALS(true, data.functorCalled, TEST_LOCATION);
585   DALI_TEST_EQUALS(Gesture::Continuing, data.receivedGesture.state, TEST_LOCATION);
586   DALI_TEST_EQUALS(1u, data.receivedGesture.numberOfTouches, TEST_LOCATION);
587   DALI_TEST_EQUALS(Vector2(300.0f, 0.0f), data.receivedGesture.displacement, 0.01f, TEST_LOCATION);
588   DALI_TEST_EQUALS(Vector2(30.0f, 0.0f), data.receivedGesture.velocity, 0.01f, TEST_LOCATION);
589   DALI_TEST_EQUALS(300.0f, data.receivedGesture.GetDistance(), 0.01f, TEST_LOCATION);
590   DALI_TEST_EQUALS(30.0f, data.receivedGesture.GetSpeed(), 0.01f, TEST_LOCATION);
591
592   // Gesture ends - we would receive a finished state
593   data.Reset();
594   application.ProcessEvent(GeneratePan(Gesture::Finished, Vector2(320.0f, 10.0f), Vector2(310.0f, 10.0f), 10));
595   DALI_TEST_EQUALS(true, data.functorCalled, TEST_LOCATION);
596   DALI_TEST_EQUALS(Gesture::Finished, data.receivedGesture.state, TEST_LOCATION);
597   DALI_TEST_EQUALS(1u, data.receivedGesture.numberOfTouches, TEST_LOCATION);
598   DALI_TEST_EQUALS(Vector2(-10.0f, 0.0f), data.receivedGesture.displacement, 0.01f, TEST_LOCATION);
599   DALI_TEST_EQUALS(Vector2(-1.0f, 0.0f), data.receivedGesture.velocity, 0.01f, TEST_LOCATION);
600   DALI_TEST_EQUALS(10.0f, data.receivedGesture.GetDistance(), 0.01f, TEST_LOCATION);
601   DALI_TEST_EQUALS(1.0f, data.receivedGesture.GetSpeed(), 0.01f, TEST_LOCATION);
602   END_TEST;
603 }
604
605 int UtcDaliPanGestureSignalReceptionDownMotionUp(void)
606 {
607   TestApplication application;
608
609   Actor actor = Actor::New();
610   actor.SetSize(100.0f, 100.0f);
611   actor.SetAnchorPoint(AnchorPoint::TOP_LEFT);
612   Stage::GetCurrent().Add(actor);
613
614   // Render and notify
615   application.SendNotification();
616   application.Render();
617
618   SignalData data;
619   GestureReceivedFunctor functor(data);
620
621   PanGestureDetector detector = PanGestureDetector::New();
622   detector.Attach(actor);
623   detector.DetectedSignal().Connect(&application, functor);
624
625   // Start pan within the actor's area
626   application.ProcessEvent(GeneratePan(Gesture::Possible, Vector2(10.0f, 20.0f), Vector2(20.0f, 20.0f), 10));
627   application.ProcessEvent(GeneratePan(Gesture::Started, Vector2(10.0f, 20.0f), Vector2(20.0f, 20.0f), 10));
628   DALI_TEST_EQUALS(true, data.functorCalled, TEST_LOCATION);
629   DALI_TEST_EQUALS(Gesture::Started, data.receivedGesture.state, TEST_LOCATION);
630   DALI_TEST_EQUALS(1u, data.receivedGesture.numberOfTouches, TEST_LOCATION);
631   DALI_TEST_EQUALS(Vector2(10.0f, 0.0f), data.receivedGesture.displacement, 0.01f, TEST_LOCATION);
632   DALI_TEST_EQUALS(Vector2(1.0f, 0.0f), data.receivedGesture.velocity, 0.01f, TEST_LOCATION);
633   DALI_TEST_EQUALS(10.0f, data.receivedGesture.GetDistance(), 0.01f, TEST_LOCATION);
634   DALI_TEST_EQUALS(1.0f, data.receivedGesture.GetSpeed(), 0.01f, TEST_LOCATION);
635
636   // Continue the pan within the actor's area - we should still receive the signal
637   data.Reset();
638   application.ProcessEvent(GeneratePan(Gesture::Continuing, Vector2(20.0f, 20.0f), Vector2(20.0f, 10.0f), 10));
639   DALI_TEST_EQUALS(true, data.functorCalled, TEST_LOCATION);
640   DALI_TEST_EQUALS(Gesture::Continuing, data.receivedGesture.state, TEST_LOCATION);
641   DALI_TEST_EQUALS(1u, data.receivedGesture.numberOfTouches, TEST_LOCATION);
642   DALI_TEST_EQUALS(Vector2(0.0f, -10.0f), data.receivedGesture.displacement, 0.01f, TEST_LOCATION);
643   DALI_TEST_EQUALS(Vector2(0.0f, -1.0f), data.receivedGesture.velocity, 0.01f, TEST_LOCATION);
644   DALI_TEST_EQUALS(10.0f, data.receivedGesture.GetDistance(), 0.01f, TEST_LOCATION);
645   DALI_TEST_EQUALS(1.0f, data.receivedGesture.GetSpeed(), 0.01f, TEST_LOCATION);
646
647   // Gesture ends within actor's area - we would receive a finished state
648   data.Reset();
649   application.ProcessEvent(GeneratePan(Gesture::Finished, Vector2(20.0f, 10.0f), Vector2(10.0f, 10.0f), 10));
650   DALI_TEST_EQUALS(true, data.functorCalled, TEST_LOCATION);
651   DALI_TEST_EQUALS(Gesture::Finished, data.receivedGesture.state, TEST_LOCATION);
652   DALI_TEST_EQUALS(1u, data.receivedGesture.numberOfTouches, TEST_LOCATION);
653   DALI_TEST_EQUALS(Vector2(-10.0f, 0.0f), data.receivedGesture.displacement, 0.01f, TEST_LOCATION);
654   DALI_TEST_EQUALS(Vector2(-1.0f, 0.0f), data.receivedGesture.velocity, 0.01f, TEST_LOCATION);
655   DALI_TEST_EQUALS(10.0f, data.receivedGesture.GetDistance(), 0.01f, TEST_LOCATION);
656   DALI_TEST_EQUALS(1.0f, data.receivedGesture.GetSpeed(), 0.01f, TEST_LOCATION);
657   END_TEST;
658 }
659
660 int UtcDaliPanGestureSignalReceptionCancelled(void)
661 {
662   TestApplication application;
663
664   Actor actor = Actor::New();
665   actor.SetSize(100.0f, 100.0f);
666   actor.SetAnchorPoint(AnchorPoint::TOP_LEFT);
667   Stage::GetCurrent().Add(actor);
668
669   // Render and notify
670   application.SendNotification();
671   application.Render();
672
673   SignalData data;
674   GestureReceivedFunctor functor(data);
675
676   PanGestureDetector detector = PanGestureDetector::New();
677   detector.Attach(actor);
678   detector.DetectedSignal().Connect(&application, functor);
679
680   // Start pan within the actor's area
681   application.ProcessEvent(GeneratePan(Gesture::Possible, Vector2(10.0f, 20.0f), Vector2(20.0f, 20.0f), 10));
682   application.ProcessEvent(GeneratePan(Gesture::Started, Vector2(10.0f, 20.0f), Vector2(20.0f, 20.0f), 10));
683   DALI_TEST_EQUALS(true, data.functorCalled, TEST_LOCATION);
684   DALI_TEST_EQUALS(Gesture::Started, data.receivedGesture.state, TEST_LOCATION);
685
686   // Continue the pan within the actor's area - we should still receive the signal
687   data.Reset();
688   application.ProcessEvent(GeneratePan(Gesture::Continuing, Vector2(20.0f, 20.0f), Vector2(20.0f, 10.0f), 10));
689   DALI_TEST_EQUALS(true, data.functorCalled, TEST_LOCATION);
690   DALI_TEST_EQUALS(Gesture::Continuing, data.receivedGesture.state, TEST_LOCATION);
691
692   // The gesture is cancelled
693   data.Reset();
694   application.ProcessEvent(GeneratePan(Gesture::Cancelled, Vector2(20.0f, 10.0f), Vector2(10.0f, 10.0f), 10));
695   DALI_TEST_EQUALS(true, data.functorCalled, TEST_LOCATION);
696   DALI_TEST_EQUALS(Gesture::Cancelled, data.receivedGesture.state, TEST_LOCATION);
697   END_TEST;
698 }
699
700 int UtcDaliPanGestureSignalReceptionDetach(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   PanGestureDetector detector = PanGestureDetector::New();
717   detector.Attach(actor);
718   detector.DetectedSignal().Connect(&application, functor);
719
720   // Start pan within the actor's area
721   application.ProcessEvent(GeneratePan(Gesture::Possible, Vector2(10.0f, 20.0f), Vector2(20.0f, 20.0f), 10));
722   application.ProcessEvent(GeneratePan(Gesture::Started, Vector2(10.0f, 20.0f), Vector2(20.0f, 20.0f), 10));
723   DALI_TEST_EQUALS(true, data.functorCalled, TEST_LOCATION);
724
725   // Continue the pan within the actor's area - we should still receive the signal
726   data.Reset();
727   application.ProcessEvent(GeneratePan(Gesture::Continuing, Vector2(20.0f, 20.0f), Vector2(20.0f, 10.0f), 10));
728   DALI_TEST_EQUALS(true, data.functorCalled, TEST_LOCATION);
729
730   // Gesture ends within actor's area
731   data.Reset();
732   application.ProcessEvent(GeneratePan(Gesture::Finished, Vector2(20.0f, 10.0f), Vector2(10.0f, 10.0f), 10));
733   DALI_TEST_EQUALS(true, data.functorCalled, TEST_LOCATION);
734
735   // Detach actor
736   detector.DetachAll();
737
738   // Ensure we are no longer signalled
739   data.Reset();
740   application.ProcessEvent(GeneratePan(Gesture::Possible, Vector2(10.0f, 20.0f), Vector2(20.0f, 20.0f), 10));
741   application.ProcessEvent(GeneratePan(Gesture::Started, Vector2(10.0f, 20.0f), Vector2(20.0f, 20.0f), 10));
742   application.ProcessEvent(GeneratePan(Gesture::Continuing, Vector2(20.0f, 20.0f), Vector2(20.0f, 10.0f), 10));
743   application.ProcessEvent(GeneratePan(Gesture::Finished, Vector2(20.0f, 10.0f), Vector2(10.0f, 10.0f), 10));
744   DALI_TEST_EQUALS(false, data.functorCalled, TEST_LOCATION);
745   END_TEST;
746 }
747
748 int UtcDaliPanGestureSignalReceptionDetachWhilePanning(void)
749 {
750   TestApplication application;
751
752   Actor actor = Actor::New();
753   actor.SetSize(100.0f, 100.0f);
754   actor.SetAnchorPoint(AnchorPoint::TOP_LEFT);
755   Stage::GetCurrent().Add(actor);
756
757   // Render and notify
758   application.SendNotification();
759   application.Render();
760
761   SignalData data;
762   GestureReceivedFunctor functor(data);
763
764   PanGestureDetector detector = PanGestureDetector::New();
765   detector.Attach(actor);
766   detector.DetectedSignal().Connect(&application, functor);
767
768   // Start pan within the actor's area
769   application.ProcessEvent(GeneratePan(Gesture::Possible, Vector2(10.0f, 20.0f), Vector2(20.0f, 20.0f), 10));
770   application.ProcessEvent(GeneratePan(Gesture::Started, Vector2(10.0f, 20.0f), Vector2(20.0f, 20.0f), 10));
771   DALI_TEST_EQUALS(true, data.functorCalled, TEST_LOCATION);
772
773   // Continue the pan within the actor's area - we should still receive the signal
774   data.Reset();
775   application.ProcessEvent(GeneratePan(Gesture::Continuing, Vector2(20.0f, 20.0f), Vector2(20.0f, 10.0f), 10));
776   DALI_TEST_EQUALS(true, data.functorCalled, TEST_LOCATION);
777
778   // Detach actor during the pan, we should not receive the next event
779   detector.DetachAll();
780
781   // Gesture ends within actor's area
782   data.Reset();
783   application.ProcessEvent(GeneratePan(Gesture::Finished, Vector2(20.0f, 10.0f), Vector2(10.0f, 10.0f), 10));
784   DALI_TEST_EQUALS(false, data.functorCalled, TEST_LOCATION);
785   END_TEST;
786 }
787
788 int UtcDaliPanGestureSignalReceptionActorDestroyedWhilePanning(void)
789 {
790   TestApplication application;
791
792   SignalData data;
793   GestureReceivedFunctor functor(data);
794
795   PanGestureDetector detector = PanGestureDetector::New();
796   detector.DetectedSignal().Connect(&application, functor);
797
798   // Attach a temporary actor to stop detector being removed from PanGestureProcessor when main actor
799   // is destroyed.
800   Actor tempActor = Actor::New();
801   tempActor.SetSize(100.0f, 100.0f);
802   tempActor.SetAnchorPoint(AnchorPoint::BOTTOM_RIGHT);
803   Stage::GetCurrent().Add(tempActor);
804   detector.Attach(tempActor);
805
806   // Actor lifetime is scoped
807   {
808     Actor actor = Actor::New();
809     actor.SetSize(100.0f, 100.0f);
810     actor.SetAnchorPoint(AnchorPoint::TOP_LEFT);
811     Stage::GetCurrent().Add(actor);
812
813     // Render and notify
814     application.SendNotification();
815     application.Render();
816
817     detector.Attach(actor);
818
819     // Start pan within the actor's area
820     application.ProcessEvent(GeneratePan(Gesture::Possible, Vector2(10.0f, 20.0f), Vector2(20.0f, 20.0f), 10));
821     application.ProcessEvent(GeneratePan(Gesture::Started, Vector2(10.0f, 20.0f), Vector2(20.0f, 20.0f), 10));
822     DALI_TEST_EQUALS(true, data.functorCalled, TEST_LOCATION);
823
824     // Continue the pan within the actor's area - we should still receive the signal
825     data.Reset();
826     application.ProcessEvent(GeneratePan(Gesture::Continuing, Vector2(20.0f, 20.0f), Vector2(20.0f, 10.0f), 10));
827     DALI_TEST_EQUALS(true, data.functorCalled, TEST_LOCATION);
828
829     // Remove the actor from stage and reset the data
830     Stage::GetCurrent().Remove(actor);
831
832     // Render and notify
833     application.SendNotification();
834     application.Render();
835   }
836
837   // Actor should now have been destroyed
838
839   // Gesture ends within the area where the actor used to be
840   data.Reset();
841   application.ProcessEvent(GeneratePan(Gesture::Finished, Vector2(20.0f, 10.0f), Vector2(10.0f, 10.0f), 10));
842   DALI_TEST_EQUALS(false, data.functorCalled, TEST_LOCATION);
843   END_TEST;
844 }
845
846 int UtcDaliPanGestureSignalReceptionRotatedActor(void)
847 {
848   TestApplication application;
849
850   Actor actor = Actor::New();
851   actor.SetSize(100.0f, 100.0f);
852   actor.SetOrientation(Dali::Degree(90.0f), Vector3::ZAXIS);
853   Stage::GetCurrent().Add(actor);
854
855   // Render and notify
856   application.SendNotification();
857   application.Render();
858
859   SignalData data;
860   GestureReceivedFunctor functor(data);
861
862   PanGestureDetector detector = PanGestureDetector::New();
863   detector.Attach(actor);
864   detector.DetectedSignal().Connect(&application, functor);
865
866   // Do an entire pan, only check finished value
867   application.ProcessEvent(GeneratePan(Gesture::Possible, Vector2(11.0f, 12.0f), Vector2(22.0f, 12.0f), 10));
868   application.ProcessEvent(GeneratePan(Gesture::Started, Vector2(11.0f, 12.0f), Vector2(22.0f, 12.0f), 10));
869   data.Reset();
870   application.ProcessEvent(GeneratePan(Gesture::Finished, Vector2(22.0f, 12.0f), Vector2(27.0f, 20.0f), 10));
871   DALI_TEST_EQUALS(true, data.functorCalled, TEST_LOCATION);
872   DALI_TEST_EQUALS(Vector2(8.0f, -5.0f), data.receivedGesture.displacement, 0.01f, TEST_LOCATION); // Actor relative
873
874   // Rotate actor again and render a couple of times
875   actor.SetOrientation(Dali::Degree(180.0f), Vector3::ZAXIS);
876   application.SendNotification();
877   application.Render();
878
879   // Do an entire pan, only check finished value
880   application.ProcessEvent(GeneratePan(Gesture::Possible, Vector2(11.0f, 12.0f), Vector2(22.0f, 12.0f), 10));
881   application.ProcessEvent(GeneratePan(Gesture::Started, Vector2(11.0f, 12.0f), Vector2(22.0f, 12.0f), 10));
882   data.Reset();
883   application.ProcessEvent(GeneratePan(Gesture::Finished, Vector2(22.0f, 12.0f), Vector2(27.0f, 20.0f), 10));
884   DALI_TEST_EQUALS(true, data.functorCalled, TEST_LOCATION);
885   DALI_TEST_EQUALS(Vector2(-5.0f, -8.0f), data.receivedGesture.displacement, 0.01f, TEST_LOCATION); // Actor relative
886
887   // Rotate actor again and render a couple of times
888   actor.SetOrientation(Dali::Degree(270.0f), Vector3::ZAXIS);
889   application.SendNotification();
890   application.Render();
891
892   // Do an entire pan, only check finished value
893   application.ProcessEvent(GeneratePan(Gesture::Possible, Vector2(11.0f, 12.0f), Vector2(22.0f, 12.0f), 10));
894   application.ProcessEvent(GeneratePan(Gesture::Started, Vector2(11.0f, 12.0f), Vector2(22.0f, 12.0f), 10));
895   data.Reset();
896   application.ProcessEvent(GeneratePan(Gesture::Finished, Vector2(22.0f, 12.0f), Vector2(27.0f, 20.0f), 10));
897   DALI_TEST_EQUALS(true, data.functorCalled, TEST_LOCATION);
898   DALI_TEST_EQUALS(Vector2(-8.0f, 5.0f), data.receivedGesture.displacement, 0.01f, TEST_LOCATION); // Actor relative
899   END_TEST;
900 }
901
902 int UtcDaliPanGestureSignalReceptionChildHit(void)
903 {
904   TestApplication application;
905
906   Actor parent = Actor::New();
907   parent.SetSize(100.0f, 100.0f);
908   parent.SetAnchorPoint(AnchorPoint::TOP_LEFT);
909   Stage::GetCurrent().Add(parent);
910
911   // Set child to completely cover parent.
912   // Change rotation of child to be different from parent so that we can check if our local coordinate
913   // conversion of the parent actor is correct.
914   Actor child = Actor::New();
915   child.SetSize(100.0f, 100.0f);
916   child.SetAnchorPoint(AnchorPoint::CENTER);
917   child.SetParentOrigin(ParentOrigin::CENTER);
918   child.SetOrientation(Dali::Degree(90.0f), Vector3::ZAXIS);
919   parent.Add(child);
920
921   TouchEventFunctor touchFunctor;
922   child.TouchedSignal().Connect(&application, touchFunctor);
923
924   // Render and notify
925   application.SendNotification();
926   application.Render();
927
928   SignalData data;
929   GestureReceivedFunctor functor(data);
930
931   PanGestureDetector detector = PanGestureDetector::New();
932   detector.Attach(parent);
933   detector.DetectedSignal().Connect(&application, functor);
934
935   // Do an entire pan, only check finished value - hits child area but parent should still receive it
936   application.ProcessEvent(GeneratePan(Gesture::Possible, Vector2(11.0f, 12.0f), Vector2(22.0f, 12.0f), 10));
937   application.ProcessEvent(GeneratePan(Gesture::Started, Vector2(11.0f, 12.0f), Vector2(22.0f, 12.0f), 10));
938   data.Reset();
939   application.ProcessEvent(GeneratePan(Gesture::Finished, Vector2(22.0f, 12.0f), Vector2(27.0f, 20.0f), 10));
940   DALI_TEST_EQUALS(true, data.functorCalled, TEST_LOCATION);
941   DALI_TEST_EQUALS(true, parent == data.pannedActor, TEST_LOCATION);
942   DALI_TEST_EQUALS(Vector2(5.0f, 8.0f), data.receivedGesture.displacement, 0.01f, TEST_LOCATION); // Actor relative
943
944   // Attach child and generate same touch points to yield a different displacement
945   // (Also proves that you can detach and then re-attach another actor)
946   detector.Attach(child);
947   detector.Detach(parent);
948
949   // Do an entire pan, only check finished value
950   application.ProcessEvent(GeneratePan(Gesture::Possible, Vector2(11.0f, 12.0f), Vector2(22.0f, 12.0f), 10));
951   application.ProcessEvent(GeneratePan(Gesture::Started, Vector2(11.0f, 12.0f), Vector2(22.0f, 12.0f), 10));
952   data.Reset();
953   application.ProcessEvent(GeneratePan(Gesture::Finished, Vector2(22.0f, 12.0f), Vector2(27.0f, 20.0f), 10));
954   DALI_TEST_EQUALS(true, data.functorCalled, TEST_LOCATION);
955   DALI_TEST_EQUALS(true, child == data.pannedActor, TEST_LOCATION);
956   DALI_TEST_EQUALS(Vector2(8.0f, -5.0f), data.receivedGesture.displacement, 0.01f, TEST_LOCATION); // Actor relative
957   END_TEST;
958 }
959
960 int UtcDaliPanGestureSignalReceptionAttachDetachMany(void)
961 {
962   TestApplication application;
963
964   Actor first = Actor::New();
965   first.SetSize(100.0f, 100.0f);
966   first.SetAnchorPoint(AnchorPoint::TOP_LEFT);
967   Stage::GetCurrent().Add(first);
968
969   Actor second = Actor::New();
970   second.SetSize(100.0f, 100.0f);
971   second.SetX(100.0f);
972   second.SetAnchorPoint(AnchorPoint::TOP_LEFT);
973   Stage::GetCurrent().Add(second);
974
975   // Render and notify
976   application.SendNotification();
977   application.Render();
978
979   SignalData data;
980   GestureReceivedFunctor functor(data);
981
982   PanGestureDetector detector = PanGestureDetector::New();
983   detector.Attach(first);
984   detector.Attach(second);
985   detector.DetectedSignal().Connect(&application, functor);
986
987   // Start pan within second actor's area
988   application.ProcessEvent(GeneratePan(Gesture::Possible, Vector2(110.0f, 20.0f), Vector2(120.0f, 20.0f), 10));
989   application.ProcessEvent(GeneratePan(Gesture::Started, Vector2(110.0f, 20.0f), Vector2(120.0f, 20.0f), 10));
990   DALI_TEST_EQUALS(true, data.functorCalled, TEST_LOCATION);
991   DALI_TEST_EQUALS(true, second == data.pannedActor, TEST_LOCATION);
992
993   // Pan moves into first actor's area - second actor should receive the pan
994   data.Reset();
995   application.ProcessEvent(GeneratePan(Gesture::Continuing, Vector2(120.0f, 20.0f), Vector2(20.0f, 10.0f), 10));
996   DALI_TEST_EQUALS(true, data.functorCalled, TEST_LOCATION);
997   DALI_TEST_EQUALS(true, second == data.pannedActor, TEST_LOCATION);
998
999   // Detach the second actor during the pan, we should not receive the next event
1000   detector.Detach(second);
1001
1002   // Gesture ends within actor's area
1003   data.Reset();
1004   application.ProcessEvent(GeneratePan(Gesture::Finished, Vector2(20.0f, 10.0f), Vector2(10.0f, 10.0f), 10));
1005   DALI_TEST_EQUALS(false, data.functorCalled, TEST_LOCATION);
1006   END_TEST;
1007 }
1008
1009 int UtcDaliPanGestureSignalReceptionActorBecomesUntouchable(void)
1010 {
1011   TestApplication application;
1012
1013   Actor actor = Actor::New();
1014   actor.SetSize(100.0f, 100.0f);
1015   actor.SetAnchorPoint(AnchorPoint::TOP_LEFT);
1016   Stage::GetCurrent().Add(actor);
1017
1018   // Render and notify
1019   application.SendNotification();
1020   application.Render();
1021
1022   SignalData data;
1023   GestureReceivedFunctor functor(data);
1024
1025   PanGestureDetector detector = PanGestureDetector::New();
1026   detector.Attach(actor);
1027   detector.DetectedSignal().Connect(&application, functor);
1028
1029   // Start pan in actor's area
1030   application.ProcessEvent(GeneratePan(Gesture::Possible, Vector2(10.0f, 20.0f), Vector2(20.0f, 20.0f), 10));
1031   application.ProcessEvent(GeneratePan(Gesture::Started, Vector2(10.0f, 20.0f), Vector2(20.0f, 20.0f), 10));
1032   DALI_TEST_EQUALS(true, data.functorCalled, TEST_LOCATION);
1033
1034   // Pan continues within actor's area
1035   data.Reset();
1036   application.ProcessEvent(GeneratePan(Gesture::Continuing, Vector2(20.0f, 20.0f), Vector2(20.0f, 10.0f), 10));
1037   DALI_TEST_EQUALS(true, data.functorCalled, TEST_LOCATION);
1038
1039   // Actor become invisible - actor should not receive the next pan
1040   actor.SetVisible(false);
1041
1042   // Render and notify
1043   application.SendNotification();
1044   application.Render();
1045
1046   // Gesture ends within actor's area
1047   data.Reset();
1048   application.ProcessEvent(GeneratePan(Gesture::Finished, Vector2(20.0f, 10.0f), Vector2(10.0f, 10.0f), 10));
1049   DALI_TEST_EQUALS(false, data.functorCalled, TEST_LOCATION);
1050   END_TEST;
1051 }
1052
1053 int UtcDaliPanGestureSignalReceptionMultipleGestureDetectors(void)
1054 {
1055   TestApplication application;
1056   Dali::TestGestureManager& gestureManager = application.GetGestureManager();
1057
1058   Actor first = Actor::New();
1059   first.SetSize(100.0f, 100.0f);
1060   first.SetAnchorPoint(AnchorPoint::TOP_LEFT);
1061   Stage::GetCurrent().Add(first);
1062
1063   Actor second = Actor::New();
1064   second.SetSize(100.0f, 100.0f);
1065   second.SetAnchorPoint(AnchorPoint::TOP_LEFT);
1066   first.Add(second);
1067
1068   // Render and notify
1069   application.SendNotification();
1070   application.Render();
1071
1072   SignalData data;
1073   GestureReceivedFunctor functor(data);
1074
1075   PanGestureDetector firstDetector = PanGestureDetector::New();
1076   firstDetector.Attach(first);
1077   firstDetector.DetectedSignal().Connect(&application, functor);
1078
1079   // secondDetector is scoped
1080   {
1081     // Reset gestureManager statistics
1082     gestureManager.Initialize();
1083
1084     PanGestureDetector secondDetector = PanGestureDetector::New();
1085     secondDetector.SetMinimumTouchesRequired(2);
1086     secondDetector.SetMaximumTouchesRequired(2);
1087     secondDetector.Attach(second);
1088     secondDetector.DetectedSignal().Connect(&application, functor);
1089
1090     DALI_TEST_EQUALS(true, gestureManager.WasCalled(TestGestureManager::UpdateType), TEST_LOCATION);
1091     DALI_TEST_EQUALS(false, gestureManager.WasCalled(TestGestureManager::RegisterType), TEST_LOCATION);
1092     DALI_TEST_EQUALS(false, gestureManager.WasCalled(TestGestureManager::UnregisterType), TEST_LOCATION);
1093
1094     // Start pan within second actor's area
1095     application.ProcessEvent(GeneratePan(Gesture::Possible, Vector2(10.0f, 20.0f), Vector2(20.0f, 20.0f), 10, 2));
1096     application.ProcessEvent(GeneratePan(Gesture::Started, Vector2(10.0f, 20.0f), Vector2(20.0f, 20.0f), 10, 2));
1097     DALI_TEST_EQUALS(true, data.functorCalled, TEST_LOCATION);
1098     DALI_TEST_EQUALS(true, second == data.pannedActor, TEST_LOCATION);
1099
1100     // Two touch pan changes to single touch - we should receive a finished state
1101     data.Reset();
1102     application.ProcessEvent(GeneratePan(Gesture::Continuing, Vector2(20.0f, 20.0f), Vector2(20.0f, 10.0f), 10));
1103     DALI_TEST_EQUALS(true, data.functorCalled, TEST_LOCATION);
1104     DALI_TEST_EQUALS(Gesture::Finished, data.receivedGesture.state, TEST_LOCATION);
1105     DALI_TEST_EQUALS(true, second == data.pannedActor, TEST_LOCATION);
1106
1107     // Pan continues as single touch gesture - we should not receive any gesture
1108     data.Reset();
1109     application.ProcessEvent(GeneratePan(Gesture::Continuing, Vector2(20.0f, 10.0f), Vector2(30.0f, 10.0f), 10));
1110     DALI_TEST_EQUALS(false, data.functorCalled, TEST_LOCATION);
1111
1112     // Pan ends - still no signal
1113     data.Reset();
1114     application.ProcessEvent(GeneratePan(Gesture::Finished, Vector2(30.0f, 10.0f), Vector2(30.0f, 20.0f), 10));
1115     DALI_TEST_EQUALS(false, data.functorCalled, TEST_LOCATION);
1116
1117     // Single touch pan starts - first actor should be panned
1118     data.Reset();
1119     application.ProcessEvent(GeneratePan(Gesture::Possible, Vector2(10.0f, 20.0f), Vector2(20.0f, 20.0f), 10));
1120     application.ProcessEvent(GeneratePan(Gesture::Started, Vector2(10.0f, 20.0f), Vector2(20.0f, 20.0f), 10));
1121     DALI_TEST_EQUALS(true, data.functorCalled, TEST_LOCATION);
1122     DALI_TEST_EQUALS(true, first == data.pannedActor, TEST_LOCATION);
1123
1124     // Pan changes to double-touch - we should receive a finished state
1125     data.Reset();
1126     application.ProcessEvent(GeneratePan(Gesture::Continuing, Vector2(20.0f, 20.0f), Vector2(20.0f, 10.0f), 10, 2));
1127     DALI_TEST_EQUALS(true, data.functorCalled, TEST_LOCATION);
1128     DALI_TEST_EQUALS(Gesture::Finished, data.receivedGesture.state, TEST_LOCATION);
1129     DALI_TEST_EQUALS(true, first == data.pannedActor, TEST_LOCATION);
1130
1131     // Pan continues as double touch gesture - we should not receive any gesture
1132     data.Reset();
1133     application.ProcessEvent(GeneratePan(Gesture::Continuing, Vector2(20.0f, 10.0f), Vector2(30.0f, 10.0f), 10));
1134     DALI_TEST_EQUALS(false, data.functorCalled, TEST_LOCATION);
1135
1136     // Pan ends - still no signal
1137     data.Reset();
1138     application.ProcessEvent(GeneratePan(Gesture::Finished, Vector2(30.0f, 10.0f), Vector2(30.0f, 20.0f), 10));
1139     DALI_TEST_EQUALS(false, data.functorCalled, TEST_LOCATION);
1140
1141     // Reset gesture manager statistics
1142     gestureManager.Initialize();
1143   }
1144
1145   // secondDetector has now been deleted.  Gesture detection should have been updated only
1146   DALI_TEST_EQUALS(true, gestureManager.WasCalled(TestGestureManager::UpdateType), TEST_LOCATION);
1147   DALI_TEST_EQUALS(false, gestureManager.WasCalled(TestGestureManager::RegisterType), TEST_LOCATION);
1148   DALI_TEST_EQUALS(false, gestureManager.WasCalled(TestGestureManager::UnregisterType), TEST_LOCATION);
1149   END_TEST;
1150 }
1151
1152 int UtcDaliPanGestureSignalReceptionMultipleDetectorsOnActor(void)
1153 {
1154   TestApplication application;
1155
1156   Actor actor = Actor::New();
1157   actor.SetSize(100.0f, 100.0f);
1158   actor.SetAnchorPoint(AnchorPoint::TOP_LEFT);
1159   Stage::GetCurrent().Add(actor);
1160
1161   Actor actor2 = Actor::New();
1162   actor2.SetSize(100.0f, 100.0f);
1163   actor2.SetAnchorPoint(AnchorPoint::BOTTOM_RIGHT);
1164   Stage::GetCurrent().Add(actor2);
1165
1166   // Render and notify
1167   application.SendNotification();
1168   application.Render();
1169
1170   // Attach actor to one detector
1171   SignalData firstData;
1172   GestureReceivedFunctor firstFunctor(firstData);
1173   PanGestureDetector firstDetector = PanGestureDetector::New();
1174   firstDetector.Attach(actor);
1175   firstDetector.DetectedSignal().Connect(&application, firstFunctor);
1176
1177   // Attach actor to another detector
1178   SignalData secondData;
1179   GestureReceivedFunctor secondFunctor(secondData);
1180   PanGestureDetector secondDetector = PanGestureDetector::New();
1181   secondDetector.Attach(actor);
1182   secondDetector.DetectedSignal().Connect(&application, secondFunctor);
1183
1184   // Add second actor to second detector, when we remove the actor, this will make sure that this
1185   // gesture detector is not removed from the GestureDetectorProcessor.  In this scenario, the
1186   // functor should still not be called (which is what we're also testing).
1187   secondDetector.Attach(actor2);
1188
1189   // Pan in actor's area - both detector's functors should be called
1190   application.ProcessEvent(GeneratePan(Gesture::Possible, Vector2(10.0f, 20.0f), Vector2(20.0f, 20.0f), 10));
1191   application.ProcessEvent(GeneratePan(Gesture::Started, Vector2(10.0f, 20.0f), Vector2(20.0f, 20.0f), 10));
1192   DALI_TEST_EQUALS(true, firstData.functorCalled, TEST_LOCATION);
1193   DALI_TEST_EQUALS(true, secondData.functorCalled, TEST_LOCATION);
1194
1195   // Pan continues in actor's area - both detector's functors should be called
1196   firstData.Reset();
1197   secondData.Reset();
1198   application.ProcessEvent(GeneratePan(Gesture::Continuing, Vector2(20.0f, 20.0f), Vector2(10.0f, 20.0f), 10));
1199   DALI_TEST_EQUALS(true, firstData.functorCalled, TEST_LOCATION);
1200   DALI_TEST_EQUALS(true, secondData.functorCalled, TEST_LOCATION);
1201
1202   // Detach actor from firstDetector and emit pan on actor, only secondDetector's functor should be called.
1203   firstDetector.Detach(actor);
1204   firstData.Reset();
1205   secondData.Reset();
1206   application.ProcessEvent(GeneratePan(Gesture::Finished, Vector2(20.0f, 20.0f), Vector2(10.0f, 20.0f), 10));
1207   DALI_TEST_EQUALS(false, firstData.functorCalled, TEST_LOCATION);
1208   DALI_TEST_EQUALS(true, secondData.functorCalled, TEST_LOCATION);
1209
1210   // New pan on actor, only secondDetector has actor attached
1211   firstData.Reset();
1212   secondData.Reset();
1213   application.ProcessEvent(GeneratePan(Gesture::Possible, Vector2(10.0f, 20.0f), Vector2(20.0f, 20.0f), 10));
1214   application.ProcessEvent(GeneratePan(Gesture::Started, Vector2(10.0f, 20.0f), Vector2(20.0f, 20.0f), 10));
1215   DALI_TEST_EQUALS(false, firstData.functorCalled, TEST_LOCATION);
1216   DALI_TEST_EQUALS(true, secondData.functorCalled, TEST_LOCATION);
1217
1218   // Detach actor from secondDetector
1219   secondDetector.Detach(actor);
1220   firstData.Reset();
1221   secondData.Reset();
1222   application.ProcessEvent(GeneratePan(Gesture::Continuing, Vector2(20.0f, 20.0f), Vector2(10.0f, 20.0f), 10));
1223   DALI_TEST_EQUALS(false, firstData.functorCalled, TEST_LOCATION);
1224   DALI_TEST_EQUALS(false, secondData.functorCalled, TEST_LOCATION);
1225   END_TEST;
1226 }
1227
1228 int UtcDaliPanGestureSignalReceptionMultipleStarted(void)
1229 {
1230   // Should handle two started events gracefully.
1231
1232   TestApplication application;
1233
1234   Actor actor = Actor::New();
1235   actor.SetSize(100.0f, 100.0f);
1236   actor.SetAnchorPoint(AnchorPoint::TOP_LEFT);
1237   Stage::GetCurrent().Add(actor);
1238
1239   SignalData data;
1240   GestureReceivedFunctor functor(data);
1241
1242   PanGestureDetector detector = PanGestureDetector::New();
1243   detector.Attach(actor);
1244   detector.DetectedSignal().Connect(&application, functor);
1245
1246   // Render and notify
1247   application.SendNotification();
1248   application.Render();
1249
1250   // Start pan in actor's area
1251   application.ProcessEvent(GeneratePan(Gesture::Possible, Vector2(10.0f, 20.0f), Vector2(20.0f, 20.0f), 10));
1252   application.ProcessEvent(GeneratePan(Gesture::Started, Vector2(10.0f, 20.0f), Vector2(20.0f, 20.0f), 10));
1253   DALI_TEST_EQUALS(true, data.functorCalled, TEST_LOCATION);
1254
1255   // Send another start in actor's area
1256   data.Reset();
1257   application.ProcessEvent(GeneratePan(Gesture::Started, Vector2(10.0f, 20.0f), Vector2(20.0f, 20.0f), 10));
1258   DALI_TEST_EQUALS(true, data.functorCalled, TEST_LOCATION);
1259
1260   // Add a child actor to overlap actor and send another start in actor's area
1261   Actor child = Actor::New();
1262   child.SetSize(100.0f, 100.0f);
1263   child.SetAnchorPoint(AnchorPoint::CENTER);
1264   child.SetParentOrigin(ParentOrigin::CENTER);
1265   actor.Add(child);
1266
1267   TouchEventFunctor touchFunctor;
1268   child.TouchedSignal().Connect(&application, touchFunctor);
1269
1270   // Render and notify
1271   application.SendNotification();
1272   application.Render();
1273
1274   // Send another possible and start in actor's area
1275   data.Reset();
1276   application.ProcessEvent(GeneratePan(Gesture::Possible, Vector2(10.0f, 20.0f), Vector2(20.0f, 20.0f), 10));
1277   application.ProcessEvent(GeneratePan(Gesture::Started, Vector2(10.0f, 20.0f), Vector2(20.0f, 20.0f), 10));
1278   DALI_TEST_EQUALS(true, data.functorCalled, TEST_LOCATION);
1279
1280   // Send another start in actor's area
1281   data.Reset();
1282   application.ProcessEvent(GeneratePan(Gesture::Possible, Vector2(10.0f, 20.0f), Vector2(20.0f, 20.0f), 10));
1283   application.ProcessEvent(GeneratePan(Gesture::Started, Vector2(10.0f, 20.0f), Vector2(20.0f, 20.0f), 10));
1284   DALI_TEST_EQUALS(true, data.functorCalled, TEST_LOCATION);
1285   END_TEST;
1286 }
1287
1288 int UtcDaliPanGestureSignalReceptionEnsureCorrectSignalling(void)
1289 {
1290   TestApplication application;
1291
1292   Actor actor1 = Actor::New();
1293   actor1.SetSize(100.0f, 100.0f);
1294   actor1.SetAnchorPoint(AnchorPoint::TOP_LEFT);
1295   Stage::GetCurrent().Add(actor1);
1296   SignalData data1;
1297   GestureReceivedFunctor functor1(data1);
1298   PanGestureDetector detector1 = PanGestureDetector::New();
1299   detector1.Attach(actor1);
1300   detector1.DetectedSignal().Connect(&application, functor1);
1301
1302   Actor actor2 = Actor::New();
1303   actor2.SetSize(100.0f, 100.0f);
1304   actor2.SetAnchorPoint(AnchorPoint::BOTTOM_RIGHT);
1305   actor2.SetParentOrigin(ParentOrigin::BOTTOM_RIGHT);
1306   Stage::GetCurrent().Add(actor2);
1307   SignalData data2;
1308   GestureReceivedFunctor functor2(data2);
1309   PanGestureDetector detector2 = PanGestureDetector::New();
1310   detector2.Attach(actor2);
1311   detector2.DetectedSignal().Connect(&application, functor2);
1312
1313   // Render and notify
1314   application.SendNotification();
1315   application.Render();
1316
1317   // Start pan in actor1's area, only data1 should be set
1318   application.ProcessEvent(GeneratePan(Gesture::Possible, Vector2(10.0f, 20.0f), Vector2(20.0f, 20.0f), 10));
1319   application.ProcessEvent(GeneratePan(Gesture::Started, Vector2(10.0f, 20.0f), Vector2(20.0f, 20.0f), 10));
1320   DALI_TEST_EQUALS(true, data1.functorCalled, TEST_LOCATION);
1321   DALI_TEST_EQUALS(false, data2.functorCalled, TEST_LOCATION);
1322   END_TEST;
1323 }
1324
1325 int UtcDaliPanGestureSignalReceptionDifferentPossible(void)
1326 {
1327   TestApplication application;
1328
1329   Actor actor = Actor::New();
1330   actor.SetSize(100.0f, 100.0f);
1331   actor.SetAnchorPoint(AnchorPoint::TOP_LEFT);
1332   Stage::GetCurrent().Add(actor);
1333
1334   // Render and notify
1335   application.SendNotification();
1336   application.Render();
1337
1338   // Attach actor to detector
1339   SignalData data;
1340   GestureReceivedFunctor functor( data );
1341   PanGestureDetector detector = PanGestureDetector::New();
1342   detector.Attach(actor);
1343   detector.DetectedSignal().Connect( &application, functor );
1344
1345   // Gesture possible in actor's area.
1346   application.ProcessEvent(GeneratePan(Gesture::Possible, Vector2(10.0f, 20.0f), Vector2(20.0f, 20.0f), 10));
1347   DALI_TEST_EQUALS(false, data.functorCalled, TEST_LOCATION);
1348
1349   // Move actor somewhere else
1350   actor.SetPosition( 100.0f, 100.0f );
1351
1352   // Render and notify
1353   application.SendNotification();
1354   application.Render();
1355
1356   // Emit Started event, we should not receive the long press.
1357   application.ProcessEvent(GeneratePan(Gesture::Started, Vector2(10.0f, 20.0f), Vector2(20.0f, 20.0f), 10));
1358   application.ProcessEvent(GeneratePan(Gesture::Finished, Vector2(10.0f, 20.0f), Vector2(20.0f, 20.0f), 10));
1359   DALI_TEST_EQUALS(false, data.functorCalled, TEST_LOCATION);
1360
1361   // LongPress possible in empty area.
1362   application.ProcessEvent(GeneratePan(Gesture::Possible, Vector2(10.0f, 20.0f), Vector2(20.0f, 20.0f), 10));
1363   DALI_TEST_EQUALS(false, data.functorCalled, TEST_LOCATION);
1364
1365   // Move actor in to the long press position.
1366   actor.SetPosition( 0.0f, 0.0f );
1367
1368   // Render and notify
1369   application.SendNotification();
1370   application.Render();
1371
1372   // Emit Started event, we should not receive the long press.
1373   application.ProcessEvent(GeneratePan(Gesture::Started, Vector2(10.0f, 20.0f), Vector2(20.0f, 20.0f), 10));
1374   application.ProcessEvent(GeneratePan(Gesture::Finished, Vector2(10.0f, 20.0f), Vector2(20.0f, 20.0f), 10));
1375   DALI_TEST_EQUALS(false, data.functorCalled, TEST_LOCATION);
1376
1377   // Normal long press in actor's area for completeness.
1378   application.ProcessEvent(GeneratePan(Gesture::Possible, Vector2(10.0f, 20.0f), Vector2(20.0f, 20.0f), 10));
1379   application.ProcessEvent(GeneratePan(Gesture::Started, Vector2(10.0f, 20.0f), Vector2(20.0f, 20.0f), 10));
1380   application.ProcessEvent(GeneratePan(Gesture::Finished, Vector2(10.0f, 20.0f), Vector2(20.0f, 20.0f), 10));
1381   DALI_TEST_EQUALS(true, data.functorCalled, TEST_LOCATION);
1382   END_TEST;
1383 }
1384
1385 int UtcDaliPanGestureEmitIncorrectState(void)
1386 {
1387   TestApplication application;
1388
1389   Actor actor = Actor::New();
1390   actor.SetSize(100.0f, 100.0f);
1391   actor.SetAnchorPoint(AnchorPoint::TOP_LEFT);
1392   Stage::GetCurrent().Add(actor);
1393
1394   // Render and notify
1395   application.SendNotification();
1396   application.Render();
1397
1398   // Attach actor to detector
1399   SignalData data;
1400   GestureReceivedFunctor functor( data );
1401   PanGestureDetector detector = PanGestureDetector::New();
1402   detector.Attach(actor);
1403   detector.DetectedSignal().Connect( &application, functor );
1404
1405   // Try a Clear state
1406   try
1407   {
1408     application.ProcessEvent(GeneratePan(Gesture::Clear, Vector2(10.0f, 20.0f), Vector2(20.0f, 20.0f), 10));
1409     tet_result(TET_FAIL);
1410   }
1411   catch ( Dali::DaliException& e )
1412   {
1413     DALI_TEST_ASSERT( e, "false", TEST_LOCATION );
1414   }
1415   END_TEST;
1416 }
1417
1418 int UtcDaliPanGestureActorUnstaged(void)
1419 {
1420   TestApplication application;
1421
1422   Actor actor = Actor::New();
1423   actor.SetSize(100.0f, 100.0f);
1424   actor.SetAnchorPoint(AnchorPoint::TOP_LEFT);
1425   Stage::GetCurrent().Add(actor);
1426
1427   // Render and notify
1428   application.SendNotification();
1429   application.Render();
1430
1431   // State to remove actor in.
1432   Gesture::State stateToUnstage( Gesture::Started );
1433
1434   // Attach actor to detector
1435   SignalData data;
1436   UnstageActorFunctor functor( data, stateToUnstage );
1437   PanGestureDetector detector = PanGestureDetector::New();
1438   detector.Attach(actor);
1439   detector.DetectedSignal().Connect( &application, functor );
1440
1441   // Emit signals
1442   application.ProcessEvent(GeneratePan(Gesture::Possible, Vector2(10.0f, 20.0f), Vector2(20.0f, 20.0f), 10));
1443   application.ProcessEvent(GeneratePan(Gesture::Started, Vector2(10.0f, 20.0f), Vector2(20.0f, 20.0f), 10));
1444   DALI_TEST_EQUALS(true, data.functorCalled, TEST_LOCATION);
1445   data.Reset();
1446   application.ProcessEvent(GeneratePan(Gesture::Finished, Vector2(10.0f, 20.0f), Vector2(20.0f, 20.0f), 10));
1447   DALI_TEST_EQUALS(false, data.functorCalled, TEST_LOCATION);
1448   data.Reset();
1449
1450   // Render and notify
1451   application.SendNotification();
1452   application.Render();
1453
1454   // Re-add actor to stage
1455   Stage::GetCurrent().Add(actor);
1456
1457   // Render and notify
1458   application.SendNotification();
1459   application.Render();
1460
1461   // Change state to Gesture::Continuing to remove
1462   stateToUnstage = Gesture::Continuing;
1463
1464   // Emit signals
1465   application.ProcessEvent(GeneratePan(Gesture::Possible, Vector2(10.0f, 20.0f), Vector2(20.0f, 20.0f), 10));
1466   application.ProcessEvent(GeneratePan(Gesture::Started, Vector2(10.0f, 20.0f), Vector2(20.0f, 20.0f), 10));
1467   DALI_TEST_EQUALS(true, data.functorCalled, TEST_LOCATION);
1468   data.Reset();
1469   application.ProcessEvent(GeneratePan(Gesture::Continuing, Vector2(10.0f, 20.0f), Vector2(20.0f, 20.0f), 10));
1470   DALI_TEST_EQUALS(true, data.functorCalled, TEST_LOCATION);
1471   data.Reset();
1472   application.ProcessEvent(GeneratePan(Gesture::Finished, Vector2(10.0f, 20.0f), Vector2(20.0f, 20.0f), 10));
1473   DALI_TEST_EQUALS(false, data.functorCalled, TEST_LOCATION);
1474   data.Reset();
1475
1476   // Render and notify
1477   application.SendNotification();
1478   application.Render();
1479
1480   // Re-add actor to stage
1481   Stage::GetCurrent().Add(actor);
1482
1483   // Render and notify
1484   application.SendNotification();
1485   application.Render();
1486
1487   // Change state to Gesture::Finished to remove
1488   stateToUnstage = Gesture::Finished;
1489
1490   // Emit signals
1491   application.ProcessEvent(GeneratePan(Gesture::Possible, Vector2(10.0f, 20.0f), Vector2(20.0f, 20.0f), 10));
1492   application.ProcessEvent(GeneratePan(Gesture::Started, Vector2(10.0f, 20.0f), Vector2(20.0f, 20.0f), 10));
1493   DALI_TEST_EQUALS(true, data.functorCalled, TEST_LOCATION);
1494   data.Reset();
1495   application.ProcessEvent(GeneratePan(Gesture::Continuing, Vector2(10.0f, 20.0f), Vector2(20.0f, 20.0f), 10));
1496   DALI_TEST_EQUALS(true, data.functorCalled, TEST_LOCATION);
1497   data.Reset();
1498   application.ProcessEvent(GeneratePan(Gesture::Finished, Vector2(10.0f, 20.0f), Vector2(20.0f, 20.0f), 10));
1499   DALI_TEST_EQUALS(true, data.functorCalled, TEST_LOCATION);
1500   tet_result( TET_PASS ); // If we get here then we have handled actor stage removal gracefully.
1501   END_TEST;
1502 }
1503
1504 int UtcDaliPanGestureActorStagedAndDestroyed(void)
1505 {
1506   TestApplication application;
1507
1508   Actor actor = Actor::New();
1509   actor.SetSize(100.0f, 100.0f);
1510   actor.SetAnchorPoint(AnchorPoint::TOP_LEFT);
1511   Stage::GetCurrent().Add(actor);
1512
1513   // Create and add a second actor so that GestureDetector destruction does not come into play.
1514   Actor dummyActor( Actor::New() );
1515   dummyActor.SetSize( 100.0f, 100.0f );
1516   dummyActor.SetPosition( 100.0f, 100.0f );
1517   dummyActor.SetAnchorPoint(AnchorPoint::TOP_LEFT);
1518   Stage::GetCurrent().Add(dummyActor);
1519
1520   // Render and notify
1521   application.SendNotification();
1522   application.Render();
1523
1524   // State to remove actor in.
1525   Gesture::State stateToUnstage( Gesture::Started );
1526
1527   // Attach actor to detector
1528   SignalData data;
1529   UnstageActorFunctor functor( data, stateToUnstage );
1530   PanGestureDetector detector = PanGestureDetector::New();
1531   detector.Attach(actor);
1532   detector.Attach(dummyActor);
1533   detector.DetectedSignal().Connect( &application, functor );
1534
1535   // Here we are testing a Started actor which is removed in the Started callback, but then added back
1536   // before we get a continuing state.  As we were removed from the stage, even if we're at the same
1537   // position, we should still not be signalled.
1538
1539   // Emit signals
1540   application.ProcessEvent(GeneratePan(Gesture::Possible, Vector2(10.0f, 20.0f), Vector2(20.0f, 20.0f), 10));
1541   application.ProcessEvent(GeneratePan(Gesture::Started, Vector2(10.0f, 20.0f), Vector2(20.0f, 20.0f), 10));
1542   DALI_TEST_EQUALS(true, data.functorCalled, TEST_LOCATION);
1543   data.Reset();
1544
1545   // Render and notify
1546   application.SendNotification();
1547   application.Render();
1548
1549   // Re add to the stage, we should not be signalled
1550   Stage::GetCurrent().Add(actor);
1551
1552   // Render and notify
1553   application.SendNotification();
1554   application.Render();
1555
1556   // Continue signal emission
1557   application.ProcessEvent(GeneratePan(Gesture::Continuing, Vector2(10.0f, 20.0f), Vector2(20.0f, 20.0f), 10));
1558   DALI_TEST_EQUALS(false, data.functorCalled, TEST_LOCATION);
1559   data.Reset();
1560   application.ProcessEvent(GeneratePan(Gesture::Finished, Vector2(10.0f, 20.0f), Vector2(20.0f, 20.0f), 10));
1561   DALI_TEST_EQUALS(false, data.functorCalled, TEST_LOCATION);
1562   data.Reset();
1563
1564   // Here we delete an actor in started, we should not receive any subsequent signalling.
1565
1566   // Emit signals
1567   application.ProcessEvent(GeneratePan(Gesture::Possible, Vector2(10.0f, 20.0f), Vector2(20.0f, 20.0f), 10));
1568   application.ProcessEvent(GeneratePan(Gesture::Started, Vector2(10.0f, 20.0f), Vector2(20.0f, 20.0f), 10));
1569   DALI_TEST_EQUALS(true, data.functorCalled, TEST_LOCATION);
1570   data.Reset();
1571
1572   // Render and notify
1573   application.SendNotification();
1574   application.Render();
1575
1576   // Delete actor as well
1577   actor.Reset();
1578
1579   // Render and notify
1580   application.SendNotification();
1581   application.Render();
1582
1583   // Continue signal emission
1584   application.ProcessEvent(GeneratePan(Gesture::Continuing, Vector2(10.0f, 20.0f), Vector2(20.0f, 20.0f), 10));
1585   DALI_TEST_EQUALS(false, data.functorCalled, TEST_LOCATION);
1586   data.Reset();
1587   application.ProcessEvent(GeneratePan(Gesture::Finished, Vector2(10.0f, 20.0f), Vector2(20.0f, 20.0f), 10));
1588   DALI_TEST_EQUALS(false, data.functorCalled, TEST_LOCATION);
1589   END_TEST;
1590 }
1591
1592 int UtcDaliPanGestureSystemOverlay(void)
1593 {
1594   TestApplication application;
1595   Dali::Integration::Core& core = application.GetCore();
1596   Dali::Integration::SystemOverlay& systemOverlay( core.GetSystemOverlay() );
1597   systemOverlay.GetOverlayRenderTasks().CreateTask();
1598
1599   Actor actor = Actor::New();
1600   actor.SetSize(100.0f, 100.0f);
1601   actor.SetAnchorPoint(AnchorPoint::TOP_LEFT);
1602   systemOverlay.Add(actor);
1603
1604   // Render and notify
1605   application.SendNotification();
1606   application.Render();
1607
1608   SignalData data;
1609   GestureReceivedFunctor functor(data);
1610
1611   PanGestureDetector detector = PanGestureDetector::New();
1612   detector.Attach(actor);
1613   detector.DetectedSignal().Connect(&application, functor);
1614
1615   Vector2 screenCoordsStart( 10.0f, 20.0f );
1616   Vector2 screenCoordsEnd( 20.0f, 20.0f );
1617
1618   // Start pan within the actor's area
1619   application.ProcessEvent( GeneratePan( Gesture::Possible, screenCoordsStart, screenCoordsEnd, 10 ) );
1620   application.ProcessEvent( GeneratePan( Gesture::Started, screenCoordsStart, screenCoordsEnd, 10 ) );
1621   DALI_TEST_EQUALS( true, data.functorCalled, TEST_LOCATION );
1622   END_TEST;
1623 }
1624
1625 int UtcDaliPanGestureBehindTouchableSystemOverlay(void)
1626 {
1627   TestApplication application;
1628   Dali::Integration::Core& core = application.GetCore();
1629   Dali::Integration::SystemOverlay& systemOverlay( core.GetSystemOverlay() );
1630   systemOverlay.GetOverlayRenderTasks().CreateTask();
1631
1632   // SystemOverlay actor
1633   Actor systemOverlayActor = Actor::New();
1634   systemOverlayActor.SetSize(100.0f, 100.0f);
1635   systemOverlayActor.SetAnchorPoint(AnchorPoint::TOP_LEFT);
1636   systemOverlay.Add(systemOverlayActor);
1637
1638   // Stage actor
1639   Actor stageActor = Actor::New();
1640   stageActor.SetSize(100.0f, 100.0f);
1641   stageActor.SetAnchorPoint(AnchorPoint::TOP_LEFT);
1642   Stage::GetCurrent().Add(stageActor);
1643
1644   // Render and notify
1645   application.SendNotification();
1646   application.Render();
1647
1648   // Set system-overlay actor to touchable
1649   TouchEventData touchData;
1650   TouchEventDataFunctor touchFunctor( touchData );
1651   systemOverlayActor.TouchedSignal().Connect(&application, touchFunctor);
1652
1653   // Set stage actor to receive the gesture
1654   SignalData data;
1655   GestureReceivedFunctor functor(data);
1656
1657   PanGestureDetector detector = PanGestureDetector::New();
1658   detector.Attach(stageActor);
1659   detector.DetectedSignal().Connect(&application, functor);
1660
1661   Vector2 screenCoordsStart( 10.0f, 20.0f );
1662   Vector2 screenCoordsEnd( 20.0f, 20.0f );
1663
1664   // Start pan within the two actors' area
1665   application.ProcessEvent( GeneratePan( Gesture::Possible, screenCoordsStart, screenCoordsEnd, 10 ) );
1666   application.ProcessEvent( GeneratePan( Gesture::Started, screenCoordsStart, screenCoordsEnd, 10 ) );
1667   application.ProcessEvent( GeneratePan( Gesture::Finished, screenCoordsStart, screenCoordsEnd, 10 ) );
1668   DALI_TEST_EQUALS( true, data.functorCalled, TEST_LOCATION );
1669   DALI_TEST_EQUALS( false, touchData.functorCalled, TEST_LOCATION );
1670
1671   data.Reset();
1672   touchData.Reset();
1673
1674   // Do touch in the same area
1675   application.ProcessEvent( touchFunctor.GenerateSingleTouch( TouchPoint::Down, screenCoordsStart ) );
1676   DALI_TEST_EQUALS( false, data.functorCalled, TEST_LOCATION );
1677   DALI_TEST_EQUALS( true, touchData.functorCalled, TEST_LOCATION );
1678
1679   END_TEST;
1680 }
1681
1682 int UtcDaliPanGestureTouchBehindGesturedSystemOverlay(void)
1683 {
1684   TestApplication application;
1685   Dali::Integration::Core& core = application.GetCore();
1686   Dali::Integration::SystemOverlay& systemOverlay( core.GetSystemOverlay() );
1687   systemOverlay.GetOverlayRenderTasks().CreateTask();
1688
1689   // SystemOverlay actor
1690   Actor systemOverlayActor = Actor::New();
1691   systemOverlayActor.SetSize(100.0f, 100.0f);
1692   systemOverlayActor.SetAnchorPoint(AnchorPoint::TOP_LEFT);
1693   systemOverlay.Add(systemOverlayActor);
1694
1695   // Stage actor
1696   Actor stageActor = Actor::New();
1697   stageActor.SetSize(100.0f, 100.0f);
1698   stageActor.SetAnchorPoint(AnchorPoint::TOP_LEFT);
1699   Stage::GetCurrent().Add(stageActor);
1700
1701   // Render and notify
1702   application.SendNotification();
1703   application.Render();
1704
1705   // Set stage actor to touchable
1706   TouchEventData touchData;
1707   TouchEventDataFunctor touchFunctor( touchData );
1708   stageActor.TouchedSignal().Connect(&application, touchFunctor);
1709
1710   // Set system-overlay actor to have the gesture
1711   SignalData data;
1712   GestureReceivedFunctor functor(data);
1713
1714   PanGestureDetector detector = PanGestureDetector::New();
1715   detector.Attach(systemOverlayActor);
1716   detector.DetectedSignal().Connect(&application, functor);
1717
1718   Vector2 screenCoordsStart( 10.0f, 20.0f );
1719   Vector2 screenCoordsEnd( 20.0f, 20.0f );
1720
1721   // Start pan within the two actors' area
1722   application.ProcessEvent( GeneratePan( Gesture::Possible, screenCoordsStart, screenCoordsEnd, 10 ) );
1723   application.ProcessEvent( GeneratePan( Gesture::Started, screenCoordsStart, screenCoordsEnd, 10 ) );
1724   application.ProcessEvent( GeneratePan( Gesture::Finished, screenCoordsStart, screenCoordsEnd, 10 ) );
1725   DALI_TEST_EQUALS( true, data.functorCalled, TEST_LOCATION );
1726   DALI_TEST_EQUALS( false, touchData.functorCalled, TEST_LOCATION );
1727
1728   data.Reset();
1729   touchData.Reset();
1730
1731   // Do touch in the same area
1732   application.ProcessEvent( touchFunctor.GenerateSingleTouch( TouchPoint::Down, screenCoordsStart ) );
1733   DALI_TEST_EQUALS( false, data.functorCalled, TEST_LOCATION );
1734   DALI_TEST_EQUALS( true, touchData.functorCalled, TEST_LOCATION );
1735
1736   END_TEST;
1737 }
1738
1739 int UtcDaliPanGestureAngleHandling(void)
1740 {
1741   TestApplication application;
1742
1743   PanGestureDetector detector = PanGestureDetector::New();
1744   const PanGestureDetector::AngleContainer& angles( detector.GetAngles() );
1745   DALI_TEST_EQUALS( angles.empty(), true, TEST_LOCATION );
1746
1747   detector.AddAngle( PanGestureDetector::DIRECTION_LEFT, Radian( Math::PI * 0.25 ) );
1748   DALI_TEST_EQUALS( angles.size(), static_cast<AngleSizeType>(1), TEST_LOCATION );
1749   for ( PanGestureDetector::AngleContainer::const_iterator iter = angles.begin(), endIter = angles.end(); iter != endIter; ++iter )
1750   {
1751     if ( iter->first == PanGestureDetector::DIRECTION_LEFT )
1752     {
1753       tet_result( TET_PASS );
1754       break;
1755     }
1756
1757     if ( iter == endIter )
1758     {
1759       tet_printf("%s, angle not added\n", TEST_LOCATION );
1760       tet_result( TET_FAIL );
1761     }
1762   }
1763
1764   detector.AddAngle( PanGestureDetector::DIRECTION_RIGHT, Radian( Math::PI * 0.25 ) );
1765   DALI_TEST_EQUALS( angles.size(), static_cast<AngleSizeType>(2), TEST_LOCATION );
1766
1767   // Remove something not in the container.
1768   detector.RemoveAngle( PanGestureDetector::DIRECTION_UP );
1769   DALI_TEST_EQUALS( angles.size(), static_cast<AngleSizeType>(2), TEST_LOCATION );
1770
1771   detector.RemoveAngle( PanGestureDetector::DIRECTION_RIGHT );
1772   DALI_TEST_EQUALS( angles.size(), static_cast<AngleSizeType>(1), TEST_LOCATION );
1773   for ( PanGestureDetector::AngleContainer::const_iterator iter = angles.begin(), endIter = angles.end(); iter != endIter; ++iter )
1774   {
1775     if ( iter->first == PanGestureDetector::DIRECTION_RIGHT )
1776     {
1777       tet_printf("%s, angle not removed\n", TEST_LOCATION );
1778       tet_result( TET_FAIL );
1779       break;
1780     }
1781   }
1782
1783   detector.ClearAngles();
1784   DALI_TEST_EQUALS( angles.size(), static_cast<AngleSizeType>(0), TEST_LOCATION );
1785   END_TEST;
1786 }
1787
1788 inline float RadiansToDegrees( float radian )
1789 {
1790   return radian * 180.0f / Math::PI;
1791 }
1792
1793 int UtcDaliPanGestureAngleOutOfRange(void)
1794 {
1795   TestApplication application;
1796
1797   PanGestureDetector detector = PanGestureDetector::New();
1798   const PanGestureDetector::AngleContainer& angles( detector.GetAngles() );
1799   DALI_TEST_EQUALS( angles.empty(), true, TEST_LOCATION );
1800
1801   //
1802   // Angle
1803   //
1804
1805   detector.AddAngle( Degree(180.0f) );
1806   DALI_TEST_EQUALS( angles.begin()->first, Radian( Degree(-180.0f) ), 0.000001, TEST_LOCATION );
1807   detector.ClearAngles();
1808
1809   detector.AddAngle( Degree(190.0f) );
1810   DALI_TEST_EQUALS( angles.begin()->first, Radian( Degree(-170.0f) ), 0.000001, TEST_LOCATION );
1811   detector.ClearAngles();
1812
1813   detector.AddAngle( Degree(-190.0f) );
1814   DALI_TEST_EQUALS( angles.begin()->first, Radian( Degree(170.0f) ), 0.000001, TEST_LOCATION );
1815   detector.ClearAngles();
1816
1817   detector.AddAngle( Degree(350.0f) );
1818   DALI_TEST_EQUALS( angles.begin()->first, Radian( Degree(-10.0f) ), 0.000001, TEST_LOCATION );
1819   detector.ClearAngles();
1820
1821   detector.AddAngle( Degree(-350.0f) );
1822   DALI_TEST_EQUALS( angles.begin()->first, Radian( Degree(10.0f) ), 0.000001, TEST_LOCATION );
1823   detector.ClearAngles();
1824
1825   detector.AddAngle( Degree(370.0f) );
1826   DALI_TEST_EQUALS( angles.begin()->first, Radian( Degree(10.0f) ), 0.000001, TEST_LOCATION );
1827   detector.ClearAngles();
1828
1829   detector.AddAngle( Degree(-370.0f) );
1830   DALI_TEST_EQUALS( angles.begin()->first, Radian( Degree(-10.0f) ), 0.000001, TEST_LOCATION );
1831   detector.ClearAngles();
1832
1833   //
1834   // Threshold
1835   //
1836
1837   detector.AddAngle( PanGestureDetector::DIRECTION_RIGHT, Degree( 0.0f ) );
1838   DALI_TEST_EQUALS( angles.begin()->second, Radian( Degree(0.0f) ), 0.000001, TEST_LOCATION );
1839   detector.ClearAngles();
1840
1841   detector.AddAngle( PanGestureDetector::DIRECTION_RIGHT, Degree( -10.0f ) );
1842   DALI_TEST_EQUALS( angles.begin()->second, Radian( Degree(10.0f) ), 0.000001, TEST_LOCATION );
1843   detector.ClearAngles();
1844
1845   detector.AddAngle( PanGestureDetector::DIRECTION_RIGHT, Degree( -181.0f ) );
1846   DALI_TEST_EQUALS( angles.begin()->second, Radian( Degree(180.0f) ), 0.000001, TEST_LOCATION );
1847   detector.ClearAngles();
1848
1849   detector.AddAngle( PanGestureDetector::DIRECTION_RIGHT, Degree( 181.0f ) );
1850   DALI_TEST_EQUALS( angles.begin()->second, Radian( Degree(180.0f) ), 0.000001, TEST_LOCATION );
1851   detector.ClearAngles();
1852   END_TEST;
1853 }
1854
1855 int UtcDaliPanGestureAngleProcessing(void)
1856 {
1857   TestApplication application;
1858
1859   Actor parent = Actor::New();
1860   parent.SetSize(100.0f, 100.0f);
1861   parent.SetAnchorPoint(AnchorPoint::TOP_LEFT);
1862   Stage::GetCurrent().Add(parent);
1863
1864   Actor child = Actor::New();
1865   child.SetSize(100.0f, 100.0f);
1866   child.SetAnchorPoint(AnchorPoint::TOP_LEFT);
1867   parent.Add(child);
1868
1869   // Render and notify
1870   application.SendNotification();
1871   application.Render();
1872
1873   // Parent detector only requires up pans
1874   PanGestureDetector parentDetector = PanGestureDetector::New();
1875   parentDetector.Attach( parent );
1876   parentDetector.AddAngle( PanGestureDetector::DIRECTION_UP, Degree( 30.0f ) );
1877   SignalData parentData;
1878   GestureReceivedFunctor parentFunctor(parentData);
1879   parentDetector.DetectedSignal().Connect(&application, parentFunctor);
1880
1881   // Child detector only requires right pans
1882   PanGestureDetector childDetector = PanGestureDetector::New();
1883   childDetector.Attach( child );
1884   childDetector.AddAngle( PanGestureDetector::DIRECTION_RIGHT, Degree( 30.0f ) );
1885   SignalData childData;
1886   GestureReceivedFunctor childFunctor(childData);
1887   childDetector.DetectedSignal().Connect(&application, childFunctor);
1888
1889   // Generate an Up pan gesture, only parent should receive it.
1890   application.ProcessEvent( GeneratePan( Gesture::Possible, Vector2(20.0f, 20.0f), Vector2(20.0f, 20.0f), 10 ) );
1891   application.ProcessEvent( GeneratePan( Gesture::Started,  Vector2(20.0f, 20.0f), Vector2(20.0f, 10.0f), 10 ) );
1892   DALI_TEST_EQUALS( true,  parentData.functorCalled, TEST_LOCATION );
1893   DALI_TEST_EQUALS( false, childData.functorCalled,  TEST_LOCATION );
1894   application.ProcessEvent( GeneratePan( Gesture::Finished,  Vector2(20.0f, 30.0f), Vector2(20.0f, 20.0f), 10 ) );
1895   parentData.Reset();
1896   childData.Reset();
1897
1898   // Generate a Right pan gesture, only child should receive it.
1899   application.ProcessEvent( GeneratePan( Gesture::Possible, Vector2(20.0f, 20.0f), Vector2(20.0f, 20.0f), 10 ) );
1900   application.ProcessEvent( GeneratePan( Gesture::Started,  Vector2(20.0f, 20.0f), Vector2(30.0f, 20.0f), 10 ) );
1901   DALI_TEST_EQUALS( false, parentData.functorCalled, TEST_LOCATION );
1902   DALI_TEST_EQUALS( true,  childData.functorCalled,  TEST_LOCATION );
1903   application.ProcessEvent( GeneratePan( Gesture::Finished,  Vector2(20.0f, 30.0f), Vector2(20.0f, 20.0f), 10 ) );
1904   parentData.Reset();
1905   childData.Reset();
1906
1907   // Generate a Down pan gesture, no one should receive it.
1908   application.ProcessEvent( GeneratePan( Gesture::Possible, Vector2(20.0f, 20.0f), Vector2(20.0f, 20.0f), 10 ) );
1909   application.ProcessEvent( GeneratePan( Gesture::Started,  Vector2(20.0f, 20.0f), Vector2(20.0f, 30.0f), 10 ) );
1910   DALI_TEST_EQUALS( false, parentData.functorCalled, TEST_LOCATION );
1911   DALI_TEST_EQUALS( false, childData.functorCalled,  TEST_LOCATION );
1912   application.ProcessEvent( GeneratePan( Gesture::Finished,  Vector2(20.0f, 30.0f), Vector2(20.0f, 20.0f), 10 ) );
1913   parentData.Reset();
1914   childData.Reset();
1915
1916   // Generate a Left pan gesture, no one should receive it.
1917   application.ProcessEvent( GeneratePan( Gesture::Possible, Vector2(20.0f, 20.0f), Vector2(20.0f, 20.0f), 10 ) );
1918   application.ProcessEvent( GeneratePan( Gesture::Started,  Vector2(20.0f, 20.0f), Vector2(10.0f, 20.0f), 10 ) );
1919   DALI_TEST_EQUALS( false, parentData.functorCalled, TEST_LOCATION );
1920   DALI_TEST_EQUALS( false, childData.functorCalled,  TEST_LOCATION );
1921   application.ProcessEvent( GeneratePan( Gesture::Finished,  Vector2(20.0f, 30.0f), Vector2(20.0f, 20.0f), 10 ) );
1922   parentData.Reset();
1923   childData.Reset();
1924   END_TEST;
1925 }
1926
1927 int UtcDaliPanGestureDirectionHandling(void)
1928 {
1929   TestApplication application;
1930
1931   PanGestureDetector detector = PanGestureDetector::New();
1932   const PanGestureDetector::AngleContainer& angles( detector.GetAngles() );
1933   DALI_TEST_EQUALS( angles.empty(), true, TEST_LOCATION );
1934
1935   detector.AddDirection( PanGestureDetector::DIRECTION_LEFT, Radian( Math::PI * 0.25 ) );
1936   DALI_TEST_EQUALS( angles.size(), static_cast<AngleSizeType>(2), TEST_LOCATION );
1937   for ( PanGestureDetector::AngleContainer::const_iterator iter = angles.begin(), endIter = angles.end(); iter != endIter; ++iter )
1938   {
1939     if ( iter->first == PanGestureDetector::DIRECTION_LEFT )
1940     {
1941       tet_result( TET_PASS );
1942       break;
1943     }
1944
1945     if ( iter == endIter )
1946     {
1947       tet_printf("%s, angle not added\n", TEST_LOCATION );
1948       tet_result( TET_FAIL );
1949     }
1950   }
1951
1952   for ( PanGestureDetector::AngleContainer::const_iterator iter = angles.begin(), endIter = angles.end(); iter != endIter; ++iter )
1953   {
1954     if ( iter->first == PanGestureDetector::DIRECTION_RIGHT )
1955     {
1956       tet_result( TET_PASS );
1957       break;
1958     }
1959
1960     if ( iter == endIter )
1961     {
1962       tet_printf("%s, angle not added\n", TEST_LOCATION );
1963       tet_result( TET_FAIL );
1964     }
1965   }
1966
1967   // Remove something not in the container.
1968   detector.RemoveDirection( PanGestureDetector::DIRECTION_UP );
1969   DALI_TEST_EQUALS( angles.size(), static_cast<AngleSizeType>(2), TEST_LOCATION );
1970
1971   detector.RemoveDirection( PanGestureDetector::DIRECTION_RIGHT );
1972   DALI_TEST_EQUALS( angles.size(), static_cast<AngleSizeType>(0), TEST_LOCATION );
1973   END_TEST;
1974 }
1975
1976 int UtcDaliPanGestureDirectionProcessing(void)
1977 {
1978   TestApplication application;
1979
1980   Actor parent = Actor::New();
1981   parent.SetSize(100.0f, 100.0f);
1982   parent.SetAnchorPoint(AnchorPoint::TOP_LEFT);
1983   Stage::GetCurrent().Add(parent);
1984
1985   Actor child = Actor::New();
1986   child.SetSize(100.0f, 100.0f);
1987   child.SetAnchorPoint(AnchorPoint::TOP_LEFT);
1988   parent.Add(child);
1989
1990   // Render and notify
1991   application.SendNotification();
1992   application.Render();
1993
1994   // Parent detector only requires vertical panning
1995   PanGestureDetector parentDetector = PanGestureDetector::New();
1996   parentDetector.Attach( parent );
1997   parentDetector.AddDirection( PanGestureDetector::DIRECTION_VERTICAL, Degree( 30.0f ) );
1998   SignalData parentData;
1999   GestureReceivedFunctor parentFunctor(parentData);
2000   parentDetector.DetectedSignal().Connect(&application, parentFunctor);
2001
2002   // Child detector only requires horizontal panning
2003   PanGestureDetector childDetector = PanGestureDetector::New();
2004   childDetector.Attach( child );
2005   childDetector.AddDirection( PanGestureDetector::DIRECTION_HORIZONTAL, Degree( 30.0f ) );
2006   SignalData childData;
2007   GestureReceivedFunctor childFunctor(childData);
2008   childDetector.DetectedSignal().Connect(&application, childFunctor);
2009
2010   // Generate an Up pan gesture, only parent should receive it.
2011   application.ProcessEvent( GeneratePan( Gesture::Possible, Vector2(20.0f, 20.0f), Vector2(20.0f, 20.0f), 10 ) );
2012   application.ProcessEvent( GeneratePan( Gesture::Started,  Vector2(20.0f, 20.0f), Vector2(20.0f, 10.0f), 10 ) );
2013   DALI_TEST_EQUALS( true,  parentData.functorCalled, TEST_LOCATION );
2014   DALI_TEST_EQUALS( false, childData.functorCalled,  TEST_LOCATION );
2015   application.ProcessEvent( GeneratePan( Gesture::Finished,  Vector2(20.0f, 30.0f), Vector2(20.0f, 20.0f), 10 ) );
2016   parentData.Reset();
2017   childData.Reset();
2018
2019   // Generate a Right pan gesture, only child should receive it.
2020   application.ProcessEvent( GeneratePan( Gesture::Possible, Vector2(20.0f, 20.0f), Vector2(20.0f, 20.0f), 10 ) );
2021   application.ProcessEvent( GeneratePan( Gesture::Started,  Vector2(20.0f, 20.0f), Vector2(30.0f, 20.0f), 10 ) );
2022   DALI_TEST_EQUALS( false, parentData.functorCalled, TEST_LOCATION );
2023   DALI_TEST_EQUALS( true,  childData.functorCalled,  TEST_LOCATION );
2024   application.ProcessEvent( GeneratePan( Gesture::Finished,  Vector2(20.0f, 30.0f), Vector2(20.0f, 20.0f), 10 ) );
2025   parentData.Reset();
2026   childData.Reset();
2027
2028   // Generate a Down pan gesture, only parent should receive it.
2029   application.ProcessEvent( GeneratePan( Gesture::Possible, Vector2(20.0f, 20.0f), Vector2(20.0f, 20.0f), 10 ) );
2030   application.ProcessEvent( GeneratePan( Gesture::Started,  Vector2(20.0f, 20.0f), Vector2(20.0f, 30.0f), 10 ) );
2031   DALI_TEST_EQUALS( true,  parentData.functorCalled, TEST_LOCATION );
2032   DALI_TEST_EQUALS( false, childData.functorCalled,  TEST_LOCATION );
2033   application.ProcessEvent( GeneratePan( Gesture::Finished,  Vector2(20.0f, 30.0f), Vector2(20.0f, 20.0f), 10 ) );
2034   parentData.Reset();
2035   childData.Reset();
2036
2037   // Generate a Left pan gesture, only child should receive it.
2038   application.ProcessEvent( GeneratePan( Gesture::Possible, Vector2(20.0f, 20.0f), Vector2(20.0f, 20.0f), 10 ) );
2039   application.ProcessEvent( GeneratePan( Gesture::Started,  Vector2(20.0f, 20.0f), Vector2(10.0f, 20.0f), 10 ) );
2040   DALI_TEST_EQUALS( false, parentData.functorCalled, TEST_LOCATION );
2041   DALI_TEST_EQUALS( true,  childData.functorCalled,  TEST_LOCATION );
2042   application.ProcessEvent( GeneratePan( Gesture::Finished,  Vector2(20.0f, 30.0f), Vector2(20.0f, 20.0f), 10 ) );
2043   parentData.Reset();
2044   childData.Reset();
2045
2046   // Generate a pan at -45 degrees, no one should receive it.
2047   application.ProcessEvent( GeneratePan( Gesture::Possible, Vector2(20.0f, 20.0f), Vector2(20.0f, 20.0f), 10 ) );
2048   application.ProcessEvent( GeneratePan( Gesture::Started,  Vector2(20.0f, 20.0f), Vector2(10.0f, 30.0f), 10 ) );
2049   DALI_TEST_EQUALS( false, parentData.functorCalled, TEST_LOCATION );
2050   DALI_TEST_EQUALS( false, childData.functorCalled,  TEST_LOCATION );
2051   application.ProcessEvent( GeneratePan( Gesture::Finished,  Vector2(20.0f, 30.0f), Vector2(20.0f, 20.0f), 10 ) );
2052   parentData.Reset();
2053   childData.Reset();
2054
2055   // Generate a pan at 45 degrees, no one should receive it.
2056   application.ProcessEvent( GeneratePan( Gesture::Possible, Vector2(20.0f, 20.0f), Vector2(20.0f, 20.0f), 10 ) );
2057   application.ProcessEvent( GeneratePan( Gesture::Started,  Vector2(20.0f, 20.0f), Vector2(30.0f, 30.0f), 10 ) );
2058   DALI_TEST_EQUALS( false, parentData.functorCalled, TEST_LOCATION );
2059   DALI_TEST_EQUALS( false, childData.functorCalled,  TEST_LOCATION );
2060   application.ProcessEvent( GeneratePan( Gesture::Finished,  Vector2(20.0f, 30.0f), Vector2(20.0f, 20.0f), 10 ) );
2061   parentData.Reset();
2062   childData.Reset();
2063
2064   // Generate a pan at 135 degrees, no one should receive it.
2065   application.ProcessEvent( GeneratePan( Gesture::Possible, Vector2(20.0f, 20.0f), Vector2(20.0f, 20.0f), 10 ) );
2066   application.ProcessEvent( GeneratePan( Gesture::Started,  Vector2(20.0f, 20.0f), Vector2(10.0f, 30.0f), 10 ) );
2067   DALI_TEST_EQUALS( false, parentData.functorCalled, TEST_LOCATION );
2068   DALI_TEST_EQUALS( false, childData.functorCalled,  TEST_LOCATION );
2069   application.ProcessEvent( GeneratePan( Gesture::Finished,  Vector2(20.0f, 30.0f), Vector2(20.0f, 20.0f), 10 ) );
2070   parentData.Reset();
2071   childData.Reset();
2072
2073   // Generate a pan at -135 degrees, no one should receive it.
2074   application.ProcessEvent( GeneratePan( Gesture::Possible, Vector2(20.0f, 20.0f), Vector2(20.0f, 20.0f), 10 ) );
2075   application.ProcessEvent( GeneratePan( Gesture::Started,  Vector2(20.0f, 20.0f), Vector2(10.0f, 10.0f), 10 ) );
2076   DALI_TEST_EQUALS( false, parentData.functorCalled, TEST_LOCATION );
2077   DALI_TEST_EQUALS( false, childData.functorCalled,  TEST_LOCATION );
2078   application.ProcessEvent( GeneratePan( Gesture::Finished,  Vector2(20.0f, 30.0f), Vector2(20.0f, 20.0f), 10 ) );
2079   parentData.Reset();
2080   childData.Reset();
2081   END_TEST;
2082 }
2083
2084 int UtcDaliPanGestureNoPredictionNoSmoothing(void)
2085 {
2086   TestApplication application;
2087   Integration::SetPanGesturePredictionMode(0);
2088   Integration::SetPanGestureSmoothingMode(0);
2089
2090   Actor actor = Actor::New();
2091   actor.SetSize(100.0f, 100.0f);
2092   actor.SetAnchorPoint(AnchorPoint::TOP_LEFT);
2093   Stage::GetCurrent().Add(actor);
2094
2095   // Add a pan detector
2096   PanGestureDetector detector = PanGestureDetector::New();
2097   detector.Attach( actor );
2098   SignalData data;
2099   GestureReceivedFunctor functor( data );
2100   detector.DetectedSignal().Connect( &application, functor );
2101
2102   Property::Index property = actor.RegisterProperty( "Dummy Property", Vector3::ZERO );
2103
2104   ConstraintData constraintData;
2105   Constraint constraint = Constraint::New<Vector3>( actor, property, PanConstraint( constraintData ) );
2106   constraint.AddSource( Source( detector, PanGestureDetector::Property::SCREEN_POSITION ) );
2107   constraint.AddSource( Source( detector, PanGestureDetector::Property::SCREEN_DISPLACEMENT ) );
2108   constraint.AddSource( Source( detector, PanGestureDetector::Property::SCREEN_VELOCITY ) );
2109   constraint.AddSource( Source( detector, PanGestureDetector::Property::LOCAL_POSITION ) );
2110   constraint.AddSource( Source( detector, PanGestureDetector::Property::LOCAL_DISPLACEMENT ) );
2111   constraint.AddSource( Source( detector, PanGestureDetector::Property::LOCAL_VELOCITY ) );
2112   constraint.Apply();
2113
2114   // Render and notify
2115   application.SendNotification();
2116   application.Render();
2117
2118   Vector2 direction(Vector2::XAXIS * -5.0f);
2119   Vector2 startPosition( 1.0f, 1.0f );
2120   PerformSwipeGestureSwipe(application, startPosition, direction, PAN_GESTURE_UPDATE_COUNT, true);
2121   DALI_TEST_EQUALS( true,  data.functorCalled, TEST_LOCATION );
2122   DALI_TEST_EQUALS( constraintData.called, true, TEST_LOCATION );
2123   DALI_TEST_EQUALS( constraintData.screenPosition, startPosition + (direction * PAN_GESTURE_UPDATE_COUNT), 0.1f, TEST_LOCATION );
2124   DALI_TEST_EQUALS( constraintData.localPosition,  startPosition + (direction * PAN_GESTURE_UPDATE_COUNT), 0.1f, TEST_LOCATION );
2125
2126   constraintData.Reset();
2127   END_TEST;
2128 }
2129
2130 int UtcDaliPanGestureNoPredictionSmoothing(void)
2131 {
2132   TestApplication application;
2133   Integration::SetPanGesturePredictionMode(0);
2134   Integration::SetPanGestureSmoothingMode(1);
2135
2136   Actor actor = Actor::New();
2137   actor.SetSize(100.0f, 100.0f);
2138   actor.SetAnchorPoint(AnchorPoint::TOP_LEFT);
2139   Stage::GetCurrent().Add(actor);
2140
2141   // Add a pan detector
2142   PanGestureDetector detector = PanGestureDetector::New();
2143   detector.Attach( actor );
2144   SignalData data;
2145   GestureReceivedFunctor functor( data );
2146   detector.DetectedSignal().Connect( &application, functor );
2147
2148   Property::Index property = actor.RegisterProperty( "Dummy Property", Vector3::ZERO );
2149
2150   ConstraintData constraintData;
2151   Constraint constraint = Constraint::New<Vector3>( actor, property, PanConstraint( constraintData ) );
2152   constraint.AddSource( Source( detector, PanGestureDetector::Property::SCREEN_POSITION ) );
2153   constraint.AddSource( Source( detector, PanGestureDetector::Property::SCREEN_DISPLACEMENT ) );
2154   constraint.AddSource( Source( detector, PanGestureDetector::Property::SCREEN_VELOCITY ) );
2155   constraint.AddSource( Source( detector, PanGestureDetector::Property::LOCAL_POSITION ) );
2156   constraint.AddSource( Source( detector, PanGestureDetector::Property::LOCAL_DISPLACEMENT ) );
2157   constraint.AddSource( Source( detector, PanGestureDetector::Property::LOCAL_VELOCITY ) );
2158   constraint.Apply();
2159
2160   // Render and notify
2161   application.SendNotification();
2162   application.Render();
2163
2164   Vector2 direction(Vector2::XAXIS * -5.0f);
2165   Vector2 previousPosition( 20.0f, 20.0f );
2166   Vector2 currentPosition( 20.0f, 10.0f );
2167   PerformSwipeGestureSwipe(application, Vector2(1.0f, 1.0f), direction, PAN_GESTURE_UPDATE_COUNT, true);
2168   DALI_TEST_EQUALS( true,  data.functorCalled, TEST_LOCATION );
2169   DALI_TEST_EQUALS( constraintData.called, true, TEST_LOCATION );
2170   DALI_TEST_EQUALS( constraintData.screenPosition, Vector2(1.0f, 1.0f) + (direction * PAN_GESTURE_UPDATE_COUNT), 0.1f, TEST_LOCATION );
2171   DALI_TEST_EQUALS( constraintData.localPosition,  Vector2(1.0f, 1.0f) + (direction * PAN_GESTURE_UPDATE_COUNT), 0.1f, TEST_LOCATION );
2172
2173   constraintData.Reset();
2174   END_TEST;
2175 }
2176
2177 int UtcDaliPanGesturePredictionNoSmoothing(void)
2178 {
2179   TestApplication application;
2180   Integration::SetPanGesturePredictionMode(1);
2181   Integration::SetPanGestureSmoothingMode(0);
2182
2183   Actor actor = Actor::New();
2184   actor.SetSize(100.0f, 100.0f);
2185   actor.SetAnchorPoint(AnchorPoint::TOP_LEFT);
2186   Stage::GetCurrent().Add(actor);
2187
2188   // Add a pan detector
2189   PanGestureDetector detector = PanGestureDetector::New();
2190   detector.Attach( actor );
2191   SignalData data;
2192   GestureReceivedFunctor functor( data );
2193   detector.DetectedSignal().Connect( &application, functor );
2194
2195   Property::Index property = actor.RegisterProperty( "Dummy Property", Vector3::ZERO );
2196
2197   ConstraintData constraintData;
2198   Constraint constraint = Constraint::New<Vector3>( actor, property, PanConstraint( constraintData ) );
2199   constraint.AddSource( Source( detector, PanGestureDetector::Property::SCREEN_POSITION ) );
2200   constraint.AddSource( Source( detector, PanGestureDetector::Property::SCREEN_DISPLACEMENT ) );
2201   constraint.AddSource( Source( detector, PanGestureDetector::Property::SCREEN_VELOCITY ) );
2202   constraint.AddSource( Source( detector, PanGestureDetector::Property::LOCAL_POSITION ) );
2203   constraint.AddSource( Source( detector, PanGestureDetector::Property::LOCAL_DISPLACEMENT ) );
2204   constraint.AddSource( Source( detector, PanGestureDetector::Property::LOCAL_VELOCITY ) );
2205   constraint.Apply();
2206
2207   // Render and notify
2208   application.SendNotification();
2209   application.Render();
2210
2211   Vector2 direction(Vector2::XAXIS * -1.0f);
2212   Vector2 previousPosition( 20.0f, 20.0f );
2213   Vector2 currentPosition( 20.0f, 10.0f );
2214   PerformSwipeGestureSwipe(application, Vector2(1.0f, 1.0f), direction, PAN_GESTURE_UPDATE_COUNT, true);
2215   DALI_TEST_EQUALS( true,  data.functorCalled, TEST_LOCATION );
2216   DALI_TEST_EQUALS( constraintData.called, true, TEST_LOCATION );
2217   DALI_TEST_EQUALS( constraintData.screenPosition, Vector2(1.0f, 1.0f) + (direction * PAN_GESTURE_UPDATE_COUNT), 10.0f, TEST_LOCATION );
2218   DALI_TEST_EQUALS( constraintData.localPosition,  Vector2(1.0f, 1.0f) + (direction * PAN_GESTURE_UPDATE_COUNT), 10.0f, TEST_LOCATION );
2219
2220   constraintData.Reset();
2221   END_TEST;
2222 }
2223
2224 int UtcDaliPanGesturePredictionSmoothing(void)
2225 {
2226   TestApplication application;
2227   Integration::SetPanGesturePredictionMode(1);
2228   Integration::SetPanGestureSmoothingMode(1);
2229
2230   Actor actor = Actor::New();
2231   actor.SetSize(100.0f, 100.0f);
2232   actor.SetAnchorPoint(AnchorPoint::TOP_LEFT);
2233   Stage::GetCurrent().Add(actor);
2234
2235   // Add a pan detector
2236   PanGestureDetector detector = PanGestureDetector::New();
2237   detector.Attach( actor );
2238   SignalData data;
2239   GestureReceivedFunctor functor( data );
2240   detector.DetectedSignal().Connect( &application, functor );
2241
2242   Property::Index property = actor.RegisterProperty( "Dummy Property", Vector3::ZERO );
2243
2244   ConstraintData constraintData;
2245   Constraint constraint = Constraint::New<Vector3>( actor, property, PanConstraint( constraintData ) );
2246   constraint.AddSource( Source( detector, PanGestureDetector::Property::SCREEN_POSITION ) );
2247   constraint.AddSource( Source( detector, PanGestureDetector::Property::SCREEN_DISPLACEMENT ) );
2248   constraint.AddSource( Source( detector, PanGestureDetector::Property::SCREEN_VELOCITY ) );
2249   constraint.AddSource( Source( detector, PanGestureDetector::Property::LOCAL_POSITION ) );
2250   constraint.AddSource( Source( detector, PanGestureDetector::Property::LOCAL_DISPLACEMENT ) );
2251   constraint.AddSource( Source( detector, PanGestureDetector::Property::LOCAL_VELOCITY ) );
2252   constraint.Apply();
2253
2254   // Render and notify
2255   application.SendNotification();
2256   application.Render();
2257
2258   Vector2 direction(Vector2::XAXIS * -1.0f);
2259   Vector2 previousPosition( 20.0f, 20.0f );
2260   Vector2 currentPosition( 20.0f, 10.0f );
2261   PerformSwipeGestureSwipe(application, Vector2(1.0f, 1.0f), direction, PAN_GESTURE_UPDATE_COUNT, true);
2262   DALI_TEST_EQUALS( true,  data.functorCalled, TEST_LOCATION );
2263   DALI_TEST_EQUALS( constraintData.called, true, TEST_LOCATION );
2264   DALI_TEST_EQUALS( constraintData.screenPosition, Vector2(1.0f, 1.0f) + (direction * PAN_GESTURE_UPDATE_COUNT), 10.0f, TEST_LOCATION );
2265   DALI_TEST_EQUALS( constraintData.localPosition,  Vector2(1.0f, 1.0f) + (direction * PAN_GESTURE_UPDATE_COUNT), 10.0f, TEST_LOCATION );
2266
2267   constraintData.Reset();
2268   END_TEST;
2269 }
2270
2271 int UtcDaliPanGestureSetProperties(void)
2272 {
2273   TestApplication application;
2274   TestRenderController& renderController( application.GetRenderController() );
2275   Integration::SetPanGesturePredictionMode(0);
2276   Integration::SetPanGestureSmoothingMode(0);
2277
2278   Actor actor = Actor::New();
2279   actor.SetSize(100.0f, 100.0f);
2280   actor.SetAnchorPoint(AnchorPoint::TOP_LEFT);
2281   Stage::GetCurrent().Add(actor);
2282
2283   // Add a pan detector
2284   PanGestureDetector detector = PanGestureDetector::New();
2285   detector.Attach( actor );
2286   SignalData data;
2287   GestureReceivedFunctor functor( data );
2288   detector.DetectedSignal().Connect( &application, functor );
2289
2290   Property::Index property = actor.RegisterProperty( "Dummy Property", Vector3::ZERO );
2291
2292   ConstraintData constraintData;
2293   Constraint constraint = Constraint::New<Vector3>( actor, property, PanConstraint( constraintData ) );
2294   constraint.AddSource( Source( detector, PanGestureDetector::Property::SCREEN_POSITION ) );
2295   constraint.AddSource( Source( detector, PanGestureDetector::Property::SCREEN_DISPLACEMENT ) );
2296   constraint.AddSource( Source( detector, PanGestureDetector::Property::SCREEN_VELOCITY ) );
2297   constraint.AddSource( Source( detector, PanGestureDetector::Property::LOCAL_POSITION ) );
2298   constraint.AddSource( Source( detector, PanGestureDetector::Property::LOCAL_DISPLACEMENT ) );
2299   constraint.AddSource( Source( detector, PanGestureDetector::Property::LOCAL_VELOCITY ) );
2300   constraint.Apply();
2301
2302   // Render and notify
2303   application.SendNotification();
2304   application.Render();
2305
2306   renderController.Initialize();
2307   DALI_TEST_EQUALS( renderController.WasCalled( TestRenderController::RequestUpdateFunc ), false, TEST_LOCATION );
2308
2309   Vector2 screenPosition( 20.0f, 20.0f );
2310   Vector2 screenDisplacement( 1.0f, 1.0f );
2311   Vector2 screenVelocity( 1.3f, 4.0f );
2312   Vector2 localPosition( 21.0f, 21.0f );
2313   Vector2 localDisplacement( 0.5f, 0.5f );
2314   Vector2 localVelocity( 1.5f, 2.5f );
2315
2316   PanGestureDetector::SetPanGestureProperties( GeneratePan( 1u, Gesture::Started, screenPosition, localPosition, screenDisplacement, localDisplacement, screenVelocity, localVelocity ) );
2317   DALI_TEST_EQUALS( renderController.WasCalled( TestRenderController::RequestUpdateFunc ), true, TEST_LOCATION );
2318
2319   // Render and notify
2320   application.SendNotification();
2321   application.Render();
2322
2323   DALI_TEST_EQUALS( constraintData.called, true, TEST_LOCATION );
2324   DALI_TEST_EQUALS( constraintData.screenPosition,     screenPosition,     TEST_LOCATION );
2325   DALI_TEST_EQUALS( constraintData.localPosition,      localPosition,      TEST_LOCATION );
2326   DALI_TEST_EQUALS( constraintData.screenDisplacement, screenDisplacement, TEST_LOCATION );
2327   DALI_TEST_EQUALS( constraintData.localDisplacement,  localDisplacement,  TEST_LOCATION );
2328   DALI_TEST_EQUALS( constraintData.screenVelocity,     screenVelocity,     TEST_LOCATION );
2329   DALI_TEST_EQUALS( constraintData.localVelocity,      localVelocity,      TEST_LOCATION );
2330   constraintData.Reset();
2331   END_TEST;
2332 }
2333
2334 int UtcDaliPanGestureSetPropertiesAlreadyPanning(void)
2335 {
2336   TestApplication application;
2337   Integration::SetPanGesturePredictionMode(0);
2338
2339   Actor actor = Actor::New();
2340   actor.SetSize(100.0f, 100.0f);
2341   actor.SetAnchorPoint(AnchorPoint::TOP_LEFT);
2342   Stage::GetCurrent().Add(actor);
2343
2344   // Add a pan detector
2345   PanGestureDetector detector = PanGestureDetector::New();
2346   detector.Attach( actor );
2347   SignalData data;
2348   GestureReceivedFunctor functor( data );
2349   detector.DetectedSignal().Connect( &application, functor );
2350
2351   Property::Index property = actor.RegisterProperty( "Dummy Property", Vector3::ZERO );
2352
2353   ConstraintData constraintData;
2354   Constraint constraint = Constraint::New<Vector3>( actor, property, PanConstraint( constraintData ) );
2355   constraint.AddSource( Source( detector, PanGestureDetector::Property::SCREEN_POSITION ) );
2356   constraint.AddSource( Source( detector, PanGestureDetector::Property::SCREEN_DISPLACEMENT ) );
2357   constraint.AddSource( Source( detector, PanGestureDetector::Property::SCREEN_VELOCITY ) );
2358   constraint.AddSource( Source( detector, PanGestureDetector::Property::LOCAL_POSITION ) );
2359   constraint.AddSource( Source( detector, PanGestureDetector::Property::LOCAL_DISPLACEMENT ) );
2360   constraint.AddSource( Source( detector, PanGestureDetector::Property::LOCAL_VELOCITY ) );
2361   constraint.Apply();
2362
2363   // Render and notify
2364   application.SendNotification();
2365   application.Render();
2366
2367   Vector2 previousPosition( 20.0f, 20.0f );
2368   Vector2 currentPosition( 20.0f, 10.0f );
2369   application.ProcessEvent( GeneratePan( Gesture::Possible, previousPosition, previousPosition, 10 ) );
2370   application.ProcessEvent( GeneratePan( Gesture::Started,  previousPosition, currentPosition, 10 ) );
2371   DALI_TEST_EQUALS( true,  data.functorCalled, TEST_LOCATION );
2372
2373   Vector2 screenPosition( 100.0f, 20.0f );
2374   Vector2 localPosition( 110.0f, 110.0f );
2375
2376   PanGestureDetector::SetPanGestureProperties( GeneratePan( 1u, Gesture::Started, screenPosition, localPosition ) );
2377
2378   // Render and notify
2379   application.SendNotification();
2380   application.Render();
2381
2382   DALI_TEST_EQUALS( constraintData.called, true, TEST_LOCATION );
2383   DALI_TEST_EQUALS( constraintData.screenPosition, currentPosition, 0.1, TEST_LOCATION );
2384   DALI_TEST_EQUALS( constraintData.localPosition,  currentPosition, 0.1f, TEST_LOCATION );
2385   constraintData.Reset();
2386   END_TEST;
2387 }
2388
2389 int UtcDaliPanGesturePropertyIndices(void)
2390 {
2391   TestApplication application;
2392   PanGestureDetector detector = PanGestureDetector::New();
2393
2394   Property::IndexContainer indices;
2395   detector.GetPropertyIndices( indices );
2396   DALI_TEST_CHECK( ! indices.empty() );
2397   DALI_TEST_EQUALS( indices.size(), detector.GetPropertyCount(), TEST_LOCATION );
2398   END_TEST;
2399 }
2400
2401 int UtcDaliPanGestureLayerConsumesTouch(void)
2402 {
2403   TestApplication application;
2404
2405   Actor actor = Actor::New();
2406   actor.SetSize(100.0f, 100.0f);
2407   actor.SetAnchorPoint(AnchorPoint::TOP_LEFT);
2408   Stage::GetCurrent().Add(actor);
2409
2410   // Add a pan detector
2411   PanGestureDetector detector = PanGestureDetector::New();
2412   detector.Attach( actor );
2413   SignalData data;
2414   GestureReceivedFunctor functor( data );
2415   detector.DetectedSignal().Connect( &application, functor );
2416
2417   // Add a layer to overlap the actor
2418   Layer layer = Layer::New();
2419   layer.SetSize(100.0f, 100.0f);
2420   layer.SetAnchorPoint(AnchorPoint::TOP_LEFT);
2421   Stage::GetCurrent().Add( layer );
2422   layer.RaiseToTop();
2423
2424   // Render and notify
2425   application.SendNotification();
2426   application.Render();
2427
2428   // Emit signals, should receive
2429   application.ProcessEvent(GeneratePan(Gesture::Possible, Vector2(10.0f, 20.0f), Vector2(20.0f, 20.0f), 10));
2430   application.ProcessEvent(GeneratePan(Gesture::Started, Vector2(10.0f, 20.0f), Vector2(20.0f, 20.0f), 10));
2431   application.ProcessEvent(GeneratePan(Gesture::Finished, Vector2(10.0f, 20.0f), Vector2(20.0f, 20.0f), 10));
2432   DALI_TEST_EQUALS(true, data.functorCalled, TEST_LOCATION);
2433   data.Reset();
2434
2435   // Set layer to consume all touch
2436   layer.SetTouchConsumed( true );
2437
2438   // Render and notify
2439   application.SendNotification();
2440   application.Render();
2441
2442   // Emit the same signals again, should not receive
2443   application.ProcessEvent(GeneratePan(Gesture::Possible, Vector2(10.0f, 20.0f), Vector2(20.0f, 20.0f), 10));
2444   application.ProcessEvent(GeneratePan(Gesture::Started, Vector2(10.0f, 20.0f), Vector2(20.0f, 20.0f), 10));
2445   application.ProcessEvent(GeneratePan(Gesture::Finished, Vector2(10.0f, 20.0f), Vector2(20.0f, 20.0f), 10));
2446   DALI_TEST_EQUALS(false, data.functorCalled, TEST_LOCATION);
2447   data.Reset();
2448
2449   END_TEST;
2450 }
2451
2452 int UtcDaliPanGestureNoTimeDiff(void)
2453 {
2454   TestApplication application;
2455
2456   Actor actor = Actor::New();
2457   actor.SetSize(100.0f, 100.0f);
2458   actor.SetAnchorPoint(AnchorPoint::TOP_LEFT);
2459   Stage::GetCurrent().Add(actor);
2460
2461   // Add a pan detector
2462   PanGestureDetector detector = PanGestureDetector::New();
2463   detector.Attach( actor );
2464   SignalData data;
2465   GestureReceivedFunctor functor( data );
2466   detector.DetectedSignal().Connect( &application, functor );
2467
2468   // Render and notify
2469   application.SendNotification();
2470   application.Render();
2471
2472   // Emit signals, should receive
2473   application.ProcessEvent(GeneratePan(Gesture::Possible, Vector2(10.0f, 20.0f), Vector2(20.0f, 20.0f), 0));
2474   application.ProcessEvent(GeneratePan(Gesture::Started, Vector2(10.0f, 20.0f), Vector2(20.0f, 20.0f), 0));
2475   application.ProcessEvent(GeneratePan(Gesture::Finished, Vector2(10.0f, 20.0f), Vector2(20.0f, 20.0f), 0));
2476   DALI_TEST_EQUALS(true, data.functorCalled, TEST_LOCATION);
2477   DALI_TEST_CHECK( !std::isinf( data.receivedGesture.velocity.x ) );
2478   DALI_TEST_CHECK( !std::isinf( data.receivedGesture.velocity.y ) );
2479   DALI_TEST_CHECK( !std::isinf( data.receivedGesture.screenVelocity.x ) );
2480   DALI_TEST_CHECK( !std::isinf( data.receivedGesture.screenVelocity.y ) );
2481   data.Reset();
2482
2483   data.Reset();
2484
2485   END_TEST;
2486 }