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