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