Gesture event refactor
[platform/core/uifw/dali-core.git] / automated-tests / src / dali / utc-Dali-TapGestureDetector.cpp
1 /*
2  * Copyright (c) 2019 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/render-task-list-integ.h>
24 #include <dali-test-suite-utils.h>
25 #include <test-touch-utils.h>
26
27 using namespace Dali;
28
29 void utc_dali_tap_gesture_detector_startup(void)
30 {
31   test_return_value = TET_UNDEF;
32 }
33
34 void utc_dali_tap_gesture_detector_cleanup(void)
35 {
36   test_return_value = TET_PASS;
37 }
38
39 ///////////////////////////////////////////////////////////////////////////////
40 namespace
41 {
42
43 // Stores data that is populated in the callback and will be read by the TET cases
44 struct SignalData
45 {
46   SignalData()
47   : functorCalled(false),
48     voidFunctorCalled(false)
49   {}
50
51   void Reset()
52   {
53     functorCalled = false;
54     voidFunctorCalled = false;
55
56     receivedGesture.numberOfTaps = 0u;
57     receivedGesture.numberOfTouches = 0u;
58     receivedGesture.screenPoint = Vector2(0.0f, 0.0f);
59     receivedGesture.localPoint = Vector2(0.0f, 0.0f);
60
61     tappedActor.Reset();
62   }
63
64   bool functorCalled;
65   bool voidFunctorCalled;
66   TapGesture receivedGesture;
67   Actor tappedActor;
68 };
69
70 // Functor that sets the data when called
71 struct GestureReceivedFunctor
72 {
73   GestureReceivedFunctor(SignalData& data) : signalData(data) { }
74
75   void operator()(Actor actor, const TapGesture& tap)
76   {
77     signalData.functorCalled = true;
78     signalData.receivedGesture = tap;
79     signalData.tappedActor = actor;
80   }
81
82   void operator()()
83   {
84     signalData.voidFunctorCalled = true;
85   }
86
87   SignalData& signalData;
88 };
89
90 // Functor that removes the gestured actor from stage
91 struct UnstageActorFunctor : public GestureReceivedFunctor
92 {
93   UnstageActorFunctor( SignalData& data ) : GestureReceivedFunctor( data ) { }
94
95   void operator()(Actor actor, const TapGesture& tap)
96   {
97     GestureReceivedFunctor::operator()( actor, tap );
98     Stage::GetCurrent().Remove( actor );
99   }
100 };
101
102 // Functor for receiving a touch event
103 struct TouchEventFunctor
104 {
105   bool operator()(Actor actor, const TouchEvent& touch)
106   {
107     //For line coverage
108     unsigned int points = touch.GetPointCount();
109     if( points > 0)
110     {
111       const TouchPoint& touchPoint = touch.GetPoint(0);
112       tet_printf("Touch Point state = %d\n", touchPoint.state);
113     }
114     return false;
115   }
116 };
117
118 } // anon namespace
119
120 ///////////////////////////////////////////////////////////////////////////////
121
122
123 // Positive test case for a method
124 int UtcDaliTapGestureDetectorConstructor(void)
125 {
126   TestApplication application;
127
128   TapGestureDetector detector;
129   DALI_TEST_CHECK(!detector);
130   END_TEST;
131 }
132
133 int UtcDaliTapGestureDetectorCopyConstructorP(void)
134 {
135   TestApplication application;
136
137   TapGestureDetector detector = TapGestureDetector::New();
138
139   TapGestureDetector copy( detector );
140   DALI_TEST_CHECK( detector );
141   END_TEST;
142 }
143
144 int UtcDaliTapGestureDetectorAssignmentOperatorP(void)
145 {
146   TestApplication application;
147
148   TapGestureDetector detector = TapGestureDetector::New();;
149
150   TapGestureDetector assign;
151   assign = detector;
152   DALI_TEST_CHECK( detector );
153
154   DALI_TEST_CHECK( detector == assign );
155   END_TEST;
156 }
157
158 int UtcDaliTapGestureDetectorNew(void)
159 {
160   TestApplication application;
161
162   TapGestureDetector detector = TapGestureDetector::New();
163   DALI_TEST_CHECK(detector);
164   DALI_TEST_EQUALS(1u, detector.GetMinimumTapsRequired(), TEST_LOCATION);
165   DALI_TEST_EQUALS(1u, detector.GetMaximumTapsRequired(), TEST_LOCATION);
166
167   TapGestureDetector detector2 = TapGestureDetector::New( 5u );
168   DALI_TEST_CHECK(detector2);
169   DALI_TEST_EQUALS(5u, detector2.GetMinimumTapsRequired(), TEST_LOCATION);
170   DALI_TEST_EQUALS(5u, detector2.GetMaximumTapsRequired(), TEST_LOCATION);
171
172   //Scoped test to test destructor
173   {
174     TapGestureDetector detector3 = TapGestureDetector::New();
175     DALI_TEST_CHECK(detector3);
176   }
177
178   // Attach an actor and emit a touch event on the actor to ensure complete line coverage
179   Actor actor = Actor::New();
180   actor.SetSize(100.0f, 100.0f);
181   actor.SetAnchorPoint(AnchorPoint::TOP_LEFT);
182   Stage::GetCurrent().Add(actor);
183
184   // Render and notify
185   application.SendNotification();
186   application.Render();
187
188   detector.Attach(actor);
189
190   TouchEventFunctor touchFunctor;
191   actor.TouchedSignal().Connect( &application, touchFunctor );
192
193   Integration::TouchEvent touchEvent(1);
194   Integration::Point point;
195   point.SetDeviceId( 1 );
196   point.SetState( PointState::DOWN );
197   point.SetScreenPosition( Vector2( 20.0f, 20.0f ) );
198   touchEvent.AddPoint(point);
199   application.ProcessEvent(touchEvent);
200
201   // Render and notify
202   application.SendNotification();
203   application.Render();
204
205   // For line coverage, Initialise default constructor
206   TouchEvent touchEvent2;
207   END_TEST;
208 }
209
210 int UtcDaliTapGestureDetectorDownCast(void)
211 {
212   TestApplication application;
213   tet_infoline("Testing Dali::TapGestureDetector::DownCast()");
214
215   TapGestureDetector detector = TapGestureDetector::New();
216
217   BaseHandle object(detector);
218
219   TapGestureDetector detector2 = TapGestureDetector::DownCast(object);
220   DALI_TEST_CHECK(detector2);
221
222   TapGestureDetector detector3 = DownCast< TapGestureDetector >(object);
223   DALI_TEST_CHECK(detector3);
224
225   BaseHandle unInitializedObject;
226   TapGestureDetector detector4 = TapGestureDetector::DownCast(unInitializedObject);
227   DALI_TEST_CHECK(!detector4);
228
229   TapGestureDetector detector5 = DownCast< TapGestureDetector >(unInitializedObject);
230   DALI_TEST_CHECK(!detector5);
231
232   GestureDetector detector6 = TapGestureDetector::New();
233   TapGestureDetector detector7 = TapGestureDetector::DownCast(detector6);
234   DALI_TEST_CHECK(detector7);
235   END_TEST;
236 }
237
238 int UtcDaliTapGestureSetTapsRequiredMinMaxCheck(void)
239 {
240   TestApplication application;
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   // Set the minimum to be greater than the maximum, should Assert
254
255   try
256   {
257     TapGestureDetector detector = TapGestureDetector::New();
258     detector.SetMinimumTapsRequired( 7u );
259     detector.SetMaximumTapsRequired( 3u );
260     detector.Attach(actor);
261     DALI_TEST_CHECK( false ); // Should not get here
262   }
263   catch ( DaliException& e )
264   {
265     DALI_TEST_CHECK( true );
266   }
267
268   END_TEST;
269 }
270
271 int UtcDaliTapGestureGetTapsRequired(void)
272 {
273   TestApplication application;
274
275   TapGestureDetector detector = TapGestureDetector::New();
276   DALI_TEST_EQUALS(1u, detector.GetMinimumTapsRequired(), TEST_LOCATION);
277   DALI_TEST_EQUALS(1u, detector.GetMaximumTapsRequired(), TEST_LOCATION);
278   END_TEST;
279 }
280
281 int UtcDaliTapGestureSignalReceptionNegative(void)
282 {
283   TestApplication application;
284
285   Actor actor = Actor::New();
286   actor.SetSize(100.0f, 100.0f);
287   actor.SetAnchorPoint(AnchorPoint::TOP_LEFT);
288   Stage::GetCurrent().Add(actor);
289
290   // Render and notify
291   application.SendNotification();
292   application.Render();
293
294   SignalData data;
295   GestureReceivedFunctor functor(data);
296
297   TapGestureDetector detector = TapGestureDetector::New();
298   detector.Attach(actor);
299   detector.DetectedSignal().Connect( &application, functor );
300
301   // Do a tap outside actor's area
302   TestGenerateTap( application, 112.0f, 112.0f, 100 );
303   DALI_TEST_EQUALS(false, data.functorCalled, TEST_LOCATION);
304   END_TEST;
305 }
306
307 int UtcDaliTapGestureSignalReceptionPositive(void)
308 {
309   TestApplication application;
310
311   Actor actor = Actor::New();
312   actor.SetSize(100.0f, 100.0f);
313   actor.SetAnchorPoint(AnchorPoint::TOP_LEFT);
314   Stage::GetCurrent().Add(actor);
315
316   // Render and notify
317   application.SendNotification();
318   application.Render();
319
320   SignalData data;
321   GestureReceivedFunctor functor(data);
322
323   TapGestureDetector detector = TapGestureDetector::New();
324   detector.Attach(actor);
325   detector.DetectedSignal().Connect( &application, functor );
326
327   // Do a tap inside actor's area
328   TestGenerateTap( application, 50.0f, 50.0f, 100 );
329   DALI_TEST_EQUALS(true, data.functorCalled, TEST_LOCATION);
330   DALI_TEST_EQUALS(1u, data.receivedGesture.numberOfTaps, TEST_LOCATION);
331   DALI_TEST_EQUALS(1u, data.receivedGesture.numberOfTouches, TEST_LOCATION);
332   DALI_TEST_EQUALS( Vector2(50.0f, 50.0f), data.receivedGesture.localPoint, 0.1, TEST_LOCATION);
333   END_TEST;
334 }
335
336 int UtcDaliTapGestureSignalReceptionDetach(void)
337 {
338   TestApplication application;
339
340   Actor actor = Actor::New();
341   actor.SetSize(100.0f, 100.0f);
342   actor.SetAnchorPoint(AnchorPoint::TOP_LEFT);
343   Stage::GetCurrent().Add(actor);
344
345   // Render and notify
346   application.SendNotification();
347   application.Render();
348
349   SignalData data;
350   GestureReceivedFunctor functor(data);
351
352   TapGestureDetector detector = TapGestureDetector::New();
353   detector.Attach(actor);
354   detector.DetectedSignal().Connect(&application, functor);
355
356   // Start tap within the actor's area
357   TestGenerateTap( application, 20.0f, 20.0f, 100 );
358   DALI_TEST_EQUALS(true, data.functorCalled, TEST_LOCATION);
359   DALI_TEST_EQUALS(1u, data.receivedGesture.numberOfTaps, TEST_LOCATION);
360   DALI_TEST_EQUALS(1u, data.receivedGesture.numberOfTouches, TEST_LOCATION);
361   DALI_TEST_EQUALS( Vector2(20.0f, 20.0f), data.receivedGesture.localPoint, 0.1, TEST_LOCATION);
362
363   // repeat the tap within the actor's area - we should still receive the signal
364   data.Reset();
365   TestGenerateTap( application, 50.0f, 50.0f, 700 );
366   DALI_TEST_EQUALS(true, data.functorCalled, TEST_LOCATION);
367   DALI_TEST_EQUALS(1u, data.receivedGesture.numberOfTaps, TEST_LOCATION);
368   DALI_TEST_EQUALS(1u, data.receivedGesture.numberOfTouches, TEST_LOCATION);
369   DALI_TEST_EQUALS( Vector2(50.0f, 50.0f), data.receivedGesture.localPoint, 0.1, TEST_LOCATION);
370
371   // Detach actor
372   detector.DetachAll();
373
374   // Ensure we are no longer signalled
375   data.Reset();
376   TestGenerateTap( application, 20.0f, 20.0f, 1300 );
377   DALI_TEST_EQUALS(false, data.functorCalled, TEST_LOCATION);
378   TestGenerateTap( application, 50.0f, 50.0f, 1900 );
379   DALI_TEST_EQUALS(false, data.functorCalled, TEST_LOCATION);
380   END_TEST;
381 }
382
383 int UtcDaliTapGestureSignalReceptionActorDestroyedWhileTapping(void)
384 {
385   TestApplication application;
386
387   SignalData data;
388   GestureReceivedFunctor functor(data);
389
390   TapGestureDetector detector = TapGestureDetector::New();
391   detector.DetectedSignal().Connect(&application, functor);
392
393   // Actor lifetime is scoped
394   {
395     Actor actor = Actor::New();
396     actor.SetSize(100.0f, 100.0f);
397     actor.SetAnchorPoint(AnchorPoint::TOP_LEFT);
398     Stage::GetCurrent().Add(actor);
399
400     // Render and notify
401     application.SendNotification();
402     application.Render();
403
404     detector.Attach(actor);
405
406     // Start tap within the actor's area
407     TestGenerateTap( application, 20.0f, 20.0f, 100 );
408     DALI_TEST_EQUALS(true, data.functorCalled, TEST_LOCATION);
409
410     // Remove the actor from stage and reset the data
411     Stage::GetCurrent().Remove(actor);
412
413     // Render and notify
414     application.SendNotification();
415     application.Render();
416   }
417
418   // Actor should now have been destroyed
419
420   data.Reset();
421   TestGenerateTap( application, 20.0f, 20.0f, 700 );
422   DALI_TEST_EQUALS(false, data.functorCalled, TEST_LOCATION);
423   END_TEST;
424 }
425
426 int UtcDaliTapGestureSignalReceptionRotatedActor(void)
427 {
428   TestApplication application;
429
430   Actor actor = Actor::New();
431   actor.SetSize(100.0f, 100.0f);
432   actor.SetOrientation(Dali::Degree(90.0f), Vector3::ZAXIS);
433   Stage::GetCurrent().Add(actor);
434
435   // Render and notify
436   application.SendNotification();
437   application.Render();
438
439   SignalData data;
440   GestureReceivedFunctor functor(data);
441
442   TapGestureDetector detector = TapGestureDetector::New();
443   detector.Attach(actor);
444   detector.DetectedSignal().Connect(&application, functor);
445
446   // Do tap, only check finished value
447   TestGenerateTap( application, 5.0f, 5.0f, 100 );
448   DALI_TEST_EQUALS(true, data.functorCalled, TEST_LOCATION);
449   DALI_TEST_EQUALS(1u, data.receivedGesture.numberOfTaps, TEST_LOCATION);
450   DALI_TEST_EQUALS(1u, data.receivedGesture.numberOfTouches, TEST_LOCATION);
451   DALI_TEST_EQUALS( Vector2(5.0f, 5.0f), data.receivedGesture.screenPoint, 0.1, TEST_LOCATION);
452
453   // Rotate actor again and render
454   actor.SetOrientation(Dali::Degree(180.0f), Vector3::ZAXIS);
455   application.SendNotification();
456   application.Render();
457
458   // Do tap, should still receive event
459   data.Reset();
460   TestGenerateTap( application, 5.0f, 5.0f, 700 );
461   DALI_TEST_EQUALS(true, data.functorCalled, TEST_LOCATION);
462   DALI_TEST_EQUALS(1u, data.receivedGesture.numberOfTaps, TEST_LOCATION);
463   DALI_TEST_EQUALS(1u, data.receivedGesture.numberOfTouches, TEST_LOCATION);
464   DALI_TEST_EQUALS( Vector2(5.0f, 5.0f), data.receivedGesture.screenPoint, 0.1, TEST_LOCATION);
465
466   // Rotate actor again and render
467   actor.SetOrientation(Dali::Degree(90.0f), Vector3::YAXIS);
468   application.SendNotification();
469   application.Render();
470
471   // Do tap, inside the actor's area (area if it is not rotated), Should not receive the event
472   data.Reset();
473   TestGenerateTap( application, 70.0f, 70.0f, 1300 );
474   DALI_TEST_EQUALS(false, data.functorCalled, TEST_LOCATION);
475   END_TEST;
476 }
477
478 int UtcDaliTapGestureSignalReceptionChildHit(void)
479 {
480   TestApplication application;
481
482   Actor parent = Actor::New();
483   parent.SetSize(100.0f, 100.0f);
484   parent.SetAnchorPoint(AnchorPoint::TOP_LEFT);
485   Stage::GetCurrent().Add(parent);
486
487   // Set child to completely cover parent.
488   // Change rotation of child to be different from parent so that we can check if our local coordinate
489   // conversion of the parent actor is correct.
490   Actor child = Actor::New();
491   child.SetSize(100.0f, 100.0f);
492   child.SetAnchorPoint(AnchorPoint::CENTER);
493   child.SetParentOrigin(ParentOrigin::CENTER);
494   child.SetOrientation(Dali::Degree(90.0f), Vector3::ZAXIS);
495   parent.Add(child);
496
497   TouchEventFunctor touchFunctor;
498   child.TouchedSignal().Connect(&application, touchFunctor);
499
500   // Render and notify
501   application.SendNotification();
502   application.Render();
503
504   SignalData data;
505   GestureReceivedFunctor functor(data);
506
507   TapGestureDetector detector = TapGestureDetector::New();
508   detector.Attach(parent);
509   detector.DetectedSignal().Connect(&application, functor);
510
511   // Do tap - hits child area but parent should still receive it
512   TestGenerateTap( application, 50.0f, 50.0f, 100 );
513   DALI_TEST_EQUALS(true, data.functorCalled, TEST_LOCATION);
514   DALI_TEST_EQUALS(true, parent == data.tappedActor, TEST_LOCATION);
515   DALI_TEST_EQUALS(Vector2(50.0f, 50.0f), data.receivedGesture.screenPoint, 0.01f, TEST_LOCATION);
516
517   // Attach child and generate same touch points
518   // (Also proves that you can detach and then re-attach another actor)
519   detector.Attach(child);
520   detector.Detach(parent);
521
522   // Do an entire tap, only check finished value
523   data.Reset();
524   TestGenerateTap( application, 51.0f, 51.0f, 700 );
525   DALI_TEST_EQUALS(true, data.functorCalled, TEST_LOCATION);
526   DALI_TEST_EQUALS(true, child == data.tappedActor, TEST_LOCATION);
527   DALI_TEST_EQUALS(Vector2(51.0f, 51.0f), data.receivedGesture.screenPoint, 0.01f, TEST_LOCATION);
528   END_TEST;
529 }
530
531 int UtcDaliTapGestureSignalReceptionAttachDetachMany(void)
532 {
533   TestApplication application;
534
535   Actor first = Actor::New();
536   first.SetSize(100.0f, 100.0f);
537   first.SetAnchorPoint(AnchorPoint::TOP_LEFT);
538   Stage::GetCurrent().Add(first);
539
540   Actor second = Actor::New();
541   second.SetSize(100.0f, 100.0f);
542   second.SetX(100.0f);
543   second.SetAnchorPoint(AnchorPoint::TOP_LEFT);
544   Stage::GetCurrent().Add(second);
545
546   // Render and notify
547   application.SendNotification();
548   application.Render();
549
550   SignalData data;
551   GestureReceivedFunctor functor(data);
552
553   TapGestureDetector detector = TapGestureDetector::New();
554   detector.Attach(first);
555   detector.Attach(second);
556   detector.DetectedSignal().Connect(&application, functor);
557
558   // Tap within second actor's area
559   TestGenerateTap( application, 120.0f, 10.0f, 100 );
560   DALI_TEST_EQUALS(true, data.functorCalled, TEST_LOCATION);
561   DALI_TEST_EQUALS(true, second == data.tappedActor, TEST_LOCATION);
562
563   // Tap within first actor's area
564   data.Reset();
565   TestGenerateTap( application, 20.0f, 10.0f, 700 );
566   DALI_TEST_EQUALS(true, data.functorCalled, TEST_LOCATION);
567   DALI_TEST_EQUALS(true, first == data.tappedActor, TEST_LOCATION);
568
569   // Detach the second actor
570   detector.Detach(second);
571
572   // second actor shouldn't receive event
573   data.Reset();
574   TestGenerateTap( application, 120.0f, 10.0f, 1300 );
575   DALI_TEST_EQUALS(false, data.functorCalled, TEST_LOCATION);
576
577   // first actor should continue receiving event
578   data.Reset();
579   TestGenerateTap( application, 20.0f, 10.0f, 1900 );
580   DALI_TEST_EQUALS(true, data.functorCalled, TEST_LOCATION);
581   END_TEST;
582 }
583
584 int UtcDaliTapGestureSignalReceptionActorBecomesUntouchable(void)
585 {
586   TestApplication application;
587
588   Actor actor = Actor::New();
589   actor.SetSize(100.0f, 100.0f);
590   actor.SetAnchorPoint(AnchorPoint::TOP_LEFT);
591   Stage::GetCurrent().Add(actor);
592
593   // Render and notify
594   application.SendNotification();
595   application.Render();
596
597   SignalData data;
598   GestureReceivedFunctor functor(data);
599
600   TapGestureDetector detector = TapGestureDetector::New();
601   detector.Attach(actor);
602   detector.DetectedSignal().Connect(&application, functor);
603
604   // Tap in actor's area
605   TestGenerateTap( application, 50.0f, 10.0f, 100 );
606   DALI_TEST_EQUALS(true, data.functorCalled, TEST_LOCATION);
607
608   // Actor become invisible - actor should not receive the next pan
609   actor.SetVisible(false);
610
611   // Render and notify
612   application.SendNotification();
613   application.Render();
614
615   // Tap in the same area, shouldn't receive event
616   data.Reset();
617   TestGenerateTap( application, 50.0f, 10.0f, 700 );
618   DALI_TEST_EQUALS(false, data.functorCalled, TEST_LOCATION);
619   END_TEST;
620 }
621
622 int UtcDaliTapGestureSignalReceptionMultipleGestureDetectors(void)
623 {
624   TestApplication application;
625
626   Actor first = Actor::New();
627   first.SetSize(100.0f, 100.0f);
628   first.SetAnchorPoint(AnchorPoint::TOP_LEFT);
629   Stage::GetCurrent().Add(first);
630
631   Actor second = Actor::New();
632   second.SetSize(100.0f, 100.0f);
633   second.SetAnchorPoint(AnchorPoint::TOP_LEFT);
634   second.SetX(100.0f);
635   first.Add(second);
636
637   // Render and notify
638   application.SendNotification();
639   application.Render();
640
641   SignalData data;
642   GestureReceivedFunctor functor(data);
643
644   TapGestureDetector firstDetector = TapGestureDetector::New();
645   firstDetector.Attach(first);
646   firstDetector.DetectedSignal().Connect(&application, functor);
647
648   // secondDetector is scoped
649   {
650     TapGestureDetector secondDetector = TapGestureDetector::New( 2 );
651     secondDetector.Attach(second);
652     secondDetector.DetectedSignal().Connect(&application, functor);
653
654     // Tap within second actor's area
655     TestGenerateTap( application, 150.0f, 10.0f, 100 );
656     TestGenerateTap( application, 150.0f, 10.0f, 200 );
657
658     DALI_TEST_EQUALS(true, data.functorCalled, TEST_LOCATION);
659     DALI_TEST_EQUALS(true, second == data.tappedActor, TEST_LOCATION);
660
661     // Tap continues as single touch gesture - we should not receive any gesture
662     data.Reset();
663     TestGenerateTap( application, 150.0f, 10.0f, 800 );
664     DALI_TEST_EQUALS(false, data.functorCalled, TEST_LOCATION);
665
666     // Single touch tap starts - first actor should be panned
667     data.Reset();
668     TestGenerateTap( application, 50.0f, 10.0f, 1400 );
669     DALI_TEST_EQUALS(true, data.functorCalled, TEST_LOCATION);
670     DALI_TEST_EQUALS(true, first == data.tappedActor, TEST_LOCATION);
671
672     // Pan changes to double-touch - we shouldn't receive event
673     data.Reset();
674
675     TestGenerateTwoPointTap( application, 50.0f, 10.0f, 60.0f, 20.0f, 2000 );
676
677     DALI_TEST_EQUALS(false, data.functorCalled, TEST_LOCATION);
678   }
679
680   END_TEST;
681 }
682
683 int UtcDaliTapGestureSignalReceptionMultipleDetectorsOnActor(void)
684 {
685   TestApplication application;
686
687   Actor actor = Actor::New();
688   actor.SetSize(100.0f, 100.0f);
689   actor.SetAnchorPoint(AnchorPoint::TOP_LEFT);
690   Stage::GetCurrent().Add(actor);
691
692   // Render and notify
693   application.SendNotification();
694   application.Render();
695
696   // Attach actor to one detector
697   SignalData firstData;
698   GestureReceivedFunctor firstFunctor(firstData);
699   TapGestureDetector firstDetector = TapGestureDetector::New();
700   firstDetector.Attach(actor);
701   firstDetector.DetectedSignal().Connect(&application, firstFunctor);
702
703   // Attach actor to another detector
704   SignalData secondData;
705   GestureReceivedFunctor secondFunctor(secondData);
706   TapGestureDetector secondDetector = TapGestureDetector::New();
707   secondDetector.Attach(actor);
708   secondDetector.DetectedSignal().Connect(&application, secondFunctor);
709
710   // Tap in actor's area - both detector's functors should be called
711   TestGenerateTap( application, 50.0f, 10.0f, 100 );
712   DALI_TEST_EQUALS(true, firstData.functorCalled, TEST_LOCATION);
713   DALI_TEST_EQUALS(true, secondData.functorCalled, TEST_LOCATION);
714   END_TEST;
715 }
716
717 int UtcDaliTapGestureSignalReceptionDifferentPossible(void)
718 {
719   TestApplication application;
720
721   Actor actor = Actor::New();
722   actor.SetSize(100.0f, 100.0f);
723   actor.SetAnchorPoint(AnchorPoint::TOP_LEFT);
724   Stage::GetCurrent().Add(actor);
725
726   // Render and notify
727   application.SendNotification();
728   application.Render();
729
730   // Attach actor to detector
731   SignalData data;
732   GestureReceivedFunctor functor( data );
733   TapGestureDetector detector = TapGestureDetector::New();
734   detector.Attach(actor);
735   detector.DetectedSignal().Connect( &application, functor );
736
737   // Gesture possible in actor's area.
738   TestStartLongPress( application, 50.0f, 10.0f, 100 );
739   DALI_TEST_EQUALS(false, data.functorCalled, TEST_LOCATION);
740
741   // Move actor somewhere else
742   actor.SetPosition( 100.0f, 100.0f );
743
744   // Render and notify
745   application.SendNotification();
746   application.Render();
747
748   // Emit Started event, we should not receive the tap.
749   TestEndPan( application, Vector2(50.0f, 10.0f), 120 );
750   DALI_TEST_EQUALS(false, data.functorCalled, TEST_LOCATION);
751
752   // Tap possible in empty area.
753   TestStartLongPress( application, 50.0f, 10.0f, 700 );
754   DALI_TEST_EQUALS(false, data.functorCalled, TEST_LOCATION);
755
756   // Move actor in to the tap position.
757   actor.SetPosition( 0.0f, 0.0f );
758
759   // Render and notify
760   application.SendNotification();
761   application.Render();
762
763   // Emit Started event, we should not receive the tap.
764   TestEndPan( application, Vector2(50.0f, 10.0f), 720 );
765   DALI_TEST_EQUALS(false, data.functorCalled, TEST_LOCATION);
766
767   // Normal tap in actor's area for completeness.
768   TestGenerateTap( application, 50.0f, 10.0f, 1300 );
769   DALI_TEST_EQUALS(true, data.functorCalled, TEST_LOCATION);
770   END_TEST;
771 }
772
773 int UtcDaliTapGestureActorUnstaged(void)
774 {
775   TestApplication application;
776
777   Actor actor = Actor::New();
778   actor.SetSize(100.0f, 100.0f);
779   actor.SetAnchorPoint(AnchorPoint::TOP_LEFT);
780   Stage::GetCurrent().Add(actor);
781
782   // Render and notify
783   application.SendNotification();
784   application.Render();
785
786   // Attach actor to detector
787   SignalData data;
788   UnstageActorFunctor functor( data );
789   TapGestureDetector detector = TapGestureDetector::New();
790   detector.Attach(actor);
791   detector.DetectedSignal().Connect( &application, functor );
792
793   TestGenerateTap( application, 50.0f, 10.0f, 100 );
794   DALI_TEST_EQUALS( true, data.functorCalled, TEST_LOCATION );
795   tet_result( TET_PASS ); // If we get here, then the actor removal on signal handler was handled gracefully.
796   END_TEST;
797 }
798
799 int UtcDaliTapGestureDetectorRemovedWhilePossible(void)
800 {
801   TestApplication application;
802
803   Actor actor = Actor::New();
804   actor.SetSize(100.0f, 100.0f);
805   actor.SetAnchorPoint(AnchorPoint::TOP_LEFT);
806   Stage::GetCurrent().Add(actor);
807
808   // Render and notify
809   application.SendNotification();
810   application.Render();
811
812   // Attach actor to detector
813   SignalData data;
814   GestureReceivedFunctor functor( data );
815   TapGestureDetector detector = TapGestureDetector::New();
816   detector.Attach(actor);
817   detector.DetectedSignal().Connect( &application, functor );
818
819   // Emit a possible - Down press, as emitted by long press function
820   TestStartLongPress( application, 50.0f, 10.0f, 100 );
821
822   // Detach actor and send a Started state, no signal.
823   detector.DetachAll();
824   TestEndPan( application, Vector2(50.0f, 10.0f), 120 );
825   DALI_TEST_EQUALS(false, data.functorCalled, TEST_LOCATION);
826   END_TEST;
827 }
828
829 int UtcDaliTapGestureActorRemovedWhilePossible(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   // Emit a possible - Down press, as emitted by long press function
850   TestStartLongPress( application, 50.0f, 10.0f, 100 );
851
852   // Remove, render and delete actor
853   Stage::GetCurrent().Remove(actor);
854   application.SendNotification();
855   application.Render();
856   actor.Reset();
857
858   // Send a Started state, no signal - Up motion as provided by end pan function
859   TestEndPan( application, Vector2(50.0f, 10.0f), 120 );
860   DALI_TEST_EQUALS(false, data.functorCalled, TEST_LOCATION);
861   END_TEST;
862 }
863
864 int UtcDaliTapGestureLayerConsumesTouch(void)
865 {
866   TestApplication application;
867
868   Actor actor = Actor::New();
869   actor.SetSize(100.0f, 100.0f);
870   actor.SetAnchorPoint(AnchorPoint::TOP_LEFT);
871   Stage::GetCurrent().Add(actor);
872
873   // Add a detector
874   SignalData data;
875   GestureReceivedFunctor functor(data);
876   TapGestureDetector detector = TapGestureDetector::New();
877   detector.Attach(actor);
878   detector.DetectedSignal().Connect( &application, functor );
879
880   // Add a layer to overlap the actor
881   Layer layer = Layer::New();
882   layer.SetSize(100.0f, 100.0f);
883   layer.SetAnchorPoint(AnchorPoint::TOP_LEFT);
884   Stage::GetCurrent().Add( layer );
885   layer.RaiseToTop();
886
887   // Render and notify
888   application.SendNotification();
889   application.Render();
890
891   // Emit signals, should receive
892   TestGenerateTap( application, 50.0f, 50.0f, 100 );
893   DALI_TEST_EQUALS(true, data.functorCalled, TEST_LOCATION);
894   data.Reset();
895
896   // Set layer to consume all touch
897   layer.SetTouchConsumed( true );
898
899   // Render and notify
900   application.SendNotification();
901   application.Render();
902
903   // Emit the same signals again, should not receive
904   TestGenerateTap( application, 50.0f, 50.0f, 700 );
905   DALI_TEST_EQUALS(false, data.functorCalled, TEST_LOCATION);
906   data.Reset();
907
908   END_TEST;
909 }