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.
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-event-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),
54 functorCalled = false;
55 voidFunctorCalled = false;
57 receivedGesture.Reset();
63 bool voidFunctorCalled;
64 PinchGesture receivedGesture;
68 // Functor that sets the data when called
69 struct GestureReceivedFunctor
71 GestureReceivedFunctor(SignalData& data) : signalData(data) { }
73 void operator()(Actor actor, const PinchGesture& pinch)
75 signalData.functorCalled = true;
76 signalData.receivedGesture = pinch;
77 signalData.pinchedActor = actor;
82 signalData.voidFunctorCalled = true;
85 SignalData& signalData;
88 // Functor that removes the gestured actor from stage
89 struct UnstageActorFunctor : public GestureReceivedFunctor
91 UnstageActorFunctor( SignalData& data, GestureState& stateToUnstage, Integration::Scene scene )
92 : GestureReceivedFunctor( data ),
93 stateToUnstage( stateToUnstage ),
98 void operator()( Actor actor, const PinchGesture& pinch )
100 GestureReceivedFunctor::operator()( actor, pinch );
102 if ( pinch.GetState() == stateToUnstage )
104 scene.Remove( actor );
108 GestureState& stateToUnstage;
109 Integration::Scene scene;
114 ///////////////////////////////////////////////////////////////////////////////
116 int UtcDaliPinchGestureDetectorConstructor(void)
118 TestApplication application;
120 PinchGestureDetector detector;
121 DALI_TEST_CHECK(!detector);
125 int UtcDaliPinchGestureDetectorCopyConstructorP(void)
127 TestApplication application;
129 PinchGestureDetector detector = PinchGestureDetector::New();;
131 PinchGestureDetector copy( detector );
132 DALI_TEST_CHECK( detector );
136 int UtcDaliPinchGestureDetectorAssignmentOperatorP(void)
138 TestApplication application;
140 PinchGestureDetector detector = PinchGestureDetector::New();;
142 PinchGestureDetector assign;
144 DALI_TEST_CHECK( detector );
146 DALI_TEST_CHECK( detector == assign );
150 int UtcDaliPinchGestureDetectorNew(void)
152 TestApplication application;
154 PinchGestureDetector detector = PinchGestureDetector::New();
156 DALI_TEST_CHECK(detector);
158 // Attach an actor and emit a touch event on the actor to ensure complete line coverage
159 Actor actor = Actor::New();
160 actor.SetProperty( Actor::Property::SIZE, Vector2( 100.0f, 100.0f ) );
161 actor.SetProperty( Actor::Property::ANCHOR_POINT,AnchorPoint::TOP_LEFT);
162 application.GetScene().Add(actor);
165 application.SendNotification();
166 application.Render();
168 detector.Attach(actor);
170 Integration::TouchEvent touchEvent(1);
171 Integration::Point point;
172 point.SetDeviceId( 1 );
173 point.SetState( PointState::DOWN );
174 point.SetScreenPosition( Vector2( 20.0f, 20.0f ) );
175 touchEvent.AddPoint(point);
176 application.ProcessEvent(touchEvent);
178 Integration::Point point2;
179 point.SetDeviceId( 1 );
180 point.SetState( PointState::DOWN );
181 point.SetScreenPosition( Vector2( 20.0f, 20.0f ) );
182 touchEvent.AddPoint(point2);
183 application.ProcessEvent(touchEvent);
187 int UtcDaliPinchGestureDetectorDownCast(void)
189 TestApplication application;
190 tet_infoline("Testing Dali::PinchGestureDetector::DownCast()");
192 PinchGestureDetector detector = PinchGestureDetector::New();
194 BaseHandle object(detector);
196 PinchGestureDetector detector2 = PinchGestureDetector::DownCast(object);
197 DALI_TEST_CHECK(detector2);
199 PinchGestureDetector detector3 = DownCast< PinchGestureDetector >(object);
200 DALI_TEST_CHECK(detector3);
202 BaseHandle unInitializedObject;
203 PinchGestureDetector detector4 = PinchGestureDetector::DownCast(unInitializedObject);
204 DALI_TEST_CHECK(!detector4);
206 PinchGestureDetector detector5 = DownCast< PinchGestureDetector >(unInitializedObject);
207 DALI_TEST_CHECK(!detector5);
209 GestureDetector detector6 = PinchGestureDetector::New();
210 PinchGestureDetector detector7 = PinchGestureDetector::DownCast(detector6);
211 DALI_TEST_CHECK(detector7);
215 // Negative test case for a method
216 int UtcDaliPinchGestureSignalReceptionNegative(void)
218 TestApplication application;
220 Actor actor = Actor::New();
221 actor.SetProperty( Actor::Property::SIZE, Vector2( 100.0f, 100.0f ) );
222 actor.SetProperty( Actor::Property::ANCHOR_POINT,AnchorPoint::TOP_LEFT);
223 application.GetScene().Add(actor);
226 application.SendNotification();
227 application.Render();
230 GestureReceivedFunctor functor(data);
232 PinchGestureDetector detector = PinchGestureDetector::New();
233 detector.Attach(actor);
234 detector.DetectedSignal().Connect(&application, functor);
236 // Do a pinch outside actor's area
237 TestStartPinch( application, Vector2( 112.0f, 62.0f ), Vector2( 112.0f, 162.0f ),
238 Vector2( 112.0f, 100.0f ), Vector2( 112.0f, 124.0f ), 100 );
240 DALI_TEST_EQUALS(false, data.functorCalled, TEST_LOCATION);
242 // Continue pinch into actor's area - we should still not receive the signal
244 TestContinuePinch( application, Vector2( 112.0f, 100.0f ), Vector2( 112.0f, 124.0f ),
245 Vector2( 5.0f, 5.0f ), Vector2( 35.0f, 35.0f ), 200 );
247 DALI_TEST_EQUALS(false, data.functorCalled, TEST_LOCATION);
249 // Stop pinching - we should still not receive the signal
251 TestEndPinch( application, Vector2( 6.0f, 6.0f ), Vector2( 18.0f, 18.0f ),
252 Vector2( 10.0f, 8.0f ), Vector2( 14.0f, 16.0f ), 300 );
254 DALI_TEST_EQUALS(false, data.functorCalled, TEST_LOCATION);
258 int UtcDaliPinchGestureSignalReceptionDownMotionLeave(void)
260 TestApplication application;
262 Actor actor = Actor::New();
263 actor.SetProperty( Actor::Property::SIZE, Vector2( 100.0f, 100.0f ) );
264 actor.SetProperty( Actor::Property::ANCHOR_POINT,AnchorPoint::TOP_LEFT);
265 application.GetScene().Add(actor);
268 application.SendNotification();
269 application.Render();
272 GestureReceivedFunctor functor(data);
274 PinchGestureDetector detector = PinchGestureDetector::New();
275 detector.Attach(actor);
276 detector.DetectedSignal().Connect(&application, functor);
278 // Start pan within the actor's area
279 TestStartPinch( application, Vector2( 5.0f, 20.0f ), Vector2( 35.0f, 20.0f ),
280 Vector2( 10.0f, 20.0f ), Vector2( 30.0f, 20.0f ), 100 );
281 DALI_TEST_EQUALS(true, data.functorCalled, TEST_LOCATION);
282 DALI_TEST_EQUALS(GestureState::STARTED, data.receivedGesture.GetState(), TEST_LOCATION);
283 DALI_TEST_EQUALS(0.666f, data.receivedGesture.GetScale(), 0.01f, TEST_LOCATION);
284 DALI_TEST_EQUALS(66.666f, data.receivedGesture.GetSpeed(), 0.01f, TEST_LOCATION);
285 DALI_TEST_EQUALS(Vector2(20.0f, 20.0f), data.receivedGesture.GetScreenCenterPoint(), 0.01f, TEST_LOCATION);
286 DALI_TEST_EQUALS(Vector2(20.0f, 20.0f), data.receivedGesture.GetLocalCenterPoint(), 0.01f, TEST_LOCATION);
288 // Continue the pan within the actor's area - we should still receive the signal
290 TestContinuePinch( application, Vector2( 10.0f, 20.0f ), Vector2( 30.0f, 20.0f ),
291 Vector2( 17.0f, 20.0f ), Vector2( 25.0f, 20.0f ), 400 );
292 DALI_TEST_EQUALS(true, data.functorCalled, TEST_LOCATION);
293 DALI_TEST_EQUALS(GestureState::CONTINUING, data.receivedGesture.GetState(), TEST_LOCATION);
294 DALI_TEST_EQUALS(0.2666f, data.receivedGesture.GetScale(), 0.01f, TEST_LOCATION);
295 DALI_TEST_EQUALS(80.0f, data.receivedGesture.GetSpeed(), 0.01f, TEST_LOCATION);
296 DALI_TEST_EQUALS(Vector2(21.0f, 20.0f), data.receivedGesture.GetScreenCenterPoint(), 0.01f, TEST_LOCATION);
297 DALI_TEST_EQUALS(Vector2(21.0f, 20.0f), data.receivedGesture.GetLocalCenterPoint(), 0.01f, TEST_LOCATION);
299 // Pinch Gesture leaves actor's area - we should still receive the signal
301 TestContinuePinch( application, Vector2( 17.0f, 20.0f ), Vector2( 25.0f, 20.0f ),
302 Vector2( 300.0f, 10.0f ), Vector2( 340.0f, 10.0f ), 1000 );
303 DALI_TEST_EQUALS(true, data.functorCalled, TEST_LOCATION);
304 DALI_TEST_EQUALS(GestureState::CONTINUING, data.receivedGesture.GetState(), TEST_LOCATION);
305 DALI_TEST_EQUALS(1.333f, data.receivedGesture.GetScale(), 0.01f, TEST_LOCATION);
306 DALI_TEST_EQUALS(213.333f, data.receivedGesture.GetSpeed(), 0.01f, TEST_LOCATION);
307 DALI_TEST_EQUALS(Vector2(320.0f, 10.0f), data.receivedGesture.GetScreenCenterPoint(), 0.01f, TEST_LOCATION);
308 DALI_TEST_EQUALS(Vector2(320.0f, 10.0f), data.receivedGesture.GetLocalCenterPoint(), 0.01f, TEST_LOCATION);
310 // Gesture ends - we would receive a finished state
312 TestEndPinch( application, Vector2( 300.0f, 10.0f ), Vector2( 340.0f, 10.0f ),
313 Vector2( 305.0f, 10.0f ), Vector2( 315.0f, 10.0f ), 1500);
314 DALI_TEST_EQUALS(true, data.functorCalled, TEST_LOCATION);
315 DALI_TEST_EQUALS(GestureState::FINISHED, data.receivedGesture.GetState(), TEST_LOCATION);
316 DALI_TEST_EQUALS(0.333f, data.receivedGesture.GetScale(), 0.01f, TEST_LOCATION);
317 DALI_TEST_EQUALS(600.0f, data.receivedGesture.GetSpeed(), 0.01f, TEST_LOCATION);
318 DALI_TEST_EQUALS(Vector2(310.0f, 10.0f), data.receivedGesture.GetScreenCenterPoint(), 0.01f, TEST_LOCATION);
319 DALI_TEST_EQUALS(Vector2(310.0f, 10.0f), data.receivedGesture.GetLocalCenterPoint(), 0.01f, TEST_LOCATION);
323 int UtcDaliPinchGestureSignalReceptionDownMotionUp(void)
325 TestApplication application;
327 Actor actor = Actor::New();
328 actor.SetProperty( Actor::Property::SIZE, Vector2( 100.0f, 100.0f ) );
329 actor.SetProperty( Actor::Property::ANCHOR_POINT,AnchorPoint::TOP_LEFT);
330 application.GetScene().Add(actor);
333 application.SendNotification();
334 application.Render();
337 GestureReceivedFunctor functor(data);
339 PinchGestureDetector detector = PinchGestureDetector::New();
340 detector.Attach(actor);
341 detector.DetectedSignal().Connect(&application, functor);
343 // Start pinch within the actor's area
344 TestStartPinch( application, Vector2( 2.0f, 20.0f ), Vector2( 38.0f, 20.0f ),
345 Vector2( 10.0f, 20.0f ), Vector2( 30.0f, 20.0f ), 100 );
346 DALI_TEST_EQUALS(true, data.functorCalled, TEST_LOCATION);
347 DALI_TEST_EQUALS(GestureState::STARTED, data.receivedGesture.GetState(), TEST_LOCATION);
348 DALI_TEST_EQUALS(0.555f, data.receivedGesture.GetScale(), 0.01f, TEST_LOCATION);
349 DALI_TEST_EQUALS(106.667f, data.receivedGesture.GetSpeed(), 0.01f, TEST_LOCATION);
350 DALI_TEST_EQUALS(Vector2(20.0f, 20.0f), data.receivedGesture.GetScreenCenterPoint(), 0.01f, TEST_LOCATION);
351 DALI_TEST_EQUALS(Vector2(20.0f, 20.0f), data.receivedGesture.GetLocalCenterPoint(), 0.01f, TEST_LOCATION);
353 // Continue the pinch within the actor's area - we should still receive the signal
355 TestContinuePinch( application, Vector2( 10.0f, 20.0f ), Vector2( 30.0f, 20.0f ),
356 Vector2( 15.0f, 20.0f ), Vector2( 25.0f, 20.0f ), 500 );
357 DALI_TEST_EQUALS(true, data.functorCalled, TEST_LOCATION);
358 DALI_TEST_EQUALS(GestureState::CONTINUING, data.receivedGesture.GetState(), TEST_LOCATION);
359 DALI_TEST_EQUALS(0.277f, data.receivedGesture.GetScale(), 0.01f, TEST_LOCATION);
360 DALI_TEST_EQUALS(66.666f, data.receivedGesture.GetSpeed(), 0.01f, TEST_LOCATION);
361 DALI_TEST_EQUALS(Vector2(20.0f, 20.0f), data.receivedGesture.GetScreenCenterPoint(), 0.01f, TEST_LOCATION);
362 DALI_TEST_EQUALS(Vector2(20.0f, 20.0f), data.receivedGesture.GetLocalCenterPoint(), 0.01f, TEST_LOCATION);
364 // Gesture ends within actor's area - we would receive a finished state
366 TestEndPinch( application, Vector2( 15.0f, 20.0f ), Vector2( 25.0f, 20.0f ),
367 Vector2( 19.0f, 20.0f ), Vector2( 21.0f, 20.0f ), 1000);
368 DALI_TEST_EQUALS(true, data.functorCalled, TEST_LOCATION);
369 DALI_TEST_EQUALS(GestureState::FINISHED, data.receivedGesture.GetState(), TEST_LOCATION);
370 DALI_TEST_EQUALS(0.055f, data.receivedGesture.GetScale(), 0.01f, TEST_LOCATION);
371 DALI_TEST_EQUALS(160.0f, data.receivedGesture.GetSpeed(), 0.01f, TEST_LOCATION);
372 DALI_TEST_EQUALS(Vector2(20.0f, 20.0f), data.receivedGesture.GetScreenCenterPoint(), 0.01f, TEST_LOCATION);
373 DALI_TEST_EQUALS(Vector2(20.0f, 20.0f), data.receivedGesture.GetLocalCenterPoint(), 0.01f, TEST_LOCATION);
377 int UtcDaliPinchGestureSignalReceptionDetach(void)
379 TestApplication application;
381 Actor actor = Actor::New();
382 actor.SetProperty( Actor::Property::SIZE, Vector2( 100.0f, 100.0f ) );
383 actor.SetProperty( Actor::Property::ANCHOR_POINT,AnchorPoint::TOP_LEFT);
384 application.GetScene().Add(actor);
387 application.SendNotification();
388 application.Render();
391 GestureReceivedFunctor functor(data);
393 PinchGestureDetector detector = PinchGestureDetector::New();
394 detector.Attach(actor);
395 detector.DetectedSignal().Connect(&application, functor);
397 // Start pinch within the actor's area
398 TestStartPinch( application, Vector2( 2.0f, 20.0f ), Vector2( 38.0f, 20.0f ),
399 Vector2( 10.0f, 20.0f ), Vector2( 30.0f, 20.0f ), 100 );
400 DALI_TEST_EQUALS(true, data.functorCalled, TEST_LOCATION);
401 DALI_TEST_EQUALS(GestureState::STARTED, data.receivedGesture.GetState(), TEST_LOCATION);
404 // Continue the pinch within the actor's area - we should still receive the signal
406 TestContinuePinch( application, Vector2( 10.0f, 20.0f ), Vector2( 30.0f, 20.0f ),
407 Vector2( 15.0f, 20.0f ), Vector2( 25.0f, 20.0f ), 500 );
408 DALI_TEST_EQUALS(true, data.functorCalled, TEST_LOCATION);
409 DALI_TEST_EQUALS(GestureState::CONTINUING, data.receivedGesture.GetState(), TEST_LOCATION);
411 // Gesture ends within actor's area
413 TestEndPinch( application, Vector2( 15.0f, 20.0f ), Vector2( 25.0f, 20.0f ),
414 Vector2( 19.0f, 20.0f ), Vector2( 21.0f, 20.0f ), 1000);
415 DALI_TEST_EQUALS(true, data.functorCalled, TEST_LOCATION);
416 DALI_TEST_EQUALS(GestureState::FINISHED, data.receivedGesture.GetState(), TEST_LOCATION);
419 detector.DetachAll();
421 // Ensure we are no longer signalled
423 TestGeneratePinch( application );
424 DALI_TEST_EQUALS(false, data.functorCalled, TEST_LOCATION);
428 int UtcDaliPinchGestureSignalReceptionDetachWhilePinching(void)
430 TestApplication application;
432 Actor actor = Actor::New();
433 actor.SetProperty( Actor::Property::SIZE, Vector2( 100.0f, 100.0f ) );
434 actor.SetProperty( Actor::Property::ANCHOR_POINT,AnchorPoint::TOP_LEFT);
435 application.GetScene().Add(actor);
438 application.SendNotification();
439 application.Render();
442 GestureReceivedFunctor functor(data);
444 PinchGestureDetector detector = PinchGestureDetector::New();
445 detector.Attach(actor);
446 detector.DetectedSignal().Connect(&application, functor);
448 // Start pinch within the actor's area
449 TestStartPinch( application, Vector2( 2.0f, 20.0f ), Vector2( 38.0f, 20.0f ),
450 Vector2( 10.0f, 20.0f ), Vector2( 30.0f, 20.0f ), 100 );
451 DALI_TEST_EQUALS(true, data.functorCalled, TEST_LOCATION);
452 DALI_TEST_EQUALS(GestureState::STARTED, data.receivedGesture.GetState(), TEST_LOCATION);
454 // Continue the pinch within the actor's area - we should still receive the signal
456 TestContinuePinch( application, Vector2( 10.0f, 20.0f ), Vector2( 30.0f, 20.0f ),
457 Vector2( 15.0f, 20.0f ), Vector2( 25.0f, 20.0f ), 500 );
458 DALI_TEST_EQUALS(true, data.functorCalled, TEST_LOCATION);
459 DALI_TEST_EQUALS(GestureState::CONTINUING, data.receivedGesture.GetState(), TEST_LOCATION);
461 // Detach actor during the pinch, we should not receive the next event
462 detector.DetachAll();
464 // Gesture ends within actor's area
466 TestEndPinch( application, Vector2( 15.0f, 20.0f ), Vector2( 25.0f, 20.0f ),
467 Vector2( 19.0f, 20.0f ), Vector2( 21.0f, 20.0f ), 1000);
468 DALI_TEST_EQUALS(false, data.functorCalled, TEST_LOCATION);
472 int UtcDaliPinchGestureSignalReceptionActorDestroyedWhilePinching(void)
474 TestApplication application;
477 GestureReceivedFunctor functor(data);
479 PinchGestureDetector detector = PinchGestureDetector::New();
480 detector.DetectedSignal().Connect(&application, functor);
482 // Attach a temporary actor to stop detector being removed from PinchGestureProcessor when main actor
484 Actor tempActor = Actor::New();
485 tempActor.SetProperty( Actor::Property::SIZE, Vector2( 100.0f, 100.0f ) );
486 tempActor.SetProperty( Actor::Property::ANCHOR_POINT,AnchorPoint::BOTTOM_RIGHT);
487 application.GetScene().Add(tempActor);
488 detector.Attach(tempActor);
490 // Actor lifetime is scoped
492 Actor actor = Actor::New();
493 actor.SetProperty( Actor::Property::SIZE, Vector2( 100.0f, 100.0f ) );
494 actor.SetProperty( Actor::Property::ANCHOR_POINT,AnchorPoint::TOP_LEFT);
495 application.GetScene().Add(actor);
498 application.SendNotification();
499 application.Render();
501 detector.Attach(actor);
503 // Start pinch within the actor's area
504 TestStartPinch( application, Vector2( 2.0f, 20.0f ), Vector2( 38.0f, 20.0f ),
505 Vector2( 10.0f, 20.0f ), Vector2( 30.0f, 20.0f ), 100 );
506 DALI_TEST_EQUALS(true, data.functorCalled, TEST_LOCATION);
507 DALI_TEST_EQUALS(GestureState::STARTED, data.receivedGesture.GetState(), TEST_LOCATION);
509 // Continue the pinch within the actor's area - we should still receive the signal
511 TestContinuePinch( application, Vector2( 10.0f, 20.0f ), Vector2( 30.0f, 20.0f ),
512 Vector2( 15.0f, 20.0f ), Vector2( 25.0f, 20.0f ), 500 );
513 DALI_TEST_EQUALS(true, data.functorCalled, TEST_LOCATION);
514 DALI_TEST_EQUALS(GestureState::CONTINUING, data.receivedGesture.GetState(), TEST_LOCATION);
516 // Remove the actor from stage and reset the data
517 application.GetScene().Remove(actor);
520 application.SendNotification();
521 application.Render();
524 // Actor should now have been destroyed
526 // Gesture ends within the area where the actor used to be
528 TestEndPinch( application, Vector2( 15.0f, 20.0f ), Vector2( 25.0f, 20.0f ),
529 Vector2( 19.0f, 20.0f ), Vector2( 21.0f, 20.0f ), 1000);
530 DALI_TEST_EQUALS(false, data.functorCalled, TEST_LOCATION);
534 int UtcDaliPinchGestureSignalReceptionRotatedActor(void)
536 TestApplication application;
538 Actor actor = Actor::New();
539 actor.SetProperty( Actor::Property::SIZE, Vector2( 100.0f, 100.0f ) );
540 actor.SetProperty( Actor::Property::ORIENTATION, Quaternion(Dali::Degree(90.0f), Vector3::ZAXIS) );
541 application.GetScene().Add(actor);
543 // Render and notify a couple of times
544 application.SendNotification();
545 application.Render();
548 GestureReceivedFunctor functor(data);
550 PinchGestureDetector detector = PinchGestureDetector::New();
551 detector.Attach(actor);
552 detector.DetectedSignal().Connect(&application, functor);
554 // Do an entire pinch, only check finished value
555 TestStartPinch( application, Vector2( 2.0f, 20.0f ), Vector2( 38.0f, 20.0f ),
556 Vector2( 10.0f, 20.0f ), Vector2( 30.0f, 20.0f ), 100 );
558 TestEndPinch( application, Vector2( 15.0f, 20.0f ), Vector2( 25.0f, 20.0f ),
559 Vector2( 19.0f, 20.0f ), Vector2( 21.0f, 20.0f ), 1000);
560 DALI_TEST_EQUALS(true, data.functorCalled, TEST_LOCATION);
561 DALI_TEST_EQUALS(0.055f, data.receivedGesture.GetScale(), 0.01f, TEST_LOCATION);
562 DALI_TEST_EQUALS(160.0f, data.receivedGesture.GetSpeed(), 0.01f, TEST_LOCATION);
563 DALI_TEST_EQUALS(Vector2(20.0f, 20.0f), data.receivedGesture.GetScreenCenterPoint(), 0.01f, TEST_LOCATION);
564 DALI_TEST_EQUALS(Vector2(70.0f, 30.0f), data.receivedGesture.GetLocalCenterPoint(), 0.01f, TEST_LOCATION);
566 // Rotate actor again and render and notify
567 actor.SetProperty( Actor::Property::ORIENTATION, Quaternion(Dali::Degree(180.0f), Vector3::ZAXIS) );
568 application.SendNotification();
569 application.Render();
571 // Do an entire pinch, only check finished value
572 TestStartPinch( application, Vector2( 2.0f, 20.0f ), Vector2( 38.0f, 20.0f ),
573 Vector2( 10.0f, 20.0f ), Vector2( 30.0f, 20.0f ), 2100 );
575 TestEndPinch( application, Vector2( 15.0f, 20.0f ), Vector2( 25.0f, 20.0f ),
576 Vector2( 19.0f, 20.0f ), Vector2( 21.0f, 20.0f ), 3000);
577 DALI_TEST_EQUALS(true, data.functorCalled, TEST_LOCATION);
578 DALI_TEST_EQUALS(0.055f, data.receivedGesture.GetScale(), 0.01f, TEST_LOCATION);
579 DALI_TEST_EQUALS(160.0f, data.receivedGesture.GetSpeed(), 0.01f, TEST_LOCATION);
580 DALI_TEST_EQUALS(Vector2(20.0f, 20.0f), data.receivedGesture.GetScreenCenterPoint(), 0.01f, TEST_LOCATION);
581 DALI_TEST_EQUALS(Vector2(30.0f, 30.0f), data.receivedGesture.GetLocalCenterPoint(), 0.01f, TEST_LOCATION);
583 // Rotate actor again and render and notify
584 actor.SetProperty( Actor::Property::ORIENTATION, Quaternion(Dali::Degree(270.0f), Vector3::ZAXIS) );
585 application.SendNotification();
586 application.Render();
588 // Do an entire pinch, only check finished value
589 TestStartPinch( application, Vector2( 2.0f, 20.0f ), Vector2( 38.0f, 20.0f ),
590 Vector2( 10.0f, 20.0f ), Vector2( 30.0f, 20.0f ), 4100 );
592 TestEndPinch( application, Vector2( 15.0f, 20.0f ), Vector2( 25.0f, 20.0f ),
593 Vector2( 19.0f, 20.0f ), Vector2( 21.0f, 20.0f ), 5000);
594 DALI_TEST_EQUALS(true, data.functorCalled, TEST_LOCATION);
595 DALI_TEST_EQUALS(0.055f, data.receivedGesture.GetScale(), 0.01f, TEST_LOCATION);
596 DALI_TEST_EQUALS(160.0f, data.receivedGesture.GetSpeed(), 0.01f, TEST_LOCATION);
597 DALI_TEST_EQUALS(Vector2(20.0f, 20.0f), data.receivedGesture.GetScreenCenterPoint(), 0.01f, TEST_LOCATION);
598 DALI_TEST_EQUALS(Vector2(30.0f, 70.0f), data.receivedGesture.GetLocalCenterPoint(), 0.01f, TEST_LOCATION);
602 int UtcDaliPinchGestureSignalReceptionChildHit(void)
604 TestApplication application;
606 Actor parent = Actor::New();
607 parent.SetProperty( Actor::Property::SIZE, Vector2( 100.0f, 100.0f ) );
608 parent.SetProperty( Actor::Property::ANCHOR_POINT,AnchorPoint::TOP_LEFT);
609 application.GetScene().Add(parent);
611 // Set child to completely cover parent.
612 // Change rotation of child to be different from parent so that we can check if our local coordinate
613 // conversion of the parent actor is correct.
614 Actor child = Actor::New();
615 child.SetProperty( Actor::Property::SIZE, Vector2( 100.0f, 100.0f ) );
616 child.SetProperty( Actor::Property::ANCHOR_POINT,AnchorPoint::CENTER);
617 child.SetProperty( Actor::Property::PARENT_ORIGIN,ParentOrigin::CENTER);
618 child.SetProperty( Actor::Property::ORIENTATION, Quaternion(Dali::Degree(90.0f), Vector3::ZAXIS) );
622 application.SendNotification();
623 application.Render();
626 GestureReceivedFunctor functor(data);
628 PinchGestureDetector detector = PinchGestureDetector::New();
629 detector.Attach(parent);
630 detector.DetectedSignal().Connect(&application, functor);
632 // Do an entire pan, only check finished value - hits child area but parent should still receive it
633 TestStartPinch( application, Vector2( 2.0f, 20.0f ), Vector2( 38.0f, 20.0f ),
634 Vector2( 10.0f, 20.0f ), Vector2( 30.0f, 20.0f ), 100 );
636 TestEndPinch( application, Vector2( 15.0f, 20.0f ), Vector2( 25.0f, 20.0f ),
637 Vector2( 19.0f, 20.0f ), Vector2( 21.0f, 20.0f ), 1000);
638 DALI_TEST_EQUALS(true, data.functorCalled, TEST_LOCATION);
639 DALI_TEST_EQUALS(true, parent == data.pinchedActor, TEST_LOCATION);
640 DALI_TEST_EQUALS(0.055f, data.receivedGesture.GetScale(), 0.01f, TEST_LOCATION);
641 DALI_TEST_EQUALS(160.0f, data.receivedGesture.GetSpeed(), 0.01f, TEST_LOCATION);
642 DALI_TEST_EQUALS(Vector2(20.0f, 20.0f), data.receivedGesture.GetScreenCenterPoint(), 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 TestStartPinch( application, Vector2( 2.0f, 20.0f ), Vector2( 38.0f, 20.0f ),
651 Vector2( 10.0f, 20.0f ), Vector2( 30.0f, 20.0f ), 2100 );
653 TestEndPinch( application, Vector2( 15.0f, 20.0f ), Vector2( 25.0f, 20.0f ),
654 Vector2( 19.0f, 20.0f ), Vector2( 21.0f, 20.0f ), 3000);
655 DALI_TEST_EQUALS(true, data.functorCalled, TEST_LOCATION);
656 DALI_TEST_EQUALS(true, child == data.pinchedActor, TEST_LOCATION);
657 DALI_TEST_EQUALS(0.055f, data.receivedGesture.GetScale(), 0.01f, TEST_LOCATION);
658 DALI_TEST_EQUALS(160.0f, data.receivedGesture.GetSpeed(), 0.01f, TEST_LOCATION);
659 DALI_TEST_EQUALS(Vector2(20.0f, 20.0f), data.receivedGesture.GetScreenCenterPoint(), 0.01f, TEST_LOCATION);
660 DALI_TEST_EQUALS(Vector2(20.0f, 80.0f), data.receivedGesture.GetLocalCenterPoint(), 0.01f, TEST_LOCATION);
664 int UtcDaliPinchGestureSignalReceptionAttachDetachMany(void)
666 TestApplication application;
668 Actor first = Actor::New();
669 first.SetProperty( Actor::Property::SIZE, Vector2( 100.0f, 100.0f ) );
670 first.SetProperty( Actor::Property::ANCHOR_POINT,AnchorPoint::TOP_LEFT);
671 application.GetScene().Add(first);
673 Actor second = Actor::New();
674 second.SetProperty( Actor::Property::SIZE, Vector2( 100.0f, 100.0f ) );
675 second.SetProperty( Actor::Property::POSITION_X, 100.0f);
676 second.SetProperty( Actor::Property::ANCHOR_POINT,AnchorPoint::TOP_LEFT);
677 application.GetScene().Add(second);
680 application.SendNotification();
681 application.Render();
684 GestureReceivedFunctor functor(data);
686 PinchGestureDetector detector = PinchGestureDetector::New();
687 detector.Attach(first);
688 detector.Attach(second);
689 detector.DetectedSignal().Connect(&application, functor);
691 // Start pinch within second actor's area
692 TestStartPinch( application, Vector2( 102.0f, 20.0f ), Vector2( 138.0f, 20.0f ),
693 Vector2( 110.0f, 20.0f ), Vector2( 130.0f, 20.0f ), 100 );
694 DALI_TEST_EQUALS(true, data.functorCalled, TEST_LOCATION);
695 DALI_TEST_EQUALS(true, second == data.pinchedActor, TEST_LOCATION);
697 // Pinch moves into first actor's area - second actor should receive the pinch
699 TestContinuePinch( application, Vector2( 110.0f, 20.0f ), Vector2( 130.0f, 20.0f ),
700 Vector2( 15.0f, 20.0f ), Vector2( 25.0f, 20.0f ), 500 );
701 DALI_TEST_EQUALS(true, data.functorCalled, TEST_LOCATION);
702 DALI_TEST_EQUALS(true, second == data.pinchedActor, TEST_LOCATION);
704 // Detach the second actor during the pinch, we should not receive the next event
705 detector.Detach(second);
707 // Gesture ends within actor's area
709 TestEndPinch( application, Vector2( 15.0f, 20.0f ), Vector2( 25.0f, 20.0f ),
710 Vector2( 119.0f, 20.0f ), Vector2( 121.0f, 20.0f ), 3000);
711 DALI_TEST_EQUALS(false, data.functorCalled, TEST_LOCATION);
715 int UtcDaliPinchGestureSignalReceptionActorBecomesUntouchable(void)
717 TestApplication application;
719 Actor actor = Actor::New();
720 actor.SetProperty( Actor::Property::SIZE, Vector2( 100.0f, 100.0f ) );
721 actor.SetProperty( Actor::Property::ANCHOR_POINT,AnchorPoint::TOP_LEFT);
722 application.GetScene().Add(actor);
725 application.SendNotification();
726 application.Render();
729 GestureReceivedFunctor functor(data);
731 PinchGestureDetector detector = PinchGestureDetector::New();
732 detector.Attach(actor);
733 detector.DetectedSignal().Connect(&application, functor);
735 // Start pinch in actor's area
736 TestStartPinch( application, Vector2( 2.0f, 20.0f ), Vector2( 38.0f, 20.0f ),
737 Vector2( 10.0f, 20.0f ), Vector2( 30.0f, 20.0f ), 100 );
738 DALI_TEST_EQUALS(true, data.functorCalled, TEST_LOCATION);
740 // Pan continues within actor's area
742 TestContinuePinch( application, Vector2( 10.0f, 20.0f ), Vector2( 30.0f, 20.0f ),
743 Vector2( 15.0f, 20.0f ), Vector2( 25.0f, 20.0f ), 500 );
744 DALI_TEST_EQUALS(true, data.functorCalled, TEST_LOCATION);
746 // Actor become invisible - actor should not receive the next pinch
747 actor.SetProperty( Actor::Property::VISIBLE,false);
750 application.SendNotification();
751 application.Render();
753 // Gesture ends within actor's area
755 TestEndPinch( application, Vector2( 15.0f, 20.0f ), Vector2( 25.0f, 20.0f ),
756 Vector2( 19.0f, 20.0f ), Vector2( 21.0f, 20.0f ), 3000);
757 DALI_TEST_EQUALS(false, data.functorCalled, TEST_LOCATION);
761 int UtcDaliPinchGestureSignalReceptionMultipleDetectorsOnActor(void)
763 TestApplication application;
765 Actor actor = Actor::New();
766 actor.SetProperty( Actor::Property::SIZE, Vector2( 100.0f, 100.0f ) );
767 actor.SetProperty( Actor::Property::ANCHOR_POINT,AnchorPoint::TOP_LEFT);
768 application.GetScene().Add(actor);
770 Actor actor2 = Actor::New();
771 actor2.SetProperty( Actor::Property::SIZE, Vector2( 100.0f, 100.0f ) );
772 actor2.SetProperty( Actor::Property::ANCHOR_POINT,AnchorPoint::BOTTOM_RIGHT);
773 application.GetScene().Add(actor2);
776 application.SendNotification();
777 application.Render();
779 // Attach actor to one detector
780 SignalData firstData;
781 GestureReceivedFunctor firstFunctor(firstData);
782 PinchGestureDetector firstDetector = PinchGestureDetector::New();
783 firstDetector.Attach(actor);
784 firstDetector.DetectedSignal().Connect(&application, firstFunctor);
786 // Attach actor to another detector
787 SignalData secondData;
788 GestureReceivedFunctor secondFunctor(secondData);
789 PinchGestureDetector secondDetector = PinchGestureDetector::New();
790 secondDetector.Attach(actor);
791 secondDetector.DetectedSignal().Connect(&application, secondFunctor);
793 // Add second actor to second detector, when we remove the actor, this will make sure that this
794 // gesture detector is not removed from the GestureDetectorProcessor. In this scenario, the
795 // functor should still not be called (which is what we're also testing).
796 secondDetector.Attach(actor2);
798 // Pinch in actor's area - both detector's functors should be called
799 TestStartPinch( application, Vector2( 2.0f, 20.0f ), Vector2( 38.0f, 20.0f ),
800 Vector2( 10.0f, 20.0f ), Vector2( 30.0f, 20.0f ), 100 );
801 DALI_TEST_EQUALS(true, firstData.functorCalled, TEST_LOCATION);
802 DALI_TEST_EQUALS(true, secondData.functorCalled, TEST_LOCATION);
804 // Pinch continues in actor's area - both detector's functors should be called
807 TestContinuePinch( application, Vector2( 10.0f, 20.0f ), Vector2( 30.0f, 20.0f ),
808 Vector2( 15.0f, 20.0f ), Vector2( 25.0f, 20.0f ), 500 );
809 DALI_TEST_EQUALS(true, firstData.functorCalled, TEST_LOCATION);
810 DALI_TEST_EQUALS(true, secondData.functorCalled, TEST_LOCATION);
812 // Detach actor from firstDetector and emit pinch on actor, only secondDetector's functor should be called.
813 firstDetector.Detach(actor);
816 TestEndPinch( application, Vector2( 15.0f, 20.0f ), Vector2( 25.0f, 20.0f ),
817 Vector2( 19.0f, 20.0f ), Vector2( 21.0f, 20.0f ), 1000);
818 DALI_TEST_EQUALS(false, firstData.functorCalled, TEST_LOCATION);
819 DALI_TEST_EQUALS(true, secondData.functorCalled, TEST_LOCATION);
821 // New pinch on actor, only secondDetector has actor attached
824 TestStartPinch( application, Vector2( 2.0f, 20.0f ), Vector2( 38.0f, 20.0f ),
825 Vector2( 10.0f, 20.0f ), Vector2( 30.0f, 20.0f ), 1500 );
826 DALI_TEST_EQUALS(false, firstData.functorCalled, TEST_LOCATION);
827 DALI_TEST_EQUALS(true, secondData.functorCalled, TEST_LOCATION);
829 // Detach actor from secondDetector
830 secondDetector.Detach(actor);
833 TestContinuePinch( application, Vector2( 10.0f, 20.0f ), Vector2( 30.0f, 20.0f ),
834 Vector2( 15.0f, 20.0f ), Vector2( 25.0f, 20.0f ), 2000 );
835 DALI_TEST_EQUALS(false, firstData.functorCalled, TEST_LOCATION);
836 DALI_TEST_EQUALS(false, secondData.functorCalled, TEST_LOCATION);
840 int UtcDaliPinchGestureSignalReceptionEnsureCorrectSignalling(void)
842 TestApplication application;
844 Actor actor1 = Actor::New();
845 actor1.SetProperty( Actor::Property::SIZE, Vector2( 100.0f, 100.0f ) );
846 actor1.SetProperty( Actor::Property::ANCHOR_POINT,AnchorPoint::TOP_LEFT);
847 application.GetScene().Add(actor1);
849 GestureReceivedFunctor functor1(data1);
850 PinchGestureDetector detector1 = PinchGestureDetector::New();
851 detector1.Attach(actor1);
852 detector1.DetectedSignal().Connect(&application, functor1);
854 Actor actor2 = Actor::New();
855 actor2.SetProperty( Actor::Property::SIZE, Vector2( 100.0f, 100.0f ) );
856 actor2.SetProperty( Actor::Property::ANCHOR_POINT,AnchorPoint::BOTTOM_RIGHT);
857 actor2.SetProperty( Actor::Property::PARENT_ORIGIN,ParentOrigin::BOTTOM_RIGHT);
858 application.GetScene().Add(actor2);
860 GestureReceivedFunctor functor2(data2);
861 PinchGestureDetector detector2 = PinchGestureDetector::New();
862 detector2.Attach(actor2);
863 detector2.DetectedSignal().Connect(&application, functor2);
866 application.SendNotification();
867 application.Render();
869 // Start pan in actor1's area, only data1 should be set
870 TestStartPinch( application, Vector2( 2.0f, 20.0f ), Vector2( 38.0f, 20.0f ),
871 Vector2( 10.0f, 20.0f ), Vector2( 30.0f, 20.0f ), 100 );
872 DALI_TEST_EQUALS(true, data1.functorCalled, TEST_LOCATION);
873 DALI_TEST_EQUALS(false, data2.functorCalled, TEST_LOCATION);
877 int UtcDaliPinchGestureActorUnstaged(void)
879 TestApplication application;
881 Actor actor = Actor::New();
882 actor.SetProperty( Actor::Property::SIZE, Vector2( 100.0f, 100.0f ) );
883 actor.SetProperty( Actor::Property::ANCHOR_POINT,AnchorPoint::TOP_LEFT);
884 application.GetScene().Add(actor);
887 application.SendNotification();
888 application.Render();
890 // State to remove actor in.
891 GestureState stateToUnstage( GestureState::STARTED );
893 // Attach actor to detector
895 UnstageActorFunctor functor( data, stateToUnstage, application.GetScene() );
896 PinchGestureDetector detector = PinchGestureDetector::New();
897 detector.Attach(actor);
898 detector.DetectedSignal().Connect( &application, functor );
901 TestStartPinch( application, Vector2( 2.0f, 20.0f ), Vector2( 38.0f, 20.0f ),
902 Vector2( 10.0f, 20.0f ), Vector2( 30.0f, 20.0f ), 100 );
903 DALI_TEST_EQUALS(true, data.functorCalled, TEST_LOCATION);
905 TestEndPinch( application, Vector2( 10.0f, 20.0f ), Vector2( 30.0f, 20.0f ),
906 Vector2( 19.0f, 20.0f ), Vector2( 21.0f, 20.0f ), 1000);
907 DALI_TEST_EQUALS(false, data.functorCalled, TEST_LOCATION);
911 application.SendNotification();
912 application.Render();
914 // Re-add actor to stage
915 application.GetScene().Add(actor);
918 application.SendNotification();
919 application.Render();
921 // Change state to GestureState::CONTINUING to remove
922 stateToUnstage = GestureState::CONTINUING;
925 TestStartPinch( application, Vector2( 2.0f, 20.0f ), Vector2( 38.0f, 20.0f ),
926 Vector2( 10.0f, 20.0f ), Vector2( 30.0f, 20.0f ), 100 );
927 DALI_TEST_EQUALS(true, data.functorCalled, TEST_LOCATION);
929 TestContinuePinch( application, Vector2( 10.0f, 20.0f ), Vector2( 30.0f, 20.0f ),
930 Vector2( 15.0f, 20.0f ), Vector2( 25.0f, 20.0f ), 500 );
931 DALI_TEST_EQUALS(true, data.functorCalled, TEST_LOCATION);
933 TestEndPinch( application, Vector2( 10.0f, 20.0f ), Vector2( 30.0f, 20.0f ),
934 Vector2( 19.0f, 20.0f ), Vector2( 21.0f, 20.0f ), 1000);
935 DALI_TEST_EQUALS(false, data.functorCalled, TEST_LOCATION);
939 application.SendNotification();
940 application.Render();
942 // Re-add actor to stage
943 application.GetScene().Add(actor);
946 application.SendNotification();
947 application.Render();
949 // Change state to GestureState::CONTINUING to remove
950 stateToUnstage = GestureState::FINISHED;
953 TestStartPinch( application, Vector2( 2.0f, 20.0f ), Vector2( 38.0f, 20.0f ),
954 Vector2( 10.0f, 20.0f ), Vector2( 30.0f, 20.0f ), 100 );
955 DALI_TEST_EQUALS(true, data.functorCalled, TEST_LOCATION);
957 TestContinuePinch( application, Vector2( 10.0f, 20.0f ), Vector2( 30.0f, 20.0f ),
958 Vector2( 15.0f, 20.0f ), Vector2( 25.0f, 20.0f ), 500 );
959 DALI_TEST_EQUALS(true, data.functorCalled, TEST_LOCATION);
961 TestEndPinch( application, Vector2( 10.0f, 20.0f ), Vector2( 30.0f, 20.0f ),
962 Vector2( 19.0f, 20.0f ), Vector2( 21.0f, 20.0f ), 1000);
963 DALI_TEST_EQUALS(true, data.functorCalled, TEST_LOCATION);
964 tet_result( TET_PASS ); // If we get here then we have handled actor stage removal gracefully.
968 int UtcDaliPinchGestureActorStagedAndDestroyed(void)
970 TestApplication application;
972 Actor actor = Actor::New();
973 actor.SetProperty( Actor::Property::SIZE, Vector2( 100.0f, 100.0f ) );
974 actor.SetProperty( Actor::Property::ANCHOR_POINT,AnchorPoint::TOP_LEFT);
975 application.GetScene().Add(actor);
977 // Create and add a second actor so that GestureDetector destruction does not come into play.
978 Actor dummyActor( Actor::New() );
979 dummyActor.SetProperty( Actor::Property::SIZE, Vector2( 100.0f, 100.0f ) );
980 dummyActor.SetProperty( Actor::Property::POSITION, Vector2( 100.0f, 100.0f ));
981 dummyActor.SetProperty( Actor::Property::ANCHOR_POINT,AnchorPoint::TOP_LEFT);
982 application.GetScene().Add(dummyActor);
985 application.SendNotification();
986 application.Render();
988 // State to remove actor in.
989 GestureState stateToUnstage( GestureState::STARTED );
991 // Attach actor to detector
993 UnstageActorFunctor functor( data, stateToUnstage, application.GetScene() );
994 PinchGestureDetector detector = PinchGestureDetector::New();
995 detector.Attach(actor);
996 detector.Attach(dummyActor);
997 detector.DetectedSignal().Connect( &application, functor );
999 // Here we are testing a STARTED actor which is removed in the STARTED callback, but then added back
1000 // before we get a continuing state. As we were removed from the stage, even if we're at the same
1001 // position, we should still not be signalled.
1004 TestStartPinch( application, Vector2( 2.0f, 20.0f ), Vector2( 38.0f, 20.0f ),
1005 Vector2( 10.0f, 20.0f ), Vector2( 30.0f, 20.0f ), 100 );
1006 DALI_TEST_EQUALS(true, data.functorCalled, TEST_LOCATION);
1009 // Render and notify
1010 application.SendNotification();
1011 application.Render();
1013 // Re add to the stage, we should not be signalled
1014 application.GetScene().Add(actor);
1016 // Render and notify
1017 application.SendNotification();
1018 application.Render();
1020 // Continue signal emission
1021 TestContinuePinch( application, Vector2( 10.0f, 20.0f ), Vector2( 30.0f, 20.0f ),
1022 Vector2( 15.0f, 20.0f ), Vector2( 25.0f, 20.0f ), 500 );
1023 DALI_TEST_EQUALS(false, data.functorCalled, TEST_LOCATION);
1025 TestEndPinch( application, Vector2( 10.0f, 20.0f ), Vector2( 30.0f, 20.0f ),
1026 Vector2( 19.0f, 20.0f ), Vector2( 21.0f, 20.0f ), 1000);
1027 DALI_TEST_EQUALS(false, data.functorCalled, TEST_LOCATION);
1030 // Here we delete an actor in started, we should not receive any subsequent signalling.
1033 TestStartPinch( application, Vector2( 2.0f, 20.0f ), Vector2( 38.0f, 20.0f ),
1034 Vector2( 10.0f, 20.0f ), Vector2( 30.0f, 20.0f ), 1500 );
1035 DALI_TEST_EQUALS(true, data.functorCalled, TEST_LOCATION);
1038 // Render and notify
1039 application.SendNotification();
1040 application.Render();
1042 // Delete actor as well
1045 // Render and notify
1046 application.SendNotification();
1047 application.Render();
1049 // Continue signal emission
1050 TestContinuePinch( application, Vector2( 10.0f, 20.0f ), Vector2( 30.0f, 20.0f ),
1051 Vector2( 15.0f, 20.0f ), Vector2( 25.0f, 20.0f ), 2000 );
1052 DALI_TEST_EQUALS(false, data.functorCalled, TEST_LOCATION);
1054 TestEndPinch( application, Vector2( 10.0f, 20.0f ), Vector2( 30.0f, 20.0f ),
1055 Vector2( 19.0f, 20.0f ), Vector2( 21.0f, 20.0f ), 3000);
1056 DALI_TEST_EQUALS(false, data.functorCalled, TEST_LOCATION);
1060 int UtcDaliPinchGestureLayerConsumesTouch(void)
1062 TestApplication application;
1064 Actor actor = Actor::New();
1065 actor.SetProperty( Actor::Property::SIZE, Vector2( 100.0f, 100.0f ) );
1066 actor.SetProperty( Actor::Property::ANCHOR_POINT,AnchorPoint::TOP_LEFT);
1067 application.GetScene().Add(actor);
1071 GestureReceivedFunctor functor(data);
1072 PinchGestureDetector detector = PinchGestureDetector::New();
1073 detector.Attach(actor);
1074 detector.DetectedSignal().Connect( &application, functor );
1076 // Add a layer to overlap the actor
1077 Layer layer = Layer::New();
1078 layer.SetProperty( Actor::Property::SIZE, Vector2( 100.0f, 100.0f ) );
1079 layer.SetProperty( Actor::Property::ANCHOR_POINT,AnchorPoint::TOP_LEFT);
1080 application.GetScene().Add( layer );
1083 // Render and notify
1084 application.SendNotification();
1085 application.Render();
1087 // Emit signals, should receive
1088 TestStartPinch( application, Vector2( 2.0f, 20.0f ), Vector2( 38.0f, 20.0f ),
1089 Vector2( 10.0f, 20.0f ), Vector2( 30.0f, 20.0f ), 100 );
1090 TestEndPinch( application, Vector2( 10.0f, 20.0f ), Vector2( 30.0f, 20.0f ),
1091 Vector2( 19.0f, 20.0f ), Vector2( 21.0f, 20.0f ), 1000);
1092 DALI_TEST_EQUALS(true, data.functorCalled, TEST_LOCATION);
1095 // Set layer to consume all touch
1096 layer.SetProperty( Layer::Property::CONSUMES_TOUCH, true );
1098 // Render and notify
1099 application.SendNotification();
1100 application.Render();
1102 // Emit the same signals again, should not receive
1103 TestStartPinch( application, Vector2( 2.0f, 20.0f ), Vector2( 38.0f, 20.0f ),
1104 Vector2( 10.0f, 20.0f ), Vector2( 30.0f, 20.0f ), 1500 );
1105 TestEndPinch( application, Vector2( 10.0f, 20.0f ), Vector2( 30.0f, 20.0f ),
1106 Vector2( 19.0f, 20.0f ), Vector2( 21.0f, 20.0f ), 2000);
1107 DALI_TEST_EQUALS(false, data.functorCalled, TEST_LOCATION);
1113 int UtcDaliPinchGestureInterruptedWhenTouchConsumed(void)
1115 TestApplication application;
1117 Actor actor = Actor::New();
1118 actor.SetProperty( Actor::Property::SIZE, Vector2( 100.0f, 100.0f ) );
1119 actor.SetProperty( Actor::Property::ANCHOR_POINT,AnchorPoint::TOP_LEFT);
1120 application.GetScene().Add(actor);
1122 bool consume = false;
1123 TouchEventFunctorConsumeSetter touchFunctor(consume);
1124 actor.TouchedSignal().Connect(&application,touchFunctor);
1126 // Render and notify
1127 application.SendNotification();
1128 application.Render();
1131 GestureReceivedFunctor functor(data);
1133 PinchGestureDetector detector = PinchGestureDetector::New();
1134 detector.Attach(actor);
1135 detector.DetectedSignal().Connect(&application, functor);
1137 // Start gesture within the actor's area, we should receive the pinch as the touch is NOT being consumed
1138 TestStartPinch( application, Vector2( 2.0f, 20.0f ), Vector2( 38.0f, 20.0f ),
1139 Vector2( 10.0f, 20.0f ), Vector2( 30.0f, 20.0f ), 100 );
1141 DALI_TEST_EQUALS(true, data.functorCalled, TEST_LOCATION);
1142 DALI_TEST_EQUALS(GestureState::STARTED, data.receivedGesture.GetState(), TEST_LOCATION);
1145 // Continue the gesture within the actor's area, but now the touch consumes thus cancelling the gesture
1148 TestContinuePinch( application, Vector2( 112.0f, 100.0f ), Vector2( 112.0f, 124.0f ),
1149 Vector2( 5.0f, 5.0f ), Vector2( 35.0f, 35.0f ), 200 );
1151 DALI_TEST_EQUALS(true, data.functorCalled, TEST_LOCATION);
1152 DALI_TEST_EQUALS(GestureState::CANCELLED, data.receivedGesture.GetState(), TEST_LOCATION);
1155 // Start another pinch, we should not even get the callback this time
1156 TestStartPinch( application, Vector2( 2.0f, 20.0f ), Vector2( 38.0f, 20.0f ),
1157 Vector2( 10.0f, 20.0f ), Vector2( 30.0f, 20.0f ), 100 );
1158 DALI_TEST_EQUALS(false, data.functorCalled, TEST_LOCATION);
1164 int UtcDaliPinchGestureDisableDetectionDuringPinchN(void)
1166 // Crash sometimes occurred when gesture-recognizer was deleted internally during a signal when the attached actor was detached
1168 TestApplication application;
1170 Actor actor = Actor::New();
1171 actor.SetProperty( Actor::Property::SIZE, Vector2( 100.0f, 100.0f ) );
1172 actor.SetProperty( Actor::Property::ANCHOR_POINT,AnchorPoint::TOP_LEFT);
1173 application.GetScene().Add(actor);
1176 PinchGestureDetector detector = PinchGestureDetector::New();
1177 bool functorCalled = false;
1178 detector.Attach( actor );
1179 detector.DetectedSignal().Connect(
1181 [&detector, &functorCalled](Actor actor, const PinchGesture& gesture)
1183 if( gesture.GetState() == GestureState::FINISHED )
1185 detector.Detach(actor);
1186 functorCalled = true;
1190 // Render and notify
1191 application.SendNotification();
1192 application.Render();
1194 // Try the gesture, should not crash
1197 TestStartPinch( application, Vector2( 2.0f, 20.0f ), Vector2( 38.0f, 20.0f ),
1198 Vector2( 10.0f, 20.0f ), Vector2( 30.0f, 20.0f ), 100 );
1199 TestContinuePinch( application, Vector2( 112.0f, 100.0f ), Vector2( 112.0f, 124.0f ),
1200 Vector2( 5.0f, 5.0f ), Vector2( 35.0f, 35.0f ), 200 );
1201 TestEndPinch( application, Vector2( 10.0f, 20.0f ), Vector2( 30.0f, 20.0f ),
1202 Vector2( 19.0f, 20.0f ), Vector2( 21.0f, 20.0f ), 1000);
1204 DALI_TEST_CHECK( true ); // No crash, test has passed
1205 DALI_TEST_EQUALS(functorCalled, true, TEST_LOCATION);
1209 DALI_TEST_CHECK( false ); // If we crash, the test has failed