2 * Copyright (c) 2023 Samsung Electronics Co., Ltd.
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
8 * http://www.apache.org/licenses/LICENSE-2.0
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
20 #include <dali-toolkit-test-suite-utils.h>
22 #include <dali-toolkit/public-api/image-loader/image-url.h>
23 #include <dali-toolkit/public-api/image-loader/image.h>
24 #include <dali/devel-api/adaptor-framework/native-image-source-queue.h>
25 #include <dali/public-api/adaptor-framework/native-image-source.h>
26 #include <dali/public-api/images/pixel-data.h>
27 #include <dali/public-api/rendering/frame-buffer.h>
28 #include <dali/public-api/rendering/texture.h>
31 using namespace Dali::Toolkit;
37 void dali_image_startup(void)
39 test_return_value = TET_UNDEF;
42 void dali_image_cleanup(void)
44 test_return_value = TET_PASS;
47 int UtcDaliImageConvertFrameBufferToUrl1(void)
49 ToolkitTestApplication application;
50 tet_infoline("UtcDaliImageConvertFrameBufferToUrl1");
52 unsigned int width(64);
53 unsigned int height(64);
54 FrameBuffer frameBuffer = FrameBuffer::New(width, height, FrameBuffer::Attachment::NONE);
56 DALI_TEST_CHECK(frameBuffer);
57 ImageUrl url = Dali::Toolkit::Image::GenerateUrl(frameBuffer, Pixel::Format::RGBA8888, width, height);
59 DALI_TEST_CHECK(url.GetUrl().size() > 0u);
64 int UtcDaliImageConvertFrameBufferToUrl2(void)
66 ToolkitTestApplication application;
67 tet_infoline("UtcDaliImageConvertFrameBufferToUrl2");
69 unsigned int width(64);
70 unsigned int height(64);
71 FrameBuffer frameBuffer = FrameBuffer::New(width, height, FrameBuffer::Attachment::NONE);
73 Texture texture = Texture::New(TextureType::TEXTURE_2D, Pixel::RGBA8888, width, height);
74 frameBuffer.AttachColorTexture(texture);
76 DALI_TEST_CHECK(Dali::Toolkit::Image::GenerateUrl(frameBuffer, 0).GetUrl().size() > 0u);
81 int UtcDaliImageConvertDepthTextureFrameBufferToUrl(void)
83 ToolkitTestApplication application;
84 tet_infoline("UtcDaliImageConvertDepthTextureFrameBufferToUrl");
86 unsigned int width(64);
87 unsigned int height(64);
88 FrameBuffer frameBuffer = FrameBuffer::New(width, height, FrameBuffer::Attachment::NONE);
90 Texture texture = Texture::New(TextureType::TEXTURE_2D, Pixel::DEPTH_UNSIGNED_INT, width, height);
91 DevelFrameBuffer::AttachDepthTexture(frameBuffer, texture);
93 DALI_TEST_CHECK(Dali::Toolkit::Image::GenerateDepthUrl(frameBuffer).GetUrl().size() > 0u);
98 int UtcDaliImageConvertPixelDataToUrl01(void)
100 ToolkitTestApplication application;
101 tet_infoline("UtcDaliImageConvertPixelDataToUrl01");
103 unsigned int width(64);
104 unsigned int height(64);
105 unsigned int bufferSize = width * height * Pixel::GetBytesPerPixel(Pixel::RGB888);
107 unsigned char* buffer = reinterpret_cast<unsigned char*>(malloc(bufferSize));
108 PixelData pixelData = PixelData::New(buffer, bufferSize, width, height, Pixel::RGB888, PixelData::FREE);
110 DALI_TEST_CHECK(Dali::Toolkit::Image::GenerateUrl(pixelData).GetUrl().size() > 0u);
115 int UtcDaliImageConvertPixelDataToUrl02(void)
117 ToolkitTestApplication application;
118 tet_infoline("UtcDaliImageConvertPixelDataToUrl02");
120 unsigned int width(64);
121 unsigned int height(64);
122 unsigned int bufferSize = width * height * Pixel::GetBytesPerPixel(Pixel::RGBA8888);
124 unsigned char* buffer = reinterpret_cast<unsigned char*>(malloc(bufferSize));
125 PixelData pixelData = PixelData::New(buffer, bufferSize, width, height, Pixel::RGBA8888, PixelData::FREE);
127 DALI_TEST_CHECK(Dali::Toolkit::Image::GenerateUrl(pixelData, true).GetUrl().size() > 0u);
132 int UtcDaliImageConvertNativeImageSourceToUrl01(void)
134 ToolkitTestApplication application;
135 tet_infoline("UtcDaliImageConvertNativeImageSourceToUrl01");
137 unsigned int width(64);
138 unsigned int height(64);
141 NativeImageSourcePtr nativeImageSource = NativeImageSource::New(width, height, NativeImageSource::COLOR_DEPTH_DEFAULT);
143 DALI_TEST_CHECK(Dali::Toolkit::Image::GenerateUrl(nativeImageSource).GetUrl().size() > 0u);
145 catch(Dali::DaliException& e)
147 DALI_TEST_PRINT_ASSERT(e);
148 DALI_TEST_ASSERT(e, "Adaptor::IsAvailable()", TEST_LOCATION);
152 tet_printf("Assertion test failed - wrong Exception\n");
153 tet_result(TET_FAIL);
159 int UtcDaliImageConvertNativeImageSourceToUrl02(void)
161 ToolkitTestApplication application;
162 tet_infoline("UtcDaliImageConvertNativeImageSourceToUrl02");
164 unsigned int width(64);
165 unsigned int height(64);
168 NativeImageSourcePtr nativeImageSource = NativeImageSource::New(width, height, NativeImageSource::COLOR_DEPTH_DEFAULT);
170 DALI_TEST_CHECK(Dali::Toolkit::Image::GenerateUrl(nativeImageSource, true).GetUrl().size() > 0u);
172 catch(Dali::DaliException& e)
174 DALI_TEST_PRINT_ASSERT(e);
175 DALI_TEST_ASSERT(e, "Adaptor::IsAvailable()", TEST_LOCATION);
179 tet_printf("Assertion test failed - wrong Exception\n");
180 tet_result(TET_FAIL);
186 int UtcDaliImageConvertNativeImageInterfaceToUrl01(void)
188 ToolkitTestApplication application;
189 tet_infoline("UtcDaliImageConvertNativeImageInterfaceToUrl01");
191 unsigned int width(64);
192 unsigned int height(64);
195 NativeImageSourceQueuePtr nativeImageQueue = NativeImageSourceQueue::New(width, height, (Dali::NativeImageSourceQueue::ColorFormat::BGR888));
197 DALI_TEST_CHECK(Dali::Toolkit::Image::GenerateUrl(nativeImageQueue).GetUrl().size() > 0u);
199 catch(Dali::DaliException& e)
201 DALI_TEST_PRINT_ASSERT(e);
202 DALI_TEST_ASSERT(e, "Adaptor::IsAvailable()", TEST_LOCATION);
206 tet_printf("Assertion test failed - wrong Exception\n");
207 tet_result(TET_FAIL);
213 int UtcDaliImageConvertNativeImageInterfaceToUrl02(void)
215 ToolkitTestApplication application;
216 tet_infoline("UtcDaliImageConvertNativeImageInterfaceToUrl02");
218 unsigned int width(64);
219 unsigned int height(64);
222 NativeImageSourceQueuePtr nativeImageQueue = NativeImageSourceQueue::New(width, height, (Dali::NativeImageSourceQueue::ColorFormat::BGR888));
224 DALI_TEST_CHECK(Dali::Toolkit::Image::GenerateUrl(nativeImageQueue, true).GetUrl().size() > 0u);
226 catch(Dali::DaliException& e)
228 DALI_TEST_PRINT_ASSERT(e);
229 DALI_TEST_ASSERT(e, "Adaptor::IsAvailable()", TEST_LOCATION);
233 tet_printf("Assertion test failed - wrong Exception\n");
234 tet_result(TET_FAIL);
240 int UtcDaliImageConvertEncodedImageBufferToUrl(void)
242 ToolkitTestApplication application;
243 tet_infoline("UtcDaliImageConvertEncodedImageBufferToUrl");
245 Dali::Vector<uint8_t> buffer;
246 buffer.PushBack(0x11);
247 buffer.PushBack(0x22);
248 buffer.PushBack(0x33);
250 DALI_TEST_CHECK(Dali::Toolkit::Image::GenerateUrl(EncodedImageBuffer::New(buffer)).GetUrl().size() > 0u);