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/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();
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));
232 application.ProcessEvent(GenerateSingleTouch(PointState::UP, Vector2(50.0f, 20.0f), 200));
234 application.SendNotification();
236 DALI_TEST_EQUALS(false, data.functorCalled, TEST_LOCATION);
241 int UtcDaliTapGestureRecognizerStartDouble(void)
243 TestApplication application;
245 TapGestureDetector detector = TapGestureDetector::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(GenerateDoubleTouch(PointState::DOWN, Vector2(20.0f, 20.0f), Vector2(25.0f, 25.0f), 150));
264 application.ProcessEvent(GenerateSingleTouch(PointState::UP, Vector2(20.0f, 20.0f), 200));
266 application.SendNotification();
268 DALI_TEST_EQUALS(false, data.functorCalled, TEST_LOCATION);
273 int UtcDaliTapGestureRecognizerEndDouble(void)
275 TestApplication application;
277 TapGestureDetector detector = TapGestureDetector::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));
296 application.ProcessEvent(GenerateDoubleTouch(PointState::DOWN, Vector2(20.0f, 20.0f), Vector2(25.0f, 25.0f), 200));
298 application.ProcessEvent(GenerateDoubleTouch(PointState::UP, Vector2(20.0f, 20.0f), Vector2(25.0f, 25.0f), 200));
300 application.SendNotification();
302 DALI_TEST_EQUALS(false, data.functorCalled, TEST_LOCATION);
307 int UtcDaliTapGestureRecognizerDoubleTap(void)
309 TestApplication application;
311 TapGestureDetector detector = TapGestureDetector::New(2);
313 Actor actor = Actor::New();
314 actor.SetProperty(Actor::Property::SIZE, Vector2(100.0f, 100.0f));
315 actor.SetProperty(Actor::Property::ANCHOR_POINT, AnchorPoint::TOP_LEFT);
316 application.GetScene().Add(actor);
319 application.SendNotification();
320 application.Render();
322 detector.Attach(actor);
325 GestureReceivedFunctor functor(data);
326 detector.DetectedSignal().Connect(&application, functor);
328 application.ProcessEvent(GenerateSingleTouch(PointState::DOWN, Vector2(20.0f, 20.0f), 150));
330 application.ProcessEvent(GenerateSingleTouch(PointState::UP, Vector2(20.0f, 20.0f), 200));
332 application.SendNotification();
334 DALI_TEST_EQUALS(false, data.functorCalled, TEST_LOCATION);
336 application.ProcessEvent(GenerateSingleTouch(PointState::DOWN, Vector2(20.0f, 20.0f), 250));
338 application.ProcessEvent(GenerateSingleTouch(PointState::UP, Vector2(20.0f, 20.0f), 300));
340 application.SendNotification();
342 DALI_TEST_EQUALS(true, data.functorCalled, TEST_LOCATION);
347 int UtcDaliTapGestureRecognizerDoubleTapMoveTooFar(void)
349 TestApplication application;
351 TapGestureDetector detector = TapGestureDetector::New(2);
353 Actor actor = Actor::New();
354 actor.SetProperty(Actor::Property::SIZE, Vector2(100.0f, 100.0f));
355 actor.SetProperty(Actor::Property::ANCHOR_POINT, AnchorPoint::TOP_LEFT);
356 application.GetScene().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(GenerateSingleTouch(PointState::DOWN, Vector2(20.0f, 20.0f), 150));
370 application.ProcessEvent(GenerateSingleTouch(PointState::UP, Vector2(20.0f, 20.0f), 200));
372 application.SendNotification();
374 DALI_TEST_EQUALS(false, data.functorCalled, TEST_LOCATION);
376 application.ProcessEvent(GenerateSingleTouch(PointState::DOWN, Vector2(20.0f, 50.0f), 250));
378 application.ProcessEvent(GenerateSingleTouch(PointState::UP, Vector2(20.0f, 50.0f), 300));
380 application.SendNotification();
382 DALI_TEST_EQUALS(false, data.functorCalled, TEST_LOCATION);
384 application.ProcessEvent(GenerateSingleTouch(PointState::DOWN, Vector2(50.0f, 50.0f), 450));
386 application.ProcessEvent(GenerateSingleTouch(PointState::UP, Vector2(50.0f, 50.0f), 500));
388 application.ProcessEvent(GenerateSingleTouch(PointState::DOWN, Vector2(50.0f, 50.0f), 550));
390 application.ProcessEvent(GenerateSingleTouch(PointState::UP, Vector2(50.0f, 50.0f), 600));
392 application.SendNotification();
394 DALI_TEST_EQUALS(true, data.functorCalled, TEST_LOCATION);
399 int UtcDaliTapGestureRecognizerDoubleTapWaitTooLong(void)
401 TestApplication application;
403 TapGestureDetector detector = TapGestureDetector::New(2);
405 Actor actor = Actor::New();
406 actor.SetProperty(Actor::Property::SIZE, Vector2(100.0f, 100.0f));
407 actor.SetProperty(Actor::Property::ANCHOR_POINT, AnchorPoint::TOP_LEFT);
408 application.GetScene().Add(actor);
411 application.SendNotification();
412 application.Render();
414 detector.Attach(actor);
417 GestureReceivedFunctor functor(data);
418 detector.DetectedSignal().Connect(&application, functor);
420 application.ProcessEvent(GenerateSingleTouch(PointState::DOWN, Vector2(20.0f, 20.0f), 150));
422 application.ProcessEvent(GenerateSingleTouch(PointState::UP, Vector2(20.0f, 20.0f), 200));
424 application.SendNotification();
426 DALI_TEST_EQUALS(false, data.functorCalled, TEST_LOCATION);
428 application.ProcessEvent(GenerateSingleTouch(PointState::DOWN, Vector2(20.0f, 20.0f), 650));
430 application.ProcessEvent(GenerateSingleTouch(PointState::UP, Vector2(20.0f, 20.0f), 750));
432 application.SendNotification();
434 DALI_TEST_EQUALS(false, data.functorCalled, TEST_LOCATION);
436 application.ProcessEvent(GenerateSingleTouch(PointState::DOWN, Vector2(50.0f, 50.0f), 950));
438 application.ProcessEvent(GenerateSingleTouch(PointState::UP, Vector2(50.0f, 50.0f), 1000));
440 application.ProcessEvent(GenerateSingleTouch(PointState::DOWN, Vector2(50.0f, 50.0f), 1050));
442 application.ProcessEvent(GenerateSingleTouch(PointState::UP, Vector2(50.0f, 50.0f), 1000));
444 application.SendNotification();
446 DALI_TEST_EQUALS(true, data.functorCalled, TEST_LOCATION);
451 int UtcDaliTapGestureRecognizerMultipleDetectors(void)
453 TestApplication application;
455 Actor actor = Actor::New();
456 actor.SetProperty(Actor::Property::SIZE, Vector2(100.0f, 100.0f));
457 actor.SetProperty(Actor::Property::ANCHOR_POINT, AnchorPoint::TOP_LEFT);
458 application.GetScene().Add(actor);
460 Actor actor2 = Actor::New();
461 actor2.SetProperty(Actor::Property::SIZE, Vector2(100.0f, 100.0f));
462 actor2.SetProperty(Actor::Property::ANCHOR_POINT, AnchorPoint::TOP_LEFT);
463 actor2.SetProperty(Actor::Property::POSITION_X, 100.0f);
464 application.GetScene().Add(actor2);
467 application.SendNotification();
468 application.Render();
470 TapGestureDetector detector = TapGestureDetector::New();
471 detector.Attach(actor);
473 TapGestureDetector detector2 = TapGestureDetector::New(2);
474 detector2.Attach(actor2);
477 GestureReceivedFunctor functor(data);
478 detector.DetectedSignal().Connect(&application, functor);
481 GestureReceivedFunctor functor2(data2);
482 detector2.DetectedSignal().Connect(&application, functor2);
484 application.ProcessEvent(GenerateSingleTouch(PointState::DOWN, Vector2(20.0f, 20.0f), 150));
486 application.ProcessEvent(GenerateSingleTouch(PointState::UP, Vector2(20.0f, 20.0f), 200));
488 application.SendNotification();
490 DALI_TEST_EQUALS(true, data.functorCalled, TEST_LOCATION);
491 DALI_TEST_EQUALS(true, actor == data.tappedActor, TEST_LOCATION);
493 DALI_TEST_EQUALS(false, data2.functorCalled, TEST_LOCATION);
495 application.ProcessEvent(GenerateSingleTouch(PointState::DOWN, Vector2(120.0f, 20.0f), 250));
497 application.ProcessEvent(GenerateSingleTouch(PointState::UP, Vector2(120.0f, 20.0f), 300));
499 application.SendNotification();
501 DALI_TEST_EQUALS(false, data2.functorCalled, TEST_LOCATION);
503 application.ProcessEvent(GenerateSingleTouch(PointState::DOWN, Vector2(120.0f, 20.0f), 350));
505 application.ProcessEvent(GenerateSingleTouch(PointState::UP, Vector2(120.0f, 20.0f), 400));
507 application.SendNotification();
509 DALI_TEST_EQUALS(false, data.functorCalled, TEST_LOCATION);
510 DALI_TEST_EQUALS(true, data2.functorCalled, TEST_LOCATION);