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 = Image::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 = Image::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 = Image::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 = Image::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 BitmapImage img = BitmapImage::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 int UtcDaliImageActorGetCurrentImageSize01(void)
179 TestApplication application;
180 tet_infoline("Positive test for Dali::ImageActor::GetCurrentImageSize");
182 Vector2 initialImageSize(100, 50);
183 BitmapImage image = BitmapImage::New( initialImageSize.width, initialImageSize.height );
184 ImageActor actor = ImageActor::New( image );
185 Stage::GetCurrent().Add(actor);
187 application.SendNotification();
188 application.Render();
190 DALI_TEST_EQUALS( actor.GetCurrentImageSize(), initialImageSize, TEST_LOCATION );
192 Vector2 size(200.0f, 200.0f);
195 // flush the queue and render once
196 application.SendNotification();
197 application.Render();
198 DALI_TEST_EQUALS( actor.GetCurrentImageSize(), size, TEST_LOCATION );
203 application.Render(8);
205 // Test when a pixel area is set
206 ImageActor::PixelArea area(0, 0, 10, 10);
207 actor.SetPixelArea(area);
208 application.Render(9);
209 DALI_TEST_EQUALS( actor.GetCurrentImageSize(), Vector2( area.width, area.height ), TEST_LOCATION );
214 int UtcDaliImageActorGetCurrentImageSize02(void)
216 TestApplication application;
217 tet_infoline("Positive test for Dali::ImageActor::GetCurrentImageSize - Test that using an image resource sets the actor size with it's natural size immediately rather than on load");
219 Vector2 initialImageSize(100, 50);
221 application.GetPlatform().SetClosestImageSize(initialImageSize);
223 Image image = Image::New("image.jpg");
224 ImageActor actor = ImageActor::New( image );
225 Stage::GetCurrent().Add(actor);
227 application.SendNotification(); // Flush update messages
228 application.Render(); // Process resource request
229 application.SendNotification(); // Flush update messages
230 application.Render(); // Process resource request
232 DALI_TEST_EQUALS( actor.GetCurrentImageSize(), initialImageSize, TEST_LOCATION );
234 // Now complete the image load
235 Integration::ResourceRequest* req = application.GetPlatform().GetRequest();
236 Integration::Bitmap* bitmap = Integration::Bitmap::New( Integration::Bitmap::BITMAP_2D_PACKED_PIXELS, false );
237 bitmap->GetPackedPixelsProfile()->ReserveBuffer( Pixel::RGBA8888, initialImageSize.width,initialImageSize.height, initialImageSize.width,initialImageSize.height );
239 Integration::ResourcePointer resourcePtr(bitmap); // reference it
240 application.GetPlatform().SetResourceLoaded(req->GetId(), req->GetType()->id, resourcePtr);
241 application.Render(); // Process LoadComplete
242 application.SendNotification(); // Process event messages
243 application.GetPlatform().DiscardRequest(); // Ensure load request is discarded
244 application.GetPlatform().ClearReadyResources(); //
246 DALI_TEST_EQUALS( actor.GetCurrentImageSize(), initialImageSize, TEST_LOCATION );
248 Vector2 size(200.0f, 200.0f);
251 // flush the queue and render once
252 application.SendNotification();
253 application.Render();
254 DALI_TEST_EQUALS( actor.GetCurrentImageSize(), size, TEST_LOCATION );
256 actor.SetToNaturalSize();
257 application.SendNotification();
258 application.Render();
259 DALI_TEST_EQUALS( actor.GetCurrentImageSize(), initialImageSize, TEST_LOCATION );
264 int UtcDaliImageActorGetCurrentImageSize03(void)
266 TestApplication application;
267 tet_infoline("Positive test for Dali::ImageActor::GetCurrentImageSize - Test that using an image resource with a requested size sets the actor size with it's nearest size immediately rather than on load");
269 Vector2 closestImageSize( 80, 45);
271 application.GetPlatform().SetClosestImageSize(closestImageSize);
273 ImageAttributes attrs;
274 attrs.SetSize(40, 30);
275 Image image = Image::New("image.jpg", attrs);
276 ImageActor actor = ImageActor::New( image );
277 Stage::GetCurrent().Add(actor);
279 application.SendNotification(); // Flush update messages
280 application.Render(); // Process resource request
281 application.SendNotification(); // Flush update messages
282 application.Render(); // Process resource request
284 DALI_TEST_EQUALS( actor.GetCurrentImageSize(), closestImageSize, TEST_LOCATION );
286 // Now complete the image load
287 Integration::ResourceRequest* req = application.GetPlatform().GetRequest();
288 Integration::Bitmap* bitmap = Integration::Bitmap::New( Integration::Bitmap::BITMAP_2D_PACKED_PIXELS, false );
289 bitmap->GetPackedPixelsProfile()->ReserveBuffer( Pixel::RGBA8888, closestImageSize.width, closestImageSize.height, closestImageSize.width, closestImageSize.height );
291 Integration::ResourcePointer resourcePtr(bitmap); // reference it
292 application.GetPlatform().SetResourceLoaded(req->GetId(), req->GetType()->id, resourcePtr);
293 application.Render(); // Process LoadComplete
294 application.SendNotification(); // Process event messages
295 application.GetPlatform().DiscardRequest(); // Ensure load request is discarded
296 application.GetPlatform().ClearReadyResources(); //
298 DALI_TEST_EQUALS( actor.GetCurrentImageSize(), closestImageSize, TEST_LOCATION );
300 // Test that setting a size on the actor can be 'undone' with SetNaturalSize()
301 Vector2 size(200.0f, 200.0f);
304 // flush the queue and render once
305 application.SendNotification();
306 application.Render();
307 DALI_TEST_EQUALS( actor.GetCurrentImageSize(), size, TEST_LOCATION );
309 actor.SetToNaturalSize();
310 application.SendNotification();
311 application.Render();
312 DALI_TEST_EQUALS( actor.GetCurrentImageSize(), closestImageSize, TEST_LOCATION );
317 int UtcDaliImageActorGetCurrentImageSize04(void)
319 TestApplication application;
320 tet_infoline("Positive test for Dali::ImageActor::GetCurrentImageSize - check a new image doesn't change a set actor size");
322 Vector2 closestImageSize( 80, 45);
323 application.GetPlatform().SetClosestImageSize(closestImageSize);
325 ImageAttributes attrs;
326 attrs.SetSize(40, 30); // Request a really small size we won't get.
327 Image image = Image::New("image.jpg", attrs);
328 ImageActor actor = ImageActor::New( image );
329 Stage::GetCurrent().Add(actor);
331 application.SendNotification(); // Flush update messages
332 application.Render(); // Process resource request
334 DALI_TEST_EQUALS( actor.GetCurrentImageSize(), closestImageSize, TEST_LOCATION );
336 // Now complete the image load
337 Integration::ResourceRequest* req = application.GetPlatform().GetRequest();
338 Integration::Bitmap* bitmap = Integration::Bitmap::New( Integration::Bitmap::BITMAP_2D_PACKED_PIXELS, false );
339 bitmap->GetPackedPixelsProfile()->ReserveBuffer( Pixel::RGBA8888, closestImageSize.width, closestImageSize.height, closestImageSize.width, closestImageSize.height );
341 Integration::ResourcePointer resourcePtr(bitmap); // reference it
342 application.GetPlatform().SetResourceLoaded(req->GetId(), req->GetType()->id, resourcePtr);
343 application.Render(); // Process LoadComplete
344 application.SendNotification(); // Process event messages
345 application.GetPlatform().DiscardRequest(); // Ensure load request is discarded
346 application.GetPlatform().ClearReadyResources(); //
348 DALI_TEST_EQUALS( actor.GetCurrentImageSize(), closestImageSize, TEST_LOCATION );
350 Vector2 size(200.0f, 200.0f);
353 // flush the queue and render once
354 application.SendNotification();
355 application.Render();
356 DALI_TEST_EQUALS( actor.GetCurrentImageSize(), size, TEST_LOCATION );
358 // Load a different image
360 Vector2 image2ClosestSize = Vector2(240, 150); // The actual size image loader will return for the request below
361 application.GetPlatform().SetClosestImageSize(image2ClosestSize);
363 attrs.SetSize(100, 100);
364 Image image2 = Image::New("image2.jpg", attrs);
365 actor.SetImage(image2);
367 application.SendNotification(); // Flush update messages
368 application.Render(); // Process resource request
369 application.SendNotification(); // Flush update messages
370 application.Render(); // Process resource request
372 // Ensure the actor size is kept
373 DALI_TEST_EQUALS( actor.GetCurrentImageSize(), size, TEST_LOCATION );
375 // Now complete the image load
376 req = application.GetPlatform().GetRequest();
377 Integration::Bitmap* bitmap2 = Integration::Bitmap::New( Integration::Bitmap::BITMAP_2D_PACKED_PIXELS, false );
378 bitmap2->GetPackedPixelsProfile()->ReserveBuffer( Pixel::RGBA8888, image2ClosestSize.width, image2ClosestSize.height, image2ClosestSize.width, image2ClosestSize.height );
380 Integration::ResourcePointer resourcePtr2(bitmap2); // reference it
381 application.GetPlatform().SetResourceLoaded(req->GetId(), req->GetType()->id, resourcePtr2);
382 application.Render(); // Process LoadComplete
383 application.SendNotification(); // Process event messages
384 application.GetPlatform().DiscardRequest(); // Ensure load request is discarded
385 application.GetPlatform().ClearReadyResources(); //
387 // Ensure the actor size is kept
388 DALI_TEST_EQUALS( actor.GetCurrentImageSize(), size, TEST_LOCATION );
390 actor.SetToNaturalSize();
391 application.SendNotification();
392 application.Render();
393 // Ensure the actor size gets the new image's natural size
394 DALI_TEST_EQUALS( actor.GetCurrentImageSize(), image2ClosestSize, TEST_LOCATION );
399 int UtcDaliImageActorGetCurrentImageSize05(void)
401 TestApplication application;
402 tet_infoline("Positive test for Dali::ImageActor::GetCurrentImageSize - check a new image doens't change actor size until load complete");
404 Vector2 closestImageSize( 80, 45);
405 application.GetPlatform().SetClosestImageSize(closestImageSize);
407 ImageAttributes attrs;
408 attrs.SetSize(40, 30); // Request a really small size we won't get.
409 Image image = Image::New("image.jpg", attrs);
410 ImageActor actor = ImageActor::New( image );
411 Stage::GetCurrent().Add(actor);
413 application.SendNotification(); // Flush update messages
414 application.Render(); // Process resource request
416 DALI_TEST_EQUALS( actor.GetCurrentImageSize(), closestImageSize, TEST_LOCATION );
418 // Now complete the image load
419 Integration::ResourceRequest* req = application.GetPlatform().GetRequest();
420 Integration::Bitmap* bitmap = Integration::Bitmap::New( Integration::Bitmap::BITMAP_2D_PACKED_PIXELS, false );
421 bitmap->GetPackedPixelsProfile()->ReserveBuffer( Pixel::RGBA8888, closestImageSize.width, closestImageSize.height, closestImageSize.width, closestImageSize.height );
423 Integration::ResourcePointer resourcePtr(bitmap); // reference it
424 application.GetPlatform().SetResourceLoaded(req->GetId(), req->GetType()->id, resourcePtr);
425 application.Render(); // Process LoadComplete
426 application.SendNotification(); // Process event messages
427 application.GetPlatform().DiscardRequest(); // Ensure load request is discarded
428 application.GetPlatform().ClearReadyResources(); //
430 DALI_TEST_EQUALS( actor.GetCurrentImageSize(), closestImageSize, TEST_LOCATION );
432 // Load a different image
434 Vector2 image2ClosestSize = Vector2(240, 150);
435 application.GetPlatform().SetClosestImageSize(image2ClosestSize);
437 attrs.SetSize(100, 100);
438 Image image2 = Image::New("image2.jpg", attrs);
439 actor.SetImage(image2);
441 application.SendNotification(); // Flush update messages
442 application.Render(); // Process resource request
443 application.SendNotification(); // Flush update messages
444 application.Render(); // Process resource request
446 // Ensure the actor size is kept
447 DALI_TEST_EQUALS( actor.GetCurrentImageSize(), closestImageSize, TEST_LOCATION );
449 // Now complete the image load
450 req = application.GetPlatform().GetRequest();
451 Integration::Bitmap* bitmap2 = Integration::Bitmap::New( Integration::Bitmap::BITMAP_2D_PACKED_PIXELS, false );
452 bitmap2->GetPackedPixelsProfile()->ReserveBuffer( Pixel::RGBA8888, image2ClosestSize.width, image2ClosestSize.height, image2ClosestSize.width, image2ClosestSize.height );
454 Integration::ResourcePointer resourcePtr2(bitmap2); // reference it
455 application.GetPlatform().SetResourceLoaded(req->GetId(), req->GetType()->id, resourcePtr2);
456 application.Render(); // Process LoadComplete
457 application.SendNotification(); // Process event messages
458 application.GetPlatform().DiscardRequest(); // Ensure load request is discarded
459 application.GetPlatform().ClearReadyResources(); //
461 application.SendNotification(); // Process event messages
462 application.Render(); // Process LoadComplete
464 // Ensure the actor size gets the new image's natural size
465 DALI_TEST_EQUALS( actor.GetCurrentImageSize(), image2ClosestSize, TEST_LOCATION );
469 int UtcDaliImageActorNaturalPixelAreaSize01(void)
471 TestApplication application;
472 tet_infoline("Positive test for Dali::ImageActor::GetCurrentImageSize - check a new image doens't change actor size until load complete");
474 //If an image is loaded without setting size, then the actor gets the natural size of the image
475 //Setting the pixel area will change the actor size to match the pixel area
476 //Setting the actor size will not change pixel area, and will cause the partial image to stretch
478 //Clearing the pixel area will not change actor size, and the actor will show the whole image.
481 Vector2 closestImageSize( 80, 45);
482 application.GetPlatform().SetClosestImageSize(closestImageSize);
484 ImageAttributes attrs;
485 attrs.SetSize(40, 30); // Request a really small size we won't get.
486 Image image = Image::New("image.jpg", attrs);
487 ImageActor actor = ImageActor::New( image );
488 Stage::GetCurrent().Add(actor);
490 application.SendNotification(); // Flush update messages
491 application.Render(); // Process resource request
493 DALI_TEST_EQUALS( actor.GetCurrentImageSize(), closestImageSize, TEST_LOCATION );
494 DALI_TEST_EQUALS( Vector2(actor.GetCurrentSize()), closestImageSize, TEST_LOCATION );
496 // Now complete the image load
497 Integration::ResourceRequest* req = application.GetPlatform().GetRequest();
498 Integration::Bitmap* bitmap = Integration::Bitmap::New( Integration::Bitmap::BITMAP_2D_PACKED_PIXELS, false );
499 bitmap->GetPackedPixelsProfile()->ReserveBuffer( Pixel::RGBA8888, closestImageSize.width, closestImageSize.height, closestImageSize.width, closestImageSize.height );
501 Integration::ResourcePointer resourcePtr(bitmap); // reference it
502 application.GetPlatform().SetResourceLoaded(req->GetId(), req->GetType()->id, resourcePtr);
503 application.Render(); // Process LoadComplete
504 application.SendNotification(); // Process event messages
505 application.GetPlatform().DiscardRequest(); // Ensure load request is discarded
506 application.GetPlatform().ClearReadyResources(); //
508 DALI_TEST_EQUALS( actor.GetCurrentImageSize(), closestImageSize, TEST_LOCATION );
509 DALI_TEST_EQUALS( Vector2(actor.GetCurrentSize()), closestImageSize, TEST_LOCATION );
511 // Set a pixel area on a naturally sized actor - expect the actor to take the
512 // pixel area as size
513 actor.SetPixelArea(ImageActor::PixelArea(0, 0, 30, 30));
514 application.SendNotification(); // Process event messages
515 application.Render(); // Process LoadComplete
516 DALI_TEST_EQUALS( actor.GetCurrentImageSize(), Vector2(30, 30), TEST_LOCATION );
517 DALI_TEST_EQUALS( Vector2(actor.GetCurrentSize()), Vector2(30, 30), TEST_LOCATION );
519 // Set a size. Expect the partial image to stretch to fill the new size
520 actor.SetSize(100, 100);
521 application.SendNotification(); // Process event messages
522 application.Render(); // Process LoadComplete
523 application.Render(); // Process LoadComplete
524 DALI_TEST_EQUALS( actor.GetCurrentImageSize(), Vector2(30, 30), TEST_LOCATION );
525 DALI_TEST_EQUALS( Vector2(actor.GetCurrentSize()), Vector2(100, 100), TEST_LOCATION );
527 // Clear the pixel area. Expect the whole image to be shown, filling the set size.
528 actor.ClearPixelArea();
529 application.SendNotification(); // Process event messages
530 application.Render(); // Process LoadComplete
531 DALI_TEST_EQUALS( actor.GetCurrentImageSize(), Vector2(100, 100), TEST_LOCATION );
532 DALI_TEST_EQUALS( Vector2(actor.GetCurrentSize()), Vector2(100, 100), TEST_LOCATION );
536 int UtcDaliImageActorNaturalPixelAreaSize02(void)
538 TestApplication application;
539 tet_infoline("Positive test for Dali::ImageActor::GetCurrentImageSize - check a new image doens't change actor size until load complete");
541 //If an image is loaded without setting size, then the actor gets the natural size of the image
542 //Setting the pixel area will change the actor size to match the pixel area
543 //Setting the actor size will not change pixel area, and will cause the partial image to stretch
545 //Clearing the pixel area will not change actor size, and the actor will show the whole image.
548 Vector2 closestImageSize( 80, 45);
549 application.GetPlatform().SetClosestImageSize(closestImageSize);
551 ImageAttributes attrs;
552 attrs.SetSize(40, 30); // Request a really small size we won't get.
553 Image image = Image::New("image.jpg", attrs);
554 ImageActor actor = ImageActor::New( image );
555 Stage::GetCurrent().Add(actor);
557 application.SendNotification(); // Flush update messages
558 application.Render(); // Process resource request
560 DALI_TEST_EQUALS( actor.GetCurrentImageSize(), closestImageSize, TEST_LOCATION );
561 DALI_TEST_EQUALS( Vector2(actor.GetCurrentSize()), closestImageSize, TEST_LOCATION );
563 // Now complete the image load
564 Integration::ResourceRequest* req = application.GetPlatform().GetRequest();
565 Integration::Bitmap* bitmap = Integration::Bitmap::New( Integration::Bitmap::BITMAP_2D_PACKED_PIXELS, false );
566 bitmap->GetPackedPixelsProfile()->ReserveBuffer( Pixel::RGBA8888, closestImageSize.width, closestImageSize.height, closestImageSize.width, closestImageSize.height );
568 Integration::ResourcePointer resourcePtr(bitmap); // reference it
569 application.GetPlatform().SetResourceLoaded(req->GetId(), req->GetType()->id, resourcePtr);
570 application.Render(); // Process LoadComplete
571 application.SendNotification(); // Process event messages
572 application.GetPlatform().DiscardRequest(); // Ensure load request is discarded
573 application.GetPlatform().ClearReadyResources(); //
575 DALI_TEST_EQUALS( actor.GetCurrentImageSize(), closestImageSize, TEST_LOCATION );
576 DALI_TEST_EQUALS( Vector2(actor.GetCurrentSize()), closestImageSize, TEST_LOCATION );
578 // Set a pixel area on a naturally sized actor - expect the actor to take the
579 // pixel area as size
580 actor.SetPixelArea(ImageActor::PixelArea(0, 0, 30, 30));
581 application.SendNotification(); // Process event messages
582 application.Render(); // Process LoadComplete
583 DALI_TEST_EQUALS( actor.GetCurrentImageSize(), Vector2(30, 30), TEST_LOCATION );
584 DALI_TEST_EQUALS( Vector2(actor.GetCurrentSize()), Vector2(30, 30), TEST_LOCATION );
586 // Clear the pixel area. Expect the whole image to be shown, changing actor size
587 actor.ClearPixelArea();
588 application.SendNotification(); // Process event messages
589 application.Render(); // Process LoadComplete
590 DALI_TEST_EQUALS( actor.GetCurrentImageSize(), closestImageSize, TEST_LOCATION );
591 DALI_TEST_EQUALS( Vector2(actor.GetCurrentSize()), closestImageSize, TEST_LOCATION );
593 // Set a size. Expect the partial image to stretch to fill the new size
594 actor.SetSize(100, 100);
595 application.SendNotification(); // Process event messages
596 application.Render(); // Process LoadComplete
597 DALI_TEST_EQUALS( actor.GetCurrentImageSize(), Vector2(100, 100), TEST_LOCATION );
598 DALI_TEST_EQUALS( Vector2(actor.GetCurrentSize()), Vector2(100, 100), TEST_LOCATION );
600 // Set a pixel area, don't expect size to change
601 actor.SetPixelArea(ImageActor::PixelArea(0, 0, 40, 40));
602 application.SendNotification(); // Process event messages
603 application.Render(); // Process LoadComplete
604 DALI_TEST_EQUALS( actor.GetCurrentImageSize(), Vector2(40, 40), TEST_LOCATION );
605 DALI_TEST_EQUALS( Vector2(actor.GetCurrentSize()), Vector2(100, 100), TEST_LOCATION );
607 // Use natural size - expect actor to change to pixel area
608 actor.SetToNaturalSize();
609 application.SendNotification(); // Process event messages
610 application.Render(); // Process LoadComplete
611 DALI_TEST_EQUALS( actor.GetCurrentImageSize(), Vector2(40, 40), TEST_LOCATION );
612 DALI_TEST_EQUALS( Vector2(actor.GetCurrentSize()), Vector2(40, 40), TEST_LOCATION );
614 // Clearing pixel area should change actor size to image size
615 actor.ClearPixelArea();
616 application.SendNotification(); // Process event messages
617 application.Render(); // Process LoadComplete
618 DALI_TEST_EQUALS( actor.GetCurrentImageSize(), closestImageSize, TEST_LOCATION );
619 DALI_TEST_EQUALS( Vector2(actor.GetCurrentSize()), closestImageSize, TEST_LOCATION );
625 int UtcDaliImageActorDefaultProperties(void)
627 TestApplication application;
628 tet_infoline("Testing Dali::ImageActor DefaultProperties");
630 BitmapImage img = BitmapImage::New( 10, 10 );
631 ImageActor actor = ImageActor::New( img );
633 std::vector<Property::Index> indices;
634 indices.push_back(ImageActor::PIXEL_AREA );
635 indices.push_back(ImageActor::FADE_IN );
636 indices.push_back(ImageActor::FADE_IN_DURATION);
637 indices.push_back(ImageActor::STYLE );
638 indices.push_back(ImageActor::BORDER );
639 indices.push_back(ImageActor::IMAGE );
641 DALI_TEST_CHECK(actor.GetPropertyCount() == ( Actor::New().GetPropertyCount() + indices.size() ) );
643 for(std::vector<Property::Index>::iterator iter = indices.begin(); iter != indices.end(); ++iter)
645 DALI_TEST_CHECK( *iter == actor.GetPropertyIndex(actor.GetPropertyName(*iter)) );
646 DALI_TEST_CHECK( actor.IsPropertyWritable(*iter) );
647 DALI_TEST_CHECK( !actor.IsPropertyAnimatable(*iter) );
648 DALI_TEST_CHECK( actor.GetPropertyType(*iter) == actor.GetPropertyType(*iter) ); // just checking call succeeds
651 // set/get one of them
652 actor.SetPixelArea(ImageActor::PixelArea( 0, 0, 0, 0 ));
654 ImageActor::PixelArea area( 1, 2, 3, 4 );
655 actor.SetProperty(ImageActor::PIXEL_AREA, Property::Value(Rect<int>(area)));
657 DALI_TEST_CHECK(Property::RECTANGLE == actor.GetPropertyType(ImageActor::PIXEL_AREA));
659 Property::Value v = actor.GetProperty(ImageActor::PIXEL_AREA);
661 DALI_TEST_CHECK(v.Get<Rect<int> >() == area);
666 int UtcDaliImageActorUseImageAlpha01(void)
668 TestApplication application;
670 tet_infoline("Testing Dali::RenderableActor::SetUseImageAlpha()");
672 BitmapImage image = BitmapImage::New( 100, 50 );
673 ImageActor actor = ImageActor::New( image );
674 actor.SetBlendMode( BlendingMode::ON );
675 actor.SetSize(100, 50);
676 application.GetGlAbstraction().EnableCullFaceCallTrace(true); // For Enable(GL_BLEND)
677 Stage::GetCurrent().Add(actor);
679 application.SendNotification();
680 application.Render();
682 const TraceCallStack& callTrace = application.GetGlAbstraction().GetCullFaceTrace();
683 DALI_TEST_EQUALS( BlendEnabled( callTrace), true, TEST_LOCATION );
684 DALI_TEST_EQUALS( BlendDisabled( callTrace ), false, TEST_LOCATION );
688 int UtcDaliImageActorUseImageAlpha02(void)
690 TestApplication application;
692 tet_infoline("Testing Dali::RenderableActor::SetUseImageAlpha()");
694 BitmapImage image = BitmapImage::New( 100, 50 );
695 ImageActor actor = ImageActor::New( image );
696 actor.SetBlendMode( BlendingMode::OFF );
697 actor.SetSize(100, 50);
698 application.GetGlAbstraction().EnableCullFaceCallTrace(true); // For Enable(GL_BLEND)
699 Stage::GetCurrent().Add(actor);
701 application.SendNotification();
702 application.Render();
704 const TraceCallStack& callTrace = application.GetGlAbstraction().GetCullFaceTrace();
705 DALI_TEST_EQUALS( BlendDisabled( callTrace ), false, TEST_LOCATION );
706 DALI_TEST_EQUALS( BlendEnabled( callTrace), false, TEST_LOCATION );
710 int UtcDaliImageActorUseImageAlpha03(void)
712 TestApplication application;
714 tet_infoline("Testing Dali::RenderableActor::SetUseImageAlpha()");
716 BitmapImage image = BitmapImage::New( 100, 50 );
717 ImageActor actor = ImageActor::New( image );
718 actor.SetBlendMode( BlendingMode::AUTO );
719 actor.SetColor(Vector4(1.0, 1.0, 1.0, 0.5));
720 actor.SetSize(100, 50);
721 application.GetGlAbstraction().EnableCullFaceCallTrace(true); // For Enable(GL_BLEND)
722 Stage::GetCurrent().Add(actor);
724 application.SendNotification();
725 application.Render();
727 const TraceCallStack& callTrace = application.GetGlAbstraction().GetCullFaceTrace();
728 DALI_TEST_EQUALS( BlendDisabled( callTrace ), false, TEST_LOCATION );
729 DALI_TEST_EQUALS( BlendEnabled( callTrace), true, TEST_LOCATION );
733 int UtcDaliImageActorUseImageAlpha04(void)
735 TestApplication application;
737 tet_infoline("Testing Dali::RenderableActor::SetUseImageAlpha()");
739 FrameBufferImage image = FrameBufferImage::New( 100, 50, Pixel::RGBA8888 );
740 RenderTaskList taskList = Stage::GetCurrent().GetRenderTaskList();
741 RenderTask task = taskList.GetTask( 0u );
742 task.SetTargetFrameBuffer( image ); // To ensure frame buffer is connected
743 application.GetGlAbstraction().SetCheckFramebufferStatusResult( GL_FRAMEBUFFER_COMPLETE );
744 application.SendNotification();
745 application.Render(0);
747 ImageActor actor = ImageActor::New( image );
748 application.SendNotification();
749 application.Render(0);
751 actor.SetBlendMode( BlendingMode::ON );
752 actor.SetColor(Vector4(1.0, 1.0, 1.0, 1.0));
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 UtcDaliImageActorUseImageAlpha05(void)
768 TestApplication application;
770 tet_infoline("Testing Dali::RenderableActor::SetUseImageAlpha()");
772 BitmapImage image = BitmapImage::New( 100, 50, Pixel::RGB888 );
773 ImageActor actor = ImageActor::New( image );
774 actor.SetBlendMode( BlendingMode::AUTO );
775 actor.SetColor(Vector4(1.0, 1.0, 1.0, 1.0));
776 actor.SetSize(100, 50);
777 application.GetGlAbstraction().EnableCullFaceCallTrace(true); // For Enable(GL_BLEND)
778 Stage::GetCurrent().Add(actor);
780 application.SendNotification();
781 application.Render();
783 const TraceCallStack& callTrace = application.GetGlAbstraction().GetCullFaceTrace();
784 DALI_TEST_EQUALS( BlendDisabled( callTrace ), false, TEST_LOCATION );
785 DALI_TEST_EQUALS( BlendEnabled( callTrace), false, TEST_LOCATION );
789 int UtcDaliImageActorClearPixelArea(void)
791 TestApplication application;
793 BitmapImage img = BitmapImage::New( 10, 10 );
794 ImageActor actor = ImageActor::New( img );
796 DALI_TEST_CHECK( actor.IsPixelAreaSet() == false );
798 ImageActor::PixelArea area( 1, 2, 3, 4 );
799 actor.SetPixelArea( area );
801 DALI_TEST_CHECK( actor.IsPixelAreaSet() == true );
803 actor.ClearPixelArea();
805 DALI_TEST_CHECK( actor.IsPixelAreaSet() == false );
809 int UtcDaliImageGetStyle(void)
811 TestApplication application;
813 Image image = Image::New(TestImageFilename);
814 ImageActor actor = ImageActor::New(image);
816 actor.SetStyle(ImageActor::STYLE_NINE_PATCH);
818 // flush the queue and render once
819 application.SendNotification();
820 application.Render();
822 DALI_TEST_EQUALS( ImageActor::STYLE_NINE_PATCH, actor.GetStyle(), TEST_LOCATION );
826 int UtcDaliImageSetNinePatchBorder(void)
828 TestApplication application;
830 Image image = Image::New(TestImageFilename);
831 ImageActor actor = ImageActor::New(image);
833 actor.SetStyle(ImageActor::STYLE_NINE_PATCH);
834 actor.SetNinePatchBorder(Vector4( 1.0f, 2.0f, 3.0f, 4.0f));
836 DALI_TEST_EQUALS( 1.0f, actor.GetNinePatchBorder().x, TEST_LOCATION );
837 DALI_TEST_EQUALS( 2.0f, actor.GetNinePatchBorder().y, TEST_LOCATION );
838 DALI_TEST_EQUALS( 3.0f, actor.GetNinePatchBorder().z, TEST_LOCATION );
839 DALI_TEST_EQUALS( 4.0f, actor.GetNinePatchBorder().w, TEST_LOCATION );
843 int UtcDaliImageSetFadeIn(void)
845 TestApplication application;
847 Image image = Image::New(TestImageFilename);
848 ImageActor actor = ImageActor::New(image);
850 actor.SetFadeIn(true);
852 // flush the queue and render once
853 application.SendNotification();
854 application.Render();
856 DALI_TEST_EQUALS( true, actor.GetFadeIn(), TEST_LOCATION );
858 actor.SetFadeIn(false);
860 // flush the queue and render once
861 application.SendNotification();
862 application.Render();
864 DALI_TEST_EQUALS( false, actor.GetFadeIn(), TEST_LOCATION );
869 int UtcDaliImageSetFadeInDuration(void)
871 TestApplication application;
873 Image image = Image::New(TestImageFilename);
874 ImageActor actor = ImageActor::New(image);
876 actor.SetFadeInDuration( 1.0f );
878 // flush the queue and render once
879 application.SendNotification();
880 application.Render();
882 DALI_TEST_EQUALS( 1.0f, actor.GetFadeInDuration(), TEST_LOCATION );
884 actor.SetFadeInDuration( 3.0f );
886 // flush the queue and render once
887 application.SendNotification();
888 application.Render();
890 DALI_TEST_EQUALS( 3.0f, actor.GetFadeInDuration(), TEST_LOCATION );
894 int UtcDaliImageActorNewNull(void)
896 TestApplication application;
898 ImageActor actor = ImageActor::New(Image());
900 DALI_TEST_CHECK(actor);
904 int UtcDaliImageActorNewNullWithArea(void)
906 TestApplication application;
908 ImageActor::PixelArea area( 1, 2, 3, 4 );
910 ImageActor actor = ImageActor::New(Image(), area);
912 DALI_TEST_CHECK(actor);
916 int UtcDaliImageActorSetImage(void)
918 TestApplication application;
920 ImageActor actor = ImageActor::New(Image());
922 DALI_TEST_CHECK(actor);
924 actor.SetImage( Image() );
926 DALI_TEST_CHECK(!actor.GetImage());
930 int UtcDaliImageActorPropertyIndices(void)
932 TestApplication application;
933 Actor basicActor = Actor::New();
934 ImageActor imageActor = ImageActor::New();
936 Property::IndexContainer indices;
937 imageActor.GetPropertyIndices( indices );
938 DALI_TEST_CHECK( indices.size() > basicActor.GetPropertyCount() );
939 DALI_TEST_EQUALS( indices.size(), imageActor.GetPropertyCount(), TEST_LOCATION );
943 int UtcDaliImageActorImageProperty(void)
945 TestApplication application;
946 Image image = Image::New( "MY_PATH" );
947 ImageActor imageActor = ImageActor::New( image );
949 Stage::GetCurrent().Add( imageActor );
950 application.SendNotification();
951 application.Render();
953 Property::Value imageMap = imageActor.GetProperty( ImageActor::IMAGE );
954 DALI_TEST_CHECK( imageMap.HasKey( "filename" ) );
955 DALI_TEST_EQUALS( imageMap.GetValue( "filename" ).Get< std::string >(), "MY_PATH", TEST_LOCATION );
959 int UtcDaliImageActorNinePatch01(void)
961 TestApplication application;
962 TestPlatformAbstraction& platform = application.GetPlatform();
963 TestGlAbstraction& glAbstraction = application.GetGlAbstraction();
964 TraceCallStack& textureTrace = glAbstraction.GetTextureTrace();
965 TraceCallStack& drawTrace = glAbstraction.GetDrawTrace();
967 tet_infoline("Test the successful loading of a nine-patch image\n");
969 platform.SetClosestImageSize(Vector2(4, 4));
970 Integration::Bitmap* bitmap = Integration::Bitmap::New( Integration::Bitmap::BITMAP_2D_PACKED_PIXELS, false );
971 Integration::PixelBuffer* pixels = bitmap->GetPackedPixelsProfile()->ReserveBuffer( Pixel::RGBA8888, 4,4,4,4 );
972 memset( pixels, 0, 64 );
974 Integration::ResourcePointer resourcePtr(bitmap); // reference it
975 platform.SetResourceLoaded( 0, Dali::Integration::ResourceBitmap, resourcePtr );
977 Image ninePatchImage = Image::New( "blah.#.png" );
978 DALI_TEST_CHECK( ninePatchImage );
980 ImageActor imageActor = ImageActor::New( ninePatchImage );
981 DALI_TEST_CHECK( imageActor );
982 Stage::GetCurrent().Add( imageActor );
985 textureTrace.Reset();
986 drawTrace.Enable(true);
987 textureTrace.Enable(true);
988 glAbstraction.ClearBoundTextures();
989 std::vector<GLuint> ids;
991 glAbstraction.SetNextTextureIds( ids );
993 application.SendNotification();
994 application.Render();
996 DALI_TEST_CHECK( drawTrace.FindMethod( "DrawArrays" ) );
997 typedef std::vector<GLuint> TexVec;
998 const TexVec& textures = glAbstraction.GetBoundTextures(GL_TEXTURE0);
999 DALI_TEST_CHECK( textures.size() > 0 );
1000 if( textures.size() > 0 )
1002 DALI_TEST_EQUALS( textures[0], 23u, TEST_LOCATION );
1009 int UtcDaliImageActorNinePatch02(void)
1011 TestApplication application;
1012 TestPlatformAbstraction& platform = application.GetPlatform();
1013 TestGlAbstraction& glAbstraction = application.GetGlAbstraction();
1014 TraceCallStack& textureTrace = glAbstraction.GetTextureTrace();
1015 TraceCallStack& drawTrace = glAbstraction.GetDrawTrace();
1017 tet_infoline("Test the failed loading of a nine-patch image\n");
1019 platform.SetClosestImageSize(Vector2(0, 0));
1020 Integration::ResourcePointer resourcePtr;
1021 platform.SetResourceLoaded( 0, Dali::Integration::ResourceBitmap, resourcePtr );
1023 Image ninePatchImage = Image::New( "blah.#.png" );
1024 DALI_TEST_CHECK( ninePatchImage );
1026 ImageActor imageActor = ImageActor::New( ninePatchImage );
1027 DALI_TEST_CHECK( imageActor );
1028 Stage::GetCurrent().Add( imageActor );
1031 textureTrace.Reset();
1032 drawTrace.Enable(true);
1033 textureTrace.Enable(true);
1034 glAbstraction.ClearBoundTextures();
1035 std::vector<GLuint> ids;
1036 ids.push_back( 23 );
1037 glAbstraction.SetNextTextureIds( ids );
1039 application.SendNotification();
1040 application.Render();
1042 // Check that nothing was drawn.
1043 DALI_TEST_CHECK( ! drawTrace.FindMethod( "DrawArrays" ) );
1044 typedef std::vector<GLuint> TexVec;
1045 const TexVec& textures = glAbstraction.GetBoundTextures(GL_TEXTURE0);
1046 DALI_TEST_CHECK( textures.size() == 0u );
1052 int UtcDaliImageActorNinePatch03(void)
1054 TestApplication application;
1055 TestPlatformAbstraction& platform = application.GetPlatform();
1056 TestGlAbstraction& glAbstraction = application.GetGlAbstraction();
1057 TraceCallStack& textureTrace = glAbstraction.GetTextureTrace();
1058 TraceCallStack& drawTrace = glAbstraction.GetDrawTrace();
1060 tet_infoline("Test the successful loading of a nine-patch image added using ImageActor::SetImage()\n");
1062 platform.SetClosestImageSize(Vector2(4, 4));
1063 Integration::Bitmap* bitmap = Integration::Bitmap::New( Integration::Bitmap::BITMAP_2D_PACKED_PIXELS, false );
1064 Integration::PixelBuffer* pixels = bitmap->GetPackedPixelsProfile()->ReserveBuffer( Pixel::RGBA8888, 4,4,4,4 );
1065 memset( pixels, 0, 64 );
1067 Integration::ResourcePointer resourcePtr(bitmap); // reference it
1068 platform.SetResourceLoaded( 0, Dali::Integration::ResourceBitmap, resourcePtr );
1070 Image ninePatchImage = Image::New( "blah.#.png" );
1071 DALI_TEST_CHECK( ninePatchImage );
1073 ImageActor imageActor = ImageActor::New();
1074 DALI_TEST_CHECK( imageActor );
1075 Stage::GetCurrent().Add( imageActor );
1077 imageActor.SetImage( ninePatchImage );
1080 textureTrace.Reset();
1081 drawTrace.Enable(true);
1082 textureTrace.Enable(true);
1083 glAbstraction.ClearBoundTextures();
1084 std::vector<GLuint> ids;
1085 ids.push_back( 23 );
1086 glAbstraction.SetNextTextureIds( ids );
1088 application.SendNotification();
1089 application.Render();
1091 DALI_TEST_CHECK( drawTrace.FindMethod( "DrawArrays" ) );
1092 typedef std::vector<GLuint> TexVec;
1093 const TexVec& textures = glAbstraction.GetBoundTextures(GL_TEXTURE0);
1094 DALI_TEST_CHECK( textures.size() > 0 );
1095 if( textures.size() > 0 )
1097 DALI_TEST_EQUALS( textures[0], 23u, TEST_LOCATION );
1104 int UtcDaliImageActorNinePatch04(void)
1106 TestApplication application;
1107 TestPlatformAbstraction& platform = application.GetPlatform();
1108 TestGlAbstraction& glAbstraction = application.GetGlAbstraction();
1109 TraceCallStack& textureTrace = glAbstraction.GetTextureTrace();
1110 TraceCallStack& drawTrace = glAbstraction.GetDrawTrace();
1112 tet_infoline("Test the failed loading of a nine-patch image using ImageActor::SetImage()\n");
1114 platform.SetClosestImageSize(Vector2(0, 0));
1115 Integration::ResourcePointer resourcePtr;
1116 platform.SetResourceLoaded( 0, Dali::Integration::ResourceBitmap, resourcePtr );
1118 Image ninePatchImage = Image::New( "blah.#.png" );
1119 DALI_TEST_CHECK( ninePatchImage );
1121 ImageActor imageActor = ImageActor::New();
1122 DALI_TEST_CHECK( imageActor );
1123 Stage::GetCurrent().Add( imageActor );
1125 imageActor.SetImage( ninePatchImage );
1128 textureTrace.Reset();
1129 drawTrace.Enable(true);
1130 textureTrace.Enable(true);
1131 glAbstraction.ClearBoundTextures();
1132 std::vector<GLuint> ids;
1133 ids.push_back( 23 );
1134 glAbstraction.SetNextTextureIds( ids );
1136 application.SendNotification();
1137 application.Render();
1139 // Check that nothing was drawn.
1140 DALI_TEST_CHECK( ! drawTrace.FindMethod( "DrawArrays" ) );
1141 typedef std::vector<GLuint> TexVec;
1142 const TexVec& textures = glAbstraction.GetBoundTextures(GL_TEXTURE0);
1143 DALI_TEST_CHECK( textures.size() == 0u );