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