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