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