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 TraceCallStack::NamedParams params;
429 params["width"] = ToString(34);
430 params["height"] = ToString(34);
431 DALI_TEST_EQUALS( callStack.FindMethodAndParams( "TexSubImage2D", params ), true, TEST_LOCATION );
436 int UtcDaliImageViewSyncLoading(void)
438 ToolkitTestApplication application;
440 Property::Map syncLoadingMap;
441 syncLoadingMap[ "synchronousLoading" ] = true;
443 // Sync loading, no atlasing for big size image
445 ImageView imageView = ImageView::New();
447 // Sync loading is used
448 syncLoadingMap[ "url" ] = gImage_600_RGB;
449 imageView.SetProperty( ImageView::Property::IMAGE, syncLoadingMap );
451 // BitmapLoader is used, and the loading is started immediately even the actor is not on stage.
452 BitmapLoader loader = BitmapLoader::GetLatestCreated();
453 DALI_TEST_CHECK( loader );
456 // Sync loading, automatic atlasing for small size image
458 BitmapLoader::ResetLatestCreated();
459 TraceCallStack& callStack = application.GetGlAbstraction().GetTextureTrace();
461 callStack.Enable(true);
463 ImageView imageView = ImageView::New( );
464 // Sync loading is used
465 syncLoadingMap[ "url" ] = gImage_34_RGBA;
466 syncLoadingMap[ "desiredHeight" ] = 34;
467 syncLoadingMap[ "desiredWidth" ] = 34;
468 imageView.SetProperty( ImageView::Property::IMAGE, syncLoadingMap );
470 // loading is started even if the actor is offStage
471 BitmapLoader loader = BitmapLoader::GetLatestCreated();
472 DALI_TEST_CHECK( loader );
474 loader.WaitForLoading();
476 DALI_TEST_CHECK( loader.IsLoaded() );
478 Stage::GetCurrent().Add( imageView );
479 application.SendNotification();
480 application.Render(16);
482 TraceCallStack::NamedParams params;
483 params["width"] = ToString(34);
484 params["height"] = ToString(34);
485 DALI_TEST_EQUALS( callStack.FindMethodAndParams( "TexSubImage2D", params ),
486 true, TEST_LOCATION );
491 int UtcDaliImageViewSizeWithBackground(void)
493 ToolkitTestApplication application;
497 Image image = CreateBufferImage( width, height, Vector4(1.f, 1.f, 1.f, 1.f) );
498 ImageView imageView = ImageView::New();
499 imageView.SetBackgroundImage( image );
501 Stage::GetCurrent().Add( imageView );
502 application.SendNotification();
503 application.Render();
505 DALI_TEST_EQUALS( imageView.GetCurrentSize().width, (float)width, TEST_LOCATION );
506 DALI_TEST_EQUALS( imageView.GetCurrentSize().height, (float)height, TEST_LOCATION );
511 int UtcDaliImageViewSizeWithBackgroundAndImage(void)
513 ToolkitTestApplication application;
515 int widthBackground = 100;
516 int heightBackground = 200;
519 Image imageBackground = CreateBufferImage( widthBackground, heightBackground, Vector4(1.f, 1.f, 1.f, 1.f) );
520 Image image = CreateBufferImage( width, height, Vector4(1.f, 1.f, 1.f, 1.f) );
522 ImageView imageView = ImageView::New();
523 imageView.SetBackgroundImage( imageBackground );
524 imageView.SetImage( image );
526 Stage::GetCurrent().Add( imageView );
527 application.SendNotification();
528 application.Render();
530 DALI_TEST_EQUALS( imageView.GetCurrentSize().width, (float)width, TEST_LOCATION );
531 DALI_TEST_EQUALS( imageView.GetCurrentSize().height, (float)height, TEST_LOCATION );
536 int UtcDaliImageViewHeightForWidthBackground(void)
538 ToolkitTestApplication application;
540 int widthBackground = 100;
541 int heightBackground = 200;
542 Image imageBackground = CreateBufferImage( widthBackground, heightBackground, Vector4(1.f, 1.f, 1.f, 1.f) );
544 ImageView imageView = ImageView::New();
545 imageView.SetBackgroundImage( imageBackground );
547 Stage::GetCurrent().Add( imageView );
548 application.SendNotification();
549 application.Render();
551 Control control = Control::DownCast( imageView );
552 DALI_TEST_CHECK( control );
553 DALI_TEST_EQUALS( imageView.GetHeightForWidth( 123.f ), control.GetHeightForWidth( 123.f ), TEST_LOCATION );
554 DALI_TEST_EQUALS( imageView.GetWidthForHeight( 321.f ), control.GetWidthForHeight( 321.f ), TEST_LOCATION );
559 int UtcDaliImageViewHeightForWidthBackgroundAndImage(void)
561 ToolkitTestApplication application;
563 int widthBackground = 100;
564 int heightBackground = 200;
567 Image imageBackground = CreateBufferImage( widthBackground, heightBackground, Vector4(1.f, 1.f, 1.f, 1.f) );
568 Image image = CreateBufferImage( width, height, Vector4(1.f, 1.f, 1.f, 1.f) );
570 ImageView imageView = ImageView::New();
571 imageView.SetBackgroundImage( imageBackground );
572 imageView.SetImage( image );
574 Stage::GetCurrent().Add( imageView );
575 application.SendNotification();
576 application.Render();
578 DALI_TEST_EQUALS( imageView.GetHeightForWidth( width ), (float)height, TEST_LOCATION );
579 DALI_TEST_EQUALS( imageView.GetWidthForHeight( height ), (float)width, TEST_LOCATION );
584 int UtcDaliImageViewSetBufferImage(void)
586 ToolkitTestApplication application;
590 BufferImage image1 = CreateBufferImage( width1, height1, Vector4( 1.f, 1.f, 1.f, 1.f ) );
591 ImageView imageView = ImageView::New();
592 imageView.SetImage( image1 );
594 TestImage( imageView, image1 );
598 BufferImage image2 = CreateBufferImage( width2, height2, Vector4( 1.f, 1.f, 1.f, 1.f ) );
599 imageView.SetImage( image2 );
601 TestImage( imageView, image2 );
606 int UtcDaliImageViewSetImageUrl(void)
608 ToolkitTestApplication application;
610 ImageView imageView = ImageView::New();
611 imageView.SetImage( TEST_IMAGE_FILE_NAME );
612 TestUrl( imageView, TEST_IMAGE_FILE_NAME );
615 imageView.SetImage( TEST_IMAGE_FILE_NAME2 );
616 TestUrl( imageView, TEST_IMAGE_FILE_NAME2 );
621 int UtcDaliImageViewSetImageOnstageP(void)
623 ToolkitTestApplication application;
625 ImageView imageView = ImageView::New();
627 Stage::GetCurrent().Add( imageView );
628 application.SendNotification();
629 application.Render();
631 ResourceImage image1 = ResourceImage::New( TEST_IMAGE_FILE_NAME );
632 imageView.SetImage( image1 );
633 TestImage( imageView, image1 );
637 BufferImage image2 = CreateBufferImage( width, height, Vector4( 1.f, 1.f, 1.f, 1.f ) );
638 imageView.SetImage( image2 );
639 TestImage( imageView, image2 );
644 int UtcDaliImageViewSetImageOnstageN(void)
646 ToolkitTestApplication application;
648 ImageView imageView = ImageView::New();
650 Stage::GetCurrent().Add( imageView );
651 application.SendNotification();
652 application.Render();
654 ResourceImage image1 = ResourceImage::New( TEST_IMAGE_FILE_NAME );
655 imageView.SetImage( image1 );
656 TestImage( imageView, image1 );
659 imageView.SetImage( image2 );
661 Property::Value value = imageView.GetProperty( imageView.GetPropertyIndex( "image" ) );
663 //the value should be empty
665 DALI_TEST_CHECK( !value.Get( url ) );
668 DALI_TEST_CHECK( !value.Get( map ) );
673 int UtcDaliImageViewSetImageOffstageP(void)
675 ToolkitTestApplication application;
677 ImageView imageView = ImageView::New();
679 Stage::GetCurrent().Add( imageView );
680 application.SendNotification();
681 application.Render();
682 Stage::GetCurrent().Remove( imageView );
684 ResourceImage image1 = ResourceImage::New( TEST_IMAGE_FILE_NAME );
685 imageView.SetImage( image1 );
686 TestImage( imageView, image1 );
690 BufferImage image2 = CreateBufferImage( width, height, Vector4( 1.f, 1.f, 1.f, 1.f ) );
691 imageView.SetImage( image2 );
692 TestImage( imageView, image2 );
697 int UtcDaliImageViewSetImageOffstageN(void)
699 ToolkitTestApplication application;
701 ImageView imageView = ImageView::New();
703 Stage::GetCurrent().Add( imageView );
704 application.SendNotification();
705 application.Render();
706 Stage::GetCurrent().Remove( imageView );
708 ResourceImage image1 = ResourceImage::New( TEST_IMAGE_FILE_NAME );
709 imageView.SetImage( image1 );
710 TestImage( imageView, image1 );
713 imageView.SetImage( image2 );
715 Property::Value value = imageView.GetProperty( imageView.GetPropertyIndex( "image" ) );
717 //the value should be empty
719 DALI_TEST_CHECK( !value.Get( url ) );
722 DALI_TEST_CHECK( !value.Get( map ) );
727 int UtcDaliImageViewSetImageN(void)
729 ToolkitTestApplication application;
732 ImageView imageView = ImageView::New();
733 imageView.SetImage( image1 );
735 Property::Value value = imageView.GetProperty( imageView.GetPropertyIndex( "image" ) );
737 //the value should be empty
739 DALI_TEST_CHECK( !value.Get( url ) );
742 DALI_TEST_CHECK( !value.Get( map ) );
744 std::string resource_url;
745 Property::Value val = imageView.GetProperty( imageView.GetPropertyIndex( "image" ) );
746 DALI_TEST_CHECK( !val.Get( resource_url ) );
751 int UtcDaliImageViewSetImageTypeChangesP(void)
753 ToolkitTestApplication application;
755 ImageView imageView = ImageView::New();
761 Property::Value value = imageView.GetProperty( imageView.GetPropertyIndex( "image" ) );
762 DALI_TEST_CHECK( ! value.Get( url ) ); // Value should be empty
763 DALI_TEST_CHECK( ! value.Get( map ) ); // Value should be empty
766 imageView.SetImage( "TEST_URL" );
767 value = imageView.GetProperty( imageView.GetPropertyIndex( "image" ) );
769 DALI_TEST_CHECK( value.Get( url ) ); // Value should NOT be empty
770 DALI_TEST_CHECK( ! value.Get( map ) ); // Value should be empty
772 // Set an empty Image
773 imageView.SetImage( Image() );
774 value = imageView.GetProperty( imageView.GetPropertyIndex( "image" ) );
776 DALI_TEST_CHECK( ! value.Get( url ) ); // Value should be empty
777 DALI_TEST_CHECK( ! value.Get( map ) ); // Value should be empty
780 ResourceImage image1 = ResourceImage::New( TEST_IMAGE_FILE_NAME );
781 imageView.SetImage( image1 );
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 NOT be empty
788 imageView.SetImage( "" );
789 value = imageView.GetProperty( imageView.GetPropertyIndex( "image" ) );
791 DALI_TEST_CHECK( ! value.Get( url ) ); // Value should be empty
792 DALI_TEST_CHECK( ! value.Get( map ) ); // Value should be empty
797 int UtcDaliImageViewResourceUrlP(void)
799 ToolkitTestApplication application;
801 ImageView imageView = ImageView::New();
802 DALI_TEST_CHECK( imageView.GetProperty( ImageView::Property::RESOURCE_URL ).Get< std::string >().empty() );
804 imageView.SetProperty( ImageView::Property::RESOURCE_URL, "TestString" );
805 DALI_TEST_EQUALS( imageView.GetProperty( ImageView::Property::RESOURCE_URL ).Get< std::string >(), "TestString", TEST_LOCATION );
810 // Scenarios 1: ImageView from regular image
811 int UtcDaliImageViewSetImageBufferImage(void)
813 ToolkitTestApplication application;
815 ImageView imageView = ImageView::New();
816 Stage::GetCurrent().Add( imageView );
818 TestGlAbstraction& gl = application.GetGlAbstraction();
819 gl.EnableTextureCallTrace( true );
821 std::vector< GLuint > ids;
823 application.GetGlAbstraction().SetNextTextureIds( ids );
827 BufferImage image = CreateBufferImage( width, height, Color::WHITE );
829 imageView.SetImage( image );
831 application.SendNotification();
832 application.Render();
834 DALI_TEST_CHECK( gl.GetTextureTrace().FindMethod("BindTexture") );
836 std::stringstream params;
837 params << GL_TEXTURE_2D << ", " << 23;
838 DALI_TEST_CHECK( gl.GetTextureTrace().FindMethodAndParams("BindTexture", params.str()) );
843 // Scenarios 2: ImageView from Native image
844 int UtcDaliImageViewSetImageNativeImage(void)
846 ToolkitTestApplication application;
848 ImageView imageView = ImageView::New();
849 Stage::GetCurrent().Add( imageView );
851 TestGlAbstraction& gl = application.GetGlAbstraction();
852 gl.EnableTextureCallTrace( true );
854 std::vector< GLuint > ids;
856 application.GetGlAbstraction().SetNextTextureIds( ids );
860 TestNativeImagePointer nativeImageInterface = TestNativeImage::New( width, height );
861 NativeImage nativeImage = NativeImage::New( *(nativeImageInterface.Get()) );
863 imageView.SetImage( nativeImage );
864 application.SendNotification();
865 application.Render();
867 DALI_TEST_CHECK( gl.GetTextureTrace().FindMethod("BindTexture") );
869 std::stringstream params;
870 params << GL_TEXTURE_2D << ", " << 23;
871 DALI_TEST_CHECK( gl.GetTextureTrace().FindMethodAndParams("BindTexture", params.str()) );
876 // Scenarios 3: ImageView initially from regular image but then SetImage called with Native image
877 int UtcDaliImageViewSetImageBufferImageToNativeImage(void)
879 ToolkitTestApplication application;
883 BufferImage image = CreateBufferImage( width, height, Color::WHITE );
885 ImageView imageView = ImageView::New( image );
886 Stage::GetCurrent().Add( imageView );
888 TestGlAbstraction& gl = application.GetGlAbstraction();
889 gl.EnableTextureCallTrace( true );
891 std::vector< GLuint > ids;
893 application.GetGlAbstraction().SetNextTextureIds( ids );
895 application.SendNotification();
896 application.Render();
898 DALI_TEST_CHECK( gl.GetTextureTrace().FindMethod("BindTexture") );
900 std::stringstream params;
901 params << GL_TEXTURE_2D << ", " << 23;
902 DALI_TEST_CHECK( gl.GetTextureTrace().FindMethodAndParams("BindTexture", params.str()) );
906 TestNativeImagePointer nativeImageInterface = TestNativeImage::New( width, height );
907 NativeImage nativeImage = NativeImage::New( *(nativeImageInterface.Get()) );
908 imageView.SetImage( nativeImage );
912 application.GetGlAbstraction().SetNextTextureIds( ids );
914 application.SendNotification();
915 application.Render();
917 DALI_TEST_CHECK( gl.GetTextureTrace().FindMethod("BindTexture") );
919 std::stringstream nextTextureParams;
920 nextTextureParams << GL_TEXTURE_2D << ", " << 24;
921 DALI_TEST_CHECK( gl.GetTextureTrace().FindMethodAndParams("BindTexture", nextTextureParams.str()) );
926 // Scenarios 4: ImageView initially from Native image but then SetImage called with regular image
927 int UtcDaliImageViewSetImageNativeImageToBufferImage(void)
929 ToolkitTestApplication application;
933 TestNativeImagePointer nativeImageInterface = TestNativeImage::New( width, height );
934 NativeImage nativeImage = NativeImage::New( *(nativeImageInterface.Get()) );
936 ImageView imageView = ImageView::New( nativeImage );
937 Stage::GetCurrent().Add( imageView );
939 TestGlAbstraction& gl = application.GetGlAbstraction();
940 gl.EnableTextureCallTrace( true );
942 std::vector< GLuint > ids;
944 application.GetGlAbstraction().SetNextTextureIds( ids );
946 application.SendNotification();
947 application.Render();
949 DALI_TEST_CHECK( gl.GetTextureTrace().FindMethod("BindTexture") );
951 std::stringstream params;
952 params << GL_TEXTURE_2D << ", " << 23;
953 DALI_TEST_CHECK( gl.GetTextureTrace().FindMethodAndParams("BindTexture", params.str()) );
957 BufferImage image = CreateBufferImage( width, height, Color::WHITE );
958 imageView.SetImage( image );
962 application.GetGlAbstraction().SetNextTextureIds( ids );
964 application.SendNotification();
965 application.Render();
967 DALI_TEST_CHECK( gl.GetTextureTrace().FindMethod("BindTexture") );
969 std::stringstream nextTextureParams;
970 nextTextureParams << GL_TEXTURE_2D << ", " << 24;
971 DALI_TEST_CHECK( gl.GetTextureTrace().FindMethodAndParams("BindTexture", nextTextureParams.str()) );
976 // Scenarios 5: ImageView from Native image with custom shader
977 int UtcDaliImageViewSetImageNativeImageWithCustomShader(void)
979 ToolkitTestApplication application;
984 Property::Map customShader;
985 customShader.Insert( "vertexShader", VERTEX_SHADER );
986 customShader.Insert( "fragmentShader", FRAGMENT_SHADER );
988 Property::Array shaderHints;
989 shaderHints.PushBack( "requiresSelfDepthTest" );
990 shaderHints.PushBack( "outputIsTransparent" );
991 shaderHints.PushBack( "outputIsOpaque" );
992 shaderHints.PushBack( "modifiesGeometry" );
994 customShader.Insert( "hints", shaderHints );
997 map.Insert( "shader", customShader );
999 TestNativeImagePointer nativeImageInterface = TestNativeImage::New( width, height );
1000 NativeImage nativeImage = NativeImage::New( *(nativeImageInterface.Get()) );
1002 ImageView imageView = ImageView::New( nativeImage );
1003 imageView.SetProperty( ImageView::Property::IMAGE, map );
1004 Stage::GetCurrent().Add( imageView );
1006 TestGlAbstraction& gl = application.GetGlAbstraction();
1007 gl.EnableTextureCallTrace( true );
1009 std::vector< GLuint > ids;
1010 ids.push_back( 23 );
1011 application.GetGlAbstraction().SetNextTextureIds( ids );
1013 application.SendNotification();
1014 application.Render();
1016 DALI_TEST_CHECK( gl.GetTextureTrace().FindMethod("BindTexture") );
1018 std::stringstream params;
1019 params << GL_TEXTURE_2D << ", " << 23;
1020 DALI_TEST_CHECK( gl.GetTextureTrace().FindMethodAndParams("BindTexture", params.str()) );
1025 // Scenarios 6: ImageView initially from regular image with custom shader but then SetImage called with Native
1026 int UtcDaliImageViewSetImageBufferImageWithCustomShaderToNativeImage(void)
1028 ToolkitTestApplication application;
1033 Property::Map customShader;
1034 customShader.Insert( "vertexShader", VERTEX_SHADER );
1035 customShader.Insert( "fragmentShader", FRAGMENT_SHADER );
1037 Property::Array shaderHints;
1038 shaderHints.PushBack( "requiresSelfDepthTest" );
1039 shaderHints.PushBack( "outputIsTransparent" );
1040 shaderHints.PushBack( "outputIsOpaque" );
1041 shaderHints.PushBack( "modifiesGeometry" );
1043 customShader.Insert( "hints", shaderHints );
1046 map.Insert( "shader", customShader );
1048 BufferImage image = CreateBufferImage( width, height, Color::WHITE );
1050 ImageView imageView = ImageView::New( image );
1051 imageView.SetProperty( ImageView::Property::IMAGE, map );
1052 Stage::GetCurrent().Add( imageView );
1054 TestGlAbstraction& gl = application.GetGlAbstraction();
1055 gl.EnableTextureCallTrace( true );
1057 std::vector< GLuint > ids;
1058 ids.push_back( 23 );
1059 application.GetGlAbstraction().SetNextTextureIds( ids );
1061 application.SendNotification();
1062 application.Render();
1064 DALI_TEST_CHECK( gl.GetTextureTrace().FindMethod("BindTexture") );
1066 std::stringstream params;
1067 params << GL_TEXTURE_2D << ", " << 23;
1068 DALI_TEST_CHECK( gl.GetTextureTrace().FindMethodAndParams("BindTexture", params.str()) );
1070 TestNativeImagePointer nativeImageInterface = TestNativeImage::New( width, height );
1071 NativeImage nativeImage = NativeImage::New( *(nativeImageInterface.Get()) );
1072 imageView.SetImage( nativeImage );
1075 ids.push_back( 24 );
1076 application.GetGlAbstraction().SetNextTextureIds( ids );
1078 application.SendNotification();
1079 application.Render();
1081 DALI_TEST_CHECK( gl.GetTextureTrace().FindMethod("BindTexture") );
1083 std::stringstream nativeImageParams;
1084 nativeImageParams << GL_TEXTURE_2D << ", " << 24;
1085 DALI_TEST_CHECK( gl.GetTextureTrace().FindMethodAndParams("BindTexture", nativeImageParams.str()) );
1091 int UtcDaliImageViewGetImageP1(void)
1093 ToolkitTestApplication application;
1095 ImageView imageView = ImageView::New();
1096 DALI_TEST_CHECK( ! imageView.GetImage() );
1098 Image image = CreateBufferImage();
1099 imageView.SetImage( image );
1100 DALI_TEST_CHECK( imageView.GetImage() == image );
1105 int UtcDaliImageViewGetImageP2(void)
1107 ToolkitTestApplication application;
1109 BufferImage image = CreateBufferImage();
1110 ImageView imageView = ImageView::New( image );
1111 DALI_TEST_CHECK( imageView.GetImage() == image );
1116 int UtcDaliImageViewGetImageN(void)
1118 ToolkitTestApplication application;
1120 ImageView imageView = ImageView::New( TEST_IMAGE_FILE_NAME );
1121 DALI_TEST_CHECK( ! imageView.GetImage() );
1123 Image image = CreateBufferImage();
1124 imageView.SetImage( image );
1125 DALI_TEST_CHECK( imageView.GetImage() == image );
1127 imageView.SetImage( TEST_IMAGE_FILE_NAME );
1128 DALI_TEST_CHECK( ! imageView.GetImage() );