Revert "[Tizen] Appendix log for ttrace + Print keycode and timestamp"
[platform/core/uifw/dali-core.git] / automated-tests / src / dali / utc-Dali-PixelData.cpp
index dd71651..5454954 100644 (file)
@@ -1,5 +1,5 @@
 /*
- * Copyright (c) 2020 Samsung Electronics Co., Ltd.
+ * Copyright (c) 2023 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.
  *
  */
 
-#include <cstdlib>
 #include <dali-test-suite-utils.h>
-
-#include <dali/public-api/images/pixel.h>
-#include <dali/public-api/images/pixel-data.h>
 #include <dali/public-api/common/dali-vector.h>
+#include <dali/public-api/images/pixel-data.h>
+#include <dali/public-api/images/pixel.h>
+
+#include <dali/integration-api/pixel-data-integ.h>
+
+#include <cstdlib>
 
 using namespace Dali;
 
@@ -28,17 +30,17 @@ int UtcDaliPixelData01(void)
 {
   TestApplication application;
 
-  unsigned int width = 10u;
-  unsigned int height = 10u;
-  unsigned int bufferSize = width*height*Pixel::GetBytesPerPixel( Pixel::RGB888 );
+  unsigned int width      = 10u;
+  unsigned int height     = 10u;
+  unsigned int bufferSize = width * height * Pixel::GetBytesPerPixel(Pixel::RGB888);
 
-  unsigned char* buffer= reinterpret_cast<unsigned char*>( malloc( bufferSize ) );
-  PixelData pixelData = PixelData::New( buffer, bufferSize, width, height, Pixel::RGB888, PixelData::FREE );
+  unsigned char* buffer    = reinterpret_cast<unsigned char*>(malloc(bufferSize));
+  PixelData      pixelData = PixelData::New(buffer, bufferSize, width, height, Pixel::RGB888, PixelData::FREE);
 
-  DALI_TEST_CHECK( pixelData );
-  DALI_TEST_CHECK( pixelData.GetWidth() == width );
-  DALI_TEST_CHECK( pixelData.GetHeight() == height );
-  DALI_TEST_CHECK( pixelData.GetPixelFormat() == Pixel::RGB888 );
+  DALI_TEST_CHECK(pixelData);
+  DALI_TEST_CHECK(pixelData.GetWidth() == width);
+  DALI_TEST_CHECK(pixelData.GetHeight() == height);
+  DALI_TEST_CHECK(pixelData.GetPixelFormat() == Pixel::RGB888);
 
   END_TEST;
 }
@@ -47,18 +49,62 @@ int UtcDaliPixelData02(void)
 {
   TestApplication application;
 
-  unsigned int width = 10u;
-  unsigned int height = 10u;
-  unsigned int bufferSize = width*height*Pixel::GetBytesPerPixel( Pixel::L8 );
-  unsigned char* buffer = new unsigned char [ bufferSize ];
-  buffer[0] = 'a';
+  unsigned int   width      = 10u;
+  unsigned int   height     = 10u;
+  unsigned int   bufferSize = width * height * Pixel::GetBytesPerPixel(Pixel::L8);
+  unsigned char* buffer     = new unsigned char[bufferSize];
+  buffer[0]                 = 'a';
+
+  PixelData pixelData = PixelData::New(buffer, bufferSize, width, height, Pixel::L8, PixelData::DELETE_ARRAY);
+
+  DALI_TEST_CHECK(pixelData);
+  DALI_TEST_CHECK(pixelData.GetWidth() == width);
+  DALI_TEST_CHECK(pixelData.GetHeight() == height);
+  DALI_TEST_CHECK(pixelData.GetStride() == 0);
+  DALI_TEST_CHECK(pixelData.GetPixelFormat() == Pixel::L8);
+
+  END_TEST;
+}
+
+int UtcDaliPixelData03(void)
+{
+  TestApplication application;
+
+  uint32_t width      = 10u;
+  uint32_t height     = 10u;
+  uint32_t stride     = 12u;
+  uint32_t bufferSize = stride * height * Pixel::GetBytesPerPixel(Pixel::RGB888);
+
+  uint8_t*  buffer    = reinterpret_cast<uint8_t*>(malloc(bufferSize));
+  PixelData pixelData = PixelData::New(buffer, bufferSize, width, height, stride, Pixel::RGB888, PixelData::FREE);
+
+  DALI_TEST_CHECK(pixelData);
+  DALI_TEST_CHECK(pixelData.GetWidth() == width);
+  DALI_TEST_CHECK(pixelData.GetHeight() == height);
+  DALI_TEST_CHECK(pixelData.GetStride() == stride);
+  DALI_TEST_CHECK(pixelData.GetPixelFormat() == Pixel::RGB888);
+
+  END_TEST;
+}
+
+int UtcDaliPixelData04(void)
+{
+  TestApplication application;
+
+  uint32_t width      = 10u;
+  uint32_t height     = 10u;
+  uint32_t stride     = 12u;
+  uint32_t bufferSize = stride * height * Pixel::GetBytesPerPixel(Pixel::L8);
+  uint8_t* buffer     = new uint8_t[bufferSize];
+  buffer[0]           = 'a';
 
-  PixelData pixelData = PixelData::New( buffer, bufferSize, width, height, Pixel::L8, PixelData::DELETE_ARRAY );
+  PixelData pixelData = PixelData::New(buffer, bufferSize, width, height, stride, Pixel::L8, PixelData::DELETE_ARRAY);
 
-  DALI_TEST_CHECK( pixelData);
-  DALI_TEST_CHECK( pixelData.GetWidth() == width );
-  DALI_TEST_CHECK( pixelData.GetHeight() == height );
-  DALI_TEST_CHECK( pixelData.GetPixelFormat() == Pixel::L8 );
+  DALI_TEST_CHECK(pixelData);
+  DALI_TEST_CHECK(pixelData.GetWidth() == width);
+  DALI_TEST_CHECK(pixelData.GetHeight() == height);
+  DALI_TEST_CHECK(pixelData.GetStride() == stride);
+  DALI_TEST_CHECK(pixelData.GetPixelFormat() == Pixel::L8);
 
   END_TEST;
 }
@@ -67,15 +113,15 @@ int UtcDaliPixelDataCopyConstructor(void)
 {
   TestApplication application;
 
-  unsigned int width = 10u;
-  unsigned int height = 10u;
-  unsigned int bufferSize = width*height*Pixel::GetBytesPerPixel( Pixel::L8 );
-  unsigned char* buffer = new unsigned char [ bufferSize ];
-  PixelData pixelData = PixelData::New( buffer, bufferSize, width, height, Pixel::L8, PixelData::DELETE_ARRAY );
+  unsigned int   width      = 10u;
+  unsigned int   height     = 10u;
+  unsigned int   bufferSize = width * height * Pixel::GetBytesPerPixel(Pixel::L8);
+  unsigned char* buffer     = new unsigned char[bufferSize];
+  PixelData      pixelData  = PixelData::New(buffer, bufferSize, width, height, Pixel::L8, PixelData::DELETE_ARRAY);
 
   PixelData pixelDataCopy(pixelData);
 
-  DALI_TEST_EQUALS( (bool)pixelDataCopy, true, TEST_LOCATION );
+  DALI_TEST_EQUALS((bool)pixelDataCopy, true, TEST_LOCATION);
   END_TEST;
 }
 
@@ -83,17 +129,17 @@ int UtcDaliPixelDataAssignmentOperator(void)
 {
   TestApplication application;
 
-  unsigned int width = 10u;
-  unsigned int height = 10u;
-  unsigned int bufferSize = width*height*Pixel::GetBytesPerPixel( Pixel::L8 );
-  unsigned char* buffer = new unsigned char [ bufferSize ];
-  PixelData pixelData = PixelData::New( buffer, bufferSize, width, height, Pixel::L8, PixelData::DELETE_ARRAY );
+  unsigned int   width      = 10u;
+  unsigned int   height     = 10u;
+  unsigned int   bufferSize = width * height * Pixel::GetBytesPerPixel(Pixel::L8);
+  unsigned char* buffer     = new unsigned char[bufferSize];
+  PixelData      pixelData  = PixelData::New(buffer, bufferSize, width, height, Pixel::L8, PixelData::DELETE_ARRAY);
 
   PixelData pixelData2;
-  DALI_TEST_EQUALS( (bool)pixelData2, false, TEST_LOCATION );
+  DALI_TEST_EQUALS((bool)pixelData2, false, TEST_LOCATION);
 
   pixelData2 = pixelData;
-  DALI_TEST_EQUALS( (bool)pixelData2, true, TEST_LOCATION );
+  DALI_TEST_EQUALS((bool)pixelData2, true, TEST_LOCATION);
 
   END_TEST;
 }
@@ -102,21 +148,21 @@ int UtcDaliPixelDataMoveConstructor(void)
 {
   TestApplication application;
 
-  unsigned int width = 10u;
-  unsigned int height = 10u;
-  unsigned int bufferSize = width*height*Pixel::GetBytesPerPixel( Pixel::L8 );
-  unsigned char* buffer = new unsigned char [ bufferSize ];
+  unsigned int   width      = 10u;
+  unsigned int   height     = 10u;
+  unsigned int   bufferSize = width * height * Pixel::GetBytesPerPixel(Pixel::L8);
+  unsigned char* buffer     = new unsigned char[bufferSize];
 
-  PixelData pixelData = PixelData::New( buffer, bufferSize, width, height, Pixel::L8, PixelData::DELETE_ARRAY );
-  DALI_TEST_CHECK( pixelData );
-  DALI_TEST_EQUALS( width, pixelData.GetWidth(), TEST_LOCATION );
-  DALI_TEST_EQUALS( height, pixelData.GetHeight(), TEST_LOCATION );
+  PixelData pixelData = PixelData::New(buffer, bufferSize, width, height, Pixel::L8, PixelData::DELETE_ARRAY);
+  DALI_TEST_CHECK(pixelData);
+  DALI_TEST_EQUALS(width, pixelData.GetWidth(), TEST_LOCATION);
+  DALI_TEST_EQUALS(height, pixelData.GetHeight(), TEST_LOCATION);
 
-  PixelData moved = std::move( pixelData);
-  DALI_TEST_CHECK( moved );
-  DALI_TEST_EQUALS( width, moved.GetWidth(), TEST_LOCATION );
-  DALI_TEST_EQUALS( height, moved.GetHeight(), TEST_LOCATION );
-  DALI_TEST_CHECK( !pixelData );
+  PixelData moved = std::move(pixelData);
+  DALI_TEST_CHECK(moved);
+  DALI_TEST_EQUALS(width, moved.GetWidth(), TEST_LOCATION);
+  DALI_TEST_EQUALS(height, moved.GetHeight(), TEST_LOCATION);
+  DALI_TEST_CHECK(!pixelData);
 
   END_TEST;
 }
@@ -125,22 +171,22 @@ int UtcDaliPixelDataMoveAssignment(void)
 {
   TestApplication application;
 
-  unsigned int width = 10u;
-  unsigned int height = 10u;
-  unsigned int bufferSize = width*height*Pixel::GetBytesPerPixel( Pixel::L8 );
-  unsigned char* buffer = new unsigned char [ bufferSize ];
+  unsigned int   width      = 10u;
+  unsigned int   height     = 10u;
+  unsigned int   bufferSize = width * height * Pixel::GetBytesPerPixel(Pixel::L8);
+  unsigned char* buffer     = new unsigned char[bufferSize];
 
-  PixelData pixelData = PixelData::New( buffer, bufferSize, width, height, Pixel::L8, PixelData::DELETE_ARRAY );
-  DALI_TEST_CHECK( pixelData );
-  DALI_TEST_EQUALS( width, pixelData.GetWidth(), TEST_LOCATION );
-  DALI_TEST_EQUALS( height, pixelData.GetHeight(), TEST_LOCATION );
+  PixelData pixelData = PixelData::New(buffer, bufferSize, width, height, Pixel::L8, PixelData::DELETE_ARRAY);
+  DALI_TEST_CHECK(pixelData);
+  DALI_TEST_EQUALS(width, pixelData.GetWidth(), TEST_LOCATION);
+  DALI_TEST_EQUALS(height, pixelData.GetHeight(), TEST_LOCATION);
 
   PixelData moved;
-  moved = std::move( pixelData);
-  DALI_TEST_CHECK( moved );
-  DALI_TEST_EQUALS( width, moved.GetWidth(), TEST_LOCATION );
-  DALI_TEST_EQUALS( height, moved.GetHeight(), TEST_LOCATION );
-  DALI_TEST_CHECK( !pixelData );
+  moved = std::move(pixelData);
+  DALI_TEST_CHECK(moved);
+  DALI_TEST_EQUALS(width, moved.GetWidth(), TEST_LOCATION);
+  DALI_TEST_EQUALS(height, moved.GetHeight(), TEST_LOCATION);
+  DALI_TEST_CHECK(!pixelData);
 
   END_TEST;
 }
@@ -192,3 +238,64 @@ int UtcDaliPixelDataGetHeightNegative(void)
   }
   END_TEST;
 }
+
+int UtcDaliPixelDataReleasePixelDataBuffer(void)
+{
+  TestApplication application;
+
+  uint32_t width      = 10u;
+  uint32_t height     = 10u;
+  uint32_t stride     = 12u;
+  uint32_t bufferSize = stride * height * Pixel::GetBytesPerPixel(Pixel::L8);
+  uint8_t* buffer     = new uint8_t[bufferSize];
+  buffer[0]           = 'a';
+
+  PixelData pixelData = PixelData::New(buffer, bufferSize, width, height, stride, Pixel::L8, PixelData::DELETE_ARRAY);
+
+  DALI_TEST_CHECK(pixelData);
+  DALI_TEST_CHECK(pixelData.GetWidth() == width);
+  DALI_TEST_CHECK(pixelData.GetHeight() == height);
+  DALI_TEST_CHECK(pixelData.GetStride() == stride);
+  DALI_TEST_CHECK(pixelData.GetPixelFormat() == Pixel::L8);
+
+  Dali::Integration::PixelDataBuffer pixelDataBuffer = Dali::Integration::ReleasePixelDataBuffer(pixelData);
+
+  DALI_TEST_CHECK(!pixelData);
+
+  DALI_TEST_EQUALS(pixelDataBuffer.bufferSize, bufferSize, TEST_LOCATION);
+  DALI_TEST_EQUALS(pixelDataBuffer.buffer[0], static_cast<uint8_t>('a'), TEST_LOCATION);
+
+  // Release memory by our self.
+  delete[] pixelDataBuffer.buffer;
+
+  END_TEST;
+}
+
+int UtcDaliPixelDataGetPixelDataBuffer(void)
+{
+  TestApplication application;
+
+  uint32_t width      = 10u;
+  uint32_t height     = 10u;
+  uint32_t stride     = 12u;
+  uint32_t bufferSize = stride * height * Pixel::GetBytesPerPixel(Pixel::L8);
+  uint8_t* buffer     = new uint8_t[bufferSize];
+  buffer[0]           = 'a';
+
+  PixelData pixelData = PixelData::New(buffer, bufferSize, width, height, stride, Pixel::L8, PixelData::DELETE_ARRAY);
+
+  DALI_TEST_CHECK(pixelData);
+  DALI_TEST_CHECK(pixelData.GetWidth() == width);
+  DALI_TEST_CHECK(pixelData.GetHeight() == height);
+  DALI_TEST_CHECK(pixelData.GetStride() == stride);
+  DALI_TEST_CHECK(pixelData.GetPixelFormat() == Pixel::L8);
+
+  Dali::Integration::PixelDataBuffer pixelDataBuffer = Dali::Integration::GetPixelDataBuffer(pixelData);
+
+  DALI_TEST_CHECK(pixelData);
+
+  DALI_TEST_EQUALS(pixelDataBuffer.bufferSize, bufferSize, TEST_LOCATION);
+  DALI_TEST_EQUALS(pixelDataBuffer.buffer[0], static_cast<uint8_t>('a'), TEST_LOCATION);
+
+  END_TEST;
+}