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