2 * Copyright (c) 2019 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.
21 #include <dali/public-api/dali-core.h>
22 #include <dali/integration-api/events/touch-event-integ.h>
23 #include <dali/integration-api/render-task-list-integ.h>
24 #include <dali-test-suite-utils.h>
25 #include <test-touch-utils.h>
29 void utc_dali_pinch_gesture_detector_startup(void)
31 test_return_value = TET_UNDEF;
34 void utc_dali_pinch_gesture_detector_cleanup(void)
36 test_return_value = TET_PASS;
39 ///////////////////////////////////////////////////////////////////////////////
43 // Stores data that is populated in the callback and will be read by the TET cases
47 : functorCalled(false),
48 voidFunctorCalled(false),
49 receivedGesture(Gesture::Started)
54 functorCalled = false;
55 voidFunctorCalled = false;
57 receivedGesture.state = Gesture::Started;
58 receivedGesture.scale = 0.0f;
59 receivedGesture.speed = 0.0f;
60 receivedGesture.screenCenterPoint = Vector2(0.0f, 0.0f);
61 receivedGesture.localCenterPoint = Vector2(0.0f, 0.0f);
67 bool voidFunctorCalled;
68 PinchGesture receivedGesture;
72 // Functor that sets the data when called
73 struct GestureReceivedFunctor
75 GestureReceivedFunctor(SignalData& data) : signalData(data) { }
77 void operator()(Actor actor, const PinchGesture& pinch)
79 signalData.functorCalled = true;
80 signalData.receivedGesture = pinch;
81 signalData.pinchedActor = actor;
86 signalData.voidFunctorCalled = true;
89 SignalData& signalData;
92 // Functor that removes the gestured actor from stage
93 struct UnstageActorFunctor : public GestureReceivedFunctor
95 UnstageActorFunctor( SignalData& data, Gesture::State& stateToUnstage )
96 : GestureReceivedFunctor( data ),
97 stateToUnstage( stateToUnstage )
101 void operator()( Actor actor, const PinchGesture& pinch )
103 GestureReceivedFunctor::operator()( actor, pinch );
105 if ( pinch.state == stateToUnstage )
107 Stage::GetCurrent().Remove( actor );
111 Gesture::State& stateToUnstage;
114 // Functor for receiving a touch event
115 struct TouchEventFunctor
117 bool operator()(Actor actor, const TouchEvent& touch)
125 ///////////////////////////////////////////////////////////////////////////////
127 int UtcDaliPinchGestureDetectorConstructor(void)
129 TestApplication application;
131 PinchGestureDetector detector;
132 DALI_TEST_CHECK(!detector);
136 int UtcDaliPinchGestureDetectorCopyConstructorP(void)
138 TestApplication application;
140 PinchGestureDetector detector = PinchGestureDetector::New();;
142 PinchGestureDetector copy( detector );
143 DALI_TEST_CHECK( detector );
147 int UtcDaliPinchGestureDetectorAssignmentOperatorP(void)
149 TestApplication application;
151 PinchGestureDetector detector = PinchGestureDetector::New();;
153 PinchGestureDetector assign;
155 DALI_TEST_CHECK( detector );
157 DALI_TEST_CHECK( detector == assign );
161 int UtcDaliPinchGestureDetectorNew(void)
163 TestApplication application;
165 PinchGestureDetector detector = PinchGestureDetector::New();
167 DALI_TEST_CHECK(detector);
169 // Attach an actor and emit a touch event on the actor to ensure complete line coverage
170 Actor actor = Actor::New();
171 actor.SetSize(100.0f, 100.0f);
172 actor.SetAnchorPoint(AnchorPoint::TOP_LEFT);
173 Stage::GetCurrent().Add(actor);
176 application.SendNotification();
177 application.Render();
179 detector.Attach(actor);
181 Integration::TouchEvent touchEvent(1);
182 Integration::Point point;
183 point.SetDeviceId( 1 );
184 point.SetState( PointState::DOWN );
185 point.SetScreenPosition( Vector2( 20.0f, 20.0f ) );
186 touchEvent.AddPoint(point);
187 application.ProcessEvent(touchEvent);
189 Integration::Point point2;
190 point.SetDeviceId( 1 );
191 point.SetState( PointState::DOWN );
192 point.SetScreenPosition( Vector2( 20.0f, 20.0f ) );
193 touchEvent.AddPoint(point2);
194 application.ProcessEvent(touchEvent);
198 int UtcDaliPinchGestureDetectorDownCast(void)
200 TestApplication application;
201 tet_infoline("Testing Dali::PinchGestureDetector::DownCast()");
203 PinchGestureDetector detector = PinchGestureDetector::New();
205 BaseHandle object(detector);
207 PinchGestureDetector detector2 = PinchGestureDetector::DownCast(object);
208 DALI_TEST_CHECK(detector2);
210 PinchGestureDetector detector3 = DownCast< PinchGestureDetector >(object);
211 DALI_TEST_CHECK(detector3);
213 BaseHandle unInitializedObject;
214 PinchGestureDetector detector4 = PinchGestureDetector::DownCast(unInitializedObject);
215 DALI_TEST_CHECK(!detector4);
217 PinchGestureDetector detector5 = DownCast< PinchGestureDetector >(unInitializedObject);
218 DALI_TEST_CHECK(!detector5);
220 GestureDetector detector6 = PinchGestureDetector::New();
221 PinchGestureDetector detector7 = PinchGestureDetector::DownCast(detector6);
222 DALI_TEST_CHECK(detector7);
226 // Negative test case for a method
227 int UtcDaliPinchGestureSignalReceptionNegative(void)
229 TestApplication application;
231 Actor actor = Actor::New();
232 actor.SetSize(100.0f, 100.0f);
233 actor.SetAnchorPoint(AnchorPoint::TOP_LEFT);
234 Stage::GetCurrent().Add(actor);
237 application.SendNotification();
238 application.Render();
241 GestureReceivedFunctor functor(data);
243 PinchGestureDetector detector = PinchGestureDetector::New();
244 detector.Attach(actor);
245 detector.DetectedSignal().Connect(&application, functor);
247 // Do a pinch outside actor's area
248 TestStartPinch( application, Vector2( 112.0f, 62.0f ), Vector2( 112.0f, 162.0f ),
249 Vector2( 112.0f, 100.0f ), Vector2( 112.0f, 124.0f ), 100 );
251 DALI_TEST_EQUALS(false, data.functorCalled, TEST_LOCATION);
253 // Continue pinch into actor's area - we should still not receive the signal
255 TestContinuePinch( application, Vector2( 112.0f, 100.0f ), Vector2( 112.0f, 124.0f ),
256 Vector2( 5.0f, 5.0f ), Vector2( 35.0f, 35.0f ), 200 );
258 DALI_TEST_EQUALS(false, data.functorCalled, TEST_LOCATION);
260 // Stop pinching - we should still not receive the signal
262 TestEndPinch( application, Vector2( 6.0f, 6.0f ), Vector2( 18.0f, 18.0f ),
263 Vector2( 10.0f, 8.0f ), Vector2( 14.0f, 16.0f ), 300 );
265 DALI_TEST_EQUALS(false, data.functorCalled, TEST_LOCATION);
269 int UtcDaliPinchGestureSignalReceptionDownMotionLeave(void)
271 TestApplication application;
273 Actor actor = Actor::New();
274 actor.SetSize(100.0f, 100.0f);
275 actor.SetAnchorPoint(AnchorPoint::TOP_LEFT);
276 Stage::GetCurrent().Add(actor);
279 application.SendNotification();
280 application.Render();
283 GestureReceivedFunctor functor(data);
285 PinchGestureDetector detector = PinchGestureDetector::New();
286 detector.Attach(actor);
287 detector.DetectedSignal().Connect(&application, functor);
289 // Start pan within the actor's area
290 TestStartPinch( application, Vector2( 5.0f, 20.0f ), Vector2( 35.0f, 20.0f ),
291 Vector2( 10.0f, 20.0f ), Vector2( 30.0f, 20.0f ), 100 );
292 DALI_TEST_EQUALS(true, data.functorCalled, TEST_LOCATION);
293 DALI_TEST_EQUALS(Gesture::Started, data.receivedGesture.state, TEST_LOCATION);
294 DALI_TEST_EQUALS(0.666f, data.receivedGesture.scale, 0.01f, TEST_LOCATION);
295 DALI_TEST_EQUALS(66.666f, data.receivedGesture.speed, 0.01f, TEST_LOCATION);
296 DALI_TEST_EQUALS(Vector2(20.0f, 20.0f), data.receivedGesture.screenCenterPoint, 0.01f, TEST_LOCATION);
298 // Continue the pan within the actor's area - we should still receive the signal
300 TestContinuePinch( application, Vector2( 10.0f, 20.0f ), Vector2( 30.0f, 20.0f ),
301 Vector2( 17.0f, 20.0f ), Vector2( 25.0f, 20.0f ), 400 );
302 DALI_TEST_EQUALS(true, data.functorCalled, TEST_LOCATION);
303 DALI_TEST_EQUALS(Gesture::Continuing, data.receivedGesture.state, TEST_LOCATION);
304 DALI_TEST_EQUALS(0.2666f, data.receivedGesture.scale, 0.01f, TEST_LOCATION);
305 DALI_TEST_EQUALS(80.0f, data.receivedGesture.speed, 0.01f, TEST_LOCATION);
306 DALI_TEST_EQUALS(Vector2(21.0f, 20.0f), data.receivedGesture.screenCenterPoint, 0.01f, TEST_LOCATION);
308 // Pan Gesture leaves actor's area - we should still receive the signal
310 TestContinuePinch( application, Vector2( 17.0f, 20.0f ), Vector2( 25.0f, 20.0f ),
311 Vector2( 300.0f, 10.0f ), Vector2( 340.0f, 10.0f ), 1000 );
312 DALI_TEST_EQUALS(true, data.functorCalled, TEST_LOCATION);
313 DALI_TEST_EQUALS(Gesture::Continuing, data.receivedGesture.state, TEST_LOCATION);
314 DALI_TEST_EQUALS(1.333f, data.receivedGesture.scale, 0.01f, TEST_LOCATION);
315 DALI_TEST_EQUALS(213.333f, data.receivedGesture.speed, 0.01f, TEST_LOCATION);
316 DALI_TEST_EQUALS(Vector2(320.0f, 10.0f), data.receivedGesture.screenCenterPoint, 0.01f, TEST_LOCATION);
318 // Gesture ends - we would receive a finished state
320 TestEndPinch( application, Vector2( 300.0f, 10.0f ), Vector2( 340.0f, 10.0f ),
321 Vector2( 305.0f, 10.0f ), Vector2( 315.0f, 10.0f ), 1500);
322 DALI_TEST_EQUALS(true, data.functorCalled, TEST_LOCATION);
323 DALI_TEST_EQUALS(Gesture::Finished, data.receivedGesture.state, TEST_LOCATION);
324 DALI_TEST_EQUALS(0.333f, data.receivedGesture.scale, 0.01f, TEST_LOCATION);
325 DALI_TEST_EQUALS(600.0f, data.receivedGesture.speed, 0.01f, TEST_LOCATION);
326 DALI_TEST_EQUALS(Vector2(310.0f, 10.0f), data.receivedGesture.screenCenterPoint, 0.01f, TEST_LOCATION);
330 int UtcDaliPinchGestureSignalReceptionDownMotionUp(void)
332 TestApplication application;
334 Actor actor = Actor::New();
335 actor.SetSize(100.0f, 100.0f);
336 actor.SetAnchorPoint(AnchorPoint::TOP_LEFT);
337 Stage::GetCurrent().Add(actor);
340 application.SendNotification();
341 application.Render();
344 GestureReceivedFunctor functor(data);
346 PinchGestureDetector detector = PinchGestureDetector::New();
347 detector.Attach(actor);
348 detector.DetectedSignal().Connect(&application, functor);
350 // Start pinch within the actor's area
351 TestStartPinch( application, Vector2( 2.0f, 20.0f ), Vector2( 38.0f, 20.0f ),
352 Vector2( 10.0f, 20.0f ), Vector2( 30.0f, 20.0f ), 100 );
353 DALI_TEST_EQUALS(true, data.functorCalled, TEST_LOCATION);
354 DALI_TEST_EQUALS(Gesture::Started, data.receivedGesture.state, TEST_LOCATION);
355 DALI_TEST_EQUALS(0.555f, data.receivedGesture.scale, 0.01f, TEST_LOCATION);
356 DALI_TEST_EQUALS(106.667f, data.receivedGesture.speed, 0.01f, TEST_LOCATION);
357 DALI_TEST_EQUALS(Vector2(20.0f, 20.0f), data.receivedGesture.screenCenterPoint, 0.01f, TEST_LOCATION);
359 // Continue the pinch within the actor's area - we should still receive the signal
361 TestContinuePinch( application, Vector2( 10.0f, 20.0f ), Vector2( 30.0f, 20.0f ),
362 Vector2( 15.0f, 20.0f ), Vector2( 25.0f, 20.0f ), 500 );
363 DALI_TEST_EQUALS(true, data.functorCalled, TEST_LOCATION);
364 DALI_TEST_EQUALS(Gesture::Continuing, data.receivedGesture.state, TEST_LOCATION);
365 DALI_TEST_EQUALS(0.277f, data.receivedGesture.scale, 0.01f, TEST_LOCATION);
366 DALI_TEST_EQUALS(66.666f, data.receivedGesture.speed, 0.01f, TEST_LOCATION);
367 DALI_TEST_EQUALS(Vector2(20.0f, 20.0f), data.receivedGesture.screenCenterPoint, 0.01f, TEST_LOCATION);
369 // Gesture ends within actor's area - we would receive a finished state
371 TestEndPinch( application, Vector2( 15.0f, 20.0f ), Vector2( 25.0f, 20.0f ),
372 Vector2( 19.0f, 20.0f ), Vector2( 21.0f, 20.0f ), 1000);
373 DALI_TEST_EQUALS(true, data.functorCalled, TEST_LOCATION);
374 DALI_TEST_EQUALS(Gesture::Finished, data.receivedGesture.state, TEST_LOCATION);
375 DALI_TEST_EQUALS(0.055f, data.receivedGesture.scale, 0.01f, TEST_LOCATION);
376 DALI_TEST_EQUALS(160.0f, data.receivedGesture.speed, 0.01f, TEST_LOCATION);
377 DALI_TEST_EQUALS(Vector2(20.0f, 20.0f), data.receivedGesture.screenCenterPoint, 0.01f, TEST_LOCATION);
381 int UtcDaliPinchGestureSignalReceptionDetach(void)
383 TestApplication application;
385 Actor actor = Actor::New();
386 actor.SetSize(100.0f, 100.0f);
387 actor.SetAnchorPoint(AnchorPoint::TOP_LEFT);
388 Stage::GetCurrent().Add(actor);
391 application.SendNotification();
392 application.Render();
395 GestureReceivedFunctor functor(data);
397 PinchGestureDetector detector = PinchGestureDetector::New();
398 detector.Attach(actor);
399 detector.DetectedSignal().Connect(&application, functor);
401 // Start pinch within the actor's area
402 TestStartPinch( application, Vector2( 2.0f, 20.0f ), Vector2( 38.0f, 20.0f ),
403 Vector2( 10.0f, 20.0f ), Vector2( 30.0f, 20.0f ), 100 );
404 DALI_TEST_EQUALS(true, data.functorCalled, TEST_LOCATION);
405 DALI_TEST_EQUALS(Gesture::Started, data.receivedGesture.state, TEST_LOCATION);
408 // Continue the pinch within the actor's area - we should still receive the signal
410 TestContinuePinch( application, Vector2( 10.0f, 20.0f ), Vector2( 30.0f, 20.0f ),
411 Vector2( 15.0f, 20.0f ), Vector2( 25.0f, 20.0f ), 500 );
412 DALI_TEST_EQUALS(true, data.functorCalled, TEST_LOCATION);
413 DALI_TEST_EQUALS(Gesture::Continuing, data.receivedGesture.state, TEST_LOCATION);
415 // Gesture ends within actor's area
417 TestEndPinch( application, Vector2( 15.0f, 20.0f ), Vector2( 25.0f, 20.0f ),
418 Vector2( 19.0f, 20.0f ), Vector2( 21.0f, 20.0f ), 1000);
419 DALI_TEST_EQUALS(true, data.functorCalled, TEST_LOCATION);
420 DALI_TEST_EQUALS(Gesture::Finished, data.receivedGesture.state, TEST_LOCATION);
423 detector.DetachAll();
425 // Ensure we are no longer signalled
427 TestGeneratePinch( application );
428 DALI_TEST_EQUALS(false, data.functorCalled, TEST_LOCATION);
432 int UtcDaliPinchGestureSignalReceptionDetachWhilePinching(void)
434 TestApplication application;
436 Actor actor = Actor::New();
437 actor.SetSize(100.0f, 100.0f);
438 actor.SetAnchorPoint(AnchorPoint::TOP_LEFT);
439 Stage::GetCurrent().Add(actor);
442 application.SendNotification();
443 application.Render();
446 GestureReceivedFunctor functor(data);
448 PinchGestureDetector detector = PinchGestureDetector::New();
449 detector.Attach(actor);
450 detector.DetectedSignal().Connect(&application, functor);
452 // Start pinch within the actor's area
453 TestStartPinch( application, Vector2( 2.0f, 20.0f ), Vector2( 38.0f, 20.0f ),
454 Vector2( 10.0f, 20.0f ), Vector2( 30.0f, 20.0f ), 100 );
455 DALI_TEST_EQUALS(true, data.functorCalled, TEST_LOCATION);
456 DALI_TEST_EQUALS(Gesture::Started, data.receivedGesture.state, TEST_LOCATION);
458 // Continue the pinch within the actor's area - we should still receive the signal
460 TestContinuePinch( application, Vector2( 10.0f, 20.0f ), Vector2( 30.0f, 20.0f ),
461 Vector2( 15.0f, 20.0f ), Vector2( 25.0f, 20.0f ), 500 );
462 DALI_TEST_EQUALS(true, data.functorCalled, TEST_LOCATION);
463 DALI_TEST_EQUALS(Gesture::Continuing, data.receivedGesture.state, TEST_LOCATION);
465 // Detach actor during the pinch, we should not receive the next event
466 detector.DetachAll();
468 // Gesture ends within actor's area
470 TestEndPinch( application, Vector2( 15.0f, 20.0f ), Vector2( 25.0f, 20.0f ),
471 Vector2( 19.0f, 20.0f ), Vector2( 21.0f, 20.0f ), 1000);
472 DALI_TEST_EQUALS(false, data.functorCalled, TEST_LOCATION);
476 int UtcDaliPinchGestureSignalReceptionActorDestroyedWhilePinching(void)
478 TestApplication application;
481 GestureReceivedFunctor functor(data);
483 PinchGestureDetector detector = PinchGestureDetector::New();
484 detector.DetectedSignal().Connect(&application, functor);
486 // Attach a temporary actor to stop detector being removed from PinchGestureProcessor when main actor
488 Actor tempActor = Actor::New();
489 tempActor.SetSize(100.0f, 100.0f);
490 tempActor.SetAnchorPoint(AnchorPoint::BOTTOM_RIGHT);
491 Stage::GetCurrent().Add(tempActor);
492 detector.Attach(tempActor);
494 // Actor lifetime is scoped
496 Actor actor = Actor::New();
497 actor.SetSize(100.0f, 100.0f);
498 actor.SetAnchorPoint(AnchorPoint::TOP_LEFT);
499 Stage::GetCurrent().Add(actor);
502 application.SendNotification();
503 application.Render();
505 detector.Attach(actor);
507 // Start pinch within the actor's area
508 TestStartPinch( application, Vector2( 2.0f, 20.0f ), Vector2( 38.0f, 20.0f ),
509 Vector2( 10.0f, 20.0f ), Vector2( 30.0f, 20.0f ), 100 );
510 DALI_TEST_EQUALS(true, data.functorCalled, TEST_LOCATION);
511 DALI_TEST_EQUALS(Gesture::Started, data.receivedGesture.state, TEST_LOCATION);
513 // Continue the pinch within the actor's area - we should still receive the signal
515 TestContinuePinch( application, Vector2( 10.0f, 20.0f ), Vector2( 30.0f, 20.0f ),
516 Vector2( 15.0f, 20.0f ), Vector2( 25.0f, 20.0f ), 500 );
517 DALI_TEST_EQUALS(true, data.functorCalled, TEST_LOCATION);
518 DALI_TEST_EQUALS(Gesture::Continuing, data.receivedGesture.state, TEST_LOCATION);
520 // Remove the actor from stage and reset the data
521 Stage::GetCurrent().Remove(actor);
524 application.SendNotification();
525 application.Render();
528 // Actor should now have been destroyed
530 // Gesture ends within the area where the actor used to be
532 TestEndPinch( application, Vector2( 15.0f, 20.0f ), Vector2( 25.0f, 20.0f ),
533 Vector2( 19.0f, 20.0f ), Vector2( 21.0f, 20.0f ), 1000);
534 DALI_TEST_EQUALS(false, data.functorCalled, TEST_LOCATION);
538 int UtcDaliPinchGestureSignalReceptionRotatedActor(void)
540 TestApplication application;
542 Actor actor = Actor::New();
543 actor.SetSize(100.0f, 100.0f);
544 actor.SetOrientation(Dali::Degree(90.0f), Vector3::ZAXIS);
545 Stage::GetCurrent().Add(actor);
547 // Render and notify a couple of times
548 application.SendNotification();
549 application.Render();
552 GestureReceivedFunctor functor(data);
554 PinchGestureDetector detector = PinchGestureDetector::New();
555 detector.Attach(actor);
556 detector.DetectedSignal().Connect(&application, functor);
558 // Do an entire pinch, only check finished value
559 TestStartPinch( application, Vector2( 2.0f, 20.0f ), Vector2( 38.0f, 20.0f ),
560 Vector2( 10.0f, 20.0f ), Vector2( 30.0f, 20.0f ), 100 );
562 TestEndPinch( application, Vector2( 15.0f, 20.0f ), Vector2( 25.0f, 20.0f ),
563 Vector2( 19.0f, 20.0f ), Vector2( 21.0f, 20.0f ), 1000);
564 DALI_TEST_EQUALS(true, data.functorCalled, TEST_LOCATION);
565 DALI_TEST_EQUALS(0.055f, data.receivedGesture.scale, 0.01f, TEST_LOCATION);
566 DALI_TEST_EQUALS(160.0f, data.receivedGesture.speed, 0.01f, TEST_LOCATION);
567 DALI_TEST_EQUALS(Vector2(20.0f, 20.0f), data.receivedGesture.screenCenterPoint, 0.01f, TEST_LOCATION);
569 // Rotate actor again and render and notify
570 actor.SetOrientation(Dali::Degree(180.0f), Vector3::ZAXIS);
571 application.SendNotification();
572 application.Render();
574 // Do an entire pinch, only check finished value
575 TestStartPinch( application, Vector2( 2.0f, 20.0f ), Vector2( 38.0f, 20.0f ),
576 Vector2( 10.0f, 20.0f ), Vector2( 30.0f, 20.0f ), 2100 );
578 TestEndPinch( application, Vector2( 15.0f, 20.0f ), Vector2( 25.0f, 20.0f ),
579 Vector2( 19.0f, 20.0f ), Vector2( 21.0f, 20.0f ), 3000);
580 DALI_TEST_EQUALS(true, data.functorCalled, TEST_LOCATION);
581 DALI_TEST_EQUALS(0.055f, data.receivedGesture.scale, 0.01f, TEST_LOCATION);
582 DALI_TEST_EQUALS(160.0f, data.receivedGesture.speed, 0.01f, TEST_LOCATION);
583 DALI_TEST_EQUALS(Vector2(20.0f, 20.0f), data.receivedGesture.screenCenterPoint, 0.01f, TEST_LOCATION);
585 // Rotate actor again and render and notify
586 actor.SetOrientation(Dali::Degree(270.0f), Vector3::ZAXIS);
587 application.SendNotification();
588 application.Render();
590 // Do an entire pinch, only check finished value
591 TestStartPinch( application, Vector2( 2.0f, 20.0f ), Vector2( 38.0f, 20.0f ),
592 Vector2( 10.0f, 20.0f ), Vector2( 30.0f, 20.0f ), 4100 );
594 TestEndPinch( application, Vector2( 15.0f, 20.0f ), Vector2( 25.0f, 20.0f ),
595 Vector2( 19.0f, 20.0f ), Vector2( 21.0f, 20.0f ), 5000);
596 DALI_TEST_EQUALS(true, data.functorCalled, TEST_LOCATION);
597 DALI_TEST_EQUALS(0.055f, data.receivedGesture.scale, 0.01f, TEST_LOCATION);
598 DALI_TEST_EQUALS(160.0f, data.receivedGesture.speed, 0.01f, TEST_LOCATION);
599 DALI_TEST_EQUALS(Vector2(20.0f, 20.0f), data.receivedGesture.screenCenterPoint, 0.01f, TEST_LOCATION);
603 int UtcDaliPinchGestureSignalReceptionChildHit(void)
605 TestApplication application;
607 Actor parent = Actor::New();
608 parent.SetSize(100.0f, 100.0f);
609 parent.SetAnchorPoint(AnchorPoint::TOP_LEFT);
610 Stage::GetCurrent().Add(parent);
612 // Set child to completely cover parent.
613 // Change rotation of child to be different from parent so that we can check if our local coordinate
614 // conversion of the parent actor is correct.
615 Actor child = Actor::New();
616 child.SetSize(100.0f, 100.0f);
617 child.SetAnchorPoint(AnchorPoint::CENTER);
618 child.SetParentOrigin(ParentOrigin::CENTER);
619 child.SetOrientation(Dali::Degree(90.0f), Vector3::ZAXIS);
622 TouchEventFunctor touchFunctor;
623 child.TouchedSignal().Connect(&application, touchFunctor);
626 application.SendNotification();
627 application.Render();
630 GestureReceivedFunctor functor(data);
632 PinchGestureDetector detector = PinchGestureDetector::New();
633 detector.Attach(parent);
634 detector.DetectedSignal().Connect(&application, functor);
636 // Do an entire pan, only check finished value - hits child area but parent should still receive it
637 TestStartPinch( application, Vector2( 2.0f, 20.0f ), Vector2( 38.0f, 20.0f ),
638 Vector2( 10.0f, 20.0f ), Vector2( 30.0f, 20.0f ), 100 );
640 TestEndPinch( application, Vector2( 15.0f, 20.0f ), Vector2( 25.0f, 20.0f ),
641 Vector2( 19.0f, 20.0f ), Vector2( 21.0f, 20.0f ), 1000);
642 DALI_TEST_EQUALS(true, data.functorCalled, TEST_LOCATION);
643 DALI_TEST_EQUALS(true, parent == data.pinchedActor, TEST_LOCATION);
644 DALI_TEST_EQUALS(0.055f, data.receivedGesture.scale, 0.01f, TEST_LOCATION);
645 DALI_TEST_EQUALS(160.0f, data.receivedGesture.speed, 0.01f, TEST_LOCATION);
646 DALI_TEST_EQUALS(Vector2(20.0f, 20.0f), data.receivedGesture.screenCenterPoint, 0.01f, TEST_LOCATION);
648 // Attach child and generate same touch points to yield same results
649 // (Also proves that you can detach and then re-attach another actor)
650 detector.Attach(child);
651 detector.Detach(parent);
653 // Do an entire pan, only check finished value
654 TestStartPinch( application, Vector2( 2.0f, 20.0f ), Vector2( 38.0f, 20.0f ),
655 Vector2( 10.0f, 20.0f ), Vector2( 30.0f, 20.0f ), 2100 );
657 TestEndPinch( application, Vector2( 15.0f, 20.0f ), Vector2( 25.0f, 20.0f ),
658 Vector2( 19.0f, 20.0f ), Vector2( 21.0f, 20.0f ), 3000);
659 DALI_TEST_EQUALS(true, data.functorCalled, TEST_LOCATION);
660 DALI_TEST_EQUALS(true, child == data.pinchedActor, TEST_LOCATION);
661 DALI_TEST_EQUALS(0.055f, data.receivedGesture.scale, 0.01f, TEST_LOCATION);
662 DALI_TEST_EQUALS(160.0f, data.receivedGesture.speed, 0.01f, TEST_LOCATION);
663 DALI_TEST_EQUALS(Vector2(20.0f, 20.0f), data.receivedGesture.screenCenterPoint, 0.01f, TEST_LOCATION);
667 int UtcDaliPinchGestureSignalReceptionAttachDetachMany(void)
669 TestApplication application;
671 Actor first = Actor::New();
672 first.SetSize(100.0f, 100.0f);
673 first.SetAnchorPoint(AnchorPoint::TOP_LEFT);
674 Stage::GetCurrent().Add(first);
676 Actor second = Actor::New();
677 second.SetSize(100.0f, 100.0f);
679 second.SetAnchorPoint(AnchorPoint::TOP_LEFT);
680 Stage::GetCurrent().Add(second);
683 application.SendNotification();
684 application.Render();
687 GestureReceivedFunctor functor(data);
689 PinchGestureDetector detector = PinchGestureDetector::New();
690 detector.Attach(first);
691 detector.Attach(second);
692 detector.DetectedSignal().Connect(&application, functor);
694 // Start pinch within second actor's area
695 TestStartPinch( application, Vector2( 102.0f, 20.0f ), Vector2( 138.0f, 20.0f ),
696 Vector2( 110.0f, 20.0f ), Vector2( 130.0f, 20.0f ), 100 );
697 DALI_TEST_EQUALS(true, data.functorCalled, TEST_LOCATION);
698 DALI_TEST_EQUALS(true, second == data.pinchedActor, TEST_LOCATION);
700 // Pinch moves into first actor's area - second actor should receive the pinch
702 TestContinuePinch( application, Vector2( 110.0f, 20.0f ), Vector2( 130.0f, 20.0f ),
703 Vector2( 15.0f, 20.0f ), Vector2( 25.0f, 20.0f ), 500 );
704 DALI_TEST_EQUALS(true, data.functorCalled, TEST_LOCATION);
705 DALI_TEST_EQUALS(true, second == data.pinchedActor, TEST_LOCATION);
707 // Detach the second actor during the pinch, we should not receive the next event
708 detector.Detach(second);
710 // Gesture ends within actor's area
712 TestEndPinch( application, Vector2( 15.0f, 20.0f ), Vector2( 25.0f, 20.0f ),
713 Vector2( 119.0f, 20.0f ), Vector2( 121.0f, 20.0f ), 3000);
714 DALI_TEST_EQUALS(false, data.functorCalled, TEST_LOCATION);
718 int UtcDaliPinchGestureSignalReceptionActorBecomesUntouchable(void)
720 TestApplication application;
722 Actor actor = Actor::New();
723 actor.SetSize(100.0f, 100.0f);
724 actor.SetAnchorPoint(AnchorPoint::TOP_LEFT);
725 Stage::GetCurrent().Add(actor);
728 application.SendNotification();
729 application.Render();
732 GestureReceivedFunctor functor(data);
734 PinchGestureDetector detector = PinchGestureDetector::New();
735 detector.Attach(actor);
736 detector.DetectedSignal().Connect(&application, functor);
738 // Start pinch in actor's area
739 TestStartPinch( application, Vector2( 2.0f, 20.0f ), Vector2( 38.0f, 20.0f ),
740 Vector2( 10.0f, 20.0f ), Vector2( 30.0f, 20.0f ), 100 );
741 DALI_TEST_EQUALS(true, data.functorCalled, TEST_LOCATION);
743 // Pan continues within actor's area
745 TestContinuePinch( application, Vector2( 10.0f, 20.0f ), Vector2( 30.0f, 20.0f ),
746 Vector2( 15.0f, 20.0f ), Vector2( 25.0f, 20.0f ), 500 );
747 DALI_TEST_EQUALS(true, data.functorCalled, TEST_LOCATION);
749 // Actor become invisible - actor should not receive the next pinch
750 actor.SetVisible(false);
753 application.SendNotification();
754 application.Render();
756 // Gesture ends within actor's area
758 TestEndPinch( application, Vector2( 15.0f, 20.0f ), Vector2( 25.0f, 20.0f ),
759 Vector2( 19.0f, 20.0f ), Vector2( 21.0f, 20.0f ), 3000);
760 DALI_TEST_EQUALS(false, data.functorCalled, TEST_LOCATION);
764 int UtcDaliPinchGestureSignalReceptionMultipleDetectorsOnActor(void)
766 TestApplication application;
768 Actor actor = Actor::New();
769 actor.SetSize(100.0f, 100.0f);
770 actor.SetAnchorPoint(AnchorPoint::TOP_LEFT);
771 Stage::GetCurrent().Add(actor);
773 Actor actor2 = Actor::New();
774 actor2.SetSize(100.0f, 100.0f);
775 actor2.SetAnchorPoint(AnchorPoint::BOTTOM_RIGHT);
776 Stage::GetCurrent().Add(actor2);
779 application.SendNotification();
780 application.Render();
782 // Attach actor to one detector
783 SignalData firstData;
784 GestureReceivedFunctor firstFunctor(firstData);
785 PinchGestureDetector firstDetector = PinchGestureDetector::New();
786 firstDetector.Attach(actor);
787 firstDetector.DetectedSignal().Connect(&application, firstFunctor);
789 // Attach actor to another detector
790 SignalData secondData;
791 GestureReceivedFunctor secondFunctor(secondData);
792 PinchGestureDetector secondDetector = PinchGestureDetector::New();
793 secondDetector.Attach(actor);
794 secondDetector.DetectedSignal().Connect(&application, secondFunctor);
796 // Add second actor to second detector, when we remove the actor, this will make sure that this
797 // gesture detector is not removed from the GestureDetectorProcessor. In this scenario, the
798 // functor should still not be called (which is what we're also testing).
799 secondDetector.Attach(actor2);
801 // Pinch in actor's area - both detector's functors should be called
802 TestStartPinch( application, Vector2( 2.0f, 20.0f ), Vector2( 38.0f, 20.0f ),
803 Vector2( 10.0f, 20.0f ), Vector2( 30.0f, 20.0f ), 100 );
804 DALI_TEST_EQUALS(true, firstData.functorCalled, TEST_LOCATION);
805 DALI_TEST_EQUALS(true, secondData.functorCalled, TEST_LOCATION);
807 // Pinch continues in actor's area - both detector's functors should be called
810 TestContinuePinch( application, Vector2( 10.0f, 20.0f ), Vector2( 30.0f, 20.0f ),
811 Vector2( 15.0f, 20.0f ), Vector2( 25.0f, 20.0f ), 500 );
812 DALI_TEST_EQUALS(true, firstData.functorCalled, TEST_LOCATION);
813 DALI_TEST_EQUALS(true, secondData.functorCalled, TEST_LOCATION);
815 // Detach actor from firstDetector and emit pinch on actor, only secondDetector's functor should be called.
816 firstDetector.Detach(actor);
819 TestEndPinch( application, Vector2( 15.0f, 20.0f ), Vector2( 25.0f, 20.0f ),
820 Vector2( 19.0f, 20.0f ), Vector2( 21.0f, 20.0f ), 1000);
821 DALI_TEST_EQUALS(false, firstData.functorCalled, TEST_LOCATION);
822 DALI_TEST_EQUALS(true, secondData.functorCalled, TEST_LOCATION);
824 // New pinch on actor, only secondDetector has actor attached
827 TestStartPinch( application, Vector2( 2.0f, 20.0f ), Vector2( 38.0f, 20.0f ),
828 Vector2( 10.0f, 20.0f ), Vector2( 30.0f, 20.0f ), 1500 );
829 DALI_TEST_EQUALS(false, firstData.functorCalled, TEST_LOCATION);
830 DALI_TEST_EQUALS(true, secondData.functorCalled, TEST_LOCATION);
832 // Detach actor from secondDetector
833 secondDetector.Detach(actor);
836 TestContinuePinch( application, Vector2( 10.0f, 20.0f ), Vector2( 30.0f, 20.0f ),
837 Vector2( 15.0f, 20.0f ), Vector2( 25.0f, 20.0f ), 2000 );
838 DALI_TEST_EQUALS(false, firstData.functorCalled, TEST_LOCATION);
839 DALI_TEST_EQUALS(false, secondData.functorCalled, TEST_LOCATION);
843 int UtcDaliPinchGestureSignalReceptionEnsureCorrectSignalling(void)
845 TestApplication application;
847 Actor actor1 = Actor::New();
848 actor1.SetSize(100.0f, 100.0f);
849 actor1.SetAnchorPoint(AnchorPoint::TOP_LEFT);
850 Stage::GetCurrent().Add(actor1);
852 GestureReceivedFunctor functor1(data1);
853 PinchGestureDetector detector1 = PinchGestureDetector::New();
854 detector1.Attach(actor1);
855 detector1.DetectedSignal().Connect(&application, functor1);
857 Actor actor2 = Actor::New();
858 actor2.SetSize(100.0f, 100.0f);
859 actor2.SetAnchorPoint(AnchorPoint::BOTTOM_RIGHT);
860 actor2.SetParentOrigin(ParentOrigin::BOTTOM_RIGHT);
861 Stage::GetCurrent().Add(actor2);
863 GestureReceivedFunctor functor2(data2);
864 PinchGestureDetector detector2 = PinchGestureDetector::New();
865 detector2.Attach(actor2);
866 detector2.DetectedSignal().Connect(&application, functor2);
869 application.SendNotification();
870 application.Render();
872 // Start pan in actor1's area, only data1 should be set
873 TestStartPinch( application, Vector2( 2.0f, 20.0f ), Vector2( 38.0f, 20.0f ),
874 Vector2( 10.0f, 20.0f ), Vector2( 30.0f, 20.0f ), 100 );
875 DALI_TEST_EQUALS(true, data1.functorCalled, TEST_LOCATION);
876 DALI_TEST_EQUALS(false, data2.functorCalled, TEST_LOCATION);
880 int UtcDaliPinchGestureActorUnstaged(void)
882 TestApplication application;
884 Actor actor = Actor::New();
885 actor.SetSize(100.0f, 100.0f);
886 actor.SetAnchorPoint(AnchorPoint::TOP_LEFT);
887 Stage::GetCurrent().Add(actor);
890 application.SendNotification();
891 application.Render();
893 // State to remove actor in.
894 Gesture::State stateToUnstage( Gesture::Started );
896 // Attach actor to detector
898 UnstageActorFunctor functor( data, stateToUnstage );
899 PinchGestureDetector detector = PinchGestureDetector::New();
900 detector.Attach(actor);
901 detector.DetectedSignal().Connect( &application, functor );
904 TestStartPinch( application, Vector2( 2.0f, 20.0f ), Vector2( 38.0f, 20.0f ),
905 Vector2( 10.0f, 20.0f ), Vector2( 30.0f, 20.0f ), 100 );
906 DALI_TEST_EQUALS(true, data.functorCalled, TEST_LOCATION);
908 TestEndPinch( application, Vector2( 10.0f, 20.0f ), Vector2( 30.0f, 20.0f ),
909 Vector2( 19.0f, 20.0f ), Vector2( 21.0f, 20.0f ), 1000);
910 DALI_TEST_EQUALS(false, data.functorCalled, TEST_LOCATION);
914 application.SendNotification();
915 application.Render();
917 // Re-add actor to stage
918 Stage::GetCurrent().Add(actor);
921 application.SendNotification();
922 application.Render();
924 // Change state to Gesture::Continuing to remove
925 stateToUnstage = Gesture::Continuing;
928 TestStartPinch( application, Vector2( 2.0f, 20.0f ), Vector2( 38.0f, 20.0f ),
929 Vector2( 10.0f, 20.0f ), Vector2( 30.0f, 20.0f ), 100 );
930 DALI_TEST_EQUALS(true, data.functorCalled, TEST_LOCATION);
932 TestContinuePinch( application, Vector2( 10.0f, 20.0f ), Vector2( 30.0f, 20.0f ),
933 Vector2( 15.0f, 20.0f ), Vector2( 25.0f, 20.0f ), 500 );
934 DALI_TEST_EQUALS(true, data.functorCalled, TEST_LOCATION);
936 TestEndPinch( application, Vector2( 10.0f, 20.0f ), Vector2( 30.0f, 20.0f ),
937 Vector2( 19.0f, 20.0f ), Vector2( 21.0f, 20.0f ), 1000);
938 DALI_TEST_EQUALS(false, data.functorCalled, TEST_LOCATION);
942 application.SendNotification();
943 application.Render();
945 // Re-add actor to stage
946 Stage::GetCurrent().Add(actor);
949 application.SendNotification();
950 application.Render();
952 // Change state to Gesture::Continuing to remove
953 stateToUnstage = Gesture::Finished;
956 TestStartPinch( application, Vector2( 2.0f, 20.0f ), Vector2( 38.0f, 20.0f ),
957 Vector2( 10.0f, 20.0f ), Vector2( 30.0f, 20.0f ), 100 );
958 DALI_TEST_EQUALS(true, data.functorCalled, TEST_LOCATION);
960 TestContinuePinch( application, Vector2( 10.0f, 20.0f ), Vector2( 30.0f, 20.0f ),
961 Vector2( 15.0f, 20.0f ), Vector2( 25.0f, 20.0f ), 500 );
962 DALI_TEST_EQUALS(true, data.functorCalled, TEST_LOCATION);
964 TestEndPinch( application, Vector2( 10.0f, 20.0f ), Vector2( 30.0f, 20.0f ),
965 Vector2( 19.0f, 20.0f ), Vector2( 21.0f, 20.0f ), 1000);
966 DALI_TEST_EQUALS(true, data.functorCalled, TEST_LOCATION);
967 tet_result( TET_PASS ); // If we get here then we have handled actor stage removal gracefully.
971 int UtcDaliPinchGestureActorStagedAndDestroyed(void)
973 TestApplication application;
975 Actor actor = Actor::New();
976 actor.SetSize(100.0f, 100.0f);
977 actor.SetAnchorPoint(AnchorPoint::TOP_LEFT);
978 Stage::GetCurrent().Add(actor);
980 // Create and add a second actor so that GestureDetector destruction does not come into play.
981 Actor dummyActor( Actor::New() );
982 dummyActor.SetSize( 100.0f, 100.0f );
983 dummyActor.SetPosition( 100.0f, 100.0f );
984 dummyActor.SetAnchorPoint(AnchorPoint::TOP_LEFT);
985 Stage::GetCurrent().Add(dummyActor);
988 application.SendNotification();
989 application.Render();
991 // State to remove actor in.
992 Gesture::State stateToUnstage( Gesture::Started );
994 // Attach actor to detector
996 UnstageActorFunctor functor( data, stateToUnstage );
997 PinchGestureDetector detector = PinchGestureDetector::New();
998 detector.Attach(actor);
999 detector.Attach(dummyActor);
1000 detector.DetectedSignal().Connect( &application, functor );
1002 // Here we are testing a Started actor which is removed in the Started callback, but then added back
1003 // before we get a continuing state. As we were removed from the stage, even if we're at the same
1004 // position, we should still not be signalled.
1007 TestStartPinch( application, Vector2( 2.0f, 20.0f ), Vector2( 38.0f, 20.0f ),
1008 Vector2( 10.0f, 20.0f ), Vector2( 30.0f, 20.0f ), 100 );
1009 DALI_TEST_EQUALS(true, data.functorCalled, TEST_LOCATION);
1012 // Render and notify
1013 application.SendNotification();
1014 application.Render();
1016 // Re add to the stage, we should not be signalled
1017 Stage::GetCurrent().Add(actor);
1019 // Render and notify
1020 application.SendNotification();
1021 application.Render();
1023 // Continue signal emission
1024 TestContinuePinch( application, Vector2( 10.0f, 20.0f ), Vector2( 30.0f, 20.0f ),
1025 Vector2( 15.0f, 20.0f ), Vector2( 25.0f, 20.0f ), 500 );
1026 DALI_TEST_EQUALS(false, data.functorCalled, TEST_LOCATION);
1028 TestEndPinch( application, Vector2( 10.0f, 20.0f ), Vector2( 30.0f, 20.0f ),
1029 Vector2( 19.0f, 20.0f ), Vector2( 21.0f, 20.0f ), 1000);
1030 DALI_TEST_EQUALS(false, data.functorCalled, TEST_LOCATION);
1033 // Here we delete an actor in started, we should not receive any subsequent signalling.
1036 TestStartPinch( application, Vector2( 2.0f, 20.0f ), Vector2( 38.0f, 20.0f ),
1037 Vector2( 10.0f, 20.0f ), Vector2( 30.0f, 20.0f ), 1500 );
1038 DALI_TEST_EQUALS(true, data.functorCalled, TEST_LOCATION);
1041 // Render and notify
1042 application.SendNotification();
1043 application.Render();
1045 // Delete actor as well
1048 // Render and notify
1049 application.SendNotification();
1050 application.Render();
1052 // Continue signal emission
1053 TestContinuePinch( application, Vector2( 10.0f, 20.0f ), Vector2( 30.0f, 20.0f ),
1054 Vector2( 15.0f, 20.0f ), Vector2( 25.0f, 20.0f ), 2000 );
1055 DALI_TEST_EQUALS(false, data.functorCalled, TEST_LOCATION);
1057 TestEndPinch( application, Vector2( 10.0f, 20.0f ), Vector2( 30.0f, 20.0f ),
1058 Vector2( 19.0f, 20.0f ), Vector2( 21.0f, 20.0f ), 3000);
1059 DALI_TEST_EQUALS(false, data.functorCalled, TEST_LOCATION);
1063 int UtcDaliPinchGestureLayerConsumesTouch(void)
1065 TestApplication application;
1067 Actor actor = Actor::New();
1068 actor.SetSize(100.0f, 100.0f);
1069 actor.SetAnchorPoint(AnchorPoint::TOP_LEFT);
1070 Stage::GetCurrent().Add(actor);
1074 GestureReceivedFunctor functor(data);
1075 PinchGestureDetector detector = PinchGestureDetector::New();
1076 detector.Attach(actor);
1077 detector.DetectedSignal().Connect( &application, functor );
1079 // Add a layer to overlap the actor
1080 Layer layer = Layer::New();
1081 layer.SetSize(100.0f, 100.0f);
1082 layer.SetAnchorPoint(AnchorPoint::TOP_LEFT);
1083 Stage::GetCurrent().Add( layer );
1086 // Render and notify
1087 application.SendNotification();
1088 application.Render();
1090 // Emit signals, should receive
1091 TestStartPinch( application, Vector2( 2.0f, 20.0f ), Vector2( 38.0f, 20.0f ),
1092 Vector2( 10.0f, 20.0f ), Vector2( 30.0f, 20.0f ), 100 );
1093 TestEndPinch( application, Vector2( 10.0f, 20.0f ), Vector2( 30.0f, 20.0f ),
1094 Vector2( 19.0f, 20.0f ), Vector2( 21.0f, 20.0f ), 1000);
1095 DALI_TEST_EQUALS(true, data.functorCalled, TEST_LOCATION);
1098 // Set layer to consume all touch
1099 layer.SetTouchConsumed( true );
1101 // Render and notify
1102 application.SendNotification();
1103 application.Render();
1105 // Emit the same signals again, should not receive
1106 TestStartPinch( application, Vector2( 2.0f, 20.0f ), Vector2( 38.0f, 20.0f ),
1107 Vector2( 10.0f, 20.0f ), Vector2( 30.0f, 20.0f ), 1500 );
1108 TestEndPinch( application, Vector2( 10.0f, 20.0f ), Vector2( 30.0f, 20.0f ),
1109 Vector2( 19.0f, 20.0f ), Vector2( 21.0f, 20.0f ), 2000);
1110 DALI_TEST_EQUALS(false, data.functorCalled, TEST_LOCATION);