2 // Copyright (c) 2014 Samsung Electronics Co., Ltd.
4 // Licensed under the Flora License, Version 1.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://floralicense.org/license/
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.
20 #include <dali/dali.h>
21 #include <dali/integration-api/events/touch-event-integ.h>
22 #include <dali/integration-api/events/pinch-gesture-event.h>
23 #include <dali/integration-api/system-overlay.h>
24 #include <dali-test-suite-utils.h>
28 void utc_dali_pinch_gesture_detector_startup(void)
30 test_return_value = TET_UNDEF;
33 void utc_dali_pinch_gesture_detector_cleanup(void)
35 test_return_value = TET_PASS;
38 ///////////////////////////////////////////////////////////////////////////////
42 // Stores data that is populated in the callback and will be read by the TET cases
46 : functorCalled(false),
47 voidFunctorCalled(false),
48 receivedGesture(Gesture::Started)
53 functorCalled = false;
54 voidFunctorCalled = false;
56 receivedGesture.state = Gesture::Started;
57 receivedGesture.scale = 0.0f;
58 receivedGesture.speed = 0.0f;
59 receivedGesture.screenCenterPoint = Vector2(0.0f, 0.0f);
60 receivedGesture.localCenterPoint = Vector2(0.0f, 0.0f);
66 bool voidFunctorCalled;
67 PinchGesture receivedGesture;
71 // Functor that sets the data when called
72 struct GestureReceivedFunctor
74 GestureReceivedFunctor(SignalData& data) : signalData(data) { }
76 void operator()(Actor actor, PinchGesture pinch)
78 signalData.functorCalled = true;
79 signalData.receivedGesture = pinch;
80 signalData.pinchedActor = 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, Gesture::State& stateToUnstage )
95 : GestureReceivedFunctor( data ),
96 stateToUnstage( stateToUnstage )
100 void operator()( Actor actor, PinchGesture pinch )
102 GestureReceivedFunctor::operator()( actor, pinch );
104 if ( pinch.state == stateToUnstage )
106 Stage::GetCurrent().Remove( actor );
110 Gesture::State& stateToUnstage;
113 // Functor for receiving a touch event
114 struct TouchEventFunctor
116 bool operator()(Actor actor, const TouchEvent& touch)
122 // Generate a PinchGestureEvent to send to Core
123 Integration::PinchGestureEvent GeneratePinch(
124 Gesture::State state,
129 Integration::PinchGestureEvent pinch(state);
133 pinch.centerPoint = centerpoint;
140 ///////////////////////////////////////////////////////////////////////////////
142 int UtcDaliPinchGestureDetectorConstructor(void)
144 TestApplication application;
146 PinchGestureDetector detector;
147 DALI_TEST_CHECK(!detector);
151 int UtcDaliPinchGestureDetectorNew(void)
153 TestApplication application;
155 PinchGestureDetector detector = PinchGestureDetector::New();
157 DALI_TEST_CHECK(detector);
159 // Attach an actor and emit a touch event on the actor to ensure complete line coverage
160 Actor actor = Actor::New();
161 actor.SetSize(100.0f, 100.0f);
162 actor.SetAnchorPoint(AnchorPoint::TOP_LEFT);
163 Stage::GetCurrent().Add(actor);
166 application.SendNotification();
167 application.Render();
169 detector.Attach(actor);
171 Integration::TouchEvent touchEvent(1);
172 TouchPoint point(1, TouchPoint::Down, 20.0f, 20.0f);
173 touchEvent.AddPoint(point);
174 application.ProcessEvent(touchEvent);
176 TouchPoint point2(1, TouchPoint::Down, 20.0f, 20.0f, 20.0f, 20.0f);
177 touchEvent.AddPoint(point2);
178 application.ProcessEvent(touchEvent);
182 int UtcDaliPinchGestureDetectorDownCast(void)
184 TestApplication application;
185 tet_infoline("Testing Dali::PinchGestureDetector::DownCast()");
187 PinchGestureDetector detector = PinchGestureDetector::New();
189 BaseHandle object(detector);
191 PinchGestureDetector detector2 = PinchGestureDetector::DownCast(object);
192 DALI_TEST_CHECK(detector2);
194 PinchGestureDetector detector3 = DownCast< PinchGestureDetector >(object);
195 DALI_TEST_CHECK(detector3);
197 BaseHandle unInitializedObject;
198 PinchGestureDetector detector4 = PinchGestureDetector::DownCast(unInitializedObject);
199 DALI_TEST_CHECK(!detector4);
201 PinchGestureDetector detector5 = DownCast< PinchGestureDetector >(unInitializedObject);
202 DALI_TEST_CHECK(!detector5);
204 GestureDetector detector6 = PinchGestureDetector::New();
205 PinchGestureDetector detector7 = PinchGestureDetector::DownCast(detector6);
206 DALI_TEST_CHECK(detector7);
210 // Negative test case for a method
211 int UtcDaliPinchGestureSignalReceptionNegative(void)
213 TestApplication application;
215 Actor actor = Actor::New();
216 actor.SetSize(100.0f, 100.0f);
217 actor.SetAnchorPoint(AnchorPoint::TOP_LEFT);
218 Stage::GetCurrent().Add(actor);
221 application.SendNotification();
222 application.Render();
225 GestureReceivedFunctor functor(data);
227 PinchGestureDetector detector = PinchGestureDetector::New();
228 detector.Attach(actor);
229 detector.DetectedSignal().Connect(&application, functor);
231 // Do a pinch outside actor's area
232 application.ProcessEvent(GeneratePinch(Gesture::Started, 10.0f, 45.0f, Vector2(112.0f, 112.0f)));
233 DALI_TEST_EQUALS(false, data.functorCalled, TEST_LOCATION);
235 // Continue pinch into actor's area - we should still not receive the signal
237 application.ProcessEvent(GeneratePinch(Gesture::Continuing, 4.5f, 95.0f, Vector2(20.0f, 20.0f)));
238 DALI_TEST_EQUALS(false, data.functorCalled, TEST_LOCATION);
240 // Stop pinching - we should still not receive the signal
242 application.ProcessEvent(GeneratePinch(Gesture::Finished, 10.0f, 50.0f, Vector2(12.0f, 12.0f)));
243 DALI_TEST_EQUALS(false, data.functorCalled, TEST_LOCATION);
247 int UtcDaliPinchGestureSignalReceptionDownMotionLeave(void)
249 TestApplication application;
251 Actor actor = Actor::New();
252 actor.SetSize(100.0f, 100.0f);
253 actor.SetAnchorPoint(AnchorPoint::TOP_LEFT);
254 Stage::GetCurrent().Add(actor);
257 application.SendNotification();
258 application.Render();
261 GestureReceivedFunctor functor(data);
263 PinchGestureDetector detector = PinchGestureDetector::New();
264 detector.Attach(actor);
265 detector.DetectedSignal().Connect(&application, functor);
267 // Start pan within the actor's area
268 application.ProcessEvent(GeneratePinch(Gesture::Started, 10.0f, 50.0f, Vector2(20.0f, 20.0f)));
269 DALI_TEST_EQUALS(true, data.functorCalled, TEST_LOCATION);
270 DALI_TEST_EQUALS(Gesture::Started, data.receivedGesture.state, TEST_LOCATION);
271 DALI_TEST_EQUALS(10.0f, data.receivedGesture.scale, 0.01f, TEST_LOCATION);
272 DALI_TEST_EQUALS(50.0f, data.receivedGesture.speed, 0.01f, TEST_LOCATION);
273 DALI_TEST_EQUALS(Vector2(20.0f, 20.0f), data.receivedGesture.screenCenterPoint, 0.01f, TEST_LOCATION);
275 // Continue the pan within the actor's area - we should still receive the signal
277 application.ProcessEvent(GeneratePinch(Gesture::Continuing, 5.0f, 90.0f, Vector2(21.0f, 20.0f)));
278 DALI_TEST_EQUALS(true, data.functorCalled, TEST_LOCATION);
279 DALI_TEST_EQUALS(Gesture::Continuing, data.receivedGesture.state, TEST_LOCATION);
280 DALI_TEST_EQUALS(5.0f, data.receivedGesture.scale, 0.01f, TEST_LOCATION);
281 DALI_TEST_EQUALS(90.0f, data.receivedGesture.speed, 0.01f, TEST_LOCATION);
282 DALI_TEST_EQUALS(Vector2(21.0f, 20.0f), data.receivedGesture.screenCenterPoint, 0.01f, TEST_LOCATION);
284 // Pan Gesture leaves actor's area - we should still receive the signal
286 application.ProcessEvent(GeneratePinch(Gesture::Continuing, 10.0f, 15.5f, Vector2(320.0f, 10.0f)));
287 DALI_TEST_EQUALS(true, data.functorCalled, TEST_LOCATION);
288 DALI_TEST_EQUALS(Gesture::Continuing, data.receivedGesture.state, TEST_LOCATION);
289 DALI_TEST_EQUALS(10.0f, data.receivedGesture.scale, 0.01f, TEST_LOCATION);
290 DALI_TEST_EQUALS(15.5f, data.receivedGesture.speed, 0.01f, TEST_LOCATION);
291 DALI_TEST_EQUALS(Vector2(320.0f, 10.0f), data.receivedGesture.screenCenterPoint, 0.01f, TEST_LOCATION);
293 // Gesture ends - we would receive a finished state
295 application.ProcessEvent(GeneratePinch(Gesture::Finished, 15.2f, 12.1f, Vector2(310.0f, 10.0f)));
296 DALI_TEST_EQUALS(true, data.functorCalled, TEST_LOCATION);
297 DALI_TEST_EQUALS(Gesture::Finished, data.receivedGesture.state, TEST_LOCATION);
298 DALI_TEST_EQUALS(15.2f, data.receivedGesture.scale, 0.01f, TEST_LOCATION);
299 DALI_TEST_EQUALS(12.1f, data.receivedGesture.speed, 0.01f, TEST_LOCATION);
300 DALI_TEST_EQUALS(Vector2(310.0f, 10.0f), data.receivedGesture.screenCenterPoint, 0.01f, TEST_LOCATION);
304 int UtcDaliPinchGestureSignalReceptionDownMotionUp(void)
306 TestApplication application;
308 Actor actor = Actor::New();
309 actor.SetSize(100.0f, 100.0f);
310 actor.SetAnchorPoint(AnchorPoint::TOP_LEFT);
311 Stage::GetCurrent().Add(actor);
314 application.SendNotification();
315 application.Render();
318 GestureReceivedFunctor functor(data);
320 PinchGestureDetector detector = PinchGestureDetector::New();
321 detector.Attach(actor);
322 detector.DetectedSignal().Connect(&application, functor);
324 // Start pinch within the actor's area
325 application.ProcessEvent(GeneratePinch(Gesture::Started, 10.0f, 50.0f, Vector2(20.0f, 20.0f)));
326 DALI_TEST_EQUALS(true, data.functorCalled, TEST_LOCATION);
327 DALI_TEST_EQUALS(Gesture::Started, data.receivedGesture.state, TEST_LOCATION);
328 DALI_TEST_EQUALS(10.0f, data.receivedGesture.scale, 0.01f, TEST_LOCATION);
329 DALI_TEST_EQUALS(50.0f, data.receivedGesture.speed, 0.01f, TEST_LOCATION);
330 DALI_TEST_EQUALS(Vector2(20.0f, 20.0f), data.receivedGesture.screenCenterPoint, 0.01f, TEST_LOCATION);
332 // Continue the pinch within the actor's area - we should still receive the signal
334 application.ProcessEvent(GeneratePinch(Gesture::Continuing, 5.0f, 25.0f, Vector2(20.0f, 20.0f)));
335 DALI_TEST_EQUALS(true, data.functorCalled, TEST_LOCATION);
336 DALI_TEST_EQUALS(Gesture::Continuing, data.receivedGesture.state, TEST_LOCATION);
337 DALI_TEST_EQUALS(5.0f, data.receivedGesture.scale, 0.01f, TEST_LOCATION);
338 DALI_TEST_EQUALS(25.0f, data.receivedGesture.speed, 0.01f, TEST_LOCATION);
339 DALI_TEST_EQUALS(Vector2(20.0f, 20.0f), data.receivedGesture.screenCenterPoint, 0.01f, TEST_LOCATION);
341 // Gesture ends within actor's area - we would receive a finished state
343 application.ProcessEvent(GeneratePinch(Gesture::Finished, 5.0f, 25.0f, Vector2(20.0f, 20.0f)));
344 DALI_TEST_EQUALS(true, data.functorCalled, TEST_LOCATION);
345 DALI_TEST_EQUALS(Gesture::Finished, data.receivedGesture.state, TEST_LOCATION);
346 DALI_TEST_EQUALS(5.0f, data.receivedGesture.scale, 0.01f, TEST_LOCATION);
347 DALI_TEST_EQUALS(25.0f, data.receivedGesture.speed, 0.01f, TEST_LOCATION);
348 DALI_TEST_EQUALS(Vector2(20.0f, 20.0f), data.receivedGesture.screenCenterPoint, 0.01f, TEST_LOCATION);
352 int UtcDaliPinchGestureSignalReceptionCancelled(void)
354 TestApplication application;
356 Actor actor = Actor::New();
357 actor.SetSize(100.0f, 100.0f);
358 actor.SetAnchorPoint(AnchorPoint::TOP_LEFT);
359 Stage::GetCurrent().Add(actor);
362 application.SendNotification();
363 application.Render();
366 GestureReceivedFunctor functor(data);
368 PinchGestureDetector detector = PinchGestureDetector::New();
369 detector.Attach(actor);
370 detector.DetectedSignal().Connect(&application, functor);
372 // Start pinch within the actor's area
373 application.ProcessEvent(GeneratePinch(Gesture::Started, 10.0f, 50.0f, Vector2(20.0f, 20.0f)));
374 DALI_TEST_EQUALS(true, data.functorCalled, TEST_LOCATION);
375 DALI_TEST_EQUALS(Gesture::Started, data.receivedGesture.state, TEST_LOCATION);
378 // Continue the pinch within the actor's area - we should still receive the signal
380 application.ProcessEvent(GeneratePinch(Gesture::Continuing, 5.0f, 25.0f, Vector2(20.0f, 20.0f)));
381 DALI_TEST_EQUALS(true, data.functorCalled, TEST_LOCATION);
382 DALI_TEST_EQUALS(Gesture::Continuing, data.receivedGesture.state, TEST_LOCATION);
384 // The gesture is cancelled
386 application.ProcessEvent(GeneratePinch(Gesture::Cancelled, 5.0f, 25.0f, Vector2(20.0f, 20.0f)));
387 DALI_TEST_EQUALS(true, data.functorCalled, TEST_LOCATION);
388 DALI_TEST_EQUALS(Gesture::Cancelled, data.receivedGesture.state, TEST_LOCATION);
392 int UtcDaliPinchGestureSignalReceptionDetach(void)
394 TestApplication application;
396 Actor actor = Actor::New();
397 actor.SetSize(100.0f, 100.0f);
398 actor.SetAnchorPoint(AnchorPoint::TOP_LEFT);
399 Stage::GetCurrent().Add(actor);
402 application.SendNotification();
403 application.Render();
406 GestureReceivedFunctor functor(data);
408 PinchGestureDetector detector = PinchGestureDetector::New();
409 detector.Attach(actor);
410 detector.DetectedSignal().Connect(&application, functor);
412 // Start pinch within the actor's area
413 application.ProcessEvent(GeneratePinch(Gesture::Started, 10.0f, 50.0f, Vector2(20.0f, 20.0f)));
414 DALI_TEST_EQUALS(true, data.functorCalled, TEST_LOCATION);
415 DALI_TEST_EQUALS(Gesture::Started, data.receivedGesture.state, TEST_LOCATION);
418 // Continue the pinch within the actor's area - we should still receive the signal
420 application.ProcessEvent(GeneratePinch(Gesture::Continuing, 5.0f, 25.0f, Vector2(20.0f, 20.0f)));
421 DALI_TEST_EQUALS(true, data.functorCalled, TEST_LOCATION);
422 DALI_TEST_EQUALS(Gesture::Continuing, data.receivedGesture.state, TEST_LOCATION);
424 // Gesture ends within actor's area
426 application.ProcessEvent(GeneratePinch(Gesture::Finished, 5.0f, 25.0f, Vector2(20.0f, 20.0f)));
427 DALI_TEST_EQUALS(true, data.functorCalled, TEST_LOCATION);
428 DALI_TEST_EQUALS(Gesture::Finished, data.receivedGesture.state, TEST_LOCATION);
431 detector.DetachAll();
433 // Ensure we are no longer signalled
435 application.ProcessEvent(GeneratePinch(Gesture::Started, 10.0f, 50.0f, Vector2(20.0f, 20.0f)));
436 application.ProcessEvent(GeneratePinch(Gesture::Continuing, 5.0f, 25.0f, Vector2(20.0f, 20.0f)));
437 application.ProcessEvent(GeneratePinch(Gesture::Finished, 5.0f, 25.0f, Vector2(20.0f, 20.0f)));
438 DALI_TEST_EQUALS(false, data.functorCalled, TEST_LOCATION);
442 int UtcDaliPinchGestureSignalReceptionDetachWhilePinching(void)
444 TestApplication application;
446 Actor actor = Actor::New();
447 actor.SetSize(100.0f, 100.0f);
448 actor.SetAnchorPoint(AnchorPoint::TOP_LEFT);
449 Stage::GetCurrent().Add(actor);
452 application.SendNotification();
453 application.Render();
456 GestureReceivedFunctor functor(data);
458 PinchGestureDetector detector = PinchGestureDetector::New();
459 detector.Attach(actor);
460 detector.DetectedSignal().Connect(&application, functor);
462 // Start pinch within the actor's area
463 application.ProcessEvent(GeneratePinch(Gesture::Started, 10.0f, 50.0f, Vector2(10.0f, 10.0f)));
464 DALI_TEST_EQUALS(true, data.functorCalled, TEST_LOCATION);
465 DALI_TEST_EQUALS(Gesture::Started, data.receivedGesture.state, TEST_LOCATION);
467 // Continue the pinch within the actor's area - we should still receive the signal
469 application.ProcessEvent(GeneratePinch(Gesture::Continuing, 5.0f, 25.0f, Vector2(20.0f, 20.0f)));
470 DALI_TEST_EQUALS(true, data.functorCalled, TEST_LOCATION);
471 DALI_TEST_EQUALS(Gesture::Continuing, data.receivedGesture.state, TEST_LOCATION);
473 // Detach actor during the pinch, we should not receive the next event
474 detector.DetachAll();
476 // Gesture ends within actor's area
478 application.ProcessEvent(GeneratePinch(Gesture::Finished, 5.0f, 25.0f, Vector2(20.0f, 20.0f)));
479 DALI_TEST_EQUALS(false, data.functorCalled, TEST_LOCATION);
483 int UtcDaliPinchGestureSignalReceptionActorDestroyedWhilePinching(void)
485 TestApplication application;
488 GestureReceivedFunctor functor(data);
490 PinchGestureDetector detector = PinchGestureDetector::New();
491 detector.DetectedSignal().Connect(&application, functor);
493 // Attach a temporary actor to stop detector being removed from PinchGestureProcessor when main actor
495 Actor tempActor = Actor::New();
496 tempActor.SetSize(100.0f, 100.0f);
497 tempActor.SetAnchorPoint(AnchorPoint::BOTTOM_RIGHT);
498 Stage::GetCurrent().Add(tempActor);
499 detector.Attach(tempActor);
501 // Actor lifetime is scoped
503 Actor actor = Actor::New();
504 actor.SetSize(100.0f, 100.0f);
505 actor.SetAnchorPoint(AnchorPoint::TOP_LEFT);
506 Stage::GetCurrent().Add(actor);
509 application.SendNotification();
510 application.Render();
512 detector.Attach(actor);
514 // Start pinch within the actor's area
515 application.ProcessEvent(GeneratePinch(Gesture::Started, 10.0f, 50.0f, Vector2(10.0f, 10.0f)));
516 DALI_TEST_EQUALS(true, data.functorCalled, TEST_LOCATION);
517 DALI_TEST_EQUALS(Gesture::Started, data.receivedGesture.state, TEST_LOCATION);
519 // Continue the pinch within the actor's area - we should still receive the signal
521 application.ProcessEvent(GeneratePinch(Gesture::Continuing, 5.0f, 25.0f, Vector2(20.0f, 20.0f)));
522 DALI_TEST_EQUALS(true, data.functorCalled, TEST_LOCATION);
523 DALI_TEST_EQUALS(Gesture::Continuing, data.receivedGesture.state, TEST_LOCATION);
525 // Remove the actor from stage and reset the data
526 Stage::GetCurrent().Remove(actor);
529 application.SendNotification();
530 application.Render();
533 // Actor should now have been destroyed
535 // Gesture ends within the area where the actor used to be
537 application.ProcessEvent(GeneratePinch(Gesture::Finished, 5.0f, 25.0f, Vector2(20.0f, 20.0f)));
538 DALI_TEST_EQUALS(false, data.functorCalled, TEST_LOCATION);
542 int UtcDaliPinchGestureSignalReceptionRotatedActor(void)
544 TestApplication application;
546 Actor actor = Actor::New();
547 actor.SetSize(100.0f, 100.0f);
548 actor.SetRotation(Dali::Degree(90.0f), Vector3::ZAXIS);
549 Stage::GetCurrent().Add(actor);
551 // Render and notify a couple of times
552 application.SendNotification();
553 application.Render();
556 GestureReceivedFunctor functor(data);
558 PinchGestureDetector detector = PinchGestureDetector::New();
559 detector.Attach(actor);
560 detector.DetectedSignal().Connect(&application, functor);
562 // Do an entire pinch, only check finished value
563 application.ProcessEvent(GeneratePinch(Gesture::Started, 10.0f, 50.0f, Vector2(10.0f, 10.0f)));
565 application.ProcessEvent(GeneratePinch(Gesture::Finished, 10.0f, 50.0f, Vector2(10.0f, 10.0f)));
566 DALI_TEST_EQUALS(true, data.functorCalled, TEST_LOCATION);
567 DALI_TEST_EQUALS(10.0f, data.receivedGesture.scale, 0.01f, TEST_LOCATION);
568 DALI_TEST_EQUALS(50.0f, data.receivedGesture.speed, 0.01f, TEST_LOCATION);
569 DALI_TEST_EQUALS(Vector2(10.0f, 10.0f), data.receivedGesture.screenCenterPoint, 0.01f, TEST_LOCATION);
571 // Rotate actor again and render and notify
572 actor.SetRotation(Dali::Degree(180.0f), Vector3::ZAXIS);
573 application.SendNotification();
574 application.Render();
576 // Do an entire pinch, only check finished value
577 application.ProcessEvent(GeneratePinch(Gesture::Started, 10.0f, 50.0f, Vector2(10.0f, 10.0f)));
579 application.ProcessEvent(GeneratePinch(Gesture::Finished, 10.0f, 50.0f, Vector2(10.0f, 10.0f)));
580 DALI_TEST_EQUALS(true, data.functorCalled, TEST_LOCATION);
581 DALI_TEST_EQUALS(10.0f, data.receivedGesture.scale, 0.01f, TEST_LOCATION);
582 DALI_TEST_EQUALS(50.0f, data.receivedGesture.speed, 0.01f, TEST_LOCATION);
583 DALI_TEST_EQUALS(Vector2(10.0f, 10.0f), data.receivedGesture.screenCenterPoint, 0.01f, TEST_LOCATION);
585 // Rotate actor again and render and notify
586 actor.SetRotation(Dali::Degree(270.0f), Vector3::ZAXIS);
587 application.SendNotification();
588 application.Render();
590 // Do an entire pinch, only check finished value
591 application.ProcessEvent(GeneratePinch(Gesture::Started, 10.0f, 50.0f, Vector2(10.0f, 10.0f)));
593 application.ProcessEvent(GeneratePinch(Gesture::Finished, 10.0f, 50.0f, Vector2(10.0f, 10.0f)));
594 DALI_TEST_EQUALS(true, data.functorCalled, TEST_LOCATION);
595 DALI_TEST_EQUALS(10.0f, data.receivedGesture.scale, 0.01f, TEST_LOCATION);
596 DALI_TEST_EQUALS(50.0f, data.receivedGesture.speed, 0.01f, TEST_LOCATION);
597 DALI_TEST_EQUALS(Vector2(10.0f, 10.0f), data.receivedGesture.screenCenterPoint, 0.01f, TEST_LOCATION);
601 int UtcDaliPinchGestureSignalReceptionChildHit(void)
603 TestApplication application;
605 Actor parent = Actor::New();
606 parent.SetSize(100.0f, 100.0f);
607 parent.SetAnchorPoint(AnchorPoint::TOP_LEFT);
608 Stage::GetCurrent().Add(parent);
610 // Set child to completely cover parent.
611 // Change rotation of child to be different from parent so that we can check if our local coordinate
612 // conversion of the parent actor is correct.
613 Actor child = Actor::New();
614 child.SetSize(100.0f, 100.0f);
615 child.SetAnchorPoint(AnchorPoint::CENTER);
616 child.SetParentOrigin(ParentOrigin::CENTER);
617 child.SetRotation(Dali::Degree(90.0f), Vector3::ZAXIS);
620 TouchEventFunctor touchFunctor;
621 child.TouchedSignal().Connect(&application, touchFunctor);
624 application.SendNotification();
625 application.Render();
628 GestureReceivedFunctor functor(data);
630 PinchGestureDetector detector = PinchGestureDetector::New();
631 detector.Attach(parent);
632 detector.DetectedSignal().Connect(&application, functor);
634 // Do an entire pan, only check finished value - hits child area but parent should still receive it
635 application.ProcessEvent(GeneratePinch(Gesture::Started, 10.0f, 50.0f, Vector2(10.0f, 10.0f)));
637 application.ProcessEvent(GeneratePinch(Gesture::Finished, 5.0f, 50.0f, Vector2(10.0f, 10.0f)));
638 DALI_TEST_EQUALS(true, data.functorCalled, TEST_LOCATION);
639 DALI_TEST_EQUALS(true, parent == data.pinchedActor, TEST_LOCATION);
640 DALI_TEST_EQUALS(5.0f, data.receivedGesture.scale, 0.01f, TEST_LOCATION);
641 DALI_TEST_EQUALS(50.0f, data.receivedGesture.speed, 0.01f, TEST_LOCATION);
642 DALI_TEST_EQUALS(Vector2(10.0f, 10.0f), data.receivedGesture.screenCenterPoint, 0.01f, TEST_LOCATION);
644 // Attach child and generate same touch points to yield same results
645 // (Also proves that you can detach and then re-attach another actor)
646 detector.Attach(child);
647 detector.Detach(parent);
649 // Do an entire pan, only check finished value
650 application.ProcessEvent(GeneratePinch(Gesture::Started, 10.0f, 50.0f, Vector2(10.0f, 10.0f)));
652 application.ProcessEvent(GeneratePinch(Gesture::Finished, 5.0f, 50.0f, Vector2(10.0f, 10.0f)));
653 DALI_TEST_EQUALS(true, data.functorCalled, TEST_LOCATION);
654 DALI_TEST_EQUALS(true, child == data.pinchedActor, TEST_LOCATION);
655 DALI_TEST_EQUALS(5.0f, data.receivedGesture.scale, 0.01f, TEST_LOCATION);
656 DALI_TEST_EQUALS(50.0f, data.receivedGesture.speed, 0.01f, TEST_LOCATION);
657 DALI_TEST_EQUALS(Vector2(10.0f, 10.0f), data.receivedGesture.screenCenterPoint, 0.01f, TEST_LOCATION);
661 int UtcDaliPinchGestureSignalReceptionAttachDetachMany(void)
663 TestApplication application;
665 Actor first = Actor::New();
666 first.SetSize(100.0f, 100.0f);
667 first.SetAnchorPoint(AnchorPoint::TOP_LEFT);
668 Stage::GetCurrent().Add(first);
670 Actor second = Actor::New();
671 second.SetSize(100.0f, 100.0f);
673 second.SetAnchorPoint(AnchorPoint::TOP_LEFT);
674 Stage::GetCurrent().Add(second);
677 application.SendNotification();
678 application.Render();
681 GestureReceivedFunctor functor(data);
683 PinchGestureDetector detector = PinchGestureDetector::New();
684 detector.Attach(first);
685 detector.Attach(second);
686 detector.DetectedSignal().Connect(&application, functor);
688 // Start pinch within second actor's area
689 application.ProcessEvent(GeneratePinch(Gesture::Started, 10.0f, 50.0f, Vector2(120.0f, 10.0f)));
690 DALI_TEST_EQUALS(true, data.functorCalled, TEST_LOCATION);
691 DALI_TEST_EQUALS(true, second == data.pinchedActor, TEST_LOCATION);
693 // Pinch moves into first actor's area - second actor should receive the pinch
695 application.ProcessEvent(GeneratePinch(Gesture::Continuing, 10.0f, 50.0f, Vector2(10.0f, 10.0f)));
696 DALI_TEST_EQUALS(true, data.functorCalled, TEST_LOCATION);
697 DALI_TEST_EQUALS(true, second == data.pinchedActor, TEST_LOCATION);
699 // Detach the second actor during the pinch, we should not receive the next event
700 detector.Detach(second);
702 // Gesture ends within actor's area
704 application.ProcessEvent(GeneratePinch(Gesture::Finished, 10.0f, 50.0f, Vector2(120.0f, 10.0f)));
705 DALI_TEST_EQUALS(false, data.functorCalled, TEST_LOCATION);
709 int UtcDaliPinchGestureSignalReceptionActorBecomesUntouchable(void)
711 TestApplication application;
713 Actor actor = Actor::New();
714 actor.SetSize(100.0f, 100.0f);
715 actor.SetAnchorPoint(AnchorPoint::TOP_LEFT);
716 Stage::GetCurrent().Add(actor);
719 application.SendNotification();
720 application.Render();
723 GestureReceivedFunctor functor(data);
725 PinchGestureDetector detector = PinchGestureDetector::New();
726 detector.Attach(actor);
727 detector.DetectedSignal().Connect(&application, functor);
729 // Start pinch in actor's area
730 application.ProcessEvent(GeneratePinch(Gesture::Started, 10.0f, 50.0f, Vector2(20.0f, 10.0f)));
731 DALI_TEST_EQUALS(true, data.functorCalled, TEST_LOCATION);
733 // Pan continues within actor's area
735 application.ProcessEvent(GeneratePinch(Gesture::Started, 5.0f, 50.0f, Vector2(10.0f, 10.0f)));
736 DALI_TEST_EQUALS(true, data.functorCalled, TEST_LOCATION);
738 // Actor become invisible - actor should not receive the next pinch
739 actor.SetVisible(false);
742 application.SendNotification();
743 application.Render();
745 // Gesture ends within actor's area
747 application.ProcessEvent(GeneratePinch(Gesture::Finished, 5.0f, 50.0f, Vector2(10.0f, 10.0f)));
748 DALI_TEST_EQUALS(false, data.functorCalled, TEST_LOCATION);
752 int UtcDaliPinchGestureSignalReceptionMultipleDetectorsOnActor(void)
754 TestApplication application;
756 Actor actor = Actor::New();
757 actor.SetSize(100.0f, 100.0f);
758 actor.SetAnchorPoint(AnchorPoint::TOP_LEFT);
759 Stage::GetCurrent().Add(actor);
761 Actor actor2 = Actor::New();
762 actor2.SetSize(100.0f, 100.0f);
763 actor2.SetAnchorPoint(AnchorPoint::BOTTOM_RIGHT);
764 Stage::GetCurrent().Add(actor2);
767 application.SendNotification();
768 application.Render();
770 // Attach actor to one detector
771 SignalData firstData;
772 GestureReceivedFunctor firstFunctor(firstData);
773 PinchGestureDetector firstDetector = PinchGestureDetector::New();
774 firstDetector.Attach(actor);
775 firstDetector.DetectedSignal().Connect(&application, firstFunctor);
777 // Attach actor to another detector
778 SignalData secondData;
779 GestureReceivedFunctor secondFunctor(secondData);
780 PinchGestureDetector secondDetector = PinchGestureDetector::New();
781 secondDetector.Attach(actor);
782 secondDetector.DetectedSignal().Connect(&application, secondFunctor);
784 // Add second actor to second detector, when we remove the actor, this will make sure that this
785 // gesture detector is not removed from the GestureDetectorProcessor. In this scenario, the
786 // functor should still not be called (which is what we're also testing).
787 secondDetector.Attach(actor2);
789 // Pinch in actor's area - both detector's functors should be called
790 application.ProcessEvent(GeneratePinch(Gesture::Started, 10.0f, 50.0f, Vector2(20.0f, 10.0f)));
791 DALI_TEST_EQUALS(true, firstData.functorCalled, TEST_LOCATION);
792 DALI_TEST_EQUALS(true, secondData.functorCalled, TEST_LOCATION);
794 // Pinch continues in actor's area - both detector's functors should be called
797 application.ProcessEvent(GeneratePinch(Gesture::Continuing, 10.0f, 50.0f, Vector2(20.0f, 10.0f)));
798 DALI_TEST_EQUALS(true, firstData.functorCalled, TEST_LOCATION);
799 DALI_TEST_EQUALS(true, secondData.functorCalled, TEST_LOCATION);
801 // Detach actor from firstDetector and emit pinch on actor, only secondDetector's functor should be called.
802 firstDetector.Detach(actor);
805 application.ProcessEvent(GeneratePinch(Gesture::Finished, 10.0f, 50.0f, Vector2(20.0f, 10.0f)));
806 DALI_TEST_EQUALS(false, firstData.functorCalled, TEST_LOCATION);
807 DALI_TEST_EQUALS(true, secondData.functorCalled, TEST_LOCATION);
809 // New pinch on actor, only secondDetector has actor attached
812 application.ProcessEvent(GeneratePinch(Gesture::Started, 10.0f, 50.0f, Vector2(20.0f, 10.0f)));
813 DALI_TEST_EQUALS(false, firstData.functorCalled, TEST_LOCATION);
814 DALI_TEST_EQUALS(true, secondData.functorCalled, TEST_LOCATION);
816 // Detach actor from secondDetector
817 secondDetector.Detach(actor);
820 application.ProcessEvent(GeneratePinch(Gesture::Continuing, 10.0f, 50.0f, Vector2(20.0f, 10.0f)));
821 DALI_TEST_EQUALS(false, firstData.functorCalled, TEST_LOCATION);
822 DALI_TEST_EQUALS(false, secondData.functorCalled, TEST_LOCATION);
826 int UtcDaliPinchGestureSignalReceptionMultipleStarted(void)
828 // Should handle two started events gracefully.
830 TestApplication application;
832 Actor actor = Actor::New();
833 actor.SetSize(100.0f, 100.0f);
834 actor.SetAnchorPoint(AnchorPoint::TOP_LEFT);
835 Stage::GetCurrent().Add(actor);
838 GestureReceivedFunctor functor(data);
840 PinchGestureDetector detector = PinchGestureDetector::New();
841 detector.Attach(actor);
842 detector.DetectedSignal().Connect(&application, functor);
845 application.SendNotification();
846 application.Render();
848 // Start pan in actor's area
849 application.ProcessEvent(GeneratePinch(Gesture::Started, 10.0f, 50.0f, Vector2(20.0f, 10.0f)));
850 DALI_TEST_EQUALS(true, data.functorCalled, TEST_LOCATION);
852 // Send another start in actor's area
854 application.ProcessEvent(GeneratePinch(Gesture::Started, 10.0f, 50.0f, Vector2(20.0f, 10.0f)));
855 DALI_TEST_EQUALS(true, data.functorCalled, TEST_LOCATION);
857 // Add a child actor to overlap actor and send another start in actor's area
858 Actor child = Actor::New();
859 child.SetSize(100.0f, 100.0f);
860 child.SetAnchorPoint(AnchorPoint::CENTER);
861 child.SetParentOrigin(ParentOrigin::CENTER);
864 TouchEventFunctor touchFunctor;
865 child.TouchedSignal().Connect(&application, touchFunctor);
868 application.SendNotification();
869 application.Render();
871 // Send another start in actor's area
873 application.ProcessEvent(GeneratePinch(Gesture::Started, 10.0f, 50.0f, Vector2(20.0f, 10.0f)));
874 DALI_TEST_EQUALS(true, data.functorCalled, TEST_LOCATION);
876 // Send another start in actor's area
878 application.ProcessEvent(GeneratePinch(Gesture::Started, 10.0f, 50.0f, Vector2(20.0f, 10.0f)));
879 DALI_TEST_EQUALS(true, data.functorCalled, TEST_LOCATION);
883 int UtcDaliPinchGestureSignalReceptionEnsureCorrectSignalling(void)
885 TestApplication application;
887 Actor actor1 = Actor::New();
888 actor1.SetSize(100.0f, 100.0f);
889 actor1.SetAnchorPoint(AnchorPoint::TOP_LEFT);
890 Stage::GetCurrent().Add(actor1);
892 GestureReceivedFunctor functor1(data1);
893 PinchGestureDetector detector1 = PinchGestureDetector::New();
894 detector1.Attach(actor1);
895 detector1.DetectedSignal().Connect(&application, functor1);
897 Actor actor2 = Actor::New();
898 actor2.SetSize(100.0f, 100.0f);
899 actor2.SetAnchorPoint(AnchorPoint::BOTTOM_RIGHT);
900 actor2.SetParentOrigin(ParentOrigin::BOTTOM_RIGHT);
901 Stage::GetCurrent().Add(actor2);
903 GestureReceivedFunctor functor2(data2);
904 PinchGestureDetector detector2 = PinchGestureDetector::New();
905 detector2.Attach(actor2);
906 detector2.DetectedSignal().Connect(&application, functor2);
909 application.SendNotification();
910 application.Render();
912 // Start pan in actor1's area, only data1 should be set
913 application.ProcessEvent(GeneratePinch(Gesture::Started, 10.0f, 50.0f, Vector2(20.0f, 10.0f)));
914 DALI_TEST_EQUALS(true, data1.functorCalled, TEST_LOCATION);
915 DALI_TEST_EQUALS(false, data2.functorCalled, TEST_LOCATION);
919 int UtcDaliPinchGestureEmitIncorrectStateClear(void)
921 TestApplication application;
923 Actor actor = Actor::New();
924 actor.SetSize(100.0f, 100.0f);
925 actor.SetAnchorPoint(AnchorPoint::TOP_LEFT);
926 Stage::GetCurrent().Add(actor);
929 application.SendNotification();
930 application.Render();
932 // Attach actor to detector
934 GestureReceivedFunctor functor( data );
935 PinchGestureDetector detector = PinchGestureDetector::New();
936 detector.Attach(actor);
937 detector.DetectedSignal().Connect( &application, functor );
942 application.ProcessEvent(GeneratePinch(Gesture::Clear, 10.0f, 50.0f, Vector2(20.0f, 10.0f)));
943 tet_result(TET_FAIL);
945 catch ( Dali::DaliException& e )
947 DALI_TEST_ASSERT( e, "false", TEST_LOCATION );
952 int UtcDaliPinchGestureEmitIncorrectStatePossible(void)
954 TestApplication application;
956 Actor actor = Actor::New();
957 actor.SetSize(100.0f, 100.0f);
958 actor.SetAnchorPoint(AnchorPoint::TOP_LEFT);
959 Stage::GetCurrent().Add(actor);
962 application.SendNotification();
963 application.Render();
965 // Attach actor to detector
967 GestureReceivedFunctor functor( data );
968 PinchGestureDetector detector = PinchGestureDetector::New();
969 detector.Attach(actor);
970 detector.DetectedSignal().Connect( &application, functor );
972 // Try a Possible state
975 application.ProcessEvent(GeneratePinch(Gesture::Possible, 10.0f, 50.0f, Vector2(20.0f, 10.0f)));
976 tet_result(TET_FAIL);
978 catch ( Dali::DaliException& e )
980 DALI_TEST_ASSERT( e, "false", TEST_LOCATION );
985 int UtcDaliPinchGestureActorUnstaged(void)
987 TestApplication application;
989 Actor actor = Actor::New();
990 actor.SetSize(100.0f, 100.0f);
991 actor.SetAnchorPoint(AnchorPoint::TOP_LEFT);
992 Stage::GetCurrent().Add(actor);
995 application.SendNotification();
996 application.Render();
998 // State to remove actor in.
999 Gesture::State stateToUnstage( Gesture::Started );
1001 // Attach actor to detector
1003 UnstageActorFunctor functor( data, stateToUnstage );
1004 PinchGestureDetector detector = PinchGestureDetector::New();
1005 detector.Attach(actor);
1006 detector.DetectedSignal().Connect( &application, functor );
1009 application.ProcessEvent(GeneratePinch(Gesture::Started, 10.0f, 50.0f, Vector2(20.0f, 10.0f)));
1010 DALI_TEST_EQUALS(true, data.functorCalled, TEST_LOCATION);
1012 application.ProcessEvent(GeneratePinch(Gesture::Finished, 10.0f, 50.0f, Vector2(20.0f, 10.0f)));
1013 DALI_TEST_EQUALS(false, data.functorCalled, TEST_LOCATION);
1016 // Render and notify
1017 application.SendNotification();
1018 application.Render();
1020 // Re-add actor to stage
1021 Stage::GetCurrent().Add(actor);
1023 // Render and notify
1024 application.SendNotification();
1025 application.Render();
1027 // Change state to Gesture::Continuing to remove
1028 stateToUnstage = Gesture::Continuing;
1031 application.ProcessEvent(GeneratePinch(Gesture::Started, 10.0f, 50.0f, Vector2(20.0f, 10.0f)));
1032 DALI_TEST_EQUALS(true, data.functorCalled, TEST_LOCATION);
1034 application.ProcessEvent(GeneratePinch(Gesture::Continuing, 10.0f, 50.0f, Vector2(20.0f, 10.0f)));
1035 DALI_TEST_EQUALS(true, data.functorCalled, TEST_LOCATION);
1037 application.ProcessEvent(GeneratePinch(Gesture::Finished, 10.0f, 50.0f, Vector2(20.0f, 10.0f)));
1038 DALI_TEST_EQUALS(false, data.functorCalled, TEST_LOCATION);
1041 // Render and notify
1042 application.SendNotification();
1043 application.Render();
1045 // Re-add actor to stage
1046 Stage::GetCurrent().Add(actor);
1048 // Render and notify
1049 application.SendNotification();
1050 application.Render();
1052 // Change state to Gesture::Continuing to remove
1053 stateToUnstage = Gesture::Finished;
1056 application.ProcessEvent(GeneratePinch(Gesture::Started, 10.0f, 50.0f, Vector2(20.0f, 10.0f)));
1057 DALI_TEST_EQUALS(true, data.functorCalled, TEST_LOCATION);
1059 application.ProcessEvent(GeneratePinch(Gesture::Continuing, 10.0f, 50.0f, Vector2(20.0f, 10.0f)));
1060 DALI_TEST_EQUALS(true, data.functorCalled, TEST_LOCATION);
1062 application.ProcessEvent(GeneratePinch(Gesture::Finished, 10.0f, 50.0f, Vector2(20.0f, 10.0f)));
1063 DALI_TEST_EQUALS(true, data.functorCalled, TEST_LOCATION);
1064 tet_result( TET_PASS ); // If we get here then we have handled actor stage removal gracefully.
1068 int UtcDaliPinchGestureActorStagedAndDestroyed(void)
1070 TestApplication application;
1072 Actor actor = Actor::New();
1073 actor.SetSize(100.0f, 100.0f);
1074 actor.SetAnchorPoint(AnchorPoint::TOP_LEFT);
1075 Stage::GetCurrent().Add(actor);
1077 // Create and add a second actor so that GestureDetector destruction does not come into play.
1078 Actor dummyActor( Actor::New() );
1079 dummyActor.SetSize( 100.0f, 100.0f );
1080 dummyActor.SetPosition( 100.0f, 100.0f );
1081 dummyActor.SetAnchorPoint(AnchorPoint::TOP_LEFT);
1082 Stage::GetCurrent().Add(dummyActor);
1084 // Render and notify
1085 application.SendNotification();
1086 application.Render();
1088 // State to remove actor in.
1089 Gesture::State stateToUnstage( Gesture::Started );
1091 // Attach actor to detector
1093 UnstageActorFunctor functor( data, stateToUnstage );
1094 PinchGestureDetector detector = PinchGestureDetector::New();
1095 detector.Attach(actor);
1096 detector.Attach(dummyActor);
1097 detector.DetectedSignal().Connect( &application, functor );
1099 // Here we are testing a Started actor which is removed in the Started callback, but then added back
1100 // before we get a continuing state. As we were removed from the stage, even if we're at the same
1101 // position, we should still not be signalled.
1104 application.ProcessEvent(GeneratePinch(Gesture::Started, 10.0f, 50.0f, Vector2(20.0f, 10.0f)));
1105 DALI_TEST_EQUALS(true, data.functorCalled, TEST_LOCATION);
1108 // Render and notify
1109 application.SendNotification();
1110 application.Render();
1112 // Re add to the stage, we should not be signalled
1113 Stage::GetCurrent().Add(actor);
1115 // Render and notify
1116 application.SendNotification();
1117 application.Render();
1119 // Continue signal emission
1120 application.ProcessEvent(GeneratePinch(Gesture::Continuing, 10.0f, 50.0f, Vector2(20.0f, 10.0f)));
1121 DALI_TEST_EQUALS(false, data.functorCalled, TEST_LOCATION);
1123 application.ProcessEvent(GeneratePinch(Gesture::Finished, 10.0f, 50.0f, Vector2(20.0f, 10.0f)));
1124 DALI_TEST_EQUALS(false, data.functorCalled, TEST_LOCATION);
1127 // Here we delete an actor in started, we should not receive any subsequent signalling.
1130 application.ProcessEvent(GeneratePinch(Gesture::Started, 10.0f, 50.0f, Vector2(20.0f, 10.0f)));
1131 DALI_TEST_EQUALS(true, data.functorCalled, TEST_LOCATION);
1134 // Render and notify
1135 application.SendNotification();
1136 application.Render();
1138 // Delete actor as well
1141 // Render and notify
1142 application.SendNotification();
1143 application.Render();
1145 // Continue signal emission
1146 application.ProcessEvent(GeneratePinch(Gesture::Continuing, 10.0f, 50.0f, Vector2(20.0f, 10.0f)));
1147 DALI_TEST_EQUALS(false, data.functorCalled, TEST_LOCATION);
1149 application.ProcessEvent(GeneratePinch(Gesture::Finished, 10.0f, 50.0f, Vector2(20.0f, 10.0f)));
1150 DALI_TEST_EQUALS(false, data.functorCalled, TEST_LOCATION);
1154 int UtcDaliPinchGestureSystemOverlay(void)
1156 TestApplication application;
1157 Dali::Integration::Core& core = application.GetCore();
1158 Dali::Integration::SystemOverlay& systemOverlay( core.GetSystemOverlay() );
1159 systemOverlay.GetOverlayRenderTasks().CreateTask();
1161 Actor actor = Actor::New();
1162 actor.SetSize(100.0f, 100.0f);
1163 actor.SetAnchorPoint(AnchorPoint::TOP_LEFT);
1164 systemOverlay.Add(actor);
1166 // Render and notify
1167 application.SendNotification();
1168 application.Render();
1171 GestureReceivedFunctor functor(data);
1173 PinchGestureDetector detector = PinchGestureDetector::New();
1174 detector.Attach(actor);
1175 detector.DetectedSignal().Connect(&application, functor);
1177 Vector2 screenCoords( 50.0f, 50.0f );
1178 float scale ( 10.0f );
1179 float speed ( 50.0f );
1181 // Start pan within the actor's area
1182 application.ProcessEvent( GeneratePinch( Gesture::Started, scale, speed, screenCoords ) );
1183 DALI_TEST_EQUALS( false, data.functorCalled, TEST_LOCATION );