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>
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/devel-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 void TestImage( ImageView imageView, BufferImage image )
85 Property::Value value = imageView.GetProperty( imageView.GetPropertyIndex( "image" ) );
88 DALI_TEST_CHECK( value.Get( map ) );
90 DALI_TEST_CHECK( map.Find( "width" ) );
91 DALI_TEST_CHECK( map.Find( "height" ) );
92 DALI_TEST_CHECK( map.Find( "type" ) );
95 DALI_TEST_CHECK( map[ "width" ].Get( width ) );
96 DALI_TEST_EQUALS( (unsigned int)width, image.GetWidth(), TEST_LOCATION );
99 DALI_TEST_CHECK( map[ "height" ].Get( height ) );
100 DALI_TEST_EQUALS( (unsigned int)height, image.GetHeight(), TEST_LOCATION );
103 DALI_TEST_CHECK( map[ "type" ].Get( type ) );
104 DALI_TEST_EQUALS( type, "BufferImage", TEST_LOCATION );
107 void TestImage( ImageView imageView, ResourceImage image )
109 Property::Value value = imageView.GetProperty( imageView.GetPropertyIndex( "image" ) );
112 DALI_TEST_CHECK( value.Get( map ) );
114 if( map.Find( "width" ) )
117 DALI_TEST_CHECK( map[ "width" ].Get( width ) );
118 DALI_TEST_EQUALS( (unsigned int)width, image.GetWidth(), TEST_LOCATION );
121 if( map.Find( "height" ) )
124 DALI_TEST_CHECK( map[ "height" ].Get( height ) );
125 DALI_TEST_EQUALS( (unsigned int)height, image.GetHeight(), TEST_LOCATION );
128 DALI_TEST_CHECK( map.Find( "type" ) );
131 DALI_TEST_CHECK( map[ "type" ].Get( type ) );
132 DALI_TEST_EQUALS( type, "ResourceImage", TEST_LOCATION );
134 std::string filename;
135 DALI_TEST_CHECK( map[ "filename" ].Get( filename ) );
136 DALI_TEST_EQUALS( filename, image.GetUrl(), TEST_LOCATION );
139 void TestUrl( ImageView imageView, const std::string url )
141 Property::Value value = imageView.GetProperty( imageView.GetPropertyIndex( "image" ) );
143 std::string urlActual;
144 DALI_TEST_CHECK( value.Get( urlActual ) );
145 DALI_TEST_EQUALS( urlActual, url, TEST_LOCATION );
150 int UtcDaliImageViewNewP(void)
152 TestApplication application;
154 ImageView imageView = ImageView::New();
156 DALI_TEST_CHECK( imageView );
161 int UtcDaliImageViewNewImageP(void)
163 TestApplication application;
165 BufferImage image = CreateBufferImage( 100, 200, Vector4( 1.f, 1.f, 1.f, 1.f ) );
166 ImageView imageView = ImageView::New( image );
168 DALI_TEST_CHECK( imageView );
169 TestImage( imageView, image );
174 int UtcDaliImageViewNewUrlP(void)
176 TestApplication application;
178 ImageView imageView = ImageView::New( TEST_IMAGE_FILE_NAME );
179 DALI_TEST_CHECK( imageView );
181 TestUrl( imageView, TEST_IMAGE_FILE_NAME );
186 int UtcDaliImageViewConstructorP(void)
188 TestApplication application;
192 DALI_TEST_CHECK( !imageView );
197 int UtcDaliImageViewCopyConstructorP(void)
199 TestApplication application;
201 // Initialize an object, ref count == 1
202 ImageView imageView = ImageView::New();
204 ImageView copy( imageView );
205 DALI_TEST_CHECK( copy );
210 int UtcDaliImageViewAssignmentOperatorP(void)
212 TestApplication application;
214 ImageView imageView = ImageView::New();
216 ImageView copy( imageView );
217 DALI_TEST_CHECK( copy );
218 DALI_TEST_EQUALS( imageView, copy, TEST_LOCATION );
223 int UtcDaliImageViewDownCastP(void)
225 TestApplication application;
227 ImageView imageView = ImageView::New();
229 BaseHandle object(imageView);
231 ImageView imageView2 = ImageView::DownCast( object );
232 DALI_TEST_CHECK(imageView2);
234 ImageView imageView3 = DownCast< ImageView >( object );
235 DALI_TEST_CHECK(imageView3);
240 int UtcDaliImageViewDownCastN(void)
242 TestApplication application;
244 BaseHandle unInitializedObject;
246 ImageView imageView1 = ImageView::DownCast( unInitializedObject );
247 DALI_TEST_CHECK( !imageView1 );
249 ImageView imageView2 = DownCast< ImageView >( unInitializedObject );
250 DALI_TEST_CHECK( !imageView2 );
255 int UtcDaliImageViewTypeRegistry(void)
257 ToolkitTestApplication application;
259 TypeRegistry typeRegistry = TypeRegistry::Get();
260 DALI_TEST_CHECK( typeRegistry );
262 TypeInfo typeInfo = typeRegistry.GetTypeInfo( "ImageView" );
263 DALI_TEST_CHECK( typeInfo );
265 BaseHandle handle = typeInfo.CreateInstance();
266 DALI_TEST_CHECK( handle );
268 ImageView imageView = ImageView::DownCast( handle );
269 DALI_TEST_CHECK( imageView );
274 int UtcDaliImageViewSetGetProperty01(void)
276 ToolkitTestApplication application;
278 ImageView imageView = ImageView::New();
280 Property::Index idx = imageView.GetPropertyIndex( "image" );
281 DALI_TEST_EQUALS( idx, (Property::Index)ImageView::Property::IMAGE, TEST_LOCATION );
283 imageView.SetProperty( idx, TEST_IMAGE_FILE_NAME );
284 TestUrl( imageView, TEST_IMAGE_FILE_NAME );
289 int UtcDaliImageViewSetGetProperty02(void)
291 ToolkitTestApplication application;
293 Image image = CreateBufferImage( 10, 10, Color::WHITE );
294 ImageView imageView = ImageView::New(image);
295 Vector4 fullImageRect( 0.f, 0.f, 1.f, 1.f );
297 Stage::GetCurrent().Add( imageView );
299 application.SendNotification();
300 application.Render();
301 TestGlAbstraction& gl = application.GetGlAbstraction();
303 Vector4 pixelAreaUniform;
304 DALI_TEST_CHECK( gl.GetUniformValue<Vector4>( "pixelArea", pixelAreaUniform ) );
305 DALI_TEST_EQUALS( pixelAreaUniform, fullImageRect, TEST_LOCATION );
307 Property::Value value = imageView.GetProperty( ImageView::Property::PIXEL_AREA );
308 Vector4 pixelAreaValue;
309 DALI_TEST_CHECK( value.Get(pixelAreaValue) );
310 DALI_TEST_EQUALS( pixelAreaValue, fullImageRect, TEST_LOCATION );
312 Vector4 pixelAreaSet( 0.2f, 0.2f, 0.3f, 0.3f );
313 imageView.SetProperty( ImageView::Property::PIXEL_AREA, pixelAreaSet);
315 application.SendNotification();
316 application.Render();
318 value = imageView.GetProperty( ImageView::Property::PIXEL_AREA );
319 value.Get(pixelAreaValue);
320 DALI_TEST_EQUALS( pixelAreaValue, pixelAreaSet, TEST_LOCATION );
322 DALI_TEST_CHECK( gl.GetUniformValue<Vector4>( "pixelArea", pixelAreaUniform ) );
323 DALI_TEST_EQUALS( pixelAreaUniform, pixelAreaSet, TEST_LOCATION );
328 int UtcDaliImageViewSetGetProperty03(void)
330 ToolkitTestApplication application;
332 Image image = CreateBufferImage( 10, 10, Color::WHITE );
333 ImageView imageView = ImageView::New(image);
334 Stage::GetCurrent().Add( imageView );
335 application.SendNotification();
336 application.Render();
338 // conventional alpha blending
339 Renderer renderer = imageView.GetRendererAt( 0 );
340 Property::Value value = renderer.GetProperty( Renderer::Property::BLEND_PRE_MULTIPLIED_ALPHA );
342 DALI_TEST_CHECK( value.Get( enable ) );
343 DALI_TEST_CHECK( !enable );
345 // pre-multiplied alpha blending
346 imageView.SetProperty( Toolkit::ImageView::Property::PRE_MULTIPLIED_ALPHA, true );
347 application.SendNotification();
348 application.Render();
350 int srcFactorRgb = renderer.GetProperty<int>( Renderer::Property::BLEND_FACTOR_SRC_RGB );
351 int destFactorRgb = renderer.GetProperty<int>( Renderer::Property::BLEND_FACTOR_DEST_RGB );
352 int srcFactorAlpha = renderer.GetProperty<int>( Renderer::Property::BLEND_FACTOR_SRC_ALPHA );
353 int destFactorAlpha = renderer.GetProperty<int>( Renderer::Property::BLEND_FACTOR_DEST_ALPHA );
354 DALI_TEST_CHECK( srcFactorRgb == BlendingFactor::ONE );
355 DALI_TEST_CHECK( destFactorRgb == BlendingFactor::ONE_MINUS_SRC_ALPHA );
356 DALI_TEST_CHECK( srcFactorAlpha == BlendingFactor::ONE );
357 DALI_TEST_CHECK( destFactorAlpha == BlendingFactor::ONE );
359 value = renderer.GetProperty( Renderer::Property::BLEND_PRE_MULTIPLIED_ALPHA );
360 DALI_TEST_CHECK( value.Get( enable ) );
361 DALI_TEST_CHECK( enable );
366 int UtcDaliImageViewAsyncLoadingWithoutAltasing(void)
368 ToolkitTestApplication application;
370 // Async loading, no atlasing for big size image
371 ImageView imageView = ImageView::New( gImage_600_RGB );
373 // By default, Aysnc loading is used
374 Stage::GetCurrent().Add( imageView );
375 application.SendNotification();
376 application.Render(16);
377 application.Render(16);
378 application.SendNotification();
380 // BitmapLoader is not used
381 BitmapLoader loader = BitmapLoader::GetLatestCreated();
382 DALI_TEST_CHECK( !loader );
387 int UtcDaliImageViewAsyncLoadingWithAltasing(void)
389 ToolkitTestApplication application;
391 //Async loading, automatic atlasing for small size image
392 TraceCallStack& callStack = application.GetGlAbstraction().GetTextureTrace();
394 callStack.Enable(true);
396 ImageView imageView = ImageView::New( gImage_34_RGBA, ImageDimensions( 34, 34 ) );
398 // By default, Aysnc loading is used
399 // loading is not started if the actor is offStage
400 BitmapLoader loader = BitmapLoader::GetLatestCreated();
401 DALI_TEST_CHECK( !loader );
403 Stage::GetCurrent().Add( imageView );
404 application.SendNotification();
405 application.Render(16);
406 application.Render(16);
407 application.SendNotification();
410 loader = BitmapLoader::GetLatestCreated();
411 DALI_TEST_CHECK( loader );
413 // worker thread is created
414 EventThreadCallback* eventTrigger = EventThreadCallback::Get();
415 DALI_TEST_CHECK( eventTrigger );
417 loader.WaitForLoading();// waiting until the image to be loaded
418 DALI_TEST_CHECK( loader.IsLoaded() );
420 CallbackBase* callback = eventTrigger->GetCallback();
421 CallbackBase::Execute( *callback );
423 application.SendNotification();
424 application.Render(16);
426 callStack.Enable(false);
428 DALI_TEST_CHECK( callStack.FindMethodAndParams("TexSubImage2D", "0, 0, 34, 34" ) );
434 int UtcDaliImageViewSyncLoading(void)
436 ToolkitTestApplication application;
438 Property::Map syncLoadingMap;
439 syncLoadingMap[ "synchronousLoading" ] = true;
441 // Sync loading, no atlasing for big size image
443 ImageView imageView = ImageView::New( gImage_600_RGB );
445 // Sync loading is used
446 imageView.SetProperty( ImageView::Property::IMAGE, syncLoadingMap );
448 // BitmapLoader is used, and the loading is started immediately even the actor is not on stage.
449 BitmapLoader loader = BitmapLoader::GetLatestCreated();
450 DALI_TEST_CHECK( loader );
453 // Sync loading, automatic atlasing for small size image
455 BitmapLoader::ResetLatestCreated();
456 TraceCallStack& callStack = application.GetGlAbstraction().GetTextureTrace();
458 callStack.Enable(true);
460 ImageView imageView = ImageView::New( );
461 // Sync loading is used
462 syncLoadingMap[ "url" ] = gImage_34_RGBA;
463 syncLoadingMap[ "desiredHeight" ] = 34;
464 syncLoadingMap[ "desiredWidth" ] = 34;
465 imageView.SetProperty( ImageView::Property::IMAGE, syncLoadingMap );
467 // loading is started even if the actor is offStage
468 BitmapLoader loader = BitmapLoader::GetLatestCreated();
469 DALI_TEST_CHECK( loader );
471 loader.WaitForLoading();
473 DALI_TEST_CHECK( loader.IsLoaded() );
475 Stage::GetCurrent().Add( imageView );
476 application.SendNotification();
477 application.Render(16);
478 DALI_TEST_CHECK( callStack.FindMethodAndParams("TexSubImage2D", "0, 0, 34, 34" ) );
484 int UtcDaliImageViewSizeWithBackground(void)
486 ToolkitTestApplication application;
490 Image image = CreateBufferImage( width, height, Vector4(1.f, 1.f, 1.f, 1.f) );
491 ImageView imageView = ImageView::New();
492 imageView.SetBackgroundImage( image );
494 Stage::GetCurrent().Add( imageView );
495 application.SendNotification();
496 application.Render();
498 DALI_TEST_EQUALS( imageView.GetCurrentSize().width, (float)width, TEST_LOCATION );
499 DALI_TEST_EQUALS( imageView.GetCurrentSize().height, (float)height, TEST_LOCATION );
504 int UtcDaliImageViewSizeWithBackgroundAndImage(void)
506 ToolkitTestApplication application;
508 int widthBackground = 100;
509 int heightBackground = 200;
512 Image imageBackground = CreateBufferImage( widthBackground, heightBackground, Vector4(1.f, 1.f, 1.f, 1.f) );
513 Image image = CreateBufferImage( width, height, Vector4(1.f, 1.f, 1.f, 1.f) );
515 ImageView imageView = ImageView::New();
516 imageView.SetBackgroundImage( imageBackground );
517 imageView.SetImage( image );
519 Stage::GetCurrent().Add( imageView );
520 application.SendNotification();
521 application.Render();
523 DALI_TEST_EQUALS( imageView.GetCurrentSize().width, (float)width, TEST_LOCATION );
524 DALI_TEST_EQUALS( imageView.GetCurrentSize().height, (float)height, TEST_LOCATION );
529 int UtcDaliImageViewHeightForWidthBackground(void)
531 ToolkitTestApplication application;
533 int widthBackground = 100;
534 int heightBackground = 200;
535 Image imageBackground = CreateBufferImage( widthBackground, heightBackground, Vector4(1.f, 1.f, 1.f, 1.f) );
537 ImageView imageView = ImageView::New();
538 imageView.SetBackgroundImage( imageBackground );
540 Stage::GetCurrent().Add( imageView );
541 application.SendNotification();
542 application.Render();
544 Control control = Control::DownCast( imageView );
545 DALI_TEST_CHECK( control );
546 DALI_TEST_EQUALS( imageView.GetHeightForWidth( 123.f ), control.GetHeightForWidth( 123.f ), TEST_LOCATION );
547 DALI_TEST_EQUALS( imageView.GetWidthForHeight( 321.f ), control.GetWidthForHeight( 321.f ), TEST_LOCATION );
552 int UtcDaliImageViewHeightForWidthBackgroundAndImage(void)
554 ToolkitTestApplication application;
556 int widthBackground = 100;
557 int heightBackground = 200;
560 Image imageBackground = CreateBufferImage( widthBackground, heightBackground, Vector4(1.f, 1.f, 1.f, 1.f) );
561 Image image = CreateBufferImage( width, height, Vector4(1.f, 1.f, 1.f, 1.f) );
563 ImageView imageView = ImageView::New();
564 imageView.SetBackgroundImage( imageBackground );
565 imageView.SetImage( image );
567 Stage::GetCurrent().Add( imageView );
568 application.SendNotification();
569 application.Render();
571 DALI_TEST_EQUALS( imageView.GetHeightForWidth( width ), (float)height, TEST_LOCATION );
572 DALI_TEST_EQUALS( imageView.GetWidthForHeight( height ), (float)width, TEST_LOCATION );
577 int UtcDaliImageViewSetBufferImage(void)
579 ToolkitTestApplication application;
583 BufferImage image1 = CreateBufferImage( width1, height1, Vector4( 1.f, 1.f, 1.f, 1.f ) );
584 ImageView imageView = ImageView::New();
585 imageView.SetImage( image1 );
587 TestImage( imageView, image1 );
591 BufferImage image2 = CreateBufferImage( width2, height2, Vector4( 1.f, 1.f, 1.f, 1.f ) );
592 imageView.SetImage( image2 );
594 TestImage( imageView, image2 );
599 int UtcDaliImageViewSetImageUrl(void)
601 ToolkitTestApplication application;
603 ImageView imageView = ImageView::New();
604 imageView.SetImage( TEST_IMAGE_FILE_NAME );
605 TestUrl( imageView, TEST_IMAGE_FILE_NAME );
608 imageView.SetImage( TEST_IMAGE_FILE_NAME2 );
609 TestUrl( imageView, TEST_IMAGE_FILE_NAME2 );
614 int UtcDaliImageViewSetImageOnstageP(void)
616 ToolkitTestApplication application;
618 ImageView imageView = ImageView::New();
620 Stage::GetCurrent().Add( imageView );
621 application.SendNotification();
622 application.Render();
624 ResourceImage image1 = ResourceImage::New( TEST_IMAGE_FILE_NAME );
625 imageView.SetImage( image1 );
626 TestImage( imageView, image1 );
630 BufferImage image2 = CreateBufferImage( width, height, Vector4( 1.f, 1.f, 1.f, 1.f ) );
631 imageView.SetImage( image2 );
632 TestImage( imageView, image2 );
637 int UtcDaliImageViewSetImageOnstageN(void)
639 ToolkitTestApplication application;
641 ImageView imageView = ImageView::New();
643 Stage::GetCurrent().Add( imageView );
644 application.SendNotification();
645 application.Render();
647 ResourceImage image1 = ResourceImage::New( TEST_IMAGE_FILE_NAME );
648 imageView.SetImage( image1 );
649 TestImage( imageView, image1 );
652 imageView.SetImage( image2 );
654 Property::Value value = imageView.GetProperty( imageView.GetPropertyIndex( "image" ) );
656 //the value should be empty
658 DALI_TEST_CHECK( !value.Get( url ) );
661 DALI_TEST_CHECK( !value.Get( map ) );
666 int UtcDaliImageViewSetImageOffstageP(void)
668 ToolkitTestApplication application;
670 ImageView imageView = ImageView::New();
672 Stage::GetCurrent().Add( imageView );
673 application.SendNotification();
674 application.Render();
675 Stage::GetCurrent().Remove( imageView );
677 ResourceImage image1 = ResourceImage::New( TEST_IMAGE_FILE_NAME );
678 imageView.SetImage( image1 );
679 TestImage( imageView, image1 );
683 BufferImage image2 = CreateBufferImage( width, height, Vector4( 1.f, 1.f, 1.f, 1.f ) );
684 imageView.SetImage( image2 );
685 TestImage( imageView, image2 );
690 int UtcDaliImageViewSetImageOffstageN(void)
692 ToolkitTestApplication application;
694 ImageView imageView = ImageView::New();
696 Stage::GetCurrent().Add( imageView );
697 application.SendNotification();
698 application.Render();
699 Stage::GetCurrent().Remove( imageView );
701 ResourceImage image1 = ResourceImage::New( TEST_IMAGE_FILE_NAME );
702 imageView.SetImage( image1 );
703 TestImage( imageView, image1 );
706 imageView.SetImage( image2 );
708 Property::Value value = imageView.GetProperty( imageView.GetPropertyIndex( "image" ) );
710 //the value should be empty
712 DALI_TEST_CHECK( !value.Get( url ) );
715 DALI_TEST_CHECK( !value.Get( map ) );
720 int UtcDaliImageViewSetImageN(void)
722 ToolkitTestApplication application;
725 ImageView imageView = ImageView::New();
726 imageView.SetImage( image1 );
728 Property::Value value = imageView.GetProperty( imageView.GetPropertyIndex( "image" ) );
730 //the value should be empty
732 DALI_TEST_CHECK( !value.Get( url ) );
735 DALI_TEST_CHECK( !value.Get( map ) );
737 std::string resource_url;
738 Property::Value val = imageView.GetProperty( imageView.GetPropertyIndex( "image" ) );
739 DALI_TEST_CHECK( !val.Get( resource_url ) );
744 int UtcDaliImageViewSetImageTypeChangesP(void)
746 ToolkitTestApplication application;
748 ImageView imageView = ImageView::New();
754 Property::Value value = imageView.GetProperty( imageView.GetPropertyIndex( "image" ) );
755 DALI_TEST_CHECK( ! value.Get( url ) ); // Value should be empty
756 DALI_TEST_CHECK( ! value.Get( map ) ); // Value should be empty
759 imageView.SetImage( "TEST_URL" );
760 value = imageView.GetProperty( imageView.GetPropertyIndex( "image" ) );
762 DALI_TEST_CHECK( value.Get( url ) ); // Value should NOT be empty
763 DALI_TEST_CHECK( ! value.Get( map ) ); // Value should be empty
765 // Set an empty Image
766 imageView.SetImage( Image() );
767 value = imageView.GetProperty( imageView.GetPropertyIndex( "image" ) );
769 DALI_TEST_CHECK( ! value.Get( url ) ); // Value should be empty
770 DALI_TEST_CHECK( ! value.Get( map ) ); // Value should be empty
773 ResourceImage image1 = ResourceImage::New( TEST_IMAGE_FILE_NAME );
774 imageView.SetImage( image1 );
775 value = imageView.GetProperty( imageView.GetPropertyIndex( "image" ) );
777 DALI_TEST_CHECK( ! value.Get( url ) ); // Value should be empty
778 DALI_TEST_CHECK( value.Get( map ) ); // Value should NOT be empty
781 imageView.SetImage( "" );
782 value = imageView.GetProperty( imageView.GetPropertyIndex( "image" ) );
784 DALI_TEST_CHECK( ! value.Get( url ) ); // Value should be empty
785 DALI_TEST_CHECK( ! value.Get( map ) ); // Value should be empty
790 int UtcDaliImageViewResourceUrlP(void)
792 ToolkitTestApplication application;
794 ImageView imageView = ImageView::New();
795 DALI_TEST_CHECK( imageView.GetProperty( ImageView::Property::RESOURCE_URL ).Get< std::string >().empty() );
797 imageView.SetProperty( ImageView::Property::RESOURCE_URL, "TestString" );
798 DALI_TEST_EQUALS( imageView.GetProperty( ImageView::Property::RESOURCE_URL ).Get< std::string >(), "TestString", TEST_LOCATION );
803 // Scenarios 1: ImageView from regular image
804 int UtcDaliImageViewSetImageBufferImage(void)
806 ToolkitTestApplication application;
808 ImageView imageView = ImageView::New();
809 Stage::GetCurrent().Add( imageView );
811 TestGlAbstraction& gl = application.GetGlAbstraction();
812 gl.EnableTextureCallTrace( true );
814 std::vector< GLuint > ids;
816 application.GetGlAbstraction().SetNextTextureIds( ids );
820 BufferImage image = CreateBufferImage( width, height, Color::WHITE );
822 imageView.SetImage( image );
824 application.SendNotification();
825 application.Render();
827 DALI_TEST_CHECK( gl.GetTextureTrace().FindMethod("BindTexture") );
829 std::stringstream params;
830 params << GL_TEXTURE_2D << ", " << 23;
831 DALI_TEST_CHECK( gl.GetTextureTrace().FindMethodAndParams("BindTexture", params.str()) );
836 // Scenarios 2: ImageView from Native image
837 int UtcDaliImageViewSetImageNativeImage(void)
839 ToolkitTestApplication application;
841 ImageView imageView = ImageView::New();
842 Stage::GetCurrent().Add( imageView );
844 TestGlAbstraction& gl = application.GetGlAbstraction();
845 gl.EnableTextureCallTrace( true );
847 std::vector< GLuint > ids;
849 application.GetGlAbstraction().SetNextTextureIds( ids );
853 TestNativeImagePointer nativeImageInterface = TestNativeImage::New( width, height );
854 NativeImage nativeImage = NativeImage::New( *(nativeImageInterface.Get()) );
856 imageView.SetImage( nativeImage );
857 application.SendNotification();
858 application.Render();
860 DALI_TEST_CHECK( gl.GetTextureTrace().FindMethod("BindTexture") );
862 std::stringstream params;
863 params << GL_TEXTURE_2D << ", " << 23;
864 DALI_TEST_CHECK( gl.GetTextureTrace().FindMethodAndParams("BindTexture", params.str()) );
869 // Scenarios 3: ImageView initially from regular image but then SetImage called with Native image
870 int UtcDaliImageViewSetImageBufferImageToNativeImage(void)
872 ToolkitTestApplication application;
876 BufferImage image = CreateBufferImage( width, height, Color::WHITE );
878 ImageView imageView = ImageView::New( image );
879 Stage::GetCurrent().Add( imageView );
881 TestGlAbstraction& gl = application.GetGlAbstraction();
882 gl.EnableTextureCallTrace( true );
884 std::vector< GLuint > ids;
886 application.GetGlAbstraction().SetNextTextureIds( ids );
888 application.SendNotification();
889 application.Render();
891 DALI_TEST_CHECK( gl.GetTextureTrace().FindMethod("BindTexture") );
893 std::stringstream params;
894 params << GL_TEXTURE_2D << ", " << 23;
895 DALI_TEST_CHECK( gl.GetTextureTrace().FindMethodAndParams("BindTexture", params.str()) );
899 TestNativeImagePointer nativeImageInterface = TestNativeImage::New( width, height );
900 NativeImage nativeImage = NativeImage::New( *(nativeImageInterface.Get()) );
901 imageView.SetImage( nativeImage );
905 application.GetGlAbstraction().SetNextTextureIds( ids );
907 application.SendNotification();
908 application.Render();
910 DALI_TEST_CHECK( gl.GetTextureTrace().FindMethod("BindTexture") );
912 std::stringstream nextTextureParams;
913 nextTextureParams << GL_TEXTURE_2D << ", " << 24;
914 DALI_TEST_CHECK( gl.GetTextureTrace().FindMethodAndParams("BindTexture", nextTextureParams.str()) );
919 // Scenarios 4: ImageView initially from Native image but then SetImage called with regular image
920 int UtcDaliImageViewSetImageNativeImageToBufferImage(void)
922 ToolkitTestApplication application;
926 TestNativeImagePointer nativeImageInterface = TestNativeImage::New( width, height );
927 NativeImage nativeImage = NativeImage::New( *(nativeImageInterface.Get()) );
929 ImageView imageView = ImageView::New( nativeImage );
930 Stage::GetCurrent().Add( imageView );
932 TestGlAbstraction& gl = application.GetGlAbstraction();
933 gl.EnableTextureCallTrace( true );
935 std::vector< GLuint > ids;
937 application.GetGlAbstraction().SetNextTextureIds( ids );
939 application.SendNotification();
940 application.Render();
942 DALI_TEST_CHECK( gl.GetTextureTrace().FindMethod("BindTexture") );
944 std::stringstream params;
945 params << GL_TEXTURE_2D << ", " << 23;
946 DALI_TEST_CHECK( gl.GetTextureTrace().FindMethodAndParams("BindTexture", params.str()) );
950 BufferImage image = CreateBufferImage( width, height, Color::WHITE );
951 imageView.SetImage( image );
955 application.GetGlAbstraction().SetNextTextureIds( ids );
957 application.SendNotification();
958 application.Render();
960 DALI_TEST_CHECK( gl.GetTextureTrace().FindMethod("BindTexture") );
962 std::stringstream nextTextureParams;
963 nextTextureParams << GL_TEXTURE_2D << ", " << 24;
964 DALI_TEST_CHECK( gl.GetTextureTrace().FindMethodAndParams("BindTexture", nextTextureParams.str()) );
969 // Scenarios 5: ImageView from Native image with custom shader
970 int UtcDaliImageViewSetImageNativeImageWithCustomShader(void)
972 ToolkitTestApplication application;
977 Property::Map customShader;
978 customShader.Insert( "vertexShader", VERTEX_SHADER );
979 customShader.Insert( "fragmentShader", FRAGMENT_SHADER );
981 Property::Array shaderHints;
982 shaderHints.PushBack( "requiresSelfDepthTest" );
983 shaderHints.PushBack( "outputIsTransparent" );
984 shaderHints.PushBack( "outputIsOpaque" );
985 shaderHints.PushBack( "modifiesGeometry" );
987 customShader.Insert( "hints", shaderHints );
990 map.Insert( "rendererType", "image" );
991 map.Insert( "shader", customShader );
993 TestNativeImagePointer nativeImageInterface = TestNativeImage::New( width, height );
994 NativeImage nativeImage = NativeImage::New( *(nativeImageInterface.Get()) );
996 ImageView imageView = ImageView::New( nativeImage );
997 imageView.SetProperty( ImageView::Property::IMAGE, map );
998 Stage::GetCurrent().Add( imageView );
1000 imageView.SetProperty( ImageView::Property::IMAGE, map );
1002 TestGlAbstraction& gl = application.GetGlAbstraction();
1003 gl.EnableTextureCallTrace( true );
1005 std::vector< GLuint > ids;
1006 ids.push_back( 23 );
1007 application.GetGlAbstraction().SetNextTextureIds( ids );
1009 application.SendNotification();
1010 application.Render();
1012 DALI_TEST_CHECK( gl.GetTextureTrace().FindMethod("BindTexture") );
1014 std::stringstream params;
1015 params << GL_TEXTURE_2D << ", " << 23;
1016 DALI_TEST_CHECK( gl.GetTextureTrace().FindMethodAndParams("BindTexture", params.str()) );
1021 // Scenarios 6: ImageView initially from regular image with custom shader but then SetImage called with Native
1022 int UtcDaliImageViewSetImageBufferImageWithCustomShaderToNativeImage(void)
1024 ToolkitTestApplication application;
1029 Property::Map customShader;
1030 customShader.Insert( "vertexShader", VERTEX_SHADER );
1031 customShader.Insert( "fragmentShader", FRAGMENT_SHADER );
1033 Property::Array shaderHints;
1034 shaderHints.PushBack( "requiresSelfDepthTest" );
1035 shaderHints.PushBack( "outputIsTransparent" );
1036 shaderHints.PushBack( "outputIsOpaque" );
1037 shaderHints.PushBack( "modifiesGeometry" );
1039 customShader.Insert( "hints", shaderHints );
1042 map.Insert( "rendererType", "image" );
1043 map.Insert( "shader", customShader );
1045 BufferImage image = CreateBufferImage( width, height, Color::WHITE );
1047 ImageView imageView = ImageView::New( image );
1048 imageView.SetProperty( ImageView::Property::IMAGE, map );
1049 Stage::GetCurrent().Add( imageView );
1051 imageView.SetProperty( ImageView::Property::IMAGE, map );
1053 TestGlAbstraction& gl = application.GetGlAbstraction();
1054 gl.EnableTextureCallTrace( true );
1056 std::vector< GLuint > ids;
1057 ids.push_back( 23 );
1058 application.GetGlAbstraction().SetNextTextureIds( ids );
1060 application.SendNotification();
1061 application.Render();
1063 DALI_TEST_CHECK( gl.GetTextureTrace().FindMethod("BindTexture") );
1065 std::stringstream params;
1066 params << GL_TEXTURE_2D << ", " << 23;
1067 DALI_TEST_CHECK( gl.GetTextureTrace().FindMethodAndParams("BindTexture", params.str()) );
1069 TestNativeImagePointer nativeImageInterface = TestNativeImage::New( width, height );
1070 NativeImage nativeImage = NativeImage::New( *(nativeImageInterface.Get()) );
1071 imageView.SetImage( nativeImage );
1074 ids.push_back( 24 );
1075 application.GetGlAbstraction().SetNextTextureIds( ids );
1077 application.SendNotification();
1078 application.Render();
1080 DALI_TEST_CHECK( gl.GetTextureTrace().FindMethod("BindTexture") );
1082 std::stringstream nativeImageParams;
1083 nativeImageParams << GL_TEXTURE_2D << ", " << 24;
1084 DALI_TEST_CHECK( gl.GetTextureTrace().FindMethodAndParams("BindTexture", nativeImageParams.str()) );
1090 int UtcDaliImageViewGetImageP1(void)
1092 ToolkitTestApplication application;
1094 ImageView imageView = ImageView::New();
1095 DALI_TEST_CHECK( ! imageView.GetImage() );
1097 Image image = CreateBufferImage();
1098 imageView.SetImage( image );
1099 DALI_TEST_CHECK( imageView.GetImage() == image );
1104 int UtcDaliImageViewGetImageP2(void)
1106 ToolkitTestApplication application;
1108 BufferImage image = CreateBufferImage();
1109 ImageView imageView = ImageView::New( image );
1110 DALI_TEST_CHECK( imageView.GetImage() == image );
1115 int UtcDaliImageViewGetImageN(void)
1117 ToolkitTestApplication application;
1119 ImageView imageView = ImageView::New( TEST_IMAGE_FILE_NAME );
1120 DALI_TEST_CHECK( ! imageView.GetImage() );
1122 Image image = CreateBufferImage();
1123 imageView.SetImage( image );
1124 DALI_TEST_CHECK( imageView.GetImage() == image );
1126 imageView.SetImage( TEST_IMAGE_FILE_NAME );
1127 DALI_TEST_CHECK( ! imageView.GetImage() );