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