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>
23 #include <test-touch-event-utils.h>
29 void utc_dali_rotation_gesture_detector_startup(void)
31 test_return_value = TET_UNDEF;
34 void utc_dali_rotation_gesture_detector_cleanup(void)
36 test_return_value = TET_PASS;
39 ///////////////////////////////////////////////////////////////////////////////
42 // Stores data that is populated in the callback and will be read by the TET cases
46 : functorCalled(false),
47 voidFunctorCalled(false),
54 functorCalled = false;
55 voidFunctorCalled = false;
57 receivedGesture.Reset();
63 bool voidFunctorCalled;
64 RotationGesture receivedGesture;
68 // Functor that sets the data when called
69 struct GestureReceivedFunctor
71 GestureReceivedFunctor(SignalData& data)
76 void operator()(Actor actor, const RotationGesture& rotation)
78 signalData.functorCalled = true;
79 signalData.receivedGesture = rotation;
80 signalData.rotatedActor = actor;
85 signalData.voidFunctorCalled = true;
88 SignalData& signalData;
91 // Functor that removes the gestured actor from stage
92 struct UnstageActorFunctor : public GestureReceivedFunctor
94 UnstageActorFunctor(SignalData& data, GestureState& stateToUnstage, Integration::Scene scene)
95 : GestureReceivedFunctor(data),
96 stateToUnstage(stateToUnstage),
101 void operator()(Actor actor, const RotationGesture& rotation)
103 GestureReceivedFunctor::operator()(actor, rotation);
105 if(rotation.GetState() == stateToUnstage)
111 GestureState& stateToUnstage;
112 Integration::Scene scene;
117 ///////////////////////////////////////////////////////////////////////////////
119 int UtcDaliRotationGestureDetectorConstructor(void)
121 TestApplication application;
123 RotationGestureDetector detector;
124 DALI_TEST_CHECK(!detector);
128 int UtcDaliRotationGestureDetectorCopyConstructorP(void)
130 TestApplication application;
132 RotationGestureDetector detector = RotationGestureDetector::New();
135 RotationGestureDetector copy(detector);
136 DALI_TEST_CHECK(detector);
140 int UtcDaliRotationGestureDetectorAssignmentOperatorP(void)
142 TestApplication application;
144 RotationGestureDetector detector = RotationGestureDetector::New();
147 RotationGestureDetector assign;
149 DALI_TEST_CHECK(detector);
151 DALI_TEST_CHECK(detector == assign);
155 int UtcDaliRotationGestureDetectorNew(void)
157 TestApplication application;
159 RotationGestureDetector detector = RotationGestureDetector::New();
161 DALI_TEST_CHECK(detector);
163 // Attach an actor and emit a touch event on the actor to ensure complete line coverage
164 Actor actor = Actor::New();
165 actor.SetProperty(Actor::Property::SIZE, Vector2(100.0f, 100.0f));
166 actor.SetProperty(Actor::Property::ANCHOR_POINT, AnchorPoint::TOP_LEFT);
167 application.GetScene().Add(actor);
170 application.SendNotification();
171 application.Render();
173 detector.Attach(actor);
175 Integration::TouchEvent touchEvent(1);
176 Integration::Point point;
177 point.SetDeviceId(1);
178 point.SetState(PointState::DOWN);
179 point.SetScreenPosition(Vector2(20.0f, 20.0f));
180 touchEvent.AddPoint(point);
181 application.ProcessEvent(touchEvent);
183 Integration::Point point2;
184 point.SetDeviceId(1);
185 point.SetState(PointState::DOWN);
186 point.SetScreenPosition(Vector2(20.0f, 20.0f));
187 touchEvent.AddPoint(point2);
188 application.ProcessEvent(touchEvent);
192 int UtcDaliRotationGestureDetectorDownCast(void)
194 TestApplication application;
195 tet_infoline("Testing Dali::RotationGestureDetector::DownCast()");
197 RotationGestureDetector detector = RotationGestureDetector::New();
199 BaseHandle object(detector);
201 RotationGestureDetector detector2 = RotationGestureDetector::DownCast(object);
202 DALI_TEST_CHECK(detector2);
204 RotationGestureDetector detector3 = DownCast<RotationGestureDetector>(object);
205 DALI_TEST_CHECK(detector3);
207 BaseHandle unInitializedObject;
208 RotationGestureDetector detector4 = RotationGestureDetector::DownCast(unInitializedObject);
209 DALI_TEST_CHECK(!detector4);
211 RotationGestureDetector detector5 = DownCast<RotationGestureDetector>(unInitializedObject);
212 DALI_TEST_CHECK(!detector5);
214 GestureDetector detector6 = RotationGestureDetector::New();
215 RotationGestureDetector detector7 = RotationGestureDetector::DownCast(detector6);
216 DALI_TEST_CHECK(detector7);
220 // Negative test case for a method
221 int UtcDaliRotationGestureSignalReceptionNegative(void)
223 TestApplication application;
225 Actor actor = Actor::New();
226 actor.SetProperty(Actor::Property::SIZE, Vector2(100.0f, 100.0f));
227 actor.SetProperty(Actor::Property::ANCHOR_POINT, AnchorPoint::TOP_LEFT);
228 application.GetScene().Add(actor);
231 application.SendNotification();
232 application.Render();
235 GestureReceivedFunctor functor(data);
237 RotationGestureDetector detector = RotationGestureDetector::New();
238 detector.Attach(actor);
239 detector.DetectedSignal().Connect(&application, functor);
241 // Do a rotation outside actor's area
242 TestStartRotation(application, Vector2(112.0f, 62.0f), Vector2(112.0f, 162.0f), Vector2(112.0f, 100.0f), Vector2(112.0f, 124.0f), 100);
244 DALI_TEST_EQUALS(false, data.functorCalled, TEST_LOCATION);
246 // Continue rotation into actor's area - we should still not receive the signal
248 TestContinueRotation(application, Vector2(112.0f, 100.0f), Vector2(112.0f, 124.0f), Vector2(5.0f, 5.0f), Vector2(35.0f, 35.0f), 200);
250 DALI_TEST_EQUALS(false, data.functorCalled, TEST_LOCATION);
252 // Stop rotating - we should still not receive the signal
254 TestEndRotation(application, Vector2(6.0f, 6.0f), Vector2(18.0f, 18.0f), Vector2(10.0f, 8.0f), Vector2(14.0f, 16.0f), 300);
256 DALI_TEST_EQUALS(false, data.functorCalled, TEST_LOCATION);
260 int UtcDaliRotationGestureSignalReceptionDownMotionLeave(void)
262 TestApplication application;
264 Actor actor = Actor::New();
265 actor.SetProperty(Actor::Property::SIZE, Vector2(100.0f, 100.0f));
266 actor.SetProperty(Actor::Property::ANCHOR_POINT, AnchorPoint::TOP_LEFT);
267 application.GetScene().Add(actor);
270 application.SendNotification();
271 application.Render();
274 GestureReceivedFunctor functor(data);
276 RotationGestureDetector detector = RotationGestureDetector::New();
277 detector.Attach(actor);
278 detector.DetectedSignal().Connect(&application, functor);
280 // Start rotation within the actor's area
281 TestStartRotation(application, Vector2(5.0f, 5.0f), Vector2(20.0f, 20.0f), Vector2(5.0f, 5.0f), Vector2(20.0f, 30.0f), 100);
282 DALI_TEST_EQUALS(true, data.functorCalled, TEST_LOCATION);
283 DALI_TEST_EQUALS(GestureState::STARTED, data.receivedGesture.GetState(), TEST_LOCATION);
284 DALI_TEST_EQUALS(0.244f, data.receivedGesture.GetRotation().radian, 0.01f, TEST_LOCATION);
285 DALI_TEST_EQUALS(Vector2(12.5f, 17.5f), data.receivedGesture.GetScreenCenterPoint(), 0.01f, TEST_LOCATION);
286 DALI_TEST_EQUALS(Vector2(12.48f, 17.5f), data.receivedGesture.GetLocalCenterPoint(), 0.01f, TEST_LOCATION);
288 // Continue the rotation within the actor's area - we should still receive the signal
290 TestContinueRotation(application, Vector2(10.0f, 20.0f), Vector2(30.0f, 20.0f), Vector2(17.0f, 20.0f), Vector2(25.0f, 20.0f), 400);
291 DALI_TEST_EQUALS(true, data.functorCalled, TEST_LOCATION);
292 DALI_TEST_EQUALS(GestureState::CONTINUING, data.receivedGesture.GetState(), TEST_LOCATION);
293 DALI_TEST_EQUALS(-0.785398f, data.receivedGesture.GetRotation().radian, 0.01f, TEST_LOCATION);
294 DALI_TEST_EQUALS(Vector2(21.0f, 20.0f), data.receivedGesture.GetScreenCenterPoint(), 0.01f, TEST_LOCATION);
295 DALI_TEST_EQUALS(Vector2(21.0f, 20.0f), data.receivedGesture.GetLocalCenterPoint(), 0.01f, TEST_LOCATION);
297 // Rotation Gesture leaves actor's area - we should still receive the signal
299 TestContinueRotation(application, Vector2(17.0f, 20.0f), Vector2(25.0f, 20.0f), Vector2(300.0f, 10.0f), Vector2(340.0f, 10.0f), 1000);
300 DALI_TEST_EQUALS(true, data.functorCalled, TEST_LOCATION);
301 DALI_TEST_EQUALS(GestureState::CONTINUING, data.receivedGesture.GetState(), TEST_LOCATION);
302 DALI_TEST_EQUALS(-0.785398f, data.receivedGesture.GetRotation().radian, 0.01f, TEST_LOCATION);
303 DALI_TEST_EQUALS(Vector2(320.0f, 10.0f), data.receivedGesture.GetScreenCenterPoint(), 0.01f, TEST_LOCATION);
304 DALI_TEST_EQUALS(Vector2(320.0f, 10.0f), data.receivedGesture.GetLocalCenterPoint(), 0.01f, TEST_LOCATION);
306 // Gesture ends - we would receive a finished state
308 TestEndRotation(application, Vector2(300.0f, 10.0f), Vector2(340.0f, 10.0f), Vector2(305.0f, 10.0f), Vector2(315.0f, 10.0f), 1500);
309 DALI_TEST_EQUALS(true, data.functorCalled, TEST_LOCATION);
310 DALI_TEST_EQUALS(GestureState::FINISHED, data.receivedGesture.GetState(), TEST_LOCATION);
311 DALI_TEST_EQUALS(-0.785398f, data.receivedGesture.GetRotation().radian, 0.01f, TEST_LOCATION);
312 DALI_TEST_EQUALS(Vector2(310.0f, 10.0f), data.receivedGesture.GetScreenCenterPoint(), 0.01f, TEST_LOCATION);
313 DALI_TEST_EQUALS(Vector2(310.0f, 10.0f), data.receivedGesture.GetLocalCenterPoint(), 0.01f, TEST_LOCATION);
317 int UtcDaliRotationGestureSignalReceptionDownMotionUp(void)
319 TestApplication application;
321 Actor actor = Actor::New();
322 actor.SetProperty(Actor::Property::SIZE, Vector2(100.0f, 100.0f));
323 actor.SetProperty(Actor::Property::ANCHOR_POINT, AnchorPoint::TOP_LEFT);
324 application.GetScene().Add(actor);
327 application.SendNotification();
328 application.Render();
331 GestureReceivedFunctor functor(data);
333 RotationGestureDetector detector = RotationGestureDetector::New();
334 detector.Attach(actor);
335 detector.DetectedSignal().Connect(&application, functor);
337 // Start rotation within the actor's area
338 TestStartRotation(application, Vector2(2.0f, 20.0f), Vector2(38.0f, 20.0f), Vector2(10.0f, 20.0f), Vector2(31.0f, 29.0f), 100);
339 DALI_TEST_EQUALS(true, data.functorCalled, TEST_LOCATION);
340 DALI_TEST_EQUALS(GestureState::STARTED, data.receivedGesture.GetState(), TEST_LOCATION);
341 DALI_TEST_EQUALS(0.404892f, data.receivedGesture.GetRotation().radian, 0.01f, TEST_LOCATION);
342 DALI_TEST_EQUALS(Vector2(20.5f, 24.5f), data.receivedGesture.GetScreenCenterPoint(), 0.01f, TEST_LOCATION);
343 DALI_TEST_EQUALS(Vector2(20.5f, 24.5f), data.receivedGesture.GetLocalCenterPoint(), 0.01f, TEST_LOCATION);
345 // Continue the rotation within the actor's area - we should still receive the signal
347 TestContinueRotation(application, Vector2(10.0f, 20.0f), Vector2(30.0f, 20.0f), Vector2(15.0f, 20.0f), Vector2(29.0f, 15.0f), 500);
348 DALI_TEST_EQUALS(true, data.functorCalled, TEST_LOCATION);
349 DALI_TEST_EQUALS(GestureState::CONTINUING, data.receivedGesture.GetState(), TEST_LOCATION);
350 DALI_TEST_EQUALS(-0.343024f, data.receivedGesture.GetRotation().radian, 0.01f, TEST_LOCATION);
351 DALI_TEST_EQUALS(Vector2(22.0f, 17.5f), data.receivedGesture.GetScreenCenterPoint(), 0.01f, TEST_LOCATION);
352 DALI_TEST_EQUALS(Vector2(22.0f, 17.5f), data.receivedGesture.GetLocalCenterPoint(), 0.01f, TEST_LOCATION);
354 // Gesture ends within actor's area - we would receive a finished state
356 TestEndRotation(application, Vector2(15.0f, 20.0f), Vector2(25.0f, 20.0f), Vector2(19.0f, 20.0f), Vector2(29.0f, 15.0f), 1000);
357 DALI_TEST_EQUALS(true, data.functorCalled, TEST_LOCATION);
358 DALI_TEST_EQUALS(GestureState::FINISHED, data.receivedGesture.GetState(), TEST_LOCATION);
359 DALI_TEST_EQUALS(-0.463648f, data.receivedGesture.GetRotation().radian, 0.01f, TEST_LOCATION);
360 DALI_TEST_EQUALS(Vector2(24.0f, 17.5f), data.receivedGesture.GetScreenCenterPoint(), 0.01f, TEST_LOCATION);
361 DALI_TEST_EQUALS(Vector2(24.0f, 17.5f), data.receivedGesture.GetLocalCenterPoint(), 0.01f, TEST_LOCATION);
365 int UtcDaliRotationGestureSignalReceptionDetach(void)
367 TestApplication application;
369 Actor actor = Actor::New();
370 actor.SetProperty(Actor::Property::SIZE, Vector2(100.0f, 100.0f));
371 actor.SetProperty(Actor::Property::ANCHOR_POINT, AnchorPoint::TOP_LEFT);
372 application.GetScene().Add(actor);
375 application.SendNotification();
376 application.Render();
379 GestureReceivedFunctor functor(data);
381 RotationGestureDetector detector = RotationGestureDetector::New();
382 detector.Attach(actor);
383 detector.DetectedSignal().Connect(&application, functor);
385 // Start rotation within the actor's area
386 TestStartRotation(application, Vector2(2.0f, 20.0f), Vector2(38.0f, 20.0f), Vector2(10.0f, 20.0f), Vector2(30.0f, 20.0f), 100);
387 DALI_TEST_EQUALS(true, data.functorCalled, TEST_LOCATION);
388 DALI_TEST_EQUALS(GestureState::STARTED, data.receivedGesture.GetState(), TEST_LOCATION);
390 // Continue the rotation within the actor's area - we should still receive the signal
392 TestContinueRotation(application, Vector2(10.0f, 20.0f), Vector2(30.0f, 20.0f), Vector2(15.0f, 20.0f), Vector2(25.0f, 20.0f), 500);
393 DALI_TEST_EQUALS(true, data.functorCalled, TEST_LOCATION);
394 DALI_TEST_EQUALS(GestureState::CONTINUING, data.receivedGesture.GetState(), TEST_LOCATION);
396 // Gesture ends within actor's area
398 TestEndRotation(application, Vector2(15.0f, 20.0f), Vector2(25.0f, 20.0f), Vector2(19.0f, 20.0f), Vector2(21.0f, 20.0f), 1000);
399 DALI_TEST_EQUALS(true, data.functorCalled, TEST_LOCATION);
400 DALI_TEST_EQUALS(GestureState::FINISHED, data.receivedGesture.GetState(), TEST_LOCATION);
403 detector.DetachAll();
405 // Ensure we are no longer signalled
407 TestGenerateRotation(application);
408 DALI_TEST_EQUALS(false, data.functorCalled, TEST_LOCATION);
412 int UtcDaliRotationGestureSignalReceptionDetachWhileRotationing(void)
414 TestApplication application;
416 Actor actor = Actor::New();
417 actor.SetProperty(Actor::Property::SIZE, Vector2(100.0f, 100.0f));
418 actor.SetProperty(Actor::Property::ANCHOR_POINT, AnchorPoint::TOP_LEFT);
419 application.GetScene().Add(actor);
422 application.SendNotification();
423 application.Render();
426 GestureReceivedFunctor functor(data);
428 RotationGestureDetector detector = RotationGestureDetector::New();
429 detector.Attach(actor);
430 detector.DetectedSignal().Connect(&application, functor);
432 // Start rotation within the actor's area
433 TestStartRotation(application, Vector2(2.0f, 20.0f), Vector2(38.0f, 20.0f), Vector2(10.0f, 20.0f), Vector2(30.0f, 20.0f), 100);
434 DALI_TEST_EQUALS(true, data.functorCalled, TEST_LOCATION);
435 DALI_TEST_EQUALS(GestureState::STARTED, data.receivedGesture.GetState(), TEST_LOCATION);
437 // Continue the rotation within the actor's area - we should still receive the signal
439 TestContinueRotation(application, Vector2(10.0f, 20.0f), Vector2(30.0f, 20.0f), Vector2(15.0f, 20.0f), Vector2(25.0f, 20.0f), 500);
440 DALI_TEST_EQUALS(true, data.functorCalled, TEST_LOCATION);
441 DALI_TEST_EQUALS(GestureState::CONTINUING, data.receivedGesture.GetState(), TEST_LOCATION);
443 // Detach actor during the rotation, we should not receive the next event
444 detector.DetachAll();
446 // Gesture ends within actor's area
448 TestEndRotation(application, Vector2(15.0f, 20.0f), Vector2(25.0f, 20.0f), Vector2(19.0f, 20.0f), Vector2(21.0f, 20.0f), 1000);
449 DALI_TEST_EQUALS(false, data.functorCalled, TEST_LOCATION);
453 int UtcDaliRotationGestureSignalReceptionActorDestroyedWhileRotationing(void)
455 TestApplication application;
458 GestureReceivedFunctor functor(data);
460 RotationGestureDetector detector = RotationGestureDetector::New();
461 detector.DetectedSignal().Connect(&application, functor);
463 // Attach a temporary actor to stop detector being removed from RotationGestureProcessor when main actor
465 Actor tempActor = Actor::New();
466 tempActor.SetProperty(Actor::Property::SIZE, Vector2(100.0f, 100.0f));
467 tempActor.SetProperty(Actor::Property::ANCHOR_POINT, AnchorPoint::BOTTOM_RIGHT);
468 application.GetScene().Add(tempActor);
469 detector.Attach(tempActor);
471 // Actor lifetime is scoped
473 Actor actor = Actor::New();
474 actor.SetProperty(Actor::Property::SIZE, Vector2(100.0f, 100.0f));
475 actor.SetProperty(Actor::Property::ANCHOR_POINT, AnchorPoint::TOP_LEFT);
476 application.GetScene().Add(actor);
479 application.SendNotification();
480 application.Render();
482 detector.Attach(actor);
484 // Start rotation within the actor's area
485 TestStartRotation(application, Vector2(2.0f, 20.0f), Vector2(38.0f, 20.0f), Vector2(10.0f, 20.0f), Vector2(30.0f, 20.0f), 100);
486 DALI_TEST_EQUALS(true, data.functorCalled, TEST_LOCATION);
487 DALI_TEST_EQUALS(GestureState::STARTED, data.receivedGesture.GetState(), TEST_LOCATION);
489 // Continue the rotation within the actor's area - we should still receive the signal
491 TestContinueRotation(application, Vector2(10.0f, 20.0f), Vector2(30.0f, 20.0f), Vector2(15.0f, 20.0f), Vector2(25.0f, 20.0f), 500);
492 DALI_TEST_EQUALS(true, data.functorCalled, TEST_LOCATION);
493 DALI_TEST_EQUALS(GestureState::CONTINUING, data.receivedGesture.GetState(), TEST_LOCATION);
495 // Remove the actor from stage and reset the data
496 application.GetScene().Remove(actor);
499 application.SendNotification();
500 application.Render();
503 // Actor should now have been destroyed
505 // Gesture ends within the area where the actor used to be
507 TestEndRotation(application, Vector2(15.0f, 20.0f), Vector2(25.0f, 20.0f), Vector2(19.0f, 20.0f), Vector2(21.0f, 20.0f), 1000);
508 DALI_TEST_EQUALS(false, data.functorCalled, TEST_LOCATION);
512 int UtcDaliRotationGestureSignalReceptionRotatedActor(void)
514 TestApplication application;
516 Actor actor = Actor::New();
517 actor.SetProperty(Actor::Property::SIZE, Vector2(100.0f, 100.0f));
518 actor.SetProperty(Actor::Property::ORIENTATION, Quaternion(Dali::Degree(90.0f), Vector3::ZAXIS));
519 application.GetScene().Add(actor);
521 // Render and notify a couple of times
522 application.SendNotification();
523 application.Render();
526 GestureReceivedFunctor functor(data);
528 RotationGestureDetector detector = RotationGestureDetector::New();
529 detector.Attach(actor);
530 detector.DetectedSignal().Connect(&application, functor);
532 // Do an entire rotation, only check finished value
533 TestStartRotation(application, Vector2(2.0f, 20.0f), Vector2(38.0f, 20.0f), Vector2(10.0f, 20.0f), Vector2(30.0f, 20.0f), 100);
535 TestEndRotation(application, Vector2(15.0f, 20.0f), Vector2(25.0f, 20.0f), Vector2(19.0f, 20.0f), Vector2(27.0f, 15.0f), 1000);
536 DALI_TEST_EQUALS(true, data.functorCalled, TEST_LOCATION);
537 DALI_TEST_EQUALS(-0.558599f, data.receivedGesture.GetRotation().radian, 0.01f, TEST_LOCATION);
538 DALI_TEST_EQUALS(Vector2(23.0f, 17.5f), data.receivedGesture.GetScreenCenterPoint(), 0.01f, TEST_LOCATION);
539 DALI_TEST_EQUALS(Vector2(67.5f, 27.0f), data.receivedGesture.GetLocalCenterPoint(), 0.01f, TEST_LOCATION);
541 // Rotate actor again and render and notify
542 actor.SetProperty(Actor::Property::ORIENTATION, Quaternion(Dali::Degree(180.0f), Vector3::ZAXIS));
543 application.SendNotification();
544 application.Render();
546 // Do an entire rotation, only check finished value
547 TestStartRotation(application, Vector2(2.0f, 20.0f), Vector2(38.0f, 20.0f), Vector2(10.0f, 20.0f), Vector2(30.0f, 20.0f), 2100);
549 TestEndRotation(application, Vector2(15.0f, 20.0f), Vector2(25.0f, 20.0f), Vector2(19.0f, 20.0f), Vector2(27.0f, 15.0f), 3000);
550 DALI_TEST_EQUALS(true, data.functorCalled, TEST_LOCATION);
551 DALI_TEST_EQUALS(-0.558599f, data.receivedGesture.GetRotation().radian, 0.01f, TEST_LOCATION);
552 DALI_TEST_EQUALS(Vector2(23.0f, 17.5f), data.receivedGesture.GetScreenCenterPoint(), 0.01f, TEST_LOCATION);
553 DALI_TEST_EQUALS(Vector2(27.0f, 32.5f), data.receivedGesture.GetLocalCenterPoint(), 0.01f, TEST_LOCATION);
555 // Rotate actor again and render and notify
556 actor.SetProperty(Actor::Property::ORIENTATION, Quaternion(Dali::Degree(270.0f), Vector3::ZAXIS));
557 application.SendNotification();
558 application.Render();
560 // Do an entire rotation, only check finished value
561 TestStartRotation(application, Vector2(2.0f, 20.0f), Vector2(38.0f, 20.0f), Vector2(10.0f, 20.0f), Vector2(30.0f, 20.0f), 4100);
563 TestEndRotation(application, Vector2(15.0f, 20.0f), Vector2(25.0f, 20.0f), Vector2(19.0f, 20.0f), Vector2(27.0f, 15.0f), 5000);
564 DALI_TEST_EQUALS(true, data.functorCalled, TEST_LOCATION);
565 DALI_TEST_EQUALS(-0.558599f, data.receivedGesture.GetRotation().radian, 0.01f, TEST_LOCATION);
566 DALI_TEST_EQUALS(Vector2(23.0f, 17.5f), data.receivedGesture.GetScreenCenterPoint(), 0.01f, TEST_LOCATION);
567 DALI_TEST_EQUALS(Vector2(32.5f, 73.0f), data.receivedGesture.GetLocalCenterPoint(), 0.01f, TEST_LOCATION);
571 int UtcDaliRotationGestureSignalReceptionChildHit(void)
573 TestApplication application;
575 Actor parent = Actor::New();
576 parent.SetProperty(Actor::Property::SIZE, Vector2(100.0f, 100.0f));
577 parent.SetProperty(Actor::Property::ANCHOR_POINT, AnchorPoint::TOP_LEFT);
578 application.GetScene().Add(parent);
580 // Set child to completely cover parent.
581 // Change rotation of child to be different from parent so that we can check if our local coordinate
582 // conversion of the parent actor is correct.
583 Actor child = Actor::New();
584 child.SetProperty(Actor::Property::SIZE, Vector2(100.0f, 100.0f));
585 child.SetProperty(Actor::Property::ANCHOR_POINT, AnchorPoint::CENTER);
586 child.SetProperty(Actor::Property::PARENT_ORIGIN, ParentOrigin::CENTER);
587 child.SetProperty(Actor::Property::ORIENTATION, Quaternion(Dali::Degree(90.0f), Vector3::ZAXIS));
591 application.SendNotification();
592 application.Render();
595 GestureReceivedFunctor functor(data);
597 RotationGestureDetector detector = RotationGestureDetector::New();
598 detector.Attach(parent);
599 detector.DetectedSignal().Connect(&application, functor);
601 // Do an entire pan, only check finished value - hits child area but parent should still receive it
602 TestStartRotation(application, Vector2(2.0f, 20.0f), Vector2(38.0f, 20.0f), Vector2(10.0f, 20.0f), Vector2(30.0f, 20.0f), 100);
604 TestEndRotation(application, Vector2(15.0f, 20.0f), Vector2(25.0f, 20.0f), Vector2(19.0f, 20.0f), Vector2(29.0f, 25.0f), 1000);
605 DALI_TEST_EQUALS(true, data.functorCalled, TEST_LOCATION);
606 DALI_TEST_EQUALS(true, parent == data.rotatedActor, TEST_LOCATION);
607 DALI_TEST_EQUALS(0.463648f, data.receivedGesture.GetRotation().radian, 0.01f, TEST_LOCATION);
608 DALI_TEST_EQUALS(Vector2(24.0f, 22.5f), data.receivedGesture.GetScreenCenterPoint(), 0.01f, TEST_LOCATION);
609 DALI_TEST_EQUALS(Vector2(24.0f, 22.5f), data.receivedGesture.GetLocalCenterPoint(), 0.01f, TEST_LOCATION);
611 // Attach child and generate same touch points to yield same results
612 // (Also proves that you can detach and then re-attach another actor)
613 detector.Attach(child);
614 detector.Detach(parent);
616 // Do an entire pan, only check finished value
617 TestStartRotation(application, Vector2(2.0f, 20.0f), Vector2(38.0f, 20.0f), Vector2(10.0f, 20.0f), Vector2(30.0f, 20.0f), 2100);
619 TestEndRotation(application, Vector2(15.0f, 20.0f), Vector2(25.0f, 20.0f), Vector2(19.0f, 20.0f), Vector2(29.0f, 35.0f), 3000);
620 DALI_TEST_EQUALS(true, data.functorCalled, TEST_LOCATION);
621 DALI_TEST_EQUALS(true, child == data.rotatedActor, TEST_LOCATION);
622 DALI_TEST_EQUALS(0.982794f, data.receivedGesture.GetRotation().radian, 0.01f, TEST_LOCATION);
623 DALI_TEST_EQUALS(Vector2(24.0f, 27.5f), data.receivedGesture.GetScreenCenterPoint(), 0.01f, TEST_LOCATION);
624 DALI_TEST_EQUALS(Vector2(27.5f, 76.0f), data.receivedGesture.GetLocalCenterPoint(), 0.01f, TEST_LOCATION);
628 int UtcDaliRotationGestureSignalReceptionAttachDetachMany(void)
630 TestApplication application;
632 Actor first = Actor::New();
633 first.SetProperty(Actor::Property::SIZE, Vector2(100.0f, 100.0f));
634 first.SetProperty(Actor::Property::ANCHOR_POINT, AnchorPoint::TOP_LEFT);
635 application.GetScene().Add(first);
637 Actor second = Actor::New();
638 second.SetProperty(Actor::Property::SIZE, Vector2(100.0f, 100.0f));
639 second.SetProperty(Actor::Property::POSITION_X, 100.0f);
640 second.SetProperty(Actor::Property::ANCHOR_POINT, AnchorPoint::TOP_LEFT);
641 application.GetScene().Add(second);
644 application.SendNotification();
645 application.Render();
648 GestureReceivedFunctor functor(data);
650 RotationGestureDetector detector = RotationGestureDetector::New();
651 detector.Attach(first);
652 detector.Attach(second);
653 detector.DetectedSignal().Connect(&application, functor);
655 // Start rotation within second actor's area
656 TestStartRotation(application, Vector2(102.0f, 20.0f), Vector2(138.0f, 20.0f), Vector2(110.0f, 20.0f), Vector2(130.0f, 20.0f), 100);
657 DALI_TEST_EQUALS(true, data.functorCalled, TEST_LOCATION);
658 DALI_TEST_EQUALS(true, second == data.rotatedActor, TEST_LOCATION);
660 // Rotation moves into first actor's area - second actor should receive the rotation
662 TestContinueRotation(application, Vector2(110.0f, 20.0f), Vector2(130.0f, 20.0f), Vector2(15.0f, 20.0f), Vector2(25.0f, 20.0f), 500);
663 DALI_TEST_EQUALS(true, data.functorCalled, TEST_LOCATION);
664 DALI_TEST_EQUALS(true, second == data.rotatedActor, TEST_LOCATION);
666 // Detach the second actor during the rotation, we should not receive the next event
667 detector.Detach(second);
669 // Gesture ends within actor's area
671 TestEndRotation(application, Vector2(15.0f, 20.0f), Vector2(25.0f, 20.0f), Vector2(119.0f, 20.0f), Vector2(121.0f, 20.0f), 3000);
672 DALI_TEST_EQUALS(false, data.functorCalled, TEST_LOCATION);
676 int UtcDaliRotationGestureSignalReceptionActorBecomesUntouchable(void)
678 TestApplication application;
680 Actor actor = Actor::New();
681 actor.SetProperty(Actor::Property::SIZE, Vector2(100.0f, 100.0f));
682 actor.SetProperty(Actor::Property::ANCHOR_POINT, AnchorPoint::TOP_LEFT);
683 application.GetScene().Add(actor);
686 application.SendNotification();
687 application.Render();
690 GestureReceivedFunctor functor(data);
692 RotationGestureDetector detector = RotationGestureDetector::New();
693 detector.Attach(actor);
694 detector.DetectedSignal().Connect(&application, functor);
696 // Start rotation in actor's area
697 TestStartRotation(application, Vector2(2.0f, 20.0f), Vector2(38.0f, 20.0f), Vector2(10.0f, 20.0f), Vector2(30.0f, 20.0f), 100);
698 DALI_TEST_EQUALS(true, data.functorCalled, TEST_LOCATION);
700 // Rotation continues within actor's area
702 TestContinueRotation(application, Vector2(10.0f, 20.0f), Vector2(30.0f, 20.0f), Vector2(15.0f, 20.0f), Vector2(25.0f, 20.0f), 500);
703 DALI_TEST_EQUALS(true, data.functorCalled, TEST_LOCATION);
705 // Actor become invisible - actor should not receive the next rotation
706 actor.SetProperty(Actor::Property::VISIBLE, false);
709 application.SendNotification();
710 application.Render();
712 // Gesture ends within actor's area
714 TestEndRotation(application, Vector2(15.0f, 20.0f), Vector2(25.0f, 20.0f), Vector2(19.0f, 20.0f), Vector2(21.0f, 20.0f), 3000);
715 DALI_TEST_EQUALS(false, data.functorCalled, TEST_LOCATION);
719 int UtcDaliRotationGestureSignalReceptionMultipleDetectorsOnActor(void)
721 TestApplication application;
723 Actor actor = Actor::New();
724 actor.SetProperty(Actor::Property::SIZE, Vector2(100.0f, 100.0f));
725 actor.SetProperty(Actor::Property::ANCHOR_POINT, AnchorPoint::TOP_LEFT);
726 application.GetScene().Add(actor);
728 Actor actor2 = Actor::New();
729 actor2.SetProperty(Actor::Property::SIZE, Vector2(100.0f, 100.0f));
730 actor2.SetProperty(Actor::Property::ANCHOR_POINT, AnchorPoint::BOTTOM_RIGHT);
731 application.GetScene().Add(actor2);
734 application.SendNotification();
735 application.Render();
737 // Attach actor to one detector
738 SignalData firstData;
739 GestureReceivedFunctor firstFunctor(firstData);
740 RotationGestureDetector firstDetector = RotationGestureDetector::New();
741 firstDetector.Attach(actor);
742 firstDetector.DetectedSignal().Connect(&application, firstFunctor);
744 // Attach actor to another detector
745 SignalData secondData;
746 GestureReceivedFunctor secondFunctor(secondData);
747 RotationGestureDetector secondDetector = RotationGestureDetector::New();
748 secondDetector.Attach(actor);
749 secondDetector.DetectedSignal().Connect(&application, secondFunctor);
751 // Add second actor to second detector, when we remove the actor, this will make sure that this
752 // gesture detector is not removed from the GestureDetectorProcessor. In this scenario, the
753 // functor should still not be called (which is what we're also testing).
754 secondDetector.Attach(actor2);
756 // Rotation in actor's area - both detector's functors should be called
757 TestStartRotation(application, Vector2(2.0f, 20.0f), Vector2(38.0f, 20.0f), Vector2(10.0f, 20.0f), Vector2(30.0f, 20.0f), 100);
758 DALI_TEST_EQUALS(true, firstData.functorCalled, TEST_LOCATION);
759 DALI_TEST_EQUALS(true, secondData.functorCalled, TEST_LOCATION);
761 // Rotation continues in actor's area - both detector's functors should be called
764 TestContinueRotation(application, Vector2(10.0f, 20.0f), Vector2(30.0f, 20.0f), Vector2(15.0f, 20.0f), Vector2(25.0f, 20.0f), 500);
765 DALI_TEST_EQUALS(true, firstData.functorCalled, TEST_LOCATION);
766 DALI_TEST_EQUALS(true, secondData.functorCalled, TEST_LOCATION);
768 // Detach actor from firstDetector and emit rotation on actor, only secondDetector's functor should be called.
769 firstDetector.Detach(actor);
772 TestEndRotation(application, Vector2(15.0f, 20.0f), Vector2(25.0f, 20.0f), Vector2(19.0f, 20.0f), Vector2(21.0f, 20.0f), 1000);
773 DALI_TEST_EQUALS(false, firstData.functorCalled, TEST_LOCATION);
774 DALI_TEST_EQUALS(true, secondData.functorCalled, TEST_LOCATION);
776 // New rotation on actor, only secondDetector has actor attached
779 TestStartRotation(application, Vector2(2.0f, 20.0f), Vector2(38.0f, 20.0f), Vector2(10.0f, 20.0f), Vector2(30.0f, 20.0f), 1500);
780 DALI_TEST_EQUALS(false, firstData.functorCalled, TEST_LOCATION);
781 DALI_TEST_EQUALS(true, secondData.functorCalled, TEST_LOCATION);
783 // Detach actor from secondDetector
784 secondDetector.Detach(actor);
787 TestContinueRotation(application, Vector2(10.0f, 20.0f), Vector2(30.0f, 20.0f), Vector2(15.0f, 20.0f), Vector2(25.0f, 20.0f), 2000);
788 DALI_TEST_EQUALS(false, firstData.functorCalled, TEST_LOCATION);
789 DALI_TEST_EQUALS(false, secondData.functorCalled, TEST_LOCATION);
793 int UtcDaliRotationGestureSignalReceptionEnsureCorrectSignalling(void)
795 TestApplication application;
797 Actor actor1 = Actor::New();
798 actor1.SetProperty(Actor::Property::SIZE, Vector2(100.0f, 100.0f));
799 actor1.SetProperty(Actor::Property::ANCHOR_POINT, AnchorPoint::TOP_LEFT);
800 application.GetScene().Add(actor1);
802 GestureReceivedFunctor functor1(data1);
803 RotationGestureDetector detector1 = RotationGestureDetector::New();
804 detector1.Attach(actor1);
805 detector1.DetectedSignal().Connect(&application, functor1);
807 Actor actor2 = Actor::New();
808 actor2.SetProperty(Actor::Property::SIZE, Vector2(100.0f, 100.0f));
809 actor2.SetProperty(Actor::Property::ANCHOR_POINT, AnchorPoint::BOTTOM_RIGHT);
810 actor2.SetProperty(Actor::Property::PARENT_ORIGIN, ParentOrigin::BOTTOM_RIGHT);
811 application.GetScene().Add(actor2);
813 GestureReceivedFunctor functor2(data2);
814 RotationGestureDetector detector2 = RotationGestureDetector::New();
815 detector2.Attach(actor2);
816 detector2.DetectedSignal().Connect(&application, functor2);
819 application.SendNotification();
820 application.Render();
822 // Start pan in actor1's area, only data1 should be set
823 TestStartRotation(application, Vector2(2.0f, 20.0f), Vector2(38.0f, 20.0f), Vector2(10.0f, 20.0f), Vector2(30.0f, 20.0f), 100);
824 DALI_TEST_EQUALS(true, data1.functorCalled, TEST_LOCATION);
825 DALI_TEST_EQUALS(false, data2.functorCalled, TEST_LOCATION);
829 int UtcDaliRotationGestureActorUnstaged(void)
831 TestApplication application;
833 Actor actor = Actor::New();
834 actor.SetProperty(Actor::Property::SIZE, Vector2(100.0f, 100.0f));
835 actor.SetProperty(Actor::Property::ANCHOR_POINT, AnchorPoint::TOP_LEFT);
836 application.GetScene().Add(actor);
839 application.SendNotification();
840 application.Render();
842 // State to remove actor in.
843 GestureState stateToUnstage(GestureState::STARTED);
845 // Attach actor to detector
847 UnstageActorFunctor functor(data, stateToUnstage, application.GetScene());
848 RotationGestureDetector detector = RotationGestureDetector::New();
849 detector.Attach(actor);
850 detector.DetectedSignal().Connect(&application, functor);
853 TestStartRotation(application, Vector2(2.0f, 20.0f), Vector2(38.0f, 20.0f), Vector2(10.0f, 20.0f), Vector2(30.0f, 20.0f), 100);
854 DALI_TEST_EQUALS(true, data.functorCalled, TEST_LOCATION);
856 TestEndRotation(application, Vector2(10.0f, 20.0f), Vector2(30.0f, 20.0f), Vector2(19.0f, 20.0f), Vector2(21.0f, 20.0f), 1000);
857 DALI_TEST_EQUALS(false, data.functorCalled, TEST_LOCATION);
861 application.SendNotification();
862 application.Render();
864 // Re-add actor to stage
865 application.GetScene().Add(actor);
868 application.SendNotification();
869 application.Render();
871 // Change state to GestureState::CONTINUING to remove
872 stateToUnstage = GestureState::CONTINUING;
875 TestStartRotation(application, Vector2(2.0f, 20.0f), Vector2(38.0f, 20.0f), Vector2(10.0f, 20.0f), Vector2(30.0f, 20.0f), 100);
876 DALI_TEST_EQUALS(true, data.functorCalled, TEST_LOCATION);
878 TestContinueRotation(application, Vector2(10.0f, 20.0f), Vector2(30.0f, 20.0f), Vector2(15.0f, 20.0f), Vector2(25.0f, 20.0f), 500);
879 DALI_TEST_EQUALS(true, data.functorCalled, TEST_LOCATION);
881 TestEndRotation(application, Vector2(10.0f, 20.0f), Vector2(30.0f, 20.0f), Vector2(19.0f, 20.0f), Vector2(21.0f, 20.0f), 1000);
882 DALI_TEST_EQUALS(false, data.functorCalled, TEST_LOCATION);
886 application.SendNotification();
887 application.Render();
889 // Re-add actor to stage
890 application.GetScene().Add(actor);
893 application.SendNotification();
894 application.Render();
896 // Change state to GestureState::CONTINUING to remove
897 stateToUnstage = GestureState::FINISHED;
900 TestStartRotation(application, Vector2(2.0f, 20.0f), Vector2(38.0f, 20.0f), Vector2(10.0f, 20.0f), Vector2(30.0f, 20.0f), 100);
901 DALI_TEST_EQUALS(true, data.functorCalled, TEST_LOCATION);
903 TestContinueRotation(application, Vector2(10.0f, 20.0f), Vector2(30.0f, 20.0f), Vector2(15.0f, 20.0f), Vector2(25.0f, 20.0f), 500);
904 DALI_TEST_EQUALS(true, data.functorCalled, TEST_LOCATION);
906 TestEndRotation(application, Vector2(10.0f, 20.0f), Vector2(30.0f, 20.0f), Vector2(19.0f, 20.0f), Vector2(21.0f, 20.0f), 1000);
907 DALI_TEST_EQUALS(true, data.functorCalled, TEST_LOCATION);
908 tet_result(TET_PASS); // If we get here then we have handled actor stage removal gracefully.
912 int UtcDaliRotationGestureActorStagedAndDestroyed(void)
914 TestApplication application;
916 Actor actor = Actor::New();
917 actor.SetProperty(Actor::Property::SIZE, Vector2(100.0f, 100.0f));
918 actor.SetProperty(Actor::Property::ANCHOR_POINT, AnchorPoint::TOP_LEFT);
919 application.GetScene().Add(actor);
921 // Create and add a second actor so that GestureDetector destruction does not come into play.
922 Actor dummyActor(Actor::New());
923 dummyActor.SetProperty(Actor::Property::SIZE, Vector2(100.0f, 100.0f));
924 dummyActor.SetProperty(Actor::Property::POSITION, Vector2(100.0f, 100.0f));
925 dummyActor.SetProperty(Actor::Property::ANCHOR_POINT, AnchorPoint::TOP_LEFT);
926 application.GetScene().Add(dummyActor);
929 application.SendNotification();
930 application.Render();
932 // State to remove actor in.
933 GestureState stateToUnstage(GestureState::STARTED);
935 // Attach actor to detector
937 UnstageActorFunctor functor(data, stateToUnstage, application.GetScene());
938 RotationGestureDetector detector = RotationGestureDetector::New();
939 detector.Attach(actor);
940 detector.Attach(dummyActor);
941 detector.DetectedSignal().Connect(&application, functor);
943 // Here we are testing a STARTED actor which is removed in the STARTED callback, but then added back
944 // before we get a continuing state. As we were removed from the stage, even if we're at the same
945 // position, we should still not be signalled.
948 TestStartRotation(application, Vector2(2.0f, 20.0f), Vector2(38.0f, 20.0f), Vector2(10.0f, 20.0f), Vector2(30.0f, 20.0f), 100);
949 DALI_TEST_EQUALS(true, data.functorCalled, TEST_LOCATION);
953 application.SendNotification();
954 application.Render();
956 // Re add to the stage, we should not be signalled
957 application.GetScene().Add(actor);
960 application.SendNotification();
961 application.Render();
963 // Continue signal emission
964 TestContinueRotation(application, Vector2(10.0f, 20.0f), Vector2(30.0f, 20.0f), Vector2(15.0f, 20.0f), Vector2(25.0f, 20.0f), 500);
965 DALI_TEST_EQUALS(false, data.functorCalled, TEST_LOCATION);
967 TestEndRotation(application, Vector2(10.0f, 20.0f), Vector2(30.0f, 20.0f), Vector2(19.0f, 20.0f), Vector2(21.0f, 20.0f), 1000);
968 DALI_TEST_EQUALS(false, data.functorCalled, TEST_LOCATION);
971 // Here we delete an actor in started, we should not receive any subsequent signalling.
974 TestStartRotation(application, Vector2(2.0f, 20.0f), Vector2(38.0f, 20.0f), Vector2(10.0f, 20.0f), Vector2(30.0f, 20.0f), 1500);
975 DALI_TEST_EQUALS(true, data.functorCalled, TEST_LOCATION);
979 application.SendNotification();
980 application.Render();
982 // Delete actor as well
986 application.SendNotification();
987 application.Render();
989 // Continue signal emission
990 TestContinueRotation(application, Vector2(10.0f, 20.0f), Vector2(30.0f, 20.0f), Vector2(15.0f, 20.0f), Vector2(25.0f, 20.0f), 2000);
991 DALI_TEST_EQUALS(false, data.functorCalled, TEST_LOCATION);
993 TestEndRotation(application, Vector2(10.0f, 20.0f), Vector2(30.0f, 20.0f), Vector2(19.0f, 20.0f), Vector2(21.0f, 20.0f), 3000);
994 DALI_TEST_EQUALS(false, data.functorCalled, TEST_LOCATION);
998 int UtcDaliRotationGestureLayerConsumesTouch(void)
1000 TestApplication application;
1002 Actor actor = Actor::New();
1003 actor.SetProperty(Actor::Property::SIZE, Vector2(100.0f, 100.0f));
1004 actor.SetProperty(Actor::Property::ANCHOR_POINT, AnchorPoint::TOP_LEFT);
1005 application.GetScene().Add(actor);
1009 GestureReceivedFunctor functor(data);
1010 RotationGestureDetector detector = RotationGestureDetector::New();
1011 detector.Attach(actor);
1012 detector.DetectedSignal().Connect(&application, functor);
1014 // Add a layer to overlap the actor
1015 Layer layer = Layer::New();
1016 layer.SetProperty(Actor::Property::SIZE, Vector2(100.0f, 100.0f));
1017 layer.SetProperty(Actor::Property::ANCHOR_POINT, AnchorPoint::TOP_LEFT);
1018 application.GetScene().Add(layer);
1021 // Render and notify
1022 application.SendNotification();
1023 application.Render();
1025 // Emit signals, should receive
1026 TestStartRotation(application, Vector2(2.0f, 20.0f), Vector2(38.0f, 20.0f), Vector2(10.0f, 20.0f), Vector2(30.0f, 20.0f), 100);
1027 TestEndRotation(application, Vector2(10.0f, 20.0f), Vector2(30.0f, 20.0f), Vector2(19.0f, 20.0f), Vector2(21.0f, 20.0f), 1000);
1028 DALI_TEST_EQUALS(true, data.functorCalled, TEST_LOCATION);
1031 // Set layer to consume all touch
1032 layer.SetProperty(Layer::Property::CONSUMES_TOUCH, true);
1034 // Render and notify
1035 application.SendNotification();
1036 application.Render();
1038 // Emit the same signals again, should not receive
1039 TestStartRotation(application, Vector2(2.0f, 20.0f), Vector2(38.0f, 20.0f), Vector2(10.0f, 20.0f), Vector2(30.0f, 20.0f), 1500);
1040 TestEndRotation(application, Vector2(10.0f, 20.0f), Vector2(30.0f, 20.0f), Vector2(19.0f, 20.0f), Vector2(21.0f, 20.0f), 2000);
1041 DALI_TEST_EQUALS(false, data.functorCalled, TEST_LOCATION);