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