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-toolkit/devel-api/controls/control-devel.h>
28 #include <dali/public-api/rendering/renderer.h>
30 #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;
431 // Async loading, no atlasing for big size image
432 ImageView imageView = ImageView::New( gImage_600_RGB );
434 // By default, Aysnc loading is used
435 Stage::GetCurrent().Add( imageView );
436 application.SendNotification();
437 application.Render(16);
438 application.Render(16);
439 application.SendNotification();
441 // BitmapLoader is not used
442 BitmapLoader loader = BitmapLoader::GetLatestCreated();
443 DALI_TEST_CHECK( !loader );
448 int UtcDaliImageViewAsyncLoadingWithAtlasing(void)
450 ToolkitTestApplication application;
452 //Async loading, automatic atlasing for small size image
453 TraceCallStack& callStack = application.GetGlAbstraction().GetTextureTrace();
455 callStack.Enable(true);
457 Property::Map imageMap;
459 imageMap[ ImageVisual::Property::URL ] = gImage_34_RGBA;
460 imageMap[ ImageVisual::Property::DESIRED_HEIGHT ] = 34;
461 imageMap[ ImageVisual::Property::DESIRED_WIDTH ] = 34;
462 imageMap[ DevelImageVisual::Property::ATLASING] = true;
464 ImageView imageView = ImageView::New();
465 imageView.SetProperty( ImageView::Property::IMAGE, imageMap );
467 // By default, Aysnc loading is used
468 // loading is not started if the actor is offStage
470 Stage::GetCurrent().Add( imageView );
471 application.SendNotification();
472 application.Render(16);
473 application.Render(16);
474 application.SendNotification();
476 // loading started, this waits for the loader thread for max 30 seconds
477 DALI_TEST_EQUALS( Test::WaitForEventThreadTrigger( 1 ), true, TEST_LOCATION );
479 application.SendNotification();
480 application.Render(16);
482 callStack.Enable(false);
484 TraceCallStack::NamedParams params;
485 params["width"] = ToString(34);
486 params["height"] = ToString(34);
487 DALI_TEST_EQUALS( callStack.FindMethodAndParams( "TexSubImage2D", params ), true, TEST_LOCATION );
492 int UtcDaliImageViewAsyncLoadingWithAtlasing02(void)
494 ToolkitTestApplication application;
496 //Async loading, automatic atlasing for small size image
497 TraceCallStack& callStack = application.GetGlAbstraction().GetTextureTrace();
499 callStack.Enable(true);
501 Property::Map asyncLoadingMap;
502 asyncLoadingMap[ "url" ] = gImage_34_RGBA;
503 asyncLoadingMap[ "desiredHeight" ] = 34;
504 asyncLoadingMap[ "desiredWidth" ] = 34;
505 asyncLoadingMap[ "synchronousLoading" ] = false;
506 asyncLoadingMap[ "atlasing" ] = true;
508 ImageView imageView = ImageView::New();
509 imageView.SetProperty( ImageView::Property::IMAGE, asyncLoadingMap );
511 Stage::GetCurrent().Add( imageView );
512 application.SendNotification();
513 application.Render(16);
514 application.Render(16);
515 application.SendNotification();
517 // loading started, this waits for the loader thread for max 30 seconds
518 DALI_TEST_EQUALS( Test::WaitForEventThreadTrigger( 1 ), true, TEST_LOCATION );
520 application.SendNotification();
521 application.Render(16);
523 callStack.Enable(false);
525 TraceCallStack::NamedParams params;
526 params["width"] = ToString(34);
527 params["height"] = ToString(34);
528 DALI_TEST_EQUALS( callStack.FindMethodAndParams( "TexSubImage2D", params ), true, TEST_LOCATION );
533 int UtcDaliImageViewSyncLoading(void)
535 ToolkitTestApplication application;
537 tet_infoline("ImageView Testing sync loading and size using index key property map");
539 Property::Map syncLoadingMap;
540 syncLoadingMap[ ImageVisual::Property::SYNCHRONOUS_LOADING ] = true;
541 syncLoadingMap[ DevelImageVisual::Property::ATLASING ] = true;
543 // Sync loading, no atlasing for big size image
545 ImageView imageView = ImageView::New();
547 // Sync loading is used
548 syncLoadingMap[ ImageVisual::Property::URL ] = gImage_600_RGB;
549 imageView.SetProperty( ImageView::Property::IMAGE, syncLoadingMap );
552 // BitmapLoader is used, and the loading is started immediately even the actor is not on stage.
553 BitmapLoader loader = BitmapLoader::GetLatestCreated();
554 DALI_TEST_CHECK( loader );
557 // Sync loading, automatic atlasing for small size image
559 BitmapLoader::ResetLatestCreated();
560 TraceCallStack& callStack = application.GetGlAbstraction().GetTextureTrace();
562 callStack.Enable(true);
564 ImageView imageView = ImageView::New( );
565 // Sync loading is used
566 syncLoadingMap[ ImageVisual::Property::URL ] = gImage_34_RGBA;
567 syncLoadingMap[ ImageVisual::Property::DESIRED_HEIGHT ] = 34;
568 syncLoadingMap[ ImageVisual::Property::DESIRED_WIDTH ] = 34;
569 imageView.SetProperty( ImageView::Property::IMAGE, syncLoadingMap );
571 // loading is started even if the actor is offStage
572 BitmapLoader loader = BitmapLoader::GetLatestCreated();
573 DALI_TEST_CHECK( loader );
575 loader.WaitForLoading();
577 DALI_TEST_CHECK( loader.IsLoaded() );
579 Stage::GetCurrent().Add( imageView );
580 application.SendNotification();
581 application.Render(16);
583 TraceCallStack::NamedParams params;
584 params["width"] = ToString(34);
585 params["height"] = ToString(34);
586 DALI_TEST_EQUALS( callStack.FindMethodAndParams( "TexSubImage2D", params ),
587 true, TEST_LOCATION );
593 int UtcDaliImageViewSyncLoading02(void)
595 ToolkitTestApplication application;
597 tet_infoline("ImageView Testing sync loading and size using string key property map");
599 // Sync loading, automatic atlasing for small size image
601 BitmapLoader::ResetLatestCreated();
602 TraceCallStack& callStack = application.GetGlAbstraction().GetTextureTrace();
604 callStack.Enable(true);
606 ImageView imageView = ImageView::New( );
608 // Sync loading is used
609 Property::Map syncLoadingMap;
610 syncLoadingMap[ "url" ] = gImage_34_RGBA;
611 syncLoadingMap[ "desiredHeight" ] = 34;
612 syncLoadingMap[ "desiredWidth" ] = 34;
613 syncLoadingMap[ "synchronousLoading" ] = true;
614 syncLoadingMap[ "atlasing" ] = true;
615 imageView.SetProperty( ImageView::Property::IMAGE, syncLoadingMap );
617 // loading is started even if the actor is offStage
618 BitmapLoader loader = BitmapLoader::GetLatestCreated();
619 DALI_TEST_CHECK( loader );
621 loader.WaitForLoading();
623 DALI_TEST_CHECK( loader.IsLoaded() );
625 Stage::GetCurrent().Add( imageView );
626 application.SendNotification();
627 application.Render(16);
629 TraceCallStack::NamedParams params;
630 params["width"] = ToString(34);
631 params["height"] = ToString(34);
632 DALI_TEST_EQUALS( callStack.FindMethodAndParams( "TexSubImage2D", params ),
633 true, TEST_LOCATION );
638 int UtcDaliImageViewSizeWithBackground(void)
640 ToolkitTestApplication application;
644 Image image = CreateBufferImage( width, height, Vector4(1.f, 1.f, 1.f, 1.f) );
645 ImageView imageView = ImageView::New();
646 imageView.SetBackgroundImage( image );
648 Stage::GetCurrent().Add( imageView );
649 application.SendNotification();
650 application.Render();
652 DALI_TEST_EQUALS( imageView.GetCurrentSize().width, (float)width, TEST_LOCATION );
653 DALI_TEST_EQUALS( imageView.GetCurrentSize().height, (float)height, TEST_LOCATION );
658 int UtcDaliImageViewSizeWithBackgroundAndImage(void)
660 ToolkitTestApplication application;
662 int widthBackground = 100;
663 int heightBackground = 200;
666 Image imageBackground = CreateBufferImage( widthBackground, heightBackground, Vector4(1.f, 1.f, 1.f, 1.f) );
667 Image image = CreateBufferImage( width, height, Vector4(1.f, 1.f, 1.f, 1.f) );
669 ImageView imageView = ImageView::New();
670 imageView.SetBackgroundImage( imageBackground );
671 imageView.SetImage( image );
673 Stage::GetCurrent().Add( imageView );
674 application.SendNotification();
675 application.Render();
677 DALI_TEST_EQUALS( imageView.GetCurrentSize().width, (float)width, TEST_LOCATION );
678 DALI_TEST_EQUALS( imageView.GetCurrentSize().height, (float)height, TEST_LOCATION );
683 int UtcDaliImageViewHeightForWidthBackground(void)
685 ToolkitTestApplication application;
687 int widthBackground = 100;
688 int heightBackground = 200;
689 Image imageBackground = CreateBufferImage( widthBackground, heightBackground, Vector4(1.f, 1.f, 1.f, 1.f) );
691 ImageView imageView = ImageView::New();
692 imageView.SetBackgroundImage( imageBackground );
694 Stage::GetCurrent().Add( imageView );
695 application.SendNotification();
696 application.Render();
698 Control control = Control::DownCast( imageView );
699 DALI_TEST_CHECK( control );
700 DALI_TEST_EQUALS( imageView.GetHeightForWidth( 123.f ), control.GetHeightForWidth( 123.f ), TEST_LOCATION );
701 DALI_TEST_EQUALS( imageView.GetWidthForHeight( 321.f ), control.GetWidthForHeight( 321.f ), TEST_LOCATION );
706 int UtcDaliImageViewHeightForWidthBackgroundAndImage(void)
708 ToolkitTestApplication application;
710 int widthBackground = 100;
711 int heightBackground = 200;
714 Image imageBackground = CreateBufferImage( widthBackground, heightBackground, Vector4(1.f, 1.f, 1.f, 1.f) );
715 Image image = CreateBufferImage( width, height, Vector4(1.f, 1.f, 1.f, 1.f) );
717 ImageView imageView = ImageView::New();
718 imageView.SetBackgroundImage( imageBackground );
719 imageView.SetImage( image );
721 Stage::GetCurrent().Add( imageView );
722 application.SendNotification();
723 application.Render();
725 DALI_TEST_EQUALS( imageView.GetHeightForWidth( width ), (float)height, TEST_LOCATION );
726 DALI_TEST_EQUALS( imageView.GetWidthForHeight( height ), (float)width, TEST_LOCATION );
731 int UtcDaliImageViewSetBufferImage(void)
733 ToolkitTestApplication application;
737 BufferImage image1 = CreateBufferImage( width1, height1, Vector4( 1.f, 1.f, 1.f, 1.f ) );
738 ImageView imageView = ImageView::New();
739 imageView.SetImage( image1 );
741 TestImage( imageView, image1 );
745 BufferImage image2 = CreateBufferImage( width2, height2, Vector4( 1.f, 1.f, 1.f, 1.f ) );
746 imageView.SetImage( image2 );
748 TestImage( imageView, image2 );
753 int UtcDaliImageViewSetImageUrl(void)
755 ToolkitTestApplication application;
757 ImageView imageView = ImageView::New();
758 imageView.SetImage( TEST_IMAGE_FILE_NAME );
759 TestUrl( imageView, TEST_IMAGE_FILE_NAME );
762 imageView.SetImage( TEST_IMAGE_FILE_NAME2 );
763 TestUrl( imageView, TEST_IMAGE_FILE_NAME2 );
768 int UtcDaliImageViewSetImageOnstageP(void)
770 ToolkitTestApplication application;
772 ImageView imageView = ImageView::New();
774 Stage::GetCurrent().Add( imageView );
775 application.SendNotification();
776 application.Render();
778 ResourceImage image1 = ResourceImage::New( TEST_IMAGE_FILE_NAME );
779 imageView.SetImage( image1 );
780 TestImage( imageView, image1 );
784 BufferImage image2 = CreateBufferImage( width, height, Vector4( 1.f, 1.f, 1.f, 1.f ) );
785 imageView.SetImage( image2 );
786 TestImage( imageView, image2 );
791 int UtcDaliImageViewSetImageOnstageN(void)
793 ToolkitTestApplication application;
795 ImageView imageView = ImageView::New();
797 Stage::GetCurrent().Add( imageView );
798 application.SendNotification();
799 application.Render();
801 ResourceImage image1 = ResourceImage::New( TEST_IMAGE_FILE_NAME );
802 imageView.SetImage( image1 );
803 TestImage( imageView, image1 );
806 imageView.SetImage( image2 );
808 Property::Value value = imageView.GetProperty( imageView.GetPropertyIndex( "image" ) );
810 //the value should be empty
812 DALI_TEST_CHECK( !value.Get( url ) );
815 DALI_TEST_CHECK( !value.Get( map ) );
820 int UtcDaliImageViewSetImageOffstageP(void)
822 ToolkitTestApplication application;
824 ImageView imageView = ImageView::New();
826 Stage::GetCurrent().Add( imageView );
827 application.SendNotification();
828 application.Render();
829 Stage::GetCurrent().Remove( imageView );
831 ResourceImage image1 = ResourceImage::New( TEST_IMAGE_FILE_NAME );
832 imageView.SetImage( image1 );
833 TestImage( imageView, image1 );
837 BufferImage image2 = CreateBufferImage( width, height, Vector4( 1.f, 1.f, 1.f, 1.f ) );
838 imageView.SetImage( image2 );
839 TestImage( imageView, image2 );
844 bool gResourceReadySignalFired = false;
846 void ResourceReadySignal( Control control )
848 gResourceReadySignalFired = true;
851 int UtcDaliImageViewCheckResourceReady(void)
853 ToolkitTestApplication application;
855 gResourceReadySignalFired = false;
860 Image image = CreateBufferImage( width, height, Vector4(1.f, 1.f, 1.f, 1.f) );
862 // Check ImageView with background and main image, to ensure both visuals are marked as loaded
863 ImageView imageView = ImageView::New( TEST_GIF_FILE_NAME );
865 imageView.SetBackgroundImage( image );
867 DALI_TEST_EQUALS( Toolkit::DevelControl::IsResourceReady( imageView ), false, TEST_LOCATION );
869 Toolkit::DevelControl::ResourceReadySignal( imageView ).Connect( &ResourceReadySignal);
871 Stage::GetCurrent().Add( imageView );
873 application.SendNotification();
874 application.Render(16);
877 DALI_TEST_EQUALS( Toolkit::DevelControl::IsResourceReady( imageView ), true, TEST_LOCATION );
879 DALI_TEST_EQUALS( gResourceReadySignalFired, true, TEST_LOCATION );
884 int UtcDaliImageViewSetImageOffstageN(void)
886 ToolkitTestApplication application;
888 ImageView imageView = ImageView::New();
890 Stage::GetCurrent().Add( imageView );
891 application.SendNotification();
892 application.Render();
893 Stage::GetCurrent().Remove( imageView );
895 ResourceImage image1 = ResourceImage::New( TEST_IMAGE_FILE_NAME );
896 imageView.SetImage( image1 );
897 TestImage( imageView, image1 );
900 imageView.SetImage( image2 );
902 Property::Value value = imageView.GetProperty( imageView.GetPropertyIndex( "image" ) );
904 //the value should be empty
906 DALI_TEST_CHECK( !value.Get( url ) );
909 DALI_TEST_CHECK( !value.Get( map ) );
914 int UtcDaliImageViewSetImageN(void)
916 ToolkitTestApplication application;
919 ImageView imageView = ImageView::New();
920 imageView.SetImage( image1 );
922 Property::Value value = imageView.GetProperty( imageView.GetPropertyIndex( "image" ) );
924 //the value should be empty
926 DALI_TEST_CHECK( !value.Get( url ) );
929 DALI_TEST_CHECK( !value.Get( map ) );
931 std::string resource_url;
932 Property::Value val = imageView.GetProperty( imageView.GetPropertyIndex( "image" ) );
933 DALI_TEST_CHECK( !val.Get( resource_url ) );
938 int UtcDaliImageViewSetImageTypeChangesP(void)
940 ToolkitTestApplication application;
942 ImageView imageView = ImageView::New();
948 Property::Value 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 imageView.SetImage( "TEST_URL" );
954 value = imageView.GetProperty( imageView.GetPropertyIndex( "image" ) );
956 DALI_TEST_CHECK( value.Get( url ) ); // Value should NOT be empty
957 DALI_TEST_CHECK( ! value.Get( map ) ); // Value should be empty
959 // Set an empty Image
960 imageView.SetImage( Image() );
961 value = imageView.GetProperty( imageView.GetPropertyIndex( "image" ) );
963 DALI_TEST_CHECK( ! value.Get( url ) ); // Value should be empty
964 DALI_TEST_CHECK( ! value.Get( map ) ); // Value should be empty
967 ResourceImage image1 = ResourceImage::New( TEST_IMAGE_FILE_NAME );
968 imageView.SetImage( image1 );
969 value = imageView.GetProperty( imageView.GetPropertyIndex( "image" ) );
971 DALI_TEST_CHECK( ! value.Get( url ) ); // Value should be empty
972 DALI_TEST_CHECK( value.Get( map ) ); // Value should NOT be empty
975 imageView.SetImage( "" );
976 value = imageView.GetProperty( imageView.GetPropertyIndex( "image" ) );
978 DALI_TEST_CHECK( ! value.Get( url ) ); // Value should be empty
979 DALI_TEST_CHECK( ! value.Get( map ) ); // Value should be empty
984 int UtcDaliImageViewResourceUrlP(void)
986 ToolkitTestApplication application;
988 ImageView imageView = ImageView::New();
989 DALI_TEST_CHECK( imageView.GetProperty( ImageView::Property::RESOURCE_URL ).Get< std::string >().empty() );
991 imageView.SetProperty( ImageView::Property::RESOURCE_URL, "TestString" );
992 DALI_TEST_EQUALS( imageView.GetProperty( ImageView::Property::RESOURCE_URL ).Get< std::string >(), "TestString", TEST_LOCATION );
997 // Scenarios 1: ImageView from regular image
998 int UtcDaliImageViewSetImageBufferImage(void)
1000 ToolkitTestApplication application;
1002 ImageView imageView = ImageView::New();
1003 Stage::GetCurrent().Add( imageView );
1005 TestGlAbstraction& gl = application.GetGlAbstraction();
1006 gl.EnableTextureCallTrace( true );
1008 std::vector< GLuint > ids;
1009 ids.push_back( 23 );
1010 application.GetGlAbstraction().SetNextTextureIds( ids );
1014 BufferImage image = CreateBufferImage( width, height, Color::WHITE );
1016 imageView.SetImage( image );
1018 application.SendNotification();
1019 application.Render();
1021 DALI_TEST_CHECK( gl.GetTextureTrace().FindMethod("BindTexture") );
1023 std::stringstream params;
1024 params << GL_TEXTURE_2D << ", " << 23;
1025 DALI_TEST_CHECK( gl.GetTextureTrace().FindMethodAndParams("BindTexture", params.str()) );
1030 // Scenarios 2: ImageView from Native image
1031 int UtcDaliImageViewSetImageNativeImage(void)
1033 ToolkitTestApplication application;
1035 ImageView imageView = ImageView::New();
1036 Stage::GetCurrent().Add( imageView );
1038 TestGlAbstraction& gl = application.GetGlAbstraction();
1039 gl.EnableTextureCallTrace( true );
1041 std::vector< GLuint > ids;
1042 ids.push_back( 23 );
1043 application.GetGlAbstraction().SetNextTextureIds( ids );
1047 TestNativeImagePointer nativeImageInterface = TestNativeImage::New( width, height );
1048 NativeImage nativeImage = NativeImage::New( *(nativeImageInterface.Get()) );
1050 imageView.SetImage( nativeImage );
1051 application.SendNotification();
1052 application.Render();
1054 DALI_TEST_CHECK( gl.GetTextureTrace().FindMethod("BindTexture") );
1056 std::stringstream params;
1057 params << GL_TEXTURE_EXTERNAL_OES << ", " << 23;
1058 DALI_TEST_CHECK( gl.GetTextureTrace().FindMethodAndParams("BindTexture", params.str()) );
1063 // Scenarios 3: ImageView initially from regular image but then SetImage called with Native image
1064 int UtcDaliImageViewSetImageBufferImageToNativeImage(void)
1066 ToolkitTestApplication application;
1070 BufferImage image = CreateBufferImage( width, height, Color::WHITE );
1072 ImageView imageView = ImageView::New( image );
1073 Stage::GetCurrent().Add( imageView );
1075 TestGlAbstraction& gl = application.GetGlAbstraction();
1076 gl.EnableTextureCallTrace( true );
1078 std::vector< GLuint > ids;
1079 ids.push_back( 23 );
1080 application.GetGlAbstraction().SetNextTextureIds( ids );
1082 application.SendNotification();
1083 application.Render();
1085 DALI_TEST_CHECK( gl.GetTextureTrace().FindMethod("BindTexture") );
1087 std::stringstream params;
1088 params << GL_TEXTURE_2D << ", " << 23;
1089 DALI_TEST_CHECK( gl.GetTextureTrace().FindMethodAndParams("BindTexture", params.str()) );
1093 TestNativeImagePointer nativeImageInterface = TestNativeImage::New( width, height );
1094 NativeImage nativeImage = NativeImage::New( *(nativeImageInterface.Get()) );
1095 imageView.SetImage( nativeImage );
1098 ids.push_back( 24 );
1099 application.GetGlAbstraction().SetNextTextureIds( ids );
1101 application.SendNotification();
1102 application.Render();
1104 DALI_TEST_CHECK( gl.GetTextureTrace().FindMethod("BindTexture") );
1106 std::stringstream nextTextureParams;
1107 nextTextureParams << GL_TEXTURE_EXTERNAL_OES << ", " << 24;
1108 DALI_TEST_CHECK( gl.GetTextureTrace().FindMethodAndParams("BindTexture", nextTextureParams.str()) );
1113 // Scenarios 4: ImageView initially from Native image but then SetImage called with regular image
1114 int UtcDaliImageViewSetImageNativeImageToBufferImage(void)
1116 ToolkitTestApplication application;
1120 TestNativeImagePointer nativeImageInterface = TestNativeImage::New( width, height );
1121 NativeImage nativeImage = NativeImage::New( *(nativeImageInterface.Get()) );
1123 ImageView imageView = ImageView::New( nativeImage );
1124 Stage::GetCurrent().Add( imageView );
1126 TestGlAbstraction& gl = application.GetGlAbstraction();
1127 gl.EnableTextureCallTrace( true );
1129 std::vector< GLuint > ids;
1130 ids.push_back( 23 );
1131 application.GetGlAbstraction().SetNextTextureIds( ids );
1133 application.SendNotification();
1134 application.Render();
1136 DALI_TEST_CHECK( gl.GetTextureTrace().FindMethod("BindTexture") );
1138 std::stringstream params;
1139 params << GL_TEXTURE_EXTERNAL_OES << ", " << 23;
1140 DALI_TEST_CHECK( gl.GetTextureTrace().FindMethodAndParams("BindTexture", params.str()) );
1144 BufferImage image = CreateBufferImage( width, height, Color::WHITE );
1145 imageView.SetImage( image );
1148 ids.push_back( 24 );
1149 application.GetGlAbstraction().SetNextTextureIds( ids );
1151 application.SendNotification();
1152 application.Render();
1154 DALI_TEST_CHECK( gl.GetTextureTrace().FindMethod("BindTexture") );
1156 std::stringstream nextTextureParams;
1157 nextTextureParams << GL_TEXTURE_2D << ", " << 24;
1158 DALI_TEST_CHECK( gl.GetTextureTrace().FindMethodAndParams("BindTexture", nextTextureParams.str()) );
1163 // Scenarios 5: ImageView from Native image with custom shader
1164 int UtcDaliImageViewSetImageNativeImageWithCustomShader(void)
1166 ToolkitTestApplication application;
1171 Property::Map customShader;
1172 customShader.Insert( "vertexShader", VERTEX_SHADER );
1173 customShader.Insert( "fragmentShader", FRAGMENT_SHADER );
1175 Property::Array shaderHints;
1176 shaderHints.PushBack( "requiresSelfDepthTest" );
1177 shaderHints.PushBack( "outputIsTransparent" );
1178 shaderHints.PushBack( "outputIsOpaque" );
1179 shaderHints.PushBack( "modifiesGeometry" );
1181 customShader.Insert( "hints", shaderHints );
1184 map.Insert( "shader", customShader );
1186 TestNativeImagePointer nativeImageInterface = TestNativeImage::New( width, height );
1187 NativeImage nativeImage = NativeImage::New( *(nativeImageInterface.Get()) );
1189 ImageView imageView = ImageView::New( nativeImage );
1190 imageView.SetProperty( ImageView::Property::IMAGE, map );
1191 Stage::GetCurrent().Add( imageView );
1193 TestGlAbstraction& gl = application.GetGlAbstraction();
1194 gl.EnableTextureCallTrace( true );
1196 std::vector< GLuint > ids;
1197 ids.push_back( 23 );
1198 application.GetGlAbstraction().SetNextTextureIds( ids );
1200 application.SendNotification();
1201 application.Render();
1203 DALI_TEST_CHECK( gl.GetTextureTrace().FindMethod("BindTexture") );
1205 std::stringstream params;
1206 params << GL_TEXTURE_EXTERNAL_OES << ", " << 23;
1207 DALI_TEST_CHECK( gl.GetTextureTrace().FindMethodAndParams("BindTexture", params.str()) );
1212 // Scenarios 6: ImageView initially from regular image with custom shader but then SetImage called with Native
1213 int UtcDaliImageViewSetImageBufferImageWithCustomShaderToNativeImage(void)
1215 ToolkitTestApplication application;
1220 Property::Map customShader;
1221 customShader.Insert( "vertexShader", VERTEX_SHADER );
1222 customShader.Insert( "fragmentShader", FRAGMENT_SHADER );
1224 Property::Array shaderHints;
1225 shaderHints.PushBack( "requiresSelfDepthTest" );
1226 shaderHints.PushBack( "outputIsTransparent" );
1227 shaderHints.PushBack( "outputIsOpaque" );
1228 shaderHints.PushBack( "modifiesGeometry" );
1230 customShader.Insert( "hints", shaderHints );
1233 map.Insert( "shader", customShader );
1235 BufferImage image = CreateBufferImage( width, height, Color::WHITE );
1237 ImageView imageView = ImageView::New( image );
1238 imageView.SetProperty( ImageView::Property::IMAGE, map );
1239 Stage::GetCurrent().Add( imageView );
1241 TestGlAbstraction& gl = application.GetGlAbstraction();
1242 gl.EnableTextureCallTrace( true );
1244 std::vector< GLuint > ids;
1245 ids.push_back( 23 );
1246 application.GetGlAbstraction().SetNextTextureIds( ids );
1248 application.SendNotification();
1249 application.Render();
1251 DALI_TEST_CHECK( gl.GetTextureTrace().FindMethod("BindTexture") );
1253 std::stringstream params;
1254 params << GL_TEXTURE_2D << ", " << 23;
1255 DALI_TEST_CHECK( gl.GetTextureTrace().FindMethodAndParams("BindTexture", params.str()) );
1257 TestNativeImagePointer nativeImageInterface = TestNativeImage::New( width, height );
1258 NativeImage nativeImage = NativeImage::New( *(nativeImageInterface.Get()) );
1259 imageView.SetImage( nativeImage );
1262 ids.push_back( 24 );
1263 application.GetGlAbstraction().SetNextTextureIds( ids );
1265 application.SendNotification();
1266 application.Render();
1268 DALI_TEST_CHECK( gl.GetTextureTrace().FindMethod("BindTexture") );
1270 std::stringstream nativeImageParams;
1271 nativeImageParams << GL_TEXTURE_EXTERNAL_OES << ", " << 24;
1272 DALI_TEST_CHECK( gl.GetTextureTrace().FindMethodAndParams("BindTexture", nativeImageParams.str()) );
1278 int UtcDaliImageViewGetImageP1(void)
1280 ToolkitTestApplication application;
1282 ImageView imageView = ImageView::New();
1283 DALI_TEST_CHECK( ! imageView.GetImage() );
1285 Image image = CreateBufferImage();
1286 imageView.SetImage( image );
1287 DALI_TEST_CHECK( imageView.GetImage() == image );
1292 int UtcDaliImageViewGetImageP2(void)
1294 ToolkitTestApplication application;
1296 BufferImage image = CreateBufferImage();
1297 ImageView imageView = ImageView::New( image );
1298 DALI_TEST_CHECK( imageView.GetImage() == image );
1303 int UtcDaliImageViewGetImageN(void)
1305 ToolkitTestApplication application;
1307 ImageView imageView = ImageView::New( TEST_IMAGE_FILE_NAME );
1308 DALI_TEST_CHECK( ! imageView.GetImage() );
1310 Image image = CreateBufferImage();
1311 imageView.SetImage( image );
1312 DALI_TEST_CHECK( imageView.GetImage() == image );
1314 imageView.SetImage( TEST_IMAGE_FILE_NAME );
1315 DALI_TEST_CHECK( ! imageView.GetImage() );