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 UtcDaliImageActorGetCurrentSize01(void)
179 TestApplication application;
180 tet_infoline("Positive test for Dali::ImageActor::GetCurrentSize");
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( Vector2(actor.GetCurrentSize()), 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( Vector2(actor.GetCurrentSize()), 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 // natural size is not used as setsize is called
210 DALI_TEST_EQUALS( Vector2(actor.GetCurrentSize()), size, TEST_LOCATION );
212 actor.SetToNaturalSize();
213 application.SendNotification();
214 application.Render(9);
215 DALI_TEST_EQUALS( Vector2(actor.GetCurrentSize()), Vector2( area.width, area.height ), TEST_LOCATION );
221 int UtcDaliImageActorGetCurrentSize02(void)
223 TestApplication application;
224 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");
226 Vector2 initialImageSize(100, 50);
228 application.GetPlatform().SetClosestImageSize(initialImageSize);
230 Image image = Image::New("image.jpg");
231 ImageActor actor = ImageActor::New( image );
232 Stage::GetCurrent().Add(actor);
234 application.SendNotification(); // Flush update messages
235 application.Render(); // Process resource request
236 application.SendNotification(); // Flush update messages
237 application.Render(); // Process resource request
239 DALI_TEST_EQUALS( Vector2(actor.GetCurrentSize()), initialImageSize, TEST_LOCATION );
241 // Now complete the image load
242 Integration::ResourceRequest* req = application.GetPlatform().GetRequest();
243 Integration::Bitmap* bitmap = Integration::Bitmap::New( Integration::Bitmap::BITMAP_2D_PACKED_PIXELS, false );
244 bitmap->GetPackedPixelsProfile()->ReserveBuffer( Pixel::RGBA8888, initialImageSize.width,initialImageSize.height, initialImageSize.width,initialImageSize.height );
246 Integration::ResourcePointer resourcePtr(bitmap); // reference it
247 application.GetPlatform().SetResourceLoaded(req->GetId(), req->GetType()->id, resourcePtr);
248 application.Render(); // Process LoadComplete
249 application.SendNotification(); // Process event messages
250 application.GetPlatform().DiscardRequest(); // Ensure load request is discarded
251 application.GetPlatform().ClearReadyResources(); //
253 DALI_TEST_EQUALS( Vector2(actor.GetCurrentSize()), initialImageSize, TEST_LOCATION );
255 Vector2 size(200.0f, 200.0f);
258 // flush the queue and render once
259 application.SendNotification();
260 application.Render();
261 DALI_TEST_EQUALS( Vector2(actor.GetCurrentSize()), size, TEST_LOCATION );
263 actor.SetToNaturalSize();
264 application.SendNotification();
265 application.Render();
266 DALI_TEST_EQUALS( Vector2(actor.GetCurrentSize()), initialImageSize, TEST_LOCATION );
271 int UtcDaliImageActorGetCurrentSize03(void)
273 TestApplication application;
274 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");
276 const Vector2 closestImageSize( 80, 45);
277 application.GetPlatform().SetClosestImageSize(closestImageSize);
279 ImageAttributes attrs;
280 const Vector2 requestedSize( 40, 30 );
281 attrs.SetSize( requestedSize.width, requestedSize.height );
282 Image image = Image::New("image.jpg", attrs);
283 ImageActor actor = ImageActor::New( image );
284 Stage::GetCurrent().Add(actor);
286 application.SendNotification(); // Flush update messages
287 application.Render(); // Process resource request
288 application.SendNotification(); // Flush update messages
289 application.Render(); // Process resource request
291 DALI_TEST_EQUALS( Vector2(actor.GetCurrentSize()), requestedSize, TEST_LOCATION );
293 // Now complete the image load
294 Integration::ResourceRequest* req = application.GetPlatform().GetRequest();
295 Integration::Bitmap* bitmap = Integration::Bitmap::New( Integration::Bitmap::BITMAP_2D_PACKED_PIXELS, false );
296 bitmap->GetPackedPixelsProfile()->ReserveBuffer( Pixel::RGBA8888, closestImageSize.width, closestImageSize.height, closestImageSize.width, closestImageSize.height );
298 Integration::ResourcePointer resourcePtr(bitmap); // reference it
299 application.GetPlatform().SetResourceLoaded(req->GetId(), req->GetType()->id, resourcePtr);
300 application.Render(); // Process LoadComplete
301 application.SendNotification(); // Process event messages
302 application.GetPlatform().DiscardRequest(); // Ensure load request is discarded
303 application.GetPlatform().ClearReadyResources(); //
305 DALI_TEST_EQUALS( Vector2(actor.GetCurrentSize()), requestedSize, TEST_LOCATION );
307 // Test that setting a size on the actor can be 'undone' with SetNaturalSize()
308 Vector2 size(200.0f, 200.0f);
311 // flush the queue and render once
312 application.SendNotification();
313 application.Render();
314 DALI_TEST_EQUALS( Vector2(actor.GetCurrentSize()), size, TEST_LOCATION );
316 actor.SetToNaturalSize();
317 application.SendNotification();
318 application.Render();
319 DALI_TEST_EQUALS( Vector2(actor.GetCurrentSize()), requestedSize, TEST_LOCATION );
324 int UtcDaliImageActorGetCurrentSize04(void)
326 TestApplication application;
327 tet_infoline("Positive test for Dali::ImageActor::GetCurrentSize - check a new image doesn't change a set actor size");
329 const Vector2 closestImageSize( 80, 45);
330 application.GetPlatform().SetClosestImageSize(closestImageSize);
332 const Vector2 requestedSize( 40, 30 );
333 ImageAttributes attrs;
334 attrs.SetSize( requestedSize.width, requestedSize.height );
335 Image image = Image::New("image.jpg", attrs);
336 ImageActor actor = ImageActor::New( image );
337 Stage::GetCurrent().Add(actor);
339 application.SendNotification(); // Flush update messages
340 application.Render(); // Process resource request
342 DALI_TEST_EQUALS( Vector2(actor.GetCurrentSize()), requestedSize, TEST_LOCATION );
344 // Now complete the image load
345 Integration::ResourceRequest* req = application.GetPlatform().GetRequest();
346 Integration::Bitmap* bitmap = Integration::Bitmap::New( Integration::Bitmap::BITMAP_2D_PACKED_PIXELS, false );
347 bitmap->GetPackedPixelsProfile()->ReserveBuffer( Pixel::RGBA8888, closestImageSize.width, closestImageSize.height, closestImageSize.width, closestImageSize.height );
349 Integration::ResourcePointer resourcePtr(bitmap); // reference it
350 application.GetPlatform().SetResourceLoaded(req->GetId(), req->GetType()->id, resourcePtr);
351 application.Render(); // Process LoadComplete
352 application.SendNotification(); // Process event messages
353 application.GetPlatform().DiscardRequest(); // Ensure load request is discarded
354 application.GetPlatform().ClearReadyResources(); //
356 DALI_TEST_EQUALS( Vector2(actor.GetCurrentSize()), requestedSize, TEST_LOCATION );
358 Vector2 size(200.0f, 200.0f);
361 // flush the queue and render once
362 application.SendNotification();
363 application.Render();
364 DALI_TEST_EQUALS( Vector2(actor.GetCurrentSize()), size, TEST_LOCATION );
366 // Load a different image
368 Vector2 image2ClosestSize = Vector2(240, 150); // The actual size image loader will return for the request below
369 application.GetPlatform().SetClosestImageSize(image2ClosestSize);
371 const Vector2 request2Size( 100, 100 );
372 attrs.SetSize( request2Size.width, request2Size.height );
373 Image image2 = Image::New("image2.jpg", attrs);
374 actor.SetImage(image2);
376 application.SendNotification(); // Flush update messages
377 application.Render(); // Process resource request
378 application.SendNotification(); // Flush update messages
379 application.Render(); // Process resource request
381 // Ensure the actor size is kept
382 DALI_TEST_EQUALS( Vector2(actor.GetCurrentSize()), size, TEST_LOCATION );
384 // Now complete the image load
385 req = application.GetPlatform().GetRequest();
386 Integration::Bitmap* bitmap2 = Integration::Bitmap::New( Integration::Bitmap::BITMAP_2D_PACKED_PIXELS, false );
387 bitmap2->GetPackedPixelsProfile()->ReserveBuffer( Pixel::RGBA8888, image2ClosestSize.width, image2ClosestSize.height, image2ClosestSize.width, image2ClosestSize.height );
389 Integration::ResourcePointer resourcePtr2(bitmap2); // reference it
390 application.GetPlatform().SetResourceLoaded(req->GetId(), req->GetType()->id, resourcePtr2);
391 application.Render(); // Process LoadComplete
392 application.SendNotification(); // Process event messages
393 application.GetPlatform().DiscardRequest(); // Ensure load request is discarded
394 application.GetPlatform().ClearReadyResources(); //
396 // Ensure the actor size is kept
397 DALI_TEST_EQUALS( Vector2(actor.GetCurrentSize()), size, TEST_LOCATION );
399 actor.SetToNaturalSize();
400 application.SendNotification();
401 application.Render();
402 // Ensure the actor size gets the new image's natural size
403 DALI_TEST_EQUALS( Vector2(actor.GetCurrentSize()), request2Size, TEST_LOCATION );
408 int UtcDaliImageActorGetCurrentSize05(void)
410 TestApplication application;
411 tet_infoline("Positive test for Dali::ImageActor::GetCurrentSize - check a new image doens't change actor size until load complete");
413 Vector2 closestImageSize( 80, 45);
414 application.GetPlatform().SetClosestImageSize(closestImageSize);
416 ImageAttributes attrs;
417 const Vector2 requestedSize( 40, 30 );
418 attrs.SetSize( requestedSize.width, requestedSize.height );
419 Image image = Image::New("image.jpg", attrs);
420 ImageActor actor = ImageActor::New( image );
421 Stage::GetCurrent().Add(actor);
423 application.SendNotification(); // Flush update messages
424 application.Render(); // Process resource request
426 DALI_TEST_EQUALS( Vector2(actor.GetCurrentSize()), requestedSize, TEST_LOCATION );
428 // Now complete the image load
429 Integration::ResourceRequest* req = application.GetPlatform().GetRequest();
430 Integration::Bitmap* bitmap = Integration::Bitmap::New( Integration::Bitmap::BITMAP_2D_PACKED_PIXELS, false );
431 bitmap->GetPackedPixelsProfile()->ReserveBuffer( Pixel::RGBA8888, closestImageSize.width, closestImageSize.height, closestImageSize.width, closestImageSize.height );
433 Integration::ResourcePointer resourcePtr(bitmap); // reference it
434 application.GetPlatform().SetResourceLoaded(req->GetId(), req->GetType()->id, resourcePtr);
435 application.Render(); // Process LoadComplete
436 application.SendNotification(); // Process event messages
437 application.GetPlatform().DiscardRequest(); // Ensure load request is discarded
438 application.GetPlatform().ClearReadyResources(); //
440 DALI_TEST_EQUALS( Vector2(actor.GetCurrentSize()), requestedSize, TEST_LOCATION );
442 // Load a different image
444 Vector2 image2ClosestSize = Vector2(240, 150);
445 application.GetPlatform().SetClosestImageSize(image2ClosestSize);
447 const Vector2 requestedSize2( 100, 100 );
448 attrs.SetSize( requestedSize2.width, requestedSize2.height );
449 Image image2 = Image::New("image2.jpg", attrs);
450 actor.SetImage(image2);
452 application.SendNotification(); // Flush update messages
453 application.Render(); // Process resource request
454 application.SendNotification(); // Flush update messages
455 application.Render(); // Process resource request
457 // Ensure the actor size is kept
458 DALI_TEST_EQUALS( Vector2(actor.GetCurrentSize()), requestedSize2, TEST_LOCATION );
460 // Now complete the image load
461 req = application.GetPlatform().GetRequest();
462 Integration::Bitmap* bitmap2 = Integration::Bitmap::New( Integration::Bitmap::BITMAP_2D_PACKED_PIXELS, false );
463 bitmap2->GetPackedPixelsProfile()->ReserveBuffer( Pixel::RGBA8888, image2ClosestSize.width, image2ClosestSize.height, image2ClosestSize.width, image2ClosestSize.height );
465 Integration::ResourcePointer resourcePtr2(bitmap2); // reference it
466 application.GetPlatform().SetResourceLoaded(req->GetId(), req->GetType()->id, resourcePtr2);
467 application.Render(); // Process LoadComplete
468 application.SendNotification(); // Process event messages
469 application.GetPlatform().DiscardRequest(); // Ensure load request is discarded
470 application.GetPlatform().ClearReadyResources(); //
472 application.SendNotification(); // Process event messages
473 application.Render(); // Process LoadComplete
475 // Ensure the actor size gets the new image's natural size
476 DALI_TEST_EQUALS( Vector2(actor.GetCurrentSize()), requestedSize2, TEST_LOCATION );
480 int UtcDaliImageActorNaturalPixelAreaSize01(void)
482 TestApplication application;
483 tet_infoline("Positive test for Dali::ImageActor::GetCurrentSize - check a new image doens't change actor size until load complete");
485 //If an image is loaded without setting size, then the actor gets the natural size of the image
486 //Setting the pixel area will change the actor size to match the pixel area
487 //Setting the actor size will not change pixel area, and will cause the partial image to stretch
489 //Clearing the pixel area will not change actor size, and the actor will show the whole image.
492 Vector2 closestImageSize( 80, 45);
493 application.GetPlatform().SetClosestImageSize(closestImageSize);
495 ImageAttributes attrs;
496 const Vector2 requestedSize( 40, 30 );
497 attrs.SetSize( requestedSize.width, requestedSize.height );
498 Image image = Image::New("image.jpg", attrs);
499 ImageActor actor = ImageActor::New( image );
500 Stage::GetCurrent().Add(actor);
502 application.SendNotification(); // Flush update messages
503 application.Render(); // Process resource request
505 DALI_TEST_EQUALS( Vector2(actor.GetCurrentSize()), requestedSize, TEST_LOCATION );
507 // Now complete the image load
508 Integration::ResourceRequest* req = application.GetPlatform().GetRequest();
509 Integration::Bitmap* bitmap = Integration::Bitmap::New( Integration::Bitmap::BITMAP_2D_PACKED_PIXELS, false );
510 bitmap->GetPackedPixelsProfile()->ReserveBuffer( Pixel::RGBA8888, closestImageSize.width, closestImageSize.height, closestImageSize.width, closestImageSize.height );
512 Integration::ResourcePointer resourcePtr(bitmap); // reference it
513 application.GetPlatform().SetResourceLoaded(req->GetId(), req->GetType()->id, resourcePtr);
514 application.Render(); // Process LoadComplete
515 application.SendNotification(); // Process event messages
516 application.GetPlatform().DiscardRequest(); // Ensure load request is discarded
517 application.GetPlatform().ClearReadyResources(); //
519 DALI_TEST_EQUALS( Vector2(actor.GetCurrentSize()), requestedSize, TEST_LOCATION );
521 // Set a pixel area on a naturally sized actor - expect the actor to take the
522 // pixel area as size
523 actor.SetPixelArea(ImageActor::PixelArea(0, 0, 30, 30));
524 application.SendNotification(); // Process event messages
525 application.Render(); // Process LoadComplete
526 DALI_TEST_EQUALS( Vector2(actor.GetCurrentSize()), Vector2(30, 30), TEST_LOCATION );
528 // Set a size. Expect the partial image to stretch to fill the new size
529 actor.SetSize(100, 100);
530 application.SendNotification(); // Process event messages
531 application.Render(); // Process LoadComplete
532 application.Render(); // Process LoadComplete
533 DALI_TEST_EQUALS( Vector2(actor.GetCurrentSize()), Vector2(100, 100), TEST_LOCATION );
535 // Clear the pixel area. Expect the whole image to be shown, filling the set size.
536 actor.ClearPixelArea();
537 application.SendNotification(); // Process event messages
538 application.Render(); // Process LoadComplete
539 DALI_TEST_EQUALS( Vector2(actor.GetCurrentSize()), Vector2(100, 100), TEST_LOCATION );
543 int UtcDaliImageActorNaturalPixelAreaSize02(void)
545 TestApplication application;
546 tet_infoline("Positive test for Dali::ImageActor::GetCurrentSize - check a new image doens't change actor size until load complete");
548 //If an image is loaded without setting size, then the actor gets the natural size of the image
549 //Setting the pixel area will change the actor size to match the pixel area
550 //Setting the actor size will not change pixel area, and will cause the partial image to stretch
552 //Clearing the pixel area will not change actor size, and the actor will show the whole image.
555 Vector2 closestImageSize( 80, 45);
556 application.GetPlatform().SetClosestImageSize(closestImageSize);
558 ImageAttributes attrs;
559 const Vector2 requestedSize( 40, 30 );
560 attrs.SetSize( requestedSize.width, requestedSize.height );
561 Image image = Image::New("image.jpg", attrs);
562 ImageActor actor = ImageActor::New( image );
563 Stage::GetCurrent().Add(actor);
565 application.SendNotification(); // Flush update messages
566 application.Render(); // Process resource request
568 DALI_TEST_EQUALS( Vector2(actor.GetCurrentSize()), requestedSize, TEST_LOCATION );
570 // Now complete the image load
571 Integration::ResourceRequest* req = application.GetPlatform().GetRequest();
572 Integration::Bitmap* bitmap = Integration::Bitmap::New( Integration::Bitmap::BITMAP_2D_PACKED_PIXELS, false );
573 bitmap->GetPackedPixelsProfile()->ReserveBuffer( Pixel::RGBA8888, closestImageSize.width, closestImageSize.height, closestImageSize.width, closestImageSize.height );
575 Integration::ResourcePointer resourcePtr(bitmap); // reference it
576 application.GetPlatform().SetResourceLoaded(req->GetId(), req->GetType()->id, resourcePtr);
577 application.Render(); // Process LoadComplete
578 application.SendNotification(); // Process event messages
579 application.GetPlatform().DiscardRequest(); // Ensure load request is discarded
580 application.GetPlatform().ClearReadyResources(); //
582 DALI_TEST_EQUALS( Vector2(actor.GetCurrentSize()), requestedSize, TEST_LOCATION );
584 // Set a pixel area on a naturally sized actor - expect the actor to take the
585 // pixel area as size
586 actor.SetPixelArea(ImageActor::PixelArea(0, 0, 30, 30));
587 application.SendNotification(); // Process event messages
588 application.Render(); // Process LoadComplete
589 DALI_TEST_EQUALS( Vector2(actor.GetCurrentSize()), Vector2(30, 30), TEST_LOCATION );
591 // Clear the pixel area. Expect the whole image to be shown, changing actor size
592 actor.ClearPixelArea();
593 application.SendNotification(); // Process event messages
594 application.Render(); // Process LoadComplete
595 DALI_TEST_EQUALS( Vector2(actor.GetCurrentSize()), requestedSize, TEST_LOCATION );
597 // Set a size. Expect the partial image to stretch to fill the new size
598 actor.SetSize(100, 100);
599 application.SendNotification(); // Process event messages
600 application.Render(); // Process LoadComplete
601 DALI_TEST_EQUALS( Vector2(actor.GetCurrentSize()), Vector2(100, 100), TEST_LOCATION );
603 // Set a pixel area, don't expect size to change
604 actor.SetPixelArea(ImageActor::PixelArea(0, 0, 40, 40));
605 application.SendNotification(); // Process event messages
606 application.Render(); // Process LoadComplete
607 DALI_TEST_EQUALS( Vector2(actor.GetCurrentSize()), Vector2(100, 100), TEST_LOCATION );
609 // Use natural size - expect actor to change to pixel area
610 actor.SetToNaturalSize();
611 application.SendNotification(); // Process event messages
612 application.Render(); // Process LoadComplete
613 DALI_TEST_EQUALS( Vector2(actor.GetCurrentSize()), Vector2(40, 40), TEST_LOCATION );
615 // Clearing pixel area should change actor size to image size
616 actor.ClearPixelArea();
617 application.SendNotification(); // Process event messages
618 application.Render(); // Process LoadComplete
619 DALI_TEST_EQUALS( Vector2(actor.GetCurrentSize()), requestedSize, 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::STYLE );
636 indices.push_back(ImageActor::BORDER );
637 indices.push_back(ImageActor::IMAGE );
639 DALI_TEST_CHECK(actor.GetPropertyCount() == ( Actor::New().GetPropertyCount() + indices.size() ) );
641 for(std::vector<Property::Index>::iterator iter = indices.begin(); iter != indices.end(); ++iter)
643 DALI_TEST_CHECK( *iter == actor.GetPropertyIndex(actor.GetPropertyName(*iter)) );
644 DALI_TEST_CHECK( actor.IsPropertyWritable(*iter) );
645 DALI_TEST_CHECK( !actor.IsPropertyAnimatable(*iter) );
646 DALI_TEST_CHECK( actor.GetPropertyType(*iter) == actor.GetPropertyType(*iter) ); // just checking call succeeds
649 // set/get one of them
650 actor.SetPixelArea(ImageActor::PixelArea( 0, 0, 0, 0 ));
652 ImageActor::PixelArea area( 1, 2, 3, 4 );
653 actor.SetProperty(ImageActor::PIXEL_AREA, Property::Value(Rect<int>(area)));
655 DALI_TEST_CHECK(Property::RECTANGLE == actor.GetPropertyType(ImageActor::PIXEL_AREA));
657 Property::Value v = actor.GetProperty(ImageActor::PIXEL_AREA);
659 DALI_TEST_CHECK(v.Get<Rect<int> >() == area);
664 int UtcDaliImageActorUseImageAlpha01(void)
666 TestApplication application;
668 tet_infoline("Testing Dali::RenderableActor::SetUseImageAlpha()");
670 BitmapImage image = BitmapImage::New( 100, 50 );
671 ImageActor actor = ImageActor::New( image );
672 actor.SetBlendMode( BlendingMode::ON );
673 actor.SetSize(100, 50);
674 application.GetGlAbstraction().EnableCullFaceCallTrace(true); // For Enable(GL_BLEND)
675 Stage::GetCurrent().Add(actor);
677 application.SendNotification();
678 application.Render();
680 const TraceCallStack& callTrace = application.GetGlAbstraction().GetCullFaceTrace();
681 DALI_TEST_EQUALS( BlendEnabled( callTrace), true, TEST_LOCATION );
682 DALI_TEST_EQUALS( BlendDisabled( callTrace ), false, TEST_LOCATION );
686 int UtcDaliImageActorUseImageAlpha02(void)
688 TestApplication application;
690 tet_infoline("Testing Dali::RenderableActor::SetUseImageAlpha()");
692 BitmapImage image = BitmapImage::New( 100, 50 );
693 ImageActor actor = ImageActor::New( image );
694 actor.SetBlendMode( BlendingMode::OFF );
695 actor.SetSize(100, 50);
696 application.GetGlAbstraction().EnableCullFaceCallTrace(true); // For Enable(GL_BLEND)
697 Stage::GetCurrent().Add(actor);
699 application.SendNotification();
700 application.Render();
702 const TraceCallStack& callTrace = application.GetGlAbstraction().GetCullFaceTrace();
703 DALI_TEST_EQUALS( BlendDisabled( callTrace ), false, TEST_LOCATION );
704 DALI_TEST_EQUALS( BlendEnabled( callTrace), false, TEST_LOCATION );
708 int UtcDaliImageActorUseImageAlpha03(void)
710 TestApplication application;
712 tet_infoline("Testing Dali::RenderableActor::SetUseImageAlpha()");
714 BitmapImage image = BitmapImage::New( 100, 50 );
715 ImageActor actor = ImageActor::New( image );
716 actor.SetBlendMode( BlendingMode::AUTO );
717 actor.SetColor(Vector4(1.0, 1.0, 1.0, 0.5));
718 actor.SetSize(100, 50);
719 application.GetGlAbstraction().EnableCullFaceCallTrace(true); // For Enable(GL_BLEND)
720 Stage::GetCurrent().Add(actor);
722 application.SendNotification();
723 application.Render();
725 const TraceCallStack& callTrace = application.GetGlAbstraction().GetCullFaceTrace();
726 DALI_TEST_EQUALS( BlendDisabled( callTrace ), false, TEST_LOCATION );
727 DALI_TEST_EQUALS( BlendEnabled( callTrace), true, TEST_LOCATION );
731 int UtcDaliImageActorUseImageAlpha04(void)
733 TestApplication application;
735 tet_infoline("Testing Dali::RenderableActor::SetUseImageAlpha()");
737 FrameBufferImage image = FrameBufferImage::New( 100, 50, Pixel::RGBA8888 );
738 RenderTaskList taskList = Stage::GetCurrent().GetRenderTaskList();
739 RenderTask task = taskList.GetTask( 0u );
740 task.SetTargetFrameBuffer( image ); // To ensure frame buffer is connected
741 application.GetGlAbstraction().SetCheckFramebufferStatusResult( GL_FRAMEBUFFER_COMPLETE );
742 application.SendNotification();
743 application.Render(0);
745 ImageActor actor = ImageActor::New( image );
746 application.SendNotification();
747 application.Render(0);
749 actor.SetBlendMode( BlendingMode::ON );
750 actor.SetColor(Vector4(1.0, 1.0, 1.0, 1.0));
751 actor.SetSize(100, 50);
752 application.GetGlAbstraction().EnableCullFaceCallTrace(true); // For Enable(GL_BLEND)
753 Stage::GetCurrent().Add(actor);
755 application.SendNotification();
756 application.Render();
758 const TraceCallStack& callTrace = application.GetGlAbstraction().GetCullFaceTrace();
759 DALI_TEST_EQUALS( BlendDisabled( callTrace ), false, TEST_LOCATION );
760 DALI_TEST_EQUALS( BlendEnabled( callTrace), true, TEST_LOCATION );
764 int UtcDaliImageActorUseImageAlpha05(void)
766 TestApplication application;
768 tet_infoline("Testing Dali::RenderableActor::SetUseImageAlpha()");
770 BitmapImage image = BitmapImage::New( 100, 50, Pixel::RGB888 );
771 ImageActor actor = ImageActor::New( image );
772 actor.SetBlendMode( BlendingMode::AUTO );
773 actor.SetColor(Vector4(1.0, 1.0, 1.0, 1.0));
774 actor.SetSize(100, 50);
775 application.GetGlAbstraction().EnableCullFaceCallTrace(true); // For Enable(GL_BLEND)
776 Stage::GetCurrent().Add(actor);
778 application.SendNotification();
779 application.Render();
781 const TraceCallStack& callTrace = application.GetGlAbstraction().GetCullFaceTrace();
782 DALI_TEST_EQUALS( BlendDisabled( callTrace ), false, TEST_LOCATION );
783 DALI_TEST_EQUALS( BlendEnabled( callTrace), false, TEST_LOCATION );
787 int UtcDaliImageActorClearPixelArea(void)
789 TestApplication application;
791 BitmapImage img = BitmapImage::New( 10, 10 );
792 ImageActor actor = ImageActor::New( img );
794 DALI_TEST_CHECK( actor.IsPixelAreaSet() == false );
796 ImageActor::PixelArea area( 1, 2, 3, 4 );
797 actor.SetPixelArea( area );
799 DALI_TEST_CHECK( actor.IsPixelAreaSet() == true );
801 actor.ClearPixelArea();
803 DALI_TEST_CHECK( actor.IsPixelAreaSet() == false );
807 int UtcDaliImageGetStyle(void)
809 TestApplication application;
811 Image image = Image::New(TestImageFilename);
812 ImageActor actor = ImageActor::New(image);
814 actor.SetStyle(ImageActor::STYLE_NINE_PATCH);
816 // flush the queue and render once
817 application.SendNotification();
818 application.Render();
820 DALI_TEST_EQUALS( ImageActor::STYLE_NINE_PATCH, actor.GetStyle(), TEST_LOCATION );
824 int UtcDaliImageSetNinePatchBorder(void)
826 TestApplication application;
828 Image image = Image::New(TestImageFilename);
829 ImageActor actor = ImageActor::New(image);
831 actor.SetStyle(ImageActor::STYLE_NINE_PATCH);
832 actor.SetNinePatchBorder(Vector4( 1.0f, 2.0f, 3.0f, 4.0f));
834 DALI_TEST_EQUALS( 1.0f, actor.GetNinePatchBorder().x, TEST_LOCATION );
835 DALI_TEST_EQUALS( 2.0f, actor.GetNinePatchBorder().y, TEST_LOCATION );
836 DALI_TEST_EQUALS( 3.0f, actor.GetNinePatchBorder().z, TEST_LOCATION );
837 DALI_TEST_EQUALS( 4.0f, actor.GetNinePatchBorder().w, TEST_LOCATION );
841 int UtcDaliImageActorNewNull(void)
843 TestApplication application;
845 ImageActor actor = ImageActor::New(Image());
847 DALI_TEST_CHECK(actor);
851 int UtcDaliImageActorNewNullWithArea(void)
853 TestApplication application;
855 ImageActor::PixelArea area( 1, 2, 3, 4 );
857 ImageActor actor = ImageActor::New(Image(), area);
859 DALI_TEST_CHECK(actor);
863 int UtcDaliImageActorSetImage(void)
865 TestApplication application;
867 ImageActor actor = ImageActor::New(Image());
869 DALI_TEST_CHECK(actor);
871 actor.SetImage( Image() );
873 DALI_TEST_CHECK(!actor.GetImage());
877 int UtcDaliImageActorPropertyIndices(void)
879 TestApplication application;
880 Actor basicActor = Actor::New();
881 ImageActor imageActor = ImageActor::New();
883 Property::IndexContainer indices;
884 imageActor.GetPropertyIndices( indices );
885 DALI_TEST_CHECK( indices.size() > basicActor.GetPropertyCount() );
886 DALI_TEST_EQUALS( indices.size(), imageActor.GetPropertyCount(), TEST_LOCATION );
890 int UtcDaliImageActorImageProperty(void)
892 TestApplication application;
893 Image image = Image::New( "MY_PATH" );
894 ImageActor imageActor = ImageActor::New( image );
896 Stage::GetCurrent().Add( imageActor );
897 application.SendNotification();
898 application.Render();
900 Property::Value imageMap = imageActor.GetProperty( ImageActor::IMAGE );
901 DALI_TEST_CHECK( imageMap.HasKey( "filename" ) );
902 DALI_TEST_EQUALS( imageMap.GetValue( "filename" ).Get< std::string >(), "MY_PATH", TEST_LOCATION );
906 int UtcDaliImageActorNinePatch01(void)
908 TestApplication application;
909 TestPlatformAbstraction& platform = application.GetPlatform();
910 TestGlAbstraction& glAbstraction = application.GetGlAbstraction();
911 TraceCallStack& textureTrace = glAbstraction.GetTextureTrace();
912 TraceCallStack& drawTrace = glAbstraction.GetDrawTrace();
914 tet_infoline("Test the successful loading of a nine-patch image\n");
916 platform.SetClosestImageSize(Vector2(4, 4));
917 Integration::Bitmap* bitmap = Integration::Bitmap::New( Integration::Bitmap::BITMAP_2D_PACKED_PIXELS, false );
918 Integration::PixelBuffer* pixels = bitmap->GetPackedPixelsProfile()->ReserveBuffer( Pixel::RGBA8888, 4,4,4,4 );
919 memset( pixels, 0, 64 );
921 Integration::ResourcePointer resourcePtr(bitmap); // reference it
922 platform.SetResourceLoaded( 0, Dali::Integration::ResourceBitmap, resourcePtr );
924 Image ninePatchImage = Image::New( "blah.#.png" );
925 DALI_TEST_CHECK( ninePatchImage );
927 ImageActor imageActor = ImageActor::New( ninePatchImage );
928 DALI_TEST_CHECK( imageActor );
929 Stage::GetCurrent().Add( imageActor );
932 textureTrace.Reset();
933 drawTrace.Enable(true);
934 textureTrace.Enable(true);
935 glAbstraction.ClearBoundTextures();
936 std::vector<GLuint> ids;
938 glAbstraction.SetNextTextureIds( ids );
940 application.SendNotification();
941 application.Render();
943 DALI_TEST_CHECK( drawTrace.FindMethod( "DrawArrays" ) );
944 typedef std::vector<GLuint> TexVec;
945 const TexVec& textures = glAbstraction.GetBoundTextures(GL_TEXTURE0);
946 DALI_TEST_CHECK( textures.size() > 0 );
947 if( textures.size() > 0 )
949 DALI_TEST_EQUALS( textures[0], 23u, TEST_LOCATION );
956 int UtcDaliImageActorNinePatch02(void)
958 TestApplication application;
959 TestPlatformAbstraction& platform = application.GetPlatform();
960 TestGlAbstraction& glAbstraction = application.GetGlAbstraction();
961 TraceCallStack& textureTrace = glAbstraction.GetTextureTrace();
962 TraceCallStack& drawTrace = glAbstraction.GetDrawTrace();
964 tet_infoline("Test the failed loading of a nine-patch image\n");
966 platform.SetClosestImageSize(Vector2(0, 0));
967 Integration::ResourcePointer resourcePtr;
968 platform.SetResourceLoaded( 0, Dali::Integration::ResourceBitmap, resourcePtr );
970 Image ninePatchImage = Image::New( "blah.#.png" );
971 DALI_TEST_CHECK( ninePatchImage );
973 ImageActor imageActor = ImageActor::New( ninePatchImage );
974 DALI_TEST_CHECK( imageActor );
975 Stage::GetCurrent().Add( imageActor );
978 textureTrace.Reset();
979 drawTrace.Enable(true);
980 textureTrace.Enable(true);
981 glAbstraction.ClearBoundTextures();
982 std::vector<GLuint> ids;
984 glAbstraction.SetNextTextureIds( ids );
986 application.SendNotification();
987 application.Render();
989 // Check that nothing was drawn.
990 DALI_TEST_CHECK( ! drawTrace.FindMethod( "DrawArrays" ) );
991 typedef std::vector<GLuint> TexVec;
992 const TexVec& textures = glAbstraction.GetBoundTextures(GL_TEXTURE0);
993 DALI_TEST_CHECK( textures.size() == 0u );
999 int UtcDaliImageActorNinePatch03(void)
1001 TestApplication application;
1002 TestPlatformAbstraction& platform = application.GetPlatform();
1003 TestGlAbstraction& glAbstraction = application.GetGlAbstraction();
1004 TraceCallStack& textureTrace = glAbstraction.GetTextureTrace();
1005 TraceCallStack& drawTrace = glAbstraction.GetDrawTrace();
1007 tet_infoline("Test the successful loading of a nine-patch image added using ImageActor::SetImage()\n");
1009 platform.SetClosestImageSize(Vector2(4, 4));
1010 Integration::Bitmap* bitmap = Integration::Bitmap::New( Integration::Bitmap::BITMAP_2D_PACKED_PIXELS, false );
1011 Integration::PixelBuffer* pixels = bitmap->GetPackedPixelsProfile()->ReserveBuffer( Pixel::RGBA8888, 4,4,4,4 );
1012 memset( pixels, 0, 64 );
1014 Integration::ResourcePointer resourcePtr(bitmap); // reference it
1015 platform.SetResourceLoaded( 0, Dali::Integration::ResourceBitmap, resourcePtr );
1017 Image ninePatchImage = Image::New( "blah.#.png" );
1018 DALI_TEST_CHECK( ninePatchImage );
1020 ImageActor imageActor = ImageActor::New();
1021 DALI_TEST_CHECK( imageActor );
1022 Stage::GetCurrent().Add( imageActor );
1024 imageActor.SetImage( ninePatchImage );
1027 textureTrace.Reset();
1028 drawTrace.Enable(true);
1029 textureTrace.Enable(true);
1030 glAbstraction.ClearBoundTextures();
1031 std::vector<GLuint> ids;
1032 ids.push_back( 23 );
1033 glAbstraction.SetNextTextureIds( ids );
1035 application.SendNotification();
1036 application.Render();
1038 DALI_TEST_CHECK( drawTrace.FindMethod( "DrawArrays" ) );
1039 typedef std::vector<GLuint> TexVec;
1040 const TexVec& textures = glAbstraction.GetBoundTextures(GL_TEXTURE0);
1041 DALI_TEST_CHECK( textures.size() > 0 );
1042 if( textures.size() > 0 )
1044 DALI_TEST_EQUALS( textures[0], 23u, TEST_LOCATION );
1051 int UtcDaliImageActorNinePatch04(void)
1053 TestApplication application;
1054 TestPlatformAbstraction& platform = application.GetPlatform();
1055 TestGlAbstraction& glAbstraction = application.GetGlAbstraction();
1056 TraceCallStack& textureTrace = glAbstraction.GetTextureTrace();
1057 TraceCallStack& drawTrace = glAbstraction.GetDrawTrace();
1059 tet_infoline("Test the failed loading of a nine-patch image using ImageActor::SetImage()\n");
1061 platform.SetClosestImageSize(Vector2(0, 0));
1062 Integration::ResourcePointer resourcePtr;
1063 platform.SetResourceLoaded( 0, Dali::Integration::ResourceBitmap, resourcePtr );
1065 Image ninePatchImage = Image::New( "blah.#.png" );
1066 DALI_TEST_CHECK( ninePatchImage );
1068 ImageActor imageActor = ImageActor::New();
1069 DALI_TEST_CHECK( imageActor );
1070 Stage::GetCurrent().Add( imageActor );
1072 imageActor.SetImage( ninePatchImage );
1075 textureTrace.Reset();
1076 drawTrace.Enable(true);
1077 textureTrace.Enable(true);
1078 glAbstraction.ClearBoundTextures();
1079 std::vector<GLuint> ids;
1080 ids.push_back( 23 );
1081 glAbstraction.SetNextTextureIds( ids );
1083 application.SendNotification();
1084 application.Render();
1086 // Check that nothing was drawn.
1087 DALI_TEST_CHECK( ! drawTrace.FindMethod( "DrawArrays" ) );
1088 typedef std::vector<GLuint> TexVec;
1089 const TexVec& textures = glAbstraction.GetBoundTextures(GL_TEXTURE0);
1090 DALI_TEST_CHECK( textures.size() == 0u );