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 );
184 actor.SetRelayoutEnabled( false );
186 ShaderEffect effect = ShaderEffect::New( " ", " ", " ", " ", ShaderEffect::HINT_GRID );
187 actor.SetShaderEffect( effect );
189 const float INVALID_SIZE = float(1u<<31);
190 Vector3 vector( INVALID_SIZE, INVALID_SIZE, INVALID_SIZE );
192 DALI_TEST_CHECK(vector != actor.GetCurrentSize());
194 actor.SetSize(vector);
195 Stage::GetCurrent().Add(actor);
197 // flush the queue and render once
198 application.SendNotification();
199 application.Render();
201 DALI_TEST_EQUALS(vector, actor.GetCurrentSize(), TEST_LOCATION );
205 int UtcDaliImageActorGetCurrentSize01(void)
207 TestApplication application;
208 tet_infoline("Positive test for Dali::ImageActor::GetCurrentSize");
210 Vector2 initialImageSize(100, 50);
211 BufferImage image = BufferImage::New( initialImageSize.width, initialImageSize.height );
212 ImageActor actor = ImageActor::New( image );
213 actor.SetRelayoutEnabled( false );
214 Stage::GetCurrent().Add(actor);
216 application.SendNotification();
217 application.Render();
219 DALI_TEST_EQUALS( Vector2(actor.GetCurrentSize()), initialImageSize, TEST_LOCATION );
221 Vector2 size(200.0f, 200.0f);
224 // flush the queue and render once
225 application.SendNotification();
226 application.Render();
227 DALI_TEST_EQUALS( Vector2(actor.GetCurrentSize()), size, TEST_LOCATION );
232 application.Render(8);
234 // Test when a pixel area is set
235 ImageActor::PixelArea area(0, 0, 10, 10);
236 actor.SetPixelArea(area);
237 application.Render(9);
238 // natural size is not used as setsize is called
239 DALI_TEST_EQUALS( Vector2(actor.GetCurrentSize()), size, TEST_LOCATION );
241 actor.SetToNaturalSize();
242 application.SendNotification();
243 application.Render(9);
244 DALI_TEST_EQUALS( Vector2(actor.GetCurrentSize()), Vector2( area.width, area.height ), TEST_LOCATION );
250 int UtcDaliImageActorGetCurrentSize02(void)
252 TestApplication application;
253 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");
255 Vector2 initialImageSize(100, 50);
257 application.GetPlatform().SetClosestImageSize(initialImageSize);
259 Image image = ResourceImage::New("image.jpg");
260 ImageActor actor = ImageActor::New( image );
261 actor.SetRelayoutEnabled( false );
262 Stage::GetCurrent().Add(actor);
264 application.SendNotification(); // Flush update messages
265 application.Render(); // Process resource request
266 application.SendNotification(); // Flush update messages
267 application.Render(); // Process resource request
269 DALI_TEST_EQUALS( Vector2(actor.GetCurrentSize()), initialImageSize, TEST_LOCATION );
271 // Now complete the image load
272 Integration::ResourceRequest* req = application.GetPlatform().GetRequest();
273 Integration::Bitmap* bitmap = Integration::Bitmap::New( Integration::Bitmap::BITMAP_2D_PACKED_PIXELS, ResourcePolicy::RETAIN );
274 bitmap->GetPackedPixelsProfile()->ReserveBuffer( Pixel::RGBA8888, initialImageSize.width,initialImageSize.height, initialImageSize.width,initialImageSize.height );
276 Integration::ResourcePointer resourcePtr(bitmap); // reference it
277 application.GetPlatform().SetResourceLoaded(req->GetId(), req->GetType()->id, resourcePtr);
278 application.Render(); // Process LoadComplete
279 application.SendNotification(); // Process event messages
280 application.GetPlatform().DiscardRequest(); // Ensure load request is discarded
281 application.GetPlatform().ClearReadyResources(); //
283 DALI_TEST_EQUALS( Vector2(actor.GetCurrentSize()), initialImageSize, TEST_LOCATION );
285 Vector2 size(200.0f, 200.0f);
288 // flush the queue and render once
289 application.SendNotification();
290 application.Render();
291 DALI_TEST_EQUALS( Vector2(actor.GetCurrentSize()), size, TEST_LOCATION );
293 actor.SetToNaturalSize();
294 application.SendNotification();
295 application.Render();
296 DALI_TEST_EQUALS( Vector2(actor.GetCurrentSize()), initialImageSize, 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 ImageAttributes attrs;
310 const Vector2 requestedSize( 40, 30 );
311 attrs.SetSize( requestedSize.width, requestedSize.height );
312 Image image = ResourceImage::New("image.jpg", attrs);
313 ImageActor actor = ImageActor::New( image );
314 actor.SetRelayoutEnabled( false );
315 Stage::GetCurrent().Add(actor);
317 application.SendNotification(); // Flush update messages
318 application.Render(); // Process resource request
319 application.SendNotification(); // Flush update messages
320 application.Render(); // Process resource request
322 DALI_TEST_EQUALS( Vector2(actor.GetCurrentSize()), requestedSize, TEST_LOCATION );
324 // Now complete the image load
325 Integration::ResourceRequest* req = application.GetPlatform().GetRequest();
326 Integration::Bitmap* bitmap = Integration::Bitmap::New( Integration::Bitmap::BITMAP_2D_PACKED_PIXELS, ResourcePolicy::RETAIN );
327 bitmap->GetPackedPixelsProfile()->ReserveBuffer( Pixel::RGBA8888, closestImageSize.width, closestImageSize.height, closestImageSize.width, closestImageSize.height );
329 Integration::ResourcePointer resourcePtr(bitmap); // reference it
330 application.GetPlatform().SetResourceLoaded(req->GetId(), req->GetType()->id, resourcePtr);
331 application.Render(); // Process LoadComplete
332 application.SendNotification(); // Process event messages
333 application.GetPlatform().DiscardRequest(); // Ensure load request is discarded
334 application.GetPlatform().ClearReadyResources(); //
336 DALI_TEST_EQUALS( Vector2(actor.GetCurrentSize()), requestedSize, TEST_LOCATION );
338 // Test that setting a size on the actor can be 'undone' with SetNaturalSize()
339 Vector2 size(200.0f, 200.0f);
342 // flush the queue and render once
343 application.SendNotification();
344 application.Render();
345 DALI_TEST_EQUALS( Vector2(actor.GetCurrentSize()), size, TEST_LOCATION );
347 actor.SetToNaturalSize();
348 application.SendNotification();
349 application.Render();
350 DALI_TEST_EQUALS( Vector2(actor.GetCurrentSize()), requestedSize, TEST_LOCATION );
355 int UtcDaliImageActorGetCurrentSize04(void)
357 TestApplication application;
358 tet_infoline("Positive test for Dali::ImageActor::GetCurrentSize - check a new image doesn't change a set actor size");
360 const Vector2 closestImageSize( 80, 45);
361 application.GetPlatform().SetClosestImageSize(closestImageSize);
363 const Vector2 requestedSize( 40, 30 );
364 ImageAttributes attrs;
365 attrs.SetSize( requestedSize.width, requestedSize.height );
366 Image image = ResourceImage::New("image.jpg", attrs);
367 ImageActor actor = ImageActor::New( image );
368 actor.SetRelayoutEnabled( false );
369 Stage::GetCurrent().Add(actor);
371 application.SendNotification(); // Flush update messages
372 application.Render(); // Process resource request
374 DALI_TEST_EQUALS( Vector2(actor.GetCurrentSize()), requestedSize, TEST_LOCATION );
376 // Now complete the image load
377 Integration::ResourceRequest* req = application.GetPlatform().GetRequest();
378 Integration::Bitmap* bitmap = Integration::Bitmap::New( Integration::Bitmap::BITMAP_2D_PACKED_PIXELS, ResourcePolicy::RETAIN );
379 bitmap->GetPackedPixelsProfile()->ReserveBuffer( Pixel::RGBA8888, closestImageSize.width, closestImageSize.height, closestImageSize.width, closestImageSize.height );
381 Integration::ResourcePointer resourcePtr(bitmap); // reference it
382 application.GetPlatform().SetResourceLoaded(req->GetId(), req->GetType()->id, resourcePtr);
383 application.Render(); // Process LoadComplete
384 application.SendNotification(); // Process event messages
385 application.GetPlatform().DiscardRequest(); // Ensure load request is discarded
386 application.GetPlatform().ClearReadyResources(); //
388 DALI_TEST_EQUALS( Vector2(actor.GetCurrentSize()), requestedSize, TEST_LOCATION );
390 Vector2 size(200.0f, 200.0f);
393 // flush the queue and render once
394 application.SendNotification();
395 application.Render();
396 DALI_TEST_EQUALS( Vector2(actor.GetCurrentSize()), size, TEST_LOCATION );
398 // Load a different image
400 Vector2 image2ClosestSize = Vector2(240, 150); // The actual size image loader will return for the request below
401 application.GetPlatform().SetClosestImageSize(image2ClosestSize);
403 const Vector2 request2Size( 100, 100 );
404 attrs.SetSize( request2Size.width, request2Size.height );
405 Image image2 = ResourceImage::New("image2.jpg", attrs);
406 actor.SetImage(image2);
408 application.SendNotification(); // Flush update messages
409 application.Render(); // Process resource request
410 application.SendNotification(); // Flush update messages
411 application.Render(); // Process resource request
413 // Ensure the actor size is kept
414 DALI_TEST_EQUALS( Vector2(actor.GetCurrentSize()), size, TEST_LOCATION );
416 // Now complete the image load
417 req = application.GetPlatform().GetRequest();
418 Integration::Bitmap* bitmap2 = Integration::Bitmap::New( Integration::Bitmap::BITMAP_2D_PACKED_PIXELS, ResourcePolicy::RETAIN );
419 bitmap2->GetPackedPixelsProfile()->ReserveBuffer( Pixel::RGBA8888, image2ClosestSize.width, image2ClosestSize.height, image2ClosestSize.width, image2ClosestSize.height );
421 Integration::ResourcePointer resourcePtr2(bitmap2); // reference it
422 application.GetPlatform().SetResourceLoaded(req->GetId(), req->GetType()->id, resourcePtr2);
423 application.Render(); // Process LoadComplete
424 application.SendNotification(); // Process event messages
425 application.GetPlatform().DiscardRequest(); // Ensure load request is discarded
426 application.GetPlatform().ClearReadyResources(); //
428 // Ensure the actor size is kept
429 DALI_TEST_EQUALS( Vector2(actor.GetCurrentSize()), size, TEST_LOCATION );
431 actor.SetToNaturalSize();
432 application.SendNotification();
433 application.Render();
434 // Ensure the actor size gets the new image's natural size
435 DALI_TEST_EQUALS( Vector2(actor.GetCurrentSize()), request2Size, TEST_LOCATION );
440 int UtcDaliImageActorGetCurrentSize05(void)
442 TestApplication application;
443 tet_infoline("Positive test for Dali::ImageActor::GetCurrentSize - check a new image doens't change actor size until load complete");
445 Vector2 closestImageSize( 80, 45);
446 application.GetPlatform().SetClosestImageSize(closestImageSize);
448 ImageAttributes attrs;
449 const Vector2 requestedSize( 40, 30 );
450 attrs.SetSize( requestedSize.width, requestedSize.height );
451 Image image = ResourceImage::New("image.jpg", attrs);
452 ImageActor actor = ImageActor::New( image );
453 actor.SetRelayoutEnabled( false );
454 Stage::GetCurrent().Add(actor);
456 application.SendNotification(); // Flush update messages
457 application.Render(); // Process resource request
459 DALI_TEST_EQUALS( Vector2(actor.GetCurrentSize()), requestedSize, TEST_LOCATION );
461 // Now complete the image load
462 Integration::ResourceRequest* req = application.GetPlatform().GetRequest();
463 Integration::Bitmap* bitmap = Integration::Bitmap::New( Integration::Bitmap::BITMAP_2D_PACKED_PIXELS, ResourcePolicy::RETAIN );
464 bitmap->GetPackedPixelsProfile()->ReserveBuffer( Pixel::RGBA8888, closestImageSize.width, closestImageSize.height, closestImageSize.width, closestImageSize.height );
466 Integration::ResourcePointer resourcePtr(bitmap); // reference it
467 application.GetPlatform().SetResourceLoaded(req->GetId(), req->GetType()->id, resourcePtr);
468 application.Render(); // Process LoadComplete
469 application.SendNotification(); // Process event messages
470 application.GetPlatform().DiscardRequest(); // Ensure load request is discarded
471 application.GetPlatform().ClearReadyResources(); //
473 DALI_TEST_EQUALS( Vector2(actor.GetCurrentSize()), requestedSize, TEST_LOCATION );
475 // Load a different image
477 Vector2 image2ClosestSize = Vector2(240, 150);
478 application.GetPlatform().SetClosestImageSize(image2ClosestSize);
480 const Vector2 requestedSize2( 100, 100 );
481 attrs.SetSize( requestedSize2.width, requestedSize2.height );
482 Image image2 = ResourceImage::New("image2.jpg", attrs);
483 actor.SetImage(image2);
485 application.SendNotification(); // Flush update messages
486 application.Render(); // Process resource request
487 application.SendNotification(); // Flush update messages
488 application.Render(); // Process resource request
490 // Ensure the actor size is kept
491 DALI_TEST_EQUALS( Vector2(actor.GetCurrentSize()), requestedSize2, TEST_LOCATION );
493 // Now complete the image load
494 req = application.GetPlatform().GetRequest();
495 Integration::Bitmap* bitmap2 = Integration::Bitmap::New( Integration::Bitmap::BITMAP_2D_PACKED_PIXELS, ResourcePolicy::RETAIN );
496 bitmap2->GetPackedPixelsProfile()->ReserveBuffer( Pixel::RGBA8888, image2ClosestSize.width, image2ClosestSize.height, image2ClosestSize.width, image2ClosestSize.height );
498 Integration::ResourcePointer resourcePtr2(bitmap2); // reference it
499 application.GetPlatform().SetResourceLoaded(req->GetId(), req->GetType()->id, resourcePtr2);
500 application.Render(); // Process LoadComplete
501 application.SendNotification(); // Process event messages
502 application.GetPlatform().DiscardRequest(); // Ensure load request is discarded
503 application.GetPlatform().ClearReadyResources(); //
505 application.SendNotification(); // Process event messages
506 application.Render(); // Process LoadComplete
508 // Ensure the actor size gets the new image's natural size
509 DALI_TEST_EQUALS( Vector2(actor.GetCurrentSize()), requestedSize2, TEST_LOCATION );
513 int UtcDaliImageActorNaturalPixelAreaSize01(void)
515 TestApplication application;
516 tet_infoline("Positive test for Dali::ImageActor::GetCurrentSize - check a new image doens't change actor size until load complete");
518 //If an image is loaded without setting size, then the actor gets the natural size of the image
519 //Setting the pixel area will change the actor size to match the pixel area
520 //Setting the actor size will not change pixel area, and will cause the partial image to stretch
522 //Clearing the pixel area will not change actor size, and the actor will show the whole image.
525 Vector2 closestImageSize( 80, 45);
526 application.GetPlatform().SetClosestImageSize(closestImageSize);
528 ImageAttributes attrs;
529 const Vector2 requestedSize( 40, 30 );
530 attrs.SetSize( requestedSize.width, requestedSize.height );
531 Image image = ResourceImage::New("image.jpg", attrs);
532 ImageActor actor = ImageActor::New( image );
533 actor.SetRelayoutEnabled( false );
534 Stage::GetCurrent().Add(actor);
536 application.SendNotification(); // Flush update messages
537 application.Render(); // Process resource request
539 DALI_TEST_EQUALS( Vector2(actor.GetCurrentSize()), requestedSize, TEST_LOCATION );
541 // Now complete the image load
542 Integration::ResourceRequest* req = application.GetPlatform().GetRequest();
543 Integration::Bitmap* bitmap = Integration::Bitmap::New( Integration::Bitmap::BITMAP_2D_PACKED_PIXELS, ResourcePolicy::RETAIN );
544 bitmap->GetPackedPixelsProfile()->ReserveBuffer( Pixel::RGBA8888, closestImageSize.width, closestImageSize.height, closestImageSize.width, closestImageSize.height );
546 Integration::ResourcePointer resourcePtr(bitmap); // reference it
547 application.GetPlatform().SetResourceLoaded(req->GetId(), req->GetType()->id, resourcePtr);
548 application.Render(); // Process LoadComplete
549 application.SendNotification(); // Process event messages
550 application.GetPlatform().DiscardRequest(); // Ensure load request is discarded
551 application.GetPlatform().ClearReadyResources(); //
553 DALI_TEST_EQUALS( Vector2(actor.GetCurrentSize()), requestedSize, TEST_LOCATION );
555 // Set a pixel area on a naturally sized actor - expect the actor to take the
556 // pixel area as size
557 actor.SetPixelArea(ImageActor::PixelArea(0, 0, 30, 30));
558 application.SendNotification(); // Process event messages
559 application.Render(); // Process LoadComplete
560 DALI_TEST_EQUALS( Vector2(actor.GetCurrentSize()), Vector2(30, 30), TEST_LOCATION );
562 // Set a size. Expect the partial image to stretch to fill the new size
563 actor.SetSize(100, 100);
564 application.SendNotification(); // Process event messages
565 application.Render(); // Process LoadComplete
566 application.Render(); // Process LoadComplete
567 DALI_TEST_EQUALS( Vector2(actor.GetCurrentSize()), Vector2(100, 100), TEST_LOCATION );
569 // Clear the pixel area. Expect the whole image to be shown, filling the set size.
570 actor.ClearPixelArea();
571 application.SendNotification(); // Process event messages
572 application.Render(); // Process LoadComplete
573 DALI_TEST_EQUALS( Vector2(actor.GetCurrentSize()), Vector2(100, 100), TEST_LOCATION );
577 int UtcDaliImageActorNaturalPixelAreaSize02(void)
579 TestApplication application;
580 tet_infoline("Positive test for Dali::ImageActor::GetCurrentSize - check a new image doens't change actor size until load complete");
582 //If an image is loaded without setting size, then the actor gets the natural size of the image
583 //Setting the pixel area will change the actor size to match the pixel area
584 //Setting the actor size will not change pixel area, and will cause the partial image to stretch
586 //Clearing the pixel area will not change actor size, and the actor will show the whole image.
589 Vector2 closestImageSize( 80, 45);
590 application.GetPlatform().SetClosestImageSize(closestImageSize);
592 ImageAttributes attrs;
593 const Vector2 requestedSize( 40, 30 );
594 attrs.SetSize( requestedSize.width, requestedSize.height );
595 Image image = ResourceImage::New("image.jpg", attrs);
596 ImageActor actor = ImageActor::New( image );
597 actor.SetRelayoutEnabled( false );
598 Stage::GetCurrent().Add(actor);
600 application.SendNotification(); // Flush update messages
601 application.Render(); // Process resource request
603 DALI_TEST_EQUALS( Vector2(actor.GetCurrentSize()), requestedSize, TEST_LOCATION );
605 // Now complete the image load
606 Integration::ResourceRequest* req = application.GetPlatform().GetRequest();
607 Integration::Bitmap* bitmap = Integration::Bitmap::New( Integration::Bitmap::BITMAP_2D_PACKED_PIXELS, ResourcePolicy::RETAIN );
608 bitmap->GetPackedPixelsProfile()->ReserveBuffer( Pixel::RGBA8888, closestImageSize.width, closestImageSize.height, closestImageSize.width, closestImageSize.height );
610 Integration::ResourcePointer resourcePtr(bitmap); // reference it
611 application.GetPlatform().SetResourceLoaded(req->GetId(), req->GetType()->id, resourcePtr);
612 application.Render(); // Process LoadComplete
613 application.SendNotification(); // Process event messages
614 application.GetPlatform().DiscardRequest(); // Ensure load request is discarded
615 application.GetPlatform().ClearReadyResources(); //
617 DALI_TEST_EQUALS( Vector2(actor.GetCurrentSize()), requestedSize, TEST_LOCATION );
619 // Set a pixel area on a naturally sized actor - expect the actor to take the
620 // pixel area as size
621 actor.SetPixelArea(ImageActor::PixelArea(0, 0, 30, 30));
622 application.SendNotification(); // Process event messages
623 application.Render(); // Process LoadComplete
624 DALI_TEST_EQUALS( Vector2(actor.GetCurrentSize()), Vector2(30, 30), TEST_LOCATION );
626 // Clear the pixel area. Expect the whole image to be shown, changing actor size
627 actor.ClearPixelArea();
628 application.SendNotification(); // Process event messages
629 application.Render(); // Process LoadComplete
630 DALI_TEST_EQUALS( Vector2(actor.GetCurrentSize()), requestedSize, TEST_LOCATION );
632 // Set a size. Expect the partial image to stretch to fill the new size
633 actor.SetSize(100, 100);
634 application.SendNotification(); // Process event messages
635 application.Render(); // Process LoadComplete
636 DALI_TEST_EQUALS( Vector2(actor.GetCurrentSize()), Vector2(100, 100), TEST_LOCATION );
638 // Set a pixel area, don't expect size to change
639 actor.SetPixelArea(ImageActor::PixelArea(0, 0, 40, 40));
640 application.SendNotification(); // Process event messages
641 application.Render(); // Process LoadComplete
642 DALI_TEST_EQUALS( Vector2(actor.GetCurrentSize()), Vector2(100, 100), TEST_LOCATION );
644 // Use natural size - expect actor to change to pixel area
645 actor.SetToNaturalSize();
646 application.SendNotification(); // Process event messages
647 application.Render(); // Process LoadComplete
648 DALI_TEST_EQUALS( Vector2(actor.GetCurrentSize()), Vector2(40, 40), TEST_LOCATION );
650 // Clearing pixel area should change actor size to image size
651 actor.ClearPixelArea();
652 application.SendNotification(); // Process event messages
653 application.Render(); // Process LoadComplete
654 DALI_TEST_EQUALS( Vector2(actor.GetCurrentSize()), requestedSize, TEST_LOCATION );
660 int UtcDaliImageActorDefaultProperties(void)
662 TestApplication application;
663 tet_infoline("Testing Dali::ImageActor DefaultProperties");
665 BufferImage img = BufferImage::New( 10, 10 );
666 ImageActor actor = ImageActor::New( img );
668 std::vector<Property::Index> indices;
669 indices.push_back(ImageActor::Property::PIXEL_AREA );
670 indices.push_back(ImageActor::Property::STYLE );
671 indices.push_back(ImageActor::Property::BORDER );
672 indices.push_back(ImageActor::Property::IMAGE );
674 DALI_TEST_CHECK(actor.GetPropertyCount() == ( Actor::New().GetPropertyCount() + indices.size() ) );
676 for(std::vector<Property::Index>::iterator iter = indices.begin(); iter != indices.end(); ++iter)
678 DALI_TEST_CHECK( *iter == actor.GetPropertyIndex(actor.GetPropertyName(*iter)) );
679 DALI_TEST_CHECK( actor.IsPropertyWritable(*iter) );
680 DALI_TEST_CHECK( !actor.IsPropertyAnimatable(*iter) );
681 DALI_TEST_CHECK( actor.GetPropertyType(*iter) == actor.GetPropertyType(*iter) ); // just checking call succeeds
684 // set/get one of them
685 actor.SetPixelArea(ImageActor::PixelArea( 0, 0, 0, 0 ));
687 ImageActor::PixelArea area( 1, 2, 3, 4 );
688 actor.SetProperty(ImageActor::Property::PIXEL_AREA, Property::Value(Rect<int>(area)));
690 DALI_TEST_CHECK(Property::RECTANGLE == actor.GetPropertyType(ImageActor::Property::PIXEL_AREA));
692 Property::Value v = actor.GetProperty(ImageActor::Property::PIXEL_AREA);
694 DALI_TEST_CHECK(v.Get<Rect<int> >() == area);
699 int UtcDaliImageActorUseImageAlpha01(void)
701 TestApplication application;
703 tet_infoline("Testing Dali::RenderableActor::SetUseImageAlpha()");
705 BufferImage image = BufferImage::New( 100, 50 );
706 ImageActor actor = ImageActor::New( image );
707 actor.SetBlendMode( BlendingMode::ON );
708 actor.SetSize(100, 50);
709 application.GetGlAbstraction().EnableCullFaceCallTrace(true); // For Enable(GL_BLEND)
710 Stage::GetCurrent().Add(actor);
712 application.SendNotification();
713 application.Render();
715 const TraceCallStack& callTrace = application.GetGlAbstraction().GetCullFaceTrace();
716 DALI_TEST_EQUALS( BlendEnabled( callTrace), true, TEST_LOCATION );
717 DALI_TEST_EQUALS( BlendDisabled( callTrace ), false, TEST_LOCATION );
721 int UtcDaliImageActorUseImageAlpha02(void)
723 TestApplication application;
725 tet_infoline("Testing Dali::RenderableActor::SetUseImageAlpha()");
727 BufferImage image = BufferImage::New( 100, 50 );
728 ImageActor actor = ImageActor::New( image );
729 actor.SetBlendMode( BlendingMode::OFF );
730 actor.SetSize(100, 50);
731 application.GetGlAbstraction().EnableCullFaceCallTrace(true); // For Enable(GL_BLEND)
732 Stage::GetCurrent().Add(actor);
734 application.SendNotification();
735 application.Render();
737 const TraceCallStack& callTrace = application.GetGlAbstraction().GetCullFaceTrace();
738 DALI_TEST_EQUALS( BlendDisabled( callTrace ), false, TEST_LOCATION );
739 DALI_TEST_EQUALS( BlendEnabled( callTrace), false, TEST_LOCATION );
743 int UtcDaliImageActorUseImageAlpha03(void)
745 TestApplication application;
747 tet_infoline("Testing Dali::RenderableActor::SetUseImageAlpha()");
749 BufferImage image = BufferImage::New( 100, 50 );
750 ImageActor actor = ImageActor::New( image );
751 actor.SetBlendMode( BlendingMode::AUTO );
752 actor.SetColor(Vector4(1.0, 1.0, 1.0, 0.5));
753 actor.SetSize(100, 50);
754 application.GetGlAbstraction().EnableCullFaceCallTrace(true); // For Enable(GL_BLEND)
755 Stage::GetCurrent().Add(actor);
757 application.SendNotification();
758 application.Render();
760 const TraceCallStack& callTrace = application.GetGlAbstraction().GetCullFaceTrace();
761 DALI_TEST_EQUALS( BlendDisabled( callTrace ), false, TEST_LOCATION );
762 DALI_TEST_EQUALS( BlendEnabled( callTrace), true, TEST_LOCATION );
766 int UtcDaliImageActorUseImageAlpha04(void)
768 TestApplication application;
770 tet_infoline("Testing Dali::RenderableActor::SetUseImageAlpha()");
772 FrameBufferImage image = FrameBufferImage::New( 100, 50, Pixel::RGBA8888 );
773 RenderTaskList taskList = Stage::GetCurrent().GetRenderTaskList();
774 RenderTask task = taskList.GetTask( 0u );
775 task.SetTargetFrameBuffer( image ); // To ensure frame buffer is connected
776 application.GetGlAbstraction().SetCheckFramebufferStatusResult( GL_FRAMEBUFFER_COMPLETE );
777 application.SendNotification();
778 application.Render(0);
780 ImageActor actor = ImageActor::New( image );
781 application.SendNotification();
782 application.Render(0);
784 actor.SetBlendMode( BlendingMode::ON );
785 actor.SetColor(Vector4(1.0, 1.0, 1.0, 1.0));
786 actor.SetSize(100, 50);
787 application.GetGlAbstraction().EnableCullFaceCallTrace(true); // For Enable(GL_BLEND)
788 Stage::GetCurrent().Add(actor);
790 application.SendNotification();
791 application.Render();
793 const TraceCallStack& callTrace = application.GetGlAbstraction().GetCullFaceTrace();
794 DALI_TEST_EQUALS( BlendDisabled( callTrace ), false, TEST_LOCATION );
795 DALI_TEST_EQUALS( BlendEnabled( callTrace), true, TEST_LOCATION );
799 int UtcDaliImageActorUseImageAlpha05(void)
801 TestApplication application;
803 tet_infoline("Testing Dali::RenderableActor::SetUseImageAlpha()");
805 BufferImage image = BufferImage::New( 100, 50, Pixel::RGB888 );
806 ImageActor actor = ImageActor::New( image );
807 actor.SetBlendMode( BlendingMode::AUTO );
808 actor.SetColor(Vector4(1.0, 1.0, 1.0, 1.0));
809 actor.SetSize(100, 50);
810 application.GetGlAbstraction().EnableCullFaceCallTrace(true); // For Enable(GL_BLEND)
811 Stage::GetCurrent().Add(actor);
813 application.SendNotification();
814 application.Render();
816 const TraceCallStack& callTrace = application.GetGlAbstraction().GetCullFaceTrace();
817 DALI_TEST_EQUALS( BlendDisabled( callTrace ), false, TEST_LOCATION );
818 DALI_TEST_EQUALS( BlendEnabled( callTrace), false, TEST_LOCATION );
822 int UtcDaliImageActorClearPixelArea(void)
824 TestApplication application;
826 BufferImage img = BufferImage::New( 10, 10 );
827 ImageActor actor = ImageActor::New( img );
829 DALI_TEST_CHECK( actor.IsPixelAreaSet() == false );
831 ImageActor::PixelArea area( 1, 2, 3, 4 );
832 actor.SetPixelArea( area );
834 DALI_TEST_CHECK( actor.IsPixelAreaSet() == true );
836 actor.ClearPixelArea();
838 DALI_TEST_CHECK( actor.IsPixelAreaSet() == false );
842 int UtcDaliImageGetStyle(void)
844 TestApplication application;
846 Image image = ResourceImage::New(TestImageFilename);
847 ImageActor actor = ImageActor::New(image);
849 actor.SetStyle(ImageActor::STYLE_NINE_PATCH);
851 // flush the queue and render once
852 application.SendNotification();
853 application.Render();
855 DALI_TEST_EQUALS( ImageActor::STYLE_NINE_PATCH, actor.GetStyle(), TEST_LOCATION );
859 int UtcDaliImageSetNinePatchBorder(void)
861 TestApplication application;
863 Image image = ResourceImage::New(TestImageFilename);
864 ImageActor actor = ImageActor::New(image);
866 actor.SetStyle(ImageActor::STYLE_NINE_PATCH);
867 actor.SetNinePatchBorder(Vector4( 1.0f, 2.0f, 3.0f, 4.0f));
869 DALI_TEST_EQUALS( 1.0f, actor.GetNinePatchBorder().x, TEST_LOCATION );
870 DALI_TEST_EQUALS( 2.0f, actor.GetNinePatchBorder().y, TEST_LOCATION );
871 DALI_TEST_EQUALS( 3.0f, actor.GetNinePatchBorder().z, TEST_LOCATION );
872 DALI_TEST_EQUALS( 4.0f, actor.GetNinePatchBorder().w, TEST_LOCATION );
876 int UtcDaliImageActorNewNull(void)
878 TestApplication application;
880 ImageActor actor = ImageActor::New(Image());
882 DALI_TEST_CHECK(actor);
886 int UtcDaliImageActorNewNullWithArea(void)
888 TestApplication application;
890 ImageActor::PixelArea area( 1, 2, 3, 4 );
892 ImageActor actor = ImageActor::New(Image(), area);
894 DALI_TEST_CHECK(actor);
898 int UtcDaliImageActorSetImage(void)
900 TestApplication application;
902 ImageActor actor = ImageActor::New(Image());
904 DALI_TEST_CHECK(actor);
906 actor.SetImage( Image() );
908 DALI_TEST_CHECK(!actor.GetImage());
912 int UtcDaliImageActorPropertyIndices(void)
914 TestApplication application;
915 Actor basicActor = Actor::New();
916 ImageActor imageActor = ImageActor::New();
918 Property::IndexContainer indices;
919 imageActor.GetPropertyIndices( indices );
920 DALI_TEST_CHECK( indices.size() > basicActor.GetPropertyCount() );
921 DALI_TEST_EQUALS( indices.size(), imageActor.GetPropertyCount(), TEST_LOCATION );
925 int UtcDaliImageActorImageProperty(void)
927 TestApplication application;
928 Image image = ResourceImage::New( "MY_PATH" );
929 ImageActor imageActor = ImageActor::New( image );
931 Stage::GetCurrent().Add( imageActor );
932 application.SendNotification();
933 application.Render();
935 Property::Value imageMap = imageActor.GetProperty( ImageActor::Property::IMAGE );
936 DALI_TEST_CHECK( imageMap.HasKey( "filename" ) );
937 DALI_TEST_EQUALS( imageMap.GetValue( "filename" ).Get< std::string >(), "MY_PATH", TEST_LOCATION );
941 int UtcDaliImageActorNinePatch01(void)
943 TestApplication application;
944 TestPlatformAbstraction& platform = application.GetPlatform();
945 TestGlAbstraction& glAbstraction = application.GetGlAbstraction();
946 TraceCallStack& textureTrace = glAbstraction.GetTextureTrace();
947 TraceCallStack& drawTrace = glAbstraction.GetDrawTrace();
949 tet_infoline("Test the successful loading of a nine-patch image\n");
951 platform.SetClosestImageSize(Vector2(4, 4));
952 Integration::Bitmap* bitmap = Integration::Bitmap::New( Integration::Bitmap::BITMAP_2D_PACKED_PIXELS, ResourcePolicy::RETAIN );
953 Integration::PixelBuffer* pixels = bitmap->GetPackedPixelsProfile()->ReserveBuffer( Pixel::RGBA8888, 4,4,4,4 );
954 memset( pixels, 0, 64 );
956 Integration::ResourcePointer resourcePtr(bitmap); // reference it
957 platform.SetResourceLoaded( 0, Dali::Integration::ResourceBitmap, resourcePtr );
959 Image ninePatchImage = ResourceImage::New( "blah.#.png" );
960 DALI_TEST_CHECK( ninePatchImage );
962 ImageActor imageActor = ImageActor::New( ninePatchImage );
963 DALI_TEST_CHECK( imageActor );
964 Stage::GetCurrent().Add( imageActor );
967 textureTrace.Reset();
968 drawTrace.Enable(true);
969 textureTrace.Enable(true);
970 glAbstraction.ClearBoundTextures();
971 std::vector<GLuint> ids;
973 glAbstraction.SetNextTextureIds( ids );
975 application.SendNotification();
976 application.Render();
978 DALI_TEST_CHECK( drawTrace.FindMethod( "DrawArrays" ) );
979 typedef std::vector<GLuint> TexVec;
980 const TexVec& textures = glAbstraction.GetBoundTextures(GL_TEXTURE0);
981 DALI_TEST_CHECK( textures.size() > 0 );
982 if( textures.size() > 0 )
984 DALI_TEST_EQUALS( textures[0], 23u, TEST_LOCATION );
991 int UtcDaliImageActorNinePatch02(void)
993 TestApplication application;
994 TestPlatformAbstraction& platform = application.GetPlatform();
995 TestGlAbstraction& glAbstraction = application.GetGlAbstraction();
996 TraceCallStack& textureTrace = glAbstraction.GetTextureTrace();
997 TraceCallStack& drawTrace = glAbstraction.GetDrawTrace();
999 tet_infoline("Test the failed loading of a nine-patch image\n");
1001 platform.SetClosestImageSize(Vector2(0, 0));
1002 Integration::ResourcePointer resourcePtr;
1003 platform.SetResourceLoaded( 0, Dali::Integration::ResourceBitmap, resourcePtr );
1005 Image ninePatchImage = ResourceImage::New( "blah.#.png" );
1006 DALI_TEST_CHECK( ninePatchImage );
1008 ImageActor imageActor = ImageActor::New( ninePatchImage );
1009 DALI_TEST_CHECK( imageActor );
1010 Stage::GetCurrent().Add( imageActor );
1013 textureTrace.Reset();
1014 drawTrace.Enable(true);
1015 textureTrace.Enable(true);
1016 glAbstraction.ClearBoundTextures();
1017 std::vector<GLuint> ids;
1018 ids.push_back( 23 );
1019 glAbstraction.SetNextTextureIds( ids );
1021 application.SendNotification();
1022 application.Render();
1024 // Check that nothing was drawn.
1025 DALI_TEST_CHECK( ! drawTrace.FindMethod( "DrawArrays" ) );
1026 typedef std::vector<GLuint> TexVec;
1027 const TexVec& textures = glAbstraction.GetBoundTextures(GL_TEXTURE0);
1028 DALI_TEST_CHECK( textures.size() == 0u );
1034 int UtcDaliImageActorNinePatch03(void)
1036 TestApplication application;
1037 TestPlatformAbstraction& platform = application.GetPlatform();
1038 TestGlAbstraction& glAbstraction = application.GetGlAbstraction();
1039 TraceCallStack& textureTrace = glAbstraction.GetTextureTrace();
1040 TraceCallStack& drawTrace = glAbstraction.GetDrawTrace();
1042 tet_infoline("Test the successful loading of a nine-patch image added using ImageActor::SetImage()\n");
1044 platform.SetClosestImageSize(Vector2(4, 4));
1045 Integration::Bitmap* bitmap = Integration::Bitmap::New( Integration::Bitmap::BITMAP_2D_PACKED_PIXELS, ResourcePolicy::RETAIN );
1046 Integration::PixelBuffer* pixels = bitmap->GetPackedPixelsProfile()->ReserveBuffer( Pixel::RGBA8888, 4,4,4,4 );
1047 memset( pixels, 0, 64 );
1049 Integration::ResourcePointer resourcePtr(bitmap); // reference it
1050 platform.SetResourceLoaded( 0, Dali::Integration::ResourceBitmap, resourcePtr );
1052 Image ninePatchImage = ResourceImage::New( "blah.#.png" );
1053 DALI_TEST_CHECK( ninePatchImage );
1055 ImageActor imageActor = ImageActor::New();
1056 DALI_TEST_CHECK( imageActor );
1057 Stage::GetCurrent().Add( imageActor );
1059 imageActor.SetImage( ninePatchImage );
1062 textureTrace.Reset();
1063 drawTrace.Enable(true);
1064 textureTrace.Enable(true);
1065 glAbstraction.ClearBoundTextures();
1066 std::vector<GLuint> ids;
1067 ids.push_back( 23 );
1068 glAbstraction.SetNextTextureIds( ids );
1070 application.SendNotification();
1071 application.Render();
1073 DALI_TEST_CHECK( drawTrace.FindMethod( "DrawArrays" ) );
1074 typedef std::vector<GLuint> TexVec;
1075 const TexVec& textures = glAbstraction.GetBoundTextures(GL_TEXTURE0);
1076 DALI_TEST_CHECK( textures.size() > 0 );
1077 if( textures.size() > 0 )
1079 DALI_TEST_EQUALS( textures[0], 23u, TEST_LOCATION );
1086 int UtcDaliImageActorNinePatch04(void)
1088 TestApplication application;
1089 TestPlatformAbstraction& platform = application.GetPlatform();
1090 TestGlAbstraction& glAbstraction = application.GetGlAbstraction();
1091 TraceCallStack& textureTrace = glAbstraction.GetTextureTrace();
1092 TraceCallStack& drawTrace = glAbstraction.GetDrawTrace();
1094 tet_infoline("Test the failed loading of a nine-patch image using ImageActor::SetImage()\n");
1096 platform.SetClosestImageSize(Vector2(0, 0));
1097 Integration::ResourcePointer resourcePtr;
1098 platform.SetResourceLoaded( 0, Dali::Integration::ResourceBitmap, resourcePtr );
1100 Image ninePatchImage = ResourceImage::New( "blah.#.png" );
1101 DALI_TEST_CHECK( ninePatchImage );
1103 ImageActor imageActor = ImageActor::New();
1104 DALI_TEST_CHECK( imageActor );
1105 Stage::GetCurrent().Add( imageActor );
1107 imageActor.SetImage( ninePatchImage );
1110 textureTrace.Reset();
1111 drawTrace.Enable(true);
1112 textureTrace.Enable(true);
1113 glAbstraction.ClearBoundTextures();
1114 std::vector<GLuint> ids;
1115 ids.push_back( 23 );
1116 glAbstraction.SetNextTextureIds( ids );
1118 application.SendNotification();
1119 application.Render();
1121 // Check that nothing was drawn.
1122 DALI_TEST_CHECK( ! drawTrace.FindMethod( "DrawArrays" ) );
1123 typedef std::vector<GLuint> TexVec;
1124 const TexVec& textures = glAbstraction.GetBoundTextures(GL_TEXTURE0);
1125 DALI_TEST_CHECK( textures.size() == 0u );
1130 int UtcDaliImageActorGetNaturalSize(void)
1132 TestApplication application;
1135 BufferImage img = BufferImage::New( 10, 10 );
1136 ImageActor actor = ImageActor::New( img );
1138 DALI_TEST_CHECK( actor.GetNaturalSize().GetVectorXY() == Vector2( 10, 10 ) );
1141 ImageActor::PixelArea area( 1, 2, 3, 4 );
1142 actor.SetPixelArea( area );
1144 DALI_TEST_CHECK( actor.GetNaturalSize().GetVectorXY() == Vector2( 3, 4 ) );