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