2 * Copyright (c) 2014 Samsung Electronics Co., Ltd.
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
8 * http://www.apache.org/licenses/LICENSE-2.0
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
18 // Need to override adaptor classes for toolkit test harness, so include
19 // test harness headers before dali headers.
20 #include <dali-toolkit-test-suite-utils.h>
22 #include <dali-toolkit/dali-toolkit.h>
23 #include <dali/devel-api/scripting/scripting.h>
24 #include <dali/devel-api/rendering/material.h>
25 #include <dali/devel-api/rendering/renderer.h>
28 using namespace Toolkit;
30 void utc_dali_toolkit_image_view_startup(void)
32 test_return_value = TET_UNDEF;
35 void utc_dali_toolkit_image_view_cleanup(void)
37 test_return_value = TET_PASS;
42 const char* TEST_IMAGE_FILE_NAME = "gallery_image_01.jpg";
43 const char* TEST_IMAGE_FILE_NAME2 = "gallery_image_02.jpg";
45 void TestImage( ImageView imageView, BufferImage image )
47 Property::Value value = imageView.GetProperty( imageView.GetPropertyIndex( "image" ) );
50 DALI_TEST_CHECK( value.Get( map ) );
52 DALI_TEST_CHECK( map.Find( "width" ) );
53 DALI_TEST_CHECK( map.Find( "height" ) );
54 DALI_TEST_CHECK( map.Find( "type" ) );
57 DALI_TEST_CHECK( map[ "width" ].Get( width ) );
58 DALI_TEST_EQUALS( (unsigned int)width, image.GetWidth(), TEST_LOCATION );
61 DALI_TEST_CHECK( map[ "height" ].Get( height ) );
62 DALI_TEST_EQUALS( (unsigned int)height, image.GetHeight(), TEST_LOCATION );
65 DALI_TEST_CHECK( map[ "type" ].Get( type ) );
66 DALI_TEST_EQUALS( type, "BufferImage", TEST_LOCATION );
69 void TestImage( ImageView imageView, ResourceImage image )
71 Property::Value value = imageView.GetProperty( imageView.GetPropertyIndex( "image" ) );
74 DALI_TEST_CHECK( value.Get( map ) );
76 if( map.Find( "width" ) )
79 DALI_TEST_CHECK( map[ "width" ].Get( width ) );
80 DALI_TEST_EQUALS( (unsigned int)width, image.GetWidth(), TEST_LOCATION );
83 if( map.Find( "height" ) )
86 DALI_TEST_CHECK( map[ "height" ].Get( height ) );
87 DALI_TEST_EQUALS( (unsigned int)height, image.GetHeight(), TEST_LOCATION );
90 DALI_TEST_CHECK( map.Find( "type" ) );
93 DALI_TEST_CHECK( map[ "type" ].Get( type ) );
94 DALI_TEST_EQUALS( type, "ResourceImage", TEST_LOCATION );
97 DALI_TEST_CHECK( map[ "filename" ].Get( filename ) );
98 DALI_TEST_EQUALS( filename, image.GetUrl(), TEST_LOCATION );
101 void TestUrl( ImageView imageView, const std::string url )
103 Property::Value value = imageView.GetProperty( imageView.GetPropertyIndex( "image" ) );
105 std::string urlActual;
106 DALI_TEST_CHECK( value.Get( urlActual ) );
107 DALI_TEST_EQUALS( urlActual, url, TEST_LOCATION );
112 int UtcDaliImageViewNewP(void)
114 TestApplication application;
116 ImageView imageView = ImageView::New();
118 DALI_TEST_CHECK( imageView );
123 int UtcDaliImageViewNewImageP(void)
125 TestApplication application;
127 BufferImage image = CreateBufferImage( 100, 200, Vector4( 1.f, 1.f, 1.f, 1.f ) );
128 ImageView imageView = ImageView::New( image );
130 DALI_TEST_CHECK( imageView );
131 TestImage( imageView, image );
136 int UtcDaliImageViewNewUrlP(void)
138 TestApplication application;
140 ImageView imageView = ImageView::New( TEST_IMAGE_FILE_NAME );
141 DALI_TEST_CHECK( imageView );
143 TestUrl( imageView, TEST_IMAGE_FILE_NAME );
148 int UtcDaliImageViewConstructorP(void)
150 TestApplication application;
154 DALI_TEST_CHECK( !imageView );
159 int UtcDaliImageViewCopyConstructorP(void)
161 TestApplication application;
163 // Initialize an object, ref count == 1
164 ImageView imageView = ImageView::New();
166 ImageView copy( imageView );
167 DALI_TEST_CHECK( copy );
172 int UtcDaliImageViewAssignmentOperatorP(void)
174 TestApplication application;
176 ImageView imageView = ImageView::New();
178 ImageView copy( imageView );
179 DALI_TEST_CHECK( copy );
180 DALI_TEST_EQUALS( imageView, copy, TEST_LOCATION );
185 int UtcDaliImageViewDownCastP(void)
187 TestApplication application;
189 ImageView imageView = ImageView::New();
191 BaseHandle object(imageView);
193 ImageView imageView2 = ImageView::DownCast( object );
194 DALI_TEST_CHECK(imageView2);
196 ImageView imageView3 = DownCast< ImageView >( object );
197 DALI_TEST_CHECK(imageView3);
202 int UtcDaliImageViewDownCastN(void)
204 TestApplication application;
206 BaseHandle unInitializedObject;
208 ImageView imageView1 = ImageView::DownCast( unInitializedObject );
209 DALI_TEST_CHECK( !imageView1 );
211 ImageView imageView2 = DownCast< ImageView >( unInitializedObject );
212 DALI_TEST_CHECK( !imageView2 );
217 int UtcDaliImageViewTypeRegistry(void)
219 ToolkitTestApplication application;
221 TypeRegistry typeRegistry = TypeRegistry::Get();
222 DALI_TEST_CHECK( typeRegistry );
224 TypeInfo typeInfo = typeRegistry.GetTypeInfo( "ImageView" );
225 DALI_TEST_CHECK( typeInfo );
227 BaseHandle handle = typeInfo.CreateInstance();
228 DALI_TEST_CHECK( handle );
230 ImageView imageView = ImageView::DownCast( handle );
231 DALI_TEST_CHECK( imageView );
236 int UtcDaliImageViewSetGetProperty01(void)
238 ToolkitTestApplication application;
240 ImageView imageView = ImageView::New();
242 Property::Index idx = imageView.GetPropertyIndex( "image" );
243 DALI_TEST_EQUALS( idx, (Property::Index)ImageView::Property::IMAGE, TEST_LOCATION );
245 imageView.SetProperty( idx, TEST_IMAGE_FILE_NAME );
246 TestUrl( imageView, TEST_IMAGE_FILE_NAME );
251 int UtcDaliImageViewSetGetProperty02(void)
253 ToolkitTestApplication application;
255 Image image = CreateBufferImage( 10, 10, Color::WHITE );
256 ImageView imageView = ImageView::New(image);
257 Vector4 fullImageRect( 0.f, 0.f, 1.f, 1.f );
259 Stage::GetCurrent().Add( imageView );
261 application.SendNotification();
262 application.Render();
263 TestGlAbstraction& gl = application.GetGlAbstraction();
265 Vector4 pixelAreaUniform;
266 DALI_TEST_CHECK( gl.GetUniformValue<Vector4>( "pixelArea", pixelAreaUniform ) );
267 DALI_TEST_EQUALS( pixelAreaUniform, fullImageRect, TEST_LOCATION );
269 Property::Value value = imageView.GetProperty( ImageView::Property::PIXEL_AREA );
270 Vector4 pixelAreaValue;
271 DALI_TEST_CHECK( value.Get(pixelAreaValue) );
272 DALI_TEST_EQUALS( pixelAreaValue, fullImageRect, TEST_LOCATION );
274 Vector4 pixelAreaSet( 0.2f, 0.2f, 0.3f, 0.3f );
275 imageView.SetProperty( ImageView::Property::PIXEL_AREA, pixelAreaSet);
277 application.SendNotification();
278 application.Render();
280 value = imageView.GetProperty( ImageView::Property::PIXEL_AREA );
281 value.Get(pixelAreaValue);
282 DALI_TEST_EQUALS( pixelAreaValue, pixelAreaSet, TEST_LOCATION );
284 DALI_TEST_CHECK( gl.GetUniformValue<Vector4>( "pixelArea", pixelAreaUniform ) );
285 DALI_TEST_EQUALS( pixelAreaUniform, pixelAreaSet, TEST_LOCATION );
290 int UtcDaliImageViewSetGetProperty03(void)
292 ToolkitTestApplication application;
294 Image image = CreateBufferImage( 10, 10, Color::WHITE );
295 ImageView imageView = ImageView::New(image);
296 Stage::GetCurrent().Add( imageView );
297 application.SendNotification();
298 application.Render();
300 // conventional alpha blending
301 Material material = imageView.GetRendererAt( 0 ).GetMaterial();
302 BlendingFactor::Type srcFactorRgb;
303 BlendingFactor::Type destFactorRgb;
304 BlendingFactor::Type srcFactorAlpha;
305 BlendingFactor::Type destFactorAlpha;
306 material.GetBlendFunc(srcFactorRgb, destFactorRgb, srcFactorAlpha, destFactorAlpha);
307 DALI_TEST_CHECK( srcFactorRgb == BlendingFactor::SRC_ALPHA );
308 DALI_TEST_CHECK( destFactorRgb == BlendingFactor::ONE_MINUS_SRC_ALPHA );
309 DALI_TEST_CHECK( srcFactorAlpha == BlendingFactor::ONE );
310 DALI_TEST_CHECK( destFactorAlpha == BlendingFactor::ONE_MINUS_SRC_ALPHA );
312 TestGlAbstraction& gl = application.GetGlAbstraction();
314 float alphaBlendingUniform;
315 DALI_TEST_CHECK( gl.GetUniformValue<float>( "uAlphaBlending", alphaBlendingUniform ) );
316 DALI_TEST_EQUALS( alphaBlendingUniform, 1.f, TEST_LOCATION );
318 // pre-multiplied alpha blending
319 imageView.SetProperty( Toolkit::ImageView::Property::PRE_MULTIPLIED_ALPHA, true );
320 application.SendNotification();
321 application.Render();
323 material.GetBlendFunc(srcFactorRgb, destFactorRgb, srcFactorAlpha, destFactorAlpha);
324 DALI_TEST_CHECK( srcFactorRgb == BlendingFactor::ONE );
325 DALI_TEST_CHECK( destFactorRgb == BlendingFactor::ONE_MINUS_SRC_ALPHA );
326 DALI_TEST_CHECK( srcFactorAlpha == BlendingFactor::ONE );
327 DALI_TEST_CHECK( destFactorAlpha == BlendingFactor::ONE );
329 DALI_TEST_CHECK( gl.GetUniformValue<float>( "uAlphaBlending", alphaBlendingUniform ) );
330 DALI_TEST_EQUALS( alphaBlendingUniform, 0.f, TEST_LOCATION );
335 int UtcDaliImageViewSizeWithBackground(void)
337 ToolkitTestApplication application;
341 Image image = CreateBufferImage( width, height, Vector4(1.f, 1.f, 1.f, 1.f) );
342 ImageView imageView = ImageView::New();
343 imageView.SetBackgroundImage( image );
345 Stage::GetCurrent().Add( imageView );
346 application.SendNotification();
347 application.Render();
349 DALI_TEST_EQUALS( imageView.GetCurrentSize().width, (float)width, TEST_LOCATION );
350 DALI_TEST_EQUALS( imageView.GetCurrentSize().height, (float)height, TEST_LOCATION );
355 int UtcDaliImageViewSizeWithBackgroundAndImage(void)
357 ToolkitTestApplication application;
359 int widthBackground = 100;
360 int heightBackground = 200;
363 Image imageBackground = CreateBufferImage( widthBackground, heightBackground, Vector4(1.f, 1.f, 1.f, 1.f) );
364 Image image = CreateBufferImage( width, height, Vector4(1.f, 1.f, 1.f, 1.f) );
366 ImageView imageView = ImageView::New();
367 imageView.SetBackgroundImage( imageBackground );
368 imageView.SetImage( image );
370 Stage::GetCurrent().Add( imageView );
371 application.SendNotification();
372 application.Render();
374 DALI_TEST_EQUALS( imageView.GetCurrentSize().width, (float)width, TEST_LOCATION );
375 DALI_TEST_EQUALS( imageView.GetCurrentSize().height, (float)height, TEST_LOCATION );
380 int UtcDaliImageViewHeightForWidthBackground(void)
382 ToolkitTestApplication application;
384 int widthBackground = 100;
385 int heightBackground = 200;
386 Image imageBackground = CreateBufferImage( widthBackground, heightBackground, Vector4(1.f, 1.f, 1.f, 1.f) );
388 ImageView imageView = ImageView::New();
389 imageView.SetBackgroundImage( imageBackground );
391 Stage::GetCurrent().Add( imageView );
392 application.SendNotification();
393 application.Render();
395 Control control = Control::DownCast( imageView );
396 DALI_TEST_CHECK( control );
397 DALI_TEST_EQUALS( imageView.GetHeightForWidth( 123.f ), control.GetHeightForWidth( 123.f ), TEST_LOCATION );
398 DALI_TEST_EQUALS( imageView.GetWidthForHeight( 321.f ), control.GetWidthForHeight( 321.f ), TEST_LOCATION );
403 int UtcDaliImageViewHeightForWidthBackgroundAndImage(void)
405 ToolkitTestApplication application;
407 int widthBackground = 100;
408 int heightBackground = 200;
411 Image imageBackground = CreateBufferImage( widthBackground, heightBackground, Vector4(1.f, 1.f, 1.f, 1.f) );
412 Image image = CreateBufferImage( width, height, Vector4(1.f, 1.f, 1.f, 1.f) );
414 ImageView imageView = ImageView::New();
415 imageView.SetBackgroundImage( imageBackground );
416 imageView.SetImage( image );
418 Stage::GetCurrent().Add( imageView );
419 application.SendNotification();
420 application.Render();
422 DALI_TEST_EQUALS( imageView.GetHeightForWidth( width ), (float)height, TEST_LOCATION );
423 DALI_TEST_EQUALS( imageView.GetWidthForHeight( height ), (float)width, TEST_LOCATION );
428 int UtcDaliImageViewSetBufferImage(void)
430 ToolkitTestApplication application;
434 BufferImage image1 = CreateBufferImage( width1, height1, Vector4( 1.f, 1.f, 1.f, 1.f ) );
435 ImageView imageView = ImageView::New();
436 imageView.SetImage( image1 );
438 TestImage( imageView, image1 );
442 BufferImage image2 = CreateBufferImage( width2, height2, Vector4( 1.f, 1.f, 1.f, 1.f ) );
443 imageView.SetImage( image2 );
445 TestImage( imageView, image2 );
450 int UtcDaliImageViewSetImageUrl(void)
452 ToolkitTestApplication application;
454 ImageView imageView = ImageView::New();
455 imageView.SetImage( TEST_IMAGE_FILE_NAME );
456 TestUrl( imageView, TEST_IMAGE_FILE_NAME );
459 imageView.SetImage( TEST_IMAGE_FILE_NAME2 );
460 TestUrl( imageView, TEST_IMAGE_FILE_NAME2 );
465 int UtcDaliImageViewSetImageOnstageP(void)
467 ToolkitTestApplication application;
469 ImageView imageView = ImageView::New();
471 Stage::GetCurrent().Add( imageView );
472 application.SendNotification();
473 application.Render();
475 ResourceImage image1 = ResourceImage::New( TEST_IMAGE_FILE_NAME );
476 imageView.SetImage( image1 );
477 TestImage( imageView, image1 );
481 BufferImage image2 = CreateBufferImage( width, height, Vector4( 1.f, 1.f, 1.f, 1.f ) );
482 imageView.SetImage( image2 );
483 TestImage( imageView, image2 );
488 int UtcDaliImageViewSetImageOnstageN(void)
490 ToolkitTestApplication application;
492 ImageView imageView = ImageView::New();
494 Stage::GetCurrent().Add( imageView );
495 application.SendNotification();
496 application.Render();
498 ResourceImage image1 = ResourceImage::New( TEST_IMAGE_FILE_NAME );
499 imageView.SetImage( image1 );
500 TestImage( imageView, image1 );
503 imageView.SetImage( image2 );
505 Property::Value value = imageView.GetProperty( imageView.GetPropertyIndex( "image" ) );
507 //the value should be empty
509 DALI_TEST_CHECK( !value.Get( url ) );
512 DALI_TEST_CHECK( !value.Get( map ) );
517 int UtcDaliImageViewSetImageOffstageP(void)
519 ToolkitTestApplication application;
521 ImageView imageView = ImageView::New();
523 Stage::GetCurrent().Add( imageView );
524 application.SendNotification();
525 application.Render();
526 Stage::GetCurrent().Remove( imageView );
528 ResourceImage image1 = ResourceImage::New( TEST_IMAGE_FILE_NAME );
529 imageView.SetImage( image1 );
530 TestImage( imageView, image1 );
534 BufferImage image2 = CreateBufferImage( width, height, Vector4( 1.f, 1.f, 1.f, 1.f ) );
535 imageView.SetImage( image2 );
536 TestImage( imageView, image2 );
541 int UtcDaliImageViewSetImageOffstageN(void)
543 ToolkitTestApplication application;
545 ImageView imageView = ImageView::New();
547 Stage::GetCurrent().Add( imageView );
548 application.SendNotification();
549 application.Render();
550 Stage::GetCurrent().Remove( imageView );
552 ResourceImage image1 = ResourceImage::New( TEST_IMAGE_FILE_NAME );
553 imageView.SetImage( image1 );
554 TestImage( imageView, image1 );
557 imageView.SetImage( image2 );
559 Property::Value value = imageView.GetProperty( imageView.GetPropertyIndex( "image" ) );
561 //the value should be empty
563 DALI_TEST_CHECK( !value.Get( url ) );
566 DALI_TEST_CHECK( !value.Get( map ) );
571 int UtcDaliImageViewSetImageN(void)
573 ToolkitTestApplication application;
576 ImageView imageView = ImageView::New();
577 imageView.SetImage( image1 );
579 Property::Value value = imageView.GetProperty( imageView.GetPropertyIndex( "image" ) );
581 //the value should be empty
583 DALI_TEST_CHECK( !value.Get( url ) );
586 DALI_TEST_CHECK( !value.Get( map ) );
588 std::string resource_url;
589 Property::Value val = imageView.GetProperty( imageView.GetPropertyIndex( "image" ) );
590 DALI_TEST_CHECK( !val.Get( resource_url ) );
595 int UtcDaliImageViewSetImageTypeChangesP(void)
597 ToolkitTestApplication application;
599 ImageView imageView = ImageView::New();
605 Property::Value value = imageView.GetProperty( imageView.GetPropertyIndex( "image" ) );
606 DALI_TEST_CHECK( ! value.Get( url ) ); // Value should be empty
607 DALI_TEST_CHECK( ! value.Get( map ) ); // Value should be empty
610 imageView.SetImage( "TEST_URL" );
611 value = imageView.GetProperty( imageView.GetPropertyIndex( "image" ) );
613 DALI_TEST_CHECK( value.Get( url ) ); // Value should NOT be empty
614 DALI_TEST_CHECK( ! value.Get( map ) ); // Value should be empty
616 // Set an empty Image
617 imageView.SetImage( Image() );
618 value = imageView.GetProperty( imageView.GetPropertyIndex( "image" ) );
620 DALI_TEST_CHECK( ! value.Get( url ) ); // Value should be empty
621 DALI_TEST_CHECK( ! value.Get( map ) ); // Value should be empty
624 ResourceImage image1 = ResourceImage::New( TEST_IMAGE_FILE_NAME );
625 imageView.SetImage( image1 );
626 value = imageView.GetProperty( imageView.GetPropertyIndex( "image" ) );
628 DALI_TEST_CHECK( ! value.Get( url ) ); // Value should be empty
629 DALI_TEST_CHECK( value.Get( map ) ); // Value should NOT be empty
632 imageView.SetImage( "" );
633 value = imageView.GetProperty( imageView.GetPropertyIndex( "image" ) );
635 DALI_TEST_CHECK( ! value.Get( url ) ); // Value should be empty
636 DALI_TEST_CHECK( ! value.Get( map ) ); // Value should be empty
641 int UtcDaliImageViewResourceUrlP(void)
643 ToolkitTestApplication application;
645 ImageView imageView = ImageView::New();
646 DALI_TEST_CHECK( imageView.GetProperty( ImageView::Property::RESOURCE_URL ).Get< std::string >().empty() );
648 imageView.SetProperty( ImageView::Property::RESOURCE_URL, "TestString" );
649 DALI_TEST_EQUALS( imageView.GetProperty( ImageView::Property::RESOURCE_URL ).Get< std::string >(), "TestString", TEST_LOCATION );