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