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