2 * Copyright (c) 2019 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.
21 #include <dali/public-api/dali-core.h>
22 #include <dali/integration-api/input-options.h>
23 #include <dali/integration-api/events/touch-event-integ.h>
24 #include <dali/integration-api/render-task-list-integ.h>
25 #include <dali/internal/event/events/pan-gesture-event.h>
26 #include <dali-test-suite-utils.h>
27 #include <test-touch-utils.h>
31 ///////////////////////////////////////////////////////////////////////////////
38 : functorCalled(false),
39 voidFunctorCalled(false),
45 functorCalled = false;
46 voidFunctorCalled = false;
48 receivedGesture.state = Gesture::Started;
54 bool voidFunctorCalled;
55 PanGesture receivedGesture;
59 // Functor that sets the data when called
60 struct GestureReceivedFunctor
62 GestureReceivedFunctor(SignalData& data) : signalData(data) { }
64 void operator()(Actor actor, const PanGesture& pan)
66 signalData.functorCalled = true;
67 signalData.receivedGesture = pan;
68 signalData.pannedActor = actor;
73 signalData.voidFunctorCalled = true;
76 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;
112 ///////////////////////////////////////////////////////////////////////////////
115 int UtcDaliPanGestureRecognizerBasicNoAction(void)
117 TestApplication application;
119 PanGestureDetector detector = PanGestureDetector::New();
121 Actor actor = Actor::New();
122 actor.SetSize(100.0f, 100.0f);
123 actor.SetAnchorPoint(AnchorPoint::TOP_LEFT);
124 Stage::GetCurrent().Add(actor);
127 application.SendNotification();
128 application.Render();
130 detector.Attach(actor);
133 GestureReceivedFunctor functor(data);
134 detector.DetectedSignal().Connect(&application, functor);
136 application.ProcessEvent( GenerateSingleTouch( PointState::DOWN, Vector2( 20.0f, 20.0f ), 150 ) );
138 application.ProcessEvent( GenerateSingleTouch( PointState::UP, Vector2( 20.0f, 20.0f ), 200 ) );
140 application.SendNotification();
142 DALI_TEST_EQUALS(false, data.functorCalled, TEST_LOCATION);
147 int UtcDaliPanGestureRecognizerBasic(void)
149 TestApplication application;
151 PanGestureDetector detector = PanGestureDetector::New();
153 Actor actor = Actor::New();
154 actor.SetSize(100.0f, 100.0f);
155 actor.SetAnchorPoint(AnchorPoint::TOP_LEFT);
156 Stage::GetCurrent().Add(actor);
159 application.SendNotification();
160 application.Render();
162 detector.Attach(actor);
165 GestureReceivedFunctor functor(data);
166 detector.DetectedSignal().Connect(&application, functor);
168 application.ProcessEvent( GenerateSingleTouch( PointState::DOWN, Vector2( 20.0f, 20.0f ), 150 ) );
169 application.ProcessEvent( GenerateSingleTouch( PointState::MOTION, Vector2( 20.0f, 40.0f ), 151 ) );
170 application.ProcessEvent( GenerateSingleTouch( PointState::MOTION, Vector2( 20.0f, 60.0f ), 152 ) );
172 application.SendNotification();
174 DALI_TEST_EQUALS(true, data.functorCalled, TEST_LOCATION);
179 int UtcDaliPanGestureRecognizerBasicInterrupted(void)
181 TestApplication application;
183 PanGestureDetector detector = PanGestureDetector::New();
185 Actor actor = Actor::New();
186 actor.SetSize(100.0f, 100.0f);
187 actor.SetAnchorPoint(AnchorPoint::TOP_LEFT);
188 Stage::GetCurrent().Add(actor);
191 application.SendNotification();
192 application.Render();
194 detector.Attach(actor);
197 GestureReceivedFunctor functor(data);
198 detector.DetectedSignal().Connect(&application, functor);
200 application.ProcessEvent( GenerateSingleTouch( PointState::DOWN, Vector2( 20.0f, 20.0f ), 150 ) );
201 application.ProcessEvent( GenerateSingleTouch( PointState::MOTION, Vector2( 20.0f, 25.0f ), 151 ) );
202 application.ProcessEvent( GenerateSingleTouch( PointState::INTERRUPTED, Vector2( 20.0f, 30.0f ), 152 ) );
204 application.SendNotification();
206 DALI_TEST_EQUALS(false, data.functorCalled, TEST_LOCATION);
211 int UtcDaliPanGestureRecognizerBasicShortest(void)
213 TestApplication application;
215 PanGestureDetector detector = PanGestureDetector::New();
217 Actor actor = Actor::New();
218 actor.SetSize(100.0f, 100.0f);
219 actor.SetAnchorPoint(AnchorPoint::TOP_LEFT);
220 Stage::GetCurrent().Add(actor);
223 application.SendNotification();
224 application.Render();
226 detector.Attach(actor);
229 GestureReceivedFunctor functor(data);
230 detector.DetectedSignal().Connect(&application, functor);
232 application.ProcessEvent( GenerateSingleTouch( PointState::DOWN, Vector2( 20.0f, 20.0f ), 150 ) );
233 application.ProcessEvent( GenerateSingleTouch( PointState::MOTION, Vector2( 20.0f, 40.0f ), 151 ) );
234 application.ProcessEvent( GenerateSingleTouch( PointState::UP, Vector2( 20.0f, 40.0f ), 155 ) );
236 application.SendNotification();
238 DALI_TEST_EQUALS(true, data.functorCalled, TEST_LOCATION);
243 int UtcDaliPanGestureRecognizerBasicFailToStart(void)
245 TestApplication application;
247 PanGestureDetector detector = PanGestureDetector::New();
249 Actor actor = Actor::New();
250 actor.SetSize(100.0f, 100.0f);
251 actor.SetAnchorPoint(AnchorPoint::TOP_LEFT);
252 Stage::GetCurrent().Add(actor);
255 application.SendNotification();
256 application.Render();
258 detector.Attach(actor);
261 GestureReceivedFunctor functor(data);
262 detector.DetectedSignal().Connect(&application, functor);
264 application.ProcessEvent( GenerateSingleTouch( PointState::DOWN, Vector2( 20.0f, 20.0f ), 150 ) );
265 application.ProcessEvent( GenerateSingleTouch( PointState::MOTION, Vector2( 20.0f, 40.0f ), 151 ) );
266 application.ProcessEvent( GenerateDoubleTouch( PointState::MOTION, Vector2( 20.0f, 50.0f ), PointState::DOWN, Vector2( 40.0f, 40.0f ), 153 ) );
268 application.SendNotification();
270 DALI_TEST_EQUALS(false, data.functorCalled, TEST_LOCATION);
275 int UtcDaliPanGestureRecognizerBasicStationary(void)
277 TestApplication application;
279 PanGestureDetector detector = PanGestureDetector::New();
281 Actor actor = Actor::New();
282 actor.SetSize(100.0f, 100.0f);
283 actor.SetAnchorPoint(AnchorPoint::TOP_LEFT);
284 Stage::GetCurrent().Add(actor);
287 application.SendNotification();
288 application.Render();
290 detector.Attach(actor);
293 GestureReceivedFunctor functor(data);
294 detector.DetectedSignal().Connect(&application, functor);
296 application.ProcessEvent( GenerateSingleTouch( PointState::DOWN, Vector2( 20.0f, 20.0f ), 150 ) );
297 application.ProcessEvent( GenerateSingleTouch( PointState::MOTION, Vector2( 20.0f, 40.0f ), 151 ) );
298 application.ProcessEvent( GenerateSingleTouch( PointState::MOTION, Vector2( 20.0f, 50.0f ), 152 ) );
299 application.ProcessEvent( GenerateSingleTouch( PointState::STATIONARY, Vector2( 20.0f, 50.0f ), 153 ) );
300 application.ProcessEvent( GenerateSingleTouch( PointState::MOTION, Vector2( 20.0f, 55.0f ), 154 ) );
302 application.SendNotification();
304 DALI_TEST_EQUALS(true, data.functorCalled, TEST_LOCATION);
309 int UtcDaliPanGestureRecognizerNewParametersFail(void)
311 TestApplication application;
313 PanGestureDetector detector = PanGestureDetector::New();
315 detector.SetMaximumTouchesRequired(2);
316 detector.SetMinimumTouchesRequired(2);
318 Actor actor = Actor::New();
319 actor.SetSize(100.0f, 100.0f);
320 actor.SetAnchorPoint(AnchorPoint::TOP_LEFT);
321 Stage::GetCurrent().Add(actor);
324 application.SendNotification();
325 application.Render();
327 detector.Attach(actor);
330 GestureReceivedFunctor functor(data);
331 detector.DetectedSignal().Connect(&application, functor);
333 application.ProcessEvent( GenerateSingleTouch( PointState::DOWN, Vector2( 20.0f, 20.0f ), 150 ) );
334 application.ProcessEvent( GenerateSingleTouch( PointState::MOTION, Vector2( 20.0f, 40.0f ), 151 ) );
335 application.ProcessEvent( GenerateSingleTouch( PointState::MOTION, Vector2( 20.0f, 60.0f ), 152 ) );
337 application.SendNotification();
339 DALI_TEST_EQUALS(false, data.functorCalled, TEST_LOCATION);
344 int UtcDaliPanGestureRecognizerNewParametersSuccess(void)
346 TestApplication application;
348 PanGestureDetector detector = PanGestureDetector::New();
350 detector.SetMaximumTouchesRequired(2);
351 detector.SetMinimumTouchesRequired(2);
353 Actor actor = Actor::New();
354 actor.SetSize(100.0f, 100.0f);
355 actor.SetAnchorPoint(AnchorPoint::TOP_LEFT);
356 Stage::GetCurrent().Add(actor);
359 application.SendNotification();
360 application.Render();
362 detector.Attach(actor);
365 GestureReceivedFunctor functor(data);
366 detector.DetectedSignal().Connect(&application, functor);
368 application.ProcessEvent( GenerateDoubleTouch( PointState::DOWN, Vector2( 20.0f, 50.0f ), PointState::DOWN, Vector2( 20.0f, 40.0f ), 150 ) );
369 application.ProcessEvent( GenerateDoubleTouch( PointState::MOTION, Vector2( 40.0f, 50.0f ), PointState::MOTION, Vector2( 40.0f, 40.0f ), 151 ) );
370 application.ProcessEvent( GenerateDoubleTouch( PointState::MOTION, Vector2( 50.0f, 50.0f ), PointState::MOTION, Vector2( 50.0f, 40.0f ), 152 ) );
372 application.SendNotification();
374 DALI_TEST_EQUALS(true, data.functorCalled, TEST_LOCATION);
379 int UtcDaliPanGestureRecognizerNewParametersEndFewerTouches01(void)
381 TestApplication application;
383 PanGestureDetector detector = PanGestureDetector::New();
385 detector.SetMaximumTouchesRequired(2);
386 detector.SetMinimumTouchesRequired(2);
388 Actor actor = Actor::New();
389 actor.SetSize(100.0f, 100.0f);
390 actor.SetAnchorPoint(AnchorPoint::TOP_LEFT);
391 Stage::GetCurrent().Add(actor);
394 application.SendNotification();
395 application.Render();
397 detector.Attach(actor);
400 GestureReceivedFunctor functor(data);
401 detector.DetectedSignal().Connect(&application, functor);
403 application.ProcessEvent( GenerateDoubleTouch( PointState::DOWN, Vector2( 20.0f, 50.0f ), PointState::DOWN, Vector2( 20.0f, 40.0f ), 150 ) );
404 application.ProcessEvent( GenerateDoubleTouch( PointState::MOTION, Vector2( 40.0f, 50.0f ), PointState::MOTION, Vector2( 40.0f, 40.0f ), 151 ) );
405 application.ProcessEvent( GenerateDoubleTouch( PointState::MOTION, Vector2( 50.0f, 50.0f ), PointState::MOTION, Vector2( 50.0f, 40.0f ), 152 ) );
406 application.ProcessEvent( GenerateSingleTouch( PointState::STATIONARY, Vector2( 50.0f, 50.0f ), 153 ) );
408 application.SendNotification();
410 DALI_TEST_EQUALS(true, data.functorCalled, TEST_LOCATION);
415 int UtcDaliPanGestureRecognizerNewParametersEndFewerTouches02(void)
417 TestApplication application;
419 PanGestureDetector detector = PanGestureDetector::New();
421 detector.SetMaximumTouchesRequired(2);
422 detector.SetMinimumTouchesRequired(2);
424 Actor actor = Actor::New();
425 actor.SetSize(100.0f, 100.0f);
426 actor.SetAnchorPoint(AnchorPoint::TOP_LEFT);
427 Stage::GetCurrent().Add(actor);
430 application.SendNotification();
431 application.Render();
433 detector.Attach(actor);
436 GestureReceivedFunctor functor(data);
437 detector.DetectedSignal().Connect(&application, functor);
439 application.ProcessEvent( GenerateDoubleTouch( PointState::DOWN, Vector2( 20.0f, 50.0f ), PointState::DOWN, Vector2( 20.0f, 40.0f ), 150 ) );
440 application.ProcessEvent( GenerateDoubleTouch( PointState::MOTION, Vector2( 40.0f, 50.0f ), PointState::MOTION, Vector2( 40.0f, 40.0f ), 151 ) );
441 application.ProcessEvent( GenerateDoubleTouch( PointState::MOTION, Vector2( 50.0f, 50.0f ), PointState::MOTION, Vector2( 50.0f, 40.0f ), 152 ) );
442 application.ProcessEvent( GenerateDoubleTouch( PointState::STATIONARY, Vector2( 50.0f, 50.0f ), PointState::UP, Vector2( 50.0f, 40.0f ), 153 ) );
444 application.SendNotification();
446 DALI_TEST_EQUALS(true, data.functorCalled, TEST_LOCATION);
451 int UtcDaliPanGestureRecognizerNewParametersNoStart(void)
453 TestApplication application;
455 PanGestureDetector detector = PanGestureDetector::New();
457 detector.SetMaximumTouchesRequired(2);
458 detector.SetMinimumTouchesRequired(2);
460 Actor actor = Actor::New();
461 actor.SetSize(100.0f, 100.0f);
462 actor.SetAnchorPoint(AnchorPoint::TOP_LEFT);
463 Stage::GetCurrent().Add(actor);
466 application.SendNotification();
467 application.Render();
469 detector.Attach(actor);
472 GestureReceivedFunctor functor(data);
473 detector.DetectedSignal().Connect(&application, functor);
475 application.ProcessEvent( GenerateDoubleTouch( PointState::DOWN, Vector2( 20.0f, 50.0f ), PointState::DOWN, Vector2( 20.0f, 40.0f ), 150 ) );
476 application.ProcessEvent( GenerateDoubleTouch( PointState::MOTION, Vector2( 40.0f, 50.0f ), PointState::MOTION, Vector2( 40.0f, 40.0f ), 151 ) );
477 application.ProcessEvent( GenerateSingleTouch( PointState::UP, Vector2( 50.0f, 50.0f ), 153 ) );
479 application.SendNotification();
481 DALI_TEST_EQUALS(false, data.functorCalled, TEST_LOCATION);
486 int UtcDaliPanGestureRecognizerNewParametersSlowRelease(void)
488 TestApplication application;
490 PanGestureDetector detector = PanGestureDetector::New();
492 detector.SetMaximumTouchesRequired(2);
493 detector.SetMinimumTouchesRequired(2);
495 Actor actor = Actor::New();
496 actor.SetSize(100.0f, 100.0f);
497 actor.SetAnchorPoint(AnchorPoint::TOP_LEFT);
498 Stage::GetCurrent().Add(actor);
501 application.SendNotification();
502 application.Render();
504 detector.Attach(actor);
507 GestureReceivedFunctor functor(data);
508 detector.DetectedSignal().Connect(&application, functor);
510 application.ProcessEvent( GenerateDoubleTouch( PointState::DOWN, Vector2( 20.0f, 50.0f ), PointState::DOWN, Vector2( 20.0f, 40.0f ), 150 ) );
511 application.ProcessEvent( GenerateDoubleTouch( PointState::MOTION, Vector2( 40.0f, 50.0f ), PointState::MOTION, Vector2( 40.0f, 40.0f ), 151 ) );
512 application.ProcessEvent( GenerateDoubleTouch( PointState::MOTION, Vector2( 50.0f, 50.0f ), PointState::MOTION, Vector2( 50.0f, 40.0f ), 152 ) );
513 application.ProcessEvent( GenerateDoubleTouch( PointState::MOTION, Vector2( 60.0f, 50.0f ), PointState::MOTION, Vector2( 60.0f, 40.0f ), 153 ) );
514 application.ProcessEvent( GenerateDoubleTouch( PointState::MOTION, Vector2( 70.0f, 50.0f ), PointState::MOTION, Vector2( 70.0f, 40.0f ), 154 ) );
515 application.ProcessEvent( GenerateSingleTouch( PointState::UP, Vector2( 70.0f, 50.0f ), 155 ) );
517 application.SendNotification();
519 DALI_TEST_EQUALS(true, data.functorCalled, TEST_LOCATION);
524 int UtcDaliPanGestureRecognizerOtherEvent(void)
526 TestApplication application;
528 PanGestureDetector detector = PanGestureDetector::New();
530 Actor actor = Actor::New();
531 actor.SetSize(100.0f, 100.0f);
532 actor.SetAnchorPoint(AnchorPoint::TOP_LEFT);
533 Stage::GetCurrent().Add(actor);
536 application.SendNotification();
537 application.Render();
539 detector.Attach(actor);
542 GestureReceivedFunctor functor(data);
543 detector.DetectedSignal().Connect(&application, functor);
545 application.ProcessEvent( GenerateSingleTouch( PointState::DOWN, Vector2( 20.0f, 20.0f ), 150 ) );
546 application.ProcessEvent( GenerateSingleTouch( PointState::MOTION, Vector2( 20.0f, 40.0f ), 151 ) );
547 application.ProcessEvent( GenerateSingleTouch( PointState::MOTION, Vector2( 20.0f, 60.0f ), 152 ) );
548 application.ProcessEvent( GenerateSingleTouch( PointState::DOWN, Vector2( 20.0f, 60.0f ), 153 ) ); // Exercise default case in Started case. Not sure if realistic
549 application.ProcessEvent( GenerateSingleTouch( PointState::MOTION, Vector2( 20.0f, 65.0f ), 154 ) );
551 application.SendNotification();
553 DALI_TEST_EQUALS(true, data.functorCalled, TEST_LOCATION);
558 int UtcDaliPanGestureRecognizerSlowMoving(void)
560 TestApplication application;
562 PanGestureDetector detector = PanGestureDetector::New();
564 Actor actor = Actor::New();
565 actor.SetSize(100.0f, 100.0f);
566 actor.SetAnchorPoint(AnchorPoint::TOP_LEFT);
567 Stage::GetCurrent().Add(actor);
570 application.SendNotification();
571 application.Render();
573 detector.Attach(actor);
576 GestureReceivedFunctor functor(data);
577 detector.DetectedSignal().Connect(&application, functor);
579 application.ProcessEvent( GenerateSingleTouch( PointState::DOWN, Vector2( 20.0f, 20.0f ), 150 ) );
580 application.ProcessEvent( GenerateSingleTouch( PointState::MOTION, Vector2( 20.0f, 40.0f ), 251 ) );
581 application.ProcessEvent( GenerateSingleTouch( PointState::MOTION, Vector2( 20.0f, 60.0f ), 352 ) );
582 application.ProcessEvent( GenerateSingleTouch( PointState::MOTION, Vector2( 20.0f, 70.0f ), 453 ) );
583 application.ProcessEvent( GenerateSingleTouch( PointState::MOTION, Vector2( 20.0f, 80.0f ), 554 ) );
584 application.ProcessEvent( GenerateSingleTouch( PointState::MOTION, Vector2( 20.0f, 90.0f ), 655 ) );
586 application.SendNotification();
588 DALI_TEST_EQUALS(true, data.functorCalled, TEST_LOCATION);
593 int UtcDaliPanGestureRecognizerNewParamsMinNum(void)
595 TestApplication application;
597 Integration::SetPanGestureMinimumPanEvents(8);
600 PanGestureDetector detector = PanGestureDetector::New();
602 Actor actor = Actor::New();
603 actor.SetSize(100.0f, 100.0f);
604 actor.SetAnchorPoint(AnchorPoint::TOP_LEFT);
605 Stage::GetCurrent().Add(actor);
608 application.SendNotification();
609 application.Render();
611 detector.Attach(actor);
614 GestureReceivedFunctor functor(data);
615 detector.DetectedSignal().Connect(&application, functor);
617 application.ProcessEvent( GenerateSingleTouch( PointState::DOWN, Vector2( 20.0f, 20.0f ), 150 ) );
618 application.ProcessEvent( GenerateSingleTouch( PointState::MOTION, Vector2( 20.0f, 40.0f ), 251 ) );
619 application.ProcessEvent( GenerateSingleTouch( PointState::MOTION, Vector2( 20.0f, 60.0f ), 352 ) );
620 application.ProcessEvent( GenerateSingleTouch( PointState::MOTION, Vector2( 20.0f, 70.0f ), 453 ) );
621 application.ProcessEvent( GenerateSingleTouch( PointState::MOTION, Vector2( 20.0f, 80.0f ), 554 ) );
622 application.ProcessEvent( GenerateSingleTouch( PointState::MOTION, Vector2( 20.0f, 90.0f ), 655 ) );
624 application.SendNotification();
626 DALI_TEST_EQUALS(false, data.functorCalled, TEST_LOCATION);
631 int UtcDaliPanGestureRecognizerNewParamsMinDistance(void)
633 TestApplication application;
635 Integration::SetPanGestureMinimumDistance(100);
637 PanGestureDetector detector = PanGestureDetector::New();
639 Actor actor = Actor::New();
640 actor.SetSize(100.0f, 100.0f);
641 actor.SetAnchorPoint(AnchorPoint::TOP_LEFT);
642 Stage::GetCurrent().Add(actor);
645 application.SendNotification();
646 application.Render();
648 detector.Attach(actor);
651 GestureReceivedFunctor functor(data);
652 detector.DetectedSignal().Connect(&application, functor);
654 application.ProcessEvent( GenerateSingleTouch( PointState::DOWN, Vector2( 20.0f, 20.0f ), 150 ) );
655 application.ProcessEvent( GenerateSingleTouch( PointState::MOTION, Vector2( 20.0f, 40.0f ), 251 ) );
656 application.ProcessEvent( GenerateSingleTouch( PointState::MOTION, Vector2( 20.0f, 60.0f ), 352 ) );
657 application.ProcessEvent( GenerateSingleTouch( PointState::MOTION, Vector2( 20.0f, 70.0f ), 453 ) );
658 application.ProcessEvent( GenerateSingleTouch( PointState::MOTION, Vector2( 20.0f, 80.0f ), 554 ) );
659 application.ProcessEvent( GenerateSingleTouch( PointState::MOTION, Vector2( 20.0f, 90.0f ), 655 ) );
661 application.SendNotification();
663 DALI_TEST_EQUALS(false, data.functorCalled, TEST_LOCATION);