[dali_1.0.42] Merge branch 'tizen'
[platform/core/uifw/dali-core.git] / automated-tests / src / dali / utc-Dali-TapGestureDetector.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/tap-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_tap_gesture_detector_startup(void)
31 {
32   test_return_value = TET_UNDEF;
33 }
34
35 void utc_dali_tap_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   {}
51
52   void Reset()
53   {
54     functorCalled = false;
55     voidFunctorCalled = false;
56
57     receivedGesture.numberOfTaps = 0u;
58     receivedGesture.numberOfTouches = 0u;
59     receivedGesture.screenPoint = Vector2(0.0f, 0.0f);
60     receivedGesture.localPoint = Vector2(0.0f, 0.0f);
61
62     tappedActor.Reset();
63   }
64
65   bool functorCalled;
66   bool voidFunctorCalled;
67   TapGesture receivedGesture;
68   Actor tappedActor;
69 };
70
71 // Functor that sets the data when called
72 struct GestureReceivedFunctor
73 {
74   GestureReceivedFunctor(SignalData& data) : signalData(data) { }
75
76   void operator()(Actor actor, const TapGesture& tap)
77   {
78     signalData.functorCalled = true;
79     signalData.receivedGesture = tap;
80     signalData.tappedActor = actor;
81   }
82
83   void operator()()
84   {
85     signalData.voidFunctorCalled = true;
86   }
87
88   SignalData& signalData;
89 };
90
91 // Functor that removes the gestured actor from stage
92 struct UnstageActorFunctor : public GestureReceivedFunctor
93 {
94   UnstageActorFunctor( SignalData& data ) : GestureReceivedFunctor( data ) { }
95
96   void operator()(Actor actor, const TapGesture& tap)
97   {
98     GestureReceivedFunctor::operator()( actor, tap );
99     Stage::GetCurrent().Remove( actor );
100   }
101 };
102
103 // Functor for receiving a touch event
104 struct TouchEventFunctor
105 {
106   bool operator()(Actor actor, const TouchEvent& touch)
107   {
108     //For line coverage
109     unsigned int points = touch.GetPointCount();
110     if( points > 0)
111     {
112       const TouchPoint& touchPoint = touch.GetPoint(0);
113       tet_printf("Touch Point state = %d\n", touchPoint.state);
114     }
115     return false;
116   }
117 };
118
119 // Generate a TapGestureEvent to send to Core
120 Integration::TapGestureEvent GenerateTap(
121     Gesture::State state,
122     unsigned int numberOfTaps,
123     unsigned int numberOfTouches,
124     Vector2 point)
125 {
126   Integration::TapGestureEvent tap( state );
127
128   tap.numberOfTaps = numberOfTaps;
129   tap.numberOfTouches = numberOfTouches;
130   tap.point = point;
131
132   return tap;
133 }
134
135 } // anon namespace
136
137 ///////////////////////////////////////////////////////////////////////////////
138
139
140 // Positive test case for a method
141 int UtcDaliTapGestureDetectorConstructor(void)
142 {
143   TestApplication application;
144
145   TapGestureDetector detector;
146   DALI_TEST_CHECK(!detector);
147   END_TEST;
148 }
149
150 int UtcDaliTapGestureDetectorCopyConstructorP(void)
151 {
152   TestApplication application;
153
154   TapGestureDetector detector = TapGestureDetector::New();
155
156   TapGestureDetector copy( detector );
157   DALI_TEST_CHECK( detector );
158   END_TEST;
159 }
160
161 int UtcDaliTapGestureDetectorAssignmentOperatorP(void)
162 {
163   TestApplication application;
164
165   TapGestureDetector detector = TapGestureDetector::New();;
166
167   TapGestureDetector assign;
168   assign = detector;
169   DALI_TEST_CHECK( detector );
170
171   DALI_TEST_CHECK( detector == assign );
172   END_TEST;
173 }
174
175 int UtcDaliTapGestureDetectorNew(void)
176 {
177   TestApplication application;
178
179   TapGestureDetector detector = TapGestureDetector::New();
180   DALI_TEST_CHECK(detector);
181   DALI_TEST_EQUALS(1u, detector.GetMinimumTapsRequired(), TEST_LOCATION);
182   DALI_TEST_EQUALS(1u, detector.GetMaximumTapsRequired(), TEST_LOCATION);
183
184   TapGestureDetector detector2 = TapGestureDetector::New( 5u );
185   DALI_TEST_CHECK(detector2);
186   DALI_TEST_EQUALS(5u, detector2.GetMinimumTapsRequired(), TEST_LOCATION);
187   DALI_TEST_EQUALS(5u, detector2.GetMaximumTapsRequired(), TEST_LOCATION);
188
189   //Scoped test to test destructor
190   {
191     TapGestureDetector detector3 = TapGestureDetector::New();
192     DALI_TEST_CHECK(detector3);
193   }
194
195   // Attach an actor and emit a touch event on the actor to ensure complete line coverage
196   Actor actor = Actor::New();
197   actor.SetSize(100.0f, 100.0f);
198   actor.SetAnchorPoint(AnchorPoint::TOP_LEFT);
199   Stage::GetCurrent().Add(actor);
200
201   // Render and notify
202   application.SendNotification();
203   application.Render();
204
205   detector.Attach(actor);
206
207   TouchEventFunctor touchFunctor;
208   actor.TouchedSignal().Connect( &application, touchFunctor );
209
210   Integration::TouchEvent touchEvent(1);
211   TouchPoint point(1, TouchPoint::Down, 20.0f, 20.0f);
212   touchEvent.AddPoint(point);
213   application.ProcessEvent(touchEvent);
214
215   // Render and notify
216   application.SendNotification();
217   application.Render();
218
219   // For line coverage, Initialise default constructor
220   TouchEvent touchEvent2;
221   END_TEST;
222 }
223
224 int UtcDaliTapGestureDetectorDownCast(void)
225 {
226   TestApplication application;
227   tet_infoline("Testing Dali::TapGestureDetector::DownCast()");
228
229   TapGestureDetector detector = TapGestureDetector::New();
230
231   BaseHandle object(detector);
232
233   TapGestureDetector detector2 = TapGestureDetector::DownCast(object);
234   DALI_TEST_CHECK(detector2);
235
236   TapGestureDetector detector3 = DownCast< TapGestureDetector >(object);
237   DALI_TEST_CHECK(detector3);
238
239   BaseHandle unInitializedObject;
240   TapGestureDetector detector4 = TapGestureDetector::DownCast(unInitializedObject);
241   DALI_TEST_CHECK(!detector4);
242
243   TapGestureDetector detector5 = DownCast< TapGestureDetector >(unInitializedObject);
244   DALI_TEST_CHECK(!detector5);
245
246   GestureDetector detector6 = TapGestureDetector::New();
247   TapGestureDetector detector7 = TapGestureDetector::DownCast(detector6);
248   DALI_TEST_CHECK(detector7);
249   END_TEST;
250 }
251
252 int UtcDaliTapGestureSetTapsRequired(void)
253 {
254   TestApplication application;
255
256   TapGestureDetector detector = TapGestureDetector::New();
257
258   const unsigned int minTaps = 3;
259   const unsigned int maxTaps = 7;
260
261   DALI_TEST_CHECK( minTaps != detector.GetMinimumTapsRequired() );
262   DALI_TEST_CHECK( maxTaps != detector.GetMaximumTapsRequired() );
263
264   detector.SetMinimumTapsRequired( minTaps );
265   detector.SetMaximumTapsRequired( maxTaps );
266
267   DALI_TEST_EQUALS( minTaps, detector.GetMinimumTapsRequired(), TEST_LOCATION );
268   DALI_TEST_EQUALS( maxTaps, detector.GetMaximumTapsRequired(), TEST_LOCATION );
269
270   // Attach an actor and change the required touches
271
272   Actor actor = Actor::New();
273   actor.SetSize(100.0f, 100.0f);
274   actor.SetAnchorPoint(AnchorPoint::TOP_LEFT);
275   Stage::GetCurrent().Add(actor);
276
277   // Render and notify
278   application.SendNotification();
279   application.Render();
280
281   SignalData data;
282   GestureReceivedFunctor functor(data);
283
284   detector.Attach(actor);
285   detector.DetectedSignal().Connect( &application, functor );
286
287   // Ensure signal is emitted if minimum taps received
288   application.ProcessEvent(GenerateTap(Gesture::Possible, minTaps, 1u, Vector2(50.0f, 50.0f)));
289   application.ProcessEvent(GenerateTap(Gesture::Started, minTaps, 1u, Vector2(50.0f, 50.0f)));
290   DALI_TEST_EQUALS( true, data.functorCalled, TEST_LOCATION );
291   DALI_TEST_EQUALS( minTaps, data.receivedGesture.numberOfTaps, TEST_LOCATION );
292   data.Reset();
293
294   // Ensure signal is emitted if maximum taps received
295   application.ProcessEvent(GenerateTap(Gesture::Possible, maxTaps, 1u, Vector2(50.0f, 50.0f)));
296   application.ProcessEvent(GenerateTap(Gesture::Started, maxTaps, 1u, Vector2(50.0f, 50.0f)));
297   DALI_TEST_EQUALS( true, data.functorCalled, TEST_LOCATION );
298   DALI_TEST_EQUALS( maxTaps, data.receivedGesture.numberOfTaps, TEST_LOCATION );
299   data.Reset();
300
301   // Ensure signal is NOT emitted if outside the range
302   application.ProcessEvent(GenerateTap(Gesture::Possible, minTaps - 1, 1u, Vector2(50.0f, 50.0f)));
303   application.ProcessEvent(GenerateTap(Gesture::Started, minTaps - 1, 1u, Vector2(50.0f, 50.0f)));
304   DALI_TEST_EQUALS( false, data.functorCalled, TEST_LOCATION );
305   data.Reset();
306   application.ProcessEvent(GenerateTap(Gesture::Possible, maxTaps + 1, 1u, Vector2(50.0f, 50.0f)));
307   application.ProcessEvent(GenerateTap(Gesture::Started, maxTaps + 1, 1u, Vector2(50.0f, 50.0f)));
308   DALI_TEST_EQUALS( false, data.functorCalled, TEST_LOCATION );
309   data.Reset();
310
311   TestGestureManager& gestureManager = application.GetGestureManager();
312   gestureManager.Initialize();
313
314   detector.SetMinimumTapsRequired(4);
315
316   // Gesture detection should have been updated only
317   DALI_TEST_EQUALS(true, gestureManager.WasCalled(TestGestureManager::UpdateType), TEST_LOCATION);
318   DALI_TEST_EQUALS(false, gestureManager.WasCalled(TestGestureManager::RegisterType), TEST_LOCATION);
319   DALI_TEST_EQUALS(false, gestureManager.WasCalled(TestGestureManager::UnregisterType), TEST_LOCATION);
320
321   // Reset values
322   gestureManager.Initialize();
323
324   detector.SetMaximumTapsRequired(maxTaps);
325
326   // Gesture detection should NOT have been updated
327   DALI_TEST_EQUALS(false, gestureManager.WasCalled(TestGestureManager::UpdateType), TEST_LOCATION);
328   DALI_TEST_EQUALS(false, gestureManager.WasCalled(TestGestureManager::RegisterType), TEST_LOCATION);
329   DALI_TEST_EQUALS(false, gestureManager.WasCalled(TestGestureManager::UnregisterType), TEST_LOCATION);
330
331   // Reset values
332   gestureManager.Initialize();
333
334   // Create a second gesture detector that requires even less maximum touches
335   TapGestureDetector secondDetector = TapGestureDetector::New();
336   secondDetector.Attach(actor);
337
338   // Gesture detection should have been updated
339   DALI_TEST_EQUALS(true, gestureManager.WasCalled(TestGestureManager::UpdateType), TEST_LOCATION);
340   DALI_TEST_EQUALS(false, gestureManager.WasCalled(TestGestureManager::RegisterType), TEST_LOCATION);
341   DALI_TEST_EQUALS(false, gestureManager.WasCalled(TestGestureManager::UnregisterType), TEST_LOCATION);
342
343   // Reset values
344   gestureManager.Initialize();
345
346   // Delete the second detector so that our detection is updated again
347   secondDetector.Reset();
348   DALI_TEST_EQUALS(true, gestureManager.WasCalled(TestGestureManager::UpdateType), TEST_LOCATION);
349   DALI_TEST_EQUALS(false, gestureManager.WasCalled(TestGestureManager::RegisterType), TEST_LOCATION);
350   DALI_TEST_EQUALS(false, gestureManager.WasCalled(TestGestureManager::UnregisterType), TEST_LOCATION);
351
352   // Set the minimum to be greater than the maximum, should Assert
353   try
354   {
355     detector.SetMinimumTapsRequired( maxTaps );
356     detector.SetMaximumTapsRequired( minTaps );
357     DALI_TEST_CHECK( false ); // Should not get here
358   }
359   catch ( DaliException& e )
360   {
361     DALI_TEST_CHECK( true );
362   }
363
364   END_TEST;
365 }
366
367 int UtcDaliTapGestureSetTapsRequiredMinMaxCheck(void)
368 {
369   TestApplication application;
370
371   // Attach an actor and change the required touches
372
373   Actor actor = Actor::New();
374   actor.SetSize(100.0f, 100.0f);
375   actor.SetAnchorPoint(AnchorPoint::TOP_LEFT);
376   Stage::GetCurrent().Add(actor);
377
378   // Render and notify
379   application.SendNotification();
380   application.Render();
381
382   // Set the minimum to be greater than the maximum, should Assert
383
384   try
385   {
386     TapGestureDetector detector = TapGestureDetector::New();
387     detector.SetMinimumTapsRequired( 7u );
388     detector.SetMaximumTapsRequired( 3u );
389     detector.Attach(actor);
390     DALI_TEST_CHECK( false ); // Should not get here
391   }
392   catch ( DaliException& e )
393   {
394     DALI_TEST_CHECK( true );
395   }
396
397   END_TEST;
398 }
399
400 int UtcDaliTapGestureGetTapsRequired(void)
401 {
402   TestApplication application;
403
404   TapGestureDetector detector = TapGestureDetector::New();
405   DALI_TEST_EQUALS(1u, detector.GetMinimumTapsRequired(), TEST_LOCATION);
406   DALI_TEST_EQUALS(1u, detector.GetMaximumTapsRequired(), TEST_LOCATION);
407   END_TEST;
408 }
409
410 int UtcDaliTapGestureSignalReceptionNegative(void)
411 {
412   TestApplication application;
413
414   Actor actor = Actor::New();
415   actor.SetSize(100.0f, 100.0f);
416   actor.SetAnchorPoint(AnchorPoint::TOP_LEFT);
417   Stage::GetCurrent().Add(actor);
418
419   // Render and notify
420   application.SendNotification();
421   application.Render();
422
423   SignalData data;
424   GestureReceivedFunctor functor(data);
425
426   TapGestureDetector detector = TapGestureDetector::New();
427   detector.Attach(actor);
428   detector.DetectedSignal().Connect( &application, functor );
429
430   // Do a tap outside actor's area
431   application.ProcessEvent(GenerateTap(Gesture::Possible, 1u, 1u, Vector2(112.0f, 112.0f)));
432   application.ProcessEvent(GenerateTap(Gesture::Started, 1u, 1u, Vector2(112.0f, 112.0f)));
433   DALI_TEST_EQUALS(false, data.functorCalled, TEST_LOCATION);
434   END_TEST;
435 }
436
437 int UtcDaliTapGestureSignalReceptionPositive(void)
438 {
439   TestApplication application;
440
441   Actor actor = Actor::New();
442   actor.SetSize(100.0f, 100.0f);
443   actor.SetAnchorPoint(AnchorPoint::TOP_LEFT);
444   Stage::GetCurrent().Add(actor);
445
446   // Render and notify
447   application.SendNotification();
448   application.Render();
449
450   SignalData data;
451   GestureReceivedFunctor functor(data);
452
453   TapGestureDetector detector = TapGestureDetector::New();
454   detector.Attach(actor);
455   detector.DetectedSignal().Connect( &application, functor );
456
457   // Do a tap inside actor's area
458   application.ProcessEvent(GenerateTap(Gesture::Possible, 1u, 1u, Vector2(50.0f, 50.0f)));
459   application.ProcessEvent(GenerateTap(Gesture::Started, 1u, 1u, Vector2(50.0f, 50.0f)));
460   DALI_TEST_EQUALS(true, data.functorCalled, TEST_LOCATION);
461   DALI_TEST_EQUALS(1u, data.receivedGesture.numberOfTaps, TEST_LOCATION);
462   DALI_TEST_EQUALS(1u, data.receivedGesture.numberOfTouches, TEST_LOCATION);
463   DALI_TEST_EQUALS( Vector2(50.0f, 50.0f), data.receivedGesture.localPoint, 0.1, TEST_LOCATION);
464   END_TEST;
465 }
466
467 int UtcDaliTapGestureSignalReceptionDetach(void)
468 {
469   TestApplication application;
470
471   Actor actor = Actor::New();
472   actor.SetSize(100.0f, 100.0f);
473   actor.SetAnchorPoint(AnchorPoint::TOP_LEFT);
474   Stage::GetCurrent().Add(actor);
475
476   // Render and notify
477   application.SendNotification();
478   application.Render();
479
480   SignalData data;
481   GestureReceivedFunctor functor(data);
482
483   TapGestureDetector detector = TapGestureDetector::New();
484   detector.Attach(actor);
485   detector.DetectedSignal().Connect(&application, functor);
486
487   // Start tap within the actor's area
488   application.ProcessEvent(GenerateTap(Gesture::Possible, 1u, 1u, Vector2(20.0f, 20.0f)));
489   application.ProcessEvent(GenerateTap(Gesture::Started, 1u, 1u, Vector2(20.0f, 20.0f)));
490   DALI_TEST_EQUALS(true, data.functorCalled, TEST_LOCATION);
491   DALI_TEST_EQUALS(1u, data.receivedGesture.numberOfTaps, TEST_LOCATION);
492   DALI_TEST_EQUALS(1u, data.receivedGesture.numberOfTouches, TEST_LOCATION);
493   DALI_TEST_EQUALS( Vector2(20.0f, 20.0f), data.receivedGesture.localPoint, 0.1, TEST_LOCATION);
494
495   // repeat the tap within the actor's area - we should still receive the signal
496   data.Reset();
497   application.ProcessEvent(GenerateTap(Gesture::Possible, 1u, 1u, Vector2(50.0f, 50.0f)));
498   application.ProcessEvent(GenerateTap(Gesture::Started, 1u, 1u, Vector2(50.0f, 50.0f)));
499   DALI_TEST_EQUALS(true, data.functorCalled, TEST_LOCATION);
500   DALI_TEST_EQUALS(1u, data.receivedGesture.numberOfTaps, TEST_LOCATION);
501   DALI_TEST_EQUALS(1u, data.receivedGesture.numberOfTouches, TEST_LOCATION);
502   DALI_TEST_EQUALS( Vector2(50.0f, 50.0f), data.receivedGesture.localPoint, 0.1, TEST_LOCATION);
503
504   // Detach actor
505   detector.DetachAll();
506
507   // Ensure we are no longer signalled
508   data.Reset();
509   application.ProcessEvent(GenerateTap(Gesture::Possible, 1u, 1u, Vector2(20.0f, 20.0f)));
510   application.ProcessEvent(GenerateTap(Gesture::Started, 1u, 1u, Vector2(20.0f, 20.0f)));
511   DALI_TEST_EQUALS(false, data.functorCalled, TEST_LOCATION);
512   application.ProcessEvent(GenerateTap(Gesture::Possible, 1u, 1u, Vector2(50.0f, 50.0f)));
513   application.ProcessEvent(GenerateTap(Gesture::Started, 1u, 1u, Vector2(50.0f, 50.0f)));
514   DALI_TEST_EQUALS(false, data.functorCalled, TEST_LOCATION);
515   END_TEST;
516 }
517
518 int UtcDaliTapGestureSignalReceptionActorDestroyedWhileTapping(void)
519 {
520   TestApplication application;
521
522   SignalData data;
523   GestureReceivedFunctor functor(data);
524
525   TapGestureDetector detector = TapGestureDetector::New();
526   detector.DetectedSignal().Connect(&application, functor);
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 tap within the actor's area
542     application.ProcessEvent(GenerateTap(Gesture::Possible, 1u, 1u, Vector2(20.0f, 20.0f)));
543     application.ProcessEvent(GenerateTap(Gesture::Started, 1u, 1u, Vector2(20.0f, 20.0f)));
544     DALI_TEST_EQUALS(true, data.functorCalled, TEST_LOCATION);
545
546     // Remove the actor from stage and reset the data
547     Stage::GetCurrent().Remove(actor);
548
549     // Render and notify
550     application.SendNotification();
551     application.Render();
552   }
553
554   // Actor should now have been destroyed
555
556   data.Reset();
557   application.ProcessEvent(GenerateTap(Gesture::Possible, 1u, 1u, Vector2(20.0f, 20.0f)));
558   application.ProcessEvent(GenerateTap(Gesture::Started, 1u, 1u, Vector2(20.0f, 20.0f)));
559   DALI_TEST_EQUALS(false, data.functorCalled, TEST_LOCATION);
560   END_TEST;
561 }
562
563 int UtcDaliTapGestureSignalReceptionRotatedActor(void)
564 {
565   TestApplication application;
566
567   Actor actor = Actor::New();
568   actor.SetSize(100.0f, 100.0f);
569   actor.SetOrientation(Dali::Degree(90.0f), Vector3::ZAXIS);
570   Stage::GetCurrent().Add(actor);
571
572   // Render and notify
573   application.SendNotification();
574   application.Render();
575
576   SignalData data;
577   GestureReceivedFunctor functor(data);
578
579   TapGestureDetector detector = TapGestureDetector::New();
580   detector.Attach(actor);
581   detector.DetectedSignal().Connect(&application, functor);
582
583   // Do tap, only check finished value
584   application.ProcessEvent(GenerateTap(Gesture::Possible, 1u, 1u, Vector2(5.0f, 5.0f)));
585   application.ProcessEvent(GenerateTap(Gesture::Started, 1u, 1u, Vector2(5.0f, 5.0f)));
586   DALI_TEST_EQUALS(true, data.functorCalled, TEST_LOCATION);
587   DALI_TEST_EQUALS(1u, data.receivedGesture.numberOfTaps, TEST_LOCATION);
588   DALI_TEST_EQUALS(1u, data.receivedGesture.numberOfTouches, TEST_LOCATION);
589   DALI_TEST_EQUALS( Vector2(5.0f, 5.0f), data.receivedGesture.screenPoint, 0.1, TEST_LOCATION);
590
591   // Rotate actor again and render
592   actor.SetOrientation(Dali::Degree(180.0f), Vector3::ZAXIS);
593   application.SendNotification();
594   application.Render();
595
596   // Do tap, should still receive event
597   data.Reset();
598   application.ProcessEvent(GenerateTap(Gesture::Possible, 1u, 1u, Vector2(5.0f, 5.0f)));
599   application.ProcessEvent(GenerateTap(Gesture::Started, 1u, 1u, Vector2(5.0f, 5.0f)));
600   DALI_TEST_EQUALS(true, data.functorCalled, TEST_LOCATION);
601   DALI_TEST_EQUALS(1u, data.receivedGesture.numberOfTaps, TEST_LOCATION);
602   DALI_TEST_EQUALS(1u, data.receivedGesture.numberOfTouches, TEST_LOCATION);
603   DALI_TEST_EQUALS( Vector2(5.0f, 5.0f), data.receivedGesture.screenPoint, 0.1, TEST_LOCATION);
604
605   // Rotate actor again and render
606   actor.SetOrientation(Dali::Degree(90.0f), Vector3::YAXIS);
607   application.SendNotification();
608   application.Render();
609
610   // Do tap, inside the actor's area (area if it is not rotated), Should not receive the event
611   data.Reset();
612   application.ProcessEvent(GenerateTap(Gesture::Possible, 1u, 1u, Vector2(70.0f, 70.0f)));
613   application.ProcessEvent(GenerateTap(Gesture::Started, 1u, 1u, Vector2(70.0f, 70.0f)));
614   DALI_TEST_EQUALS(false, data.functorCalled, TEST_LOCATION);
615   END_TEST;
616 }
617
618 int UtcDaliTapGestureSignalReceptionChildHit(void)
619 {
620   TestApplication application;
621
622   Actor parent = Actor::New();
623   parent.SetSize(100.0f, 100.0f);
624   parent.SetAnchorPoint(AnchorPoint::TOP_LEFT);
625   Stage::GetCurrent().Add(parent);
626
627   // Set child to completely cover parent.
628   // Change rotation of child to be different from parent so that we can check if our local coordinate
629   // conversion of the parent actor is correct.
630   Actor child = Actor::New();
631   child.SetSize(100.0f, 100.0f);
632   child.SetAnchorPoint(AnchorPoint::CENTER);
633   child.SetParentOrigin(ParentOrigin::CENTER);
634   child.SetOrientation(Dali::Degree(90.0f), Vector3::ZAXIS);
635   parent.Add(child);
636
637   TouchEventFunctor touchFunctor;
638   child.TouchedSignal().Connect(&application, touchFunctor);
639
640   // Render and notify
641   application.SendNotification();
642   application.Render();
643
644   SignalData data;
645   GestureReceivedFunctor functor(data);
646
647   TapGestureDetector detector = TapGestureDetector::New();
648   detector.Attach(parent);
649   detector.DetectedSignal().Connect(&application, functor);
650
651   // Do tap - hits child area but parent should still receive it
652   application.ProcessEvent(GenerateTap(Gesture::Possible, 1u, 1u, Vector2(50.0f, 50.0f)));
653   application.ProcessEvent(GenerateTap(Gesture::Started, 1u, 1u, Vector2(50.0f, 50.0f)));
654   DALI_TEST_EQUALS(true, data.functorCalled, TEST_LOCATION);
655   DALI_TEST_EQUALS(true, parent == data.tappedActor, TEST_LOCATION);
656   DALI_TEST_EQUALS(Vector2(50.0f, 50.0f), data.receivedGesture.screenPoint, 0.01f, TEST_LOCATION);
657
658   // Attach child and generate same touch points
659   // (Also proves that you can detach and then re-attach another actor)
660   detector.Attach(child);
661   detector.Detach(parent);
662
663   // Do an entire tap, only check finished value
664   data.Reset();
665   application.ProcessEvent(GenerateTap(Gesture::Possible, 1u, 1u, Vector2(51.0f, 51.0f)));
666   application.ProcessEvent(GenerateTap(Gesture::Started, 1u, 1u, Vector2(51.0f, 51.0f)));
667   DALI_TEST_EQUALS(true, data.functorCalled, TEST_LOCATION);
668   DALI_TEST_EQUALS(true, child == data.tappedActor, TEST_LOCATION);
669   DALI_TEST_EQUALS(Vector2(51.0f, 51.0f), data.receivedGesture.screenPoint, 0.01f, TEST_LOCATION);
670   END_TEST;
671 }
672
673 int UtcDaliTapGestureSignalReceptionAttachDetachMany(void)
674 {
675   TestApplication application;
676
677   Actor first = Actor::New();
678   first.SetSize(100.0f, 100.0f);
679   first.SetAnchorPoint(AnchorPoint::TOP_LEFT);
680   Stage::GetCurrent().Add(first);
681
682   Actor second = Actor::New();
683   second.SetSize(100.0f, 100.0f);
684   second.SetX(100.0f);
685   second.SetAnchorPoint(AnchorPoint::TOP_LEFT);
686   Stage::GetCurrent().Add(second);
687
688   // Render and notify
689   application.SendNotification();
690   application.Render();
691
692   SignalData data;
693   GestureReceivedFunctor functor(data);
694
695   TapGestureDetector detector = TapGestureDetector::New();
696   detector.Attach(first);
697   detector.Attach(second);
698   detector.DetectedSignal().Connect(&application, functor);
699
700   // Tap within second actor's area
701   application.ProcessEvent(GenerateTap(Gesture::Possible, 1u, 1u, Vector2(120.0f, 10.0f)));
702   application.ProcessEvent(GenerateTap(Gesture::Started, 1u, 1u, Vector2(120.0f, 10.0f)));
703   DALI_TEST_EQUALS(true, data.functorCalled, TEST_LOCATION);
704   DALI_TEST_EQUALS(true, second == data.tappedActor, TEST_LOCATION);
705
706   // Tap within first actor's area
707   data.Reset();
708   application.ProcessEvent(GenerateTap(Gesture::Possible, 1u, 1u, Vector2(20.0f, 10.0f)));
709   application.ProcessEvent(GenerateTap(Gesture::Started, 1u, 1u, Vector2(20.0f, 10.0f)));
710   DALI_TEST_EQUALS(true, data.functorCalled, TEST_LOCATION);
711   DALI_TEST_EQUALS(true, first == data.tappedActor, TEST_LOCATION);
712
713   // Detach the second actor
714   detector.Detach(second);
715
716   // second actor shouldn't receive event
717   data.Reset();
718   application.ProcessEvent(GenerateTap(Gesture::Possible, 1u, 1u, Vector2(120.0f, 10.0f)));
719   application.ProcessEvent(GenerateTap(Gesture::Started, 1u, 1u, Vector2(120.0f, 10.0f)));
720   DALI_TEST_EQUALS(false, data.functorCalled, TEST_LOCATION);
721
722   // first actor should continue receiving event
723   data.Reset();
724   application.ProcessEvent(GenerateTap(Gesture::Possible, 1u, 1u, Vector2(20.0f, 10.0f)));
725   application.ProcessEvent(GenerateTap(Gesture::Started, 1u, 1u, Vector2(20.0f, 10.0f)));
726   DALI_TEST_EQUALS(true, data.functorCalled, TEST_LOCATION);
727   END_TEST;
728 }
729
730 int UtcDaliTapGestureSignalReceptionActorBecomesUntouchable(void)
731 {
732   TestApplication application;
733
734   Actor actor = Actor::New();
735   actor.SetSize(100.0f, 100.0f);
736   actor.SetAnchorPoint(AnchorPoint::TOP_LEFT);
737   Stage::GetCurrent().Add(actor);
738
739   // Render and notify
740   application.SendNotification();
741   application.Render();
742
743   SignalData data;
744   GestureReceivedFunctor functor(data);
745
746   TapGestureDetector detector = TapGestureDetector::New();
747   detector.Attach(actor);
748   detector.DetectedSignal().Connect(&application, functor);
749
750   // Tap in actor's area
751   application.ProcessEvent(GenerateTap(Gesture::Possible, 1u, 1u, Vector2(50.0f, 10.0f)));
752   application.ProcessEvent(GenerateTap(Gesture::Started, 1u, 1u, Vector2(50.0f, 10.0f)));
753   DALI_TEST_EQUALS(true, data.functorCalled, TEST_LOCATION);
754
755   // Actor become invisible - actor should not receive the next pan
756   actor.SetVisible(false);
757
758   // Render and notify
759   application.SendNotification();
760   application.Render();
761
762   // Tap in the same area, shouldn't receive event
763   data.Reset();
764   application.ProcessEvent(GenerateTap(Gesture::Possible, 1u, 1u, Vector2(50.0f, 10.0f)));
765   application.ProcessEvent(GenerateTap(Gesture::Started, 1u, 1u, Vector2(50.0f, 10.0f)));
766   DALI_TEST_EQUALS(false, data.functorCalled, TEST_LOCATION);
767   END_TEST;
768 }
769
770 int UtcDaliTapGestureSignalReceptionMultipleGestureDetectors(void)
771 {
772   TestApplication application;
773   Dali::TestGestureManager& gestureManager = application.GetGestureManager();
774
775   Actor first = Actor::New();
776   first.SetSize(100.0f, 100.0f);
777   first.SetAnchorPoint(AnchorPoint::TOP_LEFT);
778   Stage::GetCurrent().Add(first);
779
780   Actor second = Actor::New();
781   second.SetSize(100.0f, 100.0f);
782   second.SetAnchorPoint(AnchorPoint::TOP_LEFT);
783   second.SetX(100.0f);
784   first.Add(second);
785
786   // Render and notify
787   application.SendNotification();
788   application.Render();
789
790   SignalData data;
791   GestureReceivedFunctor functor(data);
792
793   TapGestureDetector firstDetector = TapGestureDetector::New();
794   firstDetector.Attach(first);
795   firstDetector.DetectedSignal().Connect(&application, functor);
796
797   // secondDetector is scoped
798   {
799     // Reset gestureManager statistics
800     gestureManager.Initialize();
801
802     TapGestureDetector secondDetector = TapGestureDetector::New( 2 );
803     secondDetector.Attach(second);
804     secondDetector.DetectedSignal().Connect(&application, functor);
805
806     DALI_TEST_EQUALS(true, gestureManager.WasCalled(TestGestureManager::UpdateType), TEST_LOCATION);
807     DALI_TEST_EQUALS(false, gestureManager.WasCalled(TestGestureManager::RegisterType), TEST_LOCATION);
808     DALI_TEST_EQUALS(false, gestureManager.WasCalled(TestGestureManager::UnregisterType), TEST_LOCATION);
809
810     // Tap within second actor's area
811     application.ProcessEvent(GenerateTap(Gesture::Possible, 2u, 1u, Vector2(150.0f, 10.0f)));
812     application.ProcessEvent(GenerateTap(Gesture::Started, 2u, 1u, Vector2(150.0f, 10.0f)));
813     DALI_TEST_EQUALS(true, data.functorCalled, TEST_LOCATION);
814     DALI_TEST_EQUALS(true, second == data.tappedActor, TEST_LOCATION);
815
816     // Tap continues as single touch gesture - we should not receive any gesture
817     data.Reset();
818     application.ProcessEvent(GenerateTap(Gesture::Possible, 1u, 1u, Vector2(150.0f, 10.0f)));
819     application.ProcessEvent(GenerateTap(Gesture::Started, 1u, 1u, Vector2(150.0f, 10.0f)));
820     DALI_TEST_EQUALS(false, data.functorCalled, TEST_LOCATION);
821
822     // Single touch tap starts - first actor should be panned
823     data.Reset();
824     application.ProcessEvent(GenerateTap(Gesture::Possible, 1u, 1u, Vector2(50.0f, 10.0f)));
825     application.ProcessEvent(GenerateTap(Gesture::Started, 1u, 1u, Vector2(50.0f, 10.0f)));
826     DALI_TEST_EQUALS(true, data.functorCalled, TEST_LOCATION);
827     DALI_TEST_EQUALS(true, first == data.tappedActor, TEST_LOCATION);
828
829     // Pan changes to double-touch - we shouldn't receive event
830     data.Reset();
831     application.ProcessEvent(GenerateTap(Gesture::Possible, 2u, 2u, Vector2(50.0f, 10.0f)));
832     application.ProcessEvent(GenerateTap(Gesture::Started, 2u, 2u, Vector2(50.0f, 10.0f)));
833     DALI_TEST_EQUALS(false, data.functorCalled, TEST_LOCATION);
834
835     // Reset gesture manager statistics
836     gestureManager.Initialize();
837   }
838
839   // secondDetector has now been deleted.  Gesture detection should have been updated only
840   DALI_TEST_EQUALS(true, gestureManager.WasCalled(TestGestureManager::UpdateType), TEST_LOCATION);
841   DALI_TEST_EQUALS(false, gestureManager.WasCalled(TestGestureManager::RegisterType), TEST_LOCATION);
842   DALI_TEST_EQUALS(false, gestureManager.WasCalled(TestGestureManager::UnregisterType), TEST_LOCATION);
843   END_TEST;
844 }
845
846 int UtcDaliTapGestureSignalReceptionMultipleDetectorsOnActor(void)
847 {
848   TestApplication application;
849
850   Actor actor = Actor::New();
851   actor.SetSize(100.0f, 100.0f);
852   actor.SetAnchorPoint(AnchorPoint::TOP_LEFT);
853   Stage::GetCurrent().Add(actor);
854
855   // Render and notify
856   application.SendNotification();
857   application.Render();
858
859   // Attach actor to one detector
860   SignalData firstData;
861   GestureReceivedFunctor firstFunctor(firstData);
862   TapGestureDetector firstDetector = TapGestureDetector::New();
863   firstDetector.Attach(actor);
864   firstDetector.DetectedSignal().Connect(&application, firstFunctor);
865
866   // Attach actor to another detector
867   SignalData secondData;
868   GestureReceivedFunctor secondFunctor(secondData);
869   TapGestureDetector secondDetector = TapGestureDetector::New();
870   secondDetector.Attach(actor);
871   secondDetector.DetectedSignal().Connect(&application, secondFunctor);
872
873   // Tap in actor's area - both detector's functors should be called
874   application.ProcessEvent(GenerateTap(Gesture::Possible, 1u, 1u, Vector2(50.0f, 10.0f)));
875   application.ProcessEvent(GenerateTap(Gesture::Started, 1u, 1u, Vector2(50.0f, 10.0f)));
876   DALI_TEST_EQUALS(true, firstData.functorCalled, TEST_LOCATION);
877   DALI_TEST_EQUALS(true, secondData.functorCalled, TEST_LOCATION);
878   END_TEST;
879 }
880
881 int UtcDaliTapGestureSignalReceptionDifferentPossible(void)
882 {
883   TestApplication application;
884
885   Actor actor = Actor::New();
886   actor.SetSize(100.0f, 100.0f);
887   actor.SetAnchorPoint(AnchorPoint::TOP_LEFT);
888   Stage::GetCurrent().Add(actor);
889
890   // Render and notify
891   application.SendNotification();
892   application.Render();
893
894   // Attach actor to detector
895   SignalData data;
896   GestureReceivedFunctor functor( data );
897   TapGestureDetector detector = TapGestureDetector::New();
898   detector.Attach(actor);
899   detector.DetectedSignal().Connect( &application, functor );
900
901   // Gesture possible in actor's area.
902   application.ProcessEvent(GenerateTap(Gesture::Possible, 1u, 1u, Vector2(50.0f, 10.0f)));
903   DALI_TEST_EQUALS(false, data.functorCalled, TEST_LOCATION);
904
905   // Move actor somewhere else
906   actor.SetPosition( 100.0f, 100.0f );
907
908   // Render and notify
909   application.SendNotification();
910   application.Render();
911
912   // Emit Started event, we should not receive the tap.
913   application.ProcessEvent(GenerateTap(Gesture::Started, 1u, 1u, Vector2(50.0f, 10.0f)));
914   DALI_TEST_EQUALS(false, data.functorCalled, TEST_LOCATION);
915
916   // Tap possible in empty area.
917   application.ProcessEvent(GenerateTap(Gesture::Possible, 1u, 1u, Vector2(50.0f, 10.0f)));
918   DALI_TEST_EQUALS(false, data.functorCalled, TEST_LOCATION);
919
920   // Move actor in to the tap position.
921   actor.SetPosition( 0.0f, 0.0f );
922
923   // Render and notify
924   application.SendNotification();
925   application.Render();
926
927   // Emit Started event, we should not receive the tap.
928   application.ProcessEvent(GenerateTap(Gesture::Started, 1u, 1u, Vector2(50.0f, 10.0f)));
929   DALI_TEST_EQUALS(false, data.functorCalled, TEST_LOCATION);
930
931   // Normal tap in actor's area for completeness.
932   application.ProcessEvent(GenerateTap(Gesture::Possible, 1u, 1u, Vector2(50.0f, 10.0f)));
933   application.ProcessEvent(GenerateTap(Gesture::Started, 1u, 1u, Vector2(50.0f, 10.0f)));
934   DALI_TEST_EQUALS(true, data.functorCalled, TEST_LOCATION);
935   END_TEST;
936 }
937
938 int UtcDaliTapGestureEmitIncorrectStateClear(void)
939 {
940   TestApplication application;
941
942   Actor actor = Actor::New();
943   actor.SetSize(100.0f, 100.0f);
944   actor.SetAnchorPoint(AnchorPoint::TOP_LEFT);
945   Stage::GetCurrent().Add(actor);
946
947   // Render and notify
948   application.SendNotification();
949   application.Render();
950
951   // Attach actor to detector
952   SignalData data;
953   GestureReceivedFunctor functor( data );
954   TapGestureDetector detector = TapGestureDetector::New();
955   detector.Attach(actor);
956   detector.DetectedSignal().Connect( &application, functor );
957
958   // Try a Clear state
959   try
960   {
961     application.ProcessEvent(GenerateTap(Gesture::Clear, 1u, 1u, Vector2(50.0f, 10.0f)));
962     tet_result(TET_FAIL);
963   }
964   catch ( Dali::DaliException& e )
965   {
966     DALI_TEST_ASSERT( e, "false", TEST_LOCATION );
967   }
968   END_TEST;
969 }
970
971 int UtcDaliTapGestureEmitIncorrectStateContinuing(void)
972 {
973   TestApplication application;
974
975   Actor actor = Actor::New();
976   actor.SetSize(100.0f, 100.0f);
977   actor.SetAnchorPoint(AnchorPoint::TOP_LEFT);
978   Stage::GetCurrent().Add(actor);
979
980   // Render and notify
981   application.SendNotification();
982   application.Render();
983
984   // Attach actor to detector
985   SignalData data;
986   GestureReceivedFunctor functor( data );
987   TapGestureDetector detector = TapGestureDetector::New();
988   detector.Attach(actor);
989   detector.DetectedSignal().Connect( &application, functor );
990
991   // Try a Continuing state
992   try
993   {
994     application.ProcessEvent(GenerateTap(Gesture::Continuing, 1u, 1u, Vector2(50.0f, 10.0f)));
995     tet_result(TET_FAIL);
996   }
997   catch ( Dali::DaliException& e )
998   {
999     DALI_TEST_ASSERT( e, "false", TEST_LOCATION );
1000   }
1001   END_TEST;
1002 }
1003
1004 int UtcDaliTapGestureEmitIncorrectStateFinished(void)
1005 {
1006   TestApplication application;
1007
1008   Actor actor = Actor::New();
1009   actor.SetSize(100.0f, 100.0f);
1010   actor.SetAnchorPoint(AnchorPoint::TOP_LEFT);
1011   Stage::GetCurrent().Add(actor);
1012
1013   // Render and notify
1014   application.SendNotification();
1015   application.Render();
1016
1017   // Attach actor to detector
1018   SignalData data;
1019   GestureReceivedFunctor functor( data );
1020   TapGestureDetector detector = TapGestureDetector::New();
1021   detector.Attach(actor);
1022   detector.DetectedSignal().Connect( &application, functor );
1023
1024   // Try a Finished state
1025   try
1026   {
1027     application.ProcessEvent(GenerateTap(Gesture::Finished, 1u, 1u, Vector2(50.0f, 10.0f)));
1028     tet_result(TET_FAIL);
1029   }
1030   catch ( Dali::DaliException& e )
1031   {
1032     DALI_TEST_ASSERT( e, "false", TEST_LOCATION );
1033   }
1034   END_TEST;
1035 }
1036
1037 int UtcDaliTapGestureActorUnstaged(void)
1038 {
1039   TestApplication application;
1040
1041   Actor actor = Actor::New();
1042   actor.SetSize(100.0f, 100.0f);
1043   actor.SetAnchorPoint(AnchorPoint::TOP_LEFT);
1044   Stage::GetCurrent().Add(actor);
1045
1046   // Render and notify
1047   application.SendNotification();
1048   application.Render();
1049
1050   // Attach actor to detector
1051   SignalData data;
1052   UnstageActorFunctor functor( data );
1053   TapGestureDetector detector = TapGestureDetector::New();
1054   detector.Attach(actor);
1055   detector.DetectedSignal().Connect( &application, functor );
1056
1057   // Tap in Actor's area, actor removed in signal handler, should be handled gracefully.
1058   application.ProcessEvent(GenerateTap(Gesture::Possible, 1u, 1u, Vector2(50.0f, 10.0f)));
1059   application.ProcessEvent(GenerateTap(Gesture::Started, 1u, 1u, Vector2(50.0f, 10.0f)));
1060   DALI_TEST_EQUALS( true, data.functorCalled, TEST_LOCATION );
1061   tet_result( TET_PASS ); // If we get here, then the actor removal on signal handler was handled gracefully.
1062   END_TEST;
1063 }
1064
1065 int UtcDaliTapGestureRepeatedState(void)
1066 {
1067   TestApplication application;
1068
1069   Actor actor = Actor::New();
1070   actor.SetSize(100.0f, 100.0f);
1071   actor.SetAnchorPoint(AnchorPoint::TOP_LEFT);
1072   Stage::GetCurrent().Add(actor);
1073
1074   // Render and notify
1075   application.SendNotification();
1076   application.Render();
1077
1078   // Attach actor to detector
1079   SignalData data;
1080   GestureReceivedFunctor functor( data );
1081   TapGestureDetector detector = TapGestureDetector::New();
1082   detector.Attach(actor);
1083   detector.DetectedSignal().Connect( &application, functor );
1084
1085   // Emit two possibles
1086   application.ProcessEvent(GenerateTap(Gesture::Possible, 1u, 1u, Vector2(50.0f, 10.0f)));
1087   application.ProcessEvent(GenerateTap(Gesture::Possible, 1u, 1u, Vector2(50.0f, 10.0f)));
1088   DALI_TEST_EQUALS(false, data.functorCalled, TEST_LOCATION);
1089
1090   // Send a couple of Started states, only first one should be received.
1091   application.ProcessEvent(GenerateTap(Gesture::Started, 1u, 1u, Vector2(50.0f, 10.0f)));
1092   DALI_TEST_EQUALS(true, data.functorCalled, TEST_LOCATION);
1093   data.Reset();
1094   application.ProcessEvent(GenerateTap(Gesture::Started, 1u, 1u, Vector2(50.0f, 10.0f)));
1095   DALI_TEST_EQUALS(false, data.functorCalled, TEST_LOCATION);
1096
1097   // Send a couple of cancelled states, no reception
1098   application.ProcessEvent(GenerateTap(Gesture::Cancelled, 1u, 1u, Vector2(50.0f, 10.0f)));
1099   application.ProcessEvent(GenerateTap(Gesture::Cancelled, 1u, 1u, Vector2(50.0f, 10.0f)));
1100   DALI_TEST_EQUALS(false, data.functorCalled, TEST_LOCATION);
1101   END_TEST;
1102 }
1103
1104 int UtcDaliTapGesturePossibleCancelled(void)
1105 {
1106   TestApplication application;
1107
1108   Actor actor = Actor::New();
1109   actor.SetSize(100.0f, 100.0f);
1110   actor.SetAnchorPoint(AnchorPoint::TOP_LEFT);
1111   Stage::GetCurrent().Add(actor);
1112
1113   // Render and notify
1114   application.SendNotification();
1115   application.Render();
1116
1117   // Attach actor to detector
1118   SignalData data;
1119   GestureReceivedFunctor functor( data );
1120   TapGestureDetector detector = TapGestureDetector::New();
1121   detector.Attach(actor);
1122   detector.DetectedSignal().Connect( &application, functor );
1123
1124   // Emit a possible and then a cancelled, no reception
1125   application.ProcessEvent(GenerateTap(Gesture::Possible, 1u, 1u, Vector2(50.0f, 10.0f)));
1126   application.ProcessEvent(GenerateTap(Gesture::Cancelled, 1u, 1u, Vector2(50.0f, 10.0f)));
1127   DALI_TEST_EQUALS(false, data.functorCalled, TEST_LOCATION);
1128   END_TEST;
1129 }
1130
1131 int UtcDaliTapGestureDetectorRemovedWhilePossible(void)
1132 {
1133   TestApplication application;
1134
1135   Actor actor = Actor::New();
1136   actor.SetSize(100.0f, 100.0f);
1137   actor.SetAnchorPoint(AnchorPoint::TOP_LEFT);
1138   Stage::GetCurrent().Add(actor);
1139
1140   // Render and notify
1141   application.SendNotification();
1142   application.Render();
1143
1144   // Attach actor to detector
1145   SignalData data;
1146   GestureReceivedFunctor functor( data );
1147   TapGestureDetector detector = TapGestureDetector::New();
1148   detector.Attach(actor);
1149   detector.DetectedSignal().Connect( &application, functor );
1150
1151   // Emit a possible
1152   application.ProcessEvent(GenerateTap(Gesture::Possible, 1u, 1u, Vector2(50.0f, 10.0f)));
1153
1154   // Detach actor and send a Started state, no signal.
1155   detector.DetachAll();
1156   application.ProcessEvent(GenerateTap(Gesture::Started, 1u, 1u, Vector2(50.0f, 10.0f)));
1157   DALI_TEST_EQUALS(false, data.functorCalled, TEST_LOCATION);
1158   END_TEST;
1159 }
1160
1161 int UtcDaliTapGestureActorRemovedWhilePossible(void)
1162 {
1163   TestApplication application;
1164
1165   Actor actor = Actor::New();
1166   actor.SetSize(100.0f, 100.0f);
1167   actor.SetAnchorPoint(AnchorPoint::TOP_LEFT);
1168   Stage::GetCurrent().Add(actor);
1169
1170   // Render and notify
1171   application.SendNotification();
1172   application.Render();
1173
1174   // Attach actor to detector
1175   SignalData data;
1176   GestureReceivedFunctor functor( data );
1177   TapGestureDetector detector = TapGestureDetector::New();
1178   detector.Attach(actor);
1179   detector.DetectedSignal().Connect( &application, functor );
1180
1181   // Emit a possible
1182   application.ProcessEvent(GenerateTap(Gesture::Possible, 1u, 1u, Vector2(50.0f, 10.0f)));
1183
1184   // Remove, render and delete actor
1185   Stage::GetCurrent().Remove(actor);
1186   application.SendNotification();
1187   application.Render();
1188   actor.Reset();
1189
1190   // Send a Started state, no signal.
1191   application.ProcessEvent(GenerateTap(Gesture::Started, 1u, 1u, Vector2(50.0f, 10.0f)));
1192   DALI_TEST_EQUALS(false, data.functorCalled, TEST_LOCATION);
1193   END_TEST;
1194 }
1195
1196 int UtcDaliTapGestureSystemOverlay(void)
1197 {
1198   TestApplication application;
1199   Dali::Integration::Core& core = application.GetCore();
1200   Dali::Integration::SystemOverlay& systemOverlay( core.GetSystemOverlay() );
1201   systemOverlay.GetOverlayRenderTasks().CreateTask();
1202
1203   Actor actor = Actor::New();
1204   actor.SetSize(100.0f, 100.0f);
1205   actor.SetAnchorPoint(AnchorPoint::TOP_LEFT);
1206   systemOverlay.Add(actor);
1207
1208   // Render and notify
1209   application.SendNotification();
1210   application.Render();
1211
1212   SignalData data;
1213   GestureReceivedFunctor functor(data);
1214
1215   TapGestureDetector detector = TapGestureDetector::New();
1216   detector.Attach(actor);
1217   detector.DetectedSignal().Connect(&application, functor);
1218
1219   Vector2 screenCoords( 50.0f, 50.0f );
1220
1221   // Do a tap inside actor's area
1222   application.ProcessEvent( GenerateTap( Gesture::Possible, 1u, 1u, screenCoords ) );
1223   application.ProcessEvent( GenerateTap( Gesture::Started, 1u, 1u, screenCoords ) );
1224   DALI_TEST_EQUALS( true, data.functorCalled, TEST_LOCATION );
1225   END_TEST;
1226 }
1227
1228 int UtcDaliTapGestureBehindTouchableSystemOverlay(void)
1229 {
1230   TestApplication application;
1231   Dali::Integration::Core& core = application.GetCore();
1232   Dali::Integration::SystemOverlay& systemOverlay( core.GetSystemOverlay() );
1233   systemOverlay.GetOverlayRenderTasks().CreateTask();
1234
1235   // SystemOverlay actor
1236   Actor systemOverlayActor = Actor::New();
1237   systemOverlayActor.SetSize(100.0f, 100.0f);
1238   systemOverlayActor.SetAnchorPoint(AnchorPoint::TOP_LEFT);
1239   systemOverlay.Add(systemOverlayActor);
1240
1241   // Stage actor
1242   Actor stageActor = Actor::New();
1243   stageActor.SetSize(100.0f, 100.0f);
1244   stageActor.SetAnchorPoint(AnchorPoint::TOP_LEFT);
1245   Stage::GetCurrent().Add(stageActor);
1246
1247   // Render and notify
1248   application.SendNotification();
1249   application.Render();
1250
1251   // Set system-overlay actor to touchable
1252   TouchEventData touchData;
1253   TouchEventDataFunctor touchFunctor( touchData );
1254   systemOverlayActor.TouchedSignal().Connect(&application, touchFunctor);
1255
1256   // Set stage actor to receive the gesture
1257   SignalData data;
1258   GestureReceivedFunctor functor(data);
1259
1260   TapGestureDetector detector = TapGestureDetector::New();
1261   detector.Attach(stageActor);
1262   detector.DetectedSignal().Connect(&application, functor);
1263
1264   Vector2 screenCoords( 50.0f, 50.0f );
1265
1266   // Do a tap inside both actors' area
1267   application.ProcessEvent( GenerateTap( Gesture::Possible, 1u, 1u, screenCoords ) );
1268   application.ProcessEvent( GenerateTap( Gesture::Started, 1u, 1u, screenCoords ) );
1269   DALI_TEST_EQUALS( true, data.functorCalled, TEST_LOCATION );
1270   DALI_TEST_EQUALS( false, touchData.functorCalled, TEST_LOCATION );
1271
1272   data.Reset();
1273   touchData.Reset();
1274
1275   // Do touch in the same area
1276   application.ProcessEvent( touchFunctor.GenerateSingleTouch( TouchPoint::Down, screenCoords ) );
1277   DALI_TEST_EQUALS( false, data.functorCalled, TEST_LOCATION );
1278   DALI_TEST_EQUALS( true, touchData.functorCalled, TEST_LOCATION );
1279
1280   END_TEST;
1281 }
1282
1283 int UtcDaliTapGestureTouchBehindGesturedSystemOverlay(void)
1284 {
1285   TestApplication application;
1286   Dali::Integration::Core& core = application.GetCore();
1287   Dali::Integration::SystemOverlay& systemOverlay( core.GetSystemOverlay() );
1288   systemOverlay.GetOverlayRenderTasks().CreateTask();
1289
1290   // SystemOverlay actor
1291   Actor systemOverlayActor = Actor::New();
1292   systemOverlayActor.SetSize(100.0f, 100.0f);
1293   systemOverlayActor.SetAnchorPoint(AnchorPoint::TOP_LEFT);
1294   systemOverlay.Add(systemOverlayActor);
1295
1296   // Stage actor
1297   Actor stageActor = Actor::New();
1298   stageActor.SetSize(100.0f, 100.0f);
1299   stageActor.SetAnchorPoint(AnchorPoint::TOP_LEFT);
1300   Stage::GetCurrent().Add(stageActor);
1301
1302   // Render and notify
1303   application.SendNotification();
1304   application.Render();
1305
1306   // Set stage actor to touchable
1307   TouchEventData touchData;
1308   TouchEventDataFunctor touchFunctor( touchData );
1309   stageActor.TouchedSignal().Connect(&application, touchFunctor);
1310
1311   // Set system-overlay actor to have the gesture
1312   SignalData data;
1313   GestureReceivedFunctor functor(data);
1314
1315   TapGestureDetector detector = TapGestureDetector::New();
1316   detector.Attach(systemOverlayActor);
1317   detector.DetectedSignal().Connect(&application, functor);
1318
1319   Vector2 screenCoords( 50.0f, 50.0f );
1320
1321   // Do a tap inside both actors' area
1322   application.ProcessEvent( GenerateTap( Gesture::Possible, 1u, 1u, screenCoords ) );
1323   application.ProcessEvent( GenerateTap( Gesture::Started, 1u, 1u, screenCoords ) );
1324   DALI_TEST_EQUALS( true, data.functorCalled, TEST_LOCATION );
1325   DALI_TEST_EQUALS( false, touchData.functorCalled, TEST_LOCATION );
1326
1327   data.Reset();
1328   touchData.Reset();
1329
1330   // Do touch in the same area
1331   application.ProcessEvent( touchFunctor.GenerateSingleTouch( TouchPoint::Down, screenCoords ) );
1332   DALI_TEST_EQUALS( false, data.functorCalled, TEST_LOCATION );
1333   DALI_TEST_EQUALS( true, touchData.functorCalled, TEST_LOCATION );
1334
1335   END_TEST;
1336 }
1337
1338 int UtcDaliTapGestureLayerConsumesTouch(void)
1339 {
1340   TestApplication application;
1341
1342   Actor actor = Actor::New();
1343   actor.SetSize(100.0f, 100.0f);
1344   actor.SetAnchorPoint(AnchorPoint::TOP_LEFT);
1345   Stage::GetCurrent().Add(actor);
1346
1347   // Add a detector
1348   SignalData data;
1349   GestureReceivedFunctor functor(data);
1350   TapGestureDetector detector = TapGestureDetector::New();
1351   detector.Attach(actor);
1352   detector.DetectedSignal().Connect( &application, functor );
1353
1354   // Add a layer to overlap the actor
1355   Layer layer = Layer::New();
1356   layer.SetSize(100.0f, 100.0f);
1357   layer.SetAnchorPoint(AnchorPoint::TOP_LEFT);
1358   Stage::GetCurrent().Add( layer );
1359   layer.RaiseToTop();
1360
1361   // Render and notify
1362   application.SendNotification();
1363   application.Render();
1364
1365   Vector2 screenCoords( 50.0f, 50.0f );
1366
1367   // Emit signals, should receive
1368   application.ProcessEvent( GenerateTap( Gesture::Possible, 1u, 1u, screenCoords ) );
1369   application.ProcessEvent( GenerateTap( Gesture::Started, 1u, 1u, screenCoords ) );
1370   DALI_TEST_EQUALS(true, data.functorCalled, TEST_LOCATION);
1371   data.Reset();
1372
1373   // Set layer to consume all touch
1374   layer.SetTouchConsumed( true );
1375
1376   // Render and notify
1377   application.SendNotification();
1378   application.Render();
1379
1380   // Emit the same signals again, should not receive
1381   application.ProcessEvent( GenerateTap( Gesture::Possible, 1u, 1u, screenCoords ) );
1382   application.ProcessEvent( GenerateTap( Gesture::Started, 1u, 1u, screenCoords ) );
1383   DALI_TEST_EQUALS(false, data.functorCalled, TEST_LOCATION);
1384   data.Reset();
1385
1386   END_TEST;
1387 }