Merge "Klockwork: remove unreachable code, check iterators" into tizen
[platform/core/uifw/dali-core.git] / automated-tests / src / dali / utc-Dali-TapGestureDetector.cpp
1 /*
2  * Copyright (c) 2014 Samsung Electronics Co., Ltd.
3  *
4  * Licensed under the Apache License, Version 2.0 (the "License");
5  * you may not use this file except in compliance with the License.
6  * You may obtain a copy of the License at
7  *
8  * http://www.apache.org/licenses/LICENSE-2.0
9  *
10  * Unless required by applicable law or agreed to in writing, software
11  * distributed under the License is distributed on an "AS IS" BASIS,
12  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13  * See the License for the specific language governing permissions and
14  * limitations under the License.
15  *
16  */
17
18 #include <iostream>
19
20 #include <stdlib.h>
21 #include <dali/public-api/dali-core.h>
22 #include <dali/integration-api/events/touch-event-integ.h>
23 #include <dali/integration-api/events/tap-gesture-event.h>
24 #include <dali/integration-api/system-overlay.h>
25 #include <dali-test-suite-utils.h>
26 #include <test-touch-utils.h>
27
28 using namespace Dali;
29
30 void utc_dali_tap_gesture_detector_startup(void)
31 {
32   test_return_value = TET_UNDEF;
33 }
34
35 void utc_dali_tap_gesture_detector_cleanup(void)
36 {
37   test_return_value = TET_PASS;
38 }
39
40 ///////////////////////////////////////////////////////////////////////////////
41 namespace
42 {
43
44 // Stores data that is populated in the callback and will be read by the TET cases
45 struct SignalData
46 {
47   SignalData()
48   : functorCalled(false),
49     voidFunctorCalled(false)
50   {}
51
52   void Reset()
53   {
54     functorCalled = false;
55     voidFunctorCalled = false;
56
57     receivedGesture.numberOfTaps = 0u;
58     receivedGesture.numberOfTouches = 0u;
59     receivedGesture.screenPoint = Vector2(0.0f, 0.0f);
60     receivedGesture.localPoint = Vector2(0.0f, 0.0f);
61
62     tappedActor.Reset();
63   }
64
65   bool functorCalled;
66   bool voidFunctorCalled;
67   TapGesture receivedGesture;
68   Actor tappedActor;
69 };
70
71 // Functor that sets the data when called
72 struct GestureReceivedFunctor
73 {
74   GestureReceivedFunctor(SignalData& data) : signalData(data) { }
75
76   void operator()(Actor actor, 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, 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.GetTapsRequired(), TEST_LOCATION);
158   DALI_TEST_EQUALS(1u, detector.GetTouchesRequired(), TEST_LOCATION);
159
160   TapGestureDetector detector2 = TapGestureDetector::New(5u, 5u);
161   DALI_TEST_CHECK(detector2);
162   DALI_TEST_EQUALS(5u, detector2.GetTapsRequired(), TEST_LOCATION);
163   DALI_TEST_EQUALS(5u, detector2.GetTouchesRequired(), 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   unsigned int taps = 3;
235
236   DALI_TEST_CHECK(taps != detector.GetTapsRequired());
237
238   detector.SetTapsRequired(taps);
239
240   DALI_TEST_EQUALS(taps, detector.GetTapsRequired(), TEST_LOCATION);
241
242   // Attach an actor and change the required touches
243
244   Actor actor = Actor::New();
245   actor.SetSize(100.0f, 100.0f);
246   actor.SetAnchorPoint(AnchorPoint::TOP_LEFT);
247   Stage::GetCurrent().Add(actor);
248
249   // Render and notify
250   application.SendNotification();
251   application.Render();
252
253   SignalData data;
254   GestureReceivedFunctor functor(data);
255
256   detector.Attach(actor);
257   detector.DetectedSignal().Connect( &application, functor );
258
259   TestGestureManager& gestureManager = application.GetGestureManager();
260   gestureManager.Initialize();
261
262   detector.SetTapsRequired(4);
263
264   // Gesture detection should have been updated only
265   DALI_TEST_EQUALS(true, gestureManager.WasCalled(TestGestureManager::UpdateType), TEST_LOCATION);
266   DALI_TEST_EQUALS(false, gestureManager.WasCalled(TestGestureManager::RegisterType), TEST_LOCATION);
267   DALI_TEST_EQUALS(false, gestureManager.WasCalled(TestGestureManager::UnregisterType), TEST_LOCATION);
268
269   // Reset values
270   gestureManager.Initialize();
271
272   // Create a second gesture detector that requires even less maximum touches
273   TapGestureDetector secondDetector = TapGestureDetector::New();
274   secondDetector.Attach(actor);
275
276   // Gesture detection should have been updated
277   DALI_TEST_EQUALS(true, gestureManager.WasCalled(TestGestureManager::UpdateType), TEST_LOCATION);
278   DALI_TEST_EQUALS(false, gestureManager.WasCalled(TestGestureManager::RegisterType), TEST_LOCATION);
279   DALI_TEST_EQUALS(false, gestureManager.WasCalled(TestGestureManager::UnregisterType), TEST_LOCATION);
280   END_TEST;
281 }
282
283 int UtcDaliTapGestureGetTapsRequired(void)
284 {
285   TestApplication application;
286
287   TapGestureDetector detector = TapGestureDetector::New();
288   DALI_TEST_EQUALS(1u, detector.GetTapsRequired(), TEST_LOCATION);
289   END_TEST;
290 }
291
292 int UtcDaliTapGestureSetTouchesRequired(void)
293 {
294   TestApplication application;
295
296   TapGestureDetector detector = TapGestureDetector::New();
297
298   unsigned int max = 3;
299
300   DALI_TEST_CHECK(max != detector.GetTouchesRequired());
301
302   detector.SetTouchesRequired(max);
303
304   DALI_TEST_EQUALS(max, detector.GetTouchesRequired(), TEST_LOCATION);
305
306   // Attach an actor and change the maximum touches
307
308   Actor actor = Actor::New();
309   actor.SetSize(100.0f, 100.0f);
310   actor.SetAnchorPoint(AnchorPoint::TOP_LEFT);
311   Stage::GetCurrent().Add(actor);
312
313   // Render and notify
314   application.SendNotification();
315   application.Render();
316
317   SignalData data;
318   GestureReceivedFunctor functor(data);
319
320   detector.Attach(actor);
321   detector.DetectedSignal().Connect( &application, functor );
322
323   TestGestureManager& gestureManager = application.GetGestureManager();
324   gestureManager.Initialize();
325
326   detector.SetTouchesRequired(4);
327
328   // Gesture detection should have been updated only
329   DALI_TEST_EQUALS(true, gestureManager.WasCalled(TestGestureManager::UpdateType), TEST_LOCATION);
330   DALI_TEST_EQUALS(false, gestureManager.WasCalled(TestGestureManager::RegisterType), TEST_LOCATION);
331   DALI_TEST_EQUALS(false, gestureManager.WasCalled(TestGestureManager::UnregisterType), TEST_LOCATION);
332
333   // Reset values
334   gestureManager.Initialize();
335
336   // Create a second gesture detector that requires even less maximum touches
337   TapGestureDetector secondDetector = TapGestureDetector::New();
338   secondDetector.Attach(actor);
339
340   // Gesture detection should have been updated
341   DALI_TEST_EQUALS(true, gestureManager.WasCalled(TestGestureManager::UpdateType), TEST_LOCATION);
342   DALI_TEST_EQUALS(false, gestureManager.WasCalled(TestGestureManager::RegisterType), TEST_LOCATION);
343   DALI_TEST_EQUALS(false, gestureManager.WasCalled(TestGestureManager::UnregisterType), TEST_LOCATION);
344   END_TEST;
345 }
346
347 int UtcDaliTapGestureGetTouchesRequired(void)
348 {
349   TestApplication application;
350
351   TapGestureDetector detector = TapGestureDetector::New();
352   DALI_TEST_EQUALS(1u, detector.GetTouchesRequired(), TEST_LOCATION);
353   END_TEST;
354 }
355
356 int UtcDaliTapGestureSignalReceptionNegative(void)
357 {
358   TestApplication application;
359
360   Actor actor = Actor::New();
361   actor.SetSize(100.0f, 100.0f);
362   actor.SetAnchorPoint(AnchorPoint::TOP_LEFT);
363   Stage::GetCurrent().Add(actor);
364
365   // Render and notify
366   application.SendNotification();
367   application.Render();
368
369   SignalData data;
370   GestureReceivedFunctor functor(data);
371
372   TapGestureDetector detector = TapGestureDetector::New();
373   detector.Attach(actor);
374   detector.DetectedSignal().Connect( &application, functor );
375
376   // Do a tap outside actor's area
377   application.ProcessEvent(GenerateTap(Gesture::Possible, 1u, 1u, Vector2(112.0f, 112.0f)));
378   application.ProcessEvent(GenerateTap(Gesture::Started, 1u, 1u, Vector2(112.0f, 112.0f)));
379   DALI_TEST_EQUALS(false, data.functorCalled, TEST_LOCATION);
380   END_TEST;
381 }
382
383 int UtcDaliTapGestureSignalReceptionPositive(void)
384 {
385   TestApplication application;
386
387   Actor actor = Actor::New();
388   actor.SetSize(100.0f, 100.0f);
389   actor.SetAnchorPoint(AnchorPoint::TOP_LEFT);
390   Stage::GetCurrent().Add(actor);
391
392   // Render and notify
393   application.SendNotification();
394   application.Render();
395
396   SignalData data;
397   GestureReceivedFunctor functor(data);
398
399   TapGestureDetector detector = TapGestureDetector::New();
400   detector.Attach(actor);
401   detector.DetectedSignal().Connect( &application, functor );
402
403   // Do a tap inside actor's area
404   application.ProcessEvent(GenerateTap(Gesture::Possible, 1u, 1u, Vector2(50.0f, 50.0f)));
405   application.ProcessEvent(GenerateTap(Gesture::Started, 1u, 1u, Vector2(50.0f, 50.0f)));
406   DALI_TEST_EQUALS(true, data.functorCalled, TEST_LOCATION);
407   DALI_TEST_EQUALS(1u, data.receivedGesture.numberOfTaps, TEST_LOCATION);
408   DALI_TEST_EQUALS(1u, data.receivedGesture.numberOfTouches, TEST_LOCATION);
409   DALI_TEST_EQUALS( Vector2(50.0f, 50.0f), data.receivedGesture.localPoint, 0.1, TEST_LOCATION);
410   END_TEST;
411 }
412
413 int UtcDaliTapGestureSignalReceptionDetach(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   // Start tap within the actor's area
434   application.ProcessEvent(GenerateTap(Gesture::Possible, 1u, 1u, Vector2(20.0f, 20.0f)));
435   application.ProcessEvent(GenerateTap(Gesture::Started, 1u, 1u, Vector2(20.0f, 20.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(20.0f, 20.0f), data.receivedGesture.localPoint, 0.1, TEST_LOCATION);
440
441   // repeat the tap within the actor's area - we should still receive the signal
442   data.Reset();
443   application.ProcessEvent(GenerateTap(Gesture::Possible, 1u, 1u, Vector2(50.0f, 50.0f)));
444   application.ProcessEvent(GenerateTap(Gesture::Started, 1u, 1u, Vector2(50.0f, 50.0f)));
445   DALI_TEST_EQUALS(true, data.functorCalled, TEST_LOCATION);
446   DALI_TEST_EQUALS(1u, data.receivedGesture.numberOfTaps, TEST_LOCATION);
447   DALI_TEST_EQUALS(1u, data.receivedGesture.numberOfTouches, TEST_LOCATION);
448   DALI_TEST_EQUALS( Vector2(50.0f, 50.0f), data.receivedGesture.localPoint, 0.1, TEST_LOCATION);
449
450   // Detach actor
451   detector.DetachAll();
452
453   // Ensure we are no longer signalled
454   data.Reset();
455   application.ProcessEvent(GenerateTap(Gesture::Possible, 1u, 1u, Vector2(20.0f, 20.0f)));
456   application.ProcessEvent(GenerateTap(Gesture::Started, 1u, 1u, Vector2(20.0f, 20.0f)));
457   DALI_TEST_EQUALS(false, data.functorCalled, TEST_LOCATION);
458   application.ProcessEvent(GenerateTap(Gesture::Possible, 1u, 1u, Vector2(50.0f, 50.0f)));
459   application.ProcessEvent(GenerateTap(Gesture::Started, 1u, 1u, Vector2(50.0f, 50.0f)));
460   DALI_TEST_EQUALS(false, data.functorCalled, TEST_LOCATION);
461   END_TEST;
462 }
463
464 int UtcDaliTapGestureSignalReceptionActorDestroyedWhileTapping(void)
465 {
466   TestApplication application;
467
468   SignalData data;
469   GestureReceivedFunctor functor(data);
470
471   TapGestureDetector detector = TapGestureDetector::New();
472   detector.DetectedSignal().Connect(&application, functor);
473
474   // Actor lifetime is scoped
475   {
476     Actor actor = Actor::New();
477     actor.SetSize(100.0f, 100.0f);
478     actor.SetAnchorPoint(AnchorPoint::TOP_LEFT);
479     Stage::GetCurrent().Add(actor);
480
481     // Render and notify
482     application.SendNotification();
483     application.Render();
484
485     detector.Attach(actor);
486
487     // Start tap within the actor's area
488     application.ProcessEvent(GenerateTap(Gesture::Possible, 1u, 1u, Vector2(20.0f, 20.0f)));
489     application.ProcessEvent(GenerateTap(Gesture::Started, 1u, 1u, Vector2(20.0f, 20.0f)));
490     DALI_TEST_EQUALS(true, data.functorCalled, TEST_LOCATION);
491
492     // Remove the actor from stage and reset the data
493     Stage::GetCurrent().Remove(actor);
494
495     // Render and notify
496     application.SendNotification();
497     application.Render();
498   }
499
500   // Actor should now have been destroyed
501
502   data.Reset();
503   application.ProcessEvent(GenerateTap(Gesture::Possible, 1u, 1u, Vector2(20.0f, 20.0f)));
504   application.ProcessEvent(GenerateTap(Gesture::Started, 1u, 1u, Vector2(20.0f, 20.0f)));
505   DALI_TEST_EQUALS(false, data.functorCalled, TEST_LOCATION);
506   END_TEST;
507 }
508
509 int UtcDaliTapGestureSignalReceptionRotatedActor(void)
510 {
511   TestApplication application;
512
513   Actor actor = Actor::New();
514   actor.SetSize(100.0f, 100.0f);
515   actor.SetRotation(Dali::Degree(90.0f), Vector3::ZAXIS);
516   Stage::GetCurrent().Add(actor);
517
518   // Render and notify
519   application.SendNotification();
520   application.Render();
521
522   SignalData data;
523   GestureReceivedFunctor functor(data);
524
525   TapGestureDetector detector = TapGestureDetector::New();
526   detector.Attach(actor);
527   detector.DetectedSignal().Connect(&application, functor);
528
529   // Do tap, only check finished value
530   application.ProcessEvent(GenerateTap(Gesture::Possible, 1u, 1u, Vector2(5.0f, 5.0f)));
531   application.ProcessEvent(GenerateTap(Gesture::Started, 1u, 1u, Vector2(5.0f, 5.0f)));
532   DALI_TEST_EQUALS(true, data.functorCalled, TEST_LOCATION);
533   DALI_TEST_EQUALS(1u, data.receivedGesture.numberOfTaps, TEST_LOCATION);
534   DALI_TEST_EQUALS(1u, data.receivedGesture.numberOfTouches, TEST_LOCATION);
535   DALI_TEST_EQUALS( Vector2(5.0f, 5.0f), data.receivedGesture.screenPoint, 0.1, TEST_LOCATION);
536
537   // Rotate actor again and render
538   actor.SetRotation(Dali::Degree(180.0f), Vector3::ZAXIS);
539   application.SendNotification();
540   application.Render();
541
542   // Do tap, should still receive event
543   data.Reset();
544   application.ProcessEvent(GenerateTap(Gesture::Possible, 1u, 1u, Vector2(5.0f, 5.0f)));
545   application.ProcessEvent(GenerateTap(Gesture::Started, 1u, 1u, Vector2(5.0f, 5.0f)));
546   DALI_TEST_EQUALS(true, data.functorCalled, TEST_LOCATION);
547   DALI_TEST_EQUALS(1u, data.receivedGesture.numberOfTaps, TEST_LOCATION);
548   DALI_TEST_EQUALS(1u, data.receivedGesture.numberOfTouches, TEST_LOCATION);
549   DALI_TEST_EQUALS( Vector2(5.0f, 5.0f), data.receivedGesture.screenPoint, 0.1, TEST_LOCATION);
550
551   // Rotate actor again and render
552   actor.SetRotation(Dali::Degree(90.0f), Vector3::YAXIS);
553   application.SendNotification();
554   application.Render();
555
556   // Do tap, inside the actor's area (area if it is not rotated), Should not receive the event
557   data.Reset();
558   application.ProcessEvent(GenerateTap(Gesture::Possible, 1u, 1u, Vector2(70.0f, 70.0f)));
559   application.ProcessEvent(GenerateTap(Gesture::Started, 1u, 1u, Vector2(70.0f, 70.0f)));
560   DALI_TEST_EQUALS(false, data.functorCalled, TEST_LOCATION);
561   END_TEST;
562 }
563
564 int UtcDaliTapGestureSignalReceptionChildHit(void)
565 {
566   TestApplication application;
567
568   Actor parent = Actor::New();
569   parent.SetSize(100.0f, 100.0f);
570   parent.SetAnchorPoint(AnchorPoint::TOP_LEFT);
571   Stage::GetCurrent().Add(parent);
572
573   // Set child to completely cover parent.
574   // Change rotation of child to be different from parent so that we can check if our local coordinate
575   // conversion of the parent actor is correct.
576   Actor child = Actor::New();
577   child.SetSize(100.0f, 100.0f);
578   child.SetAnchorPoint(AnchorPoint::CENTER);
579   child.SetParentOrigin(ParentOrigin::CENTER);
580   child.SetRotation(Dali::Degree(90.0f), Vector3::ZAXIS);
581   parent.Add(child);
582
583   TouchEventFunctor touchFunctor;
584   child.TouchedSignal().Connect(&application, touchFunctor);
585
586   // Render and notify
587   application.SendNotification();
588   application.Render();
589
590   SignalData data;
591   GestureReceivedFunctor functor(data);
592
593   TapGestureDetector detector = TapGestureDetector::New();
594   detector.Attach(parent);
595   detector.DetectedSignal().Connect(&application, functor);
596
597   // Do tap - hits child area but parent should still receive it
598   application.ProcessEvent(GenerateTap(Gesture::Possible, 1u, 1u, Vector2(50.0f, 50.0f)));
599   application.ProcessEvent(GenerateTap(Gesture::Started, 1u, 1u, Vector2(50.0f, 50.0f)));
600   DALI_TEST_EQUALS(true, data.functorCalled, TEST_LOCATION);
601   DALI_TEST_EQUALS(true, parent == data.tappedActor, TEST_LOCATION);
602   DALI_TEST_EQUALS(Vector2(50.0f, 50.0f), data.receivedGesture.screenPoint, 0.01f, TEST_LOCATION);
603
604   // Attach child and generate same touch points
605   // (Also proves that you can detach and then re-attach another actor)
606   detector.Attach(child);
607   detector.Detach(parent);
608
609   // Do an entire tap, only check finished value
610   data.Reset();
611   application.ProcessEvent(GenerateTap(Gesture::Possible, 1u, 1u, Vector2(51.0f, 51.0f)));
612   application.ProcessEvent(GenerateTap(Gesture::Started, 1u, 1u, Vector2(51.0f, 51.0f)));
613   DALI_TEST_EQUALS(true, data.functorCalled, TEST_LOCATION);
614   DALI_TEST_EQUALS(true, child == data.tappedActor, TEST_LOCATION);
615   DALI_TEST_EQUALS(Vector2(51.0f, 51.0f), data.receivedGesture.screenPoint, 0.01f, TEST_LOCATION);
616   END_TEST;
617 }
618
619 int UtcDaliTapGestureSignalReceptionAttachDetachMany(void)
620 {
621   TestApplication application;
622
623   Actor first = Actor::New();
624   first.SetSize(100.0f, 100.0f);
625   first.SetAnchorPoint(AnchorPoint::TOP_LEFT);
626   Stage::GetCurrent().Add(first);
627
628   Actor second = Actor::New();
629   second.SetSize(100.0f, 100.0f);
630   second.SetX(100.0f);
631   second.SetAnchorPoint(AnchorPoint::TOP_LEFT);
632   Stage::GetCurrent().Add(second);
633
634   // Render and notify
635   application.SendNotification();
636   application.Render();
637
638   SignalData data;
639   GestureReceivedFunctor functor(data);
640
641   TapGestureDetector detector = TapGestureDetector::New();
642   detector.Attach(first);
643   detector.Attach(second);
644   detector.DetectedSignal().Connect(&application, functor);
645
646   // Tap within second actor's area
647   application.ProcessEvent(GenerateTap(Gesture::Possible, 1u, 1u, Vector2(120.0f, 10.0f)));
648   application.ProcessEvent(GenerateTap(Gesture::Started, 1u, 1u, Vector2(120.0f, 10.0f)));
649   DALI_TEST_EQUALS(true, data.functorCalled, TEST_LOCATION);
650   DALI_TEST_EQUALS(true, second == data.tappedActor, TEST_LOCATION);
651
652   // Tap within first actor's area
653   data.Reset();
654   application.ProcessEvent(GenerateTap(Gesture::Possible, 1u, 1u, Vector2(20.0f, 10.0f)));
655   application.ProcessEvent(GenerateTap(Gesture::Started, 1u, 1u, Vector2(20.0f, 10.0f)));
656   DALI_TEST_EQUALS(true, data.functorCalled, TEST_LOCATION);
657   DALI_TEST_EQUALS(true, first == data.tappedActor, TEST_LOCATION);
658
659   // Detach the second actor
660   detector.Detach(second);
661
662   // second actor shouldn't receive event
663   data.Reset();
664   application.ProcessEvent(GenerateTap(Gesture::Possible, 1u, 1u, Vector2(120.0f, 10.0f)));
665   application.ProcessEvent(GenerateTap(Gesture::Started, 1u, 1u, Vector2(120.0f, 10.0f)));
666   DALI_TEST_EQUALS(false, data.functorCalled, TEST_LOCATION);
667
668   // first actor should continue receiving event
669   data.Reset();
670   application.ProcessEvent(GenerateTap(Gesture::Possible, 1u, 1u, Vector2(20.0f, 10.0f)));
671   application.ProcessEvent(GenerateTap(Gesture::Started, 1u, 1u, Vector2(20.0f, 10.0f)));
672   DALI_TEST_EQUALS(true, data.functorCalled, TEST_LOCATION);
673   END_TEST;
674 }
675
676 int UtcDaliTapGestureSignalReceptionActorBecomesUntouchable(void)
677 {
678   TestApplication application;
679
680   Actor actor = Actor::New();
681   actor.SetSize(100.0f, 100.0f);
682   actor.SetAnchorPoint(AnchorPoint::TOP_LEFT);
683   Stage::GetCurrent().Add(actor);
684
685   // Render and notify
686   application.SendNotification();
687   application.Render();
688
689   SignalData data;
690   GestureReceivedFunctor functor(data);
691
692   TapGestureDetector detector = TapGestureDetector::New();
693   detector.Attach(actor);
694   detector.DetectedSignal().Connect(&application, functor);
695
696   // Tap in actor's area
697   application.ProcessEvent(GenerateTap(Gesture::Possible, 1u, 1u, Vector2(50.0f, 10.0f)));
698   application.ProcessEvent(GenerateTap(Gesture::Started, 1u, 1u, Vector2(50.0f, 10.0f)));
699   DALI_TEST_EQUALS(true, data.functorCalled, TEST_LOCATION);
700
701   // Actor become invisible - actor should not receive the next pan
702   actor.SetVisible(false);
703
704   // Render and notify
705   application.SendNotification();
706   application.Render();
707
708   // Tap in the same area, shouldn't receive event
709   data.Reset();
710   application.ProcessEvent(GenerateTap(Gesture::Possible, 1u, 1u, Vector2(50.0f, 10.0f)));
711   application.ProcessEvent(GenerateTap(Gesture::Started, 1u, 1u, Vector2(50.0f, 10.0f)));
712   DALI_TEST_EQUALS(false, data.functorCalled, TEST_LOCATION);
713   END_TEST;
714 }
715
716 int UtcDaliTapGestureSignalReceptionMultipleGestureDetectors(void)
717 {
718   TestApplication application;
719   Dali::TestGestureManager& gestureManager = application.GetGestureManager();
720
721   Actor first = Actor::New();
722   first.SetSize(100.0f, 100.0f);
723   first.SetAnchorPoint(AnchorPoint::TOP_LEFT);
724   Stage::GetCurrent().Add(first);
725
726   Actor second = Actor::New();
727   second.SetSize(100.0f, 100.0f);
728   second.SetAnchorPoint(AnchorPoint::TOP_LEFT);
729   second.SetX(100.0f);
730   first.Add(second);
731
732   // Render and notify
733   application.SendNotification();
734   application.Render();
735
736   SignalData data;
737   GestureReceivedFunctor functor(data);
738
739   TapGestureDetector firstDetector = TapGestureDetector::New();
740   firstDetector.Attach(first);
741   firstDetector.DetectedSignal().Connect(&application, functor);
742
743   // secondDetector is scoped
744   {
745     // Reset gestureManager statistics
746     gestureManager.Initialize();
747
748     TapGestureDetector secondDetector = TapGestureDetector::New();
749     secondDetector.SetTapsRequired(2);
750     secondDetector.SetTouchesRequired(2);
751     secondDetector.Attach(second);
752     secondDetector.DetectedSignal().Connect(&application, functor);
753
754     DALI_TEST_EQUALS(true, gestureManager.WasCalled(TestGestureManager::UpdateType), TEST_LOCATION);
755     DALI_TEST_EQUALS(false, gestureManager.WasCalled(TestGestureManager::RegisterType), TEST_LOCATION);
756     DALI_TEST_EQUALS(false, gestureManager.WasCalled(TestGestureManager::UnregisterType), TEST_LOCATION);
757
758     // Tap within second actor's area
759     application.ProcessEvent(GenerateTap(Gesture::Possible, 2u, 2u, Vector2(150.0f, 10.0f)));
760     application.ProcessEvent(GenerateTap(Gesture::Started, 2u, 2u, Vector2(150.0f, 10.0f)));
761     DALI_TEST_EQUALS(true, data.functorCalled, TEST_LOCATION);
762     DALI_TEST_EQUALS(true, second == data.tappedActor, TEST_LOCATION);
763
764     // Tap continues as single touch gesture - we should not receive any gesture
765     data.Reset();
766     application.ProcessEvent(GenerateTap(Gesture::Possible, 1u, 1u, Vector2(150.0f, 10.0f)));
767     application.ProcessEvent(GenerateTap(Gesture::Started, 1u, 1u, Vector2(150.0f, 10.0f)));
768     DALI_TEST_EQUALS(false, data.functorCalled, TEST_LOCATION);
769
770     // Single touch tap starts - first actor should be panned
771     data.Reset();
772     application.ProcessEvent(GenerateTap(Gesture::Possible, 1u, 1u, Vector2(50.0f, 10.0f)));
773     application.ProcessEvent(GenerateTap(Gesture::Started, 1u, 1u, Vector2(50.0f, 10.0f)));
774     DALI_TEST_EQUALS(true, data.functorCalled, TEST_LOCATION);
775     DALI_TEST_EQUALS(true, first == data.tappedActor, TEST_LOCATION);
776
777     // Pan changes to double-touch - we shouldn't receive event
778     data.Reset();
779     application.ProcessEvent(GenerateTap(Gesture::Possible, 2u, 2u, Vector2(50.0f, 10.0f)));
780     application.ProcessEvent(GenerateTap(Gesture::Started, 2u, 2u, Vector2(50.0f, 10.0f)));
781     DALI_TEST_EQUALS(false, data.functorCalled, TEST_LOCATION);
782
783     // Reset gesture manager statistics
784     gestureManager.Initialize();
785   }
786
787   // secondDetector has now been deleted.  Gesture detection should have been updated only
788   DALI_TEST_EQUALS(true, gestureManager.WasCalled(TestGestureManager::UpdateType), TEST_LOCATION);
789   DALI_TEST_EQUALS(false, gestureManager.WasCalled(TestGestureManager::RegisterType), TEST_LOCATION);
790   DALI_TEST_EQUALS(false, gestureManager.WasCalled(TestGestureManager::UnregisterType), TEST_LOCATION);
791   END_TEST;
792 }
793
794 int UtcDaliTapGestureSignalReceptionMultipleDetectorsOnActor(void)
795 {
796   TestApplication application;
797
798   Actor actor = Actor::New();
799   actor.SetSize(100.0f, 100.0f);
800   actor.SetAnchorPoint(AnchorPoint::TOP_LEFT);
801   Stage::GetCurrent().Add(actor);
802
803   // Render and notify
804   application.SendNotification();
805   application.Render();
806
807   // Attach actor to one detector
808   SignalData firstData;
809   GestureReceivedFunctor firstFunctor(firstData);
810   TapGestureDetector firstDetector = TapGestureDetector::New();
811   firstDetector.Attach(actor);
812   firstDetector.DetectedSignal().Connect(&application, firstFunctor);
813
814   // Attach actor to another detector
815   SignalData secondData;
816   GestureReceivedFunctor secondFunctor(secondData);
817   TapGestureDetector secondDetector = TapGestureDetector::New();
818   secondDetector.Attach(actor);
819   secondDetector.DetectedSignal().Connect(&application, secondFunctor);
820
821   // Tap in actor's area - both detector's functors should be called
822   application.ProcessEvent(GenerateTap(Gesture::Possible, 1u, 1u, Vector2(50.0f, 10.0f)));
823   application.ProcessEvent(GenerateTap(Gesture::Started, 1u, 1u, Vector2(50.0f, 10.0f)));
824   DALI_TEST_EQUALS(true, firstData.functorCalled, TEST_LOCATION);
825   DALI_TEST_EQUALS(true, secondData.functorCalled, TEST_LOCATION);
826   END_TEST;
827 }
828
829 int UtcDaliTapGestureSignalReceptionDifferentPossible(void)
830 {
831   TestApplication application;
832
833   Actor actor = Actor::New();
834   actor.SetSize(100.0f, 100.0f);
835   actor.SetAnchorPoint(AnchorPoint::TOP_LEFT);
836   Stage::GetCurrent().Add(actor);
837
838   // Render and notify
839   application.SendNotification();
840   application.Render();
841
842   // Attach actor to detector
843   SignalData data;
844   GestureReceivedFunctor functor( data );
845   TapGestureDetector detector = TapGestureDetector::New();
846   detector.Attach(actor);
847   detector.DetectedSignal().Connect( &application, functor );
848
849   // Gesture possible in actor's area.
850   application.ProcessEvent(GenerateTap(Gesture::Possible, 1u, 1u, Vector2(50.0f, 10.0f)));
851   DALI_TEST_EQUALS(false, data.functorCalled, TEST_LOCATION);
852
853   // Move actor somewhere else
854   actor.SetPosition( 100.0f, 100.0f );
855
856   // Render and notify
857   application.SendNotification();
858   application.Render();
859
860   // Emit Started event, we should not receive the long press.
861   application.ProcessEvent(GenerateTap(Gesture::Started, 1u, 1u, Vector2(50.0f, 10.0f)));
862   DALI_TEST_EQUALS(false, data.functorCalled, TEST_LOCATION);
863
864   // LongPress possible in empty area.
865   application.ProcessEvent(GenerateTap(Gesture::Possible, 1u, 1u, Vector2(50.0f, 10.0f)));
866   DALI_TEST_EQUALS(false, data.functorCalled, TEST_LOCATION);
867
868   // Move actor in to the long press position.
869   actor.SetPosition( 0.0f, 0.0f );
870
871   // Render and notify
872   application.SendNotification();
873   application.Render();
874
875   // Emit Started event, we should not receive the long press.
876   application.ProcessEvent(GenerateTap(Gesture::Started, 1u, 1u, Vector2(50.0f, 10.0f)));
877   DALI_TEST_EQUALS(false, data.functorCalled, TEST_LOCATION);
878
879   // Normal long press in actor's area for completeness.
880   application.ProcessEvent(GenerateTap(Gesture::Possible, 1u, 1u, Vector2(50.0f, 10.0f)));
881   application.ProcessEvent(GenerateTap(Gesture::Started, 1u, 1u, Vector2(50.0f, 10.0f)));
882   DALI_TEST_EQUALS(true, data.functorCalled, TEST_LOCATION);
883   END_TEST;
884 }
885
886 int UtcDaliTapGestureEmitIncorrectStateClear(void)
887 {
888   TestApplication application;
889
890   Actor actor = Actor::New();
891   actor.SetSize(100.0f, 100.0f);
892   actor.SetAnchorPoint(AnchorPoint::TOP_LEFT);
893   Stage::GetCurrent().Add(actor);
894
895   // Render and notify
896   application.SendNotification();
897   application.Render();
898
899   // Attach actor to detector
900   SignalData data;
901   GestureReceivedFunctor functor( data );
902   TapGestureDetector detector = TapGestureDetector::New();
903   detector.Attach(actor);
904   detector.DetectedSignal().Connect( &application, functor );
905
906   // Try a Clear state
907   try
908   {
909     application.ProcessEvent(GenerateTap(Gesture::Clear, 1u, 1u, Vector2(50.0f, 10.0f)));
910     tet_result(TET_FAIL);
911   }
912   catch ( Dali::DaliException& e )
913   {
914     DALI_TEST_ASSERT( e, "false", TEST_LOCATION );
915   }
916   END_TEST;
917 }
918
919 int UtcDaliTapGestureEmitIncorrectStateContinuing(void)
920 {
921   TestApplication application;
922
923   Actor actor = Actor::New();
924   actor.SetSize(100.0f, 100.0f);
925   actor.SetAnchorPoint(AnchorPoint::TOP_LEFT);
926   Stage::GetCurrent().Add(actor);
927
928   // Render and notify
929   application.SendNotification();
930   application.Render();
931
932   // Attach actor to detector
933   SignalData data;
934   GestureReceivedFunctor functor( data );
935   TapGestureDetector detector = TapGestureDetector::New();
936   detector.Attach(actor);
937   detector.DetectedSignal().Connect( &application, functor );
938
939   // Try a Continuing state
940   try
941   {
942     application.ProcessEvent(GenerateTap(Gesture::Continuing, 1u, 1u, Vector2(50.0f, 10.0f)));
943     tet_result(TET_FAIL);
944   }
945   catch ( Dali::DaliException& e )
946   {
947     DALI_TEST_ASSERT( e, "false", TEST_LOCATION );
948   }
949   END_TEST;
950 }
951
952 int UtcDaliTapGestureEmitIncorrectStateFinished(void)
953 {
954   TestApplication application;
955
956   Actor actor = Actor::New();
957   actor.SetSize(100.0f, 100.0f);
958   actor.SetAnchorPoint(AnchorPoint::TOP_LEFT);
959   Stage::GetCurrent().Add(actor);
960
961   // Render and notify
962   application.SendNotification();
963   application.Render();
964
965   // Attach actor to detector
966   SignalData data;
967   GestureReceivedFunctor functor( data );
968   TapGestureDetector detector = TapGestureDetector::New();
969   detector.Attach(actor);
970   detector.DetectedSignal().Connect( &application, functor );
971
972   // Try a Finished state
973   try
974   {
975     application.ProcessEvent(GenerateTap(Gesture::Finished, 1u, 1u, Vector2(50.0f, 10.0f)));
976     tet_result(TET_FAIL);
977   }
978   catch ( Dali::DaliException& e )
979   {
980     DALI_TEST_ASSERT( e, "false", TEST_LOCATION );
981   }
982   END_TEST;
983 }
984
985 int UtcDaliTapGestureActorUnstaged(void)
986 {
987   TestApplication application;
988
989   Actor actor = Actor::New();
990   actor.SetSize(100.0f, 100.0f);
991   actor.SetAnchorPoint(AnchorPoint::TOP_LEFT);
992   Stage::GetCurrent().Add(actor);
993
994   // Render and notify
995   application.SendNotification();
996   application.Render();
997
998   // Attach actor to detector
999   SignalData data;
1000   UnstageActorFunctor functor( data );
1001   TapGestureDetector detector = TapGestureDetector::New();
1002   detector.Attach(actor);
1003   detector.DetectedSignal().Connect( &application, functor );
1004
1005   // Tap in Actor's area, actor removed in signal handler, should be handled gracefully.
1006   application.ProcessEvent(GenerateTap(Gesture::Possible, 1u, 1u, Vector2(50.0f, 10.0f)));
1007   application.ProcessEvent(GenerateTap(Gesture::Started, 1u, 1u, Vector2(50.0f, 10.0f)));
1008   DALI_TEST_EQUALS( true, data.functorCalled, TEST_LOCATION );
1009   tet_result( TET_PASS ); // If we get here, then the actor removal on signal handler was handled gracefully.
1010   END_TEST;
1011 }
1012
1013 int UtcDaliTapGestureRepeatedState(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   GestureReceivedFunctor functor( data );
1029   TapGestureDetector detector = TapGestureDetector::New();
1030   detector.Attach(actor);
1031   detector.DetectedSignal().Connect( &application, functor );
1032
1033   // Emit two possibles
1034   application.ProcessEvent(GenerateTap(Gesture::Possible, 1u, 1u, Vector2(50.0f, 10.0f)));
1035   application.ProcessEvent(GenerateTap(Gesture::Possible, 1u, 1u, Vector2(50.0f, 10.0f)));
1036   DALI_TEST_EQUALS(false, data.functorCalled, TEST_LOCATION);
1037
1038   // Send a couple of Started states, only first one should be received.
1039   application.ProcessEvent(GenerateTap(Gesture::Started, 1u, 1u, Vector2(50.0f, 10.0f)));
1040   DALI_TEST_EQUALS(true, data.functorCalled, TEST_LOCATION);
1041   data.Reset();
1042   application.ProcessEvent(GenerateTap(Gesture::Started, 1u, 1u, Vector2(50.0f, 10.0f)));
1043   DALI_TEST_EQUALS(false, data.functorCalled, TEST_LOCATION);
1044
1045   // Send a couple of cancelled states, no reception
1046   application.ProcessEvent(GenerateTap(Gesture::Cancelled, 1u, 1u, Vector2(50.0f, 10.0f)));
1047   application.ProcessEvent(GenerateTap(Gesture::Cancelled, 1u, 1u, Vector2(50.0f, 10.0f)));
1048   DALI_TEST_EQUALS(false, data.functorCalled, TEST_LOCATION);
1049   END_TEST;
1050 }
1051
1052 int UtcDaliTapGesturePossibleCancelled(void)
1053 {
1054   TestApplication application;
1055
1056   Actor actor = Actor::New();
1057   actor.SetSize(100.0f, 100.0f);
1058   actor.SetAnchorPoint(AnchorPoint::TOP_LEFT);
1059   Stage::GetCurrent().Add(actor);
1060
1061   // Render and notify
1062   application.SendNotification();
1063   application.Render();
1064
1065   // Attach actor to detector
1066   SignalData data;
1067   GestureReceivedFunctor functor( data );
1068   TapGestureDetector detector = TapGestureDetector::New();
1069   detector.Attach(actor);
1070   detector.DetectedSignal().Connect( &application, functor );
1071
1072   // Emit a possible and then a cancelled, no reception
1073   application.ProcessEvent(GenerateTap(Gesture::Possible, 1u, 1u, Vector2(50.0f, 10.0f)));
1074   application.ProcessEvent(GenerateTap(Gesture::Cancelled, 1u, 1u, Vector2(50.0f, 10.0f)));
1075   DALI_TEST_EQUALS(false, data.functorCalled, TEST_LOCATION);
1076   END_TEST;
1077 }
1078
1079 int UtcDaliTapGestureDetectorRemovedWhilePossible(void)
1080 {
1081   TestApplication application;
1082
1083   Actor actor = Actor::New();
1084   actor.SetSize(100.0f, 100.0f);
1085   actor.SetAnchorPoint(AnchorPoint::TOP_LEFT);
1086   Stage::GetCurrent().Add(actor);
1087
1088   // Render and notify
1089   application.SendNotification();
1090   application.Render();
1091
1092   // Attach actor to detector
1093   SignalData data;
1094   GestureReceivedFunctor functor( data );
1095   TapGestureDetector detector = TapGestureDetector::New();
1096   detector.Attach(actor);
1097   detector.DetectedSignal().Connect( &application, functor );
1098
1099   // Emit a possible
1100   application.ProcessEvent(GenerateTap(Gesture::Possible, 1u, 1u, Vector2(50.0f, 10.0f)));
1101
1102   // Detach actor and send a Started state, no signal.
1103   detector.DetachAll();
1104   application.ProcessEvent(GenerateTap(Gesture::Started, 1u, 1u, Vector2(50.0f, 10.0f)));
1105   DALI_TEST_EQUALS(false, data.functorCalled, TEST_LOCATION);
1106   END_TEST;
1107 }
1108
1109 int UtcDaliTapGestureActorRemovedWhilePossible(void)
1110 {
1111   TestApplication application;
1112
1113   Actor actor = Actor::New();
1114   actor.SetSize(100.0f, 100.0f);
1115   actor.SetAnchorPoint(AnchorPoint::TOP_LEFT);
1116   Stage::GetCurrent().Add(actor);
1117
1118   // Render and notify
1119   application.SendNotification();
1120   application.Render();
1121
1122   // Attach actor to detector
1123   SignalData data;
1124   GestureReceivedFunctor functor( data );
1125   TapGestureDetector detector = TapGestureDetector::New();
1126   detector.Attach(actor);
1127   detector.DetectedSignal().Connect( &application, functor );
1128
1129   // Emit a possible
1130   application.ProcessEvent(GenerateTap(Gesture::Possible, 1u, 1u, Vector2(50.0f, 10.0f)));
1131
1132   // Remove, render and delete actor
1133   Stage::GetCurrent().Remove(actor);
1134   application.SendNotification();
1135   application.Render();
1136   actor.Reset();
1137
1138   // Send a Started state, no signal.
1139   application.ProcessEvent(GenerateTap(Gesture::Started, 1u, 1u, Vector2(50.0f, 10.0f)));
1140   DALI_TEST_EQUALS(false, data.functorCalled, TEST_LOCATION);
1141   END_TEST;
1142 }
1143
1144 int UtcDaliTapGestureSystemOverlay(void)
1145 {
1146   TestApplication application;
1147   Dali::Integration::Core& core = application.GetCore();
1148   Dali::Integration::SystemOverlay& systemOverlay( core.GetSystemOverlay() );
1149   systemOverlay.GetOverlayRenderTasks().CreateTask();
1150
1151   Actor actor = Actor::New();
1152   actor.SetSize(100.0f, 100.0f);
1153   actor.SetAnchorPoint(AnchorPoint::TOP_LEFT);
1154   systemOverlay.Add(actor);
1155
1156   // Render and notify
1157   application.SendNotification();
1158   application.Render();
1159
1160   SignalData data;
1161   GestureReceivedFunctor functor(data);
1162
1163   TapGestureDetector detector = TapGestureDetector::New();
1164   detector.Attach(actor);
1165   detector.DetectedSignal().Connect(&application, functor);
1166
1167   Vector2 screenCoords( 50.0f, 50.0f );
1168
1169   // Do a tap inside actor's area
1170   application.ProcessEvent( GenerateTap( Gesture::Possible, 1u, 1u, screenCoords ) );
1171   application.ProcessEvent( GenerateTap( Gesture::Started, 1u, 1u, screenCoords ) );
1172   DALI_TEST_EQUALS( true, data.functorCalled, TEST_LOCATION );
1173   END_TEST;
1174 }
1175
1176 int UtcDaliTapGestureBehindTouchableSystemOverlay(void)
1177 {
1178   TestApplication application;
1179   Dali::Integration::Core& core = application.GetCore();
1180   Dali::Integration::SystemOverlay& systemOverlay( core.GetSystemOverlay() );
1181   systemOverlay.GetOverlayRenderTasks().CreateTask();
1182
1183   // SystemOverlay actor
1184   Actor systemOverlayActor = Actor::New();
1185   systemOverlayActor.SetSize(100.0f, 100.0f);
1186   systemOverlayActor.SetAnchorPoint(AnchorPoint::TOP_LEFT);
1187   systemOverlay.Add(systemOverlayActor);
1188
1189   // Stage actor
1190   Actor stageActor = Actor::New();
1191   stageActor.SetSize(100.0f, 100.0f);
1192   stageActor.SetAnchorPoint(AnchorPoint::TOP_LEFT);
1193   Stage::GetCurrent().Add(stageActor);
1194
1195   // Render and notify
1196   application.SendNotification();
1197   application.Render();
1198
1199   // Set system-overlay actor to touchable
1200   TouchEventData touchData;
1201   TouchEventDataFunctor touchFunctor( touchData );
1202   systemOverlayActor.TouchedSignal().Connect(&application, touchFunctor);
1203
1204   // Set stage actor to receive the gesture
1205   SignalData data;
1206   GestureReceivedFunctor functor(data);
1207
1208   TapGestureDetector detector = TapGestureDetector::New();
1209   detector.Attach(stageActor);
1210   detector.DetectedSignal().Connect(&application, functor);
1211
1212   Vector2 screenCoords( 50.0f, 50.0f );
1213
1214   // Do a tap inside both actors' area
1215   application.ProcessEvent( GenerateTap( Gesture::Possible, 1u, 1u, screenCoords ) );
1216   application.ProcessEvent( GenerateTap( Gesture::Started, 1u, 1u, screenCoords ) );
1217   DALI_TEST_EQUALS( true, data.functorCalled, TEST_LOCATION );
1218   DALI_TEST_EQUALS( false, touchData.functorCalled, TEST_LOCATION );
1219
1220   data.Reset();
1221   touchData.Reset();
1222
1223   // Do touch in the same area
1224   application.ProcessEvent( touchFunctor.GenerateSingleTouch( TouchPoint::Down, screenCoords ) );
1225   DALI_TEST_EQUALS( false, data.functorCalled, TEST_LOCATION );
1226   DALI_TEST_EQUALS( true, touchData.functorCalled, TEST_LOCATION );
1227
1228   END_TEST;
1229 }
1230
1231 int UtcDaliTapGestureTouchBehindGesturedSystemOverlay(void)
1232 {
1233   TestApplication application;
1234   Dali::Integration::Core& core = application.GetCore();
1235   Dali::Integration::SystemOverlay& systemOverlay( core.GetSystemOverlay() );
1236   systemOverlay.GetOverlayRenderTasks().CreateTask();
1237
1238   // SystemOverlay actor
1239   Actor systemOverlayActor = Actor::New();
1240   systemOverlayActor.SetSize(100.0f, 100.0f);
1241   systemOverlayActor.SetAnchorPoint(AnchorPoint::TOP_LEFT);
1242   systemOverlay.Add(systemOverlayActor);
1243
1244   // Stage actor
1245   Actor stageActor = Actor::New();
1246   stageActor.SetSize(100.0f, 100.0f);
1247   stageActor.SetAnchorPoint(AnchorPoint::TOP_LEFT);
1248   Stage::GetCurrent().Add(stageActor);
1249
1250   // Render and notify
1251   application.SendNotification();
1252   application.Render();
1253
1254   // Set stage actor to touchable
1255   TouchEventData touchData;
1256   TouchEventDataFunctor touchFunctor( touchData );
1257   stageActor.TouchedSignal().Connect(&application, touchFunctor);
1258
1259   // Set system-overlay actor to have the gesture
1260   SignalData data;
1261   GestureReceivedFunctor functor(data);
1262
1263   TapGestureDetector detector = TapGestureDetector::New();
1264   detector.Attach(systemOverlayActor);
1265   detector.DetectedSignal().Connect(&application, functor);
1266
1267   Vector2 screenCoords( 50.0f, 50.0f );
1268
1269   // Do a tap inside both actors' area
1270   application.ProcessEvent( GenerateTap( Gesture::Possible, 1u, 1u, screenCoords ) );
1271   application.ProcessEvent( GenerateTap( Gesture::Started, 1u, 1u, screenCoords ) );
1272   DALI_TEST_EQUALS( true, data.functorCalled, TEST_LOCATION );
1273   DALI_TEST_EQUALS( false, touchData.functorCalled, TEST_LOCATION );
1274
1275   data.Reset();
1276   touchData.Reset();
1277
1278   // Do touch in the same area
1279   application.ProcessEvent( touchFunctor.GenerateSingleTouch( TouchPoint::Down, screenCoords ) );
1280   DALI_TEST_EQUALS( false, data.functorCalled, TEST_LOCATION );
1281   DALI_TEST_EQUALS( true, touchData.functorCalled, TEST_LOCATION );
1282
1283   END_TEST;
1284 }
1285
1286 int UtcDaliTapGestureLayerConsumesTouch(void)
1287 {
1288   TestApplication application;
1289
1290   Actor actor = Actor::New();
1291   actor.SetSize(100.0f, 100.0f);
1292   actor.SetAnchorPoint(AnchorPoint::TOP_LEFT);
1293   Stage::GetCurrent().Add(actor);
1294
1295   // Add a detector
1296   SignalData data;
1297   GestureReceivedFunctor functor(data);
1298   TapGestureDetector detector = TapGestureDetector::New();
1299   detector.Attach(actor);
1300   detector.DetectedSignal().Connect( &application, functor );
1301
1302   // Add a layer to overlap the actor
1303   Layer layer = Layer::New();
1304   layer.SetSize(100.0f, 100.0f);
1305   layer.SetAnchorPoint(AnchorPoint::TOP_LEFT);
1306   Stage::GetCurrent().Add( layer );
1307   layer.RaiseToTop();
1308
1309   // Render and notify
1310   application.SendNotification();
1311   application.Render();
1312
1313   Vector2 screenCoords( 50.0f, 50.0f );
1314
1315   // Emit signals, should receive
1316   application.ProcessEvent( GenerateTap( Gesture::Possible, 1u, 1u, screenCoords ) );
1317   application.ProcessEvent( GenerateTap( Gesture::Started, 1u, 1u, screenCoords ) );
1318   DALI_TEST_EQUALS(true, data.functorCalled, TEST_LOCATION);
1319   data.Reset();
1320
1321   // Set layer to consume all touch
1322   layer.SetTouchConsumed( true );
1323
1324   // Render and notify
1325   application.SendNotification();
1326   application.Render();
1327
1328   // Emit the same signals again, should not receive
1329   application.ProcessEvent( GenerateTap( Gesture::Possible, 1u, 1u, screenCoords ) );
1330   application.ProcessEvent( GenerateTap( Gesture::Started, 1u, 1u, screenCoords ) );
1331   DALI_TEST_EQUALS(false, data.functorCalled, TEST_LOCATION);
1332   data.Reset();
1333
1334   END_TEST;
1335 }