Revert "[Tizen] Appendix log for ttrace + Print keycode and timestamp"
[platform/core/uifw/dali-core.git] / automated-tests / src / dali / utc-Dali-LongPressGestureDetector.cpp
1 /*
2  * Copyright (c) 2022 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/devel-api/events/long-press-gesture-detector-devel.h>
21 #include <dali/integration-api/events/touch-event-integ.h>
22 #include <dali/integration-api/input-options.h>
23 #include <dali/integration-api/render-task-list-integ.h>
24 #include <dali/public-api/dali-core.h>
25 #include <stdlib.h>
26 #include <test-touch-event-utils.h>
27
28 #include <iostream>
29
30 using namespace Dali;
31
32 void utc_dali_long_press_gesture_detector_startup(void)
33 {
34   test_return_value = TET_UNDEF;
35 }
36
37 void utc_dali_long_press_gesture_detector_cleanup(void)
38 {
39   test_return_value = TET_PASS;
40 }
41
42 ///////////////////////////////////////////////////////////////////////////////
43 namespace
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(),
52     pressedActor()
53   {
54   }
55
56   void Reset()
57   {
58     functorCalled     = false;
59     voidFunctorCalled = false;
60
61     receivedGesture.Reset();
62
63     pressedActor.Reset();
64   }
65
66   bool             functorCalled;
67   bool             voidFunctorCalled;
68   LongPressGesture receivedGesture;
69   Actor            pressedActor;
70 };
71
72 // Functor that sets the data when called
73 struct GestureReceivedFunctor
74 {
75   GestureReceivedFunctor(SignalData& data)
76   : signalData(data)
77   {
78   }
79
80   void operator()(Actor actor, const LongPressGesture& longPress)
81   {
82     signalData.functorCalled   = true;
83     signalData.receivedGesture = longPress;
84     signalData.pressedActor    = actor;
85   }
86
87   void operator()()
88   {
89     signalData.voidFunctorCalled = true;
90   }
91
92   SignalData& signalData;
93 };
94
95 // Functor that removes the gestured actor from stage
96 struct UnstageActorFunctor : public GestureReceivedFunctor
97 {
98   UnstageActorFunctor(SignalData& data, GestureState& stateToUnstage, Integration::Scene scene)
99   : GestureReceivedFunctor(data),
100     stateToUnstage(stateToUnstage),
101     scene(scene)
102   {
103   }
104
105   void operator()(Actor actor, const LongPressGesture& longPress)
106   {
107     GestureReceivedFunctor::operator()(actor, longPress);
108
109     if(longPress.GetState() == stateToUnstage)
110     {
111       scene.Remove(actor);
112     }
113   }
114
115   GestureState&      stateToUnstage;
116   Integration::Scene scene;
117 };
118
119 // Functor for receiving a touch event
120 struct TouchEventFunctor
121 {
122   bool operator()(Actor actor, Dali::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 } // namespace
135
136 ///////////////////////////////////////////////////////////////////////////////
137
138 // Positive test case for a method
139 int UtcDaliLongPressGestureDetectorConstructorP(void)
140 {
141   TestApplication application;
142
143   LongPressGestureDetector detector;
144   DALI_TEST_CHECK(!detector);
145   END_TEST;
146 }
147
148 int UtcDaliLongPressGestureDetectorCopyConstructorP(void)
149 {
150   TestApplication application;
151
152   LongPressGestureDetector detector = LongPressGestureDetector::New();
153
154   LongPressGestureDetector copy(detector);
155   DALI_TEST_CHECK(detector);
156   END_TEST;
157 }
158
159 int UtcDaliLongPressGestureDetectorAssignmentOperatorP(void)
160 {
161   TestApplication application;
162
163   LongPressGestureDetector detector;
164   detector = LongPressGestureDetector::New();
165
166   LongPressGestureDetector copy;
167   copy = detector;
168   DALI_TEST_CHECK(detector);
169
170   DALI_TEST_CHECK(detector == copy);
171   END_TEST;
172 }
173
174 int UtcDaliLongPressGestureDetectorMoveConstructorP(void)
175 {
176   TestApplication application;
177
178   LongPressGestureDetector detector = LongPressGestureDetector::New();
179   DALI_TEST_CHECK(detector);
180
181   LongPressGestureDetector moved = std::move(detector);
182   DALI_TEST_CHECK(moved);
183   DALI_TEST_CHECK(!detector);
184   END_TEST;
185 }
186
187 int UtcDaliLongPressGestureDetectorMoveAssignmentOperatorP(void)
188 {
189   TestApplication application;
190
191   LongPressGestureDetector detector;
192   detector = LongPressGestureDetector::New();
193   DALI_TEST_CHECK(detector);
194
195   LongPressGestureDetector moved;
196   moved = std::move(detector);
197   DALI_TEST_CHECK(moved);
198   DALI_TEST_CHECK(!detector);
199   END_TEST;
200 }
201
202 int UtcDaliLongPressGestureDetectorNew(void)
203 {
204   TestApplication application;
205
206   LongPressGestureDetector detector = LongPressGestureDetector::New();
207   DALI_TEST_CHECK(detector);
208   DALI_TEST_EQUALS(1u, detector.GetMinimumTouchesRequired(), TEST_LOCATION);
209   DALI_TEST_EQUALS(1u, detector.GetMaximumTouchesRequired(), TEST_LOCATION);
210
211   LongPressGestureDetector detector2 = LongPressGestureDetector::New(5u);
212   DALI_TEST_CHECK(detector2);
213   DALI_TEST_EQUALS(5u, detector2.GetMinimumTouchesRequired(), TEST_LOCATION);
214   DALI_TEST_EQUALS(5u, detector2.GetMaximumTouchesRequired(), TEST_LOCATION);
215
216   LongPressGestureDetector detector3 = LongPressGestureDetector::New(5u, 7u);
217   DALI_TEST_CHECK(detector2);
218   DALI_TEST_EQUALS(5u, detector3.GetMinimumTouchesRequired(), TEST_LOCATION);
219   DALI_TEST_EQUALS(7u, detector3.GetMaximumTouchesRequired(), TEST_LOCATION);
220
221   //Scoped test to test destructor
222   {
223     LongPressGestureDetector detector4 = LongPressGestureDetector::New();
224     DALI_TEST_CHECK(detector4);
225   }
226
227   // Attach an actor and emit a touch event on the actor to ensure complete line coverage
228   Actor actor = Actor::New();
229   actor.SetProperty(Actor::Property::SIZE, Vector2(100.0f, 100.0f));
230   actor.SetProperty(Actor::Property::ANCHOR_POINT, AnchorPoint::TOP_LEFT);
231   application.GetScene().Add(actor);
232
233   // Render and notify
234   application.SendNotification();
235   application.Render();
236
237   detector.Attach(actor);
238
239   TouchEventFunctor touchFunctor;
240   actor.TouchedSignal().Connect(&application, touchFunctor);
241
242   Integration::TouchEvent touchEvent(1);
243   Integration::Point      point;
244   point.SetDeviceId(1);
245   point.SetState(PointState::DOWN);
246   point.SetScreenPosition(Vector2(20.0f, 20.0f));
247   touchEvent.AddPoint(point);
248   application.ProcessEvent(touchEvent);
249
250   // Render and notify
251   application.SendNotification();
252   application.Render();
253
254   END_TEST;
255 }
256
257 int UtcDaliLongPressGestureDetectorDownCast(void)
258 {
259   TestApplication application;
260   tet_infoline("Testing Dali::LongPressGestureDetector::DownCast()");
261
262   LongPressGestureDetector detector = LongPressGestureDetector::New();
263
264   BaseHandle object(detector);
265
266   LongPressGestureDetector detector2 = LongPressGestureDetector::DownCast(object);
267   DALI_TEST_CHECK(detector2);
268
269   LongPressGestureDetector detector3 = DownCast<LongPressGestureDetector>(object);
270   DALI_TEST_CHECK(detector3);
271
272   BaseHandle               unInitializedObject;
273   LongPressGestureDetector detector4 = LongPressGestureDetector::DownCast(unInitializedObject);
274   DALI_TEST_CHECK(!detector4);
275
276   LongPressGestureDetector detector5 = DownCast<LongPressGestureDetector>(unInitializedObject);
277   DALI_TEST_CHECK(!detector5);
278
279   GestureDetector          detector6 = LongPressGestureDetector::New();
280   LongPressGestureDetector detector7 = LongPressGestureDetector::DownCast(detector6);
281   DALI_TEST_CHECK(detector7);
282   END_TEST;
283 }
284
285 int UtcDaliLongPressGestureGetMinimumTouchesRequired(void)
286 {
287   TestApplication application;
288
289   LongPressGestureDetector detector = LongPressGestureDetector::New();
290   DALI_TEST_EQUALS(1u, detector.GetMinimumTouchesRequired(), TEST_LOCATION);
291   END_TEST;
292 }
293
294 int UtcDaliLongPressGestureGetMaximumTouchesRequired(void)
295 {
296   TestApplication application;
297
298   LongPressGestureDetector detector = LongPressGestureDetector::New();
299   DALI_TEST_EQUALS(1u, detector.GetMaximumTouchesRequired(), TEST_LOCATION);
300   END_TEST;
301 }
302
303 int UtcDaliLongPressGestureSignalReceptionNegative(void)
304 {
305   TestApplication application;
306
307   Actor actor = Actor::New();
308   actor.SetProperty(Actor::Property::SIZE, Vector2(100.0f, 100.0f));
309   actor.SetProperty(Actor::Property::ANCHOR_POINT, AnchorPoint::TOP_LEFT);
310   application.GetScene().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 outside actor's area
324   TestGenerateLongPress(application, 112.0f, 112.0f);
325   TestEndLongPress(application, 112.0f, 112.0f);
326
327   DALI_TEST_EQUALS(false, data.functorCalled, TEST_LOCATION);
328   END_TEST;
329 }
330
331 int UtcDaliLongPressGestureSignalReceptionPositive(void)
332 {
333   TestApplication application;
334
335   Actor actor = Actor::New();
336   actor.SetProperty(Actor::Property::SIZE, Vector2(100.0f, 100.0f));
337   actor.SetProperty(Actor::Property::ANCHOR_POINT, AnchorPoint::TOP_LEFT);
338   application.GetScene().Add(actor);
339
340   // Render and notify
341   application.SendNotification();
342   application.Render();
343
344   SignalData             data;
345   GestureReceivedFunctor functor(data);
346
347   LongPressGestureDetector detector = LongPressGestureDetector::New();
348   detector.Attach(actor);
349   detector.DetectedSignal().Connect(&application, functor);
350
351   // Do a long press inside actor's area
352   TestGenerateLongPress(application, 50.0f, 50.0f);
353   DALI_TEST_EQUALS(true, data.functorCalled, TEST_LOCATION);
354   DALI_TEST_EQUALS(1u, data.receivedGesture.GetNumberOfTouches(), TEST_LOCATION);
355   DALI_TEST_EQUALS(Vector2(50.0f, 50.0f), data.receivedGesture.GetLocalPoint(), 0.1, TEST_LOCATION);
356   TestEndLongPress(application, 50.0f, 50.0f);
357   END_TEST;
358 }
359
360 int UtcDaliLongPressGestureSignalReceptionDetach(void)
361 {
362   TestApplication application;
363
364   Actor actor = Actor::New();
365   actor.SetProperty(Actor::Property::SIZE, Vector2(100.0f, 100.0f));
366   actor.SetProperty(Actor::Property::ANCHOR_POINT, AnchorPoint::TOP_LEFT);
367   application.GetScene().Add(actor);
368
369   // Render and notify
370   application.SendNotification();
371   application.Render();
372
373   SignalData             data;
374   GestureReceivedFunctor functor(data);
375
376   LongPressGestureDetector detector = LongPressGestureDetector::New();
377   detector.Attach(actor);
378   detector.DetectedSignal().Connect(&application, functor);
379
380   // Start long press within the actor's area
381   TestGenerateLongPress(application, 20.0f, 20.0f);
382   DALI_TEST_EQUALS(true, data.functorCalled, TEST_LOCATION);
383   DALI_TEST_EQUALS(1u, data.receivedGesture.GetNumberOfTouches(), TEST_LOCATION);
384   DALI_TEST_EQUALS(Vector2(20.0f, 20.0f), data.receivedGesture.GetLocalPoint(), 0.1, TEST_LOCATION);
385   TestEndLongPress(application, 20.0f, 20.0f);
386
387   // repeat the long press within the actor's area - we should still receive the signal
388   data.Reset();
389   TestGenerateLongPress(application, 50.0f, 50.0f);
390   DALI_TEST_EQUALS(true, data.functorCalled, TEST_LOCATION);
391   DALI_TEST_EQUALS(1u, data.receivedGesture.GetNumberOfTouches(), TEST_LOCATION);
392   DALI_TEST_EQUALS(Vector2(50.0f, 50.0f), data.receivedGesture.GetLocalPoint(), 0.1, TEST_LOCATION);
393   TestEndLongPress(application, 50.0f, 50.0f);
394
395   // Detach actor
396   detector.DetachAll();
397
398   // Ensure we are no longer signalled
399   data.Reset();
400   TestGenerateLongPress(application, 20.0f, 20.0f);
401   DALI_TEST_EQUALS(false, data.functorCalled, TEST_LOCATION);
402   TestEndLongPress(application, 50.0f, 50.0f);
403   DALI_TEST_EQUALS(false, data.functorCalled, TEST_LOCATION);
404   END_TEST;
405 }
406
407 int UtcDaliLongPressGestureSignalReceptionActorDestroyedDuringLongPress(void)
408 {
409   TestApplication application;
410
411   SignalData             data;
412   GestureReceivedFunctor functor(data);
413
414   LongPressGestureDetector detector = LongPressGestureDetector::New();
415   detector.DetectedSignal().Connect(&application, functor);
416
417   // Actor lifetime is scoped
418   {
419     Actor actor = Actor::New();
420     actor.SetProperty(Actor::Property::SIZE, Vector2(100.0f, 100.0f));
421     actor.SetProperty(Actor::Property::ANCHOR_POINT, AnchorPoint::TOP_LEFT);
422     application.GetScene().Add(actor);
423
424     // Render and notify
425     application.SendNotification();
426     application.Render();
427
428     detector.Attach(actor);
429
430     // Start long press within the actor's area
431     TestGenerateLongPress(application, 20.0f, 20.0f);
432     DALI_TEST_EQUALS(true, data.functorCalled, TEST_LOCATION);
433
434     // Remove the actor from stage and reset the data
435     application.GetScene().Remove(actor);
436
437     // Render and notify
438     application.SendNotification();
439     application.Render();
440   }
441
442   // Actor should now have been destroyed
443
444   data.Reset();
445   TestEndLongPress(application, 20.0f, 20.0f);
446   DALI_TEST_EQUALS(false, data.functorCalled, TEST_LOCATION);
447   END_TEST;
448 }
449
450 int UtcDaliLongPressGestureSignalReceptionRotatedActor(void)
451 {
452   TestApplication application;
453
454   Actor actor = Actor::New();
455   actor.SetProperty(Actor::Property::SIZE, Vector2(100.0f, 100.0f));
456   actor.SetProperty(Actor::Property::ORIENTATION, Quaternion(Dali::Degree(90.0f), Vector3::ZAXIS));
457   application.GetScene().Add(actor);
458
459   // Render and notify
460   application.SendNotification();
461   application.Render();
462
463   SignalData             data;
464   GestureReceivedFunctor functor(data);
465
466   LongPressGestureDetector detector = LongPressGestureDetector::New();
467   detector.Attach(actor);
468   detector.DetectedSignal().Connect(&application, functor);
469
470   // Do a long press
471   TestGenerateLongPress(application, 5.0f, 5.0f);
472   TestEndLongPress(application, 5.0f, 5.0f);
473   DALI_TEST_EQUALS(true, data.functorCalled, TEST_LOCATION);
474   DALI_TEST_EQUALS(1u, data.receivedGesture.GetNumberOfTouches(), TEST_LOCATION);
475   DALI_TEST_EQUALS(Vector2(5.0f, 5.0f), data.receivedGesture.GetScreenPoint(), 0.1, TEST_LOCATION);
476
477   // Rotate actor again and render
478   actor.SetProperty(Actor::Property::ORIENTATION, Quaternion(Dali::Degree(180.0f), Vector3::ZAXIS));
479   application.SendNotification();
480   application.Render();
481
482   // Do another long press, should still receive event
483   data.Reset();
484   TestGenerateLongPress(application, 5.0f, 5.0f);
485   TestEndLongPress(application, 5.0f, 5.0f);
486   DALI_TEST_EQUALS(true, data.functorCalled, TEST_LOCATION);
487   DALI_TEST_EQUALS(1u, data.receivedGesture.GetNumberOfTouches(), TEST_LOCATION);
488   DALI_TEST_EQUALS(Vector2(5.0f, 5.0f), data.receivedGesture.GetScreenPoint(), 0.1, TEST_LOCATION);
489
490   // Rotate actor again and render
491   actor.SetProperty(Actor::Property::ORIENTATION, Quaternion(Dali::Degree(90.0f), Vector3::YAXIS));
492   application.SendNotification();
493   application.Render();
494
495   // Do a long press, inside where the actor used to be, Should not receive the event
496   data.Reset();
497   TestGenerateLongPress(application, 70.0f, 70.0f);
498   TestEndLongPress(application, 70.0f, 70.0f);
499   DALI_TEST_EQUALS(false, data.functorCalled, TEST_LOCATION);
500   END_TEST;
501 }
502
503 int UtcDaliLongPressGestureSignalReceptionChildHit(void)
504 {
505   TestApplication application;
506
507   Actor parent = Actor::New();
508   parent.SetProperty(Actor::Property::SIZE, Vector2(100.0f, 100.0f));
509   parent.SetProperty(Actor::Property::ANCHOR_POINT, AnchorPoint::TOP_LEFT);
510   application.GetScene().Add(parent);
511
512   // Set child to completely cover parent.
513   // Change rotation of child to be different from parent so that we can check if our local coordinate
514   // conversion of the parent actor is correct.
515   Actor child = Actor::New();
516   child.SetProperty(Actor::Property::SIZE, Vector2(100.0f, 100.0f));
517   child.SetProperty(Actor::Property::ANCHOR_POINT, AnchorPoint::CENTER);
518   child.SetProperty(Actor::Property::PARENT_ORIGIN, ParentOrigin::CENTER);
519   child.SetProperty(Actor::Property::ORIENTATION, Quaternion(Dali::Degree(90.0f), Vector3::ZAXIS));
520   parent.Add(child);
521
522   // Render and notify
523   application.SendNotification();
524   application.Render();
525
526   SignalData             data;
527   GestureReceivedFunctor functor(data);
528
529   LongPressGestureDetector detector = LongPressGestureDetector::New();
530   detector.Attach(parent);
531   detector.DetectedSignal().Connect(&application, functor);
532
533   // Do long press - hits child area but parent should still receive it
534   TestGenerateLongPress(application, 50.0f, 50.0f);
535   TestEndLongPress(application, 50.0f, 50.0f);
536   DALI_TEST_EQUALS(true, data.functorCalled, TEST_LOCATION);
537   DALI_TEST_EQUALS(true, parent == data.pressedActor, TEST_LOCATION);
538   DALI_TEST_EQUALS(Vector2(50.0f, 50.0f), data.receivedGesture.GetScreenPoint(), 0.01f, TEST_LOCATION);
539
540   // Attach child and generate same touch points
541   // (Also proves that you can detach and then re-attach another actor)
542   detector.Attach(child);
543   detector.Detach(parent);
544
545   // Do an entire long press, only check finished value
546   data.Reset();
547   TestGenerateLongPress(application, 51.0f, 51.0f);
548   TestEndLongPress(application, 51.0f, 51.0f);
549   DALI_TEST_EQUALS(true, data.functorCalled, TEST_LOCATION);
550   DALI_TEST_EQUALS(true, child == data.pressedActor, TEST_LOCATION);
551   DALI_TEST_EQUALS(Vector2(51.0f, 51.0f), data.receivedGesture.GetScreenPoint(), 0.01f, TEST_LOCATION);
552   END_TEST;
553 }
554
555 int UtcDaliLongPressGestureSignalReceptionAttachDetachMany(void)
556 {
557   TestApplication application;
558
559   Actor first = Actor::New();
560   first.SetProperty(Actor::Property::SIZE, Vector2(100.0f, 100.0f));
561   first.SetProperty(Actor::Property::ANCHOR_POINT, AnchorPoint::TOP_LEFT);
562   application.GetScene().Add(first);
563
564   Actor second = Actor::New();
565   second.SetProperty(Actor::Property::SIZE, Vector2(100.0f, 100.0f));
566   second.SetProperty(Actor::Property::POSITION_X, 100.0f);
567   second.SetProperty(Actor::Property::ANCHOR_POINT, AnchorPoint::TOP_LEFT);
568   application.GetScene().Add(second);
569
570   // Render and notify
571   application.SendNotification();
572   application.Render();
573
574   SignalData             data;
575   GestureReceivedFunctor functor(data);
576
577   LongPressGestureDetector detector = LongPressGestureDetector::New();
578   detector.Attach(first);
579   detector.Attach(second);
580   detector.DetectedSignal().Connect(&application, functor);
581
582   // LongPress within second actor's area
583   TestGenerateLongPress(application, 120.0f, 10.0f);
584   TestEndLongPress(application, 120.0f, 10.0f);
585   DALI_TEST_EQUALS(true, data.functorCalled, TEST_LOCATION);
586   DALI_TEST_EQUALS(true, second == data.pressedActor, TEST_LOCATION);
587
588   // LongPress within first actor's area
589   data.Reset();
590   TestGenerateLongPress(application, 20.0f, 10.0f);
591   TestEndLongPress(application, 20.0f, 10.0f);
592   DALI_TEST_EQUALS(true, data.functorCalled, TEST_LOCATION);
593   DALI_TEST_EQUALS(true, first == data.pressedActor, TEST_LOCATION);
594
595   // Detach the second actor
596   detector.Detach(second);
597
598   // second actor shouldn't receive event
599   data.Reset();
600   TestGenerateLongPress(application, 120.0f, 10.0f);
601   TestEndLongPress(application, 120.0f, 10.0f);
602   DALI_TEST_EQUALS(false, data.functorCalled, TEST_LOCATION);
603
604   // first actor should continue receiving event
605   data.Reset();
606   TestGenerateLongPress(application, 20.0f, 10.0f);
607   TestEndLongPress(application, 20.0f, 10.0f);
608   DALI_TEST_EQUALS(true, data.functorCalled, TEST_LOCATION);
609   END_TEST;
610 }
611
612 int UtcDaliLongPressGestureSignalReceptionActorBecomesUntouchable(void)
613 {
614   TestApplication application;
615
616   Actor actor = Actor::New();
617   actor.SetProperty(Actor::Property::SIZE, Vector2(100.0f, 100.0f));
618   actor.SetProperty(Actor::Property::ANCHOR_POINT, AnchorPoint::TOP_LEFT);
619   application.GetScene().Add(actor);
620
621   // Render and notify
622   application.SendNotification();
623   application.Render();
624
625   SignalData             data;
626   GestureReceivedFunctor functor(data);
627
628   LongPressGestureDetector detector = LongPressGestureDetector::New();
629   detector.Attach(actor);
630   detector.DetectedSignal().Connect(&application, functor);
631
632   // LongPress in actor's area
633   TestGenerateLongPress(application, 50.0f, 10.0f);
634   TestEndLongPress(application, 50.0f, 10.0f);
635   DALI_TEST_EQUALS(true, data.functorCalled, TEST_LOCATION);
636
637   // Actor becomes invisible - actor should not receive the next long press
638   actor.SetProperty(Actor::Property::VISIBLE, false);
639
640   // Render and notify
641   application.SendNotification();
642   application.Render();
643
644   // LongPress in the same area, shouldn't receive event
645   data.Reset();
646   TestGenerateLongPress(application, 50.0f, 10.0f);
647   TestEndLongPress(application, 50.0f, 10.0f);
648   DALI_TEST_EQUALS(false, data.functorCalled, TEST_LOCATION);
649   END_TEST;
650 }
651
652 int UtcDaliLongPressGestureSignalReceptionMultipleDetectorsOnActor(void)
653 {
654   TestApplication application;
655
656   Actor actor = Actor::New();
657   actor.SetProperty(Actor::Property::SIZE, Vector2(100.0f, 100.0f));
658   actor.SetProperty(Actor::Property::ANCHOR_POINT, AnchorPoint::TOP_LEFT);
659   application.GetScene().Add(actor);
660
661   // Render and notify
662   application.SendNotification();
663   application.Render();
664
665   // Attach actor to one detector
666   SignalData               firstData;
667   GestureReceivedFunctor   firstFunctor(firstData);
668   LongPressGestureDetector firstDetector = LongPressGestureDetector::New();
669   firstDetector.Attach(actor);
670   firstDetector.DetectedSignal().Connect(&application, firstFunctor);
671
672   // Attach actor to another detector
673   SignalData               secondData;
674   GestureReceivedFunctor   secondFunctor(secondData);
675   LongPressGestureDetector secondDetector = LongPressGestureDetector::New();
676   secondDetector.Attach(actor);
677   secondDetector.DetectedSignal().Connect(&application, secondFunctor);
678
679   // LongPress in actor's area - both detector's functors should be called
680   TestGenerateLongPress(application, 50.0f, 10.0f);
681   DALI_TEST_EQUALS(true, firstData.functorCalled, TEST_LOCATION);
682   DALI_TEST_EQUALS(true, secondData.functorCalled, TEST_LOCATION);
683   END_TEST;
684 }
685
686 int UtcDaliLongPressGestureSignalReceptionDifferentPossible(void)
687 {
688   TestApplication application;
689
690   Actor actor = Actor::New();
691   actor.SetProperty(Actor::Property::SIZE, Vector2(100.0f, 100.0f));
692   actor.SetProperty(Actor::Property::ANCHOR_POINT, AnchorPoint::TOP_LEFT);
693   application.GetScene().Add(actor);
694
695   // Render and notify
696   application.SendNotification();
697   application.Render();
698
699   // Attach actor to detector
700   SignalData               data;
701   GestureReceivedFunctor   functor(data);
702   LongPressGestureDetector detector = LongPressGestureDetector::New();
703   detector.Attach(actor);
704   detector.DetectedSignal().Connect(&application, functor);
705
706   // LongPress possible in actor's area.
707   TestStartLongPress(application, 50.0f, 10.0f);
708   DALI_TEST_EQUALS(false, data.functorCalled, TEST_LOCATION);
709
710   // Move actor somewhere else
711   actor.SetProperty(Actor::Property::POSITION, Vector2(100.0f, 100.0f));
712
713   // Render and notify
714   application.SendNotification();
715   application.Render();
716
717   // Emit Started event, we should not receive the long press.
718   TestTriggerLongPress(application);
719   TestGenerateLongPress(application, 50.0f, 10.0f);
720   DALI_TEST_EQUALS(false, data.functorCalled, TEST_LOCATION);
721
722   // LongPress possible in empty area.
723   TestStartLongPress(application, 50.0f, 10.0f);
724   DALI_TEST_EQUALS(false, data.functorCalled, TEST_LOCATION);
725
726   // Move actor in to the long press position.
727   actor.SetProperty(Actor::Property::POSITION, Vector2(0.0f, 0.0f));
728
729   // Render and notify
730   application.SendNotification();
731   application.Render();
732
733   // Emit STARTED event, we should not receive the long press.
734   TestTriggerLongPress(application);
735   TestEndLongPress(application, 50.0f, 10.0f);
736   DALI_TEST_EQUALS(false, data.functorCalled, TEST_LOCATION);
737
738   // Normal long press in actor's area for completeness.
739   TestGenerateLongPress(application, 50.0f, 10.0f);
740   TestEndLongPress(application, 50.0f, 10.0f);
741   DALI_TEST_EQUALS(true, data.functorCalled, TEST_LOCATION);
742   END_TEST;
743 }
744
745 int UtcDaliLongPressGesturePossibleCancelled(void)
746 {
747   TestApplication application;
748
749   Actor actor = Actor::New();
750   actor.SetProperty(Actor::Property::SIZE, Vector2(100.0f, 100.0f));
751   actor.SetProperty(Actor::Property::ANCHOR_POINT, AnchorPoint::TOP_LEFT);
752   application.GetScene().Add(actor);
753
754   // Render and notify
755   application.SendNotification();
756   application.Render();
757
758   // Attach actor to detector
759   SignalData               data;
760   GestureReceivedFunctor   functor(data);
761   LongPressGestureDetector detector = LongPressGestureDetector::New();
762   detector.Attach(actor);
763   detector.DetectedSignal().Connect(&application, functor);
764
765   // Send a possible followed by a cancel, we should not be signalled
766   TestStartLongPress(application, 50.0f, 10.0f);
767   DALI_TEST_EQUALS(false, data.functorCalled, TEST_LOCATION);
768   TestMovePan(application, Vector2(50.0f, 10.0f));
769   DALI_TEST_EQUALS(false, data.functorCalled, TEST_LOCATION);
770   END_TEST;
771 }
772
773 int UtcDaliLongPressGestureDetachAfterStarted(void)
774 {
775   TestApplication application;
776
777   Actor actor = Actor::New();
778   actor.SetProperty(Actor::Property::SIZE, Vector2(100.0f, 100.0f));
779   actor.SetProperty(Actor::Property::ANCHOR_POINT, AnchorPoint::TOP_LEFT);
780   application.GetScene().Add(actor);
781
782   // Render and notify
783   application.SendNotification();
784   application.Render();
785
786   // Attach actor to detector
787   SignalData               data;
788   GestureReceivedFunctor   functor(data);
789   LongPressGestureDetector detector = LongPressGestureDetector::New();
790   detector.Attach(actor);
791   detector.DetectedSignal().Connect(&application, functor);
792
793   // Emit initial signal
794   TestGenerateLongPress(application, 50.0f, 10.0f);
795   DALI_TEST_EQUALS(true, data.functorCalled, TEST_LOCATION);
796   data.Reset();
797
798   // Detach actor
799   detector.Detach(actor);
800
801   // Emit FINISHED, no signal
802   TestEndLongPress(application, 50.0f, 10.0f);
803   DALI_TEST_EQUALS(false, data.functorCalled, TEST_LOCATION);
804   END_TEST;
805 }
806
807 int UtcDaliLongPressGestureActorUnstaged(void)
808 {
809   TestApplication application;
810
811   Actor actor = Actor::New();
812   actor.SetProperty(Actor::Property::SIZE, Vector2(100.0f, 100.0f));
813   actor.SetProperty(Actor::Property::ANCHOR_POINT, AnchorPoint::TOP_LEFT);
814   application.GetScene().Add(actor);
815
816   // Render and notify
817   application.SendNotification();
818   application.Render();
819
820   // State to remove actor in.
821   GestureState stateToUnstage(GestureState::STARTED);
822
823   // Attach actor to detector
824   SignalData               data;
825   UnstageActorFunctor      functor(data, stateToUnstage, application.GetScene());
826   LongPressGestureDetector detector = LongPressGestureDetector::New();
827   detector.Attach(actor);
828   detector.DetectedSignal().Connect(&application, functor);
829
830   // Emit signals
831   TestGenerateLongPress(application, 50.0f, 10.0f);
832   DALI_TEST_EQUALS(true, data.functorCalled, TEST_LOCATION);
833   data.Reset();
834   TestEndLongPress(application, 50.0f, 10.0f);
835   DALI_TEST_EQUALS(false, data.functorCalled, TEST_LOCATION);
836
837   // Render and notify
838   application.SendNotification();
839   application.Render();
840
841   // Re-add actor to stage
842   application.GetScene().Add(actor);
843
844   // Render and notify
845   application.SendNotification();
846   application.Render();
847
848   // Change state to GestureState::CONTINUING to remove
849   stateToUnstage = GestureState::FINISHED;
850
851   // Emit signals
852   TestGenerateLongPress(application, 50.0f, 10.0f);
853   DALI_TEST_EQUALS(true, data.functorCalled, TEST_LOCATION);
854   data.Reset();
855   TestEndLongPress(application, 50.0f, 10.0f);
856   DALI_TEST_EQUALS(true, data.functorCalled, TEST_LOCATION);
857   tet_result(TET_PASS); // If we get here then we have handled actor stage removal gracefully.
858   END_TEST;
859 }
860
861 int UtcDaliLongPressGestureActorStagedAndDestroyed(void)
862 {
863   TestApplication application;
864
865   Actor actor = Actor::New();
866   actor.SetProperty(Actor::Property::SIZE, Vector2(100.0f, 100.0f));
867   actor.SetProperty(Actor::Property::ANCHOR_POINT, AnchorPoint::TOP_LEFT);
868   application.GetScene().Add(actor);
869
870   // Create and add a second actor so that GestureDetector destruction does not come into play.
871   Actor dummyActor(Actor::New());
872   dummyActor.SetProperty(Actor::Property::SIZE, Vector2(100.0f, 100.0f));
873   dummyActor.SetProperty(Actor::Property::POSITION, Vector2(100.0f, 100.0f));
874   dummyActor.SetProperty(Actor::Property::ANCHOR_POINT, AnchorPoint::TOP_LEFT);
875   application.GetScene().Add(dummyActor);
876
877   // Render and notify
878   application.SendNotification();
879   application.Render();
880
881   // State to remove actor in.
882   GestureState stateToUnstage(GestureState::STARTED);
883
884   // Attach actor to detector
885   SignalData               data;
886   UnstageActorFunctor      functor(data, stateToUnstage, application.GetScene());
887   LongPressGestureDetector detector = LongPressGestureDetector::New();
888   detector.Attach(actor);
889   detector.Attach(dummyActor);
890   detector.DetectedSignal().Connect(&application, functor);
891
892   // Here we are testing a STARTED actor which is removed in the STARTED callback, but then added back
893   // before we get a finished state.  As we were removed from the stage, even if we're at the same
894   // position, we should still not be signalled.
895
896   // Emit signals
897   TestGenerateLongPress(application, 50.0f, 10.0f);
898   DALI_TEST_EQUALS(true, data.functorCalled, TEST_LOCATION);
899   data.Reset();
900
901   // Render and notify
902   application.SendNotification();
903   application.Render();
904
905   // Re add to the stage, we should not be signalled
906   application.GetScene().Add(actor);
907
908   // Render and notify
909   application.SendNotification();
910   application.Render();
911
912   // Continue signal emission
913   TestEndLongPress(application, 50.0f, 10.0f);
914   DALI_TEST_EQUALS(false, data.functorCalled, TEST_LOCATION);
915   data.Reset();
916
917   // Here we delete an actor in started, we should not receive any subsequent signalling.
918
919   // Emit signals
920   TestGenerateLongPress(application, 50.0f, 10.0f);
921   DALI_TEST_EQUALS(true, data.functorCalled, TEST_LOCATION);
922   data.Reset();
923
924   // Render and notify
925   application.SendNotification();
926   application.Render();
927
928   // Delete actor as well
929   actor.Reset();
930
931   // Render and notify
932   application.SendNotification();
933   application.Render();
934
935   // Continue signal emission
936   TestEndLongPress(application, 50.0f, 10.0f);
937   DALI_TEST_EQUALS(false, data.functorCalled, TEST_LOCATION);
938   END_TEST;
939 }
940
941 int UtcDaliLongPressGestureLayerConsumesTouch(void)
942 {
943   TestApplication application;
944
945   Actor actor = Actor::New();
946   actor.SetProperty(Actor::Property::SIZE, Vector2(100.0f, 100.0f));
947   actor.SetProperty(Actor::Property::ANCHOR_POINT, AnchorPoint::TOP_LEFT);
948   application.GetScene().Add(actor);
949
950   // Add a detector
951   SignalData               data;
952   GestureReceivedFunctor   functor(data);
953   LongPressGestureDetector detector = LongPressGestureDetector::New();
954   detector.Attach(actor);
955   detector.DetectedSignal().Connect(&application, functor);
956
957   // Add a layer to overlap the actor
958   Layer layer = Layer::New();
959   layer.SetProperty(Actor::Property::SIZE, Vector2(100.0f, 100.0f));
960   layer.SetProperty(Actor::Property::ANCHOR_POINT, AnchorPoint::TOP_LEFT);
961   application.GetScene().Add(layer);
962   layer.RaiseToTop();
963
964   // Render and notify
965   application.SendNotification();
966   application.Render();
967
968   // Emit signals, should receive
969   TestGenerateLongPress(application, 50.0f, 50.0f);
970   TestEndLongPress(application, 50.0f, 50.0f);
971   DALI_TEST_EQUALS(true, data.functorCalled, TEST_LOCATION);
972   data.Reset();
973
974   // Set layer to consume all touch
975   layer.SetProperty(Layer::Property::CONSUMES_TOUCH, true);
976
977   // Render and notify
978   application.SendNotification();
979   application.Render();
980
981   // Emit the same signals again, should not receive
982   TestGenerateLongPress(application, 50.0f, 50.0f);
983   TestEndLongPress(application, 50.0f, 50.0f);
984   DALI_TEST_EQUALS(false, data.functorCalled, TEST_LOCATION);
985   data.Reset();
986
987   END_TEST;
988 }
989
990 int UtcDaliLongPressGestureSetMinimumHoldingTime(void)
991 {
992   TestApplication application;
993
994   const uint32_t kMinumumHolding1 = 5000;
995   const uint32_t kMinumumHolding2 = 3000;
996
997   Integration::SetLongPressMinimumHoldingTime(kMinumumHolding1);
998
999   Actor actor = Actor::New();
1000   actor.SetProperty(Actor::Property::SIZE, Vector2(100.0f, 100.0f));
1001   actor.SetProperty(Actor::Property::ANCHOR_POINT, AnchorPoint::TOP_LEFT);
1002   application.GetScene().Add(actor);
1003
1004   // Render and notify
1005   application.SendNotification();
1006   application.Render();
1007
1008   SignalData             data;
1009   GestureReceivedFunctor functor(data);
1010
1011   LongPressGestureDetector detector = LongPressGestureDetector::New();
1012   detector.Attach(actor);
1013   detector.DetectedSignal().Connect(&application, functor);
1014
1015   DALI_TEST_EQUALS(DevelLongPressGestureDetector::GetMinimumHoldingTime(detector), kMinumumHolding1, TEST_LOCATION);
1016
1017   Integration::SetLongPressMinimumHoldingTime(kMinumumHolding2);
1018   DALI_TEST_EQUALS(DevelLongPressGestureDetector::GetMinimumHoldingTime(detector), kMinumumHolding2, TEST_LOCATION);
1019
1020   END_TEST;
1021 }
1022
1023 int UtcDaliLongPressGestureDisableDetectionDuringLongPressN(void)
1024 {
1025   // Crash occurred when gesture-recognizer was deleted internally during a signal when the attached actor was detached
1026
1027   TestApplication application;
1028
1029   Actor actor = Actor::New();
1030   actor.SetProperty(Actor::Property::SIZE, Vector2(100.0f, 100.0f));
1031   actor.SetProperty(Actor::Property::ANCHOR_POINT, AnchorPoint::TOP_LEFT);
1032   application.GetScene().Add(actor);
1033
1034   // Add a detector
1035   LongPressGestureDetector detector      = LongPressGestureDetector::New();
1036   bool                     functorCalled = false;
1037   detector.Attach(actor);
1038   detector.DetectedSignal().Connect(
1039     &application,
1040     [&detector, &functorCalled](Actor actor, const LongPressGesture& gesture) {
1041       if(gesture.GetState() == GestureState::FINISHED)
1042       {
1043         detector.Detach(actor);
1044         functorCalled = true;
1045       }
1046     });
1047
1048   // Render and notify
1049   application.SendNotification();
1050   application.Render();
1051
1052   // Try the gesture, should not crash
1053   try
1054   {
1055     TestGenerateLongPress(application, 50.0f, 10.0f);
1056     TestEndLongPress(application, 50.0f, 10.0f);
1057
1058     DALI_TEST_CHECK(true); // No crash, test has passed
1059     DALI_TEST_EQUALS(functorCalled, true, TEST_LOCATION);
1060   }
1061   catch(...)
1062   {
1063     DALI_TEST_CHECK(false); // If we crash, the test has failed
1064   }
1065
1066   END_TEST;
1067 }
1068
1069 int UtcDaliLongPressGestureWhenGesturePropargation(void)
1070 {
1071   TestApplication application;
1072
1073   Actor parentActor = Actor::New();
1074   parentActor.SetProperty(Actor::Property::SIZE, Vector2(100.0f, 100.0f));
1075   parentActor.SetProperty(Actor::Property::ANCHOR_POINT, AnchorPoint::TOP_LEFT);
1076
1077   Actor childActor = Actor::New();
1078   childActor.SetProperty(Actor::Property::SIZE, Vector2(100.0f, 100.0f));
1079   childActor.SetProperty(Actor::Property::ANCHOR_POINT, AnchorPoint::TOP_LEFT);
1080
1081   parentActor.Add(childActor);
1082   application.GetScene().Add(parentActor);
1083
1084   // Render and notify
1085   application.SendNotification();
1086   application.Render();
1087
1088   SignalData             pData;
1089   GestureReceivedFunctor pFunctor(pData);
1090
1091   LongPressGestureDetector parentDetector = LongPressGestureDetector::New();
1092   parentDetector.Attach(parentActor);
1093   parentDetector.DetectedSignal().Connect(&application, pFunctor);
1094
1095   SignalData             cData;
1096   GestureReceivedFunctor cFunctor(cData);
1097
1098   LongPressGestureDetector childDetector = LongPressGestureDetector::New();
1099   childDetector.Attach(childActor);
1100   childDetector.DetectedSignal().Connect(&application, cFunctor);
1101
1102   // Start gesture within the actor's area, we receive the gesture not parent actor but child actor.
1103   TestGenerateLongPress(application, 50.0f, 50.0f);
1104   TestEndLongPress(application, 50.0f, 50.0f);
1105
1106   DALI_TEST_EQUALS(true, cData.functorCalled, TEST_LOCATION);
1107   DALI_TEST_EQUALS(false, pData.functorCalled, TEST_LOCATION);
1108   cData.Reset();
1109   pData.Reset();
1110
1111   // If GesturePropargation is set, a gesture event is to pass over to the parent.
1112   Dali::DevelActor::SetNeedGesturePropagation(childActor, true);
1113
1114   // So now the parent got the gesture event.
1115   TestGenerateLongPress(application, 50.0f, 50.0f);
1116   TestEndLongPress(application, 50.0f, 50.0f);
1117   DALI_TEST_EQUALS(true, cData.functorCalled, TEST_LOCATION);
1118   DALI_TEST_EQUALS(true, pData.functorCalled, TEST_LOCATION);
1119   cData.Reset();
1120   pData.Reset();
1121
1122   END_TEST;
1123 }