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/public-api/rendering/renderer.h>
28 #include <test-native-image.h>
32 using namespace Toolkit;
34 void utc_dali_toolkit_image_view_startup(void)
36 test_return_value = TET_UNDEF;
39 void utc_dali_toolkit_image_view_cleanup(void)
41 test_return_value = TET_PASS;
47 const char* VERTEX_SHADER = DALI_COMPOSE_SHADER(
48 attribute mediump vec2 aPosition;\n
49 varying mediump vec2 vTexCoord;\n
50 uniform mediump mat4 uMvpMatrix;\n
51 uniform mediump vec3 uSize;\n
55 mediump vec4 vertexPosition = vec4(aPosition, 0.0, 1.0);\n
56 vertexPosition.xyz *= uSize;\n
57 vertexPosition = uMvpMatrix * vertexPosition;\n
59 vTexCoord = aPosition + vec2(0.5);\n
60 gl_Position = vertexPosition;\n
64 const char* FRAGMENT_SHADER = DALI_COMPOSE_SHADER(
65 varying mediump vec2 vTexCoord;\n
66 uniform sampler2D sTexture;\n
67 uniform lowp vec4 uColor;\n
71 gl_FragColor = texture2D( sTexture, vTexCoord ) * uColor;\n
75 const char* TEST_IMAGE_FILE_NAME = "gallery_image_01.jpg";
76 const char* TEST_IMAGE_FILE_NAME2 = "gallery_image_02.jpg";
78 // resolution: 34*34, pixel format: RGBA8888
79 static const char* gImage_34_RGBA = TEST_RESOURCE_DIR "/icon-edit.png";
80 // resolution: 600*600, pixel format: RGB888
81 static const char* gImage_600_RGB = TEST_RESOURCE_DIR "/test-image-600.jpg";
83 // resolution: 50*50, frame count: 4, frame delay: 0.2 second for each frame
84 const char* TEST_GIF_FILE_NAME = TEST_RESOURCE_DIR "/anim.gif";
86 void TestImage( ImageView imageView, BufferImage image )
88 Property::Value value = imageView.GetProperty( imageView.GetPropertyIndex( "image" ) );
91 DALI_TEST_CHECK( value.Get( map ) );
93 DALI_TEST_CHECK( map.Find( "width" ) );
94 DALI_TEST_CHECK( map.Find( "height" ) );
95 DALI_TEST_CHECK( map.Find( "type" ) );
98 DALI_TEST_CHECK( map[ "width" ].Get( width ) );
99 DALI_TEST_EQUALS( (unsigned int)width, image.GetWidth(), TEST_LOCATION );
102 DALI_TEST_CHECK( map[ "height" ].Get( height ) );
103 DALI_TEST_EQUALS( (unsigned int)height, image.GetHeight(), TEST_LOCATION );
106 DALI_TEST_CHECK( map[ "type" ].Get( type ) );
107 DALI_TEST_EQUALS( type, "BufferImage", TEST_LOCATION );
110 void TestImage( ImageView imageView, ResourceImage image )
112 Property::Value value = imageView.GetProperty( imageView.GetPropertyIndex( "image" ) );
115 DALI_TEST_CHECK( value.Get( map ) );
117 if( map.Find( "width" ) )
120 DALI_TEST_CHECK( map[ "width" ].Get( width ) );
121 DALI_TEST_EQUALS( (unsigned int)width, image.GetWidth(), TEST_LOCATION );
124 if( map.Find( "height" ) )
127 DALI_TEST_CHECK( map[ "height" ].Get( height ) );
128 DALI_TEST_EQUALS( (unsigned int)height, image.GetHeight(), TEST_LOCATION );
131 DALI_TEST_CHECK( map.Find( "type" ) );
134 DALI_TEST_CHECK( map[ "type" ].Get( type ) );
135 DALI_TEST_EQUALS( type, "ResourceImage", TEST_LOCATION );
137 std::string filename;
138 DALI_TEST_CHECK( map[ "filename" ].Get( filename ) );
139 DALI_TEST_EQUALS( filename, image.GetUrl(), TEST_LOCATION );
142 void TestUrl( ImageView imageView, const std::string url )
144 Property::Value value = imageView.GetProperty( imageView.GetPropertyIndex( "image" ) );
146 std::string urlActual;
147 DALI_TEST_CHECK( value.Get( urlActual ) );
148 DALI_TEST_EQUALS( urlActual, url, TEST_LOCATION );
153 int UtcDaliImageViewNewP(void)
155 TestApplication application;
157 ImageView imageView = ImageView::New();
159 DALI_TEST_CHECK( imageView );
164 int UtcDaliImageViewNewImageP(void)
166 TestApplication application;
168 BufferImage image = CreateBufferImage( 100, 200, Vector4( 1.f, 1.f, 1.f, 1.f ) );
169 ImageView imageView = ImageView::New( image );
171 DALI_TEST_CHECK( imageView );
172 TestImage( imageView, image );
177 int UtcDaliImageViewNewUrlP(void)
179 TestApplication application;
181 ImageView imageView = ImageView::New( TEST_IMAGE_FILE_NAME );
182 DALI_TEST_CHECK( imageView );
184 TestUrl( imageView, TEST_IMAGE_FILE_NAME );
189 int UtcDaliImageViewConstructorP(void)
191 TestApplication application;
195 DALI_TEST_CHECK( !imageView );
200 int UtcDaliImageViewCopyConstructorP(void)
202 TestApplication application;
204 // Initialize an object, ref count == 1
205 ImageView imageView = ImageView::New();
207 ImageView copy( imageView );
208 DALI_TEST_CHECK( copy );
213 int UtcDaliImageViewAssignmentOperatorP(void)
215 TestApplication application;
217 ImageView imageView = ImageView::New();
219 ImageView copy( imageView );
220 DALI_TEST_CHECK( copy );
221 DALI_TEST_EQUALS( imageView, copy, TEST_LOCATION );
226 int UtcDaliImageViewDownCastP(void)
228 TestApplication application;
230 ImageView imageView = ImageView::New();
232 BaseHandle object(imageView);
234 ImageView imageView2 = ImageView::DownCast( object );
235 DALI_TEST_CHECK(imageView2);
237 ImageView imageView3 = DownCast< ImageView >( object );
238 DALI_TEST_CHECK(imageView3);
243 int UtcDaliImageViewDownCastN(void)
245 TestApplication application;
247 BaseHandle unInitializedObject;
249 ImageView imageView1 = ImageView::DownCast( unInitializedObject );
250 DALI_TEST_CHECK( !imageView1 );
252 ImageView imageView2 = DownCast< ImageView >( unInitializedObject );
253 DALI_TEST_CHECK( !imageView2 );
258 int UtcDaliImageViewTypeRegistry(void)
260 ToolkitTestApplication application;
262 TypeRegistry typeRegistry = TypeRegistry::Get();
263 DALI_TEST_CHECK( typeRegistry );
265 TypeInfo typeInfo = typeRegistry.GetTypeInfo( "ImageView" );
266 DALI_TEST_CHECK( typeInfo );
268 BaseHandle handle = typeInfo.CreateInstance();
269 DALI_TEST_CHECK( handle );
271 ImageView imageView = ImageView::DownCast( handle );
272 DALI_TEST_CHECK( imageView );
277 int UtcDaliImageViewSetGetProperty01(void)
279 ToolkitTestApplication application;
281 ImageView imageView = ImageView::New();
283 Property::Index idx = imageView.GetPropertyIndex( "image" );
284 DALI_TEST_EQUALS( idx, (Property::Index)ImageView::Property::IMAGE, TEST_LOCATION );
286 imageView.SetProperty( idx, TEST_IMAGE_FILE_NAME );
287 TestUrl( imageView, TEST_IMAGE_FILE_NAME );
292 int UtcDaliImageViewSetGetProperty02(void)
294 ToolkitTestApplication application;
296 Image image = CreateBufferImage( 10, 10, Color::WHITE );
297 ImageView imageView = ImageView::New(image);
298 Vector4 fullImageRect( 0.f, 0.f, 1.f, 1.f );
300 Stage::GetCurrent().Add( imageView );
302 application.SendNotification();
303 application.Render();
304 TestGlAbstraction& gl = application.GetGlAbstraction();
306 Vector4 pixelAreaUniform;
307 DALI_TEST_CHECK( gl.GetUniformValue<Vector4>( "pixelArea", pixelAreaUniform ) );
308 DALI_TEST_EQUALS( pixelAreaUniform, fullImageRect, TEST_LOCATION );
310 Property::Value value = imageView.GetProperty( ImageView::Property::PIXEL_AREA );
311 Vector4 pixelAreaValue;
312 DALI_TEST_CHECK( value.Get(pixelAreaValue) );
313 DALI_TEST_EQUALS( pixelAreaValue, fullImageRect, TEST_LOCATION );
315 Vector4 pixelAreaSet( 0.2f, 0.2f, 0.3f, 0.3f );
316 imageView.SetProperty( ImageView::Property::PIXEL_AREA, pixelAreaSet);
318 application.SendNotification();
319 application.Render();
321 value = imageView.GetProperty( ImageView::Property::PIXEL_AREA );
322 value.Get(pixelAreaValue);
323 DALI_TEST_EQUALS( pixelAreaValue, pixelAreaSet, TEST_LOCATION );
325 DALI_TEST_CHECK( gl.GetUniformValue<Vector4>( "pixelArea", pixelAreaUniform ) );
326 DALI_TEST_EQUALS( pixelAreaUniform, pixelAreaSet, TEST_LOCATION );
331 int UtcDaliImageViewSetGetProperty03(void)
333 ToolkitTestApplication application;
335 Image image = CreateBufferImage( 10, 10, Color::WHITE );
336 ImageView imageView = ImageView::New(image);
337 Stage::GetCurrent().Add( imageView );
338 application.SendNotification();
339 application.Render();
341 // conventional alpha blending
342 Renderer renderer = imageView.GetRendererAt( 0 );
343 Property::Value value = renderer.GetProperty( Renderer::Property::BLEND_PRE_MULTIPLIED_ALPHA );
345 DALI_TEST_CHECK( value.Get( enable ) );
346 DALI_TEST_CHECK( !enable );
348 // pre-multiplied alpha blending
349 imageView.SetProperty( Toolkit::ImageView::Property::PRE_MULTIPLIED_ALPHA, true );
350 application.SendNotification();
351 application.Render();
353 int srcFactorRgb = renderer.GetProperty<int>( Renderer::Property::BLEND_FACTOR_SRC_RGB );
354 int destFactorRgb = renderer.GetProperty<int>( Renderer::Property::BLEND_FACTOR_DEST_RGB );
355 int srcFactorAlpha = renderer.GetProperty<int>( Renderer::Property::BLEND_FACTOR_SRC_ALPHA );
356 int destFactorAlpha = renderer.GetProperty<int>( Renderer::Property::BLEND_FACTOR_DEST_ALPHA );
357 DALI_TEST_CHECK( srcFactorRgb == BlendFactor::ONE );
358 DALI_TEST_CHECK( destFactorRgb == BlendFactor::ONE_MINUS_SRC_ALPHA );
359 DALI_TEST_CHECK( srcFactorAlpha == BlendFactor::ONE );
360 DALI_TEST_CHECK( destFactorAlpha == BlendFactor::ONE );
362 value = renderer.GetProperty( Renderer::Property::BLEND_PRE_MULTIPLIED_ALPHA );
363 DALI_TEST_CHECK( value.Get( enable ) );
364 DALI_TEST_CHECK( enable );
369 int UtcDaliImageViewPixelArea(void)
371 // Test pixel area property
372 ToolkitTestApplication application;
374 // Gif image, use AnimatedImageVisual internally
375 // Atlasing is applied to pack multiple frames, use custom wrap mode
376 ImageView gifView = ImageView::New();
377 const Vector4 pixelAreaVisual( 0.f, 0.f, 2.f, 2.f );
378 gifView.SetProperty( ImageView::Property::IMAGE,
379 Property::Map().Add( ImageVisual::Property::URL, TEST_GIF_FILE_NAME )
380 .Add( ImageVisual::Property::PIXEL_AREA, pixelAreaVisual ) );
383 Stage stage = Stage::GetCurrent();
384 stage.Add( gifView );
387 application.SendNotification();
388 application.Render(16);
389 DALI_TEST_CHECK( gifView.GetRendererCount() == 1u );
391 const Vector4 fullTextureRect( 0.f, 0.f, 1.f, 1.f );
392 // test that the pixel area value defined in the visual property map is registered on renderer
393 Renderer renderer = gifView.GetRendererAt(0);
394 Property::Value pixelAreaValue = renderer.GetProperty( renderer.GetPropertyIndex( "pixelArea" ) );
395 DALI_TEST_EQUALS( pixelAreaValue.Get<Vector4>(), pixelAreaVisual, TEST_LOCATION );
397 // test that the shader has the default pixel area value registered.
398 Shader shader = renderer.GetShader();
399 pixelAreaValue = shader.GetProperty( shader.GetPropertyIndex( "pixelArea" ) );
400 DALI_TEST_EQUALS( pixelAreaValue.Get<Vector4>(), fullTextureRect, TEST_LOCATION );
402 // test that the uniform uses the pixelArea property on the renderer.
403 TestGlAbstraction& gl = application.GetGlAbstraction();
404 Vector4 pixelAreaUniform;
405 DALI_TEST_CHECK( gl.GetUniformValue<Vector4>( "pixelArea", pixelAreaUniform ) );
406 DALI_TEST_EQUALS( pixelAreaVisual, pixelAreaUniform, Math::MACHINE_EPSILON_100, TEST_LOCATION );
408 // set the pixelArea property on the control
409 const Vector4 pixelAreaControl( -1.f, -1.f, 3.f, 3.f );
410 gifView.SetProperty( ImageView::Property::PIXEL_AREA, pixelAreaControl );
411 application.SendNotification();
412 application.Render(16);
414 // check the pixelArea property on the control
415 pixelAreaValue = gifView.GetProperty( gifView.GetPropertyIndex( "pixelArea" ) );
416 DALI_TEST_EQUALS( pixelAreaValue.Get<Vector4>(), pixelAreaControl, TEST_LOCATION );
417 // test that the uniform uses the pixelArea property on the control.
418 DALI_TEST_CHECK( gl.GetUniformValue<Vector4>( "pixelArea", pixelAreaUniform ) );
419 DALI_TEST_EQUALS( pixelAreaControl, pixelAreaUniform, Math::MACHINE_EPSILON_100, TEST_LOCATION );
425 int UtcDaliImageViewAsyncLoadingWithoutAltasing(void)
427 ToolkitTestApplication application;
429 // Async loading, no atlasing for big size image
430 ImageView imageView = ImageView::New( gImage_600_RGB );
432 // By default, Aysnc loading is used
433 Stage::GetCurrent().Add( imageView );
434 application.SendNotification();
435 application.Render(16);
436 application.Render(16);
437 application.SendNotification();
439 // BitmapLoader is not used
440 BitmapLoader loader = BitmapLoader::GetLatestCreated();
441 DALI_TEST_CHECK( !loader );
446 int UtcDaliImageViewAsyncLoadingWithAtlasing(void)
448 ToolkitTestApplication application;
450 //Async loading, automatic atlasing for small size image
451 TraceCallStack& callStack = application.GetGlAbstraction().GetTextureTrace();
453 callStack.Enable(true);
455 ImageView imageView = ImageView::New( gImage_34_RGBA, ImageDimensions( 34, 34 ) );
457 // By default, Aysnc loading is used
458 // loading is not started if the actor is offStage
460 Stage::GetCurrent().Add( imageView );
461 application.SendNotification();
462 application.Render(16);
463 application.Render(16);
464 application.SendNotification();
466 // loading started, this waits for the loader thread for max 30 seconds
467 DALI_TEST_EQUALS( Test::WaitForEventThreadTrigger( 1 ), true, TEST_LOCATION );
469 application.SendNotification();
470 application.Render(16);
472 callStack.Enable(false);
474 TraceCallStack::NamedParams params;
475 params["width"] = ToString(34);
476 params["height"] = ToString(34);
477 DALI_TEST_EQUALS( callStack.FindMethodAndParams( "TexSubImage2D", params ), true, TEST_LOCATION );
482 int UtcDaliImageViewAsyncLoadingWithAtlasing02(void)
484 ToolkitTestApplication application;
486 //Async loading, automatic atlasing for small size image
487 TraceCallStack& callStack = application.GetGlAbstraction().GetTextureTrace();
489 callStack.Enable(true);
491 Property::Map asyncLoadingMap;
492 asyncLoadingMap[ "url" ] = gImage_34_RGBA;
493 asyncLoadingMap[ "desiredHeight" ] = 34;
494 asyncLoadingMap[ "desiredWidth" ] = 34;
495 asyncLoadingMap[ "synchronousLoading" ] = false;
497 ImageView imageView = ImageView::New();
498 imageView.SetProperty( ImageView::Property::IMAGE, asyncLoadingMap );
500 Stage::GetCurrent().Add( imageView );
501 application.SendNotification();
502 application.Render(16);
503 application.Render(16);
504 application.SendNotification();
506 // loading started, this waits for the loader thread for max 30 seconds
507 DALI_TEST_EQUALS( Test::WaitForEventThreadTrigger( 1 ), true, TEST_LOCATION );
509 application.SendNotification();
510 application.Render(16);
512 callStack.Enable(false);
514 TraceCallStack::NamedParams params;
515 params["width"] = ToString(34);
516 params["height"] = ToString(34);
517 DALI_TEST_EQUALS( callStack.FindMethodAndParams( "TexSubImage2D", params ), true, TEST_LOCATION );
522 int UtcDaliImageViewSyncLoading(void)
524 ToolkitTestApplication application;
526 tet_infoline("ImageView Testing sync loading and size using index key property map");
528 Property::Map syncLoadingMap;
529 syncLoadingMap[ ImageVisual::Property::SYNCHRONOUS_LOADING ] = true;
531 // Sync loading, no atlasing for big size image
533 ImageView imageView = ImageView::New();
535 // Sync loading is used
536 syncLoadingMap[ ImageVisual::Property::URL ] = gImage_600_RGB;
537 imageView.SetProperty( ImageView::Property::IMAGE, syncLoadingMap );
539 // BitmapLoader is used, and the loading is started immediately even the actor is not on stage.
540 BitmapLoader loader = BitmapLoader::GetLatestCreated();
541 DALI_TEST_CHECK( loader );
544 // Sync loading, automatic atlasing for small size image
546 BitmapLoader::ResetLatestCreated();
547 TraceCallStack& callStack = application.GetGlAbstraction().GetTextureTrace();
549 callStack.Enable(true);
551 ImageView imageView = ImageView::New( );
552 // Sync loading is used
553 syncLoadingMap[ ImageVisual::Property::URL ] = gImage_34_RGBA;
554 syncLoadingMap[ ImageVisual::Property::DESIRED_HEIGHT ] = 34;
555 syncLoadingMap[ ImageVisual::Property::DESIRED_WIDTH ] = 34;
556 imageView.SetProperty( ImageView::Property::IMAGE, syncLoadingMap );
558 // loading is started even if the actor is offStage
559 BitmapLoader loader = BitmapLoader::GetLatestCreated();
560 DALI_TEST_CHECK( loader );
562 loader.WaitForLoading();
564 DALI_TEST_CHECK( loader.IsLoaded() );
566 Stage::GetCurrent().Add( imageView );
567 application.SendNotification();
568 application.Render(16);
570 TraceCallStack::NamedParams params;
571 params["width"] = ToString(34);
572 params["height"] = ToString(34);
573 DALI_TEST_EQUALS( callStack.FindMethodAndParams( "TexSubImage2D", params ),
574 true, TEST_LOCATION );
580 int UtcDaliImageViewSyncLoading02(void)
582 ToolkitTestApplication application;
584 tet_infoline("ImageView Testing sync loading and size using string key property map");
586 // Sync loading, automatic atlasing for small size image
588 BitmapLoader::ResetLatestCreated();
589 TraceCallStack& callStack = application.GetGlAbstraction().GetTextureTrace();
591 callStack.Enable(true);
593 ImageView imageView = ImageView::New( );
595 // Sync loading is used
596 Property::Map syncLoadingMap;
597 syncLoadingMap[ "url" ] = gImage_34_RGBA;
598 syncLoadingMap[ "desiredHeight" ] = 34;
599 syncLoadingMap[ "desiredWidth" ] = 34;
600 syncLoadingMap[ "synchronousLoading" ] = true;
601 imageView.SetProperty( ImageView::Property::IMAGE, syncLoadingMap );
603 // loading is started even if the actor is offStage
604 BitmapLoader loader = BitmapLoader::GetLatestCreated();
605 DALI_TEST_CHECK( loader );
607 loader.WaitForLoading();
609 DALI_TEST_CHECK( loader.IsLoaded() );
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 int UtcDaliImageViewSetImageOffstageN(void)
832 ToolkitTestApplication application;
834 ImageView imageView = ImageView::New();
836 Stage::GetCurrent().Add( imageView );
837 application.SendNotification();
838 application.Render();
839 Stage::GetCurrent().Remove( imageView );
841 ResourceImage image1 = ResourceImage::New( TEST_IMAGE_FILE_NAME );
842 imageView.SetImage( image1 );
843 TestImage( imageView, image1 );
846 imageView.SetImage( image2 );
848 Property::Value value = imageView.GetProperty( imageView.GetPropertyIndex( "image" ) );
850 //the value should be empty
852 DALI_TEST_CHECK( !value.Get( url ) );
855 DALI_TEST_CHECK( !value.Get( map ) );
860 int UtcDaliImageViewSetImageN(void)
862 ToolkitTestApplication application;
865 ImageView imageView = ImageView::New();
866 imageView.SetImage( image1 );
868 Property::Value value = imageView.GetProperty( imageView.GetPropertyIndex( "image" ) );
870 //the value should be empty
872 DALI_TEST_CHECK( !value.Get( url ) );
875 DALI_TEST_CHECK( !value.Get( map ) );
877 std::string resource_url;
878 Property::Value val = imageView.GetProperty( imageView.GetPropertyIndex( "image" ) );
879 DALI_TEST_CHECK( !val.Get( resource_url ) );
884 int UtcDaliImageViewSetImageTypeChangesP(void)
886 ToolkitTestApplication application;
888 ImageView imageView = ImageView::New();
894 Property::Value value = imageView.GetProperty( imageView.GetPropertyIndex( "image" ) );
895 DALI_TEST_CHECK( ! value.Get( url ) ); // Value should be empty
896 DALI_TEST_CHECK( ! value.Get( map ) ); // Value should be empty
899 imageView.SetImage( "TEST_URL" );
900 value = imageView.GetProperty( imageView.GetPropertyIndex( "image" ) );
902 DALI_TEST_CHECK( value.Get( url ) ); // Value should NOT be empty
903 DALI_TEST_CHECK( ! value.Get( map ) ); // Value should be empty
905 // Set an empty Image
906 imageView.SetImage( Image() );
907 value = imageView.GetProperty( imageView.GetPropertyIndex( "image" ) );
909 DALI_TEST_CHECK( ! value.Get( url ) ); // Value should be empty
910 DALI_TEST_CHECK( ! value.Get( map ) ); // Value should be empty
913 ResourceImage image1 = ResourceImage::New( TEST_IMAGE_FILE_NAME );
914 imageView.SetImage( image1 );
915 value = imageView.GetProperty( imageView.GetPropertyIndex( "image" ) );
917 DALI_TEST_CHECK( ! value.Get( url ) ); // Value should be empty
918 DALI_TEST_CHECK( value.Get( map ) ); // Value should NOT be empty
921 imageView.SetImage( "" );
922 value = imageView.GetProperty( imageView.GetPropertyIndex( "image" ) );
924 DALI_TEST_CHECK( ! value.Get( url ) ); // Value should be empty
925 DALI_TEST_CHECK( ! value.Get( map ) ); // Value should be empty
930 int UtcDaliImageViewResourceUrlP(void)
932 ToolkitTestApplication application;
934 ImageView imageView = ImageView::New();
935 DALI_TEST_CHECK( imageView.GetProperty( ImageView::Property::RESOURCE_URL ).Get< std::string >().empty() );
937 imageView.SetProperty( ImageView::Property::RESOURCE_URL, "TestString" );
938 DALI_TEST_EQUALS( imageView.GetProperty( ImageView::Property::RESOURCE_URL ).Get< std::string >(), "TestString", TEST_LOCATION );
943 // Scenarios 1: ImageView from regular image
944 int UtcDaliImageViewSetImageBufferImage(void)
946 ToolkitTestApplication application;
948 ImageView imageView = ImageView::New();
949 Stage::GetCurrent().Add( imageView );
951 TestGlAbstraction& gl = application.GetGlAbstraction();
952 gl.EnableTextureCallTrace( true );
954 std::vector< GLuint > ids;
956 application.GetGlAbstraction().SetNextTextureIds( ids );
960 BufferImage image = CreateBufferImage( width, height, Color::WHITE );
962 imageView.SetImage( image );
964 application.SendNotification();
965 application.Render();
967 DALI_TEST_CHECK( gl.GetTextureTrace().FindMethod("BindTexture") );
969 std::stringstream params;
970 params << GL_TEXTURE_2D << ", " << 23;
971 DALI_TEST_CHECK( gl.GetTextureTrace().FindMethodAndParams("BindTexture", params.str()) );
976 // Scenarios 2: ImageView from Native image
977 int UtcDaliImageViewSetImageNativeImage(void)
979 ToolkitTestApplication application;
981 ImageView imageView = ImageView::New();
982 Stage::GetCurrent().Add( imageView );
984 TestGlAbstraction& gl = application.GetGlAbstraction();
985 gl.EnableTextureCallTrace( true );
987 std::vector< GLuint > ids;
989 application.GetGlAbstraction().SetNextTextureIds( ids );
993 TestNativeImagePointer nativeImageInterface = TestNativeImage::New( width, height );
994 NativeImage nativeImage = NativeImage::New( *(nativeImageInterface.Get()) );
996 imageView.SetImage( nativeImage );
997 application.SendNotification();
998 application.Render();
1000 DALI_TEST_CHECK( gl.GetTextureTrace().FindMethod("BindTexture") );
1002 std::stringstream params;
1003 params << GL_TEXTURE_EXTERNAL_OES << ", " << 23;
1004 DALI_TEST_CHECK( gl.GetTextureTrace().FindMethodAndParams("BindTexture", params.str()) );
1009 // Scenarios 3: ImageView initially from regular image but then SetImage called with Native image
1010 int UtcDaliImageViewSetImageBufferImageToNativeImage(void)
1012 ToolkitTestApplication application;
1016 BufferImage image = CreateBufferImage( width, height, Color::WHITE );
1018 ImageView imageView = ImageView::New( image );
1019 Stage::GetCurrent().Add( imageView );
1021 TestGlAbstraction& gl = application.GetGlAbstraction();
1022 gl.EnableTextureCallTrace( true );
1024 std::vector< GLuint > ids;
1025 ids.push_back( 23 );
1026 application.GetGlAbstraction().SetNextTextureIds( ids );
1028 application.SendNotification();
1029 application.Render();
1031 DALI_TEST_CHECK( gl.GetTextureTrace().FindMethod("BindTexture") );
1033 std::stringstream params;
1034 params << GL_TEXTURE_2D << ", " << 23;
1035 DALI_TEST_CHECK( gl.GetTextureTrace().FindMethodAndParams("BindTexture", params.str()) );
1039 TestNativeImagePointer nativeImageInterface = TestNativeImage::New( width, height );
1040 NativeImage nativeImage = NativeImage::New( *(nativeImageInterface.Get()) );
1041 imageView.SetImage( nativeImage );
1044 ids.push_back( 24 );
1045 application.GetGlAbstraction().SetNextTextureIds( ids );
1047 application.SendNotification();
1048 application.Render();
1050 DALI_TEST_CHECK( gl.GetTextureTrace().FindMethod("BindTexture") );
1052 std::stringstream nextTextureParams;
1053 nextTextureParams << GL_TEXTURE_EXTERNAL_OES << ", " << 24;
1054 DALI_TEST_CHECK( gl.GetTextureTrace().FindMethodAndParams("BindTexture", nextTextureParams.str()) );
1059 // Scenarios 4: ImageView initially from Native image but then SetImage called with regular image
1060 int UtcDaliImageViewSetImageNativeImageToBufferImage(void)
1062 ToolkitTestApplication application;
1066 TestNativeImagePointer nativeImageInterface = TestNativeImage::New( width, height );
1067 NativeImage nativeImage = NativeImage::New( *(nativeImageInterface.Get()) );
1069 ImageView imageView = ImageView::New( nativeImage );
1070 Stage::GetCurrent().Add( imageView );
1072 TestGlAbstraction& gl = application.GetGlAbstraction();
1073 gl.EnableTextureCallTrace( true );
1075 std::vector< GLuint > ids;
1076 ids.push_back( 23 );
1077 application.GetGlAbstraction().SetNextTextureIds( ids );
1079 application.SendNotification();
1080 application.Render();
1082 DALI_TEST_CHECK( gl.GetTextureTrace().FindMethod("BindTexture") );
1084 std::stringstream params;
1085 params << GL_TEXTURE_EXTERNAL_OES << ", " << 23;
1086 DALI_TEST_CHECK( gl.GetTextureTrace().FindMethodAndParams("BindTexture", params.str()) );
1090 BufferImage image = CreateBufferImage( width, height, Color::WHITE );
1091 imageView.SetImage( image );
1094 ids.push_back( 24 );
1095 application.GetGlAbstraction().SetNextTextureIds( ids );
1097 application.SendNotification();
1098 application.Render();
1100 DALI_TEST_CHECK( gl.GetTextureTrace().FindMethod("BindTexture") );
1102 std::stringstream nextTextureParams;
1103 nextTextureParams << GL_TEXTURE_2D << ", " << 24;
1104 DALI_TEST_CHECK( gl.GetTextureTrace().FindMethodAndParams("BindTexture", nextTextureParams.str()) );
1109 // Scenarios 5: ImageView from Native image with custom shader
1110 int UtcDaliImageViewSetImageNativeImageWithCustomShader(void)
1112 ToolkitTestApplication application;
1117 Property::Map customShader;
1118 customShader.Insert( "vertexShader", VERTEX_SHADER );
1119 customShader.Insert( "fragmentShader", FRAGMENT_SHADER );
1121 Property::Array shaderHints;
1122 shaderHints.PushBack( "requiresSelfDepthTest" );
1123 shaderHints.PushBack( "outputIsTransparent" );
1124 shaderHints.PushBack( "outputIsOpaque" );
1125 shaderHints.PushBack( "modifiesGeometry" );
1127 customShader.Insert( "hints", shaderHints );
1130 map.Insert( "shader", customShader );
1132 TestNativeImagePointer nativeImageInterface = TestNativeImage::New( width, height );
1133 NativeImage nativeImage = NativeImage::New( *(nativeImageInterface.Get()) );
1135 ImageView imageView = ImageView::New( nativeImage );
1136 imageView.SetProperty( ImageView::Property::IMAGE, map );
1137 Stage::GetCurrent().Add( imageView );
1139 TestGlAbstraction& gl = application.GetGlAbstraction();
1140 gl.EnableTextureCallTrace( true );
1142 std::vector< GLuint > ids;
1143 ids.push_back( 23 );
1144 application.GetGlAbstraction().SetNextTextureIds( ids );
1146 application.SendNotification();
1147 application.Render();
1149 DALI_TEST_CHECK( gl.GetTextureTrace().FindMethod("BindTexture") );
1151 std::stringstream params;
1152 params << GL_TEXTURE_EXTERNAL_OES << ", " << 23;
1153 DALI_TEST_CHECK( gl.GetTextureTrace().FindMethodAndParams("BindTexture", params.str()) );
1158 // Scenarios 6: ImageView initially from regular image with custom shader but then SetImage called with Native
1159 int UtcDaliImageViewSetImageBufferImageWithCustomShaderToNativeImage(void)
1161 ToolkitTestApplication application;
1166 Property::Map customShader;
1167 customShader.Insert( "vertexShader", VERTEX_SHADER );
1168 customShader.Insert( "fragmentShader", FRAGMENT_SHADER );
1170 Property::Array shaderHints;
1171 shaderHints.PushBack( "requiresSelfDepthTest" );
1172 shaderHints.PushBack( "outputIsTransparent" );
1173 shaderHints.PushBack( "outputIsOpaque" );
1174 shaderHints.PushBack( "modifiesGeometry" );
1176 customShader.Insert( "hints", shaderHints );
1179 map.Insert( "shader", customShader );
1181 BufferImage image = CreateBufferImage( width, height, Color::WHITE );
1183 ImageView imageView = ImageView::New( image );
1184 imageView.SetProperty( ImageView::Property::IMAGE, map );
1185 Stage::GetCurrent().Add( imageView );
1187 TestGlAbstraction& gl = application.GetGlAbstraction();
1188 gl.EnableTextureCallTrace( true );
1190 std::vector< GLuint > ids;
1191 ids.push_back( 23 );
1192 application.GetGlAbstraction().SetNextTextureIds( ids );
1194 application.SendNotification();
1195 application.Render();
1197 DALI_TEST_CHECK( gl.GetTextureTrace().FindMethod("BindTexture") );
1199 std::stringstream params;
1200 params << GL_TEXTURE_2D << ", " << 23;
1201 DALI_TEST_CHECK( gl.GetTextureTrace().FindMethodAndParams("BindTexture", params.str()) );
1203 TestNativeImagePointer nativeImageInterface = TestNativeImage::New( width, height );
1204 NativeImage nativeImage = NativeImage::New( *(nativeImageInterface.Get()) );
1205 imageView.SetImage( nativeImage );
1208 ids.push_back( 24 );
1209 application.GetGlAbstraction().SetNextTextureIds( ids );
1211 application.SendNotification();
1212 application.Render();
1214 DALI_TEST_CHECK( gl.GetTextureTrace().FindMethod("BindTexture") );
1216 std::stringstream nativeImageParams;
1217 nativeImageParams << GL_TEXTURE_EXTERNAL_OES << ", " << 24;
1218 DALI_TEST_CHECK( gl.GetTextureTrace().FindMethodAndParams("BindTexture", nativeImageParams.str()) );
1224 int UtcDaliImageViewGetImageP1(void)
1226 ToolkitTestApplication application;
1228 ImageView imageView = ImageView::New();
1229 DALI_TEST_CHECK( ! imageView.GetImage() );
1231 Image image = CreateBufferImage();
1232 imageView.SetImage( image );
1233 DALI_TEST_CHECK( imageView.GetImage() == image );
1238 int UtcDaliImageViewGetImageP2(void)
1240 ToolkitTestApplication application;
1242 BufferImage image = CreateBufferImage();
1243 ImageView imageView = ImageView::New( image );
1244 DALI_TEST_CHECK( imageView.GetImage() == image );
1249 int UtcDaliImageViewGetImageN(void)
1251 ToolkitTestApplication application;
1253 ImageView imageView = ImageView::New( TEST_IMAGE_FILE_NAME );
1254 DALI_TEST_CHECK( ! imageView.GetImage() );
1256 Image image = CreateBufferImage();
1257 imageView.SetImage( image );
1258 DALI_TEST_CHECK( imageView.GetImage() == image );
1260 imageView.SetImage( TEST_IMAGE_FILE_NAME );
1261 DALI_TEST_CHECK( ! imageView.GetImage() );