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>
25 using namespace Toolkit;
27 void utc_dali_toolkit_image_view_startup(void)
29 test_return_value = TET_UNDEF;
32 void utc_dali_toolkit_image_view_cleanup(void)
34 test_return_value = TET_PASS;
39 const char* TEST_IMAGE_FILE_NAME = "gallery_image_01.jpg";
42 int UtcDaliImageViewNewP(void)
44 TestApplication application;
46 ImageView imageView = ImageView::New();
48 DALI_TEST_CHECK( imageView );
53 int UtcDaliImageViewNewImageP(void)
55 TestApplication application;
57 Image image = CreateBufferImage( 100, 200, Vector4( 1.f, 1.f, 1.f, 1.f ) );
58 ImageView imageView = ImageView::New( image );
60 DALI_TEST_CHECK( imageView );
61 DALI_TEST_EQUALS( image, imageView.GetImage(), TEST_LOCATION );
66 int UtcDaliImageViewNewUrlP(void)
68 TestApplication application;
70 ImageView imageView = ImageView::New( TEST_IMAGE_FILE_NAME );
71 DALI_TEST_CHECK( imageView );
72 DALI_TEST_CHECK( imageView.GetImage() );
74 Property::Value val = imageView.GetProperty( imageView.GetPropertyIndex( "resource-url" ) );
75 std::string resource_url;
76 DALI_TEST_CHECK( val.Get( resource_url ) );
77 DALI_TEST_EQUALS( resource_url, TEST_IMAGE_FILE_NAME, TEST_LOCATION );
79 Image image = imageView.GetImage();
80 DALI_TEST_CHECK( image );
82 ResourceImage resourceImage = ResourceImage::DownCast( image );
83 DALI_TEST_CHECK( resourceImage );
84 DALI_TEST_EQUALS( resourceImage.GetUrl(), TEST_IMAGE_FILE_NAME, TEST_LOCATION );
89 int UtcDaliImageViewConstructorP(void)
91 TestApplication application;
95 DALI_TEST_CHECK( !imageView );
100 int UtcDaliImageViewCopyConstructorP(void)
102 TestApplication application;
104 // Initialize an object, ref count == 1
105 ImageView imageView = ImageView::New();
107 ImageView copy( imageView );
108 DALI_TEST_CHECK( copy );
113 int UtcDaliImageViewAssignmentOperatorP(void)
115 TestApplication application;
117 ImageView imageView = ImageView::New();
119 ImageView copy( imageView );
120 DALI_TEST_CHECK( copy );
121 DALI_TEST_EQUALS( imageView, copy, TEST_LOCATION );
126 int UtcDaliImageViewDownCastP(void)
128 TestApplication application;
130 ImageView imageView = ImageView::New();
132 BaseHandle object(imageView);
134 ImageView imageView2 = ImageView::DownCast( object );
135 DALI_TEST_CHECK(imageView2);
137 ImageView imageView3 = DownCast< ImageView >( object );
138 DALI_TEST_CHECK(imageView3);
143 int UtcDaliImageViewDownCastN(void)
145 TestApplication application;
147 BaseHandle unInitializedObject;
149 ImageView imageView1 = ImageView::DownCast( unInitializedObject );
150 DALI_TEST_CHECK( !imageView1 );
152 ImageView imageView2 = DownCast< ImageView >( unInitializedObject );
153 DALI_TEST_CHECK( !imageView2 );
158 int UtcDaliImageViewTypeRegistry(void)
160 ToolkitTestApplication application;
162 TypeRegistry typeRegistry = TypeRegistry::Get();
163 DALI_TEST_CHECK( typeRegistry );
165 TypeInfo typeInfo = typeRegistry.GetTypeInfo( "ImageView" );
166 DALI_TEST_CHECK( typeInfo );
168 BaseHandle handle = typeInfo.CreateInstance();
169 DALI_TEST_CHECK( handle );
171 ImageView imageView = ImageView::DownCast( handle );
172 DALI_TEST_CHECK( imageView );
177 int UtcDaliImageViewSetGetProperty(void)
179 ToolkitTestApplication application;
181 ImageView imageView = ImageView::New();
183 Property::Index idx = imageView.GetPropertyIndex( "resource-url" );
184 DALI_TEST_EQUALS( idx, ImageView::Property::RESOURCE_URL, TEST_LOCATION );
186 imageView.SetProperty( idx, TEST_IMAGE_FILE_NAME );
187 Property::Value val = imageView.GetProperty( idx );
188 std::string resource_url;
189 DALI_TEST_CHECK( val.Get( resource_url ) );
190 DALI_TEST_EQUALS( resource_url, TEST_IMAGE_FILE_NAME, TEST_LOCATION );
192 Image image = imageView.GetImage();
193 DALI_TEST_CHECK( image );
195 ResourceImage resourceImage = ResourceImage::DownCast( image );
196 DALI_TEST_CHECK( resourceImage );
197 DALI_TEST_EQUALS( resourceImage.GetUrl(), TEST_IMAGE_FILE_NAME, TEST_LOCATION );
202 int UtcDaliImageViewSizeWithBackground(void)
204 ToolkitTestApplication application;
208 Image image = CreateBufferImage( width, height, Vector4(1.f, 1.f, 1.f, 1.f) );
209 ImageView imageView = ImageView::New();
210 imageView.SetBackgroundImage( image );
212 Stage::GetCurrent().Add( imageView );
213 application.SendNotification();
214 application.Render();
216 DALI_TEST_EQUALS( imageView.GetCurrentSize().width, width, TEST_LOCATION );
217 DALI_TEST_EQUALS( imageView.GetCurrentSize().height, height, TEST_LOCATION );
222 int UtcDaliImageViewSizeWithBackgroundAndImage(void)
224 ToolkitTestApplication application;
226 int widthBackground = 100;
227 int heightBackground = 200;
230 Image imageBackground = CreateBufferImage( widthBackground, heightBackground, Vector4(1.f, 1.f, 1.f, 1.f) );
231 Image image = CreateBufferImage( width, height, Vector4(1.f, 1.f, 1.f, 1.f) );
233 ImageView imageView = ImageView::New();
234 imageView.SetBackgroundImage( imageBackground );
235 imageView.SetImage( image );
237 Stage::GetCurrent().Add( imageView );
238 application.SendNotification();
239 application.Render();
241 DALI_TEST_EQUALS( imageView.GetCurrentSize().width, width, TEST_LOCATION );
242 DALI_TEST_EQUALS( imageView.GetCurrentSize().height, height, TEST_LOCATION );
247 int UtcDaliImageViewHeightForWidthBackground(void)
249 ToolkitTestApplication application;
251 int widthBackground = 100;
252 int heightBackground = 200;
253 Image imageBackground = CreateBufferImage( widthBackground, heightBackground, Vector4(1.f, 1.f, 1.f, 1.f) );
255 ImageView imageView = ImageView::New();
256 imageView.SetBackgroundImage( imageBackground );
258 Stage::GetCurrent().Add( imageView );
259 application.SendNotification();
260 application.Render();
262 Control control = Control::DownCast( imageView );
263 DALI_TEST_CHECK( control );
264 DALI_TEST_EQUALS( imageView.GetHeightForWidth( 123.f ), control.GetHeightForWidth( 123.f ), TEST_LOCATION );
265 DALI_TEST_EQUALS( imageView.GetWidthForHeight( 321.f ), control.GetWidthForHeight( 321.f ), TEST_LOCATION );
270 int UtcDaliImageViewHeightForWidthBackgroundAndImage(void)
272 ToolkitTestApplication application;
274 int widthBackground = 100;
275 int heightBackground = 200;
278 Image imageBackground = CreateBufferImage( widthBackground, heightBackground, Vector4(1.f, 1.f, 1.f, 1.f) );
279 Image image = CreateBufferImage( width, height, Vector4(1.f, 1.f, 1.f, 1.f) );
281 ImageView imageView = ImageView::New();
282 imageView.SetBackgroundImage( imageBackground );
283 imageView.SetImage( image );
285 Stage::GetCurrent().Add( imageView );
286 application.SendNotification();
287 application.Render();
289 DALI_TEST_EQUALS( imageView.GetHeightForWidth( width ), height, TEST_LOCATION );
290 DALI_TEST_EQUALS( imageView.GetWidthForHeight( height ), width, TEST_LOCATION );
295 int UtcDaliImageViewSetBufferImage(void)
297 ToolkitTestApplication application;
301 Image image = CreateBufferImage( width, height, Vector4( 1.f, 1.f, 1.f, 1.f ) );
302 ImageView imageView = ImageView::New();
303 imageView.SetImage( image );
305 std::string resource_url;
306 Property::Value val = imageView.GetProperty( imageView.GetPropertyIndex( "resource-url" ) );
307 DALI_TEST_CHECK( val.Get( resource_url ) );
308 DALI_TEST_CHECK( resource_url.empty() );
313 int UtcDaliImageViewSetResourceImage(void)
315 ToolkitTestApplication application;
317 Image image = ResourceImage::New( TEST_IMAGE_FILE_NAME );
318 ImageView imageView = ImageView::New();
319 imageView.SetImage( image );
321 std::string resource_url;
322 Property::Value val = imageView.GetProperty( imageView.GetPropertyIndex( "resource-url" ) );
323 DALI_TEST_CHECK( val.Get( resource_url ) );
324 DALI_TEST_EQUALS( resource_url, TEST_IMAGE_FILE_NAME, TEST_LOCATION );
329 int UtcDaliImageViewSetImageOnstageP(void)
331 ToolkitTestApplication application;
333 ImageView imageView = ImageView::New();
335 Stage::GetCurrent().Add( imageView );
336 application.SendNotification();
337 application.Render();
339 Image image1 = ResourceImage::New( TEST_IMAGE_FILE_NAME );
340 imageView.SetImage( image1 );
342 Image image2 = imageView.GetImage();
343 DALI_TEST_EQUALS( image1, image2, TEST_LOCATION );
347 Image image3 = CreateBufferImage( width, height, Vector4( 1.f, 1.f, 1.f, 1.f ) );
348 imageView.SetImage( image3 );
350 Image image4 = imageView.GetImage();
351 DALI_TEST_EQUALS( image3, image4, TEST_LOCATION );
356 int UtcDaliImageViewSetImageOnstageN(void)
358 ToolkitTestApplication application;
360 ImageView imageView = ImageView::New();
362 Stage::GetCurrent().Add( imageView );
363 application.SendNotification();
364 application.Render();
366 Image image1 = ResourceImage::New( TEST_IMAGE_FILE_NAME );
367 imageView.SetImage( image1 );
369 Image image2 = imageView.GetImage();
370 DALI_TEST_EQUALS( image1, image2, TEST_LOCATION );
373 imageView.SetImage( image3 );
375 Image image4 = imageView.GetImage();
376 DALI_TEST_CHECK( !image4 );
381 int UtcDaliImageViewSetImageOffstageP(void)
383 ToolkitTestApplication application;
385 ImageView imageView = ImageView::New();
387 Stage::GetCurrent().Add( imageView );
388 application.SendNotification();
389 application.Render();
390 Stage::GetCurrent().Remove( imageView );
392 Image image1 = ResourceImage::New( TEST_IMAGE_FILE_NAME );
393 imageView.SetImage( image1 );
395 Image image2 = imageView.GetImage();
396 DALI_TEST_EQUALS( image1, image2, TEST_LOCATION );
400 Image image3 = CreateBufferImage( width, height, Vector4( 1.f, 1.f, 1.f, 1.f ) );
401 imageView.SetImage( image3 );
403 Image image4 = imageView.GetImage();
404 DALI_TEST_EQUALS( image3, image4, TEST_LOCATION );
409 int UtcDaliImageViewSetImageOffstageN(void)
411 ToolkitTestApplication application;
413 ImageView imageView = ImageView::New();
415 Stage::GetCurrent().Add( imageView );
416 application.SendNotification();
417 application.Render();
418 Stage::GetCurrent().Remove( imageView );
420 Image image1 = ResourceImage::New( TEST_IMAGE_FILE_NAME );
421 imageView.SetImage( image1 );
423 Image image2 = imageView.GetImage();
424 DALI_TEST_EQUALS( image1, image2, TEST_LOCATION );
427 imageView.SetImage( image3 );
429 Image image4 = imageView.GetImage();
430 DALI_TEST_CHECK( !image4 );
435 int UtcDaliImageViewSetImageN(void)
437 ToolkitTestApplication application;
440 ImageView imageView = ImageView::New();
441 imageView.SetImage( image1 );
443 Image image2 = imageView.GetImage();
444 DALI_TEST_CHECK( !image2 );
446 std::string resource_url;
447 Property::Value val = imageView.GetProperty( imageView.GetPropertyIndex( "resource-url" ) );
448 DALI_TEST_CHECK( val.Get( resource_url ) );
449 DALI_TEST_CHECK( resource_url.empty() );