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