Fix MSVC warning.
[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 #include <mesh-builder.h>
29
30 // Internal headers are allowed here
31
32 namespace
33 {
34
35 const std::string DEFAULT_DEVICE_NAME("hwKeyboard");
36
37 // Functor for EventProcessingFinished signal
38 struct EventProcessingFinishedFunctor
39 {
40   /**
41    * @param[in] eventProcessingFinished reference to a boolean variable used to check if signal has been called.
42    */
43   EventProcessingFinishedFunctor( bool& eventProcessingFinished )
44   : mEventProcessingFinished( eventProcessingFinished )
45   {}
46
47   void operator()()
48   {
49     mEventProcessingFinished = true;
50   }
51
52   bool& mEventProcessingFinished;
53 };
54
55 // Stores data that is populated in the key-event callback and will be read by the TET cases
56 struct KeyEventSignalData
57 {
58   KeyEventSignalData()
59   : functorCalled(false)
60   {}
61
62   void Reset()
63   {
64     functorCalled = false;
65
66     receivedKeyEvent.keyModifier = 0;
67     receivedKeyEvent.keyPressedName.clear();
68     receivedKeyEvent.keyPressed.clear();
69   }
70
71   bool functorCalled;
72   KeyEvent receivedKeyEvent;
73 };
74
75 // Functor that sets the data when called
76 struct KeyEventReceivedFunctor
77 {
78   KeyEventReceivedFunctor( KeyEventSignalData& data ) : signalData( data ) { }
79
80   bool operator()( const KeyEvent& keyEvent )
81   {
82     signalData.functorCalled = true;
83     signalData.receivedKeyEvent = keyEvent;
84
85     return true;
86   }
87
88   KeyEventSignalData& signalData;
89 };
90
91 // Stores data that is populated in the touched signal callback and will be read by the TET cases
92 struct TouchedSignalData
93 {
94   TouchedSignalData()
95   : functorCalled(false),
96     createNewScene(false),
97     newSceneCreated(false)
98   {}
99
100   void Reset()
101   {
102     functorCalled = false;
103     createNewScene = false;
104     newSceneCreated = false;
105
106     receivedTouchEvent.points.clear();
107     receivedTouchEvent.time = 0;
108
109     receivedTouchData.Reset();
110   }
111
112   bool functorCalled;
113   bool createNewScene;
114   bool newSceneCreated;
115   TouchEvent receivedTouchEvent;
116   TouchData receivedTouchData;
117 };
118
119 // Functor that sets the data when touched signal is received
120 struct TouchedFunctor
121 {
122   TouchedFunctor( TouchedSignalData& data ) : signalData( data ) { }
123
124   void operator()( const TouchEvent& touch )
125   {
126     signalData.functorCalled = true;
127     signalData.receivedTouchEvent = touch;
128   }
129
130   TouchedSignalData& signalData;
131 };
132
133 // Functor that sets the data when touched signal is received
134 struct TouchFunctor
135 {
136   TouchFunctor( TouchedSignalData& data ) : signalData( data ) { }
137
138   void operator()( const TouchData& touch )
139   {
140     signalData.functorCalled = true;
141     signalData.receivedTouchData = touch;
142
143     if ( signalData.createNewScene )
144     {
145       TestRenderSurface* surface = new TestRenderSurface( PositionSize( 0.0f, 0.0f, 480.0f, 800.0f ) ); // This is a leak, but we need to keep the surface alive till the end
146       Dali::Integration::Scene scene = Dali::Integration::Scene::New( *surface );
147       DALI_TEST_CHECK( scene );
148
149       signalData.newSceneCreated = true;
150     }
151   }
152
153   void operator()()
154   {
155     signalData.functorCalled = true;
156   }
157
158   TouchedSignalData& signalData;
159 };
160
161 // Stores data that is populated in the wheel-event callback and will be read by the TET cases
162 struct WheelEventSignalData
163 {
164   WheelEventSignalData()
165   : functorCalled(false)
166   {}
167
168   void Reset()
169   {
170     functorCalled = false;
171   }
172
173   bool functorCalled;
174   WheelEvent receivedWheelEvent;
175 };
176
177 // Functor that sets the data when wheel-event signal is received
178 struct WheelEventReceivedFunctor
179 {
180   WheelEventReceivedFunctor( WheelEventSignalData& data ) : signalData( data ) { }
181
182   bool operator()( const WheelEvent& wheelEvent )
183   {
184     signalData.functorCalled = true;
185     signalData.receivedWheelEvent = wheelEvent;
186
187     return true;
188   }
189
190   WheelEventSignalData& signalData;
191 };
192
193 // Stores data that is populated in the KeyEventGeneratedSignal callback and will be read by the TET cases
194 struct KeyEventGeneratedSignalData
195 {
196   KeyEventGeneratedSignalData()
197   : functorCalled(false)
198   {}
199
200   void Reset()
201   {
202     functorCalled = false;
203
204     receivedKeyEvent.keyModifier = 0;
205     receivedKeyEvent.keyPressedName.clear();
206     receivedKeyEvent.keyPressed.clear();
207   }
208
209   bool functorCalled;
210   KeyEvent receivedKeyEvent;
211 };
212
213 // Functor that sets the data when called
214 struct KeyEventGeneratedReceivedFunctor
215 {
216   KeyEventGeneratedReceivedFunctor( KeyEventGeneratedSignalData& data )
217   : signalData( data )
218   {}
219
220   bool operator()( const KeyEvent& keyEvent )
221   {
222     signalData.functorCalled = true;
223     signalData.receivedKeyEvent = keyEvent;
224
225     return true;
226   }
227
228   bool operator()()
229   {
230     signalData.functorCalled = true;
231     return true;
232   }
233
234   KeyEventGeneratedSignalData& signalData;
235 };
236
237 void GenerateTouch( TestApplication& application, PointState::Type state, const Vector2& screenPosition )
238 {
239   Integration::TouchEvent touchEvent;
240   Integration::Point point;
241   point.SetState( state );
242   point.SetScreenPosition( screenPosition );
243   touchEvent.points.push_back( point );
244   application.ProcessEvent( touchEvent );
245 }
246
247 bool DummyTouchCallback( Actor actor, const TouchEvent& touch )
248 {
249   return true;
250 }
251
252 } // unnamed namespace
253
254 int UtcDaliSceneAdd(void)
255 {
256   TestApplication application;
257   tet_infoline("Testing Dali::Integration::Scene::Add");
258
259   Dali::Integration::Scene scene = application.GetScene();
260
261   Actor actor = Actor::New();
262   DALI_TEST_CHECK( !actor.OnStage() );
263
264   scene.Add( actor );
265   DALI_TEST_CHECK( actor.OnStage() );
266
267   END_TEST;
268 }
269
270 int UtcDaliSceneRemove(void)
271 {
272   TestApplication application;
273   tet_infoline("Testing Dali::Integration::Scene::Remove");
274
275   Dali::Integration::Scene scene = application.GetScene();
276
277   Actor actor = Actor::New();
278   DALI_TEST_CHECK( !actor.OnStage() );
279
280   scene.Add( actor );
281   DALI_TEST_CHECK( actor.OnStage() );
282
283   scene.Remove(actor);
284   DALI_TEST_CHECK( !actor.OnStage() );
285
286   END_TEST;
287 }
288
289 int UtcDaliSceneGetSize(void)
290 {
291   TestApplication application;
292   tet_infoline("Testing Dali::Integration::Scene::GetSize");
293
294   Dali::Integration::Scene scene = application.GetScene();
295   Size size = scene.GetSize();
296   DALI_TEST_EQUALS( TestApplication::DEFAULT_SURFACE_WIDTH, size.width, TEST_LOCATION );
297   DALI_TEST_EQUALS( TestApplication::DEFAULT_SURFACE_HEIGHT, size.height, TEST_LOCATION );
298
299   END_TEST;
300 }
301
302 int UtcDaliSceneGetDpi(void)
303 {
304   TestApplication application; // Initializes core DPI to default values
305
306   // Test that setting core DPI explicitly also sets up the scene's DPI.
307   Dali::Integration::Scene scene = application.GetScene();
308   scene.SetDpi( Vector2(200.0f, 180.0f) );
309   Vector2 dpi = scene.GetDpi();
310   DALI_TEST_EQUALS( dpi.x, 200.0f, TEST_LOCATION );
311   DALI_TEST_EQUALS( dpi.y, 180.0f, TEST_LOCATION );
312   END_TEST;
313 }
314
315 int UtcDaliSceneGetRenderTaskList(void)
316 {
317   TestApplication application;
318   tet_infoline("Testing Dali::Integration::Scene::GetRenderTaskList");
319
320   Dali::Integration::Scene scene = application.GetScene();
321
322   // Check we get a valid instance.
323   const RenderTaskList& tasks = scene.GetRenderTaskList();
324
325   // There should be 1 task by default.
326   DALI_TEST_EQUALS( tasks.GetTaskCount(), 1u, TEST_LOCATION );
327
328   // RenderTaskList has it's own UTC tests.
329   // But we can confirm that GetRenderTaskList in Stage retrieves the same RenderTaskList each time.
330   RenderTask newTask = scene.GetRenderTaskList().CreateTask();
331
332   DALI_TEST_EQUALS( scene.GetRenderTaskList().GetTask( 1 ), newTask, TEST_LOCATION );
333
334   END_TEST;
335 }
336
337 int UtcDaliSceneGetRootLayer(void)
338 {
339   TestApplication application;
340   tet_infoline("Testing Dali::Integration::Scene::GetRootLayer");
341
342   Dali::Integration::Scene scene = application.GetScene();
343   Layer layer = scene.GetLayer( 0 );
344   DALI_TEST_CHECK( layer );
345
346   // Check that GetRootLayer() correctly retreived layer 0.
347   DALI_TEST_CHECK( scene.GetRootLayer() == layer );
348
349   END_TEST;
350 }
351
352 int UtcDaliSceneGetLayerCount(void)
353 {
354   TestApplication application;
355   tet_infoline("Testing Dali::Integration::Scene::GetLayerCount");
356
357   Dali::Integration::Scene scene = application.GetScene();
358   // Initially we have a default layer
359   DALI_TEST_EQUALS( scene.GetLayerCount(), 1u, TEST_LOCATION );
360
361   Layer layer = Layer::New();
362   scene.Add( layer );
363
364   DALI_TEST_EQUALS( scene.GetLayerCount(), 2u, TEST_LOCATION );
365   END_TEST;
366 }
367
368 int UtcDaliSceneGetLayer(void)
369 {
370   TestApplication application;
371   tet_infoline("Testing Dali::Integration::Scene::GetLayer");
372
373   Dali::Integration::Scene scene = application.GetScene();
374
375   Layer rootLayer = scene.GetLayer( 0 );
376   DALI_TEST_CHECK( rootLayer );
377
378   Layer layer = Layer::New();
379   scene.Add( layer );
380
381   Layer sameLayer = scene.GetLayer( 1 );
382   DALI_TEST_CHECK( layer == sameLayer );
383
384   END_TEST;
385 }
386
387 int UtcDaliSceneGet(void)
388 {
389   TestApplication application;
390   tet_infoline("Testing Dali::Integration::Scene::Get");
391
392   Dali::Integration::Scene scene = application.GetScene();
393
394   Actor actor = Actor::New();
395   DALI_TEST_CHECK( Dali::Integration::Scene() == Dali::Integration::Scene::Get( actor ) );
396
397   scene.Add( actor );
398
399   DALI_TEST_CHECK( scene == Dali::Integration::Scene::Get( actor ) );
400
401   END_TEST;
402 }
403
404 int UtcDaliSceneDiscard(void)
405 {
406   TestApplication application;
407   tet_infoline("Testing Dali::Scene::Discard");
408
409   // Create a new Scene
410   TestRenderSurface surface( PositionSize( 0.0f, 0.0f, 480.0f, 800.0f ) );
411   Dali::Integration::Scene scene = Dali::Integration::Scene::New( surface );
412   DALI_TEST_CHECK( scene );
413
414   // One reference of scene kept here and the other one kept in the Core
415   DALI_TEST_CHECK( scene.GetBaseObject().ReferenceCount() == 2 );
416
417   // Render and notify.
418   application.SendNotification();
419   application.Render(0);
420
421   // Keep the reference of the root layer handle so it will still be alive after the scene is deleted
422   Layer rootLayer = scene.GetRootLayer();
423   DALI_TEST_CHECK( rootLayer );
424   DALI_TEST_CHECK( rootLayer.GetBaseObject().ReferenceCount() == 2 );
425
426   // Request to discard the scene from the Core
427   scene.Discard();
428   DALI_TEST_CHECK( scene.GetBaseObject().ReferenceCount() == 1 );
429
430   // Reset the scene handle
431   scene.Reset();
432
433   // Render and notify.
434   application.SendNotification();
435   application.Render(0);
436
437   // At this point, the scene should have been automatically deleted
438   // To prove this, the ref count of the root layer handle should be decremented to 1
439   DALI_TEST_CHECK( rootLayer.GetBaseObject().ReferenceCount() == 1 );
440
441   // Delete the root layer handle
442   rootLayer.Reset();
443
444   // Render and notify.
445   application.SendNotification();
446   application.Render(0);
447
448   END_TEST;
449 }
450
451 int UtcDaliSceneCreateNewSceneDuringCoreEventProcessing(void)
452 {
453   TestApplication application;
454
455   Dali::Integration::Scene scene = application.GetScene();
456
457   TouchedSignalData data;
458   data.createNewScene = true;
459   TouchFunctor functor( data );
460   scene.TouchSignal().Connect( &application, functor );
461
462   // Render and notify.
463   application.SendNotification();
464   application.Render();
465
466   GenerateTouch( application, PointState::DOWN, Vector2( 10.0f, 10.0f ) );
467
468   DALI_TEST_EQUALS( true, data.functorCalled, TEST_LOCATION );
469   DALI_TEST_EQUALS( true, data.createNewScene, TEST_LOCATION );
470   DALI_TEST_EQUALS( true, data.newSceneCreated, TEST_LOCATION );
471   data.Reset();
472
473   END_TEST;
474 }
475
476 int UtcDaliSceneRootLayerAndSceneAlignment(void)
477 {
478   TestApplication application;
479
480   // Create a Scene
481   TestRenderSurface surface( PositionSize( 0.0f, 0.0f, 480.0f, 800.0f ) );
482   Dali::Integration::Scene scene = Dali::Integration::Scene::New( surface );
483   DALI_TEST_CHECK( scene );
484
485   // One reference of scene kept here and the other one kept in the Core
486   DALI_TEST_CHECK( scene.GetBaseObject().ReferenceCount() == 2 );
487
488   // Add a renderable actor to the scene
489   auto actor = CreateRenderableActor();
490   scene.Add( actor );
491
492   // Render and notify.
493   application.SendNotification();
494   application.Render(0);
495
496   // Keep the reference of the root layer handle so it will still be alive after the scene is deleted
497   Layer rootLayer = scene.GetRootLayer();
498   DALI_TEST_CHECK( rootLayer );
499   DALI_TEST_CHECK( rootLayer.GetBaseObject().ReferenceCount() == 2 );
500
501   // Request to discard the scene from the Core
502   scene.Discard();
503   DALI_TEST_CHECK( scene.GetBaseObject().ReferenceCount() == 1 );
504
505   // Reset the scene handle
506   scene.Reset();
507
508   // Render and notify.
509   application.SendNotification();
510   application.Render(0);
511
512   // At this point, the scene should have been automatically deleted
513   // To prove this, the ref count of the root layer handle should be decremented to 1
514   DALI_TEST_CHECK( rootLayer.GetBaseObject().ReferenceCount() == 1 );
515
516   // Create a new Scene while the root layer of the deleted scene is still alive
517   TestRenderSurface surface2( PositionSize( 0.0f, 0.0f, 480.0f, 800.0f ) );
518   Dali::Integration::Scene newScene = Dali::Integration::Scene::New( surface2 );
519   DALI_TEST_CHECK( newScene );
520
521   // Render and notify.
522   application.SendNotification();
523   application.Render(0);
524
525   // At this point, we have only one scene but two root layers
526   // The root layer of the deleted scene is still alive
527   DALI_TEST_CHECK( rootLayer.GetBaseObject().ReferenceCount() == 1 );
528
529   // Delete the root layer of the deleted scene
530   rootLayer.Reset();
531
532   // Render and notify.
533   application.SendNotification();
534   application.Render(0);
535
536   END_TEST;
537 }
538
539 int UtcDaliSceneDeleteSurface(void)
540 {
541   TestApplication application;
542
543   // Create the render surface for the scene
544   TestRenderSurface* renderSurface = new TestRenderSurface( Dali::PositionSize( 0, 0, 480.0f, 800.0f ) );
545
546   // Create a Scene
547   Dali::Integration::Scene scene = Dali::Integration::Scene::New( *renderSurface );
548   DALI_TEST_CHECK( scene );
549
550   // Render and notify.
551   application.SendNotification();
552   application.Render(0);
553
554   // Add a renderable actor to the scene
555   auto actor = CreateRenderableActor();
556   scene.Add( actor );
557
558   // Render and notify.
559   application.SendNotification();
560   application.Render(0);
561
562   // Notify the Core that the render surface will be deleted.
563   application.GetCore().SurfaceDeleted( renderSurface );
564
565   // Delete the render surface
566   delete renderSurface;
567   renderSurface = nullptr;
568
569   // Render and notify.
570   application.SendNotification();
571   application.Render(0);
572
573   END_TEST;
574 }
575
576 int UtcDaliSceneEventProcessingFinishedP(void)
577 {
578   TestApplication application;
579   Dali::Integration::Scene scene = application.GetScene();
580
581   bool eventProcessingFinished = false;
582   EventProcessingFinishedFunctor functor( eventProcessingFinished );
583   scene.EventProcessingFinishedSignal().Connect( &application, functor );
584
585   Actor actor( Actor::New() );
586   scene.Add( actor );
587
588   application.SendNotification();
589   application.Render();
590
591   DALI_TEST_CHECK( eventProcessingFinished );
592
593   END_TEST;
594 }
595
596 int UtcDaliSceneEventProcessingFinishedN(void)
597 {
598   TestApplication application;
599   Dali::Integration::Scene scene = application.GetScene();
600
601   bool eventProcessingFinished = false;
602   EventProcessingFinishedFunctor functor( eventProcessingFinished );
603   scene.EventProcessingFinishedSignal().Connect( &application, functor );
604
605   Actor actor( Actor::New() );
606   scene.Add( actor );
607
608   // Do not complete event processing and confirm the signal has not been emitted.
609   DALI_TEST_CHECK( !eventProcessingFinished );
610
611   END_TEST;
612 }
613
614 int UtcDaliSceneSignalKeyEventP(void)
615 {
616   TestApplication application;
617   Dali::Integration::Scene scene = application.GetScene();
618
619   KeyEventSignalData data;
620   KeyEventReceivedFunctor functor( data );
621   scene.KeyEventSignal().Connect( &application, functor );
622
623   Integration::KeyEvent event( "i", "", "i", 0, 0, 0, Integration::KeyEvent::Down, "i", DEFAULT_DEVICE_NAME, Device::Class::NONE, Device::Subclass::NONE );
624   application.ProcessEvent( event );
625
626   DALI_TEST_EQUALS( true, data.functorCalled, TEST_LOCATION );
627   DALI_TEST_CHECK( event.keyModifier == data.receivedKeyEvent.keyModifier );
628   DALI_TEST_CHECK( event.keyName == data.receivedKeyEvent.keyPressedName );
629   DALI_TEST_CHECK( event.keyString == data.receivedKeyEvent.keyPressed );
630   DALI_TEST_CHECK( event.state == static_cast<Integration::KeyEvent::State>( data.receivedKeyEvent.state ) );
631
632   data.Reset();
633
634   Integration::KeyEvent event2( "i", "", "i", 0, 0, 0, Integration::KeyEvent::Up, "i", DEFAULT_DEVICE_NAME, Device::Class::NONE, Device::Subclass::NONE );
635   application.ProcessEvent( event2 );
636
637   DALI_TEST_EQUALS( true, data.functorCalled, TEST_LOCATION );
638   DALI_TEST_CHECK( event2.keyModifier == data.receivedKeyEvent.keyModifier );
639   DALI_TEST_CHECK( event2.keyName == data.receivedKeyEvent.keyPressedName );
640   DALI_TEST_CHECK( event2.keyString == data.receivedKeyEvent.keyPressed );
641   DALI_TEST_CHECK( event2.state == static_cast<Integration::KeyEvent::State>( data.receivedKeyEvent.state ) );
642
643   data.Reset();
644
645   Integration::KeyEvent event3( "a", "", "a", 0, 0, 0, Integration::KeyEvent::Down, "a", DEFAULT_DEVICE_NAME, Device::Class::NONE, Device::Subclass::NONE );
646   application.ProcessEvent( event3 );
647
648   DALI_TEST_EQUALS( true, data.functorCalled, TEST_LOCATION );
649   DALI_TEST_CHECK( event3.keyModifier == data.receivedKeyEvent.keyModifier );
650   DALI_TEST_CHECK( event3.keyName == data.receivedKeyEvent.keyPressedName );
651   DALI_TEST_CHECK( event3.keyString == data.receivedKeyEvent.keyPressed );
652   DALI_TEST_CHECK( event3.state == static_cast<Integration::KeyEvent::State>( data.receivedKeyEvent.state ) );
653
654   data.Reset();
655
656   Integration::KeyEvent event4( "a", "", "a", 0, 0, 0, Integration::KeyEvent::Up, "a", DEFAULT_DEVICE_NAME, Device::Class::NONE, Device::Subclass::NONE );
657   application.ProcessEvent( event4 );
658
659   DALI_TEST_EQUALS( true, data.functorCalled, TEST_LOCATION );
660   DALI_TEST_CHECK( event4.keyModifier == data.receivedKeyEvent.keyModifier );
661   DALI_TEST_CHECK( event4.keyName == data.receivedKeyEvent.keyPressedName );
662   DALI_TEST_CHECK( event4.keyString == data.receivedKeyEvent.keyPressed );
663   DALI_TEST_CHECK( event4.state == static_cast<Integration::KeyEvent::State>( data.receivedKeyEvent.state ) );
664   END_TEST;
665 }
666
667 int UtcDaliSceneSignalKeyEventN(void)
668 {
669   TestApplication application;
670   Dali::Integration::Scene scene = application.GetScene();
671
672   KeyEventSignalData data;
673   KeyEventReceivedFunctor functor( data );
674   scene.KeyEventSignal().Connect( &application, functor );
675
676   // Check that a non-pressed key events data is not modified.
677   DALI_TEST_EQUALS( false, data.functorCalled, TEST_LOCATION );
678
679   END_TEST;
680 }
681
682 int UtcDaliSceneTouchSignalP(void)
683 {
684   TestApplication application;
685   Dali::Integration::Scene scene = application.GetScene();
686
687   TouchedSignalData data;
688   TouchFunctor functor( data );
689   scene.TouchSignal().Connect( &application, functor );
690
691   // Render and notify.
692   application.SendNotification();
693   application.Render();
694
695   // Basic test: No actors, single touch (down then up).
696   {
697     GenerateTouch( application, PointState::DOWN, Vector2( 10.0f, 10.0f ) );
698
699     DALI_TEST_EQUALS( true, data.functorCalled, TEST_LOCATION );
700     DALI_TEST_CHECK( data.receivedTouchData.GetPointCount() != 0u );
701     DALI_TEST_CHECK( !data.receivedTouchData.GetHitActor(0) );
702     data.Reset();
703
704     GenerateTouch( application, PointState::UP, Vector2( 10.0f, 10.0f ) );
705
706     DALI_TEST_EQUALS( true, data.functorCalled, TEST_LOCATION );
707     DALI_TEST_CHECK( data.receivedTouchData.GetPointCount() != 0u );
708     DALI_TEST_CHECK( !data.receivedTouchData.GetHitActor(0) );
709     data.Reset();
710   }
711
712   // Add an actor to the scene.
713   Actor actor = Actor::New();
714   actor.SetSize( 100.0f, 100.0f );
715   actor.SetAnchorPoint( AnchorPoint::TOP_LEFT );
716   actor.SetParentOrigin( ParentOrigin::TOP_LEFT );
717   actor.TouchedSignal().Connect( &DummyTouchCallback );
718   scene.Add( actor );
719
720   // Render and notify.
721   application.SendNotification();
722   application.Render();
723
724   // Actor on scene, single touch, down in actor, motion, then up outside actor.
725   {
726     GenerateTouch( application, PointState::DOWN, Vector2( 10.0f, 10.0f ) );
727
728     DALI_TEST_EQUALS( true, data.functorCalled, TEST_LOCATION );
729     DALI_TEST_CHECK( data.receivedTouchData.GetPointCount() != 0u );
730     DALI_TEST_CHECK( data.receivedTouchData.GetHitActor(0) == actor );
731     data.Reset();
732
733     GenerateTouch( application, PointState::MOTION, Vector2( 150.0f, 10.0f ) ); // Some motion
734
735     DALI_TEST_EQUALS( false, data.functorCalled, TEST_LOCATION );
736     data.Reset();
737
738     GenerateTouch( application, PointState::UP, Vector2( 150.0f, 10.0f ) ); // Some motion
739
740     DALI_TEST_EQUALS( true, data.functorCalled, TEST_LOCATION );
741     DALI_TEST_CHECK( data.receivedTouchData.GetPointCount() != 0u );
742     DALI_TEST_CHECK( !data.receivedTouchData.GetHitActor(0) );
743     data.Reset();
744   }
745
746   // Multiple touch. Should only receive a touch on first down and last up.
747   {
748     Integration::TouchEvent touchEvent;
749     Integration::Point point;
750
751     // 1st point
752     point.SetState( PointState::DOWN );
753     point.SetScreenPosition( Vector2( 10.0f, 10.0f ) );
754     touchEvent.points.push_back( point );
755     application.ProcessEvent( touchEvent );
756     DALI_TEST_EQUALS( true, data.functorCalled, TEST_LOCATION );
757     DALI_TEST_EQUALS( data.receivedTouchData.GetPointCount(), 1u, TEST_LOCATION );
758     data.Reset();
759
760     // 2nd point
761     touchEvent.points[0].SetState( PointState::STATIONARY );
762     point.SetDeviceId( 1 );
763     point.SetScreenPosition( Vector2( 50.0f, 50.0f ) );
764     touchEvent.points.push_back( point );
765     application.ProcessEvent( touchEvent );
766     DALI_TEST_EQUALS( false, data.functorCalled, TEST_LOCATION );
767     data.Reset();
768
769     // Primary point is up
770     touchEvent.points[0].SetState( PointState::UP );
771     touchEvent.points[1].SetState( PointState::STATIONARY );
772     application.ProcessEvent( touchEvent );
773     DALI_TEST_EQUALS( false, data.functorCalled, TEST_LOCATION );
774     data.Reset();
775
776     // Remove 1st point now, 2nd point is now in motion
777     touchEvent.points.erase( touchEvent.points.begin() );
778     touchEvent.points[0].SetState( PointState::MOTION );
779     touchEvent.points[0].SetScreenPosition( Vector2( 150.0f, 50.0f ) );
780     application.ProcessEvent( touchEvent );
781     DALI_TEST_EQUALS( false, data.functorCalled, TEST_LOCATION );
782     data.Reset();
783
784     // Final point Up
785     touchEvent.points[0].SetState( PointState::UP );
786     application.ProcessEvent( touchEvent );
787     DALI_TEST_EQUALS( true, data.functorCalled, TEST_LOCATION );
788     DALI_TEST_EQUALS( data.receivedTouchData.GetPointCount(), 1u, TEST_LOCATION );
789     data.Reset();
790   }
791   END_TEST;
792 }
793
794 int UtcDaliSceneTouchSignalN(void)
795 {
796   TestApplication application;
797   Dali::Integration::Scene scene = application.GetScene();
798
799   TouchedSignalData data;
800   TouchFunctor functor( data );
801   scene.TouchSignal().Connect( &application, functor );
802
803   // Render and notify.
804   application.SendNotification();
805   application.Render();
806
807   // Confirm functor not called before there has been any touch event.
808   DALI_TEST_EQUALS( false, data.functorCalled, TEST_LOCATION );
809
810   // No actors, single touch, down, motion then up.
811   {
812     GenerateTouch( application, PointState::DOWN, Vector2( 10.0f, 10.0f ) );
813
814     DALI_TEST_EQUALS( true, data.functorCalled, TEST_LOCATION );
815     DALI_TEST_CHECK( data.receivedTouchData.GetPointCount() != 0u );
816     DALI_TEST_CHECK( !data.receivedTouchData.GetHitActor(0));
817
818     data.Reset();
819
820     // Confirm there is no signal when the touchpoint is only moved.
821     GenerateTouch( application, PointState::MOTION, Vector2( 1200.0f, 10.0f ) ); // Some motion
822
823     DALI_TEST_EQUALS( false, data.functorCalled, TEST_LOCATION );
824     data.Reset();
825
826     // Confirm a following up event generates a signal.
827     GenerateTouch( application, PointState::UP, Vector2( 1200.0f, 10.0f ) );
828
829     DALI_TEST_EQUALS( true, data.functorCalled, TEST_LOCATION );
830     DALI_TEST_CHECK( data.receivedTouchData.GetPointCount() != 0u );
831     DALI_TEST_CHECK( !data.receivedTouchData.GetHitActor(0));
832     data.Reset();
833   }
834
835   // Add an actor to the scene.
836   Actor actor = Actor::New();
837   actor.SetSize( 100.0f, 100.0f );
838   actor.SetAnchorPoint( AnchorPoint::TOP_LEFT );
839   actor.SetParentOrigin( ParentOrigin::TOP_LEFT );
840   actor.TouchedSignal().Connect( &DummyTouchCallback );
841   scene.Add( actor );
842
843   // Render and notify.
844   application.SendNotification();
845   application.Render();
846
847   // Actor on scene. Interrupted before down and interrupted after down.
848   {
849     GenerateTouch( application, PointState::INTERRUPTED, Vector2( 10.0f, 10.0f ) );
850
851     DALI_TEST_EQUALS( true, data.functorCalled, TEST_LOCATION );
852     DALI_TEST_CHECK( data.receivedTouchData.GetPointCount() != 0u );
853     DALI_TEST_CHECK( !data.receivedTouchData.GetHitActor(0) );
854     DALI_TEST_CHECK( data.receivedTouchData.GetState(0) == PointState::INTERRUPTED );
855     data.Reset();
856
857     GenerateTouch( application, PointState::DOWN, Vector2( 10.0f, 10.0f ) );
858
859     DALI_TEST_EQUALS( true, data.functorCalled, TEST_LOCATION );
860     DALI_TEST_CHECK( data.receivedTouchData.GetPointCount() != 0u );
861     DALI_TEST_CHECK( data.receivedTouchData.GetHitActor(0) == actor );
862     DALI_TEST_CHECK( data.receivedTouchData.GetState(0) == PointState::DOWN );
863     data.Reset();
864
865     GenerateTouch( application, PointState::INTERRUPTED, Vector2( 10.0f, 10.0f ) );
866
867     DALI_TEST_EQUALS( true, data.functorCalled, TEST_LOCATION );
868     DALI_TEST_CHECK( data.receivedTouchData.GetPointCount() != 0u );
869     DALI_TEST_CHECK( !data.receivedTouchData.GetHitActor(0) );
870     DALI_TEST_CHECK( data.receivedTouchData.GetState(0) == PointState::INTERRUPTED );
871
872     DALI_TEST_EQUALS( data.receivedTouchData.GetPointCount(), 1u, TEST_LOCATION );
873
874     // Check that getting info about a non-existent point returns an empty handle
875     Actor actor = data.receivedTouchData.GetHitActor( 1 );
876     DALI_TEST_CHECK( !actor );
877
878     data.Reset();
879   }
880
881   END_TEST;
882 }
883
884 int UtcDaliSceneSignalWheelEventP(void)
885 {
886   TestApplication application;
887   Dali::Integration::Scene scene = application.GetScene();
888
889   WheelEventSignalData data;
890   WheelEventReceivedFunctor functor( data );
891   scene.WheelEventSignal().Connect( &application, functor );
892
893   Integration::WheelEvent event( Integration::WheelEvent::CUSTOM_WHEEL, 0, 0u, Vector2( 0.0f, 0.0f ), 1, 1000u );
894   application.ProcessEvent( event );
895
896   DALI_TEST_EQUALS( true, data.functorCalled, TEST_LOCATION );
897   DALI_TEST_CHECK( static_cast< WheelEvent::Type >(event.type) == data.receivedWheelEvent.type );
898   DALI_TEST_CHECK( event.direction == data.receivedWheelEvent.direction );
899   DALI_TEST_CHECK( event.modifiers == data.receivedWheelEvent.modifiers );
900   DALI_TEST_CHECK( event.point == data.receivedWheelEvent.point );
901   DALI_TEST_CHECK( event.z == data.receivedWheelEvent.z );
902   DALI_TEST_CHECK( event.timeStamp == data.receivedWheelEvent.timeStamp );
903
904   data.Reset();
905
906   Integration::WheelEvent event2( Integration::WheelEvent::CUSTOM_WHEEL, 0, 0u, Vector2( 0.0f, 0.0f ), -1, 1000u );
907   application.ProcessEvent( event2 );
908
909   DALI_TEST_EQUALS( true, data.functorCalled, TEST_LOCATION );
910   DALI_TEST_CHECK( static_cast< WheelEvent::Type >(event2.type) == data.receivedWheelEvent.type );
911   DALI_TEST_CHECK( event2.direction == data.receivedWheelEvent.direction );
912   DALI_TEST_CHECK( event2.modifiers == data.receivedWheelEvent.modifiers );
913   DALI_TEST_CHECK( event2.point == data.receivedWheelEvent.point );
914   DALI_TEST_CHECK( event2.z == data.receivedWheelEvent.z );
915   DALI_TEST_CHECK( event2.timeStamp == data.receivedWheelEvent.timeStamp );
916   END_TEST;
917 }
918
919 int UtcDaliSceneEnsureEmptySceneCleared(void)
920 {
921   tet_infoline( "Ensure we clear the newly added window" );
922
923   TestApplication application;
924
925   auto& glAbstraction = application.GetGlAbstraction();
926   auto clearCountBefore = glAbstraction.GetClearCountCalled();
927
928   application.SendNotification();
929   application.Render();
930
931   // No actor, no rendering at all
932   DALI_TEST_EQUALS( glAbstraction.GetClearCountCalled(), clearCountBefore, TEST_LOCATION );
933   DALI_TEST_EQUALS( glAbstraction.GetLastClearColor(), Color::TRANSPARENT, TEST_LOCATION );
934
935   // Need to create a renderable as we don't start rendering until we have at least one
936   // We don't need to add this to any scene
937   auto actor = CreateRenderableActor();
938
939   application.SendNotification();
940   application.Render();
941
942   // Default background color
943   DALI_TEST_EQUALS( glAbstraction.GetClearCountCalled(), clearCountBefore + 1, TEST_LOCATION );
944   DALI_TEST_EQUALS( glAbstraction.GetLastClearColor(), Color::BLACK, TEST_LOCATION );
945
946   // Create a new scene and set the background colors of both the new and the main scenes
947   auto defaultScene = application.GetScene();
948   defaultScene.SetBackgroundColor( Color::WHITE );
949
950   application.SendNotification();
951   application.Render();
952
953   DALI_TEST_EQUALS( glAbstraction.GetClearCountCalled(), clearCountBefore + 2, TEST_LOCATION );
954   DALI_TEST_EQUALS( glAbstraction.GetLastClearColor(), Color::WHITE, TEST_LOCATION );
955
956   TestRenderSurface surface( PositionSize( 0.0f, 0.0f, 480.0f, 800.0f ) );
957   auto newScene = Integration::Scene::New( surface );
958   newScene.SetBackgroundColor( Color::RED );
959
960   application.SendNotification();
961   application.Render();
962
963   // + 2 clear for 2 scenes
964   DALI_TEST_EQUALS( glAbstraction.GetClearCountCalled(), clearCountBefore + 4, TEST_LOCATION );
965   DALI_TEST_EQUALS( glAbstraction.GetLastClearColor(), Color::RED, TEST_LOCATION );
966
967   // Add the actor to the main scene
968   defaultScene.Add( actor );
969
970   application.SendNotification();
971   application.Render();
972
973   // + 2 clear for 2 scenes
974   DALI_TEST_EQUALS( glAbstraction.GetClearCountCalled(), clearCountBefore + 6, TEST_LOCATION );
975   DALI_TEST_EQUALS( glAbstraction.GetLastClearColor(), Color::RED, TEST_LOCATION );
976
977   // Add another scene and set its background color, ensure we clear it to the appropriate color
978   // + 3 clear for 3 scenes
979   TestRenderSurface surface2( PositionSize( 0.0f, 0.0f, 480.0f, 800.0f ) );
980   auto thirdScene = Integration::Scene::New( surface2 );
981   thirdScene.SetBackgroundColor( Color::BLUE );
982
983   application.SendNotification();
984   application.Render();
985
986   DALI_TEST_EQUALS( glAbstraction.GetClearCountCalled(), clearCountBefore + 9, TEST_LOCATION );
987   DALI_TEST_EQUALS( glAbstraction.GetLastClearColor(), Color::BLUE, TEST_LOCATION );
988
989   END_TEST;
990 }
991
992 int UtcDaliSceneSurfaceResizedDefaultScene(void)
993 {
994   tet_infoline( "Ensure resizing of the surface is handled properly" );
995
996   TestApplication application;
997
998   auto defaultScene = application.GetScene();
999   Integration::RenderSurface* defaultSurface = defaultScene.GetSurface();
1000   DALI_TEST_CHECK( defaultSurface );
1001
1002   // Ensure stage size matches the surface size
1003   auto stage = Stage::GetCurrent();
1004   DALI_TEST_EQUALS( stage.GetSize(), Vector2( defaultSurface->GetPositionSize().width, defaultSurface->GetPositionSize().height ), TEST_LOCATION );
1005
1006   // Resize the surface and inform the scene accordingly
1007   Vector2 newSize( 1000.0f, 2000.0f );
1008   DALI_TEST_CHECK( stage.GetSize() != newSize );
1009   defaultSurface->MoveResize( PositionSize( 0, 0, newSize.width, newSize.height ) );
1010   defaultScene.SurfaceResized();
1011
1012   DALI_TEST_EQUALS( stage.GetSize(), newSize, TEST_LOCATION );
1013   DALI_TEST_EQUALS( defaultScene.GetSize(), newSize, TEST_LOCATION );
1014
1015   END_TEST;
1016 }
1017
1018 int UtcDaliSceneSurfaceResizedDefaultSceneViewport(void)
1019 {
1020   tet_infoline( "Ensure resizing of the surface & viewport is handled properly" );
1021
1022   TestApplication application;
1023   TestGlAbstraction& glAbstraction = application.GetGlAbstraction();
1024   TraceCallStack& callStack = glAbstraction.GetViewportTrace();
1025   glAbstraction.EnableViewportCallTrace( true );
1026
1027   // Initial scene setup
1028   Geometry geometry = CreateQuadGeometry();
1029   Shader shader = CreateShader();
1030   Renderer renderer = Renderer::New( geometry, shader );
1031
1032   Actor actor = Actor::New();
1033   actor.AddRenderer(renderer);
1034   actor.SetSize(400, 400);
1035   Stage::GetCurrent().Add(actor);
1036
1037   // Render before resizing surface
1038   application.SendNotification();
1039   application.Render(0);
1040   glAbstraction.ResetViewportCallStack();
1041
1042   auto defaultScene = application.GetScene();
1043   Integration::RenderSurface* defaultSurface = defaultScene.GetSurface();
1044   DALI_TEST_CHECK( defaultSurface );
1045
1046   // Ensure stage size matches the surface size
1047   auto stage = Stage::GetCurrent();
1048   DALI_TEST_EQUALS( stage.GetSize(), Vector2( defaultSurface->GetPositionSize().width, defaultSurface->GetPositionSize().height ), TEST_LOCATION );
1049
1050   // Resize the surface and inform the scene accordingly
1051   Vector2 newSize( 1000.0f, 2000.0f );
1052   std::string viewportParams( "0, 0, 1000, 2000" ); // to match newSize
1053   DALI_TEST_CHECK( stage.GetSize() != newSize );
1054   defaultSurface->MoveResize( PositionSize( 0, 0, newSize.width, newSize.height ) );
1055   defaultScene.SurfaceResized();
1056
1057   DALI_TEST_EQUALS( stage.GetSize(), newSize, TEST_LOCATION );
1058   DALI_TEST_EQUALS( defaultScene.GetSize(), newSize, TEST_LOCATION );
1059
1060   // Render after resizing surface
1061   application.SendNotification();
1062   application.Render(0);
1063
1064   // Check that the viewport is handled properly
1065   DALI_TEST_CHECK( callStack.FindMethodAndGetParameters("Viewport", viewportParams ) );
1066
1067   END_TEST;
1068 }
1069
1070 int UtcDaliSceneSurfaceResizedMultipleRenderTasks(void)
1071 {
1072   tet_infoline( "Ensure resizing of the surface & viewport is handled properly" );
1073
1074   TestApplication application;
1075   TestGlAbstraction& glAbstraction = application.GetGlAbstraction();
1076   TraceCallStack& callStack = glAbstraction.GetViewportTrace();
1077   glAbstraction.EnableViewportCallTrace( true );
1078
1079   // Initial scene setup
1080   auto stage = Stage::GetCurrent();
1081
1082   Geometry geometry = CreateQuadGeometry();
1083   Shader shader = CreateShader();
1084   Renderer renderer = Renderer::New( geometry, shader );
1085
1086   Actor actor = Actor::New();
1087   actor.AddRenderer(renderer);
1088   int testWidth = 400;
1089   int testHeight = 400;
1090   actor.SetSize(testWidth, testHeight);
1091   stage.Add(actor);
1092
1093   CameraActor offscreenCameraActor = CameraActor::New( Size( testWidth, testHeight ) );
1094   Stage::GetCurrent().Add( offscreenCameraActor );
1095
1096   FrameBuffer newFrameBuffer = FrameBuffer::New( testWidth, testHeight, FrameBuffer::Attachment::NONE );
1097
1098   RenderTask newTask = stage.GetRenderTaskList().CreateTask();
1099   newTask.SetCameraActor( offscreenCameraActor );
1100   newTask.SetSourceActor( actor );
1101   newTask.SetFrameBuffer( newFrameBuffer );
1102   newTask.SetViewportPosition( Vector2(0, 0) );
1103   newTask.SetViewportSize( Vector2(testWidth, testHeight) );
1104
1105   // Render before resizing surface
1106   application.SendNotification();
1107   application.Render(0);
1108   glAbstraction.ResetViewportCallStack();
1109
1110   Rect<int32_t> initialViewport = newTask.GetViewport();
1111   int initialWidth = initialViewport.width;
1112   int initialHeight = initialViewport.height;
1113   DALI_TEST_EQUALS( initialWidth, testWidth, TEST_LOCATION );
1114   DALI_TEST_EQUALS( initialHeight, testHeight, TEST_LOCATION );
1115
1116   auto defaultScene = application.GetScene();
1117   Integration::RenderSurface* defaultSurface = defaultScene.GetSurface();
1118   DALI_TEST_CHECK( defaultSurface );
1119
1120   // Ensure stage size matches the surface size
1121   DALI_TEST_EQUALS( stage.GetSize(), Vector2( defaultSurface->GetPositionSize().width, defaultSurface->GetPositionSize().height ), TEST_LOCATION );
1122
1123   // Resize the surface and inform the scene accordingly
1124   Vector2 newSize( 800.0f, 480.0f );
1125   std::string viewportParams( "0, 0, 800, 480" ); // to match newSize
1126   DALI_TEST_CHECK( stage.GetSize() != newSize );
1127   defaultSurface->MoveResize( PositionSize( 0, 0, newSize.width, newSize.height ) );
1128   defaultScene.SurfaceResized();
1129
1130   DALI_TEST_EQUALS( stage.GetSize(), newSize, TEST_LOCATION );
1131   DALI_TEST_EQUALS( defaultScene.GetSize(), newSize, TEST_LOCATION );
1132
1133   // Render after resizing surface
1134   application.SendNotification();
1135   application.Render(0);
1136
1137   // Check that the viewport is handled properly
1138   DALI_TEST_CHECK( callStack.FindMethodAndGetParameters("Viewport", viewportParams ) );
1139
1140   // Second render-task should not be affected
1141   Rect<int32_t> viewport = newTask.GetViewport();
1142   int width = viewport.width;
1143   int height = viewport.height;
1144   DALI_TEST_EQUALS( width, testWidth, TEST_LOCATION );
1145   DALI_TEST_EQUALS( height, testHeight, TEST_LOCATION );
1146
1147   END_TEST;
1148 }
1149
1150 int UtcDaliSceneSurfaceResizedAdditionalScene(void)
1151 {
1152   tet_infoline( "Ensure resizing of the surface is handled properly on additional scenes" );
1153
1154   TestApplication application;
1155   Vector2 originalSurfaceSize( 500.0f, 1000.0f );
1156
1157   TestRenderSurface surface( PositionSize( 0.0f, 0.0f, originalSurfaceSize.width, originalSurfaceSize.height ) );
1158   auto scene = Integration::Scene::New( surface );
1159
1160   // Ensure stage size does NOT match the surface size
1161   auto stage = Stage::GetCurrent();
1162   const auto stageSize = stage.GetSize();
1163   DALI_TEST_CHECK( stageSize != originalSurfaceSize );
1164   DALI_TEST_EQUALS( originalSurfaceSize, scene.GetSize(), TEST_LOCATION );
1165
1166   // Resize the surface and inform the scene accordingly
1167   Vector2 newSize( 1000.0f, 2000.0f );
1168   DALI_TEST_CHECK( stage.GetSize() != newSize );
1169   surface.MoveResize( PositionSize( 0, 0, newSize.width, newSize.height ) );
1170   scene.SurfaceResized();
1171
1172   // Ensure the stage hasn't been resized
1173   DALI_TEST_EQUALS( stage.GetSize(), stageSize, TEST_LOCATION );
1174   DALI_TEST_EQUALS( scene.GetSize(), newSize, TEST_LOCATION );
1175
1176   END_TEST;
1177 }
1178
1179 int UtcDaliSceneSetSurface(void)
1180 {
1181   tet_infoline( "Scene::SetSurface test" );
1182
1183   TestApplication application;
1184
1185   // Create a scene with a surface and ensure the size and surface is set correctly on the scene
1186   Vector2 surfaceSize( 480.0f, 800.0f );
1187   TestRenderSurface surface( PositionSize( 0.0f, 0.0f, surfaceSize.width, surfaceSize.height ) );
1188   auto scene = Integration::Scene::New( surface );
1189   DALI_TEST_EQUALS( scene.GetSize(), surfaceSize, TEST_LOCATION );
1190   DALI_TEST_CHECK( scene.GetSurface() == &surface );
1191
1192   // Create a new surface and set that on the scene
1193   Vector2 newSurfaceSize( 1000.0f, 1000.0f );
1194   TestRenderSurface newSurface( PositionSize( 0.0f, 0.0f, newSurfaceSize.width, newSurfaceSize.height ) );
1195   scene.SetSurface( newSurface );
1196   DALI_TEST_EQUALS( scene.GetSize(), newSurfaceSize, TEST_LOCATION );
1197   DALI_TEST_CHECK( scene.GetSurface() == &newSurface );
1198
1199   // Ensure setting the same surface again doesn't have any side effects
1200   scene.SetSurface( newSurface );
1201   DALI_TEST_EQUALS( scene.GetSize(), newSurfaceSize, TEST_LOCATION );
1202   DALI_TEST_CHECK( scene.GetSurface() == &newSurface );
1203
1204   END_TEST;
1205 }
1206
1207 int UtcDaliSceneKeyEventGeneratedSignalP(void)
1208 {
1209   TestApplication application;
1210   Dali::Integration::Scene scene = application.GetScene();
1211
1212   KeyEventGeneratedSignalData data;
1213   KeyEventGeneratedReceivedFunctor functor( data );
1214   scene.KeyEventGeneratedSignal().Connect( &application, functor );
1215
1216   Integration::KeyEvent event( "a", "", "a", 0, 0, 0, Integration::KeyEvent::Up, "a", DEFAULT_DEVICE_NAME, Device::Class::NONE, Device::Subclass::NONE );
1217   application.ProcessEvent( event );
1218
1219   DALI_TEST_EQUALS( true, data.functorCalled, TEST_LOCATION );
1220   DALI_TEST_CHECK( event.keyModifier == data.receivedKeyEvent.keyModifier );
1221   DALI_TEST_CHECK( event.keyName == data.receivedKeyEvent.keyPressedName );
1222   DALI_TEST_CHECK( event.keyString == data.receivedKeyEvent.keyPressed );
1223   DALI_TEST_CHECK( event.state == static_cast<Integration::KeyEvent::State>( data.receivedKeyEvent.state ) );
1224
1225   data.Reset();
1226
1227   Integration::KeyEvent event2( "i", "", "i", 0, 0, 0, Integration::KeyEvent::Up, "i", DEFAULT_DEVICE_NAME, Device::Class::NONE, Device::Subclass::NONE );
1228   application.ProcessEvent( event2 );
1229
1230   DALI_TEST_EQUALS( true, data.functorCalled, TEST_LOCATION );
1231   DALI_TEST_CHECK( event2.keyModifier == data.receivedKeyEvent.keyModifier );
1232   DALI_TEST_CHECK( event2.keyName == data.receivedKeyEvent.keyPressedName );
1233   DALI_TEST_CHECK( event2.keyString == data.receivedKeyEvent.keyPressed );
1234   DALI_TEST_CHECK( event2.state == static_cast<Integration::KeyEvent::State>( data.receivedKeyEvent.state ) );
1235
1236   data.Reset();
1237
1238   Integration::KeyEvent event3( "a", "", "a", 0, 0, 0, Integration::KeyEvent::Down, "a", DEFAULT_DEVICE_NAME, Device::Class::NONE, Device::Subclass::NONE );
1239   application.ProcessEvent( event3 );
1240
1241   DALI_TEST_EQUALS( true, data.functorCalled, TEST_LOCATION );
1242   DALI_TEST_CHECK( event3.keyModifier == data.receivedKeyEvent.keyModifier );
1243   DALI_TEST_CHECK( event3.keyName == data.receivedKeyEvent.keyPressedName );
1244   DALI_TEST_CHECK( event3.keyString == data.receivedKeyEvent.keyPressed );
1245   DALI_TEST_CHECK( event3.state == static_cast<Integration::KeyEvent::State>( data.receivedKeyEvent.state ) );
1246
1247   data.Reset();
1248
1249   Integration::KeyEvent event4( "a", "", "a", 0, 0, 0, Integration::KeyEvent::Up, "a", DEFAULT_DEVICE_NAME, Device::Class::NONE, Device::Subclass::NONE );
1250   application.ProcessEvent( event4 );
1251
1252   DALI_TEST_EQUALS( true, data.functorCalled, TEST_LOCATION );
1253   DALI_TEST_CHECK( event4.keyModifier == data.receivedKeyEvent.keyModifier );
1254   DALI_TEST_CHECK( event4.keyName == data.receivedKeyEvent.keyPressedName );
1255   DALI_TEST_CHECK( event4.keyString == data.receivedKeyEvent.keyPressed );
1256   DALI_TEST_CHECK( event4.state == static_cast<Integration::KeyEvent::State>( data.receivedKeyEvent.state ) );
1257   END_TEST;
1258 }
1259
1260 int UtcDaliSceneEnsureReplacedSurfaceKeepsClearColor(void)
1261 {
1262   tet_infoline( "Ensure we keep background color when the scene surface is replaced " );
1263
1264   TestApplication application;
1265
1266   // Create a new scene and set the background color of the main scene
1267   auto defaultScene = application.GetScene();
1268   defaultScene.SetBackgroundColor( Color::BLUE );
1269
1270   // Need to create a renderable as we don't start rendering until we have at least one
1271   // We don't need to add this to any scene
1272   auto actor = CreateRenderableActor();
1273
1274   auto& glAbstraction = application.GetGlAbstraction();
1275   auto clearCountBefore = glAbstraction.GetClearCountCalled();
1276
1277   application.SendNotification();
1278   application.Render();
1279
1280   DALI_TEST_EQUALS( glAbstraction.GetClearCountCalled(), clearCountBefore + 1, TEST_LOCATION );
1281   DALI_TEST_EQUALS( glAbstraction.GetLastClearColor(), Color::BLUE, TEST_LOCATION );
1282
1283   TestRenderSurface surface( PositionSize( 0.0f, 0.0f, 480.0f, 800.0f ) );
1284   defaultScene.SetSurface( surface );
1285
1286   application.SendNotification();
1287   application.Render();
1288
1289   DALI_TEST_EQUALS( glAbstraction.GetClearCountCalled(), clearCountBefore + 2, TEST_LOCATION );
1290   DALI_TEST_EQUALS( glAbstraction.GetLastClearColor(), Color::BLUE, TEST_LOCATION );
1291
1292   // Check when the main render task viewport is set the clear color is clipped using scissors
1293   TraceCallStack& scissorTrace = glAbstraction.GetScissorTrace();
1294   TraceCallStack& enabledDisableTrace = glAbstraction.GetEnableDisableTrace();
1295   scissorTrace.Enable( true );
1296   enabledDisableTrace.Enable( true );
1297
1298   defaultScene.GetRenderTaskList().GetTask( 0 ).SetViewport( Viewport( 0.0f, 0.0f, 100.0f, 100.0f ) );
1299
1300   application.SendNotification();
1301   application.Render();
1302
1303   // Check scissor test was enabled.
1304   DALI_TEST_CHECK( enabledDisableTrace.FindMethodAndParams( "Enable", "3089" ) ); // 3089 = 0xC11 (GL_SCISSOR_TEST)
1305
1306   // Check the scissor was set, and the coordinates are correct.
1307   DALI_TEST_CHECK( scissorTrace.FindMethodAndParams( "Scissor", "0, 700, 100, 100" ) );
1308
1309   DALI_TEST_EQUALS( glAbstraction.GetClearCountCalled(), clearCountBefore + 3, TEST_LOCATION );
1310   DALI_TEST_EQUALS( glAbstraction.GetLastClearColor(), Color::BLUE, TEST_LOCATION );
1311
1312   scissorTrace.Enable( false );
1313   scissorTrace.Reset();
1314
1315   enabledDisableTrace.Enable( false );
1316   enabledDisableTrace.Reset();
1317
1318   END_TEST;
1319 }