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