2 * Copyright (c) 2014 Samsung Electronics Co., Ltd.
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
8 * http://www.apache.org/licenses/LICENSE-2.0
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
20 #include <dali/public-api/dali-core.h>
21 #include "dali-test-suite-utils/dali-test-suite-utils.h"
25 static const char* TestImageFilename = "icon_wrt.png";
27 void image_actor_test_startup(void)
29 test_return_value = TET_UNDEF;
32 void image_actor_test_cleanup(void)
34 test_return_value = TET_PASS;
38 int UtcDaliImageActorConstructorVoid(void)
40 TestApplication application;
41 tet_infoline("Testing Dali::ImageActor::ImageActor()");
45 DALI_TEST_CHECK(!actor);
49 int UtcDaliImageActorDestructor(void)
51 TestApplication application;
53 ImageActor* actor = new ImageActor();
56 DALI_TEST_CHECK( true );
60 int UtcDaliImageActorNew01(void)
62 TestApplication application;
63 tet_infoline("Positive test for Dali::ImageActor::New()");
65 Image image = ResourceImage::New(TestImageFilename);
66 ImageActor actor = ImageActor::New(image);
67 Stage::GetCurrent().Add(actor);
69 application.SendNotification();
72 application.SendNotification();
74 DALI_TEST_CHECK(application.GetPlatform().WasCalled(TestPlatformAbstraction::LoadResourceFunc));
76 DALI_TEST_CHECK(actor);
80 int UtcDaliImageActorNew02(void)
82 TestApplication application;
83 tet_infoline("Negative test for Dali::ImageActor::New()");
85 Image image = ResourceImage::New("hopefully-this-image-file-does-not-exist");
86 ImageActor actor = ImageActor::New(image);
88 DALI_TEST_CHECK(actor);
92 int UtcDaliImageActorDownCast(void)
94 TestApplication application;
95 tet_infoline("Testing Dali::ImageActor::DownCast()");
97 Image image = ResourceImage::New("IncorrectImageName");
98 ImageActor actor1 = ImageActor::New(image);
99 Actor anActor = Actor::New();
102 Actor child = anActor.GetChildAt(0);
103 ImageActor imageActor = DownCast< ImageActor >(child);
105 DALI_TEST_CHECK(imageActor);
109 int UtcDaliImageActorDownCast2(void)
111 TestApplication application;
112 tet_infoline("Testing Dali::ImageActor::DownCast()");
114 Actor actor1 = Actor::New();
115 Actor anActor = Actor::New();
118 Actor child = anActor.GetChildAt(0);
119 ImageActor imageActor = ImageActor::DownCast(child);
120 DALI_TEST_CHECK(!imageActor);
122 Actor unInitialzedActor;
123 imageActor = ImageActor::DownCast( unInitialzedActor );
124 DALI_TEST_CHECK(!imageActor);
128 int UtcDaliImageActor9Patch(void)
130 TestApplication application;
131 tet_infoline("Positive test for Dali::ImageActor:: 9 patch api");
133 Image image = ResourceImage::New(TestImageFilename);
134 ImageActor actor = ImageActor::New(image);
136 actor.SetStyle(ImageActor::STYLE_NINE_PATCH);
137 Vector4 border(0.1,0.2,0.3,0.4);
138 actor.SetNinePatchBorder(border);
140 DALI_TEST_EQUALS( 0.1f, actor.GetNinePatchBorder().x, TEST_LOCATION );
141 DALI_TEST_EQUALS( 0.2f, actor.GetNinePatchBorder().y, TEST_LOCATION );
142 DALI_TEST_EQUALS( 0.3f, actor.GetNinePatchBorder().z, TEST_LOCATION );
143 DALI_TEST_EQUALS( 0.4f, actor.GetNinePatchBorder().w, TEST_LOCATION );
147 int UtcDaliImageActorPixelArea(void)
149 TestApplication application;
150 tet_infoline("Positive test for Dali::ImageActor::UtcDaliImageActorPixelArea");
152 BufferImage img = BufferImage::New( 10, 10 );
153 ImageActor actor = ImageActor::New( img );
155 DALI_TEST_CHECK( actor.IsPixelAreaSet() == false );
157 ImageActor::PixelArea area( 1, 2, 3, 4 );
158 actor.SetPixelArea( area );
160 DALI_TEST_CHECK( actor.IsPixelAreaSet() == true );
162 DALI_TEST_EQUALS( 1, actor.GetPixelArea().x, TEST_LOCATION );
163 DALI_TEST_EQUALS( 2, actor.GetPixelArea().y, TEST_LOCATION );
164 DALI_TEST_EQUALS( 3, actor.GetPixelArea().width, TEST_LOCATION );
165 DALI_TEST_EQUALS( 4, actor.GetPixelArea().height, TEST_LOCATION );
167 ImageActor actor2 = ImageActor::New( img, ImageActor::PixelArea( 5, 6, 7, 8 ) );
168 DALI_TEST_CHECK( actor2.IsPixelAreaSet() == true );
170 DALI_TEST_EQUALS( 5, actor2.GetPixelArea().x, TEST_LOCATION );
171 DALI_TEST_EQUALS( 6, actor2.GetPixelArea().y, TEST_LOCATION );
172 DALI_TEST_EQUALS( 7, actor2.GetPixelArea().width, TEST_LOCATION );
173 DALI_TEST_EQUALS( 8, actor2.GetPixelArea().height, TEST_LOCATION );
177 // Set a size that is too large on an Image with a shader that requires grid
178 int UtcDaliImageActorSetSize01(void)
180 TestApplication application;
182 BufferImage img = BufferImage::New( 1,1 );
183 ImageActor actor = ImageActor::New( img );
185 ShaderEffect effect = ShaderEffect::New( " ", " ", GEOMETRY_TYPE_IMAGE, ShaderEffect::HINT_GRID );
186 actor.SetShaderEffect( effect );
188 const float INVALID_SIZE = float(1u<<31);
189 Vector3 vector( INVALID_SIZE, INVALID_SIZE, INVALID_SIZE );
191 DALI_TEST_CHECK(vector != actor.GetCurrentSize());
193 actor.SetSize(vector);
194 Stage::GetCurrent().Add(actor);
196 // flush the queue and render once
197 application.SendNotification();
198 application.Render();
200 DALI_TEST_EQUALS(vector, actor.GetCurrentSize(), TEST_LOCATION );
204 int UtcDaliImageActorGetCurrentSize01(void)
206 TestApplication application;
207 tet_infoline("Positive test for Dali::ImageActor::GetCurrentSize");
209 Vector2 initialImageSize(100, 50);
210 BufferImage image = BufferImage::New( initialImageSize.width, initialImageSize.height );
211 ImageActor actor = ImageActor::New( image );
212 Stage::GetCurrent().Add(actor);
214 application.SendNotification();
215 application.Render();
217 DALI_TEST_EQUALS( Vector2(actor.GetCurrentSize()), initialImageSize, TEST_LOCATION );
219 Vector2 size(200.0f, 200.0f);
222 // flush the queue and render once
223 application.SendNotification();
224 application.Render();
225 DALI_TEST_EQUALS( Vector2(actor.GetCurrentSize()), size, TEST_LOCATION );
230 application.Render(8);
232 // Test when a pixel area is set
233 ImageActor::PixelArea area(0, 0, 10, 10);
234 actor.SetPixelArea(area);
235 application.Render(9);
236 // natural size is not used as setsize is called
237 DALI_TEST_EQUALS( Vector2(actor.GetCurrentSize()), size, TEST_LOCATION );
243 int UtcDaliImageActorGetCurrentSize02(void)
245 TestApplication application;
246 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");
248 Vector2 initialImageSize(100, 50);
250 application.GetPlatform().SetClosestImageSize(initialImageSize);
252 Image image = ResourceImage::New("image.jpg");
253 ImageActor actor = ImageActor::New( image );
254 Stage::GetCurrent().Add(actor);
256 application.SendNotification(); // Flush update messages
257 application.Render(); // Process resource request
258 application.SendNotification(); // Flush update messages
259 application.Render(); // Process resource request
261 DALI_TEST_EQUALS( Vector2(actor.GetCurrentSize()), initialImageSize, TEST_LOCATION );
263 // Now complete the image load
264 Integration::ResourceRequest* req = application.GetPlatform().GetRequest();
265 Integration::Bitmap* bitmap = Integration::Bitmap::New( Integration::Bitmap::BITMAP_2D_PACKED_PIXELS, ResourcePolicy::RETAIN );
266 bitmap->GetPackedPixelsProfile()->ReserveBuffer( Pixel::RGBA8888, initialImageSize.width,initialImageSize.height, initialImageSize.width,initialImageSize.height );
268 Integration::ResourcePointer resourcePtr(bitmap); // reference it
269 application.GetPlatform().SetResourceLoaded(req->GetId(), req->GetType()->id, resourcePtr);
270 application.Render(); // Process LoadComplete
271 application.SendNotification(); // Process event messages
272 application.GetPlatform().DiscardRequest(); // Ensure load request is discarded
273 application.GetPlatform().ClearReadyResources(); //
275 DALI_TEST_EQUALS( Vector2(actor.GetCurrentSize()), initialImageSize, TEST_LOCATION );
277 Vector2 size(200.0f, 200.0f);
280 // flush the queue and render once
281 application.SendNotification();
282 application.Render();
283 DALI_TEST_EQUALS( Vector2(actor.GetCurrentSize()), size, TEST_LOCATION );
289 int UtcDaliImageActorGetCurrentSize03(void)
291 TestApplication application;
292 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");
294 const Vector2 closestImageSize( 80, 45);
295 application.GetPlatform().SetClosestImageSize(closestImageSize);
297 ImageAttributes attrs;
298 const Vector2 requestedSize( 40, 30 );
299 attrs.SetSize( requestedSize.width, requestedSize.height );
300 Image image = ResourceImage::New("image.jpg", attrs);
301 ImageActor actor = ImageActor::New( image );
302 Stage::GetCurrent().Add(actor);
304 application.SendNotification(); // Flush update messages
305 application.Render(); // Process resource request
306 application.SendNotification(); // Flush update messages
307 application.Render(); // Process resource request
309 DALI_TEST_EQUALS( Vector2(actor.GetCurrentSize()), requestedSize, TEST_LOCATION );
311 // Now complete the image load
312 Integration::ResourceRequest* req = application.GetPlatform().GetRequest();
313 Integration::Bitmap* bitmap = Integration::Bitmap::New( Integration::Bitmap::BITMAP_2D_PACKED_PIXELS, ResourcePolicy::RETAIN );
314 bitmap->GetPackedPixelsProfile()->ReserveBuffer( Pixel::RGBA8888, closestImageSize.width, closestImageSize.height, closestImageSize.width, closestImageSize.height );
316 Integration::ResourcePointer resourcePtr(bitmap); // reference it
317 application.GetPlatform().SetResourceLoaded(req->GetId(), req->GetType()->id, resourcePtr);
318 application.Render(); // Process LoadComplete
319 application.SendNotification(); // Process event messages
320 application.GetPlatform().DiscardRequest(); // Ensure load request is discarded
321 application.GetPlatform().ClearReadyResources(); //
323 DALI_TEST_EQUALS( Vector2(actor.GetCurrentSize()), requestedSize, TEST_LOCATION );
329 int UtcDaliImageActorGetCurrentSize04(void)
331 TestApplication application;
332 tet_infoline("Positive test for Dali::ImageActor::GetCurrentSize - check a new image doesn't change a set actor size");
334 const Vector2 closestImageSize( 80, 45);
335 application.GetPlatform().SetClosestImageSize(closestImageSize);
337 const Vector2 requestedSize( 40, 30 );
338 ImageAttributes attrs;
339 attrs.SetSize( requestedSize.width, requestedSize.height );
340 Image image = ResourceImage::New("image.jpg", attrs);
341 ImageActor actor = ImageActor::New( image );
342 Stage::GetCurrent().Add(actor);
344 application.SendNotification(); // Flush update messages
345 application.Render(); // Process resource request
347 DALI_TEST_EQUALS( Vector2(actor.GetCurrentSize()), requestedSize, TEST_LOCATION );
349 // Now complete the image load
350 Integration::ResourceRequest* req = application.GetPlatform().GetRequest();
351 Integration::Bitmap* bitmap = Integration::Bitmap::New( Integration::Bitmap::BITMAP_2D_PACKED_PIXELS, ResourcePolicy::RETAIN );
352 bitmap->GetPackedPixelsProfile()->ReserveBuffer( Pixel::RGBA8888, closestImageSize.width, closestImageSize.height, closestImageSize.width, closestImageSize.height );
354 Integration::ResourcePointer resourcePtr(bitmap); // reference it
355 application.GetPlatform().SetResourceLoaded(req->GetId(), req->GetType()->id, resourcePtr);
356 application.Render(); // Process LoadComplete
357 application.SendNotification(); // Process event messages
358 application.GetPlatform().DiscardRequest(); // Ensure load request is discarded
359 application.GetPlatform().ClearReadyResources(); //
361 DALI_TEST_EQUALS( Vector2(actor.GetCurrentSize()), requestedSize, TEST_LOCATION );
363 Vector2 size(200.0f, 200.0f);
366 // flush the queue and render once
367 application.SendNotification();
368 application.Render();
369 DALI_TEST_EQUALS( Vector2(actor.GetCurrentSize()), size, TEST_LOCATION );
371 // Load a different image
373 Vector2 image2ClosestSize = Vector2(240, 150); // The actual size image loader will return for the request below
374 application.GetPlatform().SetClosestImageSize(image2ClosestSize);
376 const Vector2 request2Size( 100, 100 );
377 attrs.SetSize( request2Size.width, request2Size.height );
378 Image image2 = ResourceImage::New("image2.jpg", attrs);
379 actor.SetImage(image2);
381 application.SendNotification(); // Flush update messages
382 application.Render(); // Process resource request
383 application.SendNotification(); // Flush update messages
384 application.Render(); // Process resource request
386 // Ensure the actor size is kept
387 DALI_TEST_EQUALS( Vector2(actor.GetCurrentSize()), size, TEST_LOCATION );
389 // Now complete the image load
390 req = application.GetPlatform().GetRequest();
391 Integration::Bitmap* bitmap2 = Integration::Bitmap::New( Integration::Bitmap::BITMAP_2D_PACKED_PIXELS, ResourcePolicy::RETAIN );
392 bitmap2->GetPackedPixelsProfile()->ReserveBuffer( Pixel::RGBA8888, image2ClosestSize.width, image2ClosestSize.height, image2ClosestSize.width, image2ClosestSize.height );
394 Integration::ResourcePointer resourcePtr2(bitmap2); // reference it
395 application.GetPlatform().SetResourceLoaded(req->GetId(), req->GetType()->id, resourcePtr2);
396 application.Render(); // Process LoadComplete
397 application.SendNotification(); // Process event messages
398 application.GetPlatform().DiscardRequest(); // Ensure load request is discarded
399 application.GetPlatform().ClearReadyResources(); //
401 // Ensure the actor size is kept
402 DALI_TEST_EQUALS( Vector2(actor.GetCurrentSize()), size, 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 = ResourceImage::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, ResourcePolicy::RETAIN );
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 = ResourceImage::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, ResourcePolicy::RETAIN );
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 = ResourceImage::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, ResourcePolicy::RETAIN );
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 = ResourceImage::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, ResourcePolicy::RETAIN );
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 // Clearing pixel area should change actor size to image size
610 actor.SetResizePolicy( ResizePolicy::USE_NATURAL_SIZE, Dimension::ALL_DIMENSIONS );
611 actor.ClearPixelArea();
612 application.SendNotification(); // Process event messages
613 application.Render(); // Process LoadComplete
614 DALI_TEST_EQUALS( Vector2(actor.GetCurrentSize()), requestedSize, TEST_LOCATION );
620 int UtcDaliImageActorDefaultProperties(void)
622 TestApplication application;
623 tet_infoline("Testing Dali::ImageActor DefaultProperties");
625 BufferImage img = BufferImage::New( 10, 10 );
626 ImageActor actor = ImageActor::New( img );
628 std::vector<Property::Index> indices;
629 indices.push_back(ImageActor::Property::PIXEL_AREA );
630 indices.push_back(ImageActor::Property::STYLE );
631 indices.push_back(ImageActor::Property::BORDER );
632 indices.push_back(ImageActor::Property::IMAGE );
634 DALI_TEST_CHECK(actor.GetPropertyCount() == ( Actor::New().GetPropertyCount() + indices.size() ) );
636 for(std::vector<Property::Index>::iterator iter = indices.begin(); iter != indices.end(); ++iter)
638 DALI_TEST_CHECK( *iter == actor.GetPropertyIndex(actor.GetPropertyName(*iter)) );
639 DALI_TEST_CHECK( actor.IsPropertyWritable(*iter) );
640 DALI_TEST_CHECK( !actor.IsPropertyAnimatable(*iter) );
641 DALI_TEST_CHECK( actor.GetPropertyType(*iter) == actor.GetPropertyType(*iter) ); // just checking call succeeds
644 // set/get one of them
645 actor.SetPixelArea(ImageActor::PixelArea( 0, 0, 0, 0 ));
647 ImageActor::PixelArea area( 1, 2, 3, 4 );
648 actor.SetProperty(ImageActor::Property::PIXEL_AREA, Property::Value(Rect<int>(area)));
650 DALI_TEST_CHECK(Property::RECTANGLE == actor.GetPropertyType(ImageActor::Property::PIXEL_AREA));
652 Property::Value v = actor.GetProperty(ImageActor::Property::PIXEL_AREA);
654 DALI_TEST_CHECK(v.Get<Rect<int> >() == area);
659 int UtcDaliImageActorUseImageAlpha01(void)
661 TestApplication application;
663 tet_infoline("Testing Dali::RenderableActor::SetUseImageAlpha()");
665 BufferImage image = BufferImage::New( 100, 50 );
666 ImageActor actor = ImageActor::New( image );
667 actor.SetBlendMode( BlendingMode::ON );
668 actor.SetSize(100, 50);
669 application.GetGlAbstraction().EnableCullFaceCallTrace(true); // For Enable(GL_BLEND)
670 Stage::GetCurrent().Add(actor);
672 application.SendNotification();
673 application.Render();
675 const TraceCallStack& callTrace = application.GetGlAbstraction().GetCullFaceTrace();
676 DALI_TEST_EQUALS( BlendEnabled( callTrace), true, TEST_LOCATION );
677 DALI_TEST_EQUALS( BlendDisabled( callTrace ), false, TEST_LOCATION );
681 int UtcDaliImageActorUseImageAlpha02(void)
683 TestApplication application;
685 tet_infoline("Testing Dali::RenderableActor::SetUseImageAlpha()");
687 BufferImage image = BufferImage::New( 100, 50 );
688 ImageActor actor = ImageActor::New( image );
689 actor.SetBlendMode( BlendingMode::OFF );
690 actor.SetSize(100, 50);
691 application.GetGlAbstraction().EnableCullFaceCallTrace(true); // For Enable(GL_BLEND)
692 Stage::GetCurrent().Add(actor);
694 application.SendNotification();
695 application.Render();
697 const TraceCallStack& callTrace = application.GetGlAbstraction().GetCullFaceTrace();
698 DALI_TEST_EQUALS( BlendDisabled( callTrace ), false, TEST_LOCATION );
699 DALI_TEST_EQUALS( BlendEnabled( callTrace), false, TEST_LOCATION );
703 int UtcDaliImageActorUseImageAlpha03(void)
705 TestApplication application;
707 tet_infoline("Testing Dali::RenderableActor::SetUseImageAlpha()");
709 BufferImage image = BufferImage::New( 100, 50 );
710 ImageActor actor = ImageActor::New( image );
711 actor.SetBlendMode( BlendingMode::AUTO );
712 actor.SetColor(Vector4(1.0, 1.0, 1.0, 0.5));
713 actor.SetSize(100, 50);
714 application.GetGlAbstraction().EnableCullFaceCallTrace(true); // For Enable(GL_BLEND)
715 Stage::GetCurrent().Add(actor);
717 application.SendNotification();
718 application.Render();
720 const TraceCallStack& callTrace = application.GetGlAbstraction().GetCullFaceTrace();
721 DALI_TEST_EQUALS( BlendDisabled( callTrace ), false, TEST_LOCATION );
722 DALI_TEST_EQUALS( BlendEnabled( callTrace), true, TEST_LOCATION );
726 int UtcDaliImageActorUseImageAlpha04(void)
728 TestApplication application;
730 tet_infoline("Testing Dali::RenderableActor::SetUseImageAlpha()");
732 FrameBufferImage image = FrameBufferImage::New( 100, 50, Pixel::RGBA8888 );
733 RenderTaskList taskList = Stage::GetCurrent().GetRenderTaskList();
734 RenderTask task = taskList.GetTask( 0u );
735 task.SetTargetFrameBuffer( image ); // To ensure frame buffer is connected
736 application.GetGlAbstraction().SetCheckFramebufferStatusResult( GL_FRAMEBUFFER_COMPLETE );
737 application.SendNotification();
738 application.Render(0);
740 ImageActor actor = ImageActor::New( image );
741 application.SendNotification();
742 application.Render(0);
744 actor.SetBlendMode( BlendingMode::ON );
745 actor.SetColor(Vector4(1.0, 1.0, 1.0, 1.0));
746 actor.SetSize(100, 50);
747 application.GetGlAbstraction().EnableCullFaceCallTrace(true); // For Enable(GL_BLEND)
748 Stage::GetCurrent().Add(actor);
750 application.SendNotification();
751 application.Render();
753 const TraceCallStack& callTrace = application.GetGlAbstraction().GetCullFaceTrace();
754 DALI_TEST_EQUALS( BlendDisabled( callTrace ), false, TEST_LOCATION );
755 DALI_TEST_EQUALS( BlendEnabled( callTrace), true, TEST_LOCATION );
759 int UtcDaliImageActorUseImageAlpha05(void)
761 TestApplication application;
763 tet_infoline("Testing Dali::RenderableActor::SetUseImageAlpha()");
765 BufferImage image = BufferImage::New( 100, 50, Pixel::RGB888 );
766 ImageActor actor = ImageActor::New( image );
767 actor.SetBlendMode( BlendingMode::AUTO );
768 actor.SetColor(Vector4(1.0, 1.0, 1.0, 1.0));
769 actor.SetSize(100, 50);
770 application.GetGlAbstraction().EnableCullFaceCallTrace(true); // For Enable(GL_BLEND)
771 Stage::GetCurrent().Add(actor);
773 application.SendNotification();
774 application.Render();
776 const TraceCallStack& callTrace = application.GetGlAbstraction().GetCullFaceTrace();
777 DALI_TEST_EQUALS( BlendDisabled( callTrace ), false, TEST_LOCATION );
778 DALI_TEST_EQUALS( BlendEnabled( callTrace), false, TEST_LOCATION );
782 int UtcDaliImageActorClearPixelArea(void)
784 TestApplication application;
786 BufferImage img = BufferImage::New( 10, 10 );
787 ImageActor actor = ImageActor::New( img );
789 DALI_TEST_CHECK( actor.IsPixelAreaSet() == false );
791 ImageActor::PixelArea area( 1, 2, 3, 4 );
792 actor.SetPixelArea( area );
794 DALI_TEST_CHECK( actor.IsPixelAreaSet() == true );
796 actor.ClearPixelArea();
798 DALI_TEST_CHECK( actor.IsPixelAreaSet() == false );
802 int UtcDaliImageGetStyle(void)
804 TestApplication application;
806 Image image = ResourceImage::New(TestImageFilename);
807 ImageActor actor = ImageActor::New(image);
809 actor.SetStyle(ImageActor::STYLE_NINE_PATCH);
811 // flush the queue and render once
812 application.SendNotification();
813 application.Render();
815 DALI_TEST_EQUALS( ImageActor::STYLE_NINE_PATCH, actor.GetStyle(), TEST_LOCATION );
819 int UtcDaliImageSetNinePatchBorder(void)
821 TestApplication application;
823 Image image = ResourceImage::New(TestImageFilename);
824 ImageActor actor = ImageActor::New(image);
826 actor.SetStyle(ImageActor::STYLE_NINE_PATCH);
827 actor.SetNinePatchBorder(Vector4( 1.0f, 2.0f, 3.0f, 4.0f));
829 DALI_TEST_EQUALS( 1.0f, actor.GetNinePatchBorder().x, TEST_LOCATION );
830 DALI_TEST_EQUALS( 2.0f, actor.GetNinePatchBorder().y, TEST_LOCATION );
831 DALI_TEST_EQUALS( 3.0f, actor.GetNinePatchBorder().z, TEST_LOCATION );
832 DALI_TEST_EQUALS( 4.0f, actor.GetNinePatchBorder().w, TEST_LOCATION );
836 int UtcDaliImageActorNewNull(void)
838 TestApplication application;
840 ImageActor actor = ImageActor::New(Image());
842 DALI_TEST_CHECK(actor);
846 int UtcDaliImageActorNewNullWithArea(void)
848 TestApplication application;
850 ImageActor::PixelArea area( 1, 2, 3, 4 );
852 ImageActor actor = ImageActor::New(Image(), area);
854 DALI_TEST_CHECK(actor);
858 int UtcDaliImageActorSetImage(void)
860 TestApplication application;
862 ImageActor actor = ImageActor::New(Image());
864 DALI_TEST_CHECK(actor);
866 actor.SetImage( Image() );
868 DALI_TEST_CHECK(!actor.GetImage());
872 int UtcDaliImageActorPropertyIndices(void)
874 TestApplication application;
875 Actor basicActor = Actor::New();
876 ImageActor imageActor = ImageActor::New();
878 Property::IndexContainer indices;
879 imageActor.GetPropertyIndices( indices );
880 DALI_TEST_CHECK( indices.size() > basicActor.GetPropertyCount() );
881 DALI_TEST_EQUALS( indices.size(), imageActor.GetPropertyCount(), TEST_LOCATION );
885 int UtcDaliImageActorImageProperty(void)
887 TestApplication application;
888 Image image = ResourceImage::New( "MY_PATH" );
889 ImageActor imageActor = ImageActor::New( image );
891 Stage::GetCurrent().Add( imageActor );
892 application.SendNotification();
893 application.Render();
895 Property::Value imageMap = imageActor.GetProperty( ImageActor::Property::IMAGE );
896 DALI_TEST_CHECK( imageMap.HasKey( "filename" ) );
897 DALI_TEST_EQUALS( imageMap.GetValue( "filename" ).Get< std::string >(), "MY_PATH", TEST_LOCATION );
901 int UtcDaliImageActorNinePatch01(void)
903 TestApplication application;
904 TestPlatformAbstraction& platform = application.GetPlatform();
905 TestGlAbstraction& glAbstraction = application.GetGlAbstraction();
906 TraceCallStack& textureTrace = glAbstraction.GetTextureTrace();
907 TraceCallStack& drawTrace = glAbstraction.GetDrawTrace();
909 tet_infoline("Test the successful loading of a nine-patch image\n");
911 platform.SetClosestImageSize(Vector2(4, 4));
912 Integration::Bitmap* bitmap = Integration::Bitmap::New( Integration::Bitmap::BITMAP_2D_PACKED_PIXELS, ResourcePolicy::RETAIN );
913 Integration::PixelBuffer* pixels = bitmap->GetPackedPixelsProfile()->ReserveBuffer( Pixel::RGBA8888, 4,4,4,4 );
914 memset( pixels, 0, 64 );
916 Integration::ResourcePointer resourcePtr(bitmap); // reference it
917 platform.SetResourceLoaded( 0, Dali::Integration::ResourceBitmap, resourcePtr );
919 Image ninePatchImage = ResourceImage::New( "blah.#.png" );
920 DALI_TEST_CHECK( ninePatchImage );
922 ImageActor imageActor = ImageActor::New( ninePatchImage );
923 DALI_TEST_CHECK( imageActor );
924 Stage::GetCurrent().Add( imageActor );
927 textureTrace.Reset();
928 drawTrace.Enable(true);
929 textureTrace.Enable(true);
930 glAbstraction.ClearBoundTextures();
931 std::vector<GLuint> ids;
933 glAbstraction.SetNextTextureIds( ids );
935 application.SendNotification();
936 application.Render();
938 DALI_TEST_CHECK( drawTrace.FindMethod( "DrawArrays" ) );
939 typedef std::vector<GLuint> TexVec;
940 const TexVec& textures = glAbstraction.GetBoundTextures(GL_TEXTURE0);
941 DALI_TEST_CHECK( textures.size() > 0 );
942 if( textures.size() > 0 )
944 DALI_TEST_EQUALS( textures[0], 23u, TEST_LOCATION );
951 int UtcDaliImageActorNinePatch02(void)
953 TestApplication application;
954 TestPlatformAbstraction& platform = application.GetPlatform();
955 TestGlAbstraction& glAbstraction = application.GetGlAbstraction();
956 TraceCallStack& textureTrace = glAbstraction.GetTextureTrace();
957 TraceCallStack& drawTrace = glAbstraction.GetDrawTrace();
959 tet_infoline("Test the failed loading of a nine-patch image\n");
961 platform.SetClosestImageSize(Vector2(0, 0));
962 Integration::ResourcePointer resourcePtr;
963 platform.SetResourceLoaded( 0, Dali::Integration::ResourceBitmap, resourcePtr );
965 Image ninePatchImage = ResourceImage::New( "blah.#.png" );
966 DALI_TEST_CHECK( ninePatchImage );
968 ImageActor imageActor = ImageActor::New( ninePatchImage );
969 DALI_TEST_CHECK( imageActor );
970 Stage::GetCurrent().Add( imageActor );
973 textureTrace.Reset();
974 drawTrace.Enable(true);
975 textureTrace.Enable(true);
976 glAbstraction.ClearBoundTextures();
977 std::vector<GLuint> ids;
979 glAbstraction.SetNextTextureIds( ids );
981 application.SendNotification();
982 application.Render();
984 // Check that nothing was drawn.
985 DALI_TEST_CHECK( ! drawTrace.FindMethod( "DrawArrays" ) );
986 typedef std::vector<GLuint> TexVec;
987 const TexVec& textures = glAbstraction.GetBoundTextures(GL_TEXTURE0);
988 DALI_TEST_CHECK( textures.size() == 0u );
994 int UtcDaliImageActorNinePatch03(void)
996 TestApplication application;
997 TestPlatformAbstraction& platform = application.GetPlatform();
998 TestGlAbstraction& glAbstraction = application.GetGlAbstraction();
999 TraceCallStack& textureTrace = glAbstraction.GetTextureTrace();
1000 TraceCallStack& drawTrace = glAbstraction.GetDrawTrace();
1002 tet_infoline("Test the successful loading of a nine-patch image added using ImageActor::SetImage()\n");
1004 platform.SetClosestImageSize(Vector2(4, 4));
1005 Integration::Bitmap* bitmap = Integration::Bitmap::New( Integration::Bitmap::BITMAP_2D_PACKED_PIXELS, ResourcePolicy::RETAIN );
1006 Integration::PixelBuffer* pixels = bitmap->GetPackedPixelsProfile()->ReserveBuffer( Pixel::RGBA8888, 4,4,4,4 );
1007 memset( pixels, 0, 64 );
1009 Integration::ResourcePointer resourcePtr(bitmap); // reference it
1010 platform.SetResourceLoaded( 0, Dali::Integration::ResourceBitmap, resourcePtr );
1012 Image ninePatchImage = ResourceImage::New( "blah.#.png" );
1013 DALI_TEST_CHECK( ninePatchImage );
1015 ImageActor imageActor = ImageActor::New();
1016 DALI_TEST_CHECK( imageActor );
1017 Stage::GetCurrent().Add( imageActor );
1019 imageActor.SetImage( ninePatchImage );
1022 textureTrace.Reset();
1023 drawTrace.Enable(true);
1024 textureTrace.Enable(true);
1025 glAbstraction.ClearBoundTextures();
1026 std::vector<GLuint> ids;
1027 ids.push_back( 23 );
1028 glAbstraction.SetNextTextureIds( ids );
1030 application.SendNotification();
1031 application.Render();
1033 DALI_TEST_CHECK( drawTrace.FindMethod( "DrawArrays" ) );
1034 typedef std::vector<GLuint> TexVec;
1035 const TexVec& textures = glAbstraction.GetBoundTextures(GL_TEXTURE0);
1036 DALI_TEST_CHECK( textures.size() > 0 );
1037 if( textures.size() > 0 )
1039 DALI_TEST_EQUALS( textures[0], 23u, TEST_LOCATION );
1046 int UtcDaliImageActorNinePatch04(void)
1048 TestApplication application;
1049 TestPlatformAbstraction& platform = application.GetPlatform();
1050 TestGlAbstraction& glAbstraction = application.GetGlAbstraction();
1051 TraceCallStack& textureTrace = glAbstraction.GetTextureTrace();
1052 TraceCallStack& drawTrace = glAbstraction.GetDrawTrace();
1054 tet_infoline("Test the failed loading of a nine-patch image using ImageActor::SetImage()\n");
1056 platform.SetClosestImageSize(Vector2(0, 0));
1057 Integration::ResourcePointer resourcePtr;
1058 platform.SetResourceLoaded( 0, Dali::Integration::ResourceBitmap, resourcePtr );
1060 Image ninePatchImage = ResourceImage::New( "blah.#.png" );
1061 DALI_TEST_CHECK( ninePatchImage );
1063 ImageActor imageActor = ImageActor::New();
1064 DALI_TEST_CHECK( imageActor );
1065 Stage::GetCurrent().Add( imageActor );
1067 imageActor.SetImage( ninePatchImage );
1070 textureTrace.Reset();
1071 drawTrace.Enable(true);
1072 textureTrace.Enable(true);
1073 glAbstraction.ClearBoundTextures();
1074 std::vector<GLuint> ids;
1075 ids.push_back( 23 );
1076 glAbstraction.SetNextTextureIds( ids );
1078 application.SendNotification();
1079 application.Render();
1081 // Check that nothing was drawn.
1082 DALI_TEST_CHECK( ! drawTrace.FindMethod( "DrawArrays" ) );
1083 typedef std::vector<GLuint> TexVec;
1084 const TexVec& textures = glAbstraction.GetBoundTextures(GL_TEXTURE0);
1085 DALI_TEST_CHECK( textures.size() == 0u );
1090 int UtcDaliImageActorGetNaturalSize(void)
1092 TestApplication application;
1095 BufferImage img = BufferImage::New( 10, 10 );
1096 ImageActor actor = ImageActor::New( img );
1098 DALI_TEST_CHECK( actor.GetNaturalSize().GetVectorXY() == Vector2( 10, 10 ) );
1101 ImageActor::PixelArea area( 1, 2, 3, 4 );
1102 actor.SetPixelArea( area );
1104 DALI_TEST_CHECK( actor.GetNaturalSize().GetVectorXY() == Vector2( 3, 4 ) );