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