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-test-suite-utils.h>
25 #include <test-touch-utils.h>
29 ///////////////////////////////////////////////////////////////////////////////
36 : functorCalled(false),
37 voidFunctorCalled(false),
43 functorCalled = false;
44 voidFunctorCalled = false;
46 receivedGesture.state = Gesture::Started;
52 bool voidFunctorCalled;
53 TapGesture receivedGesture;
57 // Functor that sets the data when called
58 struct GestureReceivedFunctor
60 GestureReceivedFunctor(SignalData& data) : signalData(data) { }
62 void operator()(Actor actor, const TapGesture& tap)
64 signalData.functorCalled = true;
65 signalData.receivedGesture = tap;
66 signalData.tappedActor = actor;
71 signalData.voidFunctorCalled = true;
74 SignalData& signalData;
78 Integration::TouchEvent GenerateSingleTouch( PointState::Type state, const Vector2& screenPosition, uint32_t time )
80 Integration::TouchEvent touchEvent;
81 Integration::Point point;
82 point.SetState( state );
83 point.SetScreenPosition( screenPosition );
84 point.SetDeviceClass( Device::Class::TOUCH );
85 point.SetDeviceSubclass( Device::Subclass::NONE );
86 touchEvent.points.push_back( point );
87 touchEvent.time = time;
91 Integration::TouchEvent GenerateDoubleTouch( PointState::Type state, const Vector2& screenPositionA, const Vector2& screenPositionB, uint32_t time )
93 Integration::TouchEvent touchEvent;
94 Integration::Point point;
95 point.SetState( state );
96 point.SetScreenPosition( screenPositionA );
97 point.SetDeviceClass( Device::Class::TOUCH );
98 point.SetDeviceSubclass( Device::Subclass::NONE );
99 touchEvent.points.push_back( point );
100 point.SetScreenPosition( screenPositionB );
101 touchEvent.points.push_back( point );
102 touchEvent.time = time;
109 ///////////////////////////////////////////////////////////////////////////////
112 int UtcDaliTapGestureRecognizerBasic(void)
114 TestApplication application;
116 TapGestureDetector detector = TapGestureDetector::New();
118 Actor actor = Actor::New();
119 actor.SetSize(100.0f, 100.0f);
120 actor.SetProperty( Actor::Property::ANCHOR_POINT,AnchorPoint::TOP_LEFT);
121 Stage::GetCurrent().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);
145 int UtcDaliTapGestureRecognizerGapTooLong(void)
147 TestApplication application;
149 TapGestureDetector detector = TapGestureDetector::New();
151 Actor actor = Actor::New();
152 actor.SetSize(100.0f, 100.0f);
153 actor.SetProperty( Actor::Property::ANCHOR_POINT,AnchorPoint::TOP_LEFT);
154 Stage::GetCurrent().Add(actor);
157 application.SendNotification();
158 application.Render();
160 detector.Attach(actor);
163 GestureReceivedFunctor functor(data);
164 detector.DetectedSignal().Connect(&application, functor);
166 application.ProcessEvent( GenerateSingleTouch( PointState::DOWN, Vector2( 20.0f, 20.0f ), 150 ) );
168 application.ProcessEvent( GenerateSingleTouch( PointState::UP, Vector2( 20.0f, 20.0f ), 651 ) );
170 application.SendNotification();
172 DALI_TEST_EQUALS(false, data.functorCalled, TEST_LOCATION);
178 int UtcDaliTapGestureRecognizerInterrupted(void)
180 TestApplication application;
182 TapGestureDetector detector = TapGestureDetector::New();
184 Actor actor = Actor::New();
185 actor.SetSize(100.0f, 100.0f);
186 actor.SetProperty( Actor::Property::ANCHOR_POINT,AnchorPoint::TOP_LEFT);
187 Stage::GetCurrent().Add(actor);
190 application.SendNotification();
191 application.Render();
193 detector.Attach(actor);
196 GestureReceivedFunctor functor(data);
197 detector.DetectedSignal().Connect(&application, functor);
199 application.ProcessEvent( GenerateSingleTouch( PointState::DOWN, Vector2( 20.0f, 20.0f ), 150 ) );
201 application.ProcessEvent( GenerateSingleTouch( PointState::INTERRUPTED, Vector2( 20.0f, 20.0f ), 175 ) );
203 application.ProcessEvent( GenerateSingleTouch( PointState::UP, Vector2( 20.0f, 20.0f ), 200 ) );
205 application.SendNotification();
207 DALI_TEST_EQUALS(false, data.functorCalled, TEST_LOCATION);
213 int UtcDaliTapGestureRecognizerMoveTooFar(void)
215 TestApplication application;
217 TapGestureDetector detector = TapGestureDetector::New();
219 Actor actor = Actor::New();
220 actor.SetSize(100.0f, 100.0f);
221 actor.SetProperty( Actor::Property::ANCHOR_POINT,AnchorPoint::TOP_LEFT);
222 Stage::GetCurrent().Add(actor);
225 application.SendNotification();
226 application.Render();
228 detector.Attach(actor);
231 GestureReceivedFunctor functor(data);
232 detector.DetectedSignal().Connect(&application, functor);
234 application.ProcessEvent( GenerateSingleTouch( PointState::DOWN, Vector2( 20.0f, 20.0f ), 150 ) );
236 application.ProcessEvent( GenerateSingleTouch( PointState::UP, Vector2( 50.0f, 20.0f ), 200 ) );
238 application.SendNotification();
240 DALI_TEST_EQUALS(false, data.functorCalled, TEST_LOCATION);
246 int UtcDaliTapGestureRecognizerStartDouble(void)
248 TestApplication application;
250 TapGestureDetector detector = TapGestureDetector::New();
252 Actor actor = Actor::New();
253 actor.SetSize(100.0f, 100.0f);
254 actor.SetProperty( Actor::Property::ANCHOR_POINT,AnchorPoint::TOP_LEFT);
255 Stage::GetCurrent().Add(actor);
258 application.SendNotification();
259 application.Render();
261 detector.Attach(actor);
264 GestureReceivedFunctor functor(data);
265 detector.DetectedSignal().Connect(&application, functor);
267 application.ProcessEvent( GenerateDoubleTouch( PointState::DOWN, Vector2( 20.0f, 20.0f ), Vector2( 25.0f, 25.0f ), 150 ) );
269 application.ProcessEvent( GenerateSingleTouch( PointState::UP, Vector2( 20.0f, 20.0f ), 200 ) );
271 application.SendNotification();
273 DALI_TEST_EQUALS(false, data.functorCalled, TEST_LOCATION);
279 int UtcDaliTapGestureRecognizerEndDouble(void)
281 TestApplication application;
283 TapGestureDetector detector = TapGestureDetector::New();
285 Actor actor = Actor::New();
286 actor.SetSize(100.0f, 100.0f);
287 actor.SetProperty( Actor::Property::ANCHOR_POINT,AnchorPoint::TOP_LEFT);
288 Stage::GetCurrent().Add(actor);
291 application.SendNotification();
292 application.Render();
294 detector.Attach(actor);
297 GestureReceivedFunctor functor(data);
298 detector.DetectedSignal().Connect(&application, functor);
300 application.ProcessEvent( GenerateSingleTouch( PointState::DOWN, Vector2( 20.0f, 20.0f ), 150 ) );
302 application.ProcessEvent( GenerateDoubleTouch( PointState::DOWN, Vector2( 20.0f, 20.0f ), Vector2( 25.0f, 25.0f ), 200 ) );
304 application.ProcessEvent( GenerateDoubleTouch( PointState::UP, Vector2( 20.0f, 20.0f ), Vector2( 25.0f, 25.0f ), 200 ) );
306 application.SendNotification();
308 DALI_TEST_EQUALS(false, data.functorCalled, TEST_LOCATION);
314 int UtcDaliTapGestureRecognizerDoubleTap(void)
316 TestApplication application;
318 TapGestureDetector detector = TapGestureDetector::New(2);
320 Actor actor = Actor::New();
321 actor.SetSize(100.0f, 100.0f);
322 actor.SetProperty( Actor::Property::ANCHOR_POINT,AnchorPoint::TOP_LEFT);
323 Stage::GetCurrent().Add(actor);
326 application.SendNotification();
327 application.Render();
329 detector.Attach(actor);
332 GestureReceivedFunctor functor(data);
333 detector.DetectedSignal().Connect(&application, functor);
335 application.ProcessEvent( GenerateSingleTouch( PointState::DOWN, Vector2( 20.0f, 20.0f ), 150 ) );
337 application.ProcessEvent( GenerateSingleTouch( PointState::UP, Vector2( 20.0f, 20.0f ), 200 ) );
339 application.SendNotification();
341 DALI_TEST_EQUALS(false, data.functorCalled, TEST_LOCATION);
343 application.ProcessEvent( GenerateSingleTouch( PointState::DOWN, Vector2( 20.0f, 20.0f ), 250 ) );
345 application.ProcessEvent( GenerateSingleTouch( PointState::UP, Vector2( 20.0f, 20.0f ), 300 ) );
347 application.SendNotification();
349 DALI_TEST_EQUALS(true, data.functorCalled, TEST_LOCATION);
355 int UtcDaliTapGestureRecognizerDoubleTapMoveTooFar(void)
357 TestApplication application;
359 TapGestureDetector detector = TapGestureDetector::New(2);
361 Actor actor = Actor::New();
362 actor.SetSize(100.0f, 100.0f);
363 actor.SetProperty( Actor::Property::ANCHOR_POINT,AnchorPoint::TOP_LEFT);
364 Stage::GetCurrent().Add(actor);
367 application.SendNotification();
368 application.Render();
370 detector.Attach(actor);
373 GestureReceivedFunctor functor(data);
374 detector.DetectedSignal().Connect(&application, functor);
376 application.ProcessEvent( GenerateSingleTouch( PointState::DOWN, Vector2( 20.0f, 20.0f ), 150 ) );
378 application.ProcessEvent( GenerateSingleTouch( PointState::UP, Vector2( 20.0f, 20.0f ), 200 ) );
380 application.SendNotification();
382 DALI_TEST_EQUALS(false, data.functorCalled, TEST_LOCATION);
384 application.ProcessEvent( GenerateSingleTouch( PointState::DOWN, Vector2( 20.0f, 50.0f ), 250 ) );
386 application.ProcessEvent( GenerateSingleTouch( PointState::UP, Vector2( 20.0f, 50.0f ), 300 ) );
388 application.SendNotification();
390 DALI_TEST_EQUALS(false, data.functorCalled, TEST_LOCATION);
392 application.ProcessEvent( GenerateSingleTouch( PointState::DOWN, Vector2( 50.0f, 50.0f ), 450 ) );
394 application.ProcessEvent( GenerateSingleTouch( PointState::UP, Vector2( 50.0f, 50.0f ), 500 ) );
396 application.ProcessEvent( GenerateSingleTouch( PointState::DOWN, Vector2( 50.0f, 50.0f ), 550 ) );
398 application.ProcessEvent( GenerateSingleTouch( PointState::UP, Vector2( 50.0f, 50.0f ), 600 ) );
400 application.SendNotification();
402 DALI_TEST_EQUALS(true, data.functorCalled, TEST_LOCATION);
408 int UtcDaliTapGestureRecognizerDoubleTapWaitTooLong(void)
410 TestApplication application;
412 TapGestureDetector detector = TapGestureDetector::New(2);
414 Actor actor = Actor::New();
415 actor.SetSize(100.0f, 100.0f);
416 actor.SetProperty( Actor::Property::ANCHOR_POINT,AnchorPoint::TOP_LEFT);
417 Stage::GetCurrent().Add(actor);
420 application.SendNotification();
421 application.Render();
423 detector.Attach(actor);
426 GestureReceivedFunctor functor(data);
427 detector.DetectedSignal().Connect(&application, functor);
429 application.ProcessEvent( GenerateSingleTouch( PointState::DOWN, Vector2( 20.0f, 20.0f ), 150 ) );
431 application.ProcessEvent( GenerateSingleTouch( PointState::UP, Vector2( 20.0f, 20.0f ), 200 ) );
433 application.SendNotification();
435 DALI_TEST_EQUALS(false, data.functorCalled, TEST_LOCATION);
437 application.ProcessEvent( GenerateSingleTouch( PointState::DOWN, Vector2( 20.0f, 20.0f ), 650 ) );
439 application.ProcessEvent( GenerateSingleTouch( PointState::UP, Vector2( 20.0f, 20.0f ), 750 ) );
441 application.SendNotification();
443 DALI_TEST_EQUALS(false, data.functorCalled, TEST_LOCATION);
445 application.ProcessEvent( GenerateSingleTouch( PointState::DOWN, Vector2( 50.0f, 50.0f ), 950 ) );
447 application.ProcessEvent( GenerateSingleTouch( PointState::UP, Vector2( 50.0f, 50.0f ), 1000 ) );
449 application.ProcessEvent( GenerateSingleTouch( PointState::DOWN, Vector2( 50.0f, 50.0f ), 1050 ) );
451 application.ProcessEvent( GenerateSingleTouch( PointState::UP, Vector2( 50.0f, 50.0f ), 1000 ) );
453 application.SendNotification();
455 DALI_TEST_EQUALS(true, data.functorCalled, TEST_LOCATION);
461 int UtcDaliTapGestureRecognizerMultipleDetectors(void)
463 TestApplication application;
465 Actor actor = Actor::New();
466 actor.SetSize(100.0f, 100.0f);
467 actor.SetProperty( Actor::Property::ANCHOR_POINT,AnchorPoint::TOP_LEFT);
468 Stage::GetCurrent().Add(actor);
470 Actor actor2 = Actor::New();
471 actor2.SetSize(100.0f, 100.0f);
472 actor2.SetProperty( Actor::Property::ANCHOR_POINT,AnchorPoint::TOP_LEFT);
474 Stage::GetCurrent().Add(actor2);
477 application.SendNotification();
478 application.Render();
480 TapGestureDetector detector = TapGestureDetector::New();
481 detector.Attach(actor);
483 TapGestureDetector detector2 = TapGestureDetector::New(2);
484 detector2.Attach(actor2);
487 GestureReceivedFunctor functor(data);
488 detector.DetectedSignal().Connect(&application, functor);
491 GestureReceivedFunctor functor2(data2);
492 detector2.DetectedSignal().Connect(&application, functor2);
494 application.ProcessEvent( GenerateSingleTouch( PointState::DOWN, Vector2( 20.0f, 20.0f ), 150 ) );
496 application.ProcessEvent( GenerateSingleTouch( PointState::UP, Vector2( 20.0f, 20.0f ), 200 ) );
498 application.SendNotification();
500 DALI_TEST_EQUALS(true, data.functorCalled, TEST_LOCATION);
501 DALI_TEST_EQUALS(true, actor == data.tappedActor, TEST_LOCATION);
503 DALI_TEST_EQUALS(false, data2.functorCalled, TEST_LOCATION);
505 application.ProcessEvent( GenerateSingleTouch( PointState::DOWN, Vector2( 120.0f, 20.0f ), 250 ) );
507 application.ProcessEvent( GenerateSingleTouch( PointState::UP, Vector2( 120.0f, 20.0f ), 300 ) );
509 application.SendNotification();
511 DALI_TEST_EQUALS(false, data2.functorCalled, TEST_LOCATION);
513 application.ProcessEvent( GenerateSingleTouch( PointState::DOWN, Vector2( 120.0f, 20.0f ), 350 ) );
515 application.ProcessEvent( GenerateSingleTouch( PointState::UP, Vector2( 120.0f, 20.0f ), 400 ) );
517 application.SendNotification();
519 DALI_TEST_EQUALS(false, data.functorCalled, TEST_LOCATION);
520 DALI_TEST_EQUALS(true, data2.functorCalled, TEST_LOCATION);