00eb27079969fcf09dc7e8f2dc6d1392685c0f81
[platform/core/uifw/dali-core.git] / automated-tests / src / dali / utc-Dali-RotationGestureDetector.cpp
1 /*
2  * Copyright (c) 2020 Samsung Electronics Co., Ltd.
3  *
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
7  *
8  * http://www.apache.org/licenses/LICENSE-2.0
9  *
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.
15  *
16  */
17
18 #include <iostream>
19
20 #include <stdlib.h>
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/devel-api/events/gesture-devel.h>
25 #include <dali/devel-api/events/rotation-gesture.h>
26 #include <dali/devel-api/events/rotation-gesture-detector.h>
27 #include <dali-test-suite-utils.h>
28 #include <test-touch-utils.h>
29 #include <test-touch-data-utils.h>
30
31 using namespace Dali;
32
33 void utc_dali_rotation_gesture_detector_startup(void)
34 {
35   test_return_value = TET_UNDEF;
36 }
37
38 void utc_dali_rotation_gesture_detector_cleanup(void)
39 {
40   test_return_value = TET_PASS;
41 }
42
43 ///////////////////////////////////////////////////////////////////////////////
44 namespace
45 {
46
47 // Stores data that is populated in the callback and will be read by the TET cases
48 struct SignalData
49 {
50   SignalData()
51   : functorCalled(false),
52     voidFunctorCalled(false),
53     receivedGesture(Gesture::Started)
54   {}
55
56   void Reset()
57   {
58     functorCalled = false;
59     voidFunctorCalled = false;
60
61     receivedGesture.state = Gesture::Started;
62     receivedGesture.rotation = 0.0f;
63     receivedGesture.screenCenterPoint = Vector2(0.0f, 0.0f);
64     receivedGesture.localCenterPoint = Vector2(0.0f, 0.0f);
65
66     rotatedActor.Reset();
67   }
68
69   bool functorCalled;
70   bool voidFunctorCalled;
71   RotationGesture receivedGesture;
72   Actor rotatedActor;
73 };
74
75 // Functor that sets the data when called
76 struct GestureReceivedFunctor
77 {
78   GestureReceivedFunctor(SignalData& data) : signalData(data) { }
79
80   void operator()(Actor actor, const RotationGesture& rotation)
81   {
82     signalData.functorCalled = true;
83     signalData.receivedGesture = rotation;
84     signalData.rotatedActor = actor;
85   }
86
87   void operator()()
88   {
89     signalData.voidFunctorCalled = true;
90   }
91
92   SignalData& signalData;
93 };
94
95 // Functor that removes the gestured actor from stage
96 struct UnstageActorFunctor : public GestureReceivedFunctor
97 {
98   UnstageActorFunctor( SignalData& data, Gesture::State& stateToUnstage, Integration::Scene scene )
99   : GestureReceivedFunctor( data ),
100     stateToUnstage( stateToUnstage ),
101     scene( scene )
102   {
103   }
104
105   void operator()( Actor actor, const RotationGesture& rotation )
106   {
107     GestureReceivedFunctor::operator()( actor, rotation );
108
109     if ( rotation.state == stateToUnstage )
110     {
111       scene.Remove( actor );
112     }
113   }
114
115   Gesture::State& stateToUnstage;
116   Integration::Scene scene;
117 };
118
119 // Functor for receiving a touch event
120 struct TouchEventFunctor
121 {
122   bool operator()(Actor actor, const TouchEvent& touch)
123   {
124     return false;
125   }
126 };
127
128 } // anon namespace
129
130 ///////////////////////////////////////////////////////////////////////////////
131
132 int UtcDaliRotationGestureDetectorConstructor(void)
133 {
134   TestApplication application;
135
136   RotationGestureDetector detector;
137   DALI_TEST_CHECK(!detector);
138   END_TEST;
139 }
140
141 int UtcDaliRotationGestureDetectorCopyConstructorP(void)
142 {
143   TestApplication application;
144
145   RotationGestureDetector detector = RotationGestureDetector::New();;
146
147   RotationGestureDetector copy( detector );
148   DALI_TEST_CHECK( detector );
149   END_TEST;
150 }
151
152 int UtcDaliRotationGestureDetectorAssignmentOperatorP(void)
153 {
154   TestApplication application;
155
156   RotationGestureDetector detector = RotationGestureDetector::New();;
157
158   RotationGestureDetector assign;
159   assign = detector;
160   DALI_TEST_CHECK( detector );
161
162   DALI_TEST_CHECK( detector == assign );
163   END_TEST;
164 }
165
166 int UtcDaliRotationGestureDetectorNew(void)
167 {
168   TestApplication application;
169
170   RotationGestureDetector detector = RotationGestureDetector::New();
171
172   DALI_TEST_CHECK(detector);
173
174   // Attach an actor and emit a touch event on the actor to ensure complete line coverage
175   Actor actor = Actor::New();
176   actor.SetProperty( Actor::Property::SIZE, Vector2( 100.0f, 100.0f ) );
177   actor.SetProperty( Actor::Property::ANCHOR_POINT,AnchorPoint::TOP_LEFT);
178   application.GetScene().Add(actor);
179
180   // Render and notify
181   application.SendNotification();
182   application.Render();
183
184   detector.Attach(actor);
185
186   Integration::TouchEvent touchEvent(1);
187   Integration::Point point;
188   point.SetDeviceId( 1 );
189   point.SetState( PointState::DOWN );
190   point.SetScreenPosition( Vector2( 20.0f, 20.0f ) );
191   touchEvent.AddPoint(point);
192   application.ProcessEvent(touchEvent);
193
194   Integration::Point point2;
195   point.SetDeviceId( 1 );
196   point.SetState( PointState::DOWN );
197   point.SetScreenPosition( Vector2( 20.0f, 20.0f ) );
198   touchEvent.AddPoint(point2);
199   application.ProcessEvent(touchEvent);
200   END_TEST;
201 }
202
203 int UtcDaliRotationGestureDetectorDownCast(void)
204 {
205   TestApplication application;
206   tet_infoline("Testing Dali::RotationGestureDetector::DownCast()");
207
208   RotationGestureDetector detector = RotationGestureDetector::New();
209
210   BaseHandle object(detector);
211
212   RotationGestureDetector detector2 = RotationGestureDetector::DownCast(object);
213   DALI_TEST_CHECK(detector2);
214
215   RotationGestureDetector detector3 = DownCast< RotationGestureDetector >(object);
216   DALI_TEST_CHECK(detector3);
217
218   BaseHandle unInitializedObject;
219   RotationGestureDetector detector4 = RotationGestureDetector::DownCast(unInitializedObject);
220   DALI_TEST_CHECK(!detector4);
221
222   RotationGestureDetector detector5 = DownCast< RotationGestureDetector >(unInitializedObject);
223   DALI_TEST_CHECK(!detector5);
224
225   GestureDetector detector6 = RotationGestureDetector::New();
226   RotationGestureDetector detector7 = RotationGestureDetector::DownCast(detector6);
227   DALI_TEST_CHECK(detector7);
228   END_TEST;
229 }
230
231 // Negative test case for a method
232 int UtcDaliRotationGestureSignalReceptionNegative(void)
233 {
234   TestApplication application;
235
236   Actor actor = Actor::New();
237   actor.SetProperty( Actor::Property::SIZE, Vector2( 100.0f, 100.0f ) );
238   actor.SetProperty( Actor::Property::ANCHOR_POINT,AnchorPoint::TOP_LEFT);
239   application.GetScene().Add(actor);
240
241   // Render and notify
242   application.SendNotification();
243   application.Render();
244
245   SignalData data;
246   GestureReceivedFunctor functor(data);
247
248   RotationGestureDetector detector = RotationGestureDetector::New();
249   detector.Attach(actor);
250   detector.DetectedSignal().Connect(&application, functor);
251
252   // Do a rotation outside actor's area
253   TestStartRotation( application,  Vector2( 112.0f, 62.0f ), Vector2( 112.0f, 162.0f ),
254                                    Vector2( 112.0f, 100.0f ), Vector2( 112.0f, 124.0f ), 100 );
255
256   DALI_TEST_EQUALS(false, data.functorCalled, TEST_LOCATION);
257
258   // Continue rotation into actor's area - we should still not receive the signal
259   data.Reset();
260   TestContinueRotation( application, Vector2( 112.0f, 100.0f ), Vector2( 112.0f, 124.0f ),
261                                      Vector2( 5.0f, 5.0f ), Vector2( 35.0f, 35.0f ), 200 );
262
263   DALI_TEST_EQUALS(false, data.functorCalled, TEST_LOCATION);
264
265   // Stop rotating - we should still not receive the signal
266   data.Reset();
267   TestEndRotation( application,  Vector2( 6.0f, 6.0f ), Vector2( 18.0f, 18.0f ),
268                                  Vector2( 10.0f, 8.0f ), Vector2( 14.0f, 16.0f ), 300 );
269
270   DALI_TEST_EQUALS(false, data.functorCalled, TEST_LOCATION);
271   END_TEST;
272 }
273
274 int UtcDaliRotationGestureSignalReceptionDownMotionLeave(void)
275 {
276   TestApplication application;
277
278   Actor actor = Actor::New();
279   actor.SetProperty( Actor::Property::SIZE, Vector2( 100.0f, 100.0f ) );
280   actor.SetProperty( Actor::Property::ANCHOR_POINT,AnchorPoint::TOP_LEFT);
281   application.GetScene().Add(actor);
282
283   // Render and notify
284   application.SendNotification();
285   application.Render();
286
287   SignalData data;
288   GestureReceivedFunctor functor(data);
289
290   RotationGestureDetector detector = RotationGestureDetector::New();
291   detector.Attach(actor);
292   detector.DetectedSignal().Connect(&application, functor);
293
294   // Start pan within the actor's area
295   TestStartRotation( application,  Vector2( 5.0f, 5.0f ), Vector2( 20.0f, 20.0f ),
296                                    Vector2( 5.0f, 5.0f ), Vector2( 20.0f, 30.0f ), 100 );
297   DALI_TEST_EQUALS(true, data.functorCalled, TEST_LOCATION);
298   DALI_TEST_EQUALS(Gesture::Started, data.receivedGesture.state, TEST_LOCATION);
299   DALI_TEST_EQUALS(0.244f, data.receivedGesture.rotation.radian, 0.01f, TEST_LOCATION);
300   DALI_TEST_EQUALS(Vector2(12.5f, 17.5f), data.receivedGesture.screenCenterPoint, 0.01f, TEST_LOCATION);
301
302   // Continue the pan within the actor's area - we should still receive the signal
303   data.Reset();
304   TestContinueRotation( application, Vector2( 10.0f, 20.0f ), Vector2( 30.0f, 20.0f ),
305                                      Vector2( 17.0f, 20.0f ), Vector2( 25.0f, 20.0f ), 400 );
306   DALI_TEST_EQUALS(true, data.functorCalled, TEST_LOCATION);
307   DALI_TEST_EQUALS(Gesture::Continuing, data.receivedGesture.state, TEST_LOCATION);
308   DALI_TEST_EQUALS(-0.785398f, data.receivedGesture.rotation.radian, 0.01f, TEST_LOCATION);
309   DALI_TEST_EQUALS(Vector2(21.0f, 20.0f), data.receivedGesture.screenCenterPoint, 0.01f, TEST_LOCATION);
310
311   // Pan Gesture leaves actor's area - we should still receive the signal
312   data.Reset();
313   TestContinueRotation( application, Vector2( 17.0f, 20.0f ), Vector2( 25.0f, 20.0f ),
314                                      Vector2( 300.0f, 10.0f ), Vector2( 340.0f, 10.0f ), 1000 );
315   DALI_TEST_EQUALS(true, data.functorCalled, TEST_LOCATION);
316   DALI_TEST_EQUALS(Gesture::Continuing, data.receivedGesture.state, TEST_LOCATION);
317   DALI_TEST_EQUALS(-0.785398f, data.receivedGesture.rotation.radian, 0.01f, TEST_LOCATION);
318   DALI_TEST_EQUALS(Vector2(320.0f, 10.0f), data.receivedGesture.screenCenterPoint, 0.01f, TEST_LOCATION);
319
320   // Gesture ends - we would receive a finished state
321   data.Reset();
322   TestEndRotation( application,  Vector2( 300.0f, 10.0f ), Vector2( 340.0f, 10.0f ),
323                                  Vector2( 305.0f, 10.0f ), Vector2( 315.0f, 10.0f ), 1500);
324   DALI_TEST_EQUALS(true, data.functorCalled, TEST_LOCATION);
325   DALI_TEST_EQUALS(Gesture::Finished, data.receivedGesture.state, TEST_LOCATION);
326   DALI_TEST_EQUALS(-0.785398f, data.receivedGesture.rotation.radian, 0.01f, TEST_LOCATION);
327   DALI_TEST_EQUALS(Vector2(310.0f, 10.0f), data.receivedGesture.screenCenterPoint, 0.01f, TEST_LOCATION);
328   END_TEST;
329 }
330
331 int UtcDaliRotationGestureSignalReceptionDownMotionUp(void)
332 {
333   TestApplication application;
334
335   Actor actor = Actor::New();
336   actor.SetProperty( Actor::Property::SIZE, Vector2( 100.0f, 100.0f ) );
337   actor.SetProperty( Actor::Property::ANCHOR_POINT,AnchorPoint::TOP_LEFT);
338   application.GetScene().Add(actor);
339
340   // Render and notify
341   application.SendNotification();
342   application.Render();
343
344   SignalData data;
345   GestureReceivedFunctor functor(data);
346
347   RotationGestureDetector detector = RotationGestureDetector::New();
348   detector.Attach(actor);
349   detector.DetectedSignal().Connect(&application, functor);
350
351   // Start rotation within the actor's area
352   TestStartRotation( application,  Vector2( 2.0f, 20.0f ), Vector2( 38.0f, 20.0f ),
353                                    Vector2( 10.0f, 20.0f ), Vector2( 31.0f, 29.0f ), 100 );
354   DALI_TEST_EQUALS(true, data.functorCalled, TEST_LOCATION);
355   DALI_TEST_EQUALS(Gesture::Started, data.receivedGesture.state, TEST_LOCATION);
356   DALI_TEST_EQUALS(0.404892f, data.receivedGesture.rotation.radian, 0.01f, TEST_LOCATION);
357   DALI_TEST_EQUALS(Vector2(20.5f, 24.5f), data.receivedGesture.screenCenterPoint, 0.01f, TEST_LOCATION);
358
359   // Continue the rotation within the actor's area - we should still receive the signal
360   data.Reset();
361   TestContinueRotation( application, Vector2( 10.0f, 20.0f ), Vector2( 30.0f, 20.0f ),
362                                      Vector2( 15.0f, 20.0f ), Vector2( 29.0f, 15.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.343024f, data.receivedGesture.rotation.radian, 0.01f, TEST_LOCATION);
366   DALI_TEST_EQUALS(Vector2(22.0f, 17.5f), data.receivedGesture.screenCenterPoint, 0.01f, TEST_LOCATION);
367
368   // Gesture ends within actor's area - we would receive a finished state
369   data.Reset();
370   TestEndRotation( application,  Vector2( 15.0f, 20.0f ), Vector2( 25.0f, 20.0f ),
371                                  Vector2( 19.0f, 20.0f ), Vector2( 29.0f, 15.0f ), 1000);
372   DALI_TEST_EQUALS(true, data.functorCalled, TEST_LOCATION);
373   DALI_TEST_EQUALS(Gesture::Finished, data.receivedGesture.state, TEST_LOCATION);
374   DALI_TEST_EQUALS(-0.463648f, data.receivedGesture.rotation.radian, 0.01f, TEST_LOCATION);
375   DALI_TEST_EQUALS(Vector2(24.0f, 17.5f), data.receivedGesture.screenCenterPoint, 0.01f, TEST_LOCATION);
376   END_TEST;
377 }
378
379 int UtcDaliRotationGestureSignalReceptionDetach(void)
380 {
381   TestApplication application;
382
383   Actor actor = Actor::New();
384   actor.SetProperty( Actor::Property::SIZE, Vector2( 100.0f, 100.0f ) );
385   actor.SetProperty( Actor::Property::ANCHOR_POINT,AnchorPoint::TOP_LEFT);
386   application.GetScene().Add(actor);
387
388   // Render and notify
389   application.SendNotification();
390   application.Render();
391
392   SignalData data;
393   GestureReceivedFunctor functor(data);
394
395   RotationGestureDetector detector = RotationGestureDetector::New();
396   detector.Attach(actor);
397   detector.DetectedSignal().Connect(&application, functor);
398
399   // Start rotation within the actor's area
400   TestStartRotation( application,  Vector2( 2.0f, 20.0f ), Vector2( 38.0f, 20.0f ),
401                                    Vector2( 10.0f, 20.0f ), Vector2( 30.0f, 20.0f ), 100 );
402   DALI_TEST_EQUALS(true, data.functorCalled, TEST_LOCATION);
403   DALI_TEST_EQUALS(Gesture::Started, data.receivedGesture.state, TEST_LOCATION);
404
405
406   // Continue the rotation within the actor's area - we should still receive the signal
407   data.Reset();
408   TestContinueRotation( application, Vector2( 10.0f, 20.0f ), Vector2( 30.0f, 20.0f ),
409                                      Vector2( 15.0f, 20.0f ), Vector2( 25.0f, 20.0f ), 500 );
410   DALI_TEST_EQUALS(true, data.functorCalled, TEST_LOCATION);
411   DALI_TEST_EQUALS(Gesture::Continuing, data.receivedGesture.state, TEST_LOCATION);
412
413   // Gesture ends within actor's area
414   data.Reset();
415   TestEndRotation( application,  Vector2( 15.0f, 20.0f ), Vector2( 25.0f, 20.0f ),
416                                  Vector2( 19.0f, 20.0f ), Vector2( 21.0f, 20.0f ), 1000);
417   DALI_TEST_EQUALS(true, data.functorCalled, TEST_LOCATION);
418   DALI_TEST_EQUALS(Gesture::Finished, data.receivedGesture.state, TEST_LOCATION);
419
420   // Detach actor
421   detector.DetachAll();
422
423   // Ensure we are no longer signalled
424   data.Reset();
425   TestGenerateRotation(  application );
426   DALI_TEST_EQUALS(false, data.functorCalled, TEST_LOCATION);
427   END_TEST;
428 }
429
430 int UtcDaliRotationGestureSignalReceptionDetachWhileRotationing(void)
431 {
432   TestApplication application;
433
434   Actor actor = Actor::New();
435   actor.SetProperty( Actor::Property::SIZE, Vector2( 100.0f, 100.0f ) );
436   actor.SetProperty( Actor::Property::ANCHOR_POINT,AnchorPoint::TOP_LEFT);
437   application.GetScene().Add(actor);
438
439   // Render and notify
440   application.SendNotification();
441   application.Render();
442
443   SignalData data;
444   GestureReceivedFunctor functor(data);
445
446   RotationGestureDetector detector = RotationGestureDetector::New();
447   detector.Attach(actor);
448   detector.DetectedSignal().Connect(&application, functor);
449
450   // Start rotation within the actor's area
451   TestStartRotation( application,  Vector2( 2.0f, 20.0f ), Vector2( 38.0f, 20.0f ),
452                                    Vector2( 10.0f, 20.0f ), Vector2( 30.0f, 20.0f ), 100 );
453   DALI_TEST_EQUALS(true, data.functorCalled, TEST_LOCATION);
454   DALI_TEST_EQUALS(Gesture::Started, data.receivedGesture.state, TEST_LOCATION);
455
456   // Continue the rotation within the actor's area - we should still receive the signal
457   data.Reset();
458   TestContinueRotation( application, Vector2( 10.0f, 20.0f ), Vector2( 30.0f, 20.0f ),
459                                      Vector2( 15.0f, 20.0f ), Vector2( 25.0f, 20.0f ), 500 );
460   DALI_TEST_EQUALS(true, data.functorCalled, TEST_LOCATION);
461   DALI_TEST_EQUALS(Gesture::Continuing, data.receivedGesture.state, TEST_LOCATION);
462
463   // Detach actor during the rotation, we should not receive the next event
464   detector.DetachAll();
465
466   // Gesture ends within actor's area
467   data.Reset();
468   TestEndRotation( application,  Vector2( 15.0f, 20.0f ), Vector2( 25.0f, 20.0f ),
469                                  Vector2( 19.0f, 20.0f ), Vector2( 21.0f, 20.0f ), 1000);
470   DALI_TEST_EQUALS(false, data.functorCalled, TEST_LOCATION);
471   END_TEST;
472 }
473
474 int UtcDaliRotationGestureSignalReceptionActorDestroyedWhileRotationing(void)
475 {
476   TestApplication application;
477
478   SignalData data;
479   GestureReceivedFunctor functor(data);
480
481   RotationGestureDetector detector = RotationGestureDetector::New();
482   detector.DetectedSignal().Connect(&application, functor);
483
484   // Attach a temporary actor to stop detector being removed from RotationGestureProcessor when main actor
485   // is destroyed.
486   Actor tempActor = Actor::New();
487   tempActor.SetProperty( Actor::Property::SIZE, Vector2( 100.0f, 100.0f ) );
488   tempActor.SetProperty( Actor::Property::ANCHOR_POINT,AnchorPoint::BOTTOM_RIGHT);
489   application.GetScene().Add(tempActor);
490   detector.Attach(tempActor);
491
492   // Actor lifetime is scoped
493   {
494     Actor actor = Actor::New();
495     actor.SetProperty( Actor::Property::SIZE, Vector2( 100.0f, 100.0f ) );
496     actor.SetProperty( Actor::Property::ANCHOR_POINT,AnchorPoint::TOP_LEFT);
497     application.GetScene().Add(actor);
498
499     // Render and notify
500     application.SendNotification();
501     application.Render();
502
503     detector.Attach(actor);
504
505     // Start rotation within the actor's area
506     TestStartRotation( application,  Vector2( 2.0f, 20.0f ), Vector2( 38.0f, 20.0f ),
507                                      Vector2( 10.0f, 20.0f ), Vector2( 30.0f, 20.0f ), 100 );
508     DALI_TEST_EQUALS(true, data.functorCalled, TEST_LOCATION);
509     DALI_TEST_EQUALS(Gesture::Started, data.receivedGesture.state, TEST_LOCATION);
510
511     // Continue the rotation within the actor's area - we should still receive the signal
512     data.Reset();
513     TestContinueRotation( application, Vector2( 10.0f, 20.0f ), Vector2( 30.0f, 20.0f ),
514                                        Vector2( 15.0f, 20.0f ), Vector2( 25.0f, 20.0f ), 500 );
515     DALI_TEST_EQUALS(true, data.functorCalled, TEST_LOCATION);
516     DALI_TEST_EQUALS(Gesture::Continuing, data.receivedGesture.state, TEST_LOCATION);
517
518     // Remove the actor from stage and reset the data
519     application.GetScene().Remove(actor);
520
521     // Render and notify
522     application.SendNotification();
523     application.Render();
524   }
525
526   // Actor should now have been destroyed
527
528   // Gesture ends within the area where the actor used to be
529   data.Reset();
530   TestEndRotation( application,  Vector2( 15.0f, 20.0f ), Vector2( 25.0f, 20.0f ),
531                                  Vector2( 19.0f, 20.0f ), Vector2( 21.0f, 20.0f ), 1000);
532   DALI_TEST_EQUALS(false, data.functorCalled, TEST_LOCATION);
533   END_TEST;
534 }
535
536 int UtcDaliRotationGestureSignalReceptionRotatedActor(void)
537 {
538   TestApplication application;
539
540   Actor actor = Actor::New();
541   actor.SetProperty( Actor::Property::SIZE, Vector2( 100.0f, 100.0f ) );
542   actor.SetProperty( Actor::Property::ORIENTATION, Quaternion(Dali::Degree(90.0f), Vector3::ZAXIS) );
543   application.GetScene().Add(actor);
544
545   // Render and notify a couple of times
546   application.SendNotification();
547   application.Render();
548
549   SignalData data;
550   GestureReceivedFunctor functor(data);
551
552   RotationGestureDetector detector = RotationGestureDetector::New();
553   detector.Attach(actor);
554   detector.DetectedSignal().Connect(&application, functor);
555
556   // Do an entire rotation, only check finished value
557   TestStartRotation( application,  Vector2( 2.0f, 20.0f ), Vector2( 38.0f, 20.0f ),
558                                    Vector2( 10.0f, 20.0f ), Vector2( 30.0f, 20.0f ), 100 );
559   data.Reset();
560   TestEndRotation( application,  Vector2( 15.0f, 20.0f ), Vector2( 25.0f, 20.0f ),
561                                  Vector2( 19.0f, 20.0f ), Vector2( 27.0f, 15.0f ), 1000);
562   DALI_TEST_EQUALS(true, data.functorCalled, TEST_LOCATION);
563   DALI_TEST_EQUALS(-0.558599f, data.receivedGesture.rotation.radian, 0.01f, TEST_LOCATION);
564   DALI_TEST_EQUALS(Vector2(23.0f, 17.5f), data.receivedGesture.screenCenterPoint, 0.01f, TEST_LOCATION);
565
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();
570
571   // Do an entire rotation, only check finished value
572   TestStartRotation( application,  Vector2( 2.0f, 20.0f ), Vector2( 38.0f, 20.0f ),
573                                    Vector2( 10.0f, 20.0f ), Vector2( 30.0f, 20.0f ), 2100 );
574   data.Reset();
575   TestEndRotation( application,  Vector2( 15.0f, 20.0f ), Vector2( 25.0f, 20.0f ),
576                                  Vector2( 19.0f, 20.0f ), Vector2( 27.0f, 15.0f ), 3000);
577   DALI_TEST_EQUALS(true, data.functorCalled, TEST_LOCATION);
578   DALI_TEST_EQUALS(-0.558599f, data.receivedGesture.rotation.radian, 0.01f, TEST_LOCATION);
579   DALI_TEST_EQUALS(Vector2(23.0f, 17.5f), data.receivedGesture.screenCenterPoint, 0.01f, TEST_LOCATION);
580
581   // Rotate actor again and render and notify
582   actor.SetProperty( Actor::Property::ORIENTATION, Quaternion(Dali::Degree(270.0f), Vector3::ZAXIS) );
583   application.SendNotification();
584   application.Render();
585
586   // Do an entire rotation, only check finished value
587   TestStartRotation( application,  Vector2( 2.0f, 20.0f ), Vector2( 38.0f, 20.0f ),
588                                    Vector2( 10.0f, 20.0f ), Vector2( 30.0f, 20.0f ), 4100 );
589   data.Reset();
590   TestEndRotation( application,  Vector2( 15.0f, 20.0f ), Vector2( 25.0f, 20.0f ),
591                                  Vector2( 19.0f, 20.0f ), Vector2( 27.0f, 15.0f ), 5000);
592   DALI_TEST_EQUALS(true, data.functorCalled, TEST_LOCATION);
593   DALI_TEST_EQUALS(-0.558599f, data.receivedGesture.rotation.radian, 0.01f, TEST_LOCATION);
594   DALI_TEST_EQUALS(Vector2(23.0f, 17.5f), data.receivedGesture.screenCenterPoint, 0.01f, TEST_LOCATION);
595   END_TEST;
596 }
597
598 int UtcDaliRotationGestureSignalReceptionChildHit(void)
599 {
600   TestApplication application;
601
602   Actor parent = Actor::New();
603   parent.SetProperty( Actor::Property::SIZE, Vector2( 100.0f, 100.0f ) );
604   parent.SetProperty( Actor::Property::ANCHOR_POINT,AnchorPoint::TOP_LEFT);
605   application.GetScene().Add(parent);
606
607   // Set child to completely cover parent.
608   // Change rotation of child to be different from parent so that we can check if our local coordinate
609   // conversion of the parent actor is correct.
610   Actor child = Actor::New();
611   child.SetProperty( Actor::Property::SIZE, Vector2( 100.0f, 100.0f ) );
612   child.SetProperty( Actor::Property::ANCHOR_POINT,AnchorPoint::CENTER);
613   child.SetProperty( Actor::Property::PARENT_ORIGIN,ParentOrigin::CENTER);
614   child.SetProperty( Actor::Property::ORIENTATION, Quaternion(Dali::Degree(90.0f), Vector3::ZAXIS) );
615   parent.Add(child);
616
617   TouchEventFunctor touchFunctor;
618   child.TouchedSignal().Connect(&application, touchFunctor);
619
620   // Render and notify
621   application.SendNotification();
622   application.Render();
623
624   SignalData data;
625   GestureReceivedFunctor functor(data);
626
627   RotationGestureDetector detector = RotationGestureDetector::New();
628   detector.Attach(parent);
629   detector.DetectedSignal().Connect(&application, functor);
630
631   // Do an entire pan, only check finished value - hits child area but parent should still receive it
632   TestStartRotation( application,  Vector2( 2.0f, 20.0f ), Vector2( 38.0f, 20.0f ),
633                                    Vector2( 10.0f, 20.0f ), Vector2( 30.0f, 20.0f ), 100 );
634   data.Reset();
635   TestEndRotation( application,  Vector2( 15.0f, 20.0f ), Vector2( 25.0f, 20.0f ),
636                                  Vector2( 19.0f, 20.0f ), Vector2( 29.0f, 25.0f ), 1000);
637   DALI_TEST_EQUALS(true, data.functorCalled, TEST_LOCATION);
638   DALI_TEST_EQUALS(true, parent == data.rotatedActor, TEST_LOCATION);
639   DALI_TEST_EQUALS(0.463648f, data.receivedGesture.rotation.radian, 0.01f, TEST_LOCATION);
640   DALI_TEST_EQUALS(Vector2(24.0f, 22.5f), data.receivedGesture.screenCenterPoint, 0.01f, TEST_LOCATION);
641
642   // Attach child and generate same touch points to yield same results
643   // (Also proves that you can detach and then re-attach another actor)
644   detector.Attach(child);
645   detector.Detach(parent);
646
647   // Do an entire pan, only check finished value
648   TestStartRotation( application,  Vector2( 2.0f, 20.0f ), Vector2( 38.0f, 20.0f ),
649                                    Vector2( 10.0f, 20.0f ), Vector2( 30.0f, 20.0f ), 2100 );
650   data.Reset();
651   TestEndRotation( application,  Vector2( 15.0f, 20.0f ), Vector2( 25.0f, 20.0f ),
652                                  Vector2( 19.0f, 20.0f ), Vector2( 29.0f, 35.0f ), 3000);
653   DALI_TEST_EQUALS(true, data.functorCalled, TEST_LOCATION);
654   DALI_TEST_EQUALS(true, child == data.rotatedActor, TEST_LOCATION);
655   DALI_TEST_EQUALS(0.982794f, data.receivedGesture.rotation.radian, 0.01f, TEST_LOCATION);
656   DALI_TEST_EQUALS(Vector2(24.0f, 27.5f), data.receivedGesture.screenCenterPoint, 0.01f, TEST_LOCATION);
657   END_TEST;
658 }
659
660 int UtcDaliRotationGestureSignalReceptionAttachDetachMany(void)
661 {
662   TestApplication application;
663
664   Actor first = Actor::New();
665   first.SetProperty( Actor::Property::SIZE, Vector2( 100.0f, 100.0f ) );
666   first.SetProperty( Actor::Property::ANCHOR_POINT,AnchorPoint::TOP_LEFT);
667   application.GetScene().Add(first);
668
669   Actor second = Actor::New();
670   second.SetProperty( Actor::Property::SIZE, Vector2( 100.0f, 100.0f ) );
671   second.SetProperty( Actor::Property::POSITION_X, 100.0f);
672   second.SetProperty( Actor::Property::ANCHOR_POINT,AnchorPoint::TOP_LEFT);
673   application.GetScene().Add(second);
674
675   // Render and notify
676   application.SendNotification();
677   application.Render();
678
679   SignalData data;
680   GestureReceivedFunctor functor(data);
681
682   RotationGestureDetector detector = RotationGestureDetector::New();
683   detector.Attach(first);
684   detector.Attach(second);
685   detector.DetectedSignal().Connect(&application, functor);
686
687   // Start rotation within second actor's area
688   TestStartRotation( application,  Vector2( 102.0f, 20.0f ), Vector2( 138.0f, 20.0f ),
689                                    Vector2( 110.0f, 20.0f ), Vector2( 130.0f, 20.0f ), 100 );
690   DALI_TEST_EQUALS(true, data.functorCalled, TEST_LOCATION);
691   DALI_TEST_EQUALS(true, second == data.rotatedActor, TEST_LOCATION);
692
693   // Rotation moves into first actor's area - second actor should receive the rotation
694   data.Reset();
695   TestContinueRotation( application, Vector2( 110.0f, 20.0f ), Vector2( 130.0f, 20.0f ),
696                                      Vector2( 15.0f, 20.0f ), Vector2( 25.0f, 20.0f ), 500 );
697   DALI_TEST_EQUALS(true, data.functorCalled, TEST_LOCATION);
698   DALI_TEST_EQUALS(true, second == data.rotatedActor, TEST_LOCATION);
699
700   // Detach the second actor during the rotation, we should not receive the next event
701   detector.Detach(second);
702
703   // Gesture ends within actor's area
704   data.Reset();
705   TestEndRotation( application,  Vector2( 15.0f, 20.0f ), Vector2( 25.0f, 20.0f ),
706                                  Vector2( 119.0f, 20.0f ), Vector2( 121.0f, 20.0f ), 3000);
707   DALI_TEST_EQUALS(false, data.functorCalled, TEST_LOCATION);
708   END_TEST;
709 }
710
711 int UtcDaliRotationGestureSignalReceptionActorBecomesUntouchable(void)
712 {
713   TestApplication application;
714
715   Actor actor = Actor::New();
716   actor.SetProperty( Actor::Property::SIZE, Vector2( 100.0f, 100.0f ) );
717   actor.SetProperty( Actor::Property::ANCHOR_POINT,AnchorPoint::TOP_LEFT);
718   application.GetScene().Add(actor);
719
720   // Render and notify
721   application.SendNotification();
722   application.Render();
723
724   SignalData data;
725   GestureReceivedFunctor functor(data);
726
727   RotationGestureDetector detector = RotationGestureDetector::New();
728   detector.Attach(actor);
729   detector.DetectedSignal().Connect(&application, functor);
730
731   // Start rotation in actor's area
732   TestStartRotation( application,  Vector2( 2.0f, 20.0f ), Vector2( 38.0f, 20.0f ),
733                                    Vector2( 10.0f, 20.0f ), Vector2( 30.0f, 20.0f ), 100 );
734   DALI_TEST_EQUALS(true, data.functorCalled, TEST_LOCATION);
735
736   // Pan continues within actor's area
737   data.Reset();
738   TestContinueRotation( application, Vector2( 10.0f, 20.0f ), Vector2( 30.0f, 20.0f ),
739                                      Vector2( 15.0f, 20.0f ), Vector2( 25.0f, 20.0f ), 500 );
740   DALI_TEST_EQUALS(true, data.functorCalled, TEST_LOCATION);
741
742   // Actor become invisible - actor should not receive the next rotation
743   actor.SetProperty( Actor::Property::VISIBLE,false);
744
745   // Render and notify
746   application.SendNotification();
747   application.Render();
748
749   // Gesture ends within actor's area
750   data.Reset();
751   TestEndRotation( application,  Vector2( 15.0f, 20.0f ), Vector2( 25.0f, 20.0f ),
752                                  Vector2( 19.0f, 20.0f ), Vector2( 21.0f, 20.0f ), 3000);
753   DALI_TEST_EQUALS(false, data.functorCalled, TEST_LOCATION);
754   END_TEST;
755 }
756
757 int UtcDaliRotationGestureSignalReceptionMultipleDetectorsOnActor(void)
758 {
759   TestApplication application;
760
761   Actor actor = Actor::New();
762   actor.SetProperty( Actor::Property::SIZE, Vector2( 100.0f, 100.0f ) );
763   actor.SetProperty( Actor::Property::ANCHOR_POINT,AnchorPoint::TOP_LEFT);
764   application.GetScene().Add(actor);
765
766   Actor actor2 = Actor::New();
767   actor2.SetProperty( Actor::Property::SIZE, Vector2( 100.0f, 100.0f ) );
768   actor2.SetProperty( Actor::Property::ANCHOR_POINT,AnchorPoint::BOTTOM_RIGHT);
769   application.GetScene().Add(actor2);
770
771   // Render and notify
772   application.SendNotification();
773   application.Render();
774
775   // Attach actor to one detector
776   SignalData firstData;
777   GestureReceivedFunctor firstFunctor(firstData);
778   RotationGestureDetector firstDetector = RotationGestureDetector::New();
779   firstDetector.Attach(actor);
780   firstDetector.DetectedSignal().Connect(&application, firstFunctor);
781
782   // Attach actor to another detector
783   SignalData secondData;
784   GestureReceivedFunctor secondFunctor(secondData);
785   RotationGestureDetector secondDetector = RotationGestureDetector::New();
786   secondDetector.Attach(actor);
787   secondDetector.DetectedSignal().Connect(&application, secondFunctor);
788
789   // Add second actor to second detector, when we remove the actor, this will make sure that this
790   // gesture detector is not removed from the GestureDetectorProcessor.  In this scenario, the
791   // functor should still not be called (which is what we're also testing).
792   secondDetector.Attach(actor2);
793
794   // Rotation in actor's area - both detector's functors should be called
795   TestStartRotation( application,  Vector2( 2.0f, 20.0f ), Vector2( 38.0f, 20.0f ),
796                                    Vector2( 10.0f, 20.0f ), Vector2( 30.0f, 20.0f ), 100 );
797   DALI_TEST_EQUALS(true, firstData.functorCalled, TEST_LOCATION);
798   DALI_TEST_EQUALS(true, secondData.functorCalled, TEST_LOCATION);
799
800   // Rotation continues in actor's area - both detector's functors should be called
801   firstData.Reset();
802   secondData.Reset();
803   TestContinueRotation( application, Vector2( 10.0f, 20.0f ), Vector2( 30.0f, 20.0f ),
804                                      Vector2( 15.0f, 20.0f ), Vector2( 25.0f, 20.0f ), 500 );
805   DALI_TEST_EQUALS(true, firstData.functorCalled, TEST_LOCATION);
806   DALI_TEST_EQUALS(true, secondData.functorCalled, TEST_LOCATION);
807
808   // Detach actor from firstDetector and emit rotation on actor, only secondDetector's functor should be called.
809   firstDetector.Detach(actor);
810   firstData.Reset();
811   secondData.Reset();
812   TestEndRotation( application,  Vector2( 15.0f, 20.0f ), Vector2( 25.0f, 20.0f ),
813                                  Vector2( 19.0f, 20.0f ), Vector2( 21.0f, 20.0f ), 1000);
814   DALI_TEST_EQUALS(false, firstData.functorCalled, TEST_LOCATION);
815   DALI_TEST_EQUALS(true, secondData.functorCalled, TEST_LOCATION);
816
817   // New rotation on actor, only secondDetector has actor attached
818   firstData.Reset();
819   secondData.Reset();
820   TestStartRotation( application,  Vector2( 2.0f, 20.0f ), Vector2( 38.0f, 20.0f ),
821                                    Vector2( 10.0f, 20.0f ), Vector2( 30.0f, 20.0f ), 1500 );
822   DALI_TEST_EQUALS(false, firstData.functorCalled, TEST_LOCATION);
823   DALI_TEST_EQUALS(true, secondData.functorCalled, TEST_LOCATION);
824
825   // Detach actor from secondDetector
826   secondDetector.Detach(actor);
827   firstData.Reset();
828   secondData.Reset();
829   TestContinueRotation( application, Vector2( 10.0f, 20.0f ), Vector2( 30.0f, 20.0f ),
830                                      Vector2( 15.0f, 20.0f ), Vector2( 25.0f, 20.0f ), 2000 );
831   DALI_TEST_EQUALS(false, firstData.functorCalled, TEST_LOCATION);
832   DALI_TEST_EQUALS(false, secondData.functorCalled, TEST_LOCATION);
833   END_TEST;
834 }
835
836 int UtcDaliRotationGestureSignalReceptionEnsureCorrectSignalling(void)
837 {
838   TestApplication application;
839
840   Actor actor1 = Actor::New();
841   actor1.SetProperty( Actor::Property::SIZE, Vector2( 100.0f, 100.0f ) );
842   actor1.SetProperty( Actor::Property::ANCHOR_POINT,AnchorPoint::TOP_LEFT);
843   application.GetScene().Add(actor1);
844   SignalData data1;
845   GestureReceivedFunctor functor1(data1);
846   RotationGestureDetector detector1 = RotationGestureDetector::New();
847   detector1.Attach(actor1);
848   detector1.DetectedSignal().Connect(&application, functor1);
849
850   Actor actor2 = Actor::New();
851   actor2.SetProperty( Actor::Property::SIZE, Vector2( 100.0f, 100.0f ) );
852   actor2.SetProperty( Actor::Property::ANCHOR_POINT,AnchorPoint::BOTTOM_RIGHT);
853   actor2.SetProperty( Actor::Property::PARENT_ORIGIN,ParentOrigin::BOTTOM_RIGHT);
854   application.GetScene().Add(actor2);
855   SignalData data2;
856   GestureReceivedFunctor functor2(data2);
857   RotationGestureDetector detector2 = RotationGestureDetector::New();
858   detector2.Attach(actor2);
859   detector2.DetectedSignal().Connect(&application, functor2);
860
861   // Render and notify
862   application.SendNotification();
863   application.Render();
864
865   // Start pan in actor1's area, only data1 should be set
866   TestStartRotation( application,  Vector2( 2.0f, 20.0f ), Vector2( 38.0f, 20.0f ),
867                                    Vector2( 10.0f, 20.0f ), Vector2( 30.0f, 20.0f ), 100 );
868   DALI_TEST_EQUALS(true, data1.functorCalled, TEST_LOCATION);
869   DALI_TEST_EQUALS(false, data2.functorCalled, TEST_LOCATION);
870   END_TEST;
871 }
872
873 int UtcDaliRotationGestureActorUnstaged(void)
874 {
875   TestApplication application;
876
877   Actor actor = Actor::New();
878   actor.SetProperty( Actor::Property::SIZE, Vector2( 100.0f, 100.0f ) );
879   actor.SetProperty( Actor::Property::ANCHOR_POINT,AnchorPoint::TOP_LEFT);
880   application.GetScene().Add(actor);
881
882   // Render and notify
883   application.SendNotification();
884   application.Render();
885
886   // State to remove actor in.
887   Gesture::State stateToUnstage( Gesture::Started );
888
889   // Attach actor to detector
890   SignalData data;
891   UnstageActorFunctor functor( data, stateToUnstage, application.GetScene() );
892   RotationGestureDetector detector = RotationGestureDetector::New();
893   detector.Attach(actor);
894   detector.DetectedSignal().Connect( &application, functor );
895
896   // Emit signals
897   TestStartRotation( application,  Vector2( 2.0f, 20.0f ), Vector2( 38.0f, 20.0f ),
898                                    Vector2( 10.0f, 20.0f ), Vector2( 30.0f, 20.0f ), 100 );
899   DALI_TEST_EQUALS(true, data.functorCalled, TEST_LOCATION);
900   data.Reset();
901   TestEndRotation( application,  Vector2( 10.0f, 20.0f ), Vector2( 30.0f, 20.0f ),
902                                  Vector2( 19.0f, 20.0f ), Vector2( 21.0f, 20.0f ), 1000);
903   DALI_TEST_EQUALS(false, data.functorCalled, TEST_LOCATION);
904   data.Reset();
905
906   // Render and notify
907   application.SendNotification();
908   application.Render();
909
910   // Re-add actor to stage
911   application.GetScene().Add(actor);
912
913   // Render and notify
914   application.SendNotification();
915   application.Render();
916
917   // Change state to Gesture::Continuing to remove
918   stateToUnstage = Gesture::Continuing;
919
920   // Emit signals
921   TestStartRotation( application,  Vector2( 2.0f, 20.0f ), Vector2( 38.0f, 20.0f ),
922                                    Vector2( 10.0f, 20.0f ), Vector2( 30.0f, 20.0f ), 100 );
923   DALI_TEST_EQUALS(true, data.functorCalled, TEST_LOCATION);
924   data.Reset();
925   TestContinueRotation( application, Vector2( 10.0f, 20.0f ), Vector2( 30.0f, 20.0f ),
926                                      Vector2( 15.0f, 20.0f ), Vector2( 25.0f, 20.0f ), 500 );
927   DALI_TEST_EQUALS(true, data.functorCalled, TEST_LOCATION);
928   data.Reset();
929   TestEndRotation( application,  Vector2( 10.0f, 20.0f ), Vector2( 30.0f, 20.0f ),
930                                  Vector2( 19.0f, 20.0f ), Vector2( 21.0f, 20.0f ), 1000);
931   DALI_TEST_EQUALS(false, data.functorCalled, TEST_LOCATION);
932   data.Reset();
933
934   // Render and notify
935   application.SendNotification();
936   application.Render();
937
938   // Re-add actor to stage
939   application.GetScene().Add(actor);
940
941   // Render and notify
942   application.SendNotification();
943   application.Render();
944
945   // Change state to Gesture::Continuing to remove
946   stateToUnstage = Gesture::Finished;
947
948   // Emit signals
949   TestStartRotation( application,  Vector2( 2.0f, 20.0f ), Vector2( 38.0f, 20.0f ),
950                                    Vector2( 10.0f, 20.0f ), Vector2( 30.0f, 20.0f ), 100 );
951   DALI_TEST_EQUALS(true, data.functorCalled, TEST_LOCATION);
952   data.Reset();
953   TestContinueRotation( application, Vector2( 10.0f, 20.0f ), Vector2( 30.0f, 20.0f ),
954                                      Vector2( 15.0f, 20.0f ), Vector2( 25.0f, 20.0f ), 500 );
955   DALI_TEST_EQUALS(true, data.functorCalled, TEST_LOCATION);
956   data.Reset();
957   TestEndRotation( application,  Vector2( 10.0f, 20.0f ), Vector2( 30.0f, 20.0f ),
958                                  Vector2( 19.0f, 20.0f ), Vector2( 21.0f, 20.0f ), 1000);
959   DALI_TEST_EQUALS(true, data.functorCalled, TEST_LOCATION);
960   tet_result( TET_PASS ); // If we get here then we have handled actor stage removal gracefully.
961   END_TEST;
962 }
963
964 int UtcDaliRotationGestureActorStagedAndDestroyed(void)
965 {
966   TestApplication application;
967
968   Actor actor = Actor::New();
969   actor.SetProperty( Actor::Property::SIZE, Vector2( 100.0f, 100.0f ) );
970   actor.SetProperty( Actor::Property::ANCHOR_POINT,AnchorPoint::TOP_LEFT);
971   application.GetScene().Add(actor);
972
973   // Create and add a second actor so that GestureDetector destruction does not come into play.
974   Actor dummyActor( Actor::New() );
975   dummyActor.SetProperty( Actor::Property::SIZE, Vector2( 100.0f, 100.0f ) );
976   dummyActor.SetProperty( Actor::Property::POSITION, Vector2( 100.0f, 100.0f ));
977   dummyActor.SetProperty( Actor::Property::ANCHOR_POINT,AnchorPoint::TOP_LEFT);
978   application.GetScene().Add(dummyActor);
979
980   // Render and notify
981   application.SendNotification();
982   application.Render();
983
984   // State to remove actor in.
985   Gesture::State stateToUnstage( Gesture::Started );
986
987   // Attach actor to detector
988   SignalData data;
989   UnstageActorFunctor functor( data, stateToUnstage, application.GetScene() );
990   RotationGestureDetector detector = RotationGestureDetector::New();
991   detector.Attach(actor);
992   detector.Attach(dummyActor);
993   detector.DetectedSignal().Connect( &application, functor );
994
995   // Here we are testing a Started actor which is removed in the Started callback, but then added back
996   // before we get a continuing state.  As we were removed from the stage, even if we're at the same
997   // position, we should still not be signalled.
998
999   // Emit signals
1000   TestStartRotation( application,  Vector2( 2.0f, 20.0f ), Vector2( 38.0f, 20.0f ),
1001                                    Vector2( 10.0f, 20.0f ), Vector2( 30.0f, 20.0f ), 100 );
1002   DALI_TEST_EQUALS(true, data.functorCalled, TEST_LOCATION);
1003   data.Reset();
1004
1005   // Render and notify
1006   application.SendNotification();
1007   application.Render();
1008
1009   // Re add to the stage, we should not be signalled
1010   application.GetScene().Add(actor);
1011
1012   // Render and notify
1013   application.SendNotification();
1014   application.Render();
1015
1016   // Continue signal emission
1017   TestContinueRotation( application, Vector2( 10.0f, 20.0f ), Vector2( 30.0f, 20.0f ),
1018                                      Vector2( 15.0f, 20.0f ), Vector2( 25.0f, 20.0f ), 500 );
1019   DALI_TEST_EQUALS(false, data.functorCalled, TEST_LOCATION);
1020   data.Reset();
1021   TestEndRotation( application,  Vector2( 10.0f, 20.0f ), Vector2( 30.0f, 20.0f ),
1022                                  Vector2( 19.0f, 20.0f ), Vector2( 21.0f, 20.0f ), 1000);
1023   DALI_TEST_EQUALS(false, data.functorCalled, TEST_LOCATION);
1024   data.Reset();
1025
1026   // Here we delete an actor in started, we should not receive any subsequent signalling.
1027
1028   // Emit signals
1029   TestStartRotation( application,  Vector2( 2.0f, 20.0f ), Vector2( 38.0f, 20.0f ),
1030                                    Vector2( 10.0f, 20.0f ), Vector2( 30.0f, 20.0f ), 1500 );
1031   DALI_TEST_EQUALS(true, data.functorCalled, TEST_LOCATION);
1032   data.Reset();
1033
1034   // Render and notify
1035   application.SendNotification();
1036   application.Render();
1037
1038   // Delete actor as well
1039   actor.Reset();
1040
1041   // Render and notify
1042   application.SendNotification();
1043   application.Render();
1044
1045   // Continue signal emission
1046   TestContinueRotation( application, Vector2( 10.0f, 20.0f ), Vector2( 30.0f, 20.0f ),
1047                                      Vector2( 15.0f, 20.0f ), Vector2( 25.0f, 20.0f ), 2000 );
1048   DALI_TEST_EQUALS(false, data.functorCalled, TEST_LOCATION);
1049   data.Reset();
1050   TestEndRotation( application,  Vector2( 10.0f, 20.0f ), Vector2( 30.0f, 20.0f ),
1051                                  Vector2( 19.0f, 20.0f ), Vector2( 21.0f, 20.0f ), 3000);
1052   DALI_TEST_EQUALS(false, data.functorCalled, TEST_LOCATION);
1053   END_TEST;
1054 }
1055
1056 int UtcDaliRotationGestureLayerConsumesTouch(void)
1057 {
1058   TestApplication application;
1059
1060   Actor actor = Actor::New();
1061   actor.SetProperty( Actor::Property::SIZE, Vector2( 100.0f, 100.0f ) );
1062   actor.SetProperty( Actor::Property::ANCHOR_POINT,AnchorPoint::TOP_LEFT);
1063   application.GetScene().Add(actor);
1064
1065   // Add a detector
1066   SignalData data;
1067   GestureReceivedFunctor functor(data);
1068   RotationGestureDetector detector = RotationGestureDetector::New();
1069   detector.Attach(actor);
1070   detector.DetectedSignal().Connect( &application, functor );
1071
1072   // Add a layer to overlap the actor
1073   Layer layer = Layer::New();
1074   layer.SetProperty( Actor::Property::SIZE, Vector2( 100.0f, 100.0f ) );
1075   layer.SetProperty( Actor::Property::ANCHOR_POINT,AnchorPoint::TOP_LEFT);
1076   application.GetScene().Add( layer );
1077   layer.RaiseToTop();
1078
1079   // Render and notify
1080   application.SendNotification();
1081   application.Render();
1082
1083   // Emit signals, should receive
1084   TestStartRotation( application,  Vector2( 2.0f, 20.0f ), Vector2( 38.0f, 20.0f ),
1085                                    Vector2( 10.0f, 20.0f ), Vector2( 30.0f, 20.0f ), 100 );
1086   TestEndRotation( application,  Vector2( 10.0f, 20.0f ), Vector2( 30.0f, 20.0f ),
1087                                  Vector2( 19.0f, 20.0f ), Vector2( 21.0f, 20.0f ), 1000);
1088   DALI_TEST_EQUALS(true, data.functorCalled, TEST_LOCATION);
1089   data.Reset();
1090
1091   // Set layer to consume all touch
1092   layer.SetProperty( Layer::Property::CONSUMES_TOUCH, true );
1093
1094   // Render and notify
1095   application.SendNotification();
1096   application.Render();
1097
1098   // Emit the same signals again, should not receive
1099   TestStartRotation( application,  Vector2( 2.0f, 20.0f ), Vector2( 38.0f, 20.0f ),
1100                                    Vector2( 10.0f, 20.0f ), Vector2( 30.0f, 20.0f ), 1500 );
1101   TestEndRotation( application,  Vector2( 10.0f, 20.0f ), Vector2( 30.0f, 20.0f ),
1102                                  Vector2( 19.0f, 20.0f ), Vector2( 21.0f, 20.0f ), 2000);
1103   DALI_TEST_EQUALS(false, data.functorCalled, TEST_LOCATION);
1104   data.Reset();
1105
1106   END_TEST;
1107 }
1108
1109 int UtcDaliRotationGestureInterruptedWhenTouchConsumed(void)
1110 {
1111   TestApplication application;
1112
1113   Actor actor = Actor::New();
1114   actor.SetProperty( Actor::Property::SIZE, Vector2( 100.0f, 100.0f ) );
1115   actor.SetProperty( Actor::Property::ANCHOR_POINT,AnchorPoint::TOP_LEFT);
1116   application.GetScene().Add(actor);
1117
1118   bool consume = false;
1119   TouchDataFunctorConsumeSetter touchFunctor(consume);
1120   actor.TouchSignal().Connect(&application,touchFunctor);
1121
1122   // Render and notify
1123   application.SendNotification();
1124   application.Render();
1125
1126   SignalData data;
1127   GestureReceivedFunctor functor(data);
1128
1129   RotationGestureDetector detector = RotationGestureDetector::New();
1130   detector.Attach(actor);
1131   detector.DetectedSignal().Connect(&application, functor);
1132
1133   // Start gesture within the actor's area, we should receive the pinch as the touch is NOT being consumed
1134   TestStartRotation( application,  Vector2( 2.0f, 20.0f ), Vector2( 38.0f, 20.0f ),
1135                                    Vector2( 10.0f, 20.0f ), Vector2( 30.0f, 20.0f ), 100 );
1136
1137   DALI_TEST_EQUALS(true, data.functorCalled, TEST_LOCATION);
1138   DALI_TEST_EQUALS(Gesture::Started, data.receivedGesture.state, TEST_LOCATION);
1139   data.Reset();
1140
1141   // Continue the gesture within the actor's area, but now the touch consumes thus cancelling the gesture
1142   consume = true;
1143
1144   TestContinueRotation( application, Vector2( 10.0f, 20.0f ), Vector2( 30.0f, 20.0f ),
1145                                      Vector2( 15.0f, 20.0f ), Vector2( 25.0f, 20.0f ), 500 );
1146   DALI_TEST_EQUALS(true, data.functorCalled, TEST_LOCATION);
1147   DALI_TEST_EQUALS(Gesture::Cancelled, data.receivedGesture.state, TEST_LOCATION);
1148   data.Reset();
1149
1150   // Start another pinch, we should not even get the callback this time
1151   TestStartRotation( application,  Vector2( 2.0f, 20.0f ), Vector2( 38.0f, 20.0f ),
1152                                    Vector2( 10.0f, 20.0f ), Vector2( 30.0f, 20.0f ), 100 );
1153   DALI_TEST_EQUALS(false, data.functorCalled, TEST_LOCATION);
1154
1155   END_TEST;
1156 }