Delete the Scene when requested
[platform/core/uifw/dali-core.git] / automated-tests / src / dali / utc-Dali-Scene.cpp
index 4aedee0..21076e2 100644 (file)
@@ -341,6 +341,52 @@ int UtcDaliSceneGet(void)
   END_TEST;
 }
 
+int UtcDaliSceneDiscard(void)
+{
+  TestApplication application;
+  tet_infoline("Testing Dali::Scene::Discard");
+
+  // Create a new Scene
+  Dali::Integration::Scene scene = Dali::Integration::Scene::New( Vector2( 480.0f, 800.0f ) );
+  DALI_TEST_CHECK( scene );
+
+  // One reference of scene kept here and the other one kept in the Core
+  DALI_TEST_CHECK( scene.GetBaseObject().ReferenceCount() == 2 );
+
+  // Render and notify.
+  application.SendNotification();
+  application.Render(0);
+
+  // Keep the reference of the root layer handle so it will still be alive after the scene is deleted
+  Layer rootLayer = scene.GetRootLayer();
+  DALI_TEST_CHECK( rootLayer );
+  DALI_TEST_CHECK( rootLayer.GetBaseObject().ReferenceCount() == 2 );
+
+  // Request to discard the scene from the Core
+  scene.Discard();
+  DALI_TEST_CHECK( scene.GetBaseObject().ReferenceCount() == 1 );
+
+  // Reset the scene handle
+  scene.Reset();
+
+  // Render and notify.
+  application.SendNotification();
+  application.Render(0);
+
+  // At this point, the scene should have been automatically deleted
+  // To prove this, the ref count of the root layer handle should be decremented to 1
+  DALI_TEST_CHECK( rootLayer.GetBaseObject().ReferenceCount() == 1 );
+
+  // Delete the root layer handle
+  rootLayer.Reset();
+
+  // Render and notify.
+  application.SendNotification();
+  application.Render(0);
+
+  END_TEST;
+}
+
 int UtcDaliSceneEventProcessingFinishedP(void)
 {
   TestApplication application;