Moved Gesture::State and -::Type to gesture-enumerations.h.
[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 <iostream>
19
20 #include <stdlib.h>
21 #include <dali/public-api/dali-core.h>
22 #include <dali/integration-api/input-options.h>
23 #include <dali/integration-api/events/touch-event-integ.h>
24 #include <dali/integration-api/render-task-list-integ.h>
25 #include <dali-test-suite-utils.h>
26
27 using namespace Dali;
28
29 ///////////////////////////////////////////////////////////////////////////////
30 namespace
31 {
32
33 struct SignalData
34 {
35   SignalData()
36   : functorCalled(false),
37     voidFunctorCalled(false),
38     receivedGesture()
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) : signalData(data) { }
61
62   void operator()(Actor actor, const PinchGesture& pinch)
63   {
64     signalData.functorCalled = true;
65     signalData.receivedGesture = pinch;
66     signalData.pinchedActor = actor;
67   }
68
69   void operator()()
70   {
71     signalData.voidFunctorCalled = true;
72   }
73
74   SignalData& signalData;
75 };
76
77
78 Integration::TouchEvent GenerateSingleTouch( PointState::Type state, const Vector2& screenPosition, uint32_t time )
79 {
80   Integration::TouchEvent touchEvent;
81   Integration::Point point;
82   point.SetState( state );
83   point.SetScreenPosition( screenPosition );
84   point.SetDeviceClass( Device::Class::TOUCH );
85   point.SetDeviceSubclass( Device::Subclass::NONE );
86   touchEvent.points.push_back( point );
87   touchEvent.time = time;
88   return touchEvent;
89 }
90
91 Integration::TouchEvent GenerateDoubleTouch( PointState::Type stateA, const Vector2& screenPositionA, PointState::Type stateB, const Vector2& screenPositionB, uint32_t time )
92 {
93   Integration::TouchEvent touchEvent;
94   Integration::Point point;
95   point.SetState( stateA );
96   point.SetScreenPosition( screenPositionA );
97   point.SetDeviceClass( Device::Class::TOUCH );
98   point.SetDeviceSubclass( Device::Subclass::NONE );
99   touchEvent.points.push_back( point );
100   point.SetScreenPosition( screenPositionB );
101   point.SetState( stateB);
102   touchEvent.points.push_back( point );
103   touchEvent.time = time;
104   return touchEvent;
105 }
106
107
108 } // anon namespace
109
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
439 int UtcDaliPinchGestureRecognizerShortDistance01(void)
440 {
441   TestApplication application;
442
443   Integration::SetPinchGestureMinimumDistance(7.0f);
444
445   PinchGestureDetector detector = PinchGestureDetector::New();
446
447   Actor actor = Actor::New();
448   actor.SetProperty( Actor::Property::SIZE, Vector2( 100.0f, 100.0f ) );
449   actor.SetProperty( Actor::Property::ANCHOR_POINT,AnchorPoint::TOP_LEFT);
450   application.GetScene().Add(actor);
451
452   // Render and notify
453   application.SendNotification();
454   application.Render();
455
456   detector.Attach(actor);
457
458   SignalData data;
459   GestureReceivedFunctor functor(data);
460   detector.DetectedSignal().Connect(&application, functor);
461
462   application.ProcessEvent( GenerateDoubleTouch( PointState::DOWN, Vector2( 20.0f, 20.0f ), PointState::DOWN, Vector2( 20.0f, 90.0f ), 150 ) );
463   application.ProcessEvent( GenerateDoubleTouch( PointState::MOTION, Vector2( 20.0f, 28.0f ), PointState::MOTION, Vector2( 20.0f, 82.0f ), 160 ) );
464   application.ProcessEvent( GenerateDoubleTouch( PointState::MOTION, Vector2( 20.0f, 30.0f ), PointState::MOTION, Vector2( 20.0f, 80.0f ), 170 ) );
465   application.ProcessEvent( GenerateDoubleTouch( PointState::MOTION, Vector2( 20.0f, 32.0f ), PointState::MOTION, Vector2( 20.0f, 78.0f ), 180 ) );
466   application.ProcessEvent( GenerateDoubleTouch( PointState::MOTION, Vector2( 20.0f, 34.0f ), PointState::MOTION, Vector2( 20.0f, 76.0f ), 190 ) );
467
468   application.SendNotification();
469
470   DALI_TEST_EQUALS(true, data.functorCalled, TEST_LOCATION);
471
472   END_TEST;
473 }
474
475 int UtcDaliPinchGestureRecognizerShortDistance02(void)
476 {
477   TestApplication application;
478
479   PinchGestureDetector detector = PinchGestureDetector::New();
480
481   Actor actor = Actor::New();
482   actor.SetProperty( Actor::Property::SIZE, Vector2( 100.0f, 100.0f ) );
483   actor.SetProperty( Actor::Property::ANCHOR_POINT,AnchorPoint::TOP_LEFT);
484   application.GetScene().Add(actor);
485
486   // Render and notify
487   application.SendNotification();
488   application.Render();
489
490   detector.Attach(actor);
491
492   SignalData data;
493   GestureReceivedFunctor functor(data);
494   detector.DetectedSignal().Connect(&application, functor);
495
496   Integration::SetPinchGestureMinimumDistance(7.0f);
497
498   application.ProcessEvent( GenerateDoubleTouch( PointState::DOWN, Vector2( 20.0f, 20.0f ), PointState::DOWN, Vector2( 20.0f, 90.0f ), 150 ) );
499   application.ProcessEvent( GenerateDoubleTouch( PointState::MOTION, Vector2( 20.0f, 28.0f ), PointState::MOTION, Vector2( 20.0f, 82.0f ), 160 ) );
500   application.ProcessEvent( GenerateDoubleTouch( PointState::MOTION, Vector2( 20.0f, 30.0f ), PointState::MOTION, Vector2( 20.0f, 80.0f ), 170 ) );
501   application.ProcessEvent( GenerateDoubleTouch( PointState::MOTION, Vector2( 20.0f, 32.0f ), PointState::MOTION, Vector2( 20.0f, 78.0f ), 180 ) );
502   application.ProcessEvent( GenerateDoubleTouch( PointState::MOTION, Vector2( 20.0f, 34.0f ), PointState::MOTION, Vector2( 20.0f, 76.0f ), 190 ) );
503
504   application.SendNotification();
505
506   DALI_TEST_EQUALS(true, data.functorCalled, TEST_LOCATION);
507
508   END_TEST;
509 }
510
511 int UtcDaliPinchGestureRecognizerLongDistance01(void)
512 {
513   TestApplication application;
514
515   Integration::SetPinchGestureMinimumDistance(14.0f);
516
517   PinchGestureDetector detector = PinchGestureDetector::New();
518
519   Actor actor = Actor::New();
520   actor.SetProperty( Actor::Property::SIZE, Vector2( 100.0f, 100.0f ) );
521   actor.SetProperty( Actor::Property::ANCHOR_POINT,AnchorPoint::TOP_LEFT);
522   application.GetScene().Add(actor);
523
524   // Render and notify
525   application.SendNotification();
526   application.Render();
527
528   detector.Attach(actor);
529
530   SignalData data;
531   GestureReceivedFunctor functor(data);
532   detector.DetectedSignal().Connect(&application, functor);
533
534   application.ProcessEvent( GenerateDoubleTouch( PointState::DOWN, Vector2( 20.0f, 20.0f ), PointState::DOWN, Vector2( 20.0f, 90.0f ), 150 ) );
535   application.ProcessEvent( GenerateDoubleTouch( PointState::MOTION, Vector2( 20.0f, 22.0f ), PointState::MOTION, Vector2( 20.0f, 88.0f ), 160 ) );
536   application.ProcessEvent( GenerateDoubleTouch( PointState::MOTION, Vector2( 20.0f, 24.0f ), PointState::MOTION, Vector2( 20.0f, 86.0f ), 170 ) );
537   application.ProcessEvent( GenerateDoubleTouch( PointState::MOTION, Vector2( 20.0f, 26.0f ), PointState::MOTION, Vector2( 20.0f, 84.0f ), 180 ) );
538
539   application.SendNotification();
540
541   DALI_TEST_EQUALS(false, data.functorCalled, TEST_LOCATION);
542
543   END_TEST;
544 }
545
546 int UtcDaliPinchGestureRecognizerLongDistance02(void)
547 {
548   TestApplication application;
549
550   Integration::SetPinchGestureMinimumDistance(14.0f);
551
552   PinchGestureDetector detector = PinchGestureDetector::New();
553
554   Actor actor = Actor::New();
555   actor.SetProperty( Actor::Property::SIZE, Vector2( 100.0f, 100.0f ) );
556   actor.SetProperty( Actor::Property::ANCHOR_POINT,AnchorPoint::TOP_LEFT);
557   application.GetScene().Add(actor);
558
559   // Render and notify
560   application.SendNotification();
561   application.Render();
562
563   detector.Attach(actor);
564
565   SignalData data;
566   GestureReceivedFunctor functor(data);
567   detector.DetectedSignal().Connect(&application, functor);
568
569   application.ProcessEvent( GenerateDoubleTouch( PointState::DOWN, Vector2( 20.0f, 20.0f ), PointState::DOWN, Vector2( 20.0f, 90.0f ), 150 ) );
570   application.ProcessEvent( GenerateDoubleTouch( PointState::MOTION, Vector2( 20.0f, 38.0f ), PointState::MOTION, Vector2( 20.0f, 72.0f ), 160 ) );
571   application.ProcessEvent( GenerateDoubleTouch( PointState::MOTION, Vector2( 20.0f, 40.0f ), PointState::MOTION, Vector2( 20.0f, 70.0f ), 170 ) );
572   application.ProcessEvent( GenerateDoubleTouch( PointState::MOTION, Vector2( 20.0f, 42.0f ), PointState::MOTION, Vector2( 20.0f, 68.0f ), 180 ) );
573   application.ProcessEvent( GenerateDoubleTouch( PointState::MOTION, Vector2( 20.0f, 44.0f ), PointState::MOTION, Vector2( 20.0f, 66.0f ), 190 ) );
574
575   application.SendNotification();
576
577   DALI_TEST_EQUALS(true, data.functorCalled, TEST_LOCATION);
578
579   END_TEST;
580 }
581
582 int UtcDaliPinchGestureRecognizerLongDistance03(void)
583 {
584   TestApplication application;
585
586   PinchGestureDetector detector = PinchGestureDetector::New();
587
588   Actor actor = Actor::New();
589   actor.SetProperty( Actor::Property::SIZE, Vector2( 100.0f, 100.0f ) );
590   actor.SetProperty( Actor::Property::ANCHOR_POINT,AnchorPoint::TOP_LEFT);
591   application.GetScene().Add(actor);
592
593   // Render and notify
594   application.SendNotification();
595   application.Render();
596
597   detector.Attach(actor);
598
599   SignalData data;
600   GestureReceivedFunctor functor(data);
601   detector.DetectedSignal().Connect(&application, functor);
602
603   Integration::SetPinchGestureMinimumDistance(14.0f);
604
605   application.ProcessEvent( GenerateDoubleTouch( PointState::DOWN, Vector2( 20.0f, 20.0f ), PointState::DOWN, Vector2( 20.0f, 90.0f ), 150 ) );
606   application.ProcessEvent( GenerateDoubleTouch( PointState::MOTION, Vector2( 20.0f, 22.0f ), PointState::MOTION, Vector2( 20.0f, 88.0f ), 160 ) );
607   application.ProcessEvent( GenerateDoubleTouch( PointState::MOTION, Vector2( 20.0f, 24.0f ), PointState::MOTION, Vector2( 20.0f, 86.0f ), 170 ) );
608   application.ProcessEvent( GenerateDoubleTouch( PointState::MOTION, Vector2( 20.0f, 26.0f ), PointState::MOTION, Vector2( 20.0f, 84.0f ), 180 ) );
609
610   application.SendNotification();
611
612   DALI_TEST_EQUALS(false, data.functorCalled, TEST_LOCATION);
613
614   END_TEST;
615 }
616
617 int UtcDaliPinchGestureRecognizerLongDistance04(void)
618 {
619   TestApplication application;
620
621   PinchGestureDetector detector = PinchGestureDetector::New();
622
623   Actor actor = Actor::New();
624   actor.SetProperty( Actor::Property::SIZE, Vector2( 100.0f, 100.0f ) );
625   actor.SetProperty( Actor::Property::ANCHOR_POINT,AnchorPoint::TOP_LEFT);
626   application.GetScene().Add(actor);
627
628   // Render and notify
629   application.SendNotification();
630   application.Render();
631
632   detector.Attach(actor);
633
634   SignalData data;
635   GestureReceivedFunctor functor(data);
636   detector.DetectedSignal().Connect(&application, functor);
637
638   Integration::SetPinchGestureMinimumDistance(14.0f);
639
640   application.ProcessEvent( GenerateDoubleTouch( PointState::DOWN, Vector2( 20.0f, 20.0f ), PointState::DOWN, Vector2( 20.0f, 90.0f ), 150 ) );
641   application.ProcessEvent( GenerateDoubleTouch( PointState::MOTION, Vector2( 20.0f, 38.0f ), PointState::MOTION, Vector2( 20.0f, 72.0f ), 160 ) );
642   application.ProcessEvent( GenerateDoubleTouch( PointState::MOTION, Vector2( 20.0f, 40.0f ), PointState::MOTION, Vector2( 20.0f, 70.0f ), 170 ) );
643   application.ProcessEvent( GenerateDoubleTouch( PointState::MOTION, Vector2( 20.0f, 42.0f ), PointState::MOTION, Vector2( 20.0f, 68.0f ), 180 ) );
644   application.ProcessEvent( GenerateDoubleTouch( PointState::MOTION, Vector2( 20.0f, 44.0f ), PointState::MOTION, Vector2( 20.0f, 66.0f ), 190 ) );
645
646   application.SendNotification();
647
648   DALI_TEST_EQUALS(true, data.functorCalled, TEST_LOCATION);
649
650   END_TEST;
651 }
652
653 int UtcDaliPinchGestureRecognizerMinimumTouchEvents(void)
654 {
655   TestApplication application;
656
657   PinchGestureDetector detector = PinchGestureDetector::New();
658
659   Actor actor = Actor::New();
660   actor.SetProperty( Actor::Property::SIZE, Vector2( 100.0f, 100.0f ) );
661   actor.SetProperty( Actor::Property::ANCHOR_POINT, AnchorPoint::TOP_LEFT );
662   application.GetScene().Add( actor );
663
664   // Render and notify
665   application.SendNotification();
666   application.Render();
667
668   detector.Attach( actor );
669
670   SignalData data;
671   GestureReceivedFunctor functor( data );
672   detector.DetectedSignal().Connect( &application, functor );
673
674   // Case 1
675   // 2 touch events make a gesture begin
676   Integration::SetPinchGestureMinimumTouchEvents( 2 );
677   application.ProcessEvent( GenerateDoubleTouch( PointState::DOWN, Vector2( 20.0f, 20.0f ), PointState::DOWN, Vector2( 20.0f, 90.0f ), 150 ) );
678   application.ProcessEvent( GenerateDoubleTouch( PointState::MOTION, Vector2( 20.0f, 20.0f ), PointState::MOTION, Vector2( 90.0f, 90.0f ), 160 ) );
679
680   DALI_TEST_EQUALS( GestureState::STARTED, data.receivedGesture.GetState(), TEST_LOCATION );
681   DALI_TEST_EQUALS( true, data.functorCalled, TEST_LOCATION );
682   data.Reset();
683
684   // Case 2
685   // 4 touch events make a gesture begin
686   Integration::SetPinchGestureMinimumTouchEvents( 4 );
687   application.ProcessEvent( GenerateDoubleTouch( PointState::DOWN, Vector2( 20.0f, 20.0f ), PointState::DOWN, Vector2( 20.0f, 90.0f ), 150 ) );
688   application.ProcessEvent( GenerateDoubleTouch( PointState::MOTION, Vector2( 20.0f, 20.0f ), PointState::MOTION, Vector2( 90.0f, 90.0f ), 160 ) );
689
690   // Check the gesture is not detected unlike previous case
691   DALI_TEST_EQUALS( false, data.functorCalled, TEST_LOCATION );
692
693   END_TEST;
694 }
695
696 int UtcDaliPinchGestureRecognizerMinimumTouchEventsAfterStart(void)
697 {
698   TestApplication application;
699
700   PinchGestureDetector detector = PinchGestureDetector::New();
701
702   Actor actor = Actor::New();
703   actor.SetProperty( Actor::Property::SIZE, Vector2( 100.0f, 100.0f ) );
704   actor.SetProperty( Actor::Property::ANCHOR_POINT, AnchorPoint::TOP_LEFT );
705   application.GetScene().Add( actor );
706
707   // Render and notify
708   application.SendNotification();
709   application.Render();
710
711   detector.Attach( actor );
712
713   SignalData data;
714   GestureReceivedFunctor functor( data );
715   detector.DetectedSignal().Connect( &application, functor );
716
717   // Case 1
718   // > 2 touch events make a gesture begin
719   // > 4 touch events generate gestures after begin
720   Integration::SetPinchGestureMinimumTouchEvents(2);
721   Integration::SetPinchGestureMinimumTouchEventsAfterStart(6);
722
723   application.ProcessEvent( GenerateDoubleTouch( PointState::DOWN, Vector2( 20.0f, 20.0f ), PointState::DOWN, Vector2( 20.0f, 90.0f ), 150 ) );
724   application.ProcessEvent( GenerateDoubleTouch( PointState::MOTION, Vector2( 20.0f, 20.0f ), PointState::MOTION, Vector2( 90.0f, 90.0f ), 160 ) );
725
726   DALI_TEST_EQUALS(GestureState::STARTED, data.receivedGesture.GetState(), TEST_LOCATION);
727   DALI_TEST_EQUALS(true, data.functorCalled, TEST_LOCATION);
728
729   application.ProcessEvent( GenerateDoubleTouch( PointState::MOTION, Vector2( 20.0f, 20.0f ), PointState::MOTION, Vector2( 20.0f, 90.0f ), 170 ) );
730   application.ProcessEvent( GenerateDoubleTouch( PointState::MOTION, Vector2( 20.0f, 20.0f ), PointState::MOTION, Vector2( 20.0f, 90.0f ), 180 ) );
731   application.ProcessEvent( GenerateDoubleTouch( PointState::MOTION, Vector2( 20.0f, 20.0f ), PointState::MOTION, Vector2( 20.0f, 90.0f ), 190 ) );
732   application.ProcessEvent( GenerateDoubleTouch( PointState::MOTION, Vector2( 20.0f, 20.0f ), PointState::MOTION, Vector2( 20.0f, 90.0f ), 200 ) );
733   // > Test : not enough touch events to make the gesture state "CONTINUING"
734   DALI_TEST_EQUALS(GestureState::STARTED, data.receivedGesture.GetState(), TEST_LOCATION);
735
736   application.ProcessEvent( GenerateDoubleTouch( PointState::MOTION, Vector2( 20.0f, 20.0f ), PointState::MOTION, Vector2( 20.0f, 90.0f ), 210 ) );
737   application.ProcessEvent( GenerateDoubleTouch( PointState::MOTION, Vector2( 20.0f, 20.0f ), PointState::MOTION, Vector2( 20.0f, 90.0f ), 220 ) );
738   // > Test : 6 touch events after start make the gesture state "CONTINUING"
739   DALI_TEST_EQUALS(GestureState::CONTINUING, data.receivedGesture.GetState(), TEST_LOCATION);
740
741   END_TEST;
742 }