2 * Copyright (c) 2022 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/input-options.h>
21 #include <dali/public-api/dali-core.h>
28 void utc_dali_rotation_gesture_recognizer_startup(void)
30 test_return_value = TET_UNDEF;
33 void utc_dali_rotation_gesture_recognizer_cleanup(void)
35 test_return_value = TET_PASS;
38 ///////////////////////////////////////////////////////////////////////////////
44 : functorCalled(false),
45 voidFunctorCalled(false),
52 functorCalled = false;
53 voidFunctorCalled = false;
55 receivedGesture.Reset();
61 bool voidFunctorCalled;
62 RotationGesture receivedGesture;
66 // Functor that sets the data when called
67 struct GestureReceivedFunctor
69 GestureReceivedFunctor(SignalData& data)
74 void operator()(Actor actor, const RotationGesture& rotation)
76 signalData.functorCalled = true;
77 signalData.receivedGesture = rotation;
78 signalData.rotatedActor = actor;
83 signalData.voidFunctorCalled = true;
86 SignalData& signalData;
89 Integration::TouchEvent GenerateSingleTouch(PointState::Type state, const Vector2& screenPosition, uint32_t time)
91 Integration::TouchEvent touchEvent;
92 Integration::Point point;
93 point.SetState(state);
94 point.SetScreenPosition(screenPosition);
95 point.SetDeviceClass(Device::Class::TOUCH);
96 point.SetDeviceSubclass(Device::Subclass::NONE);
97 touchEvent.points.push_back(point);
98 touchEvent.time = time;
102 Integration::TouchEvent GenerateDoubleTouch(PointState::Type stateA, const Vector2& screenPositionA, PointState::Type stateB, const Vector2& screenPositionB, uint32_t time)
104 Integration::TouchEvent touchEvent;
105 Integration::Point point;
106 point.SetState(stateA);
107 point.SetScreenPosition(screenPositionA);
108 point.SetDeviceClass(Device::Class::TOUCH);
109 point.SetDeviceSubclass(Device::Subclass::NONE);
110 touchEvent.points.push_back(point);
111 point.SetScreenPosition(screenPositionB);
112 point.SetState(stateB);
113 touchEvent.points.push_back(point);
114 touchEvent.time = time;
120 ///////////////////////////////////////////////////////////////////////////////
121 int UtcDaliRotationGestureRecognizerRealistic(void)
123 TestApplication application;
125 RotationGestureDetector detector = RotationGestureDetector::New();
127 Actor actor = Actor::New();
128 actor.SetProperty(Actor::Property::SIZE, Vector2(100.0f, 100.0f));
129 actor.SetProperty(Actor::Property::ANCHOR_POINT, AnchorPoint::TOP_LEFT);
130 application.GetScene().Add(actor);
133 application.SendNotification();
134 application.Render();
136 detector.Attach(actor);
139 GestureReceivedFunctor functor(data);
140 detector.DetectedSignal().Connect(&application, functor);
142 application.ProcessEvent(GenerateSingleTouch(PointState::DOWN, Vector2(20.0f, 20.0f), 100));
143 application.ProcessEvent(GenerateSingleTouch(PointState::UP, Vector2(20.0f, 20.0f), 105));
144 application.ProcessEvent(GenerateSingleTouch(PointState::DOWN, Vector2(20.0f, 20.0f), 110));
145 application.ProcessEvent(GenerateDoubleTouch(PointState::MOTION, Vector2(20.0f, 25.0f), PointState::DOWN, Vector2(20.0f, 90.0f), 115));
146 application.ProcessEvent(GenerateDoubleTouch(PointState::MOTION, Vector2(20.0f, 30.0f), PointState::MOTION, Vector2(20.0f, 85.0f), 120));
147 application.ProcessEvent(GenerateDoubleTouch(PointState::MOTION, Vector2(20.0f, 35.0f), PointState::MOTION, Vector2(20.0f, 80.0f), 125));
148 application.ProcessEvent(GenerateDoubleTouch(PointState::MOTION, Vector2(20.0f, 40.0f), PointState::MOTION, Vector2(20.0f, 75.0f), 130));
149 application.ProcessEvent(GenerateDoubleTouch(PointState::MOTION, Vector2(20.0f, 45.0f), PointState::MOTION, Vector2(20.0f, 70.0f), 135));
150 application.ProcessEvent(GenerateDoubleTouch(PointState::MOTION, Vector2(20.0f, 50.0f), PointState::MOTION, Vector2(20.0f, 65.0f), 140));
151 application.ProcessEvent(GenerateDoubleTouch(PointState::MOTION, Vector2(20.0f, 55.0f), PointState::MOTION, Vector2(20.0f, 60.0f), 145));
152 application.ProcessEvent(GenerateSingleTouch(PointState::UP, Vector2(20.0f, 56.0f), 155));
154 application.SendNotification();
156 DALI_TEST_EQUALS(true, data.functorCalled, TEST_LOCATION);
161 int UtcDaliRotationGestureRecognizerBasicInterrupted(void)
163 TestApplication application;
165 RotationGestureDetector detector = RotationGestureDetector::New();
167 Actor actor = Actor::New();
168 actor.SetProperty(Actor::Property::SIZE, Vector2(100.0f, 100.0f));
169 actor.SetProperty(Actor::Property::ANCHOR_POINT, AnchorPoint::TOP_LEFT);
170 application.GetScene().Add(actor);
173 application.SendNotification();
174 application.Render();
176 detector.Attach(actor);
179 GestureReceivedFunctor functor(data);
180 detector.DetectedSignal().Connect(&application, functor);
182 application.ProcessEvent(GenerateSingleTouch(PointState::INTERRUPTED, Vector2(20.0f, 30.0f), 152));
184 application.SendNotification();
186 DALI_TEST_EQUALS(false, data.functorCalled, TEST_LOCATION);
191 int UtcDaliRotationGestureRecognizerMinimumTouchEvents(void)
193 TestApplication application;
195 Actor actor = Actor::New();
196 actor.SetProperty(Actor::Property::SIZE, Vector2(100.0f, 100.0f));
197 actor.SetProperty(Actor::Property::ANCHOR_POINT, AnchorPoint::TOP_LEFT);
198 application.GetScene().Add(actor);
200 application.SendNotification();
201 application.Render();
204 GestureReceivedFunctor functor(data);
206 RotationGestureDetector detector = RotationGestureDetector::New();
207 detector.Attach(actor);
208 detector.DetectedSignal().Connect(&application, functor);
211 // 2 touch events make a gesture begin
212 Integration::SetRotationGestureMinimumTouchEvents(2);
213 application.ProcessEvent(GenerateDoubleTouch(PointState::DOWN, Vector2(20.0f, 20.0f), PointState::DOWN, Vector2(20.0f, 90.0f), 150));
214 application.ProcessEvent(GenerateDoubleTouch(PointState::MOTION, Vector2(20.0f, 20.0f), PointState::MOTION, Vector2(90.0f, 90.0f), 160));
216 DALI_TEST_EQUALS(GestureState::STARTED, data.receivedGesture.GetState(), TEST_LOCATION);
217 DALI_TEST_EQUALS(true, data.functorCalled, TEST_LOCATION);
221 // 4 touch events make a gesture begin
222 Integration::SetRotationGestureMinimumTouchEvents(4);
223 application.ProcessEvent(GenerateDoubleTouch(PointState::DOWN, Vector2(20.0f, 20.0f), PointState::DOWN, Vector2(20.0f, 90.0f), 150));
224 application.ProcessEvent(GenerateDoubleTouch(PointState::MOTION, Vector2(20.0f, 20.0f), PointState::MOTION, Vector2(90.0f, 90.0f), 160));
226 // Check the gesture is not detected unlike previous case
227 DALI_TEST_EQUALS(false, data.functorCalled, TEST_LOCATION);
232 int UtcDaliRotationGestureRecognizerMinimumTouchEventsAfterStart(void)
234 TestApplication application;
236 Actor actor = Actor::New();
237 actor.SetProperty(Actor::Property::SIZE, Vector2(100.0f, 100.0f));
238 actor.SetProperty(Actor::Property::ANCHOR_POINT, AnchorPoint::TOP_LEFT);
239 application.GetScene().Add(actor);
241 application.SendNotification();
242 application.Render();
245 GestureReceivedFunctor functor(data);
247 RotationGestureDetector detector = RotationGestureDetector::New();
248 detector.Attach(actor);
249 detector.DetectedSignal().Connect(&application, functor);
252 // > 2 touch events make a gesture begin
253 // > 4 touch events generate gestures after begin
254 Integration::SetRotationGestureMinimumTouchEvents(2);
255 Integration::SetRotationGestureMinimumTouchEventsAfterStart(6);
257 application.ProcessEvent(GenerateDoubleTouch(PointState::DOWN, Vector2(20.0f, 20.0f), PointState::DOWN, Vector2(20.0f, 90.0f), 150));
258 application.ProcessEvent(GenerateDoubleTouch(PointState::MOTION, Vector2(20.0f, 20.0f), PointState::MOTION, Vector2(90.0f, 90.0f), 160));
260 DALI_TEST_EQUALS(GestureState::STARTED, data.receivedGesture.GetState(), TEST_LOCATION);
261 DALI_TEST_EQUALS(true, data.functorCalled, TEST_LOCATION);
263 application.ProcessEvent(GenerateDoubleTouch(PointState::MOTION, Vector2(20.0f, 20.0f), PointState::MOTION, Vector2(20.0f, 90.0f), 170));
264 application.ProcessEvent(GenerateDoubleTouch(PointState::MOTION, Vector2(20.0f, 20.0f), PointState::MOTION, Vector2(20.0f, 90.0f), 180));
265 application.ProcessEvent(GenerateDoubleTouch(PointState::MOTION, Vector2(20.0f, 20.0f), PointState::MOTION, Vector2(20.0f, 90.0f), 190));
266 application.ProcessEvent(GenerateDoubleTouch(PointState::MOTION, Vector2(20.0f, 20.0f), PointState::MOTION, Vector2(20.0f, 90.0f), 200));
267 // > Test : not enough touch events to make the gesture state "CONTINUING"
268 DALI_TEST_EQUALS(GestureState::STARTED, data.receivedGesture.GetState(), TEST_LOCATION);
270 application.ProcessEvent(GenerateDoubleTouch(PointState::MOTION, Vector2(20.0f, 20.0f), PointState::MOTION, Vector2(20.0f, 90.0f), 210));
271 application.ProcessEvent(GenerateDoubleTouch(PointState::MOTION, Vector2(20.0f, 20.0f), PointState::MOTION, Vector2(20.0f, 90.0f), 220));
272 // > Test : 6 touch events after start make the gesture state "CONTINUING"
273 DALI_TEST_EQUALS(GestureState::CONTINUING, data.receivedGesture.GetState(), TEST_LOCATION);