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