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