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