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/internal/event/events/long-press-gesture-event.h>
27 #include <dali-test-suite-utils.h>
28 #include <test-touch-utils.h>
32 ///////////////////////////////////////////////////////////////////////////////
39 : functorCalled(false),
40 voidFunctorCalled(false),
41 receivedGesture(Gesture::Started)
46 functorCalled = false;
47 voidFunctorCalled = false;
49 receivedGesture.state = Gesture::Started;
55 bool voidFunctorCalled;
56 LongPressGesture receivedGesture;
60 // Functor that sets the data when called
61 struct GestureReceivedFunctor
63 GestureReceivedFunctor(SignalData& data) : signalData(data) { }
65 void operator()(Actor actor, const LongPressGesture& pan)
67 signalData.functorCalled = true;
68 signalData.receivedGesture = pan;
69 signalData.pressedActor = actor;
74 signalData.voidFunctorCalled = true;
77 SignalData& signalData;
81 Integration::TouchEvent GenerateSingleTouch( PointState::Type state, const Vector2& screenPosition, uint32_t time )
83 Integration::TouchEvent touchEvent;
84 Integration::Point point;
85 point.SetState( state );
87 point.SetScreenPosition( screenPosition );
88 point.SetDeviceClass( Device::Class::TOUCH );
89 point.SetDeviceSubclass( Device::Subclass::NONE );
90 touchEvent.points.push_back( point );
91 touchEvent.time = time;
95 Integration::TouchEvent GenerateDoubleTouch( PointState::Type stateA, const Vector2& screenPositionA, PointState::Type stateB, const Vector2& screenPositionB, uint32_t time )
97 Integration::TouchEvent touchEvent;
98 Integration::Point point;
99 point.SetState( stateA );
100 point.SetDeviceId(4);
101 point.SetScreenPosition( screenPositionA );
102 point.SetDeviceClass( Device::Class::TOUCH );
103 point.SetDeviceSubclass( Device::Subclass::NONE );
104 touchEvent.points.push_back( point );
105 point.SetScreenPosition( screenPositionB );
106 point.SetState( stateB);
107 point.SetDeviceId(7);
108 touchEvent.points.push_back( point );
109 touchEvent.time = time;
116 ///////////////////////////////////////////////////////////////////////////////
119 int UtcDaliLongPressGestureRecognizerBasicNoAction(void)
121 TestApplication application;
123 LongPressGestureDetector detector = LongPressGestureDetector::New();
125 Actor actor = Actor::New();
126 actor.SetSize(100.0f, 100.0f);
127 actor.SetAnchorPoint(AnchorPoint::TOP_LEFT);
128 Stage::GetCurrent().Add(actor);
131 application.SendNotification();
132 application.Render();
134 detector.Attach(actor);
137 GestureReceivedFunctor functor(data);
138 detector.DetectedSignal().Connect(&application, functor);
140 application.ProcessEvent( GenerateSingleTouch( PointState::DOWN, Vector2( 20.0f, 20.0f ), 150 ) );
142 application.ProcessEvent( GenerateSingleTouch( PointState::UP, Vector2( 20.0f, 20.0f ), 200 ) );
144 application.SendNotification();
146 DALI_TEST_EQUALS(false, data.functorCalled, TEST_LOCATION);
151 int UtcDaliLongPressGestureRecognizerBasic(void)
153 TestApplication application;
155 LongPressGestureDetector detector = LongPressGestureDetector::New();
157 Actor actor = Actor::New();
158 actor.SetSize(100.0f, 100.0f);
159 actor.SetAnchorPoint(AnchorPoint::TOP_LEFT);
160 Stage::GetCurrent().Add(actor);
163 application.SendNotification();
164 application.Render();
166 detector.Attach(actor);
169 GestureReceivedFunctor functor(data);
170 detector.DetectedSignal().Connect(&application, functor);
172 application.ProcessEvent( GenerateSingleTouch( PointState::DOWN, Vector2( 20.0f, 20.0f ), 150 ) );
174 application.GetPlatform().TriggerTimer();
176 application.SendNotification();
178 DALI_TEST_EQUALS(true, data.functorCalled, TEST_LOCATION);
183 int UtcDaliLongPressGestureRecognizerTooShortWait(void)
185 TestApplication application;
187 LongPressGestureDetector detector = LongPressGestureDetector::New();
189 Actor actor = Actor::New();
190 actor.SetSize(100.0f, 100.0f);
191 actor.SetAnchorPoint(AnchorPoint::TOP_LEFT);
192 Stage::GetCurrent().Add(actor);
195 application.SendNotification();
196 application.Render();
198 detector.Attach(actor);
201 GestureReceivedFunctor functor(data);
202 detector.DetectedSignal().Connect(&application, functor);
204 application.ProcessEvent( GenerateSingleTouch( PointState::DOWN, Vector2( 20.0f, 20.0f ), 150 ) );
206 application.SendNotification();
208 DALI_TEST_EQUALS(false, data.functorCalled, TEST_LOCATION);
213 int UtcDaliLongPressGestureRecognizerTooFewPoints(void)
215 TestApplication application;
217 LongPressGestureDetector detector = LongPressGestureDetector::New();
219 detector.SetTouchesRequired(2,2);
221 Actor actor = Actor::New();
222 actor.SetSize(100.0f, 100.0f);
223 actor.SetAnchorPoint(AnchorPoint::TOP_LEFT);
224 Stage::GetCurrent().Add(actor);
227 application.SendNotification();
228 application.Render();
230 detector.Attach(actor);
233 GestureReceivedFunctor functor(data);
234 detector.DetectedSignal().Connect(&application, functor);
236 application.ProcessEvent( GenerateSingleTouch( PointState::DOWN, Vector2( 20.0f, 20.0f ), 150 ) );
238 // There should be no function to call
239 application.GetPlatform().TriggerTimer();
241 application.SendNotification();
243 DALI_TEST_EQUALS(false, data.functorCalled, TEST_LOCATION);
248 int UtcDaliLongPressGestureRecognizerTooManyPoints(void)
250 TestApplication application;
252 LongPressGestureDetector detector = LongPressGestureDetector::New();
254 Actor actor = Actor::New();
255 actor.SetSize(100.0f, 100.0f);
256 actor.SetAnchorPoint(AnchorPoint::TOP_LEFT);
257 Stage::GetCurrent().Add(actor);
260 application.SendNotification();
261 application.Render();
263 detector.Attach(actor);
266 GestureReceivedFunctor functor(data);
267 detector.DetectedSignal().Connect(&application, functor);
269 application.ProcessEvent( GenerateSingleTouch( PointState::DOWN, Vector2( 20.0f, 20.0f ), 150 ) );
270 application.ProcessEvent( GenerateDoubleTouch( PointState::DOWN, Vector2( 20.0f, 20.0f ), PointState::DOWN, Vector2( 20.0f, 90.0f ), 151 ) );
272 // There should be no function to call as the double touch should have cancelled it
273 application.GetPlatform().TriggerTimer();
275 application.SendNotification();
277 DALI_TEST_EQUALS(false, data.functorCalled, TEST_LOCATION);
282 int UtcDaliLongPressGestureRecognizerMultiplePointsMoving(void)
284 TestApplication application;
286 LongPressGestureDetector detector = LongPressGestureDetector::New();
288 detector.SetTouchesRequired(2,2);
290 Actor actor = Actor::New();
291 actor.SetSize(100.0f, 100.0f);
292 actor.SetAnchorPoint(AnchorPoint::TOP_LEFT);
293 Stage::GetCurrent().Add(actor);
296 application.SendNotification();
297 application.Render();
299 detector.Attach(actor);
302 GestureReceivedFunctor functor(data);
303 detector.DetectedSignal().Connect(&application, functor);
305 application.ProcessEvent( GenerateDoubleTouch( PointState::DOWN, Vector2( 20.0f, 0.0f ), PointState::DOWN, Vector2( 20.0f, 90.0f ), 151 ) );
306 application.ProcessEvent( GenerateDoubleTouch( PointState::MOTION, Vector2( 20.0f, 10.0f ), PointState::MOTION, Vector2( 20.0f, 80.0f ), 153 ) );
307 application.ProcessEvent( GenerateDoubleTouch( PointState::MOTION, Vector2( 20.0f, 20.0f ), PointState::MOTION, Vector2( 20.0f, 70.0f ), 155 ) );
308 application.ProcessEvent( GenerateDoubleTouch( PointState::MOTION, Vector2( 20.0f, 30.0f ), PointState::MOTION, Vector2( 20.0f, 60.0f ), 157 ) );
309 application.ProcessEvent( GenerateDoubleTouch( PointState::MOTION, Vector2( 20.0f, 40.0f ), PointState::MOTION, Vector2( 20.0f, 50.0f ), 159 ) );
310 application.ProcessEvent( GenerateDoubleTouch( PointState::STATIONARY, Vector2( 20.0f, 40.0f ), PointState::UP, Vector2( 20.0f, 50.0f ), 160 ) );
311 application.ProcessEvent( GenerateSingleTouch( PointState::UP, Vector2( 20.0f, 40.0f ), 161 ) );
313 application.GetPlatform().TriggerTimer();
315 application.SendNotification();
317 DALI_TEST_EQUALS(false, data.functorCalled, TEST_LOCATION);
322 int UtcDaliLongPressGestureRecognizerMultiplePointsLongPress(void)
324 TestApplication application;
326 LongPressGestureDetector detector = LongPressGestureDetector::New();
328 detector.SetTouchesRequired(2,2);
330 Actor actor = Actor::New();
331 actor.SetSize(100.0f, 100.0f);
332 actor.SetAnchorPoint(AnchorPoint::TOP_LEFT);
333 Stage::GetCurrent().Add(actor);
336 application.SendNotification();
337 application.Render();
339 detector.Attach(actor);
342 GestureReceivedFunctor functor(data);
343 detector.DetectedSignal().Connect(&application, functor);
345 application.ProcessEvent( GenerateSingleTouch( PointState::DOWN, Vector2( 20.0f, 40.0f ), 140 ) );
346 application.ProcessEvent( GenerateDoubleTouch( PointState::DOWN, Vector2( 20.0f, 40.0f ), PointState::DOWN, Vector2( 20.0f, 90.0f ), 150 ) );
348 application.GetPlatform().TriggerTimer();
350 application.ProcessEvent( GenerateDoubleTouch( PointState::STATIONARY, Vector2( 20.0f, 20.0f ), PointState::UP, Vector2( 20.0f, 90.0f ), 760 ) );
351 application.ProcessEvent( GenerateSingleTouch( PointState::UP, Vector2( 20.0f, 20.0f ), 761 ) );
353 application.SendNotification();
355 DALI_TEST_EQUALS(true, data.functorCalled, TEST_LOCATION);
360 int UtcDaliLongPressGestureRecognizerMultipleDetectors(void)
362 TestApplication application;
364 Actor actor = Actor::New();
365 actor.SetSize(100.0f, 100.0f);
366 actor.SetAnchorPoint(AnchorPoint::TOP_LEFT);
367 Stage::GetCurrent().Add(actor);
369 Actor actor2 = Actor::New();
370 actor2.SetSize(100.0f, 100.0f);
371 actor2.SetAnchorPoint(AnchorPoint::TOP_LEFT);
373 Stage::GetCurrent().Add(actor2);
376 application.SendNotification();
377 application.Render();
379 LongPressGestureDetector detector = LongPressGestureDetector::New();
380 detector.Attach(actor);
382 LongPressGestureDetector detector2 = LongPressGestureDetector::New(2);
383 detector2.Attach(actor2);
386 GestureReceivedFunctor functor(data);
387 detector.DetectedSignal().Connect(&application, functor);
390 GestureReceivedFunctor functor2(data2);
391 detector2.DetectedSignal().Connect(&application, functor2);
393 application.ProcessEvent( GenerateSingleTouch( PointState::DOWN, Vector2( 20.0f, 20.0f ), 150 ) );
395 application.GetPlatform().TriggerTimer();
397 application.ProcessEvent( GenerateSingleTouch( PointState::UP, Vector2( 20.0f, 20.0f ), 700 ) );
399 application.SendNotification();
401 DALI_TEST_EQUALS(true, data.functorCalled, TEST_LOCATION);
402 DALI_TEST_EQUALS(true, actor == data.pressedActor, TEST_LOCATION);
404 DALI_TEST_EQUALS(false, data2.functorCalled, TEST_LOCATION);
406 application.ProcessEvent( GenerateSingleTouch( PointState::DOWN, Vector2( 120.0f, 40.0f ), 800 ) );
407 application.ProcessEvent( GenerateDoubleTouch( PointState::DOWN, Vector2( 120.0f, 40.0f ), PointState::DOWN, Vector2( 120.0f, 90.0f ), 805 ) );
409 application.GetPlatform().TriggerTimer();
411 application.SendNotification();
413 DALI_TEST_EQUALS(false, data.functorCalled, TEST_LOCATION);
414 DALI_TEST_EQUALS(true, data2.functorCalled, TEST_LOCATION);