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