2 * Copyright (c) 2022 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.
21 // Need to override adaptor classes for toolkit test harness, so include
22 // test harness headers before dali headers.
24 #include <dali-toolkit-test-suite-utils.h>
25 #include <toolkit-event-thread-callback.h>
26 #include <toolkit-vector-image-renderer.h>
27 #include "dummy-control.h"
29 #include <test-encoded-image-buffer.h>
30 #include <test-native-image.h>
32 #include <dali-toolkit/dali-toolkit.h>
33 #include <dali-toolkit/devel-api/controls/control-devel.h>
34 #include <dali-toolkit/devel-api/image-loader/texture-manager.h>
35 #include <dali-toolkit/devel-api/styling/style-manager-devel.h>
36 #include <dali-toolkit/devel-api/visual-factory/visual-base.h>
37 #include <dali-toolkit/devel-api/visuals/animated-image-visual-actions-devel.h>
38 #include <dali-toolkit/devel-api/visuals/image-visual-actions-devel.h>
39 #include <dali-toolkit/devel-api/visuals/image-visual-properties-devel.h>
40 #include <dali-toolkit/devel-api/visuals/visual-properties-devel.h>
41 #include <dali-toolkit/public-api/image-loader/image-url.h>
42 #include <dali-toolkit/public-api/image-loader/image.h>
43 #include <dali/devel-api/scripting/scripting.h>
46 using namespace Toolkit;
48 void utc_dali_toolkit_image_view_startup(void)
50 test_return_value = TET_UNDEF;
53 void utc_dali_toolkit_image_view_cleanup(void)
55 test_return_value = TET_PASS;
60 const char* TEST_IMAGE_FILE_NAME = "gallery_image_01.jpg";
61 const char* TEST_IMAGE_FILE_NAME2 = "gallery_image_02.jpg";
63 // resolution: 1024*1024
64 const char* TEST_IMAGE_1 = TEST_RESOURCE_DIR "/TB-gloss.png";
65 const char* TEST_IMAGE_2 = TEST_RESOURCE_DIR "/tb-norm.png";
67 const char* TEST_BROKEN_IMAGE_DEFAULT = TEST_RESOURCE_DIR "/broken.png";
68 const char* TEST_BROKEN_IMAGE_S = TEST_RESOURCE_DIR "/broken_s.9.png";
69 const char* TEST_BROKEN_IMAGE_M = TEST_RESOURCE_DIR "/broken_m.9.png";
70 const char* TEST_BROKEN_IMAGE_L = TEST_RESOURCE_DIR "/broken_l.9.png";
71 const char* TEST_BROKEN_IMAGE_01 = TEST_RESOURCE_DIR "/button-up.9.png";
72 const char* TEST_BROKEN_IMAGE_02 = TEST_RESOURCE_DIR "/heartsframe.9.png";
74 // resolution: 34*34, pixel format: RGBA8888
75 static const char* gImage_34_RGBA = TEST_RESOURCE_DIR "/icon-edit.png";
76 // resolution: 600*600, pixel format: RGB888
77 static const char* gImage_600_RGB = TEST_RESOURCE_DIR "/test-image-600.jpg";
79 // resolution: 50*50, frame count: 4, frame delay: 0.2 second for each frame
80 const char* TEST_GIF_FILE_NAME = TEST_RESOURCE_DIR "/anim.gif";
82 const char* TEST_SVG_FILE_NAME = TEST_RESOURCE_DIR "/svg1.svg";
83 const char* TEST_ANIMATED_VECTOR_IMAGE_FILE_NAME = TEST_RESOURCE_DIR "/insta_camera.json";
84 const char* TEST_WEBP_FILE_NAME = TEST_RESOURCE_DIR "/dali-logo.webp";
86 void TestUrl(ImageView imageView, const std::string url)
88 Property::Value value = imageView.GetProperty(imageView.GetPropertyIndex("image"));
90 std::string urlActual;
91 DALI_TEST_CHECK(value.Get(urlActual));
92 DALI_TEST_EQUALS(urlActual, url, TEST_LOCATION);
97 int UtcDaliImageViewNewP(void)
99 ToolkitTestApplication application;
101 ImageView imageView = ImageView::New();
103 DALI_TEST_CHECK(imageView);
108 int UtcDaliImageViewNewUrlP(void)
110 ToolkitTestApplication application;
112 ImageView imageView = ImageView::New(TEST_IMAGE_FILE_NAME);
113 DALI_TEST_CHECK(imageView);
115 TestUrl(imageView, TEST_IMAGE_FILE_NAME);
120 int UtcDaliImageViewConstructorP(void)
122 ToolkitTestApplication application;
126 DALI_TEST_CHECK(!imageView);
131 int UtcDaliImageViewCopyConstructorP(void)
133 ToolkitTestApplication application;
135 // Initialize an object, ref count == 1
136 ImageView imageView = ImageView::New();
138 ImageView copy(imageView);
139 DALI_TEST_CHECK(copy);
144 int UtcDaliImageViewMoveConstructor(void)
146 ToolkitTestApplication application;
148 ImageView imageView = ImageView::New();
149 DALI_TEST_EQUALS(1, imageView.GetBaseObject().ReferenceCount(), TEST_LOCATION);
150 imageView.SetProperty(Actor::Property::SENSITIVE, false);
151 DALI_TEST_CHECK(false == imageView.GetProperty<bool>(Actor::Property::SENSITIVE));
153 ImageView moved = std::move(imageView);
154 DALI_TEST_CHECK(moved);
155 DALI_TEST_EQUALS(1, moved.GetBaseObject().ReferenceCount(), TEST_LOCATION);
156 DALI_TEST_CHECK(false == moved.GetProperty<bool>(Actor::Property::SENSITIVE));
157 DALI_TEST_CHECK(!imageView);
162 int UtcDaliImageViewAssignmentOperatorP(void)
164 ToolkitTestApplication application;
166 ImageView imageView = ImageView::New();
168 ImageView copy(imageView);
169 DALI_TEST_CHECK(copy);
170 DALI_TEST_EQUALS(imageView, copy, TEST_LOCATION);
175 int UtcDaliImageViewMoveAssignment(void)
177 ToolkitTestApplication application;
179 ImageView imageView = ImageView::New();
180 DALI_TEST_EQUALS(1, imageView.GetBaseObject().ReferenceCount(), TEST_LOCATION);
181 imageView.SetProperty(Actor::Property::SENSITIVE, false);
182 DALI_TEST_CHECK(false == imageView.GetProperty<bool>(Actor::Property::SENSITIVE));
185 moved = std::move(imageView);
186 DALI_TEST_CHECK(moved);
187 DALI_TEST_EQUALS(1, moved.GetBaseObject().ReferenceCount(), TEST_LOCATION);
188 DALI_TEST_CHECK(false == moved.GetProperty<bool>(Actor::Property::SENSITIVE));
189 DALI_TEST_CHECK(!imageView);
194 int UtcDaliImageViewDownCastP(void)
196 ToolkitTestApplication application;
198 ImageView imageView = ImageView::New();
200 BaseHandle object(imageView);
202 ImageView imageView2 = ImageView::DownCast(object);
203 DALI_TEST_CHECK(imageView2);
205 ImageView imageView3 = DownCast<ImageView>(object);
206 DALI_TEST_CHECK(imageView3);
211 int UtcDaliImageViewDownCastN(void)
213 ToolkitTestApplication application;
215 BaseHandle unInitializedObject;
217 ImageView imageView1 = ImageView::DownCast(unInitializedObject);
218 DALI_TEST_CHECK(!imageView1);
220 ImageView imageView2 = DownCast<ImageView>(unInitializedObject);
221 DALI_TEST_CHECK(!imageView2);
226 int UtcDaliImageViewTypeRegistry(void)
228 ToolkitTestApplication application;
230 TypeRegistry typeRegistry = TypeRegistry::Get();
231 DALI_TEST_CHECK(typeRegistry);
233 TypeInfo typeInfo = typeRegistry.GetTypeInfo("ImageView");
234 DALI_TEST_CHECK(typeInfo);
236 BaseHandle handle = typeInfo.CreateInstance();
237 DALI_TEST_CHECK(handle);
239 ImageView imageView = ImageView::DownCast(handle);
240 DALI_TEST_CHECK(imageView);
245 int UtcDaliImageViewSetGetProperty01(void)
247 ToolkitTestApplication application;
249 ImageView imageView = ImageView::New();
251 Property::Index idx = imageView.GetPropertyIndex("image");
252 DALI_TEST_EQUALS(idx, (Property::Index)ImageView::Property::IMAGE, TEST_LOCATION);
254 imageView.SetProperty(idx, TEST_IMAGE_FILE_NAME);
255 TestUrl(imageView, TEST_IMAGE_FILE_NAME);
260 int UtcDaliImageViewPreMultipliedAlphaPng(void)
262 ToolkitTestApplication application;
264 // Set up trace debug
265 TestGlAbstraction& gl = application.GetGlAbstraction();
266 TraceCallStack& textureTrace = gl.GetTextureTrace();
267 textureTrace.Enable(true);
269 Property::Map imageMap;
270 imageMap[ImageVisual::Property::URL] = gImage_34_RGBA;
271 imageMap[ImageVisual::Property::RELEASE_POLICY] = ImageVisual::ReleasePolicy::NEVER; // To keep the texture cache
273 ImageView imageView1 = ImageView::New();
274 imageView1.SetProperty(ImageView::Property::IMAGE, imageMap);
276 application.GetScene().Add(imageView1);
278 Property::Value value = imageView1.GetProperty(ImageView::Property::PRE_MULTIPLIED_ALPHA);
280 DALI_TEST_CHECK(value.Get(enable));
281 DALI_TEST_CHECK(enable); // Default value is true
283 // loading started, this waits for the loader thread for max 30 seconds
284 DALI_TEST_EQUALS(Test::WaitForEventThreadTrigger(1), true, TEST_LOCATION);
286 application.SendNotification();
287 application.Render();
289 value = imageView1.GetProperty(ImageView::Property::PRE_MULTIPLIED_ALPHA);
290 DALI_TEST_CHECK(value.Get(enable));
291 DALI_TEST_CHECK(enable); // Keep true
293 // conventional alpha blending
294 Renderer renderer1 = imageView1.GetRendererAt(0);
295 value = renderer1.GetProperty(Renderer::Property::BLEND_PRE_MULTIPLIED_ALPHA);
296 DALI_TEST_CHECK(value.Get(enable));
297 DALI_TEST_CHECK(enable);
299 int srcFactorRgb = renderer1.GetProperty<int>(Renderer::Property::BLEND_FACTOR_SRC_RGB);
300 int destFactorRgb = renderer1.GetProperty<int>(Renderer::Property::BLEND_FACTOR_DEST_RGB);
301 int srcFactorAlpha = renderer1.GetProperty<int>(Renderer::Property::BLEND_FACTOR_SRC_ALPHA);
302 int destFactorAlpha = renderer1.GetProperty<int>(Renderer::Property::BLEND_FACTOR_DEST_ALPHA);
303 DALI_TEST_CHECK(srcFactorRgb == BlendFactor::ONE);
304 DALI_TEST_CHECK(destFactorRgb == BlendFactor::ONE_MINUS_SRC_ALPHA);
305 DALI_TEST_CHECK(srcFactorAlpha == BlendFactor::ONE);
306 DALI_TEST_CHECK(destFactorAlpha == BlendFactor::ONE_MINUS_SRC_ALPHA);
308 DALI_TEST_EQUALS(textureTrace.FindMethod("GenTextures"), true, TEST_LOCATION); // A new texture should be generated.
309 textureTrace.Reset();
311 // Disable pre-multiplied alpha blending
312 imageView1.SetProperty(ImageView::Property::PRE_MULTIPLIED_ALPHA, false);
315 Property::Map attributes;
316 DevelControl::DoAction(imageView1, ImageView::Property::IMAGE, DevelImageVisual::Action::RELOAD, attributes);
318 // loading started, this waits for the loader thread for max 30 seconds
319 DALI_TEST_EQUALS(Test::WaitForEventThreadTrigger(1), true, TEST_LOCATION);
321 application.SendNotification();
322 application.Render();
324 value = imageView1.GetProperty(ImageView::Property::PRE_MULTIPLIED_ALPHA);
325 DALI_TEST_CHECK(value.Get(enable));
326 DALI_TEST_CHECK(!enable);
328 // conventional alpha blending
329 value = renderer1.GetProperty(Renderer::Property::BLEND_PRE_MULTIPLIED_ALPHA);
330 DALI_TEST_CHECK(value.Get(enable));
331 DALI_TEST_CHECK(!enable);
333 srcFactorRgb = renderer1.GetProperty<int>(Renderer::Property::BLEND_FACTOR_SRC_RGB);
334 destFactorRgb = renderer1.GetProperty<int>(Renderer::Property::BLEND_FACTOR_DEST_RGB);
335 srcFactorAlpha = renderer1.GetProperty<int>(Renderer::Property::BLEND_FACTOR_SRC_ALPHA);
336 destFactorAlpha = renderer1.GetProperty<int>(Renderer::Property::BLEND_FACTOR_DEST_ALPHA);
337 DALI_TEST_CHECK(srcFactorRgb == BlendFactor::SRC_ALPHA);
338 DALI_TEST_CHECK(destFactorRgb == BlendFactor::ONE_MINUS_SRC_ALPHA);
339 DALI_TEST_CHECK(srcFactorAlpha == BlendFactor::ONE);
340 DALI_TEST_CHECK(destFactorAlpha == BlendFactor::ONE_MINUS_SRC_ALPHA);
342 DALI_TEST_EQUALS(textureTrace.FindMethod("GenTextures"), true, TEST_LOCATION); // A new texture should be generated.
343 textureTrace.Reset();
345 // Make a new ImageView using the same image
346 ImageView imageView2 = ImageView::New();
347 imageView2.SetProperty(ImageView::Property::IMAGE, imageMap);
349 application.GetScene().Add(imageView2);
351 application.SendNotification();
352 application.Render();
354 Renderer renderer2 = imageView2.GetRendererAt(0);
355 value = renderer2.GetProperty(Renderer::Property::BLEND_PRE_MULTIPLIED_ALPHA);
356 DALI_TEST_CHECK(value.Get(enable));
357 DALI_TEST_CHECK(enable);
359 srcFactorRgb = renderer2.GetProperty<int>(Renderer::Property::BLEND_FACTOR_SRC_RGB);
360 destFactorRgb = renderer2.GetProperty<int>(Renderer::Property::BLEND_FACTOR_DEST_RGB);
361 srcFactorAlpha = renderer2.GetProperty<int>(Renderer::Property::BLEND_FACTOR_SRC_ALPHA);
362 destFactorAlpha = renderer2.GetProperty<int>(Renderer::Property::BLEND_FACTOR_DEST_ALPHA);
363 DALI_TEST_CHECK(srcFactorRgb == BlendFactor::ONE);
364 DALI_TEST_CHECK(destFactorRgb == BlendFactor::ONE_MINUS_SRC_ALPHA);
365 DALI_TEST_CHECK(srcFactorAlpha == BlendFactor::ONE);
366 DALI_TEST_CHECK(destFactorAlpha == BlendFactor::ONE_MINUS_SRC_ALPHA);
368 DALI_TEST_EQUALS(textureTrace.FindMethod("GenTextures"), false, TEST_LOCATION); // The cached texture should be used.
373 int UtcDaliImageViewPreMultipliedAlphaJpg(void)
375 ToolkitTestApplication application;
377 // Set up trace debug
378 TestGlAbstraction& gl = application.GetGlAbstraction();
379 TraceCallStack& textureTrace = gl.GetTextureTrace();
380 textureTrace.Enable(true);
382 Property::Map imageMap;
383 imageMap[ImageVisual::Property::URL] = gImage_600_RGB;
384 imageMap[ImageVisual::Property::RELEASE_POLICY] = ImageVisual::ReleasePolicy::NEVER; // To keep the texture cache
386 ImageView imageView1 = ImageView::New();
387 imageView1.SetProperty(ImageView::Property::IMAGE, imageMap);
389 application.GetScene().Add(imageView1);
391 Property::Value value = imageView1.GetProperty(ImageView::Property::PRE_MULTIPLIED_ALPHA);
393 DALI_TEST_CHECK(value.Get(enable));
394 DALI_TEST_CHECK(enable); // Default value is true
396 // loading started, this waits for the loader thread for max 30 seconds
397 DALI_TEST_EQUALS(Test::WaitForEventThreadTrigger(1), true, TEST_LOCATION);
399 application.SendNotification();
400 application.Render();
402 value = imageView1.GetProperty(ImageView::Property::PRE_MULTIPLIED_ALPHA);
403 DALI_TEST_CHECK(value.Get(enable));
404 DALI_TEST_CHECK(!enable); // Should be false after loading
406 // conventional alpha blending
407 Renderer renderer1 = imageView1.GetRendererAt(0);
408 value = renderer1.GetProperty(Renderer::Property::BLEND_PRE_MULTIPLIED_ALPHA);
409 DALI_TEST_CHECK(value.Get(enable));
410 DALI_TEST_CHECK(!enable);
412 int srcFactorRgb = renderer1.GetProperty<int>(Renderer::Property::BLEND_FACTOR_SRC_RGB);
413 int destFactorRgb = renderer1.GetProperty<int>(Renderer::Property::BLEND_FACTOR_DEST_RGB);
414 int srcFactorAlpha = renderer1.GetProperty<int>(Renderer::Property::BLEND_FACTOR_SRC_ALPHA);
415 int destFactorAlpha = renderer1.GetProperty<int>(Renderer::Property::BLEND_FACTOR_DEST_ALPHA);
416 DALI_TEST_CHECK(srcFactorRgb == BlendFactor::SRC_ALPHA);
417 DALI_TEST_CHECK(destFactorRgb == BlendFactor::ONE_MINUS_SRC_ALPHA);
418 DALI_TEST_CHECK(srcFactorAlpha == BlendFactor::ONE);
419 DALI_TEST_CHECK(destFactorAlpha == BlendFactor::ONE_MINUS_SRC_ALPHA);
421 DALI_TEST_EQUALS(textureTrace.FindMethod("GenTextures"), true, TEST_LOCATION); // A new texture should be generated.
422 textureTrace.Reset();
424 ImageView imageView2 = ImageView::New();
425 imageView2.SetProperty(ImageView::Property::IMAGE, imageMap);
427 // Disable pre-multiplied alpha blending
428 imageView2.SetProperty(ImageView::Property::PRE_MULTIPLIED_ALPHA, false);
430 application.GetScene().Add(imageView2);
432 application.SendNotification();
433 application.Render();
435 value = imageView2.GetProperty(ImageView::Property::PRE_MULTIPLIED_ALPHA);
436 DALI_TEST_CHECK(value.Get(enable));
437 DALI_TEST_CHECK(!enable);
439 // conventional alpha blending
440 Renderer renderer2 = imageView2.GetRendererAt(0);
441 value = renderer2.GetProperty(Renderer::Property::BLEND_PRE_MULTIPLIED_ALPHA);
442 DALI_TEST_CHECK(value.Get(enable));
443 DALI_TEST_CHECK(!enable);
445 srcFactorRgb = renderer2.GetProperty<int>(Renderer::Property::BLEND_FACTOR_SRC_RGB);
446 destFactorRgb = renderer2.GetProperty<int>(Renderer::Property::BLEND_FACTOR_DEST_RGB);
447 srcFactorAlpha = renderer2.GetProperty<int>(Renderer::Property::BLEND_FACTOR_SRC_ALPHA);
448 destFactorAlpha = renderer2.GetProperty<int>(Renderer::Property::BLEND_FACTOR_DEST_ALPHA);
449 DALI_TEST_CHECK(srcFactorRgb == BlendFactor::SRC_ALPHA);
450 DALI_TEST_CHECK(destFactorRgb == BlendFactor::ONE_MINUS_SRC_ALPHA);
451 DALI_TEST_CHECK(srcFactorAlpha == BlendFactor::ONE);
452 DALI_TEST_CHECK(destFactorAlpha == BlendFactor::ONE_MINUS_SRC_ALPHA);
454 DALI_TEST_EQUALS(textureTrace.FindMethod("GenTextures"), false, TEST_LOCATION); // The cached texture should be used.
459 int UtcDaliImageViewPixelArea(void)
461 // Test pixel area property
462 ToolkitTestApplication application;
464 static std::vector<UniformData> customUniforms =
466 UniformData("pixelArea", Property::Type::VECTOR4),
469 TestGraphicsController& graphics = application.GetGraphicsController();
470 graphics.AddCustomUniforms(customUniforms);
472 // Gif image, use AnimatedImageVisual internally
473 // Atlasing is applied to pack multiple frames, use custom wrap mode
474 ImageView gifView = ImageView::New();
475 const Vector4 pixelAreaVisual(0.f, 0.f, 2.f, 2.f);
476 gifView.SetProperty(ImageView::Property::IMAGE,
477 Property::Map().Add(ImageVisual::Property::URL, TEST_GIF_FILE_NAME).Add(ImageVisual::Property::PIXEL_AREA, pixelAreaVisual));
480 Integration::Scene stage = application.GetScene();
484 application.SendNotification();
485 application.Render(16);
487 DALI_TEST_EQUALS(Test::WaitForEventThreadTrigger(2), true, TEST_LOCATION);
489 application.SendNotification();
490 application.Render();
491 DALI_TEST_CHECK(gifView.GetRendererCount() == 1u);
493 const Vector4 fullTextureRect(0.f, 0.f, 1.f, 1.f);
494 // test that the pixel area value defined in the visual property map is registered on renderer
495 Renderer renderer = gifView.GetRendererAt(0);
496 Property::Value pixelAreaValue = renderer.GetProperty(renderer.GetPropertyIndex("pixelArea"));
497 DALI_TEST_EQUALS(pixelAreaValue.Get<Vector4>(), pixelAreaVisual, TEST_LOCATION);
499 // test that the shader has the default pixel area value registered.
500 Shader shader = renderer.GetShader();
501 pixelAreaValue = shader.GetProperty(shader.GetPropertyIndex("pixelArea"));
502 DALI_TEST_EQUALS(pixelAreaValue.Get<Vector4>(), fullTextureRect, TEST_LOCATION);
504 // test that the uniform uses the pixelArea property on the renderer.
505 TestGlAbstraction& gl = application.GetGlAbstraction();
506 Vector4 pixelAreaUniform;
507 DALI_TEST_CHECK(gl.GetUniformValue<Vector4>("pixelArea", pixelAreaUniform));
508 DALI_TEST_EQUALS(pixelAreaVisual, pixelAreaUniform, Math::MACHINE_EPSILON_100, TEST_LOCATION);
510 // set the pixelArea property on the control
511 const Vector4 pixelAreaControl(-1.f, -1.f, 3.f, 3.f);
512 gifView.SetProperty(ImageView::Property::PIXEL_AREA, pixelAreaControl);
513 application.SendNotification();
514 application.Render(16);
516 // check the pixelArea property on the control
517 pixelAreaValue = gifView.GetProperty(gifView.GetPropertyIndex("pixelArea"));
518 DALI_TEST_EQUALS(pixelAreaValue.Get<Vector4>(), pixelAreaControl, TEST_LOCATION);
519 // test that the uniform uses the pixelArea property on the control.
520 DALI_TEST_CHECK(gl.GetUniformValue<Vector4>("pixelArea", pixelAreaUniform));
521 DALI_TEST_EQUALS(pixelAreaControl, pixelAreaUniform, Math::MACHINE_EPSILON_100, TEST_LOCATION);
526 int UtcDaliImageViewAsyncLoadingWithoutAltasing(void)
528 ToolkitTestApplication application;
529 TestGlAbstraction& gl = application.GetGlAbstraction();
530 const std::vector<GLuint>& textures = gl.GetBoundTextures();
531 size_t numTextures = textures.size();
533 // Async loading, no atlasing for big size image
534 ImageView imageView = ImageView::New(gImage_600_RGB);
536 // By default, Aysnc loading is used
537 application.GetScene().Add(imageView);
538 imageView.SetProperty(Actor::Property::SIZE, Vector2(100, 100));
539 imageView.SetProperty(Actor::Property::PARENT_ORIGIN, ParentOrigin::CENTER);
541 DALI_TEST_EQUALS(Test::WaitForEventThreadTrigger(1), true, TEST_LOCATION);
543 application.SendNotification();
544 application.Render(16);
545 application.SendNotification();
547 const std::vector<GLuint>& textures2 = gl.GetBoundTextures();
548 DALI_TEST_GREATER(textures2.size(), numTextures, TEST_LOCATION);
553 int UtcDaliImageViewAsyncLoadingWithAtlasing(void)
555 ToolkitTestApplication application;
557 //Async loading, automatic atlasing for small size image
558 TraceCallStack& callStack = application.GetGlAbstraction().GetTextureTrace();
560 callStack.Enable(true);
562 Property::Map imageMap;
564 imageMap[ImageVisual::Property::URL] = gImage_34_RGBA;
565 imageMap[ImageVisual::Property::DESIRED_HEIGHT] = 34;
566 imageMap[ImageVisual::Property::DESIRED_WIDTH] = 34;
567 imageMap[ImageVisual::Property::ATLASING] = true;
569 ImageView imageView = ImageView::New();
570 imageView.SetProperty(ImageView::Property::IMAGE, imageMap);
571 imageView.SetProperty(Toolkit::Control::Property::PADDING, Extents(10u, 10u, 10u, 10u));
573 // By default, Aysnc loading is used
574 // loading is not started if the actor is offScene
576 application.GetScene().Add(imageView);
577 application.SendNotification();
578 application.Render(16);
579 application.Render(16);
580 application.SendNotification();
582 imageView.SetProperty(Dali::Actor::Property::LAYOUT_DIRECTION, Dali::LayoutDirection::RIGHT_TO_LEFT);
583 application.SendNotification();
584 application.Render(16);
585 application.Render(16);
586 application.SendNotification();
588 // loading started, this waits for the loader thread for max 30 seconds
589 DALI_TEST_EQUALS(Test::WaitForEventThreadTrigger(1), true, TEST_LOCATION);
591 application.SendNotification();
592 application.Render(16);
594 callStack.Enable(false);
596 TraceCallStack::NamedParams params;
597 params["width"] << 34;
598 params["height"] << 34;
599 DALI_TEST_EQUALS(callStack.FindMethodAndParams("TexSubImage2D", params), true, TEST_LOCATION);
604 int UtcDaliImageViewAsyncLoadingWithAtlasing02(void)
606 ToolkitTestApplication application;
608 //Async loading, automatic atlasing for small size image
609 TraceCallStack& callStack = application.GetGlAbstraction().GetTextureTrace();
611 callStack.Enable(true);
613 Property::Map asyncLoadingMap;
614 asyncLoadingMap["url"] = gImage_34_RGBA;
615 asyncLoadingMap["desiredHeight"] = 34;
616 asyncLoadingMap["desiredWidth"] = 34;
617 asyncLoadingMap["synchronousLoading"] = false;
618 asyncLoadingMap["atlasing"] = true;
620 ImageView imageView = ImageView::New();
621 imageView.SetProperty(ImageView::Property::IMAGE, asyncLoadingMap);
623 application.GetScene().Add(imageView);
624 application.SendNotification();
625 application.Render(16);
626 application.Render(16);
627 application.SendNotification();
629 // loading started, this waits for the loader thread for max 30 seconds
630 DALI_TEST_EQUALS(Test::WaitForEventThreadTrigger(1), true, TEST_LOCATION);
632 application.SendNotification();
633 application.Render(16);
635 callStack.Enable(false);
637 TraceCallStack::NamedParams params;
638 params["width"] << 34;
639 params["height"] << 34;
640 DALI_TEST_EQUALS(callStack.FindMethodAndParams("TexSubImage2D", params), true, TEST_LOCATION);
645 int UtcDaliImageViewSyncLoading(void)
647 ToolkitTestApplication application;
649 tet_infoline("ImageView Testing sync loading and size using index key property map");
651 Property::Map syncLoadingMap;
652 syncLoadingMap[ImageVisual::Property::SYNCHRONOUS_LOADING] = true;
653 syncLoadingMap[ImageVisual::Property::ATLASING] = true;
655 // Sync loading, no atlasing for big size image
657 ImageView imageView = ImageView::New();
659 // Sync loading is used
660 syncLoadingMap[ImageVisual::Property::URL] = gImage_600_RGB;
661 imageView.SetProperty(ImageView::Property::IMAGE, syncLoadingMap);
664 // Sync loading, automatic atlasing for small size image
666 TraceCallStack& callStack = application.GetGlAbstraction().GetTextureTrace();
668 callStack.Enable(true);
670 ImageView imageView = ImageView::New();
672 // Sync loading is used
673 syncLoadingMap[ImageVisual::Property::URL] = gImage_34_RGBA;
674 syncLoadingMap[ImageVisual::Property::DESIRED_HEIGHT] = 34;
675 syncLoadingMap[ImageVisual::Property::DESIRED_WIDTH] = 34;
676 imageView.SetProperty(ImageView::Property::IMAGE, syncLoadingMap);
678 application.GetScene().Add(imageView);
679 application.SendNotification();
680 application.Render(16);
682 TraceCallStack::NamedParams params;
683 params["width"] << 34;
684 params["height"] << 34;
685 DALI_TEST_EQUALS(callStack.FindMethodAndParams("TexSubImage2D", params),
692 int UtcDaliImageViewSyncLoading02(void)
694 ToolkitTestApplication application;
696 tet_infoline("ImageView Testing sync loading and size using string key property map");
698 // Sync loading, automatic atlasing for small size image
700 TraceCallStack& callStack = application.GetGlAbstraction().GetTextureTrace();
702 callStack.Enable(true);
704 ImageView imageView = ImageView::New();
706 // Sync loading is used
707 Property::Map syncLoadingMap;
708 syncLoadingMap["url"] = gImage_34_RGBA;
709 syncLoadingMap["desiredHeight"] = 34;
710 syncLoadingMap["desiredWidth"] = 34;
711 syncLoadingMap["synchronousLoading"] = true;
712 syncLoadingMap["atlasing"] = true;
713 imageView.SetProperty(ImageView::Property::IMAGE, syncLoadingMap);
715 application.GetScene().Add(imageView);
716 application.SendNotification();
717 application.Render(16);
719 TraceCallStack::NamedParams params;
720 params["width"] << 34;
721 params["height"] << 34;
722 DALI_TEST_EQUALS(callStack.FindMethodAndParams("TexSubImage2D", params),
729 int UtcDaliImageViewAsyncLoadingEncodedBuffer(void)
731 ToolkitTestApplication application;
732 TestGlAbstraction& gl = application.GetGlAbstraction();
733 const std::vector<GLuint>& textures = gl.GetBoundTextures();
734 size_t numTextures = textures.size();
736 // Get encoded raw-buffer image and generate url
737 EncodedImageBuffer buffer = ConvertFileToEncodedImageBuffer(gImage_600_RGB);
738 ImageUrl url = Toolkit::Image::GenerateUrl(buffer);
740 // Async loading, no atlasing for big size image
741 ImageView imageView = ImageView::New(url.GetUrl());
743 // By default, Aysnc loading is used
744 application.GetScene().Add(imageView);
745 imageView.SetProperty(Actor::Property::SIZE, Vector2(100, 100));
746 imageView.SetProperty(Actor::Property::PARENT_ORIGIN, ParentOrigin::CENTER);
748 DALI_TEST_EQUALS(Test::WaitForEventThreadTrigger(1), true, TEST_LOCATION);
750 application.SendNotification();
751 application.Render(16);
752 application.SendNotification();
754 const std::vector<GLuint>& textures2 = gl.GetBoundTextures();
755 DALI_TEST_GREATER(textures2.size(), numTextures, TEST_LOCATION);
760 int UtcDaliImageViewAsyncLoadingEncodedBufferWithAtlasing(void)
762 ToolkitTestApplication application;
764 // Get encoded raw-buffer image and generate url
765 EncodedImageBuffer buffer = ConvertFileToEncodedImageBuffer(gImage_600_RGB);
766 ImageUrl url = Toolkit::Image::GenerateUrl(buffer);
767 ImageUrl url2 = Toolkit::Image::GenerateUrl(buffer);
769 // Generate url is not equal to url2
770 // NOTE : This behavior may changed when ImageUrl compare operator changed.
771 DALI_TEST_CHECK(url != url2);
772 // Generate url's string is equal to url2's string
773 DALI_TEST_CHECK(url.GetUrl() == url2.GetUrl());
775 EncodedImageBuffer buffer2 = ConvertFileToEncodedImageBuffer(gImage_600_RGB);
776 url2 = Toolkit::Image::GenerateUrl(buffer2);
778 // Check whethere two url are not equal
779 DALI_TEST_CHECK(url.GetUrl() != url2.GetUrl());
781 // Async loading, automatic atlasing for small size image
782 TraceCallStack& callStack = application.GetGlAbstraction().GetTextureTrace();
784 callStack.Enable(true);
786 Property::Map imageMap;
788 imageMap[ImageVisual::Property::URL] = url.GetUrl();
789 imageMap[ImageVisual::Property::DESIRED_HEIGHT] = 600;
790 imageMap[ImageVisual::Property::DESIRED_WIDTH] = 600;
791 imageMap[ImageVisual::Property::ATLASING] = true;
793 // No atlasing with big image
794 ImageView imageView_bigdesired = ImageView::New();
795 imageView_bigdesired.SetProperty(ImageView::Property::IMAGE, imageMap);
796 imageView_bigdesired.SetProperty(Toolkit::Control::Property::PADDING, Extents(10u, 10u, 10u, 10u));
798 imageMap[ImageVisual::Property::DESIRED_HEIGHT] = 0;
799 imageMap[ImageVisual::Property::DESIRED_WIDTH] = 0;
801 // No atlasing with zero desired size
802 ImageView imageView_nodesired = ImageView::New();
803 imageView_nodesired.SetProperty(ImageView::Property::IMAGE, imageMap);
804 imageView_nodesired.SetProperty(Toolkit::Control::Property::PADDING, Extents(10u, 10u, 10u, 10u));
806 imageMap[ImageVisual::Property::DESIRED_HEIGHT] = 34;
807 imageMap[ImageVisual::Property::DESIRED_WIDTH] = 34;
809 ImageView imageView = ImageView::New();
810 imageView.SetProperty(ImageView::Property::IMAGE, imageMap);
811 imageView.SetProperty(Toolkit::Control::Property::PADDING, Extents(10u, 10u, 10u, 10u));
813 // By default, Aysnc loading is used
814 // loading is not started if the actor is offScene
815 application.GetScene().Add(imageView);
816 application.GetScene().Add(imageView_bigdesired);
817 application.GetScene().Add(imageView_nodesired);
818 application.SendNotification();
819 application.Render(16);
821 // loading started, this waits for the loader thread for max 30 seconds
822 DALI_TEST_EQUALS(Test::WaitForEventThreadTrigger(1), true, TEST_LOCATION);
824 application.Render(16);
825 application.SendNotification();
827 // Change url to url2
828 imageMap[ImageVisual::Property::URL] = url2.GetUrl();
829 imageView.SetProperty(ImageView::Property::IMAGE, imageMap);
831 imageView.SetProperty(Dali::Actor::Property::LAYOUT_DIRECTION, Dali::LayoutDirection::RIGHT_TO_LEFT);
832 application.SendNotification();
833 application.Render(16);
834 application.Render(16);
835 application.SendNotification();
837 // loading started, this waits for the loader thread for max 30 seconds
838 DALI_TEST_EQUALS(Test::WaitForEventThreadTrigger(1), true, TEST_LOCATION);
840 application.SendNotification();
841 application.Render(16);
843 callStack.Enable(false);
845 TraceCallStack::NamedParams params;
846 params["width"] << 34;
847 params["height"] << 34;
848 DALI_TEST_EQUALS(callStack.FindMethodAndParams("TexSubImage2D", params), true, TEST_LOCATION);
853 int UtcDaliImageViewSyncLoadingEncodedBuffer(void)
855 ToolkitTestApplication application;
857 tet_infoline("ImageView Testing sync loading from EncodedImageBuffer");
859 // Get encoded raw-buffer image and generate url
860 EncodedImageBuffer buffer = ConvertFileToEncodedImageBuffer(gImage_34_RGBA);
861 ImageUrl url = Toolkit::Image::GenerateUrl(buffer);
863 // Sync loading, automatic atlasing for small size image
865 TraceCallStack& callStack = application.GetGlAbstraction().GetTextureTrace();
867 callStack.Enable(true);
869 ImageView imageView = ImageView::New();
871 // Sync loading is used
872 Property::Map syncLoadingMap;
873 syncLoadingMap["url"] = url.GetUrl();
874 syncLoadingMap["alphaMaskUrl"] = gImage_34_RGBA;
875 syncLoadingMap["desiredHeight"] = 34;
876 syncLoadingMap["desiredWidth"] = 34;
877 syncLoadingMap["synchronousLoading"] = true;
878 syncLoadingMap["atlasing"] = true;
879 imageView.SetProperty(ImageView::Property::IMAGE, syncLoadingMap);
881 application.GetScene().Add(imageView);
882 application.SendNotification();
883 application.Render(16);
885 TraceCallStack::NamedParams params;
886 params["width"] << 34;
887 params["height"] << 34;
888 DALI_TEST_EQUALS(callStack.FindMethodAndParams("TexSubImage2D", params),
896 int UtcDaliImageViewAddedTexture(void)
898 ToolkitTestApplication application;
900 tet_infoline("ImageView Testing image view with texture provided manager url");
902 ImageView imageView = ImageView::New();
904 // empty texture is ok, though pointless from app point of view
906 std::string url = TextureManager::AddTexture(empty);
907 DALI_TEST_CHECK(url.size() > 0u);
909 Property::Map propertyMap;
910 propertyMap[ImageVisual::Property::URL] = url;
911 imageView.SetProperty(ImageView::Property::IMAGE, propertyMap);
913 application.GetScene().Add(imageView);
914 application.SendNotification();
915 application.Render();
920 int UtcDaliImageViewSizeWithBackground(void)
922 ToolkitTestApplication application;
926 ImageView imageView = ImageView::New();
928 imageView.SetProperty(Control::Property::BACKGROUND,
930 {Toolkit::Visual::Property::TYPE, Toolkit::Visual::IMAGE},
931 {Toolkit::ImageVisual::Property::URL, TEST_RESOURCE_DIR "/gallery-small-1.jpg"},
932 {ImageVisual::Property::DESIRED_WIDTH, width},
933 {ImageVisual::Property::DESIRED_HEIGHT, height},
936 application.GetScene().Add(imageView);
937 application.SendNotification();
938 application.Render();
940 DALI_TEST_EQUALS(imageView.GetCurrentProperty<Vector3>(Actor::Property::SIZE).width, (float)width, TEST_LOCATION);
941 DALI_TEST_EQUALS(imageView.GetCurrentProperty<Vector3>(Actor::Property::SIZE).height, (float)height, TEST_LOCATION);
946 int UtcDaliImageViewSizeWithBackgroundAndImage(void)
948 ToolkitTestApplication application;
950 int widthBackground = 100;
951 int heightBackground = 200;
955 ImageView imageView = ImageView::New();
957 imageView.SetProperty(Control::Property::BACKGROUND,
959 {Toolkit::Visual::Property::TYPE, Toolkit::Visual::IMAGE},
960 {Toolkit::ImageVisual::Property::URL, TEST_RESOURCE_DIR "/gallery-small-1.jpg"},
961 {ImageVisual::Property::DESIRED_WIDTH, widthBackground},
962 {ImageVisual::Property::DESIRED_HEIGHT, heightBackground},
965 imageView.SetImage(gImage_600_RGB); // 1 to 1 ratio, 600x600 pixels
967 application.GetScene().Add(imageView);
968 application.SendNotification();
969 application.Render();
971 DALI_TEST_EQUALS(imageView.GetCurrentProperty<Vector3>(Actor::Property::SIZE).width, (float)width, TEST_LOCATION);
972 DALI_TEST_EQUALS(imageView.GetCurrentProperty<Vector3>(Actor::Property::SIZE).height, (float)height, TEST_LOCATION);
977 int UtcDaliImageViewHeightForWidthBackground(void)
979 ToolkitTestApplication application;
981 int widthBackground = 100;
982 int heightBackground = 200;
984 ImageView imageView = ImageView::New();
986 imageView.SetProperty(Control::Property::BACKGROUND,
987 {{Toolkit::Visual::Property::TYPE, Toolkit::Visual::IMAGE},
988 {Toolkit::ImageVisual::Property::URL, TEST_RESOURCE_DIR "/gallery-small-1.jpg"},
989 {ImageVisual::Property::DESIRED_WIDTH, widthBackground},
990 {ImageVisual::Property::DESIRED_HEIGHT, heightBackground}});
992 application.GetScene().Add(imageView);
993 application.SendNotification();
994 application.Render();
996 Control control = Control::DownCast(imageView);
997 DALI_TEST_CHECK(control);
998 DALI_TEST_EQUALS(imageView.GetHeightForWidth(123.f), control.GetHeightForWidth(123.f), TEST_LOCATION);
999 DALI_TEST_EQUALS(imageView.GetWidthForHeight(321.f), control.GetWidthForHeight(321.f), TEST_LOCATION);
1004 int UtcDaliImageViewHeightForWidthBackgroundAndImage(void)
1006 ToolkitTestApplication application;
1008 int widthBackground = 100;
1009 int heightBackground = 200;
1013 ImageView imageView = ImageView::New();
1015 imageView.SetProperty(Control::Property::BACKGROUND,
1016 {{Toolkit::Visual::Property::TYPE, Toolkit::Visual::IMAGE},
1017 {Toolkit::ImageVisual::Property::URL, TEST_RESOURCE_DIR "/gallery-small-1.jpg"},
1018 {ImageVisual::Property::DESIRED_WIDTH, widthBackground},
1019 {ImageVisual::Property::DESIRED_HEIGHT, heightBackground}}); // 1 to 2 ratio
1021 imageView.SetImage(gImage_600_RGB); // 1 to 1 ratio
1023 application.GetScene().Add(imageView);
1024 application.SendNotification();
1025 application.Render();
1027 DALI_TEST_EQUALS(imageView.GetHeightForWidth(width), (float)height, TEST_LOCATION);
1028 DALI_TEST_EQUALS(imageView.GetWidthForHeight(height), (float)width, TEST_LOCATION);
1033 int UtcDaliImageViewSetImageUrl(void)
1035 ToolkitTestApplication application;
1037 ImageView imageView = ImageView::New();
1038 imageView.SetImage(TEST_IMAGE_FILE_NAME);
1039 TestUrl(imageView, TEST_IMAGE_FILE_NAME);
1041 imageView.SetImage(TEST_IMAGE_FILE_NAME2);
1042 TestUrl(imageView, TEST_IMAGE_FILE_NAME2);
1047 bool gResourceReadySignalFired = false;
1048 Vector3 gNaturalSize;
1050 void ResourceReadySignal(Control control)
1052 gResourceReadySignalFired = true;
1055 int UtcDaliImageViewCheckResourceReady(void)
1057 ToolkitTestApplication application;
1059 gResourceReadySignalFired = false;
1061 // Check ImageView with background and main image, to ensure both visuals are marked as loaded
1062 ImageView imageView = ImageView::New(TEST_GIF_FILE_NAME);
1064 imageView.SetProperty(Control::Property::BACKGROUND,
1065 {{Toolkit::Visual::Property::TYPE, Toolkit::Visual::IMAGE},
1066 {Toolkit::ImageVisual::Property::URL, TEST_RESOURCE_DIR "/gallery-small-1.jpg"},
1067 {ImageVisual::Property::DESIRED_WIDTH, 100},
1068 {ImageVisual::Property::DESIRED_HEIGHT, 200}});
1070 DALI_TEST_EQUALS(imageView.IsResourceReady(), false, TEST_LOCATION);
1072 imageView.ResourceReadySignal().Connect(&ResourceReadySignal);
1074 application.GetScene().Add(imageView);
1076 // loading started, this waits for the loader thread
1077 DALI_TEST_EQUALS(Test::WaitForEventThreadTrigger(1), true, TEST_LOCATION);
1079 application.SendNotification();
1080 application.Render(16);
1082 DALI_TEST_EQUALS(Test::WaitForEventThreadTrigger(2), true, TEST_LOCATION);
1084 application.SendNotification();
1085 application.Render();
1087 DALI_TEST_EQUALS(imageView.IsResourceReady(), true, TEST_LOCATION);
1089 DALI_TEST_EQUALS(gResourceReadySignalFired, true, TEST_LOCATION);
1094 int UtcDaliImageViewSetImageTypeChangesP(void)
1096 ToolkitTestApplication application;
1098 ImageView imageView = ImageView::New();
1099 Toolkit::Internal::Control& controlImpl = Toolkit::Internal::GetImplementation(imageView);
1101 application.GetScene().Add(imageView);
1105 Toolkit::Visual::Base visual;
1107 Property::Value value = imageView.GetProperty(imageView.GetPropertyIndex("image"));
1108 visual = DevelControl::GetVisual(controlImpl, ImageView::Property::IMAGE);
1110 application.SendNotification();
1111 application.Render(16);
1113 DALI_TEST_CHECK(!value.Get(url)); // Value should be empty
1115 DALI_TEST_CHECK(map.Empty()); // Value should be empty
1116 DALI_TEST_CHECK(!visual); // Visual should be invalid
1119 imageView.SetImage("TEST_URL");
1121 application.SendNotification();
1122 application.Render(16);
1124 value = imageView.GetProperty(imageView.GetPropertyIndex("image"));
1125 visual = DevelControl::GetVisual(controlImpl, ImageView::Property::IMAGE);
1127 DALI_TEST_CHECK(value.Get(url)); // Value should NOT be empty
1128 DALI_TEST_CHECK(!value.Get(map)); // Value should be empty
1129 DALI_TEST_CHECK(visual); // Visual should be valid
1132 imageView.SetImage("");
1134 application.SendNotification();
1135 application.Render(16);
1137 value = imageView.GetProperty(imageView.GetPropertyIndex("image"));
1138 visual = DevelControl::GetVisual(controlImpl, ImageView::Property::IMAGE);
1140 DALI_TEST_CHECK(!value.Get(url)); // Value should be empty
1142 DALI_TEST_CHECK(map.Empty()); // Value should be empty
1143 DALI_TEST_CHECK(!visual); // Visual should be invalid
1145 // Set a URL in property map
1146 Property::Map propertyMap;
1147 propertyMap[ImageVisual::Property::URL] = TEST_IMAGE_FILE_NAME;
1148 imageView.SetProperty(ImageView::Property::IMAGE, propertyMap);
1150 application.SendNotification();
1151 application.Render(16);
1153 value = imageView.GetProperty(imageView.GetPropertyIndex("image"));
1154 visual = DevelControl::GetVisual(controlImpl, ImageView::Property::IMAGE);
1156 DALI_TEST_CHECK(!value.Get(url)); // Value should be empty
1157 DALI_TEST_CHECK(value.Get(map)); // Value should NOT be empty
1158 DALI_TEST_CHECK(visual); // Visual should be valid
1160 // Set a URL in property map again
1161 propertyMap[ImageVisual::Property::URL] = gImage_34_RGBA;
1162 imageView.SetProperty(ImageView::Property::IMAGE, propertyMap);
1164 application.SendNotification();
1165 application.Render(16);
1167 value = imageView.GetProperty(imageView.GetPropertyIndex("image"));
1168 visual = DevelControl::GetVisual(controlImpl, ImageView::Property::IMAGE);
1170 DALI_TEST_CHECK(!value.Get(url)); // Value should be empty
1171 DALI_TEST_CHECK(value.Get(map)); // Value should NOT be empty
1172 DALI_TEST_CHECK(visual); // Visual should be valid
1174 // Set an empty URL in property map
1175 propertyMap[ImageVisual::Property::URL] = std::string();
1176 imageView.SetProperty(ImageView::Property::IMAGE, propertyMap);
1178 application.SendNotification();
1179 application.Render(16);
1181 value = imageView.GetProperty(imageView.GetPropertyIndex("image"));
1182 visual = DevelControl::GetVisual(controlImpl, ImageView::Property::IMAGE);
1184 DALI_TEST_CHECK(!value.Get(url)); // Value should be empty
1185 DALI_TEST_CHECK(value.Get(map)); // Value should NOT be empty
1186 DALI_TEST_CHECK(!visual); // Visual should be invalid
1188 // Set a URL in property map again
1189 propertyMap[ImageVisual::Property::URL] = gImage_34_RGBA;
1190 imageView.SetProperty(ImageView::Property::IMAGE, propertyMap);
1192 application.SendNotification();
1193 application.Render(16);
1195 value = imageView.GetProperty(imageView.GetPropertyIndex("image"));
1196 visual = DevelControl::GetVisual(controlImpl, ImageView::Property::IMAGE);
1198 DALI_TEST_CHECK(!value.Get(url)); // Value should be empty
1199 DALI_TEST_CHECK(value.Get(map)); // Value should NOT be empty
1200 DALI_TEST_CHECK(visual); // Visual should be valid
1202 // Set an empty property map
1203 propertyMap.Clear();
1204 imageView.SetProperty(ImageView::Property::IMAGE, propertyMap);
1206 application.SendNotification();
1207 application.Render(16);
1209 value = imageView.GetProperty(imageView.GetPropertyIndex("image"));
1210 visual = DevelControl::GetVisual(controlImpl, ImageView::Property::IMAGE);
1212 DALI_TEST_CHECK(!value.Get(url)); // Value should be empty
1213 DALI_TEST_CHECK(value.Get(map)); // Value should NOT be empty
1214 DALI_TEST_CHECK(map.Empty()); // But PropertyMap should be empty
1215 DALI_TEST_CHECK(!visual); // Visual should be invalid
1220 int UtcDaliImageViewResourceUrlP(void)
1222 ToolkitTestApplication application;
1224 ImageView imageView = ImageView::New();
1225 DALI_TEST_CHECK(imageView.GetProperty(ImageView::Property::IMAGE).Get<std::string>().empty());
1227 imageView.SetProperty(ImageView::Property::IMAGE, "TestString");
1228 DALI_TEST_EQUALS(imageView.GetProperty(ImageView::Property::IMAGE).Get<std::string>(), "TestString", TEST_LOCATION);
1233 int UtcDaliImageViewReplaceImage(void)
1235 ToolkitTestApplication application;
1237 gResourceReadySignalFired = false;
1239 // Check ImageView with background and main image, to ensure both visuals are marked as loaded
1240 ImageView imageView = ImageView::New(TEST_IMAGE_1);
1242 DALI_TEST_EQUALS(imageView.IsResourceReady(), false, TEST_LOCATION);
1244 imageView.ResourceReadySignal().Connect(&ResourceReadySignal);
1246 application.GetScene().Add(imageView);
1248 application.SendNotification();
1249 application.Render(16);
1251 // loading started, this waits for the loader thread for max 30 seconds
1252 DALI_TEST_EQUALS(Test::WaitForEventThreadTrigger(1), true, TEST_LOCATION);
1254 DALI_TEST_EQUALS(imageView.GetRendererCount(), 1u, TEST_LOCATION);
1256 DALI_TEST_EQUALS(gResourceReadySignalFired, true, TEST_LOCATION);
1258 gResourceReadySignalFired = false;
1260 imageView.SetImage(TEST_IMAGE_2);
1262 application.SendNotification();
1263 application.Render(16);
1265 // loading started, this waits for the loader thread for max 30 seconds
1266 DALI_TEST_EQUALS(Test::WaitForEventThreadTrigger(1), true, TEST_LOCATION);
1268 DALI_TEST_EQUALS(imageView.GetRendererCount(), 1u, TEST_LOCATION);
1270 DALI_TEST_EQUALS(imageView.IsResourceReady(), true, TEST_LOCATION);
1272 DALI_TEST_EQUALS(gResourceReadySignalFired, true, TEST_LOCATION);
1277 int UtcDaliImageViewReloadAlphaMaskImage(void)
1279 ToolkitTestApplication application;
1281 gResourceReadySignalFired = false;
1283 ImageView dummy = ImageView::New();
1284 ImageView imageView = ImageView::New();
1285 Property::Map propertyMap;
1287 // To keep alpha mask cached, scene on some dummy image.
1288 // Note : If we don't cache alpha mask image, the reference count of mask image become zero.
1289 // In this case, we might need to wait mask image loading, which is not neccesary & can be changed behavior.
1290 propertyMap[ImageVisual::Property::URL] = gImage_600_RGB;
1291 propertyMap[ImageVisual::Property::ALPHA_MASK_URL] = TEST_BROKEN_IMAGE_DEFAULT;
1292 dummy.SetProperty(ImageView::Property::IMAGE, propertyMap);
1294 application.GetScene().Add(dummy);
1296 application.SendNotification();
1297 application.Render(16);
1299 DALI_TEST_EQUALS(Test::WaitForEventThreadTrigger(3), true, TEST_LOCATION);
1301 application.SendNotification();
1302 application.Render(16);
1304 propertyMap.Clear();
1305 propertyMap[ImageVisual::Property::URL] = gImage_34_RGBA;
1306 propertyMap[ImageVisual::Property::ALPHA_MASK_URL] = TEST_BROKEN_IMAGE_DEFAULT;
1307 imageView.SetProperty(ImageView::Property::IMAGE, propertyMap);
1309 DALI_TEST_EQUALS(imageView.IsResourceReady(), false, TEST_LOCATION);
1311 imageView.ResourceReadySignal().Connect(&ResourceReadySignal);
1313 application.GetScene().Add(imageView);
1315 application.SendNotification();
1316 application.Render(16);
1318 // Load image and use cached mask. Now we try to apply masking.
1319 DALI_TEST_EQUALS(Test::WaitForEventThreadTrigger(1), true, TEST_LOCATION);
1321 DALI_TEST_EQUALS(gResourceReadySignalFired, false, TEST_LOCATION);
1323 // Cancel apply masking.
1324 imageView.Unparent();
1326 application.SendNotification();
1327 application.Render(16);
1329 // Reload same image again.
1330 application.GetScene().Add(imageView);
1332 application.SendNotification();
1333 application.Render(16);
1335 // Finish apply masking.
1336 DALI_TEST_EQUALS(Test::WaitForEventThreadTrigger(1), true, TEST_LOCATION);
1338 DALI_TEST_EQUALS(imageView.GetRendererCount(), 1u, TEST_LOCATION);
1339 DALI_TEST_EQUALS(imageView.IsResourceReady(), true, TEST_LOCATION);
1340 DALI_TEST_EQUALS(gResourceReadySignalFired, true, TEST_LOCATION);
1345 void OnRelayoutOverride(Size size)
1347 gNaturalSize = size; // Size Relayout is using
1350 int UtcDaliImageViewReplaceImageAndGetNaturalSize(void)
1352 ToolkitTestApplication application;
1354 // Check ImageView with background and main image, to ensure both visuals are marked as loaded
1355 ImageView imageView = ImageView::New(TEST_IMAGE_1);
1356 imageView.SetResizePolicy(ResizePolicy::USE_NATURAL_SIZE, Dimension::ALL_DIMENSIONS);
1358 DummyControl dummyControl = DummyControl::New(true);
1359 Impl::DummyControl& dummyImpl = static_cast<Impl::DummyControl&>(dummyControl.GetImplementation());
1360 dummyControl.SetResizePolicy(ResizePolicy::FIT_TO_CHILDREN, Dimension::ALL_DIMENSIONS);
1362 dummyControl.Add(imageView);
1363 dummyImpl.SetRelayoutCallback(&OnRelayoutOverride);
1364 application.GetScene().Add(dummyControl);
1366 application.SendNotification();
1367 application.Render();
1369 // loading started, this waits for the loader thread for max 30 seconds
1370 DALI_TEST_EQUALS(Test::WaitForEventThreadTrigger(1), true, TEST_LOCATION);
1372 DALI_TEST_EQUALS(gNaturalSize.width, 1024.0f, TEST_LOCATION);
1373 DALI_TEST_EQUALS(gNaturalSize.height, 1024.0f, TEST_LOCATION);
1375 gNaturalSize = Vector3::ZERO;
1377 imageView.SetImage(gImage_600_RGB);
1379 // Waiting for resourceReady so SendNotifcation not called here.
1381 // loading started, this waits for the loader thread for max 30 seconds
1382 DALI_TEST_EQUALS(Test::WaitForEventThreadTrigger(1), true, TEST_LOCATION);
1384 // Trigger a potential relayout
1385 application.SendNotification();
1386 application.Render();
1388 DALI_TEST_EQUALS(gNaturalSize.width, 600.0f, TEST_LOCATION);
1389 DALI_TEST_EQUALS(gNaturalSize.height, 600.0f, TEST_LOCATION);
1394 int UtcDaliImageViewResourceReadySignalWithImmediateLoad(void)
1396 tet_infoline("Test Setting Image with IMMEDIATE load and receving ResourceReadySignal before staged.");
1398 ToolkitTestApplication application;
1400 gResourceReadySignalFired = false;
1402 Property::Map imageMap;
1404 imageMap[ImageVisual::Property::URL] = gImage_34_RGBA;
1405 imageMap[ImageVisual::Property::LOAD_POLICY] = ImageVisual::LoadPolicy::IMMEDIATE;
1407 tet_infoline("Creating ImageView without URL so image does not start loading");
1408 ImageView imageView = ImageView::New();
1409 tet_infoline("Connect to image loaded signal before setting image");
1410 imageView.ResourceReadySignal().Connect(&ResourceReadySignal);
1411 tet_infoline("Setting Image with IMMEDIATE load, signal already connected so will be triggered.");
1412 imageView.SetProperty(ImageView::Property::IMAGE, imageMap);
1414 // loading started, this waits for the loader thread
1415 DALI_TEST_EQUALS(Test::WaitForEventThreadTrigger(1), true, TEST_LOCATION);
1417 application.SendNotification();
1418 application.Render(16);
1420 DALI_TEST_EQUALS(gResourceReadySignalFired, true, TEST_LOCATION);
1425 int UtcDaliImageViewResourceReadySignalWithReusedImage(void)
1427 tet_infoline("Test Setting Image that was already loaded by another ImageView and still getting ResourceReadySignal.");
1429 ToolkitTestApplication application;
1431 gResourceReadySignalFired = false;
1433 Property::Map imageMap;
1435 imageMap[ImageVisual::Property::URL] = gImage_34_RGBA;
1436 imageMap[ImageVisual::Property::LOAD_POLICY] = ImageVisual::LoadPolicy::IMMEDIATE;
1438 ImageView imageView = ImageView::New();
1439 imageView.ResourceReadySignal().Connect(&ResourceReadySignal);
1440 imageView.SetProperty(ImageView::Property::IMAGE, imageMap);
1442 // loading started, this waits for the loader thread
1443 DALI_TEST_EQUALS(Test::WaitForEventThreadTrigger(1), true, TEST_LOCATION);
1445 application.SendNotification();
1446 application.Render(16);
1448 DALI_TEST_EQUALS(gResourceReadySignalFired, true, TEST_LOCATION);
1449 gResourceReadySignalFired = false;
1451 ImageView imageViewWithExistingImage = ImageView::New();
1452 imageViewWithExistingImage.ResourceReadySignal().Connect(&ResourceReadySignal);
1453 imageViewWithExistingImage.SetProperty(ImageView::Property::IMAGE, imageMap);
1455 DALI_TEST_EQUALS(gResourceReadySignalFired, true, TEST_LOCATION);
1460 int UtcDaliImageViewResourceReadySignalWithReusedImage02(void)
1462 tet_infoline("Test Setting Image that was already loaded by another ImageView and still getting ResourceReadySignal when staged.");
1464 ToolkitTestApplication application;
1466 gResourceReadySignalFired = false;
1468 Property::Map imageImmediateLoadingMap;
1469 imageImmediateLoadingMap[ImageVisual::Property::URL] = gImage_34_RGBA;
1470 imageImmediateLoadingMap[ImageVisual::Property::LOAD_POLICY] = ImageVisual::LoadPolicy::IMMEDIATE;
1472 tet_infoline("Immediate load an image");
1473 ImageView imageView = ImageView::New();
1474 imageView.ResourceReadySignal().Connect(&ResourceReadySignal);
1475 imageView.SetProperty(ImageView::Property::IMAGE, imageImmediateLoadingMap);
1477 // loading started, this waits for the loader thread
1478 DALI_TEST_EQUALS(Test::WaitForEventThreadTrigger(1), true, TEST_LOCATION);
1480 application.SendNotification();
1481 application.Render(16);
1483 tet_infoline("Check image loaded");
1484 DALI_TEST_EQUALS(gResourceReadySignalFired, true, TEST_LOCATION);
1485 gResourceReadySignalFired = false;
1487 tet_infoline("Create another ImageView with the same URL");
1488 ImageView imageViewWithExistingImage = ImageView::New(gImage_34_RGBA);
1489 tet_infoline("Connect to ResourceReady signal for second ImageView, it should still fire as resource is ready");
1490 imageViewWithExistingImage.ResourceReadySignal().Connect(&ResourceReadySignal);
1492 application.GetScene().Add(imageViewWithExistingImage);
1494 DALI_TEST_EQUALS(gResourceReadySignalFired, true, TEST_LOCATION);
1499 int UtcDaliImageViewPaddingProperty(void)
1501 ToolkitTestApplication application;
1503 ImageView imageView = ImageView::New();
1504 Property::Map imagePropertyMap;
1505 imagePropertyMap[Toolkit::Visual::Property::TYPE] = Toolkit::Visual::IMAGE;
1506 imagePropertyMap[Toolkit::ImageVisual::Property::URL] = TEST_RESOURCE_DIR "/gallery-small-1.jpg";
1507 imagePropertyMap[ImageVisual::Property::DESIRED_WIDTH] = 128;
1508 imagePropertyMap[ImageVisual::Property::DESIRED_HEIGHT] = 128;
1509 imageView.SetProperty(Toolkit::ImageView::Property::IMAGE, imagePropertyMap);
1510 imageView.SetProperty(Actor::Property::ANCHOR_POINT, AnchorPoint::TOP_LEFT);
1511 imageView.SetProperty(Actor::Property::PARENT_ORIGIN, ParentOrigin::TOP_LEFT);
1512 imageView.SetProperty(Control::Property::PADDING, Extents(15, 10, 5, 10));
1513 application.GetScene().Add(imageView);
1515 application.SendNotification();
1516 application.Render();
1518 DALI_TEST_EQUALS(imageView.GetProperty<Extents>(Control::Property::PADDING), Extents(15, 10, 5, 10), TEST_LOCATION);
1520 ImageView childImage = ImageView::New();
1521 childImage.SetBackgroundColor(Color::BLACK);
1522 childImage.SetProperty(Actor::Property::SIZE, Vector2(10.f, 10.f));
1523 imageView.Add(childImage);
1525 application.SendNotification();
1526 application.Render();
1528 // Child ImageView should be positioned dependinig on Parent ImageView's Padding value
1529 DALI_TEST_EQUALS(childImage.GetProperty<Vector3>(Dali::Actor::Property::POSITION), Vector3(15, 5, 0), TEST_LOCATION);
1531 // Check whether Image Visual transforms on ImageVieiw::OnRelayout()
1532 Toolkit::Internal::Control& controlImpl = Toolkit::Internal::GetImplementation(imageView);
1533 Toolkit::Visual::Base imageVisual = DevelControl::GetVisual(controlImpl, ImageView::Property::IMAGE);
1534 Property::Map resultMap;
1535 imageVisual.CreatePropertyMap(resultMap);
1537 Property::Value* transformValue = resultMap.Find(Visual::Property::TRANSFORM);
1538 DALI_TEST_CHECK(transformValue);
1539 Property::Map* retMap = transformValue->GetMap();
1540 DALI_TEST_CHECK(retMap);
1542 // Image Visual should be positioned depending on ImageView's padding
1543 DALI_TEST_EQUALS(retMap->Find(Visual::Transform::Property::OFFSET)->Get<Vector2>(), Vector2(15, 5), TEST_LOCATION);
1548 int UtcDaliImageViewPaddingProperty02(void)
1550 ToolkitTestApplication application;
1552 ImageView imageView = ImageView::New();
1553 Property::Map imagePropertyMap;
1554 imagePropertyMap[Toolkit::Visual::Property::TYPE] = Toolkit::Visual::IMAGE;
1555 imagePropertyMap[Toolkit::ImageVisual::Property::URL] = TEST_RESOURCE_DIR "/Kid1.svg";
1556 imagePropertyMap[ImageVisual::Property::DESIRED_WIDTH] = 128;
1557 imagePropertyMap[ImageVisual::Property::DESIRED_HEIGHT] = 128;
1558 imagePropertyMap[DevelVisual::Property::VISUAL_FITTING_MODE] = Toolkit::DevelVisual::FIT_KEEP_ASPECT_RATIO;
1559 imageView.SetProperty(Toolkit::ImageView::Property::IMAGE, imagePropertyMap);
1560 imageView.SetProperty(Actor::Property::ANCHOR_POINT, AnchorPoint::TOP_LEFT);
1561 imageView.SetProperty(Actor::Property::PARENT_ORIGIN, ParentOrigin::TOP_LEFT);
1562 imageView.SetProperty(Control::Property::PADDING, Extents(15, 10, 5, 10));
1563 application.GetScene().Add(imageView);
1565 application.SendNotification();
1566 application.Render();
1568 DALI_TEST_EQUALS(imageView.GetProperty<Extents>(Control::Property::PADDING), Extents(15, 10, 5, 10), TEST_LOCATION);
1570 // Check whether Image Visual transforms on ImageVieiw::OnRelayout()
1571 Toolkit::Internal::Control& controlImpl = Toolkit::Internal::GetImplementation(imageView);
1572 Toolkit::Visual::Base imageVisual = DevelControl::GetVisual(controlImpl, ImageView::Property::IMAGE);
1573 Property::Map resultMap;
1574 imageVisual.CreatePropertyMap(resultMap);
1576 Property::Value* transformValue = resultMap.Find(Visual::Property::TRANSFORM);
1577 DALI_TEST_CHECK(transformValue);
1578 Property::Map* retMap = transformValue->GetMap();
1579 DALI_TEST_CHECK(retMap);
1581 // Image Visual should be positioned depending on ImageView's padding
1582 DALI_TEST_EQUALS(retMap->Find(Visual::Transform::Property::OFFSET)->Get<Vector2>(), Vector2(15, 5), TEST_LOCATION);
1587 int UtcDaliImageViewPaddingProperty03(void)
1589 tet_infoline("Test Setting Image Padding then removing it.");
1591 ToolkitTestApplication application;
1593 ImageView imageView = ImageView::New();
1594 Property::Map imagePropertyMap;
1595 imagePropertyMap[Toolkit::Visual::Property::TYPE] = Toolkit::Visual::IMAGE;
1596 imagePropertyMap[Toolkit::ImageVisual::Property::URL] = TEST_RESOURCE_DIR "/Kid1.svg";
1597 imagePropertyMap[ImageVisual::Property::DESIRED_WIDTH] = 128;
1598 imagePropertyMap[ImageVisual::Property::DESIRED_HEIGHT] = 128;
1599 imagePropertyMap[DevelVisual::Property::VISUAL_FITTING_MODE] = Toolkit::DevelVisual::FIT_KEEP_ASPECT_RATIO;
1600 imageView.SetProperty(Toolkit::ImageView::Property::IMAGE, imagePropertyMap);
1601 imageView.SetProperty(Actor::Property::ANCHOR_POINT, AnchorPoint::TOP_LEFT);
1602 imageView.SetProperty(Actor::Property::PARENT_ORIGIN, ParentOrigin::TOP_LEFT);
1603 imageView.SetProperty(Control::Property::PADDING, Extents(15, 10, 5, 10));
1604 application.GetScene().Add(imageView);
1606 application.SendNotification();
1607 application.Render();
1609 DALI_TEST_EQUALS(imageView.GetProperty<Extents>(Control::Property::PADDING), Extents(15, 10, 5, 10), TEST_LOCATION);
1611 tet_infoline("Remove Padding and test Visual is position correctly");
1613 imageView.SetProperty(Control::Property::PADDING, Extents(0, 0, 0, 0));
1615 application.SendNotification();
1616 application.Render();
1618 // Check whether Image Visual transforms on ImageVieiw::OnRelayout()
1619 Toolkit::Internal::Control& controlImpl = Toolkit::Internal::GetImplementation(imageView);
1620 Toolkit::Visual::Base imageVisual = DevelControl::GetVisual(controlImpl, ImageView::Property::IMAGE);
1621 Property::Map resultMap;
1622 imageVisual.CreatePropertyMap(resultMap);
1624 Property::Value* transformValue = resultMap.Find(Visual::Property::TRANSFORM);
1625 DALI_TEST_CHECK(transformValue);
1626 Property::Map* retMap = transformValue->GetMap();
1627 DALI_TEST_CHECK(retMap);
1629 // Image Visual should be positioned depending on ImageView's padding
1630 DALI_TEST_EQUALS(retMap->Find(Visual::Transform::Property::OFFSET)->Get<Vector2>(), Vector2(0, 0), TEST_LOCATION);
1635 int UtcDaliImageViewPaddingProperty04(void)
1637 tet_infoline("Test Setting Image Padding then removing it. Visual Fitting Mode as Fill");
1639 ToolkitTestApplication application;
1641 ImageView imageView = ImageView::New();
1642 Property::Map imagePropertyMap;
1643 imagePropertyMap[Toolkit::Visual::Property::TYPE] = Toolkit::Visual::IMAGE;
1644 imagePropertyMap[Toolkit::ImageVisual::Property::URL] = TEST_RESOURCE_DIR "/Kid1.svg";
1645 imagePropertyMap[ImageVisual::Property::DESIRED_WIDTH] = 128;
1646 imagePropertyMap[ImageVisual::Property::DESIRED_HEIGHT] = 128;
1647 imagePropertyMap[DevelVisual::Property::VISUAL_FITTING_MODE] = Toolkit::DevelVisual::FILL;
1648 imageView.SetProperty(Toolkit::ImageView::Property::IMAGE, imagePropertyMap);
1649 imageView.SetProperty(Actor::Property::ANCHOR_POINT, AnchorPoint::TOP_LEFT);
1650 imageView.SetProperty(Actor::Property::PARENT_ORIGIN, ParentOrigin::TOP_LEFT);
1651 imageView.SetProperty(Control::Property::PADDING, Extents(15, 10, 5, 10));
1652 application.GetScene().Add(imageView);
1654 application.SendNotification();
1655 application.Render();
1657 DALI_TEST_EQUALS(imageView.GetProperty<Extents>(Control::Property::PADDING), Extents(15, 10, 5, 10), TEST_LOCATION);
1659 tet_infoline("Remove Padding and test Visual is position correctly");
1661 imageView.SetProperty(Control::Property::PADDING, Extents(0, 0, 0, 0));
1663 application.SendNotification();
1664 application.Render();
1666 // Check whether Image Visual transforms on ImageVieiw::OnRelayout()
1667 Toolkit::Internal::Control& controlImpl = Toolkit::Internal::GetImplementation(imageView);
1668 Toolkit::Visual::Base imageVisual = DevelControl::GetVisual(controlImpl, ImageView::Property::IMAGE);
1669 Property::Map resultMap;
1670 imageVisual.CreatePropertyMap(resultMap);
1672 Property::Value* transformValue = resultMap.Find(Visual::Property::TRANSFORM);
1673 DALI_TEST_CHECK(transformValue);
1674 Property::Map* retMap = transformValue->GetMap();
1675 DALI_TEST_CHECK(retMap);
1677 // Image Visual should be positioned depending on ImageView's padding
1678 DALI_TEST_EQUALS(retMap->Find(Visual::Transform::Property::OFFSET)->Get<Vector2>(), Vector2(0, 0), TEST_LOCATION);
1683 int UtcDaliImageViewTransformTest01(void)
1685 tet_infoline("Test Setting a offset transform on the ImageView");
1687 ToolkitTestApplication application;
1689 ImageView imageView = ImageView::New();
1690 Property::Map imagePropertyMap;
1691 imagePropertyMap.Add(Toolkit::Visual::Property::TYPE, Toolkit::Visual::IMAGE)
1692 .Add(Toolkit::ImageVisual::Property::URL, TEST_RESOURCE_DIR "/Kid1.svg")
1693 .Add(ImageVisual::Property::DESIRED_WIDTH, 120)
1694 .Add(ImageVisual::Property::DESIRED_HEIGHT, 120)
1695 .Add(DevelVisual::Property::VISUAL_FITTING_MODE, Toolkit::DevelVisual::FILL)
1696 .Add(Visual::Property::TRANSFORM,
1697 Property::Map().Add(Toolkit::Visual::Transform::Property::OFFSET_POLICY,
1698 Vector2(Visual::Transform::Policy::ABSOLUTE, Visual::Transform::Policy::ABSOLUTE))
1699 .Add(Toolkit::Visual::Transform::Property::OFFSET, Vector2(8, 8)));
1701 imageView.SetProperty(Toolkit::ImageView::Property::IMAGE, imagePropertyMap);
1702 imageView.SetProperty(Actor::Property::ANCHOR_POINT, AnchorPoint::TOP_LEFT);
1703 imageView.SetProperty(Actor::Property::PARENT_ORIGIN, ParentOrigin::TOP_LEFT);
1704 application.GetScene().Add(imageView);
1706 application.SendNotification();
1707 application.Render();
1709 // Check whether Image Visual transforms on ImageVieiw::OnRelayout()
1710 Toolkit::Internal::Control& controlImpl = Toolkit::Internal::GetImplementation(imageView);
1711 Toolkit::Visual::Base imageVisual = DevelControl::GetVisual(controlImpl, ImageView::Property::IMAGE);
1712 Property::Map resultMap;
1713 imageVisual.CreatePropertyMap(resultMap);
1715 Property::Value* transformValue = resultMap.Find(Visual::Property::TRANSFORM);
1716 DALI_TEST_CHECK(transformValue);
1717 Property::Map* retMap = transformValue->GetMap();
1718 DALI_TEST_CHECK(retMap);
1720 // Image Visual should be positioned depending on ImageView's padding
1721 DALI_TEST_EQUALS(retMap->Find(Visual::Transform::Property::OFFSET)->Get<Vector2>(), Vector2(8, 8), TEST_LOCATION);
1722 DALI_TEST_EQUALS(retMap->Find(Visual::Transform::Property::OFFSET_POLICY)->Get<Vector2>(), Vector2(Toolkit::Visual::Transform::Policy::ABSOLUTE, Toolkit::Visual::Transform::Policy::ABSOLUTE), TEST_LOCATION);
1727 int UtcDaliImageViewUsingAtlasAndGetNaturalSize(void)
1729 ToolkitTestApplication application;
1731 // Check ImageView with background and main image, to ensure both visuals are marked as loaded
1732 ImageView imageView = ImageView::New();
1733 Property::Map imageMap;
1734 imageMap[Toolkit::Visual::Property::TYPE] = Toolkit::Visual::IMAGE;
1735 imageMap[Toolkit::ImageVisual::Property::URL] = gImage_34_RGBA;
1736 imageMap[Toolkit::ImageVisual::Property::ATLASING] = true;
1737 imageView.SetProperty(Toolkit::ImageView::Property::IMAGE, imageMap);
1738 application.GetScene().Add(imageView);
1740 // Trigger a potential relayout
1741 application.SendNotification();
1742 application.Render();
1744 Vector3 naturalSize = imageView.GetNaturalSize();
1746 DALI_TEST_EQUALS(naturalSize.width, 34.0f, TEST_LOCATION);
1747 DALI_TEST_EQUALS(naturalSize.height, 34.0f, TEST_LOCATION);
1752 int UtcDaliImageViewFillMode(void)
1754 ToolkitTestApplication application;
1756 tet_infoline("Create an ImageVisual without padding and set the fill-mode to fill");
1758 ImageView imageView = ImageView::New();
1759 Property::Map imageMap;
1760 imageMap.Add(Toolkit::Visual::Property::TYPE, Toolkit::Visual::IMAGE);
1761 imageMap.Add(Toolkit::ImageVisual::Property::URL, gImage_600_RGB);
1762 imageMap.Add(DevelVisual::Property::VISUAL_FITTING_MODE, DevelVisual::FittingMode::FILL);
1764 imageView.SetProperty(Toolkit::ImageView::Property::IMAGE, imageMap);
1766 application.GetScene().Add(imageView);
1768 // Trigger a potential relayout
1769 application.SendNotification();
1770 application.Render();
1772 Toolkit::Visual::Base visual = DevelControl::GetVisual(Toolkit::Internal::GetImplementation(imageView), Toolkit::ImageView::Property::IMAGE);
1773 Property::Map returnedMap;
1774 visual.CreatePropertyMap(returnedMap);
1776 Property::Value* value = returnedMap.Find(Toolkit::Visual::Property::TRANSFORM);
1777 DALI_TEST_CHECK(value);
1778 Property::Map* map = value->GetMap();
1779 DALI_TEST_CHECK(map);
1781 value = map->Find(Toolkit::Visual::Transform::Property::SIZE);
1782 DALI_TEST_CHECK(value);
1783 DALI_TEST_EQUALS(value->Get<Vector2>(), Vector2::ONE, TEST_LOCATION);
1785 value = map->Find(Toolkit::Visual::Transform::Property::SIZE_POLICY);
1786 DALI_TEST_CHECK(value);
1787 DALI_TEST_CHECK(value->Get<int>() == Toolkit::Visual::Transform::Policy::RELATIVE);
1792 int UtcDaliImageViewFittingModeFitKeepAspectRatio(void)
1794 ToolkitTestApplication application;
1796 tet_infoline("Create an ImageVisual using FitKeepAspectRatio ( image: [600,600], view: [600,700] )");
1797 tet_infoline(" There should be need to change the transform, offset is adjusted to fit inside");
1799 ImageView imageView = ImageView::New();
1800 Property::Map imageMap;
1801 imageMap.Add(Toolkit::Visual::Property::TYPE, Toolkit::Visual::IMAGE);
1802 imageMap.Add(Toolkit::ImageVisual::Property::URL, gImage_600_RGB); // 600x600 image
1803 imageMap.Add(DevelVisual::Property::VISUAL_FITTING_MODE, Toolkit::DevelVisual::FIT_KEEP_ASPECT_RATIO);
1805 imageView.SetProperty(Toolkit::ImageView::Property::IMAGE, imageMap);
1806 imageView.SetProperty(Actor::Property::SIZE, Vector2(600, 700));
1808 application.GetScene().Add(imageView);
1810 // Trigger a potential relayout
1811 application.SendNotification();
1812 application.Render();
1814 Toolkit::Visual::Base visual = DevelControl::GetVisual(Toolkit::Internal::GetImplementation(imageView), Toolkit::ImageView::Property::IMAGE);
1815 Property::Map returnedMap;
1816 visual.CreatePropertyMap(returnedMap);
1818 Property::Value* value = returnedMap.Find(Toolkit::Visual::Property::TRANSFORM);
1819 DALI_TEST_CHECK(value);
1820 Property::Map* map = value->GetMap();
1821 DALI_TEST_CHECK(map);
1824 value = map->Find(Toolkit::Visual::Transform::Property::SIZE);
1825 DALI_TEST_CHECK(value);
1826 DALI_TEST_EQUALS(value->Get<Vector2>(), Vector2(600, 600), TEST_LOCATION);
1828 value = map->Find(Toolkit::Visual::Transform::Property::SIZE_POLICY);
1829 DALI_TEST_CHECK(value);
1830 DALI_TEST_EQUALS(value->Get<Vector2>(), Vector2(Toolkit::Visual::Transform::Policy::ABSOLUTE, Toolkit::Visual::Transform::Policy::ABSOLUTE), TEST_LOCATION);
1832 value = map->Find(Toolkit::Visual::Transform::Property::OFFSET);
1833 DALI_TEST_CHECK(value);
1834 DALI_TEST_EQUALS(value->Get<Vector2>(), Vector2(0, 50), TEST_LOCATION);
1839 int UtcDaliImageViewFittingModesFill(void)
1841 ToolkitTestApplication application;
1843 tet_infoline("Create an ImageVisual using Fill ( image: [600,600], view: [600,700] )");
1844 tet_infoline(" There should be no need to change the transform, only size is changed to fit view");
1846 ImageView imageView = ImageView::New();
1847 Property::Map imageMap;
1848 imageMap.Add(Toolkit::Visual::Property::TYPE, Toolkit::Visual::IMAGE);
1849 imageMap.Add(Toolkit::ImageVisual::Property::URL, gImage_600_RGB); // 600x600 image
1850 imageMap.Add(DevelVisual::Property::VISUAL_FITTING_MODE, Toolkit::DevelVisual::FILL);
1852 imageView.SetProperty(Toolkit::ImageView::Property::IMAGE, imageMap);
1853 imageView.SetProperty(Actor::Property::SIZE, Vector2(600, 700));
1855 application.GetScene().Add(imageView);
1857 // Trigger a potential relayout
1858 application.SendNotification();
1859 application.Render();
1861 Toolkit::Visual::Base visual = DevelControl::GetVisual(Toolkit::Internal::GetImplementation(imageView), Toolkit::ImageView::Property::IMAGE);
1862 Property::Map returnedMap;
1863 visual.CreatePropertyMap(returnedMap);
1865 Property::Value* value = returnedMap.Find(Toolkit::Visual::Property::TRANSFORM);
1866 DALI_TEST_CHECK(value);
1867 Property::Map* map = value->GetMap();
1868 DALI_TEST_CHECK(map);
1870 value = map->Find(Toolkit::Visual::Transform::Property::SIZE);
1871 DALI_TEST_CHECK(value);
1872 DALI_TEST_EQUALS(value->Get<Vector2>(), Vector2::ONE, TEST_LOCATION); // Change the internal size according to the image view size
1874 value = map->Find(Toolkit::Visual::Transform::Property::SIZE_POLICY);
1875 DALI_TEST_CHECK(value);
1876 DALI_TEST_CHECK(value->Get<int>() == Toolkit::Visual::Transform::Policy::RELATIVE);
1878 value = map->Find(Toolkit::Visual::Transform::Property::OFFSET);
1879 DALI_TEST_CHECK(value);
1880 DALI_TEST_EQUALS(value->Get<Vector2>(), Vector2(0, 0), TEST_LOCATION); // OFFSET is zero
1885 int UtcDaliImageViewFittingModesOverfitKeepAspectRatio(void)
1887 ToolkitTestApplication application;
1889 tet_infoline("Create an ImageVisual using OverFitKeepAspectRatio ( image: [600,600], view: [600,500] )");
1890 tet_infoline(" offset or size is the same as view, but adjust internally using pixelArea ");
1892 ImageView imageView = ImageView::New();
1893 Property::Map imageMap;
1894 imageMap.Add(Toolkit::Visual::Property::TYPE, Toolkit::Visual::IMAGE);
1895 imageMap.Add(Toolkit::ImageVisual::Property::URL, gImage_600_RGB); // 600x600 image
1896 imageMap.Add(DevelVisual::Property::VISUAL_FITTING_MODE, Toolkit::DevelVisual::OVER_FIT_KEEP_ASPECT_RATIO);
1898 imageView.SetProperty(Toolkit::ImageView::Property::IMAGE, imageMap);
1899 imageView.SetProperty(Actor::Property::SIZE, Vector2(600, 500));
1901 application.GetScene().Add(imageView);
1903 // Trigger a potential relayout
1904 application.SendNotification();
1905 application.Render();
1907 Toolkit::Visual::Base visual = DevelControl::GetVisual(Toolkit::Internal::GetImplementation(imageView), Toolkit::ImageView::Property::IMAGE);
1908 Property::Map returnedMap;
1909 visual.CreatePropertyMap(returnedMap);
1911 Property::Value* value = returnedMap.Find(Toolkit::Visual::Property::TRANSFORM);
1912 DALI_TEST_CHECK(value);
1913 Property::Map* map = value->GetMap();
1914 DALI_TEST_CHECK(map);
1917 value = map->Find(Toolkit::Visual::Transform::Property::SIZE);
1918 DALI_TEST_CHECK(value);
1919 DALI_TEST_EQUALS(value->Get<Vector2>(), Vector2(600, 500), TEST_LOCATION); // Change the internal size according to the image view size
1921 value = map->Find(Toolkit::Visual::Transform::Property::SIZE_POLICY);
1922 DALI_TEST_CHECK(value);
1923 DALI_TEST_EQUALS(value->Get<Vector2>(), Vector2(Toolkit::Visual::Transform::Policy::ABSOLUTE, Toolkit::Visual::Transform::Policy::ABSOLUTE), TEST_LOCATION);
1925 value = map->Find(Toolkit::Visual::Transform::Property::OFFSET);
1926 DALI_TEST_CHECK(value);
1927 DALI_TEST_EQUALS(value->Get<Vector2>(), Vector2(0, 0), TEST_LOCATION); // OFFSET is zero
1932 int UtcDaliImageViewFittingModesCenter01(void)
1934 ToolkitTestApplication application;
1936 tet_infoline("Create an ImageVisual using Center ( image: [600,600], view: [700,700] )");
1937 tet_infoline(" There should be need to change the transform, offset is adjusted to fit inside");
1939 ImageView imageView = ImageView::New();
1940 Property::Map imageMap;
1941 imageMap.Add(Toolkit::Visual::Property::TYPE, Toolkit::Visual::IMAGE);
1942 imageMap.Add(Toolkit::ImageVisual::Property::URL, gImage_600_RGB); // 600x600 image
1943 imageMap.Add(DevelVisual::Property::VISUAL_FITTING_MODE, Toolkit::DevelVisual::CENTER);
1945 imageView.SetProperty(Toolkit::ImageView::Property::IMAGE, imageMap);
1946 imageView.SetProperty(Actor::Property::SIZE, Vector2(700, 700));
1948 application.GetScene().Add(imageView);
1950 // Trigger a potential relayout
1951 application.SendNotification();
1952 application.Render();
1954 Toolkit::Visual::Base visual = DevelControl::GetVisual(Toolkit::Internal::GetImplementation(imageView), Toolkit::ImageView::Property::IMAGE);
1955 Property::Map returnedMap;
1956 visual.CreatePropertyMap(returnedMap);
1958 Property::Value* value = returnedMap.Find(Toolkit::Visual::Property::TRANSFORM);
1959 DALI_TEST_CHECK(value);
1960 Property::Map* map = value->GetMap();
1961 DALI_TEST_CHECK(map);
1963 value = map->Find(Toolkit::Visual::Transform::Property::SIZE);
1964 DALI_TEST_CHECK(value);
1965 DALI_TEST_EQUALS(value->Get<Vector2>(), Vector2(600, 600), TEST_LOCATION); // Change the internal size according to the image view size
1967 value = map->Find(Toolkit::Visual::Transform::Property::SIZE_POLICY);
1968 DALI_TEST_CHECK(value);
1969 DALI_TEST_EQUALS(value->Get<Vector2>(), Vector2(Toolkit::Visual::Transform::Policy::ABSOLUTE, Toolkit::Visual::Transform::Policy::ABSOLUTE), TEST_LOCATION);
1971 value = map->Find(Toolkit::Visual::Transform::Property::OFFSET);
1972 DALI_TEST_CHECK(value);
1973 DALI_TEST_EQUALS(value->Get<Vector2>(), Vector2(50, 50), TEST_LOCATION);
1978 int UtcDaliImageViewFittingModesCenter02(void)
1980 ToolkitTestApplication application;
1982 tet_infoline("Create an ImageVisual using Center ( image: [600,600], view: [500,500] )");
1983 tet_infoline(" There should be need to change the transform, offset is adjusted to fit inside");
1985 ImageView imageView = ImageView::New();
1986 Property::Map imageMap;
1987 imageMap.Add(Toolkit::Visual::Property::TYPE, Toolkit::Visual::IMAGE);
1988 imageMap.Add(Toolkit::ImageVisual::Property::URL, gImage_600_RGB); // 600x600 image
1989 imageMap.Add(DevelVisual::Property::VISUAL_FITTING_MODE, Toolkit::DevelVisual::CENTER);
1991 imageView.SetProperty(Toolkit::ImageView::Property::IMAGE, imageMap);
1992 imageView.SetProperty(Actor::Property::SIZE, Vector2(700, 700));
1994 application.GetScene().Add(imageView);
1996 // Trigger a potential relayout
1997 application.SendNotification();
1998 application.Render();
2000 Toolkit::Visual::Base visual = DevelControl::GetVisual(Toolkit::Internal::GetImplementation(imageView), Toolkit::ImageView::Property::IMAGE);
2001 Property::Map returnedMap;
2002 visual.CreatePropertyMap(returnedMap);
2004 Property::Value* value = returnedMap.Find(Toolkit::Visual::Property::TRANSFORM);
2005 DALI_TEST_CHECK(value);
2006 Property::Map* map = value->GetMap();
2007 DALI_TEST_CHECK(map);
2009 value = map->Find(Toolkit::Visual::Transform::Property::SIZE);
2010 DALI_TEST_CHECK(value);
2011 DALI_TEST_EQUALS(value->Get<Vector2>(), Vector2(600, 600), TEST_LOCATION); // Change the internal size according to the image view size
2013 value = map->Find(Toolkit::Visual::Transform::Property::SIZE_POLICY);
2014 DALI_TEST_CHECK(value);
2015 DALI_TEST_EQUALS(value->Get<Vector2>(), Vector2(Toolkit::Visual::Transform::Policy::ABSOLUTE, Toolkit::Visual::Transform::Policy::ABSOLUTE), TEST_LOCATION);
2017 value = map->Find(Toolkit::Visual::Transform::Property::OFFSET);
2018 DALI_TEST_CHECK(value);
2019 DALI_TEST_EQUALS(value->Get<Vector2>(), Vector2(50, 50), TEST_LOCATION);
2024 int UtcDaliImageViewFittingModesFitHeight01(void)
2026 ToolkitTestApplication application;
2028 tet_infoline("Create an ImageVisual using FitHeight ( image: [600,600], view: [600,700] )");
2030 ImageView imageView = ImageView::New();
2031 Property::Map imageMap;
2032 imageMap.Add(Toolkit::Visual::Property::TYPE, Toolkit::Visual::IMAGE);
2033 imageMap.Add(Toolkit::ImageVisual::Property::URL, gImage_600_RGB); // 600x600 image
2034 imageMap.Add(DevelVisual::Property::VISUAL_FITTING_MODE, Toolkit::DevelVisual::FIT_HEIGHT);
2036 imageView.SetProperty(Toolkit::ImageView::Property::IMAGE, imageMap);
2037 imageView.SetProperty(Actor::Property::SIZE, Vector2(600, 700));
2039 application.GetScene().Add(imageView);
2041 // Trigger a potential relayout
2042 application.SendNotification();
2043 application.Render();
2045 Toolkit::Visual::Base visual = DevelControl::GetVisual(Toolkit::Internal::GetImplementation(imageView), Toolkit::ImageView::Property::IMAGE);
2046 Property::Map returnedMap;
2047 visual.CreatePropertyMap(returnedMap);
2049 Property::Value* value = returnedMap.Find(Toolkit::Visual::Property::TRANSFORM);
2050 DALI_TEST_CHECK(value);
2051 Property::Map* map = value->GetMap();
2052 DALI_TEST_CHECK(map);
2054 value = map->Find(Toolkit::Visual::Transform::Property::SIZE);
2055 DALI_TEST_CHECK(value);
2056 DALI_TEST_EQUALS(value->Get<Vector2>(), Vector2(600, 700), TEST_LOCATION); // Change the internal size according to the image view size
2058 value = map->Find(Toolkit::Visual::Transform::Property::SIZE_POLICY);
2059 DALI_TEST_CHECK(value);
2060 DALI_TEST_EQUALS(value->Get<Vector2>(), Vector2(Toolkit::Visual::Transform::Policy::ABSOLUTE, Toolkit::Visual::Transform::Policy::ABSOLUTE), TEST_LOCATION);
2062 value = map->Find(Toolkit::Visual::Transform::Property::OFFSET);
2063 DALI_TEST_CHECK(value);
2064 DALI_TEST_EQUALS(value->Get<Vector2>(), Vector2(0, 0), TEST_LOCATION); // OFFSET is zero
2069 int UtcDaliImageViewFittingModesFitHeight02(void)
2071 ToolkitTestApplication application;
2073 tet_infoline("Create an ImageVisual using FitHeight ( image: [600,600], view: [700,600] )");
2075 ImageView imageView = ImageView::New();
2076 Property::Map imageMap;
2077 imageMap.Add(Toolkit::Visual::Property::TYPE, Toolkit::Visual::IMAGE);
2078 imageMap.Add(Toolkit::ImageVisual::Property::URL, gImage_600_RGB); // 249x169 image
2079 imageMap.Add(DevelVisual::Property::VISUAL_FITTING_MODE, Toolkit::DevelVisual::FIT_HEIGHT);
2081 imageView.SetProperty(Toolkit::ImageView::Property::IMAGE, imageMap);
2082 imageView.SetProperty(Actor::Property::SIZE, Vector2(700, 600));
2084 application.GetScene().Add(imageView);
2086 // Trigger a potential relayout
2087 application.SendNotification();
2088 application.Render();
2090 Toolkit::Visual::Base visual = DevelControl::GetVisual(Toolkit::Internal::GetImplementation(imageView), Toolkit::ImageView::Property::IMAGE);
2091 Property::Map returnedMap;
2092 visual.CreatePropertyMap(returnedMap);
2094 Property::Value* value = returnedMap.Find(Toolkit::Visual::Property::TRANSFORM);
2095 DALI_TEST_CHECK(value);
2096 Property::Map* map = value->GetMap();
2097 DALI_TEST_CHECK(map);
2099 value = map->Find(Toolkit::Visual::Transform::Property::SIZE);
2100 DALI_TEST_CHECK(value);
2101 DALI_TEST_EQUALS(value->Get<Vector2>(), Vector2(600, 600), TEST_LOCATION); // Change the internal size according to the image view size
2103 value = map->Find(Toolkit::Visual::Transform::Property::SIZE_POLICY);
2104 DALI_TEST_CHECK(value);
2105 DALI_TEST_EQUALS(value->Get<Vector2>(), Vector2(Toolkit::Visual::Transform::Policy::ABSOLUTE, Toolkit::Visual::Transform::Policy::ABSOLUTE), TEST_LOCATION);
2107 value = map->Find(Toolkit::Visual::Transform::Property::OFFSET);
2108 DALI_TEST_CHECK(value);
2109 DALI_TEST_EQUALS(value->Get<Vector2>(), Vector2(50, 0), TEST_LOCATION);
2114 int UtcDaliImageViewFittingModesFitWidth01(void)
2116 ToolkitTestApplication application;
2118 tet_infoline("Create an ImageVisual using FitWidth ( image: [600,600], view: [600,700] )");
2120 ImageView imageView = ImageView::New();
2121 Property::Map imageMap;
2122 imageMap.Add(Toolkit::Visual::Property::TYPE, Toolkit::Visual::IMAGE);
2123 imageMap.Add(Toolkit::ImageVisual::Property::URL, gImage_600_RGB); // 600x600 image
2124 imageMap.Add(DevelVisual::Property::VISUAL_FITTING_MODE, Toolkit::DevelVisual::FIT_WIDTH);
2126 imageView.SetProperty(Toolkit::ImageView::Property::IMAGE, imageMap);
2127 imageView.SetProperty(Actor::Property::SIZE, Vector2(600, 700));
2129 application.GetScene().Add(imageView);
2131 // Trigger a potential relayout
2132 application.SendNotification();
2133 application.Render();
2135 Toolkit::Visual::Base visual = DevelControl::GetVisual(Toolkit::Internal::GetImplementation(imageView), Toolkit::ImageView::Property::IMAGE);
2136 Property::Map returnedMap;
2137 visual.CreatePropertyMap(returnedMap);
2139 Property::Value* value = returnedMap.Find(Toolkit::Visual::Property::TRANSFORM);
2140 DALI_TEST_CHECK(value);
2141 Property::Map* map = value->GetMap();
2142 DALI_TEST_CHECK(map);
2144 value = map->Find(Toolkit::Visual::Transform::Property::SIZE);
2145 DALI_TEST_CHECK(value);
2146 DALI_TEST_EQUALS(value->Get<Vector2>(), Vector2(600, 600), TEST_LOCATION); // Change the internal size according to the image view size
2148 value = map->Find(Toolkit::Visual::Transform::Property::SIZE_POLICY);
2149 DALI_TEST_CHECK(value);
2150 DALI_TEST_EQUALS(value->Get<Vector2>(), Vector2(Toolkit::Visual::Transform::Policy::ABSOLUTE, Toolkit::Visual::Transform::Policy::ABSOLUTE), TEST_LOCATION);
2152 value = map->Find(Toolkit::Visual::Transform::Property::OFFSET);
2153 DALI_TEST_CHECK(value);
2154 DALI_TEST_EQUALS(value->Get<Vector2>(), Vector2(0, 50), TEST_LOCATION);
2159 int UtcDaliImageViewFittingModesFitWidth02(void)
2161 ToolkitTestApplication application;
2163 tet_infoline("Create an ImageVisual using FitWidth ( image: [600,600], view:[700,600] )");
2165 ImageView imageView = ImageView::New();
2166 Property::Map imageMap;
2167 imageMap.Add(Toolkit::Visual::Property::TYPE, Toolkit::Visual::IMAGE);
2168 imageMap.Add(Toolkit::ImageVisual::Property::URL, gImage_600_RGB); // 249x169 image
2169 imageMap.Add(DevelVisual::Property::VISUAL_FITTING_MODE, Toolkit::DevelVisual::FIT_WIDTH);
2171 imageView.SetProperty(Toolkit::ImageView::Property::IMAGE, imageMap);
2172 imageView.SetProperty(Actor::Property::SIZE, Vector2(700, 600));
2174 application.GetScene().Add(imageView);
2176 // Trigger a potential relayout
2177 application.SendNotification();
2178 application.Render();
2180 Toolkit::Visual::Base visual = DevelControl::GetVisual(Toolkit::Internal::GetImplementation(imageView), Toolkit::ImageView::Property::IMAGE);
2181 Property::Map returnedMap;
2182 visual.CreatePropertyMap(returnedMap);
2184 Property::Value* value = returnedMap.Find(Toolkit::Visual::Property::TRANSFORM);
2185 DALI_TEST_CHECK(value);
2186 Property::Map* map = value->GetMap();
2187 DALI_TEST_CHECK(map);
2189 value = map->Find(Toolkit::Visual::Transform::Property::SIZE);
2190 DALI_TEST_CHECK(value);
2191 DALI_TEST_EQUALS(value->Get<Vector2>(), Vector2(700, 600), TEST_LOCATION); // Change the internal size according to the image view size
2193 value = map->Find(Toolkit::Visual::Transform::Property::SIZE_POLICY);
2194 DALI_TEST_CHECK(value);
2195 DALI_TEST_EQUALS(value->Get<Vector2>(), Vector2(Toolkit::Visual::Transform::Policy::ABSOLUTE, Toolkit::Visual::Transform::Policy::ABSOLUTE), TEST_LOCATION);
2197 value = map->Find(Toolkit::Visual::Transform::Property::OFFSET);
2198 DALI_TEST_CHECK(value);
2199 DALI_TEST_EQUALS(value->Get<Vector2>(), Vector2(0, 0), TEST_LOCATION); // OFFSET is zero
2204 int UtcDaliImageViewFittingModesChangeFittingMode01(void)
2206 ToolkitTestApplication application;
2208 tet_infoline("UtcDaliImageViewFittingModesChangeFittingMode, image: [600,600], view:[800,700]");
2210 ImageView imageView = ImageView::New();
2212 // 1. Render using FittingMode::SHRINK_TO_FIT
2213 Property::Map imageMap;
2214 imageMap[Toolkit::Visual::Property::TYPE] = Toolkit::Visual::IMAGE;
2215 imageMap[Toolkit::ImageVisual::Property::URL] = gImage_600_RGB;
2216 imageMap[DevelVisual::Property::VISUAL_FITTING_MODE] = Toolkit::DevelVisual::FIT_KEEP_ASPECT_RATIO;
2218 imageView.SetProperty(Toolkit::ImageView::Property::IMAGE, imageMap);
2219 imageView.SetProperty(Actor::Property::SIZE, Vector2(800, 700));
2221 application.GetScene().Add(imageView);
2223 // Trigger a potential relayout
2224 application.SendNotification();
2225 application.Render();
2227 Toolkit::Visual::Base visual = DevelControl::GetVisual(Toolkit::Internal::GetImplementation(imageView), Toolkit::ImageView::Property::IMAGE);
2228 Property::Map returnedMap;
2229 visual.CreatePropertyMap(returnedMap);
2231 Property::Value* value = returnedMap.Find(Toolkit::Visual::Property::TRANSFORM);
2232 DALI_TEST_CHECK(value);
2233 Property::Map* map = value->GetMap();
2234 DALI_TEST_CHECK(map);
2236 value = map->Find(Toolkit::Visual::Transform::Property::SIZE);
2237 DALI_TEST_CHECK(value);
2238 DALI_TEST_EQUALS(value->Get<Vector2>(), Vector2(700, 700), TEST_LOCATION); // Change the internal size according to the image view size
2240 value = map->Find(Toolkit::Visual::Transform::Property::SIZE_POLICY);
2241 DALI_TEST_CHECK(value);
2242 DALI_TEST_EQUALS(value->Get<Vector2>(), Vector2(Toolkit::Visual::Transform::Policy::ABSOLUTE, Toolkit::Visual::Transform::Policy::ABSOLUTE), TEST_LOCATION);
2244 value = map->Find(Toolkit::Visual::Transform::Property::OFFSET);
2245 DALI_TEST_CHECK(value);
2246 DALI_TEST_EQUALS(value->Get<Vector2>(), Vector2(50, 0), TEST_LOCATION);
2248 // 2. Render again using DevelVisaul::CENTER
2249 Property::Map imageMap2;
2250 imageMap2[Toolkit::Visual::Property::TYPE] = Toolkit::Visual::IMAGE;
2251 imageMap2[Toolkit::ImageVisual::Property::URL] = gImage_600_RGB;
2252 imageMap2[DevelVisual::Property::VISUAL_FITTING_MODE] = Toolkit::DevelVisual::CENTER;
2254 imageView.SetProperty(Toolkit::ImageView::Property::IMAGE, imageMap2);
2255 imageView.SetProperty(Actor::Property::SIZE, Vector2(800, 700));
2257 application.GetScene().Add(imageView);
2259 DALI_TEST_EQUALS(Test::WaitForEventThreadTrigger(1), true, TEST_LOCATION);
2261 // Trigger a potential relayout
2262 application.SendNotification();
2263 application.Render();
2265 returnedMap.Clear();
2266 visual = DevelControl::GetVisual(Toolkit::Internal::GetImplementation(imageView), Toolkit::ImageView::Property::IMAGE);
2268 visual.CreatePropertyMap(returnedMap);
2270 value = returnedMap.Find(Toolkit::Visual::Property::TRANSFORM);
2271 DALI_TEST_CHECK(value);
2272 map = value->GetMap();
2273 DALI_TEST_CHECK(map);
2275 value = map->Find(Toolkit::Visual::Transform::Property::SIZE);
2276 DALI_TEST_CHECK(value);
2277 DALI_TEST_EQUALS(value->Get<Vector2>(), Vector2(600, 600), TEST_LOCATION); // Change the internal size according to the image view size
2279 value = map->Find(Toolkit::Visual::Transform::Property::SIZE_POLICY);
2280 DALI_TEST_CHECK(value);
2281 DALI_TEST_EQUALS(value->Get<Vector2>(), Vector2(Toolkit::Visual::Transform::Policy::ABSOLUTE, Toolkit::Visual::Transform::Policy::ABSOLUTE), TEST_LOCATION);
2283 value = map->Find(Toolkit::Visual::Transform::Property::OFFSET);
2284 DALI_TEST_CHECK(value);
2285 DALI_TEST_EQUALS(value->Get<Vector2>(), Vector2(100, 50), TEST_LOCATION);
2287 // 3. Render again using before fittingMode
2288 Property::Map imageMap3;
2289 imageMap3[Toolkit::Visual::Property::TYPE] = Toolkit::Visual::IMAGE;
2290 imageMap3[Toolkit::ImageVisual::Property::URL] = gImage_600_RGB;
2291 imageMap3[DevelVisual::Property::VISUAL_FITTING_MODE] = Toolkit::DevelVisual::FIT_KEEP_ASPECT_RATIO;
2293 imageView.SetProperty(Toolkit::ImageView::Property::IMAGE, imageMap3);
2294 imageView.SetProperty(Actor::Property::SIZE, Vector2(800, 700));
2296 application.GetScene().Add(imageView);
2298 // Trigger a potential relayout
2299 application.SendNotification();
2300 application.Render();
2302 returnedMap.Clear();
2303 visual = DevelControl::GetVisual(Toolkit::Internal::GetImplementation(imageView), Toolkit::ImageView::Property::IMAGE);
2304 visual.CreatePropertyMap(returnedMap);
2306 value = returnedMap.Find(Toolkit::Visual::Property::TRANSFORM);
2307 DALI_TEST_CHECK(value);
2308 map = value->GetMap();
2309 DALI_TEST_CHECK(map);
2311 value = map->Find(Toolkit::Visual::Transform::Property::SIZE);
2312 DALI_TEST_CHECK(value);
2313 DALI_TEST_EQUALS(value->Get<Vector2>(), Vector2(700, 700), TEST_LOCATION); // Change the internal size according to the image view size
2315 value = map->Find(Toolkit::Visual::Transform::Property::SIZE_POLICY);
2316 DALI_TEST_CHECK(value);
2317 DALI_TEST_EQUALS(value->Get<Vector2>(), Vector2(Toolkit::Visual::Transform::Policy::ABSOLUTE, Toolkit::Visual::Transform::Policy::ABSOLUTE), TEST_LOCATION);
2319 value = map->Find(Toolkit::Visual::Transform::Property::OFFSET);
2320 DALI_TEST_CHECK(value);
2321 DALI_TEST_EQUALS(value->Get<Vector2>(), Vector2(50, 0), TEST_LOCATION);
2326 int UtcDaliImageViewFittingModesChangeFittingMode02(void)
2328 ToolkitTestApplication application;
2330 tet_infoline("UtcDaliImageViewFittingModesChangeFittingMode, image: [600,600], view:[800,700]");
2332 ImageView imageView = ImageView::New();
2334 // 1. Render using FittingMode::OVER_FIT_KEEP_ASPECT_RATIO
2335 Property::Map imageMap;
2336 imageMap[Toolkit::Visual::Property::TYPE] = Toolkit::Visual::IMAGE;
2337 imageMap[Toolkit::ImageVisual::Property::URL] = gImage_600_RGB;
2338 imageMap[DevelVisual::Property::VISUAL_FITTING_MODE] = Toolkit::DevelVisual::OVER_FIT_KEEP_ASPECT_RATIO;
2340 imageView.SetProperty(Toolkit::ImageView::Property::IMAGE, imageMap);
2341 imageView.SetProperty(Actor::Property::SIZE, Vector2(800, 700));
2343 application.GetScene().Add(imageView);
2345 // Trigger a potential relayout
2346 application.SendNotification();
2347 application.Render();
2349 Toolkit::Visual::Base visual = DevelControl::GetVisual(Toolkit::Internal::GetImplementation(imageView), Toolkit::ImageView::Property::IMAGE);
2350 Property::Map returnedMap;
2351 visual.CreatePropertyMap(returnedMap);
2353 Property::Value* value = returnedMap.Find(Toolkit::Visual::Property::TRANSFORM);
2354 DALI_TEST_CHECK(value);
2355 Property::Map* map = value->GetMap();
2356 DALI_TEST_CHECK(map);
2358 value = map->Find(Toolkit::Visual::Transform::Property::SIZE);
2359 DALI_TEST_CHECK(value);
2360 DALI_TEST_EQUALS(value->Get<Vector2>(), Vector2(800, 700), TEST_LOCATION); // Change the internal size according to the image view size
2362 value = map->Find(Toolkit::Visual::Transform::Property::SIZE_POLICY);
2363 DALI_TEST_CHECK(value);
2364 DALI_TEST_EQUALS(value->Get<Vector2>(), Vector2(Toolkit::Visual::Transform::Policy::ABSOLUTE, Toolkit::Visual::Transform::Policy::ABSOLUTE), TEST_LOCATION);
2366 value = map->Find(Toolkit::Visual::Transform::Property::OFFSET);
2367 DALI_TEST_CHECK(value);
2368 DALI_TEST_EQUALS(value->Get<Vector2>(), Vector2(0, 0), TEST_LOCATION);
2370 // 2. Render again using DevelVisaul::CENTER
2371 Property::Map imageMap2;
2372 imageMap2[Toolkit::Visual::Property::TYPE] = Toolkit::Visual::IMAGE;
2373 imageMap2[Toolkit::ImageVisual::Property::URL] = gImage_600_RGB;
2374 imageMap2[DevelVisual::Property::VISUAL_FITTING_MODE] = Toolkit::DevelVisual::CENTER;
2376 imageView.SetProperty(Toolkit::ImageView::Property::IMAGE, imageMap2);
2377 imageView.SetProperty(Actor::Property::SIZE, Vector2(800, 700));
2379 application.GetScene().Add(imageView);
2381 DALI_TEST_EQUALS(Test::WaitForEventThreadTrigger(1), true, TEST_LOCATION);
2383 // Trigger a potential relayout
2384 application.SendNotification();
2385 application.Render();
2387 returnedMap.Clear();
2388 visual = DevelControl::GetVisual(Toolkit::Internal::GetImplementation(imageView), Toolkit::ImageView::Property::IMAGE);
2390 visual.CreatePropertyMap(returnedMap);
2392 value = returnedMap.Find(Toolkit::Visual::Property::TRANSFORM);
2393 DALI_TEST_CHECK(value);
2394 map = value->GetMap();
2395 DALI_TEST_CHECK(map);
2397 value = map->Find(Toolkit::Visual::Transform::Property::SIZE);
2398 DALI_TEST_CHECK(value);
2399 DALI_TEST_EQUALS(value->Get<Vector2>(), Vector2(600, 600), TEST_LOCATION); // Change the internal size according to the image view size
2401 value = map->Find(Toolkit::Visual::Transform::Property::SIZE_POLICY);
2402 DALI_TEST_CHECK(value);
2403 DALI_TEST_EQUALS(value->Get<Vector2>(), Vector2(Toolkit::Visual::Transform::Policy::ABSOLUTE, Toolkit::Visual::Transform::Policy::ABSOLUTE), TEST_LOCATION);
2405 value = map->Find(Toolkit::Visual::Transform::Property::OFFSET);
2406 DALI_TEST_CHECK(value);
2407 DALI_TEST_EQUALS(value->Get<Vector2>(), Vector2(100, 50), TEST_LOCATION);
2409 // 3. Render again using before fittingMode
2410 Property::Map imageMap3;
2411 imageMap3[Toolkit::Visual::Property::TYPE] = Toolkit::Visual::IMAGE;
2412 imageMap3[Toolkit::ImageVisual::Property::URL] = gImage_600_RGB;
2413 imageMap3[DevelVisual::Property::VISUAL_FITTING_MODE] = Toolkit::DevelVisual::OVER_FIT_KEEP_ASPECT_RATIO;
2415 imageView.SetProperty(Toolkit::ImageView::Property::IMAGE, imageMap3);
2416 imageView.SetProperty(Actor::Property::SIZE, Vector2(800, 700));
2418 application.GetScene().Add(imageView);
2420 // Trigger a potential relayout
2421 application.SendNotification();
2422 application.Render();
2424 returnedMap.Clear();
2425 visual = DevelControl::GetVisual(Toolkit::Internal::GetImplementation(imageView), Toolkit::ImageView::Property::IMAGE);
2426 visual.CreatePropertyMap(returnedMap);
2428 value = returnedMap.Find(Toolkit::Visual::Property::TRANSFORM);
2429 DALI_TEST_CHECK(value);
2430 map = value->GetMap();
2431 DALI_TEST_CHECK(map);
2433 value = map->Find(Toolkit::Visual::Transform::Property::SIZE);
2434 DALI_TEST_CHECK(value);
2435 DALI_TEST_EQUALS(value->Get<Vector2>(), Vector2(800, 700), TEST_LOCATION); // Change the internal size according to the image view size
2437 value = map->Find(Toolkit::Visual::Transform::Property::SIZE_POLICY);
2438 DALI_TEST_CHECK(value);
2439 DALI_TEST_EQUALS(value->Get<Vector2>(), Vector2(Toolkit::Visual::Transform::Policy::ABSOLUTE, Toolkit::Visual::Transform::Policy::ABSOLUTE), TEST_LOCATION);
2441 value = map->Find(Toolkit::Visual::Transform::Property::OFFSET);
2442 DALI_TEST_CHECK(value);
2443 DALI_TEST_EQUALS(value->Get<Vector2>(), Vector2(0, 0), TEST_LOCATION);
2448 int UtcDaliImageViewFittingModesWithAnimatedVectorImageVisual(void)
2450 ToolkitTestApplication application;
2452 tet_infoline("Create an ImageVisual using SCALE_TO_FILL and animated vector image ( image: [600,600], view:[600,600] )");
2454 ImageView imageView = ImageView::New();
2455 Property::Map imageMap;
2456 imageMap.Add(Toolkit::Visual::Property::TYPE, DevelVisual::ANIMATED_VECTOR_IMAGE);
2457 imageMap.Add(Toolkit::ImageVisual::Property::URL, TEST_ANIMATED_VECTOR_IMAGE_FILE_NAME); // 249x169 image
2459 imageView.SetProperty(Toolkit::ImageView::Property::IMAGE, imageMap);
2460 imageView.SetProperty(Actor::Property::SIZE, Vector2(600, 600));
2462 application.GetScene().Add(imageView);
2464 // Trigger a potential relayout
2465 application.SendNotification();
2466 application.Render();
2468 Toolkit::Visual::Base visual = DevelControl::GetVisual(Toolkit::Internal::GetImplementation(imageView), Toolkit::ImageView::Property::IMAGE);
2469 Property::Map returnedMap;
2470 visual.CreatePropertyMap(returnedMap);
2472 Property::Value* value = returnedMap.Find(Toolkit::Visual::Property::TRANSFORM);
2473 DALI_TEST_CHECK(value);
2474 Property::Map* map = value->GetMap();
2475 DALI_TEST_CHECK(map);
2477 value = map->Find(Toolkit::Visual::Transform::Property::SIZE);
2478 DALI_TEST_CHECK(value);
2479 DALI_TEST_EQUALS(value->Get<Vector2>(), Vector2::ONE, TEST_LOCATION); // Relative size so will take up 100%
2481 value = map->Find(Toolkit::Visual::Transform::Property::SIZE_POLICY);
2482 DALI_TEST_CHECK(value);
2483 DALI_TEST_CHECK(value->Get<int>() == Toolkit::Visual::Transform::Policy::RELATIVE);
2485 value = map->Find(Toolkit::Visual::Transform::Property::OFFSET);
2486 DALI_TEST_CHECK(value);
2487 DALI_TEST_EQUALS(value->Get<Vector2>(), Vector2(0, 0), TEST_LOCATION); // OFFSET is zero
2492 int UtcDaliImageViewCustomShader(void)
2494 ToolkitTestApplication application;
2496 // Set a custom shader with an image url
2498 Property::Map properties;
2499 Property::Map shader;
2500 const std::string vertexShader = "Foobar";
2501 const std::string fragmentShader = "Foobar";
2502 shader[Visual::Shader::Property::FRAGMENT_SHADER] = fragmentShader;
2503 shader[Visual::Shader::Property::VERTEX_SHADER] = vertexShader;
2505 properties[Visual::Property::TYPE] = Visual::IMAGE;
2506 properties[Visual::Property::SHADER] = shader;
2507 properties[ImageVisual::Property::URL] = TEST_IMAGE_FILE_NAME;
2509 ImageView imageView = ImageView::New();
2510 imageView.SetProperty(ImageView::Property::IMAGE, properties);
2512 application.GetScene().Add(imageView);
2514 application.SendNotification();
2515 application.Render();
2517 DALI_TEST_EQUALS(Test::WaitForEventThreadTrigger(1), true, TEST_LOCATION);
2519 Renderer renderer = imageView.GetRendererAt(0);
2520 Shader shader2 = renderer.GetShader();
2521 Property::Value value = shader2.GetProperty(Shader::Property::PROGRAM);
2522 Property::Map* map = value.GetMap();
2523 DALI_TEST_CHECK(map);
2525 Property::Value* fragment = map->Find("fragment"); // fragment key name from shader-impl.cpp
2526 DALI_TEST_EQUALS(fragmentShader, fragment->Get<std::string>(), TEST_LOCATION);
2528 Property::Value* vertex = map->Find("vertex"); // vertex key name from shader-impl.cpp
2529 DALI_TEST_EQUALS(vertexShader, vertex->Get<std::string>(), TEST_LOCATION);
2532 // Set a custom shader after setting an image url
2534 Property::Map properties;
2535 Property::Map shader;
2536 const std::string vertexShader = "Foobar";
2537 const std::string fragmentShader = "Foobar";
2538 shader[Visual::Shader::Property::FRAGMENT_SHADER] = fragmentShader;
2539 shader[Visual::Shader::Property::VERTEX_SHADER] = vertexShader;
2541 properties[Visual::Property::SHADER] = shader;
2543 ImageView imageView = ImageView::New(TEST_IMAGE_FILE_NAME);
2544 imageView.SetProperty(ImageView::Property::IMAGE, properties);
2546 application.GetScene().Add(imageView);
2548 application.SendNotification();
2549 application.Render();
2551 DALI_TEST_EQUALS(Test::WaitForEventThreadTrigger(1), true, TEST_LOCATION);
2553 Renderer renderer = imageView.GetRendererAt(0);
2554 Shader shader2 = renderer.GetShader();
2555 Property::Value value = shader2.GetProperty(Shader::Property::PROGRAM);
2556 Property::Map* map = value.GetMap();
2557 DALI_TEST_CHECK(map);
2559 Property::Value* fragment = map->Find("fragment"); // fragment key name from shader-impl.cpp
2560 DALI_TEST_EQUALS(fragmentShader, fragment->Get<std::string>(), TEST_LOCATION);
2562 Property::Value* vertex = map->Find("vertex"); // vertex key name from shader-impl.cpp
2563 DALI_TEST_EQUALS(vertexShader, vertex->Get<std::string>(), TEST_LOCATION);
2566 // Set a custom shader before setting an image url
2568 Property::Map properties;
2569 Property::Map shader;
2570 const std::string vertexShader = "Foobar";
2571 const std::string fragmentShader = "Foobar";
2572 shader[Visual::Shader::Property::FRAGMENT_SHADER] = fragmentShader;
2573 shader[Visual::Shader::Property::VERTEX_SHADER] = vertexShader;
2575 properties[Visual::Property::SHADER] = shader;
2577 ImageView imageView = ImageView::New();
2578 imageView.SetProperty(ImageView::Property::IMAGE, properties);
2579 imageView.SetProperty(ImageView::Property::IMAGE, TEST_IMAGE_FILE_NAME);
2581 application.GetScene().Add(imageView);
2583 application.SendNotification();
2584 application.Render();
2585 DALI_TEST_EQUALS(Test::WaitForEventThreadTrigger(1), true, TEST_LOCATION);
2587 Renderer renderer = imageView.GetRendererAt(0);
2588 Shader shader2 = renderer.GetShader();
2589 Property::Value value = shader2.GetProperty(Shader::Property::PROGRAM);
2590 Property::Map* map = value.GetMap();
2591 DALI_TEST_CHECK(map);
2593 Property::Value* fragment = map->Find("fragment"); // fragment key name from shader-impl.cpp
2594 DALI_TEST_EQUALS(fragmentShader, fragment->Get<std::string>(), TEST_LOCATION);
2596 Property::Value* vertex = map->Find("vertex"); // vertex key name from shader-impl.cpp
2597 DALI_TEST_EQUALS(vertexShader, vertex->Get<std::string>(), TEST_LOCATION);
2600 // Set a custom shader after setting a property map
2602 Property::Map properties;
2603 Property::Map shader;
2604 const std::string vertexShader = "Foobar";
2605 const std::string fragmentShader = "Foobar";
2606 shader[Visual::Shader::Property::FRAGMENT_SHADER] = fragmentShader;
2607 shader[Visual::Shader::Property::VERTEX_SHADER] = vertexShader;
2609 properties[Visual::Property::SHADER] = shader;
2611 Property::Map properties1;
2612 properties1[Visual::Property::TYPE] = Visual::IMAGE;
2613 properties1[ImageVisual::Property::URL] = TEST_IMAGE_FILE_NAME;
2615 ImageView imageView = ImageView::New();
2616 imageView.SetProperty(ImageView::Property::IMAGE, properties1);
2617 imageView.SetProperty(ImageView::Property::IMAGE, properties);
2619 application.GetScene().Add(imageView);
2621 application.SendNotification();
2622 application.Render();
2623 DALI_TEST_EQUALS(Test::WaitForEventThreadTrigger(1), true, TEST_LOCATION);
2625 Renderer renderer = imageView.GetRendererAt(0);
2626 Shader shader2 = renderer.GetShader();
2627 Property::Value value = shader2.GetProperty(Shader::Property::PROGRAM);
2628 Property::Map* map = value.GetMap();
2629 DALI_TEST_CHECK(map);
2631 Property::Value* fragment = map->Find("fragment"); // fragment key name from shader-impl.cpp
2632 DALI_TEST_EQUALS(fragmentShader, fragment->Get<std::string>(), TEST_LOCATION);
2634 Property::Value* vertex = map->Find("vertex"); // vertex key name from shader-impl.cpp
2635 DALI_TEST_EQUALS(vertexShader, vertex->Get<std::string>(), TEST_LOCATION);
2638 // Set a custom shader before setting a property map
2640 Property::Map properties;
2641 Property::Map shader;
2642 const std::string vertexShader = "Foobar";
2643 const std::string fragmentShader = "Foobar";
2644 shader[Visual::Shader::Property::FRAGMENT_SHADER] = fragmentShader;
2645 shader[Visual::Shader::Property::VERTEX_SHADER] = vertexShader;
2647 properties[Visual::Property::SHADER] = shader;
2649 Property::Map properties1;
2650 properties1[Visual::Property::TYPE] = Visual::IMAGE;
2651 properties1[ImageVisual::Property::URL] = TEST_IMAGE_FILE_NAME;
2653 ImageView imageView = ImageView::New();
2654 imageView.SetProperty(ImageView::Property::IMAGE, properties);
2655 imageView.SetProperty(ImageView::Property::IMAGE, properties1);
2657 application.GetScene().Add(imageView);
2659 application.SendNotification();
2660 application.Render();
2661 DALI_TEST_EQUALS(Test::WaitForEventThreadTrigger(1), true, TEST_LOCATION);
2663 Renderer renderer = imageView.GetRendererAt(0);
2664 Shader shader2 = renderer.GetShader();
2665 Property::Value value = shader2.GetProperty(Shader::Property::PROGRAM);
2666 Property::Map* map = value.GetMap();
2667 DALI_TEST_CHECK(map);
2669 Property::Value* fragment = map->Find("fragment"); // fragment key name from shader-impl.cpp
2670 DALI_TEST_EQUALS(fragmentShader, fragment->Get<std::string>(), TEST_LOCATION);
2672 Property::Value* vertex = map->Find("vertex"); // vertex key name from shader-impl.cpp
2673 DALI_TEST_EQUALS(vertexShader, vertex->Get<std::string>(), TEST_LOCATION);
2681 static int gFailCounter = 0;
2682 const int MAX_RETRIES(3);
2684 void ReloadImage(ImageView imageView)
2686 Property::Map imageImmediateLoadingMap;
2687 imageImmediateLoadingMap[ImageVisual::Property::URL] = "Non-existant-image.jpg";
2688 imageImmediateLoadingMap[ImageVisual::Property::LOAD_POLICY] = ImageVisual::LoadPolicy::IMMEDIATE;
2690 tet_infoline("Immediate load an image");
2691 imageView.SetProperty(ImageView::Property::IMAGE, imageImmediateLoadingMap);
2694 void ResourceFailedReload(Control control)
2700 int UtcDaliImageViewReloadFailedOnResourceReadySignal(void)
2702 tet_infoline("Test reloading failed image from within signal handler.");
2704 ToolkitTestApplication application;
2708 ImageView imageView = ImageView::New();
2709 imageView.ResourceReadySignal().Connect(&ResourceFailedReload);
2710 DALI_TEST_EQUALS(gFailCounter, 0, TEST_LOCATION);
2711 ReloadImage(imageView);
2713 // loading started, this waits for the loader thread to complete
2714 DALI_TEST_EQUALS(Test::WaitForEventThreadTrigger(1), true, TEST_LOCATION);
2715 DALI_TEST_EQUALS(gFailCounter, 1, TEST_LOCATION);
2717 ReloadImage(imageView);
2718 DALI_TEST_EQUALS(Test::WaitForEventThreadTrigger(1), true, TEST_LOCATION);
2719 DALI_TEST_EQUALS(gFailCounter, 2, TEST_LOCATION);
2721 ReloadImage(imageView);
2722 DALI_TEST_EQUALS(Test::WaitForEventThreadTrigger(1), true, TEST_LOCATION);
2723 DALI_TEST_EQUALS(gFailCounter, 3, TEST_LOCATION);
2728 int UtcDaliImageViewLoadRemoteSVG(void)
2730 tet_infoline("Test load from a remote server.");
2732 ToolkitTestApplication application;
2735 Toolkit::ImageView imageView;
2736 imageView = Toolkit::ImageView::New();
2737 imageView.SetImage("https://dev.w3.org/SVG/tools/svgweb/samples/svg-files/check.svg");
2738 imageView.SetProperty(Actor::Property::PARENT_ORIGIN, ParentOrigin::TOP_LEFT);
2739 imageView.SetProperty(Actor::Property::ANCHOR_POINT, AnchorPoint::TOP_LEFT);
2740 imageView.SetProperty(Actor::Property::SIZE, Vector2(300, 300));
2741 imageView.SetProperty(Actor::Property::POSITION, Vector3(150.0f, 150.0f, 0.0f));
2743 application.GetScene().Add(imageView);
2745 DALI_TEST_CHECK(imageView);
2747 DALI_TEST_EQUALS(imageView.GetRendererCount(), 0u, TEST_LOCATION);
2749 application.SendNotification();
2751 // Wait for loading & rasterization
2752 DALI_TEST_EQUALS(Test::WaitForEventThreadTrigger(2), true, TEST_LOCATION);
2754 application.SendNotification();
2755 application.Render();
2757 DALI_TEST_EQUALS(imageView.GetRendererCount(), 1u, TEST_LOCATION);
2762 Toolkit::ImageView imageView;
2763 imageView = Toolkit::ImageView::New();
2764 imageView.SetImage("https://dev.w3.org/SVG/tools/svgweb/samples/svg-files/check.svg");
2765 imageView.SetProperty(Actor::Property::PARENT_ORIGIN, ParentOrigin::TOP_LEFT);
2766 imageView.SetProperty(Actor::Property::ANCHOR_POINT, AnchorPoint::TOP_LEFT);
2767 imageView.SetProperty(Actor::Property::POSITION, Vector3(150.0f, 150.0f, 0.0f));
2769 application.GetScene().Add(imageView);
2771 DALI_TEST_CHECK(imageView);
2773 DALI_TEST_EQUALS(imageView.GetRendererCount(), 0u, TEST_LOCATION);
2775 application.SendNotification();
2777 // Wait for loading & rasterization
2778 DALI_TEST_EQUALS(Test::WaitForEventThreadTrigger(2), true, TEST_LOCATION);
2780 application.SendNotification();
2781 application.Render();
2783 DALI_TEST_EQUALS(imageView.GetRendererCount(), 1u, TEST_LOCATION);
2789 int UtcDaliImageViewSyncSVGLoading(void)
2791 ToolkitTestApplication application;
2793 tet_infoline("ImageView Testing SVG image sync loading");
2796 ImageView imageView = ImageView::New();
2798 // Sync loading is used
2799 Property::Map syncLoadingMap;
2800 syncLoadingMap.Insert(Toolkit::Visual::Property::TYPE, Toolkit::Visual::IMAGE);
2801 syncLoadingMap.Insert(Toolkit::ImageVisual::Property::URL, TEST_RESOURCE_DIR "/svg1.svg");
2802 syncLoadingMap.Insert(Toolkit::ImageVisual::Property::SYNCHRONOUS_LOADING, true);
2803 imageView.SetProperty(ImageView::Property::IMAGE, syncLoadingMap);
2805 application.GetScene().Add(imageView);
2806 DALI_TEST_CHECK(imageView);
2808 application.SendNotification();
2809 Vector3 naturalSize = imageView.GetNaturalSize();
2811 DALI_TEST_EQUALS(naturalSize.width, 100.0f, TEST_LOCATION);
2812 DALI_TEST_EQUALS(naturalSize.height, 100.0f, TEST_LOCATION);
2817 int UtcDaliImageViewAsyncSVGLoading(void)
2819 ToolkitTestApplication application;
2821 tet_infoline("ImageView Testing SVG image async loading");
2824 ImageView imageView = ImageView::New();
2826 // Async loading is used - default value of SYNCHRONOUS_LOADING is false.
2827 Property::Map propertyMap;
2828 propertyMap.Insert(Toolkit::Visual::Property::TYPE, Toolkit::Visual::IMAGE);
2829 propertyMap.Insert(Toolkit::ImageVisual::Property::URL, TEST_RESOURCE_DIR "/svg1.svg");
2830 imageView.SetProperty(ImageView::Property::IMAGE, propertyMap);
2832 application.GetScene().Add(imageView);
2833 DALI_TEST_CHECK(imageView);
2835 application.SendNotification();
2838 DALI_TEST_EQUALS(Test::WaitForEventThreadTrigger(1), true, TEST_LOCATION);
2840 application.SendNotification();
2841 application.Render(16);
2843 Vector3 naturalSize = imageView.GetNaturalSize();
2844 DALI_TEST_EQUALS(naturalSize.width, 100.0f, TEST_LOCATION);
2845 DALI_TEST_EQUALS(naturalSize.height, 100.0f, TEST_LOCATION);
2850 int UtcDaliImageViewSVGLoadingSyncSetInvalidValue(void)
2852 ToolkitTestApplication application;
2854 tet_infoline("ImageView Testing SVG image async loading");
2858 ImageView imageView = ImageView::New();
2860 // Sync loading is used
2861 Property::Map syncLoadingMap;
2862 syncLoadingMap.Insert(Toolkit::Visual::Property::TYPE, Toolkit::Visual::IMAGE);
2863 syncLoadingMap.Insert(Toolkit::ImageVisual::Property::URL, TEST_RESOURCE_DIR "/svg1.svg");
2865 // Check to set invalid value
2866 // The SYNCHRONOUS_LOADING property must be set to the bool value.
2867 // Check if error log is outputted when setting other value like string.
2868 // Even if the wrong value is set, the image will be shown normally, and the synchronous value should be the default value(false).
2869 syncLoadingMap.Insert(Toolkit::ImageVisual::Property::SYNCHRONOUS_LOADING, std::to_string(5));
2870 imageView.SetProperty(ImageView::Property::IMAGE, syncLoadingMap);
2872 application.GetScene().Add(imageView);
2873 DALI_TEST_CHECK(imageView);
2875 application.SendNotification();
2878 DALI_TEST_EQUALS(Test::WaitForEventThreadTrigger(1), true, TEST_LOCATION);
2880 application.SendNotification();
2881 application.Render(16);
2883 Vector3 naturalSize = imageView.GetNaturalSize();
2884 DALI_TEST_EQUALS(naturalSize.width, 100.0f, TEST_LOCATION);
2885 DALI_TEST_EQUALS(naturalSize.height, 100.0f, TEST_LOCATION);
2887 Property::Value value = imageView.GetProperty(ImageView::Property::IMAGE);
2888 Property::Map* map = value.GetMap();
2889 DALI_TEST_CHECK(map);
2891 Property::Value* sync = map->Find(Toolkit::ImageVisual::Property::SYNCHRONOUS_LOADING);
2892 DALI_TEST_CHECK(sync);
2893 DALI_TEST_EQUALS(false, sync->Get<bool>(), TEST_LOCATION);
2898 int UtcDaliImageViewSvgLoadingFailureLocalFile(void)
2900 // Local svg file - invalid file path
2902 ToolkitTestApplication application;
2904 TestGlAbstraction& gl = application.GetGlAbstraction();
2905 TraceCallStack& textureTrace = gl.GetTextureTrace();
2906 textureTrace.Enable(true);
2908 gResourceReadySignalFired = false;
2910 ImageView imageView = ImageView::New(TEST_RESOURCE_DIR "/foo.svg");
2911 imageView.SetProperty(Actor::Property::SIZE, Vector2(200.f, 200.f));
2912 imageView.ResourceReadySignal().Connect(&ResourceReadySignal);
2914 DALI_TEST_EQUALS(imageView.IsResourceReady(), false, TEST_LOCATION);
2916 application.GetScene().Add(imageView);
2918 application.SendNotification();
2920 // loading started, this waits for the loader thread - load
2921 DALI_TEST_EQUALS(Test::WaitForEventThreadTrigger(1), true, TEST_LOCATION);
2923 application.SendNotification();
2924 application.Render(16);
2926 DALI_TEST_EQUALS(gResourceReadySignalFired, true, TEST_LOCATION);
2927 DALI_TEST_EQUALS(imageView.IsResourceReady(), true, TEST_LOCATION);
2928 DALI_TEST_EQUALS(imageView.GetVisualResourceStatus(ImageView::Property::IMAGE), Visual::ResourceStatus::FAILED, TEST_LOCATION);
2930 // Should be shown a broken image
2931 DALI_TEST_EQUALS(imageView.GetRendererCount(), 1u, TEST_LOCATION);
2932 DALI_TEST_EQUALS(textureTrace.FindMethod("BindTexture"), true, TEST_LOCATION);
2935 // Local svg file - invalid file path without size set
2937 ToolkitTestApplication application;
2939 TestGlAbstraction& gl = application.GetGlAbstraction();
2940 TraceCallStack& textureTrace = gl.GetTextureTrace();
2941 textureTrace.Enable(true);
2943 gResourceReadySignalFired = false;
2944 textureTrace.Reset();
2946 ImageView imageView = ImageView::New(TEST_RESOURCE_DIR "/foo.svg");
2947 imageView.ResourceReadySignal().Connect(&ResourceReadySignal);
2949 DALI_TEST_EQUALS(imageView.IsResourceReady(), false, TEST_LOCATION);
2951 application.GetScene().Add(imageView);
2953 application.SendNotification();
2955 // loading started, this waits for the loader thread - load & rasterize
2956 DALI_TEST_EQUALS(Test::WaitForEventThreadTrigger(1), true, TEST_LOCATION);
2958 application.SendNotification();
2959 application.Render(16);
2961 DALI_TEST_EQUALS(gResourceReadySignalFired, true, TEST_LOCATION);
2962 DALI_TEST_EQUALS(imageView.IsResourceReady(), true, TEST_LOCATION);
2963 DALI_TEST_EQUALS(imageView.GetVisualResourceStatus(ImageView::Property::IMAGE), Visual::ResourceStatus::FAILED, TEST_LOCATION);
2965 // Should be shown a broken image
2966 DALI_TEST_EQUALS(imageView.GetRendererCount(), 1u, TEST_LOCATION);
2967 DALI_TEST_EQUALS(textureTrace.FindMethod("BindTexture"), true, TEST_LOCATION);
2970 // Local svg file - invalid file
2972 ToolkitTestApplication application;
2974 TestGlAbstraction& gl = application.GetGlAbstraction();
2975 TraceCallStack& textureTrace = gl.GetTextureTrace();
2976 textureTrace.Enable(true);
2978 gResourceReadySignalFired = false;
2979 textureTrace.Reset();
2981 ImageView imageView = ImageView::New(TEST_RESOURCE_DIR "/invalid.svg");
2982 imageView.SetProperty(Actor::Property::SIZE, Vector2(200.f, 200.f));
2983 imageView.ResourceReadySignal().Connect(&ResourceReadySignal);
2985 DALI_TEST_EQUALS(imageView.IsResourceReady(), false, TEST_LOCATION);
2987 application.GetScene().Add(imageView);
2989 application.SendNotification();
2991 // loading started, this waits for the loader thread - load & rasterize
2992 DALI_TEST_EQUALS(Test::WaitForEventThreadTrigger(1), true, TEST_LOCATION);
2994 application.SendNotification();
2995 application.Render(16);
2997 DALI_TEST_EQUALS(gResourceReadySignalFired, true, TEST_LOCATION);
2998 DALI_TEST_EQUALS(imageView.IsResourceReady(), true, TEST_LOCATION);
2999 DALI_TEST_EQUALS(imageView.GetVisualResourceStatus(ImageView::Property::IMAGE), Visual::ResourceStatus::FAILED, TEST_LOCATION);
3001 // Should be shown a broken image
3002 DALI_TEST_EQUALS(imageView.GetRendererCount(), 1u, TEST_LOCATION);
3003 DALI_TEST_EQUALS(textureTrace.FindMethod("BindTexture"), true, TEST_LOCATION);
3009 int UtcDaliImageViewSvgLoadingFailureRemoteFile01(void)
3013 ToolkitTestApplication application;
3015 TestGlAbstraction& gl = application.GetGlAbstraction();
3016 TraceCallStack& textureTrace = gl.GetTextureTrace();
3017 textureTrace.Enable(true);
3019 gResourceReadySignalFired = false;
3021 ImageView imageView = ImageView::New("https://127.0.0.1/foobar.svg");
3022 imageView.SetProperty(Actor::Property::SIZE, Vector2(200.f, 200.f));
3023 imageView.ResourceReadySignal().Connect(&ResourceReadySignal);
3025 DALI_TEST_EQUALS(imageView.IsResourceReady(), false, TEST_LOCATION);
3027 application.GetScene().Add(imageView);
3029 application.SendNotification();
3031 // loading started, this waits for the loader thread - load & rasterize
3032 DALI_TEST_EQUALS(Test::WaitForEventThreadTrigger(1), true, TEST_LOCATION);
3034 application.SendNotification();
3035 application.Render(16);
3037 DALI_TEST_EQUALS(gResourceReadySignalFired, true, TEST_LOCATION);
3038 DALI_TEST_EQUALS(imageView.IsResourceReady(), true, TEST_LOCATION);
3039 DALI_TEST_EQUALS(imageView.GetVisualResourceStatus(ImageView::Property::IMAGE), Visual::ResourceStatus::FAILED, TEST_LOCATION);
3041 // Should be shown a broken image
3042 DALI_TEST_EQUALS(imageView.GetRendererCount(), 1u, TEST_LOCATION);
3043 DALI_TEST_EQUALS(textureTrace.FindMethod("BindTexture"), true, TEST_LOCATION);
3049 int UtcDaliImageViewSvgLoadingFailureRemoteFile02(void)
3051 // Remote svg file without size set
3053 ToolkitTestApplication application;
3055 TestGlAbstraction& gl = application.GetGlAbstraction();
3056 TraceCallStack& textureTrace = gl.GetTextureTrace();
3057 textureTrace.Enable(true);
3059 gResourceReadySignalFired = false;
3061 ImageView imageView = ImageView::New("https://127.0.0.1/foobar.svg");
3062 imageView.ResourceReadySignal().Connect(&ResourceReadySignal);
3064 DALI_TEST_EQUALS(imageView.IsResourceReady(), false, TEST_LOCATION);
3066 application.GetScene().Add(imageView);
3068 application.SendNotification();
3070 // loading started, this waits for the loader thread - load & rasterize
3071 DALI_TEST_EQUALS(Test::WaitForEventThreadTrigger(1), true, TEST_LOCATION);
3073 application.SendNotification();
3074 application.Render(16);
3076 DALI_TEST_EQUALS(gResourceReadySignalFired, true, TEST_LOCATION);
3077 DALI_TEST_EQUALS(imageView.IsResourceReady(), true, TEST_LOCATION);
3078 DALI_TEST_EQUALS(imageView.GetVisualResourceStatus(ImageView::Property::IMAGE), Visual::ResourceStatus::FAILED, TEST_LOCATION);
3080 // Should be shown a broken image
3081 DALI_TEST_EQUALS(imageView.GetRendererCount(), 1u, TEST_LOCATION);
3082 DALI_TEST_EQUALS(textureTrace.FindMethod("BindTexture"), true, TEST_LOCATION);
3088 int UtcDaliImageViewSvgRasterizationFailure(void)
3090 ToolkitTestApplication application;
3092 gResourceReadySignalFired = false;
3094 TestGlAbstraction& gl = application.GetGlAbstraction();
3095 TraceCallStack& textureTrace = gl.GetTextureTrace();
3096 textureTrace.Enable(true);
3098 ImageView imageView = ImageView::New(TEST_RESOURCE_DIR "/invalid1.svg");
3099 imageView.SetProperty(Actor::Property::SIZE, Vector2(200.f, 200.f));
3100 imageView.ResourceReadySignal().Connect(&ResourceReadySignal);
3102 DALI_TEST_EQUALS(imageView.IsResourceReady(), false, TEST_LOCATION);
3104 application.GetScene().Add(imageView);
3106 application.SendNotification();
3108 // Wait for loading & rasterization
3109 DALI_TEST_EQUALS(Test::WaitForEventThreadTrigger(2), true, TEST_LOCATION);
3111 application.SendNotification();
3112 application.Render(16);
3114 DALI_TEST_EQUALS(gResourceReadySignalFired, true, TEST_LOCATION);
3115 DALI_TEST_EQUALS(imageView.IsResourceReady(), true, TEST_LOCATION);
3116 DALI_TEST_EQUALS(imageView.GetVisualResourceStatus(ImageView::Property::IMAGE), Visual::ResourceStatus::FAILED, TEST_LOCATION);
3118 // Should be shown a broken image
3119 DALI_TEST_EQUALS(imageView.GetRendererCount(), 1u, TEST_LOCATION);
3120 DALI_TEST_EQUALS(textureTrace.FindMethod("BindTexture"), true, TEST_LOCATION);
3125 int UtcDaliImageViewSvgChageSize(void)
3127 ToolkitTestApplication application;
3129 TestGlAbstraction& gl = application.GetGlAbstraction();
3130 TraceCallStack& textureTrace = gl.GetTextureTrace();
3131 textureTrace.Enable(true);
3133 ImageView imageView = ImageView::New(TEST_SVG_FILE_NAME);
3134 application.GetScene().Add(imageView);
3136 application.SendNotification();
3138 // Wait for loading & rasterization
3139 DALI_TEST_EQUALS(Test::WaitForEventThreadTrigger(2), true, TEST_LOCATION);
3141 application.SendNotification();
3142 application.Render(16);
3144 DALI_TEST_EQUALS(Test::VectorImageRenderer::GetLoadCount(), 1, TEST_LOCATION);
3146 // Change actor size, then rasterization should be done again
3147 imageView.SetProperty(Actor::Property::SIZE, Vector2(200.f, 200.f));
3149 application.SendNotification();
3151 // Wait for rasterization
3152 DALI_TEST_EQUALS(Test::WaitForEventThreadTrigger(1), true, TEST_LOCATION);
3154 application.SendNotification();
3155 application.Render(16);
3157 // We should not load the file again.
3158 DALI_TEST_EQUALS(Test::VectorImageRenderer::GetLoadCount(), 1, TEST_LOCATION);
3163 int UtcDaliImageViewSvgAtlasing(void)
3165 ToolkitTestApplication application;
3167 TraceCallStack& callStack = application.GetGlAbstraction().GetTextureTrace();
3169 callStack.Enable(true);
3171 Property::Map propertyMap;
3172 propertyMap["url"] = TEST_SVG_FILE_NAME;
3173 propertyMap["atlasing"] = true;
3175 ImageView imageView = ImageView::New();
3176 imageView.SetProperty(ImageView::Property::IMAGE, propertyMap);
3177 imageView.SetProperty(Actor::Property::SIZE, Vector2(100.f, 100.f));
3178 application.GetScene().Add(imageView);
3180 application.SendNotification();
3182 // Wait for loading & rasterization
3183 DALI_TEST_EQUALS(Test::WaitForEventThreadTrigger(2), true, TEST_LOCATION);
3185 application.SendNotification();
3186 application.Render(16);
3189 TraceCallStack::NamedParams params1;
3190 params1["width"] << 100;
3191 params1["height"] << 100;
3192 DALI_TEST_EQUALS(callStack.FindMethodAndParams("TexSubImage2D", params1), true, TEST_LOCATION);
3194 imageView.SetProperty(Actor::Property::SIZE, Vector2(600.f, 600.f));
3196 application.SendNotification();
3198 // Wait for rasterization
3199 DALI_TEST_EQUALS(Test::WaitForEventThreadTrigger(1), true, TEST_LOCATION);
3203 application.SendNotification();
3204 application.Render(16);
3207 TraceCallStack::NamedParams params2;
3208 params2["width"] << 600;
3209 params2["height"] << 600;
3210 DALI_TEST_EQUALS(callStack.FindMethodAndParams("TexImage2D", params2), true, TEST_LOCATION);
3215 int UtcDaliImageViewTVGLoading(void)
3217 ToolkitTestApplication application;
3219 tet_infoline("ImageView Testing TVG image loading");
3222 ImageView imageView = ImageView::New(TEST_RESOURCE_DIR "/test.tvg");
3223 application.GetScene().Add(imageView);
3224 DALI_TEST_CHECK(imageView);
3226 application.SendNotification();
3228 DALI_TEST_EQUALS(Test::WaitForEventThreadTrigger(1), true, TEST_LOCATION);
3230 application.SendNotification();
3231 application.Render(16);
3233 Vector3 naturalSize = imageView.GetNaturalSize();
3235 DALI_TEST_EQUALS(naturalSize.width, 100.0f, TEST_LOCATION);
3236 DALI_TEST_EQUALS(naturalSize.height, 100.0f, TEST_LOCATION);
3241 int UtcDaliImageViewSvgDesiredSize01(void)
3243 ToolkitTestApplication application;
3245 TestGlAbstraction& gl = application.GetGlAbstraction();
3246 TraceCallStack& textureTrace = gl.GetTextureTrace();
3247 textureTrace.Enable(true);
3249 int desiredWidth = 100, desiredHeight = 150;
3250 ImageView imageView = ImageView::New(TEST_SVG_FILE_NAME, ImageDimensions(desiredWidth, desiredHeight));
3252 application.GetScene().Add(imageView);
3254 application.SendNotification();
3256 // Wait for loading & rasterization
3257 DALI_TEST_EQUALS(Test::WaitForEventThreadTrigger(2), true, TEST_LOCATION);
3259 application.SendNotification();
3260 application.Render(16);
3263 std::stringstream out;
3264 out << GL_TEXTURE_2D << ", " << 0u << ", " << desiredWidth << ", " << desiredHeight;
3265 DALI_TEST_CHECK(textureTrace.FindMethodAndParams("TexImage2D", out.str().c_str()));
3271 int UtcDaliImageViewSvgDesiredSize02(void)
3273 ToolkitTestApplication application;
3275 TestGlAbstraction& gl = application.GetGlAbstraction();
3276 TraceCallStack& textureTrace = gl.GetTextureTrace();
3277 textureTrace.Enable(true);
3279 int desiredWidth = 150, desiredHeight = 100;
3280 ImageView imageView = ImageView::New();
3281 imageView[ImageView::Property::IMAGE] = Property::Map().Add("url", TEST_SVG_FILE_NAME).Add("desiredWidth", desiredWidth).Add("desiredHeight", desiredHeight);
3282 application.GetScene().Add(imageView);
3284 application.SendNotification();
3286 // Wait for loading & rasterization
3287 DALI_TEST_EQUALS(Test::WaitForEventThreadTrigger(2), true, TEST_LOCATION);
3289 application.SendNotification();
3290 application.Render(16);
3293 std::stringstream out;
3294 out << GL_TEXTURE_2D << ", " << 0u << ", " << desiredWidth << ", " << desiredHeight;
3295 DALI_TEST_CHECK(textureTrace.FindMethodAndParams("TexImage2D", out.str().c_str()));
3301 int UtcDaliImageViewImageLoadFailure01(void)
3303 ToolkitTestApplication application;
3305 Toolkit::StyleManager styleManager = Toolkit::StyleManager::Get();
3306 DevelStyleManager::SetBrokenImageUrl(styleManager, DevelStyleManager::BrokenImageType::SMALL, TEST_BROKEN_IMAGE_S);
3307 DevelStyleManager::SetBrokenImageUrl(styleManager, DevelStyleManager::BrokenImageType::NORMAL, TEST_BROKEN_IMAGE_M);
3308 DevelStyleManager::SetBrokenImageUrl(styleManager, DevelStyleManager::BrokenImageType::LARGE, TEST_BROKEN_IMAGE_L);
3310 std::string brokenUrl;
3311 brokenUrl = DevelStyleManager::GetBrokenImageUrl(styleManager, DevelStyleManager::BrokenImageType::SMALL);
3312 DALI_TEST_EQUALS(TEST_BROKEN_IMAGE_S, brokenUrl, TEST_LOCATION);
3314 brokenUrl = DevelStyleManager::GetBrokenImageUrl(styleManager, DevelStyleManager::BrokenImageType::NORMAL);
3315 DALI_TEST_EQUALS(TEST_BROKEN_IMAGE_M, brokenUrl, TEST_LOCATION);
3317 brokenUrl = DevelStyleManager::GetBrokenImageUrl(styleManager, DevelStyleManager::BrokenImageType::LARGE);
3318 DALI_TEST_EQUALS(TEST_BROKEN_IMAGE_L, brokenUrl, TEST_LOCATION);
3320 ImageView imageView = ImageView::New("invalidUrl.png");
3321 imageView.SetProperty(Actor::Property::SIZE, Vector2(200.f, 200.f));
3323 application.GetScene().Add(imageView);
3324 application.SendNotification();
3325 application.Render(16);
3327 // loading started, this waits for the loader thread
3328 DALI_TEST_EQUALS(Test::WaitForEventThreadTrigger(1), true, TEST_LOCATION);
3333 int UtcDaliImageViewImageLoadFailure02(void)
3335 ToolkitTestApplication application;
3337 Toolkit::StyleManager styleManager = Toolkit::StyleManager::Get();
3338 DevelStyleManager::SetBrokenImageUrl(styleManager, DevelStyleManager::BrokenImageType::SMALL, TEST_BROKEN_IMAGE_DEFAULT);
3339 DevelStyleManager::SetBrokenImageUrl(styleManager, DevelStyleManager::BrokenImageType::NORMAL, TEST_BROKEN_IMAGE_M);
3340 DevelStyleManager::SetBrokenImageUrl(styleManager, DevelStyleManager::BrokenImageType::LARGE, TEST_BROKEN_IMAGE_L);
3342 std::string brokenUrl;
3343 brokenUrl = DevelStyleManager::GetBrokenImageUrl(styleManager, DevelStyleManager::BrokenImageType::SMALL);
3344 DALI_TEST_EQUALS(TEST_BROKEN_IMAGE_DEFAULT, brokenUrl, TEST_LOCATION);
3346 brokenUrl = DevelStyleManager::GetBrokenImageUrl(styleManager, DevelStyleManager::BrokenImageType::NORMAL);
3347 DALI_TEST_EQUALS(TEST_BROKEN_IMAGE_M, brokenUrl, TEST_LOCATION);
3349 brokenUrl = DevelStyleManager::GetBrokenImageUrl(styleManager, DevelStyleManager::BrokenImageType::LARGE);
3350 DALI_TEST_EQUALS(TEST_BROKEN_IMAGE_L, brokenUrl, TEST_LOCATION);
3352 ImageView imageView = ImageView::New("invalidUrl.png");
3353 imageView.SetProperty(Actor::Property::SIZE, Vector2(30.f, 30.f));
3354 application.GetScene().Add(imageView);
3355 application.SendNotification();
3356 application.Render(16);
3358 // loading started, this waits for the loader thread
3359 DALI_TEST_EQUALS(Test::WaitForEventThreadTrigger(1), true, TEST_LOCATION);
3364 int UtcDaliImageViewImageLoadFailure03(void)
3366 ToolkitTestApplication application;
3368 Toolkit::StyleManager styleManager = Toolkit::StyleManager::Get();
3369 DevelStyleManager::SetBrokenImageUrl(styleManager, DevelStyleManager::BrokenImageType::SMALL, TEST_BROKEN_IMAGE_01);
3370 DevelStyleManager::SetBrokenImageUrl(styleManager, DevelStyleManager::BrokenImageType::NORMAL, TEST_BROKEN_IMAGE_02);
3372 std::string brokenUrl;
3373 brokenUrl = DevelStyleManager::GetBrokenImageUrl(styleManager, DevelStyleManager::BrokenImageType::SMALL);
3374 DALI_TEST_EQUALS(TEST_BROKEN_IMAGE_01, brokenUrl, TEST_LOCATION);
3376 brokenUrl = DevelStyleManager::GetBrokenImageUrl(styleManager, DevelStyleManager::BrokenImageType::NORMAL);
3377 DALI_TEST_EQUALS(TEST_BROKEN_IMAGE_02, brokenUrl, TEST_LOCATION);
3379 ImageView imageView = ImageView::New("invalidUrl.png");
3380 imageView.SetProperty(Actor::Property::SIZE, Vector2(100.f, 100.f));
3381 application.GetScene().Add(imageView);
3382 application.SendNotification();
3383 application.Render(16);
3385 // loading started, this waits for the loader thread
3386 DALI_TEST_EQUALS(Test::WaitForEventThreadTrigger(1), true, TEST_LOCATION);
3391 int UtcDaliImageViewImageLoadFailure04(void)
3393 ToolkitTestApplication application;
3395 ImageView imageView = ImageView::New("invalidUrl.png");
3396 imageView.SetProperty(Actor::Property::SIZE, Vector2(100.f, 100.f));
3397 application.GetScene().Add(imageView);
3398 application.SendNotification();
3399 application.Render(16);
3401 // loading started, this waits for the loader thread
3402 DALI_TEST_EQUALS(Test::WaitForEventThreadTrigger(1), true, TEST_LOCATION);
3404 Toolkit::StyleManager styleManager = Toolkit::StyleManager::Get();
3405 DevelStyleManager::SetBrokenImageUrl(styleManager, DevelStyleManager::BrokenImageType::SMALL, TEST_BROKEN_IMAGE_S);
3406 DevelStyleManager::SetBrokenImageUrl(styleManager, DevelStyleManager::BrokenImageType::NORMAL, "invalidBroken.png");
3407 DevelStyleManager::SetBrokenImageUrl(styleManager, DevelStyleManager::BrokenImageType::LARGE, TEST_BROKEN_IMAGE_L);
3409 ImageView imageView2 = ImageView::New("invalidUrl.png");
3410 imageView2.SetProperty(Actor::Property::SIZE, Vector2(100.f, 100.f));
3411 application.GetScene().Add(imageView2);
3413 std::string brokenUrl;
3414 brokenUrl = DevelStyleManager::GetBrokenImageUrl(styleManager, DevelStyleManager::BrokenImageType::SMALL);
3415 DALI_TEST_EQUALS(TEST_BROKEN_IMAGE_S, brokenUrl, TEST_LOCATION);
3417 brokenUrl = DevelStyleManager::GetBrokenImageUrl(styleManager, DevelStyleManager::BrokenImageType::LARGE);
3418 DALI_TEST_EQUALS(TEST_BROKEN_IMAGE_L, brokenUrl, TEST_LOCATION);
3420 application.SendNotification();
3421 application.Render(16);
3423 // loading started, this waits for the loader thread
3424 DALI_TEST_EQUALS(Test::WaitForEventThreadTrigger(1), true, TEST_LOCATION);
3426 DevelStyleManager::SetBrokenImageUrl(styleManager, DevelStyleManager::BrokenImageType::NORMAL, "invalidBroken.9.png");
3428 ImageView imageView3 = ImageView::New("invalidUrl.png");
3429 imageView3.SetProperty(Actor::Property::SIZE, Vector2(100.f, 100.f));
3430 application.GetScene().Add(imageView3);
3432 application.SendNotification();
3433 application.Render(16);
3435 // loading started, this waits for the loader thread
3436 DALI_TEST_EQUALS(Test::WaitForEventThreadTrigger(1), true, TEST_LOCATION);
3443 static int gResourceReadySignalCounter = 0;
3445 void OnResourceReadySignal01(Control control)
3447 gResourceReadySignalCounter++;
3449 if(control.GetVisualResourceStatus(ImageView::Property::IMAGE) == Visual::ResourceStatus::READY)
3451 if(gResourceReadySignalCounter == 1)
3454 // It makes the first new visual be deleted immediately
3455 ImageView::DownCast(control).SetImage(gImage_34_RGBA);
3456 ImageView::DownCast(control).SetImage(gImage_34_RGBA);
3459 else if(control.GetVisualResourceStatus(ImageView::Property::IMAGE) == Visual::ResourceStatus::FAILED)
3461 // Make the resource ready immediately
3462 control[ImageView::Property::IMAGE] = gImage_600_RGB;
3466 void OnResourceReadySignal02(Control control)
3468 if(++gResourceReadySignalCounter == 1)
3470 // It makes the first new visual be deleted immediately
3471 // The first image will not be loaded.
3472 control[ImageView::Property::IMAGE] = Property::Map().Add(ImageVisual::Property::URL, gImage_600_RGB).Add(ImageVisual::Property::RELEASE_POLICY, ImageVisual::ReleasePolicy::NEVER);
3473 control[ImageView::Property::IMAGE] = TEST_IMAGE_1;
3477 ImageView gImageView1;
3478 ImageView gImageView2;
3479 ImageView gImageView3;
3480 ImageView gImageView4;
3482 void OnResourceReadySignal03(Control control)
3484 if(gResourceReadySignalCounter == 0)
3487 // 1. Use cached image, then LoadComplete will be called right after OnResourceReadySignal03.
3488 gImageView2[ImageView::Property::IMAGE] = gImage_34_RGBA;
3490 // 2. Load a new image
3491 gImageView3[ImageView::Property::IMAGE] = TEST_IMAGE_1;
3493 // 3. Use the new image again
3494 gImageView1[ImageView::Property::IMAGE] = TEST_IMAGE_1;
3495 gImageView1.ResourceReadySignal().Connect(&OnResourceReadySignal03);
3497 else if(gResourceReadySignalCounter == 1)
3499 // This is called from TextureManager::ProcessQueuedTextures().
3500 gImageView1.Unparent();
3501 gImageView1.Reset();
3503 gResourceReadySignalCounter++;
3506 void OnSimpleResourceReadySignal(Control control)
3508 // simply increate counter
3509 gResourceReadySignalCounter++;
3512 int gResourceReadySignal04ComesOrder = 0;
3514 void OnResourceReadySignal04(Control control)
3516 gResourceReadySignalCounter++;
3517 tet_printf("rc %d\n", gResourceReadySignalCounter);
3518 if(gResourceReadySignalCounter == 1)
3520 auto scene = gImageView1.GetParent();
3522 // Request load something
3523 // We hope this request result is return later than gImageView2.
3524 gImageView3 = ImageView::New(TEST_IMAGE_1);
3525 gImageView3.ResourceReadySignal().Connect(&OnResourceReadySignal04);
3526 scene.Add(gImageView3);
3527 gImageView4 = ImageView::New(TEST_IMAGE_2);
3528 gImageView4.ResourceReadySignal().Connect(&OnResourceReadySignal04);
3529 scene.Add(gImageView4);
3531 if(control == gImageView1)
3533 gResourceReadySignal04ComesOrder = 1;
3537 gResourceReadySignal04ComesOrder = 2;
3540 if(gResourceReadySignalCounter == 2)
3542 if(gResourceReadySignal04ComesOrder == 1 && control == gImageView2)
3544 // Scene off first one.
3545 gImageView1.Unparent();
3547 // Scene off second one.
3548 gImageView2.Unparent();
3550 else if(gResourceReadySignal04ComesOrder == 2 && control == gImageView1)
3552 // Scene off first one.
3553 gImageView2.Unparent();
3555 // Scene off second one.
3556 gImageView1.Unparent();
3560 // We can't check that this utc fail case. just pass always when we come here.
3561 gResourceReadySignal04ComesOrder = -1;
3564 // If we don't seperate index of FreeList area
3565 // and if we don't queue remove during obversing,
3566 // cache index become something invalid data.
3567 // In this case, some strange observer can be called.
3568 // For example, gImageView4.LoadComplete will be called.
3572 void OnResourceReadySignal05(Control control)
3574 gResourceReadySignalCounter++;
3576 // Request load with same image
3577 // NOTE : The url must not be same as gImageView1
3578 const int viewCount = 4;
3579 for(int i = 0; i < viewCount; ++i)
3581 gImageView1.Add(ImageView::New("invalid2.jpg"));
3585 int gResourceReadySignal06ComesOrder = 0;
3587 void OnResourceReadySignal06(Control control)
3589 gResourceReadySignalCounter++;
3590 if(gResourceReadySignalCounter == 1)
3592 auto scene = gImageView1.GetParent();
3594 // Request load something
3595 // We hope this request result is return later than gImageView2.
3598 map1[Toolkit::ImageVisual::Property::URL] = TEST_IMAGE_1;
3599 map1[Toolkit::ImageVisual::Property::ALPHA_MASK_URL] = TEST_BROKEN_IMAGE_DEFAULT;
3601 gImageView3 = ImageView::New();
3602 gImageView3.SetProperty(Toolkit::ImageView::Property::IMAGE, map1);
3603 gImageView3.ResourceReadySignal().Connect(&OnResourceReadySignal06);
3606 map2[Toolkit::ImageVisual::Property::URL] = TEST_IMAGE_2;
3607 map2[Toolkit::ImageVisual::Property::ALPHA_MASK_URL] = TEST_BROKEN_IMAGE_S;
3608 gImageView4 = ImageView::New();
3609 gImageView4.SetProperty(Toolkit::ImageView::Property::IMAGE, map2);
3610 gImageView4.ResourceReadySignal().Connect(&OnResourceReadySignal06);
3612 if(control == gImageView1)
3614 gResourceReadySignal06ComesOrder = 1;
3618 gResourceReadySignal06ComesOrder = 2;
3621 if(gResourceReadySignalCounter == 2)
3623 if(gResourceReadySignal06ComesOrder == 1 && control == gImageView2)
3625 // Scene off first one.
3626 gImageView1.Unparent();
3628 // Scene off second one.
3629 gImageView2.Unparent();
3631 else if(gResourceReadySignal06ComesOrder == 2 && control == gImageView1)
3633 // Scene off first one.
3634 gImageView2.Unparent();
3636 // Scene off second one.
3637 gImageView1.Unparent();
3641 // We can't check that this utc fail case. just pass always when we come here.
3642 gResourceReadySignal06ComesOrder = -1;
3645 // If we don't seperate index of FreeList area
3646 // and if we don't queue remove during obversing,
3647 // cache index become something invalid data.
3648 // In this case, some strange observer can be called.
3649 // For example, gImageView4.LoadComplete will be called.
3653 void OnResourceReadySignal07(Control control)
3655 gResourceReadySignalCounter++;
3656 // Load masked image
3657 tet_printf("rc %d %d\n", gResourceReadySignalCounter, static_cast<bool>(gImageView2));
3661 auto scene = gImageView1.GetParent();
3664 map1[Toolkit::ImageVisual::Property::URL] = TEST_IMAGE_1;
3665 map1[Toolkit::ImageVisual::Property::ALPHA_MASK_URL] = TEST_BROKEN_IMAGE_DEFAULT;
3667 gImageView2 = ImageView::New();
3668 gImageView2.SetProperty(Toolkit::ImageView::Property::IMAGE, map1);
3669 gImageView2.ResourceReadySignal().Connect(&OnResourceReadySignal07);
3671 scene.Add(gImageView2);
3677 int UtcDaliImageViewSetImageOnResourceReadySignal01(void)
3679 tet_infoline("Test setting image from within signal handler.");
3681 ToolkitTestApplication application;
3683 gResourceReadySignalCounter = 0;
3685 ImageView imageView = ImageView::New(gImage_34_RGBA);
3686 imageView.ResourceReadySignal().Connect(&OnResourceReadySignal01);
3688 application.GetScene().Add(imageView);
3690 DALI_TEST_EQUALS(Test::WaitForEventThreadTrigger(1), true, TEST_LOCATION);
3692 application.SendNotification();
3693 application.Render();
3695 DALI_TEST_EQUALS(gResourceReadySignalCounter, 2, TEST_LOCATION);
3697 DALI_TEST_EQUALS(imageView.IsResourceReady(), true, TEST_LOCATION);
3699 // Create a new ImageView to cache the image
3700 ImageView imageView1 = ImageView::New(gImage_600_RGB);
3701 application.GetScene().Add(imageView1);
3703 DALI_TEST_EQUALS(Test::WaitForEventThreadTrigger(1), true, TEST_LOCATION);
3705 application.SendNotification();
3706 application.Render();
3709 gResourceReadySignalCounter = 0;
3711 imageView[ImageView::Property::IMAGE] = "invalid.jpg";
3713 DALI_TEST_EQUALS(Test::WaitForEventThreadTrigger(1), true, TEST_LOCATION);
3715 application.SendNotification();
3716 application.Render();
3718 // Run idle callback
3719 application.RunIdles();
3721 DALI_TEST_EQUALS(gResourceReadySignalCounter, 2, TEST_LOCATION);
3723 DALI_TEST_EQUALS(imageView.IsResourceReady(), true, TEST_LOCATION);
3728 int UtcDaliImageViewSetImageOnResourceReadySignal02(void)
3730 tet_infoline("Test setting image from within signal handler.");
3732 ToolkitTestApplication application;
3734 gResourceReadySignalCounter = 0;
3736 ImageView imageView = ImageView::New(gImage_34_RGBA);
3737 imageView.ResourceReadySignal().Connect(&OnResourceReadySignal02);
3739 application.GetScene().Add(imageView);
3741 DALI_TEST_EQUALS(Test::WaitForEventThreadTrigger(1), true, TEST_LOCATION);
3743 application.SendNotification();
3744 application.Render();
3746 // Wait for loading an image
3747 DALI_TEST_EQUALS(Test::WaitForEventThreadTrigger(1), true, TEST_LOCATION);
3749 DALI_TEST_EQUALS(gResourceReadySignalCounter, 2, TEST_LOCATION);
3751 DALI_TEST_EQUALS(imageView.IsResourceReady(), true, TEST_LOCATION);
3756 int UtcDaliImageViewSetImageOnResourceReadySignal03(void)
3758 tet_infoline("Test setting image from within signal handler.");
3760 ToolkitTestApplication application;
3762 gResourceReadySignalCounter = 0;
3764 gImageView1 = ImageView::New(gImage_34_RGBA);
3765 application.GetScene().Add(gImageView1);
3768 DALI_TEST_EQUALS(Test::WaitForEventThreadTrigger(1), true, TEST_LOCATION);
3770 gImageView2 = ImageView::New(gImage_600_RGB);
3771 gImageView2.ResourceReadySignal().Connect(&OnResourceReadySignal03);
3772 application.GetScene().Add(gImageView2);
3774 gImageView3 = ImageView::New();
3775 application.GetScene().Add(gImageView3);
3777 DALI_TEST_EQUALS(Test::WaitForEventThreadTrigger(2), true, TEST_LOCATION);
3779 application.SendNotification();
3780 application.Render();
3785 int UtcDaliImageViewOnResourceReadySignalWithBrokenAlphaMask01(void)
3787 tet_infoline("Test signal handler when image / mask image is broken.");
3789 ToolkitTestApplication application;
3791 auto TestResourceReadyUrl = [&application](int eventTriggerCount, bool isSynchronous, const std::string& url, const std::string& mask, const char* location) {
3792 gResourceReadySignalCounter = 0;
3795 map[Toolkit::ImageVisual::Property::URL] = url;
3798 map[Toolkit::ImageVisual::Property::ALPHA_MASK_URL] = mask;
3800 map[Toolkit::ImageVisual::Property::SYNCHRONOUS_LOADING] = isSynchronous;
3802 ImageView imageView = ImageView::New();
3803 imageView[Toolkit::ImageView::Property::IMAGE] = map;
3804 imageView[Actor::Property::SIZE] = Vector2(100.0f, 200.0f);
3805 imageView.ResourceReadySignal().Connect(&OnSimpleResourceReadySignal);
3807 application.GetScene().Add(imageView);
3808 application.SendNotification();
3809 application.Render();
3814 DALI_TEST_EQUALS(Test::WaitForEventThreadTrigger(eventTriggerCount), true, location);
3816 tet_printf("test %s [sync:%d] signal fired\n", url.c_str(), isSynchronous ? 1 : 0);
3817 DALI_TEST_EQUALS(gResourceReadySignalCounter, 1, location);
3819 imageView.Unparent();
3822 for(int synchronous = 0; synchronous <= 1; synchronous++)
3824 tet_printf("Test normal case (sync:%d)\n", synchronous);
3825 TestResourceReadyUrl(1, synchronous, gImage_600_RGB, "", TEST_LOCATION);
3826 TestResourceReadyUrl(3, synchronous, gImage_600_RGB, gImage_34_RGBA, TEST_LOCATION); // 3 event trigger required : 2 image load + 1 apply mask
3828 tet_printf("Test broken image case (sync:%d)\n", synchronous);
3829 TestResourceReadyUrl(1, synchronous, "invalid.jpg", "", TEST_LOCATION);
3830 TestResourceReadyUrl(2, synchronous, "invalid.jpg", gImage_34_RGBA, TEST_LOCATION);
3832 tet_printf("Test broken mask image case (sync:%d)\n", synchronous);
3833 TestResourceReadyUrl(2, synchronous, gImage_600_RGB, "invalid.png", TEST_LOCATION);
3835 tet_printf("Test broken both image, mask image case (sync:%d)\n", synchronous);
3836 TestResourceReadyUrl(2, synchronous, "invalid.jpg", "invalid.png", TEST_LOCATION);
3842 int UtcDaliImageViewOnResourceReadySignalWithBrokenAlphaMask02(void)
3844 tet_infoline("Test signal handler when image try to use cached-and-broken mask image.");
3846 ToolkitTestApplication application;
3848 gResourceReadySignalCounter = 0;
3850 auto TestBrokenMaskResourceReadyUrl = [&application](const std::string& url, const char* location) {
3852 map[Toolkit::ImageVisual::Property::URL] = url;
3853 // Use invalid mask url
3854 map[Toolkit::ImageVisual::Property::ALPHA_MASK_URL] = "invalid.png";
3856 ImageView imageView = ImageView::New();
3857 imageView[Toolkit::ImageView::Property::IMAGE] = map;
3858 imageView[Actor::Property::SIZE] = Vector2(100.0f, 200.0f);
3859 imageView.ResourceReadySignal().Connect(&OnSimpleResourceReadySignal);
3861 application.GetScene().Add(imageView);
3863 // Don't unparent imageView, for keep the cache.
3866 // Use more than 4 images (The number of LocalImageLoadThread)
3867 const std::vector<std::string> testUrlList = {gImage_34_RGBA, gImage_600_RGB, "invalid.jpg" /* invalid url */, TEST_IMAGE_1, TEST_IMAGE_2, TEST_BROKEN_IMAGE_DEFAULT};
3869 int expectResourceReadySignalCounter = 0;
3871 for(auto& url : testUrlList)
3873 TestBrokenMaskResourceReadyUrl(url, TEST_LOCATION);
3874 expectResourceReadySignalCounter++;
3877 // Remain 1 signal due to we use #URL + 1 mask image.
3878 DALI_TEST_EQUALS(Test::WaitForEventThreadTrigger(expectResourceReadySignalCounter + 1), true, TEST_LOCATION);
3879 application.SendNotification();
3880 application.Render();
3881 DALI_TEST_EQUALS(gResourceReadySignalCounter, expectResourceReadySignalCounter, TEST_LOCATION);
3886 int UtcDaliImageViewCheckVariousCaseSendOnResourceReadySignal(void)
3888 tet_infoline("Test signal handler various case.");
3890 auto TestResourceReadyUrl = [](int eventTriggerCount, bool isSynchronous, bool loadSuccess, const std::string& url, const std::string& mask, const char* location) {
3891 ToolkitTestApplication application;
3893 gResourceReadySignalCounter = 0;
3896 map[Toolkit::ImageVisual::Property::URL] = url;
3899 map[Toolkit::ImageVisual::Property::ALPHA_MASK_URL] = mask;
3901 map[Toolkit::ImageVisual::Property::SYNCHRONOUS_LOADING] = isSynchronous;
3903 ImageView imageView = ImageView::New();
3904 imageView[Toolkit::ImageView::Property::IMAGE] = map;
3905 imageView[Actor::Property::SIZE] = Vector2(100.0f, 200.0f);
3906 imageView.ResourceReadySignal().Connect(&OnSimpleResourceReadySignal);
3908 application.GetScene().Add(imageView);
3909 application.SendNotification();
3910 application.Render();
3913 DALI_TEST_EQUALS(Test::WaitForEventThreadTrigger(eventTriggerCount), true, location);
3915 tet_printf("test %s [sync:%d] signal fired\n", url.c_str(), isSynchronous ? 1 : 0);
3916 DALI_TEST_EQUALS(gResourceReadySignalCounter, 1, location);
3917 DALI_TEST_EQUALS(imageView.GetVisualResourceStatus(Toolkit::ImageView::Property::IMAGE), loadSuccess ? Toolkit::Visual::ResourceStatus::READY : Toolkit::Visual::ResourceStatus::FAILED, location);
3919 imageView.Unparent();
3922 auto TestAuxiliaryResourceReadyUrl = [](bool isSynchronous, bool loadSuccess, const std::string& url, const std::string& auxiliaryUrl, const char* location) {
3923 ToolkitTestApplication application;
3925 gResourceReadySignalCounter = 0;
3928 map[Toolkit::ImageVisual::Property::URL] = url;
3929 map[Toolkit::DevelImageVisual::Property::AUXILIARY_IMAGE] = auxiliaryUrl;
3930 map[Toolkit::DevelImageVisual::Property::AUXILIARY_IMAGE_ALPHA] = 0.5f;
3931 map[Toolkit::ImageVisual::Property::SYNCHRONOUS_LOADING] = isSynchronous;
3933 ImageView imageView = ImageView::New();
3934 imageView.SetProperty(Toolkit::ImageView::Property::IMAGE, map);
3935 imageView.SetProperty(Actor::Property::SIZE, Vector2(100.0f, 200.0f));
3936 imageView.ResourceReadySignal().Connect(&OnSimpleResourceReadySignal);
3937 application.GetScene().Add(imageView);
3939 application.SendNotification();
3940 application.Render();
3945 DALI_TEST_EQUALS(Test::WaitForEventThreadTrigger(2), true, location);
3948 tet_printf("test %s [sync:%d] signal fired\n", url.c_str(), isSynchronous ? 1 : 0);
3949 DALI_TEST_EQUALS(gResourceReadySignalCounter, 1, location);
3950 DALI_TEST_EQUALS(imageView.GetVisualResourceStatus(Toolkit::ImageView::Property::IMAGE), loadSuccess ? Toolkit::Visual::ResourceStatus::READY : Toolkit::Visual::ResourceStatus::FAILED, TEST_LOCATION);
3952 imageView.Unparent();
3955 // Case 1 : asynchronous loading
3956 tet_printf("Test invalid single simple image Asynchronous\n");
3959 TestResourceReadyUrl(1, 0, 1, gImage_600_RGB, "", TEST_LOCATION);
3960 TestResourceReadyUrl(2, 0, 1, TEST_SVG_FILE_NAME, "", TEST_LOCATION); // load & rasterize
3961 TestResourceReadyUrl(1, 0, 1, TEST_BROKEN_IMAGE_L, "", TEST_LOCATION);
3963 TestResourceReadyUrl(2, 0, 1, TEST_GIF_FILE_NAME, "", TEST_LOCATION); // 2 image loading - batch size
3964 TestResourceReadyUrl(2, 0, 1, TEST_ANIMATED_VECTOR_IMAGE_FILE_NAME, "", TEST_LOCATION); // load & rasterize
3966 TestResourceReadyUrl(3, 0, 1, gImage_600_RGB, gImage_34_RGBA, TEST_LOCATION); // 2 image loading + 1 applymask
3968 TestAuxiliaryResourceReadyUrl(0, 1, TEST_BROKEN_IMAGE_L, gImage_34_RGBA, TEST_LOCATION);
3971 TestResourceReadyUrl(1, 0, 0, "invalid.jpg", "", TEST_LOCATION);
3972 TestResourceReadyUrl(1, 0, 0, "invalid.svg", "", TEST_LOCATION);
3973 TestResourceReadyUrl(1, 0, 0, "invalid.9.png", "", TEST_LOCATION);
3974 TestResourceReadyUrl(1, 0, 0, "invalid.gif", "", TEST_LOCATION); // 1 image loading
3975 TestResourceReadyUrl(1, 0, 0, "invalid.json", "", TEST_LOCATION); // 0 rasterize
3977 TestResourceReadyUrl(2, 0, 0, "invalid.jpg", "invalid.png", TEST_LOCATION); // 2 image loading
3978 TestResourceReadyUrl(2, 0, 1, gImage_600_RGB, "invalid.png", TEST_LOCATION); // 2 image loading
3979 TestResourceReadyUrl(2, 0, 0, "invalid.jpg", gImage_34_RGBA, TEST_LOCATION); // 2 image loading
3981 TestAuxiliaryResourceReadyUrl(0, 0, "invalid.9.png", "invalid.png", TEST_LOCATION);
3982 TestAuxiliaryResourceReadyUrl(0, 1, TEST_BROKEN_IMAGE_L, "invalid.png", TEST_LOCATION);
3983 TestAuxiliaryResourceReadyUrl(0, 0, "invalid.9.png", gImage_34_RGBA, TEST_LOCATION);
3985 // Case 2 : Synchronous loading
3986 tet_printf("Test invalid single simple image Synchronous\n");
3989 TestResourceReadyUrl(0, 1, 1, gImage_600_RGB, "", TEST_LOCATION);
3990 TestResourceReadyUrl(0, 1, 1, TEST_SVG_FILE_NAME, "", TEST_LOCATION); // synchronous rasterize
3991 TestResourceReadyUrl(0, 1, 1, TEST_BROKEN_IMAGE_L, "", TEST_LOCATION);
3993 TestResourceReadyUrl(1, 1, 1, TEST_GIF_FILE_NAME, "", TEST_LOCATION); // first frame image loading sync + second frame image loading async
3995 TestResourceReadyUrl(0, 1, 1, gImage_600_RGB, gImage_34_RGBA, TEST_LOCATION);
3997 TestAuxiliaryResourceReadyUrl(1, 1, TEST_BROKEN_IMAGE_L, gImage_34_RGBA, TEST_LOCATION);
4000 TestResourceReadyUrl(0, 1, 0, "invalid.jpg", "", TEST_LOCATION);
4001 TestResourceReadyUrl(0, 1, 0, "invalid.svg", "", TEST_LOCATION);
4002 TestResourceReadyUrl(0, 1, 0, "invalid.9.png", "", TEST_LOCATION);
4003 TestResourceReadyUrl(0, 1, 0, "invalid.gif", "", TEST_LOCATION);
4005 TestResourceReadyUrl(0, 1, 0, "invalid.jpg", "invalid.png", TEST_LOCATION);
4006 TestResourceReadyUrl(0, 1, 1, gImage_600_RGB, "invalid.png", TEST_LOCATION);
4007 TestResourceReadyUrl(0, 1, 0, "invalid.jpg", gImage_34_RGBA, TEST_LOCATION);
4009 TestAuxiliaryResourceReadyUrl(1, 0, "invalid.9.png", "invalid.png", TEST_LOCATION);
4010 TestAuxiliaryResourceReadyUrl(1, 1, TEST_BROKEN_IMAGE_L, "invalid.png", TEST_LOCATION);
4011 TestAuxiliaryResourceReadyUrl(1, 0, "invalid.9.png", gImage_34_RGBA, TEST_LOCATION);
4016 int UtcDaliImageViewSetImageOnResourceReadySignal04(void)
4018 tet_infoline("Test texturemanager's remove queue works well within signal handler.");
4020 ToolkitTestApplication application;
4022 gResourceReadySignalCounter = 0;
4023 gResourceReadySignal04ComesOrder = 0;
4025 gImageView1 = ImageView::New("invalid.jpg"); // request invalid image, to make loading failed fast.
4026 gImageView1.ResourceReadySignal().Connect(&OnResourceReadySignal04);
4027 application.GetScene().Add(gImageView1);
4029 gImageView2 = ImageView::New("invalid.png"); // request invalid image, to make loading failed fast.
4030 gImageView2.ResourceReadySignal().Connect(&OnResourceReadySignal04);
4031 application.GetScene().Add(gImageView2);
4033 application.SendNotification();
4034 application.Render();
4036 tet_infoline("Try to load 2 invalid image");
4038 DALI_TEST_EQUALS(Test::WaitForEventThreadTrigger(2), true, TEST_LOCATION);
4039 DALI_TEST_EQUALS(gResourceReadySignalCounter, 2, TEST_LOCATION);
4041 tet_infoline("load done");
4043 // We can test this UTC only if gImageView1 and gImageView2 loaded done.
4044 if(gResourceReadySignal04ComesOrder == -1)
4046 tet_infoline("Bad news.. gImageView3 or gImageView4 loaded faster than others. just skip this UTC");
4050 // gImageView3 and gImageView4 load must not be successed yet.
4051 DALI_TEST_EQUALS(gImageView3.GetRendererCount(), 0u, TEST_LOCATION);
4052 DALI_TEST_EQUALS(gImageView4.GetRendererCount(), 0u, TEST_LOCATION);
4054 application.SendNotification();
4055 application.Render();
4057 tet_infoline("Try to load 2 valid image");
4059 DALI_TEST_EQUALS(Test::WaitForEventThreadTrigger(2), true, TEST_LOCATION);
4060 DALI_TEST_EQUALS(gResourceReadySignalCounter, 4, TEST_LOCATION);
4062 tet_infoline("load done");
4064 // gImageView3 and gImageView4 load must be successed now.
4065 DALI_TEST_EQUALS(gImageView3.GetRendererAt(0).GetTextures().GetTextureCount(), 1u, TEST_LOCATION);
4066 DALI_TEST_EQUALS(gImageView4.GetRendererAt(0).GetTextures().GetTextureCount(), 1u, TEST_LOCATION);
4071 int UtcDaliImageViewSetImageOnResourceReadySignal05(void)
4073 tet_infoline("Test multiple views with same image during ResourceReady load the image only 1 times");
4075 ToolkitTestApplication application;
4077 gResourceReadySignalCounter = 0;
4079 gImageView1 = ImageView::New("invalid.jpg"); // request invalid image, to make loading failed fast.
4080 gImageView1.ResourceReadySignal().Connect(&OnResourceReadySignal05);
4081 application.GetScene().Add(gImageView1);
4083 application.SendNotification();
4084 application.Render();
4086 tet_infoline("Try to load 1 invalid.jpg image");
4087 DALI_TEST_EQUALS(Test::WaitForEventThreadTrigger(1), true, TEST_LOCATION);
4088 DALI_TEST_EQUALS(gResourceReadySignalCounter, 1, TEST_LOCATION);
4090 tet_infoline("Try to load 1 invalid2.jpg image");
4091 DALI_TEST_EQUALS(Test::WaitForEventThreadTrigger(1), true, TEST_LOCATION);
4093 tet_infoline("Now we don't have any image to be loaded. Check event thread trigger failed.");
4094 DALI_TEST_EQUALS(Test::WaitForEventThreadTrigger(1, 1), false, TEST_LOCATION);
4096 gImageView1.Unparent();
4097 gImageView1.Reset();
4101 int UtcDaliImageViewSetImageOnResourceReadySignal06(void)
4103 tet_infoline("Test texturemanager's remove image & mask queue works well within signal handler.");
4105 ToolkitTestApplication application;
4107 gResourceReadySignalCounter = 0;
4108 gResourceReadySignal06ComesOrder = 0;
4111 map[Toolkit::ImageVisual::Property::URL] = "invalid.jpg";
4112 map[Toolkit::ImageVisual::Property::ALPHA_MASK_URL] = "invalid.png";
4114 gImageView1 = ImageView::New(); // request invalid image, to make loading failed fast.
4115 gImageView1.SetProperty(Toolkit::ImageView::Property::IMAGE, map);
4116 gImageView1.ResourceReadySignal().Connect(&OnResourceReadySignal06);
4117 application.GetScene().Add(gImageView1);
4119 gImageView2 = ImageView::New(); // request invalid image, to make loading failed fast.
4120 gImageView2.SetProperty(Toolkit::ImageView::Property::IMAGE, map);
4121 gImageView2.ResourceReadySignal().Connect(&OnResourceReadySignal06);
4122 application.GetScene().Add(gImageView2);
4124 application.SendNotification();
4125 application.Render();
4127 tet_infoline("Try to load 2 invalid image");
4129 DALI_TEST_EQUALS(Test::WaitForEventThreadTrigger(2), true, TEST_LOCATION);
4130 DALI_TEST_EQUALS(gResourceReadySignalCounter, 2, TEST_LOCATION);
4132 tet_infoline("load done");
4134 // We can test this UTC only if gImageView1 and gImageView2 loaded done.
4135 if(gResourceReadySignal06ComesOrder == -1)
4137 tet_infoline("Bad news.. gImageView3 or gImageView4 loaded faster than others. just skip this UTC");
4141 // gImageView3 and gImageView4 load must not be successed yet.
4142 DALI_TEST_EQUALS(gImageView3.GetRendererCount(), 0u, TEST_LOCATION);
4143 DALI_TEST_EQUALS(gImageView4.GetRendererCount(), 0u, TEST_LOCATION);
4145 application.GetScene().Add(gImageView3);
4146 application.GetScene().Add(gImageView4);
4147 application.SendNotification();
4148 application.Render();
4150 tet_infoline("Try to load 2 valid image");
4152 DALI_TEST_EQUALS(Test::WaitForEventThreadTrigger(2), true, TEST_LOCATION);
4153 DALI_TEST_EQUALS(gResourceReadySignalCounter, 2, TEST_LOCATION);
4155 tet_infoline("load done");
4160 int UtcDaliImageViewSetImageOnResourceReadySignal07(void)
4162 tet_infoline("Test texturemanager's remove image & mask queue works well within signal handler 02.");
4164 ToolkitTestApplication application;
4166 gResourceReadySignalCounter = 0;
4169 map[Toolkit::ImageVisual::Property::URL] = TEST_IMAGE_1;
4171 // Clear image view for clear test
4175 gImageView1.Reset();
4179 gImageView2.Reset();
4182 gImageView1 = ImageView::New();
4183 gImageView1.SetProperty(Toolkit::ImageView::Property::IMAGE, map);
4184 gImageView1.ResourceReadySignal().Connect(&OnResourceReadySignal07);
4185 application.GetScene().Add(gImageView1);
4187 application.SendNotification();
4188 application.Render();
4192 DALI_TEST_EQUALS(Test::WaitForEventThreadTrigger(1), true, TEST_LOCATION);
4193 DALI_TEST_EQUALS(gResourceReadySignalCounter, 1, TEST_LOCATION);
4195 tet_infoline("load image1 done");
4197 // Load gImageView2 and mask
4199 DALI_TEST_EQUALS(Test::WaitForEventThreadTrigger(2), true, TEST_LOCATION);
4200 DALI_TEST_EQUALS(gResourceReadySignalCounter, 1, TEST_LOCATION);
4202 // gImageView2 mask apply done
4204 DALI_TEST_EQUALS(Test::WaitForEventThreadTrigger(1), true, TEST_LOCATION);
4205 DALI_TEST_EQUALS(gResourceReadySignalCounter, 2, TEST_LOCATION);
4207 tet_infoline("load image2 done");
4211 int UtcDaliImageViewUseSameUrlWithAnimatedImageVisual(void)
4213 tet_infoline("Test multiple views with same image in animated image visual");
4214 ToolkitTestApplication application;
4216 gImageView1 = ImageView::New(TEST_WEBP_FILE_NAME);
4217 application.GetScene().Add(gImageView1);
4219 tet_infoline("Remove imageView and Create new imageView with same url");
4220 application.GetScene().Remove(gImageView1);
4221 gImageView2 = ImageView::New(TEST_WEBP_FILE_NAME);
4222 application.GetScene().Add(gImageView2);
4224 application.SendNotification();
4225 application.Render();
4227 tet_infoline("Check the ImageView load image successfully");
4228 DALI_TEST_EQUALS(Test::WaitForEventThreadTrigger(1), true, TEST_LOCATION);
4232 int UtcDaliImageViewNpatchImageCacheTest01(void)
4234 tet_infoline("Test npatch image cached");
4236 ToolkitTestApplication application;
4237 ImageView imageView[2];
4239 auto& gl = application.GetGlAbstraction();
4240 gl.EnableTextureCallTrace(true);
4241 auto& textureCallStack = gl.GetTextureTrace();
4242 textureCallStack.Enable(true);
4243 textureCallStack.EnableLogging(true);
4245 auto TestNPatch = [&](int index, const std::string& nPatchImageUrl, const char* location) {
4246 if(imageView[index])
4248 imageView[index].Unparent();
4250 imageView[index] = ImageView::New(nPatchImageUrl);
4251 imageView[index].SetProperty(Actor::Property::SIZE, Vector2(100.0f, 200.0f));
4252 application.GetScene().Add(imageView[index]);
4255 TestNPatch(0, TEST_BROKEN_IMAGE_M, TEST_LOCATION);
4256 DALI_TEST_EQUALS(Test::WaitForEventThreadTrigger(1), true, TEST_LOCATION);
4258 application.SendNotification();
4259 application.Render();
4261 tet_printf("trace : \n%s\n", textureCallStack.GetTraceString().c_str());
4263 // Check we gen only 1 textures
4264 DALI_TEST_EQUALS(textureCallStack.CountMethod("GenTextures"), 1, TEST_LOCATION);
4265 textureCallStack.Reset();
4267 // Let we use cached textures
4268 for(int i = 0; i < 10; i++)
4270 TestNPatch(1, TEST_BROKEN_IMAGE_M, TEST_LOCATION);
4271 TestNPatch(0, TEST_BROKEN_IMAGE_M, TEST_LOCATION);
4274 application.SendNotification();
4275 application.Render();
4276 // Check we use cached npatch data so we don't generate new texture textures
4277 DALI_TEST_EQUALS(textureCallStack.CountMethod("GenTextures"), 0, TEST_LOCATION);
4280 imageView[0].Unparent();
4281 imageView[0].Reset();
4282 imageView[1].Unparent();
4283 imageView[1].Reset();
4285 application.SendNotification();
4286 application.Render();
4288 textureCallStack.Reset();
4289 // Let we use deference textures
4290 TestNPatch(1, TEST_BROKEN_IMAGE_S, TEST_LOCATION);
4291 DALI_TEST_EQUALS(Test::WaitForEventThreadTrigger(1), true, TEST_LOCATION);
4293 application.SendNotification();
4294 application.Render();
4295 // Try to load multiple times.
4296 for(int i = 0; i < 3; i++)
4298 TestNPatch(0, TEST_BROKEN_IMAGE_M, TEST_LOCATION);
4299 DALI_TEST_EQUALS(Test::WaitForEventThreadTrigger(1), true, TEST_LOCATION);
4300 TestNPatch(1, TEST_BROKEN_IMAGE_S, TEST_LOCATION);
4301 DALI_TEST_EQUALS(Test::WaitForEventThreadTrigger(1), true, TEST_LOCATION);
4303 application.SendNotification();
4304 application.Render();
4306 imageView[0].Unparent();
4307 imageView[0].Reset();
4308 imageView[1].Unparent();
4309 imageView[1].Reset();
4311 application.SendNotification();
4312 application.Render();
4314 // Check memory leak
4315 DALI_TEST_EQUALS(textureCallStack.CountMethod("GenTextures"), textureCallStack.CountMethod("DeleteTextures"), TEST_LOCATION);
4320 int UtcDaliImageViewNpatchImageCacheTest02(void)
4322 tet_infoline("Test npatch image cached with border");
4324 ToolkitTestApplication application;
4325 ImageView imageView[2];
4327 auto& gl = application.GetGlAbstraction();
4328 gl.EnableTextureCallTrace(true);
4329 auto& textureCallStack = gl.GetTextureTrace();
4330 textureCallStack.Enable(true);
4331 textureCallStack.EnableLogging(true);
4333 auto TestBorderImage = [&](int index, const std::string& normalImageUrl, const Rect<int> border, const char* location) {
4335 map[Toolkit::Visual::Property::TYPE] = Toolkit::Visual::N_PATCH;
4336 map[Toolkit::ImageVisual::Property::URL] = normalImageUrl;
4337 map[Toolkit::ImageVisual::Property::BORDER] = border;
4339 imageView[index] = ImageView::New();
4340 imageView[index].SetProperty(Toolkit::ImageView::Property::IMAGE, map);
4341 imageView[index].SetProperty(Actor::Property::SIZE, Vector2(100.0f, 200.0f));
4342 application.GetScene().Add(imageView[index]);
4345 TestBorderImage(0, gImage_34_RGBA, Rect<int>(0, 0, 0, 0), TEST_LOCATION);
4346 DALI_TEST_EQUALS(Test::WaitForEventThreadTrigger(1), true, TEST_LOCATION);
4348 application.SendNotification();
4349 application.Render();
4351 tet_printf("trace : \n%s\n", textureCallStack.GetTraceString().c_str());
4353 // Check we gen only 1 textures
4354 DALI_TEST_EQUALS(textureCallStack.CountMethod("GenTextures"), 1, TEST_LOCATION);
4355 textureCallStack.Reset();
4357 // Let we use cached textures
4358 for(int i = 0; i < 10; i++)
4360 TestBorderImage(0, gImage_34_RGBA, Rect<int>(i, i + 1, i + 2, i + 3), TEST_LOCATION);
4361 TestBorderImage(1, gImage_34_RGBA, Rect<int>(i + 1, i, i + 3, i + 2), TEST_LOCATION);
4364 application.SendNotification();
4365 application.Render();
4367 // Check we use cached npatch data so we don't generate new texture textures
4368 DALI_TEST_EQUALS(textureCallStack.CountMethod("GenTextures"), 0, TEST_LOCATION);