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