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