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/integration-api/bitmap.h>
22 #include "dali-test-suite-utils/dali-test-suite-utils.h"
26 static const char* TestImageFilename = "icon_wrt.png";
28 void image_actor_test_startup(void)
30 test_return_value = TET_UNDEF;
33 void image_actor_test_cleanup(void)
35 test_return_value = TET_PASS;
39 int UtcDaliImageActorConstructorVoid(void)
41 TestApplication application;
42 tet_infoline("Testing Dali::ImageActor::ImageActor()");
46 DALI_TEST_CHECK(!actor);
50 int UtcDaliImageActorDestructor(void)
52 TestApplication application;
54 ImageActor* actor = new ImageActor();
57 DALI_TEST_CHECK( true );
61 int UtcDaliImageActorNew01(void)
63 TestApplication application;
64 tet_infoline("Positive test for Dali::ImageActor::New()");
66 Image image = ResourceImage::New(TestImageFilename);
67 ImageActor actor = ImageActor::New(image);
68 Stage::GetCurrent().Add(actor);
70 application.SendNotification();
73 application.SendNotification();
75 DALI_TEST_CHECK(application.GetPlatform().WasCalled(TestPlatformAbstraction::LoadResourceFunc));
77 DALI_TEST_CHECK(actor);
81 int UtcDaliImageActorNew02(void)
83 TestApplication application;
84 tet_infoline("Negative test for Dali::ImageActor::New()");
86 Image image = ResourceImage::New("hopefully-this-image-file-does-not-exist");
87 ImageActor actor = ImageActor::New(image);
89 DALI_TEST_CHECK(actor);
93 int UtcDaliImageActorDownCast(void)
95 TestApplication application;
96 tet_infoline("Testing Dali::ImageActor::DownCast()");
98 Image image = ResourceImage::New("IncorrectImageName");
99 ImageActor actor1 = ImageActor::New(image);
100 Actor anActor = Actor::New();
103 Actor child = anActor.GetChildAt(0);
104 ImageActor imageActor = DownCast< ImageActor >(child);
106 DALI_TEST_CHECK(imageActor);
110 int UtcDaliImageActorDownCast2(void)
112 TestApplication application;
113 tet_infoline("Testing Dali::ImageActor::DownCast()");
115 Actor actor1 = Actor::New();
116 Actor anActor = Actor::New();
119 Actor child = anActor.GetChildAt(0);
120 ImageActor imageActor = ImageActor::DownCast(child);
121 DALI_TEST_CHECK(!imageActor);
123 Actor unInitialzedActor;
124 imageActor = ImageActor::DownCast( unInitialzedActor );
125 DALI_TEST_CHECK(!imageActor);
129 int UtcDaliImageActor9Patch(void)
131 TestApplication application;
132 tet_infoline("Positive test for Dali::ImageActor:: 9 patch api");
134 Image image = ResourceImage::New(TestImageFilename);
135 ImageActor actor = ImageActor::New(image);
137 actor.SetStyle(ImageActor::STYLE_NINE_PATCH);
138 Vector4 border(0.1,0.2,0.3,0.4);
139 actor.SetNinePatchBorder(border);
141 DALI_TEST_EQUALS( 0.1f, actor.GetNinePatchBorder().x, TEST_LOCATION );
142 DALI_TEST_EQUALS( 0.2f, actor.GetNinePatchBorder().y, TEST_LOCATION );
143 DALI_TEST_EQUALS( 0.3f, actor.GetNinePatchBorder().z, TEST_LOCATION );
144 DALI_TEST_EQUALS( 0.4f, actor.GetNinePatchBorder().w, TEST_LOCATION );
148 int UtcDaliImageActorPixelArea(void)
150 TestApplication application;
151 tet_infoline("Positive test for Dali::ImageActor::UtcDaliImageActorPixelArea");
153 BufferImage img = BufferImage::New( 10, 10 );
154 ImageActor actor = ImageActor::New( img );
156 DALI_TEST_CHECK( actor.IsPixelAreaSet() == false );
158 ImageActor::PixelArea area( 1, 2, 3, 4 );
159 actor.SetPixelArea( area );
161 DALI_TEST_CHECK( actor.IsPixelAreaSet() == true );
163 DALI_TEST_EQUALS( 1, actor.GetPixelArea().x, TEST_LOCATION );
164 DALI_TEST_EQUALS( 2, actor.GetPixelArea().y, TEST_LOCATION );
165 DALI_TEST_EQUALS( 3, actor.GetPixelArea().width, TEST_LOCATION );
166 DALI_TEST_EQUALS( 4, actor.GetPixelArea().height, TEST_LOCATION );
168 ImageActor actor2 = ImageActor::New( img, ImageActor::PixelArea( 5, 6, 7, 8 ) );
169 DALI_TEST_CHECK( actor2.IsPixelAreaSet() == true );
171 DALI_TEST_EQUALS( 5, actor2.GetPixelArea().x, TEST_LOCATION );
172 DALI_TEST_EQUALS( 6, actor2.GetPixelArea().y, TEST_LOCATION );
173 DALI_TEST_EQUALS( 7, actor2.GetPixelArea().width, TEST_LOCATION );
174 DALI_TEST_EQUALS( 8, actor2.GetPixelArea().height, TEST_LOCATION );
178 // Set a size that is too large on an Image with a shader that requires grid
179 int UtcDaliImageActorSetSize01(void)
181 TestApplication application;
183 BufferImage img = BufferImage::New( 1,1 );
184 ImageActor actor = ImageActor::New( img );
186 ShaderEffect effect = ShaderEffect::New( " ", " ", GEOMETRY_TYPE_IMAGE, ShaderEffect::HINT_GRID );
187 actor.SetShaderEffect( effect );
189 const float INVALID_SIZE = float(1u<<31);
190 Vector3 vector( INVALID_SIZE, INVALID_SIZE, INVALID_SIZE );
192 DALI_TEST_CHECK(vector != actor.GetCurrentSize());
194 actor.SetSize(vector);
195 Stage::GetCurrent().Add(actor);
197 // flush the queue and render once
198 application.SendNotification();
199 application.Render();
201 DALI_TEST_EQUALS(vector, actor.GetCurrentSize(), TEST_LOCATION );
205 int UtcDaliImageActorGetCurrentSize01(void)
207 TestApplication application;
208 tet_infoline("Positive test for Dali::ImageActor::GetCurrentSize");
210 Vector2 initialImageSize(100, 50);
211 BufferImage image = BufferImage::New( initialImageSize.width, initialImageSize.height );
212 ImageActor actor = ImageActor::New( image );
213 Stage::GetCurrent().Add(actor);
215 application.SendNotification();
216 application.Render();
218 DALI_TEST_EQUALS( Vector2(actor.GetCurrentSize()), initialImageSize, TEST_LOCATION );
220 Vector2 size(200.0f, 200.0f);
223 // flush the queue and render once
224 application.SendNotification();
225 application.Render();
226 DALI_TEST_EQUALS( Vector2(actor.GetCurrentSize()), size, TEST_LOCATION );
231 application.Render(8);
233 // Test when a pixel area is set
234 ImageActor::PixelArea area(0, 0, 10, 10);
235 actor.SetPixelArea(area);
236 application.Render(9);
237 // natural size is not used as setsize is called
238 DALI_TEST_EQUALS( Vector2(actor.GetCurrentSize()), size, TEST_LOCATION );
244 int UtcDaliImageActorGetCurrentSize02(void)
246 TestApplication application;
247 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");
249 Vector2 initialImageSize(100, 50);
251 application.GetPlatform().SetClosestImageSize(initialImageSize);
253 Image image = ResourceImage::New("image.jpg");
254 ImageActor actor = ImageActor::New( image );
255 Stage::GetCurrent().Add(actor);
257 application.SendNotification(); // Flush update messages
258 application.Render(); // Process resource request
259 application.SendNotification(); // Flush update messages
260 application.Render(); // Process resource request
262 DALI_TEST_EQUALS( Vector2(actor.GetCurrentSize()), initialImageSize, TEST_LOCATION );
264 // Now complete the image load
265 Integration::ResourceRequest* req = application.GetPlatform().GetRequest();
266 Integration::Bitmap* bitmap = Integration::Bitmap::New( Integration::Bitmap::BITMAP_2D_PACKED_PIXELS, ResourcePolicy::RETAIN );
267 bitmap->GetPackedPixelsProfile()->ReserveBuffer( Pixel::RGBA8888, initialImageSize.width,initialImageSize.height, initialImageSize.width,initialImageSize.height );
269 Integration::ResourcePointer resourcePtr(bitmap); // reference it
270 application.GetPlatform().SetResourceLoaded(req->GetId(), req->GetType()->id, resourcePtr);
271 application.Render(); // Process LoadComplete
272 application.SendNotification(); // Process event messages
273 application.GetPlatform().DiscardRequest(); // Ensure load request is discarded
274 application.GetPlatform().ClearReadyResources(); //
276 DALI_TEST_EQUALS( Vector2(actor.GetCurrentSize()), initialImageSize, TEST_LOCATION );
278 Vector2 size(200.0f, 200.0f);
281 // flush the queue and render once
282 application.SendNotification();
283 application.Render();
284 DALI_TEST_EQUALS( Vector2(actor.GetCurrentSize()), size, TEST_LOCATION );
290 int UtcDaliImageActorGetCurrentSize03(void)
292 TestApplication application;
293 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");
295 const Vector2 closestImageSize( 80, 45);
296 application.GetPlatform().SetClosestImageSize(closestImageSize);
298 Vector2 requestedSize( 40, 30 );
299 Image image = ResourceImage::New("image.jpg", ImageDimensions( requestedSize.x, requestedSize.y ), FittingMode::DEFAULT, SamplingMode::DEFAULT );
300 ImageActor actor = ImageActor::New( image );
301 Stage::GetCurrent().Add(actor);
303 application.SendNotification(); // Flush update messages
304 application.Render(); // Process resource request
305 application.SendNotification(); // Flush update messages
306 application.Render(); // Process resource request
308 DALI_TEST_EQUALS( Vector2(actor.GetCurrentSize()), requestedSize, TEST_LOCATION );
310 // Now complete the image load
311 Integration::ResourceRequest* req = application.GetPlatform().GetRequest();
312 Integration::Bitmap* bitmap = Integration::Bitmap::New( Integration::Bitmap::BITMAP_2D_PACKED_PIXELS, ResourcePolicy::RETAIN );
313 bitmap->GetPackedPixelsProfile()->ReserveBuffer( Pixel::RGBA8888, closestImageSize.width, closestImageSize.height, closestImageSize.width, closestImageSize.height );
315 Integration::ResourcePointer resourcePtr(bitmap); // reference it
316 application.GetPlatform().SetResourceLoaded(req->GetId(), req->GetType()->id, resourcePtr);
317 application.Render(); // Process LoadComplete
318 application.SendNotification(); // Process event messages
319 application.GetPlatform().DiscardRequest(); // Ensure load request is discarded
320 application.GetPlatform().ClearReadyResources(); //
322 DALI_TEST_EQUALS( Vector2(actor.GetCurrentSize()), requestedSize, TEST_LOCATION );
328 int UtcDaliImageActorGetCurrentSize04(void)
330 TestApplication application;
331 tet_infoline("Positive test for Dali::ImageActor::GetCurrentSize - check a new image doesn't change a set actor size");
333 const Vector2 closestImageSize( 80, 45);
334 application.GetPlatform().SetClosestImageSize(closestImageSize);
336 Vector2 requestedSize( 40, 30 );
337 Image image = ResourceImage::New("image.jpg", ImageDimensions( requestedSize.x, requestedSize.y ), FittingMode::DEFAULT, SamplingMode::DEFAULT );
338 ImageActor actor = ImageActor::New( image );
339 Stage::GetCurrent().Add(actor);
341 application.SendNotification(); // Flush update messages
342 application.Render(); // Process resource request
344 DALI_TEST_EQUALS( Vector2(actor.GetCurrentSize()), requestedSize, TEST_LOCATION );
346 // Now complete the image load
347 Integration::ResourceRequest* req = application.GetPlatform().GetRequest();
348 Integration::Bitmap* bitmap = Integration::Bitmap::New( Integration::Bitmap::BITMAP_2D_PACKED_PIXELS, ResourcePolicy::RETAIN );
349 bitmap->GetPackedPixelsProfile()->ReserveBuffer( Pixel::RGBA8888, closestImageSize.width, closestImageSize.height, closestImageSize.width, closestImageSize.height );
351 Integration::ResourcePointer resourcePtr(bitmap); // reference it
352 application.GetPlatform().SetResourceLoaded(req->GetId(), req->GetType()->id, resourcePtr);
353 application.Render(); // Process LoadComplete
354 application.SendNotification(); // Process event messages
355 application.GetPlatform().DiscardRequest(); // Ensure load request is discarded
356 application.GetPlatform().ClearReadyResources(); //
358 DALI_TEST_EQUALS( Vector2(actor.GetCurrentSize()), requestedSize, TEST_LOCATION );
360 Vector2 size(200.0f, 200.0f);
363 // flush the queue and render once
364 application.SendNotification();
365 application.Render();
366 DALI_TEST_EQUALS( Vector2(actor.GetCurrentSize()), size, TEST_LOCATION );
368 // Load a different image
370 Vector2 image2ClosestSize = Vector2(240, 150); // The actual size image loader will return for the request below
371 application.GetPlatform().SetClosestImageSize(image2ClosestSize);
373 const Vector2 request2Size( 100, 100 );
374 Image image2 = ResourceImage::New("image.jpg", ImageDimensions( request2Size.x, request2Size.y ), FittingMode::DEFAULT, SamplingMode::DEFAULT );
375 actor.SetImage(image2);
377 application.SendNotification(); // Flush update messages
378 application.Render(); // Process resource request
379 application.SendNotification(); // Flush update messages
380 application.Render(); // Process resource request
382 // Ensure the actor size is kept
383 DALI_TEST_EQUALS( Vector2(actor.GetCurrentSize()), size, TEST_LOCATION );
385 // Now complete the image load
386 req = application.GetPlatform().GetRequest();
387 Integration::Bitmap* bitmap2 = Integration::Bitmap::New( Integration::Bitmap::BITMAP_2D_PACKED_PIXELS, ResourcePolicy::RETAIN );
388 bitmap2->GetPackedPixelsProfile()->ReserveBuffer( Pixel::RGBA8888, image2ClosestSize.width, image2ClosestSize.height, image2ClosestSize.width, image2ClosestSize.height );
390 Integration::ResourcePointer resourcePtr2(bitmap2); // reference it
391 application.GetPlatform().SetResourceLoaded(req->GetId(), req->GetType()->id, resourcePtr2);
392 application.Render(); // Process LoadComplete
393 application.SendNotification(); // Process event messages
394 application.GetPlatform().DiscardRequest(); // Ensure load request is discarded
395 application.GetPlatform().ClearReadyResources(); //
397 // Ensure the actor size is kept
398 DALI_TEST_EQUALS( Vector2(actor.GetCurrentSize()), size, TEST_LOCATION );
404 int UtcDaliImageActorGetCurrentSize05(void)
406 TestApplication application;
407 tet_infoline("Positive test for Dali::ImageActor::GetCurrentSize - check a new image doens't change actor size until load complete");
409 Vector2 closestImageSize( 80, 45);
410 application.GetPlatform().SetClosestImageSize(closestImageSize);
412 Vector2 requestedSize( 40, 30 );
413 Image image = ResourceImage::New("image.jpg", ImageDimensions( requestedSize.x, requestedSize.y ), FittingMode::DEFAULT, SamplingMode::DEFAULT );
414 ImageActor actor = ImageActor::New( image );
415 Stage::GetCurrent().Add(actor);
417 application.SendNotification(); // Flush update messages
418 application.Render(); // Process resource request
420 DALI_TEST_EQUALS( Vector2(actor.GetCurrentSize()), requestedSize, TEST_LOCATION );
422 // Now complete the image load
423 Integration::ResourceRequest* req = application.GetPlatform().GetRequest();
424 Integration::Bitmap* bitmap = Integration::Bitmap::New( Integration::Bitmap::BITMAP_2D_PACKED_PIXELS, ResourcePolicy::RETAIN );
425 bitmap->GetPackedPixelsProfile()->ReserveBuffer( Pixel::RGBA8888, closestImageSize.width, closestImageSize.height, closestImageSize.width, closestImageSize.height );
427 Integration::ResourcePointer resourcePtr(bitmap); // reference it
428 application.GetPlatform().SetResourceLoaded(req->GetId(), req->GetType()->id, resourcePtr);
429 application.Render(); // Process LoadComplete
430 application.SendNotification(); // Process event messages
431 application.GetPlatform().DiscardRequest(); // Ensure load request is discarded
432 application.GetPlatform().ClearReadyResources(); //
434 DALI_TEST_EQUALS( Vector2(actor.GetCurrentSize()), requestedSize, TEST_LOCATION );
436 // Load a different image
438 Vector2 image2ClosestSize = Vector2(240, 150);
439 application.GetPlatform().SetClosestImageSize(image2ClosestSize);
441 const Vector2 requestedSize2( 100, 100 );
442 Image image2 = ResourceImage::New("image.jpg", ImageDimensions( requestedSize2.x, requestedSize2.y ), FittingMode::DEFAULT, SamplingMode::DEFAULT );
443 actor.SetImage(image2);
445 application.SendNotification(); // Flush update messages
446 application.Render(); // Process resource request
447 application.SendNotification(); // Flush update messages
448 application.Render(); // Process resource request
450 // Ensure the actor size is kept
451 DALI_TEST_EQUALS( Vector2(actor.GetCurrentSize()), requestedSize2, TEST_LOCATION );
453 // Now complete the image load
454 req = application.GetPlatform().GetRequest();
455 Integration::Bitmap* bitmap2 = Integration::Bitmap::New( Integration::Bitmap::BITMAP_2D_PACKED_PIXELS, ResourcePolicy::RETAIN );
456 bitmap2->GetPackedPixelsProfile()->ReserveBuffer( Pixel::RGBA8888, image2ClosestSize.width, image2ClosestSize.height, image2ClosestSize.width, image2ClosestSize.height );
458 Integration::ResourcePointer resourcePtr2(bitmap2); // reference it
459 application.GetPlatform().SetResourceLoaded(req->GetId(), req->GetType()->id, resourcePtr2);
460 application.Render(); // Process LoadComplete
461 application.SendNotification(); // Process event messages
462 application.GetPlatform().DiscardRequest(); // Ensure load request is discarded
463 application.GetPlatform().ClearReadyResources(); //
465 application.SendNotification(); // Process event messages
466 application.Render(); // Process LoadComplete
468 // Ensure the actor size gets the new image's natural size
469 DALI_TEST_EQUALS( Vector2(actor.GetCurrentSize()), requestedSize2, TEST_LOCATION );
473 int UtcDaliImageActorNaturalPixelAreaSize01(void)
475 TestApplication application;
476 tet_infoline("Positive test for Dali::ImageActor::GetCurrentSize - check a new image doens't change actor size until load complete");
478 //If an image is loaded without setting size, then the actor gets the natural size of the image
479 //Setting the pixel area will change the actor size to match the pixel area
480 //Setting the actor size will not change pixel area, and will cause the partial image to stretch
482 //Clearing the pixel area will not change actor size, and the actor will show the whole image.
485 Vector2 closestImageSize( 80, 45);
486 application.GetPlatform().SetClosestImageSize(closestImageSize);
488 Vector2 requestedSize( 40, 30 );
489 Image image = ResourceImage::New("image.jpg", ImageDimensions( requestedSize.x, requestedSize.y ), FittingMode::DEFAULT, SamplingMode::DEFAULT );
490 ImageActor actor = ImageActor::New( image );
491 Stage::GetCurrent().Add(actor);
493 application.SendNotification(); // Flush update messages
494 application.Render(); // Process resource request
496 DALI_TEST_EQUALS( Vector2(actor.GetCurrentSize()), requestedSize, TEST_LOCATION );
498 // Now complete the image load
499 Integration::ResourceRequest* req = application.GetPlatform().GetRequest();
500 Integration::Bitmap* bitmap = Integration::Bitmap::New( Integration::Bitmap::BITMAP_2D_PACKED_PIXELS, ResourcePolicy::RETAIN );
501 bitmap->GetPackedPixelsProfile()->ReserveBuffer( Pixel::RGBA8888, closestImageSize.width, closestImageSize.height, closestImageSize.width, closestImageSize.height );
503 Integration::ResourcePointer resourcePtr(bitmap); // reference it
504 application.GetPlatform().SetResourceLoaded(req->GetId(), req->GetType()->id, resourcePtr);
505 application.Render(); // Process LoadComplete
506 application.SendNotification(); // Process event messages
507 application.GetPlatform().DiscardRequest(); // Ensure load request is discarded
508 application.GetPlatform().ClearReadyResources(); //
510 DALI_TEST_EQUALS( Vector2(actor.GetCurrentSize()), requestedSize, TEST_LOCATION );
512 // Set a pixel area on a naturally sized actor - expect the actor to take the
513 // pixel area as size
514 actor.SetPixelArea(ImageActor::PixelArea(0, 0, 30, 30));
515 application.SendNotification(); // Process event messages
516 application.Render(); // Process LoadComplete
517 DALI_TEST_EQUALS( Vector2(actor.GetCurrentSize()), Vector2(30, 30), TEST_LOCATION );
519 // Set a size. Expect the partial image to stretch to fill the new size
520 actor.SetSize(100, 100);
521 application.SendNotification(); // Process event messages
522 application.Render(); // Process LoadComplete
523 application.Render(); // Process LoadComplete
524 DALI_TEST_EQUALS( 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( Vector2(actor.GetCurrentSize()), Vector2(100, 100), TEST_LOCATION );
534 int UtcDaliImageActorNaturalPixelAreaSize02(void)
536 TestApplication application;
537 tet_infoline("Positive test for Dali::ImageActor::GetCurrentSize - check a new image doens't change actor size until load complete");
539 //If an image is loaded without setting size, then the actor gets the natural size of the image
540 //Setting the pixel area will change the actor size to match the pixel area
541 //Setting the actor size will not change pixel area, and will cause the partial image to stretch
543 //Clearing the pixel area will not change actor size, and the actor will show the whole image.
546 Vector2 closestImageSize( 80, 45);
547 application.GetPlatform().SetClosestImageSize(closestImageSize);
549 Vector2 requestedSize( 40, 30 );
550 Image image = ResourceImage::New("image.jpg", ImageDimensions( requestedSize.x, requestedSize.y ), FittingMode::DEFAULT, SamplingMode::DEFAULT );
551 ImageActor actor = ImageActor::New( image );
552 Stage::GetCurrent().Add(actor);
554 application.SendNotification(); // Flush update messages
555 application.Render(); // Process resource request
557 DALI_TEST_EQUALS( Vector2(actor.GetCurrentSize()), requestedSize, TEST_LOCATION );
559 // Now complete the image load
560 Integration::ResourceRequest* req = application.GetPlatform().GetRequest();
561 Integration::Bitmap* bitmap = Integration::Bitmap::New( Integration::Bitmap::BITMAP_2D_PACKED_PIXELS, ResourcePolicy::RETAIN );
562 bitmap->GetPackedPixelsProfile()->ReserveBuffer( Pixel::RGBA8888, closestImageSize.width, closestImageSize.height, closestImageSize.width, closestImageSize.height );
564 Integration::ResourcePointer resourcePtr(bitmap); // reference it
565 application.GetPlatform().SetResourceLoaded(req->GetId(), req->GetType()->id, resourcePtr);
566 application.Render(); // Process LoadComplete
567 application.SendNotification(); // Process event messages
568 application.GetPlatform().DiscardRequest(); // Ensure load request is discarded
569 application.GetPlatform().ClearReadyResources(); //
571 DALI_TEST_EQUALS( Vector2(actor.GetCurrentSize()), requestedSize, TEST_LOCATION );
573 // Set a pixel area on a naturally sized actor - expect the actor to take the
574 // pixel area as size
575 actor.SetPixelArea(ImageActor::PixelArea(0, 0, 30, 30));
576 application.SendNotification(); // Process event messages
577 application.Render(); // Process LoadComplete
578 DALI_TEST_EQUALS( Vector2(actor.GetCurrentSize()), Vector2(30, 30), TEST_LOCATION );
580 // Clear the pixel area. Expect the whole image to be shown, changing actor size
581 actor.ClearPixelArea();
582 application.SendNotification(); // Process event messages
583 application.Render(); // Process LoadComplete
584 DALI_TEST_EQUALS( Vector2(actor.GetCurrentSize()), requestedSize, TEST_LOCATION );
586 // Set a size. Expect the partial image to stretch to fill the new size
587 actor.SetSize(100, 100);
588 application.SendNotification(); // Process event messages
589 application.Render(); // Process LoadComplete
590 DALI_TEST_EQUALS( Vector2(actor.GetCurrentSize()), Vector2(100, 100), TEST_LOCATION );
592 // Set a pixel area, don't expect size to change
593 actor.SetPixelArea(ImageActor::PixelArea(0, 0, 40, 40));
594 application.SendNotification(); // Process event messages
595 application.Render(); // Process LoadComplete
596 DALI_TEST_EQUALS( Vector2(actor.GetCurrentSize()), Vector2(100, 100), TEST_LOCATION );
598 // Clearing pixel area should change actor size to image size
599 actor.SetResizePolicy( ResizePolicy::USE_NATURAL_SIZE, Dimension::ALL_DIMENSIONS );
600 actor.ClearPixelArea();
601 application.SendNotification(); // Process event messages
602 application.Render(); // Process LoadComplete
603 DALI_TEST_EQUALS( Vector2(actor.GetCurrentSize()), requestedSize, TEST_LOCATION );
609 int UtcDaliImageActorDefaultProperties(void)
611 TestApplication application;
612 tet_infoline("Testing Dali::ImageActor DefaultProperties");
614 BufferImage img = BufferImage::New( 10, 10 );
615 ImageActor actor = ImageActor::New( img );
617 std::vector<Property::Index> indices;
618 indices.push_back(ImageActor::Property::PIXEL_AREA );
619 indices.push_back(ImageActor::Property::STYLE );
620 indices.push_back(ImageActor::Property::BORDER );
621 indices.push_back(ImageActor::Property::IMAGE );
623 DALI_TEST_CHECK(actor.GetPropertyCount() == ( Actor::New().GetPropertyCount() + indices.size() ) );
625 for(std::vector<Property::Index>::iterator iter = indices.begin(); iter != indices.end(); ++iter)
627 DALI_TEST_CHECK( *iter == actor.GetPropertyIndex(actor.GetPropertyName(*iter)) );
628 DALI_TEST_CHECK( actor.IsPropertyWritable(*iter) );
629 DALI_TEST_CHECK( !actor.IsPropertyAnimatable(*iter) );
630 DALI_TEST_CHECK( actor.GetPropertyType(*iter) == actor.GetPropertyType(*iter) ); // just checking call succeeds
633 // set/get one of them
634 actor.SetPixelArea(ImageActor::PixelArea( 0, 0, 0, 0 ));
636 ImageActor::PixelArea area( 1, 2, 3, 4 );
637 actor.SetProperty(ImageActor::Property::PIXEL_AREA, Property::Value(Rect<int>(area)));
639 DALI_TEST_CHECK(Property::RECTANGLE == actor.GetPropertyType(ImageActor::Property::PIXEL_AREA));
641 Property::Value v = actor.GetProperty(ImageActor::Property::PIXEL_AREA);
643 DALI_TEST_CHECK(v.Get<Rect<int> >() == area);
648 int UtcDaliImageActorUseImageAlpha01(void)
650 TestApplication application;
652 tet_infoline("Testing Dali::RenderableActor::SetUseImageAlpha()");
654 BufferImage image = BufferImage::New( 100, 50 );
655 ImageActor actor = ImageActor::New( image );
656 actor.SetBlendMode( BlendingMode::ON );
657 actor.SetSize(100, 50);
658 application.GetGlAbstraction().EnableCullFaceCallTrace(true); // For Enable(GL_BLEND)
659 Stage::GetCurrent().Add(actor);
661 application.SendNotification();
662 application.Render();
664 const TraceCallStack& callTrace = application.GetGlAbstraction().GetCullFaceTrace();
665 DALI_TEST_EQUALS( BlendEnabled( callTrace), true, TEST_LOCATION );
666 DALI_TEST_EQUALS( BlendDisabled( callTrace ), false, TEST_LOCATION );
670 int UtcDaliImageActorUseImageAlpha02(void)
672 TestApplication application;
674 tet_infoline("Testing Dali::RenderableActor::SetUseImageAlpha()");
676 BufferImage image = BufferImage::New( 100, 50 );
677 ImageActor actor = ImageActor::New( image );
678 actor.SetBlendMode( BlendingMode::OFF );
679 actor.SetSize(100, 50);
680 application.GetGlAbstraction().EnableCullFaceCallTrace(true); // For Enable(GL_BLEND)
681 Stage::GetCurrent().Add(actor);
683 application.SendNotification();
684 application.Render();
686 const TraceCallStack& callTrace = application.GetGlAbstraction().GetCullFaceTrace();
687 DALI_TEST_EQUALS( BlendDisabled( callTrace ), false, TEST_LOCATION );
688 DALI_TEST_EQUALS( BlendEnabled( callTrace), false, TEST_LOCATION );
692 int UtcDaliImageActorUseImageAlpha03(void)
694 TestApplication application;
696 tet_infoline("Testing Dali::RenderableActor::SetUseImageAlpha()");
698 BufferImage image = BufferImage::New( 100, 50 );
699 ImageActor actor = ImageActor::New( image );
700 actor.SetBlendMode( BlendingMode::AUTO );
701 actor.SetColor(Vector4(1.0, 1.0, 1.0, 0.5));
702 actor.SetSize(100, 50);
703 application.GetGlAbstraction().EnableCullFaceCallTrace(true); // For Enable(GL_BLEND)
704 Stage::GetCurrent().Add(actor);
706 application.SendNotification();
707 application.Render();
709 const TraceCallStack& callTrace = application.GetGlAbstraction().GetCullFaceTrace();
710 DALI_TEST_EQUALS( BlendDisabled( callTrace ), false, TEST_LOCATION );
711 DALI_TEST_EQUALS( BlendEnabled( callTrace), true, TEST_LOCATION );
715 int UtcDaliImageActorUseImageAlpha04(void)
717 TestApplication application;
719 tet_infoline("Testing Dali::RenderableActor::SetUseImageAlpha()");
721 FrameBufferImage image = FrameBufferImage::New( 100, 50, Pixel::RGBA8888 );
722 RenderTaskList taskList = Stage::GetCurrent().GetRenderTaskList();
723 RenderTask task = taskList.GetTask( 0u );
724 task.SetTargetFrameBuffer( image ); // To ensure frame buffer is connected
725 application.GetGlAbstraction().SetCheckFramebufferStatusResult( GL_FRAMEBUFFER_COMPLETE );
726 application.SendNotification();
727 application.Render(0);
729 ImageActor actor = ImageActor::New( image );
730 application.SendNotification();
731 application.Render(0);
733 actor.SetBlendMode( BlendingMode::ON );
734 actor.SetColor(Vector4(1.0, 1.0, 1.0, 1.0));
735 actor.SetSize(100, 50);
736 application.GetGlAbstraction().EnableCullFaceCallTrace(true); // For Enable(GL_BLEND)
737 Stage::GetCurrent().Add(actor);
739 application.SendNotification();
740 application.Render();
742 const TraceCallStack& callTrace = application.GetGlAbstraction().GetCullFaceTrace();
743 DALI_TEST_EQUALS( BlendDisabled( callTrace ), false, TEST_LOCATION );
744 DALI_TEST_EQUALS( BlendEnabled( callTrace), true, TEST_LOCATION );
748 int UtcDaliImageActorUseImageAlpha05(void)
750 TestApplication application;
752 tet_infoline("Testing Dali::RenderableActor::SetUseImageAlpha()");
754 BufferImage image = BufferImage::New( 100, 50, Pixel::RGB888 );
755 ImageActor actor = ImageActor::New( image );
756 actor.SetBlendMode( BlendingMode::AUTO );
757 actor.SetColor(Vector4(1.0, 1.0, 1.0, 1.0));
758 actor.SetSize(100, 50);
759 application.GetGlAbstraction().EnableCullFaceCallTrace(true); // For Enable(GL_BLEND)
760 Stage::GetCurrent().Add(actor);
762 application.SendNotification();
763 application.Render();
765 const TraceCallStack& callTrace = application.GetGlAbstraction().GetCullFaceTrace();
766 DALI_TEST_EQUALS( BlendDisabled( callTrace ), false, TEST_LOCATION );
767 DALI_TEST_EQUALS( BlendEnabled( callTrace), false, TEST_LOCATION );
771 int UtcDaliImageActorClearPixelArea(void)
773 TestApplication application;
775 BufferImage img = BufferImage::New( 10, 10 );
776 ImageActor actor = ImageActor::New( img );
778 DALI_TEST_CHECK( actor.IsPixelAreaSet() == false );
780 ImageActor::PixelArea area( 1, 2, 3, 4 );
781 actor.SetPixelArea( area );
783 DALI_TEST_CHECK( actor.IsPixelAreaSet() == true );
785 actor.ClearPixelArea();
787 DALI_TEST_CHECK( actor.IsPixelAreaSet() == false );
791 int UtcDaliImageGetStyle(void)
793 TestApplication application;
795 Image image = ResourceImage::New(TestImageFilename);
796 ImageActor actor = ImageActor::New(image);
798 actor.SetStyle(ImageActor::STYLE_NINE_PATCH);
800 // flush the queue and render once
801 application.SendNotification();
802 application.Render();
804 DALI_TEST_EQUALS( ImageActor::STYLE_NINE_PATCH, actor.GetStyle(), TEST_LOCATION );
808 int UtcDaliImageSetNinePatchBorder(void)
810 TestApplication application;
812 Image image = ResourceImage::New(TestImageFilename);
813 ImageActor actor = ImageActor::New(image);
815 actor.SetStyle(ImageActor::STYLE_NINE_PATCH);
816 actor.SetNinePatchBorder(Vector4( 1.0f, 2.0f, 3.0f, 4.0f));
818 DALI_TEST_EQUALS( 1.0f, actor.GetNinePatchBorder().x, TEST_LOCATION );
819 DALI_TEST_EQUALS( 2.0f, actor.GetNinePatchBorder().y, TEST_LOCATION );
820 DALI_TEST_EQUALS( 3.0f, actor.GetNinePatchBorder().z, TEST_LOCATION );
821 DALI_TEST_EQUALS( 4.0f, actor.GetNinePatchBorder().w, TEST_LOCATION );
825 int UtcDaliImageActorNewNull(void)
827 TestApplication application;
829 ImageActor actor = ImageActor::New(Image());
831 DALI_TEST_CHECK(actor);
835 int UtcDaliImageActorNewNullWithArea(void)
837 TestApplication application;
839 ImageActor::PixelArea area( 1, 2, 3, 4 );
841 ImageActor actor = ImageActor::New(Image(), area);
843 DALI_TEST_CHECK(actor);
847 int UtcDaliImageActorSetImage(void)
849 TestApplication application;
851 ImageActor actor = ImageActor::New(Image());
853 DALI_TEST_CHECK(actor);
855 actor.SetImage( Image() );
857 DALI_TEST_CHECK(!actor.GetImage());
861 int UtcDaliImageActorPropertyIndices(void)
863 TestApplication application;
864 Actor basicActor = Actor::New();
865 ImageActor imageActor = ImageActor::New();
867 Property::IndexContainer indices;
868 imageActor.GetPropertyIndices( indices );
869 DALI_TEST_CHECK( indices.size() > basicActor.GetPropertyCount() );
870 DALI_TEST_EQUALS( indices.size(), imageActor.GetPropertyCount(), TEST_LOCATION );
874 int UtcDaliImageActorImageProperty(void)
876 TestApplication application;
877 Image image = ResourceImage::New( "MY_PATH" );
878 ImageActor imageActor = ImageActor::New( image );
880 Stage::GetCurrent().Add( imageActor );
881 application.SendNotification();
882 application.Render();
884 Property::Value imageMap = imageActor.GetProperty( ImageActor::Property::IMAGE );
885 DALI_TEST_CHECK( imageMap.HasKey( "filename" ) );
886 DALI_TEST_EQUALS( imageMap.GetValue( "filename" ).Get< std::string >(), "MY_PATH", TEST_LOCATION );
890 int UtcDaliImageActorNinePatch01(void)
892 TestApplication application;
893 TestPlatformAbstraction& platform = application.GetPlatform();
894 TestGlAbstraction& glAbstraction = application.GetGlAbstraction();
895 TraceCallStack& textureTrace = glAbstraction.GetTextureTrace();
896 TraceCallStack& drawTrace = glAbstraction.GetDrawTrace();
898 tet_infoline("Test the successful loading of a nine-patch image\n");
900 platform.SetClosestImageSize(Vector2(4, 4));
901 Integration::Bitmap* bitmap = Integration::Bitmap::New( Integration::Bitmap::BITMAP_2D_PACKED_PIXELS, ResourcePolicy::RETAIN );
902 Integration::PixelBuffer* pixels = bitmap->GetPackedPixelsProfile()->ReserveBuffer( Pixel::RGBA8888, 4,4,4,4 );
903 memset( pixels, 0, 64 );
905 Integration::ResourcePointer resourcePtr(bitmap); // reference it
906 platform.SetResourceLoaded( 0, Dali::Integration::ResourceBitmap, resourcePtr );
908 Image ninePatchImage = ResourceImage::New( "blah.#.png" );
909 DALI_TEST_CHECK( ninePatchImage );
911 ImageActor imageActor = ImageActor::New( ninePatchImage );
912 DALI_TEST_CHECK( imageActor );
913 Stage::GetCurrent().Add( imageActor );
916 textureTrace.Reset();
917 drawTrace.Enable(true);
918 textureTrace.Enable(true);
919 glAbstraction.ClearBoundTextures();
920 std::vector<GLuint> ids;
922 glAbstraction.SetNextTextureIds( ids );
924 application.SendNotification();
925 application.Render();
927 DALI_TEST_CHECK( drawTrace.FindMethod( "DrawArrays" ) );
928 typedef std::vector<GLuint> TexVec;
929 const TexVec& textures = glAbstraction.GetBoundTextures(GL_TEXTURE0);
930 DALI_TEST_CHECK( textures.size() > 0 );
931 if( textures.size() > 0 )
933 DALI_TEST_EQUALS( textures[0], 23u, TEST_LOCATION );
940 int UtcDaliImageActorNinePatch02(void)
942 TestApplication application;
943 TestPlatformAbstraction& platform = application.GetPlatform();
944 TestGlAbstraction& glAbstraction = application.GetGlAbstraction();
945 TraceCallStack& textureTrace = glAbstraction.GetTextureTrace();
946 TraceCallStack& drawTrace = glAbstraction.GetDrawTrace();
948 tet_infoline("Test the failed loading of a nine-patch image\n");
950 platform.SetClosestImageSize(Vector2(0, 0));
951 Integration::ResourcePointer resourcePtr;
952 platform.SetResourceLoaded( 0, Dali::Integration::ResourceBitmap, resourcePtr );
954 Image ninePatchImage = ResourceImage::New( "blah.#.png" );
955 DALI_TEST_CHECK( ninePatchImage );
957 ImageActor imageActor = ImageActor::New( ninePatchImage );
958 DALI_TEST_CHECK( imageActor );
959 Stage::GetCurrent().Add( imageActor );
962 textureTrace.Reset();
963 drawTrace.Enable(true);
964 textureTrace.Enable(true);
965 glAbstraction.ClearBoundTextures();
966 std::vector<GLuint> ids;
968 glAbstraction.SetNextTextureIds( ids );
970 application.SendNotification();
971 application.Render();
973 // Check that nothing was drawn.
974 DALI_TEST_CHECK( ! drawTrace.FindMethod( "DrawArrays" ) );
975 typedef std::vector<GLuint> TexVec;
976 const TexVec& textures = glAbstraction.GetBoundTextures(GL_TEXTURE0);
977 DALI_TEST_CHECK( textures.size() == 0u );
983 int UtcDaliImageActorNinePatch03(void)
985 TestApplication application;
986 TestPlatformAbstraction& platform = application.GetPlatform();
987 TestGlAbstraction& glAbstraction = application.GetGlAbstraction();
988 TraceCallStack& textureTrace = glAbstraction.GetTextureTrace();
989 TraceCallStack& drawTrace = glAbstraction.GetDrawTrace();
991 tet_infoline("Test the successful loading of a nine-patch image added using ImageActor::SetImage()\n");
993 platform.SetClosestImageSize(Vector2(4, 4));
994 Integration::Bitmap* bitmap = Integration::Bitmap::New( Integration::Bitmap::BITMAP_2D_PACKED_PIXELS, ResourcePolicy::RETAIN );
995 Integration::PixelBuffer* pixels = bitmap->GetPackedPixelsProfile()->ReserveBuffer( Pixel::RGBA8888, 4,4,4,4 );
996 memset( pixels, 0, 64 );
998 Integration::ResourcePointer resourcePtr(bitmap); // reference it
999 platform.SetResourceLoaded( 0, Dali::Integration::ResourceBitmap, resourcePtr );
1001 Image ninePatchImage = ResourceImage::New( "blah.#.png" );
1002 DALI_TEST_CHECK( ninePatchImage );
1004 ImageActor imageActor = ImageActor::New();
1005 DALI_TEST_CHECK( imageActor );
1006 Stage::GetCurrent().Add( imageActor );
1008 imageActor.SetImage( ninePatchImage );
1011 textureTrace.Reset();
1012 drawTrace.Enable(true);
1013 textureTrace.Enable(true);
1014 glAbstraction.ClearBoundTextures();
1015 std::vector<GLuint> ids;
1016 ids.push_back( 23 );
1017 glAbstraction.SetNextTextureIds( ids );
1019 application.SendNotification();
1020 application.Render();
1022 DALI_TEST_CHECK( drawTrace.FindMethod( "DrawArrays" ) );
1023 typedef std::vector<GLuint> TexVec;
1024 const TexVec& textures = glAbstraction.GetBoundTextures(GL_TEXTURE0);
1025 DALI_TEST_CHECK( textures.size() > 0 );
1026 if( textures.size() > 0 )
1028 DALI_TEST_EQUALS( textures[0], 23u, TEST_LOCATION );
1035 int UtcDaliImageActorNinePatch04(void)
1037 TestApplication application;
1038 TestPlatformAbstraction& platform = application.GetPlatform();
1039 TestGlAbstraction& glAbstraction = application.GetGlAbstraction();
1040 TraceCallStack& textureTrace = glAbstraction.GetTextureTrace();
1041 TraceCallStack& drawTrace = glAbstraction.GetDrawTrace();
1043 tet_infoline("Test the failed loading of a nine-patch image using ImageActor::SetImage()\n");
1045 platform.SetClosestImageSize(Vector2(0, 0));
1046 Integration::ResourcePointer resourcePtr;
1047 platform.SetResourceLoaded( 0, Dali::Integration::ResourceBitmap, resourcePtr );
1049 Image ninePatchImage = ResourceImage::New( "blah.#.png" );
1050 DALI_TEST_CHECK( ninePatchImage );
1052 ImageActor imageActor = ImageActor::New();
1053 DALI_TEST_CHECK( imageActor );
1054 Stage::GetCurrent().Add( imageActor );
1056 imageActor.SetImage( ninePatchImage );
1059 textureTrace.Reset();
1060 drawTrace.Enable(true);
1061 textureTrace.Enable(true);
1062 glAbstraction.ClearBoundTextures();
1063 std::vector<GLuint> ids;
1064 ids.push_back( 23 );
1065 glAbstraction.SetNextTextureIds( ids );
1067 application.SendNotification();
1068 application.Render();
1070 // Check that nothing was drawn.
1071 DALI_TEST_CHECK( ! drawTrace.FindMethod( "DrawArrays" ) );
1072 typedef std::vector<GLuint> TexVec;
1073 const TexVec& textures = glAbstraction.GetBoundTextures(GL_TEXTURE0);
1074 DALI_TEST_CHECK( textures.size() == 0u );
1079 int UtcDaliImageActorGetNaturalSize(void)
1081 TestApplication application;
1084 BufferImage img = BufferImage::New( 10, 10 );
1085 ImageActor actor = ImageActor::New( img );
1087 DALI_TEST_CHECK( actor.GetNaturalSize().GetVectorXY() == Vector2( 10, 10 ) );
1090 ImageActor::PixelArea area( 1, 2, 3, 4 );
1091 actor.SetPixelArea( area );
1093 DALI_TEST_CHECK( actor.GetNaturalSize().GetVectorXY() == Vector2( 3, 4 ) );