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 const char* TEST_VECTOR_IMAGE_FILE_NAME = TEST_RESOURCE_DIR "/insta_camera.json";
99 void TestImage( ImageView imageView, BufferImage image )
101 Property::Value value = imageView.GetProperty( imageView.GetPropertyIndex( "image" ) );
104 DALI_TEST_CHECK( value.Get( map ) );
106 DALI_TEST_CHECK( map.Find( "width" ) );
107 DALI_TEST_CHECK( map.Find( "height" ) );
108 DALI_TEST_CHECK( map.Find( "type" ) );
111 DALI_TEST_CHECK( map[ "width" ].Get( width ) );
112 DALI_TEST_EQUALS( (unsigned int)width, image.GetWidth(), TEST_LOCATION );
115 DALI_TEST_CHECK( map[ "height" ].Get( height ) );
116 DALI_TEST_EQUALS( (unsigned int)height, image.GetHeight(), TEST_LOCATION );
119 DALI_TEST_CHECK( map[ "type" ].Get( type ) );
120 DALI_TEST_EQUALS( type, "BufferImage", TEST_LOCATION );
123 void TestImage( ImageView imageView, ResourceImage image )
125 Property::Value value = imageView.GetProperty( imageView.GetPropertyIndex( "image" ) );
128 DALI_TEST_CHECK( value.Get( map ) );
130 if( map.Find( "width" ) )
133 DALI_TEST_CHECK( map[ "width" ].Get( width ) );
134 DALI_TEST_EQUALS( (unsigned int)width, image.GetWidth(), TEST_LOCATION );
137 if( map.Find( "height" ) )
140 DALI_TEST_CHECK( map[ "height" ].Get( height ) );
141 DALI_TEST_EQUALS( (unsigned int)height, image.GetHeight(), TEST_LOCATION );
144 DALI_TEST_CHECK( map.Find( "type" ) );
147 DALI_TEST_CHECK( map[ "type" ].Get( type ) );
148 DALI_TEST_EQUALS( type, "ResourceImage", TEST_LOCATION );
150 std::string filename;
151 DALI_TEST_CHECK( map[ "filename" ].Get( filename ) );
152 DALI_TEST_EQUALS( filename, image.GetUrl(), TEST_LOCATION );
155 void TestUrl( ImageView imageView, const std::string url )
157 Property::Value value = imageView.GetProperty( imageView.GetPropertyIndex( "image" ) );
159 std::string urlActual;
160 DALI_TEST_CHECK( value.Get( urlActual ) );
161 DALI_TEST_EQUALS( urlActual, url, TEST_LOCATION );
166 int UtcDaliImageViewNewP(void)
168 ToolkitTestApplication application;
170 ImageView imageView = ImageView::New();
172 DALI_TEST_CHECK( imageView );
177 int UtcDaliImageViewNewImageP(void)
179 ToolkitTestApplication application;
181 BufferImage image = CreateBufferImage( 100, 200, Vector4( 1.f, 1.f, 1.f, 1.f ) );
182 ImageView imageView = ImageView::New( image );
184 DALI_TEST_CHECK( imageView );
185 TestImage( imageView, image );
190 int UtcDaliImageViewNewUrlP(void)
192 ToolkitTestApplication application;
194 ImageView imageView = ImageView::New( TEST_IMAGE_FILE_NAME );
195 DALI_TEST_CHECK( imageView );
197 TestUrl( imageView, TEST_IMAGE_FILE_NAME );
202 int UtcDaliImageViewConstructorP(void)
204 ToolkitTestApplication application;
208 DALI_TEST_CHECK( !imageView );
213 int UtcDaliImageViewCopyConstructorP(void)
215 ToolkitTestApplication application;
217 // Initialize an object, ref count == 1
218 ImageView imageView = ImageView::New();
220 ImageView copy( imageView );
221 DALI_TEST_CHECK( copy );
226 int UtcDaliImageViewAssignmentOperatorP(void)
228 ToolkitTestApplication application;
230 ImageView imageView = ImageView::New();
232 ImageView copy( imageView );
233 DALI_TEST_CHECK( copy );
234 DALI_TEST_EQUALS( imageView, copy, TEST_LOCATION );
239 int UtcDaliImageViewDownCastP(void)
241 ToolkitTestApplication application;
243 ImageView imageView = ImageView::New();
245 BaseHandle object(imageView);
247 ImageView imageView2 = ImageView::DownCast( object );
248 DALI_TEST_CHECK(imageView2);
250 ImageView imageView3 = DownCast< ImageView >( object );
251 DALI_TEST_CHECK(imageView3);
256 int UtcDaliImageViewDownCastN(void)
258 ToolkitTestApplication application;
260 BaseHandle unInitializedObject;
262 ImageView imageView1 = ImageView::DownCast( unInitializedObject );
263 DALI_TEST_CHECK( !imageView1 );
265 ImageView imageView2 = DownCast< ImageView >( unInitializedObject );
266 DALI_TEST_CHECK( !imageView2 );
271 int UtcDaliImageViewTypeRegistry(void)
273 ToolkitTestApplication application;
275 TypeRegistry typeRegistry = TypeRegistry::Get();
276 DALI_TEST_CHECK( typeRegistry );
278 TypeInfo typeInfo = typeRegistry.GetTypeInfo( "ImageView" );
279 DALI_TEST_CHECK( typeInfo );
281 BaseHandle handle = typeInfo.CreateInstance();
282 DALI_TEST_CHECK( handle );
284 ImageView imageView = ImageView::DownCast( handle );
285 DALI_TEST_CHECK( imageView );
290 int UtcDaliImageViewSetGetProperty01(void)
292 ToolkitTestApplication application;
294 ImageView imageView = ImageView::New();
296 Property::Index idx = imageView.GetPropertyIndex( "image" );
297 DALI_TEST_EQUALS( idx, (Property::Index)ImageView::Property::IMAGE, TEST_LOCATION );
299 imageView.SetProperty( idx, TEST_IMAGE_FILE_NAME );
300 TestUrl( imageView, TEST_IMAGE_FILE_NAME );
305 int UtcDaliImageViewSetGetProperty02(void)
307 ToolkitTestApplication application;
309 Image image = CreateBufferImage( 10, 10, Color::WHITE );
310 ImageView imageView = ImageView::New(image);
311 Vector4 fullImageRect( 0.f, 0.f, 1.f, 1.f );
313 Stage::GetCurrent().Add( imageView );
315 application.SendNotification();
316 application.Render();
317 TestGlAbstraction& gl = application.GetGlAbstraction();
319 Vector4 pixelAreaUniform;
320 DALI_TEST_CHECK( gl.GetUniformValue<Vector4>( "pixelArea", pixelAreaUniform ) );
321 DALI_TEST_EQUALS( pixelAreaUniform, fullImageRect, TEST_LOCATION );
323 Property::Value value = imageView.GetProperty( ImageView::Property::PIXEL_AREA );
324 Vector4 pixelAreaValue;
325 DALI_TEST_CHECK( value.Get(pixelAreaValue) );
326 DALI_TEST_EQUALS( pixelAreaValue, fullImageRect, TEST_LOCATION );
328 Vector4 pixelAreaSet( 0.2f, 0.2f, 0.3f, 0.3f );
329 imageView.SetProperty( ImageView::Property::PIXEL_AREA, pixelAreaSet);
331 application.SendNotification();
332 application.Render();
334 value = imageView.GetProperty( ImageView::Property::PIXEL_AREA );
335 value.Get(pixelAreaValue);
336 DALI_TEST_EQUALS( pixelAreaValue, pixelAreaSet, TEST_LOCATION );
338 DALI_TEST_CHECK( gl.GetUniformValue<Vector4>( "pixelArea", pixelAreaUniform ) );
339 DALI_TEST_EQUALS( pixelAreaUniform, pixelAreaSet, TEST_LOCATION );
344 int UtcDaliImageViewSetGetProperty03(void)
346 ToolkitTestApplication application;
348 Image image = CreateBufferImage( 10, 10, Color::WHITE );
349 ImageView imageView = ImageView::New(image);
350 Stage::GetCurrent().Add( imageView );
351 application.SendNotification();
352 application.Render();
354 // conventional alpha blending
355 Renderer renderer = imageView.GetRendererAt( 0 );
356 Property::Value value = renderer.GetProperty( Renderer::Property::BLEND_PRE_MULTIPLIED_ALPHA );
358 DALI_TEST_CHECK( value.Get( enable ) );
359 DALI_TEST_CHECK( !enable );
361 // pre-multiplied alpha blending
362 imageView.SetProperty( Toolkit::ImageView::Property::PRE_MULTIPLIED_ALPHA, true );
363 application.SendNotification();
364 application.Render();
366 int srcFactorRgb = renderer.GetProperty<int>( Renderer::Property::BLEND_FACTOR_SRC_RGB );
367 int destFactorRgb = renderer.GetProperty<int>( Renderer::Property::BLEND_FACTOR_DEST_RGB );
368 int srcFactorAlpha = renderer.GetProperty<int>( Renderer::Property::BLEND_FACTOR_SRC_ALPHA );
369 int destFactorAlpha = renderer.GetProperty<int>( Renderer::Property::BLEND_FACTOR_DEST_ALPHA );
370 DALI_TEST_CHECK( srcFactorRgb == BlendFactor::ONE );
371 DALI_TEST_CHECK( destFactorRgb == BlendFactor::ONE_MINUS_SRC_ALPHA );
372 DALI_TEST_CHECK( srcFactorAlpha == BlendFactor::ONE );
373 DALI_TEST_CHECK( destFactorAlpha == BlendFactor::ONE_MINUS_SRC_ALPHA );
375 value = renderer.GetProperty( Renderer::Property::BLEND_PRE_MULTIPLIED_ALPHA );
376 DALI_TEST_CHECK( value.Get( enable ) );
377 DALI_TEST_CHECK( enable );
382 int UtcDaliImageViewPreMultipliedAlphaPng(void)
384 ToolkitTestApplication application;
386 // Set up trace debug
387 TestGlAbstraction& gl = application.GetGlAbstraction();
388 TraceCallStack& textureTrace = gl.GetTextureTrace();
389 textureTrace.Enable( true );
391 Property::Map imageMap;
392 imageMap[ ImageVisual::Property::URL ] = gImage_34_RGBA;
393 imageMap[ ImageVisual::Property::RELEASE_POLICY] = ImageVisual::ReleasePolicy::NEVER; // To keep the texture cache
395 ImageView imageView1 = ImageView::New();
396 imageView1.SetProperty( ImageView::Property::IMAGE, imageMap );
398 Stage::GetCurrent().Add( imageView1 );
400 Property::Value value = imageView1.GetProperty( ImageView::Property::PRE_MULTIPLIED_ALPHA );
402 DALI_TEST_CHECK( value.Get( enable ) );
403 DALI_TEST_CHECK( enable ); // Default value is true
405 // loading started, this waits for the loader thread for max 30 seconds
406 DALI_TEST_EQUALS( Test::WaitForEventThreadTrigger( 1 ), true, TEST_LOCATION );
408 application.SendNotification();
409 application.Render();
411 value = imageView1.GetProperty( ImageView::Property::PRE_MULTIPLIED_ALPHA );
412 DALI_TEST_CHECK( value.Get( enable ) );
413 DALI_TEST_CHECK( enable ); // Keep true
415 // conventional alpha blending
416 Renderer renderer1 = imageView1.GetRendererAt( 0 );
417 value = renderer1.GetProperty( Renderer::Property::BLEND_PRE_MULTIPLIED_ALPHA );
418 DALI_TEST_CHECK( value.Get( enable ) );
419 DALI_TEST_CHECK( enable );
421 int srcFactorRgb = renderer1.GetProperty<int>( Renderer::Property::BLEND_FACTOR_SRC_RGB );
422 int destFactorRgb = renderer1.GetProperty<int>( Renderer::Property::BLEND_FACTOR_DEST_RGB );
423 int srcFactorAlpha = renderer1.GetProperty<int>( Renderer::Property::BLEND_FACTOR_SRC_ALPHA );
424 int destFactorAlpha = renderer1.GetProperty<int>( Renderer::Property::BLEND_FACTOR_DEST_ALPHA );
425 DALI_TEST_CHECK( srcFactorRgb == BlendFactor::ONE );
426 DALI_TEST_CHECK( destFactorRgb == BlendFactor::ONE_MINUS_SRC_ALPHA );
427 DALI_TEST_CHECK( srcFactorAlpha == BlendFactor::ONE );
428 DALI_TEST_CHECK( destFactorAlpha == BlendFactor::ONE_MINUS_SRC_ALPHA );
430 DALI_TEST_EQUALS( textureTrace.FindMethod("GenTextures"), true, TEST_LOCATION ); // A new texture should be generated.
431 textureTrace.Reset();
433 // Disable pre-multiplied alpha blending
434 imageView1.SetProperty( ImageView::Property::PRE_MULTIPLIED_ALPHA, false );
437 Property::Map attributes;
438 DevelControl::DoAction( imageView1, ImageView::Property::IMAGE, DevelImageVisual::Action::RELOAD, attributes );
440 // loading started, this waits for the loader thread for max 30 seconds
441 DALI_TEST_EQUALS( Test::WaitForEventThreadTrigger( 1 ), true, TEST_LOCATION );
443 application.SendNotification();
444 application.Render();
446 value = imageView1.GetProperty( ImageView::Property::PRE_MULTIPLIED_ALPHA );
447 DALI_TEST_CHECK( value.Get( enable ) );
448 DALI_TEST_CHECK( !enable );
450 // conventional alpha blending
451 value = renderer1.GetProperty( Renderer::Property::BLEND_PRE_MULTIPLIED_ALPHA );
452 DALI_TEST_CHECK( value.Get( enable ) );
453 DALI_TEST_CHECK( !enable );
455 srcFactorRgb = renderer1.GetProperty<int>( Renderer::Property::BLEND_FACTOR_SRC_RGB );
456 destFactorRgb = renderer1.GetProperty<int>( Renderer::Property::BLEND_FACTOR_DEST_RGB );
457 srcFactorAlpha = renderer1.GetProperty<int>( Renderer::Property::BLEND_FACTOR_SRC_ALPHA );
458 destFactorAlpha = renderer1.GetProperty<int>( Renderer::Property::BLEND_FACTOR_DEST_ALPHA );
459 DALI_TEST_CHECK( srcFactorRgb == BlendFactor::SRC_ALPHA );
460 DALI_TEST_CHECK( destFactorRgb == BlendFactor::ONE_MINUS_SRC_ALPHA );
461 DALI_TEST_CHECK( srcFactorAlpha == BlendFactor::ONE );
462 DALI_TEST_CHECK( destFactorAlpha == BlendFactor::ONE_MINUS_SRC_ALPHA );
464 DALI_TEST_EQUALS( textureTrace.FindMethod("GenTextures"), true, TEST_LOCATION ); // A new texture should be generated.
465 textureTrace.Reset();
467 // Make a new ImageView using the same image
468 ImageView imageView2 = ImageView::New();
469 imageView2.SetProperty( ImageView::Property::IMAGE, imageMap );
471 Stage::GetCurrent().Add( imageView2 );
473 application.SendNotification();
474 application.Render();
476 Renderer renderer2 = imageView2.GetRendererAt( 0 );
477 value = renderer2.GetProperty( Renderer::Property::BLEND_PRE_MULTIPLIED_ALPHA );
478 DALI_TEST_CHECK( value.Get( enable ) );
479 DALI_TEST_CHECK( enable );
481 srcFactorRgb = renderer2.GetProperty<int>( Renderer::Property::BLEND_FACTOR_SRC_RGB );
482 destFactorRgb = renderer2.GetProperty<int>( Renderer::Property::BLEND_FACTOR_DEST_RGB );
483 srcFactorAlpha = renderer2.GetProperty<int>( Renderer::Property::BLEND_FACTOR_SRC_ALPHA );
484 destFactorAlpha = renderer2.GetProperty<int>( Renderer::Property::BLEND_FACTOR_DEST_ALPHA );
485 DALI_TEST_CHECK( srcFactorRgb == BlendFactor::ONE );
486 DALI_TEST_CHECK( destFactorRgb == BlendFactor::ONE_MINUS_SRC_ALPHA );
487 DALI_TEST_CHECK( srcFactorAlpha == BlendFactor::ONE );
488 DALI_TEST_CHECK( destFactorAlpha == BlendFactor::ONE_MINUS_SRC_ALPHA );
490 DALI_TEST_EQUALS( textureTrace.FindMethod("GenTextures"), false, TEST_LOCATION ); // The cached texture should be used.
495 int UtcDaliImageViewPreMultipliedAlphaJpg(void)
497 ToolkitTestApplication application;
499 // Set up trace debug
500 TestGlAbstraction& gl = application.GetGlAbstraction();
501 TraceCallStack& textureTrace = gl.GetTextureTrace();
502 textureTrace.Enable( true );
504 Property::Map imageMap;
505 imageMap[ ImageVisual::Property::URL ] = gImage_600_RGB;
506 imageMap[ ImageVisual::Property::RELEASE_POLICY] = ImageVisual::ReleasePolicy::NEVER; // To keep the texture cache
508 ImageView imageView1 = ImageView::New();
509 imageView1.SetProperty( ImageView::Property::IMAGE, imageMap );
511 Stage::GetCurrent().Add( imageView1 );
513 Property::Value value = imageView1.GetProperty( ImageView::Property::PRE_MULTIPLIED_ALPHA );
515 DALI_TEST_CHECK( value.Get( enable ) );
516 DALI_TEST_CHECK( enable ); // Default value is true
518 // loading started, this waits for the loader thread for max 30 seconds
519 DALI_TEST_EQUALS( Test::WaitForEventThreadTrigger( 1 ), true, TEST_LOCATION );
521 application.SendNotification();
522 application.Render();
524 value = imageView1.GetProperty( ImageView::Property::PRE_MULTIPLIED_ALPHA );
525 DALI_TEST_CHECK( value.Get( enable ) );
526 DALI_TEST_CHECK( !enable ); // Should be false after loading
528 // conventional alpha blending
529 Renderer renderer1 = imageView1.GetRendererAt( 0 );
530 value = renderer1.GetProperty( Renderer::Property::BLEND_PRE_MULTIPLIED_ALPHA );
531 DALI_TEST_CHECK( value.Get( enable ) );
532 DALI_TEST_CHECK( !enable );
534 int srcFactorRgb = renderer1.GetProperty<int>( Renderer::Property::BLEND_FACTOR_SRC_RGB );
535 int destFactorRgb = renderer1.GetProperty<int>( Renderer::Property::BLEND_FACTOR_DEST_RGB );
536 int srcFactorAlpha = renderer1.GetProperty<int>( Renderer::Property::BLEND_FACTOR_SRC_ALPHA );
537 int destFactorAlpha = renderer1.GetProperty<int>( Renderer::Property::BLEND_FACTOR_DEST_ALPHA );
538 DALI_TEST_CHECK( srcFactorRgb == BlendFactor::SRC_ALPHA );
539 DALI_TEST_CHECK( destFactorRgb == BlendFactor::ONE_MINUS_SRC_ALPHA );
540 DALI_TEST_CHECK( srcFactorAlpha == BlendFactor::ONE );
541 DALI_TEST_CHECK( destFactorAlpha == BlendFactor::ONE_MINUS_SRC_ALPHA );
543 DALI_TEST_EQUALS( textureTrace.FindMethod("GenTextures"), true, TEST_LOCATION ); // A new texture should be generated.
544 textureTrace.Reset();
546 ImageView imageView2 = ImageView::New();
547 imageView2.SetProperty( ImageView::Property::IMAGE, imageMap );
549 // Disable pre-multiplied alpha blending
550 imageView2.SetProperty( ImageView::Property::PRE_MULTIPLIED_ALPHA, false );
552 Stage::GetCurrent().Add( imageView2 );
554 application.SendNotification();
555 application.Render();
557 value = imageView2.GetProperty( ImageView::Property::PRE_MULTIPLIED_ALPHA );
558 DALI_TEST_CHECK( value.Get( enable ) );
559 DALI_TEST_CHECK( !enable );
561 // conventional alpha blending
562 Renderer renderer2 = imageView2.GetRendererAt( 0 );
563 value = renderer2.GetProperty( Renderer::Property::BLEND_PRE_MULTIPLIED_ALPHA );
564 DALI_TEST_CHECK( value.Get( enable ) );
565 DALI_TEST_CHECK( !enable );
567 srcFactorRgb = renderer2.GetProperty<int>( Renderer::Property::BLEND_FACTOR_SRC_RGB );
568 destFactorRgb = renderer2.GetProperty<int>( Renderer::Property::BLEND_FACTOR_DEST_RGB );
569 srcFactorAlpha = renderer2.GetProperty<int>( Renderer::Property::BLEND_FACTOR_SRC_ALPHA );
570 destFactorAlpha = renderer2.GetProperty<int>( Renderer::Property::BLEND_FACTOR_DEST_ALPHA );
571 DALI_TEST_CHECK( srcFactorRgb == BlendFactor::SRC_ALPHA );
572 DALI_TEST_CHECK( destFactorRgb == BlendFactor::ONE_MINUS_SRC_ALPHA );
573 DALI_TEST_CHECK( srcFactorAlpha == BlendFactor::ONE );
574 DALI_TEST_CHECK( destFactorAlpha == BlendFactor::ONE_MINUS_SRC_ALPHA );
576 DALI_TEST_EQUALS( textureTrace.FindMethod("GenTextures"), false, TEST_LOCATION ); // The cached texture should be used.
581 int UtcDaliImageViewPixelArea(void)
583 // Test pixel area property
584 ToolkitTestApplication application;
586 // Gif image, use AnimatedImageVisual internally
587 // Atlasing is applied to pack multiple frames, use custom wrap mode
588 ImageView gifView = ImageView::New();
589 const Vector4 pixelAreaVisual( 0.f, 0.f, 2.f, 2.f );
590 gifView.SetProperty( ImageView::Property::IMAGE,
591 Property::Map().Add( ImageVisual::Property::URL, TEST_GIF_FILE_NAME )
592 .Add( ImageVisual::Property::PIXEL_AREA, pixelAreaVisual ) );
595 Stage stage = Stage::GetCurrent();
596 stage.Add( gifView );
599 application.SendNotification();
600 application.Render(16);
601 DALI_TEST_CHECK( gifView.GetRendererCount() == 1u );
603 const Vector4 fullTextureRect( 0.f, 0.f, 1.f, 1.f );
604 // test that the pixel area value defined in the visual property map is registered on renderer
605 Renderer renderer = gifView.GetRendererAt(0);
606 Property::Value pixelAreaValue = renderer.GetProperty( renderer.GetPropertyIndex( "pixelArea" ) );
607 DALI_TEST_EQUALS( pixelAreaValue.Get<Vector4>(), pixelAreaVisual, TEST_LOCATION );
609 // test that the shader has the default pixel area value registered.
610 Shader shader = renderer.GetShader();
611 pixelAreaValue = shader.GetProperty( shader.GetPropertyIndex( "pixelArea" ) );
612 DALI_TEST_EQUALS( pixelAreaValue.Get<Vector4>(), fullTextureRect, TEST_LOCATION );
614 // test that the uniform uses the pixelArea property on the renderer.
615 TestGlAbstraction& gl = application.GetGlAbstraction();
616 Vector4 pixelAreaUniform;
617 DALI_TEST_CHECK( gl.GetUniformValue<Vector4>( "pixelArea", pixelAreaUniform ) );
618 DALI_TEST_EQUALS( pixelAreaVisual, pixelAreaUniform, Math::MACHINE_EPSILON_100, TEST_LOCATION );
620 // set the pixelArea property on the control
621 const Vector4 pixelAreaControl( -1.f, -1.f, 3.f, 3.f );
622 gifView.SetProperty( ImageView::Property::PIXEL_AREA, pixelAreaControl );
623 application.SendNotification();
624 application.Render(16);
626 // check the pixelArea property on the control
627 pixelAreaValue = gifView.GetProperty( gifView.GetPropertyIndex( "pixelArea" ) );
628 DALI_TEST_EQUALS( pixelAreaValue.Get<Vector4>(), pixelAreaControl, TEST_LOCATION );
629 // test that the uniform uses the pixelArea property on the control.
630 DALI_TEST_CHECK( gl.GetUniformValue<Vector4>( "pixelArea", pixelAreaUniform ) );
631 DALI_TEST_EQUALS( pixelAreaControl, pixelAreaUniform, Math::MACHINE_EPSILON_100, TEST_LOCATION );
637 int UtcDaliImageViewAsyncLoadingWithoutAltasing(void)
639 ToolkitTestApplication application;
640 TestGlAbstraction& gl = application.GetGlAbstraction();
641 const std::vector<GLuint>& textures = gl.GetBoundTextures();
642 size_t numTextures = textures.size();
644 // Async loading, no atlasing for big size image
645 ImageView imageView = ImageView::New( gImage_600_RGB );
647 // By default, Aysnc loading is used
648 Stage::GetCurrent().Add( imageView );
649 imageView.SetSize(100, 100);
650 imageView.SetProperty( Actor::Property::PARENT_ORIGIN, ParentOrigin::CENTER );
652 DALI_TEST_EQUALS( Test::WaitForEventThreadTrigger( 1 ), true, TEST_LOCATION );
654 application.SendNotification();
655 application.Render(16);
656 application.SendNotification();
658 const std::vector<GLuint>& textures2 = gl.GetBoundTextures();
659 DALI_TEST_GREATER( textures2.size(), numTextures, TEST_LOCATION );
666 int UtcDaliImageViewAsyncLoadingWithAtlasing(void)
668 ToolkitTestApplication application;
670 //Async loading, automatic atlasing for small size image
671 TraceCallStack& callStack = application.GetGlAbstraction().GetTextureTrace();
673 callStack.Enable(true);
675 Property::Map imageMap;
677 imageMap[ ImageVisual::Property::URL ] = gImage_34_RGBA;
678 imageMap[ ImageVisual::Property::DESIRED_HEIGHT ] = 34;
679 imageMap[ ImageVisual::Property::DESIRED_WIDTH ] = 34;
680 imageMap[ ImageVisual::Property::ATLASING] = true;
682 ImageView imageView = ImageView::New();
683 imageView.SetProperty( ImageView::Property::IMAGE, imageMap );
684 imageView.SetProperty( Toolkit::Control::Property::PADDING, Extents( 10u, 10u, 10u, 10u ) );
686 // By default, Aysnc loading is used
687 // loading is not started if the actor is offStage
689 Stage::GetCurrent().Add( imageView );
690 application.SendNotification();
691 application.Render(16);
692 application.Render(16);
693 application.SendNotification();
695 imageView.SetProperty( Dali::Actor::Property::LAYOUT_DIRECTION, Dali::LayoutDirection::RIGHT_TO_LEFT );
696 application.SendNotification();
697 application.Render(16);
698 application.Render(16);
699 application.SendNotification();
701 // loading started, this waits for the loader thread for max 30 seconds
702 DALI_TEST_EQUALS( Test::WaitForEventThreadTrigger( 1 ), true, TEST_LOCATION );
704 application.SendNotification();
705 application.Render(16);
707 callStack.Enable(false);
709 TraceCallStack::NamedParams params;
710 params["width"] = ToString(34);
711 params["height"] = ToString(34);
712 DALI_TEST_EQUALS( callStack.FindMethodAndParams( "TexSubImage2D", params ), true, TEST_LOCATION );
717 int UtcDaliImageViewAsyncLoadingWithAtlasing02(void)
719 ToolkitTestApplication application;
721 //Async loading, automatic atlasing for small size image
722 TraceCallStack& callStack = application.GetGlAbstraction().GetTextureTrace();
724 callStack.Enable(true);
726 Property::Map asyncLoadingMap;
727 asyncLoadingMap[ "url" ] = gImage_34_RGBA;
728 asyncLoadingMap[ "desiredHeight" ] = 34;
729 asyncLoadingMap[ "desiredWidth" ] = 34;
730 asyncLoadingMap[ "synchronousLoading" ] = false;
731 asyncLoadingMap[ "atlasing" ] = true;
733 ImageView imageView = ImageView::New();
734 imageView.SetProperty( ImageView::Property::IMAGE, asyncLoadingMap );
736 Stage::GetCurrent().Add( imageView );
737 application.SendNotification();
738 application.Render(16);
739 application.Render(16);
740 application.SendNotification();
742 // loading started, this waits for the loader thread for max 30 seconds
743 DALI_TEST_EQUALS( Test::WaitForEventThreadTrigger( 1 ), true, TEST_LOCATION );
745 application.SendNotification();
746 application.Render(16);
748 callStack.Enable(false);
750 TraceCallStack::NamedParams params;
751 params["width"] = ToString(34);
752 params["height"] = ToString(34);
753 DALI_TEST_EQUALS( callStack.FindMethodAndParams( "TexSubImage2D", params ), true, TEST_LOCATION );
758 int UtcDaliImageViewSyncLoading(void)
760 ToolkitTestApplication application;
762 tet_infoline("ImageView Testing sync loading and size using index key property map");
764 Property::Map syncLoadingMap;
765 syncLoadingMap[ ImageVisual::Property::SYNCHRONOUS_LOADING ] = true;
766 syncLoadingMap[ ImageVisual::Property::ATLASING ] = true;
768 // Sync loading, no atlasing for big size image
770 ImageView imageView = ImageView::New();
772 // Sync loading is used
773 syncLoadingMap[ ImageVisual::Property::URL ] = gImage_600_RGB;
774 imageView.SetProperty( ImageView::Property::IMAGE, syncLoadingMap );
777 // Sync loading, automatic atlasing for small size image
779 TraceCallStack& callStack = application.GetGlAbstraction().GetTextureTrace();
781 callStack.Enable(true);
783 ImageView imageView = ImageView::New( );
785 // Sync loading is used
786 syncLoadingMap[ ImageVisual::Property::URL ] = gImage_34_RGBA;
787 syncLoadingMap[ ImageVisual::Property::DESIRED_HEIGHT ] = 34;
788 syncLoadingMap[ ImageVisual::Property::DESIRED_WIDTH ] = 34;
789 imageView.SetProperty( ImageView::Property::IMAGE, syncLoadingMap );
791 Stage::GetCurrent().Add( imageView );
792 application.SendNotification();
793 application.Render(16);
795 TraceCallStack::NamedParams params;
796 params["width"] = ToString(34);
797 params["height"] = ToString(34);
798 DALI_TEST_EQUALS( callStack.FindMethodAndParams( "TexSubImage2D", params ),
799 true, TEST_LOCATION );
804 int UtcDaliImageViewSyncLoading02(void)
806 ToolkitTestApplication application;
808 tet_infoline("ImageView Testing sync loading and size using string key property map");
810 // Sync loading, automatic atlasing for small size image
812 TraceCallStack& callStack = application.GetGlAbstraction().GetTextureTrace();
814 callStack.Enable(true);
816 ImageView imageView = ImageView::New( );
818 // Sync loading is used
819 Property::Map syncLoadingMap;
820 syncLoadingMap[ "url" ] = gImage_34_RGBA;
821 syncLoadingMap[ "desiredHeight" ] = 34;
822 syncLoadingMap[ "desiredWidth" ] = 34;
823 syncLoadingMap[ "synchronousLoading" ] = true;
824 syncLoadingMap[ "atlasing" ] = true;
825 imageView.SetProperty( ImageView::Property::IMAGE, syncLoadingMap );
827 Stage::GetCurrent().Add( imageView );
828 application.SendNotification();
829 application.Render(16);
831 TraceCallStack::NamedParams params;
832 params["width"] = ToString(34);
833 params["height"] = ToString(34);
834 DALI_TEST_EQUALS( callStack.FindMethodAndParams( "TexSubImage2D", params ),
835 true, TEST_LOCATION );
840 int UtcDaliImageViewAddedTexture(void)
842 ToolkitTestApplication application;
844 tet_infoline("ImageView Testing image view with texture provided manager url");
846 ImageView imageView = ImageView::New();
848 // empty texture is ok, though pointless from app point of view
850 std::string url = TextureManager::AddTexture(empty);
851 DALI_TEST_CHECK(url.size() > 0u);
853 Property::Map propertyMap;
854 propertyMap[ImageVisual::Property::URL] = url;
855 imageView.SetProperty(ImageView::Property::IMAGE, propertyMap);
857 Stage::GetCurrent().Add( imageView );
858 application.SendNotification();
859 application.Render();
864 int UtcDaliImageViewSizeWithBackground(void)
866 ToolkitTestApplication application;
870 ImageView imageView = ImageView::New();
872 imageView.SetProperty( Control::Property::BACKGROUND,
874 { Toolkit::Visual::Property::TYPE, Toolkit::Visual::IMAGE },
875 { Toolkit::ImageVisual::Property::URL, TEST_RESOURCE_DIR "/gallery-small-1.jpg" },
876 { ImageVisual::Property::DESIRED_WIDTH, width },
877 { ImageVisual::Property::DESIRED_HEIGHT, height },
881 Stage::GetCurrent().Add( imageView );
882 application.SendNotification();
883 application.Render();
885 DALI_TEST_EQUALS( imageView.GetCurrentProperty< Vector3 >( Actor::Property::SIZE ).width, (float)width, TEST_LOCATION );
886 DALI_TEST_EQUALS( imageView.GetCurrentProperty< Vector3 >( Actor::Property::SIZE ).height, (float)height, TEST_LOCATION );
891 int UtcDaliImageViewSizeWithBackgroundAndImage(void)
893 ToolkitTestApplication application;
895 int widthBackground = 100;
896 int heightBackground = 200;
899 Image image = CreateBufferImage( width, height, Vector4(1.f, 1.f, 1.f, 1.f) );
901 ImageView imageView = ImageView::New();
903 imageView.SetProperty( Control::Property::BACKGROUND,
905 { Toolkit::Visual::Property::TYPE, Toolkit::Visual::IMAGE },
906 { Toolkit::ImageVisual::Property::URL, TEST_RESOURCE_DIR "/gallery-small-1.jpg" },
907 { ImageVisual::Property::DESIRED_WIDTH, widthBackground },
908 { ImageVisual::Property::DESIRED_HEIGHT, heightBackground },
912 imageView.SetImage( image );
914 Stage::GetCurrent().Add( imageView );
915 application.SendNotification();
916 application.Render();
918 DALI_TEST_EQUALS( imageView.GetCurrentProperty< Vector3 >( Actor::Property::SIZE ).width, (float)width, TEST_LOCATION );
919 DALI_TEST_EQUALS( imageView.GetCurrentProperty< Vector3 >( Actor::Property::SIZE ).height, (float)height, TEST_LOCATION );
924 int UtcDaliImageViewHeightForWidthBackground(void)
926 ToolkitTestApplication application;
928 int widthBackground = 100;
929 int heightBackground = 200;
931 ImageView imageView = ImageView::New();
933 imageView.SetProperty( Control::Property::BACKGROUND,
935 { Toolkit::Visual::Property::TYPE, Toolkit::Visual::IMAGE },
936 { Toolkit::ImageVisual::Property::URL, TEST_RESOURCE_DIR "/gallery-small-1.jpg" },
937 { ImageVisual::Property::DESIRED_WIDTH, widthBackground },
938 { ImageVisual::Property::DESIRED_HEIGHT, heightBackground }
942 Stage::GetCurrent().Add( imageView );
943 application.SendNotification();
944 application.Render();
946 Control control = Control::DownCast( imageView );
947 DALI_TEST_CHECK( control );
948 DALI_TEST_EQUALS( imageView.GetHeightForWidth( 123.f ), control.GetHeightForWidth( 123.f ), TEST_LOCATION );
949 DALI_TEST_EQUALS( imageView.GetWidthForHeight( 321.f ), control.GetWidthForHeight( 321.f ), TEST_LOCATION );
954 int UtcDaliImageViewHeightForWidthBackgroundAndImage(void)
956 ToolkitTestApplication application;
958 int widthBackground = 100;
959 int heightBackground = 200;
963 Image image = CreateBufferImage( width, height, Vector4(1.f, 1.f, 1.f, 1.f) );
965 ImageView imageView = ImageView::New();
967 imageView.SetProperty( Control::Property::BACKGROUND,
969 { Toolkit::Visual::Property::TYPE, Toolkit::Visual::IMAGE },
970 { Toolkit::ImageVisual::Property::URL, TEST_RESOURCE_DIR "/gallery-small-1.jpg" },
971 { ImageVisual::Property::DESIRED_WIDTH, widthBackground },
972 { ImageVisual::Property::DESIRED_HEIGHT, heightBackground }
976 imageView.SetImage( image );
978 Stage::GetCurrent().Add( imageView );
979 application.SendNotification();
980 application.Render();
982 DALI_TEST_EQUALS( imageView.GetHeightForWidth( width ), (float)height, TEST_LOCATION );
983 DALI_TEST_EQUALS( imageView.GetWidthForHeight( height ), (float)width, TEST_LOCATION );
988 int UtcDaliImageViewSetBufferImage(void)
990 ToolkitTestApplication application;
994 BufferImage image1 = CreateBufferImage( width1, height1, Vector4( 1.f, 1.f, 1.f, 1.f ) );
995 ImageView imageView = ImageView::New();
996 imageView.SetImage( image1 );
998 TestImage( imageView, image1 );
1002 BufferImage image2 = CreateBufferImage( width2, height2, Vector4( 1.f, 1.f, 1.f, 1.f ) );
1003 imageView.SetImage( image2 );
1005 TestImage( imageView, image2 );
1010 int UtcDaliImageViewSetImageUrl(void)
1012 ToolkitTestApplication application;
1014 ImageView imageView = ImageView::New();
1015 imageView.SetImage( TEST_IMAGE_FILE_NAME );
1016 TestUrl( imageView, TEST_IMAGE_FILE_NAME );
1019 imageView.SetImage( TEST_IMAGE_FILE_NAME2 );
1020 TestUrl( imageView, TEST_IMAGE_FILE_NAME2 );
1025 int UtcDaliImageViewSetImageOnstageP(void)
1027 ToolkitTestApplication application;
1029 ImageView imageView = ImageView::New();
1031 Stage::GetCurrent().Add( imageView );
1032 application.SendNotification();
1033 application.Render();
1035 ResourceImage image1 = ResourceImage::New( TEST_IMAGE_FILE_NAME );
1036 imageView.SetImage( image1 );
1037 TestImage( imageView, image1 );
1041 BufferImage image2 = CreateBufferImage( width, height, Vector4( 1.f, 1.f, 1.f, 1.f ) );
1042 imageView.SetImage( image2 );
1043 TestImage( imageView, image2 );
1048 int UtcDaliImageViewSetImageOnstageN(void)
1050 ToolkitTestApplication application;
1052 ImageView imageView = ImageView::New();
1054 Stage::GetCurrent().Add( imageView );
1055 application.SendNotification();
1056 application.Render();
1058 ResourceImage image1 = ResourceImage::New( TEST_IMAGE_FILE_NAME );
1059 imageView.SetImage( image1 );
1060 TestImage( imageView, image1 );
1063 imageView.SetImage( image2 );
1065 Property::Value value = imageView.GetProperty( imageView.GetPropertyIndex( "image" ) );
1067 //the value should be empty
1069 DALI_TEST_CHECK( !value.Get( url ) );
1073 DALI_TEST_CHECK( map.Empty() );
1078 int UtcDaliImageViewSetImageOffstageP(void)
1080 ToolkitTestApplication application;
1082 ImageView imageView = ImageView::New();
1084 Stage::GetCurrent().Add( imageView );
1085 application.SendNotification();
1086 application.Render();
1087 Stage::GetCurrent().Remove( imageView );
1089 ResourceImage image1 = ResourceImage::New( TEST_IMAGE_FILE_NAME );
1090 imageView.SetImage( image1 );
1091 TestImage( imageView, image1 );
1095 BufferImage image2 = CreateBufferImage( width, height, Vector4( 1.f, 1.f, 1.f, 1.f ) );
1096 imageView.SetImage( image2 );
1097 TestImage( imageView, image2 );
1102 bool gResourceReadySignalFired = false;
1103 Vector3 gNaturalSize;
1105 void ResourceReadySignal( Control control )
1107 gResourceReadySignalFired = true;
1110 int UtcDaliImageViewCheckResourceReady(void)
1112 ToolkitTestApplication application;
1114 gResourceReadySignalFired = false;
1116 // Check ImageView with background and main image, to ensure both visuals are marked as loaded
1117 ImageView imageView = ImageView::New( TEST_GIF_FILE_NAME );
1119 imageView.SetProperty( Control::Property::BACKGROUND,
1121 { Toolkit::Visual::Property::TYPE, Toolkit::Visual::IMAGE },
1122 { Toolkit::ImageVisual::Property::URL, TEST_RESOURCE_DIR "/gallery-small-1.jpg" },
1123 { ImageVisual::Property::DESIRED_WIDTH, 100 },
1124 { ImageVisual::Property::DESIRED_HEIGHT, 200 }
1128 DALI_TEST_EQUALS( imageView.IsResourceReady(), false, TEST_LOCATION );
1130 imageView.ResourceReadySignal().Connect( &ResourceReadySignal);
1132 Stage::GetCurrent().Add( imageView );
1134 // loading started, this waits for the loader thread
1135 DALI_TEST_EQUALS( Test::WaitForEventThreadTrigger( 1 ), true, TEST_LOCATION );
1137 application.SendNotification();
1138 application.Render(16);
1140 DALI_TEST_EQUALS( imageView.IsResourceReady(), true, TEST_LOCATION );
1142 DALI_TEST_EQUALS( gResourceReadySignalFired, true, TEST_LOCATION );
1147 int UtcDaliImageViewSetImageOffstageN(void)
1149 ToolkitTestApplication application;
1151 ImageView imageView = ImageView::New();
1153 Stage::GetCurrent().Add( imageView );
1154 application.SendNotification();
1155 application.Render();
1156 Stage::GetCurrent().Remove( imageView );
1158 ResourceImage image1 = ResourceImage::New( TEST_IMAGE_FILE_NAME );
1159 imageView.SetImage( image1 );
1160 TestImage( imageView, image1 );
1163 imageView.SetImage( image2 );
1165 Property::Value value = imageView.GetProperty( imageView.GetPropertyIndex( "image" ) );
1167 //the value should be empty
1169 DALI_TEST_CHECK( !value.Get( url ) );
1173 DALI_TEST_CHECK( map.Empty() );
1178 int UtcDaliImageViewSetImageN(void)
1180 ToolkitTestApplication application;
1183 ImageView imageView = ImageView::New();
1184 imageView.SetImage( image1 );
1186 Property::Value value = imageView.GetProperty( imageView.GetPropertyIndex( "image" ) );
1188 //the value should be empty
1190 DALI_TEST_CHECK( !value.Get( url ) );
1194 DALI_TEST_CHECK( map.Empty() );
1196 std::string resource_url;
1197 Property::Value val = imageView.GetProperty( imageView.GetPropertyIndex( "image" ) );
1198 DALI_TEST_CHECK( !val.Get( resource_url ) );
1203 int UtcDaliImageViewSetImageTypeChangesP(void)
1205 ToolkitTestApplication application;
1207 ImageView imageView = ImageView::New();
1208 Toolkit::Internal::Control& controlImpl = Toolkit::Internal::GetImplementation( imageView );
1210 Stage::GetCurrent().Add( imageView );
1214 Toolkit::Visual::Base visual;
1216 Property::Value value = imageView.GetProperty( imageView.GetPropertyIndex( "image" ) );
1217 visual = DevelControl::GetVisual( controlImpl, ImageView::Property::IMAGE );
1219 application.SendNotification();
1220 application.Render( 16 );
1222 DALI_TEST_CHECK( ! value.Get( url ) ); // Value should be empty
1224 DALI_TEST_CHECK( map.Empty() ); // Value should be empty
1225 DALI_TEST_CHECK( ! visual ); // Visual should be invalid
1228 imageView.SetImage( "TEST_URL" );
1230 application.SendNotification();
1231 application.Render( 16 );
1233 value = imageView.GetProperty( imageView.GetPropertyIndex( "image" ) );
1234 visual = DevelControl::GetVisual( controlImpl, ImageView::Property::IMAGE );
1236 DALI_TEST_CHECK( value.Get( url ) ); // Value should NOT be empty
1237 DALI_TEST_CHECK( ! value.Get( map ) ); // Value should be empty
1238 DALI_TEST_CHECK( visual ); // Visual should be valid
1240 // Set an empty Image
1241 imageView.SetImage( Image() );
1243 application.SendNotification();
1244 application.Render( 16 );
1246 value = imageView.GetProperty( imageView.GetPropertyIndex( "image" ) );
1247 visual = DevelControl::GetVisual( controlImpl, ImageView::Property::IMAGE );
1249 DALI_TEST_CHECK( ! value.Get( url ) ); // Value should be empty
1251 DALI_TEST_CHECK( map.Empty() ); // Value should be empty
1252 DALI_TEST_CHECK( ! visual ); // Visual should be invalid
1255 ResourceImage image1 = ResourceImage::New( TEST_IMAGE_FILE_NAME );
1256 imageView.SetImage( image1 );
1258 application.SendNotification();
1259 application.Render( 16 );
1261 value = imageView.GetProperty( imageView.GetPropertyIndex( "image" ) );
1262 visual = DevelControl::GetVisual( controlImpl, ImageView::Property::IMAGE );
1264 DALI_TEST_CHECK( ! value.Get( url ) ); // Value should be empty
1265 DALI_TEST_CHECK( value.Get( map ) ); // Value should NOT be empty
1266 DALI_TEST_CHECK( visual ); // Visual should be valid
1269 imageView.SetImage( "" );
1271 application.SendNotification();
1272 application.Render( 16 );
1274 value = imageView.GetProperty( imageView.GetPropertyIndex( "image" ) );
1275 visual = DevelControl::GetVisual( controlImpl, ImageView::Property::IMAGE );
1277 DALI_TEST_CHECK( ! value.Get( url ) ); // Value should be empty
1279 DALI_TEST_CHECK( map.Empty() ); // Value should be empty
1280 DALI_TEST_CHECK( ! visual ); // Visual should be invalid
1282 // Set a URL in property map
1283 Property::Map propertyMap;
1284 propertyMap[ImageVisual::Property::URL] = TEST_IMAGE_FILE_NAME;
1285 imageView.SetProperty( ImageView::Property::IMAGE, propertyMap );
1287 application.SendNotification();
1288 application.Render( 16 );
1290 value = imageView.GetProperty( imageView.GetPropertyIndex( "image" ) );
1291 visual = DevelControl::GetVisual( controlImpl, ImageView::Property::IMAGE );
1293 DALI_TEST_CHECK( ! value.Get( url ) ); // Value should be empty
1294 DALI_TEST_CHECK( value.Get( map ) ); // Value should NOT be empty
1295 DALI_TEST_CHECK( visual ); // Visual should be valid
1297 // Set a URL in property map again
1298 propertyMap[ImageVisual::Property::URL] = gImage_34_RGBA;
1299 imageView.SetProperty( ImageView::Property::IMAGE, propertyMap );
1301 application.SendNotification();
1302 application.Render( 16 );
1304 value = imageView.GetProperty( imageView.GetPropertyIndex( "image" ) );
1305 visual = DevelControl::GetVisual( controlImpl, ImageView::Property::IMAGE );
1307 DALI_TEST_CHECK( ! value.Get( url ) ); // Value should be empty
1308 DALI_TEST_CHECK( value.Get( map ) ); // Value should NOT be empty
1309 DALI_TEST_CHECK( visual ); // Visual should be valid
1311 // Set an empty URL in property map
1312 propertyMap[ImageVisual::Property::URL] = std::string();
1313 imageView.SetProperty( ImageView::Property::IMAGE, propertyMap );
1315 application.SendNotification();
1316 application.Render( 16 );
1318 value = imageView.GetProperty( imageView.GetPropertyIndex( "image" ) );
1319 visual = DevelControl::GetVisual( controlImpl, ImageView::Property::IMAGE );
1321 DALI_TEST_CHECK( ! value.Get( url ) ); // Value should be empty
1322 DALI_TEST_CHECK( value.Get( map ) ); // Value should NOT be empty
1323 DALI_TEST_CHECK( ! visual ); // Visual should be invalid
1328 int UtcDaliImageViewResourceUrlP(void)
1330 ToolkitTestApplication application;
1332 ImageView imageView = ImageView::New();
1333 DALI_TEST_CHECK( imageView.GetProperty( ImageView::Property::IMAGE ).Get< std::string >().empty() );
1335 imageView.SetProperty( ImageView::Property::IMAGE, "TestString" );
1336 DALI_TEST_EQUALS( imageView.GetProperty( ImageView::Property::IMAGE ).Get< std::string >(), "TestString", TEST_LOCATION );
1341 // Scenarios 1: ImageView from regular image
1342 int UtcDaliImageViewSetImageBufferImage(void)
1344 ToolkitTestApplication application;
1346 ImageView imageView = ImageView::New();
1347 Stage::GetCurrent().Add( imageView );
1349 TestGlAbstraction& gl = application.GetGlAbstraction();
1350 gl.EnableTextureCallTrace( true );
1352 std::vector< GLuint > ids;
1353 ids.push_back( 23 );
1354 application.GetGlAbstraction().SetNextTextureIds( ids );
1358 BufferImage image = CreateBufferImage( width, height, Color::WHITE );
1360 imageView.SetImage( image );
1362 application.SendNotification();
1363 application.Render();
1365 DALI_TEST_CHECK( gl.GetTextureTrace().FindMethod("BindTexture") );
1367 std::stringstream params;
1368 params << GL_TEXTURE_2D << ", " << 23;
1369 DALI_TEST_CHECK( gl.GetTextureTrace().FindMethodAndParams("BindTexture", params.str()) );
1374 // Scenarios 2: ImageView from Native image
1375 int UtcDaliImageViewSetImageNativeImage(void)
1377 ToolkitTestApplication application;
1379 ImageView imageView = ImageView::New();
1380 Stage::GetCurrent().Add( imageView );
1382 TestGlAbstraction& gl = application.GetGlAbstraction();
1383 gl.EnableTextureCallTrace( true );
1385 std::vector< GLuint > ids;
1386 ids.push_back( 23 );
1387 application.GetGlAbstraction().SetNextTextureIds( ids );
1391 TestNativeImagePointer nativeImageInterface = TestNativeImage::New( width, height );
1392 NativeImage nativeImage = NativeImage::New( *(nativeImageInterface.Get()) );
1394 imageView.SetImage( nativeImage );
1395 application.SendNotification();
1396 application.Render();
1398 DALI_TEST_CHECK( gl.GetTextureTrace().FindMethod("BindTexture") );
1400 std::stringstream params;
1401 params << GL_TEXTURE_EXTERNAL_OES << ", " << 23;
1402 DALI_TEST_CHECK( gl.GetTextureTrace().FindMethodAndParams("BindTexture", params.str()) );
1407 // Scenarios 3: ImageView initially from regular image but then SetImage called with Native image
1408 int UtcDaliImageViewSetImageBufferImageToNativeImage(void)
1410 ToolkitTestApplication application;
1414 BufferImage image = CreateBufferImage( width, height, Color::WHITE );
1416 ImageView imageView = ImageView::New( image );
1417 Stage::GetCurrent().Add( imageView );
1419 TestGlAbstraction& gl = application.GetGlAbstraction();
1420 gl.EnableTextureCallTrace( true );
1422 std::vector< GLuint > ids;
1423 ids.push_back( 23 );
1424 application.GetGlAbstraction().SetNextTextureIds( ids );
1426 application.SendNotification();
1427 application.Render();
1429 DALI_TEST_CHECK( gl.GetTextureTrace().FindMethod("BindTexture") );
1431 std::stringstream params;
1432 params << GL_TEXTURE_2D << ", " << 23;
1433 DALI_TEST_CHECK( gl.GetTextureTrace().FindMethodAndParams("BindTexture", params.str()) );
1437 TestNativeImagePointer nativeImageInterface = TestNativeImage::New( width, height );
1438 NativeImage nativeImage = NativeImage::New( *(nativeImageInterface.Get()) );
1439 imageView.SetImage( nativeImage );
1442 ids.push_back( 24 );
1443 application.GetGlAbstraction().SetNextTextureIds( ids );
1445 application.SendNotification();
1446 application.Render();
1448 DALI_TEST_CHECK( gl.GetTextureTrace().FindMethod("BindTexture") );
1450 std::stringstream nextTextureParams;
1451 nextTextureParams << GL_TEXTURE_EXTERNAL_OES << ", " << 24;
1452 DALI_TEST_CHECK( gl.GetTextureTrace().FindMethodAndParams("BindTexture", nextTextureParams.str()) );
1457 // Scenarios 4: ImageView initially from Native image but then SetImage called with regular image
1458 int UtcDaliImageViewSetImageNativeImageToBufferImage(void)
1460 ToolkitTestApplication application;
1464 TestNativeImagePointer nativeImageInterface = TestNativeImage::New( width, height );
1465 NativeImage nativeImage = NativeImage::New( *(nativeImageInterface.Get()) );
1467 ImageView imageView = ImageView::New( nativeImage );
1468 Stage::GetCurrent().Add( imageView );
1470 TestGlAbstraction& gl = application.GetGlAbstraction();
1471 gl.EnableTextureCallTrace( true );
1473 std::vector< GLuint > ids;
1474 ids.push_back( 23 );
1475 application.GetGlAbstraction().SetNextTextureIds( ids );
1477 application.SendNotification();
1478 application.Render();
1480 DALI_TEST_CHECK( gl.GetTextureTrace().FindMethod("BindTexture") );
1482 std::stringstream params;
1483 params << GL_TEXTURE_EXTERNAL_OES << ", " << 23;
1484 DALI_TEST_CHECK( gl.GetTextureTrace().FindMethodAndParams("BindTexture", params.str()) );
1488 BufferImage image = CreateBufferImage( width, height, Color::WHITE );
1489 imageView.SetImage( image );
1492 ids.push_back( 24 );
1493 application.GetGlAbstraction().SetNextTextureIds( ids );
1495 application.SendNotification();
1496 application.Render();
1498 DALI_TEST_CHECK( gl.GetTextureTrace().FindMethod("BindTexture") );
1500 std::stringstream nextTextureParams;
1501 nextTextureParams << GL_TEXTURE_2D << ", " << 24;
1502 DALI_TEST_CHECK( gl.GetTextureTrace().FindMethodAndParams("BindTexture", nextTextureParams.str()) );
1507 // Scenarios 5: ImageView from Native image with custom shader
1508 int UtcDaliImageViewSetImageNativeImageWithCustomShader(void)
1510 ToolkitTestApplication application;
1515 Property::Map customShader;
1516 customShader.Insert( "vertexShader", VERTEX_SHADER );
1517 customShader.Insert( "fragmentShader", FRAGMENT_SHADER );
1519 Property::Array shaderHints;
1520 shaderHints.PushBack( "requiresSelfDepthTest" );
1521 shaderHints.PushBack( "outputIsTransparent" );
1522 shaderHints.PushBack( "outputIsOpaque" );
1523 shaderHints.PushBack( "modifiesGeometry" );
1525 customShader.Insert( "hints", shaderHints );
1528 map.Insert( "shader", customShader );
1530 TestNativeImagePointer nativeImageInterface = TestNativeImage::New( width, height );
1531 NativeImage nativeImage = NativeImage::New( *(nativeImageInterface.Get()) );
1533 ImageView imageView = ImageView::New( nativeImage );
1534 imageView.SetProperty( ImageView::Property::IMAGE, map );
1535 Stage::GetCurrent().Add( imageView );
1537 TestGlAbstraction& gl = application.GetGlAbstraction();
1538 gl.EnableTextureCallTrace( true );
1540 std::vector< GLuint > ids;
1541 ids.push_back( 23 );
1542 application.GetGlAbstraction().SetNextTextureIds( ids );
1544 application.SendNotification();
1545 application.Render();
1547 DALI_TEST_CHECK( gl.GetTextureTrace().FindMethod("BindTexture") );
1549 std::stringstream params;
1550 params << GL_TEXTURE_EXTERNAL_OES << ", " << 23;
1551 DALI_TEST_CHECK( gl.GetTextureTrace().FindMethodAndParams("BindTexture", params.str()) );
1556 // Scenarios 6: ImageView initially from regular image with custom shader but then SetImage called with Native
1557 int UtcDaliImageViewSetImageBufferImageWithCustomShaderToNativeImage(void)
1559 ToolkitTestApplication application;
1564 Property::Map customShader;
1565 customShader.Insert( "vertexShader", VERTEX_SHADER );
1566 customShader.Insert( "fragmentShader", FRAGMENT_SHADER );
1568 Property::Array shaderHints;
1569 shaderHints.PushBack( "requiresSelfDepthTest" );
1570 shaderHints.PushBack( "outputIsTransparent" );
1571 shaderHints.PushBack( "outputIsOpaque" );
1572 shaderHints.PushBack( "modifiesGeometry" );
1574 customShader.Insert( "hints", shaderHints );
1577 map.Insert( "shader", customShader );
1579 BufferImage image = CreateBufferImage( width, height, Color::WHITE );
1581 ImageView imageView = ImageView::New( image );
1582 imageView.SetProperty( ImageView::Property::IMAGE, map );
1583 Stage::GetCurrent().Add( imageView );
1585 TestGlAbstraction& gl = application.GetGlAbstraction();
1586 gl.EnableTextureCallTrace( true );
1588 std::vector< GLuint > ids;
1589 ids.push_back( 23 );
1590 application.GetGlAbstraction().SetNextTextureIds( ids );
1592 application.SendNotification();
1593 application.Render();
1595 DALI_TEST_CHECK( gl.GetTextureTrace().FindMethod("BindTexture") );
1597 std::stringstream params;
1598 params << GL_TEXTURE_2D << ", " << 23;
1599 DALI_TEST_CHECK( gl.GetTextureTrace().FindMethodAndParams("BindTexture", params.str()) );
1601 TestNativeImagePointer nativeImageInterface = TestNativeImage::New( width, height );
1602 NativeImage nativeImage = NativeImage::New( *(nativeImageInterface.Get()) );
1603 imageView.SetImage( nativeImage );
1606 ids.push_back( 24 );
1607 application.GetGlAbstraction().SetNextTextureIds( ids );
1609 application.SendNotification();
1610 application.Render();
1612 DALI_TEST_CHECK( gl.GetTextureTrace().FindMethod("BindTexture") );
1614 std::stringstream nativeImageParams;
1615 nativeImageParams << GL_TEXTURE_EXTERNAL_OES << ", " << 24;
1616 DALI_TEST_CHECK( gl.GetTextureTrace().FindMethodAndParams("BindTexture", nativeImageParams.str()) );
1622 int UtcDaliImageViewGetImageP1(void)
1624 ToolkitTestApplication application;
1626 ImageView imageView = ImageView::New();
1627 DALI_TEST_CHECK( ! imageView.GetImage() );
1629 Image image = CreateBufferImage();
1630 imageView.SetImage( image );
1631 DALI_TEST_CHECK( imageView.GetImage() == image );
1636 int UtcDaliImageViewGetImageP2(void)
1638 ToolkitTestApplication application;
1640 BufferImage image = CreateBufferImage();
1641 ImageView imageView = ImageView::New( image );
1642 DALI_TEST_CHECK( imageView.GetImage() == image );
1647 int UtcDaliImageViewGetImageN(void)
1649 ToolkitTestApplication application;
1651 ImageView imageView = ImageView::New( TEST_IMAGE_FILE_NAME );
1652 DALI_TEST_CHECK( ! imageView.GetImage() );
1654 Image image = CreateBufferImage();
1655 imageView.SetImage( image );
1656 DALI_TEST_CHECK( imageView.GetImage() == image );
1658 imageView.SetImage( TEST_IMAGE_FILE_NAME );
1659 DALI_TEST_CHECK( ! imageView.GetImage() );
1665 int UtcDaliImageViewReplaceImage(void)
1667 ToolkitTestApplication application;
1669 gResourceReadySignalFired = false;
1673 Image image = CreateBufferImage( width, height, Vector4(1.f, 1.f, 1.f, 1.f) );
1675 // Check ImageView with background and main image, to ensure both visuals are marked as loaded
1676 ImageView imageView = ImageView::New( TEST_IMAGE_1 );
1678 DALI_TEST_EQUALS( imageView.IsResourceReady(), false, TEST_LOCATION );
1680 imageView.ResourceReadySignal().Connect( &ResourceReadySignal);
1682 Stage::GetCurrent().Add( imageView );
1684 application.SendNotification();
1685 application.Render(16);
1687 // loading started, this waits for the loader thread for max 30 seconds
1688 DALI_TEST_EQUALS( Test::WaitForEventThreadTrigger( 1 ), true, TEST_LOCATION );
1690 DALI_TEST_EQUALS( imageView.GetRendererCount(), 1u, TEST_LOCATION );
1692 DALI_TEST_EQUALS( gResourceReadySignalFired, true, TEST_LOCATION );
1694 gResourceReadySignalFired = false;
1696 imageView.SetImage(TEST_IMAGE_2);
1698 application.SendNotification();
1699 application.Render(16);
1701 // loading started, this waits for the loader thread for max 30 seconds
1702 DALI_TEST_EQUALS( Test::WaitForEventThreadTrigger( 1 ), true, TEST_LOCATION );
1704 DALI_TEST_EQUALS( imageView.GetRendererCount(), 1u, TEST_LOCATION );
1706 DALI_TEST_EQUALS( imageView.IsResourceReady(), true, TEST_LOCATION );
1708 DALI_TEST_EQUALS( gResourceReadySignalFired, true, TEST_LOCATION );
1713 void OnRelayoutOverride( Size size )
1715 gNaturalSize = size; // Size Relayout is using
1718 int UtcDaliImageViewReplaceImageAndGetNaturalSize(void)
1720 ToolkitTestApplication application;
1722 // Check ImageView with background and main image, to ensure both visuals are marked as loaded
1723 ImageView imageView = ImageView::New( TEST_IMAGE_1 );
1724 imageView.SetResizePolicy( ResizePolicy::USE_NATURAL_SIZE, Dimension::ALL_DIMENSIONS );
1726 DummyControl dummyControl = DummyControl::New( true );
1727 Impl::DummyControl& dummyImpl = static_cast<Impl::DummyControl&>(dummyControl.GetImplementation());
1728 dummyControl.SetResizePolicy( ResizePolicy::FIT_TO_CHILDREN, Dimension::ALL_DIMENSIONS );
1730 dummyControl.Add( imageView );
1731 dummyImpl.SetRelayoutCallback( &OnRelayoutOverride );
1732 Stage::GetCurrent().Add( dummyControl );
1734 application.SendNotification();
1735 application.Render();
1737 // loading started, this waits for the loader thread for max 30 seconds
1738 DALI_TEST_EQUALS( Test::WaitForEventThreadTrigger( 1 ), true, TEST_LOCATION );
1740 DALI_TEST_EQUALS( gNaturalSize.width, 1024.0f, TEST_LOCATION );
1741 DALI_TEST_EQUALS( gNaturalSize.height, 1024.0f, TEST_LOCATION );
1743 gNaturalSize = Vector3::ZERO;
1745 imageView.SetImage(gImage_600_RGB);
1747 // Waiting for resourceReady so SendNotifcation not called here.
1749 // loading started, this waits for the loader thread for max 30 seconds
1750 DALI_TEST_EQUALS( Test::WaitForEventThreadTrigger( 1 ), true, TEST_LOCATION );
1752 // Trigger a potential relayout
1753 application.SendNotification();
1754 application.Render();
1756 DALI_TEST_EQUALS( gNaturalSize.width, 600.0f, TEST_LOCATION );
1757 DALI_TEST_EQUALS( gNaturalSize.height, 600.0f, TEST_LOCATION );
1762 int UtcDaliImageViewResourceReadySignalWithImmediateLoad(void)
1764 tet_infoline("Test Setting Image with IMMEDIATE load and receving ResourceReadySignal before staged.");
1766 ToolkitTestApplication application;
1768 gResourceReadySignalFired = false;
1770 Property::Map imageMap;
1772 imageMap[ ImageVisual::Property::URL ] = gImage_34_RGBA;
1773 imageMap[ ImageVisual::Property::LOAD_POLICY ] = ImageVisual::LoadPolicy::IMMEDIATE;
1775 tet_infoline("Creating ImageView without URL so image does not start loading");
1776 ImageView imageView = ImageView::New();
1777 tet_infoline("Connect to image loaded signal before setting image");
1778 imageView.ResourceReadySignal().Connect( &ResourceReadySignal);
1779 tet_infoline("Setting Image with IMMEDIATE load, signal already connected so will be triggered.");
1780 imageView.SetProperty( ImageView::Property::IMAGE, imageMap );
1782 // loading started, this waits for the loader thread
1783 DALI_TEST_EQUALS( Test::WaitForEventThreadTrigger( 1 ), true, TEST_LOCATION );
1785 application.SendNotification();
1786 application.Render(16);
1788 DALI_TEST_EQUALS( gResourceReadySignalFired, true, TEST_LOCATION );
1793 int UtcDaliImageViewResourceReadySignalWithReusedImage(void)
1795 tet_infoline("Test Setting Image that was already loaded by another ImageView and still getting ResourceReadySignal.");
1797 ToolkitTestApplication application;
1799 gResourceReadySignalFired = false;
1801 Property::Map imageMap;
1803 imageMap[ ImageVisual::Property::URL ] = gImage_34_RGBA;
1804 imageMap[ ImageVisual::Property::LOAD_POLICY ] = ImageVisual::LoadPolicy::IMMEDIATE;
1806 ImageView imageView = ImageView::New();
1807 imageView.ResourceReadySignal().Connect( &ResourceReadySignal);
1808 imageView.SetProperty( ImageView::Property::IMAGE, imageMap );
1810 // loading started, this waits for the loader thread
1811 DALI_TEST_EQUALS( Test::WaitForEventThreadTrigger( 1 ), true, TEST_LOCATION );
1813 application.SendNotification();
1814 application.Render(16);
1816 DALI_TEST_EQUALS( gResourceReadySignalFired, true, TEST_LOCATION );
1817 gResourceReadySignalFired = false;
1819 ImageView imageViewWithExistingImage = ImageView::New();
1820 imageViewWithExistingImage.ResourceReadySignal().Connect( &ResourceReadySignal);
1821 imageViewWithExistingImage.SetProperty( ImageView::Property::IMAGE, imageMap );
1823 DALI_TEST_EQUALS( gResourceReadySignalFired, true, TEST_LOCATION );
1828 int UtcDaliImageViewResourceReadySignalWithReusedImage02(void)
1830 tet_infoline("Test Setting Image that was already loaded by another ImageView and still getting ResourceReadySignal when staged.");
1832 ToolkitTestApplication application;
1834 gResourceReadySignalFired = false;
1836 Property::Map imageImmediateLoadingMap;
1837 imageImmediateLoadingMap[ ImageVisual::Property::URL ] = gImage_34_RGBA;
1838 imageImmediateLoadingMap[ ImageVisual::Property::LOAD_POLICY ] = ImageVisual::LoadPolicy::IMMEDIATE;
1840 tet_infoline("Immediate load an image");
1841 ImageView imageView = ImageView::New();
1842 imageView.ResourceReadySignal().Connect( &ResourceReadySignal);
1843 imageView.SetProperty( ImageView::Property::IMAGE, imageImmediateLoadingMap );
1845 // loading started, this waits for the loader thread
1846 DALI_TEST_EQUALS( Test::WaitForEventThreadTrigger( 1 ), true, TEST_LOCATION );
1848 application.SendNotification();
1849 application.Render(16);
1851 tet_infoline("Check image loaded");
1852 DALI_TEST_EQUALS( gResourceReadySignalFired, true, TEST_LOCATION );
1853 gResourceReadySignalFired = false;
1855 tet_infoline("Create another ImageView with the same URL");
1856 ImageView imageViewWithExistingImage = ImageView::New( gImage_34_RGBA );
1857 tet_infoline("Connect to ResourceReady signal for second ImageView, it should still fire as resource is ready");
1858 imageViewWithExistingImage.ResourceReadySignal().Connect( &ResourceReadySignal);
1860 Stage::GetCurrent().Add( imageViewWithExistingImage );
1862 DALI_TEST_EQUALS( gResourceReadySignalFired, true, TEST_LOCATION );
1867 int UtcDaliImageViewPaddingProperty(void)
1869 ToolkitTestApplication application;
1871 ImageView imageView = ImageView::New();
1872 Property::Map imagePropertyMap;
1873 imagePropertyMap[ Toolkit::Visual::Property::TYPE ] = Toolkit::Visual::IMAGE;
1874 imagePropertyMap[ Toolkit::ImageVisual::Property::URL ] = TEST_RESOURCE_DIR "/gallery-small-1.jpg" ;
1875 imagePropertyMap[ ImageVisual::Property::DESIRED_WIDTH ] = 128;
1876 imagePropertyMap[ ImageVisual::Property::DESIRED_HEIGHT ] = 128;
1877 imageView.SetProperty( Toolkit::ImageView::Property::IMAGE , imagePropertyMap );
1878 imageView.SetProperty( Actor::Property::ANCHOR_POINT, AnchorPoint::TOP_LEFT );
1879 imageView.SetProperty( Actor::Property::PARENT_ORIGIN, ParentOrigin::TOP_LEFT );
1880 imageView.SetProperty( Control::Property::PADDING, Extents( 15, 10, 5, 10 ) );
1881 Stage::GetCurrent().Add( imageView );
1883 application.SendNotification();
1884 application.Render();
1886 DALI_TEST_EQUALS( imageView.GetProperty<Extents>( Control::Property::PADDING ), Extents( 15, 10, 5, 10 ), TEST_LOCATION );
1888 ImageView childImage = ImageView::New();
1889 childImage.SetBackgroundColor( Color::BLACK );
1890 childImage.SetSize( 10.f, 10.f );
1891 imageView.Add( childImage );
1893 application.SendNotification();
1894 application.Render();
1896 // Child ImageView should be positioned dependinig on Parent ImageView's Padding value
1897 DALI_TEST_EQUALS( childImage.GetProperty<Vector3>( Dali::Actor::Property::POSITION ), Vector3( 15, 5, 0 ), TEST_LOCATION );
1899 // Check whether Image Visual transforms on ImageVieiw::OnRelayout()
1900 Toolkit::Internal::Control& controlImpl = Toolkit::Internal::GetImplementation( imageView );
1901 Toolkit::Visual::Base imageVisual = DevelControl::GetVisual( controlImpl, ImageView::Property::IMAGE );
1902 Property::Map resultMap;
1903 imageVisual.CreatePropertyMap( resultMap );
1905 Property::Value* transformValue = resultMap.Find( Visual::Property::TRANSFORM );
1906 DALI_TEST_CHECK( transformValue );
1907 Property::Map* retMap = transformValue->GetMap();
1908 DALI_TEST_CHECK( retMap );
1910 // Image Visual should be positioned depending on ImageView's padding
1911 DALI_TEST_EQUALS( retMap->Find( Visual::Transform::Property::OFFSET )->Get< Vector2 >(), Vector2( 15, 5 ), TEST_LOCATION );
1916 int UtcDaliImageViewPaddingProperty02(void)
1918 ToolkitTestApplication application;
1920 ImageView imageView = ImageView::New();
1921 Property::Map imagePropertyMap;
1922 imagePropertyMap[ Toolkit::Visual::Property::TYPE ] = Toolkit::Visual::IMAGE;
1923 imagePropertyMap[ Toolkit::ImageVisual::Property::URL ] = TEST_RESOURCE_DIR "/Kid1.svg" ;
1924 imagePropertyMap[ ImageVisual::Property::DESIRED_WIDTH ] = 128;
1925 imagePropertyMap[ ImageVisual::Property::DESIRED_HEIGHT ] = 128;
1926 imagePropertyMap[ DevelVisual::Property::VISUAL_FITTING_MODE ] = Toolkit::DevelVisual::FIT_KEEP_ASPECT_RATIO;
1927 imageView.SetProperty( Toolkit::ImageView::Property::IMAGE , imagePropertyMap );
1928 imageView.SetProperty( Actor::Property::ANCHOR_POINT, AnchorPoint::TOP_LEFT );
1929 imageView.SetProperty( Actor::Property::PARENT_ORIGIN, ParentOrigin::TOP_LEFT );
1930 imageView.SetProperty( Control::Property::PADDING, Extents( 15, 10, 5, 10 ) );
1931 Stage::GetCurrent().Add( imageView );
1933 application.SendNotification();
1934 application.Render();
1936 DALI_TEST_EQUALS( imageView.GetProperty<Extents>( Control::Property::PADDING ), Extents( 15, 10, 5, 10 ), TEST_LOCATION );
1938 // Check whether Image Visual transforms on ImageVieiw::OnRelayout()
1939 Toolkit::Internal::Control& controlImpl = Toolkit::Internal::GetImplementation( imageView );
1940 Toolkit::Visual::Base imageVisual = DevelControl::GetVisual( controlImpl, ImageView::Property::IMAGE );
1941 Property::Map resultMap;
1942 imageVisual.CreatePropertyMap( resultMap );
1944 Property::Value* transformValue = resultMap.Find( Visual::Property::TRANSFORM );
1945 DALI_TEST_CHECK( transformValue );
1946 Property::Map* retMap = transformValue->GetMap();
1947 DALI_TEST_CHECK( retMap );
1949 // Image Visual should be positioned depending on ImageView's padding
1950 DALI_TEST_EQUALS( retMap->Find( Visual::Transform::Property::OFFSET )->Get< Vector2 >(), Vector2( 15, 5 ), TEST_LOCATION );
1955 int UtcDaliImageViewPaddingProperty03(void)
1957 tet_infoline("Test Setting Image Padding then removing it.");
1959 ToolkitTestApplication application;
1961 ImageView imageView = ImageView::New();
1962 Property::Map imagePropertyMap;
1963 imagePropertyMap[ Toolkit::Visual::Property::TYPE ] = Toolkit::Visual::IMAGE;
1964 imagePropertyMap[ Toolkit::ImageVisual::Property::URL ] = TEST_RESOURCE_DIR "/Kid1.svg" ;
1965 imagePropertyMap[ ImageVisual::Property::DESIRED_WIDTH ] = 128;
1966 imagePropertyMap[ ImageVisual::Property::DESIRED_HEIGHT ] = 128;
1967 imagePropertyMap[ DevelVisual::Property::VISUAL_FITTING_MODE ] = Toolkit::DevelVisual::FIT_KEEP_ASPECT_RATIO;
1968 imageView.SetProperty( Toolkit::ImageView::Property::IMAGE , imagePropertyMap );
1969 imageView.SetProperty( Actor::Property::ANCHOR_POINT, AnchorPoint::TOP_LEFT );
1970 imageView.SetProperty( Actor::Property::PARENT_ORIGIN, ParentOrigin::TOP_LEFT );
1971 imageView.SetProperty( Control::Property::PADDING, Extents( 15, 10, 5, 10 ) );
1972 Stage::GetCurrent().Add( imageView );
1974 application.SendNotification();
1975 application.Render();
1977 DALI_TEST_EQUALS( imageView.GetProperty<Extents>( Control::Property::PADDING ), Extents( 15, 10, 5, 10 ), TEST_LOCATION );
1979 tet_infoline("Remove Padding and test Visual is position correctly");
1981 imageView.SetProperty( Control::Property::PADDING, Extents( 0, 0, 0, 0 ) );
1983 application.SendNotification();
1984 application.Render();
1986 // Check whether Image Visual transforms on ImageVieiw::OnRelayout()
1987 Toolkit::Internal::Control& controlImpl = Toolkit::Internal::GetImplementation( imageView );
1988 Toolkit::Visual::Base imageVisual = DevelControl::GetVisual( controlImpl, ImageView::Property::IMAGE );
1989 Property::Map resultMap;
1990 imageVisual.CreatePropertyMap( resultMap );
1992 Property::Value* transformValue = resultMap.Find( Visual::Property::TRANSFORM );
1993 DALI_TEST_CHECK( transformValue );
1994 Property::Map* retMap = transformValue->GetMap();
1995 DALI_TEST_CHECK( retMap );
1997 // Image Visual should be positioned depending on ImageView's padding
1998 DALI_TEST_EQUALS( retMap->Find( Visual::Transform::Property::OFFSET )->Get< Vector2 >(), Vector2( 0, 0 ), TEST_LOCATION );
2003 int UtcDaliImageViewPaddingProperty04(void)
2005 tet_infoline("Test Setting Image Padding then removing it. Visual Fitting Mode as Fill");
2007 ToolkitTestApplication application;
2009 ImageView imageView = ImageView::New();
2010 Property::Map imagePropertyMap;
2011 imagePropertyMap[ Toolkit::Visual::Property::TYPE ] = Toolkit::Visual::IMAGE;
2012 imagePropertyMap[ Toolkit::ImageVisual::Property::URL ] = TEST_RESOURCE_DIR "/Kid1.svg" ;
2013 imagePropertyMap[ ImageVisual::Property::DESIRED_WIDTH ] = 128;
2014 imagePropertyMap[ ImageVisual::Property::DESIRED_HEIGHT ] = 128;
2015 imagePropertyMap[ DevelVisual::Property::VISUAL_FITTING_MODE ] = Toolkit::DevelVisual::FILL;
2016 imageView.SetProperty( Toolkit::ImageView::Property::IMAGE , imagePropertyMap );
2017 imageView.SetProperty( Actor::Property::ANCHOR_POINT, AnchorPoint::TOP_LEFT );
2018 imageView.SetProperty( Actor::Property::PARENT_ORIGIN, ParentOrigin::TOP_LEFT );
2019 imageView.SetProperty( Control::Property::PADDING, Extents( 15, 10, 5, 10 ) );
2020 Stage::GetCurrent().Add( imageView );
2022 application.SendNotification();
2023 application.Render();
2025 DALI_TEST_EQUALS( imageView.GetProperty<Extents>( Control::Property::PADDING ), Extents( 15, 10, 5, 10 ), TEST_LOCATION );
2027 tet_infoline("Remove Padding and test Visual is position correctly");
2029 imageView.SetProperty( Control::Property::PADDING, Extents( 0, 0, 0, 0 ) );
2031 application.SendNotification();
2032 application.Render();
2034 // Check whether Image Visual transforms on ImageVieiw::OnRelayout()
2035 Toolkit::Internal::Control& controlImpl = Toolkit::Internal::GetImplementation( imageView );
2036 Toolkit::Visual::Base imageVisual = DevelControl::GetVisual( controlImpl, ImageView::Property::IMAGE );
2037 Property::Map resultMap;
2038 imageVisual.CreatePropertyMap( resultMap );
2040 Property::Value* transformValue = resultMap.Find( Visual::Property::TRANSFORM );
2041 DALI_TEST_CHECK( transformValue );
2042 Property::Map* retMap = transformValue->GetMap();
2043 DALI_TEST_CHECK( retMap );
2045 // Image Visual should be positioned depending on ImageView's padding
2046 DALI_TEST_EQUALS( retMap->Find( Visual::Transform::Property::OFFSET )->Get< Vector2 >(), Vector2( 0, 0 ), TEST_LOCATION );
2051 int UtcDaliImageViewTransformTest01(void)
2053 tet_infoline("Test Setting a offset transform on the ImageView");
2055 ToolkitTestApplication application;
2057 ImageView imageView = ImageView::New();
2058 Property::Map imagePropertyMap;
2059 imagePropertyMap.Add( Toolkit::Visual::Property::TYPE,Toolkit::Visual::IMAGE )
2060 .Add( Toolkit::ImageVisual::Property::URL,TEST_RESOURCE_DIR "/Kid1.svg" )
2061 .Add( ImageVisual::Property::DESIRED_WIDTH,120 )
2062 .Add( ImageVisual::Property::DESIRED_HEIGHT,120 )
2063 .Add( DevelVisual::Property::VISUAL_FITTING_MODE, Toolkit::DevelVisual::FILL )
2064 .Add( Visual::Property::TRANSFORM,
2065 Property::Map().Add( Toolkit::Visual::Transform::Property::OFFSET_POLICY,
2066 Vector2( Visual::Transform::Policy::ABSOLUTE, Visual::Transform::Policy::ABSOLUTE ) )
2067 .Add( Toolkit::Visual::Transform::Property::OFFSET, Vector2( 8, 8 ) ) );
2069 imageView.SetProperty( Toolkit::ImageView::Property::IMAGE , imagePropertyMap );
2070 imageView.SetProperty( Actor::Property::ANCHOR_POINT, AnchorPoint::TOP_LEFT );
2071 imageView.SetProperty( Actor::Property::PARENT_ORIGIN, ParentOrigin::TOP_LEFT );
2072 Stage::GetCurrent().Add( imageView );
2074 application.SendNotification();
2075 application.Render();
2077 // Check whether Image Visual transforms on ImageVieiw::OnRelayout()
2078 Toolkit::Internal::Control& controlImpl = Toolkit::Internal::GetImplementation( imageView );
2079 Toolkit::Visual::Base imageVisual = DevelControl::GetVisual( controlImpl, ImageView::Property::IMAGE );
2080 Property::Map resultMap;
2081 imageVisual.CreatePropertyMap( resultMap );
2083 Property::Value* transformValue = resultMap.Find( Visual::Property::TRANSFORM );
2084 DALI_TEST_CHECK( transformValue );
2085 Property::Map* retMap = transformValue->GetMap();
2086 DALI_TEST_CHECK( retMap );
2088 // Image Visual should be positioned depending on ImageView's padding
2089 DALI_TEST_EQUALS( retMap->Find( Visual::Transform::Property::OFFSET )->Get< Vector2 >(), Vector2( 8, 8 ), TEST_LOCATION );
2090 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 );
2095 int UtcDaliImageViewUsingAtlasAndGetNaturalSize(void)
2097 ToolkitTestApplication application;
2099 // Check ImageView with background and main image, to ensure both visuals are marked as loaded
2100 ImageView imageView = ImageView::New();
2101 Property::Map imageMap;
2102 imageMap[ Toolkit::Visual::Property::TYPE ] = Toolkit::Visual::IMAGE;
2103 imageMap[ Toolkit::ImageVisual::Property::URL ] = gImage_34_RGBA;
2104 imageMap[ Toolkit::ImageVisual::Property::ATLASING ] = true;
2105 imageView.SetProperty( Toolkit::ImageView::Property::IMAGE, imageMap );
2106 Stage::GetCurrent().Add( imageView );
2108 // Trigger a potential relayout
2109 application.SendNotification();
2110 application.Render();
2112 Vector3 naturalSize = imageView.GetNaturalSize();
2114 DALI_TEST_EQUALS( naturalSize.width, 34.0f, TEST_LOCATION );
2115 DALI_TEST_EQUALS( naturalSize.height, 34.0f, TEST_LOCATION );
2120 int UtcDaliImageViewFillMode(void)
2122 ToolkitTestApplication application;
2124 tet_infoline( "Create an ImageVisual without padding and set the fill-mode to fill" );
2126 ImageView imageView = ImageView::New();
2127 Property::Map imageMap;
2128 imageMap.Add( Toolkit::Visual::Property::TYPE, Toolkit::Visual::IMAGE );
2129 imageMap.Add( Toolkit::ImageVisual::Property::URL, gImage_600_RGB );
2130 imageMap.Add( DevelVisual::Property::VISUAL_FITTING_MODE, DevelVisual::FittingMode::FILL );
2132 imageView.SetProperty( Toolkit::ImageView::Property::IMAGE, imageMap );
2134 Stage::GetCurrent().Add( imageView );
2136 // Trigger a potential relayout
2137 application.SendNotification();
2138 application.Render();
2140 Toolkit::Visual::Base visual = DevelControl::GetVisual( Toolkit::Internal::GetImplementation( imageView ), Toolkit::ImageView::Property::IMAGE );
2141 Property::Map returnedMap;
2142 visual.CreatePropertyMap( returnedMap );
2144 Property::Value* value = returnedMap.Find( Toolkit::Visual::Property::TRANSFORM );
2145 DALI_TEST_CHECK( value );
2146 Property::Map* map = value->GetMap();
2147 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 );
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 UtcDaliImageViewFittingModeFitKeepAspectRatio(void)
2162 ToolkitTestApplication application;
2164 tet_infoline( "Create an ImageVisual using FitKeepAspectRatio ( image: [600,600], view: [600,700] )" );
2165 tet_infoline( " There should be need to change the transform, offset is adjusted to fit inside");
2167 ImageView imageView = ImageView::New();
2168 Property::Map imageMap;
2169 imageMap.Add( Toolkit::Visual::Property::TYPE, Toolkit::Visual::IMAGE );
2170 imageMap.Add( Toolkit::ImageVisual::Property::URL, gImage_600_RGB ); // 600x600 image
2171 imageMap.Add( DevelVisual::Property::VISUAL_FITTING_MODE , Toolkit::DevelVisual::FIT_KEEP_ASPECT_RATIO );
2173 imageView.SetProperty( Toolkit::ImageView::Property::IMAGE, imageMap );
2174 imageView.SetSize(600,700);
2176 Stage::GetCurrent().Add( imageView );
2178 // Trigger a potential relayout
2179 application.SendNotification();
2180 application.Render();
2182 Toolkit::Visual::Base visual = DevelControl::GetVisual( Toolkit::Internal::GetImplementation( imageView ), Toolkit::ImageView::Property::IMAGE );
2183 Property::Map returnedMap;
2184 visual.CreatePropertyMap( returnedMap );
2186 Property::Value* value = returnedMap.Find( Toolkit::Visual::Property::TRANSFORM );
2187 DALI_TEST_CHECK( value );
2188 Property::Map* map = value->GetMap();
2189 DALI_TEST_CHECK( map );
2192 value = map->Find( Toolkit::Visual::Transform::Property::SIZE );
2193 DALI_TEST_CHECK( value );
2194 DALI_TEST_EQUALS( value->Get< Vector2 >(), Vector2( 600, 600 ), TEST_LOCATION );
2196 value = map->Find( Toolkit::Visual::Transform::Property::SIZE_POLICY );
2197 DALI_TEST_CHECK( value );
2198 DALI_TEST_EQUALS( value->Get< Vector2 >(), Vector2( Toolkit::Visual::Transform::Policy::ABSOLUTE, Toolkit::Visual::Transform::Policy::ABSOLUTE ), TEST_LOCATION );
2200 value = map->Find( Toolkit::Visual::Transform::Property::OFFSET );
2201 DALI_TEST_CHECK( value );
2202 DALI_TEST_EQUALS( value->Get< Vector2 >(), Vector2( 0, 50 ), TEST_LOCATION );
2207 int UtcDaliImageViewFittingModesFill(void)
2209 ToolkitTestApplication application;
2211 tet_infoline( "Create an ImageVisual using Fill ( image: [600,600], view: [600,700] )" );
2212 tet_infoline( " There should be no need to change the transform, only size is changed to fit view");
2214 ImageView imageView = ImageView::New();
2215 Property::Map imageMap;
2216 imageMap.Add( Toolkit::Visual::Property::TYPE, Toolkit::Visual::IMAGE );
2217 imageMap.Add( Toolkit::ImageVisual::Property::URL, gImage_600_RGB ); // 600x600 image
2218 imageMap.Add( DevelVisual::Property::VISUAL_FITTING_MODE , Toolkit::DevelVisual::FILL );
2220 imageView.SetProperty( Toolkit::ImageView::Property::IMAGE, imageMap );
2221 imageView.SetSize(600,700);
2223 Stage::GetCurrent().Add( imageView );
2225 // Trigger a potential relayout
2226 application.SendNotification();
2227 application.Render();
2229 Toolkit::Visual::Base visual = DevelControl::GetVisual( Toolkit::Internal::GetImplementation( imageView ), Toolkit::ImageView::Property::IMAGE );
2230 Property::Map returnedMap;
2231 visual.CreatePropertyMap( returnedMap );
2233 Property::Value* value = returnedMap.Find( Toolkit::Visual::Property::TRANSFORM );
2234 DALI_TEST_CHECK( value );
2235 Property::Map* map = value->GetMap();
2236 DALI_TEST_CHECK( map );
2238 value = map->Find( Toolkit::Visual::Transform::Property::SIZE );
2239 DALI_TEST_CHECK( value );
2240 DALI_TEST_EQUALS( value->Get< Vector2 >(), Vector2::ONE, TEST_LOCATION ); // Change the internal size according to the image view size
2242 value = map->Find( Toolkit::Visual::Transform::Property::SIZE_POLICY );
2243 DALI_TEST_CHECK( value );
2244 DALI_TEST_CHECK( value->Get< int >() == Toolkit::Visual::Transform::Policy::RELATIVE );
2246 value = map->Find( Toolkit::Visual::Transform::Property::OFFSET );
2247 DALI_TEST_CHECK( value );
2248 DALI_TEST_EQUALS( value->Get< Vector2 >(), Vector2( 0, 0 ), TEST_LOCATION ); // OFFSET is zero
2253 int UtcDaliImageViewFittingModesOverfitKeepAspectRatio(void)
2255 ToolkitTestApplication application;
2257 tet_infoline( "Create an ImageVisual using OverFitKeepAspectRatio ( image: [600,600], view: [600,500] )" );
2258 tet_infoline( " offset or size is the same as view, but adjust internally using pixelArea ");
2260 ImageView imageView = ImageView::New();
2261 Property::Map imageMap;
2262 imageMap.Add( Toolkit::Visual::Property::TYPE, Toolkit::Visual::IMAGE );
2263 imageMap.Add( Toolkit::ImageVisual::Property::URL, gImage_600_RGB ); // 600x600 image
2264 imageMap.Add( DevelVisual::Property::VISUAL_FITTING_MODE , Toolkit::DevelVisual::OVER_FIT_KEEP_ASPECT_RATIO );
2266 imageView.SetProperty( Toolkit::ImageView::Property::IMAGE, imageMap );
2267 imageView.SetSize(600,500);
2269 Stage::GetCurrent().Add( imageView );
2271 // Trigger a potential relayout
2272 application.SendNotification();
2273 application.Render();
2275 Toolkit::Visual::Base visual = DevelControl::GetVisual( Toolkit::Internal::GetImplementation( imageView ), Toolkit::ImageView::Property::IMAGE );
2276 Property::Map returnedMap;
2277 visual.CreatePropertyMap( returnedMap );
2279 Property::Value* value = returnedMap.Find( Toolkit::Visual::Property::TRANSFORM );
2280 DALI_TEST_CHECK( value );
2281 Property::Map* map = value->GetMap();
2282 DALI_TEST_CHECK( map );
2285 value = map->Find( Toolkit::Visual::Transform::Property::SIZE );
2286 DALI_TEST_CHECK( value );
2287 DALI_TEST_EQUALS( value->Get< Vector2 >(), Vector2( 600, 500 ), TEST_LOCATION ); // Change the internal size according to the image view size
2289 value = map->Find( Toolkit::Visual::Transform::Property::SIZE_POLICY );
2290 DALI_TEST_CHECK( value );
2291 DALI_TEST_EQUALS( value->Get< Vector2 >(), Vector2( Toolkit::Visual::Transform::Policy::ABSOLUTE, Toolkit::Visual::Transform::Policy::ABSOLUTE ), TEST_LOCATION );
2293 value = map->Find( Toolkit::Visual::Transform::Property::OFFSET );
2294 DALI_TEST_CHECK( value );
2295 DALI_TEST_EQUALS( value->Get< Vector2 >(), Vector2( 0, 0 ), TEST_LOCATION ); // OFFSET is zero
2300 int UtcDaliImageViewFittingModesCenter01(void)
2302 ToolkitTestApplication application;
2304 tet_infoline( "Create an ImageVisual using Center ( image: [600,600], view: [700,700] )" );
2305 tet_infoline( " There should be need to change the transform, offset is adjusted to fit inside");
2307 ImageView imageView = ImageView::New();
2308 Property::Map imageMap;
2309 imageMap.Add( Toolkit::Visual::Property::TYPE, Toolkit::Visual::IMAGE );
2310 imageMap.Add( Toolkit::ImageVisual::Property::URL, gImage_600_RGB ); // 600x600 image
2311 imageMap.Add( DevelVisual::Property::VISUAL_FITTING_MODE, Toolkit::DevelVisual::CENTER);
2313 imageView.SetProperty( Toolkit::ImageView::Property::IMAGE, imageMap );
2314 imageView.SetSize(700,700);
2316 Stage::GetCurrent().Add( imageView );
2318 // Trigger a potential relayout
2319 application.SendNotification();
2320 application.Render();
2322 Toolkit::Visual::Base visual = DevelControl::GetVisual( Toolkit::Internal::GetImplementation( imageView ), Toolkit::ImageView::Property::IMAGE );
2323 Property::Map returnedMap;
2324 visual.CreatePropertyMap( returnedMap );
2326 Property::Value* value = returnedMap.Find( Toolkit::Visual::Property::TRANSFORM );
2327 DALI_TEST_CHECK( value );
2328 Property::Map* map = value->GetMap();
2329 DALI_TEST_CHECK( map );
2331 value = map->Find( Toolkit::Visual::Transform::Property::SIZE );
2332 DALI_TEST_CHECK( value );
2333 DALI_TEST_EQUALS( value->Get< Vector2 >(), Vector2( 600, 600 ), TEST_LOCATION ); // Change the internal size according to the image view size
2335 value = map->Find( Toolkit::Visual::Transform::Property::SIZE_POLICY );
2336 DALI_TEST_CHECK( value );
2337 DALI_TEST_EQUALS( value->Get< Vector2 >(), Vector2( Toolkit::Visual::Transform::Policy::ABSOLUTE, Toolkit::Visual::Transform::Policy::ABSOLUTE ), TEST_LOCATION );
2339 value = map->Find( Toolkit::Visual::Transform::Property::OFFSET );
2340 DALI_TEST_CHECK( value );
2341 DALI_TEST_EQUALS( value->Get< Vector2 >(), Vector2( 50, 50 ), TEST_LOCATION );
2346 int UtcDaliImageViewFittingModesCenter02(void)
2348 ToolkitTestApplication application;
2350 tet_infoline( "Create an ImageVisual using Center ( image: [600,600], view: [500,500] )" );
2351 tet_infoline( " There should be need to change the transform, offset is adjusted to fit inside");
2353 ImageView imageView = ImageView::New();
2354 Property::Map imageMap;
2355 imageMap.Add( Toolkit::Visual::Property::TYPE, Toolkit::Visual::IMAGE );
2356 imageMap.Add( Toolkit::ImageVisual::Property::URL, gImage_600_RGB ); // 600x600 image
2357 imageMap.Add( DevelVisual::Property::VISUAL_FITTING_MODE, Toolkit::DevelVisual::CENTER);
2359 imageView.SetProperty( Toolkit::ImageView::Property::IMAGE, imageMap );
2360 imageView.SetSize(700,700);
2362 Stage::GetCurrent().Add( imageView );
2364 // Trigger a potential relayout
2365 application.SendNotification();
2366 application.Render();
2368 Toolkit::Visual::Base visual = DevelControl::GetVisual( Toolkit::Internal::GetImplementation( imageView ), Toolkit::ImageView::Property::IMAGE );
2369 Property::Map returnedMap;
2370 visual.CreatePropertyMap( returnedMap );
2372 Property::Value* value = returnedMap.Find( Toolkit::Visual::Property::TRANSFORM );
2373 DALI_TEST_CHECK( value );
2374 Property::Map* map = value->GetMap();
2375 DALI_TEST_CHECK( map );
2377 value = map->Find( Toolkit::Visual::Transform::Property::SIZE );
2378 DALI_TEST_CHECK( value );
2379 DALI_TEST_EQUALS( value->Get< Vector2 >(), Vector2( 600, 600 ), TEST_LOCATION ); // Change the internal size according to the image view size
2381 value = map->Find( Toolkit::Visual::Transform::Property::SIZE_POLICY );
2382 DALI_TEST_CHECK( value );
2383 DALI_TEST_EQUALS( value->Get< Vector2 >(), Vector2( Toolkit::Visual::Transform::Policy::ABSOLUTE, Toolkit::Visual::Transform::Policy::ABSOLUTE ), TEST_LOCATION );
2385 value = map->Find( Toolkit::Visual::Transform::Property::OFFSET );
2386 DALI_TEST_CHECK( value );
2387 DALI_TEST_EQUALS( value->Get< Vector2 >(), Vector2( 50, 50 ), TEST_LOCATION );
2392 int UtcDaliImageViewFittingModesFitHeight01(void)
2394 ToolkitTestApplication application;
2396 tet_infoline( "Create an ImageVisual using FitHeight ( image: [600,600], view: [600,700] )" );
2398 ImageView imageView = ImageView::New();
2399 Property::Map imageMap;
2400 imageMap.Add( Toolkit::Visual::Property::TYPE, Toolkit::Visual::IMAGE );
2401 imageMap.Add( Toolkit::ImageVisual::Property::URL, gImage_600_RGB ); // 600x600 image
2402 imageMap.Add( DevelVisual::Property::VISUAL_FITTING_MODE, Toolkit::DevelVisual::FIT_HEIGHT);
2404 imageView.SetProperty( Toolkit::ImageView::Property::IMAGE, imageMap );
2405 imageView.SetSize(600,700);
2407 Stage::GetCurrent().Add( imageView );
2409 // Trigger a potential relayout
2410 application.SendNotification();
2411 application.Render();
2413 Toolkit::Visual::Base visual = DevelControl::GetVisual( Toolkit::Internal::GetImplementation( imageView ), Toolkit::ImageView::Property::IMAGE );
2414 Property::Map returnedMap;
2415 visual.CreatePropertyMap( returnedMap );
2417 Property::Value* value = returnedMap.Find( Toolkit::Visual::Property::TRANSFORM );
2418 DALI_TEST_CHECK( value );
2419 Property::Map* map = value->GetMap();
2420 DALI_TEST_CHECK( map );
2422 value = map->Find( Toolkit::Visual::Transform::Property::SIZE );
2423 DALI_TEST_CHECK( value );
2424 DALI_TEST_EQUALS( value->Get< Vector2 >(), Vector2( 600, 700 ), TEST_LOCATION ); // Change the internal size according to the image view size
2426 value = map->Find( Toolkit::Visual::Transform::Property::SIZE_POLICY );
2427 DALI_TEST_CHECK( value );
2428 DALI_TEST_EQUALS( value->Get< Vector2 >(), Vector2( Toolkit::Visual::Transform::Policy::ABSOLUTE, Toolkit::Visual::Transform::Policy::ABSOLUTE ), TEST_LOCATION );
2430 value = map->Find( Toolkit::Visual::Transform::Property::OFFSET );
2431 DALI_TEST_CHECK( value );
2432 DALI_TEST_EQUALS( value->Get< Vector2 >(), Vector2( 0, 0 ), TEST_LOCATION ); // OFFSET is zero
2437 int UtcDaliImageViewFittingModesFitHeight02(void)
2439 ToolkitTestApplication application;
2441 tet_infoline( "Create an ImageVisual using FitHeight ( image: [600,600], view: [700,600] )" );
2443 ImageView imageView = ImageView::New();
2444 Property::Map imageMap;
2445 imageMap.Add( Toolkit::Visual::Property::TYPE, Toolkit::Visual::IMAGE );
2446 imageMap.Add( Toolkit::ImageVisual::Property::URL, gImage_600_RGB ); // 249x169 image
2447 imageMap.Add( DevelVisual::Property::VISUAL_FITTING_MODE, Toolkit::DevelVisual::FIT_HEIGHT);
2449 imageView.SetProperty( Toolkit::ImageView::Property::IMAGE, imageMap );
2450 imageView.SetSize(700,600);
2452 Stage::GetCurrent().Add( imageView );
2454 // Trigger a potential relayout
2455 application.SendNotification();
2456 application.Render();
2458 Toolkit::Visual::Base visual = DevelControl::GetVisual( Toolkit::Internal::GetImplementation( imageView ), Toolkit::ImageView::Property::IMAGE );
2459 Property::Map returnedMap;
2460 visual.CreatePropertyMap( returnedMap );
2462 Property::Value* value = returnedMap.Find( Toolkit::Visual::Property::TRANSFORM );
2463 DALI_TEST_CHECK( value );
2464 Property::Map* map = value->GetMap();
2465 DALI_TEST_CHECK( map );
2467 value = map->Find( Toolkit::Visual::Transform::Property::SIZE );
2468 DALI_TEST_CHECK( value );
2469 DALI_TEST_EQUALS( value->Get< Vector2 >(), Vector2( 600, 600 ), TEST_LOCATION ); // Change the internal size according to the image view size
2471 value = map->Find( Toolkit::Visual::Transform::Property::SIZE_POLICY );
2472 DALI_TEST_CHECK( value );
2473 DALI_TEST_EQUALS( value->Get< Vector2 >(), Vector2( Toolkit::Visual::Transform::Policy::ABSOLUTE, Toolkit::Visual::Transform::Policy::ABSOLUTE ), TEST_LOCATION );
2475 value = map->Find( Toolkit::Visual::Transform::Property::OFFSET );
2476 DALI_TEST_CHECK( value );
2477 DALI_TEST_EQUALS( value->Get< Vector2 >(), Vector2( 50, 0 ), TEST_LOCATION );
2482 int UtcDaliImageViewFittingModesFitWidth01(void)
2484 ToolkitTestApplication application;
2486 tet_infoline( "Create an ImageVisual using FitWidth ( image: [600,600], view: [600,700] )" );
2488 ImageView imageView = ImageView::New();
2489 Property::Map imageMap;
2490 imageMap.Add( Toolkit::Visual::Property::TYPE, Toolkit::Visual::IMAGE );
2491 imageMap.Add( Toolkit::ImageVisual::Property::URL, gImage_600_RGB ); // 600x600 image
2492 imageMap.Add( DevelVisual::Property::VISUAL_FITTING_MODE, Toolkit::DevelVisual::FIT_WIDTH);
2494 imageView.SetProperty( Toolkit::ImageView::Property::IMAGE, imageMap );
2495 imageView.SetSize(600,700);
2497 Stage::GetCurrent().Add( imageView );
2499 // Trigger a potential relayout
2500 application.SendNotification();
2501 application.Render();
2503 Toolkit::Visual::Base visual = DevelControl::GetVisual( Toolkit::Internal::GetImplementation( imageView ), Toolkit::ImageView::Property::IMAGE );
2504 Property::Map returnedMap;
2505 visual.CreatePropertyMap( returnedMap );
2507 Property::Value* value = returnedMap.Find( Toolkit::Visual::Property::TRANSFORM );
2508 DALI_TEST_CHECK( value );
2509 Property::Map* map = value->GetMap();
2510 DALI_TEST_CHECK( map );
2512 value = map->Find( Toolkit::Visual::Transform::Property::SIZE );
2513 DALI_TEST_CHECK( value );
2514 DALI_TEST_EQUALS( value->Get< Vector2 >(), Vector2( 600, 600 ), TEST_LOCATION ); // Change the internal size according to the image view size
2516 value = map->Find( Toolkit::Visual::Transform::Property::SIZE_POLICY );
2517 DALI_TEST_CHECK( value );
2518 DALI_TEST_EQUALS( value->Get< Vector2 >(), Vector2( Toolkit::Visual::Transform::Policy::ABSOLUTE, Toolkit::Visual::Transform::Policy::ABSOLUTE ), TEST_LOCATION );
2520 value = map->Find( Toolkit::Visual::Transform::Property::OFFSET );
2521 DALI_TEST_CHECK( value );
2522 DALI_TEST_EQUALS( value->Get< Vector2 >(), Vector2( 0, 50 ), TEST_LOCATION );
2527 int UtcDaliImageViewFittingModesFitWidth02(void)
2529 ToolkitTestApplication application;
2531 tet_infoline( "Create an ImageVisual using FitWidth ( image: [600,600], view:[700,600] )" );
2533 ImageView imageView = ImageView::New();
2534 Property::Map imageMap;
2535 imageMap.Add( Toolkit::Visual::Property::TYPE, Toolkit::Visual::IMAGE );
2536 imageMap.Add( Toolkit::ImageVisual::Property::URL, gImage_600_RGB ); // 249x169 image
2537 imageMap.Add( DevelVisual::Property::VISUAL_FITTING_MODE, Toolkit::DevelVisual::FIT_WIDTH);
2539 imageView.SetProperty( Toolkit::ImageView::Property::IMAGE, imageMap );
2540 imageView.SetSize(700,600);
2542 Stage::GetCurrent().Add( imageView );
2544 // Trigger a potential relayout
2545 application.SendNotification();
2546 application.Render();
2548 Toolkit::Visual::Base visual = DevelControl::GetVisual( Toolkit::Internal::GetImplementation( imageView ), Toolkit::ImageView::Property::IMAGE );
2549 Property::Map returnedMap;
2550 visual.CreatePropertyMap( returnedMap );
2552 Property::Value* value = returnedMap.Find( Toolkit::Visual::Property::TRANSFORM );
2553 DALI_TEST_CHECK( value );
2554 Property::Map* map = value->GetMap();
2555 DALI_TEST_CHECK( map );
2557 value = map->Find( Toolkit::Visual::Transform::Property::SIZE );
2558 DALI_TEST_CHECK( value );
2559 DALI_TEST_EQUALS( value->Get< Vector2 >(), Vector2( 700, 600 ), TEST_LOCATION ); // Change the internal size according to the image view size
2561 value = map->Find( Toolkit::Visual::Transform::Property::SIZE_POLICY );
2562 DALI_TEST_CHECK( value );
2563 DALI_TEST_EQUALS( value->Get< Vector2 >(), Vector2( Toolkit::Visual::Transform::Policy::ABSOLUTE, Toolkit::Visual::Transform::Policy::ABSOLUTE ), TEST_LOCATION );
2565 value = map->Find( Toolkit::Visual::Transform::Property::OFFSET );
2566 DALI_TEST_CHECK( value );
2567 DALI_TEST_EQUALS( value->Get< Vector2 >(), Vector2( 0, 0 ), TEST_LOCATION ); // OFFSET is zero
2572 int UtcDaliImageViewFittingModesChangeFittingMode01(void)
2574 ToolkitTestApplication application;
2576 tet_infoline( "UtcDaliImageViewFittingModesChangeFittingMode, image: [600,600], view:[800,700]" );
2578 ImageView imageView = ImageView::New();
2580 // 1. Render using FittingMode::SHRINK_TO_FIT
2581 Property::Map imageMap;
2582 imageMap[ Toolkit::Visual::Property::TYPE ] = Toolkit::Visual::IMAGE;
2583 imageMap[ Toolkit::ImageVisual::Property::URL ] = gImage_600_RGB;
2584 imageMap[ DevelVisual::Property::VISUAL_FITTING_MODE ] = Toolkit::DevelVisual::FIT_KEEP_ASPECT_RATIO;
2586 imageView.SetProperty( Toolkit::ImageView::Property::IMAGE, imageMap );
2587 imageView.SetSize(800,700);
2589 Stage::GetCurrent().Add( imageView );
2591 // Trigger a potential relayout
2592 application.SendNotification();
2593 application.Render();
2595 Toolkit::Visual::Base visual = DevelControl::GetVisual( Toolkit::Internal::GetImplementation( imageView ), Toolkit::ImageView::Property::IMAGE );
2596 Property::Map returnedMap;
2597 visual.CreatePropertyMap( returnedMap );
2599 Property::Value* value = returnedMap.Find( Toolkit::Visual::Property::TRANSFORM );
2600 DALI_TEST_CHECK( value );
2601 Property::Map* map = value->GetMap();
2602 DALI_TEST_CHECK( map );
2604 value = map->Find( Toolkit::Visual::Transform::Property::SIZE );
2605 DALI_TEST_CHECK( value );
2606 DALI_TEST_EQUALS( value->Get< Vector2 >(), Vector2( 700, 700 ), TEST_LOCATION ); // Change the internal size according to the image view size
2608 value = map->Find( Toolkit::Visual::Transform::Property::SIZE_POLICY );
2609 DALI_TEST_CHECK( value );
2610 DALI_TEST_EQUALS( value->Get< Vector2 >(), Vector2( Toolkit::Visual::Transform::Policy::ABSOLUTE, Toolkit::Visual::Transform::Policy::ABSOLUTE ), TEST_LOCATION );
2612 value = map->Find( Toolkit::Visual::Transform::Property::OFFSET );
2613 DALI_TEST_CHECK( value );
2614 DALI_TEST_EQUALS( value->Get< Vector2 >(), Vector2( 50, 0 ), TEST_LOCATION );
2616 // 2. Render again using DevelVisaul::CENTER
2617 Property::Map imageMap2;
2618 imageMap2[ Toolkit::Visual::Property::TYPE ] = Toolkit::Visual::IMAGE;
2619 imageMap2[ Toolkit::ImageVisual::Property::URL ] = gImage_600_RGB;
2620 imageMap2[ DevelVisual::Property::VISUAL_FITTING_MODE ] = Toolkit::DevelVisual::CENTER;
2622 imageView.SetProperty( Toolkit::ImageView::Property::IMAGE, imageMap2 );
2623 imageView.SetSize(800,700);
2625 Stage::GetCurrent().Add( imageView );
2627 DALI_TEST_EQUALS( Test::WaitForEventThreadTrigger( 1 ), true, TEST_LOCATION );
2629 // Trigger a potential relayout
2630 application.SendNotification();
2631 application.Render();
2633 returnedMap.Clear();
2634 visual = DevelControl::GetVisual( Toolkit::Internal::GetImplementation( imageView ), Toolkit::ImageView::Property::IMAGE );
2636 visual.CreatePropertyMap( returnedMap );
2638 value = returnedMap.Find( Toolkit::Visual::Property::TRANSFORM );
2639 DALI_TEST_CHECK( value );
2640 map = value->GetMap();
2641 DALI_TEST_CHECK( map );
2643 value = map->Find( Toolkit::Visual::Transform::Property::SIZE );
2644 DALI_TEST_CHECK( value );
2645 DALI_TEST_EQUALS( value->Get< Vector2 >(), Vector2( 600, 600 ), TEST_LOCATION ); // Change the internal size according to the image view size
2647 value = map->Find( Toolkit::Visual::Transform::Property::SIZE_POLICY );
2648 DALI_TEST_CHECK( value );
2649 DALI_TEST_EQUALS( value->Get< Vector2 >(), Vector2( Toolkit::Visual::Transform::Policy::ABSOLUTE, Toolkit::Visual::Transform::Policy::ABSOLUTE ), TEST_LOCATION );
2651 value = map->Find( Toolkit::Visual::Transform::Property::OFFSET );
2652 DALI_TEST_CHECK( value );
2653 DALI_TEST_EQUALS( value->Get< Vector2 >(), Vector2( 100, 50 ), TEST_LOCATION );
2655 // 3. Render again using before fittingMode
2656 Property::Map imageMap3;
2657 imageMap3[ Toolkit::Visual::Property::TYPE ] = Toolkit::Visual::IMAGE;
2658 imageMap3[ Toolkit::ImageVisual::Property::URL ] = gImage_600_RGB;
2659 imageMap3[ DevelVisual::Property::VISUAL_FITTING_MODE ] = Toolkit::DevelVisual::FIT_KEEP_ASPECT_RATIO;
2661 imageView.SetProperty( Toolkit::ImageView::Property::IMAGE, imageMap3 );
2662 imageView.SetSize(800,700);
2664 Stage::GetCurrent().Add( imageView );
2666 // Trigger a potential relayout
2667 application.SendNotification();
2668 application.Render();
2670 returnedMap.Clear();
2671 visual = DevelControl::GetVisual( Toolkit::Internal::GetImplementation( imageView ), Toolkit::ImageView::Property::IMAGE );
2672 visual.CreatePropertyMap( returnedMap );
2674 value = returnedMap.Find( Toolkit::Visual::Property::TRANSFORM );
2675 DALI_TEST_CHECK( value );
2676 map = value->GetMap();
2677 DALI_TEST_CHECK( map );
2679 value = map->Find( Toolkit::Visual::Transform::Property::SIZE );
2680 DALI_TEST_CHECK( value );
2681 DALI_TEST_EQUALS( value->Get< Vector2 >(), Vector2( 700, 700 ), TEST_LOCATION ); // Change the internal size according to the image view size
2683 value = map->Find( Toolkit::Visual::Transform::Property::SIZE_POLICY );
2684 DALI_TEST_CHECK( value );
2685 DALI_TEST_EQUALS( value->Get< Vector2 >(), Vector2( Toolkit::Visual::Transform::Policy::ABSOLUTE, Toolkit::Visual::Transform::Policy::ABSOLUTE ), TEST_LOCATION );
2687 value = map->Find( Toolkit::Visual::Transform::Property::OFFSET );
2688 DALI_TEST_CHECK( value );
2689 DALI_TEST_EQUALS( value->Get< Vector2 >(), Vector2( 50, 0 ), TEST_LOCATION );
2694 int UtcDaliImageViewFittingModesChangeFittingMode02(void)
2696 ToolkitTestApplication application;
2698 tet_infoline( "UtcDaliImageViewFittingModesChangeFittingMode, image: [600,600], view:[800,700]" );
2700 ImageView imageView = ImageView::New();
2702 // 1. Render using FittingMode::OVER_FIT_KEEP_ASPECT_RATIO
2703 Property::Map imageMap;
2704 imageMap[ Toolkit::Visual::Property::TYPE ] = Toolkit::Visual::IMAGE;
2705 imageMap[ Toolkit::ImageVisual::Property::URL ] = gImage_600_RGB;
2706 imageMap[ DevelVisual::Property::VISUAL_FITTING_MODE ] = Toolkit::DevelVisual::OVER_FIT_KEEP_ASPECT_RATIO;
2708 imageView.SetProperty( Toolkit::ImageView::Property::IMAGE, imageMap );
2709 imageView.SetSize(800,700);
2711 Stage::GetCurrent().Add( imageView );
2713 // Trigger a potential relayout
2714 application.SendNotification();
2715 application.Render();
2717 Toolkit::Visual::Base visual = DevelControl::GetVisual( Toolkit::Internal::GetImplementation( imageView ), Toolkit::ImageView::Property::IMAGE );
2718 Property::Map returnedMap;
2719 visual.CreatePropertyMap( returnedMap );
2721 Property::Value* value = returnedMap.Find( Toolkit::Visual::Property::TRANSFORM );
2722 DALI_TEST_CHECK( value );
2723 Property::Map* map = value->GetMap();
2724 DALI_TEST_CHECK( map );
2726 value = map->Find( Toolkit::Visual::Transform::Property::SIZE );
2727 DALI_TEST_CHECK( value );
2728 DALI_TEST_EQUALS( value->Get< Vector2 >(), Vector2( 800, 700 ), TEST_LOCATION ); // Change the internal size according to the image view size
2730 value = map->Find( Toolkit::Visual::Transform::Property::SIZE_POLICY );
2731 DALI_TEST_CHECK( value );
2732 DALI_TEST_EQUALS( value->Get< Vector2 >(), Vector2( Toolkit::Visual::Transform::Policy::ABSOLUTE, Toolkit::Visual::Transform::Policy::ABSOLUTE ), TEST_LOCATION );
2734 value = map->Find( Toolkit::Visual::Transform::Property::OFFSET );
2735 DALI_TEST_CHECK( value );
2736 DALI_TEST_EQUALS( value->Get< Vector2 >(), Vector2( 0, 0 ), TEST_LOCATION );
2738 // 2. Render again using DevelVisaul::CENTER
2739 Property::Map imageMap2;
2740 imageMap2[ Toolkit::Visual::Property::TYPE ] = Toolkit::Visual::IMAGE;
2741 imageMap2[ Toolkit::ImageVisual::Property::URL ] = gImage_600_RGB;
2742 imageMap2[ DevelVisual::Property::VISUAL_FITTING_MODE ] = Toolkit::DevelVisual::CENTER;
2744 imageView.SetProperty( Toolkit::ImageView::Property::IMAGE, imageMap2 );
2745 imageView.SetSize(800,700);
2747 Stage::GetCurrent().Add( imageView );
2749 DALI_TEST_EQUALS( Test::WaitForEventThreadTrigger( 1 ), true, TEST_LOCATION );
2751 // Trigger a potential relayout
2752 application.SendNotification();
2753 application.Render();
2755 returnedMap.Clear();
2756 visual = DevelControl::GetVisual( Toolkit::Internal::GetImplementation( imageView ), Toolkit::ImageView::Property::IMAGE );
2758 visual.CreatePropertyMap( returnedMap );
2760 value = returnedMap.Find( Toolkit::Visual::Property::TRANSFORM );
2761 DALI_TEST_CHECK( value );
2762 map = value->GetMap();
2763 DALI_TEST_CHECK( map );
2765 value = map->Find( Toolkit::Visual::Transform::Property::SIZE );
2766 DALI_TEST_CHECK( value );
2767 DALI_TEST_EQUALS( value->Get< Vector2 >(), Vector2( 600, 600 ), TEST_LOCATION ); // Change the internal size according to the image view size
2769 value = map->Find( Toolkit::Visual::Transform::Property::SIZE_POLICY );
2770 DALI_TEST_CHECK( value );
2771 DALI_TEST_EQUALS( value->Get< Vector2 >(), Vector2( Toolkit::Visual::Transform::Policy::ABSOLUTE, Toolkit::Visual::Transform::Policy::ABSOLUTE ), TEST_LOCATION );
2773 value = map->Find( Toolkit::Visual::Transform::Property::OFFSET );
2774 DALI_TEST_CHECK( value );
2775 DALI_TEST_EQUALS( value->Get< Vector2 >(), Vector2( 100, 50 ), TEST_LOCATION );
2777 // 3. Render again using before fittingMode
2778 Property::Map imageMap3;
2779 imageMap3[ Toolkit::Visual::Property::TYPE ] = Toolkit::Visual::IMAGE;
2780 imageMap3[ Toolkit::ImageVisual::Property::URL ] = gImage_600_RGB;
2781 imageMap3[ DevelVisual::Property::VISUAL_FITTING_MODE ] = Toolkit::DevelVisual::OVER_FIT_KEEP_ASPECT_RATIO;
2783 imageView.SetProperty( Toolkit::ImageView::Property::IMAGE, imageMap3 );
2784 imageView.SetSize(800,700);
2786 Stage::GetCurrent().Add( imageView );
2788 // Trigger a potential relayout
2789 application.SendNotification();
2790 application.Render();
2792 returnedMap.Clear();
2793 visual = DevelControl::GetVisual( Toolkit::Internal::GetImplementation( imageView ), Toolkit::ImageView::Property::IMAGE );
2794 visual.CreatePropertyMap( returnedMap );
2796 value = returnedMap.Find( Toolkit::Visual::Property::TRANSFORM );
2797 DALI_TEST_CHECK( value );
2798 map = value->GetMap();
2799 DALI_TEST_CHECK( map );
2801 value = map->Find( Toolkit::Visual::Transform::Property::SIZE );
2802 DALI_TEST_CHECK( value );
2803 DALI_TEST_EQUALS( value->Get< Vector2 >(), Vector2( 800, 700 ), TEST_LOCATION ); // Change the internal size according to the image view size
2805 value = map->Find( Toolkit::Visual::Transform::Property::SIZE_POLICY );
2806 DALI_TEST_CHECK( value );
2807 DALI_TEST_EQUALS( value->Get< Vector2 >(), Vector2( Toolkit::Visual::Transform::Policy::ABSOLUTE, Toolkit::Visual::Transform::Policy::ABSOLUTE ), TEST_LOCATION );
2809 value = map->Find( Toolkit::Visual::Transform::Property::OFFSET );
2810 DALI_TEST_CHECK( value );
2811 DALI_TEST_EQUALS( value->Get< Vector2 >(), Vector2( 0, 0 ), TEST_LOCATION );
2816 int UtcDaliImageViewFittingModesWithAnimatedVectorImageVisual(void)
2818 ToolkitTestApplication application;
2820 tet_infoline( "Create an ImageVisual using ScaleToFill and animated vector image ( image: [600,600], view:[600,600] )" );
2822 ImageView imageView = ImageView::New();
2823 Property::Map imageMap;
2824 imageMap.Add( Toolkit::Visual::Property::TYPE, DevelVisual::ANIMATED_VECTOR_IMAGE );
2825 imageMap.Add( Toolkit::ImageVisual::Property::URL, TEST_VECTOR_IMAGE_FILE_NAME ); // 249x169 image
2827 imageView.SetProperty( Toolkit::ImageView::Property::IMAGE, imageMap );
2828 imageView.SetSize(600,600);
2830 Stage::GetCurrent().Add( imageView );
2832 // Trigger a potential relayout
2833 application.SendNotification();
2834 application.Render();
2836 Toolkit::Visual::Base visual = DevelControl::GetVisual( Toolkit::Internal::GetImplementation( imageView ), Toolkit::ImageView::Property::IMAGE );
2837 Property::Map returnedMap;
2838 visual.CreatePropertyMap( returnedMap );
2840 Property::Value* value = returnedMap.Find( Toolkit::Visual::Property::TRANSFORM );
2841 DALI_TEST_CHECK( value );
2842 Property::Map* map = value->GetMap();
2843 DALI_TEST_CHECK( map );
2845 value = map->Find( Toolkit::Visual::Transform::Property::SIZE );
2846 DALI_TEST_CHECK( value );
2847 DALI_TEST_EQUALS( value->Get< Vector2 >(), Vector2::ONE, TEST_LOCATION ); // Relative size so will take up 100%
2849 value = map->Find( Toolkit::Visual::Transform::Property::SIZE_POLICY );
2850 DALI_TEST_CHECK( value );
2851 DALI_TEST_CHECK( value->Get< int >() == Toolkit::Visual::Transform::Policy::RELATIVE );
2853 value = map->Find( Toolkit::Visual::Transform::Property::OFFSET );
2854 DALI_TEST_CHECK( value );
2855 DALI_TEST_EQUALS( value->Get< Vector2 >(), Vector2( 0, 0 ), TEST_LOCATION ); // OFFSET is zero
2861 int UtcDaliImageViewCustomShader(void)
2863 ToolkitTestApplication application;
2865 // Set a custom shader with an image url
2867 Property::Map properties;
2868 Property::Map shader;
2869 const std::string vertexShader = "Foobar";
2870 const std::string fragmentShader = "Foobar";
2871 shader[Visual::Shader::Property::FRAGMENT_SHADER] = fragmentShader;
2872 shader[Visual::Shader::Property::VERTEX_SHADER] = vertexShader;
2874 properties[Visual::Property::TYPE] = Visual::IMAGE;
2875 properties[Visual::Property::SHADER] = shader;
2876 properties[ImageVisual::Property::URL] = TEST_IMAGE_FILE_NAME;
2878 ImageView imageView = ImageView::New();
2879 imageView.SetProperty( ImageView::Property::IMAGE, properties );
2881 Stage::GetCurrent().Add( imageView );
2883 application.SendNotification();
2884 application.Render();
2886 DALI_TEST_EQUALS( Test::WaitForEventThreadTrigger( 1 ), true, TEST_LOCATION );
2888 Renderer renderer = imageView.GetRendererAt( 0 );
2889 Shader shader2 = renderer.GetShader();
2890 Property::Value value = shader2.GetProperty( Shader::Property::PROGRAM );
2891 Property::Map* map = value.GetMap();
2892 DALI_TEST_CHECK( map );
2894 Property::Value* fragment = map->Find( "fragment" ); // fragment key name from shader-impl.cpp
2895 DALI_TEST_EQUALS( fragmentShader, fragment->Get< std::string >(), TEST_LOCATION );
2897 Property::Value* vertex = map->Find( "vertex" ); // vertex key name from shader-impl.cpp
2898 DALI_TEST_EQUALS( vertexShader, vertex->Get< std::string >(), TEST_LOCATION );
2901 // Set a custom shader after setting an image url
2903 Property::Map properties;
2904 Property::Map shader;
2905 const std::string vertexShader = "Foobar";
2906 const std::string fragmentShader = "Foobar";
2907 shader[Visual::Shader::Property::FRAGMENT_SHADER] = fragmentShader;
2908 shader[Visual::Shader::Property::VERTEX_SHADER] = vertexShader;
2910 properties[Visual::Property::SHADER] = shader;
2912 ImageView imageView = ImageView::New( TEST_IMAGE_FILE_NAME );
2913 imageView.SetProperty( ImageView::Property::IMAGE, properties );
2915 Stage::GetCurrent().Add( imageView );
2917 application.SendNotification();
2918 application.Render();
2920 DALI_TEST_EQUALS( Test::WaitForEventThreadTrigger( 1 ), true, TEST_LOCATION );
2922 Renderer renderer = imageView.GetRendererAt( 0 );
2923 Shader shader2 = renderer.GetShader();
2924 Property::Value value = shader2.GetProperty( Shader::Property::PROGRAM );
2925 Property::Map* map = value.GetMap();
2926 DALI_TEST_CHECK( map );
2928 Property::Value* fragment = map->Find( "fragment" ); // fragment key name from shader-impl.cpp
2929 DALI_TEST_EQUALS( fragmentShader, fragment->Get< std::string >(), TEST_LOCATION );
2931 Property::Value* vertex = map->Find( "vertex" ); // vertex key name from shader-impl.cpp
2932 DALI_TEST_EQUALS( vertexShader, vertex->Get< std::string >(), TEST_LOCATION );
2935 // Set a custom shader before setting an image url
2937 Property::Map properties;
2938 Property::Map shader;
2939 const std::string vertexShader = "Foobar";
2940 const std::string fragmentShader = "Foobar";
2941 shader[Visual::Shader::Property::FRAGMENT_SHADER] = fragmentShader;
2942 shader[Visual::Shader::Property::VERTEX_SHADER] = vertexShader;
2944 properties[Visual::Property::SHADER] = shader;
2946 ImageView imageView = ImageView::New();
2947 imageView.SetProperty( ImageView::Property::IMAGE, properties );
2948 imageView.SetProperty( ImageView::Property::IMAGE, TEST_IMAGE_FILE_NAME );
2950 Stage::GetCurrent().Add( imageView );
2952 application.SendNotification();
2953 application.Render();
2954 DALI_TEST_EQUALS( Test::WaitForEventThreadTrigger( 1 ), true, TEST_LOCATION );
2956 Renderer renderer = imageView.GetRendererAt( 0 );
2957 Shader shader2 = renderer.GetShader();
2958 Property::Value value = shader2.GetProperty( Shader::Property::PROGRAM );
2959 Property::Map* map = value.GetMap();
2960 DALI_TEST_CHECK( map );
2962 Property::Value* fragment = map->Find( "fragment" ); // fragment key name from shader-impl.cpp
2963 DALI_TEST_EQUALS( fragmentShader, fragment->Get< std::string >(), TEST_LOCATION );
2965 Property::Value* vertex = map->Find( "vertex" ); // vertex key name from shader-impl.cpp
2966 DALI_TEST_EQUALS( vertexShader, vertex->Get< std::string >(), TEST_LOCATION );
2969 // Set a custom shader after setting a property map
2971 Property::Map properties;
2972 Property::Map shader;
2973 const std::string vertexShader = "Foobar";
2974 const std::string fragmentShader = "Foobar";
2975 shader[Visual::Shader::Property::FRAGMENT_SHADER] = fragmentShader;
2976 shader[Visual::Shader::Property::VERTEX_SHADER] = vertexShader;
2978 properties[Visual::Property::SHADER] = shader;
2980 Property::Map properties1;
2981 properties1[Visual::Property::TYPE] = Visual::IMAGE;
2982 properties1[ImageVisual::Property::URL] = TEST_IMAGE_FILE_NAME;
2984 ImageView imageView = ImageView::New();
2985 imageView.SetProperty( ImageView::Property::IMAGE, properties1 );
2986 imageView.SetProperty( ImageView::Property::IMAGE, properties );
2988 Stage::GetCurrent().Add( imageView );
2990 application.SendNotification();
2991 application.Render();
2992 DALI_TEST_EQUALS( Test::WaitForEventThreadTrigger( 1 ), true, TEST_LOCATION );
2994 Renderer renderer = imageView.GetRendererAt( 0 );
2995 Shader shader2 = renderer.GetShader();
2996 Property::Value value = shader2.GetProperty( Shader::Property::PROGRAM );
2997 Property::Map* map = value.GetMap();
2998 DALI_TEST_CHECK( map );
3000 Property::Value* fragment = map->Find( "fragment" ); // fragment key name from shader-impl.cpp
3001 DALI_TEST_EQUALS( fragmentShader, fragment->Get< std::string >(), TEST_LOCATION );
3003 Property::Value* vertex = map->Find( "vertex" ); // vertex key name from shader-impl.cpp
3004 DALI_TEST_EQUALS( vertexShader, vertex->Get< std::string >(), TEST_LOCATION );
3007 // Set a custom shader before setting a property map
3009 Property::Map properties;
3010 Property::Map shader;
3011 const std::string vertexShader = "Foobar";
3012 const std::string fragmentShader = "Foobar";
3013 shader[Visual::Shader::Property::FRAGMENT_SHADER] = fragmentShader;
3014 shader[Visual::Shader::Property::VERTEX_SHADER] = vertexShader;
3016 properties[Visual::Property::SHADER] = shader;
3018 Property::Map properties1;
3019 properties1[Visual::Property::TYPE] = Visual::IMAGE;
3020 properties1[ImageVisual::Property::URL] = TEST_IMAGE_FILE_NAME;
3022 ImageView imageView = ImageView::New();
3023 imageView.SetProperty( ImageView::Property::IMAGE, properties );
3024 imageView.SetProperty( ImageView::Property::IMAGE, properties1 );
3026 Stage::GetCurrent().Add( imageView );
3028 application.SendNotification();
3029 application.Render();
3030 DALI_TEST_EQUALS( Test::WaitForEventThreadTrigger( 1 ), true, TEST_LOCATION );
3032 Renderer renderer = imageView.GetRendererAt( 0 );
3033 Shader shader2 = renderer.GetShader();
3034 Property::Value value = shader2.GetProperty( Shader::Property::PROGRAM );
3035 Property::Map* map = value.GetMap();
3036 DALI_TEST_CHECK( map );
3038 Property::Value* fragment = map->Find( "fragment" ); // fragment key name from shader-impl.cpp
3039 DALI_TEST_EQUALS( fragmentShader, fragment->Get< std::string >(), TEST_LOCATION );
3041 Property::Value* vertex = map->Find( "vertex" ); // vertex key name from shader-impl.cpp
3042 DALI_TEST_EQUALS( vertexShader, vertex->Get< std::string >(), TEST_LOCATION );
3051 static int gFailCounter = 0;
3052 const int MAX_RETRIES(3);
3054 void ReloadImage(ImageView imageView)
3056 Property::Map imageImmediateLoadingMap;
3057 imageImmediateLoadingMap[ ImageVisual::Property::URL ] = "Non-existant-image.jpg";
3058 imageImmediateLoadingMap[ ImageVisual::Property::LOAD_POLICY ] = ImageVisual::LoadPolicy::IMMEDIATE;
3060 tet_infoline("Immediate load an image");
3061 imageView.SetProperty( ImageView::Property::IMAGE, imageImmediateLoadingMap );
3064 void ResourceFailedReload( Control control )
3067 if( gFailCounter < MAX_RETRIES )
3069 ReloadImage(ImageView::DownCast(control));
3074 int UtcDaliImageViewReloadFailedOnResourceReadySignal(void)
3076 tet_infoline("Test reloading failed image from within signal handler.");
3078 ToolkitTestApplication application;
3082 ImageView imageView = ImageView::New();
3083 imageView.ResourceReadySignal().Connect( &ResourceFailedReload );
3084 DALI_TEST_EQUALS( gFailCounter, 0, TEST_LOCATION );
3085 ReloadImage(imageView);
3087 // loading started, this waits for the loader thread to complete
3088 DALI_TEST_EQUALS( Test::WaitForEventThreadTrigger( 1 ), true, TEST_LOCATION );
3089 application.SendNotification();
3091 DALI_TEST_EQUALS( gFailCounter, 1, TEST_LOCATION );
3093 DALI_TEST_EQUALS( Test::WaitForEventThreadTrigger( 1 ), true, TEST_LOCATION );
3094 application.SendNotification();
3096 DALI_TEST_EQUALS( gFailCounter, 2, TEST_LOCATION );
3098 DALI_TEST_EQUALS( Test::WaitForEventThreadTrigger( 1 ), true, TEST_LOCATION );
3099 application.SendNotification();
3100 DALI_TEST_EQUALS( gFailCounter, 3, TEST_LOCATION );
3105 int UtcDaliImageViewLoadRemoteSVG(void)
3107 tet_infoline("Test load from a remote server.");
3109 ToolkitTestApplication application;
3110 Toolkit::ImageView imageView;
3111 imageView = Toolkit::ImageView::New( );
3112 imageView.SetImage("https://dev.w3.org/SVG/tools/svgweb/samples/svg-files/check.svg");
3113 // Victor. Temporary (or permanent?) update as the url above seems not to work from time to time ...
3114 imageView.SetImage("https://upload.wikimedia.org/wikipedia/commons/thumb/0/02/SVG_logo.svg/64px-SVG_logo.svg.png");
3115 imageView.SetProperty( Actor::Property::PARENT_ORIGIN, ParentOrigin::TOP_LEFT );
3116 imageView.SetProperty( Actor::Property::ANCHOR_POINT, AnchorPoint::TOP_LEFT );
3117 imageView.SetSize(300, 300);
3118 imageView.SetPosition( Vector3( 150.0f , 150.0f , 0.0f ) );
3120 Stage::GetCurrent().Add( imageView );
3122 DALI_TEST_CHECK( imageView );
3124 DALI_TEST_EQUALS( imageView.GetRendererCount(), 0u, TEST_LOCATION );
3126 application.SendNotification();
3128 DALI_TEST_EQUALS( Test::WaitForEventThreadTrigger( 1 ), true, TEST_LOCATION );
3130 application.SendNotification();
3131 application.Render();
3133 DALI_TEST_EQUALS( imageView.GetRendererCount(), 1u, TEST_LOCATION );
3138 int UtcDaliImageViewSyncSVGLoading(void)
3140 ToolkitTestApplication application;
3142 tet_infoline("ImageView Testing SVG image sync loading");
3144 // Sync loading, automatic atlasing for small size image
3146 TraceCallStack& callStack = application.GetGlAbstraction().GetTextureTrace();
3148 callStack.Enable(true);
3150 ImageView imageView = ImageView::New( );
3152 // Sync loading is used
3153 Property::Map syncLoadingMap;
3154 syncLoadingMap.Insert( Toolkit::Visual::Property::TYPE, Toolkit::Visual::IMAGE );
3155 syncLoadingMap.Insert( Toolkit::ImageVisual::Property::URL, TEST_RESOURCE_DIR "/svg1.svg" );
3156 syncLoadingMap.Insert( Toolkit::ImageVisual::Property::SYNCHRONOUS_LOADING, true);
3157 imageView.SetProperty( ImageView::Property::IMAGE, syncLoadingMap );
3159 Stage::GetCurrent().Add( imageView );
3160 DALI_TEST_CHECK( imageView );
3162 application.SendNotification();
3163 application.Render(16);
3164 Vector3 naturalSize = imageView.GetNaturalSize();
3166 DALI_TEST_EQUALS( naturalSize.width, 100.0f, TEST_LOCATION );
3167 DALI_TEST_EQUALS( naturalSize.height, 100.0f, TEST_LOCATION );
3173 int UtcDaliImageViewAsyncSVGLoading(void)
3175 ToolkitTestApplication application;
3177 tet_infoline("ImageView Testing SVG image async loading");
3179 // Sync loading, automatic atlasing for small size image
3181 TraceCallStack& callStack = application.GetGlAbstraction().GetTextureTrace();
3183 callStack.Enable(true);
3185 ImageView imageView = ImageView::New( );
3187 // Sync loading is used
3188 Property::Map syncLoadingMap;
3189 syncLoadingMap.Insert( Toolkit::Visual::Property::TYPE, Toolkit::Visual::IMAGE );
3190 syncLoadingMap.Insert( Toolkit::ImageVisual::Property::URL, TEST_RESOURCE_DIR "/svg1.svg" );
3191 syncLoadingMap.Insert( Toolkit::ImageVisual::Property::SYNCHRONOUS_LOADING, false);
3192 imageView.SetProperty( ImageView::Property::IMAGE, syncLoadingMap );
3194 Stage::GetCurrent().Add( imageView );
3195 DALI_TEST_CHECK( imageView );
3197 application.SendNotification();
3198 application.Render(16);
3199 Vector3 naturalSize = imageView.GetNaturalSize();
3201 DALI_TEST_EQUALS( naturalSize.width, 100.0f, TEST_LOCATION );
3202 DALI_TEST_EQUALS( naturalSize.height, 100.0f, TEST_LOCATION );
3207 int UtcDaliImageViewSVGLoadingSyncSetInvalidValue(void)
3209 ToolkitTestApplication application;
3211 tet_infoline("ImageView Testing SVG image async loading");
3213 // Sync loading, automatic atlasing for small size image
3215 TraceCallStack& callStack = application.GetGlAbstraction().GetTextureTrace();
3217 callStack.Enable(true);
3219 ImageView imageView = ImageView::New( );
3221 // Sync loading is used
3222 Property::Map syncLoadingMap;
3223 syncLoadingMap.Insert( Toolkit::Visual::Property::TYPE, Toolkit::Visual::IMAGE );
3224 syncLoadingMap.Insert( Toolkit::ImageVisual::Property::URL, TEST_RESOURCE_DIR "/svg1.svg" );
3226 // Check to set invalid value
3227 // The SYNCHRONOUS_LOADING property must be set to the bool value.
3228 // Check if error log is outputted when setting other value like string.
3229 // Even if the wrong value is set, the image will be shown normally, and the synchronous value should be the default value(false).
3230 syncLoadingMap.Insert( Toolkit::ImageVisual::Property::SYNCHRONOUS_LOADING, std::to_string(5) );
3231 imageView.SetProperty( ImageView::Property::IMAGE, syncLoadingMap );
3233 Stage::GetCurrent().Add( imageView );
3234 DALI_TEST_CHECK( imageView );
3236 application.SendNotification();
3237 application.Render(16);
3238 Vector3 naturalSize = imageView.GetNaturalSize();
3239 DALI_TEST_EQUALS( naturalSize.width, 100.0f, TEST_LOCATION );
3240 DALI_TEST_EQUALS( naturalSize.height, 100.0f, TEST_LOCATION );
3242 Property::Value value = imageView.GetProperty( ImageView::Property::IMAGE );
3243 Property::Map* map = value.GetMap();
3244 DALI_TEST_CHECK( map );
3246 Property::Value* sync = map->Find( Toolkit::ImageVisual::Property::SYNCHRONOUS_LOADING );
3247 DALI_TEST_CHECK( sync );
3248 DALI_TEST_EQUALS( false, sync->Get< bool >(), TEST_LOCATION );
3254 int UtcDaliImageViewSvgLoadingFailure(void)
3256 ToolkitTestApplication application;
3260 gResourceReadySignalFired = false;
3262 ImageView imageView = ImageView::New( TEST_RESOURCE_DIR "/Kid1.svg" );
3263 imageView.SetSize( 200.f, 200.f );
3264 imageView.ResourceReadySignal().Connect( &ResourceReadySignal);
3266 DALI_TEST_EQUALS( imageView.IsResourceReady(), false, TEST_LOCATION );
3268 Stage::GetCurrent().Add( imageView );
3270 application.SendNotification();
3272 // loading started, this waits for the loader thread
3273 DALI_TEST_EQUALS( Test::WaitForEventThreadTrigger( 1 ), true, TEST_LOCATION );
3275 application.SendNotification();
3276 application.Render(16);
3278 DALI_TEST_EQUALS( gResourceReadySignalFired, true, TEST_LOCATION );
3279 DALI_TEST_EQUALS( imageView.IsResourceReady(), true, TEST_LOCATION );
3280 DALI_TEST_EQUALS( imageView.GetVisualResourceStatus( ImageView::Property::IMAGE ), Visual::ResourceStatus::FAILED, TEST_LOCATION );
3285 gResourceReadySignalFired = false;
3287 ImageView imageView = ImageView::New( "https://bar.org/foobar.svg" );
3288 imageView.SetSize( 200.f, 200.f );
3289 imageView.ResourceReadySignal().Connect( &ResourceReadySignal);
3291 DALI_TEST_EQUALS( imageView.IsResourceReady(), false, TEST_LOCATION );
3293 Stage::GetCurrent().Add( imageView );
3295 application.SendNotification();
3297 // loading started, this waits for the loader thread
3298 DALI_TEST_EQUALS( Test::WaitForEventThreadTrigger( 1 ), true, TEST_LOCATION );
3300 application.SendNotification();
3301 application.Render(16);
3303 DALI_TEST_EQUALS( gResourceReadySignalFired, true, TEST_LOCATION );
3304 DALI_TEST_EQUALS( imageView.IsResourceReady(), true, TEST_LOCATION );
3305 DALI_TEST_EQUALS( imageView.GetVisualResourceStatus( ImageView::Property::IMAGE ), Visual::ResourceStatus::FAILED, TEST_LOCATION );
3314 static int gResourceReadySignalCounter = 0;
3316 void OnResourceReadySignal( Control control )
3318 gResourceReadySignalCounter++;
3320 if( gResourceReadySignalCounter == 1 )
3323 ImageView::DownCast( control ).SetImage( gImage_34_RGBA );
3324 ImageView::DownCast( control ).SetImage( gImage_34_RGBA );
3330 int UtcDaliImageViewSetImageOnResourceReadySignal(void)
3332 tet_infoline("Test setting image from within signal handler.");
3334 ToolkitTestApplication application;
3336 gResourceReadySignalCounter = 0;
3338 ImageView imageView = ImageView::New( gImage_34_RGBA );
3339 imageView.ResourceReadySignal().Connect( &OnResourceReadySignal );
3341 Stage::GetCurrent().Add( imageView );
3343 DALI_TEST_EQUALS( Test::WaitForEventThreadTrigger( 1 ), true, TEST_LOCATION );
3345 application.SendNotification();
3346 application.Render();
3348 DALI_TEST_EQUALS( gResourceReadySignalCounter, 2, TEST_LOCATION );
3350 DALI_TEST_EQUALS( imageView.IsResourceReady(), true, TEST_LOCATION );