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