Merge "Trigger svg loading early" into devel/master
[platform/core/uifw/dali-toolkit.git] / automated-tests / src / dali-toolkit / utc-Dali-ImageView.cpp
1 /*
2  * Copyright (c) 2022 Samsung Electronics Co., Ltd.
3  *
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
7  *
8  * http://www.apache.org/licenses/LICENSE-2.0
9  *
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.
15  *
16  */
17
18 #include <unistd.h>
19 #include <sstream>
20
21 // Need to override adaptor classes for toolkit test harness, so include
22 // test harness headers before dali headers.
23
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"
28
29 #include <test-encoded-image-buffer.h>
30 #include <test-native-image.h>
31
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>
44
45 using namespace Dali;
46 using namespace Toolkit;
47
48 void utc_dali_toolkit_image_view_startup(void)
49 {
50   test_return_value = TET_UNDEF;
51 }
52
53 void utc_dali_toolkit_image_view_cleanup(void)
54 {
55   test_return_value = TET_PASS;
56 }
57
58 namespace
59 {
60 const char* TEST_IMAGE_FILE_NAME  = "gallery_image_01.jpg";
61 const char* TEST_IMAGE_FILE_NAME2 = "gallery_image_02.jpg";
62
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";
66
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";
73
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";
78
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";
81
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
85 void TestUrl(ImageView imageView, const std::string url)
86 {
87   Property::Value value = imageView.GetProperty(imageView.GetPropertyIndex("image"));
88
89   std::string urlActual;
90   DALI_TEST_CHECK(value.Get(urlActual));
91   DALI_TEST_EQUALS(urlActual, url, TEST_LOCATION);
92 }
93
94 } // namespace
95
96 int UtcDaliImageViewNewP(void)
97 {
98   ToolkitTestApplication application;
99
100   ImageView imageView = ImageView::New();
101
102   DALI_TEST_CHECK(imageView);
103
104   END_TEST;
105 }
106
107 int UtcDaliImageViewNewUrlP(void)
108 {
109   ToolkitTestApplication application;
110
111   ImageView imageView = ImageView::New(TEST_IMAGE_FILE_NAME);
112   DALI_TEST_CHECK(imageView);
113
114   TestUrl(imageView, TEST_IMAGE_FILE_NAME);
115
116   END_TEST;
117 }
118
119 int UtcDaliImageViewConstructorP(void)
120 {
121   ToolkitTestApplication application;
122
123   ImageView imageView;
124
125   DALI_TEST_CHECK(!imageView);
126
127   END_TEST;
128 }
129
130 int UtcDaliImageViewCopyConstructorP(void)
131 {
132   ToolkitTestApplication application;
133
134   // Initialize an object, ref count == 1
135   ImageView imageView = ImageView::New();
136
137   ImageView copy(imageView);
138   DALI_TEST_CHECK(copy);
139
140   END_TEST;
141 }
142
143 int UtcDaliImageViewMoveConstructor(void)
144 {
145   ToolkitTestApplication application;
146
147   ImageView imageView = ImageView::New();
148   DALI_TEST_EQUALS(1, imageView.GetBaseObject().ReferenceCount(), TEST_LOCATION);
149   imageView.SetProperty(Actor::Property::SENSITIVE, false);
150   DALI_TEST_CHECK(false == imageView.GetProperty<bool>(Actor::Property::SENSITIVE));
151
152   ImageView moved = std::move(imageView);
153   DALI_TEST_CHECK(moved);
154   DALI_TEST_EQUALS(1, moved.GetBaseObject().ReferenceCount(), TEST_LOCATION);
155   DALI_TEST_CHECK(false == moved.GetProperty<bool>(Actor::Property::SENSITIVE));
156   DALI_TEST_CHECK(!imageView);
157
158   END_TEST;
159 }
160
161 int UtcDaliImageViewAssignmentOperatorP(void)
162 {
163   ToolkitTestApplication application;
164
165   ImageView imageView = ImageView::New();
166
167   ImageView copy(imageView);
168   DALI_TEST_CHECK(copy);
169   DALI_TEST_EQUALS(imageView, copy, TEST_LOCATION);
170
171   END_TEST;
172 }
173
174 int UtcDaliImageViewMoveAssignment(void)
175 {
176   ToolkitTestApplication application;
177
178   ImageView imageView = ImageView::New();
179   DALI_TEST_EQUALS(1, imageView.GetBaseObject().ReferenceCount(), TEST_LOCATION);
180   imageView.SetProperty(Actor::Property::SENSITIVE, false);
181   DALI_TEST_CHECK(false == imageView.GetProperty<bool>(Actor::Property::SENSITIVE));
182
183   ImageView moved;
184   moved = std::move(imageView);
185   DALI_TEST_CHECK(moved);
186   DALI_TEST_EQUALS(1, moved.GetBaseObject().ReferenceCount(), TEST_LOCATION);
187   DALI_TEST_CHECK(false == moved.GetProperty<bool>(Actor::Property::SENSITIVE));
188   DALI_TEST_CHECK(!imageView);
189
190   END_TEST;
191 }
192
193 int UtcDaliImageViewDownCastP(void)
194 {
195   ToolkitTestApplication application;
196
197   ImageView imageView = ImageView::New();
198
199   BaseHandle object(imageView);
200
201   ImageView imageView2 = ImageView::DownCast(object);
202   DALI_TEST_CHECK(imageView2);
203
204   ImageView imageView3 = DownCast<ImageView>(object);
205   DALI_TEST_CHECK(imageView3);
206
207   END_TEST;
208 }
209
210 int UtcDaliImageViewDownCastN(void)
211 {
212   ToolkitTestApplication application;
213
214   BaseHandle unInitializedObject;
215
216   ImageView imageView1 = ImageView::DownCast(unInitializedObject);
217   DALI_TEST_CHECK(!imageView1);
218
219   ImageView imageView2 = DownCast<ImageView>(unInitializedObject);
220   DALI_TEST_CHECK(!imageView2);
221
222   END_TEST;
223 }
224
225 int UtcDaliImageViewTypeRegistry(void)
226 {
227   ToolkitTestApplication application;
228
229   TypeRegistry typeRegistry = TypeRegistry::Get();
230   DALI_TEST_CHECK(typeRegistry);
231
232   TypeInfo typeInfo = typeRegistry.GetTypeInfo("ImageView");
233   DALI_TEST_CHECK(typeInfo);
234
235   BaseHandle handle = typeInfo.CreateInstance();
236   DALI_TEST_CHECK(handle);
237
238   ImageView imageView = ImageView::DownCast(handle);
239   DALI_TEST_CHECK(imageView);
240
241   END_TEST;
242 }
243
244 int UtcDaliImageViewSetGetProperty01(void)
245 {
246   ToolkitTestApplication application;
247
248   ImageView imageView = ImageView::New();
249
250   Property::Index idx = imageView.GetPropertyIndex("image");
251   DALI_TEST_EQUALS(idx, (Property::Index)ImageView::Property::IMAGE, TEST_LOCATION);
252
253   imageView.SetProperty(idx, TEST_IMAGE_FILE_NAME);
254   TestUrl(imageView, TEST_IMAGE_FILE_NAME);
255
256   END_TEST;
257 }
258
259 int UtcDaliImageViewPreMultipliedAlphaPng(void)
260 {
261   ToolkitTestApplication application;
262
263   // Set up trace debug
264   TestGlAbstraction& gl           = application.GetGlAbstraction();
265   TraceCallStack&    textureTrace = gl.GetTextureTrace();
266   textureTrace.Enable(true);
267
268   Property::Map imageMap;
269   imageMap[ImageVisual::Property::URL]            = gImage_34_RGBA;
270   imageMap[ImageVisual::Property::RELEASE_POLICY] = ImageVisual::ReleasePolicy::NEVER; // To keep the texture cache
271
272   ImageView imageView1 = ImageView::New();
273   imageView1.SetProperty(ImageView::Property::IMAGE, imageMap);
274
275   application.GetScene().Add(imageView1);
276
277   Property::Value value = imageView1.GetProperty(ImageView::Property::PRE_MULTIPLIED_ALPHA);
278   bool            enable;
279   DALI_TEST_CHECK(value.Get(enable));
280   DALI_TEST_CHECK(enable); // Default value is true
281
282   // loading started, this waits for the loader thread for max 30 seconds
283   DALI_TEST_EQUALS(Test::WaitForEventThreadTrigger(1), true, TEST_LOCATION);
284
285   application.SendNotification();
286   application.Render();
287
288   value = imageView1.GetProperty(ImageView::Property::PRE_MULTIPLIED_ALPHA);
289   DALI_TEST_CHECK(value.Get(enable));
290   DALI_TEST_CHECK(enable); // Keep true
291
292   // conventional alpha blending
293   Renderer renderer1 = imageView1.GetRendererAt(0);
294   value              = renderer1.GetProperty(Renderer::Property::BLEND_PRE_MULTIPLIED_ALPHA);
295   DALI_TEST_CHECK(value.Get(enable));
296   DALI_TEST_CHECK(enable);
297
298   int srcFactorRgb    = renderer1.GetProperty<int>(Renderer::Property::BLEND_FACTOR_SRC_RGB);
299   int destFactorRgb   = renderer1.GetProperty<int>(Renderer::Property::BLEND_FACTOR_DEST_RGB);
300   int srcFactorAlpha  = renderer1.GetProperty<int>(Renderer::Property::BLEND_FACTOR_SRC_ALPHA);
301   int destFactorAlpha = renderer1.GetProperty<int>(Renderer::Property::BLEND_FACTOR_DEST_ALPHA);
302   DALI_TEST_CHECK(srcFactorRgb == BlendFactor::ONE);
303   DALI_TEST_CHECK(destFactorRgb == BlendFactor::ONE_MINUS_SRC_ALPHA);
304   DALI_TEST_CHECK(srcFactorAlpha == BlendFactor::ONE);
305   DALI_TEST_CHECK(destFactorAlpha == BlendFactor::ONE_MINUS_SRC_ALPHA);
306
307   DALI_TEST_EQUALS(textureTrace.FindMethod("GenTextures"), true, TEST_LOCATION); // A new texture should be generated.
308   textureTrace.Reset();
309
310   // Disable pre-multiplied alpha blending
311   imageView1.SetProperty(ImageView::Property::PRE_MULTIPLIED_ALPHA, false);
312
313   // Reload the image
314   Property::Map attributes;
315   DevelControl::DoAction(imageView1, ImageView::Property::IMAGE, DevelImageVisual::Action::RELOAD, attributes);
316
317   // loading started, this waits for the loader thread for max 30 seconds
318   DALI_TEST_EQUALS(Test::WaitForEventThreadTrigger(1), true, TEST_LOCATION);
319
320   application.SendNotification();
321   application.Render();
322
323   value = imageView1.GetProperty(ImageView::Property::PRE_MULTIPLIED_ALPHA);
324   DALI_TEST_CHECK(value.Get(enable));
325   DALI_TEST_CHECK(!enable);
326
327   // conventional alpha blending
328   value = renderer1.GetProperty(Renderer::Property::BLEND_PRE_MULTIPLIED_ALPHA);
329   DALI_TEST_CHECK(value.Get(enable));
330   DALI_TEST_CHECK(!enable);
331
332   srcFactorRgb    = renderer1.GetProperty<int>(Renderer::Property::BLEND_FACTOR_SRC_RGB);
333   destFactorRgb   = renderer1.GetProperty<int>(Renderer::Property::BLEND_FACTOR_DEST_RGB);
334   srcFactorAlpha  = renderer1.GetProperty<int>(Renderer::Property::BLEND_FACTOR_SRC_ALPHA);
335   destFactorAlpha = renderer1.GetProperty<int>(Renderer::Property::BLEND_FACTOR_DEST_ALPHA);
336   DALI_TEST_CHECK(srcFactorRgb == BlendFactor::SRC_ALPHA);
337   DALI_TEST_CHECK(destFactorRgb == BlendFactor::ONE_MINUS_SRC_ALPHA);
338   DALI_TEST_CHECK(srcFactorAlpha == BlendFactor::ONE);
339   DALI_TEST_CHECK(destFactorAlpha == BlendFactor::ONE_MINUS_SRC_ALPHA);
340
341   DALI_TEST_EQUALS(textureTrace.FindMethod("GenTextures"), true, TEST_LOCATION); // A new texture should be generated.
342   textureTrace.Reset();
343
344   // Make a new ImageView using the same image
345   ImageView imageView2 = ImageView::New();
346   imageView2.SetProperty(ImageView::Property::IMAGE, imageMap);
347
348   application.GetScene().Add(imageView2);
349
350   application.SendNotification();
351   application.Render();
352
353   Renderer renderer2 = imageView2.GetRendererAt(0);
354   value              = renderer2.GetProperty(Renderer::Property::BLEND_PRE_MULTIPLIED_ALPHA);
355   DALI_TEST_CHECK(value.Get(enable));
356   DALI_TEST_CHECK(enable);
357
358   srcFactorRgb    = renderer2.GetProperty<int>(Renderer::Property::BLEND_FACTOR_SRC_RGB);
359   destFactorRgb   = renderer2.GetProperty<int>(Renderer::Property::BLEND_FACTOR_DEST_RGB);
360   srcFactorAlpha  = renderer2.GetProperty<int>(Renderer::Property::BLEND_FACTOR_SRC_ALPHA);
361   destFactorAlpha = renderer2.GetProperty<int>(Renderer::Property::BLEND_FACTOR_DEST_ALPHA);
362   DALI_TEST_CHECK(srcFactorRgb == BlendFactor::ONE);
363   DALI_TEST_CHECK(destFactorRgb == BlendFactor::ONE_MINUS_SRC_ALPHA);
364   DALI_TEST_CHECK(srcFactorAlpha == BlendFactor::ONE);
365   DALI_TEST_CHECK(destFactorAlpha == BlendFactor::ONE_MINUS_SRC_ALPHA);
366
367   DALI_TEST_EQUALS(textureTrace.FindMethod("GenTextures"), false, TEST_LOCATION); // The cached texture should be used.
368
369   END_TEST;
370 }
371
372 int UtcDaliImageViewPreMultipliedAlphaJpg(void)
373 {
374   ToolkitTestApplication application;
375
376   // Set up trace debug
377   TestGlAbstraction& gl           = application.GetGlAbstraction();
378   TraceCallStack&    textureTrace = gl.GetTextureTrace();
379   textureTrace.Enable(true);
380
381   Property::Map imageMap;
382   imageMap[ImageVisual::Property::URL]            = gImage_600_RGB;
383   imageMap[ImageVisual::Property::RELEASE_POLICY] = ImageVisual::ReleasePolicy::NEVER; // To keep the texture cache
384
385   ImageView imageView1 = ImageView::New();
386   imageView1.SetProperty(ImageView::Property::IMAGE, imageMap);
387
388   application.GetScene().Add(imageView1);
389
390   Property::Value value = imageView1.GetProperty(ImageView::Property::PRE_MULTIPLIED_ALPHA);
391   bool            enable;
392   DALI_TEST_CHECK(value.Get(enable));
393   DALI_TEST_CHECK(enable); // Default value is true
394
395   // loading started, this waits for the loader thread for max 30 seconds
396   DALI_TEST_EQUALS(Test::WaitForEventThreadTrigger(1), true, TEST_LOCATION);
397
398   application.SendNotification();
399   application.Render();
400
401   value = imageView1.GetProperty(ImageView::Property::PRE_MULTIPLIED_ALPHA);
402   DALI_TEST_CHECK(value.Get(enable));
403   DALI_TEST_CHECK(!enable); // Should be false after loading
404
405   // conventional alpha blending
406   Renderer renderer1 = imageView1.GetRendererAt(0);
407   value              = renderer1.GetProperty(Renderer::Property::BLEND_PRE_MULTIPLIED_ALPHA);
408   DALI_TEST_CHECK(value.Get(enable));
409   DALI_TEST_CHECK(!enable);
410
411   int srcFactorRgb    = renderer1.GetProperty<int>(Renderer::Property::BLEND_FACTOR_SRC_RGB);
412   int destFactorRgb   = renderer1.GetProperty<int>(Renderer::Property::BLEND_FACTOR_DEST_RGB);
413   int srcFactorAlpha  = renderer1.GetProperty<int>(Renderer::Property::BLEND_FACTOR_SRC_ALPHA);
414   int destFactorAlpha = renderer1.GetProperty<int>(Renderer::Property::BLEND_FACTOR_DEST_ALPHA);
415   DALI_TEST_CHECK(srcFactorRgb == BlendFactor::SRC_ALPHA);
416   DALI_TEST_CHECK(destFactorRgb == BlendFactor::ONE_MINUS_SRC_ALPHA);
417   DALI_TEST_CHECK(srcFactorAlpha == BlendFactor::ONE);
418   DALI_TEST_CHECK(destFactorAlpha == BlendFactor::ONE_MINUS_SRC_ALPHA);
419
420   DALI_TEST_EQUALS(textureTrace.FindMethod("GenTextures"), true, TEST_LOCATION); // A new texture should be generated.
421   textureTrace.Reset();
422
423   ImageView imageView2 = ImageView::New();
424   imageView2.SetProperty(ImageView::Property::IMAGE, imageMap);
425
426   // Disable pre-multiplied alpha blending
427   imageView2.SetProperty(ImageView::Property::PRE_MULTIPLIED_ALPHA, false);
428
429   application.GetScene().Add(imageView2);
430
431   application.SendNotification();
432   application.Render();
433
434   value = imageView2.GetProperty(ImageView::Property::PRE_MULTIPLIED_ALPHA);
435   DALI_TEST_CHECK(value.Get(enable));
436   DALI_TEST_CHECK(!enable);
437
438   // conventional alpha blending
439   Renderer renderer2 = imageView2.GetRendererAt(0);
440   value              = renderer2.GetProperty(Renderer::Property::BLEND_PRE_MULTIPLIED_ALPHA);
441   DALI_TEST_CHECK(value.Get(enable));
442   DALI_TEST_CHECK(!enable);
443
444   srcFactorRgb    = renderer2.GetProperty<int>(Renderer::Property::BLEND_FACTOR_SRC_RGB);
445   destFactorRgb   = renderer2.GetProperty<int>(Renderer::Property::BLEND_FACTOR_DEST_RGB);
446   srcFactorAlpha  = renderer2.GetProperty<int>(Renderer::Property::BLEND_FACTOR_SRC_ALPHA);
447   destFactorAlpha = renderer2.GetProperty<int>(Renderer::Property::BLEND_FACTOR_DEST_ALPHA);
448   DALI_TEST_CHECK(srcFactorRgb == BlendFactor::SRC_ALPHA);
449   DALI_TEST_CHECK(destFactorRgb == BlendFactor::ONE_MINUS_SRC_ALPHA);
450   DALI_TEST_CHECK(srcFactorAlpha == BlendFactor::ONE);
451   DALI_TEST_CHECK(destFactorAlpha == BlendFactor::ONE_MINUS_SRC_ALPHA);
452
453   DALI_TEST_EQUALS(textureTrace.FindMethod("GenTextures"), false, TEST_LOCATION); // The cached texture should be used.
454
455   END_TEST;
456 }
457
458 int UtcDaliImageViewPixelArea(void)
459 {
460   // Test pixel area property
461   ToolkitTestApplication application;
462
463   static std::vector<UniformData> customUniforms =
464     {
465       UniformData("pixelArea", Property::Type::VECTOR4),
466     };
467
468   TestGraphicsController& graphics = application.GetGraphicsController();
469   graphics.AddCustomUniforms(customUniforms);
470
471   // Gif image, use AnimatedImageVisual internally
472   // Atlasing is applied to pack multiple frames, use custom wrap mode
473   ImageView     gifView = ImageView::New();
474   const Vector4 pixelAreaVisual(0.f, 0.f, 2.f, 2.f);
475   gifView.SetProperty(ImageView::Property::IMAGE,
476                       Property::Map().Add(ImageVisual::Property::URL, TEST_GIF_FILE_NAME).Add(ImageVisual::Property::PIXEL_AREA, pixelAreaVisual));
477
478   // Add to stage
479   Integration::Scene stage = application.GetScene();
480   stage.Add(gifView);
481
482   // loading started
483   application.SendNotification();
484   application.Render(16);
485
486   DALI_TEST_EQUALS(Test::WaitForEventThreadTrigger(2), true, TEST_LOCATION);
487
488   application.SendNotification();
489   application.Render();
490   DALI_TEST_CHECK(gifView.GetRendererCount() == 1u);
491
492   const Vector4 fullTextureRect(0.f, 0.f, 1.f, 1.f);
493   // test that the pixel area value defined in the visual property map is registered on renderer
494   Renderer        renderer       = gifView.GetRendererAt(0);
495   Property::Value pixelAreaValue = renderer.GetProperty(renderer.GetPropertyIndex("pixelArea"));
496   DALI_TEST_EQUALS(pixelAreaValue.Get<Vector4>(), pixelAreaVisual, TEST_LOCATION);
497
498   // test that the shader has the default pixel area value registered.
499   Shader shader  = renderer.GetShader();
500   pixelAreaValue = shader.GetProperty(shader.GetPropertyIndex("pixelArea"));
501   DALI_TEST_EQUALS(pixelAreaValue.Get<Vector4>(), fullTextureRect, TEST_LOCATION);
502
503   // test that the uniform uses the pixelArea property on the renderer.
504   TestGlAbstraction& gl = application.GetGlAbstraction();
505   Vector4            pixelAreaUniform;
506   DALI_TEST_CHECK(gl.GetUniformValue<Vector4>("pixelArea", pixelAreaUniform));
507   DALI_TEST_EQUALS(pixelAreaVisual, pixelAreaUniform, Math::MACHINE_EPSILON_100, TEST_LOCATION);
508
509   // set the pixelArea property on the control
510   const Vector4 pixelAreaControl(-1.f, -1.f, 3.f, 3.f);
511   gifView.SetProperty(ImageView::Property::PIXEL_AREA, pixelAreaControl);
512   application.SendNotification();
513   application.Render(16);
514
515   // check the pixelArea property on the control
516   pixelAreaValue = gifView.GetProperty(gifView.GetPropertyIndex("pixelArea"));
517   DALI_TEST_EQUALS(pixelAreaValue.Get<Vector4>(), pixelAreaControl, TEST_LOCATION);
518   // test that the uniform uses the pixelArea property on the control.
519   DALI_TEST_CHECK(gl.GetUniformValue<Vector4>("pixelArea", pixelAreaUniform));
520   DALI_TEST_EQUALS(pixelAreaControl, pixelAreaUniform, Math::MACHINE_EPSILON_100, TEST_LOCATION);
521
522   END_TEST;
523 }
524
525 int UtcDaliImageViewAsyncLoadingWithoutAltasing(void)
526 {
527   ToolkitTestApplication     application;
528   TestGlAbstraction&         gl          = application.GetGlAbstraction();
529   const std::vector<GLuint>& textures    = gl.GetBoundTextures();
530   size_t                     numTextures = textures.size();
531
532   // Async loading, no atlasing for big size image
533   ImageView imageView = ImageView::New(gImage_600_RGB);
534
535   // By default, Aysnc loading is used
536   application.GetScene().Add(imageView);
537   imageView.SetProperty(Actor::Property::SIZE, Vector2(100, 100));
538   imageView.SetProperty(Actor::Property::PARENT_ORIGIN, ParentOrigin::CENTER);
539
540   DALI_TEST_EQUALS(Test::WaitForEventThreadTrigger(1), true, TEST_LOCATION);
541
542   application.SendNotification();
543   application.Render(16);
544   application.SendNotification();
545
546   const std::vector<GLuint>& textures2 = gl.GetBoundTextures();
547   DALI_TEST_GREATER(textures2.size(), numTextures, TEST_LOCATION);
548
549   END_TEST;
550 }
551
552 int UtcDaliImageViewAsyncLoadingWithAtlasing(void)
553 {
554   ToolkitTestApplication application;
555
556   //Async loading, automatic atlasing for small size image
557   TraceCallStack& callStack = application.GetGlAbstraction().GetTextureTrace();
558   callStack.Reset();
559   callStack.Enable(true);
560
561   Property::Map imageMap;
562
563   imageMap[ImageVisual::Property::URL]            = gImage_34_RGBA;
564   imageMap[ImageVisual::Property::DESIRED_HEIGHT] = 34;
565   imageMap[ImageVisual::Property::DESIRED_WIDTH]  = 34;
566   imageMap[ImageVisual::Property::ATLASING]       = true;
567
568   ImageView imageView = ImageView::New();
569   imageView.SetProperty(ImageView::Property::IMAGE, imageMap);
570   imageView.SetProperty(Toolkit::Control::Property::PADDING, Extents(10u, 10u, 10u, 10u));
571
572   // By default, Aysnc loading is used
573   // loading is not started if the actor is offScene
574
575   application.GetScene().Add(imageView);
576   application.SendNotification();
577   application.Render(16);
578   application.Render(16);
579   application.SendNotification();
580
581   imageView.SetProperty(Dali::Actor::Property::LAYOUT_DIRECTION, Dali::LayoutDirection::RIGHT_TO_LEFT);
582   application.SendNotification();
583   application.Render(16);
584   application.Render(16);
585   application.SendNotification();
586
587   // loading started, this waits for the loader thread for max 30 seconds
588   DALI_TEST_EQUALS(Test::WaitForEventThreadTrigger(1), true, TEST_LOCATION);
589
590   application.SendNotification();
591   application.Render(16);
592
593   callStack.Enable(false);
594
595   TraceCallStack::NamedParams params;
596   params["width"] << 34;
597   params["height"] << 34;
598   DALI_TEST_EQUALS(callStack.FindMethodAndParams("TexSubImage2D", params), true, TEST_LOCATION);
599
600   END_TEST;
601 }
602
603 int UtcDaliImageViewAsyncLoadingWithAtlasing02(void)
604 {
605   ToolkitTestApplication application;
606
607   //Async loading, automatic atlasing for small size image
608   TraceCallStack& callStack = application.GetGlAbstraction().GetTextureTrace();
609   callStack.Reset();
610   callStack.Enable(true);
611
612   Property::Map asyncLoadingMap;
613   asyncLoadingMap["url"]                = gImage_34_RGBA;
614   asyncLoadingMap["desiredHeight"]      = 34;
615   asyncLoadingMap["desiredWidth"]       = 34;
616   asyncLoadingMap["synchronousLoading"] = false;
617   asyncLoadingMap["atlasing"]           = true;
618
619   ImageView imageView = ImageView::New();
620   imageView.SetProperty(ImageView::Property::IMAGE, asyncLoadingMap);
621
622   application.GetScene().Add(imageView);
623   application.SendNotification();
624   application.Render(16);
625   application.Render(16);
626   application.SendNotification();
627
628   // loading started, this waits for the loader thread for max 30 seconds
629   DALI_TEST_EQUALS(Test::WaitForEventThreadTrigger(1), true, TEST_LOCATION);
630
631   application.SendNotification();
632   application.Render(16);
633
634   callStack.Enable(false);
635
636   TraceCallStack::NamedParams params;
637   params["width"] << 34;
638   params["height"] << 34;
639   DALI_TEST_EQUALS(callStack.FindMethodAndParams("TexSubImage2D", params), true, TEST_LOCATION);
640
641   END_TEST;
642 }
643
644 int UtcDaliImageViewSyncLoading(void)
645 {
646   ToolkitTestApplication application;
647
648   tet_infoline("ImageView Testing sync loading and size using index key property map");
649
650   Property::Map syncLoadingMap;
651   syncLoadingMap[ImageVisual::Property::SYNCHRONOUS_LOADING] = true;
652   syncLoadingMap[ImageVisual::Property::ATLASING]            = true;
653
654   // Sync loading, no atlasing for big size image
655   {
656     ImageView imageView = ImageView::New();
657
658     // Sync loading is used
659     syncLoadingMap[ImageVisual::Property::URL] = gImage_600_RGB;
660     imageView.SetProperty(ImageView::Property::IMAGE, syncLoadingMap);
661   }
662
663   // Sync loading, automatic atlasing for small size image
664   {
665     TraceCallStack& callStack = application.GetGlAbstraction().GetTextureTrace();
666     callStack.Reset();
667     callStack.Enable(true);
668
669     ImageView imageView = ImageView::New();
670
671     // Sync loading is used
672     syncLoadingMap[ImageVisual::Property::URL]            = gImage_34_RGBA;
673     syncLoadingMap[ImageVisual::Property::DESIRED_HEIGHT] = 34;
674     syncLoadingMap[ImageVisual::Property::DESIRED_WIDTH]  = 34;
675     imageView.SetProperty(ImageView::Property::IMAGE, syncLoadingMap);
676
677     application.GetScene().Add(imageView);
678     application.SendNotification();
679     application.Render(16);
680
681     TraceCallStack::NamedParams params;
682     params["width"] << 34;
683     params["height"] << 34;
684     DALI_TEST_EQUALS(callStack.FindMethodAndParams("TexSubImage2D", params),
685                      true,
686                      TEST_LOCATION);
687   }
688   END_TEST;
689 }
690
691 int UtcDaliImageViewSyncLoading02(void)
692 {
693   ToolkitTestApplication application;
694
695   tet_infoline("ImageView Testing sync loading and size using string key property map");
696
697   // Sync loading, automatic atlasing for small size image
698   {
699     TraceCallStack& callStack = application.GetGlAbstraction().GetTextureTrace();
700     callStack.Reset();
701     callStack.Enable(true);
702
703     ImageView imageView = ImageView::New();
704
705     // Sync loading is used
706     Property::Map syncLoadingMap;
707     syncLoadingMap["url"]                = gImage_34_RGBA;
708     syncLoadingMap["desiredHeight"]      = 34;
709     syncLoadingMap["desiredWidth"]       = 34;
710     syncLoadingMap["synchronousLoading"] = true;
711     syncLoadingMap["atlasing"]           = true;
712     imageView.SetProperty(ImageView::Property::IMAGE, syncLoadingMap);
713
714     application.GetScene().Add(imageView);
715     application.SendNotification();
716     application.Render(16);
717
718     TraceCallStack::NamedParams params;
719     params["width"] << 34;
720     params["height"] << 34;
721     DALI_TEST_EQUALS(callStack.FindMethodAndParams("TexSubImage2D", params),
722                      true,
723                      TEST_LOCATION);
724   }
725   END_TEST;
726 }
727
728 int UtcDaliImageViewAsyncLoadingEncodedBuffer(void)
729 {
730   ToolkitTestApplication     application;
731   TestGlAbstraction&         gl          = application.GetGlAbstraction();
732   const std::vector<GLuint>& textures    = gl.GetBoundTextures();
733   size_t                     numTextures = textures.size();
734
735   // Get encoded raw-buffer image and generate url
736   EncodedImageBuffer buffer = ConvertFileToEncodedImageBuffer(gImage_600_RGB);
737   ImageUrl           url    = Toolkit::Image::GenerateUrl(buffer);
738
739   // Async loading, no atlasing for big size image
740   ImageView imageView = ImageView::New(url.GetUrl());
741
742   // By default, Aysnc loading is used
743   application.GetScene().Add(imageView);
744   imageView.SetProperty(Actor::Property::SIZE, Vector2(100, 100));
745   imageView.SetProperty(Actor::Property::PARENT_ORIGIN, ParentOrigin::CENTER);
746
747   DALI_TEST_EQUALS(Test::WaitForEventThreadTrigger(1), true, TEST_LOCATION);
748
749   application.SendNotification();
750   application.Render(16);
751   application.SendNotification();
752
753   const std::vector<GLuint>& textures2 = gl.GetBoundTextures();
754   DALI_TEST_GREATER(textures2.size(), numTextures, TEST_LOCATION);
755
756   END_TEST;
757 }
758
759 int UtcDaliImageViewAsyncLoadingEncodedBufferWithAtlasing(void)
760 {
761   ToolkitTestApplication application;
762
763   // Get encoded raw-buffer image and generate url
764   EncodedImageBuffer buffer = ConvertFileToEncodedImageBuffer(gImage_600_RGB);
765   ImageUrl           url    = Toolkit::Image::GenerateUrl(buffer);
766   ImageUrl           url2   = Toolkit::Image::GenerateUrl(buffer);
767
768   // Generate url is not equal to url2
769   // NOTE : This behavior may changed when ImageUrl compare operator changed.
770   DALI_TEST_CHECK(url != url2);
771   // Generate url's string is equal to url2's string
772   DALI_TEST_CHECK(url.GetUrl() == url2.GetUrl());
773
774   EncodedImageBuffer buffer2 = ConvertFileToEncodedImageBuffer(gImage_600_RGB);
775   url2                       = Toolkit::Image::GenerateUrl(buffer2);
776
777   // Check whethere two url are not equal
778   DALI_TEST_CHECK(url.GetUrl() != url2.GetUrl());
779
780   // Async loading, automatic atlasing for small size image
781   TraceCallStack& callStack = application.GetGlAbstraction().GetTextureTrace();
782   callStack.Reset();
783   callStack.Enable(true);
784
785   Property::Map imageMap;
786
787   imageMap[ImageVisual::Property::URL]            = url.GetUrl();
788   imageMap[ImageVisual::Property::DESIRED_HEIGHT] = 600;
789   imageMap[ImageVisual::Property::DESIRED_WIDTH]  = 600;
790   imageMap[ImageVisual::Property::ATLASING]       = true;
791
792   // No atlasing with big image
793   ImageView imageView_bigdesired = ImageView::New();
794   imageView_bigdesired.SetProperty(ImageView::Property::IMAGE, imageMap);
795   imageView_bigdesired.SetProperty(Toolkit::Control::Property::PADDING, Extents(10u, 10u, 10u, 10u));
796
797   imageMap[ImageVisual::Property::DESIRED_HEIGHT] = 0;
798   imageMap[ImageVisual::Property::DESIRED_WIDTH]  = 0;
799
800   // No atlasing with zero desired size
801   ImageView imageView_nodesired = ImageView::New();
802   imageView_nodesired.SetProperty(ImageView::Property::IMAGE, imageMap);
803   imageView_nodesired.SetProperty(Toolkit::Control::Property::PADDING, Extents(10u, 10u, 10u, 10u));
804
805   imageMap[ImageVisual::Property::DESIRED_HEIGHT] = 34;
806   imageMap[ImageVisual::Property::DESIRED_WIDTH]  = 34;
807
808   ImageView imageView = ImageView::New();
809   imageView.SetProperty(ImageView::Property::IMAGE, imageMap);
810   imageView.SetProperty(Toolkit::Control::Property::PADDING, Extents(10u, 10u, 10u, 10u));
811
812   // By default, Aysnc loading is used
813   // loading is not started if the actor is offScene
814   application.GetScene().Add(imageView);
815   application.GetScene().Add(imageView_bigdesired);
816   application.GetScene().Add(imageView_nodesired);
817   application.SendNotification();
818   application.Render(16);
819
820   // loading started, this waits for the loader thread for max 30 seconds
821   DALI_TEST_EQUALS(Test::WaitForEventThreadTrigger(1), true, TEST_LOCATION);
822
823   application.Render(16);
824   application.SendNotification();
825
826   // Change url to url2
827   imageMap[ImageVisual::Property::URL] = url2.GetUrl();
828   imageView.SetProperty(ImageView::Property::IMAGE, imageMap);
829
830   imageView.SetProperty(Dali::Actor::Property::LAYOUT_DIRECTION, Dali::LayoutDirection::RIGHT_TO_LEFT);
831   application.SendNotification();
832   application.Render(16);
833   application.Render(16);
834   application.SendNotification();
835
836   // loading started, this waits for the loader thread for max 30 seconds
837   DALI_TEST_EQUALS(Test::WaitForEventThreadTrigger(1), true, TEST_LOCATION);
838
839   application.SendNotification();
840   application.Render(16);
841
842   callStack.Enable(false);
843
844   TraceCallStack::NamedParams params;
845   params["width"] << 34;
846   params["height"] << 34;
847   DALI_TEST_EQUALS(callStack.FindMethodAndParams("TexSubImage2D", params), true, TEST_LOCATION);
848
849   END_TEST;
850 }
851
852 int UtcDaliImageViewSyncLoadingEncodedBuffer(void)
853 {
854   ToolkitTestApplication application;
855
856   tet_infoline("ImageView Testing sync loading from EncodedImageBuffer");
857
858   // Get encoded raw-buffer image and generate url
859   EncodedImageBuffer buffer = ConvertFileToEncodedImageBuffer(gImage_34_RGBA);
860   ImageUrl           url    = Toolkit::Image::GenerateUrl(buffer);
861
862   // Sync loading, automatic atlasing for small size image
863   {
864     TraceCallStack& callStack = application.GetGlAbstraction().GetTextureTrace();
865     callStack.Reset();
866     callStack.Enable(true);
867
868     ImageView imageView = ImageView::New();
869
870     // Sync loading is used
871     Property::Map syncLoadingMap;
872     syncLoadingMap["url"]                = url.GetUrl();
873     syncLoadingMap["alphaMaskUrl"]       = gImage_34_RGBA;
874     syncLoadingMap["desiredHeight"]      = 34;
875     syncLoadingMap["desiredWidth"]       = 34;
876     syncLoadingMap["synchronousLoading"] = true;
877     syncLoadingMap["atlasing"]           = true;
878     imageView.SetProperty(ImageView::Property::IMAGE, syncLoadingMap);
879
880     application.GetScene().Add(imageView);
881     application.SendNotification();
882     application.Render(16);
883
884     TraceCallStack::NamedParams params;
885     params["width"] << 34;
886     params["height"] << 34;
887     DALI_TEST_EQUALS(callStack.FindMethodAndParams("TexSubImage2D", params),
888                      true,
889                      TEST_LOCATION);
890   }
891
892   END_TEST;
893 }
894
895 int UtcDaliImageViewAddedTexture(void)
896 {
897   ToolkitTestApplication application;
898
899   tet_infoline("ImageView Testing image view with texture provided manager url");
900
901   ImageView imageView = ImageView::New();
902
903   // empty texture is ok, though pointless from app point of view
904   TextureSet  empty;
905   std::string url = TextureManager::AddTexture(empty);
906   DALI_TEST_CHECK(url.size() > 0u);
907
908   Property::Map propertyMap;
909   propertyMap[ImageVisual::Property::URL] = url;
910   imageView.SetProperty(ImageView::Property::IMAGE, propertyMap);
911
912   application.GetScene().Add(imageView);
913   application.SendNotification();
914   application.Render();
915
916   END_TEST;
917 }
918
919 int UtcDaliImageViewSizeWithBackground(void)
920 {
921   ToolkitTestApplication application;
922
923   int       width     = 100;
924   int       height    = 200;
925   ImageView imageView = ImageView::New();
926
927   imageView.SetProperty(Control::Property::BACKGROUND,
928                         {
929                           {Toolkit::Visual::Property::TYPE, Toolkit::Visual::IMAGE},
930                           {Toolkit::ImageVisual::Property::URL, TEST_RESOURCE_DIR "/gallery-small-1.jpg"},
931                           {ImageVisual::Property::DESIRED_WIDTH, width},
932                           {ImageVisual::Property::DESIRED_HEIGHT, height},
933                         });
934
935   application.GetScene().Add(imageView);
936   application.SendNotification();
937   application.Render();
938
939   DALI_TEST_EQUALS(imageView.GetCurrentProperty<Vector3>(Actor::Property::SIZE).width, (float)width, TEST_LOCATION);
940   DALI_TEST_EQUALS(imageView.GetCurrentProperty<Vector3>(Actor::Property::SIZE).height, (float)height, TEST_LOCATION);
941
942   END_TEST;
943 }
944
945 int UtcDaliImageViewSizeWithBackgroundAndImage(void)
946 {
947   ToolkitTestApplication application;
948
949   int widthBackground  = 100;
950   int heightBackground = 200;
951   int width            = 600;
952   int height           = 600;
953
954   ImageView imageView = ImageView::New();
955
956   imageView.SetProperty(Control::Property::BACKGROUND,
957                         {
958                           {Toolkit::Visual::Property::TYPE, Toolkit::Visual::IMAGE},
959                           {Toolkit::ImageVisual::Property::URL, TEST_RESOURCE_DIR "/gallery-small-1.jpg"},
960                           {ImageVisual::Property::DESIRED_WIDTH, widthBackground},
961                           {ImageVisual::Property::DESIRED_HEIGHT, heightBackground},
962                         });
963
964   imageView.SetImage(gImage_600_RGB); // 1 to 1 ratio, 600x600 pixels
965
966   application.GetScene().Add(imageView);
967   application.SendNotification();
968   application.Render();
969
970   DALI_TEST_EQUALS(imageView.GetCurrentProperty<Vector3>(Actor::Property::SIZE).width, (float)width, TEST_LOCATION);
971   DALI_TEST_EQUALS(imageView.GetCurrentProperty<Vector3>(Actor::Property::SIZE).height, (float)height, TEST_LOCATION);
972
973   END_TEST;
974 }
975
976 int UtcDaliImageViewHeightForWidthBackground(void)
977 {
978   ToolkitTestApplication application;
979
980   int widthBackground  = 100;
981   int heightBackground = 200;
982
983   ImageView imageView = ImageView::New();
984
985   imageView.SetProperty(Control::Property::BACKGROUND,
986                         {{Toolkit::Visual::Property::TYPE, Toolkit::Visual::IMAGE},
987                          {Toolkit::ImageVisual::Property::URL, TEST_RESOURCE_DIR "/gallery-small-1.jpg"},
988                          {ImageVisual::Property::DESIRED_WIDTH, widthBackground},
989                          {ImageVisual::Property::DESIRED_HEIGHT, heightBackground}});
990
991   application.GetScene().Add(imageView);
992   application.SendNotification();
993   application.Render();
994
995   Control control = Control::DownCast(imageView);
996   DALI_TEST_CHECK(control);
997   DALI_TEST_EQUALS(imageView.GetHeightForWidth(123.f), control.GetHeightForWidth(123.f), TEST_LOCATION);
998   DALI_TEST_EQUALS(imageView.GetWidthForHeight(321.f), control.GetWidthForHeight(321.f), TEST_LOCATION);
999
1000   END_TEST;
1001 }
1002
1003 int UtcDaliImageViewHeightForWidthBackgroundAndImage(void)
1004 {
1005   ToolkitTestApplication application;
1006
1007   int widthBackground  = 100;
1008   int heightBackground = 200;
1009   int width            = 300;
1010   int height           = 300;
1011
1012   ImageView imageView = ImageView::New();
1013
1014   imageView.SetProperty(Control::Property::BACKGROUND,
1015                         {{Toolkit::Visual::Property::TYPE, Toolkit::Visual::IMAGE},
1016                          {Toolkit::ImageVisual::Property::URL, TEST_RESOURCE_DIR "/gallery-small-1.jpg"},
1017                          {ImageVisual::Property::DESIRED_WIDTH, widthBackground},
1018                          {ImageVisual::Property::DESIRED_HEIGHT, heightBackground}}); // 1 to 2 ratio
1019
1020   imageView.SetImage(gImage_600_RGB); // 1 to 1 ratio
1021
1022   application.GetScene().Add(imageView);
1023   application.SendNotification();
1024   application.Render();
1025
1026   DALI_TEST_EQUALS(imageView.GetHeightForWidth(width), (float)height, TEST_LOCATION);
1027   DALI_TEST_EQUALS(imageView.GetWidthForHeight(height), (float)width, TEST_LOCATION);
1028
1029   END_TEST;
1030 }
1031
1032 int UtcDaliImageViewSetImageUrl(void)
1033 {
1034   ToolkitTestApplication application;
1035
1036   ImageView imageView = ImageView::New();
1037   imageView.SetImage(TEST_IMAGE_FILE_NAME);
1038   TestUrl(imageView, TEST_IMAGE_FILE_NAME);
1039
1040   imageView.SetImage(TEST_IMAGE_FILE_NAME2);
1041   TestUrl(imageView, TEST_IMAGE_FILE_NAME2);
1042
1043   END_TEST;
1044 }
1045
1046 bool    gResourceReadySignalFired = false;
1047 Vector3 gNaturalSize;
1048
1049 void ResourceReadySignal(Control control)
1050 {
1051   gResourceReadySignalFired = true;
1052 }
1053
1054 int UtcDaliImageViewCheckResourceReady(void)
1055 {
1056   ToolkitTestApplication application;
1057
1058   gResourceReadySignalFired = false;
1059
1060   // Check ImageView with background and main image, to ensure both visuals are marked as loaded
1061   ImageView imageView = ImageView::New(TEST_GIF_FILE_NAME);
1062
1063   imageView.SetProperty(Control::Property::BACKGROUND,
1064                         {{Toolkit::Visual::Property::TYPE, Toolkit::Visual::IMAGE},
1065                          {Toolkit::ImageVisual::Property::URL, TEST_RESOURCE_DIR "/gallery-small-1.jpg"},
1066                          {ImageVisual::Property::DESIRED_WIDTH, 100},
1067                          {ImageVisual::Property::DESIRED_HEIGHT, 200}});
1068
1069   DALI_TEST_EQUALS(imageView.IsResourceReady(), false, TEST_LOCATION);
1070
1071   imageView.ResourceReadySignal().Connect(&ResourceReadySignal);
1072
1073   application.GetScene().Add(imageView);
1074
1075   // loading started, this waits for the loader thread
1076   DALI_TEST_EQUALS(Test::WaitForEventThreadTrigger(1), true, TEST_LOCATION);
1077
1078   application.SendNotification();
1079   application.Render(16);
1080
1081   DALI_TEST_EQUALS(Test::WaitForEventThreadTrigger(2), true, TEST_LOCATION);
1082
1083   application.SendNotification();
1084   application.Render();
1085
1086   DALI_TEST_EQUALS(imageView.IsResourceReady(), true, TEST_LOCATION);
1087
1088   DALI_TEST_EQUALS(gResourceReadySignalFired, true, TEST_LOCATION);
1089
1090   END_TEST;
1091 }
1092
1093 int UtcDaliImageViewSetImageTypeChangesP(void)
1094 {
1095   ToolkitTestApplication application;
1096
1097   ImageView                   imageView   = ImageView::New();
1098   Toolkit::Internal::Control& controlImpl = Toolkit::Internal::GetImplementation(imageView);
1099
1100   application.GetScene().Add(imageView);
1101
1102   std::string           url;
1103   Property::Map         map;
1104   Toolkit::Visual::Base visual;
1105
1106   Property::Value value = imageView.GetProperty(imageView.GetPropertyIndex("image"));
1107   visual                = DevelControl::GetVisual(controlImpl, ImageView::Property::IMAGE);
1108
1109   application.SendNotification();
1110   application.Render(16);
1111
1112   DALI_TEST_CHECK(!value.Get(url)); // Value should be empty
1113   value.Get(map);
1114   DALI_TEST_CHECK(map.Empty()); // Value should be empty
1115   DALI_TEST_CHECK(!visual);     // Visual should be invalid
1116
1117   // Set a URL
1118   imageView.SetImage("TEST_URL");
1119
1120   application.SendNotification();
1121   application.Render(16);
1122
1123   value  = imageView.GetProperty(imageView.GetPropertyIndex("image"));
1124   visual = DevelControl::GetVisual(controlImpl, ImageView::Property::IMAGE);
1125
1126   DALI_TEST_CHECK(value.Get(url));  // Value should NOT be empty
1127   DALI_TEST_CHECK(!value.Get(map)); // Value should be empty
1128   DALI_TEST_CHECK(visual);          // Visual should be valid
1129
1130   // Set an empty URL
1131   imageView.SetImage("");
1132
1133   application.SendNotification();
1134   application.Render(16);
1135
1136   value  = imageView.GetProperty(imageView.GetPropertyIndex("image"));
1137   visual = DevelControl::GetVisual(controlImpl, ImageView::Property::IMAGE);
1138
1139   DALI_TEST_CHECK(!value.Get(url)); // Value should be empty
1140   value.Get(map);
1141   DALI_TEST_CHECK(map.Empty()); // Value should be empty
1142   DALI_TEST_CHECK(!visual);     // Visual should be invalid
1143
1144   // Set a URL in property map
1145   Property::Map propertyMap;
1146   propertyMap[ImageVisual::Property::URL] = TEST_IMAGE_FILE_NAME;
1147   imageView.SetProperty(ImageView::Property::IMAGE, propertyMap);
1148
1149   application.SendNotification();
1150   application.Render(16);
1151
1152   value  = imageView.GetProperty(imageView.GetPropertyIndex("image"));
1153   visual = DevelControl::GetVisual(controlImpl, ImageView::Property::IMAGE);
1154
1155   DALI_TEST_CHECK(!value.Get(url)); // Value should be empty
1156   DALI_TEST_CHECK(value.Get(map));  // Value should NOT be empty
1157   DALI_TEST_CHECK(visual);          // Visual should be valid
1158
1159   // Set a URL in property map again
1160   propertyMap[ImageVisual::Property::URL] = gImage_34_RGBA;
1161   imageView.SetProperty(ImageView::Property::IMAGE, propertyMap);
1162
1163   application.SendNotification();
1164   application.Render(16);
1165
1166   value  = imageView.GetProperty(imageView.GetPropertyIndex("image"));
1167   visual = DevelControl::GetVisual(controlImpl, ImageView::Property::IMAGE);
1168
1169   DALI_TEST_CHECK(!value.Get(url)); // Value should be empty
1170   DALI_TEST_CHECK(value.Get(map));  // Value should NOT be empty
1171   DALI_TEST_CHECK(visual);          // Visual should be valid
1172
1173   // Set an empty URL in property map
1174   propertyMap[ImageVisual::Property::URL] = std::string();
1175   imageView.SetProperty(ImageView::Property::IMAGE, propertyMap);
1176
1177   application.SendNotification();
1178   application.Render(16);
1179
1180   value  = imageView.GetProperty(imageView.GetPropertyIndex("image"));
1181   visual = DevelControl::GetVisual(controlImpl, ImageView::Property::IMAGE);
1182
1183   DALI_TEST_CHECK(!value.Get(url)); // Value should be empty
1184   DALI_TEST_CHECK(value.Get(map));  // Value should NOT be empty
1185   DALI_TEST_CHECK(!visual);         // Visual should be invalid
1186
1187   // Set a URL in property map again
1188   propertyMap[ImageVisual::Property::URL] = gImage_34_RGBA;
1189   imageView.SetProperty(ImageView::Property::IMAGE, propertyMap);
1190
1191   application.SendNotification();
1192   application.Render(16);
1193
1194   value  = imageView.GetProperty(imageView.GetPropertyIndex("image"));
1195   visual = DevelControl::GetVisual(controlImpl, ImageView::Property::IMAGE);
1196
1197   DALI_TEST_CHECK(!value.Get(url)); // Value should be empty
1198   DALI_TEST_CHECK(value.Get(map));  // Value should NOT be empty
1199   DALI_TEST_CHECK(visual);          // Visual should be valid
1200
1201   // Set an empty property map
1202   propertyMap.Clear();
1203   imageView.SetProperty(ImageView::Property::IMAGE, propertyMap);
1204
1205   application.SendNotification();
1206   application.Render(16);
1207
1208   value  = imageView.GetProperty(imageView.GetPropertyIndex("image"));
1209   visual = DevelControl::GetVisual(controlImpl, ImageView::Property::IMAGE);
1210
1211   DALI_TEST_CHECK(!value.Get(url)); // Value should be empty
1212   DALI_TEST_CHECK(value.Get(map));  // Value should NOT be empty
1213   DALI_TEST_CHECK(map.Empty());     // But PropertyMap should be empty
1214   DALI_TEST_CHECK(!visual);         // Visual should be invalid
1215
1216   END_TEST;
1217 }
1218
1219 int UtcDaliImageViewResourceUrlP(void)
1220 {
1221   ToolkitTestApplication application;
1222
1223   ImageView imageView = ImageView::New();
1224   DALI_TEST_CHECK(imageView.GetProperty(ImageView::Property::IMAGE).Get<std::string>().empty());
1225
1226   imageView.SetProperty(ImageView::Property::IMAGE, "TestString");
1227   DALI_TEST_EQUALS(imageView.GetProperty(ImageView::Property::IMAGE).Get<std::string>(), "TestString", TEST_LOCATION);
1228
1229   END_TEST;
1230 }
1231
1232 int UtcDaliImageViewReplaceImage(void)
1233 {
1234   ToolkitTestApplication application;
1235
1236   gResourceReadySignalFired = false;
1237
1238   // Check ImageView with background and main image, to ensure both visuals are marked as loaded
1239   ImageView imageView = ImageView::New(TEST_IMAGE_1);
1240
1241   DALI_TEST_EQUALS(imageView.IsResourceReady(), false, TEST_LOCATION);
1242
1243   imageView.ResourceReadySignal().Connect(&ResourceReadySignal);
1244
1245   application.GetScene().Add(imageView);
1246
1247   application.SendNotification();
1248   application.Render(16);
1249
1250   // loading started, this waits for the loader thread for max 30 seconds
1251   DALI_TEST_EQUALS(Test::WaitForEventThreadTrigger(1), true, TEST_LOCATION);
1252
1253   DALI_TEST_EQUALS(imageView.GetRendererCount(), 1u, TEST_LOCATION);
1254
1255   DALI_TEST_EQUALS(gResourceReadySignalFired, true, TEST_LOCATION);
1256
1257   gResourceReadySignalFired = false;
1258
1259   imageView.SetImage(TEST_IMAGE_2);
1260
1261   application.SendNotification();
1262   application.Render(16);
1263
1264   // loading started, this waits for the loader thread for max 30 seconds
1265   DALI_TEST_EQUALS(Test::WaitForEventThreadTrigger(1), true, TEST_LOCATION);
1266
1267   DALI_TEST_EQUALS(imageView.GetRendererCount(), 1u, TEST_LOCATION);
1268
1269   DALI_TEST_EQUALS(imageView.IsResourceReady(), true, TEST_LOCATION);
1270
1271   DALI_TEST_EQUALS(gResourceReadySignalFired, true, TEST_LOCATION);
1272
1273   END_TEST;
1274 }
1275
1276 void OnRelayoutOverride(Size size)
1277 {
1278   gNaturalSize = size; // Size Relayout is using
1279 }
1280
1281 int UtcDaliImageViewReplaceImageAndGetNaturalSize(void)
1282 {
1283   ToolkitTestApplication application;
1284
1285   // Check ImageView with background and main image, to ensure both visuals are marked as loaded
1286   ImageView imageView = ImageView::New(TEST_IMAGE_1);
1287   imageView.SetResizePolicy(ResizePolicy::USE_NATURAL_SIZE, Dimension::ALL_DIMENSIONS);
1288
1289   DummyControl        dummyControl = DummyControl::New(true);
1290   Impl::DummyControl& dummyImpl    = static_cast<Impl::DummyControl&>(dummyControl.GetImplementation());
1291   dummyControl.SetResizePolicy(ResizePolicy::FIT_TO_CHILDREN, Dimension::ALL_DIMENSIONS);
1292
1293   dummyControl.Add(imageView);
1294   dummyImpl.SetRelayoutCallback(&OnRelayoutOverride);
1295   application.GetScene().Add(dummyControl);
1296
1297   application.SendNotification();
1298   application.Render();
1299
1300   // loading started, this waits for the loader thread for max 30 seconds
1301   DALI_TEST_EQUALS(Test::WaitForEventThreadTrigger(1), true, TEST_LOCATION);
1302
1303   DALI_TEST_EQUALS(gNaturalSize.width, 1024.0f, TEST_LOCATION);
1304   DALI_TEST_EQUALS(gNaturalSize.height, 1024.0f, TEST_LOCATION);
1305
1306   gNaturalSize = Vector3::ZERO;
1307
1308   imageView.SetImage(gImage_600_RGB);
1309
1310   // Waiting for resourceReady so SendNotifcation not called here.
1311
1312   // loading started, this waits for the loader thread for max 30 seconds
1313   DALI_TEST_EQUALS(Test::WaitForEventThreadTrigger(1), true, TEST_LOCATION);
1314
1315   // Trigger a potential relayout
1316   application.SendNotification();
1317   application.Render();
1318
1319   DALI_TEST_EQUALS(gNaturalSize.width, 600.0f, TEST_LOCATION);
1320   DALI_TEST_EQUALS(gNaturalSize.height, 600.0f, TEST_LOCATION);
1321
1322   END_TEST;
1323 }
1324
1325 int UtcDaliImageViewResourceReadySignalWithImmediateLoad(void)
1326 {
1327   tet_infoline("Test Setting Image with IMMEDIATE load and receving ResourceReadySignal before staged.");
1328
1329   ToolkitTestApplication application;
1330
1331   gResourceReadySignalFired = false;
1332
1333   Property::Map imageMap;
1334
1335   imageMap[ImageVisual::Property::URL]         = gImage_34_RGBA;
1336   imageMap[ImageVisual::Property::LOAD_POLICY] = ImageVisual::LoadPolicy::IMMEDIATE;
1337
1338   tet_infoline("Creating ImageView without URL so image does not start loading");
1339   ImageView imageView = ImageView::New();
1340   tet_infoline("Connect to image loaded signal before setting image");
1341   imageView.ResourceReadySignal().Connect(&ResourceReadySignal);
1342   tet_infoline("Setting Image with IMMEDIATE load, signal already connected so will be triggered.");
1343   imageView.SetProperty(ImageView::Property::IMAGE, imageMap);
1344
1345   // loading started, this waits for the loader thread
1346   DALI_TEST_EQUALS(Test::WaitForEventThreadTrigger(1), true, TEST_LOCATION);
1347
1348   application.SendNotification();
1349   application.Render(16);
1350
1351   DALI_TEST_EQUALS(gResourceReadySignalFired, true, TEST_LOCATION);
1352
1353   END_TEST;
1354 }
1355
1356 int UtcDaliImageViewResourceReadySignalWithReusedImage(void)
1357 {
1358   tet_infoline("Test Setting Image that was already loaded by another ImageView and still getting ResourceReadySignal.");
1359
1360   ToolkitTestApplication application;
1361
1362   gResourceReadySignalFired = false;
1363
1364   Property::Map imageMap;
1365
1366   imageMap[ImageVisual::Property::URL]         = gImage_34_RGBA;
1367   imageMap[ImageVisual::Property::LOAD_POLICY] = ImageVisual::LoadPolicy::IMMEDIATE;
1368
1369   ImageView imageView = ImageView::New();
1370   imageView.ResourceReadySignal().Connect(&ResourceReadySignal);
1371   imageView.SetProperty(ImageView::Property::IMAGE, imageMap);
1372
1373   // loading started, this waits for the loader thread
1374   DALI_TEST_EQUALS(Test::WaitForEventThreadTrigger(1), true, TEST_LOCATION);
1375
1376   application.SendNotification();
1377   application.Render(16);
1378
1379   DALI_TEST_EQUALS(gResourceReadySignalFired, true, TEST_LOCATION);
1380   gResourceReadySignalFired = false;
1381
1382   ImageView imageViewWithExistingImage = ImageView::New();
1383   imageViewWithExistingImage.ResourceReadySignal().Connect(&ResourceReadySignal);
1384   imageViewWithExistingImage.SetProperty(ImageView::Property::IMAGE, imageMap);
1385
1386   DALI_TEST_EQUALS(gResourceReadySignalFired, true, TEST_LOCATION);
1387
1388   END_TEST;
1389 }
1390
1391 int UtcDaliImageViewResourceReadySignalWithReusedImage02(void)
1392 {
1393   tet_infoline("Test Setting Image that was already loaded by another ImageView and still getting ResourceReadySignal when staged.");
1394
1395   ToolkitTestApplication application;
1396
1397   gResourceReadySignalFired = false;
1398
1399   Property::Map imageImmediateLoadingMap;
1400   imageImmediateLoadingMap[ImageVisual::Property::URL]         = gImage_34_RGBA;
1401   imageImmediateLoadingMap[ImageVisual::Property::LOAD_POLICY] = ImageVisual::LoadPolicy::IMMEDIATE;
1402
1403   tet_infoline("Immediate load an image");
1404   ImageView imageView = ImageView::New();
1405   imageView.ResourceReadySignal().Connect(&ResourceReadySignal);
1406   imageView.SetProperty(ImageView::Property::IMAGE, imageImmediateLoadingMap);
1407
1408   // loading started, this waits for the loader thread
1409   DALI_TEST_EQUALS(Test::WaitForEventThreadTrigger(1), true, TEST_LOCATION);
1410
1411   application.SendNotification();
1412   application.Render(16);
1413
1414   tet_infoline("Check image loaded");
1415   DALI_TEST_EQUALS(gResourceReadySignalFired, true, TEST_LOCATION);
1416   gResourceReadySignalFired = false;
1417
1418   tet_infoline("Create another ImageView with the same URL");
1419   ImageView imageViewWithExistingImage = ImageView::New(gImage_34_RGBA);
1420   tet_infoline("Connect to ResourceReady signal for second ImageView, it should still fire as resource is ready");
1421   imageViewWithExistingImage.ResourceReadySignal().Connect(&ResourceReadySignal);
1422
1423   application.GetScene().Add(imageViewWithExistingImage);
1424
1425   DALI_TEST_EQUALS(gResourceReadySignalFired, true, TEST_LOCATION);
1426
1427   END_TEST;
1428 }
1429
1430 int UtcDaliImageViewPaddingProperty(void)
1431 {
1432   ToolkitTestApplication application;
1433
1434   ImageView     imageView = ImageView::New();
1435   Property::Map imagePropertyMap;
1436   imagePropertyMap[Toolkit::Visual::Property::TYPE]       = Toolkit::Visual::IMAGE;
1437   imagePropertyMap[Toolkit::ImageVisual::Property::URL]   = TEST_RESOURCE_DIR "/gallery-small-1.jpg";
1438   imagePropertyMap[ImageVisual::Property::DESIRED_WIDTH]  = 128;
1439   imagePropertyMap[ImageVisual::Property::DESIRED_HEIGHT] = 128;
1440   imageView.SetProperty(Toolkit::ImageView::Property::IMAGE, imagePropertyMap);
1441   imageView.SetProperty(Actor::Property::ANCHOR_POINT, AnchorPoint::TOP_LEFT);
1442   imageView.SetProperty(Actor::Property::PARENT_ORIGIN, ParentOrigin::TOP_LEFT);
1443   imageView.SetProperty(Control::Property::PADDING, Extents(15, 10, 5, 10));
1444   application.GetScene().Add(imageView);
1445
1446   application.SendNotification();
1447   application.Render();
1448
1449   DALI_TEST_EQUALS(imageView.GetProperty<Extents>(Control::Property::PADDING), Extents(15, 10, 5, 10), TEST_LOCATION);
1450
1451   ImageView childImage = ImageView::New();
1452   childImage.SetBackgroundColor(Color::BLACK);
1453   childImage.SetProperty(Actor::Property::SIZE, Vector2(10.f, 10.f));
1454   imageView.Add(childImage);
1455
1456   application.SendNotification();
1457   application.Render();
1458
1459   // Child ImageView should be positioned dependinig on Parent ImageView's Padding value
1460   DALI_TEST_EQUALS(childImage.GetProperty<Vector3>(Dali::Actor::Property::POSITION), Vector3(15, 5, 0), TEST_LOCATION);
1461
1462   // Check whether Image Visual transforms on ImageVieiw::OnRelayout()
1463   Toolkit::Internal::Control& controlImpl = Toolkit::Internal::GetImplementation(imageView);
1464   Toolkit::Visual::Base       imageVisual = DevelControl::GetVisual(controlImpl, ImageView::Property::IMAGE);
1465   Property::Map               resultMap;
1466   imageVisual.CreatePropertyMap(resultMap);
1467
1468   Property::Value* transformValue = resultMap.Find(Visual::Property::TRANSFORM);
1469   DALI_TEST_CHECK(transformValue);
1470   Property::Map* retMap = transformValue->GetMap();
1471   DALI_TEST_CHECK(retMap);
1472
1473   // Image Visual should be positioned depending on ImageView's padding
1474   DALI_TEST_EQUALS(retMap->Find(Visual::Transform::Property::OFFSET)->Get<Vector2>(), Vector2(15, 5), TEST_LOCATION);
1475
1476   END_TEST;
1477 }
1478
1479 int UtcDaliImageViewPaddingProperty02(void)
1480 {
1481   ToolkitTestApplication application;
1482
1483   ImageView     imageView = ImageView::New();
1484   Property::Map imagePropertyMap;
1485   imagePropertyMap[Toolkit::Visual::Property::TYPE]            = Toolkit::Visual::IMAGE;
1486   imagePropertyMap[Toolkit::ImageVisual::Property::URL]        = TEST_RESOURCE_DIR "/Kid1.svg";
1487   imagePropertyMap[ImageVisual::Property::DESIRED_WIDTH]       = 128;
1488   imagePropertyMap[ImageVisual::Property::DESIRED_HEIGHT]      = 128;
1489   imagePropertyMap[DevelVisual::Property::VISUAL_FITTING_MODE] = Toolkit::DevelVisual::FIT_KEEP_ASPECT_RATIO;
1490   imageView.SetProperty(Toolkit::ImageView::Property::IMAGE, imagePropertyMap);
1491   imageView.SetProperty(Actor::Property::ANCHOR_POINT, AnchorPoint::TOP_LEFT);
1492   imageView.SetProperty(Actor::Property::PARENT_ORIGIN, ParentOrigin::TOP_LEFT);
1493   imageView.SetProperty(Control::Property::PADDING, Extents(15, 10, 5, 10));
1494   application.GetScene().Add(imageView);
1495
1496   application.SendNotification();
1497   application.Render();
1498
1499   DALI_TEST_EQUALS(imageView.GetProperty<Extents>(Control::Property::PADDING), Extents(15, 10, 5, 10), TEST_LOCATION);
1500
1501   // Check whether Image Visual transforms on ImageVieiw::OnRelayout()
1502   Toolkit::Internal::Control& controlImpl = Toolkit::Internal::GetImplementation(imageView);
1503   Toolkit::Visual::Base       imageVisual = DevelControl::GetVisual(controlImpl, ImageView::Property::IMAGE);
1504   Property::Map               resultMap;
1505   imageVisual.CreatePropertyMap(resultMap);
1506
1507   Property::Value* transformValue = resultMap.Find(Visual::Property::TRANSFORM);
1508   DALI_TEST_CHECK(transformValue);
1509   Property::Map* retMap = transformValue->GetMap();
1510   DALI_TEST_CHECK(retMap);
1511
1512   // Image Visual should be positioned depending on ImageView's padding
1513   DALI_TEST_EQUALS(retMap->Find(Visual::Transform::Property::OFFSET)->Get<Vector2>(), Vector2(15, 5), TEST_LOCATION);
1514
1515   END_TEST;
1516 }
1517
1518 int UtcDaliImageViewPaddingProperty03(void)
1519 {
1520   tet_infoline("Test Setting Image Padding then removing it.");
1521
1522   ToolkitTestApplication application;
1523
1524   ImageView     imageView = ImageView::New();
1525   Property::Map imagePropertyMap;
1526   imagePropertyMap[Toolkit::Visual::Property::TYPE]            = Toolkit::Visual::IMAGE;
1527   imagePropertyMap[Toolkit::ImageVisual::Property::URL]        = TEST_RESOURCE_DIR "/Kid1.svg";
1528   imagePropertyMap[ImageVisual::Property::DESIRED_WIDTH]       = 128;
1529   imagePropertyMap[ImageVisual::Property::DESIRED_HEIGHT]      = 128;
1530   imagePropertyMap[DevelVisual::Property::VISUAL_FITTING_MODE] = Toolkit::DevelVisual::FIT_KEEP_ASPECT_RATIO;
1531   imageView.SetProperty(Toolkit::ImageView::Property::IMAGE, imagePropertyMap);
1532   imageView.SetProperty(Actor::Property::ANCHOR_POINT, AnchorPoint::TOP_LEFT);
1533   imageView.SetProperty(Actor::Property::PARENT_ORIGIN, ParentOrigin::TOP_LEFT);
1534   imageView.SetProperty(Control::Property::PADDING, Extents(15, 10, 5, 10));
1535   application.GetScene().Add(imageView);
1536
1537   application.SendNotification();
1538   application.Render();
1539
1540   DALI_TEST_EQUALS(imageView.GetProperty<Extents>(Control::Property::PADDING), Extents(15, 10, 5, 10), TEST_LOCATION);
1541
1542   tet_infoline("Remove Padding and test Visual is position correctly");
1543
1544   imageView.SetProperty(Control::Property::PADDING, Extents(0, 0, 0, 0));
1545
1546   application.SendNotification();
1547   application.Render();
1548
1549   // Check whether Image Visual transforms on ImageVieiw::OnRelayout()
1550   Toolkit::Internal::Control& controlImpl = Toolkit::Internal::GetImplementation(imageView);
1551   Toolkit::Visual::Base       imageVisual = DevelControl::GetVisual(controlImpl, ImageView::Property::IMAGE);
1552   Property::Map               resultMap;
1553   imageVisual.CreatePropertyMap(resultMap);
1554
1555   Property::Value* transformValue = resultMap.Find(Visual::Property::TRANSFORM);
1556   DALI_TEST_CHECK(transformValue);
1557   Property::Map* retMap = transformValue->GetMap();
1558   DALI_TEST_CHECK(retMap);
1559
1560   // Image Visual should be positioned depending on ImageView's padding
1561   DALI_TEST_EQUALS(retMap->Find(Visual::Transform::Property::OFFSET)->Get<Vector2>(), Vector2(0, 0), TEST_LOCATION);
1562
1563   END_TEST;
1564 }
1565
1566 int UtcDaliImageViewPaddingProperty04(void)
1567 {
1568   tet_infoline("Test Setting Image Padding then removing it. Visual Fitting Mode as Fill");
1569
1570   ToolkitTestApplication application;
1571
1572   ImageView     imageView = ImageView::New();
1573   Property::Map imagePropertyMap;
1574   imagePropertyMap[Toolkit::Visual::Property::TYPE]            = Toolkit::Visual::IMAGE;
1575   imagePropertyMap[Toolkit::ImageVisual::Property::URL]        = TEST_RESOURCE_DIR "/Kid1.svg";
1576   imagePropertyMap[ImageVisual::Property::DESIRED_WIDTH]       = 128;
1577   imagePropertyMap[ImageVisual::Property::DESIRED_HEIGHT]      = 128;
1578   imagePropertyMap[DevelVisual::Property::VISUAL_FITTING_MODE] = Toolkit::DevelVisual::FILL;
1579   imageView.SetProperty(Toolkit::ImageView::Property::IMAGE, imagePropertyMap);
1580   imageView.SetProperty(Actor::Property::ANCHOR_POINT, AnchorPoint::TOP_LEFT);
1581   imageView.SetProperty(Actor::Property::PARENT_ORIGIN, ParentOrigin::TOP_LEFT);
1582   imageView.SetProperty(Control::Property::PADDING, Extents(15, 10, 5, 10));
1583   application.GetScene().Add(imageView);
1584
1585   application.SendNotification();
1586   application.Render();
1587
1588   DALI_TEST_EQUALS(imageView.GetProperty<Extents>(Control::Property::PADDING), Extents(15, 10, 5, 10), TEST_LOCATION);
1589
1590   tet_infoline("Remove Padding and test Visual is position correctly");
1591
1592   imageView.SetProperty(Control::Property::PADDING, Extents(0, 0, 0, 0));
1593
1594   application.SendNotification();
1595   application.Render();
1596
1597   // Check whether Image Visual transforms on ImageVieiw::OnRelayout()
1598   Toolkit::Internal::Control& controlImpl = Toolkit::Internal::GetImplementation(imageView);
1599   Toolkit::Visual::Base       imageVisual = DevelControl::GetVisual(controlImpl, ImageView::Property::IMAGE);
1600   Property::Map               resultMap;
1601   imageVisual.CreatePropertyMap(resultMap);
1602
1603   Property::Value* transformValue = resultMap.Find(Visual::Property::TRANSFORM);
1604   DALI_TEST_CHECK(transformValue);
1605   Property::Map* retMap = transformValue->GetMap();
1606   DALI_TEST_CHECK(retMap);
1607
1608   // Image Visual should be positioned depending on ImageView's padding
1609   DALI_TEST_EQUALS(retMap->Find(Visual::Transform::Property::OFFSET)->Get<Vector2>(), Vector2(0, 0), TEST_LOCATION);
1610
1611   END_TEST;
1612 }
1613
1614 int UtcDaliImageViewTransformTest01(void)
1615 {
1616   tet_infoline("Test Setting a offset transform on the ImageView");
1617
1618   ToolkitTestApplication application;
1619
1620   ImageView     imageView = ImageView::New();
1621   Property::Map imagePropertyMap;
1622   imagePropertyMap.Add(Toolkit::Visual::Property::TYPE, Toolkit::Visual::IMAGE)
1623     .Add(Toolkit::ImageVisual::Property::URL, TEST_RESOURCE_DIR "/Kid1.svg")
1624     .Add(ImageVisual::Property::DESIRED_WIDTH, 120)
1625     .Add(ImageVisual::Property::DESIRED_HEIGHT, 120)
1626     .Add(DevelVisual::Property::VISUAL_FITTING_MODE, Toolkit::DevelVisual::FILL)
1627     .Add(Visual::Property::TRANSFORM,
1628          Property::Map().Add(Toolkit::Visual::Transform::Property::OFFSET_POLICY,
1629                              Vector2(Visual::Transform::Policy::ABSOLUTE, Visual::Transform::Policy::ABSOLUTE))
1630            .Add(Toolkit::Visual::Transform::Property::OFFSET, Vector2(8, 8)));
1631
1632   imageView.SetProperty(Toolkit::ImageView::Property::IMAGE, imagePropertyMap);
1633   imageView.SetProperty(Actor::Property::ANCHOR_POINT, AnchorPoint::TOP_LEFT);
1634   imageView.SetProperty(Actor::Property::PARENT_ORIGIN, ParentOrigin::TOP_LEFT);
1635   application.GetScene().Add(imageView);
1636
1637   application.SendNotification();
1638   application.Render();
1639
1640   // Check whether Image Visual transforms on ImageVieiw::OnRelayout()
1641   Toolkit::Internal::Control& controlImpl = Toolkit::Internal::GetImplementation(imageView);
1642   Toolkit::Visual::Base       imageVisual = DevelControl::GetVisual(controlImpl, ImageView::Property::IMAGE);
1643   Property::Map               resultMap;
1644   imageVisual.CreatePropertyMap(resultMap);
1645
1646   Property::Value* transformValue = resultMap.Find(Visual::Property::TRANSFORM);
1647   DALI_TEST_CHECK(transformValue);
1648   Property::Map* retMap = transformValue->GetMap();
1649   DALI_TEST_CHECK(retMap);
1650
1651   // Image Visual should be positioned depending on ImageView's padding
1652   DALI_TEST_EQUALS(retMap->Find(Visual::Transform::Property::OFFSET)->Get<Vector2>(), Vector2(8, 8), TEST_LOCATION);
1653   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);
1654
1655   END_TEST;
1656 }
1657
1658 int UtcDaliImageViewUsingAtlasAndGetNaturalSize(void)
1659 {
1660   ToolkitTestApplication application;
1661
1662   // Check ImageView with background and main image, to ensure both visuals are marked as loaded
1663   ImageView     imageView = ImageView::New();
1664   Property::Map imageMap;
1665   imageMap[Toolkit::Visual::Property::TYPE]          = Toolkit::Visual::IMAGE;
1666   imageMap[Toolkit::ImageVisual::Property::URL]      = gImage_34_RGBA;
1667   imageMap[Toolkit::ImageVisual::Property::ATLASING] = true;
1668   imageView.SetProperty(Toolkit::ImageView::Property::IMAGE, imageMap);
1669   application.GetScene().Add(imageView);
1670
1671   // Trigger a potential relayout
1672   application.SendNotification();
1673   application.Render();
1674
1675   Vector3 naturalSize = imageView.GetNaturalSize();
1676
1677   DALI_TEST_EQUALS(naturalSize.width, 34.0f, TEST_LOCATION);
1678   DALI_TEST_EQUALS(naturalSize.height, 34.0f, TEST_LOCATION);
1679
1680   END_TEST;
1681 }
1682
1683 int UtcDaliImageViewFillMode(void)
1684 {
1685   ToolkitTestApplication application;
1686
1687   tet_infoline("Create an ImageVisual without padding and set the fill-mode to fill");
1688
1689   ImageView     imageView = ImageView::New();
1690   Property::Map imageMap;
1691   imageMap.Add(Toolkit::Visual::Property::TYPE, Toolkit::Visual::IMAGE);
1692   imageMap.Add(Toolkit::ImageVisual::Property::URL, gImage_600_RGB);
1693   imageMap.Add(DevelVisual::Property::VISUAL_FITTING_MODE, DevelVisual::FittingMode::FILL);
1694
1695   imageView.SetProperty(Toolkit::ImageView::Property::IMAGE, imageMap);
1696
1697   application.GetScene().Add(imageView);
1698
1699   // Trigger a potential relayout
1700   application.SendNotification();
1701   application.Render();
1702
1703   Toolkit::Visual::Base visual = DevelControl::GetVisual(Toolkit::Internal::GetImplementation(imageView), Toolkit::ImageView::Property::IMAGE);
1704   Property::Map         returnedMap;
1705   visual.CreatePropertyMap(returnedMap);
1706
1707   Property::Value* value = returnedMap.Find(Toolkit::Visual::Property::TRANSFORM);
1708   DALI_TEST_CHECK(value);
1709   Property::Map* map = value->GetMap();
1710   DALI_TEST_CHECK(map);
1711
1712   value = map->Find(Toolkit::Visual::Transform::Property::SIZE);
1713   DALI_TEST_CHECK(value);
1714   DALI_TEST_EQUALS(value->Get<Vector2>(), Vector2::ONE, TEST_LOCATION);
1715
1716   value = map->Find(Toolkit::Visual::Transform::Property::SIZE_POLICY);
1717   DALI_TEST_CHECK(value);
1718   DALI_TEST_CHECK(value->Get<int>() == Toolkit::Visual::Transform::Policy::RELATIVE);
1719
1720   END_TEST;
1721 }
1722
1723 int UtcDaliImageViewFittingModeFitKeepAspectRatio(void)
1724 {
1725   ToolkitTestApplication application;
1726
1727   tet_infoline("Create an ImageVisual using FitKeepAspectRatio ( image: [600,600], view: [600,700] )");
1728   tet_infoline("  There should be need to change the transform, offset is adjusted to fit inside");
1729
1730   ImageView     imageView = ImageView::New();
1731   Property::Map imageMap;
1732   imageMap.Add(Toolkit::Visual::Property::TYPE, Toolkit::Visual::IMAGE);
1733   imageMap.Add(Toolkit::ImageVisual::Property::URL, gImage_600_RGB); // 600x600 image
1734   imageMap.Add(DevelVisual::Property::VISUAL_FITTING_MODE, Toolkit::DevelVisual::FIT_KEEP_ASPECT_RATIO);
1735
1736   imageView.SetProperty(Toolkit::ImageView::Property::IMAGE, imageMap);
1737   imageView.SetProperty(Actor::Property::SIZE, Vector2(600, 700));
1738
1739   application.GetScene().Add(imageView);
1740
1741   // Trigger a potential relayout
1742   application.SendNotification();
1743   application.Render();
1744
1745   Toolkit::Visual::Base visual = DevelControl::GetVisual(Toolkit::Internal::GetImplementation(imageView), Toolkit::ImageView::Property::IMAGE);
1746   Property::Map         returnedMap;
1747   visual.CreatePropertyMap(returnedMap);
1748
1749   Property::Value* value = returnedMap.Find(Toolkit::Visual::Property::TRANSFORM);
1750   DALI_TEST_CHECK(value);
1751   Property::Map* map = value->GetMap();
1752   DALI_TEST_CHECK(map);
1753
1754   // If there's
1755   value = map->Find(Toolkit::Visual::Transform::Property::SIZE);
1756   DALI_TEST_CHECK(value);
1757   DALI_TEST_EQUALS(value->Get<Vector2>(), Vector2(600, 600), TEST_LOCATION);
1758
1759   value = map->Find(Toolkit::Visual::Transform::Property::SIZE_POLICY);
1760   DALI_TEST_CHECK(value);
1761   DALI_TEST_EQUALS(value->Get<Vector2>(), Vector2(Toolkit::Visual::Transform::Policy::ABSOLUTE, Toolkit::Visual::Transform::Policy::ABSOLUTE), TEST_LOCATION);
1762
1763   value = map->Find(Toolkit::Visual::Transform::Property::OFFSET);
1764   DALI_TEST_CHECK(value);
1765   DALI_TEST_EQUALS(value->Get<Vector2>(), Vector2(0, 50), TEST_LOCATION);
1766
1767   END_TEST;
1768 }
1769
1770 int UtcDaliImageViewFittingModesFill(void)
1771 {
1772   ToolkitTestApplication application;
1773
1774   tet_infoline("Create an ImageVisual using Fill ( image: [600,600], view: [600,700] )");
1775   tet_infoline("  There should be no need to change the transform, only size is changed to fit view");
1776
1777   ImageView     imageView = ImageView::New();
1778   Property::Map imageMap;
1779   imageMap.Add(Toolkit::Visual::Property::TYPE, Toolkit::Visual::IMAGE);
1780   imageMap.Add(Toolkit::ImageVisual::Property::URL, gImage_600_RGB); // 600x600 image
1781   imageMap.Add(DevelVisual::Property::VISUAL_FITTING_MODE, Toolkit::DevelVisual::FILL);
1782
1783   imageView.SetProperty(Toolkit::ImageView::Property::IMAGE, imageMap);
1784   imageView.SetProperty(Actor::Property::SIZE, Vector2(600, 700));
1785
1786   application.GetScene().Add(imageView);
1787
1788   // Trigger a potential relayout
1789   application.SendNotification();
1790   application.Render();
1791
1792   Toolkit::Visual::Base visual = DevelControl::GetVisual(Toolkit::Internal::GetImplementation(imageView), Toolkit::ImageView::Property::IMAGE);
1793   Property::Map         returnedMap;
1794   visual.CreatePropertyMap(returnedMap);
1795
1796   Property::Value* value = returnedMap.Find(Toolkit::Visual::Property::TRANSFORM);
1797   DALI_TEST_CHECK(value);
1798   Property::Map* map = value->GetMap();
1799   DALI_TEST_CHECK(map);
1800
1801   value = map->Find(Toolkit::Visual::Transform::Property::SIZE);
1802   DALI_TEST_CHECK(value);
1803   DALI_TEST_EQUALS(value->Get<Vector2>(), Vector2::ONE, TEST_LOCATION); // Change the internal size according to the image view size
1804
1805   value = map->Find(Toolkit::Visual::Transform::Property::SIZE_POLICY);
1806   DALI_TEST_CHECK(value);
1807   DALI_TEST_CHECK(value->Get<int>() == Toolkit::Visual::Transform::Policy::RELATIVE);
1808
1809   value = map->Find(Toolkit::Visual::Transform::Property::OFFSET);
1810   DALI_TEST_CHECK(value);
1811   DALI_TEST_EQUALS(value->Get<Vector2>(), Vector2(0, 0), TEST_LOCATION); // OFFSET is zero
1812
1813   END_TEST;
1814 }
1815
1816 int UtcDaliImageViewFittingModesOverfitKeepAspectRatio(void)
1817 {
1818   ToolkitTestApplication application;
1819
1820   tet_infoline("Create an ImageVisual using OverFitKeepAspectRatio ( image: [600,600], view: [600,500] )");
1821   tet_infoline("  offset or size is the same as view, but adjust internally using pixelArea ");
1822
1823   ImageView     imageView = ImageView::New();
1824   Property::Map imageMap;
1825   imageMap.Add(Toolkit::Visual::Property::TYPE, Toolkit::Visual::IMAGE);
1826   imageMap.Add(Toolkit::ImageVisual::Property::URL, gImage_600_RGB); // 600x600 image
1827   imageMap.Add(DevelVisual::Property::VISUAL_FITTING_MODE, Toolkit::DevelVisual::OVER_FIT_KEEP_ASPECT_RATIO);
1828
1829   imageView.SetProperty(Toolkit::ImageView::Property::IMAGE, imageMap);
1830   imageView.SetProperty(Actor::Property::SIZE, Vector2(600, 500));
1831
1832   application.GetScene().Add(imageView);
1833
1834   // Trigger a potential relayout
1835   application.SendNotification();
1836   application.Render();
1837
1838   Toolkit::Visual::Base visual = DevelControl::GetVisual(Toolkit::Internal::GetImplementation(imageView), Toolkit::ImageView::Property::IMAGE);
1839   Property::Map         returnedMap;
1840   visual.CreatePropertyMap(returnedMap);
1841
1842   Property::Value* value = returnedMap.Find(Toolkit::Visual::Property::TRANSFORM);
1843   DALI_TEST_CHECK(value);
1844   Property::Map* map = value->GetMap();
1845   DALI_TEST_CHECK(map);
1846
1847   // If there's
1848   value = map->Find(Toolkit::Visual::Transform::Property::SIZE);
1849   DALI_TEST_CHECK(value);
1850   DALI_TEST_EQUALS(value->Get<Vector2>(), Vector2(600, 500), TEST_LOCATION); // Change the internal size according to the image view size
1851
1852   value = map->Find(Toolkit::Visual::Transform::Property::SIZE_POLICY);
1853   DALI_TEST_CHECK(value);
1854   DALI_TEST_EQUALS(value->Get<Vector2>(), Vector2(Toolkit::Visual::Transform::Policy::ABSOLUTE, Toolkit::Visual::Transform::Policy::ABSOLUTE), TEST_LOCATION);
1855
1856   value = map->Find(Toolkit::Visual::Transform::Property::OFFSET);
1857   DALI_TEST_CHECK(value);
1858   DALI_TEST_EQUALS(value->Get<Vector2>(), Vector2(0, 0), TEST_LOCATION); // OFFSET is zero
1859
1860   END_TEST;
1861 }
1862
1863 int UtcDaliImageViewFittingModesCenter01(void)
1864 {
1865   ToolkitTestApplication application;
1866
1867   tet_infoline("Create an ImageVisual using Center ( image: [600,600], view: [700,700] )");
1868   tet_infoline("  There should be need to change the transform, offset is adjusted to fit inside");
1869
1870   ImageView     imageView = ImageView::New();
1871   Property::Map imageMap;
1872   imageMap.Add(Toolkit::Visual::Property::TYPE, Toolkit::Visual::IMAGE);
1873   imageMap.Add(Toolkit::ImageVisual::Property::URL, gImage_600_RGB); // 600x600 image
1874   imageMap.Add(DevelVisual::Property::VISUAL_FITTING_MODE, Toolkit::DevelVisual::CENTER);
1875
1876   imageView.SetProperty(Toolkit::ImageView::Property::IMAGE, imageMap);
1877   imageView.SetProperty(Actor::Property::SIZE, Vector2(700, 700));
1878
1879   application.GetScene().Add(imageView);
1880
1881   // Trigger a potential relayout
1882   application.SendNotification();
1883   application.Render();
1884
1885   Toolkit::Visual::Base visual = DevelControl::GetVisual(Toolkit::Internal::GetImplementation(imageView), Toolkit::ImageView::Property::IMAGE);
1886   Property::Map         returnedMap;
1887   visual.CreatePropertyMap(returnedMap);
1888
1889   Property::Value* value = returnedMap.Find(Toolkit::Visual::Property::TRANSFORM);
1890   DALI_TEST_CHECK(value);
1891   Property::Map* map = value->GetMap();
1892   DALI_TEST_CHECK(map);
1893
1894   value = map->Find(Toolkit::Visual::Transform::Property::SIZE);
1895   DALI_TEST_CHECK(value);
1896   DALI_TEST_EQUALS(value->Get<Vector2>(), Vector2(600, 600), TEST_LOCATION); // Change the internal size according to the image view size
1897
1898   value = map->Find(Toolkit::Visual::Transform::Property::SIZE_POLICY);
1899   DALI_TEST_CHECK(value);
1900   DALI_TEST_EQUALS(value->Get<Vector2>(), Vector2(Toolkit::Visual::Transform::Policy::ABSOLUTE, Toolkit::Visual::Transform::Policy::ABSOLUTE), TEST_LOCATION);
1901
1902   value = map->Find(Toolkit::Visual::Transform::Property::OFFSET);
1903   DALI_TEST_CHECK(value);
1904   DALI_TEST_EQUALS(value->Get<Vector2>(), Vector2(50, 50), TEST_LOCATION);
1905
1906   END_TEST;
1907 }
1908
1909 int UtcDaliImageViewFittingModesCenter02(void)
1910 {
1911   ToolkitTestApplication application;
1912
1913   tet_infoline("Create an ImageVisual using Center ( image: [600,600], view: [500,500] )");
1914   tet_infoline("  There should be need to change the transform, offset is adjusted to fit inside");
1915
1916   ImageView     imageView = ImageView::New();
1917   Property::Map imageMap;
1918   imageMap.Add(Toolkit::Visual::Property::TYPE, Toolkit::Visual::IMAGE);
1919   imageMap.Add(Toolkit::ImageVisual::Property::URL, gImage_600_RGB); // 600x600 image
1920   imageMap.Add(DevelVisual::Property::VISUAL_FITTING_MODE, Toolkit::DevelVisual::CENTER);
1921
1922   imageView.SetProperty(Toolkit::ImageView::Property::IMAGE, imageMap);
1923   imageView.SetProperty(Actor::Property::SIZE, Vector2(700, 700));
1924
1925   application.GetScene().Add(imageView);
1926
1927   // Trigger a potential relayout
1928   application.SendNotification();
1929   application.Render();
1930
1931   Toolkit::Visual::Base visual = DevelControl::GetVisual(Toolkit::Internal::GetImplementation(imageView), Toolkit::ImageView::Property::IMAGE);
1932   Property::Map         returnedMap;
1933   visual.CreatePropertyMap(returnedMap);
1934
1935   Property::Value* value = returnedMap.Find(Toolkit::Visual::Property::TRANSFORM);
1936   DALI_TEST_CHECK(value);
1937   Property::Map* map = value->GetMap();
1938   DALI_TEST_CHECK(map);
1939
1940   value = map->Find(Toolkit::Visual::Transform::Property::SIZE);
1941   DALI_TEST_CHECK(value);
1942   DALI_TEST_EQUALS(value->Get<Vector2>(), Vector2(600, 600), TEST_LOCATION); // Change the internal size according to the image view size
1943
1944   value = map->Find(Toolkit::Visual::Transform::Property::SIZE_POLICY);
1945   DALI_TEST_CHECK(value);
1946   DALI_TEST_EQUALS(value->Get<Vector2>(), Vector2(Toolkit::Visual::Transform::Policy::ABSOLUTE, Toolkit::Visual::Transform::Policy::ABSOLUTE), TEST_LOCATION);
1947
1948   value = map->Find(Toolkit::Visual::Transform::Property::OFFSET);
1949   DALI_TEST_CHECK(value);
1950   DALI_TEST_EQUALS(value->Get<Vector2>(), Vector2(50, 50), TEST_LOCATION);
1951
1952   END_TEST;
1953 }
1954
1955 int UtcDaliImageViewFittingModesFitHeight01(void)
1956 {
1957   ToolkitTestApplication application;
1958
1959   tet_infoline("Create an ImageVisual using FitHeight ( image: [600,600], view: [600,700] )");
1960
1961   ImageView     imageView = ImageView::New();
1962   Property::Map imageMap;
1963   imageMap.Add(Toolkit::Visual::Property::TYPE, Toolkit::Visual::IMAGE);
1964   imageMap.Add(Toolkit::ImageVisual::Property::URL, gImage_600_RGB); // 600x600 image
1965   imageMap.Add(DevelVisual::Property::VISUAL_FITTING_MODE, Toolkit::DevelVisual::FIT_HEIGHT);
1966
1967   imageView.SetProperty(Toolkit::ImageView::Property::IMAGE, imageMap);
1968   imageView.SetProperty(Actor::Property::SIZE, Vector2(600, 700));
1969
1970   application.GetScene().Add(imageView);
1971
1972   // Trigger a potential relayout
1973   application.SendNotification();
1974   application.Render();
1975
1976   Toolkit::Visual::Base visual = DevelControl::GetVisual(Toolkit::Internal::GetImplementation(imageView), Toolkit::ImageView::Property::IMAGE);
1977   Property::Map         returnedMap;
1978   visual.CreatePropertyMap(returnedMap);
1979
1980   Property::Value* value = returnedMap.Find(Toolkit::Visual::Property::TRANSFORM);
1981   DALI_TEST_CHECK(value);
1982   Property::Map* map = value->GetMap();
1983   DALI_TEST_CHECK(map);
1984
1985   value = map->Find(Toolkit::Visual::Transform::Property::SIZE);
1986   DALI_TEST_CHECK(value);
1987   DALI_TEST_EQUALS(value->Get<Vector2>(), Vector2(600, 700), TEST_LOCATION); // Change the internal size according to the image view size
1988
1989   value = map->Find(Toolkit::Visual::Transform::Property::SIZE_POLICY);
1990   DALI_TEST_CHECK(value);
1991   DALI_TEST_EQUALS(value->Get<Vector2>(), Vector2(Toolkit::Visual::Transform::Policy::ABSOLUTE, Toolkit::Visual::Transform::Policy::ABSOLUTE), TEST_LOCATION);
1992
1993   value = map->Find(Toolkit::Visual::Transform::Property::OFFSET);
1994   DALI_TEST_CHECK(value);
1995   DALI_TEST_EQUALS(value->Get<Vector2>(), Vector2(0, 0), TEST_LOCATION); // OFFSET is zero
1996
1997   END_TEST;
1998 }
1999
2000 int UtcDaliImageViewFittingModesFitHeight02(void)
2001 {
2002   ToolkitTestApplication application;
2003
2004   tet_infoline("Create an ImageVisual using FitHeight ( image: [600,600], view: [700,600] )");
2005
2006   ImageView     imageView = ImageView::New();
2007   Property::Map imageMap;
2008   imageMap.Add(Toolkit::Visual::Property::TYPE, Toolkit::Visual::IMAGE);
2009   imageMap.Add(Toolkit::ImageVisual::Property::URL, gImage_600_RGB); // 249x169 image
2010   imageMap.Add(DevelVisual::Property::VISUAL_FITTING_MODE, Toolkit::DevelVisual::FIT_HEIGHT);
2011
2012   imageView.SetProperty(Toolkit::ImageView::Property::IMAGE, imageMap);
2013   imageView.SetProperty(Actor::Property::SIZE, Vector2(700, 600));
2014
2015   application.GetScene().Add(imageView);
2016
2017   // Trigger a potential relayout
2018   application.SendNotification();
2019   application.Render();
2020
2021   Toolkit::Visual::Base visual = DevelControl::GetVisual(Toolkit::Internal::GetImplementation(imageView), Toolkit::ImageView::Property::IMAGE);
2022   Property::Map         returnedMap;
2023   visual.CreatePropertyMap(returnedMap);
2024
2025   Property::Value* value = returnedMap.Find(Toolkit::Visual::Property::TRANSFORM);
2026   DALI_TEST_CHECK(value);
2027   Property::Map* map = value->GetMap();
2028   DALI_TEST_CHECK(map);
2029
2030   value = map->Find(Toolkit::Visual::Transform::Property::SIZE);
2031   DALI_TEST_CHECK(value);
2032   DALI_TEST_EQUALS(value->Get<Vector2>(), Vector2(600, 600), TEST_LOCATION); // Change the internal size according to the image view size
2033
2034   value = map->Find(Toolkit::Visual::Transform::Property::SIZE_POLICY);
2035   DALI_TEST_CHECK(value);
2036   DALI_TEST_EQUALS(value->Get<Vector2>(), Vector2(Toolkit::Visual::Transform::Policy::ABSOLUTE, Toolkit::Visual::Transform::Policy::ABSOLUTE), TEST_LOCATION);
2037
2038   value = map->Find(Toolkit::Visual::Transform::Property::OFFSET);
2039   DALI_TEST_CHECK(value);
2040   DALI_TEST_EQUALS(value->Get<Vector2>(), Vector2(50, 0), TEST_LOCATION);
2041
2042   END_TEST;
2043 }
2044
2045 int UtcDaliImageViewFittingModesFitWidth01(void)
2046 {
2047   ToolkitTestApplication application;
2048
2049   tet_infoline("Create an ImageVisual using FitWidth ( image: [600,600], view: [600,700] )");
2050
2051   ImageView     imageView = ImageView::New();
2052   Property::Map imageMap;
2053   imageMap.Add(Toolkit::Visual::Property::TYPE, Toolkit::Visual::IMAGE);
2054   imageMap.Add(Toolkit::ImageVisual::Property::URL, gImage_600_RGB); // 600x600 image
2055   imageMap.Add(DevelVisual::Property::VISUAL_FITTING_MODE, Toolkit::DevelVisual::FIT_WIDTH);
2056
2057   imageView.SetProperty(Toolkit::ImageView::Property::IMAGE, imageMap);
2058   imageView.SetProperty(Actor::Property::SIZE, Vector2(600, 700));
2059
2060   application.GetScene().Add(imageView);
2061
2062   // Trigger a potential relayout
2063   application.SendNotification();
2064   application.Render();
2065
2066   Toolkit::Visual::Base visual = DevelControl::GetVisual(Toolkit::Internal::GetImplementation(imageView), Toolkit::ImageView::Property::IMAGE);
2067   Property::Map         returnedMap;
2068   visual.CreatePropertyMap(returnedMap);
2069
2070   Property::Value* value = returnedMap.Find(Toolkit::Visual::Property::TRANSFORM);
2071   DALI_TEST_CHECK(value);
2072   Property::Map* map = value->GetMap();
2073   DALI_TEST_CHECK(map);
2074
2075   value = map->Find(Toolkit::Visual::Transform::Property::SIZE);
2076   DALI_TEST_CHECK(value);
2077   DALI_TEST_EQUALS(value->Get<Vector2>(), Vector2(600, 600), TEST_LOCATION); // Change the internal size according to the image view size
2078
2079   value = map->Find(Toolkit::Visual::Transform::Property::SIZE_POLICY);
2080   DALI_TEST_CHECK(value);
2081   DALI_TEST_EQUALS(value->Get<Vector2>(), Vector2(Toolkit::Visual::Transform::Policy::ABSOLUTE, Toolkit::Visual::Transform::Policy::ABSOLUTE), TEST_LOCATION);
2082
2083   value = map->Find(Toolkit::Visual::Transform::Property::OFFSET);
2084   DALI_TEST_CHECK(value);
2085   DALI_TEST_EQUALS(value->Get<Vector2>(), Vector2(0, 50), TEST_LOCATION);
2086
2087   END_TEST;
2088 }
2089
2090 int UtcDaliImageViewFittingModesFitWidth02(void)
2091 {
2092   ToolkitTestApplication application;
2093
2094   tet_infoline("Create an ImageVisual using FitWidth ( image: [600,600], view:[700,600] )");
2095
2096   ImageView     imageView = ImageView::New();
2097   Property::Map imageMap;
2098   imageMap.Add(Toolkit::Visual::Property::TYPE, Toolkit::Visual::IMAGE);
2099   imageMap.Add(Toolkit::ImageVisual::Property::URL, gImage_600_RGB); // 249x169 image
2100   imageMap.Add(DevelVisual::Property::VISUAL_FITTING_MODE, Toolkit::DevelVisual::FIT_WIDTH);
2101
2102   imageView.SetProperty(Toolkit::ImageView::Property::IMAGE, imageMap);
2103   imageView.SetProperty(Actor::Property::SIZE, Vector2(700, 600));
2104
2105   application.GetScene().Add(imageView);
2106
2107   // Trigger a potential relayout
2108   application.SendNotification();
2109   application.Render();
2110
2111   Toolkit::Visual::Base visual = DevelControl::GetVisual(Toolkit::Internal::GetImplementation(imageView), Toolkit::ImageView::Property::IMAGE);
2112   Property::Map         returnedMap;
2113   visual.CreatePropertyMap(returnedMap);
2114
2115   Property::Value* value = returnedMap.Find(Toolkit::Visual::Property::TRANSFORM);
2116   DALI_TEST_CHECK(value);
2117   Property::Map* map = value->GetMap();
2118   DALI_TEST_CHECK(map);
2119
2120   value = map->Find(Toolkit::Visual::Transform::Property::SIZE);
2121   DALI_TEST_CHECK(value);
2122   DALI_TEST_EQUALS(value->Get<Vector2>(), Vector2(700, 600), TEST_LOCATION); // Change the internal size according to the image view size
2123
2124   value = map->Find(Toolkit::Visual::Transform::Property::SIZE_POLICY);
2125   DALI_TEST_CHECK(value);
2126   DALI_TEST_EQUALS(value->Get<Vector2>(), Vector2(Toolkit::Visual::Transform::Policy::ABSOLUTE, Toolkit::Visual::Transform::Policy::ABSOLUTE), TEST_LOCATION);
2127
2128   value = map->Find(Toolkit::Visual::Transform::Property::OFFSET);
2129   DALI_TEST_CHECK(value);
2130   DALI_TEST_EQUALS(value->Get<Vector2>(), Vector2(0, 0), TEST_LOCATION); // OFFSET is zero
2131
2132   END_TEST;
2133 }
2134
2135 int UtcDaliImageViewFittingModesChangeFittingMode01(void)
2136 {
2137   ToolkitTestApplication application;
2138
2139   tet_infoline("UtcDaliImageViewFittingModesChangeFittingMode, image: [600,600], view:[800,700]");
2140
2141   ImageView imageView = ImageView::New();
2142
2143   // 1. Render using FittingMode::SHRINK_TO_FIT
2144   Property::Map imageMap;
2145   imageMap[Toolkit::Visual::Property::TYPE]            = Toolkit::Visual::IMAGE;
2146   imageMap[Toolkit::ImageVisual::Property::URL]        = gImage_600_RGB;
2147   imageMap[DevelVisual::Property::VISUAL_FITTING_MODE] = Toolkit::DevelVisual::FIT_KEEP_ASPECT_RATIO;
2148
2149   imageView.SetProperty(Toolkit::ImageView::Property::IMAGE, imageMap);
2150   imageView.SetProperty(Actor::Property::SIZE, Vector2(800, 700));
2151
2152   application.GetScene().Add(imageView);
2153
2154   // Trigger a potential relayout
2155   application.SendNotification();
2156   application.Render();
2157
2158   Toolkit::Visual::Base visual = DevelControl::GetVisual(Toolkit::Internal::GetImplementation(imageView), Toolkit::ImageView::Property::IMAGE);
2159   Property::Map         returnedMap;
2160   visual.CreatePropertyMap(returnedMap);
2161
2162   Property::Value* value = returnedMap.Find(Toolkit::Visual::Property::TRANSFORM);
2163   DALI_TEST_CHECK(value);
2164   Property::Map* map = value->GetMap();
2165   DALI_TEST_CHECK(map);
2166
2167   value = map->Find(Toolkit::Visual::Transform::Property::SIZE);
2168   DALI_TEST_CHECK(value);
2169   DALI_TEST_EQUALS(value->Get<Vector2>(), Vector2(700, 700), TEST_LOCATION); // Change the internal size according to the image view size
2170
2171   value = map->Find(Toolkit::Visual::Transform::Property::SIZE_POLICY);
2172   DALI_TEST_CHECK(value);
2173   DALI_TEST_EQUALS(value->Get<Vector2>(), Vector2(Toolkit::Visual::Transform::Policy::ABSOLUTE, Toolkit::Visual::Transform::Policy::ABSOLUTE), TEST_LOCATION);
2174
2175   value = map->Find(Toolkit::Visual::Transform::Property::OFFSET);
2176   DALI_TEST_CHECK(value);
2177   DALI_TEST_EQUALS(value->Get<Vector2>(), Vector2(50, 0), TEST_LOCATION);
2178
2179   // 2. Render again using DevelVisaul::CENTER
2180   Property::Map imageMap2;
2181   imageMap2[Toolkit::Visual::Property::TYPE]            = Toolkit::Visual::IMAGE;
2182   imageMap2[Toolkit::ImageVisual::Property::URL]        = gImage_600_RGB;
2183   imageMap2[DevelVisual::Property::VISUAL_FITTING_MODE] = Toolkit::DevelVisual::CENTER;
2184
2185   imageView.SetProperty(Toolkit::ImageView::Property::IMAGE, imageMap2);
2186   imageView.SetProperty(Actor::Property::SIZE, Vector2(800, 700));
2187
2188   application.GetScene().Add(imageView);
2189
2190   DALI_TEST_EQUALS(Test::WaitForEventThreadTrigger(1), true, TEST_LOCATION);
2191
2192   // Trigger a potential relayout
2193   application.SendNotification();
2194   application.Render();
2195
2196   returnedMap.Clear();
2197   visual = DevelControl::GetVisual(Toolkit::Internal::GetImplementation(imageView), Toolkit::ImageView::Property::IMAGE);
2198
2199   visual.CreatePropertyMap(returnedMap);
2200
2201   value = returnedMap.Find(Toolkit::Visual::Property::TRANSFORM);
2202   DALI_TEST_CHECK(value);
2203   map = value->GetMap();
2204   DALI_TEST_CHECK(map);
2205
2206   value = map->Find(Toolkit::Visual::Transform::Property::SIZE);
2207   DALI_TEST_CHECK(value);
2208   DALI_TEST_EQUALS(value->Get<Vector2>(), Vector2(600, 600), TEST_LOCATION); // Change the internal size according to the image view size
2209
2210   value = map->Find(Toolkit::Visual::Transform::Property::SIZE_POLICY);
2211   DALI_TEST_CHECK(value);
2212   DALI_TEST_EQUALS(value->Get<Vector2>(), Vector2(Toolkit::Visual::Transform::Policy::ABSOLUTE, Toolkit::Visual::Transform::Policy::ABSOLUTE), TEST_LOCATION);
2213
2214   value = map->Find(Toolkit::Visual::Transform::Property::OFFSET);
2215   DALI_TEST_CHECK(value);
2216   DALI_TEST_EQUALS(value->Get<Vector2>(), Vector2(100, 50), TEST_LOCATION);
2217
2218   // 3. Render again using before fittingMode
2219   Property::Map imageMap3;
2220   imageMap3[Toolkit::Visual::Property::TYPE]            = Toolkit::Visual::IMAGE;
2221   imageMap3[Toolkit::ImageVisual::Property::URL]        = gImage_600_RGB;
2222   imageMap3[DevelVisual::Property::VISUAL_FITTING_MODE] = Toolkit::DevelVisual::FIT_KEEP_ASPECT_RATIO;
2223
2224   imageView.SetProperty(Toolkit::ImageView::Property::IMAGE, imageMap3);
2225   imageView.SetProperty(Actor::Property::SIZE, Vector2(800, 700));
2226
2227   application.GetScene().Add(imageView);
2228
2229   // Trigger a potential relayout
2230   application.SendNotification();
2231   application.Render();
2232
2233   returnedMap.Clear();
2234   visual = DevelControl::GetVisual(Toolkit::Internal::GetImplementation(imageView), Toolkit::ImageView::Property::IMAGE);
2235   visual.CreatePropertyMap(returnedMap);
2236
2237   value = returnedMap.Find(Toolkit::Visual::Property::TRANSFORM);
2238   DALI_TEST_CHECK(value);
2239   map = value->GetMap();
2240   DALI_TEST_CHECK(map);
2241
2242   value = map->Find(Toolkit::Visual::Transform::Property::SIZE);
2243   DALI_TEST_CHECK(value);
2244   DALI_TEST_EQUALS(value->Get<Vector2>(), Vector2(700, 700), TEST_LOCATION); // Change the internal size according to the image view size
2245
2246   value = map->Find(Toolkit::Visual::Transform::Property::SIZE_POLICY);
2247   DALI_TEST_CHECK(value);
2248   DALI_TEST_EQUALS(value->Get<Vector2>(), Vector2(Toolkit::Visual::Transform::Policy::ABSOLUTE, Toolkit::Visual::Transform::Policy::ABSOLUTE), TEST_LOCATION);
2249
2250   value = map->Find(Toolkit::Visual::Transform::Property::OFFSET);
2251   DALI_TEST_CHECK(value);
2252   DALI_TEST_EQUALS(value->Get<Vector2>(), Vector2(50, 0), TEST_LOCATION);
2253
2254   END_TEST;
2255 }
2256
2257 int UtcDaliImageViewFittingModesChangeFittingMode02(void)
2258 {
2259   ToolkitTestApplication application;
2260
2261   tet_infoline("UtcDaliImageViewFittingModesChangeFittingMode, image: [600,600], view:[800,700]");
2262
2263   ImageView imageView = ImageView::New();
2264
2265   // 1. Render using FittingMode::OVER_FIT_KEEP_ASPECT_RATIO
2266   Property::Map imageMap;
2267   imageMap[Toolkit::Visual::Property::TYPE]            = Toolkit::Visual::IMAGE;
2268   imageMap[Toolkit::ImageVisual::Property::URL]        = gImage_600_RGB;
2269   imageMap[DevelVisual::Property::VISUAL_FITTING_MODE] = Toolkit::DevelVisual::OVER_FIT_KEEP_ASPECT_RATIO;
2270
2271   imageView.SetProperty(Toolkit::ImageView::Property::IMAGE, imageMap);
2272   imageView.SetProperty(Actor::Property::SIZE, Vector2(800, 700));
2273
2274   application.GetScene().Add(imageView);
2275
2276   // Trigger a potential relayout
2277   application.SendNotification();
2278   application.Render();
2279
2280   Toolkit::Visual::Base visual = DevelControl::GetVisual(Toolkit::Internal::GetImplementation(imageView), Toolkit::ImageView::Property::IMAGE);
2281   Property::Map         returnedMap;
2282   visual.CreatePropertyMap(returnedMap);
2283
2284   Property::Value* value = returnedMap.Find(Toolkit::Visual::Property::TRANSFORM);
2285   DALI_TEST_CHECK(value);
2286   Property::Map* map = value->GetMap();
2287   DALI_TEST_CHECK(map);
2288
2289   value = map->Find(Toolkit::Visual::Transform::Property::SIZE);
2290   DALI_TEST_CHECK(value);
2291   DALI_TEST_EQUALS(value->Get<Vector2>(), Vector2(800, 700), TEST_LOCATION); // Change the internal size according to the image view size
2292
2293   value = map->Find(Toolkit::Visual::Transform::Property::SIZE_POLICY);
2294   DALI_TEST_CHECK(value);
2295   DALI_TEST_EQUALS(value->Get<Vector2>(), Vector2(Toolkit::Visual::Transform::Policy::ABSOLUTE, Toolkit::Visual::Transform::Policy::ABSOLUTE), TEST_LOCATION);
2296
2297   value = map->Find(Toolkit::Visual::Transform::Property::OFFSET);
2298   DALI_TEST_CHECK(value);
2299   DALI_TEST_EQUALS(value->Get<Vector2>(), Vector2(0, 0), TEST_LOCATION);
2300
2301   // 2. Render again using DevelVisaul::CENTER
2302   Property::Map imageMap2;
2303   imageMap2[Toolkit::Visual::Property::TYPE]            = Toolkit::Visual::IMAGE;
2304   imageMap2[Toolkit::ImageVisual::Property::URL]        = gImage_600_RGB;
2305   imageMap2[DevelVisual::Property::VISUAL_FITTING_MODE] = Toolkit::DevelVisual::CENTER;
2306
2307   imageView.SetProperty(Toolkit::ImageView::Property::IMAGE, imageMap2);
2308   imageView.SetProperty(Actor::Property::SIZE, Vector2(800, 700));
2309
2310   application.GetScene().Add(imageView);
2311
2312   DALI_TEST_EQUALS(Test::WaitForEventThreadTrigger(1), true, TEST_LOCATION);
2313
2314   // Trigger a potential relayout
2315   application.SendNotification();
2316   application.Render();
2317
2318   returnedMap.Clear();
2319   visual = DevelControl::GetVisual(Toolkit::Internal::GetImplementation(imageView), Toolkit::ImageView::Property::IMAGE);
2320
2321   visual.CreatePropertyMap(returnedMap);
2322
2323   value = returnedMap.Find(Toolkit::Visual::Property::TRANSFORM);
2324   DALI_TEST_CHECK(value);
2325   map = value->GetMap();
2326   DALI_TEST_CHECK(map);
2327
2328   value = map->Find(Toolkit::Visual::Transform::Property::SIZE);
2329   DALI_TEST_CHECK(value);
2330   DALI_TEST_EQUALS(value->Get<Vector2>(), Vector2(600, 600), TEST_LOCATION); // Change the internal size according to the image view size
2331
2332   value = map->Find(Toolkit::Visual::Transform::Property::SIZE_POLICY);
2333   DALI_TEST_CHECK(value);
2334   DALI_TEST_EQUALS(value->Get<Vector2>(), Vector2(Toolkit::Visual::Transform::Policy::ABSOLUTE, Toolkit::Visual::Transform::Policy::ABSOLUTE), TEST_LOCATION);
2335
2336   value = map->Find(Toolkit::Visual::Transform::Property::OFFSET);
2337   DALI_TEST_CHECK(value);
2338   DALI_TEST_EQUALS(value->Get<Vector2>(), Vector2(100, 50), TEST_LOCATION);
2339
2340   // 3. Render again using before fittingMode
2341   Property::Map imageMap3;
2342   imageMap3[Toolkit::Visual::Property::TYPE]            = Toolkit::Visual::IMAGE;
2343   imageMap3[Toolkit::ImageVisual::Property::URL]        = gImage_600_RGB;
2344   imageMap3[DevelVisual::Property::VISUAL_FITTING_MODE] = Toolkit::DevelVisual::OVER_FIT_KEEP_ASPECT_RATIO;
2345
2346   imageView.SetProperty(Toolkit::ImageView::Property::IMAGE, imageMap3);
2347   imageView.SetProperty(Actor::Property::SIZE, Vector2(800, 700));
2348
2349   application.GetScene().Add(imageView);
2350
2351   // Trigger a potential relayout
2352   application.SendNotification();
2353   application.Render();
2354
2355   returnedMap.Clear();
2356   visual = DevelControl::GetVisual(Toolkit::Internal::GetImplementation(imageView), Toolkit::ImageView::Property::IMAGE);
2357   visual.CreatePropertyMap(returnedMap);
2358
2359   value = returnedMap.Find(Toolkit::Visual::Property::TRANSFORM);
2360   DALI_TEST_CHECK(value);
2361   map = value->GetMap();
2362   DALI_TEST_CHECK(map);
2363
2364   value = map->Find(Toolkit::Visual::Transform::Property::SIZE);
2365   DALI_TEST_CHECK(value);
2366   DALI_TEST_EQUALS(value->Get<Vector2>(), Vector2(800, 700), TEST_LOCATION); // Change the internal size according to the image view size
2367
2368   value = map->Find(Toolkit::Visual::Transform::Property::SIZE_POLICY);
2369   DALI_TEST_CHECK(value);
2370   DALI_TEST_EQUALS(value->Get<Vector2>(), Vector2(Toolkit::Visual::Transform::Policy::ABSOLUTE, Toolkit::Visual::Transform::Policy::ABSOLUTE), TEST_LOCATION);
2371
2372   value = map->Find(Toolkit::Visual::Transform::Property::OFFSET);
2373   DALI_TEST_CHECK(value);
2374   DALI_TEST_EQUALS(value->Get<Vector2>(), Vector2(0, 0), TEST_LOCATION);
2375
2376   END_TEST;
2377 }
2378
2379 int UtcDaliImageViewFittingModesWithAnimatedVectorImageVisual(void)
2380 {
2381   ToolkitTestApplication application;
2382
2383   tet_infoline("Create an ImageVisual using SCALE_TO_FILL and animated vector image ( image: [600,600], view:[600,600] )");
2384
2385   ImageView     imageView = ImageView::New();
2386   Property::Map imageMap;
2387   imageMap.Add(Toolkit::Visual::Property::TYPE, DevelVisual::ANIMATED_VECTOR_IMAGE);
2388   imageMap.Add(Toolkit::ImageVisual::Property::URL, TEST_ANIMATED_VECTOR_IMAGE_FILE_NAME); // 249x169 image
2389
2390   imageView.SetProperty(Toolkit::ImageView::Property::IMAGE, imageMap);
2391   imageView.SetProperty(Actor::Property::SIZE, Vector2(600, 600));
2392
2393   application.GetScene().Add(imageView);
2394
2395   // Trigger a potential relayout
2396   application.SendNotification();
2397   application.Render();
2398
2399   Toolkit::Visual::Base visual = DevelControl::GetVisual(Toolkit::Internal::GetImplementation(imageView), Toolkit::ImageView::Property::IMAGE);
2400   Property::Map         returnedMap;
2401   visual.CreatePropertyMap(returnedMap);
2402
2403   Property::Value* value = returnedMap.Find(Toolkit::Visual::Property::TRANSFORM);
2404   DALI_TEST_CHECK(value);
2405   Property::Map* map = value->GetMap();
2406   DALI_TEST_CHECK(map);
2407
2408   value = map->Find(Toolkit::Visual::Transform::Property::SIZE);
2409   DALI_TEST_CHECK(value);
2410   DALI_TEST_EQUALS(value->Get<Vector2>(), Vector2::ONE, TEST_LOCATION); // Relative size so will take up 100%
2411
2412   value = map->Find(Toolkit::Visual::Transform::Property::SIZE_POLICY);
2413   DALI_TEST_CHECK(value);
2414   DALI_TEST_CHECK(value->Get<int>() == Toolkit::Visual::Transform::Policy::RELATIVE);
2415
2416   value = map->Find(Toolkit::Visual::Transform::Property::OFFSET);
2417   DALI_TEST_CHECK(value);
2418   DALI_TEST_EQUALS(value->Get<Vector2>(), Vector2(0, 0), TEST_LOCATION); // OFFSET is zero
2419
2420   END_TEST;
2421 }
2422
2423 int UtcDaliImageViewCustomShader(void)
2424 {
2425   ToolkitTestApplication application;
2426
2427   // Set a custom shader with an image url
2428   {
2429     Property::Map     properties;
2430     Property::Map     shader;
2431     const std::string vertexShader                    = "Foobar";
2432     const std::string fragmentShader                  = "Foobar";
2433     shader[Visual::Shader::Property::FRAGMENT_SHADER] = fragmentShader;
2434     shader[Visual::Shader::Property::VERTEX_SHADER]   = vertexShader;
2435
2436     properties[Visual::Property::TYPE]     = Visual::IMAGE;
2437     properties[Visual::Property::SHADER]   = shader;
2438     properties[ImageVisual::Property::URL] = TEST_IMAGE_FILE_NAME;
2439
2440     ImageView imageView = ImageView::New();
2441     imageView.SetProperty(ImageView::Property::IMAGE, properties);
2442
2443     application.GetScene().Add(imageView);
2444
2445     application.SendNotification();
2446     application.Render();
2447
2448     DALI_TEST_EQUALS(Test::WaitForEventThreadTrigger(1), true, TEST_LOCATION);
2449
2450     Renderer        renderer = imageView.GetRendererAt(0);
2451     Shader          shader2  = renderer.GetShader();
2452     Property::Value value    = shader2.GetProperty(Shader::Property::PROGRAM);
2453     Property::Map*  map      = value.GetMap();
2454     DALI_TEST_CHECK(map);
2455
2456     Property::Value* fragment = map->Find("fragment"); // fragment key name from shader-impl.cpp
2457     DALI_TEST_EQUALS(fragmentShader, fragment->Get<std::string>(), TEST_LOCATION);
2458
2459     Property::Value* vertex = map->Find("vertex"); // vertex key name from shader-impl.cpp
2460     DALI_TEST_EQUALS(vertexShader, vertex->Get<std::string>(), TEST_LOCATION);
2461   }
2462
2463   // Set a custom shader after setting an image url
2464   {
2465     Property::Map     properties;
2466     Property::Map     shader;
2467     const std::string vertexShader                    = "Foobar";
2468     const std::string fragmentShader                  = "Foobar";
2469     shader[Visual::Shader::Property::FRAGMENT_SHADER] = fragmentShader;
2470     shader[Visual::Shader::Property::VERTEX_SHADER]   = vertexShader;
2471
2472     properties[Visual::Property::SHADER] = shader;
2473
2474     ImageView imageView = ImageView::New(TEST_IMAGE_FILE_NAME);
2475     imageView.SetProperty(ImageView::Property::IMAGE, properties);
2476
2477     application.GetScene().Add(imageView);
2478
2479     application.SendNotification();
2480     application.Render();
2481
2482     DALI_TEST_EQUALS(Test::WaitForEventThreadTrigger(1), true, TEST_LOCATION);
2483
2484     Renderer        renderer = imageView.GetRendererAt(0);
2485     Shader          shader2  = renderer.GetShader();
2486     Property::Value value    = shader2.GetProperty(Shader::Property::PROGRAM);
2487     Property::Map*  map      = value.GetMap();
2488     DALI_TEST_CHECK(map);
2489
2490     Property::Value* fragment = map->Find("fragment"); // fragment key name from shader-impl.cpp
2491     DALI_TEST_EQUALS(fragmentShader, fragment->Get<std::string>(), TEST_LOCATION);
2492
2493     Property::Value* vertex = map->Find("vertex"); // vertex key name from shader-impl.cpp
2494     DALI_TEST_EQUALS(vertexShader, vertex->Get<std::string>(), TEST_LOCATION);
2495   }
2496
2497   // Set a custom shader before setting an image url
2498   {
2499     Property::Map     properties;
2500     Property::Map     shader;
2501     const std::string vertexShader                    = "Foobar";
2502     const std::string fragmentShader                  = "Foobar";
2503     shader[Visual::Shader::Property::FRAGMENT_SHADER] = fragmentShader;
2504     shader[Visual::Shader::Property::VERTEX_SHADER]   = vertexShader;
2505
2506     properties[Visual::Property::SHADER] = shader;
2507
2508     ImageView imageView = ImageView::New();
2509     imageView.SetProperty(ImageView::Property::IMAGE, properties);
2510     imageView.SetProperty(ImageView::Property::IMAGE, TEST_IMAGE_FILE_NAME);
2511
2512     application.GetScene().Add(imageView);
2513
2514     application.SendNotification();
2515     application.Render();
2516     DALI_TEST_EQUALS(Test::WaitForEventThreadTrigger(1), true, TEST_LOCATION);
2517
2518     Renderer        renderer = imageView.GetRendererAt(0);
2519     Shader          shader2  = renderer.GetShader();
2520     Property::Value value    = shader2.GetProperty(Shader::Property::PROGRAM);
2521     Property::Map*  map      = value.GetMap();
2522     DALI_TEST_CHECK(map);
2523
2524     Property::Value* fragment = map->Find("fragment"); // fragment key name from shader-impl.cpp
2525     DALI_TEST_EQUALS(fragmentShader, fragment->Get<std::string>(), TEST_LOCATION);
2526
2527     Property::Value* vertex = map->Find("vertex"); // vertex key name from shader-impl.cpp
2528     DALI_TEST_EQUALS(vertexShader, vertex->Get<std::string>(), TEST_LOCATION);
2529   }
2530
2531   // Set a custom shader after setting a property map
2532   {
2533     Property::Map     properties;
2534     Property::Map     shader;
2535     const std::string vertexShader                    = "Foobar";
2536     const std::string fragmentShader                  = "Foobar";
2537     shader[Visual::Shader::Property::FRAGMENT_SHADER] = fragmentShader;
2538     shader[Visual::Shader::Property::VERTEX_SHADER]   = vertexShader;
2539
2540     properties[Visual::Property::SHADER] = shader;
2541
2542     Property::Map properties1;
2543     properties1[Visual::Property::TYPE]     = Visual::IMAGE;
2544     properties1[ImageVisual::Property::URL] = TEST_IMAGE_FILE_NAME;
2545
2546     ImageView imageView = ImageView::New();
2547     imageView.SetProperty(ImageView::Property::IMAGE, properties1);
2548     imageView.SetProperty(ImageView::Property::IMAGE, properties);
2549
2550     application.GetScene().Add(imageView);
2551
2552     application.SendNotification();
2553     application.Render();
2554     DALI_TEST_EQUALS(Test::WaitForEventThreadTrigger(1), true, TEST_LOCATION);
2555
2556     Renderer        renderer = imageView.GetRendererAt(0);
2557     Shader          shader2  = renderer.GetShader();
2558     Property::Value value    = shader2.GetProperty(Shader::Property::PROGRAM);
2559     Property::Map*  map      = value.GetMap();
2560     DALI_TEST_CHECK(map);
2561
2562     Property::Value* fragment = map->Find("fragment"); // fragment key name from shader-impl.cpp
2563     DALI_TEST_EQUALS(fragmentShader, fragment->Get<std::string>(), TEST_LOCATION);
2564
2565     Property::Value* vertex = map->Find("vertex"); // vertex key name from shader-impl.cpp
2566     DALI_TEST_EQUALS(vertexShader, vertex->Get<std::string>(), TEST_LOCATION);
2567   }
2568
2569   // Set a custom shader before setting a property map
2570   {
2571     Property::Map     properties;
2572     Property::Map     shader;
2573     const std::string vertexShader                    = "Foobar";
2574     const std::string fragmentShader                  = "Foobar";
2575     shader[Visual::Shader::Property::FRAGMENT_SHADER] = fragmentShader;
2576     shader[Visual::Shader::Property::VERTEX_SHADER]   = vertexShader;
2577
2578     properties[Visual::Property::SHADER] = shader;
2579
2580     Property::Map properties1;
2581     properties1[Visual::Property::TYPE]     = Visual::IMAGE;
2582     properties1[ImageVisual::Property::URL] = TEST_IMAGE_FILE_NAME;
2583
2584     ImageView imageView = ImageView::New();
2585     imageView.SetProperty(ImageView::Property::IMAGE, properties);
2586     imageView.SetProperty(ImageView::Property::IMAGE, properties1);
2587
2588     application.GetScene().Add(imageView);
2589
2590     application.SendNotification();
2591     application.Render();
2592     DALI_TEST_EQUALS(Test::WaitForEventThreadTrigger(1), true, TEST_LOCATION);
2593
2594     Renderer        renderer = imageView.GetRendererAt(0);
2595     Shader          shader2  = renderer.GetShader();
2596     Property::Value value    = shader2.GetProperty(Shader::Property::PROGRAM);
2597     Property::Map*  map      = value.GetMap();
2598     DALI_TEST_CHECK(map);
2599
2600     Property::Value* fragment = map->Find("fragment"); // fragment key name from shader-impl.cpp
2601     DALI_TEST_EQUALS(fragmentShader, fragment->Get<std::string>(), TEST_LOCATION);
2602
2603     Property::Value* vertex = map->Find("vertex"); // vertex key name from shader-impl.cpp
2604     DALI_TEST_EQUALS(vertexShader, vertex->Get<std::string>(), TEST_LOCATION);
2605   }
2606
2607   END_TEST;
2608 }
2609
2610 namespace
2611 {
2612 static int gFailCounter = 0;
2613 const int  MAX_RETRIES(3);
2614
2615 void ReloadImage(ImageView imageView)
2616 {
2617   Property::Map imageImmediateLoadingMap;
2618   imageImmediateLoadingMap[ImageVisual::Property::URL]         = "Non-existant-image.jpg";
2619   imageImmediateLoadingMap[ImageVisual::Property::LOAD_POLICY] = ImageVisual::LoadPolicy::IMMEDIATE;
2620
2621   tet_infoline("Immediate load an image");
2622   imageView.SetProperty(ImageView::Property::IMAGE, imageImmediateLoadingMap);
2623 }
2624
2625 void ResourceFailedReload(Control control)
2626 {
2627   gFailCounter++;
2628   if(gFailCounter < MAX_RETRIES)
2629   {
2630     ReloadImage(ImageView::DownCast(control));
2631   }
2632 }
2633 } // namespace
2634
2635 int UtcDaliImageViewReloadFailedOnResourceReadySignal(void)
2636 {
2637   tet_infoline("Test reloading failed image from within signal handler.");
2638
2639   ToolkitTestApplication application;
2640
2641   gFailCounter = 0;
2642
2643   ImageView imageView = ImageView::New();
2644   imageView.ResourceReadySignal().Connect(&ResourceFailedReload);
2645   DALI_TEST_EQUALS(gFailCounter, 0, TEST_LOCATION);
2646   ReloadImage(imageView);
2647
2648   // loading started, this waits for the loader thread to complete
2649   DALI_TEST_EQUALS(Test::WaitForEventThreadTrigger(1), true, TEST_LOCATION);
2650   application.SendNotification();
2651
2652   DALI_TEST_EQUALS(gFailCounter, 1, TEST_LOCATION);
2653
2654   DALI_TEST_EQUALS(Test::WaitForEventThreadTrigger(1), true, TEST_LOCATION);
2655   application.SendNotification();
2656
2657   DALI_TEST_EQUALS(gFailCounter, 2, TEST_LOCATION);
2658
2659   DALI_TEST_EQUALS(Test::WaitForEventThreadTrigger(1), true, TEST_LOCATION);
2660   application.SendNotification();
2661   DALI_TEST_EQUALS(gFailCounter, 3, TEST_LOCATION);
2662
2663   END_TEST;
2664 }
2665
2666 int UtcDaliImageViewLoadRemoteSVG(void)
2667 {
2668   tet_infoline("Test load from a remote server.");
2669
2670   ToolkitTestApplication application;
2671
2672   {
2673     Toolkit::ImageView imageView;
2674     imageView = Toolkit::ImageView::New();
2675     imageView.SetImage("https://dev.w3.org/SVG/tools/svgweb/samples/svg-files/check.svg");
2676     imageView.SetProperty(Actor::Property::PARENT_ORIGIN, ParentOrigin::TOP_LEFT);
2677     imageView.SetProperty(Actor::Property::ANCHOR_POINT, AnchorPoint::TOP_LEFT);
2678     imageView.SetProperty(Actor::Property::SIZE, Vector2(300, 300));
2679     imageView.SetProperty(Actor::Property::POSITION, Vector3(150.0f, 150.0f, 0.0f));
2680
2681     application.GetScene().Add(imageView);
2682
2683     DALI_TEST_CHECK(imageView);
2684
2685     DALI_TEST_EQUALS(imageView.GetRendererCount(), 0u, TEST_LOCATION);
2686
2687     application.SendNotification();
2688
2689     // Wait for loading & rasterization
2690     DALI_TEST_EQUALS(Test::WaitForEventThreadTrigger(2), true, TEST_LOCATION);
2691
2692     application.SendNotification();
2693     application.Render();
2694
2695     DALI_TEST_EQUALS(imageView.GetRendererCount(), 1u, TEST_LOCATION);
2696   }
2697
2698   // Without size set
2699   {
2700     Toolkit::ImageView imageView;
2701     imageView = Toolkit::ImageView::New();
2702     imageView.SetImage("https://dev.w3.org/SVG/tools/svgweb/samples/svg-files/check.svg");
2703     imageView.SetProperty(Actor::Property::PARENT_ORIGIN, ParentOrigin::TOP_LEFT);
2704     imageView.SetProperty(Actor::Property::ANCHOR_POINT, AnchorPoint::TOP_LEFT);
2705     imageView.SetProperty(Actor::Property::POSITION, Vector3(150.0f, 150.0f, 0.0f));
2706
2707     application.GetScene().Add(imageView);
2708
2709     DALI_TEST_CHECK(imageView);
2710
2711     DALI_TEST_EQUALS(imageView.GetRendererCount(), 0u, TEST_LOCATION);
2712
2713     application.SendNotification();
2714
2715     // Wait for loading & rasterization
2716     DALI_TEST_EQUALS(Test::WaitForEventThreadTrigger(2), true, TEST_LOCATION);
2717
2718     application.SendNotification();
2719     application.Render();
2720
2721     DALI_TEST_EQUALS(imageView.GetRendererCount(), 1u, TEST_LOCATION);
2722   }
2723
2724   END_TEST;
2725 }
2726
2727 int UtcDaliImageViewSyncSVGLoading(void)
2728 {
2729   ToolkitTestApplication application;
2730
2731   tet_infoline("ImageView Testing SVG image sync loading");
2732
2733   {
2734     ImageView imageView = ImageView::New();
2735
2736     // Sync loading is used
2737     Property::Map syncLoadingMap;
2738     syncLoadingMap.Insert(Toolkit::Visual::Property::TYPE, Toolkit::Visual::IMAGE);
2739     syncLoadingMap.Insert(Toolkit::ImageVisual::Property::URL, TEST_RESOURCE_DIR "/svg1.svg");
2740     syncLoadingMap.Insert(Toolkit::ImageVisual::Property::SYNCHRONOUS_LOADING, true);
2741     imageView.SetProperty(ImageView::Property::IMAGE, syncLoadingMap);
2742
2743     application.GetScene().Add(imageView);
2744     DALI_TEST_CHECK(imageView);
2745
2746     application.SendNotification();
2747     Vector3 naturalSize = imageView.GetNaturalSize();
2748
2749     DALI_TEST_EQUALS(naturalSize.width, 100.0f, TEST_LOCATION);
2750     DALI_TEST_EQUALS(naturalSize.height, 100.0f, TEST_LOCATION);
2751   }
2752   END_TEST;
2753 }
2754
2755 int UtcDaliImageViewAsyncSVGLoading(void)
2756 {
2757   ToolkitTestApplication application;
2758
2759   tet_infoline("ImageView Testing SVG image async loading");
2760
2761   {
2762     ImageView imageView = ImageView::New();
2763
2764     // Async loading is used - default value of SYNCHRONOUS_LOADING is false.
2765     Property::Map propertyMap;
2766     propertyMap.Insert(Toolkit::Visual::Property::TYPE, Toolkit::Visual::IMAGE);
2767     propertyMap.Insert(Toolkit::ImageVisual::Property::URL, TEST_RESOURCE_DIR "/svg1.svg");
2768     imageView.SetProperty(ImageView::Property::IMAGE, propertyMap);
2769
2770     application.GetScene().Add(imageView);
2771     DALI_TEST_CHECK(imageView);
2772
2773     application.SendNotification();
2774
2775     // Wait for loading
2776     DALI_TEST_EQUALS(Test::WaitForEventThreadTrigger(1), true, TEST_LOCATION);
2777
2778     application.SendNotification();
2779     application.Render(16);
2780
2781     Vector3 naturalSize = imageView.GetNaturalSize();
2782     DALI_TEST_EQUALS(naturalSize.width, 100.0f, TEST_LOCATION);
2783     DALI_TEST_EQUALS(naturalSize.height, 100.0f, TEST_LOCATION);
2784   }
2785   END_TEST;
2786 }
2787
2788 int UtcDaliImageViewSVGLoadingSyncSetInvalidValue(void)
2789 {
2790   ToolkitTestApplication application;
2791
2792   tet_infoline("ImageView Testing SVG image async loading");
2793
2794   // Sync loading
2795   {
2796     ImageView imageView = ImageView::New();
2797
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
2803     // Check to set invalid value
2804     // The SYNCHRONOUS_LOADING property must be set to the bool value.
2805     // Check if error log is outputted when setting other value like string.
2806     // Even if the wrong value is set, the image will be shown normally, and the synchronous value should be the default value(false).
2807     syncLoadingMap.Insert(Toolkit::ImageVisual::Property::SYNCHRONOUS_LOADING, std::to_string(5));
2808     imageView.SetProperty(ImageView::Property::IMAGE, syncLoadingMap);
2809
2810     application.GetScene().Add(imageView);
2811     DALI_TEST_CHECK(imageView);
2812
2813     application.SendNotification();
2814
2815     // Wait for loading
2816     DALI_TEST_EQUALS(Test::WaitForEventThreadTrigger(1), true, TEST_LOCATION);
2817
2818     application.SendNotification();
2819     application.Render(16);
2820
2821     Vector3 naturalSize = imageView.GetNaturalSize();
2822     DALI_TEST_EQUALS(naturalSize.width, 100.0f, TEST_LOCATION);
2823     DALI_TEST_EQUALS(naturalSize.height, 100.0f, TEST_LOCATION);
2824
2825     Property::Value value = imageView.GetProperty(ImageView::Property::IMAGE);
2826     Property::Map*  map   = value.GetMap();
2827     DALI_TEST_CHECK(map);
2828
2829     Property::Value* sync = map->Find(Toolkit::ImageVisual::Property::SYNCHRONOUS_LOADING);
2830     DALI_TEST_CHECK(sync);
2831     DALI_TEST_EQUALS(false, sync->Get<bool>(), TEST_LOCATION);
2832   }
2833   END_TEST;
2834 }
2835
2836 int UtcDaliImageViewSvgLoadingFailure(void)
2837 {
2838   // Local svg file - invalid file path
2839   {
2840     ToolkitTestApplication application;
2841
2842     TestGlAbstraction& gl           = application.GetGlAbstraction();
2843     TraceCallStack&    textureTrace = gl.GetTextureTrace();
2844     textureTrace.Enable(true);
2845
2846     gResourceReadySignalFired = false;
2847
2848     ImageView imageView = ImageView::New(TEST_RESOURCE_DIR "/foo.svg");
2849     imageView.SetProperty(Actor::Property::SIZE, Vector2(200.f, 200.f));
2850     imageView.ResourceReadySignal().Connect(&ResourceReadySignal);
2851
2852     DALI_TEST_EQUALS(imageView.IsResourceReady(), false, TEST_LOCATION);
2853
2854     application.GetScene().Add(imageView);
2855
2856     application.SendNotification();
2857
2858     // loading started, this waits for the loader thread - load
2859     DALI_TEST_EQUALS(Test::WaitForEventThreadTrigger(1), true, TEST_LOCATION);
2860
2861     application.SendNotification();
2862     application.Render(16);
2863
2864     DALI_TEST_EQUALS(gResourceReadySignalFired, true, TEST_LOCATION);
2865     DALI_TEST_EQUALS(imageView.IsResourceReady(), true, TEST_LOCATION);
2866     DALI_TEST_EQUALS(imageView.GetVisualResourceStatus(ImageView::Property::IMAGE), Visual::ResourceStatus::FAILED, TEST_LOCATION);
2867
2868     // Should be shown a broken image
2869     DALI_TEST_EQUALS(imageView.GetRendererCount(), 1u, TEST_LOCATION);
2870     DALI_TEST_EQUALS(textureTrace.FindMethod("BindTexture"), true, TEST_LOCATION);
2871   }
2872
2873   // Local svg file - invalid file path without size set
2874   {
2875     ToolkitTestApplication application;
2876
2877     TestGlAbstraction& gl           = application.GetGlAbstraction();
2878     TraceCallStack&    textureTrace = gl.GetTextureTrace();
2879     textureTrace.Enable(true);
2880
2881     gResourceReadySignalFired = false;
2882     textureTrace.Reset();
2883
2884     ImageView imageView = ImageView::New(TEST_RESOURCE_DIR "/foo.svg");
2885     imageView.ResourceReadySignal().Connect(&ResourceReadySignal);
2886
2887     DALI_TEST_EQUALS(imageView.IsResourceReady(), false, TEST_LOCATION);
2888
2889     application.GetScene().Add(imageView);
2890
2891     application.SendNotification();
2892
2893     // loading started, this waits for the loader thread - load & rasterize
2894     DALI_TEST_EQUALS(Test::WaitForEventThreadTrigger(1), true, TEST_LOCATION);
2895
2896     application.SendNotification();
2897     application.Render(16);
2898
2899     DALI_TEST_EQUALS(gResourceReadySignalFired, true, TEST_LOCATION);
2900     DALI_TEST_EQUALS(imageView.IsResourceReady(), true, TEST_LOCATION);
2901     DALI_TEST_EQUALS(imageView.GetVisualResourceStatus(ImageView::Property::IMAGE), Visual::ResourceStatus::FAILED, TEST_LOCATION);
2902
2903     // Should be shown a broken image
2904     DALI_TEST_EQUALS(imageView.GetRendererCount(), 1u, TEST_LOCATION);
2905     DALI_TEST_EQUALS(textureTrace.FindMethod("BindTexture"), true, TEST_LOCATION);
2906   }
2907
2908   // Local svg file - invalid file
2909   {
2910     ToolkitTestApplication application;
2911
2912     TestGlAbstraction& gl           = application.GetGlAbstraction();
2913     TraceCallStack&    textureTrace = gl.GetTextureTrace();
2914     textureTrace.Enable(true);
2915
2916     gResourceReadySignalFired = false;
2917     textureTrace.Reset();
2918
2919     ImageView imageView = ImageView::New(TEST_RESOURCE_DIR "/invalid.svg");
2920     imageView.SetProperty(Actor::Property::SIZE, Vector2(200.f, 200.f));
2921     imageView.ResourceReadySignal().Connect(&ResourceReadySignal);
2922
2923     DALI_TEST_EQUALS(imageView.IsResourceReady(), false, TEST_LOCATION);
2924
2925     application.GetScene().Add(imageView);
2926
2927     application.SendNotification();
2928
2929     // loading started, this waits for the loader thread - load & rasterize
2930     DALI_TEST_EQUALS(Test::WaitForEventThreadTrigger(1), true, TEST_LOCATION);
2931
2932     application.SendNotification();
2933     application.Render(16);
2934
2935     DALI_TEST_EQUALS(gResourceReadySignalFired, true, TEST_LOCATION);
2936     DALI_TEST_EQUALS(imageView.IsResourceReady(), true, TEST_LOCATION);
2937     DALI_TEST_EQUALS(imageView.GetVisualResourceStatus(ImageView::Property::IMAGE), Visual::ResourceStatus::FAILED, TEST_LOCATION);
2938
2939     // Should be shown a broken image
2940     DALI_TEST_EQUALS(imageView.GetRendererCount(), 1u, TEST_LOCATION);
2941     DALI_TEST_EQUALS(textureTrace.FindMethod("BindTexture"), true, TEST_LOCATION);
2942   }
2943
2944   // Remote svg file
2945   {
2946     ToolkitTestApplication application;
2947
2948     TestGlAbstraction& gl           = application.GetGlAbstraction();
2949     TraceCallStack&    textureTrace = gl.GetTextureTrace();
2950     textureTrace.Enable(true);
2951
2952     gResourceReadySignalFired = false;
2953     textureTrace.Reset();
2954
2955     ImageView imageView = ImageView::New("https://bar.org/foobar.svg");
2956     imageView.SetProperty(Actor::Property::SIZE, Vector2(200.f, 200.f));
2957     imageView.ResourceReadySignal().Connect(&ResourceReadySignal);
2958
2959     DALI_TEST_EQUALS(imageView.IsResourceReady(), false, TEST_LOCATION);
2960
2961     application.GetScene().Add(imageView);
2962
2963     application.SendNotification();
2964
2965     // loading started, this waits for the loader thread - load & rasterize
2966     DALI_TEST_EQUALS(Test::WaitForEventThreadTrigger(1), true, TEST_LOCATION);
2967
2968     application.SendNotification();
2969     application.Render(16);
2970
2971     DALI_TEST_EQUALS(gResourceReadySignalFired, true, TEST_LOCATION);
2972     DALI_TEST_EQUALS(imageView.IsResourceReady(), true, TEST_LOCATION);
2973     DALI_TEST_EQUALS(imageView.GetVisualResourceStatus(ImageView::Property::IMAGE), Visual::ResourceStatus::FAILED, TEST_LOCATION);
2974
2975     // Should be shown a broken image
2976     DALI_TEST_EQUALS(imageView.GetRendererCount(), 1u, TEST_LOCATION);
2977     DALI_TEST_EQUALS(textureTrace.FindMethod("BindTexture"), true, TEST_LOCATION);
2978   }
2979
2980   // Remote svg file without size set
2981   {
2982     ToolkitTestApplication application;
2983
2984     TestGlAbstraction& gl           = application.GetGlAbstraction();
2985     TraceCallStack&    textureTrace = gl.GetTextureTrace();
2986     textureTrace.Enable(true);
2987
2988     gResourceReadySignalFired = false;
2989     textureTrace.Reset();
2990
2991     ImageView imageView = ImageView::New("https://bar.org/foobar.svg");
2992     imageView.ResourceReadySignal().Connect(&ResourceReadySignal);
2993
2994     DALI_TEST_EQUALS(imageView.IsResourceReady(), false, TEST_LOCATION);
2995
2996     application.GetScene().Add(imageView);
2997
2998     application.SendNotification();
2999
3000     // loading started, this waits for the loader thread - load & rasterize
3001     DALI_TEST_EQUALS(Test::WaitForEventThreadTrigger(1), true, TEST_LOCATION);
3002
3003     application.SendNotification();
3004     application.Render(16);
3005
3006     DALI_TEST_EQUALS(gResourceReadySignalFired, true, TEST_LOCATION);
3007     DALI_TEST_EQUALS(imageView.IsResourceReady(), true, TEST_LOCATION);
3008     DALI_TEST_EQUALS(imageView.GetVisualResourceStatus(ImageView::Property::IMAGE), Visual::ResourceStatus::FAILED, TEST_LOCATION);
3009
3010     // Should be shown a broken image
3011     DALI_TEST_EQUALS(imageView.GetRendererCount(), 1u, TEST_LOCATION);
3012     DALI_TEST_EQUALS(textureTrace.FindMethod("BindTexture"), true, TEST_LOCATION);
3013   }
3014
3015   END_TEST;
3016 }
3017
3018 int UtcDaliImageViewSvgRasterizationFailure(void)
3019 {
3020   ToolkitTestApplication application;
3021
3022   gResourceReadySignalFired = false;
3023
3024   TestGlAbstraction& gl           = application.GetGlAbstraction();
3025   TraceCallStack&    textureTrace = gl.GetTextureTrace();
3026   textureTrace.Enable(true);
3027
3028   ImageView imageView = ImageView::New(TEST_RESOURCE_DIR "/invalid1.svg");
3029   imageView.SetProperty(Actor::Property::SIZE, Vector2(200.f, 200.f));
3030   imageView.ResourceReadySignal().Connect(&ResourceReadySignal);
3031
3032   DALI_TEST_EQUALS(imageView.IsResourceReady(), false, TEST_LOCATION);
3033
3034   application.GetScene().Add(imageView);
3035
3036   application.SendNotification();
3037
3038   // Wait for loading & rasterization
3039   DALI_TEST_EQUALS(Test::WaitForEventThreadTrigger(2), true, TEST_LOCATION);
3040
3041   application.SendNotification();
3042   application.Render(16);
3043
3044   DALI_TEST_EQUALS(gResourceReadySignalFired, true, TEST_LOCATION);
3045   DALI_TEST_EQUALS(imageView.IsResourceReady(), true, TEST_LOCATION);
3046   DALI_TEST_EQUALS(imageView.GetVisualResourceStatus(ImageView::Property::IMAGE), Visual::ResourceStatus::FAILED, TEST_LOCATION);
3047
3048   // Should be shown a broken image
3049   DALI_TEST_EQUALS(imageView.GetRendererCount(), 1u, TEST_LOCATION);
3050   DALI_TEST_EQUALS(textureTrace.FindMethod("BindTexture"), true, TEST_LOCATION);
3051
3052   END_TEST;
3053 }
3054
3055 int UtcDaliImageViewSvgChageSize(void)
3056 {
3057   ToolkitTestApplication application;
3058
3059   TestGlAbstraction& gl           = application.GetGlAbstraction();
3060   TraceCallStack&    textureTrace = gl.GetTextureTrace();
3061   textureTrace.Enable(true);
3062
3063   ImageView imageView = ImageView::New(TEST_SVG_FILE_NAME);
3064   application.GetScene().Add(imageView);
3065
3066   application.SendNotification();
3067
3068   // Wait for loading & rasterization
3069   DALI_TEST_EQUALS(Test::WaitForEventThreadTrigger(2), true, TEST_LOCATION);
3070
3071   application.SendNotification();
3072   application.Render(16);
3073
3074   DALI_TEST_EQUALS(Test::VectorImageRenderer::GetLoadCount(), 1, TEST_LOCATION);
3075
3076   // Change actor size, then rasterization should be done again
3077   imageView.SetProperty(Actor::Property::SIZE, Vector2(200.f, 200.f));
3078
3079   application.SendNotification();
3080
3081   // Wait for rasterization
3082   DALI_TEST_EQUALS(Test::WaitForEventThreadTrigger(1), true, TEST_LOCATION);
3083
3084   application.SendNotification();
3085   application.Render(16);
3086
3087   // We should not load the file again.
3088   DALI_TEST_EQUALS(Test::VectorImageRenderer::GetLoadCount(), 1, TEST_LOCATION);
3089
3090   END_TEST;
3091 }
3092
3093 int UtcDaliImageViewSvgAtlasing(void)
3094 {
3095   ToolkitTestApplication application;
3096
3097   TraceCallStack& callStack = application.GetGlAbstraction().GetTextureTrace();
3098   callStack.Reset();
3099   callStack.Enable(true);
3100
3101   Property::Map propertyMap;
3102   propertyMap["url"]      = TEST_SVG_FILE_NAME;
3103   propertyMap["atlasing"] = true;
3104
3105   ImageView imageView = ImageView::New();
3106   imageView.SetProperty(ImageView::Property::IMAGE, propertyMap);
3107   imageView.SetProperty(Actor::Property::SIZE, Vector2(100.f, 100.f));
3108   application.GetScene().Add(imageView);
3109
3110   application.SendNotification();
3111
3112   // Wait for loading & rasterization
3113   DALI_TEST_EQUALS(Test::WaitForEventThreadTrigger(2), true, TEST_LOCATION);
3114
3115   application.SendNotification();
3116   application.Render(16);
3117
3118   // use atlas
3119   TraceCallStack::NamedParams params1;
3120   params1["width"] << 100;
3121   params1["height"] << 100;
3122   DALI_TEST_EQUALS(callStack.FindMethodAndParams("TexSubImage2D", params1), true, TEST_LOCATION);
3123
3124   imageView.SetProperty(Actor::Property::SIZE, Vector2(600.f, 600.f));
3125
3126   application.SendNotification();
3127
3128   // Wait for rasterization
3129   DALI_TEST_EQUALS(Test::WaitForEventThreadTrigger(1), true, TEST_LOCATION);
3130
3131   callStack.Reset();
3132
3133   application.SendNotification();
3134   application.Render(16);
3135
3136   // not use atlas
3137   TraceCallStack::NamedParams params2;
3138   params2["width"] << 600;
3139   params2["height"] << 600;
3140   DALI_TEST_EQUALS(callStack.FindMethodAndParams("TexImage2D", params2), true, TEST_LOCATION);
3141
3142   END_TEST;
3143 }
3144
3145 int UtcDaliImageViewTVGLoading(void)
3146 {
3147   ToolkitTestApplication application;
3148
3149   tet_infoline("ImageView Testing TVG image loading");
3150
3151   {
3152     ImageView imageView = ImageView::New(TEST_RESOURCE_DIR "/test.tvg");
3153     application.GetScene().Add(imageView);
3154     DALI_TEST_CHECK(imageView);
3155
3156     application.SendNotification();
3157
3158     DALI_TEST_EQUALS(Test::WaitForEventThreadTrigger(1), true, TEST_LOCATION);
3159
3160     application.SendNotification();
3161     application.Render(16);
3162
3163     Vector3 naturalSize = imageView.GetNaturalSize();
3164
3165     DALI_TEST_EQUALS(naturalSize.width, 100.0f, TEST_LOCATION);
3166     DALI_TEST_EQUALS(naturalSize.height, 100.0f, TEST_LOCATION);
3167   }
3168   END_TEST;
3169 }
3170
3171 int UtcDaliImageViewImageLoadFailure01(void)
3172 {
3173   ToolkitTestApplication application;
3174
3175   Toolkit::StyleManager styleManager = Toolkit::StyleManager::Get();
3176   DevelStyleManager::SetBrokenImageUrl(styleManager, DevelStyleManager::BrokenImageType::SMALL, TEST_BROKEN_IMAGE_S);
3177   DevelStyleManager::SetBrokenImageUrl(styleManager, DevelStyleManager::BrokenImageType::NORMAL, TEST_BROKEN_IMAGE_M);
3178   DevelStyleManager::SetBrokenImageUrl(styleManager, DevelStyleManager::BrokenImageType::LARGE, TEST_BROKEN_IMAGE_L);
3179
3180   std::string brokenUrl;
3181   brokenUrl = DevelStyleManager::GetBrokenImageUrl(styleManager, DevelStyleManager::BrokenImageType::SMALL);
3182   DALI_TEST_EQUALS(TEST_BROKEN_IMAGE_S, brokenUrl, TEST_LOCATION);
3183
3184   brokenUrl = DevelStyleManager::GetBrokenImageUrl(styleManager, DevelStyleManager::BrokenImageType::NORMAL);
3185   DALI_TEST_EQUALS(TEST_BROKEN_IMAGE_M, brokenUrl, TEST_LOCATION);
3186
3187   brokenUrl = DevelStyleManager::GetBrokenImageUrl(styleManager, DevelStyleManager::BrokenImageType::LARGE);
3188   DALI_TEST_EQUALS(TEST_BROKEN_IMAGE_L, brokenUrl, TEST_LOCATION);
3189
3190   ImageView imageView = ImageView::New("invalidUrl.png");
3191   imageView.SetProperty(Actor::Property::SIZE, Vector2(200.f, 200.f));
3192
3193   application.GetScene().Add(imageView);
3194   application.SendNotification();
3195   application.Render(16);
3196
3197   // loading started, this waits for the loader thread
3198   DALI_TEST_EQUALS(Test::WaitForEventThreadTrigger(1), true, TEST_LOCATION);
3199
3200   END_TEST;
3201 }
3202
3203 int UtcDaliImageViewImageLoadFailure02(void)
3204 {
3205   ToolkitTestApplication application;
3206
3207   Toolkit::StyleManager styleManager = Toolkit::StyleManager::Get();
3208   DevelStyleManager::SetBrokenImageUrl(styleManager, DevelStyleManager::BrokenImageType::SMALL, TEST_BROKEN_IMAGE_DEFAULT);
3209   DevelStyleManager::SetBrokenImageUrl(styleManager, DevelStyleManager::BrokenImageType::NORMAL, TEST_BROKEN_IMAGE_M);
3210   DevelStyleManager::SetBrokenImageUrl(styleManager, DevelStyleManager::BrokenImageType::LARGE, TEST_BROKEN_IMAGE_L);
3211
3212   std::string brokenUrl;
3213   brokenUrl = DevelStyleManager::GetBrokenImageUrl(styleManager, DevelStyleManager::BrokenImageType::SMALL);
3214   DALI_TEST_EQUALS(TEST_BROKEN_IMAGE_DEFAULT, brokenUrl, TEST_LOCATION);
3215
3216   brokenUrl = DevelStyleManager::GetBrokenImageUrl(styleManager, DevelStyleManager::BrokenImageType::NORMAL);
3217   DALI_TEST_EQUALS(TEST_BROKEN_IMAGE_M, brokenUrl, TEST_LOCATION);
3218
3219   brokenUrl = DevelStyleManager::GetBrokenImageUrl(styleManager, DevelStyleManager::BrokenImageType::LARGE);
3220   DALI_TEST_EQUALS(TEST_BROKEN_IMAGE_L, brokenUrl, TEST_LOCATION);
3221
3222   ImageView imageView = ImageView::New("invalidUrl.png");
3223   imageView.SetProperty(Actor::Property::SIZE, Vector2(30.f, 30.f));
3224   application.GetScene().Add(imageView);
3225   application.SendNotification();
3226   application.Render(16);
3227
3228   // loading started, this waits for the loader thread
3229   DALI_TEST_EQUALS(Test::WaitForEventThreadTrigger(1), true, TEST_LOCATION);
3230
3231   END_TEST;
3232 }
3233
3234 int UtcDaliImageViewImageLoadFailure03(void)
3235 {
3236   ToolkitTestApplication application;
3237
3238   Toolkit::StyleManager styleManager = Toolkit::StyleManager::Get();
3239   DevelStyleManager::SetBrokenImageUrl(styleManager, DevelStyleManager::BrokenImageType::SMALL, TEST_BROKEN_IMAGE_01);
3240   DevelStyleManager::SetBrokenImageUrl(styleManager, DevelStyleManager::BrokenImageType::NORMAL, TEST_BROKEN_IMAGE_02);
3241
3242   std::string brokenUrl;
3243   brokenUrl = DevelStyleManager::GetBrokenImageUrl(styleManager, DevelStyleManager::BrokenImageType::SMALL);
3244   DALI_TEST_EQUALS(TEST_BROKEN_IMAGE_01, brokenUrl, TEST_LOCATION);
3245
3246   brokenUrl = DevelStyleManager::GetBrokenImageUrl(styleManager, DevelStyleManager::BrokenImageType::NORMAL);
3247   DALI_TEST_EQUALS(TEST_BROKEN_IMAGE_02, brokenUrl, TEST_LOCATION);
3248
3249   ImageView imageView = ImageView::New("invalidUrl.png");
3250   imageView.SetProperty(Actor::Property::SIZE, Vector2(100.f, 100.f));
3251   application.GetScene().Add(imageView);
3252   application.SendNotification();
3253   application.Render(16);
3254
3255   // loading started, this waits for the loader thread
3256   DALI_TEST_EQUALS(Test::WaitForEventThreadTrigger(1), true, TEST_LOCATION);
3257
3258   END_TEST;
3259 }
3260
3261 int UtcDaliImageViewImageLoadFailure04(void)
3262 {
3263   ToolkitTestApplication application;
3264
3265   ImageView imageView = ImageView::New("invalidUrl.png");
3266   imageView.SetProperty(Actor::Property::SIZE, Vector2(100.f, 100.f));
3267   application.GetScene().Add(imageView);
3268   application.SendNotification();
3269   application.Render(16);
3270
3271   // loading started, this waits for the loader thread
3272   DALI_TEST_EQUALS(Test::WaitForEventThreadTrigger(1), true, TEST_LOCATION);
3273
3274   Toolkit::StyleManager styleManager = Toolkit::StyleManager::Get();
3275   DevelStyleManager::SetBrokenImageUrl(styleManager, DevelStyleManager::BrokenImageType::SMALL, TEST_BROKEN_IMAGE_S);
3276   DevelStyleManager::SetBrokenImageUrl(styleManager, DevelStyleManager::BrokenImageType::NORMAL, "invalidBroken.png");
3277   DevelStyleManager::SetBrokenImageUrl(styleManager, DevelStyleManager::BrokenImageType::LARGE, TEST_BROKEN_IMAGE_L);
3278
3279   ImageView imageView2 = ImageView::New("invalidUrl.png");
3280   imageView2.SetProperty(Actor::Property::SIZE, Vector2(100.f, 100.f));
3281   application.GetScene().Add(imageView2);
3282
3283   std::string brokenUrl;
3284   brokenUrl = DevelStyleManager::GetBrokenImageUrl(styleManager, DevelStyleManager::BrokenImageType::SMALL);
3285   DALI_TEST_EQUALS(TEST_BROKEN_IMAGE_S, brokenUrl, TEST_LOCATION);
3286
3287   brokenUrl = DevelStyleManager::GetBrokenImageUrl(styleManager, DevelStyleManager::BrokenImageType::LARGE);
3288   DALI_TEST_EQUALS(TEST_BROKEN_IMAGE_L, brokenUrl, TEST_LOCATION);
3289
3290   application.SendNotification();
3291   application.Render(16);
3292
3293   // loading started, this waits for the loader thread
3294   DALI_TEST_EQUALS(Test::WaitForEventThreadTrigger(1), true, TEST_LOCATION);
3295
3296   DevelStyleManager::SetBrokenImageUrl(styleManager, DevelStyleManager::BrokenImageType::NORMAL, "invalidBroken.9.png");
3297
3298   ImageView imageView3 = ImageView::New("invalidUrl.png");
3299   imageView3.SetProperty(Actor::Property::SIZE, Vector2(100.f, 100.f));
3300   application.GetScene().Add(imageView3);
3301
3302   application.SendNotification();
3303   application.Render(16);
3304
3305   // loading started, this waits for the loader thread
3306   DALI_TEST_EQUALS(Test::WaitForEventThreadTrigger(1), true, TEST_LOCATION);
3307
3308   END_TEST;
3309 }
3310
3311 namespace
3312 {
3313 static int gResourceReadySignalCounter = 0;
3314
3315 void OnResourceReadySignal01(Control control)
3316 {
3317   gResourceReadySignalCounter++;
3318
3319   if(control.GetVisualResourceStatus(ImageView::Property::IMAGE) == Visual::ResourceStatus::READY)
3320   {
3321     if(gResourceReadySignalCounter == 1)
3322     {
3323       // Set image twice
3324       // It makes the first new visual be deleted immediately
3325       ImageView::DownCast(control).SetImage(gImage_34_RGBA);
3326       ImageView::DownCast(control).SetImage(gImage_34_RGBA);
3327     }
3328   }
3329   else if(control.GetVisualResourceStatus(ImageView::Property::IMAGE) == Visual::ResourceStatus::FAILED)
3330   {
3331     // Make the resource ready immediately
3332     control[ImageView::Property::IMAGE] = gImage_600_RGB;
3333   }
3334 }
3335
3336 void OnResourceReadySignal02(Control control)
3337 {
3338   if(++gResourceReadySignalCounter == 1)
3339   {
3340     // It makes the first new visual be deleted immediately
3341     // The first image will not be loaded.
3342     control[ImageView::Property::IMAGE] = Property::Map().Add(ImageVisual::Property::URL, gImage_600_RGB).Add(ImageVisual::Property::RELEASE_POLICY, ImageVisual::ReleasePolicy::NEVER);
3343     control[ImageView::Property::IMAGE] = TEST_IMAGE_1;
3344   }
3345 }
3346
3347 ImageView gImageView1;
3348 ImageView gImageView2;
3349 ImageView gImageView3;
3350 ImageView gImageView4;
3351
3352 void OnResourceReadySignal03(Control control)
3353 {
3354   if(gResourceReadySignalCounter == 0)
3355   {
3356     // Queue loading
3357     // 1. Use cached image, then LoadComplete will be called right after OnResourceReadySignal03.
3358     gImageView2[ImageView::Property::IMAGE] = gImage_34_RGBA;
3359
3360     // 2. Load a new image
3361     gImageView3[ImageView::Property::IMAGE] = TEST_IMAGE_1;
3362
3363     // 3. Use the new image again
3364     gImageView1[ImageView::Property::IMAGE] = TEST_IMAGE_1;
3365     gImageView1.ResourceReadySignal().Connect(&OnResourceReadySignal03);
3366   }
3367   else if(gResourceReadySignalCounter == 1)
3368   {
3369     // This is called from TextureManager::ProcessQueuedTextures().
3370     gImageView1.Unparent();
3371     gImageView1.Reset();
3372   }
3373   gResourceReadySignalCounter++;
3374 }
3375
3376 void OnSimpleResourceReadySignal(Control control)
3377 {
3378   // simply increate counter
3379   gResourceReadySignalCounter++;
3380 }
3381
3382 int gResourceReadySignal04ComesOrder = 0;
3383
3384 void OnResourceReadySignal04(Control control)
3385 {
3386   gResourceReadySignalCounter++;
3387   tet_printf("rc %d\n", gResourceReadySignalCounter);
3388   if(gResourceReadySignalCounter == 1)
3389   {
3390     auto scene = gImageView1.GetParent();
3391
3392     // Request load something
3393     // We hope this request result is return later than gImageView2.
3394     gImageView3 = ImageView::New(TEST_IMAGE_1);
3395     gImageView3.ResourceReadySignal().Connect(&OnResourceReadySignal04);
3396     scene.Add(gImageView3);
3397     gImageView4 = ImageView::New(TEST_IMAGE_2);
3398     gImageView4.ResourceReadySignal().Connect(&OnResourceReadySignal04);
3399     scene.Add(gImageView4);
3400
3401     if(control == gImageView1)
3402     {
3403       gResourceReadySignal04ComesOrder = 1;
3404     }
3405     else
3406     {
3407       gResourceReadySignal04ComesOrder = 2;
3408     }
3409   }
3410   if(gResourceReadySignalCounter == 2)
3411   {
3412     if(gResourceReadySignal04ComesOrder == 1 && control == gImageView2)
3413     {
3414       // Scene off first one.
3415       gImageView1.Unparent();
3416
3417       // Scene off second one.
3418       gImageView2.Unparent();
3419     }
3420     else if(gResourceReadySignal04ComesOrder == 2 && control == gImageView1)
3421     {
3422       // Scene off first one.
3423       gImageView2.Unparent();
3424
3425       // Scene off second one.
3426       gImageView1.Unparent();
3427     }
3428     else
3429     {
3430       // We can't check that this utc fail case. just pass always when we come here.
3431       gResourceReadySignal04ComesOrder = -1;
3432     }
3433
3434     // If we don't seperate index of FreeList area
3435     // and if we don't queue remove during obversing,
3436     // cache index become something invalid data.
3437     // In this case, some strange observer can be called.
3438     // For example, gImageView4.LoadComplete will be called.
3439   }
3440 }
3441
3442 } // namespace
3443
3444 int UtcDaliImageViewSetImageOnResourceReadySignal01(void)
3445 {
3446   tet_infoline("Test setting image from within signal handler.");
3447
3448   ToolkitTestApplication application;
3449
3450   gResourceReadySignalCounter = 0;
3451
3452   ImageView imageView = ImageView::New(gImage_34_RGBA);
3453   imageView.ResourceReadySignal().Connect(&OnResourceReadySignal01);
3454
3455   application.GetScene().Add(imageView);
3456
3457   DALI_TEST_EQUALS(Test::WaitForEventThreadTrigger(1), true, TEST_LOCATION);
3458
3459   application.SendNotification();
3460   application.Render();
3461
3462   DALI_TEST_EQUALS(gResourceReadySignalCounter, 2, TEST_LOCATION);
3463
3464   DALI_TEST_EQUALS(imageView.IsResourceReady(), true, TEST_LOCATION);
3465
3466   // Create a new ImageView to cache the image
3467   ImageView imageView1 = ImageView::New(gImage_600_RGB);
3468   application.GetScene().Add(imageView1);
3469
3470   DALI_TEST_EQUALS(Test::WaitForEventThreadTrigger(1), true, TEST_LOCATION);
3471
3472   application.SendNotification();
3473   application.Render();
3474
3475   // Reset count
3476   gResourceReadySignalCounter = 0;
3477
3478   imageView[ImageView::Property::IMAGE] = "invalid.jpg";
3479
3480   DALI_TEST_EQUALS(Test::WaitForEventThreadTrigger(1), true, TEST_LOCATION);
3481
3482   application.SendNotification();
3483   application.Render();
3484
3485   // Run idle callback
3486   application.RunIdles();
3487
3488   DALI_TEST_EQUALS(gResourceReadySignalCounter, 2, TEST_LOCATION);
3489
3490   DALI_TEST_EQUALS(imageView.IsResourceReady(), true, TEST_LOCATION);
3491
3492   END_TEST;
3493 }
3494
3495 int UtcDaliImageViewSetImageOnResourceReadySignal02(void)
3496 {
3497   tet_infoline("Test setting image from within signal handler.");
3498
3499   ToolkitTestApplication application;
3500
3501   gResourceReadySignalCounter = 0;
3502
3503   ImageView imageView = ImageView::New(gImage_34_RGBA);
3504   imageView.ResourceReadySignal().Connect(&OnResourceReadySignal02);
3505
3506   application.GetScene().Add(imageView);
3507
3508   DALI_TEST_EQUALS(Test::WaitForEventThreadTrigger(1), true, TEST_LOCATION);
3509
3510   application.SendNotification();
3511   application.Render();
3512
3513   // Wait for loading an image
3514   DALI_TEST_EQUALS(Test::WaitForEventThreadTrigger(1), true, TEST_LOCATION);
3515
3516   DALI_TEST_EQUALS(gResourceReadySignalCounter, 2, TEST_LOCATION);
3517
3518   DALI_TEST_EQUALS(imageView.IsResourceReady(), true, TEST_LOCATION);
3519
3520   END_TEST;
3521 }
3522
3523 int UtcDaliImageViewSetImageOnResourceReadySignal03(void)
3524 {
3525   tet_infoline("Test setting image from within signal handler.");
3526
3527   ToolkitTestApplication application;
3528
3529   gResourceReadySignalCounter = 0;
3530
3531   gImageView1 = ImageView::New(gImage_34_RGBA);
3532   application.GetScene().Add(gImageView1);
3533
3534   // Wait for loading
3535   DALI_TEST_EQUALS(Test::WaitForEventThreadTrigger(1), true, TEST_LOCATION);
3536
3537   gImageView2 = ImageView::New(gImage_600_RGB);
3538   gImageView2.ResourceReadySignal().Connect(&OnResourceReadySignal03);
3539   application.GetScene().Add(gImageView2);
3540
3541   gImageView3 = ImageView::New();
3542   application.GetScene().Add(gImageView3);
3543
3544   DALI_TEST_EQUALS(Test::WaitForEventThreadTrigger(2), true, TEST_LOCATION);
3545
3546   application.SendNotification();
3547   application.Render();
3548
3549   END_TEST;
3550 }
3551
3552 int UtcDaliImageViewOnResourceReadySignalWithBrokenAlphaMask01(void)
3553 {
3554   tet_infoline("Test signal handler when image / mask image is broken.");
3555
3556   ToolkitTestApplication application;
3557
3558   auto TestResourceReadyUrl = [&application](int eventTriggerCount, bool isSynchronous, const std::string& url, const std::string& mask, const char* location) {
3559     gResourceReadySignalCounter = 0;
3560
3561     Property::Map map;
3562     map[Toolkit::ImageVisual::Property::URL] = url;
3563     if(!mask.empty())
3564     {
3565       map[Toolkit::ImageVisual::Property::ALPHA_MASK_URL] = mask;
3566     }
3567     map[Toolkit::ImageVisual::Property::SYNCHRONOUS_LOADING] = isSynchronous;
3568
3569     ImageView imageView                            = ImageView::New();
3570     imageView[Toolkit::ImageView::Property::IMAGE] = map;
3571     imageView[Actor::Property::SIZE]               = Vector2(100.0f, 200.0f);
3572     imageView.ResourceReadySignal().Connect(&OnSimpleResourceReadySignal);
3573
3574     application.GetScene().Add(imageView);
3575     application.SendNotification();
3576     application.Render();
3577
3578     if(!isSynchronous)
3579     {
3580       // Wait for loading
3581       DALI_TEST_EQUALS(Test::WaitForEventThreadTrigger(eventTriggerCount), true, location);
3582     }
3583     tet_printf("test %s [sync:%d] signal fired\n", url.c_str(), isSynchronous ? 1 : 0);
3584     DALI_TEST_EQUALS(gResourceReadySignalCounter, 1, location);
3585
3586     imageView.Unparent();
3587   };
3588
3589   for(int synchronous = 0; synchronous <= 1; synchronous++)
3590   {
3591     tet_printf("Test normal case (sync:%d)\n", synchronous);
3592     TestResourceReadyUrl(1, synchronous, gImage_600_RGB, "", TEST_LOCATION);
3593     TestResourceReadyUrl(3, synchronous, gImage_600_RGB, gImage_34_RGBA, TEST_LOCATION); // 3 event trigger required : 2 image load + 1 apply mask
3594
3595     tet_printf("Test broken image case (sync:%d)\n", synchronous);
3596     TestResourceReadyUrl(1, synchronous, "invalid.jpg", "", TEST_LOCATION);
3597     TestResourceReadyUrl(2, synchronous, "invalid.jpg", gImage_34_RGBA, TEST_LOCATION);
3598
3599     tet_printf("Test broken mask image case (sync:%d)\n", synchronous);
3600     TestResourceReadyUrl(2, synchronous, gImage_600_RGB, "invalid.png", TEST_LOCATION);
3601
3602     tet_printf("Test broken both image, mask image case (sync:%d)\n", synchronous);
3603     TestResourceReadyUrl(2, synchronous, "invalid.jpg", "invalid.png", TEST_LOCATION);
3604   }
3605
3606   END_TEST;
3607 }
3608
3609 int UtcDaliImageViewOnResourceReadySignalWithBrokenAlphaMask02(void)
3610 {
3611   tet_infoline("Test signal handler when image try to use cached-and-broken mask image.");
3612
3613   ToolkitTestApplication application;
3614
3615   gResourceReadySignalCounter = 0;
3616
3617   auto TestBrokenMaskResourceReadyUrl = [&application](const std::string& url, const char* location) {
3618     Property::Map map;
3619     map[Toolkit::ImageVisual::Property::URL] = url;
3620     // Use invalid mask url
3621     map[Toolkit::ImageVisual::Property::ALPHA_MASK_URL] = "invalid.png";
3622
3623     ImageView imageView                            = ImageView::New();
3624     imageView[Toolkit::ImageView::Property::IMAGE] = map;
3625     imageView[Actor::Property::SIZE]               = Vector2(100.0f, 200.0f);
3626     imageView.ResourceReadySignal().Connect(&OnSimpleResourceReadySignal);
3627
3628     application.GetScene().Add(imageView);
3629     application.SendNotification();
3630     application.Render();
3631
3632     // Don't unparent imageView, for keep the cache.
3633   };
3634
3635   // Use more than 4 images (The number of LocalImageLoadThread)
3636   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};
3637
3638   int expectResourceReadySignalCounter = 0;
3639
3640   for(auto& url : testUrlList)
3641   {
3642     TestBrokenMaskResourceReadyUrl(url, TEST_LOCATION);
3643     expectResourceReadySignalCounter++;
3644   }
3645
3646   // Remain 1 signal due to we use #URL + 1 mask image.
3647   DALI_TEST_EQUALS(Test::WaitForEventThreadTrigger(expectResourceReadySignalCounter + 1), true, TEST_LOCATION);
3648
3649   DALI_TEST_EQUALS(gResourceReadySignalCounter, expectResourceReadySignalCounter, TEST_LOCATION);
3650
3651   END_TEST;
3652 }
3653
3654 int UtcDaliImageViewCheckVariousCaseSendOnResourceReadySignal(void)
3655 {
3656   tet_infoline("Test signal handler various case.");
3657
3658   ToolkitTestApplication application;
3659
3660   auto TestResourceReadyUrl = [&application](int eventTriggerCount, bool isSynchronous, bool loadSuccess, const std::string& url, const std::string& mask, const char* location) {
3661     gResourceReadySignalCounter = 0;
3662
3663     Property::Map map;
3664     map[Toolkit::ImageVisual::Property::URL] = url;
3665     if(!mask.empty())
3666     {
3667       map[Toolkit::ImageVisual::Property::ALPHA_MASK_URL] = mask;
3668     }
3669     map[Toolkit::ImageVisual::Property::SYNCHRONOUS_LOADING] = isSynchronous;
3670
3671     ImageView imageView                            = ImageView::New();
3672     imageView[Toolkit::ImageView::Property::IMAGE] = map;
3673     imageView[Actor::Property::SIZE]               = Vector2(100.0f, 200.0f);
3674     imageView.ResourceReadySignal().Connect(&OnSimpleResourceReadySignal);
3675
3676     application.GetScene().Add(imageView);
3677     application.SendNotification();
3678     application.Render();
3679
3680     // Wait for loading
3681     DALI_TEST_EQUALS(Test::WaitForEventThreadTrigger(eventTriggerCount), true, location);
3682
3683     tet_printf("test %s [sync:%d] signal fired\n", url.c_str(), isSynchronous ? 1 : 0);
3684     DALI_TEST_EQUALS(gResourceReadySignalCounter, 1, location);
3685     DALI_TEST_EQUALS(imageView.GetVisualResourceStatus(Toolkit::ImageView::Property::IMAGE), loadSuccess ? Toolkit::Visual::ResourceStatus::READY : Toolkit::Visual::ResourceStatus::FAILED, TEST_LOCATION);
3686
3687     imageView.Unparent();
3688   };
3689
3690   auto TestAuxiliaryResourceReadyUrl = [&application](bool isSynchronous, bool loadSuccess, const std::string& url, const std::string& auxiliaryUrl, const char* location) {
3691     gResourceReadySignalCounter = 0;
3692
3693     Property::Map map;
3694     map[Toolkit::ImageVisual::Property::URL]                        = url;
3695     map[Toolkit::DevelImageVisual::Property::AUXILIARY_IMAGE]       = auxiliaryUrl;
3696     map[Toolkit::DevelImageVisual::Property::AUXILIARY_IMAGE_ALPHA] = 0.5f;
3697     map[Toolkit::ImageVisual::Property::SYNCHRONOUS_LOADING]        = isSynchronous;
3698
3699     ImageView imageView = ImageView::New();
3700     imageView.SetProperty(Toolkit::ImageView::Property::IMAGE, map);
3701     imageView.SetProperty(Actor::Property::SIZE, Vector2(100.0f, 200.0f));
3702     imageView.ResourceReadySignal().Connect(&OnSimpleResourceReadySignal);
3703     application.GetScene().Add(imageView);
3704
3705     application.SendNotification();
3706     application.Render();
3707
3708     if(!isSynchronous)
3709     {
3710       // Wait for loading
3711       DALI_TEST_EQUALS(Test::WaitForEventThreadTrigger(2), true, location);
3712     }
3713
3714     tet_printf("test %s [sync:%d] signal fired\n", url.c_str(), isSynchronous ? 1 : 0);
3715     DALI_TEST_EQUALS(gResourceReadySignalCounter, 1, location);
3716     DALI_TEST_EQUALS(imageView.GetVisualResourceStatus(Toolkit::ImageView::Property::IMAGE), loadSuccess ? Toolkit::Visual::ResourceStatus::READY : Toolkit::Visual::ResourceStatus::FAILED, TEST_LOCATION);
3717
3718     imageView.Unparent();
3719   };
3720
3721   // Case 1 : asynchronous loading
3722   tet_printf("Test invalid single simple image Asynchronous\n");
3723
3724   // Test normal case
3725   TestResourceReadyUrl(1, 0, 1, gImage_600_RGB, "", TEST_LOCATION);
3726   TestResourceReadyUrl(2, 0, 1, TEST_SVG_FILE_NAME, "", TEST_LOCATION); // load & rasterize
3727   TestResourceReadyUrl(1, 0, 1, TEST_BROKEN_IMAGE_L, "", TEST_LOCATION);
3728
3729   TestResourceReadyUrl(2, 0, 1, TEST_GIF_FILE_NAME, "", TEST_LOCATION);                   // 2 image loading - batch size
3730   TestResourceReadyUrl(1, 0, 1, TEST_ANIMATED_VECTOR_IMAGE_FILE_NAME, "", TEST_LOCATION); // 1 rasterize
3731
3732   TestResourceReadyUrl(3, 0, 1, gImage_600_RGB, gImage_34_RGBA, TEST_LOCATION); // 2 image loading + 1 applymask
3733
3734   TestAuxiliaryResourceReadyUrl(0, 1, TEST_BROKEN_IMAGE_L, gImage_34_RGBA, TEST_LOCATION);
3735
3736   // Test broken case
3737   TestResourceReadyUrl(1, 0, 0, "invalid.jpg", "", TEST_LOCATION);
3738   TestResourceReadyUrl(1, 0, 0, "invalid.svg", "", TEST_LOCATION);
3739   TestResourceReadyUrl(1, 0, 0, "invalid.9.png", "", TEST_LOCATION);
3740   TestResourceReadyUrl(1, 0, 0, "invalid.gif", "", TEST_LOCATION);  // 1 image loading
3741   TestResourceReadyUrl(0, 0, 0, "invalid.json", "", TEST_LOCATION); // 0 rasterize
3742
3743   TestResourceReadyUrl(2, 0, 0, "invalid.jpg", "invalid.png", TEST_LOCATION);  // 2 image loading
3744   TestResourceReadyUrl(2, 0, 1, gImage_600_RGB, "invalid.png", TEST_LOCATION); // 2 image loading
3745   TestResourceReadyUrl(2, 0, 0, "invalid.jpg", gImage_34_RGBA, TEST_LOCATION); // 2 image loading
3746
3747   TestAuxiliaryResourceReadyUrl(0, 0, "invalid.9.png", "invalid.png", TEST_LOCATION);
3748   TestAuxiliaryResourceReadyUrl(0, 1, TEST_BROKEN_IMAGE_L, "invalid.png", TEST_LOCATION);
3749   TestAuxiliaryResourceReadyUrl(0, 0, "invalid.9.png", gImage_34_RGBA, TEST_LOCATION);
3750
3751   // Case 2 : Synchronous loading
3752   tet_printf("Test invalid single simple image Synchronous\n");
3753
3754   // Test normal case
3755   TestResourceReadyUrl(0, 1, 1, gImage_600_RGB, "", TEST_LOCATION);
3756   TestResourceReadyUrl(0, 1, 1, TEST_SVG_FILE_NAME, "", TEST_LOCATION); // synchronous rasterize
3757   TestResourceReadyUrl(0, 1, 1, TEST_BROKEN_IMAGE_L, "", TEST_LOCATION);
3758
3759   TestResourceReadyUrl(1, 1, 1, TEST_GIF_FILE_NAME, "", TEST_LOCATION);                   // first frame image loading sync + second frame image loading async
3760   TestResourceReadyUrl(0, 1, 1, TEST_ANIMATED_VECTOR_IMAGE_FILE_NAME, "", TEST_LOCATION); // synchronous rasterize
3761
3762   TestResourceReadyUrl(0, 1, 1, gImage_600_RGB, gImage_34_RGBA, TEST_LOCATION);
3763
3764   TestAuxiliaryResourceReadyUrl(1, 1, TEST_BROKEN_IMAGE_L, gImage_34_RGBA, TEST_LOCATION);
3765
3766   // Test broken case
3767   TestResourceReadyUrl(0, 1, 0, "invalid.jpg", "", TEST_LOCATION);
3768   TestResourceReadyUrl(0, 1, 0, "invalid.svg", "", TEST_LOCATION);
3769   TestResourceReadyUrl(0, 1, 0, "invalid.9.png", "", TEST_LOCATION);
3770   TestResourceReadyUrl(0, 1, 0, "invalid.gif", "", TEST_LOCATION);
3771   TestResourceReadyUrl(0, 1, 0, "invalid.json", "", TEST_LOCATION); // 0 rasterize
3772
3773   TestResourceReadyUrl(0, 1, 0, "invalid.jpg", "invalid.png", TEST_LOCATION);
3774   TestResourceReadyUrl(0, 1, 1, gImage_600_RGB, "invalid.png", TEST_LOCATION);
3775   TestResourceReadyUrl(0, 1, 0, "invalid.jpg", gImage_34_RGBA, TEST_LOCATION);
3776
3777   TestAuxiliaryResourceReadyUrl(1, 0, "invalid.9.png", "invalid.png", TEST_LOCATION);
3778   TestAuxiliaryResourceReadyUrl(1, 1, TEST_BROKEN_IMAGE_L, "invalid.png", TEST_LOCATION);
3779   TestAuxiliaryResourceReadyUrl(1, 0, "invalid.9.png", gImage_34_RGBA, TEST_LOCATION);
3780
3781   END_TEST;
3782 }
3783
3784 int UtcDaliImageViewSetImageOnResourceReadySignal04(void)
3785 {
3786   tet_infoline("Test texturemanager's remove queue works well within signal handler.");
3787
3788   ToolkitTestApplication application;
3789
3790   gResourceReadySignalCounter      = 0;
3791   gResourceReadySignal04ComesOrder = 0;
3792
3793   gImageView1 = ImageView::New("invalid.jpg"); // request invalid image, to make loading failed fast.
3794   gImageView1.ResourceReadySignal().Connect(&OnResourceReadySignal04);
3795   application.GetScene().Add(gImageView1);
3796
3797   gImageView2 = ImageView::New("invalid.png"); // request invalid image, to make loading failed fast.
3798   gImageView2.ResourceReadySignal().Connect(&OnResourceReadySignal04);
3799   application.GetScene().Add(gImageView2);
3800
3801   application.SendNotification();
3802   application.Render();
3803
3804   tet_infoline("Try to load 2 invalid image");
3805
3806   DALI_TEST_EQUALS(Test::WaitForEventThreadTrigger(2), true, TEST_LOCATION);
3807   DALI_TEST_EQUALS(gResourceReadySignalCounter, 2, TEST_LOCATION);
3808
3809   tet_infoline("load done");
3810
3811   // We can test this UTC only if gImageView1 and gImageView2 loaded done.
3812   if(gResourceReadySignal04ComesOrder == -1)
3813   {
3814     tet_infoline("Bad news.. gImageView3 or gImageView4 loaded faster than others. just skip this UTC");
3815   }
3816   else
3817   {
3818     // gImageView3 and gImageView4 load must not be successed yet.
3819     DALI_TEST_EQUALS(gImageView3.GetRendererCount(), 0u, TEST_LOCATION);
3820     DALI_TEST_EQUALS(gImageView4.GetRendererCount(), 0u, TEST_LOCATION);
3821
3822     application.SendNotification();
3823     application.Render();
3824
3825     tet_infoline("Try to load 2 valid image");
3826
3827     DALI_TEST_EQUALS(Test::WaitForEventThreadTrigger(2), true, TEST_LOCATION);
3828     DALI_TEST_EQUALS(gResourceReadySignalCounter, 4, TEST_LOCATION);
3829
3830     tet_infoline("load done");
3831
3832     // gImageView3 and gImageView4 load must be successed now.
3833     DALI_TEST_EQUALS(gImageView3.GetRendererAt(0).GetTextures().GetTextureCount(), 1u, TEST_LOCATION);
3834     DALI_TEST_EQUALS(gImageView4.GetRendererAt(0).GetTextures().GetTextureCount(), 1u, TEST_LOCATION);
3835   }
3836
3837   END_TEST;
3838 }