2 * Copyright (c) 2018 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>
28 #include <dali-toolkit/devel-api/visuals/image-visual-properties-devel.h>
29 #include <dali-toolkit/devel-api/visuals/visual-properties-devel.h>
31 #include <test-native-image.h>
36 #include "dummy-control.h"
39 using namespace Toolkit;
41 void utc_dali_toolkit_image_view_startup(void)
43 test_return_value = TET_UNDEF;
46 void utc_dali_toolkit_image_view_cleanup(void)
48 test_return_value = TET_PASS;
54 const char* VERTEX_SHADER = DALI_COMPOSE_SHADER(
55 attribute mediump vec2 aPosition;\n
56 varying mediump vec2 vTexCoord;\n
57 uniform mediump mat4 uMvpMatrix;\n
58 uniform mediump vec3 uSize;\n
62 mediump vec4 vertexPosition = vec4(aPosition, 0.0, 1.0);\n
63 vertexPosition.xyz *= uSize;\n
64 vertexPosition = uMvpMatrix * vertexPosition;\n
66 vTexCoord = aPosition + vec2(0.5);\n
67 gl_Position = vertexPosition;\n
71 const char* FRAGMENT_SHADER = DALI_COMPOSE_SHADER(
72 varying mediump vec2 vTexCoord;\n
73 uniform sampler2D sTexture;\n
74 uniform lowp vec4 uColor;\n
78 gl_FragColor = texture2D( sTexture, vTexCoord ) * uColor;\n
82 const char* TEST_IMAGE_FILE_NAME = "gallery_image_01.jpg";
83 const char* TEST_IMAGE_FILE_NAME2 = "gallery_image_02.jpg";
85 const char* TEST_IMAGE_1 = TEST_RESOURCE_DIR "/TB-gloss.png";
86 const char* TEST_IMAGE_2 = TEST_RESOURCE_DIR "/tb-norm.png";
88 // resolution: 34*34, pixel format: RGBA8888
89 static const char* gImage_34_RGBA = TEST_RESOURCE_DIR "/icon-edit.png";
90 // resolution: 600*600, pixel format: RGB888
91 static const char* gImage_600_RGB = TEST_RESOURCE_DIR "/test-image-600.jpg";
93 // resolution: 50*50, frame count: 4, frame delay: 0.2 second for each frame
94 const char* TEST_GIF_FILE_NAME = TEST_RESOURCE_DIR "/anim.gif";
96 void TestImage( ImageView imageView, BufferImage image )
98 Property::Value value = imageView.GetProperty( imageView.GetPropertyIndex( "image" ) );
101 DALI_TEST_CHECK( value.Get( map ) );
103 DALI_TEST_CHECK( map.Find( "width" ) );
104 DALI_TEST_CHECK( map.Find( "height" ) );
105 DALI_TEST_CHECK( map.Find( "type" ) );
108 DALI_TEST_CHECK( map[ "width" ].Get( width ) );
109 DALI_TEST_EQUALS( (unsigned int)width, image.GetWidth(), TEST_LOCATION );
112 DALI_TEST_CHECK( map[ "height" ].Get( height ) );
113 DALI_TEST_EQUALS( (unsigned int)height, image.GetHeight(), TEST_LOCATION );
116 DALI_TEST_CHECK( map[ "type" ].Get( type ) );
117 DALI_TEST_EQUALS( type, "BufferImage", TEST_LOCATION );
120 void TestImage( ImageView imageView, ResourceImage image )
122 Property::Value value = imageView.GetProperty( imageView.GetPropertyIndex( "image" ) );
125 DALI_TEST_CHECK( value.Get( map ) );
127 if( map.Find( "width" ) )
130 DALI_TEST_CHECK( map[ "width" ].Get( width ) );
131 DALI_TEST_EQUALS( (unsigned int)width, image.GetWidth(), TEST_LOCATION );
134 if( map.Find( "height" ) )
137 DALI_TEST_CHECK( map[ "height" ].Get( height ) );
138 DALI_TEST_EQUALS( (unsigned int)height, image.GetHeight(), TEST_LOCATION );
141 DALI_TEST_CHECK( map.Find( "type" ) );
144 DALI_TEST_CHECK( map[ "type" ].Get( type ) );
145 DALI_TEST_EQUALS( type, "ResourceImage", TEST_LOCATION );
147 std::string filename;
148 DALI_TEST_CHECK( map[ "filename" ].Get( filename ) );
149 DALI_TEST_EQUALS( filename, image.GetUrl(), TEST_LOCATION );
152 void TestUrl( ImageView imageView, const std::string url )
154 Property::Value value = imageView.GetProperty( imageView.GetPropertyIndex( "image" ) );
156 std::string urlActual;
157 DALI_TEST_CHECK( value.Get( urlActual ) );
158 DALI_TEST_EQUALS( urlActual, url, TEST_LOCATION );
163 int UtcDaliImageViewNewP(void)
165 TestApplication application;
167 ImageView imageView = ImageView::New();
169 DALI_TEST_CHECK( imageView );
174 int UtcDaliImageViewNewImageP(void)
176 TestApplication application;
178 BufferImage image = CreateBufferImage( 100, 200, Vector4( 1.f, 1.f, 1.f, 1.f ) );
179 ImageView imageView = ImageView::New( image );
181 DALI_TEST_CHECK( imageView );
182 TestImage( imageView, image );
187 int UtcDaliImageViewNewUrlP(void)
189 TestApplication application;
191 ImageView imageView = ImageView::New( TEST_IMAGE_FILE_NAME );
192 DALI_TEST_CHECK( imageView );
194 TestUrl( imageView, TEST_IMAGE_FILE_NAME );
199 int UtcDaliImageViewConstructorP(void)
201 TestApplication application;
205 DALI_TEST_CHECK( !imageView );
210 int UtcDaliImageViewCopyConstructorP(void)
212 TestApplication application;
214 // Initialize an object, ref count == 1
215 ImageView imageView = ImageView::New();
217 ImageView copy( imageView );
218 DALI_TEST_CHECK( copy );
223 int UtcDaliImageViewAssignmentOperatorP(void)
225 TestApplication application;
227 ImageView imageView = ImageView::New();
229 ImageView copy( imageView );
230 DALI_TEST_CHECK( copy );
231 DALI_TEST_EQUALS( imageView, copy, TEST_LOCATION );
236 int UtcDaliImageViewDownCastP(void)
238 TestApplication application;
240 ImageView imageView = ImageView::New();
242 BaseHandle object(imageView);
244 ImageView imageView2 = ImageView::DownCast( object );
245 DALI_TEST_CHECK(imageView2);
247 ImageView imageView3 = DownCast< ImageView >( object );
248 DALI_TEST_CHECK(imageView3);
253 int UtcDaliImageViewDownCastN(void)
255 TestApplication application;
257 BaseHandle unInitializedObject;
259 ImageView imageView1 = ImageView::DownCast( unInitializedObject );
260 DALI_TEST_CHECK( !imageView1 );
262 ImageView imageView2 = DownCast< ImageView >( unInitializedObject );
263 DALI_TEST_CHECK( !imageView2 );
268 int UtcDaliImageViewTypeRegistry(void)
270 ToolkitTestApplication application;
272 TypeRegistry typeRegistry = TypeRegistry::Get();
273 DALI_TEST_CHECK( typeRegistry );
275 TypeInfo typeInfo = typeRegistry.GetTypeInfo( "ImageView" );
276 DALI_TEST_CHECK( typeInfo );
278 BaseHandle handle = typeInfo.CreateInstance();
279 DALI_TEST_CHECK( handle );
281 ImageView imageView = ImageView::DownCast( handle );
282 DALI_TEST_CHECK( imageView );
287 int UtcDaliImageViewSetGetProperty01(void)
289 ToolkitTestApplication application;
291 ImageView imageView = ImageView::New();
293 Property::Index idx = imageView.GetPropertyIndex( "image" );
294 DALI_TEST_EQUALS( idx, (Property::Index)ImageView::Property::IMAGE, TEST_LOCATION );
296 imageView.SetProperty( idx, TEST_IMAGE_FILE_NAME );
297 TestUrl( imageView, TEST_IMAGE_FILE_NAME );
302 int UtcDaliImageViewSetGetProperty02(void)
304 ToolkitTestApplication application;
306 Image image = CreateBufferImage( 10, 10, Color::WHITE );
307 ImageView imageView = ImageView::New(image);
308 Vector4 fullImageRect( 0.f, 0.f, 1.f, 1.f );
310 Stage::GetCurrent().Add( imageView );
312 application.SendNotification();
313 application.Render();
314 TestGlAbstraction& gl = application.GetGlAbstraction();
316 Vector4 pixelAreaUniform;
317 DALI_TEST_CHECK( gl.GetUniformValue<Vector4>( "pixelArea", pixelAreaUniform ) );
318 DALI_TEST_EQUALS( pixelAreaUniform, fullImageRect, TEST_LOCATION );
320 Property::Value value = imageView.GetProperty( ImageView::Property::PIXEL_AREA );
321 Vector4 pixelAreaValue;
322 DALI_TEST_CHECK( value.Get(pixelAreaValue) );
323 DALI_TEST_EQUALS( pixelAreaValue, fullImageRect, TEST_LOCATION );
325 Vector4 pixelAreaSet( 0.2f, 0.2f, 0.3f, 0.3f );
326 imageView.SetProperty( ImageView::Property::PIXEL_AREA, pixelAreaSet);
328 application.SendNotification();
329 application.Render();
331 value = imageView.GetProperty( ImageView::Property::PIXEL_AREA );
332 value.Get(pixelAreaValue);
333 DALI_TEST_EQUALS( pixelAreaValue, pixelAreaSet, TEST_LOCATION );
335 DALI_TEST_CHECK( gl.GetUniformValue<Vector4>( "pixelArea", pixelAreaUniform ) );
336 DALI_TEST_EQUALS( pixelAreaUniform, pixelAreaSet, TEST_LOCATION );
341 int UtcDaliImageViewSetGetProperty03(void)
343 ToolkitTestApplication application;
345 Image image = CreateBufferImage( 10, 10, Color::WHITE );
346 ImageView imageView = ImageView::New(image);
347 Stage::GetCurrent().Add( imageView );
348 application.SendNotification();
349 application.Render();
351 // conventional alpha blending
352 Renderer renderer = imageView.GetRendererAt( 0 );
353 Property::Value value = renderer.GetProperty( Renderer::Property::BLEND_PRE_MULTIPLIED_ALPHA );
355 DALI_TEST_CHECK( value.Get( enable ) );
356 DALI_TEST_CHECK( !enable );
358 // pre-multiplied alpha blending
359 imageView.SetProperty( Toolkit::ImageView::Property::PRE_MULTIPLIED_ALPHA, true );
360 application.SendNotification();
361 application.Render();
363 int srcFactorRgb = renderer.GetProperty<int>( Renderer::Property::BLEND_FACTOR_SRC_RGB );
364 int destFactorRgb = renderer.GetProperty<int>( Renderer::Property::BLEND_FACTOR_DEST_RGB );
365 int srcFactorAlpha = renderer.GetProperty<int>( Renderer::Property::BLEND_FACTOR_SRC_ALPHA );
366 int destFactorAlpha = renderer.GetProperty<int>( Renderer::Property::BLEND_FACTOR_DEST_ALPHA );
367 DALI_TEST_CHECK( srcFactorRgb == BlendFactor::ONE );
368 DALI_TEST_CHECK( destFactorRgb == BlendFactor::ONE_MINUS_SRC_ALPHA );
369 DALI_TEST_CHECK( srcFactorAlpha == BlendFactor::ONE );
370 DALI_TEST_CHECK( destFactorAlpha == BlendFactor::ONE_MINUS_SRC_ALPHA );
372 value = renderer.GetProperty( Renderer::Property::BLEND_PRE_MULTIPLIED_ALPHA );
373 DALI_TEST_CHECK( value.Get( enable ) );
374 DALI_TEST_CHECK( enable );
379 int UtcDaliImageViewPixelArea(void)
381 // Test pixel area property
382 ToolkitTestApplication application;
384 // Gif image, use AnimatedImageVisual internally
385 // Atlasing is applied to pack multiple frames, use custom wrap mode
386 ImageView gifView = ImageView::New();
387 const Vector4 pixelAreaVisual( 0.f, 0.f, 2.f, 2.f );
388 gifView.SetProperty( ImageView::Property::IMAGE,
389 Property::Map().Add( ImageVisual::Property::URL, TEST_GIF_FILE_NAME )
390 .Add( ImageVisual::Property::PIXEL_AREA, pixelAreaVisual ) );
393 Stage stage = Stage::GetCurrent();
394 stage.Add( gifView );
397 application.SendNotification();
398 application.Render(16);
399 DALI_TEST_CHECK( gifView.GetRendererCount() == 1u );
401 const Vector4 fullTextureRect( 0.f, 0.f, 1.f, 1.f );
402 // test that the pixel area value defined in the visual property map is registered on renderer
403 Renderer renderer = gifView.GetRendererAt(0);
404 Property::Value pixelAreaValue = renderer.GetProperty( renderer.GetPropertyIndex( "pixelArea" ) );
405 DALI_TEST_EQUALS( pixelAreaValue.Get<Vector4>(), pixelAreaVisual, TEST_LOCATION );
407 // test that the shader has the default pixel area value registered.
408 Shader shader = renderer.GetShader();
409 pixelAreaValue = shader.GetProperty( shader.GetPropertyIndex( "pixelArea" ) );
410 DALI_TEST_EQUALS( pixelAreaValue.Get<Vector4>(), fullTextureRect, TEST_LOCATION );
412 // test that the uniform uses the pixelArea property on the renderer.
413 TestGlAbstraction& gl = application.GetGlAbstraction();
414 Vector4 pixelAreaUniform;
415 DALI_TEST_CHECK( gl.GetUniformValue<Vector4>( "pixelArea", pixelAreaUniform ) );
416 DALI_TEST_EQUALS( pixelAreaVisual, pixelAreaUniform, Math::MACHINE_EPSILON_100, TEST_LOCATION );
418 // set the pixelArea property on the control
419 const Vector4 pixelAreaControl( -1.f, -1.f, 3.f, 3.f );
420 gifView.SetProperty( ImageView::Property::PIXEL_AREA, pixelAreaControl );
421 application.SendNotification();
422 application.Render(16);
424 // check the pixelArea property on the control
425 pixelAreaValue = gifView.GetProperty( gifView.GetPropertyIndex( "pixelArea" ) );
426 DALI_TEST_EQUALS( pixelAreaValue.Get<Vector4>(), pixelAreaControl, TEST_LOCATION );
427 // test that the uniform uses the pixelArea property on the control.
428 DALI_TEST_CHECK( gl.GetUniformValue<Vector4>( "pixelArea", pixelAreaUniform ) );
429 DALI_TEST_EQUALS( pixelAreaControl, pixelAreaUniform, Math::MACHINE_EPSILON_100, TEST_LOCATION );
435 int UtcDaliImageViewAsyncLoadingWithoutAltasing(void)
437 ToolkitTestApplication application;
438 TestGlAbstraction& gl = application.GetGlAbstraction();
439 const std::vector<GLuint>& textures = gl.GetBoundTextures();
440 size_t numTextures = textures.size();
442 // Async loading, no atlasing for big size image
443 ImageView imageView = ImageView::New( gImage_600_RGB );
445 // By default, Aysnc loading is used
446 Stage::GetCurrent().Add( imageView );
447 imageView.SetSize(100, 100);
448 imageView.SetParentOrigin( ParentOrigin::CENTER );
450 DALI_TEST_EQUALS( Test::WaitForEventThreadTrigger( 1 ), true, TEST_LOCATION );
452 application.SendNotification();
453 application.Render(16);
454 application.SendNotification();
456 const std::vector<GLuint>& textures2 = gl.GetBoundTextures();
457 DALI_TEST_GREATER( textures2.size(), numTextures, TEST_LOCATION );
464 int UtcDaliImageViewAsyncLoadingWithAtlasing(void)
466 ToolkitTestApplication application;
468 //Async loading, automatic atlasing for small size image
469 TraceCallStack& callStack = application.GetGlAbstraction().GetTextureTrace();
471 callStack.Enable(true);
473 Property::Map imageMap;
475 imageMap[ ImageVisual::Property::URL ] = gImage_34_RGBA;
476 imageMap[ ImageVisual::Property::DESIRED_HEIGHT ] = 34;
477 imageMap[ ImageVisual::Property::DESIRED_WIDTH ] = 34;
478 imageMap[ ImageVisual::Property::ATLASING] = true;
480 ImageView imageView = ImageView::New();
481 imageView.SetProperty( ImageView::Property::IMAGE, imageMap );
482 imageView.SetProperty( Toolkit::Control::Property::PADDING, Extents( 10u, 10u, 10u, 10u ) );
484 // By default, Aysnc loading is used
485 // loading is not started if the actor is offStage
487 Stage::GetCurrent().Add( imageView );
488 application.SendNotification();
489 application.Render(16);
490 application.Render(16);
491 application.SendNotification();
493 imageView.SetProperty( Dali::Actor::Property::LAYOUT_DIRECTION, Dali::LayoutDirection::RIGHT_TO_LEFT );
494 application.SendNotification();
495 application.Render(16);
496 application.Render(16);
497 application.SendNotification();
499 // loading started, this waits for the loader thread for max 30 seconds
500 DALI_TEST_EQUALS( Test::WaitForEventThreadTrigger( 1 ), true, TEST_LOCATION );
502 application.SendNotification();
503 application.Render(16);
505 callStack.Enable(false);
507 TraceCallStack::NamedParams params;
508 params["width"] = ToString(34);
509 params["height"] = ToString(34);
510 DALI_TEST_EQUALS( callStack.FindMethodAndParams( "TexSubImage2D", params ), true, TEST_LOCATION );
515 int UtcDaliImageViewAsyncLoadingWithAtlasing02(void)
517 ToolkitTestApplication application;
519 //Async loading, automatic atlasing for small size image
520 TraceCallStack& callStack = application.GetGlAbstraction().GetTextureTrace();
522 callStack.Enable(true);
524 Property::Map asyncLoadingMap;
525 asyncLoadingMap[ "url" ] = gImage_34_RGBA;
526 asyncLoadingMap[ "desiredHeight" ] = 34;
527 asyncLoadingMap[ "desiredWidth" ] = 34;
528 asyncLoadingMap[ "synchronousLoading" ] = false;
529 asyncLoadingMap[ "atlasing" ] = true;
531 ImageView imageView = ImageView::New();
532 imageView.SetProperty( ImageView::Property::IMAGE, asyncLoadingMap );
534 Stage::GetCurrent().Add( imageView );
535 application.SendNotification();
536 application.Render(16);
537 application.Render(16);
538 application.SendNotification();
540 // loading started, this waits for the loader thread for max 30 seconds
541 DALI_TEST_EQUALS( Test::WaitForEventThreadTrigger( 1 ), true, TEST_LOCATION );
543 application.SendNotification();
544 application.Render(16);
546 callStack.Enable(false);
548 TraceCallStack::NamedParams params;
549 params["width"] = ToString(34);
550 params["height"] = ToString(34);
551 DALI_TEST_EQUALS( callStack.FindMethodAndParams( "TexSubImage2D", params ), true, TEST_LOCATION );
556 int UtcDaliImageViewSyncLoading(void)
558 ToolkitTestApplication application;
560 tet_infoline("ImageView Testing sync loading and size using index key property map");
562 Property::Map syncLoadingMap;
563 syncLoadingMap[ ImageVisual::Property::SYNCHRONOUS_LOADING ] = true;
564 syncLoadingMap[ ImageVisual::Property::ATLASING ] = true;
566 // Sync loading, no atlasing for big size image
568 ImageView imageView = ImageView::New();
570 // Sync loading is used
571 syncLoadingMap[ ImageVisual::Property::URL ] = gImage_600_RGB;
572 imageView.SetProperty( ImageView::Property::IMAGE, syncLoadingMap );
575 // Sync loading, automatic atlasing for small size image
577 TraceCallStack& callStack = application.GetGlAbstraction().GetTextureTrace();
579 callStack.Enable(true);
581 ImageView imageView = ImageView::New( );
583 // Sync loading is used
584 syncLoadingMap[ ImageVisual::Property::URL ] = gImage_34_RGBA;
585 syncLoadingMap[ ImageVisual::Property::DESIRED_HEIGHT ] = 34;
586 syncLoadingMap[ ImageVisual::Property::DESIRED_WIDTH ] = 34;
587 imageView.SetProperty( ImageView::Property::IMAGE, syncLoadingMap );
589 Stage::GetCurrent().Add( imageView );
590 application.SendNotification();
591 application.Render(16);
593 TraceCallStack::NamedParams params;
594 params["width"] = ToString(34);
595 params["height"] = ToString(34);
596 DALI_TEST_EQUALS( callStack.FindMethodAndParams( "TexSubImage2D", params ),
597 true, TEST_LOCATION );
602 int UtcDaliImageViewSyncLoading02(void)
604 ToolkitTestApplication application;
606 tet_infoline("ImageView Testing sync loading and size using string key property map");
608 // Sync loading, automatic atlasing for small size image
610 TraceCallStack& callStack = application.GetGlAbstraction().GetTextureTrace();
612 callStack.Enable(true);
614 ImageView imageView = ImageView::New( );
616 // Sync loading is used
617 Property::Map syncLoadingMap;
618 syncLoadingMap[ "url" ] = gImage_34_RGBA;
619 syncLoadingMap[ "desiredHeight" ] = 34;
620 syncLoadingMap[ "desiredWidth" ] = 34;
621 syncLoadingMap[ "synchronousLoading" ] = true;
622 syncLoadingMap[ "atlasing" ] = true;
623 imageView.SetProperty( ImageView::Property::IMAGE, syncLoadingMap );
625 Stage::GetCurrent().Add( imageView );
626 application.SendNotification();
627 application.Render(16);
629 TraceCallStack::NamedParams params;
630 params["width"] = ToString(34);
631 params["height"] = ToString(34);
632 DALI_TEST_EQUALS( callStack.FindMethodAndParams( "TexSubImage2D", params ),
633 true, TEST_LOCATION );
638 int UtcDaliImageViewAddedTexture(void)
640 ToolkitTestApplication application;
642 tet_infoline("ImageView Testing image view with texture provided manager url");
644 ImageView imageView = ImageView::New();
646 // empty texture is ok, though pointless from app point of view
648 std::string url = TextureManager::AddTexture(empty);
649 DALI_TEST_CHECK(url.size() > 0u);
651 Property::Map propertyMap;
652 propertyMap[ImageVisual::Property::URL] = url;
653 imageView.SetProperty(ImageView::Property::IMAGE, propertyMap);
655 Stage::GetCurrent().Add( imageView );
656 application.SendNotification();
657 application.Render();
662 int UtcDaliImageViewSizeWithBackground(void)
664 ToolkitTestApplication application;
668 Image image = CreateBufferImage( width, height, Vector4(1.f, 1.f, 1.f, 1.f) );
669 ImageView imageView = ImageView::New();
670 imageView.SetBackgroundImage( image );
672 Stage::GetCurrent().Add( imageView );
673 application.SendNotification();
674 application.Render();
676 DALI_TEST_EQUALS( imageView.GetCurrentSize().width, (float)width, TEST_LOCATION );
677 DALI_TEST_EQUALS( imageView.GetCurrentSize().height, (float)height, TEST_LOCATION );
682 int UtcDaliImageViewSizeWithBackgroundAndImage(void)
684 ToolkitTestApplication application;
686 int widthBackground = 100;
687 int heightBackground = 200;
690 Image imageBackground = CreateBufferImage( widthBackground, heightBackground, Vector4(1.f, 1.f, 1.f, 1.f) );
691 Image image = CreateBufferImage( width, height, Vector4(1.f, 1.f, 1.f, 1.f) );
693 ImageView imageView = ImageView::New();
694 imageView.SetBackgroundImage( imageBackground );
695 imageView.SetImage( image );
697 Stage::GetCurrent().Add( imageView );
698 application.SendNotification();
699 application.Render();
701 DALI_TEST_EQUALS( imageView.GetCurrentSize().width, (float)width, TEST_LOCATION );
702 DALI_TEST_EQUALS( imageView.GetCurrentSize().height, (float)height, TEST_LOCATION );
707 int UtcDaliImageViewHeightForWidthBackground(void)
709 ToolkitTestApplication application;
711 int widthBackground = 100;
712 int heightBackground = 200;
713 Image imageBackground = CreateBufferImage( widthBackground, heightBackground, Vector4(1.f, 1.f, 1.f, 1.f) );
715 ImageView imageView = ImageView::New();
716 imageView.SetBackgroundImage( imageBackground );
718 Stage::GetCurrent().Add( imageView );
719 application.SendNotification();
720 application.Render();
722 Control control = Control::DownCast( imageView );
723 DALI_TEST_CHECK( control );
724 DALI_TEST_EQUALS( imageView.GetHeightForWidth( 123.f ), control.GetHeightForWidth( 123.f ), TEST_LOCATION );
725 DALI_TEST_EQUALS( imageView.GetWidthForHeight( 321.f ), control.GetWidthForHeight( 321.f ), TEST_LOCATION );
730 int UtcDaliImageViewHeightForWidthBackgroundAndImage(void)
732 ToolkitTestApplication application;
734 int widthBackground = 100;
735 int heightBackground = 200;
738 Image imageBackground = CreateBufferImage( widthBackground, heightBackground, Vector4(1.f, 1.f, 1.f, 1.f) );
739 Image image = CreateBufferImage( width, height, Vector4(1.f, 1.f, 1.f, 1.f) );
741 ImageView imageView = ImageView::New();
742 imageView.SetBackgroundImage( imageBackground );
743 imageView.SetImage( image );
745 Stage::GetCurrent().Add( imageView );
746 application.SendNotification();
747 application.Render();
749 DALI_TEST_EQUALS( imageView.GetHeightForWidth( width ), (float)height, TEST_LOCATION );
750 DALI_TEST_EQUALS( imageView.GetWidthForHeight( height ), (float)width, TEST_LOCATION );
755 int UtcDaliImageViewSetBufferImage(void)
757 ToolkitTestApplication application;
761 BufferImage image1 = CreateBufferImage( width1, height1, Vector4( 1.f, 1.f, 1.f, 1.f ) );
762 ImageView imageView = ImageView::New();
763 imageView.SetImage( image1 );
765 TestImage( imageView, image1 );
769 BufferImage image2 = CreateBufferImage( width2, height2, Vector4( 1.f, 1.f, 1.f, 1.f ) );
770 imageView.SetImage( image2 );
772 TestImage( imageView, image2 );
777 int UtcDaliImageViewSetImageUrl(void)
779 ToolkitTestApplication application;
781 ImageView imageView = ImageView::New();
782 imageView.SetImage( TEST_IMAGE_FILE_NAME );
783 TestUrl( imageView, TEST_IMAGE_FILE_NAME );
786 imageView.SetImage( TEST_IMAGE_FILE_NAME2 );
787 TestUrl( imageView, TEST_IMAGE_FILE_NAME2 );
792 int UtcDaliImageViewSetImageOnstageP(void)
794 ToolkitTestApplication application;
796 ImageView imageView = ImageView::New();
798 Stage::GetCurrent().Add( imageView );
799 application.SendNotification();
800 application.Render();
802 ResourceImage image1 = ResourceImage::New( TEST_IMAGE_FILE_NAME );
803 imageView.SetImage( image1 );
804 TestImage( imageView, image1 );
808 BufferImage image2 = CreateBufferImage( width, height, Vector4( 1.f, 1.f, 1.f, 1.f ) );
809 imageView.SetImage( image2 );
810 TestImage( imageView, image2 );
815 int UtcDaliImageViewSetImageOnstageN(void)
817 ToolkitTestApplication application;
819 ImageView imageView = ImageView::New();
821 Stage::GetCurrent().Add( imageView );
822 application.SendNotification();
823 application.Render();
825 ResourceImage image1 = ResourceImage::New( TEST_IMAGE_FILE_NAME );
826 imageView.SetImage( image1 );
827 TestImage( imageView, image1 );
830 imageView.SetImage( image2 );
832 Property::Value value = imageView.GetProperty( imageView.GetPropertyIndex( "image" ) );
834 //the value should be empty
836 DALI_TEST_CHECK( !value.Get( url ) );
839 DALI_TEST_CHECK( !value.Get( map ) );
844 int UtcDaliImageViewSetImageOffstageP(void)
846 ToolkitTestApplication application;
848 ImageView imageView = ImageView::New();
850 Stage::GetCurrent().Add( imageView );
851 application.SendNotification();
852 application.Render();
853 Stage::GetCurrent().Remove( imageView );
855 ResourceImage image1 = ResourceImage::New( TEST_IMAGE_FILE_NAME );
856 imageView.SetImage( image1 );
857 TestImage( imageView, image1 );
861 BufferImage image2 = CreateBufferImage( width, height, Vector4( 1.f, 1.f, 1.f, 1.f ) );
862 imageView.SetImage( image2 );
863 TestImage( imageView, image2 );
868 bool gResourceReadySignalFired = false;
869 Vector3 gNaturalSize;
871 void ResourceReadySignal( Control control )
873 gResourceReadySignalFired = true;
876 int UtcDaliImageViewCheckResourceReady(void)
878 ToolkitTestApplication application;
880 gResourceReadySignalFired = false;
885 Image image = CreateBufferImage( width, height, Vector4(1.f, 1.f, 1.f, 1.f) );
887 // Check ImageView with background and main image, to ensure both visuals are marked as loaded
888 ImageView imageView = ImageView::New( TEST_GIF_FILE_NAME );
890 imageView.SetBackgroundImage( image );
892 DALI_TEST_EQUALS( imageView.IsResourceReady(), false, TEST_LOCATION );
894 imageView.ResourceReadySignal().Connect( &ResourceReadySignal);
896 Stage::GetCurrent().Add( imageView );
898 application.SendNotification();
899 application.Render(16);
902 DALI_TEST_EQUALS( imageView.IsResourceReady(), true, TEST_LOCATION );
904 DALI_TEST_EQUALS( gResourceReadySignalFired, true, TEST_LOCATION );
909 int UtcDaliImageViewSetImageOffstageN(void)
911 ToolkitTestApplication application;
913 ImageView imageView = ImageView::New();
915 Stage::GetCurrent().Add( imageView );
916 application.SendNotification();
917 application.Render();
918 Stage::GetCurrent().Remove( imageView );
920 ResourceImage image1 = ResourceImage::New( TEST_IMAGE_FILE_NAME );
921 imageView.SetImage( image1 );
922 TestImage( imageView, image1 );
925 imageView.SetImage( image2 );
927 Property::Value value = imageView.GetProperty( imageView.GetPropertyIndex( "image" ) );
929 //the value should be empty
931 DALI_TEST_CHECK( !value.Get( url ) );
934 DALI_TEST_CHECK( !value.Get( map ) );
939 int UtcDaliImageViewSetImageN(void)
941 ToolkitTestApplication application;
944 ImageView imageView = ImageView::New();
945 imageView.SetImage( image1 );
947 Property::Value value = imageView.GetProperty( imageView.GetPropertyIndex( "image" ) );
949 //the value should be empty
951 DALI_TEST_CHECK( !value.Get( url ) );
954 DALI_TEST_CHECK( !value.Get( map ) );
956 std::string resource_url;
957 Property::Value val = imageView.GetProperty( imageView.GetPropertyIndex( "image" ) );
958 DALI_TEST_CHECK( !val.Get( resource_url ) );
963 int UtcDaliImageViewSetImageTypeChangesP(void)
965 ToolkitTestApplication application;
967 ImageView imageView = ImageView::New();
968 Toolkit::Internal::Control& controlImpl = Toolkit::Internal::GetImplementation( imageView );
970 Stage::GetCurrent().Add( imageView );
974 Toolkit::Visual::Base visual;
976 Property::Value value = imageView.GetProperty( imageView.GetPropertyIndex( "image" ) );
977 visual = DevelControl::GetVisual( controlImpl, ImageView::Property::IMAGE );
979 application.SendNotification();
980 application.Render( 16 );
982 DALI_TEST_CHECK( ! value.Get( url ) ); // Value should be empty
983 DALI_TEST_CHECK( ! value.Get( map ) ); // Value should be empty
984 DALI_TEST_CHECK( ! visual ); // Visual should be invalid
987 imageView.SetImage( "TEST_URL" );
989 application.SendNotification();
990 application.Render( 16 );
992 value = imageView.GetProperty( imageView.GetPropertyIndex( "image" ) );
993 visual = DevelControl::GetVisual( controlImpl, ImageView::Property::IMAGE );
995 DALI_TEST_CHECK( value.Get( url ) ); // Value should NOT be empty
996 DALI_TEST_CHECK( ! value.Get( map ) ); // Value should be empty
997 DALI_TEST_CHECK( visual ); // Visual should be valid
999 // Set an empty Image
1000 imageView.SetImage( Image() );
1002 application.SendNotification();
1003 application.Render( 16 );
1005 value = imageView.GetProperty( imageView.GetPropertyIndex( "image" ) );
1006 visual = DevelControl::GetVisual( controlImpl, ImageView::Property::IMAGE );
1008 DALI_TEST_CHECK( ! value.Get( url ) ); // Value should be empty
1009 DALI_TEST_CHECK( ! value.Get( map ) ); // Value should be empty
1010 DALI_TEST_CHECK( ! visual ); // Visual should be invalid
1013 ResourceImage image1 = ResourceImage::New( TEST_IMAGE_FILE_NAME );
1014 imageView.SetImage( image1 );
1016 application.SendNotification();
1017 application.Render( 16 );
1019 value = imageView.GetProperty( imageView.GetPropertyIndex( "image" ) );
1020 visual = DevelControl::GetVisual( controlImpl, ImageView::Property::IMAGE );
1022 DALI_TEST_CHECK( ! value.Get( url ) ); // Value should be empty
1023 DALI_TEST_CHECK( value.Get( map ) ); // Value should NOT be empty
1024 DALI_TEST_CHECK( visual ); // Visual should be valid
1027 imageView.SetImage( "" );
1029 application.SendNotification();
1030 application.Render( 16 );
1032 value = imageView.GetProperty( imageView.GetPropertyIndex( "image" ) );
1033 visual = DevelControl::GetVisual( controlImpl, ImageView::Property::IMAGE );
1035 DALI_TEST_CHECK( ! value.Get( url ) ); // Value should be empty
1036 DALI_TEST_CHECK( ! value.Get( map ) ); // Value should be empty
1037 DALI_TEST_CHECK( ! visual ); // Visual should be invalid
1039 // Set a URL in property map
1040 Property::Map propertyMap;
1041 propertyMap[ImageVisual::Property::URL] = TEST_IMAGE_FILE_NAME;
1042 imageView.SetProperty( ImageView::Property::IMAGE, propertyMap );
1044 application.SendNotification();
1045 application.Render( 16 );
1047 value = imageView.GetProperty( imageView.GetPropertyIndex( "image" ) );
1048 visual = DevelControl::GetVisual( controlImpl, ImageView::Property::IMAGE );
1050 DALI_TEST_CHECK( ! value.Get( url ) ); // Value should be empty
1051 DALI_TEST_CHECK( value.Get( map ) ); // Value should NOT be empty
1052 DALI_TEST_CHECK( visual ); // Visual should be valid
1054 // Set a URL in property map again
1055 propertyMap[ImageVisual::Property::URL] = gImage_34_RGBA;
1056 imageView.SetProperty( ImageView::Property::IMAGE, propertyMap );
1058 application.SendNotification();
1059 application.Render( 16 );
1061 value = imageView.GetProperty( imageView.GetPropertyIndex( "image" ) );
1062 visual = DevelControl::GetVisual( controlImpl, ImageView::Property::IMAGE );
1064 DALI_TEST_CHECK( ! value.Get( url ) ); // Value should be empty
1065 DALI_TEST_CHECK( value.Get( map ) ); // Value should NOT be empty
1066 DALI_TEST_CHECK( visual ); // Visual should be valid
1068 // Set an empty URL in property map
1069 propertyMap[ImageVisual::Property::URL] = std::string();
1070 imageView.SetProperty( ImageView::Property::IMAGE, propertyMap );
1072 application.SendNotification();
1073 application.Render( 16 );
1075 value = imageView.GetProperty( imageView.GetPropertyIndex( "image" ) );
1076 visual = DevelControl::GetVisual( controlImpl, ImageView::Property::IMAGE );
1078 DALI_TEST_CHECK( ! value.Get( url ) ); // Value should be empty
1079 DALI_TEST_CHECK( value.Get( map ) ); // Value should NOT be empty
1080 DALI_TEST_CHECK( ! visual ); // Visual should be invalid
1085 int UtcDaliImageViewResourceUrlP(void)
1087 ToolkitTestApplication application;
1089 ImageView imageView = ImageView::New();
1090 DALI_TEST_CHECK( imageView.GetProperty( ImageView::Property::RESOURCE_URL ).Get< std::string >().empty() );
1092 imageView.SetProperty( ImageView::Property::RESOURCE_URL, "TestString" );
1093 DALI_TEST_EQUALS( imageView.GetProperty( ImageView::Property::RESOURCE_URL ).Get< std::string >(), "TestString", TEST_LOCATION );
1098 // Scenarios 1: ImageView from regular image
1099 int UtcDaliImageViewSetImageBufferImage(void)
1101 ToolkitTestApplication application;
1103 ImageView imageView = ImageView::New();
1104 Stage::GetCurrent().Add( imageView );
1106 TestGlAbstraction& gl = application.GetGlAbstraction();
1107 gl.EnableTextureCallTrace( true );
1109 std::vector< GLuint > ids;
1110 ids.push_back( 23 );
1111 application.GetGlAbstraction().SetNextTextureIds( ids );
1115 BufferImage image = CreateBufferImage( width, height, Color::WHITE );
1117 imageView.SetImage( image );
1119 application.SendNotification();
1120 application.Render();
1122 DALI_TEST_CHECK( gl.GetTextureTrace().FindMethod("BindTexture") );
1124 std::stringstream params;
1125 params << GL_TEXTURE_2D << ", " << 23;
1126 DALI_TEST_CHECK( gl.GetTextureTrace().FindMethodAndParams("BindTexture", params.str()) );
1131 // Scenarios 2: ImageView from Native image
1132 int UtcDaliImageViewSetImageNativeImage(void)
1134 ToolkitTestApplication application;
1136 ImageView imageView = ImageView::New();
1137 Stage::GetCurrent().Add( imageView );
1139 TestGlAbstraction& gl = application.GetGlAbstraction();
1140 gl.EnableTextureCallTrace( true );
1142 std::vector< GLuint > ids;
1143 ids.push_back( 23 );
1144 application.GetGlAbstraction().SetNextTextureIds( ids );
1148 TestNativeImagePointer nativeImageInterface = TestNativeImage::New( width, height );
1149 NativeImage nativeImage = NativeImage::New( *(nativeImageInterface.Get()) );
1151 imageView.SetImage( nativeImage );
1152 application.SendNotification();
1153 application.Render();
1155 DALI_TEST_CHECK( gl.GetTextureTrace().FindMethod("BindTexture") );
1157 std::stringstream params;
1158 params << GL_TEXTURE_EXTERNAL_OES << ", " << 23;
1159 DALI_TEST_CHECK( gl.GetTextureTrace().FindMethodAndParams("BindTexture", params.str()) );
1164 // Scenarios 3: ImageView initially from regular image but then SetImage called with Native image
1165 int UtcDaliImageViewSetImageBufferImageToNativeImage(void)
1167 ToolkitTestApplication application;
1171 BufferImage image = CreateBufferImage( width, height, Color::WHITE );
1173 ImageView imageView = ImageView::New( image );
1174 Stage::GetCurrent().Add( imageView );
1176 TestGlAbstraction& gl = application.GetGlAbstraction();
1177 gl.EnableTextureCallTrace( true );
1179 std::vector< GLuint > ids;
1180 ids.push_back( 23 );
1181 application.GetGlAbstraction().SetNextTextureIds( ids );
1183 application.SendNotification();
1184 application.Render();
1186 DALI_TEST_CHECK( gl.GetTextureTrace().FindMethod("BindTexture") );
1188 std::stringstream params;
1189 params << GL_TEXTURE_2D << ", " << 23;
1190 DALI_TEST_CHECK( gl.GetTextureTrace().FindMethodAndParams("BindTexture", params.str()) );
1194 TestNativeImagePointer nativeImageInterface = TestNativeImage::New( width, height );
1195 NativeImage nativeImage = NativeImage::New( *(nativeImageInterface.Get()) );
1196 imageView.SetImage( nativeImage );
1199 ids.push_back( 24 );
1200 application.GetGlAbstraction().SetNextTextureIds( ids );
1202 application.SendNotification();
1203 application.Render();
1205 DALI_TEST_CHECK( gl.GetTextureTrace().FindMethod("BindTexture") );
1207 std::stringstream nextTextureParams;
1208 nextTextureParams << GL_TEXTURE_EXTERNAL_OES << ", " << 24;
1209 DALI_TEST_CHECK( gl.GetTextureTrace().FindMethodAndParams("BindTexture", nextTextureParams.str()) );
1214 // Scenarios 4: ImageView initially from Native image but then SetImage called with regular image
1215 int UtcDaliImageViewSetImageNativeImageToBufferImage(void)
1217 ToolkitTestApplication application;
1221 TestNativeImagePointer nativeImageInterface = TestNativeImage::New( width, height );
1222 NativeImage nativeImage = NativeImage::New( *(nativeImageInterface.Get()) );
1224 ImageView imageView = ImageView::New( nativeImage );
1225 Stage::GetCurrent().Add( imageView );
1227 TestGlAbstraction& gl = application.GetGlAbstraction();
1228 gl.EnableTextureCallTrace( true );
1230 std::vector< GLuint > ids;
1231 ids.push_back( 23 );
1232 application.GetGlAbstraction().SetNextTextureIds( ids );
1234 application.SendNotification();
1235 application.Render();
1237 DALI_TEST_CHECK( gl.GetTextureTrace().FindMethod("BindTexture") );
1239 std::stringstream params;
1240 params << GL_TEXTURE_EXTERNAL_OES << ", " << 23;
1241 DALI_TEST_CHECK( gl.GetTextureTrace().FindMethodAndParams("BindTexture", params.str()) );
1245 BufferImage image = CreateBufferImage( width, height, Color::WHITE );
1246 imageView.SetImage( image );
1249 ids.push_back( 24 );
1250 application.GetGlAbstraction().SetNextTextureIds( ids );
1252 application.SendNotification();
1253 application.Render();
1255 DALI_TEST_CHECK( gl.GetTextureTrace().FindMethod("BindTexture") );
1257 std::stringstream nextTextureParams;
1258 nextTextureParams << GL_TEXTURE_2D << ", " << 24;
1259 DALI_TEST_CHECK( gl.GetTextureTrace().FindMethodAndParams("BindTexture", nextTextureParams.str()) );
1264 // Scenarios 5: ImageView from Native image with custom shader
1265 int UtcDaliImageViewSetImageNativeImageWithCustomShader(void)
1267 ToolkitTestApplication application;
1272 Property::Map customShader;
1273 customShader.Insert( "vertexShader", VERTEX_SHADER );
1274 customShader.Insert( "fragmentShader", FRAGMENT_SHADER );
1276 Property::Array shaderHints;
1277 shaderHints.PushBack( "requiresSelfDepthTest" );
1278 shaderHints.PushBack( "outputIsTransparent" );
1279 shaderHints.PushBack( "outputIsOpaque" );
1280 shaderHints.PushBack( "modifiesGeometry" );
1282 customShader.Insert( "hints", shaderHints );
1285 map.Insert( "shader", customShader );
1287 TestNativeImagePointer nativeImageInterface = TestNativeImage::New( width, height );
1288 NativeImage nativeImage = NativeImage::New( *(nativeImageInterface.Get()) );
1290 ImageView imageView = ImageView::New( nativeImage );
1291 imageView.SetProperty( ImageView::Property::IMAGE, map );
1292 Stage::GetCurrent().Add( imageView );
1294 TestGlAbstraction& gl = application.GetGlAbstraction();
1295 gl.EnableTextureCallTrace( true );
1297 std::vector< GLuint > ids;
1298 ids.push_back( 23 );
1299 application.GetGlAbstraction().SetNextTextureIds( ids );
1301 application.SendNotification();
1302 application.Render();
1304 DALI_TEST_CHECK( gl.GetTextureTrace().FindMethod("BindTexture") );
1306 std::stringstream params;
1307 params << GL_TEXTURE_EXTERNAL_OES << ", " << 23;
1308 DALI_TEST_CHECK( gl.GetTextureTrace().FindMethodAndParams("BindTexture", params.str()) );
1313 // Scenarios 6: ImageView initially from regular image with custom shader but then SetImage called with Native
1314 int UtcDaliImageViewSetImageBufferImageWithCustomShaderToNativeImage(void)
1316 ToolkitTestApplication application;
1321 Property::Map customShader;
1322 customShader.Insert( "vertexShader", VERTEX_SHADER );
1323 customShader.Insert( "fragmentShader", FRAGMENT_SHADER );
1325 Property::Array shaderHints;
1326 shaderHints.PushBack( "requiresSelfDepthTest" );
1327 shaderHints.PushBack( "outputIsTransparent" );
1328 shaderHints.PushBack( "outputIsOpaque" );
1329 shaderHints.PushBack( "modifiesGeometry" );
1331 customShader.Insert( "hints", shaderHints );
1334 map.Insert( "shader", customShader );
1336 BufferImage image = CreateBufferImage( width, height, Color::WHITE );
1338 ImageView imageView = ImageView::New( image );
1339 imageView.SetProperty( ImageView::Property::IMAGE, map );
1340 Stage::GetCurrent().Add( imageView );
1342 TestGlAbstraction& gl = application.GetGlAbstraction();
1343 gl.EnableTextureCallTrace( true );
1345 std::vector< GLuint > ids;
1346 ids.push_back( 23 );
1347 application.GetGlAbstraction().SetNextTextureIds( ids );
1349 application.SendNotification();
1350 application.Render();
1352 DALI_TEST_CHECK( gl.GetTextureTrace().FindMethod("BindTexture") );
1354 std::stringstream params;
1355 params << GL_TEXTURE_2D << ", " << 23;
1356 DALI_TEST_CHECK( gl.GetTextureTrace().FindMethodAndParams("BindTexture", params.str()) );
1358 TestNativeImagePointer nativeImageInterface = TestNativeImage::New( width, height );
1359 NativeImage nativeImage = NativeImage::New( *(nativeImageInterface.Get()) );
1360 imageView.SetImage( nativeImage );
1363 ids.push_back( 24 );
1364 application.GetGlAbstraction().SetNextTextureIds( ids );
1366 application.SendNotification();
1367 application.Render();
1369 DALI_TEST_CHECK( gl.GetTextureTrace().FindMethod("BindTexture") );
1371 std::stringstream nativeImageParams;
1372 nativeImageParams << GL_TEXTURE_EXTERNAL_OES << ", " << 24;
1373 DALI_TEST_CHECK( gl.GetTextureTrace().FindMethodAndParams("BindTexture", nativeImageParams.str()) );
1379 int UtcDaliImageViewGetImageP1(void)
1381 ToolkitTestApplication application;
1383 ImageView imageView = ImageView::New();
1384 DALI_TEST_CHECK( ! imageView.GetImage() );
1386 Image image = CreateBufferImage();
1387 imageView.SetImage( image );
1388 DALI_TEST_CHECK( imageView.GetImage() == image );
1393 int UtcDaliImageViewGetImageP2(void)
1395 ToolkitTestApplication application;
1397 BufferImage image = CreateBufferImage();
1398 ImageView imageView = ImageView::New( image );
1399 DALI_TEST_CHECK( imageView.GetImage() == image );
1404 int UtcDaliImageViewGetImageN(void)
1406 ToolkitTestApplication application;
1408 ImageView imageView = ImageView::New( TEST_IMAGE_FILE_NAME );
1409 DALI_TEST_CHECK( ! imageView.GetImage() );
1411 Image image = CreateBufferImage();
1412 imageView.SetImage( image );
1413 DALI_TEST_CHECK( imageView.GetImage() == image );
1415 imageView.SetImage( TEST_IMAGE_FILE_NAME );
1416 DALI_TEST_CHECK( ! imageView.GetImage() );
1422 int UtcDaliImageViewReplaceImage(void)
1424 ToolkitTestApplication application;
1426 gResourceReadySignalFired = false;
1430 Image image = CreateBufferImage( width, height, Vector4(1.f, 1.f, 1.f, 1.f) );
1432 // Check ImageView with background and main image, to ensure both visuals are marked as loaded
1433 ImageView imageView = ImageView::New( TEST_IMAGE_1 );
1435 DALI_TEST_EQUALS( imageView.IsResourceReady(), false, TEST_LOCATION );
1437 imageView.ResourceReadySignal().Connect( &ResourceReadySignal);
1439 Stage::GetCurrent().Add( imageView );
1441 application.SendNotification();
1442 application.Render(16);
1444 // loading started, this waits for the loader thread for max 30 seconds
1445 DALI_TEST_EQUALS( Test::WaitForEventThreadTrigger( 1 ), true, TEST_LOCATION );
1447 DALI_TEST_EQUALS( imageView.GetRendererCount(), 1u, TEST_LOCATION );
1449 DALI_TEST_EQUALS( gResourceReadySignalFired, true, TEST_LOCATION );
1451 gResourceReadySignalFired = false;
1453 imageView.SetImage(TEST_IMAGE_2);
1455 application.SendNotification();
1456 application.Render(16);
1458 // loading started, this waits for the loader thread for max 30 seconds
1459 DALI_TEST_EQUALS( Test::WaitForEventThreadTrigger( 1 ), true, TEST_LOCATION );
1461 DALI_TEST_EQUALS( imageView.GetRendererCount(), 1u, TEST_LOCATION );
1463 DALI_TEST_EQUALS( imageView.IsResourceReady(), true, TEST_LOCATION );
1465 DALI_TEST_EQUALS( gResourceReadySignalFired, true, TEST_LOCATION );
1470 void OnRelayoutOverride( Size size )
1472 gNaturalSize = size; // Size Relayout is using
1475 int UtcDaliImageViewReplaceImageAndGetNaturalSize(void)
1477 ToolkitTestApplication application;
1479 // Check ImageView with background and main image, to ensure both visuals are marked as loaded
1480 ImageView imageView = ImageView::New( TEST_IMAGE_1 );
1481 imageView.SetResizePolicy( ResizePolicy::USE_NATURAL_SIZE, Dimension::ALL_DIMENSIONS );
1483 DummyControl dummyControl = DummyControl::New( true );
1484 Impl::DummyControl& dummyImpl = static_cast<Impl::DummyControl&>(dummyControl.GetImplementation());
1485 dummyControl.SetResizePolicy( ResizePolicy::FIT_TO_CHILDREN, Dimension::ALL_DIMENSIONS );
1487 dummyControl.Add( imageView );
1488 dummyImpl.SetRelayoutCallback( &OnRelayoutOverride );
1489 Stage::GetCurrent().Add( dummyControl );
1491 application.SendNotification();
1492 application.Render();
1494 // loading started, this waits for the loader thread for max 30 seconds
1495 DALI_TEST_EQUALS( Test::WaitForEventThreadTrigger( 1 ), true, TEST_LOCATION );
1497 DALI_TEST_EQUALS( gNaturalSize.width, 1024.0f, TEST_LOCATION );
1498 DALI_TEST_EQUALS( gNaturalSize.height, 1024.0f, TEST_LOCATION );
1500 gNaturalSize = Vector3::ZERO;
1502 imageView.SetImage(gImage_600_RGB);
1504 // Waiting for resourceReady so SendNotifcation not called here.
1506 // loading started, this waits for the loader thread for max 30 seconds
1507 DALI_TEST_EQUALS( Test::WaitForEventThreadTrigger( 1 ), true, TEST_LOCATION );
1509 // Trigger a potential relayout
1510 application.SendNotification();
1511 application.Render();
1513 DALI_TEST_EQUALS( gNaturalSize.width, 600.0f, TEST_LOCATION );
1514 DALI_TEST_EQUALS( gNaturalSize.height, 600.0f, TEST_LOCATION );
1519 int UtcDaliImageViewResourceReadySignalWithImmediateLoad(void)
1521 tet_infoline("Test Setting Image with IMMEDIATE load and receving ResourceReadySignal before staged.");
1523 ToolkitTestApplication application;
1525 gResourceReadySignalFired = false;
1527 Property::Map imageMap;
1529 imageMap[ ImageVisual::Property::URL ] = gImage_34_RGBA;
1530 imageMap[ ImageVisual::Property::LOAD_POLICY ] = ImageVisual::LoadPolicy::IMMEDIATE;
1532 tet_infoline("Creating ImageView without URL so image does not start loading");
1533 ImageView imageView = ImageView::New();
1534 tet_infoline("Connect to image loaded signal before setting image");
1535 imageView.ResourceReadySignal().Connect( &ResourceReadySignal);
1536 tet_infoline("Setting Image with IMMEDIATE load, signal already connected so will be triggered.");
1537 imageView.SetProperty( ImageView::Property::IMAGE, imageMap );
1539 // loading started, this waits for the loader thread
1540 DALI_TEST_EQUALS( Test::WaitForEventThreadTrigger( 1 ), true, TEST_LOCATION );
1542 application.SendNotification();
1543 application.Render(16);
1545 DALI_TEST_EQUALS( gResourceReadySignalFired, true, TEST_LOCATION );
1550 int UtcDaliImageViewResourceReadySignalWithReusedImage(void)
1552 tet_infoline("Test Setting Image that was already loaded by another ImageView and still getting ResourceReadySignal.");
1554 ToolkitTestApplication application;
1556 gResourceReadySignalFired = false;
1558 Property::Map imageMap;
1560 imageMap[ ImageVisual::Property::URL ] = gImage_34_RGBA;
1561 imageMap[ ImageVisual::Property::LOAD_POLICY ] = ImageVisual::LoadPolicy::IMMEDIATE;
1563 ImageView imageView = ImageView::New();
1564 imageView.ResourceReadySignal().Connect( &ResourceReadySignal);
1565 imageView.SetProperty( ImageView::Property::IMAGE, imageMap );
1567 // loading started, this waits for the loader thread
1568 DALI_TEST_EQUALS( Test::WaitForEventThreadTrigger( 1 ), true, TEST_LOCATION );
1570 application.SendNotification();
1571 application.Render(16);
1573 DALI_TEST_EQUALS( gResourceReadySignalFired, true, TEST_LOCATION );
1574 gResourceReadySignalFired = false;
1576 ImageView imageViewWithExistingImage = ImageView::New();
1577 imageViewWithExistingImage.ResourceReadySignal().Connect( &ResourceReadySignal);
1578 imageViewWithExistingImage.SetProperty( ImageView::Property::IMAGE, imageMap );
1580 DALI_TEST_EQUALS( gResourceReadySignalFired, true, TEST_LOCATION );
1585 int UtcDaliImageViewResourceReadySignalWithReusedImage02(void)
1587 tet_infoline("Test Setting Image that was already loaded by another ImageView and still getting ResourceReadySignal when staged.");
1589 ToolkitTestApplication application;
1591 gResourceReadySignalFired = false;
1593 Property::Map imageImmediateLoadingMap;
1594 imageImmediateLoadingMap[ ImageVisual::Property::URL ] = gImage_34_RGBA;
1595 imageImmediateLoadingMap[ ImageVisual::Property::LOAD_POLICY ] = ImageVisual::LoadPolicy::IMMEDIATE;
1597 tet_infoline("Immediate load an image");
1598 ImageView imageView = ImageView::New();
1599 imageView.ResourceReadySignal().Connect( &ResourceReadySignal);
1600 imageView.SetProperty( ImageView::Property::IMAGE, imageImmediateLoadingMap );
1602 // loading started, this waits for the loader thread
1603 DALI_TEST_EQUALS( Test::WaitForEventThreadTrigger( 1 ), true, TEST_LOCATION );
1605 application.SendNotification();
1606 application.Render(16);
1608 tet_infoline("Check image loaded");
1609 DALI_TEST_EQUALS( gResourceReadySignalFired, true, TEST_LOCATION );
1610 gResourceReadySignalFired = false;
1612 tet_infoline("Create another ImageView with the same URL");
1613 ImageView imageViewWithExistingImage = ImageView::New( gImage_34_RGBA );
1614 tet_infoline("Connect to ResourceReady signal for second ImageView, it should still fire as resource is ready");
1615 imageViewWithExistingImage.ResourceReadySignal().Connect( &ResourceReadySignal);
1617 Stage::GetCurrent().Add( imageViewWithExistingImage );
1619 DALI_TEST_EQUALS( gResourceReadySignalFired, true, TEST_LOCATION );
1624 int UtcDaliImageViewPaddingProperty(void)
1626 ToolkitTestApplication application;
1628 ImageView imageView = ImageView::New();
1629 Property::Map imagePropertyMap;
1630 imagePropertyMap[ Toolkit::Visual::Property::TYPE ] = Toolkit::Visual::IMAGE;
1631 imagePropertyMap[ Toolkit::ImageVisual::Property::URL ] = TEST_RESOURCE_DIR "/gallery-small-1.jpg" ;
1632 imagePropertyMap[ ImageVisual::Property::DESIRED_WIDTH ] = 128;
1633 imagePropertyMap[ ImageVisual::Property::DESIRED_HEIGHT ] = 128;
1634 imageView.SetProperty( Toolkit::ImageView::Property::IMAGE , imagePropertyMap );
1635 imageView.SetAnchorPoint( AnchorPoint::TOP_LEFT );
1636 imageView.SetParentOrigin( ParentOrigin::TOP_LEFT );
1637 imageView.SetProperty( Control::Property::PADDING, Extents( 15, 10, 5, 10 ) );
1638 Stage::GetCurrent().Add( imageView );
1640 application.SendNotification();
1641 application.Render();
1643 DALI_TEST_EQUALS( imageView.GetProperty<Extents>( Control::Property::PADDING ), Extents( 15, 10, 5, 10 ), TEST_LOCATION );
1645 ImageView childImage = ImageView::New();
1646 childImage.SetBackgroundColor( Color::BLACK );
1647 childImage.SetSize( 10.f, 10.f );
1648 imageView.Add( childImage );
1650 application.SendNotification();
1651 application.Render();
1653 // Child ImageView should be positioned dependinig on Parent ImageView's Padding value
1654 DALI_TEST_EQUALS( childImage.GetProperty<Vector3>( Dali::Actor::Property::POSITION ), Vector3( 15, 5, 0 ), TEST_LOCATION );
1656 // Check whether Image Visual transforms on ImageVieiw::OnRelayout()
1657 Toolkit::Internal::Control& controlImpl = Toolkit::Internal::GetImplementation( imageView );
1658 Toolkit::Visual::Base imageVisual = DevelControl::GetVisual( controlImpl, ImageView::Property::IMAGE );
1659 Property::Map resultMap;
1660 imageVisual.CreatePropertyMap( resultMap );
1662 Property::Value* transformValue = resultMap.Find( Visual::Property::TRANSFORM );
1663 DALI_TEST_CHECK( transformValue );
1664 Property::Map* retMap = transformValue->GetMap();
1665 DALI_TEST_CHECK( retMap );
1667 // Image Visual should be positioned depending on ImageView's padding
1668 DALI_TEST_EQUALS( retMap->Find( Visual::Transform::Property::OFFSET )->Get< Vector2 >(), Vector2( 15, 5 ), TEST_LOCATION );
1673 int UtcDaliImageViewPaddingProperty02(void)
1675 ToolkitTestApplication application;
1677 ImageView imageView = ImageView::New();
1678 Property::Map imagePropertyMap;
1679 imagePropertyMap[ Toolkit::Visual::Property::TYPE ] = Toolkit::Visual::IMAGE;
1680 imagePropertyMap[ Toolkit::ImageVisual::Property::URL ] = TEST_RESOURCE_DIR "/Kid1.svg" ;
1681 imagePropertyMap[ ImageVisual::Property::DESIRED_WIDTH ] = 128;
1682 imagePropertyMap[ ImageVisual::Property::DESIRED_HEIGHT ] = 128;
1683 imagePropertyMap[ DevelVisual::Property::VISUAL_FITTING_MODE ] = Toolkit::DevelVisual::FIT_KEEP_ASPECT_RATIO;
1684 imageView.SetProperty( Toolkit::ImageView::Property::IMAGE , imagePropertyMap );
1685 imageView.SetAnchorPoint( AnchorPoint::TOP_LEFT );
1686 imageView.SetParentOrigin( ParentOrigin::TOP_LEFT );
1687 imageView.SetProperty( Control::Property::PADDING, Extents( 15, 10, 5, 10 ) );
1688 Stage::GetCurrent().Add( imageView );
1690 application.SendNotification();
1691 application.Render();
1693 DALI_TEST_EQUALS( imageView.GetProperty<Extents>( Control::Property::PADDING ), Extents( 15, 10, 5, 10 ), TEST_LOCATION );
1695 // Check whether Image Visual transforms on ImageVieiw::OnRelayout()
1696 Toolkit::Internal::Control& controlImpl = Toolkit::Internal::GetImplementation( imageView );
1697 Toolkit::Visual::Base imageVisual = DevelControl::GetVisual( controlImpl, ImageView::Property::IMAGE );
1698 Property::Map resultMap;
1699 imageVisual.CreatePropertyMap( resultMap );
1701 Property::Value* transformValue = resultMap.Find( Visual::Property::TRANSFORM );
1702 DALI_TEST_CHECK( transformValue );
1703 Property::Map* retMap = transformValue->GetMap();
1704 DALI_TEST_CHECK( retMap );
1706 // Image Visual should be positioned depending on ImageView's padding
1707 DALI_TEST_EQUALS( retMap->Find( Visual::Transform::Property::OFFSET )->Get< Vector2 >(), Vector2( 15, 5 ), TEST_LOCATION );
1712 int UtcDaliImageViewUsingAtlasAndGetNaturalSize(void)
1714 ToolkitTestApplication application;
1716 // Check ImageView with background and main image, to ensure both visuals are marked as loaded
1717 ImageView imageView = ImageView::New();
1718 Property::Map imageMap;
1719 imageMap[ Toolkit::Visual::Property::TYPE ] = Toolkit::Visual::IMAGE;
1720 imageMap[ Toolkit::ImageVisual::Property::URL ] = gImage_34_RGBA;
1721 imageMap[ Toolkit::ImageVisual::Property::ATLASING ] = true;
1722 imageView.SetProperty( Toolkit::ImageView::Property::IMAGE, imageMap );
1723 Stage::GetCurrent().Add( imageView );
1725 // Trigger a potential relayout
1726 application.SendNotification();
1727 application.Render();
1729 Vector3 naturalSize = imageView.GetNaturalSize();
1731 DALI_TEST_EQUALS( naturalSize.width, 34.0f, TEST_LOCATION );
1732 DALI_TEST_EQUALS( naturalSize.height, 34.0f, TEST_LOCATION );
1737 int UtcDaliImageViewFillMode(void)
1739 ToolkitTestApplication application;
1741 tet_infoline( "Create an ImageVisual without padding and set the fill-mode to fill" );
1742 tet_infoline( " There should be no need to change the transform, our size-policy should be relative and size shoudl be [1,1]");
1744 ImageView imageView = ImageView::New();
1745 Property::Map imageMap;
1746 imageMap.Add( Toolkit::Visual::Property::TYPE, Toolkit::Visual::IMAGE );
1747 imageMap.Add( Toolkit::ImageVisual::Property::URL, gImage_600_RGB );
1748 imageMap.Add( DevelVisual::Property::VISUAL_FITTING_MODE, DevelVisual::FittingMode::FILL );
1750 imageView.SetProperty( Toolkit::ImageView::Property::IMAGE, imageMap );
1752 Stage::GetCurrent().Add( imageView );
1754 // Trigger a potential relayout
1755 application.SendNotification();
1756 application.Render();
1758 Toolkit::Visual::Base visual = DevelControl::GetVisual( Toolkit::Internal::GetImplementation( imageView ), Toolkit::ImageView::Property::IMAGE );
1759 Property::Map returnedMap;
1760 visual.CreatePropertyMap( returnedMap );
1762 Property::Value* value = returnedMap.Find( Toolkit::Visual::Property::TRANSFORM );
1763 DALI_TEST_CHECK( value );
1764 Property::Map* map = value->GetMap();
1765 DALI_TEST_CHECK( map );
1768 value = map->Find( Toolkit::Visual::Transform::Property::SIZE );
1769 DALI_TEST_CHECK( value );
1770 DALI_TEST_EQUALS( value->Get< Vector2 >(), Vector2::ONE, TEST_LOCATION ); // Relative size so will take up 100%
1772 value = map->Find( Toolkit::Visual::Transform::Property::SIZE_POLICY );
1773 DALI_TEST_CHECK( value );
1774 DALI_TEST_CHECK( value->Get< int >() == Toolkit::Visual::Transform::Policy::RELATIVE );