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 UtcDaliImageViewSizeWithBackground(void)
251 ToolkitTestApplication application;
255 Image image = CreateBufferImage( width, height, Vector4(1.f, 1.f, 1.f, 1.f) );
256 ImageView imageView = ImageView::New();
257 imageView.SetBackgroundImage( image );
259 Stage::GetCurrent().Add( imageView );
260 application.SendNotification();
261 application.Render();
263 DALI_TEST_EQUALS( imageView.GetCurrentSize().width, (float)width, TEST_LOCATION );
264 DALI_TEST_EQUALS( imageView.GetCurrentSize().height, (float)height, TEST_LOCATION );
269 int UtcDaliImageViewSizeWithBackgroundAndImage(void)
271 ToolkitTestApplication application;
273 int widthBackground = 100;
274 int heightBackground = 200;
277 Image imageBackground = CreateBufferImage( widthBackground, heightBackground, Vector4(1.f, 1.f, 1.f, 1.f) );
278 Image image = CreateBufferImage( width, height, Vector4(1.f, 1.f, 1.f, 1.f) );
280 ImageView imageView = ImageView::New();
281 imageView.SetBackgroundImage( imageBackground );
282 imageView.SetImage( image );
284 Stage::GetCurrent().Add( imageView );
285 application.SendNotification();
286 application.Render();
288 DALI_TEST_EQUALS( imageView.GetCurrentSize().width, (float)width, TEST_LOCATION );
289 DALI_TEST_EQUALS( imageView.GetCurrentSize().height, (float)height, TEST_LOCATION );
294 int UtcDaliImageViewHeightForWidthBackground(void)
296 ToolkitTestApplication application;
298 int widthBackground = 100;
299 int heightBackground = 200;
300 Image imageBackground = CreateBufferImage( widthBackground, heightBackground, Vector4(1.f, 1.f, 1.f, 1.f) );
302 ImageView imageView = ImageView::New();
303 imageView.SetBackgroundImage( imageBackground );
305 Stage::GetCurrent().Add( imageView );
306 application.SendNotification();
307 application.Render();
309 Control control = Control::DownCast( imageView );
310 DALI_TEST_CHECK( control );
311 DALI_TEST_EQUALS( imageView.GetHeightForWidth( 123.f ), control.GetHeightForWidth( 123.f ), TEST_LOCATION );
312 DALI_TEST_EQUALS( imageView.GetWidthForHeight( 321.f ), control.GetWidthForHeight( 321.f ), TEST_LOCATION );
317 int UtcDaliImageViewHeightForWidthBackgroundAndImage(void)
319 ToolkitTestApplication application;
321 int widthBackground = 100;
322 int heightBackground = 200;
325 Image imageBackground = CreateBufferImage( widthBackground, heightBackground, Vector4(1.f, 1.f, 1.f, 1.f) );
326 Image image = CreateBufferImage( width, height, Vector4(1.f, 1.f, 1.f, 1.f) );
328 ImageView imageView = ImageView::New();
329 imageView.SetBackgroundImage( imageBackground );
330 imageView.SetImage( image );
332 Stage::GetCurrent().Add( imageView );
333 application.SendNotification();
334 application.Render();
336 DALI_TEST_EQUALS( imageView.GetHeightForWidth( width ), (float)height, TEST_LOCATION );
337 DALI_TEST_EQUALS( imageView.GetWidthForHeight( height ), (float)width, TEST_LOCATION );
342 int UtcDaliImageViewSetBufferImage(void)
344 ToolkitTestApplication application;
348 BufferImage image1 = CreateBufferImage( width1, height1, Vector4( 1.f, 1.f, 1.f, 1.f ) );
349 ImageView imageView = ImageView::New();
350 imageView.SetImage( image1 );
352 TestImage( imageView, image1 );
356 BufferImage image2 = CreateBufferImage( width2, height2, Vector4( 1.f, 1.f, 1.f, 1.f ) );
357 imageView.SetImage( image2 );
359 TestImage( imageView, image2 );
364 int UtcDaliImageViewSetImageUrl(void)
366 ToolkitTestApplication application;
368 ImageView imageView = ImageView::New();
369 imageView.SetImage( TEST_IMAGE_FILE_NAME );
370 TestUrl( imageView, TEST_IMAGE_FILE_NAME );
373 imageView.SetImage( TEST_IMAGE_FILE_NAME2 );
374 TestUrl( imageView, TEST_IMAGE_FILE_NAME2 );
379 int UtcDaliImageViewSetImageOnstageP(void)
381 ToolkitTestApplication application;
383 ImageView imageView = ImageView::New();
385 Stage::GetCurrent().Add( imageView );
386 application.SendNotification();
387 application.Render();
389 ResourceImage image1 = ResourceImage::New( TEST_IMAGE_FILE_NAME );
390 imageView.SetImage( image1 );
391 TestImage( imageView, image1 );
395 BufferImage image2 = CreateBufferImage( width, height, Vector4( 1.f, 1.f, 1.f, 1.f ) );
396 imageView.SetImage( image2 );
397 TestImage( imageView, image2 );
402 int UtcDaliImageViewSetImageOnstageN(void)
404 ToolkitTestApplication application;
406 ImageView imageView = ImageView::New();
408 Stage::GetCurrent().Add( imageView );
409 application.SendNotification();
410 application.Render();
412 ResourceImage image1 = ResourceImage::New( TEST_IMAGE_FILE_NAME );
413 imageView.SetImage( image1 );
414 TestImage( imageView, image1 );
417 imageView.SetImage( image2 );
419 Property::Value value = imageView.GetProperty( imageView.GetPropertyIndex( "image" ) );
421 //the value should be empty
423 DALI_TEST_CHECK( !value.Get( url ) );
426 DALI_TEST_CHECK( !value.Get( map ) );
431 int UtcDaliImageViewSetImageOffstageP(void)
433 ToolkitTestApplication application;
435 ImageView imageView = ImageView::New();
437 Stage::GetCurrent().Add( imageView );
438 application.SendNotification();
439 application.Render();
440 Stage::GetCurrent().Remove( imageView );
442 ResourceImage image1 = ResourceImage::New( TEST_IMAGE_FILE_NAME );
443 imageView.SetImage( image1 );
444 TestImage( imageView, image1 );
448 BufferImage image2 = CreateBufferImage( width, height, Vector4( 1.f, 1.f, 1.f, 1.f ) );
449 imageView.SetImage( image2 );
450 TestImage( imageView, image2 );
455 int UtcDaliImageViewSetImageOffstageN(void)
457 ToolkitTestApplication application;
459 ImageView imageView = ImageView::New();
461 Stage::GetCurrent().Add( imageView );
462 application.SendNotification();
463 application.Render();
464 Stage::GetCurrent().Remove( imageView );
466 ResourceImage image1 = ResourceImage::New( TEST_IMAGE_FILE_NAME );
467 imageView.SetImage( image1 );
468 TestImage( imageView, image1 );
471 imageView.SetImage( image2 );
473 Property::Value value = imageView.GetProperty( imageView.GetPropertyIndex( "image" ) );
475 //the value should be empty
477 DALI_TEST_CHECK( !value.Get( url ) );
480 DALI_TEST_CHECK( !value.Get( map ) );
485 int UtcDaliImageViewSetImageN(void)
487 ToolkitTestApplication application;
490 ImageView imageView = ImageView::New();
491 imageView.SetImage( image1 );
493 Property::Value value = imageView.GetProperty( imageView.GetPropertyIndex( "image" ) );
495 //the value should be empty
497 DALI_TEST_CHECK( !value.Get( url ) );
500 DALI_TEST_CHECK( !value.Get( map ) );
502 std::string resource_url;
503 Property::Value val = imageView.GetProperty( imageView.GetPropertyIndex( "image" ) );
504 DALI_TEST_CHECK( !val.Get( resource_url ) );
509 int UtcDaliImageViewSetImageTypeChangesP(void)
511 ToolkitTestApplication application;
513 ImageView imageView = ImageView::New();
519 Property::Value value = imageView.GetProperty( imageView.GetPropertyIndex( "image" ) );
520 DALI_TEST_CHECK( ! value.Get( url ) ); // Value should be empty
521 DALI_TEST_CHECK( ! value.Get( map ) ); // Value should be empty
524 imageView.SetImage( "TEST_URL" );
525 value = imageView.GetProperty( imageView.GetPropertyIndex( "image" ) );
527 DALI_TEST_CHECK( value.Get( url ) ); // Value should NOT be empty
528 DALI_TEST_CHECK( ! value.Get( map ) ); // Value should be empty
530 // Set an empty Image
531 imageView.SetImage( Image() );
532 value = imageView.GetProperty( imageView.GetPropertyIndex( "image" ) );
534 DALI_TEST_CHECK( ! value.Get( url ) ); // Value should be empty
535 DALI_TEST_CHECK( ! value.Get( map ) ); // Value should be empty
538 ResourceImage image1 = ResourceImage::New( TEST_IMAGE_FILE_NAME );
539 imageView.SetImage( image1 );
540 value = imageView.GetProperty( imageView.GetPropertyIndex( "image" ) );
542 DALI_TEST_CHECK( ! value.Get( url ) ); // Value should be empty
543 DALI_TEST_CHECK( value.Get( map ) ); // Value should NOT be empty
546 imageView.SetImage( "" );
547 value = imageView.GetProperty( imageView.GetPropertyIndex( "image" ) );
549 DALI_TEST_CHECK( ! value.Get( url ) ); // Value should be empty
550 DALI_TEST_CHECK( ! value.Get( map ) ); // Value should be empty
555 int UtcDaliImageViewResourceUrlP(void)
557 ToolkitTestApplication application;
559 ImageView imageView = ImageView::New();
560 DALI_TEST_CHECK( imageView.GetProperty( ImageView::Property::RESOURCE_URL ).Get< std::string >().empty() );
562 imageView.SetProperty( ImageView::Property::RESOURCE_URL, "TestString" );
563 DALI_TEST_EQUALS( imageView.GetProperty( ImageView::Property::RESOURCE_URL ).Get< std::string >(), "TestString", TEST_LOCATION );