(Vector) Support EncodedImageBuffer can use for vector image
[platform/core/uifw/dali-toolkit.git] / automated-tests / src / dali-toolkit-internal / utc-Dali-TextureManager.cpp
index b9970b3..f9df7d8 100644 (file)
@@ -62,6 +62,9 @@ const char* TEST_IMAGE_3_FILE_NAME = TEST_RESOURCE_DIR "/icon-edit.png";
 const char* TEST_IMAGE_4_FILE_NAME = TEST_RESOURCE_DIR "/application-icon-20.png";
 const char* TEST_MASK_FILE_NAME    = TEST_RESOURCE_DIR "/mask.png";
 
+const char* TEST_SVG_FILE_NAME                   = TEST_RESOURCE_DIR "/svg1.svg";
+const char* TEST_ANIMATED_VECTOR_IMAGE_FILE_NAME = TEST_RESOURCE_DIR "/insta_camera.json";
+
 class TestObserver : public Dali::Toolkit::TextureUploadObserver
 {
 public:
@@ -258,7 +261,7 @@ int UtcTextureManagerEncodedImageBuffer(void)
 
   std::string url1 = textureManager.AddEncodedImageBuffer(buffer1);
   std::string url2 = textureManager.AddEncodedImageBuffer(buffer1);
-  std::string url3 = VisualUrl::CreateBufferUrl(""); ///< Impossible Buffer URL. for coverage
+  std::string url3 = VisualUrl::CreateBufferUrl("", ""); ///< Impossible Buffer URL. for coverage
 
   // Check if same EncodedImageBuffer get same url
   DALI_TEST_CHECK(url1 == url2);
@@ -437,6 +440,72 @@ int UtcTextureManagerEncodedImageBuffer(void)
   END_TEST;
 }
 
+int UtcTextureManagerEncodedImageBufferWithImageType(void)
+{
+  ToolkitTestApplication application;
+  tet_infoline("UtcTextureManagerEncodedImageBufferWithImageType");
+
+  auto  visualFactory  = Toolkit::VisualFactory::Get();
+  auto& textureManager = GetImplementation(visualFactory).GetTextureManager(); // Use VisualFactory's texture manager
+
+  // Get encoded raw-buffer image and generate url
+  EncodedImageBuffer buffer1 = ConvertFileToEncodedImageBuffer(TEST_SVG_FILE_NAME);
+  EncodedImageBuffer buffer2 = ConvertFileToEncodedImageBuffer(TEST_ANIMATED_VECTOR_IMAGE_FILE_NAME);
+
+  std::string url1 = textureManager.AddEncodedImageBuffer(buffer1);
+  std::string url2 = textureManager.AddEncodedImageBuffer(buffer1);
+
+  // Check if same EncodedImageBuffer get same url
+  DALI_TEST_CHECK(url1 == url2);
+  // Reduce reference count
+  textureManager.RemoveEncodedImageBuffer(url1);
+  // Check whethere url1 still valid
+  DALI_TEST_CHECK(textureManager.GetEncodedImageBuffer(url1));
+
+  url2 = textureManager.AddEncodedImageBuffer(buffer2);
+  // Check if difference EncodedImageBuffer get difference url
+  DALI_TEST_CHECK(url1 != url2);
+
+  buffer1.SetImageType(EncodedImageBuffer::ImageType::VECTOR_IMAGE);
+  buffer2.SetImageType(EncodedImageBuffer::ImageType::ANIMATED_VECTOR_IMAGE);
+
+  std::string url1AfterType = textureManager.AddEncodedImageBuffer(buffer1);
+  std::string url2AfterType = textureManager.AddEncodedImageBuffer(buffer2);
+
+  // Check if EncodedImageBuffer with imagetype get difference url.
+  DALI_TEST_CHECK(url1 != url1AfterType);
+  DALI_TEST_CHECK(url2 != url2AfterType);
+  DALI_TEST_CHECK(url1AfterType != url2AfterType);
+
+  int  bufferId      = std::atoi(VisualUrl::GetLocationWithoutExtension(url1AfterType).c_str());
+  auto urlFromBuffer = textureManager.GetVisualUrl(bufferId);
+
+  // Check url from buffer id is equal with what we know.
+  DALI_TEST_CHECK(url1AfterType == urlFromBuffer.GetUrl());
+
+  // Reduce reference count
+  textureManager.RemoveEncodedImageBuffer(url1AfterType);
+  // Check whethere url1 still valid
+  DALI_TEST_CHECK(textureManager.GetEncodedImageBuffer(url1AfterType));
+
+  // Reduce reference count
+  textureManager.RemoveEncodedImageBuffer(url1AfterType);
+  // Check whethere url1 is invalid
+  DALI_TEST_CHECK(!textureManager.GetEncodedImageBuffer(url1AfterType));
+
+  // Reduce reference count
+  textureManager.RemoveEncodedImageBuffer(url2);
+  // Check whethere url2 is still valid
+  DALI_TEST_CHECK(textureManager.GetEncodedImageBuffer(url2));
+
+  // Reduce reference count
+  textureManager.RemoveEncodedImageBuffer(url2);
+  // Check whethere url2 is invalid
+  DALI_TEST_CHECK(!textureManager.GetEncodedImageBuffer(url2));
+
+  END_TEST;
+}
+
 int UtcTextureManagerExternalTexture(void)
 {
   ToolkitTestApplication application;
@@ -1046,9 +1115,6 @@ int UtcTextureManagerUseInvalidMaskAndMaskLoadedLater(void)
   DALI_TEST_EQUALS(observer.mLoaded, false, TEST_LOCATION);
   DALI_TEST_EQUALS(observer.mObserverCalled, false, TEST_LOCATION);
 
-  application.SendNotification();
-  application.Render();
-
   // CAPTION : HARD-CODING for coverage.
   {
     Dali::Devel::PixelBuffer pixelBuffer = textureManager.LoadPixelBuffer(
@@ -1500,9 +1566,6 @@ int UtcTextureManagerRemoveDuringApplyMasking(void)
     preMultiply,
     synchronousLoading);
 
-  application.SendNotification();
-  application.Render();
-
   DALI_TEST_EQUALS(observer1.mLoaded, false, TEST_LOCATION);
   DALI_TEST_EQUALS(observer1.mObserverCalled, false, TEST_LOCATION);
   DALI_TEST_EQUALS(observer2.mLoaded, false, TEST_LOCATION);
@@ -1903,9 +1966,6 @@ int UtcTextureManagerRemoveDuringGPUMasking(void)
       *data3.observerCalleddPtr = data3.self->mObserverCalled;
     });
 
-  application.SendNotification();
-  application.Render();
-
   tet_printf("Id info - mask : {%d}, 1 : {%d}, 2 : {%d}, 3 : {%d}, 4 : {%d}\n", static_cast<int>(maskInfo[0]->mAlphaMaskId), static_cast<int>(textureId1), static_cast<int>(textureId2), static_cast<int>(textureId3), static_cast<int>(textureId4));
 
   // CAPTION : HARD-CODING.
@@ -2193,9 +2253,6 @@ int UtcTextureManagerDestroyObserverDuringObserve(void)
       *data2.observerCalledPtr = data2.self->mObserverCalled;
     });
 
-  application.SendNotification();
-  application.Render();
-
   tet_printf("Id info - 1 : {%d}, 2 : {%d}, 3 : {%d}, 4 : {%d}\n", static_cast<int>(textureId1), static_cast<int>(textureId2), static_cast<int>(textureId3), static_cast<int>(textureId4));
 
   DALI_TEST_EQUALS(observer1.mLoaded, false, TEST_LOCATION);