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