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