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