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