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 ) );
838 DALI_TEST_CHECK( !value.Get( map ) );
843 int UtcDaliImageViewSetImageOffstageP(void)
845 ToolkitTestApplication application;
847 ImageView imageView = ImageView::New();
849 Stage::GetCurrent().Add( imageView );
850 application.SendNotification();
851 application.Render();
852 Stage::GetCurrent().Remove( imageView );
854 ResourceImage image1 = ResourceImage::New( TEST_IMAGE_FILE_NAME );
855 imageView.SetImage( image1 );
856 TestImage( imageView, image1 );
860 BufferImage image2 = CreateBufferImage( width, height, Vector4( 1.f, 1.f, 1.f, 1.f ) );
861 imageView.SetImage( image2 );
862 TestImage( imageView, image2 );
867 bool gResourceReadySignalFired = false;
868 Vector3 gNaturalSize;
870 void ResourceReadySignal( Control control )
872 gResourceReadySignalFired = true;
875 int UtcDaliImageViewCheckResourceReady(void)
877 ToolkitTestApplication application;
879 gResourceReadySignalFired = false;
884 Image image = CreateBufferImage( width, height, Vector4(1.f, 1.f, 1.f, 1.f) );
886 // Check ImageView with background and main image, to ensure both visuals are marked as loaded
887 ImageView imageView = ImageView::New( TEST_GIF_FILE_NAME );
889 imageView.SetBackgroundImage( image );
891 DALI_TEST_EQUALS( imageView.IsResourceReady(), false, TEST_LOCATION );
893 imageView.ResourceReadySignal().Connect( &ResourceReadySignal);
895 Stage::GetCurrent().Add( imageView );
897 application.SendNotification();
898 application.Render(16);
901 DALI_TEST_EQUALS( imageView.IsResourceReady(), true, TEST_LOCATION );
903 DALI_TEST_EQUALS( gResourceReadySignalFired, true, TEST_LOCATION );
908 int UtcDaliImageViewSetImageOffstageN(void)
910 ToolkitTestApplication application;
912 ImageView imageView = ImageView::New();
914 Stage::GetCurrent().Add( imageView );
915 application.SendNotification();
916 application.Render();
917 Stage::GetCurrent().Remove( imageView );
919 ResourceImage image1 = ResourceImage::New( TEST_IMAGE_FILE_NAME );
920 imageView.SetImage( image1 );
921 TestImage( imageView, image1 );
924 imageView.SetImage( image2 );
926 Property::Value value = imageView.GetProperty( imageView.GetPropertyIndex( "image" ) );
928 //the value should be empty
930 DALI_TEST_CHECK( !value.Get( url ) );
933 DALI_TEST_CHECK( !value.Get( map ) );
938 int UtcDaliImageViewSetImageN(void)
940 ToolkitTestApplication application;
943 ImageView imageView = ImageView::New();
944 imageView.SetImage( image1 );
946 Property::Value value = imageView.GetProperty( imageView.GetPropertyIndex( "image" ) );
948 //the value should be empty
950 DALI_TEST_CHECK( !value.Get( url ) );
953 DALI_TEST_CHECK( !value.Get( map ) );
955 std::string resource_url;
956 Property::Value val = imageView.GetProperty( imageView.GetPropertyIndex( "image" ) );
957 DALI_TEST_CHECK( !val.Get( resource_url ) );
962 int UtcDaliImageViewSetImageTypeChangesP(void)
964 ToolkitTestApplication application;
966 ImageView imageView = ImageView::New();
967 Toolkit::Internal::Control& controlImpl = Toolkit::Internal::GetImplementation( imageView );
969 Stage::GetCurrent().Add( imageView );
973 Toolkit::Visual::Base visual;
975 Property::Value value = imageView.GetProperty( imageView.GetPropertyIndex( "image" ) );
976 visual = DevelControl::GetVisual( controlImpl, ImageView::Property::IMAGE );
978 application.SendNotification();
979 application.Render( 16 );
981 DALI_TEST_CHECK( ! value.Get( url ) ); // Value should be empty
982 DALI_TEST_CHECK( ! value.Get( map ) ); // Value should be empty
983 DALI_TEST_CHECK( ! visual ); // Visual should be invalid
986 imageView.SetImage( "TEST_URL" );
988 application.SendNotification();
989 application.Render( 16 );
991 value = imageView.GetProperty( imageView.GetPropertyIndex( "image" ) );
992 visual = DevelControl::GetVisual( controlImpl, ImageView::Property::IMAGE );
994 DALI_TEST_CHECK( value.Get( url ) ); // Value should NOT be empty
995 DALI_TEST_CHECK( ! value.Get( map ) ); // Value should be empty
996 DALI_TEST_CHECK( visual ); // Visual should be valid
998 // Set an empty Image
999 imageView.SetImage( Image() );
1001 application.SendNotification();
1002 application.Render( 16 );
1004 value = imageView.GetProperty( imageView.GetPropertyIndex( "image" ) );
1005 visual = DevelControl::GetVisual( controlImpl, ImageView::Property::IMAGE );
1007 DALI_TEST_CHECK( ! value.Get( url ) ); // Value should be empty
1008 DALI_TEST_CHECK( ! value.Get( map ) ); // Value should be empty
1009 DALI_TEST_CHECK( ! visual ); // Visual should be invalid
1012 ResourceImage image1 = ResourceImage::New( TEST_IMAGE_FILE_NAME );
1013 imageView.SetImage( image1 );
1015 application.SendNotification();
1016 application.Render( 16 );
1018 value = imageView.GetProperty( imageView.GetPropertyIndex( "image" ) );
1019 visual = DevelControl::GetVisual( controlImpl, ImageView::Property::IMAGE );
1021 DALI_TEST_CHECK( ! value.Get( url ) ); // Value should be empty
1022 DALI_TEST_CHECK( value.Get( map ) ); // Value should NOT be empty
1023 DALI_TEST_CHECK( visual ); // Visual should be valid
1026 imageView.SetImage( "" );
1028 application.SendNotification();
1029 application.Render( 16 );
1031 value = imageView.GetProperty( imageView.GetPropertyIndex( "image" ) );
1032 visual = DevelControl::GetVisual( controlImpl, ImageView::Property::IMAGE );
1034 DALI_TEST_CHECK( ! value.Get( url ) ); // Value should be empty
1035 DALI_TEST_CHECK( ! value.Get( map ) ); // Value should be empty
1036 DALI_TEST_CHECK( ! visual ); // Visual should be invalid
1038 // Set a URL in property map
1039 Property::Map propertyMap;
1040 propertyMap[ImageVisual::Property::URL] = TEST_IMAGE_FILE_NAME;
1041 imageView.SetProperty( ImageView::Property::IMAGE, propertyMap );
1043 application.SendNotification();
1044 application.Render( 16 );
1046 value = imageView.GetProperty( imageView.GetPropertyIndex( "image" ) );
1047 visual = DevelControl::GetVisual( controlImpl, ImageView::Property::IMAGE );
1049 DALI_TEST_CHECK( ! value.Get( url ) ); // Value should be empty
1050 DALI_TEST_CHECK( value.Get( map ) ); // Value should NOT be empty
1051 DALI_TEST_CHECK( visual ); // Visual should be valid
1053 // Set a URL in property map again
1054 propertyMap[ImageVisual::Property::URL] = gImage_34_RGBA;
1055 imageView.SetProperty( ImageView::Property::IMAGE, propertyMap );
1057 application.SendNotification();
1058 application.Render( 16 );
1060 value = imageView.GetProperty( imageView.GetPropertyIndex( "image" ) );
1061 visual = DevelControl::GetVisual( controlImpl, ImageView::Property::IMAGE );
1063 DALI_TEST_CHECK( ! value.Get( url ) ); // Value should be empty
1064 DALI_TEST_CHECK( value.Get( map ) ); // Value should NOT be empty
1065 DALI_TEST_CHECK( visual ); // Visual should be valid
1067 // Set an empty URL in property map
1068 propertyMap[ImageVisual::Property::URL] = std::string();
1069 imageView.SetProperty( ImageView::Property::IMAGE, propertyMap );
1071 application.SendNotification();
1072 application.Render( 16 );
1074 value = imageView.GetProperty( imageView.GetPropertyIndex( "image" ) );
1075 visual = DevelControl::GetVisual( controlImpl, ImageView::Property::IMAGE );
1077 DALI_TEST_CHECK( ! value.Get( url ) ); // Value should be empty
1078 DALI_TEST_CHECK( value.Get( map ) ); // Value should NOT be empty
1079 DALI_TEST_CHECK( ! visual ); // Visual should be invalid
1084 int UtcDaliImageViewResourceUrlP(void)
1086 ToolkitTestApplication application;
1088 ImageView imageView = ImageView::New();
1089 DALI_TEST_CHECK( imageView.GetProperty( ImageView::Property::RESOURCE_URL ).Get< std::string >().empty() );
1091 imageView.SetProperty( ImageView::Property::RESOURCE_URL, "TestString" );
1092 DALI_TEST_EQUALS( imageView.GetProperty( ImageView::Property::RESOURCE_URL ).Get< std::string >(), "TestString", TEST_LOCATION );
1097 // Scenarios 1: ImageView from regular image
1098 int UtcDaliImageViewSetImageBufferImage(void)
1100 ToolkitTestApplication application;
1102 ImageView imageView = ImageView::New();
1103 Stage::GetCurrent().Add( imageView );
1105 TestGlAbstraction& gl = application.GetGlAbstraction();
1106 gl.EnableTextureCallTrace( true );
1108 std::vector< GLuint > ids;
1109 ids.push_back( 23 );
1110 application.GetGlAbstraction().SetNextTextureIds( ids );
1114 BufferImage image = CreateBufferImage( width, height, Color::WHITE );
1116 imageView.SetImage( image );
1118 application.SendNotification();
1119 application.Render();
1121 DALI_TEST_CHECK( gl.GetTextureTrace().FindMethod("BindTexture") );
1123 std::stringstream params;
1124 params << GL_TEXTURE_2D << ", " << 23;
1125 DALI_TEST_CHECK( gl.GetTextureTrace().FindMethodAndParams("BindTexture", params.str()) );
1130 // Scenarios 2: ImageView from Native image
1131 int UtcDaliImageViewSetImageNativeImage(void)
1133 ToolkitTestApplication application;
1135 ImageView imageView = ImageView::New();
1136 Stage::GetCurrent().Add( imageView );
1138 TestGlAbstraction& gl = application.GetGlAbstraction();
1139 gl.EnableTextureCallTrace( true );
1141 std::vector< GLuint > ids;
1142 ids.push_back( 23 );
1143 application.GetGlAbstraction().SetNextTextureIds( ids );
1147 TestNativeImagePointer nativeImageInterface = TestNativeImage::New( width, height );
1148 NativeImage nativeImage = NativeImage::New( *(nativeImageInterface.Get()) );
1150 imageView.SetImage( nativeImage );
1151 application.SendNotification();
1152 application.Render();
1154 DALI_TEST_CHECK( gl.GetTextureTrace().FindMethod("BindTexture") );
1156 std::stringstream params;
1157 params << GL_TEXTURE_EXTERNAL_OES << ", " << 23;
1158 DALI_TEST_CHECK( gl.GetTextureTrace().FindMethodAndParams("BindTexture", params.str()) );
1163 // Scenarios 3: ImageView initially from regular image but then SetImage called with Native image
1164 int UtcDaliImageViewSetImageBufferImageToNativeImage(void)
1166 ToolkitTestApplication application;
1170 BufferImage image = CreateBufferImage( width, height, Color::WHITE );
1172 ImageView imageView = ImageView::New( image );
1173 Stage::GetCurrent().Add( imageView );
1175 TestGlAbstraction& gl = application.GetGlAbstraction();
1176 gl.EnableTextureCallTrace( true );
1178 std::vector< GLuint > ids;
1179 ids.push_back( 23 );
1180 application.GetGlAbstraction().SetNextTextureIds( ids );
1182 application.SendNotification();
1183 application.Render();
1185 DALI_TEST_CHECK( gl.GetTextureTrace().FindMethod("BindTexture") );
1187 std::stringstream params;
1188 params << GL_TEXTURE_2D << ", " << 23;
1189 DALI_TEST_CHECK( gl.GetTextureTrace().FindMethodAndParams("BindTexture", params.str()) );
1193 TestNativeImagePointer nativeImageInterface = TestNativeImage::New( width, height );
1194 NativeImage nativeImage = NativeImage::New( *(nativeImageInterface.Get()) );
1195 imageView.SetImage( nativeImage );
1198 ids.push_back( 24 );
1199 application.GetGlAbstraction().SetNextTextureIds( ids );
1201 application.SendNotification();
1202 application.Render();
1204 DALI_TEST_CHECK( gl.GetTextureTrace().FindMethod("BindTexture") );
1206 std::stringstream nextTextureParams;
1207 nextTextureParams << GL_TEXTURE_EXTERNAL_OES << ", " << 24;
1208 DALI_TEST_CHECK( gl.GetTextureTrace().FindMethodAndParams("BindTexture", nextTextureParams.str()) );
1213 // Scenarios 4: ImageView initially from Native image but then SetImage called with regular image
1214 int UtcDaliImageViewSetImageNativeImageToBufferImage(void)
1216 ToolkitTestApplication application;
1220 TestNativeImagePointer nativeImageInterface = TestNativeImage::New( width, height );
1221 NativeImage nativeImage = NativeImage::New( *(nativeImageInterface.Get()) );
1223 ImageView imageView = ImageView::New( nativeImage );
1224 Stage::GetCurrent().Add( imageView );
1226 TestGlAbstraction& gl = application.GetGlAbstraction();
1227 gl.EnableTextureCallTrace( true );
1229 std::vector< GLuint > ids;
1230 ids.push_back( 23 );
1231 application.GetGlAbstraction().SetNextTextureIds( ids );
1233 application.SendNotification();
1234 application.Render();
1236 DALI_TEST_CHECK( gl.GetTextureTrace().FindMethod("BindTexture") );
1238 std::stringstream params;
1239 params << GL_TEXTURE_EXTERNAL_OES << ", " << 23;
1240 DALI_TEST_CHECK( gl.GetTextureTrace().FindMethodAndParams("BindTexture", params.str()) );
1244 BufferImage image = CreateBufferImage( width, height, Color::WHITE );
1245 imageView.SetImage( image );
1248 ids.push_back( 24 );
1249 application.GetGlAbstraction().SetNextTextureIds( ids );
1251 application.SendNotification();
1252 application.Render();
1254 DALI_TEST_CHECK( gl.GetTextureTrace().FindMethod("BindTexture") );
1256 std::stringstream nextTextureParams;
1257 nextTextureParams << GL_TEXTURE_2D << ", " << 24;
1258 DALI_TEST_CHECK( gl.GetTextureTrace().FindMethodAndParams("BindTexture", nextTextureParams.str()) );
1263 // Scenarios 5: ImageView from Native image with custom shader
1264 int UtcDaliImageViewSetImageNativeImageWithCustomShader(void)
1266 ToolkitTestApplication application;
1271 Property::Map customShader;
1272 customShader.Insert( "vertexShader", VERTEX_SHADER );
1273 customShader.Insert( "fragmentShader", FRAGMENT_SHADER );
1275 Property::Array shaderHints;
1276 shaderHints.PushBack( "requiresSelfDepthTest" );
1277 shaderHints.PushBack( "outputIsTransparent" );
1278 shaderHints.PushBack( "outputIsOpaque" );
1279 shaderHints.PushBack( "modifiesGeometry" );
1281 customShader.Insert( "hints", shaderHints );
1284 map.Insert( "shader", customShader );
1286 TestNativeImagePointer nativeImageInterface = TestNativeImage::New( width, height );
1287 NativeImage nativeImage = NativeImage::New( *(nativeImageInterface.Get()) );
1289 ImageView imageView = ImageView::New( nativeImage );
1290 imageView.SetProperty( ImageView::Property::IMAGE, map );
1291 Stage::GetCurrent().Add( imageView );
1293 TestGlAbstraction& gl = application.GetGlAbstraction();
1294 gl.EnableTextureCallTrace( true );
1296 std::vector< GLuint > ids;
1297 ids.push_back( 23 );
1298 application.GetGlAbstraction().SetNextTextureIds( ids );
1300 application.SendNotification();
1301 application.Render();
1303 DALI_TEST_CHECK( gl.GetTextureTrace().FindMethod("BindTexture") );
1305 std::stringstream params;
1306 params << GL_TEXTURE_EXTERNAL_OES << ", " << 23;
1307 DALI_TEST_CHECK( gl.GetTextureTrace().FindMethodAndParams("BindTexture", params.str()) );
1312 // Scenarios 6: ImageView initially from regular image with custom shader but then SetImage called with Native
1313 int UtcDaliImageViewSetImageBufferImageWithCustomShaderToNativeImage(void)
1315 ToolkitTestApplication application;
1320 Property::Map customShader;
1321 customShader.Insert( "vertexShader", VERTEX_SHADER );
1322 customShader.Insert( "fragmentShader", FRAGMENT_SHADER );
1324 Property::Array shaderHints;
1325 shaderHints.PushBack( "requiresSelfDepthTest" );
1326 shaderHints.PushBack( "outputIsTransparent" );
1327 shaderHints.PushBack( "outputIsOpaque" );
1328 shaderHints.PushBack( "modifiesGeometry" );
1330 customShader.Insert( "hints", shaderHints );
1333 map.Insert( "shader", customShader );
1335 BufferImage image = CreateBufferImage( width, height, Color::WHITE );
1337 ImageView imageView = ImageView::New( image );
1338 imageView.SetProperty( ImageView::Property::IMAGE, map );
1339 Stage::GetCurrent().Add( imageView );
1341 TestGlAbstraction& gl = application.GetGlAbstraction();
1342 gl.EnableTextureCallTrace( true );
1344 std::vector< GLuint > ids;
1345 ids.push_back( 23 );
1346 application.GetGlAbstraction().SetNextTextureIds( ids );
1348 application.SendNotification();
1349 application.Render();
1351 DALI_TEST_CHECK( gl.GetTextureTrace().FindMethod("BindTexture") );
1353 std::stringstream params;
1354 params << GL_TEXTURE_2D << ", " << 23;
1355 DALI_TEST_CHECK( gl.GetTextureTrace().FindMethodAndParams("BindTexture", params.str()) );
1357 TestNativeImagePointer nativeImageInterface = TestNativeImage::New( width, height );
1358 NativeImage nativeImage = NativeImage::New( *(nativeImageInterface.Get()) );
1359 imageView.SetImage( nativeImage );
1362 ids.push_back( 24 );
1363 application.GetGlAbstraction().SetNextTextureIds( ids );
1365 application.SendNotification();
1366 application.Render();
1368 DALI_TEST_CHECK( gl.GetTextureTrace().FindMethod("BindTexture") );
1370 std::stringstream nativeImageParams;
1371 nativeImageParams << GL_TEXTURE_EXTERNAL_OES << ", " << 24;
1372 DALI_TEST_CHECK( gl.GetTextureTrace().FindMethodAndParams("BindTexture", nativeImageParams.str()) );
1378 int UtcDaliImageViewGetImageP1(void)
1380 ToolkitTestApplication application;
1382 ImageView imageView = ImageView::New();
1383 DALI_TEST_CHECK( ! imageView.GetImage() );
1385 Image image = CreateBufferImage();
1386 imageView.SetImage( image );
1387 DALI_TEST_CHECK( imageView.GetImage() == image );
1392 int UtcDaliImageViewGetImageP2(void)
1394 ToolkitTestApplication application;
1396 BufferImage image = CreateBufferImage();
1397 ImageView imageView = ImageView::New( image );
1398 DALI_TEST_CHECK( imageView.GetImage() == image );
1403 int UtcDaliImageViewGetImageN(void)
1405 ToolkitTestApplication application;
1407 ImageView imageView = ImageView::New( TEST_IMAGE_FILE_NAME );
1408 DALI_TEST_CHECK( ! imageView.GetImage() );
1410 Image image = CreateBufferImage();
1411 imageView.SetImage( image );
1412 DALI_TEST_CHECK( imageView.GetImage() == image );
1414 imageView.SetImage( TEST_IMAGE_FILE_NAME );
1415 DALI_TEST_CHECK( ! imageView.GetImage() );
1421 int UtcDaliImageViewReplaceImage(void)
1423 ToolkitTestApplication application;
1425 gResourceReadySignalFired = false;
1429 Image image = CreateBufferImage( width, height, Vector4(1.f, 1.f, 1.f, 1.f) );
1431 // Check ImageView with background and main image, to ensure both visuals are marked as loaded
1432 ImageView imageView = ImageView::New( TEST_IMAGE_1 );
1434 DALI_TEST_EQUALS( imageView.IsResourceReady(), false, TEST_LOCATION );
1436 imageView.ResourceReadySignal().Connect( &ResourceReadySignal);
1438 Stage::GetCurrent().Add( imageView );
1440 application.SendNotification();
1441 application.Render(16);
1443 // loading started, this waits for the loader thread for max 30 seconds
1444 DALI_TEST_EQUALS( Test::WaitForEventThreadTrigger( 1 ), true, TEST_LOCATION );
1446 DALI_TEST_EQUALS( imageView.GetRendererCount(), 1u, TEST_LOCATION );
1448 DALI_TEST_EQUALS( gResourceReadySignalFired, true, TEST_LOCATION );
1450 gResourceReadySignalFired = false;
1452 imageView.SetImage(TEST_IMAGE_2);
1454 application.SendNotification();
1455 application.Render(16);
1457 // loading started, this waits for the loader thread for max 30 seconds
1458 DALI_TEST_EQUALS( Test::WaitForEventThreadTrigger( 1 ), true, TEST_LOCATION );
1460 DALI_TEST_EQUALS( imageView.GetRendererCount(), 1u, TEST_LOCATION );
1462 DALI_TEST_EQUALS( imageView.IsResourceReady(), true, TEST_LOCATION );
1464 DALI_TEST_EQUALS( gResourceReadySignalFired, true, TEST_LOCATION );
1469 void OnRelayoutOverride( Size size )
1471 gNaturalSize = size; // Size Relayout is using
1474 int UtcDaliImageViewReplaceImageAndGetNaturalSize(void)
1476 ToolkitTestApplication application;
1478 // Check ImageView with background and main image, to ensure both visuals are marked as loaded
1479 ImageView imageView = ImageView::New( TEST_IMAGE_1 );
1480 imageView.SetResizePolicy( ResizePolicy::USE_NATURAL_SIZE, Dimension::ALL_DIMENSIONS );
1482 DummyControl dummyControl = DummyControl::New( true );
1483 Impl::DummyControl& dummyImpl = static_cast<Impl::DummyControl&>(dummyControl.GetImplementation());
1484 dummyControl.SetResizePolicy( ResizePolicy::FIT_TO_CHILDREN, Dimension::ALL_DIMENSIONS );
1486 dummyControl.Add( imageView );
1487 dummyImpl.SetRelayoutCallback( &OnRelayoutOverride );
1488 Stage::GetCurrent().Add( dummyControl );
1490 application.SendNotification();
1491 application.Render();
1493 // loading started, this waits for the loader thread for max 30 seconds
1494 DALI_TEST_EQUALS( Test::WaitForEventThreadTrigger( 1 ), true, TEST_LOCATION );
1496 DALI_TEST_EQUALS( gNaturalSize.width, 1024.0f, TEST_LOCATION );
1497 DALI_TEST_EQUALS( gNaturalSize.height, 1024.0f, TEST_LOCATION );
1499 gNaturalSize = Vector3::ZERO;
1501 imageView.SetImage(gImage_600_RGB);
1503 // Waiting for resourceReady so SendNotifcation not called here.
1505 // loading started, this waits for the loader thread for max 30 seconds
1506 DALI_TEST_EQUALS( Test::WaitForEventThreadTrigger( 1 ), true, TEST_LOCATION );
1508 // Trigger a potential relayout
1509 application.SendNotification();
1510 application.Render();
1512 DALI_TEST_EQUALS( gNaturalSize.width, 600.0f, TEST_LOCATION );
1513 DALI_TEST_EQUALS( gNaturalSize.height, 600.0f, TEST_LOCATION );
1518 int UtcDaliImageViewResourceReadySignalWithImmediateLoad(void)
1520 tet_infoline("Test Setting Image with IMMEDIATE load and receving ResourceReadySignal before staged.");
1522 ToolkitTestApplication application;
1524 gResourceReadySignalFired = false;
1526 Property::Map imageMap;
1528 imageMap[ ImageVisual::Property::URL ] = gImage_34_RGBA;
1529 imageMap[ ImageVisual::Property::LOAD_POLICY ] = ImageVisual::LoadPolicy::IMMEDIATE;
1531 tet_infoline("Creating ImageView without URL so image does not start loading");
1532 ImageView imageView = ImageView::New();
1533 tet_infoline("Connect to image loaded signal before setting image");
1534 imageView.ResourceReadySignal().Connect( &ResourceReadySignal);
1535 tet_infoline("Setting Image with IMMEDIATE load, signal already connected so will be triggered.");
1536 imageView.SetProperty( ImageView::Property::IMAGE, imageMap );
1538 // loading started, this waits for the loader thread
1539 DALI_TEST_EQUALS( Test::WaitForEventThreadTrigger( 1 ), true, TEST_LOCATION );
1541 application.SendNotification();
1542 application.Render(16);
1544 DALI_TEST_EQUALS( gResourceReadySignalFired, true, TEST_LOCATION );
1549 int UtcDaliImageViewResourceReadySignalWithReusedImage(void)
1551 tet_infoline("Test Setting Image that was already loaded by another ImageView and still getting ResourceReadySignal.");
1553 ToolkitTestApplication application;
1555 gResourceReadySignalFired = false;
1557 Property::Map imageMap;
1559 imageMap[ ImageVisual::Property::URL ] = gImage_34_RGBA;
1560 imageMap[ ImageVisual::Property::LOAD_POLICY ] = ImageVisual::LoadPolicy::IMMEDIATE;
1562 ImageView imageView = ImageView::New();
1563 imageView.ResourceReadySignal().Connect( &ResourceReadySignal);
1564 imageView.SetProperty( ImageView::Property::IMAGE, imageMap );
1566 // loading started, this waits for the loader thread
1567 DALI_TEST_EQUALS( Test::WaitForEventThreadTrigger( 1 ), true, TEST_LOCATION );
1569 application.SendNotification();
1570 application.Render(16);
1572 DALI_TEST_EQUALS( gResourceReadySignalFired, true, TEST_LOCATION );
1573 gResourceReadySignalFired = false;
1575 ImageView imageViewWithExistingImage = ImageView::New();
1576 imageViewWithExistingImage.ResourceReadySignal().Connect( &ResourceReadySignal);
1577 imageViewWithExistingImage.SetProperty( ImageView::Property::IMAGE, imageMap );
1579 DALI_TEST_EQUALS( gResourceReadySignalFired, true, TEST_LOCATION );
1584 int UtcDaliImageViewResourceReadySignalWithReusedImage02(void)
1586 tet_infoline("Test Setting Image that was already loaded by another ImageView and still getting ResourceReadySignal when staged.");
1588 ToolkitTestApplication application;
1590 gResourceReadySignalFired = false;
1592 Property::Map imageImmediateLoadingMap;
1593 imageImmediateLoadingMap[ ImageVisual::Property::URL ] = gImage_34_RGBA;
1594 imageImmediateLoadingMap[ ImageVisual::Property::LOAD_POLICY ] = ImageVisual::LoadPolicy::IMMEDIATE;
1596 tet_infoline("Immediate load an image");
1597 ImageView imageView = ImageView::New();
1598 imageView.ResourceReadySignal().Connect( &ResourceReadySignal);
1599 imageView.SetProperty( ImageView::Property::IMAGE, imageImmediateLoadingMap );
1601 // loading started, this waits for the loader thread
1602 DALI_TEST_EQUALS( Test::WaitForEventThreadTrigger( 1 ), true, TEST_LOCATION );
1604 application.SendNotification();
1605 application.Render(16);
1607 tet_infoline("Check image loaded");
1608 DALI_TEST_EQUALS( gResourceReadySignalFired, true, TEST_LOCATION );
1609 gResourceReadySignalFired = false;
1611 tet_infoline("Create another ImageView with the same URL");
1612 ImageView imageViewWithExistingImage = ImageView::New( gImage_34_RGBA );
1613 tet_infoline("Connect to ResourceReady signal for second ImageView, it should still fire as resource is ready");
1614 imageViewWithExistingImage.ResourceReadySignal().Connect( &ResourceReadySignal);
1616 Stage::GetCurrent().Add( imageViewWithExistingImage );
1618 DALI_TEST_EQUALS( gResourceReadySignalFired, true, TEST_LOCATION );