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