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-test-suite-utils/dali-test-suite-utils.h"
25 static const char* TestImageFilename = "icon_wrt.png";
27 void image_actor_test_startup(void)
29 test_return_value = TET_UNDEF;
32 void image_actor_test_cleanup(void)
34 test_return_value = TET_PASS;
38 int UtcDaliImageActorConstructorVoid(void)
40 TestApplication application;
41 tet_infoline("Testing Dali::ImageActor::ImageActor()");
45 DALI_TEST_CHECK(!actor);
49 int UtcDaliImageActorDestructor(void)
51 TestApplication application;
53 ImageActor* actor = new ImageActor();
56 DALI_TEST_CHECK( true );
60 int UtcDaliImageActorNew01(void)
62 TestApplication application;
63 tet_infoline("Positive test for Dali::ImageActor::New()");
65 Image image = ResourceImage::New(TestImageFilename);
66 ImageActor actor = ImageActor::New(image);
67 Stage::GetCurrent().Add(actor);
69 application.SendNotification();
72 application.SendNotification();
74 DALI_TEST_CHECK(application.GetPlatform().WasCalled(TestPlatformAbstraction::LoadResourceFunc));
76 DALI_TEST_CHECK(actor);
80 int UtcDaliImageActorNew02(void)
82 TestApplication application;
83 tet_infoline("Negative test for Dali::ImageActor::New()");
85 Image image = ResourceImage::New("hopefully-this-image-file-does-not-exist");
86 ImageActor actor = ImageActor::New(image);
88 DALI_TEST_CHECK(actor);
92 int UtcDaliImageActorDownCast(void)
94 TestApplication application;
95 tet_infoline("Testing Dali::ImageActor::DownCast()");
97 Image image = ResourceImage::New("IncorrectImageName");
98 ImageActor actor1 = ImageActor::New(image);
99 Actor anActor = Actor::New();
102 Actor child = anActor.GetChildAt(0);
103 ImageActor imageActor = DownCast< ImageActor >(child);
105 DALI_TEST_CHECK(imageActor);
109 int UtcDaliImageActorDownCast2(void)
111 TestApplication application;
112 tet_infoline("Testing Dali::ImageActor::DownCast()");
114 Actor actor1 = Actor::New();
115 Actor anActor = Actor::New();
118 Actor child = anActor.GetChildAt(0);
119 ImageActor imageActor = ImageActor::DownCast(child);
120 DALI_TEST_CHECK(!imageActor);
122 Actor unInitialzedActor;
123 imageActor = ImageActor::DownCast( unInitialzedActor );
124 DALI_TEST_CHECK(!imageActor);
128 int UtcDaliImageActor9Patch(void)
130 TestApplication application;
131 tet_infoline("Positive test for Dali::ImageActor:: 9 patch api");
133 Image image = ResourceImage::New(TestImageFilename);
134 ImageActor actor = ImageActor::New(image);
136 actor.SetStyle(ImageActor::STYLE_NINE_PATCH);
137 Vector4 border(0.1,0.2,0.3,0.4);
138 actor.SetNinePatchBorder(border);
140 DALI_TEST_EQUALS( 0.1f, actor.GetNinePatchBorder().x, TEST_LOCATION );
141 DALI_TEST_EQUALS( 0.2f, actor.GetNinePatchBorder().y, TEST_LOCATION );
142 DALI_TEST_EQUALS( 0.3f, actor.GetNinePatchBorder().z, TEST_LOCATION );
143 DALI_TEST_EQUALS( 0.4f, actor.GetNinePatchBorder().w, TEST_LOCATION );
147 int UtcDaliImageActorPixelArea(void)
149 TestApplication application;
150 tet_infoline("Positive test for Dali::ImageActor::UtcDaliImageActorPixelArea");
152 BufferImage img = BufferImage::New( 10, 10 );
153 ImageActor actor = ImageActor::New( img );
155 DALI_TEST_CHECK( actor.IsPixelAreaSet() == false );
157 ImageActor::PixelArea area( 1, 2, 3, 4 );
158 actor.SetPixelArea( area );
160 DALI_TEST_CHECK( actor.IsPixelAreaSet() == true );
162 DALI_TEST_EQUALS( 1, actor.GetPixelArea().x, TEST_LOCATION );
163 DALI_TEST_EQUALS( 2, actor.GetPixelArea().y, TEST_LOCATION );
164 DALI_TEST_EQUALS( 3, actor.GetPixelArea().width, TEST_LOCATION );
165 DALI_TEST_EQUALS( 4, actor.GetPixelArea().height, TEST_LOCATION );
167 ImageActor actor2 = ImageActor::New( img, ImageActor::PixelArea( 5, 6, 7, 8 ) );
168 DALI_TEST_CHECK( actor2.IsPixelAreaSet() == true );
170 DALI_TEST_EQUALS( 5, actor2.GetPixelArea().x, TEST_LOCATION );
171 DALI_TEST_EQUALS( 6, actor2.GetPixelArea().y, TEST_LOCATION );
172 DALI_TEST_EQUALS( 7, actor2.GetPixelArea().width, TEST_LOCATION );
173 DALI_TEST_EQUALS( 8, actor2.GetPixelArea().height, TEST_LOCATION );
177 // Set a size that is too large on an Image with a shader that requires grid
178 int UtcDaliImageActorSetSize01(void)
180 TestApplication application;
182 BufferImage img = BufferImage::New( 1,1 );
183 ImageActor actor = ImageActor::New( img );
185 ShaderEffect effect = ShaderEffect::New( " ", " ", " ", " ", ShaderEffect::HINT_GRID );
186 actor.SetShaderEffect( effect );
188 const float INVALID_SIZE = float(1u<<31);
189 Vector3 vector( INVALID_SIZE, INVALID_SIZE, INVALID_SIZE );
191 DALI_TEST_CHECK(vector != actor.GetCurrentSize());
193 actor.SetSize(vector);
194 Stage::GetCurrent().Add(actor);
196 // flush the queue and render once
197 application.SendNotification();
198 application.Render();
200 DALI_TEST_EQUALS(vector, actor.GetCurrentSize(), TEST_LOCATION );
204 int UtcDaliImageActorGetCurrentSize01(void)
206 TestApplication application;
207 tet_infoline("Positive test for Dali::ImageActor::GetCurrentSize");
209 Vector2 initialImageSize(100, 50);
210 BufferImage image = BufferImage::New( initialImageSize.width, initialImageSize.height );
211 ImageActor actor = ImageActor::New( image );
212 Stage::GetCurrent().Add(actor);
214 application.SendNotification();
215 application.Render();
217 DALI_TEST_EQUALS( Vector2(actor.GetCurrentSize()), initialImageSize, TEST_LOCATION );
219 Vector2 size(200.0f, 200.0f);
222 // flush the queue and render once
223 application.SendNotification();
224 application.Render();
225 DALI_TEST_EQUALS( Vector2(actor.GetCurrentSize()), size, TEST_LOCATION );
230 application.Render(8);
232 // Test when a pixel area is set
233 ImageActor::PixelArea area(0, 0, 10, 10);
234 actor.SetPixelArea(area);
235 application.Render(9);
236 // natural size is not used as setsize is called
237 DALI_TEST_EQUALS( Vector2(actor.GetCurrentSize()), size, TEST_LOCATION );
239 actor.SetToNaturalSize();
240 application.SendNotification();
241 application.Render(9);
242 DALI_TEST_EQUALS( Vector2(actor.GetCurrentSize()), Vector2( area.width, area.height ), TEST_LOCATION );
248 int UtcDaliImageActorGetCurrentSize02(void)
250 TestApplication application;
251 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");
253 Vector2 initialImageSize(100, 50);
255 application.GetPlatform().SetClosestImageSize(initialImageSize);
257 Image image = ResourceImage::New("image.jpg");
258 ImageActor actor = ImageActor::New( image );
259 Stage::GetCurrent().Add(actor);
261 application.SendNotification(); // Flush update messages
262 application.Render(); // Process resource request
263 application.SendNotification(); // Flush update messages
264 application.Render(); // Process resource request
266 DALI_TEST_EQUALS( Vector2(actor.GetCurrentSize()), initialImageSize, TEST_LOCATION );
268 // Now complete the image load
269 Integration::ResourceRequest* req = application.GetPlatform().GetRequest();
270 Integration::Bitmap* bitmap = Integration::Bitmap::New( Integration::Bitmap::BITMAP_2D_PACKED_PIXELS, ResourcePolicy::RETAIN );
271 bitmap->GetPackedPixelsProfile()->ReserveBuffer( Pixel::RGBA8888, initialImageSize.width,initialImageSize.height, initialImageSize.width,initialImageSize.height );
273 Integration::ResourcePointer resourcePtr(bitmap); // reference it
274 application.GetPlatform().SetResourceLoaded(req->GetId(), req->GetType()->id, resourcePtr);
275 application.Render(); // Process LoadComplete
276 application.SendNotification(); // Process event messages
277 application.GetPlatform().DiscardRequest(); // Ensure load request is discarded
278 application.GetPlatform().ClearReadyResources(); //
280 DALI_TEST_EQUALS( Vector2(actor.GetCurrentSize()), initialImageSize, TEST_LOCATION );
282 Vector2 size(200.0f, 200.0f);
285 // flush the queue and render once
286 application.SendNotification();
287 application.Render();
288 DALI_TEST_EQUALS( Vector2(actor.GetCurrentSize()), size, TEST_LOCATION );
290 actor.SetToNaturalSize();
291 application.SendNotification();
292 application.Render();
293 DALI_TEST_EQUALS( Vector2(actor.GetCurrentSize()), initialImageSize, TEST_LOCATION );
298 int UtcDaliImageActorGetCurrentSize03(void)
300 TestApplication application;
301 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");
303 const Vector2 closestImageSize( 80, 45);
304 application.GetPlatform().SetClosestImageSize(closestImageSize);
306 ImageAttributes attrs;
307 const Vector2 requestedSize( 40, 30 );
308 attrs.SetSize( requestedSize.width, requestedSize.height );
309 Image image = ResourceImage::New("image.jpg", attrs);
310 ImageActor actor = ImageActor::New( image );
311 Stage::GetCurrent().Add(actor);
313 application.SendNotification(); // Flush update messages
314 application.Render(); // Process resource request
315 application.SendNotification(); // Flush update messages
316 application.Render(); // Process resource request
318 DALI_TEST_EQUALS( Vector2(actor.GetCurrentSize()), requestedSize, TEST_LOCATION );
320 // Now complete the image load
321 Integration::ResourceRequest* req = application.GetPlatform().GetRequest();
322 Integration::Bitmap* bitmap = Integration::Bitmap::New( Integration::Bitmap::BITMAP_2D_PACKED_PIXELS, ResourcePolicy::RETAIN );
323 bitmap->GetPackedPixelsProfile()->ReserveBuffer( Pixel::RGBA8888, closestImageSize.width, closestImageSize.height, closestImageSize.width, closestImageSize.height );
325 Integration::ResourcePointer resourcePtr(bitmap); // reference it
326 application.GetPlatform().SetResourceLoaded(req->GetId(), req->GetType()->id, resourcePtr);
327 application.Render(); // Process LoadComplete
328 application.SendNotification(); // Process event messages
329 application.GetPlatform().DiscardRequest(); // Ensure load request is discarded
330 application.GetPlatform().ClearReadyResources(); //
332 DALI_TEST_EQUALS( Vector2(actor.GetCurrentSize()), requestedSize, TEST_LOCATION );
334 // Test that setting a size on the actor can be 'undone' with SetNaturalSize()
335 Vector2 size(200.0f, 200.0f);
338 // flush the queue and render once
339 application.SendNotification();
340 application.Render();
341 DALI_TEST_EQUALS( Vector2(actor.GetCurrentSize()), size, TEST_LOCATION );
343 actor.SetToNaturalSize();
344 application.SendNotification();
345 application.Render();
346 DALI_TEST_EQUALS( Vector2(actor.GetCurrentSize()), requestedSize, TEST_LOCATION );
351 int UtcDaliImageActorGetCurrentSize04(void)
353 TestApplication application;
354 tet_infoline("Positive test for Dali::ImageActor::GetCurrentSize - check a new image doesn't change a set actor size");
356 const Vector2 closestImageSize( 80, 45);
357 application.GetPlatform().SetClosestImageSize(closestImageSize);
359 const Vector2 requestedSize( 40, 30 );
360 ImageAttributes attrs;
361 attrs.SetSize( requestedSize.width, requestedSize.height );
362 Image image = ResourceImage::New("image.jpg", attrs);
363 ImageActor actor = ImageActor::New( image );
364 Stage::GetCurrent().Add(actor);
366 application.SendNotification(); // Flush update messages
367 application.Render(); // Process resource request
369 DALI_TEST_EQUALS( Vector2(actor.GetCurrentSize()), requestedSize, TEST_LOCATION );
371 // Now complete the image load
372 Integration::ResourceRequest* req = application.GetPlatform().GetRequest();
373 Integration::Bitmap* bitmap = Integration::Bitmap::New( Integration::Bitmap::BITMAP_2D_PACKED_PIXELS, ResourcePolicy::RETAIN );
374 bitmap->GetPackedPixelsProfile()->ReserveBuffer( Pixel::RGBA8888, closestImageSize.width, closestImageSize.height, closestImageSize.width, closestImageSize.height );
376 Integration::ResourcePointer resourcePtr(bitmap); // reference it
377 application.GetPlatform().SetResourceLoaded(req->GetId(), req->GetType()->id, resourcePtr);
378 application.Render(); // Process LoadComplete
379 application.SendNotification(); // Process event messages
380 application.GetPlatform().DiscardRequest(); // Ensure load request is discarded
381 application.GetPlatform().ClearReadyResources(); //
383 DALI_TEST_EQUALS( Vector2(actor.GetCurrentSize()), requestedSize, TEST_LOCATION );
385 Vector2 size(200.0f, 200.0f);
388 // flush the queue and render once
389 application.SendNotification();
390 application.Render();
391 DALI_TEST_EQUALS( Vector2(actor.GetCurrentSize()), size, TEST_LOCATION );
393 // Load a different image
395 Vector2 image2ClosestSize = Vector2(240, 150); // The actual size image loader will return for the request below
396 application.GetPlatform().SetClosestImageSize(image2ClosestSize);
398 const Vector2 request2Size( 100, 100 );
399 attrs.SetSize( request2Size.width, request2Size.height );
400 Image image2 = ResourceImage::New("image2.jpg", attrs);
401 actor.SetImage(image2);
403 application.SendNotification(); // Flush update messages
404 application.Render(); // Process resource request
405 application.SendNotification(); // Flush update messages
406 application.Render(); // Process resource request
408 // Ensure the actor size is kept
409 DALI_TEST_EQUALS( Vector2(actor.GetCurrentSize()), size, TEST_LOCATION );
411 // Now complete the image load
412 req = application.GetPlatform().GetRequest();
413 Integration::Bitmap* bitmap2 = Integration::Bitmap::New( Integration::Bitmap::BITMAP_2D_PACKED_PIXELS, ResourcePolicy::RETAIN );
414 bitmap2->GetPackedPixelsProfile()->ReserveBuffer( Pixel::RGBA8888, image2ClosestSize.width, image2ClosestSize.height, image2ClosestSize.width, image2ClosestSize.height );
416 Integration::ResourcePointer resourcePtr2(bitmap2); // reference it
417 application.GetPlatform().SetResourceLoaded(req->GetId(), req->GetType()->id, resourcePtr2);
418 application.Render(); // Process LoadComplete
419 application.SendNotification(); // Process event messages
420 application.GetPlatform().DiscardRequest(); // Ensure load request is discarded
421 application.GetPlatform().ClearReadyResources(); //
423 // Ensure the actor size is kept
424 DALI_TEST_EQUALS( Vector2(actor.GetCurrentSize()), size, TEST_LOCATION );
426 actor.SetToNaturalSize();
427 application.SendNotification();
428 application.Render();
429 // Ensure the actor size gets the new image's natural size
430 DALI_TEST_EQUALS( Vector2(actor.GetCurrentSize()), request2Size, TEST_LOCATION );
435 int UtcDaliImageActorGetCurrentSize05(void)
437 TestApplication application;
438 tet_infoline("Positive test for Dali::ImageActor::GetCurrentSize - check a new image doens't change actor size until load complete");
440 Vector2 closestImageSize( 80, 45);
441 application.GetPlatform().SetClosestImageSize(closestImageSize);
443 ImageAttributes attrs;
444 const Vector2 requestedSize( 40, 30 );
445 attrs.SetSize( requestedSize.width, requestedSize.height );
446 Image image = ResourceImage::New("image.jpg", attrs);
447 ImageActor actor = ImageActor::New( image );
448 Stage::GetCurrent().Add(actor);
450 application.SendNotification(); // Flush update messages
451 application.Render(); // Process resource request
453 DALI_TEST_EQUALS( Vector2(actor.GetCurrentSize()), requestedSize, TEST_LOCATION );
455 // Now complete the image load
456 Integration::ResourceRequest* req = application.GetPlatform().GetRequest();
457 Integration::Bitmap* bitmap = Integration::Bitmap::New( Integration::Bitmap::BITMAP_2D_PACKED_PIXELS, ResourcePolicy::RETAIN );
458 bitmap->GetPackedPixelsProfile()->ReserveBuffer( Pixel::RGBA8888, closestImageSize.width, closestImageSize.height, closestImageSize.width, closestImageSize.height );
460 Integration::ResourcePointer resourcePtr(bitmap); // reference it
461 application.GetPlatform().SetResourceLoaded(req->GetId(), req->GetType()->id, resourcePtr);
462 application.Render(); // Process LoadComplete
463 application.SendNotification(); // Process event messages
464 application.GetPlatform().DiscardRequest(); // Ensure load request is discarded
465 application.GetPlatform().ClearReadyResources(); //
467 DALI_TEST_EQUALS( Vector2(actor.GetCurrentSize()), requestedSize, TEST_LOCATION );
469 // Load a different image
471 Vector2 image2ClosestSize = Vector2(240, 150);
472 application.GetPlatform().SetClosestImageSize(image2ClosestSize);
474 const Vector2 requestedSize2( 100, 100 );
475 attrs.SetSize( requestedSize2.width, requestedSize2.height );
476 Image image2 = ResourceImage::New("image2.jpg", attrs);
477 actor.SetImage(image2);
479 application.SendNotification(); // Flush update messages
480 application.Render(); // Process resource request
481 application.SendNotification(); // Flush update messages
482 application.Render(); // Process resource request
484 // Ensure the actor size is kept
485 DALI_TEST_EQUALS( Vector2(actor.GetCurrentSize()), requestedSize2, TEST_LOCATION );
487 // Now complete the image load
488 req = application.GetPlatform().GetRequest();
489 Integration::Bitmap* bitmap2 = Integration::Bitmap::New( Integration::Bitmap::BITMAP_2D_PACKED_PIXELS, ResourcePolicy::RETAIN );
490 bitmap2->GetPackedPixelsProfile()->ReserveBuffer( Pixel::RGBA8888, image2ClosestSize.width, image2ClosestSize.height, image2ClosestSize.width, image2ClosestSize.height );
492 Integration::ResourcePointer resourcePtr2(bitmap2); // reference it
493 application.GetPlatform().SetResourceLoaded(req->GetId(), req->GetType()->id, resourcePtr2);
494 application.Render(); // Process LoadComplete
495 application.SendNotification(); // Process event messages
496 application.GetPlatform().DiscardRequest(); // Ensure load request is discarded
497 application.GetPlatform().ClearReadyResources(); //
499 application.SendNotification(); // Process event messages
500 application.Render(); // Process LoadComplete
502 // Ensure the actor size gets the new image's natural size
503 DALI_TEST_EQUALS( Vector2(actor.GetCurrentSize()), requestedSize2, TEST_LOCATION );
507 int UtcDaliImageActorNaturalPixelAreaSize01(void)
509 TestApplication application;
510 tet_infoline("Positive test for Dali::ImageActor::GetCurrentSize - check a new image doens't change actor size until load complete");
512 //If an image is loaded without setting size, then the actor gets the natural size of the image
513 //Setting the pixel area will change the actor size to match the pixel area
514 //Setting the actor size will not change pixel area, and will cause the partial image to stretch
516 //Clearing the pixel area will not change actor size, and the actor will show the whole image.
519 Vector2 closestImageSize( 80, 45);
520 application.GetPlatform().SetClosestImageSize(closestImageSize);
522 ImageAttributes attrs;
523 const Vector2 requestedSize( 40, 30 );
524 attrs.SetSize( requestedSize.width, requestedSize.height );
525 Image image = ResourceImage::New("image.jpg", attrs);
526 ImageActor actor = ImageActor::New( image );
527 Stage::GetCurrent().Add(actor);
529 application.SendNotification(); // Flush update messages
530 application.Render(); // Process resource request
532 DALI_TEST_EQUALS( Vector2(actor.GetCurrentSize()), requestedSize, TEST_LOCATION );
534 // Now complete the image load
535 Integration::ResourceRequest* req = application.GetPlatform().GetRequest();
536 Integration::Bitmap* bitmap = Integration::Bitmap::New( Integration::Bitmap::BITMAP_2D_PACKED_PIXELS, ResourcePolicy::RETAIN );
537 bitmap->GetPackedPixelsProfile()->ReserveBuffer( Pixel::RGBA8888, closestImageSize.width, closestImageSize.height, closestImageSize.width, closestImageSize.height );
539 Integration::ResourcePointer resourcePtr(bitmap); // reference it
540 application.GetPlatform().SetResourceLoaded(req->GetId(), req->GetType()->id, resourcePtr);
541 application.Render(); // Process LoadComplete
542 application.SendNotification(); // Process event messages
543 application.GetPlatform().DiscardRequest(); // Ensure load request is discarded
544 application.GetPlatform().ClearReadyResources(); //
546 DALI_TEST_EQUALS( Vector2(actor.GetCurrentSize()), requestedSize, TEST_LOCATION );
548 // Set a pixel area on a naturally sized actor - expect the actor to take the
549 // pixel area as size
550 actor.SetPixelArea(ImageActor::PixelArea(0, 0, 30, 30));
551 application.SendNotification(); // Process event messages
552 application.Render(); // Process LoadComplete
553 DALI_TEST_EQUALS( Vector2(actor.GetCurrentSize()), Vector2(30, 30), TEST_LOCATION );
555 // Set a size. Expect the partial image to stretch to fill the new size
556 actor.SetSize(100, 100);
557 application.SendNotification(); // Process event messages
558 application.Render(); // Process LoadComplete
559 application.Render(); // Process LoadComplete
560 DALI_TEST_EQUALS( Vector2(actor.GetCurrentSize()), Vector2(100, 100), TEST_LOCATION );
562 // Clear the pixel area. Expect the whole image to be shown, filling the set size.
563 actor.ClearPixelArea();
564 application.SendNotification(); // Process event messages
565 application.Render(); // Process LoadComplete
566 DALI_TEST_EQUALS( Vector2(actor.GetCurrentSize()), Vector2(100, 100), TEST_LOCATION );
570 int UtcDaliImageActorNaturalPixelAreaSize02(void)
572 TestApplication application;
573 tet_infoline("Positive test for Dali::ImageActor::GetCurrentSize - check a new image doens't change actor size until load complete");
575 //If an image is loaded without setting size, then the actor gets the natural size of the image
576 //Setting the pixel area will change the actor size to match the pixel area
577 //Setting the actor size will not change pixel area, and will cause the partial image to stretch
579 //Clearing the pixel area will not change actor size, and the actor will show the whole image.
582 Vector2 closestImageSize( 80, 45);
583 application.GetPlatform().SetClosestImageSize(closestImageSize);
585 ImageAttributes attrs;
586 const Vector2 requestedSize( 40, 30 );
587 attrs.SetSize( requestedSize.width, requestedSize.height );
588 Image image = ResourceImage::New("image.jpg", attrs);
589 ImageActor actor = ImageActor::New( image );
590 Stage::GetCurrent().Add(actor);
592 application.SendNotification(); // Flush update messages
593 application.Render(); // Process resource request
595 DALI_TEST_EQUALS( Vector2(actor.GetCurrentSize()), requestedSize, TEST_LOCATION );
597 // Now complete the image load
598 Integration::ResourceRequest* req = application.GetPlatform().GetRequest();
599 Integration::Bitmap* bitmap = Integration::Bitmap::New( Integration::Bitmap::BITMAP_2D_PACKED_PIXELS, ResourcePolicy::RETAIN );
600 bitmap->GetPackedPixelsProfile()->ReserveBuffer( Pixel::RGBA8888, closestImageSize.width, closestImageSize.height, closestImageSize.width, closestImageSize.height );
602 Integration::ResourcePointer resourcePtr(bitmap); // reference it
603 application.GetPlatform().SetResourceLoaded(req->GetId(), req->GetType()->id, resourcePtr);
604 application.Render(); // Process LoadComplete
605 application.SendNotification(); // Process event messages
606 application.GetPlatform().DiscardRequest(); // Ensure load request is discarded
607 application.GetPlatform().ClearReadyResources(); //
609 DALI_TEST_EQUALS( Vector2(actor.GetCurrentSize()), requestedSize, TEST_LOCATION );
611 // Set a pixel area on a naturally sized actor - expect the actor to take the
612 // pixel area as size
613 actor.SetPixelArea(ImageActor::PixelArea(0, 0, 30, 30));
614 application.SendNotification(); // Process event messages
615 application.Render(); // Process LoadComplete
616 DALI_TEST_EQUALS( Vector2(actor.GetCurrentSize()), Vector2(30, 30), TEST_LOCATION );
618 // Clear the pixel area. Expect the whole image to be shown, changing actor size
619 actor.ClearPixelArea();
620 application.SendNotification(); // Process event messages
621 application.Render(); // Process LoadComplete
622 DALI_TEST_EQUALS( Vector2(actor.GetCurrentSize()), requestedSize, TEST_LOCATION );
624 // Set a size. Expect the partial image to stretch to fill the new size
625 actor.SetSize(100, 100);
626 application.SendNotification(); // Process event messages
627 application.Render(); // Process LoadComplete
628 DALI_TEST_EQUALS( Vector2(actor.GetCurrentSize()), Vector2(100, 100), TEST_LOCATION );
630 // Set a pixel area, don't expect size to change
631 actor.SetPixelArea(ImageActor::PixelArea(0, 0, 40, 40));
632 application.SendNotification(); // Process event messages
633 application.Render(); // Process LoadComplete
634 DALI_TEST_EQUALS( Vector2(actor.GetCurrentSize()), Vector2(100, 100), TEST_LOCATION );
636 // Use natural size - expect actor to change to pixel area
637 actor.SetToNaturalSize();
638 application.SendNotification(); // Process event messages
639 application.Render(); // Process LoadComplete
640 DALI_TEST_EQUALS( Vector2(actor.GetCurrentSize()), Vector2(40, 40), TEST_LOCATION );
642 // Clearing pixel area should change actor size to image size
643 actor.ClearPixelArea();
644 application.SendNotification(); // Process event messages
645 application.Render(); // Process LoadComplete
646 DALI_TEST_EQUALS( Vector2(actor.GetCurrentSize()), requestedSize, TEST_LOCATION );
652 int UtcDaliImageActorDefaultProperties(void)
654 TestApplication application;
655 tet_infoline("Testing Dali::ImageActor DefaultProperties");
657 BufferImage img = BufferImage::New( 10, 10 );
658 ImageActor actor = ImageActor::New( img );
660 std::vector<Property::Index> indices;
661 indices.push_back(ImageActor::PIXEL_AREA );
662 indices.push_back(ImageActor::STYLE );
663 indices.push_back(ImageActor::BORDER );
664 indices.push_back(ImageActor::IMAGE );
666 DALI_TEST_CHECK(actor.GetPropertyCount() == ( Actor::New().GetPropertyCount() + indices.size() ) );
668 for(std::vector<Property::Index>::iterator iter = indices.begin(); iter != indices.end(); ++iter)
670 DALI_TEST_CHECK( *iter == actor.GetPropertyIndex(actor.GetPropertyName(*iter)) );
671 DALI_TEST_CHECK( actor.IsPropertyWritable(*iter) );
672 DALI_TEST_CHECK( !actor.IsPropertyAnimatable(*iter) );
673 DALI_TEST_CHECK( actor.GetPropertyType(*iter) == actor.GetPropertyType(*iter) ); // just checking call succeeds
676 // set/get one of them
677 actor.SetPixelArea(ImageActor::PixelArea( 0, 0, 0, 0 ));
679 ImageActor::PixelArea area( 1, 2, 3, 4 );
680 actor.SetProperty(ImageActor::PIXEL_AREA, Property::Value(Rect<int>(area)));
682 DALI_TEST_CHECK(Property::RECTANGLE == actor.GetPropertyType(ImageActor::PIXEL_AREA));
684 Property::Value v = actor.GetProperty(ImageActor::PIXEL_AREA);
686 DALI_TEST_CHECK(v.Get<Rect<int> >() == area);
691 int UtcDaliImageActorUseImageAlpha01(void)
693 TestApplication application;
695 tet_infoline("Testing Dali::RenderableActor::SetUseImageAlpha()");
697 BufferImage image = BufferImage::New( 100, 50 );
698 ImageActor actor = ImageActor::New( image );
699 actor.SetBlendMode( BlendingMode::ON );
700 actor.SetSize(100, 50);
701 application.GetGlAbstraction().EnableCullFaceCallTrace(true); // For Enable(GL_BLEND)
702 Stage::GetCurrent().Add(actor);
704 application.SendNotification();
705 application.Render();
707 const TraceCallStack& callTrace = application.GetGlAbstraction().GetCullFaceTrace();
708 DALI_TEST_EQUALS( BlendEnabled( callTrace), true, TEST_LOCATION );
709 DALI_TEST_EQUALS( BlendDisabled( callTrace ), false, TEST_LOCATION );
713 int UtcDaliImageActorUseImageAlpha02(void)
715 TestApplication application;
717 tet_infoline("Testing Dali::RenderableActor::SetUseImageAlpha()");
719 BufferImage image = BufferImage::New( 100, 50 );
720 ImageActor actor = ImageActor::New( image );
721 actor.SetBlendMode( BlendingMode::OFF );
722 actor.SetSize(100, 50);
723 application.GetGlAbstraction().EnableCullFaceCallTrace(true); // For Enable(GL_BLEND)
724 Stage::GetCurrent().Add(actor);
726 application.SendNotification();
727 application.Render();
729 const TraceCallStack& callTrace = application.GetGlAbstraction().GetCullFaceTrace();
730 DALI_TEST_EQUALS( BlendDisabled( callTrace ), false, TEST_LOCATION );
731 DALI_TEST_EQUALS( BlendEnabled( callTrace), false, TEST_LOCATION );
735 int UtcDaliImageActorUseImageAlpha03(void)
737 TestApplication application;
739 tet_infoline("Testing Dali::RenderableActor::SetUseImageAlpha()");
741 BufferImage image = BufferImage::New( 100, 50 );
742 ImageActor actor = ImageActor::New( image );
743 actor.SetBlendMode( BlendingMode::AUTO );
744 actor.SetColor(Vector4(1.0, 1.0, 1.0, 0.5));
745 actor.SetSize(100, 50);
746 application.GetGlAbstraction().EnableCullFaceCallTrace(true); // For Enable(GL_BLEND)
747 Stage::GetCurrent().Add(actor);
749 application.SendNotification();
750 application.Render();
752 const TraceCallStack& callTrace = application.GetGlAbstraction().GetCullFaceTrace();
753 DALI_TEST_EQUALS( BlendDisabled( callTrace ), false, TEST_LOCATION );
754 DALI_TEST_EQUALS( BlendEnabled( callTrace), true, TEST_LOCATION );
758 int UtcDaliImageActorUseImageAlpha04(void)
760 TestApplication application;
762 tet_infoline("Testing Dali::RenderableActor::SetUseImageAlpha()");
764 FrameBufferImage image = FrameBufferImage::New( 100, 50, Pixel::RGBA8888 );
765 RenderTaskList taskList = Stage::GetCurrent().GetRenderTaskList();
766 RenderTask task = taskList.GetTask( 0u );
767 task.SetTargetFrameBuffer( image ); // To ensure frame buffer is connected
768 application.GetGlAbstraction().SetCheckFramebufferStatusResult( GL_FRAMEBUFFER_COMPLETE );
769 application.SendNotification();
770 application.Render(0);
772 ImageActor actor = ImageActor::New( image );
773 application.SendNotification();
774 application.Render(0);
776 actor.SetBlendMode( BlendingMode::ON );
777 actor.SetColor(Vector4(1.0, 1.0, 1.0, 1.0));
778 actor.SetSize(100, 50);
779 application.GetGlAbstraction().EnableCullFaceCallTrace(true); // For Enable(GL_BLEND)
780 Stage::GetCurrent().Add(actor);
782 application.SendNotification();
783 application.Render();
785 const TraceCallStack& callTrace = application.GetGlAbstraction().GetCullFaceTrace();
786 DALI_TEST_EQUALS( BlendDisabled( callTrace ), false, TEST_LOCATION );
787 DALI_TEST_EQUALS( BlendEnabled( callTrace), true, TEST_LOCATION );
791 int UtcDaliImageActorUseImageAlpha05(void)
793 TestApplication application;
795 tet_infoline("Testing Dali::RenderableActor::SetUseImageAlpha()");
797 BufferImage image = BufferImage::New( 100, 50, Pixel::RGB888 );
798 ImageActor actor = ImageActor::New( image );
799 actor.SetBlendMode( BlendingMode::AUTO );
800 actor.SetColor(Vector4(1.0, 1.0, 1.0, 1.0));
801 actor.SetSize(100, 50);
802 application.GetGlAbstraction().EnableCullFaceCallTrace(true); // For Enable(GL_BLEND)
803 Stage::GetCurrent().Add(actor);
805 application.SendNotification();
806 application.Render();
808 const TraceCallStack& callTrace = application.GetGlAbstraction().GetCullFaceTrace();
809 DALI_TEST_EQUALS( BlendDisabled( callTrace ), false, TEST_LOCATION );
810 DALI_TEST_EQUALS( BlendEnabled( callTrace), false, TEST_LOCATION );
814 int UtcDaliImageActorClearPixelArea(void)
816 TestApplication application;
818 BufferImage img = BufferImage::New( 10, 10 );
819 ImageActor actor = ImageActor::New( img );
821 DALI_TEST_CHECK( actor.IsPixelAreaSet() == false );
823 ImageActor::PixelArea area( 1, 2, 3, 4 );
824 actor.SetPixelArea( area );
826 DALI_TEST_CHECK( actor.IsPixelAreaSet() == true );
828 actor.ClearPixelArea();
830 DALI_TEST_CHECK( actor.IsPixelAreaSet() == false );
834 int UtcDaliImageGetStyle(void)
836 TestApplication application;
838 Image image = ResourceImage::New(TestImageFilename);
839 ImageActor actor = ImageActor::New(image);
841 actor.SetStyle(ImageActor::STYLE_NINE_PATCH);
843 // flush the queue and render once
844 application.SendNotification();
845 application.Render();
847 DALI_TEST_EQUALS( ImageActor::STYLE_NINE_PATCH, actor.GetStyle(), TEST_LOCATION );
851 int UtcDaliImageSetNinePatchBorder(void)
853 TestApplication application;
855 Image image = ResourceImage::New(TestImageFilename);
856 ImageActor actor = ImageActor::New(image);
858 actor.SetStyle(ImageActor::STYLE_NINE_PATCH);
859 actor.SetNinePatchBorder(Vector4( 1.0f, 2.0f, 3.0f, 4.0f));
861 DALI_TEST_EQUALS( 1.0f, actor.GetNinePatchBorder().x, TEST_LOCATION );
862 DALI_TEST_EQUALS( 2.0f, actor.GetNinePatchBorder().y, TEST_LOCATION );
863 DALI_TEST_EQUALS( 3.0f, actor.GetNinePatchBorder().z, TEST_LOCATION );
864 DALI_TEST_EQUALS( 4.0f, actor.GetNinePatchBorder().w, TEST_LOCATION );
868 int UtcDaliImageActorNewNull(void)
870 TestApplication application;
872 ImageActor actor = ImageActor::New(Image());
874 DALI_TEST_CHECK(actor);
878 int UtcDaliImageActorNewNullWithArea(void)
880 TestApplication application;
882 ImageActor::PixelArea area( 1, 2, 3, 4 );
884 ImageActor actor = ImageActor::New(Image(), area);
886 DALI_TEST_CHECK(actor);
890 int UtcDaliImageActorSetImage(void)
892 TestApplication application;
894 ImageActor actor = ImageActor::New(Image());
896 DALI_TEST_CHECK(actor);
898 actor.SetImage( Image() );
900 DALI_TEST_CHECK(!actor.GetImage());
904 int UtcDaliImageActorPropertyIndices(void)
906 TestApplication application;
907 Actor basicActor = Actor::New();
908 ImageActor imageActor = ImageActor::New();
910 Property::IndexContainer indices;
911 imageActor.GetPropertyIndices( indices );
912 DALI_TEST_CHECK( indices.size() > basicActor.GetPropertyCount() );
913 DALI_TEST_EQUALS( indices.size(), imageActor.GetPropertyCount(), TEST_LOCATION );
917 int UtcDaliImageActorImageProperty(void)
919 TestApplication application;
920 Image image = ResourceImage::New( "MY_PATH" );
921 ImageActor imageActor = ImageActor::New( image );
923 Stage::GetCurrent().Add( imageActor );
924 application.SendNotification();
925 application.Render();
927 Property::Value imageMap = imageActor.GetProperty( ImageActor::IMAGE );
928 DALI_TEST_CHECK( imageMap.HasKey( "filename" ) );
929 DALI_TEST_EQUALS( imageMap.GetValue( "filename" ).Get< std::string >(), "MY_PATH", TEST_LOCATION );
933 int UtcDaliImageActorNinePatch01(void)
935 TestApplication application;
936 TestPlatformAbstraction& platform = application.GetPlatform();
937 TestGlAbstraction& glAbstraction = application.GetGlAbstraction();
938 TraceCallStack& textureTrace = glAbstraction.GetTextureTrace();
939 TraceCallStack& drawTrace = glAbstraction.GetDrawTrace();
941 tet_infoline("Test the successful loading of a nine-patch image\n");
943 platform.SetClosestImageSize(Vector2(4, 4));
944 Integration::Bitmap* bitmap = Integration::Bitmap::New( Integration::Bitmap::BITMAP_2D_PACKED_PIXELS, ResourcePolicy::RETAIN );
945 Integration::PixelBuffer* pixels = bitmap->GetPackedPixelsProfile()->ReserveBuffer( Pixel::RGBA8888, 4,4,4,4 );
946 memset( pixels, 0, 64 );
948 Integration::ResourcePointer resourcePtr(bitmap); // reference it
949 platform.SetResourceLoaded( 0, Dali::Integration::ResourceBitmap, resourcePtr );
951 Image ninePatchImage = ResourceImage::New( "blah.#.png" );
952 DALI_TEST_CHECK( ninePatchImage );
954 ImageActor imageActor = ImageActor::New( ninePatchImage );
955 DALI_TEST_CHECK( imageActor );
956 Stage::GetCurrent().Add( imageActor );
959 textureTrace.Reset();
960 drawTrace.Enable(true);
961 textureTrace.Enable(true);
962 glAbstraction.ClearBoundTextures();
963 std::vector<GLuint> ids;
965 glAbstraction.SetNextTextureIds( ids );
967 application.SendNotification();
968 application.Render();
970 DALI_TEST_CHECK( drawTrace.FindMethod( "DrawArrays" ) );
971 typedef std::vector<GLuint> TexVec;
972 const TexVec& textures = glAbstraction.GetBoundTextures(GL_TEXTURE0);
973 DALI_TEST_CHECK( textures.size() > 0 );
974 if( textures.size() > 0 )
976 DALI_TEST_EQUALS( textures[0], 23u, TEST_LOCATION );
983 int UtcDaliImageActorNinePatch02(void)
985 TestApplication application;
986 TestPlatformAbstraction& platform = application.GetPlatform();
987 TestGlAbstraction& glAbstraction = application.GetGlAbstraction();
988 TraceCallStack& textureTrace = glAbstraction.GetTextureTrace();
989 TraceCallStack& drawTrace = glAbstraction.GetDrawTrace();
991 tet_infoline("Test the failed loading of a nine-patch image\n");
993 platform.SetClosestImageSize(Vector2(0, 0));
994 Integration::ResourcePointer resourcePtr;
995 platform.SetResourceLoaded( 0, Dali::Integration::ResourceBitmap, resourcePtr );
997 Image ninePatchImage = ResourceImage::New( "blah.#.png" );
998 DALI_TEST_CHECK( ninePatchImage );
1000 ImageActor imageActor = ImageActor::New( ninePatchImage );
1001 DALI_TEST_CHECK( imageActor );
1002 Stage::GetCurrent().Add( imageActor );
1005 textureTrace.Reset();
1006 drawTrace.Enable(true);
1007 textureTrace.Enable(true);
1008 glAbstraction.ClearBoundTextures();
1009 std::vector<GLuint> ids;
1010 ids.push_back( 23 );
1011 glAbstraction.SetNextTextureIds( ids );
1013 application.SendNotification();
1014 application.Render();
1016 // Check that nothing was drawn.
1017 DALI_TEST_CHECK( ! drawTrace.FindMethod( "DrawArrays" ) );
1018 typedef std::vector<GLuint> TexVec;
1019 const TexVec& textures = glAbstraction.GetBoundTextures(GL_TEXTURE0);
1020 DALI_TEST_CHECK( textures.size() == 0u );
1026 int UtcDaliImageActorNinePatch03(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 successful loading of a nine-patch image added using ImageActor::SetImage()\n");
1036 platform.SetClosestImageSize(Vector2(4, 4));
1037 Integration::Bitmap* bitmap = Integration::Bitmap::New( Integration::Bitmap::BITMAP_2D_PACKED_PIXELS, ResourcePolicy::RETAIN );
1038 Integration::PixelBuffer* pixels = bitmap->GetPackedPixelsProfile()->ReserveBuffer( Pixel::RGBA8888, 4,4,4,4 );
1039 memset( pixels, 0, 64 );
1041 Integration::ResourcePointer resourcePtr(bitmap); // reference it
1042 platform.SetResourceLoaded( 0, Dali::Integration::ResourceBitmap, resourcePtr );
1044 Image ninePatchImage = ResourceImage::New( "blah.#.png" );
1045 DALI_TEST_CHECK( ninePatchImage );
1047 ImageActor imageActor = ImageActor::New();
1048 DALI_TEST_CHECK( imageActor );
1049 Stage::GetCurrent().Add( imageActor );
1051 imageActor.SetImage( ninePatchImage );
1054 textureTrace.Reset();
1055 drawTrace.Enable(true);
1056 textureTrace.Enable(true);
1057 glAbstraction.ClearBoundTextures();
1058 std::vector<GLuint> ids;
1059 ids.push_back( 23 );
1060 glAbstraction.SetNextTextureIds( ids );
1062 application.SendNotification();
1063 application.Render();
1065 DALI_TEST_CHECK( drawTrace.FindMethod( "DrawArrays" ) );
1066 typedef std::vector<GLuint> TexVec;
1067 const TexVec& textures = glAbstraction.GetBoundTextures(GL_TEXTURE0);
1068 DALI_TEST_CHECK( textures.size() > 0 );
1069 if( textures.size() > 0 )
1071 DALI_TEST_EQUALS( textures[0], 23u, TEST_LOCATION );
1078 int UtcDaliImageActorNinePatch04(void)
1080 TestApplication application;
1081 TestPlatformAbstraction& platform = application.GetPlatform();
1082 TestGlAbstraction& glAbstraction = application.GetGlAbstraction();
1083 TraceCallStack& textureTrace = glAbstraction.GetTextureTrace();
1084 TraceCallStack& drawTrace = glAbstraction.GetDrawTrace();
1086 tet_infoline("Test the failed loading of a nine-patch image using ImageActor::SetImage()\n");
1088 platform.SetClosestImageSize(Vector2(0, 0));
1089 Integration::ResourcePointer resourcePtr;
1090 platform.SetResourceLoaded( 0, Dali::Integration::ResourceBitmap, resourcePtr );
1092 Image ninePatchImage = ResourceImage::New( "blah.#.png" );
1093 DALI_TEST_CHECK( ninePatchImage );
1095 ImageActor imageActor = ImageActor::New();
1096 DALI_TEST_CHECK( imageActor );
1097 Stage::GetCurrent().Add( imageActor );
1099 imageActor.SetImage( ninePatchImage );
1102 textureTrace.Reset();
1103 drawTrace.Enable(true);
1104 textureTrace.Enable(true);
1105 glAbstraction.ClearBoundTextures();
1106 std::vector<GLuint> ids;
1107 ids.push_back( 23 );
1108 glAbstraction.SetNextTextureIds( ids );
1110 application.SendNotification();
1111 application.Render();
1113 // Check that nothing was drawn.
1114 DALI_TEST_CHECK( ! drawTrace.FindMethod( "DrawArrays" ) );
1115 typedef std::vector<GLuint> TexVec;
1116 const TexVec& textures = glAbstraction.GetBoundTextures(GL_TEXTURE0);
1117 DALI_TEST_CHECK( textures.size() == 0u );
1122 int UtcDaliImageActorGetNaturalSize(void)
1124 TestApplication application;
1127 BufferImage img = BufferImage::New( 10, 10 );
1128 ImageActor actor = ImageActor::New( img );
1130 DALI_TEST_CHECK( actor.GetNaturalSize().GetVectorXY() == Vector2( 10, 10 ) );
1133 ImageActor::PixelArea area( 1, 2, 3, 4 );
1134 actor.SetPixelArea( area );
1136 DALI_TEST_CHECK( actor.GetNaturalSize().GetVectorXY() == Vector2( 3, 4 ) );