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