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