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