[dali_1.4.7] 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/integration-api/render-task-list-integ.h>
26 #include <dali-test-suite-utils.h>
27 #include <test-touch-utils.h>
28
29 using namespace Dali;
30
31 void utc_dali_pinch_gesture_detector_startup(void)
32 {
33   test_return_value = TET_UNDEF;
34 }
35
36 void utc_dali_pinch_gesture_detector_cleanup(void)
37 {
38   test_return_value = TET_PASS;
39 }
40
41 ///////////////////////////////////////////////////////////////////////////////
42 namespace
43 {
44
45 // Stores data that is populated in the callback and will be read by the TET cases
46 struct SignalData
47 {
48   SignalData()
49   : functorCalled(false),
50     voidFunctorCalled(false),
51     receivedGesture(Gesture::Started)
52   {}
53
54   void Reset()
55   {
56     functorCalled = false;
57     voidFunctorCalled = false;
58
59     receivedGesture.state = Gesture::Started;
60     receivedGesture.scale = 0.0f;
61     receivedGesture.speed = 0.0f;
62     receivedGesture.screenCenterPoint = Vector2(0.0f, 0.0f);
63     receivedGesture.localCenterPoint = Vector2(0.0f, 0.0f);
64
65     pinchedActor.Reset();
66   }
67
68   bool functorCalled;
69   bool voidFunctorCalled;
70   PinchGesture receivedGesture;
71   Actor pinchedActor;
72 };
73
74 // Functor that sets the data when called
75 struct GestureReceivedFunctor
76 {
77   GestureReceivedFunctor(SignalData& data) : signalData(data) { }
78
79   void operator()(Actor actor, const PinchGesture& pinch)
80   {
81     signalData.functorCalled = true;
82     signalData.receivedGesture = pinch;
83     signalData.pinchedActor = actor;
84   }
85
86   void operator()()
87   {
88     signalData.voidFunctorCalled = true;
89   }
90
91   SignalData& signalData;
92 };
93
94 // Functor that removes the gestured actor from stage
95 struct UnstageActorFunctor : public GestureReceivedFunctor
96 {
97   UnstageActorFunctor( SignalData& data, Gesture::State& stateToUnstage )
98   : GestureReceivedFunctor( data ),
99     stateToUnstage( stateToUnstage )
100   {
101   }
102
103   void operator()( Actor actor, const PinchGesture& pinch )
104   {
105     GestureReceivedFunctor::operator()( actor, pinch );
106
107     if ( pinch.state == stateToUnstage )
108     {
109       Stage::GetCurrent().Remove( actor );
110     }
111   }
112
113   Gesture::State& stateToUnstage;
114 };
115
116 // Functor for receiving a touch event
117 struct TouchEventFunctor
118 {
119   bool operator()(Actor actor, const TouchEvent& touch)
120   {
121     return false;
122   }
123 };
124
125 // Generate a PinchGestureEvent to send to Core
126 Integration::PinchGestureEvent GeneratePinch(
127     Gesture::State state,
128     float scale,
129     float speed,
130     Vector2 centerpoint)
131 {
132   Integration::PinchGestureEvent pinch(state);
133
134   pinch.scale = scale;
135   pinch.speed = speed;
136   pinch.centerPoint = centerpoint;
137
138   return pinch;
139 }
140
141 } // anon namespace
142
143 ///////////////////////////////////////////////////////////////////////////////
144
145 int UtcDaliPinchGestureDetectorConstructor(void)
146 {
147   TestApplication application;
148
149   PinchGestureDetector detector;
150   DALI_TEST_CHECK(!detector);
151   END_TEST;
152 }
153
154 int UtcDaliPinchGestureDetectorCopyConstructorP(void)
155 {
156   TestApplication application;
157
158   PinchGestureDetector detector = PinchGestureDetector::New();;
159
160   PinchGestureDetector copy( detector );
161   DALI_TEST_CHECK( detector );
162   END_TEST;
163 }
164
165 int UtcDaliPinchGestureDetectorAssignmentOperatorP(void)
166 {
167   TestApplication application;
168
169   PinchGestureDetector detector = PinchGestureDetector::New();;
170
171   PinchGestureDetector assign;
172   assign = detector;
173   DALI_TEST_CHECK( detector );
174
175   DALI_TEST_CHECK( detector == assign );
176   END_TEST;
177 }
178
179 int UtcDaliPinchGestureDetectorNew(void)
180 {
181   TestApplication application;
182
183   PinchGestureDetector detector = PinchGestureDetector::New();
184
185   DALI_TEST_CHECK(detector);
186
187   // Attach an actor and emit a touch event on the actor to ensure complete line coverage
188   Actor actor = Actor::New();
189   actor.SetSize(100.0f, 100.0f);
190   actor.SetAnchorPoint(AnchorPoint::TOP_LEFT);
191   Stage::GetCurrent().Add(actor);
192
193   // Render and notify
194   application.SendNotification();
195   application.Render();
196
197   detector.Attach(actor);
198
199   Integration::TouchEvent touchEvent(1);
200   Integration::Point point;
201   point.SetDeviceId( 1 );
202   point.SetState( PointState::DOWN );
203   point.SetScreenPosition( Vector2( 20.0f, 20.0f ) );
204   touchEvent.AddPoint(point);
205   application.ProcessEvent(touchEvent);
206
207   Integration::Point point2;
208   point.SetDeviceId( 1 );
209   point.SetState( PointState::DOWN );
210   point.SetScreenPosition( 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, "Incorrect state", 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, "Incorrect state", 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
1194   Dali::RenderTaskList overlayRenderTaskList = Integration::RenderTaskList::New();
1195   Dali::Actor overlayRootActor = systemOverlay.GetDefaultRootActor();
1196   Dali::CameraActor overlayCameraActor = systemOverlay.GetDefaultCameraActor();
1197   Integration::RenderTaskList::CreateTask( overlayRenderTaskList, overlayRootActor, overlayCameraActor );
1198   systemOverlay.SetOverlayRenderTasks( overlayRenderTaskList );
1199
1200   Actor actor = Actor::New();
1201   actor.SetSize(100.0f, 100.0f);
1202   actor.SetAnchorPoint(AnchorPoint::TOP_LEFT);
1203   systemOverlay.Add(actor);
1204
1205   // Render and notify
1206   application.SendNotification();
1207   application.Render();
1208
1209   SignalData data;
1210   GestureReceivedFunctor functor(data);
1211
1212   PinchGestureDetector detector = PinchGestureDetector::New();
1213   detector.Attach(actor);
1214   detector.DetectedSignal().Connect(&application, functor);
1215
1216   Vector2 screenCoords( 50.0f, 50.0f );
1217   float scale ( 10.0f );
1218   float speed ( 50.0f );
1219
1220   // Start pan within the actor's area
1221   application.ProcessEvent( GeneratePinch( Gesture::Started, scale, speed, screenCoords ) );
1222   DALI_TEST_EQUALS( true, data.functorCalled, TEST_LOCATION );
1223   END_TEST;
1224 }
1225
1226 int UtcDaliPinchGestureBehindTouchableSystemOverlay(void)
1227 {
1228   TestApplication application;
1229   Dali::Integration::Core& core = application.GetCore();
1230   Dali::Integration::SystemOverlay& systemOverlay( core.GetSystemOverlay() );
1231
1232   Dali::RenderTaskList overlayRenderTaskList = Integration::RenderTaskList::New();
1233   Dali::Actor overlayRootActor = systemOverlay.GetDefaultRootActor();
1234   Dali::CameraActor overlayCameraActor = systemOverlay.GetDefaultCameraActor();
1235   Integration::RenderTaskList::CreateTask( overlayRenderTaskList, overlayRootActor, overlayCameraActor );
1236   systemOverlay.SetOverlayRenderTasks( overlayRenderTaskList );
1237
1238   // SystemOverlay actor
1239   Actor systemOverlayActor = Actor::New();
1240   systemOverlayActor.SetSize(100.0f, 100.0f);
1241   systemOverlayActor.SetAnchorPoint(AnchorPoint::TOP_LEFT);
1242   systemOverlay.Add(systemOverlayActor);
1243
1244   // Stage actor
1245   Actor stageActor = Actor::New();
1246   stageActor.SetSize(100.0f, 100.0f);
1247   stageActor.SetAnchorPoint(AnchorPoint::TOP_LEFT);
1248   Stage::GetCurrent().Add(stageActor);
1249
1250   // Render and notify
1251   application.SendNotification();
1252   application.Render();
1253
1254   // Set system-overlay actor to touchable
1255   TouchEventData touchData;
1256   TouchEventDataFunctor touchFunctor( touchData );
1257   systemOverlayActor.TouchedSignal().Connect(&application, touchFunctor);
1258
1259   // Set stage actor to receive the gesture
1260   SignalData data;
1261   GestureReceivedFunctor functor(data);
1262
1263   PinchGestureDetector detector = PinchGestureDetector::New();
1264   detector.Attach(stageActor);
1265   detector.DetectedSignal().Connect(&application, functor);
1266
1267   Vector2 screenCoords( 50.0f, 50.0f );
1268   float scale ( 10.0f );
1269   float speed ( 50.0f );
1270
1271   // Start pinch within the two actors' area
1272   application.ProcessEvent( GeneratePinch( Gesture::Started, scale, speed, screenCoords ) );
1273   application.ProcessEvent( GeneratePinch( Gesture::Finished, scale, speed, screenCoords ) );
1274   DALI_TEST_EQUALS( true, data.functorCalled, TEST_LOCATION );
1275   DALI_TEST_EQUALS( false, touchData.functorCalled, TEST_LOCATION );
1276
1277   data.Reset();
1278   touchData.Reset();
1279
1280   // Do touch in the same area
1281   application.ProcessEvent( touchFunctor.GenerateSingleTouch( PointState::DOWN, screenCoords ) );
1282   DALI_TEST_EQUALS( false, data.functorCalled, TEST_LOCATION );
1283   DALI_TEST_EQUALS( true, touchData.functorCalled, TEST_LOCATION );
1284
1285   END_TEST;
1286 }
1287
1288 int UtcDaliPinchGestureTouchBehindGesturedSystemOverlay(void)
1289 {
1290   TestApplication application;
1291   Dali::Integration::Core& core = application.GetCore();
1292   Dali::Integration::SystemOverlay& systemOverlay( core.GetSystemOverlay() );
1293
1294   Dali::RenderTaskList overlayRenderTaskList = Integration::RenderTaskList::New();
1295   Dali::Actor overlayRootActor = systemOverlay.GetDefaultRootActor();
1296   Dali::CameraActor overlayCameraActor = systemOverlay.GetDefaultCameraActor();
1297   Integration::RenderTaskList::CreateTask( overlayRenderTaskList, overlayRootActor, overlayCameraActor );
1298   systemOverlay.SetOverlayRenderTasks( overlayRenderTaskList );
1299
1300   // SystemOverlay actor
1301   Actor systemOverlayActor = Actor::New();
1302   systemOverlayActor.SetSize(100.0f, 100.0f);
1303   systemOverlayActor.SetAnchorPoint(AnchorPoint::TOP_LEFT);
1304   systemOverlay.Add(systemOverlayActor);
1305
1306   // Stage actor
1307   Actor stageActor = Actor::New();
1308   stageActor.SetSize(100.0f, 100.0f);
1309   stageActor.SetAnchorPoint(AnchorPoint::TOP_LEFT);
1310   Stage::GetCurrent().Add(stageActor);
1311
1312   // Render and notify
1313   application.SendNotification();
1314   application.Render();
1315
1316   // Set stage actor to touchable
1317   TouchEventData touchData;
1318   TouchEventDataFunctor touchFunctor( touchData );
1319   stageActor.TouchedSignal().Connect(&application, touchFunctor);
1320
1321   // Set system-overlay actor to have the gesture
1322   SignalData data;
1323   GestureReceivedFunctor functor(data);
1324
1325   PinchGestureDetector detector = PinchGestureDetector::New();
1326   detector.Attach(systemOverlayActor);
1327   detector.DetectedSignal().Connect(&application, functor);
1328
1329   Vector2 screenCoords( 50.0f, 50.0f );
1330   float scale ( 10.0f );
1331   float speed ( 50.0f );
1332
1333   // Start pinch within the two actors' area
1334   application.ProcessEvent( GeneratePinch( Gesture::Started, scale, speed, screenCoords ) );
1335   application.ProcessEvent( GeneratePinch( Gesture::Finished, scale, speed, screenCoords ) );
1336   DALI_TEST_EQUALS( true, data.functorCalled, TEST_LOCATION );
1337   DALI_TEST_EQUALS( false, touchData.functorCalled, TEST_LOCATION );
1338
1339   data.Reset();
1340   touchData.Reset();
1341
1342   // Do touch in the same area
1343   application.ProcessEvent( touchFunctor.GenerateSingleTouch( PointState::DOWN, screenCoords ) );
1344   DALI_TEST_EQUALS( false, data.functorCalled, TEST_LOCATION );
1345   DALI_TEST_EQUALS( true, touchData.functorCalled, TEST_LOCATION );
1346
1347   END_TEST;
1348 }
1349
1350 int UtcDaliPinchGestureLayerConsumesTouch(void)
1351 {
1352   TestApplication application;
1353
1354   Actor actor = Actor::New();
1355   actor.SetSize(100.0f, 100.0f);
1356   actor.SetAnchorPoint(AnchorPoint::TOP_LEFT);
1357   Stage::GetCurrent().Add(actor);
1358
1359   // Add a detector
1360   SignalData data;
1361   GestureReceivedFunctor functor(data);
1362   PinchGestureDetector detector = PinchGestureDetector::New();
1363   detector.Attach(actor);
1364   detector.DetectedSignal().Connect( &application, functor );
1365
1366   // Add a layer to overlap the actor
1367   Layer layer = Layer::New();
1368   layer.SetSize(100.0f, 100.0f);
1369   layer.SetAnchorPoint(AnchorPoint::TOP_LEFT);
1370   Stage::GetCurrent().Add( layer );
1371   layer.RaiseToTop();
1372
1373   // Render and notify
1374   application.SendNotification();
1375   application.Render();
1376
1377   Vector2 screenCoords( 50.0f, 50.0f );
1378   float scale ( 10.0f );
1379   float speed ( 50.0f );
1380
1381   // Emit signals, should receive
1382   application.ProcessEvent( GeneratePinch( Gesture::Started, scale, speed, screenCoords ) );
1383   application.ProcessEvent( GeneratePinch( Gesture::Finished, scale, speed, screenCoords ) );
1384   DALI_TEST_EQUALS(true, data.functorCalled, TEST_LOCATION);
1385   data.Reset();
1386
1387   // Set layer to consume all touch
1388   layer.SetTouchConsumed( true );
1389
1390   // Render and notify
1391   application.SendNotification();
1392   application.Render();
1393
1394   // Emit the same signals again, should not receive
1395   application.ProcessEvent( GeneratePinch( Gesture::Started, scale, speed, screenCoords ) );
1396   application.ProcessEvent( GeneratePinch( Gesture::Finished, scale, speed, screenCoords ) );
1397   DALI_TEST_EQUALS(false, data.functorCalled, TEST_LOCATION);
1398   data.Reset();
1399
1400   END_TEST;
1401 }