[dali_1.1.39] Merge branch 'devel/master'
[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/system-overlay.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   point.SetLocalPosition( Vector2( 20.0f, 20.0f ) );
211   touchEvent.AddPoint(point2);
212   application.ProcessEvent(touchEvent);
213   END_TEST;
214 }
215
216 int UtcDaliPinchGestureDetectorDownCast(void)
217 {
218   TestApplication application;
219   tet_infoline("Testing Dali::PinchGestureDetector::DownCast()");
220
221   PinchGestureDetector detector = PinchGestureDetector::New();
222
223   BaseHandle object(detector);
224
225   PinchGestureDetector detector2 = PinchGestureDetector::DownCast(object);
226   DALI_TEST_CHECK(detector2);
227
228   PinchGestureDetector detector3 = DownCast< PinchGestureDetector >(object);
229   DALI_TEST_CHECK(detector3);
230
231   BaseHandle unInitializedObject;
232   PinchGestureDetector detector4 = PinchGestureDetector::DownCast(unInitializedObject);
233   DALI_TEST_CHECK(!detector4);
234
235   PinchGestureDetector detector5 = DownCast< PinchGestureDetector >(unInitializedObject);
236   DALI_TEST_CHECK(!detector5);
237
238   GestureDetector detector6 = PinchGestureDetector::New();
239   PinchGestureDetector detector7 = PinchGestureDetector::DownCast(detector6);
240   DALI_TEST_CHECK(detector7);
241   END_TEST;
242 }
243
244 // Negative test case for a method
245 int UtcDaliPinchGestureSignalReceptionNegative(void)
246 {
247   TestApplication application;
248
249   Actor actor = Actor::New();
250   actor.SetSize(100.0f, 100.0f);
251   actor.SetAnchorPoint(AnchorPoint::TOP_LEFT);
252   Stage::GetCurrent().Add(actor);
253
254   // Render and notify
255   application.SendNotification();
256   application.Render();
257
258   SignalData data;
259   GestureReceivedFunctor functor(data);
260
261   PinchGestureDetector detector = PinchGestureDetector::New();
262   detector.Attach(actor);
263   detector.DetectedSignal().Connect(&application, functor);
264
265   // Do a pinch outside actor's area
266   application.ProcessEvent(GeneratePinch(Gesture::Started, 10.0f, 45.0f, Vector2(112.0f, 112.0f)));
267   DALI_TEST_EQUALS(false, data.functorCalled, TEST_LOCATION);
268
269   // Continue pinch into actor's area - we should still not receive the signal
270   data.Reset();
271   application.ProcessEvent(GeneratePinch(Gesture::Continuing, 4.5f, 95.0f, Vector2(20.0f, 20.0f)));
272   DALI_TEST_EQUALS(false, data.functorCalled, TEST_LOCATION);
273
274   // Stop pinching - we should still not receive the signal
275   data.Reset();
276   application.ProcessEvent(GeneratePinch(Gesture::Finished, 10.0f, 50.0f, Vector2(12.0f, 12.0f)));
277   DALI_TEST_EQUALS(false, data.functorCalled, TEST_LOCATION);
278   END_TEST;
279 }
280
281 int UtcDaliPinchGestureSignalReceptionDownMotionLeave(void)
282 {
283   TestApplication application;
284
285   Actor actor = Actor::New();
286   actor.SetSize(100.0f, 100.0f);
287   actor.SetAnchorPoint(AnchorPoint::TOP_LEFT);
288   Stage::GetCurrent().Add(actor);
289
290   // Render and notify
291   application.SendNotification();
292   application.Render();
293
294   SignalData data;
295   GestureReceivedFunctor functor(data);
296
297   PinchGestureDetector detector = PinchGestureDetector::New();
298   detector.Attach(actor);
299   detector.DetectedSignal().Connect(&application, functor);
300
301   // Start pan within the actor's area
302   application.ProcessEvent(GeneratePinch(Gesture::Started, 10.0f, 50.0f, Vector2(20.0f, 20.0f)));
303   DALI_TEST_EQUALS(true, data.functorCalled, TEST_LOCATION);
304   DALI_TEST_EQUALS(Gesture::Started, data.receivedGesture.state, TEST_LOCATION);
305   DALI_TEST_EQUALS(10.0f, data.receivedGesture.scale, 0.01f, TEST_LOCATION);
306   DALI_TEST_EQUALS(50.0f, data.receivedGesture.speed, 0.01f, TEST_LOCATION);
307   DALI_TEST_EQUALS(Vector2(20.0f, 20.0f), data.receivedGesture.screenCenterPoint, 0.01f, TEST_LOCATION);
308
309   // Continue the pan within the actor's area - we should still receive the signal
310   data.Reset();
311   application.ProcessEvent(GeneratePinch(Gesture::Continuing, 5.0f, 90.0f, Vector2(21.0f, 20.0f)));
312   DALI_TEST_EQUALS(true, data.functorCalled, TEST_LOCATION);
313   DALI_TEST_EQUALS(Gesture::Continuing, data.receivedGesture.state, TEST_LOCATION);
314   DALI_TEST_EQUALS(5.0f, data.receivedGesture.scale, 0.01f, TEST_LOCATION);
315   DALI_TEST_EQUALS(90.0f, data.receivedGesture.speed, 0.01f, TEST_LOCATION);
316   DALI_TEST_EQUALS(Vector2(21.0f, 20.0f), data.receivedGesture.screenCenterPoint, 0.01f, TEST_LOCATION);
317
318   // Pan Gesture leaves actor's area - we should still receive the signal
319   data.Reset();
320   application.ProcessEvent(GeneratePinch(Gesture::Continuing, 10.0f, 15.5f, Vector2(320.0f, 10.0f)));
321   DALI_TEST_EQUALS(true, data.functorCalled, TEST_LOCATION);
322   DALI_TEST_EQUALS(Gesture::Continuing, data.receivedGesture.state, TEST_LOCATION);
323   DALI_TEST_EQUALS(10.0f, data.receivedGesture.scale, 0.01f, TEST_LOCATION);
324   DALI_TEST_EQUALS(15.5f, data.receivedGesture.speed, 0.01f, TEST_LOCATION);
325   DALI_TEST_EQUALS(Vector2(320.0f, 10.0f), data.receivedGesture.screenCenterPoint, 0.01f, TEST_LOCATION);
326
327   // Gesture ends - we would receive a finished state
328   data.Reset();
329   application.ProcessEvent(GeneratePinch(Gesture::Finished, 15.2f, 12.1f, Vector2(310.0f, 10.0f)));
330   DALI_TEST_EQUALS(true, data.functorCalled, TEST_LOCATION);
331   DALI_TEST_EQUALS(Gesture::Finished, data.receivedGesture.state, TEST_LOCATION);
332   DALI_TEST_EQUALS(15.2f, data.receivedGesture.scale, 0.01f, TEST_LOCATION);
333   DALI_TEST_EQUALS(12.1f, data.receivedGesture.speed, 0.01f, TEST_LOCATION);
334   DALI_TEST_EQUALS(Vector2(310.0f, 10.0f), data.receivedGesture.screenCenterPoint, 0.01f, TEST_LOCATION);
335   END_TEST;
336 }
337
338 int UtcDaliPinchGestureSignalReceptionDownMotionUp(void)
339 {
340   TestApplication application;
341
342   Actor actor = Actor::New();
343   actor.SetSize(100.0f, 100.0f);
344   actor.SetAnchorPoint(AnchorPoint::TOP_LEFT);
345   Stage::GetCurrent().Add(actor);
346
347   // Render and notify
348   application.SendNotification();
349   application.Render();
350
351   SignalData data;
352   GestureReceivedFunctor functor(data);
353
354   PinchGestureDetector detector = PinchGestureDetector::New();
355   detector.Attach(actor);
356   detector.DetectedSignal().Connect(&application, functor);
357
358   // Start pinch within the actor's area
359   application.ProcessEvent(GeneratePinch(Gesture::Started, 10.0f, 50.0f, Vector2(20.0f, 20.0f)));
360   DALI_TEST_EQUALS(true, data.functorCalled, TEST_LOCATION);
361   DALI_TEST_EQUALS(Gesture::Started, data.receivedGesture.state, TEST_LOCATION);
362   DALI_TEST_EQUALS(10.0f, data.receivedGesture.scale, 0.01f, TEST_LOCATION);
363   DALI_TEST_EQUALS(50.0f, data.receivedGesture.speed, 0.01f, TEST_LOCATION);
364   DALI_TEST_EQUALS(Vector2(20.0f, 20.0f), data.receivedGesture.screenCenterPoint, 0.01f, TEST_LOCATION);
365
366   // Continue the pinch within the actor's area - we should still receive the signal
367   data.Reset();
368   application.ProcessEvent(GeneratePinch(Gesture::Continuing, 5.0f, 25.0f, Vector2(20.0f, 20.0f)));
369   DALI_TEST_EQUALS(true, data.functorCalled, TEST_LOCATION);
370   DALI_TEST_EQUALS(Gesture::Continuing, data.receivedGesture.state, TEST_LOCATION);
371   DALI_TEST_EQUALS(5.0f, data.receivedGesture.scale, 0.01f, TEST_LOCATION);
372   DALI_TEST_EQUALS(25.0f, data.receivedGesture.speed, 0.01f, TEST_LOCATION);
373   DALI_TEST_EQUALS(Vector2(20.0f, 20.0f), data.receivedGesture.screenCenterPoint, 0.01f, TEST_LOCATION);
374
375   // Gesture ends within actor's area - we would receive a finished state
376   data.Reset();
377   application.ProcessEvent(GeneratePinch(Gesture::Finished, 5.0f, 25.0f, Vector2(20.0f, 20.0f)));
378   DALI_TEST_EQUALS(true, data.functorCalled, TEST_LOCATION);
379   DALI_TEST_EQUALS(Gesture::Finished, data.receivedGesture.state, TEST_LOCATION);
380   DALI_TEST_EQUALS(5.0f, data.receivedGesture.scale, 0.01f, TEST_LOCATION);
381   DALI_TEST_EQUALS(25.0f, data.receivedGesture.speed, 0.01f, TEST_LOCATION);
382   DALI_TEST_EQUALS(Vector2(20.0f, 20.0f), data.receivedGesture.screenCenterPoint, 0.01f, TEST_LOCATION);
383   END_TEST;
384 }
385
386 int UtcDaliPinchGestureSignalReceptionCancelled(void)
387 {
388   TestApplication application;
389
390   Actor actor = Actor::New();
391   actor.SetSize(100.0f, 100.0f);
392   actor.SetAnchorPoint(AnchorPoint::TOP_LEFT);
393   Stage::GetCurrent().Add(actor);
394
395   // Render and notify
396   application.SendNotification();
397   application.Render();
398
399   SignalData data;
400   GestureReceivedFunctor functor(data);
401
402   PinchGestureDetector detector = PinchGestureDetector::New();
403   detector.Attach(actor);
404   detector.DetectedSignal().Connect(&application, functor);
405
406   // Start pinch within the actor's area
407   application.ProcessEvent(GeneratePinch(Gesture::Started, 10.0f, 50.0f, Vector2(20.0f, 20.0f)));
408   DALI_TEST_EQUALS(true, data.functorCalled, TEST_LOCATION);
409   DALI_TEST_EQUALS(Gesture::Started, data.receivedGesture.state, TEST_LOCATION);
410
411
412   // Continue the pinch within the actor's area - we should still receive the signal
413   data.Reset();
414   application.ProcessEvent(GeneratePinch(Gesture::Continuing, 5.0f, 25.0f, Vector2(20.0f, 20.0f)));
415   DALI_TEST_EQUALS(true, data.functorCalled, TEST_LOCATION);
416   DALI_TEST_EQUALS(Gesture::Continuing, data.receivedGesture.state, TEST_LOCATION);
417
418   // The gesture is cancelled
419   data.Reset();
420   application.ProcessEvent(GeneratePinch(Gesture::Cancelled, 5.0f, 25.0f, Vector2(20.0f, 20.0f)));
421   DALI_TEST_EQUALS(true, data.functorCalled, TEST_LOCATION);
422   DALI_TEST_EQUALS(Gesture::Cancelled, data.receivedGesture.state, TEST_LOCATION);
423   END_TEST;
424 }
425
426 int UtcDaliPinchGestureSignalReceptionDetach(void)
427 {
428   TestApplication application;
429
430   Actor actor = Actor::New();
431   actor.SetSize(100.0f, 100.0f);
432   actor.SetAnchorPoint(AnchorPoint::TOP_LEFT);
433   Stage::GetCurrent().Add(actor);
434
435   // Render and notify
436   application.SendNotification();
437   application.Render();
438
439   SignalData data;
440   GestureReceivedFunctor functor(data);
441
442   PinchGestureDetector detector = PinchGestureDetector::New();
443   detector.Attach(actor);
444   detector.DetectedSignal().Connect(&application, functor);
445
446   // Start pinch within the actor's area
447   application.ProcessEvent(GeneratePinch(Gesture::Started, 10.0f, 50.0f, Vector2(20.0f, 20.0f)));
448   DALI_TEST_EQUALS(true, data.functorCalled, TEST_LOCATION);
449   DALI_TEST_EQUALS(Gesture::Started, data.receivedGesture.state, TEST_LOCATION);
450
451
452   // Continue the pinch within the actor's area - we should still receive the signal
453   data.Reset();
454   application.ProcessEvent(GeneratePinch(Gesture::Continuing, 5.0f, 25.0f, Vector2(20.0f, 20.0f)));
455   DALI_TEST_EQUALS(true, data.functorCalled, TEST_LOCATION);
456   DALI_TEST_EQUALS(Gesture::Continuing, data.receivedGesture.state, TEST_LOCATION);
457
458   // Gesture ends within actor's area
459   data.Reset();
460   application.ProcessEvent(GeneratePinch(Gesture::Finished, 5.0f, 25.0f, Vector2(20.0f, 20.0f)));
461   DALI_TEST_EQUALS(true, data.functorCalled, TEST_LOCATION);
462   DALI_TEST_EQUALS(Gesture::Finished, data.receivedGesture.state, TEST_LOCATION);
463
464   // Detach actor
465   detector.DetachAll();
466
467   // Ensure we are no longer signalled
468   data.Reset();
469   application.ProcessEvent(GeneratePinch(Gesture::Started, 10.0f, 50.0f, Vector2(20.0f, 20.0f)));
470   application.ProcessEvent(GeneratePinch(Gesture::Continuing, 5.0f, 25.0f, Vector2(20.0f, 20.0f)));
471   application.ProcessEvent(GeneratePinch(Gesture::Finished, 5.0f, 25.0f, Vector2(20.0f, 20.0f)));
472   DALI_TEST_EQUALS(false, data.functorCalled, TEST_LOCATION);
473   END_TEST;
474 }
475
476 int UtcDaliPinchGestureSignalReceptionDetachWhilePinching(void)
477 {
478   TestApplication application;
479
480   Actor actor = Actor::New();
481   actor.SetSize(100.0f, 100.0f);
482   actor.SetAnchorPoint(AnchorPoint::TOP_LEFT);
483   Stage::GetCurrent().Add(actor);
484
485   // Render and notify
486   application.SendNotification();
487   application.Render();
488
489   SignalData data;
490   GestureReceivedFunctor functor(data);
491
492   PinchGestureDetector detector = PinchGestureDetector::New();
493   detector.Attach(actor);
494   detector.DetectedSignal().Connect(&application, functor);
495
496   // Start pinch within the actor's area
497   application.ProcessEvent(GeneratePinch(Gesture::Started, 10.0f, 50.0f, Vector2(10.0f, 10.0f)));
498   DALI_TEST_EQUALS(true, data.functorCalled, TEST_LOCATION);
499   DALI_TEST_EQUALS(Gesture::Started, data.receivedGesture.state, TEST_LOCATION);
500
501   // Continue the pinch within the actor's area - we should still receive the signal
502   data.Reset();
503   application.ProcessEvent(GeneratePinch(Gesture::Continuing, 5.0f, 25.0f, Vector2(20.0f, 20.0f)));
504   DALI_TEST_EQUALS(true, data.functorCalled, TEST_LOCATION);
505   DALI_TEST_EQUALS(Gesture::Continuing, data.receivedGesture.state, TEST_LOCATION);
506
507   // Detach actor during the pinch, we should not receive the next event
508   detector.DetachAll();
509
510   // Gesture ends within actor's area
511   data.Reset();
512   application.ProcessEvent(GeneratePinch(Gesture::Finished, 5.0f, 25.0f, Vector2(20.0f, 20.0f)));
513   DALI_TEST_EQUALS(false, data.functorCalled, TEST_LOCATION);
514   END_TEST;
515 }
516
517 int UtcDaliPinchGestureSignalReceptionActorDestroyedWhilePinching(void)
518 {
519   TestApplication application;
520
521   SignalData data;
522   GestureReceivedFunctor functor(data);
523
524   PinchGestureDetector detector = PinchGestureDetector::New();
525   detector.DetectedSignal().Connect(&application, functor);
526
527   // Attach a temporary actor to stop detector being removed from PinchGestureProcessor when main actor
528   // is destroyed.
529   Actor tempActor = Actor::New();
530   tempActor.SetSize(100.0f, 100.0f);
531   tempActor.SetAnchorPoint(AnchorPoint::BOTTOM_RIGHT);
532   Stage::GetCurrent().Add(tempActor);
533   detector.Attach(tempActor);
534
535   // Actor lifetime is scoped
536   {
537     Actor actor = Actor::New();
538     actor.SetSize(100.0f, 100.0f);
539     actor.SetAnchorPoint(AnchorPoint::TOP_LEFT);
540     Stage::GetCurrent().Add(actor);
541
542     // Render and notify
543     application.SendNotification();
544     application.Render();
545
546     detector.Attach(actor);
547
548     // Start pinch within the actor's area
549     application.ProcessEvent(GeneratePinch(Gesture::Started, 10.0f, 50.0f, Vector2(10.0f, 10.0f)));
550     DALI_TEST_EQUALS(true, data.functorCalled, TEST_LOCATION);
551     DALI_TEST_EQUALS(Gesture::Started, data.receivedGesture.state, TEST_LOCATION);
552
553     // Continue the pinch within the actor's area - we should still receive the signal
554     data.Reset();
555     application.ProcessEvent(GeneratePinch(Gesture::Continuing, 5.0f, 25.0f, Vector2(20.0f, 20.0f)));
556     DALI_TEST_EQUALS(true, data.functorCalled, TEST_LOCATION);
557     DALI_TEST_EQUALS(Gesture::Continuing, data.receivedGesture.state, TEST_LOCATION);
558
559     // Remove the actor from stage and reset the data
560     Stage::GetCurrent().Remove(actor);
561
562     // Render and notify
563     application.SendNotification();
564     application.Render();
565   }
566
567   // Actor should now have been destroyed
568
569   // Gesture ends within the area where the actor used to be
570   data.Reset();
571   application.ProcessEvent(GeneratePinch(Gesture::Finished, 5.0f, 25.0f, Vector2(20.0f, 20.0f)));
572   DALI_TEST_EQUALS(false, data.functorCalled, TEST_LOCATION);
573   END_TEST;
574 }
575
576 int UtcDaliPinchGestureSignalReceptionRotatedActor(void)
577 {
578   TestApplication application;
579
580   Actor actor = Actor::New();
581   actor.SetSize(100.0f, 100.0f);
582   actor.SetOrientation(Dali::Degree(90.0f), Vector3::ZAXIS);
583   Stage::GetCurrent().Add(actor);
584
585   // Render and notify a couple of times
586   application.SendNotification();
587   application.Render();
588
589   SignalData data;
590   GestureReceivedFunctor functor(data);
591
592   PinchGestureDetector detector = PinchGestureDetector::New();
593   detector.Attach(actor);
594   detector.DetectedSignal().Connect(&application, functor);
595
596   // Do an entire pinch, only check finished value
597   application.ProcessEvent(GeneratePinch(Gesture::Started, 10.0f, 50.0f, Vector2(10.0f, 10.0f)));
598   data.Reset();
599   application.ProcessEvent(GeneratePinch(Gesture::Finished, 10.0f, 50.0f, Vector2(10.0f, 10.0f)));
600   DALI_TEST_EQUALS(true, data.functorCalled, TEST_LOCATION);
601   DALI_TEST_EQUALS(10.0f, data.receivedGesture.scale, 0.01f, TEST_LOCATION);
602   DALI_TEST_EQUALS(50.0f, data.receivedGesture.speed, 0.01f, TEST_LOCATION);
603   DALI_TEST_EQUALS(Vector2(10.0f, 10.0f), data.receivedGesture.screenCenterPoint, 0.01f, TEST_LOCATION);
604
605   // Rotate actor again and render and notify
606   actor.SetOrientation(Dali::Degree(180.0f), Vector3::ZAXIS);
607   application.SendNotification();
608   application.Render();
609
610   // Do an entire pinch, only check finished value
611   application.ProcessEvent(GeneratePinch(Gesture::Started, 10.0f, 50.0f, Vector2(10.0f, 10.0f)));
612   data.Reset();
613   application.ProcessEvent(GeneratePinch(Gesture::Finished, 10.0f, 50.0f, Vector2(10.0f, 10.0f)));
614   DALI_TEST_EQUALS(true, data.functorCalled, TEST_LOCATION);
615   DALI_TEST_EQUALS(10.0f, data.receivedGesture.scale, 0.01f, TEST_LOCATION);
616   DALI_TEST_EQUALS(50.0f, data.receivedGesture.speed, 0.01f, TEST_LOCATION);
617   DALI_TEST_EQUALS(Vector2(10.0f, 10.0f), data.receivedGesture.screenCenterPoint, 0.01f, TEST_LOCATION);
618
619   // Rotate actor again and render and notify
620   actor.SetOrientation(Dali::Degree(270.0f), Vector3::ZAXIS);
621   application.SendNotification();
622   application.Render();
623
624   // Do an entire pinch, only check finished value
625   application.ProcessEvent(GeneratePinch(Gesture::Started, 10.0f, 50.0f, Vector2(10.0f, 10.0f)));
626   data.Reset();
627   application.ProcessEvent(GeneratePinch(Gesture::Finished, 10.0f, 50.0f, Vector2(10.0f, 10.0f)));
628   DALI_TEST_EQUALS(true, data.functorCalled, TEST_LOCATION);
629   DALI_TEST_EQUALS(10.0f, data.receivedGesture.scale, 0.01f, TEST_LOCATION);
630   DALI_TEST_EQUALS(50.0f, data.receivedGesture.speed, 0.01f, TEST_LOCATION);
631   DALI_TEST_EQUALS(Vector2(10.0f, 10.0f), data.receivedGesture.screenCenterPoint, 0.01f, TEST_LOCATION);
632   END_TEST;
633 }
634
635 int UtcDaliPinchGestureSignalReceptionChildHit(void)
636 {
637   TestApplication application;
638
639   Actor parent = Actor::New();
640   parent.SetSize(100.0f, 100.0f);
641   parent.SetAnchorPoint(AnchorPoint::TOP_LEFT);
642   Stage::GetCurrent().Add(parent);
643
644   // Set child to completely cover parent.
645   // Change rotation of child to be different from parent so that we can check if our local coordinate
646   // conversion of the parent actor is correct.
647   Actor child = Actor::New();
648   child.SetSize(100.0f, 100.0f);
649   child.SetAnchorPoint(AnchorPoint::CENTER);
650   child.SetParentOrigin(ParentOrigin::CENTER);
651   child.SetOrientation(Dali::Degree(90.0f), Vector3::ZAXIS);
652   parent.Add(child);
653
654   TouchEventFunctor touchFunctor;
655   child.TouchedSignal().Connect(&application, touchFunctor);
656
657   // Render and notify
658   application.SendNotification();
659   application.Render();
660
661   SignalData data;
662   GestureReceivedFunctor functor(data);
663
664   PinchGestureDetector detector = PinchGestureDetector::New();
665   detector.Attach(parent);
666   detector.DetectedSignal().Connect(&application, functor);
667
668   // Do an entire pan, only check finished value - hits child area but parent should still receive it
669   application.ProcessEvent(GeneratePinch(Gesture::Started, 10.0f, 50.0f, Vector2(10.0f, 10.0f)));
670   data.Reset();
671   application.ProcessEvent(GeneratePinch(Gesture::Finished, 5.0f, 50.0f, Vector2(10.0f, 10.0f)));
672   DALI_TEST_EQUALS(true, data.functorCalled, TEST_LOCATION);
673   DALI_TEST_EQUALS(true, parent == data.pinchedActor, TEST_LOCATION);
674   DALI_TEST_EQUALS(5.0f, data.receivedGesture.scale, 0.01f, TEST_LOCATION);
675   DALI_TEST_EQUALS(50.0f, data.receivedGesture.speed, 0.01f, TEST_LOCATION);
676   DALI_TEST_EQUALS(Vector2(10.0f, 10.0f), data.receivedGesture.screenCenterPoint, 0.01f, TEST_LOCATION);
677
678   // Attach child and generate same touch points to yield same results
679   // (Also proves that you can detach and then re-attach another actor)
680   detector.Attach(child);
681   detector.Detach(parent);
682
683   // Do an entire pan, only check finished value
684   application.ProcessEvent(GeneratePinch(Gesture::Started, 10.0f, 50.0f, Vector2(10.0f, 10.0f)));
685   data.Reset();
686   application.ProcessEvent(GeneratePinch(Gesture::Finished, 5.0f, 50.0f, Vector2(10.0f, 10.0f)));
687   DALI_TEST_EQUALS(true, data.functorCalled, TEST_LOCATION);
688   DALI_TEST_EQUALS(true, child == data.pinchedActor, TEST_LOCATION);
689   DALI_TEST_EQUALS(5.0f, data.receivedGesture.scale, 0.01f, TEST_LOCATION);
690   DALI_TEST_EQUALS(50.0f, data.receivedGesture.speed, 0.01f, TEST_LOCATION);
691   DALI_TEST_EQUALS(Vector2(10.0f, 10.0f), data.receivedGesture.screenCenterPoint, 0.01f, TEST_LOCATION);
692   END_TEST;
693 }
694
695 int UtcDaliPinchGestureSignalReceptionAttachDetachMany(void)
696 {
697   TestApplication application;
698
699   Actor first = Actor::New();
700   first.SetSize(100.0f, 100.0f);
701   first.SetAnchorPoint(AnchorPoint::TOP_LEFT);
702   Stage::GetCurrent().Add(first);
703
704   Actor second = Actor::New();
705   second.SetSize(100.0f, 100.0f);
706   second.SetX(100.0f);
707   second.SetAnchorPoint(AnchorPoint::TOP_LEFT);
708   Stage::GetCurrent().Add(second);
709
710   // Render and notify
711   application.SendNotification();
712   application.Render();
713
714   SignalData data;
715   GestureReceivedFunctor functor(data);
716
717   PinchGestureDetector detector = PinchGestureDetector::New();
718   detector.Attach(first);
719   detector.Attach(second);
720   detector.DetectedSignal().Connect(&application, functor);
721
722   // Start pinch within second actor's area
723   application.ProcessEvent(GeneratePinch(Gesture::Started, 10.0f, 50.0f, Vector2(120.0f, 10.0f)));
724   DALI_TEST_EQUALS(true, data.functorCalled, TEST_LOCATION);
725   DALI_TEST_EQUALS(true, second == data.pinchedActor, TEST_LOCATION);
726
727   // Pinch moves into first actor's area - second actor should receive the pinch
728   data.Reset();
729   application.ProcessEvent(GeneratePinch(Gesture::Continuing, 10.0f, 50.0f, Vector2(10.0f, 10.0f)));
730   DALI_TEST_EQUALS(true, data.functorCalled, TEST_LOCATION);
731   DALI_TEST_EQUALS(true, second == data.pinchedActor, TEST_LOCATION);
732
733   // Detach the second actor during the pinch, we should not receive the next event
734   detector.Detach(second);
735
736   // Gesture ends within actor's area
737   data.Reset();
738   application.ProcessEvent(GeneratePinch(Gesture::Finished, 10.0f, 50.0f, Vector2(120.0f, 10.0f)));
739   DALI_TEST_EQUALS(false, data.functorCalled, TEST_LOCATION);
740   END_TEST;
741 }
742
743 int UtcDaliPinchGestureSignalReceptionActorBecomesUntouchable(void)
744 {
745   TestApplication application;
746
747   Actor actor = Actor::New();
748   actor.SetSize(100.0f, 100.0f);
749   actor.SetAnchorPoint(AnchorPoint::TOP_LEFT);
750   Stage::GetCurrent().Add(actor);
751
752   // Render and notify
753   application.SendNotification();
754   application.Render();
755
756   SignalData data;
757   GestureReceivedFunctor functor(data);
758
759   PinchGestureDetector detector = PinchGestureDetector::New();
760   detector.Attach(actor);
761   detector.DetectedSignal().Connect(&application, functor);
762
763   // Start pinch in actor's area
764   application.ProcessEvent(GeneratePinch(Gesture::Started, 10.0f, 50.0f, Vector2(20.0f, 10.0f)));
765   DALI_TEST_EQUALS(true, data.functorCalled, TEST_LOCATION);
766
767   // Pan continues within actor's area
768   data.Reset();
769   application.ProcessEvent(GeneratePinch(Gesture::Started, 5.0f, 50.0f, Vector2(10.0f, 10.0f)));
770   DALI_TEST_EQUALS(true, data.functorCalled, TEST_LOCATION);
771
772   // Actor become invisible - actor should not receive the next pinch
773   actor.SetVisible(false);
774
775   // Render and notify
776   application.SendNotification();
777   application.Render();
778
779   // Gesture ends within actor's area
780   data.Reset();
781   application.ProcessEvent(GeneratePinch(Gesture::Finished, 5.0f, 50.0f, Vector2(10.0f, 10.0f)));
782   DALI_TEST_EQUALS(false, data.functorCalled, TEST_LOCATION);
783   END_TEST;
784 }
785
786 int UtcDaliPinchGestureSignalReceptionMultipleDetectorsOnActor(void)
787 {
788   TestApplication application;
789
790   Actor actor = Actor::New();
791   actor.SetSize(100.0f, 100.0f);
792   actor.SetAnchorPoint(AnchorPoint::TOP_LEFT);
793   Stage::GetCurrent().Add(actor);
794
795   Actor actor2 = Actor::New();
796   actor2.SetSize(100.0f, 100.0f);
797   actor2.SetAnchorPoint(AnchorPoint::BOTTOM_RIGHT);
798   Stage::GetCurrent().Add(actor2);
799
800   // Render and notify
801   application.SendNotification();
802   application.Render();
803
804   // Attach actor to one detector
805   SignalData firstData;
806   GestureReceivedFunctor firstFunctor(firstData);
807   PinchGestureDetector firstDetector = PinchGestureDetector::New();
808   firstDetector.Attach(actor);
809   firstDetector.DetectedSignal().Connect(&application, firstFunctor);
810
811   // Attach actor to another detector
812   SignalData secondData;
813   GestureReceivedFunctor secondFunctor(secondData);
814   PinchGestureDetector secondDetector = PinchGestureDetector::New();
815   secondDetector.Attach(actor);
816   secondDetector.DetectedSignal().Connect(&application, secondFunctor);
817
818   // Add second actor to second detector, when we remove the actor, this will make sure that this
819   // gesture detector is not removed from the GestureDetectorProcessor.  In this scenario, the
820   // functor should still not be called (which is what we're also testing).
821   secondDetector.Attach(actor2);
822
823   // Pinch in actor's area - both detector's functors should be called
824   application.ProcessEvent(GeneratePinch(Gesture::Started, 10.0f, 50.0f, Vector2(20.0f, 10.0f)));
825   DALI_TEST_EQUALS(true, firstData.functorCalled, TEST_LOCATION);
826   DALI_TEST_EQUALS(true, secondData.functorCalled, TEST_LOCATION);
827
828   // Pinch continues in actor's area - both detector's functors should be called
829   firstData.Reset();
830   secondData.Reset();
831   application.ProcessEvent(GeneratePinch(Gesture::Continuing, 10.0f, 50.0f, Vector2(20.0f, 10.0f)));
832   DALI_TEST_EQUALS(true, firstData.functorCalled, TEST_LOCATION);
833   DALI_TEST_EQUALS(true, secondData.functorCalled, TEST_LOCATION);
834
835   // Detach actor from firstDetector and emit pinch on actor, only secondDetector's functor should be called.
836   firstDetector.Detach(actor);
837   firstData.Reset();
838   secondData.Reset();
839   application.ProcessEvent(GeneratePinch(Gesture::Finished, 10.0f, 50.0f, Vector2(20.0f, 10.0f)));
840   DALI_TEST_EQUALS(false, firstData.functorCalled, TEST_LOCATION);
841   DALI_TEST_EQUALS(true, secondData.functorCalled, TEST_LOCATION);
842
843   // New pinch on actor, only secondDetector has actor attached
844   firstData.Reset();
845   secondData.Reset();
846   application.ProcessEvent(GeneratePinch(Gesture::Started, 10.0f, 50.0f, Vector2(20.0f, 10.0f)));
847   DALI_TEST_EQUALS(false, firstData.functorCalled, TEST_LOCATION);
848   DALI_TEST_EQUALS(true, secondData.functorCalled, TEST_LOCATION);
849
850   // Detach actor from secondDetector
851   secondDetector.Detach(actor);
852   firstData.Reset();
853   secondData.Reset();
854   application.ProcessEvent(GeneratePinch(Gesture::Continuing, 10.0f, 50.0f, Vector2(20.0f, 10.0f)));
855   DALI_TEST_EQUALS(false, firstData.functorCalled, TEST_LOCATION);
856   DALI_TEST_EQUALS(false, secondData.functorCalled, TEST_LOCATION);
857   END_TEST;
858 }
859
860 int UtcDaliPinchGestureSignalReceptionMultipleStarted(void)
861 {
862   // Should handle two started events gracefully.
863
864   TestApplication application;
865
866   Actor actor = Actor::New();
867   actor.SetSize(100.0f, 100.0f);
868   actor.SetAnchorPoint(AnchorPoint::TOP_LEFT);
869   Stage::GetCurrent().Add(actor);
870
871   SignalData data;
872   GestureReceivedFunctor functor(data);
873
874   PinchGestureDetector detector = PinchGestureDetector::New();
875   detector.Attach(actor);
876   detector.DetectedSignal().Connect(&application, functor);
877
878   // Render and notify
879   application.SendNotification();
880   application.Render();
881
882   // Start pan in actor's area
883   application.ProcessEvent(GeneratePinch(Gesture::Started, 10.0f, 50.0f, Vector2(20.0f, 10.0f)));
884   DALI_TEST_EQUALS(true, data.functorCalled, TEST_LOCATION);
885
886   // Send another start in actor's area
887   data.Reset();
888   application.ProcessEvent(GeneratePinch(Gesture::Started, 10.0f, 50.0f, Vector2(20.0f, 10.0f)));
889   DALI_TEST_EQUALS(true, data.functorCalled, TEST_LOCATION);
890
891   // Add a child actor to overlap actor and send another start in actor's area
892   Actor child = Actor::New();
893   child.SetSize(100.0f, 100.0f);
894   child.SetAnchorPoint(AnchorPoint::CENTER);
895   child.SetParentOrigin(ParentOrigin::CENTER);
896   actor.Add(child);
897
898   TouchEventFunctor touchFunctor;
899   child.TouchedSignal().Connect(&application, touchFunctor);
900
901   // Render and notify
902   application.SendNotification();
903   application.Render();
904
905   // Send another start in actor's area
906   data.Reset();
907   application.ProcessEvent(GeneratePinch(Gesture::Started, 10.0f, 50.0f, Vector2(20.0f, 10.0f)));
908   DALI_TEST_EQUALS(true, data.functorCalled, TEST_LOCATION);
909
910   // Send another start in actor's area
911   data.Reset();
912   application.ProcessEvent(GeneratePinch(Gesture::Started, 10.0f, 50.0f, Vector2(20.0f, 10.0f)));
913   DALI_TEST_EQUALS(true, data.functorCalled, TEST_LOCATION);
914   END_TEST;
915 }
916
917 int UtcDaliPinchGestureSignalReceptionEnsureCorrectSignalling(void)
918 {
919   TestApplication application;
920
921   Actor actor1 = Actor::New();
922   actor1.SetSize(100.0f, 100.0f);
923   actor1.SetAnchorPoint(AnchorPoint::TOP_LEFT);
924   Stage::GetCurrent().Add(actor1);
925   SignalData data1;
926   GestureReceivedFunctor functor1(data1);
927   PinchGestureDetector detector1 = PinchGestureDetector::New();
928   detector1.Attach(actor1);
929   detector1.DetectedSignal().Connect(&application, functor1);
930
931   Actor actor2 = Actor::New();
932   actor2.SetSize(100.0f, 100.0f);
933   actor2.SetAnchorPoint(AnchorPoint::BOTTOM_RIGHT);
934   actor2.SetParentOrigin(ParentOrigin::BOTTOM_RIGHT);
935   Stage::GetCurrent().Add(actor2);
936   SignalData data2;
937   GestureReceivedFunctor functor2(data2);
938   PinchGestureDetector detector2 = PinchGestureDetector::New();
939   detector2.Attach(actor2);
940   detector2.DetectedSignal().Connect(&application, functor2);
941
942   // Render and notify
943   application.SendNotification();
944   application.Render();
945
946   // Start pan in actor1's area, only data1 should be set
947   application.ProcessEvent(GeneratePinch(Gesture::Started, 10.0f, 50.0f, Vector2(20.0f, 10.0f)));
948   DALI_TEST_EQUALS(true, data1.functorCalled, TEST_LOCATION);
949   DALI_TEST_EQUALS(false, data2.functorCalled, TEST_LOCATION);
950   END_TEST;
951 }
952
953 int UtcDaliPinchGestureEmitIncorrectStateClear(void)
954 {
955   TestApplication application;
956
957   Actor actor = Actor::New();
958   actor.SetSize(100.0f, 100.0f);
959   actor.SetAnchorPoint(AnchorPoint::TOP_LEFT);
960   Stage::GetCurrent().Add(actor);
961
962   // Render and notify
963   application.SendNotification();
964   application.Render();
965
966   // Attach actor to detector
967   SignalData data;
968   GestureReceivedFunctor functor( data );
969   PinchGestureDetector detector = PinchGestureDetector::New();
970   detector.Attach(actor);
971   detector.DetectedSignal().Connect( &application, functor );
972
973   // Try a Clear state
974   try
975   {
976     application.ProcessEvent(GeneratePinch(Gesture::Clear, 10.0f, 50.0f, Vector2(20.0f, 10.0f)));
977     tet_result(TET_FAIL);
978   }
979   catch ( Dali::DaliException& e )
980   {
981     DALI_TEST_ASSERT( e, "false", TEST_LOCATION );
982   }
983   END_TEST;
984 }
985
986 int UtcDaliPinchGestureEmitIncorrectStatePossible(void)
987 {
988   TestApplication application;
989
990   Actor actor = Actor::New();
991   actor.SetSize(100.0f, 100.0f);
992   actor.SetAnchorPoint(AnchorPoint::TOP_LEFT);
993   Stage::GetCurrent().Add(actor);
994
995   // Render and notify
996   application.SendNotification();
997   application.Render();
998
999   // Attach actor to detector
1000   SignalData data;
1001   GestureReceivedFunctor functor( data );
1002   PinchGestureDetector detector = PinchGestureDetector::New();
1003   detector.Attach(actor);
1004   detector.DetectedSignal().Connect( &application, functor );
1005
1006   // Try a Possible state
1007   try
1008   {
1009     application.ProcessEvent(GeneratePinch(Gesture::Possible, 10.0f, 50.0f, Vector2(20.0f, 10.0f)));
1010     tet_result(TET_FAIL);
1011   }
1012   catch ( Dali::DaliException& e )
1013   {
1014     DALI_TEST_ASSERT( e, "false", TEST_LOCATION );
1015   }
1016   END_TEST;
1017 }
1018
1019 int UtcDaliPinchGestureActorUnstaged(void)
1020 {
1021   TestApplication application;
1022
1023   Actor actor = Actor::New();
1024   actor.SetSize(100.0f, 100.0f);
1025   actor.SetAnchorPoint(AnchorPoint::TOP_LEFT);
1026   Stage::GetCurrent().Add(actor);
1027
1028   // Render and notify
1029   application.SendNotification();
1030   application.Render();
1031
1032   // State to remove actor in.
1033   Gesture::State stateToUnstage( Gesture::Started );
1034
1035   // Attach actor to detector
1036   SignalData data;
1037   UnstageActorFunctor functor( data, stateToUnstage );
1038   PinchGestureDetector detector = PinchGestureDetector::New();
1039   detector.Attach(actor);
1040   detector.DetectedSignal().Connect( &application, functor );
1041
1042   // Emit signals
1043   application.ProcessEvent(GeneratePinch(Gesture::Started, 10.0f, 50.0f, Vector2(20.0f, 10.0f)));
1044   DALI_TEST_EQUALS(true, data.functorCalled, TEST_LOCATION);
1045   data.Reset();
1046   application.ProcessEvent(GeneratePinch(Gesture::Finished, 10.0f, 50.0f, Vector2(20.0f, 10.0f)));
1047   DALI_TEST_EQUALS(false, data.functorCalled, TEST_LOCATION);
1048   data.Reset();
1049
1050   // Render and notify
1051   application.SendNotification();
1052   application.Render();
1053
1054   // Re-add actor to stage
1055   Stage::GetCurrent().Add(actor);
1056
1057   // Render and notify
1058   application.SendNotification();
1059   application.Render();
1060
1061   // Change state to Gesture::Continuing to remove
1062   stateToUnstage = Gesture::Continuing;
1063
1064   // Emit signals
1065   application.ProcessEvent(GeneratePinch(Gesture::Started, 10.0f, 50.0f, Vector2(20.0f, 10.0f)));
1066   DALI_TEST_EQUALS(true, data.functorCalled, TEST_LOCATION);
1067   data.Reset();
1068   application.ProcessEvent(GeneratePinch(Gesture::Continuing, 10.0f, 50.0f, Vector2(20.0f, 10.0f)));
1069   DALI_TEST_EQUALS(true, data.functorCalled, TEST_LOCATION);
1070   data.Reset();
1071   application.ProcessEvent(GeneratePinch(Gesture::Finished, 10.0f, 50.0f, Vector2(20.0f, 10.0f)));
1072   DALI_TEST_EQUALS(false, data.functorCalled, TEST_LOCATION);
1073   data.Reset();
1074
1075   // Render and notify
1076   application.SendNotification();
1077   application.Render();
1078
1079   // Re-add actor to stage
1080   Stage::GetCurrent().Add(actor);
1081
1082   // Render and notify
1083   application.SendNotification();
1084   application.Render();
1085
1086   // Change state to Gesture::Continuing to remove
1087   stateToUnstage = Gesture::Finished;
1088
1089   // Emit signals
1090   application.ProcessEvent(GeneratePinch(Gesture::Started, 10.0f, 50.0f, Vector2(20.0f, 10.0f)));
1091   DALI_TEST_EQUALS(true, data.functorCalled, TEST_LOCATION);
1092   data.Reset();
1093   application.ProcessEvent(GeneratePinch(Gesture::Continuing, 10.0f, 50.0f, Vector2(20.0f, 10.0f)));
1094   DALI_TEST_EQUALS(true, data.functorCalled, TEST_LOCATION);
1095   data.Reset();
1096   application.ProcessEvent(GeneratePinch(Gesture::Finished, 10.0f, 50.0f, Vector2(20.0f, 10.0f)));
1097   DALI_TEST_EQUALS(true, data.functorCalled, TEST_LOCATION);
1098   tet_result( TET_PASS ); // If we get here then we have handled actor stage removal gracefully.
1099   END_TEST;
1100 }
1101
1102 int UtcDaliPinchGestureActorStagedAndDestroyed(void)
1103 {
1104   TestApplication application;
1105
1106   Actor actor = Actor::New();
1107   actor.SetSize(100.0f, 100.0f);
1108   actor.SetAnchorPoint(AnchorPoint::TOP_LEFT);
1109   Stage::GetCurrent().Add(actor);
1110
1111   // Create and add a second actor so that GestureDetector destruction does not come into play.
1112   Actor dummyActor( Actor::New() );
1113   dummyActor.SetSize( 100.0f, 100.0f );
1114   dummyActor.SetPosition( 100.0f, 100.0f );
1115   dummyActor.SetAnchorPoint(AnchorPoint::TOP_LEFT);
1116   Stage::GetCurrent().Add(dummyActor);
1117
1118   // Render and notify
1119   application.SendNotification();
1120   application.Render();
1121
1122   // State to remove actor in.
1123   Gesture::State stateToUnstage( Gesture::Started );
1124
1125   // Attach actor to detector
1126   SignalData data;
1127   UnstageActorFunctor functor( data, stateToUnstage );
1128   PinchGestureDetector detector = PinchGestureDetector::New();
1129   detector.Attach(actor);
1130   detector.Attach(dummyActor);
1131   detector.DetectedSignal().Connect( &application, functor );
1132
1133   // Here we are testing a Started actor which is removed in the Started callback, but then added back
1134   // before we get a continuing state.  As we were removed from the stage, even if we're at the same
1135   // position, we should still not be signalled.
1136
1137   // Emit signals
1138   application.ProcessEvent(GeneratePinch(Gesture::Started, 10.0f, 50.0f, Vector2(20.0f, 10.0f)));
1139   DALI_TEST_EQUALS(true, data.functorCalled, TEST_LOCATION);
1140   data.Reset();
1141
1142   // Render and notify
1143   application.SendNotification();
1144   application.Render();
1145
1146   // Re add to the stage, we should not be signalled
1147   Stage::GetCurrent().Add(actor);
1148
1149   // Render and notify
1150   application.SendNotification();
1151   application.Render();
1152
1153   // Continue signal emission
1154   application.ProcessEvent(GeneratePinch(Gesture::Continuing, 10.0f, 50.0f, Vector2(20.0f, 10.0f)));
1155   DALI_TEST_EQUALS(false, data.functorCalled, TEST_LOCATION);
1156   data.Reset();
1157   application.ProcessEvent(GeneratePinch(Gesture::Finished, 10.0f, 50.0f, Vector2(20.0f, 10.0f)));
1158   DALI_TEST_EQUALS(false, data.functorCalled, TEST_LOCATION);
1159   data.Reset();
1160
1161   // Here we delete an actor in started, we should not receive any subsequent signalling.
1162
1163   // Emit signals
1164   application.ProcessEvent(GeneratePinch(Gesture::Started, 10.0f, 50.0f, Vector2(20.0f, 10.0f)));
1165   DALI_TEST_EQUALS(true, data.functorCalled, TEST_LOCATION);
1166   data.Reset();
1167
1168   // Render and notify
1169   application.SendNotification();
1170   application.Render();
1171
1172   // Delete actor as well
1173   actor.Reset();
1174
1175   // Render and notify
1176   application.SendNotification();
1177   application.Render();
1178
1179   // Continue signal emission
1180   application.ProcessEvent(GeneratePinch(Gesture::Continuing, 10.0f, 50.0f, Vector2(20.0f, 10.0f)));
1181   DALI_TEST_EQUALS(false, data.functorCalled, TEST_LOCATION);
1182   data.Reset();
1183   application.ProcessEvent(GeneratePinch(Gesture::Finished, 10.0f, 50.0f, Vector2(20.0f, 10.0f)));
1184   DALI_TEST_EQUALS(false, data.functorCalled, TEST_LOCATION);
1185   END_TEST;
1186 }
1187
1188 int UtcDaliPinchGestureSystemOverlay(void)
1189 {
1190   TestApplication application;
1191   Dali::Integration::Core& core = application.GetCore();
1192   Dali::Integration::SystemOverlay& systemOverlay( core.GetSystemOverlay() );
1193   systemOverlay.GetOverlayRenderTasks().CreateTask();
1194
1195   Actor actor = Actor::New();
1196   actor.SetSize(100.0f, 100.0f);
1197   actor.SetAnchorPoint(AnchorPoint::TOP_LEFT);
1198   systemOverlay.Add(actor);
1199
1200   // Render and notify
1201   application.SendNotification();
1202   application.Render();
1203
1204   SignalData data;
1205   GestureReceivedFunctor functor(data);
1206
1207   PinchGestureDetector detector = PinchGestureDetector::New();
1208   detector.Attach(actor);
1209   detector.DetectedSignal().Connect(&application, functor);
1210
1211   Vector2 screenCoords( 50.0f, 50.0f );
1212   float scale ( 10.0f );
1213   float speed ( 50.0f );
1214
1215   // Start pan within the actor's area
1216   application.ProcessEvent( GeneratePinch( Gesture::Started, scale, speed, screenCoords ) );
1217   DALI_TEST_EQUALS( true, data.functorCalled, TEST_LOCATION );
1218   END_TEST;
1219 }
1220
1221 int UtcDaliPinchGestureBehindTouchableSystemOverlay(void)
1222 {
1223   TestApplication application;
1224   Dali::Integration::Core& core = application.GetCore();
1225   Dali::Integration::SystemOverlay& systemOverlay( core.GetSystemOverlay() );
1226   systemOverlay.GetOverlayRenderTasks().CreateTask();
1227
1228   // SystemOverlay actor
1229   Actor systemOverlayActor = Actor::New();
1230   systemOverlayActor.SetSize(100.0f, 100.0f);
1231   systemOverlayActor.SetAnchorPoint(AnchorPoint::TOP_LEFT);
1232   systemOverlay.Add(systemOverlayActor);
1233
1234   // Stage actor
1235   Actor stageActor = Actor::New();
1236   stageActor.SetSize(100.0f, 100.0f);
1237   stageActor.SetAnchorPoint(AnchorPoint::TOP_LEFT);
1238   Stage::GetCurrent().Add(stageActor);
1239
1240   // Render and notify
1241   application.SendNotification();
1242   application.Render();
1243
1244   // Set system-overlay actor to touchable
1245   TouchEventData touchData;
1246   TouchEventDataFunctor touchFunctor( touchData );
1247   systemOverlayActor.TouchedSignal().Connect(&application, touchFunctor);
1248
1249   // Set stage actor to receive the gesture
1250   SignalData data;
1251   GestureReceivedFunctor functor(data);
1252
1253   PinchGestureDetector detector = PinchGestureDetector::New();
1254   detector.Attach(stageActor);
1255   detector.DetectedSignal().Connect(&application, functor);
1256
1257   Vector2 screenCoords( 50.0f, 50.0f );
1258   float scale ( 10.0f );
1259   float speed ( 50.0f );
1260
1261   // Start pinch within the two actors' area
1262   application.ProcessEvent( GeneratePinch( Gesture::Started, scale, speed, screenCoords ) );
1263   application.ProcessEvent( GeneratePinch( Gesture::Finished, scale, speed, screenCoords ) );
1264   DALI_TEST_EQUALS( true, data.functorCalled, TEST_LOCATION );
1265   DALI_TEST_EQUALS( false, touchData.functorCalled, TEST_LOCATION );
1266
1267   data.Reset();
1268   touchData.Reset();
1269
1270   // Do touch in the same area
1271   application.ProcessEvent( touchFunctor.GenerateSingleTouch( PointState::DOWN, screenCoords ) );
1272   DALI_TEST_EQUALS( false, data.functorCalled, TEST_LOCATION );
1273   DALI_TEST_EQUALS( true, touchData.functorCalled, TEST_LOCATION );
1274
1275   END_TEST;
1276 }
1277
1278 int UtcDaliPinchGestureTouchBehindGesturedSystemOverlay(void)
1279 {
1280   TestApplication application;
1281   Dali::Integration::Core& core = application.GetCore();
1282   Dali::Integration::SystemOverlay& systemOverlay( core.GetSystemOverlay() );
1283   systemOverlay.GetOverlayRenderTasks().CreateTask();
1284
1285   // SystemOverlay actor
1286   Actor systemOverlayActor = Actor::New();
1287   systemOverlayActor.SetSize(100.0f, 100.0f);
1288   systemOverlayActor.SetAnchorPoint(AnchorPoint::TOP_LEFT);
1289   systemOverlay.Add(systemOverlayActor);
1290
1291   // Stage actor
1292   Actor stageActor = Actor::New();
1293   stageActor.SetSize(100.0f, 100.0f);
1294   stageActor.SetAnchorPoint(AnchorPoint::TOP_LEFT);
1295   Stage::GetCurrent().Add(stageActor);
1296
1297   // Render and notify
1298   application.SendNotification();
1299   application.Render();
1300
1301   // Set stage actor to touchable
1302   TouchEventData touchData;
1303   TouchEventDataFunctor touchFunctor( touchData );
1304   stageActor.TouchedSignal().Connect(&application, touchFunctor);
1305
1306   // Set system-overlay actor to have the gesture
1307   SignalData data;
1308   GestureReceivedFunctor functor(data);
1309
1310   PinchGestureDetector detector = PinchGestureDetector::New();
1311   detector.Attach(systemOverlayActor);
1312   detector.DetectedSignal().Connect(&application, functor);
1313
1314   Vector2 screenCoords( 50.0f, 50.0f );
1315   float scale ( 10.0f );
1316   float speed ( 50.0f );
1317
1318   // Start pinch within the two actors' area
1319   application.ProcessEvent( GeneratePinch( Gesture::Started, scale, speed, screenCoords ) );
1320   application.ProcessEvent( GeneratePinch( Gesture::Finished, scale, speed, screenCoords ) );
1321   DALI_TEST_EQUALS( true, data.functorCalled, TEST_LOCATION );
1322   DALI_TEST_EQUALS( false, touchData.functorCalled, TEST_LOCATION );
1323
1324   data.Reset();
1325   touchData.Reset();
1326
1327   // Do touch in the same area
1328   application.ProcessEvent( touchFunctor.GenerateSingleTouch( PointState::DOWN, screenCoords ) );
1329   DALI_TEST_EQUALS( false, data.functorCalled, TEST_LOCATION );
1330   DALI_TEST_EQUALS( true, touchData.functorCalled, TEST_LOCATION );
1331
1332   END_TEST;
1333 }
1334
1335 int UtcDaliPinchGestureLayerConsumesTouch(void)
1336 {
1337   TestApplication application;
1338
1339   Actor actor = Actor::New();
1340   actor.SetSize(100.0f, 100.0f);
1341   actor.SetAnchorPoint(AnchorPoint::TOP_LEFT);
1342   Stage::GetCurrent().Add(actor);
1343
1344   // Add a detector
1345   SignalData data;
1346   GestureReceivedFunctor functor(data);
1347   PinchGestureDetector detector = PinchGestureDetector::New();
1348   detector.Attach(actor);
1349   detector.DetectedSignal().Connect( &application, functor );
1350
1351   // Add a layer to overlap the actor
1352   Layer layer = Layer::New();
1353   layer.SetSize(100.0f, 100.0f);
1354   layer.SetAnchorPoint(AnchorPoint::TOP_LEFT);
1355   Stage::GetCurrent().Add( layer );
1356   layer.RaiseToTop();
1357
1358   // Render and notify
1359   application.SendNotification();
1360   application.Render();
1361
1362   Vector2 screenCoords( 50.0f, 50.0f );
1363   float scale ( 10.0f );
1364   float speed ( 50.0f );
1365
1366   // Emit signals, should receive
1367   application.ProcessEvent( GeneratePinch( Gesture::Started, scale, speed, screenCoords ) );
1368   application.ProcessEvent( GeneratePinch( Gesture::Finished, scale, speed, screenCoords ) );
1369   DALI_TEST_EQUALS(true, data.functorCalled, TEST_LOCATION);
1370   data.Reset();
1371
1372   // Set layer to consume all touch
1373   layer.SetTouchConsumed( true );
1374
1375   // Render and notify
1376   application.SendNotification();
1377   application.Render();
1378
1379   // Emit the same signals again, should not receive
1380   application.ProcessEvent( GeneratePinch( Gesture::Started, scale, speed, screenCoords ) );
1381   application.ProcessEvent( GeneratePinch( Gesture::Finished, scale, speed, screenCoords ) );
1382   DALI_TEST_EQUALS(false, data.functorCalled, TEST_LOCATION);
1383   data.Reset();
1384
1385   END_TEST;
1386 }