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