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