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-bitmap-loader.h>
22 #include <toolkit-event-thread-callback.h>
24 #include <dali-toolkit/dali-toolkit.h>
25 #include <dali/devel-api/scripting/scripting.h>
26 #include <dali-toolkit/devel-api/visuals/image-visual-properties-devel.h>
27 #include <dali/public-api/rendering/renderer.h>
29 #include <test-native-image.h>
33 using namespace Toolkit;
35 void utc_dali_toolkit_image_view_startup(void)
37 test_return_value = TET_UNDEF;
40 void utc_dali_toolkit_image_view_cleanup(void)
42 test_return_value = TET_PASS;
48 const char* VERTEX_SHADER = DALI_COMPOSE_SHADER(
49 attribute mediump vec2 aPosition;\n
50 varying mediump vec2 vTexCoord;\n
51 uniform mediump mat4 uMvpMatrix;\n
52 uniform mediump vec3 uSize;\n
56 mediump vec4 vertexPosition = vec4(aPosition, 0.0, 1.0);\n
57 vertexPosition.xyz *= uSize;\n
58 vertexPosition = uMvpMatrix * vertexPosition;\n
60 vTexCoord = aPosition + vec2(0.5);\n
61 gl_Position = vertexPosition;\n
65 const char* FRAGMENT_SHADER = DALI_COMPOSE_SHADER(
66 varying mediump vec2 vTexCoord;\n
67 uniform sampler2D sTexture;\n
68 uniform lowp vec4 uColor;\n
72 gl_FragColor = texture2D( sTexture, vTexCoord ) * uColor;\n
76 const char* TEST_IMAGE_FILE_NAME = "gallery_image_01.jpg";
77 const char* TEST_IMAGE_FILE_NAME2 = "gallery_image_02.jpg";
79 // resolution: 34*34, pixel format: RGBA8888
80 static const char* gImage_34_RGBA = TEST_RESOURCE_DIR "/icon-edit.png";
81 // resolution: 600*600, pixel format: RGB888
82 static const char* gImage_600_RGB = TEST_RESOURCE_DIR "/test-image-600.jpg";
84 // resolution: 50*50, frame count: 4, frame delay: 0.2 second for each frame
85 const char* TEST_GIF_FILE_NAME = TEST_RESOURCE_DIR "/anim.gif";
87 void TestImage( ImageView imageView, BufferImage image )
89 Property::Value value = imageView.GetProperty( imageView.GetPropertyIndex( "image" ) );
92 DALI_TEST_CHECK( value.Get( map ) );
94 DALI_TEST_CHECK( map.Find( "width" ) );
95 DALI_TEST_CHECK( map.Find( "height" ) );
96 DALI_TEST_CHECK( map.Find( "type" ) );
99 DALI_TEST_CHECK( map[ "width" ].Get( width ) );
100 DALI_TEST_EQUALS( (unsigned int)width, image.GetWidth(), TEST_LOCATION );
103 DALI_TEST_CHECK( map[ "height" ].Get( height ) );
104 DALI_TEST_EQUALS( (unsigned int)height, image.GetHeight(), TEST_LOCATION );
107 DALI_TEST_CHECK( map[ "type" ].Get( type ) );
108 DALI_TEST_EQUALS( type, "BufferImage", TEST_LOCATION );
111 void TestImage( ImageView imageView, ResourceImage image )
113 Property::Value value = imageView.GetProperty( imageView.GetPropertyIndex( "image" ) );
116 DALI_TEST_CHECK( value.Get( map ) );
118 if( map.Find( "width" ) )
121 DALI_TEST_CHECK( map[ "width" ].Get( width ) );
122 DALI_TEST_EQUALS( (unsigned int)width, image.GetWidth(), TEST_LOCATION );
125 if( map.Find( "height" ) )
128 DALI_TEST_CHECK( map[ "height" ].Get( height ) );
129 DALI_TEST_EQUALS( (unsigned int)height, image.GetHeight(), TEST_LOCATION );
132 DALI_TEST_CHECK( map.Find( "type" ) );
135 DALI_TEST_CHECK( map[ "type" ].Get( type ) );
136 DALI_TEST_EQUALS( type, "ResourceImage", TEST_LOCATION );
138 std::string filename;
139 DALI_TEST_CHECK( map[ "filename" ].Get( filename ) );
140 DALI_TEST_EQUALS( filename, image.GetUrl(), TEST_LOCATION );
143 void TestUrl( ImageView imageView, const std::string url )
145 Property::Value value = imageView.GetProperty( imageView.GetPropertyIndex( "image" ) );
147 std::string urlActual;
148 DALI_TEST_CHECK( value.Get( urlActual ) );
149 DALI_TEST_EQUALS( urlActual, url, TEST_LOCATION );
154 int UtcDaliImageViewNewP(void)
156 TestApplication application;
158 ImageView imageView = ImageView::New();
160 DALI_TEST_CHECK( imageView );
165 int UtcDaliImageViewNewImageP(void)
167 TestApplication application;
169 BufferImage image = CreateBufferImage( 100, 200, Vector4( 1.f, 1.f, 1.f, 1.f ) );
170 ImageView imageView = ImageView::New( image );
172 DALI_TEST_CHECK( imageView );
173 TestImage( imageView, image );
178 int UtcDaliImageViewNewUrlP(void)
180 TestApplication application;
182 ImageView imageView = ImageView::New( TEST_IMAGE_FILE_NAME );
183 DALI_TEST_CHECK( imageView );
185 TestUrl( imageView, TEST_IMAGE_FILE_NAME );
190 int UtcDaliImageViewConstructorP(void)
192 TestApplication application;
196 DALI_TEST_CHECK( !imageView );
201 int UtcDaliImageViewCopyConstructorP(void)
203 TestApplication application;
205 // Initialize an object, ref count == 1
206 ImageView imageView = ImageView::New();
208 ImageView copy( imageView );
209 DALI_TEST_CHECK( copy );
214 int UtcDaliImageViewAssignmentOperatorP(void)
216 TestApplication application;
218 ImageView imageView = ImageView::New();
220 ImageView copy( imageView );
221 DALI_TEST_CHECK( copy );
222 DALI_TEST_EQUALS( imageView, copy, TEST_LOCATION );
227 int UtcDaliImageViewDownCastP(void)
229 TestApplication application;
231 ImageView imageView = ImageView::New();
233 BaseHandle object(imageView);
235 ImageView imageView2 = ImageView::DownCast( object );
236 DALI_TEST_CHECK(imageView2);
238 ImageView imageView3 = DownCast< ImageView >( object );
239 DALI_TEST_CHECK(imageView3);
244 int UtcDaliImageViewDownCastN(void)
246 TestApplication application;
248 BaseHandle unInitializedObject;
250 ImageView imageView1 = ImageView::DownCast( unInitializedObject );
251 DALI_TEST_CHECK( !imageView1 );
253 ImageView imageView2 = DownCast< ImageView >( unInitializedObject );
254 DALI_TEST_CHECK( !imageView2 );
259 int UtcDaliImageViewTypeRegistry(void)
261 ToolkitTestApplication application;
263 TypeRegistry typeRegistry = TypeRegistry::Get();
264 DALI_TEST_CHECK( typeRegistry );
266 TypeInfo typeInfo = typeRegistry.GetTypeInfo( "ImageView" );
267 DALI_TEST_CHECK( typeInfo );
269 BaseHandle handle = typeInfo.CreateInstance();
270 DALI_TEST_CHECK( handle );
272 ImageView imageView = ImageView::DownCast( handle );
273 DALI_TEST_CHECK( imageView );
278 int UtcDaliImageViewSetGetProperty01(void)
280 ToolkitTestApplication application;
282 ImageView imageView = ImageView::New();
284 Property::Index idx = imageView.GetPropertyIndex( "image" );
285 DALI_TEST_EQUALS( idx, (Property::Index)ImageView::Property::IMAGE, TEST_LOCATION );
287 imageView.SetProperty( idx, TEST_IMAGE_FILE_NAME );
288 TestUrl( imageView, TEST_IMAGE_FILE_NAME );
293 int UtcDaliImageViewSetGetProperty02(void)
295 ToolkitTestApplication application;
297 Image image = CreateBufferImage( 10, 10, Color::WHITE );
298 ImageView imageView = ImageView::New(image);
299 Vector4 fullImageRect( 0.f, 0.f, 1.f, 1.f );
301 Stage::GetCurrent().Add( imageView );
303 application.SendNotification();
304 application.Render();
305 TestGlAbstraction& gl = application.GetGlAbstraction();
307 Vector4 pixelAreaUniform;
308 DALI_TEST_CHECK( gl.GetUniformValue<Vector4>( "pixelArea", pixelAreaUniform ) );
309 DALI_TEST_EQUALS( pixelAreaUniform, fullImageRect, TEST_LOCATION );
311 Property::Value value = imageView.GetProperty( ImageView::Property::PIXEL_AREA );
312 Vector4 pixelAreaValue;
313 DALI_TEST_CHECK( value.Get(pixelAreaValue) );
314 DALI_TEST_EQUALS( pixelAreaValue, fullImageRect, TEST_LOCATION );
316 Vector4 pixelAreaSet( 0.2f, 0.2f, 0.3f, 0.3f );
317 imageView.SetProperty( ImageView::Property::PIXEL_AREA, pixelAreaSet);
319 application.SendNotification();
320 application.Render();
322 value = imageView.GetProperty( ImageView::Property::PIXEL_AREA );
323 value.Get(pixelAreaValue);
324 DALI_TEST_EQUALS( pixelAreaValue, pixelAreaSet, TEST_LOCATION );
326 DALI_TEST_CHECK( gl.GetUniformValue<Vector4>( "pixelArea", pixelAreaUniform ) );
327 DALI_TEST_EQUALS( pixelAreaUniform, pixelAreaSet, TEST_LOCATION );
332 int UtcDaliImageViewSetGetProperty03(void)
334 ToolkitTestApplication application;
336 Image image = CreateBufferImage( 10, 10, Color::WHITE );
337 ImageView imageView = ImageView::New(image);
338 Stage::GetCurrent().Add( imageView );
339 application.SendNotification();
340 application.Render();
342 // conventional alpha blending
343 Renderer renderer = imageView.GetRendererAt( 0 );
344 Property::Value value = renderer.GetProperty( Renderer::Property::BLEND_PRE_MULTIPLIED_ALPHA );
346 DALI_TEST_CHECK( value.Get( enable ) );
347 DALI_TEST_CHECK( !enable );
349 // pre-multiplied alpha blending
350 imageView.SetProperty( Toolkit::ImageView::Property::PRE_MULTIPLIED_ALPHA, true );
351 application.SendNotification();
352 application.Render();
354 int srcFactorRgb = renderer.GetProperty<int>( Renderer::Property::BLEND_FACTOR_SRC_RGB );
355 int destFactorRgb = renderer.GetProperty<int>( Renderer::Property::BLEND_FACTOR_DEST_RGB );
356 int srcFactorAlpha = renderer.GetProperty<int>( Renderer::Property::BLEND_FACTOR_SRC_ALPHA );
357 int destFactorAlpha = renderer.GetProperty<int>( Renderer::Property::BLEND_FACTOR_DEST_ALPHA );
358 DALI_TEST_CHECK( srcFactorRgb == BlendFactor::ONE );
359 DALI_TEST_CHECK( destFactorRgb == BlendFactor::ONE_MINUS_SRC_ALPHA );
360 DALI_TEST_CHECK( srcFactorAlpha == BlendFactor::ONE );
361 DALI_TEST_CHECK( destFactorAlpha == BlendFactor::ONE );
363 value = renderer.GetProperty( Renderer::Property::BLEND_PRE_MULTIPLIED_ALPHA );
364 DALI_TEST_CHECK( value.Get( enable ) );
365 DALI_TEST_CHECK( enable );
370 int UtcDaliImageViewPixelArea(void)
372 // Test pixel area property
373 ToolkitTestApplication application;
375 // Gif image, use AnimatedImageVisual internally
376 // Atlasing is applied to pack multiple frames, use custom wrap mode
377 ImageView gifView = ImageView::New();
378 const Vector4 pixelAreaVisual( 0.f, 0.f, 2.f, 2.f );
379 gifView.SetProperty( ImageView::Property::IMAGE,
380 Property::Map().Add( ImageVisual::Property::URL, TEST_GIF_FILE_NAME )
381 .Add( ImageVisual::Property::PIXEL_AREA, pixelAreaVisual ) );
384 Stage stage = Stage::GetCurrent();
385 stage.Add( gifView );
388 application.SendNotification();
389 application.Render(16);
390 DALI_TEST_CHECK( gifView.GetRendererCount() == 1u );
392 const Vector4 fullTextureRect( 0.f, 0.f, 1.f, 1.f );
393 // test that the pixel area value defined in the visual property map is registered on renderer
394 Renderer renderer = gifView.GetRendererAt(0);
395 Property::Value pixelAreaValue = renderer.GetProperty( renderer.GetPropertyIndex( "pixelArea" ) );
396 DALI_TEST_EQUALS( pixelAreaValue.Get<Vector4>(), pixelAreaVisual, TEST_LOCATION );
398 // test that the shader has the default pixel area value registered.
399 Shader shader = renderer.GetShader();
400 pixelAreaValue = shader.GetProperty( shader.GetPropertyIndex( "pixelArea" ) );
401 DALI_TEST_EQUALS( pixelAreaValue.Get<Vector4>(), fullTextureRect, TEST_LOCATION );
403 // test that the uniform uses the pixelArea property on the renderer.
404 TestGlAbstraction& gl = application.GetGlAbstraction();
405 Vector4 pixelAreaUniform;
406 DALI_TEST_CHECK( gl.GetUniformValue<Vector4>( "pixelArea", pixelAreaUniform ) );
407 DALI_TEST_EQUALS( pixelAreaVisual, pixelAreaUniform, Math::MACHINE_EPSILON_100, TEST_LOCATION );
409 // set the pixelArea property on the control
410 const Vector4 pixelAreaControl( -1.f, -1.f, 3.f, 3.f );
411 gifView.SetProperty( ImageView::Property::PIXEL_AREA, pixelAreaControl );
412 application.SendNotification();
413 application.Render(16);
415 // check the pixelArea property on the control
416 pixelAreaValue = gifView.GetProperty( gifView.GetPropertyIndex( "pixelArea" ) );
417 DALI_TEST_EQUALS( pixelAreaValue.Get<Vector4>(), pixelAreaControl, TEST_LOCATION );
418 // test that the uniform uses the pixelArea property on the control.
419 DALI_TEST_CHECK( gl.GetUniformValue<Vector4>( "pixelArea", pixelAreaUniform ) );
420 DALI_TEST_EQUALS( pixelAreaControl, pixelAreaUniform, Math::MACHINE_EPSILON_100, TEST_LOCATION );
426 int UtcDaliImageViewAsyncLoadingWithoutAltasing(void)
428 ToolkitTestApplication application;
430 // Async loading, no atlasing for big size image
431 ImageView imageView = ImageView::New( gImage_600_RGB );
433 // By default, Aysnc loading is used
434 Stage::GetCurrent().Add( imageView );
435 application.SendNotification();
436 application.Render(16);
437 application.Render(16);
438 application.SendNotification();
440 // BitmapLoader is not used
441 BitmapLoader loader = BitmapLoader::GetLatestCreated();
442 DALI_TEST_CHECK( !loader );
447 int UtcDaliImageViewAsyncLoadingWithAtlasing(void)
449 ToolkitTestApplication application;
451 //Async loading, automatic atlasing for small size image
452 TraceCallStack& callStack = application.GetGlAbstraction().GetTextureTrace();
454 callStack.Enable(true);
456 Property::Map imageMap;
458 imageMap[ ImageVisual::Property::URL ] = gImage_34_RGBA;
459 imageMap[ ImageVisual::Property::DESIRED_HEIGHT ] = 34;
460 imageMap[ ImageVisual::Property::DESIRED_WIDTH ] = 34;
461 imageMap[ DevelImageVisual::Property::ATLASING] = true;
463 ImageView imageView = ImageView::New();
464 imageView.SetProperty( ImageView::Property::IMAGE, imageMap );
466 // By default, Aysnc loading is used
467 // loading is not started if the actor is offStage
469 Stage::GetCurrent().Add( imageView );
470 application.SendNotification();
471 application.Render(16);
472 application.Render(16);
473 application.SendNotification();
475 // loading started, this waits for the loader thread for max 30 seconds
476 DALI_TEST_EQUALS( Test::WaitForEventThreadTrigger( 1 ), true, TEST_LOCATION );
478 application.SendNotification();
479 application.Render(16);
481 callStack.Enable(false);
483 TraceCallStack::NamedParams params;
484 params["width"] = ToString(34);
485 params["height"] = ToString(34);
486 DALI_TEST_EQUALS( callStack.FindMethodAndParams( "TexSubImage2D", params ), true, TEST_LOCATION );
491 int UtcDaliImageViewAsyncLoadingWithAtlasing02(void)
493 ToolkitTestApplication application;
495 //Async loading, automatic atlasing for small size image
496 TraceCallStack& callStack = application.GetGlAbstraction().GetTextureTrace();
498 callStack.Enable(true);
500 Property::Map asyncLoadingMap;
501 asyncLoadingMap[ "url" ] = gImage_34_RGBA;
502 asyncLoadingMap[ "desiredHeight" ] = 34;
503 asyncLoadingMap[ "desiredWidth" ] = 34;
504 asyncLoadingMap[ "synchronousLoading" ] = false;
505 asyncLoadingMap[ "atlasing" ] = true;
507 ImageView imageView = ImageView::New();
508 imageView.SetProperty( ImageView::Property::IMAGE, asyncLoadingMap );
510 Stage::GetCurrent().Add( imageView );
511 application.SendNotification();
512 application.Render(16);
513 application.Render(16);
514 application.SendNotification();
516 // loading started, this waits for the loader thread for max 30 seconds
517 DALI_TEST_EQUALS( Test::WaitForEventThreadTrigger( 1 ), true, TEST_LOCATION );
519 application.SendNotification();
520 application.Render(16);
522 callStack.Enable(false);
524 TraceCallStack::NamedParams params;
525 params["width"] = ToString(34);
526 params["height"] = ToString(34);
527 DALI_TEST_EQUALS( callStack.FindMethodAndParams( "TexSubImage2D", params ), true, TEST_LOCATION );
532 int UtcDaliImageViewSyncLoading(void)
534 ToolkitTestApplication application;
536 tet_infoline("ImageView Testing sync loading and size using index key property map");
538 Property::Map syncLoadingMap;
539 syncLoadingMap[ ImageVisual::Property::SYNCHRONOUS_LOADING ] = true;
540 syncLoadingMap[ DevelImageVisual::Property::ATLASING ] = true;
542 // Sync loading, no atlasing for big size image
544 ImageView imageView = ImageView::New();
546 // Sync loading is used
547 syncLoadingMap[ ImageVisual::Property::URL ] = gImage_600_RGB;
548 imageView.SetProperty( ImageView::Property::IMAGE, syncLoadingMap );
551 // BitmapLoader is used, and the loading is started immediately even the actor is not on stage.
552 BitmapLoader loader = BitmapLoader::GetLatestCreated();
553 DALI_TEST_CHECK( loader );
556 // Sync loading, automatic atlasing for small size image
558 BitmapLoader::ResetLatestCreated();
559 TraceCallStack& callStack = application.GetGlAbstraction().GetTextureTrace();
561 callStack.Enable(true);
563 ImageView imageView = ImageView::New( );
564 // Sync loading is used
565 syncLoadingMap[ ImageVisual::Property::URL ] = gImage_34_RGBA;
566 syncLoadingMap[ ImageVisual::Property::DESIRED_HEIGHT ] = 34;
567 syncLoadingMap[ ImageVisual::Property::DESIRED_WIDTH ] = 34;
568 imageView.SetProperty( ImageView::Property::IMAGE, syncLoadingMap );
570 // loading is started even if the actor is offStage
571 BitmapLoader loader = BitmapLoader::GetLatestCreated();
572 DALI_TEST_CHECK( loader );
574 loader.WaitForLoading();
576 DALI_TEST_CHECK( loader.IsLoaded() );
578 Stage::GetCurrent().Add( imageView );
579 application.SendNotification();
580 application.Render(16);
582 TraceCallStack::NamedParams params;
583 params["width"] = ToString(34);
584 params["height"] = ToString(34);
585 DALI_TEST_EQUALS( callStack.FindMethodAndParams( "TexSubImage2D", params ),
586 true, TEST_LOCATION );
592 int UtcDaliImageViewSyncLoading02(void)
594 ToolkitTestApplication application;
596 tet_infoline("ImageView Testing sync loading and size using string key property map");
598 // Sync loading, automatic atlasing for small size image
600 BitmapLoader::ResetLatestCreated();
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 // loading is started even if the actor is offStage
617 BitmapLoader loader = BitmapLoader::GetLatestCreated();
618 DALI_TEST_CHECK( loader );
620 loader.WaitForLoading();
622 DALI_TEST_CHECK( loader.IsLoaded() );
624 Stage::GetCurrent().Add( imageView );
625 application.SendNotification();
626 application.Render(16);
628 TraceCallStack::NamedParams params;
629 params["width"] = ToString(34);
630 params["height"] = ToString(34);
631 DALI_TEST_EQUALS( callStack.FindMethodAndParams( "TexSubImage2D", params ),
632 true, TEST_LOCATION );
637 int UtcDaliImageViewSizeWithBackground(void)
639 ToolkitTestApplication application;
643 Image image = CreateBufferImage( width, height, Vector4(1.f, 1.f, 1.f, 1.f) );
644 ImageView imageView = ImageView::New();
645 imageView.SetBackgroundImage( image );
647 Stage::GetCurrent().Add( imageView );
648 application.SendNotification();
649 application.Render();
651 DALI_TEST_EQUALS( imageView.GetCurrentSize().width, (float)width, TEST_LOCATION );
652 DALI_TEST_EQUALS( imageView.GetCurrentSize().height, (float)height, TEST_LOCATION );
657 int UtcDaliImageViewSizeWithBackgroundAndImage(void)
659 ToolkitTestApplication application;
661 int widthBackground = 100;
662 int heightBackground = 200;
665 Image imageBackground = CreateBufferImage( widthBackground, heightBackground, Vector4(1.f, 1.f, 1.f, 1.f) );
666 Image image = CreateBufferImage( width, height, Vector4(1.f, 1.f, 1.f, 1.f) );
668 ImageView imageView = ImageView::New();
669 imageView.SetBackgroundImage( imageBackground );
670 imageView.SetImage( image );
672 Stage::GetCurrent().Add( imageView );
673 application.SendNotification();
674 application.Render();
676 DALI_TEST_EQUALS( imageView.GetCurrentSize().width, (float)width, TEST_LOCATION );
677 DALI_TEST_EQUALS( imageView.GetCurrentSize().height, (float)height, TEST_LOCATION );
682 int UtcDaliImageViewHeightForWidthBackground(void)
684 ToolkitTestApplication application;
686 int widthBackground = 100;
687 int heightBackground = 200;
688 Image imageBackground = CreateBufferImage( widthBackground, heightBackground, Vector4(1.f, 1.f, 1.f, 1.f) );
690 ImageView imageView = ImageView::New();
691 imageView.SetBackgroundImage( imageBackground );
693 Stage::GetCurrent().Add( imageView );
694 application.SendNotification();
695 application.Render();
697 Control control = Control::DownCast( imageView );
698 DALI_TEST_CHECK( control );
699 DALI_TEST_EQUALS( imageView.GetHeightForWidth( 123.f ), control.GetHeightForWidth( 123.f ), TEST_LOCATION );
700 DALI_TEST_EQUALS( imageView.GetWidthForHeight( 321.f ), control.GetWidthForHeight( 321.f ), TEST_LOCATION );
705 int UtcDaliImageViewHeightForWidthBackgroundAndImage(void)
707 ToolkitTestApplication application;
709 int widthBackground = 100;
710 int heightBackground = 200;
713 Image imageBackground = CreateBufferImage( widthBackground, heightBackground, Vector4(1.f, 1.f, 1.f, 1.f) );
714 Image image = CreateBufferImage( width, height, Vector4(1.f, 1.f, 1.f, 1.f) );
716 ImageView imageView = ImageView::New();
717 imageView.SetBackgroundImage( imageBackground );
718 imageView.SetImage( image );
720 Stage::GetCurrent().Add( imageView );
721 application.SendNotification();
722 application.Render();
724 DALI_TEST_EQUALS( imageView.GetHeightForWidth( width ), (float)height, TEST_LOCATION );
725 DALI_TEST_EQUALS( imageView.GetWidthForHeight( height ), (float)width, TEST_LOCATION );
730 int UtcDaliImageViewSetBufferImage(void)
732 ToolkitTestApplication application;
736 BufferImage image1 = CreateBufferImage( width1, height1, Vector4( 1.f, 1.f, 1.f, 1.f ) );
737 ImageView imageView = ImageView::New();
738 imageView.SetImage( image1 );
740 TestImage( imageView, image1 );
744 BufferImage image2 = CreateBufferImage( width2, height2, Vector4( 1.f, 1.f, 1.f, 1.f ) );
745 imageView.SetImage( image2 );
747 TestImage( imageView, image2 );
752 int UtcDaliImageViewSetImageUrl(void)
754 ToolkitTestApplication application;
756 ImageView imageView = ImageView::New();
757 imageView.SetImage( TEST_IMAGE_FILE_NAME );
758 TestUrl( imageView, TEST_IMAGE_FILE_NAME );
761 imageView.SetImage( TEST_IMAGE_FILE_NAME2 );
762 TestUrl( imageView, TEST_IMAGE_FILE_NAME2 );
767 int UtcDaliImageViewSetImageOnstageP(void)
769 ToolkitTestApplication application;
771 ImageView imageView = ImageView::New();
773 Stage::GetCurrent().Add( imageView );
774 application.SendNotification();
775 application.Render();
777 ResourceImage image1 = ResourceImage::New( TEST_IMAGE_FILE_NAME );
778 imageView.SetImage( image1 );
779 TestImage( imageView, image1 );
783 BufferImage image2 = CreateBufferImage( width, height, Vector4( 1.f, 1.f, 1.f, 1.f ) );
784 imageView.SetImage( image2 );
785 TestImage( imageView, image2 );
790 int UtcDaliImageViewSetImageOnstageN(void)
792 ToolkitTestApplication application;
794 ImageView imageView = ImageView::New();
796 Stage::GetCurrent().Add( imageView );
797 application.SendNotification();
798 application.Render();
800 ResourceImage image1 = ResourceImage::New( TEST_IMAGE_FILE_NAME );
801 imageView.SetImage( image1 );
802 TestImage( imageView, image1 );
805 imageView.SetImage( image2 );
807 Property::Value value = imageView.GetProperty( imageView.GetPropertyIndex( "image" ) );
809 //the value should be empty
811 DALI_TEST_CHECK( !value.Get( url ) );
814 DALI_TEST_CHECK( !value.Get( map ) );
819 int UtcDaliImageViewSetImageOffstageP(void)
821 ToolkitTestApplication application;
823 ImageView imageView = ImageView::New();
825 Stage::GetCurrent().Add( imageView );
826 application.SendNotification();
827 application.Render();
828 Stage::GetCurrent().Remove( imageView );
830 ResourceImage image1 = ResourceImage::New( TEST_IMAGE_FILE_NAME );
831 imageView.SetImage( image1 );
832 TestImage( imageView, image1 );
836 BufferImage image2 = CreateBufferImage( width, height, Vector4( 1.f, 1.f, 1.f, 1.f ) );
837 imageView.SetImage( image2 );
838 TestImage( imageView, image2 );
843 int UtcDaliImageViewSetImageOffstageN(void)
845 ToolkitTestApplication application;
847 ImageView imageView = ImageView::New();
849 Stage::GetCurrent().Add( imageView );
850 application.SendNotification();
851 application.Render();
852 Stage::GetCurrent().Remove( imageView );
854 ResourceImage image1 = ResourceImage::New( TEST_IMAGE_FILE_NAME );
855 imageView.SetImage( image1 );
856 TestImage( imageView, image1 );
859 imageView.SetImage( image2 );
861 Property::Value value = imageView.GetProperty( imageView.GetPropertyIndex( "image" ) );
863 //the value should be empty
865 DALI_TEST_CHECK( !value.Get( url ) );
868 DALI_TEST_CHECK( !value.Get( map ) );
873 int UtcDaliImageViewSetImageN(void)
875 ToolkitTestApplication application;
878 ImageView imageView = ImageView::New();
879 imageView.SetImage( image1 );
881 Property::Value value = imageView.GetProperty( imageView.GetPropertyIndex( "image" ) );
883 //the value should be empty
885 DALI_TEST_CHECK( !value.Get( url ) );
888 DALI_TEST_CHECK( !value.Get( map ) );
890 std::string resource_url;
891 Property::Value val = imageView.GetProperty( imageView.GetPropertyIndex( "image" ) );
892 DALI_TEST_CHECK( !val.Get( resource_url ) );
897 int UtcDaliImageViewSetImageTypeChangesP(void)
899 ToolkitTestApplication application;
901 ImageView imageView = ImageView::New();
907 Property::Value value = imageView.GetProperty( imageView.GetPropertyIndex( "image" ) );
908 DALI_TEST_CHECK( ! value.Get( url ) ); // Value should be empty
909 DALI_TEST_CHECK( ! value.Get( map ) ); // Value should be empty
912 imageView.SetImage( "TEST_URL" );
913 value = imageView.GetProperty( imageView.GetPropertyIndex( "image" ) );
915 DALI_TEST_CHECK( value.Get( url ) ); // Value should NOT be empty
916 DALI_TEST_CHECK( ! value.Get( map ) ); // Value should be empty
918 // Set an empty Image
919 imageView.SetImage( Image() );
920 value = imageView.GetProperty( imageView.GetPropertyIndex( "image" ) );
922 DALI_TEST_CHECK( ! value.Get( url ) ); // Value should be empty
923 DALI_TEST_CHECK( ! value.Get( map ) ); // Value should be empty
926 ResourceImage image1 = ResourceImage::New( TEST_IMAGE_FILE_NAME );
927 imageView.SetImage( image1 );
928 value = imageView.GetProperty( imageView.GetPropertyIndex( "image" ) );
930 DALI_TEST_CHECK( ! value.Get( url ) ); // Value should be empty
931 DALI_TEST_CHECK( value.Get( map ) ); // Value should NOT be empty
934 imageView.SetImage( "" );
935 value = imageView.GetProperty( imageView.GetPropertyIndex( "image" ) );
937 DALI_TEST_CHECK( ! value.Get( url ) ); // Value should be empty
938 DALI_TEST_CHECK( ! value.Get( map ) ); // Value should be empty
943 int UtcDaliImageViewResourceUrlP(void)
945 ToolkitTestApplication application;
947 ImageView imageView = ImageView::New();
948 DALI_TEST_CHECK( imageView.GetProperty( ImageView::Property::RESOURCE_URL ).Get< std::string >().empty() );
950 imageView.SetProperty( ImageView::Property::RESOURCE_URL, "TestString" );
951 DALI_TEST_EQUALS( imageView.GetProperty( ImageView::Property::RESOURCE_URL ).Get< std::string >(), "TestString", TEST_LOCATION );
956 // Scenarios 1: ImageView from regular image
957 int UtcDaliImageViewSetImageBufferImage(void)
959 ToolkitTestApplication application;
961 ImageView imageView = ImageView::New();
962 Stage::GetCurrent().Add( imageView );
964 TestGlAbstraction& gl = application.GetGlAbstraction();
965 gl.EnableTextureCallTrace( true );
967 std::vector< GLuint > ids;
969 application.GetGlAbstraction().SetNextTextureIds( ids );
973 BufferImage image = CreateBufferImage( width, height, Color::WHITE );
975 imageView.SetImage( image );
977 application.SendNotification();
978 application.Render();
980 DALI_TEST_CHECK( gl.GetTextureTrace().FindMethod("BindTexture") );
982 std::stringstream params;
983 params << GL_TEXTURE_2D << ", " << 23;
984 DALI_TEST_CHECK( gl.GetTextureTrace().FindMethodAndParams("BindTexture", params.str()) );
989 // Scenarios 2: ImageView from Native image
990 int UtcDaliImageViewSetImageNativeImage(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 TestNativeImagePointer nativeImageInterface = TestNativeImage::New( width, height );
1007 NativeImage nativeImage = NativeImage::New( *(nativeImageInterface.Get()) );
1009 imageView.SetImage( nativeImage );
1010 application.SendNotification();
1011 application.Render();
1013 DALI_TEST_CHECK( gl.GetTextureTrace().FindMethod("BindTexture") );
1015 std::stringstream params;
1016 params << GL_TEXTURE_EXTERNAL_OES << ", " << 23;
1017 DALI_TEST_CHECK( gl.GetTextureTrace().FindMethodAndParams("BindTexture", params.str()) );
1022 // Scenarios 3: ImageView initially from regular image but then SetImage called with Native image
1023 int UtcDaliImageViewSetImageBufferImageToNativeImage(void)
1025 ToolkitTestApplication application;
1029 BufferImage image = CreateBufferImage( width, height, Color::WHITE );
1031 ImageView imageView = ImageView::New( image );
1032 Stage::GetCurrent().Add( imageView );
1034 TestGlAbstraction& gl = application.GetGlAbstraction();
1035 gl.EnableTextureCallTrace( true );
1037 std::vector< GLuint > ids;
1038 ids.push_back( 23 );
1039 application.GetGlAbstraction().SetNextTextureIds( ids );
1041 application.SendNotification();
1042 application.Render();
1044 DALI_TEST_CHECK( gl.GetTextureTrace().FindMethod("BindTexture") );
1046 std::stringstream params;
1047 params << GL_TEXTURE_2D << ", " << 23;
1048 DALI_TEST_CHECK( gl.GetTextureTrace().FindMethodAndParams("BindTexture", params.str()) );
1052 TestNativeImagePointer nativeImageInterface = TestNativeImage::New( width, height );
1053 NativeImage nativeImage = NativeImage::New( *(nativeImageInterface.Get()) );
1054 imageView.SetImage( nativeImage );
1057 ids.push_back( 24 );
1058 application.GetGlAbstraction().SetNextTextureIds( ids );
1060 application.SendNotification();
1061 application.Render();
1063 DALI_TEST_CHECK( gl.GetTextureTrace().FindMethod("BindTexture") );
1065 std::stringstream nextTextureParams;
1066 nextTextureParams << GL_TEXTURE_EXTERNAL_OES << ", " << 24;
1067 DALI_TEST_CHECK( gl.GetTextureTrace().FindMethodAndParams("BindTexture", nextTextureParams.str()) );
1072 // Scenarios 4: ImageView initially from Native image but then SetImage called with regular image
1073 int UtcDaliImageViewSetImageNativeImageToBufferImage(void)
1075 ToolkitTestApplication application;
1079 TestNativeImagePointer nativeImageInterface = TestNativeImage::New( width, height );
1080 NativeImage nativeImage = NativeImage::New( *(nativeImageInterface.Get()) );
1082 ImageView imageView = ImageView::New( nativeImage );
1083 Stage::GetCurrent().Add( imageView );
1085 TestGlAbstraction& gl = application.GetGlAbstraction();
1086 gl.EnableTextureCallTrace( true );
1088 std::vector< GLuint > ids;
1089 ids.push_back( 23 );
1090 application.GetGlAbstraction().SetNextTextureIds( ids );
1092 application.SendNotification();
1093 application.Render();
1095 DALI_TEST_CHECK( gl.GetTextureTrace().FindMethod("BindTexture") );
1097 std::stringstream params;
1098 params << GL_TEXTURE_EXTERNAL_OES << ", " << 23;
1099 DALI_TEST_CHECK( gl.GetTextureTrace().FindMethodAndParams("BindTexture", params.str()) );
1103 BufferImage image = CreateBufferImage( width, height, Color::WHITE );
1104 imageView.SetImage( image );
1107 ids.push_back( 24 );
1108 application.GetGlAbstraction().SetNextTextureIds( ids );
1110 application.SendNotification();
1111 application.Render();
1113 DALI_TEST_CHECK( gl.GetTextureTrace().FindMethod("BindTexture") );
1115 std::stringstream nextTextureParams;
1116 nextTextureParams << GL_TEXTURE_2D << ", " << 24;
1117 DALI_TEST_CHECK( gl.GetTextureTrace().FindMethodAndParams("BindTexture", nextTextureParams.str()) );
1122 // Scenarios 5: ImageView from Native image with custom shader
1123 int UtcDaliImageViewSetImageNativeImageWithCustomShader(void)
1125 ToolkitTestApplication application;
1130 Property::Map customShader;
1131 customShader.Insert( "vertexShader", VERTEX_SHADER );
1132 customShader.Insert( "fragmentShader", FRAGMENT_SHADER );
1134 Property::Array shaderHints;
1135 shaderHints.PushBack( "requiresSelfDepthTest" );
1136 shaderHints.PushBack( "outputIsTransparent" );
1137 shaderHints.PushBack( "outputIsOpaque" );
1138 shaderHints.PushBack( "modifiesGeometry" );
1140 customShader.Insert( "hints", shaderHints );
1143 map.Insert( "shader", customShader );
1145 TestNativeImagePointer nativeImageInterface = TestNativeImage::New( width, height );
1146 NativeImage nativeImage = NativeImage::New( *(nativeImageInterface.Get()) );
1148 ImageView imageView = ImageView::New( nativeImage );
1149 imageView.SetProperty( ImageView::Property::IMAGE, map );
1150 Stage::GetCurrent().Add( imageView );
1152 TestGlAbstraction& gl = application.GetGlAbstraction();
1153 gl.EnableTextureCallTrace( true );
1155 std::vector< GLuint > ids;
1156 ids.push_back( 23 );
1157 application.GetGlAbstraction().SetNextTextureIds( ids );
1159 application.SendNotification();
1160 application.Render();
1162 DALI_TEST_CHECK( gl.GetTextureTrace().FindMethod("BindTexture") );
1164 std::stringstream params;
1165 params << GL_TEXTURE_EXTERNAL_OES << ", " << 23;
1166 DALI_TEST_CHECK( gl.GetTextureTrace().FindMethodAndParams("BindTexture", params.str()) );
1171 // Scenarios 6: ImageView initially from regular image with custom shader but then SetImage called with Native
1172 int UtcDaliImageViewSetImageBufferImageWithCustomShaderToNativeImage(void)
1174 ToolkitTestApplication application;
1179 Property::Map customShader;
1180 customShader.Insert( "vertexShader", VERTEX_SHADER );
1181 customShader.Insert( "fragmentShader", FRAGMENT_SHADER );
1183 Property::Array shaderHints;
1184 shaderHints.PushBack( "requiresSelfDepthTest" );
1185 shaderHints.PushBack( "outputIsTransparent" );
1186 shaderHints.PushBack( "outputIsOpaque" );
1187 shaderHints.PushBack( "modifiesGeometry" );
1189 customShader.Insert( "hints", shaderHints );
1192 map.Insert( "shader", customShader );
1194 BufferImage image = CreateBufferImage( width, height, Color::WHITE );
1196 ImageView imageView = ImageView::New( image );
1197 imageView.SetProperty( ImageView::Property::IMAGE, map );
1198 Stage::GetCurrent().Add( imageView );
1200 TestGlAbstraction& gl = application.GetGlAbstraction();
1201 gl.EnableTextureCallTrace( true );
1203 std::vector< GLuint > ids;
1204 ids.push_back( 23 );
1205 application.GetGlAbstraction().SetNextTextureIds( ids );
1207 application.SendNotification();
1208 application.Render();
1210 DALI_TEST_CHECK( gl.GetTextureTrace().FindMethod("BindTexture") );
1212 std::stringstream params;
1213 params << GL_TEXTURE_2D << ", " << 23;
1214 DALI_TEST_CHECK( gl.GetTextureTrace().FindMethodAndParams("BindTexture", params.str()) );
1216 TestNativeImagePointer nativeImageInterface = TestNativeImage::New( width, height );
1217 NativeImage nativeImage = NativeImage::New( *(nativeImageInterface.Get()) );
1218 imageView.SetImage( nativeImage );
1221 ids.push_back( 24 );
1222 application.GetGlAbstraction().SetNextTextureIds( ids );
1224 application.SendNotification();
1225 application.Render();
1227 DALI_TEST_CHECK( gl.GetTextureTrace().FindMethod("BindTexture") );
1229 std::stringstream nativeImageParams;
1230 nativeImageParams << GL_TEXTURE_EXTERNAL_OES << ", " << 24;
1231 DALI_TEST_CHECK( gl.GetTextureTrace().FindMethodAndParams("BindTexture", nativeImageParams.str()) );
1237 int UtcDaliImageViewGetImageP1(void)
1239 ToolkitTestApplication application;
1241 ImageView imageView = ImageView::New();
1242 DALI_TEST_CHECK( ! imageView.GetImage() );
1244 Image image = CreateBufferImage();
1245 imageView.SetImage( image );
1246 DALI_TEST_CHECK( imageView.GetImage() == image );
1251 int UtcDaliImageViewGetImageP2(void)
1253 ToolkitTestApplication application;
1255 BufferImage image = CreateBufferImage();
1256 ImageView imageView = ImageView::New( image );
1257 DALI_TEST_CHECK( imageView.GetImage() == image );
1262 int UtcDaliImageViewGetImageN(void)
1264 ToolkitTestApplication application;
1266 ImageView imageView = ImageView::New( TEST_IMAGE_FILE_NAME );
1267 DALI_TEST_CHECK( ! imageView.GetImage() );
1269 Image image = CreateBufferImage();
1270 imageView.SetImage( image );
1271 DALI_TEST_CHECK( imageView.GetImage() == image );
1273 imageView.SetImage( TEST_IMAGE_FILE_NAME );
1274 DALI_TEST_CHECK( ! imageView.GetImage() );