Revert "[Tizen] Appendix log for ttrace + Print keycode and timestamp"
[platform/core/uifw/dali-core.git] / automated-tests / src / dali / utc-Dali-PinchGestureRecognizer.cpp
1 /*
2  * Copyright (c) 2020 Samsung Electronics Co., Ltd.
3  *
4  * Licensed under the Apache License, Version 2.0 (the "License");
5  * you may not use this file except in compliance with the License.
6  * You may obtain a copy of the License at
7  *
8  * http://www.apache.org/licenses/LICENSE-2.0
9  *
10  * Unless required by applicable law or agreed to in writing, software
11  * distributed under the License is distributed on an "AS IS" BASIS,
12  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13  * See the License for the specific language governing permissions and
14  * limitations under the License.
15  *
16  */
17
18 #include <dali-test-suite-utils.h>
19 #include <dali/integration-api/events/touch-event-integ.h>
20 #include <dali/integration-api/input-options.h>
21 #include <dali/integration-api/render-task-list-integ.h>
22 #include <dali/public-api/dali-core.h>
23 #include <stdlib.h>
24
25 #include <iostream>
26
27 using namespace Dali;
28
29 ///////////////////////////////////////////////////////////////////////////////
30 namespace
31 {
32 struct SignalData
33 {
34   SignalData()
35   : functorCalled(false),
36     voidFunctorCalled(false),
37     receivedGesture()
38   {
39   }
40
41   void Reset()
42   {
43     functorCalled     = false;
44     voidFunctorCalled = false;
45
46     receivedGesture.Reset();
47
48     pinchedActor.Reset();
49   }
50
51   bool         functorCalled;
52   bool         voidFunctorCalled;
53   PinchGesture receivedGesture;
54   Actor        pinchedActor;
55 };
56
57 // Functor that sets the data when called
58 struct GestureReceivedFunctor
59 {
60   GestureReceivedFunctor(SignalData& data)
61   : signalData(data)
62   {
63   }
64
65   void operator()(Actor actor, const PinchGesture& pinch)
66   {
67     signalData.functorCalled   = true;
68     signalData.receivedGesture = pinch;
69     signalData.pinchedActor    = actor;
70   }
71
72   void operator()()
73   {
74     signalData.voidFunctorCalled = true;
75   }
76
77   SignalData& signalData;
78 };
79
80 Integration::TouchEvent GenerateSingleTouch(PointState::Type state, const Vector2& screenPosition, uint32_t time)
81 {
82   Integration::TouchEvent touchEvent;
83   Integration::Point      point;
84   point.SetState(state);
85   point.SetScreenPosition(screenPosition);
86   point.SetDeviceClass(Device::Class::TOUCH);
87   point.SetDeviceSubclass(Device::Subclass::NONE);
88   touchEvent.points.push_back(point);
89   touchEvent.time = time;
90   return touchEvent;
91 }
92
93 Integration::TouchEvent GenerateDoubleTouch(PointState::Type stateA, const Vector2& screenPositionA, PointState::Type stateB, const Vector2& screenPositionB, uint32_t time)
94 {
95   Integration::TouchEvent touchEvent;
96   Integration::Point      point;
97   point.SetState(stateA);
98   point.SetScreenPosition(screenPositionA);
99   point.SetDeviceClass(Device::Class::TOUCH);
100   point.SetDeviceSubclass(Device::Subclass::NONE);
101   touchEvent.points.push_back(point);
102   point.SetScreenPosition(screenPositionB);
103   point.SetState(stateB);
104   touchEvent.points.push_back(point);
105   touchEvent.time = time;
106   return touchEvent;
107 }
108
109 } // namespace
110
111 ///////////////////////////////////////////////////////////////////////////////
112
113 int UtcDaliPinchGestureRecognizerBasicNoAction(void)
114 {
115   TestApplication application;
116
117   PinchGestureDetector detector = PinchGestureDetector::New();
118
119   Actor actor = Actor::New();
120   actor.SetProperty(Actor::Property::SIZE, Vector2(100.0f, 100.0f));
121   actor.SetProperty(Actor::Property::ANCHOR_POINT, AnchorPoint::TOP_LEFT);
122   application.GetScene().Add(actor);
123
124   // Render and notify
125   application.SendNotification();
126   application.Render();
127
128   detector.Attach(actor);
129
130   SignalData             data;
131   GestureReceivedFunctor functor(data);
132   detector.DetectedSignal().Connect(&application, functor);
133
134   application.ProcessEvent(GenerateSingleTouch(PointState::DOWN, Vector2(20.0f, 20.0f), 150));
135
136   application.ProcessEvent(GenerateSingleTouch(PointState::UP, Vector2(20.0f, 20.0f), 200));
137
138   application.SendNotification();
139
140   DALI_TEST_EQUALS(false, data.functorCalled, TEST_LOCATION);
141
142   END_TEST;
143 }
144
145 int UtcDaliPinchGestureRecognizerBasic(void)
146 {
147   TestApplication application;
148
149   PinchGestureDetector detector = PinchGestureDetector::New();
150
151   Actor actor = Actor::New();
152   actor.SetProperty(Actor::Property::SIZE, Vector2(100.0f, 100.0f));
153   actor.SetProperty(Actor::Property::ANCHOR_POINT, AnchorPoint::TOP_LEFT);
154   application.GetScene().Add(actor);
155
156   // Render and notify
157   application.SendNotification();
158   application.Render();
159
160   detector.Attach(actor);
161
162   SignalData             data;
163   GestureReceivedFunctor functor(data);
164   detector.DetectedSignal().Connect(&application, functor);
165
166   application.ProcessEvent(GenerateDoubleTouch(PointState::DOWN, Vector2(20.0f, 20.0f), PointState::DOWN, Vector2(20.0f, 90.0f), 150));
167   application.ProcessEvent(GenerateDoubleTouch(PointState::MOTION, Vector2(20.0f, 28.0f), PointState::MOTION, Vector2(20.0f, 82.0f), 160));
168   application.ProcessEvent(GenerateDoubleTouch(PointState::MOTION, Vector2(20.0f, 37.0f), PointState::MOTION, Vector2(20.0f, 74.0f), 170));
169   application.ProcessEvent(GenerateDoubleTouch(PointState::MOTION, Vector2(20.0f, 46.0f), PointState::MOTION, Vector2(20.0f, 66.0f), 180));
170   application.ProcessEvent(GenerateDoubleTouch(PointState::MOTION, Vector2(20.0f, 55.0f), PointState::MOTION, Vector2(20.0f, 58.0f), 190));
171
172   application.SendNotification();
173
174   DALI_TEST_EQUALS(true, data.functorCalled, TEST_LOCATION);
175
176   END_TEST;
177 }
178
179 int UtcDaliPinchGestureRecognizerEndEarly01(void)
180 {
181   TestApplication application;
182
183   PinchGestureDetector detector = PinchGestureDetector::New();
184
185   Actor actor = Actor::New();
186   actor.SetProperty(Actor::Property::SIZE, Vector2(100.0f, 100.0f));
187   actor.SetProperty(Actor::Property::ANCHOR_POINT, AnchorPoint::TOP_LEFT);
188   application.GetScene().Add(actor);
189
190   // Render and notify
191   application.SendNotification();
192   application.Render();
193
194   detector.Attach(actor);
195
196   SignalData             data;
197   GestureReceivedFunctor functor(data);
198   detector.DetectedSignal().Connect(&application, functor);
199
200   application.ProcessEvent(GenerateDoubleTouch(PointState::DOWN, Vector2(20.0f, 20.0f), PointState::DOWN, Vector2(20.0f, 90.0f), 150));
201   application.ProcessEvent(GenerateDoubleTouch(PointState::MOTION, Vector2(20.0f, 28.0f), PointState::MOTION, Vector2(20.0f, 82.0f), 160));
202   application.ProcessEvent(GenerateSingleTouch(PointState::DOWN, Vector2(20.0f, 29.0f), 165));
203   application.ProcessEvent(GenerateDoubleTouch(PointState::MOTION, Vector2(20.0f, 37.0f), PointState::MOTION, Vector2(20.0f, 74.0f), 170));
204   application.ProcessEvent(GenerateDoubleTouch(PointState::MOTION, Vector2(20.0f, 46.0f), PointState::MOTION, Vector2(20.0f, 66.0f), 180));
205   application.ProcessEvent(GenerateDoubleTouch(PointState::MOTION, Vector2(20.0f, 55.0f), PointState::MOTION, Vector2(20.0f, 58.0f), 190));
206
207   application.SendNotification();
208
209   DALI_TEST_EQUALS(false, data.functorCalled, TEST_LOCATION);
210
211   END_TEST;
212 }
213
214 int UtcDaliPinchGestureRecognizerEndEarly02(void)
215 {
216   TestApplication application;
217
218   PinchGestureDetector detector = PinchGestureDetector::New();
219
220   Actor actor = Actor::New();
221   actor.SetProperty(Actor::Property::SIZE, Vector2(100.0f, 100.0f));
222   actor.SetProperty(Actor::Property::ANCHOR_POINT, AnchorPoint::TOP_LEFT);
223   application.GetScene().Add(actor);
224
225   // Render and notify
226   application.SendNotification();
227   application.Render();
228
229   detector.Attach(actor);
230
231   SignalData             data;
232   GestureReceivedFunctor functor(data);
233   detector.DetectedSignal().Connect(&application, functor);
234
235   application.ProcessEvent(GenerateDoubleTouch(PointState::DOWN, Vector2(20.0f, 20.0f), PointState::DOWN, Vector2(20.0f, 90.0f), 150));
236   application.ProcessEvent(GenerateDoubleTouch(PointState::MOTION, Vector2(20.0f, 28.0f), PointState::MOTION, Vector2(20.0f, 82.0f), 160));
237   application.ProcessEvent(GenerateDoubleTouch(PointState::MOTION, Vector2(20.0f, 37.0f), PointState::MOTION, Vector2(20.0f, 74.0f), 170));
238   application.ProcessEvent(GenerateDoubleTouch(PointState::MOTION, Vector2(20.0f, 37.0f), PointState::UP, Vector2(20.0f, 74.0f), 173));
239   application.ProcessEvent(GenerateDoubleTouch(PointState::MOTION, Vector2(20.0f, 37.0f), PointState::DOWN, Vector2(20.0f, 74.0f), 178));
240   application.ProcessEvent(GenerateDoubleTouch(PointState::MOTION, Vector2(20.0f, 46.0f), PointState::MOTION, Vector2(20.0f, 66.0f), 180));
241   application.ProcessEvent(GenerateDoubleTouch(PointState::MOTION, Vector2(20.0f, 55.0f), PointState::MOTION, Vector2(20.0f, 58.0f), 190));
242
243   application.SendNotification();
244
245   DALI_TEST_EQUALS(false, data.functorCalled, TEST_LOCATION);
246
247   END_TEST;
248 }
249
250 int UtcDaliPinchGestureRecognizerRealistic01(void)
251 {
252   TestApplication application;
253
254   PinchGestureDetector detector = PinchGestureDetector::New();
255
256   Actor actor = Actor::New();
257   actor.SetProperty(Actor::Property::SIZE, Vector2(100.0f, 100.0f));
258   actor.SetProperty(Actor::Property::ANCHOR_POINT, AnchorPoint::TOP_LEFT);
259   application.GetScene().Add(actor);
260
261   // Render and notify
262   application.SendNotification();
263   application.Render();
264
265   detector.Attach(actor);
266
267   SignalData             data;
268   GestureReceivedFunctor functor(data);
269   detector.DetectedSignal().Connect(&application, functor);
270
271   application.ProcessEvent(GenerateSingleTouch(PointState::DOWN, Vector2(20.0f, 20.0f), 100));
272   application.ProcessEvent(GenerateSingleTouch(PointState::UP, Vector2(20.0f, 20.0f), 105));
273   application.ProcessEvent(GenerateSingleTouch(PointState::DOWN, Vector2(20.0f, 20.0f), 110));
274   application.ProcessEvent(GenerateDoubleTouch(PointState::MOTION, Vector2(20.0f, 25.0f), PointState::DOWN, Vector2(20.0f, 90.0f), 115));
275   application.ProcessEvent(GenerateDoubleTouch(PointState::MOTION, Vector2(20.0f, 30.0f), PointState::MOTION, Vector2(20.0f, 85.0f), 120));
276   application.ProcessEvent(GenerateDoubleTouch(PointState::MOTION, Vector2(20.0f, 35.0f), PointState::MOTION, Vector2(20.0f, 80.0f), 125));
277   application.ProcessEvent(GenerateDoubleTouch(PointState::MOTION, Vector2(20.0f, 40.0f), PointState::MOTION, Vector2(20.0f, 75.0f), 130));
278   application.ProcessEvent(GenerateDoubleTouch(PointState::MOTION, Vector2(20.0f, 45.0f), PointState::MOTION, Vector2(20.0f, 70.0f), 135));
279   application.ProcessEvent(GenerateDoubleTouch(PointState::MOTION, Vector2(20.0f, 50.0f), PointState::MOTION, Vector2(20.0f, 65.0f), 140));
280   application.ProcessEvent(GenerateDoubleTouch(PointState::MOTION, Vector2(20.0f, 55.0f), PointState::MOTION, Vector2(20.0f, 60.0f), 145));
281   application.ProcessEvent(GenerateDoubleTouch(PointState::MOTION, Vector2(20.0f, 56.0f), PointState::UP, Vector2(20.0f, 60.0f), 150));
282   application.ProcessEvent(GenerateSingleTouch(PointState::UP, Vector2(20.0f, 56.0f), 155));
283
284   application.SendNotification();
285
286   DALI_TEST_EQUALS(true, data.functorCalled, TEST_LOCATION);
287
288   END_TEST;
289 }
290
291 int UtcDaliPinchGestureRecognizerRealistic02(void)
292 {
293   TestApplication application;
294
295   PinchGestureDetector detector = PinchGestureDetector::New();
296
297   Actor actor = Actor::New();
298   actor.SetProperty(Actor::Property::SIZE, Vector2(100.0f, 100.0f));
299   actor.SetProperty(Actor::Property::ANCHOR_POINT, AnchorPoint::TOP_LEFT);
300   application.GetScene().Add(actor);
301
302   // Render and notify
303   application.SendNotification();
304   application.Render();
305
306   detector.Attach(actor);
307
308   SignalData             data;
309   GestureReceivedFunctor functor(data);
310   detector.DetectedSignal().Connect(&application, functor);
311
312   application.ProcessEvent(GenerateSingleTouch(PointState::DOWN, Vector2(20.0f, 20.0f), 100));
313   application.ProcessEvent(GenerateSingleTouch(PointState::UP, Vector2(20.0f, 20.0f), 105));
314   application.ProcessEvent(GenerateSingleTouch(PointState::DOWN, Vector2(20.0f, 20.0f), 110));
315   application.ProcessEvent(GenerateDoubleTouch(PointState::MOTION, Vector2(20.0f, 25.0f), PointState::DOWN, Vector2(20.0f, 90.0f), 115));
316   application.ProcessEvent(GenerateDoubleTouch(PointState::MOTION, Vector2(20.0f, 30.0f), PointState::MOTION, Vector2(20.0f, 85.0f), 120));
317   application.ProcessEvent(GenerateDoubleTouch(PointState::MOTION, Vector2(20.0f, 35.0f), PointState::MOTION, Vector2(20.0f, 80.0f), 125));
318   application.ProcessEvent(GenerateDoubleTouch(PointState::MOTION, Vector2(20.0f, 40.0f), PointState::MOTION, Vector2(20.0f, 75.0f), 130));
319   application.ProcessEvent(GenerateDoubleTouch(PointState::MOTION, Vector2(20.0f, 45.0f), PointState::MOTION, Vector2(20.0f, 70.0f), 135));
320   application.ProcessEvent(GenerateDoubleTouch(PointState::MOTION, Vector2(20.0f, 50.0f), PointState::MOTION, Vector2(20.0f, 65.0f), 140));
321   application.ProcessEvent(GenerateDoubleTouch(PointState::MOTION, Vector2(20.0f, 55.0f), PointState::MOTION, Vector2(20.0f, 60.0f), 145));
322   application.ProcessEvent(GenerateSingleTouch(PointState::UP, Vector2(20.0f, 56.0f), 155));
323
324   application.SendNotification();
325
326   DALI_TEST_EQUALS(true, data.functorCalled, TEST_LOCATION);
327
328   END_TEST;
329 }
330
331 int UtcDaliPinchGestureRecognizerRealistic03(void)
332 {
333   TestApplication application;
334
335   PinchGestureDetector detector = PinchGestureDetector::New();
336
337   Actor actor = Actor::New();
338   actor.SetProperty(Actor::Property::SIZE, Vector2(100.0f, 100.0f));
339   actor.SetProperty(Actor::Property::ANCHOR_POINT, AnchorPoint::TOP_LEFT);
340   application.GetScene().Add(actor);
341
342   // Render and notify
343   application.SendNotification();
344   application.Render();
345
346   detector.Attach(actor);
347
348   SignalData             data;
349   GestureReceivedFunctor functor(data);
350   detector.DetectedSignal().Connect(&application, functor);
351
352   application.ProcessEvent(GenerateSingleTouch(PointState::DOWN, Vector2(20.0f, 20.0f), 100));
353   application.ProcessEvent(GenerateSingleTouch(PointState::UP, Vector2(20.0f, 20.0f), 105));
354   application.ProcessEvent(GenerateSingleTouch(PointState::DOWN, Vector2(20.0f, 20.0f), 110));
355   application.ProcessEvent(GenerateDoubleTouch(PointState::MOTION, Vector2(20.0f, 25.0f), PointState::DOWN, Vector2(20.0f, 90.0f), 115));
356   application.ProcessEvent(GenerateDoubleTouch(PointState::MOTION, Vector2(20.0f, 30.0f), PointState::MOTION, Vector2(20.0f, 85.0f), 120));
357   application.ProcessEvent(GenerateDoubleTouch(PointState::MOTION, Vector2(20.0f, 35.0f), PointState::MOTION, Vector2(20.0f, 80.0f), 125));
358   application.ProcessEvent(GenerateDoubleTouch(PointState::MOTION, Vector2(20.0f, 37.0f), PointState::MOTION, Vector2(20.0f, 77.0f), 127));
359   application.ProcessEvent(GenerateDoubleTouch(PointState::MOTION, Vector2(20.0f, 40.0f), PointState::MOTION, Vector2(20.0f, 75.0f), 130));
360   application.ProcessEvent(GenerateDoubleTouch(PointState::MOTION, Vector2(20.0f, 47.0f), PointState::MOTION, Vector2(20.0f, 73.0f), 133));
361   application.ProcessEvent(GenerateDoubleTouch(PointState::MOTION, Vector2(20.0f, 45.0f), PointState::MOTION, Vector2(20.0f, 70.0f), 135));
362   application.ProcessEvent(GenerateDoubleTouch(PointState::MOTION, Vector2(20.0f, 47.0f), PointState::MOTION, Vector2(20.0f, 67.0f), 137));
363   application.ProcessEvent(GenerateDoubleTouch(PointState::MOTION, Vector2(20.0f, 50.0f), PointState::MOTION, Vector2(20.0f, 65.0f), 140));
364   application.ProcessEvent(GenerateDoubleTouch(PointState::MOTION, Vector2(20.0f, 53.0f), PointState::MOTION, Vector2(20.0f, 63.0f), 143));
365   application.ProcessEvent(GenerateDoubleTouch(PointState::MOTION, Vector2(20.0f, 55.0f), PointState::MOTION, Vector2(20.0f, 60.0f), 145));
366
367   application.ProcessEvent(GenerateSingleTouch(PointState::UP, Vector2(20.0f, 56.0f), 155));
368
369   application.SendNotification();
370
371   DALI_TEST_EQUALS(true, data.functorCalled, TEST_LOCATION);
372
373   END_TEST;
374 }
375
376 int UtcDaliPinchGestureRecognizerMultipleDetectors(void)
377 {
378   TestApplication application;
379
380   Actor actor = Actor::New();
381   actor.SetProperty(Actor::Property::SIZE, Vector2(100.0f, 100.0f));
382   actor.SetProperty(Actor::Property::ANCHOR_POINT, AnchorPoint::TOP_LEFT);
383   application.GetScene().Add(actor);
384
385   Actor actor2 = Actor::New();
386   actor2.SetProperty(Actor::Property::SIZE, Vector2(100.0f, 100.0f));
387   actor2.SetProperty(Actor::Property::ANCHOR_POINT, AnchorPoint::TOP_LEFT);
388   actor2.SetProperty(Actor::Property::POSITION_X, 100.0f);
389   application.GetScene().Add(actor2);
390
391   // Render and notify
392   application.SendNotification();
393   application.Render();
394
395   PinchGestureDetector detector = PinchGestureDetector::New();
396   detector.Attach(actor);
397
398   PinchGestureDetector detector2 = PinchGestureDetector::New();
399   detector2.Attach(actor2);
400
401   SignalData             data;
402   GestureReceivedFunctor functor(data);
403   detector.DetectedSignal().Connect(&application, functor);
404
405   SignalData             data2;
406   GestureReceivedFunctor functor2(data2);
407   detector2.DetectedSignal().Connect(&application, functor2);
408
409   application.ProcessEvent(GenerateDoubleTouch(PointState::DOWN, Vector2(120.0f, 20.0f), PointState::DOWN, Vector2(120.0f, 90.0f), 150));
410   application.ProcessEvent(GenerateDoubleTouch(PointState::MOTION, Vector2(120.0f, 28.0f), PointState::MOTION, Vector2(120.0f, 82.0f), 160));
411   application.ProcessEvent(GenerateDoubleTouch(PointState::MOTION, Vector2(120.0f, 37.0f), PointState::MOTION, Vector2(120.0f, 74.0f), 170));
412   application.ProcessEvent(GenerateDoubleTouch(PointState::MOTION, Vector2(120.0f, 46.0f), PointState::MOTION, Vector2(120.0f, 66.0f), 180));
413   application.ProcessEvent(GenerateDoubleTouch(PointState::MOTION, Vector2(120.0f, 55.0f), PointState::MOTION, Vector2(120.0f, 58.0f), 190));
414   application.ProcessEvent(GenerateDoubleTouch(PointState::UP, Vector2(120.0f, 55.0f), PointState::UP, Vector2(120.0f, 58.0f), 200));
415
416   application.SendNotification();
417
418   DALI_TEST_EQUALS(false, data.functorCalled, TEST_LOCATION);
419   DALI_TEST_EQUALS(true, data2.functorCalled, TEST_LOCATION);
420   DALI_TEST_EQUALS(true, actor2 == data2.pinchedActor, TEST_LOCATION);
421   data2.Reset();
422
423   application.ProcessEvent(GenerateDoubleTouch(PointState::DOWN, Vector2(20.0f, 20.0f), PointState::DOWN, Vector2(20.0f, 90.0f), 250));
424   application.ProcessEvent(GenerateDoubleTouch(PointState::MOTION, Vector2(20.0f, 28.0f), PointState::MOTION, Vector2(20.0f, 82.0f), 260));
425   application.ProcessEvent(GenerateDoubleTouch(PointState::MOTION, Vector2(20.0f, 37.0f), PointState::MOTION, Vector2(20.0f, 74.0f), 270));
426   application.ProcessEvent(GenerateDoubleTouch(PointState::MOTION, Vector2(20.0f, 46.0f), PointState::MOTION, Vector2(20.0f, 66.0f), 280));
427   application.ProcessEvent(GenerateDoubleTouch(PointState::MOTION, Vector2(20.0f, 55.0f), PointState::MOTION, Vector2(20.0f, 58.0f), 290));
428
429   application.SendNotification();
430
431   DALI_TEST_EQUALS(true, data.functorCalled, TEST_LOCATION);
432   DALI_TEST_EQUALS(true, actor == data.pinchedActor, TEST_LOCATION);
433   DALI_TEST_EQUALS(false, data2.functorCalled, TEST_LOCATION);
434
435   END_TEST;
436 }
437
438 int UtcDaliPinchGestureRecognizerShortDistance01(void)
439 {
440   TestApplication application;
441
442   Integration::SetPinchGestureMinimumDistance(7.0f);
443
444   PinchGestureDetector detector = PinchGestureDetector::New();
445
446   Actor actor = Actor::New();
447   actor.SetProperty(Actor::Property::SIZE, Vector2(100.0f, 100.0f));
448   actor.SetProperty(Actor::Property::ANCHOR_POINT, AnchorPoint::TOP_LEFT);
449   application.GetScene().Add(actor);
450
451   // Render and notify
452   application.SendNotification();
453   application.Render();
454
455   detector.Attach(actor);
456
457   SignalData             data;
458   GestureReceivedFunctor functor(data);
459   detector.DetectedSignal().Connect(&application, functor);
460
461   application.ProcessEvent(GenerateDoubleTouch(PointState::DOWN, Vector2(20.0f, 20.0f), PointState::DOWN, Vector2(20.0f, 90.0f), 150));
462   application.ProcessEvent(GenerateDoubleTouch(PointState::MOTION, Vector2(20.0f, 28.0f), PointState::MOTION, Vector2(20.0f, 82.0f), 160));
463   application.ProcessEvent(GenerateDoubleTouch(PointState::MOTION, Vector2(20.0f, 30.0f), PointState::MOTION, Vector2(20.0f, 80.0f), 170));
464   application.ProcessEvent(GenerateDoubleTouch(PointState::MOTION, Vector2(20.0f, 32.0f), PointState::MOTION, Vector2(20.0f, 78.0f), 180));
465   application.ProcessEvent(GenerateDoubleTouch(PointState::MOTION, Vector2(20.0f, 34.0f), PointState::MOTION, Vector2(20.0f, 76.0f), 190));
466
467   application.SendNotification();
468
469   DALI_TEST_EQUALS(true, data.functorCalled, TEST_LOCATION);
470
471   END_TEST;
472 }
473
474 int UtcDaliPinchGestureRecognizerShortDistance02(void)
475 {
476   TestApplication application;
477
478   PinchGestureDetector detector = PinchGestureDetector::New();
479
480   Actor actor = Actor::New();
481   actor.SetProperty(Actor::Property::SIZE, Vector2(100.0f, 100.0f));
482   actor.SetProperty(Actor::Property::ANCHOR_POINT, AnchorPoint::TOP_LEFT);
483   application.GetScene().Add(actor);
484
485   // Render and notify
486   application.SendNotification();
487   application.Render();
488
489   detector.Attach(actor);
490
491   SignalData             data;
492   GestureReceivedFunctor functor(data);
493   detector.DetectedSignal().Connect(&application, functor);
494
495   Integration::SetPinchGestureMinimumDistance(7.0f);
496
497   application.ProcessEvent(GenerateDoubleTouch(PointState::DOWN, Vector2(20.0f, 20.0f), PointState::DOWN, Vector2(20.0f, 90.0f), 150));
498   application.ProcessEvent(GenerateDoubleTouch(PointState::MOTION, Vector2(20.0f, 28.0f), PointState::MOTION, Vector2(20.0f, 82.0f), 160));
499   application.ProcessEvent(GenerateDoubleTouch(PointState::MOTION, Vector2(20.0f, 30.0f), PointState::MOTION, Vector2(20.0f, 80.0f), 170));
500   application.ProcessEvent(GenerateDoubleTouch(PointState::MOTION, Vector2(20.0f, 32.0f), PointState::MOTION, Vector2(20.0f, 78.0f), 180));
501   application.ProcessEvent(GenerateDoubleTouch(PointState::MOTION, Vector2(20.0f, 34.0f), PointState::MOTION, Vector2(20.0f, 76.0f), 190));
502
503   application.SendNotification();
504
505   DALI_TEST_EQUALS(true, data.functorCalled, TEST_LOCATION);
506
507   END_TEST;
508 }
509
510 int UtcDaliPinchGestureRecognizerLongDistance01(void)
511 {
512   TestApplication application;
513
514   Integration::SetPinchGestureMinimumDistance(14.0f);
515
516   PinchGestureDetector detector = PinchGestureDetector::New();
517
518   Actor actor = Actor::New();
519   actor.SetProperty(Actor::Property::SIZE, Vector2(100.0f, 100.0f));
520   actor.SetProperty(Actor::Property::ANCHOR_POINT, AnchorPoint::TOP_LEFT);
521   application.GetScene().Add(actor);
522
523   // Render and notify
524   application.SendNotification();
525   application.Render();
526
527   detector.Attach(actor);
528
529   SignalData             data;
530   GestureReceivedFunctor functor(data);
531   detector.DetectedSignal().Connect(&application, functor);
532
533   application.ProcessEvent(GenerateDoubleTouch(PointState::DOWN, Vector2(20.0f, 20.0f), PointState::DOWN, Vector2(20.0f, 90.0f), 150));
534   application.ProcessEvent(GenerateDoubleTouch(PointState::MOTION, Vector2(20.0f, 22.0f), PointState::MOTION, Vector2(20.0f, 88.0f), 160));
535   application.ProcessEvent(GenerateDoubleTouch(PointState::MOTION, Vector2(20.0f, 24.0f), PointState::MOTION, Vector2(20.0f, 86.0f), 170));
536   application.ProcessEvent(GenerateDoubleTouch(PointState::MOTION, Vector2(20.0f, 26.0f), PointState::MOTION, Vector2(20.0f, 84.0f), 180));
537
538   application.SendNotification();
539
540   DALI_TEST_EQUALS(false, data.functorCalled, TEST_LOCATION);
541
542   END_TEST;
543 }
544
545 int UtcDaliPinchGestureRecognizerLongDistance02(void)
546 {
547   TestApplication application;
548
549   Integration::SetPinchGestureMinimumDistance(14.0f);
550
551   PinchGestureDetector detector = PinchGestureDetector::New();
552
553   Actor actor = Actor::New();
554   actor.SetProperty(Actor::Property::SIZE, Vector2(100.0f, 100.0f));
555   actor.SetProperty(Actor::Property::ANCHOR_POINT, AnchorPoint::TOP_LEFT);
556   application.GetScene().Add(actor);
557
558   // Render and notify
559   application.SendNotification();
560   application.Render();
561
562   detector.Attach(actor);
563
564   SignalData             data;
565   GestureReceivedFunctor functor(data);
566   detector.DetectedSignal().Connect(&application, functor);
567
568   application.ProcessEvent(GenerateDoubleTouch(PointState::DOWN, Vector2(20.0f, 20.0f), PointState::DOWN, Vector2(20.0f, 90.0f), 150));
569   application.ProcessEvent(GenerateDoubleTouch(PointState::MOTION, Vector2(20.0f, 38.0f), PointState::MOTION, Vector2(20.0f, 72.0f), 160));
570   application.ProcessEvent(GenerateDoubleTouch(PointState::MOTION, Vector2(20.0f, 40.0f), PointState::MOTION, Vector2(20.0f, 70.0f), 170));
571   application.ProcessEvent(GenerateDoubleTouch(PointState::MOTION, Vector2(20.0f, 42.0f), PointState::MOTION, Vector2(20.0f, 68.0f), 180));
572   application.ProcessEvent(GenerateDoubleTouch(PointState::MOTION, Vector2(20.0f, 44.0f), PointState::MOTION, Vector2(20.0f, 66.0f), 190));
573
574   application.SendNotification();
575
576   DALI_TEST_EQUALS(true, data.functorCalled, TEST_LOCATION);
577
578   END_TEST;
579 }
580
581 int UtcDaliPinchGestureRecognizerLongDistance03(void)
582 {
583   TestApplication application;
584
585   PinchGestureDetector detector = PinchGestureDetector::New();
586
587   Actor actor = Actor::New();
588   actor.SetProperty(Actor::Property::SIZE, Vector2(100.0f, 100.0f));
589   actor.SetProperty(Actor::Property::ANCHOR_POINT, AnchorPoint::TOP_LEFT);
590   application.GetScene().Add(actor);
591
592   // Render and notify
593   application.SendNotification();
594   application.Render();
595
596   detector.Attach(actor);
597
598   SignalData             data;
599   GestureReceivedFunctor functor(data);
600   detector.DetectedSignal().Connect(&application, functor);
601
602   Integration::SetPinchGestureMinimumDistance(14.0f);
603
604   application.ProcessEvent(GenerateDoubleTouch(PointState::DOWN, Vector2(20.0f, 20.0f), PointState::DOWN, Vector2(20.0f, 90.0f), 150));
605   application.ProcessEvent(GenerateDoubleTouch(PointState::MOTION, Vector2(20.0f, 22.0f), PointState::MOTION, Vector2(20.0f, 88.0f), 160));
606   application.ProcessEvent(GenerateDoubleTouch(PointState::MOTION, Vector2(20.0f, 24.0f), PointState::MOTION, Vector2(20.0f, 86.0f), 170));
607   application.ProcessEvent(GenerateDoubleTouch(PointState::MOTION, Vector2(20.0f, 26.0f), PointState::MOTION, Vector2(20.0f, 84.0f), 180));
608
609   application.SendNotification();
610
611   DALI_TEST_EQUALS(false, data.functorCalled, TEST_LOCATION);
612
613   END_TEST;
614 }
615
616 int UtcDaliPinchGestureRecognizerLongDistance04(void)
617 {
618   TestApplication application;
619
620   PinchGestureDetector detector = PinchGestureDetector::New();
621
622   Actor actor = Actor::New();
623   actor.SetProperty(Actor::Property::SIZE, Vector2(100.0f, 100.0f));
624   actor.SetProperty(Actor::Property::ANCHOR_POINT, AnchorPoint::TOP_LEFT);
625   application.GetScene().Add(actor);
626
627   // Render and notify
628   application.SendNotification();
629   application.Render();
630
631   detector.Attach(actor);
632
633   SignalData             data;
634   GestureReceivedFunctor functor(data);
635   detector.DetectedSignal().Connect(&application, functor);
636
637   Integration::SetPinchGestureMinimumDistance(14.0f);
638
639   application.ProcessEvent(GenerateDoubleTouch(PointState::DOWN, Vector2(20.0f, 20.0f), PointState::DOWN, Vector2(20.0f, 90.0f), 150));
640   application.ProcessEvent(GenerateDoubleTouch(PointState::MOTION, Vector2(20.0f, 38.0f), PointState::MOTION, Vector2(20.0f, 72.0f), 160));
641   application.ProcessEvent(GenerateDoubleTouch(PointState::MOTION, Vector2(20.0f, 40.0f), PointState::MOTION, Vector2(20.0f, 70.0f), 170));
642   application.ProcessEvent(GenerateDoubleTouch(PointState::MOTION, Vector2(20.0f, 42.0f), PointState::MOTION, Vector2(20.0f, 68.0f), 180));
643   application.ProcessEvent(GenerateDoubleTouch(PointState::MOTION, Vector2(20.0f, 44.0f), PointState::MOTION, Vector2(20.0f, 66.0f), 190));
644
645   application.SendNotification();
646
647   DALI_TEST_EQUALS(true, data.functorCalled, TEST_LOCATION);
648
649   END_TEST;
650 }
651
652 int UtcDaliPinchGestureRecognizerMinimumTouchEvents(void)
653 {
654   TestApplication application;
655
656   PinchGestureDetector detector = PinchGestureDetector::New();
657
658   Actor actor = Actor::New();
659   actor.SetProperty(Actor::Property::SIZE, Vector2(100.0f, 100.0f));
660   actor.SetProperty(Actor::Property::ANCHOR_POINT, AnchorPoint::TOP_LEFT);
661   application.GetScene().Add(actor);
662
663   // Render and notify
664   application.SendNotification();
665   application.Render();
666
667   detector.Attach(actor);
668
669   SignalData             data;
670   GestureReceivedFunctor functor(data);
671   detector.DetectedSignal().Connect(&application, functor);
672
673   // Case 1
674   // 2 touch events make a gesture begin
675   Integration::SetPinchGestureMinimumTouchEvents(2);
676   application.ProcessEvent(GenerateDoubleTouch(PointState::DOWN, Vector2(20.0f, 20.0f), PointState::DOWN, Vector2(20.0f, 90.0f), 150));
677   application.ProcessEvent(GenerateDoubleTouch(PointState::MOTION, Vector2(20.0f, 20.0f), PointState::MOTION, Vector2(90.0f, 90.0f), 160));
678
679   DALI_TEST_EQUALS(GestureState::STARTED, data.receivedGesture.GetState(), TEST_LOCATION);
680   DALI_TEST_EQUALS(true, data.functorCalled, TEST_LOCATION);
681   data.Reset();
682
683   // Case 2
684   // 4 touch events make a gesture begin
685   Integration::SetPinchGestureMinimumTouchEvents(4);
686   application.ProcessEvent(GenerateDoubleTouch(PointState::DOWN, Vector2(20.0f, 20.0f), PointState::DOWN, Vector2(20.0f, 90.0f), 150));
687   application.ProcessEvent(GenerateDoubleTouch(PointState::MOTION, Vector2(20.0f, 20.0f), PointState::MOTION, Vector2(90.0f, 90.0f), 160));
688
689   // Check the gesture is not detected unlike previous case
690   DALI_TEST_EQUALS(false, data.functorCalled, TEST_LOCATION);
691
692   END_TEST;
693 }
694
695 int UtcDaliPinchGestureRecognizerMinimumTouchEventsAfterStart(void)
696 {
697   TestApplication application;
698
699   PinchGestureDetector detector = PinchGestureDetector::New();
700
701   Actor actor = Actor::New();
702   actor.SetProperty(Actor::Property::SIZE, Vector2(100.0f, 100.0f));
703   actor.SetProperty(Actor::Property::ANCHOR_POINT, AnchorPoint::TOP_LEFT);
704   application.GetScene().Add(actor);
705
706   // Render and notify
707   application.SendNotification();
708   application.Render();
709
710   detector.Attach(actor);
711
712   SignalData             data;
713   GestureReceivedFunctor functor(data);
714   detector.DetectedSignal().Connect(&application, functor);
715
716   // Case 1
717   // > 2 touch events make a gesture begin
718   // > 4 touch events generate gestures after begin
719   Integration::SetPinchGestureMinimumTouchEvents(2);
720   Integration::SetPinchGestureMinimumTouchEventsAfterStart(6);
721
722   application.ProcessEvent(GenerateDoubleTouch(PointState::DOWN, Vector2(20.0f, 20.0f), PointState::DOWN, Vector2(20.0f, 90.0f), 150));
723   application.ProcessEvent(GenerateDoubleTouch(PointState::MOTION, Vector2(20.0f, 20.0f), PointState::MOTION, Vector2(90.0f, 90.0f), 160));
724
725   DALI_TEST_EQUALS(GestureState::STARTED, data.receivedGesture.GetState(), TEST_LOCATION);
726   DALI_TEST_EQUALS(true, data.functorCalled, TEST_LOCATION);
727
728   application.ProcessEvent(GenerateDoubleTouch(PointState::MOTION, Vector2(20.0f, 20.0f), PointState::MOTION, Vector2(20.0f, 90.0f), 170));
729   application.ProcessEvent(GenerateDoubleTouch(PointState::MOTION, Vector2(20.0f, 20.0f), PointState::MOTION, Vector2(20.0f, 90.0f), 180));
730   application.ProcessEvent(GenerateDoubleTouch(PointState::MOTION, Vector2(20.0f, 20.0f), PointState::MOTION, Vector2(20.0f, 90.0f), 190));
731   application.ProcessEvent(GenerateDoubleTouch(PointState::MOTION, Vector2(20.0f, 20.0f), PointState::MOTION, Vector2(20.0f, 90.0f), 200));
732   // > Test : not enough touch events to make the gesture state "CONTINUING"
733   DALI_TEST_EQUALS(GestureState::STARTED, data.receivedGesture.GetState(), TEST_LOCATION);
734
735   application.ProcessEvent(GenerateDoubleTouch(PointState::MOTION, Vector2(20.0f, 20.0f), PointState::MOTION, Vector2(20.0f, 90.0f), 210));
736   application.ProcessEvent(GenerateDoubleTouch(PointState::MOTION, Vector2(20.0f, 20.0f), PointState::MOTION, Vector2(20.0f, 90.0f), 220));
737   // > Test : 6 touch events after start make the gesture state "CONTINUING"
738   DALI_TEST_EQUALS(GestureState::CONTINUING, data.receivedGesture.GetState(), TEST_LOCATION);
739
740   END_TEST;
741 }