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