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