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