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>
26 using namespace Toolkit;
28 void utc_dali_toolkit_image_view_startup(void)
30 test_return_value = TET_UNDEF;
33 void utc_dali_toolkit_image_view_cleanup(void)
35 test_return_value = TET_PASS;
40 const char* TEST_IMAGE_FILE_NAME = "gallery_image_01.jpg";
41 const char* TEST_IMAGE_FILE_NAME2 = "gallery_image_02.jpg";
43 void TestImage( ImageView imageView, BufferImage image )
45 Property::Value value = imageView.GetProperty( imageView.GetPropertyIndex( "image" ) );
48 DALI_TEST_CHECK( value.Get( map ) );
50 DALI_TEST_CHECK( map.Find( "width" ) );
51 DALI_TEST_CHECK( map.Find( "height" ) );
52 DALI_TEST_CHECK( map.Find( "type" ) );
55 DALI_TEST_CHECK( map[ "width" ].Get( width ) );
56 DALI_TEST_EQUALS( (unsigned int)width, image.GetWidth(), TEST_LOCATION );
59 DALI_TEST_CHECK( map[ "height" ].Get( height ) );
60 DALI_TEST_EQUALS( (unsigned int)height, image.GetHeight(), TEST_LOCATION );
63 DALI_TEST_CHECK( map[ "type" ].Get( type ) );
64 DALI_TEST_EQUALS( type, "BufferImage", TEST_LOCATION );
67 void TestImage( ImageView imageView, ResourceImage image )
69 Property::Value value = imageView.GetProperty( imageView.GetPropertyIndex( "image" ) );
72 DALI_TEST_CHECK( value.Get( map ) );
74 if( map.Find( "width" ) )
77 DALI_TEST_CHECK( map[ "width" ].Get( width ) );
78 DALI_TEST_EQUALS( (unsigned int)width, image.GetWidth(), TEST_LOCATION );
81 if( map.Find( "height" ) )
84 DALI_TEST_CHECK( map[ "height" ].Get( height ) );
85 DALI_TEST_EQUALS( (unsigned int)height, image.GetHeight(), TEST_LOCATION );
88 DALI_TEST_CHECK( map.Find( "type" ) );
91 DALI_TEST_CHECK( map[ "type" ].Get( type ) );
92 DALI_TEST_EQUALS( type, "ResourceImage", TEST_LOCATION );
95 DALI_TEST_CHECK( map[ "filename" ].Get( filename ) );
96 DALI_TEST_EQUALS( filename, image.GetUrl(), TEST_LOCATION );
99 void TestUrl( ImageView imageView, const std::string url )
101 Property::Value value = imageView.GetProperty( imageView.GetPropertyIndex( "image" ) );
103 std::string urlActual;
104 DALI_TEST_CHECK( value.Get( urlActual ) );
105 DALI_TEST_EQUALS( urlActual, url, TEST_LOCATION );
110 int UtcDaliImageViewNewP(void)
112 TestApplication application;
114 ImageView imageView = ImageView::New();
116 DALI_TEST_CHECK( imageView );
121 int UtcDaliImageViewNewImageP(void)
123 TestApplication application;
125 BufferImage image = CreateBufferImage( 100, 200, Vector4( 1.f, 1.f, 1.f, 1.f ) );
126 ImageView imageView = ImageView::New( image );
128 DALI_TEST_CHECK( imageView );
129 TestImage( imageView, image );
134 int UtcDaliImageViewNewUrlP(void)
136 TestApplication application;
138 ImageView imageView = ImageView::New( TEST_IMAGE_FILE_NAME );
139 DALI_TEST_CHECK( imageView );
141 TestUrl( imageView, TEST_IMAGE_FILE_NAME );
146 int UtcDaliImageViewConstructorP(void)
148 TestApplication application;
152 DALI_TEST_CHECK( !imageView );
157 int UtcDaliImageViewCopyConstructorP(void)
159 TestApplication application;
161 // Initialize an object, ref count == 1
162 ImageView imageView = ImageView::New();
164 ImageView copy( imageView );
165 DALI_TEST_CHECK( copy );
170 int UtcDaliImageViewAssignmentOperatorP(void)
172 TestApplication application;
174 ImageView imageView = ImageView::New();
176 ImageView copy( imageView );
177 DALI_TEST_CHECK( copy );
178 DALI_TEST_EQUALS( imageView, copy, TEST_LOCATION );
183 int UtcDaliImageViewDownCastP(void)
185 TestApplication application;
187 ImageView imageView = ImageView::New();
189 BaseHandle object(imageView);
191 ImageView imageView2 = ImageView::DownCast( object );
192 DALI_TEST_CHECK(imageView2);
194 ImageView imageView3 = DownCast< ImageView >( object );
195 DALI_TEST_CHECK(imageView3);
200 int UtcDaliImageViewDownCastN(void)
202 TestApplication application;
204 BaseHandle unInitializedObject;
206 ImageView imageView1 = ImageView::DownCast( unInitializedObject );
207 DALI_TEST_CHECK( !imageView1 );
209 ImageView imageView2 = DownCast< ImageView >( unInitializedObject );
210 DALI_TEST_CHECK( !imageView2 );
215 int UtcDaliImageViewTypeRegistry(void)
217 ToolkitTestApplication application;
219 TypeRegistry typeRegistry = TypeRegistry::Get();
220 DALI_TEST_CHECK( typeRegistry );
222 TypeInfo typeInfo = typeRegistry.GetTypeInfo( "ImageView" );
223 DALI_TEST_CHECK( typeInfo );
225 BaseHandle handle = typeInfo.CreateInstance();
226 DALI_TEST_CHECK( handle );
228 ImageView imageView = ImageView::DownCast( handle );
229 DALI_TEST_CHECK( imageView );
234 int UtcDaliImageViewSetGetProperty01(void)
236 ToolkitTestApplication application;
238 ImageView imageView = ImageView::New();
240 Property::Index idx = imageView.GetPropertyIndex( "image" );
241 DALI_TEST_EQUALS( idx, (Property::Index)ImageView::Property::IMAGE, TEST_LOCATION );
243 imageView.SetProperty( idx, TEST_IMAGE_FILE_NAME );
244 TestUrl( imageView, TEST_IMAGE_FILE_NAME );
249 int UtcDaliImageViewSetGetProperty02(void)
251 ToolkitTestApplication application;
253 Image image = CreateBufferImage( 10, 10, Color::WHITE );
254 ImageView imageView = ImageView::New(image);
255 Vector4 fullImageRect( 0.f, 0.f, 1.f, 1.f );
257 Stage::GetCurrent().Add( imageView );
259 application.SendNotification();
260 application.Render();
261 TestGlAbstraction& gl = application.GetGlAbstraction();
263 Vector4 pixelAreaUniform;
264 DALI_TEST_CHECK( gl.GetUniformValue<Vector4>( "pixelArea", pixelAreaUniform ) );
265 DALI_TEST_EQUALS( pixelAreaUniform, fullImageRect, TEST_LOCATION );
267 Property::Value value = imageView.GetProperty( ImageView::Property::PIXEL_AREA );
268 Vector4 pixelAreaValue;
269 DALI_TEST_CHECK( value.Get(pixelAreaValue) );
270 DALI_TEST_EQUALS( pixelAreaValue, fullImageRect, TEST_LOCATION );
272 Vector4 pixelAreaSet( 0.2f, 0.2f, 0.3f, 0.3f );
273 imageView.SetProperty( ImageView::Property::PIXEL_AREA, pixelAreaSet);
275 application.SendNotification();
276 application.Render();
278 value = imageView.GetProperty( ImageView::Property::PIXEL_AREA );
279 value.Get(pixelAreaValue);
280 DALI_TEST_EQUALS( pixelAreaValue, pixelAreaSet, TEST_LOCATION );
282 DALI_TEST_CHECK( gl.GetUniformValue<Vector4>( "pixelArea", pixelAreaUniform ) );
283 DALI_TEST_EQUALS( pixelAreaUniform, pixelAreaSet, TEST_LOCATION );
287 int UtcDaliImageViewSizeWithBackground(void)
289 ToolkitTestApplication application;
293 Image image = CreateBufferImage( width, height, Vector4(1.f, 1.f, 1.f, 1.f) );
294 ImageView imageView = ImageView::New();
295 imageView.SetBackgroundImage( image );
297 Stage::GetCurrent().Add( imageView );
298 application.SendNotification();
299 application.Render();
301 DALI_TEST_EQUALS( imageView.GetCurrentSize().width, (float)width, TEST_LOCATION );
302 DALI_TEST_EQUALS( imageView.GetCurrentSize().height, (float)height, TEST_LOCATION );
307 int UtcDaliImageViewSizeWithBackgroundAndImage(void)
309 ToolkitTestApplication application;
311 int widthBackground = 100;
312 int heightBackground = 200;
315 Image imageBackground = CreateBufferImage( widthBackground, heightBackground, Vector4(1.f, 1.f, 1.f, 1.f) );
316 Image image = CreateBufferImage( width, height, Vector4(1.f, 1.f, 1.f, 1.f) );
318 ImageView imageView = ImageView::New();
319 imageView.SetBackgroundImage( imageBackground );
320 imageView.SetImage( image );
322 Stage::GetCurrent().Add( imageView );
323 application.SendNotification();
324 application.Render();
326 DALI_TEST_EQUALS( imageView.GetCurrentSize().width, (float)width, TEST_LOCATION );
327 DALI_TEST_EQUALS( imageView.GetCurrentSize().height, (float)height, TEST_LOCATION );
332 int UtcDaliImageViewHeightForWidthBackground(void)
334 ToolkitTestApplication application;
336 int widthBackground = 100;
337 int heightBackground = 200;
338 Image imageBackground = CreateBufferImage( widthBackground, heightBackground, Vector4(1.f, 1.f, 1.f, 1.f) );
340 ImageView imageView = ImageView::New();
341 imageView.SetBackgroundImage( imageBackground );
343 Stage::GetCurrent().Add( imageView );
344 application.SendNotification();
345 application.Render();
347 Control control = Control::DownCast( imageView );
348 DALI_TEST_CHECK( control );
349 DALI_TEST_EQUALS( imageView.GetHeightForWidth( 123.f ), control.GetHeightForWidth( 123.f ), TEST_LOCATION );
350 DALI_TEST_EQUALS( imageView.GetWidthForHeight( 321.f ), control.GetWidthForHeight( 321.f ), TEST_LOCATION );
355 int UtcDaliImageViewHeightForWidthBackgroundAndImage(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.GetHeightForWidth( width ), (float)height, TEST_LOCATION );
375 DALI_TEST_EQUALS( imageView.GetWidthForHeight( height ), (float)width, TEST_LOCATION );
380 int UtcDaliImageViewSetBufferImage(void)
382 ToolkitTestApplication application;
386 BufferImage image1 = CreateBufferImage( width1, height1, Vector4( 1.f, 1.f, 1.f, 1.f ) );
387 ImageView imageView = ImageView::New();
388 imageView.SetImage( image1 );
390 TestImage( imageView, image1 );
394 BufferImage image2 = CreateBufferImage( width2, height2, Vector4( 1.f, 1.f, 1.f, 1.f ) );
395 imageView.SetImage( image2 );
397 TestImage( imageView, image2 );
402 int UtcDaliImageViewSetImageUrl(void)
404 ToolkitTestApplication application;
406 ImageView imageView = ImageView::New();
407 imageView.SetImage( TEST_IMAGE_FILE_NAME );
408 TestUrl( imageView, TEST_IMAGE_FILE_NAME );
411 imageView.SetImage( TEST_IMAGE_FILE_NAME2 );
412 TestUrl( imageView, TEST_IMAGE_FILE_NAME2 );
417 int UtcDaliImageViewSetImageOnstageP(void)
419 ToolkitTestApplication application;
421 ImageView imageView = ImageView::New();
423 Stage::GetCurrent().Add( imageView );
424 application.SendNotification();
425 application.Render();
427 ResourceImage image1 = ResourceImage::New( TEST_IMAGE_FILE_NAME );
428 imageView.SetImage( image1 );
429 TestImage( imageView, image1 );
433 BufferImage image2 = CreateBufferImage( width, height, Vector4( 1.f, 1.f, 1.f, 1.f ) );
434 imageView.SetImage( image2 );
435 TestImage( imageView, image2 );
440 int UtcDaliImageViewSetImageOnstageN(void)
442 ToolkitTestApplication application;
444 ImageView imageView = ImageView::New();
446 Stage::GetCurrent().Add( imageView );
447 application.SendNotification();
448 application.Render();
450 ResourceImage image1 = ResourceImage::New( TEST_IMAGE_FILE_NAME );
451 imageView.SetImage( image1 );
452 TestImage( imageView, image1 );
455 imageView.SetImage( image2 );
457 Property::Value value = imageView.GetProperty( imageView.GetPropertyIndex( "image" ) );
459 //the value should be empty
461 DALI_TEST_CHECK( !value.Get( url ) );
464 DALI_TEST_CHECK( !value.Get( map ) );
469 int UtcDaliImageViewSetImageOffstageP(void)
471 ToolkitTestApplication application;
473 ImageView imageView = ImageView::New();
475 Stage::GetCurrent().Add( imageView );
476 application.SendNotification();
477 application.Render();
478 Stage::GetCurrent().Remove( imageView );
480 ResourceImage image1 = ResourceImage::New( TEST_IMAGE_FILE_NAME );
481 imageView.SetImage( image1 );
482 TestImage( imageView, image1 );
486 BufferImage image2 = CreateBufferImage( width, height, Vector4( 1.f, 1.f, 1.f, 1.f ) );
487 imageView.SetImage( image2 );
488 TestImage( imageView, image2 );
493 int UtcDaliImageViewSetImageOffstageN(void)
495 ToolkitTestApplication application;
497 ImageView imageView = ImageView::New();
499 Stage::GetCurrent().Add( imageView );
500 application.SendNotification();
501 application.Render();
502 Stage::GetCurrent().Remove( imageView );
504 ResourceImage image1 = ResourceImage::New( TEST_IMAGE_FILE_NAME );
505 imageView.SetImage( image1 );
506 TestImage( imageView, image1 );
509 imageView.SetImage( image2 );
511 Property::Value value = imageView.GetProperty( imageView.GetPropertyIndex( "image" ) );
513 //the value should be empty
515 DALI_TEST_CHECK( !value.Get( url ) );
518 DALI_TEST_CHECK( !value.Get( map ) );
523 int UtcDaliImageViewSetImageN(void)
525 ToolkitTestApplication application;
528 ImageView imageView = ImageView::New();
529 imageView.SetImage( image1 );
531 Property::Value value = imageView.GetProperty( imageView.GetPropertyIndex( "image" ) );
533 //the value should be empty
535 DALI_TEST_CHECK( !value.Get( url ) );
538 DALI_TEST_CHECK( !value.Get( map ) );
540 std::string resource_url;
541 Property::Value val = imageView.GetProperty( imageView.GetPropertyIndex( "image" ) );
542 DALI_TEST_CHECK( !val.Get( resource_url ) );
547 int UtcDaliImageViewSetImageTypeChangesP(void)
549 ToolkitTestApplication application;
551 ImageView imageView = ImageView::New();
557 Property::Value value = imageView.GetProperty( imageView.GetPropertyIndex( "image" ) );
558 DALI_TEST_CHECK( ! value.Get( url ) ); // Value should be empty
559 DALI_TEST_CHECK( ! value.Get( map ) ); // Value should be empty
562 imageView.SetImage( "TEST_URL" );
563 value = imageView.GetProperty( imageView.GetPropertyIndex( "image" ) );
565 DALI_TEST_CHECK( value.Get( url ) ); // Value should NOT be empty
566 DALI_TEST_CHECK( ! value.Get( map ) ); // Value should be empty
568 // Set an empty Image
569 imageView.SetImage( Image() );
570 value = imageView.GetProperty( imageView.GetPropertyIndex( "image" ) );
572 DALI_TEST_CHECK( ! value.Get( url ) ); // Value should be empty
573 DALI_TEST_CHECK( ! value.Get( map ) ); // Value should be empty
576 ResourceImage image1 = ResourceImage::New( TEST_IMAGE_FILE_NAME );
577 imageView.SetImage( image1 );
578 value = imageView.GetProperty( imageView.GetPropertyIndex( "image" ) );
580 DALI_TEST_CHECK( ! value.Get( url ) ); // Value should be empty
581 DALI_TEST_CHECK( value.Get( map ) ); // Value should NOT be empty
584 imageView.SetImage( "" );
585 value = imageView.GetProperty( imageView.GetPropertyIndex( "image" ) );
587 DALI_TEST_CHECK( ! value.Get( url ) ); // Value should be empty
588 DALI_TEST_CHECK( ! value.Get( map ) ); // Value should be empty
593 int UtcDaliImageViewResourceUrlP(void)
595 ToolkitTestApplication application;
597 ImageView imageView = ImageView::New();
598 DALI_TEST_CHECK( imageView.GetProperty( ImageView::Property::RESOURCE_URL ).Get< std::string >().empty() );
600 imageView.SetProperty( ImageView::Property::RESOURCE_URL, "TestString" );
601 DALI_TEST_EQUALS( imageView.GetProperty( ImageView::Property::RESOURCE_URL ).Get< std::string >(), "TestString", TEST_LOCATION );