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.
20 #include <dali/public-api/dali-core.h>
21 #include <dali/integration-api/bitmap.h>
22 #include "dali-test-suite-utils/dali-test-suite-utils.h"
26 static const char* TestImageFilename = "icon_wrt.png";
28 void image_actor_test_startup(void)
30 test_return_value = TET_UNDEF;
33 void image_actor_test_cleanup(void)
35 test_return_value = TET_PASS;
39 int UtcDaliImageActorConstructorVoid(void)
41 TestApplication application;
42 tet_infoline("Testing Dali::ImageActor::ImageActor()");
46 DALI_TEST_CHECK(!actor);
50 int UtcDaliImageActorDestructor(void)
52 TestApplication application;
54 ImageActor* actor = new ImageActor();
57 DALI_TEST_CHECK( true );
61 int UtcDaliImageActorNew01(void)
63 TestApplication application;
64 tet_infoline("Positive test for Dali::ImageActor::New()");
66 Image image = ResourceImage::New(TestImageFilename);
67 ImageActor actor = ImageActor::New(image);
68 Stage::GetCurrent().Add(actor);
70 application.SendNotification();
73 application.SendNotification();
75 DALI_TEST_CHECK(application.GetPlatform().WasCalled(TestPlatformAbstraction::LoadResourceFunc));
77 DALI_TEST_CHECK(actor);
81 int UtcDaliImageActorNew02(void)
83 TestApplication application;
84 tet_infoline("Negative test for Dali::ImageActor::New()");
86 Image image = ResourceImage::New("hopefully-this-image-file-does-not-exist");
87 ImageActor actor = ImageActor::New(image);
89 DALI_TEST_CHECK(actor);
93 int UtcDaliImageActorDownCast(void)
95 TestApplication application;
96 tet_infoline("Testing Dali::ImageActor::DownCast()");
98 Image image = ResourceImage::New("IncorrectImageName");
99 ImageActor actor1 = ImageActor::New(image);
100 Actor anActor = Actor::New();
103 Actor child = anActor.GetChildAt(0);
104 ImageActor imageActor = DownCast< ImageActor >(child);
106 DALI_TEST_CHECK(imageActor);
110 int UtcDaliImageActorDownCast2(void)
112 TestApplication application;
113 tet_infoline("Testing Dali::ImageActor::DownCast()");
115 Actor actor1 = Actor::New();
116 Actor anActor = Actor::New();
119 Actor child = anActor.GetChildAt(0);
120 ImageActor imageActor = ImageActor::DownCast(child);
121 DALI_TEST_CHECK(!imageActor);
123 Actor unInitialzedActor;
124 imageActor = ImageActor::DownCast( unInitialzedActor );
125 DALI_TEST_CHECK(!imageActor);
129 int UtcDaliImageActorCopyConstructor(void)
131 TestApplication application;
132 tet_infoline("Testing Dali::ImageActor::ImageActor(const ImageActor& )");
134 Image image = ResourceImage::New("IncorrectImageName");
135 ImageActor actor1 = ImageActor::New(image);
137 ImageActor actor2(actor1);
138 DALI_TEST_CHECK(actor2);
139 DALI_TEST_EQUALS( actor2, actor1, TEST_LOCATION );
140 DALI_TEST_EQUALS( actor2.GetImage(), image, TEST_LOCATION );
145 int UtcDaliImageActor9Patch(void)
147 TestApplication application;
148 tet_infoline("Positive test for Dali::ImageActor:: 9 patch api");
150 Image image = ResourceImage::New(TestImageFilename);
151 ImageActor actor = ImageActor::New(image);
153 actor.SetStyle(ImageActor::STYLE_NINE_PATCH);
154 Vector4 border(0.1,0.2,0.3,0.4);
155 actor.SetNinePatchBorder(border);
157 DALI_TEST_EQUALS( 0.1f, actor.GetNinePatchBorder().x, TEST_LOCATION );
158 DALI_TEST_EQUALS( 0.2f, actor.GetNinePatchBorder().y, TEST_LOCATION );
159 DALI_TEST_EQUALS( 0.3f, actor.GetNinePatchBorder().z, TEST_LOCATION );
160 DALI_TEST_EQUALS( 0.4f, actor.GetNinePatchBorder().w, TEST_LOCATION );
164 int UtcDaliImageActorPixelArea(void)
166 TestApplication application;
167 tet_infoline("Positive test for Dali::ImageActor::UtcDaliImageActorPixelArea");
169 BufferImage img = BufferImage::New( 10, 10 );
170 ImageActor actor = ImageActor::New( img );
172 ImageActor::PixelArea area( 1, 2, 3, 4 );
173 actor.SetPixelArea( area );
175 DALI_TEST_EQUALS( 1, actor.GetPixelArea().x, TEST_LOCATION );
176 DALI_TEST_EQUALS( 2, actor.GetPixelArea().y, TEST_LOCATION );
177 DALI_TEST_EQUALS( 3, actor.GetPixelArea().width, TEST_LOCATION );
178 DALI_TEST_EQUALS( 4, actor.GetPixelArea().height, TEST_LOCATION );
180 ImageActor actor2 = ImageActor::New( img, ImageActor::PixelArea( 5, 6, 7, 8 ) );
182 DALI_TEST_EQUALS( 5, actor2.GetPixelArea().x, TEST_LOCATION );
183 DALI_TEST_EQUALS( 6, actor2.GetPixelArea().y, TEST_LOCATION );
184 DALI_TEST_EQUALS( 7, actor2.GetPixelArea().width, TEST_LOCATION );
185 DALI_TEST_EQUALS( 8, actor2.GetPixelArea().height, TEST_LOCATION );
189 // Set a size that is too large on an Image with a shader that requires grid
190 int UtcDaliImageActorSetSize01(void)
192 TestApplication application;
194 BufferImage img = BufferImage::New( 1,1 );
195 ImageActor actor = ImageActor::New( img );
197 ShaderEffect effect = ShaderEffect::New( " ", " ", GEOMETRY_TYPE_IMAGE, ShaderEffect::HINT_GRID );
198 actor.SetShaderEffect( effect );
200 const float INVALID_SIZE = float(1u<<31);
201 Vector3 vector( INVALID_SIZE, INVALID_SIZE, INVALID_SIZE );
203 DALI_TEST_CHECK(vector != actor.GetCurrentSize());
205 actor.SetSize(vector);
206 Stage::GetCurrent().Add(actor);
208 // flush the queue and render once
209 application.SendNotification();
210 application.Render();
212 DALI_TEST_EQUALS(vector, actor.GetCurrentSize(), TEST_LOCATION );
216 int UtcDaliImageActorGetCurrentSize01(void)
218 TestApplication application;
219 tet_infoline("Positive test for Dali::ImageActor::GetCurrentSize");
221 Vector2 initialImageSize(100, 50);
222 BufferImage image = BufferImage::New( initialImageSize.width, initialImageSize.height );
223 ImageActor actor = ImageActor::New( image );
224 Stage::GetCurrent().Add(actor);
226 application.SendNotification();
227 application.Render();
229 DALI_TEST_EQUALS( Vector2(actor.GetCurrentSize()), initialImageSize, TEST_LOCATION );
231 Vector2 size(200.0f, 200.0f);
234 // flush the queue and render once
235 application.SendNotification();
236 application.Render();
237 DALI_TEST_EQUALS( Vector2(actor.GetCurrentSize()), size, TEST_LOCATION );
242 application.Render(8);
244 // Test when a pixel area is set
245 ImageActor::PixelArea area(0, 0, 10, 10);
246 actor.SetPixelArea(area);
247 application.Render(9);
248 // natural size is not used as setsize is called
249 DALI_TEST_EQUALS( Vector2(actor.GetCurrentSize()), size, TEST_LOCATION );
255 int UtcDaliImageActorGetCurrentSize02(void)
257 TestApplication application;
258 tet_infoline("Positive test for Dali::ImageActor::GetCurrentSize - Test that using an image resource sets the actor size with it's natural size immediately rather than on load");
260 Vector2 initialImageSize(100, 50);
262 application.GetPlatform().SetClosestImageSize(initialImageSize);
264 Image image = ResourceImage::New("image.jpg");
265 ImageActor actor = ImageActor::New( image );
266 Stage::GetCurrent().Add(actor);
268 application.SendNotification(); // Flush update messages
269 application.Render(); // Process resource request
270 application.SendNotification(); // Flush update messages
271 application.Render(); // Process resource request
273 DALI_TEST_EQUALS( Vector2(actor.GetCurrentSize()), initialImageSize, TEST_LOCATION );
275 // Now complete the image load
276 Integration::ResourceRequest* req = application.GetPlatform().GetRequest();
277 Integration::Bitmap* bitmap = Integration::Bitmap::New( Integration::Bitmap::BITMAP_2D_PACKED_PIXELS, ResourcePolicy::RETAIN );
278 bitmap->GetPackedPixelsProfile()->ReserveBuffer( Pixel::RGBA8888, initialImageSize.width,initialImageSize.height, initialImageSize.width,initialImageSize.height );
280 Integration::ResourcePointer resourcePtr(bitmap); // reference it
281 application.GetPlatform().SetResourceLoaded(req->GetId(), req->GetType()->id, resourcePtr);
282 application.Render(); // Process LoadComplete
283 application.SendNotification(); // Process event messages
284 application.GetPlatform().DiscardRequest(); // Ensure load request is discarded
285 application.GetPlatform().ClearReadyResources(); //
287 DALI_TEST_EQUALS( Vector2(actor.GetCurrentSize()), initialImageSize, TEST_LOCATION );
289 Vector2 size(200.0f, 200.0f);
292 // flush the queue and render once
293 application.SendNotification();
294 application.Render();
295 DALI_TEST_EQUALS( Vector2(actor.GetCurrentSize()), size, TEST_LOCATION );
301 int UtcDaliImageActorGetCurrentSize03(void)
303 TestApplication application;
304 tet_infoline("Positive test for Dali::ImageActor::GetCurrentSize - Test that using an image resource with a requested size sets the actor size with it's nearest size immediately rather than on load");
306 const Vector2 closestImageSize( 80, 45);
307 application.GetPlatform().SetClosestImageSize(closestImageSize);
309 Vector2 requestedSize( 40, 30 );
310 Image image = ResourceImage::New("image.jpg", ImageDimensions( requestedSize.x, requestedSize.y ), FittingMode::DEFAULT, SamplingMode::DEFAULT );
311 ImageActor actor = ImageActor::New( image );
312 Stage::GetCurrent().Add(actor);
314 application.SendNotification(); // Flush update messages
315 application.Render(); // Process resource request
316 application.SendNotification(); // Flush update messages
317 application.Render(); // Process resource request
319 DALI_TEST_EQUALS( Vector2(actor.GetCurrentSize()), requestedSize, TEST_LOCATION );
321 // Now complete the image load
322 Integration::ResourceRequest* req = application.GetPlatform().GetRequest();
323 Integration::Bitmap* bitmap = Integration::Bitmap::New( Integration::Bitmap::BITMAP_2D_PACKED_PIXELS, ResourcePolicy::RETAIN );
324 bitmap->GetPackedPixelsProfile()->ReserveBuffer( Pixel::RGBA8888, closestImageSize.width, closestImageSize.height, closestImageSize.width, closestImageSize.height );
326 Integration::ResourcePointer resourcePtr(bitmap); // reference it
327 application.GetPlatform().SetResourceLoaded(req->GetId(), req->GetType()->id, resourcePtr);
328 application.Render(); // Process LoadComplete
329 application.SendNotification(); // Process event messages
330 application.GetPlatform().DiscardRequest(); // Ensure load request is discarded
331 application.GetPlatform().ClearReadyResources(); //
333 DALI_TEST_EQUALS( Vector2(actor.GetCurrentSize()), requestedSize, TEST_LOCATION );
339 int UtcDaliImageActorGetCurrentSize04(void)
341 TestApplication application;
342 tet_infoline("Positive test for Dali::ImageActor::GetCurrentSize - check a new image doesn't change a set actor size");
344 const Vector2 closestImageSize( 80, 45);
345 application.GetPlatform().SetClosestImageSize(closestImageSize);
347 Vector2 requestedSize( 40, 30 );
348 Image image = ResourceImage::New("image.jpg", ImageDimensions( requestedSize.x, requestedSize.y ), FittingMode::DEFAULT, SamplingMode::DEFAULT );
349 ImageActor actor = ImageActor::New( image );
350 Stage::GetCurrent().Add(actor);
352 application.SendNotification(); // Flush update messages
353 application.Render(); // Process resource request
355 DALI_TEST_EQUALS( Vector2(actor.GetCurrentSize()), requestedSize, TEST_LOCATION );
357 // Now complete the image load
358 Integration::ResourceRequest* req = application.GetPlatform().GetRequest();
359 Integration::Bitmap* bitmap = Integration::Bitmap::New( Integration::Bitmap::BITMAP_2D_PACKED_PIXELS, ResourcePolicy::RETAIN );
360 bitmap->GetPackedPixelsProfile()->ReserveBuffer( Pixel::RGBA8888, closestImageSize.width, closestImageSize.height, closestImageSize.width, closestImageSize.height );
362 Integration::ResourcePointer resourcePtr(bitmap); // reference it
363 application.GetPlatform().SetResourceLoaded(req->GetId(), req->GetType()->id, resourcePtr);
364 application.Render(); // Process LoadComplete
365 application.SendNotification(); // Process event messages
366 application.GetPlatform().DiscardRequest(); // Ensure load request is discarded
367 application.GetPlatform().ClearReadyResources(); //
369 DALI_TEST_EQUALS( Vector2(actor.GetCurrentSize()), requestedSize, TEST_LOCATION );
371 Vector2 size(200.0f, 200.0f);
374 // flush the queue and render once
375 application.SendNotification();
376 application.Render();
377 DALI_TEST_EQUALS( Vector2(actor.GetCurrentSize()), size, TEST_LOCATION );
379 // Load a different image
381 Vector2 image2ClosestSize = Vector2(240, 150); // The actual size image loader will return for the request below
382 application.GetPlatform().SetClosestImageSize(image2ClosestSize);
384 const Vector2 request2Size( 100, 100 );
385 Image image2 = ResourceImage::New("image.jpg", ImageDimensions( request2Size.x, request2Size.y ), FittingMode::DEFAULT, SamplingMode::DEFAULT );
386 actor.SetImage(image2);
388 application.SendNotification(); // Flush update messages
389 application.Render(); // Process resource request
390 application.SendNotification(); // Flush update messages
391 application.Render(); // Process resource request
393 // Ensure the actor size is kept
394 DALI_TEST_EQUALS( Vector2(actor.GetCurrentSize()), size, TEST_LOCATION );
396 // Now complete the image load
397 req = application.GetPlatform().GetRequest();
398 Integration::Bitmap* bitmap2 = Integration::Bitmap::New( Integration::Bitmap::BITMAP_2D_PACKED_PIXELS, ResourcePolicy::RETAIN );
399 bitmap2->GetPackedPixelsProfile()->ReserveBuffer( Pixel::RGBA8888, image2ClosestSize.width, image2ClosestSize.height, image2ClosestSize.width, image2ClosestSize.height );
401 Integration::ResourcePointer resourcePtr2(bitmap2); // reference it
402 application.GetPlatform().SetResourceLoaded(req->GetId(), req->GetType()->id, resourcePtr2);
403 application.Render(); // Process LoadComplete
404 application.SendNotification(); // Process event messages
405 application.GetPlatform().DiscardRequest(); // Ensure load request is discarded
406 application.GetPlatform().ClearReadyResources(); //
408 // Ensure the actor size is kept
409 DALI_TEST_EQUALS( Vector2(actor.GetCurrentSize()), size, TEST_LOCATION );
415 int UtcDaliImageActorGetCurrentSize05(void)
417 TestApplication application;
418 tet_infoline("Positive test for Dali::ImageActor::GetCurrentSize - check a new image doens't change actor size until load complete");
420 Vector2 closestImageSize( 80, 45);
421 application.GetPlatform().SetClosestImageSize(closestImageSize);
423 Vector2 requestedSize( 40, 30 );
424 Image image = ResourceImage::New("image.jpg", ImageDimensions( requestedSize.x, requestedSize.y ), FittingMode::DEFAULT, SamplingMode::DEFAULT );
425 ImageActor actor = ImageActor::New( image );
426 Stage::GetCurrent().Add(actor);
428 application.SendNotification(); // Flush update messages
429 application.Render(); // Process resource request
431 DALI_TEST_EQUALS( Vector2(actor.GetCurrentSize()), requestedSize, TEST_LOCATION );
433 // Now complete the image load
434 Integration::ResourceRequest* req = application.GetPlatform().GetRequest();
435 Integration::Bitmap* bitmap = Integration::Bitmap::New( Integration::Bitmap::BITMAP_2D_PACKED_PIXELS, ResourcePolicy::RETAIN );
436 bitmap->GetPackedPixelsProfile()->ReserveBuffer( Pixel::RGBA8888, closestImageSize.width, closestImageSize.height, closestImageSize.width, closestImageSize.height );
438 Integration::ResourcePointer resourcePtr(bitmap); // reference it
439 application.GetPlatform().SetResourceLoaded(req->GetId(), req->GetType()->id, resourcePtr);
440 application.Render(); // Process LoadComplete
441 application.SendNotification(); // Process event messages
442 application.GetPlatform().DiscardRequest(); // Ensure load request is discarded
443 application.GetPlatform().ClearReadyResources(); //
445 DALI_TEST_EQUALS( Vector2(actor.GetCurrentSize()), requestedSize, TEST_LOCATION );
447 // Load a different image
449 Vector2 image2ClosestSize = Vector2(240, 150);
450 application.GetPlatform().SetClosestImageSize(image2ClosestSize);
452 const Vector2 requestedSize2( 100, 100 );
453 Image image2 = ResourceImage::New("image.jpg", ImageDimensions( requestedSize2.x, requestedSize2.y ), FittingMode::DEFAULT, SamplingMode::DEFAULT );
454 actor.SetImage(image2);
456 application.SendNotification(); // Flush update messages
457 application.Render(); // Process resource request
458 application.SendNotification(); // Flush update messages
459 application.Render(); // Process resource request
461 // Ensure the actor size is kept
462 DALI_TEST_EQUALS( Vector2(actor.GetCurrentSize()), requestedSize2, TEST_LOCATION );
464 // Now complete the image load
465 req = application.GetPlatform().GetRequest();
466 Integration::Bitmap* bitmap2 = Integration::Bitmap::New( Integration::Bitmap::BITMAP_2D_PACKED_PIXELS, ResourcePolicy::RETAIN );
467 bitmap2->GetPackedPixelsProfile()->ReserveBuffer( Pixel::RGBA8888, image2ClosestSize.width, image2ClosestSize.height, image2ClosestSize.width, image2ClosestSize.height );
469 Integration::ResourcePointer resourcePtr2(bitmap2); // reference it
470 application.GetPlatform().SetResourceLoaded(req->GetId(), req->GetType()->id, resourcePtr2);
471 application.Render(); // Process LoadComplete
472 application.SendNotification(); // Process event messages
473 application.GetPlatform().DiscardRequest(); // Ensure load request is discarded
474 application.GetPlatform().ClearReadyResources(); //
476 application.SendNotification(); // Process event messages
477 application.Render(); // Process LoadComplete
479 // Ensure the actor size gets the new image's natural size
480 DALI_TEST_EQUALS( Vector2(actor.GetCurrentSize()), requestedSize2, TEST_LOCATION );
484 int UtcDaliImageActorNaturalPixelAreaSize01(void)
486 TestApplication application;
487 tet_infoline("Positive test for Dali::ImageActor::GetCurrentSize - check a new image doens't change actor size until load complete");
489 //If an image is loaded without setting size, then the actor gets the natural size of the image
490 //Setting the pixel area will change the actor size to match the pixel area
491 //Setting the actor size will not change pixel area, and will cause the partial image to stretch
493 //Clearing the pixel area will not change actor size, and the actor will show the whole image.
496 Vector2 closestImageSize( 80, 45);
497 application.GetPlatform().SetClosestImageSize(closestImageSize);
499 Vector2 requestedSize( 40, 30 );
500 Image image = ResourceImage::New("image.jpg", ImageDimensions( requestedSize.x, requestedSize.y ), FittingMode::DEFAULT, SamplingMode::DEFAULT );
501 ImageActor actor = ImageActor::New( image );
502 Stage::GetCurrent().Add(actor);
504 application.SendNotification(); // Flush update messages
505 application.Render(); // Process resource request
507 DALI_TEST_EQUALS( Vector2(actor.GetCurrentSize()), requestedSize, TEST_LOCATION );
509 // Now complete the image load
510 Integration::ResourceRequest* req = application.GetPlatform().GetRequest();
511 Integration::Bitmap* bitmap = Integration::Bitmap::New( Integration::Bitmap::BITMAP_2D_PACKED_PIXELS, ResourcePolicy::RETAIN );
512 bitmap->GetPackedPixelsProfile()->ReserveBuffer( Pixel::RGBA8888, closestImageSize.width, closestImageSize.height, closestImageSize.width, closestImageSize.height );
514 Integration::ResourcePointer resourcePtr(bitmap); // reference it
515 application.GetPlatform().SetResourceLoaded(req->GetId(), req->GetType()->id, resourcePtr);
516 application.Render(); // Process LoadComplete
517 application.SendNotification(); // Process event messages
518 application.GetPlatform().DiscardRequest(); // Ensure load request is discarded
519 application.GetPlatform().ClearReadyResources(); //
521 DALI_TEST_EQUALS( Vector2(actor.GetCurrentSize()), requestedSize, TEST_LOCATION );
523 // Set a pixel area on a naturally sized actor - expect the actor to take the
524 // pixel area as size
525 actor.SetPixelArea(ImageActor::PixelArea(0, 0, 30, 30));
526 application.SendNotification(); // Process event messages
527 application.Render(); // Process LoadComplete
528 DALI_TEST_EQUALS( Vector2(actor.GetCurrentSize()), Vector2(30, 30), TEST_LOCATION );
530 // Set a size. Expect the partial image to stretch to fill the new size
531 actor.SetSize(100, 100);
532 application.SendNotification(); // Process event messages
533 application.Render(); // Process LoadComplete
534 application.Render(); // Process LoadComplete
535 DALI_TEST_EQUALS( Vector2(actor.GetCurrentSize()), Vector2(100, 100), TEST_LOCATION );
537 // Clear the pixel area. Expect the whole image to be shown, filling the set size.
538 actor.SetPixelArea( ImageActor::PixelArea( 0, 0, image.GetWidth(), image.GetHeight()) );
539 application.SendNotification(); // Process event messages
540 application.Render(); // Process LoadComplete
541 DALI_TEST_EQUALS( Vector2(actor.GetCurrentSize()), Vector2(100, 100), TEST_LOCATION );
545 int UtcDaliImageActorNaturalPixelAreaSize02(void)
547 TestApplication application;
548 tet_infoline("Positive test for Dali::ImageActor::GetCurrentSize - check a new image doens't change actor size until load complete");
550 //If an image is loaded without setting size, then the actor gets the natural size of the image
551 //Setting the pixel area will change the actor size to match the pixel area
552 //Setting the actor size will not change pixel area, and will cause the partial image to stretch
554 //Clearing the pixel area will not change actor size, and the actor will show the whole image.
557 Vector2 closestImageSize( 80, 45);
558 application.GetPlatform().SetClosestImageSize(closestImageSize);
560 Vector2 requestedSize( 40, 30 );
561 Image image = ResourceImage::New("image.jpg", ImageDimensions( requestedSize.x, requestedSize.y ), FittingMode::DEFAULT, SamplingMode::DEFAULT );
562 ImageActor actor = ImageActor::New( image );
563 Stage::GetCurrent().Add(actor);
565 application.SendNotification(); // Flush update messages
566 application.Render(); // Process resource request
568 DALI_TEST_EQUALS( Vector2(actor.GetCurrentSize()), requestedSize, TEST_LOCATION );
570 // Now complete the image load
571 Integration::ResourceRequest* req = application.GetPlatform().GetRequest();
572 Integration::Bitmap* bitmap = Integration::Bitmap::New( Integration::Bitmap::BITMAP_2D_PACKED_PIXELS, ResourcePolicy::RETAIN );
573 bitmap->GetPackedPixelsProfile()->ReserveBuffer( Pixel::RGBA8888, closestImageSize.width, closestImageSize.height, closestImageSize.width, closestImageSize.height );
575 Integration::ResourcePointer resourcePtr(bitmap); // reference it
576 application.GetPlatform().SetResourceLoaded(req->GetId(), req->GetType()->id, resourcePtr);
577 application.Render(); // Process LoadComplete
578 application.SendNotification(); // Process event messages
579 application.GetPlatform().DiscardRequest(); // Ensure load request is discarded
580 application.GetPlatform().ClearReadyResources(); //
582 DALI_TEST_EQUALS( Vector2(actor.GetCurrentSize()), requestedSize, TEST_LOCATION );
584 // Set a pixel area on a naturally sized actor - expect the actor to take the
585 // pixel area as size
586 actor.SetPixelArea(ImageActor::PixelArea(0, 0, 30, 30));
587 application.SendNotification(); // Process event messages
588 application.Render(); // Process LoadComplete
589 DALI_TEST_EQUALS( Vector2(actor.GetCurrentSize()), Vector2(30, 30), TEST_LOCATION );
591 // Clear the pixel area. Expect the whole image to be shown, changing actor size
592 actor.SetPixelArea( ImageActor::PixelArea( 0, 0, image.GetWidth(), image.GetHeight()) );
593 application.SendNotification(); // Process event messages
594 application.Render(); // Process LoadComplete
595 DALI_TEST_EQUALS( Vector2(actor.GetCurrentSize()), requestedSize, TEST_LOCATION );
597 // Set a size. Expect the partial image to stretch to fill the new size
598 actor.SetSize(100, 100);
599 application.SendNotification(); // Process event messages
600 application.Render(); // Process LoadComplete
601 DALI_TEST_EQUALS( Vector2(actor.GetCurrentSize()), Vector2(100, 100), TEST_LOCATION );
603 // Set a pixel area, don't expect size to change
604 actor.SetPixelArea(ImageActor::PixelArea(0, 0, 40, 40));
605 application.SendNotification(); // Process event messages
606 application.Render(); // Process LoadComplete
607 DALI_TEST_EQUALS( Vector2(actor.GetCurrentSize()), Vector2(100, 100), TEST_LOCATION );
609 // Clearing pixel area should change actor size to image size
610 actor.SetResizePolicy( ResizePolicy::USE_NATURAL_SIZE, Dimension::ALL_DIMENSIONS );
611 actor.SetPixelArea( ImageActor::PixelArea( 0, 0, image.GetWidth(), image.GetHeight()) );
612 application.SendNotification(); // Process event messages
613 application.Render(); // Process LoadComplete
614 DALI_TEST_EQUALS( Vector2(actor.GetCurrentSize()), requestedSize, TEST_LOCATION );
620 int UtcDaliImageActorDefaultProperties(void)
622 TestApplication application;
623 tet_infoline("Testing Dali::ImageActor DefaultProperties");
625 BufferImage img = BufferImage::New( 10, 10 );
626 ImageActor actor = ImageActor::New( img );
628 std::vector<Property::Index> indices;
629 indices.push_back(ImageActor::Property::PIXEL_AREA );
630 indices.push_back(ImageActor::Property::STYLE );
631 indices.push_back(ImageActor::Property::BORDER );
632 indices.push_back(ImageActor::Property::IMAGE );
634 DALI_TEST_CHECK(actor.GetPropertyCount() == ( Actor::New().GetPropertyCount() + indices.size() ) );
636 for(std::vector<Property::Index>::iterator iter = indices.begin(); iter != indices.end(); ++iter)
638 DALI_TEST_CHECK( *iter == actor.GetPropertyIndex(actor.GetPropertyName(*iter)) );
639 DALI_TEST_CHECK( actor.IsPropertyWritable(*iter) );
640 DALI_TEST_CHECK( !actor.IsPropertyAnimatable(*iter) );
641 DALI_TEST_CHECK( actor.GetPropertyType(*iter) == actor.GetPropertyType(*iter) ); // just checking call succeeds
644 // set/get one of them
645 actor.SetPixelArea(ImageActor::PixelArea( 0, 0, 0, 0 ));
647 ImageActor::PixelArea area( 1, 2, 3, 4 );
648 actor.SetProperty(ImageActor::Property::PIXEL_AREA, Property::Value(Rect<int>(area)));
650 DALI_TEST_CHECK(Property::RECTANGLE == actor.GetPropertyType(ImageActor::Property::PIXEL_AREA));
652 Property::Value v = actor.GetProperty(ImageActor::Property::PIXEL_AREA);
654 DALI_TEST_CHECK(v.Get<Rect<int> >() == area);
659 int UtcDaliImageActorUseImageAlpha01(void)
661 TestApplication application;
663 tet_infoline("Testing Dali::RenderableActor::SetUseImageAlpha()");
665 BufferImage image = BufferImage::New( 100, 50 );
666 ImageActor actor = ImageActor::New( image );
667 actor.SetBlendMode( BlendingMode::ON );
668 actor.SetSize(100, 50);
669 application.GetGlAbstraction().EnableCullFaceCallTrace(true); // For Enable(GL_BLEND)
670 Stage::GetCurrent().Add(actor);
672 application.SendNotification();
673 application.Render();
675 const TraceCallStack& callTrace = application.GetGlAbstraction().GetCullFaceTrace();
676 DALI_TEST_EQUALS( BlendEnabled( callTrace), true, TEST_LOCATION );
677 DALI_TEST_EQUALS( BlendDisabled( callTrace ), false, TEST_LOCATION );
681 int UtcDaliImageActorUseImageAlpha02(void)
683 TestApplication application;
685 tet_infoline("Testing Dali::RenderableActor::SetUseImageAlpha()");
687 BufferImage image = BufferImage::New( 100, 50 );
688 ImageActor actor = ImageActor::New( image );
689 actor.SetBlendMode( BlendingMode::OFF );
690 actor.SetSize(100, 50);
691 application.GetGlAbstraction().EnableCullFaceCallTrace(true); // For Enable(GL_BLEND)
692 Stage::GetCurrent().Add(actor);
694 application.SendNotification();
695 application.Render();
697 const TraceCallStack& callTrace = application.GetGlAbstraction().GetCullFaceTrace();
698 DALI_TEST_EQUALS( BlendDisabled( callTrace ), false, TEST_LOCATION );
699 DALI_TEST_EQUALS( BlendEnabled( callTrace), false, TEST_LOCATION );
703 int UtcDaliImageActorUseImageAlpha03(void)
705 TestApplication application;
707 tet_infoline("Testing Dali::RenderableActor::SetUseImageAlpha()");
709 BufferImage image = BufferImage::New( 100, 50 );
710 ImageActor actor = ImageActor::New( image );
711 actor.SetBlendMode( BlendingMode::AUTO );
712 actor.SetColor(Vector4(1.0, 1.0, 1.0, 0.5));
713 actor.SetSize(100, 50);
714 application.GetGlAbstraction().EnableCullFaceCallTrace(true); // For Enable(GL_BLEND)
715 Stage::GetCurrent().Add(actor);
717 application.SendNotification();
718 application.Render();
720 const TraceCallStack& callTrace = application.GetGlAbstraction().GetCullFaceTrace();
721 DALI_TEST_EQUALS( BlendDisabled( callTrace ), false, TEST_LOCATION );
722 DALI_TEST_EQUALS( BlendEnabled( callTrace), true, TEST_LOCATION );
726 int UtcDaliImageActorUseImageAlpha04(void)
728 TestApplication application;
730 tet_infoline("Testing Dali::RenderableActor::SetUseImageAlpha()");
732 FrameBufferImage image = FrameBufferImage::New( 100, 50, Pixel::RGBA8888 );
733 RenderTaskList taskList = Stage::GetCurrent().GetRenderTaskList();
734 RenderTask task = taskList.GetTask( 0u );
735 task.SetTargetFrameBuffer( image ); // To ensure frame buffer is connected
736 application.GetGlAbstraction().SetCheckFramebufferStatusResult( GL_FRAMEBUFFER_COMPLETE );
737 application.SendNotification();
738 application.Render(0);
740 ImageActor actor = ImageActor::New( image );
741 application.SendNotification();
742 application.Render(0);
744 actor.SetBlendMode( BlendingMode::ON );
745 actor.SetColor(Vector4(1.0, 1.0, 1.0, 1.0));
746 actor.SetSize(100, 50);
747 application.GetGlAbstraction().EnableCullFaceCallTrace(true); // For Enable(GL_BLEND)
748 Stage::GetCurrent().Add(actor);
750 application.SendNotification();
751 application.Render();
753 const TraceCallStack& callTrace = application.GetGlAbstraction().GetCullFaceTrace();
754 DALI_TEST_EQUALS( BlendDisabled( callTrace ), false, TEST_LOCATION );
755 DALI_TEST_EQUALS( BlendEnabled( callTrace), true, TEST_LOCATION );
759 int UtcDaliImageActorUseImageAlpha05(void)
761 TestApplication application;
763 tet_infoline("Testing Dali::RenderableActor::SetUseImageAlpha()");
765 BufferImage image = BufferImage::New( 100, 50, Pixel::RGB888 );
766 ImageActor actor = ImageActor::New( image );
767 actor.SetBlendMode( BlendingMode::AUTO );
768 actor.SetColor(Vector4(1.0, 1.0, 1.0, 1.0));
769 actor.SetSize(100, 50);
770 application.GetGlAbstraction().EnableCullFaceCallTrace(true); // For Enable(GL_BLEND)
771 Stage::GetCurrent().Add(actor);
773 application.SendNotification();
774 application.Render();
776 const TraceCallStack& callTrace = application.GetGlAbstraction().GetCullFaceTrace();
777 DALI_TEST_EQUALS( BlendDisabled( callTrace ), false, TEST_LOCATION );
778 DALI_TEST_EQUALS( BlendEnabled( callTrace), false, TEST_LOCATION );
782 int UtcDaliImageGetStyle(void)
784 TestApplication application;
786 Image image = ResourceImage::New(TestImageFilename);
787 ImageActor actor = ImageActor::New(image);
789 actor.SetStyle(ImageActor::STYLE_NINE_PATCH);
791 // flush the queue and render once
792 application.SendNotification();
793 application.Render();
795 DALI_TEST_EQUALS( ImageActor::STYLE_NINE_PATCH, actor.GetStyle(), TEST_LOCATION );
799 int UtcDaliImageSetNinePatchBorder(void)
801 TestApplication application;
803 Image image = ResourceImage::New(TestImageFilename);
804 ImageActor actor = ImageActor::New(image);
806 actor.SetStyle(ImageActor::STYLE_NINE_PATCH);
807 actor.SetNinePatchBorder(Vector4( 1.0f, 2.0f, 3.0f, 4.0f));
809 DALI_TEST_EQUALS( 1.0f, actor.GetNinePatchBorder().x, TEST_LOCATION );
810 DALI_TEST_EQUALS( 2.0f, actor.GetNinePatchBorder().y, TEST_LOCATION );
811 DALI_TEST_EQUALS( 3.0f, actor.GetNinePatchBorder().z, TEST_LOCATION );
812 DALI_TEST_EQUALS( 4.0f, actor.GetNinePatchBorder().w, TEST_LOCATION );
816 int UtcDaliImageActorNewNull(void)
818 TestApplication application;
820 ImageActor actor = ImageActor::New(Image());
822 DALI_TEST_CHECK(actor);
826 int UtcDaliImageActorNewNullWithArea(void)
828 TestApplication application;
830 ImageActor::PixelArea area( 1, 2, 3, 4 );
832 ImageActor actor = ImageActor::New(Image(), area);
834 DALI_TEST_CHECK(actor);
838 int UtcDaliImageActorSetImage(void)
840 TestApplication application;
842 ImageActor actor = ImageActor::New(Image());
844 DALI_TEST_CHECK(actor);
846 actor.SetImage( Image() );
848 DALI_TEST_CHECK(!actor.GetImage());
852 int UtcDaliImageActorPropertyIndices(void)
854 TestApplication application;
855 Actor basicActor = Actor::New();
856 ImageActor imageActor = ImageActor::New();
858 Property::IndexContainer indices;
859 imageActor.GetPropertyIndices( indices );
860 DALI_TEST_CHECK( indices.Size() > basicActor.GetPropertyCount() );
861 DALI_TEST_EQUALS( indices.Size(), imageActor.GetPropertyCount(), TEST_LOCATION );
865 int UtcDaliImageActorImageProperty(void)
867 TestApplication application;
868 Image image = ResourceImage::New( "MY_PATH" );
869 ImageActor imageActor = ImageActor::New( image );
871 Stage::GetCurrent().Add( imageActor );
872 application.SendNotification();
873 application.Render();
875 Property::Value imageMap = imageActor.GetProperty( ImageActor::Property::IMAGE );
876 DALI_TEST_CHECK( imageMap.HasKey( "filename" ) );
877 DALI_TEST_EQUALS( imageMap.GetValue( "filename" ).Get< std::string >(), "MY_PATH", TEST_LOCATION );
881 int UtcDaliImageActorNinePatch01(void)
883 TestApplication application;
884 TestPlatformAbstraction& platform = application.GetPlatform();
885 TestGlAbstraction& glAbstraction = application.GetGlAbstraction();
886 TraceCallStack& textureTrace = glAbstraction.GetTextureTrace();
887 TraceCallStack& drawTrace = glAbstraction.GetDrawTrace();
889 tet_infoline("Test the successful loading of a nine-patch image\n");
891 platform.SetClosestImageSize(Vector2(4, 4));
892 Integration::Bitmap* bitmap = Integration::Bitmap::New( Integration::Bitmap::BITMAP_2D_PACKED_PIXELS, ResourcePolicy::RETAIN );
893 Integration::PixelBuffer* pixels = bitmap->GetPackedPixelsProfile()->ReserveBuffer( Pixel::RGBA8888, 4,4,4,4 );
894 memset( pixels, 0, 64 );
896 Integration::ResourcePointer resourcePtr(bitmap); // reference it
897 platform.SetResourceLoaded( 0, Dali::Integration::ResourceBitmap, resourcePtr );
899 Image ninePatchImage = ResourceImage::New( "blah.#.png" );
900 DALI_TEST_CHECK( ninePatchImage );
902 ImageActor imageActor = ImageActor::New( ninePatchImage );
903 DALI_TEST_CHECK( imageActor );
904 Stage::GetCurrent().Add( imageActor );
907 textureTrace.Reset();
908 drawTrace.Enable(true);
909 textureTrace.Enable(true);
910 glAbstraction.ClearBoundTextures();
911 std::vector<GLuint> ids;
913 glAbstraction.SetNextTextureIds( ids );
915 application.SendNotification();
916 application.Render();
918 DALI_TEST_CHECK( drawTrace.FindMethod( "DrawArrays" ) );
919 typedef std::vector<GLuint> TexVec;
920 const TexVec& textures = glAbstraction.GetBoundTextures(GL_TEXTURE0);
921 DALI_TEST_CHECK( textures.size() > 0 );
922 if( textures.size() > 0 )
924 DALI_TEST_EQUALS( textures[0], 23u, TEST_LOCATION );
931 int UtcDaliImageActorNinePatch02(void)
933 TestApplication application;
934 TestPlatformAbstraction& platform = application.GetPlatform();
935 TestGlAbstraction& glAbstraction = application.GetGlAbstraction();
936 TraceCallStack& textureTrace = glAbstraction.GetTextureTrace();
937 TraceCallStack& drawTrace = glAbstraction.GetDrawTrace();
939 tet_infoline("Test the failed loading of a nine-patch image\n");
941 platform.SetClosestImageSize(Vector2(0, 0));
942 Integration::ResourcePointer resourcePtr;
943 platform.SetResourceLoaded( 0, Dali::Integration::ResourceBitmap, resourcePtr );
945 Image ninePatchImage = ResourceImage::New( "blah.#.png" );
946 DALI_TEST_CHECK( ninePatchImage );
948 ImageActor imageActor = ImageActor::New( ninePatchImage );
949 DALI_TEST_CHECK( imageActor );
950 Stage::GetCurrent().Add( imageActor );
953 textureTrace.Reset();
954 drawTrace.Enable(true);
955 textureTrace.Enable(true);
956 glAbstraction.ClearBoundTextures();
957 std::vector<GLuint> ids;
959 glAbstraction.SetNextTextureIds( ids );
961 application.SendNotification();
962 application.Render();
964 // Check that nothing was drawn.
965 DALI_TEST_CHECK( ! drawTrace.FindMethod( "DrawArrays" ) );
966 typedef std::vector<GLuint> TexVec;
967 const TexVec& textures = glAbstraction.GetBoundTextures(GL_TEXTURE0);
968 DALI_TEST_CHECK( textures.size() == 0u );
974 int UtcDaliImageActorNinePatch03(void)
976 TestApplication application;
977 TestPlatformAbstraction& platform = application.GetPlatform();
978 TestGlAbstraction& glAbstraction = application.GetGlAbstraction();
979 TraceCallStack& textureTrace = glAbstraction.GetTextureTrace();
980 TraceCallStack& drawTrace = glAbstraction.GetDrawTrace();
982 tet_infoline("Test the successful loading of a nine-patch image added using ImageActor::SetImage()\n");
984 platform.SetClosestImageSize(Vector2(4, 4));
985 Integration::Bitmap* bitmap = Integration::Bitmap::New( Integration::Bitmap::BITMAP_2D_PACKED_PIXELS, ResourcePolicy::RETAIN );
986 Integration::PixelBuffer* pixels = bitmap->GetPackedPixelsProfile()->ReserveBuffer( Pixel::RGBA8888, 4,4,4,4 );
987 memset( pixels, 0, 64 );
989 Integration::ResourcePointer resourcePtr(bitmap); // reference it
990 platform.SetResourceLoaded( 0, Dali::Integration::ResourceBitmap, resourcePtr );
992 Image ninePatchImage = ResourceImage::New( "blah.#.png" );
993 DALI_TEST_CHECK( ninePatchImage );
995 ImageActor imageActor = ImageActor::New();
996 DALI_TEST_CHECK( imageActor );
997 Stage::GetCurrent().Add( imageActor );
999 imageActor.SetImage( ninePatchImage );
1002 textureTrace.Reset();
1003 drawTrace.Enable(true);
1004 textureTrace.Enable(true);
1005 glAbstraction.ClearBoundTextures();
1006 std::vector<GLuint> ids;
1007 ids.push_back( 23 );
1008 glAbstraction.SetNextTextureIds( ids );
1010 application.SendNotification();
1011 application.Render();
1013 DALI_TEST_CHECK( drawTrace.FindMethod( "DrawArrays" ) );
1014 typedef std::vector<GLuint> TexVec;
1015 const TexVec& textures = glAbstraction.GetBoundTextures(GL_TEXTURE0);
1016 DALI_TEST_CHECK( textures.size() > 0 );
1017 if( textures.size() > 0 )
1019 DALI_TEST_EQUALS( textures[0], 23u, TEST_LOCATION );
1026 int UtcDaliImageActorNinePatch04(void)
1028 TestApplication application;
1029 TestPlatformAbstraction& platform = application.GetPlatform();
1030 TestGlAbstraction& glAbstraction = application.GetGlAbstraction();
1031 TraceCallStack& textureTrace = glAbstraction.GetTextureTrace();
1032 TraceCallStack& drawTrace = glAbstraction.GetDrawTrace();
1034 tet_infoline("Test the failed loading of a nine-patch image using ImageActor::SetImage()\n");
1036 platform.SetClosestImageSize(Vector2(0, 0));
1037 Integration::ResourcePointer resourcePtr;
1038 platform.SetResourceLoaded( 0, Dali::Integration::ResourceBitmap, resourcePtr );
1040 Image ninePatchImage = ResourceImage::New( "blah.#.png" );
1041 DALI_TEST_CHECK( ninePatchImage );
1043 ImageActor imageActor = ImageActor::New();
1044 DALI_TEST_CHECK( imageActor );
1045 Stage::GetCurrent().Add( imageActor );
1047 imageActor.SetImage( ninePatchImage );
1050 textureTrace.Reset();
1051 drawTrace.Enable(true);
1052 textureTrace.Enable(true);
1053 glAbstraction.ClearBoundTextures();
1054 std::vector<GLuint> ids;
1055 ids.push_back( 23 );
1056 glAbstraction.SetNextTextureIds( ids );
1058 application.SendNotification();
1059 application.Render();
1061 // Check that nothing was drawn.
1062 DALI_TEST_CHECK( ! drawTrace.FindMethod( "DrawArrays" ) );
1063 typedef std::vector<GLuint> TexVec;
1064 const TexVec& textures = glAbstraction.GetBoundTextures(GL_TEXTURE0);
1065 DALI_TEST_CHECK( textures.size() == 0u );
1070 int UtcDaliImageActorGetNaturalSize(void)
1072 TestApplication application;
1075 BufferImage img = BufferImage::New( 10, 10 );
1076 ImageActor actor = ImageActor::New( img );
1078 DALI_TEST_CHECK( actor.GetNaturalSize().GetVectorXY() == Vector2( 10, 10 ) );
1081 ImageActor::PixelArea area( 1, 2, 3, 4 );
1082 actor.SetPixelArea( area );
1084 DALI_TEST_CHECK( actor.GetNaturalSize().GetVectorXY() == Vector2( 3, 4 ) );