[dali_1.4.8] Merge branch 'devel/master'
[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/render-task-list-integ.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   Integration::Point point;
212   point.SetDeviceId( 1 );
213   point.SetState( PointState::DOWN );
214   point.SetScreenPosition( Vector2( 20.0f, 20.0f ) );
215   touchEvent.AddPoint(point);
216   application.ProcessEvent(touchEvent);
217
218   // Render and notify
219   application.SendNotification();
220   application.Render();
221
222   // For line coverage, Initialise default constructor
223   TouchEvent touchEvent2;
224   END_TEST;
225 }
226
227 int UtcDaliTapGestureDetectorDownCast(void)
228 {
229   TestApplication application;
230   tet_infoline("Testing Dali::TapGestureDetector::DownCast()");
231
232   TapGestureDetector detector = TapGestureDetector::New();
233
234   BaseHandle object(detector);
235
236   TapGestureDetector detector2 = TapGestureDetector::DownCast(object);
237   DALI_TEST_CHECK(detector2);
238
239   TapGestureDetector detector3 = DownCast< TapGestureDetector >(object);
240   DALI_TEST_CHECK(detector3);
241
242   BaseHandle unInitializedObject;
243   TapGestureDetector detector4 = TapGestureDetector::DownCast(unInitializedObject);
244   DALI_TEST_CHECK(!detector4);
245
246   TapGestureDetector detector5 = DownCast< TapGestureDetector >(unInitializedObject);
247   DALI_TEST_CHECK(!detector5);
248
249   GestureDetector detector6 = TapGestureDetector::New();
250   TapGestureDetector detector7 = TapGestureDetector::DownCast(detector6);
251   DALI_TEST_CHECK(detector7);
252   END_TEST;
253 }
254
255 int UtcDaliTapGestureSetTapsRequired(void)
256 {
257   TestApplication application;
258
259   TapGestureDetector detector = TapGestureDetector::New();
260
261   const unsigned int minTaps = 3;
262   const unsigned int maxTaps = 7;
263
264   DALI_TEST_CHECK( minTaps != detector.GetMinimumTapsRequired() );
265   DALI_TEST_CHECK( maxTaps != detector.GetMaximumTapsRequired() );
266
267   detector.SetMinimumTapsRequired( minTaps );
268   detector.SetMaximumTapsRequired( maxTaps );
269
270   DALI_TEST_EQUALS( minTaps, detector.GetMinimumTapsRequired(), TEST_LOCATION );
271   DALI_TEST_EQUALS( maxTaps, detector.GetMaximumTapsRequired(), TEST_LOCATION );
272
273   // Attach an actor and change the required touches
274
275   Actor actor = Actor::New();
276   actor.SetSize(100.0f, 100.0f);
277   actor.SetAnchorPoint(AnchorPoint::TOP_LEFT);
278   Stage::GetCurrent().Add(actor);
279
280   // Render and notify
281   application.SendNotification();
282   application.Render();
283
284   SignalData data;
285   GestureReceivedFunctor functor(data);
286
287   detector.Attach(actor);
288   detector.DetectedSignal().Connect( &application, functor );
289
290   // Ensure signal is emitted if minimum taps received
291   application.ProcessEvent(GenerateTap(Gesture::Possible, minTaps, 1u, Vector2(50.0f, 50.0f)));
292   application.ProcessEvent(GenerateTap(Gesture::Started, minTaps, 1u, Vector2(50.0f, 50.0f)));
293   DALI_TEST_EQUALS( true, data.functorCalled, TEST_LOCATION );
294   DALI_TEST_EQUALS( minTaps, data.receivedGesture.numberOfTaps, TEST_LOCATION );
295   data.Reset();
296
297   // Ensure signal is emitted if maximum taps received
298   application.ProcessEvent(GenerateTap(Gesture::Possible, maxTaps, 1u, Vector2(50.0f, 50.0f)));
299   application.ProcessEvent(GenerateTap(Gesture::Started, maxTaps, 1u, Vector2(50.0f, 50.0f)));
300   DALI_TEST_EQUALS( true, data.functorCalled, TEST_LOCATION );
301   DALI_TEST_EQUALS( maxTaps, data.receivedGesture.numberOfTaps, TEST_LOCATION );
302   data.Reset();
303
304   // Ensure signal is NOT emitted if outside the range
305   application.ProcessEvent(GenerateTap(Gesture::Possible, minTaps - 1, 1u, Vector2(50.0f, 50.0f)));
306   application.ProcessEvent(GenerateTap(Gesture::Started, minTaps - 1, 1u, Vector2(50.0f, 50.0f)));
307   DALI_TEST_EQUALS( false, data.functorCalled, TEST_LOCATION );
308   data.Reset();
309   application.ProcessEvent(GenerateTap(Gesture::Possible, maxTaps + 1, 1u, Vector2(50.0f, 50.0f)));
310   application.ProcessEvent(GenerateTap(Gesture::Started, maxTaps + 1, 1u, Vector2(50.0f, 50.0f)));
311   DALI_TEST_EQUALS( false, data.functorCalled, TEST_LOCATION );
312   data.Reset();
313
314   TestGestureManager& gestureManager = application.GetGestureManager();
315   gestureManager.Initialize();
316
317   detector.SetMinimumTapsRequired(4);
318
319   // Gesture detection should have been updated only
320   DALI_TEST_EQUALS(true, gestureManager.WasCalled(TestGestureManager::UpdateType), TEST_LOCATION);
321   DALI_TEST_EQUALS(false, gestureManager.WasCalled(TestGestureManager::RegisterType), TEST_LOCATION);
322   DALI_TEST_EQUALS(false, gestureManager.WasCalled(TestGestureManager::UnregisterType), TEST_LOCATION);
323
324   // Reset values
325   gestureManager.Initialize();
326
327   detector.SetMaximumTapsRequired(maxTaps);
328
329   // Gesture detection should NOT have been updated
330   DALI_TEST_EQUALS(false, gestureManager.WasCalled(TestGestureManager::UpdateType), TEST_LOCATION);
331   DALI_TEST_EQUALS(false, gestureManager.WasCalled(TestGestureManager::RegisterType), TEST_LOCATION);
332   DALI_TEST_EQUALS(false, gestureManager.WasCalled(TestGestureManager::UnregisterType), TEST_LOCATION);
333
334   // Reset values
335   gestureManager.Initialize();
336
337   // Create a second gesture detector that requires even less maximum touches
338   TapGestureDetector secondDetector = TapGestureDetector::New();
339   secondDetector.Attach(actor);
340
341   // Gesture detection should have been updated
342   DALI_TEST_EQUALS(true, gestureManager.WasCalled(TestGestureManager::UpdateType), TEST_LOCATION);
343   DALI_TEST_EQUALS(false, gestureManager.WasCalled(TestGestureManager::RegisterType), TEST_LOCATION);
344   DALI_TEST_EQUALS(false, gestureManager.WasCalled(TestGestureManager::UnregisterType), TEST_LOCATION);
345
346   // Reset values
347   gestureManager.Initialize();
348
349   // Delete the second detector so that our detection is updated again
350   secondDetector.Reset();
351   DALI_TEST_EQUALS(true, gestureManager.WasCalled(TestGestureManager::UpdateType), TEST_LOCATION);
352   DALI_TEST_EQUALS(false, gestureManager.WasCalled(TestGestureManager::RegisterType), TEST_LOCATION);
353   DALI_TEST_EQUALS(false, gestureManager.WasCalled(TestGestureManager::UnregisterType), TEST_LOCATION);
354
355   // Set the minimum to be greater than the maximum, should Assert
356   try
357   {
358     detector.SetMinimumTapsRequired( maxTaps );
359     detector.SetMaximumTapsRequired( minTaps );
360     DALI_TEST_CHECK( false ); // Should not get here
361   }
362   catch ( DaliException& e )
363   {
364     DALI_TEST_CHECK( true );
365   }
366
367   END_TEST;
368 }
369
370 int UtcDaliTapGestureSetTapsRequiredMinMaxCheck(void)
371 {
372   TestApplication application;
373
374   // Attach an actor and change the required touches
375
376   Actor actor = Actor::New();
377   actor.SetSize(100.0f, 100.0f);
378   actor.SetAnchorPoint(AnchorPoint::TOP_LEFT);
379   Stage::GetCurrent().Add(actor);
380
381   // Render and notify
382   application.SendNotification();
383   application.Render();
384
385   // Set the minimum to be greater than the maximum, should Assert
386
387   try
388   {
389     TapGestureDetector detector = TapGestureDetector::New();
390     detector.SetMinimumTapsRequired( 7u );
391     detector.SetMaximumTapsRequired( 3u );
392     detector.Attach(actor);
393     DALI_TEST_CHECK( false ); // Should not get here
394   }
395   catch ( DaliException& e )
396   {
397     DALI_TEST_CHECK( true );
398   }
399
400   END_TEST;
401 }
402
403 int UtcDaliTapGestureGetTapsRequired(void)
404 {
405   TestApplication application;
406
407   TapGestureDetector detector = TapGestureDetector::New();
408   DALI_TEST_EQUALS(1u, detector.GetMinimumTapsRequired(), TEST_LOCATION);
409   DALI_TEST_EQUALS(1u, detector.GetMaximumTapsRequired(), TEST_LOCATION);
410   END_TEST;
411 }
412
413 int UtcDaliTapGestureSignalReceptionNegative(void)
414 {
415   TestApplication application;
416
417   Actor actor = Actor::New();
418   actor.SetSize(100.0f, 100.0f);
419   actor.SetAnchorPoint(AnchorPoint::TOP_LEFT);
420   Stage::GetCurrent().Add(actor);
421
422   // Render and notify
423   application.SendNotification();
424   application.Render();
425
426   SignalData data;
427   GestureReceivedFunctor functor(data);
428
429   TapGestureDetector detector = TapGestureDetector::New();
430   detector.Attach(actor);
431   detector.DetectedSignal().Connect( &application, functor );
432
433   // Do a tap outside actor's area
434   application.ProcessEvent(GenerateTap(Gesture::Possible, 1u, 1u, Vector2(112.0f, 112.0f)));
435   application.ProcessEvent(GenerateTap(Gesture::Started, 1u, 1u, Vector2(112.0f, 112.0f)));
436   DALI_TEST_EQUALS(false, data.functorCalled, TEST_LOCATION);
437   END_TEST;
438 }
439
440 int UtcDaliTapGestureSignalReceptionPositive(void)
441 {
442   TestApplication application;
443
444   Actor actor = Actor::New();
445   actor.SetSize(100.0f, 100.0f);
446   actor.SetAnchorPoint(AnchorPoint::TOP_LEFT);
447   Stage::GetCurrent().Add(actor);
448
449   // Render and notify
450   application.SendNotification();
451   application.Render();
452
453   SignalData data;
454   GestureReceivedFunctor functor(data);
455
456   TapGestureDetector detector = TapGestureDetector::New();
457   detector.Attach(actor);
458   detector.DetectedSignal().Connect( &application, functor );
459
460   // Do a tap inside actor's area
461   application.ProcessEvent(GenerateTap(Gesture::Possible, 1u, 1u, Vector2(50.0f, 50.0f)));
462   application.ProcessEvent(GenerateTap(Gesture::Started, 1u, 1u, Vector2(50.0f, 50.0f)));
463   DALI_TEST_EQUALS(true, data.functorCalled, TEST_LOCATION);
464   DALI_TEST_EQUALS(1u, data.receivedGesture.numberOfTaps, TEST_LOCATION);
465   DALI_TEST_EQUALS(1u, data.receivedGesture.numberOfTouches, TEST_LOCATION);
466   DALI_TEST_EQUALS( Vector2(50.0f, 50.0f), data.receivedGesture.localPoint, 0.1, TEST_LOCATION);
467   END_TEST;
468 }
469
470 int UtcDaliTapGestureSignalReceptionDetach(void)
471 {
472   TestApplication application;
473
474   Actor actor = Actor::New();
475   actor.SetSize(100.0f, 100.0f);
476   actor.SetAnchorPoint(AnchorPoint::TOP_LEFT);
477   Stage::GetCurrent().Add(actor);
478
479   // Render and notify
480   application.SendNotification();
481   application.Render();
482
483   SignalData data;
484   GestureReceivedFunctor functor(data);
485
486   TapGestureDetector detector = TapGestureDetector::New();
487   detector.Attach(actor);
488   detector.DetectedSignal().Connect(&application, functor);
489
490   // Start tap within the actor's area
491   application.ProcessEvent(GenerateTap(Gesture::Possible, 1u, 1u, Vector2(20.0f, 20.0f)));
492   application.ProcessEvent(GenerateTap(Gesture::Started, 1u, 1u, Vector2(20.0f, 20.0f)));
493   DALI_TEST_EQUALS(true, data.functorCalled, TEST_LOCATION);
494   DALI_TEST_EQUALS(1u, data.receivedGesture.numberOfTaps, TEST_LOCATION);
495   DALI_TEST_EQUALS(1u, data.receivedGesture.numberOfTouches, TEST_LOCATION);
496   DALI_TEST_EQUALS( Vector2(20.0f, 20.0f), data.receivedGesture.localPoint, 0.1, TEST_LOCATION);
497
498   // repeat the tap within the actor's area - we should still receive the signal
499   data.Reset();
500   application.ProcessEvent(GenerateTap(Gesture::Possible, 1u, 1u, Vector2(50.0f, 50.0f)));
501   application.ProcessEvent(GenerateTap(Gesture::Started, 1u, 1u, Vector2(50.0f, 50.0f)));
502   DALI_TEST_EQUALS(true, data.functorCalled, TEST_LOCATION);
503   DALI_TEST_EQUALS(1u, data.receivedGesture.numberOfTaps, TEST_LOCATION);
504   DALI_TEST_EQUALS(1u, data.receivedGesture.numberOfTouches, TEST_LOCATION);
505   DALI_TEST_EQUALS( Vector2(50.0f, 50.0f), data.receivedGesture.localPoint, 0.1, TEST_LOCATION);
506
507   // Detach actor
508   detector.DetachAll();
509
510   // Ensure we are no longer signalled
511   data.Reset();
512   application.ProcessEvent(GenerateTap(Gesture::Possible, 1u, 1u, Vector2(20.0f, 20.0f)));
513   application.ProcessEvent(GenerateTap(Gesture::Started, 1u, 1u, Vector2(20.0f, 20.0f)));
514   DALI_TEST_EQUALS(false, data.functorCalled, TEST_LOCATION);
515   application.ProcessEvent(GenerateTap(Gesture::Possible, 1u, 1u, Vector2(50.0f, 50.0f)));
516   application.ProcessEvent(GenerateTap(Gesture::Started, 1u, 1u, Vector2(50.0f, 50.0f)));
517   DALI_TEST_EQUALS(false, data.functorCalled, TEST_LOCATION);
518   END_TEST;
519 }
520
521 int UtcDaliTapGestureSignalReceptionActorDestroyedWhileTapping(void)
522 {
523   TestApplication application;
524
525   SignalData data;
526   GestureReceivedFunctor functor(data);
527
528   TapGestureDetector detector = TapGestureDetector::New();
529   detector.DetectedSignal().Connect(&application, functor);
530
531   // Actor lifetime is scoped
532   {
533     Actor actor = Actor::New();
534     actor.SetSize(100.0f, 100.0f);
535     actor.SetAnchorPoint(AnchorPoint::TOP_LEFT);
536     Stage::GetCurrent().Add(actor);
537
538     // Render and notify
539     application.SendNotification();
540     application.Render();
541
542     detector.Attach(actor);
543
544     // Start tap within the actor's area
545     application.ProcessEvent(GenerateTap(Gesture::Possible, 1u, 1u, Vector2(20.0f, 20.0f)));
546     application.ProcessEvent(GenerateTap(Gesture::Started, 1u, 1u, Vector2(20.0f, 20.0f)));
547     DALI_TEST_EQUALS(true, data.functorCalled, TEST_LOCATION);
548
549     // Remove the actor from stage and reset the data
550     Stage::GetCurrent().Remove(actor);
551
552     // Render and notify
553     application.SendNotification();
554     application.Render();
555   }
556
557   // Actor should now have been destroyed
558
559   data.Reset();
560   application.ProcessEvent(GenerateTap(Gesture::Possible, 1u, 1u, Vector2(20.0f, 20.0f)));
561   application.ProcessEvent(GenerateTap(Gesture::Started, 1u, 1u, Vector2(20.0f, 20.0f)));
562   DALI_TEST_EQUALS(false, data.functorCalled, TEST_LOCATION);
563   END_TEST;
564 }
565
566 int UtcDaliTapGestureSignalReceptionRotatedActor(void)
567 {
568   TestApplication application;
569
570   Actor actor = Actor::New();
571   actor.SetSize(100.0f, 100.0f);
572   actor.SetOrientation(Dali::Degree(90.0f), Vector3::ZAXIS);
573   Stage::GetCurrent().Add(actor);
574
575   // Render and notify
576   application.SendNotification();
577   application.Render();
578
579   SignalData data;
580   GestureReceivedFunctor functor(data);
581
582   TapGestureDetector detector = TapGestureDetector::New();
583   detector.Attach(actor);
584   detector.DetectedSignal().Connect(&application, functor);
585
586   // Do tap, only check finished value
587   application.ProcessEvent(GenerateTap(Gesture::Possible, 1u, 1u, Vector2(5.0f, 5.0f)));
588   application.ProcessEvent(GenerateTap(Gesture::Started, 1u, 1u, Vector2(5.0f, 5.0f)));
589   DALI_TEST_EQUALS(true, data.functorCalled, TEST_LOCATION);
590   DALI_TEST_EQUALS(1u, data.receivedGesture.numberOfTaps, TEST_LOCATION);
591   DALI_TEST_EQUALS(1u, data.receivedGesture.numberOfTouches, TEST_LOCATION);
592   DALI_TEST_EQUALS( Vector2(5.0f, 5.0f), data.receivedGesture.screenPoint, 0.1, TEST_LOCATION);
593
594   // Rotate actor again and render
595   actor.SetOrientation(Dali::Degree(180.0f), Vector3::ZAXIS);
596   application.SendNotification();
597   application.Render();
598
599   // Do tap, should still receive event
600   data.Reset();
601   application.ProcessEvent(GenerateTap(Gesture::Possible, 1u, 1u, Vector2(5.0f, 5.0f)));
602   application.ProcessEvent(GenerateTap(Gesture::Started, 1u, 1u, Vector2(5.0f, 5.0f)));
603   DALI_TEST_EQUALS(true, data.functorCalled, TEST_LOCATION);
604   DALI_TEST_EQUALS(1u, data.receivedGesture.numberOfTaps, TEST_LOCATION);
605   DALI_TEST_EQUALS(1u, data.receivedGesture.numberOfTouches, TEST_LOCATION);
606   DALI_TEST_EQUALS( Vector2(5.0f, 5.0f), data.receivedGesture.screenPoint, 0.1, TEST_LOCATION);
607
608   // Rotate actor again and render
609   actor.SetOrientation(Dali::Degree(90.0f), Vector3::YAXIS);
610   application.SendNotification();
611   application.Render();
612
613   // Do tap, inside the actor's area (area if it is not rotated), Should not receive the event
614   data.Reset();
615   application.ProcessEvent(GenerateTap(Gesture::Possible, 1u, 1u, Vector2(70.0f, 70.0f)));
616   application.ProcessEvent(GenerateTap(Gesture::Started, 1u, 1u, Vector2(70.0f, 70.0f)));
617   DALI_TEST_EQUALS(false, data.functorCalled, TEST_LOCATION);
618   END_TEST;
619 }
620
621 int UtcDaliTapGestureSignalReceptionChildHit(void)
622 {
623   TestApplication application;
624
625   Actor parent = Actor::New();
626   parent.SetSize(100.0f, 100.0f);
627   parent.SetAnchorPoint(AnchorPoint::TOP_LEFT);
628   Stage::GetCurrent().Add(parent);
629
630   // Set child to completely cover parent.
631   // Change rotation of child to be different from parent so that we can check if our local coordinate
632   // conversion of the parent actor is correct.
633   Actor child = Actor::New();
634   child.SetSize(100.0f, 100.0f);
635   child.SetAnchorPoint(AnchorPoint::CENTER);
636   child.SetParentOrigin(ParentOrigin::CENTER);
637   child.SetOrientation(Dali::Degree(90.0f), Vector3::ZAXIS);
638   parent.Add(child);
639
640   TouchEventFunctor touchFunctor;
641   child.TouchedSignal().Connect(&application, touchFunctor);
642
643   // Render and notify
644   application.SendNotification();
645   application.Render();
646
647   SignalData data;
648   GestureReceivedFunctor functor(data);
649
650   TapGestureDetector detector = TapGestureDetector::New();
651   detector.Attach(parent);
652   detector.DetectedSignal().Connect(&application, functor);
653
654   // Do tap - hits child area but parent should still receive it
655   application.ProcessEvent(GenerateTap(Gesture::Possible, 1u, 1u, Vector2(50.0f, 50.0f)));
656   application.ProcessEvent(GenerateTap(Gesture::Started, 1u, 1u, Vector2(50.0f, 50.0f)));
657   DALI_TEST_EQUALS(true, data.functorCalled, TEST_LOCATION);
658   DALI_TEST_EQUALS(true, parent == data.tappedActor, TEST_LOCATION);
659   DALI_TEST_EQUALS(Vector2(50.0f, 50.0f), data.receivedGesture.screenPoint, 0.01f, TEST_LOCATION);
660
661   // Attach child and generate same touch points
662   // (Also proves that you can detach and then re-attach another actor)
663   detector.Attach(child);
664   detector.Detach(parent);
665
666   // Do an entire tap, only check finished value
667   data.Reset();
668   application.ProcessEvent(GenerateTap(Gesture::Possible, 1u, 1u, Vector2(51.0f, 51.0f)));
669   application.ProcessEvent(GenerateTap(Gesture::Started, 1u, 1u, Vector2(51.0f, 51.0f)));
670   DALI_TEST_EQUALS(true, data.functorCalled, TEST_LOCATION);
671   DALI_TEST_EQUALS(true, child == data.tappedActor, TEST_LOCATION);
672   DALI_TEST_EQUALS(Vector2(51.0f, 51.0f), data.receivedGesture.screenPoint, 0.01f, TEST_LOCATION);
673   END_TEST;
674 }
675
676 int UtcDaliTapGestureSignalReceptionAttachDetachMany(void)
677 {
678   TestApplication application;
679
680   Actor first = Actor::New();
681   first.SetSize(100.0f, 100.0f);
682   first.SetAnchorPoint(AnchorPoint::TOP_LEFT);
683   Stage::GetCurrent().Add(first);
684
685   Actor second = Actor::New();
686   second.SetSize(100.0f, 100.0f);
687   second.SetX(100.0f);
688   second.SetAnchorPoint(AnchorPoint::TOP_LEFT);
689   Stage::GetCurrent().Add(second);
690
691   // Render and notify
692   application.SendNotification();
693   application.Render();
694
695   SignalData data;
696   GestureReceivedFunctor functor(data);
697
698   TapGestureDetector detector = TapGestureDetector::New();
699   detector.Attach(first);
700   detector.Attach(second);
701   detector.DetectedSignal().Connect(&application, functor);
702
703   // Tap within second actor's area
704   application.ProcessEvent(GenerateTap(Gesture::Possible, 1u, 1u, Vector2(120.0f, 10.0f)));
705   application.ProcessEvent(GenerateTap(Gesture::Started, 1u, 1u, Vector2(120.0f, 10.0f)));
706   DALI_TEST_EQUALS(true, data.functorCalled, TEST_LOCATION);
707   DALI_TEST_EQUALS(true, second == data.tappedActor, TEST_LOCATION);
708
709   // Tap within first actor's area
710   data.Reset();
711   application.ProcessEvent(GenerateTap(Gesture::Possible, 1u, 1u, Vector2(20.0f, 10.0f)));
712   application.ProcessEvent(GenerateTap(Gesture::Started, 1u, 1u, Vector2(20.0f, 10.0f)));
713   DALI_TEST_EQUALS(true, data.functorCalled, TEST_LOCATION);
714   DALI_TEST_EQUALS(true, first == data.tappedActor, TEST_LOCATION);
715
716   // Detach the second actor
717   detector.Detach(second);
718
719   // second actor shouldn't receive event
720   data.Reset();
721   application.ProcessEvent(GenerateTap(Gesture::Possible, 1u, 1u, Vector2(120.0f, 10.0f)));
722   application.ProcessEvent(GenerateTap(Gesture::Started, 1u, 1u, Vector2(120.0f, 10.0f)));
723   DALI_TEST_EQUALS(false, data.functorCalled, TEST_LOCATION);
724
725   // first actor should continue receiving event
726   data.Reset();
727   application.ProcessEvent(GenerateTap(Gesture::Possible, 1u, 1u, Vector2(20.0f, 10.0f)));
728   application.ProcessEvent(GenerateTap(Gesture::Started, 1u, 1u, Vector2(20.0f, 10.0f)));
729   DALI_TEST_EQUALS(true, data.functorCalled, TEST_LOCATION);
730   END_TEST;
731 }
732
733 int UtcDaliTapGestureSignalReceptionActorBecomesUntouchable(void)
734 {
735   TestApplication application;
736
737   Actor actor = Actor::New();
738   actor.SetSize(100.0f, 100.0f);
739   actor.SetAnchorPoint(AnchorPoint::TOP_LEFT);
740   Stage::GetCurrent().Add(actor);
741
742   // Render and notify
743   application.SendNotification();
744   application.Render();
745
746   SignalData data;
747   GestureReceivedFunctor functor(data);
748
749   TapGestureDetector detector = TapGestureDetector::New();
750   detector.Attach(actor);
751   detector.DetectedSignal().Connect(&application, functor);
752
753   // Tap in actor's area
754   application.ProcessEvent(GenerateTap(Gesture::Possible, 1u, 1u, Vector2(50.0f, 10.0f)));
755   application.ProcessEvent(GenerateTap(Gesture::Started, 1u, 1u, Vector2(50.0f, 10.0f)));
756   DALI_TEST_EQUALS(true, data.functorCalled, TEST_LOCATION);
757
758   // Actor become invisible - actor should not receive the next pan
759   actor.SetVisible(false);
760
761   // Render and notify
762   application.SendNotification();
763   application.Render();
764
765   // Tap in the same area, shouldn't receive event
766   data.Reset();
767   application.ProcessEvent(GenerateTap(Gesture::Possible, 1u, 1u, Vector2(50.0f, 10.0f)));
768   application.ProcessEvent(GenerateTap(Gesture::Started, 1u, 1u, Vector2(50.0f, 10.0f)));
769   DALI_TEST_EQUALS(false, data.functorCalled, TEST_LOCATION);
770   END_TEST;
771 }
772
773 int UtcDaliTapGestureSignalReceptionMultipleGestureDetectors(void)
774 {
775   TestApplication application;
776   Dali::TestGestureManager& gestureManager = application.GetGestureManager();
777
778   Actor first = Actor::New();
779   first.SetSize(100.0f, 100.0f);
780   first.SetAnchorPoint(AnchorPoint::TOP_LEFT);
781   Stage::GetCurrent().Add(first);
782
783   Actor second = Actor::New();
784   second.SetSize(100.0f, 100.0f);
785   second.SetAnchorPoint(AnchorPoint::TOP_LEFT);
786   second.SetX(100.0f);
787   first.Add(second);
788
789   // Render and notify
790   application.SendNotification();
791   application.Render();
792
793   SignalData data;
794   GestureReceivedFunctor functor(data);
795
796   TapGestureDetector firstDetector = TapGestureDetector::New();
797   firstDetector.Attach(first);
798   firstDetector.DetectedSignal().Connect(&application, functor);
799
800   // secondDetector is scoped
801   {
802     // Reset gestureManager statistics
803     gestureManager.Initialize();
804
805     TapGestureDetector secondDetector = TapGestureDetector::New( 2 );
806     secondDetector.Attach(second);
807     secondDetector.DetectedSignal().Connect(&application, functor);
808
809     DALI_TEST_EQUALS(true, gestureManager.WasCalled(TestGestureManager::UpdateType), TEST_LOCATION);
810     DALI_TEST_EQUALS(false, gestureManager.WasCalled(TestGestureManager::RegisterType), TEST_LOCATION);
811     DALI_TEST_EQUALS(false, gestureManager.WasCalled(TestGestureManager::UnregisterType), TEST_LOCATION);
812
813     // Tap within second actor's area
814     application.ProcessEvent(GenerateTap(Gesture::Possible, 2u, 1u, Vector2(150.0f, 10.0f)));
815     application.ProcessEvent(GenerateTap(Gesture::Started, 2u, 1u, Vector2(150.0f, 10.0f)));
816     DALI_TEST_EQUALS(true, data.functorCalled, TEST_LOCATION);
817     DALI_TEST_EQUALS(true, second == data.tappedActor, TEST_LOCATION);
818
819     // Tap continues as single touch gesture - we should not receive any gesture
820     data.Reset();
821     application.ProcessEvent(GenerateTap(Gesture::Possible, 1u, 1u, Vector2(150.0f, 10.0f)));
822     application.ProcessEvent(GenerateTap(Gesture::Started, 1u, 1u, Vector2(150.0f, 10.0f)));
823     DALI_TEST_EQUALS(false, data.functorCalled, TEST_LOCATION);
824
825     // Single touch tap starts - first actor should be panned
826     data.Reset();
827     application.ProcessEvent(GenerateTap(Gesture::Possible, 1u, 1u, Vector2(50.0f, 10.0f)));
828     application.ProcessEvent(GenerateTap(Gesture::Started, 1u, 1u, Vector2(50.0f, 10.0f)));
829     DALI_TEST_EQUALS(true, data.functorCalled, TEST_LOCATION);
830     DALI_TEST_EQUALS(true, first == data.tappedActor, TEST_LOCATION);
831
832     // Pan changes to double-touch - we shouldn't receive event
833     data.Reset();
834     application.ProcessEvent(GenerateTap(Gesture::Possible, 2u, 2u, Vector2(50.0f, 10.0f)));
835     application.ProcessEvent(GenerateTap(Gesture::Started, 2u, 2u, Vector2(50.0f, 10.0f)));
836     DALI_TEST_EQUALS(false, data.functorCalled, TEST_LOCATION);
837
838     // Reset gesture manager statistics
839     gestureManager.Initialize();
840   }
841
842   // secondDetector has now been deleted.  Gesture detection should have been updated only
843   DALI_TEST_EQUALS(true, gestureManager.WasCalled(TestGestureManager::UpdateType), TEST_LOCATION);
844   DALI_TEST_EQUALS(false, gestureManager.WasCalled(TestGestureManager::RegisterType), TEST_LOCATION);
845   DALI_TEST_EQUALS(false, gestureManager.WasCalled(TestGestureManager::UnregisterType), TEST_LOCATION);
846   END_TEST;
847 }
848
849 int UtcDaliTapGestureSignalReceptionMultipleDetectorsOnActor(void)
850 {
851   TestApplication application;
852
853   Actor actor = Actor::New();
854   actor.SetSize(100.0f, 100.0f);
855   actor.SetAnchorPoint(AnchorPoint::TOP_LEFT);
856   Stage::GetCurrent().Add(actor);
857
858   // Render and notify
859   application.SendNotification();
860   application.Render();
861
862   // Attach actor to one detector
863   SignalData firstData;
864   GestureReceivedFunctor firstFunctor(firstData);
865   TapGestureDetector firstDetector = TapGestureDetector::New();
866   firstDetector.Attach(actor);
867   firstDetector.DetectedSignal().Connect(&application, firstFunctor);
868
869   // Attach actor to another detector
870   SignalData secondData;
871   GestureReceivedFunctor secondFunctor(secondData);
872   TapGestureDetector secondDetector = TapGestureDetector::New();
873   secondDetector.Attach(actor);
874   secondDetector.DetectedSignal().Connect(&application, secondFunctor);
875
876   // Tap in actor's area - both detector's functors should be called
877   application.ProcessEvent(GenerateTap(Gesture::Possible, 1u, 1u, Vector2(50.0f, 10.0f)));
878   application.ProcessEvent(GenerateTap(Gesture::Started, 1u, 1u, Vector2(50.0f, 10.0f)));
879   DALI_TEST_EQUALS(true, firstData.functorCalled, TEST_LOCATION);
880   DALI_TEST_EQUALS(true, secondData.functorCalled, TEST_LOCATION);
881   END_TEST;
882 }
883
884 int UtcDaliTapGestureSignalReceptionDifferentPossible(void)
885 {
886   TestApplication application;
887
888   Actor actor = Actor::New();
889   actor.SetSize(100.0f, 100.0f);
890   actor.SetAnchorPoint(AnchorPoint::TOP_LEFT);
891   Stage::GetCurrent().Add(actor);
892
893   // Render and notify
894   application.SendNotification();
895   application.Render();
896
897   // Attach actor to detector
898   SignalData data;
899   GestureReceivedFunctor functor( data );
900   TapGestureDetector detector = TapGestureDetector::New();
901   detector.Attach(actor);
902   detector.DetectedSignal().Connect( &application, functor );
903
904   // Gesture possible in actor's area.
905   application.ProcessEvent(GenerateTap(Gesture::Possible, 1u, 1u, Vector2(50.0f, 10.0f)));
906   DALI_TEST_EQUALS(false, data.functorCalled, TEST_LOCATION);
907
908   // Move actor somewhere else
909   actor.SetPosition( 100.0f, 100.0f );
910
911   // Render and notify
912   application.SendNotification();
913   application.Render();
914
915   // Emit Started event, we should not receive the tap.
916   application.ProcessEvent(GenerateTap(Gesture::Started, 1u, 1u, Vector2(50.0f, 10.0f)));
917   DALI_TEST_EQUALS(false, data.functorCalled, TEST_LOCATION);
918
919   // Tap possible in empty area.
920   application.ProcessEvent(GenerateTap(Gesture::Possible, 1u, 1u, Vector2(50.0f, 10.0f)));
921   DALI_TEST_EQUALS(false, data.functorCalled, TEST_LOCATION);
922
923   // Move actor in to the tap position.
924   actor.SetPosition( 0.0f, 0.0f );
925
926   // Render and notify
927   application.SendNotification();
928   application.Render();
929
930   // Emit Started event, we should not receive the tap.
931   application.ProcessEvent(GenerateTap(Gesture::Started, 1u, 1u, Vector2(50.0f, 10.0f)));
932   DALI_TEST_EQUALS(false, data.functorCalled, TEST_LOCATION);
933
934   // Normal tap in actor's area for completeness.
935   application.ProcessEvent(GenerateTap(Gesture::Possible, 1u, 1u, Vector2(50.0f, 10.0f)));
936   application.ProcessEvent(GenerateTap(Gesture::Started, 1u, 1u, Vector2(50.0f, 10.0f)));
937   DALI_TEST_EQUALS(true, data.functorCalled, TEST_LOCATION);
938   END_TEST;
939 }
940
941 int UtcDaliTapGestureEmitIncorrectStateClear(void)
942 {
943   TestApplication application;
944
945   Actor actor = Actor::New();
946   actor.SetSize(100.0f, 100.0f);
947   actor.SetAnchorPoint(AnchorPoint::TOP_LEFT);
948   Stage::GetCurrent().Add(actor);
949
950   // Render and notify
951   application.SendNotification();
952   application.Render();
953
954   // Attach actor to detector
955   SignalData data;
956   GestureReceivedFunctor functor( data );
957   TapGestureDetector detector = TapGestureDetector::New();
958   detector.Attach(actor);
959   detector.DetectedSignal().Connect( &application, functor );
960
961   // Try a Clear state
962   try
963   {
964     application.ProcessEvent(GenerateTap(Gesture::Clear, 1u, 1u, Vector2(50.0f, 10.0f)));
965     tet_result(TET_FAIL);
966   }
967   catch ( Dali::DaliException& e )
968   {
969     DALI_TEST_ASSERT( e, "Incorrect state", TEST_LOCATION );
970   }
971   END_TEST;
972 }
973
974 int UtcDaliTapGestureEmitIncorrectStateContinuing(void)
975 {
976   TestApplication application;
977
978   Actor actor = Actor::New();
979   actor.SetSize(100.0f, 100.0f);
980   actor.SetAnchorPoint(AnchorPoint::TOP_LEFT);
981   Stage::GetCurrent().Add(actor);
982
983   // Render and notify
984   application.SendNotification();
985   application.Render();
986
987   // Attach actor to detector
988   SignalData data;
989   GestureReceivedFunctor functor( data );
990   TapGestureDetector detector = TapGestureDetector::New();
991   detector.Attach(actor);
992   detector.DetectedSignal().Connect( &application, functor );
993
994   // Try a Continuing state
995   try
996   {
997     application.ProcessEvent(GenerateTap(Gesture::Continuing, 1u, 1u, Vector2(50.0f, 10.0f)));
998     tet_result(TET_FAIL);
999   }
1000   catch ( Dali::DaliException& e )
1001   {
1002     DALI_TEST_ASSERT( e, "Incorrect state", TEST_LOCATION );
1003   }
1004   END_TEST;
1005 }
1006
1007 int UtcDaliTapGestureEmitIncorrectStateFinished(void)
1008 {
1009   TestApplication application;
1010
1011   Actor actor = Actor::New();
1012   actor.SetSize(100.0f, 100.0f);
1013   actor.SetAnchorPoint(AnchorPoint::TOP_LEFT);
1014   Stage::GetCurrent().Add(actor);
1015
1016   // Render and notify
1017   application.SendNotification();
1018   application.Render();
1019
1020   // Attach actor to detector
1021   SignalData data;
1022   GestureReceivedFunctor functor( data );
1023   TapGestureDetector detector = TapGestureDetector::New();
1024   detector.Attach(actor);
1025   detector.DetectedSignal().Connect( &application, functor );
1026
1027   // Try a Finished state
1028   try
1029   {
1030     application.ProcessEvent(GenerateTap(Gesture::Finished, 1u, 1u, Vector2(50.0f, 10.0f)));
1031     tet_result(TET_FAIL);
1032   }
1033   catch ( Dali::DaliException& e )
1034   {
1035     DALI_TEST_ASSERT( e, "Incorrect state", TEST_LOCATION );
1036   }
1037   END_TEST;
1038 }
1039
1040 int UtcDaliTapGestureActorUnstaged(void)
1041 {
1042   TestApplication application;
1043
1044   Actor actor = Actor::New();
1045   actor.SetSize(100.0f, 100.0f);
1046   actor.SetAnchorPoint(AnchorPoint::TOP_LEFT);
1047   Stage::GetCurrent().Add(actor);
1048
1049   // Render and notify
1050   application.SendNotification();
1051   application.Render();
1052
1053   // Attach actor to detector
1054   SignalData data;
1055   UnstageActorFunctor functor( data );
1056   TapGestureDetector detector = TapGestureDetector::New();
1057   detector.Attach(actor);
1058   detector.DetectedSignal().Connect( &application, functor );
1059
1060   // Tap in Actor's area, actor removed in signal handler, should be handled gracefully.
1061   application.ProcessEvent(GenerateTap(Gesture::Possible, 1u, 1u, Vector2(50.0f, 10.0f)));
1062   application.ProcessEvent(GenerateTap(Gesture::Started, 1u, 1u, Vector2(50.0f, 10.0f)));
1063   DALI_TEST_EQUALS( true, data.functorCalled, TEST_LOCATION );
1064   tet_result( TET_PASS ); // If we get here, then the actor removal on signal handler was handled gracefully.
1065   END_TEST;
1066 }
1067
1068 int UtcDaliTapGestureRepeatedState(void)
1069 {
1070   TestApplication application;
1071
1072   Actor actor = Actor::New();
1073   actor.SetSize(100.0f, 100.0f);
1074   actor.SetAnchorPoint(AnchorPoint::TOP_LEFT);
1075   Stage::GetCurrent().Add(actor);
1076
1077   // Render and notify
1078   application.SendNotification();
1079   application.Render();
1080
1081   // Attach actor to detector
1082   SignalData data;
1083   GestureReceivedFunctor functor( data );
1084   TapGestureDetector detector = TapGestureDetector::New();
1085   detector.Attach(actor);
1086   detector.DetectedSignal().Connect( &application, functor );
1087
1088   // Emit two possibles
1089   application.ProcessEvent(GenerateTap(Gesture::Possible, 1u, 1u, Vector2(50.0f, 10.0f)));
1090   application.ProcessEvent(GenerateTap(Gesture::Possible, 1u, 1u, Vector2(50.0f, 10.0f)));
1091   DALI_TEST_EQUALS(false, data.functorCalled, TEST_LOCATION);
1092
1093   // Send a couple of Started states, only first one should be received.
1094   application.ProcessEvent(GenerateTap(Gesture::Started, 1u, 1u, Vector2(50.0f, 10.0f)));
1095   DALI_TEST_EQUALS(true, data.functorCalled, TEST_LOCATION);
1096   data.Reset();
1097   application.ProcessEvent(GenerateTap(Gesture::Started, 1u, 1u, Vector2(50.0f, 10.0f)));
1098   DALI_TEST_EQUALS(false, data.functorCalled, TEST_LOCATION);
1099
1100   // Send a couple of cancelled states, no reception
1101   application.ProcessEvent(GenerateTap(Gesture::Cancelled, 1u, 1u, Vector2(50.0f, 10.0f)));
1102   application.ProcessEvent(GenerateTap(Gesture::Cancelled, 1u, 1u, Vector2(50.0f, 10.0f)));
1103   DALI_TEST_EQUALS(false, data.functorCalled, TEST_LOCATION);
1104   END_TEST;
1105 }
1106
1107 int UtcDaliTapGesturePossibleCancelled(void)
1108 {
1109   TestApplication application;
1110
1111   Actor actor = Actor::New();
1112   actor.SetSize(100.0f, 100.0f);
1113   actor.SetAnchorPoint(AnchorPoint::TOP_LEFT);
1114   Stage::GetCurrent().Add(actor);
1115
1116   // Render and notify
1117   application.SendNotification();
1118   application.Render();
1119
1120   // Attach actor to detector
1121   SignalData data;
1122   GestureReceivedFunctor functor( data );
1123   TapGestureDetector detector = TapGestureDetector::New();
1124   detector.Attach(actor);
1125   detector.DetectedSignal().Connect( &application, functor );
1126
1127   // Emit a possible and then a cancelled, no reception
1128   application.ProcessEvent(GenerateTap(Gesture::Possible, 1u, 1u, Vector2(50.0f, 10.0f)));
1129   application.ProcessEvent(GenerateTap(Gesture::Cancelled, 1u, 1u, Vector2(50.0f, 10.0f)));
1130   DALI_TEST_EQUALS(false, data.functorCalled, TEST_LOCATION);
1131   END_TEST;
1132 }
1133
1134 int UtcDaliTapGestureDetectorRemovedWhilePossible(void)
1135 {
1136   TestApplication application;
1137
1138   Actor actor = Actor::New();
1139   actor.SetSize(100.0f, 100.0f);
1140   actor.SetAnchorPoint(AnchorPoint::TOP_LEFT);
1141   Stage::GetCurrent().Add(actor);
1142
1143   // Render and notify
1144   application.SendNotification();
1145   application.Render();
1146
1147   // Attach actor to detector
1148   SignalData data;
1149   GestureReceivedFunctor functor( data );
1150   TapGestureDetector detector = TapGestureDetector::New();
1151   detector.Attach(actor);
1152   detector.DetectedSignal().Connect( &application, functor );
1153
1154   // Emit a possible
1155   application.ProcessEvent(GenerateTap(Gesture::Possible, 1u, 1u, Vector2(50.0f, 10.0f)));
1156
1157   // Detach actor and send a Started state, no signal.
1158   detector.DetachAll();
1159   application.ProcessEvent(GenerateTap(Gesture::Started, 1u, 1u, Vector2(50.0f, 10.0f)));
1160   DALI_TEST_EQUALS(false, data.functorCalled, TEST_LOCATION);
1161   END_TEST;
1162 }
1163
1164 int UtcDaliTapGestureActorRemovedWhilePossible(void)
1165 {
1166   TestApplication application;
1167
1168   Actor actor = Actor::New();
1169   actor.SetSize(100.0f, 100.0f);
1170   actor.SetAnchorPoint(AnchorPoint::TOP_LEFT);
1171   Stage::GetCurrent().Add(actor);
1172
1173   // Render and notify
1174   application.SendNotification();
1175   application.Render();
1176
1177   // Attach actor to detector
1178   SignalData data;
1179   GestureReceivedFunctor functor( data );
1180   TapGestureDetector detector = TapGestureDetector::New();
1181   detector.Attach(actor);
1182   detector.DetectedSignal().Connect( &application, functor );
1183
1184   // Emit a possible
1185   application.ProcessEvent(GenerateTap(Gesture::Possible, 1u, 1u, Vector2(50.0f, 10.0f)));
1186
1187   // Remove, render and delete actor
1188   Stage::GetCurrent().Remove(actor);
1189   application.SendNotification();
1190   application.Render();
1191   actor.Reset();
1192
1193   // Send a Started state, no signal.
1194   application.ProcessEvent(GenerateTap(Gesture::Started, 1u, 1u, Vector2(50.0f, 10.0f)));
1195   DALI_TEST_EQUALS(false, data.functorCalled, TEST_LOCATION);
1196   END_TEST;
1197 }
1198
1199 int UtcDaliTapGestureLayerConsumesTouch(void)
1200 {
1201   TestApplication application;
1202
1203   Actor actor = Actor::New();
1204   actor.SetSize(100.0f, 100.0f);
1205   actor.SetAnchorPoint(AnchorPoint::TOP_LEFT);
1206   Stage::GetCurrent().Add(actor);
1207
1208   // Add a detector
1209   SignalData data;
1210   GestureReceivedFunctor functor(data);
1211   TapGestureDetector detector = TapGestureDetector::New();
1212   detector.Attach(actor);
1213   detector.DetectedSignal().Connect( &application, functor );
1214
1215   // Add a layer to overlap the actor
1216   Layer layer = Layer::New();
1217   layer.SetSize(100.0f, 100.0f);
1218   layer.SetAnchorPoint(AnchorPoint::TOP_LEFT);
1219   Stage::GetCurrent().Add( layer );
1220   layer.RaiseToTop();
1221
1222   // Render and notify
1223   application.SendNotification();
1224   application.Render();
1225
1226   Vector2 screenCoords( 50.0f, 50.0f );
1227
1228   // Emit signals, should receive
1229   application.ProcessEvent( GenerateTap( Gesture::Possible, 1u, 1u, screenCoords ) );
1230   application.ProcessEvent( GenerateTap( Gesture::Started, 1u, 1u, screenCoords ) );
1231   DALI_TEST_EQUALS(true, data.functorCalled, TEST_LOCATION);
1232   data.Reset();
1233
1234   // Set layer to consume all touch
1235   layer.SetTouchConsumed( true );
1236
1237   // Render and notify
1238   application.SendNotification();
1239   application.Render();
1240
1241   // Emit the same signals again, should not receive
1242   application.ProcessEvent( GenerateTap( Gesture::Possible, 1u, 1u, screenCoords ) );
1243   application.ProcessEvent( GenerateTap( Gesture::Started, 1u, 1u, screenCoords ) );
1244   DALI_TEST_EQUALS(false, data.functorCalled, TEST_LOCATION);
1245   data.Reset();
1246
1247   END_TEST;
1248 }