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>
34 using namespace Toolkit;
36 void utc_dali_toolkit_image_view_startup(void)
38 test_return_value = TET_UNDEF;
41 void utc_dali_toolkit_image_view_cleanup(void)
43 test_return_value = TET_PASS;
49 const char* VERTEX_SHADER = DALI_COMPOSE_SHADER(
50 attribute mediump vec2 aPosition;\n
51 varying mediump vec2 vTexCoord;\n
52 uniform mediump mat4 uMvpMatrix;\n
53 uniform mediump vec3 uSize;\n
57 mediump vec4 vertexPosition = vec4(aPosition, 0.0, 1.0);\n
58 vertexPosition.xyz *= uSize;\n
59 vertexPosition = uMvpMatrix * vertexPosition;\n
61 vTexCoord = aPosition + vec2(0.5);\n
62 gl_Position = vertexPosition;\n
66 const char* FRAGMENT_SHADER = DALI_COMPOSE_SHADER(
67 varying mediump vec2 vTexCoord;\n
68 uniform sampler2D sTexture;\n
69 uniform lowp vec4 uColor;\n
73 gl_FragColor = texture2D( sTexture, vTexCoord ) * uColor;\n
77 const char* TEST_IMAGE_FILE_NAME = "gallery_image_01.jpg";
78 const char* TEST_IMAGE_FILE_NAME2 = "gallery_image_02.jpg";
80 const char* TEST_IMAGE_1 = TEST_RESOURCE_DIR "/TB-gloss.png";
81 const char* TEST_IMAGE_2 = TEST_RESOURCE_DIR "/tb-norm.png";
83 // resolution: 34*34, pixel format: RGBA8888
84 static const char* gImage_34_RGBA = TEST_RESOURCE_DIR "/icon-edit.png";
85 // resolution: 600*600, pixel format: RGB888
86 static const char* gImage_600_RGB = TEST_RESOURCE_DIR "/test-image-600.jpg";
88 // resolution: 50*50, frame count: 4, frame delay: 0.2 second for each frame
89 const char* TEST_GIF_FILE_NAME = TEST_RESOURCE_DIR "/anim.gif";
91 void TestImage( ImageView imageView, BufferImage image )
93 Property::Value value = imageView.GetProperty( imageView.GetPropertyIndex( "image" ) );
96 DALI_TEST_CHECK( value.Get( map ) );
98 DALI_TEST_CHECK( map.Find( "width" ) );
99 DALI_TEST_CHECK( map.Find( "height" ) );
100 DALI_TEST_CHECK( map.Find( "type" ) );
103 DALI_TEST_CHECK( map[ "width" ].Get( width ) );
104 DALI_TEST_EQUALS( (unsigned int)width, image.GetWidth(), TEST_LOCATION );
107 DALI_TEST_CHECK( map[ "height" ].Get( height ) );
108 DALI_TEST_EQUALS( (unsigned int)height, image.GetHeight(), TEST_LOCATION );
111 DALI_TEST_CHECK( map[ "type" ].Get( type ) );
112 DALI_TEST_EQUALS( type, "BufferImage", TEST_LOCATION );
115 void TestImage( ImageView imageView, ResourceImage image )
117 Property::Value value = imageView.GetProperty( imageView.GetPropertyIndex( "image" ) );
120 DALI_TEST_CHECK( value.Get( map ) );
122 if( map.Find( "width" ) )
125 DALI_TEST_CHECK( map[ "width" ].Get( width ) );
126 DALI_TEST_EQUALS( (unsigned int)width, image.GetWidth(), TEST_LOCATION );
129 if( map.Find( "height" ) )
132 DALI_TEST_CHECK( map[ "height" ].Get( height ) );
133 DALI_TEST_EQUALS( (unsigned int)height, image.GetHeight(), TEST_LOCATION );
136 DALI_TEST_CHECK( map.Find( "type" ) );
139 DALI_TEST_CHECK( map[ "type" ].Get( type ) );
140 DALI_TEST_EQUALS( type, "ResourceImage", TEST_LOCATION );
142 std::string filename;
143 DALI_TEST_CHECK( map[ "filename" ].Get( filename ) );
144 DALI_TEST_EQUALS( filename, image.GetUrl(), TEST_LOCATION );
147 void TestUrl( ImageView imageView, const std::string url )
149 Property::Value value = imageView.GetProperty( imageView.GetPropertyIndex( "image" ) );
151 std::string urlActual;
152 DALI_TEST_CHECK( value.Get( urlActual ) );
153 DALI_TEST_EQUALS( urlActual, url, TEST_LOCATION );
158 int UtcDaliImageViewNewP(void)
160 TestApplication application;
162 ImageView imageView = ImageView::New();
164 DALI_TEST_CHECK( imageView );
169 int UtcDaliImageViewNewImageP(void)
171 TestApplication application;
173 BufferImage image = CreateBufferImage( 100, 200, Vector4( 1.f, 1.f, 1.f, 1.f ) );
174 ImageView imageView = ImageView::New( image );
176 DALI_TEST_CHECK( imageView );
177 TestImage( imageView, image );
182 int UtcDaliImageViewNewUrlP(void)
184 TestApplication application;
186 ImageView imageView = ImageView::New( TEST_IMAGE_FILE_NAME );
187 DALI_TEST_CHECK( imageView );
189 TestUrl( imageView, TEST_IMAGE_FILE_NAME );
194 int UtcDaliImageViewConstructorP(void)
196 TestApplication application;
200 DALI_TEST_CHECK( !imageView );
205 int UtcDaliImageViewCopyConstructorP(void)
207 TestApplication application;
209 // Initialize an object, ref count == 1
210 ImageView imageView = ImageView::New();
212 ImageView copy( imageView );
213 DALI_TEST_CHECK( copy );
218 int UtcDaliImageViewAssignmentOperatorP(void)
220 TestApplication application;
222 ImageView imageView = ImageView::New();
224 ImageView copy( imageView );
225 DALI_TEST_CHECK( copy );
226 DALI_TEST_EQUALS( imageView, copy, TEST_LOCATION );
231 int UtcDaliImageViewDownCastP(void)
233 TestApplication application;
235 ImageView imageView = ImageView::New();
237 BaseHandle object(imageView);
239 ImageView imageView2 = ImageView::DownCast( object );
240 DALI_TEST_CHECK(imageView2);
242 ImageView imageView3 = DownCast< ImageView >( object );
243 DALI_TEST_CHECK(imageView3);
248 int UtcDaliImageViewDownCastN(void)
250 TestApplication application;
252 BaseHandle unInitializedObject;
254 ImageView imageView1 = ImageView::DownCast( unInitializedObject );
255 DALI_TEST_CHECK( !imageView1 );
257 ImageView imageView2 = DownCast< ImageView >( unInitializedObject );
258 DALI_TEST_CHECK( !imageView2 );
263 int UtcDaliImageViewTypeRegistry(void)
265 ToolkitTestApplication application;
267 TypeRegistry typeRegistry = TypeRegistry::Get();
268 DALI_TEST_CHECK( typeRegistry );
270 TypeInfo typeInfo = typeRegistry.GetTypeInfo( "ImageView" );
271 DALI_TEST_CHECK( typeInfo );
273 BaseHandle handle = typeInfo.CreateInstance();
274 DALI_TEST_CHECK( handle );
276 ImageView imageView = ImageView::DownCast( handle );
277 DALI_TEST_CHECK( imageView );
282 int UtcDaliImageViewSetGetProperty01(void)
284 ToolkitTestApplication application;
286 ImageView imageView = ImageView::New();
288 Property::Index idx = imageView.GetPropertyIndex( "image" );
289 DALI_TEST_EQUALS( idx, (Property::Index)ImageView::Property::IMAGE, TEST_LOCATION );
291 imageView.SetProperty( idx, TEST_IMAGE_FILE_NAME );
292 TestUrl( imageView, TEST_IMAGE_FILE_NAME );
297 int UtcDaliImageViewSetGetProperty02(void)
299 ToolkitTestApplication application;
301 Image image = CreateBufferImage( 10, 10, Color::WHITE );
302 ImageView imageView = ImageView::New(image);
303 Vector4 fullImageRect( 0.f, 0.f, 1.f, 1.f );
305 Stage::GetCurrent().Add( imageView );
307 application.SendNotification();
308 application.Render();
309 TestGlAbstraction& gl = application.GetGlAbstraction();
311 Vector4 pixelAreaUniform;
312 DALI_TEST_CHECK( gl.GetUniformValue<Vector4>( "pixelArea", pixelAreaUniform ) );
313 DALI_TEST_EQUALS( pixelAreaUniform, fullImageRect, TEST_LOCATION );
315 Property::Value value = imageView.GetProperty( ImageView::Property::PIXEL_AREA );
316 Vector4 pixelAreaValue;
317 DALI_TEST_CHECK( value.Get(pixelAreaValue) );
318 DALI_TEST_EQUALS( pixelAreaValue, fullImageRect, TEST_LOCATION );
320 Vector4 pixelAreaSet( 0.2f, 0.2f, 0.3f, 0.3f );
321 imageView.SetProperty( ImageView::Property::PIXEL_AREA, pixelAreaSet);
323 application.SendNotification();
324 application.Render();
326 value = imageView.GetProperty( ImageView::Property::PIXEL_AREA );
327 value.Get(pixelAreaValue);
328 DALI_TEST_EQUALS( pixelAreaValue, pixelAreaSet, TEST_LOCATION );
330 DALI_TEST_CHECK( gl.GetUniformValue<Vector4>( "pixelArea", pixelAreaUniform ) );
331 DALI_TEST_EQUALS( pixelAreaUniform, pixelAreaSet, TEST_LOCATION );
336 int UtcDaliImageViewSetGetProperty03(void)
338 ToolkitTestApplication application;
340 Image image = CreateBufferImage( 10, 10, Color::WHITE );
341 ImageView imageView = ImageView::New(image);
342 Stage::GetCurrent().Add( imageView );
343 application.SendNotification();
344 application.Render();
346 // conventional alpha blending
347 Renderer renderer = imageView.GetRendererAt( 0 );
348 Property::Value value = renderer.GetProperty( Renderer::Property::BLEND_PRE_MULTIPLIED_ALPHA );
350 DALI_TEST_CHECK( value.Get( enable ) );
351 DALI_TEST_CHECK( !enable );
353 // pre-multiplied alpha blending
354 imageView.SetProperty( Toolkit::ImageView::Property::PRE_MULTIPLIED_ALPHA, true );
355 application.SendNotification();
356 application.Render();
358 int srcFactorRgb = renderer.GetProperty<int>( Renderer::Property::BLEND_FACTOR_SRC_RGB );
359 int destFactorRgb = renderer.GetProperty<int>( Renderer::Property::BLEND_FACTOR_DEST_RGB );
360 int srcFactorAlpha = renderer.GetProperty<int>( Renderer::Property::BLEND_FACTOR_SRC_ALPHA );
361 int destFactorAlpha = renderer.GetProperty<int>( Renderer::Property::BLEND_FACTOR_DEST_ALPHA );
362 DALI_TEST_CHECK( srcFactorRgb == BlendFactor::ONE );
363 DALI_TEST_CHECK( destFactorRgb == BlendFactor::ONE_MINUS_SRC_ALPHA );
364 DALI_TEST_CHECK( srcFactorAlpha == BlendFactor::ONE );
365 DALI_TEST_CHECK( destFactorAlpha == BlendFactor::ONE );
367 value = renderer.GetProperty( Renderer::Property::BLEND_PRE_MULTIPLIED_ALPHA );
368 DALI_TEST_CHECK( value.Get( enable ) );
369 DALI_TEST_CHECK( enable );
374 int UtcDaliImageViewPixelArea(void)
376 // Test pixel area property
377 ToolkitTestApplication application;
379 // Gif image, use AnimatedImageVisual internally
380 // Atlasing is applied to pack multiple frames, use custom wrap mode
381 ImageView gifView = ImageView::New();
382 const Vector4 pixelAreaVisual( 0.f, 0.f, 2.f, 2.f );
383 gifView.SetProperty( ImageView::Property::IMAGE,
384 Property::Map().Add( ImageVisual::Property::URL, TEST_GIF_FILE_NAME )
385 .Add( ImageVisual::Property::PIXEL_AREA, pixelAreaVisual ) );
388 Stage stage = Stage::GetCurrent();
389 stage.Add( gifView );
392 application.SendNotification();
393 application.Render(16);
394 DALI_TEST_CHECK( gifView.GetRendererCount() == 1u );
396 const Vector4 fullTextureRect( 0.f, 0.f, 1.f, 1.f );
397 // test that the pixel area value defined in the visual property map is registered on renderer
398 Renderer renderer = gifView.GetRendererAt(0);
399 Property::Value pixelAreaValue = renderer.GetProperty( renderer.GetPropertyIndex( "pixelArea" ) );
400 DALI_TEST_EQUALS( pixelAreaValue.Get<Vector4>(), pixelAreaVisual, TEST_LOCATION );
402 // test that the shader has the default pixel area value registered.
403 Shader shader = renderer.GetShader();
404 pixelAreaValue = shader.GetProperty( shader.GetPropertyIndex( "pixelArea" ) );
405 DALI_TEST_EQUALS( pixelAreaValue.Get<Vector4>(), fullTextureRect, TEST_LOCATION );
407 // test that the uniform uses the pixelArea property on the renderer.
408 TestGlAbstraction& gl = application.GetGlAbstraction();
409 Vector4 pixelAreaUniform;
410 DALI_TEST_CHECK( gl.GetUniformValue<Vector4>( "pixelArea", pixelAreaUniform ) );
411 DALI_TEST_EQUALS( pixelAreaVisual, pixelAreaUniform, Math::MACHINE_EPSILON_100, TEST_LOCATION );
413 // set the pixelArea property on the control
414 const Vector4 pixelAreaControl( -1.f, -1.f, 3.f, 3.f );
415 gifView.SetProperty( ImageView::Property::PIXEL_AREA, pixelAreaControl );
416 application.SendNotification();
417 application.Render(16);
419 // check the pixelArea property on the control
420 pixelAreaValue = gifView.GetProperty( gifView.GetPropertyIndex( "pixelArea" ) );
421 DALI_TEST_EQUALS( pixelAreaValue.Get<Vector4>(), pixelAreaControl, TEST_LOCATION );
422 // test that the uniform uses the pixelArea property on the control.
423 DALI_TEST_CHECK( gl.GetUniformValue<Vector4>( "pixelArea", pixelAreaUniform ) );
424 DALI_TEST_EQUALS( pixelAreaControl, pixelAreaUniform, Math::MACHINE_EPSILON_100, TEST_LOCATION );
430 int UtcDaliImageViewAsyncLoadingWithoutAltasing(void)
432 ToolkitTestApplication application;
433 TestGlAbstraction& gl = application.GetGlAbstraction();
434 const std::vector<GLuint>& textures = gl.GetBoundTextures();
435 size_t numTextures = textures.size();
437 // Async loading, no atlasing for big size image
438 ImageView imageView = ImageView::New( gImage_600_RGB );
440 // By default, Aysnc loading is used
441 Stage::GetCurrent().Add( imageView );
442 imageView.SetSize(100, 100);
443 imageView.SetParentOrigin( ParentOrigin::CENTER );
445 DALI_TEST_EQUALS( Test::WaitForEventThreadTrigger( 1 ), true, TEST_LOCATION );
447 application.SendNotification();
448 application.Render(16);
449 application.SendNotification();
451 const std::vector<GLuint>& textures2 = gl.GetBoundTextures();
452 DALI_TEST_GREATER( textures2.size(), numTextures, TEST_LOCATION );
459 int UtcDaliImageViewAsyncLoadingWithAtlasing(void)
461 ToolkitTestApplication application;
463 //Async loading, automatic atlasing for small size image
464 TraceCallStack& callStack = application.GetGlAbstraction().GetTextureTrace();
466 callStack.Enable(true);
468 Property::Map imageMap;
470 imageMap[ ImageVisual::Property::URL ] = gImage_34_RGBA;
471 imageMap[ ImageVisual::Property::DESIRED_HEIGHT ] = 34;
472 imageMap[ ImageVisual::Property::DESIRED_WIDTH ] = 34;
473 imageMap[ DevelImageVisual::Property::ATLASING] = true;
475 ImageView imageView = ImageView::New();
476 imageView.SetProperty( ImageView::Property::IMAGE, imageMap );
478 // By default, Aysnc loading is used
479 // loading is not started if the actor is offStage
481 Stage::GetCurrent().Add( imageView );
482 application.SendNotification();
483 application.Render(16);
484 application.Render(16);
485 application.SendNotification();
487 // loading started, this waits for the loader thread for max 30 seconds
488 DALI_TEST_EQUALS( Test::WaitForEventThreadTrigger( 1 ), true, TEST_LOCATION );
490 application.SendNotification();
491 application.Render(16);
493 callStack.Enable(false);
495 TraceCallStack::NamedParams params;
496 params["width"] = ToString(34);
497 params["height"] = ToString(34);
498 DALI_TEST_EQUALS( callStack.FindMethodAndParams( "TexSubImage2D", params ), true, TEST_LOCATION );
503 int UtcDaliImageViewAsyncLoadingWithAtlasing02(void)
505 ToolkitTestApplication application;
507 //Async loading, automatic atlasing for small size image
508 TraceCallStack& callStack = application.GetGlAbstraction().GetTextureTrace();
510 callStack.Enable(true);
512 Property::Map asyncLoadingMap;
513 asyncLoadingMap[ "url" ] = gImage_34_RGBA;
514 asyncLoadingMap[ "desiredHeight" ] = 34;
515 asyncLoadingMap[ "desiredWidth" ] = 34;
516 asyncLoadingMap[ "synchronousLoading" ] = false;
517 asyncLoadingMap[ "atlasing" ] = true;
519 ImageView imageView = ImageView::New();
520 imageView.SetProperty( ImageView::Property::IMAGE, asyncLoadingMap );
522 Stage::GetCurrent().Add( imageView );
523 application.SendNotification();
524 application.Render(16);
525 application.Render(16);
526 application.SendNotification();
528 // loading started, this waits for the loader thread for max 30 seconds
529 DALI_TEST_EQUALS( Test::WaitForEventThreadTrigger( 1 ), true, TEST_LOCATION );
531 application.SendNotification();
532 application.Render(16);
534 callStack.Enable(false);
536 TraceCallStack::NamedParams params;
537 params["width"] = ToString(34);
538 params["height"] = ToString(34);
539 DALI_TEST_EQUALS( callStack.FindMethodAndParams( "TexSubImage2D", params ), true, TEST_LOCATION );
544 int UtcDaliImageViewSyncLoading(void)
546 ToolkitTestApplication application;
548 tet_infoline("ImageView Testing sync loading and size using index key property map");
550 Property::Map syncLoadingMap;
551 syncLoadingMap[ ImageVisual::Property::SYNCHRONOUS_LOADING ] = true;
552 syncLoadingMap[ DevelImageVisual::Property::ATLASING ] = true;
554 // Sync loading, no atlasing for big size image
556 ImageView imageView = ImageView::New();
558 // Sync loading is used
559 syncLoadingMap[ ImageVisual::Property::URL ] = gImage_600_RGB;
560 imageView.SetProperty( ImageView::Property::IMAGE, syncLoadingMap );
563 // Sync loading, automatic atlasing for small size image
565 TraceCallStack& callStack = application.GetGlAbstraction().GetTextureTrace();
567 callStack.Enable(true);
569 ImageView imageView = ImageView::New( );
571 // Sync loading is used
572 syncLoadingMap[ ImageVisual::Property::URL ] = gImage_34_RGBA;
573 syncLoadingMap[ ImageVisual::Property::DESIRED_HEIGHT ] = 34;
574 syncLoadingMap[ ImageVisual::Property::DESIRED_WIDTH ] = 34;
575 imageView.SetProperty( ImageView::Property::IMAGE, syncLoadingMap );
577 Stage::GetCurrent().Add( imageView );
578 application.SendNotification();
579 application.Render(16);
581 TraceCallStack::NamedParams params;
582 params["width"] = ToString(34);
583 params["height"] = ToString(34);
584 DALI_TEST_EQUALS( callStack.FindMethodAndParams( "TexSubImage2D", params ),
585 true, TEST_LOCATION );
591 int UtcDaliImageViewSyncLoading02(void)
593 ToolkitTestApplication application;
595 tet_infoline("ImageView Testing sync loading and size using string key property map");
597 // Sync loading, automatic atlasing for small size image
599 TraceCallStack& callStack = application.GetGlAbstraction().GetTextureTrace();
601 callStack.Enable(true);
603 ImageView imageView = ImageView::New( );
605 // Sync loading is used
606 Property::Map syncLoadingMap;
607 syncLoadingMap[ "url" ] = gImage_34_RGBA;
608 syncLoadingMap[ "desiredHeight" ] = 34;
609 syncLoadingMap[ "desiredWidth" ] = 34;
610 syncLoadingMap[ "synchronousLoading" ] = true;
611 syncLoadingMap[ "atlasing" ] = true;
612 imageView.SetProperty( ImageView::Property::IMAGE, syncLoadingMap );
614 Stage::GetCurrent().Add( imageView );
615 application.SendNotification();
616 application.Render(16);
618 TraceCallStack::NamedParams params;
619 params["width"] = ToString(34);
620 params["height"] = ToString(34);
621 DALI_TEST_EQUALS( callStack.FindMethodAndParams( "TexSubImage2D", params ),
622 true, TEST_LOCATION );
627 int UtcDaliImageViewSizeWithBackground(void)
629 ToolkitTestApplication application;
633 Image image = CreateBufferImage( width, height, Vector4(1.f, 1.f, 1.f, 1.f) );
634 ImageView imageView = ImageView::New();
635 imageView.SetBackgroundImage( image );
637 Stage::GetCurrent().Add( imageView );
638 application.SendNotification();
639 application.Render();
641 DALI_TEST_EQUALS( imageView.GetCurrentSize().width, (float)width, TEST_LOCATION );
642 DALI_TEST_EQUALS( imageView.GetCurrentSize().height, (float)height, TEST_LOCATION );
647 int UtcDaliImageViewSizeWithBackgroundAndImage(void)
649 ToolkitTestApplication application;
651 int widthBackground = 100;
652 int heightBackground = 200;
655 Image imageBackground = CreateBufferImage( widthBackground, heightBackground, Vector4(1.f, 1.f, 1.f, 1.f) );
656 Image image = CreateBufferImage( width, height, Vector4(1.f, 1.f, 1.f, 1.f) );
658 ImageView imageView = ImageView::New();
659 imageView.SetBackgroundImage( imageBackground );
660 imageView.SetImage( image );
662 Stage::GetCurrent().Add( imageView );
663 application.SendNotification();
664 application.Render();
666 DALI_TEST_EQUALS( imageView.GetCurrentSize().width, (float)width, TEST_LOCATION );
667 DALI_TEST_EQUALS( imageView.GetCurrentSize().height, (float)height, TEST_LOCATION );
672 int UtcDaliImageViewHeightForWidthBackground(void)
674 ToolkitTestApplication application;
676 int widthBackground = 100;
677 int heightBackground = 200;
678 Image imageBackground = CreateBufferImage( widthBackground, heightBackground, Vector4(1.f, 1.f, 1.f, 1.f) );
680 ImageView imageView = ImageView::New();
681 imageView.SetBackgroundImage( imageBackground );
683 Stage::GetCurrent().Add( imageView );
684 application.SendNotification();
685 application.Render();
687 Control control = Control::DownCast( imageView );
688 DALI_TEST_CHECK( control );
689 DALI_TEST_EQUALS( imageView.GetHeightForWidth( 123.f ), control.GetHeightForWidth( 123.f ), TEST_LOCATION );
690 DALI_TEST_EQUALS( imageView.GetWidthForHeight( 321.f ), control.GetWidthForHeight( 321.f ), TEST_LOCATION );
695 int UtcDaliImageViewHeightForWidthBackgroundAndImage(void)
697 ToolkitTestApplication application;
699 int widthBackground = 100;
700 int heightBackground = 200;
703 Image imageBackground = CreateBufferImage( widthBackground, heightBackground, Vector4(1.f, 1.f, 1.f, 1.f) );
704 Image image = CreateBufferImage( width, height, Vector4(1.f, 1.f, 1.f, 1.f) );
706 ImageView imageView = ImageView::New();
707 imageView.SetBackgroundImage( imageBackground );
708 imageView.SetImage( image );
710 Stage::GetCurrent().Add( imageView );
711 application.SendNotification();
712 application.Render();
714 DALI_TEST_EQUALS( imageView.GetHeightForWidth( width ), (float)height, TEST_LOCATION );
715 DALI_TEST_EQUALS( imageView.GetWidthForHeight( height ), (float)width, TEST_LOCATION );
720 int UtcDaliImageViewSetBufferImage(void)
722 ToolkitTestApplication application;
726 BufferImage image1 = CreateBufferImage( width1, height1, Vector4( 1.f, 1.f, 1.f, 1.f ) );
727 ImageView imageView = ImageView::New();
728 imageView.SetImage( image1 );
730 TestImage( imageView, image1 );
734 BufferImage image2 = CreateBufferImage( width2, height2, Vector4( 1.f, 1.f, 1.f, 1.f ) );
735 imageView.SetImage( image2 );
737 TestImage( imageView, image2 );
742 int UtcDaliImageViewSetImageUrl(void)
744 ToolkitTestApplication application;
746 ImageView imageView = ImageView::New();
747 imageView.SetImage( TEST_IMAGE_FILE_NAME );
748 TestUrl( imageView, TEST_IMAGE_FILE_NAME );
751 imageView.SetImage( TEST_IMAGE_FILE_NAME2 );
752 TestUrl( imageView, TEST_IMAGE_FILE_NAME2 );
757 int UtcDaliImageViewSetImageOnstageP(void)
759 ToolkitTestApplication application;
761 ImageView imageView = ImageView::New();
763 Stage::GetCurrent().Add( imageView );
764 application.SendNotification();
765 application.Render();
767 ResourceImage image1 = ResourceImage::New( TEST_IMAGE_FILE_NAME );
768 imageView.SetImage( image1 );
769 TestImage( imageView, image1 );
773 BufferImage image2 = CreateBufferImage( width, height, Vector4( 1.f, 1.f, 1.f, 1.f ) );
774 imageView.SetImage( image2 );
775 TestImage( imageView, image2 );
780 int UtcDaliImageViewSetImageOnstageN(void)
782 ToolkitTestApplication application;
784 ImageView imageView = ImageView::New();
786 Stage::GetCurrent().Add( imageView );
787 application.SendNotification();
788 application.Render();
790 ResourceImage image1 = ResourceImage::New( TEST_IMAGE_FILE_NAME );
791 imageView.SetImage( image1 );
792 TestImage( imageView, image1 );
795 imageView.SetImage( image2 );
797 Property::Value value = imageView.GetProperty( imageView.GetPropertyIndex( "image" ) );
799 //the value should be empty
801 DALI_TEST_CHECK( !value.Get( url ) );
804 DALI_TEST_CHECK( !value.Get( map ) );
809 int UtcDaliImageViewSetImageOffstageP(void)
811 ToolkitTestApplication application;
813 ImageView imageView = ImageView::New();
815 Stage::GetCurrent().Add( imageView );
816 application.SendNotification();
817 application.Render();
818 Stage::GetCurrent().Remove( imageView );
820 ResourceImage image1 = ResourceImage::New( TEST_IMAGE_FILE_NAME );
821 imageView.SetImage( image1 );
822 TestImage( imageView, image1 );
826 BufferImage image2 = CreateBufferImage( width, height, Vector4( 1.f, 1.f, 1.f, 1.f ) );
827 imageView.SetImage( image2 );
828 TestImage( imageView, image2 );
833 bool gResourceReadySignalFired = false;
835 void ResourceReadySignal( Control control )
837 gResourceReadySignalFired = true;
840 int UtcDaliImageViewCheckResourceReady(void)
842 ToolkitTestApplication application;
844 gResourceReadySignalFired = false;
849 Image image = CreateBufferImage( width, height, Vector4(1.f, 1.f, 1.f, 1.f) );
851 // Check ImageView with background and main image, to ensure both visuals are marked as loaded
852 ImageView imageView = ImageView::New( TEST_GIF_FILE_NAME );
854 imageView.SetBackgroundImage( image );
856 DALI_TEST_EQUALS( Toolkit::DevelControl::IsResourceReady( imageView ), false, TEST_LOCATION );
858 Toolkit::DevelControl::ResourceReadySignal( imageView ).Connect( &ResourceReadySignal);
860 Stage::GetCurrent().Add( imageView );
862 application.SendNotification();
863 application.Render(16);
866 DALI_TEST_EQUALS( Toolkit::DevelControl::IsResourceReady( imageView ), true, TEST_LOCATION );
868 DALI_TEST_EQUALS( gResourceReadySignalFired, true, TEST_LOCATION );
873 int UtcDaliImageViewSetImageOffstageN(void)
875 ToolkitTestApplication application;
877 ImageView imageView = ImageView::New();
879 Stage::GetCurrent().Add( imageView );
880 application.SendNotification();
881 application.Render();
882 Stage::GetCurrent().Remove( imageView );
884 ResourceImage image1 = ResourceImage::New( TEST_IMAGE_FILE_NAME );
885 imageView.SetImage( image1 );
886 TestImage( imageView, image1 );
889 imageView.SetImage( image2 );
891 Property::Value value = imageView.GetProperty( imageView.GetPropertyIndex( "image" ) );
893 //the value should be empty
895 DALI_TEST_CHECK( !value.Get( url ) );
898 DALI_TEST_CHECK( !value.Get( map ) );
903 int UtcDaliImageViewSetImageN(void)
905 ToolkitTestApplication application;
908 ImageView imageView = ImageView::New();
909 imageView.SetImage( image1 );
911 Property::Value value = imageView.GetProperty( imageView.GetPropertyIndex( "image" ) );
913 //the value should be empty
915 DALI_TEST_CHECK( !value.Get( url ) );
918 DALI_TEST_CHECK( !value.Get( map ) );
920 std::string resource_url;
921 Property::Value val = imageView.GetProperty( imageView.GetPropertyIndex( "image" ) );
922 DALI_TEST_CHECK( !val.Get( resource_url ) );
927 int UtcDaliImageViewSetImageTypeChangesP(void)
929 ToolkitTestApplication application;
931 ImageView imageView = ImageView::New();
937 Property::Value value = imageView.GetProperty( imageView.GetPropertyIndex( "image" ) );
938 DALI_TEST_CHECK( ! value.Get( url ) ); // Value should be empty
939 DALI_TEST_CHECK( ! value.Get( map ) ); // Value should be empty
942 imageView.SetImage( "TEST_URL" );
943 value = imageView.GetProperty( imageView.GetPropertyIndex( "image" ) );
945 DALI_TEST_CHECK( value.Get( url ) ); // Value should NOT be empty
946 DALI_TEST_CHECK( ! value.Get( map ) ); // Value should be empty
948 // Set an empty Image
949 imageView.SetImage( Image() );
950 value = imageView.GetProperty( imageView.GetPropertyIndex( "image" ) );
952 DALI_TEST_CHECK( ! value.Get( url ) ); // Value should be empty
953 DALI_TEST_CHECK( ! value.Get( map ) ); // Value should be empty
956 ResourceImage image1 = ResourceImage::New( TEST_IMAGE_FILE_NAME );
957 imageView.SetImage( image1 );
958 value = imageView.GetProperty( imageView.GetPropertyIndex( "image" ) );
960 DALI_TEST_CHECK( ! value.Get( url ) ); // Value should be empty
961 DALI_TEST_CHECK( value.Get( map ) ); // Value should NOT be empty
964 imageView.SetImage( "" );
965 value = imageView.GetProperty( imageView.GetPropertyIndex( "image" ) );
967 DALI_TEST_CHECK( ! value.Get( url ) ); // Value should be empty
968 DALI_TEST_CHECK( ! value.Get( map ) ); // Value should be empty
973 int UtcDaliImageViewResourceUrlP(void)
975 ToolkitTestApplication application;
977 ImageView imageView = ImageView::New();
978 DALI_TEST_CHECK( imageView.GetProperty( ImageView::Property::RESOURCE_URL ).Get< std::string >().empty() );
980 imageView.SetProperty( ImageView::Property::RESOURCE_URL, "TestString" );
981 DALI_TEST_EQUALS( imageView.GetProperty( ImageView::Property::RESOURCE_URL ).Get< std::string >(), "TestString", TEST_LOCATION );
986 // Scenarios 1: ImageView from regular image
987 int UtcDaliImageViewSetImageBufferImage(void)
989 ToolkitTestApplication application;
991 ImageView imageView = ImageView::New();
992 Stage::GetCurrent().Add( imageView );
994 TestGlAbstraction& gl = application.GetGlAbstraction();
995 gl.EnableTextureCallTrace( true );
997 std::vector< GLuint > ids;
999 application.GetGlAbstraction().SetNextTextureIds( ids );
1003 BufferImage image = CreateBufferImage( width, height, Color::WHITE );
1005 imageView.SetImage( image );
1007 application.SendNotification();
1008 application.Render();
1010 DALI_TEST_CHECK( gl.GetTextureTrace().FindMethod("BindTexture") );
1012 std::stringstream params;
1013 params << GL_TEXTURE_2D << ", " << 23;
1014 DALI_TEST_CHECK( gl.GetTextureTrace().FindMethodAndParams("BindTexture", params.str()) );
1019 // Scenarios 2: ImageView from Native image
1020 int UtcDaliImageViewSetImageNativeImage(void)
1022 ToolkitTestApplication application;
1024 ImageView imageView = ImageView::New();
1025 Stage::GetCurrent().Add( imageView );
1027 TestGlAbstraction& gl = application.GetGlAbstraction();
1028 gl.EnableTextureCallTrace( true );
1030 std::vector< GLuint > ids;
1031 ids.push_back( 23 );
1032 application.GetGlAbstraction().SetNextTextureIds( ids );
1036 TestNativeImagePointer nativeImageInterface = TestNativeImage::New( width, height );
1037 NativeImage nativeImage = NativeImage::New( *(nativeImageInterface.Get()) );
1039 imageView.SetImage( nativeImage );
1040 application.SendNotification();
1041 application.Render();
1043 DALI_TEST_CHECK( gl.GetTextureTrace().FindMethod("BindTexture") );
1045 std::stringstream params;
1046 params << GL_TEXTURE_EXTERNAL_OES << ", " << 23;
1047 DALI_TEST_CHECK( gl.GetTextureTrace().FindMethodAndParams("BindTexture", params.str()) );
1052 // Scenarios 3: ImageView initially from regular image but then SetImage called with Native image
1053 int UtcDaliImageViewSetImageBufferImageToNativeImage(void)
1055 ToolkitTestApplication application;
1059 BufferImage image = CreateBufferImage( width, height, Color::WHITE );
1061 ImageView imageView = ImageView::New( image );
1062 Stage::GetCurrent().Add( imageView );
1064 TestGlAbstraction& gl = application.GetGlAbstraction();
1065 gl.EnableTextureCallTrace( true );
1067 std::vector< GLuint > ids;
1068 ids.push_back( 23 );
1069 application.GetGlAbstraction().SetNextTextureIds( ids );
1071 application.SendNotification();
1072 application.Render();
1074 DALI_TEST_CHECK( gl.GetTextureTrace().FindMethod("BindTexture") );
1076 std::stringstream params;
1077 params << GL_TEXTURE_2D << ", " << 23;
1078 DALI_TEST_CHECK( gl.GetTextureTrace().FindMethodAndParams("BindTexture", params.str()) );
1082 TestNativeImagePointer nativeImageInterface = TestNativeImage::New( width, height );
1083 NativeImage nativeImage = NativeImage::New( *(nativeImageInterface.Get()) );
1084 imageView.SetImage( nativeImage );
1087 ids.push_back( 24 );
1088 application.GetGlAbstraction().SetNextTextureIds( ids );
1090 application.SendNotification();
1091 application.Render();
1093 DALI_TEST_CHECK( gl.GetTextureTrace().FindMethod("BindTexture") );
1095 std::stringstream nextTextureParams;
1096 nextTextureParams << GL_TEXTURE_EXTERNAL_OES << ", " << 24;
1097 DALI_TEST_CHECK( gl.GetTextureTrace().FindMethodAndParams("BindTexture", nextTextureParams.str()) );
1102 // Scenarios 4: ImageView initially from Native image but then SetImage called with regular image
1103 int UtcDaliImageViewSetImageNativeImageToBufferImage(void)
1105 ToolkitTestApplication application;
1109 TestNativeImagePointer nativeImageInterface = TestNativeImage::New( width, height );
1110 NativeImage nativeImage = NativeImage::New( *(nativeImageInterface.Get()) );
1112 ImageView imageView = ImageView::New( nativeImage );
1113 Stage::GetCurrent().Add( imageView );
1115 TestGlAbstraction& gl = application.GetGlAbstraction();
1116 gl.EnableTextureCallTrace( true );
1118 std::vector< GLuint > ids;
1119 ids.push_back( 23 );
1120 application.GetGlAbstraction().SetNextTextureIds( ids );
1122 application.SendNotification();
1123 application.Render();
1125 DALI_TEST_CHECK( gl.GetTextureTrace().FindMethod("BindTexture") );
1127 std::stringstream params;
1128 params << GL_TEXTURE_EXTERNAL_OES << ", " << 23;
1129 DALI_TEST_CHECK( gl.GetTextureTrace().FindMethodAndParams("BindTexture", params.str()) );
1133 BufferImage image = CreateBufferImage( width, height, Color::WHITE );
1134 imageView.SetImage( image );
1137 ids.push_back( 24 );
1138 application.GetGlAbstraction().SetNextTextureIds( ids );
1140 application.SendNotification();
1141 application.Render();
1143 DALI_TEST_CHECK( gl.GetTextureTrace().FindMethod("BindTexture") );
1145 std::stringstream nextTextureParams;
1146 nextTextureParams << GL_TEXTURE_2D << ", " << 24;
1147 DALI_TEST_CHECK( gl.GetTextureTrace().FindMethodAndParams("BindTexture", nextTextureParams.str()) );
1152 // Scenarios 5: ImageView from Native image with custom shader
1153 int UtcDaliImageViewSetImageNativeImageWithCustomShader(void)
1155 ToolkitTestApplication application;
1160 Property::Map customShader;
1161 customShader.Insert( "vertexShader", VERTEX_SHADER );
1162 customShader.Insert( "fragmentShader", FRAGMENT_SHADER );
1164 Property::Array shaderHints;
1165 shaderHints.PushBack( "requiresSelfDepthTest" );
1166 shaderHints.PushBack( "outputIsTransparent" );
1167 shaderHints.PushBack( "outputIsOpaque" );
1168 shaderHints.PushBack( "modifiesGeometry" );
1170 customShader.Insert( "hints", shaderHints );
1173 map.Insert( "shader", customShader );
1175 TestNativeImagePointer nativeImageInterface = TestNativeImage::New( width, height );
1176 NativeImage nativeImage = NativeImage::New( *(nativeImageInterface.Get()) );
1178 ImageView imageView = ImageView::New( nativeImage );
1179 imageView.SetProperty( ImageView::Property::IMAGE, map );
1180 Stage::GetCurrent().Add( imageView );
1182 TestGlAbstraction& gl = application.GetGlAbstraction();
1183 gl.EnableTextureCallTrace( true );
1185 std::vector< GLuint > ids;
1186 ids.push_back( 23 );
1187 application.GetGlAbstraction().SetNextTextureIds( ids );
1189 application.SendNotification();
1190 application.Render();
1192 DALI_TEST_CHECK( gl.GetTextureTrace().FindMethod("BindTexture") );
1194 std::stringstream params;
1195 params << GL_TEXTURE_EXTERNAL_OES << ", " << 23;
1196 DALI_TEST_CHECK( gl.GetTextureTrace().FindMethodAndParams("BindTexture", params.str()) );
1201 // Scenarios 6: ImageView initially from regular image with custom shader but then SetImage called with Native
1202 int UtcDaliImageViewSetImageBufferImageWithCustomShaderToNativeImage(void)
1204 ToolkitTestApplication application;
1209 Property::Map customShader;
1210 customShader.Insert( "vertexShader", VERTEX_SHADER );
1211 customShader.Insert( "fragmentShader", FRAGMENT_SHADER );
1213 Property::Array shaderHints;
1214 shaderHints.PushBack( "requiresSelfDepthTest" );
1215 shaderHints.PushBack( "outputIsTransparent" );
1216 shaderHints.PushBack( "outputIsOpaque" );
1217 shaderHints.PushBack( "modifiesGeometry" );
1219 customShader.Insert( "hints", shaderHints );
1222 map.Insert( "shader", customShader );
1224 BufferImage image = CreateBufferImage( width, height, Color::WHITE );
1226 ImageView imageView = ImageView::New( image );
1227 imageView.SetProperty( ImageView::Property::IMAGE, map );
1228 Stage::GetCurrent().Add( imageView );
1230 TestGlAbstraction& gl = application.GetGlAbstraction();
1231 gl.EnableTextureCallTrace( true );
1233 std::vector< GLuint > ids;
1234 ids.push_back( 23 );
1235 application.GetGlAbstraction().SetNextTextureIds( ids );
1237 application.SendNotification();
1238 application.Render();
1240 DALI_TEST_CHECK( gl.GetTextureTrace().FindMethod("BindTexture") );
1242 std::stringstream params;
1243 params << GL_TEXTURE_2D << ", " << 23;
1244 DALI_TEST_CHECK( gl.GetTextureTrace().FindMethodAndParams("BindTexture", params.str()) );
1246 TestNativeImagePointer nativeImageInterface = TestNativeImage::New( width, height );
1247 NativeImage nativeImage = NativeImage::New( *(nativeImageInterface.Get()) );
1248 imageView.SetImage( nativeImage );
1251 ids.push_back( 24 );
1252 application.GetGlAbstraction().SetNextTextureIds( ids );
1254 application.SendNotification();
1255 application.Render();
1257 DALI_TEST_CHECK( gl.GetTextureTrace().FindMethod("BindTexture") );
1259 std::stringstream nativeImageParams;
1260 nativeImageParams << GL_TEXTURE_EXTERNAL_OES << ", " << 24;
1261 DALI_TEST_CHECK( gl.GetTextureTrace().FindMethodAndParams("BindTexture", nativeImageParams.str()) );
1267 int UtcDaliImageViewGetImageP1(void)
1269 ToolkitTestApplication application;
1271 ImageView imageView = ImageView::New();
1272 DALI_TEST_CHECK( ! imageView.GetImage() );
1274 Image image = CreateBufferImage();
1275 imageView.SetImage( image );
1276 DALI_TEST_CHECK( imageView.GetImage() == image );
1281 int UtcDaliImageViewGetImageP2(void)
1283 ToolkitTestApplication application;
1285 BufferImage image = CreateBufferImage();
1286 ImageView imageView = ImageView::New( image );
1287 DALI_TEST_CHECK( imageView.GetImage() == image );
1292 int UtcDaliImageViewGetImageN(void)
1294 ToolkitTestApplication application;
1296 ImageView imageView = ImageView::New( TEST_IMAGE_FILE_NAME );
1297 DALI_TEST_CHECK( ! imageView.GetImage() );
1299 Image image = CreateBufferImage();
1300 imageView.SetImage( image );
1301 DALI_TEST_CHECK( imageView.GetImage() == image );
1303 imageView.SetImage( TEST_IMAGE_FILE_NAME );
1304 DALI_TEST_CHECK( ! imageView.GetImage() );
1310 int UtcDaliImageViewReplaceImage(void)
1312 ToolkitTestApplication application;
1314 gResourceReadySignalFired = false;
1318 Image image = CreateBufferImage( width, height, Vector4(1.f, 1.f, 1.f, 1.f) );
1320 // Check ImageView with background and main image, to ensure both visuals are marked as loaded
1321 ImageView imageView = ImageView::New( TEST_IMAGE_1 );
1323 DALI_TEST_EQUALS( Toolkit::DevelControl::IsResourceReady( imageView ), false, TEST_LOCATION );
1325 Toolkit::DevelControl::ResourceReadySignal( imageView ).Connect( &ResourceReadySignal);
1327 Stage::GetCurrent().Add( imageView );
1329 application.SendNotification();
1330 application.Render(16);
1332 // loading started, this waits for the loader thread for max 30 seconds
1333 DALI_TEST_EQUALS( Test::WaitForEventThreadTrigger( 1 ), true, TEST_LOCATION );
1335 DALI_TEST_EQUALS( imageView.GetRendererCount(), 1u, TEST_LOCATION );
1337 DALI_TEST_EQUALS( gResourceReadySignalFired, true, TEST_LOCATION );
1339 gResourceReadySignalFired = false;
1341 imageView.SetImage(TEST_IMAGE_2);
1343 application.SendNotification();
1344 application.Render(16);
1346 // loading started, this waits for the loader thread for max 30 seconds
1347 DALI_TEST_EQUALS( Test::WaitForEventThreadTrigger( 1 ), true, TEST_LOCATION );
1349 DALI_TEST_EQUALS( imageView.GetRendererCount(), 1u, TEST_LOCATION );
1351 DALI_TEST_EQUALS( Toolkit::DevelControl::IsResourceReady( imageView ), true, TEST_LOCATION );
1353 DALI_TEST_EQUALS( gResourceReadySignalFired, true, TEST_LOCATION );