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