Remove Unused Retention policy
[platform/core/uifw/dali-core.git] / automated-tests / src / dali / utc-Dali-TextureSet.cpp
index 4811fe7..3daa753 100644 (file)
 #include <mesh-builder.h>
 
 using namespace Dali;
+
+namespace
+{
+
+enum SetSampler
+{
+  SET_SAMPLER,
+  DONT_SET_SAMPLER
+};
+
+Actor CreateActor( SetSampler setSamplerOption )
+{
+  Texture texture = Texture::New( TextureType::TEXTURE_2D, Pixel::RGBA8888, 64, 64 );
+
+  Shader shader = CreateShader();
+  TextureSet textureSet = CreateTextureSet();
+
+  Sampler sampler = Sampler::New();
+  sampler.SetFilterMode( FilterMode::NEAREST, FilterMode::NEAREST );
+  textureSet.SetTexture( 0u, texture );
+  if( setSamplerOption == SET_SAMPLER )
+  {
+    textureSet.SetSampler( 0u, sampler );
+  }
+
+  Geometry geometry = CreateQuadGeometry();
+  Renderer renderer = Renderer::New( geometry, shader );
+  renderer.SetTextures( textureSet );
+
+  Actor actor = Actor::New();
+  actor.AddRenderer(renderer);
+  actor.SetParentOrigin( ParentOrigin::CENTER );
+  actor.SetSize(400, 400);
+
+  return actor;
+}
+
+} // namespace
+
+
 void texture_set_test_startup(void)
 {
   test_return_value = TET_UNDEF;
@@ -108,20 +148,7 @@ int UtcDaliTextureSetTexture01(void)
 {
   TestApplication application;
 
-  Texture texture = Texture::New( TextureType::TEXTURE_2D, Pixel::RGBA8888, 64, 64 );
-
-  Shader shader = CreateShader();
-  TextureSet textureSet = CreateTextureSet();
-  textureSet.SetTexture( 0u, texture );
-
-  Geometry geometry = CreateQuadGeometry();
-  Renderer renderer = Renderer::New( geometry, shader );
-  renderer.SetTextures( textureSet );
-
-  Actor actor = Actor::New();
-  actor.AddRenderer(renderer);
-  actor.SetParentOrigin( ParentOrigin::CENTER );
-  actor.SetSize(400, 400);
+  Actor actor = CreateActor( DONT_SET_SAMPLER );
 
   Stage::GetCurrent().Add( actor );
 
@@ -151,26 +178,42 @@ int UtcDaliTextureSetTexture02(void)
 {
   TestApplication application;
 
-  Texture texture = Texture::New( TextureType::TEXTURE_2D, Pixel::RGBA8888, 64, 64 );
+  Actor actor = CreateActor(SET_SAMPLER);
 
-  Shader shader = CreateShader();
-  TextureSet textureSet = CreateTextureSet();
+  Stage::GetCurrent().Add( actor );
 
-  Sampler sampler = Sampler::New();
-  sampler.SetFilterMode( FilterMode::NEAREST, FilterMode::NEAREST );
-  textureSet.SetTexture( 0u, texture );
-  textureSet.SetSampler( 0u, sampler );
+  TestGlAbstraction& gl = application.GetGlAbstraction();
 
-  Geometry geometry = CreateQuadGeometry();
-  Renderer renderer = Renderer::New( geometry, shader );
-  renderer.SetTextures( textureSet );
+  TraceCallStack& texParameterTrace = gl.GetTexParameterTrace();
+  texParameterTrace.Reset();
+  texParameterTrace.Enable( true );
+  application.SendNotification();
+  application.Render();
 
-  Actor actor = Actor::New();
-  actor.AddRenderer(renderer);
-  actor.SetParentOrigin( ParentOrigin::CENTER );
-  actor.SetSize(400, 400);
+  int textureUnit=-1;
+  DALI_TEST_CHECK( gl.GetUniformValue<int>( "sTexture", textureUnit ) );
+  DALI_TEST_EQUALS( textureUnit, 0, TEST_LOCATION );
 
-  Stage::GetCurrent().Add( actor );
+  texParameterTrace.Enable( false );
+
+  // Verify gl state
+  // There are four calls to TexParameteri when the texture is first created
+  // Texture minification and magnification filters are now different than default so
+  //there should have been two extra TexParameteri calls to set the new filter mode
+  DALI_TEST_EQUALS( texParameterTrace.CountMethod( "TexParameteri" ), 6, TEST_LOCATION);
+
+  END_TEST;
+}
+
+int UtcDaliTextureSetMultiple(void)
+{
+  TestApplication application;
+
+  Actor actor1 = CreateActor(SET_SAMPLER);
+  Actor actor2 = CreateActor(SET_SAMPLER);
+
+  Stage::GetCurrent().Add( actor1 );
+  Stage::GetCurrent().Add( actor2 );
 
   TestGlAbstraction& gl = application.GetGlAbstraction();
 
@@ -187,13 +230,14 @@ int UtcDaliTextureSetTexture02(void)
   texParameterTrace.Enable( false );
 
   // Verify gl state
-  // There are four calls to TexParameteri when the texture is first created
+  // For each actor there are four calls to TexParameteri when the texture is first created
   // Texture minification and magnification filters are now different than default so
   //there should have been two extra TexParameteri calls to set the new filter mode
-  DALI_TEST_EQUALS( texParameterTrace.CountMethod( "TexParameteri" ), 6, TEST_LOCATION);
+  DALI_TEST_EQUALS( texParameterTrace.CountMethod( "TexParameteri" ), 2 * 6, TEST_LOCATION);
 
   END_TEST;
 }
+
 int UtcDaliTextureSetSetSampler(void)
 {
   TestApplication application;
@@ -254,6 +298,20 @@ int UtcDaliTextureSetSetSampler(void)
   END_TEST;
 }
 
+int UtcDaliTextureSetGetImage(void)
+{
+  TestApplication application;
+
+  TextureSet textureSet = CreateTextureSet();
+  Image imageSource = BufferImage::New( 64, 64, Pixel::RGBA8888 );
+  TextureSetImage( textureSet, 0u, imageSource );
+
+  Image imageReturn = TextureGetImage( textureSet, 0u );
+  DALI_TEST_EQUALS( imageSource, imageReturn, TEST_LOCATION );
+
+  END_TEST;
+}
+
 int UtcDaliTextureSetGetTexture(void)
 {
   TestApplication application;