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/events/touch-event-integ.h>
23 #include <dali/integration-api/render-task-list-integ.h>
24 #include <dali/internal/event/events/tap-gesture-event.h>
25 #include <dali-test-suite-utils.h>
26 #include <test-touch-utils.h>
30 ///////////////////////////////////////////////////////////////////////////////
37 : functorCalled(false),
38 voidFunctorCalled(false),
44 functorCalled = false;
45 voidFunctorCalled = false;
47 receivedGesture.state = Gesture::Started;
53 bool voidFunctorCalled;
54 TapGesture receivedGesture;
58 // Functor that sets the data when called
59 struct GestureReceivedFunctor
61 GestureReceivedFunctor(SignalData& data) : signalData(data) { }
63 void operator()(Actor actor, const TapGesture& tap)
65 signalData.functorCalled = true;
66 signalData.receivedGesture = tap;
67 signalData.tappedActor = actor;
72 signalData.voidFunctorCalled = true;
75 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;
110 ///////////////////////////////////////////////////////////////////////////////
113 int UtcDaliTapGestureRecognizerBasic(void)
115 TestApplication application;
117 TapGestureDetector detector = TapGestureDetector::New();
119 Actor actor = Actor::New();
120 actor.SetSize(100.0f, 100.0f);
121 actor.SetAnchorPoint(AnchorPoint::TOP_LEFT);
122 Stage::GetCurrent().Add(actor);
125 application.SendNotification();
126 application.Render();
128 detector.Attach(actor);
131 GestureReceivedFunctor functor(data);
132 detector.DetectedSignal().Connect(&application, functor);
134 application.ProcessEvent( GenerateSingleTouch( PointState::DOWN, Vector2( 20.0f, 20.0f ), 150 ) );
136 application.ProcessEvent( GenerateSingleTouch( PointState::UP, Vector2( 20.0f, 20.0f ), 200 ) );
138 application.SendNotification();
140 DALI_TEST_EQUALS(true, data.functorCalled, TEST_LOCATION);
146 int UtcDaliTapGestureRecognizerGapTooLong(void)
148 TestApplication application;
150 TapGestureDetector detector = TapGestureDetector::New();
152 Actor actor = Actor::New();
153 actor.SetSize(100.0f, 100.0f);
154 actor.SetAnchorPoint(AnchorPoint::TOP_LEFT);
155 Stage::GetCurrent().Add(actor);
158 application.SendNotification();
159 application.Render();
161 detector.Attach(actor);
164 GestureReceivedFunctor functor(data);
165 detector.DetectedSignal().Connect(&application, functor);
167 application.ProcessEvent( GenerateSingleTouch( PointState::DOWN, Vector2( 20.0f, 20.0f ), 150 ) );
169 application.ProcessEvent( GenerateSingleTouch( PointState::UP, Vector2( 20.0f, 20.0f ), 651 ) );
171 application.SendNotification();
173 DALI_TEST_EQUALS(false, data.functorCalled, TEST_LOCATION);
179 int UtcDaliTapGestureRecognizerInterrupted(void)
181 TestApplication application;
183 TapGestureDetector detector = TapGestureDetector::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 ) );
202 application.ProcessEvent( GenerateSingleTouch( PointState::INTERRUPTED, Vector2( 20.0f, 20.0f ), 175 ) );
204 application.ProcessEvent( GenerateSingleTouch( PointState::UP, Vector2( 20.0f, 20.0f ), 200 ) );
206 application.SendNotification();
208 DALI_TEST_EQUALS(false, data.functorCalled, TEST_LOCATION);
214 int UtcDaliTapGestureRecognizerMoveTooFar(void)
216 TestApplication application;
218 TapGestureDetector detector = TapGestureDetector::New();
220 Actor actor = Actor::New();
221 actor.SetSize(100.0f, 100.0f);
222 actor.SetAnchorPoint(AnchorPoint::TOP_LEFT);
223 Stage::GetCurrent().Add(actor);
226 application.SendNotification();
227 application.Render();
229 detector.Attach(actor);
232 GestureReceivedFunctor functor(data);
233 detector.DetectedSignal().Connect(&application, functor);
235 application.ProcessEvent( GenerateSingleTouch( PointState::DOWN, Vector2( 20.0f, 20.0f ), 150 ) );
237 application.ProcessEvent( GenerateSingleTouch( PointState::UP, Vector2( 50.0f, 20.0f ), 200 ) );
239 application.SendNotification();
241 DALI_TEST_EQUALS(false, data.functorCalled, TEST_LOCATION);
247 int UtcDaliTapGestureRecognizerStartDouble(void)
249 TestApplication application;
251 TapGestureDetector detector = TapGestureDetector::New();
253 Actor actor = Actor::New();
254 actor.SetSize(100.0f, 100.0f);
255 actor.SetAnchorPoint(AnchorPoint::TOP_LEFT);
256 Stage::GetCurrent().Add(actor);
259 application.SendNotification();
260 application.Render();
262 detector.Attach(actor);
265 GestureReceivedFunctor functor(data);
266 detector.DetectedSignal().Connect(&application, functor);
268 application.ProcessEvent( GenerateDoubleTouch( PointState::DOWN, Vector2( 20.0f, 20.0f ), Vector2( 25.0f, 25.0f ), 150 ) );
270 application.ProcessEvent( GenerateSingleTouch( PointState::UP, Vector2( 20.0f, 20.0f ), 200 ) );
272 application.SendNotification();
274 DALI_TEST_EQUALS(false, data.functorCalled, TEST_LOCATION);
280 int UtcDaliTapGestureRecognizerEndDouble(void)
282 TestApplication application;
284 TapGestureDetector detector = TapGestureDetector::New();
286 Actor actor = Actor::New();
287 actor.SetSize(100.0f, 100.0f);
288 actor.SetAnchorPoint(AnchorPoint::TOP_LEFT);
289 Stage::GetCurrent().Add(actor);
292 application.SendNotification();
293 application.Render();
295 detector.Attach(actor);
298 GestureReceivedFunctor functor(data);
299 detector.DetectedSignal().Connect(&application, functor);
301 application.ProcessEvent( GenerateSingleTouch( PointState::DOWN, Vector2( 20.0f, 20.0f ), 150 ) );
303 application.ProcessEvent( GenerateDoubleTouch( PointState::DOWN, Vector2( 20.0f, 20.0f ), Vector2( 25.0f, 25.0f ), 200 ) );
305 application.ProcessEvent( GenerateDoubleTouch( PointState::UP, Vector2( 20.0f, 20.0f ), Vector2( 25.0f, 25.0f ), 200 ) );
307 application.SendNotification();
309 DALI_TEST_EQUALS(false, data.functorCalled, TEST_LOCATION);
315 int UtcDaliTapGestureRecognizerDoubleTap(void)
317 TestApplication application;
319 TapGestureDetector detector = TapGestureDetector::New(2);
321 Actor actor = Actor::New();
322 actor.SetSize(100.0f, 100.0f);
323 actor.SetAnchorPoint(AnchorPoint::TOP_LEFT);
324 Stage::GetCurrent().Add(actor);
327 application.SendNotification();
328 application.Render();
330 detector.Attach(actor);
333 GestureReceivedFunctor functor(data);
334 detector.DetectedSignal().Connect(&application, functor);
336 application.ProcessEvent( GenerateSingleTouch( PointState::DOWN, Vector2( 20.0f, 20.0f ), 150 ) );
338 application.ProcessEvent( GenerateSingleTouch( PointState::UP, Vector2( 20.0f, 20.0f ), 200 ) );
340 application.SendNotification();
342 DALI_TEST_EQUALS(false, data.functorCalled, TEST_LOCATION);
344 application.ProcessEvent( GenerateSingleTouch( PointState::DOWN, Vector2( 20.0f, 20.0f ), 250 ) );
346 application.ProcessEvent( GenerateSingleTouch( PointState::UP, Vector2( 20.0f, 20.0f ), 300 ) );
348 application.SendNotification();
350 DALI_TEST_EQUALS(true, data.functorCalled, TEST_LOCATION);
356 int UtcDaliTapGestureRecognizerDoubleTapMoveTooFar(void)
358 TestApplication application;
360 TapGestureDetector detector = TapGestureDetector::New(2);
362 Actor actor = Actor::New();
363 actor.SetSize(100.0f, 100.0f);
364 actor.SetAnchorPoint(AnchorPoint::TOP_LEFT);
365 Stage::GetCurrent().Add(actor);
368 application.SendNotification();
369 application.Render();
371 detector.Attach(actor);
374 GestureReceivedFunctor functor(data);
375 detector.DetectedSignal().Connect(&application, functor);
377 application.ProcessEvent( GenerateSingleTouch( PointState::DOWN, Vector2( 20.0f, 20.0f ), 150 ) );
379 application.ProcessEvent( GenerateSingleTouch( PointState::UP, Vector2( 20.0f, 20.0f ), 200 ) );
381 application.SendNotification();
383 DALI_TEST_EQUALS(false, data.functorCalled, TEST_LOCATION);
385 application.ProcessEvent( GenerateSingleTouch( PointState::DOWN, Vector2( 20.0f, 50.0f ), 250 ) );
387 application.ProcessEvent( GenerateSingleTouch( PointState::UP, Vector2( 20.0f, 50.0f ), 300 ) );
389 application.SendNotification();
391 DALI_TEST_EQUALS(false, data.functorCalled, TEST_LOCATION);
393 application.ProcessEvent( GenerateSingleTouch( PointState::DOWN, Vector2( 50.0f, 50.0f ), 450 ) );
395 application.ProcessEvent( GenerateSingleTouch( PointState::UP, Vector2( 50.0f, 50.0f ), 500 ) );
397 application.ProcessEvent( GenerateSingleTouch( PointState::DOWN, Vector2( 50.0f, 50.0f ), 550 ) );
399 application.ProcessEvent( GenerateSingleTouch( PointState::UP, Vector2( 50.0f, 50.0f ), 600 ) );
401 application.SendNotification();
403 DALI_TEST_EQUALS(true, data.functorCalled, TEST_LOCATION);
409 int UtcDaliTapGestureRecognizerDoubleTapWaitTooLong(void)
411 TestApplication application;
413 TapGestureDetector detector = TapGestureDetector::New(2);
415 Actor actor = Actor::New();
416 actor.SetSize(100.0f, 100.0f);
417 actor.SetAnchorPoint(AnchorPoint::TOP_LEFT);
418 Stage::GetCurrent().Add(actor);
421 application.SendNotification();
422 application.Render();
424 detector.Attach(actor);
427 GestureReceivedFunctor functor(data);
428 detector.DetectedSignal().Connect(&application, functor);
430 application.ProcessEvent( GenerateSingleTouch( PointState::DOWN, Vector2( 20.0f, 20.0f ), 150 ) );
432 application.ProcessEvent( GenerateSingleTouch( PointState::UP, Vector2( 20.0f, 20.0f ), 200 ) );
434 application.SendNotification();
436 DALI_TEST_EQUALS(false, data.functorCalled, TEST_LOCATION);
438 application.ProcessEvent( GenerateSingleTouch( PointState::DOWN, Vector2( 20.0f, 20.0f ), 650 ) );
440 application.ProcessEvent( GenerateSingleTouch( PointState::UP, Vector2( 20.0f, 20.0f ), 750 ) );
442 application.SendNotification();
444 DALI_TEST_EQUALS(false, data.functorCalled, TEST_LOCATION);
446 application.ProcessEvent( GenerateSingleTouch( PointState::DOWN, Vector2( 50.0f, 50.0f ), 950 ) );
448 application.ProcessEvent( GenerateSingleTouch( PointState::UP, Vector2( 50.0f, 50.0f ), 1000 ) );
450 application.ProcessEvent( GenerateSingleTouch( PointState::DOWN, Vector2( 50.0f, 50.0f ), 1050 ) );
452 application.ProcessEvent( GenerateSingleTouch( PointState::UP, Vector2( 50.0f, 50.0f ), 1000 ) );
454 application.SendNotification();
456 DALI_TEST_EQUALS(true, data.functorCalled, TEST_LOCATION);
462 int UtcDaliTapGestureRecognizerMultipleDetectors(void)
464 TestApplication application;
466 Actor actor = Actor::New();
467 actor.SetSize(100.0f, 100.0f);
468 actor.SetAnchorPoint(AnchorPoint::TOP_LEFT);
469 Stage::GetCurrent().Add(actor);
471 Actor actor2 = Actor::New();
472 actor2.SetSize(100.0f, 100.0f);
473 actor2.SetAnchorPoint(AnchorPoint::TOP_LEFT);
475 Stage::GetCurrent().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 DALI_TEST_EQUALS(true, data.functorCalled, TEST_LOCATION);
502 DALI_TEST_EQUALS(true, actor == data.tappedActor, TEST_LOCATION);
504 DALI_TEST_EQUALS(false, data2.functorCalled, TEST_LOCATION);
506 application.ProcessEvent( GenerateSingleTouch( PointState::DOWN, Vector2( 120.0f, 20.0f ), 250 ) );
508 application.ProcessEvent( GenerateSingleTouch( PointState::UP, Vector2( 120.0f, 20.0f ), 300 ) );
510 application.SendNotification();
512 DALI_TEST_EQUALS(false, data2.functorCalled, TEST_LOCATION);
514 application.ProcessEvent( GenerateSingleTouch( PointState::DOWN, Vector2( 120.0f, 20.0f ), 350 ) );
516 application.ProcessEvent( GenerateSingleTouch( PointState::UP, Vector2( 120.0f, 20.0f ), 400 ) );
518 application.SendNotification();
520 DALI_TEST_EQUALS(false, data.functorCalled, TEST_LOCATION);
521 DALI_TEST_EQUALS(true, data2.functorCalled, TEST_LOCATION);