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