251039354b01e123c9f8cb73bd2640f525286730
[platform/core/uifw/dali-toolkit.git] / automated-tests / src / dali-toolkit / utc-Dali-ImageView.cpp
1 /*
2  * Copyright (c) 2023 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 const char* TEST_INVALID_NPATCH_FILE_NAME_01 = "invalid1.9.png";
75
76 // resolution: 34*34, pixel format: RGBA8888
77 static const char* gImage_34_RGBA = TEST_RESOURCE_DIR "/icon-edit.png";
78 // resolution: 600*600, pixel format: RGB888
79 static const char* gImage_600_RGB = TEST_RESOURCE_DIR "/test-image-600.jpg";
80
81 // resolution: 50*50, frame count: 4, frame delay: 0.2 second for each frame
82 const char* TEST_GIF_FILE_NAME = TEST_RESOURCE_DIR "/anim.gif";
83
84 const char* TEST_SVG_FILE_NAME                   = TEST_RESOURCE_DIR "/svg1.svg";
85 const char* TEST_ANIMATED_VECTOR_IMAGE_FILE_NAME = TEST_RESOURCE_DIR "/insta_camera.json";
86 const char* TEST_WEBP_FILE_NAME                  = TEST_RESOURCE_DIR "/dali-logo.webp";
87
88 void TestUrl(ImageView imageView, const std::string url)
89 {
90   Property::Value value = imageView.GetProperty(imageView.GetPropertyIndex("image"));
91
92   std::string urlActual;
93   DALI_TEST_CHECK(value.Get(urlActual));
94   DALI_TEST_EQUALS(urlActual, url, TEST_LOCATION);
95 }
96
97 } // namespace
98
99 int UtcDaliImageViewNewP(void)
100 {
101   ToolkitTestApplication application;
102
103   ImageView imageView = ImageView::New();
104
105   DALI_TEST_CHECK(imageView);
106
107   END_TEST;
108 }
109
110 int UtcDaliImageViewNewUrlP(void)
111 {
112   ToolkitTestApplication application;
113
114   ImageView imageView = ImageView::New(TEST_IMAGE_FILE_NAME);
115   DALI_TEST_CHECK(imageView);
116
117   TestUrl(imageView, TEST_IMAGE_FILE_NAME);
118
119   END_TEST;
120 }
121
122 int UtcDaliImageViewConstructorP(void)
123 {
124   ToolkitTestApplication application;
125
126   ImageView imageView;
127
128   DALI_TEST_CHECK(!imageView);
129
130   END_TEST;
131 }
132
133 int UtcDaliImageViewCopyConstructorP(void)
134 {
135   ToolkitTestApplication application;
136
137   // Initialize an object, ref count == 1
138   ImageView imageView = ImageView::New();
139
140   ImageView copy(imageView);
141   DALI_TEST_CHECK(copy);
142
143   END_TEST;
144 }
145
146 int UtcDaliImageViewMoveConstructor(void)
147 {
148   ToolkitTestApplication application;
149
150   ImageView imageView = ImageView::New();
151   DALI_TEST_EQUALS(1, imageView.GetBaseObject().ReferenceCount(), TEST_LOCATION);
152   imageView.SetProperty(Actor::Property::SENSITIVE, false);
153   DALI_TEST_CHECK(false == imageView.GetProperty<bool>(Actor::Property::SENSITIVE));
154
155   ImageView moved = std::move(imageView);
156   DALI_TEST_CHECK(moved);
157   DALI_TEST_EQUALS(1, moved.GetBaseObject().ReferenceCount(), TEST_LOCATION);
158   DALI_TEST_CHECK(false == moved.GetProperty<bool>(Actor::Property::SENSITIVE));
159   DALI_TEST_CHECK(!imageView);
160
161   END_TEST;
162 }
163
164 int UtcDaliImageViewAssignmentOperatorP(void)
165 {
166   ToolkitTestApplication application;
167
168   ImageView imageView = ImageView::New();
169
170   ImageView copy(imageView);
171   DALI_TEST_CHECK(copy);
172   DALI_TEST_EQUALS(imageView, copy, TEST_LOCATION);
173
174   END_TEST;
175 }
176
177 int UtcDaliImageViewMoveAssignment(void)
178 {
179   ToolkitTestApplication application;
180
181   ImageView imageView = ImageView::New();
182   DALI_TEST_EQUALS(1, imageView.GetBaseObject().ReferenceCount(), TEST_LOCATION);
183   imageView.SetProperty(Actor::Property::SENSITIVE, false);
184   DALI_TEST_CHECK(false == imageView.GetProperty<bool>(Actor::Property::SENSITIVE));
185
186   ImageView moved;
187   moved = std::move(imageView);
188   DALI_TEST_CHECK(moved);
189   DALI_TEST_EQUALS(1, moved.GetBaseObject().ReferenceCount(), TEST_LOCATION);
190   DALI_TEST_CHECK(false == moved.GetProperty<bool>(Actor::Property::SENSITIVE));
191   DALI_TEST_CHECK(!imageView);
192
193   END_TEST;
194 }
195
196 int UtcDaliImageViewDownCastP(void)
197 {
198   ToolkitTestApplication application;
199
200   ImageView imageView = ImageView::New();
201
202   BaseHandle object(imageView);
203
204   ImageView imageView2 = ImageView::DownCast(object);
205   DALI_TEST_CHECK(imageView2);
206
207   ImageView imageView3 = DownCast<ImageView>(object);
208   DALI_TEST_CHECK(imageView3);
209
210   END_TEST;
211 }
212
213 int UtcDaliImageViewDownCastN(void)
214 {
215   ToolkitTestApplication application;
216
217   BaseHandle unInitializedObject;
218
219   ImageView imageView1 = ImageView::DownCast(unInitializedObject);
220   DALI_TEST_CHECK(!imageView1);
221
222   ImageView imageView2 = DownCast<ImageView>(unInitializedObject);
223   DALI_TEST_CHECK(!imageView2);
224
225   END_TEST;
226 }
227
228 int UtcDaliImageViewTypeRegistry(void)
229 {
230   ToolkitTestApplication application;
231
232   TypeRegistry typeRegistry = TypeRegistry::Get();
233   DALI_TEST_CHECK(typeRegistry);
234
235   TypeInfo typeInfo = typeRegistry.GetTypeInfo("ImageView");
236   DALI_TEST_CHECK(typeInfo);
237
238   BaseHandle handle = typeInfo.CreateInstance();
239   DALI_TEST_CHECK(handle);
240
241   ImageView imageView = ImageView::DownCast(handle);
242   DALI_TEST_CHECK(imageView);
243
244   END_TEST;
245 }
246
247 int UtcDaliImageViewSetGetProperty01(void)
248 {
249   ToolkitTestApplication application;
250
251   ImageView imageView = ImageView::New();
252
253   Property::Index idx = imageView.GetPropertyIndex("image");
254   DALI_TEST_EQUALS(idx, (Property::Index)ImageView::Property::IMAGE, TEST_LOCATION);
255
256   imageView.SetProperty(idx, TEST_IMAGE_FILE_NAME);
257   TestUrl(imageView, TEST_IMAGE_FILE_NAME);
258
259   END_TEST;
260 }
261
262 int UtcDaliImageViewPreMultipliedAlphaPng(void)
263 {
264   ToolkitTestApplication application;
265
266   // Set up trace debug
267   TestGlAbstraction& gl           = application.GetGlAbstraction();
268   TraceCallStack&    textureTrace = gl.GetTextureTrace();
269   textureTrace.Enable(true);
270
271   Property::Map imageMap;
272   imageMap[ImageVisual::Property::URL]            = gImage_34_RGBA;
273   imageMap[ImageVisual::Property::RELEASE_POLICY] = ImageVisual::ReleasePolicy::NEVER; // To keep the texture cache
274
275   ImageView imageView1 = ImageView::New();
276   imageView1.SetProperty(ImageView::Property::IMAGE, imageMap);
277
278   application.GetScene().Add(imageView1);
279
280   Property::Value value = imageView1.GetProperty(ImageView::Property::PRE_MULTIPLIED_ALPHA);
281   bool            enable;
282   DALI_TEST_CHECK(value.Get(enable));
283   DALI_TEST_CHECK(enable); // Default value is true
284
285   // loading started, this waits for the loader thread for max 30 seconds
286   DALI_TEST_EQUALS(Test::WaitForEventThreadTrigger(1), true, TEST_LOCATION);
287
288   application.SendNotification();
289   application.Render();
290
291   value = imageView1.GetProperty(ImageView::Property::PRE_MULTIPLIED_ALPHA);
292   DALI_TEST_CHECK(value.Get(enable));
293   DALI_TEST_CHECK(enable); // Keep true
294
295   // conventional alpha blending
296   Renderer renderer1 = imageView1.GetRendererAt(0);
297   value              = renderer1.GetProperty(Renderer::Property::BLEND_PRE_MULTIPLIED_ALPHA);
298   DALI_TEST_CHECK(value.Get(enable));
299   DALI_TEST_CHECK(enable);
300
301   int srcFactorRgb    = renderer1.GetProperty<int>(Renderer::Property::BLEND_FACTOR_SRC_RGB);
302   int destFactorRgb   = renderer1.GetProperty<int>(Renderer::Property::BLEND_FACTOR_DEST_RGB);
303   int srcFactorAlpha  = renderer1.GetProperty<int>(Renderer::Property::BLEND_FACTOR_SRC_ALPHA);
304   int destFactorAlpha = renderer1.GetProperty<int>(Renderer::Property::BLEND_FACTOR_DEST_ALPHA);
305   DALI_TEST_CHECK(srcFactorRgb == BlendFactor::ONE);
306   DALI_TEST_CHECK(destFactorRgb == BlendFactor::ONE_MINUS_SRC_ALPHA);
307   DALI_TEST_CHECK(srcFactorAlpha == BlendFactor::ONE);
308   DALI_TEST_CHECK(destFactorAlpha == BlendFactor::ONE_MINUS_SRC_ALPHA);
309
310   DALI_TEST_EQUALS(textureTrace.FindMethod("GenTextures"), true, TEST_LOCATION); // A new texture should be generated.
311   textureTrace.Reset();
312
313   // Disable pre-multiplied alpha blending
314   imageView1.SetProperty(ImageView::Property::PRE_MULTIPLIED_ALPHA, false);
315
316   // Reload the image
317   Property::Map attributes;
318   DevelControl::DoAction(imageView1, ImageView::Property::IMAGE, DevelImageVisual::Action::RELOAD, attributes);
319
320   // loading started, this waits for the loader thread for max 30 seconds
321   DALI_TEST_EQUALS(Test::WaitForEventThreadTrigger(1), true, TEST_LOCATION);
322
323   application.SendNotification();
324   application.Render();
325
326   value = imageView1.GetProperty(ImageView::Property::PRE_MULTIPLIED_ALPHA);
327   DALI_TEST_CHECK(value.Get(enable));
328   DALI_TEST_CHECK(!enable);
329
330   // conventional alpha blending
331   value = renderer1.GetProperty(Renderer::Property::BLEND_PRE_MULTIPLIED_ALPHA);
332   DALI_TEST_CHECK(value.Get(enable));
333   DALI_TEST_CHECK(!enable);
334
335   srcFactorRgb    = renderer1.GetProperty<int>(Renderer::Property::BLEND_FACTOR_SRC_RGB);
336   destFactorRgb   = renderer1.GetProperty<int>(Renderer::Property::BLEND_FACTOR_DEST_RGB);
337   srcFactorAlpha  = renderer1.GetProperty<int>(Renderer::Property::BLEND_FACTOR_SRC_ALPHA);
338   destFactorAlpha = renderer1.GetProperty<int>(Renderer::Property::BLEND_FACTOR_DEST_ALPHA);
339   DALI_TEST_CHECK(srcFactorRgb == BlendFactor::SRC_ALPHA);
340   DALI_TEST_CHECK(destFactorRgb == BlendFactor::ONE_MINUS_SRC_ALPHA);
341   DALI_TEST_CHECK(srcFactorAlpha == BlendFactor::ONE);
342   DALI_TEST_CHECK(destFactorAlpha == BlendFactor::ONE_MINUS_SRC_ALPHA);
343
344   DALI_TEST_EQUALS(textureTrace.FindMethod("GenTextures"), true, TEST_LOCATION); // A new texture should be generated.
345   textureTrace.Reset();
346
347   // Make a new ImageView using the same image
348   ImageView imageView2 = ImageView::New();
349   imageView2.SetProperty(ImageView::Property::IMAGE, imageMap);
350
351   application.GetScene().Add(imageView2);
352
353   application.SendNotification();
354   application.Render();
355
356   Renderer renderer2 = imageView2.GetRendererAt(0);
357   value              = renderer2.GetProperty(Renderer::Property::BLEND_PRE_MULTIPLIED_ALPHA);
358   DALI_TEST_CHECK(value.Get(enable));
359   DALI_TEST_CHECK(enable);
360
361   srcFactorRgb    = renderer2.GetProperty<int>(Renderer::Property::BLEND_FACTOR_SRC_RGB);
362   destFactorRgb   = renderer2.GetProperty<int>(Renderer::Property::BLEND_FACTOR_DEST_RGB);
363   srcFactorAlpha  = renderer2.GetProperty<int>(Renderer::Property::BLEND_FACTOR_SRC_ALPHA);
364   destFactorAlpha = renderer2.GetProperty<int>(Renderer::Property::BLEND_FACTOR_DEST_ALPHA);
365   DALI_TEST_CHECK(srcFactorRgb == BlendFactor::ONE);
366   DALI_TEST_CHECK(destFactorRgb == BlendFactor::ONE_MINUS_SRC_ALPHA);
367   DALI_TEST_CHECK(srcFactorAlpha == BlendFactor::ONE);
368   DALI_TEST_CHECK(destFactorAlpha == BlendFactor::ONE_MINUS_SRC_ALPHA);
369
370   DALI_TEST_EQUALS(textureTrace.FindMethod("GenTextures"), false, TEST_LOCATION); // The cached texture should be used.
371
372   END_TEST;
373 }
374
375 int UtcDaliImageViewPreMultipliedAlphaJpg(void)
376 {
377   ToolkitTestApplication application;
378
379   // Set up trace debug
380   TestGlAbstraction& gl           = application.GetGlAbstraction();
381   TraceCallStack&    textureTrace = gl.GetTextureTrace();
382   textureTrace.Enable(true);
383
384   Property::Map imageMap;
385   imageMap[ImageVisual::Property::URL]            = gImage_600_RGB;
386   imageMap[ImageVisual::Property::RELEASE_POLICY] = ImageVisual::ReleasePolicy::NEVER; // To keep the texture cache
387
388   ImageView imageView1 = ImageView::New();
389   imageView1.SetProperty(ImageView::Property::IMAGE, imageMap);
390
391   application.GetScene().Add(imageView1);
392
393   Property::Value value = imageView1.GetProperty(ImageView::Property::PRE_MULTIPLIED_ALPHA);
394   bool            enable;
395   DALI_TEST_CHECK(value.Get(enable));
396   DALI_TEST_CHECK(enable); // Default value is true
397
398   // loading started, this waits for the loader thread for max 30 seconds
399   DALI_TEST_EQUALS(Test::WaitForEventThreadTrigger(1), true, TEST_LOCATION);
400
401   application.SendNotification();
402   application.Render();
403
404   value = imageView1.GetProperty(ImageView::Property::PRE_MULTIPLIED_ALPHA);
405   DALI_TEST_CHECK(value.Get(enable));
406   DALI_TEST_CHECK(!enable); // Should be false after loading
407
408   // conventional alpha blending
409   Renderer renderer1 = imageView1.GetRendererAt(0);
410   value              = renderer1.GetProperty(Renderer::Property::BLEND_PRE_MULTIPLIED_ALPHA);
411   DALI_TEST_CHECK(value.Get(enable));
412   DALI_TEST_CHECK(!enable);
413
414   int srcFactorRgb    = renderer1.GetProperty<int>(Renderer::Property::BLEND_FACTOR_SRC_RGB);
415   int destFactorRgb   = renderer1.GetProperty<int>(Renderer::Property::BLEND_FACTOR_DEST_RGB);
416   int srcFactorAlpha  = renderer1.GetProperty<int>(Renderer::Property::BLEND_FACTOR_SRC_ALPHA);
417   int destFactorAlpha = renderer1.GetProperty<int>(Renderer::Property::BLEND_FACTOR_DEST_ALPHA);
418   DALI_TEST_CHECK(srcFactorRgb == BlendFactor::SRC_ALPHA);
419   DALI_TEST_CHECK(destFactorRgb == BlendFactor::ONE_MINUS_SRC_ALPHA);
420   DALI_TEST_CHECK(srcFactorAlpha == BlendFactor::ONE);
421   DALI_TEST_CHECK(destFactorAlpha == BlendFactor::ONE_MINUS_SRC_ALPHA);
422
423   DALI_TEST_EQUALS(textureTrace.FindMethod("GenTextures"), true, TEST_LOCATION); // A new texture should be generated.
424   textureTrace.Reset();
425
426   ImageView imageView2 = ImageView::New();
427   imageView2.SetProperty(ImageView::Property::IMAGE, imageMap);
428
429   // Disable pre-multiplied alpha blending
430   imageView2.SetProperty(ImageView::Property::PRE_MULTIPLIED_ALPHA, false);
431
432   application.GetScene().Add(imageView2);
433
434   application.SendNotification();
435   application.Render();
436
437   value = imageView2.GetProperty(ImageView::Property::PRE_MULTIPLIED_ALPHA);
438   DALI_TEST_CHECK(value.Get(enable));
439   DALI_TEST_CHECK(!enable);
440
441   // conventional alpha blending
442   Renderer renderer2 = imageView2.GetRendererAt(0);
443   value              = renderer2.GetProperty(Renderer::Property::BLEND_PRE_MULTIPLIED_ALPHA);
444   DALI_TEST_CHECK(value.Get(enable));
445   DALI_TEST_CHECK(!enable);
446
447   srcFactorRgb    = renderer2.GetProperty<int>(Renderer::Property::BLEND_FACTOR_SRC_RGB);
448   destFactorRgb   = renderer2.GetProperty<int>(Renderer::Property::BLEND_FACTOR_DEST_RGB);
449   srcFactorAlpha  = renderer2.GetProperty<int>(Renderer::Property::BLEND_FACTOR_SRC_ALPHA);
450   destFactorAlpha = renderer2.GetProperty<int>(Renderer::Property::BLEND_FACTOR_DEST_ALPHA);
451   DALI_TEST_CHECK(srcFactorRgb == BlendFactor::SRC_ALPHA);
452   DALI_TEST_CHECK(destFactorRgb == BlendFactor::ONE_MINUS_SRC_ALPHA);
453   DALI_TEST_CHECK(srcFactorAlpha == BlendFactor::ONE);
454   DALI_TEST_CHECK(destFactorAlpha == BlendFactor::ONE_MINUS_SRC_ALPHA);
455
456   DALI_TEST_EQUALS(textureTrace.FindMethod("GenTextures"), false, TEST_LOCATION); // The cached texture should be used.
457
458   END_TEST;
459 }
460
461 int UtcDaliImageViewPixelArea(void)
462 {
463   // Test pixel area property
464   ToolkitTestApplication application;
465
466   static std::vector<UniformData> customUniforms =
467     {
468       UniformData("pixelArea", Property::Type::VECTOR4),
469     };
470
471   TestGraphicsController& graphics = application.GetGraphicsController();
472   graphics.AddCustomUniforms(customUniforms);
473
474   // Gif image, use AnimatedImageVisual internally
475   // Atlasing is applied to pack multiple frames, use custom wrap mode
476   ImageView     gifView = ImageView::New();
477   const Vector4 pixelAreaVisual(0.f, 0.f, 2.f, 2.f);
478   gifView.SetProperty(ImageView::Property::IMAGE,
479                       Property::Map().Add(ImageVisual::Property::URL, TEST_GIF_FILE_NAME).Add(ImageVisual::Property::PIXEL_AREA, pixelAreaVisual));
480
481   // Add to stage
482   Integration::Scene stage = application.GetScene();
483   stage.Add(gifView);
484
485   // loading started
486   application.SendNotification();
487   application.Render(16);
488
489   DALI_TEST_EQUALS(Test::WaitForEventThreadTrigger(2), true, TEST_LOCATION);
490
491   application.SendNotification();
492   application.Render();
493   DALI_TEST_CHECK(gifView.GetRendererCount() == 1u);
494
495   const Vector4 fullTextureRect(0.f, 0.f, 1.f, 1.f);
496   // test that the pixel area value defined in the visual property map is registered on renderer
497   Renderer        renderer       = gifView.GetRendererAt(0);
498   Property::Value pixelAreaValue = renderer.GetProperty(renderer.GetPropertyIndex("pixelArea"));
499   DALI_TEST_EQUALS(pixelAreaValue.Get<Vector4>(), pixelAreaVisual, TEST_LOCATION);
500
501   // test that the shader has the default pixel area value registered.
502   Shader shader  = renderer.GetShader();
503   pixelAreaValue = shader.GetProperty(shader.GetPropertyIndex("pixelArea"));
504   DALI_TEST_EQUALS(pixelAreaValue.Get<Vector4>(), fullTextureRect, TEST_LOCATION);
505
506   // test that the uniform uses the pixelArea property on the renderer.
507   TestGlAbstraction& gl = application.GetGlAbstraction();
508   Vector4            pixelAreaUniform;
509   DALI_TEST_CHECK(gl.GetUniformValue<Vector4>("pixelArea", pixelAreaUniform));
510   DALI_TEST_EQUALS(pixelAreaVisual, pixelAreaUniform, Math::MACHINE_EPSILON_100, TEST_LOCATION);
511
512   // set the pixelArea property on the control
513   const Vector4 pixelAreaControl(-1.f, -1.f, 3.f, 3.f);
514   gifView.SetProperty(ImageView::Property::PIXEL_AREA, pixelAreaControl);
515   application.SendNotification();
516   application.Render(16);
517
518   // check the pixelArea property on the control
519   pixelAreaValue = gifView.GetProperty(gifView.GetPropertyIndex("pixelArea"));
520   DALI_TEST_EQUALS(pixelAreaValue.Get<Vector4>(), pixelAreaControl, TEST_LOCATION);
521   // test that the uniform uses the pixelArea property on the control.
522   DALI_TEST_CHECK(gl.GetUniformValue<Vector4>("pixelArea", pixelAreaUniform));
523   DALI_TEST_EQUALS(pixelAreaControl, pixelAreaUniform, Math::MACHINE_EPSILON_100, TEST_LOCATION);
524
525   END_TEST;
526 }
527
528 int UtcDaliImageViewAsyncLoadingWithoutAltasing(void)
529 {
530   ToolkitTestApplication     application;
531   TestGlAbstraction&         gl          = application.GetGlAbstraction();
532   const std::vector<GLuint>& textures    = gl.GetBoundTextures();
533   size_t                     numTextures = textures.size();
534
535   // Async loading, no atlasing for big size image
536   ImageView imageView = ImageView::New(gImage_600_RGB);
537
538   // By default, Aysnc loading is used
539   application.GetScene().Add(imageView);
540   imageView.SetProperty(Actor::Property::SIZE, Vector2(100, 100));
541   imageView.SetProperty(Actor::Property::PARENT_ORIGIN, ParentOrigin::CENTER);
542
543   DALI_TEST_EQUALS(Test::WaitForEventThreadTrigger(1), true, TEST_LOCATION);
544
545   application.SendNotification();
546   application.Render(16);
547   application.SendNotification();
548
549   const std::vector<GLuint>& textures2 = gl.GetBoundTextures();
550   DALI_TEST_GREATER(textures2.size(), numTextures, TEST_LOCATION);
551
552   END_TEST;
553 }
554
555 int UtcDaliImageViewAsyncLoadingWithAtlasing(void)
556 {
557   ToolkitTestApplication application;
558
559   //Async loading, automatic atlasing for small size image
560   TraceCallStack& callStack = application.GetGlAbstraction().GetTextureTrace();
561   callStack.Reset();
562   callStack.Enable(true);
563
564   Property::Map imageMap;
565
566   imageMap[ImageVisual::Property::URL]            = gImage_34_RGBA;
567   imageMap[ImageVisual::Property::DESIRED_HEIGHT] = 34;
568   imageMap[ImageVisual::Property::DESIRED_WIDTH]  = 34;
569   imageMap[ImageVisual::Property::ATLASING]       = true;
570
571   ImageView imageView = ImageView::New();
572   imageView.SetProperty(ImageView::Property::IMAGE, imageMap);
573   imageView.SetProperty(Toolkit::Control::Property::PADDING, Extents(10u, 10u, 10u, 10u));
574
575   // By default, Aysnc loading is used
576   // loading is not started if the actor is offScene
577
578   application.GetScene().Add(imageView);
579
580   imageView.SetProperty(Dali::Actor::Property::LAYOUT_DIRECTION, Dali::LayoutDirection::RIGHT_TO_LEFT);
581
582   // loading started, this waits for the loader thread for max 30 seconds
583   DALI_TEST_EQUALS(Test::WaitForEventThreadTrigger(1), true, TEST_LOCATION);
584
585   application.SendNotification();
586   application.Render(16);
587
588   callStack.Enable(false);
589
590   TraceCallStack::NamedParams params;
591   params["width"] << 34;
592   params["height"] << 34;
593   DALI_TEST_EQUALS(callStack.FindMethodAndParams("TexSubImage2D", params), true, TEST_LOCATION);
594
595   END_TEST;
596 }
597
598 int UtcDaliImageViewAsyncLoadingWithAtlasing02(void)
599 {
600   ToolkitTestApplication application;
601
602   //Async loading, automatic atlasing for small size image
603   TraceCallStack& callStack = application.GetGlAbstraction().GetTextureTrace();
604   callStack.Reset();
605   callStack.Enable(true);
606
607   Property::Map asyncLoadingMap;
608   asyncLoadingMap["url"]                = gImage_34_RGBA;
609   asyncLoadingMap["desiredHeight"]      = 34;
610   asyncLoadingMap["desiredWidth"]       = 34;
611   asyncLoadingMap["synchronousLoading"] = false;
612   asyncLoadingMap["atlasing"]           = true;
613
614   ImageView imageView = ImageView::New();
615   imageView.SetProperty(ImageView::Property::IMAGE, asyncLoadingMap);
616
617   application.GetScene().Add(imageView);
618
619   // loading started, this waits for the loader thread for max 30 seconds
620   DALI_TEST_EQUALS(Test::WaitForEventThreadTrigger(1), true, TEST_LOCATION);
621
622   application.SendNotification();
623   application.Render(16);
624
625   callStack.Enable(false);
626
627   TraceCallStack::NamedParams params;
628   params["width"] << 34;
629   params["height"] << 34;
630   DALI_TEST_EQUALS(callStack.FindMethodAndParams("TexSubImage2D", params), true, TEST_LOCATION);
631
632   END_TEST;
633 }
634
635 int UtcDaliImageViewSyncLoading(void)
636 {
637   ToolkitTestApplication application;
638
639   tet_infoline("ImageView Testing sync loading and size using index key property map");
640
641   Property::Map syncLoadingMap;
642   syncLoadingMap[ImageVisual::Property::SYNCHRONOUS_LOADING] = true;
643   syncLoadingMap[ImageVisual::Property::ATLASING]            = true;
644
645   // Sync loading, no atlasing for big size image
646   {
647     ImageView imageView = ImageView::New();
648
649     // Sync loading is used
650     syncLoadingMap[ImageVisual::Property::URL] = gImage_600_RGB;
651     imageView.SetProperty(ImageView::Property::IMAGE, syncLoadingMap);
652   }
653
654   // Sync loading, automatic atlasing for small size image
655   {
656     TraceCallStack& callStack = application.GetGlAbstraction().GetTextureTrace();
657     callStack.Reset();
658     callStack.Enable(true);
659
660     ImageView imageView = ImageView::New();
661
662     // Sync loading is used
663     syncLoadingMap[ImageVisual::Property::URL]            = gImage_34_RGBA;
664     syncLoadingMap[ImageVisual::Property::DESIRED_HEIGHT] = 34;
665     syncLoadingMap[ImageVisual::Property::DESIRED_WIDTH]  = 34;
666     imageView.SetProperty(ImageView::Property::IMAGE, syncLoadingMap);
667
668     application.GetScene().Add(imageView);
669     application.SendNotification();
670     application.Render(16);
671
672     TraceCallStack::NamedParams params;
673     params["width"] << 34;
674     params["height"] << 34;
675     DALI_TEST_EQUALS(callStack.FindMethodAndParams("TexSubImage2D", params),
676                      true,
677                      TEST_LOCATION);
678   }
679   END_TEST;
680 }
681
682 int UtcDaliImageViewSyncLoading02(void)
683 {
684   ToolkitTestApplication application;
685
686   tet_infoline("ImageView Testing sync loading and size using string key property map");
687
688   // Sync loading, automatic atlasing for small size image
689   {
690     TraceCallStack& callStack = application.GetGlAbstraction().GetTextureTrace();
691     callStack.Reset();
692     callStack.Enable(true);
693
694     ImageView imageView = ImageView::New();
695
696     // Sync loading is used
697     Property::Map syncLoadingMap;
698     syncLoadingMap["url"]                = gImage_34_RGBA;
699     syncLoadingMap["desiredHeight"]      = 34;
700     syncLoadingMap["desiredWidth"]       = 34;
701     syncLoadingMap["synchronousLoading"] = true;
702     syncLoadingMap["atlasing"]           = true;
703     imageView.SetProperty(ImageView::Property::IMAGE, syncLoadingMap);
704
705     application.GetScene().Add(imageView);
706     application.SendNotification();
707     application.Render(16);
708
709     TraceCallStack::NamedParams params;
710     params["width"] << 34;
711     params["height"] << 34;
712     DALI_TEST_EQUALS(callStack.FindMethodAndParams("TexSubImage2D", params),
713                      true,
714                      TEST_LOCATION);
715   }
716   END_TEST;
717 }
718
719 int UtcDaliImageViewAsyncLoadingEncodedBuffer(void)
720 {
721   ToolkitTestApplication     application;
722   TestGlAbstraction&         gl          = application.GetGlAbstraction();
723   const std::vector<GLuint>& textures    = gl.GetBoundTextures();
724   size_t                     numTextures = textures.size();
725
726   // Get encoded raw-buffer image and generate url
727   EncodedImageBuffer buffer = ConvertFileToEncodedImageBuffer(gImage_600_RGB);
728   ImageUrl           url    = Toolkit::Image::GenerateUrl(buffer);
729
730   // Async loading, no atlasing for big size image
731   ImageView imageView = ImageView::New(url.GetUrl());
732
733   // By default, Aysnc loading is used
734   application.GetScene().Add(imageView);
735   imageView.SetProperty(Actor::Property::SIZE, Vector2(100, 100));
736   imageView.SetProperty(Actor::Property::PARENT_ORIGIN, ParentOrigin::CENTER);
737
738   DALI_TEST_EQUALS(Test::WaitForEventThreadTrigger(1), true, TEST_LOCATION);
739
740   application.SendNotification();
741   application.Render(16);
742   application.SendNotification();
743
744   const std::vector<GLuint>& textures2 = gl.GetBoundTextures();
745   DALI_TEST_GREATER(textures2.size(), numTextures, TEST_LOCATION);
746
747   END_TEST;
748 }
749
750 int UtcDaliImageViewAsyncLoadingEncodedBufferWithAtlasing(void)
751 {
752   ToolkitTestApplication application;
753
754   // Get encoded raw-buffer image and generate url
755   EncodedImageBuffer buffer = ConvertFileToEncodedImageBuffer(gImage_600_RGB);
756   ImageUrl           url    = Toolkit::Image::GenerateUrl(buffer);
757   ImageUrl           url2   = Toolkit::Image::GenerateUrl(buffer);
758
759   // Generate url is not equal to url2
760   // NOTE : This behavior may changed when ImageUrl compare operator changed.
761   DALI_TEST_CHECK(url != url2);
762   // Generate url's string is equal to url2's string
763   DALI_TEST_CHECK(url.GetUrl() == url2.GetUrl());
764
765   EncodedImageBuffer buffer2 = ConvertFileToEncodedImageBuffer(gImage_600_RGB);
766   url2                       = Toolkit::Image::GenerateUrl(buffer2);
767
768   // Check whethere two url are not equal
769   DALI_TEST_CHECK(url.GetUrl() != url2.GetUrl());
770
771   // Async loading, automatic atlasing for small size image
772   TraceCallStack& callStack = application.GetGlAbstraction().GetTextureTrace();
773   callStack.Reset();
774   callStack.Enable(true);
775
776   Property::Map imageMap;
777
778   imageMap[ImageVisual::Property::URL]            = url.GetUrl();
779   imageMap[ImageVisual::Property::DESIRED_HEIGHT] = 600;
780   imageMap[ImageVisual::Property::DESIRED_WIDTH]  = 600;
781   imageMap[ImageVisual::Property::ATLASING]       = true;
782
783   // No atlasing with big image
784   ImageView imageView_bigdesired = ImageView::New();
785   imageView_bigdesired.SetProperty(ImageView::Property::IMAGE, imageMap);
786   imageView_bigdesired.SetProperty(Toolkit::Control::Property::PADDING, Extents(10u, 10u, 10u, 10u));
787
788   imageMap[ImageVisual::Property::DESIRED_HEIGHT] = 0;
789   imageMap[ImageVisual::Property::DESIRED_WIDTH]  = 0;
790
791   // No atlasing with zero desired size
792   ImageView imageView_nodesired = ImageView::New();
793   imageView_nodesired.SetProperty(ImageView::Property::IMAGE, imageMap);
794   imageView_nodesired.SetProperty(Toolkit::Control::Property::PADDING, Extents(10u, 10u, 10u, 10u));
795
796   imageMap[ImageVisual::Property::DESIRED_HEIGHT] = 34;
797   imageMap[ImageVisual::Property::DESIRED_WIDTH]  = 34;
798
799   ImageView imageView = ImageView::New();
800   imageView.SetProperty(ImageView::Property::IMAGE, imageMap);
801   imageView.SetProperty(Toolkit::Control::Property::PADDING, Extents(10u, 10u, 10u, 10u));
802
803   // By default, Aysnc loading is used
804   // loading is not started if the actor is offScene
805   application.GetScene().Add(imageView);
806   application.GetScene().Add(imageView_bigdesired);
807   application.GetScene().Add(imageView_nodesired);
808   application.SendNotification();
809   application.Render(16);
810
811   // loading started, this waits for the loader thread for max 30 seconds
812   DALI_TEST_EQUALS(Test::WaitForEventThreadTrigger(1), true, TEST_LOCATION);
813
814   application.Render(16);
815   application.SendNotification();
816
817   // Change url to url2
818   imageMap[ImageVisual::Property::URL] = url2.GetUrl();
819   imageView.SetProperty(ImageView::Property::IMAGE, imageMap);
820
821   imageView.SetProperty(Dali::Actor::Property::LAYOUT_DIRECTION, Dali::LayoutDirection::RIGHT_TO_LEFT);
822
823   // loading started, this waits for the loader thread for max 30 seconds
824   DALI_TEST_EQUALS(Test::WaitForEventThreadTrigger(1), true, TEST_LOCATION);
825
826   application.SendNotification();
827   application.Render(16);
828
829   callStack.Enable(false);
830
831   TraceCallStack::NamedParams params;
832   params["width"] << 34;
833   params["height"] << 34;
834   DALI_TEST_EQUALS(callStack.FindMethodAndParams("TexSubImage2D", params), true, TEST_LOCATION);
835
836   END_TEST;
837 }
838
839 int UtcDaliImageViewSyncLoadingEncodedBuffer(void)
840 {
841   ToolkitTestApplication application;
842
843   tet_infoline("ImageView Testing sync loading from EncodedImageBuffer");
844
845   // Get encoded raw-buffer image and generate url
846   EncodedImageBuffer buffer = ConvertFileToEncodedImageBuffer(gImage_34_RGBA);
847   ImageUrl           url    = Toolkit::Image::GenerateUrl(buffer);
848
849   // Sync loading, automatic atlasing for small size image
850   {
851     TraceCallStack& callStack = application.GetGlAbstraction().GetTextureTrace();
852     callStack.Reset();
853     callStack.Enable(true);
854
855     ImageView imageView = ImageView::New();
856
857     // Sync loading is used
858     Property::Map syncLoadingMap;
859     syncLoadingMap["url"]                = url.GetUrl();
860     syncLoadingMap["alphaMaskUrl"]       = gImage_34_RGBA;
861     syncLoadingMap["desiredHeight"]      = 34;
862     syncLoadingMap["desiredWidth"]       = 34;
863     syncLoadingMap["synchronousLoading"] = true;
864     syncLoadingMap["atlasing"]           = true;
865     imageView.SetProperty(ImageView::Property::IMAGE, syncLoadingMap);
866
867     application.GetScene().Add(imageView);
868     application.SendNotification();
869     application.Render(16);
870
871     TraceCallStack::NamedParams params;
872     params["width"] << 34;
873     params["height"] << 34;
874     DALI_TEST_EQUALS(callStack.FindMethodAndParams("TexSubImage2D", params),
875                      true,
876                      TEST_LOCATION);
877   }
878
879   END_TEST;
880 }
881
882 int UtcDaliImageViewEncodedBufferWithSvg(void)
883 {
884   ToolkitTestApplication     application;
885   TestGlAbstraction&         gl          = application.GetGlAbstraction();
886   const std::vector<GLuint>& textures    = gl.GetBoundTextures();
887   size_t                     numTextures = textures.size();
888
889   // Get encoded raw-buffer svg image and generate url
890   EncodedImageBuffer buffer = ConvertFileToEncodedImageBuffer(TEST_SVG_FILE_NAME, EncodedImageBuffer::ImageType::VECTOR_IMAGE);
891   ImageUrl           url    = Toolkit::Image::GenerateUrl(buffer);
892
893   // Async loading, no atlasing for big size image
894   ImageView imageView = ImageView::New(url.GetUrl());
895
896   // By default, Aysnc loading is used
897   application.GetScene().Add(imageView);
898   imageView.SetProperty(Actor::Property::SIZE, Vector2(100, 100));
899   imageView.SetProperty(Actor::Property::PARENT_ORIGIN, ParentOrigin::CENTER);
900
901   application.SendNotification();
902   application.Render(16);
903
904   // Load svg image + rasterize.
905   DALI_TEST_EQUALS(Test::WaitForEventThreadTrigger(2), true, TEST_LOCATION);
906
907   application.SendNotification();
908   application.Render(16);
909   application.SendNotification();
910
911   const std::vector<GLuint>& textures2 = gl.GetBoundTextures();
912   DALI_TEST_GREATER(textures2.size(), numTextures, TEST_LOCATION);
913
914   // Remove visual, for line coverage.
915   imageView.Unparent();
916   application.SendNotification();
917   application.Render(16);
918
919   END_TEST;
920 }
921
922 int UtcDaliImageViewEncodedBufferWithAnimatedVectorImage(void)
923 {
924   ToolkitTestApplication     application;
925   TestGlAbstraction&         gl          = application.GetGlAbstraction();
926   const std::vector<GLuint>& textures    = gl.GetBoundTextures();
927   size_t                     numTextures = textures.size();
928
929   // Get encoded raw-buffer lottie image and generate url
930   EncodedImageBuffer buffer = ConvertFileToEncodedImageBuffer(TEST_ANIMATED_VECTOR_IMAGE_FILE_NAME, EncodedImageBuffer::ImageType::ANIMATED_VECTOR_IMAGE);
931   ImageUrl           url    = Toolkit::Image::GenerateUrl(buffer);
932
933   // Async loading, no atlasing for big size image
934   ImageView imageView = ImageView::New(url.GetUrl());
935
936   // By default, Aysnc loading is used
937   application.GetScene().Add(imageView);
938   imageView.SetProperty(Actor::Property::SIZE, Vector2(100, 100));
939   imageView.SetProperty(Actor::Property::PARENT_ORIGIN, ParentOrigin::CENTER);
940
941   application.SendNotification();
942   application.Render(16);
943
944   // Load lottie image is sync. Only wait rasterize.
945   DALI_TEST_EQUALS(Test::WaitForEventThreadTrigger(1), true, TEST_LOCATION);
946
947   application.SendNotification();
948   application.Render(16);
949   application.SendNotification();
950
951   const std::vector<GLuint>& textures2 = gl.GetBoundTextures();
952   DALI_TEST_GREATER(textures2.size(), numTextures, TEST_LOCATION);
953
954   // Remove visual, for line coverage.
955   imageView.Unparent();
956   application.SendNotification();
957   application.Render(16);
958
959   END_TEST;
960 }
961
962 int UtcDaliImageViewEncodedBufferWithInvalidImageType(void)
963 {
964   ToolkitTestApplication     application;
965   TestGlAbstraction&         gl          = application.GetGlAbstraction();
966   const std::vector<GLuint>& textures    = gl.GetBoundTextures();
967   size_t                     numTextures = textures.size();
968
969   // Get encoded raw-buffer jpg image with invalid image type, and generate url
970   EncodedImageBuffer buffer = ConvertFileToEncodedImageBuffer(gImage_34_RGBA, static_cast<EncodedImageBuffer::ImageType>(-1));
971   ImageUrl           url    = Toolkit::Image::GenerateUrl(buffer);
972
973   // Async loading, no atlasing for big size image
974   ImageView imageView = ImageView::New(url.GetUrl());
975
976   // By default, Aysnc loading is used
977   application.GetScene().Add(imageView);
978   imageView.SetProperty(Actor::Property::SIZE, Vector2(100, 100));
979   imageView.SetProperty(Actor::Property::PARENT_ORIGIN, ParentOrigin::CENTER);
980
981   application.SendNotification();
982   application.Render(16);
983
984   // Load image
985   DALI_TEST_EQUALS(Test::WaitForEventThreadTrigger(1), true, TEST_LOCATION);
986
987   application.SendNotification();
988   application.Render(16);
989   application.SendNotification();
990
991   const std::vector<GLuint>& textures2 = gl.GetBoundTextures();
992   DALI_TEST_GREATER(textures2.size(), numTextures, TEST_LOCATION);
993
994   // Remove visual, for line coverage.
995   imageView.Unparent();
996   application.SendNotification();
997   application.Render(16);
998
999   END_TEST;
1000 }
1001
1002 int UtcDaliImageViewAddedTexture(void)
1003 {
1004   ToolkitTestApplication application;
1005
1006   tet_infoline("ImageView Testing image view with texture provided manager url");
1007
1008   ImageView imageView = ImageView::New();
1009
1010   // empty texture is ok, though pointless from app point of view
1011   TextureSet  empty;
1012   std::string url = TextureManager::AddTexture(empty);
1013   DALI_TEST_CHECK(url.size() > 0u);
1014
1015   Property::Map propertyMap;
1016   propertyMap[ImageVisual::Property::URL] = url;
1017   imageView.SetProperty(ImageView::Property::IMAGE, propertyMap);
1018
1019   application.GetScene().Add(imageView);
1020   application.SendNotification();
1021   application.Render();
1022
1023   END_TEST;
1024 }
1025
1026 int UtcDaliImageViewSizeWithBackground(void)
1027 {
1028   ToolkitTestApplication application;
1029
1030   int       width     = 100;
1031   int       height    = 200;
1032   ImageView imageView = ImageView::New();
1033
1034   imageView.SetProperty(Control::Property::BACKGROUND,
1035                         {
1036                           {Toolkit::Visual::Property::TYPE, Toolkit::Visual::IMAGE},
1037                           {Toolkit::ImageVisual::Property::URL, TEST_RESOURCE_DIR "/gallery-small-1.jpg"},
1038                           {ImageVisual::Property::DESIRED_WIDTH, width},
1039                           {ImageVisual::Property::DESIRED_HEIGHT, height},
1040                         });
1041
1042   application.GetScene().Add(imageView);
1043   application.SendNotification();
1044   application.Render();
1045
1046   DALI_TEST_EQUALS(imageView.GetCurrentProperty<Vector3>(Actor::Property::SIZE).width, (float)width, TEST_LOCATION);
1047   DALI_TEST_EQUALS(imageView.GetCurrentProperty<Vector3>(Actor::Property::SIZE).height, (float)height, TEST_LOCATION);
1048
1049   END_TEST;
1050 }
1051
1052 int UtcDaliImageViewSizeWithBackgroundAndImage(void)
1053 {
1054   ToolkitTestApplication application;
1055
1056   int widthBackground  = 100;
1057   int heightBackground = 200;
1058   int width            = 600;
1059   int height           = 600;
1060
1061   ImageView imageView = ImageView::New();
1062
1063   imageView.SetProperty(Control::Property::BACKGROUND,
1064                         {
1065                           {Toolkit::Visual::Property::TYPE, Toolkit::Visual::IMAGE},
1066                           {Toolkit::ImageVisual::Property::URL, TEST_RESOURCE_DIR "/gallery-small-1.jpg"},
1067                           {ImageVisual::Property::DESIRED_WIDTH, widthBackground},
1068                           {ImageVisual::Property::DESIRED_HEIGHT, heightBackground},
1069                         });
1070
1071   imageView.SetImage(gImage_600_RGB); // 1 to 1 ratio, 600x600 pixels
1072
1073   application.GetScene().Add(imageView);
1074   application.SendNotification();
1075   application.Render();
1076
1077   DALI_TEST_EQUALS(imageView.GetCurrentProperty<Vector3>(Actor::Property::SIZE).width, (float)width, TEST_LOCATION);
1078   DALI_TEST_EQUALS(imageView.GetCurrentProperty<Vector3>(Actor::Property::SIZE).height, (float)height, TEST_LOCATION);
1079
1080   END_TEST;
1081 }
1082
1083 int UtcDaliImageViewHeightForWidthBackground(void)
1084 {
1085   ToolkitTestApplication application;
1086
1087   int widthBackground  = 100;
1088   int heightBackground = 200;
1089
1090   ImageView imageView = ImageView::New();
1091
1092   imageView.SetProperty(Control::Property::BACKGROUND,
1093                         {{Toolkit::Visual::Property::TYPE, Toolkit::Visual::IMAGE},
1094                          {Toolkit::ImageVisual::Property::URL, TEST_RESOURCE_DIR "/gallery-small-1.jpg"},
1095                          {ImageVisual::Property::DESIRED_WIDTH, widthBackground},
1096                          {ImageVisual::Property::DESIRED_HEIGHT, heightBackground}});
1097
1098   application.GetScene().Add(imageView);
1099   application.SendNotification();
1100   application.Render();
1101
1102   Control control = Control::DownCast(imageView);
1103   DALI_TEST_CHECK(control);
1104   DALI_TEST_EQUALS(imageView.GetHeightForWidth(123.f), control.GetHeightForWidth(123.f), TEST_LOCATION);
1105   DALI_TEST_EQUALS(imageView.GetWidthForHeight(321.f), control.GetWidthForHeight(321.f), TEST_LOCATION);
1106
1107   END_TEST;
1108 }
1109
1110 int UtcDaliImageViewHeightForWidthBackgroundAndImage(void)
1111 {
1112   ToolkitTestApplication application;
1113
1114   int widthBackground  = 100;
1115   int heightBackground = 200;
1116   int width            = 300;
1117   int height           = 300;
1118
1119   ImageView imageView = ImageView::New();
1120
1121   imageView.SetProperty(Control::Property::BACKGROUND,
1122                         {{Toolkit::Visual::Property::TYPE, Toolkit::Visual::IMAGE},
1123                          {Toolkit::ImageVisual::Property::URL, TEST_RESOURCE_DIR "/gallery-small-1.jpg"},
1124                          {ImageVisual::Property::DESIRED_WIDTH, widthBackground},
1125                          {ImageVisual::Property::DESIRED_HEIGHT, heightBackground}}); // 1 to 2 ratio
1126
1127   imageView.SetImage(gImage_600_RGB); // 1 to 1 ratio
1128
1129   application.GetScene().Add(imageView);
1130   application.SendNotification();
1131   application.Render();
1132
1133   DALI_TEST_EQUALS(imageView.GetHeightForWidth(width), (float)height, TEST_LOCATION);
1134   DALI_TEST_EQUALS(imageView.GetWidthForHeight(height), (float)width, TEST_LOCATION);
1135
1136   END_TEST;
1137 }
1138
1139 int UtcDaliImageViewSetImageUrl(void)
1140 {
1141   ToolkitTestApplication application;
1142
1143   ImageView imageView = ImageView::New();
1144   imageView.SetImage(TEST_IMAGE_FILE_NAME);
1145   TestUrl(imageView, TEST_IMAGE_FILE_NAME);
1146
1147   imageView.SetImage(TEST_IMAGE_FILE_NAME2);
1148   TestUrl(imageView, TEST_IMAGE_FILE_NAME2);
1149
1150   END_TEST;
1151 }
1152
1153 bool    gResourceReadySignalFired = false;
1154 Vector3 gNaturalSize;
1155
1156 void ResourceReadySignal(Control control)
1157 {
1158   gResourceReadySignalFired = true;
1159 }
1160
1161 void OnResourceReadySignalSVG(Control control)
1162 {
1163   // Check whether Image Visual transforms on ImageVieiw::OnRelayout()
1164   Toolkit::Internal::Control& controlImpl = Toolkit::Internal::GetImplementation(control);
1165   Toolkit::Visual::Base       imageVisual = DevelControl::GetVisual(controlImpl, ImageView::Property::IMAGE);
1166   Property::Map               resultMap;
1167   imageVisual.CreatePropertyMap(resultMap);
1168
1169   Property::Value* transformValue = resultMap.Find(Visual::Property::TRANSFORM);
1170   DALI_TEST_CHECK(transformValue);
1171   Property::Map* retMap = transformValue->GetMap();
1172   DALI_TEST_CHECK(retMap);
1173
1174   // Fitting mode should not be applied at this point
1175   DALI_TEST_EQUALS(retMap->Find(Visual::Transform::Property::SIZE)->Get<Vector2>(), Vector2::ZERO, TEST_LOCATION);
1176 }
1177
1178 int UtcDaliImageViewCheckResourceReady(void)
1179 {
1180   ToolkitTestApplication application;
1181
1182   gResourceReadySignalFired = false;
1183
1184   // Check ImageView with background and main image, to ensure both visuals are marked as loaded
1185   ImageView imageView = ImageView::New(TEST_GIF_FILE_NAME);
1186
1187   imageView.SetProperty(Control::Property::BACKGROUND,
1188                         {{Toolkit::Visual::Property::TYPE, Toolkit::Visual::IMAGE},
1189                          {Toolkit::ImageVisual::Property::URL, TEST_RESOURCE_DIR "/gallery-small-1.jpg"},
1190                          {ImageVisual::Property::DESIRED_WIDTH, 100},
1191                          {ImageVisual::Property::DESIRED_HEIGHT, 200}});
1192
1193   DALI_TEST_EQUALS(imageView.IsResourceReady(), false, TEST_LOCATION);
1194
1195   imageView.ResourceReadySignal().Connect(&ResourceReadySignal);
1196
1197   application.GetScene().Add(imageView);
1198
1199   // loading started, this waits for the loader thread
1200   DALI_TEST_EQUALS(Test::WaitForEventThreadTrigger(1), true, TEST_LOCATION);
1201
1202   application.SendNotification();
1203   application.Render(16);
1204
1205   DALI_TEST_EQUALS(Test::WaitForEventThreadTrigger(2), true, TEST_LOCATION);
1206
1207   application.SendNotification();
1208   application.Render();
1209
1210   DALI_TEST_EQUALS(imageView.IsResourceReady(), true, TEST_LOCATION);
1211
1212   DALI_TEST_EQUALS(gResourceReadySignalFired, true, TEST_LOCATION);
1213
1214   END_TEST;
1215 }
1216
1217 int UtcDaliImageViewSetImageTypeChangesP(void)
1218 {
1219   ToolkitTestApplication application;
1220
1221   ImageView                   imageView   = ImageView::New();
1222   Toolkit::Internal::Control& controlImpl = Toolkit::Internal::GetImplementation(imageView);
1223
1224   application.GetScene().Add(imageView);
1225
1226   std::string           url;
1227   Property::Map         map;
1228   Toolkit::Visual::Base visual;
1229
1230   Property::Value value = imageView.GetProperty(imageView.GetPropertyIndex("image"));
1231   visual                = DevelControl::GetVisual(controlImpl, ImageView::Property::IMAGE);
1232
1233   application.SendNotification();
1234   application.Render(16);
1235
1236   DALI_TEST_CHECK(!value.Get(url)); // Value should be empty
1237   value.Get(map);
1238   DALI_TEST_CHECK(map.Empty()); // Value should be empty
1239   DALI_TEST_CHECK(!visual);     // Visual should be invalid
1240
1241   // Set a URL
1242   imageView.SetImage("TEST_URL");
1243
1244   application.SendNotification();
1245   application.Render(16);
1246
1247   value  = imageView.GetProperty(imageView.GetPropertyIndex("image"));
1248   visual = DevelControl::GetVisual(controlImpl, ImageView::Property::IMAGE);
1249
1250   DALI_TEST_CHECK(value.Get(url));  // Value should NOT be empty
1251   DALI_TEST_CHECK(!value.Get(map)); // Value should be empty
1252   DALI_TEST_CHECK(visual);          // Visual should be valid
1253
1254   // Set an empty URL
1255   imageView.SetImage("");
1256
1257   application.SendNotification();
1258   application.Render(16);
1259
1260   value  = imageView.GetProperty(imageView.GetPropertyIndex("image"));
1261   visual = DevelControl::GetVisual(controlImpl, ImageView::Property::IMAGE);
1262
1263   DALI_TEST_CHECK(!value.Get(url)); // Value should be empty
1264   value.Get(map);
1265   DALI_TEST_CHECK(map.Empty()); // Value should be empty
1266   DALI_TEST_CHECK(!visual);     // Visual should be invalid
1267
1268   // Set a URL in property map
1269   Property::Map propertyMap;
1270   propertyMap[ImageVisual::Property::URL] = TEST_IMAGE_FILE_NAME;
1271   imageView.SetProperty(ImageView::Property::IMAGE, propertyMap);
1272
1273   application.SendNotification();
1274   application.Render(16);
1275
1276   value  = imageView.GetProperty(imageView.GetPropertyIndex("image"));
1277   visual = DevelControl::GetVisual(controlImpl, ImageView::Property::IMAGE);
1278
1279   DALI_TEST_CHECK(!value.Get(url)); // Value should be empty
1280   DALI_TEST_CHECK(value.Get(map));  // Value should NOT be empty
1281   DALI_TEST_CHECK(visual);          // Visual should be valid
1282
1283   // Set a URL in property map again
1284   propertyMap[ImageVisual::Property::URL] = gImage_34_RGBA;
1285   imageView.SetProperty(ImageView::Property::IMAGE, propertyMap);
1286
1287   application.SendNotification();
1288   application.Render(16);
1289
1290   value  = imageView.GetProperty(imageView.GetPropertyIndex("image"));
1291   visual = DevelControl::GetVisual(controlImpl, ImageView::Property::IMAGE);
1292
1293   DALI_TEST_CHECK(!value.Get(url)); // Value should be empty
1294   DALI_TEST_CHECK(value.Get(map));  // Value should NOT be empty
1295   DALI_TEST_CHECK(visual);          // Visual should be valid
1296
1297   // Set an empty URL in property map
1298   propertyMap[ImageVisual::Property::URL] = std::string();
1299   imageView.SetProperty(ImageView::Property::IMAGE, propertyMap);
1300
1301   application.SendNotification();
1302   application.Render(16);
1303
1304   value  = imageView.GetProperty(imageView.GetPropertyIndex("image"));
1305   visual = DevelControl::GetVisual(controlImpl, ImageView::Property::IMAGE);
1306
1307   DALI_TEST_CHECK(!value.Get(url)); // Value should be empty
1308   DALI_TEST_CHECK(value.Get(map));  // Value should NOT be empty
1309   DALI_TEST_CHECK(!visual);         // Visual should be invalid
1310
1311   // Set a URL in property map again
1312   propertyMap[ImageVisual::Property::URL] = gImage_34_RGBA;
1313   imageView.SetProperty(ImageView::Property::IMAGE, propertyMap);
1314
1315   application.SendNotification();
1316   application.Render(16);
1317
1318   value  = imageView.GetProperty(imageView.GetPropertyIndex("image"));
1319   visual = DevelControl::GetVisual(controlImpl, ImageView::Property::IMAGE);
1320
1321   DALI_TEST_CHECK(!value.Get(url)); // Value should be empty
1322   DALI_TEST_CHECK(value.Get(map));  // Value should NOT be empty
1323   DALI_TEST_CHECK(visual);          // Visual should be valid
1324
1325   // Set an empty property map
1326   propertyMap.Clear();
1327   imageView.SetProperty(ImageView::Property::IMAGE, propertyMap);
1328
1329   application.SendNotification();
1330   application.Render(16);
1331
1332   value  = imageView.GetProperty(imageView.GetPropertyIndex("image"));
1333   visual = DevelControl::GetVisual(controlImpl, ImageView::Property::IMAGE);
1334
1335   DALI_TEST_CHECK(!value.Get(url)); // Value should be empty
1336   DALI_TEST_CHECK(value.Get(map));  // Value should NOT be empty
1337   DALI_TEST_CHECK(map.Empty());     // But PropertyMap should be empty
1338   DALI_TEST_CHECK(!visual);         // Visual should be invalid
1339
1340   END_TEST;
1341 }
1342
1343 int UtcDaliImageViewResourceUrlP(void)
1344 {
1345   ToolkitTestApplication application;
1346
1347   ImageView imageView = ImageView::New();
1348   DALI_TEST_CHECK(imageView.GetProperty(ImageView::Property::IMAGE).Get<std::string>().empty());
1349
1350   imageView.SetProperty(ImageView::Property::IMAGE, "TestString");
1351   DALI_TEST_EQUALS(imageView.GetProperty(ImageView::Property::IMAGE).Get<std::string>(), "TestString", TEST_LOCATION);
1352
1353   END_TEST;
1354 }
1355
1356 int UtcDaliImageViewReplaceImage(void)
1357 {
1358   ToolkitTestApplication application;
1359
1360   gResourceReadySignalFired = false;
1361
1362   // Check ImageView with background and main image, to ensure both visuals are marked as loaded
1363   ImageView imageView = ImageView::New(TEST_IMAGE_1);
1364
1365   DALI_TEST_EQUALS(imageView.IsResourceReady(), false, TEST_LOCATION);
1366
1367   imageView.ResourceReadySignal().Connect(&ResourceReadySignal);
1368
1369   application.GetScene().Add(imageView);
1370
1371   application.SendNotification();
1372   application.Render(16);
1373
1374   // loading started, this waits for the loader thread for max 30 seconds
1375   DALI_TEST_EQUALS(Test::WaitForEventThreadTrigger(1), true, TEST_LOCATION);
1376
1377   DALI_TEST_EQUALS(imageView.GetRendererCount(), 1u, TEST_LOCATION);
1378
1379   DALI_TEST_EQUALS(gResourceReadySignalFired, true, TEST_LOCATION);
1380
1381   gResourceReadySignalFired = false;
1382
1383   imageView.SetImage(TEST_IMAGE_2);
1384
1385   application.SendNotification();
1386   application.Render(16);
1387
1388   // loading started, this waits for the loader thread for max 30 seconds
1389   DALI_TEST_EQUALS(Test::WaitForEventThreadTrigger(1), true, TEST_LOCATION);
1390
1391   DALI_TEST_EQUALS(imageView.GetRendererCount(), 1u, TEST_LOCATION);
1392
1393   DALI_TEST_EQUALS(imageView.IsResourceReady(), true, TEST_LOCATION);
1394
1395   DALI_TEST_EQUALS(gResourceReadySignalFired, true, TEST_LOCATION);
1396
1397   END_TEST;
1398 }
1399
1400 int UtcDaliImageViewReloadAlphaMaskImage(void)
1401 {
1402   ToolkitTestApplication application;
1403
1404   gResourceReadySignalFired = false;
1405
1406   ImageView     dummy     = ImageView::New();
1407   ImageView     imageView = ImageView::New();
1408   Property::Map propertyMap;
1409
1410   // To keep alpha mask cached, scene on some dummy image.
1411   // Note : If we don't cache alpha mask image, the reference count of mask image become zero.
1412   // In this case, we might need to wait mask image loading, which is not neccesary & can be changed behavior.
1413   propertyMap[ImageVisual::Property::URL]            = gImage_600_RGB;
1414   propertyMap[ImageVisual::Property::ALPHA_MASK_URL] = TEST_BROKEN_IMAGE_DEFAULT;
1415   dummy.SetProperty(ImageView::Property::IMAGE, propertyMap);
1416
1417   application.GetScene().Add(dummy);
1418
1419   application.SendNotification();
1420   application.Render(16);
1421
1422   DALI_TEST_EQUALS(Test::WaitForEventThreadTrigger(3), true, TEST_LOCATION);
1423
1424   application.SendNotification();
1425   application.Render(16);
1426
1427   propertyMap.Clear();
1428   propertyMap[ImageVisual::Property::URL]            = gImage_34_RGBA;
1429   propertyMap[ImageVisual::Property::ALPHA_MASK_URL] = TEST_BROKEN_IMAGE_DEFAULT;
1430   imageView.SetProperty(ImageView::Property::IMAGE, propertyMap);
1431
1432   DALI_TEST_EQUALS(imageView.IsResourceReady(), false, TEST_LOCATION);
1433
1434   imageView.ResourceReadySignal().Connect(&ResourceReadySignal);
1435
1436   application.GetScene().Add(imageView);
1437
1438   application.SendNotification();
1439   application.Render(16);
1440
1441   // Load image and use cached mask. Now we try to apply masking.
1442   DALI_TEST_EQUALS(Test::WaitForEventThreadTrigger(1), true, TEST_LOCATION);
1443
1444   DALI_TEST_EQUALS(gResourceReadySignalFired, false, TEST_LOCATION);
1445
1446   // Cancel apply masking.
1447   imageView.Unparent();
1448
1449   application.SendNotification();
1450   application.Render(16);
1451
1452   // Reload same image again.
1453   application.GetScene().Add(imageView);
1454
1455   application.SendNotification();
1456   application.Render(16);
1457
1458   // Finish apply masking.
1459   DALI_TEST_EQUALS(Test::WaitForEventThreadTrigger(1), true, TEST_LOCATION);
1460
1461   DALI_TEST_EQUALS(imageView.GetRendererCount(), 1u, TEST_LOCATION);
1462   DALI_TEST_EQUALS(imageView.IsResourceReady(), true, TEST_LOCATION);
1463   DALI_TEST_EQUALS(gResourceReadySignalFired, true, TEST_LOCATION);
1464
1465   END_TEST;
1466 }
1467
1468 void OnRelayoutOverride(Size size)
1469 {
1470   gNaturalSize = size; // Size Relayout is using
1471 }
1472
1473 int UtcDaliImageViewReplaceImageAndGetNaturalSize(void)
1474 {
1475   ToolkitTestApplication application;
1476
1477   // Check ImageView with background and main image, to ensure both visuals are marked as loaded
1478   ImageView imageView = ImageView::New(TEST_IMAGE_1);
1479   imageView.SetResizePolicy(ResizePolicy::USE_NATURAL_SIZE, Dimension::ALL_DIMENSIONS);
1480
1481   DummyControl        dummyControl = DummyControl::New(true);
1482   Impl::DummyControl& dummyImpl    = static_cast<Impl::DummyControl&>(dummyControl.GetImplementation());
1483   dummyControl.SetResizePolicy(ResizePolicy::FIT_TO_CHILDREN, Dimension::ALL_DIMENSIONS);
1484
1485   dummyControl.Add(imageView);
1486   dummyImpl.SetRelayoutCallback(&OnRelayoutOverride);
1487   application.GetScene().Add(dummyControl);
1488
1489   application.SendNotification();
1490   application.Render();
1491
1492   // loading started, this waits for the loader thread for max 30 seconds
1493   DALI_TEST_EQUALS(Test::WaitForEventThreadTrigger(1), true, TEST_LOCATION);
1494
1495   DALI_TEST_EQUALS(gNaturalSize.width, 1024.0f, TEST_LOCATION);
1496   DALI_TEST_EQUALS(gNaturalSize.height, 1024.0f, TEST_LOCATION);
1497
1498   gNaturalSize = Vector3::ZERO;
1499
1500   imageView.SetImage(gImage_600_RGB);
1501
1502   // Waiting for resourceReady so SendNotifcation not called here.
1503
1504   // loading started, this waits for the loader thread for max 30 seconds
1505   DALI_TEST_EQUALS(Test::WaitForEventThreadTrigger(1), true, TEST_LOCATION);
1506
1507   // Trigger a potential relayout
1508   application.SendNotification();
1509   application.Render();
1510
1511   DALI_TEST_EQUALS(gNaturalSize.width, 600.0f, TEST_LOCATION);
1512   DALI_TEST_EQUALS(gNaturalSize.height, 600.0f, TEST_LOCATION);
1513
1514   END_TEST;
1515 }
1516
1517 int UtcDaliImageViewResourceReadySignalWithImmediateLoad(void)
1518 {
1519   tet_infoline("Test Setting Image with IMMEDIATE load and receving ResourceReadySignal before staged.");
1520
1521   ToolkitTestApplication application;
1522
1523   gResourceReadySignalFired = false;
1524
1525   Property::Map imageMap;
1526
1527   imageMap[ImageVisual::Property::URL]         = gImage_34_RGBA;
1528   imageMap[ImageVisual::Property::LOAD_POLICY] = ImageVisual::LoadPolicy::IMMEDIATE;
1529
1530   tet_infoline("Creating ImageView without URL so image does not start loading");
1531   ImageView imageView = ImageView::New();
1532   tet_infoline("Connect to image loaded signal before setting image");
1533   imageView.ResourceReadySignal().Connect(&ResourceReadySignal);
1534   tet_infoline("Setting Image with IMMEDIATE load, signal already connected so will be triggered.");
1535   imageView.SetProperty(ImageView::Property::IMAGE, imageMap);
1536
1537   // loading started, this waits for the loader thread
1538   DALI_TEST_EQUALS(Test::WaitForEventThreadTrigger(1), true, TEST_LOCATION);
1539
1540   application.SendNotification();
1541   application.Render(16);
1542
1543   DALI_TEST_EQUALS(gResourceReadySignalFired, true, TEST_LOCATION);
1544
1545   END_TEST;
1546 }
1547
1548 int UtcDaliImageViewResourceReadySignalWithReusedImage(void)
1549 {
1550   tet_infoline("Test Setting Image that was already loaded by another ImageView and still getting ResourceReadySignal.");
1551
1552   ToolkitTestApplication application;
1553
1554   gResourceReadySignalFired = false;
1555
1556   Property::Map imageMap;
1557
1558   imageMap[ImageVisual::Property::URL]         = gImage_34_RGBA;
1559   imageMap[ImageVisual::Property::LOAD_POLICY] = ImageVisual::LoadPolicy::IMMEDIATE;
1560
1561   ImageView imageView = ImageView::New();
1562   imageView.ResourceReadySignal().Connect(&ResourceReadySignal);
1563   imageView.SetProperty(ImageView::Property::IMAGE, imageMap);
1564
1565   // loading started, this waits for the loader thread
1566   DALI_TEST_EQUALS(Test::WaitForEventThreadTrigger(1), true, TEST_LOCATION);
1567
1568   application.SendNotification();
1569   application.Render(16);
1570
1571   DALI_TEST_EQUALS(gResourceReadySignalFired, true, TEST_LOCATION);
1572   gResourceReadySignalFired = false;
1573
1574   ImageView imageViewWithExistingImage = ImageView::New();
1575   imageViewWithExistingImage.ResourceReadySignal().Connect(&ResourceReadySignal);
1576   imageViewWithExistingImage.SetProperty(ImageView::Property::IMAGE, imageMap);
1577
1578   DALI_TEST_EQUALS(gResourceReadySignalFired, true, TEST_LOCATION);
1579
1580   END_TEST;
1581 }
1582
1583 int UtcDaliImageViewResourceReadySignalWithReusedImage02(void)
1584 {
1585   tet_infoline("Test Setting Image that was already loaded by another ImageView and still getting ResourceReadySignal when staged.");
1586
1587   ToolkitTestApplication application;
1588
1589   gResourceReadySignalFired = false;
1590
1591   Property::Map imageImmediateLoadingMap;
1592   imageImmediateLoadingMap[ImageVisual::Property::URL]         = gImage_34_RGBA;
1593   imageImmediateLoadingMap[ImageVisual::Property::LOAD_POLICY] = ImageVisual::LoadPolicy::IMMEDIATE;
1594
1595   tet_infoline("Immediate load an image");
1596   ImageView imageView = ImageView::New();
1597   imageView.ResourceReadySignal().Connect(&ResourceReadySignal);
1598   imageView.SetProperty(ImageView::Property::IMAGE, imageImmediateLoadingMap);
1599
1600   // loading started, this waits for the loader thread
1601   DALI_TEST_EQUALS(Test::WaitForEventThreadTrigger(1), true, TEST_LOCATION);
1602
1603   application.SendNotification();
1604   application.Render(16);
1605
1606   tet_infoline("Check image loaded");
1607   DALI_TEST_EQUALS(gResourceReadySignalFired, true, TEST_LOCATION);
1608   gResourceReadySignalFired = false;
1609
1610   tet_infoline("Create another ImageView with the same URL");
1611   ImageView imageViewWithExistingImage = ImageView::New(gImage_34_RGBA);
1612   tet_infoline("Connect to ResourceReady signal for second ImageView, it should still fire as resource is ready");
1613   imageViewWithExistingImage.ResourceReadySignal().Connect(&ResourceReadySignal);
1614
1615   application.GetScene().Add(imageViewWithExistingImage);
1616
1617   DALI_TEST_EQUALS(gResourceReadySignalFired, true, TEST_LOCATION);
1618
1619   END_TEST;
1620 }
1621
1622 int UtcDaliImageViewPaddingProperty(void)
1623 {
1624   ToolkitTestApplication application;
1625
1626   ImageView     imageView = ImageView::New();
1627   Property::Map imagePropertyMap;
1628   imagePropertyMap[Toolkit::Visual::Property::TYPE]       = Toolkit::Visual::IMAGE;
1629   imagePropertyMap[Toolkit::ImageVisual::Property::URL]   = TEST_RESOURCE_DIR "/gallery-small-1.jpg";
1630   imagePropertyMap[ImageVisual::Property::DESIRED_WIDTH]  = 128;
1631   imagePropertyMap[ImageVisual::Property::DESIRED_HEIGHT] = 128;
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   imageView.SetProperty(Control::Property::PADDING, Extents(15, 10, 5, 10));
1636   application.GetScene().Add(imageView);
1637
1638   application.SendNotification();
1639   application.Render();
1640
1641   DALI_TEST_EQUALS(imageView.GetProperty<Extents>(Control::Property::PADDING), Extents(15, 10, 5, 10), TEST_LOCATION);
1642
1643   ImageView childImage = ImageView::New();
1644   childImage.SetBackgroundColor(Color::BLACK);
1645   childImage.SetProperty(Actor::Property::SIZE, Vector2(10.f, 10.f));
1646   imageView.Add(childImage);
1647
1648   application.SendNotification();
1649   application.Render();
1650
1651   // Child ImageView should be positioned dependinig on Parent ImageView's Padding value
1652   DALI_TEST_EQUALS(childImage.GetProperty<Vector3>(Dali::Actor::Property::POSITION), Vector3(15, 5, 0), TEST_LOCATION);
1653
1654   // Check whether Image Visual transforms on ImageVieiw::OnRelayout()
1655   Toolkit::Internal::Control& controlImpl = Toolkit::Internal::GetImplementation(imageView);
1656   Toolkit::Visual::Base       imageVisual = DevelControl::GetVisual(controlImpl, ImageView::Property::IMAGE);
1657   Property::Map               resultMap;
1658   imageVisual.CreatePropertyMap(resultMap);
1659
1660   Property::Value* transformValue = resultMap.Find(Visual::Property::TRANSFORM);
1661   DALI_TEST_CHECK(transformValue);
1662   Property::Map* retMap = transformValue->GetMap();
1663   DALI_TEST_CHECK(retMap);
1664
1665   // Image Visual should be positioned depending on ImageView's padding
1666   DALI_TEST_EQUALS(retMap->Find(Visual::Transform::Property::OFFSET)->Get<Vector2>(), Vector2(15, 5), TEST_LOCATION);
1667
1668   END_TEST;
1669 }
1670
1671 int UtcDaliImageViewPaddingProperty02(void)
1672 {
1673   ToolkitTestApplication application;
1674
1675   ImageView     imageView = ImageView::New();
1676   Property::Map imagePropertyMap;
1677   imagePropertyMap[Toolkit::Visual::Property::TYPE]            = Toolkit::Visual::IMAGE;
1678   imagePropertyMap[Toolkit::ImageVisual::Property::URL]        = TEST_RESOURCE_DIR "/Kid1.svg";
1679   imagePropertyMap[ImageVisual::Property::DESIRED_WIDTH]       = 128;
1680   imagePropertyMap[ImageVisual::Property::DESIRED_HEIGHT]      = 128;
1681   imagePropertyMap[DevelVisual::Property::VISUAL_FITTING_MODE] = Toolkit::DevelVisual::FIT_KEEP_ASPECT_RATIO;
1682   imageView.SetProperty(Toolkit::ImageView::Property::IMAGE, imagePropertyMap);
1683   imageView.SetProperty(Actor::Property::ANCHOR_POINT, AnchorPoint::TOP_LEFT);
1684   imageView.SetProperty(Actor::Property::PARENT_ORIGIN, ParentOrigin::TOP_LEFT);
1685   imageView.SetProperty(Control::Property::PADDING, Extents(15, 10, 5, 10));
1686   application.GetScene().Add(imageView);
1687
1688   application.SendNotification();
1689   application.Render();
1690
1691   DALI_TEST_EQUALS(imageView.GetProperty<Extents>(Control::Property::PADDING), Extents(15, 10, 5, 10), TEST_LOCATION);
1692
1693   // Check whether Image Visual transforms on ImageVieiw::OnRelayout()
1694   Toolkit::Internal::Control& controlImpl = Toolkit::Internal::GetImplementation(imageView);
1695   Toolkit::Visual::Base       imageVisual = DevelControl::GetVisual(controlImpl, ImageView::Property::IMAGE);
1696   Property::Map               resultMap;
1697   imageVisual.CreatePropertyMap(resultMap);
1698
1699   Property::Value* transformValue = resultMap.Find(Visual::Property::TRANSFORM);
1700   DALI_TEST_CHECK(transformValue);
1701   Property::Map* retMap = transformValue->GetMap();
1702   DALI_TEST_CHECK(retMap);
1703
1704   // Image Visual should be positioned depending on ImageView's padding
1705   DALI_TEST_EQUALS(retMap->Find(Visual::Transform::Property::OFFSET)->Get<Vector2>(), Vector2(15, 5), TEST_LOCATION);
1706
1707   END_TEST;
1708 }
1709
1710 int UtcDaliImageViewPaddingProperty03(void)
1711 {
1712   tet_infoline("Test Setting Image Padding then removing it.");
1713
1714   ToolkitTestApplication application;
1715
1716   ImageView     imageView = ImageView::New();
1717   Property::Map imagePropertyMap;
1718   imagePropertyMap[Toolkit::Visual::Property::TYPE]            = Toolkit::Visual::IMAGE;
1719   imagePropertyMap[Toolkit::ImageVisual::Property::URL]        = TEST_RESOURCE_DIR "/Kid1.svg";
1720   imagePropertyMap[ImageVisual::Property::DESIRED_WIDTH]       = 128;
1721   imagePropertyMap[ImageVisual::Property::DESIRED_HEIGHT]      = 128;
1722   imagePropertyMap[DevelVisual::Property::VISUAL_FITTING_MODE] = Toolkit::DevelVisual::FIT_KEEP_ASPECT_RATIO;
1723   imageView.SetProperty(Toolkit::ImageView::Property::IMAGE, imagePropertyMap);
1724   imageView.SetProperty(Actor::Property::ANCHOR_POINT, AnchorPoint::TOP_LEFT);
1725   imageView.SetProperty(Actor::Property::PARENT_ORIGIN, ParentOrigin::TOP_LEFT);
1726   imageView.SetProperty(Control::Property::PADDING, Extents(15, 10, 5, 10));
1727   application.GetScene().Add(imageView);
1728
1729   application.SendNotification();
1730   application.Render();
1731
1732   DALI_TEST_EQUALS(imageView.GetProperty<Extents>(Control::Property::PADDING), Extents(15, 10, 5, 10), TEST_LOCATION);
1733
1734   tet_infoline("Remove Padding and test Visual is position correctly");
1735
1736   imageView.SetProperty(Control::Property::PADDING, Extents(0, 0, 0, 0));
1737
1738   application.SendNotification();
1739   application.Render();
1740
1741   // Check whether Image Visual transforms on ImageVieiw::OnRelayout()
1742   Toolkit::Internal::Control& controlImpl = Toolkit::Internal::GetImplementation(imageView);
1743   Toolkit::Visual::Base       imageVisual = DevelControl::GetVisual(controlImpl, ImageView::Property::IMAGE);
1744   Property::Map               resultMap;
1745   imageVisual.CreatePropertyMap(resultMap);
1746
1747   Property::Value* transformValue = resultMap.Find(Visual::Property::TRANSFORM);
1748   DALI_TEST_CHECK(transformValue);
1749   Property::Map* retMap = transformValue->GetMap();
1750   DALI_TEST_CHECK(retMap);
1751
1752   // Image Visual should be positioned depending on ImageView's padding
1753   DALI_TEST_EQUALS(retMap->Find(Visual::Transform::Property::OFFSET)->Get<Vector2>(), Vector2(0, 0), TEST_LOCATION);
1754
1755   END_TEST;
1756 }
1757
1758 int UtcDaliImageViewPaddingProperty04(void)
1759 {
1760   tet_infoline("Test Setting Image Padding then removing it. Visual Fitting Mode as Fill");
1761
1762   ToolkitTestApplication application;
1763
1764   ImageView     imageView = ImageView::New();
1765   Property::Map imagePropertyMap;
1766   imagePropertyMap[Toolkit::Visual::Property::TYPE]            = Toolkit::Visual::IMAGE;
1767   imagePropertyMap[Toolkit::ImageVisual::Property::URL]        = TEST_RESOURCE_DIR "/Kid1.svg";
1768   imagePropertyMap[ImageVisual::Property::DESIRED_WIDTH]       = 128;
1769   imagePropertyMap[ImageVisual::Property::DESIRED_HEIGHT]      = 128;
1770   imagePropertyMap[DevelVisual::Property::VISUAL_FITTING_MODE] = Toolkit::DevelVisual::FILL;
1771   imageView.SetProperty(Toolkit::ImageView::Property::IMAGE, imagePropertyMap);
1772   imageView.SetProperty(Actor::Property::ANCHOR_POINT, AnchorPoint::TOP_LEFT);
1773   imageView.SetProperty(Actor::Property::PARENT_ORIGIN, ParentOrigin::TOP_LEFT);
1774   imageView.SetProperty(Control::Property::PADDING, Extents(15, 10, 5, 10));
1775   application.GetScene().Add(imageView);
1776
1777   application.SendNotification();
1778   application.Render();
1779
1780   DALI_TEST_EQUALS(imageView.GetProperty<Extents>(Control::Property::PADDING), Extents(15, 10, 5, 10), TEST_LOCATION);
1781
1782   tet_infoline("Remove Padding and test Visual is position correctly");
1783
1784   imageView.SetProperty(Control::Property::PADDING, Extents(0, 0, 0, 0));
1785
1786   application.SendNotification();
1787   application.Render();
1788
1789   // Check whether Image Visual transforms on ImageVieiw::OnRelayout()
1790   Toolkit::Internal::Control& controlImpl = Toolkit::Internal::GetImplementation(imageView);
1791   Toolkit::Visual::Base       imageVisual = DevelControl::GetVisual(controlImpl, ImageView::Property::IMAGE);
1792   Property::Map               resultMap;
1793   imageVisual.CreatePropertyMap(resultMap);
1794
1795   Property::Value* transformValue = resultMap.Find(Visual::Property::TRANSFORM);
1796   DALI_TEST_CHECK(transformValue);
1797   Property::Map* retMap = transformValue->GetMap();
1798   DALI_TEST_CHECK(retMap);
1799
1800   // Image Visual should be positioned depending on ImageView's padding
1801   DALI_TEST_EQUALS(retMap->Find(Visual::Transform::Property::OFFSET)->Get<Vector2>(), Vector2(0, 0), TEST_LOCATION);
1802
1803   END_TEST;
1804 }
1805
1806 int UtcDaliImageViewTransformTest01(void)
1807 {
1808   tet_infoline("Test Setting a offset transform on the ImageView");
1809
1810   ToolkitTestApplication application;
1811
1812   ImageView     imageView = ImageView::New();
1813   Property::Map imagePropertyMap;
1814   imagePropertyMap.Add(Toolkit::Visual::Property::TYPE, Toolkit::Visual::IMAGE)
1815     .Add(Toolkit::ImageVisual::Property::URL, TEST_RESOURCE_DIR "/Kid1.svg")
1816     .Add(ImageVisual::Property::DESIRED_WIDTH, 120)
1817     .Add(ImageVisual::Property::DESIRED_HEIGHT, 120)
1818     .Add(DevelVisual::Property::VISUAL_FITTING_MODE, Toolkit::DevelVisual::FILL)
1819     .Add(Visual::Property::TRANSFORM,
1820          Property::Map().Add(Toolkit::Visual::Transform::Property::OFFSET_POLICY,
1821                              Vector2(Visual::Transform::Policy::ABSOLUTE, Visual::Transform::Policy::ABSOLUTE))
1822            .Add(Toolkit::Visual::Transform::Property::OFFSET, Vector2(8, 8)));
1823
1824   imageView.SetProperty(Toolkit::ImageView::Property::IMAGE, imagePropertyMap);
1825   imageView.SetProperty(Actor::Property::ANCHOR_POINT, AnchorPoint::TOP_LEFT);
1826   imageView.SetProperty(Actor::Property::PARENT_ORIGIN, ParentOrigin::TOP_LEFT);
1827   application.GetScene().Add(imageView);
1828
1829   application.SendNotification();
1830   application.Render();
1831
1832   // Check whether Image Visual transforms on ImageVieiw::OnRelayout()
1833   Toolkit::Internal::Control& controlImpl = Toolkit::Internal::GetImplementation(imageView);
1834   Toolkit::Visual::Base       imageVisual = DevelControl::GetVisual(controlImpl, ImageView::Property::IMAGE);
1835   Property::Map               resultMap;
1836   imageVisual.CreatePropertyMap(resultMap);
1837
1838   Property::Value* transformValue = resultMap.Find(Visual::Property::TRANSFORM);
1839   DALI_TEST_CHECK(transformValue);
1840   Property::Map* retMap = transformValue->GetMap();
1841   DALI_TEST_CHECK(retMap);
1842
1843   // Image Visual should be positioned depending on ImageView's padding
1844   DALI_TEST_EQUALS(retMap->Find(Visual::Transform::Property::OFFSET)->Get<Vector2>(), Vector2(8, 8), TEST_LOCATION);
1845   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);
1846
1847   END_TEST;
1848 }
1849
1850 int UtcDaliImageViewUsingAtlasAndGetNaturalSize(void)
1851 {
1852   ToolkitTestApplication application;
1853
1854   // Check ImageView with background and main image, to ensure both visuals are marked as loaded
1855   ImageView     imageView = ImageView::New();
1856   Property::Map imageMap;
1857   imageMap[Toolkit::Visual::Property::TYPE]          = Toolkit::Visual::IMAGE;
1858   imageMap[Toolkit::ImageVisual::Property::URL]      = gImage_34_RGBA;
1859   imageMap[Toolkit::ImageVisual::Property::ATLASING] = true;
1860   imageView.SetProperty(Toolkit::ImageView::Property::IMAGE, imageMap);
1861   application.GetScene().Add(imageView);
1862
1863   // Trigger a potential relayout
1864   application.SendNotification();
1865   application.Render();
1866
1867   Vector3 naturalSize = imageView.GetNaturalSize();
1868
1869   DALI_TEST_EQUALS(naturalSize.width, 34.0f, TEST_LOCATION);
1870   DALI_TEST_EQUALS(naturalSize.height, 34.0f, TEST_LOCATION);
1871
1872   END_TEST;
1873 }
1874
1875 int UtcDaliImageViewFillMode(void)
1876 {
1877   ToolkitTestApplication application;
1878
1879   tet_infoline("Create an ImageVisual without padding and set the fill-mode to fill");
1880
1881   ImageView     imageView = ImageView::New();
1882   Property::Map imageMap;
1883   imageMap.Add(Toolkit::Visual::Property::TYPE, Toolkit::Visual::IMAGE);
1884   imageMap.Add(Toolkit::ImageVisual::Property::URL, gImage_600_RGB);
1885   imageMap.Add(DevelVisual::Property::VISUAL_FITTING_MODE, DevelVisual::FittingMode::FILL);
1886
1887   imageView.SetProperty(Toolkit::ImageView::Property::IMAGE, imageMap);
1888
1889   application.GetScene().Add(imageView);
1890
1891   // Trigger a potential relayout
1892   application.SendNotification();
1893   application.Render();
1894
1895   Toolkit::Visual::Base visual = DevelControl::GetVisual(Toolkit::Internal::GetImplementation(imageView), Toolkit::ImageView::Property::IMAGE);
1896   Property::Map         returnedMap;
1897   visual.CreatePropertyMap(returnedMap);
1898
1899   Property::Value* value = returnedMap.Find(Toolkit::Visual::Property::TRANSFORM);
1900   DALI_TEST_CHECK(value);
1901   Property::Map* map = value->GetMap();
1902   DALI_TEST_CHECK(map);
1903
1904   value = map->Find(Toolkit::Visual::Transform::Property::SIZE);
1905   DALI_TEST_CHECK(value);
1906   DALI_TEST_EQUALS(value->Get<Vector2>(), Vector2::ONE, TEST_LOCATION);
1907
1908   value = map->Find(Toolkit::Visual::Transform::Property::SIZE_POLICY);
1909   DALI_TEST_CHECK(value);
1910   DALI_TEST_CHECK(value->Get<int>() == Toolkit::Visual::Transform::Policy::RELATIVE);
1911
1912   END_TEST;
1913 }
1914
1915 int UtcDaliImageViewFittingModeFitKeepAspectRatio(void)
1916 {
1917   ToolkitTestApplication application;
1918
1919   tet_infoline("Create an ImageVisual using FitKeepAspectRatio ( image: [600,600], view: [600,700] )");
1920   tet_infoline("  There should be need to change the transform, offset is adjusted to fit inside");
1921
1922   ImageView     imageView = ImageView::New();
1923   Property::Map imageMap;
1924   imageMap.Add(Toolkit::Visual::Property::TYPE, Toolkit::Visual::IMAGE);
1925   imageMap.Add(Toolkit::ImageVisual::Property::URL, gImage_600_RGB); // 600x600 image
1926   imageMap.Add(DevelVisual::Property::VISUAL_FITTING_MODE, Toolkit::DevelVisual::FIT_KEEP_ASPECT_RATIO);
1927
1928   imageView.SetProperty(Toolkit::ImageView::Property::IMAGE, imageMap);
1929   imageView.SetProperty(Actor::Property::SIZE, Vector2(600, 700));
1930
1931   application.GetScene().Add(imageView);
1932
1933   // Trigger a potential relayout
1934   application.SendNotification();
1935   application.Render();
1936
1937   Toolkit::Visual::Base visual = DevelControl::GetVisual(Toolkit::Internal::GetImplementation(imageView), Toolkit::ImageView::Property::IMAGE);
1938   Property::Map         returnedMap;
1939   visual.CreatePropertyMap(returnedMap);
1940
1941   Property::Value* value = returnedMap.Find(Toolkit::Visual::Property::TRANSFORM);
1942   DALI_TEST_CHECK(value);
1943   Property::Map* map = value->GetMap();
1944   DALI_TEST_CHECK(map);
1945
1946   // If there's
1947   value = map->Find(Toolkit::Visual::Transform::Property::SIZE);
1948   DALI_TEST_CHECK(value);
1949   DALI_TEST_EQUALS(value->Get<Vector2>(), Vector2(600, 600), TEST_LOCATION);
1950
1951   value = map->Find(Toolkit::Visual::Transform::Property::SIZE_POLICY);
1952   DALI_TEST_CHECK(value);
1953   DALI_TEST_EQUALS(value->Get<Vector2>(), Vector2(Toolkit::Visual::Transform::Policy::ABSOLUTE, Toolkit::Visual::Transform::Policy::ABSOLUTE), TEST_LOCATION);
1954
1955   value = map->Find(Toolkit::Visual::Transform::Property::OFFSET);
1956   DALI_TEST_CHECK(value);
1957   DALI_TEST_EQUALS(value->Get<Vector2>(), Vector2(0, 50), TEST_LOCATION);
1958
1959   END_TEST;
1960 }
1961
1962 int UtcDaliImageViewFittingModesFill(void)
1963 {
1964   ToolkitTestApplication application;
1965
1966   tet_infoline("Create an ImageVisual using Fill ( image: [600,600], view: [600,700] )");
1967   tet_infoline("  There should be no need to change the transform, only size is changed to fit view");
1968
1969   ImageView     imageView = ImageView::New();
1970   Property::Map imageMap;
1971   imageMap.Add(Toolkit::Visual::Property::TYPE, Toolkit::Visual::IMAGE);
1972   imageMap.Add(Toolkit::ImageVisual::Property::URL, gImage_600_RGB); // 600x600 image
1973   imageMap.Add(DevelVisual::Property::VISUAL_FITTING_MODE, Toolkit::DevelVisual::FILL);
1974
1975   imageView.SetProperty(Toolkit::ImageView::Property::IMAGE, imageMap);
1976   imageView.SetProperty(Actor::Property::SIZE, Vector2(600, 700));
1977
1978   application.GetScene().Add(imageView);
1979
1980   // Trigger a potential relayout
1981   application.SendNotification();
1982   application.Render();
1983
1984   Toolkit::Visual::Base visual = DevelControl::GetVisual(Toolkit::Internal::GetImplementation(imageView), Toolkit::ImageView::Property::IMAGE);
1985   Property::Map         returnedMap;
1986   visual.CreatePropertyMap(returnedMap);
1987
1988   Property::Value* value = returnedMap.Find(Toolkit::Visual::Property::TRANSFORM);
1989   DALI_TEST_CHECK(value);
1990   Property::Map* map = value->GetMap();
1991   DALI_TEST_CHECK(map);
1992
1993   value = map->Find(Toolkit::Visual::Transform::Property::SIZE);
1994   DALI_TEST_CHECK(value);
1995   DALI_TEST_EQUALS(value->Get<Vector2>(), Vector2::ONE, TEST_LOCATION); // Change the internal size according to the image view size
1996
1997   value = map->Find(Toolkit::Visual::Transform::Property::SIZE_POLICY);
1998   DALI_TEST_CHECK(value);
1999   DALI_TEST_CHECK(value->Get<int>() == Toolkit::Visual::Transform::Policy::RELATIVE);
2000
2001   value = map->Find(Toolkit::Visual::Transform::Property::OFFSET);
2002   DALI_TEST_CHECK(value);
2003   DALI_TEST_EQUALS(value->Get<Vector2>(), Vector2(0, 0), TEST_LOCATION); // OFFSET is zero
2004
2005   END_TEST;
2006 }
2007
2008 int UtcDaliImageViewFittingModesOverfitKeepAspectRatio(void)
2009 {
2010   ToolkitTestApplication application;
2011
2012   tet_infoline("Create an ImageVisual using OverFitKeepAspectRatio ( image: [600,600], view: [600,500] )");
2013   tet_infoline("  offset or size is the same as view, but adjust internally using pixelArea ");
2014
2015   ImageView     imageView = ImageView::New();
2016   Property::Map imageMap;
2017   imageMap.Add(Toolkit::Visual::Property::TYPE, Toolkit::Visual::IMAGE);
2018   imageMap.Add(Toolkit::ImageVisual::Property::URL, gImage_600_RGB); // 600x600 image
2019   imageMap.Add(DevelVisual::Property::VISUAL_FITTING_MODE, Toolkit::DevelVisual::OVER_FIT_KEEP_ASPECT_RATIO);
2020
2021   imageView.SetProperty(Toolkit::ImageView::Property::IMAGE, imageMap);
2022   imageView.SetProperty(Actor::Property::SIZE, Vector2(600, 500));
2023
2024   application.GetScene().Add(imageView);
2025
2026   // Trigger a potential relayout
2027   application.SendNotification();
2028   application.Render();
2029
2030   Toolkit::Visual::Base visual = DevelControl::GetVisual(Toolkit::Internal::GetImplementation(imageView), Toolkit::ImageView::Property::IMAGE);
2031   Property::Map         returnedMap;
2032   visual.CreatePropertyMap(returnedMap);
2033
2034   Property::Value* value = returnedMap.Find(Toolkit::Visual::Property::TRANSFORM);
2035   DALI_TEST_CHECK(value);
2036   Property::Map* map = value->GetMap();
2037   DALI_TEST_CHECK(map);
2038
2039   // If there's
2040   value = map->Find(Toolkit::Visual::Transform::Property::SIZE);
2041   DALI_TEST_CHECK(value);
2042   DALI_TEST_EQUALS(value->Get<Vector2>(), Vector2(600, 500), TEST_LOCATION); // Change the internal size according to the image view size
2043
2044   value = map->Find(Toolkit::Visual::Transform::Property::SIZE_POLICY);
2045   DALI_TEST_CHECK(value);
2046   DALI_TEST_EQUALS(value->Get<Vector2>(), Vector2(Toolkit::Visual::Transform::Policy::ABSOLUTE, Toolkit::Visual::Transform::Policy::ABSOLUTE), TEST_LOCATION);
2047
2048   value = map->Find(Toolkit::Visual::Transform::Property::OFFSET);
2049   DALI_TEST_CHECK(value);
2050   DALI_TEST_EQUALS(value->Get<Vector2>(), Vector2(0, 0), TEST_LOCATION); // OFFSET is zero
2051
2052   END_TEST;
2053 }
2054
2055 int UtcDaliImageViewFittingModesCenter01(void)
2056 {
2057   ToolkitTestApplication application;
2058
2059   tet_infoline("Create an ImageVisual using Center ( image: [600,600], view: [700,700] )");
2060   tet_infoline("  There should be need to change the transform, offset is adjusted to fit inside");
2061
2062   ImageView     imageView = ImageView::New();
2063   Property::Map imageMap;
2064   imageMap.Add(Toolkit::Visual::Property::TYPE, Toolkit::Visual::IMAGE);
2065   imageMap.Add(Toolkit::ImageVisual::Property::URL, gImage_600_RGB); // 600x600 image
2066   imageMap.Add(DevelVisual::Property::VISUAL_FITTING_MODE, Toolkit::DevelVisual::CENTER);
2067
2068   imageView.SetProperty(Toolkit::ImageView::Property::IMAGE, imageMap);
2069   imageView.SetProperty(Actor::Property::SIZE, Vector2(700, 700));
2070
2071   application.GetScene().Add(imageView);
2072
2073   // Trigger a potential relayout
2074   application.SendNotification();
2075   application.Render();
2076
2077   Toolkit::Visual::Base visual = DevelControl::GetVisual(Toolkit::Internal::GetImplementation(imageView), Toolkit::ImageView::Property::IMAGE);
2078   Property::Map         returnedMap;
2079   visual.CreatePropertyMap(returnedMap);
2080
2081   Property::Value* value = returnedMap.Find(Toolkit::Visual::Property::TRANSFORM);
2082   DALI_TEST_CHECK(value);
2083   Property::Map* map = value->GetMap();
2084   DALI_TEST_CHECK(map);
2085
2086   value = map->Find(Toolkit::Visual::Transform::Property::SIZE);
2087   DALI_TEST_CHECK(value);
2088   DALI_TEST_EQUALS(value->Get<Vector2>(), Vector2(600, 600), TEST_LOCATION); // Change the internal size according to the image view size
2089
2090   value = map->Find(Toolkit::Visual::Transform::Property::SIZE_POLICY);
2091   DALI_TEST_CHECK(value);
2092   DALI_TEST_EQUALS(value->Get<Vector2>(), Vector2(Toolkit::Visual::Transform::Policy::ABSOLUTE, Toolkit::Visual::Transform::Policy::ABSOLUTE), TEST_LOCATION);
2093
2094   value = map->Find(Toolkit::Visual::Transform::Property::OFFSET);
2095   DALI_TEST_CHECK(value);
2096   DALI_TEST_EQUALS(value->Get<Vector2>(), Vector2(50, 50), TEST_LOCATION);
2097
2098   END_TEST;
2099 }
2100
2101 int UtcDaliImageViewFittingModesCenter02(void)
2102 {
2103   ToolkitTestApplication application;
2104
2105   tet_infoline("Create an ImageVisual using Center ( image: [600,600], view: [500,500] )");
2106   tet_infoline("  There should be need to change the transform, offset is adjusted to fit inside");
2107
2108   ImageView     imageView = ImageView::New();
2109   Property::Map imageMap;
2110   imageMap.Add(Toolkit::Visual::Property::TYPE, Toolkit::Visual::IMAGE);
2111   imageMap.Add(Toolkit::ImageVisual::Property::URL, gImage_600_RGB); // 600x600 image
2112   imageMap.Add(DevelVisual::Property::VISUAL_FITTING_MODE, Toolkit::DevelVisual::CENTER);
2113
2114   imageView.SetProperty(Toolkit::ImageView::Property::IMAGE, imageMap);
2115   imageView.SetProperty(Actor::Property::SIZE, Vector2(700, 700));
2116
2117   application.GetScene().Add(imageView);
2118
2119   // Trigger a potential relayout
2120   application.SendNotification();
2121   application.Render();
2122
2123   Toolkit::Visual::Base visual = DevelControl::GetVisual(Toolkit::Internal::GetImplementation(imageView), Toolkit::ImageView::Property::IMAGE);
2124   Property::Map         returnedMap;
2125   visual.CreatePropertyMap(returnedMap);
2126
2127   Property::Value* value = returnedMap.Find(Toolkit::Visual::Property::TRANSFORM);
2128   DALI_TEST_CHECK(value);
2129   Property::Map* map = value->GetMap();
2130   DALI_TEST_CHECK(map);
2131
2132   value = map->Find(Toolkit::Visual::Transform::Property::SIZE);
2133   DALI_TEST_CHECK(value);
2134   DALI_TEST_EQUALS(value->Get<Vector2>(), Vector2(600, 600), TEST_LOCATION); // Change the internal size according to the image view size
2135
2136   value = map->Find(Toolkit::Visual::Transform::Property::SIZE_POLICY);
2137   DALI_TEST_CHECK(value);
2138   DALI_TEST_EQUALS(value->Get<Vector2>(), Vector2(Toolkit::Visual::Transform::Policy::ABSOLUTE, Toolkit::Visual::Transform::Policy::ABSOLUTE), TEST_LOCATION);
2139
2140   value = map->Find(Toolkit::Visual::Transform::Property::OFFSET);
2141   DALI_TEST_CHECK(value);
2142   DALI_TEST_EQUALS(value->Get<Vector2>(), Vector2(50, 50), TEST_LOCATION);
2143
2144   END_TEST;
2145 }
2146
2147 int UtcDaliImageViewFittingModesFitHeight01(void)
2148 {
2149   ToolkitTestApplication application;
2150
2151   tet_infoline("Create an ImageVisual using FitHeight ( image: [600,600], view: [600,700] )");
2152
2153   ImageView     imageView = ImageView::New();
2154   Property::Map imageMap;
2155   imageMap.Add(Toolkit::Visual::Property::TYPE, Toolkit::Visual::IMAGE);
2156   imageMap.Add(Toolkit::ImageVisual::Property::URL, gImage_600_RGB); // 600x600 image
2157   imageMap.Add(DevelVisual::Property::VISUAL_FITTING_MODE, Toolkit::DevelVisual::FIT_HEIGHT);
2158
2159   imageView.SetProperty(Toolkit::ImageView::Property::IMAGE, imageMap);
2160   imageView.SetProperty(Actor::Property::SIZE, Vector2(600, 700));
2161
2162   application.GetScene().Add(imageView);
2163
2164   // Trigger a potential relayout
2165   application.SendNotification();
2166   application.Render();
2167
2168   Toolkit::Visual::Base visual = DevelControl::GetVisual(Toolkit::Internal::GetImplementation(imageView), Toolkit::ImageView::Property::IMAGE);
2169   Property::Map         returnedMap;
2170   visual.CreatePropertyMap(returnedMap);
2171
2172   Property::Value* value = returnedMap.Find(Toolkit::Visual::Property::TRANSFORM);
2173   DALI_TEST_CHECK(value);
2174   Property::Map* map = value->GetMap();
2175   DALI_TEST_CHECK(map);
2176
2177   value = map->Find(Toolkit::Visual::Transform::Property::SIZE);
2178   DALI_TEST_CHECK(value);
2179   DALI_TEST_EQUALS(value->Get<Vector2>(), Vector2(600, 700), TEST_LOCATION); // Change the internal size according to the image view size
2180
2181   value = map->Find(Toolkit::Visual::Transform::Property::SIZE_POLICY);
2182   DALI_TEST_CHECK(value);
2183   DALI_TEST_EQUALS(value->Get<Vector2>(), Vector2(Toolkit::Visual::Transform::Policy::ABSOLUTE, Toolkit::Visual::Transform::Policy::ABSOLUTE), TEST_LOCATION);
2184
2185   value = map->Find(Toolkit::Visual::Transform::Property::OFFSET);
2186   DALI_TEST_CHECK(value);
2187   DALI_TEST_EQUALS(value->Get<Vector2>(), Vector2(0, 0), TEST_LOCATION); // OFFSET is zero
2188
2189   END_TEST;
2190 }
2191
2192 int UtcDaliImageViewFittingModesFitHeight02(void)
2193 {
2194   ToolkitTestApplication application;
2195
2196   tet_infoline("Create an ImageVisual using FitHeight ( image: [600,600], view: [700,600] )");
2197
2198   ImageView     imageView = ImageView::New();
2199   Property::Map imageMap;
2200   imageMap.Add(Toolkit::Visual::Property::TYPE, Toolkit::Visual::IMAGE);
2201   imageMap.Add(Toolkit::ImageVisual::Property::URL, gImage_600_RGB); // 249x169 image
2202   imageMap.Add(DevelVisual::Property::VISUAL_FITTING_MODE, Toolkit::DevelVisual::FIT_HEIGHT);
2203
2204   imageView.SetProperty(Toolkit::ImageView::Property::IMAGE, imageMap);
2205   imageView.SetProperty(Actor::Property::SIZE, Vector2(700, 600));
2206
2207   application.GetScene().Add(imageView);
2208
2209   // Trigger a potential relayout
2210   application.SendNotification();
2211   application.Render();
2212
2213   Toolkit::Visual::Base visual = DevelControl::GetVisual(Toolkit::Internal::GetImplementation(imageView), Toolkit::ImageView::Property::IMAGE);
2214   Property::Map         returnedMap;
2215   visual.CreatePropertyMap(returnedMap);
2216
2217   Property::Value* value = returnedMap.Find(Toolkit::Visual::Property::TRANSFORM);
2218   DALI_TEST_CHECK(value);
2219   Property::Map* map = value->GetMap();
2220   DALI_TEST_CHECK(map);
2221
2222   value = map->Find(Toolkit::Visual::Transform::Property::SIZE);
2223   DALI_TEST_CHECK(value);
2224   DALI_TEST_EQUALS(value->Get<Vector2>(), Vector2(600, 600), TEST_LOCATION); // Change the internal size according to the image view size
2225
2226   value = map->Find(Toolkit::Visual::Transform::Property::SIZE_POLICY);
2227   DALI_TEST_CHECK(value);
2228   DALI_TEST_EQUALS(value->Get<Vector2>(), Vector2(Toolkit::Visual::Transform::Policy::ABSOLUTE, Toolkit::Visual::Transform::Policy::ABSOLUTE), TEST_LOCATION);
2229
2230   value = map->Find(Toolkit::Visual::Transform::Property::OFFSET);
2231   DALI_TEST_CHECK(value);
2232   DALI_TEST_EQUALS(value->Get<Vector2>(), Vector2(50, 0), TEST_LOCATION);
2233
2234   END_TEST;
2235 }
2236
2237 int UtcDaliImageViewFittingModesFitWidth01(void)
2238 {
2239   ToolkitTestApplication application;
2240
2241   tet_infoline("Create an ImageVisual using FitWidth ( image: [600,600], view: [600,700] )");
2242
2243   ImageView     imageView = ImageView::New();
2244   Property::Map imageMap;
2245   imageMap.Add(Toolkit::Visual::Property::TYPE, Toolkit::Visual::IMAGE);
2246   imageMap.Add(Toolkit::ImageVisual::Property::URL, gImage_600_RGB); // 600x600 image
2247   imageMap.Add(DevelVisual::Property::VISUAL_FITTING_MODE, Toolkit::DevelVisual::FIT_WIDTH);
2248
2249   imageView.SetProperty(Toolkit::ImageView::Property::IMAGE, imageMap);
2250   imageView.SetProperty(Actor::Property::SIZE, Vector2(600, 700));
2251
2252   application.GetScene().Add(imageView);
2253
2254   // Trigger a potential relayout
2255   application.SendNotification();
2256   application.Render();
2257
2258   Toolkit::Visual::Base visual = DevelControl::GetVisual(Toolkit::Internal::GetImplementation(imageView), Toolkit::ImageView::Property::IMAGE);
2259   Property::Map         returnedMap;
2260   visual.CreatePropertyMap(returnedMap);
2261
2262   Property::Value* value = returnedMap.Find(Toolkit::Visual::Property::TRANSFORM);
2263   DALI_TEST_CHECK(value);
2264   Property::Map* map = value->GetMap();
2265   DALI_TEST_CHECK(map);
2266
2267   value = map->Find(Toolkit::Visual::Transform::Property::SIZE);
2268   DALI_TEST_CHECK(value);
2269   DALI_TEST_EQUALS(value->Get<Vector2>(), Vector2(600, 600), TEST_LOCATION); // Change the internal size according to the image view size
2270
2271   value = map->Find(Toolkit::Visual::Transform::Property::SIZE_POLICY);
2272   DALI_TEST_CHECK(value);
2273   DALI_TEST_EQUALS(value->Get<Vector2>(), Vector2(Toolkit::Visual::Transform::Policy::ABSOLUTE, Toolkit::Visual::Transform::Policy::ABSOLUTE), TEST_LOCATION);
2274
2275   value = map->Find(Toolkit::Visual::Transform::Property::OFFSET);
2276   DALI_TEST_CHECK(value);
2277   DALI_TEST_EQUALS(value->Get<Vector2>(), Vector2(0, 50), TEST_LOCATION);
2278
2279   END_TEST;
2280 }
2281
2282 int UtcDaliImageViewFittingModesFitWidth02(void)
2283 {
2284   ToolkitTestApplication application;
2285
2286   tet_infoline("Create an ImageVisual using FitWidth ( image: [600,600], view:[700,600] )");
2287
2288   ImageView     imageView = ImageView::New();
2289   Property::Map imageMap;
2290   imageMap.Add(Toolkit::Visual::Property::TYPE, Toolkit::Visual::IMAGE);
2291   imageMap.Add(Toolkit::ImageVisual::Property::URL, gImage_600_RGB); // 249x169 image
2292   imageMap.Add(DevelVisual::Property::VISUAL_FITTING_MODE, Toolkit::DevelVisual::FIT_WIDTH);
2293
2294   imageView.SetProperty(Toolkit::ImageView::Property::IMAGE, imageMap);
2295   imageView.SetProperty(Actor::Property::SIZE, Vector2(700, 600));
2296
2297   application.GetScene().Add(imageView);
2298
2299   // Trigger a potential relayout
2300   application.SendNotification();
2301   application.Render();
2302
2303   Toolkit::Visual::Base visual = DevelControl::GetVisual(Toolkit::Internal::GetImplementation(imageView), Toolkit::ImageView::Property::IMAGE);
2304   Property::Map         returnedMap;
2305   visual.CreatePropertyMap(returnedMap);
2306
2307   Property::Value* value = returnedMap.Find(Toolkit::Visual::Property::TRANSFORM);
2308   DALI_TEST_CHECK(value);
2309   Property::Map* map = value->GetMap();
2310   DALI_TEST_CHECK(map);
2311
2312   value = map->Find(Toolkit::Visual::Transform::Property::SIZE);
2313   DALI_TEST_CHECK(value);
2314   DALI_TEST_EQUALS(value->Get<Vector2>(), Vector2(700, 600), TEST_LOCATION); // Change the internal size according to the image view size
2315
2316   value = map->Find(Toolkit::Visual::Transform::Property::SIZE_POLICY);
2317   DALI_TEST_CHECK(value);
2318   DALI_TEST_EQUALS(value->Get<Vector2>(), Vector2(Toolkit::Visual::Transform::Policy::ABSOLUTE, Toolkit::Visual::Transform::Policy::ABSOLUTE), TEST_LOCATION);
2319
2320   value = map->Find(Toolkit::Visual::Transform::Property::OFFSET);
2321   DALI_TEST_CHECK(value);
2322   DALI_TEST_EQUALS(value->Get<Vector2>(), Vector2(0, 0), TEST_LOCATION); // OFFSET is zero
2323
2324   END_TEST;
2325 }
2326
2327 int UtcDaliImageViewFittingModesChangeFittingMode01(void)
2328 {
2329   ToolkitTestApplication application;
2330
2331   tet_infoline("UtcDaliImageViewFittingModesChangeFittingMode, image: [600,600], view:[800,700]");
2332
2333   ImageView imageView = ImageView::New();
2334
2335   // 1. Render using FittingMode::SHRINK_TO_FIT
2336   Property::Map imageMap;
2337   imageMap[Toolkit::Visual::Property::TYPE]            = Toolkit::Visual::IMAGE;
2338   imageMap[Toolkit::ImageVisual::Property::URL]        = gImage_600_RGB;
2339   imageMap[DevelVisual::Property::VISUAL_FITTING_MODE] = Toolkit::DevelVisual::FIT_KEEP_ASPECT_RATIO;
2340
2341   imageView.SetProperty(Toolkit::ImageView::Property::IMAGE, imageMap);
2342   imageView.SetProperty(Actor::Property::SIZE, Vector2(800, 700));
2343
2344   application.GetScene().Add(imageView);
2345
2346   // Trigger a potential relayout
2347   application.SendNotification();
2348   application.Render();
2349
2350   Toolkit::Visual::Base visual = DevelControl::GetVisual(Toolkit::Internal::GetImplementation(imageView), Toolkit::ImageView::Property::IMAGE);
2351   Property::Map         returnedMap;
2352   visual.CreatePropertyMap(returnedMap);
2353
2354   Property::Value* value = returnedMap.Find(Toolkit::Visual::Property::TRANSFORM);
2355   DALI_TEST_CHECK(value);
2356   Property::Map* map = value->GetMap();
2357   DALI_TEST_CHECK(map);
2358
2359   value = map->Find(Toolkit::Visual::Transform::Property::SIZE);
2360   DALI_TEST_CHECK(value);
2361   DALI_TEST_EQUALS(value->Get<Vector2>(), Vector2(700, 700), TEST_LOCATION); // Change the internal size according to the image view size
2362
2363   value = map->Find(Toolkit::Visual::Transform::Property::SIZE_POLICY);
2364   DALI_TEST_CHECK(value);
2365   DALI_TEST_EQUALS(value->Get<Vector2>(), Vector2(Toolkit::Visual::Transform::Policy::ABSOLUTE, Toolkit::Visual::Transform::Policy::ABSOLUTE), TEST_LOCATION);
2366
2367   value = map->Find(Toolkit::Visual::Transform::Property::OFFSET);
2368   DALI_TEST_CHECK(value);
2369   DALI_TEST_EQUALS(value->Get<Vector2>(), Vector2(50, 0), TEST_LOCATION);
2370
2371   // 2. Render again using DevelVisaul::CENTER
2372   Property::Map imageMap2;
2373   imageMap2[Toolkit::Visual::Property::TYPE]            = Toolkit::Visual::IMAGE;
2374   imageMap2[Toolkit::ImageVisual::Property::URL]        = gImage_600_RGB;
2375   imageMap2[DevelVisual::Property::VISUAL_FITTING_MODE] = Toolkit::DevelVisual::CENTER;
2376
2377   imageView.SetProperty(Toolkit::ImageView::Property::IMAGE, imageMap2);
2378   imageView.SetProperty(Actor::Property::SIZE, Vector2(800, 700));
2379
2380   application.GetScene().Add(imageView);
2381
2382   DALI_TEST_EQUALS(Test::WaitForEventThreadTrigger(1), true, TEST_LOCATION);
2383
2384   // Trigger a potential relayout
2385   application.SendNotification();
2386   application.Render();
2387
2388   returnedMap.Clear();
2389   visual = DevelControl::GetVisual(Toolkit::Internal::GetImplementation(imageView), Toolkit::ImageView::Property::IMAGE);
2390
2391   visual.CreatePropertyMap(returnedMap);
2392
2393   value = returnedMap.Find(Toolkit::Visual::Property::TRANSFORM);
2394   DALI_TEST_CHECK(value);
2395   map = value->GetMap();
2396   DALI_TEST_CHECK(map);
2397
2398   value = map->Find(Toolkit::Visual::Transform::Property::SIZE);
2399   DALI_TEST_CHECK(value);
2400   DALI_TEST_EQUALS(value->Get<Vector2>(), Vector2(600, 600), TEST_LOCATION); // Change the internal size according to the image view size
2401
2402   value = map->Find(Toolkit::Visual::Transform::Property::SIZE_POLICY);
2403   DALI_TEST_CHECK(value);
2404   DALI_TEST_EQUALS(value->Get<Vector2>(), Vector2(Toolkit::Visual::Transform::Policy::ABSOLUTE, Toolkit::Visual::Transform::Policy::ABSOLUTE), TEST_LOCATION);
2405
2406   value = map->Find(Toolkit::Visual::Transform::Property::OFFSET);
2407   DALI_TEST_CHECK(value);
2408   DALI_TEST_EQUALS(value->Get<Vector2>(), Vector2(100, 50), TEST_LOCATION);
2409
2410   // 3. Render again using before fittingMode
2411   Property::Map imageMap3;
2412   imageMap3[Toolkit::Visual::Property::TYPE]            = Toolkit::Visual::IMAGE;
2413   imageMap3[Toolkit::ImageVisual::Property::URL]        = gImage_600_RGB;
2414   imageMap3[DevelVisual::Property::VISUAL_FITTING_MODE] = Toolkit::DevelVisual::FIT_KEEP_ASPECT_RATIO;
2415
2416   imageView.SetProperty(Toolkit::ImageView::Property::IMAGE, imageMap3);
2417   imageView.SetProperty(Actor::Property::SIZE, Vector2(800, 700));
2418
2419   application.GetScene().Add(imageView);
2420
2421   // Trigger a potential relayout
2422   application.SendNotification();
2423   application.Render();
2424
2425   returnedMap.Clear();
2426   visual = DevelControl::GetVisual(Toolkit::Internal::GetImplementation(imageView), Toolkit::ImageView::Property::IMAGE);
2427   visual.CreatePropertyMap(returnedMap);
2428
2429   value = returnedMap.Find(Toolkit::Visual::Property::TRANSFORM);
2430   DALI_TEST_CHECK(value);
2431   map = value->GetMap();
2432   DALI_TEST_CHECK(map);
2433
2434   value = map->Find(Toolkit::Visual::Transform::Property::SIZE);
2435   DALI_TEST_CHECK(value);
2436   DALI_TEST_EQUALS(value->Get<Vector2>(), Vector2(700, 700), TEST_LOCATION); // Change the internal size according to the image view size
2437
2438   value = map->Find(Toolkit::Visual::Transform::Property::SIZE_POLICY);
2439   DALI_TEST_CHECK(value);
2440   DALI_TEST_EQUALS(value->Get<Vector2>(), Vector2(Toolkit::Visual::Transform::Policy::ABSOLUTE, Toolkit::Visual::Transform::Policy::ABSOLUTE), TEST_LOCATION);
2441
2442   value = map->Find(Toolkit::Visual::Transform::Property::OFFSET);
2443   DALI_TEST_CHECK(value);
2444   DALI_TEST_EQUALS(value->Get<Vector2>(), Vector2(50, 0), TEST_LOCATION);
2445
2446   END_TEST;
2447 }
2448
2449 int UtcDaliImageViewFittingModesChangeFittingMode02(void)
2450 {
2451   ToolkitTestApplication application;
2452
2453   tet_infoline("UtcDaliImageViewFittingModesChangeFittingMode, image: [600,600], view:[800,700]");
2454
2455   ImageView imageView = ImageView::New();
2456
2457   // 1. Render using FittingMode::OVER_FIT_KEEP_ASPECT_RATIO
2458   Property::Map imageMap;
2459   imageMap[Toolkit::Visual::Property::TYPE]            = Toolkit::Visual::IMAGE;
2460   imageMap[Toolkit::ImageVisual::Property::URL]        = gImage_600_RGB;
2461   imageMap[DevelVisual::Property::VISUAL_FITTING_MODE] = Toolkit::DevelVisual::OVER_FIT_KEEP_ASPECT_RATIO;
2462
2463   imageView.SetProperty(Toolkit::ImageView::Property::IMAGE, imageMap);
2464   imageView.SetProperty(Actor::Property::SIZE, Vector2(800, 700));
2465
2466   application.GetScene().Add(imageView);
2467
2468   // Trigger a potential relayout
2469   application.SendNotification();
2470   application.Render();
2471
2472   Toolkit::Visual::Base visual = DevelControl::GetVisual(Toolkit::Internal::GetImplementation(imageView), Toolkit::ImageView::Property::IMAGE);
2473   Property::Map         returnedMap;
2474   visual.CreatePropertyMap(returnedMap);
2475
2476   Property::Value* value = returnedMap.Find(Toolkit::Visual::Property::TRANSFORM);
2477   DALI_TEST_CHECK(value);
2478   Property::Map* map = value->GetMap();
2479   DALI_TEST_CHECK(map);
2480
2481   value = map->Find(Toolkit::Visual::Transform::Property::SIZE);
2482   DALI_TEST_CHECK(value);
2483   DALI_TEST_EQUALS(value->Get<Vector2>(), Vector2(800, 700), TEST_LOCATION); // Change the internal size according to the image view size
2484
2485   value = map->Find(Toolkit::Visual::Transform::Property::SIZE_POLICY);
2486   DALI_TEST_CHECK(value);
2487   DALI_TEST_EQUALS(value->Get<Vector2>(), Vector2(Toolkit::Visual::Transform::Policy::ABSOLUTE, Toolkit::Visual::Transform::Policy::ABSOLUTE), TEST_LOCATION);
2488
2489   value = map->Find(Toolkit::Visual::Transform::Property::OFFSET);
2490   DALI_TEST_CHECK(value);
2491   DALI_TEST_EQUALS(value->Get<Vector2>(), Vector2(0, 0), TEST_LOCATION);
2492
2493   // 2. Render again using DevelVisaul::CENTER
2494   Property::Map imageMap2;
2495   imageMap2[Toolkit::Visual::Property::TYPE]            = Toolkit::Visual::IMAGE;
2496   imageMap2[Toolkit::ImageVisual::Property::URL]        = gImage_600_RGB;
2497   imageMap2[DevelVisual::Property::VISUAL_FITTING_MODE] = Toolkit::DevelVisual::CENTER;
2498
2499   imageView.SetProperty(Toolkit::ImageView::Property::IMAGE, imageMap2);
2500   imageView.SetProperty(Actor::Property::SIZE, Vector2(800, 700));
2501
2502   application.GetScene().Add(imageView);
2503
2504   DALI_TEST_EQUALS(Test::WaitForEventThreadTrigger(1), true, TEST_LOCATION);
2505
2506   // Trigger a potential relayout
2507   application.SendNotification();
2508   application.Render();
2509
2510   returnedMap.Clear();
2511   visual = DevelControl::GetVisual(Toolkit::Internal::GetImplementation(imageView), Toolkit::ImageView::Property::IMAGE);
2512
2513   visual.CreatePropertyMap(returnedMap);
2514
2515   value = returnedMap.Find(Toolkit::Visual::Property::TRANSFORM);
2516   DALI_TEST_CHECK(value);
2517   map = value->GetMap();
2518   DALI_TEST_CHECK(map);
2519
2520   value = map->Find(Toolkit::Visual::Transform::Property::SIZE);
2521   DALI_TEST_CHECK(value);
2522   DALI_TEST_EQUALS(value->Get<Vector2>(), Vector2(600, 600), TEST_LOCATION); // Change the internal size according to the image view size
2523
2524   value = map->Find(Toolkit::Visual::Transform::Property::SIZE_POLICY);
2525   DALI_TEST_CHECK(value);
2526   DALI_TEST_EQUALS(value->Get<Vector2>(), Vector2(Toolkit::Visual::Transform::Policy::ABSOLUTE, Toolkit::Visual::Transform::Policy::ABSOLUTE), TEST_LOCATION);
2527
2528   value = map->Find(Toolkit::Visual::Transform::Property::OFFSET);
2529   DALI_TEST_CHECK(value);
2530   DALI_TEST_EQUALS(value->Get<Vector2>(), Vector2(100, 50), TEST_LOCATION);
2531
2532   // 3. Render again using before fittingMode
2533   Property::Map imageMap3;
2534   imageMap3[Toolkit::Visual::Property::TYPE]            = Toolkit::Visual::IMAGE;
2535   imageMap3[Toolkit::ImageVisual::Property::URL]        = gImage_600_RGB;
2536   imageMap3[DevelVisual::Property::VISUAL_FITTING_MODE] = Toolkit::DevelVisual::OVER_FIT_KEEP_ASPECT_RATIO;
2537
2538   imageView.SetProperty(Toolkit::ImageView::Property::IMAGE, imageMap3);
2539   imageView.SetProperty(Actor::Property::SIZE, Vector2(800, 700));
2540
2541   application.GetScene().Add(imageView);
2542
2543   // Trigger a potential relayout
2544   application.SendNotification();
2545   application.Render();
2546
2547   returnedMap.Clear();
2548   visual = DevelControl::GetVisual(Toolkit::Internal::GetImplementation(imageView), Toolkit::ImageView::Property::IMAGE);
2549   visual.CreatePropertyMap(returnedMap);
2550
2551   value = returnedMap.Find(Toolkit::Visual::Property::TRANSFORM);
2552   DALI_TEST_CHECK(value);
2553   map = value->GetMap();
2554   DALI_TEST_CHECK(map);
2555
2556   value = map->Find(Toolkit::Visual::Transform::Property::SIZE);
2557   DALI_TEST_CHECK(value);
2558   DALI_TEST_EQUALS(value->Get<Vector2>(), Vector2(800, 700), TEST_LOCATION); // Change the internal size according to the image view size
2559
2560   value = map->Find(Toolkit::Visual::Transform::Property::SIZE_POLICY);
2561   DALI_TEST_CHECK(value);
2562   DALI_TEST_EQUALS(value->Get<Vector2>(), Vector2(Toolkit::Visual::Transform::Policy::ABSOLUTE, Toolkit::Visual::Transform::Policy::ABSOLUTE), TEST_LOCATION);
2563
2564   value = map->Find(Toolkit::Visual::Transform::Property::OFFSET);
2565   DALI_TEST_CHECK(value);
2566   DALI_TEST_EQUALS(value->Get<Vector2>(), Vector2(0, 0), TEST_LOCATION);
2567
2568   END_TEST;
2569 }
2570
2571 int UtcDaliImageViewFittingModesWithAnimatedVectorImageVisual(void)
2572 {
2573   ToolkitTestApplication application;
2574
2575   tet_infoline("Create an ImageVisual using SCALE_TO_FILL and animated vector image ( image: [600,600], view:[600,600] )");
2576
2577   ImageView     imageView = ImageView::New();
2578   Property::Map imageMap;
2579   imageMap.Add(Toolkit::Visual::Property::TYPE, DevelVisual::ANIMATED_VECTOR_IMAGE);
2580   imageMap.Add(Toolkit::ImageVisual::Property::URL, TEST_ANIMATED_VECTOR_IMAGE_FILE_NAME); // 249x169 image
2581
2582   imageView.SetProperty(Toolkit::ImageView::Property::IMAGE, imageMap);
2583   imageView.SetProperty(Actor::Property::SIZE, Vector2(600, 600));
2584
2585   application.GetScene().Add(imageView);
2586
2587   // Trigger a potential relayout
2588   application.SendNotification();
2589   application.Render();
2590
2591   Toolkit::Visual::Base visual = DevelControl::GetVisual(Toolkit::Internal::GetImplementation(imageView), Toolkit::ImageView::Property::IMAGE);
2592   Property::Map         returnedMap;
2593   visual.CreatePropertyMap(returnedMap);
2594
2595   Property::Value* value = returnedMap.Find(Toolkit::Visual::Property::TRANSFORM);
2596   DALI_TEST_CHECK(value);
2597   Property::Map* map = value->GetMap();
2598   DALI_TEST_CHECK(map);
2599
2600   value = map->Find(Toolkit::Visual::Transform::Property::SIZE);
2601   DALI_TEST_CHECK(value);
2602   DALI_TEST_EQUALS(value->Get<Vector2>(), Vector2::ONE, TEST_LOCATION); // Relative size so will take up 100%
2603
2604   value = map->Find(Toolkit::Visual::Transform::Property::SIZE_POLICY);
2605   DALI_TEST_CHECK(value);
2606   DALI_TEST_CHECK(value->Get<int>() == Toolkit::Visual::Transform::Policy::RELATIVE);
2607
2608   value = map->Find(Toolkit::Visual::Transform::Property::OFFSET);
2609   DALI_TEST_CHECK(value);
2610   DALI_TEST_EQUALS(value->Get<Vector2>(), Vector2(0, 0), TEST_LOCATION); // OFFSET is zero
2611
2612   END_TEST;
2613 }
2614
2615 int UtcDaliImageViewCustomShader(void)
2616 {
2617   ToolkitTestApplication application;
2618
2619   // Set a custom shader with an image url
2620   {
2621     Property::Map     properties;
2622     Property::Map     shader;
2623     const std::string vertexShader                    = "Foobar";
2624     const std::string fragmentShader                  = "Foobar";
2625     shader[Visual::Shader::Property::FRAGMENT_SHADER] = fragmentShader;
2626     shader[Visual::Shader::Property::VERTEX_SHADER]   = vertexShader;
2627
2628     properties[Visual::Property::TYPE]     = Visual::IMAGE;
2629     properties[Visual::Property::SHADER]   = shader;
2630     properties[ImageVisual::Property::URL] = TEST_IMAGE_FILE_NAME;
2631
2632     ImageView imageView = ImageView::New();
2633     imageView.SetProperty(ImageView::Property::IMAGE, properties);
2634
2635     application.GetScene().Add(imageView);
2636
2637     application.SendNotification();
2638     application.Render();
2639
2640     DALI_TEST_EQUALS(Test::WaitForEventThreadTrigger(1), true, TEST_LOCATION);
2641
2642     Renderer        renderer = imageView.GetRendererAt(0);
2643     Shader          shader2  = renderer.GetShader();
2644     Property::Value value    = shader2.GetProperty(Shader::Property::PROGRAM);
2645     Property::Map*  map      = value.GetMap();
2646     DALI_TEST_CHECK(map);
2647
2648     Property::Value* fragment = map->Find("fragment"); // fragment key name from shader-impl.cpp
2649     DALI_TEST_EQUALS(fragmentShader, fragment->Get<std::string>(), TEST_LOCATION);
2650
2651     Property::Value* vertex = map->Find("vertex"); // vertex key name from shader-impl.cpp
2652     DALI_TEST_EQUALS(vertexShader, vertex->Get<std::string>(), TEST_LOCATION);
2653   }
2654
2655   // Set a custom shader after setting an image url
2656   {
2657     Property::Map     properties;
2658     Property::Map     shader;
2659     const std::string vertexShader                    = "Foobar";
2660     const std::string fragmentShader                  = "Foobar";
2661     shader[Visual::Shader::Property::FRAGMENT_SHADER] = fragmentShader;
2662     shader[Visual::Shader::Property::VERTEX_SHADER]   = vertexShader;
2663
2664     properties[Visual::Property::SHADER] = shader;
2665
2666     ImageView imageView = ImageView::New(TEST_IMAGE_FILE_NAME);
2667     imageView.SetProperty(ImageView::Property::IMAGE, properties);
2668
2669     application.GetScene().Add(imageView);
2670
2671     application.SendNotification();
2672     application.Render();
2673
2674     DALI_TEST_EQUALS(Test::WaitForEventThreadTrigger(1), true, TEST_LOCATION);
2675
2676     Renderer        renderer = imageView.GetRendererAt(0);
2677     Shader          shader2  = renderer.GetShader();
2678     Property::Value value    = shader2.GetProperty(Shader::Property::PROGRAM);
2679     Property::Map*  map      = value.GetMap();
2680     DALI_TEST_CHECK(map);
2681
2682     Property::Value* fragment = map->Find("fragment"); // fragment key name from shader-impl.cpp
2683     DALI_TEST_EQUALS(fragmentShader, fragment->Get<std::string>(), TEST_LOCATION);
2684
2685     Property::Value* vertex = map->Find("vertex"); // vertex key name from shader-impl.cpp
2686     DALI_TEST_EQUALS(vertexShader, vertex->Get<std::string>(), TEST_LOCATION);
2687   }
2688
2689   // Set a custom shader before setting an image url
2690   {
2691     Property::Map     properties;
2692     Property::Map     shader;
2693     const std::string vertexShader                    = "Foobar";
2694     const std::string fragmentShader                  = "Foobar";
2695     shader[Visual::Shader::Property::FRAGMENT_SHADER] = fragmentShader;
2696     shader[Visual::Shader::Property::VERTEX_SHADER]   = vertexShader;
2697
2698     properties[Visual::Property::SHADER] = shader;
2699
2700     ImageView imageView = ImageView::New();
2701     imageView.SetProperty(ImageView::Property::IMAGE, properties);
2702     imageView.SetProperty(ImageView::Property::IMAGE, TEST_IMAGE_FILE_NAME);
2703
2704     application.GetScene().Add(imageView);
2705
2706     application.SendNotification();
2707     application.Render();
2708     DALI_TEST_EQUALS(Test::WaitForEventThreadTrigger(1), true, TEST_LOCATION);
2709
2710     Renderer        renderer = imageView.GetRendererAt(0);
2711     Shader          shader2  = renderer.GetShader();
2712     Property::Value value    = shader2.GetProperty(Shader::Property::PROGRAM);
2713     Property::Map*  map      = value.GetMap();
2714     DALI_TEST_CHECK(map);
2715
2716     Property::Value* fragment = map->Find("fragment"); // fragment key name from shader-impl.cpp
2717     DALI_TEST_EQUALS(fragmentShader, fragment->Get<std::string>(), TEST_LOCATION);
2718
2719     Property::Value* vertex = map->Find("vertex"); // vertex key name from shader-impl.cpp
2720     DALI_TEST_EQUALS(vertexShader, vertex->Get<std::string>(), TEST_LOCATION);
2721   }
2722
2723   // Set a custom shader after setting a property map
2724   {
2725     Property::Map     properties;
2726     Property::Map     shader;
2727     const std::string vertexShader                    = "Foobar";
2728     const std::string fragmentShader                  = "Foobar";
2729     shader[Visual::Shader::Property::FRAGMENT_SHADER] = fragmentShader;
2730     shader[Visual::Shader::Property::VERTEX_SHADER]   = vertexShader;
2731
2732     properties[Visual::Property::SHADER] = shader;
2733
2734     Property::Map properties1;
2735     properties1[Visual::Property::TYPE]     = Visual::IMAGE;
2736     properties1[ImageVisual::Property::URL] = TEST_IMAGE_FILE_NAME;
2737
2738     ImageView imageView = ImageView::New();
2739     imageView.SetProperty(ImageView::Property::IMAGE, properties1);
2740     imageView.SetProperty(ImageView::Property::IMAGE, properties);
2741
2742     application.GetScene().Add(imageView);
2743
2744     application.SendNotification();
2745     application.Render();
2746     DALI_TEST_EQUALS(Test::WaitForEventThreadTrigger(1), true, TEST_LOCATION);
2747
2748     Renderer        renderer = imageView.GetRendererAt(0);
2749     Shader          shader2  = renderer.GetShader();
2750     Property::Value value    = shader2.GetProperty(Shader::Property::PROGRAM);
2751     Property::Map*  map      = value.GetMap();
2752     DALI_TEST_CHECK(map);
2753
2754     Property::Value* fragment = map->Find("fragment"); // fragment key name from shader-impl.cpp
2755     DALI_TEST_EQUALS(fragmentShader, fragment->Get<std::string>(), TEST_LOCATION);
2756
2757     Property::Value* vertex = map->Find("vertex"); // vertex key name from shader-impl.cpp
2758     DALI_TEST_EQUALS(vertexShader, vertex->Get<std::string>(), TEST_LOCATION);
2759   }
2760
2761   // Set a custom shader before setting a property map
2762   {
2763     Property::Map     properties;
2764     Property::Map     shader;
2765     const std::string vertexShader                    = "Foobar";
2766     const std::string fragmentShader                  = "Foobar";
2767     shader[Visual::Shader::Property::FRAGMENT_SHADER] = fragmentShader;
2768     shader[Visual::Shader::Property::VERTEX_SHADER]   = vertexShader;
2769
2770     properties[Visual::Property::SHADER] = shader;
2771
2772     Property::Map properties1;
2773     properties1[Visual::Property::TYPE]     = Visual::IMAGE;
2774     properties1[ImageVisual::Property::URL] = TEST_IMAGE_FILE_NAME;
2775
2776     ImageView imageView = ImageView::New();
2777     imageView.SetProperty(ImageView::Property::IMAGE, properties);
2778     imageView.SetProperty(ImageView::Property::IMAGE, properties1);
2779
2780     application.GetScene().Add(imageView);
2781
2782     application.SendNotification();
2783     application.Render();
2784     DALI_TEST_EQUALS(Test::WaitForEventThreadTrigger(1), true, TEST_LOCATION);
2785
2786     Renderer        renderer = imageView.GetRendererAt(0);
2787     Shader          shader2  = renderer.GetShader();
2788     Property::Value value    = shader2.GetProperty(Shader::Property::PROGRAM);
2789     Property::Map*  map      = value.GetMap();
2790     DALI_TEST_CHECK(map);
2791
2792     Property::Value* fragment = map->Find("fragment"); // fragment key name from shader-impl.cpp
2793     DALI_TEST_EQUALS(fragmentShader, fragment->Get<std::string>(), TEST_LOCATION);
2794
2795     Property::Value* vertex = map->Find("vertex"); // vertex key name from shader-impl.cpp
2796     DALI_TEST_EQUALS(vertexShader, vertex->Get<std::string>(), TEST_LOCATION);
2797   }
2798
2799   END_TEST;
2800 }
2801
2802 namespace
2803 {
2804 static int gFailCounter = 0;
2805 const int  MAX_RETRIES(3);
2806
2807 void ReloadImage(ImageView imageView)
2808 {
2809   Property::Map imageImmediateLoadingMap;
2810   imageImmediateLoadingMap[ImageVisual::Property::URL]         = "Non-existant-image.jpg";
2811   imageImmediateLoadingMap[ImageVisual::Property::LOAD_POLICY] = ImageVisual::LoadPolicy::IMMEDIATE;
2812
2813   tet_infoline("Immediate load an image");
2814   imageView.SetProperty(ImageView::Property::IMAGE, imageImmediateLoadingMap);
2815 }
2816
2817 void ResourceFailedReload(Control control)
2818 {
2819   gFailCounter++;
2820 }
2821 } // namespace
2822
2823 int UtcDaliImageViewReloadFailedOnResourceReadySignal(void)
2824 {
2825   tet_infoline("Test reloading failed image from within signal handler.");
2826
2827   ToolkitTestApplication application;
2828
2829   gFailCounter = 0;
2830
2831   ImageView imageView = ImageView::New();
2832   imageView.ResourceReadySignal().Connect(&ResourceFailedReload);
2833   DALI_TEST_EQUALS(gFailCounter, 0, TEST_LOCATION);
2834   ReloadImage(imageView);
2835
2836   // loading started, this waits for the loader thread to complete
2837   DALI_TEST_EQUALS(Test::WaitForEventThreadTrigger(1), true, TEST_LOCATION);
2838   DALI_TEST_EQUALS(gFailCounter, 1, TEST_LOCATION);
2839
2840   ReloadImage(imageView);
2841   DALI_TEST_EQUALS(Test::WaitForEventThreadTrigger(1), true, TEST_LOCATION);
2842   DALI_TEST_EQUALS(gFailCounter, 2, TEST_LOCATION);
2843
2844   ReloadImage(imageView);
2845   DALI_TEST_EQUALS(Test::WaitForEventThreadTrigger(1), true, TEST_LOCATION);
2846   DALI_TEST_EQUALS(gFailCounter, 3, TEST_LOCATION);
2847
2848   END_TEST;
2849 }
2850
2851 int UtcDaliImageViewLoadRemoteSVG(void)
2852 {
2853   tet_infoline("Test load from a remote server.");
2854
2855   ToolkitTestApplication application;
2856
2857   {
2858     Toolkit::ImageView imageView;
2859     imageView = Toolkit::ImageView::New();
2860     imageView.SetImage("https://dev.w3.org/SVG/tools/svgweb/samples/svg-files/check.svg");
2861     imageView.SetProperty(Actor::Property::PARENT_ORIGIN, ParentOrigin::TOP_LEFT);
2862     imageView.SetProperty(Actor::Property::ANCHOR_POINT, AnchorPoint::TOP_LEFT);
2863     imageView.SetProperty(Actor::Property::SIZE, Vector2(300, 300));
2864     imageView.SetProperty(Actor::Property::POSITION, Vector3(150.0f, 150.0f, 0.0f));
2865
2866     application.GetScene().Add(imageView);
2867
2868     DALI_TEST_CHECK(imageView);
2869
2870     DALI_TEST_EQUALS(imageView.GetRendererCount(), 0u, TEST_LOCATION);
2871
2872     application.SendNotification();
2873
2874     // Wait for loading & rasterization
2875     DALI_TEST_EQUALS(Test::WaitForEventThreadTrigger(2), true, TEST_LOCATION);
2876
2877     application.SendNotification();
2878     application.Render();
2879
2880     DALI_TEST_EQUALS(imageView.GetRendererCount(), 1u, TEST_LOCATION);
2881   }
2882
2883   // Without size set
2884   {
2885     Toolkit::ImageView imageView;
2886     imageView = Toolkit::ImageView::New();
2887     imageView.SetImage("https://dev.w3.org/SVG/tools/svgweb/samples/svg-files/check.svg");
2888     imageView.SetProperty(Actor::Property::PARENT_ORIGIN, ParentOrigin::TOP_LEFT);
2889     imageView.SetProperty(Actor::Property::ANCHOR_POINT, AnchorPoint::TOP_LEFT);
2890     imageView.SetProperty(Actor::Property::POSITION, Vector3(150.0f, 150.0f, 0.0f));
2891
2892     application.GetScene().Add(imageView);
2893
2894     DALI_TEST_CHECK(imageView);
2895
2896     DALI_TEST_EQUALS(imageView.GetRendererCount(), 0u, TEST_LOCATION);
2897
2898     application.SendNotification();
2899
2900     // Wait for loading & rasterization
2901     DALI_TEST_EQUALS(Test::WaitForEventThreadTrigger(2), true, TEST_LOCATION);
2902
2903     application.SendNotification();
2904     application.Render();
2905
2906     DALI_TEST_EQUALS(imageView.GetRendererCount(), 1u, TEST_LOCATION);
2907   }
2908
2909   END_TEST;
2910 }
2911
2912 int UtcDaliImageViewLoadRemoteLottie(void)
2913 {
2914   tet_infoline("Test load from a remote server. (Note we don't support real download now. Just for line coverage)");
2915
2916   ToolkitTestApplication application;
2917
2918   {
2919     Toolkit::ImageView imageView;
2920     imageView = Toolkit::ImageView::New();
2921     imageView.SetImage("https://lottie.json");
2922     imageView.SetProperty(Actor::Property::PARENT_ORIGIN, ParentOrigin::TOP_LEFT);
2923     imageView.SetProperty(Actor::Property::ANCHOR_POINT, AnchorPoint::TOP_LEFT);
2924     imageView.SetProperty(Actor::Property::SIZE, Vector2(300, 300));
2925     imageView.SetProperty(Actor::Property::POSITION, Vector3(150.0f, 150.0f, 0.0f));
2926
2927     application.GetScene().Add(imageView);
2928
2929     DALI_TEST_CHECK(imageView);
2930
2931     application.SendNotification();
2932     application.Render();
2933
2934     // Do not check anything for here.
2935   }
2936
2937   END_TEST;
2938 }
2939
2940 int UtcDaliImageViewSyncSVGLoading(void)
2941 {
2942   ToolkitTestApplication application;
2943
2944   tet_infoline("ImageView Testing SVG image sync loading");
2945
2946   {
2947     ImageView imageView = ImageView::New();
2948
2949     // Sync loading is used
2950     Property::Map syncLoadingMap;
2951     syncLoadingMap.Insert(Toolkit::Visual::Property::TYPE, Toolkit::Visual::IMAGE);
2952     syncLoadingMap.Insert(Toolkit::ImageVisual::Property::URL, TEST_RESOURCE_DIR "/svg1.svg");
2953     syncLoadingMap.Insert(Toolkit::ImageVisual::Property::SYNCHRONOUS_LOADING, true);
2954     imageView.SetProperty(ImageView::Property::IMAGE, syncLoadingMap);
2955
2956     application.GetScene().Add(imageView);
2957     DALI_TEST_CHECK(imageView);
2958
2959     application.SendNotification();
2960     Vector3 naturalSize = imageView.GetNaturalSize();
2961
2962     DALI_TEST_EQUALS(naturalSize.width, 100.0f, TEST_LOCATION);
2963     DALI_TEST_EQUALS(naturalSize.height, 100.0f, TEST_LOCATION);
2964   }
2965   END_TEST;
2966 }
2967
2968 int UtcDaliImageViewSyncSVGLoading02(void)
2969 {
2970   ToolkitTestApplication application;
2971
2972   tet_infoline("ImageView Testing SVG image sync loading");
2973
2974   {
2975     ImageView imageView = ImageView::New();
2976
2977     // Sync loading is used
2978     Property::Map syncLoadingMap;
2979     syncLoadingMap.Insert(Toolkit::Visual::Property::TYPE, Toolkit::Visual::IMAGE);
2980     syncLoadingMap.Insert(Toolkit::ImageVisual::Property::URL, TEST_RESOURCE_DIR "/svg1.svg");
2981     syncLoadingMap.Insert(Toolkit::ImageVisual::Property::SYNCHRONOUS_LOADING, true);
2982     syncLoadingMap.Insert(DevelVisual::Property::VISUAL_FITTING_MODE, Toolkit::DevelVisual::FIT_KEEP_ASPECT_RATIO);
2983     imageView.SetProperty(ImageView::Property::IMAGE, syncLoadingMap);
2984     imageView.ResourceReadySignal().Connect(&OnResourceReadySignalSVG);
2985
2986     application.GetScene().Add(imageView);
2987     DALI_TEST_CHECK(imageView);
2988
2989     application.SendNotification();
2990     application.Render();
2991
2992     // Check whether Image Visual transforms on ImageVieiw::OnRelayout()
2993     Toolkit::Internal::Control& controlImpl = Toolkit::Internal::GetImplementation(imageView);
2994     Toolkit::Visual::Base       imageVisual = DevelControl::GetVisual(controlImpl, ImageView::Property::IMAGE);
2995     Property::Map               resultMap;
2996     imageVisual.CreatePropertyMap(resultMap);
2997
2998     Property::Value* transformValue = resultMap.Find(Visual::Property::TRANSFORM);
2999     DALI_TEST_CHECK(transformValue);
3000     Property::Map* retMap = transformValue->GetMap();
3001     DALI_TEST_CHECK(retMap);
3002
3003     // Image Visual should be positioned depending on ImageView's padding
3004     DALI_TEST_EQUALS(retMap->Find(Visual::Transform::Property::SIZE)->Get<Vector2>(), Vector2(100, 100), TEST_LOCATION);
3005
3006     Vector3 naturalSize = imageView.GetNaturalSize();
3007     DALI_TEST_EQUALS(naturalSize.width, 100.0f, TEST_LOCATION);
3008     DALI_TEST_EQUALS(naturalSize.height, 100.0f, TEST_LOCATION);
3009   }
3010   END_TEST;
3011 }
3012
3013 int UtcDaliImageViewAsyncSVGLoading(void)
3014 {
3015   ToolkitTestApplication application;
3016
3017   tet_infoline("ImageView Testing SVG image async loading");
3018
3019   {
3020     ImageView imageView = ImageView::New();
3021
3022     // Async loading is used - default value of SYNCHRONOUS_LOADING is false.
3023     Property::Map propertyMap;
3024     propertyMap.Insert(Toolkit::Visual::Property::TYPE, Toolkit::Visual::IMAGE);
3025     propertyMap.Insert(Toolkit::ImageVisual::Property::URL, TEST_RESOURCE_DIR "/svg1.svg");
3026     imageView.SetProperty(ImageView::Property::IMAGE, propertyMap);
3027
3028     application.GetScene().Add(imageView);
3029     DALI_TEST_CHECK(imageView);
3030
3031     application.SendNotification();
3032
3033     // Wait for loading
3034     DALI_TEST_EQUALS(Test::WaitForEventThreadTrigger(1), true, TEST_LOCATION);
3035
3036     application.SendNotification();
3037     application.Render(16);
3038
3039     Vector3 naturalSize = imageView.GetNaturalSize();
3040     DALI_TEST_EQUALS(naturalSize.width, 100.0f, TEST_LOCATION);
3041     DALI_TEST_EQUALS(naturalSize.height, 100.0f, TEST_LOCATION);
3042   }
3043   END_TEST;
3044 }
3045
3046 int UtcDaliImageViewSVGLoadingSyncSetInvalidValue(void)
3047 {
3048   ToolkitTestApplication application;
3049
3050   tet_infoline("ImageView Testing SVG image async loading");
3051
3052   // Sync loading
3053   {
3054     ImageView imageView = ImageView::New();
3055
3056     // Sync loading is used
3057     Property::Map syncLoadingMap;
3058     syncLoadingMap.Insert(Toolkit::Visual::Property::TYPE, Toolkit::Visual::IMAGE);
3059     syncLoadingMap.Insert(Toolkit::ImageVisual::Property::URL, TEST_RESOURCE_DIR "/svg1.svg");
3060
3061     // Check to set invalid value
3062     // The SYNCHRONOUS_LOADING property must be set to the bool value.
3063     // Check if error log is outputted when setting other value like string.
3064     // Even if the wrong value is set, the image will be shown normally, and the synchronous value should be the default value(false).
3065     syncLoadingMap.Insert(Toolkit::ImageVisual::Property::SYNCHRONOUS_LOADING, std::to_string(5));
3066     imageView.SetProperty(ImageView::Property::IMAGE, syncLoadingMap);
3067
3068     application.GetScene().Add(imageView);
3069     DALI_TEST_CHECK(imageView);
3070
3071     application.SendNotification();
3072
3073     // Wait for loading
3074     DALI_TEST_EQUALS(Test::WaitForEventThreadTrigger(1), true, TEST_LOCATION);
3075
3076     application.SendNotification();
3077     application.Render(16);
3078
3079     Vector3 naturalSize = imageView.GetNaturalSize();
3080     DALI_TEST_EQUALS(naturalSize.width, 100.0f, TEST_LOCATION);
3081     DALI_TEST_EQUALS(naturalSize.height, 100.0f, TEST_LOCATION);
3082
3083     Property::Value value = imageView.GetProperty(ImageView::Property::IMAGE);
3084     Property::Map*  map   = value.GetMap();
3085     DALI_TEST_CHECK(map);
3086
3087     Property::Value* sync = map->Find(Toolkit::ImageVisual::Property::SYNCHRONOUS_LOADING);
3088     DALI_TEST_CHECK(sync);
3089     DALI_TEST_EQUALS(false, sync->Get<bool>(), TEST_LOCATION);
3090   }
3091   END_TEST;
3092 }
3093
3094 int UtcDaliImageViewSvgLoadingFailureLocalFile(void)
3095 {
3096   // Local svg file - invalid file path
3097   {
3098     ToolkitTestApplication application;
3099
3100     TestGlAbstraction& gl           = application.GetGlAbstraction();
3101     TraceCallStack&    textureTrace = gl.GetTextureTrace();
3102     textureTrace.Enable(true);
3103
3104     gResourceReadySignalFired = false;
3105
3106     ImageView imageView = ImageView::New(TEST_RESOURCE_DIR "/foo.svg");
3107     imageView.SetProperty(Actor::Property::SIZE, Vector2(200.f, 200.f));
3108     imageView.ResourceReadySignal().Connect(&ResourceReadySignal);
3109
3110     DALI_TEST_EQUALS(imageView.IsResourceReady(), false, TEST_LOCATION);
3111
3112     application.GetScene().Add(imageView);
3113
3114     application.SendNotification();
3115
3116     // loading started, this waits for the loader thread - load
3117     DALI_TEST_EQUALS(Test::WaitForEventThreadTrigger(1), true, TEST_LOCATION);
3118
3119     application.SendNotification();
3120     application.Render(16);
3121
3122     DALI_TEST_EQUALS(gResourceReadySignalFired, true, TEST_LOCATION);
3123     DALI_TEST_EQUALS(imageView.IsResourceReady(), true, TEST_LOCATION);
3124     DALI_TEST_EQUALS(imageView.GetVisualResourceStatus(ImageView::Property::IMAGE), Visual::ResourceStatus::FAILED, TEST_LOCATION);
3125
3126     // Should be shown a broken image
3127     DALI_TEST_EQUALS(imageView.GetRendererCount(), 1u, TEST_LOCATION);
3128     DALI_TEST_EQUALS(textureTrace.FindMethod("BindTexture"), true, TEST_LOCATION);
3129   }
3130
3131   // Local svg file - invalid file path without size set
3132   {
3133     ToolkitTestApplication application;
3134
3135     TestGlAbstraction& gl           = application.GetGlAbstraction();
3136     TraceCallStack&    textureTrace = gl.GetTextureTrace();
3137     textureTrace.Enable(true);
3138
3139     gResourceReadySignalFired = false;
3140     textureTrace.Reset();
3141
3142     ImageView imageView = ImageView::New(TEST_RESOURCE_DIR "/foo.svg");
3143     imageView.ResourceReadySignal().Connect(&ResourceReadySignal);
3144
3145     DALI_TEST_EQUALS(imageView.IsResourceReady(), false, TEST_LOCATION);
3146
3147     application.GetScene().Add(imageView);
3148
3149     application.SendNotification();
3150
3151     // loading started, this waits for the loader thread - load & rasterize
3152     DALI_TEST_EQUALS(Test::WaitForEventThreadTrigger(1), true, TEST_LOCATION);
3153
3154     application.SendNotification();
3155     application.Render(16);
3156
3157     DALI_TEST_EQUALS(gResourceReadySignalFired, true, TEST_LOCATION);
3158     DALI_TEST_EQUALS(imageView.IsResourceReady(), true, TEST_LOCATION);
3159     DALI_TEST_EQUALS(imageView.GetVisualResourceStatus(ImageView::Property::IMAGE), Visual::ResourceStatus::FAILED, TEST_LOCATION);
3160
3161     // Should be shown a broken image
3162     DALI_TEST_EQUALS(imageView.GetRendererCount(), 1u, TEST_LOCATION);
3163     DALI_TEST_EQUALS(textureTrace.FindMethod("BindTexture"), true, TEST_LOCATION);
3164   }
3165
3166   // Local svg file - invalid file
3167   {
3168     ToolkitTestApplication application;
3169
3170     TestGlAbstraction& gl           = application.GetGlAbstraction();
3171     TraceCallStack&    textureTrace = gl.GetTextureTrace();
3172     textureTrace.Enable(true);
3173
3174     gResourceReadySignalFired = false;
3175     textureTrace.Reset();
3176
3177     ImageView imageView = ImageView::New(TEST_RESOURCE_DIR "/invalid.svg");
3178     imageView.SetProperty(Actor::Property::SIZE, Vector2(200.f, 200.f));
3179     imageView.ResourceReadySignal().Connect(&ResourceReadySignal);
3180
3181     DALI_TEST_EQUALS(imageView.IsResourceReady(), false, TEST_LOCATION);
3182
3183     application.GetScene().Add(imageView);
3184
3185     application.SendNotification();
3186
3187     // loading started, this waits for the loader thread - load & rasterize
3188     DALI_TEST_EQUALS(Test::WaitForEventThreadTrigger(1), true, TEST_LOCATION);
3189
3190     application.SendNotification();
3191     application.Render(16);
3192
3193     DALI_TEST_EQUALS(gResourceReadySignalFired, true, TEST_LOCATION);
3194     DALI_TEST_EQUALS(imageView.IsResourceReady(), true, TEST_LOCATION);
3195     DALI_TEST_EQUALS(imageView.GetVisualResourceStatus(ImageView::Property::IMAGE), Visual::ResourceStatus::FAILED, TEST_LOCATION);
3196
3197     // Should be shown a broken image
3198     DALI_TEST_EQUALS(imageView.GetRendererCount(), 1u, TEST_LOCATION);
3199     DALI_TEST_EQUALS(textureTrace.FindMethod("BindTexture"), true, TEST_LOCATION);
3200   }
3201
3202   END_TEST;
3203 }
3204
3205 int UtcDaliImageViewSvgLoadingFailureRemoteFile01(void)
3206 {
3207   // Remote svg file
3208   {
3209     ToolkitTestApplication application;
3210
3211     TestGlAbstraction& gl           = application.GetGlAbstraction();
3212     TraceCallStack&    textureTrace = gl.GetTextureTrace();
3213     textureTrace.Enable(true);
3214
3215     gResourceReadySignalFired = false;
3216
3217     ImageView imageView = ImageView::New("https://127.0.0.1/foobar.svg");
3218     imageView.SetProperty(Actor::Property::SIZE, Vector2(200.f, 200.f));
3219     imageView.ResourceReadySignal().Connect(&ResourceReadySignal);
3220
3221     DALI_TEST_EQUALS(imageView.IsResourceReady(), false, TEST_LOCATION);
3222
3223     application.GetScene().Add(imageView);
3224
3225     application.SendNotification();
3226
3227     // loading started, this waits for the loader thread - load & rasterize
3228     DALI_TEST_EQUALS(Test::WaitForEventThreadTrigger(1), true, TEST_LOCATION);
3229
3230     application.SendNotification();
3231     application.Render(16);
3232
3233     DALI_TEST_EQUALS(gResourceReadySignalFired, true, TEST_LOCATION);
3234     DALI_TEST_EQUALS(imageView.IsResourceReady(), true, TEST_LOCATION);
3235     DALI_TEST_EQUALS(imageView.GetVisualResourceStatus(ImageView::Property::IMAGE), Visual::ResourceStatus::FAILED, TEST_LOCATION);
3236
3237     // Should be shown a broken image
3238     DALI_TEST_EQUALS(imageView.GetRendererCount(), 1u, TEST_LOCATION);
3239     DALI_TEST_EQUALS(textureTrace.FindMethod("BindTexture"), true, TEST_LOCATION);
3240   }
3241
3242   END_TEST;
3243 }
3244
3245 int UtcDaliImageViewSvgLoadingFailureRemoteFile02(void)
3246 {
3247   // Remote svg file without size set
3248   {
3249     ToolkitTestApplication application;
3250
3251     TestGlAbstraction& gl           = application.GetGlAbstraction();
3252     TraceCallStack&    textureTrace = gl.GetTextureTrace();
3253     textureTrace.Enable(true);
3254
3255     gResourceReadySignalFired = false;
3256
3257     ImageView imageView = ImageView::New("https://127.0.0.1/foobar.svg");
3258     imageView.ResourceReadySignal().Connect(&ResourceReadySignal);
3259
3260     DALI_TEST_EQUALS(imageView.IsResourceReady(), false, TEST_LOCATION);
3261
3262     application.GetScene().Add(imageView);
3263
3264     application.SendNotification();
3265
3266     // loading started, this waits for the loader thread - load & rasterize
3267     DALI_TEST_EQUALS(Test::WaitForEventThreadTrigger(1), true, TEST_LOCATION);
3268
3269     application.SendNotification();
3270     application.Render(16);
3271
3272     DALI_TEST_EQUALS(gResourceReadySignalFired, true, TEST_LOCATION);
3273     DALI_TEST_EQUALS(imageView.IsResourceReady(), true, TEST_LOCATION);
3274     DALI_TEST_EQUALS(imageView.GetVisualResourceStatus(ImageView::Property::IMAGE), Visual::ResourceStatus::FAILED, TEST_LOCATION);
3275
3276     // Should be shown a broken image
3277     DALI_TEST_EQUALS(imageView.GetRendererCount(), 1u, TEST_LOCATION);
3278     DALI_TEST_EQUALS(textureTrace.FindMethod("BindTexture"), true, TEST_LOCATION);
3279   }
3280
3281   END_TEST;
3282 }
3283
3284 int UtcDaliImageViewSvgRasterizationFailure(void)
3285 {
3286   ToolkitTestApplication application;
3287
3288   gResourceReadySignalFired = false;
3289
3290   TestGlAbstraction& gl           = application.GetGlAbstraction();
3291   TraceCallStack&    textureTrace = gl.GetTextureTrace();
3292   textureTrace.Enable(true);
3293
3294   ImageView imageView = ImageView::New(TEST_RESOURCE_DIR "/invalid1.svg");
3295   imageView.SetProperty(Actor::Property::SIZE, Vector2(200.f, 200.f));
3296   imageView.ResourceReadySignal().Connect(&ResourceReadySignal);
3297
3298   DALI_TEST_EQUALS(imageView.IsResourceReady(), false, TEST_LOCATION);
3299
3300   application.GetScene().Add(imageView);
3301
3302   application.SendNotification();
3303
3304   // Wait for loading & rasterization
3305   DALI_TEST_EQUALS(Test::WaitForEventThreadTrigger(2), true, TEST_LOCATION);
3306
3307   application.SendNotification();
3308   application.Render(16);
3309
3310   DALI_TEST_EQUALS(gResourceReadySignalFired, true, TEST_LOCATION);
3311   DALI_TEST_EQUALS(imageView.IsResourceReady(), true, TEST_LOCATION);
3312   DALI_TEST_EQUALS(imageView.GetVisualResourceStatus(ImageView::Property::IMAGE), Visual::ResourceStatus::FAILED, TEST_LOCATION);
3313
3314   // Should be shown a broken image
3315   DALI_TEST_EQUALS(imageView.GetRendererCount(), 1u, TEST_LOCATION);
3316   DALI_TEST_EQUALS(textureTrace.FindMethod("BindTexture"), true, TEST_LOCATION);
3317
3318   END_TEST;
3319 }
3320
3321 int UtcDaliImageViewSvgChageSize(void)
3322 {
3323   ToolkitTestApplication application;
3324
3325   TestGlAbstraction& gl           = application.GetGlAbstraction();
3326   TraceCallStack&    textureTrace = gl.GetTextureTrace();
3327   textureTrace.Enable(true);
3328
3329   ImageView imageView = ImageView::New(TEST_SVG_FILE_NAME);
3330   application.GetScene().Add(imageView);
3331
3332   application.SendNotification();
3333
3334   // Wait for loading & rasterization
3335   DALI_TEST_EQUALS(Test::WaitForEventThreadTrigger(2), true, TEST_LOCATION);
3336
3337   application.SendNotification();
3338   application.Render(16);
3339
3340   DALI_TEST_EQUALS(Test::VectorImageRenderer::GetLoadCount(), 1, TEST_LOCATION);
3341
3342   // Change actor size, then rasterization should be done again
3343   imageView.SetProperty(Actor::Property::SIZE, Vector2(200.f, 200.f));
3344
3345   application.SendNotification();
3346
3347   // Wait for rasterization
3348   DALI_TEST_EQUALS(Test::WaitForEventThreadTrigger(1), true, TEST_LOCATION);
3349
3350   application.SendNotification();
3351   application.Render(16);
3352
3353   // We should not load the file again.
3354   DALI_TEST_EQUALS(Test::VectorImageRenderer::GetLoadCount(), 1, TEST_LOCATION);
3355
3356   END_TEST;
3357 }
3358
3359 int UtcDaliImageViewSvgAtlasing(void)
3360 {
3361   ToolkitTestApplication application;
3362
3363   TraceCallStack& callStack = application.GetGlAbstraction().GetTextureTrace();
3364   callStack.Reset();
3365   callStack.Enable(true);
3366
3367   Property::Map propertyMap;
3368   propertyMap["url"]      = TEST_SVG_FILE_NAME;
3369   propertyMap["atlasing"] = true;
3370
3371   ImageView imageView = ImageView::New();
3372   imageView.SetProperty(ImageView::Property::IMAGE, propertyMap);
3373   imageView.SetProperty(Actor::Property::SIZE, Vector2(100.f, 100.f));
3374   application.GetScene().Add(imageView);
3375
3376   application.SendNotification();
3377
3378   // Wait for loading & rasterization
3379   DALI_TEST_EQUALS(Test::WaitForEventThreadTrigger(2), true, TEST_LOCATION);
3380
3381   application.SendNotification();
3382   application.Render(16);
3383
3384   // use atlas
3385   TraceCallStack::NamedParams params1;
3386   params1["width"] << 100;
3387   params1["height"] << 100;
3388   DALI_TEST_EQUALS(callStack.FindMethodAndParams("TexSubImage2D", params1), true, TEST_LOCATION);
3389
3390   imageView.SetProperty(Actor::Property::SIZE, Vector2(600.f, 600.f));
3391
3392   application.SendNotification();
3393
3394   // Wait for rasterization
3395   DALI_TEST_EQUALS(Test::WaitForEventThreadTrigger(1), true, TEST_LOCATION);
3396
3397   callStack.Reset();
3398
3399   application.SendNotification();
3400   application.Render(16);
3401
3402   // not use atlas
3403   TraceCallStack::NamedParams params2;
3404   params2["width"] << 600;
3405   params2["height"] << 600;
3406   DALI_TEST_EQUALS(callStack.FindMethodAndParams("TexImage2D", params2), true, TEST_LOCATION);
3407
3408   END_TEST;
3409 }
3410
3411 int UtcDaliImageViewTVGLoading(void)
3412 {
3413   ToolkitTestApplication application;
3414
3415   tet_infoline("ImageView Testing TVG image loading");
3416
3417   {
3418     ImageView imageView = ImageView::New(TEST_RESOURCE_DIR "/test.tvg");
3419     application.GetScene().Add(imageView);
3420     DALI_TEST_CHECK(imageView);
3421
3422     application.SendNotification();
3423
3424     DALI_TEST_EQUALS(Test::WaitForEventThreadTrigger(1), true, TEST_LOCATION);
3425
3426     application.SendNotification();
3427     application.Render(16);
3428
3429     Vector3 naturalSize = imageView.GetNaturalSize();
3430
3431     DALI_TEST_EQUALS(naturalSize.width, 100.0f, TEST_LOCATION);
3432     DALI_TEST_EQUALS(naturalSize.height, 100.0f, TEST_LOCATION);
3433   }
3434   END_TEST;
3435 }
3436
3437 int UtcDaliImageViewSvgDesiredSize01(void)
3438 {
3439   ToolkitTestApplication application;
3440
3441   TestGlAbstraction& gl           = application.GetGlAbstraction();
3442   TraceCallStack&    textureTrace = gl.GetTextureTrace();
3443   textureTrace.Enable(true);
3444
3445   int       desiredWidth = 100, desiredHeight = 150;
3446   ImageView imageView = ImageView::New(TEST_SVG_FILE_NAME, ImageDimensions(desiredWidth, desiredHeight));
3447
3448   application.GetScene().Add(imageView);
3449
3450   application.SendNotification();
3451
3452   // Wait for loading & rasterization
3453   DALI_TEST_EQUALS(Test::WaitForEventThreadTrigger(2), true, TEST_LOCATION);
3454
3455   application.SendNotification();
3456   application.Render(16);
3457
3458   {
3459     std::stringstream out;
3460     out << GL_TEXTURE_2D << ", " << 0u << ", " << desiredWidth << ", " << desiredHeight;
3461     DALI_TEST_CHECK(textureTrace.FindMethodAndParams("TexImage2D", out.str().c_str()));
3462   }
3463
3464   END_TEST;
3465 }
3466
3467 int UtcDaliImageViewSvgDesiredSize02(void)
3468 {
3469   ToolkitTestApplication application;
3470
3471   TestGlAbstraction& gl           = application.GetGlAbstraction();
3472   TraceCallStack&    textureTrace = gl.GetTextureTrace();
3473   textureTrace.Enable(true);
3474
3475   int       desiredWidth = 150, desiredHeight = 100;
3476   ImageView imageView                   = ImageView::New();
3477   imageView[ImageView::Property::IMAGE] = Property::Map().Add("url", TEST_SVG_FILE_NAME).Add("desiredWidth", desiredWidth).Add("desiredHeight", desiredHeight);
3478   application.GetScene().Add(imageView);
3479
3480   application.SendNotification();
3481
3482   // Wait for loading & rasterization
3483   DALI_TEST_EQUALS(Test::WaitForEventThreadTrigger(2), true, TEST_LOCATION);
3484
3485   application.SendNotification();
3486   application.Render(16);
3487
3488   {
3489     std::stringstream out;
3490     out << GL_TEXTURE_2D << ", " << 0u << ", " << desiredWidth << ", " << desiredHeight;
3491     DALI_TEST_CHECK(textureTrace.FindMethodAndParams("TexImage2D", out.str().c_str()));
3492   }
3493
3494   END_TEST;
3495 }
3496
3497 int UtcDaliImageViewImageLoadFailure01(void)
3498 {
3499   ToolkitTestApplication application;
3500
3501   Toolkit::StyleManager styleManager = Toolkit::StyleManager::Get();
3502   DevelStyleManager::SetBrokenImageUrl(styleManager, DevelStyleManager::BrokenImageType::SMALL, TEST_BROKEN_IMAGE_S);
3503   DevelStyleManager::SetBrokenImageUrl(styleManager, DevelStyleManager::BrokenImageType::NORMAL, TEST_BROKEN_IMAGE_M);
3504   DevelStyleManager::SetBrokenImageUrl(styleManager, DevelStyleManager::BrokenImageType::LARGE, TEST_BROKEN_IMAGE_L);
3505
3506   std::string brokenUrl;
3507   brokenUrl = DevelStyleManager::GetBrokenImageUrl(styleManager, DevelStyleManager::BrokenImageType::SMALL);
3508   DALI_TEST_EQUALS(TEST_BROKEN_IMAGE_S, brokenUrl, TEST_LOCATION);
3509
3510   brokenUrl = DevelStyleManager::GetBrokenImageUrl(styleManager, DevelStyleManager::BrokenImageType::NORMAL);
3511   DALI_TEST_EQUALS(TEST_BROKEN_IMAGE_M, brokenUrl, TEST_LOCATION);
3512
3513   brokenUrl = DevelStyleManager::GetBrokenImageUrl(styleManager, DevelStyleManager::BrokenImageType::LARGE);
3514   DALI_TEST_EQUALS(TEST_BROKEN_IMAGE_L, brokenUrl, TEST_LOCATION);
3515
3516   ImageView imageView = ImageView::New("invalidUrl.png");
3517   imageView.SetProperty(Actor::Property::SIZE, Vector2(200.f, 200.f));
3518
3519   application.GetScene().Add(imageView);
3520   application.SendNotification();
3521   application.Render(16);
3522
3523   // loading started, this waits for the loader thread
3524   DALI_TEST_EQUALS(Test::WaitForEventThreadTrigger(1), true, TEST_LOCATION);
3525
3526   END_TEST;
3527 }
3528
3529 int UtcDaliImageViewImageLoadFailure02(void)
3530 {
3531   ToolkitTestApplication application;
3532
3533   Toolkit::StyleManager styleManager = Toolkit::StyleManager::Get();
3534   DevelStyleManager::SetBrokenImageUrl(styleManager, DevelStyleManager::BrokenImageType::SMALL, TEST_BROKEN_IMAGE_DEFAULT);
3535   DevelStyleManager::SetBrokenImageUrl(styleManager, DevelStyleManager::BrokenImageType::NORMAL, TEST_BROKEN_IMAGE_M);
3536   DevelStyleManager::SetBrokenImageUrl(styleManager, DevelStyleManager::BrokenImageType::LARGE, TEST_BROKEN_IMAGE_L);
3537
3538   std::string brokenUrl;
3539   brokenUrl = DevelStyleManager::GetBrokenImageUrl(styleManager, DevelStyleManager::BrokenImageType::SMALL);
3540   DALI_TEST_EQUALS(TEST_BROKEN_IMAGE_DEFAULT, brokenUrl, TEST_LOCATION);
3541
3542   brokenUrl = DevelStyleManager::GetBrokenImageUrl(styleManager, DevelStyleManager::BrokenImageType::NORMAL);
3543   DALI_TEST_EQUALS(TEST_BROKEN_IMAGE_M, brokenUrl, TEST_LOCATION);
3544
3545   brokenUrl = DevelStyleManager::GetBrokenImageUrl(styleManager, DevelStyleManager::BrokenImageType::LARGE);
3546   DALI_TEST_EQUALS(TEST_BROKEN_IMAGE_L, brokenUrl, TEST_LOCATION);
3547
3548   ImageView imageView = ImageView::New("invalidUrl.png");
3549   imageView.SetProperty(Actor::Property::SIZE, Vector2(30.f, 30.f));
3550   application.GetScene().Add(imageView);
3551   application.SendNotification();
3552   application.Render(16);
3553
3554   // loading started, this waits for the loader thread
3555   DALI_TEST_EQUALS(Test::WaitForEventThreadTrigger(1), true, TEST_LOCATION);
3556
3557   END_TEST;
3558 }
3559
3560 int UtcDaliImageViewImageLoadFailure03(void)
3561 {
3562   ToolkitTestApplication application;
3563
3564   Toolkit::StyleManager styleManager = Toolkit::StyleManager::Get();
3565   DevelStyleManager::SetBrokenImageUrl(styleManager, DevelStyleManager::BrokenImageType::SMALL, TEST_BROKEN_IMAGE_01);
3566   DevelStyleManager::SetBrokenImageUrl(styleManager, DevelStyleManager::BrokenImageType::NORMAL, TEST_BROKEN_IMAGE_02);
3567
3568   std::string brokenUrl;
3569   brokenUrl = DevelStyleManager::GetBrokenImageUrl(styleManager, DevelStyleManager::BrokenImageType::SMALL);
3570   DALI_TEST_EQUALS(TEST_BROKEN_IMAGE_01, brokenUrl, TEST_LOCATION);
3571
3572   brokenUrl = DevelStyleManager::GetBrokenImageUrl(styleManager, DevelStyleManager::BrokenImageType::NORMAL);
3573   DALI_TEST_EQUALS(TEST_BROKEN_IMAGE_02, brokenUrl, TEST_LOCATION);
3574
3575   ImageView imageView = ImageView::New("invalidUrl.png");
3576   imageView.SetProperty(Actor::Property::SIZE, Vector2(100.f, 100.f));
3577   application.GetScene().Add(imageView);
3578   application.SendNotification();
3579   application.Render(16);
3580
3581   // loading started, this waits for the loader thread
3582   DALI_TEST_EQUALS(Test::WaitForEventThreadTrigger(1), true, TEST_LOCATION);
3583
3584   END_TEST;
3585 }
3586
3587 int UtcDaliImageViewImageLoadFailure04(void)
3588 {
3589   ToolkitTestApplication application;
3590
3591   ImageView imageView = ImageView::New("invalidUrl.png");
3592   imageView.SetProperty(Actor::Property::SIZE, Vector2(100.f, 100.f));
3593   application.GetScene().Add(imageView);
3594   application.SendNotification();
3595   application.Render(16);
3596
3597   // loading started, this waits for the loader thread
3598   DALI_TEST_EQUALS(Test::WaitForEventThreadTrigger(1), true, TEST_LOCATION);
3599
3600   Toolkit::StyleManager styleManager = Toolkit::StyleManager::Get();
3601   DevelStyleManager::SetBrokenImageUrl(styleManager, DevelStyleManager::BrokenImageType::SMALL, TEST_BROKEN_IMAGE_S);
3602   DevelStyleManager::SetBrokenImageUrl(styleManager, DevelStyleManager::BrokenImageType::NORMAL, "invalidBroken.png");
3603   DevelStyleManager::SetBrokenImageUrl(styleManager, DevelStyleManager::BrokenImageType::LARGE, TEST_BROKEN_IMAGE_L);
3604
3605   ImageView imageView2 = ImageView::New("invalidUrl.png");
3606   imageView2.SetProperty(Actor::Property::SIZE, Vector2(100.f, 100.f));
3607   application.GetScene().Add(imageView2);
3608
3609   std::string brokenUrl;
3610   brokenUrl = DevelStyleManager::GetBrokenImageUrl(styleManager, DevelStyleManager::BrokenImageType::SMALL);
3611   DALI_TEST_EQUALS(TEST_BROKEN_IMAGE_S, brokenUrl, TEST_LOCATION);
3612
3613   brokenUrl = DevelStyleManager::GetBrokenImageUrl(styleManager, DevelStyleManager::BrokenImageType::LARGE);
3614   DALI_TEST_EQUALS(TEST_BROKEN_IMAGE_L, brokenUrl, TEST_LOCATION);
3615
3616   application.SendNotification();
3617   application.Render(16);
3618
3619   // loading started, this waits for the loader thread
3620   DALI_TEST_EQUALS(Test::WaitForEventThreadTrigger(1), true, TEST_LOCATION);
3621
3622   DevelStyleManager::SetBrokenImageUrl(styleManager, DevelStyleManager::BrokenImageType::NORMAL, "invalidBroken.9.png");
3623
3624   ImageView imageView3 = ImageView::New("invalidUrl.png");
3625   imageView3.SetProperty(Actor::Property::SIZE, Vector2(100.f, 100.f));
3626   application.GetScene().Add(imageView3);
3627
3628   application.SendNotification();
3629   application.Render(16);
3630
3631   // loading started, this waits for the loader thread
3632   DALI_TEST_EQUALS(Test::WaitForEventThreadTrigger(1), true, TEST_LOCATION);
3633
3634   END_TEST;
3635 }
3636
3637 namespace
3638 {
3639 static int gResourceReadySignalCounter = 0;
3640
3641 void OnResourceReadySignal01(Control control)
3642 {
3643   gResourceReadySignalCounter++;
3644
3645   if(control.GetVisualResourceStatus(ImageView::Property::IMAGE) == Visual::ResourceStatus::READY)
3646   {
3647     if(gResourceReadySignalCounter == 1)
3648     {
3649       // Set image twice
3650       // It makes the first new visual be deleted immediately
3651       ImageView::DownCast(control).SetImage(gImage_34_RGBA);
3652       ImageView::DownCast(control).SetImage(gImage_34_RGBA);
3653     }
3654   }
3655   else if(control.GetVisualResourceStatus(ImageView::Property::IMAGE) == Visual::ResourceStatus::FAILED)
3656   {
3657     // Make the resource ready immediately
3658     control[ImageView::Property::IMAGE] = gImage_600_RGB;
3659   }
3660 }
3661
3662 void OnResourceReadySignal02(Control control)
3663 {
3664   if(++gResourceReadySignalCounter == 1)
3665   {
3666     // It makes the first new visual be deleted immediately
3667     // The first image will not be loaded.
3668     control[ImageView::Property::IMAGE] = Property::Map().Add(ImageVisual::Property::URL, gImage_600_RGB).Add(ImageVisual::Property::RELEASE_POLICY, ImageVisual::ReleasePolicy::NEVER);
3669     control[ImageView::Property::IMAGE] = TEST_IMAGE_1;
3670   }
3671 }
3672
3673 ImageView gImageView1;
3674 ImageView gImageView2;
3675 ImageView gImageView3;
3676 ImageView gImageView4;
3677
3678 void OnResourceReadySignal03(Control control)
3679 {
3680   if(gResourceReadySignalCounter == 0)
3681   {
3682     // Queue loading
3683     // 1. Use cached image, then LoadComplete will be called right after OnResourceReadySignal03.
3684     gImageView2[ImageView::Property::IMAGE] = gImage_34_RGBA;
3685
3686     // 2. Load a new image
3687     gImageView3[ImageView::Property::IMAGE] = TEST_IMAGE_1;
3688
3689     // 3. Use the new image again
3690     gImageView1[ImageView::Property::IMAGE] = TEST_IMAGE_1;
3691     gImageView1.ResourceReadySignal().Connect(&OnResourceReadySignal03);
3692   }
3693   else if(gResourceReadySignalCounter == 1)
3694   {
3695     // This is called from TextureManager::ProcessQueuedTextures().
3696     gImageView1.Unparent();
3697     gImageView1.Reset();
3698   }
3699   gResourceReadySignalCounter++;
3700 }
3701
3702 void OnSimpleResourceReadySignal(Control control)
3703 {
3704   // simply increate counter
3705   gResourceReadySignalCounter++;
3706 }
3707
3708 int gResourceReadySignal04ComesOrder = 0;
3709
3710 void OnResourceReadySignal04(Control control)
3711 {
3712   gResourceReadySignalCounter++;
3713   tet_printf("rc %d\n", gResourceReadySignalCounter);
3714   if(gResourceReadySignalCounter == 1)
3715   {
3716     auto scene = gImageView1.GetParent();
3717
3718     // Request load something
3719     // We hope this request result is return later than gImageView2.
3720     gImageView3 = ImageView::New(TEST_IMAGE_1);
3721     gImageView3.ResourceReadySignal().Connect(&OnResourceReadySignal04);
3722     scene.Add(gImageView3);
3723     gImageView4 = ImageView::New(TEST_IMAGE_2);
3724     gImageView4.ResourceReadySignal().Connect(&OnResourceReadySignal04);
3725     scene.Add(gImageView4);
3726
3727     if(control == gImageView1)
3728     {
3729       gResourceReadySignal04ComesOrder = 1;
3730     }
3731     else
3732     {
3733       gResourceReadySignal04ComesOrder = 2;
3734     }
3735   }
3736   if(gResourceReadySignalCounter == 2)
3737   {
3738     if(gResourceReadySignal04ComesOrder == 1 && control == gImageView2)
3739     {
3740       // Scene off first one.
3741       gImageView1.Unparent();
3742
3743       // Scene off second one.
3744       gImageView2.Unparent();
3745     }
3746     else if(gResourceReadySignal04ComesOrder == 2 && control == gImageView1)
3747     {
3748       // Scene off first one.
3749       gImageView2.Unparent();
3750
3751       // Scene off second one.
3752       gImageView1.Unparent();
3753     }
3754     else
3755     {
3756       // We can't check that this utc fail case. just pass always when we come here.
3757       gResourceReadySignal04ComesOrder = -1;
3758     }
3759
3760     // If we don't seperate index of FreeList area
3761     // and if we don't queue remove during obversing,
3762     // cache index become something invalid data.
3763     // In this case, some strange observer can be called.
3764     // For example, gImageView4.LoadComplete will be called.
3765   }
3766 }
3767
3768 void OnResourceReadySignal05(Control control)
3769 {
3770   gResourceReadySignalCounter++;
3771
3772   // Request load with same image
3773   // NOTE : The url must not be same as gImageView1
3774   const int viewCount = 4;
3775   for(int i = 0; i < viewCount; ++i)
3776   {
3777     gImageView1.Add(ImageView::New("invalid2.jpg"));
3778   }
3779 }
3780
3781 int gResourceReadySignal06ComesOrder = 0;
3782
3783 void OnResourceReadySignal06(Control control)
3784 {
3785   gResourceReadySignalCounter++;
3786   if(gResourceReadySignalCounter == 1)
3787   {
3788     auto scene = gImageView1.GetParent();
3789
3790     // Request load something
3791     // We hope this request result is return later than gImageView2.
3792
3793     Property::Map map1;
3794     map1[Toolkit::ImageVisual::Property::URL]            = TEST_IMAGE_1;
3795     map1[Toolkit::ImageVisual::Property::ALPHA_MASK_URL] = TEST_BROKEN_IMAGE_DEFAULT;
3796
3797     gImageView3 = ImageView::New();
3798     gImageView3.SetProperty(Toolkit::ImageView::Property::IMAGE, map1);
3799     gImageView3.ResourceReadySignal().Connect(&OnResourceReadySignal06);
3800
3801     Property::Map map2;
3802     map2[Toolkit::ImageVisual::Property::URL]            = TEST_IMAGE_2;
3803     map2[Toolkit::ImageVisual::Property::ALPHA_MASK_URL] = TEST_BROKEN_IMAGE_S;
3804     gImageView4                                          = ImageView::New();
3805     gImageView4.SetProperty(Toolkit::ImageView::Property::IMAGE, map2);
3806     gImageView4.ResourceReadySignal().Connect(&OnResourceReadySignal06);
3807
3808     if(control == gImageView1)
3809     {
3810       gResourceReadySignal06ComesOrder = 1;
3811     }
3812     else
3813     {
3814       gResourceReadySignal06ComesOrder = 2;
3815     }
3816   }
3817   if(gResourceReadySignalCounter == 2)
3818   {
3819     if(gResourceReadySignal06ComesOrder == 1 && control == gImageView2)
3820     {
3821       // Scene off first one.
3822       gImageView1.Unparent();
3823
3824       // Scene off second one.
3825       gImageView2.Unparent();
3826     }
3827     else if(gResourceReadySignal06ComesOrder == 2 && control == gImageView1)
3828     {
3829       // Scene off first one.
3830       gImageView2.Unparent();
3831
3832       // Scene off second one.
3833       gImageView1.Unparent();
3834     }
3835     else
3836     {
3837       // We can't check that this utc fail case. just pass always when we come here.
3838       gResourceReadySignal06ComesOrder = -1;
3839     }
3840
3841     // If we don't seperate index of FreeList area
3842     // and if we don't queue remove during obversing,
3843     // cache index become something invalid data.
3844     // In this case, some strange observer can be called.
3845     // For example, gImageView4.LoadComplete will be called.
3846   }
3847 }
3848
3849 void OnResourceReadySignal07(Control control)
3850 {
3851   gResourceReadySignalCounter++;
3852   // Load masked image
3853   tet_printf("rc %d %d\n", gResourceReadySignalCounter, static_cast<bool>(gImageView2));
3854
3855   if(!gImageView2)
3856   {
3857     auto scene = gImageView1.GetParent();
3858
3859     Property::Map map1;
3860     map1[Toolkit::ImageVisual::Property::URL]            = TEST_IMAGE_1;
3861     map1[Toolkit::ImageVisual::Property::ALPHA_MASK_URL] = TEST_BROKEN_IMAGE_DEFAULT;
3862
3863     gImageView2 = ImageView::New();
3864     gImageView2.SetProperty(Toolkit::ImageView::Property::IMAGE, map1);
3865     gImageView2.ResourceReadySignal().Connect(&OnResourceReadySignal07);
3866
3867     scene.Add(gImageView2);
3868   }
3869 }
3870
3871 void OnResourceReadySignal08(Control control)
3872 {
3873   gResourceReadySignalCounter++;
3874
3875   if(gImageView1)
3876   {
3877     gImageView1.Unparent();
3878     gImageView1.Reset();
3879   }
3880   if(gImageView2)
3881   {
3882     gImageView2.Unparent();
3883     gImageView2.Reset();
3884   }
3885 }
3886
3887 std::size_t gResourceReadySignal09Emitted = false;
3888
3889 void OnResourceReadySignal09(Control control)
3890 {
3891   gResourceReadySignalCounter++;
3892
3893   if(gImageView1 && !gResourceReadySignal09Emitted)
3894   {
3895     gResourceReadySignal09Emitted = true;
3896     gImageView1.ResourceReadySignal().Disconnect(&OnResourceReadySignal09);
3897
3898     // Try to load cached invalid nine patch image. It will request load now.
3899     gImageView1.SetImage(TEST_INVALID_NPATCH_FILE_NAME_01);
3900     gImageView2.SetImage(TEST_INVALID_NPATCH_FILE_NAME_01);
3901
3902     // Destroy all visuals immediatly.
3903     gImageView1.Unparent();
3904     gImageView1.Reset();
3905     gImageView2.Unparent();
3906     gImageView2.Reset();
3907   }
3908 }
3909 constexpr int gResourceReadySignal10MaxCounter = 5;
3910
3911 void OnResourceReadySignal10(Control control)
3912 {
3913   gResourceReadySignalCounter++;
3914
3915   tet_printf("OnResourceReadySignal10 comes!\n");
3916   if(gResourceReadySignalCounter < gResourceReadySignal10MaxCounter)
3917   {
3918     tet_printf("OnResourceReadySignal10 Set image\n");
3919     gImageView1.SetProperty(Toolkit::ImageView::Property::IMAGE, gImage_34_RGBA);
3920     tet_printf("OnResourceReadySignal10 Set image done\n");
3921   }
3922 }
3923
3924 void OnResourceReadySignal11(Control control)
3925 {
3926   gResourceReadySignalCounter++;
3927
3928   if(!gImageView2)
3929   {
3930     auto scene = gImageView1.GetParent();
3931
3932     // Try to load animated image visual here which is already cached, and then ignore forcely.
3933
3934     Property::Map map1;
3935     map1[Toolkit::ImageVisual::Property::URL] = TEST_GIF_FILE_NAME;
3936
3937     gImageView2 = ImageView::New();
3938     gImageView2.SetProperty(Toolkit::ImageView::Property::IMAGE, map1);
3939
3940     gImageView3 = ImageView::New();
3941     gImageView3.SetProperty(Toolkit::ImageView::Property::IMAGE, map1);
3942
3943     scene.Add(gImageView2);
3944     gImageView2.Unparent();
3945
3946     scene.Add(gImageView3);
3947     gImageView3.Unparent();
3948     gImageView3.Reset(); // Destroy visual
3949   }
3950 }
3951
3952 } // namespace
3953
3954 int UtcDaliImageViewSetImageOnResourceReadySignal01(void)
3955 {
3956   tet_infoline("Test setting image from within signal handler.");
3957
3958   ToolkitTestApplication application;
3959
3960   gResourceReadySignalCounter = 0;
3961
3962   ImageView imageView = ImageView::New(gImage_34_RGBA);
3963   imageView.ResourceReadySignal().Connect(&OnResourceReadySignal01);
3964
3965   application.GetScene().Add(imageView);
3966
3967   DALI_TEST_EQUALS(Test::WaitForEventThreadTrigger(1), true, TEST_LOCATION);
3968
3969   application.SendNotification();
3970   application.Render();
3971
3972   DALI_TEST_EQUALS(gResourceReadySignalCounter, 2, TEST_LOCATION);
3973
3974   DALI_TEST_EQUALS(imageView.IsResourceReady(), true, TEST_LOCATION);
3975
3976   // Create a new ImageView to cache the image
3977   ImageView imageView1 = ImageView::New(gImage_600_RGB);
3978   application.GetScene().Add(imageView1);
3979
3980   DALI_TEST_EQUALS(Test::WaitForEventThreadTrigger(1), true, TEST_LOCATION);
3981
3982   application.SendNotification();
3983   application.Render();
3984
3985   // Reset count
3986   gResourceReadySignalCounter = 0;
3987
3988   imageView[ImageView::Property::IMAGE] = "invalid.jpg";
3989
3990   DALI_TEST_EQUALS(Test::WaitForEventThreadTrigger(1), true, TEST_LOCATION);
3991
3992   application.SendNotification();
3993   application.Render();
3994
3995   // Run idle callback
3996   application.RunIdles();
3997
3998   DALI_TEST_EQUALS(gResourceReadySignalCounter, 2, TEST_LOCATION);
3999
4000   DALI_TEST_EQUALS(imageView.IsResourceReady(), true, TEST_LOCATION);
4001
4002   END_TEST;
4003 }
4004
4005 int UtcDaliImageViewSetImageOnResourceReadySignal02(void)
4006 {
4007   tet_infoline("Test setting image from within signal handler.");
4008
4009   ToolkitTestApplication application;
4010
4011   gResourceReadySignalCounter = 0;
4012
4013   ImageView imageView = ImageView::New(gImage_34_RGBA);
4014   imageView.ResourceReadySignal().Connect(&OnResourceReadySignal02);
4015
4016   application.GetScene().Add(imageView);
4017
4018   DALI_TEST_EQUALS(Test::WaitForEventThreadTrigger(1), true, TEST_LOCATION);
4019
4020   application.SendNotification();
4021   application.Render();
4022
4023   // Wait for loading an image
4024   DALI_TEST_EQUALS(Test::WaitForEventThreadTrigger(1), true, TEST_LOCATION);
4025
4026   DALI_TEST_EQUALS(gResourceReadySignalCounter, 2, TEST_LOCATION);
4027
4028   DALI_TEST_EQUALS(imageView.IsResourceReady(), true, TEST_LOCATION);
4029
4030   END_TEST;
4031 }
4032
4033 int UtcDaliImageViewSetImageOnResourceReadySignal03(void)
4034 {
4035   tet_infoline("Test setting image from within signal handler.");
4036
4037   ToolkitTestApplication application;
4038
4039   gResourceReadySignalCounter = 0;
4040
4041   gImageView1 = ImageView::New(gImage_34_RGBA);
4042   application.GetScene().Add(gImageView1);
4043
4044   // Wait for loading
4045   DALI_TEST_EQUALS(Test::WaitForEventThreadTrigger(1), true, TEST_LOCATION);
4046
4047   gImageView2 = ImageView::New(gImage_600_RGB);
4048   gImageView2.ResourceReadySignal().Connect(&OnResourceReadySignal03);
4049   application.GetScene().Add(gImageView2);
4050
4051   gImageView3 = ImageView::New();
4052   application.GetScene().Add(gImageView3);
4053
4054   DALI_TEST_EQUALS(Test::WaitForEventThreadTrigger(2), true, TEST_LOCATION);
4055
4056   application.SendNotification();
4057   application.Render();
4058
4059   END_TEST;
4060 }
4061
4062 int UtcDaliImageViewOnResourceReadySignalWithBrokenAlphaMask01(void)
4063 {
4064   tet_infoline("Test signal handler when image / mask image is broken.");
4065
4066   ToolkitTestApplication application;
4067
4068   auto TestResourceReadyUrl = [&application](int eventTriggerCount, bool isSynchronous, const std::string& url, const std::string& mask, const char* location) {
4069     gResourceReadySignalCounter = 0;
4070
4071     Property::Map map;
4072     map[Toolkit::ImageVisual::Property::URL] = url;
4073     if(!mask.empty())
4074     {
4075       map[Toolkit::ImageVisual::Property::ALPHA_MASK_URL] = mask;
4076     }
4077     map[Toolkit::ImageVisual::Property::SYNCHRONOUS_LOADING] = isSynchronous;
4078
4079     ImageView imageView                            = ImageView::New();
4080     imageView[Toolkit::ImageView::Property::IMAGE] = map;
4081     imageView[Actor::Property::SIZE]               = Vector2(100.0f, 200.0f);
4082     imageView.ResourceReadySignal().Connect(&OnSimpleResourceReadySignal);
4083
4084     application.GetScene().Add(imageView);
4085     application.SendNotification();
4086     application.Render();
4087
4088     if(!isSynchronous)
4089     {
4090       // Wait for loading
4091       DALI_TEST_EQUALS(Test::WaitForEventThreadTrigger(eventTriggerCount), true, location);
4092     }
4093     tet_printf("test %s [sync:%d] signal fired\n", url.c_str(), isSynchronous ? 1 : 0);
4094     DALI_TEST_EQUALS(gResourceReadySignalCounter, 1, location);
4095
4096     imageView.Unparent();
4097   };
4098
4099   for(int synchronous = 0; synchronous <= 1; synchronous++)
4100   {
4101     tet_printf("Test normal case (sync:%d)\n", synchronous);
4102     TestResourceReadyUrl(1, synchronous, gImage_600_RGB, "", TEST_LOCATION);
4103     TestResourceReadyUrl(3, synchronous, gImage_600_RGB, gImage_34_RGBA, TEST_LOCATION); // 3 event trigger required : 2 image load + 1 apply mask
4104
4105     tet_printf("Test broken image case (sync:%d)\n", synchronous);
4106     TestResourceReadyUrl(1, synchronous, "invalid.jpg", "", TEST_LOCATION);
4107     TestResourceReadyUrl(2, synchronous, "invalid.jpg", gImage_34_RGBA, TEST_LOCATION);
4108
4109     tet_printf("Test broken mask image case (sync:%d)\n", synchronous);
4110     TestResourceReadyUrl(2, synchronous, gImage_600_RGB, "invalid.png", TEST_LOCATION);
4111
4112     tet_printf("Test broken both image, mask image case (sync:%d)\n", synchronous);
4113     TestResourceReadyUrl(2, synchronous, "invalid.jpg", "invalid.png", TEST_LOCATION);
4114   }
4115
4116   END_TEST;
4117 }
4118
4119 int UtcDaliImageViewOnResourceReadySignalWithBrokenAlphaMask02(void)
4120 {
4121   tet_infoline("Test signal handler when image try to use cached-and-broken mask image.");
4122
4123   ToolkitTestApplication application;
4124
4125   gResourceReadySignalCounter = 0;
4126
4127   auto TestBrokenMaskResourceReadyUrl = [&application](const std::string& url, const char* location) {
4128     Property::Map map;
4129     map[Toolkit::ImageVisual::Property::URL] = url;
4130     // Use invalid mask url
4131     map[Toolkit::ImageVisual::Property::ALPHA_MASK_URL] = "invalid.png";
4132
4133     ImageView imageView                            = ImageView::New();
4134     imageView[Toolkit::ImageView::Property::IMAGE] = map;
4135     imageView[Actor::Property::SIZE]               = Vector2(100.0f, 200.0f);
4136     imageView.ResourceReadySignal().Connect(&OnSimpleResourceReadySignal);
4137
4138     application.GetScene().Add(imageView);
4139
4140     // Don't unparent imageView, for keep the cache.
4141   };
4142
4143   // Use more than 4 images (The number of LocalImageLoadThread)
4144   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};
4145
4146   int expectResourceReadySignalCounter = 0;
4147
4148   for(auto& url : testUrlList)
4149   {
4150     TestBrokenMaskResourceReadyUrl(url, TEST_LOCATION);
4151     expectResourceReadySignalCounter++;
4152   }
4153
4154   // Remain 1 signal due to we use #URL + 1 mask image.
4155   DALI_TEST_EQUALS(Test::WaitForEventThreadTrigger(expectResourceReadySignalCounter + 1), true, TEST_LOCATION);
4156   application.SendNotification();
4157   application.Render();
4158   DALI_TEST_EQUALS(gResourceReadySignalCounter, expectResourceReadySignalCounter, TEST_LOCATION);
4159
4160   END_TEST;
4161 }
4162
4163 int UtcDaliImageViewCheckVariousCaseSendOnResourceReadySignal(void)
4164 {
4165   tet_infoline("Test signal handler various case.");
4166
4167   auto TestResourceReadyUrl = [](int eventTriggerCount, bool isSynchronous, bool loadSuccess, const std::string& url, const std::string& mask, const char* location) {
4168     ToolkitTestApplication application;
4169
4170     gResourceReadySignalCounter = 0;
4171
4172     Property::Map map;
4173     map[Toolkit::ImageVisual::Property::URL] = url;
4174     if(!mask.empty())
4175     {
4176       map[Toolkit::ImageVisual::Property::ALPHA_MASK_URL] = mask;
4177     }
4178     map[Toolkit::ImageVisual::Property::SYNCHRONOUS_LOADING] = isSynchronous;
4179
4180     ImageView imageView                            = ImageView::New();
4181     imageView[Toolkit::ImageView::Property::IMAGE] = map;
4182     imageView[Actor::Property::SIZE]               = Vector2(100.0f, 200.0f);
4183     imageView.ResourceReadySignal().Connect(&OnSimpleResourceReadySignal);
4184
4185     application.GetScene().Add(imageView);
4186     application.SendNotification();
4187     application.Render();
4188
4189     // Wait for loading
4190     DALI_TEST_EQUALS(Test::WaitForEventThreadTrigger(eventTriggerCount), true, location);
4191
4192     tet_printf("test %s [sync:%d] signal fired\n", url.c_str(), isSynchronous ? 1 : 0);
4193     DALI_TEST_EQUALS(gResourceReadySignalCounter, 1, location);
4194     DALI_TEST_EQUALS(imageView.GetVisualResourceStatus(Toolkit::ImageView::Property::IMAGE), loadSuccess ? Toolkit::Visual::ResourceStatus::READY : Toolkit::Visual::ResourceStatus::FAILED, location);
4195
4196     imageView.Unparent();
4197   };
4198
4199   auto TestAuxiliaryResourceReadyUrl = [](bool isSynchronous, bool loadSuccess, const std::string& url, const std::string& auxiliaryUrl, const char* location) {
4200     ToolkitTestApplication application;
4201
4202     gResourceReadySignalCounter = 0;
4203
4204     Property::Map map;
4205     map[Toolkit::ImageVisual::Property::URL]                        = url;
4206     map[Toolkit::DevelImageVisual::Property::AUXILIARY_IMAGE]       = auxiliaryUrl;
4207     map[Toolkit::DevelImageVisual::Property::AUXILIARY_IMAGE_ALPHA] = 0.5f;
4208     map[Toolkit::ImageVisual::Property::SYNCHRONOUS_LOADING]        = isSynchronous;
4209
4210     ImageView imageView = ImageView::New();
4211     imageView.SetProperty(Toolkit::ImageView::Property::IMAGE, map);
4212     imageView.SetProperty(Actor::Property::SIZE, Vector2(100.0f, 200.0f));
4213     imageView.ResourceReadySignal().Connect(&OnSimpleResourceReadySignal);
4214     application.GetScene().Add(imageView);
4215
4216     application.SendNotification();
4217     application.Render();
4218
4219     if(!isSynchronous)
4220     {
4221       // Wait for loading
4222       DALI_TEST_EQUALS(Test::WaitForEventThreadTrigger(2), true, location);
4223     }
4224
4225     tet_printf("test %s [sync:%d] signal fired\n", url.c_str(), isSynchronous ? 1 : 0);
4226     DALI_TEST_EQUALS(gResourceReadySignalCounter, 1, location);
4227     DALI_TEST_EQUALS(imageView.GetVisualResourceStatus(Toolkit::ImageView::Property::IMAGE), loadSuccess ? Toolkit::Visual::ResourceStatus::READY : Toolkit::Visual::ResourceStatus::FAILED, TEST_LOCATION);
4228
4229     imageView.Unparent();
4230   };
4231
4232   // Case 1 : asynchronous loading
4233   tet_printf("Test invalid single simple image Asynchronous\n");
4234
4235   // Test normal case
4236   TestResourceReadyUrl(1, 0, 1, gImage_600_RGB, "", TEST_LOCATION);
4237   TestResourceReadyUrl(2, 0, 1, TEST_SVG_FILE_NAME, "", TEST_LOCATION); // load & rasterize
4238   TestResourceReadyUrl(1, 0, 1, TEST_BROKEN_IMAGE_L, "", TEST_LOCATION);
4239
4240   TestResourceReadyUrl(2, 0, 1, TEST_GIF_FILE_NAME, "", TEST_LOCATION);                   // 2 image loading - batch size
4241   TestResourceReadyUrl(2, 0, 1, TEST_ANIMATED_VECTOR_IMAGE_FILE_NAME, "", TEST_LOCATION); // load & rasterize
4242
4243   TestResourceReadyUrl(3, 0, 1, gImage_600_RGB, gImage_34_RGBA, TEST_LOCATION); // 2 image loading + 1 applymask
4244
4245   TestAuxiliaryResourceReadyUrl(0, 1, TEST_BROKEN_IMAGE_L, gImage_34_RGBA, TEST_LOCATION);
4246
4247   // Test broken case
4248   TestResourceReadyUrl(1, 0, 0, "invalid.jpg", "", TEST_LOCATION);
4249   TestResourceReadyUrl(1, 0, 0, "invalid.svg", "", TEST_LOCATION);
4250   TestResourceReadyUrl(1, 0, 0, "invalid.9.png", "", TEST_LOCATION);
4251   TestResourceReadyUrl(1, 0, 0, "invalid.gif", "", TEST_LOCATION);  // 1 image loading
4252   TestResourceReadyUrl(1, 0, 0, "invalid.json", "", TEST_LOCATION); // 0 rasterize
4253
4254   TestResourceReadyUrl(2, 0, 0, "invalid.jpg", "invalid.png", TEST_LOCATION);  // 2 image loading
4255   TestResourceReadyUrl(2, 0, 1, gImage_600_RGB, "invalid.png", TEST_LOCATION); // 2 image loading
4256   TestResourceReadyUrl(2, 0, 0, "invalid.jpg", gImage_34_RGBA, TEST_LOCATION); // 2 image loading
4257
4258   TestAuxiliaryResourceReadyUrl(0, 0, "invalid.9.png", "invalid.png", TEST_LOCATION);
4259   TestAuxiliaryResourceReadyUrl(0, 1, TEST_BROKEN_IMAGE_L, "invalid.png", TEST_LOCATION);
4260   TestAuxiliaryResourceReadyUrl(0, 0, "invalid.9.png", gImage_34_RGBA, TEST_LOCATION);
4261
4262   // Case 2 : Synchronous loading
4263   tet_printf("Test invalid single simple image Synchronous\n");
4264
4265   // Test normal case
4266   TestResourceReadyUrl(0, 1, 1, gImage_600_RGB, "", TEST_LOCATION);
4267   TestResourceReadyUrl(0, 1, 1, TEST_SVG_FILE_NAME, "", TEST_LOCATION); // synchronous rasterize
4268   TestResourceReadyUrl(0, 1, 1, TEST_BROKEN_IMAGE_L, "", TEST_LOCATION);
4269
4270   TestResourceReadyUrl(1, 1, 1, TEST_GIF_FILE_NAME, "", TEST_LOCATION); // first frame image loading sync + second frame image loading async
4271
4272   TestResourceReadyUrl(0, 1, 1, gImage_600_RGB, gImage_34_RGBA, TEST_LOCATION);
4273
4274   TestAuxiliaryResourceReadyUrl(1, 1, TEST_BROKEN_IMAGE_L, gImage_34_RGBA, TEST_LOCATION);
4275
4276   // Test broken case
4277   TestResourceReadyUrl(0, 1, 0, "invalid.jpg", "", TEST_LOCATION);
4278   TestResourceReadyUrl(0, 1, 0, "invalid.svg", "", TEST_LOCATION);
4279   TestResourceReadyUrl(0, 1, 0, "invalid.9.png", "", TEST_LOCATION);
4280   TestResourceReadyUrl(0, 1, 0, "invalid.gif", "", TEST_LOCATION);
4281
4282   TestResourceReadyUrl(0, 1, 0, "invalid.jpg", "invalid.png", TEST_LOCATION);
4283   TestResourceReadyUrl(0, 1, 1, gImage_600_RGB, "invalid.png", TEST_LOCATION);
4284   TestResourceReadyUrl(0, 1, 0, "invalid.jpg", gImage_34_RGBA, TEST_LOCATION);
4285
4286   TestAuxiliaryResourceReadyUrl(1, 0, "invalid.9.png", "invalid.png", TEST_LOCATION);
4287   TestAuxiliaryResourceReadyUrl(1, 1, TEST_BROKEN_IMAGE_L, "invalid.png", TEST_LOCATION);
4288   TestAuxiliaryResourceReadyUrl(1, 0, "invalid.9.png", gImage_34_RGBA, TEST_LOCATION);
4289
4290   END_TEST;
4291 }
4292
4293 int UtcDaliImageViewSetImageOnResourceReadySignal04(void)
4294 {
4295   tet_infoline("Test texturemanager's remove queue works well within signal handler.");
4296
4297   ToolkitTestApplication application;
4298
4299   gResourceReadySignalCounter      = 0;
4300   gResourceReadySignal04ComesOrder = 0;
4301
4302   gImageView1 = ImageView::New("invalid.jpg"); // request invalid image, to make loading failed fast.
4303   gImageView1.ResourceReadySignal().Connect(&OnResourceReadySignal04);
4304   application.GetScene().Add(gImageView1);
4305
4306   gImageView2 = ImageView::New("invalid.png"); // request invalid image, to make loading failed fast.
4307   gImageView2.ResourceReadySignal().Connect(&OnResourceReadySignal04);
4308   application.GetScene().Add(gImageView2);
4309
4310   application.SendNotification();
4311   application.Render();
4312
4313   tet_infoline("Try to load 2 invalid image");
4314
4315   DALI_TEST_EQUALS(Test::WaitForEventThreadTrigger(2), true, TEST_LOCATION);
4316   DALI_TEST_EQUALS(gResourceReadySignalCounter, 2, TEST_LOCATION);
4317
4318   tet_infoline("load done");
4319
4320   // We can test this UTC only if gImageView1 and gImageView2 loaded done.
4321   if(gResourceReadySignal04ComesOrder == -1)
4322   {
4323     tet_infoline("Bad news.. gImageView3 or gImageView4 loaded faster than others. just skip this UTC");
4324   }
4325   else
4326   {
4327     // gImageView3 and gImageView4 load must not be successed yet.
4328     DALI_TEST_EQUALS(gImageView3.GetRendererCount(), 0u, TEST_LOCATION);
4329     DALI_TEST_EQUALS(gImageView4.GetRendererCount(), 0u, TEST_LOCATION);
4330
4331     application.SendNotification();
4332     application.Render();
4333
4334     tet_infoline("Try to load 2 valid image");
4335
4336     DALI_TEST_EQUALS(Test::WaitForEventThreadTrigger(2), true, TEST_LOCATION);
4337     DALI_TEST_EQUALS(gResourceReadySignalCounter, 4, TEST_LOCATION);
4338
4339     tet_infoline("load done");
4340
4341     // gImageView3 and gImageView4 load must be successed now.
4342     DALI_TEST_EQUALS(gImageView3.GetRendererAt(0).GetTextures().GetTextureCount(), 1u, TEST_LOCATION);
4343     DALI_TEST_EQUALS(gImageView4.GetRendererAt(0).GetTextures().GetTextureCount(), 1u, TEST_LOCATION);
4344   }
4345
4346   END_TEST;
4347 }
4348 int UtcDaliImageViewSetImageOnResourceReadySignal05(void)
4349 {
4350   tet_infoline("Test multiple views with same image during ResourceReady load the image only 1 times");
4351
4352   ToolkitTestApplication application;
4353
4354   gResourceReadySignalCounter = 0;
4355
4356   gImageView1 = ImageView::New("invalid.jpg"); // request invalid image, to make loading failed fast.
4357   gImageView1.ResourceReadySignal().Connect(&OnResourceReadySignal05);
4358   application.GetScene().Add(gImageView1);
4359
4360   application.SendNotification();
4361   application.Render();
4362
4363   tet_infoline("Try to load 1 invalid.jpg image");
4364   DALI_TEST_EQUALS(Test::WaitForEventThreadTrigger(1), true, TEST_LOCATION);
4365   DALI_TEST_EQUALS(gResourceReadySignalCounter, 1, TEST_LOCATION);
4366
4367   tet_infoline("Try to load 1 invalid2.jpg image");
4368   DALI_TEST_EQUALS(Test::WaitForEventThreadTrigger(1), true, TEST_LOCATION);
4369
4370   tet_infoline("Now we don't have any image to be loaded. Check event thread trigger failed.");
4371   DALI_TEST_EQUALS(Test::WaitForEventThreadTrigger(1, 1), false, TEST_LOCATION);
4372
4373   gImageView1.Unparent();
4374   gImageView1.Reset();
4375
4376   END_TEST;
4377 }
4378 int UtcDaliImageViewSetImageOnResourceReadySignal06(void)
4379 {
4380   tet_infoline("Test texturemanager's remove image & mask queue works well within signal handler.");
4381
4382   ToolkitTestApplication application;
4383
4384   gResourceReadySignalCounter      = 0;
4385   gResourceReadySignal06ComesOrder = 0;
4386
4387   Property::Map map;
4388   map[Toolkit::ImageVisual::Property::URL]            = "invalid.jpg";
4389   map[Toolkit::ImageVisual::Property::ALPHA_MASK_URL] = "invalid.png";
4390
4391   gImageView1 = ImageView::New(); // request invalid image, to make loading failed fast.
4392   gImageView1.SetProperty(Toolkit::ImageView::Property::IMAGE, map);
4393   gImageView1.ResourceReadySignal().Connect(&OnResourceReadySignal06);
4394   application.GetScene().Add(gImageView1);
4395
4396   gImageView2 = ImageView::New(); // request invalid image, to make loading failed fast.
4397   gImageView2.SetProperty(Toolkit::ImageView::Property::IMAGE, map);
4398   gImageView2.ResourceReadySignal().Connect(&OnResourceReadySignal06);
4399   application.GetScene().Add(gImageView2);
4400
4401   application.SendNotification();
4402   application.Render();
4403
4404   tet_infoline("Try to load 2 invalid image");
4405
4406   DALI_TEST_EQUALS(Test::WaitForEventThreadTrigger(2), true, TEST_LOCATION);
4407   DALI_TEST_EQUALS(gResourceReadySignalCounter, 2, TEST_LOCATION);
4408
4409   tet_infoline("load done");
4410
4411   // We can test this UTC only if gImageView1 and gImageView2 loaded done.
4412   if(gResourceReadySignal06ComesOrder == -1)
4413   {
4414     tet_infoline("Bad news.. gImageView3 or gImageView4 loaded faster than others. just skip this UTC");
4415   }
4416   else
4417   {
4418     // gImageView3 and gImageView4 load must not be successed yet.
4419     DALI_TEST_EQUALS(gImageView3.GetRendererCount(), 0u, TEST_LOCATION);
4420     DALI_TEST_EQUALS(gImageView4.GetRendererCount(), 0u, TEST_LOCATION);
4421
4422     application.GetScene().Add(gImageView3);
4423     application.GetScene().Add(gImageView4);
4424     application.SendNotification();
4425     application.Render();
4426
4427     tet_infoline("Try to load 2 valid image");
4428
4429     DALI_TEST_EQUALS(Test::WaitForEventThreadTrigger(2), true, TEST_LOCATION);
4430     DALI_TEST_EQUALS(gResourceReadySignalCounter, 2, TEST_LOCATION);
4431
4432     tet_infoline("Note that resource ready should not come now.");
4433     tet_infoline("Try to load remained 2 valid image + apply masking");
4434
4435     DALI_TEST_EQUALS(Test::WaitForEventThreadTrigger(4), true, TEST_LOCATION);
4436     DALI_TEST_EQUALS(gResourceReadySignalCounter, 4, TEST_LOCATION);
4437
4438     tet_infoline("Check all resource ready comes now.");
4439   }
4440   END_TEST;
4441 }
4442
4443 int UtcDaliImageViewSetImageOnResourceReadySignal07(void)
4444 {
4445   tet_infoline("Test texturemanager's remove image & mask queue works well within signal handler 02.");
4446
4447   ToolkitTestApplication application;
4448
4449   gResourceReadySignalCounter = 0;
4450
4451   Property::Map map;
4452   map[Toolkit::ImageVisual::Property::URL] = TEST_IMAGE_1;
4453
4454   // Clear image view for clear test
4455
4456   if(gImageView1)
4457   {
4458     gImageView1.Reset();
4459   }
4460   if(gImageView2)
4461   {
4462     gImageView2.Reset();
4463   }
4464
4465   gImageView1 = ImageView::New();
4466   gImageView1.SetProperty(Toolkit::ImageView::Property::IMAGE, map);
4467   gImageView1.ResourceReadySignal().Connect(&OnResourceReadySignal07);
4468   application.GetScene().Add(gImageView1);
4469
4470   application.SendNotification();
4471   application.Render();
4472
4473   // Load gImageView1
4474
4475   DALI_TEST_EQUALS(Test::WaitForEventThreadTrigger(1), true, TEST_LOCATION);
4476   DALI_TEST_EQUALS(gResourceReadySignalCounter, 1, TEST_LOCATION);
4477
4478   tet_infoline("load image1 done");
4479
4480   // Load gImageView2 and mask
4481
4482   DALI_TEST_EQUALS(Test::WaitForEventThreadTrigger(2), true, TEST_LOCATION);
4483   DALI_TEST_EQUALS(gResourceReadySignalCounter, 1, TEST_LOCATION);
4484
4485   // gImageView2 mask apply done
4486
4487   DALI_TEST_EQUALS(Test::WaitForEventThreadTrigger(1), true, TEST_LOCATION);
4488   DALI_TEST_EQUALS(gResourceReadySignalCounter, 2, TEST_LOCATION);
4489
4490   tet_infoline("load image2 done");
4491   END_TEST;
4492 }
4493
4494 int UtcDaliImageViewSetImageOnResourceReadySignal08(void)
4495 {
4496   tet_infoline("Test remove npatch images during resource ready");
4497
4498   ToolkitTestApplication application;
4499
4500   gResourceReadySignalCounter = 0;
4501
4502   Property::Map map;
4503   map[Toolkit::ImageVisual::Property::URL] = TEST_BROKEN_IMAGE_M;
4504
4505   // Clear image view for clear test
4506
4507   if(gImageView1)
4508   {
4509     gImageView1.Reset();
4510   }
4511   if(gImageView2)
4512   {
4513     gImageView2.Reset();
4514   }
4515
4516   // Case 1 : Remove all images during resource ready.
4517   try
4518   {
4519     gImageView1 = ImageView::New();
4520     gImageView1.SetProperty(Toolkit::ImageView::Property::IMAGE, map);
4521     gImageView1.ResourceReadySignal().Connect(&OnResourceReadySignal08);
4522     application.GetScene().Add(gImageView1);
4523
4524     application.SendNotification();
4525     application.Render();
4526
4527     // Load gImageView1
4528     DALI_TEST_EQUALS(Test::WaitForEventThreadTrigger(1), true, TEST_LOCATION);
4529     DALI_TEST_EQUALS(gResourceReadySignalCounter, 1, TEST_LOCATION);
4530
4531     application.SendNotification();
4532     application.Render();
4533
4534     DALI_TEST_CHECK(true);
4535   }
4536   catch(...)
4537   {
4538     // Exception should not happened
4539     DALI_TEST_CHECK(false);
4540   }
4541
4542   // Clear cache.
4543   application.SendNotification();
4544   application.Render();
4545
4546   gResourceReadySignalCounter = 0;
4547
4548   // Case 2 : Remove all images when we use cached resource.
4549   try
4550   {
4551     gImageView1 = ImageView::New();
4552     gImageView1.SetProperty(Toolkit::ImageView::Property::IMAGE, map);
4553     gImageView1.ResourceReadySignal().Connect(&OnSimpleResourceReadySignal);
4554     application.GetScene().Add(gImageView1);
4555
4556     application.SendNotification();
4557     application.Render();
4558
4559     // Load gImageView1
4560     DALI_TEST_EQUALS(Test::WaitForEventThreadTrigger(1), true, TEST_LOCATION);
4561     DALI_TEST_EQUALS(gResourceReadySignalCounter, 1, TEST_LOCATION);
4562
4563     application.SendNotification();
4564     application.Render();
4565
4566     gImageView2 = ImageView::New();
4567     gImageView2.SetProperty(Toolkit::ImageView::Property::IMAGE, map);
4568     gImageView2.ResourceReadySignal().Connect(&OnResourceReadySignal08);
4569     application.GetScene().Add(gImageView2);
4570     DALI_TEST_EQUALS(gResourceReadySignalCounter, 2, TEST_LOCATION);
4571
4572     application.SendNotification();
4573     application.Render();
4574
4575     DALI_TEST_CHECK(true);
4576   }
4577   catch(...)
4578   {
4579     // Exception should not happened
4580     DALI_TEST_CHECK(false);
4581   }
4582   gResourceReadySignalCounter = 0;
4583
4584   // Clear image view for clear test
4585
4586   if(gImageView1)
4587   {
4588     gImageView1.Reset();
4589   }
4590   if(gImageView2)
4591   {
4592     gImageView2.Reset();
4593   }
4594
4595   END_TEST;
4596 }
4597
4598 int UtcDaliImageViewSetImageOnResourceReadySignal09(void)
4599 {
4600   tet_infoline("Test load invalid npatch images during invalid resource ready");
4601
4602   ToolkitTestApplication application;
4603
4604   gResourceReadySignalCounter = 0;
4605
4606   Property::Map map;
4607   map[Toolkit::ImageVisual::Property::URL] = TEST_INVALID_NPATCH_FILE_NAME_01;
4608
4609   // Clear image view for clear test
4610
4611   if(gImageView1)
4612   {
4613     gImageView1.Reset();
4614   }
4615   if(gImageView2)
4616   {
4617     gImageView2.Reset();
4618   }
4619   if(gImageView3)
4620   {
4621     gImageView3.Reset();
4622   }
4623
4624   // Dummy view with npatch image
4625   ImageView dummyView = ImageView::New(TEST_BROKEN_IMAGE_M);
4626   application.GetScene().Add(dummyView);
4627
4628   application.SendNotification();
4629   application.Render();
4630   DALI_TEST_EQUALS(Test::WaitForEventThreadTrigger(1), true, TEST_LOCATION);
4631   application.SendNotification();
4632   application.Render();
4633
4634   // Case 1 : Reload images during resource ready.
4635   try
4636   {
4637     gResourceReadySignal09Emitted = false;
4638
4639     gImageView1 = ImageView::New();
4640     gImageView1.SetProperty(Toolkit::ImageView::Property::IMAGE, map);
4641     gImageView1.ResourceReadySignal().Connect(&OnResourceReadySignal09);
4642     application.GetScene().Add(gImageView1);
4643
4644     gImageView2 = ImageView::New();
4645     application.GetScene().Add(gImageView2);
4646
4647     // Load TEST_INVALID_NPATCH_FILE_NAME_01
4648     DALI_TEST_EQUALS(Test::WaitForEventThreadTrigger(1), true, TEST_LOCATION);
4649
4650     // Load TEST_INVALID_NPATCH_FILE_NAME_01 one more times.
4651     DALI_TEST_EQUALS(Test::WaitForEventThreadTrigger(1), true, TEST_LOCATION);
4652
4653     application.SendNotification();
4654     application.Render();
4655
4656     DALI_TEST_CHECK(true);
4657   }
4658   catch(...)
4659   {
4660     // Exception should not happened
4661     DALI_TEST_CHECK(false);
4662   }
4663
4664   // Clear cache.
4665   application.SendNotification();
4666   application.Render();
4667
4668   gResourceReadySignalCounter = 0;
4669
4670   // Case 2 : Remove all images when we use cached resource.
4671   try
4672   {
4673     gResourceReadySignal09Emitted = false;
4674
4675     gImageView3 = ImageView::New();
4676     gImageView3.SetProperty(Toolkit::ImageView::Property::IMAGE, map);
4677     gImageView3.ResourceReadySignal().Connect(&OnSimpleResourceReadySignal);
4678     application.GetScene().Add(gImageView3);
4679
4680     gImageView2 = ImageView::New();
4681     application.GetScene().Add(gImageView2);
4682
4683     // Load gImageView2
4684     DALI_TEST_EQUALS(Test::WaitForEventThreadTrigger(1), true, TEST_LOCATION);
4685
4686     gImageView1 = ImageView::New();
4687     gImageView1.SetProperty(Toolkit::ImageView::Property::IMAGE, map);
4688     gImageView1.ResourceReadySignal().Connect(&OnResourceReadySignal09);
4689     application.GetScene().Add(gImageView1);
4690
4691     // Load gImageView1
4692     DALI_TEST_EQUALS(Test::WaitForEventThreadTrigger(1), true, TEST_LOCATION);
4693
4694     // Load TEST_INVALID_NPATCH_FILE_NAME_01 one more times.
4695     DALI_TEST_EQUALS(Test::WaitForEventThreadTrigger(1), true, TEST_LOCATION);
4696
4697     application.SendNotification();
4698     application.Render();
4699
4700     DALI_TEST_CHECK(true);
4701   }
4702   catch(...)
4703   {
4704     // Exception should not happened
4705     DALI_TEST_CHECK(false);
4706   }
4707   gResourceReadySignalCounter = 0;
4708
4709   // Clear image view for clear test
4710
4711   if(gImageView1)
4712   {
4713     gImageView1.Reset();
4714   }
4715   if(gImageView2)
4716   {
4717     gImageView2.Reset();
4718   }
4719   if(gImageView3)
4720   {
4721     gImageView3.Reset();
4722   }
4723
4724   END_TEST;
4725 }
4726
4727 int UtcDaliImageViewSetImageOnResourceReadySignal10(void)
4728 {
4729   tet_infoline("Test ResourceReady signal comes more than 2 times.");
4730
4731   ToolkitTestApplication application;
4732
4733   gResourceReadySignalCounter = 0;
4734
4735   // Clear image view for clear test
4736
4737   if(gImageView1)
4738   {
4739     gImageView1.Reset();
4740   }
4741
4742   // Dummy view to cache image.
4743   ImageView dummyView = ImageView::New(gImage_34_RGBA);
4744   application.GetScene().Add(dummyView);
4745
4746   application.SendNotification();
4747   application.Render();
4748   DALI_TEST_EQUALS(Test::WaitForEventThreadTrigger(1), true, TEST_LOCATION);
4749   application.SendNotification();
4750   application.Render();
4751
4752   try
4753   {
4754     gImageView1 = ImageView::New();
4755     gImageView1.SetProperty(Toolkit::ImageView::Property::IMAGE, gImage_34_RGBA);
4756     gImageView1.ResourceReadySignal().Connect(&OnResourceReadySignal10);
4757     application.GetScene().Add(gImageView1); // It will call resourceReady signal 1 time.
4758
4759     tet_printf("ResourceReady called %d times\n", gResourceReadySignalCounter);
4760
4761     DALI_TEST_GREATER(gResourceReadySignal10MaxCounter, gResourceReadySignalCounter, TEST_LOCATION); // Check whether resource ready call too much.
4762
4763     for(int i = 0; i < gResourceReadySignal10MaxCounter; ++i)
4764     {
4765       tet_printf("RunIdles\n");
4766       // Executes the idle callbacks.
4767       application.RunIdles();
4768       application.SendNotification();
4769       application.Render();
4770       tet_printf("RunIdles done\n");
4771     }
4772     tet_printf("ResourceReady called %d times\n", gResourceReadySignalCounter);
4773
4774     DALI_TEST_EQUALS(gResourceReadySignalCounter, gResourceReadySignal10MaxCounter, TEST_LOCATION);
4775
4776     DALI_TEST_CHECK(true);
4777   }
4778   catch(...)
4779   {
4780     // Exception should not happened
4781     DALI_TEST_CHECK(false);
4782   }
4783
4784   // Clear cache.
4785   application.SendNotification();
4786   application.Render();
4787
4788   gResourceReadySignalCounter = 0;
4789
4790   gResourceReadySignalCounter = 0;
4791
4792   // Clear image view for clear test
4793
4794   if(gImageView1)
4795   {
4796     gImageView1.Reset();
4797   }
4798
4799   END_TEST;
4800 }
4801
4802 int UtcDaliImageViewSetImageOnResourceReadySignal11(void)
4803 {
4804   tet_infoline("Test ResourceReady Add AnimatedImageVisual and then Remove immediately.");
4805
4806   ToolkitTestApplication application;
4807
4808   gResourceReadySignalCounter = 0;
4809
4810   // Clear image view for clear test
4811
4812   if(gImageView1)
4813   {
4814     gImageView1.Reset();
4815   }
4816   if(gImageView2)
4817   {
4818     gImageView2.Reset();
4819   }
4820   if(gImageView3)
4821   {
4822     gImageView3.Reset();
4823   }
4824
4825   try
4826   {
4827     gImageView1 = ImageView::New();
4828     gImageView1.SetProperty(Toolkit::ImageView::Property::IMAGE, TEST_GIF_FILE_NAME);
4829     gImageView1.ResourceReadySignal().Connect(&OnResourceReadySignal11);
4830     application.GetScene().Add(gImageView1); // It will call resourceReady signal 1 time.
4831
4832     tet_printf("ResourceReady called %d times\n", gResourceReadySignalCounter);
4833
4834     DALI_TEST_EQUALS(gResourceReadySignalCounter, 0, TEST_LOCATION);
4835
4836     application.SendNotification();
4837     application.Render();
4838
4839     // Load gImageView1
4840     DALI_TEST_EQUALS(Test::WaitForEventThreadTrigger(1), true, TEST_LOCATION);
4841
4842     tet_printf("ResourceReady called %d times\n", gResourceReadySignalCounter);
4843
4844     DALI_TEST_EQUALS(gResourceReadySignalCounter, 1, TEST_LOCATION);
4845
4846     DALI_TEST_CHECK(true);
4847   }
4848   catch(...)
4849   {
4850     // Exception should not happened
4851     DALI_TEST_CHECK(false);
4852   }
4853
4854   // Clear cache.
4855   application.SendNotification();
4856   application.Render();
4857
4858   gResourceReadySignalCounter = 0;
4859
4860   // Clear image view for clear test
4861
4862   if(gImageView1)
4863   {
4864     gImageView1.Reset();
4865   }
4866   if(gImageView2)
4867   {
4868     gImageView2.Reset();
4869   }
4870   if(gImageView3)
4871   {
4872     gImageView3.Reset();
4873   }
4874
4875   END_TEST;
4876 }
4877
4878 int UtcDaliImageViewUseSameUrlWithAnimatedImageVisual(void)
4879 {
4880   tet_infoline("Test multiple views with same image in animated image visual");
4881   ToolkitTestApplication application;
4882
4883   gImageView1 = ImageView::New(TEST_WEBP_FILE_NAME);
4884   application.GetScene().Add(gImageView1);
4885
4886   tet_infoline("Remove imageView and Create new imageView with same url");
4887   application.GetScene().Remove(gImageView1);
4888   gImageView2 = ImageView::New(TEST_WEBP_FILE_NAME);
4889   application.GetScene().Add(gImageView2);
4890
4891   application.SendNotification();
4892   application.Render();
4893
4894   tet_infoline("Check the ImageView load image successfully");
4895   DALI_TEST_EQUALS(Test::WaitForEventThreadTrigger(1), true, TEST_LOCATION);
4896   END_TEST;
4897 }
4898
4899 int UtcDaliImageViewNpatchImageCacheTest01(void)
4900 {
4901   tet_infoline("Test npatch image cached");
4902
4903   ToolkitTestApplication application;
4904   ImageView              imageView[2];
4905
4906   auto& gl = application.GetGlAbstraction();
4907   gl.EnableTextureCallTrace(true);
4908   auto& textureCallStack = gl.GetTextureTrace();
4909   textureCallStack.Enable(true);
4910   textureCallStack.EnableLogging(true);
4911
4912   auto TestNPatch = [&](int index, const std::string& nPatchImageUrl, const char* location) {
4913     if(imageView[index])
4914     {
4915       imageView[index].Unparent();
4916     }
4917
4918     // Ensure remove npatch cache if required.
4919     application.SendNotification();
4920     application.Render();
4921
4922     imageView[index] = ImageView::New(nPatchImageUrl);
4923     imageView[index].SetProperty(Actor::Property::SIZE, Vector2(100.0f, 200.0f));
4924     application.GetScene().Add(imageView[index]);
4925   };
4926
4927   TestNPatch(0, TEST_BROKEN_IMAGE_M, TEST_LOCATION);
4928   DALI_TEST_EQUALS(Test::WaitForEventThreadTrigger(1), true, TEST_LOCATION);
4929
4930   application.SendNotification();
4931   application.Render();
4932
4933   tet_printf("trace : \n%s\n", textureCallStack.GetTraceString().c_str());
4934
4935   // Check we gen only 1 textures
4936   DALI_TEST_EQUALS(textureCallStack.CountMethod("GenTextures"), 1, TEST_LOCATION);
4937   textureCallStack.Reset();
4938
4939   // Let we use cached textures
4940   for(int i = 0; i < 10; i++)
4941   {
4942     TestNPatch(1, TEST_BROKEN_IMAGE_M, TEST_LOCATION);
4943     TestNPatch(0, TEST_BROKEN_IMAGE_M, TEST_LOCATION);
4944   }
4945
4946   application.SendNotification();
4947   application.Render();
4948   // Check we use cached npatch data so we don't generate new texture textures
4949   DALI_TEST_EQUALS(textureCallStack.CountMethod("GenTextures"), 0, TEST_LOCATION);
4950
4951   // Clear all cached
4952   imageView[0].Unparent();
4953   imageView[0].Reset();
4954   imageView[1].Unparent();
4955   imageView[1].Reset();
4956
4957   application.SendNotification();
4958   application.Render();
4959
4960   textureCallStack.Reset();
4961   // Let we use deference textures
4962   TestNPatch(1, TEST_BROKEN_IMAGE_S, TEST_LOCATION);
4963   DALI_TEST_EQUALS(Test::WaitForEventThreadTrigger(1), true, TEST_LOCATION);
4964
4965   application.SendNotification();
4966   application.Render();
4967   // Try to load multiple times.
4968   for(int i = 0; i < 3; i++)
4969   {
4970     TestNPatch(0, TEST_BROKEN_IMAGE_M, TEST_LOCATION);
4971     DALI_TEST_EQUALS(Test::WaitForEventThreadTrigger(1), true, TEST_LOCATION);
4972     TestNPatch(1, TEST_BROKEN_IMAGE_S, TEST_LOCATION);
4973     DALI_TEST_EQUALS(Test::WaitForEventThreadTrigger(1), true, TEST_LOCATION);
4974   }
4975   application.SendNotification();
4976   application.Render();
4977
4978   imageView[0].Unparent();
4979   imageView[0].Reset();
4980   imageView[1].Unparent();
4981   imageView[1].Reset();
4982
4983   application.SendNotification();
4984   application.Render();
4985
4986   // Check memory leak
4987   DALI_TEST_EQUALS(textureCallStack.CountMethod("GenTextures"), textureCallStack.CountMethod("DeleteTextures"), TEST_LOCATION);
4988
4989   END_TEST;
4990 }
4991
4992 int UtcDaliImageViewNpatchImageCacheTest02(void)
4993 {
4994   tet_infoline("Test npatch image cached with border");
4995
4996   ToolkitTestApplication application;
4997   ImageView              imageView[2];
4998
4999   auto& gl = application.GetGlAbstraction();
5000   gl.EnableTextureCallTrace(true);
5001   auto& textureCallStack = gl.GetTextureTrace();
5002   textureCallStack.Enable(true);
5003   textureCallStack.EnableLogging(true);
5004
5005   auto TestBorderImage = [&](int index, const std::string& normalImageUrl, const Rect<int> border, const char* location) {
5006     Property::Map map;
5007     map[Toolkit::Visual::Property::TYPE]        = Toolkit::Visual::N_PATCH;
5008     map[Toolkit::ImageVisual::Property::URL]    = normalImageUrl;
5009     map[Toolkit::ImageVisual::Property::BORDER] = border;
5010
5011     imageView[index] = ImageView::New();
5012     imageView[index].SetProperty(Toolkit::ImageView::Property::IMAGE, map);
5013     imageView[index].SetProperty(Actor::Property::SIZE, Vector2(100.0f, 200.0f));
5014     application.GetScene().Add(imageView[index]);
5015   };
5016
5017   TestBorderImage(0, gImage_34_RGBA, Rect<int>(0, 0, 0, 0), TEST_LOCATION);
5018   DALI_TEST_EQUALS(Test::WaitForEventThreadTrigger(1), true, TEST_LOCATION);
5019
5020   application.SendNotification();
5021   application.Render();
5022
5023   tet_printf("trace : \n%s\n", textureCallStack.GetTraceString().c_str());
5024
5025   // Check we gen only 1 textures
5026   DALI_TEST_EQUALS(textureCallStack.CountMethod("GenTextures"), 1, TEST_LOCATION);
5027   textureCallStack.Reset();
5028
5029   // Let we use cached textures
5030   for(int i = 0; i < 10; i++)
5031   {
5032     TestBorderImage(0, gImage_34_RGBA, Rect<int>(i, i + 1, i + 2, i + 3), TEST_LOCATION);
5033     TestBorderImage(1, gImage_34_RGBA, Rect<int>(i + 1, i, i + 3, i + 2), TEST_LOCATION);
5034   }
5035
5036   application.SendNotification();
5037   application.Render();
5038
5039   // Check we use cached npatch data so we don't generate new texture textures
5040   DALI_TEST_EQUALS(textureCallStack.CountMethod("GenTextures"), 0, TEST_LOCATION);
5041
5042   END_TEST;
5043 }
5044
5045 int UtcDaliImageViewPlaceholderImage01(void)
5046 {
5047   tet_infoline("Test imageView use placeholder image");
5048
5049   ToolkitTestApplication application;
5050   Property::Map          map;
5051   map[Toolkit::ImageVisual::Property::URL] = gImage_600_RGB;
5052
5053   ImageView imageView = ImageView::New();
5054   imageView.SetProperty(Toolkit::ImageView::Property::IMAGE, map);
5055   imageView.SetProperty(Actor::Property::SIZE, Vector2(100.0f, 200.0f));
5056   application.GetScene().Add(imageView);
5057
5058   Property::Value value = imageView.GetProperty(ImageView::Property::PLACEHOLDER_IMAGE);
5059   std::string     url;
5060   DALI_TEST_CHECK(value.Get(url));
5061   DALI_TEST_CHECK(url.empty());
5062   imageView.SetProperty(Toolkit::ImageView::Property::PLACEHOLDER_IMAGE, gImage_34_RGBA);
5063
5064   application.SendNotification();
5065   application.Render();
5066
5067   value = imageView.GetProperty(ImageView::Property::PLACEHOLDER_IMAGE);
5068   DALI_TEST_CHECK(value.Get(url));
5069   DALI_TEST_CHECK(url == gImage_34_RGBA);
5070
5071   imageView.SetProperty(Toolkit::ImageView::Property::IMAGE, map);
5072   application.SendNotification();
5073   application.Render();
5074
5075   // Replace Image test
5076   map[Toolkit::ImageVisual::Property::URL]    = TEST_IMAGE_1;
5077   map[ImageView::Property::PLACEHOLDER_IMAGE] = gImage_34_RGBA;
5078   imageView.SetProperty(Toolkit::ImageView::Property::IMAGE, map);
5079   application.SendNotification();
5080   application.Render();
5081
5082   map[Toolkit::ImageVisual::Property::URL] = "";
5083   imageView.SetProperty(Toolkit::ImageView::Property::IMAGE, map);
5084   application.SendNotification();
5085   application.Render();
5086
5087   map[Toolkit::ImageVisual::Property::URL] = TEST_IMAGE_2;
5088   imageView.SetProperty(Toolkit::ImageView::Property::IMAGE, map);
5089   application.SendNotification();
5090   application.Render();
5091
5092   // Replace Image test2
5093   map[Toolkit::ImageVisual::Property::URL] = TEST_IMAGE_1;
5094   imageView.SetProperty(Toolkit::ImageView::Property::IMAGE, map);
5095   application.SendNotification();
5096   application.Render();
5097
5098   map[Toolkit::ImageVisual::Property::URL] = TEST_IMAGE_2;
5099   imageView.SetProperty(Toolkit::ImageView::Property::IMAGE, map);
5100   application.SendNotification();
5101   application.Render();
5102
5103   map[Toolkit::ImageVisual::Property::URL] = gImage_600_RGB;
5104   imageView.SetProperty(Toolkit::ImageView::Property::IMAGE, map);
5105   application.SendNotification();
5106   application.Render(900);
5107
5108   map[Toolkit::ImageVisual::Property::URL] = "";
5109   imageView.SetProperty(Toolkit::ImageView::Property::IMAGE, map);
5110   application.SendNotification();
5111   application.Render();
5112
5113   map[Toolkit::ImageVisual::Property::URL] = TEST_IMAGE_1;
5114   imageView.SetProperty(Toolkit::ImageView::Property::IMAGE, map);
5115   application.SendNotification();
5116   application.Render();
5117
5118   END_TEST;
5119 }
5120
5121 int UtcDaliImageViewPlaceholderImage02(void)
5122 {
5123   tet_infoline("Test imageView use placeholder image without resource ready");
5124
5125   ToolkitTestApplication application;
5126
5127   Property::Map map;
5128   map[Toolkit::ImageVisual::Property::URL] = gImage_600_RGB;
5129
5130   ImageView imageView = ImageView::New();
5131   imageView.SetProperty(Toolkit::ImageView::Property::IMAGE, map);
5132   imageView.SetProperty(Actor::Property::SIZE, Vector2(100.0f, 200.0f));
5133   DALI_TEST_EQUALS(imageView.IsResourceReady(), false, TEST_LOCATION);
5134   imageView.ResourceReadySignal().Connect(&ResourceReadySignal);
5135   application.GetScene().Add(imageView);
5136
5137   Property::Value value = imageView.GetProperty(ImageView::Property::PLACEHOLDER_IMAGE);
5138   std::string     url;
5139   DALI_TEST_CHECK(value.Get(url));
5140   DALI_TEST_CHECK(url.empty());
5141
5142   imageView.SetProperty(Toolkit::ImageView::Property::PLACEHOLDER_IMAGE, gImage_34_RGBA);
5143   application.SendNotification();
5144   application.Render();
5145
5146   DALI_TEST_EQUALS(Test::WaitForEventThreadTrigger(1), true, TEST_LOCATION);
5147
5148   value = imageView.GetProperty(ImageView::Property::PLACEHOLDER_IMAGE);
5149   DALI_TEST_CHECK(value.Get(url));
5150   DALI_TEST_CHECK(url == gImage_34_RGBA);
5151
5152   DALI_TEST_EQUALS(imageView.IsResourceReady(), true, TEST_LOCATION);
5153   DALI_TEST_EQUALS(gResourceReadySignalFired, true, TEST_LOCATION);
5154
5155   gResourceReadySignalFired                = false;
5156   map[Toolkit::ImageVisual::Property::URL] = "";
5157   imageView.SetProperty(Toolkit::ImageView::Property::IMAGE, map);
5158   application.SendNotification();
5159   application.Render();
5160
5161   DALI_TEST_EQUALS(imageView.IsResourceReady(), true, TEST_LOCATION);
5162   DALI_TEST_EQUALS(gResourceReadySignalFired, false, TEST_LOCATION);
5163
5164   END_TEST;
5165 }
5166
5167 int UtcDaliImageViewTransitionEffect01(void)
5168 {
5169   tet_infoline("Test imageView use transition effect");
5170
5171   ToolkitTestApplication application;
5172   Property::Map          map;
5173   map[Toolkit::ImageVisual::Property::URL] = gImage_600_RGB;
5174   map[Toolkit::Visual::Property::OPACITY]  = 0.9f;
5175
5176   ImageView imageView = ImageView::New();
5177   imageView.SetProperty(Toolkit::ImageView::Property::IMAGE, map);
5178   imageView.SetProperty(Actor::Property::SIZE, Vector2(100.0f, 200.0f));
5179   application.GetScene().Add(imageView);
5180
5181   Property::Value value = imageView.GetProperty(ImageView::Property::ENABLE_TRANSITION_EFFECT);
5182   bool            transition;
5183   DALI_TEST_CHECK(value.Get(transition));
5184   DALI_TEST_CHECK(transition == false);
5185   imageView.SetProperty(Toolkit::ImageView::Property::ENABLE_TRANSITION_EFFECT, true);
5186
5187   application.SendNotification();
5188   application.Render();
5189
5190   value = imageView.GetProperty(ImageView::Property::ENABLE_TRANSITION_EFFECT);
5191   DALI_TEST_CHECK(value.Get(transition));
5192   DALI_TEST_CHECK(transition == true);
5193
5194   imageView.SetProperty(Toolkit::ImageView::Property::IMAGE, map);
5195   DALI_TEST_EQUALS(Test::WaitForEventThreadTrigger(1), true, TEST_LOCATION);
5196   application.SendNotification();
5197   application.Render();
5198
5199   // Test transition effect with placeholder
5200   map[Toolkit::ImageVisual::Property::URL] = TEST_IMAGE_1;
5201   imageView.SetProperty(Toolkit::ImageView::Property::IMAGE, map);
5202   imageView.SetProperty(Toolkit::ImageView::Property::PLACEHOLDER_IMAGE, gImage_34_RGBA);
5203   DALI_TEST_EQUALS(Test::WaitForEventThreadTrigger(1), true, TEST_LOCATION);
5204   application.SendNotification();
5205   application.Render();
5206
5207   map[Toolkit::ImageVisual::Property::URL] = "";
5208   imageView.SetProperty(Toolkit::ImageView::Property::IMAGE, map);
5209   imageView.SetProperty(Toolkit::ImageView::Property::PLACEHOLDER_IMAGE, gImage_34_RGBA);
5210   application.SendNotification();
5211   application.Render();
5212
5213   map[Toolkit::ImageVisual::Property::URL] = gImage_600_RGB;
5214   imageView.SetProperty(Toolkit::ImageView::Property::IMAGE, map);
5215   imageView.SetProperty(Toolkit::ImageView::Property::PLACEHOLDER_IMAGE, gImage_34_RGBA);
5216   application.SendNotification();
5217   application.Render();
5218
5219   map[Toolkit::ImageVisual::Property::URL] = TEST_IMAGE_1;
5220   imageView.SetProperty(Toolkit::ImageView::Property::IMAGE, map);
5221   imageView.SetProperty(Toolkit::ImageView::Property::PLACEHOLDER_IMAGE, gImage_34_RGBA);
5222   application.SendNotification();
5223
5224   map[Toolkit::ImageVisual::Property::URL] = "";
5225   imageView.SetProperty(Toolkit::ImageView::Property::IMAGE, map);
5226   imageView.SetProperty(Toolkit::ImageView::Property::PLACEHOLDER_IMAGE, gImage_34_RGBA);
5227   application.SendNotification();
5228   application.Render();
5229
5230   map[Toolkit::ImageVisual::Property::URL] = gImage_600_RGB;
5231   imageView.SetProperty(Toolkit::ImageView::Property::IMAGE, map);
5232   imageView.SetProperty(Toolkit::ImageView::Property::PLACEHOLDER_IMAGE, "");
5233   application.SendNotification();
5234   application.Render();
5235
5236   map[Toolkit::ImageVisual::Property::URL] = gImage_600_RGB;
5237   imageView.SetProperty(Toolkit::ImageView::Property::IMAGE, map);
5238   application.SendNotification();
5239   application.Render();
5240
5241   map[Toolkit::ImageVisual::Property::URL] = "";
5242   imageView.SetProperty(Toolkit::ImageView::Property::IMAGE, map);
5243   application.SendNotification();
5244   application.Render();
5245
5246   // Test transition effect without placeholder
5247   map[Toolkit::ImageVisual::Property::URL] = TEST_IMAGE_1;
5248   imageView.SetProperty(Toolkit::ImageView::Property::IMAGE, map);
5249   application.SendNotification();
5250   application.Render();
5251
5252   map[Toolkit::ImageVisual::Property::URL] = gImage_600_RGB;
5253   imageView.SetProperty(Toolkit::ImageView::Property::IMAGE, map);
5254   application.SendNotification();
5255   application.Render();
5256
5257   map[Toolkit::ImageVisual::Property::URL] = "";
5258   imageView.SetProperty(Toolkit::ImageView::Property::IMAGE, map);
5259   application.SendNotification();
5260   application.Render();
5261
5262   map[Toolkit::ImageVisual::Property::URL] = gImage_600_RGB;
5263   imageView.SetProperty(Toolkit::ImageView::Property::IMAGE, map);
5264   application.SendNotification();
5265   application.Render();
5266
5267   imageView.SetImage(TEST_IMAGE_1);
5268   application.SendNotification();
5269   application.Render();
5270
5271   imageView.SetImage(gImage_600_RGB);
5272   application.SendNotification();
5273   application.Render(9000);
5274
5275   imageView.SetImage("");
5276   application.SendNotification();
5277   application.Render();
5278
5279   imageView.SetImage(TEST_IMAGE_1);
5280   application.SendNotification();
5281   application.Render();
5282
5283   // Clear all cached
5284   imageView.Unparent();
5285   imageView.Reset();
5286
5287   END_TEST;
5288 }
5289
5290 int UtcDaliImageViewTransitionEffect02(void)
5291 {
5292   tet_infoline("Test imageView use transition effect with replace image");
5293
5294   ToolkitTestApplication application;
5295
5296   Property::Map map;
5297
5298   ImageView imageView = ImageView::New();
5299   imageView.SetProperty(Toolkit::ImageView::Property::IMAGE, map);
5300   imageView.SetProperty(Actor::Property::SIZE, Vector2(100.0f, 200.0f));
5301   application.GetScene().Add(imageView);
5302
5303   Property::Value value;
5304   value = imageView.GetProperty(ImageView::Property::ENABLE_TRANSITION_EFFECT);
5305   bool transition;
5306   DALI_TEST_CHECK(value.Get(transition));
5307   DALI_TEST_CHECK(transition == false);
5308   imageView.SetProperty(Toolkit::ImageView::Property::ENABLE_TRANSITION_EFFECT, true);
5309
5310   value = imageView.GetProperty(ImageView::Property::PLACEHOLDER_IMAGE);
5311   std::string url;
5312   DALI_TEST_CHECK(value.Get(url));
5313   DALI_TEST_CHECK(url.empty());
5314   imageView.SetProperty(Toolkit::ImageView::Property::PLACEHOLDER_IMAGE, gImage_34_RGBA);
5315   application.SendNotification();
5316   application.Render();
5317
5318   imageView.SetProperty(Toolkit::ImageView::Property::PLACEHOLDER_IMAGE, "");
5319   application.SendNotification();
5320   application.Render();
5321
5322   imageView.SetProperty(Toolkit::ImageView::Property::PLACEHOLDER_IMAGE, gImage_34_RGBA);
5323   application.SendNotification();
5324   application.Render();
5325
5326   value = imageView.GetProperty(ImageView::Property::ENABLE_TRANSITION_EFFECT);
5327   DALI_TEST_CHECK(value.Get(transition));
5328   DALI_TEST_CHECK(transition == true);
5329
5330   value = imageView.GetProperty(ImageView::Property::PLACEHOLDER_IMAGE);
5331   DALI_TEST_CHECK(value.Get(url));
5332   DALI_TEST_CHECK(url == gImage_34_RGBA);
5333
5334   imageView.SetProperty(Toolkit::ImageView::Property::IMAGE, map);
5335   application.SendNotification();
5336   application.Render();
5337
5338   // Clear all cached
5339   imageView.Unparent();
5340   imageView.Reset();
5341
5342   END_TEST;
5343 }
5344
5345 int UtcDaliImageViewTransitionEffect03(void)
5346 {
5347   tet_infoline("Test imageView use transition effect with placeholder");
5348
5349   ToolkitTestApplication application;
5350   Property::Map          map;
5351
5352   ImageView imageView = ImageView::New();
5353   imageView.SetImage("");
5354   imageView.SetProperty(Actor::Property::SIZE, Vector2(100.0f, 200.0f));
5355   imageView.SetProperty(ImageView::Property::PLACEHOLDER_IMAGE, gImage_34_RGBA);
5356   imageView.SetProperty(ImageView::Property::ENABLE_TRANSITION_EFFECT, true);
5357   application.GetScene().Add(imageView);
5358
5359   //DALI_TEST_EQUALS(Test::WaitForEventThreadTrigger(1), true, TEST_LOCATION);
5360
5361   application.SendNotification();
5362   application.Render(16);
5363
5364   tet_infoline("(1)");
5365   imageView.SetImage(gImage_600_RGB);
5366   imageView.SetProperty(ImageView::Property::PLACEHOLDER_IMAGE, gImage_34_RGBA);
5367   DALI_TEST_EQUALS(Test::WaitForEventThreadTrigger(2), true, TEST_LOCATION);
5368   application.SendNotification();
5369   application.Render(16);
5370
5371   Property::Value value;
5372   value = imageView.GetProperty(ImageView::Property::ENABLE_TRANSITION_EFFECT);
5373   bool transition;
5374   DALI_TEST_CHECK(value.Get(transition));
5375   DALI_TEST_CHECK(transition == true);
5376
5377   value = imageView.GetProperty(ImageView::Property::PLACEHOLDER_IMAGE);
5378   std::string url;
5379   DALI_TEST_CHECK(value.Get(url));
5380   DALI_TEST_CHECK(url == gImage_34_RGBA);
5381
5382   imageView.SetImage("");
5383   application.SendNotification();
5384   application.Render(16);
5385
5386   imageView.SetImage(TEST_IMAGE_1);
5387   imageView.SetProperty(ImageView::Property::PLACEHOLDER_IMAGE, gImage_34_RGBA);
5388   DALI_TEST_EQUALS(Test::WaitForEventThreadTrigger(1), true, TEST_LOCATION);
5389   application.SendNotification();
5390   application.Render(16);
5391
5392   // Clear all cached
5393   imageView.Unparent();
5394   imageView.Reset();
5395
5396   END_TEST;
5397 }