2 * Copyright (c) 2019 Samsung Electronics Co., Ltd.
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
8 * http://www.apache.org/licenses/LICENSE-2.0
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
18 // Need to override adaptor classes for toolkit test harness, so include
19 // test harness headers before dali headers.
20 #include <dali-toolkit-test-suite-utils.h>
21 #include <toolkit-event-thread-callback.h>
23 #include <dali-toolkit/dali-toolkit.h>
24 #include <dali/devel-api/scripting/scripting.h>
25 #include <dali-toolkit/devel-api/controls/control-devel.h>
26 #include <dali-toolkit/devel-api/image-loader/texture-manager.h>
27 #include <dali-toolkit/devel-api/visual-factory/visual-base.h>
28 #include <dali-toolkit/devel-api/visuals/image-visual-properties-devel.h>
29 #include <dali-toolkit/devel-api/visuals/image-visual-actions-devel.h>
30 #include <dali-toolkit/devel-api/visuals/visual-properties-devel.h>
32 #include <test-native-image.h>
37 #include "dummy-control.h"
40 using namespace Toolkit;
42 void utc_dali_toolkit_image_view_startup(void)
44 test_return_value = TET_UNDEF;
47 void utc_dali_toolkit_image_view_cleanup(void)
49 test_return_value = TET_PASS;
55 const char* VERTEX_SHADER = DALI_COMPOSE_SHADER(
56 attribute mediump vec2 aPosition;\n
57 varying mediump vec2 vTexCoord;\n
58 uniform mediump mat4 uMvpMatrix;\n
59 uniform mediump vec3 uSize;\n
63 mediump vec4 vertexPosition = vec4(aPosition, 0.0, 1.0);\n
64 vertexPosition.xyz *= uSize;\n
65 vertexPosition = uMvpMatrix * vertexPosition;\n
67 vTexCoord = aPosition + vec2(0.5);\n
68 gl_Position = vertexPosition;\n
72 const char* FRAGMENT_SHADER = DALI_COMPOSE_SHADER(
73 varying mediump vec2 vTexCoord;\n
74 uniform sampler2D sTexture;\n
75 uniform lowp vec4 uColor;\n
79 gl_FragColor = texture2D( sTexture, vTexCoord ) * uColor;\n
83 const char* TEST_IMAGE_FILE_NAME = "gallery_image_01.jpg";
84 const char* TEST_IMAGE_FILE_NAME2 = "gallery_image_02.jpg";
86 const char* TEST_IMAGE_1 = TEST_RESOURCE_DIR "/TB-gloss.png";
87 const char* TEST_IMAGE_2 = TEST_RESOURCE_DIR "/tb-norm.png";
89 // resolution: 34*34, pixel format: RGBA8888
90 static const char* gImage_34_RGBA = TEST_RESOURCE_DIR "/icon-edit.png";
91 // resolution: 600*600, pixel format: RGB888
92 static const char* gImage_600_RGB = TEST_RESOURCE_DIR "/test-image-600.jpg";
94 // resolution: 50*50, frame count: 4, frame delay: 0.2 second for each frame
95 const char* TEST_GIF_FILE_NAME = TEST_RESOURCE_DIR "/anim.gif";
97 void TestImage( ImageView imageView, BufferImage image )
99 Property::Value value = imageView.GetProperty( imageView.GetPropertyIndex( "image" ) );
102 DALI_TEST_CHECK( value.Get( map ) );
104 DALI_TEST_CHECK( map.Find( "width" ) );
105 DALI_TEST_CHECK( map.Find( "height" ) );
106 DALI_TEST_CHECK( map.Find( "type" ) );
109 DALI_TEST_CHECK( map[ "width" ].Get( width ) );
110 DALI_TEST_EQUALS( (unsigned int)width, image.GetWidth(), TEST_LOCATION );
113 DALI_TEST_CHECK( map[ "height" ].Get( height ) );
114 DALI_TEST_EQUALS( (unsigned int)height, image.GetHeight(), TEST_LOCATION );
117 DALI_TEST_CHECK( map[ "type" ].Get( type ) );
118 DALI_TEST_EQUALS( type, "BufferImage", TEST_LOCATION );
121 void TestImage( ImageView imageView, ResourceImage image )
123 Property::Value value = imageView.GetProperty( imageView.GetPropertyIndex( "image" ) );
126 DALI_TEST_CHECK( value.Get( map ) );
128 if( map.Find( "width" ) )
131 DALI_TEST_CHECK( map[ "width" ].Get( width ) );
132 DALI_TEST_EQUALS( (unsigned int)width, image.GetWidth(), TEST_LOCATION );
135 if( map.Find( "height" ) )
138 DALI_TEST_CHECK( map[ "height" ].Get( height ) );
139 DALI_TEST_EQUALS( (unsigned int)height, image.GetHeight(), TEST_LOCATION );
142 DALI_TEST_CHECK( map.Find( "type" ) );
145 DALI_TEST_CHECK( map[ "type" ].Get( type ) );
146 DALI_TEST_EQUALS( type, "ResourceImage", TEST_LOCATION );
148 std::string filename;
149 DALI_TEST_CHECK( map[ "filename" ].Get( filename ) );
150 DALI_TEST_EQUALS( filename, image.GetUrl(), TEST_LOCATION );
153 void TestUrl( ImageView imageView, const std::string url )
155 Property::Value value = imageView.GetProperty( imageView.GetPropertyIndex( "image" ) );
157 std::string urlActual;
158 DALI_TEST_CHECK( value.Get( urlActual ) );
159 DALI_TEST_EQUALS( urlActual, url, TEST_LOCATION );
164 int UtcDaliImageViewNewP(void)
166 ToolkitTestApplication application;
168 ImageView imageView = ImageView::New();
170 DALI_TEST_CHECK( imageView );
175 int UtcDaliImageViewNewImageP(void)
177 ToolkitTestApplication application;
179 BufferImage image = CreateBufferImage( 100, 200, Vector4( 1.f, 1.f, 1.f, 1.f ) );
180 ImageView imageView = ImageView::New( image );
182 DALI_TEST_CHECK( imageView );
183 TestImage( imageView, image );
188 int UtcDaliImageViewNewUrlP(void)
190 ToolkitTestApplication application;
192 ImageView imageView = ImageView::New( TEST_IMAGE_FILE_NAME );
193 DALI_TEST_CHECK( imageView );
195 TestUrl( imageView, TEST_IMAGE_FILE_NAME );
200 int UtcDaliImageViewConstructorP(void)
202 ToolkitTestApplication application;
206 DALI_TEST_CHECK( !imageView );
211 int UtcDaliImageViewCopyConstructorP(void)
213 ToolkitTestApplication application;
215 // Initialize an object, ref count == 1
216 ImageView imageView = ImageView::New();
218 ImageView copy( imageView );
219 DALI_TEST_CHECK( copy );
224 int UtcDaliImageViewAssignmentOperatorP(void)
226 ToolkitTestApplication application;
228 ImageView imageView = ImageView::New();
230 ImageView copy( imageView );
231 DALI_TEST_CHECK( copy );
232 DALI_TEST_EQUALS( imageView, copy, TEST_LOCATION );
237 int UtcDaliImageViewDownCastP(void)
239 ToolkitTestApplication application;
241 ImageView imageView = ImageView::New();
243 BaseHandle object(imageView);
245 ImageView imageView2 = ImageView::DownCast( object );
246 DALI_TEST_CHECK(imageView2);
248 ImageView imageView3 = DownCast< ImageView >( object );
249 DALI_TEST_CHECK(imageView3);
254 int UtcDaliImageViewDownCastN(void)
256 ToolkitTestApplication application;
258 BaseHandle unInitializedObject;
260 ImageView imageView1 = ImageView::DownCast( unInitializedObject );
261 DALI_TEST_CHECK( !imageView1 );
263 ImageView imageView2 = DownCast< ImageView >( unInitializedObject );
264 DALI_TEST_CHECK( !imageView2 );
269 int UtcDaliImageViewTypeRegistry(void)
271 ToolkitTestApplication application;
273 TypeRegistry typeRegistry = TypeRegistry::Get();
274 DALI_TEST_CHECK( typeRegistry );
276 TypeInfo typeInfo = typeRegistry.GetTypeInfo( "ImageView" );
277 DALI_TEST_CHECK( typeInfo );
279 BaseHandle handle = typeInfo.CreateInstance();
280 DALI_TEST_CHECK( handle );
282 ImageView imageView = ImageView::DownCast( handle );
283 DALI_TEST_CHECK( imageView );
288 int UtcDaliImageViewSetGetProperty01(void)
290 ToolkitTestApplication application;
292 ImageView imageView = ImageView::New();
294 Property::Index idx = imageView.GetPropertyIndex( "image" );
295 DALI_TEST_EQUALS( idx, (Property::Index)ImageView::Property::IMAGE, TEST_LOCATION );
297 imageView.SetProperty( idx, TEST_IMAGE_FILE_NAME );
298 TestUrl( imageView, TEST_IMAGE_FILE_NAME );
303 int UtcDaliImageViewSetGetProperty02(void)
305 ToolkitTestApplication application;
307 Image image = CreateBufferImage( 10, 10, Color::WHITE );
308 ImageView imageView = ImageView::New(image);
309 Vector4 fullImageRect( 0.f, 0.f, 1.f, 1.f );
311 Stage::GetCurrent().Add( imageView );
313 application.SendNotification();
314 application.Render();
315 TestGlAbstraction& gl = application.GetGlAbstraction();
317 Vector4 pixelAreaUniform;
318 DALI_TEST_CHECK( gl.GetUniformValue<Vector4>( "pixelArea", pixelAreaUniform ) );
319 DALI_TEST_EQUALS( pixelAreaUniform, fullImageRect, TEST_LOCATION );
321 Property::Value value = imageView.GetProperty( ImageView::Property::PIXEL_AREA );
322 Vector4 pixelAreaValue;
323 DALI_TEST_CHECK( value.Get(pixelAreaValue) );
324 DALI_TEST_EQUALS( pixelAreaValue, fullImageRect, TEST_LOCATION );
326 Vector4 pixelAreaSet( 0.2f, 0.2f, 0.3f, 0.3f );
327 imageView.SetProperty( ImageView::Property::PIXEL_AREA, pixelAreaSet);
329 application.SendNotification();
330 application.Render();
332 value = imageView.GetProperty( ImageView::Property::PIXEL_AREA );
333 value.Get(pixelAreaValue);
334 DALI_TEST_EQUALS( pixelAreaValue, pixelAreaSet, TEST_LOCATION );
336 DALI_TEST_CHECK( gl.GetUniformValue<Vector4>( "pixelArea", pixelAreaUniform ) );
337 DALI_TEST_EQUALS( pixelAreaUniform, pixelAreaSet, TEST_LOCATION );
342 int UtcDaliImageViewSetGetProperty03(void)
344 ToolkitTestApplication application;
346 Image image = CreateBufferImage( 10, 10, Color::WHITE );
347 ImageView imageView = ImageView::New(image);
348 Stage::GetCurrent().Add( imageView );
349 application.SendNotification();
350 application.Render();
352 // conventional alpha blending
353 Renderer renderer = imageView.GetRendererAt( 0 );
354 Property::Value value = renderer.GetProperty( Renderer::Property::BLEND_PRE_MULTIPLIED_ALPHA );
356 DALI_TEST_CHECK( value.Get( enable ) );
357 DALI_TEST_CHECK( !enable );
359 // pre-multiplied alpha blending
360 imageView.SetProperty( Toolkit::ImageView::Property::PRE_MULTIPLIED_ALPHA, true );
361 application.SendNotification();
362 application.Render();
364 int srcFactorRgb = renderer.GetProperty<int>( Renderer::Property::BLEND_FACTOR_SRC_RGB );
365 int destFactorRgb = renderer.GetProperty<int>( Renderer::Property::BLEND_FACTOR_DEST_RGB );
366 int srcFactorAlpha = renderer.GetProperty<int>( Renderer::Property::BLEND_FACTOR_SRC_ALPHA );
367 int destFactorAlpha = renderer.GetProperty<int>( Renderer::Property::BLEND_FACTOR_DEST_ALPHA );
368 DALI_TEST_CHECK( srcFactorRgb == BlendFactor::ONE );
369 DALI_TEST_CHECK( destFactorRgb == BlendFactor::ONE_MINUS_SRC_ALPHA );
370 DALI_TEST_CHECK( srcFactorAlpha == BlendFactor::ONE );
371 DALI_TEST_CHECK( destFactorAlpha == BlendFactor::ONE_MINUS_SRC_ALPHA );
373 value = renderer.GetProperty( Renderer::Property::BLEND_PRE_MULTIPLIED_ALPHA );
374 DALI_TEST_CHECK( value.Get( enable ) );
375 DALI_TEST_CHECK( enable );
380 int UtcDaliImageViewPreMultipliedAlphaPng(void)
382 ToolkitTestApplication application;
384 // Set up trace debug
385 TestGlAbstraction& gl = application.GetGlAbstraction();
386 TraceCallStack& textureTrace = gl.GetTextureTrace();
387 textureTrace.Enable( true );
389 Property::Map imageMap;
390 imageMap[ ImageVisual::Property::URL ] = gImage_34_RGBA;
391 imageMap[ ImageVisual::Property::RELEASE_POLICY] = ImageVisual::ReleasePolicy::NEVER; // To keep the texture cache
393 ImageView imageView1 = ImageView::New();
394 imageView1.SetProperty( ImageView::Property::IMAGE, imageMap );
396 Stage::GetCurrent().Add( imageView1 );
398 Property::Value value = imageView1.GetProperty( ImageView::Property::PRE_MULTIPLIED_ALPHA );
400 DALI_TEST_CHECK( value.Get( enable ) );
401 DALI_TEST_CHECK( enable ); // Default value is true
403 // loading started, this waits for the loader thread for max 30 seconds
404 DALI_TEST_EQUALS( Test::WaitForEventThreadTrigger( 1 ), true, TEST_LOCATION );
406 application.SendNotification();
407 application.Render();
409 value = imageView1.GetProperty( ImageView::Property::PRE_MULTIPLIED_ALPHA );
410 DALI_TEST_CHECK( value.Get( enable ) );
411 DALI_TEST_CHECK( enable ); // Keep true
413 // conventional alpha blending
414 Renderer renderer1 = imageView1.GetRendererAt( 0 );
415 value = renderer1.GetProperty( Renderer::Property::BLEND_PRE_MULTIPLIED_ALPHA );
416 DALI_TEST_CHECK( value.Get( enable ) );
417 DALI_TEST_CHECK( enable );
419 int srcFactorRgb = renderer1.GetProperty<int>( Renderer::Property::BLEND_FACTOR_SRC_RGB );
420 int destFactorRgb = renderer1.GetProperty<int>( Renderer::Property::BLEND_FACTOR_DEST_RGB );
421 int srcFactorAlpha = renderer1.GetProperty<int>( Renderer::Property::BLEND_FACTOR_SRC_ALPHA );
422 int destFactorAlpha = renderer1.GetProperty<int>( Renderer::Property::BLEND_FACTOR_DEST_ALPHA );
423 DALI_TEST_CHECK( srcFactorRgb == BlendFactor::ONE );
424 DALI_TEST_CHECK( destFactorRgb == BlendFactor::ONE_MINUS_SRC_ALPHA );
425 DALI_TEST_CHECK( srcFactorAlpha == BlendFactor::ONE );
426 DALI_TEST_CHECK( destFactorAlpha == BlendFactor::ONE_MINUS_SRC_ALPHA );
428 DALI_TEST_EQUALS( textureTrace.FindMethod("GenTextures"), true, TEST_LOCATION ); // A new texture should be generated.
429 textureTrace.Reset();
431 // Disable pre-multiplied alpha blending
432 imageView1.SetProperty( ImageView::Property::PRE_MULTIPLIED_ALPHA, false );
435 Property::Map attributes;
436 DevelControl::DoAction( imageView1, ImageView::Property::IMAGE, DevelImageVisual::Action::RELOAD, attributes );
438 // loading started, this waits for the loader thread for max 30 seconds
439 DALI_TEST_EQUALS( Test::WaitForEventThreadTrigger( 1 ), true, TEST_LOCATION );
441 application.SendNotification();
442 application.Render();
444 value = imageView1.GetProperty( ImageView::Property::PRE_MULTIPLIED_ALPHA );
445 DALI_TEST_CHECK( value.Get( enable ) );
446 DALI_TEST_CHECK( !enable );
448 // conventional alpha blending
449 value = renderer1.GetProperty( Renderer::Property::BLEND_PRE_MULTIPLIED_ALPHA );
450 DALI_TEST_CHECK( value.Get( enable ) );
451 DALI_TEST_CHECK( !enable );
453 srcFactorRgb = renderer1.GetProperty<int>( Renderer::Property::BLEND_FACTOR_SRC_RGB );
454 destFactorRgb = renderer1.GetProperty<int>( Renderer::Property::BLEND_FACTOR_DEST_RGB );
455 srcFactorAlpha = renderer1.GetProperty<int>( Renderer::Property::BLEND_FACTOR_SRC_ALPHA );
456 destFactorAlpha = renderer1.GetProperty<int>( Renderer::Property::BLEND_FACTOR_DEST_ALPHA );
457 DALI_TEST_CHECK( srcFactorRgb == BlendFactor::SRC_ALPHA );
458 DALI_TEST_CHECK( destFactorRgb == BlendFactor::ONE_MINUS_SRC_ALPHA );
459 DALI_TEST_CHECK( srcFactorAlpha == BlendFactor::ONE );
460 DALI_TEST_CHECK( destFactorAlpha == BlendFactor::ONE_MINUS_SRC_ALPHA );
462 DALI_TEST_EQUALS( textureTrace.FindMethod("GenTextures"), true, TEST_LOCATION ); // A new texture should be generated.
463 textureTrace.Reset();
465 // Make a new ImageView using the same image
466 ImageView imageView2 = ImageView::New();
467 imageView2.SetProperty( ImageView::Property::IMAGE, imageMap );
469 Stage::GetCurrent().Add( imageView2 );
471 application.SendNotification();
472 application.Render();
474 Renderer renderer2 = imageView2.GetRendererAt( 0 );
475 value = renderer2.GetProperty( Renderer::Property::BLEND_PRE_MULTIPLIED_ALPHA );
476 DALI_TEST_CHECK( value.Get( enable ) );
477 DALI_TEST_CHECK( enable );
479 srcFactorRgb = renderer2.GetProperty<int>( Renderer::Property::BLEND_FACTOR_SRC_RGB );
480 destFactorRgb = renderer2.GetProperty<int>( Renderer::Property::BLEND_FACTOR_DEST_RGB );
481 srcFactorAlpha = renderer2.GetProperty<int>( Renderer::Property::BLEND_FACTOR_SRC_ALPHA );
482 destFactorAlpha = renderer2.GetProperty<int>( Renderer::Property::BLEND_FACTOR_DEST_ALPHA );
483 DALI_TEST_CHECK( srcFactorRgb == BlendFactor::ONE );
484 DALI_TEST_CHECK( destFactorRgb == BlendFactor::ONE_MINUS_SRC_ALPHA );
485 DALI_TEST_CHECK( srcFactorAlpha == BlendFactor::ONE );
486 DALI_TEST_CHECK( destFactorAlpha == BlendFactor::ONE_MINUS_SRC_ALPHA );
488 DALI_TEST_EQUALS( textureTrace.FindMethod("GenTextures"), false, TEST_LOCATION ); // The cached texture should be used.
493 int UtcDaliImageViewPreMultipliedAlphaJpg(void)
495 ToolkitTestApplication application;
497 // Set up trace debug
498 TestGlAbstraction& gl = application.GetGlAbstraction();
499 TraceCallStack& textureTrace = gl.GetTextureTrace();
500 textureTrace.Enable( true );
502 Property::Map imageMap;
503 imageMap[ ImageVisual::Property::URL ] = gImage_600_RGB;
504 imageMap[ ImageVisual::Property::RELEASE_POLICY] = ImageVisual::ReleasePolicy::NEVER; // To keep the texture cache
506 ImageView imageView1 = ImageView::New();
507 imageView1.SetProperty( ImageView::Property::IMAGE, imageMap );
509 Stage::GetCurrent().Add( imageView1 );
511 Property::Value value = imageView1.GetProperty( ImageView::Property::PRE_MULTIPLIED_ALPHA );
513 DALI_TEST_CHECK( value.Get( enable ) );
514 DALI_TEST_CHECK( enable ); // Default value is true
516 // loading started, this waits for the loader thread for max 30 seconds
517 DALI_TEST_EQUALS( Test::WaitForEventThreadTrigger( 1 ), true, TEST_LOCATION );
519 application.SendNotification();
520 application.Render();
522 value = imageView1.GetProperty( ImageView::Property::PRE_MULTIPLIED_ALPHA );
523 DALI_TEST_CHECK( value.Get( enable ) );
524 DALI_TEST_CHECK( !enable ); // Should be false after loading
526 // conventional alpha blending
527 Renderer renderer1 = imageView1.GetRendererAt( 0 );
528 value = renderer1.GetProperty( Renderer::Property::BLEND_PRE_MULTIPLIED_ALPHA );
529 DALI_TEST_CHECK( value.Get( enable ) );
530 DALI_TEST_CHECK( !enable );
532 int srcFactorRgb = renderer1.GetProperty<int>( Renderer::Property::BLEND_FACTOR_SRC_RGB );
533 int destFactorRgb = renderer1.GetProperty<int>( Renderer::Property::BLEND_FACTOR_DEST_RGB );
534 int srcFactorAlpha = renderer1.GetProperty<int>( Renderer::Property::BLEND_FACTOR_SRC_ALPHA );
535 int destFactorAlpha = renderer1.GetProperty<int>( Renderer::Property::BLEND_FACTOR_DEST_ALPHA );
536 DALI_TEST_CHECK( srcFactorRgb == BlendFactor::SRC_ALPHA );
537 DALI_TEST_CHECK( destFactorRgb == BlendFactor::ONE_MINUS_SRC_ALPHA );
538 DALI_TEST_CHECK( srcFactorAlpha == BlendFactor::ONE );
539 DALI_TEST_CHECK( destFactorAlpha == BlendFactor::ONE_MINUS_SRC_ALPHA );
541 DALI_TEST_EQUALS( textureTrace.FindMethod("GenTextures"), true, TEST_LOCATION ); // A new texture should be generated.
542 textureTrace.Reset();
544 ImageView imageView2 = ImageView::New();
545 imageView2.SetProperty( ImageView::Property::IMAGE, imageMap );
547 // Disable pre-multiplied alpha blending
548 imageView2.SetProperty( ImageView::Property::PRE_MULTIPLIED_ALPHA, false );
550 Stage::GetCurrent().Add( imageView2 );
552 application.SendNotification();
553 application.Render();
555 value = imageView2.GetProperty( ImageView::Property::PRE_MULTIPLIED_ALPHA );
556 DALI_TEST_CHECK( value.Get( enable ) );
557 DALI_TEST_CHECK( !enable );
559 // conventional alpha blending
560 Renderer renderer2 = imageView2.GetRendererAt( 0 );
561 value = renderer2.GetProperty( Renderer::Property::BLEND_PRE_MULTIPLIED_ALPHA );
562 DALI_TEST_CHECK( value.Get( enable ) );
563 DALI_TEST_CHECK( !enable );
565 srcFactorRgb = renderer2.GetProperty<int>( Renderer::Property::BLEND_FACTOR_SRC_RGB );
566 destFactorRgb = renderer2.GetProperty<int>( Renderer::Property::BLEND_FACTOR_DEST_RGB );
567 srcFactorAlpha = renderer2.GetProperty<int>( Renderer::Property::BLEND_FACTOR_SRC_ALPHA );
568 destFactorAlpha = renderer2.GetProperty<int>( Renderer::Property::BLEND_FACTOR_DEST_ALPHA );
569 DALI_TEST_CHECK( srcFactorRgb == BlendFactor::SRC_ALPHA );
570 DALI_TEST_CHECK( destFactorRgb == BlendFactor::ONE_MINUS_SRC_ALPHA );
571 DALI_TEST_CHECK( srcFactorAlpha == BlendFactor::ONE );
572 DALI_TEST_CHECK( destFactorAlpha == BlendFactor::ONE_MINUS_SRC_ALPHA );
574 DALI_TEST_EQUALS( textureTrace.FindMethod("GenTextures"), false, TEST_LOCATION ); // The cached texture should be used.
579 int UtcDaliImageViewPixelArea(void)
581 // Test pixel area property
582 ToolkitTestApplication application;
584 // Gif image, use AnimatedImageVisual internally
585 // Atlasing is applied to pack multiple frames, use custom wrap mode
586 ImageView gifView = ImageView::New();
587 const Vector4 pixelAreaVisual( 0.f, 0.f, 2.f, 2.f );
588 gifView.SetProperty( ImageView::Property::IMAGE,
589 Property::Map().Add( ImageVisual::Property::URL, TEST_GIF_FILE_NAME )
590 .Add( ImageVisual::Property::PIXEL_AREA, pixelAreaVisual ) );
593 Stage stage = Stage::GetCurrent();
594 stage.Add( gifView );
597 application.SendNotification();
598 application.Render(16);
599 DALI_TEST_CHECK( gifView.GetRendererCount() == 1u );
601 const Vector4 fullTextureRect( 0.f, 0.f, 1.f, 1.f );
602 // test that the pixel area value defined in the visual property map is registered on renderer
603 Renderer renderer = gifView.GetRendererAt(0);
604 Property::Value pixelAreaValue = renderer.GetProperty( renderer.GetPropertyIndex( "pixelArea" ) );
605 DALI_TEST_EQUALS( pixelAreaValue.Get<Vector4>(), pixelAreaVisual, TEST_LOCATION );
607 // test that the shader has the default pixel area value registered.
608 Shader shader = renderer.GetShader();
609 pixelAreaValue = shader.GetProperty( shader.GetPropertyIndex( "pixelArea" ) );
610 DALI_TEST_EQUALS( pixelAreaValue.Get<Vector4>(), fullTextureRect, TEST_LOCATION );
612 // test that the uniform uses the pixelArea property on the renderer.
613 TestGlAbstraction& gl = application.GetGlAbstraction();
614 Vector4 pixelAreaUniform;
615 DALI_TEST_CHECK( gl.GetUniformValue<Vector4>( "pixelArea", pixelAreaUniform ) );
616 DALI_TEST_EQUALS( pixelAreaVisual, pixelAreaUniform, Math::MACHINE_EPSILON_100, TEST_LOCATION );
618 // set the pixelArea property on the control
619 const Vector4 pixelAreaControl( -1.f, -1.f, 3.f, 3.f );
620 gifView.SetProperty( ImageView::Property::PIXEL_AREA, pixelAreaControl );
621 application.SendNotification();
622 application.Render(16);
624 // check the pixelArea property on the control
625 pixelAreaValue = gifView.GetProperty( gifView.GetPropertyIndex( "pixelArea" ) );
626 DALI_TEST_EQUALS( pixelAreaValue.Get<Vector4>(), pixelAreaControl, TEST_LOCATION );
627 // test that the uniform uses the pixelArea property on the control.
628 DALI_TEST_CHECK( gl.GetUniformValue<Vector4>( "pixelArea", pixelAreaUniform ) );
629 DALI_TEST_EQUALS( pixelAreaControl, pixelAreaUniform, Math::MACHINE_EPSILON_100, TEST_LOCATION );
635 int UtcDaliImageViewAsyncLoadingWithoutAltasing(void)
637 ToolkitTestApplication application;
638 TestGlAbstraction& gl = application.GetGlAbstraction();
639 const std::vector<GLuint>& textures = gl.GetBoundTextures();
640 size_t numTextures = textures.size();
642 // Async loading, no atlasing for big size image
643 ImageView imageView = ImageView::New( gImage_600_RGB );
645 // By default, Aysnc loading is used
646 Stage::GetCurrent().Add( imageView );
647 imageView.SetSize(100, 100);
648 imageView.SetParentOrigin( ParentOrigin::CENTER );
650 DALI_TEST_EQUALS( Test::WaitForEventThreadTrigger( 1 ), true, TEST_LOCATION );
652 application.SendNotification();
653 application.Render(16);
654 application.SendNotification();
656 const std::vector<GLuint>& textures2 = gl.GetBoundTextures();
657 DALI_TEST_GREATER( textures2.size(), numTextures, TEST_LOCATION );
664 int UtcDaliImageViewAsyncLoadingWithAtlasing(void)
666 ToolkitTestApplication application;
668 //Async loading, automatic atlasing for small size image
669 TraceCallStack& callStack = application.GetGlAbstraction().GetTextureTrace();
671 callStack.Enable(true);
673 Property::Map imageMap;
675 imageMap[ ImageVisual::Property::URL ] = gImage_34_RGBA;
676 imageMap[ ImageVisual::Property::DESIRED_HEIGHT ] = 34;
677 imageMap[ ImageVisual::Property::DESIRED_WIDTH ] = 34;
678 imageMap[ ImageVisual::Property::ATLASING] = true;
680 ImageView imageView = ImageView::New();
681 imageView.SetProperty( ImageView::Property::IMAGE, imageMap );
682 imageView.SetProperty( Toolkit::Control::Property::PADDING, Extents( 10u, 10u, 10u, 10u ) );
684 // By default, Aysnc loading is used
685 // loading is not started if the actor is offStage
687 Stage::GetCurrent().Add( imageView );
688 application.SendNotification();
689 application.Render(16);
690 application.Render(16);
691 application.SendNotification();
693 imageView.SetProperty( Dali::Actor::Property::LAYOUT_DIRECTION, Dali::LayoutDirection::RIGHT_TO_LEFT );
694 application.SendNotification();
695 application.Render(16);
696 application.Render(16);
697 application.SendNotification();
699 // loading started, this waits for the loader thread for max 30 seconds
700 DALI_TEST_EQUALS( Test::WaitForEventThreadTrigger( 1 ), true, TEST_LOCATION );
702 application.SendNotification();
703 application.Render(16);
705 callStack.Enable(false);
707 TraceCallStack::NamedParams params;
708 params["width"] = ToString(34);
709 params["height"] = ToString(34);
710 DALI_TEST_EQUALS( callStack.FindMethodAndParams( "TexSubImage2D", params ), true, TEST_LOCATION );
715 int UtcDaliImageViewAsyncLoadingWithAtlasing02(void)
717 ToolkitTestApplication application;
719 //Async loading, automatic atlasing for small size image
720 TraceCallStack& callStack = application.GetGlAbstraction().GetTextureTrace();
722 callStack.Enable(true);
724 Property::Map asyncLoadingMap;
725 asyncLoadingMap[ "url" ] = gImage_34_RGBA;
726 asyncLoadingMap[ "desiredHeight" ] = 34;
727 asyncLoadingMap[ "desiredWidth" ] = 34;
728 asyncLoadingMap[ "synchronousLoading" ] = false;
729 asyncLoadingMap[ "atlasing" ] = true;
731 ImageView imageView = ImageView::New();
732 imageView.SetProperty( ImageView::Property::IMAGE, asyncLoadingMap );
734 Stage::GetCurrent().Add( imageView );
735 application.SendNotification();
736 application.Render(16);
737 application.Render(16);
738 application.SendNotification();
740 // loading started, this waits for the loader thread for max 30 seconds
741 DALI_TEST_EQUALS( Test::WaitForEventThreadTrigger( 1 ), true, TEST_LOCATION );
743 application.SendNotification();
744 application.Render(16);
746 callStack.Enable(false);
748 TraceCallStack::NamedParams params;
749 params["width"] = ToString(34);
750 params["height"] = ToString(34);
751 DALI_TEST_EQUALS( callStack.FindMethodAndParams( "TexSubImage2D", params ), true, TEST_LOCATION );
756 int UtcDaliImageViewSyncLoading(void)
758 ToolkitTestApplication application;
760 tet_infoline("ImageView Testing sync loading and size using index key property map");
762 Property::Map syncLoadingMap;
763 syncLoadingMap[ ImageVisual::Property::SYNCHRONOUS_LOADING ] = true;
764 syncLoadingMap[ ImageVisual::Property::ATLASING ] = true;
766 // Sync loading, no atlasing for big size image
768 ImageView imageView = ImageView::New();
770 // Sync loading is used
771 syncLoadingMap[ ImageVisual::Property::URL ] = gImage_600_RGB;
772 imageView.SetProperty( ImageView::Property::IMAGE, syncLoadingMap );
775 // Sync loading, automatic atlasing for small size image
777 TraceCallStack& callStack = application.GetGlAbstraction().GetTextureTrace();
779 callStack.Enable(true);
781 ImageView imageView = ImageView::New( );
783 // Sync loading is used
784 syncLoadingMap[ ImageVisual::Property::URL ] = gImage_34_RGBA;
785 syncLoadingMap[ ImageVisual::Property::DESIRED_HEIGHT ] = 34;
786 syncLoadingMap[ ImageVisual::Property::DESIRED_WIDTH ] = 34;
787 imageView.SetProperty( ImageView::Property::IMAGE, syncLoadingMap );
789 Stage::GetCurrent().Add( imageView );
790 application.SendNotification();
791 application.Render(16);
793 TraceCallStack::NamedParams params;
794 params["width"] = ToString(34);
795 params["height"] = ToString(34);
796 DALI_TEST_EQUALS( callStack.FindMethodAndParams( "TexSubImage2D", params ),
797 true, TEST_LOCATION );
802 int UtcDaliImageViewSyncLoading02(void)
804 ToolkitTestApplication application;
806 tet_infoline("ImageView Testing sync loading and size using string key property map");
808 // Sync loading, automatic atlasing for small size image
810 TraceCallStack& callStack = application.GetGlAbstraction().GetTextureTrace();
812 callStack.Enable(true);
814 ImageView imageView = ImageView::New( );
816 // Sync loading is used
817 Property::Map syncLoadingMap;
818 syncLoadingMap[ "url" ] = gImage_34_RGBA;
819 syncLoadingMap[ "desiredHeight" ] = 34;
820 syncLoadingMap[ "desiredWidth" ] = 34;
821 syncLoadingMap[ "synchronousLoading" ] = true;
822 syncLoadingMap[ "atlasing" ] = true;
823 imageView.SetProperty( ImageView::Property::IMAGE, syncLoadingMap );
825 Stage::GetCurrent().Add( imageView );
826 application.SendNotification();
827 application.Render(16);
829 TraceCallStack::NamedParams params;
830 params["width"] = ToString(34);
831 params["height"] = ToString(34);
832 DALI_TEST_EQUALS( callStack.FindMethodAndParams( "TexSubImage2D", params ),
833 true, TEST_LOCATION );
838 int UtcDaliImageViewAddedTexture(void)
840 ToolkitTestApplication application;
842 tet_infoline("ImageView Testing image view with texture provided manager url");
844 ImageView imageView = ImageView::New();
846 // empty texture is ok, though pointless from app point of view
848 std::string url = TextureManager::AddTexture(empty);
849 DALI_TEST_CHECK(url.size() > 0u);
851 Property::Map propertyMap;
852 propertyMap[ImageVisual::Property::URL] = url;
853 imageView.SetProperty(ImageView::Property::IMAGE, propertyMap);
855 Stage::GetCurrent().Add( imageView );
856 application.SendNotification();
857 application.Render();
862 int UtcDaliImageViewSizeWithBackground(void)
864 ToolkitTestApplication application;
868 ImageView imageView = ImageView::New();
870 imageView.SetProperty( Control::Property::BACKGROUND,
872 { Toolkit::Visual::Property::TYPE, Toolkit::Visual::IMAGE },
873 { Toolkit::ImageVisual::Property::URL, TEST_RESOURCE_DIR "/gallery-small-1.jpg" },
874 { ImageVisual::Property::DESIRED_WIDTH, width },
875 { ImageVisual::Property::DESIRED_HEIGHT, height },
879 Stage::GetCurrent().Add( imageView );
880 application.SendNotification();
881 application.Render();
883 DALI_TEST_EQUALS( imageView.GetCurrentSize().width, (float)width, TEST_LOCATION );
884 DALI_TEST_EQUALS( imageView.GetCurrentSize().height, (float)height, TEST_LOCATION );
889 int UtcDaliImageViewSizeWithBackgroundAndImage(void)
891 ToolkitTestApplication application;
893 int widthBackground = 100;
894 int heightBackground = 200;
897 Image image = CreateBufferImage( width, height, Vector4(1.f, 1.f, 1.f, 1.f) );
899 ImageView imageView = ImageView::New();
901 imageView.SetProperty( Control::Property::BACKGROUND,
903 { Toolkit::Visual::Property::TYPE, Toolkit::Visual::IMAGE },
904 { Toolkit::ImageVisual::Property::URL, TEST_RESOURCE_DIR "/gallery-small-1.jpg" },
905 { ImageVisual::Property::DESIRED_WIDTH, widthBackground },
906 { ImageVisual::Property::DESIRED_HEIGHT, heightBackground },
910 imageView.SetImage( image );
912 Stage::GetCurrent().Add( imageView );
913 application.SendNotification();
914 application.Render();
916 DALI_TEST_EQUALS( imageView.GetCurrentSize().width, (float)width, TEST_LOCATION );
917 DALI_TEST_EQUALS( imageView.GetCurrentSize().height, (float)height, TEST_LOCATION );
922 int UtcDaliImageViewHeightForWidthBackground(void)
924 ToolkitTestApplication application;
926 int widthBackground = 100;
927 int heightBackground = 200;
929 ImageView imageView = ImageView::New();
931 imageView.SetProperty( Control::Property::BACKGROUND,
933 { Toolkit::Visual::Property::TYPE, Toolkit::Visual::IMAGE },
934 { Toolkit::ImageVisual::Property::URL, TEST_RESOURCE_DIR "/gallery-small-1.jpg" },
935 { ImageVisual::Property::DESIRED_WIDTH, widthBackground },
936 { ImageVisual::Property::DESIRED_HEIGHT, heightBackground }
940 Stage::GetCurrent().Add( imageView );
941 application.SendNotification();
942 application.Render();
944 Control control = Control::DownCast( imageView );
945 DALI_TEST_CHECK( control );
946 DALI_TEST_EQUALS( imageView.GetHeightForWidth( 123.f ), control.GetHeightForWidth( 123.f ), TEST_LOCATION );
947 DALI_TEST_EQUALS( imageView.GetWidthForHeight( 321.f ), control.GetWidthForHeight( 321.f ), TEST_LOCATION );
952 int UtcDaliImageViewHeightForWidthBackgroundAndImage(void)
954 ToolkitTestApplication application;
956 int widthBackground = 100;
957 int heightBackground = 200;
961 Image image = CreateBufferImage( width, height, Vector4(1.f, 1.f, 1.f, 1.f) );
963 ImageView imageView = ImageView::New();
965 imageView.SetProperty( Control::Property::BACKGROUND,
967 { Toolkit::Visual::Property::TYPE, Toolkit::Visual::IMAGE },
968 { Toolkit::ImageVisual::Property::URL, TEST_RESOURCE_DIR "/gallery-small-1.jpg" },
969 { ImageVisual::Property::DESIRED_WIDTH, widthBackground },
970 { ImageVisual::Property::DESIRED_HEIGHT, heightBackground }
974 imageView.SetImage( image );
976 Stage::GetCurrent().Add( imageView );
977 application.SendNotification();
978 application.Render();
980 DALI_TEST_EQUALS( imageView.GetHeightForWidth( width ), (float)height, TEST_LOCATION );
981 DALI_TEST_EQUALS( imageView.GetWidthForHeight( height ), (float)width, TEST_LOCATION );
986 int UtcDaliImageViewSetBufferImage(void)
988 ToolkitTestApplication application;
992 BufferImage image1 = CreateBufferImage( width1, height1, Vector4( 1.f, 1.f, 1.f, 1.f ) );
993 ImageView imageView = ImageView::New();
994 imageView.SetImage( image1 );
996 TestImage( imageView, image1 );
1000 BufferImage image2 = CreateBufferImage( width2, height2, Vector4( 1.f, 1.f, 1.f, 1.f ) );
1001 imageView.SetImage( image2 );
1003 TestImage( imageView, image2 );
1008 int UtcDaliImageViewSetImageUrl(void)
1010 ToolkitTestApplication application;
1012 ImageView imageView = ImageView::New();
1013 imageView.SetImage( TEST_IMAGE_FILE_NAME );
1014 TestUrl( imageView, TEST_IMAGE_FILE_NAME );
1017 imageView.SetImage( TEST_IMAGE_FILE_NAME2 );
1018 TestUrl( imageView, TEST_IMAGE_FILE_NAME2 );
1023 int UtcDaliImageViewSetImageOnstageP(void)
1025 ToolkitTestApplication application;
1027 ImageView imageView = ImageView::New();
1029 Stage::GetCurrent().Add( imageView );
1030 application.SendNotification();
1031 application.Render();
1033 ResourceImage image1 = ResourceImage::New( TEST_IMAGE_FILE_NAME );
1034 imageView.SetImage( image1 );
1035 TestImage( imageView, image1 );
1039 BufferImage image2 = CreateBufferImage( width, height, Vector4( 1.f, 1.f, 1.f, 1.f ) );
1040 imageView.SetImage( image2 );
1041 TestImage( imageView, image2 );
1046 int UtcDaliImageViewSetImageOnstageN(void)
1048 ToolkitTestApplication application;
1050 ImageView imageView = ImageView::New();
1052 Stage::GetCurrent().Add( imageView );
1053 application.SendNotification();
1054 application.Render();
1056 ResourceImage image1 = ResourceImage::New( TEST_IMAGE_FILE_NAME );
1057 imageView.SetImage( image1 );
1058 TestImage( imageView, image1 );
1061 imageView.SetImage( image2 );
1063 Property::Value value = imageView.GetProperty( imageView.GetPropertyIndex( "image" ) );
1065 //the value should be empty
1067 DALI_TEST_CHECK( !value.Get( url ) );
1071 DALI_TEST_CHECK( map.Empty() );
1076 int UtcDaliImageViewSetImageOffstageP(void)
1078 ToolkitTestApplication application;
1080 ImageView imageView = ImageView::New();
1082 Stage::GetCurrent().Add( imageView );
1083 application.SendNotification();
1084 application.Render();
1085 Stage::GetCurrent().Remove( imageView );
1087 ResourceImage image1 = ResourceImage::New( TEST_IMAGE_FILE_NAME );
1088 imageView.SetImage( image1 );
1089 TestImage( imageView, image1 );
1093 BufferImage image2 = CreateBufferImage( width, height, Vector4( 1.f, 1.f, 1.f, 1.f ) );
1094 imageView.SetImage( image2 );
1095 TestImage( imageView, image2 );
1100 bool gResourceReadySignalFired = false;
1101 Vector3 gNaturalSize;
1103 void ResourceReadySignal( Control control )
1105 gResourceReadySignalFired = true;
1108 int UtcDaliImageViewCheckResourceReady(void)
1110 ToolkitTestApplication application;
1112 gResourceReadySignalFired = false;
1114 // Check ImageView with background and main image, to ensure both visuals are marked as loaded
1115 ImageView imageView = ImageView::New( TEST_GIF_FILE_NAME );
1117 imageView.SetProperty( Control::Property::BACKGROUND,
1119 { Toolkit::Visual::Property::TYPE, Toolkit::Visual::IMAGE },
1120 { Toolkit::ImageVisual::Property::URL, TEST_RESOURCE_DIR "/gallery-small-1.jpg" },
1121 { ImageVisual::Property::DESIRED_WIDTH, 100 },
1122 { ImageVisual::Property::DESIRED_HEIGHT, 200 }
1126 DALI_TEST_EQUALS( imageView.IsResourceReady(), false, TEST_LOCATION );
1128 imageView.ResourceReadySignal().Connect( &ResourceReadySignal);
1130 Stage::GetCurrent().Add( imageView );
1132 // loading started, this waits for the loader thread
1133 DALI_TEST_EQUALS( Test::WaitForEventThreadTrigger( 1 ), true, TEST_LOCATION );
1135 application.SendNotification();
1136 application.Render(16);
1138 DALI_TEST_EQUALS( imageView.IsResourceReady(), true, TEST_LOCATION );
1140 DALI_TEST_EQUALS( gResourceReadySignalFired, true, TEST_LOCATION );
1145 int UtcDaliImageViewSetImageOffstageN(void)
1147 ToolkitTestApplication application;
1149 ImageView imageView = ImageView::New();
1151 Stage::GetCurrent().Add( imageView );
1152 application.SendNotification();
1153 application.Render();
1154 Stage::GetCurrent().Remove( imageView );
1156 ResourceImage image1 = ResourceImage::New( TEST_IMAGE_FILE_NAME );
1157 imageView.SetImage( image1 );
1158 TestImage( imageView, image1 );
1161 imageView.SetImage( image2 );
1163 Property::Value value = imageView.GetProperty( imageView.GetPropertyIndex( "image" ) );
1165 //the value should be empty
1167 DALI_TEST_CHECK( !value.Get( url ) );
1171 DALI_TEST_CHECK( map.Empty() );
1176 int UtcDaliImageViewSetImageN(void)
1178 ToolkitTestApplication application;
1181 ImageView imageView = ImageView::New();
1182 imageView.SetImage( image1 );
1184 Property::Value value = imageView.GetProperty( imageView.GetPropertyIndex( "image" ) );
1186 //the value should be empty
1188 DALI_TEST_CHECK( !value.Get( url ) );
1192 DALI_TEST_CHECK( map.Empty() );
1194 std::string resource_url;
1195 Property::Value val = imageView.GetProperty( imageView.GetPropertyIndex( "image" ) );
1196 DALI_TEST_CHECK( !val.Get( resource_url ) );
1201 int UtcDaliImageViewSetImageTypeChangesP(void)
1203 ToolkitTestApplication application;
1205 ImageView imageView = ImageView::New();
1206 Toolkit::Internal::Control& controlImpl = Toolkit::Internal::GetImplementation( imageView );
1208 Stage::GetCurrent().Add( imageView );
1212 Toolkit::Visual::Base visual;
1214 Property::Value value = imageView.GetProperty( imageView.GetPropertyIndex( "image" ) );
1215 visual = DevelControl::GetVisual( controlImpl, ImageView::Property::IMAGE );
1217 application.SendNotification();
1218 application.Render( 16 );
1220 DALI_TEST_CHECK( ! value.Get( url ) ); // Value should be empty
1222 DALI_TEST_CHECK( map.Empty() ); // Value should be empty
1223 DALI_TEST_CHECK( ! visual ); // Visual should be invalid
1226 imageView.SetImage( "TEST_URL" );
1228 application.SendNotification();
1229 application.Render( 16 );
1231 value = imageView.GetProperty( imageView.GetPropertyIndex( "image" ) );
1232 visual = DevelControl::GetVisual( controlImpl, ImageView::Property::IMAGE );
1234 DALI_TEST_CHECK( value.Get( url ) ); // Value should NOT be empty
1235 DALI_TEST_CHECK( ! value.Get( map ) ); // Value should be empty
1236 DALI_TEST_CHECK( visual ); // Visual should be valid
1238 // Set an empty Image
1239 imageView.SetImage( Image() );
1241 application.SendNotification();
1242 application.Render( 16 );
1244 value = imageView.GetProperty( imageView.GetPropertyIndex( "image" ) );
1245 visual = DevelControl::GetVisual( controlImpl, ImageView::Property::IMAGE );
1247 DALI_TEST_CHECK( ! value.Get( url ) ); // Value should be empty
1249 DALI_TEST_CHECK( map.Empty() ); // Value should be empty
1250 DALI_TEST_CHECK( ! visual ); // Visual should be invalid
1253 ResourceImage image1 = ResourceImage::New( TEST_IMAGE_FILE_NAME );
1254 imageView.SetImage( image1 );
1256 application.SendNotification();
1257 application.Render( 16 );
1259 value = imageView.GetProperty( imageView.GetPropertyIndex( "image" ) );
1260 visual = DevelControl::GetVisual( controlImpl, ImageView::Property::IMAGE );
1262 DALI_TEST_CHECK( ! value.Get( url ) ); // Value should be empty
1263 DALI_TEST_CHECK( value.Get( map ) ); // Value should NOT be empty
1264 DALI_TEST_CHECK( visual ); // Visual should be valid
1267 imageView.SetImage( "" );
1269 application.SendNotification();
1270 application.Render( 16 );
1272 value = imageView.GetProperty( imageView.GetPropertyIndex( "image" ) );
1273 visual = DevelControl::GetVisual( controlImpl, ImageView::Property::IMAGE );
1275 DALI_TEST_CHECK( ! value.Get( url ) ); // Value should be empty
1277 DALI_TEST_CHECK( map.Empty() ); // Value should be empty
1278 DALI_TEST_CHECK( ! visual ); // Visual should be invalid
1280 // Set a URL in property map
1281 Property::Map propertyMap;
1282 propertyMap[ImageVisual::Property::URL] = TEST_IMAGE_FILE_NAME;
1283 imageView.SetProperty( ImageView::Property::IMAGE, propertyMap );
1285 application.SendNotification();
1286 application.Render( 16 );
1288 value = imageView.GetProperty( imageView.GetPropertyIndex( "image" ) );
1289 visual = DevelControl::GetVisual( controlImpl, ImageView::Property::IMAGE );
1291 DALI_TEST_CHECK( ! value.Get( url ) ); // Value should be empty
1292 DALI_TEST_CHECK( value.Get( map ) ); // Value should NOT be empty
1293 DALI_TEST_CHECK( visual ); // Visual should be valid
1295 // Set a URL in property map again
1296 propertyMap[ImageVisual::Property::URL] = gImage_34_RGBA;
1297 imageView.SetProperty( ImageView::Property::IMAGE, propertyMap );
1299 application.SendNotification();
1300 application.Render( 16 );
1302 value = imageView.GetProperty( imageView.GetPropertyIndex( "image" ) );
1303 visual = DevelControl::GetVisual( controlImpl, ImageView::Property::IMAGE );
1305 DALI_TEST_CHECK( ! value.Get( url ) ); // Value should be empty
1306 DALI_TEST_CHECK( value.Get( map ) ); // Value should NOT be empty
1307 DALI_TEST_CHECK( visual ); // Visual should be valid
1309 // Set an empty URL in property map
1310 propertyMap[ImageVisual::Property::URL] = std::string();
1311 imageView.SetProperty( ImageView::Property::IMAGE, propertyMap );
1313 application.SendNotification();
1314 application.Render( 16 );
1316 value = imageView.GetProperty( imageView.GetPropertyIndex( "image" ) );
1317 visual = DevelControl::GetVisual( controlImpl, ImageView::Property::IMAGE );
1319 DALI_TEST_CHECK( ! value.Get( url ) ); // Value should be empty
1320 DALI_TEST_CHECK( value.Get( map ) ); // Value should NOT be empty
1321 DALI_TEST_CHECK( ! visual ); // Visual should be invalid
1326 int UtcDaliImageViewResourceUrlP(void)
1328 ToolkitTestApplication application;
1330 ImageView imageView = ImageView::New();
1331 DALI_TEST_CHECK( imageView.GetProperty( ImageView::Property::IMAGE ).Get< std::string >().empty() );
1333 imageView.SetProperty( ImageView::Property::IMAGE, "TestString" );
1334 DALI_TEST_EQUALS( imageView.GetProperty( ImageView::Property::IMAGE ).Get< std::string >(), "TestString", TEST_LOCATION );
1339 // Scenarios 1: ImageView from regular image
1340 int UtcDaliImageViewSetImageBufferImage(void)
1342 ToolkitTestApplication application;
1344 ImageView imageView = ImageView::New();
1345 Stage::GetCurrent().Add( imageView );
1347 TestGlAbstraction& gl = application.GetGlAbstraction();
1348 gl.EnableTextureCallTrace( true );
1350 std::vector< GLuint > ids;
1351 ids.push_back( 23 );
1352 application.GetGlAbstraction().SetNextTextureIds( ids );
1356 BufferImage image = CreateBufferImage( width, height, Color::WHITE );
1358 imageView.SetImage( image );
1360 application.SendNotification();
1361 application.Render();
1363 DALI_TEST_CHECK( gl.GetTextureTrace().FindMethod("BindTexture") );
1365 std::stringstream params;
1366 params << GL_TEXTURE_2D << ", " << 23;
1367 DALI_TEST_CHECK( gl.GetTextureTrace().FindMethodAndParams("BindTexture", params.str()) );
1372 // Scenarios 2: ImageView from Native image
1373 int UtcDaliImageViewSetImageNativeImage(void)
1375 ToolkitTestApplication application;
1377 ImageView imageView = ImageView::New();
1378 Stage::GetCurrent().Add( imageView );
1380 TestGlAbstraction& gl = application.GetGlAbstraction();
1381 gl.EnableTextureCallTrace( true );
1383 std::vector< GLuint > ids;
1384 ids.push_back( 23 );
1385 application.GetGlAbstraction().SetNextTextureIds( ids );
1389 TestNativeImagePointer nativeImageInterface = TestNativeImage::New( width, height );
1390 NativeImage nativeImage = NativeImage::New( *(nativeImageInterface.Get()) );
1392 imageView.SetImage( nativeImage );
1393 application.SendNotification();
1394 application.Render();
1396 DALI_TEST_CHECK( gl.GetTextureTrace().FindMethod("BindTexture") );
1398 std::stringstream params;
1399 params << GL_TEXTURE_EXTERNAL_OES << ", " << 23;
1400 DALI_TEST_CHECK( gl.GetTextureTrace().FindMethodAndParams("BindTexture", params.str()) );
1405 // Scenarios 3: ImageView initially from regular image but then SetImage called with Native image
1406 int UtcDaliImageViewSetImageBufferImageToNativeImage(void)
1408 ToolkitTestApplication application;
1412 BufferImage image = CreateBufferImage( width, height, Color::WHITE );
1414 ImageView imageView = ImageView::New( image );
1415 Stage::GetCurrent().Add( imageView );
1417 TestGlAbstraction& gl = application.GetGlAbstraction();
1418 gl.EnableTextureCallTrace( true );
1420 std::vector< GLuint > ids;
1421 ids.push_back( 23 );
1422 application.GetGlAbstraction().SetNextTextureIds( ids );
1424 application.SendNotification();
1425 application.Render();
1427 DALI_TEST_CHECK( gl.GetTextureTrace().FindMethod("BindTexture") );
1429 std::stringstream params;
1430 params << GL_TEXTURE_2D << ", " << 23;
1431 DALI_TEST_CHECK( gl.GetTextureTrace().FindMethodAndParams("BindTexture", params.str()) );
1435 TestNativeImagePointer nativeImageInterface = TestNativeImage::New( width, height );
1436 NativeImage nativeImage = NativeImage::New( *(nativeImageInterface.Get()) );
1437 imageView.SetImage( nativeImage );
1440 ids.push_back( 24 );
1441 application.GetGlAbstraction().SetNextTextureIds( ids );
1443 application.SendNotification();
1444 application.Render();
1446 DALI_TEST_CHECK( gl.GetTextureTrace().FindMethod("BindTexture") );
1448 std::stringstream nextTextureParams;
1449 nextTextureParams << GL_TEXTURE_EXTERNAL_OES << ", " << 24;
1450 DALI_TEST_CHECK( gl.GetTextureTrace().FindMethodAndParams("BindTexture", nextTextureParams.str()) );
1455 // Scenarios 4: ImageView initially from Native image but then SetImage called with regular image
1456 int UtcDaliImageViewSetImageNativeImageToBufferImage(void)
1458 ToolkitTestApplication application;
1462 TestNativeImagePointer nativeImageInterface = TestNativeImage::New( width, height );
1463 NativeImage nativeImage = NativeImage::New( *(nativeImageInterface.Get()) );
1465 ImageView imageView = ImageView::New( nativeImage );
1466 Stage::GetCurrent().Add( imageView );
1468 TestGlAbstraction& gl = application.GetGlAbstraction();
1469 gl.EnableTextureCallTrace( true );
1471 std::vector< GLuint > ids;
1472 ids.push_back( 23 );
1473 application.GetGlAbstraction().SetNextTextureIds( ids );
1475 application.SendNotification();
1476 application.Render();
1478 DALI_TEST_CHECK( gl.GetTextureTrace().FindMethod("BindTexture") );
1480 std::stringstream params;
1481 params << GL_TEXTURE_EXTERNAL_OES << ", " << 23;
1482 DALI_TEST_CHECK( gl.GetTextureTrace().FindMethodAndParams("BindTexture", params.str()) );
1486 BufferImage image = CreateBufferImage( width, height, Color::WHITE );
1487 imageView.SetImage( image );
1490 ids.push_back( 24 );
1491 application.GetGlAbstraction().SetNextTextureIds( ids );
1493 application.SendNotification();
1494 application.Render();
1496 DALI_TEST_CHECK( gl.GetTextureTrace().FindMethod("BindTexture") );
1498 std::stringstream nextTextureParams;
1499 nextTextureParams << GL_TEXTURE_2D << ", " << 24;
1500 DALI_TEST_CHECK( gl.GetTextureTrace().FindMethodAndParams("BindTexture", nextTextureParams.str()) );
1505 // Scenarios 5: ImageView from Native image with custom shader
1506 int UtcDaliImageViewSetImageNativeImageWithCustomShader(void)
1508 ToolkitTestApplication application;
1513 Property::Map customShader;
1514 customShader.Insert( "vertexShader", VERTEX_SHADER );
1515 customShader.Insert( "fragmentShader", FRAGMENT_SHADER );
1517 Property::Array shaderHints;
1518 shaderHints.PushBack( "requiresSelfDepthTest" );
1519 shaderHints.PushBack( "outputIsTransparent" );
1520 shaderHints.PushBack( "outputIsOpaque" );
1521 shaderHints.PushBack( "modifiesGeometry" );
1523 customShader.Insert( "hints", shaderHints );
1526 map.Insert( "shader", customShader );
1528 TestNativeImagePointer nativeImageInterface = TestNativeImage::New( width, height );
1529 NativeImage nativeImage = NativeImage::New( *(nativeImageInterface.Get()) );
1531 ImageView imageView = ImageView::New( nativeImage );
1532 imageView.SetProperty( ImageView::Property::IMAGE, map );
1533 Stage::GetCurrent().Add( imageView );
1535 TestGlAbstraction& gl = application.GetGlAbstraction();
1536 gl.EnableTextureCallTrace( true );
1538 std::vector< GLuint > ids;
1539 ids.push_back( 23 );
1540 application.GetGlAbstraction().SetNextTextureIds( ids );
1542 application.SendNotification();
1543 application.Render();
1545 DALI_TEST_CHECK( gl.GetTextureTrace().FindMethod("BindTexture") );
1547 std::stringstream params;
1548 params << GL_TEXTURE_EXTERNAL_OES << ", " << 23;
1549 DALI_TEST_CHECK( gl.GetTextureTrace().FindMethodAndParams("BindTexture", params.str()) );
1554 // Scenarios 6: ImageView initially from regular image with custom shader but then SetImage called with Native
1555 int UtcDaliImageViewSetImageBufferImageWithCustomShaderToNativeImage(void)
1557 ToolkitTestApplication application;
1562 Property::Map customShader;
1563 customShader.Insert( "vertexShader", VERTEX_SHADER );
1564 customShader.Insert( "fragmentShader", FRAGMENT_SHADER );
1566 Property::Array shaderHints;
1567 shaderHints.PushBack( "requiresSelfDepthTest" );
1568 shaderHints.PushBack( "outputIsTransparent" );
1569 shaderHints.PushBack( "outputIsOpaque" );
1570 shaderHints.PushBack( "modifiesGeometry" );
1572 customShader.Insert( "hints", shaderHints );
1575 map.Insert( "shader", customShader );
1577 BufferImage image = CreateBufferImage( width, height, Color::WHITE );
1579 ImageView imageView = ImageView::New( image );
1580 imageView.SetProperty( ImageView::Property::IMAGE, map );
1581 Stage::GetCurrent().Add( imageView );
1583 TestGlAbstraction& gl = application.GetGlAbstraction();
1584 gl.EnableTextureCallTrace( true );
1586 std::vector< GLuint > ids;
1587 ids.push_back( 23 );
1588 application.GetGlAbstraction().SetNextTextureIds( ids );
1590 application.SendNotification();
1591 application.Render();
1593 DALI_TEST_CHECK( gl.GetTextureTrace().FindMethod("BindTexture") );
1595 std::stringstream params;
1596 params << GL_TEXTURE_2D << ", " << 23;
1597 DALI_TEST_CHECK( gl.GetTextureTrace().FindMethodAndParams("BindTexture", params.str()) );
1599 TestNativeImagePointer nativeImageInterface = TestNativeImage::New( width, height );
1600 NativeImage nativeImage = NativeImage::New( *(nativeImageInterface.Get()) );
1601 imageView.SetImage( nativeImage );
1604 ids.push_back( 24 );
1605 application.GetGlAbstraction().SetNextTextureIds( ids );
1607 application.SendNotification();
1608 application.Render();
1610 DALI_TEST_CHECK( gl.GetTextureTrace().FindMethod("BindTexture") );
1612 std::stringstream nativeImageParams;
1613 nativeImageParams << GL_TEXTURE_EXTERNAL_OES << ", " << 24;
1614 DALI_TEST_CHECK( gl.GetTextureTrace().FindMethodAndParams("BindTexture", nativeImageParams.str()) );
1620 int UtcDaliImageViewGetImageP1(void)
1622 ToolkitTestApplication application;
1624 ImageView imageView = ImageView::New();
1625 DALI_TEST_CHECK( ! imageView.GetImage() );
1627 Image image = CreateBufferImage();
1628 imageView.SetImage( image );
1629 DALI_TEST_CHECK( imageView.GetImage() == image );
1634 int UtcDaliImageViewGetImageP2(void)
1636 ToolkitTestApplication application;
1638 BufferImage image = CreateBufferImage();
1639 ImageView imageView = ImageView::New( image );
1640 DALI_TEST_CHECK( imageView.GetImage() == image );
1645 int UtcDaliImageViewGetImageN(void)
1647 ToolkitTestApplication application;
1649 ImageView imageView = ImageView::New( TEST_IMAGE_FILE_NAME );
1650 DALI_TEST_CHECK( ! imageView.GetImage() );
1652 Image image = CreateBufferImage();
1653 imageView.SetImage( image );
1654 DALI_TEST_CHECK( imageView.GetImage() == image );
1656 imageView.SetImage( TEST_IMAGE_FILE_NAME );
1657 DALI_TEST_CHECK( ! imageView.GetImage() );
1663 int UtcDaliImageViewReplaceImage(void)
1665 ToolkitTestApplication application;
1667 gResourceReadySignalFired = false;
1671 Image image = CreateBufferImage( width, height, Vector4(1.f, 1.f, 1.f, 1.f) );
1673 // Check ImageView with background and main image, to ensure both visuals are marked as loaded
1674 ImageView imageView = ImageView::New( TEST_IMAGE_1 );
1676 DALI_TEST_EQUALS( imageView.IsResourceReady(), false, TEST_LOCATION );
1678 imageView.ResourceReadySignal().Connect( &ResourceReadySignal);
1680 Stage::GetCurrent().Add( imageView );
1682 application.SendNotification();
1683 application.Render(16);
1685 // loading started, this waits for the loader thread for max 30 seconds
1686 DALI_TEST_EQUALS( Test::WaitForEventThreadTrigger( 1 ), true, TEST_LOCATION );
1688 DALI_TEST_EQUALS( imageView.GetRendererCount(), 1u, TEST_LOCATION );
1690 DALI_TEST_EQUALS( gResourceReadySignalFired, true, TEST_LOCATION );
1692 gResourceReadySignalFired = false;
1694 imageView.SetImage(TEST_IMAGE_2);
1696 application.SendNotification();
1697 application.Render(16);
1699 // loading started, this waits for the loader thread for max 30 seconds
1700 DALI_TEST_EQUALS( Test::WaitForEventThreadTrigger( 1 ), true, TEST_LOCATION );
1702 DALI_TEST_EQUALS( imageView.GetRendererCount(), 1u, TEST_LOCATION );
1704 DALI_TEST_EQUALS( imageView.IsResourceReady(), true, TEST_LOCATION );
1706 DALI_TEST_EQUALS( gResourceReadySignalFired, true, TEST_LOCATION );
1711 void OnRelayoutOverride( Size size )
1713 gNaturalSize = size; // Size Relayout is using
1716 int UtcDaliImageViewReplaceImageAndGetNaturalSize(void)
1718 ToolkitTestApplication application;
1720 // Check ImageView with background and main image, to ensure both visuals are marked as loaded
1721 ImageView imageView = ImageView::New( TEST_IMAGE_1 );
1722 imageView.SetResizePolicy( ResizePolicy::USE_NATURAL_SIZE, Dimension::ALL_DIMENSIONS );
1724 DummyControl dummyControl = DummyControl::New( true );
1725 Impl::DummyControl& dummyImpl = static_cast<Impl::DummyControl&>(dummyControl.GetImplementation());
1726 dummyControl.SetResizePolicy( ResizePolicy::FIT_TO_CHILDREN, Dimension::ALL_DIMENSIONS );
1728 dummyControl.Add( imageView );
1729 dummyImpl.SetRelayoutCallback( &OnRelayoutOverride );
1730 Stage::GetCurrent().Add( dummyControl );
1732 application.SendNotification();
1733 application.Render();
1735 // loading started, this waits for the loader thread for max 30 seconds
1736 DALI_TEST_EQUALS( Test::WaitForEventThreadTrigger( 1 ), true, TEST_LOCATION );
1738 DALI_TEST_EQUALS( gNaturalSize.width, 1024.0f, TEST_LOCATION );
1739 DALI_TEST_EQUALS( gNaturalSize.height, 1024.0f, TEST_LOCATION );
1741 gNaturalSize = Vector3::ZERO;
1743 imageView.SetImage(gImage_600_RGB);
1745 // Waiting for resourceReady so SendNotifcation not called here.
1747 // loading started, this waits for the loader thread for max 30 seconds
1748 DALI_TEST_EQUALS( Test::WaitForEventThreadTrigger( 1 ), true, TEST_LOCATION );
1750 // Trigger a potential relayout
1751 application.SendNotification();
1752 application.Render();
1754 DALI_TEST_EQUALS( gNaturalSize.width, 600.0f, TEST_LOCATION );
1755 DALI_TEST_EQUALS( gNaturalSize.height, 600.0f, TEST_LOCATION );
1760 int UtcDaliImageViewResourceReadySignalWithImmediateLoad(void)
1762 tet_infoline("Test Setting Image with IMMEDIATE load and receving ResourceReadySignal before staged.");
1764 ToolkitTestApplication application;
1766 gResourceReadySignalFired = false;
1768 Property::Map imageMap;
1770 imageMap[ ImageVisual::Property::URL ] = gImage_34_RGBA;
1771 imageMap[ ImageVisual::Property::LOAD_POLICY ] = ImageVisual::LoadPolicy::IMMEDIATE;
1773 tet_infoline("Creating ImageView without URL so image does not start loading");
1774 ImageView imageView = ImageView::New();
1775 tet_infoline("Connect to image loaded signal before setting image");
1776 imageView.ResourceReadySignal().Connect( &ResourceReadySignal);
1777 tet_infoline("Setting Image with IMMEDIATE load, signal already connected so will be triggered.");
1778 imageView.SetProperty( ImageView::Property::IMAGE, imageMap );
1780 // loading started, this waits for the loader thread
1781 DALI_TEST_EQUALS( Test::WaitForEventThreadTrigger( 1 ), true, TEST_LOCATION );
1783 application.SendNotification();
1784 application.Render(16);
1786 DALI_TEST_EQUALS( gResourceReadySignalFired, true, TEST_LOCATION );
1791 int UtcDaliImageViewResourceReadySignalWithReusedImage(void)
1793 tet_infoline("Test Setting Image that was already loaded by another ImageView and still getting ResourceReadySignal.");
1795 ToolkitTestApplication application;
1797 gResourceReadySignalFired = false;
1799 Property::Map imageMap;
1801 imageMap[ ImageVisual::Property::URL ] = gImage_34_RGBA;
1802 imageMap[ ImageVisual::Property::LOAD_POLICY ] = ImageVisual::LoadPolicy::IMMEDIATE;
1804 ImageView imageView = ImageView::New();
1805 imageView.ResourceReadySignal().Connect( &ResourceReadySignal);
1806 imageView.SetProperty( ImageView::Property::IMAGE, imageMap );
1808 // loading started, this waits for the loader thread
1809 DALI_TEST_EQUALS( Test::WaitForEventThreadTrigger( 1 ), true, TEST_LOCATION );
1811 application.SendNotification();
1812 application.Render(16);
1814 DALI_TEST_EQUALS( gResourceReadySignalFired, true, TEST_LOCATION );
1815 gResourceReadySignalFired = false;
1817 ImageView imageViewWithExistingImage = ImageView::New();
1818 imageViewWithExistingImage.ResourceReadySignal().Connect( &ResourceReadySignal);
1819 imageViewWithExistingImage.SetProperty( ImageView::Property::IMAGE, imageMap );
1821 DALI_TEST_EQUALS( gResourceReadySignalFired, true, TEST_LOCATION );
1826 int UtcDaliImageViewResourceReadySignalWithReusedImage02(void)
1828 tet_infoline("Test Setting Image that was already loaded by another ImageView and still getting ResourceReadySignal when staged.");
1830 ToolkitTestApplication application;
1832 gResourceReadySignalFired = false;
1834 Property::Map imageImmediateLoadingMap;
1835 imageImmediateLoadingMap[ ImageVisual::Property::URL ] = gImage_34_RGBA;
1836 imageImmediateLoadingMap[ ImageVisual::Property::LOAD_POLICY ] = ImageVisual::LoadPolicy::IMMEDIATE;
1838 tet_infoline("Immediate load an image");
1839 ImageView imageView = ImageView::New();
1840 imageView.ResourceReadySignal().Connect( &ResourceReadySignal);
1841 imageView.SetProperty( ImageView::Property::IMAGE, imageImmediateLoadingMap );
1843 // loading started, this waits for the loader thread
1844 DALI_TEST_EQUALS( Test::WaitForEventThreadTrigger( 1 ), true, TEST_LOCATION );
1846 application.SendNotification();
1847 application.Render(16);
1849 tet_infoline("Check image loaded");
1850 DALI_TEST_EQUALS( gResourceReadySignalFired, true, TEST_LOCATION );
1851 gResourceReadySignalFired = false;
1853 tet_infoline("Create another ImageView with the same URL");
1854 ImageView imageViewWithExistingImage = ImageView::New( gImage_34_RGBA );
1855 tet_infoline("Connect to ResourceReady signal for second ImageView, it should still fire as resource is ready");
1856 imageViewWithExistingImage.ResourceReadySignal().Connect( &ResourceReadySignal);
1858 Stage::GetCurrent().Add( imageViewWithExistingImage );
1860 DALI_TEST_EQUALS( gResourceReadySignalFired, true, TEST_LOCATION );
1865 int UtcDaliImageViewPaddingProperty(void)
1867 ToolkitTestApplication application;
1869 ImageView imageView = ImageView::New();
1870 Property::Map imagePropertyMap;
1871 imagePropertyMap[ Toolkit::Visual::Property::TYPE ] = Toolkit::Visual::IMAGE;
1872 imagePropertyMap[ Toolkit::ImageVisual::Property::URL ] = TEST_RESOURCE_DIR "/gallery-small-1.jpg" ;
1873 imagePropertyMap[ ImageVisual::Property::DESIRED_WIDTH ] = 128;
1874 imagePropertyMap[ ImageVisual::Property::DESIRED_HEIGHT ] = 128;
1875 imageView.SetProperty( Toolkit::ImageView::Property::IMAGE , imagePropertyMap );
1876 imageView.SetAnchorPoint( AnchorPoint::TOP_LEFT );
1877 imageView.SetParentOrigin( ParentOrigin::TOP_LEFT );
1878 imageView.SetProperty( Control::Property::PADDING, Extents( 15, 10, 5, 10 ) );
1879 Stage::GetCurrent().Add( imageView );
1881 application.SendNotification();
1882 application.Render();
1884 DALI_TEST_EQUALS( imageView.GetProperty<Extents>( Control::Property::PADDING ), Extents( 15, 10, 5, 10 ), TEST_LOCATION );
1886 ImageView childImage = ImageView::New();
1887 childImage.SetBackgroundColor( Color::BLACK );
1888 childImage.SetSize( 10.f, 10.f );
1889 imageView.Add( childImage );
1891 application.SendNotification();
1892 application.Render();
1894 // Child ImageView should be positioned dependinig on Parent ImageView's Padding value
1895 DALI_TEST_EQUALS( childImage.GetProperty<Vector3>( Dali::Actor::Property::POSITION ), Vector3( 15, 5, 0 ), TEST_LOCATION );
1897 // Check whether Image Visual transforms on ImageVieiw::OnRelayout()
1898 Toolkit::Internal::Control& controlImpl = Toolkit::Internal::GetImplementation( imageView );
1899 Toolkit::Visual::Base imageVisual = DevelControl::GetVisual( controlImpl, ImageView::Property::IMAGE );
1900 Property::Map resultMap;
1901 imageVisual.CreatePropertyMap( resultMap );
1903 Property::Value* transformValue = resultMap.Find( Visual::Property::TRANSFORM );
1904 DALI_TEST_CHECK( transformValue );
1905 Property::Map* retMap = transformValue->GetMap();
1906 DALI_TEST_CHECK( retMap );
1908 // Image Visual should be positioned depending on ImageView's padding
1909 DALI_TEST_EQUALS( retMap->Find( Visual::Transform::Property::OFFSET )->Get< Vector2 >(), Vector2( 15, 5 ), TEST_LOCATION );
1914 int UtcDaliImageViewPaddingProperty02(void)
1916 ToolkitTestApplication application;
1918 ImageView imageView = ImageView::New();
1919 Property::Map imagePropertyMap;
1920 imagePropertyMap[ Toolkit::Visual::Property::TYPE ] = Toolkit::Visual::IMAGE;
1921 imagePropertyMap[ Toolkit::ImageVisual::Property::URL ] = TEST_RESOURCE_DIR "/Kid1.svg" ;
1922 imagePropertyMap[ ImageVisual::Property::DESIRED_WIDTH ] = 128;
1923 imagePropertyMap[ ImageVisual::Property::DESIRED_HEIGHT ] = 128;
1924 imagePropertyMap[ DevelVisual::Property::VISUAL_FITTING_MODE ] = Toolkit::DevelVisual::FIT_KEEP_ASPECT_RATIO;
1925 imageView.SetProperty( Toolkit::ImageView::Property::IMAGE , imagePropertyMap );
1926 imageView.SetAnchorPoint( AnchorPoint::TOP_LEFT );
1927 imageView.SetParentOrigin( ParentOrigin::TOP_LEFT );
1928 imageView.SetProperty( Control::Property::PADDING, Extents( 15, 10, 5, 10 ) );
1929 Stage::GetCurrent().Add( imageView );
1931 application.SendNotification();
1932 application.Render();
1934 DALI_TEST_EQUALS( imageView.GetProperty<Extents>( Control::Property::PADDING ), Extents( 15, 10, 5, 10 ), TEST_LOCATION );
1936 // Check whether Image Visual transforms on ImageVieiw::OnRelayout()
1937 Toolkit::Internal::Control& controlImpl = Toolkit::Internal::GetImplementation( imageView );
1938 Toolkit::Visual::Base imageVisual = DevelControl::GetVisual( controlImpl, ImageView::Property::IMAGE );
1939 Property::Map resultMap;
1940 imageVisual.CreatePropertyMap( resultMap );
1942 Property::Value* transformValue = resultMap.Find( Visual::Property::TRANSFORM );
1943 DALI_TEST_CHECK( transformValue );
1944 Property::Map* retMap = transformValue->GetMap();
1945 DALI_TEST_CHECK( retMap );
1947 // Image Visual should be positioned depending on ImageView's padding
1948 DALI_TEST_EQUALS( retMap->Find( Visual::Transform::Property::OFFSET )->Get< Vector2 >(), Vector2( 15, 5 ), TEST_LOCATION );
1953 int UtcDaliImageViewPaddingProperty03(void)
1955 tet_infoline("Test Setting Image Padding then removing it.");
1957 ToolkitTestApplication application;
1959 ImageView imageView = ImageView::New();
1960 Property::Map imagePropertyMap;
1961 imagePropertyMap[ Toolkit::Visual::Property::TYPE ] = Toolkit::Visual::IMAGE;
1962 imagePropertyMap[ Toolkit::ImageVisual::Property::URL ] = TEST_RESOURCE_DIR "/Kid1.svg" ;
1963 imagePropertyMap[ ImageVisual::Property::DESIRED_WIDTH ] = 128;
1964 imagePropertyMap[ ImageVisual::Property::DESIRED_HEIGHT ] = 128;
1965 imagePropertyMap[ DevelVisual::Property::VISUAL_FITTING_MODE ] = Toolkit::DevelVisual::FIT_KEEP_ASPECT_RATIO;
1966 imageView.SetProperty( Toolkit::ImageView::Property::IMAGE , imagePropertyMap );
1967 imageView.SetAnchorPoint( AnchorPoint::TOP_LEFT );
1968 imageView.SetParentOrigin( ParentOrigin::TOP_LEFT );
1969 imageView.SetProperty( Control::Property::PADDING, Extents( 15, 10, 5, 10 ) );
1970 Stage::GetCurrent().Add( imageView );
1972 application.SendNotification();
1973 application.Render();
1975 DALI_TEST_EQUALS( imageView.GetProperty<Extents>( Control::Property::PADDING ), Extents( 15, 10, 5, 10 ), TEST_LOCATION );
1977 tet_infoline("Remove Padding and test Visual is position correctly");
1979 imageView.SetProperty( Control::Property::PADDING, Extents( 0, 0, 0, 0 ) );
1981 application.SendNotification();
1982 application.Render();
1984 // Check whether Image Visual transforms on ImageVieiw::OnRelayout()
1985 Toolkit::Internal::Control& controlImpl = Toolkit::Internal::GetImplementation( imageView );
1986 Toolkit::Visual::Base imageVisual = DevelControl::GetVisual( controlImpl, ImageView::Property::IMAGE );
1987 Property::Map resultMap;
1988 imageVisual.CreatePropertyMap( resultMap );
1990 Property::Value* transformValue = resultMap.Find( Visual::Property::TRANSFORM );
1991 DALI_TEST_CHECK( transformValue );
1992 Property::Map* retMap = transformValue->GetMap();
1993 DALI_TEST_CHECK( retMap );
1995 // Image Visual should be positioned depending on ImageView's padding
1996 DALI_TEST_EQUALS( retMap->Find( Visual::Transform::Property::OFFSET )->Get< Vector2 >(), Vector2( 0, 0 ), TEST_LOCATION );
2001 int UtcDaliImageViewPaddingProperty04(void)
2003 tet_infoline("Test Setting Image Padding then removing it. Visual Fitting Mode as Fill");
2005 ToolkitTestApplication application;
2007 ImageView imageView = ImageView::New();
2008 Property::Map imagePropertyMap;
2009 imagePropertyMap[ Toolkit::Visual::Property::TYPE ] = Toolkit::Visual::IMAGE;
2010 imagePropertyMap[ Toolkit::ImageVisual::Property::URL ] = TEST_RESOURCE_DIR "/Kid1.svg" ;
2011 imagePropertyMap[ ImageVisual::Property::DESIRED_WIDTH ] = 128;
2012 imagePropertyMap[ ImageVisual::Property::DESIRED_HEIGHT ] = 128;
2013 imagePropertyMap[ DevelVisual::Property::VISUAL_FITTING_MODE ] = Toolkit::DevelVisual::FILL;
2014 imageView.SetProperty( Toolkit::ImageView::Property::IMAGE , imagePropertyMap );
2015 imageView.SetAnchorPoint( AnchorPoint::TOP_LEFT );
2016 imageView.SetParentOrigin( ParentOrigin::TOP_LEFT );
2017 imageView.SetProperty( Control::Property::PADDING, Extents( 15, 10, 5, 10 ) );
2018 Stage::GetCurrent().Add( imageView );
2020 application.SendNotification();
2021 application.Render();
2023 DALI_TEST_EQUALS( imageView.GetProperty<Extents>( Control::Property::PADDING ), Extents( 15, 10, 5, 10 ), TEST_LOCATION );
2025 tet_infoline("Remove Padding and test Visual is position correctly");
2027 imageView.SetProperty( Control::Property::PADDING, Extents( 0, 0, 0, 0 ) );
2029 application.SendNotification();
2030 application.Render();
2032 // Check whether Image Visual transforms on ImageVieiw::OnRelayout()
2033 Toolkit::Internal::Control& controlImpl = Toolkit::Internal::GetImplementation( imageView );
2034 Toolkit::Visual::Base imageVisual = DevelControl::GetVisual( controlImpl, ImageView::Property::IMAGE );
2035 Property::Map resultMap;
2036 imageVisual.CreatePropertyMap( resultMap );
2038 Property::Value* transformValue = resultMap.Find( Visual::Property::TRANSFORM );
2039 DALI_TEST_CHECK( transformValue );
2040 Property::Map* retMap = transformValue->GetMap();
2041 DALI_TEST_CHECK( retMap );
2043 // Image Visual should be positioned depending on ImageView's padding
2044 DALI_TEST_EQUALS( retMap->Find( Visual::Transform::Property::OFFSET )->Get< Vector2 >(), Vector2( 0, 0 ), TEST_LOCATION );
2049 int UtcDaliImageViewTransformTest01(void)
2051 tet_infoline("Test Setting a offset transform on the ImageView");
2053 ToolkitTestApplication application;
2055 ImageView imageView = ImageView::New();
2056 Property::Map imagePropertyMap;
2057 imagePropertyMap.Add( Toolkit::Visual::Property::TYPE,Toolkit::Visual::IMAGE )
2058 .Add( Toolkit::ImageVisual::Property::URL,TEST_RESOURCE_DIR "/Kid1.svg" )
2059 .Add( ImageVisual::Property::DESIRED_WIDTH,120 )
2060 .Add( ImageVisual::Property::DESIRED_HEIGHT,120 )
2061 .Add( DevelVisual::Property::VISUAL_FITTING_MODE, Toolkit::DevelVisual::FILL )
2062 .Add( Visual::Property::TRANSFORM,
2063 Property::Map().Add( Toolkit::Visual::Transform::Property::OFFSET_POLICY,
2064 Vector2( Visual::Transform::Policy::ABSOLUTE, Visual::Transform::Policy::ABSOLUTE ) )
2065 .Add( Toolkit::Visual::Transform::Property::OFFSET, Vector2( 8, 8 ) ) );
2067 imageView.SetProperty( Toolkit::ImageView::Property::IMAGE , imagePropertyMap );
2068 imageView.SetAnchorPoint( AnchorPoint::TOP_LEFT );
2069 imageView.SetParentOrigin( ParentOrigin::TOP_LEFT );
2070 Stage::GetCurrent().Add( imageView );
2072 application.SendNotification();
2073 application.Render();
2075 // Check whether Image Visual transforms on ImageVieiw::OnRelayout()
2076 Toolkit::Internal::Control& controlImpl = Toolkit::Internal::GetImplementation( imageView );
2077 Toolkit::Visual::Base imageVisual = DevelControl::GetVisual( controlImpl, ImageView::Property::IMAGE );
2078 Property::Map resultMap;
2079 imageVisual.CreatePropertyMap( resultMap );
2081 Property::Value* transformValue = resultMap.Find( Visual::Property::TRANSFORM );
2082 DALI_TEST_CHECK( transformValue );
2083 Property::Map* retMap = transformValue->GetMap();
2084 DALI_TEST_CHECK( retMap );
2086 // Image Visual should be positioned depending on ImageView's padding
2087 DALI_TEST_EQUALS( retMap->Find( Visual::Transform::Property::OFFSET )->Get< Vector2 >(), Vector2( 8, 8 ), TEST_LOCATION );
2088 DALI_TEST_EQUALS( retMap->Find( Visual::Transform::Property::OFFSET_POLICY )->Get< Vector2 >(), Vector2( Toolkit::Visual::Transform::Policy::ABSOLUTE, Toolkit::Visual::Transform::Policy::ABSOLUTE ), TEST_LOCATION );
2093 int UtcDaliImageViewUsingAtlasAndGetNaturalSize(void)
2095 ToolkitTestApplication application;
2097 // Check ImageView with background and main image, to ensure both visuals are marked as loaded
2098 ImageView imageView = ImageView::New();
2099 Property::Map imageMap;
2100 imageMap[ Toolkit::Visual::Property::TYPE ] = Toolkit::Visual::IMAGE;
2101 imageMap[ Toolkit::ImageVisual::Property::URL ] = gImage_34_RGBA;
2102 imageMap[ Toolkit::ImageVisual::Property::ATLASING ] = true;
2103 imageView.SetProperty( Toolkit::ImageView::Property::IMAGE, imageMap );
2104 Stage::GetCurrent().Add( imageView );
2106 // Trigger a potential relayout
2107 application.SendNotification();
2108 application.Render();
2110 Vector3 naturalSize = imageView.GetNaturalSize();
2112 DALI_TEST_EQUALS( naturalSize.width, 34.0f, TEST_LOCATION );
2113 DALI_TEST_EQUALS( naturalSize.height, 34.0f, TEST_LOCATION );
2118 int UtcDaliImageViewFillMode(void)
2120 ToolkitTestApplication application;
2122 tet_infoline( "Create an ImageVisual without padding and set the fill-mode to fill" );
2123 tet_infoline( " There should be no need to change the transform, our size-policy should be relative and size should be [1,1]");
2125 ImageView imageView = ImageView::New();
2126 Property::Map imageMap;
2127 imageMap.Add( Toolkit::Visual::Property::TYPE, Toolkit::Visual::IMAGE );
2128 imageMap.Add( Toolkit::ImageVisual::Property::URL, gImage_600_RGB );
2129 imageMap.Add( DevelVisual::Property::VISUAL_FITTING_MODE, DevelVisual::FittingMode::FILL );
2131 imageView.SetProperty( Toolkit::ImageView::Property::IMAGE, imageMap );
2133 Stage::GetCurrent().Add( imageView );
2135 // Trigger a potential relayout
2136 application.SendNotification();
2137 application.Render();
2139 Toolkit::Visual::Base visual = DevelControl::GetVisual( Toolkit::Internal::GetImplementation( imageView ), Toolkit::ImageView::Property::IMAGE );
2140 Property::Map returnedMap;
2141 visual.CreatePropertyMap( returnedMap );
2143 Property::Value* value = returnedMap.Find( Toolkit::Visual::Property::TRANSFORM );
2144 DALI_TEST_CHECK( value );
2145 Property::Map* map = value->GetMap();
2146 DALI_TEST_CHECK( map );
2149 value = map->Find( Toolkit::Visual::Transform::Property::SIZE );
2150 DALI_TEST_CHECK( value );
2151 DALI_TEST_EQUALS( value->Get< Vector2 >(), Vector2::ONE, TEST_LOCATION ); // Relative size so will take up 100%
2153 value = map->Find( Toolkit::Visual::Transform::Property::SIZE_POLICY );
2154 DALI_TEST_CHECK( value );
2155 DALI_TEST_CHECK( value->Get< int >() == Toolkit::Visual::Transform::Policy::RELATIVE );
2160 int UtcDaliImageViewCustomShader(void)
2162 ToolkitTestApplication application;
2164 // Set a custom shader with an image url
2166 Property::Map properties;
2167 Property::Map shader;
2168 const std::string vertexShader = "Foobar";
2169 const std::string fragmentShader = "Foobar";
2170 shader[Visual::Shader::Property::FRAGMENT_SHADER] = fragmentShader;
2171 shader[Visual::Shader::Property::VERTEX_SHADER] = vertexShader;
2173 properties[Visual::Property::TYPE] = Visual::IMAGE;
2174 properties[Visual::Property::SHADER] = shader;
2175 properties[ImageVisual::Property::URL] = TEST_IMAGE_FILE_NAME;
2177 ImageView imageView = ImageView::New();
2178 imageView.SetProperty( ImageView::Property::IMAGE, properties );
2180 Stage::GetCurrent().Add( imageView );
2182 application.SendNotification();
2183 application.Render();
2185 DALI_TEST_EQUALS( Test::WaitForEventThreadTrigger( 1 ), true, TEST_LOCATION );
2187 Renderer renderer = imageView.GetRendererAt( 0 );
2188 Shader shader2 = renderer.GetShader();
2189 Property::Value value = shader2.GetProperty( Shader::Property::PROGRAM );
2190 Property::Map* map = value.GetMap();
2191 DALI_TEST_CHECK( map );
2193 Property::Value* fragment = map->Find( "fragment" ); // fragment key name from shader-impl.cpp
2194 DALI_TEST_EQUALS( fragmentShader, fragment->Get< std::string >(), TEST_LOCATION );
2196 Property::Value* vertex = map->Find( "vertex" ); // vertex key name from shader-impl.cpp
2197 DALI_TEST_EQUALS( vertexShader, vertex->Get< std::string >(), TEST_LOCATION );
2200 // Set a custom shader after setting an image url
2202 Property::Map properties;
2203 Property::Map shader;
2204 const std::string vertexShader = "Foobar";
2205 const std::string fragmentShader = "Foobar";
2206 shader[Visual::Shader::Property::FRAGMENT_SHADER] = fragmentShader;
2207 shader[Visual::Shader::Property::VERTEX_SHADER] = vertexShader;
2209 properties[Visual::Property::SHADER] = shader;
2211 ImageView imageView = ImageView::New( TEST_IMAGE_FILE_NAME );
2212 imageView.SetProperty( ImageView::Property::IMAGE, properties );
2214 Stage::GetCurrent().Add( imageView );
2216 application.SendNotification();
2217 application.Render();
2219 DALI_TEST_EQUALS( Test::WaitForEventThreadTrigger( 1 ), true, TEST_LOCATION );
2221 Renderer renderer = imageView.GetRendererAt( 0 );
2222 Shader shader2 = renderer.GetShader();
2223 Property::Value value = shader2.GetProperty( Shader::Property::PROGRAM );
2224 Property::Map* map = value.GetMap();
2225 DALI_TEST_CHECK( map );
2227 Property::Value* fragment = map->Find( "fragment" ); // fragment key name from shader-impl.cpp
2228 DALI_TEST_EQUALS( fragmentShader, fragment->Get< std::string >(), TEST_LOCATION );
2230 Property::Value* vertex = map->Find( "vertex" ); // vertex key name from shader-impl.cpp
2231 DALI_TEST_EQUALS( vertexShader, vertex->Get< std::string >(), TEST_LOCATION );
2234 // Set a custom shader before setting an image url
2236 Property::Map properties;
2237 Property::Map shader;
2238 const std::string vertexShader = "Foobar";
2239 const std::string fragmentShader = "Foobar";
2240 shader[Visual::Shader::Property::FRAGMENT_SHADER] = fragmentShader;
2241 shader[Visual::Shader::Property::VERTEX_SHADER] = vertexShader;
2243 properties[Visual::Property::SHADER] = shader;
2245 ImageView imageView = ImageView::New();
2246 imageView.SetProperty( ImageView::Property::IMAGE, properties );
2247 imageView.SetProperty( ImageView::Property::IMAGE, TEST_IMAGE_FILE_NAME );
2249 Stage::GetCurrent().Add( imageView );
2251 application.SendNotification();
2252 application.Render();
2253 DALI_TEST_EQUALS( Test::WaitForEventThreadTrigger( 1 ), true, TEST_LOCATION );
2255 Renderer renderer = imageView.GetRendererAt( 0 );
2256 Shader shader2 = renderer.GetShader();
2257 Property::Value value = shader2.GetProperty( Shader::Property::PROGRAM );
2258 Property::Map* map = value.GetMap();
2259 DALI_TEST_CHECK( map );
2261 Property::Value* fragment = map->Find( "fragment" ); // fragment key name from shader-impl.cpp
2262 DALI_TEST_EQUALS( fragmentShader, fragment->Get< std::string >(), TEST_LOCATION );
2264 Property::Value* vertex = map->Find( "vertex" ); // vertex key name from shader-impl.cpp
2265 DALI_TEST_EQUALS( vertexShader, vertex->Get< std::string >(), TEST_LOCATION );
2268 // Set a custom shader after setting a property map
2270 Property::Map properties;
2271 Property::Map shader;
2272 const std::string vertexShader = "Foobar";
2273 const std::string fragmentShader = "Foobar";
2274 shader[Visual::Shader::Property::FRAGMENT_SHADER] = fragmentShader;
2275 shader[Visual::Shader::Property::VERTEX_SHADER] = vertexShader;
2277 properties[Visual::Property::SHADER] = shader;
2279 Property::Map properties1;
2280 properties1[Visual::Property::TYPE] = Visual::IMAGE;
2281 properties1[ImageVisual::Property::URL] = TEST_IMAGE_FILE_NAME;
2283 ImageView imageView = ImageView::New();
2284 imageView.SetProperty( ImageView::Property::IMAGE, properties1 );
2285 imageView.SetProperty( ImageView::Property::IMAGE, properties );
2287 Stage::GetCurrent().Add( imageView );
2289 application.SendNotification();
2290 application.Render();
2291 DALI_TEST_EQUALS( Test::WaitForEventThreadTrigger( 1 ), true, TEST_LOCATION );
2293 Renderer renderer = imageView.GetRendererAt( 0 );
2294 Shader shader2 = renderer.GetShader();
2295 Property::Value value = shader2.GetProperty( Shader::Property::PROGRAM );
2296 Property::Map* map = value.GetMap();
2297 DALI_TEST_CHECK( map );
2299 Property::Value* fragment = map->Find( "fragment" ); // fragment key name from shader-impl.cpp
2300 DALI_TEST_EQUALS( fragmentShader, fragment->Get< std::string >(), TEST_LOCATION );
2302 Property::Value* vertex = map->Find( "vertex" ); // vertex key name from shader-impl.cpp
2303 DALI_TEST_EQUALS( vertexShader, vertex->Get< std::string >(), TEST_LOCATION );
2306 // Set a custom shader before setting a property map
2308 Property::Map properties;
2309 Property::Map shader;
2310 const std::string vertexShader = "Foobar";
2311 const std::string fragmentShader = "Foobar";
2312 shader[Visual::Shader::Property::FRAGMENT_SHADER] = fragmentShader;
2313 shader[Visual::Shader::Property::VERTEX_SHADER] = vertexShader;
2315 properties[Visual::Property::SHADER] = shader;
2317 Property::Map properties1;
2318 properties1[Visual::Property::TYPE] = Visual::IMAGE;
2319 properties1[ImageVisual::Property::URL] = TEST_IMAGE_FILE_NAME;
2321 ImageView imageView = ImageView::New();
2322 imageView.SetProperty( ImageView::Property::IMAGE, properties );
2323 imageView.SetProperty( ImageView::Property::IMAGE, properties1 );
2325 Stage::GetCurrent().Add( imageView );
2327 application.SendNotification();
2328 application.Render();
2329 DALI_TEST_EQUALS( Test::WaitForEventThreadTrigger( 1 ), true, TEST_LOCATION );
2331 Renderer renderer = imageView.GetRendererAt( 0 );
2332 Shader shader2 = renderer.GetShader();
2333 Property::Value value = shader2.GetProperty( Shader::Property::PROGRAM );
2334 Property::Map* map = value.GetMap();
2335 DALI_TEST_CHECK( map );
2337 Property::Value* fragment = map->Find( "fragment" ); // fragment key name from shader-impl.cpp
2338 DALI_TEST_EQUALS( fragmentShader, fragment->Get< std::string >(), TEST_LOCATION );
2340 Property::Value* vertex = map->Find( "vertex" ); // vertex key name from shader-impl.cpp
2341 DALI_TEST_EQUALS( vertexShader, vertex->Get< std::string >(), TEST_LOCATION );
2350 static int gFailCounter = 0;
2351 const int MAX_RETRIES(3);
2353 void ReloadImage(ImageView imageView)
2355 Property::Map imageImmediateLoadingMap;
2356 imageImmediateLoadingMap[ ImageVisual::Property::URL ] = "Non-existant-image.jpg";
2357 imageImmediateLoadingMap[ ImageVisual::Property::LOAD_POLICY ] = ImageVisual::LoadPolicy::IMMEDIATE;
2359 tet_infoline("Immediate load an image");
2360 imageView.SetProperty( ImageView::Property::IMAGE, imageImmediateLoadingMap );
2363 void ResourceFailedReload( Control control )
2366 if( gFailCounter < MAX_RETRIES )
2368 ReloadImage(ImageView::DownCast(control));
2373 int UtcDaliImageViewReloadFailedOnResourceReadySignal(void)
2375 tet_infoline("Test reloading failed image from within signal handler.");
2377 ToolkitTestApplication application;
2381 ImageView imageView = ImageView::New();
2382 imageView.ResourceReadySignal().Connect( &ResourceFailedReload );
2383 DALI_TEST_EQUALS( gFailCounter, 0, TEST_LOCATION );
2384 ReloadImage(imageView);
2386 // loading started, this waits for the loader thread to complete
2387 DALI_TEST_EQUALS( Test::WaitForEventThreadTrigger( 1 ), true, TEST_LOCATION );
2388 application.SendNotification();
2390 DALI_TEST_EQUALS( gFailCounter, 1, TEST_LOCATION );
2392 DALI_TEST_EQUALS( Test::WaitForEventThreadTrigger( 1 ), true, TEST_LOCATION );
2393 application.SendNotification();
2395 DALI_TEST_EQUALS( gFailCounter, 2, TEST_LOCATION );
2397 DALI_TEST_EQUALS( Test::WaitForEventThreadTrigger( 1 ), true, TEST_LOCATION );
2398 application.SendNotification();
2399 DALI_TEST_EQUALS( gFailCounter, 3, TEST_LOCATION );
2404 int UtcDaliImageViewLoadRemoteSVG(void)
2406 tet_infoline("Test load from a remote server.");
2408 ToolkitTestApplication application;
2409 Toolkit::ImageView imageView;
2410 imageView = Toolkit::ImageView::New( );
2411 imageView.SetImage("https://dev.w3.org/SVG/tools/svgweb/samples/svg-files/check.svg");
2412 // Victor. Temporary (or permanent?) update as the url above seems not to work from time to time ...
2413 imageView.SetImage("https://upload.wikimedia.org/wikipedia/commons/thumb/0/02/SVG_logo.svg/64px-SVG_logo.svg.png");
2414 imageView.SetParentOrigin( ParentOrigin::TOP_LEFT );
2415 imageView.SetAnchorPoint( AnchorPoint::TOP_LEFT );
2416 imageView.SetSize(300, 300);
2417 imageView.SetPosition( Vector3( 150.0f , 150.0f , 0.0f ) );
2419 Stage::GetCurrent().Add( imageView );
2421 DALI_TEST_CHECK( imageView );
2423 DALI_TEST_EQUALS( imageView.GetRendererCount(), 0u, TEST_LOCATION );
2425 application.SendNotification();
2427 DALI_TEST_EQUALS( Test::WaitForEventThreadTrigger( 1 ), true, TEST_LOCATION );
2429 application.SendNotification();
2430 application.Render();
2432 DALI_TEST_EQUALS( imageView.GetRendererCount(), 1u, TEST_LOCATION );
2437 int UtcDaliImageViewSyncSVGLoading(void)
2439 ToolkitTestApplication application;
2441 tet_infoline("ImageView Testing SVG image sync loading");
2443 // Sync loading, automatic atlasing for small size image
2445 TraceCallStack& callStack = application.GetGlAbstraction().GetTextureTrace();
2447 callStack.Enable(true);
2449 ImageView imageView = ImageView::New( );
2451 // Sync loading is used
2452 Property::Map syncLoadingMap;
2453 syncLoadingMap.Insert( Toolkit::Visual::Property::TYPE, Toolkit::Visual::IMAGE );
2454 syncLoadingMap.Insert( Toolkit::ImageVisual::Property::URL, TEST_RESOURCE_DIR "/svg1.svg" );
2455 syncLoadingMap.Insert( Toolkit::ImageVisual::Property::SYNCHRONOUS_LOADING, true);
2456 imageView.SetProperty( ImageView::Property::IMAGE, syncLoadingMap );
2458 Stage::GetCurrent().Add( imageView );
2459 DALI_TEST_CHECK( imageView );
2461 application.SendNotification();
2462 application.Render(16);
2463 Vector3 naturalSize = imageView.GetNaturalSize();
2465 DALI_TEST_EQUALS( naturalSize.width, 100.0f, TEST_LOCATION );
2466 DALI_TEST_EQUALS( naturalSize.height, 100.0f, TEST_LOCATION );
2472 int UtcDaliImageViewAsyncSVGLoading(void)
2474 ToolkitTestApplication application;
2476 tet_infoline("ImageView Testing SVG image async loading");
2478 // Sync loading, automatic atlasing for small size image
2480 TraceCallStack& callStack = application.GetGlAbstraction().GetTextureTrace();
2482 callStack.Enable(true);
2484 ImageView imageView = ImageView::New( );
2486 // Sync loading is used
2487 Property::Map syncLoadingMap;
2488 syncLoadingMap.Insert( Toolkit::Visual::Property::TYPE, Toolkit::Visual::IMAGE );
2489 syncLoadingMap.Insert( Toolkit::ImageVisual::Property::URL, TEST_RESOURCE_DIR "/svg1.svg" );
2490 syncLoadingMap.Insert( Toolkit::ImageVisual::Property::SYNCHRONOUS_LOADING, false);
2491 imageView.SetProperty( ImageView::Property::IMAGE, syncLoadingMap );
2493 Stage::GetCurrent().Add( imageView );
2494 DALI_TEST_CHECK( imageView );
2496 application.SendNotification();
2497 application.Render(16);
2498 Vector3 naturalSize = imageView.GetNaturalSize();
2500 DALI_TEST_EQUALS( naturalSize.width, 100.0f, TEST_LOCATION );
2501 DALI_TEST_EQUALS( naturalSize.height, 100.0f, TEST_LOCATION );
2506 int UtcDaliImageViewSVGLoadingSyncSetInvalidValue(void)
2508 ToolkitTestApplication application;
2510 tet_infoline("ImageView Testing SVG image async loading");
2512 // Sync loading, automatic atlasing for small size image
2514 TraceCallStack& callStack = application.GetGlAbstraction().GetTextureTrace();
2516 callStack.Enable(true);
2518 ImageView imageView = ImageView::New( );
2520 // Sync loading is used
2521 Property::Map syncLoadingMap;
2522 syncLoadingMap.Insert( Toolkit::Visual::Property::TYPE, Toolkit::Visual::IMAGE );
2523 syncLoadingMap.Insert( Toolkit::ImageVisual::Property::URL, TEST_RESOURCE_DIR "/svg1.svg" );
2525 // Check to set invalid value
2526 // The SYNCHRONOUS_LOADING property must be set to the bool value.
2527 // Check if error log is outputted when setting other value like string.
2528 // Even if the wrong value is set, the image will be shown normally, and the synchronous value should be the default value(false).
2529 syncLoadingMap.Insert( Toolkit::ImageVisual::Property::SYNCHRONOUS_LOADING, std::to_string(5) );
2530 imageView.SetProperty( ImageView::Property::IMAGE, syncLoadingMap );
2532 Stage::GetCurrent().Add( imageView );
2533 DALI_TEST_CHECK( imageView );
2535 application.SendNotification();
2536 application.Render(16);
2537 Vector3 naturalSize = imageView.GetNaturalSize();
2538 DALI_TEST_EQUALS( naturalSize.width, 100.0f, TEST_LOCATION );
2539 DALI_TEST_EQUALS( naturalSize.height, 100.0f, TEST_LOCATION );
2541 Property::Value value = imageView.GetProperty( ImageView::Property::IMAGE );
2542 Property::Map* map = value.GetMap();
2543 DALI_TEST_CHECK( map );
2545 Property::Value* sync = map->Find( Toolkit::ImageVisual::Property::SYNCHRONOUS_LOADING );
2546 DALI_TEST_CHECK( sync );
2547 DALI_TEST_EQUALS( false, sync->Get< bool >(), TEST_LOCATION );
2553 int UtcDaliImageViewSvgLoadingFailure(void)
2555 ToolkitTestApplication application;
2559 gResourceReadySignalFired = false;
2561 ImageView imageView = ImageView::New( TEST_RESOURCE_DIR "/Kid1.svg" );
2562 imageView.SetSize( 200.f, 200.f );
2563 imageView.ResourceReadySignal().Connect( &ResourceReadySignal);
2565 DALI_TEST_EQUALS( imageView.IsResourceReady(), false, TEST_LOCATION );
2567 Stage::GetCurrent().Add( imageView );
2569 application.SendNotification();
2571 // loading started, this waits for the loader thread
2572 DALI_TEST_EQUALS( Test::WaitForEventThreadTrigger( 1 ), true, TEST_LOCATION );
2574 application.SendNotification();
2575 application.Render(16);
2577 DALI_TEST_EQUALS( gResourceReadySignalFired, true, TEST_LOCATION );
2578 DALI_TEST_EQUALS( imageView.IsResourceReady(), true, TEST_LOCATION );
2579 DALI_TEST_EQUALS( imageView.GetVisualResourceStatus( ImageView::Property::IMAGE ), Visual::ResourceStatus::FAILED, TEST_LOCATION );
2584 gResourceReadySignalFired = false;
2586 ImageView imageView = ImageView::New( "https://bar.org/foobar.svg" );
2587 imageView.SetSize( 200.f, 200.f );
2588 imageView.ResourceReadySignal().Connect( &ResourceReadySignal);
2590 DALI_TEST_EQUALS( imageView.IsResourceReady(), false, TEST_LOCATION );
2592 Stage::GetCurrent().Add( imageView );
2594 application.SendNotification();
2596 // loading started, this waits for the loader thread
2597 DALI_TEST_EQUALS( Test::WaitForEventThreadTrigger( 1 ), true, TEST_LOCATION );
2599 application.SendNotification();
2600 application.Render(16);
2602 DALI_TEST_EQUALS( gResourceReadySignalFired, true, TEST_LOCATION );
2603 DALI_TEST_EQUALS( imageView.IsResourceReady(), true, TEST_LOCATION );
2604 DALI_TEST_EQUALS( imageView.GetVisualResourceStatus( ImageView::Property::IMAGE ), Visual::ResourceStatus::FAILED, TEST_LOCATION );
2613 static int gResourceReadySignalCounter = 0;
2615 void OnResourceReadySignal( Control control )
2617 gResourceReadySignalCounter++;
2619 if( gResourceReadySignalCounter == 1 )
2622 ImageView::DownCast( control ).SetImage( gImage_34_RGBA );
2623 ImageView::DownCast( control ).SetImage( gImage_34_RGBA );
2629 int UtcDaliImageViewSetImageOnResourceReadySignal(void)
2631 tet_infoline("Test setting image from within signal handler.");
2633 ToolkitTestApplication application;
2635 gResourceReadySignalCounter = 0;
2637 ImageView imageView = ImageView::New( gImage_34_RGBA );
2638 imageView.ResourceReadySignal().Connect( &OnResourceReadySignal );
2640 Stage::GetCurrent().Add( imageView );
2642 DALI_TEST_EQUALS( Test::WaitForEventThreadTrigger( 1 ), true, TEST_LOCATION );
2644 application.SendNotification();
2645 application.Render();
2647 DALI_TEST_EQUALS( gResourceReadySignalCounter, 2, TEST_LOCATION );
2649 DALI_TEST_EQUALS( imageView.IsResourceReady(), true, TEST_LOCATION );