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