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