2 // Copyright (c) 2014 Samsung Electronics Co., Ltd.
4 // Licensed under the Flora License, Version 1.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://floralicense.org/license/
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.
19 #include <dali/dali.h>
20 #include "dali-test-suite-utils/dali-test-suite-utils.h"
24 static const char* TestImageFilename = "icon_wrt.png";
26 void image_actor_test_startup(void)
28 test_return_value = TET_UNDEF;
31 void image_actor_test_cleanup(void)
33 test_return_value = TET_PASS;
37 int UtcDaliImageActorConstructorVoid(void)
39 TestApplication application;
40 tet_infoline("Testing Dali::ImageActor::ImageActor()");
44 DALI_TEST_CHECK(!actor);
48 int UtcDaliImageActorDestructor(void)
50 TestApplication application;
52 ImageActor* actor = new ImageActor();
55 DALI_TEST_CHECK( true );
59 int UtcDaliImageActorNew01(void)
61 TestApplication application;
62 tet_infoline("Positive test for Dali::ImageActor::New()");
64 Image image = Image::New(TestImageFilename);
65 ImageActor actor = ImageActor::New(image);
66 Stage::GetCurrent().Add(actor);
68 application.SendNotification();
71 application.SendNotification();
73 DALI_TEST_CHECK(application.GetPlatform().WasCalled(TestPlatformAbstraction::LoadResourceFunc));
75 DALI_TEST_CHECK(actor);
79 int UtcDaliImageActorNew02(void)
81 TestApplication application;
82 tet_infoline("Negative test for Dali::ImageActor::New()");
84 Image image = Image::New("hopefully-this-image-file-does-not-exist");
85 ImageActor actor = ImageActor::New(image);
87 DALI_TEST_CHECK(actor);
91 int UtcDaliImageActorDownCast(void)
93 TestApplication application;
94 tet_infoline("Testing Dali::ImageActor::DownCast()");
96 Image image = Image::New("IncorrectImageName");
97 ImageActor actor1 = ImageActor::New(image);
98 Actor anActor = Actor::New();
101 Actor child = anActor.GetChildAt(0);
102 ImageActor imageActor = DownCast< ImageActor >(child);
104 DALI_TEST_CHECK(imageActor);
108 int UtcDaliImageActorDownCast2(void)
110 TestApplication application;
111 tet_infoline("Testing Dali::ImageActor::DownCast()");
113 Actor actor1 = Actor::New();
114 Actor anActor = Actor::New();
117 Actor child = anActor.GetChildAt(0);
118 ImageActor imageActor = ImageActor::DownCast(child);
119 DALI_TEST_CHECK(!imageActor);
121 Actor unInitialzedActor;
122 imageActor = ImageActor::DownCast( unInitialzedActor );
123 DALI_TEST_CHECK(!imageActor);
127 int UtcDaliImageActor9Patch(void)
129 TestApplication application;
130 tet_infoline("Positive test for Dali::ImageActor:: 9 patch api");
132 Image image = Image::New(TestImageFilename);
133 ImageActor actor = ImageActor::New(image);
135 actor.SetStyle(ImageActor::STYLE_NINE_PATCH);
136 Vector4 border(0.1,0.2,0.3,0.4);
137 actor.SetNinePatchBorder(border);
139 DALI_TEST_EQUALS( 0.1f, actor.GetNinePatchBorder().x, TEST_LOCATION );
140 DALI_TEST_EQUALS( 0.2f, actor.GetNinePatchBorder().y, TEST_LOCATION );
141 DALI_TEST_EQUALS( 0.3f, actor.GetNinePatchBorder().z, TEST_LOCATION );
142 DALI_TEST_EQUALS( 0.4f, actor.GetNinePatchBorder().w, TEST_LOCATION );
146 int UtcDaliImageActorPixelArea(void)
148 TestApplication application;
149 tet_infoline("Positive test for Dali::ImageActor::UtcDaliImageActorPixelArea");
151 BitmapImage img = BitmapImage::New( 10, 10 );
152 ImageActor actor = ImageActor::New( img );
154 DALI_TEST_CHECK( actor.IsPixelAreaSet() == false );
156 ImageActor::PixelArea area( 1, 2, 3, 4 );
157 actor.SetPixelArea( area );
159 DALI_TEST_CHECK( actor.IsPixelAreaSet() == true );
161 DALI_TEST_EQUALS( 1, actor.GetPixelArea().x, TEST_LOCATION );
162 DALI_TEST_EQUALS( 2, actor.GetPixelArea().y, TEST_LOCATION );
163 DALI_TEST_EQUALS( 3, actor.GetPixelArea().width, TEST_LOCATION );
164 DALI_TEST_EQUALS( 4, actor.GetPixelArea().height, TEST_LOCATION );
166 ImageActor actor2 = ImageActor::New( img, ImageActor::PixelArea( 5, 6, 7, 8 ) );
167 DALI_TEST_CHECK( actor2.IsPixelAreaSet() == true );
169 DALI_TEST_EQUALS( 5, actor2.GetPixelArea().x, TEST_LOCATION );
170 DALI_TEST_EQUALS( 6, actor2.GetPixelArea().y, TEST_LOCATION );
171 DALI_TEST_EQUALS( 7, actor2.GetPixelArea().width, TEST_LOCATION );
172 DALI_TEST_EQUALS( 8, actor2.GetPixelArea().height, TEST_LOCATION );
176 int UtcDaliImageActorGetCurrentImageSize01(void)
178 TestApplication application;
179 tet_infoline("Positive test for Dali::ImageActor::GetCurrentImageSize");
181 Vector2 initialImageSize(100, 50);
182 BitmapImage image = BitmapImage::New( initialImageSize.width, initialImageSize.height );
183 ImageActor actor = ImageActor::New( image );
184 Stage::GetCurrent().Add(actor);
186 application.SendNotification();
187 application.Render();
189 DALI_TEST_EQUALS( actor.GetCurrentImageSize(), initialImageSize, TEST_LOCATION );
191 Vector2 size(200.0f, 200.0f);
194 // flush the queue and render once
195 application.SendNotification();
196 application.Render();
197 DALI_TEST_EQUALS( actor.GetCurrentImageSize(), size, TEST_LOCATION );
202 application.Render(8);
204 // Test when a pixel area is set
205 ImageActor::PixelArea area(0, 0, 10, 10);
206 actor.SetPixelArea(area);
207 application.Render(9);
208 DALI_TEST_EQUALS( actor.GetCurrentImageSize(), Vector2( area.width, area.height ), TEST_LOCATION );
213 int UtcDaliImageActorGetCurrentImageSize02(void)
215 TestApplication application;
216 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");
218 Vector2 initialImageSize(100, 50);
220 application.GetPlatform().SetClosestImageSize(initialImageSize);
222 Image image = Image::New("image.jpg");
223 ImageActor actor = ImageActor::New( image );
224 Stage::GetCurrent().Add(actor);
226 application.SendNotification(); // Flush update messages
227 application.Render(); // Process resource request
228 application.SendNotification(); // Flush update messages
229 application.Render(); // Process resource request
231 DALI_TEST_EQUALS( actor.GetCurrentImageSize(), initialImageSize, TEST_LOCATION );
233 // Now complete the image load
234 Integration::ResourceRequest* req = application.GetPlatform().GetRequest();
235 Integration::Bitmap* bitmap = Integration::Bitmap::New( Integration::Bitmap::BITMAP_2D_PACKED_PIXELS, false );
236 bitmap->GetPackedPixelsProfile()->ReserveBuffer( Pixel::RGBA8888, initialImageSize.width,initialImageSize.height, initialImageSize.width,initialImageSize.height );
238 Integration::ResourcePointer resourcePtr(bitmap); // reference it
239 application.GetPlatform().SetResourceLoaded(req->GetId(), req->GetType()->id, resourcePtr);
240 application.Render(); // Process LoadComplete
241 application.SendNotification(); // Process event messages
242 application.GetPlatform().DiscardRequest(); // Ensure load request is discarded
243 application.GetPlatform().ClearReadyResources(); //
245 DALI_TEST_EQUALS( actor.GetCurrentImageSize(), initialImageSize, TEST_LOCATION );
247 Vector2 size(200.0f, 200.0f);
250 // flush the queue and render once
251 application.SendNotification();
252 application.Render();
253 DALI_TEST_EQUALS( actor.GetCurrentImageSize(), size, TEST_LOCATION );
255 actor.SetToNaturalSize();
256 application.SendNotification();
257 application.Render();
258 DALI_TEST_EQUALS( actor.GetCurrentImageSize(), initialImageSize, TEST_LOCATION );
263 int UtcDaliImageActorGetCurrentImageSize03(void)
265 TestApplication application;
266 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");
268 Vector2 closestImageSize( 80, 45);
270 application.GetPlatform().SetClosestImageSize(closestImageSize);
272 ImageAttributes attrs;
273 attrs.SetSize(40, 30);
274 Image image = Image::New("image.jpg", attrs);
275 ImageActor actor = ImageActor::New( image );
276 Stage::GetCurrent().Add(actor);
278 application.SendNotification(); // Flush update messages
279 application.Render(); // Process resource request
280 application.SendNotification(); // Flush update messages
281 application.Render(); // Process resource request
283 DALI_TEST_EQUALS( actor.GetCurrentImageSize(), closestImageSize, TEST_LOCATION );
285 // Now complete the image load
286 Integration::ResourceRequest* req = application.GetPlatform().GetRequest();
287 Integration::Bitmap* bitmap = Integration::Bitmap::New( Integration::Bitmap::BITMAP_2D_PACKED_PIXELS, false );
288 bitmap->GetPackedPixelsProfile()->ReserveBuffer( Pixel::RGBA8888, closestImageSize.width, closestImageSize.height, closestImageSize.width, closestImageSize.height );
290 Integration::ResourcePointer resourcePtr(bitmap); // reference it
291 application.GetPlatform().SetResourceLoaded(req->GetId(), req->GetType()->id, resourcePtr);
292 application.Render(); // Process LoadComplete
293 application.SendNotification(); // Process event messages
294 application.GetPlatform().DiscardRequest(); // Ensure load request is discarded
295 application.GetPlatform().ClearReadyResources(); //
297 DALI_TEST_EQUALS( actor.GetCurrentImageSize(), closestImageSize, TEST_LOCATION );
299 // Test that setting a size on the actor can be 'undone' with SetNaturalSize()
300 Vector2 size(200.0f, 200.0f);
303 // flush the queue and render once
304 application.SendNotification();
305 application.Render();
306 DALI_TEST_EQUALS( actor.GetCurrentImageSize(), size, TEST_LOCATION );
308 actor.SetToNaturalSize();
309 application.SendNotification();
310 application.Render();
311 DALI_TEST_EQUALS( actor.GetCurrentImageSize(), closestImageSize, TEST_LOCATION );
316 int UtcDaliImageActorGetCurrentImageSize04(void)
318 TestApplication application;
319 tet_infoline("Positive test for Dali::ImageActor::GetCurrentImageSize - check a new image doesn't change a set actor size");
321 Vector2 closestImageSize( 80, 45);
322 application.GetPlatform().SetClosestImageSize(closestImageSize);
324 ImageAttributes attrs;
325 attrs.SetSize(40, 30); // Request a really small size we won't get.
326 Image image = Image::New("image.jpg", attrs);
327 ImageActor actor = ImageActor::New( image );
328 Stage::GetCurrent().Add(actor);
330 application.SendNotification(); // Flush update messages
331 application.Render(); // Process resource request
333 DALI_TEST_EQUALS( actor.GetCurrentImageSize(), closestImageSize, TEST_LOCATION );
335 // Now complete the image load
336 Integration::ResourceRequest* req = application.GetPlatform().GetRequest();
337 Integration::Bitmap* bitmap = Integration::Bitmap::New( Integration::Bitmap::BITMAP_2D_PACKED_PIXELS, false );
338 bitmap->GetPackedPixelsProfile()->ReserveBuffer( Pixel::RGBA8888, closestImageSize.width, closestImageSize.height, closestImageSize.width, closestImageSize.height );
340 Integration::ResourcePointer resourcePtr(bitmap); // reference it
341 application.GetPlatform().SetResourceLoaded(req->GetId(), req->GetType()->id, resourcePtr);
342 application.Render(); // Process LoadComplete
343 application.SendNotification(); // Process event messages
344 application.GetPlatform().DiscardRequest(); // Ensure load request is discarded
345 application.GetPlatform().ClearReadyResources(); //
347 DALI_TEST_EQUALS( actor.GetCurrentImageSize(), closestImageSize, TEST_LOCATION );
349 Vector2 size(200.0f, 200.0f);
352 // flush the queue and render once
353 application.SendNotification();
354 application.Render();
355 DALI_TEST_EQUALS( actor.GetCurrentImageSize(), size, TEST_LOCATION );
357 // Load a different image
359 Vector2 image2ClosestSize = Vector2(240, 150); // The actual size image loader will return for the request below
360 application.GetPlatform().SetClosestImageSize(image2ClosestSize);
362 attrs.SetSize(100, 100);
363 Image image2 = Image::New("image2.jpg", attrs);
364 actor.SetImage(image2);
366 application.SendNotification(); // Flush update messages
367 application.Render(); // Process resource request
368 application.SendNotification(); // Flush update messages
369 application.Render(); // Process resource request
371 // Ensure the actor size is kept
372 DALI_TEST_EQUALS( actor.GetCurrentImageSize(), size, TEST_LOCATION );
374 // Now complete the image load
375 req = application.GetPlatform().GetRequest();
376 Integration::Bitmap* bitmap2 = Integration::Bitmap::New( Integration::Bitmap::BITMAP_2D_PACKED_PIXELS, false );
377 bitmap2->GetPackedPixelsProfile()->ReserveBuffer( Pixel::RGBA8888, image2ClosestSize.width, image2ClosestSize.height, image2ClosestSize.width, image2ClosestSize.height );
379 Integration::ResourcePointer resourcePtr2(bitmap2); // reference it
380 application.GetPlatform().SetResourceLoaded(req->GetId(), req->GetType()->id, resourcePtr2);
381 application.Render(); // Process LoadComplete
382 application.SendNotification(); // Process event messages
383 application.GetPlatform().DiscardRequest(); // Ensure load request is discarded
384 application.GetPlatform().ClearReadyResources(); //
386 // Ensure the actor size is kept
387 DALI_TEST_EQUALS( actor.GetCurrentImageSize(), size, TEST_LOCATION );
389 actor.SetToNaturalSize();
390 application.SendNotification();
391 application.Render();
392 // Ensure the actor size gets the new image's natural size
393 DALI_TEST_EQUALS( actor.GetCurrentImageSize(), image2ClosestSize, TEST_LOCATION );
398 int UtcDaliImageActorGetCurrentImageSize05(void)
400 TestApplication application;
401 tet_infoline("Positive test for Dali::ImageActor::GetCurrentImageSize - check a new image doens't change actor size until load complete");
403 Vector2 closestImageSize( 80, 45);
404 application.GetPlatform().SetClosestImageSize(closestImageSize);
406 ImageAttributes attrs;
407 attrs.SetSize(40, 30); // Request a really small size we won't get.
408 Image image = Image::New("image.jpg", attrs);
409 ImageActor actor = ImageActor::New( image );
410 Stage::GetCurrent().Add(actor);
412 application.SendNotification(); // Flush update messages
413 application.Render(); // Process resource request
415 DALI_TEST_EQUALS( actor.GetCurrentImageSize(), closestImageSize, TEST_LOCATION );
417 // Now complete the image load
418 Integration::ResourceRequest* req = application.GetPlatform().GetRequest();
419 Integration::Bitmap* bitmap = Integration::Bitmap::New( Integration::Bitmap::BITMAP_2D_PACKED_PIXELS, false );
420 bitmap->GetPackedPixelsProfile()->ReserveBuffer( Pixel::RGBA8888, closestImageSize.width, closestImageSize.height, closestImageSize.width, closestImageSize.height );
422 Integration::ResourcePointer resourcePtr(bitmap); // reference it
423 application.GetPlatform().SetResourceLoaded(req->GetId(), req->GetType()->id, resourcePtr);
424 application.Render(); // Process LoadComplete
425 application.SendNotification(); // Process event messages
426 application.GetPlatform().DiscardRequest(); // Ensure load request is discarded
427 application.GetPlatform().ClearReadyResources(); //
429 DALI_TEST_EQUALS( actor.GetCurrentImageSize(), closestImageSize, TEST_LOCATION );
431 // Load a different image
433 Vector2 image2ClosestSize = Vector2(240, 150);
434 application.GetPlatform().SetClosestImageSize(image2ClosestSize);
436 attrs.SetSize(100, 100);
437 Image image2 = Image::New("image2.jpg", attrs);
438 actor.SetImage(image2);
440 application.SendNotification(); // Flush update messages
441 application.Render(); // Process resource request
442 application.SendNotification(); // Flush update messages
443 application.Render(); // Process resource request
445 // Ensure the actor size is kept
446 DALI_TEST_EQUALS( actor.GetCurrentImageSize(), closestImageSize, TEST_LOCATION );
448 // Now complete the image load
449 req = application.GetPlatform().GetRequest();
450 Integration::Bitmap* bitmap2 = Integration::Bitmap::New( Integration::Bitmap::BITMAP_2D_PACKED_PIXELS, false );
451 bitmap2->GetPackedPixelsProfile()->ReserveBuffer( Pixel::RGBA8888, image2ClosestSize.width, image2ClosestSize.height, image2ClosestSize.width, image2ClosestSize.height );
453 Integration::ResourcePointer resourcePtr2(bitmap2); // reference it
454 application.GetPlatform().SetResourceLoaded(req->GetId(), req->GetType()->id, resourcePtr2);
455 application.Render(); // Process LoadComplete
456 application.SendNotification(); // Process event messages
457 application.GetPlatform().DiscardRequest(); // Ensure load request is discarded
458 application.GetPlatform().ClearReadyResources(); //
460 application.SendNotification(); // Process event messages
461 application.Render(); // Process LoadComplete
463 // Ensure the actor size gets the new image's natural size
464 DALI_TEST_EQUALS( actor.GetCurrentImageSize(), image2ClosestSize, TEST_LOCATION );
468 int UtcDaliImageActorNaturalPixelAreaSize01(void)
470 TestApplication application;
471 tet_infoline("Positive test for Dali::ImageActor::GetCurrentImageSize - check a new image doens't change actor size until load complete");
473 //If an image is loaded without setting size, then the actor gets the natural size of the image
474 //Setting the pixel area will change the actor size to match the pixel area
475 //Setting the actor size will not change pixel area, and will cause the partial image to stretch
477 //Clearing the pixel area will not change actor size, and the actor will show the whole image.
480 Vector2 closestImageSize( 80, 45);
481 application.GetPlatform().SetClosestImageSize(closestImageSize);
483 ImageAttributes attrs;
484 attrs.SetSize(40, 30); // Request a really small size we won't get.
485 Image image = Image::New("image.jpg", attrs);
486 ImageActor actor = ImageActor::New( image );
487 Stage::GetCurrent().Add(actor);
489 application.SendNotification(); // Flush update messages
490 application.Render(); // Process resource request
492 DALI_TEST_EQUALS( actor.GetCurrentImageSize(), closestImageSize, TEST_LOCATION );
493 DALI_TEST_EQUALS( Vector2(actor.GetCurrentSize()), closestImageSize, TEST_LOCATION );
495 // Now complete the image load
496 Integration::ResourceRequest* req = application.GetPlatform().GetRequest();
497 Integration::Bitmap* bitmap = Integration::Bitmap::New( Integration::Bitmap::BITMAP_2D_PACKED_PIXELS, false );
498 bitmap->GetPackedPixelsProfile()->ReserveBuffer( Pixel::RGBA8888, closestImageSize.width, closestImageSize.height, closestImageSize.width, closestImageSize.height );
500 Integration::ResourcePointer resourcePtr(bitmap); // reference it
501 application.GetPlatform().SetResourceLoaded(req->GetId(), req->GetType()->id, resourcePtr);
502 application.Render(); // Process LoadComplete
503 application.SendNotification(); // Process event messages
504 application.GetPlatform().DiscardRequest(); // Ensure load request is discarded
505 application.GetPlatform().ClearReadyResources(); //
507 DALI_TEST_EQUALS( actor.GetCurrentImageSize(), closestImageSize, TEST_LOCATION );
508 DALI_TEST_EQUALS( Vector2(actor.GetCurrentSize()), closestImageSize, TEST_LOCATION );
510 // Set a pixel area on a naturally sized actor - expect the actor to take the
511 // pixel area as size
512 actor.SetPixelArea(ImageActor::PixelArea(0, 0, 30, 30));
513 application.SendNotification(); // Process event messages
514 application.Render(); // Process LoadComplete
515 DALI_TEST_EQUALS( actor.GetCurrentImageSize(), Vector2(30, 30), TEST_LOCATION );
516 DALI_TEST_EQUALS( Vector2(actor.GetCurrentSize()), Vector2(30, 30), TEST_LOCATION );
518 // Set a size. Expect the partial image to stretch to fill the new size
519 actor.SetSize(100, 100);
520 application.SendNotification(); // Process event messages
521 application.Render(); // Process LoadComplete
522 application.Render(); // Process LoadComplete
523 DALI_TEST_EQUALS( actor.GetCurrentImageSize(), Vector2(30, 30), TEST_LOCATION );
524 DALI_TEST_EQUALS( Vector2(actor.GetCurrentSize()), Vector2(100, 100), TEST_LOCATION );
526 // Clear the pixel area. Expect the whole image to be shown, filling the set size.
527 actor.ClearPixelArea();
528 application.SendNotification(); // Process event messages
529 application.Render(); // Process LoadComplete
530 DALI_TEST_EQUALS( actor.GetCurrentImageSize(), Vector2(100, 100), TEST_LOCATION );
531 DALI_TEST_EQUALS( Vector2(actor.GetCurrentSize()), Vector2(100, 100), TEST_LOCATION );
535 int UtcDaliImageActorNaturalPixelAreaSize02(void)
537 TestApplication application;
538 tet_infoline("Positive test for Dali::ImageActor::GetCurrentImageSize - check a new image doens't change actor size until load complete");
540 //If an image is loaded without setting size, then the actor gets the natural size of the image
541 //Setting the pixel area will change the actor size to match the pixel area
542 //Setting the actor size will not change pixel area, and will cause the partial image to stretch
544 //Clearing the pixel area will not change actor size, and the actor will show the whole image.
547 Vector2 closestImageSize( 80, 45);
548 application.GetPlatform().SetClosestImageSize(closestImageSize);
550 ImageAttributes attrs;
551 attrs.SetSize(40, 30); // Request a really small size we won't get.
552 Image image = Image::New("image.jpg", attrs);
553 ImageActor actor = ImageActor::New( image );
554 Stage::GetCurrent().Add(actor);
556 application.SendNotification(); // Flush update messages
557 application.Render(); // Process resource request
559 DALI_TEST_EQUALS( actor.GetCurrentImageSize(), closestImageSize, TEST_LOCATION );
560 DALI_TEST_EQUALS( Vector2(actor.GetCurrentSize()), closestImageSize, TEST_LOCATION );
562 // Now complete the image load
563 Integration::ResourceRequest* req = application.GetPlatform().GetRequest();
564 Integration::Bitmap* bitmap = Integration::Bitmap::New( Integration::Bitmap::BITMAP_2D_PACKED_PIXELS, false );
565 bitmap->GetPackedPixelsProfile()->ReserveBuffer( Pixel::RGBA8888, closestImageSize.width, closestImageSize.height, closestImageSize.width, closestImageSize.height );
567 Integration::ResourcePointer resourcePtr(bitmap); // reference it
568 application.GetPlatform().SetResourceLoaded(req->GetId(), req->GetType()->id, resourcePtr);
569 application.Render(); // Process LoadComplete
570 application.SendNotification(); // Process event messages
571 application.GetPlatform().DiscardRequest(); // Ensure load request is discarded
572 application.GetPlatform().ClearReadyResources(); //
574 DALI_TEST_EQUALS( actor.GetCurrentImageSize(), closestImageSize, TEST_LOCATION );
575 DALI_TEST_EQUALS( Vector2(actor.GetCurrentSize()), closestImageSize, TEST_LOCATION );
577 // Set a pixel area on a naturally sized actor - expect the actor to take the
578 // pixel area as size
579 actor.SetPixelArea(ImageActor::PixelArea(0, 0, 30, 30));
580 application.SendNotification(); // Process event messages
581 application.Render(); // Process LoadComplete
582 DALI_TEST_EQUALS( actor.GetCurrentImageSize(), Vector2(30, 30), TEST_LOCATION );
583 DALI_TEST_EQUALS( Vector2(actor.GetCurrentSize()), Vector2(30, 30), TEST_LOCATION );
585 // Clear the pixel area. Expect the whole image to be shown, changing actor size
586 actor.ClearPixelArea();
587 application.SendNotification(); // Process event messages
588 application.Render(); // Process LoadComplete
589 DALI_TEST_EQUALS( actor.GetCurrentImageSize(), closestImageSize, TEST_LOCATION );
590 DALI_TEST_EQUALS( Vector2(actor.GetCurrentSize()), closestImageSize, TEST_LOCATION );
592 // Set a size. Expect the partial image to stretch to fill the new size
593 actor.SetSize(100, 100);
594 application.SendNotification(); // Process event messages
595 application.Render(); // Process LoadComplete
596 DALI_TEST_EQUALS( actor.GetCurrentImageSize(), Vector2(100, 100), TEST_LOCATION );
597 DALI_TEST_EQUALS( Vector2(actor.GetCurrentSize()), Vector2(100, 100), TEST_LOCATION );
599 // Set a pixel area, don't expect size to change
600 actor.SetPixelArea(ImageActor::PixelArea(0, 0, 40, 40));
601 application.SendNotification(); // Process event messages
602 application.Render(); // Process LoadComplete
603 DALI_TEST_EQUALS( actor.GetCurrentImageSize(), Vector2(40, 40), TEST_LOCATION );
604 DALI_TEST_EQUALS( Vector2(actor.GetCurrentSize()), Vector2(100, 100), TEST_LOCATION );
606 // Use natural size - expect actor to change to pixel area
607 actor.SetToNaturalSize();
608 application.SendNotification(); // Process event messages
609 application.Render(); // Process LoadComplete
610 DALI_TEST_EQUALS( actor.GetCurrentImageSize(), Vector2(40, 40), TEST_LOCATION );
611 DALI_TEST_EQUALS( Vector2(actor.GetCurrentSize()), Vector2(40, 40), TEST_LOCATION );
613 // Clearing pixel area should change actor size to image size
614 actor.ClearPixelArea();
615 application.SendNotification(); // Process event messages
616 application.Render(); // Process LoadComplete
617 DALI_TEST_EQUALS( actor.GetCurrentImageSize(), closestImageSize, TEST_LOCATION );
618 DALI_TEST_EQUALS( Vector2(actor.GetCurrentSize()), closestImageSize, TEST_LOCATION );
624 int UtcDaliImageActorDefaultProperties(void)
626 TestApplication application;
627 tet_infoline("Testing Dali::ImageActor DefaultProperties");
629 BitmapImage img = BitmapImage::New( 10, 10 );
630 ImageActor actor = ImageActor::New( img );
632 std::vector<Property::Index> indices;
633 indices.push_back(ImageActor::PIXEL_AREA );
634 indices.push_back(ImageActor::FADE_IN );
635 indices.push_back(ImageActor::FADE_IN_DURATION);
636 indices.push_back(ImageActor::STYLE );
637 indices.push_back(ImageActor::BORDER );
638 indices.push_back(ImageActor::IMAGE );
640 DALI_TEST_CHECK(actor.GetPropertyCount() == ( Actor::New().GetPropertyCount() + indices.size() ) );
642 for(std::vector<Property::Index>::iterator iter = indices.begin(); iter != indices.end(); ++iter)
644 DALI_TEST_CHECK( *iter == actor.GetPropertyIndex(actor.GetPropertyName(*iter)) );
645 DALI_TEST_CHECK( actor.IsPropertyWritable(*iter) );
646 DALI_TEST_CHECK( !actor.IsPropertyAnimatable(*iter) );
647 DALI_TEST_CHECK( actor.GetPropertyType(*iter) == actor.GetPropertyType(*iter) ); // just checking call succeeds
650 // set/get one of them
651 actor.SetPixelArea(ImageActor::PixelArea( 0, 0, 0, 0 ));
653 ImageActor::PixelArea area( 1, 2, 3, 4 );
654 actor.SetProperty(ImageActor::PIXEL_AREA, Property::Value(Rect<int>(area)));
656 DALI_TEST_CHECK(Property::RECTANGLE == actor.GetPropertyType(ImageActor::PIXEL_AREA));
658 Property::Value v = actor.GetProperty(ImageActor::PIXEL_AREA);
660 DALI_TEST_CHECK(v.Get<Rect<int> >() == area);
665 int UtcDaliImageActorUseImageAlpha01(void)
667 TestApplication application;
669 tet_infoline("Testing Dali::RenderableActor::SetUseImageAlpha()");
671 BitmapImage image = BitmapImage::New( 100, 50 );
672 ImageActor actor = ImageActor::New( image );
673 actor.SetBlendMode( BlendingMode::ON );
674 actor.SetSize(100, 50);
675 application.GetGlAbstraction().EnableCullFaceCallTrace(true); // For Enable(GL_BLEND)
676 Stage::GetCurrent().Add(actor);
678 application.SendNotification();
679 application.Render();
681 const TraceCallStack& callTrace = application.GetGlAbstraction().GetCullFaceTrace();
682 DALI_TEST_EQUALS( BlendEnabled( callTrace), true, TEST_LOCATION );
683 DALI_TEST_EQUALS( BlendDisabled( callTrace ), false, TEST_LOCATION );
687 int UtcDaliImageActorUseImageAlpha02(void)
689 TestApplication application;
691 tet_infoline("Testing Dali::RenderableActor::SetUseImageAlpha()");
693 BitmapImage image = BitmapImage::New( 100, 50 );
694 ImageActor actor = ImageActor::New( image );
695 actor.SetBlendMode( BlendingMode::OFF );
696 actor.SetSize(100, 50);
697 application.GetGlAbstraction().EnableCullFaceCallTrace(true); // For Enable(GL_BLEND)
698 Stage::GetCurrent().Add(actor);
700 application.SendNotification();
701 application.Render();
703 const TraceCallStack& callTrace = application.GetGlAbstraction().GetCullFaceTrace();
704 DALI_TEST_EQUALS( BlendDisabled( callTrace ), false, TEST_LOCATION );
705 DALI_TEST_EQUALS( BlendEnabled( callTrace), false, TEST_LOCATION );
709 int UtcDaliImageActorUseImageAlpha03(void)
711 TestApplication application;
713 tet_infoline("Testing Dali::RenderableActor::SetUseImageAlpha()");
715 BitmapImage image = BitmapImage::New( 100, 50 );
716 ImageActor actor = ImageActor::New( image );
717 actor.SetBlendMode( BlendingMode::AUTO );
718 actor.SetColor(Vector4(1.0, 1.0, 1.0, 0.5));
719 actor.SetSize(100, 50);
720 application.GetGlAbstraction().EnableCullFaceCallTrace(true); // For Enable(GL_BLEND)
721 Stage::GetCurrent().Add(actor);
723 application.SendNotification();
724 application.Render();
726 const TraceCallStack& callTrace = application.GetGlAbstraction().GetCullFaceTrace();
727 DALI_TEST_EQUALS( BlendDisabled( callTrace ), false, TEST_LOCATION );
728 DALI_TEST_EQUALS( BlendEnabled( callTrace), true, TEST_LOCATION );
732 int UtcDaliImageActorUseImageAlpha04(void)
734 TestApplication application;
736 tet_infoline("Testing Dali::RenderableActor::SetUseImageAlpha()");
738 FrameBufferImage image = FrameBufferImage::New( 100, 50, Pixel::RGBA8888 );
739 RenderTaskList taskList = Stage::GetCurrent().GetRenderTaskList();
740 RenderTask task = taskList.GetTask( 0u );
741 task.SetTargetFrameBuffer( image ); // To ensure frame buffer is connected
742 application.GetGlAbstraction().SetCheckFramebufferStatusResult( GL_FRAMEBUFFER_COMPLETE );
743 application.SendNotification();
744 application.Render(0);
746 ImageActor actor = ImageActor::New( image );
747 application.SendNotification();
748 application.Render(0);
750 actor.SetBlendMode( BlendingMode::ON );
751 actor.SetColor(Vector4(1.0, 1.0, 1.0, 1.0));
752 actor.SetSize(100, 50);
753 application.GetGlAbstraction().EnableCullFaceCallTrace(true); // For Enable(GL_BLEND)
754 Stage::GetCurrent().Add(actor);
756 application.SendNotification();
757 application.Render();
759 const TraceCallStack& callTrace = application.GetGlAbstraction().GetCullFaceTrace();
760 DALI_TEST_EQUALS( BlendDisabled( callTrace ), false, TEST_LOCATION );
761 DALI_TEST_EQUALS( BlendEnabled( callTrace), true, TEST_LOCATION );
765 int UtcDaliImageActorUseImageAlpha05(void)
767 TestApplication application;
769 tet_infoline("Testing Dali::RenderableActor::SetUseImageAlpha()");
771 BitmapImage image = BitmapImage::New( 100, 50, Pixel::RGB888 );
772 ImageActor actor = ImageActor::New( image );
773 actor.SetBlendMode( BlendingMode::AUTO );
774 actor.SetColor(Vector4(1.0, 1.0, 1.0, 1.0));
775 actor.SetSize(100, 50);
776 application.GetGlAbstraction().EnableCullFaceCallTrace(true); // For Enable(GL_BLEND)
777 Stage::GetCurrent().Add(actor);
779 application.SendNotification();
780 application.Render();
782 const TraceCallStack& callTrace = application.GetGlAbstraction().GetCullFaceTrace();
783 DALI_TEST_EQUALS( BlendDisabled( callTrace ), false, TEST_LOCATION );
784 DALI_TEST_EQUALS( BlendEnabled( callTrace), false, TEST_LOCATION );
788 int UtcDaliImageActorClearPixelArea(void)
790 TestApplication application;
792 BitmapImage img = BitmapImage::New( 10, 10 );
793 ImageActor actor = ImageActor::New( img );
795 DALI_TEST_CHECK( actor.IsPixelAreaSet() == false );
797 ImageActor::PixelArea area( 1, 2, 3, 4 );
798 actor.SetPixelArea( area );
800 DALI_TEST_CHECK( actor.IsPixelAreaSet() == true );
802 actor.ClearPixelArea();
804 DALI_TEST_CHECK( actor.IsPixelAreaSet() == false );
808 int UtcDaliImageGetStyle(void)
810 TestApplication application;
812 Image image = Image::New(TestImageFilename);
813 ImageActor actor = ImageActor::New(image);
815 actor.SetStyle(ImageActor::STYLE_NINE_PATCH);
817 // flush the queue and render once
818 application.SendNotification();
819 application.Render();
821 DALI_TEST_EQUALS( ImageActor::STYLE_NINE_PATCH, actor.GetStyle(), TEST_LOCATION );
825 int UtcDaliImageSetNinePatchBorder(void)
827 TestApplication application;
829 Image image = Image::New(TestImageFilename);
830 ImageActor actor = ImageActor::New(image);
832 actor.SetStyle(ImageActor::STYLE_NINE_PATCH);
833 actor.SetNinePatchBorder(Vector4( 1.0f, 2.0f, 3.0f, 4.0f));
835 DALI_TEST_EQUALS( 1.0f, actor.GetNinePatchBorder().x, TEST_LOCATION );
836 DALI_TEST_EQUALS( 2.0f, actor.GetNinePatchBorder().y, TEST_LOCATION );
837 DALI_TEST_EQUALS( 3.0f, actor.GetNinePatchBorder().z, TEST_LOCATION );
838 DALI_TEST_EQUALS( 4.0f, actor.GetNinePatchBorder().w, TEST_LOCATION );
842 int UtcDaliImageSetFadeIn(void)
844 TestApplication application;
846 Image image = Image::New(TestImageFilename);
847 ImageActor actor = ImageActor::New(image);
849 actor.SetFadeIn(true);
851 // flush the queue and render once
852 application.SendNotification();
853 application.Render();
855 DALI_TEST_EQUALS( true, actor.GetFadeIn(), TEST_LOCATION );
857 actor.SetFadeIn(false);
859 // flush the queue and render once
860 application.SendNotification();
861 application.Render();
863 DALI_TEST_EQUALS( false, actor.GetFadeIn(), TEST_LOCATION );
868 int UtcDaliImageSetFadeInDuration(void)
870 TestApplication application;
872 Image image = Image::New(TestImageFilename);
873 ImageActor actor = ImageActor::New(image);
875 actor.SetFadeInDuration( 1.0f );
877 // flush the queue and render once
878 application.SendNotification();
879 application.Render();
881 DALI_TEST_EQUALS( 1.0f, actor.GetFadeInDuration(), TEST_LOCATION );
883 actor.SetFadeInDuration( 3.0f );
885 // flush the queue and render once
886 application.SendNotification();
887 application.Render();
889 DALI_TEST_EQUALS( 3.0f, actor.GetFadeInDuration(), TEST_LOCATION );
893 int UtcDaliImageActorNewNull(void)
895 TestApplication application;
897 ImageActor actor = ImageActor::New(Image());
899 DALI_TEST_CHECK(actor);
903 int UtcDaliImageActorNewNullWithArea(void)
905 TestApplication application;
907 ImageActor::PixelArea area( 1, 2, 3, 4 );
909 ImageActor actor = ImageActor::New(Image(), area);
911 DALI_TEST_CHECK(actor);
915 int UtcDaliImageActorSetImage(void)
917 TestApplication application;
919 ImageActor actor = ImageActor::New(Image());
921 DALI_TEST_CHECK(actor);
923 actor.SetImage( Image() );
925 DALI_TEST_CHECK(!actor.GetImage());
929 int UtcDaliImageActorPropertyIndices(void)
931 TestApplication application;
932 Actor basicActor = Actor::New();
933 ImageActor imageActor = ImageActor::New();
935 Property::IndexContainer indices;
936 imageActor.GetPropertyIndices( indices );
937 DALI_TEST_CHECK( indices.size() > basicActor.GetPropertyCount() );
938 DALI_TEST_EQUALS( indices.size(), imageActor.GetPropertyCount(), TEST_LOCATION );