(Gestures) Each actor is now aware of what gestures it requires which is used when...
[platform/core/uifw/dali-core.git] / automated-tests / src / dali / utc-Dali-PinchGestureDetector.cpp
1 //
2 // Copyright (c) 2014 Samsung Electronics Co., Ltd.
3 //
4 // Licensed under the Flora License, Version 1.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://floralicense.org/license/
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 #include <iostream>
18
19 #include <stdlib.h>
20 #include <dali/dali.h>
21 #include <dali/integration-api/events/touch-event-integ.h>
22 #include <dali/integration-api/events/pinch-gesture-event.h>
23 #include <dali/integration-api/system-overlay.h>
24 #include <dali-test-suite-utils.h>
25 #include <test-touch-utils.h>
26
27 using namespace Dali;
28
29 void utc_dali_pinch_gesture_detector_startup(void)
30 {
31   test_return_value = TET_UNDEF;
32 }
33
34 void utc_dali_pinch_gesture_detector_cleanup(void)
35 {
36   test_return_value = TET_PASS;
37 }
38
39 ///////////////////////////////////////////////////////////////////////////////
40 namespace
41 {
42
43 // Stores data that is populated in the callback and will be read by the TET cases
44 struct SignalData
45 {
46   SignalData()
47   : functorCalled(false),
48     voidFunctorCalled(false),
49     receivedGesture(Gesture::Started)
50   {}
51
52   void Reset()
53   {
54     functorCalled = false;
55     voidFunctorCalled = false;
56
57     receivedGesture.state = Gesture::Started;
58     receivedGesture.scale = 0.0f;
59     receivedGesture.speed = 0.0f;
60     receivedGesture.screenCenterPoint = Vector2(0.0f, 0.0f);
61     receivedGesture.localCenterPoint = Vector2(0.0f, 0.0f);
62
63     pinchedActor = NULL;
64   }
65
66   bool functorCalled;
67   bool voidFunctorCalled;
68   PinchGesture receivedGesture;
69   Actor pinchedActor;
70 };
71
72 // Functor that sets the data when called
73 struct GestureReceivedFunctor
74 {
75   GestureReceivedFunctor(SignalData& data) : signalData(data) { }
76
77   void operator()(Actor actor, PinchGesture pinch)
78   {
79     signalData.functorCalled = true;
80     signalData.receivedGesture = pinch;
81     signalData.pinchedActor = actor;
82   }
83
84   void operator()()
85   {
86     signalData.voidFunctorCalled = true;
87   }
88
89   SignalData& signalData;
90 };
91
92 // Functor that removes the gestured actor from stage
93 struct UnstageActorFunctor : public GestureReceivedFunctor
94 {
95   UnstageActorFunctor( SignalData& data, Gesture::State& stateToUnstage )
96   : GestureReceivedFunctor( data ),
97     stateToUnstage( stateToUnstage )
98   {
99   }
100
101   void operator()( Actor actor, PinchGesture pinch )
102   {
103     GestureReceivedFunctor::operator()( actor, pinch );
104
105     if ( pinch.state == stateToUnstage )
106     {
107       Stage::GetCurrent().Remove( actor );
108     }
109   }
110
111   Gesture::State& stateToUnstage;
112 };
113
114 // Functor for receiving a touch event
115 struct TouchEventFunctor
116 {
117   bool operator()(Actor actor, const TouchEvent& touch)
118   {
119     return false;
120   }
121 };
122
123 // Generate a PinchGestureEvent to send to Core
124 Integration::PinchGestureEvent GeneratePinch(
125     Gesture::State state,
126     float scale,
127     float speed,
128     Vector2 centerpoint)
129 {
130   Integration::PinchGestureEvent pinch(state);
131
132   pinch.scale = scale;
133   pinch.speed = speed;
134   pinch.centerPoint = centerpoint;
135
136   return pinch;
137 }
138
139 } // anon namespace
140
141 ///////////////////////////////////////////////////////////////////////////////
142
143 int UtcDaliPinchGestureDetectorConstructor(void)
144 {
145   TestApplication application;
146
147   PinchGestureDetector detector;
148   DALI_TEST_CHECK(!detector);
149   END_TEST;
150 }
151
152 int UtcDaliPinchGestureDetectorNew(void)
153 {
154   TestApplication application;
155
156   PinchGestureDetector detector = PinchGestureDetector::New();
157
158   DALI_TEST_CHECK(detector);
159
160   // Attach an actor and emit a touch event on the actor to ensure complete line coverage
161   Actor actor = Actor::New();
162   actor.SetSize(100.0f, 100.0f);
163   actor.SetAnchorPoint(AnchorPoint::TOP_LEFT);
164   Stage::GetCurrent().Add(actor);
165
166   // Render and notify
167   application.SendNotification();
168   application.Render();
169
170   detector.Attach(actor);
171
172   Integration::TouchEvent touchEvent(1);
173   TouchPoint point(1, TouchPoint::Down, 20.0f, 20.0f);
174   touchEvent.AddPoint(point);
175   application.ProcessEvent(touchEvent);
176
177   TouchPoint point2(1, TouchPoint::Down, 20.0f, 20.0f, 20.0f, 20.0f);
178   touchEvent.AddPoint(point2);
179   application.ProcessEvent(touchEvent);
180   END_TEST;
181 }
182
183 int UtcDaliPinchGestureDetectorDownCast(void)
184 {
185   TestApplication application;
186   tet_infoline("Testing Dali::PinchGestureDetector::DownCast()");
187
188   PinchGestureDetector detector = PinchGestureDetector::New();
189
190   BaseHandle object(detector);
191
192   PinchGestureDetector detector2 = PinchGestureDetector::DownCast(object);
193   DALI_TEST_CHECK(detector2);
194
195   PinchGestureDetector detector3 = DownCast< PinchGestureDetector >(object);
196   DALI_TEST_CHECK(detector3);
197
198   BaseHandle unInitializedObject;
199   PinchGestureDetector detector4 = PinchGestureDetector::DownCast(unInitializedObject);
200   DALI_TEST_CHECK(!detector4);
201
202   PinchGestureDetector detector5 = DownCast< PinchGestureDetector >(unInitializedObject);
203   DALI_TEST_CHECK(!detector5);
204
205   GestureDetector detector6 = PinchGestureDetector::New();
206   PinchGestureDetector detector7 = PinchGestureDetector::DownCast(detector6);
207   DALI_TEST_CHECK(detector7);
208   END_TEST;
209 }
210
211 // Negative test case for a method
212 int UtcDaliPinchGestureSignalReceptionNegative(void)
213 {
214   TestApplication application;
215
216   Actor actor = Actor::New();
217   actor.SetSize(100.0f, 100.0f);
218   actor.SetAnchorPoint(AnchorPoint::TOP_LEFT);
219   Stage::GetCurrent().Add(actor);
220
221   // Render and notify
222   application.SendNotification();
223   application.Render();
224
225   SignalData data;
226   GestureReceivedFunctor functor(data);
227
228   PinchGestureDetector detector = PinchGestureDetector::New();
229   detector.Attach(actor);
230   detector.DetectedSignal().Connect(&application, functor);
231
232   // Do a pinch outside actor's area
233   application.ProcessEvent(GeneratePinch(Gesture::Started, 10.0f, 45.0f, Vector2(112.0f, 112.0f)));
234   DALI_TEST_EQUALS(false, data.functorCalled, TEST_LOCATION);
235
236   // Continue pinch into actor's area - we should still not receive the signal
237   data.Reset();
238   application.ProcessEvent(GeneratePinch(Gesture::Continuing, 4.5f, 95.0f, Vector2(20.0f, 20.0f)));
239   DALI_TEST_EQUALS(false, data.functorCalled, TEST_LOCATION);
240
241   // Stop pinching - we should still not receive the signal
242   data.Reset();
243   application.ProcessEvent(GeneratePinch(Gesture::Finished, 10.0f, 50.0f, Vector2(12.0f, 12.0f)));
244   DALI_TEST_EQUALS(false, data.functorCalled, TEST_LOCATION);
245   END_TEST;
246 }
247
248 int UtcDaliPinchGestureSignalReceptionDownMotionLeave(void)
249 {
250   TestApplication application;
251
252   Actor actor = Actor::New();
253   actor.SetSize(100.0f, 100.0f);
254   actor.SetAnchorPoint(AnchorPoint::TOP_LEFT);
255   Stage::GetCurrent().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   // Start pan within the actor's area
269   application.ProcessEvent(GeneratePinch(Gesture::Started, 10.0f, 50.0f, Vector2(20.0f, 20.0f)));
270   DALI_TEST_EQUALS(true, data.functorCalled, TEST_LOCATION);
271   DALI_TEST_EQUALS(Gesture::Started, data.receivedGesture.state, TEST_LOCATION);
272   DALI_TEST_EQUALS(10.0f, data.receivedGesture.scale, 0.01f, TEST_LOCATION);
273   DALI_TEST_EQUALS(50.0f, data.receivedGesture.speed, 0.01f, TEST_LOCATION);
274   DALI_TEST_EQUALS(Vector2(20.0f, 20.0f), data.receivedGesture.screenCenterPoint, 0.01f, TEST_LOCATION);
275
276   // Continue the pan within the actor's area - we should still receive the signal
277   data.Reset();
278   application.ProcessEvent(GeneratePinch(Gesture::Continuing, 5.0f, 90.0f, Vector2(21.0f, 20.0f)));
279   DALI_TEST_EQUALS(true, data.functorCalled, TEST_LOCATION);
280   DALI_TEST_EQUALS(Gesture::Continuing, data.receivedGesture.state, TEST_LOCATION);
281   DALI_TEST_EQUALS(5.0f, data.receivedGesture.scale, 0.01f, TEST_LOCATION);
282   DALI_TEST_EQUALS(90.0f, data.receivedGesture.speed, 0.01f, TEST_LOCATION);
283   DALI_TEST_EQUALS(Vector2(21.0f, 20.0f), data.receivedGesture.screenCenterPoint, 0.01f, TEST_LOCATION);
284
285   // Pan Gesture leaves actor's area - we should still receive the signal
286   data.Reset();
287   application.ProcessEvent(GeneratePinch(Gesture::Continuing, 10.0f, 15.5f, Vector2(320.0f, 10.0f)));
288   DALI_TEST_EQUALS(true, data.functorCalled, TEST_LOCATION);
289   DALI_TEST_EQUALS(Gesture::Continuing, data.receivedGesture.state, TEST_LOCATION);
290   DALI_TEST_EQUALS(10.0f, data.receivedGesture.scale, 0.01f, TEST_LOCATION);
291   DALI_TEST_EQUALS(15.5f, data.receivedGesture.speed, 0.01f, TEST_LOCATION);
292   DALI_TEST_EQUALS(Vector2(320.0f, 10.0f), data.receivedGesture.screenCenterPoint, 0.01f, TEST_LOCATION);
293
294   // Gesture ends - we would receive a finished state
295   data.Reset();
296   application.ProcessEvent(GeneratePinch(Gesture::Finished, 15.2f, 12.1f, Vector2(310.0f, 10.0f)));
297   DALI_TEST_EQUALS(true, data.functorCalled, TEST_LOCATION);
298   DALI_TEST_EQUALS(Gesture::Finished, data.receivedGesture.state, TEST_LOCATION);
299   DALI_TEST_EQUALS(15.2f, data.receivedGesture.scale, 0.01f, TEST_LOCATION);
300   DALI_TEST_EQUALS(12.1f, data.receivedGesture.speed, 0.01f, TEST_LOCATION);
301   DALI_TEST_EQUALS(Vector2(310.0f, 10.0f), data.receivedGesture.screenCenterPoint, 0.01f, TEST_LOCATION);
302   END_TEST;
303 }
304
305 int UtcDaliPinchGestureSignalReceptionDownMotionUp(void)
306 {
307   TestApplication application;
308
309   Actor actor = Actor::New();
310   actor.SetSize(100.0f, 100.0f);
311   actor.SetAnchorPoint(AnchorPoint::TOP_LEFT);
312   Stage::GetCurrent().Add(actor);
313
314   // Render and notify
315   application.SendNotification();
316   application.Render();
317
318   SignalData data;
319   GestureReceivedFunctor functor(data);
320
321   PinchGestureDetector detector = PinchGestureDetector::New();
322   detector.Attach(actor);
323   detector.DetectedSignal().Connect(&application, functor);
324
325   // Start pinch within the actor's area
326   application.ProcessEvent(GeneratePinch(Gesture::Started, 10.0f, 50.0f, Vector2(20.0f, 20.0f)));
327   DALI_TEST_EQUALS(true, data.functorCalled, TEST_LOCATION);
328   DALI_TEST_EQUALS(Gesture::Started, data.receivedGesture.state, TEST_LOCATION);
329   DALI_TEST_EQUALS(10.0f, data.receivedGesture.scale, 0.01f, TEST_LOCATION);
330   DALI_TEST_EQUALS(50.0f, data.receivedGesture.speed, 0.01f, TEST_LOCATION);
331   DALI_TEST_EQUALS(Vector2(20.0f, 20.0f), data.receivedGesture.screenCenterPoint, 0.01f, TEST_LOCATION);
332
333   // Continue the pinch within the actor's area - we should still receive the signal
334   data.Reset();
335   application.ProcessEvent(GeneratePinch(Gesture::Continuing, 5.0f, 25.0f, Vector2(20.0f, 20.0f)));
336   DALI_TEST_EQUALS(true, data.functorCalled, TEST_LOCATION);
337   DALI_TEST_EQUALS(Gesture::Continuing, data.receivedGesture.state, TEST_LOCATION);
338   DALI_TEST_EQUALS(5.0f, data.receivedGesture.scale, 0.01f, TEST_LOCATION);
339   DALI_TEST_EQUALS(25.0f, data.receivedGesture.speed, 0.01f, TEST_LOCATION);
340   DALI_TEST_EQUALS(Vector2(20.0f, 20.0f), data.receivedGesture.screenCenterPoint, 0.01f, TEST_LOCATION);
341
342   // Gesture ends within actor's area - we would receive a finished state
343   data.Reset();
344   application.ProcessEvent(GeneratePinch(Gesture::Finished, 5.0f, 25.0f, Vector2(20.0f, 20.0f)));
345   DALI_TEST_EQUALS(true, data.functorCalled, TEST_LOCATION);
346   DALI_TEST_EQUALS(Gesture::Finished, data.receivedGesture.state, TEST_LOCATION);
347   DALI_TEST_EQUALS(5.0f, data.receivedGesture.scale, 0.01f, TEST_LOCATION);
348   DALI_TEST_EQUALS(25.0f, data.receivedGesture.speed, 0.01f, TEST_LOCATION);
349   DALI_TEST_EQUALS(Vector2(20.0f, 20.0f), data.receivedGesture.screenCenterPoint, 0.01f, TEST_LOCATION);
350   END_TEST;
351 }
352
353 int UtcDaliPinchGestureSignalReceptionCancelled(void)
354 {
355   TestApplication application;
356
357   Actor actor = Actor::New();
358   actor.SetSize(100.0f, 100.0f);
359   actor.SetAnchorPoint(AnchorPoint::TOP_LEFT);
360   Stage::GetCurrent().Add(actor);
361
362   // Render and notify
363   application.SendNotification();
364   application.Render();
365
366   SignalData data;
367   GestureReceivedFunctor functor(data);
368
369   PinchGestureDetector detector = PinchGestureDetector::New();
370   detector.Attach(actor);
371   detector.DetectedSignal().Connect(&application, functor);
372
373   // Start pinch within the actor's area
374   application.ProcessEvent(GeneratePinch(Gesture::Started, 10.0f, 50.0f, Vector2(20.0f, 20.0f)));
375   DALI_TEST_EQUALS(true, data.functorCalled, TEST_LOCATION);
376   DALI_TEST_EQUALS(Gesture::Started, data.receivedGesture.state, TEST_LOCATION);
377
378
379   // Continue the pinch within the actor's area - we should still receive the signal
380   data.Reset();
381   application.ProcessEvent(GeneratePinch(Gesture::Continuing, 5.0f, 25.0f, Vector2(20.0f, 20.0f)));
382   DALI_TEST_EQUALS(true, data.functorCalled, TEST_LOCATION);
383   DALI_TEST_EQUALS(Gesture::Continuing, data.receivedGesture.state, TEST_LOCATION);
384
385   // The gesture is cancelled
386   data.Reset();
387   application.ProcessEvent(GeneratePinch(Gesture::Cancelled, 5.0f, 25.0f, Vector2(20.0f, 20.0f)));
388   DALI_TEST_EQUALS(true, data.functorCalled, TEST_LOCATION);
389   DALI_TEST_EQUALS(Gesture::Cancelled, data.receivedGesture.state, TEST_LOCATION);
390   END_TEST;
391 }
392
393 int UtcDaliPinchGestureSignalReceptionDetach(void)
394 {
395   TestApplication application;
396
397   Actor actor = Actor::New();
398   actor.SetSize(100.0f, 100.0f);
399   actor.SetAnchorPoint(AnchorPoint::TOP_LEFT);
400   Stage::GetCurrent().Add(actor);
401
402   // Render and notify
403   application.SendNotification();
404   application.Render();
405
406   SignalData data;
407   GestureReceivedFunctor functor(data);
408
409   PinchGestureDetector detector = PinchGestureDetector::New();
410   detector.Attach(actor);
411   detector.DetectedSignal().Connect(&application, functor);
412
413   // Start pinch within the actor's area
414   application.ProcessEvent(GeneratePinch(Gesture::Started, 10.0f, 50.0f, Vector2(20.0f, 20.0f)));
415   DALI_TEST_EQUALS(true, data.functorCalled, TEST_LOCATION);
416   DALI_TEST_EQUALS(Gesture::Started, data.receivedGesture.state, TEST_LOCATION);
417
418
419   // Continue the pinch within the actor's area - we should still receive the signal
420   data.Reset();
421   application.ProcessEvent(GeneratePinch(Gesture::Continuing, 5.0f, 25.0f, Vector2(20.0f, 20.0f)));
422   DALI_TEST_EQUALS(true, data.functorCalled, TEST_LOCATION);
423   DALI_TEST_EQUALS(Gesture::Continuing, data.receivedGesture.state, TEST_LOCATION);
424
425   // Gesture ends within actor's area
426   data.Reset();
427   application.ProcessEvent(GeneratePinch(Gesture::Finished, 5.0f, 25.0f, Vector2(20.0f, 20.0f)));
428   DALI_TEST_EQUALS(true, data.functorCalled, TEST_LOCATION);
429   DALI_TEST_EQUALS(Gesture::Finished, data.receivedGesture.state, TEST_LOCATION);
430
431   // Detach actor
432   detector.DetachAll();
433
434   // Ensure we are no longer signalled
435   data.Reset();
436   application.ProcessEvent(GeneratePinch(Gesture::Started, 10.0f, 50.0f, Vector2(20.0f, 20.0f)));
437   application.ProcessEvent(GeneratePinch(Gesture::Continuing, 5.0f, 25.0f, Vector2(20.0f, 20.0f)));
438   application.ProcessEvent(GeneratePinch(Gesture::Finished, 5.0f, 25.0f, Vector2(20.0f, 20.0f)));
439   DALI_TEST_EQUALS(false, data.functorCalled, TEST_LOCATION);
440   END_TEST;
441 }
442
443 int UtcDaliPinchGestureSignalReceptionDetachWhilePinching(void)
444 {
445   TestApplication application;
446
447   Actor actor = Actor::New();
448   actor.SetSize(100.0f, 100.0f);
449   actor.SetAnchorPoint(AnchorPoint::TOP_LEFT);
450   Stage::GetCurrent().Add(actor);
451
452   // Render and notify
453   application.SendNotification();
454   application.Render();
455
456   SignalData data;
457   GestureReceivedFunctor functor(data);
458
459   PinchGestureDetector detector = PinchGestureDetector::New();
460   detector.Attach(actor);
461   detector.DetectedSignal().Connect(&application, functor);
462
463   // Start pinch within the actor's area
464   application.ProcessEvent(GeneratePinch(Gesture::Started, 10.0f, 50.0f, Vector2(10.0f, 10.0f)));
465   DALI_TEST_EQUALS(true, data.functorCalled, TEST_LOCATION);
466   DALI_TEST_EQUALS(Gesture::Started, data.receivedGesture.state, TEST_LOCATION);
467
468   // Continue the pinch within the actor's area - we should still receive the signal
469   data.Reset();
470   application.ProcessEvent(GeneratePinch(Gesture::Continuing, 5.0f, 25.0f, Vector2(20.0f, 20.0f)));
471   DALI_TEST_EQUALS(true, data.functorCalled, TEST_LOCATION);
472   DALI_TEST_EQUALS(Gesture::Continuing, data.receivedGesture.state, TEST_LOCATION);
473
474   // Detach actor during the pinch, we should not receive the next event
475   detector.DetachAll();
476
477   // Gesture ends within actor's area
478   data.Reset();
479   application.ProcessEvent(GeneratePinch(Gesture::Finished, 5.0f, 25.0f, Vector2(20.0f, 20.0f)));
480   DALI_TEST_EQUALS(false, data.functorCalled, TEST_LOCATION);
481   END_TEST;
482 }
483
484 int UtcDaliPinchGestureSignalReceptionActorDestroyedWhilePinching(void)
485 {
486   TestApplication application;
487
488   SignalData data;
489   GestureReceivedFunctor functor(data);
490
491   PinchGestureDetector detector = PinchGestureDetector::New();
492   detector.DetectedSignal().Connect(&application, functor);
493
494   // Attach a temporary actor to stop detector being removed from PinchGestureProcessor when main actor
495   // is destroyed.
496   Actor tempActor = Actor::New();
497   tempActor.SetSize(100.0f, 100.0f);
498   tempActor.SetAnchorPoint(AnchorPoint::BOTTOM_RIGHT);
499   Stage::GetCurrent().Add(tempActor);
500   detector.Attach(tempActor);
501
502   // Actor lifetime is scoped
503   {
504     Actor actor = Actor::New();
505     actor.SetSize(100.0f, 100.0f);
506     actor.SetAnchorPoint(AnchorPoint::TOP_LEFT);
507     Stage::GetCurrent().Add(actor);
508
509     // Render and notify
510     application.SendNotification();
511     application.Render();
512
513     detector.Attach(actor);
514
515     // Start pinch within the actor's area
516     application.ProcessEvent(GeneratePinch(Gesture::Started, 10.0f, 50.0f, Vector2(10.0f, 10.0f)));
517     DALI_TEST_EQUALS(true, data.functorCalled, TEST_LOCATION);
518     DALI_TEST_EQUALS(Gesture::Started, data.receivedGesture.state, TEST_LOCATION);
519
520     // Continue the pinch within the actor's area - we should still receive the signal
521     data.Reset();
522     application.ProcessEvent(GeneratePinch(Gesture::Continuing, 5.0f, 25.0f, Vector2(20.0f, 20.0f)));
523     DALI_TEST_EQUALS(true, data.functorCalled, TEST_LOCATION);
524     DALI_TEST_EQUALS(Gesture::Continuing, data.receivedGesture.state, TEST_LOCATION);
525
526     // Remove the actor from stage and reset the data
527     Stage::GetCurrent().Remove(actor);
528
529     // Render and notify
530     application.SendNotification();
531     application.Render();
532   }
533
534   // Actor should now have been destroyed
535
536   // Gesture ends within the area where the actor used to be
537   data.Reset();
538   application.ProcessEvent(GeneratePinch(Gesture::Finished, 5.0f, 25.0f, Vector2(20.0f, 20.0f)));
539   DALI_TEST_EQUALS(false, data.functorCalled, TEST_LOCATION);
540   END_TEST;
541 }
542
543 int UtcDaliPinchGestureSignalReceptionRotatedActor(void)
544 {
545   TestApplication application;
546
547   Actor actor = Actor::New();
548   actor.SetSize(100.0f, 100.0f);
549   actor.SetRotation(Dali::Degree(90.0f), Vector3::ZAXIS);
550   Stage::GetCurrent().Add(actor);
551
552   // Render and notify a couple of times
553   application.SendNotification();
554   application.Render();
555
556   SignalData data;
557   GestureReceivedFunctor functor(data);
558
559   PinchGestureDetector detector = PinchGestureDetector::New();
560   detector.Attach(actor);
561   detector.DetectedSignal().Connect(&application, functor);
562
563   // Do an entire pinch, only check finished value
564   application.ProcessEvent(GeneratePinch(Gesture::Started, 10.0f, 50.0f, Vector2(10.0f, 10.0f)));
565   data.Reset();
566   application.ProcessEvent(GeneratePinch(Gesture::Finished, 10.0f, 50.0f, Vector2(10.0f, 10.0f)));
567   DALI_TEST_EQUALS(true, data.functorCalled, TEST_LOCATION);
568   DALI_TEST_EQUALS(10.0f, data.receivedGesture.scale, 0.01f, TEST_LOCATION);
569   DALI_TEST_EQUALS(50.0f, data.receivedGesture.speed, 0.01f, TEST_LOCATION);
570   DALI_TEST_EQUALS(Vector2(10.0f, 10.0f), data.receivedGesture.screenCenterPoint, 0.01f, TEST_LOCATION);
571
572   // Rotate actor again and render and notify
573   actor.SetRotation(Dali::Degree(180.0f), Vector3::ZAXIS);
574   application.SendNotification();
575   application.Render();
576
577   // Do an entire pinch, only check finished value
578   application.ProcessEvent(GeneratePinch(Gesture::Started, 10.0f, 50.0f, Vector2(10.0f, 10.0f)));
579   data.Reset();
580   application.ProcessEvent(GeneratePinch(Gesture::Finished, 10.0f, 50.0f, Vector2(10.0f, 10.0f)));
581   DALI_TEST_EQUALS(true, data.functorCalled, TEST_LOCATION);
582   DALI_TEST_EQUALS(10.0f, data.receivedGesture.scale, 0.01f, TEST_LOCATION);
583   DALI_TEST_EQUALS(50.0f, data.receivedGesture.speed, 0.01f, TEST_LOCATION);
584   DALI_TEST_EQUALS(Vector2(10.0f, 10.0f), data.receivedGesture.screenCenterPoint, 0.01f, TEST_LOCATION);
585
586   // Rotate actor again and render and notify
587   actor.SetRotation(Dali::Degree(270.0f), Vector3::ZAXIS);
588   application.SendNotification();
589   application.Render();
590
591   // Do an entire pinch, only check finished value
592   application.ProcessEvent(GeneratePinch(Gesture::Started, 10.0f, 50.0f, Vector2(10.0f, 10.0f)));
593   data.Reset();
594   application.ProcessEvent(GeneratePinch(Gesture::Finished, 10.0f, 50.0f, Vector2(10.0f, 10.0f)));
595   DALI_TEST_EQUALS(true, data.functorCalled, TEST_LOCATION);
596   DALI_TEST_EQUALS(10.0f, data.receivedGesture.scale, 0.01f, TEST_LOCATION);
597   DALI_TEST_EQUALS(50.0f, data.receivedGesture.speed, 0.01f, TEST_LOCATION);
598   DALI_TEST_EQUALS(Vector2(10.0f, 10.0f), data.receivedGesture.screenCenterPoint, 0.01f, TEST_LOCATION);
599   END_TEST;
600 }
601
602 int UtcDaliPinchGestureSignalReceptionChildHit(void)
603 {
604   TestApplication application;
605
606   Actor parent = Actor::New();
607   parent.SetSize(100.0f, 100.0f);
608   parent.SetAnchorPoint(AnchorPoint::TOP_LEFT);
609   Stage::GetCurrent().Add(parent);
610
611   // Set child to completely cover parent.
612   // Change rotation of child to be different from parent so that we can check if our local coordinate
613   // conversion of the parent actor is correct.
614   Actor child = Actor::New();
615   child.SetSize(100.0f, 100.0f);
616   child.SetAnchorPoint(AnchorPoint::CENTER);
617   child.SetParentOrigin(ParentOrigin::CENTER);
618   child.SetRotation(Dali::Degree(90.0f), Vector3::ZAXIS);
619   parent.Add(child);
620
621   TouchEventFunctor touchFunctor;
622   child.TouchedSignal().Connect(&application, touchFunctor);
623
624   // Render and notify
625   application.SendNotification();
626   application.Render();
627
628   SignalData data;
629   GestureReceivedFunctor functor(data);
630
631   PinchGestureDetector detector = PinchGestureDetector::New();
632   detector.Attach(parent);
633   detector.DetectedSignal().Connect(&application, functor);
634
635   // Do an entire pan, only check finished value - hits child area but parent should still receive it
636   application.ProcessEvent(GeneratePinch(Gesture::Started, 10.0f, 50.0f, Vector2(10.0f, 10.0f)));
637   data.Reset();
638   application.ProcessEvent(GeneratePinch(Gesture::Finished, 5.0f, 50.0f, Vector2(10.0f, 10.0f)));
639   DALI_TEST_EQUALS(true, data.functorCalled, TEST_LOCATION);
640   DALI_TEST_EQUALS(true, parent == data.pinchedActor, TEST_LOCATION);
641   DALI_TEST_EQUALS(5.0f, data.receivedGesture.scale, 0.01f, TEST_LOCATION);
642   DALI_TEST_EQUALS(50.0f, data.receivedGesture.speed, 0.01f, TEST_LOCATION);
643   DALI_TEST_EQUALS(Vector2(10.0f, 10.0f), data.receivedGesture.screenCenterPoint, 0.01f, TEST_LOCATION);
644
645   // Attach child and generate same touch points to yield same results
646   // (Also proves that you can detach and then re-attach another actor)
647   detector.Attach(child);
648   detector.Detach(parent);
649
650   // Do an entire pan, only check finished value
651   application.ProcessEvent(GeneratePinch(Gesture::Started, 10.0f, 50.0f, Vector2(10.0f, 10.0f)));
652   data.Reset();
653   application.ProcessEvent(GeneratePinch(Gesture::Finished, 5.0f, 50.0f, Vector2(10.0f, 10.0f)));
654   DALI_TEST_EQUALS(true, data.functorCalled, TEST_LOCATION);
655   DALI_TEST_EQUALS(true, child == data.pinchedActor, TEST_LOCATION);
656   DALI_TEST_EQUALS(5.0f, data.receivedGesture.scale, 0.01f, TEST_LOCATION);
657   DALI_TEST_EQUALS(50.0f, data.receivedGesture.speed, 0.01f, TEST_LOCATION);
658   DALI_TEST_EQUALS(Vector2(10.0f, 10.0f), data.receivedGesture.screenCenterPoint, 0.01f, TEST_LOCATION);
659   END_TEST;
660 }
661
662 int UtcDaliPinchGestureSignalReceptionAttachDetachMany(void)
663 {
664   TestApplication application;
665
666   Actor first = Actor::New();
667   first.SetSize(100.0f, 100.0f);
668   first.SetAnchorPoint(AnchorPoint::TOP_LEFT);
669   Stage::GetCurrent().Add(first);
670
671   Actor second = Actor::New();
672   second.SetSize(100.0f, 100.0f);
673   second.SetX(100.0f);
674   second.SetAnchorPoint(AnchorPoint::TOP_LEFT);
675   Stage::GetCurrent().Add(second);
676
677   // Render and notify
678   application.SendNotification();
679   application.Render();
680
681   SignalData data;
682   GestureReceivedFunctor functor(data);
683
684   PinchGestureDetector detector = PinchGestureDetector::New();
685   detector.Attach(first);
686   detector.Attach(second);
687   detector.DetectedSignal().Connect(&application, functor);
688
689   // Start pinch within second actor's area
690   application.ProcessEvent(GeneratePinch(Gesture::Started, 10.0f, 50.0f, Vector2(120.0f, 10.0f)));
691   DALI_TEST_EQUALS(true, data.functorCalled, TEST_LOCATION);
692   DALI_TEST_EQUALS(true, second == data.pinchedActor, TEST_LOCATION);
693
694   // Pinch moves into first actor's area - second actor should receive the pinch
695   data.Reset();
696   application.ProcessEvent(GeneratePinch(Gesture::Continuing, 10.0f, 50.0f, Vector2(10.0f, 10.0f)));
697   DALI_TEST_EQUALS(true, data.functorCalled, TEST_LOCATION);
698   DALI_TEST_EQUALS(true, second == data.pinchedActor, TEST_LOCATION);
699
700   // Detach the second actor during the pinch, we should not receive the next event
701   detector.Detach(second);
702
703   // Gesture ends within actor's area
704   data.Reset();
705   application.ProcessEvent(GeneratePinch(Gesture::Finished, 10.0f, 50.0f, Vector2(120.0f, 10.0f)));
706   DALI_TEST_EQUALS(false, data.functorCalled, TEST_LOCATION);
707   END_TEST;
708 }
709
710 int UtcDaliPinchGestureSignalReceptionActorBecomesUntouchable(void)
711 {
712   TestApplication application;
713
714   Actor actor = Actor::New();
715   actor.SetSize(100.0f, 100.0f);
716   actor.SetAnchorPoint(AnchorPoint::TOP_LEFT);
717   Stage::GetCurrent().Add(actor);
718
719   // Render and notify
720   application.SendNotification();
721   application.Render();
722
723   SignalData data;
724   GestureReceivedFunctor functor(data);
725
726   PinchGestureDetector detector = PinchGestureDetector::New();
727   detector.Attach(actor);
728   detector.DetectedSignal().Connect(&application, functor);
729
730   // Start pinch in actor's area
731   application.ProcessEvent(GeneratePinch(Gesture::Started, 10.0f, 50.0f, Vector2(20.0f, 10.0f)));
732   DALI_TEST_EQUALS(true, data.functorCalled, TEST_LOCATION);
733
734   // Pan continues within actor's area
735   data.Reset();
736   application.ProcessEvent(GeneratePinch(Gesture::Started, 5.0f, 50.0f, Vector2(10.0f, 10.0f)));
737   DALI_TEST_EQUALS(true, data.functorCalled, TEST_LOCATION);
738
739   // Actor become invisible - actor should not receive the next pinch
740   actor.SetVisible(false);
741
742   // Render and notify
743   application.SendNotification();
744   application.Render();
745
746   // Gesture ends within actor's area
747   data.Reset();
748   application.ProcessEvent(GeneratePinch(Gesture::Finished, 5.0f, 50.0f, Vector2(10.0f, 10.0f)));
749   DALI_TEST_EQUALS(false, data.functorCalled, TEST_LOCATION);
750   END_TEST;
751 }
752
753 int UtcDaliPinchGestureSignalReceptionMultipleDetectorsOnActor(void)
754 {
755   TestApplication application;
756
757   Actor actor = Actor::New();
758   actor.SetSize(100.0f, 100.0f);
759   actor.SetAnchorPoint(AnchorPoint::TOP_LEFT);
760   Stage::GetCurrent().Add(actor);
761
762   Actor actor2 = Actor::New();
763   actor2.SetSize(100.0f, 100.0f);
764   actor2.SetAnchorPoint(AnchorPoint::BOTTOM_RIGHT);
765   Stage::GetCurrent().Add(actor2);
766
767   // Render and notify
768   application.SendNotification();
769   application.Render();
770
771   // Attach actor to one detector
772   SignalData firstData;
773   GestureReceivedFunctor firstFunctor(firstData);
774   PinchGestureDetector firstDetector = PinchGestureDetector::New();
775   firstDetector.Attach(actor);
776   firstDetector.DetectedSignal().Connect(&application, firstFunctor);
777
778   // Attach actor to another detector
779   SignalData secondData;
780   GestureReceivedFunctor secondFunctor(secondData);
781   PinchGestureDetector secondDetector = PinchGestureDetector::New();
782   secondDetector.Attach(actor);
783   secondDetector.DetectedSignal().Connect(&application, secondFunctor);
784
785   // Add second actor to second detector, when we remove the actor, this will make sure that this
786   // gesture detector is not removed from the GestureDetectorProcessor.  In this scenario, the
787   // functor should still not be called (which is what we're also testing).
788   secondDetector.Attach(actor2);
789
790   // Pinch in actor's area - both detector's functors should be called
791   application.ProcessEvent(GeneratePinch(Gesture::Started, 10.0f, 50.0f, Vector2(20.0f, 10.0f)));
792   DALI_TEST_EQUALS(true, firstData.functorCalled, TEST_LOCATION);
793   DALI_TEST_EQUALS(true, secondData.functorCalled, TEST_LOCATION);
794
795   // Pinch continues in actor's area - both detector's functors should be called
796   firstData.Reset();
797   secondData.Reset();
798   application.ProcessEvent(GeneratePinch(Gesture::Continuing, 10.0f, 50.0f, Vector2(20.0f, 10.0f)));
799   DALI_TEST_EQUALS(true, firstData.functorCalled, TEST_LOCATION);
800   DALI_TEST_EQUALS(true, secondData.functorCalled, TEST_LOCATION);
801
802   // Detach actor from firstDetector and emit pinch on actor, only secondDetector's functor should be called.
803   firstDetector.Detach(actor);
804   firstData.Reset();
805   secondData.Reset();
806   application.ProcessEvent(GeneratePinch(Gesture::Finished, 10.0f, 50.0f, Vector2(20.0f, 10.0f)));
807   DALI_TEST_EQUALS(false, firstData.functorCalled, TEST_LOCATION);
808   DALI_TEST_EQUALS(true, secondData.functorCalled, TEST_LOCATION);
809
810   // New pinch on actor, only secondDetector has actor attached
811   firstData.Reset();
812   secondData.Reset();
813   application.ProcessEvent(GeneratePinch(Gesture::Started, 10.0f, 50.0f, Vector2(20.0f, 10.0f)));
814   DALI_TEST_EQUALS(false, firstData.functorCalled, TEST_LOCATION);
815   DALI_TEST_EQUALS(true, secondData.functorCalled, TEST_LOCATION);
816
817   // Detach actor from secondDetector
818   secondDetector.Detach(actor);
819   firstData.Reset();
820   secondData.Reset();
821   application.ProcessEvent(GeneratePinch(Gesture::Continuing, 10.0f, 50.0f, Vector2(20.0f, 10.0f)));
822   DALI_TEST_EQUALS(false, firstData.functorCalled, TEST_LOCATION);
823   DALI_TEST_EQUALS(false, secondData.functorCalled, TEST_LOCATION);
824   END_TEST;
825 }
826
827 int UtcDaliPinchGestureSignalReceptionMultipleStarted(void)
828 {
829   // Should handle two started events gracefully.
830
831   TestApplication application;
832
833   Actor actor = Actor::New();
834   actor.SetSize(100.0f, 100.0f);
835   actor.SetAnchorPoint(AnchorPoint::TOP_LEFT);
836   Stage::GetCurrent().Add(actor);
837
838   SignalData data;
839   GestureReceivedFunctor functor(data);
840
841   PinchGestureDetector detector = PinchGestureDetector::New();
842   detector.Attach(actor);
843   detector.DetectedSignal().Connect(&application, functor);
844
845   // Render and notify
846   application.SendNotification();
847   application.Render();
848
849   // Start pan in actor's area
850   application.ProcessEvent(GeneratePinch(Gesture::Started, 10.0f, 50.0f, Vector2(20.0f, 10.0f)));
851   DALI_TEST_EQUALS(true, data.functorCalled, TEST_LOCATION);
852
853   // Send another start in actor's area
854   data.Reset();
855   application.ProcessEvent(GeneratePinch(Gesture::Started, 10.0f, 50.0f, Vector2(20.0f, 10.0f)));
856   DALI_TEST_EQUALS(true, data.functorCalled, TEST_LOCATION);
857
858   // Add a child actor to overlap actor and send another start in actor's area
859   Actor child = Actor::New();
860   child.SetSize(100.0f, 100.0f);
861   child.SetAnchorPoint(AnchorPoint::CENTER);
862   child.SetParentOrigin(ParentOrigin::CENTER);
863   actor.Add(child);
864
865   TouchEventFunctor touchFunctor;
866   child.TouchedSignal().Connect(&application, touchFunctor);
867
868   // Render and notify
869   application.SendNotification();
870   application.Render();
871
872   // Send another start in actor's area
873   data.Reset();
874   application.ProcessEvent(GeneratePinch(Gesture::Started, 10.0f, 50.0f, Vector2(20.0f, 10.0f)));
875   DALI_TEST_EQUALS(true, data.functorCalled, TEST_LOCATION);
876
877   // Send another start in actor's area
878   data.Reset();
879   application.ProcessEvent(GeneratePinch(Gesture::Started, 10.0f, 50.0f, Vector2(20.0f, 10.0f)));
880   DALI_TEST_EQUALS(true, data.functorCalled, TEST_LOCATION);
881   END_TEST;
882 }
883
884 int UtcDaliPinchGestureSignalReceptionEnsureCorrectSignalling(void)
885 {
886   TestApplication application;
887
888   Actor actor1 = Actor::New();
889   actor1.SetSize(100.0f, 100.0f);
890   actor1.SetAnchorPoint(AnchorPoint::TOP_LEFT);
891   Stage::GetCurrent().Add(actor1);
892   SignalData data1;
893   GestureReceivedFunctor functor1(data1);
894   PinchGestureDetector detector1 = PinchGestureDetector::New();
895   detector1.Attach(actor1);
896   detector1.DetectedSignal().Connect(&application, functor1);
897
898   Actor actor2 = Actor::New();
899   actor2.SetSize(100.0f, 100.0f);
900   actor2.SetAnchorPoint(AnchorPoint::BOTTOM_RIGHT);
901   actor2.SetParentOrigin(ParentOrigin::BOTTOM_RIGHT);
902   Stage::GetCurrent().Add(actor2);
903   SignalData data2;
904   GestureReceivedFunctor functor2(data2);
905   PinchGestureDetector detector2 = PinchGestureDetector::New();
906   detector2.Attach(actor2);
907   detector2.DetectedSignal().Connect(&application, functor2);
908
909   // Render and notify
910   application.SendNotification();
911   application.Render();
912
913   // Start pan in actor1's area, only data1 should be set
914   application.ProcessEvent(GeneratePinch(Gesture::Started, 10.0f, 50.0f, Vector2(20.0f, 10.0f)));
915   DALI_TEST_EQUALS(true, data1.functorCalled, TEST_LOCATION);
916   DALI_TEST_EQUALS(false, data2.functorCalled, TEST_LOCATION);
917   END_TEST;
918 }
919
920 int UtcDaliPinchGestureEmitIncorrectStateClear(void)
921 {
922   TestApplication application;
923
924   Actor actor = Actor::New();
925   actor.SetSize(100.0f, 100.0f);
926   actor.SetAnchorPoint(AnchorPoint::TOP_LEFT);
927   Stage::GetCurrent().Add(actor);
928
929   // Render and notify
930   application.SendNotification();
931   application.Render();
932
933   // Attach actor to detector
934   SignalData data;
935   GestureReceivedFunctor functor( data );
936   PinchGestureDetector detector = PinchGestureDetector::New();
937   detector.Attach(actor);
938   detector.DetectedSignal().Connect( &application, functor );
939
940   // Try a Clear state
941   try
942   {
943     application.ProcessEvent(GeneratePinch(Gesture::Clear, 10.0f, 50.0f, Vector2(20.0f, 10.0f)));
944     tet_result(TET_FAIL);
945   }
946   catch ( Dali::DaliException& e )
947   {
948     DALI_TEST_ASSERT( e, "false", TEST_LOCATION );
949   }
950   END_TEST;
951 }
952
953 int UtcDaliPinchGestureEmitIncorrectStatePossible(void)
954 {
955   TestApplication application;
956
957   Actor actor = Actor::New();
958   actor.SetSize(100.0f, 100.0f);
959   actor.SetAnchorPoint(AnchorPoint::TOP_LEFT);
960   Stage::GetCurrent().Add(actor);
961
962   // Render and notify
963   application.SendNotification();
964   application.Render();
965
966   // Attach actor to detector
967   SignalData data;
968   GestureReceivedFunctor functor( data );
969   PinchGestureDetector detector = PinchGestureDetector::New();
970   detector.Attach(actor);
971   detector.DetectedSignal().Connect( &application, functor );
972
973   // Try a Possible state
974   try
975   {
976     application.ProcessEvent(GeneratePinch(Gesture::Possible, 10.0f, 50.0f, Vector2(20.0f, 10.0f)));
977     tet_result(TET_FAIL);
978   }
979   catch ( Dali::DaliException& e )
980   {
981     DALI_TEST_ASSERT( e, "false", TEST_LOCATION );
982   }
983   END_TEST;
984 }
985
986 int UtcDaliPinchGestureActorUnstaged(void)
987 {
988   TestApplication application;
989
990   Actor actor = Actor::New();
991   actor.SetSize(100.0f, 100.0f);
992   actor.SetAnchorPoint(AnchorPoint::TOP_LEFT);
993   Stage::GetCurrent().Add(actor);
994
995   // Render and notify
996   application.SendNotification();
997   application.Render();
998
999   // State to remove actor in.
1000   Gesture::State stateToUnstage( Gesture::Started );
1001
1002   // Attach actor to detector
1003   SignalData data;
1004   UnstageActorFunctor functor( data, stateToUnstage );
1005   PinchGestureDetector detector = PinchGestureDetector::New();
1006   detector.Attach(actor);
1007   detector.DetectedSignal().Connect( &application, functor );
1008
1009   // Emit signals
1010   application.ProcessEvent(GeneratePinch(Gesture::Started, 10.0f, 50.0f, Vector2(20.0f, 10.0f)));
1011   DALI_TEST_EQUALS(true, data.functorCalled, TEST_LOCATION);
1012   data.Reset();
1013   application.ProcessEvent(GeneratePinch(Gesture::Finished, 10.0f, 50.0f, Vector2(20.0f, 10.0f)));
1014   DALI_TEST_EQUALS(false, data.functorCalled, TEST_LOCATION);
1015   data.Reset();
1016
1017   // Render and notify
1018   application.SendNotification();
1019   application.Render();
1020
1021   // Re-add actor to stage
1022   Stage::GetCurrent().Add(actor);
1023
1024   // Render and notify
1025   application.SendNotification();
1026   application.Render();
1027
1028   // Change state to Gesture::Continuing to remove
1029   stateToUnstage = Gesture::Continuing;
1030
1031   // Emit signals
1032   application.ProcessEvent(GeneratePinch(Gesture::Started, 10.0f, 50.0f, Vector2(20.0f, 10.0f)));
1033   DALI_TEST_EQUALS(true, data.functorCalled, TEST_LOCATION);
1034   data.Reset();
1035   application.ProcessEvent(GeneratePinch(Gesture::Continuing, 10.0f, 50.0f, Vector2(20.0f, 10.0f)));
1036   DALI_TEST_EQUALS(true, data.functorCalled, TEST_LOCATION);
1037   data.Reset();
1038   application.ProcessEvent(GeneratePinch(Gesture::Finished, 10.0f, 50.0f, Vector2(20.0f, 10.0f)));
1039   DALI_TEST_EQUALS(false, data.functorCalled, TEST_LOCATION);
1040   data.Reset();
1041
1042   // Render and notify
1043   application.SendNotification();
1044   application.Render();
1045
1046   // Re-add actor to stage
1047   Stage::GetCurrent().Add(actor);
1048
1049   // Render and notify
1050   application.SendNotification();
1051   application.Render();
1052
1053   // Change state to Gesture::Continuing to remove
1054   stateToUnstage = Gesture::Finished;
1055
1056   // Emit signals
1057   application.ProcessEvent(GeneratePinch(Gesture::Started, 10.0f, 50.0f, Vector2(20.0f, 10.0f)));
1058   DALI_TEST_EQUALS(true, data.functorCalled, TEST_LOCATION);
1059   data.Reset();
1060   application.ProcessEvent(GeneratePinch(Gesture::Continuing, 10.0f, 50.0f, Vector2(20.0f, 10.0f)));
1061   DALI_TEST_EQUALS(true, data.functorCalled, TEST_LOCATION);
1062   data.Reset();
1063   application.ProcessEvent(GeneratePinch(Gesture::Finished, 10.0f, 50.0f, Vector2(20.0f, 10.0f)));
1064   DALI_TEST_EQUALS(true, data.functorCalled, TEST_LOCATION);
1065   tet_result( TET_PASS ); // If we get here then we have handled actor stage removal gracefully.
1066   END_TEST;
1067 }
1068
1069 int UtcDaliPinchGestureActorStagedAndDestroyed(void)
1070 {
1071   TestApplication application;
1072
1073   Actor actor = Actor::New();
1074   actor.SetSize(100.0f, 100.0f);
1075   actor.SetAnchorPoint(AnchorPoint::TOP_LEFT);
1076   Stage::GetCurrent().Add(actor);
1077
1078   // Create and add a second actor so that GestureDetector destruction does not come into play.
1079   Actor dummyActor( Actor::New() );
1080   dummyActor.SetSize( 100.0f, 100.0f );
1081   dummyActor.SetPosition( 100.0f, 100.0f );
1082   dummyActor.SetAnchorPoint(AnchorPoint::TOP_LEFT);
1083   Stage::GetCurrent().Add(dummyActor);
1084
1085   // Render and notify
1086   application.SendNotification();
1087   application.Render();
1088
1089   // State to remove actor in.
1090   Gesture::State stateToUnstage( Gesture::Started );
1091
1092   // Attach actor to detector
1093   SignalData data;
1094   UnstageActorFunctor functor( data, stateToUnstage );
1095   PinchGestureDetector detector = PinchGestureDetector::New();
1096   detector.Attach(actor);
1097   detector.Attach(dummyActor);
1098   detector.DetectedSignal().Connect( &application, functor );
1099
1100   // Here we are testing a Started actor which is removed in the Started callback, but then added back
1101   // before we get a continuing state.  As we were removed from the stage, even if we're at the same
1102   // position, we should still not be signalled.
1103
1104   // Emit signals
1105   application.ProcessEvent(GeneratePinch(Gesture::Started, 10.0f, 50.0f, Vector2(20.0f, 10.0f)));
1106   DALI_TEST_EQUALS(true, data.functorCalled, TEST_LOCATION);
1107   data.Reset();
1108
1109   // Render and notify
1110   application.SendNotification();
1111   application.Render();
1112
1113   // Re add to the stage, we should not be signalled
1114   Stage::GetCurrent().Add(actor);
1115
1116   // Render and notify
1117   application.SendNotification();
1118   application.Render();
1119
1120   // Continue signal emission
1121   application.ProcessEvent(GeneratePinch(Gesture::Continuing, 10.0f, 50.0f, Vector2(20.0f, 10.0f)));
1122   DALI_TEST_EQUALS(false, data.functorCalled, TEST_LOCATION);
1123   data.Reset();
1124   application.ProcessEvent(GeneratePinch(Gesture::Finished, 10.0f, 50.0f, Vector2(20.0f, 10.0f)));
1125   DALI_TEST_EQUALS(false, data.functorCalled, TEST_LOCATION);
1126   data.Reset();
1127
1128   // Here we delete an actor in started, we should not receive any subsequent signalling.
1129
1130   // Emit signals
1131   application.ProcessEvent(GeneratePinch(Gesture::Started, 10.0f, 50.0f, Vector2(20.0f, 10.0f)));
1132   DALI_TEST_EQUALS(true, data.functorCalled, TEST_LOCATION);
1133   data.Reset();
1134
1135   // Render and notify
1136   application.SendNotification();
1137   application.Render();
1138
1139   // Delete actor as well
1140   actor = NULL;
1141
1142   // Render and notify
1143   application.SendNotification();
1144   application.Render();
1145
1146   // Continue signal emission
1147   application.ProcessEvent(GeneratePinch(Gesture::Continuing, 10.0f, 50.0f, Vector2(20.0f, 10.0f)));
1148   DALI_TEST_EQUALS(false, data.functorCalled, TEST_LOCATION);
1149   data.Reset();
1150   application.ProcessEvent(GeneratePinch(Gesture::Finished, 10.0f, 50.0f, Vector2(20.0f, 10.0f)));
1151   DALI_TEST_EQUALS(false, data.functorCalled, TEST_LOCATION);
1152   END_TEST;
1153 }
1154
1155 int UtcDaliPinchGestureSystemOverlay(void)
1156 {
1157   TestApplication application;
1158   Dali::Integration::Core& core = application.GetCore();
1159   Dali::Integration::SystemOverlay& systemOverlay( core.GetSystemOverlay() );
1160   systemOverlay.GetOverlayRenderTasks().CreateTask();
1161
1162   Actor actor = Actor::New();
1163   actor.SetSize(100.0f, 100.0f);
1164   actor.SetAnchorPoint(AnchorPoint::TOP_LEFT);
1165   systemOverlay.Add(actor);
1166
1167   // Render and notify
1168   application.SendNotification();
1169   application.Render();
1170
1171   SignalData data;
1172   GestureReceivedFunctor functor(data);
1173
1174   PinchGestureDetector detector = PinchGestureDetector::New();
1175   detector.Attach(actor);
1176   detector.DetectedSignal().Connect(&application, functor);
1177
1178   Vector2 screenCoords( 50.0f, 50.0f );
1179   float scale ( 10.0f );
1180   float speed ( 50.0f );
1181
1182   // Start pan within the actor's area
1183   application.ProcessEvent( GeneratePinch( Gesture::Started, scale, speed, screenCoords ) );
1184   DALI_TEST_EQUALS( true, data.functorCalled, TEST_LOCATION );
1185   END_TEST;
1186 }
1187
1188 int UtcDaliPinchGestureBehindTouchableSystemOverlay(void)
1189 {
1190   TestApplication application;
1191   Dali::Integration::Core& core = application.GetCore();
1192   Dali::Integration::SystemOverlay& systemOverlay( core.GetSystemOverlay() );
1193   systemOverlay.GetOverlayRenderTasks().CreateTask();
1194
1195   // SystemOverlay actor
1196   Actor systemOverlayActor = Actor::New();
1197   systemOverlayActor.SetSize(100.0f, 100.0f);
1198   systemOverlayActor.SetAnchorPoint(AnchorPoint::TOP_LEFT);
1199   systemOverlay.Add(systemOverlayActor);
1200
1201   // Stage actor
1202   Actor stageActor = Actor::New();
1203   stageActor.SetSize(100.0f, 100.0f);
1204   stageActor.SetAnchorPoint(AnchorPoint::TOP_LEFT);
1205   Stage::GetCurrent().Add(stageActor);
1206
1207   // Render and notify
1208   application.SendNotification();
1209   application.Render();
1210
1211   // Set system-overlay actor to touchable
1212   TouchEventData touchData;
1213   TouchEventDataFunctor touchFunctor( touchData );
1214   systemOverlayActor.TouchedSignal().Connect(&application, touchFunctor);
1215
1216   // Set stage actor to receive the gesture
1217   SignalData data;
1218   GestureReceivedFunctor functor(data);
1219
1220   PinchGestureDetector detector = PinchGestureDetector::New();
1221   detector.Attach(stageActor);
1222   detector.DetectedSignal().Connect(&application, functor);
1223
1224   Vector2 screenCoords( 50.0f, 50.0f );
1225   float scale ( 10.0f );
1226   float speed ( 50.0f );
1227
1228   // Start pinch within the two actors' area
1229   application.ProcessEvent( GeneratePinch( Gesture::Started, scale, speed, screenCoords ) );
1230   application.ProcessEvent( GeneratePinch( Gesture::Finished, scale, speed, screenCoords ) );
1231   DALI_TEST_EQUALS( true, data.functorCalled, TEST_LOCATION );
1232   DALI_TEST_EQUALS( false, touchData.functorCalled, TEST_LOCATION );
1233
1234   data.Reset();
1235   touchData.Reset();
1236
1237   // Do touch in the same area
1238   application.ProcessEvent( touchFunctor.GenerateSingleTouch( TouchPoint::Down, screenCoords ) );
1239   DALI_TEST_EQUALS( false, data.functorCalled, TEST_LOCATION );
1240   DALI_TEST_EQUALS( true, touchData.functorCalled, TEST_LOCATION );
1241
1242   END_TEST;
1243 }
1244
1245 int UtcDaliPinchGestureTouchBehindGesturedSystemOverlay(void)
1246 {
1247   TestApplication application;
1248   Dali::Integration::Core& core = application.GetCore();
1249   Dali::Integration::SystemOverlay& systemOverlay( core.GetSystemOverlay() );
1250   systemOverlay.GetOverlayRenderTasks().CreateTask();
1251
1252   // SystemOverlay actor
1253   Actor systemOverlayActor = Actor::New();
1254   systemOverlayActor.SetSize(100.0f, 100.0f);
1255   systemOverlayActor.SetAnchorPoint(AnchorPoint::TOP_LEFT);
1256   systemOverlay.Add(systemOverlayActor);
1257
1258   // Stage actor
1259   Actor stageActor = Actor::New();
1260   stageActor.SetSize(100.0f, 100.0f);
1261   stageActor.SetAnchorPoint(AnchorPoint::TOP_LEFT);
1262   Stage::GetCurrent().Add(stageActor);
1263
1264   // Render and notify
1265   application.SendNotification();
1266   application.Render();
1267
1268   // Set stage actor to touchable
1269   TouchEventData touchData;
1270   TouchEventDataFunctor touchFunctor( touchData );
1271   stageActor.TouchedSignal().Connect(&application, touchFunctor);
1272
1273   // Set system-overlay actor to have the gesture
1274   SignalData data;
1275   GestureReceivedFunctor functor(data);
1276
1277   PinchGestureDetector detector = PinchGestureDetector::New();
1278   detector.Attach(systemOverlayActor);
1279   detector.DetectedSignal().Connect(&application, functor);
1280
1281   Vector2 screenCoords( 50.0f, 50.0f );
1282   float scale ( 10.0f );
1283   float speed ( 50.0f );
1284
1285   // Start pinch within the two actors' area
1286   application.ProcessEvent( GeneratePinch( Gesture::Started, scale, speed, screenCoords ) );
1287   application.ProcessEvent( GeneratePinch( Gesture::Finished, scale, speed, screenCoords ) );
1288   DALI_TEST_EQUALS( true, data.functorCalled, TEST_LOCATION );
1289   DALI_TEST_EQUALS( false, touchData.functorCalled, TEST_LOCATION );
1290
1291   data.Reset();
1292   touchData.Reset();
1293
1294   // Do touch in the same area
1295   application.ProcessEvent( touchFunctor.GenerateSingleTouch( TouchPoint::Down, screenCoords ) );
1296   DALI_TEST_EQUALS( false, data.functorCalled, TEST_LOCATION );
1297   DALI_TEST_EQUALS( true, touchData.functorCalled, TEST_LOCATION );
1298
1299   END_TEST;
1300 }