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 // resolution: 34*34, pixel format: RGBA8888
81 static const char* gImage_34_RGBA = TEST_RESOURCE_DIR "/icon-edit.png";
82 // resolution: 600*600, pixel format: RGB888
83 static const char* gImage_600_RGB = TEST_RESOURCE_DIR "/test-image-600.jpg";
85 // resolution: 50*50, frame count: 4, frame delay: 0.2 second for each frame
86 const char* TEST_GIF_FILE_NAME = TEST_RESOURCE_DIR "/anim.gif";
88 void TestImage( ImageView imageView, BufferImage image )
90 Property::Value value = imageView.GetProperty( imageView.GetPropertyIndex( "image" ) );
93 DALI_TEST_CHECK( value.Get( map ) );
95 DALI_TEST_CHECK( map.Find( "width" ) );
96 DALI_TEST_CHECK( map.Find( "height" ) );
97 DALI_TEST_CHECK( map.Find( "type" ) );
100 DALI_TEST_CHECK( map[ "width" ].Get( width ) );
101 DALI_TEST_EQUALS( (unsigned int)width, image.GetWidth(), TEST_LOCATION );
104 DALI_TEST_CHECK( map[ "height" ].Get( height ) );
105 DALI_TEST_EQUALS( (unsigned int)height, image.GetHeight(), TEST_LOCATION );
108 DALI_TEST_CHECK( map[ "type" ].Get( type ) );
109 DALI_TEST_EQUALS( type, "BufferImage", TEST_LOCATION );
112 void TestImage( ImageView imageView, ResourceImage image )
114 Property::Value value = imageView.GetProperty( imageView.GetPropertyIndex( "image" ) );
117 DALI_TEST_CHECK( value.Get( map ) );
119 if( map.Find( "width" ) )
122 DALI_TEST_CHECK( map[ "width" ].Get( width ) );
123 DALI_TEST_EQUALS( (unsigned int)width, image.GetWidth(), TEST_LOCATION );
126 if( map.Find( "height" ) )
129 DALI_TEST_CHECK( map[ "height" ].Get( height ) );
130 DALI_TEST_EQUALS( (unsigned int)height, image.GetHeight(), TEST_LOCATION );
133 DALI_TEST_CHECK( map.Find( "type" ) );
136 DALI_TEST_CHECK( map[ "type" ].Get( type ) );
137 DALI_TEST_EQUALS( type, "ResourceImage", TEST_LOCATION );
139 std::string filename;
140 DALI_TEST_CHECK( map[ "filename" ].Get( filename ) );
141 DALI_TEST_EQUALS( filename, image.GetUrl(), TEST_LOCATION );
144 void TestUrl( ImageView imageView, const std::string url )
146 Property::Value value = imageView.GetProperty( imageView.GetPropertyIndex( "image" ) );
148 std::string urlActual;
149 DALI_TEST_CHECK( value.Get( urlActual ) );
150 DALI_TEST_EQUALS( urlActual, url, TEST_LOCATION );
155 int UtcDaliImageViewNewP(void)
157 TestApplication application;
159 ImageView imageView = ImageView::New();
161 DALI_TEST_CHECK( imageView );
166 int UtcDaliImageViewNewImageP(void)
168 TestApplication application;
170 BufferImage image = CreateBufferImage( 100, 200, Vector4( 1.f, 1.f, 1.f, 1.f ) );
171 ImageView imageView = ImageView::New( image );
173 DALI_TEST_CHECK( imageView );
174 TestImage( imageView, image );
179 int UtcDaliImageViewNewUrlP(void)
181 TestApplication application;
183 ImageView imageView = ImageView::New( TEST_IMAGE_FILE_NAME );
184 DALI_TEST_CHECK( imageView );
186 TestUrl( imageView, TEST_IMAGE_FILE_NAME );
191 int UtcDaliImageViewConstructorP(void)
193 TestApplication application;
197 DALI_TEST_CHECK( !imageView );
202 int UtcDaliImageViewCopyConstructorP(void)
204 TestApplication application;
206 // Initialize an object, ref count == 1
207 ImageView imageView = ImageView::New();
209 ImageView copy( imageView );
210 DALI_TEST_CHECK( copy );
215 int UtcDaliImageViewAssignmentOperatorP(void)
217 TestApplication application;
219 ImageView imageView = ImageView::New();
221 ImageView copy( imageView );
222 DALI_TEST_CHECK( copy );
223 DALI_TEST_EQUALS( imageView, copy, TEST_LOCATION );
228 int UtcDaliImageViewDownCastP(void)
230 TestApplication application;
232 ImageView imageView = ImageView::New();
234 BaseHandle object(imageView);
236 ImageView imageView2 = ImageView::DownCast( object );
237 DALI_TEST_CHECK(imageView2);
239 ImageView imageView3 = DownCast< ImageView >( object );
240 DALI_TEST_CHECK(imageView3);
245 int UtcDaliImageViewDownCastN(void)
247 TestApplication application;
249 BaseHandle unInitializedObject;
251 ImageView imageView1 = ImageView::DownCast( unInitializedObject );
252 DALI_TEST_CHECK( !imageView1 );
254 ImageView imageView2 = DownCast< ImageView >( unInitializedObject );
255 DALI_TEST_CHECK( !imageView2 );
260 int UtcDaliImageViewTypeRegistry(void)
262 ToolkitTestApplication application;
264 TypeRegistry typeRegistry = TypeRegistry::Get();
265 DALI_TEST_CHECK( typeRegistry );
267 TypeInfo typeInfo = typeRegistry.GetTypeInfo( "ImageView" );
268 DALI_TEST_CHECK( typeInfo );
270 BaseHandle handle = typeInfo.CreateInstance();
271 DALI_TEST_CHECK( handle );
273 ImageView imageView = ImageView::DownCast( handle );
274 DALI_TEST_CHECK( imageView );
279 int UtcDaliImageViewSetGetProperty01(void)
281 ToolkitTestApplication application;
283 ImageView imageView = ImageView::New();
285 Property::Index idx = imageView.GetPropertyIndex( "image" );
286 DALI_TEST_EQUALS( idx, (Property::Index)ImageView::Property::IMAGE, TEST_LOCATION );
288 imageView.SetProperty( idx, TEST_IMAGE_FILE_NAME );
289 TestUrl( imageView, TEST_IMAGE_FILE_NAME );
294 int UtcDaliImageViewSetGetProperty02(void)
296 ToolkitTestApplication application;
298 Image image = CreateBufferImage( 10, 10, Color::WHITE );
299 ImageView imageView = ImageView::New(image);
300 Vector4 fullImageRect( 0.f, 0.f, 1.f, 1.f );
302 Stage::GetCurrent().Add( imageView );
304 application.SendNotification();
305 application.Render();
306 TestGlAbstraction& gl = application.GetGlAbstraction();
308 Vector4 pixelAreaUniform;
309 DALI_TEST_CHECK( gl.GetUniformValue<Vector4>( "pixelArea", pixelAreaUniform ) );
310 DALI_TEST_EQUALS( pixelAreaUniform, fullImageRect, TEST_LOCATION );
312 Property::Value value = imageView.GetProperty( ImageView::Property::PIXEL_AREA );
313 Vector4 pixelAreaValue;
314 DALI_TEST_CHECK( value.Get(pixelAreaValue) );
315 DALI_TEST_EQUALS( pixelAreaValue, fullImageRect, TEST_LOCATION );
317 Vector4 pixelAreaSet( 0.2f, 0.2f, 0.3f, 0.3f );
318 imageView.SetProperty( ImageView::Property::PIXEL_AREA, pixelAreaSet);
320 application.SendNotification();
321 application.Render();
323 value = imageView.GetProperty( ImageView::Property::PIXEL_AREA );
324 value.Get(pixelAreaValue);
325 DALI_TEST_EQUALS( pixelAreaValue, pixelAreaSet, TEST_LOCATION );
327 DALI_TEST_CHECK( gl.GetUniformValue<Vector4>( "pixelArea", pixelAreaUniform ) );
328 DALI_TEST_EQUALS( pixelAreaUniform, pixelAreaSet, TEST_LOCATION );
333 int UtcDaliImageViewSetGetProperty03(void)
335 ToolkitTestApplication application;
337 Image image = CreateBufferImage( 10, 10, Color::WHITE );
338 ImageView imageView = ImageView::New(image);
339 Stage::GetCurrent().Add( imageView );
340 application.SendNotification();
341 application.Render();
343 // conventional alpha blending
344 Renderer renderer = imageView.GetRendererAt( 0 );
345 Property::Value value = renderer.GetProperty( Renderer::Property::BLEND_PRE_MULTIPLIED_ALPHA );
347 DALI_TEST_CHECK( value.Get( enable ) );
348 DALI_TEST_CHECK( !enable );
350 // pre-multiplied alpha blending
351 imageView.SetProperty( Toolkit::ImageView::Property::PRE_MULTIPLIED_ALPHA, true );
352 application.SendNotification();
353 application.Render();
355 int srcFactorRgb = renderer.GetProperty<int>( Renderer::Property::BLEND_FACTOR_SRC_RGB );
356 int destFactorRgb = renderer.GetProperty<int>( Renderer::Property::BLEND_FACTOR_DEST_RGB );
357 int srcFactorAlpha = renderer.GetProperty<int>( Renderer::Property::BLEND_FACTOR_SRC_ALPHA );
358 int destFactorAlpha = renderer.GetProperty<int>( Renderer::Property::BLEND_FACTOR_DEST_ALPHA );
359 DALI_TEST_CHECK( srcFactorRgb == BlendFactor::ONE );
360 DALI_TEST_CHECK( destFactorRgb == BlendFactor::ONE_MINUS_SRC_ALPHA );
361 DALI_TEST_CHECK( srcFactorAlpha == BlendFactor::ONE );
362 DALI_TEST_CHECK( destFactorAlpha == BlendFactor::ONE );
364 value = renderer.GetProperty( Renderer::Property::BLEND_PRE_MULTIPLIED_ALPHA );
365 DALI_TEST_CHECK( value.Get( enable ) );
366 DALI_TEST_CHECK( enable );
371 int UtcDaliImageViewPixelArea(void)
373 // Test pixel area property
374 ToolkitTestApplication application;
376 // Gif image, use AnimatedImageVisual internally
377 // Atlasing is applied to pack multiple frames, use custom wrap mode
378 ImageView gifView = ImageView::New();
379 const Vector4 pixelAreaVisual( 0.f, 0.f, 2.f, 2.f );
380 gifView.SetProperty( ImageView::Property::IMAGE,
381 Property::Map().Add( ImageVisual::Property::URL, TEST_GIF_FILE_NAME )
382 .Add( ImageVisual::Property::PIXEL_AREA, pixelAreaVisual ) );
385 Stage stage = Stage::GetCurrent();
386 stage.Add( gifView );
389 application.SendNotification();
390 application.Render(16);
391 DALI_TEST_CHECK( gifView.GetRendererCount() == 1u );
393 const Vector4 fullTextureRect( 0.f, 0.f, 1.f, 1.f );
394 // test that the pixel area value defined in the visual property map is registered on renderer
395 Renderer renderer = gifView.GetRendererAt(0);
396 Property::Value pixelAreaValue = renderer.GetProperty( renderer.GetPropertyIndex( "pixelArea" ) );
397 DALI_TEST_EQUALS( pixelAreaValue.Get<Vector4>(), pixelAreaVisual, TEST_LOCATION );
399 // test that the shader has the default pixel area value registered.
400 Shader shader = renderer.GetShader();
401 pixelAreaValue = shader.GetProperty( shader.GetPropertyIndex( "pixelArea" ) );
402 DALI_TEST_EQUALS( pixelAreaValue.Get<Vector4>(), fullTextureRect, TEST_LOCATION );
404 // test that the uniform uses the pixelArea property on the renderer.
405 TestGlAbstraction& gl = application.GetGlAbstraction();
406 Vector4 pixelAreaUniform;
407 DALI_TEST_CHECK( gl.GetUniformValue<Vector4>( "pixelArea", pixelAreaUniform ) );
408 DALI_TEST_EQUALS( pixelAreaVisual, pixelAreaUniform, Math::MACHINE_EPSILON_100, TEST_LOCATION );
410 // set the pixelArea property on the control
411 const Vector4 pixelAreaControl( -1.f, -1.f, 3.f, 3.f );
412 gifView.SetProperty( ImageView::Property::PIXEL_AREA, pixelAreaControl );
413 application.SendNotification();
414 application.Render(16);
416 // check the pixelArea property on the control
417 pixelAreaValue = gifView.GetProperty( gifView.GetPropertyIndex( "pixelArea" ) );
418 DALI_TEST_EQUALS( pixelAreaValue.Get<Vector4>(), pixelAreaControl, TEST_LOCATION );
419 // test that the uniform uses the pixelArea property on the control.
420 DALI_TEST_CHECK( gl.GetUniformValue<Vector4>( "pixelArea", pixelAreaUniform ) );
421 DALI_TEST_EQUALS( pixelAreaControl, pixelAreaUniform, Math::MACHINE_EPSILON_100, TEST_LOCATION );
427 int UtcDaliImageViewAsyncLoadingWithoutAltasing(void)
429 ToolkitTestApplication application;
430 TestGlAbstraction& gl = application.GetGlAbstraction();
431 const std::vector<GLuint>& textures = gl.GetBoundTextures();
432 size_t numTextures = textures.size();
434 // Async loading, no atlasing for big size image
435 ImageView imageView = ImageView::New( gImage_600_RGB );
437 // By default, Aysnc loading is used
438 Stage::GetCurrent().Add( imageView );
439 imageView.SetSize(100, 100);
440 imageView.SetParentOrigin( ParentOrigin::CENTER );
442 DALI_TEST_EQUALS( Test::WaitForEventThreadTrigger( 1 ), true, TEST_LOCATION );
444 application.SendNotification();
445 application.Render(16);
446 application.SendNotification();
448 const std::vector<GLuint>& textures2 = gl.GetBoundTextures();
449 DALI_TEST_GREATER( textures2.size(), numTextures, TEST_LOCATION );
456 int UtcDaliImageViewAsyncLoadingWithAtlasing(void)
458 ToolkitTestApplication application;
460 //Async loading, automatic atlasing for small size image
461 TraceCallStack& callStack = application.GetGlAbstraction().GetTextureTrace();
463 callStack.Enable(true);
465 Property::Map imageMap;
467 imageMap[ ImageVisual::Property::URL ] = gImage_34_RGBA;
468 imageMap[ ImageVisual::Property::DESIRED_HEIGHT ] = 34;
469 imageMap[ ImageVisual::Property::DESIRED_WIDTH ] = 34;
470 imageMap[ DevelImageVisual::Property::ATLASING] = true;
472 ImageView imageView = ImageView::New();
473 imageView.SetProperty( ImageView::Property::IMAGE, imageMap );
475 // By default, Aysnc loading is used
476 // loading is not started if the actor is offStage
478 Stage::GetCurrent().Add( imageView );
479 application.SendNotification();
480 application.Render(16);
481 application.Render(16);
482 application.SendNotification();
484 // loading started, this waits for the loader thread for max 30 seconds
485 DALI_TEST_EQUALS( Test::WaitForEventThreadTrigger( 1 ), true, TEST_LOCATION );
487 application.SendNotification();
488 application.Render(16);
490 callStack.Enable(false);
492 TraceCallStack::NamedParams params;
493 params["width"] = ToString(34);
494 params["height"] = ToString(34);
495 DALI_TEST_EQUALS( callStack.FindMethodAndParams( "TexSubImage2D", params ), true, TEST_LOCATION );
500 int UtcDaliImageViewAsyncLoadingWithAtlasing02(void)
502 ToolkitTestApplication application;
504 //Async loading, automatic atlasing for small size image
505 TraceCallStack& callStack = application.GetGlAbstraction().GetTextureTrace();
507 callStack.Enable(true);
509 Property::Map asyncLoadingMap;
510 asyncLoadingMap[ "url" ] = gImage_34_RGBA;
511 asyncLoadingMap[ "desiredHeight" ] = 34;
512 asyncLoadingMap[ "desiredWidth" ] = 34;
513 asyncLoadingMap[ "synchronousLoading" ] = false;
514 asyncLoadingMap[ "atlasing" ] = true;
516 ImageView imageView = ImageView::New();
517 imageView.SetProperty( ImageView::Property::IMAGE, asyncLoadingMap );
519 Stage::GetCurrent().Add( imageView );
520 application.SendNotification();
521 application.Render(16);
522 application.Render(16);
523 application.SendNotification();
525 // loading started, this waits for the loader thread for max 30 seconds
526 DALI_TEST_EQUALS( Test::WaitForEventThreadTrigger( 1 ), true, TEST_LOCATION );
528 application.SendNotification();
529 application.Render(16);
531 callStack.Enable(false);
533 TraceCallStack::NamedParams params;
534 params["width"] = ToString(34);
535 params["height"] = ToString(34);
536 DALI_TEST_EQUALS( callStack.FindMethodAndParams( "TexSubImage2D", params ), true, TEST_LOCATION );
541 int UtcDaliImageViewSyncLoading(void)
543 ToolkitTestApplication application;
545 tet_infoline("ImageView Testing sync loading and size using index key property map");
547 Property::Map syncLoadingMap;
548 syncLoadingMap[ ImageVisual::Property::SYNCHRONOUS_LOADING ] = true;
549 syncLoadingMap[ DevelImageVisual::Property::ATLASING ] = true;
551 // Sync loading, no atlasing for big size image
553 ImageView imageView = ImageView::New();
555 // Sync loading is used
556 syncLoadingMap[ ImageVisual::Property::URL ] = gImage_600_RGB;
557 imageView.SetProperty( ImageView::Property::IMAGE, syncLoadingMap );
560 // Sync loading, automatic atlasing for small size image
562 TraceCallStack& callStack = application.GetGlAbstraction().GetTextureTrace();
564 callStack.Enable(true);
566 ImageView imageView = ImageView::New( );
568 // Sync loading is used
569 syncLoadingMap[ ImageVisual::Property::URL ] = gImage_34_RGBA;
570 syncLoadingMap[ ImageVisual::Property::DESIRED_HEIGHT ] = 34;
571 syncLoadingMap[ ImageVisual::Property::DESIRED_WIDTH ] = 34;
572 imageView.SetProperty( ImageView::Property::IMAGE, syncLoadingMap );
574 Stage::GetCurrent().Add( imageView );
575 application.SendNotification();
576 application.Render(16);
578 TraceCallStack::NamedParams params;
579 params["width"] = ToString(34);
580 params["height"] = ToString(34);
581 DALI_TEST_EQUALS( callStack.FindMethodAndParams( "TexSubImage2D", params ),
582 true, TEST_LOCATION );
588 int UtcDaliImageViewSyncLoading02(void)
590 ToolkitTestApplication application;
592 tet_infoline("ImageView Testing sync loading and size using string key property map");
594 // Sync loading, automatic atlasing for small size image
596 TraceCallStack& callStack = application.GetGlAbstraction().GetTextureTrace();
598 callStack.Enable(true);
600 ImageView imageView = ImageView::New( );
602 // Sync loading is used
603 Property::Map syncLoadingMap;
604 syncLoadingMap[ "url" ] = gImage_34_RGBA;
605 syncLoadingMap[ "desiredHeight" ] = 34;
606 syncLoadingMap[ "desiredWidth" ] = 34;
607 syncLoadingMap[ "synchronousLoading" ] = true;
608 syncLoadingMap[ "atlasing" ] = true;
609 imageView.SetProperty( ImageView::Property::IMAGE, syncLoadingMap );
611 Stage::GetCurrent().Add( imageView );
612 application.SendNotification();
613 application.Render(16);
615 TraceCallStack::NamedParams params;
616 params["width"] = ToString(34);
617 params["height"] = ToString(34);
618 DALI_TEST_EQUALS( callStack.FindMethodAndParams( "TexSubImage2D", params ),
619 true, TEST_LOCATION );
624 int UtcDaliImageViewSizeWithBackground(void)
626 ToolkitTestApplication application;
630 Image image = CreateBufferImage( width, height, Vector4(1.f, 1.f, 1.f, 1.f) );
631 ImageView imageView = ImageView::New();
632 imageView.SetBackgroundImage( image );
634 Stage::GetCurrent().Add( imageView );
635 application.SendNotification();
636 application.Render();
638 DALI_TEST_EQUALS( imageView.GetCurrentSize().width, (float)width, TEST_LOCATION );
639 DALI_TEST_EQUALS( imageView.GetCurrentSize().height, (float)height, TEST_LOCATION );
644 int UtcDaliImageViewSizeWithBackgroundAndImage(void)
646 ToolkitTestApplication application;
648 int widthBackground = 100;
649 int heightBackground = 200;
652 Image imageBackground = CreateBufferImage( widthBackground, heightBackground, Vector4(1.f, 1.f, 1.f, 1.f) );
653 Image image = CreateBufferImage( width, height, Vector4(1.f, 1.f, 1.f, 1.f) );
655 ImageView imageView = ImageView::New();
656 imageView.SetBackgroundImage( imageBackground );
657 imageView.SetImage( image );
659 Stage::GetCurrent().Add( imageView );
660 application.SendNotification();
661 application.Render();
663 DALI_TEST_EQUALS( imageView.GetCurrentSize().width, (float)width, TEST_LOCATION );
664 DALI_TEST_EQUALS( imageView.GetCurrentSize().height, (float)height, TEST_LOCATION );
669 int UtcDaliImageViewHeightForWidthBackground(void)
671 ToolkitTestApplication application;
673 int widthBackground = 100;
674 int heightBackground = 200;
675 Image imageBackground = CreateBufferImage( widthBackground, heightBackground, Vector4(1.f, 1.f, 1.f, 1.f) );
677 ImageView imageView = ImageView::New();
678 imageView.SetBackgroundImage( imageBackground );
680 Stage::GetCurrent().Add( imageView );
681 application.SendNotification();
682 application.Render();
684 Control control = Control::DownCast( imageView );
685 DALI_TEST_CHECK( control );
686 DALI_TEST_EQUALS( imageView.GetHeightForWidth( 123.f ), control.GetHeightForWidth( 123.f ), TEST_LOCATION );
687 DALI_TEST_EQUALS( imageView.GetWidthForHeight( 321.f ), control.GetWidthForHeight( 321.f ), TEST_LOCATION );
692 int UtcDaliImageViewHeightForWidthBackgroundAndImage(void)
694 ToolkitTestApplication application;
696 int widthBackground = 100;
697 int heightBackground = 200;
700 Image imageBackground = CreateBufferImage( widthBackground, heightBackground, Vector4(1.f, 1.f, 1.f, 1.f) );
701 Image image = CreateBufferImage( width, height, Vector4(1.f, 1.f, 1.f, 1.f) );
703 ImageView imageView = ImageView::New();
704 imageView.SetBackgroundImage( imageBackground );
705 imageView.SetImage( image );
707 Stage::GetCurrent().Add( imageView );
708 application.SendNotification();
709 application.Render();
711 DALI_TEST_EQUALS( imageView.GetHeightForWidth( width ), (float)height, TEST_LOCATION );
712 DALI_TEST_EQUALS( imageView.GetWidthForHeight( height ), (float)width, TEST_LOCATION );
717 int UtcDaliImageViewSetBufferImage(void)
719 ToolkitTestApplication application;
723 BufferImage image1 = CreateBufferImage( width1, height1, Vector4( 1.f, 1.f, 1.f, 1.f ) );
724 ImageView imageView = ImageView::New();
725 imageView.SetImage( image1 );
727 TestImage( imageView, image1 );
731 BufferImage image2 = CreateBufferImage( width2, height2, Vector4( 1.f, 1.f, 1.f, 1.f ) );
732 imageView.SetImage( image2 );
734 TestImage( imageView, image2 );
739 int UtcDaliImageViewSetImageUrl(void)
741 ToolkitTestApplication application;
743 ImageView imageView = ImageView::New();
744 imageView.SetImage( TEST_IMAGE_FILE_NAME );
745 TestUrl( imageView, TEST_IMAGE_FILE_NAME );
748 imageView.SetImage( TEST_IMAGE_FILE_NAME2 );
749 TestUrl( imageView, TEST_IMAGE_FILE_NAME2 );
754 int UtcDaliImageViewSetImageOnstageP(void)
756 ToolkitTestApplication application;
758 ImageView imageView = ImageView::New();
760 Stage::GetCurrent().Add( imageView );
761 application.SendNotification();
762 application.Render();
764 ResourceImage image1 = ResourceImage::New( TEST_IMAGE_FILE_NAME );
765 imageView.SetImage( image1 );
766 TestImage( imageView, image1 );
770 BufferImage image2 = CreateBufferImage( width, height, Vector4( 1.f, 1.f, 1.f, 1.f ) );
771 imageView.SetImage( image2 );
772 TestImage( imageView, image2 );
777 int UtcDaliImageViewSetImageOnstageN(void)
779 ToolkitTestApplication application;
781 ImageView imageView = ImageView::New();
783 Stage::GetCurrent().Add( imageView );
784 application.SendNotification();
785 application.Render();
787 ResourceImage image1 = ResourceImage::New( TEST_IMAGE_FILE_NAME );
788 imageView.SetImage( image1 );
789 TestImage( imageView, image1 );
792 imageView.SetImage( image2 );
794 Property::Value value = imageView.GetProperty( imageView.GetPropertyIndex( "image" ) );
796 //the value should be empty
798 DALI_TEST_CHECK( !value.Get( url ) );
801 DALI_TEST_CHECK( !value.Get( map ) );
806 int UtcDaliImageViewSetImageOffstageP(void)
808 ToolkitTestApplication application;
810 ImageView imageView = ImageView::New();
812 Stage::GetCurrent().Add( imageView );
813 application.SendNotification();
814 application.Render();
815 Stage::GetCurrent().Remove( imageView );
817 ResourceImage image1 = ResourceImage::New( TEST_IMAGE_FILE_NAME );
818 imageView.SetImage( image1 );
819 TestImage( imageView, image1 );
823 BufferImage image2 = CreateBufferImage( width, height, Vector4( 1.f, 1.f, 1.f, 1.f ) );
824 imageView.SetImage( image2 );
825 TestImage( imageView, image2 );
830 bool gResourceReadySignalFired = false;
832 void ResourceReadySignal( Control control )
834 gResourceReadySignalFired = true;
837 int UtcDaliImageViewCheckResourceReady(void)
839 ToolkitTestApplication application;
841 gResourceReadySignalFired = false;
846 Image image = CreateBufferImage( width, height, Vector4(1.f, 1.f, 1.f, 1.f) );
848 // Check ImageView with background and main image, to ensure both visuals are marked as loaded
849 ImageView imageView = ImageView::New( TEST_GIF_FILE_NAME );
851 imageView.SetBackgroundImage( image );
853 DALI_TEST_EQUALS( Toolkit::DevelControl::IsResourceReady( imageView ), false, TEST_LOCATION );
855 Toolkit::DevelControl::ResourceReadySignal( imageView ).Connect( &ResourceReadySignal);
857 Stage::GetCurrent().Add( imageView );
859 application.SendNotification();
860 application.Render(16);
863 DALI_TEST_EQUALS( Toolkit::DevelControl::IsResourceReady( imageView ), true, TEST_LOCATION );
865 DALI_TEST_EQUALS( gResourceReadySignalFired, true, TEST_LOCATION );
870 int UtcDaliImageViewSetImageOffstageN(void)
872 ToolkitTestApplication application;
874 ImageView imageView = ImageView::New();
876 Stage::GetCurrent().Add( imageView );
877 application.SendNotification();
878 application.Render();
879 Stage::GetCurrent().Remove( imageView );
881 ResourceImage image1 = ResourceImage::New( TEST_IMAGE_FILE_NAME );
882 imageView.SetImage( image1 );
883 TestImage( imageView, image1 );
886 imageView.SetImage( image2 );
888 Property::Value value = imageView.GetProperty( imageView.GetPropertyIndex( "image" ) );
890 //the value should be empty
892 DALI_TEST_CHECK( !value.Get( url ) );
895 DALI_TEST_CHECK( !value.Get( map ) );
900 int UtcDaliImageViewSetImageN(void)
902 ToolkitTestApplication application;
905 ImageView imageView = ImageView::New();
906 imageView.SetImage( image1 );
908 Property::Value value = imageView.GetProperty( imageView.GetPropertyIndex( "image" ) );
910 //the value should be empty
912 DALI_TEST_CHECK( !value.Get( url ) );
915 DALI_TEST_CHECK( !value.Get( map ) );
917 std::string resource_url;
918 Property::Value val = imageView.GetProperty( imageView.GetPropertyIndex( "image" ) );
919 DALI_TEST_CHECK( !val.Get( resource_url ) );
924 int UtcDaliImageViewSetImageTypeChangesP(void)
926 ToolkitTestApplication application;
928 ImageView imageView = ImageView::New();
934 Property::Value value = imageView.GetProperty( imageView.GetPropertyIndex( "image" ) );
935 DALI_TEST_CHECK( ! value.Get( url ) ); // Value should be empty
936 DALI_TEST_CHECK( ! value.Get( map ) ); // Value should be empty
939 imageView.SetImage( "TEST_URL" );
940 value = imageView.GetProperty( imageView.GetPropertyIndex( "image" ) );
942 DALI_TEST_CHECK( value.Get( url ) ); // Value should NOT be empty
943 DALI_TEST_CHECK( ! value.Get( map ) ); // Value should be empty
945 // Set an empty Image
946 imageView.SetImage( Image() );
947 value = imageView.GetProperty( imageView.GetPropertyIndex( "image" ) );
949 DALI_TEST_CHECK( ! value.Get( url ) ); // Value should be empty
950 DALI_TEST_CHECK( ! value.Get( map ) ); // Value should be empty
953 ResourceImage image1 = ResourceImage::New( TEST_IMAGE_FILE_NAME );
954 imageView.SetImage( image1 );
955 value = imageView.GetProperty( imageView.GetPropertyIndex( "image" ) );
957 DALI_TEST_CHECK( ! value.Get( url ) ); // Value should be empty
958 DALI_TEST_CHECK( value.Get( map ) ); // Value should NOT be empty
961 imageView.SetImage( "" );
962 value = imageView.GetProperty( imageView.GetPropertyIndex( "image" ) );
964 DALI_TEST_CHECK( ! value.Get( url ) ); // Value should be empty
965 DALI_TEST_CHECK( ! value.Get( map ) ); // Value should be empty
970 int UtcDaliImageViewResourceUrlP(void)
972 ToolkitTestApplication application;
974 ImageView imageView = ImageView::New();
975 DALI_TEST_CHECK( imageView.GetProperty( ImageView::Property::RESOURCE_URL ).Get< std::string >().empty() );
977 imageView.SetProperty( ImageView::Property::RESOURCE_URL, "TestString" );
978 DALI_TEST_EQUALS( imageView.GetProperty( ImageView::Property::RESOURCE_URL ).Get< std::string >(), "TestString", TEST_LOCATION );
983 // Scenarios 1: ImageView from regular image
984 int UtcDaliImageViewSetImageBufferImage(void)
986 ToolkitTestApplication application;
988 ImageView imageView = ImageView::New();
989 Stage::GetCurrent().Add( imageView );
991 TestGlAbstraction& gl = application.GetGlAbstraction();
992 gl.EnableTextureCallTrace( true );
994 std::vector< GLuint > ids;
996 application.GetGlAbstraction().SetNextTextureIds( ids );
1000 BufferImage image = CreateBufferImage( width, height, Color::WHITE );
1002 imageView.SetImage( image );
1004 application.SendNotification();
1005 application.Render();
1007 DALI_TEST_CHECK( gl.GetTextureTrace().FindMethod("BindTexture") );
1009 std::stringstream params;
1010 params << GL_TEXTURE_2D << ", " << 23;
1011 DALI_TEST_CHECK( gl.GetTextureTrace().FindMethodAndParams("BindTexture", params.str()) );
1016 // Scenarios 2: ImageView from Native image
1017 int UtcDaliImageViewSetImageNativeImage(void)
1019 ToolkitTestApplication application;
1021 ImageView imageView = ImageView::New();
1022 Stage::GetCurrent().Add( imageView );
1024 TestGlAbstraction& gl = application.GetGlAbstraction();
1025 gl.EnableTextureCallTrace( true );
1027 std::vector< GLuint > ids;
1028 ids.push_back( 23 );
1029 application.GetGlAbstraction().SetNextTextureIds( ids );
1033 TestNativeImagePointer nativeImageInterface = TestNativeImage::New( width, height );
1034 NativeImage nativeImage = NativeImage::New( *(nativeImageInterface.Get()) );
1036 imageView.SetImage( nativeImage );
1037 application.SendNotification();
1038 application.Render();
1040 DALI_TEST_CHECK( gl.GetTextureTrace().FindMethod("BindTexture") );
1042 std::stringstream params;
1043 params << GL_TEXTURE_EXTERNAL_OES << ", " << 23;
1044 DALI_TEST_CHECK( gl.GetTextureTrace().FindMethodAndParams("BindTexture", params.str()) );
1049 // Scenarios 3: ImageView initially from regular image but then SetImage called with Native image
1050 int UtcDaliImageViewSetImageBufferImageToNativeImage(void)
1052 ToolkitTestApplication application;
1056 BufferImage image = CreateBufferImage( width, height, Color::WHITE );
1058 ImageView imageView = ImageView::New( image );
1059 Stage::GetCurrent().Add( imageView );
1061 TestGlAbstraction& gl = application.GetGlAbstraction();
1062 gl.EnableTextureCallTrace( true );
1064 std::vector< GLuint > ids;
1065 ids.push_back( 23 );
1066 application.GetGlAbstraction().SetNextTextureIds( ids );
1068 application.SendNotification();
1069 application.Render();
1071 DALI_TEST_CHECK( gl.GetTextureTrace().FindMethod("BindTexture") );
1073 std::stringstream params;
1074 params << GL_TEXTURE_2D << ", " << 23;
1075 DALI_TEST_CHECK( gl.GetTextureTrace().FindMethodAndParams("BindTexture", params.str()) );
1079 TestNativeImagePointer nativeImageInterface = TestNativeImage::New( width, height );
1080 NativeImage nativeImage = NativeImage::New( *(nativeImageInterface.Get()) );
1081 imageView.SetImage( nativeImage );
1084 ids.push_back( 24 );
1085 application.GetGlAbstraction().SetNextTextureIds( ids );
1087 application.SendNotification();
1088 application.Render();
1090 DALI_TEST_CHECK( gl.GetTextureTrace().FindMethod("BindTexture") );
1092 std::stringstream nextTextureParams;
1093 nextTextureParams << GL_TEXTURE_EXTERNAL_OES << ", " << 24;
1094 DALI_TEST_CHECK( gl.GetTextureTrace().FindMethodAndParams("BindTexture", nextTextureParams.str()) );
1099 // Scenarios 4: ImageView initially from Native image but then SetImage called with regular image
1100 int UtcDaliImageViewSetImageNativeImageToBufferImage(void)
1102 ToolkitTestApplication application;
1106 TestNativeImagePointer nativeImageInterface = TestNativeImage::New( width, height );
1107 NativeImage nativeImage = NativeImage::New( *(nativeImageInterface.Get()) );
1109 ImageView imageView = ImageView::New( nativeImage );
1110 Stage::GetCurrent().Add( imageView );
1112 TestGlAbstraction& gl = application.GetGlAbstraction();
1113 gl.EnableTextureCallTrace( true );
1115 std::vector< GLuint > ids;
1116 ids.push_back( 23 );
1117 application.GetGlAbstraction().SetNextTextureIds( ids );
1119 application.SendNotification();
1120 application.Render();
1122 DALI_TEST_CHECK( gl.GetTextureTrace().FindMethod("BindTexture") );
1124 std::stringstream params;
1125 params << GL_TEXTURE_EXTERNAL_OES << ", " << 23;
1126 DALI_TEST_CHECK( gl.GetTextureTrace().FindMethodAndParams("BindTexture", params.str()) );
1130 BufferImage image = CreateBufferImage( width, height, Color::WHITE );
1131 imageView.SetImage( image );
1134 ids.push_back( 24 );
1135 application.GetGlAbstraction().SetNextTextureIds( ids );
1137 application.SendNotification();
1138 application.Render();
1140 DALI_TEST_CHECK( gl.GetTextureTrace().FindMethod("BindTexture") );
1142 std::stringstream nextTextureParams;
1143 nextTextureParams << GL_TEXTURE_2D << ", " << 24;
1144 DALI_TEST_CHECK( gl.GetTextureTrace().FindMethodAndParams("BindTexture", nextTextureParams.str()) );
1149 // Scenarios 5: ImageView from Native image with custom shader
1150 int UtcDaliImageViewSetImageNativeImageWithCustomShader(void)
1152 ToolkitTestApplication application;
1157 Property::Map customShader;
1158 customShader.Insert( "vertexShader", VERTEX_SHADER );
1159 customShader.Insert( "fragmentShader", FRAGMENT_SHADER );
1161 Property::Array shaderHints;
1162 shaderHints.PushBack( "requiresSelfDepthTest" );
1163 shaderHints.PushBack( "outputIsTransparent" );
1164 shaderHints.PushBack( "outputIsOpaque" );
1165 shaderHints.PushBack( "modifiesGeometry" );
1167 customShader.Insert( "hints", shaderHints );
1170 map.Insert( "shader", customShader );
1172 TestNativeImagePointer nativeImageInterface = TestNativeImage::New( width, height );
1173 NativeImage nativeImage = NativeImage::New( *(nativeImageInterface.Get()) );
1175 ImageView imageView = ImageView::New( nativeImage );
1176 imageView.SetProperty( ImageView::Property::IMAGE, map );
1177 Stage::GetCurrent().Add( imageView );
1179 TestGlAbstraction& gl = application.GetGlAbstraction();
1180 gl.EnableTextureCallTrace( true );
1182 std::vector< GLuint > ids;
1183 ids.push_back( 23 );
1184 application.GetGlAbstraction().SetNextTextureIds( ids );
1186 application.SendNotification();
1187 application.Render();
1189 DALI_TEST_CHECK( gl.GetTextureTrace().FindMethod("BindTexture") );
1191 std::stringstream params;
1192 params << GL_TEXTURE_EXTERNAL_OES << ", " << 23;
1193 DALI_TEST_CHECK( gl.GetTextureTrace().FindMethodAndParams("BindTexture", params.str()) );
1198 // Scenarios 6: ImageView initially from regular image with custom shader but then SetImage called with Native
1199 int UtcDaliImageViewSetImageBufferImageWithCustomShaderToNativeImage(void)
1201 ToolkitTestApplication application;
1206 Property::Map customShader;
1207 customShader.Insert( "vertexShader", VERTEX_SHADER );
1208 customShader.Insert( "fragmentShader", FRAGMENT_SHADER );
1210 Property::Array shaderHints;
1211 shaderHints.PushBack( "requiresSelfDepthTest" );
1212 shaderHints.PushBack( "outputIsTransparent" );
1213 shaderHints.PushBack( "outputIsOpaque" );
1214 shaderHints.PushBack( "modifiesGeometry" );
1216 customShader.Insert( "hints", shaderHints );
1219 map.Insert( "shader", customShader );
1221 BufferImage image = CreateBufferImage( width, height, Color::WHITE );
1223 ImageView imageView = ImageView::New( image );
1224 imageView.SetProperty( ImageView::Property::IMAGE, map );
1225 Stage::GetCurrent().Add( imageView );
1227 TestGlAbstraction& gl = application.GetGlAbstraction();
1228 gl.EnableTextureCallTrace( true );
1230 std::vector< GLuint > ids;
1231 ids.push_back( 23 );
1232 application.GetGlAbstraction().SetNextTextureIds( ids );
1234 application.SendNotification();
1235 application.Render();
1237 DALI_TEST_CHECK( gl.GetTextureTrace().FindMethod("BindTexture") );
1239 std::stringstream params;
1240 params << GL_TEXTURE_2D << ", " << 23;
1241 DALI_TEST_CHECK( gl.GetTextureTrace().FindMethodAndParams("BindTexture", params.str()) );
1243 TestNativeImagePointer nativeImageInterface = TestNativeImage::New( width, height );
1244 NativeImage nativeImage = NativeImage::New( *(nativeImageInterface.Get()) );
1245 imageView.SetImage( nativeImage );
1248 ids.push_back( 24 );
1249 application.GetGlAbstraction().SetNextTextureIds( ids );
1251 application.SendNotification();
1252 application.Render();
1254 DALI_TEST_CHECK( gl.GetTextureTrace().FindMethod("BindTexture") );
1256 std::stringstream nativeImageParams;
1257 nativeImageParams << GL_TEXTURE_EXTERNAL_OES << ", " << 24;
1258 DALI_TEST_CHECK( gl.GetTextureTrace().FindMethodAndParams("BindTexture", nativeImageParams.str()) );
1264 int UtcDaliImageViewGetImageP1(void)
1266 ToolkitTestApplication application;
1268 ImageView imageView = ImageView::New();
1269 DALI_TEST_CHECK( ! imageView.GetImage() );
1271 Image image = CreateBufferImage();
1272 imageView.SetImage( image );
1273 DALI_TEST_CHECK( imageView.GetImage() == image );
1278 int UtcDaliImageViewGetImageP2(void)
1280 ToolkitTestApplication application;
1282 BufferImage image = CreateBufferImage();
1283 ImageView imageView = ImageView::New( image );
1284 DALI_TEST_CHECK( imageView.GetImage() == image );
1289 int UtcDaliImageViewGetImageN(void)
1291 ToolkitTestApplication application;
1293 ImageView imageView = ImageView::New( TEST_IMAGE_FILE_NAME );
1294 DALI_TEST_CHECK( ! imageView.GetImage() );
1296 Image image = CreateBufferImage();
1297 imageView.SetImage( image );
1298 DALI_TEST_CHECK( imageView.GetImage() == image );
1300 imageView.SetImage( TEST_IMAGE_FILE_NAME );
1301 DALI_TEST_CHECK( ! imageView.GetImage() );