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