2 * Copyright (c) 2021 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), 650));
433 application.ProcessEvent(GenerateSingleTouch(PointState::UP, Vector2(20.0f, 20.0f), 750));
435 application.SendNotification();
437 DALI_TEST_EQUALS(false, data.functorCalled, TEST_LOCATION);
439 application.ProcessEvent(GenerateSingleTouch(PointState::DOWN, Vector2(50.0f, 50.0f), 950));
441 application.ProcessEvent(GenerateSingleTouch(PointState::UP, Vector2(50.0f, 50.0f), 1000));
443 application.ProcessEvent(GenerateSingleTouch(PointState::DOWN, Vector2(50.0f, 50.0f), 1050));
445 application.ProcessEvent(GenerateSingleTouch(PointState::UP, Vector2(50.0f, 50.0f), 1000));
447 application.SendNotification();
449 DALI_TEST_EQUALS(true, data.functorCalled, TEST_LOCATION);
454 int UtcDaliTapGestureRecognizerMultipleDetectors(void)
456 TestApplication application;
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);
463 Actor actor2 = Actor::New();
464 actor2.SetProperty(Actor::Property::SIZE, Vector2(100.0f, 100.0f));
465 actor2.SetProperty(Actor::Property::ANCHOR_POINT, AnchorPoint::TOP_LEFT);
466 actor2.SetProperty(Actor::Property::POSITION_X, 100.0f);
467 application.GetScene().Add(actor2);
470 application.SendNotification();
471 application.Render();
473 TapGestureDetector detector = TapGestureDetector::New();
474 detector.Attach(actor);
476 TapGestureDetector detector2 = TapGestureDetector::New(2);
477 detector2.Attach(actor2);
480 GestureReceivedFunctor functor(data);
481 detector.DetectedSignal().Connect(&application, functor);
484 GestureReceivedFunctor functor2(data2);
485 detector2.DetectedSignal().Connect(&application, functor2);
487 application.ProcessEvent(GenerateSingleTouch(PointState::DOWN, Vector2(20.0f, 20.0f), 150));
489 application.ProcessEvent(GenerateSingleTouch(PointState::UP, Vector2(20.0f, 20.0f), 200));
491 application.SendNotification();
493 application.GetPlatform().TriggerTimer();
494 DALI_TEST_EQUALS(true, data.functorCalled, TEST_LOCATION);
495 DALI_TEST_EQUALS(true, actor == data.tappedActor, TEST_LOCATION);
497 DALI_TEST_EQUALS(false, data2.functorCalled, TEST_LOCATION);
499 application.ProcessEvent(GenerateSingleTouch(PointState::DOWN, Vector2(120.0f, 20.0f), 250));
501 application.ProcessEvent(GenerateSingleTouch(PointState::UP, Vector2(120.0f, 20.0f), 300));
503 application.SendNotification();
505 DALI_TEST_EQUALS(false, data2.functorCalled, TEST_LOCATION);
507 application.ProcessEvent(GenerateSingleTouch(PointState::DOWN, Vector2(120.0f, 20.0f), 350));
509 application.ProcessEvent(GenerateSingleTouch(PointState::UP, Vector2(120.0f, 20.0f), 400));
511 application.SendNotification();
513 application.GetPlatform().TriggerTimer();
514 DALI_TEST_EQUALS(false, data.functorCalled, TEST_LOCATION);
515 DALI_TEST_EQUALS(true, data2.functorCalled, TEST_LOCATION);
520 int UtcDaliTapGestureRecognizerTripleTap(void)
522 TestApplication application;
524 TapGestureDetector detector = TapGestureDetector::New(3);
526 Actor actor = Actor::New();
527 actor.SetProperty(Actor::Property::SIZE, Vector2(100.0f, 100.0f));
528 actor.SetProperty(Actor::Property::ANCHOR_POINT, AnchorPoint::TOP_LEFT);
529 application.GetScene().Add(actor);
532 application.SendNotification();
533 application.Render();
535 detector.Attach(actor);
538 GestureReceivedFunctor functor(data);
539 detector.DetectedSignal().Connect(&application, functor);
541 application.ProcessEvent(GenerateSingleTouch(PointState::DOWN, Vector2(20.0f, 20.0f), 150));
543 application.ProcessEvent(GenerateSingleTouch(PointState::UP, Vector2(20.0f, 20.0f), 200));
545 application.SendNotification();
547 DALI_TEST_EQUALS(false, data.functorCalled, TEST_LOCATION);
549 application.ProcessEvent(GenerateSingleTouch(PointState::DOWN, Vector2(20.0f, 20.0f), 250));
551 application.ProcessEvent(GenerateSingleTouch(PointState::UP, Vector2(20.0f, 20.0f), 300));
553 application.SendNotification();
555 DALI_TEST_EQUALS(false, data.functorCalled, TEST_LOCATION);
557 application.ProcessEvent(GenerateSingleTouch(PointState::DOWN, Vector2(20.0f, 20.0f), 350));
559 application.ProcessEvent(GenerateSingleTouch(PointState::UP, Vector2(20.0f, 20.0f), 400));
561 application.SendNotification();
563 DALI_TEST_EQUALS(true, data.functorCalled, TEST_LOCATION);
568 int UtcDaliTapGestureSetMaximumAllowedTime(void)
570 TestApplication application;
572 TapGestureDetector detector = TapGestureDetector::New(2);
574 Actor actor = Actor::New();
575 actor.SetProperty(Actor::Property::SIZE, Vector2(100.0f, 100.0f));
576 actor.SetProperty(Actor::Property::ANCHOR_POINT, AnchorPoint::TOP_LEFT);
577 application.GetScene().Add(actor);
580 application.SendNotification();
581 application.Render();
583 detector.Attach(actor);
587 Integration::SetTapMaximumAllowedTime(0);
591 DALI_TEST_CHECK(false); // Should not get here
594 // Reduce the maximum allowable time. 500 -> 100
595 Integration::SetTapMaximumAllowedTime(100);
598 GestureReceivedFunctor functor(data);
599 detector.DetectedSignal().Connect(&application, functor);
601 application.ProcessEvent(GenerateSingleTouch(PointState::DOWN, Vector2(20.0f, 20.0f), 150));
603 application.ProcessEvent(GenerateSingleTouch(PointState::UP, Vector2(20.0f, 20.0f), 200));
605 application.SendNotification();
607 DALI_TEST_EQUALS(false, data.functorCalled, TEST_LOCATION);
609 application.ProcessEvent(GenerateSingleTouch(PointState::DOWN, Vector2(20.0f, 20.0f), 250));
611 application.ProcessEvent(GenerateSingleTouch(PointState::UP, Vector2(20.0f, 20.0f), 300));
613 application.SendNotification();
615 // The double tap fails because the maximum allowed time has been exceeded
616 DALI_TEST_EQUALS(false, data.functorCalled, TEST_LOCATION);
618 // reset maximum allowed time
619 Integration::SetTapMaximumAllowedTime(500);