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