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 ) );
840 DALI_TEST_CHECK( map.Empty() );
845 int UtcDaliImageViewSetImageOffstageP(void)
847 ToolkitTestApplication application;
849 ImageView imageView = ImageView::New();
851 Stage::GetCurrent().Add( imageView );
852 application.SendNotification();
853 application.Render();
854 Stage::GetCurrent().Remove( imageView );
856 ResourceImage image1 = ResourceImage::New( TEST_IMAGE_FILE_NAME );
857 imageView.SetImage( image1 );
858 TestImage( imageView, image1 );
862 BufferImage image2 = CreateBufferImage( width, height, Vector4( 1.f, 1.f, 1.f, 1.f ) );
863 imageView.SetImage( image2 );
864 TestImage( imageView, image2 );
869 bool gResourceReadySignalFired = false;
870 Vector3 gNaturalSize;
872 void ResourceReadySignal( Control control )
874 gResourceReadySignalFired = true;
877 int UtcDaliImageViewCheckResourceReady(void)
879 ToolkitTestApplication application;
881 gResourceReadySignalFired = false;
886 Image image = CreateBufferImage( width, height, Vector4(1.f, 1.f, 1.f, 1.f) );
888 // Check ImageView with background and main image, to ensure both visuals are marked as loaded
889 ImageView imageView = ImageView::New( TEST_GIF_FILE_NAME );
891 imageView.SetBackgroundImage( image );
893 DALI_TEST_EQUALS( imageView.IsResourceReady(), false, TEST_LOCATION );
895 imageView.ResourceReadySignal().Connect( &ResourceReadySignal);
897 Stage::GetCurrent().Add( imageView );
899 application.SendNotification();
900 application.Render(16);
903 DALI_TEST_EQUALS( imageView.IsResourceReady(), true, TEST_LOCATION );
905 DALI_TEST_EQUALS( gResourceReadySignalFired, true, TEST_LOCATION );
910 int UtcDaliImageViewSetImageOffstageN(void)
912 ToolkitTestApplication application;
914 ImageView imageView = ImageView::New();
916 Stage::GetCurrent().Add( imageView );
917 application.SendNotification();
918 application.Render();
919 Stage::GetCurrent().Remove( imageView );
921 ResourceImage image1 = ResourceImage::New( TEST_IMAGE_FILE_NAME );
922 imageView.SetImage( image1 );
923 TestImage( imageView, image1 );
926 imageView.SetImage( image2 );
928 Property::Value value = imageView.GetProperty( imageView.GetPropertyIndex( "image" ) );
930 //the value should be empty
932 DALI_TEST_CHECK( !value.Get( url ) );
936 DALI_TEST_CHECK( map.Empty() );
941 int UtcDaliImageViewSetImageN(void)
943 ToolkitTestApplication application;
946 ImageView imageView = ImageView::New();
947 imageView.SetImage( image1 );
949 Property::Value value = imageView.GetProperty( imageView.GetPropertyIndex( "image" ) );
951 //the value should be empty
953 DALI_TEST_CHECK( !value.Get( url ) );
957 DALI_TEST_CHECK( map.Empty() );
959 std::string resource_url;
960 Property::Value val = imageView.GetProperty( imageView.GetPropertyIndex( "image" ) );
961 DALI_TEST_CHECK( !val.Get( resource_url ) );
966 int UtcDaliImageViewSetImageTypeChangesP(void)
968 ToolkitTestApplication application;
970 ImageView imageView = ImageView::New();
971 Toolkit::Internal::Control& controlImpl = Toolkit::Internal::GetImplementation( imageView );
973 Stage::GetCurrent().Add( imageView );
977 Toolkit::Visual::Base visual;
979 Property::Value value = imageView.GetProperty( imageView.GetPropertyIndex( "image" ) );
980 visual = DevelControl::GetVisual( controlImpl, ImageView::Property::IMAGE );
982 application.SendNotification();
983 application.Render( 16 );
985 DALI_TEST_CHECK( ! value.Get( url ) ); // Value should be empty
987 DALI_TEST_CHECK( map.Empty() ); // Value should be empty
988 DALI_TEST_CHECK( ! visual ); // Visual should be invalid
991 imageView.SetImage( "TEST_URL" );
993 application.SendNotification();
994 application.Render( 16 );
996 value = imageView.GetProperty( imageView.GetPropertyIndex( "image" ) );
997 visual = DevelControl::GetVisual( controlImpl, ImageView::Property::IMAGE );
999 DALI_TEST_CHECK( value.Get( url ) ); // Value should NOT be empty
1000 DALI_TEST_CHECK( ! value.Get( map ) ); // Value should be empty
1001 DALI_TEST_CHECK( visual ); // Visual should be valid
1003 // Set an empty Image
1004 imageView.SetImage( Image() );
1006 application.SendNotification();
1007 application.Render( 16 );
1009 value = imageView.GetProperty( imageView.GetPropertyIndex( "image" ) );
1010 visual = DevelControl::GetVisual( controlImpl, ImageView::Property::IMAGE );
1012 DALI_TEST_CHECK( ! value.Get( url ) ); // Value should be empty
1014 DALI_TEST_CHECK( map.Empty() ); // Value should be empty
1015 DALI_TEST_CHECK( ! visual ); // Visual should be invalid
1018 ResourceImage image1 = ResourceImage::New( TEST_IMAGE_FILE_NAME );
1019 imageView.SetImage( image1 );
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 NOT be empty
1029 DALI_TEST_CHECK( visual ); // Visual should be valid
1032 imageView.SetImage( "" );
1034 application.SendNotification();
1035 application.Render( 16 );
1037 value = imageView.GetProperty( imageView.GetPropertyIndex( "image" ) );
1038 visual = DevelControl::GetVisual( controlImpl, ImageView::Property::IMAGE );
1040 DALI_TEST_CHECK( ! value.Get( url ) ); // Value should be empty
1042 DALI_TEST_CHECK( map.Empty() ); // Value should be empty
1043 DALI_TEST_CHECK( ! visual ); // Visual should be invalid
1045 // Set a URL in property map
1046 Property::Map propertyMap;
1047 propertyMap[ImageVisual::Property::URL] = TEST_IMAGE_FILE_NAME;
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 a URL in property map again
1061 propertyMap[ImageVisual::Property::URL] = gImage_34_RGBA;
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 valid
1074 // Set an empty URL in property map
1075 propertyMap[ImageVisual::Property::URL] = std::string();
1076 imageView.SetProperty( ImageView::Property::IMAGE, propertyMap );
1078 application.SendNotification();
1079 application.Render( 16 );
1081 value = imageView.GetProperty( imageView.GetPropertyIndex( "image" ) );
1082 visual = DevelControl::GetVisual( controlImpl, ImageView::Property::IMAGE );
1084 DALI_TEST_CHECK( ! value.Get( url ) ); // Value should be empty
1085 DALI_TEST_CHECK( value.Get( map ) ); // Value should NOT be empty
1086 DALI_TEST_CHECK( ! visual ); // Visual should be invalid
1091 int UtcDaliImageViewResourceUrlP(void)
1093 ToolkitTestApplication application;
1095 ImageView imageView = ImageView::New();
1096 DALI_TEST_CHECK( imageView.GetProperty( ImageView::Property::RESOURCE_URL ).Get< std::string >().empty() );
1098 imageView.SetProperty( ImageView::Property::RESOURCE_URL, "TestString" );
1099 DALI_TEST_EQUALS( imageView.GetProperty( ImageView::Property::RESOURCE_URL ).Get< std::string >(), "TestString", TEST_LOCATION );
1104 // Scenarios 1: ImageView from regular image
1105 int UtcDaliImageViewSetImageBufferImage(void)
1107 ToolkitTestApplication application;
1109 ImageView imageView = ImageView::New();
1110 Stage::GetCurrent().Add( imageView );
1112 TestGlAbstraction& gl = application.GetGlAbstraction();
1113 gl.EnableTextureCallTrace( true );
1115 std::vector< GLuint > ids;
1116 ids.push_back( 23 );
1117 application.GetGlAbstraction().SetNextTextureIds( ids );
1121 BufferImage image = CreateBufferImage( width, height, Color::WHITE );
1123 imageView.SetImage( image );
1125 application.SendNotification();
1126 application.Render();
1128 DALI_TEST_CHECK( gl.GetTextureTrace().FindMethod("BindTexture") );
1130 std::stringstream params;
1131 params << GL_TEXTURE_2D << ", " << 23;
1132 DALI_TEST_CHECK( gl.GetTextureTrace().FindMethodAndParams("BindTexture", params.str()) );
1137 // Scenarios 2: ImageView from Native image
1138 int UtcDaliImageViewSetImageNativeImage(void)
1140 ToolkitTestApplication application;
1142 ImageView imageView = ImageView::New();
1143 Stage::GetCurrent().Add( imageView );
1145 TestGlAbstraction& gl = application.GetGlAbstraction();
1146 gl.EnableTextureCallTrace( true );
1148 std::vector< GLuint > ids;
1149 ids.push_back( 23 );
1150 application.GetGlAbstraction().SetNextTextureIds( ids );
1154 TestNativeImagePointer nativeImageInterface = TestNativeImage::New( width, height );
1155 NativeImage nativeImage = NativeImage::New( *(nativeImageInterface.Get()) );
1157 imageView.SetImage( nativeImage );
1158 application.SendNotification();
1159 application.Render();
1161 DALI_TEST_CHECK( gl.GetTextureTrace().FindMethod("BindTexture") );
1163 std::stringstream params;
1164 params << GL_TEXTURE_EXTERNAL_OES << ", " << 23;
1165 DALI_TEST_CHECK( gl.GetTextureTrace().FindMethodAndParams("BindTexture", params.str()) );
1170 // Scenarios 3: ImageView initially from regular image but then SetImage called with Native image
1171 int UtcDaliImageViewSetImageBufferImageToNativeImage(void)
1173 ToolkitTestApplication application;
1177 BufferImage image = CreateBufferImage( width, height, Color::WHITE );
1179 ImageView imageView = ImageView::New( image );
1180 Stage::GetCurrent().Add( imageView );
1182 TestGlAbstraction& gl = application.GetGlAbstraction();
1183 gl.EnableTextureCallTrace( true );
1185 std::vector< GLuint > ids;
1186 ids.push_back( 23 );
1187 application.GetGlAbstraction().SetNextTextureIds( ids );
1189 application.SendNotification();
1190 application.Render();
1192 DALI_TEST_CHECK( gl.GetTextureTrace().FindMethod("BindTexture") );
1194 std::stringstream params;
1195 params << GL_TEXTURE_2D << ", " << 23;
1196 DALI_TEST_CHECK( gl.GetTextureTrace().FindMethodAndParams("BindTexture", params.str()) );
1200 TestNativeImagePointer nativeImageInterface = TestNativeImage::New( width, height );
1201 NativeImage nativeImage = NativeImage::New( *(nativeImageInterface.Get()) );
1202 imageView.SetImage( nativeImage );
1205 ids.push_back( 24 );
1206 application.GetGlAbstraction().SetNextTextureIds( ids );
1208 application.SendNotification();
1209 application.Render();
1211 DALI_TEST_CHECK( gl.GetTextureTrace().FindMethod("BindTexture") );
1213 std::stringstream nextTextureParams;
1214 nextTextureParams << GL_TEXTURE_EXTERNAL_OES << ", " << 24;
1215 DALI_TEST_CHECK( gl.GetTextureTrace().FindMethodAndParams("BindTexture", nextTextureParams.str()) );
1220 // Scenarios 4: ImageView initially from Native image but then SetImage called with regular image
1221 int UtcDaliImageViewSetImageNativeImageToBufferImage(void)
1223 ToolkitTestApplication application;
1227 TestNativeImagePointer nativeImageInterface = TestNativeImage::New( width, height );
1228 NativeImage nativeImage = NativeImage::New( *(nativeImageInterface.Get()) );
1230 ImageView imageView = ImageView::New( nativeImage );
1231 Stage::GetCurrent().Add( imageView );
1233 TestGlAbstraction& gl = application.GetGlAbstraction();
1234 gl.EnableTextureCallTrace( true );
1236 std::vector< GLuint > ids;
1237 ids.push_back( 23 );
1238 application.GetGlAbstraction().SetNextTextureIds( ids );
1240 application.SendNotification();
1241 application.Render();
1243 DALI_TEST_CHECK( gl.GetTextureTrace().FindMethod("BindTexture") );
1245 std::stringstream params;
1246 params << GL_TEXTURE_EXTERNAL_OES << ", " << 23;
1247 DALI_TEST_CHECK( gl.GetTextureTrace().FindMethodAndParams("BindTexture", params.str()) );
1251 BufferImage image = CreateBufferImage( width, height, Color::WHITE );
1252 imageView.SetImage( image );
1255 ids.push_back( 24 );
1256 application.GetGlAbstraction().SetNextTextureIds( ids );
1258 application.SendNotification();
1259 application.Render();
1261 DALI_TEST_CHECK( gl.GetTextureTrace().FindMethod("BindTexture") );
1263 std::stringstream nextTextureParams;
1264 nextTextureParams << GL_TEXTURE_2D << ", " << 24;
1265 DALI_TEST_CHECK( gl.GetTextureTrace().FindMethodAndParams("BindTexture", nextTextureParams.str()) );
1270 // Scenarios 5: ImageView from Native image with custom shader
1271 int UtcDaliImageViewSetImageNativeImageWithCustomShader(void)
1273 ToolkitTestApplication application;
1278 Property::Map customShader;
1279 customShader.Insert( "vertexShader", VERTEX_SHADER );
1280 customShader.Insert( "fragmentShader", FRAGMENT_SHADER );
1282 Property::Array shaderHints;
1283 shaderHints.PushBack( "requiresSelfDepthTest" );
1284 shaderHints.PushBack( "outputIsTransparent" );
1285 shaderHints.PushBack( "outputIsOpaque" );
1286 shaderHints.PushBack( "modifiesGeometry" );
1288 customShader.Insert( "hints", shaderHints );
1291 map.Insert( "shader", customShader );
1293 TestNativeImagePointer nativeImageInterface = TestNativeImage::New( width, height );
1294 NativeImage nativeImage = NativeImage::New( *(nativeImageInterface.Get()) );
1296 ImageView imageView = ImageView::New( nativeImage );
1297 imageView.SetProperty( ImageView::Property::IMAGE, map );
1298 Stage::GetCurrent().Add( imageView );
1300 TestGlAbstraction& gl = application.GetGlAbstraction();
1301 gl.EnableTextureCallTrace( true );
1303 std::vector< GLuint > ids;
1304 ids.push_back( 23 );
1305 application.GetGlAbstraction().SetNextTextureIds( ids );
1307 application.SendNotification();
1308 application.Render();
1310 DALI_TEST_CHECK( gl.GetTextureTrace().FindMethod("BindTexture") );
1312 std::stringstream params;
1313 params << GL_TEXTURE_EXTERNAL_OES << ", " << 23;
1314 DALI_TEST_CHECK( gl.GetTextureTrace().FindMethodAndParams("BindTexture", params.str()) );
1319 // Scenarios 6: ImageView initially from regular image with custom shader but then SetImage called with Native
1320 int UtcDaliImageViewSetImageBufferImageWithCustomShaderToNativeImage(void)
1322 ToolkitTestApplication application;
1327 Property::Map customShader;
1328 customShader.Insert( "vertexShader", VERTEX_SHADER );
1329 customShader.Insert( "fragmentShader", FRAGMENT_SHADER );
1331 Property::Array shaderHints;
1332 shaderHints.PushBack( "requiresSelfDepthTest" );
1333 shaderHints.PushBack( "outputIsTransparent" );
1334 shaderHints.PushBack( "outputIsOpaque" );
1335 shaderHints.PushBack( "modifiesGeometry" );
1337 customShader.Insert( "hints", shaderHints );
1340 map.Insert( "shader", customShader );
1342 BufferImage image = CreateBufferImage( width, height, Color::WHITE );
1344 ImageView imageView = ImageView::New( image );
1345 imageView.SetProperty( ImageView::Property::IMAGE, map );
1346 Stage::GetCurrent().Add( imageView );
1348 TestGlAbstraction& gl = application.GetGlAbstraction();
1349 gl.EnableTextureCallTrace( true );
1351 std::vector< GLuint > ids;
1352 ids.push_back( 23 );
1353 application.GetGlAbstraction().SetNextTextureIds( ids );
1355 application.SendNotification();
1356 application.Render();
1358 DALI_TEST_CHECK( gl.GetTextureTrace().FindMethod("BindTexture") );
1360 std::stringstream params;
1361 params << GL_TEXTURE_2D << ", " << 23;
1362 DALI_TEST_CHECK( gl.GetTextureTrace().FindMethodAndParams("BindTexture", params.str()) );
1364 TestNativeImagePointer nativeImageInterface = TestNativeImage::New( width, height );
1365 NativeImage nativeImage = NativeImage::New( *(nativeImageInterface.Get()) );
1366 imageView.SetImage( nativeImage );
1369 ids.push_back( 24 );
1370 application.GetGlAbstraction().SetNextTextureIds( ids );
1372 application.SendNotification();
1373 application.Render();
1375 DALI_TEST_CHECK( gl.GetTextureTrace().FindMethod("BindTexture") );
1377 std::stringstream nativeImageParams;
1378 nativeImageParams << GL_TEXTURE_EXTERNAL_OES << ", " << 24;
1379 DALI_TEST_CHECK( gl.GetTextureTrace().FindMethodAndParams("BindTexture", nativeImageParams.str()) );
1385 int UtcDaliImageViewGetImageP1(void)
1387 ToolkitTestApplication application;
1389 ImageView imageView = ImageView::New();
1390 DALI_TEST_CHECK( ! imageView.GetImage() );
1392 Image image = CreateBufferImage();
1393 imageView.SetImage( image );
1394 DALI_TEST_CHECK( imageView.GetImage() == image );
1399 int UtcDaliImageViewGetImageP2(void)
1401 ToolkitTestApplication application;
1403 BufferImage image = CreateBufferImage();
1404 ImageView imageView = ImageView::New( image );
1405 DALI_TEST_CHECK( imageView.GetImage() == image );
1410 int UtcDaliImageViewGetImageN(void)
1412 ToolkitTestApplication application;
1414 ImageView imageView = ImageView::New( TEST_IMAGE_FILE_NAME );
1415 DALI_TEST_CHECK( ! imageView.GetImage() );
1417 Image image = CreateBufferImage();
1418 imageView.SetImage( image );
1419 DALI_TEST_CHECK( imageView.GetImage() == image );
1421 imageView.SetImage( TEST_IMAGE_FILE_NAME );
1422 DALI_TEST_CHECK( ! imageView.GetImage() );
1428 int UtcDaliImageViewReplaceImage(void)
1430 ToolkitTestApplication application;
1432 gResourceReadySignalFired = false;
1436 Image image = CreateBufferImage( width, height, Vector4(1.f, 1.f, 1.f, 1.f) );
1438 // Check ImageView with background and main image, to ensure both visuals are marked as loaded
1439 ImageView imageView = ImageView::New( TEST_IMAGE_1 );
1441 DALI_TEST_EQUALS( imageView.IsResourceReady(), false, TEST_LOCATION );
1443 imageView.ResourceReadySignal().Connect( &ResourceReadySignal);
1445 Stage::GetCurrent().Add( imageView );
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( gResourceReadySignalFired, true, TEST_LOCATION );
1457 gResourceReadySignalFired = false;
1459 imageView.SetImage(TEST_IMAGE_2);
1461 application.SendNotification();
1462 application.Render(16);
1464 // loading started, this waits for the loader thread for max 30 seconds
1465 DALI_TEST_EQUALS( Test::WaitForEventThreadTrigger( 1 ), true, TEST_LOCATION );
1467 DALI_TEST_EQUALS( imageView.GetRendererCount(), 1u, TEST_LOCATION );
1469 DALI_TEST_EQUALS( imageView.IsResourceReady(), true, TEST_LOCATION );
1471 DALI_TEST_EQUALS( gResourceReadySignalFired, true, TEST_LOCATION );
1476 void OnRelayoutOverride( Size size )
1478 gNaturalSize = size; // Size Relayout is using
1481 int UtcDaliImageViewReplaceImageAndGetNaturalSize(void)
1483 ToolkitTestApplication application;
1485 // Check ImageView with background and main image, to ensure both visuals are marked as loaded
1486 ImageView imageView = ImageView::New( TEST_IMAGE_1 );
1487 imageView.SetResizePolicy( ResizePolicy::USE_NATURAL_SIZE, Dimension::ALL_DIMENSIONS );
1489 DummyControl dummyControl = DummyControl::New( true );
1490 Impl::DummyControl& dummyImpl = static_cast<Impl::DummyControl&>(dummyControl.GetImplementation());
1491 dummyControl.SetResizePolicy( ResizePolicy::FIT_TO_CHILDREN, Dimension::ALL_DIMENSIONS );
1493 dummyControl.Add( imageView );
1494 dummyImpl.SetRelayoutCallback( &OnRelayoutOverride );
1495 Stage::GetCurrent().Add( dummyControl );
1497 application.SendNotification();
1498 application.Render();
1500 // loading started, this waits for the loader thread for max 30 seconds
1501 DALI_TEST_EQUALS( Test::WaitForEventThreadTrigger( 1 ), true, TEST_LOCATION );
1503 DALI_TEST_EQUALS( gNaturalSize.width, 1024.0f, TEST_LOCATION );
1504 DALI_TEST_EQUALS( gNaturalSize.height, 1024.0f, TEST_LOCATION );
1506 gNaturalSize = Vector3::ZERO;
1508 imageView.SetImage(gImage_600_RGB);
1510 // Waiting for resourceReady so SendNotifcation not called here.
1512 // loading started, this waits for the loader thread for max 30 seconds
1513 DALI_TEST_EQUALS( Test::WaitForEventThreadTrigger( 1 ), true, TEST_LOCATION );
1515 // Trigger a potential relayout
1516 application.SendNotification();
1517 application.Render();
1519 DALI_TEST_EQUALS( gNaturalSize.width, 600.0f, TEST_LOCATION );
1520 DALI_TEST_EQUALS( gNaturalSize.height, 600.0f, TEST_LOCATION );
1525 int UtcDaliImageViewResourceReadySignalWithImmediateLoad(void)
1527 tet_infoline("Test Setting Image with IMMEDIATE load and receving ResourceReadySignal before staged.");
1529 ToolkitTestApplication application;
1531 gResourceReadySignalFired = false;
1533 Property::Map imageMap;
1535 imageMap[ ImageVisual::Property::URL ] = gImage_34_RGBA;
1536 imageMap[ ImageVisual::Property::LOAD_POLICY ] = ImageVisual::LoadPolicy::IMMEDIATE;
1538 tet_infoline("Creating ImageView without URL so image does not start loading");
1539 ImageView imageView = ImageView::New();
1540 tet_infoline("Connect to image loaded signal before setting image");
1541 imageView.ResourceReadySignal().Connect( &ResourceReadySignal);
1542 tet_infoline("Setting Image with IMMEDIATE load, signal already connected so will be triggered.");
1543 imageView.SetProperty( ImageView::Property::IMAGE, imageMap );
1545 // loading started, this waits for the loader thread
1546 DALI_TEST_EQUALS( Test::WaitForEventThreadTrigger( 1 ), true, TEST_LOCATION );
1548 application.SendNotification();
1549 application.Render(16);
1551 DALI_TEST_EQUALS( gResourceReadySignalFired, true, TEST_LOCATION );
1556 int UtcDaliImageViewResourceReadySignalWithReusedImage(void)
1558 tet_infoline("Test Setting Image that was already loaded by another ImageView and still getting ResourceReadySignal.");
1560 ToolkitTestApplication application;
1562 gResourceReadySignalFired = false;
1564 Property::Map imageMap;
1566 imageMap[ ImageVisual::Property::URL ] = gImage_34_RGBA;
1567 imageMap[ ImageVisual::Property::LOAD_POLICY ] = ImageVisual::LoadPolicy::IMMEDIATE;
1569 ImageView imageView = ImageView::New();
1570 imageView.ResourceReadySignal().Connect( &ResourceReadySignal);
1571 imageView.SetProperty( ImageView::Property::IMAGE, imageMap );
1573 // loading started, this waits for the loader thread
1574 DALI_TEST_EQUALS( Test::WaitForEventThreadTrigger( 1 ), true, TEST_LOCATION );
1576 application.SendNotification();
1577 application.Render(16);
1579 DALI_TEST_EQUALS( gResourceReadySignalFired, true, TEST_LOCATION );
1580 gResourceReadySignalFired = false;
1582 ImageView imageViewWithExistingImage = ImageView::New();
1583 imageViewWithExistingImage.ResourceReadySignal().Connect( &ResourceReadySignal);
1584 imageViewWithExistingImage.SetProperty( ImageView::Property::IMAGE, imageMap );
1586 DALI_TEST_EQUALS( gResourceReadySignalFired, true, TEST_LOCATION );
1591 int UtcDaliImageViewResourceReadySignalWithReusedImage02(void)
1593 tet_infoline("Test Setting Image that was already loaded by another ImageView and still getting ResourceReadySignal when staged.");
1595 ToolkitTestApplication application;
1597 gResourceReadySignalFired = false;
1599 Property::Map imageImmediateLoadingMap;
1600 imageImmediateLoadingMap[ ImageVisual::Property::URL ] = gImage_34_RGBA;
1601 imageImmediateLoadingMap[ ImageVisual::Property::LOAD_POLICY ] = ImageVisual::LoadPolicy::IMMEDIATE;
1603 tet_infoline("Immediate load an image");
1604 ImageView imageView = ImageView::New();
1605 imageView.ResourceReadySignal().Connect( &ResourceReadySignal);
1606 imageView.SetProperty( ImageView::Property::IMAGE, imageImmediateLoadingMap );
1608 // loading started, this waits for the loader thread
1609 DALI_TEST_EQUALS( Test::WaitForEventThreadTrigger( 1 ), true, TEST_LOCATION );
1611 application.SendNotification();
1612 application.Render(16);
1614 tet_infoline("Check image loaded");
1615 DALI_TEST_EQUALS( gResourceReadySignalFired, true, TEST_LOCATION );
1616 gResourceReadySignalFired = false;
1618 tet_infoline("Create another ImageView with the same URL");
1619 ImageView imageViewWithExistingImage = ImageView::New( gImage_34_RGBA );
1620 tet_infoline("Connect to ResourceReady signal for second ImageView, it should still fire as resource is ready");
1621 imageViewWithExistingImage.ResourceReadySignal().Connect( &ResourceReadySignal);
1623 Stage::GetCurrent().Add( imageViewWithExistingImage );
1625 DALI_TEST_EQUALS( gResourceReadySignalFired, true, TEST_LOCATION );
1630 int UtcDaliImageViewPaddingProperty(void)
1632 ToolkitTestApplication application;
1634 ImageView imageView = ImageView::New();
1635 Property::Map imagePropertyMap;
1636 imagePropertyMap[ Toolkit::Visual::Property::TYPE ] = Toolkit::Visual::IMAGE;
1637 imagePropertyMap[ Toolkit::ImageVisual::Property::URL ] = TEST_RESOURCE_DIR "/gallery-small-1.jpg" ;
1638 imagePropertyMap[ ImageVisual::Property::DESIRED_WIDTH ] = 128;
1639 imagePropertyMap[ ImageVisual::Property::DESIRED_HEIGHT ] = 128;
1640 imageView.SetProperty( Toolkit::ImageView::Property::IMAGE , imagePropertyMap );
1641 imageView.SetAnchorPoint( AnchorPoint::TOP_LEFT );
1642 imageView.SetParentOrigin( ParentOrigin::TOP_LEFT );
1643 imageView.SetProperty( Control::Property::PADDING, Extents( 15, 10, 5, 10 ) );
1644 Stage::GetCurrent().Add( imageView );
1646 application.SendNotification();
1647 application.Render();
1649 DALI_TEST_EQUALS( imageView.GetProperty<Extents>( Control::Property::PADDING ), Extents( 15, 10, 5, 10 ), TEST_LOCATION );
1651 ImageView childImage = ImageView::New();
1652 childImage.SetBackgroundColor( Color::BLACK );
1653 childImage.SetSize( 10.f, 10.f );
1654 imageView.Add( childImage );
1656 application.SendNotification();
1657 application.Render();
1659 // Child ImageView should be positioned dependinig on Parent ImageView's Padding value
1660 DALI_TEST_EQUALS( childImage.GetProperty<Vector3>( Dali::Actor::Property::POSITION ), Vector3( 15, 5, 0 ), TEST_LOCATION );
1662 // Check whether Image Visual transforms on ImageVieiw::OnRelayout()
1663 Toolkit::Internal::Control& controlImpl = Toolkit::Internal::GetImplementation( imageView );
1664 Toolkit::Visual::Base imageVisual = DevelControl::GetVisual( controlImpl, ImageView::Property::IMAGE );
1665 Property::Map resultMap;
1666 imageVisual.CreatePropertyMap( resultMap );
1668 Property::Value* transformValue = resultMap.Find( Visual::Property::TRANSFORM );
1669 DALI_TEST_CHECK( transformValue );
1670 Property::Map* retMap = transformValue->GetMap();
1671 DALI_TEST_CHECK( retMap );
1673 // Image Visual should be positioned depending on ImageView's padding
1674 DALI_TEST_EQUALS( retMap->Find( Visual::Transform::Property::OFFSET )->Get< Vector2 >(), Vector2( 15, 5 ), TEST_LOCATION );
1679 int UtcDaliImageViewPaddingProperty02(void)
1681 ToolkitTestApplication application;
1683 ImageView imageView = ImageView::New();
1684 Property::Map imagePropertyMap;
1685 imagePropertyMap[ Toolkit::Visual::Property::TYPE ] = Toolkit::Visual::IMAGE;
1686 imagePropertyMap[ Toolkit::ImageVisual::Property::URL ] = TEST_RESOURCE_DIR "/Kid1.svg" ;
1687 imagePropertyMap[ ImageVisual::Property::DESIRED_WIDTH ] = 128;
1688 imagePropertyMap[ ImageVisual::Property::DESIRED_HEIGHT ] = 128;
1689 imagePropertyMap[ DevelVisual::Property::VISUAL_FITTING_MODE ] = Toolkit::DevelVisual::FIT_KEEP_ASPECT_RATIO;
1690 imageView.SetProperty( Toolkit::ImageView::Property::IMAGE , imagePropertyMap );
1691 imageView.SetAnchorPoint( AnchorPoint::TOP_LEFT );
1692 imageView.SetParentOrigin( ParentOrigin::TOP_LEFT );
1693 imageView.SetProperty( Control::Property::PADDING, Extents( 15, 10, 5, 10 ) );
1694 Stage::GetCurrent().Add( imageView );
1696 application.SendNotification();
1697 application.Render();
1699 DALI_TEST_EQUALS( imageView.GetProperty<Extents>( Control::Property::PADDING ), Extents( 15, 10, 5, 10 ), TEST_LOCATION );
1701 // Check whether Image Visual transforms on ImageVieiw::OnRelayout()
1702 Toolkit::Internal::Control& controlImpl = Toolkit::Internal::GetImplementation( imageView );
1703 Toolkit::Visual::Base imageVisual = DevelControl::GetVisual( controlImpl, ImageView::Property::IMAGE );
1704 Property::Map resultMap;
1705 imageVisual.CreatePropertyMap( resultMap );
1707 Property::Value* transformValue = resultMap.Find( Visual::Property::TRANSFORM );
1708 DALI_TEST_CHECK( transformValue );
1709 Property::Map* retMap = transformValue->GetMap();
1710 DALI_TEST_CHECK( retMap );
1712 // Image Visual should be positioned depending on ImageView's padding
1713 DALI_TEST_EQUALS( retMap->Find( Visual::Transform::Property::OFFSET )->Get< Vector2 >(), Vector2( 15, 5 ), TEST_LOCATION );
1718 int UtcDaliImageViewUsingAtlasAndGetNaturalSize(void)
1720 ToolkitTestApplication application;
1722 // Check ImageView with background and main image, to ensure both visuals are marked as loaded
1723 ImageView imageView = ImageView::New();
1724 Property::Map imageMap;
1725 imageMap[ Toolkit::Visual::Property::TYPE ] = Toolkit::Visual::IMAGE;
1726 imageMap[ Toolkit::ImageVisual::Property::URL ] = gImage_34_RGBA;
1727 imageMap[ Toolkit::ImageVisual::Property::ATLASING ] = true;
1728 imageView.SetProperty( Toolkit::ImageView::Property::IMAGE, imageMap );
1729 Stage::GetCurrent().Add( imageView );
1731 // Trigger a potential relayout
1732 application.SendNotification();
1733 application.Render();
1735 Vector3 naturalSize = imageView.GetNaturalSize();
1737 DALI_TEST_EQUALS( naturalSize.width, 34.0f, TEST_LOCATION );
1738 DALI_TEST_EQUALS( naturalSize.height, 34.0f, TEST_LOCATION );
1743 int UtcDaliImageViewFillMode(void)
1745 ToolkitTestApplication application;
1747 tet_infoline( "Create an ImageVisual without padding and set the fill-mode to fill" );
1748 tet_infoline( " There should be no need to change the transform, our size-policy should be relative and size shoudl be [1,1]");
1750 ImageView imageView = ImageView::New();
1751 Property::Map imageMap;
1752 imageMap.Add( Toolkit::Visual::Property::TYPE, Toolkit::Visual::IMAGE );
1753 imageMap.Add( Toolkit::ImageVisual::Property::URL, gImage_600_RGB );
1754 imageMap.Add( DevelVisual::Property::VISUAL_FITTING_MODE, DevelVisual::FittingMode::FILL );
1756 imageView.SetProperty( Toolkit::ImageView::Property::IMAGE, imageMap );
1758 Stage::GetCurrent().Add( imageView );
1760 // Trigger a potential relayout
1761 application.SendNotification();
1762 application.Render();
1764 Toolkit::Visual::Base visual = DevelControl::GetVisual( Toolkit::Internal::GetImplementation( imageView ), Toolkit::ImageView::Property::IMAGE );
1765 Property::Map returnedMap;
1766 visual.CreatePropertyMap( returnedMap );
1768 Property::Value* value = returnedMap.Find( Toolkit::Visual::Property::TRANSFORM );
1769 DALI_TEST_CHECK( value );
1770 Property::Map* map = value->GetMap();
1771 DALI_TEST_CHECK( map );
1774 value = map->Find( Toolkit::Visual::Transform::Property::SIZE );
1775 DALI_TEST_CHECK( value );
1776 DALI_TEST_EQUALS( value->Get< Vector2 >(), Vector2::ONE, TEST_LOCATION ); // Relative size so will take up 100%
1778 value = map->Find( Toolkit::Visual::Transform::Property::SIZE_POLICY );
1779 DALI_TEST_CHECK( value );
1780 DALI_TEST_CHECK( value->Get< int >() == Toolkit::Visual::Transform::Policy::RELATIVE );
1785 int UtcDaliImageViewCustomShader(void)
1787 ToolkitTestApplication application;
1789 // Set a custom shader with an image url
1791 Property::Map properties;
1792 Property::Map shader;
1793 const std::string vertexShader = "Foobar";
1794 const std::string fragmentShader = "Foobar";
1795 shader[Visual::Shader::Property::FRAGMENT_SHADER] = fragmentShader;
1796 shader[Visual::Shader::Property::VERTEX_SHADER] = vertexShader;
1798 properties[Visual::Property::TYPE] = Visual::IMAGE;
1799 properties[Visual::Property::SHADER] = shader;
1800 properties[ImageVisual::Property::URL] = TEST_IMAGE_FILE_NAME;
1802 ImageView imageView = ImageView::New();
1803 imageView.SetProperty( ImageView::Property::IMAGE, properties );
1805 Stage::GetCurrent().Add( imageView );
1807 application.SendNotification();
1808 application.Render();
1810 DALI_TEST_EQUALS( Test::WaitForEventThreadTrigger( 1 ), true, TEST_LOCATION );
1812 Renderer renderer = imageView.GetRendererAt( 0 );
1813 Shader shader2 = renderer.GetShader();
1814 Property::Value value = shader2.GetProperty( Shader::Property::PROGRAM );
1815 Property::Map* map = value.GetMap();
1816 DALI_TEST_CHECK( map );
1818 Property::Value* fragment = map->Find( "fragment" ); // fragment key name from shader-impl.cpp
1819 DALI_TEST_EQUALS( fragmentShader, fragment->Get< std::string >(), TEST_LOCATION );
1821 Property::Value* vertex = map->Find( "vertex" ); // vertex key name from shader-impl.cpp
1822 DALI_TEST_EQUALS( vertexShader, vertex->Get< std::string >(), TEST_LOCATION );
1825 // Set a custom shader after setting an image url
1827 Property::Map properties;
1828 Property::Map shader;
1829 const std::string vertexShader = "Foobar";
1830 const std::string fragmentShader = "Foobar";
1831 shader[Visual::Shader::Property::FRAGMENT_SHADER] = fragmentShader;
1832 shader[Visual::Shader::Property::VERTEX_SHADER] = vertexShader;
1834 properties[Visual::Property::SHADER] = shader;
1836 ImageView imageView = ImageView::New( TEST_IMAGE_FILE_NAME );
1837 imageView.SetProperty( ImageView::Property::IMAGE, properties );
1839 Stage::GetCurrent().Add( imageView );
1841 application.SendNotification();
1842 application.Render();
1844 Renderer renderer = imageView.GetRendererAt( 0 );
1845 Shader shader2 = renderer.GetShader();
1846 Property::Value value = shader2.GetProperty( Shader::Property::PROGRAM );
1847 Property::Map* map = value.GetMap();
1848 DALI_TEST_CHECK( map );
1850 Property::Value* fragment = map->Find( "fragment" ); // fragment key name from shader-impl.cpp
1851 DALI_TEST_EQUALS( fragmentShader, fragment->Get< std::string >(), TEST_LOCATION );
1853 Property::Value* vertex = map->Find( "vertex" ); // vertex key name from shader-impl.cpp
1854 DALI_TEST_EQUALS( vertexShader, vertex->Get< std::string >(), TEST_LOCATION );
1857 // Set a custom shader before setting an image url
1859 Property::Map properties;
1860 Property::Map shader;
1861 const std::string vertexShader = "Foobar";
1862 const std::string fragmentShader = "Foobar";
1863 shader[Visual::Shader::Property::FRAGMENT_SHADER] = fragmentShader;
1864 shader[Visual::Shader::Property::VERTEX_SHADER] = vertexShader;
1866 properties[Visual::Property::SHADER] = shader;
1868 ImageView imageView = ImageView::New();
1869 imageView.SetProperty( ImageView::Property::IMAGE, properties );
1870 imageView.SetProperty( ImageView::Property::IMAGE, TEST_IMAGE_FILE_NAME );
1872 Stage::GetCurrent().Add( imageView );
1874 application.SendNotification();
1875 application.Render();
1877 Renderer renderer = imageView.GetRendererAt( 0 );
1878 Shader shader2 = renderer.GetShader();
1879 Property::Value value = shader2.GetProperty( Shader::Property::PROGRAM );
1880 Property::Map* map = value.GetMap();
1881 DALI_TEST_CHECK( map );
1883 Property::Value* fragment = map->Find( "fragment" ); // fragment key name from shader-impl.cpp
1884 DALI_TEST_EQUALS( fragmentShader, fragment->Get< std::string >(), TEST_LOCATION );
1886 Property::Value* vertex = map->Find( "vertex" ); // vertex key name from shader-impl.cpp
1887 DALI_TEST_EQUALS( vertexShader, vertex->Get< std::string >(), TEST_LOCATION );
1890 // Set a custom shader after setting a property map
1892 Property::Map properties;
1893 Property::Map shader;
1894 const std::string vertexShader = "Foobar";
1895 const std::string fragmentShader = "Foobar";
1896 shader[Visual::Shader::Property::FRAGMENT_SHADER] = fragmentShader;
1897 shader[Visual::Shader::Property::VERTEX_SHADER] = vertexShader;
1899 properties[Visual::Property::SHADER] = shader;
1901 Property::Map properties1;
1902 properties1[Visual::Property::TYPE] = Visual::IMAGE;
1903 properties1[ImageVisual::Property::URL] = TEST_IMAGE_FILE_NAME;
1905 ImageView imageView = ImageView::New();
1906 imageView.SetProperty( ImageView::Property::IMAGE, properties1 );
1907 imageView.SetProperty( ImageView::Property::IMAGE, properties );
1909 Stage::GetCurrent().Add( imageView );
1911 application.SendNotification();
1912 application.Render();
1914 Renderer renderer = imageView.GetRendererAt( 0 );
1915 Shader shader2 = renderer.GetShader();
1916 Property::Value value = shader2.GetProperty( Shader::Property::PROGRAM );
1917 Property::Map* map = value.GetMap();
1918 DALI_TEST_CHECK( map );
1920 Property::Value* fragment = map->Find( "fragment" ); // fragment key name from shader-impl.cpp
1921 DALI_TEST_EQUALS( fragmentShader, fragment->Get< std::string >(), TEST_LOCATION );
1923 Property::Value* vertex = map->Find( "vertex" ); // vertex key name from shader-impl.cpp
1924 DALI_TEST_EQUALS( vertexShader, vertex->Get< std::string >(), TEST_LOCATION );
1927 // Set a custom shader before setting a property map
1929 Property::Map properties;
1930 Property::Map shader;
1931 const std::string vertexShader = "Foobar";
1932 const std::string fragmentShader = "Foobar";
1933 shader[Visual::Shader::Property::FRAGMENT_SHADER] = fragmentShader;
1934 shader[Visual::Shader::Property::VERTEX_SHADER] = vertexShader;
1936 properties[Visual::Property::SHADER] = shader;
1938 Property::Map properties1;
1939 properties1[Visual::Property::TYPE] = Visual::IMAGE;
1940 properties1[ImageVisual::Property::URL] = TEST_IMAGE_FILE_NAME;
1942 ImageView imageView = ImageView::New();
1943 imageView.SetProperty( ImageView::Property::IMAGE, properties );
1944 imageView.SetProperty( ImageView::Property::IMAGE, properties1 );
1946 Stage::GetCurrent().Add( imageView );
1948 application.SendNotification();
1949 application.Render();
1951 Renderer renderer = imageView.GetRendererAt( 0 );
1952 Shader shader2 = renderer.GetShader();
1953 Property::Value value = shader2.GetProperty( Shader::Property::PROGRAM );
1954 Property::Map* map = value.GetMap();
1955 DALI_TEST_CHECK( map );
1957 Property::Value* fragment = map->Find( "fragment" ); // fragment key name from shader-impl.cpp
1958 DALI_TEST_EQUALS( fragmentShader, fragment->Get< std::string >(), TEST_LOCATION );
1960 Property::Value* vertex = map->Find( "vertex" ); // vertex key name from shader-impl.cpp
1961 DALI_TEST_EQUALS( vertexShader, vertex->Get< std::string >(), TEST_LOCATION );