844a67aeba72fe14ead2320ea3731c586c12b6a5
[platform/core/uifw/dali-core.git] / automated-tests / src / dali / utc-Dali-TouchDataProcessing.cpp
1 /*
2  * Copyright (c) 2016 Samsung Electronics Co., Ltd.
3  *
4  * Licensed under the Apache License, Version 2.0 (the "License");
5  * you may not use this file except in compliance with the License.
6  * You may obtain a copy of the License at
7  *
8  * http://www.apache.org/licenses/LICENSE-2.0
9  *
10  * Unless required by applicable law or agreed to in writing, software
11  * distributed under the License is distributed on an "AS IS" BASIS,
12  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13  * See the License for the specific language governing permissions and
14  * limitations under the License.
15  *
16  */
17
18 #include <iostream>
19
20 #include <stdlib.h>
21 #include <dali/public-api/dali-core.h>
22 #include <dali/integration-api/events/touch-event-integ.h>
23 #include <dali/integration-api/system-overlay.h>
24 #include <dali/devel-api/events/touch-event-devel.h>
25 #include <dali-test-suite-utils.h>
26
27 using namespace Dali;
28
29 void utc_dali_touch_data_processing_startup(void)
30 {
31   test_return_value = TET_UNDEF;
32 }
33
34 void utc_dali_touch_data_processing_cleanup(void)
35 {
36   test_return_value = TET_PASS;
37 }
38
39 ///////////////////////////////////////////////////////////////////////////////
40
41 namespace
42 {
43 struct TestPoint
44 {
45   int32_t deviceId;
46   PointState::Type state;
47   Actor hitActor;
48   Vector2 local;
49   Vector2 screen;
50   float radius;
51   Vector2 ellipseRadius;
52   float pressure;
53   Degree angle;
54   DevelDevice::Class::Type deviceClass;
55   DevelDevice::Subclass::Type deviceSubclass;
56
57   TestPoint()
58   : deviceId(-1), state(PointState::FINISHED), radius(0), pressure(0)
59   {
60   }
61   static const TestPoint ZERO;
62 };
63
64 const TestPoint TestPoint::ZERO;
65
66
67 // Stores data that is populated in the callback and will be read by the TET cases
68 struct SignalData
69 {
70   SignalData()
71   : functorCalled( false ),
72     touchData(),
73     touchedActor()
74   {
75   }
76
77   struct TestTouchData
78   {
79     unsigned long time;
80     std::vector<TestPoint> points;
81
82     const TestPoint& GetPoint(size_t i)
83     {
84       if( i < points.size() )
85       {
86         return points[i];
87       }
88       return TestPoint::ZERO;
89     }
90     size_t GetPointCount()
91     {
92       return points.size();
93     }
94   };
95
96   void Reset()
97   {
98     functorCalled = false;
99
100     touchData.time = 0u;
101     touchData.points.clear();
102
103     touchedActor.Reset();
104   }
105
106   bool functorCalled;
107   TestTouchData touchData;
108   Actor touchedActor;
109 };
110
111 // Functor that sets the data when called
112 struct TouchDataFunctor
113 {
114   /**
115    * Constructor.
116    * @param[in]  data         Reference to the data to store callback information.
117    * @param[in]  returnValue  What the functor should return.
118    */
119   TouchDataFunctor( SignalData& data, bool returnValue = true )
120   : signalData( data ),
121     returnValue( returnValue )
122   {
123   }
124
125   bool operator()( Actor actor, const TouchData& touchData )
126   {
127     signalData.functorCalled = true;
128     signalData.touchedActor = actor;
129
130     signalData.touchData.time = touchData.GetTime();
131     signalData.touchData.points.clear();
132
133     for( size_t i=0; i<touchData.GetPointCount(); ++i )
134     {
135       TestPoint p;
136       p.deviceId = touchData.GetDeviceId(i);
137       p.state = touchData.GetState(i);
138       p.hitActor = touchData.GetHitActor(i);
139       p.local = touchData.GetLocalPosition(i);
140       p.screen = touchData.GetScreenPosition(i);
141       p.radius = touchData.GetRadius(i);
142       p.ellipseRadius = touchData.GetEllipseRadius(i);
143       p.pressure = touchData.GetPressure(i);
144       p.angle = touchData.GetAngle(i);
145       p.deviceClass = DevelTouchData::GetDeviceClass(touchData, i);
146       p.deviceSubclass = DevelTouchData::GetDeviceSubclass(touchData, i);
147       signalData.touchData.points.push_back(p);
148     }
149
150     return returnValue;
151   }
152
153   SignalData& signalData;
154   bool returnValue;
155 };
156
157 struct HandleData
158 {
159   bool signalReceived;
160   TouchData touchData;
161
162   HandleData()
163   : signalReceived(false)
164   {
165   }
166 };
167
168 struct TouchDataHandleFunctor
169 {
170   /**
171    * Constructor.
172    * @param[in]  data         Reference to the data to store callback information.
173    * @param[in]  returnValue  What the functor should return.
174    */
175   TouchDataHandleFunctor( HandleData& handleData, bool returnValue = true )
176   : handleData(handleData),
177     returnValue( returnValue )
178   {
179   }
180
181   bool operator()( Actor actor, const TouchData& someTouchData )
182   {
183     handleData.signalReceived = true;
184     TouchData handle(someTouchData);
185     handleData.touchData = handle;
186     return returnValue;
187   }
188
189   HandleData& handleData;
190   bool returnValue;
191 };
192
193
194 // Functor that removes the actor when called.
195 struct RemoveActorFunctor : public TouchDataFunctor
196 {
197   /**
198    * Constructor.
199    * @param[in]  data         Reference to the data to store callback information.
200    * @param[in]  returnValue  What the functor should return.
201    */
202   RemoveActorFunctor( SignalData& data, bool returnValue = true )
203   : TouchDataFunctor( data, returnValue )
204   {
205   }
206
207   bool operator()( Actor actor, const TouchData& touchData )
208   {
209     Actor parent( actor.GetParent() );
210     if ( parent )
211     {
212       parent.Remove( actor );
213     }
214
215     return TouchDataFunctor::operator()( actor, touchData );
216   }
217 };
218
219 struct OutOfBoundsData
220 {
221   TestPoint point;
222   bool functorCalled;
223
224   OutOfBoundsData()
225   :functorCalled(false)
226   {
227   }
228 };
229
230 // Functor that reads out of bounds data when called
231 struct OutOfBoundsFunctor
232 {
233   /**
234    * Constructor.
235    * @param[in]  data         Reference to the data to store callback information.
236    * @param[in]  returnValue  What the functor should return.
237    */
238   OutOfBoundsFunctor( OutOfBoundsData& data, bool returnValue = true )
239   : outOfBoundsData ( data ),
240     returnValue( returnValue )
241   {
242   }
243
244   bool operator()( Actor actor, const TouchData& touchData )
245   {
246     outOfBoundsData.functorCalled = true;
247     size_t count = touchData.GetPointCount();
248
249     // Read out of bounds data
250     outOfBoundsData.point.deviceId = touchData.GetDeviceId(count+1);
251     outOfBoundsData.point.state = touchData.GetState(count+1);
252     outOfBoundsData.point.hitActor = touchData.GetHitActor(count+1);
253     outOfBoundsData.point.local = touchData.GetLocalPosition(count+1);
254     outOfBoundsData.point.screen = touchData.GetScreenPosition(count+1);
255
256     return returnValue;
257   }
258
259   OutOfBoundsData& outOfBoundsData;
260   bool returnValue;
261 };
262
263 struct TouchEventFunctor
264 {
265   /**
266    * Constructor.
267    * @param[in]  functorCalled  Reference to a boolean which is set to true if the touch event functor is called.
268    */
269   TouchEventFunctor( bool& functorCalled )
270   : functorCalled( functorCalled )
271   {
272   }
273
274   bool operator()( Actor actor, const TouchEvent& touch )
275   {
276     functorCalled = true;
277     return true;
278   }
279
280   bool& functorCalled;
281 };
282
283 Integration::TouchEvent GenerateSingleTouch( PointState::Type state, const Vector2& screenPosition )
284 {
285   Integration::TouchEvent touchEvent;
286   Integration::Point point;
287   point.SetState( state );
288   point.SetScreenPosition( screenPosition );
289   point.SetDeviceClass( DevelDevice::Class::TOUCH );
290   point.SetDeviceSubclass( DevelDevice::Subclass::NONE );
291   touchEvent.points.push_back( point );
292   return touchEvent;
293 }
294
295 } // anon namespace
296
297 ///////////////////////////////////////////////////////////////////////////////
298
299 int UtcDaliTouchDataNormalProcessing01(void)
300 {
301   TestApplication application;
302
303   Actor actor = Actor::New();
304   actor.SetSize(100.0f, 100.0f);
305   actor.SetAnchorPoint(AnchorPoint::TOP_LEFT);
306   Stage::GetCurrent().Add(actor);
307
308   // Render and notify
309   application.SendNotification();
310   application.Render();
311
312   // Connect to actor's touched signal
313   SignalData data;
314   TouchDataFunctor functor( data );
315   actor.TouchSignal().Connect( &application, functor );
316
317   Vector2 screenCoordinates( 10.0f, 10.0f );
318   Vector2 localCoordinates;
319   actor.ScreenToLocal( localCoordinates.x, localCoordinates.y, screenCoordinates.x, screenCoordinates.y );
320
321   // Emit a down signal
322   application.ProcessEvent( GenerateSingleTouch( PointState::DOWN, screenCoordinates ) );
323   const TestPoint *point1 = &data.touchData.GetPoint(0);
324   DALI_TEST_EQUALS( true, data.functorCalled, TEST_LOCATION );
325   DALI_TEST_EQUALS( 1u, data.touchData.GetPointCount(), TEST_LOCATION );
326   DALI_TEST_EQUALS( PointState::DOWN, point1->state, TEST_LOCATION );
327   DALI_TEST_EQUALS( screenCoordinates, point1->screen, TEST_LOCATION );
328   DALI_TEST_EQUALS( localCoordinates, point1->local, 0.1f, TEST_LOCATION );
329   data.Reset();
330
331   // Emit a motion signal
332   screenCoordinates.x = screenCoordinates.y = 11.0f;
333   actor.ScreenToLocal( localCoordinates.x, localCoordinates.y, screenCoordinates.x, screenCoordinates.y );
334   application.ProcessEvent( GenerateSingleTouch( PointState::MOTION, screenCoordinates ) );
335   const TestPoint *point2 = &data.touchData.GetPoint(0);
336   DALI_TEST_EQUALS( true, data.functorCalled, TEST_LOCATION );
337   DALI_TEST_EQUALS( 1u, data.touchData.GetPointCount(), TEST_LOCATION );
338   DALI_TEST_EQUALS( PointState::MOTION, point2->state, TEST_LOCATION );
339   DALI_TEST_EQUALS( screenCoordinates, point2->screen, TEST_LOCATION );
340   DALI_TEST_EQUALS( localCoordinates, point2->local, 0.1f, TEST_LOCATION );
341   data.Reset();
342
343   // Emit an up signal
344   screenCoordinates.x = screenCoordinates.y = 12.0f;
345   actor.ScreenToLocal( localCoordinates.x, localCoordinates.y, screenCoordinates.x, screenCoordinates.y );
346   application.ProcessEvent( GenerateSingleTouch( PointState::UP, screenCoordinates ) );
347   const TestPoint *point3 = &data.touchData.GetPoint(0);
348   DALI_TEST_EQUALS( true, data.functorCalled, TEST_LOCATION );
349   DALI_TEST_EQUALS( 1u, data.touchData.GetPointCount(), TEST_LOCATION );
350   DALI_TEST_EQUALS( PointState::UP, point3->state, TEST_LOCATION );
351   DALI_TEST_EQUALS( screenCoordinates, point3->screen, TEST_LOCATION );
352   DALI_TEST_EQUALS( localCoordinates, point3->local, 0.1f, TEST_LOCATION );
353   data.Reset();
354
355   // Emit a down signal where the actor is not present
356   screenCoordinates.x = screenCoordinates.y = 200.0f;
357   application.ProcessEvent( GenerateSingleTouch( PointState::DOWN, screenCoordinates ) );
358   DALI_TEST_EQUALS( false, data.functorCalled, TEST_LOCATION );
359   END_TEST;
360 }
361
362
363 int UtcDaliTouchDataNormalProcessing02(void)
364 {
365   TestApplication application;
366
367   Actor actor = Actor::New();
368   actor.SetSize(100.0f, 100.0f);
369   actor.SetAnchorPoint(AnchorPoint::TOP_LEFT);
370   Stage::GetCurrent().Add(actor);
371
372   // Render and notify
373   application.SendNotification();
374   application.Render();
375
376   // Connect to actor's touched signal
377   HandleData handleData;
378   TouchDataHandleFunctor functor( handleData );
379   actor.TouchSignal().Connect( &application, functor );
380
381   Vector2 screenCoordinates( 10.0f, 10.0f );
382   Vector2 localCoordinates;
383   actor.ScreenToLocal( localCoordinates.x, localCoordinates.y, screenCoordinates.x, screenCoordinates.y );
384
385   // Emit a down signal
386   application.ProcessEvent( GenerateSingleTouch( PointState::DOWN, screenCoordinates ) );
387   DALI_TEST_EQUALS( true, handleData.signalReceived, TEST_LOCATION );
388   DALI_TEST_EQUALS( 1u, handleData.touchData.GetPointCount(), TEST_LOCATION );
389   DALI_TEST_EQUALS( PointState::DOWN, handleData.touchData.GetState(0), TEST_LOCATION );
390   DALI_TEST_EQUALS( screenCoordinates, handleData.touchData.GetScreenPosition(0), TEST_LOCATION );
391   DALI_TEST_EQUALS( localCoordinates, handleData.touchData.GetLocalPosition(0), 0.1f, TEST_LOCATION );
392
393   END_TEST;
394 }
395
396
397 int UtcDaliTouchDataAPINegative(void)
398 {
399   TestApplication application;
400
401   Actor actor = Actor::New();
402   actor.SetSize(100.0f, 100.0f);
403   actor.SetAnchorPoint(AnchorPoint::TOP_LEFT);
404   Stage::GetCurrent().Add(actor);
405
406   // Render and notify
407   application.SendNotification();
408   application.Render();
409
410   // Connect to actor's touched signal
411   OutOfBoundsData data;
412   OutOfBoundsFunctor functor( data, true );
413   actor.TouchSignal().Connect( &application, functor );
414
415   Vector2 screenCoordinates( 10.0f, 10.0f );
416   Vector2 localCoordinates;
417   actor.ScreenToLocal( localCoordinates.x, localCoordinates.y, screenCoordinates.x, screenCoordinates.y );
418
419   // Emit a down signal
420   application.ProcessEvent( GenerateSingleTouch( PointState::DOWN, screenCoordinates ) );
421
422   DALI_TEST_EQUALS( true, data.functorCalled, TEST_LOCATION );
423   DALI_TEST_EQUALS( -1, data.point.deviceId, TEST_LOCATION );
424   DALI_TEST_EQUALS( PointState::FINISHED, data.point.state, TEST_LOCATION );
425   DALI_TEST_EQUALS( Vector2::ZERO, data.point.screen, TEST_LOCATION );
426   DALI_TEST_EQUALS( Vector2::ZERO, data.point.local, 0.1f, TEST_LOCATION );
427   DALI_TEST_CHECK( ! data.point.hitActor );
428
429   END_TEST;
430 }
431
432
433 int UtcDaliTouchDataOutsideCameraNearFarPlanes(void)
434 {
435   TestApplication application;
436
437   Stage stage = Stage::GetCurrent();
438   Vector2 stageSize = stage.GetSize();
439
440   Actor actor = Actor::New();
441   actor.SetSize(100.0f, 100.0f);
442   actor.SetAnchorPoint(AnchorPoint::CENTER);
443   actor.SetParentOrigin(ParentOrigin::CENTER);
444   stage.Add(actor);
445
446   // Render and notify
447   application.SendNotification();
448   application.Render();
449
450   // Get the camera's near and far planes
451   RenderTaskList taskList = stage.GetRenderTaskList();
452   Dali::RenderTask task = taskList.GetTask(0);
453   CameraActor camera = task.GetCameraActor();
454   float nearPlane = camera.GetNearClippingPlane();
455   float farPlane = camera.GetFarClippingPlane();
456
457   // Calculate the current distance of the actor from the camera
458   float tanHalfFov = tanf(camera.GetFieldOfView() * 0.5f);
459   float distance = (stageSize.y * 0.5f) / tanHalfFov;
460
461   // Connect to actor's touched signal
462   SignalData data;
463   TouchDataFunctor functor( data );
464   actor.TouchSignal().Connect( &application, functor );
465
466   Vector2 screenCoordinates( stageSize.x * 0.5f, stageSize.y * 0.5f );
467
468   // Emit a down signal
469   application.ProcessEvent( GenerateSingleTouch( PointState::DOWN, screenCoordinates ) );
470   DALI_TEST_EQUALS( true, data.functorCalled, TEST_LOCATION );
471   data.Reset();
472
473   // Emit a down signal where actor is just at the camera's near plane
474   actor.SetZ(distance - nearPlane);
475
476   // Render and notify
477   application.SendNotification();
478   application.Render();
479
480   application.ProcessEvent( GenerateSingleTouch( PointState::DOWN, screenCoordinates ) );
481   DALI_TEST_EQUALS( true, data.functorCalled, TEST_LOCATION );
482   data.Reset();
483
484   // Emit a down signal where actor is closer than the camera's near plane
485   actor.SetZ((distance - nearPlane) + 1.0f);
486
487   // Render and notify
488   application.SendNotification();
489   application.Render();
490
491   application.ProcessEvent( GenerateSingleTouch( PointState::DOWN, screenCoordinates ) );
492   DALI_TEST_EQUALS( false, data.functorCalled, TEST_LOCATION );
493   data.Reset();
494
495   // Emit a down signal where actor is just at the camera's far plane
496   actor.SetZ(distance - farPlane);
497
498   // Render and notify
499   application.SendNotification();
500   application.Render();
501
502   application.ProcessEvent( GenerateSingleTouch( PointState::DOWN, screenCoordinates ) );
503   DALI_TEST_EQUALS( true, data.functorCalled, TEST_LOCATION );
504   data.Reset();
505
506   // Emit a down signal where actor is further than the camera's far plane
507   actor.SetZ((distance - farPlane) - 1.0f);
508
509   // Render and notify
510   application.SendNotification();
511   application.Render();
512
513   application.ProcessEvent( GenerateSingleTouch( PointState::DOWN, screenCoordinates ) );
514   DALI_TEST_EQUALS( false, data.functorCalled, TEST_LOCATION );
515   data.Reset();
516   END_TEST;
517 }
518
519 int UtcDaliTouchDataEmitEmpty(void)
520 {
521   TestApplication application;
522
523   try
524   {
525     // Emit an empty TouchEvent
526     Integration::TouchEvent event;
527     application.ProcessEvent( event );
528     tet_result( TET_FAIL );
529   }
530   catch ( Dali::DaliException& e )
531   {
532     DALI_TEST_ASSERT( e, "!event.points.empty()", TEST_LOCATION );
533   }
534   END_TEST;
535 }
536
537 int UtcDaliTouchDataInterrupted(void)
538 {
539   TestApplication application;
540
541   Actor actor = Actor::New();
542   actor.SetSize(100.0f, 100.0f);
543   actor.SetAnchorPoint(AnchorPoint::TOP_LEFT);
544   Stage::GetCurrent().Add(actor);
545
546   // Render and notify
547   application.SendNotification();
548   application.Render();
549
550   // Connect to actor's touched signal
551   SignalData data;
552   TouchDataFunctor functor( data );
553   actor.TouchSignal().Connect( &application, functor );
554
555   // Emit a down signal
556   application.ProcessEvent( GenerateSingleTouch( PointState::DOWN, Vector2( 10.0f, 10.0f ) ) );
557   DALI_TEST_EQUALS( true, data.functorCalled, TEST_LOCATION );
558   DALI_TEST_EQUALS( PointState::DOWN, data.touchData.points[0].state, TEST_LOCATION );
559   data.Reset();
560
561   // Emit an interrupted signal, we should be signalled regardless of whether there is a hit or not.
562   application.ProcessEvent( GenerateSingleTouch( PointState::INTERRUPTED, Vector2( 200.0f, 200.0f /* Outside actor */ ) ) );
563   DALI_TEST_EQUALS( true, data.functorCalled, TEST_LOCATION );
564   DALI_TEST_EQUALS( PointState::INTERRUPTED, data.touchData.points[0].state, TEST_LOCATION );
565   data.Reset();
566
567   // Emit another interrupted signal, our signal handler should not be called.
568   application.ProcessEvent( GenerateSingleTouch( PointState::INTERRUPTED, Vector2( 200.0f, 200.0f ) ) );
569   DALI_TEST_EQUALS( false, data.functorCalled, TEST_LOCATION );
570   END_TEST;
571 }
572
573 int UtcDaliTouchDataParentConsumer(void)
574 {
575   TestApplication application;
576   Actor rootActor( Stage::GetCurrent().GetRootLayer() );
577
578   Actor actor = Actor::New();
579   actor.SetSize(100.0f, 100.0f);
580   actor.SetAnchorPoint(AnchorPoint::TOP_LEFT);
581   Stage::GetCurrent().Add(actor);
582
583   // Render and notify
584   application.SendNotification();
585   application.Render();
586
587   // Connect to actor's touched signal
588   SignalData data;
589   TouchDataFunctor functor( data, false );
590   actor.TouchSignal().Connect( &application, functor );
591
592   // Connect to root actor's touched signal
593   SignalData rootData;
594   TouchDataFunctor rootFunctor( rootData ); // Consumes signal
595   rootActor.TouchSignal().Connect( &application, rootFunctor );
596
597   Vector2 screenCoordinates( 10.0f, 10.0f );
598   Vector2 actorCoordinates, rootCoordinates;
599   actor.ScreenToLocal( actorCoordinates.x, actorCoordinates.y, screenCoordinates.x, screenCoordinates.y );
600   rootActor.ScreenToLocal( rootCoordinates.x, rootCoordinates.y, screenCoordinates.x, screenCoordinates.y );
601
602   // Emit a down signal
603   application.ProcessEvent( GenerateSingleTouch( PointState::DOWN, screenCoordinates ) );
604   DALI_TEST_EQUALS( true, data.functorCalled, TEST_LOCATION );
605   DALI_TEST_EQUALS( true, rootData.functorCalled, TEST_LOCATION );
606   DALI_TEST_EQUALS( 1u, data.touchData.GetPointCount(), TEST_LOCATION );
607   DALI_TEST_EQUALS( 1u, rootData.touchData.GetPointCount(), TEST_LOCATION );
608   DALI_TEST_EQUALS( PointState::DOWN, data.touchData.points[0].state, TEST_LOCATION );
609   DALI_TEST_EQUALS( PointState::DOWN, rootData.touchData.points[0].state, TEST_LOCATION );
610   DALI_TEST_EQUALS( screenCoordinates, data.touchData.points[0].screen, TEST_LOCATION );
611   DALI_TEST_EQUALS( screenCoordinates, rootData.touchData.points[0].screen, TEST_LOCATION );
612   DALI_TEST_EQUALS( actorCoordinates, data.touchData.points[0].local, 0.1f, TEST_LOCATION );
613   DALI_TEST_EQUALS( rootCoordinates, rootData.touchData.points[0].local, 0.1f, TEST_LOCATION );
614   DALI_TEST_CHECK( actor == data.touchData.points[0].hitActor );
615   DALI_TEST_CHECK( actor == rootData.touchData.points[0].hitActor );
616   data.Reset();
617   rootData.Reset();
618
619   // Emit a motion signal
620   screenCoordinates.x = screenCoordinates.y = 11.0f;
621   actor.ScreenToLocal( actorCoordinates.x, actorCoordinates.y, screenCoordinates.x, screenCoordinates.y );
622   rootActor.ScreenToLocal( rootCoordinates.x, rootCoordinates.y, screenCoordinates.x, screenCoordinates.y );
623   application.ProcessEvent( GenerateSingleTouch( PointState::MOTION, screenCoordinates ) );
624   DALI_TEST_EQUALS( true, data.functorCalled, TEST_LOCATION );
625   DALI_TEST_EQUALS( true, rootData.functorCalled, TEST_LOCATION );
626   DALI_TEST_EQUALS( 1u, data.touchData.GetPointCount(), TEST_LOCATION );
627   DALI_TEST_EQUALS( 1u, rootData.touchData.GetPointCount(), TEST_LOCATION );
628   DALI_TEST_EQUALS( PointState::MOTION, data.touchData.points[0].state, TEST_LOCATION );
629   DALI_TEST_EQUALS( PointState::MOTION, rootData.touchData.points[0].state, TEST_LOCATION );
630   DALI_TEST_EQUALS( screenCoordinates, data.touchData.points[0].screen, TEST_LOCATION );
631   DALI_TEST_EQUALS( screenCoordinates, rootData.touchData.points[0].screen, TEST_LOCATION );
632   DALI_TEST_EQUALS( actorCoordinates, data.touchData.points[0].local, 0.1f, TEST_LOCATION );
633   DALI_TEST_EQUALS( rootCoordinates, rootData.touchData.points[0].local, 0.1f, TEST_LOCATION );
634   DALI_TEST_CHECK( actor == data.touchData.points[0].hitActor );
635   DALI_TEST_CHECK( actor == rootData.touchData.points[0].hitActor );
636   data.Reset();
637   rootData.Reset();
638
639   // Emit an up signal
640   screenCoordinates.x = screenCoordinates.y = 12.0f;
641   actor.ScreenToLocal( actorCoordinates.x, actorCoordinates.y, screenCoordinates.x, screenCoordinates.y );
642   rootActor.ScreenToLocal( rootCoordinates.x, rootCoordinates.y, screenCoordinates.x, screenCoordinates.y );
643   application.ProcessEvent( GenerateSingleTouch( PointState::UP, screenCoordinates ) );
644   DALI_TEST_EQUALS( true, data.functorCalled, TEST_LOCATION );
645   DALI_TEST_EQUALS( true, rootData.functorCalled, TEST_LOCATION );
646   DALI_TEST_EQUALS( 1u, data.touchData.GetPointCount(), TEST_LOCATION );
647   DALI_TEST_EQUALS( 1u, rootData.touchData.GetPointCount(), TEST_LOCATION );
648   DALI_TEST_EQUALS( PointState::UP, data.touchData.points[0].state, TEST_LOCATION );
649   DALI_TEST_EQUALS( PointState::UP, rootData.touchData.points[0].state, TEST_LOCATION );
650   DALI_TEST_EQUALS( screenCoordinates, data.touchData.points[0].screen, TEST_LOCATION );
651   DALI_TEST_EQUALS( screenCoordinates, rootData.touchData.points[0].screen, TEST_LOCATION );
652   DALI_TEST_EQUALS( actorCoordinates, data.touchData.points[0].local, 0.1f, TEST_LOCATION );
653   DALI_TEST_EQUALS( rootCoordinates, rootData.touchData.points[0].local, 0.1f, TEST_LOCATION );
654   DALI_TEST_CHECK( actor == data.touchData.points[0].hitActor );
655   DALI_TEST_CHECK( actor == rootData.touchData.points[0].hitActor );
656   data.Reset();
657   rootData.Reset();
658
659   // Emit a down signal where the actor is not present, will hit the root actor though
660   screenCoordinates.x = screenCoordinates.y = 200.0f;
661   rootActor.ScreenToLocal( rootCoordinates.x, rootCoordinates.y, screenCoordinates.x, screenCoordinates.y );
662   application.ProcessEvent( GenerateSingleTouch( PointState::DOWN, screenCoordinates ) );
663   DALI_TEST_EQUALS( false, data.functorCalled, TEST_LOCATION );
664   DALI_TEST_EQUALS( true, rootData.functorCalled, TEST_LOCATION );
665   DALI_TEST_EQUALS( 1u, rootData.touchData.GetPointCount(), TEST_LOCATION );
666   DALI_TEST_EQUALS( PointState::DOWN, rootData.touchData.points[0].state, TEST_LOCATION );
667   DALI_TEST_EQUALS( screenCoordinates, rootData.touchData.points[0].screen, TEST_LOCATION );
668   DALI_TEST_EQUALS( rootCoordinates, rootData.touchData.points[0].local, 0.1f, TEST_LOCATION );
669   DALI_TEST_CHECK( rootActor == rootData.touchData.points[0].hitActor );
670   END_TEST;
671 }
672
673 int UtcDaliTouchDataInterruptedParentConsumer(void)
674 {
675   TestApplication application;
676   Actor rootActor( Stage::GetCurrent().GetRootLayer() );
677
678   Actor actor = Actor::New();
679   actor.SetSize(100.0f, 100.0f);
680   actor.SetAnchorPoint(AnchorPoint::TOP_LEFT);
681   Stage::GetCurrent().Add(actor);
682
683   // Render and notify
684   application.SendNotification();
685   application.Render();
686
687   // Connect to actor's touched signal
688   SignalData data;
689   TouchDataFunctor functor( data, false );
690   actor.TouchSignal().Connect( &application, functor );
691
692   // Connect to root actor's touched signal
693   SignalData rootData;
694   TouchDataFunctor rootFunctor( rootData ); // Consumes signal
695   rootActor.TouchSignal().Connect( &application, rootFunctor );
696
697   // Emit a down signal
698   application.ProcessEvent( GenerateSingleTouch( PointState::DOWN, Vector2( 10.0f, 10.0f ) ) );
699   DALI_TEST_EQUALS( true, data.functorCalled, TEST_LOCATION );
700   DALI_TEST_EQUALS( true, rootData.functorCalled, TEST_LOCATION );
701   DALI_TEST_EQUALS( PointState::DOWN, data.touchData.points[0].state, TEST_LOCATION );
702   DALI_TEST_EQUALS( PointState::DOWN, rootData.touchData.points[0].state, TEST_LOCATION );
703   DALI_TEST_CHECK( actor == data.touchData.points[0].hitActor );
704   DALI_TEST_CHECK( actor == rootData.touchData.points[0].hitActor );
705   data.Reset();
706   rootData.Reset();
707
708   // Emit an interrupted signal
709   application.ProcessEvent( GenerateSingleTouch( PointState::INTERRUPTED, Vector2( 200.0f, 200.0f ) ) );
710   DALI_TEST_EQUALS( true, data.functorCalled, TEST_LOCATION );
711   DALI_TEST_EQUALS( true, rootData.functorCalled, TEST_LOCATION );
712   DALI_TEST_EQUALS( PointState::INTERRUPTED, data.touchData.points[0].state, TEST_LOCATION );
713   DALI_TEST_EQUALS( PointState::INTERRUPTED, rootData.touchData.points[0].state, TEST_LOCATION );
714   DALI_TEST_CHECK( actor == data.touchData.points[0].hitActor );
715   DALI_TEST_CHECK( actor == rootData.touchData.points[0].hitActor );
716   data.Reset();
717   rootData.Reset();
718
719   // Emit another down signal
720   application.ProcessEvent( GenerateSingleTouch( PointState::DOWN, Vector2( 10.0f, 10.0f ) ) );
721   DALI_TEST_EQUALS( true, data.functorCalled, TEST_LOCATION );
722   DALI_TEST_EQUALS( true, rootData.functorCalled, TEST_LOCATION );
723   DALI_TEST_EQUALS( PointState::DOWN, data.touchData.points[0].state, TEST_LOCATION );
724   DALI_TEST_EQUALS( PointState::DOWN, rootData.touchData.points[0].state, TEST_LOCATION );
725   data.Reset();
726   rootData.Reset();
727
728   // Remove actor from Stage
729   Stage::GetCurrent().Remove( actor );
730   data.Reset();
731   rootData.Reset();
732
733   // Render and notify
734   application.SendNotification();
735   application.Render();
736
737   // Emit an interrupted signal, only root actor's signal should be called.
738   application.ProcessEvent( GenerateSingleTouch( PointState::INTERRUPTED, Vector2( 200.0f, 200.0f /* Outside actor */ ) ) );
739   DALI_TEST_EQUALS( false, data.functorCalled, TEST_LOCATION );
740   DALI_TEST_EQUALS( true, rootData.functorCalled, TEST_LOCATION );
741   DALI_TEST_EQUALS( PointState::INTERRUPTED, rootData.touchData.points[0].state, TEST_LOCATION );
742   DALI_TEST_CHECK( rootActor == rootData.touchData.points[0].hitActor );
743   data.Reset();
744   rootData.Reset();
745
746   // Emit another interrupted state, none of the signal's should be called.
747   application.ProcessEvent( GenerateSingleTouch( PointState::INTERRUPTED, Vector2( 200.0f, 200.0f ) ) );
748   DALI_TEST_EQUALS( false, data.functorCalled, TEST_LOCATION );
749   DALI_TEST_EQUALS( false, rootData.functorCalled, TEST_LOCATION );
750   END_TEST;
751 }
752
753 int UtcDaliTouchDataLeave(void)
754 {
755   TestApplication application;
756
757   Actor actor = Actor::New();
758   actor.SetSize(100.0f, 100.0f);
759   actor.SetAnchorPoint(AnchorPoint::TOP_LEFT);
760   Stage::GetCurrent().Add(actor);
761
762   // Render and notify
763   application.SendNotification();
764   application.Render();
765
766   // Connect to actor's touched signal
767   SignalData data;
768   TouchDataFunctor functor( data );
769   actor.TouchSignal().Connect( &application, functor );
770
771   // Set actor to require leave events
772   actor.SetLeaveRequired( true );
773
774   // Emit a down signal
775   application.ProcessEvent( GenerateSingleTouch( PointState::DOWN, Vector2( 10.0f, 10.0f ) ) );
776   DALI_TEST_EQUALS( true, data.functorCalled, TEST_LOCATION );
777   DALI_TEST_EQUALS( PointState::DOWN, data.touchData.points[0].state, TEST_LOCATION );
778   data.Reset();
779
780   // Emit a motion signal outside of actor, should be signalled with a Leave
781   application.ProcessEvent( GenerateSingleTouch( PointState::MOTION, Vector2 ( 200.0f, 200.0f )) );
782   DALI_TEST_EQUALS( true, data.functorCalled, TEST_LOCATION );
783   DALI_TEST_EQUALS( PointState::LEAVE, data.touchData.points[0].state, TEST_LOCATION );
784   data.Reset();
785
786   // Another motion outside of actor, no signalling
787   application.ProcessEvent( GenerateSingleTouch( PointState::MOTION, Vector2 ( 201.0f, 201.0f )) );
788   DALI_TEST_EQUALS( false, data.functorCalled, TEST_LOCATION );
789   data.Reset();
790
791   // Another motion event inside actor, signalled with motion
792   application.ProcessEvent( GenerateSingleTouch( PointState::MOTION, Vector2 ( 10.0f, 10.0f )) );
793   DALI_TEST_EQUALS( true, data.functorCalled, TEST_LOCATION );
794   DALI_TEST_EQUALS( PointState::MOTION, data.touchData.points[0].state, TEST_LOCATION );
795   data.Reset();
796
797   // We do not want to listen to leave events anymore
798   actor.SetLeaveRequired( false );
799
800   // Another motion event outside of actor, no signalling
801   application.ProcessEvent( GenerateSingleTouch( PointState::MOTION, Vector2 ( 200.0f, 200.0f )) );
802   DALI_TEST_EQUALS( false, data.functorCalled, TEST_LOCATION );
803   data.Reset();
804   END_TEST;
805 }
806
807 int UtcDaliTouchDataLeaveParentConsumer(void)
808 {
809   TestApplication application;
810   Actor rootActor( Stage::GetCurrent().GetRootLayer() );
811
812   Actor actor = Actor::New();
813   actor.SetSize(100.0f, 100.0f);
814   actor.SetAnchorPoint(AnchorPoint::TOP_LEFT);
815   Stage::GetCurrent().Add(actor);
816
817   // Render and notify
818   application.SendNotification();
819   application.Render();
820
821   // Connect to actor's touched signal
822   SignalData data;
823   TouchDataFunctor functor( data, false );
824   actor.TouchSignal().Connect( &application, functor );
825
826   // Connect to root actor's touched signal
827   SignalData rootData;
828   TouchDataFunctor rootFunctor( rootData ); // Consumes signal
829   rootActor.TouchSignal().Connect( &application, rootFunctor );
830
831   // Set actor to require leave events
832   actor.SetLeaveRequired( true );
833   rootActor.SetLeaveRequired( true );
834
835   // Emit a down signal
836   application.ProcessEvent( GenerateSingleTouch( PointState::DOWN, Vector2( 10.0f, 10.0f ) ) );
837   DALI_TEST_EQUALS( true, data.functorCalled, TEST_LOCATION );
838   DALI_TEST_EQUALS( true, rootData.functorCalled, TEST_LOCATION );
839   DALI_TEST_EQUALS( PointState::DOWN, data.touchData.points[0].state, TEST_LOCATION );
840   DALI_TEST_EQUALS( PointState::DOWN, rootData.touchData.points[0].state, TEST_LOCATION );
841   DALI_TEST_CHECK( actor == data.touchData.points[0].hitActor );
842   DALI_TEST_CHECK( actor == rootData.touchData.points[0].hitActor );
843   data.Reset();
844   rootData.Reset();
845
846   // Emit a motion signal outside of actor, should be signalled with a Leave
847   application.ProcessEvent( GenerateSingleTouch( PointState::MOTION, Vector2 ( 200.0f, 200.0f )) );
848   DALI_TEST_EQUALS( true, data.functorCalled, TEST_LOCATION );
849   DALI_TEST_EQUALS( true, rootData.functorCalled, TEST_LOCATION );
850   DALI_TEST_EQUALS( PointState::LEAVE, data.touchData.points[0].state, TEST_LOCATION );
851   DALI_TEST_EQUALS( PointState::LEAVE, rootData.touchData.points[0].state, TEST_LOCATION );
852   DALI_TEST_CHECK( actor == data.touchData.points[0].hitActor );
853   DALI_TEST_CHECK( actor == rootData.touchData.points[0].hitActor );
854   data.Reset();
855   rootData.Reset();
856
857   // Another motion outside of actor, only rootActor signalled
858   application.ProcessEvent( GenerateSingleTouch( PointState::MOTION, Vector2 ( 201.0f, 201.0f )) );
859   DALI_TEST_EQUALS( false, data.functorCalled, TEST_LOCATION );
860   DALI_TEST_EQUALS( true, rootData.functorCalled, TEST_LOCATION );
861   DALI_TEST_EQUALS( PointState::MOTION, rootData.touchData.points[0].state, TEST_LOCATION );
862   DALI_TEST_CHECK( rootActor == rootData.touchData.points[0].hitActor );
863   data.Reset();
864   rootData.Reset();
865
866   // Another motion event inside actor, signalled with motion
867   application.ProcessEvent( GenerateSingleTouch( PointState::MOTION, Vector2 ( 10.0f, 10.0f )) );
868   DALI_TEST_EQUALS( true, data.functorCalled, TEST_LOCATION );
869   DALI_TEST_EQUALS( true, rootData.functorCalled, TEST_LOCATION );
870   DALI_TEST_EQUALS( PointState::MOTION, data.touchData.points[0].state, TEST_LOCATION );
871   DALI_TEST_EQUALS( PointState::MOTION, rootData.touchData.points[0].state, TEST_LOCATION );
872   DALI_TEST_CHECK( actor == data.touchData.points[0].hitActor );
873   DALI_TEST_CHECK( actor == rootData.touchData.points[0].hitActor );
874   data.Reset();
875   rootData.Reset();
876
877   // We do not want to listen to leave events of actor anymore
878   actor.SetLeaveRequired( false );
879
880   // Another motion event outside of root actor, only root signalled
881   Vector2 stageSize( Stage::GetCurrent().GetSize() );
882   application.ProcessEvent( GenerateSingleTouch( PointState::MOTION, Vector2 ( stageSize.width + 10.0f, stageSize.height + 10.0f )) );
883   DALI_TEST_EQUALS( false, data.functorCalled, TEST_LOCATION );
884   DALI_TEST_EQUALS( true, rootData.functorCalled, TEST_LOCATION );
885   DALI_TEST_EQUALS( PointState::LEAVE, rootData.touchData.points[0].state, TEST_LOCATION );
886   END_TEST;
887 }
888
889 int UtcDaliTouchDataActorBecomesInsensitive(void)
890 {
891   TestApplication application;
892
893   Actor actor = Actor::New();
894   actor.SetSize(100.0f, 100.0f);
895   actor.SetAnchorPoint(AnchorPoint::TOP_LEFT);
896   Stage::GetCurrent().Add(actor);
897
898   // Render and notify
899   application.SendNotification();
900   application.Render();
901
902   // Connect to actor's touched signal
903   SignalData data;
904   TouchDataFunctor functor( data );
905   actor.TouchSignal().Connect( &application, functor );
906
907   // Emit a down signal
908   application.ProcessEvent( GenerateSingleTouch( PointState::DOWN, Vector2( 10.0f, 10.0f ) ) );
909   DALI_TEST_EQUALS( true, data.functorCalled, TEST_LOCATION );
910   DALI_TEST_EQUALS( PointState::DOWN, data.touchData.points[0].state, TEST_LOCATION );
911   data.Reset();
912
913   // Change actor to insensitive
914   actor.SetSensitive( false );
915
916   // Emit a motion signal, signalled with an interrupted
917   application.ProcessEvent( GenerateSingleTouch( PointState::MOTION, Vector2 ( 200.0f, 200.0f )) );
918   DALI_TEST_EQUALS( true, data.functorCalled, TEST_LOCATION );
919   DALI_TEST_EQUALS( PointState::INTERRUPTED, data.touchData.points[0].state, TEST_LOCATION );
920   data.Reset();
921   END_TEST;
922 }
923
924 int UtcDaliTouchDataActorBecomesInsensitiveParentConsumer(void)
925 {
926   TestApplication application;
927   Actor rootActor( Stage::GetCurrent().GetRootLayer() );
928
929   Actor actor = Actor::New();
930   actor.SetSize(100.0f, 100.0f);
931   actor.SetAnchorPoint(AnchorPoint::TOP_LEFT);
932   Stage::GetCurrent().Add(actor);
933
934   // Render and notify
935   application.SendNotification();
936   application.Render();
937
938   // Connect to actor's touched signal
939   SignalData data;
940   TouchDataFunctor functor( data, false );
941   actor.TouchSignal().Connect( &application, functor );
942
943   // Connect to root actor's touched signal
944   SignalData rootData;
945   TouchDataFunctor rootFunctor( rootData ); // Consumes signal
946   rootActor.TouchSignal().Connect( &application, rootFunctor );
947
948   // Emit a down signal
949   application.ProcessEvent( GenerateSingleTouch( PointState::DOWN, Vector2( 10.0f, 10.0f ) ) );
950   DALI_TEST_EQUALS( true, data.functorCalled, TEST_LOCATION );
951   DALI_TEST_EQUALS( true, rootData.functorCalled, TEST_LOCATION );
952   DALI_TEST_EQUALS( PointState::DOWN, data.touchData.points[0].state, TEST_LOCATION );
953   DALI_TEST_EQUALS( PointState::DOWN, rootData.touchData.points[0].state, TEST_LOCATION );
954   DALI_TEST_CHECK( actor == data.touchData.points[0].hitActor );
955   DALI_TEST_CHECK( actor == rootData.touchData.points[0].hitActor );
956   data.Reset();
957   rootData.Reset();
958
959   // Render and notify
960   application.SendNotification();
961   application.Render();
962
963   // Make root actor insensitive
964   rootActor.SetSensitive( false );
965
966   // Emit a motion signal, signalled with an interrupted (should get interrupted even if within root actor)
967   application.ProcessEvent( GenerateSingleTouch( PointState::MOTION, Vector2 ( 200.0f, 200.0f )) );
968   DALI_TEST_EQUALS( true, data.functorCalled, TEST_LOCATION );
969   DALI_TEST_EQUALS( PointState::INTERRUPTED, data.touchData.points[0].state, TEST_LOCATION );
970   DALI_TEST_EQUALS( true, rootData.functorCalled, TEST_LOCATION );
971   DALI_TEST_EQUALS( PointState::INTERRUPTED, rootData.touchData.points[0].state, TEST_LOCATION );
972   END_TEST;
973 }
974
975 int UtcDaliTouchDataMultipleLayers(void)
976 {
977   TestApplication application;
978   Actor rootActor( Stage::GetCurrent().GetRootLayer() );
979
980   // Connect to actor's touched signal
981   SignalData data;
982   TouchDataFunctor functor( data );
983
984   Layer layer1 ( Layer::New() );
985   layer1.SetSize(100.0f, 100.0f);
986   layer1.SetAnchorPoint(AnchorPoint::TOP_LEFT);
987   Stage::GetCurrent().Add( layer1 );
988
989   Actor actor1 ( Actor::New() );
990   actor1.SetSize( 100.0f, 100.0f );
991   actor1.SetAnchorPoint(AnchorPoint::TOP_LEFT);
992   actor1.SetZ( 1.0f ); // Should hit actor1 in this layer
993   layer1.Add( actor1 );
994
995   // Render and notify
996   application.SendNotification();
997   application.Render();
998
999   // Connect to layer1 and actor1
1000   layer1.TouchSignal().Connect( &application, functor );
1001   actor1.TouchSignal().Connect( &application, functor );
1002
1003   // Hit in hittable area, actor1 should be hit
1004   application.ProcessEvent( GenerateSingleTouch( PointState::DOWN, Vector2( 10.0f, 10.0f ) ) );
1005   DALI_TEST_EQUALS( true, data.functorCalled, TEST_LOCATION );
1006   DALI_TEST_CHECK( data.touchedActor == actor1 );
1007   data.Reset();
1008
1009   // Make layer1 insensitive, nothing should be hit
1010   layer1.SetSensitive( false );
1011   application.ProcessEvent( GenerateSingleTouch( PointState::DOWN, Vector2( 10.0f, 10.0f ) ) );
1012   DALI_TEST_EQUALS( false, data.functorCalled, TEST_LOCATION );
1013   data.Reset();
1014
1015   // Make layer1 sensitive again, again actor1 will be hit
1016   layer1.SetSensitive( true );
1017   application.ProcessEvent( GenerateSingleTouch( PointState::DOWN, Vector2( 10.0f, 10.0f ) ) );
1018   DALI_TEST_EQUALS( true, data.functorCalled, TEST_LOCATION );
1019   DALI_TEST_CHECK( data.touchedActor == actor1 );
1020   data.Reset();
1021
1022   // Make rootActor insensitive, nothing should be hit
1023   rootActor.SetSensitive( false );
1024   application.ProcessEvent( GenerateSingleTouch( PointState::DOWN, Vector2( 10.0f, 10.0f ) ) );
1025   DALI_TEST_EQUALS( false, data.functorCalled, TEST_LOCATION );
1026   data.Reset();
1027
1028   // Make rootActor sensitive
1029   rootActor.SetSensitive( true );
1030
1031   // Add another layer
1032   Layer layer2 ( Layer::New() );
1033   layer2.SetSize(100.0f, 100.0f );
1034   layer2.SetAnchorPoint(AnchorPoint::TOP_LEFT);
1035   layer2.SetZ( 10.0f ); // Should hit layer2 in this layer rather than actor2
1036   Stage::GetCurrent().Add( layer2 );
1037
1038   Actor actor2 ( Actor::New() );
1039   actor2.SetSize(100.0f, 100.0f);
1040   actor2.SetAnchorPoint(AnchorPoint::TOP_LEFT);
1041   layer2.Add( actor2 );
1042
1043   // Render and notify
1044   application.SendNotification();
1045   application.Render();
1046
1047   // Connect to layer2 and actor2
1048   layer2.TouchSignal().Connect( &application, functor );
1049   actor2.TouchSignal().Connect( &application, functor );
1050
1051   // Emit an event, should hit layer2
1052   application.ProcessEvent( GenerateSingleTouch( PointState::DOWN, Vector2( 10.0f, 10.0f ) ) );
1053   DALI_TEST_EQUALS( true, data.functorCalled, TEST_LOCATION );
1054   //DALI_TEST_CHECK( data.touchedActor == layer2 ); // TODO: Uncomment this after removing renderable hack!
1055   data.Reset();
1056
1057   // Make layer2 insensitive, should hit actor1
1058   layer2.SetSensitive( false );
1059   application.ProcessEvent( GenerateSingleTouch( PointState::DOWN, Vector2( 10.0f, 10.0f ) ) );
1060   DALI_TEST_EQUALS( true, data.functorCalled, TEST_LOCATION );
1061   DALI_TEST_CHECK( data.touchedActor == actor1 );
1062   data.Reset();
1063
1064   // Make layer2 sensitive again, should hit layer2
1065   layer2.SetSensitive( true );
1066   application.ProcessEvent( GenerateSingleTouch( PointState::DOWN, Vector2( 10.0f, 10.0f ) ) );
1067   DALI_TEST_EQUALS( true, data.functorCalled, TEST_LOCATION );
1068   //DALI_TEST_CHECK( data.touchedActor == layer2 ); // TODO: Uncomment this after removing renderable hack!
1069   data.Reset();
1070
1071   // Make layer2 invisible, render and notify
1072   layer2.SetVisible( false );
1073   application.SendNotification();
1074   application.Render();
1075
1076   // Should hit actor1
1077   application.ProcessEvent( GenerateSingleTouch( PointState::DOWN, Vector2( 10.0f, 10.0f ) ) );
1078   DALI_TEST_EQUALS( true, data.functorCalled, TEST_LOCATION );
1079   DALI_TEST_CHECK( data.touchedActor == actor1 );
1080   data.Reset();
1081
1082   // Make rootActor invisible, render and notify
1083   rootActor.SetVisible( false );
1084   application.SendNotification();
1085   application.Render();
1086
1087   // Should not hit anything
1088   application.ProcessEvent( GenerateSingleTouch( PointState::DOWN, Vector2( 10.0f, 10.0f ) ) );
1089   DALI_TEST_EQUALS( false, data.functorCalled, TEST_LOCATION );
1090   data.Reset();
1091   END_TEST;
1092 }
1093
1094 int UtcDaliTouchDataMultipleRenderTasks(void)
1095 {
1096   TestApplication application;
1097   Stage stage ( Stage::GetCurrent() );
1098   Vector2 stageSize ( stage.GetSize() );
1099
1100   Actor actor = Actor::New();
1101   actor.SetSize(100.0f, 100.0f);
1102   actor.SetAnchorPoint(AnchorPoint::TOP_LEFT);
1103   stage.Add(actor);
1104
1105   // Create render task
1106   Viewport viewport( stageSize.width * 0.5f, stageSize.height * 0.5f, stageSize.width * 0.5f, stageSize.height * 0.5f );
1107   RenderTask renderTask ( Stage::GetCurrent().GetRenderTaskList().CreateTask() );
1108   renderTask.SetViewport( viewport );
1109   renderTask.SetInputEnabled( true );
1110
1111   // Render and notify
1112   application.SendNotification();
1113   application.Render();
1114
1115   // Connect to actor's touched signal
1116   SignalData data;
1117   TouchDataFunctor functor( data );
1118   actor.TouchSignal().Connect( &application, functor );
1119
1120   // Emit a down signal
1121   application.ProcessEvent( GenerateSingleTouch( PointState::DOWN, Vector2( 10.0f, 10.0f ) ) );
1122   DALI_TEST_EQUALS( true, data.functorCalled, TEST_LOCATION );
1123   data.Reset();
1124
1125   // Ensure renderTask actor can be hit too.
1126   application.ProcessEvent( GenerateSingleTouch( PointState::DOWN, Vector2( viewport.x + 5.0f, viewport.y + 5.0f ) ) );
1127   DALI_TEST_EQUALS( true, data.functorCalled, TEST_LOCATION );
1128   data.Reset();
1129
1130   // Disable input on renderTask, should not be hittable
1131   renderTask.SetInputEnabled( false );
1132   application.ProcessEvent( GenerateSingleTouch( PointState::DOWN, Vector2( viewport.x + 5.0f, viewport.y + 5.0f ) ) );
1133   DALI_TEST_EQUALS( false, data.functorCalled, TEST_LOCATION );
1134   data.Reset();
1135   END_TEST;
1136 }
1137
1138 int UtcDaliTouchDataMultipleRenderTasksWithChildLayer(void)
1139 {
1140   TestApplication application;
1141   Stage stage ( Stage::GetCurrent() );
1142   Vector2 stageSize ( stage.GetSize() );
1143
1144   Actor actor = Actor::New();
1145   actor.SetSize(100.0f, 100.0f);
1146   actor.SetAnchorPoint(AnchorPoint::TOP_LEFT);
1147   stage.Add(actor);
1148
1149   Layer layer = Layer::New();
1150   layer.SetSize(100.0f, 100.0f);
1151   layer.SetAnchorPoint(AnchorPoint::TOP_LEFT);
1152   actor.Add(layer);
1153
1154   // Create render task
1155   Viewport viewport( stageSize.width * 0.5f, stageSize.height * 0.5f, stageSize.width * 0.5f, stageSize.height * 0.5f );
1156   RenderTask renderTask ( Stage::GetCurrent().GetRenderTaskList().CreateTask() );
1157   renderTask.SetViewport( viewport );
1158   renderTask.SetInputEnabled( true );
1159   renderTask.SetSourceActor( actor );
1160
1161   // Render and notify
1162   application.SendNotification();
1163   application.Render();
1164
1165   // Connect to layer's touched signal
1166   SignalData data;
1167   TouchDataFunctor functor( data );
1168   actor.TouchSignal().Connect( &application, functor );
1169   layer.TouchSignal().Connect( &application, functor );
1170
1171   // Emit a down signal
1172   application.ProcessEvent( GenerateSingleTouch( PointState::DOWN, Vector2( 10.0f, 10.0f ) ) );
1173   DALI_TEST_EQUALS( true, data.functorCalled, TEST_LOCATION );
1174   data.Reset();
1175
1176   // Ensure renderTask actor can be hit too.
1177   application.ProcessEvent( GenerateSingleTouch( PointState::DOWN, Vector2( viewport.x + 5.0f, viewport.y + 5.0f ) ) );
1178   DALI_TEST_EQUALS( true, data.functorCalled, TEST_LOCATION );
1179   data.Reset();
1180
1181   // Disable input on renderTask, should not be hittable
1182   renderTask.SetInputEnabled( false );
1183   application.ProcessEvent( GenerateSingleTouch( PointState::DOWN, Vector2( viewport.x + 5.0f, viewport.y + 5.0f ) ) );
1184   DALI_TEST_EQUALS( false, data.functorCalled, TEST_LOCATION );
1185   data.Reset();
1186   END_TEST;
1187 }
1188
1189 int UtcDaliTouchDataOffscreenRenderTasks(void)
1190 {
1191   TestApplication application;
1192   Stage stage ( Stage::GetCurrent() );
1193   Vector2 stageSize ( stage.GetSize() );
1194
1195   // FrameBufferImage for offscreen RenderTask
1196   FrameBufferImage frameBufferImage( FrameBufferImage::New( stageSize.width, stageSize.height, Pixel::RGBA8888 ) );
1197
1198   // Create a renderable actor to display the FrameBufferImage
1199   Actor renderableActor = CreateRenderableActor( frameBufferImage );
1200   renderableActor.SetParentOrigin(ParentOrigin::CENTER);
1201   renderableActor.SetSize( stageSize.x, stageSize.y );
1202   renderableActor.ScaleBy( Vector3(1.0f, -1.0f, 1.0f) ); // FIXME
1203   stage.Add( renderableActor );
1204
1205   Actor actor = Actor::New();
1206   actor.SetSize(100.0f, 100.0f);
1207   actor.SetAnchorPoint(AnchorPoint::TOP_LEFT);
1208   stage.Add( actor );
1209   application.GetGlAbstraction().SetCheckFramebufferStatusResult( GL_FRAMEBUFFER_COMPLETE ); // Ensure framebuffer connects
1210
1211   stage.GetRenderTaskList().GetTask( 0u ).SetScreenToFrameBufferFunction( RenderTask::FULLSCREEN_FRAMEBUFFER_FUNCTION );
1212
1213   // Create a RenderTask
1214   RenderTask renderTask = stage.GetRenderTaskList().CreateTask();
1215   renderTask.SetSourceActor( actor );
1216   renderTask.SetTargetFrameBuffer( frameBufferImage );
1217   renderTask.SetInputEnabled( true );
1218
1219   // Create another RenderTask
1220   RenderTask renderTask2( stage.GetRenderTaskList().CreateTask() );
1221   renderTask2.SetInputEnabled( true );
1222
1223   // Render and notify
1224   application.SendNotification();
1225   application.Render();
1226
1227   // Connect to actor's touched signal
1228   SignalData data;
1229   TouchDataFunctor functor( data );
1230   actor.TouchSignal().Connect( &application, functor );
1231
1232   // Emit a down signal
1233   application.ProcessEvent( GenerateSingleTouch( PointState::DOWN, Vector2( 10.0f, 10.0f ) ) );
1234   DALI_TEST_EQUALS( true, data.functorCalled, TEST_LOCATION );
1235   data.Reset();
1236   END_TEST;
1237 }
1238
1239 int UtcDaliTouchDataMultipleRenderableActors(void)
1240 {
1241   TestApplication application;
1242   Stage stage ( Stage::GetCurrent() );
1243   Vector2 stageSize ( stage.GetSize() );
1244
1245   Actor parent = CreateRenderableActor();
1246   parent.SetSize(100.0f, 100.0f);
1247   parent.SetAnchorPoint(AnchorPoint::TOP_LEFT);
1248   stage.Add(parent);
1249
1250   Actor actor = CreateRenderableActor();
1251   actor.SetSize(100.0f, 100.0f);
1252   actor.SetAnchorPoint(AnchorPoint::TOP_LEFT);
1253   parent.Add(actor);
1254
1255   // Render and notify
1256   application.SendNotification();
1257   application.Render();
1258
1259   // Connect to layer's touched signal
1260   SignalData data;
1261   TouchDataFunctor functor( data );
1262   parent.TouchSignal().Connect( &application, functor );
1263   actor.TouchSignal().Connect( &application, functor );
1264
1265   // Emit a down signal
1266   application.ProcessEvent( GenerateSingleTouch( PointState::DOWN, Vector2( 10.0f, 10.0f ) ) );
1267   DALI_TEST_EQUALS( true, data.functorCalled, TEST_LOCATION );
1268   DALI_TEST_CHECK( actor == data.touchedActor );
1269   END_TEST;
1270 }
1271
1272 int UtcDaliTouchDataActorRemovedInSignal(void)
1273 {
1274   TestApplication application;
1275
1276   Actor actor = Actor::New();
1277   actor.SetSize(100.0f, 100.0f);
1278   actor.SetAnchorPoint(AnchorPoint::TOP_LEFT);
1279   Stage::GetCurrent().Add(actor);
1280
1281   // Render and notify
1282   application.SendNotification();
1283   application.Render();
1284
1285   // Connect to actor's touched signal
1286   SignalData data;
1287   RemoveActorFunctor functor( data );
1288   actor.TouchSignal().Connect( &application, functor );
1289
1290   // Register for leave events
1291   actor.SetLeaveRequired( true );
1292
1293   // Emit a down signal
1294   application.ProcessEvent( GenerateSingleTouch( PointState::DOWN, Vector2( 10.0f, 10.0f ) ) );
1295   DALI_TEST_EQUALS( true, data.functorCalled, TEST_LOCATION );
1296   data.Reset();
1297
1298   // Re-add, render and notify
1299   Stage::GetCurrent().Add(actor);
1300   application.SendNotification();
1301   application.Render();
1302
1303   // Emit another signal outside of actor's area, should not get anything as the scene has changed.
1304   application.ProcessEvent( GenerateSingleTouch( PointState::MOTION, Vector2( 210.0f, 210.0f ) ) );
1305   DALI_TEST_EQUALS( false, data.functorCalled, TEST_LOCATION );
1306   data.Reset();
1307
1308   // Emit a down signal
1309   application.ProcessEvent( GenerateSingleTouch( PointState::DOWN, Vector2( 10.0f, 10.0f ) ) );
1310   DALI_TEST_EQUALS( true, data.functorCalled, TEST_LOCATION );
1311   data.Reset();
1312
1313   // Render and notify
1314   application.SendNotification();
1315   application.Render();
1316
1317   // Emit another signal outside of actor's area, should not get anything as the scene has changed.
1318   application.ProcessEvent( GenerateSingleTouch( PointState::MOTION, Vector2( 210.0f, 210.0f ) ) );
1319   DALI_TEST_EQUALS( false, data.functorCalled, TEST_LOCATION );
1320   data.Reset();
1321
1322   // Re-add actor back to stage, render and notify
1323   Stage::GetCurrent().Add(actor);
1324   application.SendNotification();
1325   application.Render();
1326
1327   // Emit another down event
1328   application.ProcessEvent( GenerateSingleTouch( PointState::DOWN, Vector2( 10.0f, 10.0f ) ) );
1329   DALI_TEST_EQUALS( true, data.functorCalled, TEST_LOCATION );
1330   data.Reset();
1331
1332   // Completely delete the actor
1333   actor.Reset();
1334
1335   // Emit event, should not crash and should not receive an event.
1336   application.ProcessEvent( GenerateSingleTouch( PointState::MOTION, Vector2( 210.0f, 210.0f ) ) );
1337   DALI_TEST_EQUALS( false, data.functorCalled, TEST_LOCATION );
1338   END_TEST;
1339 }
1340
1341 int UtcDaliTouchDataActorSignalNotConsumed(void)
1342 {
1343   TestApplication application;
1344
1345   Actor actor = Actor::New();
1346   actor.SetSize(100.0f, 100.0f);
1347   actor.SetAnchorPoint(AnchorPoint::TOP_LEFT);
1348   Stage::GetCurrent().Add(actor);
1349
1350   // Render and notify
1351   application.SendNotification();
1352   application.Render();
1353
1354   // Connect to actor's touched signal
1355   SignalData data;
1356   TouchDataFunctor functor( data, false );
1357   actor.TouchSignal().Connect( &application, functor );
1358
1359   // Emit a down signal
1360   application.ProcessEvent( GenerateSingleTouch( PointState::DOWN, Vector2( 10.0f, 10.0f ) ) );
1361   DALI_TEST_EQUALS( true, data.functorCalled, TEST_LOCATION );
1362   END_TEST;
1363 }
1364
1365 int UtcDaliTouchDataActorUnStaged(void)
1366 {
1367   TestApplication application;
1368
1369   Actor actor = Actor::New();
1370   actor.SetSize(100.0f, 100.0f);
1371   actor.SetAnchorPoint(AnchorPoint::TOP_LEFT);
1372   Stage::GetCurrent().Add(actor);
1373
1374   // Render and notify
1375   application.SendNotification();
1376   application.Render();
1377
1378   // Connect to actor's touched signal
1379   SignalData data;
1380   TouchDataFunctor functor( data );
1381   actor.TouchSignal().Connect( &application, functor );
1382
1383   // Emit a down signal
1384   application.ProcessEvent( GenerateSingleTouch( PointState::DOWN, Vector2( 10.0f, 10.0f ) ) );
1385   DALI_TEST_EQUALS( true, data.functorCalled, TEST_LOCATION );
1386   data.Reset();
1387
1388   // Remove actor from stage
1389   Stage::GetCurrent().Remove( actor );
1390   data.Reset();
1391
1392   // Render and notify
1393   application.SendNotification();
1394   application.Render();
1395
1396   // Emit a move at the same point, we should not be signalled.
1397   application.ProcessEvent( GenerateSingleTouch( PointState::MOTION, Vector2( 10.0f, 10.0f ) ) );
1398   DALI_TEST_EQUALS( false, data.functorCalled, TEST_LOCATION );
1399   data.Reset();
1400   END_TEST;
1401 }
1402
1403 int UtcDaliTouchDataSystemOverlayActor(void)
1404 {
1405   TestApplication application;
1406   Dali::Integration::Core& core( application.GetCore() );
1407   Dali::Integration::SystemOverlay& systemOverlay( core.GetSystemOverlay() );
1408   systemOverlay.GetOverlayRenderTasks().CreateTask();
1409
1410   // Create an actor and add it to the system overlay.
1411   Actor systemActor = Actor::New();
1412   systemActor.SetSize(100.0f, 100.0f);
1413   systemActor.SetAnchorPoint(AnchorPoint::TOP_LEFT);
1414   systemOverlay.Add( systemActor );
1415
1416   // Create an actor and add it to the stage as per normal, same position and size as systemActor
1417   Actor actor = Actor::New();
1418   actor.SetSize(100.0f, 100.0f);
1419   actor.SetAnchorPoint(AnchorPoint::TOP_LEFT);
1420   Stage::GetCurrent().Add(actor);
1421
1422   // Connect to the touch signals.
1423   SignalData data;
1424   TouchDataFunctor functor( data );
1425   systemActor.TouchSignal().Connect( &application, functor );
1426   actor.TouchSignal().Connect( &application, functor );
1427
1428   // Render and notify
1429   application.SendNotification();
1430   application.Render();
1431
1432   // Emit a down signal, the system overlay is drawn last so is at the top, should hit the systemActor.
1433   application.ProcessEvent( GenerateSingleTouch( PointState::DOWN, Vector2( 10.0f, 10.0f ) ) );
1434   DALI_TEST_EQUALS( true, data.functorCalled, TEST_LOCATION );
1435   DALI_TEST_CHECK( systemActor == data.touchedActor );
1436   END_TEST;
1437 }
1438
1439 int UtcDaliTouchDataLayerConsumesTouch(void)
1440 {
1441   TestApplication application;
1442
1443   Actor actor = Actor::New();
1444   actor.SetSize(100.0f, 100.0f);
1445   actor.SetAnchorPoint(AnchorPoint::TOP_LEFT);
1446   Stage::GetCurrent().Add(actor);
1447
1448   // Render and notify
1449   application.SendNotification();
1450   application.Render();
1451
1452   // Connect to actor's touched signal
1453   SignalData data;
1454   TouchDataFunctor functor( data );
1455   actor.TouchSignal().Connect( &application, functor );
1456
1457   // Add a layer to overlap the actor
1458   Layer layer = Layer::New();
1459   layer.SetSize(100.0f, 100.0f);
1460   layer.SetAnchorPoint(AnchorPoint::TOP_LEFT);
1461   Stage::GetCurrent().Add( layer );
1462   layer.RaiseToTop();
1463
1464   // Render and notify
1465   application.SendNotification();
1466   application.Render();
1467
1468   // Emit a few touch signals
1469   application.ProcessEvent( GenerateSingleTouch( PointState::DOWN, Vector2( 10.0f, 10.0f ) ) );
1470   application.ProcessEvent( GenerateSingleTouch( PointState::UP, Vector2( 10.0f, 10.0f ) ) );
1471   DALI_TEST_EQUALS( true, data.functorCalled, TEST_LOCATION );
1472   data.Reset();
1473
1474   // Set layer to consume all touch
1475   layer.SetTouchConsumed( true );
1476
1477   // Render and notify
1478   application.SendNotification();
1479   application.Render();
1480
1481   // Emit the same signals again, should not receive
1482   application.ProcessEvent( GenerateSingleTouch( PointState::DOWN, Vector2( 10.0f, 10.0f ) ) );
1483   application.ProcessEvent( GenerateSingleTouch( PointState::UP, Vector2( 10.0f, 10.0f ) ) );
1484   DALI_TEST_EQUALS(false, data.functorCalled, TEST_LOCATION);
1485   data.Reset();
1486
1487   END_TEST;
1488 }
1489
1490 int UtcDaliTouchDataLeaveActorReadded(void)
1491 {
1492   TestApplication application;
1493   Stage stage = Stage::GetCurrent();
1494
1495   Actor actor = Actor::New();
1496   actor.SetSize(100.0f, 100.0f);
1497   actor.SetAnchorPoint(AnchorPoint::TOP_LEFT);
1498   stage.Add(actor);
1499
1500   // Set actor to receive touch-events
1501   actor.SetLeaveRequired( true );
1502
1503   // Render and notify
1504   application.SendNotification();
1505   application.Render();
1506
1507   // Connect to actor's touched signal
1508   SignalData data;
1509   TouchDataFunctor functor( data );
1510   actor.TouchSignal().Connect( &application, functor );
1511
1512   // Emit a down and motion
1513   application.ProcessEvent( GenerateSingleTouch( PointState::DOWN, Vector2( 10.0f, 10.0f ) ) );
1514   application.ProcessEvent( GenerateSingleTouch( PointState::MOTION, Vector2( 11.0f, 10.0f ) ) );
1515   DALI_TEST_EQUALS( true, data.functorCalled, TEST_LOCATION );
1516   data.Reset();
1517
1518   // Remove actor from stage and add again
1519   stage.Remove( actor );
1520   stage.Add( actor );
1521
1522   // Emit a motion within the actor's bounds
1523   application.ProcessEvent( GenerateSingleTouch( PointState::MOTION, Vector2( 12.0f, 10.0f ) ) );
1524   DALI_TEST_EQUALS( true, data.functorCalled, TEST_LOCATION );
1525   data.Reset();
1526
1527   // Emit a motion outside the actor's bounds
1528   application.ProcessEvent( GenerateSingleTouch( PointState::MOTION, Vector2( 200.0f, 200.0f ) ) );
1529   DALI_TEST_EQUALS( true, data.functorCalled, TEST_LOCATION );
1530   DALI_TEST_EQUALS( PointState::LEAVE, data.touchData.points[0].state, TEST_LOCATION );
1531   data.Reset();
1532
1533   END_TEST;
1534 }
1535
1536 int UtcDaliTouchDataClippedActor(void)
1537 {
1538   TestApplication application;
1539   Stage stage = Stage::GetCurrent();
1540
1541   Actor actor = Actor::New();
1542   actor.SetSize( 100.0f, 100.0f );
1543   actor.SetAnchorPoint( AnchorPoint::TOP_LEFT );
1544   stage.Add( actor );
1545
1546   Actor clippingActor = Actor::New();
1547   clippingActor.SetSize( 50.0f, 50.0f );
1548   clippingActor.SetAnchorPoint( AnchorPoint::TOP_LEFT );
1549   clippingActor.SetProperty( Actor::Property::CLIPPING_MODE, ClippingMode::CLIP_CHILDREN );
1550   stage.Add( clippingActor );
1551
1552   // Add a child to the clipped region.
1553   Actor clippingChild = Actor::New();
1554   clippingChild.SetSize( 50.0f, 50.0f );
1555   clippingChild.SetPosition( 25.0f, 25.0f );
1556   clippingChild.SetAnchorPoint( AnchorPoint::TOP_LEFT );
1557   clippingActor.Add( clippingChild );
1558
1559   // Render and notify.
1560   application.SendNotification();
1561   application.Render();
1562
1563   // Connect to actor's touch signal.
1564   SignalData data;
1565   TouchDataFunctor functor( data );
1566   actor.TouchSignal().Connect( &application, functor );
1567
1568   // Emit an event within clipped area - no hit.
1569   application.ProcessEvent( GenerateSingleTouch( PointState::DOWN, Vector2( 10.0f, 10.0f ) ) );
1570   DALI_TEST_EQUALS( false, data.functorCalled, TEST_LOCATION );
1571   data.Reset();
1572
1573   // Emit an event outside the clipped area but within the actor area, we should have a hit.
1574   application.ProcessEvent( GenerateSingleTouch( PointState::DOWN, Vector2( 60.0f, 60.0f ) ) );
1575   DALI_TEST_EQUALS( true, data.functorCalled, TEST_LOCATION );
1576   data.Reset();
1577
1578   clippingChild.TouchSignal().Connect( &application, functor );
1579
1580   // Emit an event inside part of the child which is within the clipped area, we should have a hit.
1581   application.ProcessEvent( GenerateSingleTouch( PointState::DOWN, Vector2( 30.0f, 30.0f ) ) );
1582   DALI_TEST_EQUALS( true, data.functorCalled, TEST_LOCATION );
1583   data.Reset();
1584
1585   END_TEST;
1586 }
1587
1588 int UtcDaliTouchDataActorUnstaged(void)
1589 {
1590   TestApplication application;
1591
1592   Actor actor = Actor::New();
1593   actor.SetSize(100.0f, 100.0f);
1594   actor.SetAnchorPoint(AnchorPoint::TOP_LEFT);
1595   Stage::GetCurrent().Add(actor);
1596
1597   // Render and notify
1598   application.SendNotification();
1599   application.Render();
1600
1601   // Connect to actor's touched signal
1602   SignalData data;
1603   TouchDataFunctor functor( data );
1604   actor.TouchSignal().Connect( &application, functor );
1605
1606   // Emit a down signal
1607   application.ProcessEvent( GenerateSingleTouch( PointState::DOWN, Vector2( 10.0f, 10.0f ) ) );
1608   DALI_TEST_EQUALS( true, data.functorCalled, TEST_LOCATION );
1609   DALI_TEST_EQUALS( PointState::DOWN, data.touchData.points[0].state, TEST_LOCATION );
1610   DALI_TEST_CHECK( actor == data.touchData.points[0].hitActor );
1611   data.Reset();
1612
1613   // Render and notify
1614   application.SendNotification();
1615   application.Render();
1616
1617   // Unparent the actor
1618   actor.Unparent();
1619
1620   // Should receive an interrupted event
1621   DALI_TEST_EQUALS( true, data.functorCalled, TEST_LOCATION );
1622   DALI_TEST_EQUALS( PointState::INTERRUPTED, data.touchData.points[0].state, TEST_LOCATION );
1623   END_TEST;
1624 }
1625
1626 int UtcDaliTouchDataParentUnstaged(void)
1627 {
1628   TestApplication application;
1629
1630   Actor parent = Actor::New();
1631   parent.SetSize(100.0f, 100.0f);
1632   parent.SetAnchorPoint(AnchorPoint::TOP_LEFT);
1633   Stage::GetCurrent().Add(parent);
1634
1635   Actor actor = Actor::New();
1636   actor.SetSize(100.0f, 100.0f);
1637   actor.SetAnchorPoint(AnchorPoint::TOP_LEFT);
1638   parent.Add(actor);
1639
1640   // Render and notify
1641   application.SendNotification();
1642   application.Render();
1643
1644   // Connect to actor's touched signal
1645   SignalData data;
1646   TouchDataFunctor functor( data );
1647   actor.TouchSignal().Connect( &application, functor );
1648
1649   // Emit a down signal
1650   application.ProcessEvent( GenerateSingleTouch( PointState::DOWN, Vector2( 10.0f, 10.0f ) ) );
1651   DALI_TEST_EQUALS( true, data.functorCalled, TEST_LOCATION );
1652   DALI_TEST_EQUALS( PointState::DOWN, data.touchData.points[0].state, TEST_LOCATION );
1653   DALI_TEST_CHECK( actor == data.touchData.points[0].hitActor );
1654   data.Reset();
1655
1656   // Render and notify
1657   application.SendNotification();
1658   application.Render();
1659
1660   // Unparent the parent of the touchable actor
1661   parent.Unparent();
1662
1663   // Should receive an interrupted event
1664   DALI_TEST_EQUALS( true, data.functorCalled, TEST_LOCATION );
1665   DALI_TEST_EQUALS( PointState::INTERRUPTED, data.touchData.points[0].state, TEST_LOCATION );
1666   END_TEST;
1667 }
1668
1669 int UtcDaliTouchDataActorUnstagedDifferentConsumer(void)
1670 {
1671   TestApplication application;
1672
1673   Actor parent = Actor::New();
1674   parent.SetSize(100.0f, 100.0f);
1675   parent.SetAnchorPoint(AnchorPoint::TOP_LEFT);
1676   Stage::GetCurrent().Add(parent);
1677
1678   Actor actor = Actor::New();
1679   actor.SetSize(100.0f, 100.0f);
1680   actor.SetAnchorPoint(AnchorPoint::TOP_LEFT);
1681   parent.Add(actor);
1682
1683   // Render and notify
1684   application.SendNotification();
1685   application.Render();
1686
1687   // Connect to actor's touched signal
1688   SignalData data;
1689   TouchDataFunctor functor( data, false /* Do not consume */ );
1690   actor.TouchSignal().Connect( &application, functor );
1691
1692   // Connect to parent's touched signal
1693   SignalData parentData;
1694   TouchDataFunctor parentFunctor( parentData );
1695   parent.TouchSignal().Connect( &application, parentFunctor );
1696
1697   // Emit a down signal
1698   application.ProcessEvent( GenerateSingleTouch( PointState::DOWN, Vector2( 10.0f, 10.0f ) ) );
1699   DALI_TEST_EQUALS( true, data.functorCalled, TEST_LOCATION );
1700   DALI_TEST_EQUALS( PointState::DOWN, data.touchData.points[0].state, TEST_LOCATION );
1701   DALI_TEST_CHECK( actor == data.touchData.points[0].hitActor );
1702   DALI_TEST_CHECK( actor == data.touchedActor );
1703   DALI_TEST_EQUALS( true, parentData.functorCalled, TEST_LOCATION );
1704   DALI_TEST_EQUALS( PointState::DOWN, parentData.touchData.points[0].state, TEST_LOCATION );
1705   DALI_TEST_CHECK( actor == parentData.touchData.points[0].hitActor );
1706   DALI_TEST_CHECK( parent == parentData.touchedActor );
1707   data.Reset();
1708   parentData.Reset();
1709
1710   // Render and notify
1711   application.SendNotification();
1712   application.Render();
1713
1714   // Unparent the actor
1715   actor.Unparent();
1716
1717   // Should receive an interrupted event for both actor & parent
1718   DALI_TEST_EQUALS( true, data.functorCalled, TEST_LOCATION );
1719   DALI_TEST_EQUALS( PointState::INTERRUPTED, data.touchData.points[0].state, TEST_LOCATION );
1720   DALI_TEST_EQUALS( true, parentData.functorCalled, TEST_LOCATION );
1721   DALI_TEST_EQUALS( PointState::INTERRUPTED, parentData.touchData.points[0].state, TEST_LOCATION );
1722   data.Reset();
1723   parentData.Reset();
1724
1725   // Readd actor to parent
1726   parent.Add(actor);
1727
1728   // Render and notify
1729   application.SendNotification();
1730   application.Render();
1731
1732   // Emit a motion signal
1733   application.ProcessEvent( GenerateSingleTouch( PointState::MOTION, Vector2( 10.0f, 10.0f ) ) );
1734   DALI_TEST_EQUALS( true, data.functorCalled, TEST_LOCATION );
1735   DALI_TEST_EQUALS( true, parentData.functorCalled, TEST_LOCATION );
1736   data.Reset();
1737   parentData.Reset();
1738
1739   // Parent is now consumer, connect again to the touched signal of the actor so that it becomes the consumer
1740   SignalData secondData;
1741   TouchDataFunctor secondFunctor( secondData /* Consume */ );
1742   actor.TouchSignal().Connect( &application, secondFunctor );
1743
1744   // Unparent the actor
1745   actor.Unparent();
1746
1747   // Should receive an interrupted event for both actor functors & the parent as well as it was last consumer
1748   DALI_TEST_EQUALS( true, data.functorCalled, TEST_LOCATION );
1749   DALI_TEST_EQUALS( PointState::INTERRUPTED, data.touchData.points[0].state, TEST_LOCATION );
1750   DALI_TEST_EQUALS( true, parentData.functorCalled, TEST_LOCATION );
1751   DALI_TEST_EQUALS( PointState::INTERRUPTED, parentData.touchData.points[0].state, TEST_LOCATION );
1752   DALI_TEST_EQUALS( true, secondData.functorCalled, TEST_LOCATION );
1753   DALI_TEST_EQUALS( PointState::INTERRUPTED, secondData.touchData.points[0].state, TEST_LOCATION );
1754   data.Reset();
1755   parentData.Reset();
1756   secondData.Reset();
1757
1758   END_TEST;
1759 }
1760
1761 int UtcDaliTouchDataInterruptedDifferentConsumer(void)
1762 {
1763   TestApplication application;
1764   Actor rootActor( Stage::GetCurrent().GetRootLayer() );
1765
1766   Actor parent = Actor::New();
1767   parent.SetSize(100.0f, 100.0f);
1768   parent.SetAnchorPoint(AnchorPoint::TOP_LEFT);
1769   Stage::GetCurrent().Add(parent);
1770
1771   Actor actor = Actor::New();
1772   actor.SetSize(100.0f, 100.0f);
1773   actor.SetAnchorPoint(AnchorPoint::TOP_LEFT);
1774   parent.Add(actor);
1775
1776   // Render and notify
1777   application.SendNotification();
1778   application.Render();
1779
1780   // Connect to actor's touched signal
1781   SignalData data;
1782   TouchDataFunctor functor( data, false /* Do not consume */ );
1783   actor.TouchSignal().Connect( &application, functor );
1784
1785   // Connect to parent's touched signal
1786   SignalData parentData;
1787   TouchDataFunctor parentFunctor( parentData, false /* Do not consume */ );
1788   parent.TouchSignal().Connect( &application, parentFunctor );
1789
1790   // Connect to root's touched signal and consume
1791   SignalData rootData;
1792   TouchDataFunctor rootFunctor( rootData );
1793   rootActor.TouchSignal().Connect( &application, rootFunctor );
1794
1795   // Emit a down signal
1796   application.ProcessEvent( GenerateSingleTouch( PointState::DOWN, Vector2( 10.0f, 10.0f ) ) );
1797   DALI_TEST_EQUALS( true, data.functorCalled, TEST_LOCATION );
1798   DALI_TEST_EQUALS( PointState::DOWN, data.touchData.points[0].state, TEST_LOCATION );
1799   DALI_TEST_CHECK( actor == data.touchData.points[0].hitActor );
1800   DALI_TEST_CHECK( actor == data.touchedActor );
1801   DALI_TEST_EQUALS( true, parentData.functorCalled, TEST_LOCATION );
1802   DALI_TEST_EQUALS( PointState::DOWN, parentData.touchData.points[0].state, TEST_LOCATION );
1803   DALI_TEST_CHECK( actor == parentData.touchData.points[0].hitActor );
1804   DALI_TEST_CHECK( parent == parentData.touchedActor );
1805   DALI_TEST_EQUALS( true, rootData.functorCalled, TEST_LOCATION );
1806   DALI_TEST_EQUALS( PointState::DOWN, rootData.touchData.points[0].state, TEST_LOCATION );
1807   DALI_TEST_CHECK( actor == rootData.touchData.points[0].hitActor );
1808   DALI_TEST_CHECK( rootActor == rootData.touchedActor );
1809   data.Reset();
1810   parentData.Reset();
1811   rootData.Reset();
1812
1813   // Root is now consumer, connect to the touched signal of the parent so that it becomes the consumer
1814   SignalData secondData;
1815   TouchDataFunctor secondFunctor( secondData /* Consume */ );
1816   parent.TouchSignal().Connect( &application, secondFunctor );
1817
1818   // Emit an interrupted signal, all three should STILL be called
1819   application.ProcessEvent( GenerateSingleTouch( PointState::INTERRUPTED, Vector2( 10.0f, 10.0f ) ) );
1820   DALI_TEST_EQUALS( true, data.functorCalled, TEST_LOCATION );
1821   DALI_TEST_EQUALS( PointState::INTERRUPTED, data.touchData.points[0].state, TEST_LOCATION );
1822   DALI_TEST_EQUALS( true, parentData.functorCalled, TEST_LOCATION );
1823   DALI_TEST_EQUALS( PointState::INTERRUPTED, parentData.touchData.points[0].state, TEST_LOCATION );
1824   DALI_TEST_EQUALS( true, rootData.functorCalled, TEST_LOCATION );
1825   DALI_TEST_EQUALS( PointState::INTERRUPTED, rootData.touchData.points[0].state, TEST_LOCATION );
1826   data.Reset();
1827   parentData.Reset();
1828   rootData.Reset();
1829
1830   END_TEST;
1831 }
1832
1833 int UtcDaliTouchDataGetRadius(void)
1834 {
1835   TestApplication application;
1836
1837   Actor actor = Actor::New();
1838   actor.SetSize(100.0f, 100.0f);
1839   actor.SetAnchorPoint(AnchorPoint::TOP_LEFT);
1840   Stage::GetCurrent().Add(actor);
1841
1842   // Render and notify
1843   application.SendNotification();
1844   application.Render();
1845
1846   // Connect to actor's touched signal
1847   SignalData data;
1848   TouchDataFunctor functor( data );
1849   actor.TouchSignal().Connect( &application, functor );
1850
1851   // Emit a down signal with an angle
1852   Integration::TouchEvent touchEvent = GenerateSingleTouch( PointState::DOWN, Vector2( 10.0f, 10.0f ) );
1853   touchEvent.points[ 0 ].SetRadius( 100.0f );
1854   application.ProcessEvent( touchEvent );
1855   DALI_TEST_EQUALS( true, data.functorCalled, TEST_LOCATION );
1856   DALI_TEST_EQUALS( PointState::DOWN, data.touchData.points[0].state, TEST_LOCATION );
1857   DALI_TEST_EQUALS( 100.0f, data.touchData.points[0].radius, TEST_LOCATION );
1858   DALI_TEST_EQUALS( 100.0f, data.touchData.points[0].ellipseRadius.x, TEST_LOCATION );
1859   DALI_TEST_EQUALS( 100.0f, data.touchData.points[0].ellipseRadius.y, TEST_LOCATION );
1860
1861   END_TEST;
1862 }
1863
1864 int UtcDaliTouchDataGetEllipseRadius(void)
1865 {
1866   TestApplication application;
1867
1868   Actor actor = Actor::New();
1869   actor.SetSize(100.0f, 100.0f);
1870   actor.SetAnchorPoint(AnchorPoint::TOP_LEFT);
1871   Stage::GetCurrent().Add(actor);
1872
1873   // Render and notify
1874   application.SendNotification();
1875   application.Render();
1876
1877   // Connect to actor's touched signal
1878   SignalData data;
1879   TouchDataFunctor functor( data );
1880   actor.TouchSignal().Connect( &application, functor );
1881
1882   // Emit a down signal with an angle
1883   Integration::TouchEvent touchEvent = GenerateSingleTouch( PointState::DOWN, Vector2( 10.0f, 10.0f ) );
1884   touchEvent.points[ 0 ].SetRadius( 100.0f, Vector2( 20.0f, 10.0f ) );
1885   application.ProcessEvent( touchEvent );
1886   DALI_TEST_EQUALS( true, data.functorCalled, TEST_LOCATION );
1887   DALI_TEST_EQUALS( PointState::DOWN, data.touchData.points[0].state, TEST_LOCATION );
1888   DALI_TEST_EQUALS( 100.0f, data.touchData.points[0].radius, TEST_LOCATION );
1889   DALI_TEST_EQUALS( 20.0f, data.touchData.points[0].ellipseRadius.x, TEST_LOCATION );
1890   DALI_TEST_EQUALS( 10.0f, data.touchData.points[0].ellipseRadius.y, TEST_LOCATION );
1891
1892   END_TEST;
1893 }
1894
1895 int UtcDaliTouchDataGetAngle(void)
1896 {
1897   TestApplication application;
1898
1899   Actor actor = Actor::New();
1900   actor.SetSize(100.0f, 100.0f);
1901   actor.SetAnchorPoint(AnchorPoint::TOP_LEFT);
1902   Stage::GetCurrent().Add(actor);
1903
1904   // Render and notify
1905   application.SendNotification();
1906   application.Render();
1907
1908   // Connect to actor's touched signal
1909   SignalData data;
1910   TouchDataFunctor functor( data );
1911   actor.TouchSignal().Connect( &application, functor );
1912
1913   // Emit a down signal with an angle
1914   Integration::TouchEvent touchEvent = GenerateSingleTouch( PointState::DOWN, Vector2( 10.0f, 10.0f ) );
1915   touchEvent.points[ 0 ].SetAngle( Degree( 90.0f ) );
1916   application.ProcessEvent( touchEvent );
1917   DALI_TEST_EQUALS( true, data.functorCalled, TEST_LOCATION );
1918   DALI_TEST_EQUALS( PointState::DOWN, data.touchData.points[0].state, TEST_LOCATION );
1919   DALI_TEST_EQUALS( Degree( 90.0f ), data.touchData.points[0].angle, TEST_LOCATION );
1920
1921   END_TEST;
1922 }
1923
1924 int UtcDaliTouchDataGetPressure(void)
1925 {
1926   TestApplication application;
1927
1928   Actor actor = Actor::New();
1929   actor.SetSize(100.0f, 100.0f);
1930   actor.SetAnchorPoint(AnchorPoint::TOP_LEFT);
1931   Stage::GetCurrent().Add(actor);
1932
1933   // Render and notify
1934   application.SendNotification();
1935   application.Render();
1936
1937   // Connect to actor's touched signal
1938   SignalData data;
1939   TouchDataFunctor functor( data );
1940   actor.TouchSignal().Connect( &application, functor );
1941
1942   // Emit a down signal with an angle
1943   Integration::TouchEvent touchEvent = GenerateSingleTouch( PointState::DOWN, Vector2( 10.0f, 10.0f ) );
1944   touchEvent.points[ 0 ].SetPressure( 10.0f );
1945   application.ProcessEvent( touchEvent );
1946   DALI_TEST_EQUALS( true, data.functorCalled, TEST_LOCATION );
1947   DALI_TEST_EQUALS( PointState::DOWN, data.touchData.points[0].state, TEST_LOCATION );
1948   DALI_TEST_EQUALS( 10.0f, data.touchData.points[0].pressure, TEST_LOCATION );
1949
1950   END_TEST;
1951 }
1952
1953 int UtcDaliTouchDataAndEventUsage(void)
1954 {
1955   TestApplication application;
1956
1957   Actor actor = Actor::New();
1958   actor.SetSize(100.0f, 100.0f);
1959   actor.SetAnchorPoint(AnchorPoint::TOP_LEFT);
1960   Stage::GetCurrent().Add(actor);
1961
1962   // Render and notify
1963   application.SendNotification();
1964   application.Render();
1965
1966   // Connect to actor's touched signal
1967   SignalData data;
1968   TouchDataFunctor functor( data );
1969   actor.TouchSignal().Connect( &application, functor );
1970
1971   // Connect to actor's touched signal (OLD)
1972   bool touchEventFunctorCalled = false;
1973   TouchEventFunctor eventFunctor( touchEventFunctorCalled );
1974   actor.TouchedSignal().Connect( &application, eventFunctor );
1975
1976   // Emit a down signal with an angle
1977   application.ProcessEvent( GenerateSingleTouch( PointState::DOWN, Vector2( 10.0f, 10.0f ) ) );
1978   DALI_TEST_EQUALS( true, data.functorCalled, TEST_LOCATION );
1979   DALI_TEST_EQUALS( true, touchEventFunctorCalled, TEST_LOCATION );
1980
1981   END_TEST;
1982 }
1983
1984 int UtcDaliTouchDataGetDeviceAPINegative(void)
1985 {
1986   TestApplication application;
1987
1988   Actor actor = Actor::New();
1989   actor.SetSize(100.0f, 100.0f);
1990   actor.SetAnchorPoint(AnchorPoint::TOP_LEFT);
1991   Stage::GetCurrent().Add(actor);
1992
1993   // Render and notify
1994   application.SendNotification();
1995   application.Render();
1996
1997   // Connect to actor's touched signal
1998   HandleData handleData;
1999   TouchDataHandleFunctor functor( handleData );
2000   actor.TouchSignal().Connect( &application, functor );
2001
2002   Vector2 screenCoordinates( 10.0f, 10.0f );
2003   Vector2 localCoordinates;
2004   actor.ScreenToLocal( localCoordinates.x, localCoordinates.y, screenCoordinates.x, screenCoordinates.y );
2005
2006   // Emit a down signal
2007   application.ProcessEvent( GenerateSingleTouch( PointState::DOWN, screenCoordinates ) );
2008
2009   TouchData data = handleData.touchData;
2010   DALI_TEST_EQUALS( DevelTouchData::GetDeviceClass( data, -1 ), DevelDevice::Class::NONE, TEST_LOCATION );
2011   DALI_TEST_EQUALS( DevelTouchData::GetDeviceSubclass( data, -1 ), DevelDevice::Subclass::NONE, TEST_LOCATION );
2012   END_TEST;
2013 }