2 * Copyright (c) 2017 Samsung Electronics Co., Ltd.
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
8 * http://www.apache.org/licenses/LICENSE-2.0
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
18 // Need to override adaptor classes for toolkit test harness, so include
19 // test harness headers before dali headers.
20 #include <dali-toolkit-test-suite-utils.h>
21 #include <toolkit-event-thread-callback.h>
23 #include <dali-toolkit/dali-toolkit.h>
24 #include <dali/devel-api/scripting/scripting.h>
25 #include <dali-toolkit/devel-api/controls/control-devel.h>
26 #include <dali-toolkit/devel-api/image-loader/texture-manager.h>
27 #include <dali-toolkit/devel-api/visual-factory/visual-base.h>
28 #include <dali-toolkit/devel-api/visuals/image-visual-properties-devel.h>
30 #include <test-native-image.h>
35 #include "dummy-control.h"
38 using namespace Toolkit;
40 void utc_dali_toolkit_image_view_startup(void)
42 test_return_value = TET_UNDEF;
45 void utc_dali_toolkit_image_view_cleanup(void)
47 test_return_value = TET_PASS;
53 const char* VERTEX_SHADER = DALI_COMPOSE_SHADER(
54 attribute mediump vec2 aPosition;\n
55 varying mediump vec2 vTexCoord;\n
56 uniform mediump mat4 uMvpMatrix;\n
57 uniform mediump vec3 uSize;\n
61 mediump vec4 vertexPosition = vec4(aPosition, 0.0, 1.0);\n
62 vertexPosition.xyz *= uSize;\n
63 vertexPosition = uMvpMatrix * vertexPosition;\n
65 vTexCoord = aPosition + vec2(0.5);\n
66 gl_Position = vertexPosition;\n
70 const char* FRAGMENT_SHADER = DALI_COMPOSE_SHADER(
71 varying mediump vec2 vTexCoord;\n
72 uniform sampler2D sTexture;\n
73 uniform lowp vec4 uColor;\n
77 gl_FragColor = texture2D( sTexture, vTexCoord ) * uColor;\n
81 const char* TEST_IMAGE_FILE_NAME = "gallery_image_01.jpg";
82 const char* TEST_IMAGE_FILE_NAME2 = "gallery_image_02.jpg";
84 const char* TEST_IMAGE_1 = TEST_RESOURCE_DIR "/TB-gloss.png";
85 const char* TEST_IMAGE_2 = TEST_RESOURCE_DIR "/tb-norm.png";
87 // resolution: 34*34, pixel format: RGBA8888
88 static const char* gImage_34_RGBA = TEST_RESOURCE_DIR "/icon-edit.png";
89 // resolution: 600*600, pixel format: RGB888
90 static const char* gImage_600_RGB = TEST_RESOURCE_DIR "/test-image-600.jpg";
92 // resolution: 50*50, frame count: 4, frame delay: 0.2 second for each frame
93 const char* TEST_GIF_FILE_NAME = TEST_RESOURCE_DIR "/anim.gif";
95 void TestImage( ImageView imageView, BufferImage image )
97 Property::Value value = imageView.GetProperty( imageView.GetPropertyIndex( "image" ) );
100 DALI_TEST_CHECK( value.Get( map ) );
102 DALI_TEST_CHECK( map.Find( "width" ) );
103 DALI_TEST_CHECK( map.Find( "height" ) );
104 DALI_TEST_CHECK( map.Find( "type" ) );
107 DALI_TEST_CHECK( map[ "width" ].Get( width ) );
108 DALI_TEST_EQUALS( (unsigned int)width, image.GetWidth(), TEST_LOCATION );
111 DALI_TEST_CHECK( map[ "height" ].Get( height ) );
112 DALI_TEST_EQUALS( (unsigned int)height, image.GetHeight(), TEST_LOCATION );
115 DALI_TEST_CHECK( map[ "type" ].Get( type ) );
116 DALI_TEST_EQUALS( type, "BufferImage", TEST_LOCATION );
119 void TestImage( ImageView imageView, ResourceImage image )
121 Property::Value value = imageView.GetProperty( imageView.GetPropertyIndex( "image" ) );
124 DALI_TEST_CHECK( value.Get( map ) );
126 if( map.Find( "width" ) )
129 DALI_TEST_CHECK( map[ "width" ].Get( width ) );
130 DALI_TEST_EQUALS( (unsigned int)width, image.GetWidth(), TEST_LOCATION );
133 if( map.Find( "height" ) )
136 DALI_TEST_CHECK( map[ "height" ].Get( height ) );
137 DALI_TEST_EQUALS( (unsigned int)height, image.GetHeight(), TEST_LOCATION );
140 DALI_TEST_CHECK( map.Find( "type" ) );
143 DALI_TEST_CHECK( map[ "type" ].Get( type ) );
144 DALI_TEST_EQUALS( type, "ResourceImage", TEST_LOCATION );
146 std::string filename;
147 DALI_TEST_CHECK( map[ "filename" ].Get( filename ) );
148 DALI_TEST_EQUALS( filename, image.GetUrl(), TEST_LOCATION );
151 void TestUrl( ImageView imageView, const std::string url )
153 Property::Value value = imageView.GetProperty( imageView.GetPropertyIndex( "image" ) );
155 std::string urlActual;
156 DALI_TEST_CHECK( value.Get( urlActual ) );
157 DALI_TEST_EQUALS( urlActual, url, TEST_LOCATION );
162 int UtcDaliImageViewNewP(void)
164 TestApplication application;
166 ImageView imageView = ImageView::New();
168 DALI_TEST_CHECK( imageView );
173 int UtcDaliImageViewNewImageP(void)
175 TestApplication application;
177 BufferImage image = CreateBufferImage( 100, 200, Vector4( 1.f, 1.f, 1.f, 1.f ) );
178 ImageView imageView = ImageView::New( image );
180 DALI_TEST_CHECK( imageView );
181 TestImage( imageView, image );
186 int UtcDaliImageViewNewUrlP(void)
188 TestApplication application;
190 ImageView imageView = ImageView::New( TEST_IMAGE_FILE_NAME );
191 DALI_TEST_CHECK( imageView );
193 TestUrl( imageView, TEST_IMAGE_FILE_NAME );
198 int UtcDaliImageViewConstructorP(void)
200 TestApplication application;
204 DALI_TEST_CHECK( !imageView );
209 int UtcDaliImageViewCopyConstructorP(void)
211 TestApplication application;
213 // Initialize an object, ref count == 1
214 ImageView imageView = ImageView::New();
216 ImageView copy( imageView );
217 DALI_TEST_CHECK( copy );
222 int UtcDaliImageViewAssignmentOperatorP(void)
224 TestApplication application;
226 ImageView imageView = ImageView::New();
228 ImageView copy( imageView );
229 DALI_TEST_CHECK( copy );
230 DALI_TEST_EQUALS( imageView, copy, TEST_LOCATION );
235 int UtcDaliImageViewDownCastP(void)
237 TestApplication application;
239 ImageView imageView = ImageView::New();
241 BaseHandle object(imageView);
243 ImageView imageView2 = ImageView::DownCast( object );
244 DALI_TEST_CHECK(imageView2);
246 ImageView imageView3 = DownCast< ImageView >( object );
247 DALI_TEST_CHECK(imageView3);
252 int UtcDaliImageViewDownCastN(void)
254 TestApplication application;
256 BaseHandle unInitializedObject;
258 ImageView imageView1 = ImageView::DownCast( unInitializedObject );
259 DALI_TEST_CHECK( !imageView1 );
261 ImageView imageView2 = DownCast< ImageView >( unInitializedObject );
262 DALI_TEST_CHECK( !imageView2 );
267 int UtcDaliImageViewTypeRegistry(void)
269 ToolkitTestApplication application;
271 TypeRegistry typeRegistry = TypeRegistry::Get();
272 DALI_TEST_CHECK( typeRegistry );
274 TypeInfo typeInfo = typeRegistry.GetTypeInfo( "ImageView" );
275 DALI_TEST_CHECK( typeInfo );
277 BaseHandle handle = typeInfo.CreateInstance();
278 DALI_TEST_CHECK( handle );
280 ImageView imageView = ImageView::DownCast( handle );
281 DALI_TEST_CHECK( imageView );
286 int UtcDaliImageViewSetGetProperty01(void)
288 ToolkitTestApplication application;
290 ImageView imageView = ImageView::New();
292 Property::Index idx = imageView.GetPropertyIndex( "image" );
293 DALI_TEST_EQUALS( idx, (Property::Index)ImageView::Property::IMAGE, TEST_LOCATION );
295 imageView.SetProperty( idx, TEST_IMAGE_FILE_NAME );
296 TestUrl( imageView, TEST_IMAGE_FILE_NAME );
301 int UtcDaliImageViewSetGetProperty02(void)
303 ToolkitTestApplication application;
305 Image image = CreateBufferImage( 10, 10, Color::WHITE );
306 ImageView imageView = ImageView::New(image);
307 Vector4 fullImageRect( 0.f, 0.f, 1.f, 1.f );
309 Stage::GetCurrent().Add( imageView );
311 application.SendNotification();
312 application.Render();
313 TestGlAbstraction& gl = application.GetGlAbstraction();
315 Vector4 pixelAreaUniform;
316 DALI_TEST_CHECK( gl.GetUniformValue<Vector4>( "pixelArea", pixelAreaUniform ) );
317 DALI_TEST_EQUALS( pixelAreaUniform, fullImageRect, TEST_LOCATION );
319 Property::Value value = imageView.GetProperty( ImageView::Property::PIXEL_AREA );
320 Vector4 pixelAreaValue;
321 DALI_TEST_CHECK( value.Get(pixelAreaValue) );
322 DALI_TEST_EQUALS( pixelAreaValue, fullImageRect, TEST_LOCATION );
324 Vector4 pixelAreaSet( 0.2f, 0.2f, 0.3f, 0.3f );
325 imageView.SetProperty( ImageView::Property::PIXEL_AREA, pixelAreaSet);
327 application.SendNotification();
328 application.Render();
330 value = imageView.GetProperty( ImageView::Property::PIXEL_AREA );
331 value.Get(pixelAreaValue);
332 DALI_TEST_EQUALS( pixelAreaValue, pixelAreaSet, TEST_LOCATION );
334 DALI_TEST_CHECK( gl.GetUniformValue<Vector4>( "pixelArea", pixelAreaUniform ) );
335 DALI_TEST_EQUALS( pixelAreaUniform, pixelAreaSet, TEST_LOCATION );
340 int UtcDaliImageViewSetGetProperty03(void)
342 ToolkitTestApplication application;
344 Image image = CreateBufferImage( 10, 10, Color::WHITE );
345 ImageView imageView = ImageView::New(image);
346 Stage::GetCurrent().Add( imageView );
347 application.SendNotification();
348 application.Render();
350 // conventional alpha blending
351 Renderer renderer = imageView.GetRendererAt( 0 );
352 Property::Value value = renderer.GetProperty( Renderer::Property::BLEND_PRE_MULTIPLIED_ALPHA );
354 DALI_TEST_CHECK( value.Get( enable ) );
355 DALI_TEST_CHECK( !enable );
357 // pre-multiplied alpha blending
358 imageView.SetProperty( Toolkit::ImageView::Property::PRE_MULTIPLIED_ALPHA, true );
359 application.SendNotification();
360 application.Render();
362 int srcFactorRgb = renderer.GetProperty<int>( Renderer::Property::BLEND_FACTOR_SRC_RGB );
363 int destFactorRgb = renderer.GetProperty<int>( Renderer::Property::BLEND_FACTOR_DEST_RGB );
364 int srcFactorAlpha = renderer.GetProperty<int>( Renderer::Property::BLEND_FACTOR_SRC_ALPHA );
365 int destFactorAlpha = renderer.GetProperty<int>( Renderer::Property::BLEND_FACTOR_DEST_ALPHA );
366 DALI_TEST_CHECK( srcFactorRgb == BlendFactor::ONE );
367 DALI_TEST_CHECK( destFactorRgb == BlendFactor::ONE_MINUS_SRC_ALPHA );
368 DALI_TEST_CHECK( srcFactorAlpha == BlendFactor::ONE );
369 DALI_TEST_CHECK( destFactorAlpha == BlendFactor::ONE_MINUS_SRC_ALPHA );
371 value = renderer.GetProperty( Renderer::Property::BLEND_PRE_MULTIPLIED_ALPHA );
372 DALI_TEST_CHECK( value.Get( enable ) );
373 DALI_TEST_CHECK( enable );
378 int UtcDaliImageViewPixelArea(void)
380 // Test pixel area property
381 ToolkitTestApplication application;
383 // Gif image, use AnimatedImageVisual internally
384 // Atlasing is applied to pack multiple frames, use custom wrap mode
385 ImageView gifView = ImageView::New();
386 const Vector4 pixelAreaVisual( 0.f, 0.f, 2.f, 2.f );
387 gifView.SetProperty( ImageView::Property::IMAGE,
388 Property::Map().Add( ImageVisual::Property::URL, TEST_GIF_FILE_NAME )
389 .Add( ImageVisual::Property::PIXEL_AREA, pixelAreaVisual ) );
392 Stage stage = Stage::GetCurrent();
393 stage.Add( gifView );
396 application.SendNotification();
397 application.Render(16);
398 DALI_TEST_CHECK( gifView.GetRendererCount() == 1u );
400 const Vector4 fullTextureRect( 0.f, 0.f, 1.f, 1.f );
401 // test that the pixel area value defined in the visual property map is registered on renderer
402 Renderer renderer = gifView.GetRendererAt(0);
403 Property::Value pixelAreaValue = renderer.GetProperty( renderer.GetPropertyIndex( "pixelArea" ) );
404 DALI_TEST_EQUALS( pixelAreaValue.Get<Vector4>(), pixelAreaVisual, TEST_LOCATION );
406 // test that the shader has the default pixel area value registered.
407 Shader shader = renderer.GetShader();
408 pixelAreaValue = shader.GetProperty( shader.GetPropertyIndex( "pixelArea" ) );
409 DALI_TEST_EQUALS( pixelAreaValue.Get<Vector4>(), fullTextureRect, TEST_LOCATION );
411 // test that the uniform uses the pixelArea property on the renderer.
412 TestGlAbstraction& gl = application.GetGlAbstraction();
413 Vector4 pixelAreaUniform;
414 DALI_TEST_CHECK( gl.GetUniformValue<Vector4>( "pixelArea", pixelAreaUniform ) );
415 DALI_TEST_EQUALS( pixelAreaVisual, pixelAreaUniform, Math::MACHINE_EPSILON_100, TEST_LOCATION );
417 // set the pixelArea property on the control
418 const Vector4 pixelAreaControl( -1.f, -1.f, 3.f, 3.f );
419 gifView.SetProperty( ImageView::Property::PIXEL_AREA, pixelAreaControl );
420 application.SendNotification();
421 application.Render(16);
423 // check the pixelArea property on the control
424 pixelAreaValue = gifView.GetProperty( gifView.GetPropertyIndex( "pixelArea" ) );
425 DALI_TEST_EQUALS( pixelAreaValue.Get<Vector4>(), pixelAreaControl, TEST_LOCATION );
426 // test that the uniform uses the pixelArea property on the control.
427 DALI_TEST_CHECK( gl.GetUniformValue<Vector4>( "pixelArea", pixelAreaUniform ) );
428 DALI_TEST_EQUALS( pixelAreaControl, pixelAreaUniform, Math::MACHINE_EPSILON_100, TEST_LOCATION );
434 int UtcDaliImageViewAsyncLoadingWithoutAltasing(void)
436 ToolkitTestApplication application;
437 TestGlAbstraction& gl = application.GetGlAbstraction();
438 const std::vector<GLuint>& textures = gl.GetBoundTextures();
439 size_t numTextures = textures.size();
441 // Async loading, no atlasing for big size image
442 ImageView imageView = ImageView::New( gImage_600_RGB );
444 // By default, Aysnc loading is used
445 Stage::GetCurrent().Add( imageView );
446 imageView.SetSize(100, 100);
447 imageView.SetParentOrigin( ParentOrigin::CENTER );
449 DALI_TEST_EQUALS( Test::WaitForEventThreadTrigger( 1 ), true, TEST_LOCATION );
451 application.SendNotification();
452 application.Render(16);
453 application.SendNotification();
455 const std::vector<GLuint>& textures2 = gl.GetBoundTextures();
456 DALI_TEST_GREATER( textures2.size(), numTextures, TEST_LOCATION );
463 int UtcDaliImageViewAsyncLoadingWithAtlasing(void)
465 ToolkitTestApplication application;
467 //Async loading, automatic atlasing for small size image
468 TraceCallStack& callStack = application.GetGlAbstraction().GetTextureTrace();
470 callStack.Enable(true);
472 Property::Map imageMap;
474 imageMap[ ImageVisual::Property::URL ] = gImage_34_RGBA;
475 imageMap[ ImageVisual::Property::DESIRED_HEIGHT ] = 34;
476 imageMap[ ImageVisual::Property::DESIRED_WIDTH ] = 34;
477 imageMap[ ImageVisual::Property::ATLASING] = true;
479 ImageView imageView = ImageView::New();
480 imageView.SetProperty( ImageView::Property::IMAGE, imageMap );
481 imageView.SetProperty( Toolkit::Control::Property::PADDING, Extents( 10u, 10u, 10u, 10u ) );
483 // By default, Aysnc loading is used
484 // loading is not started if the actor is offStage
486 Stage::GetCurrent().Add( imageView );
487 application.SendNotification();
488 application.Render(16);
489 application.Render(16);
490 application.SendNotification();
492 imageView.SetProperty( Dali::Actor::Property::LAYOUT_DIRECTION, Dali::LayoutDirection::RIGHT_TO_LEFT );
493 application.SendNotification();
494 application.Render(16);
495 application.Render(16);
496 application.SendNotification();
498 // loading started, this waits for the loader thread for max 30 seconds
499 DALI_TEST_EQUALS( Test::WaitForEventThreadTrigger( 1 ), true, TEST_LOCATION );
501 application.SendNotification();
502 application.Render(16);
504 callStack.Enable(false);
506 TraceCallStack::NamedParams params;
507 params["width"] = ToString(34);
508 params["height"] = ToString(34);
509 DALI_TEST_EQUALS( callStack.FindMethodAndParams( "TexSubImage2D", params ), true, TEST_LOCATION );
514 int UtcDaliImageViewAsyncLoadingWithAtlasing02(void)
516 ToolkitTestApplication application;
518 //Async loading, automatic atlasing for small size image
519 TraceCallStack& callStack = application.GetGlAbstraction().GetTextureTrace();
521 callStack.Enable(true);
523 Property::Map asyncLoadingMap;
524 asyncLoadingMap[ "url" ] = gImage_34_RGBA;
525 asyncLoadingMap[ "desiredHeight" ] = 34;
526 asyncLoadingMap[ "desiredWidth" ] = 34;
527 asyncLoadingMap[ "synchronousLoading" ] = false;
528 asyncLoadingMap[ "atlasing" ] = true;
530 ImageView imageView = ImageView::New();
531 imageView.SetProperty( ImageView::Property::IMAGE, asyncLoadingMap );
533 Stage::GetCurrent().Add( imageView );
534 application.SendNotification();
535 application.Render(16);
536 application.Render(16);
537 application.SendNotification();
539 // loading started, this waits for the loader thread for max 30 seconds
540 DALI_TEST_EQUALS( Test::WaitForEventThreadTrigger( 1 ), true, TEST_LOCATION );
542 application.SendNotification();
543 application.Render(16);
545 callStack.Enable(false);
547 TraceCallStack::NamedParams params;
548 params["width"] = ToString(34);
549 params["height"] = ToString(34);
550 DALI_TEST_EQUALS( callStack.FindMethodAndParams( "TexSubImage2D", params ), true, TEST_LOCATION );
555 int UtcDaliImageViewSyncLoading(void)
557 ToolkitTestApplication application;
559 tet_infoline("ImageView Testing sync loading and size using index key property map");
561 Property::Map syncLoadingMap;
562 syncLoadingMap[ ImageVisual::Property::SYNCHRONOUS_LOADING ] = true;
563 syncLoadingMap[ ImageVisual::Property::ATLASING ] = true;
565 // Sync loading, no atlasing for big size image
567 ImageView imageView = ImageView::New();
569 // Sync loading is used
570 syncLoadingMap[ ImageVisual::Property::URL ] = gImage_600_RGB;
571 imageView.SetProperty( ImageView::Property::IMAGE, syncLoadingMap );
574 // Sync loading, automatic atlasing for small size image
576 TraceCallStack& callStack = application.GetGlAbstraction().GetTextureTrace();
578 callStack.Enable(true);
580 ImageView imageView = ImageView::New( );
582 // Sync loading is used
583 syncLoadingMap[ ImageVisual::Property::URL ] = gImage_34_RGBA;
584 syncLoadingMap[ ImageVisual::Property::DESIRED_HEIGHT ] = 34;
585 syncLoadingMap[ ImageVisual::Property::DESIRED_WIDTH ] = 34;
586 imageView.SetProperty( ImageView::Property::IMAGE, syncLoadingMap );
588 Stage::GetCurrent().Add( imageView );
589 application.SendNotification();
590 application.Render(16);
592 TraceCallStack::NamedParams params;
593 params["width"] = ToString(34);
594 params["height"] = ToString(34);
595 DALI_TEST_EQUALS( callStack.FindMethodAndParams( "TexSubImage2D", params ),
596 true, TEST_LOCATION );
601 int UtcDaliImageViewSyncLoading02(void)
603 ToolkitTestApplication application;
605 tet_infoline("ImageView Testing sync loading and size using string key property map");
607 // Sync loading, automatic atlasing for small size image
609 TraceCallStack& callStack = application.GetGlAbstraction().GetTextureTrace();
611 callStack.Enable(true);
613 ImageView imageView = ImageView::New( );
615 // Sync loading is used
616 Property::Map syncLoadingMap;
617 syncLoadingMap[ "url" ] = gImage_34_RGBA;
618 syncLoadingMap[ "desiredHeight" ] = 34;
619 syncLoadingMap[ "desiredWidth" ] = 34;
620 syncLoadingMap[ "synchronousLoading" ] = true;
621 syncLoadingMap[ "atlasing" ] = true;
622 imageView.SetProperty( ImageView::Property::IMAGE, syncLoadingMap );
624 Stage::GetCurrent().Add( imageView );
625 application.SendNotification();
626 application.Render(16);
628 TraceCallStack::NamedParams params;
629 params["width"] = ToString(34);
630 params["height"] = ToString(34);
631 DALI_TEST_EQUALS( callStack.FindMethodAndParams( "TexSubImage2D", params ),
632 true, TEST_LOCATION );
637 int UtcDaliImageViewAddedTexture(void)
639 ToolkitTestApplication application;
641 tet_infoline("ImageView Testing image view with texture provided manager url");
643 ImageView imageView = ImageView::New();
645 // empty texture is ok, though pointless from app point of view
647 std::string url = TextureManager::AddTexture(empty);
648 DALI_TEST_CHECK(url.size() > 0u);
650 Property::Map propertyMap;
651 propertyMap[ImageVisual::Property::URL] = url;
652 imageView.SetProperty(ImageView::Property::IMAGE, propertyMap);
654 Stage::GetCurrent().Add( imageView );
655 application.SendNotification();
656 application.Render();
661 int UtcDaliImageViewSizeWithBackground(void)
663 ToolkitTestApplication application;
667 Image image = CreateBufferImage( width, height, Vector4(1.f, 1.f, 1.f, 1.f) );
668 ImageView imageView = ImageView::New();
669 imageView.SetBackgroundImage( image );
671 Stage::GetCurrent().Add( imageView );
672 application.SendNotification();
673 application.Render();
675 DALI_TEST_EQUALS( imageView.GetCurrentSize().width, (float)width, TEST_LOCATION );
676 DALI_TEST_EQUALS( imageView.GetCurrentSize().height, (float)height, TEST_LOCATION );
681 int UtcDaliImageViewSizeWithBackgroundAndImage(void)
683 ToolkitTestApplication application;
685 int widthBackground = 100;
686 int heightBackground = 200;
689 Image imageBackground = CreateBufferImage( widthBackground, heightBackground, Vector4(1.f, 1.f, 1.f, 1.f) );
690 Image image = CreateBufferImage( width, height, Vector4(1.f, 1.f, 1.f, 1.f) );
692 ImageView imageView = ImageView::New();
693 imageView.SetBackgroundImage( imageBackground );
694 imageView.SetImage( image );
696 Stage::GetCurrent().Add( imageView );
697 application.SendNotification();
698 application.Render();
700 DALI_TEST_EQUALS( imageView.GetCurrentSize().width, (float)width, TEST_LOCATION );
701 DALI_TEST_EQUALS( imageView.GetCurrentSize().height, (float)height, TEST_LOCATION );
706 int UtcDaliImageViewHeightForWidthBackground(void)
708 ToolkitTestApplication application;
710 int widthBackground = 100;
711 int heightBackground = 200;
712 Image imageBackground = CreateBufferImage( widthBackground, heightBackground, Vector4(1.f, 1.f, 1.f, 1.f) );
714 ImageView imageView = ImageView::New();
715 imageView.SetBackgroundImage( imageBackground );
717 Stage::GetCurrent().Add( imageView );
718 application.SendNotification();
719 application.Render();
721 Control control = Control::DownCast( imageView );
722 DALI_TEST_CHECK( control );
723 DALI_TEST_EQUALS( imageView.GetHeightForWidth( 123.f ), control.GetHeightForWidth( 123.f ), TEST_LOCATION );
724 DALI_TEST_EQUALS( imageView.GetWidthForHeight( 321.f ), control.GetWidthForHeight( 321.f ), TEST_LOCATION );
729 int UtcDaliImageViewHeightForWidthBackgroundAndImage(void)
731 ToolkitTestApplication application;
733 int widthBackground = 100;
734 int heightBackground = 200;
737 Image imageBackground = CreateBufferImage( widthBackground, heightBackground, Vector4(1.f, 1.f, 1.f, 1.f) );
738 Image image = CreateBufferImage( width, height, Vector4(1.f, 1.f, 1.f, 1.f) );
740 ImageView imageView = ImageView::New();
741 imageView.SetBackgroundImage( imageBackground );
742 imageView.SetImage( image );
744 Stage::GetCurrent().Add( imageView );
745 application.SendNotification();
746 application.Render();
748 DALI_TEST_EQUALS( imageView.GetHeightForWidth( width ), (float)height, TEST_LOCATION );
749 DALI_TEST_EQUALS( imageView.GetWidthForHeight( height ), (float)width, TEST_LOCATION );
754 int UtcDaliImageViewSetBufferImage(void)
756 ToolkitTestApplication application;
760 BufferImage image1 = CreateBufferImage( width1, height1, Vector4( 1.f, 1.f, 1.f, 1.f ) );
761 ImageView imageView = ImageView::New();
762 imageView.SetImage( image1 );
764 TestImage( imageView, image1 );
768 BufferImage image2 = CreateBufferImage( width2, height2, Vector4( 1.f, 1.f, 1.f, 1.f ) );
769 imageView.SetImage( image2 );
771 TestImage( imageView, image2 );
776 int UtcDaliImageViewSetImageUrl(void)
778 ToolkitTestApplication application;
780 ImageView imageView = ImageView::New();
781 imageView.SetImage( TEST_IMAGE_FILE_NAME );
782 TestUrl( imageView, TEST_IMAGE_FILE_NAME );
785 imageView.SetImage( TEST_IMAGE_FILE_NAME2 );
786 TestUrl( imageView, TEST_IMAGE_FILE_NAME2 );
791 int UtcDaliImageViewSetImageOnstageP(void)
793 ToolkitTestApplication application;
795 ImageView imageView = ImageView::New();
797 Stage::GetCurrent().Add( imageView );
798 application.SendNotification();
799 application.Render();
801 ResourceImage image1 = ResourceImage::New( TEST_IMAGE_FILE_NAME );
802 imageView.SetImage( image1 );
803 TestImage( imageView, image1 );
807 BufferImage image2 = CreateBufferImage( width, height, Vector4( 1.f, 1.f, 1.f, 1.f ) );
808 imageView.SetImage( image2 );
809 TestImage( imageView, image2 );
814 int UtcDaliImageViewSetImageOnstageN(void)
816 ToolkitTestApplication application;
818 ImageView imageView = ImageView::New();
820 Stage::GetCurrent().Add( imageView );
821 application.SendNotification();
822 application.Render();
824 ResourceImage image1 = ResourceImage::New( TEST_IMAGE_FILE_NAME );
825 imageView.SetImage( image1 );
826 TestImage( imageView, image1 );
829 imageView.SetImage( image2 );
831 Property::Value value = imageView.GetProperty( imageView.GetPropertyIndex( "image" ) );
833 //the value should be empty
835 DALI_TEST_CHECK( !value.Get( url ) );
839 DALI_TEST_CHECK( map.Empty() );
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 ) );
935 DALI_TEST_CHECK( map.Empty() );
940 int UtcDaliImageViewSetImageN(void)
942 ToolkitTestApplication application;
945 ImageView imageView = ImageView::New();
946 imageView.SetImage( image1 );
948 Property::Value value = imageView.GetProperty( imageView.GetPropertyIndex( "image" ) );
950 //the value should be empty
952 DALI_TEST_CHECK( !value.Get( url ) );
956 DALI_TEST_CHECK( map.Empty() );
958 std::string resource_url;
959 Property::Value val = imageView.GetProperty( imageView.GetPropertyIndex( "image" ) );
960 DALI_TEST_CHECK( !val.Get( resource_url ) );
965 int UtcDaliImageViewSetImageTypeChangesP(void)
967 ToolkitTestApplication application;
969 ImageView imageView = ImageView::New();
970 Toolkit::Internal::Control& controlImpl = Toolkit::Internal::GetImplementation( imageView );
972 Stage::GetCurrent().Add( imageView );
976 Toolkit::Visual::Base visual;
978 Property::Value value = imageView.GetProperty( imageView.GetPropertyIndex( "image" ) );
979 visual = DevelControl::GetVisual( controlImpl, ImageView::Property::IMAGE );
981 application.SendNotification();
982 application.Render( 16 );
984 DALI_TEST_CHECK( ! value.Get( url ) ); // Value should be empty
986 DALI_TEST_CHECK( map.Empty() ); // Value should be empty
987 DALI_TEST_CHECK( ! visual ); // Visual should be invalid
990 imageView.SetImage( "TEST_URL" );
992 application.SendNotification();
993 application.Render( 16 );
995 value = imageView.GetProperty( imageView.GetPropertyIndex( "image" ) );
996 visual = DevelControl::GetVisual( controlImpl, ImageView::Property::IMAGE );
998 DALI_TEST_CHECK( value.Get( url ) ); // Value should NOT be empty
999 DALI_TEST_CHECK( ! value.Get( map ) ); // Value should be empty
1000 DALI_TEST_CHECK( visual ); // Visual should be valid
1002 // Set an empty Image
1003 imageView.SetImage( Image() );
1005 application.SendNotification();
1006 application.Render( 16 );
1008 value = imageView.GetProperty( imageView.GetPropertyIndex( "image" ) );
1009 visual = DevelControl::GetVisual( controlImpl, ImageView::Property::IMAGE );
1011 DALI_TEST_CHECK( ! value.Get( url ) ); // Value should be empty
1013 DALI_TEST_CHECK( map.Empty() ); // Value should be empty
1014 DALI_TEST_CHECK( ! visual ); // Visual should be invalid
1017 ResourceImage image1 = ResourceImage::New( TEST_IMAGE_FILE_NAME );
1018 imageView.SetImage( image1 );
1020 application.SendNotification();
1021 application.Render( 16 );
1023 value = imageView.GetProperty( imageView.GetPropertyIndex( "image" ) );
1024 visual = DevelControl::GetVisual( controlImpl, ImageView::Property::IMAGE );
1026 DALI_TEST_CHECK( ! value.Get( url ) ); // Value should be empty
1027 DALI_TEST_CHECK( value.Get( map ) ); // Value should NOT be empty
1028 DALI_TEST_CHECK( visual ); // Visual should be valid
1031 imageView.SetImage( "" );
1033 application.SendNotification();
1034 application.Render( 16 );
1036 value = imageView.GetProperty( imageView.GetPropertyIndex( "image" ) );
1037 visual = DevelControl::GetVisual( controlImpl, ImageView::Property::IMAGE );
1039 DALI_TEST_CHECK( ! value.Get( url ) ); // Value should be empty
1041 DALI_TEST_CHECK( map.Empty() ); // Value should be empty
1042 DALI_TEST_CHECK( ! visual ); // Visual should be invalid
1044 // Set a URL in property map
1045 Property::Map propertyMap;
1046 propertyMap[ImageVisual::Property::URL] = TEST_IMAGE_FILE_NAME;
1047 imageView.SetProperty( ImageView::Property::IMAGE, propertyMap );
1049 application.SendNotification();
1050 application.Render( 16 );
1052 value = imageView.GetProperty( imageView.GetPropertyIndex( "image" ) );
1053 visual = DevelControl::GetVisual( controlImpl, ImageView::Property::IMAGE );
1055 DALI_TEST_CHECK( ! value.Get( url ) ); // Value should be empty
1056 DALI_TEST_CHECK( value.Get( map ) ); // Value should NOT be empty
1057 DALI_TEST_CHECK( visual ); // Visual should be valid
1059 // Set a URL in property map again
1060 propertyMap[ImageVisual::Property::URL] = gImage_34_RGBA;
1061 imageView.SetProperty( ImageView::Property::IMAGE, propertyMap );
1063 application.SendNotification();
1064 application.Render( 16 );
1066 value = imageView.GetProperty( imageView.GetPropertyIndex( "image" ) );
1067 visual = DevelControl::GetVisual( controlImpl, ImageView::Property::IMAGE );
1069 DALI_TEST_CHECK( ! value.Get( url ) ); // Value should be empty
1070 DALI_TEST_CHECK( value.Get( map ) ); // Value should NOT be empty
1071 DALI_TEST_CHECK( visual ); // Visual should be valid
1073 // Set an empty URL in property map
1074 propertyMap[ImageVisual::Property::URL] = std::string();
1075 imageView.SetProperty( ImageView::Property::IMAGE, propertyMap );
1077 application.SendNotification();
1078 application.Render( 16 );
1080 value = imageView.GetProperty( imageView.GetPropertyIndex( "image" ) );
1081 visual = DevelControl::GetVisual( controlImpl, ImageView::Property::IMAGE );
1083 DALI_TEST_CHECK( ! value.Get( url ) ); // Value should be empty
1084 DALI_TEST_CHECK( value.Get( map ) ); // Value should NOT be empty
1085 DALI_TEST_CHECK( ! visual ); // Visual should be invalid
1090 int UtcDaliImageViewResourceUrlP(void)
1092 ToolkitTestApplication application;
1094 ImageView imageView = ImageView::New();
1095 DALI_TEST_CHECK( imageView.GetProperty( ImageView::Property::RESOURCE_URL ).Get< std::string >().empty() );
1097 imageView.SetProperty( ImageView::Property::RESOURCE_URL, "TestString" );
1098 DALI_TEST_EQUALS( imageView.GetProperty( ImageView::Property::RESOURCE_URL ).Get< std::string >(), "TestString", TEST_LOCATION );
1103 // Scenarios 1: ImageView from regular image
1104 int UtcDaliImageViewSetImageBufferImage(void)
1106 ToolkitTestApplication application;
1108 ImageView imageView = ImageView::New();
1109 Stage::GetCurrent().Add( imageView );
1111 TestGlAbstraction& gl = application.GetGlAbstraction();
1112 gl.EnableTextureCallTrace( true );
1114 std::vector< GLuint > ids;
1115 ids.push_back( 23 );
1116 application.GetGlAbstraction().SetNextTextureIds( ids );
1120 BufferImage image = CreateBufferImage( width, height, Color::WHITE );
1122 imageView.SetImage( image );
1124 application.SendNotification();
1125 application.Render();
1127 DALI_TEST_CHECK( gl.GetTextureTrace().FindMethod("BindTexture") );
1129 std::stringstream params;
1130 params << GL_TEXTURE_2D << ", " << 23;
1131 DALI_TEST_CHECK( gl.GetTextureTrace().FindMethodAndParams("BindTexture", params.str()) );
1136 // Scenarios 2: ImageView from Native image
1137 int UtcDaliImageViewSetImageNativeImage(void)
1139 ToolkitTestApplication application;
1141 ImageView imageView = ImageView::New();
1142 Stage::GetCurrent().Add( imageView );
1144 TestGlAbstraction& gl = application.GetGlAbstraction();
1145 gl.EnableTextureCallTrace( true );
1147 std::vector< GLuint > ids;
1148 ids.push_back( 23 );
1149 application.GetGlAbstraction().SetNextTextureIds( ids );
1153 TestNativeImagePointer nativeImageInterface = TestNativeImage::New( width, height );
1154 NativeImage nativeImage = NativeImage::New( *(nativeImageInterface.Get()) );
1156 imageView.SetImage( nativeImage );
1157 application.SendNotification();
1158 application.Render();
1160 DALI_TEST_CHECK( gl.GetTextureTrace().FindMethod("BindTexture") );
1162 std::stringstream params;
1163 params << GL_TEXTURE_EXTERNAL_OES << ", " << 23;
1164 DALI_TEST_CHECK( gl.GetTextureTrace().FindMethodAndParams("BindTexture", params.str()) );
1169 // Scenarios 3: ImageView initially from regular image but then SetImage called with Native image
1170 int UtcDaliImageViewSetImageBufferImageToNativeImage(void)
1172 ToolkitTestApplication application;
1176 BufferImage image = CreateBufferImage( width, height, Color::WHITE );
1178 ImageView imageView = ImageView::New( image );
1179 Stage::GetCurrent().Add( imageView );
1181 TestGlAbstraction& gl = application.GetGlAbstraction();
1182 gl.EnableTextureCallTrace( true );
1184 std::vector< GLuint > ids;
1185 ids.push_back( 23 );
1186 application.GetGlAbstraction().SetNextTextureIds( ids );
1188 application.SendNotification();
1189 application.Render();
1191 DALI_TEST_CHECK( gl.GetTextureTrace().FindMethod("BindTexture") );
1193 std::stringstream params;
1194 params << GL_TEXTURE_2D << ", " << 23;
1195 DALI_TEST_CHECK( gl.GetTextureTrace().FindMethodAndParams("BindTexture", params.str()) );
1199 TestNativeImagePointer nativeImageInterface = TestNativeImage::New( width, height );
1200 NativeImage nativeImage = NativeImage::New( *(nativeImageInterface.Get()) );
1201 imageView.SetImage( nativeImage );
1204 ids.push_back( 24 );
1205 application.GetGlAbstraction().SetNextTextureIds( ids );
1207 application.SendNotification();
1208 application.Render();
1210 DALI_TEST_CHECK( gl.GetTextureTrace().FindMethod("BindTexture") );
1212 std::stringstream nextTextureParams;
1213 nextTextureParams << GL_TEXTURE_EXTERNAL_OES << ", " << 24;
1214 DALI_TEST_CHECK( gl.GetTextureTrace().FindMethodAndParams("BindTexture", nextTextureParams.str()) );
1219 // Scenarios 4: ImageView initially from Native image but then SetImage called with regular image
1220 int UtcDaliImageViewSetImageNativeImageToBufferImage(void)
1222 ToolkitTestApplication application;
1226 TestNativeImagePointer nativeImageInterface = TestNativeImage::New( width, height );
1227 NativeImage nativeImage = NativeImage::New( *(nativeImageInterface.Get()) );
1229 ImageView imageView = ImageView::New( nativeImage );
1230 Stage::GetCurrent().Add( imageView );
1232 TestGlAbstraction& gl = application.GetGlAbstraction();
1233 gl.EnableTextureCallTrace( true );
1235 std::vector< GLuint > ids;
1236 ids.push_back( 23 );
1237 application.GetGlAbstraction().SetNextTextureIds( ids );
1239 application.SendNotification();
1240 application.Render();
1242 DALI_TEST_CHECK( gl.GetTextureTrace().FindMethod("BindTexture") );
1244 std::stringstream params;
1245 params << GL_TEXTURE_EXTERNAL_OES << ", " << 23;
1246 DALI_TEST_CHECK( gl.GetTextureTrace().FindMethodAndParams("BindTexture", params.str()) );
1250 BufferImage image = CreateBufferImage( width, height, Color::WHITE );
1251 imageView.SetImage( image );
1254 ids.push_back( 24 );
1255 application.GetGlAbstraction().SetNextTextureIds( ids );
1257 application.SendNotification();
1258 application.Render();
1260 DALI_TEST_CHECK( gl.GetTextureTrace().FindMethod("BindTexture") );
1262 std::stringstream nextTextureParams;
1263 nextTextureParams << GL_TEXTURE_2D << ", " << 24;
1264 DALI_TEST_CHECK( gl.GetTextureTrace().FindMethodAndParams("BindTexture", nextTextureParams.str()) );
1269 // Scenarios 5: ImageView from Native image with custom shader
1270 int UtcDaliImageViewSetImageNativeImageWithCustomShader(void)
1272 ToolkitTestApplication application;
1277 Property::Map customShader;
1278 customShader.Insert( "vertexShader", VERTEX_SHADER );
1279 customShader.Insert( "fragmentShader", FRAGMENT_SHADER );
1281 Property::Array shaderHints;
1282 shaderHints.PushBack( "requiresSelfDepthTest" );
1283 shaderHints.PushBack( "outputIsTransparent" );
1284 shaderHints.PushBack( "outputIsOpaque" );
1285 shaderHints.PushBack( "modifiesGeometry" );
1287 customShader.Insert( "hints", shaderHints );
1290 map.Insert( "shader", customShader );
1292 TestNativeImagePointer nativeImageInterface = TestNativeImage::New( width, height );
1293 NativeImage nativeImage = NativeImage::New( *(nativeImageInterface.Get()) );
1295 ImageView imageView = ImageView::New( nativeImage );
1296 imageView.SetProperty( ImageView::Property::IMAGE, map );
1297 Stage::GetCurrent().Add( imageView );
1299 TestGlAbstraction& gl = application.GetGlAbstraction();
1300 gl.EnableTextureCallTrace( true );
1302 std::vector< GLuint > ids;
1303 ids.push_back( 23 );
1304 application.GetGlAbstraction().SetNextTextureIds( ids );
1306 application.SendNotification();
1307 application.Render();
1309 DALI_TEST_CHECK( gl.GetTextureTrace().FindMethod("BindTexture") );
1311 std::stringstream params;
1312 params << GL_TEXTURE_EXTERNAL_OES << ", " << 23;
1313 DALI_TEST_CHECK( gl.GetTextureTrace().FindMethodAndParams("BindTexture", params.str()) );
1318 // Scenarios 6: ImageView initially from regular image with custom shader but then SetImage called with Native
1319 int UtcDaliImageViewSetImageBufferImageWithCustomShaderToNativeImage(void)
1321 ToolkitTestApplication application;
1326 Property::Map customShader;
1327 customShader.Insert( "vertexShader", VERTEX_SHADER );
1328 customShader.Insert( "fragmentShader", FRAGMENT_SHADER );
1330 Property::Array shaderHints;
1331 shaderHints.PushBack( "requiresSelfDepthTest" );
1332 shaderHints.PushBack( "outputIsTransparent" );
1333 shaderHints.PushBack( "outputIsOpaque" );
1334 shaderHints.PushBack( "modifiesGeometry" );
1336 customShader.Insert( "hints", shaderHints );
1339 map.Insert( "shader", customShader );
1341 BufferImage image = CreateBufferImage( width, height, Color::WHITE );
1343 ImageView imageView = ImageView::New( image );
1344 imageView.SetProperty( ImageView::Property::IMAGE, map );
1345 Stage::GetCurrent().Add( imageView );
1347 TestGlAbstraction& gl = application.GetGlAbstraction();
1348 gl.EnableTextureCallTrace( true );
1350 std::vector< GLuint > ids;
1351 ids.push_back( 23 );
1352 application.GetGlAbstraction().SetNextTextureIds( ids );
1354 application.SendNotification();
1355 application.Render();
1357 DALI_TEST_CHECK( gl.GetTextureTrace().FindMethod("BindTexture") );
1359 std::stringstream params;
1360 params << GL_TEXTURE_2D << ", " << 23;
1361 DALI_TEST_CHECK( gl.GetTextureTrace().FindMethodAndParams("BindTexture", params.str()) );
1363 TestNativeImagePointer nativeImageInterface = TestNativeImage::New( width, height );
1364 NativeImage nativeImage = NativeImage::New( *(nativeImageInterface.Get()) );
1365 imageView.SetImage( nativeImage );
1368 ids.push_back( 24 );
1369 application.GetGlAbstraction().SetNextTextureIds( ids );
1371 application.SendNotification();
1372 application.Render();
1374 DALI_TEST_CHECK( gl.GetTextureTrace().FindMethod("BindTexture") );
1376 std::stringstream nativeImageParams;
1377 nativeImageParams << GL_TEXTURE_EXTERNAL_OES << ", " << 24;
1378 DALI_TEST_CHECK( gl.GetTextureTrace().FindMethodAndParams("BindTexture", nativeImageParams.str()) );
1384 int UtcDaliImageViewGetImageP1(void)
1386 ToolkitTestApplication application;
1388 ImageView imageView = ImageView::New();
1389 DALI_TEST_CHECK( ! imageView.GetImage() );
1391 Image image = CreateBufferImage();
1392 imageView.SetImage( image );
1393 DALI_TEST_CHECK( imageView.GetImage() == image );
1398 int UtcDaliImageViewGetImageP2(void)
1400 ToolkitTestApplication application;
1402 BufferImage image = CreateBufferImage();
1403 ImageView imageView = ImageView::New( image );
1404 DALI_TEST_CHECK( imageView.GetImage() == image );
1409 int UtcDaliImageViewGetImageN(void)
1411 ToolkitTestApplication application;
1413 ImageView imageView = ImageView::New( TEST_IMAGE_FILE_NAME );
1414 DALI_TEST_CHECK( ! imageView.GetImage() );
1416 Image image = CreateBufferImage();
1417 imageView.SetImage( image );
1418 DALI_TEST_CHECK( imageView.GetImage() == image );
1420 imageView.SetImage( TEST_IMAGE_FILE_NAME );
1421 DALI_TEST_CHECK( ! imageView.GetImage() );
1427 int UtcDaliImageViewReplaceImage(void)
1429 ToolkitTestApplication application;
1431 gResourceReadySignalFired = false;
1435 Image image = CreateBufferImage( width, height, Vector4(1.f, 1.f, 1.f, 1.f) );
1437 // Check ImageView with background and main image, to ensure both visuals are marked as loaded
1438 ImageView imageView = ImageView::New( TEST_IMAGE_1 );
1440 DALI_TEST_EQUALS( imageView.IsResourceReady(), false, TEST_LOCATION );
1442 imageView.ResourceReadySignal().Connect( &ResourceReadySignal);
1444 Stage::GetCurrent().Add( imageView );
1446 application.SendNotification();
1447 application.Render(16);
1449 // loading started, this waits for the loader thread for max 30 seconds
1450 DALI_TEST_EQUALS( Test::WaitForEventThreadTrigger( 1 ), true, TEST_LOCATION );
1452 DALI_TEST_EQUALS( imageView.GetRendererCount(), 1u, TEST_LOCATION );
1454 DALI_TEST_EQUALS( gResourceReadySignalFired, true, TEST_LOCATION );
1456 gResourceReadySignalFired = false;
1458 imageView.SetImage(TEST_IMAGE_2);
1460 application.SendNotification();
1461 application.Render(16);
1463 // loading started, this waits for the loader thread for max 30 seconds
1464 DALI_TEST_EQUALS( Test::WaitForEventThreadTrigger( 1 ), true, TEST_LOCATION );
1466 DALI_TEST_EQUALS( imageView.GetRendererCount(), 1u, TEST_LOCATION );
1468 DALI_TEST_EQUALS( imageView.IsResourceReady(), true, TEST_LOCATION );
1470 DALI_TEST_EQUALS( gResourceReadySignalFired, true, TEST_LOCATION );
1475 void OnRelayoutOverride( Size size )
1477 gNaturalSize = size; // Size Relayout is using
1480 int UtcDaliImageViewReplaceImageAndGetNaturalSize(void)
1482 ToolkitTestApplication application;
1484 // Check ImageView with background and main image, to ensure both visuals are marked as loaded
1485 ImageView imageView = ImageView::New( TEST_IMAGE_1 );
1486 imageView.SetResizePolicy( ResizePolicy::USE_NATURAL_SIZE, Dimension::ALL_DIMENSIONS );
1488 DummyControl dummyControl = DummyControl::New( true );
1489 Impl::DummyControl& dummyImpl = static_cast<Impl::DummyControl&>(dummyControl.GetImplementation());
1490 dummyControl.SetResizePolicy( ResizePolicy::FIT_TO_CHILDREN, Dimension::ALL_DIMENSIONS );
1492 dummyControl.Add( imageView );
1493 dummyImpl.SetRelayoutCallback( &OnRelayoutOverride );
1494 Stage::GetCurrent().Add( dummyControl );
1496 application.SendNotification();
1497 application.Render();
1499 // loading started, this waits for the loader thread for max 30 seconds
1500 DALI_TEST_EQUALS( Test::WaitForEventThreadTrigger( 1 ), true, TEST_LOCATION );
1502 DALI_TEST_EQUALS( gNaturalSize.width, 1024.0f, TEST_LOCATION );
1503 DALI_TEST_EQUALS( gNaturalSize.height, 1024.0f, TEST_LOCATION );
1505 gNaturalSize = Vector3::ZERO;
1507 imageView.SetImage(gImage_600_RGB);
1509 // Waiting for resourceReady so SendNotifcation not called here.
1511 // loading started, this waits for the loader thread for max 30 seconds
1512 DALI_TEST_EQUALS( Test::WaitForEventThreadTrigger( 1 ), true, TEST_LOCATION );
1514 // Trigger a potential relayout
1515 application.SendNotification();
1516 application.Render();
1518 DALI_TEST_EQUALS( gNaturalSize.width, 600.0f, TEST_LOCATION );
1519 DALI_TEST_EQUALS( gNaturalSize.height, 600.0f, TEST_LOCATION );
1524 int UtcDaliImageViewResourceReadySignalWithImmediateLoad(void)
1526 tet_infoline("Test Setting Image with IMMEDIATE load and receving ResourceReadySignal before staged.");
1528 ToolkitTestApplication application;
1530 gResourceReadySignalFired = false;
1532 Property::Map imageMap;
1534 imageMap[ ImageVisual::Property::URL ] = gImage_34_RGBA;
1535 imageMap[ ImageVisual::Property::LOAD_POLICY ] = ImageVisual::LoadPolicy::IMMEDIATE;
1537 tet_infoline("Creating ImageView without URL so image does not start loading");
1538 ImageView imageView = ImageView::New();
1539 tet_infoline("Connect to image loaded signal before setting image");
1540 imageView.ResourceReadySignal().Connect( &ResourceReadySignal);
1541 tet_infoline("Setting Image with IMMEDIATE load, signal already connected so will be triggered.");
1542 imageView.SetProperty( ImageView::Property::IMAGE, imageMap );
1544 // loading started, this waits for the loader thread
1545 DALI_TEST_EQUALS( Test::WaitForEventThreadTrigger( 1 ), true, TEST_LOCATION );
1547 application.SendNotification();
1548 application.Render(16);
1550 DALI_TEST_EQUALS( gResourceReadySignalFired, true, TEST_LOCATION );
1555 int UtcDaliImageViewResourceReadySignalWithReusedImage(void)
1557 tet_infoline("Test Setting Image that was already loaded by another ImageView and still getting ResourceReadySignal.");
1559 ToolkitTestApplication application;
1561 gResourceReadySignalFired = false;
1563 Property::Map imageMap;
1565 imageMap[ ImageVisual::Property::URL ] = gImage_34_RGBA;
1566 imageMap[ ImageVisual::Property::LOAD_POLICY ] = ImageVisual::LoadPolicy::IMMEDIATE;
1568 ImageView imageView = ImageView::New();
1569 imageView.ResourceReadySignal().Connect( &ResourceReadySignal);
1570 imageView.SetProperty( ImageView::Property::IMAGE, imageMap );
1572 // loading started, this waits for the loader thread
1573 DALI_TEST_EQUALS( Test::WaitForEventThreadTrigger( 1 ), true, TEST_LOCATION );
1575 application.SendNotification();
1576 application.Render(16);
1578 DALI_TEST_EQUALS( gResourceReadySignalFired, true, TEST_LOCATION );
1579 gResourceReadySignalFired = false;
1581 ImageView imageViewWithExistingImage = ImageView::New();
1582 imageViewWithExistingImage.ResourceReadySignal().Connect( &ResourceReadySignal);
1583 imageViewWithExistingImage.SetProperty( ImageView::Property::IMAGE, imageMap );
1585 DALI_TEST_EQUALS( gResourceReadySignalFired, true, TEST_LOCATION );
1590 int UtcDaliImageViewResourceReadySignalWithReusedImage02(void)
1592 tet_infoline("Test Setting Image that was already loaded by another ImageView and still getting ResourceReadySignal when staged.");
1594 ToolkitTestApplication application;
1596 gResourceReadySignalFired = false;
1598 Property::Map imageImmediateLoadingMap;
1599 imageImmediateLoadingMap[ ImageVisual::Property::URL ] = gImage_34_RGBA;
1600 imageImmediateLoadingMap[ ImageVisual::Property::LOAD_POLICY ] = ImageVisual::LoadPolicy::IMMEDIATE;
1602 tet_infoline("Immediate load an image");
1603 ImageView imageView = ImageView::New();
1604 imageView.ResourceReadySignal().Connect( &ResourceReadySignal);
1605 imageView.SetProperty( ImageView::Property::IMAGE, imageImmediateLoadingMap );
1607 // loading started, this waits for the loader thread
1608 DALI_TEST_EQUALS( Test::WaitForEventThreadTrigger( 1 ), true, TEST_LOCATION );
1610 application.SendNotification();
1611 application.Render(16);
1613 tet_infoline("Check image loaded");
1614 DALI_TEST_EQUALS( gResourceReadySignalFired, true, TEST_LOCATION );
1615 gResourceReadySignalFired = false;
1617 tet_infoline("Create another ImageView with the same URL");
1618 ImageView imageViewWithExistingImage = ImageView::New( gImage_34_RGBA );
1619 tet_infoline("Connect to ResourceReady signal for second ImageView, it should still fire as resource is ready");
1620 imageViewWithExistingImage.ResourceReadySignal().Connect( &ResourceReadySignal);
1622 Stage::GetCurrent().Add( imageViewWithExistingImage );
1624 DALI_TEST_EQUALS( gResourceReadySignalFired, true, TEST_LOCATION );
1630 static int gFailCounter = 0;
1631 const int MAX_RETRIES(3);
1633 void ReloadImage(ImageView imageView)
1635 Property::Map imageImmediateLoadingMap;
1636 imageImmediateLoadingMap[ ImageVisual::Property::URL ] = "Non-existant-image.jpg";
1637 imageImmediateLoadingMap[ ImageVisual::Property::LOAD_POLICY ] = ImageVisual::LoadPolicy::IMMEDIATE;
1639 tet_infoline("Immediate load an image");
1640 imageView.SetProperty( ImageView::Property::IMAGE, imageImmediateLoadingMap );
1643 void ResourceFailedReload( Control control )
1646 if( gFailCounter < MAX_RETRIES )
1648 ReloadImage(ImageView::DownCast(control));
1652 int UtcDaliImageViewReloadFailedOnResourceReadySignal(void)
1654 tet_infoline("Test Setting Image that was already loaded by another ImageView and still getting ResourceReadySignal when staged.");
1656 ToolkitTestApplication application;
1660 ImageView imageView = ImageView::New();
1661 imageView.ResourceReadySignal().Connect( &ResourceFailedReload );
1662 DALI_TEST_EQUALS( gFailCounter, 0, TEST_LOCATION );
1663 ReloadImage(imageView);
1665 // loading started, this waits for the loader thread to complete
1666 DALI_TEST_EQUALS( Test::WaitForEventThreadTrigger( 1 ), true, TEST_LOCATION );
1667 application.SendNotification();
1669 DALI_TEST_EQUALS( gFailCounter, 1, TEST_LOCATION );
1671 DALI_TEST_EQUALS( Test::WaitForEventThreadTrigger( 1 ), true, TEST_LOCATION );
1672 application.SendNotification();
1674 DALI_TEST_EQUALS( gFailCounter, 2, TEST_LOCATION );
1676 DALI_TEST_EQUALS( Test::WaitForEventThreadTrigger( 1 ), true, TEST_LOCATION );
1677 application.SendNotification();
1678 DALI_TEST_EQUALS( gFailCounter, 3, TEST_LOCATION );
1683 int UtcDaliImageViewCustomShader(void)
1685 ToolkitTestApplication application;
1687 // Set a custom shader with an image url
1689 Property::Map properties;
1690 Property::Map shader;
1691 const std::string vertexShader = "Foobar";
1692 const std::string fragmentShader = "Foobar";
1693 shader[Visual::Shader::Property::FRAGMENT_SHADER] = fragmentShader;
1694 shader[Visual::Shader::Property::VERTEX_SHADER] = vertexShader;
1696 properties[Visual::Property::TYPE] = Visual::IMAGE;
1697 properties[Visual::Property::SHADER] = shader;
1698 properties[ImageVisual::Property::URL] = TEST_IMAGE_FILE_NAME;
1700 ImageView imageView = ImageView::New();
1701 imageView.SetProperty( ImageView::Property::IMAGE, properties );
1703 Stage::GetCurrent().Add( imageView );
1705 application.SendNotification();
1706 application.Render();
1708 DALI_TEST_EQUALS( Test::WaitForEventThreadTrigger( 1 ), true, TEST_LOCATION );
1710 Renderer renderer = imageView.GetRendererAt( 0 );
1711 Shader shader2 = renderer.GetShader();
1712 Property::Value value = shader2.GetProperty( Shader::Property::PROGRAM );
1713 Property::Map* map = value.GetMap();
1714 DALI_TEST_CHECK( map );
1716 Property::Value* fragment = map->Find( "fragment" ); // fragment key name from shader-impl.cpp
1717 DALI_TEST_EQUALS( fragmentShader, fragment->Get< std::string >(), TEST_LOCATION );
1719 Property::Value* vertex = map->Find( "vertex" ); // vertex key name from shader-impl.cpp
1720 DALI_TEST_EQUALS( vertexShader, vertex->Get< std::string >(), TEST_LOCATION );
1723 // Set a custom shader after setting an image url
1725 Property::Map properties;
1726 Property::Map shader;
1727 const std::string vertexShader = "Foobar";
1728 const std::string fragmentShader = "Foobar";
1729 shader[Visual::Shader::Property::FRAGMENT_SHADER] = fragmentShader;
1730 shader[Visual::Shader::Property::VERTEX_SHADER] = vertexShader;
1732 properties[Visual::Property::SHADER] = shader;
1734 ImageView imageView = ImageView::New( TEST_IMAGE_FILE_NAME );
1735 imageView.SetProperty( ImageView::Property::IMAGE, properties );
1737 Stage::GetCurrent().Add( imageView );
1739 application.SendNotification();
1740 application.Render();
1742 Renderer renderer = imageView.GetRendererAt( 0 );
1743 Shader shader2 = renderer.GetShader();
1744 Property::Value value = shader2.GetProperty( Shader::Property::PROGRAM );
1745 Property::Map* map = value.GetMap();
1746 DALI_TEST_CHECK( map );
1748 Property::Value* fragment = map->Find( "fragment" ); // fragment key name from shader-impl.cpp
1749 DALI_TEST_EQUALS( fragmentShader, fragment->Get< std::string >(), TEST_LOCATION );
1751 Property::Value* vertex = map->Find( "vertex" ); // vertex key name from shader-impl.cpp
1752 DALI_TEST_EQUALS( vertexShader, vertex->Get< std::string >(), TEST_LOCATION );
1755 // Set a custom shader before setting an image url
1757 Property::Map properties;
1758 Property::Map shader;
1759 const std::string vertexShader = "Foobar";
1760 const std::string fragmentShader = "Foobar";
1761 shader[Visual::Shader::Property::FRAGMENT_SHADER] = fragmentShader;
1762 shader[Visual::Shader::Property::VERTEX_SHADER] = vertexShader;
1764 properties[Visual::Property::SHADER] = shader;
1766 ImageView imageView = ImageView::New();
1767 imageView.SetProperty( ImageView::Property::IMAGE, properties );
1768 imageView.SetProperty( ImageView::Property::IMAGE, TEST_IMAGE_FILE_NAME );
1770 Stage::GetCurrent().Add( imageView );
1772 application.SendNotification();
1773 application.Render();
1775 Renderer renderer = imageView.GetRendererAt( 0 );
1776 Shader shader2 = renderer.GetShader();
1777 Property::Value value = shader2.GetProperty( Shader::Property::PROGRAM );
1778 Property::Map* map = value.GetMap();
1779 DALI_TEST_CHECK( map );
1781 Property::Value* fragment = map->Find( "fragment" ); // fragment key name from shader-impl.cpp
1782 DALI_TEST_EQUALS( fragmentShader, fragment->Get< std::string >(), TEST_LOCATION );
1784 Property::Value* vertex = map->Find( "vertex" ); // vertex key name from shader-impl.cpp
1785 DALI_TEST_EQUALS( vertexShader, vertex->Get< std::string >(), TEST_LOCATION );
1788 // Set a custom shader after setting a property map
1790 Property::Map properties;
1791 Property::Map shader;
1792 const std::string vertexShader = "Foobar";
1793 const std::string fragmentShader = "Foobar";
1794 shader[Visual::Shader::Property::FRAGMENT_SHADER] = fragmentShader;
1795 shader[Visual::Shader::Property::VERTEX_SHADER] = vertexShader;
1797 properties[Visual::Property::SHADER] = shader;
1799 Property::Map properties1;
1800 properties1[Visual::Property::TYPE] = Visual::IMAGE;
1801 properties1[ImageVisual::Property::URL] = TEST_IMAGE_FILE_NAME;
1803 ImageView imageView = ImageView::New();
1804 imageView.SetProperty( ImageView::Property::IMAGE, properties1 );
1805 imageView.SetProperty( ImageView::Property::IMAGE, properties );
1807 Stage::GetCurrent().Add( imageView );
1809 application.SendNotification();
1810 application.Render();
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 before setting a property map
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 Property::Map properties1;
1837 properties1[Visual::Property::TYPE] = Visual::IMAGE;
1838 properties1[ImageVisual::Property::URL] = TEST_IMAGE_FILE_NAME;
1840 ImageView imageView = ImageView::New();
1841 imageView.SetProperty( ImageView::Property::IMAGE, properties );
1842 imageView.SetProperty( ImageView::Property::IMAGE, properties1 );
1844 Stage::GetCurrent().Add( imageView );
1846 application.SendNotification();
1847 application.Render();
1849 Renderer renderer = imageView.GetRendererAt( 0 );
1850 Shader shader2 = renderer.GetShader();
1851 Property::Value value = shader2.GetProperty( Shader::Property::PROGRAM );
1852 Property::Map* map = value.GetMap();
1853 DALI_TEST_CHECK( map );
1855 Property::Value* fragment = map->Find( "fragment" ); // fragment key name from shader-impl.cpp
1856 DALI_TEST_EQUALS( fragmentShader, fragment->Get< std::string >(), TEST_LOCATION );
1858 Property::Value* vertex = map->Find( "vertex" ); // vertex key name from shader-impl.cpp
1859 DALI_TEST_EQUALS( vertexShader, vertex->Get< std::string >(), TEST_LOCATION );