Renamed TouchSignal to TouchedSignal
[platform/core/uifw/dali-core.git] / automated-tests / src / dali / utc-Dali-PinchGestureDetector.cpp
1 /*
2  * Copyright (c) 2020 Samsung Electronics Co., Ltd.
3  *
4  * Licensed under the Apache License, Version 2.0 (the "License");
5  * you may not use this file except in compliance with the License.
6  * You may obtain a copy of the License at
7  *
8  * http://www.apache.org/licenses/LICENSE-2.0
9  *
10  * Unless required by applicable law or agreed to in writing, software
11  * distributed under the License is distributed on an "AS IS" BASIS,
12  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13  * See the License for the specific language governing permissions and
14  * limitations under the License.
15  *
16  */
17
18 #include <iostream>
19
20 #include <stdlib.h>
21 #include <dali/public-api/dali-core.h>
22 #include <dali/integration-api/events/touch-event-integ.h>
23 #include <dali/integration-api/render-task-list-integ.h>
24 #include <dali-test-suite-utils.h>
25 #include <test-touch-event-utils.h>
26
27 using namespace Dali;
28
29 void utc_dali_pinch_gesture_detector_startup(void)
30 {
31   test_return_value = TET_UNDEF;
32 }
33
34 void utc_dali_pinch_gesture_detector_cleanup(void)
35 {
36   test_return_value = TET_PASS;
37 }
38
39 ///////////////////////////////////////////////////////////////////////////////
40 namespace
41 {
42
43 // Stores data that is populated in the callback and will be read by the TET cases
44 struct SignalData
45 {
46   SignalData()
47   : functorCalled(false),
48     voidFunctorCalled(false),
49     receivedGesture()
50   {}
51
52   void Reset()
53   {
54     functorCalled = false;
55     voidFunctorCalled = false;
56
57     receivedGesture.Reset();
58
59     pinchedActor.Reset();
60   }
61
62   bool functorCalled;
63   bool voidFunctorCalled;
64   PinchGesture receivedGesture;
65   Actor pinchedActor;
66 };
67
68 // Functor that sets the data when called
69 struct GestureReceivedFunctor
70 {
71   GestureReceivedFunctor(SignalData& data) : signalData(data) { }
72
73   void operator()(Actor actor, const PinchGesture& pinch)
74   {
75     signalData.functorCalled = true;
76     signalData.receivedGesture = pinch;
77     signalData.pinchedActor = actor;
78   }
79
80   void operator()()
81   {
82     signalData.voidFunctorCalled = true;
83   }
84
85   SignalData& signalData;
86 };
87
88 // Functor that removes the gestured actor from stage
89 struct UnstageActorFunctor : public GestureReceivedFunctor
90 {
91   UnstageActorFunctor( SignalData& data, Gesture::State& stateToUnstage, Integration::Scene scene )
92   : GestureReceivedFunctor( data ),
93     stateToUnstage( stateToUnstage ),
94     scene( scene )
95   {
96   }
97
98   void operator()( Actor actor, const PinchGesture& pinch )
99   {
100     GestureReceivedFunctor::operator()( actor, pinch );
101
102     if ( pinch.GetState() == stateToUnstage )
103     {
104       scene.Remove( actor );
105     }
106   }
107
108   Gesture::State& stateToUnstage;
109   Integration::Scene scene;
110 };
111
112 } // anon namespace
113
114 ///////////////////////////////////////////////////////////////////////////////
115
116 int UtcDaliPinchGestureDetectorConstructor(void)
117 {
118   TestApplication application;
119
120   PinchGestureDetector detector;
121   DALI_TEST_CHECK(!detector);
122   END_TEST;
123 }
124
125 int UtcDaliPinchGestureDetectorCopyConstructorP(void)
126 {
127   TestApplication application;
128
129   PinchGestureDetector detector = PinchGestureDetector::New();;
130
131   PinchGestureDetector copy( detector );
132   DALI_TEST_CHECK( detector );
133   END_TEST;
134 }
135
136 int UtcDaliPinchGestureDetectorAssignmentOperatorP(void)
137 {
138   TestApplication application;
139
140   PinchGestureDetector detector = PinchGestureDetector::New();;
141
142   PinchGestureDetector assign;
143   assign = detector;
144   DALI_TEST_CHECK( detector );
145
146   DALI_TEST_CHECK( detector == assign );
147   END_TEST;
148 }
149
150 int UtcDaliPinchGestureDetectorNew(void)
151 {
152   TestApplication application;
153
154   PinchGestureDetector detector = PinchGestureDetector::New();
155
156   DALI_TEST_CHECK(detector);
157
158   // Attach an actor and emit a touch event on the actor to ensure complete line coverage
159   Actor actor = Actor::New();
160   actor.SetProperty( Actor::Property::SIZE, Vector2( 100.0f, 100.0f ) );
161   actor.SetProperty( Actor::Property::ANCHOR_POINT,AnchorPoint::TOP_LEFT);
162   application.GetScene().Add(actor);
163
164   // Render and notify
165   application.SendNotification();
166   application.Render();
167
168   detector.Attach(actor);
169
170   Integration::TouchEvent touchEvent(1);
171   Integration::Point point;
172   point.SetDeviceId( 1 );
173   point.SetState( PointState::DOWN );
174   point.SetScreenPosition( Vector2( 20.0f, 20.0f ) );
175   touchEvent.AddPoint(point);
176   application.ProcessEvent(touchEvent);
177
178   Integration::Point point2;
179   point.SetDeviceId( 1 );
180   point.SetState( PointState::DOWN );
181   point.SetScreenPosition( Vector2( 20.0f, 20.0f ) );
182   touchEvent.AddPoint(point2);
183   application.ProcessEvent(touchEvent);
184   END_TEST;
185 }
186
187 int UtcDaliPinchGestureDetectorDownCast(void)
188 {
189   TestApplication application;
190   tet_infoline("Testing Dali::PinchGestureDetector::DownCast()");
191
192   PinchGestureDetector detector = PinchGestureDetector::New();
193
194   BaseHandle object(detector);
195
196   PinchGestureDetector detector2 = PinchGestureDetector::DownCast(object);
197   DALI_TEST_CHECK(detector2);
198
199   PinchGestureDetector detector3 = DownCast< PinchGestureDetector >(object);
200   DALI_TEST_CHECK(detector3);
201
202   BaseHandle unInitializedObject;
203   PinchGestureDetector detector4 = PinchGestureDetector::DownCast(unInitializedObject);
204   DALI_TEST_CHECK(!detector4);
205
206   PinchGestureDetector detector5 = DownCast< PinchGestureDetector >(unInitializedObject);
207   DALI_TEST_CHECK(!detector5);
208
209   GestureDetector detector6 = PinchGestureDetector::New();
210   PinchGestureDetector detector7 = PinchGestureDetector::DownCast(detector6);
211   DALI_TEST_CHECK(detector7);
212   END_TEST;
213 }
214
215 // Negative test case for a method
216 int UtcDaliPinchGestureSignalReceptionNegative(void)
217 {
218   TestApplication application;
219
220   Actor actor = Actor::New();
221   actor.SetProperty( Actor::Property::SIZE, Vector2( 100.0f, 100.0f ) );
222   actor.SetProperty( Actor::Property::ANCHOR_POINT,AnchorPoint::TOP_LEFT);
223   application.GetScene().Add(actor);
224
225   // Render and notify
226   application.SendNotification();
227   application.Render();
228
229   SignalData data;
230   GestureReceivedFunctor functor(data);
231
232   PinchGestureDetector detector = PinchGestureDetector::New();
233   detector.Attach(actor);
234   detector.DetectedSignal().Connect(&application, functor);
235
236   // Do a pinch outside actor's area
237   TestStartPinch( application,  Vector2( 112.0f, 62.0f ), Vector2( 112.0f, 162.0f ),
238                                 Vector2( 112.0f, 100.0f ), Vector2( 112.0f, 124.0f ), 100 );
239
240   DALI_TEST_EQUALS(false, data.functorCalled, TEST_LOCATION);
241
242   // Continue pinch into actor's area - we should still not receive the signal
243   data.Reset();
244   TestContinuePinch( application, Vector2( 112.0f, 100.0f ), Vector2( 112.0f, 124.0f ),
245                                   Vector2( 5.0f, 5.0f ), Vector2( 35.0f, 35.0f ), 200 );
246
247   DALI_TEST_EQUALS(false, data.functorCalled, TEST_LOCATION);
248
249   // Stop pinching - we should still not receive the signal
250   data.Reset();
251   TestEndPinch( application,  Vector2( 6.0f, 6.0f ), Vector2( 18.0f, 18.0f ),
252                               Vector2( 10.0f, 8.0f ), Vector2( 14.0f, 16.0f ), 300 );
253
254   DALI_TEST_EQUALS(false, data.functorCalled, TEST_LOCATION);
255   END_TEST;
256 }
257
258 int UtcDaliPinchGestureSignalReceptionDownMotionLeave(void)
259 {
260   TestApplication application;
261
262   Actor actor = Actor::New();
263   actor.SetProperty( Actor::Property::SIZE, Vector2( 100.0f, 100.0f ) );
264   actor.SetProperty( Actor::Property::ANCHOR_POINT,AnchorPoint::TOP_LEFT);
265   application.GetScene().Add(actor);
266
267   // Render and notify
268   application.SendNotification();
269   application.Render();
270
271   SignalData data;
272   GestureReceivedFunctor functor(data);
273
274   PinchGestureDetector detector = PinchGestureDetector::New();
275   detector.Attach(actor);
276   detector.DetectedSignal().Connect(&application, functor);
277
278   // Start pan within the actor's area
279   TestStartPinch( application,  Vector2( 5.0f, 20.0f ), Vector2( 35.0f, 20.0f ),
280                                 Vector2( 10.0f, 20.0f ), Vector2( 30.0f, 20.0f ), 100 );
281   DALI_TEST_EQUALS(true, data.functorCalled, TEST_LOCATION);
282   DALI_TEST_EQUALS(Gesture::Started, data.receivedGesture.GetState(), TEST_LOCATION);
283   DALI_TEST_EQUALS(0.666f, data.receivedGesture.GetScale(), 0.01f, TEST_LOCATION);
284   DALI_TEST_EQUALS(66.666f, data.receivedGesture.GetSpeed(), 0.01f, TEST_LOCATION);
285   DALI_TEST_EQUALS(Vector2(20.0f, 20.0f), data.receivedGesture.GetScreenCenterPoint(), 0.01f, TEST_LOCATION);
286   DALI_TEST_EQUALS(Vector2(20.0f, 20.0f), data.receivedGesture.GetLocalCenterPoint(), 0.01f, TEST_LOCATION);
287
288   // Continue the pan within the actor's area - we should still receive the signal
289   data.Reset();
290   TestContinuePinch( application, Vector2( 10.0f, 20.0f ), Vector2( 30.0f, 20.0f ),
291                                   Vector2( 17.0f, 20.0f ), Vector2( 25.0f, 20.0f ), 400 );
292   DALI_TEST_EQUALS(true, data.functorCalled, TEST_LOCATION);
293   DALI_TEST_EQUALS(Gesture::Continuing, data.receivedGesture.GetState(), TEST_LOCATION);
294   DALI_TEST_EQUALS(0.2666f, data.receivedGesture.GetScale(), 0.01f, TEST_LOCATION);
295   DALI_TEST_EQUALS(80.0f, data.receivedGesture.GetSpeed(), 0.01f, TEST_LOCATION);
296   DALI_TEST_EQUALS(Vector2(21.0f, 20.0f), data.receivedGesture.GetScreenCenterPoint(), 0.01f, TEST_LOCATION);
297   DALI_TEST_EQUALS(Vector2(21.0f, 20.0f), data.receivedGesture.GetLocalCenterPoint(), 0.01f, TEST_LOCATION);
298
299   // Pan Gesture leaves actor's area - we should still receive the signal
300   data.Reset();
301   TestContinuePinch( application, Vector2( 17.0f, 20.0f ), Vector2( 25.0f, 20.0f ),
302                                   Vector2( 300.0f, 10.0f ), Vector2( 340.0f, 10.0f ), 1000 );
303   DALI_TEST_EQUALS(true, data.functorCalled, TEST_LOCATION);
304   DALI_TEST_EQUALS(Gesture::Continuing, data.receivedGesture.GetState(), TEST_LOCATION);
305   DALI_TEST_EQUALS(1.333f, data.receivedGesture.GetScale(), 0.01f, TEST_LOCATION);
306   DALI_TEST_EQUALS(213.333f, data.receivedGesture.GetSpeed(), 0.01f, TEST_LOCATION);
307   DALI_TEST_EQUALS(Vector2(320.0f, 10.0f), data.receivedGesture.GetScreenCenterPoint(), 0.01f, TEST_LOCATION);
308   DALI_TEST_EQUALS(Vector2(320.0f, 10.0f), data.receivedGesture.GetLocalCenterPoint(), 0.01f, TEST_LOCATION);
309
310   // Gesture ends - we would receive a finished state
311   data.Reset();
312   TestEndPinch( application,  Vector2( 300.0f, 10.0f ), Vector2( 340.0f, 10.0f ),
313                               Vector2( 305.0f, 10.0f ), Vector2( 315.0f, 10.0f ), 1500);
314   DALI_TEST_EQUALS(true, data.functorCalled, TEST_LOCATION);
315   DALI_TEST_EQUALS(Gesture::Finished, data.receivedGesture.GetState(), TEST_LOCATION);
316   DALI_TEST_EQUALS(0.333f, data.receivedGesture.GetScale(), 0.01f, TEST_LOCATION);
317   DALI_TEST_EQUALS(600.0f, data.receivedGesture.GetSpeed(), 0.01f, TEST_LOCATION);
318   DALI_TEST_EQUALS(Vector2(310.0f, 10.0f), data.receivedGesture.GetScreenCenterPoint(), 0.01f, TEST_LOCATION);
319   DALI_TEST_EQUALS(Vector2(310.0f, 10.0f), data.receivedGesture.GetLocalCenterPoint(), 0.01f, TEST_LOCATION);
320   END_TEST;
321 }
322
323 int UtcDaliPinchGestureSignalReceptionDownMotionUp(void)
324 {
325   TestApplication application;
326
327   Actor actor = Actor::New();
328   actor.SetProperty( Actor::Property::SIZE, Vector2( 100.0f, 100.0f ) );
329   actor.SetProperty( Actor::Property::ANCHOR_POINT,AnchorPoint::TOP_LEFT);
330   application.GetScene().Add(actor);
331
332   // Render and notify
333   application.SendNotification();
334   application.Render();
335
336   SignalData data;
337   GestureReceivedFunctor functor(data);
338
339   PinchGestureDetector detector = PinchGestureDetector::New();
340   detector.Attach(actor);
341   detector.DetectedSignal().Connect(&application, functor);
342
343   // Start pinch within the actor's area
344   TestStartPinch( application,  Vector2( 2.0f, 20.0f ), Vector2( 38.0f, 20.0f ),
345                                 Vector2( 10.0f, 20.0f ), Vector2( 30.0f, 20.0f ), 100 );
346   DALI_TEST_EQUALS(true, data.functorCalled, TEST_LOCATION);
347   DALI_TEST_EQUALS(Gesture::Started, data.receivedGesture.GetState(), TEST_LOCATION);
348   DALI_TEST_EQUALS(0.555f, data.receivedGesture.GetScale(), 0.01f, TEST_LOCATION);
349   DALI_TEST_EQUALS(106.667f, data.receivedGesture.GetSpeed(), 0.01f, TEST_LOCATION);
350   DALI_TEST_EQUALS(Vector2(20.0f, 20.0f), data.receivedGesture.GetScreenCenterPoint(), 0.01f, TEST_LOCATION);
351   DALI_TEST_EQUALS(Vector2(20.0f, 20.0f), data.receivedGesture.GetLocalCenterPoint(), 0.01f, TEST_LOCATION);
352
353   // Continue the pinch within the actor's area - we should still receive the signal
354   data.Reset();
355   TestContinuePinch( application, Vector2( 10.0f, 20.0f ), Vector2( 30.0f, 20.0f ),
356                                   Vector2( 15.0f, 20.0f ), Vector2( 25.0f, 20.0f ), 500 );
357   DALI_TEST_EQUALS(true, data.functorCalled, TEST_LOCATION);
358   DALI_TEST_EQUALS(Gesture::Continuing, data.receivedGesture.GetState(), TEST_LOCATION);
359   DALI_TEST_EQUALS(0.277f, data.receivedGesture.GetScale(), 0.01f, TEST_LOCATION);
360   DALI_TEST_EQUALS(66.666f, data.receivedGesture.GetSpeed(), 0.01f, TEST_LOCATION);
361   DALI_TEST_EQUALS(Vector2(20.0f, 20.0f), data.receivedGesture.GetScreenCenterPoint(), 0.01f, TEST_LOCATION);
362   DALI_TEST_EQUALS(Vector2(20.0f, 20.0f), data.receivedGesture.GetLocalCenterPoint(), 0.01f, TEST_LOCATION);
363
364   // Gesture ends within actor's area - we would receive a finished state
365   data.Reset();
366   TestEndPinch( application,  Vector2( 15.0f, 20.0f ), Vector2( 25.0f, 20.0f ),
367                               Vector2( 19.0f, 20.0f ), Vector2( 21.0f, 20.0f ), 1000);
368   DALI_TEST_EQUALS(true, data.functorCalled, TEST_LOCATION);
369   DALI_TEST_EQUALS(Gesture::Finished, data.receivedGesture.GetState(), TEST_LOCATION);
370   DALI_TEST_EQUALS(0.055f, data.receivedGesture.GetScale(), 0.01f, TEST_LOCATION);
371   DALI_TEST_EQUALS(160.0f, data.receivedGesture.GetSpeed(), 0.01f, TEST_LOCATION);
372   DALI_TEST_EQUALS(Vector2(20.0f, 20.0f), data.receivedGesture.GetScreenCenterPoint(), 0.01f, TEST_LOCATION);
373   DALI_TEST_EQUALS(Vector2(20.0f, 20.0f), data.receivedGesture.GetLocalCenterPoint(), 0.01f, TEST_LOCATION);
374   END_TEST;
375 }
376
377 int UtcDaliPinchGestureSignalReceptionDetach(void)
378 {
379   TestApplication application;
380
381   Actor actor = Actor::New();
382   actor.SetProperty( Actor::Property::SIZE, Vector2( 100.0f, 100.0f ) );
383   actor.SetProperty( Actor::Property::ANCHOR_POINT,AnchorPoint::TOP_LEFT);
384   application.GetScene().Add(actor);
385
386   // Render and notify
387   application.SendNotification();
388   application.Render();
389
390   SignalData data;
391   GestureReceivedFunctor functor(data);
392
393   PinchGestureDetector detector = PinchGestureDetector::New();
394   detector.Attach(actor);
395   detector.DetectedSignal().Connect(&application, functor);
396
397   // Start pinch within the actor's area
398   TestStartPinch( application,  Vector2( 2.0f, 20.0f ), Vector2( 38.0f, 20.0f ),
399                                 Vector2( 10.0f, 20.0f ), Vector2( 30.0f, 20.0f ), 100 );
400   DALI_TEST_EQUALS(true, data.functorCalled, TEST_LOCATION);
401   DALI_TEST_EQUALS(Gesture::Started, data.receivedGesture.GetState(), TEST_LOCATION);
402
403
404   // Continue the pinch within the actor's area - we should still receive the signal
405   data.Reset();
406   TestContinuePinch( application, Vector2( 10.0f, 20.0f ), Vector2( 30.0f, 20.0f ),
407                                   Vector2( 15.0f, 20.0f ), Vector2( 25.0f, 20.0f ), 500 );
408   DALI_TEST_EQUALS(true, data.functorCalled, TEST_LOCATION);
409   DALI_TEST_EQUALS(Gesture::Continuing, data.receivedGesture.GetState(), TEST_LOCATION);
410
411   // Gesture ends within actor's area
412   data.Reset();
413   TestEndPinch( application,  Vector2( 15.0f, 20.0f ), Vector2( 25.0f, 20.0f ),
414                               Vector2( 19.0f, 20.0f ), Vector2( 21.0f, 20.0f ), 1000);
415   DALI_TEST_EQUALS(true, data.functorCalled, TEST_LOCATION);
416   DALI_TEST_EQUALS(Gesture::Finished, data.receivedGesture.GetState(), TEST_LOCATION);
417
418   // Detach actor
419   detector.DetachAll();
420
421   // Ensure we are no longer signalled
422   data.Reset();
423   TestGeneratePinch(  application );
424   DALI_TEST_EQUALS(false, data.functorCalled, TEST_LOCATION);
425   END_TEST;
426 }
427
428 int UtcDaliPinchGestureSignalReceptionDetachWhilePinching(void)
429 {
430   TestApplication application;
431
432   Actor actor = Actor::New();
433   actor.SetProperty( Actor::Property::SIZE, Vector2( 100.0f, 100.0f ) );
434   actor.SetProperty( Actor::Property::ANCHOR_POINT,AnchorPoint::TOP_LEFT);
435   application.GetScene().Add(actor);
436
437   // Render and notify
438   application.SendNotification();
439   application.Render();
440
441   SignalData data;
442   GestureReceivedFunctor functor(data);
443
444   PinchGestureDetector detector = PinchGestureDetector::New();
445   detector.Attach(actor);
446   detector.DetectedSignal().Connect(&application, functor);
447
448   // Start pinch within the actor's area
449   TestStartPinch( application,  Vector2( 2.0f, 20.0f ), Vector2( 38.0f, 20.0f ),
450                                 Vector2( 10.0f, 20.0f ), Vector2( 30.0f, 20.0f ), 100 );
451   DALI_TEST_EQUALS(true, data.functorCalled, TEST_LOCATION);
452   DALI_TEST_EQUALS(Gesture::Started, data.receivedGesture.GetState(), TEST_LOCATION);
453
454   // Continue the pinch within the actor's area - we should still receive the signal
455   data.Reset();
456   TestContinuePinch( application, Vector2( 10.0f, 20.0f ), Vector2( 30.0f, 20.0f ),
457                                   Vector2( 15.0f, 20.0f ), Vector2( 25.0f, 20.0f ), 500 );
458   DALI_TEST_EQUALS(true, data.functorCalled, TEST_LOCATION);
459   DALI_TEST_EQUALS(Gesture::Continuing, data.receivedGesture.GetState(), TEST_LOCATION);
460
461   // Detach actor during the pinch, we should not receive the next event
462   detector.DetachAll();
463
464   // Gesture ends within actor's area
465   data.Reset();
466   TestEndPinch( application,  Vector2( 15.0f, 20.0f ), Vector2( 25.0f, 20.0f ),
467                               Vector2( 19.0f, 20.0f ), Vector2( 21.0f, 20.0f ), 1000);
468   DALI_TEST_EQUALS(false, data.functorCalled, TEST_LOCATION);
469   END_TEST;
470 }
471
472 int UtcDaliPinchGestureSignalReceptionActorDestroyedWhilePinching(void)
473 {
474   TestApplication application;
475
476   SignalData data;
477   GestureReceivedFunctor functor(data);
478
479   PinchGestureDetector detector = PinchGestureDetector::New();
480   detector.DetectedSignal().Connect(&application, functor);
481
482   // Attach a temporary actor to stop detector being removed from PinchGestureProcessor when main actor
483   // is destroyed.
484   Actor tempActor = Actor::New();
485   tempActor.SetProperty( Actor::Property::SIZE, Vector2( 100.0f, 100.0f ) );
486   tempActor.SetProperty( Actor::Property::ANCHOR_POINT,AnchorPoint::BOTTOM_RIGHT);
487   application.GetScene().Add(tempActor);
488   detector.Attach(tempActor);
489
490   // Actor lifetime is scoped
491   {
492     Actor actor = Actor::New();
493     actor.SetProperty( Actor::Property::SIZE, Vector2( 100.0f, 100.0f ) );
494     actor.SetProperty( Actor::Property::ANCHOR_POINT,AnchorPoint::TOP_LEFT);
495     application.GetScene().Add(actor);
496
497     // Render and notify
498     application.SendNotification();
499     application.Render();
500
501     detector.Attach(actor);
502
503     // Start pinch within the actor's area
504     TestStartPinch( application,  Vector2( 2.0f, 20.0f ), Vector2( 38.0f, 20.0f ),
505                                   Vector2( 10.0f, 20.0f ), Vector2( 30.0f, 20.0f ), 100 );
506     DALI_TEST_EQUALS(true, data.functorCalled, TEST_LOCATION);
507     DALI_TEST_EQUALS(Gesture::Started, data.receivedGesture.GetState(), TEST_LOCATION);
508
509     // Continue the pinch within the actor's area - we should still receive the signal
510     data.Reset();
511     TestContinuePinch( application, Vector2( 10.0f, 20.0f ), Vector2( 30.0f, 20.0f ),
512                                     Vector2( 15.0f, 20.0f ), Vector2( 25.0f, 20.0f ), 500 );
513     DALI_TEST_EQUALS(true, data.functorCalled, TEST_LOCATION);
514     DALI_TEST_EQUALS(Gesture::Continuing, data.receivedGesture.GetState(), TEST_LOCATION);
515
516     // Remove the actor from stage and reset the data
517     application.GetScene().Remove(actor);
518
519     // Render and notify
520     application.SendNotification();
521     application.Render();
522   }
523
524   // Actor should now have been destroyed
525
526   // Gesture ends within the area where the actor used to be
527   data.Reset();
528   TestEndPinch( application,  Vector2( 15.0f, 20.0f ), Vector2( 25.0f, 20.0f ),
529                               Vector2( 19.0f, 20.0f ), Vector2( 21.0f, 20.0f ), 1000);
530   DALI_TEST_EQUALS(false, data.functorCalled, TEST_LOCATION);
531   END_TEST;
532 }
533
534 int UtcDaliPinchGestureSignalReceptionRotatedActor(void)
535 {
536   TestApplication application;
537
538   Actor actor = Actor::New();
539   actor.SetProperty( Actor::Property::SIZE, Vector2( 100.0f, 100.0f ) );
540   actor.SetProperty( Actor::Property::ORIENTATION, Quaternion(Dali::Degree(90.0f), Vector3::ZAXIS) );
541   application.GetScene().Add(actor);
542
543   // Render and notify a couple of times
544   application.SendNotification();
545   application.Render();
546
547   SignalData data;
548   GestureReceivedFunctor functor(data);
549
550   PinchGestureDetector detector = PinchGestureDetector::New();
551   detector.Attach(actor);
552   detector.DetectedSignal().Connect(&application, functor);
553
554   // Do an entire pinch, only check finished value
555   TestStartPinch( application,  Vector2( 2.0f, 20.0f ), Vector2( 38.0f, 20.0f ),
556                                 Vector2( 10.0f, 20.0f ), Vector2( 30.0f, 20.0f ), 100 );
557   data.Reset();
558   TestEndPinch( application,  Vector2( 15.0f, 20.0f ), Vector2( 25.0f, 20.0f ),
559                               Vector2( 19.0f, 20.0f ), Vector2( 21.0f, 20.0f ), 1000);
560   DALI_TEST_EQUALS(true, data.functorCalled, TEST_LOCATION);
561   DALI_TEST_EQUALS(0.055f, data.receivedGesture.GetScale(), 0.01f, TEST_LOCATION);
562   DALI_TEST_EQUALS(160.0f, data.receivedGesture.GetSpeed(), 0.01f, TEST_LOCATION);
563   DALI_TEST_EQUALS(Vector2(20.0f, 20.0f), data.receivedGesture.GetScreenCenterPoint(), 0.01f, TEST_LOCATION);
564   DALI_TEST_EQUALS(Vector2(70.0f, 30.0f), data.receivedGesture.GetLocalCenterPoint(), 0.01f, TEST_LOCATION);
565
566   // Rotate actor again and render and notify
567   actor.SetProperty( Actor::Property::ORIENTATION, Quaternion(Dali::Degree(180.0f), Vector3::ZAXIS) );
568   application.SendNotification();
569   application.Render();
570
571   // Do an entire pinch, only check finished value
572   TestStartPinch( application,  Vector2( 2.0f, 20.0f ), Vector2( 38.0f, 20.0f ),
573                                 Vector2( 10.0f, 20.0f ), Vector2( 30.0f, 20.0f ), 2100 );
574   data.Reset();
575   TestEndPinch( application,  Vector2( 15.0f, 20.0f ), Vector2( 25.0f, 20.0f ),
576                               Vector2( 19.0f, 20.0f ), Vector2( 21.0f, 20.0f ), 3000);
577   DALI_TEST_EQUALS(true, data.functorCalled, TEST_LOCATION);
578   DALI_TEST_EQUALS(0.055f, data.receivedGesture.GetScale(), 0.01f, TEST_LOCATION);
579   DALI_TEST_EQUALS(160.0f, data.receivedGesture.GetSpeed(), 0.01f, TEST_LOCATION);
580   DALI_TEST_EQUALS(Vector2(20.0f, 20.0f), data.receivedGesture.GetScreenCenterPoint(), 0.01f, TEST_LOCATION);
581   DALI_TEST_EQUALS(Vector2(30.0f, 30.0f), data.receivedGesture.GetLocalCenterPoint(), 0.01f, TEST_LOCATION);
582
583   // Rotate actor again and render and notify
584   actor.SetProperty( Actor::Property::ORIENTATION, Quaternion(Dali::Degree(270.0f), Vector3::ZAXIS) );
585   application.SendNotification();
586   application.Render();
587
588   // Do an entire pinch, only check finished value
589   TestStartPinch( application,  Vector2( 2.0f, 20.0f ), Vector2( 38.0f, 20.0f ),
590                                 Vector2( 10.0f, 20.0f ), Vector2( 30.0f, 20.0f ), 4100 );
591   data.Reset();
592   TestEndPinch( application,  Vector2( 15.0f, 20.0f ), Vector2( 25.0f, 20.0f ),
593                               Vector2( 19.0f, 20.0f ), Vector2( 21.0f, 20.0f ), 5000);
594   DALI_TEST_EQUALS(true, data.functorCalled, TEST_LOCATION);
595   DALI_TEST_EQUALS(0.055f, data.receivedGesture.GetScale(), 0.01f, TEST_LOCATION);
596   DALI_TEST_EQUALS(160.0f, data.receivedGesture.GetSpeed(), 0.01f, TEST_LOCATION);
597   DALI_TEST_EQUALS(Vector2(20.0f, 20.0f), data.receivedGesture.GetScreenCenterPoint(), 0.01f, TEST_LOCATION);
598   DALI_TEST_EQUALS(Vector2(30.0f, 70.0f), data.receivedGesture.GetLocalCenterPoint(), 0.01f, TEST_LOCATION);
599   END_TEST;
600 }
601
602 int UtcDaliPinchGestureSignalReceptionChildHit(void)
603 {
604   TestApplication application;
605
606   Actor parent = Actor::New();
607   parent.SetProperty( Actor::Property::SIZE, Vector2( 100.0f, 100.0f ) );
608   parent.SetProperty( Actor::Property::ANCHOR_POINT,AnchorPoint::TOP_LEFT);
609   application.GetScene().Add(parent);
610
611   // Set child to completely cover parent.
612   // Change rotation of child to be different from parent so that we can check if our local coordinate
613   // conversion of the parent actor is correct.
614   Actor child = Actor::New();
615   child.SetProperty( Actor::Property::SIZE, Vector2( 100.0f, 100.0f ) );
616   child.SetProperty( Actor::Property::ANCHOR_POINT,AnchorPoint::CENTER);
617   child.SetProperty( Actor::Property::PARENT_ORIGIN,ParentOrigin::CENTER);
618   child.SetProperty( Actor::Property::ORIENTATION, Quaternion(Dali::Degree(90.0f), Vector3::ZAXIS) );
619   parent.Add(child);
620
621   // Render and notify
622   application.SendNotification();
623   application.Render();
624
625   SignalData data;
626   GestureReceivedFunctor functor(data);
627
628   PinchGestureDetector detector = PinchGestureDetector::New();
629   detector.Attach(parent);
630   detector.DetectedSignal().Connect(&application, functor);
631
632   // Do an entire pan, only check finished value - hits child area but parent should still receive it
633   TestStartPinch( application,  Vector2( 2.0f, 20.0f ), Vector2( 38.0f, 20.0f ),
634                                 Vector2( 10.0f, 20.0f ), Vector2( 30.0f, 20.0f ), 100 );
635   data.Reset();
636   TestEndPinch( application,  Vector2( 15.0f, 20.0f ), Vector2( 25.0f, 20.0f ),
637                               Vector2( 19.0f, 20.0f ), Vector2( 21.0f, 20.0f ), 1000);
638   DALI_TEST_EQUALS(true, data.functorCalled, TEST_LOCATION);
639   DALI_TEST_EQUALS(true, parent == data.pinchedActor, TEST_LOCATION);
640   DALI_TEST_EQUALS(0.055f, data.receivedGesture.GetScale(), 0.01f, TEST_LOCATION);
641   DALI_TEST_EQUALS(160.0f, data.receivedGesture.GetSpeed(), 0.01f, TEST_LOCATION);
642   DALI_TEST_EQUALS(Vector2(20.0f, 20.0f), data.receivedGesture.GetScreenCenterPoint(), 0.01f, TEST_LOCATION);
643
644   // Attach child and generate same touch points to yield same results
645   // (Also proves that you can detach and then re-attach another actor)
646   detector.Attach(child);
647   detector.Detach(parent);
648
649   // Do an entire pan, only check finished value
650   TestStartPinch( application,  Vector2( 2.0f, 20.0f ), Vector2( 38.0f, 20.0f ),
651                                 Vector2( 10.0f, 20.0f ), Vector2( 30.0f, 20.0f ), 2100 );
652   data.Reset();
653   TestEndPinch( application,  Vector2( 15.0f, 20.0f ), Vector2( 25.0f, 20.0f ),
654                               Vector2( 19.0f, 20.0f ), Vector2( 21.0f, 20.0f ), 3000);
655   DALI_TEST_EQUALS(true, data.functorCalled, TEST_LOCATION);
656   DALI_TEST_EQUALS(true, child == data.pinchedActor, TEST_LOCATION);
657   DALI_TEST_EQUALS(0.055f, data.receivedGesture.GetScale(), 0.01f, TEST_LOCATION);
658   DALI_TEST_EQUALS(160.0f, data.receivedGesture.GetSpeed(), 0.01f, TEST_LOCATION);
659   DALI_TEST_EQUALS(Vector2(20.0f, 20.0f), data.receivedGesture.GetScreenCenterPoint(), 0.01f, TEST_LOCATION);
660   DALI_TEST_EQUALS(Vector2(20.0f, 80.0f), data.receivedGesture.GetLocalCenterPoint(), 0.01f, TEST_LOCATION);
661   END_TEST;
662 }
663
664 int UtcDaliPinchGestureSignalReceptionAttachDetachMany(void)
665 {
666   TestApplication application;
667
668   Actor first = Actor::New();
669   first.SetProperty( Actor::Property::SIZE, Vector2( 100.0f, 100.0f ) );
670   first.SetProperty( Actor::Property::ANCHOR_POINT,AnchorPoint::TOP_LEFT);
671   application.GetScene().Add(first);
672
673   Actor second = Actor::New();
674   second.SetProperty( Actor::Property::SIZE, Vector2( 100.0f, 100.0f ) );
675   second.SetProperty( Actor::Property::POSITION_X, 100.0f);
676   second.SetProperty( Actor::Property::ANCHOR_POINT,AnchorPoint::TOP_LEFT);
677   application.GetScene().Add(second);
678
679   // Render and notify
680   application.SendNotification();
681   application.Render();
682
683   SignalData data;
684   GestureReceivedFunctor functor(data);
685
686   PinchGestureDetector detector = PinchGestureDetector::New();
687   detector.Attach(first);
688   detector.Attach(second);
689   detector.DetectedSignal().Connect(&application, functor);
690
691   // Start pinch within second actor's area
692   TestStartPinch( application,  Vector2( 102.0f, 20.0f ), Vector2( 138.0f, 20.0f ),
693                                     Vector2( 110.0f, 20.0f ), Vector2( 130.0f, 20.0f ), 100 );
694   DALI_TEST_EQUALS(true, data.functorCalled, TEST_LOCATION);
695   DALI_TEST_EQUALS(true, second == data.pinchedActor, TEST_LOCATION);
696
697   // Pinch moves into first actor's area - second actor should receive the pinch
698   data.Reset();
699   TestContinuePinch( application, Vector2( 110.0f, 20.0f ), Vector2( 130.0f, 20.0f ),
700                                   Vector2( 15.0f, 20.0f ), Vector2( 25.0f, 20.0f ), 500 );
701   DALI_TEST_EQUALS(true, data.functorCalled, TEST_LOCATION);
702   DALI_TEST_EQUALS(true, second == data.pinchedActor, TEST_LOCATION);
703
704   // Detach the second actor during the pinch, we should not receive the next event
705   detector.Detach(second);
706
707   // Gesture ends within actor's area
708   data.Reset();
709   TestEndPinch( application,  Vector2( 15.0f, 20.0f ), Vector2( 25.0f, 20.0f ),
710                               Vector2( 119.0f, 20.0f ), Vector2( 121.0f, 20.0f ), 3000);
711   DALI_TEST_EQUALS(false, data.functorCalled, TEST_LOCATION);
712   END_TEST;
713 }
714
715 int UtcDaliPinchGestureSignalReceptionActorBecomesUntouchable(void)
716 {
717   TestApplication application;
718
719   Actor actor = Actor::New();
720   actor.SetProperty( Actor::Property::SIZE, Vector2( 100.0f, 100.0f ) );
721   actor.SetProperty( Actor::Property::ANCHOR_POINT,AnchorPoint::TOP_LEFT);
722   application.GetScene().Add(actor);
723
724   // Render and notify
725   application.SendNotification();
726   application.Render();
727
728   SignalData data;
729   GestureReceivedFunctor functor(data);
730
731   PinchGestureDetector detector = PinchGestureDetector::New();
732   detector.Attach(actor);
733   detector.DetectedSignal().Connect(&application, functor);
734
735   // Start pinch in actor's area
736   TestStartPinch( application,  Vector2( 2.0f, 20.0f ), Vector2( 38.0f, 20.0f ),
737                                 Vector2( 10.0f, 20.0f ), Vector2( 30.0f, 20.0f ), 100 );
738   DALI_TEST_EQUALS(true, data.functorCalled, TEST_LOCATION);
739
740   // Pan continues within actor's area
741   data.Reset();
742   TestContinuePinch( application, Vector2( 10.0f, 20.0f ), Vector2( 30.0f, 20.0f ),
743                                   Vector2( 15.0f, 20.0f ), Vector2( 25.0f, 20.0f ), 500 );
744   DALI_TEST_EQUALS(true, data.functorCalled, TEST_LOCATION);
745
746   // Actor become invisible - actor should not receive the next pinch
747   actor.SetProperty( Actor::Property::VISIBLE,false);
748
749   // Render and notify
750   application.SendNotification();
751   application.Render();
752
753   // Gesture ends within actor's area
754   data.Reset();
755   TestEndPinch( application,  Vector2( 15.0f, 20.0f ), Vector2( 25.0f, 20.0f ),
756                               Vector2( 19.0f, 20.0f ), Vector2( 21.0f, 20.0f ), 3000);
757   DALI_TEST_EQUALS(false, data.functorCalled, TEST_LOCATION);
758   END_TEST;
759 }
760
761 int UtcDaliPinchGestureSignalReceptionMultipleDetectorsOnActor(void)
762 {
763   TestApplication application;
764
765   Actor actor = Actor::New();
766   actor.SetProperty( Actor::Property::SIZE, Vector2( 100.0f, 100.0f ) );
767   actor.SetProperty( Actor::Property::ANCHOR_POINT,AnchorPoint::TOP_LEFT);
768   application.GetScene().Add(actor);
769
770   Actor actor2 = Actor::New();
771   actor2.SetProperty( Actor::Property::SIZE, Vector2( 100.0f, 100.0f ) );
772   actor2.SetProperty( Actor::Property::ANCHOR_POINT,AnchorPoint::BOTTOM_RIGHT);
773   application.GetScene().Add(actor2);
774
775   // Render and notify
776   application.SendNotification();
777   application.Render();
778
779   // Attach actor to one detector
780   SignalData firstData;
781   GestureReceivedFunctor firstFunctor(firstData);
782   PinchGestureDetector firstDetector = PinchGestureDetector::New();
783   firstDetector.Attach(actor);
784   firstDetector.DetectedSignal().Connect(&application, firstFunctor);
785
786   // Attach actor to another detector
787   SignalData secondData;
788   GestureReceivedFunctor secondFunctor(secondData);
789   PinchGestureDetector secondDetector = PinchGestureDetector::New();
790   secondDetector.Attach(actor);
791   secondDetector.DetectedSignal().Connect(&application, secondFunctor);
792
793   // Add second actor to second detector, when we remove the actor, this will make sure that this
794   // gesture detector is not removed from the GestureDetectorProcessor.  In this scenario, the
795   // functor should still not be called (which is what we're also testing).
796   secondDetector.Attach(actor2);
797
798   // Pinch in actor's area - both detector's functors should be called
799   TestStartPinch( application,  Vector2( 2.0f, 20.0f ), Vector2( 38.0f, 20.0f ),
800                                 Vector2( 10.0f, 20.0f ), Vector2( 30.0f, 20.0f ), 100 );
801   DALI_TEST_EQUALS(true, firstData.functorCalled, TEST_LOCATION);
802   DALI_TEST_EQUALS(true, secondData.functorCalled, TEST_LOCATION);
803
804   // Pinch continues in actor's area - both detector's functors should be called
805   firstData.Reset();
806   secondData.Reset();
807   TestContinuePinch( application, Vector2( 10.0f, 20.0f ), Vector2( 30.0f, 20.0f ),
808                                   Vector2( 15.0f, 20.0f ), Vector2( 25.0f, 20.0f ), 500 );
809   DALI_TEST_EQUALS(true, firstData.functorCalled, TEST_LOCATION);
810   DALI_TEST_EQUALS(true, secondData.functorCalled, TEST_LOCATION);
811
812   // Detach actor from firstDetector and emit pinch on actor, only secondDetector's functor should be called.
813   firstDetector.Detach(actor);
814   firstData.Reset();
815   secondData.Reset();
816   TestEndPinch( application,  Vector2( 15.0f, 20.0f ), Vector2( 25.0f, 20.0f ),
817                               Vector2( 19.0f, 20.0f ), Vector2( 21.0f, 20.0f ), 1000);
818   DALI_TEST_EQUALS(false, firstData.functorCalled, TEST_LOCATION);
819   DALI_TEST_EQUALS(true, secondData.functorCalled, TEST_LOCATION);
820
821   // New pinch on actor, only secondDetector has actor attached
822   firstData.Reset();
823   secondData.Reset();
824   TestStartPinch( application,  Vector2( 2.0f, 20.0f ), Vector2( 38.0f, 20.0f ),
825                                 Vector2( 10.0f, 20.0f ), Vector2( 30.0f, 20.0f ), 1500 );
826   DALI_TEST_EQUALS(false, firstData.functorCalled, TEST_LOCATION);
827   DALI_TEST_EQUALS(true, secondData.functorCalled, TEST_LOCATION);
828
829   // Detach actor from secondDetector
830   secondDetector.Detach(actor);
831   firstData.Reset();
832   secondData.Reset();
833   TestContinuePinch( application, Vector2( 10.0f, 20.0f ), Vector2( 30.0f, 20.0f ),
834                                   Vector2( 15.0f, 20.0f ), Vector2( 25.0f, 20.0f ), 2000 );
835   DALI_TEST_EQUALS(false, firstData.functorCalled, TEST_LOCATION);
836   DALI_TEST_EQUALS(false, secondData.functorCalled, TEST_LOCATION);
837   END_TEST;
838 }
839
840 int UtcDaliPinchGestureSignalReceptionEnsureCorrectSignalling(void)
841 {
842   TestApplication application;
843
844   Actor actor1 = Actor::New();
845   actor1.SetProperty( Actor::Property::SIZE, Vector2( 100.0f, 100.0f ) );
846   actor1.SetProperty( Actor::Property::ANCHOR_POINT,AnchorPoint::TOP_LEFT);
847   application.GetScene().Add(actor1);
848   SignalData data1;
849   GestureReceivedFunctor functor1(data1);
850   PinchGestureDetector detector1 = PinchGestureDetector::New();
851   detector1.Attach(actor1);
852   detector1.DetectedSignal().Connect(&application, functor1);
853
854   Actor actor2 = Actor::New();
855   actor2.SetProperty( Actor::Property::SIZE, Vector2( 100.0f, 100.0f ) );
856   actor2.SetProperty( Actor::Property::ANCHOR_POINT,AnchorPoint::BOTTOM_RIGHT);
857   actor2.SetProperty( Actor::Property::PARENT_ORIGIN,ParentOrigin::BOTTOM_RIGHT);
858   application.GetScene().Add(actor2);
859   SignalData data2;
860   GestureReceivedFunctor functor2(data2);
861   PinchGestureDetector detector2 = PinchGestureDetector::New();
862   detector2.Attach(actor2);
863   detector2.DetectedSignal().Connect(&application, functor2);
864
865   // Render and notify
866   application.SendNotification();
867   application.Render();
868
869   // Start pan in actor1's area, only data1 should be set
870   TestStartPinch( application,  Vector2( 2.0f, 20.0f ), Vector2( 38.0f, 20.0f ),
871                                 Vector2( 10.0f, 20.0f ), Vector2( 30.0f, 20.0f ), 100 );
872   DALI_TEST_EQUALS(true, data1.functorCalled, TEST_LOCATION);
873   DALI_TEST_EQUALS(false, data2.functorCalled, TEST_LOCATION);
874   END_TEST;
875 }
876
877 int UtcDaliPinchGestureActorUnstaged(void)
878 {
879   TestApplication application;
880
881   Actor actor = Actor::New();
882   actor.SetProperty( Actor::Property::SIZE, Vector2( 100.0f, 100.0f ) );
883   actor.SetProperty( Actor::Property::ANCHOR_POINT,AnchorPoint::TOP_LEFT);
884   application.GetScene().Add(actor);
885
886   // Render and notify
887   application.SendNotification();
888   application.Render();
889
890   // State to remove actor in.
891   Gesture::State stateToUnstage( Gesture::Started );
892
893   // Attach actor to detector
894   SignalData data;
895   UnstageActorFunctor functor( data, stateToUnstage, application.GetScene() );
896   PinchGestureDetector detector = PinchGestureDetector::New();
897   detector.Attach(actor);
898   detector.DetectedSignal().Connect( &application, functor );
899
900   // Emit signals
901   TestStartPinch( application,  Vector2( 2.0f, 20.0f ), Vector2( 38.0f, 20.0f ),
902                                 Vector2( 10.0f, 20.0f ), Vector2( 30.0f, 20.0f ), 100 );
903   DALI_TEST_EQUALS(true, data.functorCalled, TEST_LOCATION);
904   data.Reset();
905   TestEndPinch( application,  Vector2( 10.0f, 20.0f ), Vector2( 30.0f, 20.0f ),
906                               Vector2( 19.0f, 20.0f ), Vector2( 21.0f, 20.0f ), 1000);
907   DALI_TEST_EQUALS(false, data.functorCalled, TEST_LOCATION);
908   data.Reset();
909
910   // Render and notify
911   application.SendNotification();
912   application.Render();
913
914   // Re-add actor to stage
915   application.GetScene().Add(actor);
916
917   // Render and notify
918   application.SendNotification();
919   application.Render();
920
921   // Change state to Gesture::Continuing to remove
922   stateToUnstage = Gesture::Continuing;
923
924   // Emit signals
925   TestStartPinch( application,  Vector2( 2.0f, 20.0f ), Vector2( 38.0f, 20.0f ),
926                                 Vector2( 10.0f, 20.0f ), Vector2( 30.0f, 20.0f ), 100 );
927   DALI_TEST_EQUALS(true, data.functorCalled, TEST_LOCATION);
928   data.Reset();
929   TestContinuePinch( application, Vector2( 10.0f, 20.0f ), Vector2( 30.0f, 20.0f ),
930                                   Vector2( 15.0f, 20.0f ), Vector2( 25.0f, 20.0f ), 500 );
931   DALI_TEST_EQUALS(true, data.functorCalled, TEST_LOCATION);
932   data.Reset();
933   TestEndPinch( application,  Vector2( 10.0f, 20.0f ), Vector2( 30.0f, 20.0f ),
934                               Vector2( 19.0f, 20.0f ), Vector2( 21.0f, 20.0f ), 1000);
935   DALI_TEST_EQUALS(false, data.functorCalled, TEST_LOCATION);
936   data.Reset();
937
938   // Render and notify
939   application.SendNotification();
940   application.Render();
941
942   // Re-add actor to stage
943   application.GetScene().Add(actor);
944
945   // Render and notify
946   application.SendNotification();
947   application.Render();
948
949   // Change state to Gesture::Continuing to remove
950   stateToUnstage = Gesture::Finished;
951
952   // Emit signals
953   TestStartPinch( application,  Vector2( 2.0f, 20.0f ), Vector2( 38.0f, 20.0f ),
954                                 Vector2( 10.0f, 20.0f ), Vector2( 30.0f, 20.0f ), 100 );
955   DALI_TEST_EQUALS(true, data.functorCalled, TEST_LOCATION);
956   data.Reset();
957   TestContinuePinch( application, Vector2( 10.0f, 20.0f ), Vector2( 30.0f, 20.0f ),
958                                   Vector2( 15.0f, 20.0f ), Vector2( 25.0f, 20.0f ), 500 );
959   DALI_TEST_EQUALS(true, data.functorCalled, TEST_LOCATION);
960   data.Reset();
961   TestEndPinch( application,  Vector2( 10.0f, 20.0f ), Vector2( 30.0f, 20.0f ),
962                               Vector2( 19.0f, 20.0f ), Vector2( 21.0f, 20.0f ), 1000);
963   DALI_TEST_EQUALS(true, data.functorCalled, TEST_LOCATION);
964   tet_result( TET_PASS ); // If we get here then we have handled actor stage removal gracefully.
965   END_TEST;
966 }
967
968 int UtcDaliPinchGestureActorStagedAndDestroyed(void)
969 {
970   TestApplication application;
971
972   Actor actor = Actor::New();
973   actor.SetProperty( Actor::Property::SIZE, Vector2( 100.0f, 100.0f ) );
974   actor.SetProperty( Actor::Property::ANCHOR_POINT,AnchorPoint::TOP_LEFT);
975   application.GetScene().Add(actor);
976
977   // Create and add a second actor so that GestureDetector destruction does not come into play.
978   Actor dummyActor( Actor::New() );
979   dummyActor.SetProperty( Actor::Property::SIZE, Vector2( 100.0f, 100.0f ) );
980   dummyActor.SetProperty( Actor::Property::POSITION, Vector2( 100.0f, 100.0f ));
981   dummyActor.SetProperty( Actor::Property::ANCHOR_POINT,AnchorPoint::TOP_LEFT);
982   application.GetScene().Add(dummyActor);
983
984   // Render and notify
985   application.SendNotification();
986   application.Render();
987
988   // State to remove actor in.
989   Gesture::State stateToUnstage( Gesture::Started );
990
991   // Attach actor to detector
992   SignalData data;
993   UnstageActorFunctor functor( data, stateToUnstage, application.GetScene() );
994   PinchGestureDetector detector = PinchGestureDetector::New();
995   detector.Attach(actor);
996   detector.Attach(dummyActor);
997   detector.DetectedSignal().Connect( &application, functor );
998
999   // Here we are testing a Started actor which is removed in the Started callback, but then added back
1000   // before we get a continuing state.  As we were removed from the stage, even if we're at the same
1001   // position, we should still not be signalled.
1002
1003   // Emit signals
1004   TestStartPinch( application,  Vector2( 2.0f, 20.0f ), Vector2( 38.0f, 20.0f ),
1005                                 Vector2( 10.0f, 20.0f ), Vector2( 30.0f, 20.0f ), 100 );
1006   DALI_TEST_EQUALS(true, data.functorCalled, TEST_LOCATION);
1007   data.Reset();
1008
1009   // Render and notify
1010   application.SendNotification();
1011   application.Render();
1012
1013   // Re add to the stage, we should not be signalled
1014   application.GetScene().Add(actor);
1015
1016   // Render and notify
1017   application.SendNotification();
1018   application.Render();
1019
1020   // Continue signal emission
1021   TestContinuePinch( application, Vector2( 10.0f, 20.0f ), Vector2( 30.0f, 20.0f ),
1022                                   Vector2( 15.0f, 20.0f ), Vector2( 25.0f, 20.0f ), 500 );
1023   DALI_TEST_EQUALS(false, data.functorCalled, TEST_LOCATION);
1024   data.Reset();
1025   TestEndPinch( application,  Vector2( 10.0f, 20.0f ), Vector2( 30.0f, 20.0f ),
1026                                 Vector2( 19.0f, 20.0f ), Vector2( 21.0f, 20.0f ), 1000);
1027   DALI_TEST_EQUALS(false, data.functorCalled, TEST_LOCATION);
1028   data.Reset();
1029
1030   // Here we delete an actor in started, we should not receive any subsequent signalling.
1031
1032   // Emit signals
1033   TestStartPinch( application,  Vector2( 2.0f, 20.0f ), Vector2( 38.0f, 20.0f ),
1034                                 Vector2( 10.0f, 20.0f ), Vector2( 30.0f, 20.0f ), 1500 );
1035   DALI_TEST_EQUALS(true, data.functorCalled, TEST_LOCATION);
1036   data.Reset();
1037
1038   // Render and notify
1039   application.SendNotification();
1040   application.Render();
1041
1042   // Delete actor as well
1043   actor.Reset();
1044
1045   // Render and notify
1046   application.SendNotification();
1047   application.Render();
1048
1049   // Continue signal emission
1050   TestContinuePinch( application, Vector2( 10.0f, 20.0f ), Vector2( 30.0f, 20.0f ),
1051                                   Vector2( 15.0f, 20.0f ), Vector2( 25.0f, 20.0f ), 2000 );
1052   DALI_TEST_EQUALS(false, data.functorCalled, TEST_LOCATION);
1053   data.Reset();
1054   TestEndPinch( application,  Vector2( 10.0f, 20.0f ), Vector2( 30.0f, 20.0f ),
1055                                 Vector2( 19.0f, 20.0f ), Vector2( 21.0f, 20.0f ), 3000);
1056   DALI_TEST_EQUALS(false, data.functorCalled, TEST_LOCATION);
1057   END_TEST;
1058 }
1059
1060 int UtcDaliPinchGestureLayerConsumesTouch(void)
1061 {
1062   TestApplication application;
1063
1064   Actor actor = Actor::New();
1065   actor.SetProperty( Actor::Property::SIZE, Vector2( 100.0f, 100.0f ) );
1066   actor.SetProperty( Actor::Property::ANCHOR_POINT,AnchorPoint::TOP_LEFT);
1067   application.GetScene().Add(actor);
1068
1069   // Add a detector
1070   SignalData data;
1071   GestureReceivedFunctor functor(data);
1072   PinchGestureDetector detector = PinchGestureDetector::New();
1073   detector.Attach(actor);
1074   detector.DetectedSignal().Connect( &application, functor );
1075
1076   // Add a layer to overlap the actor
1077   Layer layer = Layer::New();
1078   layer.SetProperty( Actor::Property::SIZE, Vector2( 100.0f, 100.0f ) );
1079   layer.SetProperty( Actor::Property::ANCHOR_POINT,AnchorPoint::TOP_LEFT);
1080   application.GetScene().Add( layer );
1081   layer.RaiseToTop();
1082
1083   // Render and notify
1084   application.SendNotification();
1085   application.Render();
1086
1087   // Emit signals, should receive
1088   TestStartPinch( application,  Vector2( 2.0f, 20.0f ), Vector2( 38.0f, 20.0f ),
1089                                 Vector2( 10.0f, 20.0f ), Vector2( 30.0f, 20.0f ), 100 );
1090   TestEndPinch( application,  Vector2( 10.0f, 20.0f ), Vector2( 30.0f, 20.0f ),
1091                               Vector2( 19.0f, 20.0f ), Vector2( 21.0f, 20.0f ), 1000);
1092   DALI_TEST_EQUALS(true, data.functorCalled, TEST_LOCATION);
1093   data.Reset();
1094
1095   // Set layer to consume all touch
1096   layer.SetProperty( Layer::Property::CONSUMES_TOUCH, true );
1097
1098   // Render and notify
1099   application.SendNotification();
1100   application.Render();
1101
1102   // Emit the same signals again, should not receive
1103   TestStartPinch( application,  Vector2( 2.0f, 20.0f ), Vector2( 38.0f, 20.0f ),
1104                                 Vector2( 10.0f, 20.0f ), Vector2( 30.0f, 20.0f ), 1500 );
1105   TestEndPinch( application,  Vector2( 10.0f, 20.0f ), Vector2( 30.0f, 20.0f ),
1106                               Vector2( 19.0f, 20.0f ), Vector2( 21.0f, 20.0f ), 2000);
1107   DALI_TEST_EQUALS(false, data.functorCalled, TEST_LOCATION);
1108   data.Reset();
1109
1110   END_TEST;
1111 }
1112
1113 int UtcDaliPinchGestureInterruptedWhenTouchConsumed(void)
1114 {
1115   TestApplication application;
1116
1117   Actor actor = Actor::New();
1118   actor.SetProperty( Actor::Property::SIZE, Vector2( 100.0f, 100.0f ) );
1119   actor.SetProperty( Actor::Property::ANCHOR_POINT,AnchorPoint::TOP_LEFT);
1120   application.GetScene().Add(actor);
1121
1122   bool consume = false;
1123   TouchEventFunctorConsumeSetter touchFunctor(consume);
1124   actor.TouchedSignal().Connect(&application,touchFunctor);
1125
1126   // Render and notify
1127   application.SendNotification();
1128   application.Render();
1129
1130   SignalData data;
1131   GestureReceivedFunctor functor(data);
1132
1133   PinchGestureDetector detector = PinchGestureDetector::New();
1134   detector.Attach(actor);
1135   detector.DetectedSignal().Connect(&application, functor);
1136
1137   // Start gesture within the actor's area, we should receive the pinch as the touch is NOT being consumed
1138   TestStartPinch( application,  Vector2( 2.0f, 20.0f ), Vector2( 38.0f, 20.0f ),
1139                                 Vector2( 10.0f, 20.0f ), Vector2( 30.0f, 20.0f ), 100 );
1140
1141   DALI_TEST_EQUALS(true, data.functorCalled, TEST_LOCATION);
1142   DALI_TEST_EQUALS(Gesture::Started, data.receivedGesture.GetState(), TEST_LOCATION);
1143   data.Reset();
1144
1145   // Continue the gesture within the actor's area, but now the touch consumes thus cancelling the gesture
1146   consume = true;
1147
1148   TestContinuePinch( application, Vector2( 112.0f, 100.0f ), Vector2( 112.0f, 124.0f ),
1149                                   Vector2( 5.0f, 5.0f ), Vector2( 35.0f, 35.0f ), 200 );
1150
1151   DALI_TEST_EQUALS(true, data.functorCalled, TEST_LOCATION);
1152   DALI_TEST_EQUALS(Gesture::Cancelled, data.receivedGesture.GetState(), TEST_LOCATION);
1153   data.Reset();
1154
1155   // Start another pinch, we should not even get the callback this time
1156   TestStartPinch( application,  Vector2( 2.0f, 20.0f ), Vector2( 38.0f, 20.0f ),
1157                                 Vector2( 10.0f, 20.0f ), Vector2( 30.0f, 20.0f ), 100 );
1158   DALI_TEST_EQUALS(false, data.functorCalled, TEST_LOCATION);
1159
1160   END_TEST;
1161 }
1162
1163
1164 int UtcDaliPinchGestureDisableDetectionDuringPinchN(void)
1165 {
1166   // Crash sometimes occurred when gesture-recognizer was deleted internally during a signal when the attached actor was detached
1167
1168   TestApplication application;
1169
1170   Actor actor = Actor::New();
1171   actor.SetProperty( Actor::Property::SIZE, Vector2( 100.0f, 100.0f ) );
1172   actor.SetProperty( Actor::Property::ANCHOR_POINT,AnchorPoint::TOP_LEFT);
1173   application.GetScene().Add(actor);
1174
1175   // Add a detector
1176   PinchGestureDetector detector = PinchGestureDetector::New();
1177   bool functorCalled = false;
1178   detector.Attach( actor );
1179   detector.DetectedSignal().Connect(
1180       &application,
1181       [&detector, &functorCalled](Actor actor, const PinchGesture& gesture)
1182       {
1183         if( gesture.GetState() == Gesture::Finished )
1184         {
1185           detector.Detach(actor);
1186           functorCalled = true;
1187         }
1188       });
1189
1190   // Render and notify
1191   application.SendNotification();
1192   application.Render();
1193
1194   // Try the gesture, should not crash
1195   try
1196   {
1197     TestStartPinch( application,  Vector2( 2.0f, 20.0f ), Vector2( 38.0f, 20.0f ),
1198                                   Vector2( 10.0f, 20.0f ), Vector2( 30.0f, 20.0f ), 100 );
1199     TestContinuePinch( application, Vector2( 112.0f, 100.0f ), Vector2( 112.0f, 124.0f ),
1200                                     Vector2( 5.0f, 5.0f ), Vector2( 35.0f, 35.0f ), 200 );
1201     TestEndPinch( application,  Vector2( 10.0f, 20.0f ), Vector2( 30.0f, 20.0f ),
1202                                 Vector2( 19.0f, 20.0f ), Vector2( 21.0f, 20.0f ), 1000);
1203
1204     DALI_TEST_CHECK( true ); // No crash, test has passed
1205     DALI_TEST_EQUALS(functorCalled, true, TEST_LOCATION);
1206   }
1207   catch(...)
1208   {
1209     DALI_TEST_CHECK( false ); // If we crash, the test has failed
1210   }
1211
1212   END_TEST;
1213 }