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