2 * Copyright (c) 2017 Samsung Electronics Co., Ltd.
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
8 * http://www.apache.org/licenses/LICENSE-2.0
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
18 // Need to override adaptor classes for toolkit test harness, so include
19 // test harness headers before dali headers.
20 #include <dali-toolkit-test-suite-utils.h>
21 #include <toolkit-event-thread-callback.h>
23 #include <dali-toolkit/dali-toolkit.h>
24 #include <dali/devel-api/scripting/scripting.h>
25 #include <dali-toolkit/devel-api/visuals/image-visual-properties-devel.h>
26 #include <dali-toolkit/devel-api/controls/control-devel.h>
27 #include <dali/public-api/rendering/renderer.h>
29 #include <test-native-image.h>
33 #include "dummy-control.h"
36 using namespace Toolkit;
38 void utc_dali_toolkit_image_view_startup(void)
40 test_return_value = TET_UNDEF;
43 void utc_dali_toolkit_image_view_cleanup(void)
45 test_return_value = TET_PASS;
51 const char* VERTEX_SHADER = DALI_COMPOSE_SHADER(
52 attribute mediump vec2 aPosition;\n
53 varying mediump vec2 vTexCoord;\n
54 uniform mediump mat4 uMvpMatrix;\n
55 uniform mediump vec3 uSize;\n
59 mediump vec4 vertexPosition = vec4(aPosition, 0.0, 1.0);\n
60 vertexPosition.xyz *= uSize;\n
61 vertexPosition = uMvpMatrix * vertexPosition;\n
63 vTexCoord = aPosition + vec2(0.5);\n
64 gl_Position = vertexPosition;\n
68 const char* FRAGMENT_SHADER = DALI_COMPOSE_SHADER(
69 varying mediump vec2 vTexCoord;\n
70 uniform sampler2D sTexture;\n
71 uniform lowp vec4 uColor;\n
75 gl_FragColor = texture2D( sTexture, vTexCoord ) * uColor;\n
79 const char* TEST_IMAGE_FILE_NAME = "gallery_image_01.jpg";
80 const char* TEST_IMAGE_FILE_NAME2 = "gallery_image_02.jpg";
82 const char* TEST_IMAGE_1 = TEST_RESOURCE_DIR "/TB-gloss.png";
83 const char* TEST_IMAGE_2 = TEST_RESOURCE_DIR "/tb-norm.png";
85 // resolution: 34*34, pixel format: RGBA8888
86 static const char* gImage_34_RGBA = TEST_RESOURCE_DIR "/icon-edit.png";
87 // resolution: 600*600, pixel format: RGB888
88 static const char* gImage_600_RGB = TEST_RESOURCE_DIR "/test-image-600.jpg";
90 // resolution: 50*50, frame count: 4, frame delay: 0.2 second for each frame
91 const char* TEST_GIF_FILE_NAME = TEST_RESOURCE_DIR "/anim.gif";
93 void TestImage( ImageView imageView, BufferImage image )
95 Property::Value value = imageView.GetProperty( imageView.GetPropertyIndex( "image" ) );
98 DALI_TEST_CHECK( value.Get( map ) );
100 DALI_TEST_CHECK( map.Find( "width" ) );
101 DALI_TEST_CHECK( map.Find( "height" ) );
102 DALI_TEST_CHECK( map.Find( "type" ) );
105 DALI_TEST_CHECK( map[ "width" ].Get( width ) );
106 DALI_TEST_EQUALS( (unsigned int)width, image.GetWidth(), TEST_LOCATION );
109 DALI_TEST_CHECK( map[ "height" ].Get( height ) );
110 DALI_TEST_EQUALS( (unsigned int)height, image.GetHeight(), TEST_LOCATION );
113 DALI_TEST_CHECK( map[ "type" ].Get( type ) );
114 DALI_TEST_EQUALS( type, "BufferImage", TEST_LOCATION );
117 void TestImage( ImageView imageView, ResourceImage image )
119 Property::Value value = imageView.GetProperty( imageView.GetPropertyIndex( "image" ) );
122 DALI_TEST_CHECK( value.Get( map ) );
124 if( map.Find( "width" ) )
127 DALI_TEST_CHECK( map[ "width" ].Get( width ) );
128 DALI_TEST_EQUALS( (unsigned int)width, image.GetWidth(), TEST_LOCATION );
131 if( map.Find( "height" ) )
134 DALI_TEST_CHECK( map[ "height" ].Get( height ) );
135 DALI_TEST_EQUALS( (unsigned int)height, image.GetHeight(), TEST_LOCATION );
138 DALI_TEST_CHECK( map.Find( "type" ) );
141 DALI_TEST_CHECK( map[ "type" ].Get( type ) );
142 DALI_TEST_EQUALS( type, "ResourceImage", TEST_LOCATION );
144 std::string filename;
145 DALI_TEST_CHECK( map[ "filename" ].Get( filename ) );
146 DALI_TEST_EQUALS( filename, image.GetUrl(), TEST_LOCATION );
149 void TestUrl( ImageView imageView, const std::string url )
151 Property::Value value = imageView.GetProperty( imageView.GetPropertyIndex( "image" ) );
153 std::string urlActual;
154 DALI_TEST_CHECK( value.Get( urlActual ) );
155 DALI_TEST_EQUALS( urlActual, url, TEST_LOCATION );
160 int UtcDaliImageViewNewP(void)
162 TestApplication application;
164 ImageView imageView = ImageView::New();
166 DALI_TEST_CHECK( imageView );
171 int UtcDaliImageViewNewImageP(void)
173 TestApplication application;
175 BufferImage image = CreateBufferImage( 100, 200, Vector4( 1.f, 1.f, 1.f, 1.f ) );
176 ImageView imageView = ImageView::New( image );
178 DALI_TEST_CHECK( imageView );
179 TestImage( imageView, image );
184 int UtcDaliImageViewNewUrlP(void)
186 TestApplication application;
188 ImageView imageView = ImageView::New( TEST_IMAGE_FILE_NAME );
189 DALI_TEST_CHECK( imageView );
191 TestUrl( imageView, TEST_IMAGE_FILE_NAME );
196 int UtcDaliImageViewConstructorP(void)
198 TestApplication application;
202 DALI_TEST_CHECK( !imageView );
207 int UtcDaliImageViewCopyConstructorP(void)
209 TestApplication application;
211 // Initialize an object, ref count == 1
212 ImageView imageView = ImageView::New();
214 ImageView copy( imageView );
215 DALI_TEST_CHECK( copy );
220 int UtcDaliImageViewAssignmentOperatorP(void)
222 TestApplication application;
224 ImageView imageView = ImageView::New();
226 ImageView copy( imageView );
227 DALI_TEST_CHECK( copy );
228 DALI_TEST_EQUALS( imageView, copy, TEST_LOCATION );
233 int UtcDaliImageViewDownCastP(void)
235 TestApplication application;
237 ImageView imageView = ImageView::New();
239 BaseHandle object(imageView);
241 ImageView imageView2 = ImageView::DownCast( object );
242 DALI_TEST_CHECK(imageView2);
244 ImageView imageView3 = DownCast< ImageView >( object );
245 DALI_TEST_CHECK(imageView3);
250 int UtcDaliImageViewDownCastN(void)
252 TestApplication application;
254 BaseHandle unInitializedObject;
256 ImageView imageView1 = ImageView::DownCast( unInitializedObject );
257 DALI_TEST_CHECK( !imageView1 );
259 ImageView imageView2 = DownCast< ImageView >( unInitializedObject );
260 DALI_TEST_CHECK( !imageView2 );
265 int UtcDaliImageViewTypeRegistry(void)
267 ToolkitTestApplication application;
269 TypeRegistry typeRegistry = TypeRegistry::Get();
270 DALI_TEST_CHECK( typeRegistry );
272 TypeInfo typeInfo = typeRegistry.GetTypeInfo( "ImageView" );
273 DALI_TEST_CHECK( typeInfo );
275 BaseHandle handle = typeInfo.CreateInstance();
276 DALI_TEST_CHECK( handle );
278 ImageView imageView = ImageView::DownCast( handle );
279 DALI_TEST_CHECK( imageView );
284 int UtcDaliImageViewSetGetProperty01(void)
286 ToolkitTestApplication application;
288 ImageView imageView = ImageView::New();
290 Property::Index idx = imageView.GetPropertyIndex( "image" );
291 DALI_TEST_EQUALS( idx, (Property::Index)ImageView::Property::IMAGE, TEST_LOCATION );
293 imageView.SetProperty( idx, TEST_IMAGE_FILE_NAME );
294 TestUrl( imageView, TEST_IMAGE_FILE_NAME );
299 int UtcDaliImageViewSetGetProperty02(void)
301 ToolkitTestApplication application;
303 Image image = CreateBufferImage( 10, 10, Color::WHITE );
304 ImageView imageView = ImageView::New(image);
305 Vector4 fullImageRect( 0.f, 0.f, 1.f, 1.f );
307 Stage::GetCurrent().Add( imageView );
309 application.SendNotification();
310 application.Render();
311 TestGlAbstraction& gl = application.GetGlAbstraction();
313 Vector4 pixelAreaUniform;
314 DALI_TEST_CHECK( gl.GetUniformValue<Vector4>( "pixelArea", pixelAreaUniform ) );
315 DALI_TEST_EQUALS( pixelAreaUniform, fullImageRect, TEST_LOCATION );
317 Property::Value value = imageView.GetProperty( ImageView::Property::PIXEL_AREA );
318 Vector4 pixelAreaValue;
319 DALI_TEST_CHECK( value.Get(pixelAreaValue) );
320 DALI_TEST_EQUALS( pixelAreaValue, fullImageRect, TEST_LOCATION );
322 Vector4 pixelAreaSet( 0.2f, 0.2f, 0.3f, 0.3f );
323 imageView.SetProperty( ImageView::Property::PIXEL_AREA, pixelAreaSet);
325 application.SendNotification();
326 application.Render();
328 value = imageView.GetProperty( ImageView::Property::PIXEL_AREA );
329 value.Get(pixelAreaValue);
330 DALI_TEST_EQUALS( pixelAreaValue, pixelAreaSet, TEST_LOCATION );
332 DALI_TEST_CHECK( gl.GetUniformValue<Vector4>( "pixelArea", pixelAreaUniform ) );
333 DALI_TEST_EQUALS( pixelAreaUniform, pixelAreaSet, TEST_LOCATION );
338 int UtcDaliImageViewSetGetProperty03(void)
340 ToolkitTestApplication application;
342 Image image = CreateBufferImage( 10, 10, Color::WHITE );
343 ImageView imageView = ImageView::New(image);
344 Stage::GetCurrent().Add( imageView );
345 application.SendNotification();
346 application.Render();
348 // conventional alpha blending
349 Renderer renderer = imageView.GetRendererAt( 0 );
350 Property::Value value = renderer.GetProperty( Renderer::Property::BLEND_PRE_MULTIPLIED_ALPHA );
352 DALI_TEST_CHECK( value.Get( enable ) );
353 DALI_TEST_CHECK( !enable );
355 // pre-multiplied alpha blending
356 imageView.SetProperty( Toolkit::ImageView::Property::PRE_MULTIPLIED_ALPHA, true );
357 application.SendNotification();
358 application.Render();
360 int srcFactorRgb = renderer.GetProperty<int>( Renderer::Property::BLEND_FACTOR_SRC_RGB );
361 int destFactorRgb = renderer.GetProperty<int>( Renderer::Property::BLEND_FACTOR_DEST_RGB );
362 int srcFactorAlpha = renderer.GetProperty<int>( Renderer::Property::BLEND_FACTOR_SRC_ALPHA );
363 int destFactorAlpha = renderer.GetProperty<int>( Renderer::Property::BLEND_FACTOR_DEST_ALPHA );
364 DALI_TEST_CHECK( srcFactorRgb == BlendFactor::ONE );
365 DALI_TEST_CHECK( destFactorRgb == BlendFactor::ONE_MINUS_SRC_ALPHA );
366 DALI_TEST_CHECK( srcFactorAlpha == BlendFactor::ONE );
367 DALI_TEST_CHECK( destFactorAlpha == BlendFactor::ONE );
369 value = renderer.GetProperty( Renderer::Property::BLEND_PRE_MULTIPLIED_ALPHA );
370 DALI_TEST_CHECK( value.Get( enable ) );
371 DALI_TEST_CHECK( enable );
376 int UtcDaliImageViewPixelArea(void)
378 // Test pixel area property
379 ToolkitTestApplication application;
381 // Gif image, use AnimatedImageVisual internally
382 // Atlasing is applied to pack multiple frames, use custom wrap mode
383 ImageView gifView = ImageView::New();
384 const Vector4 pixelAreaVisual( 0.f, 0.f, 2.f, 2.f );
385 gifView.SetProperty( ImageView::Property::IMAGE,
386 Property::Map().Add( ImageVisual::Property::URL, TEST_GIF_FILE_NAME )
387 .Add( ImageVisual::Property::PIXEL_AREA, pixelAreaVisual ) );
390 Stage stage = Stage::GetCurrent();
391 stage.Add( gifView );
394 application.SendNotification();
395 application.Render(16);
396 DALI_TEST_CHECK( gifView.GetRendererCount() == 1u );
398 const Vector4 fullTextureRect( 0.f, 0.f, 1.f, 1.f );
399 // test that the pixel area value defined in the visual property map is registered on renderer
400 Renderer renderer = gifView.GetRendererAt(0);
401 Property::Value pixelAreaValue = renderer.GetProperty( renderer.GetPropertyIndex( "pixelArea" ) );
402 DALI_TEST_EQUALS( pixelAreaValue.Get<Vector4>(), pixelAreaVisual, TEST_LOCATION );
404 // test that the shader has the default pixel area value registered.
405 Shader shader = renderer.GetShader();
406 pixelAreaValue = shader.GetProperty( shader.GetPropertyIndex( "pixelArea" ) );
407 DALI_TEST_EQUALS( pixelAreaValue.Get<Vector4>(), fullTextureRect, TEST_LOCATION );
409 // test that the uniform uses the pixelArea property on the renderer.
410 TestGlAbstraction& gl = application.GetGlAbstraction();
411 Vector4 pixelAreaUniform;
412 DALI_TEST_CHECK( gl.GetUniformValue<Vector4>( "pixelArea", pixelAreaUniform ) );
413 DALI_TEST_EQUALS( pixelAreaVisual, pixelAreaUniform, Math::MACHINE_EPSILON_100, TEST_LOCATION );
415 // set the pixelArea property on the control
416 const Vector4 pixelAreaControl( -1.f, -1.f, 3.f, 3.f );
417 gifView.SetProperty( ImageView::Property::PIXEL_AREA, pixelAreaControl );
418 application.SendNotification();
419 application.Render(16);
421 // check the pixelArea property on the control
422 pixelAreaValue = gifView.GetProperty( gifView.GetPropertyIndex( "pixelArea" ) );
423 DALI_TEST_EQUALS( pixelAreaValue.Get<Vector4>(), pixelAreaControl, TEST_LOCATION );
424 // test that the uniform uses the pixelArea property on the control.
425 DALI_TEST_CHECK( gl.GetUniformValue<Vector4>( "pixelArea", pixelAreaUniform ) );
426 DALI_TEST_EQUALS( pixelAreaControl, pixelAreaUniform, Math::MACHINE_EPSILON_100, TEST_LOCATION );
432 int UtcDaliImageViewAsyncLoadingWithoutAltasing(void)
434 ToolkitTestApplication application;
435 TestGlAbstraction& gl = application.GetGlAbstraction();
436 const std::vector<GLuint>& textures = gl.GetBoundTextures();
437 size_t numTextures = textures.size();
439 // Async loading, no atlasing for big size image
440 ImageView imageView = ImageView::New( gImage_600_RGB );
442 // By default, Aysnc loading is used
443 Stage::GetCurrent().Add( imageView );
444 imageView.SetSize(100, 100);
445 imageView.SetParentOrigin( ParentOrigin::CENTER );
447 DALI_TEST_EQUALS( Test::WaitForEventThreadTrigger( 1 ), true, TEST_LOCATION );
449 application.SendNotification();
450 application.Render(16);
451 application.SendNotification();
453 const std::vector<GLuint>& textures2 = gl.GetBoundTextures();
454 DALI_TEST_GREATER( textures2.size(), numTextures, TEST_LOCATION );
461 int UtcDaliImageViewAsyncLoadingWithAtlasing(void)
463 ToolkitTestApplication application;
465 //Async loading, automatic atlasing for small size image
466 TraceCallStack& callStack = application.GetGlAbstraction().GetTextureTrace();
468 callStack.Enable(true);
470 Property::Map imageMap;
472 imageMap[ ImageVisual::Property::URL ] = gImage_34_RGBA;
473 imageMap[ ImageVisual::Property::DESIRED_HEIGHT ] = 34;
474 imageMap[ ImageVisual::Property::DESIRED_WIDTH ] = 34;
475 imageMap[ DevelImageVisual::Property::ATLASING] = true;
477 ImageView imageView = ImageView::New();
478 imageView.SetProperty( ImageView::Property::IMAGE, imageMap );
480 // By default, Aysnc loading is used
481 // loading is not started if the actor is offStage
483 Stage::GetCurrent().Add( imageView );
484 application.SendNotification();
485 application.Render(16);
486 application.Render(16);
487 application.SendNotification();
489 // loading started, this waits for the loader thread for max 30 seconds
490 DALI_TEST_EQUALS( Test::WaitForEventThreadTrigger( 1 ), true, TEST_LOCATION );
492 application.SendNotification();
493 application.Render(16);
495 callStack.Enable(false);
497 TraceCallStack::NamedParams params;
498 params["width"] = ToString(34);
499 params["height"] = ToString(34);
500 DALI_TEST_EQUALS( callStack.FindMethodAndParams( "TexSubImage2D", params ), true, TEST_LOCATION );
505 int UtcDaliImageViewAsyncLoadingWithAtlasing02(void)
507 ToolkitTestApplication application;
509 //Async loading, automatic atlasing for small size image
510 TraceCallStack& callStack = application.GetGlAbstraction().GetTextureTrace();
512 callStack.Enable(true);
514 Property::Map asyncLoadingMap;
515 asyncLoadingMap[ "url" ] = gImage_34_RGBA;
516 asyncLoadingMap[ "desiredHeight" ] = 34;
517 asyncLoadingMap[ "desiredWidth" ] = 34;
518 asyncLoadingMap[ "synchronousLoading" ] = false;
519 asyncLoadingMap[ "atlasing" ] = true;
521 ImageView imageView = ImageView::New();
522 imageView.SetProperty( ImageView::Property::IMAGE, asyncLoadingMap );
524 Stage::GetCurrent().Add( imageView );
525 application.SendNotification();
526 application.Render(16);
527 application.Render(16);
528 application.SendNotification();
530 // loading started, this waits for the loader thread for max 30 seconds
531 DALI_TEST_EQUALS( Test::WaitForEventThreadTrigger( 1 ), true, TEST_LOCATION );
533 application.SendNotification();
534 application.Render(16);
536 callStack.Enable(false);
538 TraceCallStack::NamedParams params;
539 params["width"] = ToString(34);
540 params["height"] = ToString(34);
541 DALI_TEST_EQUALS( callStack.FindMethodAndParams( "TexSubImage2D", params ), true, TEST_LOCATION );
546 int UtcDaliImageViewSyncLoading(void)
548 ToolkitTestApplication application;
550 tet_infoline("ImageView Testing sync loading and size using index key property map");
552 Property::Map syncLoadingMap;
553 syncLoadingMap[ ImageVisual::Property::SYNCHRONOUS_LOADING ] = true;
554 syncLoadingMap[ DevelImageVisual::Property::ATLASING ] = true;
556 // Sync loading, no atlasing for big size image
558 ImageView imageView = ImageView::New();
560 // Sync loading is used
561 syncLoadingMap[ ImageVisual::Property::URL ] = gImage_600_RGB;
562 imageView.SetProperty( ImageView::Property::IMAGE, syncLoadingMap );
565 // Sync loading, automatic atlasing for small size image
567 TraceCallStack& callStack = application.GetGlAbstraction().GetTextureTrace();
569 callStack.Enable(true);
571 ImageView imageView = ImageView::New( );
573 // Sync loading is used
574 syncLoadingMap[ ImageVisual::Property::URL ] = gImage_34_RGBA;
575 syncLoadingMap[ ImageVisual::Property::DESIRED_HEIGHT ] = 34;
576 syncLoadingMap[ ImageVisual::Property::DESIRED_WIDTH ] = 34;
577 imageView.SetProperty( ImageView::Property::IMAGE, syncLoadingMap );
579 Stage::GetCurrent().Add( imageView );
580 application.SendNotification();
581 application.Render(16);
583 TraceCallStack::NamedParams params;
584 params["width"] = ToString(34);
585 params["height"] = ToString(34);
586 DALI_TEST_EQUALS( callStack.FindMethodAndParams( "TexSubImage2D", params ),
587 true, TEST_LOCATION );
593 int UtcDaliImageViewSyncLoading02(void)
595 ToolkitTestApplication application;
597 tet_infoline("ImageView Testing sync loading and size using string key property map");
599 // Sync loading, automatic atlasing for small size image
601 TraceCallStack& callStack = application.GetGlAbstraction().GetTextureTrace();
603 callStack.Enable(true);
605 ImageView imageView = ImageView::New( );
607 // Sync loading is used
608 Property::Map syncLoadingMap;
609 syncLoadingMap[ "url" ] = gImage_34_RGBA;
610 syncLoadingMap[ "desiredHeight" ] = 34;
611 syncLoadingMap[ "desiredWidth" ] = 34;
612 syncLoadingMap[ "synchronousLoading" ] = true;
613 syncLoadingMap[ "atlasing" ] = true;
614 imageView.SetProperty( ImageView::Property::IMAGE, syncLoadingMap );
616 Stage::GetCurrent().Add( imageView );
617 application.SendNotification();
618 application.Render(16);
620 TraceCallStack::NamedParams params;
621 params["width"] = ToString(34);
622 params["height"] = ToString(34);
623 DALI_TEST_EQUALS( callStack.FindMethodAndParams( "TexSubImage2D", params ),
624 true, TEST_LOCATION );
629 int UtcDaliImageViewSizeWithBackground(void)
631 ToolkitTestApplication application;
635 Image image = CreateBufferImage( width, height, Vector4(1.f, 1.f, 1.f, 1.f) );
636 ImageView imageView = ImageView::New();
637 imageView.SetBackgroundImage( image );
639 Stage::GetCurrent().Add( imageView );
640 application.SendNotification();
641 application.Render();
643 DALI_TEST_EQUALS( imageView.GetCurrentSize().width, (float)width, TEST_LOCATION );
644 DALI_TEST_EQUALS( imageView.GetCurrentSize().height, (float)height, TEST_LOCATION );
649 int UtcDaliImageViewSizeWithBackgroundAndImage(void)
651 ToolkitTestApplication application;
653 int widthBackground = 100;
654 int heightBackground = 200;
657 Image imageBackground = CreateBufferImage( widthBackground, heightBackground, Vector4(1.f, 1.f, 1.f, 1.f) );
658 Image image = CreateBufferImage( width, height, Vector4(1.f, 1.f, 1.f, 1.f) );
660 ImageView imageView = ImageView::New();
661 imageView.SetBackgroundImage( imageBackground );
662 imageView.SetImage( image );
664 Stage::GetCurrent().Add( imageView );
665 application.SendNotification();
666 application.Render();
668 DALI_TEST_EQUALS( imageView.GetCurrentSize().width, (float)width, TEST_LOCATION );
669 DALI_TEST_EQUALS( imageView.GetCurrentSize().height, (float)height, TEST_LOCATION );
674 int UtcDaliImageViewHeightForWidthBackground(void)
676 ToolkitTestApplication application;
678 int widthBackground = 100;
679 int heightBackground = 200;
680 Image imageBackground = CreateBufferImage( widthBackground, heightBackground, Vector4(1.f, 1.f, 1.f, 1.f) );
682 ImageView imageView = ImageView::New();
683 imageView.SetBackgroundImage( imageBackground );
685 Stage::GetCurrent().Add( imageView );
686 application.SendNotification();
687 application.Render();
689 Control control = Control::DownCast( imageView );
690 DALI_TEST_CHECK( control );
691 DALI_TEST_EQUALS( imageView.GetHeightForWidth( 123.f ), control.GetHeightForWidth( 123.f ), TEST_LOCATION );
692 DALI_TEST_EQUALS( imageView.GetWidthForHeight( 321.f ), control.GetWidthForHeight( 321.f ), TEST_LOCATION );
697 int UtcDaliImageViewHeightForWidthBackgroundAndImage(void)
699 ToolkitTestApplication application;
701 int widthBackground = 100;
702 int heightBackground = 200;
705 Image imageBackground = CreateBufferImage( widthBackground, heightBackground, Vector4(1.f, 1.f, 1.f, 1.f) );
706 Image image = CreateBufferImage( width, height, Vector4(1.f, 1.f, 1.f, 1.f) );
708 ImageView imageView = ImageView::New();
709 imageView.SetBackgroundImage( imageBackground );
710 imageView.SetImage( image );
712 Stage::GetCurrent().Add( imageView );
713 application.SendNotification();
714 application.Render();
716 DALI_TEST_EQUALS( imageView.GetHeightForWidth( width ), (float)height, TEST_LOCATION );
717 DALI_TEST_EQUALS( imageView.GetWidthForHeight( height ), (float)width, TEST_LOCATION );
722 int UtcDaliImageViewSetBufferImage(void)
724 ToolkitTestApplication application;
728 BufferImage image1 = CreateBufferImage( width1, height1, Vector4( 1.f, 1.f, 1.f, 1.f ) );
729 ImageView imageView = ImageView::New();
730 imageView.SetImage( image1 );
732 TestImage( imageView, image1 );
736 BufferImage image2 = CreateBufferImage( width2, height2, Vector4( 1.f, 1.f, 1.f, 1.f ) );
737 imageView.SetImage( image2 );
739 TestImage( imageView, image2 );
744 int UtcDaliImageViewSetImageUrl(void)
746 ToolkitTestApplication application;
748 ImageView imageView = ImageView::New();
749 imageView.SetImage( TEST_IMAGE_FILE_NAME );
750 TestUrl( imageView, TEST_IMAGE_FILE_NAME );
753 imageView.SetImage( TEST_IMAGE_FILE_NAME2 );
754 TestUrl( imageView, TEST_IMAGE_FILE_NAME2 );
759 int UtcDaliImageViewSetImageOnstageP(void)
761 ToolkitTestApplication application;
763 ImageView imageView = ImageView::New();
765 Stage::GetCurrent().Add( imageView );
766 application.SendNotification();
767 application.Render();
769 ResourceImage image1 = ResourceImage::New( TEST_IMAGE_FILE_NAME );
770 imageView.SetImage( image1 );
771 TestImage( imageView, image1 );
775 BufferImage image2 = CreateBufferImage( width, height, Vector4( 1.f, 1.f, 1.f, 1.f ) );
776 imageView.SetImage( image2 );
777 TestImage( imageView, image2 );
782 int UtcDaliImageViewSetImageOnstageN(void)
784 ToolkitTestApplication application;
786 ImageView imageView = ImageView::New();
788 Stage::GetCurrent().Add( imageView );
789 application.SendNotification();
790 application.Render();
792 ResourceImage image1 = ResourceImage::New( TEST_IMAGE_FILE_NAME );
793 imageView.SetImage( image1 );
794 TestImage( imageView, image1 );
797 imageView.SetImage( image2 );
799 Property::Value value = imageView.GetProperty( imageView.GetPropertyIndex( "image" ) );
801 //the value should be empty
803 DALI_TEST_CHECK( !value.Get( url ) );
806 DALI_TEST_CHECK( !value.Get( map ) );
811 int UtcDaliImageViewSetImageOffstageP(void)
813 ToolkitTestApplication application;
815 ImageView imageView = ImageView::New();
817 Stage::GetCurrent().Add( imageView );
818 application.SendNotification();
819 application.Render();
820 Stage::GetCurrent().Remove( imageView );
822 ResourceImage image1 = ResourceImage::New( TEST_IMAGE_FILE_NAME );
823 imageView.SetImage( image1 );
824 TestImage( imageView, image1 );
828 BufferImage image2 = CreateBufferImage( width, height, Vector4( 1.f, 1.f, 1.f, 1.f ) );
829 imageView.SetImage( image2 );
830 TestImage( imageView, image2 );
835 bool gResourceReadySignalFired = false;
836 Vector3 gNaturalSize;
838 void ResourceReadySignal( Control control )
840 gResourceReadySignalFired = true;
843 int UtcDaliImageViewCheckResourceReady(void)
845 ToolkitTestApplication application;
847 gResourceReadySignalFired = false;
852 Image image = CreateBufferImage( width, height, Vector4(1.f, 1.f, 1.f, 1.f) );
854 // Check ImageView with background and main image, to ensure both visuals are marked as loaded
855 ImageView imageView = ImageView::New( TEST_GIF_FILE_NAME );
857 imageView.SetBackgroundImage( image );
859 DALI_TEST_EQUALS( Toolkit::DevelControl::IsResourceReady( imageView ), false, TEST_LOCATION );
861 Toolkit::DevelControl::ResourceReadySignal( imageView ).Connect( &ResourceReadySignal);
863 Stage::GetCurrent().Add( imageView );
865 application.SendNotification();
866 application.Render(16);
869 DALI_TEST_EQUALS( Toolkit::DevelControl::IsResourceReady( imageView ), true, TEST_LOCATION );
871 DALI_TEST_EQUALS( gResourceReadySignalFired, true, TEST_LOCATION );
876 int UtcDaliImageViewSetImageOffstageN(void)
878 ToolkitTestApplication application;
880 ImageView imageView = ImageView::New();
882 Stage::GetCurrent().Add( imageView );
883 application.SendNotification();
884 application.Render();
885 Stage::GetCurrent().Remove( imageView );
887 ResourceImage image1 = ResourceImage::New( TEST_IMAGE_FILE_NAME );
888 imageView.SetImage( image1 );
889 TestImage( imageView, image1 );
892 imageView.SetImage( image2 );
894 Property::Value value = imageView.GetProperty( imageView.GetPropertyIndex( "image" ) );
896 //the value should be empty
898 DALI_TEST_CHECK( !value.Get( url ) );
901 DALI_TEST_CHECK( !value.Get( map ) );
906 int UtcDaliImageViewSetImageN(void)
908 ToolkitTestApplication application;
911 ImageView imageView = ImageView::New();
912 imageView.SetImage( image1 );
914 Property::Value value = imageView.GetProperty( imageView.GetPropertyIndex( "image" ) );
916 //the value should be empty
918 DALI_TEST_CHECK( !value.Get( url ) );
921 DALI_TEST_CHECK( !value.Get( map ) );
923 std::string resource_url;
924 Property::Value val = imageView.GetProperty( imageView.GetPropertyIndex( "image" ) );
925 DALI_TEST_CHECK( !val.Get( resource_url ) );
930 int UtcDaliImageViewSetImageTypeChangesP(void)
932 ToolkitTestApplication application;
934 ImageView imageView = ImageView::New();
940 Property::Value value = imageView.GetProperty( imageView.GetPropertyIndex( "image" ) );
941 DALI_TEST_CHECK( ! value.Get( url ) ); // Value should be empty
942 DALI_TEST_CHECK( ! value.Get( map ) ); // Value should be empty
945 imageView.SetImage( "TEST_URL" );
946 value = imageView.GetProperty( imageView.GetPropertyIndex( "image" ) );
948 DALI_TEST_CHECK( value.Get( url ) ); // Value should NOT be empty
949 DALI_TEST_CHECK( ! value.Get( map ) ); // Value should be empty
951 // Set an empty Image
952 imageView.SetImage( Image() );
953 value = imageView.GetProperty( imageView.GetPropertyIndex( "image" ) );
955 DALI_TEST_CHECK( ! value.Get( url ) ); // Value should be empty
956 DALI_TEST_CHECK( ! value.Get( map ) ); // Value should be empty
959 ResourceImage image1 = ResourceImage::New( TEST_IMAGE_FILE_NAME );
960 imageView.SetImage( image1 );
961 value = imageView.GetProperty( imageView.GetPropertyIndex( "image" ) );
963 DALI_TEST_CHECK( ! value.Get( url ) ); // Value should be empty
964 DALI_TEST_CHECK( value.Get( map ) ); // Value should NOT be empty
967 imageView.SetImage( "" );
968 value = imageView.GetProperty( imageView.GetPropertyIndex( "image" ) );
970 DALI_TEST_CHECK( ! value.Get( url ) ); // Value should be empty
971 DALI_TEST_CHECK( ! value.Get( map ) ); // Value should be empty
976 int UtcDaliImageViewResourceUrlP(void)
978 ToolkitTestApplication application;
980 ImageView imageView = ImageView::New();
981 DALI_TEST_CHECK( imageView.GetProperty( ImageView::Property::RESOURCE_URL ).Get< std::string >().empty() );
983 imageView.SetProperty( ImageView::Property::RESOURCE_URL, "TestString" );
984 DALI_TEST_EQUALS( imageView.GetProperty( ImageView::Property::RESOURCE_URL ).Get< std::string >(), "TestString", TEST_LOCATION );
989 // Scenarios 1: ImageView from regular image
990 int UtcDaliImageViewSetImageBufferImage(void)
992 ToolkitTestApplication application;
994 ImageView imageView = ImageView::New();
995 Stage::GetCurrent().Add( imageView );
997 TestGlAbstraction& gl = application.GetGlAbstraction();
998 gl.EnableTextureCallTrace( true );
1000 std::vector< GLuint > ids;
1001 ids.push_back( 23 );
1002 application.GetGlAbstraction().SetNextTextureIds( ids );
1006 BufferImage image = CreateBufferImage( width, height, Color::WHITE );
1008 imageView.SetImage( image );
1010 application.SendNotification();
1011 application.Render();
1013 DALI_TEST_CHECK( gl.GetTextureTrace().FindMethod("BindTexture") );
1015 std::stringstream params;
1016 params << GL_TEXTURE_2D << ", " << 23;
1017 DALI_TEST_CHECK( gl.GetTextureTrace().FindMethodAndParams("BindTexture", params.str()) );
1022 // Scenarios 2: ImageView from Native image
1023 int UtcDaliImageViewSetImageNativeImage(void)
1025 ToolkitTestApplication application;
1027 ImageView imageView = ImageView::New();
1028 Stage::GetCurrent().Add( imageView );
1030 TestGlAbstraction& gl = application.GetGlAbstraction();
1031 gl.EnableTextureCallTrace( true );
1033 std::vector< GLuint > ids;
1034 ids.push_back( 23 );
1035 application.GetGlAbstraction().SetNextTextureIds( ids );
1039 TestNativeImagePointer nativeImageInterface = TestNativeImage::New( width, height );
1040 NativeImage nativeImage = NativeImage::New( *(nativeImageInterface.Get()) );
1042 imageView.SetImage( nativeImage );
1043 application.SendNotification();
1044 application.Render();
1046 DALI_TEST_CHECK( gl.GetTextureTrace().FindMethod("BindTexture") );
1048 std::stringstream params;
1049 params << GL_TEXTURE_EXTERNAL_OES << ", " << 23;
1050 DALI_TEST_CHECK( gl.GetTextureTrace().FindMethodAndParams("BindTexture", params.str()) );
1055 // Scenarios 3: ImageView initially from regular image but then SetImage called with Native image
1056 int UtcDaliImageViewSetImageBufferImageToNativeImage(void)
1058 ToolkitTestApplication application;
1062 BufferImage image = CreateBufferImage( width, height, Color::WHITE );
1064 ImageView imageView = ImageView::New( image );
1065 Stage::GetCurrent().Add( imageView );
1067 TestGlAbstraction& gl = application.GetGlAbstraction();
1068 gl.EnableTextureCallTrace( true );
1070 std::vector< GLuint > ids;
1071 ids.push_back( 23 );
1072 application.GetGlAbstraction().SetNextTextureIds( ids );
1074 application.SendNotification();
1075 application.Render();
1077 DALI_TEST_CHECK( gl.GetTextureTrace().FindMethod("BindTexture") );
1079 std::stringstream params;
1080 params << GL_TEXTURE_2D << ", " << 23;
1081 DALI_TEST_CHECK( gl.GetTextureTrace().FindMethodAndParams("BindTexture", params.str()) );
1085 TestNativeImagePointer nativeImageInterface = TestNativeImage::New( width, height );
1086 NativeImage nativeImage = NativeImage::New( *(nativeImageInterface.Get()) );
1087 imageView.SetImage( nativeImage );
1090 ids.push_back( 24 );
1091 application.GetGlAbstraction().SetNextTextureIds( ids );
1093 application.SendNotification();
1094 application.Render();
1096 DALI_TEST_CHECK( gl.GetTextureTrace().FindMethod("BindTexture") );
1098 std::stringstream nextTextureParams;
1099 nextTextureParams << GL_TEXTURE_EXTERNAL_OES << ", " << 24;
1100 DALI_TEST_CHECK( gl.GetTextureTrace().FindMethodAndParams("BindTexture", nextTextureParams.str()) );
1105 // Scenarios 4: ImageView initially from Native image but then SetImage called with regular image
1106 int UtcDaliImageViewSetImageNativeImageToBufferImage(void)
1108 ToolkitTestApplication application;
1112 TestNativeImagePointer nativeImageInterface = TestNativeImage::New( width, height );
1113 NativeImage nativeImage = NativeImage::New( *(nativeImageInterface.Get()) );
1115 ImageView imageView = ImageView::New( nativeImage );
1116 Stage::GetCurrent().Add( imageView );
1118 TestGlAbstraction& gl = application.GetGlAbstraction();
1119 gl.EnableTextureCallTrace( true );
1121 std::vector< GLuint > ids;
1122 ids.push_back( 23 );
1123 application.GetGlAbstraction().SetNextTextureIds( ids );
1125 application.SendNotification();
1126 application.Render();
1128 DALI_TEST_CHECK( gl.GetTextureTrace().FindMethod("BindTexture") );
1130 std::stringstream params;
1131 params << GL_TEXTURE_EXTERNAL_OES << ", " << 23;
1132 DALI_TEST_CHECK( gl.GetTextureTrace().FindMethodAndParams("BindTexture", params.str()) );
1136 BufferImage image = CreateBufferImage( width, height, Color::WHITE );
1137 imageView.SetImage( image );
1140 ids.push_back( 24 );
1141 application.GetGlAbstraction().SetNextTextureIds( ids );
1143 application.SendNotification();
1144 application.Render();
1146 DALI_TEST_CHECK( gl.GetTextureTrace().FindMethod("BindTexture") );
1148 std::stringstream nextTextureParams;
1149 nextTextureParams << GL_TEXTURE_2D << ", " << 24;
1150 DALI_TEST_CHECK( gl.GetTextureTrace().FindMethodAndParams("BindTexture", nextTextureParams.str()) );
1155 // Scenarios 5: ImageView from Native image with custom shader
1156 int UtcDaliImageViewSetImageNativeImageWithCustomShader(void)
1158 ToolkitTestApplication application;
1163 Property::Map customShader;
1164 customShader.Insert( "vertexShader", VERTEX_SHADER );
1165 customShader.Insert( "fragmentShader", FRAGMENT_SHADER );
1167 Property::Array shaderHints;
1168 shaderHints.PushBack( "requiresSelfDepthTest" );
1169 shaderHints.PushBack( "outputIsTransparent" );
1170 shaderHints.PushBack( "outputIsOpaque" );
1171 shaderHints.PushBack( "modifiesGeometry" );
1173 customShader.Insert( "hints", shaderHints );
1176 map.Insert( "shader", customShader );
1178 TestNativeImagePointer nativeImageInterface = TestNativeImage::New( width, height );
1179 NativeImage nativeImage = NativeImage::New( *(nativeImageInterface.Get()) );
1181 ImageView imageView = ImageView::New( nativeImage );
1182 imageView.SetProperty( ImageView::Property::IMAGE, map );
1183 Stage::GetCurrent().Add( imageView );
1185 TestGlAbstraction& gl = application.GetGlAbstraction();
1186 gl.EnableTextureCallTrace( true );
1188 std::vector< GLuint > ids;
1189 ids.push_back( 23 );
1190 application.GetGlAbstraction().SetNextTextureIds( ids );
1192 application.SendNotification();
1193 application.Render();
1195 DALI_TEST_CHECK( gl.GetTextureTrace().FindMethod("BindTexture") );
1197 std::stringstream params;
1198 params << GL_TEXTURE_EXTERNAL_OES << ", " << 23;
1199 DALI_TEST_CHECK( gl.GetTextureTrace().FindMethodAndParams("BindTexture", params.str()) );
1204 // Scenarios 6: ImageView initially from regular image with custom shader but then SetImage called with Native
1205 int UtcDaliImageViewSetImageBufferImageWithCustomShaderToNativeImage(void)
1207 ToolkitTestApplication application;
1212 Property::Map customShader;
1213 customShader.Insert( "vertexShader", VERTEX_SHADER );
1214 customShader.Insert( "fragmentShader", FRAGMENT_SHADER );
1216 Property::Array shaderHints;
1217 shaderHints.PushBack( "requiresSelfDepthTest" );
1218 shaderHints.PushBack( "outputIsTransparent" );
1219 shaderHints.PushBack( "outputIsOpaque" );
1220 shaderHints.PushBack( "modifiesGeometry" );
1222 customShader.Insert( "hints", shaderHints );
1225 map.Insert( "shader", customShader );
1227 BufferImage image = CreateBufferImage( width, height, Color::WHITE );
1229 ImageView imageView = ImageView::New( image );
1230 imageView.SetProperty( ImageView::Property::IMAGE, map );
1231 Stage::GetCurrent().Add( imageView );
1233 TestGlAbstraction& gl = application.GetGlAbstraction();
1234 gl.EnableTextureCallTrace( true );
1236 std::vector< GLuint > ids;
1237 ids.push_back( 23 );
1238 application.GetGlAbstraction().SetNextTextureIds( ids );
1240 application.SendNotification();
1241 application.Render();
1243 DALI_TEST_CHECK( gl.GetTextureTrace().FindMethod("BindTexture") );
1245 std::stringstream params;
1246 params << GL_TEXTURE_2D << ", " << 23;
1247 DALI_TEST_CHECK( gl.GetTextureTrace().FindMethodAndParams("BindTexture", params.str()) );
1249 TestNativeImagePointer nativeImageInterface = TestNativeImage::New( width, height );
1250 NativeImage nativeImage = NativeImage::New( *(nativeImageInterface.Get()) );
1251 imageView.SetImage( nativeImage );
1254 ids.push_back( 24 );
1255 application.GetGlAbstraction().SetNextTextureIds( ids );
1257 application.SendNotification();
1258 application.Render();
1260 DALI_TEST_CHECK( gl.GetTextureTrace().FindMethod("BindTexture") );
1262 std::stringstream nativeImageParams;
1263 nativeImageParams << GL_TEXTURE_EXTERNAL_OES << ", " << 24;
1264 DALI_TEST_CHECK( gl.GetTextureTrace().FindMethodAndParams("BindTexture", nativeImageParams.str()) );
1270 int UtcDaliImageViewGetImageP1(void)
1272 ToolkitTestApplication application;
1274 ImageView imageView = ImageView::New();
1275 DALI_TEST_CHECK( ! imageView.GetImage() );
1277 Image image = CreateBufferImage();
1278 imageView.SetImage( image );
1279 DALI_TEST_CHECK( imageView.GetImage() == image );
1284 int UtcDaliImageViewGetImageP2(void)
1286 ToolkitTestApplication application;
1288 BufferImage image = CreateBufferImage();
1289 ImageView imageView = ImageView::New( image );
1290 DALI_TEST_CHECK( imageView.GetImage() == image );
1295 int UtcDaliImageViewGetImageN(void)
1297 ToolkitTestApplication application;
1299 ImageView imageView = ImageView::New( TEST_IMAGE_FILE_NAME );
1300 DALI_TEST_CHECK( ! imageView.GetImage() );
1302 Image image = CreateBufferImage();
1303 imageView.SetImage( image );
1304 DALI_TEST_CHECK( imageView.GetImage() == image );
1306 imageView.SetImage( TEST_IMAGE_FILE_NAME );
1307 DALI_TEST_CHECK( ! imageView.GetImage() );
1313 int UtcDaliImageViewReplaceImage(void)
1315 ToolkitTestApplication application;
1317 gResourceReadySignalFired = false;
1321 Image image = CreateBufferImage( width, height, Vector4(1.f, 1.f, 1.f, 1.f) );
1323 // Check ImageView with background and main image, to ensure both visuals are marked as loaded
1324 ImageView imageView = ImageView::New( TEST_IMAGE_1 );
1326 DALI_TEST_EQUALS( Toolkit::DevelControl::IsResourceReady( imageView ), false, TEST_LOCATION );
1328 Toolkit::DevelControl::ResourceReadySignal( imageView ).Connect( &ResourceReadySignal);
1330 Stage::GetCurrent().Add( imageView );
1332 application.SendNotification();
1333 application.Render(16);
1335 // loading started, this waits for the loader thread for max 30 seconds
1336 DALI_TEST_EQUALS( Test::WaitForEventThreadTrigger( 1 ), true, TEST_LOCATION );
1338 DALI_TEST_EQUALS( imageView.GetRendererCount(), 1u, TEST_LOCATION );
1340 DALI_TEST_EQUALS( gResourceReadySignalFired, true, TEST_LOCATION );
1342 gResourceReadySignalFired = false;
1344 imageView.SetImage(TEST_IMAGE_2);
1346 application.SendNotification();
1347 application.Render(16);
1349 // loading started, this waits for the loader thread for max 30 seconds
1350 DALI_TEST_EQUALS( Test::WaitForEventThreadTrigger( 1 ), true, TEST_LOCATION );
1352 DALI_TEST_EQUALS( imageView.GetRendererCount(), 1u, TEST_LOCATION );
1354 DALI_TEST_EQUALS( Toolkit::DevelControl::IsResourceReady( imageView ), true, TEST_LOCATION );
1356 DALI_TEST_EQUALS( gResourceReadySignalFired, true, TEST_LOCATION );
1361 void OnRelayoutOverride( Size size )
1363 gNaturalSize = size; // Size Relayout is using
1366 int UtcDaliImageViewReplaceImageAndGetNaturalSize(void)
1368 ToolkitTestApplication application;
1370 // Check ImageView with background and main image, to ensure both visuals are marked as loaded
1371 ImageView imageView = ImageView::New( TEST_IMAGE_1 );
1372 imageView.SetResizePolicy( ResizePolicy::USE_NATURAL_SIZE, Dimension::ALL_DIMENSIONS );
1374 DummyControl dummyControl = DummyControl::New( true );
1375 Impl::DummyControl& dummyImpl = static_cast<Impl::DummyControl&>(dummyControl.GetImplementation());
1376 dummyControl.SetResizePolicy( ResizePolicy::FIT_TO_CHILDREN, Dimension::ALL_DIMENSIONS );
1378 dummyControl.Add( imageView );
1379 dummyImpl.SetRelayoutCallback( &OnRelayoutOverride );
1380 Stage::GetCurrent().Add( dummyControl );
1382 application.SendNotification();
1383 application.Render();
1385 // loading started, this waits for the loader thread for max 30 seconds
1386 DALI_TEST_EQUALS( Test::WaitForEventThreadTrigger( 1 ), true, TEST_LOCATION );
1388 DALI_TEST_EQUALS( gNaturalSize.width, 1024.0f, TEST_LOCATION );
1389 DALI_TEST_EQUALS( gNaturalSize.height, 1024.0f, TEST_LOCATION );
1391 gNaturalSize = Vector3::ZERO;
1393 imageView.SetImage(gImage_600_RGB);
1395 // Waiting for resourceReady so SendNotifcation not called here.
1397 // loading started, this waits for the loader thread for max 30 seconds
1398 DALI_TEST_EQUALS( Test::WaitForEventThreadTrigger( 1 ), true, TEST_LOCATION );
1400 // Trigger a potential relayout
1401 application.SendNotification();
1402 application.Render();
1404 DALI_TEST_EQUALS( gNaturalSize.width, 600.0f, TEST_LOCATION );
1405 DALI_TEST_EQUALS( gNaturalSize.height, 600.0f, TEST_LOCATION );