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