Add an environment variable for long press gesture
[platform/core/uifw/dali-core.git] / automated-tests / src / dali / utc-Dali-LongPressGestureDetector.cpp
1 /*
2  * Copyright (c) 2019 Samsung Electronics Co., Ltd.
3  *
4  * Licensed under the Apache License, Version 2.0 (the "License");
5  * you may not use this file except in compliance with the License.
6  * You may obtain a copy of the License at
7  *
8  * http://www.apache.org/licenses/LICENSE-2.0
9  *
10  * Unless required by applicable law or agreed to in writing, software
11  * distributed under the License is distributed on an "AS IS" BASIS,
12  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13  * See the License for the specific language governing permissions and
14  * limitations under the License.
15  *
16  */
17
18 #include <iostream>
19
20 #include <stdlib.h>
21 #include <dali/public-api/dali-core.h>
22 #include <dali/integration-api/events/touch-event-integ.h>
23 #include <dali/integration-api/input-options.h>
24 #include <dali/integration-api/render-task-list-integ.h>
25 #include <dali/devel-api/events/long-press-gesture-detector-devel.h>
26 #include <dali-test-suite-utils.h>
27 #include <test-touch-utils.h>
28
29 using namespace Dali;
30
31 void utc_dali_long_press_gesture_detector_startup(void)
32 {
33   test_return_value = TET_UNDEF;
34 }
35
36 void utc_dali_long_press_gesture_detector_cleanup(void)
37 {
38   test_return_value = TET_PASS;
39 }
40
41 ///////////////////////////////////////////////////////////////////////////////
42 namespace
43 {
44
45 // Stores data that is populated in the callback and will be read by the TET cases
46 struct SignalData
47 {
48   SignalData()
49   : functorCalled( false ),
50     voidFunctorCalled( false ),
51     receivedGesture( Gesture::Clear ),
52     pressedActor()
53   {}
54
55   void Reset()
56   {
57     functorCalled = false;
58     voidFunctorCalled = false;
59
60     receivedGesture.numberOfTouches = 0u;
61     receivedGesture.screenPoint = Vector2(0.0f, 0.0f);
62     receivedGesture.localPoint = Vector2(0.0f, 0.0f);
63
64     pressedActor.Reset();
65   }
66
67   bool functorCalled;
68   bool voidFunctorCalled;
69   LongPressGesture receivedGesture;
70   Actor pressedActor;
71 };
72
73 // Functor that sets the data when called
74 struct GestureReceivedFunctor
75 {
76   GestureReceivedFunctor(SignalData& data) : signalData(data) { }
77
78   void operator()(Actor actor, const LongPressGesture& longPress)
79   {
80     signalData.functorCalled = true;
81     signalData.receivedGesture = longPress;
82     signalData.pressedActor = actor;
83   }
84
85   void operator()()
86   {
87     signalData.voidFunctorCalled = true;
88   }
89
90   SignalData& signalData;
91 };
92
93 // Functor that removes the gestured actor from stage
94 struct UnstageActorFunctor : public GestureReceivedFunctor
95 {
96   UnstageActorFunctor( SignalData& data, Gesture::State& stateToUnstage )
97   : GestureReceivedFunctor( data ),
98     stateToUnstage( stateToUnstage )
99   {
100   }
101
102   void operator()( Actor actor, const LongPressGesture& longPress )
103   {
104     GestureReceivedFunctor::operator()( actor, longPress );
105
106     if ( longPress.state == stateToUnstage )
107     {
108       Stage::GetCurrent().Remove( actor );
109     }
110   }
111
112   Gesture::State& stateToUnstage;
113 };
114
115 // Functor for receiving a touch event
116 struct TouchEventFunctor
117 {
118   bool operator()(Actor actor, const TouchEvent& touch)
119   {
120     //For line coverage
121     unsigned int points = touch.GetPointCount();
122     if( points > 0)
123     {
124       const TouchPoint& touchPoint = touch.GetPoint(0);
125       tet_printf("Touch Point state = %d\n", touchPoint.state);
126     }
127     return false;
128   }
129 };
130
131 } // anon namespace
132
133 ///////////////////////////////////////////////////////////////////////////////
134
135
136 // Positive test case for a method
137 int UtcDaliLongPressGestureDetectorConstructorP(void)
138 {
139   TestApplication application;
140
141   LongPressGestureDetector detector;
142   DALI_TEST_CHECK(!detector);
143   END_TEST;
144 }
145
146 int UtcDaliLongPressGestureDetectorCopyConstructorP(void)
147 {
148   TestApplication application;
149
150   LongPressGestureDetector detector = LongPressGestureDetector::New();;
151
152   LongPressGestureDetector copy( detector );
153   DALI_TEST_CHECK( detector );
154   END_TEST;
155 }
156
157 int UtcDaliLongPressGestureDetectorAssignmentOperatorP(void)
158 {
159   TestApplication application;
160
161   LongPressGestureDetector detector;
162   detector = LongPressGestureDetector::New();;
163
164   LongPressGestureDetector copy;
165   copy = detector;
166   DALI_TEST_CHECK( detector );
167
168   DALI_TEST_CHECK( detector == copy );
169   END_TEST;
170 }
171
172 int UtcDaliLongPressGestureDetectorNew(void)
173 {
174   TestApplication application;
175
176   LongPressGestureDetector detector = LongPressGestureDetector::New();
177   DALI_TEST_CHECK(detector);
178   DALI_TEST_EQUALS(1u, detector.GetMinimumTouchesRequired(), TEST_LOCATION);
179   DALI_TEST_EQUALS(1u, detector.GetMaximumTouchesRequired(), TEST_LOCATION);
180
181   LongPressGestureDetector detector2 = LongPressGestureDetector::New(5u);
182   DALI_TEST_CHECK(detector2);
183   DALI_TEST_EQUALS(5u, detector2.GetMinimumTouchesRequired(), TEST_LOCATION);
184   DALI_TEST_EQUALS(5u, detector2.GetMaximumTouchesRequired(), TEST_LOCATION);
185
186   LongPressGestureDetector detector3 = LongPressGestureDetector::New(5u, 7u);
187   DALI_TEST_CHECK(detector2);
188   DALI_TEST_EQUALS(5u, detector3.GetMinimumTouchesRequired(), TEST_LOCATION);
189   DALI_TEST_EQUALS(7u, detector3.GetMaximumTouchesRequired(), TEST_LOCATION);
190
191   //Scoped test to test destructor
192   {
193     LongPressGestureDetector detector4 = LongPressGestureDetector::New();
194     DALI_TEST_CHECK(detector4);
195   }
196
197   // Attach an actor and emit a touch event on the actor to ensure complete line coverage
198   Actor actor = Actor::New();
199   actor.SetSize(100.0f, 100.0f);
200   actor.SetAnchorPoint(AnchorPoint::TOP_LEFT);
201   Stage::GetCurrent().Add(actor);
202
203   // Render and notify
204   application.SendNotification();
205   application.Render();
206
207   detector.Attach(actor);
208
209   TouchEventFunctor touchFunctor;
210   actor.TouchedSignal().Connect(&application, touchFunctor);
211
212   Integration::TouchEvent touchEvent(1);
213   Integration::Point point;
214   point.SetDeviceId( 1 );
215   point.SetState( PointState::DOWN );
216   point.SetScreenPosition( Vector2( 20.0f, 20.0f ) );
217   touchEvent.AddPoint(point);
218   application.ProcessEvent(touchEvent);
219
220   // Render and notify
221   application.SendNotification();
222   application.Render();
223
224   // For line coverage, Initialise default constructor
225   TouchEvent touchEvent2;
226   END_TEST;
227 }
228
229 int UtcDaliLongPressGestureDetectorDownCast(void)
230 {
231   TestApplication application;
232   tet_infoline("Testing Dali::LongPressGestureDetector::DownCast()");
233
234   LongPressGestureDetector detector = LongPressGestureDetector::New();
235
236   BaseHandle object(detector);
237
238   LongPressGestureDetector detector2 = LongPressGestureDetector::DownCast(object);
239   DALI_TEST_CHECK(detector2);
240
241   LongPressGestureDetector detector3 = DownCast< LongPressGestureDetector >(object);
242   DALI_TEST_CHECK(detector3);
243
244   BaseHandle unInitializedObject;
245   LongPressGestureDetector detector4 = LongPressGestureDetector::DownCast(unInitializedObject);
246   DALI_TEST_CHECK(!detector4);
247
248   LongPressGestureDetector detector5 = DownCast< LongPressGestureDetector >(unInitializedObject);
249   DALI_TEST_CHECK(!detector5);
250
251   GestureDetector detector6 = LongPressGestureDetector::New();
252   LongPressGestureDetector detector7 = LongPressGestureDetector::DownCast(detector6);
253   DALI_TEST_CHECK(detector7);
254   END_TEST;
255 }
256
257 int UtcDaliLongPressGestureGetMinimumTouchesRequired(void)
258 {
259   TestApplication application;
260
261   LongPressGestureDetector detector = LongPressGestureDetector::New();
262   DALI_TEST_EQUALS(1u, detector.GetMinimumTouchesRequired(), TEST_LOCATION);
263   END_TEST;
264 }
265
266 int UtcDaliLongPressGestureGetMaximumTouchesRequired(void)
267 {
268   TestApplication application;
269
270   LongPressGestureDetector detector = LongPressGestureDetector::New();
271   DALI_TEST_EQUALS(1u, detector.GetMaximumTouchesRequired(), TEST_LOCATION);
272   END_TEST;
273 }
274
275 int UtcDaliLongPressGestureSignalReceptionNegative(void)
276 {
277   TestApplication application;
278
279   Actor actor = Actor::New();
280   actor.SetSize(100.0f, 100.0f);
281   actor.SetAnchorPoint(AnchorPoint::TOP_LEFT);
282   Stage::GetCurrent().Add(actor);
283
284   // Render and notify
285   application.SendNotification();
286   application.Render();
287
288   SignalData data;
289   GestureReceivedFunctor functor(data);
290
291   LongPressGestureDetector detector = LongPressGestureDetector::New();
292   detector.Attach(actor);
293   detector.DetectedSignal().Connect(&application, functor);
294
295   // Do a long press outside actor's area
296   TestGenerateLongPress( application, 112.0f, 112.0f );
297   TestEndLongPress( application, 112.0f, 112.0f);
298
299   DALI_TEST_EQUALS(false, data.functorCalled, TEST_LOCATION);
300   END_TEST;
301 }
302
303 int UtcDaliLongPressGestureSignalReceptionPositive(void)
304 {
305   TestApplication application;
306
307   Actor actor = Actor::New();
308   actor.SetSize(100.0f, 100.0f);
309   actor.SetAnchorPoint(AnchorPoint::TOP_LEFT);
310   Stage::GetCurrent().Add(actor);
311
312   // Render and notify
313   application.SendNotification();
314   application.Render();
315
316   SignalData data;
317   GestureReceivedFunctor functor(data);
318
319   LongPressGestureDetector detector = LongPressGestureDetector::New();
320   detector.Attach(actor);
321   detector.DetectedSignal().Connect(&application, functor);
322
323   // Do a long press inside actor's area
324   TestGenerateLongPress( application, 50.0f, 50.0f );
325   DALI_TEST_EQUALS(true, data.functorCalled, TEST_LOCATION);
326   DALI_TEST_EQUALS(1u, data.receivedGesture.numberOfTouches, TEST_LOCATION);
327   DALI_TEST_EQUALS( Vector2(50.0f, 50.0f), data.receivedGesture.localPoint, 0.1, TEST_LOCATION);
328   TestEndLongPress( application, 50.0f, 50.0f);
329   END_TEST;
330 }
331
332 int UtcDaliLongPressGestureSignalReceptionDetach(void)
333 {
334   TestApplication application;
335
336   Actor actor = Actor::New();
337   actor.SetSize(100.0f, 100.0f);
338   actor.SetAnchorPoint(AnchorPoint::TOP_LEFT);
339   Stage::GetCurrent().Add(actor);
340
341   // Render and notify
342   application.SendNotification();
343   application.Render();
344
345   SignalData data;
346   GestureReceivedFunctor functor(data);
347
348   LongPressGestureDetector detector = LongPressGestureDetector::New();
349   detector.Attach(actor);
350   detector.DetectedSignal().Connect(&application, functor);
351
352   // Start long press within the actor's area
353   TestGenerateLongPress( application, 20.0f, 20.0f );
354   DALI_TEST_EQUALS(true, data.functorCalled, TEST_LOCATION);
355   DALI_TEST_EQUALS(1u, data.receivedGesture.numberOfTouches, TEST_LOCATION);
356   DALI_TEST_EQUALS( Vector2(20.0f, 20.0f), data.receivedGesture.localPoint, 0.1, TEST_LOCATION);
357   TestEndLongPress( application, 20.0f, 20.0f);
358
359   // repeat the long press within the actor's area - we should still receive the signal
360   data.Reset();
361   TestGenerateLongPress( application, 50.0f, 50.0f );
362   DALI_TEST_EQUALS(true, data.functorCalled, TEST_LOCATION);
363   DALI_TEST_EQUALS(1u, data.receivedGesture.numberOfTouches, TEST_LOCATION);
364   DALI_TEST_EQUALS( Vector2(50.0f, 50.0f), data.receivedGesture.localPoint, 0.1, TEST_LOCATION);
365   TestEndLongPress( application, 50.0f, 50.0f);
366
367   // Detach actor
368   detector.DetachAll();
369
370   // Ensure we are no longer signalled
371   data.Reset();
372   TestGenerateLongPress( application, 20.0f, 20.0f );
373   DALI_TEST_EQUALS(false, data.functorCalled, TEST_LOCATION);
374   TestEndLongPress( application, 50.0f, 50.0f);
375   DALI_TEST_EQUALS(false, data.functorCalled, TEST_LOCATION);
376   END_TEST;
377 }
378
379 int UtcDaliLongPressGestureSignalReceptionActorDestroyedDuringLongPress(void)
380 {
381   TestApplication application;
382
383   SignalData data;
384   GestureReceivedFunctor functor(data);
385
386   LongPressGestureDetector detector = LongPressGestureDetector::New();
387   detector.DetectedSignal().Connect(&application, functor);
388
389   // Actor lifetime is scoped
390   {
391     Actor actor = Actor::New();
392     actor.SetSize(100.0f, 100.0f);
393     actor.SetAnchorPoint(AnchorPoint::TOP_LEFT);
394     Stage::GetCurrent().Add(actor);
395
396     // Render and notify
397     application.SendNotification();
398     application.Render();
399
400     detector.Attach(actor);
401
402     // Start long press within the actor's area
403     TestGenerateLongPress( application, 20.0f, 20.0f );
404     DALI_TEST_EQUALS(true, data.functorCalled, TEST_LOCATION);
405
406     // Remove the actor from stage and reset the data
407     Stage::GetCurrent().Remove(actor);
408
409     // Render and notify
410     application.SendNotification();
411     application.Render();
412   }
413
414   // Actor should now have been destroyed
415
416   data.Reset();
417   TestEndLongPress( application, 20.0f, 20.0f);
418   DALI_TEST_EQUALS(false, data.functorCalled, TEST_LOCATION);
419   END_TEST;
420 }
421
422 int UtcDaliLongPressGestureSignalReceptionRotatedActor(void)
423 {
424   TestApplication application;
425
426   Actor actor = Actor::New();
427   actor.SetSize(100.0f, 100.0f);
428   actor.SetOrientation(Dali::Degree(90.0f), Vector3::ZAXIS);
429   Stage::GetCurrent().Add(actor);
430
431   // Render and notify
432   application.SendNotification();
433   application.Render();
434
435   SignalData data;
436   GestureReceivedFunctor functor(data);
437
438   LongPressGestureDetector detector = LongPressGestureDetector::New();
439   detector.Attach(actor);
440   detector.DetectedSignal().Connect(&application, functor);
441
442   // Do a long press
443   TestGenerateLongPress( application, 5.0f, 5.0f );
444   TestEndLongPress( application, 5.0f, 5.0f);
445   DALI_TEST_EQUALS(true, data.functorCalled, TEST_LOCATION);
446   DALI_TEST_EQUALS(1u, data.receivedGesture.numberOfTouches, TEST_LOCATION);
447   DALI_TEST_EQUALS( Vector2(5.0f, 5.0f), data.receivedGesture.screenPoint, 0.1, TEST_LOCATION);
448
449   // Rotate actor again and render
450   actor.SetOrientation(Dali::Degree(180.0f), Vector3::ZAXIS);
451   application.SendNotification();
452   application.Render();
453
454   // Do another long press, should still receive event
455   data.Reset();
456   TestGenerateLongPress( application, 5.0f, 5.0f );
457   TestEndLongPress( application, 5.0f, 5.0f);
458   DALI_TEST_EQUALS(true, data.functorCalled, TEST_LOCATION);
459   DALI_TEST_EQUALS(1u, data.receivedGesture.numberOfTouches, TEST_LOCATION);
460   DALI_TEST_EQUALS( Vector2(5.0f, 5.0f), data.receivedGesture.screenPoint, 0.1, TEST_LOCATION);
461
462   // Rotate actor again and render
463   actor.SetOrientation(Dali::Degree(90.0f), Vector3::YAXIS);
464   application.SendNotification();
465   application.Render();
466
467   // Do a long press, inside where the actor used to be, Should not receive the event
468   data.Reset();
469   TestGenerateLongPress( application, 70.0f, 70.0f );
470   TestEndLongPress( application, 70.0f, 70.0f);
471   DALI_TEST_EQUALS(false, data.functorCalled, TEST_LOCATION);
472   END_TEST;
473 }
474
475 int UtcDaliLongPressGestureSignalReceptionChildHit(void)
476 {
477   TestApplication application;
478
479   Actor parent = Actor::New();
480   parent.SetSize(100.0f, 100.0f);
481   parent.SetAnchorPoint(AnchorPoint::TOP_LEFT);
482   Stage::GetCurrent().Add(parent);
483
484   // Set child to completely cover parent.
485   // Change rotation of child to be different from parent so that we can check if our local coordinate
486   // conversion of the parent actor is correct.
487   Actor child = Actor::New();
488   child.SetSize(100.0f, 100.0f);
489   child.SetAnchorPoint(AnchorPoint::CENTER);
490   child.SetParentOrigin(ParentOrigin::CENTER);
491   child.SetOrientation(Dali::Degree(90.0f), Vector3::ZAXIS);
492   parent.Add(child);
493
494   TouchEventFunctor touchFunctor;
495   child.TouchedSignal().Connect(&application, touchFunctor);
496
497   // Render and notify
498   application.SendNotification();
499   application.Render();
500
501   SignalData data;
502   GestureReceivedFunctor functor(data);
503
504   LongPressGestureDetector detector = LongPressGestureDetector::New();
505   detector.Attach(parent);
506   detector.DetectedSignal().Connect(&application, functor);
507
508   // Do long press - hits child area but parent should still receive it
509   TestGenerateLongPress( application, 50.0f, 50.0f );
510   TestEndLongPress( application, 50.0f, 50.0f);
511   DALI_TEST_EQUALS(true, data.functorCalled, TEST_LOCATION);
512   DALI_TEST_EQUALS(true, parent == data.pressedActor, TEST_LOCATION);
513   DALI_TEST_EQUALS(Vector2(50.0f, 50.0f), data.receivedGesture.screenPoint, 0.01f, TEST_LOCATION);
514
515   // Attach child and generate same touch points
516   // (Also proves that you can detach and then re-attach another actor)
517   detector.Attach(child);
518   detector.Detach(parent);
519
520   // Do an entire long press, only check finished value
521   data.Reset();
522   TestGenerateLongPress( application, 51.0f, 51.0f );
523   TestEndLongPress( application, 51.0f, 51.0f);
524   DALI_TEST_EQUALS(true, data.functorCalled, TEST_LOCATION);
525   DALI_TEST_EQUALS(true, child == data.pressedActor, TEST_LOCATION);
526   DALI_TEST_EQUALS(Vector2(51.0f, 51.0f), data.receivedGesture.screenPoint, 0.01f, TEST_LOCATION);
527   END_TEST;
528 }
529
530 int UtcDaliLongPressGestureSignalReceptionAttachDetachMany(void)
531 {
532   TestApplication application;
533
534   Actor first = Actor::New();
535   first.SetSize(100.0f, 100.0f);
536   first.SetAnchorPoint(AnchorPoint::TOP_LEFT);
537   Stage::GetCurrent().Add(first);
538
539   Actor second = Actor::New();
540   second.SetSize(100.0f, 100.0f);
541   second.SetX(100.0f);
542   second.SetAnchorPoint(AnchorPoint::TOP_LEFT);
543   Stage::GetCurrent().Add(second);
544
545   // Render and notify
546   application.SendNotification();
547   application.Render();
548
549   SignalData data;
550   GestureReceivedFunctor functor(data);
551
552   LongPressGestureDetector detector = LongPressGestureDetector::New();
553   detector.Attach(first);
554   detector.Attach(second);
555   detector.DetectedSignal().Connect(&application, functor);
556
557   // LongPress within second actor's area
558   TestGenerateLongPress( application, 120.0f, 10.0f );
559   TestEndLongPress( application, 120.0f, 10.0f);
560   DALI_TEST_EQUALS(true, data.functorCalled, TEST_LOCATION);
561   DALI_TEST_EQUALS(true, second == data.pressedActor, TEST_LOCATION);
562
563   // LongPress within first actor's area
564   data.Reset();
565   TestGenerateLongPress( application, 20.0f, 10.0f );
566   TestEndLongPress( application, 20.0f, 10.0f);
567   DALI_TEST_EQUALS(true, data.functorCalled, TEST_LOCATION);
568   DALI_TEST_EQUALS(true, first == data.pressedActor, TEST_LOCATION);
569
570   // Detach the second actor
571   detector.Detach(second);
572
573   // second actor shouldn't receive event
574   data.Reset();
575   TestGenerateLongPress( application, 120.0f, 10.0f );
576   TestEndLongPress( application, 120.0f, 10.0f);
577   DALI_TEST_EQUALS(false, data.functorCalled, TEST_LOCATION);
578
579   // first actor should continue receiving event
580   data.Reset();
581   TestGenerateLongPress( application, 20.0f, 10.0f );
582   TestEndLongPress( application, 20.0f, 10.0f);
583   DALI_TEST_EQUALS(true, data.functorCalled, TEST_LOCATION);
584   END_TEST;
585 }
586
587 int UtcDaliLongPressGestureSignalReceptionActorBecomesUntouchable(void)
588 {
589   TestApplication application;
590
591   Actor actor = Actor::New();
592   actor.SetSize(100.0f, 100.0f);
593   actor.SetAnchorPoint(AnchorPoint::TOP_LEFT);
594   Stage::GetCurrent().Add(actor);
595
596   // Render and notify
597   application.SendNotification();
598   application.Render();
599
600   SignalData data;
601   GestureReceivedFunctor functor(data);
602
603   LongPressGestureDetector detector = LongPressGestureDetector::New();
604   detector.Attach(actor);
605   detector.DetectedSignal().Connect(&application, functor);
606
607   // LongPress in actor's area
608   TestGenerateLongPress( application, 50.0f, 10.0f );
609   TestEndLongPress( application, 50.0f, 10.0f);
610   DALI_TEST_EQUALS(true, data.functorCalled, TEST_LOCATION);
611
612   // Actor becomes invisible - actor should not receive the next long press
613   actor.SetVisible(false);
614
615   // Render and notify
616   application.SendNotification();
617   application.Render();
618
619   // LongPress in the same area, shouldn't receive event
620   data.Reset();
621   TestGenerateLongPress( application, 50.0f, 10.0f );
622   TestEndLongPress( application, 50.0f, 10.0f);
623   DALI_TEST_EQUALS(false, data.functorCalled, TEST_LOCATION);
624   END_TEST;
625 }
626
627 int UtcDaliLongPressGestureSignalReceptionMultipleDetectorsOnActor(void)
628 {
629   TestApplication application;
630
631   Actor actor = Actor::New();
632   actor.SetSize(100.0f, 100.0f);
633   actor.SetAnchorPoint(AnchorPoint::TOP_LEFT);
634   Stage::GetCurrent().Add(actor);
635
636   // Render and notify
637   application.SendNotification();
638   application.Render();
639
640   // Attach actor to one detector
641   SignalData firstData;
642   GestureReceivedFunctor firstFunctor(firstData);
643   LongPressGestureDetector firstDetector = LongPressGestureDetector::New();
644   firstDetector.Attach(actor);
645   firstDetector.DetectedSignal().Connect(&application, firstFunctor);
646
647   // Attach actor to another detector
648   SignalData secondData;
649   GestureReceivedFunctor secondFunctor(secondData);
650   LongPressGestureDetector secondDetector = LongPressGestureDetector::New();
651   secondDetector.Attach(actor);
652   secondDetector.DetectedSignal().Connect(&application, secondFunctor);
653
654   // LongPress in actor's area - both detector's functors should be called
655   TestGenerateLongPress( application, 50.0f, 10.0f );
656   DALI_TEST_EQUALS(true, firstData.functorCalled, TEST_LOCATION);
657   DALI_TEST_EQUALS(true, secondData.functorCalled, TEST_LOCATION);
658   END_TEST;
659 }
660
661 int UtcDaliLongPressGestureSignalReceptionDifferentPossible(void)
662 {
663   TestApplication application;
664
665   Actor actor = Actor::New();
666   actor.SetSize(100.0f, 100.0f);
667   actor.SetAnchorPoint(AnchorPoint::TOP_LEFT);
668   Stage::GetCurrent().Add(actor);
669
670   // Render and notify
671   application.SendNotification();
672   application.Render();
673
674   // Attach actor to detector
675   SignalData data;
676   GestureReceivedFunctor functor( data );
677   LongPressGestureDetector detector = LongPressGestureDetector::New();
678   detector.Attach(actor);
679   detector.DetectedSignal().Connect( &application, functor );
680
681   // LongPress possible in actor's area.
682   TestStartLongPress( application, 50.0f, 10.0f );
683   DALI_TEST_EQUALS(false, data.functorCalled, TEST_LOCATION);
684
685   // Move actor somewhere else
686   actor.SetPosition( 100.0f, 100.0f );
687
688   // Render and notify
689   application.SendNotification();
690   application.Render();
691
692   // Emit Started event, we should not receive the long press.
693   TestTriggerLongPress( application );
694   TestGenerateLongPress( application, 50.0f, 10.0f );
695   DALI_TEST_EQUALS(false, data.functorCalled, TEST_LOCATION);
696
697   // LongPress possible in empty area.
698   TestStartLongPress( application, 50.0f, 10.0f );
699   DALI_TEST_EQUALS(false, data.functorCalled, TEST_LOCATION);
700
701   // Move actor in to the long press position.
702   actor.SetPosition( 0.0f, 0.0f );
703
704   // Render and notify
705   application.SendNotification();
706   application.Render();
707
708   // Emit Started event, we should not receive the long press.
709   TestTriggerLongPress( application );
710   TestEndLongPress( application, 50.0f, 10.0f );
711   DALI_TEST_EQUALS(false, data.functorCalled, TEST_LOCATION);
712
713   // Normal long press in actor's area for completeness.
714   TestGenerateLongPress( application, 50.0f, 10.0f );
715   TestEndLongPress( application, 50.0f, 10.0f);
716   DALI_TEST_EQUALS(true, data.functorCalled, TEST_LOCATION);
717   END_TEST;
718 }
719
720 int UtcDaliLongPressGesturePossibleCancelled(void)
721 {
722   TestApplication application;
723
724   Actor actor = Actor::New();
725   actor.SetSize(100.0f, 100.0f);
726   actor.SetAnchorPoint(AnchorPoint::TOP_LEFT);
727   Stage::GetCurrent().Add(actor);
728
729   // Render and notify
730   application.SendNotification();
731   application.Render();
732
733   // Attach actor to detector
734   SignalData data;
735   GestureReceivedFunctor functor( data );
736   LongPressGestureDetector detector = LongPressGestureDetector::New();
737   detector.Attach(actor);
738   detector.DetectedSignal().Connect( &application, functor );
739
740   // Send a possible followed by a cancel, we should not be signalled
741   TestStartLongPress( application, 50.0f, 10.0f );
742   DALI_TEST_EQUALS(false, data.functorCalled, TEST_LOCATION);
743   TestMovePan( application, Vector2( 50.0f, 10.0f ) );
744   DALI_TEST_EQUALS(false, data.functorCalled, TEST_LOCATION);
745   END_TEST;
746 }
747
748 int UtcDaliLongPressGestureDetachAfterStarted(void)
749 {
750   TestApplication application;
751
752   Actor actor = Actor::New();
753   actor.SetSize(100.0f, 100.0f);
754   actor.SetAnchorPoint(AnchorPoint::TOP_LEFT);
755   Stage::GetCurrent().Add(actor);
756
757   // Render and notify
758   application.SendNotification();
759   application.Render();
760
761   // Attach actor to detector
762   SignalData data;
763   GestureReceivedFunctor functor( data );
764   LongPressGestureDetector detector = LongPressGestureDetector::New();
765   detector.Attach(actor);
766   detector.DetectedSignal().Connect( &application, functor );
767
768   // Emit initial signal
769   TestGenerateLongPress( application, 50.0f, 10.0f );
770   DALI_TEST_EQUALS(true, data.functorCalled, TEST_LOCATION);
771   data.Reset();
772
773   // Detach actor
774   detector.Detach(actor);
775
776   // Emit Finished, no signal
777   TestEndLongPress( application, 50.0f, 10.0f );
778   DALI_TEST_EQUALS(false, data.functorCalled, TEST_LOCATION);
779   END_TEST;
780 }
781
782 int UtcDaliLongPressGestureActorUnstaged(void)
783 {
784   TestApplication application;
785
786   Actor actor = Actor::New();
787   actor.SetSize(100.0f, 100.0f);
788   actor.SetAnchorPoint(AnchorPoint::TOP_LEFT);
789   Stage::GetCurrent().Add(actor);
790
791   // Render and notify
792   application.SendNotification();
793   application.Render();
794
795   // State to remove actor in.
796   Gesture::State stateToUnstage( Gesture::Started );
797
798   // Attach actor to detector
799   SignalData data;
800   UnstageActorFunctor functor( data, stateToUnstage );
801   LongPressGestureDetector detector = LongPressGestureDetector::New();
802   detector.Attach(actor);
803   detector.DetectedSignal().Connect( &application, functor );
804
805   // Emit signals
806   TestGenerateLongPress( application, 50.0f, 10.0f );
807   DALI_TEST_EQUALS(true, data.functorCalled, TEST_LOCATION);
808   data.Reset();
809   TestEndLongPress( application, 50.0f, 10.0f );
810   DALI_TEST_EQUALS(false, data.functorCalled, TEST_LOCATION);
811
812   // Render and notify
813   application.SendNotification();
814   application.Render();
815
816   // Re-add actor to stage
817   Stage::GetCurrent().Add(actor);
818
819   // Render and notify
820   application.SendNotification();
821   application.Render();
822
823   // Change state to Gesture::Continuing to remove
824   stateToUnstage = Gesture::Finished;
825
826   // Emit signals
827   TestGenerateLongPress( application, 50.0f, 10.0f );
828   DALI_TEST_EQUALS(true, data.functorCalled, TEST_LOCATION);
829   data.Reset();
830   TestEndLongPress( application, 50.0f, 10.0f );
831   DALI_TEST_EQUALS(true, data.functorCalled, TEST_LOCATION);
832   tet_result( TET_PASS ); // If we get here then we have handled actor stage removal gracefully.
833   END_TEST;
834 }
835
836 int UtcDaliLongPressGestureActorStagedAndDestroyed(void)
837 {
838   TestApplication application;
839
840   Actor actor = Actor::New();
841   actor.SetSize(100.0f, 100.0f);
842   actor.SetAnchorPoint(AnchorPoint::TOP_LEFT);
843   Stage::GetCurrent().Add(actor);
844
845   // Create and add a second actor so that GestureDetector destruction does not come into play.
846   Actor dummyActor( Actor::New() );
847   dummyActor.SetSize( 100.0f, 100.0f );
848   dummyActor.SetPosition( 100.0f, 100.0f );
849   dummyActor.SetAnchorPoint(AnchorPoint::TOP_LEFT);
850   Stage::GetCurrent().Add(dummyActor);
851
852   // Render and notify
853   application.SendNotification();
854   application.Render();
855
856   // State to remove actor in.
857   Gesture::State stateToUnstage( Gesture::Started );
858
859   // Attach actor to detector
860   SignalData data;
861   UnstageActorFunctor functor( data, stateToUnstage );
862   LongPressGestureDetector detector = LongPressGestureDetector::New();
863   detector.Attach(actor);
864   detector.Attach(dummyActor);
865   detector.DetectedSignal().Connect( &application, functor );
866
867   // Here we are testing a Started actor which is removed in the Started callback, but then added back
868   // before we get a finished state.  As we were removed from the stage, even if we're at the same
869   // position, we should still not be signalled.
870
871   // Emit signals
872   TestGenerateLongPress( application, 50.0f, 10.0f );
873   DALI_TEST_EQUALS(true, data.functorCalled, TEST_LOCATION);
874   data.Reset();
875
876   // Render and notify
877   application.SendNotification();
878   application.Render();
879
880   // Re add to the stage, we should not be signalled
881   Stage::GetCurrent().Add(actor);
882
883   // Render and notify
884   application.SendNotification();
885   application.Render();
886
887   // Continue signal emission
888   TestEndLongPress( application, 50.0f, 10.0f );
889   DALI_TEST_EQUALS(false, data.functorCalled, TEST_LOCATION);
890   data.Reset();
891
892   // Here we delete an actor in started, we should not receive any subsequent signalling.
893
894   // Emit signals
895   TestGenerateLongPress( application, 50.0f, 10.0f );
896   DALI_TEST_EQUALS(true, data.functorCalled, TEST_LOCATION);
897   data.Reset();
898
899   // Render and notify
900   application.SendNotification();
901   application.Render();
902
903   // Delete actor as well
904   actor.Reset();
905
906   // Render and notify
907   application.SendNotification();
908   application.Render();
909
910   // Continue signal emission
911   TestEndLongPress( application, 50.0f, 10.0f );
912   DALI_TEST_EQUALS(false, data.functorCalled, TEST_LOCATION);
913   END_TEST;
914 }
915
916 int UtcDaliLongPressGestureLayerConsumesTouch(void)
917 {
918   TestApplication application;
919
920   Actor actor = Actor::New();
921   actor.SetSize(100.0f, 100.0f);
922   actor.SetAnchorPoint(AnchorPoint::TOP_LEFT);
923   Stage::GetCurrent().Add(actor);
924
925   // Add a detector
926   SignalData data;
927   GestureReceivedFunctor functor(data);
928   LongPressGestureDetector detector = LongPressGestureDetector::New();
929   detector.Attach(actor);
930   detector.DetectedSignal().Connect( &application, functor );
931
932   // Add a layer to overlap the actor
933   Layer layer = Layer::New();
934   layer.SetSize(100.0f, 100.0f);
935   layer.SetAnchorPoint(AnchorPoint::TOP_LEFT);
936   Stage::GetCurrent().Add( layer );
937   layer.RaiseToTop();
938
939   // Render and notify
940   application.SendNotification();
941   application.Render();
942
943   // Emit signals, should receive
944   TestGenerateLongPress( application, 50.0f, 50.0f );
945   TestEndLongPress( application, 50.0f, 50.0f );
946   DALI_TEST_EQUALS(true, data.functorCalled, TEST_LOCATION);
947   data.Reset();
948
949   // Set layer to consume all touch
950   layer.SetTouchConsumed( true );
951
952   // Render and notify
953   application.SendNotification();
954   application.Render();
955
956   // Emit the same signals again, should not receive
957   TestGenerateLongPress( application, 50.0f, 50.0f );
958   TestEndLongPress( application, 50.0f, 50.0f );
959   DALI_TEST_EQUALS(false, data.functorCalled, TEST_LOCATION);
960   data.Reset();
961
962   END_TEST;
963 }
964
965 int UtcDaliLongPressGestureSetMinimumHoldingTime(void)
966 {
967   TestApplication application;
968
969   const uint32_t kMinumumHolding1 = 5000;
970   const uint32_t kMinumumHolding2 = 3000;
971
972   Integration::SetLongPressMinimumHoldingTime( kMinumumHolding1 );
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   SignalData data;
984   GestureReceivedFunctor functor( data );
985
986   LongPressGestureDetector detector = LongPressGestureDetector::New();
987   detector.Attach(actor);
988   detector.DetectedSignal().Connect(&application, functor);
989
990   DALI_TEST_EQUALS( DevelLongPressGestureDetector::GetMinimumHoldingTime( detector ), kMinumumHolding1, TEST_LOCATION );
991
992   Integration::SetLongPressMinimumHoldingTime( kMinumumHolding2 );
993   DALI_TEST_EQUALS( DevelLongPressGestureDetector::GetMinimumHoldingTime( detector ), kMinumumHolding2, TEST_LOCATION );
994
995   END_TEST;
996 }