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