2 * Copyright (c) 2016 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/public-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 == BlendFactor::ONE );
355 DALI_TEST_CHECK( destFactorRgb == BlendFactor::ONE_MINUS_SRC_ALPHA );
356 DALI_TEST_CHECK( srcFactorAlpha == BlendFactor::ONE );
357 DALI_TEST_CHECK( destFactorAlpha == BlendFactor::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 eventTrigger->WaitingForTrigger( 1 );
421 CallbackBase* callback = eventTrigger->GetCallback();
422 CallbackBase::Execute( *callback );
424 application.SendNotification();
425 application.Render(16);
427 callStack.Enable(false);
429 TraceCallStack::NamedParams params;
430 params["width"] = ToString(34);
431 params["height"] = ToString(34);
432 DALI_TEST_EQUALS( callStack.FindMethodAndParams( "TexSubImage2D", params ), true, TEST_LOCATION );
437 int UtcDaliImageViewSyncLoading(void)
439 ToolkitTestApplication application;
441 Property::Map syncLoadingMap;
442 syncLoadingMap[ "synchronousLoading" ] = true;
444 // Sync loading, no atlasing for big size image
446 ImageView imageView = ImageView::New();
448 // Sync loading is used
449 syncLoadingMap[ ImageVisual::Property::URL ] = gImage_600_RGB;
450 imageView.SetProperty( ImageView::Property::IMAGE, syncLoadingMap );
452 // BitmapLoader is used, and the loading is started immediately even the actor is not on stage.
453 BitmapLoader loader = BitmapLoader::GetLatestCreated();
454 DALI_TEST_CHECK( loader );
457 // Sync loading, automatic atlasing for small size image
459 BitmapLoader::ResetLatestCreated();
460 TraceCallStack& callStack = application.GetGlAbstraction().GetTextureTrace();
462 callStack.Enable(true);
464 ImageView imageView = ImageView::New( );
465 // Sync loading is used
466 syncLoadingMap[ ImageVisual::Property::URL ] = gImage_34_RGBA;
467 syncLoadingMap[ ImageVisual::Property::DESIRED_HEIGHT ] = 34;
468 syncLoadingMap[ ImageVisual::Property::DESIRED_WIDTH ] = 34;
469 imageView.SetProperty( ImageView::Property::IMAGE, syncLoadingMap );
471 // loading is started even if the actor is offStage
472 BitmapLoader loader = BitmapLoader::GetLatestCreated();
473 DALI_TEST_CHECK( loader );
475 loader.WaitForLoading();
477 DALI_TEST_CHECK( loader.IsLoaded() );
479 Stage::GetCurrent().Add( imageView );
480 application.SendNotification();
481 application.Render(16);
483 TraceCallStack::NamedParams params;
484 params["width"] = ToString(34);
485 params["height"] = ToString(34);
486 DALI_TEST_EQUALS( callStack.FindMethodAndParams( "TexSubImage2D", params ),
487 true, TEST_LOCATION );
492 int UtcDaliImageViewSizeWithBackground(void)
494 ToolkitTestApplication application;
498 Image image = CreateBufferImage( width, height, Vector4(1.f, 1.f, 1.f, 1.f) );
499 ImageView imageView = ImageView::New();
500 imageView.SetBackgroundImage( image );
502 Stage::GetCurrent().Add( imageView );
503 application.SendNotification();
504 application.Render();
506 DALI_TEST_EQUALS( imageView.GetCurrentSize().width, (float)width, TEST_LOCATION );
507 DALI_TEST_EQUALS( imageView.GetCurrentSize().height, (float)height, TEST_LOCATION );
512 int UtcDaliImageViewSizeWithBackgroundAndImage(void)
514 ToolkitTestApplication application;
516 int widthBackground = 100;
517 int heightBackground = 200;
520 Image imageBackground = CreateBufferImage( widthBackground, heightBackground, Vector4(1.f, 1.f, 1.f, 1.f) );
521 Image image = CreateBufferImage( width, height, Vector4(1.f, 1.f, 1.f, 1.f) );
523 ImageView imageView = ImageView::New();
524 imageView.SetBackgroundImage( imageBackground );
525 imageView.SetImage( image );
527 Stage::GetCurrent().Add( imageView );
528 application.SendNotification();
529 application.Render();
531 DALI_TEST_EQUALS( imageView.GetCurrentSize().width, (float)width, TEST_LOCATION );
532 DALI_TEST_EQUALS( imageView.GetCurrentSize().height, (float)height, TEST_LOCATION );
537 int UtcDaliImageViewHeightForWidthBackground(void)
539 ToolkitTestApplication application;
541 int widthBackground = 100;
542 int heightBackground = 200;
543 Image imageBackground = CreateBufferImage( widthBackground, heightBackground, Vector4(1.f, 1.f, 1.f, 1.f) );
545 ImageView imageView = ImageView::New();
546 imageView.SetBackgroundImage( imageBackground );
548 Stage::GetCurrent().Add( imageView );
549 application.SendNotification();
550 application.Render();
552 Control control = Control::DownCast( imageView );
553 DALI_TEST_CHECK( control );
554 DALI_TEST_EQUALS( imageView.GetHeightForWidth( 123.f ), control.GetHeightForWidth( 123.f ), TEST_LOCATION );
555 DALI_TEST_EQUALS( imageView.GetWidthForHeight( 321.f ), control.GetWidthForHeight( 321.f ), TEST_LOCATION );
560 int UtcDaliImageViewHeightForWidthBackgroundAndImage(void)
562 ToolkitTestApplication application;
564 int widthBackground = 100;
565 int heightBackground = 200;
568 Image imageBackground = CreateBufferImage( widthBackground, heightBackground, Vector4(1.f, 1.f, 1.f, 1.f) );
569 Image image = CreateBufferImage( width, height, Vector4(1.f, 1.f, 1.f, 1.f) );
571 ImageView imageView = ImageView::New();
572 imageView.SetBackgroundImage( imageBackground );
573 imageView.SetImage( image );
575 Stage::GetCurrent().Add( imageView );
576 application.SendNotification();
577 application.Render();
579 DALI_TEST_EQUALS( imageView.GetHeightForWidth( width ), (float)height, TEST_LOCATION );
580 DALI_TEST_EQUALS( imageView.GetWidthForHeight( height ), (float)width, TEST_LOCATION );
585 int UtcDaliImageViewSetBufferImage(void)
587 ToolkitTestApplication application;
591 BufferImage image1 = CreateBufferImage( width1, height1, Vector4( 1.f, 1.f, 1.f, 1.f ) );
592 ImageView imageView = ImageView::New();
593 imageView.SetImage( image1 );
595 TestImage( imageView, image1 );
599 BufferImage image2 = CreateBufferImage( width2, height2, Vector4( 1.f, 1.f, 1.f, 1.f ) );
600 imageView.SetImage( image2 );
602 TestImage( imageView, image2 );
607 int UtcDaliImageViewSetImageUrl(void)
609 ToolkitTestApplication application;
611 ImageView imageView = ImageView::New();
612 imageView.SetImage( TEST_IMAGE_FILE_NAME );
613 TestUrl( imageView, TEST_IMAGE_FILE_NAME );
616 imageView.SetImage( TEST_IMAGE_FILE_NAME2 );
617 TestUrl( imageView, TEST_IMAGE_FILE_NAME2 );
622 int UtcDaliImageViewSetImageOnstageP(void)
624 ToolkitTestApplication application;
626 ImageView imageView = ImageView::New();
628 Stage::GetCurrent().Add( imageView );
629 application.SendNotification();
630 application.Render();
632 ResourceImage image1 = ResourceImage::New( TEST_IMAGE_FILE_NAME );
633 imageView.SetImage( image1 );
634 TestImage( imageView, image1 );
638 BufferImage image2 = CreateBufferImage( width, height, Vector4( 1.f, 1.f, 1.f, 1.f ) );
639 imageView.SetImage( image2 );
640 TestImage( imageView, image2 );
645 int UtcDaliImageViewSetImageOnstageN(void)
647 ToolkitTestApplication application;
649 ImageView imageView = ImageView::New();
651 Stage::GetCurrent().Add( imageView );
652 application.SendNotification();
653 application.Render();
655 ResourceImage image1 = ResourceImage::New( TEST_IMAGE_FILE_NAME );
656 imageView.SetImage( image1 );
657 TestImage( imageView, image1 );
660 imageView.SetImage( image2 );
662 Property::Value value = imageView.GetProperty( imageView.GetPropertyIndex( "image" ) );
664 //the value should be empty
666 DALI_TEST_CHECK( !value.Get( url ) );
669 DALI_TEST_CHECK( !value.Get( map ) );
674 int UtcDaliImageViewSetImageOffstageP(void)
676 ToolkitTestApplication application;
678 ImageView imageView = ImageView::New();
680 Stage::GetCurrent().Add( imageView );
681 application.SendNotification();
682 application.Render();
683 Stage::GetCurrent().Remove( imageView );
685 ResourceImage image1 = ResourceImage::New( TEST_IMAGE_FILE_NAME );
686 imageView.SetImage( image1 );
687 TestImage( imageView, image1 );
691 BufferImage image2 = CreateBufferImage( width, height, Vector4( 1.f, 1.f, 1.f, 1.f ) );
692 imageView.SetImage( image2 );
693 TestImage( imageView, image2 );
698 int UtcDaliImageViewSetImageOffstageN(void)
700 ToolkitTestApplication application;
702 ImageView imageView = ImageView::New();
704 Stage::GetCurrent().Add( imageView );
705 application.SendNotification();
706 application.Render();
707 Stage::GetCurrent().Remove( imageView );
709 ResourceImage image1 = ResourceImage::New( TEST_IMAGE_FILE_NAME );
710 imageView.SetImage( image1 );
711 TestImage( imageView, image1 );
714 imageView.SetImage( image2 );
716 Property::Value value = imageView.GetProperty( imageView.GetPropertyIndex( "image" ) );
718 //the value should be empty
720 DALI_TEST_CHECK( !value.Get( url ) );
723 DALI_TEST_CHECK( !value.Get( map ) );
728 int UtcDaliImageViewSetImageN(void)
730 ToolkitTestApplication application;
733 ImageView imageView = ImageView::New();
734 imageView.SetImage( image1 );
736 Property::Value value = imageView.GetProperty( imageView.GetPropertyIndex( "image" ) );
738 //the value should be empty
740 DALI_TEST_CHECK( !value.Get( url ) );
743 DALI_TEST_CHECK( !value.Get( map ) );
745 std::string resource_url;
746 Property::Value val = imageView.GetProperty( imageView.GetPropertyIndex( "image" ) );
747 DALI_TEST_CHECK( !val.Get( resource_url ) );
752 int UtcDaliImageViewSetImageTypeChangesP(void)
754 ToolkitTestApplication application;
756 ImageView imageView = ImageView::New();
762 Property::Value value = imageView.GetProperty( imageView.GetPropertyIndex( "image" ) );
763 DALI_TEST_CHECK( ! value.Get( url ) ); // Value should be empty
764 DALI_TEST_CHECK( ! value.Get( map ) ); // Value should be empty
767 imageView.SetImage( "TEST_URL" );
768 value = imageView.GetProperty( imageView.GetPropertyIndex( "image" ) );
770 DALI_TEST_CHECK( value.Get( url ) ); // Value should NOT be empty
771 DALI_TEST_CHECK( ! value.Get( map ) ); // Value should be empty
773 // Set an empty Image
774 imageView.SetImage( Image() );
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 be empty
781 ResourceImage image1 = ResourceImage::New( TEST_IMAGE_FILE_NAME );
782 imageView.SetImage( image1 );
783 value = imageView.GetProperty( imageView.GetPropertyIndex( "image" ) );
785 DALI_TEST_CHECK( ! value.Get( url ) ); // Value should be empty
786 DALI_TEST_CHECK( value.Get( map ) ); // Value should NOT be empty
789 imageView.SetImage( "" );
790 value = imageView.GetProperty( imageView.GetPropertyIndex( "image" ) );
792 DALI_TEST_CHECK( ! value.Get( url ) ); // Value should be empty
793 DALI_TEST_CHECK( ! value.Get( map ) ); // Value should be empty
798 int UtcDaliImageViewResourceUrlP(void)
800 ToolkitTestApplication application;
802 ImageView imageView = ImageView::New();
803 DALI_TEST_CHECK( imageView.GetProperty( ImageView::Property::RESOURCE_URL ).Get< std::string >().empty() );
805 imageView.SetProperty( ImageView::Property::RESOURCE_URL, "TestString" );
806 DALI_TEST_EQUALS( imageView.GetProperty( ImageView::Property::RESOURCE_URL ).Get< std::string >(), "TestString", TEST_LOCATION );
811 // Scenarios 1: ImageView from regular image
812 int UtcDaliImageViewSetImageBufferImage(void)
814 ToolkitTestApplication application;
816 ImageView imageView = ImageView::New();
817 Stage::GetCurrent().Add( imageView );
819 TestGlAbstraction& gl = application.GetGlAbstraction();
820 gl.EnableTextureCallTrace( true );
822 std::vector< GLuint > ids;
824 application.GetGlAbstraction().SetNextTextureIds( ids );
828 BufferImage image = CreateBufferImage( width, height, Color::WHITE );
830 imageView.SetImage( image );
832 application.SendNotification();
833 application.Render();
835 DALI_TEST_CHECK( gl.GetTextureTrace().FindMethod("BindTexture") );
837 std::stringstream params;
838 params << GL_TEXTURE_2D << ", " << 23;
839 DALI_TEST_CHECK( gl.GetTextureTrace().FindMethodAndParams("BindTexture", params.str()) );
844 // Scenarios 2: ImageView from Native image
845 int UtcDaliImageViewSetImageNativeImage(void)
847 ToolkitTestApplication application;
849 ImageView imageView = ImageView::New();
850 Stage::GetCurrent().Add( imageView );
852 TestGlAbstraction& gl = application.GetGlAbstraction();
853 gl.EnableTextureCallTrace( true );
855 std::vector< GLuint > ids;
857 application.GetGlAbstraction().SetNextTextureIds( ids );
861 TestNativeImagePointer nativeImageInterface = TestNativeImage::New( width, height );
862 NativeImage nativeImage = NativeImage::New( *(nativeImageInterface.Get()) );
864 imageView.SetImage( nativeImage );
865 application.SendNotification();
866 application.Render();
868 DALI_TEST_CHECK( gl.GetTextureTrace().FindMethod("BindTexture") );
870 std::stringstream params;
871 params << GL_TEXTURE_2D << ", " << 23;
872 DALI_TEST_CHECK( gl.GetTextureTrace().FindMethodAndParams("BindTexture", params.str()) );
877 // Scenarios 3: ImageView initially from regular image but then SetImage called with Native image
878 int UtcDaliImageViewSetImageBufferImageToNativeImage(void)
880 ToolkitTestApplication application;
884 BufferImage image = CreateBufferImage( width, height, Color::WHITE );
886 ImageView imageView = ImageView::New( image );
887 Stage::GetCurrent().Add( imageView );
889 TestGlAbstraction& gl = application.GetGlAbstraction();
890 gl.EnableTextureCallTrace( true );
892 std::vector< GLuint > ids;
894 application.GetGlAbstraction().SetNextTextureIds( ids );
896 application.SendNotification();
897 application.Render();
899 DALI_TEST_CHECK( gl.GetTextureTrace().FindMethod("BindTexture") );
901 std::stringstream params;
902 params << GL_TEXTURE_2D << ", " << 23;
903 DALI_TEST_CHECK( gl.GetTextureTrace().FindMethodAndParams("BindTexture", params.str()) );
907 TestNativeImagePointer nativeImageInterface = TestNativeImage::New( width, height );
908 NativeImage nativeImage = NativeImage::New( *(nativeImageInterface.Get()) );
909 imageView.SetImage( nativeImage );
913 application.GetGlAbstraction().SetNextTextureIds( ids );
915 application.SendNotification();
916 application.Render();
918 DALI_TEST_CHECK( gl.GetTextureTrace().FindMethod("BindTexture") );
920 std::stringstream nextTextureParams;
921 nextTextureParams << GL_TEXTURE_2D << ", " << 24;
922 DALI_TEST_CHECK( gl.GetTextureTrace().FindMethodAndParams("BindTexture", nextTextureParams.str()) );
927 // Scenarios 4: ImageView initially from Native image but then SetImage called with regular image
928 int UtcDaliImageViewSetImageNativeImageToBufferImage(void)
930 ToolkitTestApplication application;
934 TestNativeImagePointer nativeImageInterface = TestNativeImage::New( width, height );
935 NativeImage nativeImage = NativeImage::New( *(nativeImageInterface.Get()) );
937 ImageView imageView = ImageView::New( nativeImage );
938 Stage::GetCurrent().Add( imageView );
940 TestGlAbstraction& gl = application.GetGlAbstraction();
941 gl.EnableTextureCallTrace( true );
943 std::vector< GLuint > ids;
945 application.GetGlAbstraction().SetNextTextureIds( ids );
947 application.SendNotification();
948 application.Render();
950 DALI_TEST_CHECK( gl.GetTextureTrace().FindMethod("BindTexture") );
952 std::stringstream params;
953 params << GL_TEXTURE_2D << ", " << 23;
954 DALI_TEST_CHECK( gl.GetTextureTrace().FindMethodAndParams("BindTexture", params.str()) );
958 BufferImage image = CreateBufferImage( width, height, Color::WHITE );
959 imageView.SetImage( image );
963 application.GetGlAbstraction().SetNextTextureIds( ids );
965 application.SendNotification();
966 application.Render();
968 DALI_TEST_CHECK( gl.GetTextureTrace().FindMethod("BindTexture") );
970 std::stringstream nextTextureParams;
971 nextTextureParams << GL_TEXTURE_2D << ", " << 24;
972 DALI_TEST_CHECK( gl.GetTextureTrace().FindMethodAndParams("BindTexture", nextTextureParams.str()) );
977 // Scenarios 5: ImageView from Native image with custom shader
978 int UtcDaliImageViewSetImageNativeImageWithCustomShader(void)
980 ToolkitTestApplication application;
985 Property::Map customShader;
986 customShader.Insert( "vertexShader", VERTEX_SHADER );
987 customShader.Insert( "fragmentShader", FRAGMENT_SHADER );
989 Property::Array shaderHints;
990 shaderHints.PushBack( "requiresSelfDepthTest" );
991 shaderHints.PushBack( "outputIsTransparent" );
992 shaderHints.PushBack( "outputIsOpaque" );
993 shaderHints.PushBack( "modifiesGeometry" );
995 customShader.Insert( "hints", shaderHints );
998 map.Insert( "shader", customShader );
1000 TestNativeImagePointer nativeImageInterface = TestNativeImage::New( width, height );
1001 NativeImage nativeImage = NativeImage::New( *(nativeImageInterface.Get()) );
1003 ImageView imageView = ImageView::New( nativeImage );
1004 imageView.SetProperty( ImageView::Property::IMAGE, map );
1005 Stage::GetCurrent().Add( imageView );
1007 TestGlAbstraction& gl = application.GetGlAbstraction();
1008 gl.EnableTextureCallTrace( true );
1010 std::vector< GLuint > ids;
1011 ids.push_back( 23 );
1012 application.GetGlAbstraction().SetNextTextureIds( ids );
1014 application.SendNotification();
1015 application.Render();
1017 DALI_TEST_CHECK( gl.GetTextureTrace().FindMethod("BindTexture") );
1019 std::stringstream params;
1020 params << GL_TEXTURE_2D << ", " << 23;
1021 DALI_TEST_CHECK( gl.GetTextureTrace().FindMethodAndParams("BindTexture", params.str()) );
1026 // Scenarios 6: ImageView initially from regular image with custom shader but then SetImage called with Native
1027 int UtcDaliImageViewSetImageBufferImageWithCustomShaderToNativeImage(void)
1029 ToolkitTestApplication application;
1034 Property::Map customShader;
1035 customShader.Insert( "vertexShader", VERTEX_SHADER );
1036 customShader.Insert( "fragmentShader", FRAGMENT_SHADER );
1038 Property::Array shaderHints;
1039 shaderHints.PushBack( "requiresSelfDepthTest" );
1040 shaderHints.PushBack( "outputIsTransparent" );
1041 shaderHints.PushBack( "outputIsOpaque" );
1042 shaderHints.PushBack( "modifiesGeometry" );
1044 customShader.Insert( "hints", shaderHints );
1047 map.Insert( "shader", customShader );
1049 BufferImage image = CreateBufferImage( width, height, Color::WHITE );
1051 ImageView imageView = ImageView::New( image );
1052 imageView.SetProperty( ImageView::Property::IMAGE, map );
1053 Stage::GetCurrent().Add( imageView );
1055 TestGlAbstraction& gl = application.GetGlAbstraction();
1056 gl.EnableTextureCallTrace( true );
1058 std::vector< GLuint > ids;
1059 ids.push_back( 23 );
1060 application.GetGlAbstraction().SetNextTextureIds( ids );
1062 application.SendNotification();
1063 application.Render();
1065 DALI_TEST_CHECK( gl.GetTextureTrace().FindMethod("BindTexture") );
1067 std::stringstream params;
1068 params << GL_TEXTURE_2D << ", " << 23;
1069 DALI_TEST_CHECK( gl.GetTextureTrace().FindMethodAndParams("BindTexture", params.str()) );
1071 TestNativeImagePointer nativeImageInterface = TestNativeImage::New( width, height );
1072 NativeImage nativeImage = NativeImage::New( *(nativeImageInterface.Get()) );
1073 imageView.SetImage( nativeImage );
1076 ids.push_back( 24 );
1077 application.GetGlAbstraction().SetNextTextureIds( ids );
1079 application.SendNotification();
1080 application.Render();
1082 DALI_TEST_CHECK( gl.GetTextureTrace().FindMethod("BindTexture") );
1084 std::stringstream nativeImageParams;
1085 nativeImageParams << GL_TEXTURE_2D << ", " << 24;
1086 DALI_TEST_CHECK( gl.GetTextureTrace().FindMethodAndParams("BindTexture", nativeImageParams.str()) );
1092 int UtcDaliImageViewGetImageP1(void)
1094 ToolkitTestApplication application;
1096 ImageView imageView = ImageView::New();
1097 DALI_TEST_CHECK( ! imageView.GetImage() );
1099 Image image = CreateBufferImage();
1100 imageView.SetImage( image );
1101 DALI_TEST_CHECK( imageView.GetImage() == image );
1106 int UtcDaliImageViewGetImageP2(void)
1108 ToolkitTestApplication application;
1110 BufferImage image = CreateBufferImage();
1111 ImageView imageView = ImageView::New( image );
1112 DALI_TEST_CHECK( imageView.GetImage() == image );
1117 int UtcDaliImageViewGetImageN(void)
1119 ToolkitTestApplication application;
1121 ImageView imageView = ImageView::New( TEST_IMAGE_FILE_NAME );
1122 DALI_TEST_CHECK( ! imageView.GetImage() );
1124 Image image = CreateBufferImage();
1125 imageView.SetImage( image );
1126 DALI_TEST_CHECK( imageView.GetImage() == image );
1128 imageView.SetImage( TEST_IMAGE_FILE_NAME );
1129 DALI_TEST_CHECK( ! imageView.GetImage() );