Adding 'override', removing 'virtual' from overriding functions' declarations in...
[platform/core/uifw/dali-core.git] / automated-tests / src / dali / utc-Dali-Texture.cpp
index 5613e17..b170b6a 100644 (file)
@@ -1,5 +1,5 @@
 /*
- * Copyright (c) 2016 Samsung Electronics Co., Ltd.
+ * Copyright (c) 2020 Samsung Electronics Co., Ltd.
  *
  * Licensed under the Apache License, Version 2.0 (the "License");
  * you may not use this file except in compliance with the License.
@@ -16,6 +16,7 @@
  */
 
 #include <dali/public-api/dali-core.h>
+#include <dali/devel-api/images/pixel-data-devel.h>
 #include <dali-test-suite-utils.h>
 #include <test-native-image.h>
 
@@ -58,7 +59,7 @@ int UtcDaliTextureNew03(void)
   TestApplication application;
 
   // Create a native image source.
-  TestNativeImageNoExtPointer testNativeImage = TestNativeImageNoExt::New( 64u, 64u );
+  TestNativeImagePointer testNativeImage = TestNativeImage::New( 64u, 64u );
 
   // Create a texture from the native image source.
   Texture nativeTexture = Texture::New( *testNativeImage );
@@ -100,6 +101,51 @@ int UtcDaliTextureAssignmentOperator(void)
   END_TEST;
 }
 
+int UtcDaliTextureMoveConstructor(void)
+{
+  TestApplication application;
+
+  uint32_t width = 64;
+  uint32_t height = 64;
+  Texture texture = Texture::New( TextureType::TEXTURE_2D, Pixel::RGBA8888, width, height );
+  DALI_TEST_CHECK( texture );
+  DALI_TEST_EQUALS( 1, texture.GetBaseObject().ReferenceCount(), TEST_LOCATION );
+  DALI_TEST_EQUALS( texture.GetWidth(), width, TEST_LOCATION );
+  DALI_TEST_EQUALS( texture.GetHeight(), height, TEST_LOCATION );
+
+  Texture move = std::move( texture );
+  DALI_TEST_CHECK( move );
+  DALI_TEST_EQUALS( 1, move.GetBaseObject().ReferenceCount(), TEST_LOCATION );
+  DALI_TEST_EQUALS( move.GetWidth(), width, TEST_LOCATION );
+  DALI_TEST_EQUALS( move.GetHeight(), height, TEST_LOCATION );
+  DALI_TEST_CHECK( !texture );
+
+  END_TEST;
+}
+
+int UtcDaliTextureMoveAssignment(void)
+{
+  TestApplication application;
+
+  uint32_t width = 64;
+  uint32_t height = 64;
+  Texture texture = Texture::New( TextureType::TEXTURE_2D, Pixel::RGBA8888, width, height );
+  DALI_TEST_CHECK( texture );
+  DALI_TEST_EQUALS( 1, texture.GetBaseObject().ReferenceCount(), TEST_LOCATION );
+  DALI_TEST_EQUALS( texture.GetWidth(), width, TEST_LOCATION );
+  DALI_TEST_EQUALS( texture.GetHeight(), height, TEST_LOCATION );
+
+  Texture move;
+  move = std::move( texture );
+  DALI_TEST_CHECK( move );
+  DALI_TEST_EQUALS( 1, move.GetBaseObject().ReferenceCount(), TEST_LOCATION );
+  DALI_TEST_EQUALS( move.GetWidth(), width, TEST_LOCATION );
+  DALI_TEST_EQUALS( move.GetHeight(), height, TEST_LOCATION );
+  DALI_TEST_CHECK( !texture );
+
+  END_TEST;
+}
+
 int UtcDaliTextureDownCast01(void)
 {
   TestApplication application;
@@ -408,60 +454,109 @@ int UtcDaliTextureUpload04(void)
 
 int UtcDaliTextureUpload05(void)
 {
-  TestApplication application;
+  Pixel::Format COMPRESSED_PIXEL_FORMATS[] =
+  {
+    Pixel::COMPRESSED_R11_EAC,
+    Pixel::COMPRESSED_SIGNED_R11_EAC,
+    Pixel::COMPRESSED_RG11_EAC,
+    Pixel::COMPRESSED_SIGNED_RG11_EAC,
+    Pixel::COMPRESSED_RGB8_ETC2,
+    Pixel::COMPRESSED_SRGB8_ETC2,
+    Pixel::COMPRESSED_RGB8_PUNCHTHROUGH_ALPHA1_ETC2,
+    Pixel::COMPRESSED_SRGB8_PUNCHTHROUGH_ALPHA1_ETC2,
+    Pixel::COMPRESSED_RGBA8_ETC2_EAC,
+    Pixel::COMPRESSED_SRGB8_ALPHA8_ETC2_EAC,
+    Pixel::COMPRESSED_RGB8_ETC1,
+    Pixel::COMPRESSED_RGB_PVRTC_4BPPV1,
+    Pixel::COMPRESSED_RGBA_ASTC_4x4_KHR,
+    Pixel::COMPRESSED_RGBA_ASTC_5x4_KHR,
+    Pixel::COMPRESSED_RGBA_ASTC_5x5_KHR,
+    Pixel::COMPRESSED_RGBA_ASTC_6x5_KHR,
+    Pixel::COMPRESSED_RGBA_ASTC_6x6_KHR,
+    Pixel::COMPRESSED_RGBA_ASTC_8x5_KHR,
+    Pixel::COMPRESSED_RGBA_ASTC_8x6_KHR,
+    Pixel::COMPRESSED_RGBA_ASTC_8x8_KHR,
+    Pixel::COMPRESSED_RGBA_ASTC_10x5_KHR,
+    Pixel::COMPRESSED_RGBA_ASTC_10x6_KHR,
+    Pixel::COMPRESSED_RGBA_ASTC_10x8_KHR,
+    Pixel::COMPRESSED_RGBA_ASTC_10x10_KHR,
+    Pixel::COMPRESSED_RGBA_ASTC_12x10_KHR,
+    Pixel::COMPRESSED_RGBA_ASTC_12x12_KHR,
+    Pixel::COMPRESSED_SRGB8_ALPHA8_ASTC_4x4_KHR,
+    Pixel::COMPRESSED_SRGB8_ALPHA8_ASTC_5x4_KHR,
+    Pixel::COMPRESSED_SRGB8_ALPHA8_ASTC_5x5_KHR,
+    Pixel::COMPRESSED_SRGB8_ALPHA8_ASTC_6x5_KHR,
+    Pixel::COMPRESSED_SRGB8_ALPHA8_ASTC_6x6_KHR,
+    Pixel::COMPRESSED_SRGB8_ALPHA8_ASTC_8x5_KHR,
+    Pixel::COMPRESSED_SRGB8_ALPHA8_ASTC_8x6_KHR,
+    Pixel::COMPRESSED_SRGB8_ALPHA8_ASTC_8x8_KHR,
+    Pixel::COMPRESSED_SRGB8_ALPHA8_ASTC_10x5_KHR,
+    Pixel::COMPRESSED_SRGB8_ALPHA8_ASTC_10x6_KHR,
+    Pixel::COMPRESSED_SRGB8_ALPHA8_ASTC_10x8_KHR,
+    Pixel::COMPRESSED_SRGB8_ALPHA8_ASTC_10x10_KHR,
+    Pixel::COMPRESSED_SRGB8_ALPHA8_ASTC_12x10_KHR,
+    Pixel::COMPRESSED_SRGB8_ALPHA8_ASTC_12x12_KHR,
+  };
+  const unsigned int NUMBER_OF_COMPRESSED_PIXEL_FORMATS = sizeof( COMPRESSED_PIXEL_FORMATS ) / sizeof( Pixel::Format );
+
+  for( unsigned int index = 0; index < NUMBER_OF_COMPRESSED_PIXEL_FORMATS; ++index )
+  {
+    TestApplication application;
 
-  //Create a texture with a compressed format
-  unsigned int width(64);
-  unsigned int height(64);
-  Texture texture = Texture::New( TextureType::TEXTURE_2D, Pixel::COMPRESSED_RGBA_ASTC_4x4_KHR, width, height );
+    //Create a texture with a compressed format
+    unsigned int width(64);
+    unsigned int height(64);
+    Texture texture = Texture::New( TextureType::TEXTURE_2D, COMPRESSED_PIXEL_FORMATS[index], width, height );
 
-  application.GetGlAbstraction().EnableTextureCallTrace(true);
+    application.GetGlAbstraction().EnableTextureCallTrace(true);
 
-  application.SendNotification();
-  application.Render();
+    application.SendNotification();
+    application.Render();
 
-  TraceCallStack& callStack = application.GetGlAbstraction().GetTextureTrace();
+    TraceCallStack& callStack = application.GetGlAbstraction().GetTextureTrace();
 
-  //CompressedTexImage2D should be called with a null pointer to reserve storage for the texture in the gpu
-  {
-    std::stringstream out;
-    out << GL_TEXTURE_2D <<", "<< 0u << ", " << width <<", "<< height;
-    DALI_TEST_CHECK( callStack.FindMethodAndParams("CompressedTexImage2D", out.str().c_str() ) );
-  }
+    //CompressedTexImage2D should be called with a null pointer to reserve storage for the texture in the gpu
+    {
+      std::stringstream out;
+      out << GL_TEXTURE_2D <<", "<< 0u << ", " << width <<", "<< height;
+      DALI_TEST_CHECK( callStack.FindMethodAndParams("CompressedTexImage2D", out.str().c_str() ) );
+    }
 
-  //Upload data to the texture
-  callStack.Reset();
+    //Upload data to the texture
+    callStack.Reset();
 
-  unsigned int bufferSize( width * height * 4 );
-  unsigned char* buffer= reinterpret_cast<unsigned char*>( malloc( bufferSize ) );
-  PixelData pixelData = PixelData::New( buffer, bufferSize, width, height, Pixel::COMPRESSED_RGBA_ASTC_4x4_KHR, PixelData::FREE );
-  texture.Upload( pixelData );
-  application.SendNotification();
-  application.Render();
+    unsigned int bufferSize( width * height * 4 );
+    unsigned char* buffer= reinterpret_cast<unsigned char*>( malloc( bufferSize ) );
+    PixelData pixelData = PixelData::New( buffer, bufferSize, width, height, COMPRESSED_PIXEL_FORMATS[index], PixelData::FREE );
+    texture.Upload( pixelData );
+    application.SendNotification();
+    application.Render();
 
-  //CompressedTexImage2D should be called to upload the data
-  {
-    std::stringstream out;
-    out << GL_TEXTURE_2D <<", "<< 0u << ", " << width <<", "<< height;
-    DALI_TEST_CHECK( callStack.FindMethodAndParams("CompressedTexImage2D", out.str().c_str() ) );
-  }
+    //CompressedTexImage2D should be called to upload the data
+    {
+      std::stringstream out;
+      out << GL_TEXTURE_2D <<", "<< 0u << ", " << width <<", "<< height;
+      DALI_TEST_CHECK( callStack.FindMethodAndParams("CompressedTexImage2D", out.str().c_str() ) );
+    }
 
-  //Upload part of the texture
-  callStack.Reset();
-  bufferSize =  width * height * 2;
-  buffer = reinterpret_cast<unsigned char*>( malloc( bufferSize ) );
-  PixelData pixelDataSubImage = PixelData::New( buffer, bufferSize, width, height, Pixel::COMPRESSED_RGBA_ASTC_4x4_KHR, PixelData::FREE );
-  texture.Upload( pixelDataSubImage, 0u, 0u, width/2, height/2, width/2, height/2 );
-  application.SendNotification();
-  application.Render();
+    //Upload part of the texture
+    callStack.Reset();
+    bufferSize =  width * height * 2;
+    buffer = reinterpret_cast<unsigned char*>( malloc( bufferSize ) );
+    PixelData pixelDataSubImage = PixelData::New( buffer, bufferSize, width, height, COMPRESSED_PIXEL_FORMATS[index], PixelData::FREE );
+    texture.Upload( pixelDataSubImage, 0u, 0u, width/2, height/2, width/2, height/2 );
+    application.SendNotification();
+    application.Render();
 
-  //CompressedTexSubImage2D should be called to upload the data
-  {
-    std::stringstream out;
-    out << GL_TEXTURE_2D <<", "<< 0u << ", " << width/2 << ", " <<  height/2 << ", " << width/2 << ", " <<  height/2;
-    DALI_TEST_CHECK( callStack.FindMethodAndParams("CompressedTexSubImage2D", out.str().c_str() ) );
-  }
+    //CompressedTexSubImage2D should be called to upload the data
+    {
+      std::stringstream out;
+      out << GL_TEXTURE_2D <<", "<< 0u << ", " << width/2 << ", " <<  height/2 << ", " << width/2 << ", " <<  height/2;
+      DALI_TEST_CHECK( callStack.FindMethodAndParams("CompressedTexSubImage2D", out.str().c_str() ) );
+    }
 
+    application.GetGlAbstraction().ResetTextureCallStack();
+  }
 
   END_TEST;
 }
@@ -511,6 +606,61 @@ int UtcDaliTextureUpload06(void)
   END_TEST;
 }
 
+int UtcDaliTextureUpload07(void)
+{
+  Pixel::Format FLOATING_POINT_PIXEL_FORMATS[] =
+  {
+    Pixel::RGB16F,
+    Pixel::RGB32F,
+  };
+  const unsigned int NUMBER_OF_FLOATING_POINT_PIXEL_FORMATS = sizeof( FLOATING_POINT_PIXEL_FORMATS ) / sizeof( Pixel::Format );
+
+  for( unsigned int index = 0; index < NUMBER_OF_FLOATING_POINT_PIXEL_FORMATS; ++index )
+  {
+    TestApplication application;
+
+    //Create the texture
+    unsigned int width(64);
+    unsigned int height(64);
+    tet_infoline( "Creating a floating point texture" );
+    Texture texture = Texture::New( TextureType::TEXTURE_2D, FLOATING_POINT_PIXEL_FORMATS[index], width, height );
+
+    application.GetGlAbstraction().EnableTextureCallTrace(true);
+
+    application.SendNotification();
+    application.Render();
+
+    TraceCallStack& callStack = application.GetGlAbstraction().GetTextureTrace();
+
+    tet_infoline( "TexImage2D should be called with a null pointer to reserve storage for the texture in the gpu" );
+    {
+      std::stringstream out;
+      out << GL_TEXTURE_2D <<", "<< 0u << ", " << width <<", "<< height;
+      DALI_TEST_CHECK( callStack.FindMethodAndParams("TexImage2D", out.str().c_str() ) );
+    }
+
+    tet_infoline( "Upload data to the texture" );
+    callStack.Reset();
+
+    tet_infoline( "Creating a RGB pixel buffer and adding that to the texture to ensure it is handled correctly" );
+    unsigned int bufferSize( width * height * 3 );
+    unsigned char* buffer= reinterpret_cast<unsigned char*>( malloc( bufferSize ) );
+    PixelData pixelData = PixelData::New( buffer, bufferSize, width, height, FLOATING_POINT_PIXEL_FORMATS[index], PixelData::FREE );
+    texture.Upload( pixelData );
+    application.SendNotification();
+    application.Render();
+
+    tet_infoline( "TexImage2D should be called to upload the data" );
+    {
+      std::stringstream out;
+      out << GL_TEXTURE_2D <<", "<< 0u << ", " << width <<", "<< height;
+      DALI_TEST_CHECK( callStack.FindMethodAndParams("TexImage2D", out.str().c_str() ) );
+    }
+  }
+
+  END_TEST;
+}
+
 int UtcDaliTextureUploadSmallerThanSize(void)
 {
   TestApplication application;
@@ -615,7 +765,7 @@ int UtcDaliTextureGetHeight(void)
 int UtcDaliTextureContextLoss(void)
 {
   tet_infoline("UtcDaliTextureContextLoss\n");
-  TestApplication application; // Default config: DALI_DISCARDS_ALL_DATA
+  TestApplication application;
 
   //Create the texture
   unsigned int width(64);
@@ -633,20 +783,162 @@ int UtcDaliTextureContextLoss(void)
   END_TEST;
 }
 
-int UtcDaliNativeImageTexture(void)
+int UtcDaliNativeImageTexture01(void)
 {
   TestApplication application;
-  tet_infoline( "UtcDaliNativeImageTexture" );
+  tet_infoline( "UtcDaliNativeImageTexture01" );
 
   TestNativeImagePointer imageInterface = TestNativeImage::New( 16, 16 );
-  Texture texture = Texture::New( *(imageInterface.Get()) );
-  DALI_TEST_CHECK( texture );
+  {
+    Texture texture = Texture::New( *(imageInterface.Get()) );
+    Actor actor = CreateRenderableActor(texture, "", "");
+    application.GetScene().Add(actor);
+
+    DALI_TEST_CHECK( texture );
+
+    application.SendNotification();
+    application.Render(16);
+
+    DALI_TEST_EQUALS( imageInterface->mExtensionCreateCalls, 1, TEST_LOCATION );
+    DALI_TEST_EQUALS( imageInterface->mExtensionDestroyCalls, 0, TEST_LOCATION );
+    DALI_TEST_EQUALS( actor.GetProperty(Actor::Property::SIZE), Property::Value(Vector3(16,16,0)), TEST_LOCATION);
 
+    UnparentAndReset(actor);
+
+    application.SendNotification();
+    application.Render(16);
+  }
   application.SendNotification();
   application.Render(16);
 
-  DALI_TEST_CHECK( texture );
+  DALI_TEST_EQUALS( imageInterface->mExtensionCreateCalls, 1, TEST_LOCATION );
+  DALI_TEST_EQUALS( imageInterface->mExtensionDestroyCalls, 1, TEST_LOCATION );
+
+  END_TEST;
+}
+
+
+int UtcDaliNativeImageTexture02(void)
+{
+  TestApplication application;
+  tet_infoline( "UtcDaliNativeImageTexture02 - test error on TargetTexture" );
+
+  TestNativeImagePointer imageInterface = TestNativeImage::New( 16, 16 );
+  imageInterface->mTargetTextureError = 1u;
+  {
+    Texture texture = Texture::New( *(imageInterface.Get()) );
+    Actor actor = CreateRenderableActor(texture, "", "");
+    application.GetScene().Add(actor);
+
+    DALI_TEST_CHECK( texture );
+
+    application.SendNotification();
+    application.Render(16);
+
+    // Expect 2 attempts to create the texture - once when adding the texture
+    // to the scene-graph, and again since that failed, during the Bind.
+    DALI_TEST_EQUALS( imageInterface->mExtensionCreateCalls, 2, TEST_LOCATION );
+    DALI_TEST_EQUALS( imageInterface->mExtensionDestroyCalls, 2, TEST_LOCATION );
+
+    UnparentAndReset(actor);
+
+    application.SendNotification();
+    application.Render(16);
+  }
+  application.SendNotification();
+  application.Render(16);
+
+  // Expect that there are no further calls to create/destroy resource
+  DALI_TEST_EQUALS( imageInterface->mExtensionCreateCalls, 2, TEST_LOCATION );
+  DALI_TEST_EQUALS( imageInterface->mExtensionDestroyCalls, 2, TEST_LOCATION );
+
+  END_TEST;
+}
+
+int UtcDaliTextureGenerateMipmapsNegative(void)
+{
+  TestApplication application;
+  Dali::Texture instance;
+  try
+  {
+    instance.GenerateMipmaps();
+    DALI_TEST_CHECK(false); // Should not get here
+  }
+  catch(...)
+  {
+    DALI_TEST_CHECK(true); // We expect an assert
+  }
+  END_TEST;
+}
+
+int UtcDaliTextureUploadNegative01(void)
+{
+  TestApplication application;
+  Dali::Texture instance;
+  try
+  {
+    Dali::PixelData arg1;
+    instance.Upload(arg1);
+    DALI_TEST_CHECK(false); // Should not get here
+  }
+  catch(...)
+  {
+    DALI_TEST_CHECK(true); // We expect an assert
+  }
+  END_TEST;
+}
 
+int UtcDaliTextureUploadNegative02(void)
+{
+  TestApplication application;
+  Dali::Texture instance;
+  try
+  {
+    Dali::PixelData arg1;
+    unsigned int arg2(0u);
+    unsigned int arg3(0u);
+    unsigned int arg4(0u);
+    unsigned int arg5(0u);
+    unsigned int arg6(0u);
+    unsigned int arg7(0u);
+    instance.Upload(arg1,arg2,arg3,arg4,arg5,arg6,arg7);
+    DALI_TEST_CHECK(false); // Should not get here
+  }
+  catch(...)
+  {
+    DALI_TEST_CHECK(true); // We expect an assert
+  }
   END_TEST;
 }
 
+int UtcDaliTextureGetWidthNegative(void)
+{
+  TestApplication application;
+  Dali::Texture instance;
+  try
+  {
+    instance.GetWidth();
+    DALI_TEST_CHECK(false); // Should not get here
+  }
+  catch(...)
+  {
+    DALI_TEST_CHECK(true); // We expect an assert
+  }
+  END_TEST;
+}
+
+int UtcDaliTextureGetHeightNegative(void)
+{
+  TestApplication application;
+  Dali::Texture instance;
+  try
+  {
+    instance.GetHeight();
+    DALI_TEST_CHECK(false); // Should not get here
+  }
+  catch(...)
+  {
+    DALI_TEST_CHECK(true); // We expect an assert
+  }
+  END_TEST;
+}