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