[dali_2.3.33] Merge branch 'devel/master'
[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/events/touch-integ.h>
22 #include <dali/integration-api/render-task-list-integ.h>
23 #include <dali/internal/event/events/touch-event-impl.h>
24 #include <dali/internal/event/render-tasks/render-task-impl.h>
25 #include <dali/public-api/dali-core.h>
26 #include <stdlib.h>
27 #include <test-touch-event-utils.h>
28
29 #include <iostream>
30
31 using namespace Dali;
32
33 void utc_dali_pinch_gesture_detector_startup(void)
34 {
35   test_return_value = TET_UNDEF;
36 }
37
38 void utc_dali_pinch_gesture_detector_cleanup(void)
39 {
40   test_return_value = TET_PASS;
41 }
42
43 ///////////////////////////////////////////////////////////////////////////////
44 namespace
45 {
46 // Stores data that is populated in the callback and will be read by the TET cases
47 struct SignalData
48 {
49   SignalData()
50   : functorCalled(false),
51     voidFunctorCalled(false),
52     receivedGesture()
53   {
54   }
55
56   void Reset()
57   {
58     functorCalled     = false;
59     voidFunctorCalled = false;
60
61     receivedGesture.Reset();
62
63     pinchedActor.Reset();
64   }
65
66   bool         functorCalled;
67   bool         voidFunctorCalled;
68   PinchGesture receivedGesture;
69   Actor        pinchedActor;
70 };
71
72 // Functor that sets the data when called
73 struct GestureReceivedFunctor
74 {
75   GestureReceivedFunctor(SignalData& data)
76   : signalData(data)
77   {
78   }
79
80   void operator()(Actor actor, const PinchGesture& pinch)
81   {
82     signalData.functorCalled   = true;
83     signalData.receivedGesture = pinch;
84     signalData.pinchedActor    = actor;
85   }
86
87   void operator()()
88   {
89     signalData.voidFunctorCalled = true;
90   }
91
92   SignalData& signalData;
93 };
94
95 // Functor that removes the gestured actor from stage
96 struct UnstageActorFunctor : public GestureReceivedFunctor
97 {
98   UnstageActorFunctor(SignalData& data, GestureState& stateToUnstage, Integration::Scene scene)
99   : GestureReceivedFunctor(data),
100     stateToUnstage(stateToUnstage),
101     scene(scene)
102   {
103   }
104
105   void operator()(Actor actor, const PinchGesture& pinch)
106   {
107     GestureReceivedFunctor::operator()(actor, pinch);
108
109     if(pinch.GetState() == stateToUnstage)
110     {
111       scene.Remove(actor);
112     }
113   }
114
115   GestureState&      stateToUnstage;
116   Integration::Scene scene;
117 };
118
119
120 Integration::TouchEvent GenerateDoubleTouch(PointState::Type stateA, const Vector2& screenPositionA, PointState::Type stateB, const Vector2& screenPositionB, uint32_t time)
121 {
122   Integration::TouchEvent touchEvent;
123   Integration::Point      point;
124   point.SetState(stateA);
125   point.SetScreenPosition(screenPositionA);
126   point.SetDeviceClass(Device::Class::TOUCH);
127   point.SetDeviceSubclass(Device::Subclass::NONE);
128   touchEvent.points.push_back(point);
129   point.SetScreenPosition(screenPositionB);
130   point.SetState(stateB);
131   touchEvent.points.push_back(point);
132   touchEvent.time = time;
133   return touchEvent;
134 }
135
136 } // namespace
137
138 ///////////////////////////////////////////////////////////////////////////////
139
140 int UtcDaliPinchGestureDetectorConstructor(void)
141 {
142   TestApplication application;
143
144   PinchGestureDetector detector;
145   DALI_TEST_CHECK(!detector);
146   END_TEST;
147 }
148
149 int UtcDaliPinchGestureDetectorCopyConstructorP(void)
150 {
151   TestApplication application;
152
153   PinchGestureDetector detector = PinchGestureDetector::New();
154
155   PinchGestureDetector copy(detector);
156   DALI_TEST_CHECK(detector);
157   END_TEST;
158 }
159
160 int UtcDaliPinchGestureDetectorAssignmentOperatorP(void)
161 {
162   TestApplication application;
163
164   PinchGestureDetector detector = PinchGestureDetector::New();
165
166   PinchGestureDetector assign;
167   assign = detector;
168   DALI_TEST_CHECK(detector);
169
170   DALI_TEST_CHECK(detector == assign);
171   END_TEST;
172 }
173
174 int UtcDaliPinchGestureDetectorMoveConstructorP(void)
175 {
176   TestApplication application;
177
178   PinchGestureDetector detector = PinchGestureDetector::New();
179   DALI_TEST_CHECK(detector);
180
181   PinchGestureDetector moved = std::move(detector);
182   DALI_TEST_CHECK(moved);
183   DALI_TEST_CHECK(!detector);
184   END_TEST;
185 }
186
187 int UtcDaliPinchGestureDetectorMoveAssignmentOperatorP(void)
188 {
189   TestApplication application;
190
191   PinchGestureDetector detector;
192   detector = PinchGestureDetector::New();
193   DALI_TEST_CHECK(detector);
194
195   PinchGestureDetector moved;
196   moved = std::move(detector);
197   DALI_TEST_CHECK(moved);
198   DALI_TEST_CHECK(!detector);
199   END_TEST;
200 }
201
202 int UtcDaliPinchGestureDetectorNew(void)
203 {
204   TestApplication application;
205
206   PinchGestureDetector detector = PinchGestureDetector::New();
207
208   DALI_TEST_CHECK(detector);
209
210   // Attach an actor and emit a touch event on the actor to ensure complete line coverage
211   Actor actor = Actor::New();
212   actor.SetProperty(Actor::Property::SIZE, Vector2(100.0f, 100.0f));
213   actor.SetProperty(Actor::Property::ANCHOR_POINT, AnchorPoint::TOP_LEFT);
214   application.GetScene().Add(actor);
215
216   // Render and notify
217   application.SendNotification();
218   application.Render();
219
220   detector.Attach(actor);
221
222   Integration::TouchEvent touchEvent(1);
223   Integration::Point      point;
224   point.SetDeviceId(1);
225   point.SetState(PointState::DOWN);
226   point.SetScreenPosition(Vector2(20.0f, 20.0f));
227   touchEvent.AddPoint(point);
228   application.ProcessEvent(touchEvent);
229
230   Integration::Point point2;
231   point.SetDeviceId(1);
232   point.SetState(PointState::DOWN);
233   point.SetScreenPosition(Vector2(20.0f, 20.0f));
234   touchEvent.AddPoint(point2);
235   application.ProcessEvent(touchEvent);
236   END_TEST;
237 }
238
239 int UtcDaliPinchGestureDetectorDownCast(void)
240 {
241   TestApplication application;
242   tet_infoline("Testing Dali::PinchGestureDetector::DownCast()");
243
244   PinchGestureDetector detector = PinchGestureDetector::New();
245
246   BaseHandle object(detector);
247
248   PinchGestureDetector detector2 = PinchGestureDetector::DownCast(object);
249   DALI_TEST_CHECK(detector2);
250
251   PinchGestureDetector detector3 = DownCast<PinchGestureDetector>(object);
252   DALI_TEST_CHECK(detector3);
253
254   BaseHandle           unInitializedObject;
255   PinchGestureDetector detector4 = PinchGestureDetector::DownCast(unInitializedObject);
256   DALI_TEST_CHECK(!detector4);
257
258   PinchGestureDetector detector5 = DownCast<PinchGestureDetector>(unInitializedObject);
259   DALI_TEST_CHECK(!detector5);
260
261   GestureDetector      detector6 = PinchGestureDetector::New();
262   PinchGestureDetector detector7 = PinchGestureDetector::DownCast(detector6);
263   DALI_TEST_CHECK(detector7);
264   END_TEST;
265 }
266
267 // Negative test case for a method
268 int UtcDaliPinchGestureSignalReceptionNegative(void)
269 {
270   TestApplication application;
271
272   Actor actor = Actor::New();
273   actor.SetProperty(Actor::Property::SIZE, Vector2(100.0f, 100.0f));
274   actor.SetProperty(Actor::Property::ANCHOR_POINT, AnchorPoint::TOP_LEFT);
275   application.GetScene().Add(actor);
276
277   // Render and notify
278   application.SendNotification();
279   application.Render();
280
281   SignalData             data;
282   GestureReceivedFunctor functor(data);
283
284   PinchGestureDetector detector = PinchGestureDetector::New();
285   detector.Attach(actor);
286   detector.DetectedSignal().Connect(&application, functor);
287
288   // Do a pinch outside actor's area
289   TestStartPinch(application, Vector2(112.0f, 62.0f), Vector2(112.0f, 162.0f), Vector2(112.0f, 100.0f), Vector2(112.0f, 124.0f), 100);
290
291   DALI_TEST_EQUALS(false, data.functorCalled, TEST_LOCATION);
292
293   // Continue pinch into actor's area - we should still not receive the signal
294   data.Reset();
295   TestContinuePinch(application, Vector2(112.0f, 100.0f), Vector2(112.0f, 124.0f), Vector2(5.0f, 5.0f), Vector2(35.0f, 35.0f), 200);
296
297   DALI_TEST_EQUALS(false, data.functorCalled, TEST_LOCATION);
298
299   // Stop pinching - we should still not receive the signal
300   data.Reset();
301   TestEndPinch(application, Vector2(6.0f, 6.0f), Vector2(18.0f, 18.0f), Vector2(10.0f, 8.0f), Vector2(14.0f, 16.0f), 300);
302
303   DALI_TEST_EQUALS(false, data.functorCalled, TEST_LOCATION);
304   END_TEST;
305 }
306
307 int UtcDaliPinchGestureSignalReceptionDownMotionLeave(void)
308 {
309   TestApplication application;
310
311   Actor actor = Actor::New();
312   actor.SetProperty(Actor::Property::SIZE, Vector2(100.0f, 100.0f));
313   actor.SetProperty(Actor::Property::ANCHOR_POINT, AnchorPoint::TOP_LEFT);
314   application.GetScene().Add(actor);
315
316   // Render and notify
317   application.SendNotification();
318   application.Render();
319
320   SignalData             data;
321   GestureReceivedFunctor functor(data);
322
323   PinchGestureDetector detector = PinchGestureDetector::New();
324   detector.Attach(actor);
325   detector.DetectedSignal().Connect(&application, functor);
326
327   // Start pan within the actor's area
328   TestStartPinch(application, Vector2(5.0f, 20.0f), Vector2(35.0f, 20.0f), Vector2(10.0f, 20.0f), Vector2(30.0f, 20.0f), 100);
329   DALI_TEST_EQUALS(true, data.functorCalled, TEST_LOCATION);
330   DALI_TEST_EQUALS(GestureState::STARTED, data.receivedGesture.GetState(), TEST_LOCATION);
331   DALI_TEST_EQUALS(0.666f, data.receivedGesture.GetScale(), 0.01f, TEST_LOCATION);
332   DALI_TEST_EQUALS(66.666f, data.receivedGesture.GetSpeed(), 0.01f, TEST_LOCATION);
333   DALI_TEST_EQUALS(Vector2(20.0f, 20.0f), data.receivedGesture.GetScreenCenterPoint(), 0.01f, TEST_LOCATION);
334   DALI_TEST_EQUALS(Vector2(20.0f, 20.0f), data.receivedGesture.GetLocalCenterPoint(), 0.01f, TEST_LOCATION);
335
336   // Continue the pan within the actor's area - we should still receive the signal
337   data.Reset();
338   TestContinuePinch(application, Vector2(10.0f, 20.0f), Vector2(30.0f, 20.0f), Vector2(17.0f, 20.0f), Vector2(25.0f, 20.0f), 400);
339   DALI_TEST_EQUALS(true, data.functorCalled, TEST_LOCATION);
340   DALI_TEST_EQUALS(GestureState::CONTINUING, data.receivedGesture.GetState(), TEST_LOCATION);
341   DALI_TEST_EQUALS(0.2666f, data.receivedGesture.GetScale(), 0.01f, TEST_LOCATION);
342   DALI_TEST_EQUALS(80.0f, data.receivedGesture.GetSpeed(), 0.01f, TEST_LOCATION);
343   DALI_TEST_EQUALS(Vector2(21.0f, 20.0f), data.receivedGesture.GetScreenCenterPoint(), 0.01f, TEST_LOCATION);
344   DALI_TEST_EQUALS(Vector2(21.0f, 20.0f), data.receivedGesture.GetLocalCenterPoint(), 0.01f, TEST_LOCATION);
345
346   // Pinch Gesture leaves actor's area - we should still receive the signal
347   data.Reset();
348   TestContinuePinch(application, Vector2(17.0f, 20.0f), Vector2(25.0f, 20.0f), Vector2(300.0f, 10.0f), Vector2(340.0f, 10.0f), 1000);
349   DALI_TEST_EQUALS(true, data.functorCalled, TEST_LOCATION);
350   DALI_TEST_EQUALS(GestureState::CONTINUING, data.receivedGesture.GetState(), TEST_LOCATION);
351   DALI_TEST_EQUALS(1.333f, data.receivedGesture.GetScale(), 0.01f, TEST_LOCATION);
352   DALI_TEST_EQUALS(213.333f, data.receivedGesture.GetSpeed(), 0.01f, TEST_LOCATION);
353   DALI_TEST_EQUALS(Vector2(320.0f, 10.0f), data.receivedGesture.GetScreenCenterPoint(), 0.01f, TEST_LOCATION);
354   DALI_TEST_EQUALS(Vector2(320.0f, 10.0f), data.receivedGesture.GetLocalCenterPoint(), 0.01f, TEST_LOCATION);
355
356   // Gesture ends - we would receive a finished state
357   data.Reset();
358   TestEndPinch(application, Vector2(300.0f, 10.0f), Vector2(340.0f, 10.0f), Vector2(305.0f, 10.0f), Vector2(315.0f, 10.0f), 1500);
359   DALI_TEST_EQUALS(true, data.functorCalled, TEST_LOCATION);
360   DALI_TEST_EQUALS(GestureState::FINISHED, data.receivedGesture.GetState(), TEST_LOCATION);
361   DALI_TEST_EQUALS(0.333f, data.receivedGesture.GetScale(), 0.01f, TEST_LOCATION);
362   DALI_TEST_EQUALS(600.0f, data.receivedGesture.GetSpeed(), 0.01f, TEST_LOCATION);
363   DALI_TEST_EQUALS(Vector2(310.0f, 10.0f), data.receivedGesture.GetScreenCenterPoint(), 0.01f, TEST_LOCATION);
364   DALI_TEST_EQUALS(Vector2(310.0f, 10.0f), data.receivedGesture.GetLocalCenterPoint(), 0.01f, TEST_LOCATION);
365   END_TEST;
366 }
367
368 int UtcDaliPinchGestureSignalReceptionDownMotionUp(void)
369 {
370   TestApplication application;
371
372   Actor actor = Actor::New();
373   actor.SetProperty(Actor::Property::SIZE, Vector2(100.0f, 100.0f));
374   actor.SetProperty(Actor::Property::ANCHOR_POINT, AnchorPoint::TOP_LEFT);
375   application.GetScene().Add(actor);
376
377   // Render and notify
378   application.SendNotification();
379   application.Render();
380
381   SignalData             data;
382   GestureReceivedFunctor functor(data);
383
384   PinchGestureDetector detector = PinchGestureDetector::New();
385   detector.Attach(actor);
386   detector.DetectedSignal().Connect(&application, functor);
387
388   // Start pinch within the actor's area
389   TestStartPinch(application, Vector2(2.0f, 20.0f), Vector2(38.0f, 20.0f), Vector2(10.0f, 20.0f), Vector2(30.0f, 20.0f), 100);
390   DALI_TEST_EQUALS(true, data.functorCalled, TEST_LOCATION);
391   DALI_TEST_EQUALS(GestureState::STARTED, data.receivedGesture.GetState(), TEST_LOCATION);
392   DALI_TEST_EQUALS(0.555f, data.receivedGesture.GetScale(), 0.01f, TEST_LOCATION);
393   DALI_TEST_EQUALS(106.667f, 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
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   DALI_TEST_EQUALS(0.277f, data.receivedGesture.GetScale(), 0.01f, TEST_LOCATION);
403   DALI_TEST_EQUALS(66.666f, data.receivedGesture.GetSpeed(), 0.01f, TEST_LOCATION);
404   DALI_TEST_EQUALS(Vector2(20.0f, 20.0f), data.receivedGesture.GetScreenCenterPoint(), 0.01f, TEST_LOCATION);
405   DALI_TEST_EQUALS(Vector2(20.0f, 20.0f), data.receivedGesture.GetLocalCenterPoint(), 0.01f, TEST_LOCATION);
406
407   // Gesture ends within actor's area - we would receive a finished state
408   data.Reset();
409   TestEndPinch(application, Vector2(15.0f, 20.0f), Vector2(25.0f, 20.0f), Vector2(19.0f, 20.0f), Vector2(21.0f, 20.0f), 1000);
410   DALI_TEST_EQUALS(true, data.functorCalled, TEST_LOCATION);
411   DALI_TEST_EQUALS(GestureState::FINISHED, data.receivedGesture.GetState(), TEST_LOCATION);
412   DALI_TEST_EQUALS(0.055f, data.receivedGesture.GetScale(), 0.01f, TEST_LOCATION);
413   DALI_TEST_EQUALS(160.0f, data.receivedGesture.GetSpeed(), 0.01f, TEST_LOCATION);
414   DALI_TEST_EQUALS(Vector2(20.0f, 20.0f), data.receivedGesture.GetScreenCenterPoint(), 0.01f, TEST_LOCATION);
415   DALI_TEST_EQUALS(Vector2(20.0f, 20.0f), data.receivedGesture.GetLocalCenterPoint(), 0.01f, TEST_LOCATION);
416   END_TEST;
417 }
418
419 int UtcDaliPinchGestureSignalReceptionDetach(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   // Gesture ends within actor's area
451   data.Reset();
452   TestEndPinch(application, Vector2(15.0f, 20.0f), Vector2(25.0f, 20.0f), Vector2(19.0f, 20.0f), Vector2(21.0f, 20.0f), 1000);
453   DALI_TEST_EQUALS(true, data.functorCalled, TEST_LOCATION);
454   DALI_TEST_EQUALS(GestureState::FINISHED, data.receivedGesture.GetState(), TEST_LOCATION);
455
456   // Detach actor
457   detector.DetachAll();
458
459   // Ensure we are no longer signalled
460   data.Reset();
461   TestGeneratePinch(application);
462   DALI_TEST_EQUALS(false, data.functorCalled, TEST_LOCATION);
463   END_TEST;
464 }
465
466 int UtcDaliPinchGestureSignalReceptionDetachWhilePinching(void)
467 {
468   TestApplication application;
469
470   Actor actor = Actor::New();
471   actor.SetProperty(Actor::Property::SIZE, Vector2(100.0f, 100.0f));
472   actor.SetProperty(Actor::Property::ANCHOR_POINT, AnchorPoint::TOP_LEFT);
473   application.GetScene().Add(actor);
474
475   // Render and notify
476   application.SendNotification();
477   application.Render();
478
479   SignalData             data;
480   GestureReceivedFunctor functor(data);
481
482   PinchGestureDetector detector = PinchGestureDetector::New();
483   detector.Attach(actor);
484   detector.DetectedSignal().Connect(&application, functor);
485
486   // Start pinch within the actor's area
487   TestStartPinch(application, Vector2(2.0f, 20.0f), Vector2(38.0f, 20.0f), Vector2(10.0f, 20.0f), Vector2(30.0f, 20.0f), 100);
488   DALI_TEST_EQUALS(true, data.functorCalled, TEST_LOCATION);
489   DALI_TEST_EQUALS(GestureState::STARTED, data.receivedGesture.GetState(), TEST_LOCATION);
490
491   // Continue the pinch within the actor's area - we should still receive the signal
492   data.Reset();
493   TestContinuePinch(application, Vector2(10.0f, 20.0f), Vector2(30.0f, 20.0f), Vector2(15.0f, 20.0f), Vector2(25.0f, 20.0f), 500);
494   DALI_TEST_EQUALS(true, data.functorCalled, TEST_LOCATION);
495   DALI_TEST_EQUALS(GestureState::CONTINUING, data.receivedGesture.GetState(), TEST_LOCATION);
496
497   // Detach actor during the pinch, we should not receive the next event
498   detector.DetachAll();
499
500   // Gesture ends within actor's area
501   data.Reset();
502   TestEndPinch(application, Vector2(15.0f, 20.0f), Vector2(25.0f, 20.0f), Vector2(19.0f, 20.0f), Vector2(21.0f, 20.0f), 1000);
503   DALI_TEST_EQUALS(false, data.functorCalled, TEST_LOCATION);
504   END_TEST;
505 }
506
507 int UtcDaliPinchGestureSignalReceptionActorDestroyedWhilePinching(void)
508 {
509   TestApplication application;
510
511   SignalData             data;
512   GestureReceivedFunctor functor(data);
513
514   PinchGestureDetector detector = PinchGestureDetector::New();
515   detector.DetectedSignal().Connect(&application, functor);
516
517   // Attach a temporary actor to stop detector being removed from PinchGestureProcessor when main actor
518   // is destroyed.
519   Actor tempActor = Actor::New();
520   tempActor.SetProperty(Actor::Property::SIZE, Vector2(100.0f, 100.0f));
521   tempActor.SetProperty(Actor::Property::ANCHOR_POINT, AnchorPoint::BOTTOM_RIGHT);
522   application.GetScene().Add(tempActor);
523   detector.Attach(tempActor);
524
525   // Actor lifetime is scoped
526   {
527     Actor actor = Actor::New();
528     actor.SetProperty(Actor::Property::SIZE, Vector2(100.0f, 100.0f));
529     actor.SetProperty(Actor::Property::ANCHOR_POINT, AnchorPoint::TOP_LEFT);
530     application.GetScene().Add(actor);
531
532     // Render and notify
533     application.SendNotification();
534     application.Render();
535
536     detector.Attach(actor);
537
538     // Start pinch within the actor's area
539     TestStartPinch(application, Vector2(2.0f, 20.0f), Vector2(38.0f, 20.0f), Vector2(10.0f, 20.0f), Vector2(30.0f, 20.0f), 100);
540     DALI_TEST_EQUALS(true, data.functorCalled, TEST_LOCATION);
541     DALI_TEST_EQUALS(GestureState::STARTED, data.receivedGesture.GetState(), TEST_LOCATION);
542
543     // Continue the pinch within the actor's area - we should still receive the signal
544     data.Reset();
545     TestContinuePinch(application, Vector2(10.0f, 20.0f), Vector2(30.0f, 20.0f), Vector2(15.0f, 20.0f), Vector2(25.0f, 20.0f), 500);
546     DALI_TEST_EQUALS(true, data.functorCalled, TEST_LOCATION);
547     DALI_TEST_EQUALS(GestureState::CONTINUING, data.receivedGesture.GetState(), TEST_LOCATION);
548
549     // Remove the actor from stage and reset the data
550     application.GetScene().Remove(actor);
551
552     // Render and notify
553     application.SendNotification();
554     application.Render();
555   }
556
557   // Actor should now have been destroyed
558
559   // Gesture ends within the area where the actor used to be
560   data.Reset();
561   TestEndPinch(application, Vector2(15.0f, 20.0f), Vector2(25.0f, 20.0f), Vector2(19.0f, 20.0f), Vector2(21.0f, 20.0f), 1000);
562   DALI_TEST_EQUALS(false, data.functorCalled, TEST_LOCATION);
563   END_TEST;
564 }
565
566 int UtcDaliPinchGestureSignalReceptionRotatedActor(void)
567 {
568   TestApplication application;
569
570   Actor actor = Actor::New();
571   actor.SetProperty(Actor::Property::SIZE, Vector2(100.0f, 100.0f));
572   actor.SetProperty(Actor::Property::ORIENTATION, Quaternion(Dali::Degree(90.0f), Vector3::ZAXIS));
573   application.GetScene().Add(actor);
574
575   // Render and notify a couple of times
576   application.SendNotification();
577   application.Render();
578
579   SignalData             data;
580   GestureReceivedFunctor functor(data);
581
582   PinchGestureDetector detector = PinchGestureDetector::New();
583   detector.Attach(actor);
584   detector.DetectedSignal().Connect(&application, functor);
585
586   // Do an entire pinch, only check finished value
587   TestStartPinch(application, Vector2(2.0f, 20.0f), Vector2(38.0f, 20.0f), Vector2(10.0f, 20.0f), Vector2(30.0f, 20.0f), 100);
588   data.Reset();
589   TestEndPinch(application, Vector2(15.0f, 20.0f), Vector2(25.0f, 20.0f), Vector2(19.0f, 20.0f), Vector2(21.0f, 20.0f), 1000);
590   DALI_TEST_EQUALS(true, data.functorCalled, TEST_LOCATION);
591   DALI_TEST_EQUALS(0.055f, data.receivedGesture.GetScale(), 0.01f, TEST_LOCATION);
592   DALI_TEST_EQUALS(160.0f, data.receivedGesture.GetSpeed(), 0.01f, TEST_LOCATION);
593   DALI_TEST_EQUALS(Vector2(20.0f, 20.0f), data.receivedGesture.GetScreenCenterPoint(), 0.01f, TEST_LOCATION);
594   DALI_TEST_EQUALS(Vector2(70.0f, 30.0f), data.receivedGesture.GetLocalCenterPoint(), 0.01f, TEST_LOCATION);
595
596   // Rotate actor again and render and notify
597   actor.SetProperty(Actor::Property::ORIENTATION, Quaternion(Dali::Degree(180.0f), Vector3::ZAXIS));
598   application.SendNotification();
599   application.Render();
600
601   // Do an entire pinch, only check finished value
602   TestStartPinch(application, Vector2(2.0f, 20.0f), Vector2(38.0f, 20.0f), Vector2(10.0f, 20.0f), Vector2(30.0f, 20.0f), 2100);
603   data.Reset();
604   TestEndPinch(application, Vector2(15.0f, 20.0f), Vector2(25.0f, 20.0f), Vector2(19.0f, 20.0f), Vector2(21.0f, 20.0f), 3000);
605   DALI_TEST_EQUALS(true, data.functorCalled, TEST_LOCATION);
606   DALI_TEST_EQUALS(0.055f, data.receivedGesture.GetScale(), 0.01f, TEST_LOCATION);
607   DALI_TEST_EQUALS(160.0f, data.receivedGesture.GetSpeed(), 0.01f, TEST_LOCATION);
608   DALI_TEST_EQUALS(Vector2(20.0f, 20.0f), data.receivedGesture.GetScreenCenterPoint(), 0.01f, TEST_LOCATION);
609   DALI_TEST_EQUALS(Vector2(30.0f, 30.0f), data.receivedGesture.GetLocalCenterPoint(), 0.01f, TEST_LOCATION);
610
611   // Rotate actor again and render and notify
612   actor.SetProperty(Actor::Property::ORIENTATION, Quaternion(Dali::Degree(270.0f), Vector3::ZAXIS));
613   application.SendNotification();
614   application.Render();
615
616   // Do an entire pinch, only check finished value
617   TestStartPinch(application, Vector2(2.0f, 20.0f), Vector2(38.0f, 20.0f), Vector2(10.0f, 20.0f), Vector2(30.0f, 20.0f), 4100);
618   data.Reset();
619   TestEndPinch(application, Vector2(15.0f, 20.0f), Vector2(25.0f, 20.0f), Vector2(19.0f, 20.0f), Vector2(21.0f, 20.0f), 5000);
620   DALI_TEST_EQUALS(true, data.functorCalled, TEST_LOCATION);
621   DALI_TEST_EQUALS(0.055f, data.receivedGesture.GetScale(), 0.01f, TEST_LOCATION);
622   DALI_TEST_EQUALS(160.0f, data.receivedGesture.GetSpeed(), 0.01f, TEST_LOCATION);
623   DALI_TEST_EQUALS(Vector2(20.0f, 20.0f), data.receivedGesture.GetScreenCenterPoint(), 0.01f, TEST_LOCATION);
624   DALI_TEST_EQUALS(Vector2(30.0f, 70.0f), data.receivedGesture.GetLocalCenterPoint(), 0.01f, TEST_LOCATION);
625   END_TEST;
626 }
627
628 int UtcDaliPinchGestureSignalReceptionChildHit(void)
629 {
630   TestApplication application;
631
632   Actor parent = Actor::New();
633   parent.SetProperty(Actor::Property::SIZE, Vector2(100.0f, 100.0f));
634   parent.SetProperty(Actor::Property::ANCHOR_POINT, AnchorPoint::TOP_LEFT);
635   application.GetScene().Add(parent);
636
637   // Set child to completely cover parent.
638   // Change rotation of child to be different from parent so that we can check if our local coordinate
639   // conversion of the parent actor is correct.
640   Actor child = Actor::New();
641   child.SetProperty(Actor::Property::SIZE, Vector2(100.0f, 100.0f));
642   child.SetProperty(Actor::Property::ANCHOR_POINT, AnchorPoint::CENTER);
643   child.SetProperty(Actor::Property::PARENT_ORIGIN, ParentOrigin::CENTER);
644   child.SetProperty(Actor::Property::ORIENTATION, Quaternion(Dali::Degree(90.0f), Vector3::ZAXIS));
645   parent.Add(child);
646
647   // Render and notify
648   application.SendNotification();
649   application.Render();
650
651   SignalData             data;
652   GestureReceivedFunctor functor(data);
653
654   PinchGestureDetector detector = PinchGestureDetector::New();
655   detector.Attach(parent);
656   detector.DetectedSignal().Connect(&application, functor);
657
658   // Do an entire pan, only check finished value - hits child area but parent should still receive it
659   TestStartPinch(application, Vector2(2.0f, 20.0f), Vector2(38.0f, 20.0f), Vector2(10.0f, 20.0f), Vector2(30.0f, 20.0f), 100);
660   data.Reset();
661   TestEndPinch(application, Vector2(15.0f, 20.0f), Vector2(25.0f, 20.0f), Vector2(19.0f, 20.0f), Vector2(21.0f, 20.0f), 1000);
662   DALI_TEST_EQUALS(true, data.functorCalled, TEST_LOCATION);
663   DALI_TEST_EQUALS(true, parent == data.pinchedActor, TEST_LOCATION);
664   DALI_TEST_EQUALS(0.055f, data.receivedGesture.GetScale(), 0.01f, TEST_LOCATION);
665   DALI_TEST_EQUALS(160.0f, data.receivedGesture.GetSpeed(), 0.01f, TEST_LOCATION);
666   DALI_TEST_EQUALS(Vector2(20.0f, 20.0f), data.receivedGesture.GetScreenCenterPoint(), 0.01f, TEST_LOCATION);
667
668   // Attach child and generate same touch points to yield same results
669   // (Also proves that you can detach and then re-attach another actor)
670   detector.Attach(child);
671   detector.Detach(parent);
672
673   // Do an entire pan, only check finished value
674   TestStartPinch(application, Vector2(2.0f, 20.0f), Vector2(38.0f, 20.0f), Vector2(10.0f, 20.0f), Vector2(30.0f, 20.0f), 2100);
675   data.Reset();
676   TestEndPinch(application, Vector2(15.0f, 20.0f), Vector2(25.0f, 20.0f), Vector2(19.0f, 20.0f), Vector2(21.0f, 20.0f), 3000);
677   DALI_TEST_EQUALS(true, data.functorCalled, TEST_LOCATION);
678   DALI_TEST_EQUALS(true, child == data.pinchedActor, TEST_LOCATION);
679   DALI_TEST_EQUALS(0.055f, data.receivedGesture.GetScale(), 0.01f, TEST_LOCATION);
680   DALI_TEST_EQUALS(160.0f, data.receivedGesture.GetSpeed(), 0.01f, TEST_LOCATION);
681   DALI_TEST_EQUALS(Vector2(20.0f, 20.0f), data.receivedGesture.GetScreenCenterPoint(), 0.01f, TEST_LOCATION);
682   DALI_TEST_EQUALS(Vector2(20.0f, 80.0f), data.receivedGesture.GetLocalCenterPoint(), 0.01f, TEST_LOCATION);
683   END_TEST;
684 }
685
686 int UtcDaliPinchGestureSignalReceptionAttachDetachMany(void)
687 {
688   TestApplication application;
689
690   Actor first = Actor::New();
691   first.SetProperty(Actor::Property::SIZE, Vector2(100.0f, 100.0f));
692   first.SetProperty(Actor::Property::ANCHOR_POINT, AnchorPoint::TOP_LEFT);
693   application.GetScene().Add(first);
694
695   Actor second = Actor::New();
696   second.SetProperty(Actor::Property::SIZE, Vector2(100.0f, 100.0f));
697   second.SetProperty(Actor::Property::POSITION_X, 100.0f);
698   second.SetProperty(Actor::Property::ANCHOR_POINT, AnchorPoint::TOP_LEFT);
699   application.GetScene().Add(second);
700
701   // Render and notify
702   application.SendNotification();
703   application.Render();
704
705   SignalData             data;
706   GestureReceivedFunctor functor(data);
707
708   PinchGestureDetector detector = PinchGestureDetector::New();
709   detector.Attach(first);
710   detector.Attach(second);
711   detector.DetectedSignal().Connect(&application, functor);
712
713   // Start pinch within second actor's area
714   TestStartPinch(application, Vector2(102.0f, 20.0f), Vector2(138.0f, 20.0f), Vector2(110.0f, 20.0f), Vector2(130.0f, 20.0f), 100);
715   DALI_TEST_EQUALS(true, data.functorCalled, TEST_LOCATION);
716   DALI_TEST_EQUALS(true, second == data.pinchedActor, TEST_LOCATION);
717
718   // Pinch moves into first actor's area - second actor should receive the pinch
719   data.Reset();
720   TestContinuePinch(application, Vector2(110.0f, 20.0f), Vector2(130.0f, 20.0f), Vector2(15.0f, 20.0f), Vector2(25.0f, 20.0f), 500);
721   DALI_TEST_EQUALS(true, data.functorCalled, TEST_LOCATION);
722   DALI_TEST_EQUALS(true, second == data.pinchedActor, TEST_LOCATION);
723
724   // Detach the second actor during the pinch, we should not receive the next event
725   detector.Detach(second);
726
727   // Gesture ends within actor's area
728   data.Reset();
729   TestEndPinch(application, Vector2(15.0f, 20.0f), Vector2(25.0f, 20.0f), Vector2(119.0f, 20.0f), Vector2(121.0f, 20.0f), 3000);
730   DALI_TEST_EQUALS(false, data.functorCalled, TEST_LOCATION);
731   END_TEST;
732 }
733
734 int UtcDaliPinchGestureSignalReceptionActorBecomesUntouchable(void)
735 {
736   TestApplication application;
737
738   Actor actor = Actor::New();
739   actor.SetProperty(Actor::Property::SIZE, Vector2(100.0f, 100.0f));
740   actor.SetProperty(Actor::Property::ANCHOR_POINT, AnchorPoint::TOP_LEFT);
741   application.GetScene().Add(actor);
742
743   // Render and notify
744   application.SendNotification();
745   application.Render();
746
747   SignalData             data;
748   GestureReceivedFunctor functor(data);
749
750   PinchGestureDetector detector = PinchGestureDetector::New();
751   detector.Attach(actor);
752   detector.DetectedSignal().Connect(&application, functor);
753
754   // Start pinch in actor's area
755   TestStartPinch(application, Vector2(2.0f, 20.0f), Vector2(38.0f, 20.0f), Vector2(10.0f, 20.0f), Vector2(30.0f, 20.0f), 100);
756   DALI_TEST_EQUALS(true, data.functorCalled, TEST_LOCATION);
757
758   // Pan continues within actor's area
759   data.Reset();
760   TestContinuePinch(application, Vector2(10.0f, 20.0f), Vector2(30.0f, 20.0f), Vector2(15.0f, 20.0f), Vector2(25.0f, 20.0f), 500);
761   DALI_TEST_EQUALS(true, data.functorCalled, TEST_LOCATION);
762
763   // Actor become invisible - actor should not receive the next pinch
764   actor.SetProperty(Actor::Property::VISIBLE, false);
765
766   // Render and notify
767   application.SendNotification();
768   application.Render();
769
770   // Gesture ends within actor's area
771   data.Reset();
772   TestEndPinch(application, Vector2(15.0f, 20.0f), Vector2(25.0f, 20.0f), Vector2(19.0f, 20.0f), Vector2(21.0f, 20.0f), 3000);
773   DALI_TEST_EQUALS(false, data.functorCalled, TEST_LOCATION);
774   END_TEST;
775 }
776
777 int UtcDaliPinchGestureSignalReceptionMultipleDetectorsOnActor(void)
778 {
779   TestApplication application;
780
781   Actor actor = Actor::New();
782   actor.SetProperty(Actor::Property::SIZE, Vector2(100.0f, 100.0f));
783   actor.SetProperty(Actor::Property::ANCHOR_POINT, AnchorPoint::TOP_LEFT);
784   application.GetScene().Add(actor);
785
786   Actor actor2 = Actor::New();
787   actor2.SetProperty(Actor::Property::SIZE, Vector2(100.0f, 100.0f));
788   actor2.SetProperty(Actor::Property::ANCHOR_POINT, AnchorPoint::BOTTOM_RIGHT);
789   application.GetScene().Add(actor2);
790
791   // Render and notify
792   application.SendNotification();
793   application.Render();
794
795   // Attach actor to one detector
796   SignalData             firstData;
797   GestureReceivedFunctor firstFunctor(firstData);
798   PinchGestureDetector   firstDetector = PinchGestureDetector::New();
799   firstDetector.Attach(actor);
800   firstDetector.DetectedSignal().Connect(&application, firstFunctor);
801
802   // Attach actor to another detector
803   SignalData             secondData;
804   GestureReceivedFunctor secondFunctor(secondData);
805   PinchGestureDetector   secondDetector = PinchGestureDetector::New();
806   secondDetector.Attach(actor);
807   secondDetector.DetectedSignal().Connect(&application, secondFunctor);
808
809   // Add second actor to second detector, when we remove the actor, this will make sure that this
810   // gesture detector is not removed from the GestureDetectorProcessor.  In this scenario, the
811   // functor should still not be called (which is what we're also testing).
812   secondDetector.Attach(actor2);
813
814   // Pinch in actor's area - both detector's functors should be called
815   TestStartPinch(application, Vector2(2.0f, 20.0f), Vector2(38.0f, 20.0f), Vector2(10.0f, 20.0f), Vector2(30.0f, 20.0f), 100);
816   DALI_TEST_EQUALS(true, firstData.functorCalled, TEST_LOCATION);
817   DALI_TEST_EQUALS(true, secondData.functorCalled, TEST_LOCATION);
818
819   // Pinch continues in actor's area - both detector's functors should be called
820   firstData.Reset();
821   secondData.Reset();
822   TestContinuePinch(application, Vector2(10.0f, 20.0f), Vector2(30.0f, 20.0f), Vector2(15.0f, 20.0f), Vector2(25.0f, 20.0f), 500);
823   DALI_TEST_EQUALS(true, firstData.functorCalled, TEST_LOCATION);
824   DALI_TEST_EQUALS(true, secondData.functorCalled, TEST_LOCATION);
825
826   // Detach actor from firstDetector and emit pinch on actor, only secondDetector's functor should be called.
827   firstDetector.Detach(actor);
828   firstData.Reset();
829   secondData.Reset();
830   TestEndPinch(application, Vector2(15.0f, 20.0f), Vector2(25.0f, 20.0f), Vector2(19.0f, 20.0f), Vector2(21.0f, 20.0f), 1000);
831   DALI_TEST_EQUALS(false, firstData.functorCalled, TEST_LOCATION);
832   DALI_TEST_EQUALS(true, secondData.functorCalled, TEST_LOCATION);
833
834   // New pinch on actor, only secondDetector has actor attached
835   firstData.Reset();
836   secondData.Reset();
837   TestStartPinch(application, Vector2(2.0f, 20.0f), Vector2(38.0f, 20.0f), Vector2(10.0f, 20.0f), Vector2(30.0f, 20.0f), 1500);
838   DALI_TEST_EQUALS(false, firstData.functorCalled, TEST_LOCATION);
839   DALI_TEST_EQUALS(true, secondData.functorCalled, TEST_LOCATION);
840
841   // Detach actor from secondDetector
842   secondDetector.Detach(actor);
843   firstData.Reset();
844   secondData.Reset();
845   TestContinuePinch(application, Vector2(10.0f, 20.0f), Vector2(30.0f, 20.0f), Vector2(15.0f, 20.0f), Vector2(25.0f, 20.0f), 2000);
846   DALI_TEST_EQUALS(false, firstData.functorCalled, TEST_LOCATION);
847   DALI_TEST_EQUALS(false, secondData.functorCalled, TEST_LOCATION);
848   END_TEST;
849 }
850
851 int UtcDaliPinchGestureSignalReceptionEnsureCorrectSignalling(void)
852 {
853   TestApplication application;
854
855   Actor actor1 = Actor::New();
856   actor1.SetProperty(Actor::Property::SIZE, Vector2(100.0f, 100.0f));
857   actor1.SetProperty(Actor::Property::ANCHOR_POINT, AnchorPoint::TOP_LEFT);
858   application.GetScene().Add(actor1);
859   SignalData             data1;
860   GestureReceivedFunctor functor1(data1);
861   PinchGestureDetector   detector1 = PinchGestureDetector::New();
862   detector1.Attach(actor1);
863   detector1.DetectedSignal().Connect(&application, functor1);
864
865   Actor actor2 = Actor::New();
866   actor2.SetProperty(Actor::Property::SIZE, Vector2(100.0f, 100.0f));
867   actor2.SetProperty(Actor::Property::ANCHOR_POINT, AnchorPoint::BOTTOM_RIGHT);
868   actor2.SetProperty(Actor::Property::PARENT_ORIGIN, ParentOrigin::BOTTOM_RIGHT);
869   application.GetScene().Add(actor2);
870   SignalData             data2;
871   GestureReceivedFunctor functor2(data2);
872   PinchGestureDetector   detector2 = PinchGestureDetector::New();
873   detector2.Attach(actor2);
874   detector2.DetectedSignal().Connect(&application, functor2);
875
876   // Render and notify
877   application.SendNotification();
878   application.Render();
879
880   // Start pan in actor1's area, only data1 should be set
881   TestStartPinch(application, Vector2(2.0f, 20.0f), Vector2(38.0f, 20.0f), Vector2(10.0f, 20.0f), Vector2(30.0f, 20.0f), 100);
882   DALI_TEST_EQUALS(true, data1.functorCalled, TEST_LOCATION);
883   DALI_TEST_EQUALS(false, data2.functorCalled, TEST_LOCATION);
884   END_TEST;
885 }
886
887 int UtcDaliPinchGestureActorUnstaged(void)
888 {
889   TestApplication application;
890
891   Actor actor = Actor::New();
892   actor.SetProperty(Actor::Property::SIZE, Vector2(100.0f, 100.0f));
893   actor.SetProperty(Actor::Property::ANCHOR_POINT, AnchorPoint::TOP_LEFT);
894   application.GetScene().Add(actor);
895
896   // Render and notify
897   application.SendNotification();
898   application.Render();
899
900   // State to remove actor in.
901   GestureState stateToUnstage(GestureState::STARTED);
902
903   // Attach actor to detector
904   SignalData           data;
905   UnstageActorFunctor  functor(data, stateToUnstage, application.GetScene());
906   PinchGestureDetector detector = PinchGestureDetector::New();
907   detector.Attach(actor);
908   detector.DetectedSignal().Connect(&application, functor);
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   TestEndPinch(application, Vector2(10.0f, 20.0f), Vector2(30.0f, 20.0f), Vector2(19.0f, 20.0f), Vector2(21.0f, 20.0f), 1000);
915   DALI_TEST_EQUALS(false, data.functorCalled, TEST_LOCATION);
916   data.Reset();
917
918   // Render and notify
919   application.SendNotification();
920   application.Render();
921
922   // Re-add actor to stage
923   application.GetScene().Add(actor);
924
925   // Render and notify
926   application.SendNotification();
927   application.Render();
928
929   // Change state to GestureState::CONTINUING to remove
930   stateToUnstage = GestureState::CONTINUING;
931
932   // Emit signals
933   TestStartPinch(application, Vector2(2.0f, 20.0f), Vector2(38.0f, 20.0f), Vector2(10.0f, 20.0f), Vector2(30.0f, 20.0f), 100);
934   DALI_TEST_EQUALS(true, data.functorCalled, TEST_LOCATION);
935   data.Reset();
936   TestContinuePinch(application, Vector2(10.0f, 20.0f), Vector2(30.0f, 20.0f), Vector2(15.0f, 20.0f), Vector2(25.0f, 20.0f), 500);
937   DALI_TEST_EQUALS(true, data.functorCalled, TEST_LOCATION);
938   data.Reset();
939   TestEndPinch(application, Vector2(10.0f, 20.0f), Vector2(30.0f, 20.0f), Vector2(19.0f, 20.0f), Vector2(21.0f, 20.0f), 1000);
940   DALI_TEST_EQUALS(false, data.functorCalled, TEST_LOCATION);
941   data.Reset();
942
943   // Render and notify
944   application.SendNotification();
945   application.Render();
946
947   // Re-add actor to stage
948   application.GetScene().Add(actor);
949
950   // Render and notify
951   application.SendNotification();
952   application.Render();
953
954   // Change state to GestureState::CONTINUING to remove
955   stateToUnstage = GestureState::FINISHED;
956
957   // Emit signals
958   TestStartPinch(application, Vector2(2.0f, 20.0f), Vector2(38.0f, 20.0f), Vector2(10.0f, 20.0f), Vector2(30.0f, 20.0f), 100);
959   DALI_TEST_EQUALS(true, data.functorCalled, TEST_LOCATION);
960   data.Reset();
961   TestContinuePinch(application, Vector2(10.0f, 20.0f), Vector2(30.0f, 20.0f), Vector2(15.0f, 20.0f), Vector2(25.0f, 20.0f), 500);
962   DALI_TEST_EQUALS(true, data.functorCalled, TEST_LOCATION);
963   data.Reset();
964   TestEndPinch(application, Vector2(10.0f, 20.0f), Vector2(30.0f, 20.0f), Vector2(19.0f, 20.0f), Vector2(21.0f, 20.0f), 1000);
965   DALI_TEST_EQUALS(true, data.functorCalled, TEST_LOCATION);
966   tet_result(TET_PASS); // If we get here then we have handled actor stage removal gracefully.
967   END_TEST;
968 }
969
970 int UtcDaliPinchGestureActorStagedAndDestroyed(void)
971 {
972   TestApplication application;
973
974   Actor actor = Actor::New();
975   actor.SetProperty(Actor::Property::SIZE, Vector2(100.0f, 100.0f));
976   actor.SetProperty(Actor::Property::ANCHOR_POINT, AnchorPoint::TOP_LEFT);
977   application.GetScene().Add(actor);
978
979   // Create and add a second actor so that GestureDetector destruction does not come into play.
980   Actor dummyActor(Actor::New());
981   dummyActor.SetProperty(Actor::Property::SIZE, Vector2(100.0f, 100.0f));
982   dummyActor.SetProperty(Actor::Property::POSITION, Vector2(100.0f, 100.0f));
983   dummyActor.SetProperty(Actor::Property::ANCHOR_POINT, AnchorPoint::TOP_LEFT);
984   application.GetScene().Add(dummyActor);
985
986   // Render and notify
987   application.SendNotification();
988   application.Render();
989
990   // State to remove actor in.
991   GestureState stateToUnstage(GestureState::STARTED);
992
993   // Attach actor to detector
994   SignalData           data;
995   UnstageActorFunctor  functor(data, stateToUnstage, application.GetScene());
996   PinchGestureDetector detector = PinchGestureDetector::New();
997   detector.Attach(actor);
998   detector.Attach(dummyActor);
999   detector.DetectedSignal().Connect(&application, functor);
1000
1001   // Here we are testing a STARTED actor which is removed in the STARTED callback, but then added back
1002   // before we get a continuing state.  As we were removed from the stage, even if we're at the same
1003   // position, we should still not be signalled.
1004
1005   // Emit signals
1006   TestStartPinch(application, Vector2(2.0f, 20.0f), Vector2(38.0f, 20.0f), Vector2(10.0f, 20.0f), Vector2(30.0f, 20.0f), 100);
1007   DALI_TEST_EQUALS(true, data.functorCalled, TEST_LOCATION);
1008   data.Reset();
1009
1010   // Render and notify
1011   application.SendNotification();
1012   application.Render();
1013
1014   // Re add to the stage, we should not be signalled
1015   application.GetScene().Add(actor);
1016
1017   // Render and notify
1018   application.SendNotification();
1019   application.Render();
1020
1021   // Continue signal emission
1022   TestContinuePinch(application, Vector2(10.0f, 20.0f), Vector2(30.0f, 20.0f), Vector2(15.0f, 20.0f), Vector2(25.0f, 20.0f), 500);
1023   DALI_TEST_EQUALS(false, data.functorCalled, TEST_LOCATION);
1024   data.Reset();
1025   TestEndPinch(application, Vector2(10.0f, 20.0f), Vector2(30.0f, 20.0f), Vector2(19.0f, 20.0f), Vector2(21.0f, 20.0f), 1000);
1026   DALI_TEST_EQUALS(false, data.functorCalled, TEST_LOCATION);
1027   data.Reset();
1028
1029   // Here we delete an actor in started, we should not receive any subsequent signalling.
1030
1031   // Emit signals
1032   TestStartPinch(application, Vector2(2.0f, 20.0f), Vector2(38.0f, 20.0f), Vector2(10.0f, 20.0f), Vector2(30.0f, 20.0f), 1500);
1033   DALI_TEST_EQUALS(true, data.functorCalled, TEST_LOCATION);
1034   data.Reset();
1035
1036   // Render and notify
1037   application.SendNotification();
1038   application.Render();
1039
1040   // Delete actor as well
1041   actor.Reset();
1042
1043   // Render and notify
1044   application.SendNotification();
1045   application.Render();
1046
1047   // Continue signal emission
1048   TestContinuePinch(application, Vector2(10.0f, 20.0f), Vector2(30.0f, 20.0f), Vector2(15.0f, 20.0f), Vector2(25.0f, 20.0f), 2000);
1049   DALI_TEST_EQUALS(false, data.functorCalled, TEST_LOCATION);
1050   data.Reset();
1051   TestEndPinch(application, Vector2(10.0f, 20.0f), Vector2(30.0f, 20.0f), Vector2(19.0f, 20.0f), Vector2(21.0f, 20.0f), 3000);
1052   DALI_TEST_EQUALS(false, data.functorCalled, TEST_LOCATION);
1053   END_TEST;
1054 }
1055
1056 int UtcDaliPinchGestureLayerConsumesTouch(void)
1057 {
1058   TestApplication application;
1059
1060   Actor actor = Actor::New();
1061   actor.SetProperty(Actor::Property::SIZE, Vector2(100.0f, 100.0f));
1062   actor.SetProperty(Actor::Property::ANCHOR_POINT, AnchorPoint::TOP_LEFT);
1063   application.GetScene().Add(actor);
1064
1065   // Add a detector
1066   SignalData             data;
1067   GestureReceivedFunctor functor(data);
1068   PinchGestureDetector   detector = PinchGestureDetector::New();
1069   detector.Attach(actor);
1070   detector.DetectedSignal().Connect(&application, functor);
1071
1072   // Add a layer to overlap the actor
1073   Layer layer = Layer::New();
1074   layer.SetProperty(Actor::Property::SIZE, Vector2(100.0f, 100.0f));
1075   layer.SetProperty(Actor::Property::ANCHOR_POINT, AnchorPoint::TOP_LEFT);
1076   application.GetScene().Add(layer);
1077   layer.RaiseToTop();
1078
1079   // Render and notify
1080   application.SendNotification();
1081   application.Render();
1082
1083   // Emit signals, should receive
1084   TestStartPinch(application, Vector2(2.0f, 20.0f), Vector2(38.0f, 20.0f), Vector2(10.0f, 20.0f), Vector2(30.0f, 20.0f), 100);
1085   TestEndPinch(application, Vector2(10.0f, 20.0f), Vector2(30.0f, 20.0f), Vector2(19.0f, 20.0f), Vector2(21.0f, 20.0f), 1000);
1086   DALI_TEST_EQUALS(true, data.functorCalled, TEST_LOCATION);
1087   data.Reset();
1088
1089   // Set layer to consume all touch
1090   layer.SetProperty(Layer::Property::CONSUMES_TOUCH, true);
1091
1092   // Render and notify
1093   application.SendNotification();
1094   application.Render();
1095
1096   // Emit the same signals again, should not receive
1097   TestStartPinch(application, Vector2(2.0f, 20.0f), Vector2(38.0f, 20.0f), Vector2(10.0f, 20.0f), Vector2(30.0f, 20.0f), 1500);
1098   TestEndPinch(application, Vector2(10.0f, 20.0f), Vector2(30.0f, 20.0f), Vector2(19.0f, 20.0f), Vector2(21.0f, 20.0f), 2000);
1099   DALI_TEST_EQUALS(false, data.functorCalled, TEST_LOCATION);
1100   data.Reset();
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 }
1151
1152 int UtcDaliPinchGestureWhenGesturePropargation(void)
1153 {
1154   TestApplication application;
1155
1156   Actor parentActor = Actor::New();
1157   parentActor.SetProperty(Actor::Property::SIZE, Vector2(100.0f, 100.0f));
1158   parentActor.SetProperty(Actor::Property::ANCHOR_POINT, AnchorPoint::TOP_LEFT);
1159
1160   Actor childActor = Actor::New();
1161   childActor.SetProperty(Actor::Property::SIZE, Vector2(100.0f, 100.0f));
1162   childActor.SetProperty(Actor::Property::ANCHOR_POINT, AnchorPoint::TOP_LEFT);
1163
1164   parentActor.Add(childActor);
1165   application.GetScene().Add(parentActor);
1166
1167   // Render and notify
1168   application.SendNotification();
1169   application.Render();
1170
1171   SignalData             pData;
1172   GestureReceivedFunctor pFunctor(pData);
1173
1174   PinchGestureDetector parentDetector = PinchGestureDetector::New();
1175   parentDetector.Attach(parentActor);
1176   parentDetector.DetectedSignal().Connect(&application, pFunctor);
1177
1178   SignalData             cData;
1179   GestureReceivedFunctor cFunctor(cData);
1180
1181   PinchGestureDetector childDetector = PinchGestureDetector::New();
1182   childDetector.Attach(childActor);
1183   childDetector.DetectedSignal().Connect(&application, cFunctor);
1184
1185   // Start gesture within the actor's area, we receive the gesture not parent actor but child actor.
1186   TestStartPinch(application, Vector2(2.0f, 20.0f), Vector2(38.0f, 20.0f), Vector2(10.0f, 20.0f), Vector2(30.0f, 20.0f), 100);
1187   DALI_TEST_EQUALS(true, cData.functorCalled, TEST_LOCATION);
1188   DALI_TEST_EQUALS(false, pData.functorCalled, TEST_LOCATION);
1189   cData.Reset();
1190   pData.Reset();
1191
1192   TestContinuePinch(application, Vector2(112.0f, 100.0f), Vector2(112.0f, 124.0f), Vector2(5.0f, 5.0f), Vector2(35.0f, 35.0f), 200);
1193   DALI_TEST_EQUALS(true, cData.functorCalled, TEST_LOCATION);
1194   DALI_TEST_EQUALS(false, pData.functorCalled, TEST_LOCATION);
1195   cData.Reset();
1196   pData.Reset();
1197
1198   TestEndPinch(application, Vector2(15.0f, 20.0f), Vector2(25.0f, 20.0f), Vector2(19.0f, 20.0f), Vector2(21.0f, 20.0f), 300);
1199   DALI_TEST_EQUALS(true, cData.functorCalled, TEST_LOCATION);
1200   DALI_TEST_EQUALS(false, pData.functorCalled, TEST_LOCATION);
1201   cData.Reset();
1202   pData.Reset();
1203
1204   // If GesturePropargation is set, a gesture event is to pass over to the parent.
1205   Dali::DevelActor::SetNeedGesturePropagation(childActor, true);
1206
1207   // So now the parent got the gesture event.
1208   TestStartPinch(application, Vector2(2.0f, 20.0f), Vector2(38.0f, 20.0f), Vector2(10.0f, 20.0f), Vector2(30.0f, 20.0f), 700);
1209   DALI_TEST_EQUALS(true, cData.functorCalled, TEST_LOCATION);
1210   DALI_TEST_EQUALS(true, pData.functorCalled, TEST_LOCATION);
1211   cData.Reset();
1212   pData.Reset();
1213
1214   // child does not receive gestures. This is because we have passed the permission of the gesture to the parent.
1215   TestContinuePinch(application, Vector2(112.0f, 100.0f), Vector2(112.0f, 124.0f), Vector2(5.0f, 5.0f), Vector2(35.0f, 35.0f), 800);
1216   DALI_TEST_EQUALS(false, cData.functorCalled, TEST_LOCATION);
1217   DALI_TEST_EQUALS(true, pData.functorCalled, TEST_LOCATION);
1218   cData.Reset();
1219   pData.Reset();
1220
1221   TestEndPinch(application, Vector2(15.0f, 20.0f), Vector2(25.0f, 20.0f), Vector2(19.0f, 20.0f), Vector2(21.0f, 20.0f), 900);
1222   DALI_TEST_EQUALS(false, cData.functorCalled, TEST_LOCATION);
1223   DALI_TEST_EQUALS(true, pData.functorCalled, TEST_LOCATION);
1224   cData.Reset();
1225   pData.Reset();
1226
1227   END_TEST;
1228 }
1229
1230 int UtcDaliPinchGestureSignalReceptionWithGeometryHittest(void)
1231 {
1232   TestApplication application;
1233   application.GetScene().SetGeometryHittestEnabled(true);
1234
1235   Actor actor = Actor::New();
1236   actor.SetProperty(Actor::Property::SIZE, Vector2(100.0f, 100.0f));
1237   actor.SetProperty(Actor::Property::ANCHOR_POINT, AnchorPoint::TOP_LEFT);
1238   application.GetScene().Add(actor);
1239
1240   // Render and notify
1241   application.SendNotification();
1242   application.Render();
1243
1244   SignalData             data;
1245   GestureReceivedFunctor functor(data);
1246
1247   PinchGestureDetector detector = PinchGestureDetector::New();
1248   detector.Attach(actor);
1249   detector.DetectedSignal().Connect(&application, functor);
1250
1251   // Start pinch within the actor's area
1252   TestStartPinch(application, Vector2(2.0f, 20.0f), Vector2(38.0f, 20.0f), Vector2(10.0f, 20.0f), Vector2(30.0f, 20.0f), 100);
1253   DALI_TEST_EQUALS(true, data.functorCalled, TEST_LOCATION);
1254   DALI_TEST_EQUALS(GestureState::STARTED, data.receivedGesture.GetState(), TEST_LOCATION);
1255
1256   // Continue the pinch within the actor's area - we should still receive the signal
1257   data.Reset();
1258   TestContinuePinch(application, Vector2(10.0f, 20.0f), Vector2(30.0f, 20.0f), Vector2(15.0f, 20.0f), Vector2(25.0f, 20.0f), 500);
1259   DALI_TEST_EQUALS(true, data.functorCalled, TEST_LOCATION);
1260   DALI_TEST_EQUALS(GestureState::CONTINUING, data.receivedGesture.GetState(), TEST_LOCATION);
1261
1262   // Gesture ends within actor's area
1263   data.Reset();
1264   TestEndPinch(application, Vector2(15.0f, 20.0f), Vector2(25.0f, 20.0f), Vector2(19.0f, 20.0f), Vector2(21.0f, 20.0f), 1000);
1265   DALI_TEST_EQUALS(true, data.functorCalled, TEST_LOCATION);
1266   DALI_TEST_EQUALS(GestureState::FINISHED, data.receivedGesture.GetState(), TEST_LOCATION);
1267
1268   // Detach actor
1269   detector.DetachAll();
1270
1271   // Ensure we are no longer signalled
1272   data.Reset();
1273   TestGeneratePinch(application);
1274   DALI_TEST_EQUALS(false, data.functorCalled, TEST_LOCATION);
1275   END_TEST;
1276 }
1277
1278 int UtcDaliPinchGestureHandleEvent(void)
1279 {
1280   TestApplication application;
1281   Integration::Scene scene     = application.GetScene();
1282   RenderTaskList   taskList  = scene.GetRenderTaskList();
1283   Dali::RenderTask task      = taskList.GetTask(0);
1284
1285   Actor parentActor = Actor::New();
1286   parentActor.SetProperty(Actor::Property::SIZE, Vector2(100.0f, 100.0f));
1287   parentActor.SetProperty(Actor::Property::ANCHOR_POINT, AnchorPoint::TOP_LEFT);
1288
1289   Actor childActor = Actor::New();
1290   childActor.SetProperty(Actor::Property::SIZE, Vector2(100.0f, 100.0f));
1291   childActor.SetProperty(Actor::Property::ANCHOR_POINT, AnchorPoint::TOP_LEFT);
1292
1293   parentActor.Add(childActor);
1294   application.GetScene().Add(parentActor);
1295
1296   // Render and notify
1297   application.SendNotification();
1298   application.Render();
1299
1300   SignalData             pData;
1301   GestureReceivedFunctor pFunctor(pData);
1302
1303   PinchGestureDetector parentDetector = PinchGestureDetector::New();
1304   parentDetector.DetectedSignal().Connect(&application, pFunctor);
1305
1306   Integration::TouchEvent tp = GenerateDoubleTouch(PointState::DOWN, Vector2(2.0f, 20.0f), PointState::DOWN, Vector2(38.0f, 20.0f), 100);
1307   Internal::TouchEventPtr touchEventImpl(new Internal::TouchEvent(100));
1308   touchEventImpl->AddPoint(tp.GetPoint(0));
1309   touchEventImpl->AddPoint(tp.GetPoint(1));
1310   touchEventImpl->SetRenderTask(task);
1311   Dali::TouchEvent touchEventHandle(touchEventImpl.Get());
1312   parentDetector.HandleEvent(parentActor, touchEventHandle);
1313
1314   tp = GenerateDoubleTouch(PointState::MOTION, Vector2(10.0f, 20.0f), PointState::MOTION, Vector2(30.0f, 20.0f), 150);
1315   touchEventImpl = new Internal::TouchEvent(150);
1316   touchEventImpl->AddPoint(tp.GetPoint(0));
1317   touchEventImpl->AddPoint(tp.GetPoint(1));
1318   touchEventImpl->SetRenderTask(task);
1319   touchEventHandle = Dali::TouchEvent(touchEventImpl.Get());
1320   parentDetector.HandleEvent(parentActor, touchEventHandle);
1321
1322   tp = GenerateDoubleTouch(PointState::MOTION, Vector2(10.0f, 20.0f), PointState::MOTION, Vector2(30.0f, 20.0f), 200);
1323   touchEventImpl = new Internal::TouchEvent(200);
1324   touchEventImpl->AddPoint(tp.GetPoint(0));
1325   touchEventImpl->AddPoint(tp.GetPoint(1));
1326   touchEventImpl->SetRenderTask(task);
1327   touchEventHandle = Dali::TouchEvent(touchEventImpl.Get());
1328   parentDetector.HandleEvent(parentActor, touchEventHandle);
1329
1330   tp = GenerateDoubleTouch(PointState::MOTION, Vector2(10.0f, 20.0f), PointState::MOTION, Vector2(30.0f, 20.0f), 250);
1331   touchEventImpl = new Internal::TouchEvent(250);
1332   touchEventImpl->AddPoint(tp.GetPoint(0));
1333   touchEventImpl->AddPoint(tp.GetPoint(1));
1334   touchEventImpl->SetRenderTask(task);
1335   touchEventHandle = Dali::TouchEvent(touchEventImpl.Get());
1336   parentDetector.HandleEvent(parentActor, touchEventHandle);
1337
1338   tp = GenerateDoubleTouch(PointState::MOTION, Vector2(10.0f, 20.0f), PointState::MOTION, Vector2(30.0f, 20.0f), 300);
1339   touchEventImpl = new Internal::TouchEvent(300);
1340   touchEventImpl->AddPoint(tp.GetPoint(0));
1341   touchEventImpl->AddPoint(tp.GetPoint(1));
1342   touchEventImpl->SetRenderTask(task);
1343   touchEventHandle = Dali::TouchEvent(touchEventImpl.Get());
1344   parentDetector.HandleEvent(parentActor, touchEventHandle);
1345
1346   tp = GenerateDoubleTouch(PointState::UP, Vector2(10.0f, 20.0f), PointState::UP, Vector2(30.0f, 20.0f), 350);
1347   touchEventImpl = new Internal::TouchEvent(350);
1348   touchEventImpl->AddPoint(tp.GetPoint(0));
1349   touchEventImpl->AddPoint(tp.GetPoint(1));
1350   touchEventImpl->SetRenderTask(task);
1351   touchEventHandle = Dali::TouchEvent(touchEventImpl.Get());
1352   parentDetector.HandleEvent(parentActor, touchEventHandle);
1353
1354
1355   DALI_TEST_EQUALS(true, pData.functorCalled, TEST_LOCATION);
1356   pData.Reset();
1357
1358   END_TEST;
1359 }