2 * Copyright (c) 2022 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 TapGesture receivedGesture;
57 // Functor that sets the data when called
58 struct GestureReceivedFunctor
60 GestureReceivedFunctor(SignalData& data)
65 void operator()(Actor actor, const TapGesture& tap)
67 signalData.functorCalled = true;
68 signalData.receivedGesture = tap;
69 signalData.tappedActor = 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 state, const Vector2& screenPositionA, const Vector2& screenPositionB, uint32_t time)
95 Integration::TouchEvent touchEvent;
96 Integration::Point point;
97 point.SetState(state);
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 touchEvent.points.push_back(point);
104 touchEvent.time = time;
110 ///////////////////////////////////////////////////////////////////////////////
112 int UtcDaliTapGestureRecognizerBasic(void)
114 TestApplication application;
116 TapGestureDetector detector = TapGestureDetector::New();
118 Actor actor = Actor::New();
119 actor.SetProperty(Actor::Property::SIZE, Vector2(100.0f, 100.0f));
120 actor.SetProperty(Actor::Property::ANCHOR_POINT, AnchorPoint::TOP_LEFT);
121 application.GetScene().Add(actor);
124 application.SendNotification();
125 application.Render();
127 detector.Attach(actor);
130 GestureReceivedFunctor functor(data);
131 detector.DetectedSignal().Connect(&application, functor);
133 application.ProcessEvent(GenerateSingleTouch(PointState::DOWN, Vector2(20.0f, 20.0f), 150));
135 application.ProcessEvent(GenerateSingleTouch(PointState::UP, Vector2(20.0f, 20.0f), 200));
137 application.SendNotification();
139 DALI_TEST_EQUALS(true, data.functorCalled, TEST_LOCATION);
144 int UtcDaliTapGestureRecognizerGapTooLong(void)
146 TestApplication application;
148 TapGestureDetector detector = TapGestureDetector::New();
150 Actor actor = Actor::New();
151 actor.SetProperty(Actor::Property::SIZE, Vector2(100.0f, 100.0f));
152 actor.SetProperty(Actor::Property::ANCHOR_POINT, AnchorPoint::TOP_LEFT);
153 application.GetScene().Add(actor);
156 application.SendNotification();
157 application.Render();
159 detector.Attach(actor);
162 GestureReceivedFunctor functor(data);
163 detector.DetectedSignal().Connect(&application, functor);
165 application.ProcessEvent(GenerateSingleTouch(PointState::DOWN, Vector2(20.0f, 20.0f), 150));
167 application.ProcessEvent(GenerateSingleTouch(PointState::UP, Vector2(20.0f, 20.0f), 651));
169 application.SendNotification();
171 DALI_TEST_EQUALS(false, data.functorCalled, TEST_LOCATION);
176 int UtcDaliTapGestureRecognizerInterrupted(void)
178 TestApplication application;
180 TapGestureDetector detector = TapGestureDetector::New();
182 Actor actor = Actor::New();
183 actor.SetProperty(Actor::Property::SIZE, Vector2(100.0f, 100.0f));
184 actor.SetProperty(Actor::Property::ANCHOR_POINT, AnchorPoint::TOP_LEFT);
185 application.GetScene().Add(actor);
188 application.SendNotification();
189 application.Render();
191 detector.Attach(actor);
194 GestureReceivedFunctor functor(data);
195 detector.DetectedSignal().Connect(&application, functor);
197 application.ProcessEvent(GenerateSingleTouch(PointState::DOWN, Vector2(20.0f, 20.0f), 150));
199 application.ProcessEvent(GenerateSingleTouch(PointState::INTERRUPTED, Vector2(20.0f, 20.0f), 175));
201 application.ProcessEvent(GenerateSingleTouch(PointState::UP, Vector2(20.0f, 20.0f), 200));
203 application.SendNotification();
205 DALI_TEST_EQUALS(false, data.functorCalled, TEST_LOCATION);
210 int UtcDaliTapGestureRecognizerMoveTooFar(void)
212 TestApplication application;
214 TapGestureDetector detector = TapGestureDetector::New();
215 detector.SetMaximumTapsRequired(2);
217 Actor actor = Actor::New();
218 actor.SetProperty(Actor::Property::SIZE, Vector2(100.0f, 100.0f));
219 actor.SetProperty(Actor::Property::ANCHOR_POINT, AnchorPoint::TOP_LEFT);
220 application.GetScene().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));
234 application.ProcessEvent(GenerateSingleTouch(PointState::UP, Vector2(50.0f, 20.0f), 200));
236 application.SendNotification();
238 application.GetPlatform().TriggerTimer();
239 DALI_TEST_EQUALS(false, data.functorCalled, TEST_LOCATION);
244 int UtcDaliTapGestureRecognizerStartDouble(void)
246 TestApplication application;
248 TapGestureDetector detector = TapGestureDetector::New();
250 Actor actor = Actor::New();
251 actor.SetProperty(Actor::Property::SIZE, Vector2(100.0f, 100.0f));
252 actor.SetProperty(Actor::Property::ANCHOR_POINT, AnchorPoint::TOP_LEFT);
253 application.GetScene().Add(actor);
256 application.SendNotification();
257 application.Render();
259 detector.Attach(actor);
262 GestureReceivedFunctor functor(data);
263 detector.DetectedSignal().Connect(&application, functor);
265 application.ProcessEvent(GenerateDoubleTouch(PointState::DOWN, Vector2(20.0f, 20.0f), Vector2(25.0f, 25.0f), 150));
267 application.ProcessEvent(GenerateSingleTouch(PointState::UP, Vector2(20.0f, 20.0f), 200));
269 application.SendNotification();
271 DALI_TEST_EQUALS(false, data.functorCalled, TEST_LOCATION);
276 int UtcDaliTapGestureRecognizerEndDouble(void)
278 TestApplication application;
280 TapGestureDetector detector = TapGestureDetector::New();
282 Actor actor = Actor::New();
283 actor.SetProperty(Actor::Property::SIZE, Vector2(100.0f, 100.0f));
284 actor.SetProperty(Actor::Property::ANCHOR_POINT, AnchorPoint::TOP_LEFT);
285 application.GetScene().Add(actor);
288 application.SendNotification();
289 application.Render();
291 detector.Attach(actor);
294 GestureReceivedFunctor functor(data);
295 detector.DetectedSignal().Connect(&application, functor);
297 application.ProcessEvent(GenerateSingleTouch(PointState::DOWN, Vector2(20.0f, 20.0f), 150));
299 application.ProcessEvent(GenerateDoubleTouch(PointState::DOWN, Vector2(20.0f, 20.0f), Vector2(25.0f, 25.0f), 200));
301 application.ProcessEvent(GenerateDoubleTouch(PointState::UP, Vector2(20.0f, 20.0f), Vector2(25.0f, 25.0f), 200));
303 application.SendNotification();
305 DALI_TEST_EQUALS(false, data.functorCalled, TEST_LOCATION);
310 int UtcDaliTapGestureRecognizerDoubleTap(void)
312 TestApplication application;
314 TapGestureDetector detector = TapGestureDetector::New(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));
333 application.ProcessEvent(GenerateSingleTouch(PointState::UP, Vector2(20.0f, 20.0f), 200));
335 application.SendNotification();
337 DALI_TEST_EQUALS(false, data.functorCalled, TEST_LOCATION);
339 application.ProcessEvent(GenerateSingleTouch(PointState::DOWN, Vector2(20.0f, 20.0f), 250));
341 application.ProcessEvent(GenerateSingleTouch(PointState::UP, Vector2(20.0f, 20.0f), 300));
343 application.SendNotification();
345 DALI_TEST_EQUALS(true, data.functorCalled, TEST_LOCATION);
350 int UtcDaliTapGestureRecognizerDoubleTapMoveTooFar(void)
352 TestApplication application;
354 TapGestureDetector detector = TapGestureDetector::New(2);
356 Actor actor = Actor::New();
357 actor.SetProperty(Actor::Property::SIZE, Vector2(100.0f, 100.0f));
358 actor.SetProperty(Actor::Property::ANCHOR_POINT, AnchorPoint::TOP_LEFT);
359 application.GetScene().Add(actor);
362 application.SendNotification();
363 application.Render();
365 detector.Attach(actor);
368 GestureReceivedFunctor functor(data);
369 detector.DetectedSignal().Connect(&application, functor);
371 application.ProcessEvent(GenerateSingleTouch(PointState::DOWN, Vector2(20.0f, 20.0f), 150));
373 application.ProcessEvent(GenerateSingleTouch(PointState::UP, Vector2(20.0f, 20.0f), 200));
375 application.SendNotification();
377 DALI_TEST_EQUALS(false, data.functorCalled, TEST_LOCATION);
379 application.ProcessEvent(GenerateSingleTouch(PointState::DOWN, Vector2(20.0f, 50.0f), 250));
381 application.ProcessEvent(GenerateSingleTouch(PointState::UP, Vector2(20.0f, 50.0f), 300));
383 application.SendNotification();
385 DALI_TEST_EQUALS(false, data.functorCalled, TEST_LOCATION);
387 application.ProcessEvent(GenerateSingleTouch(PointState::DOWN, Vector2(50.0f, 50.0f), 450));
389 application.ProcessEvent(GenerateSingleTouch(PointState::UP, Vector2(50.0f, 50.0f), 500));
391 application.ProcessEvent(GenerateSingleTouch(PointState::DOWN, Vector2(50.0f, 50.0f), 550));
393 application.ProcessEvent(GenerateSingleTouch(PointState::UP, Vector2(50.0f, 50.0f), 600));
395 application.SendNotification();
397 DALI_TEST_EQUALS(true, data.functorCalled, TEST_LOCATION);
402 int UtcDaliTapGestureRecognizerDoubleTapWaitTooLong(void)
404 TestApplication application;
406 TapGestureDetector detector = TapGestureDetector::New(2);
408 Actor actor = Actor::New();
409 actor.SetProperty(Actor::Property::SIZE, Vector2(100.0f, 100.0f));
410 actor.SetProperty(Actor::Property::ANCHOR_POINT, AnchorPoint::TOP_LEFT);
411 application.GetScene().Add(actor);
414 application.SendNotification();
415 application.Render();
417 detector.Attach(actor);
420 GestureReceivedFunctor functor(data);
421 detector.DetectedSignal().Connect(&application, functor);
423 application.ProcessEvent(GenerateSingleTouch(PointState::DOWN, Vector2(20.0f, 20.0f), 150));
425 application.ProcessEvent(GenerateSingleTouch(PointState::UP, Vector2(20.0f, 20.0f), 200));
427 application.SendNotification();
429 DALI_TEST_EQUALS(false, data.functorCalled, TEST_LOCATION);
431 application.ProcessEvent(GenerateSingleTouch(PointState::DOWN, Vector2(20.0f, 20.0f), 750));
433 application.ProcessEvent(GenerateSingleTouch(PointState::UP, Vector2(20.0f, 20.0f), 850));
435 application.SendNotification();
437 DALI_TEST_EQUALS(false, data.functorCalled, TEST_LOCATION);
439 application.ProcessEvent(GenerateSingleTouch(PointState::DOWN, Vector2(20.0f, 20.0f), 900));
441 application.ProcessEvent(GenerateSingleTouch(PointState::UP, Vector2(20.0f, 20.0f), 1450));
443 application.SendNotification();
445 DALI_TEST_EQUALS(false, data.functorCalled, TEST_LOCATION);
447 application.ProcessEvent(GenerateSingleTouch(PointState::DOWN, Vector2(50.0f, 50.0f), 1500));
449 application.ProcessEvent(GenerateSingleTouch(PointState::UP, Vector2(50.0f, 50.0f), 1550));
451 application.ProcessEvent(GenerateSingleTouch(PointState::DOWN, Vector2(50.0f, 50.0f), 1600));
453 application.ProcessEvent(GenerateSingleTouch(PointState::UP, Vector2(50.0f, 50.0f), 1650));
455 application.SendNotification();
457 DALI_TEST_EQUALS(true, data.functorCalled, TEST_LOCATION);
462 int UtcDaliTapGestureRecognizerMultipleDetectors(void)
464 TestApplication application;
466 Actor actor = Actor::New();
467 actor.SetProperty(Actor::Property::SIZE, Vector2(100.0f, 100.0f));
468 actor.SetProperty(Actor::Property::ANCHOR_POINT, AnchorPoint::TOP_LEFT);
469 application.GetScene().Add(actor);
471 Actor actor2 = Actor::New();
472 actor2.SetProperty(Actor::Property::SIZE, Vector2(100.0f, 100.0f));
473 actor2.SetProperty(Actor::Property::ANCHOR_POINT, AnchorPoint::TOP_LEFT);
474 actor2.SetProperty(Actor::Property::POSITION_X, 100.0f);
475 application.GetScene().Add(actor2);
478 application.SendNotification();
479 application.Render();
481 TapGestureDetector detector = TapGestureDetector::New();
482 detector.Attach(actor);
484 TapGestureDetector detector2 = TapGestureDetector::New(2);
485 detector2.Attach(actor2);
488 GestureReceivedFunctor functor(data);
489 detector.DetectedSignal().Connect(&application, functor);
492 GestureReceivedFunctor functor2(data2);
493 detector2.DetectedSignal().Connect(&application, functor2);
495 application.ProcessEvent(GenerateSingleTouch(PointState::DOWN, Vector2(20.0f, 20.0f), 150));
497 application.ProcessEvent(GenerateSingleTouch(PointState::UP, Vector2(20.0f, 20.0f), 200));
499 application.SendNotification();
501 application.GetPlatform().TriggerTimer();
502 DALI_TEST_EQUALS(true, data.functorCalled, TEST_LOCATION);
503 DALI_TEST_EQUALS(true, actor == data.tappedActor, TEST_LOCATION);
505 DALI_TEST_EQUALS(false, data2.functorCalled, TEST_LOCATION);
507 application.ProcessEvent(GenerateSingleTouch(PointState::DOWN, Vector2(120.0f, 20.0f), 250));
509 application.ProcessEvent(GenerateSingleTouch(PointState::UP, Vector2(120.0f, 20.0f), 300));
511 application.SendNotification();
513 DALI_TEST_EQUALS(false, data2.functorCalled, TEST_LOCATION);
515 application.ProcessEvent(GenerateSingleTouch(PointState::DOWN, Vector2(120.0f, 20.0f), 350));
517 application.ProcessEvent(GenerateSingleTouch(PointState::UP, Vector2(120.0f, 20.0f), 400));
519 application.SendNotification();
521 application.GetPlatform().TriggerTimer();
522 DALI_TEST_EQUALS(false, data.functorCalled, TEST_LOCATION);
523 DALI_TEST_EQUALS(true, data2.functorCalled, TEST_LOCATION);
528 int UtcDaliTapGestureRecognizerTripleTap(void)
530 TestApplication application;
532 TapGestureDetector detector = TapGestureDetector::New(3);
534 Actor actor = Actor::New();
535 actor.SetProperty(Actor::Property::SIZE, Vector2(100.0f, 100.0f));
536 actor.SetProperty(Actor::Property::ANCHOR_POINT, AnchorPoint::TOP_LEFT);
537 application.GetScene().Add(actor);
540 application.SendNotification();
541 application.Render();
543 detector.Attach(actor);
546 GestureReceivedFunctor functor(data);
547 detector.DetectedSignal().Connect(&application, functor);
549 application.ProcessEvent(GenerateSingleTouch(PointState::DOWN, Vector2(20.0f, 20.0f), 150));
551 application.ProcessEvent(GenerateSingleTouch(PointState::UP, Vector2(20.0f, 20.0f), 200));
553 application.SendNotification();
555 DALI_TEST_EQUALS(false, data.functorCalled, TEST_LOCATION);
557 application.ProcessEvent(GenerateSingleTouch(PointState::DOWN, Vector2(20.0f, 20.0f), 250));
559 application.ProcessEvent(GenerateSingleTouch(PointState::UP, Vector2(20.0f, 20.0f), 300));
561 application.SendNotification();
563 DALI_TEST_EQUALS(false, data.functorCalled, TEST_LOCATION);
565 application.ProcessEvent(GenerateSingleTouch(PointState::DOWN, Vector2(20.0f, 20.0f), 350));
567 application.ProcessEvent(GenerateSingleTouch(PointState::UP, Vector2(20.0f, 20.0f), 400));
569 application.SendNotification();
571 DALI_TEST_EQUALS(true, data.functorCalled, TEST_LOCATION);
576 int UtcDaliTapGestureSetMaximumAllowedTime(void)
578 TestApplication application;
580 TapGestureDetector detector = TapGestureDetector::New(2);
582 Actor actor = Actor::New();
583 actor.SetProperty(Actor::Property::SIZE, Vector2(100.0f, 100.0f));
584 actor.SetProperty(Actor::Property::ANCHOR_POINT, AnchorPoint::TOP_LEFT);
585 application.GetScene().Add(actor);
588 application.SendNotification();
589 application.Render();
591 detector.Attach(actor);
595 Integration::SetTapMaximumAllowedTime(0);
599 DALI_TEST_CHECK(false); // Should not get here
602 // Reduce the maximum allowable time. 500 -> 100
603 Integration::SetTapMaximumAllowedTime(100);
606 GestureReceivedFunctor functor(data);
607 detector.DetectedSignal().Connect(&application, functor);
609 application.ProcessEvent(GenerateSingleTouch(PointState::DOWN, Vector2(20.0f, 20.0f), 150));
611 application.ProcessEvent(GenerateSingleTouch(PointState::UP, Vector2(20.0f, 20.0f), 200));
613 application.SendNotification();
615 DALI_TEST_EQUALS(false, data.functorCalled, TEST_LOCATION);
617 application.ProcessEvent(GenerateSingleTouch(PointState::DOWN, Vector2(20.0f, 20.0f), 300));
619 application.ProcessEvent(GenerateSingleTouch(PointState::UP, Vector2(20.0f, 20.0f), 350));
621 application.SendNotification();
623 // The double tap fails because the maximum allowed time has been exceeded
624 DALI_TEST_EQUALS(false, data.functorCalled, TEST_LOCATION);
626 // reset maximum allowed time
627 Integration::SetTapMaximumAllowedTime(500);