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