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/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::DOWN, Vector2( 20.0f, 20.0f ), 150 ) );
183 // application.ProcessEvent( GenerateSingleTouch( PointState::MOTION, Vector2( 20.0f, 25.0f ), 151 ) );
184 application.ProcessEvent(GenerateSingleTouch(PointState::INTERRUPTED, Vector2(20.0f, 30.0f), 152));
186 application.SendNotification();
188 DALI_TEST_EQUALS(false, data.functorCalled, TEST_LOCATION);
193 int UtcDaliRotationGestureRecognizerMinimumTouchEvents(void)
195 TestApplication application;
197 Actor actor = Actor::New();
198 actor.SetProperty(Actor::Property::SIZE, Vector2(100.0f, 100.0f));
199 actor.SetProperty(Actor::Property::ANCHOR_POINT, AnchorPoint::TOP_LEFT);
200 application.GetScene().Add(actor);
202 application.SendNotification();
203 application.Render();
206 GestureReceivedFunctor functor(data);
208 RotationGestureDetector detector = RotationGestureDetector::New();
209 detector.Attach(actor);
210 detector.DetectedSignal().Connect(&application, functor);
213 // 2 touch events make a gesture begin
214 Integration::SetRotationGestureMinimumTouchEvents(2);
215 application.ProcessEvent(GenerateDoubleTouch(PointState::DOWN, Vector2(20.0f, 20.0f), PointState::DOWN, Vector2(20.0f, 90.0f), 150));
216 application.ProcessEvent(GenerateDoubleTouch(PointState::MOTION, Vector2(20.0f, 20.0f), PointState::MOTION, Vector2(90.0f, 90.0f), 160));
218 DALI_TEST_EQUALS(GestureState::STARTED, data.receivedGesture.GetState(), TEST_LOCATION);
219 DALI_TEST_EQUALS(true, data.functorCalled, TEST_LOCATION);
223 // 4 touch events make a gesture begin
224 Integration::SetRotationGestureMinimumTouchEvents(4);
225 application.ProcessEvent(GenerateDoubleTouch(PointState::DOWN, Vector2(20.0f, 20.0f), PointState::DOWN, Vector2(20.0f, 90.0f), 150));
226 application.ProcessEvent(GenerateDoubleTouch(PointState::MOTION, Vector2(20.0f, 20.0f), PointState::MOTION, Vector2(90.0f, 90.0f), 160));
228 // Check the gesture is not detected unlike previous case
229 DALI_TEST_EQUALS(false, data.functorCalled, TEST_LOCATION);
234 int UtcDaliRotationGestureRecognizerMinimumTouchEventsAfterStart(void)
236 TestApplication application;
238 Actor actor = Actor::New();
239 actor.SetProperty(Actor::Property::SIZE, Vector2(100.0f, 100.0f));
240 actor.SetProperty(Actor::Property::ANCHOR_POINT, AnchorPoint::TOP_LEFT);
241 application.GetScene().Add(actor);
243 application.SendNotification();
244 application.Render();
247 GestureReceivedFunctor functor(data);
249 RotationGestureDetector detector = RotationGestureDetector::New();
250 detector.Attach(actor);
251 detector.DetectedSignal().Connect(&application, functor);
254 // > 2 touch events make a gesture begin
255 // > 4 touch events generate gestures after begin
256 Integration::SetRotationGestureMinimumTouchEvents(2);
257 Integration::SetRotationGestureMinimumTouchEventsAfterStart(6);
259 application.ProcessEvent(GenerateDoubleTouch(PointState::DOWN, Vector2(20.0f, 20.0f), PointState::DOWN, Vector2(20.0f, 90.0f), 150));
260 application.ProcessEvent(GenerateDoubleTouch(PointState::MOTION, Vector2(20.0f, 20.0f), PointState::MOTION, Vector2(90.0f, 90.0f), 160));
262 DALI_TEST_EQUALS(GestureState::STARTED, data.receivedGesture.GetState(), TEST_LOCATION);
263 DALI_TEST_EQUALS(true, data.functorCalled, TEST_LOCATION);
265 application.ProcessEvent(GenerateDoubleTouch(PointState::MOTION, Vector2(20.0f, 20.0f), PointState::MOTION, Vector2(20.0f, 90.0f), 170));
266 application.ProcessEvent(GenerateDoubleTouch(PointState::MOTION, Vector2(20.0f, 20.0f), PointState::MOTION, Vector2(20.0f, 90.0f), 180));
267 application.ProcessEvent(GenerateDoubleTouch(PointState::MOTION, Vector2(20.0f, 20.0f), PointState::MOTION, Vector2(20.0f, 90.0f), 190));
268 application.ProcessEvent(GenerateDoubleTouch(PointState::MOTION, Vector2(20.0f, 20.0f), PointState::MOTION, Vector2(20.0f, 90.0f), 200));
269 // > Test : not enough touch events to make the gesture state "CONTINUING"
270 DALI_TEST_EQUALS(GestureState::STARTED, data.receivedGesture.GetState(), TEST_LOCATION);
272 application.ProcessEvent(GenerateDoubleTouch(PointState::MOTION, Vector2(20.0f, 20.0f), PointState::MOTION, Vector2(20.0f, 90.0f), 210));
273 application.ProcessEvent(GenerateDoubleTouch(PointState::MOTION, Vector2(20.0f, 20.0f), PointState::MOTION, Vector2(20.0f, 90.0f), 220));
274 // > Test : 6 touch events after start make the gesture state "CONTINUING"
275 DALI_TEST_EQUALS(GestureState::CONTINUING, data.receivedGesture.GetState(), TEST_LOCATION);