2 * Copyright (c) 2017 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.
18 // Need to override adaptor classes for toolkit test harness, so include
19 // test harness headers before dali headers.
20 #include <dali-toolkit-test-suite-utils.h>
21 #include <toolkit-event-thread-callback.h>
23 #include <dali-toolkit/dali-toolkit.h>
24 #include <dali/devel-api/scripting/scripting.h>
25 #include <dali-toolkit/devel-api/controls/control-devel.h>
26 #include <dali-toolkit/devel-api/image-loader/texture-manager.h>
27 #include <dali-toolkit/devel-api/visual-factory/visual-base.h>
29 #include <test-native-image.h>
34 #include "dummy-control.h"
37 using namespace Toolkit;
39 void utc_dali_toolkit_image_view_startup(void)
41 test_return_value = TET_UNDEF;
44 void utc_dali_toolkit_image_view_cleanup(void)
46 test_return_value = TET_PASS;
52 const char* VERTEX_SHADER = DALI_COMPOSE_SHADER(
53 attribute mediump vec2 aPosition;\n
54 varying mediump vec2 vTexCoord;\n
55 uniform mediump mat4 uMvpMatrix;\n
56 uniform mediump vec3 uSize;\n
60 mediump vec4 vertexPosition = vec4(aPosition, 0.0, 1.0);\n
61 vertexPosition.xyz *= uSize;\n
62 vertexPosition = uMvpMatrix * vertexPosition;\n
64 vTexCoord = aPosition + vec2(0.5);\n
65 gl_Position = vertexPosition;\n
69 const char* FRAGMENT_SHADER = DALI_COMPOSE_SHADER(
70 varying mediump vec2 vTexCoord;\n
71 uniform sampler2D sTexture;\n
72 uniform lowp vec4 uColor;\n
76 gl_FragColor = texture2D( sTexture, vTexCoord ) * uColor;\n
80 const char* TEST_IMAGE_FILE_NAME = "gallery_image_01.jpg";
81 const char* TEST_IMAGE_FILE_NAME2 = "gallery_image_02.jpg";
83 const char* TEST_IMAGE_1 = TEST_RESOURCE_DIR "/TB-gloss.png";
84 const char* TEST_IMAGE_2 = TEST_RESOURCE_DIR "/tb-norm.png";
86 // resolution: 34*34, pixel format: RGBA8888
87 static const char* gImage_34_RGBA = TEST_RESOURCE_DIR "/icon-edit.png";
88 // resolution: 600*600, pixel format: RGB888
89 static const char* gImage_600_RGB = TEST_RESOURCE_DIR "/test-image-600.jpg";
91 // resolution: 50*50, frame count: 4, frame delay: 0.2 second for each frame
92 const char* TEST_GIF_FILE_NAME = TEST_RESOURCE_DIR "/anim.gif";
94 void TestImage( ImageView imageView, BufferImage image )
96 Property::Value value = imageView.GetProperty( imageView.GetPropertyIndex( "image" ) );
99 DALI_TEST_CHECK( value.Get( map ) );
101 DALI_TEST_CHECK( map.Find( "width" ) );
102 DALI_TEST_CHECK( map.Find( "height" ) );
103 DALI_TEST_CHECK( map.Find( "type" ) );
106 DALI_TEST_CHECK( map[ "width" ].Get( width ) );
107 DALI_TEST_EQUALS( (unsigned int)width, image.GetWidth(), TEST_LOCATION );
110 DALI_TEST_CHECK( map[ "height" ].Get( height ) );
111 DALI_TEST_EQUALS( (unsigned int)height, image.GetHeight(), TEST_LOCATION );
114 DALI_TEST_CHECK( map[ "type" ].Get( type ) );
115 DALI_TEST_EQUALS( type, "BufferImage", TEST_LOCATION );
118 void TestImage( ImageView imageView, ResourceImage image )
120 Property::Value value = imageView.GetProperty( imageView.GetPropertyIndex( "image" ) );
123 DALI_TEST_CHECK( value.Get( map ) );
125 if( map.Find( "width" ) )
128 DALI_TEST_CHECK( map[ "width" ].Get( width ) );
129 DALI_TEST_EQUALS( (unsigned int)width, image.GetWidth(), TEST_LOCATION );
132 if( map.Find( "height" ) )
135 DALI_TEST_CHECK( map[ "height" ].Get( height ) );
136 DALI_TEST_EQUALS( (unsigned int)height, image.GetHeight(), TEST_LOCATION );
139 DALI_TEST_CHECK( map.Find( "type" ) );
142 DALI_TEST_CHECK( map[ "type" ].Get( type ) );
143 DALI_TEST_EQUALS( type, "ResourceImage", TEST_LOCATION );
145 std::string filename;
146 DALI_TEST_CHECK( map[ "filename" ].Get( filename ) );
147 DALI_TEST_EQUALS( filename, image.GetUrl(), TEST_LOCATION );
150 void TestUrl( ImageView imageView, const std::string url )
152 Property::Value value = imageView.GetProperty( imageView.GetPropertyIndex( "image" ) );
154 std::string urlActual;
155 DALI_TEST_CHECK( value.Get( urlActual ) );
156 DALI_TEST_EQUALS( urlActual, url, TEST_LOCATION );
161 int UtcDaliImageViewNewP(void)
163 TestApplication application;
165 ImageView imageView = ImageView::New();
167 DALI_TEST_CHECK( imageView );
172 int UtcDaliImageViewNewImageP(void)
174 TestApplication application;
176 BufferImage image = CreateBufferImage( 100, 200, Vector4( 1.f, 1.f, 1.f, 1.f ) );
177 ImageView imageView = ImageView::New( image );
179 DALI_TEST_CHECK( imageView );
180 TestImage( imageView, image );
185 int UtcDaliImageViewNewUrlP(void)
187 TestApplication application;
189 ImageView imageView = ImageView::New( TEST_IMAGE_FILE_NAME );
190 DALI_TEST_CHECK( imageView );
192 TestUrl( imageView, TEST_IMAGE_FILE_NAME );
197 int UtcDaliImageViewConstructorP(void)
199 TestApplication application;
203 DALI_TEST_CHECK( !imageView );
208 int UtcDaliImageViewCopyConstructorP(void)
210 TestApplication application;
212 // Initialize an object, ref count == 1
213 ImageView imageView = ImageView::New();
215 ImageView copy( imageView );
216 DALI_TEST_CHECK( copy );
221 int UtcDaliImageViewAssignmentOperatorP(void)
223 TestApplication application;
225 ImageView imageView = ImageView::New();
227 ImageView copy( imageView );
228 DALI_TEST_CHECK( copy );
229 DALI_TEST_EQUALS( imageView, copy, TEST_LOCATION );
234 int UtcDaliImageViewDownCastP(void)
236 TestApplication application;
238 ImageView imageView = ImageView::New();
240 BaseHandle object(imageView);
242 ImageView imageView2 = ImageView::DownCast( object );
243 DALI_TEST_CHECK(imageView2);
245 ImageView imageView3 = DownCast< ImageView >( object );
246 DALI_TEST_CHECK(imageView3);
251 int UtcDaliImageViewDownCastN(void)
253 TestApplication application;
255 BaseHandle unInitializedObject;
257 ImageView imageView1 = ImageView::DownCast( unInitializedObject );
258 DALI_TEST_CHECK( !imageView1 );
260 ImageView imageView2 = DownCast< ImageView >( unInitializedObject );
261 DALI_TEST_CHECK( !imageView2 );
266 int UtcDaliImageViewTypeRegistry(void)
268 ToolkitTestApplication application;
270 TypeRegistry typeRegistry = TypeRegistry::Get();
271 DALI_TEST_CHECK( typeRegistry );
273 TypeInfo typeInfo = typeRegistry.GetTypeInfo( "ImageView" );
274 DALI_TEST_CHECK( typeInfo );
276 BaseHandle handle = typeInfo.CreateInstance();
277 DALI_TEST_CHECK( handle );
279 ImageView imageView = ImageView::DownCast( handle );
280 DALI_TEST_CHECK( imageView );
285 int UtcDaliImageViewSetGetProperty01(void)
287 ToolkitTestApplication application;
289 ImageView imageView = ImageView::New();
291 Property::Index idx = imageView.GetPropertyIndex( "image" );
292 DALI_TEST_EQUALS( idx, (Property::Index)ImageView::Property::IMAGE, TEST_LOCATION );
294 imageView.SetProperty( idx, TEST_IMAGE_FILE_NAME );
295 TestUrl( imageView, TEST_IMAGE_FILE_NAME );
300 int UtcDaliImageViewSetGetProperty02(void)
302 ToolkitTestApplication application;
304 Image image = CreateBufferImage( 10, 10, Color::WHITE );
305 ImageView imageView = ImageView::New(image);
306 Vector4 fullImageRect( 0.f, 0.f, 1.f, 1.f );
308 Stage::GetCurrent().Add( imageView );
310 application.SendNotification();
311 application.Render();
312 TestGlAbstraction& gl = application.GetGlAbstraction();
314 Vector4 pixelAreaUniform;
315 DALI_TEST_CHECK( gl.GetUniformValue<Vector4>( "pixelArea", pixelAreaUniform ) );
316 DALI_TEST_EQUALS( pixelAreaUniform, fullImageRect, TEST_LOCATION );
318 Property::Value value = imageView.GetProperty( ImageView::Property::PIXEL_AREA );
319 Vector4 pixelAreaValue;
320 DALI_TEST_CHECK( value.Get(pixelAreaValue) );
321 DALI_TEST_EQUALS( pixelAreaValue, fullImageRect, TEST_LOCATION );
323 Vector4 pixelAreaSet( 0.2f, 0.2f, 0.3f, 0.3f );
324 imageView.SetProperty( ImageView::Property::PIXEL_AREA, pixelAreaSet);
326 application.SendNotification();
327 application.Render();
329 value = imageView.GetProperty( ImageView::Property::PIXEL_AREA );
330 value.Get(pixelAreaValue);
331 DALI_TEST_EQUALS( pixelAreaValue, pixelAreaSet, TEST_LOCATION );
333 DALI_TEST_CHECK( gl.GetUniformValue<Vector4>( "pixelArea", pixelAreaUniform ) );
334 DALI_TEST_EQUALS( pixelAreaUniform, pixelAreaSet, TEST_LOCATION );
339 int UtcDaliImageViewSetGetProperty03(void)
341 ToolkitTestApplication application;
343 Image image = CreateBufferImage( 10, 10, Color::WHITE );
344 ImageView imageView = ImageView::New(image);
345 Stage::GetCurrent().Add( imageView );
346 application.SendNotification();
347 application.Render();
349 // conventional alpha blending
350 Renderer renderer = imageView.GetRendererAt( 0 );
351 Property::Value value = renderer.GetProperty( Renderer::Property::BLEND_PRE_MULTIPLIED_ALPHA );
353 DALI_TEST_CHECK( value.Get( enable ) );
354 DALI_TEST_CHECK( !enable );
356 // pre-multiplied alpha blending
357 imageView.SetProperty( Toolkit::ImageView::Property::PRE_MULTIPLIED_ALPHA, true );
358 application.SendNotification();
359 application.Render();
361 int srcFactorRgb = renderer.GetProperty<int>( Renderer::Property::BLEND_FACTOR_SRC_RGB );
362 int destFactorRgb = renderer.GetProperty<int>( Renderer::Property::BLEND_FACTOR_DEST_RGB );
363 int srcFactorAlpha = renderer.GetProperty<int>( Renderer::Property::BLEND_FACTOR_SRC_ALPHA );
364 int destFactorAlpha = renderer.GetProperty<int>( Renderer::Property::BLEND_FACTOR_DEST_ALPHA );
365 DALI_TEST_CHECK( srcFactorRgb == BlendFactor::ONE );
366 DALI_TEST_CHECK( destFactorRgb == BlendFactor::ONE_MINUS_SRC_ALPHA );
367 DALI_TEST_CHECK( srcFactorAlpha == BlendFactor::ONE );
368 DALI_TEST_CHECK( destFactorAlpha == BlendFactor::ONE );
370 value = renderer.GetProperty( Renderer::Property::BLEND_PRE_MULTIPLIED_ALPHA );
371 DALI_TEST_CHECK( value.Get( enable ) );
372 DALI_TEST_CHECK( enable );
377 int UtcDaliImageViewPixelArea(void)
379 // Test pixel area property
380 ToolkitTestApplication application;
382 // Gif image, use AnimatedImageVisual internally
383 // Atlasing is applied to pack multiple frames, use custom wrap mode
384 ImageView gifView = ImageView::New();
385 const Vector4 pixelAreaVisual( 0.f, 0.f, 2.f, 2.f );
386 gifView.SetProperty( ImageView::Property::IMAGE,
387 Property::Map().Add( ImageVisual::Property::URL, TEST_GIF_FILE_NAME )
388 .Add( ImageVisual::Property::PIXEL_AREA, pixelAreaVisual ) );
391 Stage stage = Stage::GetCurrent();
392 stage.Add( gifView );
395 application.SendNotification();
396 application.Render(16);
397 DALI_TEST_CHECK( gifView.GetRendererCount() == 1u );
399 const Vector4 fullTextureRect( 0.f, 0.f, 1.f, 1.f );
400 // test that the pixel area value defined in the visual property map is registered on renderer
401 Renderer renderer = gifView.GetRendererAt(0);
402 Property::Value pixelAreaValue = renderer.GetProperty( renderer.GetPropertyIndex( "pixelArea" ) );
403 DALI_TEST_EQUALS( pixelAreaValue.Get<Vector4>(), pixelAreaVisual, TEST_LOCATION );
405 // test that the shader has the default pixel area value registered.
406 Shader shader = renderer.GetShader();
407 pixelAreaValue = shader.GetProperty( shader.GetPropertyIndex( "pixelArea" ) );
408 DALI_TEST_EQUALS( pixelAreaValue.Get<Vector4>(), fullTextureRect, TEST_LOCATION );
410 // test that the uniform uses the pixelArea property on the renderer.
411 TestGlAbstraction& gl = application.GetGlAbstraction();
412 Vector4 pixelAreaUniform;
413 DALI_TEST_CHECK( gl.GetUniformValue<Vector4>( "pixelArea", pixelAreaUniform ) );
414 DALI_TEST_EQUALS( pixelAreaVisual, pixelAreaUniform, Math::MACHINE_EPSILON_100, TEST_LOCATION );
416 // set the pixelArea property on the control
417 const Vector4 pixelAreaControl( -1.f, -1.f, 3.f, 3.f );
418 gifView.SetProperty( ImageView::Property::PIXEL_AREA, pixelAreaControl );
419 application.SendNotification();
420 application.Render(16);
422 // check the pixelArea property on the control
423 pixelAreaValue = gifView.GetProperty( gifView.GetPropertyIndex( "pixelArea" ) );
424 DALI_TEST_EQUALS( pixelAreaValue.Get<Vector4>(), pixelAreaControl, TEST_LOCATION );
425 // test that the uniform uses the pixelArea property on the control.
426 DALI_TEST_CHECK( gl.GetUniformValue<Vector4>( "pixelArea", pixelAreaUniform ) );
427 DALI_TEST_EQUALS( pixelAreaControl, pixelAreaUniform, Math::MACHINE_EPSILON_100, TEST_LOCATION );
433 int UtcDaliImageViewAsyncLoadingWithoutAltasing(void)
435 ToolkitTestApplication application;
436 TestGlAbstraction& gl = application.GetGlAbstraction();
437 const std::vector<GLuint>& textures = gl.GetBoundTextures();
438 size_t numTextures = textures.size();
440 // Async loading, no atlasing for big size image
441 ImageView imageView = ImageView::New( gImage_600_RGB );
443 // By default, Aysnc loading is used
444 Stage::GetCurrent().Add( imageView );
445 imageView.SetSize(100, 100);
446 imageView.SetParentOrigin( ParentOrigin::CENTER );
448 DALI_TEST_EQUALS( Test::WaitForEventThreadTrigger( 1 ), true, TEST_LOCATION );
450 application.SendNotification();
451 application.Render(16);
452 application.SendNotification();
454 const std::vector<GLuint>& textures2 = gl.GetBoundTextures();
455 DALI_TEST_GREATER( textures2.size(), numTextures, TEST_LOCATION );
462 int UtcDaliImageViewAsyncLoadingWithAtlasing(void)
464 ToolkitTestApplication application;
466 //Async loading, automatic atlasing for small size image
467 TraceCallStack& callStack = application.GetGlAbstraction().GetTextureTrace();
469 callStack.Enable(true);
471 Property::Map imageMap;
473 imageMap[ ImageVisual::Property::URL ] = gImage_34_RGBA;
474 imageMap[ ImageVisual::Property::DESIRED_HEIGHT ] = 34;
475 imageMap[ ImageVisual::Property::DESIRED_WIDTH ] = 34;
476 imageMap[ ImageVisual::Property::ATLASING] = true;
478 ImageView imageView = ImageView::New();
479 imageView.SetProperty( ImageView::Property::IMAGE, imageMap );
480 imageView.SetProperty( Toolkit::Control::Property::PADDING, Extents( 10u, 10u, 10u, 10u ) );
482 // By default, Aysnc loading is used
483 // loading is not started if the actor is offStage
485 Stage::GetCurrent().Add( imageView );
486 application.SendNotification();
487 application.Render(16);
488 application.Render(16);
489 application.SendNotification();
491 // loading started, this waits for the loader thread for max 30 seconds
492 DALI_TEST_EQUALS( Test::WaitForEventThreadTrigger( 1 ), true, TEST_LOCATION );
494 application.SendNotification();
495 application.Render(16);
497 callStack.Enable(false);
499 TraceCallStack::NamedParams params;
500 params["width"] = ToString(34);
501 params["height"] = ToString(34);
502 DALI_TEST_EQUALS( callStack.FindMethodAndParams( "TexSubImage2D", params ), true, TEST_LOCATION );
507 int UtcDaliImageViewAsyncLoadingWithAtlasing02(void)
509 ToolkitTestApplication application;
511 //Async loading, automatic atlasing for small size image
512 TraceCallStack& callStack = application.GetGlAbstraction().GetTextureTrace();
514 callStack.Enable(true);
516 Property::Map asyncLoadingMap;
517 asyncLoadingMap[ "url" ] = gImage_34_RGBA;
518 asyncLoadingMap[ "desiredHeight" ] = 34;
519 asyncLoadingMap[ "desiredWidth" ] = 34;
520 asyncLoadingMap[ "synchronousLoading" ] = false;
521 asyncLoadingMap[ "atlasing" ] = true;
523 ImageView imageView = ImageView::New();
524 imageView.SetProperty( ImageView::Property::IMAGE, asyncLoadingMap );
526 Stage::GetCurrent().Add( imageView );
527 application.SendNotification();
528 application.Render(16);
529 application.Render(16);
530 application.SendNotification();
532 // loading started, this waits for the loader thread for max 30 seconds
533 DALI_TEST_EQUALS( Test::WaitForEventThreadTrigger( 1 ), true, TEST_LOCATION );
535 application.SendNotification();
536 application.Render(16);
538 callStack.Enable(false);
540 TraceCallStack::NamedParams params;
541 params["width"] = ToString(34);
542 params["height"] = ToString(34);
543 DALI_TEST_EQUALS( callStack.FindMethodAndParams( "TexSubImage2D", params ), true, TEST_LOCATION );
548 int UtcDaliImageViewSyncLoading(void)
550 ToolkitTestApplication application;
552 tet_infoline("ImageView Testing sync loading and size using index key property map");
554 Property::Map syncLoadingMap;
555 syncLoadingMap[ ImageVisual::Property::SYNCHRONOUS_LOADING ] = true;
556 syncLoadingMap[ ImageVisual::Property::ATLASING ] = true;
558 // Sync loading, no atlasing for big size image
560 ImageView imageView = ImageView::New();
562 // Sync loading is used
563 syncLoadingMap[ ImageVisual::Property::URL ] = gImage_600_RGB;
564 imageView.SetProperty( ImageView::Property::IMAGE, syncLoadingMap );
567 // Sync loading, automatic atlasing for small size image
569 TraceCallStack& callStack = application.GetGlAbstraction().GetTextureTrace();
571 callStack.Enable(true);
573 ImageView imageView = ImageView::New( );
575 // Sync loading is used
576 syncLoadingMap[ ImageVisual::Property::URL ] = gImage_34_RGBA;
577 syncLoadingMap[ ImageVisual::Property::DESIRED_HEIGHT ] = 34;
578 syncLoadingMap[ ImageVisual::Property::DESIRED_WIDTH ] = 34;
579 imageView.SetProperty( ImageView::Property::IMAGE, syncLoadingMap );
581 Stage::GetCurrent().Add( imageView );
582 application.SendNotification();
583 application.Render(16);
585 TraceCallStack::NamedParams params;
586 params["width"] = ToString(34);
587 params["height"] = ToString(34);
588 DALI_TEST_EQUALS( callStack.FindMethodAndParams( "TexSubImage2D", params ),
589 true, TEST_LOCATION );
594 int UtcDaliImageViewSyncLoading02(void)
596 ToolkitTestApplication application;
598 tet_infoline("ImageView Testing sync loading and size using string key property map");
600 // Sync loading, automatic atlasing for small size image
602 TraceCallStack& callStack = application.GetGlAbstraction().GetTextureTrace();
604 callStack.Enable(true);
606 ImageView imageView = ImageView::New( );
608 // Sync loading is used
609 Property::Map syncLoadingMap;
610 syncLoadingMap[ "url" ] = gImage_34_RGBA;
611 syncLoadingMap[ "desiredHeight" ] = 34;
612 syncLoadingMap[ "desiredWidth" ] = 34;
613 syncLoadingMap[ "synchronousLoading" ] = true;
614 syncLoadingMap[ "atlasing" ] = true;
615 imageView.SetProperty( ImageView::Property::IMAGE, syncLoadingMap );
617 Stage::GetCurrent().Add( imageView );
618 application.SendNotification();
619 application.Render(16);
621 TraceCallStack::NamedParams params;
622 params["width"] = ToString(34);
623 params["height"] = ToString(34);
624 DALI_TEST_EQUALS( callStack.FindMethodAndParams( "TexSubImage2D", params ),
625 true, TEST_LOCATION );
630 int UtcDaliImageViewAddedTexture(void)
632 ToolkitTestApplication application;
634 tet_infoline("ImageView Testing image view with texture provided manager url");
636 ImageView imageView = ImageView::New();
638 // empty texture is ok, though pointless from app point of view
640 std::string url = TextureManager::AddTexture(empty);
641 DALI_TEST_CHECK(url.size() > 0u);
643 Property::Map propertyMap;
644 propertyMap[ImageVisual::Property::URL] = url;
645 imageView.SetProperty(ImageView::Property::IMAGE, propertyMap);
647 Stage::GetCurrent().Add( imageView );
648 application.SendNotification();
649 application.Render();
654 int UtcDaliImageViewSizeWithBackground(void)
656 ToolkitTestApplication application;
660 Image image = CreateBufferImage( width, height, Vector4(1.f, 1.f, 1.f, 1.f) );
661 ImageView imageView = ImageView::New();
662 imageView.SetBackgroundImage( image );
664 Stage::GetCurrent().Add( imageView );
665 application.SendNotification();
666 application.Render();
668 DALI_TEST_EQUALS( imageView.GetCurrentSize().width, (float)width, TEST_LOCATION );
669 DALI_TEST_EQUALS( imageView.GetCurrentSize().height, (float)height, TEST_LOCATION );
674 int UtcDaliImageViewSizeWithBackgroundAndImage(void)
676 ToolkitTestApplication application;
678 int widthBackground = 100;
679 int heightBackground = 200;
682 Image imageBackground = CreateBufferImage( widthBackground, heightBackground, Vector4(1.f, 1.f, 1.f, 1.f) );
683 Image image = CreateBufferImage( width, height, Vector4(1.f, 1.f, 1.f, 1.f) );
685 ImageView imageView = ImageView::New();
686 imageView.SetBackgroundImage( imageBackground );
687 imageView.SetImage( image );
689 Stage::GetCurrent().Add( imageView );
690 application.SendNotification();
691 application.Render();
693 DALI_TEST_EQUALS( imageView.GetCurrentSize().width, (float)width, TEST_LOCATION );
694 DALI_TEST_EQUALS( imageView.GetCurrentSize().height, (float)height, TEST_LOCATION );
699 int UtcDaliImageViewHeightForWidthBackground(void)
701 ToolkitTestApplication application;
703 int widthBackground = 100;
704 int heightBackground = 200;
705 Image imageBackground = CreateBufferImage( widthBackground, heightBackground, Vector4(1.f, 1.f, 1.f, 1.f) );
707 ImageView imageView = ImageView::New();
708 imageView.SetBackgroundImage( imageBackground );
710 Stage::GetCurrent().Add( imageView );
711 application.SendNotification();
712 application.Render();
714 Control control = Control::DownCast( imageView );
715 DALI_TEST_CHECK( control );
716 DALI_TEST_EQUALS( imageView.GetHeightForWidth( 123.f ), control.GetHeightForWidth( 123.f ), TEST_LOCATION );
717 DALI_TEST_EQUALS( imageView.GetWidthForHeight( 321.f ), control.GetWidthForHeight( 321.f ), TEST_LOCATION );
722 int UtcDaliImageViewHeightForWidthBackgroundAndImage(void)
724 ToolkitTestApplication application;
726 int widthBackground = 100;
727 int heightBackground = 200;
730 Image imageBackground = CreateBufferImage( widthBackground, heightBackground, Vector4(1.f, 1.f, 1.f, 1.f) );
731 Image image = CreateBufferImage( width, height, Vector4(1.f, 1.f, 1.f, 1.f) );
733 ImageView imageView = ImageView::New();
734 imageView.SetBackgroundImage( imageBackground );
735 imageView.SetImage( image );
737 Stage::GetCurrent().Add( imageView );
738 application.SendNotification();
739 application.Render();
741 DALI_TEST_EQUALS( imageView.GetHeightForWidth( width ), (float)height, TEST_LOCATION );
742 DALI_TEST_EQUALS( imageView.GetWidthForHeight( height ), (float)width, TEST_LOCATION );
747 int UtcDaliImageViewSetBufferImage(void)
749 ToolkitTestApplication application;
753 BufferImage image1 = CreateBufferImage( width1, height1, Vector4( 1.f, 1.f, 1.f, 1.f ) );
754 ImageView imageView = ImageView::New();
755 imageView.SetImage( image1 );
757 TestImage( imageView, image1 );
761 BufferImage image2 = CreateBufferImage( width2, height2, Vector4( 1.f, 1.f, 1.f, 1.f ) );
762 imageView.SetImage( image2 );
764 TestImage( imageView, image2 );
769 int UtcDaliImageViewSetImageUrl(void)
771 ToolkitTestApplication application;
773 ImageView imageView = ImageView::New();
774 imageView.SetImage( TEST_IMAGE_FILE_NAME );
775 TestUrl( imageView, TEST_IMAGE_FILE_NAME );
778 imageView.SetImage( TEST_IMAGE_FILE_NAME2 );
779 TestUrl( imageView, TEST_IMAGE_FILE_NAME2 );
784 int UtcDaliImageViewSetImageOnstageP(void)
786 ToolkitTestApplication application;
788 ImageView imageView = ImageView::New();
790 Stage::GetCurrent().Add( imageView );
791 application.SendNotification();
792 application.Render();
794 ResourceImage image1 = ResourceImage::New( TEST_IMAGE_FILE_NAME );
795 imageView.SetImage( image1 );
796 TestImage( imageView, image1 );
800 BufferImage image2 = CreateBufferImage( width, height, Vector4( 1.f, 1.f, 1.f, 1.f ) );
801 imageView.SetImage( image2 );
802 TestImage( imageView, image2 );
807 int UtcDaliImageViewSetImageOnstageN(void)
809 ToolkitTestApplication application;
811 ImageView imageView = ImageView::New();
813 Stage::GetCurrent().Add( imageView );
814 application.SendNotification();
815 application.Render();
817 ResourceImage image1 = ResourceImage::New( TEST_IMAGE_FILE_NAME );
818 imageView.SetImage( image1 );
819 TestImage( imageView, image1 );
822 imageView.SetImage( image2 );
824 Property::Value value = imageView.GetProperty( imageView.GetPropertyIndex( "image" ) );
826 //the value should be empty
828 DALI_TEST_CHECK( !value.Get( url ) );
831 DALI_TEST_CHECK( !value.Get( map ) );
836 int UtcDaliImageViewSetImageOffstageP(void)
838 ToolkitTestApplication application;
840 ImageView imageView = ImageView::New();
842 Stage::GetCurrent().Add( imageView );
843 application.SendNotification();
844 application.Render();
845 Stage::GetCurrent().Remove( imageView );
847 ResourceImage image1 = ResourceImage::New( TEST_IMAGE_FILE_NAME );
848 imageView.SetImage( image1 );
849 TestImage( imageView, image1 );
853 BufferImage image2 = CreateBufferImage( width, height, Vector4( 1.f, 1.f, 1.f, 1.f ) );
854 imageView.SetImage( image2 );
855 TestImage( imageView, image2 );
860 bool gResourceReadySignalFired = false;
861 Vector3 gNaturalSize;
863 void ResourceReadySignal( Control control )
865 gResourceReadySignalFired = true;
868 int UtcDaliImageViewCheckResourceReady(void)
870 ToolkitTestApplication application;
872 gResourceReadySignalFired = false;
877 Image image = CreateBufferImage( width, height, Vector4(1.f, 1.f, 1.f, 1.f) );
879 // Check ImageView with background and main image, to ensure both visuals are marked as loaded
880 ImageView imageView = ImageView::New( TEST_GIF_FILE_NAME );
882 imageView.SetBackgroundImage( image );
884 DALI_TEST_EQUALS( imageView.IsResourceReady(), false, TEST_LOCATION );
886 imageView.ResourceReadySignal().Connect( &ResourceReadySignal);
888 Stage::GetCurrent().Add( imageView );
890 application.SendNotification();
891 application.Render(16);
894 DALI_TEST_EQUALS( imageView.IsResourceReady(), true, TEST_LOCATION );
896 DALI_TEST_EQUALS( gResourceReadySignalFired, true, TEST_LOCATION );
901 int UtcDaliImageViewSetImageOffstageN(void)
903 ToolkitTestApplication application;
905 ImageView imageView = ImageView::New();
907 Stage::GetCurrent().Add( imageView );
908 application.SendNotification();
909 application.Render();
910 Stage::GetCurrent().Remove( imageView );
912 ResourceImage image1 = ResourceImage::New( TEST_IMAGE_FILE_NAME );
913 imageView.SetImage( image1 );
914 TestImage( imageView, image1 );
917 imageView.SetImage( image2 );
919 Property::Value value = imageView.GetProperty( imageView.GetPropertyIndex( "image" ) );
921 //the value should be empty
923 DALI_TEST_CHECK( !value.Get( url ) );
926 DALI_TEST_CHECK( !value.Get( map ) );
931 int UtcDaliImageViewSetImageN(void)
933 ToolkitTestApplication application;
936 ImageView imageView = ImageView::New();
937 imageView.SetImage( image1 );
939 Property::Value value = imageView.GetProperty( imageView.GetPropertyIndex( "image" ) );
941 //the value should be empty
943 DALI_TEST_CHECK( !value.Get( url ) );
946 DALI_TEST_CHECK( !value.Get( map ) );
948 std::string resource_url;
949 Property::Value val = imageView.GetProperty( imageView.GetPropertyIndex( "image" ) );
950 DALI_TEST_CHECK( !val.Get( resource_url ) );
955 int UtcDaliImageViewSetImageTypeChangesP(void)
957 ToolkitTestApplication application;
959 ImageView imageView = ImageView::New();
960 Toolkit::Internal::Control& controlImpl = Toolkit::Internal::GetImplementation( imageView );
962 Stage::GetCurrent().Add( imageView );
966 Toolkit::Visual::Base visual;
968 Property::Value value = imageView.GetProperty( imageView.GetPropertyIndex( "image" ) );
969 visual = DevelControl::GetVisual( controlImpl, ImageView::Property::IMAGE );
971 application.SendNotification();
972 application.Render( 16 );
974 DALI_TEST_CHECK( ! value.Get( url ) ); // Value should be empty
975 DALI_TEST_CHECK( ! value.Get( map ) ); // Value should be empty
976 DALI_TEST_CHECK( ! visual ); // Visual should be invalid
979 imageView.SetImage( "TEST_URL" );
981 application.SendNotification();
982 application.Render( 16 );
984 value = imageView.GetProperty( imageView.GetPropertyIndex( "image" ) );
985 visual = DevelControl::GetVisual( controlImpl, ImageView::Property::IMAGE );
987 DALI_TEST_CHECK( value.Get( url ) ); // Value should NOT be empty
988 DALI_TEST_CHECK( ! value.Get( map ) ); // Value should be empty
989 DALI_TEST_CHECK( visual ); // Visual should be valid
991 // Set an empty Image
992 imageView.SetImage( Image() );
994 application.SendNotification();
995 application.Render( 16 );
997 value = imageView.GetProperty( imageView.GetPropertyIndex( "image" ) );
998 visual = DevelControl::GetVisual( controlImpl, ImageView::Property::IMAGE );
1000 DALI_TEST_CHECK( ! value.Get( url ) ); // Value should be empty
1001 DALI_TEST_CHECK( ! value.Get( map ) ); // Value should be empty
1002 DALI_TEST_CHECK( ! visual ); // Visual should be invalid
1005 ResourceImage image1 = ResourceImage::New( TEST_IMAGE_FILE_NAME );
1006 imageView.SetImage( image1 );
1008 application.SendNotification();
1009 application.Render( 16 );
1011 value = imageView.GetProperty( imageView.GetPropertyIndex( "image" ) );
1012 visual = DevelControl::GetVisual( controlImpl, ImageView::Property::IMAGE );
1014 DALI_TEST_CHECK( ! value.Get( url ) ); // Value should be empty
1015 DALI_TEST_CHECK( value.Get( map ) ); // Value should NOT be empty
1016 DALI_TEST_CHECK( visual ); // Visual should be valid
1019 imageView.SetImage( "" );
1021 application.SendNotification();
1022 application.Render( 16 );
1024 value = imageView.GetProperty( imageView.GetPropertyIndex( "image" ) );
1025 visual = DevelControl::GetVisual( controlImpl, ImageView::Property::IMAGE );
1027 DALI_TEST_CHECK( ! value.Get( url ) ); // Value should be empty
1028 DALI_TEST_CHECK( ! value.Get( map ) ); // Value should be empty
1029 DALI_TEST_CHECK( ! visual ); // Visual should be invalid
1031 // Set a URL in property map
1032 Property::Map propertyMap;
1033 propertyMap[ImageVisual::Property::URL] = TEST_IMAGE_FILE_NAME;
1034 imageView.SetProperty( ImageView::Property::IMAGE, propertyMap );
1036 application.SendNotification();
1037 application.Render( 16 );
1039 value = imageView.GetProperty( imageView.GetPropertyIndex( "image" ) );
1040 visual = DevelControl::GetVisual( controlImpl, ImageView::Property::IMAGE );
1042 DALI_TEST_CHECK( ! value.Get( url ) ); // Value should be empty
1043 DALI_TEST_CHECK( value.Get( map ) ); // Value should NOT be empty
1044 DALI_TEST_CHECK( visual ); // Visual should be valid
1046 // Set a URL in property map again
1047 propertyMap[ImageVisual::Property::URL] = gImage_34_RGBA;
1048 imageView.SetProperty( ImageView::Property::IMAGE, propertyMap );
1050 application.SendNotification();
1051 application.Render( 16 );
1053 value = imageView.GetProperty( imageView.GetPropertyIndex( "image" ) );
1054 visual = DevelControl::GetVisual( controlImpl, ImageView::Property::IMAGE );
1056 DALI_TEST_CHECK( ! value.Get( url ) ); // Value should be empty
1057 DALI_TEST_CHECK( value.Get( map ) ); // Value should NOT be empty
1058 DALI_TEST_CHECK( visual ); // Visual should be valid
1060 // Set an empty URL in property map
1061 propertyMap[ImageVisual::Property::URL] = std::string();
1062 imageView.SetProperty( ImageView::Property::IMAGE, propertyMap );
1064 application.SendNotification();
1065 application.Render( 16 );
1067 value = imageView.GetProperty( imageView.GetPropertyIndex( "image" ) );
1068 visual = DevelControl::GetVisual( controlImpl, ImageView::Property::IMAGE );
1070 DALI_TEST_CHECK( ! value.Get( url ) ); // Value should be empty
1071 DALI_TEST_CHECK( value.Get( map ) ); // Value should NOT be empty
1072 DALI_TEST_CHECK( ! visual ); // Visual should be invalid
1077 int UtcDaliImageViewResourceUrlP(void)
1079 ToolkitTestApplication application;
1081 ImageView imageView = ImageView::New();
1082 DALI_TEST_CHECK( imageView.GetProperty( ImageView::Property::RESOURCE_URL ).Get< std::string >().empty() );
1084 imageView.SetProperty( ImageView::Property::RESOURCE_URL, "TestString" );
1085 DALI_TEST_EQUALS( imageView.GetProperty( ImageView::Property::RESOURCE_URL ).Get< std::string >(), "TestString", TEST_LOCATION );
1090 // Scenarios 1: ImageView from regular image
1091 int UtcDaliImageViewSetImageBufferImage(void)
1093 ToolkitTestApplication application;
1095 ImageView imageView = ImageView::New();
1096 Stage::GetCurrent().Add( imageView );
1098 TestGlAbstraction& gl = application.GetGlAbstraction();
1099 gl.EnableTextureCallTrace( true );
1101 std::vector< GLuint > ids;
1102 ids.push_back( 23 );
1103 application.GetGlAbstraction().SetNextTextureIds( ids );
1107 BufferImage image = CreateBufferImage( width, height, Color::WHITE );
1109 imageView.SetImage( image );
1111 application.SendNotification();
1112 application.Render();
1114 DALI_TEST_CHECK( gl.GetTextureTrace().FindMethod("BindTexture") );
1116 std::stringstream params;
1117 params << GL_TEXTURE_2D << ", " << 23;
1118 DALI_TEST_CHECK( gl.GetTextureTrace().FindMethodAndParams("BindTexture", params.str()) );
1123 // Scenarios 2: ImageView from Native image
1124 int UtcDaliImageViewSetImageNativeImage(void)
1126 ToolkitTestApplication application;
1128 ImageView imageView = ImageView::New();
1129 Stage::GetCurrent().Add( imageView );
1131 TestGlAbstraction& gl = application.GetGlAbstraction();
1132 gl.EnableTextureCallTrace( true );
1134 std::vector< GLuint > ids;
1135 ids.push_back( 23 );
1136 application.GetGlAbstraction().SetNextTextureIds( ids );
1140 TestNativeImagePointer nativeImageInterface = TestNativeImage::New( width, height );
1141 NativeImage nativeImage = NativeImage::New( *(nativeImageInterface.Get()) );
1143 imageView.SetImage( nativeImage );
1144 application.SendNotification();
1145 application.Render();
1147 DALI_TEST_CHECK( gl.GetTextureTrace().FindMethod("BindTexture") );
1149 std::stringstream params;
1150 params << GL_TEXTURE_EXTERNAL_OES << ", " << 23;
1151 DALI_TEST_CHECK( gl.GetTextureTrace().FindMethodAndParams("BindTexture", params.str()) );
1156 // Scenarios 3: ImageView initially from regular image but then SetImage called with Native image
1157 int UtcDaliImageViewSetImageBufferImageToNativeImage(void)
1159 ToolkitTestApplication application;
1163 BufferImage image = CreateBufferImage( width, height, Color::WHITE );
1165 ImageView imageView = ImageView::New( image );
1166 Stage::GetCurrent().Add( imageView );
1168 TestGlAbstraction& gl = application.GetGlAbstraction();
1169 gl.EnableTextureCallTrace( true );
1171 std::vector< GLuint > ids;
1172 ids.push_back( 23 );
1173 application.GetGlAbstraction().SetNextTextureIds( ids );
1175 application.SendNotification();
1176 application.Render();
1178 DALI_TEST_CHECK( gl.GetTextureTrace().FindMethod("BindTexture") );
1180 std::stringstream params;
1181 params << GL_TEXTURE_2D << ", " << 23;
1182 DALI_TEST_CHECK( gl.GetTextureTrace().FindMethodAndParams("BindTexture", params.str()) );
1186 TestNativeImagePointer nativeImageInterface = TestNativeImage::New( width, height );
1187 NativeImage nativeImage = NativeImage::New( *(nativeImageInterface.Get()) );
1188 imageView.SetImage( nativeImage );
1191 ids.push_back( 24 );
1192 application.GetGlAbstraction().SetNextTextureIds( ids );
1194 application.SendNotification();
1195 application.Render();
1197 DALI_TEST_CHECK( gl.GetTextureTrace().FindMethod("BindTexture") );
1199 std::stringstream nextTextureParams;
1200 nextTextureParams << GL_TEXTURE_EXTERNAL_OES << ", " << 24;
1201 DALI_TEST_CHECK( gl.GetTextureTrace().FindMethodAndParams("BindTexture", nextTextureParams.str()) );
1206 // Scenarios 4: ImageView initially from Native image but then SetImage called with regular image
1207 int UtcDaliImageViewSetImageNativeImageToBufferImage(void)
1209 ToolkitTestApplication application;
1213 TestNativeImagePointer nativeImageInterface = TestNativeImage::New( width, height );
1214 NativeImage nativeImage = NativeImage::New( *(nativeImageInterface.Get()) );
1216 ImageView imageView = ImageView::New( nativeImage );
1217 Stage::GetCurrent().Add( imageView );
1219 TestGlAbstraction& gl = application.GetGlAbstraction();
1220 gl.EnableTextureCallTrace( true );
1222 std::vector< GLuint > ids;
1223 ids.push_back( 23 );
1224 application.GetGlAbstraction().SetNextTextureIds( ids );
1226 application.SendNotification();
1227 application.Render();
1229 DALI_TEST_CHECK( gl.GetTextureTrace().FindMethod("BindTexture") );
1231 std::stringstream params;
1232 params << GL_TEXTURE_EXTERNAL_OES << ", " << 23;
1233 DALI_TEST_CHECK( gl.GetTextureTrace().FindMethodAndParams("BindTexture", params.str()) );
1237 BufferImage image = CreateBufferImage( width, height, Color::WHITE );
1238 imageView.SetImage( image );
1241 ids.push_back( 24 );
1242 application.GetGlAbstraction().SetNextTextureIds( ids );
1244 application.SendNotification();
1245 application.Render();
1247 DALI_TEST_CHECK( gl.GetTextureTrace().FindMethod("BindTexture") );
1249 std::stringstream nextTextureParams;
1250 nextTextureParams << GL_TEXTURE_2D << ", " << 24;
1251 DALI_TEST_CHECK( gl.GetTextureTrace().FindMethodAndParams("BindTexture", nextTextureParams.str()) );
1256 // Scenarios 5: ImageView from Native image with custom shader
1257 int UtcDaliImageViewSetImageNativeImageWithCustomShader(void)
1259 ToolkitTestApplication application;
1264 Property::Map customShader;
1265 customShader.Insert( "vertexShader", VERTEX_SHADER );
1266 customShader.Insert( "fragmentShader", FRAGMENT_SHADER );
1268 Property::Array shaderHints;
1269 shaderHints.PushBack( "requiresSelfDepthTest" );
1270 shaderHints.PushBack( "outputIsTransparent" );
1271 shaderHints.PushBack( "outputIsOpaque" );
1272 shaderHints.PushBack( "modifiesGeometry" );
1274 customShader.Insert( "hints", shaderHints );
1277 map.Insert( "shader", customShader );
1279 TestNativeImagePointer nativeImageInterface = TestNativeImage::New( width, height );
1280 NativeImage nativeImage = NativeImage::New( *(nativeImageInterface.Get()) );
1282 ImageView imageView = ImageView::New( nativeImage );
1283 imageView.SetProperty( ImageView::Property::IMAGE, map );
1284 Stage::GetCurrent().Add( imageView );
1286 TestGlAbstraction& gl = application.GetGlAbstraction();
1287 gl.EnableTextureCallTrace( true );
1289 std::vector< GLuint > ids;
1290 ids.push_back( 23 );
1291 application.GetGlAbstraction().SetNextTextureIds( ids );
1293 application.SendNotification();
1294 application.Render();
1296 DALI_TEST_CHECK( gl.GetTextureTrace().FindMethod("BindTexture") );
1298 std::stringstream params;
1299 params << GL_TEXTURE_EXTERNAL_OES << ", " << 23;
1300 DALI_TEST_CHECK( gl.GetTextureTrace().FindMethodAndParams("BindTexture", params.str()) );
1305 // Scenarios 6: ImageView initially from regular image with custom shader but then SetImage called with Native
1306 int UtcDaliImageViewSetImageBufferImageWithCustomShaderToNativeImage(void)
1308 ToolkitTestApplication application;
1313 Property::Map customShader;
1314 customShader.Insert( "vertexShader", VERTEX_SHADER );
1315 customShader.Insert( "fragmentShader", FRAGMENT_SHADER );
1317 Property::Array shaderHints;
1318 shaderHints.PushBack( "requiresSelfDepthTest" );
1319 shaderHints.PushBack( "outputIsTransparent" );
1320 shaderHints.PushBack( "outputIsOpaque" );
1321 shaderHints.PushBack( "modifiesGeometry" );
1323 customShader.Insert( "hints", shaderHints );
1326 map.Insert( "shader", customShader );
1328 BufferImage image = CreateBufferImage( width, height, Color::WHITE );
1330 ImageView imageView = ImageView::New( image );
1331 imageView.SetProperty( ImageView::Property::IMAGE, map );
1332 Stage::GetCurrent().Add( imageView );
1334 TestGlAbstraction& gl = application.GetGlAbstraction();
1335 gl.EnableTextureCallTrace( true );
1337 std::vector< GLuint > ids;
1338 ids.push_back( 23 );
1339 application.GetGlAbstraction().SetNextTextureIds( ids );
1341 application.SendNotification();
1342 application.Render();
1344 DALI_TEST_CHECK( gl.GetTextureTrace().FindMethod("BindTexture") );
1346 std::stringstream params;
1347 params << GL_TEXTURE_2D << ", " << 23;
1348 DALI_TEST_CHECK( gl.GetTextureTrace().FindMethodAndParams("BindTexture", params.str()) );
1350 TestNativeImagePointer nativeImageInterface = TestNativeImage::New( width, height );
1351 NativeImage nativeImage = NativeImage::New( *(nativeImageInterface.Get()) );
1352 imageView.SetImage( nativeImage );
1355 ids.push_back( 24 );
1356 application.GetGlAbstraction().SetNextTextureIds( ids );
1358 application.SendNotification();
1359 application.Render();
1361 DALI_TEST_CHECK( gl.GetTextureTrace().FindMethod("BindTexture") );
1363 std::stringstream nativeImageParams;
1364 nativeImageParams << GL_TEXTURE_EXTERNAL_OES << ", " << 24;
1365 DALI_TEST_CHECK( gl.GetTextureTrace().FindMethodAndParams("BindTexture", nativeImageParams.str()) );
1371 int UtcDaliImageViewGetImageP1(void)
1373 ToolkitTestApplication application;
1375 ImageView imageView = ImageView::New();
1376 DALI_TEST_CHECK( ! imageView.GetImage() );
1378 Image image = CreateBufferImage();
1379 imageView.SetImage( image );
1380 DALI_TEST_CHECK( imageView.GetImage() == image );
1385 int UtcDaliImageViewGetImageP2(void)
1387 ToolkitTestApplication application;
1389 BufferImage image = CreateBufferImage();
1390 ImageView imageView = ImageView::New( image );
1391 DALI_TEST_CHECK( imageView.GetImage() == image );
1396 int UtcDaliImageViewGetImageN(void)
1398 ToolkitTestApplication application;
1400 ImageView imageView = ImageView::New( TEST_IMAGE_FILE_NAME );
1401 DALI_TEST_CHECK( ! imageView.GetImage() );
1403 Image image = CreateBufferImage();
1404 imageView.SetImage( image );
1405 DALI_TEST_CHECK( imageView.GetImage() == image );
1407 imageView.SetImage( TEST_IMAGE_FILE_NAME );
1408 DALI_TEST_CHECK( ! imageView.GetImage() );
1414 int UtcDaliImageViewReplaceImage(void)
1416 ToolkitTestApplication application;
1418 gResourceReadySignalFired = false;
1422 Image image = CreateBufferImage( width, height, Vector4(1.f, 1.f, 1.f, 1.f) );
1424 // Check ImageView with background and main image, to ensure both visuals are marked as loaded
1425 ImageView imageView = ImageView::New( TEST_IMAGE_1 );
1427 DALI_TEST_EQUALS( imageView.IsResourceReady(), false, TEST_LOCATION );
1429 imageView.ResourceReadySignal().Connect( &ResourceReadySignal);
1431 Stage::GetCurrent().Add( imageView );
1433 application.SendNotification();
1434 application.Render(16);
1436 // loading started, this waits for the loader thread for max 30 seconds
1437 DALI_TEST_EQUALS( Test::WaitForEventThreadTrigger( 1 ), true, TEST_LOCATION );
1439 DALI_TEST_EQUALS( imageView.GetRendererCount(), 1u, TEST_LOCATION );
1441 DALI_TEST_EQUALS( gResourceReadySignalFired, true, TEST_LOCATION );
1443 gResourceReadySignalFired = false;
1445 imageView.SetImage(TEST_IMAGE_2);
1447 application.SendNotification();
1448 application.Render(16);
1450 // loading started, this waits for the loader thread for max 30 seconds
1451 DALI_TEST_EQUALS( Test::WaitForEventThreadTrigger( 1 ), true, TEST_LOCATION );
1453 DALI_TEST_EQUALS( imageView.GetRendererCount(), 1u, TEST_LOCATION );
1455 DALI_TEST_EQUALS( imageView.IsResourceReady(), true, TEST_LOCATION );
1457 DALI_TEST_EQUALS( gResourceReadySignalFired, true, TEST_LOCATION );
1462 void OnRelayoutOverride( Size size )
1464 gNaturalSize = size; // Size Relayout is using
1467 int UtcDaliImageViewReplaceImageAndGetNaturalSize(void)
1469 ToolkitTestApplication application;
1471 // Check ImageView with background and main image, to ensure both visuals are marked as loaded
1472 ImageView imageView = ImageView::New( TEST_IMAGE_1 );
1473 imageView.SetResizePolicy( ResizePolicy::USE_NATURAL_SIZE, Dimension::ALL_DIMENSIONS );
1475 DummyControl dummyControl = DummyControl::New( true );
1476 Impl::DummyControl& dummyImpl = static_cast<Impl::DummyControl&>(dummyControl.GetImplementation());
1477 dummyControl.SetResizePolicy( ResizePolicy::FIT_TO_CHILDREN, Dimension::ALL_DIMENSIONS );
1479 dummyControl.Add( imageView );
1480 dummyImpl.SetRelayoutCallback( &OnRelayoutOverride );
1481 Stage::GetCurrent().Add( dummyControl );
1483 application.SendNotification();
1484 application.Render();
1486 // loading started, this waits for the loader thread for max 30 seconds
1487 DALI_TEST_EQUALS( Test::WaitForEventThreadTrigger( 1 ), true, TEST_LOCATION );
1489 DALI_TEST_EQUALS( gNaturalSize.width, 1024.0f, TEST_LOCATION );
1490 DALI_TEST_EQUALS( gNaturalSize.height, 1024.0f, TEST_LOCATION );
1492 gNaturalSize = Vector3::ZERO;
1494 imageView.SetImage(gImage_600_RGB);
1496 // Waiting for resourceReady so SendNotifcation not called here.
1498 // loading started, this waits for the loader thread for max 30 seconds
1499 DALI_TEST_EQUALS( Test::WaitForEventThreadTrigger( 1 ), true, TEST_LOCATION );
1501 // Trigger a potential relayout
1502 application.SendNotification();
1503 application.Render();
1505 DALI_TEST_EQUALS( gNaturalSize.width, 600.0f, TEST_LOCATION );
1506 DALI_TEST_EQUALS( gNaturalSize.height, 600.0f, TEST_LOCATION );