Fix resource leaks in layouting.
[platform/core/uifw/dali-toolkit.git] / automated-tests / src / dali-toolkit / utc-Dali-LayoutingAnimation.cpp
index 2bf827a..9750070 100644 (file)
@@ -30,6 +30,7 @@
 #include <dali-toolkit/devel-api/layouting/layout-group-impl.h>
 
 #include <../custom-layout.h>
+#include <dummy-control.h>
 
 #include <layout-utils.h>
 
@@ -1797,3 +1798,72 @@ int UtcDaliLayouting_DefaultTransition01(void)
   END_TEST;
 }
 
+int UtcDaliLayouting_CheckResourceLeak01(void)
+{
+  ToolkitTestApplication application;
+  tet_infoline(" UtcDaliLayouting_CheckResourceLeak01 - Remove animating layout and add child to stage" );
+
+  Dali::Toolkit::Impl::DummyControl::constructorCount = 0;
+  Dali::Toolkit::Impl::DummyControl::destructorCount = 0;
+
+  Stage stage = Stage::GetCurrent();
+  auto container = Control::New();
+  auto linearLayout = LinearLayout::New();
+  linearLayout.SetAnimateLayout( true );
+
+  DevelControl::SetLayout( container, linearLayout );
+  container.SetName( "Container" );
+
+  stage.Add( container );
+
+  DummyControl control = DummyControl::New( true );
+  control.SetName( "DummyControl01" );
+  control.SetSize( 100, 100 );
+  container.Add( control );
+
+  control = DummyControl::New( true );
+  control.SetName( "DummyControl02" );
+  control.SetSize( 100, 100 );
+  container.Add( control );
+
+  linearLayout.SetAnimateLayout( true );
+
+  DALI_TEST_EQUALS( Dali::Toolkit::Impl::DummyControl::constructorCount, 2, TEST_LOCATION );
+  DALI_TEST_EQUALS( Dali::Toolkit::Impl::DummyControl::destructorCount, 0, TEST_LOCATION );
+
+  // Initial rendering done
+  application.SendNotification();
+  application.Render(static_cast<unsigned int>( 0.5f * 1000.0f ) + 1u /*just after the end of the animation*/ );
+
+  DALI_TEST_EQUALS( Dali::Toolkit::Impl::DummyControl::constructorCount, 2, TEST_LOCATION );
+  DALI_TEST_EQUALS( Dali::Toolkit::Impl::DummyControl::destructorCount, 0, TEST_LOCATION );
+
+  stage.Remove( container );
+  container.Reset();
+
+  application.SendNotification();
+  application.Render(static_cast<unsigned int>( 0.5f * 1000.0f ) + 1u /*just after the end of the animation*/ );
+
+  DALI_TEST_EQUALS( Dali::Toolkit::Impl::DummyControl::constructorCount, 2, TEST_LOCATION );
+  DALI_TEST_EQUALS( Dali::Toolkit::Impl::DummyControl::destructorCount, 1, TEST_LOCATION );
+
+  Stage::GetCurrent().Add( control );
+
+  application.SendNotification();
+  application.Render(static_cast<unsigned int>( 0.5f * 1000.0f ) + 1u /*just after the end of the animation*/ );
+
+  DALI_TEST_EQUALS( Dali::Toolkit::Impl::DummyControl::constructorCount, 2, TEST_LOCATION );
+  DALI_TEST_EQUALS( Dali::Toolkit::Impl::DummyControl::destructorCount, 1, TEST_LOCATION );
+
+  stage.Remove( control );
+  control.Reset();
+
+  application.SendNotification();
+  application.Render(static_cast<unsigned int>( 0.5f * 1000.0f ) + 1u /*just after the end of the animation*/ );
+
+  DALI_TEST_EQUALS( Dali::Toolkit::Impl::DummyControl::constructorCount, 2, TEST_LOCATION );
+  DALI_TEST_EQUALS( Dali::Toolkit::Impl::DummyControl::destructorCount, 2, TEST_LOCATION );
+
+  END_TEST;
+}
+