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