2 * Copyright (c) 2020 Samsung Electronics Co., Ltd.
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
8 * http://www.apache.org/licenses/LICENSE-2.0
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.
18 #include <dali-test-suite-utils.h>
19 #include <dali/integration-api/events/touch-event-integ.h>
20 #include <dali/integration-api/input-options.h>
21 #include <dali/integration-api/render-task-list-integ.h>
22 #include <dali/public-api/dali-core.h>
29 ///////////////////////////////////////////////////////////////////////////////
35 : functorCalled(false),
36 voidFunctorCalled(false),
43 functorCalled = false;
44 voidFunctorCalled = false;
46 receivedGesture.Reset();
52 bool voidFunctorCalled;
53 PanGesture receivedGesture;
57 // Functor that sets the data when called
58 struct GestureReceivedFunctor
60 GestureReceivedFunctor(SignalData& data)
65 void operator()(Actor actor, const PanGesture& pan)
67 signalData.functorCalled = true;
68 signalData.receivedGesture = pan;
69 signalData.pannedActor = actor;
74 signalData.voidFunctorCalled = true;
77 SignalData& signalData;
80 Integration::TouchEvent GenerateSingleTouch(PointState::Type state, const Vector2& screenPosition, uint32_t time)
82 Integration::TouchEvent touchEvent;
83 Integration::Point point;
84 point.SetState(state);
85 point.SetScreenPosition(screenPosition);
86 point.SetDeviceClass(Device::Class::TOUCH);
87 point.SetDeviceSubclass(Device::Subclass::NONE);
88 touchEvent.points.push_back(point);
89 touchEvent.time = time;
93 Integration::TouchEvent GenerateDoubleTouch(PointState::Type stateA, const Vector2& screenPositionA, PointState::Type stateB, const Vector2& screenPositionB, uint32_t time)
95 Integration::TouchEvent touchEvent;
96 Integration::Point point;
97 point.SetState(stateA);
98 point.SetScreenPosition(screenPositionA);
99 point.SetDeviceClass(Device::Class::TOUCH);
100 point.SetDeviceSubclass(Device::Subclass::NONE);
101 touchEvent.points.push_back(point);
102 point.SetScreenPosition(screenPositionB);
103 point.SetState(stateB);
104 touchEvent.points.push_back(point);
105 touchEvent.time = time;
111 ///////////////////////////////////////////////////////////////////////////////
113 int UtcDaliPanGestureRecognizerBasicNoAction(void)
115 TestApplication application;
117 PanGestureDetector detector = PanGestureDetector::New();
119 Actor actor = Actor::New();
120 actor.SetProperty(Actor::Property::SIZE, Vector2(100.0f, 100.0f));
121 actor.SetProperty(Actor::Property::ANCHOR_POINT, AnchorPoint::TOP_LEFT);
122 application.GetScene().Add(actor);
125 application.SendNotification();
126 application.Render();
128 detector.Attach(actor);
131 GestureReceivedFunctor functor(data);
132 detector.DetectedSignal().Connect(&application, functor);
134 application.ProcessEvent(GenerateSingleTouch(PointState::DOWN, Vector2(20.0f, 20.0f), 150));
136 application.ProcessEvent(GenerateSingleTouch(PointState::UP, Vector2(20.0f, 20.0f), 200));
138 application.SendNotification();
140 DALI_TEST_EQUALS(false, data.functorCalled, TEST_LOCATION);
145 int UtcDaliPanGestureRecognizerBasic(void)
147 TestApplication application;
149 PanGestureDetector detector = PanGestureDetector::New();
151 Actor actor = Actor::New();
152 actor.SetProperty(Actor::Property::SIZE, Vector2(100.0f, 100.0f));
153 actor.SetProperty(Actor::Property::ANCHOR_POINT, AnchorPoint::TOP_LEFT);
154 application.GetScene().Add(actor);
157 application.SendNotification();
158 application.Render();
160 detector.Attach(actor);
163 GestureReceivedFunctor functor(data);
164 detector.DetectedSignal().Connect(&application, functor);
166 application.ProcessEvent(GenerateSingleTouch(PointState::DOWN, Vector2(20.0f, 20.0f), 150));
167 application.ProcessEvent(GenerateSingleTouch(PointState::MOTION, Vector2(20.0f, 40.0f), 151));
168 application.ProcessEvent(GenerateSingleTouch(PointState::MOTION, Vector2(20.0f, 60.0f), 152));
170 application.SendNotification();
172 DALI_TEST_EQUALS(true, data.functorCalled, TEST_LOCATION);
177 int UtcDaliPanGestureRecognizerBasicInterrupted(void)
179 TestApplication application;
181 PanGestureDetector detector = PanGestureDetector::New();
183 Actor actor = Actor::New();
184 actor.SetProperty(Actor::Property::SIZE, Vector2(100.0f, 100.0f));
185 actor.SetProperty(Actor::Property::ANCHOR_POINT, AnchorPoint::TOP_LEFT);
186 application.GetScene().Add(actor);
189 application.SendNotification();
190 application.Render();
192 detector.Attach(actor);
195 GestureReceivedFunctor functor(data);
196 detector.DetectedSignal().Connect(&application, functor);
198 application.ProcessEvent(GenerateSingleTouch(PointState::DOWN, Vector2(20.0f, 20.0f), 150));
199 application.ProcessEvent(GenerateSingleTouch(PointState::MOTION, Vector2(20.0f, 25.0f), 151));
200 application.ProcessEvent(GenerateSingleTouch(PointState::INTERRUPTED, Vector2(20.0f, 30.0f), 152));
202 application.SendNotification();
204 DALI_TEST_EQUALS(false, data.functorCalled, TEST_LOCATION);
209 int UtcDaliPanGestureRecognizerBasicShortest(void)
211 TestApplication application;
213 PanGestureDetector detector = PanGestureDetector::New();
215 Actor actor = Actor::New();
216 actor.SetProperty(Actor::Property::SIZE, Vector2(100.0f, 100.0f));
217 actor.SetProperty(Actor::Property::ANCHOR_POINT, AnchorPoint::TOP_LEFT);
218 application.GetScene().Add(actor);
221 application.SendNotification();
222 application.Render();
224 detector.Attach(actor);
227 GestureReceivedFunctor functor(data);
228 detector.DetectedSignal().Connect(&application, functor);
230 application.ProcessEvent(GenerateSingleTouch(PointState::DOWN, Vector2(20.0f, 20.0f), 150));
231 application.ProcessEvent(GenerateSingleTouch(PointState::MOTION, Vector2(20.0f, 40.0f), 151));
232 application.ProcessEvent(GenerateSingleTouch(PointState::UP, Vector2(20.0f, 40.0f), 155));
234 application.SendNotification();
236 DALI_TEST_EQUALS(true, data.functorCalled, TEST_LOCATION);
241 int UtcDaliPanGestureRecognizerBasicFailToStart(void)
243 TestApplication application;
245 PanGestureDetector detector = PanGestureDetector::New();
247 Actor actor = Actor::New();
248 actor.SetProperty(Actor::Property::SIZE, Vector2(100.0f, 100.0f));
249 actor.SetProperty(Actor::Property::ANCHOR_POINT, AnchorPoint::TOP_LEFT);
250 application.GetScene().Add(actor);
253 application.SendNotification();
254 application.Render();
256 detector.Attach(actor);
259 GestureReceivedFunctor functor(data);
260 detector.DetectedSignal().Connect(&application, functor);
262 application.ProcessEvent(GenerateSingleTouch(PointState::DOWN, Vector2(20.0f, 20.0f), 150));
263 application.ProcessEvent(GenerateSingleTouch(PointState::MOTION, Vector2(20.0f, 40.0f), 151));
264 application.ProcessEvent(GenerateDoubleTouch(PointState::MOTION, Vector2(20.0f, 50.0f), PointState::DOWN, Vector2(40.0f, 40.0f), 153));
266 application.SendNotification();
268 DALI_TEST_EQUALS(false, data.functorCalled, TEST_LOCATION);
273 int UtcDaliPanGestureRecognizerBasicStationary(void)
275 TestApplication application;
277 PanGestureDetector detector = PanGestureDetector::New();
279 Actor actor = Actor::New();
280 actor.SetProperty(Actor::Property::SIZE, Vector2(100.0f, 100.0f));
281 actor.SetProperty(Actor::Property::ANCHOR_POINT, AnchorPoint::TOP_LEFT);
282 application.GetScene().Add(actor);
285 application.SendNotification();
286 application.Render();
288 detector.Attach(actor);
291 GestureReceivedFunctor functor(data);
292 detector.DetectedSignal().Connect(&application, functor);
294 application.ProcessEvent(GenerateSingleTouch(PointState::DOWN, Vector2(20.0f, 20.0f), 150));
295 application.ProcessEvent(GenerateSingleTouch(PointState::MOTION, Vector2(20.0f, 40.0f), 151));
296 application.ProcessEvent(GenerateSingleTouch(PointState::MOTION, Vector2(20.0f, 50.0f), 152));
297 application.ProcessEvent(GenerateSingleTouch(PointState::STATIONARY, Vector2(20.0f, 50.0f), 153));
298 application.ProcessEvent(GenerateSingleTouch(PointState::MOTION, Vector2(20.0f, 55.0f), 154));
300 application.SendNotification();
302 DALI_TEST_EQUALS(true, data.functorCalled, TEST_LOCATION);
307 int UtcDaliPanGestureRecognizerNewParametersFail(void)
309 TestApplication application;
311 PanGestureDetector detector = PanGestureDetector::New();
313 detector.SetMaximumTouchesRequired(2);
314 detector.SetMinimumTouchesRequired(2);
316 Actor actor = Actor::New();
317 actor.SetProperty(Actor::Property::SIZE, Vector2(100.0f, 100.0f));
318 actor.SetProperty(Actor::Property::ANCHOR_POINT, AnchorPoint::TOP_LEFT);
319 application.GetScene().Add(actor);
322 application.SendNotification();
323 application.Render();
325 detector.Attach(actor);
328 GestureReceivedFunctor functor(data);
329 detector.DetectedSignal().Connect(&application, functor);
331 application.ProcessEvent(GenerateSingleTouch(PointState::DOWN, Vector2(20.0f, 20.0f), 150));
332 application.ProcessEvent(GenerateSingleTouch(PointState::MOTION, Vector2(20.0f, 40.0f), 151));
333 application.ProcessEvent(GenerateSingleTouch(PointState::MOTION, Vector2(20.0f, 60.0f), 152));
335 application.SendNotification();
337 DALI_TEST_EQUALS(false, data.functorCalled, TEST_LOCATION);
342 int UtcDaliPanGestureRecognizerNewParametersSuccess(void)
344 TestApplication application;
346 PanGestureDetector detector = PanGestureDetector::New();
348 detector.SetMaximumTouchesRequired(2);
349 detector.SetMinimumTouchesRequired(2);
351 Actor actor = Actor::New();
352 actor.SetProperty(Actor::Property::SIZE, Vector2(100.0f, 100.0f));
353 actor.SetProperty(Actor::Property::ANCHOR_POINT, AnchorPoint::TOP_LEFT);
354 application.GetScene().Add(actor);
357 application.SendNotification();
358 application.Render();
360 detector.Attach(actor);
363 GestureReceivedFunctor functor(data);
364 detector.DetectedSignal().Connect(&application, functor);
366 application.ProcessEvent(GenerateDoubleTouch(PointState::DOWN, Vector2(20.0f, 50.0f), PointState::DOWN, Vector2(20.0f, 40.0f), 150));
367 application.ProcessEvent(GenerateDoubleTouch(PointState::MOTION, Vector2(40.0f, 50.0f), PointState::MOTION, Vector2(40.0f, 40.0f), 151));
368 application.ProcessEvent(GenerateDoubleTouch(PointState::MOTION, Vector2(50.0f, 50.0f), PointState::MOTION, Vector2(50.0f, 40.0f), 152));
370 application.SendNotification();
372 DALI_TEST_EQUALS(true, data.functorCalled, TEST_LOCATION);
377 int UtcDaliPanGestureRecognizerNewParametersEndFewerTouches01(void)
379 TestApplication application;
381 PanGestureDetector detector = PanGestureDetector::New();
383 detector.SetMaximumTouchesRequired(2);
384 detector.SetMinimumTouchesRequired(2);
386 Actor actor = Actor::New();
387 actor.SetProperty(Actor::Property::SIZE, Vector2(100.0f, 100.0f));
388 actor.SetProperty(Actor::Property::ANCHOR_POINT, AnchorPoint::TOP_LEFT);
389 application.GetScene().Add(actor);
392 application.SendNotification();
393 application.Render();
395 detector.Attach(actor);
398 GestureReceivedFunctor functor(data);
399 detector.DetectedSignal().Connect(&application, functor);
401 application.ProcessEvent(GenerateDoubleTouch(PointState::DOWN, Vector2(20.0f, 50.0f), PointState::DOWN, Vector2(20.0f, 40.0f), 150));
402 application.ProcessEvent(GenerateDoubleTouch(PointState::MOTION, Vector2(40.0f, 50.0f), PointState::MOTION, Vector2(40.0f, 40.0f), 151));
403 application.ProcessEvent(GenerateDoubleTouch(PointState::MOTION, Vector2(50.0f, 50.0f), PointState::MOTION, Vector2(50.0f, 40.0f), 152));
404 application.ProcessEvent(GenerateSingleTouch(PointState::STATIONARY, Vector2(50.0f, 50.0f), 153));
406 application.SendNotification();
408 DALI_TEST_EQUALS(true, data.functorCalled, TEST_LOCATION);
413 int UtcDaliPanGestureRecognizerNewParametersEndFewerTouches02(void)
415 TestApplication application;
417 PanGestureDetector detector = PanGestureDetector::New();
419 detector.SetMaximumTouchesRequired(2);
420 detector.SetMinimumTouchesRequired(2);
422 Actor actor = Actor::New();
423 actor.SetProperty(Actor::Property::SIZE, Vector2(100.0f, 100.0f));
424 actor.SetProperty(Actor::Property::ANCHOR_POINT, AnchorPoint::TOP_LEFT);
425 application.GetScene().Add(actor);
428 application.SendNotification();
429 application.Render();
431 detector.Attach(actor);
434 GestureReceivedFunctor functor(data);
435 detector.DetectedSignal().Connect(&application, functor);
437 application.ProcessEvent(GenerateDoubleTouch(PointState::DOWN, Vector2(20.0f, 50.0f), PointState::DOWN, Vector2(20.0f, 40.0f), 150));
438 application.ProcessEvent(GenerateDoubleTouch(PointState::MOTION, Vector2(40.0f, 50.0f), PointState::MOTION, Vector2(40.0f, 40.0f), 151));
439 application.ProcessEvent(GenerateDoubleTouch(PointState::MOTION, Vector2(50.0f, 50.0f), PointState::MOTION, Vector2(50.0f, 40.0f), 152));
440 application.ProcessEvent(GenerateDoubleTouch(PointState::STATIONARY, Vector2(50.0f, 50.0f), PointState::UP, Vector2(50.0f, 40.0f), 153));
442 application.SendNotification();
444 DALI_TEST_EQUALS(true, data.functorCalled, TEST_LOCATION);
449 int UtcDaliPanGestureRecognizerNewParametersNoStart(void)
451 TestApplication application;
453 PanGestureDetector detector = PanGestureDetector::New();
455 detector.SetMaximumTouchesRequired(2);
456 detector.SetMinimumTouchesRequired(2);
458 Actor actor = Actor::New();
459 actor.SetProperty(Actor::Property::SIZE, Vector2(100.0f, 100.0f));
460 actor.SetProperty(Actor::Property::ANCHOR_POINT, AnchorPoint::TOP_LEFT);
461 application.GetScene().Add(actor);
464 application.SendNotification();
465 application.Render();
467 detector.Attach(actor);
470 GestureReceivedFunctor functor(data);
471 detector.DetectedSignal().Connect(&application, functor);
473 application.ProcessEvent(GenerateDoubleTouch(PointState::DOWN, Vector2(20.0f, 50.0f), PointState::DOWN, Vector2(20.0f, 40.0f), 150));
474 application.ProcessEvent(GenerateDoubleTouch(PointState::MOTION, Vector2(40.0f, 50.0f), PointState::MOTION, Vector2(40.0f, 40.0f), 151));
475 application.ProcessEvent(GenerateSingleTouch(PointState::UP, Vector2(50.0f, 50.0f), 153));
477 application.SendNotification();
479 DALI_TEST_EQUALS(false, data.functorCalled, TEST_LOCATION);
484 int UtcDaliPanGestureRecognizerNewParametersSlowRelease(void)
486 TestApplication application;
488 PanGestureDetector detector = PanGestureDetector::New();
490 detector.SetMaximumTouchesRequired(2);
491 detector.SetMinimumTouchesRequired(2);
493 Actor actor = Actor::New();
494 actor.SetProperty(Actor::Property::SIZE, Vector2(100.0f, 100.0f));
495 actor.SetProperty(Actor::Property::ANCHOR_POINT, AnchorPoint::TOP_LEFT);
496 application.GetScene().Add(actor);
499 application.SendNotification();
500 application.Render();
502 detector.Attach(actor);
505 GestureReceivedFunctor functor(data);
506 detector.DetectedSignal().Connect(&application, functor);
508 application.ProcessEvent(GenerateDoubleTouch(PointState::DOWN, Vector2(20.0f, 50.0f), PointState::DOWN, Vector2(20.0f, 40.0f), 150));
509 application.ProcessEvent(GenerateDoubleTouch(PointState::MOTION, Vector2(40.0f, 50.0f), PointState::MOTION, Vector2(40.0f, 40.0f), 151));
510 application.ProcessEvent(GenerateDoubleTouch(PointState::MOTION, Vector2(50.0f, 50.0f), PointState::MOTION, Vector2(50.0f, 40.0f), 152));
511 application.ProcessEvent(GenerateDoubleTouch(PointState::MOTION, Vector2(60.0f, 50.0f), PointState::MOTION, Vector2(60.0f, 40.0f), 153));
512 application.ProcessEvent(GenerateDoubleTouch(PointState::MOTION, Vector2(70.0f, 50.0f), PointState::MOTION, Vector2(70.0f, 40.0f), 154));
513 application.ProcessEvent(GenerateSingleTouch(PointState::UP, Vector2(70.0f, 50.0f), 155));
515 application.SendNotification();
517 DALI_TEST_EQUALS(true, data.functorCalled, TEST_LOCATION);
522 int UtcDaliPanGestureRecognizerOtherEvent(void)
524 TestApplication application;
526 PanGestureDetector detector = PanGestureDetector::New();
528 Actor actor = Actor::New();
529 actor.SetProperty(Actor::Property::SIZE, Vector2(100.0f, 100.0f));
530 actor.SetProperty(Actor::Property::ANCHOR_POINT, AnchorPoint::TOP_LEFT);
531 application.GetScene().Add(actor);
534 application.SendNotification();
535 application.Render();
537 detector.Attach(actor);
540 GestureReceivedFunctor functor(data);
541 detector.DetectedSignal().Connect(&application, functor);
543 application.ProcessEvent(GenerateSingleTouch(PointState::DOWN, Vector2(20.0f, 20.0f), 150));
544 application.ProcessEvent(GenerateSingleTouch(PointState::MOTION, Vector2(20.0f, 40.0f), 151));
545 application.ProcessEvent(GenerateSingleTouch(PointState::MOTION, Vector2(20.0f, 60.0f), 152));
546 application.ProcessEvent(GenerateSingleTouch(PointState::DOWN, Vector2(20.0f, 60.0f), 153)); // Exercise default case in STARTED case. Not sure if realistic
547 application.ProcessEvent(GenerateSingleTouch(PointState::MOTION, Vector2(20.0f, 65.0f), 154));
549 application.SendNotification();
551 DALI_TEST_EQUALS(true, data.functorCalled, TEST_LOCATION);
556 int UtcDaliPanGestureRecognizerSlowMoving(void)
558 TestApplication application;
560 PanGestureDetector detector = PanGestureDetector::New();
562 Actor actor = Actor::New();
563 actor.SetProperty(Actor::Property::SIZE, Vector2(100.0f, 100.0f));
564 actor.SetProperty(Actor::Property::ANCHOR_POINT, AnchorPoint::TOP_LEFT);
565 application.GetScene().Add(actor);
568 application.SendNotification();
569 application.Render();
571 detector.Attach(actor);
574 GestureReceivedFunctor functor(data);
575 detector.DetectedSignal().Connect(&application, functor);
577 application.ProcessEvent(GenerateSingleTouch(PointState::DOWN, Vector2(20.0f, 20.0f), 150));
578 application.ProcessEvent(GenerateSingleTouch(PointState::MOTION, Vector2(20.0f, 40.0f), 251));
579 application.ProcessEvent(GenerateSingleTouch(PointState::MOTION, Vector2(20.0f, 60.0f), 352));
580 application.ProcessEvent(GenerateSingleTouch(PointState::MOTION, Vector2(20.0f, 70.0f), 453));
581 application.ProcessEvent(GenerateSingleTouch(PointState::MOTION, Vector2(20.0f, 80.0f), 554));
582 application.ProcessEvent(GenerateSingleTouch(PointState::MOTION, Vector2(20.0f, 90.0f), 655));
584 application.SendNotification();
586 DALI_TEST_EQUALS(true, data.functorCalled, TEST_LOCATION);
591 int UtcDaliPanGestureRecognizerNewParamsMinNum(void)
593 TestApplication application;
595 Integration::SetPanGestureMinimumPanEvents(8);
597 PanGestureDetector detector = PanGestureDetector::New();
599 Actor actor = Actor::New();
600 actor.SetProperty(Actor::Property::SIZE, Vector2(100.0f, 100.0f));
601 actor.SetProperty(Actor::Property::ANCHOR_POINT, AnchorPoint::TOP_LEFT);
602 application.GetScene().Add(actor);
605 application.SendNotification();
606 application.Render();
608 detector.Attach(actor);
611 GestureReceivedFunctor functor(data);
612 detector.DetectedSignal().Connect(&application, functor);
614 application.ProcessEvent(GenerateSingleTouch(PointState::DOWN, Vector2(20.0f, 20.0f), 150));
615 application.ProcessEvent(GenerateSingleTouch(PointState::MOTION, Vector2(20.0f, 40.0f), 251));
616 application.ProcessEvent(GenerateSingleTouch(PointState::MOTION, Vector2(20.0f, 60.0f), 352));
617 application.ProcessEvent(GenerateSingleTouch(PointState::MOTION, Vector2(20.0f, 70.0f), 453));
618 application.ProcessEvent(GenerateSingleTouch(PointState::MOTION, Vector2(20.0f, 80.0f), 554));
619 application.ProcessEvent(GenerateSingleTouch(PointState::MOTION, Vector2(20.0f, 90.0f), 655));
621 application.SendNotification();
623 DALI_TEST_EQUALS(false, data.functorCalled, TEST_LOCATION);
628 int UtcDaliPanGestureRecognizerNewParamsMinDistance(void)
630 TestApplication application;
632 Integration::SetPanGestureMinimumDistance(100);
634 PanGestureDetector detector = PanGestureDetector::New();
636 Actor actor = Actor::New();
637 actor.SetProperty(Actor::Property::SIZE, Vector2(100.0f, 100.0f));
638 actor.SetProperty(Actor::Property::ANCHOR_POINT, AnchorPoint::TOP_LEFT);
639 application.GetScene().Add(actor);
642 application.SendNotification();
643 application.Render();
645 detector.Attach(actor);
648 GestureReceivedFunctor functor(data);
649 detector.DetectedSignal().Connect(&application, functor);
651 application.ProcessEvent(GenerateSingleTouch(PointState::DOWN, Vector2(20.0f, 20.0f), 150));
652 application.ProcessEvent(GenerateSingleTouch(PointState::MOTION, Vector2(20.0f, 40.0f), 251));
653 application.ProcessEvent(GenerateSingleTouch(PointState::MOTION, Vector2(20.0f, 60.0f), 352));
654 application.ProcessEvent(GenerateSingleTouch(PointState::MOTION, Vector2(20.0f, 70.0f), 453));
655 application.ProcessEvent(GenerateSingleTouch(PointState::MOTION, Vector2(20.0f, 80.0f), 554));
656 application.ProcessEvent(GenerateSingleTouch(PointState::MOTION, Vector2(20.0f, 90.0f), 655));
658 application.SendNotification();
660 DALI_TEST_EQUALS(false, data.functorCalled, TEST_LOCATION);