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( gImage_600_RGB );
447 // Sync loading is used
448 imageView.SetProperty( ImageView::Property::IMAGE, syncLoadingMap );
450 // BitmapLoader is used, and the loading is started immediately even the actor is not on stage.
451 BitmapLoader loader = BitmapLoader::GetLatestCreated();
452 DALI_TEST_CHECK( loader );
455 // Sync loading, automatic atlasing for small size image
457 BitmapLoader::ResetLatestCreated();
458 TraceCallStack& callStack = application.GetGlAbstraction().GetTextureTrace();
460 callStack.Enable(true);
462 ImageView imageView = ImageView::New( );
463 // Sync loading is used
464 syncLoadingMap[ "url" ] = gImage_34_RGBA;
465 syncLoadingMap[ "desiredHeight" ] = 34;
466 syncLoadingMap[ "desiredWidth" ] = 34;
467 imageView.SetProperty( ImageView::Property::IMAGE, syncLoadingMap );
469 // loading is started even if the actor is offStage
470 BitmapLoader loader = BitmapLoader::GetLatestCreated();
471 DALI_TEST_CHECK( loader );
473 loader.WaitForLoading();
475 DALI_TEST_CHECK( loader.IsLoaded() );
477 Stage::GetCurrent().Add( imageView );
478 application.SendNotification();
479 application.Render(16);
481 TraceCallStack::NamedParams params;
482 params["width"] = ToString(34);
483 params["height"] = ToString(34);
484 DALI_TEST_EQUALS( callStack.FindMethodAndParams( "TexSubImage2D", params ),
485 true, TEST_LOCATION );
490 int UtcDaliImageViewSizeWithBackground(void)
492 ToolkitTestApplication application;
496 Image image = CreateBufferImage( width, height, Vector4(1.f, 1.f, 1.f, 1.f) );
497 ImageView imageView = ImageView::New();
498 imageView.SetBackgroundImage( image );
500 Stage::GetCurrent().Add( imageView );
501 application.SendNotification();
502 application.Render();
504 DALI_TEST_EQUALS( imageView.GetCurrentSize().width, (float)width, TEST_LOCATION );
505 DALI_TEST_EQUALS( imageView.GetCurrentSize().height, (float)height, TEST_LOCATION );
510 int UtcDaliImageViewSizeWithBackgroundAndImage(void)
512 ToolkitTestApplication application;
514 int widthBackground = 100;
515 int heightBackground = 200;
518 Image imageBackground = CreateBufferImage( widthBackground, heightBackground, Vector4(1.f, 1.f, 1.f, 1.f) );
519 Image image = CreateBufferImage( width, height, Vector4(1.f, 1.f, 1.f, 1.f) );
521 ImageView imageView = ImageView::New();
522 imageView.SetBackgroundImage( imageBackground );
523 imageView.SetImage( image );
525 Stage::GetCurrent().Add( imageView );
526 application.SendNotification();
527 application.Render();
529 DALI_TEST_EQUALS( imageView.GetCurrentSize().width, (float)width, TEST_LOCATION );
530 DALI_TEST_EQUALS( imageView.GetCurrentSize().height, (float)height, TEST_LOCATION );
535 int UtcDaliImageViewHeightForWidthBackground(void)
537 ToolkitTestApplication application;
539 int widthBackground = 100;
540 int heightBackground = 200;
541 Image imageBackground = CreateBufferImage( widthBackground, heightBackground, Vector4(1.f, 1.f, 1.f, 1.f) );
543 ImageView imageView = ImageView::New();
544 imageView.SetBackgroundImage( imageBackground );
546 Stage::GetCurrent().Add( imageView );
547 application.SendNotification();
548 application.Render();
550 Control control = Control::DownCast( imageView );
551 DALI_TEST_CHECK( control );
552 DALI_TEST_EQUALS( imageView.GetHeightForWidth( 123.f ), control.GetHeightForWidth( 123.f ), TEST_LOCATION );
553 DALI_TEST_EQUALS( imageView.GetWidthForHeight( 321.f ), control.GetWidthForHeight( 321.f ), TEST_LOCATION );
558 int UtcDaliImageViewHeightForWidthBackgroundAndImage(void)
560 ToolkitTestApplication application;
562 int widthBackground = 100;
563 int heightBackground = 200;
566 Image imageBackground = CreateBufferImage( widthBackground, heightBackground, Vector4(1.f, 1.f, 1.f, 1.f) );
567 Image image = CreateBufferImage( width, height, Vector4(1.f, 1.f, 1.f, 1.f) );
569 ImageView imageView = ImageView::New();
570 imageView.SetBackgroundImage( imageBackground );
571 imageView.SetImage( image );
573 Stage::GetCurrent().Add( imageView );
574 application.SendNotification();
575 application.Render();
577 DALI_TEST_EQUALS( imageView.GetHeightForWidth( width ), (float)height, TEST_LOCATION );
578 DALI_TEST_EQUALS( imageView.GetWidthForHeight( height ), (float)width, TEST_LOCATION );
583 int UtcDaliImageViewSetBufferImage(void)
585 ToolkitTestApplication application;
589 BufferImage image1 = CreateBufferImage( width1, height1, Vector4( 1.f, 1.f, 1.f, 1.f ) );
590 ImageView imageView = ImageView::New();
591 imageView.SetImage( image1 );
593 TestImage( imageView, image1 );
597 BufferImage image2 = CreateBufferImage( width2, height2, Vector4( 1.f, 1.f, 1.f, 1.f ) );
598 imageView.SetImage( image2 );
600 TestImage( imageView, image2 );
605 int UtcDaliImageViewSetImageUrl(void)
607 ToolkitTestApplication application;
609 ImageView imageView = ImageView::New();
610 imageView.SetImage( TEST_IMAGE_FILE_NAME );
611 TestUrl( imageView, TEST_IMAGE_FILE_NAME );
614 imageView.SetImage( TEST_IMAGE_FILE_NAME2 );
615 TestUrl( imageView, TEST_IMAGE_FILE_NAME2 );
620 int UtcDaliImageViewSetImageOnstageP(void)
622 ToolkitTestApplication application;
624 ImageView imageView = ImageView::New();
626 Stage::GetCurrent().Add( imageView );
627 application.SendNotification();
628 application.Render();
630 ResourceImage image1 = ResourceImage::New( TEST_IMAGE_FILE_NAME );
631 imageView.SetImage( image1 );
632 TestImage( imageView, image1 );
636 BufferImage image2 = CreateBufferImage( width, height, Vector4( 1.f, 1.f, 1.f, 1.f ) );
637 imageView.SetImage( image2 );
638 TestImage( imageView, image2 );
643 int UtcDaliImageViewSetImageOnstageN(void)
645 ToolkitTestApplication application;
647 ImageView imageView = ImageView::New();
649 Stage::GetCurrent().Add( imageView );
650 application.SendNotification();
651 application.Render();
653 ResourceImage image1 = ResourceImage::New( TEST_IMAGE_FILE_NAME );
654 imageView.SetImage( image1 );
655 TestImage( imageView, image1 );
658 imageView.SetImage( image2 );
660 Property::Value value = imageView.GetProperty( imageView.GetPropertyIndex( "image" ) );
662 //the value should be empty
664 DALI_TEST_CHECK( !value.Get( url ) );
667 DALI_TEST_CHECK( !value.Get( map ) );
672 int UtcDaliImageViewSetImageOffstageP(void)
674 ToolkitTestApplication application;
676 ImageView imageView = ImageView::New();
678 Stage::GetCurrent().Add( imageView );
679 application.SendNotification();
680 application.Render();
681 Stage::GetCurrent().Remove( imageView );
683 ResourceImage image1 = ResourceImage::New( TEST_IMAGE_FILE_NAME );
684 imageView.SetImage( image1 );
685 TestImage( imageView, image1 );
689 BufferImage image2 = CreateBufferImage( width, height, Vector4( 1.f, 1.f, 1.f, 1.f ) );
690 imageView.SetImage( image2 );
691 TestImage( imageView, image2 );
696 int UtcDaliImageViewSetImageOffstageN(void)
698 ToolkitTestApplication application;
700 ImageView imageView = ImageView::New();
702 Stage::GetCurrent().Add( imageView );
703 application.SendNotification();
704 application.Render();
705 Stage::GetCurrent().Remove( imageView );
707 ResourceImage image1 = ResourceImage::New( TEST_IMAGE_FILE_NAME );
708 imageView.SetImage( image1 );
709 TestImage( imageView, image1 );
712 imageView.SetImage( image2 );
714 Property::Value value = imageView.GetProperty( imageView.GetPropertyIndex( "image" ) );
716 //the value should be empty
718 DALI_TEST_CHECK( !value.Get( url ) );
721 DALI_TEST_CHECK( !value.Get( map ) );
726 int UtcDaliImageViewSetImageN(void)
728 ToolkitTestApplication application;
731 ImageView imageView = ImageView::New();
732 imageView.SetImage( image1 );
734 Property::Value value = imageView.GetProperty( imageView.GetPropertyIndex( "image" ) );
736 //the value should be empty
738 DALI_TEST_CHECK( !value.Get( url ) );
741 DALI_TEST_CHECK( !value.Get( map ) );
743 std::string resource_url;
744 Property::Value val = imageView.GetProperty( imageView.GetPropertyIndex( "image" ) );
745 DALI_TEST_CHECK( !val.Get( resource_url ) );
750 int UtcDaliImageViewSetImageTypeChangesP(void)
752 ToolkitTestApplication application;
754 ImageView imageView = ImageView::New();
760 Property::Value value = imageView.GetProperty( imageView.GetPropertyIndex( "image" ) );
761 DALI_TEST_CHECK( ! value.Get( url ) ); // Value should be empty
762 DALI_TEST_CHECK( ! value.Get( map ) ); // Value should be empty
765 imageView.SetImage( "TEST_URL" );
766 value = imageView.GetProperty( imageView.GetPropertyIndex( "image" ) );
768 DALI_TEST_CHECK( value.Get( url ) ); // Value should NOT be empty
769 DALI_TEST_CHECK( ! value.Get( map ) ); // Value should be empty
771 // Set an empty Image
772 imageView.SetImage( Image() );
773 value = imageView.GetProperty( imageView.GetPropertyIndex( "image" ) );
775 DALI_TEST_CHECK( ! value.Get( url ) ); // Value should be empty
776 DALI_TEST_CHECK( ! value.Get( map ) ); // Value should be empty
779 ResourceImage image1 = ResourceImage::New( TEST_IMAGE_FILE_NAME );
780 imageView.SetImage( image1 );
781 value = imageView.GetProperty( imageView.GetPropertyIndex( "image" ) );
783 DALI_TEST_CHECK( ! value.Get( url ) ); // Value should be empty
784 DALI_TEST_CHECK( value.Get( map ) ); // Value should NOT be empty
787 imageView.SetImage( "" );
788 value = imageView.GetProperty( imageView.GetPropertyIndex( "image" ) );
790 DALI_TEST_CHECK( ! value.Get( url ) ); // Value should be empty
791 DALI_TEST_CHECK( ! value.Get( map ) ); // Value should be empty
796 int UtcDaliImageViewResourceUrlP(void)
798 ToolkitTestApplication application;
800 ImageView imageView = ImageView::New();
801 DALI_TEST_CHECK( imageView.GetProperty( ImageView::Property::RESOURCE_URL ).Get< std::string >().empty() );
803 imageView.SetProperty( ImageView::Property::RESOURCE_URL, "TestString" );
804 DALI_TEST_EQUALS( imageView.GetProperty( ImageView::Property::RESOURCE_URL ).Get< std::string >(), "TestString", TEST_LOCATION );
809 // Scenarios 1: ImageView from regular image
810 int UtcDaliImageViewSetImageBufferImage(void)
812 ToolkitTestApplication application;
814 ImageView imageView = ImageView::New();
815 Stage::GetCurrent().Add( imageView );
817 TestGlAbstraction& gl = application.GetGlAbstraction();
818 gl.EnableTextureCallTrace( true );
820 std::vector< GLuint > ids;
822 application.GetGlAbstraction().SetNextTextureIds( ids );
826 BufferImage image = CreateBufferImage( width, height, Color::WHITE );
828 imageView.SetImage( image );
830 application.SendNotification();
831 application.Render();
833 DALI_TEST_CHECK( gl.GetTextureTrace().FindMethod("BindTexture") );
835 std::stringstream params;
836 params << GL_TEXTURE_2D << ", " << 23;
837 DALI_TEST_CHECK( gl.GetTextureTrace().FindMethodAndParams("BindTexture", params.str()) );
842 // Scenarios 2: ImageView from Native image
843 int UtcDaliImageViewSetImageNativeImage(void)
845 ToolkitTestApplication application;
847 ImageView imageView = ImageView::New();
848 Stage::GetCurrent().Add( imageView );
850 TestGlAbstraction& gl = application.GetGlAbstraction();
851 gl.EnableTextureCallTrace( true );
853 std::vector< GLuint > ids;
855 application.GetGlAbstraction().SetNextTextureIds( ids );
859 TestNativeImagePointer nativeImageInterface = TestNativeImage::New( width, height );
860 NativeImage nativeImage = NativeImage::New( *(nativeImageInterface.Get()) );
862 imageView.SetImage( nativeImage );
863 application.SendNotification();
864 application.Render();
866 DALI_TEST_CHECK( gl.GetTextureTrace().FindMethod("BindTexture") );
868 std::stringstream params;
869 params << GL_TEXTURE_2D << ", " << 23;
870 DALI_TEST_CHECK( gl.GetTextureTrace().FindMethodAndParams("BindTexture", params.str()) );
875 // Scenarios 3: ImageView initially from regular image but then SetImage called with Native image
876 int UtcDaliImageViewSetImageBufferImageToNativeImage(void)
878 ToolkitTestApplication application;
882 BufferImage image = CreateBufferImage( width, height, Color::WHITE );
884 ImageView imageView = ImageView::New( image );
885 Stage::GetCurrent().Add( imageView );
887 TestGlAbstraction& gl = application.GetGlAbstraction();
888 gl.EnableTextureCallTrace( true );
890 std::vector< GLuint > ids;
892 application.GetGlAbstraction().SetNextTextureIds( ids );
894 application.SendNotification();
895 application.Render();
897 DALI_TEST_CHECK( gl.GetTextureTrace().FindMethod("BindTexture") );
899 std::stringstream params;
900 params << GL_TEXTURE_2D << ", " << 23;
901 DALI_TEST_CHECK( gl.GetTextureTrace().FindMethodAndParams("BindTexture", params.str()) );
905 TestNativeImagePointer nativeImageInterface = TestNativeImage::New( width, height );
906 NativeImage nativeImage = NativeImage::New( *(nativeImageInterface.Get()) );
907 imageView.SetImage( nativeImage );
911 application.GetGlAbstraction().SetNextTextureIds( ids );
913 application.SendNotification();
914 application.Render();
916 DALI_TEST_CHECK( gl.GetTextureTrace().FindMethod("BindTexture") );
918 std::stringstream nextTextureParams;
919 nextTextureParams << GL_TEXTURE_2D << ", " << 24;
920 DALI_TEST_CHECK( gl.GetTextureTrace().FindMethodAndParams("BindTexture", nextTextureParams.str()) );
925 // Scenarios 4: ImageView initially from Native image but then SetImage called with regular image
926 int UtcDaliImageViewSetImageNativeImageToBufferImage(void)
928 ToolkitTestApplication application;
932 TestNativeImagePointer nativeImageInterface = TestNativeImage::New( width, height );
933 NativeImage nativeImage = NativeImage::New( *(nativeImageInterface.Get()) );
935 ImageView imageView = ImageView::New( nativeImage );
936 Stage::GetCurrent().Add( imageView );
938 TestGlAbstraction& gl = application.GetGlAbstraction();
939 gl.EnableTextureCallTrace( true );
941 std::vector< GLuint > ids;
943 application.GetGlAbstraction().SetNextTextureIds( ids );
945 application.SendNotification();
946 application.Render();
948 DALI_TEST_CHECK( gl.GetTextureTrace().FindMethod("BindTexture") );
950 std::stringstream params;
951 params << GL_TEXTURE_2D << ", " << 23;
952 DALI_TEST_CHECK( gl.GetTextureTrace().FindMethodAndParams("BindTexture", params.str()) );
956 BufferImage image = CreateBufferImage( width, height, Color::WHITE );
957 imageView.SetImage( image );
961 application.GetGlAbstraction().SetNextTextureIds( ids );
963 application.SendNotification();
964 application.Render();
966 DALI_TEST_CHECK( gl.GetTextureTrace().FindMethod("BindTexture") );
968 std::stringstream nextTextureParams;
969 nextTextureParams << GL_TEXTURE_2D << ", " << 24;
970 DALI_TEST_CHECK( gl.GetTextureTrace().FindMethodAndParams("BindTexture", nextTextureParams.str()) );
975 // Scenarios 5: ImageView from Native image with custom shader
976 int UtcDaliImageViewSetImageNativeImageWithCustomShader(void)
978 ToolkitTestApplication application;
983 Property::Map customShader;
984 customShader.Insert( "vertexShader", VERTEX_SHADER );
985 customShader.Insert( "fragmentShader", FRAGMENT_SHADER );
987 Property::Array shaderHints;
988 shaderHints.PushBack( "requiresSelfDepthTest" );
989 shaderHints.PushBack( "outputIsTransparent" );
990 shaderHints.PushBack( "outputIsOpaque" );
991 shaderHints.PushBack( "modifiesGeometry" );
993 customShader.Insert( "hints", shaderHints );
996 map.Insert( "rendererType", "image" );
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 imageView.SetProperty( ImageView::Property::IMAGE, map );
1008 TestGlAbstraction& gl = application.GetGlAbstraction();
1009 gl.EnableTextureCallTrace( true );
1011 std::vector< GLuint > ids;
1012 ids.push_back( 23 );
1013 application.GetGlAbstraction().SetNextTextureIds( ids );
1015 application.SendNotification();
1016 application.Render();
1018 DALI_TEST_CHECK( gl.GetTextureTrace().FindMethod("BindTexture") );
1020 std::stringstream params;
1021 params << GL_TEXTURE_2D << ", " << 23;
1022 DALI_TEST_CHECK( gl.GetTextureTrace().FindMethodAndParams("BindTexture", params.str()) );
1027 // Scenarios 6: ImageView initially from regular image with custom shader but then SetImage called with Native
1028 int UtcDaliImageViewSetImageBufferImageWithCustomShaderToNativeImage(void)
1030 ToolkitTestApplication application;
1035 Property::Map customShader;
1036 customShader.Insert( "vertexShader", VERTEX_SHADER );
1037 customShader.Insert( "fragmentShader", FRAGMENT_SHADER );
1039 Property::Array shaderHints;
1040 shaderHints.PushBack( "requiresSelfDepthTest" );
1041 shaderHints.PushBack( "outputIsTransparent" );
1042 shaderHints.PushBack( "outputIsOpaque" );
1043 shaderHints.PushBack( "modifiesGeometry" );
1045 customShader.Insert( "hints", shaderHints );
1048 map.Insert( "rendererType", "image" );
1049 map.Insert( "shader", customShader );
1051 BufferImage image = CreateBufferImage( width, height, Color::WHITE );
1053 ImageView imageView = ImageView::New( image );
1054 imageView.SetProperty( ImageView::Property::IMAGE, map );
1055 Stage::GetCurrent().Add( imageView );
1057 imageView.SetProperty( ImageView::Property::IMAGE, map );
1059 TestGlAbstraction& gl = application.GetGlAbstraction();
1060 gl.EnableTextureCallTrace( true );
1062 std::vector< GLuint > ids;
1063 ids.push_back( 23 );
1064 application.GetGlAbstraction().SetNextTextureIds( ids );
1066 application.SendNotification();
1067 application.Render();
1069 DALI_TEST_CHECK( gl.GetTextureTrace().FindMethod("BindTexture") );
1071 std::stringstream params;
1072 params << GL_TEXTURE_2D << ", " << 23;
1073 DALI_TEST_CHECK( gl.GetTextureTrace().FindMethodAndParams("BindTexture", params.str()) );
1075 TestNativeImagePointer nativeImageInterface = TestNativeImage::New( width, height );
1076 NativeImage nativeImage = NativeImage::New( *(nativeImageInterface.Get()) );
1077 imageView.SetImage( nativeImage );
1080 ids.push_back( 24 );
1081 application.GetGlAbstraction().SetNextTextureIds( ids );
1083 application.SendNotification();
1084 application.Render();
1086 DALI_TEST_CHECK( gl.GetTextureTrace().FindMethod("BindTexture") );
1088 std::stringstream nativeImageParams;
1089 nativeImageParams << GL_TEXTURE_2D << ", " << 24;
1090 DALI_TEST_CHECK( gl.GetTextureTrace().FindMethodAndParams("BindTexture", nativeImageParams.str()) );
1096 int UtcDaliImageViewGetImageP1(void)
1098 ToolkitTestApplication application;
1100 ImageView imageView = ImageView::New();
1101 DALI_TEST_CHECK( ! imageView.GetImage() );
1103 Image image = CreateBufferImage();
1104 imageView.SetImage( image );
1105 DALI_TEST_CHECK( imageView.GetImage() == image );
1110 int UtcDaliImageViewGetImageP2(void)
1112 ToolkitTestApplication application;
1114 BufferImage image = CreateBufferImage();
1115 ImageView imageView = ImageView::New( image );
1116 DALI_TEST_CHECK( imageView.GetImage() == image );
1121 int UtcDaliImageViewGetImageN(void)
1123 ToolkitTestApplication application;
1125 ImageView imageView = ImageView::New( TEST_IMAGE_FILE_NAME );
1126 DALI_TEST_CHECK( ! imageView.GetImage() );
1128 Image image = CreateBufferImage();
1129 imageView.SetImage( image );
1130 DALI_TEST_CHECK( imageView.GetImage() == image );
1132 imageView.SetImage( TEST_IMAGE_FILE_NAME );
1133 DALI_TEST_CHECK( ! imageView.GetImage() );