2 * Copyright (c) 2014 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>
22 #include <dali-toolkit/dali-toolkit.h>
23 #include <dali/devel-api/scripting/scripting.h>
24 #include <dali/devel-api/rendering/renderer.h>
26 #include <test-native-image.h>
30 using namespace Toolkit;
32 void utc_dali_toolkit_image_view_startup(void)
34 test_return_value = TET_UNDEF;
37 void utc_dali_toolkit_image_view_cleanup(void)
39 test_return_value = TET_PASS;
45 const char* VERTEX_SHADER = DALI_COMPOSE_SHADER(
46 attribute mediump vec2 aPosition;\n
47 varying mediump vec2 vTexCoord;\n
48 uniform mediump mat4 uMvpMatrix;\n
49 uniform mediump vec3 uSize;\n
53 mediump vec4 vertexPosition = vec4(aPosition, 0.0, 1.0);\n
54 vertexPosition.xyz *= uSize;\n
55 vertexPosition = uMvpMatrix * vertexPosition;\n
57 vTexCoord = aPosition + vec2(0.5);\n
58 gl_Position = vertexPosition;\n
62 const char* FRAGMENT_SHADER = DALI_COMPOSE_SHADER(
63 varying mediump vec2 vTexCoord;\n
64 uniform sampler2D sTexture;\n
65 uniform lowp vec4 uColor;\n
69 gl_FragColor = texture2D( sTexture, vTexCoord ) * uColor;\n
73 const char* TEST_IMAGE_FILE_NAME = "gallery_image_01.jpg";
74 const char* TEST_IMAGE_FILE_NAME2 = "gallery_image_02.jpg";
76 void TestImage( ImageView imageView, BufferImage image )
78 Property::Value value = imageView.GetProperty( imageView.GetPropertyIndex( "image" ) );
81 DALI_TEST_CHECK( value.Get( map ) );
83 DALI_TEST_CHECK( map.Find( "width" ) );
84 DALI_TEST_CHECK( map.Find( "height" ) );
85 DALI_TEST_CHECK( map.Find( "type" ) );
88 DALI_TEST_CHECK( map[ "width" ].Get( width ) );
89 DALI_TEST_EQUALS( (unsigned int)width, image.GetWidth(), TEST_LOCATION );
92 DALI_TEST_CHECK( map[ "height" ].Get( height ) );
93 DALI_TEST_EQUALS( (unsigned int)height, image.GetHeight(), TEST_LOCATION );
96 DALI_TEST_CHECK( map[ "type" ].Get( type ) );
97 DALI_TEST_EQUALS( type, "BufferImage", TEST_LOCATION );
100 void TestImage( ImageView imageView, ResourceImage image )
102 Property::Value value = imageView.GetProperty( imageView.GetPropertyIndex( "image" ) );
105 DALI_TEST_CHECK( value.Get( map ) );
107 if( map.Find( "width" ) )
110 DALI_TEST_CHECK( map[ "width" ].Get( width ) );
111 DALI_TEST_EQUALS( (unsigned int)width, image.GetWidth(), TEST_LOCATION );
114 if( map.Find( "height" ) )
117 DALI_TEST_CHECK( map[ "height" ].Get( height ) );
118 DALI_TEST_EQUALS( (unsigned int)height, image.GetHeight(), TEST_LOCATION );
121 DALI_TEST_CHECK( map.Find( "type" ) );
124 DALI_TEST_CHECK( map[ "type" ].Get( type ) );
125 DALI_TEST_EQUALS( type, "ResourceImage", TEST_LOCATION );
127 std::string filename;
128 DALI_TEST_CHECK( map[ "filename" ].Get( filename ) );
129 DALI_TEST_EQUALS( filename, image.GetUrl(), TEST_LOCATION );
132 void TestUrl( ImageView imageView, const std::string url )
134 Property::Value value = imageView.GetProperty( imageView.GetPropertyIndex( "image" ) );
136 std::string urlActual;
137 DALI_TEST_CHECK( value.Get( urlActual ) );
138 DALI_TEST_EQUALS( urlActual, url, TEST_LOCATION );
143 int UtcDaliImageViewNewP(void)
145 TestApplication application;
147 ImageView imageView = ImageView::New();
149 DALI_TEST_CHECK( imageView );
154 int UtcDaliImageViewNewImageP(void)
156 TestApplication application;
158 BufferImage image = CreateBufferImage( 100, 200, Vector4( 1.f, 1.f, 1.f, 1.f ) );
159 ImageView imageView = ImageView::New( image );
161 DALI_TEST_CHECK( imageView );
162 TestImage( imageView, image );
167 int UtcDaliImageViewNewUrlP(void)
169 TestApplication application;
171 ImageView imageView = ImageView::New( TEST_IMAGE_FILE_NAME );
172 DALI_TEST_CHECK( imageView );
174 TestUrl( imageView, TEST_IMAGE_FILE_NAME );
179 int UtcDaliImageViewConstructorP(void)
181 TestApplication application;
185 DALI_TEST_CHECK( !imageView );
190 int UtcDaliImageViewCopyConstructorP(void)
192 TestApplication application;
194 // Initialize an object, ref count == 1
195 ImageView imageView = ImageView::New();
197 ImageView copy( imageView );
198 DALI_TEST_CHECK( copy );
203 int UtcDaliImageViewAssignmentOperatorP(void)
205 TestApplication application;
207 ImageView imageView = ImageView::New();
209 ImageView copy( imageView );
210 DALI_TEST_CHECK( copy );
211 DALI_TEST_EQUALS( imageView, copy, TEST_LOCATION );
216 int UtcDaliImageViewDownCastP(void)
218 TestApplication application;
220 ImageView imageView = ImageView::New();
222 BaseHandle object(imageView);
224 ImageView imageView2 = ImageView::DownCast( object );
225 DALI_TEST_CHECK(imageView2);
227 ImageView imageView3 = DownCast< ImageView >( object );
228 DALI_TEST_CHECK(imageView3);
233 int UtcDaliImageViewDownCastN(void)
235 TestApplication application;
237 BaseHandle unInitializedObject;
239 ImageView imageView1 = ImageView::DownCast( unInitializedObject );
240 DALI_TEST_CHECK( !imageView1 );
242 ImageView imageView2 = DownCast< ImageView >( unInitializedObject );
243 DALI_TEST_CHECK( !imageView2 );
248 int UtcDaliImageViewTypeRegistry(void)
250 ToolkitTestApplication application;
252 TypeRegistry typeRegistry = TypeRegistry::Get();
253 DALI_TEST_CHECK( typeRegistry );
255 TypeInfo typeInfo = typeRegistry.GetTypeInfo( "ImageView" );
256 DALI_TEST_CHECK( typeInfo );
258 BaseHandle handle = typeInfo.CreateInstance();
259 DALI_TEST_CHECK( handle );
261 ImageView imageView = ImageView::DownCast( handle );
262 DALI_TEST_CHECK( imageView );
267 int UtcDaliImageViewSetGetProperty01(void)
269 ToolkitTestApplication application;
271 ImageView imageView = ImageView::New();
273 Property::Index idx = imageView.GetPropertyIndex( "image" );
274 DALI_TEST_EQUALS( idx, (Property::Index)ImageView::Property::IMAGE, TEST_LOCATION );
276 imageView.SetProperty( idx, TEST_IMAGE_FILE_NAME );
277 TestUrl( imageView, TEST_IMAGE_FILE_NAME );
282 int UtcDaliImageViewSetGetProperty02(void)
284 ToolkitTestApplication application;
286 Image image = CreateBufferImage( 10, 10, Color::WHITE );
287 ImageView imageView = ImageView::New(image);
288 Vector4 fullImageRect( 0.f, 0.f, 1.f, 1.f );
290 Stage::GetCurrent().Add( imageView );
292 application.SendNotification();
293 application.Render();
294 TestGlAbstraction& gl = application.GetGlAbstraction();
296 Vector4 pixelAreaUniform;
297 DALI_TEST_CHECK( gl.GetUniformValue<Vector4>( "pixelArea", pixelAreaUniform ) );
298 DALI_TEST_EQUALS( pixelAreaUniform, fullImageRect, TEST_LOCATION );
300 Property::Value value = imageView.GetProperty( ImageView::Property::PIXEL_AREA );
301 Vector4 pixelAreaValue;
302 DALI_TEST_CHECK( value.Get(pixelAreaValue) );
303 DALI_TEST_EQUALS( pixelAreaValue, fullImageRect, TEST_LOCATION );
305 Vector4 pixelAreaSet( 0.2f, 0.2f, 0.3f, 0.3f );
306 imageView.SetProperty( ImageView::Property::PIXEL_AREA, pixelAreaSet);
308 application.SendNotification();
309 application.Render();
311 value = imageView.GetProperty( ImageView::Property::PIXEL_AREA );
312 value.Get(pixelAreaValue);
313 DALI_TEST_EQUALS( pixelAreaValue, pixelAreaSet, TEST_LOCATION );
315 DALI_TEST_CHECK( gl.GetUniformValue<Vector4>( "pixelArea", pixelAreaUniform ) );
316 DALI_TEST_EQUALS( pixelAreaUniform, pixelAreaSet, TEST_LOCATION );
321 int UtcDaliImageViewSetGetProperty03(void)
323 ToolkitTestApplication application;
325 Image image = CreateBufferImage( 10, 10, Color::WHITE );
326 ImageView imageView = ImageView::New(image);
327 Stage::GetCurrent().Add( imageView );
328 application.SendNotification();
329 application.Render();
331 // conventional alpha blending
332 Renderer renderer = imageView.GetRendererAt( 0 );
333 Property::Value value = renderer.GetProperty( Renderer::Property::BLEND_PRE_MULTIPLIED_ALPHA );
335 DALI_TEST_CHECK( value.Get( enable ) );
336 DALI_TEST_CHECK( !enable );
338 // pre-multiplied alpha blending
339 imageView.SetProperty( Toolkit::ImageView::Property::PRE_MULTIPLIED_ALPHA, true );
340 application.SendNotification();
341 application.Render();
343 int srcFactorRgb = renderer.GetProperty<int>( Renderer::Property::BLEND_FACTOR_SRC_RGB );
344 int destFactorRgb = renderer.GetProperty<int>( Renderer::Property::BLEND_FACTOR_DEST_RGB );
345 int srcFactorAlpha = renderer.GetProperty<int>( Renderer::Property::BLEND_FACTOR_SRC_ALPHA );
346 int destFactorAlpha = renderer.GetProperty<int>( Renderer::Property::BLEND_FACTOR_DEST_ALPHA );
347 DALI_TEST_CHECK( srcFactorRgb == BlendingFactor::ONE );
348 DALI_TEST_CHECK( destFactorRgb == BlendingFactor::ONE_MINUS_SRC_ALPHA );
349 DALI_TEST_CHECK( srcFactorAlpha == BlendingFactor::ONE );
350 DALI_TEST_CHECK( destFactorAlpha == BlendingFactor::ONE );
352 value = renderer.GetProperty( Renderer::Property::BLEND_PRE_MULTIPLIED_ALPHA );
353 DALI_TEST_CHECK( value.Get( enable ) );
354 DALI_TEST_CHECK( enable );
359 int UtcDaliImageViewSizeWithBackground(void)
361 ToolkitTestApplication application;
365 Image image = CreateBufferImage( width, height, Vector4(1.f, 1.f, 1.f, 1.f) );
366 ImageView imageView = ImageView::New();
367 imageView.SetBackgroundImage( image );
369 Stage::GetCurrent().Add( imageView );
370 application.SendNotification();
371 application.Render();
373 DALI_TEST_EQUALS( imageView.GetCurrentSize().width, (float)width, TEST_LOCATION );
374 DALI_TEST_EQUALS( imageView.GetCurrentSize().height, (float)height, TEST_LOCATION );
379 int UtcDaliImageViewSizeWithBackgroundAndImage(void)
381 ToolkitTestApplication application;
383 int widthBackground = 100;
384 int heightBackground = 200;
387 Image imageBackground = CreateBufferImage( widthBackground, heightBackground, Vector4(1.f, 1.f, 1.f, 1.f) );
388 Image image = CreateBufferImage( width, height, Vector4(1.f, 1.f, 1.f, 1.f) );
390 ImageView imageView = ImageView::New();
391 imageView.SetBackgroundImage( imageBackground );
392 imageView.SetImage( image );
394 Stage::GetCurrent().Add( imageView );
395 application.SendNotification();
396 application.Render();
398 DALI_TEST_EQUALS( imageView.GetCurrentSize().width, (float)width, TEST_LOCATION );
399 DALI_TEST_EQUALS( imageView.GetCurrentSize().height, (float)height, TEST_LOCATION );
404 int UtcDaliImageViewHeightForWidthBackground(void)
406 ToolkitTestApplication application;
408 int widthBackground = 100;
409 int heightBackground = 200;
410 Image imageBackground = CreateBufferImage( widthBackground, heightBackground, Vector4(1.f, 1.f, 1.f, 1.f) );
412 ImageView imageView = ImageView::New();
413 imageView.SetBackgroundImage( imageBackground );
415 Stage::GetCurrent().Add( imageView );
416 application.SendNotification();
417 application.Render();
419 Control control = Control::DownCast( imageView );
420 DALI_TEST_CHECK( control );
421 DALI_TEST_EQUALS( imageView.GetHeightForWidth( 123.f ), control.GetHeightForWidth( 123.f ), TEST_LOCATION );
422 DALI_TEST_EQUALS( imageView.GetWidthForHeight( 321.f ), control.GetWidthForHeight( 321.f ), TEST_LOCATION );
427 int UtcDaliImageViewHeightForWidthBackgroundAndImage(void)
429 ToolkitTestApplication application;
431 int widthBackground = 100;
432 int heightBackground = 200;
435 Image imageBackground = CreateBufferImage( widthBackground, heightBackground, Vector4(1.f, 1.f, 1.f, 1.f) );
436 Image image = CreateBufferImage( width, height, Vector4(1.f, 1.f, 1.f, 1.f) );
438 ImageView imageView = ImageView::New();
439 imageView.SetBackgroundImage( imageBackground );
440 imageView.SetImage( image );
442 Stage::GetCurrent().Add( imageView );
443 application.SendNotification();
444 application.Render();
446 DALI_TEST_EQUALS( imageView.GetHeightForWidth( width ), (float)height, TEST_LOCATION );
447 DALI_TEST_EQUALS( imageView.GetWidthForHeight( height ), (float)width, TEST_LOCATION );
452 int UtcDaliImageViewSetBufferImage(void)
454 ToolkitTestApplication application;
458 BufferImage image1 = CreateBufferImage( width1, height1, Vector4( 1.f, 1.f, 1.f, 1.f ) );
459 ImageView imageView = ImageView::New();
460 imageView.SetImage( image1 );
462 TestImage( imageView, image1 );
466 BufferImage image2 = CreateBufferImage( width2, height2, Vector4( 1.f, 1.f, 1.f, 1.f ) );
467 imageView.SetImage( image2 );
469 TestImage( imageView, image2 );
474 int UtcDaliImageViewSetImageUrl(void)
476 ToolkitTestApplication application;
478 ImageView imageView = ImageView::New();
479 imageView.SetImage( TEST_IMAGE_FILE_NAME );
480 TestUrl( imageView, TEST_IMAGE_FILE_NAME );
483 imageView.SetImage( TEST_IMAGE_FILE_NAME2 );
484 TestUrl( imageView, TEST_IMAGE_FILE_NAME2 );
489 int UtcDaliImageViewSetImageOnstageP(void)
491 ToolkitTestApplication application;
493 ImageView imageView = ImageView::New();
495 Stage::GetCurrent().Add( imageView );
496 application.SendNotification();
497 application.Render();
499 ResourceImage image1 = ResourceImage::New( TEST_IMAGE_FILE_NAME );
500 imageView.SetImage( image1 );
501 TestImage( imageView, image1 );
505 BufferImage image2 = CreateBufferImage( width, height, Vector4( 1.f, 1.f, 1.f, 1.f ) );
506 imageView.SetImage( image2 );
507 TestImage( imageView, image2 );
512 int UtcDaliImageViewSetImageOnstageN(void)
514 ToolkitTestApplication application;
516 ImageView imageView = ImageView::New();
518 Stage::GetCurrent().Add( imageView );
519 application.SendNotification();
520 application.Render();
522 ResourceImage image1 = ResourceImage::New( TEST_IMAGE_FILE_NAME );
523 imageView.SetImage( image1 );
524 TestImage( imageView, image1 );
527 imageView.SetImage( image2 );
529 Property::Value value = imageView.GetProperty( imageView.GetPropertyIndex( "image" ) );
531 //the value should be empty
533 DALI_TEST_CHECK( !value.Get( url ) );
536 DALI_TEST_CHECK( !value.Get( map ) );
541 int UtcDaliImageViewSetImageOffstageP(void)
543 ToolkitTestApplication application;
545 ImageView imageView = ImageView::New();
547 Stage::GetCurrent().Add( imageView );
548 application.SendNotification();
549 application.Render();
550 Stage::GetCurrent().Remove( imageView );
552 ResourceImage image1 = ResourceImage::New( TEST_IMAGE_FILE_NAME );
553 imageView.SetImage( image1 );
554 TestImage( imageView, image1 );
558 BufferImage image2 = CreateBufferImage( width, height, Vector4( 1.f, 1.f, 1.f, 1.f ) );
559 imageView.SetImage( image2 );
560 TestImage( imageView, image2 );
565 int UtcDaliImageViewSetImageOffstageN(void)
567 ToolkitTestApplication application;
569 ImageView imageView = ImageView::New();
571 Stage::GetCurrent().Add( imageView );
572 application.SendNotification();
573 application.Render();
574 Stage::GetCurrent().Remove( imageView );
576 ResourceImage image1 = ResourceImage::New( TEST_IMAGE_FILE_NAME );
577 imageView.SetImage( image1 );
578 TestImage( imageView, image1 );
581 imageView.SetImage( image2 );
583 Property::Value value = imageView.GetProperty( imageView.GetPropertyIndex( "image" ) );
585 //the value should be empty
587 DALI_TEST_CHECK( !value.Get( url ) );
590 DALI_TEST_CHECK( !value.Get( map ) );
595 int UtcDaliImageViewSetImageN(void)
597 ToolkitTestApplication application;
600 ImageView imageView = ImageView::New();
601 imageView.SetImage( image1 );
603 Property::Value value = imageView.GetProperty( imageView.GetPropertyIndex( "image" ) );
605 //the value should be empty
607 DALI_TEST_CHECK( !value.Get( url ) );
610 DALI_TEST_CHECK( !value.Get( map ) );
612 std::string resource_url;
613 Property::Value val = imageView.GetProperty( imageView.GetPropertyIndex( "image" ) );
614 DALI_TEST_CHECK( !val.Get( resource_url ) );
619 int UtcDaliImageViewSetImageTypeChangesP(void)
621 ToolkitTestApplication application;
623 ImageView imageView = ImageView::New();
629 Property::Value value = imageView.GetProperty( imageView.GetPropertyIndex( "image" ) );
630 DALI_TEST_CHECK( ! value.Get( url ) ); // Value should be empty
631 DALI_TEST_CHECK( ! value.Get( map ) ); // Value should be empty
634 imageView.SetImage( "TEST_URL" );
635 value = imageView.GetProperty( imageView.GetPropertyIndex( "image" ) );
637 DALI_TEST_CHECK( value.Get( url ) ); // Value should NOT be empty
638 DALI_TEST_CHECK( ! value.Get( map ) ); // Value should be empty
640 // Set an empty Image
641 imageView.SetImage( Image() );
642 value = imageView.GetProperty( imageView.GetPropertyIndex( "image" ) );
644 DALI_TEST_CHECK( ! value.Get( url ) ); // Value should be empty
645 DALI_TEST_CHECK( ! value.Get( map ) ); // Value should be empty
648 ResourceImage image1 = ResourceImage::New( TEST_IMAGE_FILE_NAME );
649 imageView.SetImage( image1 );
650 value = imageView.GetProperty( imageView.GetPropertyIndex( "image" ) );
652 DALI_TEST_CHECK( ! value.Get( url ) ); // Value should be empty
653 DALI_TEST_CHECK( value.Get( map ) ); // Value should NOT be empty
656 imageView.SetImage( "" );
657 value = imageView.GetProperty( imageView.GetPropertyIndex( "image" ) );
659 DALI_TEST_CHECK( ! value.Get( url ) ); // Value should be empty
660 DALI_TEST_CHECK( ! value.Get( map ) ); // Value should be empty
665 int UtcDaliImageViewResourceUrlP(void)
667 ToolkitTestApplication application;
669 ImageView imageView = ImageView::New();
670 DALI_TEST_CHECK( imageView.GetProperty( ImageView::Property::RESOURCE_URL ).Get< std::string >().empty() );
672 imageView.SetProperty( ImageView::Property::RESOURCE_URL, "TestString" );
673 DALI_TEST_EQUALS( imageView.GetProperty( ImageView::Property::RESOURCE_URL ).Get< std::string >(), "TestString", TEST_LOCATION );
678 // Scenarios 1: ImageView from regular image
679 int UtcDaliImageViewSetImageBufferImage(void)
681 ToolkitTestApplication application;
683 ImageView imageView = ImageView::New();
684 Stage::GetCurrent().Add( imageView );
686 TestGlAbstraction& gl = application.GetGlAbstraction();
687 gl.EnableTextureCallTrace( true );
689 std::vector< GLuint > ids;
691 application.GetGlAbstraction().SetNextTextureIds( ids );
695 BufferImage image = CreateBufferImage( width, height, Color::WHITE );
697 imageView.SetImage( image );
699 application.SendNotification();
700 application.Render();
702 DALI_TEST_CHECK( gl.GetTextureTrace().FindMethod("BindTexture") );
704 std::stringstream params;
705 params << GL_TEXTURE_2D << ", " << 23;
706 DALI_TEST_CHECK( gl.GetTextureTrace().FindMethodAndParams("BindTexture", params.str()) );
711 // Scenarios 2: ImageView from Native image
712 int UtcDaliImageViewSetImageNativeImage(void)
714 ToolkitTestApplication application;
716 ImageView imageView = ImageView::New();
717 Stage::GetCurrent().Add( imageView );
719 TestGlAbstraction& gl = application.GetGlAbstraction();
720 gl.EnableTextureCallTrace( true );
722 std::vector< GLuint > ids;
724 application.GetGlAbstraction().SetNextTextureIds( ids );
728 TestNativeImagePointer nativeImageInterface = TestNativeImage::New( width, height );
729 NativeImage nativeImage = NativeImage::New( *(nativeImageInterface.Get()) );
731 imageView.SetImage( nativeImage );
732 application.SendNotification();
733 application.Render();
735 DALI_TEST_CHECK( gl.GetTextureTrace().FindMethod("BindTexture") );
737 std::stringstream params;
738 params << GL_TEXTURE_2D << ", " << 23;
739 DALI_TEST_CHECK( gl.GetTextureTrace().FindMethodAndParams("BindTexture", params.str()) );
744 // Scenarios 3: ImageView initially from regular image but then SetImage called with Native image
745 int UtcDaliImageViewSetImageBufferImageToNativeImage(void)
747 ToolkitTestApplication application;
751 BufferImage image = CreateBufferImage( width, height, Color::WHITE );
753 ImageView imageView = ImageView::New( image );
754 Stage::GetCurrent().Add( imageView );
756 TestGlAbstraction& gl = application.GetGlAbstraction();
757 gl.EnableTextureCallTrace( true );
759 std::vector< GLuint > ids;
761 application.GetGlAbstraction().SetNextTextureIds( ids );
763 application.SendNotification();
764 application.Render();
766 DALI_TEST_CHECK( gl.GetTextureTrace().FindMethod("BindTexture") );
768 std::stringstream params;
769 params << GL_TEXTURE_2D << ", " << 23;
770 DALI_TEST_CHECK( gl.GetTextureTrace().FindMethodAndParams("BindTexture", params.str()) );
774 TestNativeImagePointer nativeImageInterface = TestNativeImage::New( width, height );
775 NativeImage nativeImage = NativeImage::New( *(nativeImageInterface.Get()) );
776 imageView.SetImage( nativeImage );
780 application.GetGlAbstraction().SetNextTextureIds( ids );
782 application.SendNotification();
783 application.Render();
785 DALI_TEST_CHECK( gl.GetTextureTrace().FindMethod("BindTexture") );
787 std::stringstream nextTextureParams;
788 nextTextureParams << GL_TEXTURE_2D << ", " << 24;
789 DALI_TEST_CHECK( gl.GetTextureTrace().FindMethodAndParams("BindTexture", nextTextureParams.str()) );
794 // Scenarios 4: ImageView initially from Native image but then SetImage called with regular image
795 int UtcDaliImageViewSetImageNativeImageToBufferImage(void)
797 ToolkitTestApplication application;
801 TestNativeImagePointer nativeImageInterface = TestNativeImage::New( width, height );
802 NativeImage nativeImage = NativeImage::New( *(nativeImageInterface.Get()) );
804 ImageView imageView = ImageView::New( nativeImage );
805 Stage::GetCurrent().Add( imageView );
807 TestGlAbstraction& gl = application.GetGlAbstraction();
808 gl.EnableTextureCallTrace( true );
810 std::vector< GLuint > ids;
812 application.GetGlAbstraction().SetNextTextureIds( ids );
814 application.SendNotification();
815 application.Render();
817 DALI_TEST_CHECK( gl.GetTextureTrace().FindMethod("BindTexture") );
819 std::stringstream params;
820 params << GL_TEXTURE_2D << ", " << 23;
821 DALI_TEST_CHECK( gl.GetTextureTrace().FindMethodAndParams("BindTexture", params.str()) );
825 BufferImage image = CreateBufferImage( width, height, Color::WHITE );
826 imageView.SetImage( image );
830 application.GetGlAbstraction().SetNextTextureIds( ids );
832 application.SendNotification();
833 application.Render();
835 DALI_TEST_CHECK( gl.GetTextureTrace().FindMethod("BindTexture") );
837 std::stringstream nextTextureParams;
838 nextTextureParams << GL_TEXTURE_2D << ", " << 24;
839 DALI_TEST_CHECK( gl.GetTextureTrace().FindMethodAndParams("BindTexture", nextTextureParams.str()) );
844 // Scenarios 5: ImageView from Native image with custom shader
845 int UtcDaliImageViewSetImageNativeImageWithCustomShader(void)
847 ToolkitTestApplication application;
852 Property::Map customShader;
853 customShader.Insert( "vertexShader", VERTEX_SHADER );
854 customShader.Insert( "fragmentShader", FRAGMENT_SHADER );
856 Property::Array shaderHints;
857 shaderHints.PushBack( "requiresSelfDepthTest" );
858 shaderHints.PushBack( "outputIsTransparent" );
859 shaderHints.PushBack( "outputIsOpaque" );
860 shaderHints.PushBack( "modifiesGeometry" );
862 customShader.Insert( "hints", shaderHints );
865 map.Insert( "rendererType", "image" );
866 map.Insert( "shader", customShader );
868 TestNativeImagePointer nativeImageInterface = TestNativeImage::New( width, height );
869 NativeImage nativeImage = NativeImage::New( *(nativeImageInterface.Get()) );
871 ImageView imageView = ImageView::New( nativeImage );
872 imageView.SetProperty( ImageView::Property::IMAGE, map );
873 Stage::GetCurrent().Add( imageView );
875 imageView.SetProperty( ImageView::Property::IMAGE, map );
877 TestGlAbstraction& gl = application.GetGlAbstraction();
878 gl.EnableTextureCallTrace( true );
880 std::vector< GLuint > ids;
882 application.GetGlAbstraction().SetNextTextureIds( ids );
884 application.SendNotification();
885 application.Render();
887 DALI_TEST_CHECK( gl.GetTextureTrace().FindMethod("BindTexture") );
889 std::stringstream params;
890 params << GL_TEXTURE_2D << ", " << 23;
891 DALI_TEST_CHECK( gl.GetTextureTrace().FindMethodAndParams("BindTexture", params.str()) );
896 // Scenarios 6: ImageView initially from regular image with custom shader but then SetImage called with Native
897 int UtcDaliImageViewSetImageBufferImageWithCustomShaderToNativeImage(void)
899 ToolkitTestApplication application;
904 Property::Map customShader;
905 customShader.Insert( "vertexShader", VERTEX_SHADER );
906 customShader.Insert( "fragmentShader", FRAGMENT_SHADER );
908 Property::Array shaderHints;
909 shaderHints.PushBack( "requiresSelfDepthTest" );
910 shaderHints.PushBack( "outputIsTransparent" );
911 shaderHints.PushBack( "outputIsOpaque" );
912 shaderHints.PushBack( "modifiesGeometry" );
914 customShader.Insert( "hints", shaderHints );
917 map.Insert( "rendererType", "image" );
918 map.Insert( "shader", customShader );
920 BufferImage image = CreateBufferImage( width, height, Color::WHITE );
922 ImageView imageView = ImageView::New( image );
923 imageView.SetProperty( ImageView::Property::IMAGE, map );
924 Stage::GetCurrent().Add( imageView );
926 imageView.SetProperty( ImageView::Property::IMAGE, map );
928 TestGlAbstraction& gl = application.GetGlAbstraction();
929 gl.EnableTextureCallTrace( true );
931 std::vector< GLuint > ids;
933 application.GetGlAbstraction().SetNextTextureIds( ids );
935 application.SendNotification();
936 application.Render();
938 DALI_TEST_CHECK( gl.GetTextureTrace().FindMethod("BindTexture") );
940 std::stringstream params;
941 params << GL_TEXTURE_2D << ", " << 23;
942 DALI_TEST_CHECK( gl.GetTextureTrace().FindMethodAndParams("BindTexture", params.str()) );
944 TestNativeImagePointer nativeImageInterface = TestNativeImage::New( width, height );
945 NativeImage nativeImage = NativeImage::New( *(nativeImageInterface.Get()) );
946 imageView.SetImage( nativeImage );
950 application.GetGlAbstraction().SetNextTextureIds( ids );
952 application.SendNotification();
953 application.Render();
955 DALI_TEST_CHECK( gl.GetTextureTrace().FindMethod("BindTexture") );
957 std::stringstream nativeImageParams;
958 nativeImageParams << GL_TEXTURE_2D << ", " << 24;
959 DALI_TEST_CHECK( gl.GetTextureTrace().FindMethodAndParams("BindTexture", nativeImageParams.str()) );
965 int UtcDaliImageViewGetImageP1(void)
967 ToolkitTestApplication application;
969 ImageView imageView = ImageView::New();
970 DALI_TEST_CHECK( ! imageView.GetImage() );
972 Image image = CreateBufferImage();
973 imageView.SetImage( image );
974 DALI_TEST_CHECK( imageView.GetImage() == image );
979 int UtcDaliImageViewGetImageP2(void)
981 ToolkitTestApplication application;
983 BufferImage image = CreateBufferImage();
984 ImageView imageView = ImageView::New( image );
985 DALI_TEST_CHECK( imageView.GetImage() == image );
990 int UtcDaliImageViewGetImageN(void)
992 ToolkitTestApplication application;
994 ImageView imageView = ImageView::New( TEST_IMAGE_FILE_NAME );
995 DALI_TEST_CHECK( ! imageView.GetImage() );
997 Image image = CreateBufferImage();
998 imageView.SetImage( image );
999 DALI_TEST_CHECK( imageView.GetImage() == image );
1001 imageView.SetImage( TEST_IMAGE_FILE_NAME );
1002 DALI_TEST_CHECK( ! imageView.GetImage() );