0a4c13b63cf0bcf1b9b96aa478f4e21639bc470f
[platform/core/uifw/dali-core.git] / automated-tests / src / dali / utc-Dali-Scene.cpp
1 /*
2  * Copyright (c) 2019 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/integration-api/scene.h>
22 #include <dali/integration-api/events/key-event-integ.h>
23 #include <dali/public-api/events/key-event.h>
24 #include <dali/integration-api/events/touch-event-integ.h>
25 #include <dali/integration-api/events/wheel-event-integ.h>
26
27 #include <dali-test-suite-utils.h>
28
29 // Internal headers are allowed here
30
31 namespace
32 {
33
34 const std::string DEFAULT_DEVICE_NAME("hwKeyboard");
35
36 // Functor for EventProcessingFinished signal
37 struct EventProcessingFinishedFunctor
38 {
39   /**
40    * @param[in] eventProcessingFinished reference to a boolean variable used to check if signal has been called.
41    */
42   EventProcessingFinishedFunctor( bool& eventProcessingFinished )
43   : mEventProcessingFinished( eventProcessingFinished )
44   {}
45
46   void operator()()
47   {
48     mEventProcessingFinished = true;
49   }
50
51   bool& mEventProcessingFinished;
52 };
53
54 // Stores data that is populated in the key-event callback and will be read by the TET cases
55 struct KeyEventSignalData
56 {
57   KeyEventSignalData()
58   : functorCalled(false)
59   {}
60
61   void Reset()
62   {
63     functorCalled = false;
64
65     receivedKeyEvent.keyModifier = 0;
66     receivedKeyEvent.keyPressedName.clear();
67     receivedKeyEvent.keyPressed.clear();
68   }
69
70   bool functorCalled;
71   KeyEvent receivedKeyEvent;
72 };
73
74 // Functor that sets the data when called
75 struct KeyEventReceivedFunctor
76 {
77   KeyEventReceivedFunctor( KeyEventSignalData& data ) : signalData( data ) { }
78
79   bool operator()( const KeyEvent& keyEvent )
80   {
81     signalData.functorCalled = true;
82     signalData.receivedKeyEvent = keyEvent;
83
84     return true;
85   }
86
87   KeyEventSignalData& signalData;
88 };
89
90 // Stores data that is populated in the touched signal callback and will be read by the TET cases
91 struct TouchedSignalData
92 {
93   TouchedSignalData()
94   : functorCalled(false),
95     createNewScene(false),
96     newSceneCreated(false)
97   {}
98
99   void Reset()
100   {
101     functorCalled = false;
102     createNewScene = false;
103     newSceneCreated = false;
104
105     receivedTouchEvent.points.clear();
106     receivedTouchEvent.time = 0;
107
108     receivedTouchData.Reset();
109   }
110
111   bool functorCalled;
112   bool createNewScene;
113   bool newSceneCreated;
114   TouchEvent receivedTouchEvent;
115   TouchData receivedTouchData;
116 };
117
118 // Functor that sets the data when touched signal is received
119 struct TouchedFunctor
120 {
121   TouchedFunctor( TouchedSignalData& data ) : signalData( data ) { }
122
123   void operator()( const TouchEvent& touch )
124   {
125     signalData.functorCalled = true;
126     signalData.receivedTouchEvent = touch;
127   }
128
129   TouchedSignalData& signalData;
130 };
131
132 // Functor that sets the data when touched signal is received
133 struct TouchFunctor
134 {
135   TouchFunctor( TouchedSignalData& data ) : signalData( data ) { }
136
137   void operator()( const TouchData& touch )
138   {
139     signalData.functorCalled = true;
140     signalData.receivedTouchData = touch;
141
142     if ( signalData.createNewScene )
143     {
144       Dali::Integration::Scene scene = Dali::Integration::Scene::New( Vector2( 480.0f, 800.0f ) );
145       DALI_TEST_CHECK( scene );
146
147       signalData.newSceneCreated = true;
148     }
149   }
150
151   void operator()()
152   {
153     signalData.functorCalled = true;
154   }
155
156   TouchedSignalData& signalData;
157 };
158
159 // Stores data that is populated in the wheel-event callback and will be read by the TET cases
160 struct WheelEventSignalData
161 {
162   WheelEventSignalData()
163   : functorCalled(false)
164   {}
165
166   void Reset()
167   {
168     functorCalled = false;
169   }
170
171   bool functorCalled;
172   WheelEvent receivedWheelEvent;
173 };
174
175 // Functor that sets the data when wheel-event signal is received
176 struct WheelEventReceivedFunctor
177 {
178   WheelEventReceivedFunctor( WheelEventSignalData& data ) : signalData( data ) { }
179
180   bool operator()( const WheelEvent& wheelEvent )
181   {
182     signalData.functorCalled = true;
183     signalData.receivedWheelEvent = wheelEvent;
184
185     return true;
186   }
187
188   WheelEventSignalData& signalData;
189 };
190
191 void GenerateTouch( TestApplication& application, PointState::Type state, const Vector2& screenPosition )
192 {
193   Integration::TouchEvent touchEvent;
194   Integration::Point point;
195   point.SetState( state );
196   point.SetScreenPosition( screenPosition );
197   touchEvent.points.push_back( point );
198   application.ProcessEvent( touchEvent );
199 }
200
201 bool DummyTouchCallback( Actor actor, const TouchEvent& touch )
202 {
203   return true;
204 }
205
206 } // unnamed namespace
207
208 int UtcDaliSceneAdd(void)
209 {
210   TestApplication application;
211   tet_infoline("Testing Dali::Integration::Scene::Add");
212
213   Dali::Integration::Scene scene = application.GetScene();
214
215   Actor actor = Actor::New();
216   DALI_TEST_CHECK( !actor.OnStage() );
217
218   scene.Add( actor );
219   DALI_TEST_CHECK( actor.OnStage() );
220
221   END_TEST;
222 }
223
224 int UtcDaliSceneRemove(void)
225 {
226   TestApplication application;
227   tet_infoline("Testing Dali::Integration::Scene::Remove");
228
229   Dali::Integration::Scene scene = application.GetScene();
230
231   Actor actor = Actor::New();
232   DALI_TEST_CHECK( !actor.OnStage() );
233
234   scene.Add( actor );
235   DALI_TEST_CHECK( actor.OnStage() );
236
237   scene.Remove(actor);
238   DALI_TEST_CHECK( !actor.OnStage() );
239
240   END_TEST;
241 }
242
243 int UtcDaliSceneGetSize(void)
244 {
245   TestApplication application;
246   tet_infoline("Testing Dali::Integration::Scene::GetSize");
247
248   Dali::Integration::Scene scene = application.GetScene();
249   Size size = scene.GetSize();
250   DALI_TEST_EQUALS( TestApplication::DEFAULT_SURFACE_WIDTH, size.width, TEST_LOCATION );
251   DALI_TEST_EQUALS( TestApplication::DEFAULT_SURFACE_HEIGHT, size.height, TEST_LOCATION );
252
253   END_TEST;
254 }
255
256 int UtcDaliSceneGetDpi(void)
257 {
258   TestApplication application; // Initializes core DPI to default values
259
260   // Test that setting core DPI explicitly also sets up the scene's DPI.
261   Dali::Integration::Scene scene = application.GetScene();
262   scene.SetDpi( Vector2(200.0f, 180.0f) );
263   Vector2 dpi = scene.GetDpi();
264   DALI_TEST_EQUALS( dpi.x, 200.0f, TEST_LOCATION );
265   DALI_TEST_EQUALS( dpi.y, 180.0f, TEST_LOCATION );
266   END_TEST;
267 }
268
269 int UtcDaliSceneGetRenderTaskList(void)
270 {
271   TestApplication application;
272   tet_infoline("Testing Dali::Integration::Scene::GetRenderTaskList");
273
274   Dali::Integration::Scene scene = application.GetScene();
275
276   // Check we get a valid instance.
277   const RenderTaskList& tasks = scene.GetRenderTaskList();
278
279   // There should be 1 task by default.
280   DALI_TEST_EQUALS( tasks.GetTaskCount(), 1u, TEST_LOCATION );
281
282   // RenderTaskList has it's own UTC tests.
283   // But we can confirm that GetRenderTaskList in Stage retrieves the same RenderTaskList each time.
284   RenderTask newTask = scene.GetRenderTaskList().CreateTask();
285
286   DALI_TEST_EQUALS( scene.GetRenderTaskList().GetTask( 1 ), newTask, TEST_LOCATION );
287
288   END_TEST;
289 }
290
291 int UtcDaliSceneGetRootLayer(void)
292 {
293   TestApplication application;
294   tet_infoline("Testing Dali::Integration::Scene::GetRootLayer");
295
296   Dali::Integration::Scene scene = application.GetScene();
297   Layer layer = scene.GetLayer( 0 );
298   DALI_TEST_CHECK( layer );
299
300   // Check that GetRootLayer() correctly retreived layer 0.
301   DALI_TEST_CHECK( scene.GetRootLayer() == layer );
302
303   END_TEST;
304 }
305
306 int UtcDaliSceneGetLayerCount(void)
307 {
308   TestApplication application;
309   tet_infoline("Testing Dali::Integration::Scene::GetLayerCount");
310
311   Dali::Integration::Scene scene = application.GetScene();
312   // Initially we have a default layer
313   DALI_TEST_EQUALS( scene.GetLayerCount(), 1u, TEST_LOCATION );
314
315   Layer layer = Layer::New();
316   scene.Add( layer );
317
318   DALI_TEST_EQUALS( scene.GetLayerCount(), 2u, TEST_LOCATION );
319   END_TEST;
320 }
321
322 int UtcDaliSceneGetLayer(void)
323 {
324   TestApplication application;
325   tet_infoline("Testing Dali::Integration::Scene::GetLayer");
326
327   Dali::Integration::Scene scene = application.GetScene();
328
329   Layer rootLayer = scene.GetLayer( 0 );
330   DALI_TEST_CHECK( rootLayer );
331
332   Layer layer = Layer::New();
333   scene.Add( layer );
334
335   Layer sameLayer = scene.GetLayer( 1 );
336   DALI_TEST_CHECK( layer == sameLayer );
337
338   END_TEST;
339 }
340
341 int UtcDaliSceneGet(void)
342 {
343   TestApplication application;
344   tet_infoline("Testing Dali::Integration::Scene::Get");
345
346   Dali::Integration::Scene scene = application.GetScene();
347
348   Actor actor = Actor::New();
349   DALI_TEST_CHECK( Dali::Integration::Scene() == Dali::Integration::Scene::Get( actor ) );
350
351   scene.Add( actor );
352
353   DALI_TEST_CHECK( scene == Dali::Integration::Scene::Get( actor ) );
354
355   END_TEST;
356 }
357
358 int UtcDaliSceneDiscard(void)
359 {
360   TestApplication application;
361   tet_infoline("Testing Dali::Scene::Discard");
362
363   // Create a new Scene
364   Dali::Integration::Scene scene = Dali::Integration::Scene::New( Vector2( 480.0f, 800.0f ) );
365   DALI_TEST_CHECK( scene );
366
367   // One reference of scene kept here and the other one kept in the Core
368   DALI_TEST_CHECK( scene.GetBaseObject().ReferenceCount() == 2 );
369
370   // Render and notify.
371   application.SendNotification();
372   application.Render(0);
373
374   // Keep the reference of the root layer handle so it will still be alive after the scene is deleted
375   Layer rootLayer = scene.GetRootLayer();
376   DALI_TEST_CHECK( rootLayer );
377   DALI_TEST_CHECK( rootLayer.GetBaseObject().ReferenceCount() == 2 );
378
379   // Request to discard the scene from the Core
380   scene.Discard();
381   DALI_TEST_CHECK( scene.GetBaseObject().ReferenceCount() == 1 );
382
383   // Reset the scene handle
384   scene.Reset();
385
386   // Render and notify.
387   application.SendNotification();
388   application.Render(0);
389
390   // At this point, the scene should have been automatically deleted
391   // To prove this, the ref count of the root layer handle should be decremented to 1
392   DALI_TEST_CHECK( rootLayer.GetBaseObject().ReferenceCount() == 1 );
393
394   // Delete the root layer handle
395   rootLayer.Reset();
396
397   // Render and notify.
398   application.SendNotification();
399   application.Render(0);
400
401   END_TEST;
402 }
403
404 int UtcDaliSceneCreateNewSceneDuringCoreEventProcessing(void)
405 {
406   TestApplication application;
407
408   Dali::Integration::Scene scene = application.GetScene();
409
410   TouchedSignalData data;
411   data.createNewScene = true;
412   TouchFunctor functor( data );
413   scene.TouchSignal().Connect( &application, functor );
414
415   // Render and notify.
416   application.SendNotification();
417   application.Render();
418
419   GenerateTouch( application, PointState::DOWN, Vector2( 10.0f, 10.0f ) );
420
421   DALI_TEST_EQUALS( true, data.functorCalled, TEST_LOCATION );
422   DALI_TEST_EQUALS( true, data.createNewScene, TEST_LOCATION );
423   DALI_TEST_EQUALS( true, data.newSceneCreated, TEST_LOCATION );
424   data.Reset();
425
426   END_TEST;
427 }
428
429 int UtcDaliSceneRootLayerAndSceneAlignment(void)
430 {
431   TestApplication application;
432
433   // Create a Scene
434   Dali::Integration::Scene scene = Dali::Integration::Scene::New( Vector2( 480.0f, 800.0f ) );
435   DALI_TEST_CHECK( scene );
436
437   // Create the render surface for the scene
438   TestRenderSurface* renderSurface = new TestRenderSurface( Dali::PositionSize( 0, 0, 480.0f, 800.0f ) );
439   scene.SetSurface( *renderSurface );
440
441   // One reference of scene kept here and the other one kept in the Core
442   DALI_TEST_CHECK( scene.GetBaseObject().ReferenceCount() == 2 );
443
444   // Add a renderable actor to the scene
445   auto actor = CreateRenderableActor();
446   scene.Add( actor );
447
448   // Render and notify.
449   application.SendNotification();
450   application.Render(0);
451
452   // Keep the reference of the root layer handle so it will still be alive after the scene is deleted
453   Layer rootLayer = scene.GetRootLayer();
454   DALI_TEST_CHECK( rootLayer );
455   DALI_TEST_CHECK( rootLayer.GetBaseObject().ReferenceCount() == 2 );
456
457   // Request to discard the scene from the Core
458   scene.Discard();
459   DALI_TEST_CHECK( scene.GetBaseObject().ReferenceCount() == 1 );
460
461   // Reset the scene handle
462   scene.Reset();
463
464   // Render and notify.
465   application.SendNotification();
466   application.Render(0);
467
468   // At this point, the scene should have been automatically deleted
469   // To prove this, the ref count of the root layer handle should be decremented to 1
470   DALI_TEST_CHECK( rootLayer.GetBaseObject().ReferenceCount() == 1 );
471
472   // Create a new Scene while the root layer of the deleted scene is still alive
473   Dali::Integration::Scene newScene = Dali::Integration::Scene::New( Vector2( 480.0f, 800.0f ) );
474   DALI_TEST_CHECK( newScene );
475
476   // Render and notify.
477   application.SendNotification();
478   application.Render(0);
479
480   // At this point, we have only one scene but two root layers
481   // The root layer of the deleted scene is still alive
482   DALI_TEST_CHECK( rootLayer.GetBaseObject().ReferenceCount() == 1 );
483
484   // Delete the root layer of the deleted scene
485   rootLayer.Reset();
486
487   // Render and notify.
488   application.SendNotification();
489   application.Render(0);
490
491   END_TEST;
492 }
493
494 int UtcDaliSceneDeleteSurface(void)
495 {
496   TestApplication application;
497
498   // Create a Scene
499   Dali::Integration::Scene scene = Dali::Integration::Scene::New( Vector2( 480.0f, 800.0f ) );
500   DALI_TEST_CHECK( scene );
501
502   // Create the render surface for the scene
503   TestRenderSurface* renderSurface = new TestRenderSurface( Dali::PositionSize( 0, 0, 480.0f, 800.0f ) );
504   scene.SetSurface( *renderSurface );
505
506   // Render and notify.
507   application.SendNotification();
508   application.Render(0);
509
510   // Add a renderable actor to the scene
511   auto actor = CreateRenderableActor();
512   scene.Add( actor );
513
514   // Render and notify.
515   application.SendNotification();
516   application.Render(0);
517
518   // Notify the Core that the render surface will be deleted.
519   application.GetCore().SurfaceDeleted( renderSurface );
520
521   // Delete the render surface
522   delete renderSurface;
523   renderSurface = nullptr;
524
525   // Render and notify.
526   application.SendNotification();
527   application.Render(0);
528
529   END_TEST;
530 }
531
532 int UtcDaliSceneEventProcessingFinishedP(void)
533 {
534   TestApplication application;
535   Dali::Integration::Scene scene = application.GetScene();
536
537   bool eventProcessingFinished = false;
538   EventProcessingFinishedFunctor functor( eventProcessingFinished );
539   scene.EventProcessingFinishedSignal().Connect( &application, functor );
540
541   Actor actor( Actor::New() );
542   scene.Add( actor );
543
544   application.SendNotification();
545   application.Render();
546
547   DALI_TEST_CHECK( eventProcessingFinished );
548
549   END_TEST;
550 }
551
552 int UtcDaliSceneEventProcessingFinishedN(void)
553 {
554   TestApplication application;
555   Dali::Integration::Scene scene = application.GetScene();
556
557   bool eventProcessingFinished = false;
558   EventProcessingFinishedFunctor functor( eventProcessingFinished );
559   scene.EventProcessingFinishedSignal().Connect( &application, functor );
560
561   Actor actor( Actor::New() );
562   scene.Add( actor );
563
564   // Do not complete event processing and confirm the signal has not been emitted.
565   DALI_TEST_CHECK( !eventProcessingFinished );
566
567   END_TEST;
568 }
569
570 int UtcDaliSceneSignalKeyEventP(void)
571 {
572   TestApplication application;
573   Dali::Integration::Scene scene = application.GetScene();
574
575   KeyEventSignalData data;
576   KeyEventReceivedFunctor functor( data );
577   scene.KeyEventSignal().Connect( &application, functor );
578
579   Integration::KeyEvent event( "i", "", "i", 0, 0, 0, Integration::KeyEvent::Down, "i", DEFAULT_DEVICE_NAME, Device::Class::NONE, Device::Subclass::NONE );
580   application.ProcessEvent( event );
581
582   DALI_TEST_EQUALS( true, data.functorCalled, TEST_LOCATION );
583   DALI_TEST_CHECK( event.keyModifier == data.receivedKeyEvent.keyModifier );
584   DALI_TEST_CHECK( event.keyName == data.receivedKeyEvent.keyPressedName );
585   DALI_TEST_CHECK( event.keyString == data.receivedKeyEvent.keyPressed );
586   DALI_TEST_CHECK( event.state == static_cast<Integration::KeyEvent::State>( data.receivedKeyEvent.state ) );
587
588   data.Reset();
589
590   Integration::KeyEvent event2( "i", "", "i", 0, 0, 0, Integration::KeyEvent::Up, "i", DEFAULT_DEVICE_NAME, Device::Class::NONE, Device::Subclass::NONE );
591   application.ProcessEvent( event2 );
592
593   DALI_TEST_EQUALS( true, data.functorCalled, TEST_LOCATION );
594   DALI_TEST_CHECK( event2.keyModifier == data.receivedKeyEvent.keyModifier );
595   DALI_TEST_CHECK( event2.keyName == data.receivedKeyEvent.keyPressedName );
596   DALI_TEST_CHECK( event2.keyString == data.receivedKeyEvent.keyPressed );
597   DALI_TEST_CHECK( event2.state == static_cast<Integration::KeyEvent::State>( data.receivedKeyEvent.state ) );
598
599   data.Reset();
600
601   Integration::KeyEvent event3( "a", "", "a", 0, 0, 0, Integration::KeyEvent::Down, "a", DEFAULT_DEVICE_NAME, Device::Class::NONE, Device::Subclass::NONE );
602   application.ProcessEvent( event3 );
603
604   DALI_TEST_EQUALS( true, data.functorCalled, TEST_LOCATION );
605   DALI_TEST_CHECK( event3.keyModifier == data.receivedKeyEvent.keyModifier );
606   DALI_TEST_CHECK( event3.keyName == data.receivedKeyEvent.keyPressedName );
607   DALI_TEST_CHECK( event3.keyString == data.receivedKeyEvent.keyPressed );
608   DALI_TEST_CHECK( event3.state == static_cast<Integration::KeyEvent::State>( data.receivedKeyEvent.state ) );
609
610   data.Reset();
611
612   Integration::KeyEvent event4( "a", "", "a", 0, 0, 0, Integration::KeyEvent::Up, "a", DEFAULT_DEVICE_NAME, Device::Class::NONE, Device::Subclass::NONE );
613   application.ProcessEvent( event4 );
614
615   DALI_TEST_EQUALS( true, data.functorCalled, TEST_LOCATION );
616   DALI_TEST_CHECK( event4.keyModifier == data.receivedKeyEvent.keyModifier );
617   DALI_TEST_CHECK( event4.keyName == data.receivedKeyEvent.keyPressedName );
618   DALI_TEST_CHECK( event4.keyString == data.receivedKeyEvent.keyPressed );
619   DALI_TEST_CHECK( event4.state == static_cast<Integration::KeyEvent::State>( data.receivedKeyEvent.state ) );
620   END_TEST;
621 }
622
623 int UtcDaliSceneSignalKeyEventN(void)
624 {
625   TestApplication application;
626   Dali::Integration::Scene scene = application.GetScene();
627
628   KeyEventSignalData data;
629   KeyEventReceivedFunctor functor( data );
630   scene.KeyEventSignal().Connect( &application, functor );
631
632   // Check that a non-pressed key events data is not modified.
633   DALI_TEST_EQUALS( false, data.functorCalled, TEST_LOCATION );
634
635   END_TEST;
636 }
637
638 int UtcDaliSceneTouchSignalP(void)
639 {
640   TestApplication application;
641   Dali::Integration::Scene scene = application.GetScene();
642
643   TouchedSignalData data;
644   TouchFunctor functor( data );
645   scene.TouchSignal().Connect( &application, functor );
646
647   // Render and notify.
648   application.SendNotification();
649   application.Render();
650
651   // Basic test: No actors, single touch (down then up).
652   {
653     GenerateTouch( application, PointState::DOWN, Vector2( 10.0f, 10.0f ) );
654
655     DALI_TEST_EQUALS( true, data.functorCalled, TEST_LOCATION );
656     DALI_TEST_CHECK( data.receivedTouchData.GetPointCount() != 0u );
657     DALI_TEST_CHECK( !data.receivedTouchData.GetHitActor(0) );
658     data.Reset();
659
660     GenerateTouch( application, PointState::UP, Vector2( 10.0f, 10.0f ) );
661
662     DALI_TEST_EQUALS( true, data.functorCalled, TEST_LOCATION );
663     DALI_TEST_CHECK( data.receivedTouchData.GetPointCount() != 0u );
664     DALI_TEST_CHECK( !data.receivedTouchData.GetHitActor(0) );
665     data.Reset();
666   }
667
668   // Add an actor to the scene.
669   Actor actor = Actor::New();
670   actor.SetSize( 100.0f, 100.0f );
671   actor.SetAnchorPoint( AnchorPoint::TOP_LEFT );
672   actor.SetParentOrigin( ParentOrigin::TOP_LEFT );
673   actor.TouchedSignal().Connect( &DummyTouchCallback );
674   scene.Add( actor );
675
676   // Render and notify.
677   application.SendNotification();
678   application.Render();
679
680   // Actor on scene, single touch, down in actor, motion, then up outside actor.
681   {
682     GenerateTouch( application, PointState::DOWN, Vector2( 10.0f, 10.0f ) );
683
684     DALI_TEST_EQUALS( true, data.functorCalled, TEST_LOCATION );
685     DALI_TEST_CHECK( data.receivedTouchData.GetPointCount() != 0u );
686     DALI_TEST_CHECK( data.receivedTouchData.GetHitActor(0) == actor );
687     data.Reset();
688
689     GenerateTouch( application, PointState::MOTION, Vector2( 150.0f, 10.0f ) ); // Some motion
690
691     DALI_TEST_EQUALS( false, data.functorCalled, TEST_LOCATION );
692     data.Reset();
693
694     GenerateTouch( application, PointState::UP, Vector2( 150.0f, 10.0f ) ); // Some motion
695
696     DALI_TEST_EQUALS( true, data.functorCalled, TEST_LOCATION );
697     DALI_TEST_CHECK( data.receivedTouchData.GetPointCount() != 0u );
698     DALI_TEST_CHECK( !data.receivedTouchData.GetHitActor(0) );
699     data.Reset();
700   }
701
702   // Multiple touch. Should only receive a touch on first down and last up.
703   {
704     Integration::TouchEvent touchEvent;
705     Integration::Point point;
706
707     // 1st point
708     point.SetState( PointState::DOWN );
709     point.SetScreenPosition( Vector2( 10.0f, 10.0f ) );
710     touchEvent.points.push_back( point );
711     application.ProcessEvent( touchEvent );
712     DALI_TEST_EQUALS( true, data.functorCalled, TEST_LOCATION );
713     DALI_TEST_EQUALS( data.receivedTouchData.GetPointCount(), 1u, TEST_LOCATION );
714     data.Reset();
715
716     // 2nd point
717     touchEvent.points[0].SetState( PointState::STATIONARY );
718     point.SetDeviceId( 1 );
719     point.SetScreenPosition( Vector2( 50.0f, 50.0f ) );
720     touchEvent.points.push_back( point );
721     application.ProcessEvent( touchEvent );
722     DALI_TEST_EQUALS( false, data.functorCalled, TEST_LOCATION );
723     data.Reset();
724
725     // Primary point is up
726     touchEvent.points[0].SetState( PointState::UP );
727     touchEvent.points[1].SetState( PointState::STATIONARY );
728     application.ProcessEvent( touchEvent );
729     DALI_TEST_EQUALS( false, data.functorCalled, TEST_LOCATION );
730     data.Reset();
731
732     // Remove 1st point now, 2nd point is now in motion
733     touchEvent.points.erase( touchEvent.points.begin() );
734     touchEvent.points[0].SetState( PointState::MOTION );
735     touchEvent.points[0].SetScreenPosition( Vector2( 150.0f, 50.0f ) );
736     application.ProcessEvent( touchEvent );
737     DALI_TEST_EQUALS( false, data.functorCalled, TEST_LOCATION );
738     data.Reset();
739
740     // Final point Up
741     touchEvent.points[0].SetState( PointState::UP );
742     application.ProcessEvent( touchEvent );
743     DALI_TEST_EQUALS( true, data.functorCalled, TEST_LOCATION );
744     DALI_TEST_EQUALS( data.receivedTouchData.GetPointCount(), 1u, TEST_LOCATION );
745     data.Reset();
746   }
747   END_TEST;
748 }
749
750 int UtcDaliSceneTouchSignalN(void)
751 {
752   TestApplication application;
753   Dali::Integration::Scene scene = application.GetScene();
754
755   TouchedSignalData data;
756   TouchFunctor functor( data );
757   scene.TouchSignal().Connect( &application, functor );
758
759   // Render and notify.
760   application.SendNotification();
761   application.Render();
762
763   // Confirm functor not called before there has been any touch event.
764   DALI_TEST_EQUALS( false, data.functorCalled, TEST_LOCATION );
765
766   // No actors, single touch, down, motion then up.
767   {
768     GenerateTouch( application, PointState::DOWN, Vector2( 10.0f, 10.0f ) );
769
770     DALI_TEST_EQUALS( true, data.functorCalled, TEST_LOCATION );
771     DALI_TEST_CHECK( data.receivedTouchData.GetPointCount() != 0u );
772     DALI_TEST_CHECK( !data.receivedTouchData.GetHitActor(0));
773
774     data.Reset();
775
776     // Confirm there is no signal when the touchpoint is only moved.
777     GenerateTouch( application, PointState::MOTION, Vector2( 1200.0f, 10.0f ) ); // Some motion
778
779     DALI_TEST_EQUALS( false, data.functorCalled, TEST_LOCATION );
780     data.Reset();
781
782     // Confirm a following up event generates a signal.
783     GenerateTouch( application, PointState::UP, Vector2( 1200.0f, 10.0f ) );
784
785     DALI_TEST_EQUALS( true, data.functorCalled, TEST_LOCATION );
786     DALI_TEST_CHECK( data.receivedTouchData.GetPointCount() != 0u );
787     DALI_TEST_CHECK( !data.receivedTouchData.GetHitActor(0));
788     data.Reset();
789   }
790
791   // Add an actor to the scene.
792   Actor actor = Actor::New();
793   actor.SetSize( 100.0f, 100.0f );
794   actor.SetAnchorPoint( AnchorPoint::TOP_LEFT );
795   actor.SetParentOrigin( ParentOrigin::TOP_LEFT );
796   actor.TouchedSignal().Connect( &DummyTouchCallback );
797   scene.Add( actor );
798
799   // Render and notify.
800   application.SendNotification();
801   application.Render();
802
803   // Actor on scene. Interrupted before down and interrupted after down.
804   {
805     GenerateTouch( application, PointState::INTERRUPTED, Vector2( 10.0f, 10.0f ) );
806
807     DALI_TEST_EQUALS( true, data.functorCalled, TEST_LOCATION );
808     DALI_TEST_CHECK( data.receivedTouchData.GetPointCount() != 0u );
809     DALI_TEST_CHECK( !data.receivedTouchData.GetHitActor(0) );
810     DALI_TEST_CHECK( data.receivedTouchData.GetState(0) == PointState::INTERRUPTED );
811     data.Reset();
812
813     GenerateTouch( application, PointState::DOWN, Vector2( 10.0f, 10.0f ) );
814
815     DALI_TEST_EQUALS( true, data.functorCalled, TEST_LOCATION );
816     DALI_TEST_CHECK( data.receivedTouchData.GetPointCount() != 0u );
817     DALI_TEST_CHECK( data.receivedTouchData.GetHitActor(0) == actor );
818     DALI_TEST_CHECK( data.receivedTouchData.GetState(0) == PointState::DOWN );
819     data.Reset();
820
821     GenerateTouch( application, PointState::INTERRUPTED, Vector2( 10.0f, 10.0f ) );
822
823     DALI_TEST_EQUALS( true, data.functorCalled, TEST_LOCATION );
824     DALI_TEST_CHECK( data.receivedTouchData.GetPointCount() != 0u );
825     DALI_TEST_CHECK( !data.receivedTouchData.GetHitActor(0) );
826     DALI_TEST_CHECK( data.receivedTouchData.GetState(0) == PointState::INTERRUPTED );
827
828     DALI_TEST_EQUALS( data.receivedTouchData.GetPointCount(), 1u, TEST_LOCATION );
829
830     // Check that getting info about a non-existent point returns an empty handle
831     Actor actor = data.receivedTouchData.GetHitActor( 1 );
832     DALI_TEST_CHECK( !actor );
833
834     data.Reset();
835   }
836
837   END_TEST;
838 }
839
840 int UtcDaliSceneSignalWheelEventP(void)
841 {
842   TestApplication application;
843   Dali::Integration::Scene scene = application.GetScene();
844
845   WheelEventSignalData data;
846   WheelEventReceivedFunctor functor( data );
847   scene.WheelEventSignal().Connect( &application, functor );
848
849   Integration::WheelEvent event( Integration::WheelEvent::CUSTOM_WHEEL, 0, 0u, Vector2( 0.0f, 0.0f ), 1, 1000u );
850   application.ProcessEvent( event );
851
852   DALI_TEST_EQUALS( true, data.functorCalled, TEST_LOCATION );
853   DALI_TEST_CHECK( static_cast< WheelEvent::Type >(event.type) == data.receivedWheelEvent.type );
854   DALI_TEST_CHECK( event.direction == data.receivedWheelEvent.direction );
855   DALI_TEST_CHECK( event.modifiers == data.receivedWheelEvent.modifiers );
856   DALI_TEST_CHECK( event.point == data.receivedWheelEvent.point );
857   DALI_TEST_CHECK( event.z == data.receivedWheelEvent.z );
858   DALI_TEST_CHECK( event.timeStamp == data.receivedWheelEvent.timeStamp );
859
860   data.Reset();
861
862   Integration::WheelEvent event2( Integration::WheelEvent::CUSTOM_WHEEL, 0, 0u, Vector2( 0.0f, 0.0f ), -1, 1000u );
863   application.ProcessEvent( event2 );
864
865   DALI_TEST_EQUALS( true, data.functorCalled, TEST_LOCATION );
866   DALI_TEST_CHECK( static_cast< WheelEvent::Type >(event2.type) == data.receivedWheelEvent.type );
867   DALI_TEST_CHECK( event2.direction == data.receivedWheelEvent.direction );
868   DALI_TEST_CHECK( event2.modifiers == data.receivedWheelEvent.modifiers );
869   DALI_TEST_CHECK( event2.point == data.receivedWheelEvent.point );
870   DALI_TEST_CHECK( event2.z == data.receivedWheelEvent.z );
871   DALI_TEST_CHECK( event2.timeStamp == data.receivedWheelEvent.timeStamp );
872   END_TEST;
873 }
874
875 int UtcDaliSceneEnsureEmptySceneCleared(void)
876 {
877   tet_infoline( "Ensure we clear the newly added window" );
878
879   TestApplication application;
880
881   // Create a new scene and set the background colors of both the new and the main scenes
882   auto defaultScene = application.GetScene();
883   defaultScene.SetBackgroundColor( Color::WHITE );
884
885   auto newScene = Integration::Scene::New( Vector2( 480.0f, 800.0f ) );
886   newScene.SetBackgroundColor( Color::RED );
887
888   // Need to create a renderable as we don't start rendering until we have at least one
889   // We don't need to add this to any scene
890   auto actor = CreateRenderableActor();
891
892   auto& glAbstraction = application.GetGlAbstraction();
893   auto clearCountBefore = glAbstraction.GetClearCountCalled();
894
895   application.SendNotification();
896   application.Render();
897
898   DALI_TEST_EQUALS( glAbstraction.GetClearCountCalled(), clearCountBefore + 2, TEST_LOCATION );
899
900   // Add the actor to the main scene
901   defaultScene.Add( actor );
902
903   application.SendNotification();
904   application.Render();
905
906   // Add another scene and set its background color, ensure we clear it to the appropriate color
907
908   auto thirdScene = Integration::Scene::New( Vector2( 200.0f, 200.0f ) );
909   thirdScene.SetBackgroundColor( Color::BLUE );
910
911   clearCountBefore = glAbstraction.GetClearCountCalled();
912
913   application.SendNotification();
914   application.Render();
915
916   DALI_TEST_EQUALS( glAbstraction.GetClearCountCalled(), clearCountBefore + 3, TEST_LOCATION );
917
918   END_TEST;
919 }
920
921 int UtcDaliSceneSurfaceResizedDefaultScene(void)
922 {
923   tet_infoline( "Ensure resizing of the surface is handled properly" );
924
925   TestApplication application;
926
927   auto defaultScene = application.GetScene();
928   Integration::RenderSurface* defaultSurface = defaultScene.GetSurface();
929   DALI_TEST_CHECK( defaultSurface );
930
931   // Ensure stage size matches the surface size
932   auto stage = Stage::GetCurrent();
933   DALI_TEST_EQUALS( stage.GetSize(), Vector2( defaultSurface->GetPositionSize().width, defaultSurface->GetPositionSize().height ), TEST_LOCATION );
934
935   // Resize the surface and inform the scene accordingly
936   Vector2 newSize( 1000.0f, 2000.0f );
937   DALI_TEST_CHECK( stage.GetSize() != newSize );
938   defaultSurface->MoveResize( PositionSize( 0, 0, newSize.width, newSize.height ) );
939   defaultScene.SurfaceResized();
940
941   DALI_TEST_EQUALS( stage.GetSize(), newSize, TEST_LOCATION );
942   DALI_TEST_EQUALS( defaultScene.GetSize(), newSize, TEST_LOCATION );
943
944   END_TEST;
945 }
946
947 int UtcDaliSceneSurfaceResizedAdditionalScene(void)
948 {
949   tet_infoline( "Ensure resizing of the surface is handled properly on additional scenes" );
950
951   TestApplication application;
952   Vector2 originalSurfaceSize( 500.0f, 1000.0f );
953
954   auto scene = Integration::Scene::New( Vector2::ZERO );
955   TestRenderSurface surface( PositionSize( 0.0f, 0.0f, originalSurfaceSize.width, originalSurfaceSize.height ) );
956   scene.SetSurface( surface );
957
958   // Ensure stage size does NOT match the surface size
959   auto stage = Stage::GetCurrent();
960   const auto stageSize = stage.GetSize();
961   DALI_TEST_CHECK( stageSize != originalSurfaceSize );
962   DALI_TEST_EQUALS( originalSurfaceSize, scene.GetSize(), TEST_LOCATION );
963
964   // Resize the surface and inform the scene accordingly
965   Vector2 newSize( 1000.0f, 2000.0f );
966   DALI_TEST_CHECK( stage.GetSize() != newSize );
967   surface.MoveResize( PositionSize( 0, 0, newSize.width, newSize.height ) );
968   scene.SurfaceResized();
969
970   // Ensure the stage hasn't been resized
971   DALI_TEST_EQUALS( stage.GetSize(), stageSize, TEST_LOCATION );
972   DALI_TEST_EQUALS( scene.GetSize(), newSize, TEST_LOCATION );
973
974   END_TEST;
975 }