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.
23 #include <dali/public-api/dali-core.h>
24 #include <dali/integration-api/events/touch-event-integ.h>
25 #include <dali/integration-api/render-task-list-integ.h>
26 #include <dali-test-suite-utils.h>
27 #include <test-touch-utils.h>
31 ///////////////////////////////////////////////////////////////////////////////
38 : functorCalled(false),
39 voidFunctorCalled(false),
40 receivedGesture(Gesture::Started)
45 functorCalled = false;
46 voidFunctorCalled = false;
48 receivedGesture.state = Gesture::Started;
54 bool voidFunctorCalled;
55 LongPressGesture receivedGesture;
59 // Functor that sets the data when called
60 struct GestureReceivedFunctor
62 GestureReceivedFunctor(SignalData& data) : signalData(data) { }
64 void operator()(Actor actor, const LongPressGesture& pan)
66 signalData.functorCalled = true;
67 signalData.receivedGesture = pan;
68 signalData.pressedActor = actor;
73 signalData.voidFunctorCalled = true;
76 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 );
86 point.SetScreenPosition( screenPosition );
87 point.SetDeviceClass( Device::Class::TOUCH );
88 point.SetDeviceSubclass( Device::Subclass::NONE );
89 touchEvent.points.push_back( point );
90 touchEvent.time = time;
94 Integration::TouchEvent GenerateDoubleTouch( PointState::Type stateA, const Vector2& screenPositionA, PointState::Type stateB, const Vector2& screenPositionB, uint32_t time )
96 Integration::TouchEvent touchEvent;
97 Integration::Point point;
98 point.SetState( stateA );
100 point.SetScreenPosition( screenPositionA );
101 point.SetDeviceClass( Device::Class::TOUCH );
102 point.SetDeviceSubclass( Device::Subclass::NONE );
103 touchEvent.points.push_back( point );
104 point.SetScreenPosition( screenPositionB );
105 point.SetState( stateB);
106 point.SetDeviceId(7);
107 touchEvent.points.push_back( point );
108 touchEvent.time = time;
115 ///////////////////////////////////////////////////////////////////////////////
118 int UtcDaliLongPressGestureRecognizerBasicNoAction(void)
120 TestApplication application;
122 LongPressGestureDetector detector = LongPressGestureDetector::New();
124 Actor actor = Actor::New();
125 actor.SetSize(100.0f, 100.0f);
126 actor.SetAnchorPoint(AnchorPoint::TOP_LEFT);
127 Stage::GetCurrent().Add(actor);
130 application.SendNotification();
131 application.Render();
133 detector.Attach(actor);
136 GestureReceivedFunctor functor(data);
137 detector.DetectedSignal().Connect(&application, functor);
139 application.ProcessEvent( GenerateSingleTouch( PointState::DOWN, Vector2( 20.0f, 20.0f ), 150 ) );
141 application.ProcessEvent( GenerateSingleTouch( PointState::UP, Vector2( 20.0f, 20.0f ), 200 ) );
143 application.SendNotification();
145 DALI_TEST_EQUALS(false, data.functorCalled, TEST_LOCATION);
150 int UtcDaliLongPressGestureRecognizerBasic(void)
152 TestApplication application;
154 LongPressGestureDetector detector = LongPressGestureDetector::New();
156 Actor actor = Actor::New();
157 actor.SetSize(100.0f, 100.0f);
158 actor.SetAnchorPoint(AnchorPoint::TOP_LEFT);
159 Stage::GetCurrent().Add(actor);
162 application.SendNotification();
163 application.Render();
165 detector.Attach(actor);
168 GestureReceivedFunctor functor(data);
169 detector.DetectedSignal().Connect(&application, functor);
171 application.ProcessEvent( GenerateSingleTouch( PointState::DOWN, Vector2( 20.0f, 20.0f ), 150 ) );
173 application.GetPlatform().TriggerTimer();
175 application.SendNotification();
177 DALI_TEST_EQUALS(true, data.functorCalled, TEST_LOCATION);
182 int UtcDaliLongPressGestureRecognizerTooShortWait(void)
184 TestApplication application;
186 LongPressGestureDetector detector = LongPressGestureDetector::New();
188 Actor actor = Actor::New();
189 actor.SetSize(100.0f, 100.0f);
190 actor.SetAnchorPoint(AnchorPoint::TOP_LEFT);
191 Stage::GetCurrent().Add(actor);
194 application.SendNotification();
195 application.Render();
197 detector.Attach(actor);
200 GestureReceivedFunctor functor(data);
201 detector.DetectedSignal().Connect(&application, functor);
203 application.ProcessEvent( GenerateSingleTouch( PointState::DOWN, Vector2( 20.0f, 20.0f ), 150 ) );
205 application.SendNotification();
207 DALI_TEST_EQUALS(false, data.functorCalled, TEST_LOCATION);
212 int UtcDaliLongPressGestureRecognizerTooFewPoints(void)
214 TestApplication application;
216 LongPressGestureDetector detector = LongPressGestureDetector::New();
218 detector.SetTouchesRequired(2,2);
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 // There should be no function to call
238 application.GetPlatform().TriggerTimer();
240 application.SendNotification();
242 DALI_TEST_EQUALS(false, data.functorCalled, TEST_LOCATION);
247 int UtcDaliLongPressGestureRecognizerTooManyPoints(void)
249 TestApplication application;
251 LongPressGestureDetector detector = LongPressGestureDetector::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( GenerateSingleTouch( PointState::DOWN, Vector2( 20.0f, 20.0f ), 150 ) );
269 application.ProcessEvent( GenerateDoubleTouch( PointState::DOWN, Vector2( 20.0f, 20.0f ), PointState::DOWN, Vector2( 20.0f, 90.0f ), 151 ) );
271 // There should be no function to call as the double touch should have cancelled it
272 application.GetPlatform().TriggerTimer();
274 application.SendNotification();
276 DALI_TEST_EQUALS(false, data.functorCalled, TEST_LOCATION);
281 int UtcDaliLongPressGestureRecognizerMultiplePointsMoving(void)
283 TestApplication application;
285 LongPressGestureDetector detector = LongPressGestureDetector::New();
287 detector.SetTouchesRequired(2,2);
289 Actor actor = Actor::New();
290 actor.SetSize(100.0f, 100.0f);
291 actor.SetAnchorPoint(AnchorPoint::TOP_LEFT);
292 Stage::GetCurrent().Add(actor);
295 application.SendNotification();
296 application.Render();
298 detector.Attach(actor);
301 GestureReceivedFunctor functor(data);
302 detector.DetectedSignal().Connect(&application, functor);
304 application.ProcessEvent( GenerateDoubleTouch( PointState::DOWN, Vector2( 20.0f, 0.0f ), PointState::DOWN, Vector2( 20.0f, 90.0f ), 151 ) );
305 application.ProcessEvent( GenerateDoubleTouch( PointState::MOTION, Vector2( 20.0f, 10.0f ), PointState::MOTION, Vector2( 20.0f, 80.0f ), 153 ) );
306 application.ProcessEvent( GenerateDoubleTouch( PointState::MOTION, Vector2( 20.0f, 20.0f ), PointState::MOTION, Vector2( 20.0f, 70.0f ), 155 ) );
307 application.ProcessEvent( GenerateDoubleTouch( PointState::MOTION, Vector2( 20.0f, 30.0f ), PointState::MOTION, Vector2( 20.0f, 60.0f ), 157 ) );
308 application.ProcessEvent( GenerateDoubleTouch( PointState::MOTION, Vector2( 20.0f, 40.0f ), PointState::MOTION, Vector2( 20.0f, 50.0f ), 159 ) );
309 application.ProcessEvent( GenerateDoubleTouch( PointState::STATIONARY, Vector2( 20.0f, 40.0f ), PointState::UP, Vector2( 20.0f, 50.0f ), 160 ) );
310 application.ProcessEvent( GenerateSingleTouch( PointState::UP, Vector2( 20.0f, 40.0f ), 161 ) );
312 application.GetPlatform().TriggerTimer();
314 application.SendNotification();
316 DALI_TEST_EQUALS(false, data.functorCalled, TEST_LOCATION);
321 int UtcDaliLongPressGestureRecognizerMultiplePointsLongPress(void)
323 TestApplication application;
325 LongPressGestureDetector detector = LongPressGestureDetector::New();
327 detector.SetTouchesRequired(2,2);
329 Actor actor = Actor::New();
330 actor.SetSize(100.0f, 100.0f);
331 actor.SetAnchorPoint(AnchorPoint::TOP_LEFT);
332 Stage::GetCurrent().Add(actor);
335 application.SendNotification();
336 application.Render();
338 detector.Attach(actor);
341 GestureReceivedFunctor functor(data);
342 detector.DetectedSignal().Connect(&application, functor);
344 application.ProcessEvent( GenerateSingleTouch( PointState::DOWN, Vector2( 20.0f, 40.0f ), 140 ) );
345 application.ProcessEvent( GenerateDoubleTouch( PointState::DOWN, Vector2( 20.0f, 40.0f ), PointState::DOWN, Vector2( 20.0f, 90.0f ), 150 ) );
347 application.GetPlatform().TriggerTimer();
349 application.ProcessEvent( GenerateDoubleTouch( PointState::STATIONARY, Vector2( 20.0f, 20.0f ), PointState::UP, Vector2( 20.0f, 90.0f ), 760 ) );
350 application.ProcessEvent( GenerateSingleTouch( PointState::UP, Vector2( 20.0f, 20.0f ), 761 ) );
352 application.SendNotification();
354 DALI_TEST_EQUALS(true, data.functorCalled, TEST_LOCATION);
359 int UtcDaliLongPressGestureRecognizerMultipleDetectors(void)
361 TestApplication application;
363 Actor actor = Actor::New();
364 actor.SetSize(100.0f, 100.0f);
365 actor.SetAnchorPoint(AnchorPoint::TOP_LEFT);
366 Stage::GetCurrent().Add(actor);
368 Actor actor2 = Actor::New();
369 actor2.SetSize(100.0f, 100.0f);
370 actor2.SetAnchorPoint(AnchorPoint::TOP_LEFT);
372 Stage::GetCurrent().Add(actor2);
375 application.SendNotification();
376 application.Render();
378 LongPressGestureDetector detector = LongPressGestureDetector::New();
379 detector.Attach(actor);
381 LongPressGestureDetector detector2 = LongPressGestureDetector::New(2);
382 detector2.Attach(actor2);
385 GestureReceivedFunctor functor(data);
386 detector.DetectedSignal().Connect(&application, functor);
389 GestureReceivedFunctor functor2(data2);
390 detector2.DetectedSignal().Connect(&application, functor2);
392 application.ProcessEvent( GenerateSingleTouch( PointState::DOWN, Vector2( 20.0f, 20.0f ), 150 ) );
394 application.GetPlatform().TriggerTimer();
396 application.ProcessEvent( GenerateSingleTouch( PointState::UP, Vector2( 20.0f, 20.0f ), 700 ) );
398 application.SendNotification();
400 DALI_TEST_EQUALS(true, data.functorCalled, TEST_LOCATION);
401 DALI_TEST_EQUALS(true, actor == data.pressedActor, TEST_LOCATION);
403 DALI_TEST_EQUALS(false, data2.functorCalled, TEST_LOCATION);
405 application.ProcessEvent( GenerateSingleTouch( PointState::DOWN, Vector2( 120.0f, 40.0f ), 800 ) );
406 application.ProcessEvent( GenerateDoubleTouch( PointState::DOWN, Vector2( 120.0f, 40.0f ), PointState::DOWN, Vector2( 120.0f, 90.0f ), 805 ) );
408 application.GetPlatform().TriggerTimer();
410 application.SendNotification();
412 DALI_TEST_EQUALS(false, data.functorCalled, TEST_LOCATION);
413 DALI_TEST_EQUALS(true, data2.functorCalled, TEST_LOCATION);