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