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