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 );
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 // loading started, this waits for the loader thread for max 30 seconds
493 DALI_TEST_EQUALS( Test::WaitForEventThreadTrigger( 1 ), true, TEST_LOCATION );
495 application.SendNotification();
496 application.Render(16);
498 callStack.Enable(false);
500 TraceCallStack::NamedParams params;
501 params["width"] = ToString(34);
502 params["height"] = ToString(34);
503 DALI_TEST_EQUALS( callStack.FindMethodAndParams( "TexSubImage2D", params ), true, TEST_LOCATION );
508 int UtcDaliImageViewAsyncLoadingWithAtlasing02(void)
510 ToolkitTestApplication application;
512 //Async loading, automatic atlasing for small size image
513 TraceCallStack& callStack = application.GetGlAbstraction().GetTextureTrace();
515 callStack.Enable(true);
517 Property::Map asyncLoadingMap;
518 asyncLoadingMap[ "url" ] = gImage_34_RGBA;
519 asyncLoadingMap[ "desiredHeight" ] = 34;
520 asyncLoadingMap[ "desiredWidth" ] = 34;
521 asyncLoadingMap[ "synchronousLoading" ] = false;
522 asyncLoadingMap[ "atlasing" ] = true;
524 ImageView imageView = ImageView::New();
525 imageView.SetProperty( ImageView::Property::IMAGE, asyncLoadingMap );
527 Stage::GetCurrent().Add( imageView );
528 application.SendNotification();
529 application.Render(16);
530 application.Render(16);
531 application.SendNotification();
533 // loading started, this waits for the loader thread for max 30 seconds
534 DALI_TEST_EQUALS( Test::WaitForEventThreadTrigger( 1 ), true, TEST_LOCATION );
536 application.SendNotification();
537 application.Render(16);
539 callStack.Enable(false);
541 TraceCallStack::NamedParams params;
542 params["width"] = ToString(34);
543 params["height"] = ToString(34);
544 DALI_TEST_EQUALS( callStack.FindMethodAndParams( "TexSubImage2D", params ), true, TEST_LOCATION );
549 int UtcDaliImageViewSyncLoading(void)
551 ToolkitTestApplication application;
553 tet_infoline("ImageView Testing sync loading and size using index key property map");
555 Property::Map syncLoadingMap;
556 syncLoadingMap[ ImageVisual::Property::SYNCHRONOUS_LOADING ] = true;
557 syncLoadingMap[ ImageVisual::Property::ATLASING ] = true;
559 // Sync loading, no atlasing for big size image
561 ImageView imageView = ImageView::New();
563 // Sync loading is used
564 syncLoadingMap[ ImageVisual::Property::URL ] = gImage_600_RGB;
565 imageView.SetProperty( ImageView::Property::IMAGE, syncLoadingMap );
568 // Sync loading, automatic atlasing for small size image
570 TraceCallStack& callStack = application.GetGlAbstraction().GetTextureTrace();
572 callStack.Enable(true);
574 ImageView imageView = ImageView::New( );
576 // Sync loading is used
577 syncLoadingMap[ ImageVisual::Property::URL ] = gImage_34_RGBA;
578 syncLoadingMap[ ImageVisual::Property::DESIRED_HEIGHT ] = 34;
579 syncLoadingMap[ ImageVisual::Property::DESIRED_WIDTH ] = 34;
580 imageView.SetProperty( ImageView::Property::IMAGE, syncLoadingMap );
582 Stage::GetCurrent().Add( imageView );
583 application.SendNotification();
584 application.Render(16);
586 TraceCallStack::NamedParams params;
587 params["width"] = ToString(34);
588 params["height"] = ToString(34);
589 DALI_TEST_EQUALS( callStack.FindMethodAndParams( "TexSubImage2D", params ),
590 true, TEST_LOCATION );
595 int UtcDaliImageViewSyncLoading02(void)
597 ToolkitTestApplication application;
599 tet_infoline("ImageView Testing sync loading and size using string key property map");
601 // Sync loading, automatic atlasing for small size image
603 TraceCallStack& callStack = application.GetGlAbstraction().GetTextureTrace();
605 callStack.Enable(true);
607 ImageView imageView = ImageView::New( );
609 // Sync loading is used
610 Property::Map syncLoadingMap;
611 syncLoadingMap[ "url" ] = gImage_34_RGBA;
612 syncLoadingMap[ "desiredHeight" ] = 34;
613 syncLoadingMap[ "desiredWidth" ] = 34;
614 syncLoadingMap[ "synchronousLoading" ] = true;
615 syncLoadingMap[ "atlasing" ] = true;
616 imageView.SetProperty( ImageView::Property::IMAGE, syncLoadingMap );
618 Stage::GetCurrent().Add( imageView );
619 application.SendNotification();
620 application.Render(16);
622 TraceCallStack::NamedParams params;
623 params["width"] = ToString(34);
624 params["height"] = ToString(34);
625 DALI_TEST_EQUALS( callStack.FindMethodAndParams( "TexSubImage2D", params ),
626 true, TEST_LOCATION );
631 int UtcDaliImageViewAddedTexture(void)
633 ToolkitTestApplication application;
635 tet_infoline("ImageView Testing image view with texture provided manager url");
637 ImageView imageView = ImageView::New();
639 // empty texture is ok, though pointless from app point of view
641 std::string url = TextureManager::AddTexture(empty);
642 DALI_TEST_CHECK(url.size() > 0u);
644 Property::Map propertyMap;
645 propertyMap[ImageVisual::Property::URL] = url;
646 imageView.SetProperty(ImageView::Property::IMAGE, propertyMap);
648 Stage::GetCurrent().Add( imageView );
649 application.SendNotification();
650 application.Render();
655 int UtcDaliImageViewSizeWithBackground(void)
657 ToolkitTestApplication application;
661 Image image = CreateBufferImage( width, height, Vector4(1.f, 1.f, 1.f, 1.f) );
662 ImageView imageView = ImageView::New();
663 imageView.SetBackgroundImage( image );
665 Stage::GetCurrent().Add( imageView );
666 application.SendNotification();
667 application.Render();
669 DALI_TEST_EQUALS( imageView.GetCurrentSize().width, (float)width, TEST_LOCATION );
670 DALI_TEST_EQUALS( imageView.GetCurrentSize().height, (float)height, TEST_LOCATION );
675 int UtcDaliImageViewSizeWithBackgroundAndImage(void)
677 ToolkitTestApplication application;
679 int widthBackground = 100;
680 int heightBackground = 200;
683 Image imageBackground = CreateBufferImage( widthBackground, heightBackground, Vector4(1.f, 1.f, 1.f, 1.f) );
684 Image image = CreateBufferImage( width, height, Vector4(1.f, 1.f, 1.f, 1.f) );
686 ImageView imageView = ImageView::New();
687 imageView.SetBackgroundImage( imageBackground );
688 imageView.SetImage( image );
690 Stage::GetCurrent().Add( imageView );
691 application.SendNotification();
692 application.Render();
694 DALI_TEST_EQUALS( imageView.GetCurrentSize().width, (float)width, TEST_LOCATION );
695 DALI_TEST_EQUALS( imageView.GetCurrentSize().height, (float)height, TEST_LOCATION );
700 int UtcDaliImageViewHeightForWidthBackground(void)
702 ToolkitTestApplication application;
704 int widthBackground = 100;
705 int heightBackground = 200;
706 Image imageBackground = CreateBufferImage( widthBackground, heightBackground, Vector4(1.f, 1.f, 1.f, 1.f) );
708 ImageView imageView = ImageView::New();
709 imageView.SetBackgroundImage( imageBackground );
711 Stage::GetCurrent().Add( imageView );
712 application.SendNotification();
713 application.Render();
715 Control control = Control::DownCast( imageView );
716 DALI_TEST_CHECK( control );
717 DALI_TEST_EQUALS( imageView.GetHeightForWidth( 123.f ), control.GetHeightForWidth( 123.f ), TEST_LOCATION );
718 DALI_TEST_EQUALS( imageView.GetWidthForHeight( 321.f ), control.GetWidthForHeight( 321.f ), TEST_LOCATION );
723 int UtcDaliImageViewHeightForWidthBackgroundAndImage(void)
725 ToolkitTestApplication application;
727 int widthBackground = 100;
728 int heightBackground = 200;
731 Image imageBackground = CreateBufferImage( widthBackground, heightBackground, Vector4(1.f, 1.f, 1.f, 1.f) );
732 Image image = CreateBufferImage( width, height, Vector4(1.f, 1.f, 1.f, 1.f) );
734 ImageView imageView = ImageView::New();
735 imageView.SetBackgroundImage( imageBackground );
736 imageView.SetImage( image );
738 Stage::GetCurrent().Add( imageView );
739 application.SendNotification();
740 application.Render();
742 DALI_TEST_EQUALS( imageView.GetHeightForWidth( width ), (float)height, TEST_LOCATION );
743 DALI_TEST_EQUALS( imageView.GetWidthForHeight( height ), (float)width, TEST_LOCATION );
748 int UtcDaliImageViewSetBufferImage(void)
750 ToolkitTestApplication application;
754 BufferImage image1 = CreateBufferImage( width1, height1, Vector4( 1.f, 1.f, 1.f, 1.f ) );
755 ImageView imageView = ImageView::New();
756 imageView.SetImage( image1 );
758 TestImage( imageView, image1 );
762 BufferImage image2 = CreateBufferImage( width2, height2, Vector4( 1.f, 1.f, 1.f, 1.f ) );
763 imageView.SetImage( image2 );
765 TestImage( imageView, image2 );
770 int UtcDaliImageViewSetImageUrl(void)
772 ToolkitTestApplication application;
774 ImageView imageView = ImageView::New();
775 imageView.SetImage( TEST_IMAGE_FILE_NAME );
776 TestUrl( imageView, TEST_IMAGE_FILE_NAME );
779 imageView.SetImage( TEST_IMAGE_FILE_NAME2 );
780 TestUrl( imageView, TEST_IMAGE_FILE_NAME2 );
785 int UtcDaliImageViewSetImageOnstageP(void)
787 ToolkitTestApplication application;
789 ImageView imageView = ImageView::New();
791 Stage::GetCurrent().Add( imageView );
792 application.SendNotification();
793 application.Render();
795 ResourceImage image1 = ResourceImage::New( TEST_IMAGE_FILE_NAME );
796 imageView.SetImage( image1 );
797 TestImage( imageView, image1 );
801 BufferImage image2 = CreateBufferImage( width, height, Vector4( 1.f, 1.f, 1.f, 1.f ) );
802 imageView.SetImage( image2 );
803 TestImage( imageView, image2 );
808 int UtcDaliImageViewSetImageOnstageN(void)
810 ToolkitTestApplication application;
812 ImageView imageView = ImageView::New();
814 Stage::GetCurrent().Add( imageView );
815 application.SendNotification();
816 application.Render();
818 ResourceImage image1 = ResourceImage::New( TEST_IMAGE_FILE_NAME );
819 imageView.SetImage( image1 );
820 TestImage( imageView, image1 );
823 imageView.SetImage( image2 );
825 Property::Value value = imageView.GetProperty( imageView.GetPropertyIndex( "image" ) );
827 //the value should be empty
829 DALI_TEST_CHECK( !value.Get( url ) );
832 DALI_TEST_CHECK( !value.Get( map ) );
837 int UtcDaliImageViewSetImageOffstageP(void)
839 ToolkitTestApplication application;
841 ImageView imageView = ImageView::New();
843 Stage::GetCurrent().Add( imageView );
844 application.SendNotification();
845 application.Render();
846 Stage::GetCurrent().Remove( imageView );
848 ResourceImage image1 = ResourceImage::New( TEST_IMAGE_FILE_NAME );
849 imageView.SetImage( image1 );
850 TestImage( imageView, image1 );
854 BufferImage image2 = CreateBufferImage( width, height, Vector4( 1.f, 1.f, 1.f, 1.f ) );
855 imageView.SetImage( image2 );
856 TestImage( imageView, image2 );
861 bool gResourceReadySignalFired = false;
862 Vector3 gNaturalSize;
864 void ResourceReadySignal( Control control )
866 gResourceReadySignalFired = true;
869 int UtcDaliImageViewCheckResourceReady(void)
871 ToolkitTestApplication application;
873 gResourceReadySignalFired = false;
878 Image image = CreateBufferImage( width, height, Vector4(1.f, 1.f, 1.f, 1.f) );
880 // Check ImageView with background and main image, to ensure both visuals are marked as loaded
881 ImageView imageView = ImageView::New( TEST_GIF_FILE_NAME );
883 imageView.SetBackgroundImage( image );
885 DALI_TEST_EQUALS( imageView.IsResourceReady(), false, TEST_LOCATION );
887 imageView.ResourceReadySignal().Connect( &ResourceReadySignal);
889 Stage::GetCurrent().Add( imageView );
891 application.SendNotification();
892 application.Render(16);
895 DALI_TEST_EQUALS( imageView.IsResourceReady(), true, TEST_LOCATION );
897 DALI_TEST_EQUALS( gResourceReadySignalFired, true, TEST_LOCATION );
902 int UtcDaliImageViewSetImageOffstageN(void)
904 ToolkitTestApplication application;
906 ImageView imageView = ImageView::New();
908 Stage::GetCurrent().Add( imageView );
909 application.SendNotification();
910 application.Render();
911 Stage::GetCurrent().Remove( imageView );
913 ResourceImage image1 = ResourceImage::New( TEST_IMAGE_FILE_NAME );
914 imageView.SetImage( image1 );
915 TestImage( imageView, image1 );
918 imageView.SetImage( image2 );
920 Property::Value value = imageView.GetProperty( imageView.GetPropertyIndex( "image" ) );
922 //the value should be empty
924 DALI_TEST_CHECK( !value.Get( url ) );
927 DALI_TEST_CHECK( !value.Get( map ) );
932 int UtcDaliImageViewSetImageN(void)
934 ToolkitTestApplication application;
937 ImageView imageView = ImageView::New();
938 imageView.SetImage( image1 );
940 Property::Value value = imageView.GetProperty( imageView.GetPropertyIndex( "image" ) );
942 //the value should be empty
944 DALI_TEST_CHECK( !value.Get( url ) );
947 DALI_TEST_CHECK( !value.Get( map ) );
949 std::string resource_url;
950 Property::Value val = imageView.GetProperty( imageView.GetPropertyIndex( "image" ) );
951 DALI_TEST_CHECK( !val.Get( resource_url ) );
956 int UtcDaliImageViewSetImageTypeChangesP(void)
958 ToolkitTestApplication application;
960 ImageView imageView = ImageView::New();
961 Toolkit::Internal::Control& controlImpl = Toolkit::Internal::GetImplementation( imageView );
963 Stage::GetCurrent().Add( imageView );
967 Toolkit::Visual::Base visual;
969 Property::Value value = imageView.GetProperty( imageView.GetPropertyIndex( "image" ) );
970 visual = DevelControl::GetVisual( controlImpl, ImageView::Property::IMAGE );
972 application.SendNotification();
973 application.Render( 16 );
975 DALI_TEST_CHECK( ! value.Get( url ) ); // Value should be empty
976 DALI_TEST_CHECK( ! value.Get( map ) ); // Value should be empty
977 DALI_TEST_CHECK( ! visual ); // Visual should be invalid
980 imageView.SetImage( "TEST_URL" );
982 application.SendNotification();
983 application.Render( 16 );
985 value = imageView.GetProperty( imageView.GetPropertyIndex( "image" ) );
986 visual = DevelControl::GetVisual( controlImpl, ImageView::Property::IMAGE );
988 DALI_TEST_CHECK( value.Get( url ) ); // Value should NOT be empty
989 DALI_TEST_CHECK( ! value.Get( map ) ); // Value should be empty
990 DALI_TEST_CHECK( visual ); // Visual should be valid
992 // Set an empty Image
993 imageView.SetImage( Image() );
995 application.SendNotification();
996 application.Render( 16 );
998 value = imageView.GetProperty( imageView.GetPropertyIndex( "image" ) );
999 visual = DevelControl::GetVisual( controlImpl, ImageView::Property::IMAGE );
1001 DALI_TEST_CHECK( ! value.Get( url ) ); // Value should be empty
1002 DALI_TEST_CHECK( ! value.Get( map ) ); // Value should be empty
1003 DALI_TEST_CHECK( ! visual ); // Visual should be invalid
1006 ResourceImage image1 = ResourceImage::New( TEST_IMAGE_FILE_NAME );
1007 imageView.SetImage( image1 );
1009 application.SendNotification();
1010 application.Render( 16 );
1012 value = imageView.GetProperty( imageView.GetPropertyIndex( "image" ) );
1013 visual = DevelControl::GetVisual( controlImpl, ImageView::Property::IMAGE );
1015 DALI_TEST_CHECK( ! value.Get( url ) ); // Value should be empty
1016 DALI_TEST_CHECK( value.Get( map ) ); // Value should NOT be empty
1017 DALI_TEST_CHECK( visual ); // Visual should be valid
1020 imageView.SetImage( "" );
1022 application.SendNotification();
1023 application.Render( 16 );
1025 value = imageView.GetProperty( imageView.GetPropertyIndex( "image" ) );
1026 visual = DevelControl::GetVisual( controlImpl, ImageView::Property::IMAGE );
1028 DALI_TEST_CHECK( ! value.Get( url ) ); // Value should be empty
1029 DALI_TEST_CHECK( ! value.Get( map ) ); // Value should be empty
1030 DALI_TEST_CHECK( ! visual ); // Visual should be invalid
1032 // Set a URL in property map
1033 Property::Map propertyMap;
1034 propertyMap[ImageVisual::Property::URL] = TEST_IMAGE_FILE_NAME;
1035 imageView.SetProperty( ImageView::Property::IMAGE, propertyMap );
1037 application.SendNotification();
1038 application.Render( 16 );
1040 value = imageView.GetProperty( imageView.GetPropertyIndex( "image" ) );
1041 visual = DevelControl::GetVisual( controlImpl, ImageView::Property::IMAGE );
1043 DALI_TEST_CHECK( ! value.Get( url ) ); // Value should be empty
1044 DALI_TEST_CHECK( value.Get( map ) ); // Value should NOT be empty
1045 DALI_TEST_CHECK( visual ); // Visual should be valid
1047 // Set a URL in property map again
1048 propertyMap[ImageVisual::Property::URL] = gImage_34_RGBA;
1049 imageView.SetProperty( ImageView::Property::IMAGE, propertyMap );
1051 application.SendNotification();
1052 application.Render( 16 );
1054 value = imageView.GetProperty( imageView.GetPropertyIndex( "image" ) );
1055 visual = DevelControl::GetVisual( controlImpl, ImageView::Property::IMAGE );
1057 DALI_TEST_CHECK( ! value.Get( url ) ); // Value should be empty
1058 DALI_TEST_CHECK( value.Get( map ) ); // Value should NOT be empty
1059 DALI_TEST_CHECK( visual ); // Visual should be valid
1061 // Set an empty URL in property map
1062 propertyMap[ImageVisual::Property::URL] = std::string();
1063 imageView.SetProperty( ImageView::Property::IMAGE, propertyMap );
1065 application.SendNotification();
1066 application.Render( 16 );
1068 value = imageView.GetProperty( imageView.GetPropertyIndex( "image" ) );
1069 visual = DevelControl::GetVisual( controlImpl, ImageView::Property::IMAGE );
1071 DALI_TEST_CHECK( ! value.Get( url ) ); // Value should be empty
1072 DALI_TEST_CHECK( value.Get( map ) ); // Value should NOT be empty
1073 DALI_TEST_CHECK( ! visual ); // Visual should be invalid
1078 int UtcDaliImageViewResourceUrlP(void)
1080 ToolkitTestApplication application;
1082 ImageView imageView = ImageView::New();
1083 DALI_TEST_CHECK( imageView.GetProperty( ImageView::Property::RESOURCE_URL ).Get< std::string >().empty() );
1085 imageView.SetProperty( ImageView::Property::RESOURCE_URL, "TestString" );
1086 DALI_TEST_EQUALS( imageView.GetProperty( ImageView::Property::RESOURCE_URL ).Get< std::string >(), "TestString", TEST_LOCATION );
1091 // Scenarios 1: ImageView from regular image
1092 int UtcDaliImageViewSetImageBufferImage(void)
1094 ToolkitTestApplication application;
1096 ImageView imageView = ImageView::New();
1097 Stage::GetCurrent().Add( imageView );
1099 TestGlAbstraction& gl = application.GetGlAbstraction();
1100 gl.EnableTextureCallTrace( true );
1102 std::vector< GLuint > ids;
1103 ids.push_back( 23 );
1104 application.GetGlAbstraction().SetNextTextureIds( ids );
1108 BufferImage image = CreateBufferImage( width, height, Color::WHITE );
1110 imageView.SetImage( image );
1112 application.SendNotification();
1113 application.Render();
1115 DALI_TEST_CHECK( gl.GetTextureTrace().FindMethod("BindTexture") );
1117 std::stringstream params;
1118 params << GL_TEXTURE_2D << ", " << 23;
1119 DALI_TEST_CHECK( gl.GetTextureTrace().FindMethodAndParams("BindTexture", params.str()) );
1124 // Scenarios 2: ImageView from Native image
1125 int UtcDaliImageViewSetImageNativeImage(void)
1127 ToolkitTestApplication application;
1129 ImageView imageView = ImageView::New();
1130 Stage::GetCurrent().Add( imageView );
1132 TestGlAbstraction& gl = application.GetGlAbstraction();
1133 gl.EnableTextureCallTrace( true );
1135 std::vector< GLuint > ids;
1136 ids.push_back( 23 );
1137 application.GetGlAbstraction().SetNextTextureIds( ids );
1141 TestNativeImagePointer nativeImageInterface = TestNativeImage::New( width, height );
1142 NativeImage nativeImage = NativeImage::New( *(nativeImageInterface.Get()) );
1144 imageView.SetImage( nativeImage );
1145 application.SendNotification();
1146 application.Render();
1148 DALI_TEST_CHECK( gl.GetTextureTrace().FindMethod("BindTexture") );
1150 std::stringstream params;
1151 params << GL_TEXTURE_EXTERNAL_OES << ", " << 23;
1152 DALI_TEST_CHECK( gl.GetTextureTrace().FindMethodAndParams("BindTexture", params.str()) );
1157 // Scenarios 3: ImageView initially from regular image but then SetImage called with Native image
1158 int UtcDaliImageViewSetImageBufferImageToNativeImage(void)
1160 ToolkitTestApplication application;
1164 BufferImage image = CreateBufferImage( width, height, Color::WHITE );
1166 ImageView imageView = ImageView::New( image );
1167 Stage::GetCurrent().Add( imageView );
1169 TestGlAbstraction& gl = application.GetGlAbstraction();
1170 gl.EnableTextureCallTrace( true );
1172 std::vector< GLuint > ids;
1173 ids.push_back( 23 );
1174 application.GetGlAbstraction().SetNextTextureIds( ids );
1176 application.SendNotification();
1177 application.Render();
1179 DALI_TEST_CHECK( gl.GetTextureTrace().FindMethod("BindTexture") );
1181 std::stringstream params;
1182 params << GL_TEXTURE_2D << ", " << 23;
1183 DALI_TEST_CHECK( gl.GetTextureTrace().FindMethodAndParams("BindTexture", params.str()) );
1187 TestNativeImagePointer nativeImageInterface = TestNativeImage::New( width, height );
1188 NativeImage nativeImage = NativeImage::New( *(nativeImageInterface.Get()) );
1189 imageView.SetImage( nativeImage );
1192 ids.push_back( 24 );
1193 application.GetGlAbstraction().SetNextTextureIds( ids );
1195 application.SendNotification();
1196 application.Render();
1198 DALI_TEST_CHECK( gl.GetTextureTrace().FindMethod("BindTexture") );
1200 std::stringstream nextTextureParams;
1201 nextTextureParams << GL_TEXTURE_EXTERNAL_OES << ", " << 24;
1202 DALI_TEST_CHECK( gl.GetTextureTrace().FindMethodAndParams("BindTexture", nextTextureParams.str()) );
1207 // Scenarios 4: ImageView initially from Native image but then SetImage called with regular image
1208 int UtcDaliImageViewSetImageNativeImageToBufferImage(void)
1210 ToolkitTestApplication application;
1214 TestNativeImagePointer nativeImageInterface = TestNativeImage::New( width, height );
1215 NativeImage nativeImage = NativeImage::New( *(nativeImageInterface.Get()) );
1217 ImageView imageView = ImageView::New( nativeImage );
1218 Stage::GetCurrent().Add( imageView );
1220 TestGlAbstraction& gl = application.GetGlAbstraction();
1221 gl.EnableTextureCallTrace( true );
1223 std::vector< GLuint > ids;
1224 ids.push_back( 23 );
1225 application.GetGlAbstraction().SetNextTextureIds( ids );
1227 application.SendNotification();
1228 application.Render();
1230 DALI_TEST_CHECK( gl.GetTextureTrace().FindMethod("BindTexture") );
1232 std::stringstream params;
1233 params << GL_TEXTURE_EXTERNAL_OES << ", " << 23;
1234 DALI_TEST_CHECK( gl.GetTextureTrace().FindMethodAndParams("BindTexture", params.str()) );
1238 BufferImage image = CreateBufferImage( width, height, Color::WHITE );
1239 imageView.SetImage( image );
1242 ids.push_back( 24 );
1243 application.GetGlAbstraction().SetNextTextureIds( ids );
1245 application.SendNotification();
1246 application.Render();
1248 DALI_TEST_CHECK( gl.GetTextureTrace().FindMethod("BindTexture") );
1250 std::stringstream nextTextureParams;
1251 nextTextureParams << GL_TEXTURE_2D << ", " << 24;
1252 DALI_TEST_CHECK( gl.GetTextureTrace().FindMethodAndParams("BindTexture", nextTextureParams.str()) );
1257 // Scenarios 5: ImageView from Native image with custom shader
1258 int UtcDaliImageViewSetImageNativeImageWithCustomShader(void)
1260 ToolkitTestApplication application;
1265 Property::Map customShader;
1266 customShader.Insert( "vertexShader", VERTEX_SHADER );
1267 customShader.Insert( "fragmentShader", FRAGMENT_SHADER );
1269 Property::Array shaderHints;
1270 shaderHints.PushBack( "requiresSelfDepthTest" );
1271 shaderHints.PushBack( "outputIsTransparent" );
1272 shaderHints.PushBack( "outputIsOpaque" );
1273 shaderHints.PushBack( "modifiesGeometry" );
1275 customShader.Insert( "hints", shaderHints );
1278 map.Insert( "shader", customShader );
1280 TestNativeImagePointer nativeImageInterface = TestNativeImage::New( width, height );
1281 NativeImage nativeImage = NativeImage::New( *(nativeImageInterface.Get()) );
1283 ImageView imageView = ImageView::New( nativeImage );
1284 imageView.SetProperty( ImageView::Property::IMAGE, map );
1285 Stage::GetCurrent().Add( imageView );
1287 TestGlAbstraction& gl = application.GetGlAbstraction();
1288 gl.EnableTextureCallTrace( true );
1290 std::vector< GLuint > ids;
1291 ids.push_back( 23 );
1292 application.GetGlAbstraction().SetNextTextureIds( ids );
1294 application.SendNotification();
1295 application.Render();
1297 DALI_TEST_CHECK( gl.GetTextureTrace().FindMethod("BindTexture") );
1299 std::stringstream params;
1300 params << GL_TEXTURE_EXTERNAL_OES << ", " << 23;
1301 DALI_TEST_CHECK( gl.GetTextureTrace().FindMethodAndParams("BindTexture", params.str()) );
1306 // Scenarios 6: ImageView initially from regular image with custom shader but then SetImage called with Native
1307 int UtcDaliImageViewSetImageBufferImageWithCustomShaderToNativeImage(void)
1309 ToolkitTestApplication application;
1314 Property::Map customShader;
1315 customShader.Insert( "vertexShader", VERTEX_SHADER );
1316 customShader.Insert( "fragmentShader", FRAGMENT_SHADER );
1318 Property::Array shaderHints;
1319 shaderHints.PushBack( "requiresSelfDepthTest" );
1320 shaderHints.PushBack( "outputIsTransparent" );
1321 shaderHints.PushBack( "outputIsOpaque" );
1322 shaderHints.PushBack( "modifiesGeometry" );
1324 customShader.Insert( "hints", shaderHints );
1327 map.Insert( "shader", customShader );
1329 BufferImage image = CreateBufferImage( width, height, Color::WHITE );
1331 ImageView imageView = ImageView::New( image );
1332 imageView.SetProperty( ImageView::Property::IMAGE, map );
1333 Stage::GetCurrent().Add( imageView );
1335 TestGlAbstraction& gl = application.GetGlAbstraction();
1336 gl.EnableTextureCallTrace( true );
1338 std::vector< GLuint > ids;
1339 ids.push_back( 23 );
1340 application.GetGlAbstraction().SetNextTextureIds( ids );
1342 application.SendNotification();
1343 application.Render();
1345 DALI_TEST_CHECK( gl.GetTextureTrace().FindMethod("BindTexture") );
1347 std::stringstream params;
1348 params << GL_TEXTURE_2D << ", " << 23;
1349 DALI_TEST_CHECK( gl.GetTextureTrace().FindMethodAndParams("BindTexture", params.str()) );
1351 TestNativeImagePointer nativeImageInterface = TestNativeImage::New( width, height );
1352 NativeImage nativeImage = NativeImage::New( *(nativeImageInterface.Get()) );
1353 imageView.SetImage( nativeImage );
1356 ids.push_back( 24 );
1357 application.GetGlAbstraction().SetNextTextureIds( ids );
1359 application.SendNotification();
1360 application.Render();
1362 DALI_TEST_CHECK( gl.GetTextureTrace().FindMethod("BindTexture") );
1364 std::stringstream nativeImageParams;
1365 nativeImageParams << GL_TEXTURE_EXTERNAL_OES << ", " << 24;
1366 DALI_TEST_CHECK( gl.GetTextureTrace().FindMethodAndParams("BindTexture", nativeImageParams.str()) );
1372 int UtcDaliImageViewGetImageP1(void)
1374 ToolkitTestApplication application;
1376 ImageView imageView = ImageView::New();
1377 DALI_TEST_CHECK( ! imageView.GetImage() );
1379 Image image = CreateBufferImage();
1380 imageView.SetImage( image );
1381 DALI_TEST_CHECK( imageView.GetImage() == image );
1386 int UtcDaliImageViewGetImageP2(void)
1388 ToolkitTestApplication application;
1390 BufferImage image = CreateBufferImage();
1391 ImageView imageView = ImageView::New( image );
1392 DALI_TEST_CHECK( imageView.GetImage() == image );
1397 int UtcDaliImageViewGetImageN(void)
1399 ToolkitTestApplication application;
1401 ImageView imageView = ImageView::New( TEST_IMAGE_FILE_NAME );
1402 DALI_TEST_CHECK( ! imageView.GetImage() );
1404 Image image = CreateBufferImage();
1405 imageView.SetImage( image );
1406 DALI_TEST_CHECK( imageView.GetImage() == image );
1408 imageView.SetImage( TEST_IMAGE_FILE_NAME );
1409 DALI_TEST_CHECK( ! imageView.GetImage() );
1415 int UtcDaliImageViewReplaceImage(void)
1417 ToolkitTestApplication application;
1419 gResourceReadySignalFired = false;
1423 Image image = CreateBufferImage( width, height, Vector4(1.f, 1.f, 1.f, 1.f) );
1425 // Check ImageView with background and main image, to ensure both visuals are marked as loaded
1426 ImageView imageView = ImageView::New( TEST_IMAGE_1 );
1428 DALI_TEST_EQUALS( imageView.IsResourceReady(), false, TEST_LOCATION );
1430 imageView.ResourceReadySignal().Connect( &ResourceReadySignal);
1432 Stage::GetCurrent().Add( imageView );
1434 application.SendNotification();
1435 application.Render(16);
1437 // loading started, this waits for the loader thread for max 30 seconds
1438 DALI_TEST_EQUALS( Test::WaitForEventThreadTrigger( 1 ), true, TEST_LOCATION );
1440 DALI_TEST_EQUALS( imageView.GetRendererCount(), 1u, TEST_LOCATION );
1442 DALI_TEST_EQUALS( gResourceReadySignalFired, true, TEST_LOCATION );
1444 gResourceReadySignalFired = false;
1446 imageView.SetImage(TEST_IMAGE_2);
1448 application.SendNotification();
1449 application.Render(16);
1451 // loading started, this waits for the loader thread for max 30 seconds
1452 DALI_TEST_EQUALS( Test::WaitForEventThreadTrigger( 1 ), true, TEST_LOCATION );
1454 DALI_TEST_EQUALS( imageView.GetRendererCount(), 1u, TEST_LOCATION );
1456 DALI_TEST_EQUALS( imageView.IsResourceReady(), true, TEST_LOCATION );
1458 DALI_TEST_EQUALS( gResourceReadySignalFired, true, TEST_LOCATION );
1463 void OnRelayoutOverride( Size size )
1465 gNaturalSize = size; // Size Relayout is using
1468 int UtcDaliImageViewReplaceImageAndGetNaturalSize(void)
1470 ToolkitTestApplication application;
1472 // Check ImageView with background and main image, to ensure both visuals are marked as loaded
1473 ImageView imageView = ImageView::New( TEST_IMAGE_1 );
1474 imageView.SetResizePolicy( ResizePolicy::USE_NATURAL_SIZE, Dimension::ALL_DIMENSIONS );
1476 DummyControl dummyControl = DummyControl::New( true );
1477 Impl::DummyControl& dummyImpl = static_cast<Impl::DummyControl&>(dummyControl.GetImplementation());
1478 dummyControl.SetResizePolicy( ResizePolicy::FIT_TO_CHILDREN, Dimension::ALL_DIMENSIONS );
1480 dummyControl.Add( imageView );
1481 dummyImpl.SetRelayoutCallback( &OnRelayoutOverride );
1482 Stage::GetCurrent().Add( dummyControl );
1484 application.SendNotification();
1485 application.Render();
1487 // loading started, this waits for the loader thread for max 30 seconds
1488 DALI_TEST_EQUALS( Test::WaitForEventThreadTrigger( 1 ), true, TEST_LOCATION );
1490 DALI_TEST_EQUALS( gNaturalSize.width, 1024.0f, TEST_LOCATION );
1491 DALI_TEST_EQUALS( gNaturalSize.height, 1024.0f, TEST_LOCATION );
1493 gNaturalSize = Vector3::ZERO;
1495 imageView.SetImage(gImage_600_RGB);
1497 // Waiting for resourceReady so SendNotifcation not called here.
1499 // loading started, this waits for the loader thread for max 30 seconds
1500 DALI_TEST_EQUALS( Test::WaitForEventThreadTrigger( 1 ), true, TEST_LOCATION );
1502 // Trigger a potential relayout
1503 application.SendNotification();
1504 application.Render();
1506 DALI_TEST_EQUALS( gNaturalSize.width, 600.0f, TEST_LOCATION );
1507 DALI_TEST_EQUALS( gNaturalSize.height, 600.0f, TEST_LOCATION );
1512 int UtcDaliImageViewResourceReadySignalWithImmediateLoad(void)
1514 tet_infoline("Test Setting Image with IMMEDIATE load and receving ResourceReadySignal before staged.");
1516 ToolkitTestApplication application;
1518 gResourceReadySignalFired = false;
1520 Property::Map imageMap;
1522 imageMap[ ImageVisual::Property::URL ] = gImage_34_RGBA;
1523 imageMap[ DevelImageVisual::Property::LOAD_POLICY ] = DevelImageVisual::LoadPolicy::IMMEDIATE;
1525 tet_infoline("Creating ImageView without URL so image does not start loading");
1526 ImageView imageView = ImageView::New();
1527 tet_infoline("Connect to image loaded signal before setting image");
1528 imageView.ResourceReadySignal().Connect( &ResourceReadySignal);
1529 tet_infoline("Setting Image with IMMEDIATE load, signal already connected so will be triggered.");
1530 imageView.SetProperty( ImageView::Property::IMAGE, imageMap );
1532 // loading started, this waits for the loader thread
1533 DALI_TEST_EQUALS( Test::WaitForEventThreadTrigger( 1 ), true, TEST_LOCATION );
1535 application.SendNotification();
1536 application.Render(16);
1538 DALI_TEST_EQUALS( gResourceReadySignalFired, true, TEST_LOCATION );
1543 int UtcDaliImageViewResourceReadySignalWithReusedImage(void)
1545 tet_infoline("Test Setting Image that was already loaded by another ImageView and still getting ResourceReadySignal.");
1547 ToolkitTestApplication application;
1549 gResourceReadySignalFired = false;
1551 Property::Map imageMap;
1553 imageMap[ ImageVisual::Property::URL ] = gImage_34_RGBA;
1554 imageMap[ DevelImageVisual::Property::LOAD_POLICY ] = DevelImageVisual::LoadPolicy::IMMEDIATE;
1556 ImageView imageView = ImageView::New();
1557 imageView.ResourceReadySignal().Connect( &ResourceReadySignal);
1558 imageView.SetProperty( ImageView::Property::IMAGE, imageMap );
1560 // loading started, this waits for the loader thread
1561 DALI_TEST_EQUALS( Test::WaitForEventThreadTrigger( 1 ), true, TEST_LOCATION );
1563 application.SendNotification();
1564 application.Render(16);
1566 DALI_TEST_EQUALS( gResourceReadySignalFired, true, TEST_LOCATION );
1567 gResourceReadySignalFired = false;
1569 ImageView imageViewWithExistingImage = ImageView::New();
1570 imageViewWithExistingImage.ResourceReadySignal().Connect( &ResourceReadySignal);
1571 imageViewWithExistingImage.SetProperty( ImageView::Property::IMAGE, imageMap );
1573 DALI_TEST_EQUALS( gResourceReadySignalFired, true, TEST_LOCATION );
1578 int UtcDaliImageViewResourceReadySignalWithReusedImage02(void)
1580 tet_infoline("Test Setting Image that was already loaded by another ImageView and still getting ResourceReadySignal when staged.");
1582 ToolkitTestApplication application;
1584 gResourceReadySignalFired = false;
1586 Property::Map imageImmediateLoadingMap;
1587 imageImmediateLoadingMap[ ImageVisual::Property::URL ] = gImage_34_RGBA;
1588 imageImmediateLoadingMap[ DevelImageVisual::Property::LOAD_POLICY ] = DevelImageVisual::LoadPolicy::IMMEDIATE;
1590 tet_infoline("Immediate load an image");
1591 ImageView imageView = ImageView::New();
1592 imageView.ResourceReadySignal().Connect( &ResourceReadySignal);
1593 imageView.SetProperty( ImageView::Property::IMAGE, imageImmediateLoadingMap );
1595 // loading started, this waits for the loader thread
1596 DALI_TEST_EQUALS( Test::WaitForEventThreadTrigger( 1 ), true, TEST_LOCATION );
1598 application.SendNotification();
1599 application.Render(16);
1601 tet_infoline("Check image loaded");
1602 DALI_TEST_EQUALS( gResourceReadySignalFired, true, TEST_LOCATION );
1603 gResourceReadySignalFired = false;
1605 tet_infoline("Create another ImageView with the same URL");
1606 ImageView imageViewWithExistingImage = ImageView::New( gImage_34_RGBA );
1607 tet_infoline("Connect to ResourceReady signal for second ImageView, it should still fire as resource is ready");
1608 imageViewWithExistingImage.ResourceReadySignal().Connect( &ResourceReadySignal);
1610 Stage::GetCurrent().Add( imageViewWithExistingImage );
1612 DALI_TEST_EQUALS( gResourceReadySignalFired, true, TEST_LOCATION );