2 * Copyright (c) 2014 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.
22 #include <dali/public-api/dali-core.h>
23 #include <dali-test-suite-utils.h>
28 void utc_dali_bitmap_image_startup(void)
30 test_return_value = TET_UNDEF;
33 void utc_dali_bitmap_image_cleanup(void)
35 test_return_value = TET_PASS;
38 int UtcDaliBitmapImageNew01(void)
40 TestApplication application;
42 tet_infoline("UtcDaliBitmapImageNew01 - BitmapImage::New(unsigned int, unsigned int, Pixel::Format)");
44 // invoke default handle constructor
48 image = BitmapImage::New(16, 16);
49 application.SendNotification();
50 application.Render(16);
51 application.Render(16);
52 application.SendNotification();
54 ImageAttributes attributes = image.GetAttributes();
56 DALI_TEST_CHECK( attributes.GetWidth() == 16);
60 int UtcDaliBitmapImageNew02(void)
62 TestApplication application;
64 tet_infoline("UtcDaliBitmapImageNew02 - BitmapImage::New(PixelBuffer*, unsigned int, unsigned int, Pixel::Format, unsigned int)");
66 PixelBuffer* buffer = new PixelBuffer[16 * 16];
67 BitmapImage image = BitmapImage::New(buffer, 16, 16, Pixel::A8);
68 application.SendNotification();
69 application.Render(16);
70 application.Render(16);
71 application.SendNotification();
73 Dali::ImageAttributes attributes = image.GetAttributes();
75 DALI_TEST_CHECK( attributes.GetWidth() == 16);
81 int UtcDaliBitmapImageNewWithPolicy01(void)
83 TestApplication application;
85 tet_infoline("UtcDaliBitmapImageNewWithPolicy01 - BitmapImage::New(unsigned int, unsigned int, Pixel::Format, LoadPolicy, ReleasePolicy)");
88 std::vector<GLuint> ids;
90 application.GetGlAbstraction().SetNextTextureIds( ids );
92 // invoke default handle constructor
96 image = BitmapImage::New(16, 16, Pixel::A8, Image::OnDemand, Image::Unused);
97 application.SendNotification();
98 application.Render(16);
99 application.Render(16);
100 application.SendNotification();
102 ImageAttributes attributes = image.GetAttributes();
103 DALI_TEST_CHECK( attributes.GetWidth() == 16);
104 /// @todo: how to test OnDemand? - resource id would be 0 if buffer only allocated on first call to ::GetBuffer()
106 ImageActor actor = ImageActor::New(image);
107 Stage::GetCurrent().Add(actor);
109 application.SendNotification();
110 application.Render(16);
111 // testing ReleasePolicy::Unused
112 // fake loading image
113 application.Render(16);
114 application.SendNotification();
116 DALI_TEST_CHECK ( !application.GetGlAbstraction().CheckTextureDeleted(23) );
118 // discard texture when actor comes off stage
119 Stage::GetCurrent().Remove(actor);
120 application.Render(16);
121 application.SendNotification();
122 application.Render(16);
123 application.SendNotification();
124 DALI_TEST_CHECK ( application.GetGlAbstraction().CheckTextureDeleted(23) );
128 int UtcDaliBitmapImageNewWithPolicy02(void)
130 TestApplication application;
132 tet_infoline("UtcDaliBitmapImageNewWithPolicy02 - BitmapImage::New(PixelBuffer*, unsigned int, unsigned int, Pixel::Format, unsigned int, ReleasePolicy)");
134 // Force texture id's
135 std::vector<GLuint> ids;
137 application.GetGlAbstraction().SetNextTextureIds( ids );
139 PixelBuffer* buffer = new PixelBuffer[16 * 16];
140 BitmapImage image = BitmapImage::New(buffer, 16, 16, Pixel::A8, 16, Image::Unused);
141 application.SendNotification();
142 application.Render(16);
143 application.Render(16);
144 application.SendNotification();
146 ImageAttributes attributes = image.GetAttributes();
147 DALI_TEST_CHECK( attributes.GetWidth() == 16);
148 /// @todo: how to test OnDemand? - resource id would be 0 if buffer only allocated on first call to ::GetBuffer()
150 ImageActor actor = ImageActor::New(image);
151 Stage::GetCurrent().Add(actor);
153 application.SendNotification();
154 application.Render(16);
155 // testing ReleasePolicy::Unused
156 // fake loading image
157 application.Render(16);
158 application.SendNotification();
160 DALI_TEST_CHECK ( !application.GetGlAbstraction().CheckTextureDeleted(23) );
162 // discard texture when actor comes off stage
163 Stage::GetCurrent().Remove(actor);
164 application.Render(16);
165 application.SendNotification();
166 application.Render(16);
167 application.SendNotification();
168 DALI_TEST_CHECK ( application.GetGlAbstraction().CheckTextureDeleted(23) );
172 int UtcDaliBitmapImageDownCast(void)
174 TestApplication application;
175 tet_infoline("Testing Dali::BitmapImage::DownCast()");
177 BitmapImage bitmap = BitmapImage::New(1, 1, Dali::Pixel::BGRA8888);
178 ImageActor imageActor = ImageActor::New(bitmap);
179 application.SendNotification();
180 application.Render(16);
181 application.Render(16);
182 application.SendNotification();
184 Image image = imageActor.GetImage();
185 BitmapImage bitmapImage = BitmapImage::DownCast( image );
187 DALI_TEST_CHECK(bitmapImage);
191 int UtcDaliBitmapImageDownCast2(void)
193 TestApplication application;
194 tet_infoline("Testing Dali::BitmapImage::DownCast()");
196 Image image = Image::New("IncorrectImageName");
197 ImageActor imageActor = ImageActor::New(image);
198 application.SendNotification();
199 application.Render(16);
200 application.Render(16);
201 application.SendNotification();
203 Image image1 = imageActor.GetImage();
205 BitmapImage bitmapImage = BitmapImage::DownCast( image1 );
206 DALI_TEST_CHECK(!bitmapImage);
208 Actor unInitialzedActor;
209 bitmapImage = BitmapImage::DownCast( unInitialzedActor );
210 DALI_TEST_CHECK(!bitmapImage);
214 int UtcDaliBitmapImageWHITE(void)
216 TestApplication application;
218 tet_infoline("UtcDaliBitmapImageWHITE - BitmapImage::WHITE()");
220 BitmapImage image = BitmapImage::WHITE(); // creates a 1x1 RGBA white pixel
221 application.SendNotification();
222 application.Render(16);
223 application.Render(16);
224 application.SendNotification();
226 Dali::ImageAttributes attributes = image.GetAttributes();
227 PixelBuffer* buffer = image.GetBuffer();
229 DALI_TEST_CHECK( attributes.GetWidth() == 1 && // 1 pixel wide
230 buffer != NULL && // valid buffer
231 *buffer == 0xff); // r component is 255
235 int UtcDaliBitmapImageGetBuffer(void)
237 TestApplication application;
239 tet_infoline("UtcDaliBitmapImageGetBuffer");
241 BitmapImage image = BitmapImage::WHITE(); // creates a 1x1 RGBA white pixel
243 PixelBuffer* buffer = image.GetBuffer();
244 application.SendNotification();
245 application.Render();
246 application.Render();
247 application.SendNotification();
249 ImageAttributes attributes = image.GetAttributes();
250 DALI_TEST_CHECK( attributes.GetWidth() == 1 && // 1 pixel wide
251 buffer != NULL && // valid buffer
252 *((unsigned int*)buffer) == 0xffffffff); // all component are 255
256 int UtcDaliBitmapImageGetBufferSize(void)
258 TestApplication application;
260 tet_infoline("UtcDaliBitmapImageGetBufferSize");
262 BitmapImage image = BitmapImage::WHITE(); // creates a 1x1 RGBA white pixel
263 application.SendNotification();
264 application.Render();
265 application.Render();
266 application.SendNotification();
268 Dali::ImageAttributes attributes = image.GetAttributes();
269 PixelBuffer* buffer = image.GetBuffer();
270 unsigned int bufferSize = image.GetBufferSize();
271 unsigned int pixelSize = Pixel::GetBytesPerPixel(attributes.GetPixelFormat());
273 DALI_TEST_CHECK( attributes.GetWidth() == 1 && // 1 pixel wide
274 buffer != NULL && // valid buffer
275 bufferSize == pixelSize); // r component is 255
279 int UtcDaliBitmapImageGetBufferStride(void)
281 TestApplication application;
283 tet_infoline("UtcDaliBitmapImageGetBufferStride");
285 BitmapImage image = BitmapImage::WHITE(); // creates a 1x1 RGBA white pixel
286 application.SendNotification();
287 application.Render();
288 application.Render();
289 application.SendNotification();
291 Dali::ImageAttributes attributes = image.GetAttributes();
292 unsigned int pixelSize = Pixel::GetBytesPerPixel(attributes.GetPixelFormat());
293 unsigned int bufferStride = image.GetBufferStride();
294 DALI_TEST_CHECK( bufferStride == pixelSize );
295 DALI_TEST_CHECK( !image.IsDataExternal() );
297 PixelBuffer* buffer = new PixelBuffer[20 * 16];
298 image = BitmapImage::New(buffer, 16, 16, Pixel::A8, 20);
299 application.SendNotification();
300 application.Render(16);
301 application.Render(16);
302 application.SendNotification();
304 bufferStride = image.GetBufferStride();
306 DALI_TEST_CHECK( bufferStride == 20);
307 DALI_TEST_CHECK( image.IsDataExternal() );
314 int UtcDaliBitmapImageIsDataExternal(void)
316 TestApplication application;
318 tet_infoline("UtcDaliBitmapImageIsDataExternal - BitmapImage::IsDataExternal()");
320 PixelBuffer* buffer = new PixelBuffer[16 * 16];
321 BitmapImage image = BitmapImage::New(buffer, 16, 16, Pixel::A8);
322 application.SendNotification();
323 application.Render();
324 application.Render();
325 application.SendNotification();
327 DALI_TEST_CHECK( image.IsDataExternal() );
334 static bool SignalReceived;
335 static void ImageUploaded(Image image)
337 tet_infoline("Received image uploaded signal");
338 SignalReceived = true;
342 int UtcDaliBitmapImageUpdate01(void)
344 TestApplication application;
346 tet_infoline("UtcDaliBitmapImageUpdate01 - single empty rect");
348 PixelBuffer* buffer = new PixelBuffer[16 * 16];
350 BitmapImage image = BitmapImage::New(buffer, 16, 16, Pixel::A8);
351 ImageActor actor = ImageActor::New(image);
352 Stage::GetCurrent().Add(actor);
353 actor.SetVisible(true);
355 SignalReceived = false;
356 image.UploadedSignal().Connect( ImageUploaded );
358 std::vector<GLuint> ids;
362 application.GetGlAbstraction().SetNextTextureIds(ids);
364 // Allow actor to be staged and rendered
365 application.SendNotification();
366 application.Render(0);
367 application.Render(16);
368 application.SendNotification();
369 application.Render(16);
370 application.SendNotification();
372 DALI_TEST_CHECK( image.IsDataExternal() );
373 application.GetGlAbstraction().EnableTextureCallTrace(true);
375 image.Update();//(RectArea()); // notify Core that the image has been updated
376 application.SendNotification();
377 application.Render(16);
378 application.Render(16);
379 application.SendNotification();
380 application.Render(16);
381 application.SendNotification();
383 const TraceCallStack& callStack = application.GetGlAbstraction().GetTextureTrace();
384 DALI_TEST_EQUALS( callStack.TestMethodAndParams(0, "TexSubImage2D", "0, 0, 16, 16"), true, TEST_LOCATION);
386 DALI_TEST_CHECK( SignalReceived == true );
387 SignalReceived = false;
391 int UtcDaliBitmapImageUpdate02(void)
393 TestApplication application;
395 tet_infoline("UtcDaliBitmapImageUpdate02 - Multiple rects");
397 PixelBuffer* buffer = new PixelBuffer[16 * 16];
398 BitmapImage image = BitmapImage::New(buffer, 16, 16, Pixel::A8);
399 ImageActor actor = ImageActor::New(image);
400 Stage::GetCurrent().Add(actor);
401 actor.SetVisible(true);
403 SignalReceived = false;
404 image.UploadedSignal().Connect( ImageUploaded );
406 std::vector<GLuint> ids;
410 application.GetGlAbstraction().SetNextTextureIds(ids);
412 application.SendNotification();
413 application.Render(0);
414 application.Render(16);
415 application.SendNotification();
416 application.Render(16);
417 application.SendNotification();
419 DALI_TEST_CHECK( image.IsDataExternal() );
420 application.GetGlAbstraction().EnableTextureCallTrace(true);
422 image.Update(RectArea(9,9,5,5)); // notify Core that the image has been updated
424 application.SendNotification();
425 application.Render(16);
426 application.Render(16);
427 application.SendNotification();
428 application.Render(16);
429 application.SendNotification();
431 const TraceCallStack& callStack = application.GetGlAbstraction().GetTextureTrace();
432 DALI_TEST_EQUALS( callStack.TestMethodAndParams(0, "TexSubImage2D", "9, 9, 5, 1"), true, TEST_LOCATION);
433 DALI_TEST_EQUALS( callStack.TestMethodAndParams(1, "TexSubImage2D", "9, 10, 5, 1"), true, TEST_LOCATION);
434 DALI_TEST_EQUALS( callStack.TestMethodAndParams(2, "TexSubImage2D", "9, 11, 5, 1"), true, TEST_LOCATION);
435 DALI_TEST_EQUALS( callStack.TestMethodAndParams(3, "TexSubImage2D", "9, 12, 5, 1"), true, TEST_LOCATION);
436 DALI_TEST_EQUALS( callStack.TestMethodAndParams(4, "TexSubImage2D", "9, 13, 5, 1"), true, TEST_LOCATION);
438 DALI_TEST_CHECK( SignalReceived == true );
439 SignalReceived = false;
443 int UtcDaliBitmapImageUploadedSignal01(void)
445 TestApplication application;
447 tet_infoline("UtcDaliBitmapImageUploadedSignal - Test that Uploaded signal is sent when image is staged");
449 PixelBuffer* buffer = new PixelBuffer[16 * 16];
450 BitmapImage image = BitmapImage::New(buffer, 16, 16, Pixel::A8);
451 SignalReceived = false;
452 image.UploadedSignal().Connect( ImageUploaded );
454 application.SendNotification();
455 application.Render(16);
456 application.Render(16);
457 application.SendNotification();
459 Dali::ImageActor imageActor = ImageActor::New(image);
460 Stage::GetCurrent().Add(imageActor);
461 application.SendNotification();
462 application.Render(16);
463 application.SendNotification();
464 application.Render(16);
465 application.SendNotification();
466 application.Render(16);
467 application.SendNotification();
469 DALI_TEST_CHECK( SignalReceived == true );
473 int UtcDaliBitmapImageUploadedSignal02(void)
475 TestApplication application;
477 tet_infoline("UtcDaliBitmapImageUploadedSignal - Test that Uploaded signal is sent after Update");
479 PixelBuffer* buffer = new PixelBuffer[16 * 16];
480 BitmapImage image = BitmapImage::New(buffer, 16, 16, Pixel::A8);
481 SignalReceived = false;
482 //ScopedConnection connection =
483 image.UploadedSignal().Connect( ImageUploaded );
485 application.SendNotification();
486 application.Render(16);
487 application.Render(16);
488 application.SendNotification();
490 Dali::ImageActor imageActor = ImageActor::New(image);
491 Stage::GetCurrent().Add(imageActor);
492 application.SendNotification();
493 application.Render(16);
494 application.SendNotification();
495 application.Render(16);
496 application.SendNotification();
497 application.Render(16);
498 application.SendNotification();
499 DALI_TEST_CHECK( SignalReceived == true );
500 SignalReceived = false;
502 image.Update(RectArea()); // notify Core that the whole image has been updated
503 application.SendNotification();
504 application.Render(16);
505 application.SendNotification();
506 application.Render(16);
507 application.SendNotification();
508 application.Render(16);
509 application.SendNotification();
510 DALI_TEST_CHECK( SignalReceived == true );