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>
30 ///////////////////////////////////////////////////////////////////////////////
36 : functorCalled(false),
37 voidFunctorCalled(false),
44 functorCalled = false;
45 voidFunctorCalled = false;
47 receivedGesture.Reset();
53 bool voidFunctorCalled;
54 LongPressGesture receivedGesture;
58 // Functor that sets the data when called
59 struct GestureReceivedFunctor
61 GestureReceivedFunctor(SignalData& data)
66 void operator()(Actor actor, const LongPressGesture& pan)
68 signalData.functorCalled = true;
69 signalData.receivedGesture = pan;
70 signalData.pressedActor = actor;
75 signalData.voidFunctorCalled = true;
78 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;
115 ///////////////////////////////////////////////////////////////////////////////
117 int UtcDaliLongPressGestureRecognizerBasicNoAction(void)
119 TestApplication application;
121 LongPressGestureDetector detector = LongPressGestureDetector::New();
123 Actor actor = Actor::New();
124 actor.SetProperty(Actor::Property::SIZE, Vector2(100.0f, 100.0f));
125 actor.SetProperty(Actor::Property::ANCHOR_POINT, AnchorPoint::TOP_LEFT);
126 application.GetScene().Add(actor);
129 application.SendNotification();
130 application.Render();
132 detector.Attach(actor);
135 GestureReceivedFunctor functor(data);
136 detector.DetectedSignal().Connect(&application, functor);
138 application.ProcessEvent(GenerateSingleTouch(PointState::DOWN, Vector2(20.0f, 20.0f), 150));
140 application.ProcessEvent(GenerateSingleTouch(PointState::UP, Vector2(20.0f, 20.0f), 200));
142 application.SendNotification();
144 DALI_TEST_EQUALS(false, data.functorCalled, TEST_LOCATION);
149 int UtcDaliLongPressGestureRecognizerBasic(void)
151 TestApplication application;
153 LongPressGestureDetector detector = LongPressGestureDetector::New();
155 Actor actor = Actor::New();
156 actor.SetProperty(Actor::Property::SIZE, Vector2(100.0f, 100.0f));
157 actor.SetProperty(Actor::Property::ANCHOR_POINT, AnchorPoint::TOP_LEFT);
158 application.GetScene().Add(actor);
161 application.SendNotification();
162 application.Render();
164 detector.Attach(actor);
167 GestureReceivedFunctor functor(data);
168 detector.DetectedSignal().Connect(&application, functor);
170 application.ProcessEvent(GenerateSingleTouch(PointState::DOWN, Vector2(20.0f, 20.0f), 150));
172 application.GetPlatform().TriggerTimer();
174 application.SendNotification();
176 DALI_TEST_EQUALS(true, data.functorCalled, TEST_LOCATION);
181 int UtcDaliLongPressGestureRecognizerTooShortWait(void)
183 TestApplication application;
185 LongPressGestureDetector detector = LongPressGestureDetector::New();
187 Actor actor = Actor::New();
188 actor.SetProperty(Actor::Property::SIZE, Vector2(100.0f, 100.0f));
189 actor.SetProperty(Actor::Property::ANCHOR_POINT, AnchorPoint::TOP_LEFT);
190 application.GetScene().Add(actor);
193 application.SendNotification();
194 application.Render();
196 detector.Attach(actor);
199 GestureReceivedFunctor functor(data);
200 detector.DetectedSignal().Connect(&application, functor);
202 application.ProcessEvent(GenerateSingleTouch(PointState::DOWN, Vector2(20.0f, 20.0f), 150));
204 application.SendNotification();
206 DALI_TEST_EQUALS(false, data.functorCalled, TEST_LOCATION);
211 int UtcDaliLongPressGestureRecognizerTooFewPoints(void)
213 TestApplication application;
215 LongPressGestureDetector detector = LongPressGestureDetector::New();
217 detector.SetTouchesRequired(2, 2);
219 Actor actor = Actor::New();
220 actor.SetProperty(Actor::Property::SIZE, Vector2(100.0f, 100.0f));
221 actor.SetProperty(Actor::Property::ANCHOR_POINT, AnchorPoint::TOP_LEFT);
222 application.GetScene().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 // There should be no function to call
237 application.GetPlatform().TriggerTimer();
239 application.SendNotification();
241 DALI_TEST_EQUALS(false, data.functorCalled, TEST_LOCATION);
246 int UtcDaliLongPressGestureRecognizerTooManyPoints(void)
248 TestApplication application;
250 LongPressGestureDetector detector = LongPressGestureDetector::New();
252 Actor actor = Actor::New();
253 actor.SetProperty(Actor::Property::SIZE, Vector2(100.0f, 100.0f));
254 actor.SetProperty(Actor::Property::ANCHOR_POINT, AnchorPoint::TOP_LEFT);
255 application.GetScene().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(GenerateSingleTouch(PointState::DOWN, Vector2(20.0f, 20.0f), 150));
268 application.ProcessEvent(GenerateDoubleTouch(PointState::DOWN, Vector2(20.0f, 20.0f), PointState::DOWN, Vector2(20.0f, 90.0f), 151));
270 // There should be no function to call as the double touch should have cancelled it
271 application.GetPlatform().TriggerTimer();
273 application.SendNotification();
275 DALI_TEST_EQUALS(false, data.functorCalled, TEST_LOCATION);
280 int UtcDaliLongPressGestureRecognizerMultiplePointsMoving(void)
282 TestApplication application;
284 LongPressGestureDetector detector = LongPressGestureDetector::New();
286 detector.SetTouchesRequired(2, 2);
288 Actor actor = Actor::New();
289 actor.SetProperty(Actor::Property::SIZE, Vector2(100.0f, 100.0f));
290 actor.SetProperty(Actor::Property::ANCHOR_POINT, AnchorPoint::TOP_LEFT);
291 application.GetScene().Add(actor);
294 application.SendNotification();
295 application.Render();
297 detector.Attach(actor);
300 GestureReceivedFunctor functor(data);
301 detector.DetectedSignal().Connect(&application, functor);
303 application.ProcessEvent(GenerateDoubleTouch(PointState::DOWN, Vector2(20.0f, 0.0f), PointState::DOWN, Vector2(20.0f, 90.0f), 151));
304 application.ProcessEvent(GenerateDoubleTouch(PointState::MOTION, Vector2(20.0f, 10.0f), PointState::MOTION, Vector2(20.0f, 80.0f), 153));
305 application.ProcessEvent(GenerateDoubleTouch(PointState::MOTION, Vector2(20.0f, 20.0f), PointState::MOTION, Vector2(20.0f, 70.0f), 155));
306 application.ProcessEvent(GenerateDoubleTouch(PointState::MOTION, Vector2(20.0f, 30.0f), PointState::MOTION, Vector2(20.0f, 60.0f), 157));
307 application.ProcessEvent(GenerateDoubleTouch(PointState::MOTION, Vector2(20.0f, 40.0f), PointState::MOTION, Vector2(20.0f, 50.0f), 159));
308 application.ProcessEvent(GenerateDoubleTouch(PointState::STATIONARY, Vector2(20.0f, 40.0f), PointState::UP, Vector2(20.0f, 50.0f), 160));
309 application.ProcessEvent(GenerateSingleTouch(PointState::UP, Vector2(20.0f, 40.0f), 161));
311 application.GetPlatform().TriggerTimer();
313 application.SendNotification();
315 DALI_TEST_EQUALS(false, data.functorCalled, TEST_LOCATION);
320 int UtcDaliLongPressGestureRecognizerMultiplePointsLongPress(void)
322 TestApplication application;
324 LongPressGestureDetector detector = LongPressGestureDetector::New();
326 Actor actor = Actor::New();
327 actor.SetProperty(Actor::Property::SIZE, Vector2(100.0f, 100.0f));
328 actor.SetProperty(Actor::Property::ANCHOR_POINT, AnchorPoint::TOP_LEFT);
329 application.GetScene().Add(actor);
332 application.SendNotification();
333 application.Render();
335 detector.Attach(actor);
336 detector.SetTouchesRequired(2, 2); // Set after we've attached forcing us to change things internally
339 GestureReceivedFunctor functor(data);
340 detector.DetectedSignal().Connect(&application, functor);
342 application.ProcessEvent(GenerateSingleTouch(PointState::DOWN, Vector2(20.0f, 40.0f), 140));
343 application.ProcessEvent(GenerateDoubleTouch(PointState::DOWN, Vector2(20.0f, 40.0f), PointState::DOWN, Vector2(20.0f, 90.0f), 150));
345 application.GetPlatform().TriggerTimer();
347 application.ProcessEvent(GenerateDoubleTouch(PointState::STATIONARY, Vector2(20.0f, 20.0f), PointState::UP, Vector2(20.0f, 90.0f), 760));
348 application.ProcessEvent(GenerateSingleTouch(PointState::UP, Vector2(20.0f, 20.0f), 761));
350 application.SendNotification();
352 DALI_TEST_EQUALS(true, data.functorCalled, TEST_LOCATION);
357 int UtcDaliLongPressGestureRecognizerMultipleDetectors(void)
359 TestApplication application;
361 Actor actor = Actor::New();
362 actor.SetProperty(Actor::Property::SIZE, Vector2(100.0f, 100.0f));
363 actor.SetProperty(Actor::Property::ANCHOR_POINT, AnchorPoint::TOP_LEFT);
364 application.GetScene().Add(actor);
366 Actor actor2 = Actor::New();
367 actor2.SetProperty(Actor::Property::SIZE, Vector2(100.0f, 100.0f));
368 actor2.SetProperty(Actor::Property::ANCHOR_POINT, AnchorPoint::TOP_LEFT);
369 actor2.SetProperty(Actor::Property::POSITION_X, 100.0f);
370 application.GetScene().Add(actor2);
373 application.SendNotification();
374 application.Render();
376 LongPressGestureDetector detector = LongPressGestureDetector::New();
377 detector.Attach(actor);
379 LongPressGestureDetector detector2 = LongPressGestureDetector::New(2);
380 detector2.Attach(actor2);
383 GestureReceivedFunctor functor(data);
384 detector.DetectedSignal().Connect(&application, functor);
387 GestureReceivedFunctor functor2(data2);
388 detector2.DetectedSignal().Connect(&application, functor2);
390 application.ProcessEvent(GenerateSingleTouch(PointState::DOWN, Vector2(20.0f, 20.0f), 150));
392 application.GetPlatform().TriggerTimer();
394 application.ProcessEvent(GenerateSingleTouch(PointState::UP, Vector2(20.0f, 20.0f), 700));
396 application.SendNotification();
398 DALI_TEST_EQUALS(true, data.functorCalled, TEST_LOCATION);
399 DALI_TEST_EQUALS(true, actor == data.pressedActor, TEST_LOCATION);
401 DALI_TEST_EQUALS(false, data2.functorCalled, TEST_LOCATION);
403 application.ProcessEvent(GenerateSingleTouch(PointState::DOWN, Vector2(120.0f, 40.0f), 800));
404 application.ProcessEvent(GenerateDoubleTouch(PointState::DOWN, Vector2(120.0f, 40.0f), PointState::DOWN, Vector2(120.0f, 90.0f), 805));
406 application.GetPlatform().TriggerTimer();
408 application.SendNotification();
410 DALI_TEST_EQUALS(false, data.functorCalled, TEST_LOCATION);
411 DALI_TEST_EQUALS(true, data2.functorCalled, TEST_LOCATION);