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