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/render-task-list-integ.h>
21 #include <dali/public-api/dali-core.h>
28 ///////////////////////////////////////////////////////////////////////////////
34 : functorCalled(false),
35 voidFunctorCalled(false),
42 functorCalled = false;
43 voidFunctorCalled = false;
45 receivedGesture.Reset();
51 bool voidFunctorCalled;
52 TapGesture receivedGesture;
56 // Functor that sets the data when called
57 struct GestureReceivedFunctor
59 GestureReceivedFunctor(SignalData& data)
64 void operator()(Actor actor, const TapGesture& tap)
66 signalData.functorCalled = true;
67 signalData.receivedGesture = tap;
68 signalData.tappedActor = actor;
73 signalData.voidFunctorCalled = true;
76 SignalData& signalData;
79 Integration::TouchEvent GenerateSingleTouch(PointState::Type state, const Vector2& screenPosition, uint32_t time)
81 Integration::TouchEvent touchEvent;
82 Integration::Point point;
83 point.SetState(state);
84 point.SetScreenPosition(screenPosition);
85 point.SetDeviceClass(Device::Class::TOUCH);
86 point.SetDeviceSubclass(Device::Subclass::NONE);
87 touchEvent.points.push_back(point);
88 touchEvent.time = time;
92 Integration::TouchEvent GenerateDoubleTouch(PointState::Type state, const Vector2& screenPositionA, const Vector2& screenPositionB, uint32_t time)
94 Integration::TouchEvent touchEvent;
95 Integration::Point point;
96 point.SetState(state);
97 point.SetScreenPosition(screenPositionA);
98 point.SetDeviceClass(Device::Class::TOUCH);
99 point.SetDeviceSubclass(Device::Subclass::NONE);
100 touchEvent.points.push_back(point);
101 point.SetScreenPosition(screenPositionB);
102 touchEvent.points.push_back(point);
103 touchEvent.time = time;
109 ///////////////////////////////////////////////////////////////////////////////
111 int UtcDaliTapGestureRecognizerBasic(void)
113 TestApplication application;
115 TapGestureDetector detector = TapGestureDetector::New();
117 Actor actor = Actor::New();
118 actor.SetProperty(Actor::Property::SIZE, Vector2(100.0f, 100.0f));
119 actor.SetProperty(Actor::Property::ANCHOR_POINT, AnchorPoint::TOP_LEFT);
120 application.GetScene().Add(actor);
123 application.SendNotification();
124 application.Render();
126 detector.Attach(actor);
129 GestureReceivedFunctor functor(data);
130 detector.DetectedSignal().Connect(&application, functor);
132 application.ProcessEvent(GenerateSingleTouch(PointState::DOWN, Vector2(20.0f, 20.0f), 150));
134 application.ProcessEvent(GenerateSingleTouch(PointState::UP, Vector2(20.0f, 20.0f), 200));
136 application.SendNotification();
138 DALI_TEST_EQUALS(true, data.functorCalled, TEST_LOCATION);
143 int UtcDaliTapGestureRecognizerGapTooLong(void)
145 TestApplication application;
147 TapGestureDetector detector = TapGestureDetector::New();
149 Actor actor = Actor::New();
150 actor.SetProperty(Actor::Property::SIZE, Vector2(100.0f, 100.0f));
151 actor.SetProperty(Actor::Property::ANCHOR_POINT, AnchorPoint::TOP_LEFT);
152 application.GetScene().Add(actor);
155 application.SendNotification();
156 application.Render();
158 detector.Attach(actor);
161 GestureReceivedFunctor functor(data);
162 detector.DetectedSignal().Connect(&application, functor);
164 application.ProcessEvent(GenerateSingleTouch(PointState::DOWN, Vector2(20.0f, 20.0f), 150));
166 application.ProcessEvent(GenerateSingleTouch(PointState::UP, Vector2(20.0f, 20.0f), 651));
168 application.SendNotification();
170 DALI_TEST_EQUALS(false, data.functorCalled, TEST_LOCATION);
175 int UtcDaliTapGestureRecognizerInterrupted(void)
177 TestApplication application;
179 TapGestureDetector detector = TapGestureDetector::New();
181 Actor actor = Actor::New();
182 actor.SetProperty(Actor::Property::SIZE, Vector2(100.0f, 100.0f));
183 actor.SetProperty(Actor::Property::ANCHOR_POINT, AnchorPoint::TOP_LEFT);
184 application.GetScene().Add(actor);
187 application.SendNotification();
188 application.Render();
190 detector.Attach(actor);
193 GestureReceivedFunctor functor(data);
194 detector.DetectedSignal().Connect(&application, functor);
196 application.ProcessEvent(GenerateSingleTouch(PointState::DOWN, Vector2(20.0f, 20.0f), 150));
198 application.ProcessEvent(GenerateSingleTouch(PointState::INTERRUPTED, Vector2(20.0f, 20.0f), 175));
200 application.ProcessEvent(GenerateSingleTouch(PointState::UP, Vector2(20.0f, 20.0f), 200));
202 application.SendNotification();
204 DALI_TEST_EQUALS(false, data.functorCalled, TEST_LOCATION);
209 int UtcDaliTapGestureRecognizerMoveTooFar(void)
211 TestApplication application;
213 TapGestureDetector detector = TapGestureDetector::New();
214 detector.SetMaximumTapsRequired(2);
216 Actor actor = Actor::New();
217 actor.SetProperty(Actor::Property::SIZE, Vector2(100.0f, 100.0f));
218 actor.SetProperty(Actor::Property::ANCHOR_POINT, AnchorPoint::TOP_LEFT);
219 application.GetScene().Add(actor);
222 application.SendNotification();
223 application.Render();
225 detector.Attach(actor);
228 GestureReceivedFunctor functor(data);
229 detector.DetectedSignal().Connect(&application, functor);
231 application.ProcessEvent(GenerateSingleTouch(PointState::DOWN, Vector2(20.0f, 20.0f), 150));
233 application.ProcessEvent(GenerateSingleTouch(PointState::UP, Vector2(50.0f, 20.0f), 200));
235 application.SendNotification();
237 application.GetPlatform().TriggerTimer();
238 DALI_TEST_EQUALS(false, data.functorCalled, TEST_LOCATION);
243 int UtcDaliTapGestureRecognizerStartDouble(void)
245 TestApplication application;
247 TapGestureDetector detector = TapGestureDetector::New();
249 Actor actor = Actor::New();
250 actor.SetProperty(Actor::Property::SIZE, Vector2(100.0f, 100.0f));
251 actor.SetProperty(Actor::Property::ANCHOR_POINT, AnchorPoint::TOP_LEFT);
252 application.GetScene().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(GenerateDoubleTouch(PointState::DOWN, Vector2(20.0f, 20.0f), Vector2(25.0f, 25.0f), 150));
266 application.ProcessEvent(GenerateSingleTouch(PointState::UP, Vector2(20.0f, 20.0f), 200));
268 application.SendNotification();
270 DALI_TEST_EQUALS(false, data.functorCalled, TEST_LOCATION);
275 int UtcDaliTapGestureRecognizerEndDouble(void)
277 TestApplication application;
279 TapGestureDetector detector = TapGestureDetector::New();
281 Actor actor = Actor::New();
282 actor.SetProperty(Actor::Property::SIZE, Vector2(100.0f, 100.0f));
283 actor.SetProperty(Actor::Property::ANCHOR_POINT, AnchorPoint::TOP_LEFT);
284 application.GetScene().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));
298 application.ProcessEvent(GenerateDoubleTouch(PointState::DOWN, Vector2(20.0f, 20.0f), Vector2(25.0f, 25.0f), 200));
300 application.ProcessEvent(GenerateDoubleTouch(PointState::UP, Vector2(20.0f, 20.0f), Vector2(25.0f, 25.0f), 200));
302 application.SendNotification();
304 DALI_TEST_EQUALS(false, data.functorCalled, TEST_LOCATION);
309 int UtcDaliTapGestureRecognizerDoubleTap(void)
311 TestApplication application;
313 TapGestureDetector detector = TapGestureDetector::New(2);
315 Actor actor = Actor::New();
316 actor.SetProperty(Actor::Property::SIZE, Vector2(100.0f, 100.0f));
317 actor.SetProperty(Actor::Property::ANCHOR_POINT, AnchorPoint::TOP_LEFT);
318 application.GetScene().Add(actor);
321 application.SendNotification();
322 application.Render();
324 detector.Attach(actor);
327 GestureReceivedFunctor functor(data);
328 detector.DetectedSignal().Connect(&application, functor);
330 application.ProcessEvent(GenerateSingleTouch(PointState::DOWN, Vector2(20.0f, 20.0f), 150));
332 application.ProcessEvent(GenerateSingleTouch(PointState::UP, Vector2(20.0f, 20.0f), 200));
334 application.SendNotification();
336 DALI_TEST_EQUALS(false, data.functorCalled, TEST_LOCATION);
338 application.ProcessEvent(GenerateSingleTouch(PointState::DOWN, Vector2(20.0f, 20.0f), 250));
340 application.ProcessEvent(GenerateSingleTouch(PointState::UP, Vector2(20.0f, 20.0f), 300));
342 application.SendNotification();
344 DALI_TEST_EQUALS(true, data.functorCalled, TEST_LOCATION);
349 int UtcDaliTapGestureRecognizerDoubleTapMoveTooFar(void)
351 TestApplication application;
353 TapGestureDetector detector = TapGestureDetector::New(2);
355 Actor actor = Actor::New();
356 actor.SetProperty(Actor::Property::SIZE, Vector2(100.0f, 100.0f));
357 actor.SetProperty(Actor::Property::ANCHOR_POINT, AnchorPoint::TOP_LEFT);
358 application.GetScene().Add(actor);
361 application.SendNotification();
362 application.Render();
364 detector.Attach(actor);
367 GestureReceivedFunctor functor(data);
368 detector.DetectedSignal().Connect(&application, functor);
370 application.ProcessEvent(GenerateSingleTouch(PointState::DOWN, Vector2(20.0f, 20.0f), 150));
372 application.ProcessEvent(GenerateSingleTouch(PointState::UP, Vector2(20.0f, 20.0f), 200));
374 application.SendNotification();
376 DALI_TEST_EQUALS(false, data.functorCalled, TEST_LOCATION);
378 application.ProcessEvent(GenerateSingleTouch(PointState::DOWN, Vector2(20.0f, 50.0f), 250));
380 application.ProcessEvent(GenerateSingleTouch(PointState::UP, Vector2(20.0f, 50.0f), 300));
382 application.SendNotification();
384 DALI_TEST_EQUALS(false, data.functorCalled, TEST_LOCATION);
386 application.ProcessEvent(GenerateSingleTouch(PointState::DOWN, Vector2(50.0f, 50.0f), 450));
388 application.ProcessEvent(GenerateSingleTouch(PointState::UP, Vector2(50.0f, 50.0f), 500));
390 application.ProcessEvent(GenerateSingleTouch(PointState::DOWN, Vector2(50.0f, 50.0f), 550));
392 application.ProcessEvent(GenerateSingleTouch(PointState::UP, Vector2(50.0f, 50.0f), 600));
394 application.SendNotification();
396 DALI_TEST_EQUALS(true, data.functorCalled, TEST_LOCATION);
401 int UtcDaliTapGestureRecognizerDoubleTapWaitTooLong(void)
403 TestApplication application;
405 TapGestureDetector detector = TapGestureDetector::New(2);
407 Actor actor = Actor::New();
408 actor.SetProperty(Actor::Property::SIZE, Vector2(100.0f, 100.0f));
409 actor.SetProperty(Actor::Property::ANCHOR_POINT, AnchorPoint::TOP_LEFT);
410 application.GetScene().Add(actor);
413 application.SendNotification();
414 application.Render();
416 detector.Attach(actor);
419 GestureReceivedFunctor functor(data);
420 detector.DetectedSignal().Connect(&application, functor);
422 application.ProcessEvent(GenerateSingleTouch(PointState::DOWN, Vector2(20.0f, 20.0f), 150));
424 application.ProcessEvent(GenerateSingleTouch(PointState::UP, Vector2(20.0f, 20.0f), 200));
426 application.SendNotification();
428 DALI_TEST_EQUALS(false, data.functorCalled, TEST_LOCATION);
430 application.ProcessEvent(GenerateSingleTouch(PointState::DOWN, Vector2(20.0f, 20.0f), 650));
432 application.ProcessEvent(GenerateSingleTouch(PointState::UP, Vector2(20.0f, 20.0f), 750));
434 application.SendNotification();
436 DALI_TEST_EQUALS(false, data.functorCalled, TEST_LOCATION);
438 application.ProcessEvent(GenerateSingleTouch(PointState::DOWN, Vector2(50.0f, 50.0f), 950));
440 application.ProcessEvent(GenerateSingleTouch(PointState::UP, Vector2(50.0f, 50.0f), 1000));
442 application.ProcessEvent(GenerateSingleTouch(PointState::DOWN, Vector2(50.0f, 50.0f), 1050));
444 application.ProcessEvent(GenerateSingleTouch(PointState::UP, Vector2(50.0f, 50.0f), 1000));
446 application.SendNotification();
448 DALI_TEST_EQUALS(true, data.functorCalled, TEST_LOCATION);
453 int UtcDaliTapGestureRecognizerMultipleDetectors(void)
455 TestApplication application;
457 Actor actor = Actor::New();
458 actor.SetProperty(Actor::Property::SIZE, Vector2(100.0f, 100.0f));
459 actor.SetProperty(Actor::Property::ANCHOR_POINT, AnchorPoint::TOP_LEFT);
460 application.GetScene().Add(actor);
462 Actor actor2 = Actor::New();
463 actor2.SetProperty(Actor::Property::SIZE, Vector2(100.0f, 100.0f));
464 actor2.SetProperty(Actor::Property::ANCHOR_POINT, AnchorPoint::TOP_LEFT);
465 actor2.SetProperty(Actor::Property::POSITION_X, 100.0f);
466 application.GetScene().Add(actor2);
469 application.SendNotification();
470 application.Render();
472 TapGestureDetector detector = TapGestureDetector::New();
473 detector.Attach(actor);
475 TapGestureDetector detector2 = TapGestureDetector::New(2);
476 detector2.Attach(actor2);
479 GestureReceivedFunctor functor(data);
480 detector.DetectedSignal().Connect(&application, functor);
483 GestureReceivedFunctor functor2(data2);
484 detector2.DetectedSignal().Connect(&application, functor2);
486 application.ProcessEvent(GenerateSingleTouch(PointState::DOWN, Vector2(20.0f, 20.0f), 150));
488 application.ProcessEvent(GenerateSingleTouch(PointState::UP, Vector2(20.0f, 20.0f), 200));
490 application.SendNotification();
492 application.GetPlatform().TriggerTimer();
493 DALI_TEST_EQUALS(true, data.functorCalled, TEST_LOCATION);
494 DALI_TEST_EQUALS(true, actor == data.tappedActor, TEST_LOCATION);
496 DALI_TEST_EQUALS(false, data2.functorCalled, TEST_LOCATION);
498 application.ProcessEvent(GenerateSingleTouch(PointState::DOWN, Vector2(120.0f, 20.0f), 250));
500 application.ProcessEvent(GenerateSingleTouch(PointState::UP, Vector2(120.0f, 20.0f), 300));
502 application.SendNotification();
504 DALI_TEST_EQUALS(false, data2.functorCalled, TEST_LOCATION);
506 application.ProcessEvent(GenerateSingleTouch(PointState::DOWN, Vector2(120.0f, 20.0f), 350));
508 application.ProcessEvent(GenerateSingleTouch(PointState::UP, Vector2(120.0f, 20.0f), 400));
510 application.SendNotification();
512 application.GetPlatform().TriggerTimer();
513 DALI_TEST_EQUALS(false, data.functorCalled, TEST_LOCATION);
514 DALI_TEST_EQUALS(true, data2.functorCalled, TEST_LOCATION);
519 int UtcDaliTapGestureRecognizerTripleTap(void)
521 TestApplication application;
523 TapGestureDetector detector = TapGestureDetector::New(3);
525 Actor actor = Actor::New();
526 actor.SetProperty(Actor::Property::SIZE, Vector2(100.0f, 100.0f));
527 actor.SetProperty(Actor::Property::ANCHOR_POINT, AnchorPoint::TOP_LEFT);
528 application.GetScene().Add(actor);
531 application.SendNotification();
532 application.Render();
534 detector.Attach(actor);
537 GestureReceivedFunctor functor(data);
538 detector.DetectedSignal().Connect(&application, functor);
540 application.ProcessEvent(GenerateSingleTouch(PointState::DOWN, Vector2(20.0f, 20.0f), 150));
542 application.ProcessEvent(GenerateSingleTouch(PointState::UP, Vector2(20.0f, 20.0f), 200));
544 application.SendNotification();
546 DALI_TEST_EQUALS(false, data.functorCalled, TEST_LOCATION);
548 application.ProcessEvent(GenerateSingleTouch(PointState::DOWN, Vector2(20.0f, 20.0f), 250));
550 application.ProcessEvent(GenerateSingleTouch(PointState::UP, Vector2(20.0f, 20.0f), 300));
552 application.SendNotification();
554 DALI_TEST_EQUALS(false, data.functorCalled, TEST_LOCATION);
556 application.ProcessEvent(GenerateSingleTouch(PointState::DOWN, Vector2(20.0f, 20.0f), 350));
558 application.ProcessEvent(GenerateSingleTouch(PointState::UP, Vector2(20.0f, 20.0f), 400));
560 application.SendNotification();
562 DALI_TEST_EQUALS(true, data.functorCalled, TEST_LOCATION);