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