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