[dali_2.3.21] Merge branch 'devel/master'
[platform/core/uifw/dali-toolkit.git] / automated-tests / src / dali-toolkit / utc-Dali-Image.cpp
1 /*
2  * Copyright (c) 2023 Samsung Electronics Co., Ltd.
3  *
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
7  *
8  * http://www.apache.org/licenses/LICENSE-2.0
9  *
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.
15  */
16
17 #include <stdlib.h>
18 #include <iostream>
19
20 #include <dali-toolkit-test-suite-utils.h>
21
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>
29
30 using namespace Dali;
31 using namespace Dali::Toolkit;
32
33 namespace
34 {
35 } // namespace
36
37 void dali_image_startup(void)
38 {
39   test_return_value = TET_UNDEF;
40 }
41
42 void dali_image_cleanup(void)
43 {
44   test_return_value = TET_PASS;
45 }
46
47 int UtcDaliImageConvertFrameBufferToUrl1(void)
48 {
49   ToolkitTestApplication application;
50   tet_infoline("UtcDaliImageConvertFrameBufferToUrl1");
51
52   unsigned int width(64);
53   unsigned int height(64);
54   FrameBuffer  frameBuffer = FrameBuffer::New(width, height, FrameBuffer::Attachment::NONE);
55
56   DALI_TEST_CHECK(frameBuffer);
57   ImageUrl url = Dali::Toolkit::Image::GenerateUrl(frameBuffer, Pixel::Format::RGBA8888, width, height);
58
59   DALI_TEST_CHECK(url.GetUrl().size() > 0u);
60
61   END_TEST;
62 }
63
64 int UtcDaliImageConvertFrameBufferToUrl2(void)
65 {
66   ToolkitTestApplication application;
67   tet_infoline("UtcDaliImageConvertFrameBufferToUrl2");
68
69   unsigned int width(64);
70   unsigned int height(64);
71   FrameBuffer  frameBuffer = FrameBuffer::New(width, height, FrameBuffer::Attachment::NONE);
72
73   Texture texture = Texture::New(TextureType::TEXTURE_2D, Pixel::RGBA8888, width, height);
74   frameBuffer.AttachColorTexture(texture);
75
76   DALI_TEST_CHECK(Dali::Toolkit::Image::GenerateUrl(frameBuffer, 0).GetUrl().size() > 0u);
77
78   END_TEST;
79 }
80
81 int UtcDaliImageConvertDepthTextureFrameBufferToUrl(void)
82 {
83   ToolkitTestApplication application;
84   tet_infoline("UtcDaliImageConvertDepthTextureFrameBufferToUrl");
85
86   unsigned int width(64);
87   unsigned int height(64);
88   FrameBuffer  frameBuffer = FrameBuffer::New(width, height, FrameBuffer::Attachment::NONE);
89
90   Texture texture = Texture::New(TextureType::TEXTURE_2D, Pixel::DEPTH_UNSIGNED_INT, width, height);
91   DevelFrameBuffer::AttachDepthTexture(frameBuffer, texture);
92
93   DALI_TEST_CHECK(Dali::Toolkit::Image::GenerateDepthUrl(frameBuffer).GetUrl().size() > 0u);
94
95   END_TEST;
96 }
97
98 int UtcDaliImageConvertPixelDataToUrl01(void)
99 {
100   ToolkitTestApplication application;
101   tet_infoline("UtcDaliImageConvertPixelDataToUrl01");
102
103   unsigned int width(64);
104   unsigned int height(64);
105   unsigned int bufferSize = width * height * Pixel::GetBytesPerPixel(Pixel::RGB888);
106
107   unsigned char* buffer    = reinterpret_cast<unsigned char*>(malloc(bufferSize));
108   PixelData      pixelData = PixelData::New(buffer, bufferSize, width, height, Pixel::RGB888, PixelData::FREE);
109
110   DALI_TEST_CHECK(Dali::Toolkit::Image::GenerateUrl(pixelData).GetUrl().size() > 0u);
111
112   END_TEST;
113 }
114
115 int UtcDaliImageConvertPixelDataToUrl02(void)
116 {
117   ToolkitTestApplication application;
118   tet_infoline("UtcDaliImageConvertPixelDataToUrl02");
119
120   unsigned int width(64);
121   unsigned int height(64);
122   unsigned int bufferSize = width * height * Pixel::GetBytesPerPixel(Pixel::RGBA8888);
123
124   unsigned char* buffer    = reinterpret_cast<unsigned char*>(malloc(bufferSize));
125   PixelData      pixelData = PixelData::New(buffer, bufferSize, width, height, Pixel::RGBA8888, PixelData::FREE);
126
127   DALI_TEST_CHECK(Dali::Toolkit::Image::GenerateUrl(pixelData, true).GetUrl().size() > 0u);
128
129   END_TEST;
130 }
131
132 int UtcDaliImageConvertNativeImageSourceToUrl01(void)
133 {
134   ToolkitTestApplication application;
135   tet_infoline("UtcDaliImageConvertNativeImageSourceToUrl01");
136
137   unsigned int width(64);
138   unsigned int height(64);
139   try
140   {
141     NativeImageSourcePtr nativeImageSource = NativeImageSource::New(width, height, NativeImageSource::COLOR_DEPTH_DEFAULT);
142
143     DALI_TEST_CHECK(Dali::Toolkit::Image::GenerateUrl(nativeImageSource).GetUrl().size() > 0u);
144   }
145   catch(Dali::DaliException& e)
146   {
147     DALI_TEST_PRINT_ASSERT(e);
148     DALI_TEST_ASSERT(e, "Adaptor::IsAvailable()", TEST_LOCATION);
149   }
150   catch(...)
151   {
152     tet_printf("Assertion test failed - wrong Exception\n");
153     tet_result(TET_FAIL);
154   }
155
156   END_TEST;
157 }
158
159 int UtcDaliImageConvertNativeImageSourceToUrl02(void)
160 {
161   ToolkitTestApplication application;
162   tet_infoline("UtcDaliImageConvertNativeImageSourceToUrl02");
163
164   unsigned int width(64);
165   unsigned int height(64);
166   try
167   {
168     NativeImageSourcePtr nativeImageSource = NativeImageSource::New(width, height, NativeImageSource::COLOR_DEPTH_DEFAULT);
169
170     DALI_TEST_CHECK(Dali::Toolkit::Image::GenerateUrl(nativeImageSource, true).GetUrl().size() > 0u);
171   }
172   catch(Dali::DaliException& e)
173   {
174     DALI_TEST_PRINT_ASSERT(e);
175     DALI_TEST_ASSERT(e, "Adaptor::IsAvailable()", TEST_LOCATION);
176   }
177   catch(...)
178   {
179     tet_printf("Assertion test failed - wrong Exception\n");
180     tet_result(TET_FAIL);
181   }
182
183   END_TEST;
184 }
185
186 int UtcDaliImageConvertNativeImageInterfaceToUrl01(void)
187 {
188   ToolkitTestApplication application;
189   tet_infoline("UtcDaliImageConvertNativeImageInterfaceToUrl01");
190
191   unsigned int width(64);
192   unsigned int height(64);
193   try
194   {
195     NativeImageSourceQueuePtr nativeImageQueue = NativeImageSourceQueue::New(width, height, (Dali::NativeImageSourceQueue::ColorFormat::BGR888));
196
197     DALI_TEST_CHECK(Dali::Toolkit::Image::GenerateUrl(nativeImageQueue).GetUrl().size() > 0u);
198   }
199   catch(Dali::DaliException& e)
200   {
201     DALI_TEST_PRINT_ASSERT(e);
202     DALI_TEST_ASSERT(e, "Adaptor::IsAvailable()", TEST_LOCATION);
203   }
204   catch(...)
205   {
206     tet_printf("Assertion test failed - wrong Exception\n");
207     tet_result(TET_FAIL);
208   }
209
210   END_TEST;
211 }
212
213 int UtcDaliImageConvertNativeImageInterfaceToUrl02(void)
214 {
215   ToolkitTestApplication application;
216   tet_infoline("UtcDaliImageConvertNativeImageInterfaceToUrl02");
217
218   unsigned int width(64);
219   unsigned int height(64);
220   try
221   {
222     NativeImageSourceQueuePtr nativeImageQueue = NativeImageSourceQueue::New(width, height, (Dali::NativeImageSourceQueue::ColorFormat::BGR888));
223
224     DALI_TEST_CHECK(Dali::Toolkit::Image::GenerateUrl(nativeImageQueue, true).GetUrl().size() > 0u);
225   }
226   catch(Dali::DaliException& e)
227   {
228     DALI_TEST_PRINT_ASSERT(e);
229     DALI_TEST_ASSERT(e, "Adaptor::IsAvailable()", TEST_LOCATION);
230   }
231   catch(...)
232   {
233     tet_printf("Assertion test failed - wrong Exception\n");
234     tet_result(TET_FAIL);
235   }
236
237   END_TEST;
238 }
239
240 int UtcDaliImageConvertEncodedImageBufferToUrl(void)
241 {
242   ToolkitTestApplication application;
243   tet_infoline("UtcDaliImageConvertEncodedImageBufferToUrl");
244
245   Dali::Vector<uint8_t> buffer;
246   buffer.PushBack(0x11);
247   buffer.PushBack(0x22);
248   buffer.PushBack(0x33);
249
250   DALI_TEST_CHECK(Dali::Toolkit::Image::GenerateUrl(EncodedImageBuffer::New(buffer)).GetUrl().size() > 0u);
251
252   END_TEST;
253 }