2 * Copyright (c) 2018 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/visual-properties-devel.h>
31 #include <test-native-image.h>
36 #include "dummy-control.h"
39 using namespace Toolkit;
41 void utc_dali_toolkit_image_view_startup(void)
43 test_return_value = TET_UNDEF;
46 void utc_dali_toolkit_image_view_cleanup(void)
48 test_return_value = TET_PASS;
54 const char* VERTEX_SHADER = DALI_COMPOSE_SHADER(
55 attribute mediump vec2 aPosition;\n
56 varying mediump vec2 vTexCoord;\n
57 uniform mediump mat4 uMvpMatrix;\n
58 uniform mediump vec3 uSize;\n
62 mediump vec4 vertexPosition = vec4(aPosition, 0.0, 1.0);\n
63 vertexPosition.xyz *= uSize;\n
64 vertexPosition = uMvpMatrix * vertexPosition;\n
66 vTexCoord = aPosition + vec2(0.5);\n
67 gl_Position = vertexPosition;\n
71 const char* FRAGMENT_SHADER = DALI_COMPOSE_SHADER(
72 varying mediump vec2 vTexCoord;\n
73 uniform sampler2D sTexture;\n
74 uniform lowp vec4 uColor;\n
78 gl_FragColor = texture2D( sTexture, vTexCoord ) * uColor;\n
82 const char* TEST_IMAGE_FILE_NAME = "gallery_image_01.jpg";
83 const char* TEST_IMAGE_FILE_NAME2 = "gallery_image_02.jpg";
85 const char* TEST_IMAGE_1 = TEST_RESOURCE_DIR "/TB-gloss.png";
86 const char* TEST_IMAGE_2 = TEST_RESOURCE_DIR "/tb-norm.png";
88 // resolution: 34*34, pixel format: RGBA8888
89 static const char* gImage_34_RGBA = TEST_RESOURCE_DIR "/icon-edit.png";
90 // resolution: 600*600, pixel format: RGB888
91 static const char* gImage_600_RGB = TEST_RESOURCE_DIR "/test-image-600.jpg";
93 // resolution: 50*50, frame count: 4, frame delay: 0.2 second for each frame
94 const char* TEST_GIF_FILE_NAME = TEST_RESOURCE_DIR "/anim.gif";
96 void TestImage( ImageView imageView, BufferImage image )
98 Property::Value value = imageView.GetProperty( imageView.GetPropertyIndex( "image" ) );
101 DALI_TEST_CHECK( value.Get( map ) );
103 DALI_TEST_CHECK( map.Find( "width" ) );
104 DALI_TEST_CHECK( map.Find( "height" ) );
105 DALI_TEST_CHECK( map.Find( "type" ) );
108 DALI_TEST_CHECK( map[ "width" ].Get( width ) );
109 DALI_TEST_EQUALS( (unsigned int)width, image.GetWidth(), TEST_LOCATION );
112 DALI_TEST_CHECK( map[ "height" ].Get( height ) );
113 DALI_TEST_EQUALS( (unsigned int)height, image.GetHeight(), TEST_LOCATION );
116 DALI_TEST_CHECK( map[ "type" ].Get( type ) );
117 DALI_TEST_EQUALS( type, "BufferImage", TEST_LOCATION );
120 void TestImage( ImageView imageView, ResourceImage image )
122 Property::Value value = imageView.GetProperty( imageView.GetPropertyIndex( "image" ) );
125 DALI_TEST_CHECK( value.Get( map ) );
127 if( map.Find( "width" ) )
130 DALI_TEST_CHECK( map[ "width" ].Get( width ) );
131 DALI_TEST_EQUALS( (unsigned int)width, image.GetWidth(), TEST_LOCATION );
134 if( map.Find( "height" ) )
137 DALI_TEST_CHECK( map[ "height" ].Get( height ) );
138 DALI_TEST_EQUALS( (unsigned int)height, image.GetHeight(), TEST_LOCATION );
141 DALI_TEST_CHECK( map.Find( "type" ) );
144 DALI_TEST_CHECK( map[ "type" ].Get( type ) );
145 DALI_TEST_EQUALS( type, "ResourceImage", TEST_LOCATION );
147 std::string filename;
148 DALI_TEST_CHECK( map[ "filename" ].Get( filename ) );
149 DALI_TEST_EQUALS( filename, image.GetUrl(), TEST_LOCATION );
152 void TestUrl( ImageView imageView, const std::string url )
154 Property::Value value = imageView.GetProperty( imageView.GetPropertyIndex( "image" ) );
156 std::string urlActual;
157 DALI_TEST_CHECK( value.Get( urlActual ) );
158 DALI_TEST_EQUALS( urlActual, url, TEST_LOCATION );
163 int UtcDaliImageViewNewP(void)
165 TestApplication application;
167 ImageView imageView = ImageView::New();
169 DALI_TEST_CHECK( imageView );
174 int UtcDaliImageViewNewImageP(void)
176 TestApplication application;
178 BufferImage image = CreateBufferImage( 100, 200, Vector4( 1.f, 1.f, 1.f, 1.f ) );
179 ImageView imageView = ImageView::New( image );
181 DALI_TEST_CHECK( imageView );
182 TestImage( imageView, image );
187 int UtcDaliImageViewNewUrlP(void)
189 TestApplication application;
191 ImageView imageView = ImageView::New( TEST_IMAGE_FILE_NAME );
192 DALI_TEST_CHECK( imageView );
194 TestUrl( imageView, TEST_IMAGE_FILE_NAME );
199 int UtcDaliImageViewConstructorP(void)
201 TestApplication application;
205 DALI_TEST_CHECK( !imageView );
210 int UtcDaliImageViewCopyConstructorP(void)
212 TestApplication application;
214 // Initialize an object, ref count == 1
215 ImageView imageView = ImageView::New();
217 ImageView copy( imageView );
218 DALI_TEST_CHECK( copy );
223 int UtcDaliImageViewAssignmentOperatorP(void)
225 TestApplication application;
227 ImageView imageView = ImageView::New();
229 ImageView copy( imageView );
230 DALI_TEST_CHECK( copy );
231 DALI_TEST_EQUALS( imageView, copy, TEST_LOCATION );
236 int UtcDaliImageViewDownCastP(void)
238 TestApplication application;
240 ImageView imageView = ImageView::New();
242 BaseHandle object(imageView);
244 ImageView imageView2 = ImageView::DownCast( object );
245 DALI_TEST_CHECK(imageView2);
247 ImageView imageView3 = DownCast< ImageView >( object );
248 DALI_TEST_CHECK(imageView3);
253 int UtcDaliImageViewDownCastN(void)
255 TestApplication application;
257 BaseHandle unInitializedObject;
259 ImageView imageView1 = ImageView::DownCast( unInitializedObject );
260 DALI_TEST_CHECK( !imageView1 );
262 ImageView imageView2 = DownCast< ImageView >( unInitializedObject );
263 DALI_TEST_CHECK( !imageView2 );
268 int UtcDaliImageViewTypeRegistry(void)
270 ToolkitTestApplication application;
272 TypeRegistry typeRegistry = TypeRegistry::Get();
273 DALI_TEST_CHECK( typeRegistry );
275 TypeInfo typeInfo = typeRegistry.GetTypeInfo( "ImageView" );
276 DALI_TEST_CHECK( typeInfo );
278 BaseHandle handle = typeInfo.CreateInstance();
279 DALI_TEST_CHECK( handle );
281 ImageView imageView = ImageView::DownCast( handle );
282 DALI_TEST_CHECK( imageView );
287 int UtcDaliImageViewSetGetProperty01(void)
289 ToolkitTestApplication application;
291 ImageView imageView = ImageView::New();
293 Property::Index idx = imageView.GetPropertyIndex( "image" );
294 DALI_TEST_EQUALS( idx, (Property::Index)ImageView::Property::IMAGE, TEST_LOCATION );
296 imageView.SetProperty( idx, TEST_IMAGE_FILE_NAME );
297 TestUrl( imageView, TEST_IMAGE_FILE_NAME );
302 int UtcDaliImageViewSetGetProperty02(void)
304 ToolkitTestApplication application;
306 Image image = CreateBufferImage( 10, 10, Color::WHITE );
307 ImageView imageView = ImageView::New(image);
308 Vector4 fullImageRect( 0.f, 0.f, 1.f, 1.f );
310 Stage::GetCurrent().Add( imageView );
312 application.SendNotification();
313 application.Render();
314 TestGlAbstraction& gl = application.GetGlAbstraction();
316 Vector4 pixelAreaUniform;
317 DALI_TEST_CHECK( gl.GetUniformValue<Vector4>( "pixelArea", pixelAreaUniform ) );
318 DALI_TEST_EQUALS( pixelAreaUniform, fullImageRect, TEST_LOCATION );
320 Property::Value value = imageView.GetProperty( ImageView::Property::PIXEL_AREA );
321 Vector4 pixelAreaValue;
322 DALI_TEST_CHECK( value.Get(pixelAreaValue) );
323 DALI_TEST_EQUALS( pixelAreaValue, fullImageRect, TEST_LOCATION );
325 Vector4 pixelAreaSet( 0.2f, 0.2f, 0.3f, 0.3f );
326 imageView.SetProperty( ImageView::Property::PIXEL_AREA, pixelAreaSet);
328 application.SendNotification();
329 application.Render();
331 value = imageView.GetProperty( ImageView::Property::PIXEL_AREA );
332 value.Get(pixelAreaValue);
333 DALI_TEST_EQUALS( pixelAreaValue, pixelAreaSet, TEST_LOCATION );
335 DALI_TEST_CHECK( gl.GetUniformValue<Vector4>( "pixelArea", pixelAreaUniform ) );
336 DALI_TEST_EQUALS( pixelAreaUniform, pixelAreaSet, TEST_LOCATION );
341 int UtcDaliImageViewSetGetProperty03(void)
343 ToolkitTestApplication application;
345 Image image = CreateBufferImage( 10, 10, Color::WHITE );
346 ImageView imageView = ImageView::New(image);
347 Stage::GetCurrent().Add( imageView );
348 application.SendNotification();
349 application.Render();
351 // conventional alpha blending
352 Renderer renderer = imageView.GetRendererAt( 0 );
353 Property::Value value = renderer.GetProperty( Renderer::Property::BLEND_PRE_MULTIPLIED_ALPHA );
355 DALI_TEST_CHECK( value.Get( enable ) );
356 DALI_TEST_CHECK( enable );
358 // pre-multiplied alpha blending
359 imageView.SetProperty( Toolkit::ImageView::Property::PRE_MULTIPLIED_ALPHA, true );
360 application.SendNotification();
361 application.Render();
363 int srcFactorRgb = renderer.GetProperty<int>( Renderer::Property::BLEND_FACTOR_SRC_RGB );
364 int destFactorRgb = renderer.GetProperty<int>( Renderer::Property::BLEND_FACTOR_DEST_RGB );
365 int srcFactorAlpha = renderer.GetProperty<int>( Renderer::Property::BLEND_FACTOR_SRC_ALPHA );
366 int destFactorAlpha = renderer.GetProperty<int>( Renderer::Property::BLEND_FACTOR_DEST_ALPHA );
367 DALI_TEST_CHECK( srcFactorRgb == BlendFactor::ONE );
368 DALI_TEST_CHECK( destFactorRgb == BlendFactor::ONE_MINUS_SRC_ALPHA );
369 DALI_TEST_CHECK( srcFactorAlpha == BlendFactor::ONE );
370 DALI_TEST_CHECK( destFactorAlpha == BlendFactor::ONE_MINUS_SRC_ALPHA );
372 value = renderer.GetProperty( Renderer::Property::BLEND_PRE_MULTIPLIED_ALPHA );
373 DALI_TEST_CHECK( value.Get( enable ) );
374 DALI_TEST_CHECK( enable );
379 int UtcDaliImageViewPreMultipliedAlpha(void)
381 ToolkitTestApplication application;
383 ImageView imageView = ImageView::New( gImage_34_RGBA );
385 // Disable pre-multiplied alpha blending
386 imageView.SetProperty( Toolkit::ImageView::Property::PRE_MULTIPLIED_ALPHA, false );
388 Stage::GetCurrent().Add( imageView );
390 application.SendNotification();
391 application.Render();
393 // loading started, this waits for the loader thread for max 30 seconds
394 DALI_TEST_EQUALS( Test::WaitForEventThreadTrigger( 1 ), true, TEST_LOCATION );
396 // conventional alpha blending
397 Renderer renderer = imageView.GetRendererAt( 0 );
398 Property::Value value = renderer.GetProperty( Renderer::Property::BLEND_PRE_MULTIPLIED_ALPHA );
400 DALI_TEST_CHECK( value.Get( enable ) );
401 DALI_TEST_CHECK( !enable );
403 int srcFactorRgb = renderer.GetProperty<int>( Renderer::Property::BLEND_FACTOR_SRC_RGB );
404 int destFactorRgb = renderer.GetProperty<int>( Renderer::Property::BLEND_FACTOR_DEST_RGB );
405 int srcFactorAlpha = renderer.GetProperty<int>( Renderer::Property::BLEND_FACTOR_SRC_ALPHA );
406 int destFactorAlpha = renderer.GetProperty<int>( Renderer::Property::BLEND_FACTOR_DEST_ALPHA );
407 DALI_TEST_CHECK( srcFactorRgb == BlendFactor::SRC_ALPHA );
408 DALI_TEST_CHECK( destFactorRgb == BlendFactor::ONE_MINUS_SRC_ALPHA );
409 DALI_TEST_CHECK( srcFactorAlpha == BlendFactor::ONE );
410 DALI_TEST_CHECK( destFactorAlpha == BlendFactor::ONE_MINUS_SRC_ALPHA );
412 value = renderer.GetProperty( Renderer::Property::BLEND_PRE_MULTIPLIED_ALPHA );
413 DALI_TEST_CHECK( value.Get( enable ) );
414 DALI_TEST_CHECK( !enable );
416 // Enable pre-multiplied alpha blending
417 imageView.SetProperty( Toolkit::ImageView::Property::PRE_MULTIPLIED_ALPHA, true );
418 application.SendNotification();
419 application.Render();
421 srcFactorRgb = renderer.GetProperty<int>( Renderer::Property::BLEND_FACTOR_SRC_RGB );
422 destFactorRgb = renderer.GetProperty<int>( Renderer::Property::BLEND_FACTOR_DEST_RGB );
423 srcFactorAlpha = renderer.GetProperty<int>( Renderer::Property::BLEND_FACTOR_SRC_ALPHA );
424 destFactorAlpha = renderer.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 value = renderer.GetProperty( Renderer::Property::BLEND_PRE_MULTIPLIED_ALPHA );
431 DALI_TEST_CHECK( value.Get( enable ) );
432 DALI_TEST_CHECK( enable );
437 int UtcDaliImageViewPixelArea(void)
439 // Test pixel area property
440 ToolkitTestApplication application;
442 // Gif image, use AnimatedImageVisual internally
443 // Atlasing is applied to pack multiple frames, use custom wrap mode
444 ImageView gifView = ImageView::New();
445 const Vector4 pixelAreaVisual( 0.f, 0.f, 2.f, 2.f );
446 gifView.SetProperty( ImageView::Property::IMAGE,
447 Property::Map().Add( ImageVisual::Property::URL, TEST_GIF_FILE_NAME )
448 .Add( ImageVisual::Property::PIXEL_AREA, pixelAreaVisual ) );
451 Stage stage = Stage::GetCurrent();
452 stage.Add( gifView );
455 application.SendNotification();
456 application.Render(16);
457 DALI_TEST_CHECK( gifView.GetRendererCount() == 1u );
459 const Vector4 fullTextureRect( 0.f, 0.f, 1.f, 1.f );
460 // test that the pixel area value defined in the visual property map is registered on renderer
461 Renderer renderer = gifView.GetRendererAt(0);
462 Property::Value pixelAreaValue = renderer.GetProperty( renderer.GetPropertyIndex( "pixelArea" ) );
463 DALI_TEST_EQUALS( pixelAreaValue.Get<Vector4>(), pixelAreaVisual, TEST_LOCATION );
465 // test that the shader has the default pixel area value registered.
466 Shader shader = renderer.GetShader();
467 pixelAreaValue = shader.GetProperty( shader.GetPropertyIndex( "pixelArea" ) );
468 DALI_TEST_EQUALS( pixelAreaValue.Get<Vector4>(), fullTextureRect, TEST_LOCATION );
470 // test that the uniform uses the pixelArea property on the renderer.
471 TestGlAbstraction& gl = application.GetGlAbstraction();
472 Vector4 pixelAreaUniform;
473 DALI_TEST_CHECK( gl.GetUniformValue<Vector4>( "pixelArea", pixelAreaUniform ) );
474 DALI_TEST_EQUALS( pixelAreaVisual, pixelAreaUniform, Math::MACHINE_EPSILON_100, TEST_LOCATION );
476 // set the pixelArea property on the control
477 const Vector4 pixelAreaControl( -1.f, -1.f, 3.f, 3.f );
478 gifView.SetProperty( ImageView::Property::PIXEL_AREA, pixelAreaControl );
479 application.SendNotification();
480 application.Render(16);
482 // check the pixelArea property on the control
483 pixelAreaValue = gifView.GetProperty( gifView.GetPropertyIndex( "pixelArea" ) );
484 DALI_TEST_EQUALS( pixelAreaValue.Get<Vector4>(), pixelAreaControl, TEST_LOCATION );
485 // test that the uniform uses the pixelArea property on the control.
486 DALI_TEST_CHECK( gl.GetUniformValue<Vector4>( "pixelArea", pixelAreaUniform ) );
487 DALI_TEST_EQUALS( pixelAreaControl, pixelAreaUniform, Math::MACHINE_EPSILON_100, TEST_LOCATION );
493 int UtcDaliImageViewAsyncLoadingWithoutAltasing(void)
495 ToolkitTestApplication application;
496 TestGlAbstraction& gl = application.GetGlAbstraction();
497 const std::vector<GLuint>& textures = gl.GetBoundTextures();
498 size_t numTextures = textures.size();
500 // Async loading, no atlasing for big size image
501 ImageView imageView = ImageView::New( gImage_600_RGB );
503 // By default, Aysnc loading is used
504 Stage::GetCurrent().Add( imageView );
505 imageView.SetSize(100, 100);
506 imageView.SetParentOrigin( ParentOrigin::CENTER );
508 DALI_TEST_EQUALS( Test::WaitForEventThreadTrigger( 1 ), true, TEST_LOCATION );
510 application.SendNotification();
511 application.Render(16);
512 application.SendNotification();
514 const std::vector<GLuint>& textures2 = gl.GetBoundTextures();
515 DALI_TEST_GREATER( textures2.size(), numTextures, TEST_LOCATION );
522 int UtcDaliImageViewAsyncLoadingWithAtlasing(void)
524 ToolkitTestApplication application;
526 //Async loading, automatic atlasing for small size image
527 TraceCallStack& callStack = application.GetGlAbstraction().GetTextureTrace();
529 callStack.Enable(true);
531 Property::Map imageMap;
533 imageMap[ ImageVisual::Property::URL ] = gImage_34_RGBA;
534 imageMap[ ImageVisual::Property::DESIRED_HEIGHT ] = 34;
535 imageMap[ ImageVisual::Property::DESIRED_WIDTH ] = 34;
536 imageMap[ ImageVisual::Property::ATLASING] = true;
538 ImageView imageView = ImageView::New();
539 imageView.SetProperty( ImageView::Property::IMAGE, imageMap );
540 imageView.SetProperty( Toolkit::Control::Property::PADDING, Extents( 10u, 10u, 10u, 10u ) );
542 // By default, Aysnc loading is used
543 // loading is not started if the actor is offStage
545 Stage::GetCurrent().Add( imageView );
546 application.SendNotification();
547 application.Render(16);
548 application.Render(16);
549 application.SendNotification();
551 imageView.SetProperty( Dali::Actor::Property::LAYOUT_DIRECTION, Dali::LayoutDirection::RIGHT_TO_LEFT );
552 application.SendNotification();
553 application.Render(16);
554 application.Render(16);
555 application.SendNotification();
557 // loading started, this waits for the loader thread for max 30 seconds
558 DALI_TEST_EQUALS( Test::WaitForEventThreadTrigger( 1 ), true, TEST_LOCATION );
560 application.SendNotification();
561 application.Render(16);
563 callStack.Enable(false);
565 TraceCallStack::NamedParams params;
566 params["width"] = ToString(34);
567 params["height"] = ToString(34);
568 DALI_TEST_EQUALS( callStack.FindMethodAndParams( "TexSubImage2D", params ), true, TEST_LOCATION );
573 int UtcDaliImageViewAsyncLoadingWithAtlasing02(void)
575 ToolkitTestApplication application;
577 //Async loading, automatic atlasing for small size image
578 TraceCallStack& callStack = application.GetGlAbstraction().GetTextureTrace();
580 callStack.Enable(true);
582 Property::Map asyncLoadingMap;
583 asyncLoadingMap[ "url" ] = gImage_34_RGBA;
584 asyncLoadingMap[ "desiredHeight" ] = 34;
585 asyncLoadingMap[ "desiredWidth" ] = 34;
586 asyncLoadingMap[ "synchronousLoading" ] = false;
587 asyncLoadingMap[ "atlasing" ] = true;
589 ImageView imageView = ImageView::New();
590 imageView.SetProperty( ImageView::Property::IMAGE, asyncLoadingMap );
592 Stage::GetCurrent().Add( imageView );
593 application.SendNotification();
594 application.Render(16);
595 application.Render(16);
596 application.SendNotification();
598 // loading started, this waits for the loader thread for max 30 seconds
599 DALI_TEST_EQUALS( Test::WaitForEventThreadTrigger( 1 ), true, TEST_LOCATION );
601 application.SendNotification();
602 application.Render(16);
604 callStack.Enable(false);
606 TraceCallStack::NamedParams params;
607 params["width"] = ToString(34);
608 params["height"] = ToString(34);
609 DALI_TEST_EQUALS( callStack.FindMethodAndParams( "TexSubImage2D", params ), true, TEST_LOCATION );
614 int UtcDaliImageViewSyncLoading(void)
616 ToolkitTestApplication application;
618 tet_infoline("ImageView Testing sync loading and size using index key property map");
620 Property::Map syncLoadingMap;
621 syncLoadingMap[ ImageVisual::Property::SYNCHRONOUS_LOADING ] = true;
622 syncLoadingMap[ ImageVisual::Property::ATLASING ] = true;
624 // Sync loading, no atlasing for big size image
626 ImageView imageView = ImageView::New();
628 // Sync loading is used
629 syncLoadingMap[ ImageVisual::Property::URL ] = gImage_600_RGB;
630 imageView.SetProperty( ImageView::Property::IMAGE, syncLoadingMap );
633 // Sync loading, automatic atlasing for small size image
635 TraceCallStack& callStack = application.GetGlAbstraction().GetTextureTrace();
637 callStack.Enable(true);
639 ImageView imageView = ImageView::New( );
641 // Sync loading is used
642 syncLoadingMap[ ImageVisual::Property::URL ] = gImage_34_RGBA;
643 syncLoadingMap[ ImageVisual::Property::DESIRED_HEIGHT ] = 34;
644 syncLoadingMap[ ImageVisual::Property::DESIRED_WIDTH ] = 34;
645 imageView.SetProperty( ImageView::Property::IMAGE, syncLoadingMap );
647 Stage::GetCurrent().Add( imageView );
648 application.SendNotification();
649 application.Render(16);
651 TraceCallStack::NamedParams params;
652 params["width"] = ToString(34);
653 params["height"] = ToString(34);
654 DALI_TEST_EQUALS( callStack.FindMethodAndParams( "TexSubImage2D", params ),
655 true, TEST_LOCATION );
660 int UtcDaliImageViewSyncLoading02(void)
662 ToolkitTestApplication application;
664 tet_infoline("ImageView Testing sync loading and size using string key property map");
666 // Sync loading, automatic atlasing for small size image
668 TraceCallStack& callStack = application.GetGlAbstraction().GetTextureTrace();
670 callStack.Enable(true);
672 ImageView imageView = ImageView::New( );
674 // Sync loading is used
675 Property::Map syncLoadingMap;
676 syncLoadingMap[ "url" ] = gImage_34_RGBA;
677 syncLoadingMap[ "desiredHeight" ] = 34;
678 syncLoadingMap[ "desiredWidth" ] = 34;
679 syncLoadingMap[ "synchronousLoading" ] = true;
680 syncLoadingMap[ "atlasing" ] = true;
681 imageView.SetProperty( ImageView::Property::IMAGE, syncLoadingMap );
683 Stage::GetCurrent().Add( imageView );
684 application.SendNotification();
685 application.Render(16);
687 TraceCallStack::NamedParams params;
688 params["width"] = ToString(34);
689 params["height"] = ToString(34);
690 DALI_TEST_EQUALS( callStack.FindMethodAndParams( "TexSubImage2D", params ),
691 true, TEST_LOCATION );
696 int UtcDaliImageViewAddedTexture(void)
698 ToolkitTestApplication application;
700 tet_infoline("ImageView Testing image view with texture provided manager url");
702 ImageView imageView = ImageView::New();
704 // empty texture is ok, though pointless from app point of view
706 std::string url = TextureManager::AddTexture(empty);
707 DALI_TEST_CHECK(url.size() > 0u);
709 Property::Map propertyMap;
710 propertyMap[ImageVisual::Property::URL] = url;
711 imageView.SetProperty(ImageView::Property::IMAGE, propertyMap);
713 Stage::GetCurrent().Add( imageView );
714 application.SendNotification();
715 application.Render();
720 int UtcDaliImageViewSizeWithBackground(void)
722 ToolkitTestApplication application;
726 Image image = CreateBufferImage( width, height, Vector4(1.f, 1.f, 1.f, 1.f) );
727 ImageView imageView = ImageView::New();
728 imageView.SetBackgroundImage( image );
730 Stage::GetCurrent().Add( imageView );
731 application.SendNotification();
732 application.Render();
734 DALI_TEST_EQUALS( imageView.GetCurrentSize().width, (float)width, TEST_LOCATION );
735 DALI_TEST_EQUALS( imageView.GetCurrentSize().height, (float)height, TEST_LOCATION );
740 int UtcDaliImageViewSizeWithBackgroundAndImage(void)
742 ToolkitTestApplication application;
744 int widthBackground = 100;
745 int heightBackground = 200;
748 Image imageBackground = CreateBufferImage( widthBackground, heightBackground, Vector4(1.f, 1.f, 1.f, 1.f) );
749 Image image = CreateBufferImage( width, height, Vector4(1.f, 1.f, 1.f, 1.f) );
751 ImageView imageView = ImageView::New();
752 imageView.SetBackgroundImage( imageBackground );
753 imageView.SetImage( image );
755 Stage::GetCurrent().Add( imageView );
756 application.SendNotification();
757 application.Render();
759 DALI_TEST_EQUALS( imageView.GetCurrentSize().width, (float)width, TEST_LOCATION );
760 DALI_TEST_EQUALS( imageView.GetCurrentSize().height, (float)height, TEST_LOCATION );
765 int UtcDaliImageViewHeightForWidthBackground(void)
767 ToolkitTestApplication application;
769 int widthBackground = 100;
770 int heightBackground = 200;
771 Image imageBackground = CreateBufferImage( widthBackground, heightBackground, Vector4(1.f, 1.f, 1.f, 1.f) );
773 ImageView imageView = ImageView::New();
774 imageView.SetBackgroundImage( imageBackground );
776 Stage::GetCurrent().Add( imageView );
777 application.SendNotification();
778 application.Render();
780 Control control = Control::DownCast( imageView );
781 DALI_TEST_CHECK( control );
782 DALI_TEST_EQUALS( imageView.GetHeightForWidth( 123.f ), control.GetHeightForWidth( 123.f ), TEST_LOCATION );
783 DALI_TEST_EQUALS( imageView.GetWidthForHeight( 321.f ), control.GetWidthForHeight( 321.f ), TEST_LOCATION );
788 int UtcDaliImageViewHeightForWidthBackgroundAndImage(void)
790 ToolkitTestApplication application;
792 int widthBackground = 100;
793 int heightBackground = 200;
796 Image imageBackground = CreateBufferImage( widthBackground, heightBackground, Vector4(1.f, 1.f, 1.f, 1.f) );
797 Image image = CreateBufferImage( width, height, Vector4(1.f, 1.f, 1.f, 1.f) );
799 ImageView imageView = ImageView::New();
800 imageView.SetBackgroundImage( imageBackground );
801 imageView.SetImage( image );
803 Stage::GetCurrent().Add( imageView );
804 application.SendNotification();
805 application.Render();
807 DALI_TEST_EQUALS( imageView.GetHeightForWidth( width ), (float)height, TEST_LOCATION );
808 DALI_TEST_EQUALS( imageView.GetWidthForHeight( height ), (float)width, TEST_LOCATION );
813 int UtcDaliImageViewSetBufferImage(void)
815 ToolkitTestApplication application;
819 BufferImage image1 = CreateBufferImage( width1, height1, Vector4( 1.f, 1.f, 1.f, 1.f ) );
820 ImageView imageView = ImageView::New();
821 imageView.SetImage( image1 );
823 TestImage( imageView, image1 );
827 BufferImage image2 = CreateBufferImage( width2, height2, Vector4( 1.f, 1.f, 1.f, 1.f ) );
828 imageView.SetImage( image2 );
830 TestImage( imageView, image2 );
835 int UtcDaliImageViewSetImageUrl(void)
837 ToolkitTestApplication application;
839 ImageView imageView = ImageView::New();
840 imageView.SetImage( TEST_IMAGE_FILE_NAME );
841 TestUrl( imageView, TEST_IMAGE_FILE_NAME );
844 imageView.SetImage( TEST_IMAGE_FILE_NAME2 );
845 TestUrl( imageView, TEST_IMAGE_FILE_NAME2 );
850 int UtcDaliImageViewSetImageOnstageP(void)
852 ToolkitTestApplication application;
854 ImageView imageView = ImageView::New();
856 Stage::GetCurrent().Add( imageView );
857 application.SendNotification();
858 application.Render();
860 ResourceImage image1 = ResourceImage::New( TEST_IMAGE_FILE_NAME );
861 imageView.SetImage( image1 );
862 TestImage( imageView, image1 );
866 BufferImage image2 = CreateBufferImage( width, height, Vector4( 1.f, 1.f, 1.f, 1.f ) );
867 imageView.SetImage( image2 );
868 TestImage( imageView, image2 );
873 int UtcDaliImageViewSetImageOnstageN(void)
875 ToolkitTestApplication application;
877 ImageView imageView = ImageView::New();
879 Stage::GetCurrent().Add( imageView );
880 application.SendNotification();
881 application.Render();
883 ResourceImage image1 = ResourceImage::New( TEST_IMAGE_FILE_NAME );
884 imageView.SetImage( image1 );
885 TestImage( imageView, image1 );
888 imageView.SetImage( image2 );
890 Property::Value value = imageView.GetProperty( imageView.GetPropertyIndex( "image" ) );
892 //the value should be empty
894 DALI_TEST_CHECK( !value.Get( url ) );
897 DALI_TEST_CHECK( !value.Get( map ) );
902 int UtcDaliImageViewSetImageOffstageP(void)
904 ToolkitTestApplication application;
906 ImageView imageView = ImageView::New();
908 Stage::GetCurrent().Add( imageView );
909 application.SendNotification();
910 application.Render();
911 Stage::GetCurrent().Remove( imageView );
913 ResourceImage image1 = ResourceImage::New( TEST_IMAGE_FILE_NAME );
914 imageView.SetImage( image1 );
915 TestImage( imageView, image1 );
919 BufferImage image2 = CreateBufferImage( width, height, Vector4( 1.f, 1.f, 1.f, 1.f ) );
920 imageView.SetImage( image2 );
921 TestImage( imageView, image2 );
926 bool gResourceReadySignalFired = false;
927 Vector3 gNaturalSize;
929 void ResourceReadySignal( Control control )
931 gResourceReadySignalFired = true;
934 int UtcDaliImageViewCheckResourceReady(void)
936 ToolkitTestApplication application;
938 gResourceReadySignalFired = false;
943 Image image = CreateBufferImage( width, height, Vector4(1.f, 1.f, 1.f, 1.f) );
945 // Check ImageView with background and main image, to ensure both visuals are marked as loaded
946 ImageView imageView = ImageView::New( TEST_GIF_FILE_NAME );
948 imageView.SetBackgroundImage( image );
950 DALI_TEST_EQUALS( imageView.IsResourceReady(), false, TEST_LOCATION );
952 imageView.ResourceReadySignal().Connect( &ResourceReadySignal);
954 Stage::GetCurrent().Add( imageView );
956 application.SendNotification();
957 application.Render(16);
960 DALI_TEST_EQUALS( imageView.IsResourceReady(), true, TEST_LOCATION );
962 DALI_TEST_EQUALS( gResourceReadySignalFired, true, TEST_LOCATION );
967 int UtcDaliImageViewSetImageOffstageN(void)
969 ToolkitTestApplication application;
971 ImageView imageView = ImageView::New();
973 Stage::GetCurrent().Add( imageView );
974 application.SendNotification();
975 application.Render();
976 Stage::GetCurrent().Remove( imageView );
978 ResourceImage image1 = ResourceImage::New( TEST_IMAGE_FILE_NAME );
979 imageView.SetImage( image1 );
980 TestImage( imageView, image1 );
983 imageView.SetImage( image2 );
985 Property::Value value = imageView.GetProperty( imageView.GetPropertyIndex( "image" ) );
987 //the value should be empty
989 DALI_TEST_CHECK( !value.Get( url ) );
992 DALI_TEST_CHECK( !value.Get( map ) );
997 int UtcDaliImageViewSetImageN(void)
999 ToolkitTestApplication application;
1002 ImageView imageView = ImageView::New();
1003 imageView.SetImage( image1 );
1005 Property::Value value = imageView.GetProperty( imageView.GetPropertyIndex( "image" ) );
1007 //the value should be empty
1009 DALI_TEST_CHECK( !value.Get( url ) );
1012 DALI_TEST_CHECK( !value.Get( map ) );
1014 std::string resource_url;
1015 Property::Value val = imageView.GetProperty( imageView.GetPropertyIndex( "image" ) );
1016 DALI_TEST_CHECK( !val.Get( resource_url ) );
1021 int UtcDaliImageViewSetImageTypeChangesP(void)
1023 ToolkitTestApplication application;
1025 ImageView imageView = ImageView::New();
1026 Toolkit::Internal::Control& controlImpl = Toolkit::Internal::GetImplementation( imageView );
1028 Stage::GetCurrent().Add( imageView );
1032 Toolkit::Visual::Base visual;
1034 Property::Value value = imageView.GetProperty( imageView.GetPropertyIndex( "image" ) );
1035 visual = DevelControl::GetVisual( controlImpl, ImageView::Property::IMAGE );
1037 application.SendNotification();
1038 application.Render( 16 );
1040 DALI_TEST_CHECK( ! value.Get( url ) ); // Value should be empty
1041 DALI_TEST_CHECK( ! value.Get( map ) ); // Value should be empty
1042 DALI_TEST_CHECK( ! visual ); // Visual should be invalid
1045 imageView.SetImage( "TEST_URL" );
1047 application.SendNotification();
1048 application.Render( 16 );
1050 value = imageView.GetProperty( imageView.GetPropertyIndex( "image" ) );
1051 visual = DevelControl::GetVisual( controlImpl, ImageView::Property::IMAGE );
1053 DALI_TEST_CHECK( value.Get( url ) ); // Value should NOT be empty
1054 DALI_TEST_CHECK( ! value.Get( map ) ); // Value should be empty
1055 DALI_TEST_CHECK( visual ); // Visual should be valid
1057 // Set an empty Image
1058 imageView.SetImage( Image() );
1060 application.SendNotification();
1061 application.Render( 16 );
1063 value = imageView.GetProperty( imageView.GetPropertyIndex( "image" ) );
1064 visual = DevelControl::GetVisual( controlImpl, ImageView::Property::IMAGE );
1066 DALI_TEST_CHECK( ! value.Get( url ) ); // Value should be empty
1067 DALI_TEST_CHECK( ! value.Get( map ) ); // Value should be empty
1068 DALI_TEST_CHECK( ! visual ); // Visual should be invalid
1071 ResourceImage image1 = ResourceImage::New( TEST_IMAGE_FILE_NAME );
1072 imageView.SetImage( image1 );
1074 application.SendNotification();
1075 application.Render( 16 );
1077 value = imageView.GetProperty( imageView.GetPropertyIndex( "image" ) );
1078 visual = DevelControl::GetVisual( controlImpl, ImageView::Property::IMAGE );
1080 DALI_TEST_CHECK( ! value.Get( url ) ); // Value should be empty
1081 DALI_TEST_CHECK( value.Get( map ) ); // Value should NOT be empty
1082 DALI_TEST_CHECK( visual ); // Visual should be valid
1085 imageView.SetImage( "" );
1087 application.SendNotification();
1088 application.Render( 16 );
1090 value = imageView.GetProperty( imageView.GetPropertyIndex( "image" ) );
1091 visual = DevelControl::GetVisual( controlImpl, ImageView::Property::IMAGE );
1093 DALI_TEST_CHECK( ! value.Get( url ) ); // Value should be empty
1094 DALI_TEST_CHECK( ! value.Get( map ) ); // Value should be empty
1095 DALI_TEST_CHECK( ! visual ); // Visual should be invalid
1097 // Set a URL in property map
1098 Property::Map propertyMap;
1099 propertyMap[ImageVisual::Property::URL] = TEST_IMAGE_FILE_NAME;
1100 imageView.SetProperty( ImageView::Property::IMAGE, propertyMap );
1102 application.SendNotification();
1103 application.Render( 16 );
1105 value = imageView.GetProperty( imageView.GetPropertyIndex( "image" ) );
1106 visual = DevelControl::GetVisual( controlImpl, ImageView::Property::IMAGE );
1108 DALI_TEST_CHECK( ! value.Get( url ) ); // Value should be empty
1109 DALI_TEST_CHECK( value.Get( map ) ); // Value should NOT be empty
1110 DALI_TEST_CHECK( visual ); // Visual should be valid
1112 // Set a URL in property map again
1113 propertyMap[ImageVisual::Property::URL] = gImage_34_RGBA;
1114 imageView.SetProperty( ImageView::Property::IMAGE, propertyMap );
1116 application.SendNotification();
1117 application.Render( 16 );
1119 value = imageView.GetProperty( imageView.GetPropertyIndex( "image" ) );
1120 visual = DevelControl::GetVisual( controlImpl, ImageView::Property::IMAGE );
1122 DALI_TEST_CHECK( ! value.Get( url ) ); // Value should be empty
1123 DALI_TEST_CHECK( value.Get( map ) ); // Value should NOT be empty
1124 DALI_TEST_CHECK( visual ); // Visual should be valid
1126 // Set an empty URL in property map
1127 propertyMap[ImageVisual::Property::URL] = std::string();
1128 imageView.SetProperty( ImageView::Property::IMAGE, propertyMap );
1130 application.SendNotification();
1131 application.Render( 16 );
1133 value = imageView.GetProperty( imageView.GetPropertyIndex( "image" ) );
1134 visual = DevelControl::GetVisual( controlImpl, ImageView::Property::IMAGE );
1136 DALI_TEST_CHECK( ! value.Get( url ) ); // Value should be empty
1137 DALI_TEST_CHECK( value.Get( map ) ); // Value should NOT be empty
1138 DALI_TEST_CHECK( ! visual ); // Visual should be invalid
1143 int UtcDaliImageViewResourceUrlP(void)
1145 ToolkitTestApplication application;
1147 ImageView imageView = ImageView::New();
1148 DALI_TEST_CHECK( imageView.GetProperty( ImageView::Property::RESOURCE_URL ).Get< std::string >().empty() );
1150 imageView.SetProperty( ImageView::Property::RESOURCE_URL, "TestString" );
1151 DALI_TEST_EQUALS( imageView.GetProperty( ImageView::Property::RESOURCE_URL ).Get< std::string >(), "TestString", TEST_LOCATION );
1156 // Scenarios 1: ImageView from regular image
1157 int UtcDaliImageViewSetImageBufferImage(void)
1159 ToolkitTestApplication application;
1161 ImageView imageView = ImageView::New();
1162 Stage::GetCurrent().Add( imageView );
1164 TestGlAbstraction& gl = application.GetGlAbstraction();
1165 gl.EnableTextureCallTrace( true );
1167 std::vector< GLuint > ids;
1168 ids.push_back( 23 );
1169 application.GetGlAbstraction().SetNextTextureIds( ids );
1173 BufferImage image = CreateBufferImage( width, height, Color::WHITE );
1175 imageView.SetImage( image );
1177 application.SendNotification();
1178 application.Render();
1180 DALI_TEST_CHECK( gl.GetTextureTrace().FindMethod("BindTexture") );
1182 std::stringstream params;
1183 params << GL_TEXTURE_2D << ", " << 23;
1184 DALI_TEST_CHECK( gl.GetTextureTrace().FindMethodAndParams("BindTexture", params.str()) );
1189 // Scenarios 2: ImageView from Native image
1190 int UtcDaliImageViewSetImageNativeImage(void)
1192 ToolkitTestApplication application;
1194 ImageView imageView = ImageView::New();
1195 Stage::GetCurrent().Add( imageView );
1197 TestGlAbstraction& gl = application.GetGlAbstraction();
1198 gl.EnableTextureCallTrace( true );
1200 std::vector< GLuint > ids;
1201 ids.push_back( 23 );
1202 application.GetGlAbstraction().SetNextTextureIds( ids );
1206 TestNativeImagePointer nativeImageInterface = TestNativeImage::New( width, height );
1207 NativeImage nativeImage = NativeImage::New( *(nativeImageInterface.Get()) );
1209 imageView.SetImage( nativeImage );
1210 application.SendNotification();
1211 application.Render();
1213 DALI_TEST_CHECK( gl.GetTextureTrace().FindMethod("BindTexture") );
1215 std::stringstream params;
1216 params << GL_TEXTURE_EXTERNAL_OES << ", " << 23;
1217 DALI_TEST_CHECK( gl.GetTextureTrace().FindMethodAndParams("BindTexture", params.str()) );
1222 // Scenarios 3: ImageView initially from regular image but then SetImage called with Native image
1223 int UtcDaliImageViewSetImageBufferImageToNativeImage(void)
1225 ToolkitTestApplication application;
1229 BufferImage image = CreateBufferImage( width, height, Color::WHITE );
1231 ImageView imageView = ImageView::New( image );
1232 Stage::GetCurrent().Add( imageView );
1234 TestGlAbstraction& gl = application.GetGlAbstraction();
1235 gl.EnableTextureCallTrace( true );
1237 std::vector< GLuint > ids;
1238 ids.push_back( 23 );
1239 application.GetGlAbstraction().SetNextTextureIds( ids );
1241 application.SendNotification();
1242 application.Render();
1244 DALI_TEST_CHECK( gl.GetTextureTrace().FindMethod("BindTexture") );
1246 std::stringstream params;
1247 params << GL_TEXTURE_2D << ", " << 23;
1248 DALI_TEST_CHECK( gl.GetTextureTrace().FindMethodAndParams("BindTexture", params.str()) );
1252 TestNativeImagePointer nativeImageInterface = TestNativeImage::New( width, height );
1253 NativeImage nativeImage = NativeImage::New( *(nativeImageInterface.Get()) );
1254 imageView.SetImage( nativeImage );
1257 ids.push_back( 24 );
1258 application.GetGlAbstraction().SetNextTextureIds( ids );
1260 application.SendNotification();
1261 application.Render();
1263 DALI_TEST_CHECK( gl.GetTextureTrace().FindMethod("BindTexture") );
1265 std::stringstream nextTextureParams;
1266 nextTextureParams << GL_TEXTURE_EXTERNAL_OES << ", " << 24;
1267 DALI_TEST_CHECK( gl.GetTextureTrace().FindMethodAndParams("BindTexture", nextTextureParams.str()) );
1272 // Scenarios 4: ImageView initially from Native image but then SetImage called with regular image
1273 int UtcDaliImageViewSetImageNativeImageToBufferImage(void)
1275 ToolkitTestApplication application;
1279 TestNativeImagePointer nativeImageInterface = TestNativeImage::New( width, height );
1280 NativeImage nativeImage = NativeImage::New( *(nativeImageInterface.Get()) );
1282 ImageView imageView = ImageView::New( nativeImage );
1283 Stage::GetCurrent().Add( imageView );
1285 TestGlAbstraction& gl = application.GetGlAbstraction();
1286 gl.EnableTextureCallTrace( true );
1288 std::vector< GLuint > ids;
1289 ids.push_back( 23 );
1290 application.GetGlAbstraction().SetNextTextureIds( ids );
1292 application.SendNotification();
1293 application.Render();
1295 DALI_TEST_CHECK( gl.GetTextureTrace().FindMethod("BindTexture") );
1297 std::stringstream params;
1298 params << GL_TEXTURE_EXTERNAL_OES << ", " << 23;
1299 DALI_TEST_CHECK( gl.GetTextureTrace().FindMethodAndParams("BindTexture", params.str()) );
1303 BufferImage image = CreateBufferImage( width, height, Color::WHITE );
1304 imageView.SetImage( image );
1307 ids.push_back( 24 );
1308 application.GetGlAbstraction().SetNextTextureIds( ids );
1310 application.SendNotification();
1311 application.Render();
1313 DALI_TEST_CHECK( gl.GetTextureTrace().FindMethod("BindTexture") );
1315 std::stringstream nextTextureParams;
1316 nextTextureParams << GL_TEXTURE_2D << ", " << 24;
1317 DALI_TEST_CHECK( gl.GetTextureTrace().FindMethodAndParams("BindTexture", nextTextureParams.str()) );
1322 // Scenarios 5: ImageView from Native image with custom shader
1323 int UtcDaliImageViewSetImageNativeImageWithCustomShader(void)
1325 ToolkitTestApplication application;
1330 Property::Map customShader;
1331 customShader.Insert( "vertexShader", VERTEX_SHADER );
1332 customShader.Insert( "fragmentShader", FRAGMENT_SHADER );
1334 Property::Array shaderHints;
1335 shaderHints.PushBack( "requiresSelfDepthTest" );
1336 shaderHints.PushBack( "outputIsTransparent" );
1337 shaderHints.PushBack( "outputIsOpaque" );
1338 shaderHints.PushBack( "modifiesGeometry" );
1340 customShader.Insert( "hints", shaderHints );
1343 map.Insert( "shader", customShader );
1345 TestNativeImagePointer nativeImageInterface = TestNativeImage::New( width, height );
1346 NativeImage nativeImage = NativeImage::New( *(nativeImageInterface.Get()) );
1348 ImageView imageView = ImageView::New( nativeImage );
1349 imageView.SetProperty( ImageView::Property::IMAGE, map );
1350 Stage::GetCurrent().Add( imageView );
1352 TestGlAbstraction& gl = application.GetGlAbstraction();
1353 gl.EnableTextureCallTrace( true );
1355 std::vector< GLuint > ids;
1356 ids.push_back( 23 );
1357 application.GetGlAbstraction().SetNextTextureIds( ids );
1359 application.SendNotification();
1360 application.Render();
1362 DALI_TEST_CHECK( gl.GetTextureTrace().FindMethod("BindTexture") );
1364 std::stringstream params;
1365 params << GL_TEXTURE_EXTERNAL_OES << ", " << 23;
1366 DALI_TEST_CHECK( gl.GetTextureTrace().FindMethodAndParams("BindTexture", params.str()) );
1371 // Scenarios 6: ImageView initially from regular image with custom shader but then SetImage called with Native
1372 int UtcDaliImageViewSetImageBufferImageWithCustomShaderToNativeImage(void)
1374 ToolkitTestApplication application;
1379 Property::Map customShader;
1380 customShader.Insert( "vertexShader", VERTEX_SHADER );
1381 customShader.Insert( "fragmentShader", FRAGMENT_SHADER );
1383 Property::Array shaderHints;
1384 shaderHints.PushBack( "requiresSelfDepthTest" );
1385 shaderHints.PushBack( "outputIsTransparent" );
1386 shaderHints.PushBack( "outputIsOpaque" );
1387 shaderHints.PushBack( "modifiesGeometry" );
1389 customShader.Insert( "hints", shaderHints );
1392 map.Insert( "shader", customShader );
1394 BufferImage image = CreateBufferImage( width, height, Color::WHITE );
1396 ImageView imageView = ImageView::New( image );
1397 imageView.SetProperty( ImageView::Property::IMAGE, map );
1398 Stage::GetCurrent().Add( imageView );
1400 TestGlAbstraction& gl = application.GetGlAbstraction();
1401 gl.EnableTextureCallTrace( true );
1403 std::vector< GLuint > ids;
1404 ids.push_back( 23 );
1405 application.GetGlAbstraction().SetNextTextureIds( ids );
1407 application.SendNotification();
1408 application.Render();
1410 DALI_TEST_CHECK( gl.GetTextureTrace().FindMethod("BindTexture") );
1412 std::stringstream params;
1413 params << GL_TEXTURE_2D << ", " << 23;
1414 DALI_TEST_CHECK( gl.GetTextureTrace().FindMethodAndParams("BindTexture", params.str()) );
1416 TestNativeImagePointer nativeImageInterface = TestNativeImage::New( width, height );
1417 NativeImage nativeImage = NativeImage::New( *(nativeImageInterface.Get()) );
1418 imageView.SetImage( nativeImage );
1421 ids.push_back( 24 );
1422 application.GetGlAbstraction().SetNextTextureIds( ids );
1424 application.SendNotification();
1425 application.Render();
1427 DALI_TEST_CHECK( gl.GetTextureTrace().FindMethod("BindTexture") );
1429 std::stringstream nativeImageParams;
1430 nativeImageParams << GL_TEXTURE_EXTERNAL_OES << ", " << 24;
1431 DALI_TEST_CHECK( gl.GetTextureTrace().FindMethodAndParams("BindTexture", nativeImageParams.str()) );
1437 int UtcDaliImageViewGetImageP1(void)
1439 ToolkitTestApplication application;
1441 ImageView imageView = ImageView::New();
1442 DALI_TEST_CHECK( ! imageView.GetImage() );
1444 Image image = CreateBufferImage();
1445 imageView.SetImage( image );
1446 DALI_TEST_CHECK( imageView.GetImage() == image );
1451 int UtcDaliImageViewGetImageP2(void)
1453 ToolkitTestApplication application;
1455 BufferImage image = CreateBufferImage();
1456 ImageView imageView = ImageView::New( image );
1457 DALI_TEST_CHECK( imageView.GetImage() == image );
1462 int UtcDaliImageViewGetImageN(void)
1464 ToolkitTestApplication application;
1466 ImageView imageView = ImageView::New( TEST_IMAGE_FILE_NAME );
1467 DALI_TEST_CHECK( ! imageView.GetImage() );
1469 Image image = CreateBufferImage();
1470 imageView.SetImage( image );
1471 DALI_TEST_CHECK( imageView.GetImage() == image );
1473 imageView.SetImage( TEST_IMAGE_FILE_NAME );
1474 DALI_TEST_CHECK( ! imageView.GetImage() );
1480 int UtcDaliImageViewReplaceImage(void)
1482 ToolkitTestApplication application;
1484 gResourceReadySignalFired = false;
1488 Image image = CreateBufferImage( width, height, Vector4(1.f, 1.f, 1.f, 1.f) );
1490 // Check ImageView with background and main image, to ensure both visuals are marked as loaded
1491 ImageView imageView = ImageView::New( TEST_IMAGE_1 );
1493 DALI_TEST_EQUALS( imageView.IsResourceReady(), false, TEST_LOCATION );
1495 imageView.ResourceReadySignal().Connect( &ResourceReadySignal);
1497 Stage::GetCurrent().Add( imageView );
1499 application.SendNotification();
1500 application.Render(16);
1502 // loading started, this waits for the loader thread for max 30 seconds
1503 DALI_TEST_EQUALS( Test::WaitForEventThreadTrigger( 1 ), true, TEST_LOCATION );
1505 DALI_TEST_EQUALS( imageView.GetRendererCount(), 1u, TEST_LOCATION );
1507 DALI_TEST_EQUALS( gResourceReadySignalFired, true, TEST_LOCATION );
1509 gResourceReadySignalFired = false;
1511 imageView.SetImage(TEST_IMAGE_2);
1513 application.SendNotification();
1514 application.Render(16);
1516 // loading started, this waits for the loader thread for max 30 seconds
1517 DALI_TEST_EQUALS( Test::WaitForEventThreadTrigger( 1 ), true, TEST_LOCATION );
1519 DALI_TEST_EQUALS( imageView.GetRendererCount(), 1u, TEST_LOCATION );
1521 DALI_TEST_EQUALS( imageView.IsResourceReady(), true, TEST_LOCATION );
1523 DALI_TEST_EQUALS( gResourceReadySignalFired, true, TEST_LOCATION );
1528 void OnRelayoutOverride( Size size )
1530 gNaturalSize = size; // Size Relayout is using
1533 int UtcDaliImageViewReplaceImageAndGetNaturalSize(void)
1535 ToolkitTestApplication application;
1537 // Check ImageView with background and main image, to ensure both visuals are marked as loaded
1538 ImageView imageView = ImageView::New( TEST_IMAGE_1 );
1539 imageView.SetResizePolicy( ResizePolicy::USE_NATURAL_SIZE, Dimension::ALL_DIMENSIONS );
1541 DummyControl dummyControl = DummyControl::New( true );
1542 Impl::DummyControl& dummyImpl = static_cast<Impl::DummyControl&>(dummyControl.GetImplementation());
1543 dummyControl.SetResizePolicy( ResizePolicy::FIT_TO_CHILDREN, Dimension::ALL_DIMENSIONS );
1545 dummyControl.Add( imageView );
1546 dummyImpl.SetRelayoutCallback( &OnRelayoutOverride );
1547 Stage::GetCurrent().Add( dummyControl );
1549 application.SendNotification();
1550 application.Render();
1552 // loading started, this waits for the loader thread for max 30 seconds
1553 DALI_TEST_EQUALS( Test::WaitForEventThreadTrigger( 1 ), true, TEST_LOCATION );
1555 DALI_TEST_EQUALS( gNaturalSize.width, 1024.0f, TEST_LOCATION );
1556 DALI_TEST_EQUALS( gNaturalSize.height, 1024.0f, TEST_LOCATION );
1558 gNaturalSize = Vector3::ZERO;
1560 imageView.SetImage(gImage_600_RGB);
1562 // Waiting for resourceReady so SendNotifcation not called here.
1564 // loading started, this waits for the loader thread for max 30 seconds
1565 DALI_TEST_EQUALS( Test::WaitForEventThreadTrigger( 1 ), true, TEST_LOCATION );
1567 // Trigger a potential relayout
1568 application.SendNotification();
1569 application.Render();
1571 DALI_TEST_EQUALS( gNaturalSize.width, 600.0f, TEST_LOCATION );
1572 DALI_TEST_EQUALS( gNaturalSize.height, 600.0f, TEST_LOCATION );
1577 int UtcDaliImageViewResourceReadySignalWithImmediateLoad(void)
1579 tet_infoline("Test Setting Image with IMMEDIATE load and receving ResourceReadySignal before staged.");
1581 ToolkitTestApplication application;
1583 gResourceReadySignalFired = false;
1585 Property::Map imageMap;
1587 imageMap[ ImageVisual::Property::URL ] = gImage_34_RGBA;
1588 imageMap[ ImageVisual::Property::LOAD_POLICY ] = ImageVisual::LoadPolicy::IMMEDIATE;
1590 tet_infoline("Creating ImageView without URL so image does not start loading");
1591 ImageView imageView = ImageView::New();
1592 tet_infoline("Connect to image loaded signal before setting image");
1593 imageView.ResourceReadySignal().Connect( &ResourceReadySignal);
1594 tet_infoline("Setting Image with IMMEDIATE load, signal already connected so will be triggered.");
1595 imageView.SetProperty( ImageView::Property::IMAGE, imageMap );
1597 // loading started, this waits for the loader thread
1598 DALI_TEST_EQUALS( Test::WaitForEventThreadTrigger( 1 ), true, TEST_LOCATION );
1600 application.SendNotification();
1601 application.Render(16);
1603 DALI_TEST_EQUALS( gResourceReadySignalFired, true, TEST_LOCATION );
1608 int UtcDaliImageViewResourceReadySignalWithReusedImage(void)
1610 tet_infoline("Test Setting Image that was already loaded by another ImageView and still getting ResourceReadySignal.");
1612 ToolkitTestApplication application;
1614 gResourceReadySignalFired = false;
1616 Property::Map imageMap;
1618 imageMap[ ImageVisual::Property::URL ] = gImage_34_RGBA;
1619 imageMap[ ImageVisual::Property::LOAD_POLICY ] = ImageVisual::LoadPolicy::IMMEDIATE;
1621 ImageView imageView = ImageView::New();
1622 imageView.ResourceReadySignal().Connect( &ResourceReadySignal);
1623 imageView.SetProperty( ImageView::Property::IMAGE, imageMap );
1625 // loading started, this waits for the loader thread
1626 DALI_TEST_EQUALS( Test::WaitForEventThreadTrigger( 1 ), true, TEST_LOCATION );
1628 application.SendNotification();
1629 application.Render(16);
1631 DALI_TEST_EQUALS( gResourceReadySignalFired, true, TEST_LOCATION );
1632 gResourceReadySignalFired = false;
1634 ImageView imageViewWithExistingImage = ImageView::New();
1635 imageViewWithExistingImage.ResourceReadySignal().Connect( &ResourceReadySignal);
1636 imageViewWithExistingImage.SetProperty( ImageView::Property::IMAGE, imageMap );
1638 DALI_TEST_EQUALS( gResourceReadySignalFired, true, TEST_LOCATION );
1643 int UtcDaliImageViewResourceReadySignalWithReusedImage02(void)
1645 tet_infoline("Test Setting Image that was already loaded by another ImageView and still getting ResourceReadySignal when staged.");
1647 ToolkitTestApplication application;
1649 gResourceReadySignalFired = false;
1651 Property::Map imageImmediateLoadingMap;
1652 imageImmediateLoadingMap[ ImageVisual::Property::URL ] = gImage_34_RGBA;
1653 imageImmediateLoadingMap[ ImageVisual::Property::LOAD_POLICY ] = ImageVisual::LoadPolicy::IMMEDIATE;
1655 tet_infoline("Immediate load an image");
1656 ImageView imageView = ImageView::New();
1657 imageView.ResourceReadySignal().Connect( &ResourceReadySignal);
1658 imageView.SetProperty( ImageView::Property::IMAGE, imageImmediateLoadingMap );
1660 // loading started, this waits for the loader thread
1661 DALI_TEST_EQUALS( Test::WaitForEventThreadTrigger( 1 ), true, TEST_LOCATION );
1663 application.SendNotification();
1664 application.Render(16);
1666 tet_infoline("Check image loaded");
1667 DALI_TEST_EQUALS( gResourceReadySignalFired, true, TEST_LOCATION );
1668 gResourceReadySignalFired = false;
1670 tet_infoline("Create another ImageView with the same URL");
1671 ImageView imageViewWithExistingImage = ImageView::New( gImage_34_RGBA );
1672 tet_infoline("Connect to ResourceReady signal for second ImageView, it should still fire as resource is ready");
1673 imageViewWithExistingImage.ResourceReadySignal().Connect( &ResourceReadySignal);
1675 Stage::GetCurrent().Add( imageViewWithExistingImage );
1677 DALI_TEST_EQUALS( gResourceReadySignalFired, true, TEST_LOCATION );
1682 int UtcDaliImageViewPaddingProperty(void)
1684 ToolkitTestApplication application;
1686 ImageView imageView = ImageView::New();
1687 Property::Map imagePropertyMap;
1688 imagePropertyMap[ Toolkit::Visual::Property::TYPE ] = Toolkit::Visual::IMAGE;
1689 imagePropertyMap[ Toolkit::ImageVisual::Property::URL ] = TEST_RESOURCE_DIR "/gallery-small-1.jpg" ;
1690 imagePropertyMap[ ImageVisual::Property::DESIRED_WIDTH ] = 128;
1691 imagePropertyMap[ ImageVisual::Property::DESIRED_HEIGHT ] = 128;
1692 imageView.SetProperty( Toolkit::ImageView::Property::IMAGE , imagePropertyMap );
1693 imageView.SetAnchorPoint( AnchorPoint::TOP_LEFT );
1694 imageView.SetParentOrigin( ParentOrigin::TOP_LEFT );
1695 imageView.SetProperty( Control::Property::PADDING, Extents( 15, 10, 5, 10 ) );
1696 Stage::GetCurrent().Add( imageView );
1698 application.SendNotification();
1699 application.Render();
1701 DALI_TEST_EQUALS( imageView.GetProperty<Extents>( Control::Property::PADDING ), Extents( 15, 10, 5, 10 ), TEST_LOCATION );
1703 ImageView childImage = ImageView::New();
1704 childImage.SetBackgroundColor( Color::BLACK );
1705 childImage.SetSize( 10.f, 10.f );
1706 imageView.Add( childImage );
1708 application.SendNotification();
1709 application.Render();
1711 // Child ImageView should be positioned dependinig on Parent ImageView's Padding value
1712 DALI_TEST_EQUALS( childImage.GetProperty<Vector3>( Dali::Actor::Property::POSITION ), Vector3( 15, 5, 0 ), TEST_LOCATION );
1714 // Check whether Image Visual transforms on ImageVieiw::OnRelayout()
1715 Toolkit::Internal::Control& controlImpl = Toolkit::Internal::GetImplementation( imageView );
1716 Toolkit::Visual::Base imageVisual = DevelControl::GetVisual( controlImpl, ImageView::Property::IMAGE );
1717 Property::Map resultMap;
1718 imageVisual.CreatePropertyMap( resultMap );
1720 Property::Value* transformValue = resultMap.Find( Visual::Property::TRANSFORM );
1721 DALI_TEST_CHECK( transformValue );
1722 Property::Map* retMap = transformValue->GetMap();
1723 DALI_TEST_CHECK( retMap );
1725 // Image Visual should be positioned depending on ImageView's padding
1726 DALI_TEST_EQUALS( retMap->Find( Visual::Transform::Property::OFFSET )->Get< Vector2 >(), Vector2( 15, 5 ), TEST_LOCATION );
1731 int UtcDaliImageViewPaddingProperty02(void)
1733 ToolkitTestApplication application;
1735 ImageView imageView = ImageView::New();
1736 Property::Map imagePropertyMap;
1737 imagePropertyMap[ Toolkit::Visual::Property::TYPE ] = Toolkit::Visual::IMAGE;
1738 imagePropertyMap[ Toolkit::ImageVisual::Property::URL ] = TEST_RESOURCE_DIR "/Kid1.svg" ;
1739 imagePropertyMap[ ImageVisual::Property::DESIRED_WIDTH ] = 128;
1740 imagePropertyMap[ ImageVisual::Property::DESIRED_HEIGHT ] = 128;
1741 imagePropertyMap[ DevelVisual::Property::VISUAL_FITTING_MODE ] = Toolkit::DevelVisual::FIT_KEEP_ASPECT_RATIO;
1742 imageView.SetProperty( Toolkit::ImageView::Property::IMAGE , imagePropertyMap );
1743 imageView.SetAnchorPoint( AnchorPoint::TOP_LEFT );
1744 imageView.SetParentOrigin( ParentOrigin::TOP_LEFT );
1745 imageView.SetProperty( Control::Property::PADDING, Extents( 15, 10, 5, 10 ) );
1746 Stage::GetCurrent().Add( imageView );
1748 application.SendNotification();
1749 application.Render();
1751 DALI_TEST_EQUALS( imageView.GetProperty<Extents>( Control::Property::PADDING ), Extents( 15, 10, 5, 10 ), TEST_LOCATION );
1753 // Check whether Image Visual transforms on ImageVieiw::OnRelayout()
1754 Toolkit::Internal::Control& controlImpl = Toolkit::Internal::GetImplementation( imageView );
1755 Toolkit::Visual::Base imageVisual = DevelControl::GetVisual( controlImpl, ImageView::Property::IMAGE );
1756 Property::Map resultMap;
1757 imageVisual.CreatePropertyMap( resultMap );
1759 Property::Value* transformValue = resultMap.Find( Visual::Property::TRANSFORM );
1760 DALI_TEST_CHECK( transformValue );
1761 Property::Map* retMap = transformValue->GetMap();
1762 DALI_TEST_CHECK( retMap );
1764 // Image Visual should be positioned depending on ImageView's padding
1765 DALI_TEST_EQUALS( retMap->Find( Visual::Transform::Property::OFFSET )->Get< Vector2 >(), Vector2( 15, 5 ), TEST_LOCATION );
1770 int UtcDaliImageViewUsingAtlasAndGetNaturalSize(void)
1772 ToolkitTestApplication application;
1774 // Check ImageView with background and main image, to ensure both visuals are marked as loaded
1775 ImageView imageView = ImageView::New();
1776 Property::Map imageMap;
1777 imageMap[ Toolkit::Visual::Property::TYPE ] = Toolkit::Visual::IMAGE;
1778 imageMap[ Toolkit::ImageVisual::Property::URL ] = gImage_34_RGBA;
1779 imageMap[ Toolkit::ImageVisual::Property::ATLASING ] = true;
1780 imageView.SetProperty( Toolkit::ImageView::Property::IMAGE, imageMap );
1781 Stage::GetCurrent().Add( imageView );
1783 // Trigger a potential relayout
1784 application.SendNotification();
1785 application.Render();
1787 Vector3 naturalSize = imageView.GetNaturalSize();
1789 DALI_TEST_EQUALS( naturalSize.width, 34.0f, TEST_LOCATION );
1790 DALI_TEST_EQUALS( naturalSize.height, 34.0f, TEST_LOCATION );
1795 int UtcDaliImageViewFillMode(void)
1797 ToolkitTestApplication application;
1799 tet_infoline( "Create an ImageVisual without padding and set the fill-mode to fill" );
1800 tet_infoline( " There should be no need to change the transform, our size-policy should be relative and size shoudl be [1,1]");
1802 ImageView imageView = ImageView::New();
1803 Property::Map imageMap;
1804 imageMap.Add( Toolkit::Visual::Property::TYPE, Toolkit::Visual::IMAGE );
1805 imageMap.Add( Toolkit::ImageVisual::Property::URL, gImage_600_RGB );
1806 imageMap.Add( DevelVisual::Property::VISUAL_FITTING_MODE, DevelVisual::FittingMode::FILL );
1808 imageView.SetProperty( Toolkit::ImageView::Property::IMAGE, imageMap );
1810 Stage::GetCurrent().Add( imageView );
1812 // Trigger a potential relayout
1813 application.SendNotification();
1814 application.Render();
1816 Toolkit::Visual::Base visual = DevelControl::GetVisual( Toolkit::Internal::GetImplementation( imageView ), Toolkit::ImageView::Property::IMAGE );
1817 Property::Map returnedMap;
1818 visual.CreatePropertyMap( returnedMap );
1820 Property::Value* value = returnedMap.Find( Toolkit::Visual::Property::TRANSFORM );
1821 DALI_TEST_CHECK( value );
1822 Property::Map* map = value->GetMap();
1823 DALI_TEST_CHECK( map );
1826 value = map->Find( Toolkit::Visual::Transform::Property::SIZE );
1827 DALI_TEST_CHECK( value );
1828 DALI_TEST_EQUALS( value->Get< Vector2 >(), Vector2::ONE, TEST_LOCATION ); // Relative size so will take up 100%
1830 value = map->Find( Toolkit::Visual::Transform::Property::SIZE_POLICY );
1831 DALI_TEST_CHECK( value );
1832 DALI_TEST_CHECK( value->Get< int >() == Toolkit::Visual::Transform::Policy::RELATIVE );
1837 int UtcDaliImageViewCustomShader(void)
1839 ToolkitTestApplication application;
1841 // Set a custom shader with an image url
1843 Property::Map properties;
1844 Property::Map shader;
1845 const std::string vertexShader = "Foobar";
1846 const std::string fragmentShader = "Foobar";
1847 shader[Visual::Shader::Property::FRAGMENT_SHADER] = fragmentShader;
1848 shader[Visual::Shader::Property::VERTEX_SHADER] = vertexShader;
1850 properties[Visual::Property::TYPE] = Visual::IMAGE;
1851 properties[Visual::Property::SHADER] = shader;
1852 properties[ImageVisual::Property::URL] = TEST_IMAGE_FILE_NAME;
1854 ImageView imageView = ImageView::New();
1855 imageView.SetProperty( ImageView::Property::IMAGE, properties );
1857 Stage::GetCurrent().Add( imageView );
1859 application.SendNotification();
1860 application.Render();
1862 DALI_TEST_EQUALS( Test::WaitForEventThreadTrigger( 1 ), true, TEST_LOCATION );
1864 Renderer renderer = imageView.GetRendererAt( 0 );
1865 Shader shader2 = renderer.GetShader();
1866 Property::Value value = shader2.GetProperty( Shader::Property::PROGRAM );
1867 Property::Map* map = value.GetMap();
1868 DALI_TEST_CHECK( map );
1870 Property::Value* fragment = map->Find( "fragment" ); // fragment key name from shader-impl.cpp
1871 DALI_TEST_EQUALS( fragmentShader, fragment->Get< std::string >(), TEST_LOCATION );
1873 Property::Value* vertex = map->Find( "vertex" ); // vertex key name from shader-impl.cpp
1874 DALI_TEST_EQUALS( vertexShader, vertex->Get< std::string >(), TEST_LOCATION );
1877 // Set a custom shader after setting an image url
1879 Property::Map properties;
1880 Property::Map shader;
1881 const std::string vertexShader = "Foobar";
1882 const std::string fragmentShader = "Foobar";
1883 shader[Visual::Shader::Property::FRAGMENT_SHADER] = fragmentShader;
1884 shader[Visual::Shader::Property::VERTEX_SHADER] = vertexShader;
1886 properties[Visual::Property::SHADER] = shader;
1888 ImageView imageView = ImageView::New( TEST_IMAGE_FILE_NAME );
1889 imageView.SetProperty( ImageView::Property::IMAGE, properties );
1891 Stage::GetCurrent().Add( imageView );
1893 application.SendNotification();
1894 application.Render();
1896 Renderer renderer = imageView.GetRendererAt( 0 );
1897 Shader shader2 = renderer.GetShader();
1898 Property::Value value = shader2.GetProperty( Shader::Property::PROGRAM );
1899 Property::Map* map = value.GetMap();
1900 DALI_TEST_CHECK( map );
1902 Property::Value* fragment = map->Find( "fragment" ); // fragment key name from shader-impl.cpp
1903 DALI_TEST_EQUALS( fragmentShader, fragment->Get< std::string >(), TEST_LOCATION );
1905 Property::Value* vertex = map->Find( "vertex" ); // vertex key name from shader-impl.cpp
1906 DALI_TEST_EQUALS( vertexShader, vertex->Get< std::string >(), TEST_LOCATION );
1909 // Set a custom shader before setting an image url
1911 Property::Map properties;
1912 Property::Map shader;
1913 const std::string vertexShader = "Foobar";
1914 const std::string fragmentShader = "Foobar";
1915 shader[Visual::Shader::Property::FRAGMENT_SHADER] = fragmentShader;
1916 shader[Visual::Shader::Property::VERTEX_SHADER] = vertexShader;
1918 properties[Visual::Property::SHADER] = shader;
1920 ImageView imageView = ImageView::New();
1921 imageView.SetProperty( ImageView::Property::IMAGE, properties );
1922 imageView.SetProperty( ImageView::Property::IMAGE, TEST_IMAGE_FILE_NAME );
1924 Stage::GetCurrent().Add( imageView );
1926 application.SendNotification();
1927 application.Render();
1929 Renderer renderer = imageView.GetRendererAt( 0 );
1930 Shader shader2 = renderer.GetShader();
1931 Property::Value value = shader2.GetProperty( Shader::Property::PROGRAM );
1932 Property::Map* map = value.GetMap();
1933 DALI_TEST_CHECK( map );
1935 Property::Value* fragment = map->Find( "fragment" ); // fragment key name from shader-impl.cpp
1936 DALI_TEST_EQUALS( fragmentShader, fragment->Get< std::string >(), TEST_LOCATION );
1938 Property::Value* vertex = map->Find( "vertex" ); // vertex key name from shader-impl.cpp
1939 DALI_TEST_EQUALS( vertexShader, vertex->Get< std::string >(), TEST_LOCATION );
1942 // Set a custom shader after setting a property map
1944 Property::Map properties;
1945 Property::Map shader;
1946 const std::string vertexShader = "Foobar";
1947 const std::string fragmentShader = "Foobar";
1948 shader[Visual::Shader::Property::FRAGMENT_SHADER] = fragmentShader;
1949 shader[Visual::Shader::Property::VERTEX_SHADER] = vertexShader;
1951 properties[Visual::Property::SHADER] = shader;
1953 Property::Map properties1;
1954 properties1[Visual::Property::TYPE] = Visual::IMAGE;
1955 properties1[ImageVisual::Property::URL] = TEST_IMAGE_FILE_NAME;
1957 ImageView imageView = ImageView::New();
1958 imageView.SetProperty( ImageView::Property::IMAGE, properties1 );
1959 imageView.SetProperty( ImageView::Property::IMAGE, properties );
1961 Stage::GetCurrent().Add( imageView );
1963 application.SendNotification();
1964 application.Render();
1966 Renderer renderer = imageView.GetRendererAt( 0 );
1967 Shader shader2 = renderer.GetShader();
1968 Property::Value value = shader2.GetProperty( Shader::Property::PROGRAM );
1969 Property::Map* map = value.GetMap();
1970 DALI_TEST_CHECK( map );
1972 Property::Value* fragment = map->Find( "fragment" ); // fragment key name from shader-impl.cpp
1973 DALI_TEST_EQUALS( fragmentShader, fragment->Get< std::string >(), TEST_LOCATION );
1975 Property::Value* vertex = map->Find( "vertex" ); // vertex key name from shader-impl.cpp
1976 DALI_TEST_EQUALS( vertexShader, vertex->Get< std::string >(), TEST_LOCATION );
1979 // Set a custom shader before setting a property map
1981 Property::Map properties;
1982 Property::Map shader;
1983 const std::string vertexShader = "Foobar";
1984 const std::string fragmentShader = "Foobar";
1985 shader[Visual::Shader::Property::FRAGMENT_SHADER] = fragmentShader;
1986 shader[Visual::Shader::Property::VERTEX_SHADER] = vertexShader;
1988 properties[Visual::Property::SHADER] = shader;
1990 Property::Map properties1;
1991 properties1[Visual::Property::TYPE] = Visual::IMAGE;
1992 properties1[ImageVisual::Property::URL] = TEST_IMAGE_FILE_NAME;
1994 ImageView imageView = ImageView::New();
1995 imageView.SetProperty( ImageView::Property::IMAGE, properties );
1996 imageView.SetProperty( ImageView::Property::IMAGE, properties1 );
1998 Stage::GetCurrent().Add( imageView );
2000 application.SendNotification();
2001 application.Render();
2003 Renderer renderer = imageView.GetRendererAt( 0 );
2004 Shader shader2 = renderer.GetShader();
2005 Property::Value value = shader2.GetProperty( Shader::Property::PROGRAM );
2006 Property::Map* map = value.GetMap();
2007 DALI_TEST_CHECK( map );
2009 Property::Value* fragment = map->Find( "fragment" ); // fragment key name from shader-impl.cpp
2010 DALI_TEST_EQUALS( fragmentShader, fragment->Get< std::string >(), TEST_LOCATION );
2012 Property::Value* vertex = map->Find( "vertex" ); // vertex key name from shader-impl.cpp
2013 DALI_TEST_EQUALS( vertexShader, vertex->Get< std::string >(), TEST_LOCATION );