Merge "Apply premultiply when external texture use mask" into devel/master
[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 UtcDaliImageViewAddedTexture(void)
883 {
884   ToolkitTestApplication application;
885
886   tet_infoline("ImageView Testing image view with texture provided manager url");
887
888   ImageView imageView = ImageView::New();
889
890   // empty texture is ok, though pointless from app point of view
891   TextureSet  empty;
892   std::string url = TextureManager::AddTexture(empty);
893   DALI_TEST_CHECK(url.size() > 0u);
894
895   Property::Map propertyMap;
896   propertyMap[ImageVisual::Property::URL] = url;
897   imageView.SetProperty(ImageView::Property::IMAGE, propertyMap);
898
899   application.GetScene().Add(imageView);
900   application.SendNotification();
901   application.Render();
902
903   END_TEST;
904 }
905
906 int UtcDaliImageViewSizeWithBackground(void)
907 {
908   ToolkitTestApplication application;
909
910   int       width     = 100;
911   int       height    = 200;
912   ImageView imageView = ImageView::New();
913
914   imageView.SetProperty(Control::Property::BACKGROUND,
915                         {
916                           {Toolkit::Visual::Property::TYPE, Toolkit::Visual::IMAGE},
917                           {Toolkit::ImageVisual::Property::URL, TEST_RESOURCE_DIR "/gallery-small-1.jpg"},
918                           {ImageVisual::Property::DESIRED_WIDTH, width},
919                           {ImageVisual::Property::DESIRED_HEIGHT, height},
920                         });
921
922   application.GetScene().Add(imageView);
923   application.SendNotification();
924   application.Render();
925
926   DALI_TEST_EQUALS(imageView.GetCurrentProperty<Vector3>(Actor::Property::SIZE).width, (float)width, TEST_LOCATION);
927   DALI_TEST_EQUALS(imageView.GetCurrentProperty<Vector3>(Actor::Property::SIZE).height, (float)height, TEST_LOCATION);
928
929   END_TEST;
930 }
931
932 int UtcDaliImageViewSizeWithBackgroundAndImage(void)
933 {
934   ToolkitTestApplication application;
935
936   int widthBackground  = 100;
937   int heightBackground = 200;
938   int width            = 600;
939   int height           = 600;
940
941   ImageView imageView = ImageView::New();
942
943   imageView.SetProperty(Control::Property::BACKGROUND,
944                         {
945                           {Toolkit::Visual::Property::TYPE, Toolkit::Visual::IMAGE},
946                           {Toolkit::ImageVisual::Property::URL, TEST_RESOURCE_DIR "/gallery-small-1.jpg"},
947                           {ImageVisual::Property::DESIRED_WIDTH, widthBackground},
948                           {ImageVisual::Property::DESIRED_HEIGHT, heightBackground},
949                         });
950
951   imageView.SetImage(gImage_600_RGB); // 1 to 1 ratio, 600x600 pixels
952
953   application.GetScene().Add(imageView);
954   application.SendNotification();
955   application.Render();
956
957   DALI_TEST_EQUALS(imageView.GetCurrentProperty<Vector3>(Actor::Property::SIZE).width, (float)width, TEST_LOCATION);
958   DALI_TEST_EQUALS(imageView.GetCurrentProperty<Vector3>(Actor::Property::SIZE).height, (float)height, TEST_LOCATION);
959
960   END_TEST;
961 }
962
963 int UtcDaliImageViewHeightForWidthBackground(void)
964 {
965   ToolkitTestApplication application;
966
967   int widthBackground  = 100;
968   int heightBackground = 200;
969
970   ImageView imageView = ImageView::New();
971
972   imageView.SetProperty(Control::Property::BACKGROUND,
973                         {{Toolkit::Visual::Property::TYPE, Toolkit::Visual::IMAGE},
974                          {Toolkit::ImageVisual::Property::URL, TEST_RESOURCE_DIR "/gallery-small-1.jpg"},
975                          {ImageVisual::Property::DESIRED_WIDTH, widthBackground},
976                          {ImageVisual::Property::DESIRED_HEIGHT, heightBackground}});
977
978   application.GetScene().Add(imageView);
979   application.SendNotification();
980   application.Render();
981
982   Control control = Control::DownCast(imageView);
983   DALI_TEST_CHECK(control);
984   DALI_TEST_EQUALS(imageView.GetHeightForWidth(123.f), control.GetHeightForWidth(123.f), TEST_LOCATION);
985   DALI_TEST_EQUALS(imageView.GetWidthForHeight(321.f), control.GetWidthForHeight(321.f), TEST_LOCATION);
986
987   END_TEST;
988 }
989
990 int UtcDaliImageViewHeightForWidthBackgroundAndImage(void)
991 {
992   ToolkitTestApplication application;
993
994   int widthBackground  = 100;
995   int heightBackground = 200;
996   int width            = 300;
997   int height           = 300;
998
999   ImageView imageView = ImageView::New();
1000
1001   imageView.SetProperty(Control::Property::BACKGROUND,
1002                         {{Toolkit::Visual::Property::TYPE, Toolkit::Visual::IMAGE},
1003                          {Toolkit::ImageVisual::Property::URL, TEST_RESOURCE_DIR "/gallery-small-1.jpg"},
1004                          {ImageVisual::Property::DESIRED_WIDTH, widthBackground},
1005                          {ImageVisual::Property::DESIRED_HEIGHT, heightBackground}}); // 1 to 2 ratio
1006
1007   imageView.SetImage(gImage_600_RGB); // 1 to 1 ratio
1008
1009   application.GetScene().Add(imageView);
1010   application.SendNotification();
1011   application.Render();
1012
1013   DALI_TEST_EQUALS(imageView.GetHeightForWidth(width), (float)height, TEST_LOCATION);
1014   DALI_TEST_EQUALS(imageView.GetWidthForHeight(height), (float)width, TEST_LOCATION);
1015
1016   END_TEST;
1017 }
1018
1019 int UtcDaliImageViewSetImageUrl(void)
1020 {
1021   ToolkitTestApplication application;
1022
1023   ImageView imageView = ImageView::New();
1024   imageView.SetImage(TEST_IMAGE_FILE_NAME);
1025   TestUrl(imageView, TEST_IMAGE_FILE_NAME);
1026
1027   imageView.SetImage(TEST_IMAGE_FILE_NAME2);
1028   TestUrl(imageView, TEST_IMAGE_FILE_NAME2);
1029
1030   END_TEST;
1031 }
1032
1033 bool    gResourceReadySignalFired = false;
1034 Vector3 gNaturalSize;
1035
1036 void ResourceReadySignal(Control control)
1037 {
1038   gResourceReadySignalFired = true;
1039 }
1040
1041 void OnResourceReadySignalSVG(Control control)
1042 {
1043   // Check whether Image Visual transforms on ImageVieiw::OnRelayout()
1044   Toolkit::Internal::Control& controlImpl = Toolkit::Internal::GetImplementation(control);
1045   Toolkit::Visual::Base       imageVisual = DevelControl::GetVisual(controlImpl, ImageView::Property::IMAGE);
1046   Property::Map               resultMap;
1047   imageVisual.CreatePropertyMap(resultMap);
1048
1049   Property::Value* transformValue = resultMap.Find(Visual::Property::TRANSFORM);
1050   DALI_TEST_CHECK(transformValue);
1051   Property::Map* retMap = transformValue->GetMap();
1052   DALI_TEST_CHECK(retMap);
1053
1054   // Fitting mode should not be applied at this point
1055   DALI_TEST_EQUALS(retMap->Find(Visual::Transform::Property::SIZE)->Get<Vector2>(), Vector2::ZERO, TEST_LOCATION);
1056 }
1057
1058 int UtcDaliImageViewCheckResourceReady(void)
1059 {
1060   ToolkitTestApplication application;
1061
1062   gResourceReadySignalFired = false;
1063
1064   // Check ImageView with background and main image, to ensure both visuals are marked as loaded
1065   ImageView imageView = ImageView::New(TEST_GIF_FILE_NAME);
1066
1067   imageView.SetProperty(Control::Property::BACKGROUND,
1068                         {{Toolkit::Visual::Property::TYPE, Toolkit::Visual::IMAGE},
1069                          {Toolkit::ImageVisual::Property::URL, TEST_RESOURCE_DIR "/gallery-small-1.jpg"},
1070                          {ImageVisual::Property::DESIRED_WIDTH, 100},
1071                          {ImageVisual::Property::DESIRED_HEIGHT, 200}});
1072
1073   DALI_TEST_EQUALS(imageView.IsResourceReady(), false, TEST_LOCATION);
1074
1075   imageView.ResourceReadySignal().Connect(&ResourceReadySignal);
1076
1077   application.GetScene().Add(imageView);
1078
1079   // loading started, this waits for the loader thread
1080   DALI_TEST_EQUALS(Test::WaitForEventThreadTrigger(1), true, TEST_LOCATION);
1081
1082   application.SendNotification();
1083   application.Render(16);
1084
1085   DALI_TEST_EQUALS(Test::WaitForEventThreadTrigger(2), true, TEST_LOCATION);
1086
1087   application.SendNotification();
1088   application.Render();
1089
1090   DALI_TEST_EQUALS(imageView.IsResourceReady(), true, TEST_LOCATION);
1091
1092   DALI_TEST_EQUALS(gResourceReadySignalFired, true, TEST_LOCATION);
1093
1094   END_TEST;
1095 }
1096
1097 int UtcDaliImageViewSetImageTypeChangesP(void)
1098 {
1099   ToolkitTestApplication application;
1100
1101   ImageView                   imageView   = ImageView::New();
1102   Toolkit::Internal::Control& controlImpl = Toolkit::Internal::GetImplementation(imageView);
1103
1104   application.GetScene().Add(imageView);
1105
1106   std::string           url;
1107   Property::Map         map;
1108   Toolkit::Visual::Base visual;
1109
1110   Property::Value value = imageView.GetProperty(imageView.GetPropertyIndex("image"));
1111   visual                = DevelControl::GetVisual(controlImpl, ImageView::Property::IMAGE);
1112
1113   application.SendNotification();
1114   application.Render(16);
1115
1116   DALI_TEST_CHECK(!value.Get(url)); // Value should be empty
1117   value.Get(map);
1118   DALI_TEST_CHECK(map.Empty()); // Value should be empty
1119   DALI_TEST_CHECK(!visual);     // Visual should be invalid
1120
1121   // Set a URL
1122   imageView.SetImage("TEST_URL");
1123
1124   application.SendNotification();
1125   application.Render(16);
1126
1127   value  = imageView.GetProperty(imageView.GetPropertyIndex("image"));
1128   visual = DevelControl::GetVisual(controlImpl, ImageView::Property::IMAGE);
1129
1130   DALI_TEST_CHECK(value.Get(url));  // Value should NOT be empty
1131   DALI_TEST_CHECK(!value.Get(map)); // Value should be empty
1132   DALI_TEST_CHECK(visual);          // Visual should be valid
1133
1134   // Set an empty URL
1135   imageView.SetImage("");
1136
1137   application.SendNotification();
1138   application.Render(16);
1139
1140   value  = imageView.GetProperty(imageView.GetPropertyIndex("image"));
1141   visual = DevelControl::GetVisual(controlImpl, ImageView::Property::IMAGE);
1142
1143   DALI_TEST_CHECK(!value.Get(url)); // Value should be empty
1144   value.Get(map);
1145   DALI_TEST_CHECK(map.Empty()); // Value should be empty
1146   DALI_TEST_CHECK(!visual);     // Visual should be invalid
1147
1148   // Set a URL in property map
1149   Property::Map propertyMap;
1150   propertyMap[ImageVisual::Property::URL] = TEST_IMAGE_FILE_NAME;
1151   imageView.SetProperty(ImageView::Property::IMAGE, propertyMap);
1152
1153   application.SendNotification();
1154   application.Render(16);
1155
1156   value  = imageView.GetProperty(imageView.GetPropertyIndex("image"));
1157   visual = DevelControl::GetVisual(controlImpl, ImageView::Property::IMAGE);
1158
1159   DALI_TEST_CHECK(!value.Get(url)); // Value should be empty
1160   DALI_TEST_CHECK(value.Get(map));  // Value should NOT be empty
1161   DALI_TEST_CHECK(visual);          // Visual should be valid
1162
1163   // Set a URL in property map again
1164   propertyMap[ImageVisual::Property::URL] = gImage_34_RGBA;
1165   imageView.SetProperty(ImageView::Property::IMAGE, propertyMap);
1166
1167   application.SendNotification();
1168   application.Render(16);
1169
1170   value  = imageView.GetProperty(imageView.GetPropertyIndex("image"));
1171   visual = DevelControl::GetVisual(controlImpl, ImageView::Property::IMAGE);
1172
1173   DALI_TEST_CHECK(!value.Get(url)); // Value should be empty
1174   DALI_TEST_CHECK(value.Get(map));  // Value should NOT be empty
1175   DALI_TEST_CHECK(visual);          // Visual should be valid
1176
1177   // Set an empty URL in property map
1178   propertyMap[ImageVisual::Property::URL] = std::string();
1179   imageView.SetProperty(ImageView::Property::IMAGE, propertyMap);
1180
1181   application.SendNotification();
1182   application.Render(16);
1183
1184   value  = imageView.GetProperty(imageView.GetPropertyIndex("image"));
1185   visual = DevelControl::GetVisual(controlImpl, ImageView::Property::IMAGE);
1186
1187   DALI_TEST_CHECK(!value.Get(url)); // Value should be empty
1188   DALI_TEST_CHECK(value.Get(map));  // Value should NOT be empty
1189   DALI_TEST_CHECK(!visual);         // Visual should be invalid
1190
1191   // Set a URL in property map again
1192   propertyMap[ImageVisual::Property::URL] = gImage_34_RGBA;
1193   imageView.SetProperty(ImageView::Property::IMAGE, propertyMap);
1194
1195   application.SendNotification();
1196   application.Render(16);
1197
1198   value  = imageView.GetProperty(imageView.GetPropertyIndex("image"));
1199   visual = DevelControl::GetVisual(controlImpl, ImageView::Property::IMAGE);
1200
1201   DALI_TEST_CHECK(!value.Get(url)); // Value should be empty
1202   DALI_TEST_CHECK(value.Get(map));  // Value should NOT be empty
1203   DALI_TEST_CHECK(visual);          // Visual should be valid
1204
1205   // Set an empty property map
1206   propertyMap.Clear();
1207   imageView.SetProperty(ImageView::Property::IMAGE, propertyMap);
1208
1209   application.SendNotification();
1210   application.Render(16);
1211
1212   value  = imageView.GetProperty(imageView.GetPropertyIndex("image"));
1213   visual = DevelControl::GetVisual(controlImpl, ImageView::Property::IMAGE);
1214
1215   DALI_TEST_CHECK(!value.Get(url)); // Value should be empty
1216   DALI_TEST_CHECK(value.Get(map));  // Value should NOT be empty
1217   DALI_TEST_CHECK(map.Empty());     // But PropertyMap should be empty
1218   DALI_TEST_CHECK(!visual);         // Visual should be invalid
1219
1220   END_TEST;
1221 }
1222
1223 int UtcDaliImageViewResourceUrlP(void)
1224 {
1225   ToolkitTestApplication application;
1226
1227   ImageView imageView = ImageView::New();
1228   DALI_TEST_CHECK(imageView.GetProperty(ImageView::Property::IMAGE).Get<std::string>().empty());
1229
1230   imageView.SetProperty(ImageView::Property::IMAGE, "TestString");
1231   DALI_TEST_EQUALS(imageView.GetProperty(ImageView::Property::IMAGE).Get<std::string>(), "TestString", TEST_LOCATION);
1232
1233   END_TEST;
1234 }
1235
1236 int UtcDaliImageViewReplaceImage(void)
1237 {
1238   ToolkitTestApplication application;
1239
1240   gResourceReadySignalFired = false;
1241
1242   // Check ImageView with background and main image, to ensure both visuals are marked as loaded
1243   ImageView imageView = ImageView::New(TEST_IMAGE_1);
1244
1245   DALI_TEST_EQUALS(imageView.IsResourceReady(), false, TEST_LOCATION);
1246
1247   imageView.ResourceReadySignal().Connect(&ResourceReadySignal);
1248
1249   application.GetScene().Add(imageView);
1250
1251   application.SendNotification();
1252   application.Render(16);
1253
1254   // loading started, this waits for the loader thread for max 30 seconds
1255   DALI_TEST_EQUALS(Test::WaitForEventThreadTrigger(1), true, TEST_LOCATION);
1256
1257   DALI_TEST_EQUALS(imageView.GetRendererCount(), 1u, TEST_LOCATION);
1258
1259   DALI_TEST_EQUALS(gResourceReadySignalFired, true, TEST_LOCATION);
1260
1261   gResourceReadySignalFired = false;
1262
1263   imageView.SetImage(TEST_IMAGE_2);
1264
1265   application.SendNotification();
1266   application.Render(16);
1267
1268   // loading started, this waits for the loader thread for max 30 seconds
1269   DALI_TEST_EQUALS(Test::WaitForEventThreadTrigger(1), true, TEST_LOCATION);
1270
1271   DALI_TEST_EQUALS(imageView.GetRendererCount(), 1u, TEST_LOCATION);
1272
1273   DALI_TEST_EQUALS(imageView.IsResourceReady(), true, TEST_LOCATION);
1274
1275   DALI_TEST_EQUALS(gResourceReadySignalFired, true, TEST_LOCATION);
1276
1277   END_TEST;
1278 }
1279
1280 int UtcDaliImageViewReloadAlphaMaskImage(void)
1281 {
1282   ToolkitTestApplication application;
1283
1284   gResourceReadySignalFired = false;
1285
1286   ImageView     dummy     = ImageView::New();
1287   ImageView     imageView = ImageView::New();
1288   Property::Map propertyMap;
1289
1290   // To keep alpha mask cached, scene on some dummy image.
1291   // Note : If we don't cache alpha mask image, the reference count of mask image become zero.
1292   // In this case, we might need to wait mask image loading, which is not neccesary & can be changed behavior.
1293   propertyMap[ImageVisual::Property::URL]            = gImage_600_RGB;
1294   propertyMap[ImageVisual::Property::ALPHA_MASK_URL] = TEST_BROKEN_IMAGE_DEFAULT;
1295   dummy.SetProperty(ImageView::Property::IMAGE, propertyMap);
1296
1297   application.GetScene().Add(dummy);
1298
1299   application.SendNotification();
1300   application.Render(16);
1301
1302   DALI_TEST_EQUALS(Test::WaitForEventThreadTrigger(3), true, TEST_LOCATION);
1303
1304   application.SendNotification();
1305   application.Render(16);
1306
1307   propertyMap.Clear();
1308   propertyMap[ImageVisual::Property::URL]            = gImage_34_RGBA;
1309   propertyMap[ImageVisual::Property::ALPHA_MASK_URL] = TEST_BROKEN_IMAGE_DEFAULT;
1310   imageView.SetProperty(ImageView::Property::IMAGE, propertyMap);
1311
1312   DALI_TEST_EQUALS(imageView.IsResourceReady(), false, TEST_LOCATION);
1313
1314   imageView.ResourceReadySignal().Connect(&ResourceReadySignal);
1315
1316   application.GetScene().Add(imageView);
1317
1318   application.SendNotification();
1319   application.Render(16);
1320
1321   // Load image and use cached mask. Now we try to apply masking.
1322   DALI_TEST_EQUALS(Test::WaitForEventThreadTrigger(1), true, TEST_LOCATION);
1323
1324   DALI_TEST_EQUALS(gResourceReadySignalFired, false, TEST_LOCATION);
1325
1326   // Cancel apply masking.
1327   imageView.Unparent();
1328
1329   application.SendNotification();
1330   application.Render(16);
1331
1332   // Reload same image again.
1333   application.GetScene().Add(imageView);
1334
1335   application.SendNotification();
1336   application.Render(16);
1337
1338   // Finish apply masking.
1339   DALI_TEST_EQUALS(Test::WaitForEventThreadTrigger(1), true, TEST_LOCATION);
1340
1341   DALI_TEST_EQUALS(imageView.GetRendererCount(), 1u, TEST_LOCATION);
1342   DALI_TEST_EQUALS(imageView.IsResourceReady(), true, TEST_LOCATION);
1343   DALI_TEST_EQUALS(gResourceReadySignalFired, true, TEST_LOCATION);
1344
1345   END_TEST;
1346 }
1347
1348 void OnRelayoutOverride(Size size)
1349 {
1350   gNaturalSize = size; // Size Relayout is using
1351 }
1352
1353 int UtcDaliImageViewReplaceImageAndGetNaturalSize(void)
1354 {
1355   ToolkitTestApplication application;
1356
1357   // Check ImageView with background and main image, to ensure both visuals are marked as loaded
1358   ImageView imageView = ImageView::New(TEST_IMAGE_1);
1359   imageView.SetResizePolicy(ResizePolicy::USE_NATURAL_SIZE, Dimension::ALL_DIMENSIONS);
1360
1361   DummyControl        dummyControl = DummyControl::New(true);
1362   Impl::DummyControl& dummyImpl    = static_cast<Impl::DummyControl&>(dummyControl.GetImplementation());
1363   dummyControl.SetResizePolicy(ResizePolicy::FIT_TO_CHILDREN, Dimension::ALL_DIMENSIONS);
1364
1365   dummyControl.Add(imageView);
1366   dummyImpl.SetRelayoutCallback(&OnRelayoutOverride);
1367   application.GetScene().Add(dummyControl);
1368
1369   application.SendNotification();
1370   application.Render();
1371
1372   // loading started, this waits for the loader thread for max 30 seconds
1373   DALI_TEST_EQUALS(Test::WaitForEventThreadTrigger(1), true, TEST_LOCATION);
1374
1375   DALI_TEST_EQUALS(gNaturalSize.width, 1024.0f, TEST_LOCATION);
1376   DALI_TEST_EQUALS(gNaturalSize.height, 1024.0f, TEST_LOCATION);
1377
1378   gNaturalSize = Vector3::ZERO;
1379
1380   imageView.SetImage(gImage_600_RGB);
1381
1382   // Waiting for resourceReady so SendNotifcation not called here.
1383
1384   // loading started, this waits for the loader thread for max 30 seconds
1385   DALI_TEST_EQUALS(Test::WaitForEventThreadTrigger(1), true, TEST_LOCATION);
1386
1387   // Trigger a potential relayout
1388   application.SendNotification();
1389   application.Render();
1390
1391   DALI_TEST_EQUALS(gNaturalSize.width, 600.0f, TEST_LOCATION);
1392   DALI_TEST_EQUALS(gNaturalSize.height, 600.0f, TEST_LOCATION);
1393
1394   END_TEST;
1395 }
1396
1397 int UtcDaliImageViewResourceReadySignalWithImmediateLoad(void)
1398 {
1399   tet_infoline("Test Setting Image with IMMEDIATE load and receving ResourceReadySignal before staged.");
1400
1401   ToolkitTestApplication application;
1402
1403   gResourceReadySignalFired = false;
1404
1405   Property::Map imageMap;
1406
1407   imageMap[ImageVisual::Property::URL]         = gImage_34_RGBA;
1408   imageMap[ImageVisual::Property::LOAD_POLICY] = ImageVisual::LoadPolicy::IMMEDIATE;
1409
1410   tet_infoline("Creating ImageView without URL so image does not start loading");
1411   ImageView imageView = ImageView::New();
1412   tet_infoline("Connect to image loaded signal before setting image");
1413   imageView.ResourceReadySignal().Connect(&ResourceReadySignal);
1414   tet_infoline("Setting Image with IMMEDIATE load, signal already connected so will be triggered.");
1415   imageView.SetProperty(ImageView::Property::IMAGE, imageMap);
1416
1417   // loading started, this waits for the loader thread
1418   DALI_TEST_EQUALS(Test::WaitForEventThreadTrigger(1), true, TEST_LOCATION);
1419
1420   application.SendNotification();
1421   application.Render(16);
1422
1423   DALI_TEST_EQUALS(gResourceReadySignalFired, true, TEST_LOCATION);
1424
1425   END_TEST;
1426 }
1427
1428 int UtcDaliImageViewResourceReadySignalWithReusedImage(void)
1429 {
1430   tet_infoline("Test Setting Image that was already loaded by another ImageView and still getting ResourceReadySignal.");
1431
1432   ToolkitTestApplication application;
1433
1434   gResourceReadySignalFired = false;
1435
1436   Property::Map imageMap;
1437
1438   imageMap[ImageVisual::Property::URL]         = gImage_34_RGBA;
1439   imageMap[ImageVisual::Property::LOAD_POLICY] = ImageVisual::LoadPolicy::IMMEDIATE;
1440
1441   ImageView imageView = ImageView::New();
1442   imageView.ResourceReadySignal().Connect(&ResourceReadySignal);
1443   imageView.SetProperty(ImageView::Property::IMAGE, imageMap);
1444
1445   // loading started, this waits for the loader thread
1446   DALI_TEST_EQUALS(Test::WaitForEventThreadTrigger(1), true, TEST_LOCATION);
1447
1448   application.SendNotification();
1449   application.Render(16);
1450
1451   DALI_TEST_EQUALS(gResourceReadySignalFired, true, TEST_LOCATION);
1452   gResourceReadySignalFired = false;
1453
1454   ImageView imageViewWithExistingImage = ImageView::New();
1455   imageViewWithExistingImage.ResourceReadySignal().Connect(&ResourceReadySignal);
1456   imageViewWithExistingImage.SetProperty(ImageView::Property::IMAGE, imageMap);
1457
1458   DALI_TEST_EQUALS(gResourceReadySignalFired, true, TEST_LOCATION);
1459
1460   END_TEST;
1461 }
1462
1463 int UtcDaliImageViewResourceReadySignalWithReusedImage02(void)
1464 {
1465   tet_infoline("Test Setting Image that was already loaded by another ImageView and still getting ResourceReadySignal when staged.");
1466
1467   ToolkitTestApplication application;
1468
1469   gResourceReadySignalFired = false;
1470
1471   Property::Map imageImmediateLoadingMap;
1472   imageImmediateLoadingMap[ImageVisual::Property::URL]         = gImage_34_RGBA;
1473   imageImmediateLoadingMap[ImageVisual::Property::LOAD_POLICY] = ImageVisual::LoadPolicy::IMMEDIATE;
1474
1475   tet_infoline("Immediate load an image");
1476   ImageView imageView = ImageView::New();
1477   imageView.ResourceReadySignal().Connect(&ResourceReadySignal);
1478   imageView.SetProperty(ImageView::Property::IMAGE, imageImmediateLoadingMap);
1479
1480   // loading started, this waits for the loader thread
1481   DALI_TEST_EQUALS(Test::WaitForEventThreadTrigger(1), true, TEST_LOCATION);
1482
1483   application.SendNotification();
1484   application.Render(16);
1485
1486   tet_infoline("Check image loaded");
1487   DALI_TEST_EQUALS(gResourceReadySignalFired, true, TEST_LOCATION);
1488   gResourceReadySignalFired = false;
1489
1490   tet_infoline("Create another ImageView with the same URL");
1491   ImageView imageViewWithExistingImage = ImageView::New(gImage_34_RGBA);
1492   tet_infoline("Connect to ResourceReady signal for second ImageView, it should still fire as resource is ready");
1493   imageViewWithExistingImage.ResourceReadySignal().Connect(&ResourceReadySignal);
1494
1495   application.GetScene().Add(imageViewWithExistingImage);
1496
1497   DALI_TEST_EQUALS(gResourceReadySignalFired, true, TEST_LOCATION);
1498
1499   END_TEST;
1500 }
1501
1502 int UtcDaliImageViewPaddingProperty(void)
1503 {
1504   ToolkitTestApplication application;
1505
1506   ImageView     imageView = ImageView::New();
1507   Property::Map imagePropertyMap;
1508   imagePropertyMap[Toolkit::Visual::Property::TYPE]       = Toolkit::Visual::IMAGE;
1509   imagePropertyMap[Toolkit::ImageVisual::Property::URL]   = TEST_RESOURCE_DIR "/gallery-small-1.jpg";
1510   imagePropertyMap[ImageVisual::Property::DESIRED_WIDTH]  = 128;
1511   imagePropertyMap[ImageVisual::Property::DESIRED_HEIGHT] = 128;
1512   imageView.SetProperty(Toolkit::ImageView::Property::IMAGE, imagePropertyMap);
1513   imageView.SetProperty(Actor::Property::ANCHOR_POINT, AnchorPoint::TOP_LEFT);
1514   imageView.SetProperty(Actor::Property::PARENT_ORIGIN, ParentOrigin::TOP_LEFT);
1515   imageView.SetProperty(Control::Property::PADDING, Extents(15, 10, 5, 10));
1516   application.GetScene().Add(imageView);
1517
1518   application.SendNotification();
1519   application.Render();
1520
1521   DALI_TEST_EQUALS(imageView.GetProperty<Extents>(Control::Property::PADDING), Extents(15, 10, 5, 10), TEST_LOCATION);
1522
1523   ImageView childImage = ImageView::New();
1524   childImage.SetBackgroundColor(Color::BLACK);
1525   childImage.SetProperty(Actor::Property::SIZE, Vector2(10.f, 10.f));
1526   imageView.Add(childImage);
1527
1528   application.SendNotification();
1529   application.Render();
1530
1531   // Child ImageView should be positioned dependinig on Parent ImageView's Padding value
1532   DALI_TEST_EQUALS(childImage.GetProperty<Vector3>(Dali::Actor::Property::POSITION), Vector3(15, 5, 0), TEST_LOCATION);
1533
1534   // Check whether Image Visual transforms on ImageVieiw::OnRelayout()
1535   Toolkit::Internal::Control& controlImpl = Toolkit::Internal::GetImplementation(imageView);
1536   Toolkit::Visual::Base       imageVisual = DevelControl::GetVisual(controlImpl, ImageView::Property::IMAGE);
1537   Property::Map               resultMap;
1538   imageVisual.CreatePropertyMap(resultMap);
1539
1540   Property::Value* transformValue = resultMap.Find(Visual::Property::TRANSFORM);
1541   DALI_TEST_CHECK(transformValue);
1542   Property::Map* retMap = transformValue->GetMap();
1543   DALI_TEST_CHECK(retMap);
1544
1545   // Image Visual should be positioned depending on ImageView's padding
1546   DALI_TEST_EQUALS(retMap->Find(Visual::Transform::Property::OFFSET)->Get<Vector2>(), Vector2(15, 5), TEST_LOCATION);
1547
1548   END_TEST;
1549 }
1550
1551 int UtcDaliImageViewPaddingProperty02(void)
1552 {
1553   ToolkitTestApplication application;
1554
1555   ImageView     imageView = ImageView::New();
1556   Property::Map imagePropertyMap;
1557   imagePropertyMap[Toolkit::Visual::Property::TYPE]            = Toolkit::Visual::IMAGE;
1558   imagePropertyMap[Toolkit::ImageVisual::Property::URL]        = TEST_RESOURCE_DIR "/Kid1.svg";
1559   imagePropertyMap[ImageVisual::Property::DESIRED_WIDTH]       = 128;
1560   imagePropertyMap[ImageVisual::Property::DESIRED_HEIGHT]      = 128;
1561   imagePropertyMap[DevelVisual::Property::VISUAL_FITTING_MODE] = Toolkit::DevelVisual::FIT_KEEP_ASPECT_RATIO;
1562   imageView.SetProperty(Toolkit::ImageView::Property::IMAGE, imagePropertyMap);
1563   imageView.SetProperty(Actor::Property::ANCHOR_POINT, AnchorPoint::TOP_LEFT);
1564   imageView.SetProperty(Actor::Property::PARENT_ORIGIN, ParentOrigin::TOP_LEFT);
1565   imageView.SetProperty(Control::Property::PADDING, Extents(15, 10, 5, 10));
1566   application.GetScene().Add(imageView);
1567
1568   application.SendNotification();
1569   application.Render();
1570
1571   DALI_TEST_EQUALS(imageView.GetProperty<Extents>(Control::Property::PADDING), Extents(15, 10, 5, 10), TEST_LOCATION);
1572
1573   // Check whether Image Visual transforms on ImageVieiw::OnRelayout()
1574   Toolkit::Internal::Control& controlImpl = Toolkit::Internal::GetImplementation(imageView);
1575   Toolkit::Visual::Base       imageVisual = DevelControl::GetVisual(controlImpl, ImageView::Property::IMAGE);
1576   Property::Map               resultMap;
1577   imageVisual.CreatePropertyMap(resultMap);
1578
1579   Property::Value* transformValue = resultMap.Find(Visual::Property::TRANSFORM);
1580   DALI_TEST_CHECK(transformValue);
1581   Property::Map* retMap = transformValue->GetMap();
1582   DALI_TEST_CHECK(retMap);
1583
1584   // Image Visual should be positioned depending on ImageView's padding
1585   DALI_TEST_EQUALS(retMap->Find(Visual::Transform::Property::OFFSET)->Get<Vector2>(), Vector2(15, 5), TEST_LOCATION);
1586
1587   END_TEST;
1588 }
1589
1590 int UtcDaliImageViewPaddingProperty03(void)
1591 {
1592   tet_infoline("Test Setting Image Padding then removing it.");
1593
1594   ToolkitTestApplication application;
1595
1596   ImageView     imageView = ImageView::New();
1597   Property::Map imagePropertyMap;
1598   imagePropertyMap[Toolkit::Visual::Property::TYPE]            = Toolkit::Visual::IMAGE;
1599   imagePropertyMap[Toolkit::ImageVisual::Property::URL]        = TEST_RESOURCE_DIR "/Kid1.svg";
1600   imagePropertyMap[ImageVisual::Property::DESIRED_WIDTH]       = 128;
1601   imagePropertyMap[ImageVisual::Property::DESIRED_HEIGHT]      = 128;
1602   imagePropertyMap[DevelVisual::Property::VISUAL_FITTING_MODE] = Toolkit::DevelVisual::FIT_KEEP_ASPECT_RATIO;
1603   imageView.SetProperty(Toolkit::ImageView::Property::IMAGE, imagePropertyMap);
1604   imageView.SetProperty(Actor::Property::ANCHOR_POINT, AnchorPoint::TOP_LEFT);
1605   imageView.SetProperty(Actor::Property::PARENT_ORIGIN, ParentOrigin::TOP_LEFT);
1606   imageView.SetProperty(Control::Property::PADDING, Extents(15, 10, 5, 10));
1607   application.GetScene().Add(imageView);
1608
1609   application.SendNotification();
1610   application.Render();
1611
1612   DALI_TEST_EQUALS(imageView.GetProperty<Extents>(Control::Property::PADDING), Extents(15, 10, 5, 10), TEST_LOCATION);
1613
1614   tet_infoline("Remove Padding and test Visual is position correctly");
1615
1616   imageView.SetProperty(Control::Property::PADDING, Extents(0, 0, 0, 0));
1617
1618   application.SendNotification();
1619   application.Render();
1620
1621   // Check whether Image Visual transforms on ImageVieiw::OnRelayout()
1622   Toolkit::Internal::Control& controlImpl = Toolkit::Internal::GetImplementation(imageView);
1623   Toolkit::Visual::Base       imageVisual = DevelControl::GetVisual(controlImpl, ImageView::Property::IMAGE);
1624   Property::Map               resultMap;
1625   imageVisual.CreatePropertyMap(resultMap);
1626
1627   Property::Value* transformValue = resultMap.Find(Visual::Property::TRANSFORM);
1628   DALI_TEST_CHECK(transformValue);
1629   Property::Map* retMap = transformValue->GetMap();
1630   DALI_TEST_CHECK(retMap);
1631
1632   // Image Visual should be positioned depending on ImageView's padding
1633   DALI_TEST_EQUALS(retMap->Find(Visual::Transform::Property::OFFSET)->Get<Vector2>(), Vector2(0, 0), TEST_LOCATION);
1634
1635   END_TEST;
1636 }
1637
1638 int UtcDaliImageViewPaddingProperty04(void)
1639 {
1640   tet_infoline("Test Setting Image Padding then removing it. Visual Fitting Mode as Fill");
1641
1642   ToolkitTestApplication application;
1643
1644   ImageView     imageView = ImageView::New();
1645   Property::Map imagePropertyMap;
1646   imagePropertyMap[Toolkit::Visual::Property::TYPE]            = Toolkit::Visual::IMAGE;
1647   imagePropertyMap[Toolkit::ImageVisual::Property::URL]        = TEST_RESOURCE_DIR "/Kid1.svg";
1648   imagePropertyMap[ImageVisual::Property::DESIRED_WIDTH]       = 128;
1649   imagePropertyMap[ImageVisual::Property::DESIRED_HEIGHT]      = 128;
1650   imagePropertyMap[DevelVisual::Property::VISUAL_FITTING_MODE] = Toolkit::DevelVisual::FILL;
1651   imageView.SetProperty(Toolkit::ImageView::Property::IMAGE, imagePropertyMap);
1652   imageView.SetProperty(Actor::Property::ANCHOR_POINT, AnchorPoint::TOP_LEFT);
1653   imageView.SetProperty(Actor::Property::PARENT_ORIGIN, ParentOrigin::TOP_LEFT);
1654   imageView.SetProperty(Control::Property::PADDING, Extents(15, 10, 5, 10));
1655   application.GetScene().Add(imageView);
1656
1657   application.SendNotification();
1658   application.Render();
1659
1660   DALI_TEST_EQUALS(imageView.GetProperty<Extents>(Control::Property::PADDING), Extents(15, 10, 5, 10), TEST_LOCATION);
1661
1662   tet_infoline("Remove Padding and test Visual is position correctly");
1663
1664   imageView.SetProperty(Control::Property::PADDING, Extents(0, 0, 0, 0));
1665
1666   application.SendNotification();
1667   application.Render();
1668
1669   // Check whether Image Visual transforms on ImageVieiw::OnRelayout()
1670   Toolkit::Internal::Control& controlImpl = Toolkit::Internal::GetImplementation(imageView);
1671   Toolkit::Visual::Base       imageVisual = DevelControl::GetVisual(controlImpl, ImageView::Property::IMAGE);
1672   Property::Map               resultMap;
1673   imageVisual.CreatePropertyMap(resultMap);
1674
1675   Property::Value* transformValue = resultMap.Find(Visual::Property::TRANSFORM);
1676   DALI_TEST_CHECK(transformValue);
1677   Property::Map* retMap = transformValue->GetMap();
1678   DALI_TEST_CHECK(retMap);
1679
1680   // Image Visual should be positioned depending on ImageView's padding
1681   DALI_TEST_EQUALS(retMap->Find(Visual::Transform::Property::OFFSET)->Get<Vector2>(), Vector2(0, 0), TEST_LOCATION);
1682
1683   END_TEST;
1684 }
1685
1686 int UtcDaliImageViewTransformTest01(void)
1687 {
1688   tet_infoline("Test Setting a offset transform on the ImageView");
1689
1690   ToolkitTestApplication application;
1691
1692   ImageView     imageView = ImageView::New();
1693   Property::Map imagePropertyMap;
1694   imagePropertyMap.Add(Toolkit::Visual::Property::TYPE, Toolkit::Visual::IMAGE)
1695     .Add(Toolkit::ImageVisual::Property::URL, TEST_RESOURCE_DIR "/Kid1.svg")
1696     .Add(ImageVisual::Property::DESIRED_WIDTH, 120)
1697     .Add(ImageVisual::Property::DESIRED_HEIGHT, 120)
1698     .Add(DevelVisual::Property::VISUAL_FITTING_MODE, Toolkit::DevelVisual::FILL)
1699     .Add(Visual::Property::TRANSFORM,
1700          Property::Map().Add(Toolkit::Visual::Transform::Property::OFFSET_POLICY,
1701                              Vector2(Visual::Transform::Policy::ABSOLUTE, Visual::Transform::Policy::ABSOLUTE))
1702            .Add(Toolkit::Visual::Transform::Property::OFFSET, Vector2(8, 8)));
1703
1704   imageView.SetProperty(Toolkit::ImageView::Property::IMAGE, imagePropertyMap);
1705   imageView.SetProperty(Actor::Property::ANCHOR_POINT, AnchorPoint::TOP_LEFT);
1706   imageView.SetProperty(Actor::Property::PARENT_ORIGIN, ParentOrigin::TOP_LEFT);
1707   application.GetScene().Add(imageView);
1708
1709   application.SendNotification();
1710   application.Render();
1711
1712   // Check whether Image Visual transforms on ImageVieiw::OnRelayout()
1713   Toolkit::Internal::Control& controlImpl = Toolkit::Internal::GetImplementation(imageView);
1714   Toolkit::Visual::Base       imageVisual = DevelControl::GetVisual(controlImpl, ImageView::Property::IMAGE);
1715   Property::Map               resultMap;
1716   imageVisual.CreatePropertyMap(resultMap);
1717
1718   Property::Value* transformValue = resultMap.Find(Visual::Property::TRANSFORM);
1719   DALI_TEST_CHECK(transformValue);
1720   Property::Map* retMap = transformValue->GetMap();
1721   DALI_TEST_CHECK(retMap);
1722
1723   // Image Visual should be positioned depending on ImageView's padding
1724   DALI_TEST_EQUALS(retMap->Find(Visual::Transform::Property::OFFSET)->Get<Vector2>(), Vector2(8, 8), TEST_LOCATION);
1725   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);
1726
1727   END_TEST;
1728 }
1729
1730 int UtcDaliImageViewUsingAtlasAndGetNaturalSize(void)
1731 {
1732   ToolkitTestApplication application;
1733
1734   // Check ImageView with background and main image, to ensure both visuals are marked as loaded
1735   ImageView     imageView = ImageView::New();
1736   Property::Map imageMap;
1737   imageMap[Toolkit::Visual::Property::TYPE]          = Toolkit::Visual::IMAGE;
1738   imageMap[Toolkit::ImageVisual::Property::URL]      = gImage_34_RGBA;
1739   imageMap[Toolkit::ImageVisual::Property::ATLASING] = true;
1740   imageView.SetProperty(Toolkit::ImageView::Property::IMAGE, imageMap);
1741   application.GetScene().Add(imageView);
1742
1743   // Trigger a potential relayout
1744   application.SendNotification();
1745   application.Render();
1746
1747   Vector3 naturalSize = imageView.GetNaturalSize();
1748
1749   DALI_TEST_EQUALS(naturalSize.width, 34.0f, TEST_LOCATION);
1750   DALI_TEST_EQUALS(naturalSize.height, 34.0f, TEST_LOCATION);
1751
1752   END_TEST;
1753 }
1754
1755 int UtcDaliImageViewFillMode(void)
1756 {
1757   ToolkitTestApplication application;
1758
1759   tet_infoline("Create an ImageVisual without padding and set the fill-mode to fill");
1760
1761   ImageView     imageView = ImageView::New();
1762   Property::Map imageMap;
1763   imageMap.Add(Toolkit::Visual::Property::TYPE, Toolkit::Visual::IMAGE);
1764   imageMap.Add(Toolkit::ImageVisual::Property::URL, gImage_600_RGB);
1765   imageMap.Add(DevelVisual::Property::VISUAL_FITTING_MODE, DevelVisual::FittingMode::FILL);
1766
1767   imageView.SetProperty(Toolkit::ImageView::Property::IMAGE, imageMap);
1768
1769   application.GetScene().Add(imageView);
1770
1771   // Trigger a potential relayout
1772   application.SendNotification();
1773   application.Render();
1774
1775   Toolkit::Visual::Base visual = DevelControl::GetVisual(Toolkit::Internal::GetImplementation(imageView), Toolkit::ImageView::Property::IMAGE);
1776   Property::Map         returnedMap;
1777   visual.CreatePropertyMap(returnedMap);
1778
1779   Property::Value* value = returnedMap.Find(Toolkit::Visual::Property::TRANSFORM);
1780   DALI_TEST_CHECK(value);
1781   Property::Map* map = value->GetMap();
1782   DALI_TEST_CHECK(map);
1783
1784   value = map->Find(Toolkit::Visual::Transform::Property::SIZE);
1785   DALI_TEST_CHECK(value);
1786   DALI_TEST_EQUALS(value->Get<Vector2>(), Vector2::ONE, TEST_LOCATION);
1787
1788   value = map->Find(Toolkit::Visual::Transform::Property::SIZE_POLICY);
1789   DALI_TEST_CHECK(value);
1790   DALI_TEST_CHECK(value->Get<int>() == Toolkit::Visual::Transform::Policy::RELATIVE);
1791
1792   END_TEST;
1793 }
1794
1795 int UtcDaliImageViewFittingModeFitKeepAspectRatio(void)
1796 {
1797   ToolkitTestApplication application;
1798
1799   tet_infoline("Create an ImageVisual using FitKeepAspectRatio ( image: [600,600], view: [600,700] )");
1800   tet_infoline("  There should be need to change the transform, offset is adjusted to fit inside");
1801
1802   ImageView     imageView = ImageView::New();
1803   Property::Map imageMap;
1804   imageMap.Add(Toolkit::Visual::Property::TYPE, Toolkit::Visual::IMAGE);
1805   imageMap.Add(Toolkit::ImageVisual::Property::URL, gImage_600_RGB); // 600x600 image
1806   imageMap.Add(DevelVisual::Property::VISUAL_FITTING_MODE, Toolkit::DevelVisual::FIT_KEEP_ASPECT_RATIO);
1807
1808   imageView.SetProperty(Toolkit::ImageView::Property::IMAGE, imageMap);
1809   imageView.SetProperty(Actor::Property::SIZE, Vector2(600, 700));
1810
1811   application.GetScene().Add(imageView);
1812
1813   // Trigger a potential relayout
1814   application.SendNotification();
1815   application.Render();
1816
1817   Toolkit::Visual::Base visual = DevelControl::GetVisual(Toolkit::Internal::GetImplementation(imageView), Toolkit::ImageView::Property::IMAGE);
1818   Property::Map         returnedMap;
1819   visual.CreatePropertyMap(returnedMap);
1820
1821   Property::Value* value = returnedMap.Find(Toolkit::Visual::Property::TRANSFORM);
1822   DALI_TEST_CHECK(value);
1823   Property::Map* map = value->GetMap();
1824   DALI_TEST_CHECK(map);
1825
1826   // If there's
1827   value = map->Find(Toolkit::Visual::Transform::Property::SIZE);
1828   DALI_TEST_CHECK(value);
1829   DALI_TEST_EQUALS(value->Get<Vector2>(), Vector2(600, 600), TEST_LOCATION);
1830
1831   value = map->Find(Toolkit::Visual::Transform::Property::SIZE_POLICY);
1832   DALI_TEST_CHECK(value);
1833   DALI_TEST_EQUALS(value->Get<Vector2>(), Vector2(Toolkit::Visual::Transform::Policy::ABSOLUTE, Toolkit::Visual::Transform::Policy::ABSOLUTE), TEST_LOCATION);
1834
1835   value = map->Find(Toolkit::Visual::Transform::Property::OFFSET);
1836   DALI_TEST_CHECK(value);
1837   DALI_TEST_EQUALS(value->Get<Vector2>(), Vector2(0, 50), TEST_LOCATION);
1838
1839   END_TEST;
1840 }
1841
1842 int UtcDaliImageViewFittingModesFill(void)
1843 {
1844   ToolkitTestApplication application;
1845
1846   tet_infoline("Create an ImageVisual using Fill ( image: [600,600], view: [600,700] )");
1847   tet_infoline("  There should be no need to change the transform, only size is changed to fit view");
1848
1849   ImageView     imageView = ImageView::New();
1850   Property::Map imageMap;
1851   imageMap.Add(Toolkit::Visual::Property::TYPE, Toolkit::Visual::IMAGE);
1852   imageMap.Add(Toolkit::ImageVisual::Property::URL, gImage_600_RGB); // 600x600 image
1853   imageMap.Add(DevelVisual::Property::VISUAL_FITTING_MODE, Toolkit::DevelVisual::FILL);
1854
1855   imageView.SetProperty(Toolkit::ImageView::Property::IMAGE, imageMap);
1856   imageView.SetProperty(Actor::Property::SIZE, Vector2(600, 700));
1857
1858   application.GetScene().Add(imageView);
1859
1860   // Trigger a potential relayout
1861   application.SendNotification();
1862   application.Render();
1863
1864   Toolkit::Visual::Base visual = DevelControl::GetVisual(Toolkit::Internal::GetImplementation(imageView), Toolkit::ImageView::Property::IMAGE);
1865   Property::Map         returnedMap;
1866   visual.CreatePropertyMap(returnedMap);
1867
1868   Property::Value* value = returnedMap.Find(Toolkit::Visual::Property::TRANSFORM);
1869   DALI_TEST_CHECK(value);
1870   Property::Map* map = value->GetMap();
1871   DALI_TEST_CHECK(map);
1872
1873   value = map->Find(Toolkit::Visual::Transform::Property::SIZE);
1874   DALI_TEST_CHECK(value);
1875   DALI_TEST_EQUALS(value->Get<Vector2>(), Vector2::ONE, TEST_LOCATION); // Change the internal size according to the image view size
1876
1877   value = map->Find(Toolkit::Visual::Transform::Property::SIZE_POLICY);
1878   DALI_TEST_CHECK(value);
1879   DALI_TEST_CHECK(value->Get<int>() == Toolkit::Visual::Transform::Policy::RELATIVE);
1880
1881   value = map->Find(Toolkit::Visual::Transform::Property::OFFSET);
1882   DALI_TEST_CHECK(value);
1883   DALI_TEST_EQUALS(value->Get<Vector2>(), Vector2(0, 0), TEST_LOCATION); // OFFSET is zero
1884
1885   END_TEST;
1886 }
1887
1888 int UtcDaliImageViewFittingModesOverfitKeepAspectRatio(void)
1889 {
1890   ToolkitTestApplication application;
1891
1892   tet_infoline("Create an ImageVisual using OverFitKeepAspectRatio ( image: [600,600], view: [600,500] )");
1893   tet_infoline("  offset or size is the same as view, but adjust internally using pixelArea ");
1894
1895   ImageView     imageView = ImageView::New();
1896   Property::Map imageMap;
1897   imageMap.Add(Toolkit::Visual::Property::TYPE, Toolkit::Visual::IMAGE);
1898   imageMap.Add(Toolkit::ImageVisual::Property::URL, gImage_600_RGB); // 600x600 image
1899   imageMap.Add(DevelVisual::Property::VISUAL_FITTING_MODE, Toolkit::DevelVisual::OVER_FIT_KEEP_ASPECT_RATIO);
1900
1901   imageView.SetProperty(Toolkit::ImageView::Property::IMAGE, imageMap);
1902   imageView.SetProperty(Actor::Property::SIZE, Vector2(600, 500));
1903
1904   application.GetScene().Add(imageView);
1905
1906   // Trigger a potential relayout
1907   application.SendNotification();
1908   application.Render();
1909
1910   Toolkit::Visual::Base visual = DevelControl::GetVisual(Toolkit::Internal::GetImplementation(imageView), Toolkit::ImageView::Property::IMAGE);
1911   Property::Map         returnedMap;
1912   visual.CreatePropertyMap(returnedMap);
1913
1914   Property::Value* value = returnedMap.Find(Toolkit::Visual::Property::TRANSFORM);
1915   DALI_TEST_CHECK(value);
1916   Property::Map* map = value->GetMap();
1917   DALI_TEST_CHECK(map);
1918
1919   // If there's
1920   value = map->Find(Toolkit::Visual::Transform::Property::SIZE);
1921   DALI_TEST_CHECK(value);
1922   DALI_TEST_EQUALS(value->Get<Vector2>(), Vector2(600, 500), TEST_LOCATION); // Change the internal size according to the image view size
1923
1924   value = map->Find(Toolkit::Visual::Transform::Property::SIZE_POLICY);
1925   DALI_TEST_CHECK(value);
1926   DALI_TEST_EQUALS(value->Get<Vector2>(), Vector2(Toolkit::Visual::Transform::Policy::ABSOLUTE, Toolkit::Visual::Transform::Policy::ABSOLUTE), TEST_LOCATION);
1927
1928   value = map->Find(Toolkit::Visual::Transform::Property::OFFSET);
1929   DALI_TEST_CHECK(value);
1930   DALI_TEST_EQUALS(value->Get<Vector2>(), Vector2(0, 0), TEST_LOCATION); // OFFSET is zero
1931
1932   END_TEST;
1933 }
1934
1935 int UtcDaliImageViewFittingModesCenter01(void)
1936 {
1937   ToolkitTestApplication application;
1938
1939   tet_infoline("Create an ImageVisual using Center ( image: [600,600], view: [700,700] )");
1940   tet_infoline("  There should be need to change the transform, offset is adjusted to fit inside");
1941
1942   ImageView     imageView = ImageView::New();
1943   Property::Map imageMap;
1944   imageMap.Add(Toolkit::Visual::Property::TYPE, Toolkit::Visual::IMAGE);
1945   imageMap.Add(Toolkit::ImageVisual::Property::URL, gImage_600_RGB); // 600x600 image
1946   imageMap.Add(DevelVisual::Property::VISUAL_FITTING_MODE, Toolkit::DevelVisual::CENTER);
1947
1948   imageView.SetProperty(Toolkit::ImageView::Property::IMAGE, imageMap);
1949   imageView.SetProperty(Actor::Property::SIZE, Vector2(700, 700));
1950
1951   application.GetScene().Add(imageView);
1952
1953   // Trigger a potential relayout
1954   application.SendNotification();
1955   application.Render();
1956
1957   Toolkit::Visual::Base visual = DevelControl::GetVisual(Toolkit::Internal::GetImplementation(imageView), Toolkit::ImageView::Property::IMAGE);
1958   Property::Map         returnedMap;
1959   visual.CreatePropertyMap(returnedMap);
1960
1961   Property::Value* value = returnedMap.Find(Toolkit::Visual::Property::TRANSFORM);
1962   DALI_TEST_CHECK(value);
1963   Property::Map* map = value->GetMap();
1964   DALI_TEST_CHECK(map);
1965
1966   value = map->Find(Toolkit::Visual::Transform::Property::SIZE);
1967   DALI_TEST_CHECK(value);
1968   DALI_TEST_EQUALS(value->Get<Vector2>(), Vector2(600, 600), TEST_LOCATION); // Change the internal size according to the image view size
1969
1970   value = map->Find(Toolkit::Visual::Transform::Property::SIZE_POLICY);
1971   DALI_TEST_CHECK(value);
1972   DALI_TEST_EQUALS(value->Get<Vector2>(), Vector2(Toolkit::Visual::Transform::Policy::ABSOLUTE, Toolkit::Visual::Transform::Policy::ABSOLUTE), TEST_LOCATION);
1973
1974   value = map->Find(Toolkit::Visual::Transform::Property::OFFSET);
1975   DALI_TEST_CHECK(value);
1976   DALI_TEST_EQUALS(value->Get<Vector2>(), Vector2(50, 50), TEST_LOCATION);
1977
1978   END_TEST;
1979 }
1980
1981 int UtcDaliImageViewFittingModesCenter02(void)
1982 {
1983   ToolkitTestApplication application;
1984
1985   tet_infoline("Create an ImageVisual using Center ( image: [600,600], view: [500,500] )");
1986   tet_infoline("  There should be need to change the transform, offset is adjusted to fit inside");
1987
1988   ImageView     imageView = ImageView::New();
1989   Property::Map imageMap;
1990   imageMap.Add(Toolkit::Visual::Property::TYPE, Toolkit::Visual::IMAGE);
1991   imageMap.Add(Toolkit::ImageVisual::Property::URL, gImage_600_RGB); // 600x600 image
1992   imageMap.Add(DevelVisual::Property::VISUAL_FITTING_MODE, Toolkit::DevelVisual::CENTER);
1993
1994   imageView.SetProperty(Toolkit::ImageView::Property::IMAGE, imageMap);
1995   imageView.SetProperty(Actor::Property::SIZE, Vector2(700, 700));
1996
1997   application.GetScene().Add(imageView);
1998
1999   // Trigger a potential relayout
2000   application.SendNotification();
2001   application.Render();
2002
2003   Toolkit::Visual::Base visual = DevelControl::GetVisual(Toolkit::Internal::GetImplementation(imageView), Toolkit::ImageView::Property::IMAGE);
2004   Property::Map         returnedMap;
2005   visual.CreatePropertyMap(returnedMap);
2006
2007   Property::Value* value = returnedMap.Find(Toolkit::Visual::Property::TRANSFORM);
2008   DALI_TEST_CHECK(value);
2009   Property::Map* map = value->GetMap();
2010   DALI_TEST_CHECK(map);
2011
2012   value = map->Find(Toolkit::Visual::Transform::Property::SIZE);
2013   DALI_TEST_CHECK(value);
2014   DALI_TEST_EQUALS(value->Get<Vector2>(), Vector2(600, 600), TEST_LOCATION); // Change the internal size according to the image view size
2015
2016   value = map->Find(Toolkit::Visual::Transform::Property::SIZE_POLICY);
2017   DALI_TEST_CHECK(value);
2018   DALI_TEST_EQUALS(value->Get<Vector2>(), Vector2(Toolkit::Visual::Transform::Policy::ABSOLUTE, Toolkit::Visual::Transform::Policy::ABSOLUTE), TEST_LOCATION);
2019
2020   value = map->Find(Toolkit::Visual::Transform::Property::OFFSET);
2021   DALI_TEST_CHECK(value);
2022   DALI_TEST_EQUALS(value->Get<Vector2>(), Vector2(50, 50), TEST_LOCATION);
2023
2024   END_TEST;
2025 }
2026
2027 int UtcDaliImageViewFittingModesFitHeight01(void)
2028 {
2029   ToolkitTestApplication application;
2030
2031   tet_infoline("Create an ImageVisual using FitHeight ( image: [600,600], view: [600,700] )");
2032
2033   ImageView     imageView = ImageView::New();
2034   Property::Map imageMap;
2035   imageMap.Add(Toolkit::Visual::Property::TYPE, Toolkit::Visual::IMAGE);
2036   imageMap.Add(Toolkit::ImageVisual::Property::URL, gImage_600_RGB); // 600x600 image
2037   imageMap.Add(DevelVisual::Property::VISUAL_FITTING_MODE, Toolkit::DevelVisual::FIT_HEIGHT);
2038
2039   imageView.SetProperty(Toolkit::ImageView::Property::IMAGE, imageMap);
2040   imageView.SetProperty(Actor::Property::SIZE, Vector2(600, 700));
2041
2042   application.GetScene().Add(imageView);
2043
2044   // Trigger a potential relayout
2045   application.SendNotification();
2046   application.Render();
2047
2048   Toolkit::Visual::Base visual = DevelControl::GetVisual(Toolkit::Internal::GetImplementation(imageView), Toolkit::ImageView::Property::IMAGE);
2049   Property::Map         returnedMap;
2050   visual.CreatePropertyMap(returnedMap);
2051
2052   Property::Value* value = returnedMap.Find(Toolkit::Visual::Property::TRANSFORM);
2053   DALI_TEST_CHECK(value);
2054   Property::Map* map = value->GetMap();
2055   DALI_TEST_CHECK(map);
2056
2057   value = map->Find(Toolkit::Visual::Transform::Property::SIZE);
2058   DALI_TEST_CHECK(value);
2059   DALI_TEST_EQUALS(value->Get<Vector2>(), Vector2(600, 700), TEST_LOCATION); // Change the internal size according to the image view size
2060
2061   value = map->Find(Toolkit::Visual::Transform::Property::SIZE_POLICY);
2062   DALI_TEST_CHECK(value);
2063   DALI_TEST_EQUALS(value->Get<Vector2>(), Vector2(Toolkit::Visual::Transform::Policy::ABSOLUTE, Toolkit::Visual::Transform::Policy::ABSOLUTE), TEST_LOCATION);
2064
2065   value = map->Find(Toolkit::Visual::Transform::Property::OFFSET);
2066   DALI_TEST_CHECK(value);
2067   DALI_TEST_EQUALS(value->Get<Vector2>(), Vector2(0, 0), TEST_LOCATION); // OFFSET is zero
2068
2069   END_TEST;
2070 }
2071
2072 int UtcDaliImageViewFittingModesFitHeight02(void)
2073 {
2074   ToolkitTestApplication application;
2075
2076   tet_infoline("Create an ImageVisual using FitHeight ( image: [600,600], view: [700,600] )");
2077
2078   ImageView     imageView = ImageView::New();
2079   Property::Map imageMap;
2080   imageMap.Add(Toolkit::Visual::Property::TYPE, Toolkit::Visual::IMAGE);
2081   imageMap.Add(Toolkit::ImageVisual::Property::URL, gImage_600_RGB); // 249x169 image
2082   imageMap.Add(DevelVisual::Property::VISUAL_FITTING_MODE, Toolkit::DevelVisual::FIT_HEIGHT);
2083
2084   imageView.SetProperty(Toolkit::ImageView::Property::IMAGE, imageMap);
2085   imageView.SetProperty(Actor::Property::SIZE, Vector2(700, 600));
2086
2087   application.GetScene().Add(imageView);
2088
2089   // Trigger a potential relayout
2090   application.SendNotification();
2091   application.Render();
2092
2093   Toolkit::Visual::Base visual = DevelControl::GetVisual(Toolkit::Internal::GetImplementation(imageView), Toolkit::ImageView::Property::IMAGE);
2094   Property::Map         returnedMap;
2095   visual.CreatePropertyMap(returnedMap);
2096
2097   Property::Value* value = returnedMap.Find(Toolkit::Visual::Property::TRANSFORM);
2098   DALI_TEST_CHECK(value);
2099   Property::Map* map = value->GetMap();
2100   DALI_TEST_CHECK(map);
2101
2102   value = map->Find(Toolkit::Visual::Transform::Property::SIZE);
2103   DALI_TEST_CHECK(value);
2104   DALI_TEST_EQUALS(value->Get<Vector2>(), Vector2(600, 600), TEST_LOCATION); // Change the internal size according to the image view size
2105
2106   value = map->Find(Toolkit::Visual::Transform::Property::SIZE_POLICY);
2107   DALI_TEST_CHECK(value);
2108   DALI_TEST_EQUALS(value->Get<Vector2>(), Vector2(Toolkit::Visual::Transform::Policy::ABSOLUTE, Toolkit::Visual::Transform::Policy::ABSOLUTE), TEST_LOCATION);
2109
2110   value = map->Find(Toolkit::Visual::Transform::Property::OFFSET);
2111   DALI_TEST_CHECK(value);
2112   DALI_TEST_EQUALS(value->Get<Vector2>(), Vector2(50, 0), TEST_LOCATION);
2113
2114   END_TEST;
2115 }
2116
2117 int UtcDaliImageViewFittingModesFitWidth01(void)
2118 {
2119   ToolkitTestApplication application;
2120
2121   tet_infoline("Create an ImageVisual using FitWidth ( image: [600,600], view: [600,700] )");
2122
2123   ImageView     imageView = ImageView::New();
2124   Property::Map imageMap;
2125   imageMap.Add(Toolkit::Visual::Property::TYPE, Toolkit::Visual::IMAGE);
2126   imageMap.Add(Toolkit::ImageVisual::Property::URL, gImage_600_RGB); // 600x600 image
2127   imageMap.Add(DevelVisual::Property::VISUAL_FITTING_MODE, Toolkit::DevelVisual::FIT_WIDTH);
2128
2129   imageView.SetProperty(Toolkit::ImageView::Property::IMAGE, imageMap);
2130   imageView.SetProperty(Actor::Property::SIZE, Vector2(600, 700));
2131
2132   application.GetScene().Add(imageView);
2133
2134   // Trigger a potential relayout
2135   application.SendNotification();
2136   application.Render();
2137
2138   Toolkit::Visual::Base visual = DevelControl::GetVisual(Toolkit::Internal::GetImplementation(imageView), Toolkit::ImageView::Property::IMAGE);
2139   Property::Map         returnedMap;
2140   visual.CreatePropertyMap(returnedMap);
2141
2142   Property::Value* value = returnedMap.Find(Toolkit::Visual::Property::TRANSFORM);
2143   DALI_TEST_CHECK(value);
2144   Property::Map* map = value->GetMap();
2145   DALI_TEST_CHECK(map);
2146
2147   value = map->Find(Toolkit::Visual::Transform::Property::SIZE);
2148   DALI_TEST_CHECK(value);
2149   DALI_TEST_EQUALS(value->Get<Vector2>(), Vector2(600, 600), TEST_LOCATION); // Change the internal size according to the image view size
2150
2151   value = map->Find(Toolkit::Visual::Transform::Property::SIZE_POLICY);
2152   DALI_TEST_CHECK(value);
2153   DALI_TEST_EQUALS(value->Get<Vector2>(), Vector2(Toolkit::Visual::Transform::Policy::ABSOLUTE, Toolkit::Visual::Transform::Policy::ABSOLUTE), TEST_LOCATION);
2154
2155   value = map->Find(Toolkit::Visual::Transform::Property::OFFSET);
2156   DALI_TEST_CHECK(value);
2157   DALI_TEST_EQUALS(value->Get<Vector2>(), Vector2(0, 50), TEST_LOCATION);
2158
2159   END_TEST;
2160 }
2161
2162 int UtcDaliImageViewFittingModesFitWidth02(void)
2163 {
2164   ToolkitTestApplication application;
2165
2166   tet_infoline("Create an ImageVisual using FitWidth ( image: [600,600], view:[700,600] )");
2167
2168   ImageView     imageView = ImageView::New();
2169   Property::Map imageMap;
2170   imageMap.Add(Toolkit::Visual::Property::TYPE, Toolkit::Visual::IMAGE);
2171   imageMap.Add(Toolkit::ImageVisual::Property::URL, gImage_600_RGB); // 249x169 image
2172   imageMap.Add(DevelVisual::Property::VISUAL_FITTING_MODE, Toolkit::DevelVisual::FIT_WIDTH);
2173
2174   imageView.SetProperty(Toolkit::ImageView::Property::IMAGE, imageMap);
2175   imageView.SetProperty(Actor::Property::SIZE, Vector2(700, 600));
2176
2177   application.GetScene().Add(imageView);
2178
2179   // Trigger a potential relayout
2180   application.SendNotification();
2181   application.Render();
2182
2183   Toolkit::Visual::Base visual = DevelControl::GetVisual(Toolkit::Internal::GetImplementation(imageView), Toolkit::ImageView::Property::IMAGE);
2184   Property::Map         returnedMap;
2185   visual.CreatePropertyMap(returnedMap);
2186
2187   Property::Value* value = returnedMap.Find(Toolkit::Visual::Property::TRANSFORM);
2188   DALI_TEST_CHECK(value);
2189   Property::Map* map = value->GetMap();
2190   DALI_TEST_CHECK(map);
2191
2192   value = map->Find(Toolkit::Visual::Transform::Property::SIZE);
2193   DALI_TEST_CHECK(value);
2194   DALI_TEST_EQUALS(value->Get<Vector2>(), Vector2(700, 600), TEST_LOCATION); // Change the internal size according to the image view size
2195
2196   value = map->Find(Toolkit::Visual::Transform::Property::SIZE_POLICY);
2197   DALI_TEST_CHECK(value);
2198   DALI_TEST_EQUALS(value->Get<Vector2>(), Vector2(Toolkit::Visual::Transform::Policy::ABSOLUTE, Toolkit::Visual::Transform::Policy::ABSOLUTE), TEST_LOCATION);
2199
2200   value = map->Find(Toolkit::Visual::Transform::Property::OFFSET);
2201   DALI_TEST_CHECK(value);
2202   DALI_TEST_EQUALS(value->Get<Vector2>(), Vector2(0, 0), TEST_LOCATION); // OFFSET is zero
2203
2204   END_TEST;
2205 }
2206
2207 int UtcDaliImageViewFittingModesChangeFittingMode01(void)
2208 {
2209   ToolkitTestApplication application;
2210
2211   tet_infoline("UtcDaliImageViewFittingModesChangeFittingMode, image: [600,600], view:[800,700]");
2212
2213   ImageView imageView = ImageView::New();
2214
2215   // 1. Render using FittingMode::SHRINK_TO_FIT
2216   Property::Map imageMap;
2217   imageMap[Toolkit::Visual::Property::TYPE]            = Toolkit::Visual::IMAGE;
2218   imageMap[Toolkit::ImageVisual::Property::URL]        = gImage_600_RGB;
2219   imageMap[DevelVisual::Property::VISUAL_FITTING_MODE] = Toolkit::DevelVisual::FIT_KEEP_ASPECT_RATIO;
2220
2221   imageView.SetProperty(Toolkit::ImageView::Property::IMAGE, imageMap);
2222   imageView.SetProperty(Actor::Property::SIZE, Vector2(800, 700));
2223
2224   application.GetScene().Add(imageView);
2225
2226   // Trigger a potential relayout
2227   application.SendNotification();
2228   application.Render();
2229
2230   Toolkit::Visual::Base visual = DevelControl::GetVisual(Toolkit::Internal::GetImplementation(imageView), Toolkit::ImageView::Property::IMAGE);
2231   Property::Map         returnedMap;
2232   visual.CreatePropertyMap(returnedMap);
2233
2234   Property::Value* value = returnedMap.Find(Toolkit::Visual::Property::TRANSFORM);
2235   DALI_TEST_CHECK(value);
2236   Property::Map* map = value->GetMap();
2237   DALI_TEST_CHECK(map);
2238
2239   value = map->Find(Toolkit::Visual::Transform::Property::SIZE);
2240   DALI_TEST_CHECK(value);
2241   DALI_TEST_EQUALS(value->Get<Vector2>(), Vector2(700, 700), TEST_LOCATION); // Change the internal size according to the image view size
2242
2243   value = map->Find(Toolkit::Visual::Transform::Property::SIZE_POLICY);
2244   DALI_TEST_CHECK(value);
2245   DALI_TEST_EQUALS(value->Get<Vector2>(), Vector2(Toolkit::Visual::Transform::Policy::ABSOLUTE, Toolkit::Visual::Transform::Policy::ABSOLUTE), TEST_LOCATION);
2246
2247   value = map->Find(Toolkit::Visual::Transform::Property::OFFSET);
2248   DALI_TEST_CHECK(value);
2249   DALI_TEST_EQUALS(value->Get<Vector2>(), Vector2(50, 0), TEST_LOCATION);
2250
2251   // 2. Render again using DevelVisaul::CENTER
2252   Property::Map imageMap2;
2253   imageMap2[Toolkit::Visual::Property::TYPE]            = Toolkit::Visual::IMAGE;
2254   imageMap2[Toolkit::ImageVisual::Property::URL]        = gImage_600_RGB;
2255   imageMap2[DevelVisual::Property::VISUAL_FITTING_MODE] = Toolkit::DevelVisual::CENTER;
2256
2257   imageView.SetProperty(Toolkit::ImageView::Property::IMAGE, imageMap2);
2258   imageView.SetProperty(Actor::Property::SIZE, Vector2(800, 700));
2259
2260   application.GetScene().Add(imageView);
2261
2262   DALI_TEST_EQUALS(Test::WaitForEventThreadTrigger(1), true, TEST_LOCATION);
2263
2264   // Trigger a potential relayout
2265   application.SendNotification();
2266   application.Render();
2267
2268   returnedMap.Clear();
2269   visual = DevelControl::GetVisual(Toolkit::Internal::GetImplementation(imageView), Toolkit::ImageView::Property::IMAGE);
2270
2271   visual.CreatePropertyMap(returnedMap);
2272
2273   value = returnedMap.Find(Toolkit::Visual::Property::TRANSFORM);
2274   DALI_TEST_CHECK(value);
2275   map = value->GetMap();
2276   DALI_TEST_CHECK(map);
2277
2278   value = map->Find(Toolkit::Visual::Transform::Property::SIZE);
2279   DALI_TEST_CHECK(value);
2280   DALI_TEST_EQUALS(value->Get<Vector2>(), Vector2(600, 600), TEST_LOCATION); // Change the internal size according to the image view size
2281
2282   value = map->Find(Toolkit::Visual::Transform::Property::SIZE_POLICY);
2283   DALI_TEST_CHECK(value);
2284   DALI_TEST_EQUALS(value->Get<Vector2>(), Vector2(Toolkit::Visual::Transform::Policy::ABSOLUTE, Toolkit::Visual::Transform::Policy::ABSOLUTE), TEST_LOCATION);
2285
2286   value = map->Find(Toolkit::Visual::Transform::Property::OFFSET);
2287   DALI_TEST_CHECK(value);
2288   DALI_TEST_EQUALS(value->Get<Vector2>(), Vector2(100, 50), TEST_LOCATION);
2289
2290   // 3. Render again using before fittingMode
2291   Property::Map imageMap3;
2292   imageMap3[Toolkit::Visual::Property::TYPE]            = Toolkit::Visual::IMAGE;
2293   imageMap3[Toolkit::ImageVisual::Property::URL]        = gImage_600_RGB;
2294   imageMap3[DevelVisual::Property::VISUAL_FITTING_MODE] = Toolkit::DevelVisual::FIT_KEEP_ASPECT_RATIO;
2295
2296   imageView.SetProperty(Toolkit::ImageView::Property::IMAGE, imageMap3);
2297   imageView.SetProperty(Actor::Property::SIZE, Vector2(800, 700));
2298
2299   application.GetScene().Add(imageView);
2300
2301   // Trigger a potential relayout
2302   application.SendNotification();
2303   application.Render();
2304
2305   returnedMap.Clear();
2306   visual = DevelControl::GetVisual(Toolkit::Internal::GetImplementation(imageView), Toolkit::ImageView::Property::IMAGE);
2307   visual.CreatePropertyMap(returnedMap);
2308
2309   value = returnedMap.Find(Toolkit::Visual::Property::TRANSFORM);
2310   DALI_TEST_CHECK(value);
2311   map = value->GetMap();
2312   DALI_TEST_CHECK(map);
2313
2314   value = map->Find(Toolkit::Visual::Transform::Property::SIZE);
2315   DALI_TEST_CHECK(value);
2316   DALI_TEST_EQUALS(value->Get<Vector2>(), Vector2(700, 700), TEST_LOCATION); // Change the internal size according to the image view size
2317
2318   value = map->Find(Toolkit::Visual::Transform::Property::SIZE_POLICY);
2319   DALI_TEST_CHECK(value);
2320   DALI_TEST_EQUALS(value->Get<Vector2>(), Vector2(Toolkit::Visual::Transform::Policy::ABSOLUTE, Toolkit::Visual::Transform::Policy::ABSOLUTE), TEST_LOCATION);
2321
2322   value = map->Find(Toolkit::Visual::Transform::Property::OFFSET);
2323   DALI_TEST_CHECK(value);
2324   DALI_TEST_EQUALS(value->Get<Vector2>(), Vector2(50, 0), TEST_LOCATION);
2325
2326   END_TEST;
2327 }
2328
2329 int UtcDaliImageViewFittingModesChangeFittingMode02(void)
2330 {
2331   ToolkitTestApplication application;
2332
2333   tet_infoline("UtcDaliImageViewFittingModesChangeFittingMode, image: [600,600], view:[800,700]");
2334
2335   ImageView imageView = ImageView::New();
2336
2337   // 1. Render using FittingMode::OVER_FIT_KEEP_ASPECT_RATIO
2338   Property::Map imageMap;
2339   imageMap[Toolkit::Visual::Property::TYPE]            = Toolkit::Visual::IMAGE;
2340   imageMap[Toolkit::ImageVisual::Property::URL]        = gImage_600_RGB;
2341   imageMap[DevelVisual::Property::VISUAL_FITTING_MODE] = Toolkit::DevelVisual::OVER_FIT_KEEP_ASPECT_RATIO;
2342
2343   imageView.SetProperty(Toolkit::ImageView::Property::IMAGE, imageMap);
2344   imageView.SetProperty(Actor::Property::SIZE, Vector2(800, 700));
2345
2346   application.GetScene().Add(imageView);
2347
2348   // Trigger a potential relayout
2349   application.SendNotification();
2350   application.Render();
2351
2352   Toolkit::Visual::Base visual = DevelControl::GetVisual(Toolkit::Internal::GetImplementation(imageView), Toolkit::ImageView::Property::IMAGE);
2353   Property::Map         returnedMap;
2354   visual.CreatePropertyMap(returnedMap);
2355
2356   Property::Value* value = returnedMap.Find(Toolkit::Visual::Property::TRANSFORM);
2357   DALI_TEST_CHECK(value);
2358   Property::Map* map = value->GetMap();
2359   DALI_TEST_CHECK(map);
2360
2361   value = map->Find(Toolkit::Visual::Transform::Property::SIZE);
2362   DALI_TEST_CHECK(value);
2363   DALI_TEST_EQUALS(value->Get<Vector2>(), Vector2(800, 700), TEST_LOCATION); // Change the internal size according to the image view size
2364
2365   value = map->Find(Toolkit::Visual::Transform::Property::SIZE_POLICY);
2366   DALI_TEST_CHECK(value);
2367   DALI_TEST_EQUALS(value->Get<Vector2>(), Vector2(Toolkit::Visual::Transform::Policy::ABSOLUTE, Toolkit::Visual::Transform::Policy::ABSOLUTE), TEST_LOCATION);
2368
2369   value = map->Find(Toolkit::Visual::Transform::Property::OFFSET);
2370   DALI_TEST_CHECK(value);
2371   DALI_TEST_EQUALS(value->Get<Vector2>(), Vector2(0, 0), TEST_LOCATION);
2372
2373   // 2. Render again using DevelVisaul::CENTER
2374   Property::Map imageMap2;
2375   imageMap2[Toolkit::Visual::Property::TYPE]            = Toolkit::Visual::IMAGE;
2376   imageMap2[Toolkit::ImageVisual::Property::URL]        = gImage_600_RGB;
2377   imageMap2[DevelVisual::Property::VISUAL_FITTING_MODE] = Toolkit::DevelVisual::CENTER;
2378
2379   imageView.SetProperty(Toolkit::ImageView::Property::IMAGE, imageMap2);
2380   imageView.SetProperty(Actor::Property::SIZE, Vector2(800, 700));
2381
2382   application.GetScene().Add(imageView);
2383
2384   DALI_TEST_EQUALS(Test::WaitForEventThreadTrigger(1), true, TEST_LOCATION);
2385
2386   // Trigger a potential relayout
2387   application.SendNotification();
2388   application.Render();
2389
2390   returnedMap.Clear();
2391   visual = DevelControl::GetVisual(Toolkit::Internal::GetImplementation(imageView), Toolkit::ImageView::Property::IMAGE);
2392
2393   visual.CreatePropertyMap(returnedMap);
2394
2395   value = returnedMap.Find(Toolkit::Visual::Property::TRANSFORM);
2396   DALI_TEST_CHECK(value);
2397   map = value->GetMap();
2398   DALI_TEST_CHECK(map);
2399
2400   value = map->Find(Toolkit::Visual::Transform::Property::SIZE);
2401   DALI_TEST_CHECK(value);
2402   DALI_TEST_EQUALS(value->Get<Vector2>(), Vector2(600, 600), TEST_LOCATION); // Change the internal size according to the image view size
2403
2404   value = map->Find(Toolkit::Visual::Transform::Property::SIZE_POLICY);
2405   DALI_TEST_CHECK(value);
2406   DALI_TEST_EQUALS(value->Get<Vector2>(), Vector2(Toolkit::Visual::Transform::Policy::ABSOLUTE, Toolkit::Visual::Transform::Policy::ABSOLUTE), TEST_LOCATION);
2407
2408   value = map->Find(Toolkit::Visual::Transform::Property::OFFSET);
2409   DALI_TEST_CHECK(value);
2410   DALI_TEST_EQUALS(value->Get<Vector2>(), Vector2(100, 50), TEST_LOCATION);
2411
2412   // 3. Render again using before fittingMode
2413   Property::Map imageMap3;
2414   imageMap3[Toolkit::Visual::Property::TYPE]            = Toolkit::Visual::IMAGE;
2415   imageMap3[Toolkit::ImageVisual::Property::URL]        = gImage_600_RGB;
2416   imageMap3[DevelVisual::Property::VISUAL_FITTING_MODE] = Toolkit::DevelVisual::OVER_FIT_KEEP_ASPECT_RATIO;
2417
2418   imageView.SetProperty(Toolkit::ImageView::Property::IMAGE, imageMap3);
2419   imageView.SetProperty(Actor::Property::SIZE, Vector2(800, 700));
2420
2421   application.GetScene().Add(imageView);
2422
2423   // Trigger a potential relayout
2424   application.SendNotification();
2425   application.Render();
2426
2427   returnedMap.Clear();
2428   visual = DevelControl::GetVisual(Toolkit::Internal::GetImplementation(imageView), Toolkit::ImageView::Property::IMAGE);
2429   visual.CreatePropertyMap(returnedMap);
2430
2431   value = returnedMap.Find(Toolkit::Visual::Property::TRANSFORM);
2432   DALI_TEST_CHECK(value);
2433   map = value->GetMap();
2434   DALI_TEST_CHECK(map);
2435
2436   value = map->Find(Toolkit::Visual::Transform::Property::SIZE);
2437   DALI_TEST_CHECK(value);
2438   DALI_TEST_EQUALS(value->Get<Vector2>(), Vector2(800, 700), TEST_LOCATION); // Change the internal size according to the image view size
2439
2440   value = map->Find(Toolkit::Visual::Transform::Property::SIZE_POLICY);
2441   DALI_TEST_CHECK(value);
2442   DALI_TEST_EQUALS(value->Get<Vector2>(), Vector2(Toolkit::Visual::Transform::Policy::ABSOLUTE, Toolkit::Visual::Transform::Policy::ABSOLUTE), TEST_LOCATION);
2443
2444   value = map->Find(Toolkit::Visual::Transform::Property::OFFSET);
2445   DALI_TEST_CHECK(value);
2446   DALI_TEST_EQUALS(value->Get<Vector2>(), Vector2(0, 0), TEST_LOCATION);
2447
2448   END_TEST;
2449 }
2450
2451 int UtcDaliImageViewFittingModesWithAnimatedVectorImageVisual(void)
2452 {
2453   ToolkitTestApplication application;
2454
2455   tet_infoline("Create an ImageVisual using SCALE_TO_FILL and animated vector image ( image: [600,600], view:[600,600] )");
2456
2457   ImageView     imageView = ImageView::New();
2458   Property::Map imageMap;
2459   imageMap.Add(Toolkit::Visual::Property::TYPE, DevelVisual::ANIMATED_VECTOR_IMAGE);
2460   imageMap.Add(Toolkit::ImageVisual::Property::URL, TEST_ANIMATED_VECTOR_IMAGE_FILE_NAME); // 249x169 image
2461
2462   imageView.SetProperty(Toolkit::ImageView::Property::IMAGE, imageMap);
2463   imageView.SetProperty(Actor::Property::SIZE, Vector2(600, 600));
2464
2465   application.GetScene().Add(imageView);
2466
2467   // Trigger a potential relayout
2468   application.SendNotification();
2469   application.Render();
2470
2471   Toolkit::Visual::Base visual = DevelControl::GetVisual(Toolkit::Internal::GetImplementation(imageView), Toolkit::ImageView::Property::IMAGE);
2472   Property::Map         returnedMap;
2473   visual.CreatePropertyMap(returnedMap);
2474
2475   Property::Value* value = returnedMap.Find(Toolkit::Visual::Property::TRANSFORM);
2476   DALI_TEST_CHECK(value);
2477   Property::Map* map = value->GetMap();
2478   DALI_TEST_CHECK(map);
2479
2480   value = map->Find(Toolkit::Visual::Transform::Property::SIZE);
2481   DALI_TEST_CHECK(value);
2482   DALI_TEST_EQUALS(value->Get<Vector2>(), Vector2::ONE, TEST_LOCATION); // Relative size so will take up 100%
2483
2484   value = map->Find(Toolkit::Visual::Transform::Property::SIZE_POLICY);
2485   DALI_TEST_CHECK(value);
2486   DALI_TEST_CHECK(value->Get<int>() == Toolkit::Visual::Transform::Policy::RELATIVE);
2487
2488   value = map->Find(Toolkit::Visual::Transform::Property::OFFSET);
2489   DALI_TEST_CHECK(value);
2490   DALI_TEST_EQUALS(value->Get<Vector2>(), Vector2(0, 0), TEST_LOCATION); // OFFSET is zero
2491
2492   END_TEST;
2493 }
2494
2495 int UtcDaliImageViewCustomShader(void)
2496 {
2497   ToolkitTestApplication application;
2498
2499   // Set a custom shader with an image url
2500   {
2501     Property::Map     properties;
2502     Property::Map     shader;
2503     const std::string vertexShader                    = "Foobar";
2504     const std::string fragmentShader                  = "Foobar";
2505     shader[Visual::Shader::Property::FRAGMENT_SHADER] = fragmentShader;
2506     shader[Visual::Shader::Property::VERTEX_SHADER]   = vertexShader;
2507
2508     properties[Visual::Property::TYPE]     = Visual::IMAGE;
2509     properties[Visual::Property::SHADER]   = shader;
2510     properties[ImageVisual::Property::URL] = TEST_IMAGE_FILE_NAME;
2511
2512     ImageView imageView = ImageView::New();
2513     imageView.SetProperty(ImageView::Property::IMAGE, properties);
2514
2515     application.GetScene().Add(imageView);
2516
2517     application.SendNotification();
2518     application.Render();
2519
2520     DALI_TEST_EQUALS(Test::WaitForEventThreadTrigger(1), true, TEST_LOCATION);
2521
2522     Renderer        renderer = imageView.GetRendererAt(0);
2523     Shader          shader2  = renderer.GetShader();
2524     Property::Value value    = shader2.GetProperty(Shader::Property::PROGRAM);
2525     Property::Map*  map      = value.GetMap();
2526     DALI_TEST_CHECK(map);
2527
2528     Property::Value* fragment = map->Find("fragment"); // fragment key name from shader-impl.cpp
2529     DALI_TEST_EQUALS(fragmentShader, fragment->Get<std::string>(), TEST_LOCATION);
2530
2531     Property::Value* vertex = map->Find("vertex"); // vertex key name from shader-impl.cpp
2532     DALI_TEST_EQUALS(vertexShader, vertex->Get<std::string>(), TEST_LOCATION);
2533   }
2534
2535   // Set a custom shader after setting an image url
2536   {
2537     Property::Map     properties;
2538     Property::Map     shader;
2539     const std::string vertexShader                    = "Foobar";
2540     const std::string fragmentShader                  = "Foobar";
2541     shader[Visual::Shader::Property::FRAGMENT_SHADER] = fragmentShader;
2542     shader[Visual::Shader::Property::VERTEX_SHADER]   = vertexShader;
2543
2544     properties[Visual::Property::SHADER] = shader;
2545
2546     ImageView imageView = ImageView::New(TEST_IMAGE_FILE_NAME);
2547     imageView.SetProperty(ImageView::Property::IMAGE, properties);
2548
2549     application.GetScene().Add(imageView);
2550
2551     application.SendNotification();
2552     application.Render();
2553
2554     DALI_TEST_EQUALS(Test::WaitForEventThreadTrigger(1), true, TEST_LOCATION);
2555
2556     Renderer        renderer = imageView.GetRendererAt(0);
2557     Shader          shader2  = renderer.GetShader();
2558     Property::Value value    = shader2.GetProperty(Shader::Property::PROGRAM);
2559     Property::Map*  map      = value.GetMap();
2560     DALI_TEST_CHECK(map);
2561
2562     Property::Value* fragment = map->Find("fragment"); // fragment key name from shader-impl.cpp
2563     DALI_TEST_EQUALS(fragmentShader, fragment->Get<std::string>(), TEST_LOCATION);
2564
2565     Property::Value* vertex = map->Find("vertex"); // vertex key name from shader-impl.cpp
2566     DALI_TEST_EQUALS(vertexShader, vertex->Get<std::string>(), TEST_LOCATION);
2567   }
2568
2569   // Set a custom shader before setting an image url
2570   {
2571     Property::Map     properties;
2572     Property::Map     shader;
2573     const std::string vertexShader                    = "Foobar";
2574     const std::string fragmentShader                  = "Foobar";
2575     shader[Visual::Shader::Property::FRAGMENT_SHADER] = fragmentShader;
2576     shader[Visual::Shader::Property::VERTEX_SHADER]   = vertexShader;
2577
2578     properties[Visual::Property::SHADER] = shader;
2579
2580     ImageView imageView = ImageView::New();
2581     imageView.SetProperty(ImageView::Property::IMAGE, properties);
2582     imageView.SetProperty(ImageView::Property::IMAGE, TEST_IMAGE_FILE_NAME);
2583
2584     application.GetScene().Add(imageView);
2585
2586     application.SendNotification();
2587     application.Render();
2588     DALI_TEST_EQUALS(Test::WaitForEventThreadTrigger(1), true, TEST_LOCATION);
2589
2590     Renderer        renderer = imageView.GetRendererAt(0);
2591     Shader          shader2  = renderer.GetShader();
2592     Property::Value value    = shader2.GetProperty(Shader::Property::PROGRAM);
2593     Property::Map*  map      = value.GetMap();
2594     DALI_TEST_CHECK(map);
2595
2596     Property::Value* fragment = map->Find("fragment"); // fragment key name from shader-impl.cpp
2597     DALI_TEST_EQUALS(fragmentShader, fragment->Get<std::string>(), TEST_LOCATION);
2598
2599     Property::Value* vertex = map->Find("vertex"); // vertex key name from shader-impl.cpp
2600     DALI_TEST_EQUALS(vertexShader, vertex->Get<std::string>(), TEST_LOCATION);
2601   }
2602
2603   // Set a custom shader after setting a property map
2604   {
2605     Property::Map     properties;
2606     Property::Map     shader;
2607     const std::string vertexShader                    = "Foobar";
2608     const std::string fragmentShader                  = "Foobar";
2609     shader[Visual::Shader::Property::FRAGMENT_SHADER] = fragmentShader;
2610     shader[Visual::Shader::Property::VERTEX_SHADER]   = vertexShader;
2611
2612     properties[Visual::Property::SHADER] = shader;
2613
2614     Property::Map properties1;
2615     properties1[Visual::Property::TYPE]     = Visual::IMAGE;
2616     properties1[ImageVisual::Property::URL] = TEST_IMAGE_FILE_NAME;
2617
2618     ImageView imageView = ImageView::New();
2619     imageView.SetProperty(ImageView::Property::IMAGE, properties1);
2620     imageView.SetProperty(ImageView::Property::IMAGE, properties);
2621
2622     application.GetScene().Add(imageView);
2623
2624     application.SendNotification();
2625     application.Render();
2626     DALI_TEST_EQUALS(Test::WaitForEventThreadTrigger(1), true, TEST_LOCATION);
2627
2628     Renderer        renderer = imageView.GetRendererAt(0);
2629     Shader          shader2  = renderer.GetShader();
2630     Property::Value value    = shader2.GetProperty(Shader::Property::PROGRAM);
2631     Property::Map*  map      = value.GetMap();
2632     DALI_TEST_CHECK(map);
2633
2634     Property::Value* fragment = map->Find("fragment"); // fragment key name from shader-impl.cpp
2635     DALI_TEST_EQUALS(fragmentShader, fragment->Get<std::string>(), TEST_LOCATION);
2636
2637     Property::Value* vertex = map->Find("vertex"); // vertex key name from shader-impl.cpp
2638     DALI_TEST_EQUALS(vertexShader, vertex->Get<std::string>(), TEST_LOCATION);
2639   }
2640
2641   // Set a custom shader before setting a property map
2642   {
2643     Property::Map     properties;
2644     Property::Map     shader;
2645     const std::string vertexShader                    = "Foobar";
2646     const std::string fragmentShader                  = "Foobar";
2647     shader[Visual::Shader::Property::FRAGMENT_SHADER] = fragmentShader;
2648     shader[Visual::Shader::Property::VERTEX_SHADER]   = vertexShader;
2649
2650     properties[Visual::Property::SHADER] = shader;
2651
2652     Property::Map properties1;
2653     properties1[Visual::Property::TYPE]     = Visual::IMAGE;
2654     properties1[ImageVisual::Property::URL] = TEST_IMAGE_FILE_NAME;
2655
2656     ImageView imageView = ImageView::New();
2657     imageView.SetProperty(ImageView::Property::IMAGE, properties);
2658     imageView.SetProperty(ImageView::Property::IMAGE, properties1);
2659
2660     application.GetScene().Add(imageView);
2661
2662     application.SendNotification();
2663     application.Render();
2664     DALI_TEST_EQUALS(Test::WaitForEventThreadTrigger(1), true, TEST_LOCATION);
2665
2666     Renderer        renderer = imageView.GetRendererAt(0);
2667     Shader          shader2  = renderer.GetShader();
2668     Property::Value value    = shader2.GetProperty(Shader::Property::PROGRAM);
2669     Property::Map*  map      = value.GetMap();
2670     DALI_TEST_CHECK(map);
2671
2672     Property::Value* fragment = map->Find("fragment"); // fragment key name from shader-impl.cpp
2673     DALI_TEST_EQUALS(fragmentShader, fragment->Get<std::string>(), TEST_LOCATION);
2674
2675     Property::Value* vertex = map->Find("vertex"); // vertex key name from shader-impl.cpp
2676     DALI_TEST_EQUALS(vertexShader, vertex->Get<std::string>(), TEST_LOCATION);
2677   }
2678
2679   END_TEST;
2680 }
2681
2682 namespace
2683 {
2684 static int gFailCounter = 0;
2685 const int  MAX_RETRIES(3);
2686
2687 void ReloadImage(ImageView imageView)
2688 {
2689   Property::Map imageImmediateLoadingMap;
2690   imageImmediateLoadingMap[ImageVisual::Property::URL]         = "Non-existant-image.jpg";
2691   imageImmediateLoadingMap[ImageVisual::Property::LOAD_POLICY] = ImageVisual::LoadPolicy::IMMEDIATE;
2692
2693   tet_infoline("Immediate load an image");
2694   imageView.SetProperty(ImageView::Property::IMAGE, imageImmediateLoadingMap);
2695 }
2696
2697 void ResourceFailedReload(Control control)
2698 {
2699   gFailCounter++;
2700 }
2701 } // namespace
2702
2703 int UtcDaliImageViewReloadFailedOnResourceReadySignal(void)
2704 {
2705   tet_infoline("Test reloading failed image from within signal handler.");
2706
2707   ToolkitTestApplication application;
2708
2709   gFailCounter = 0;
2710
2711   ImageView imageView = ImageView::New();
2712   imageView.ResourceReadySignal().Connect(&ResourceFailedReload);
2713   DALI_TEST_EQUALS(gFailCounter, 0, TEST_LOCATION);
2714   ReloadImage(imageView);
2715
2716   // loading started, this waits for the loader thread to complete
2717   DALI_TEST_EQUALS(Test::WaitForEventThreadTrigger(1), true, TEST_LOCATION);
2718   DALI_TEST_EQUALS(gFailCounter, 1, TEST_LOCATION);
2719
2720   ReloadImage(imageView);
2721   DALI_TEST_EQUALS(Test::WaitForEventThreadTrigger(1), true, TEST_LOCATION);
2722   DALI_TEST_EQUALS(gFailCounter, 2, TEST_LOCATION);
2723
2724   ReloadImage(imageView);
2725   DALI_TEST_EQUALS(Test::WaitForEventThreadTrigger(1), true, TEST_LOCATION);
2726   DALI_TEST_EQUALS(gFailCounter, 3, TEST_LOCATION);
2727
2728   END_TEST;
2729 }
2730
2731 int UtcDaliImageViewLoadRemoteSVG(void)
2732 {
2733   tet_infoline("Test load from a remote server.");
2734
2735   ToolkitTestApplication application;
2736
2737   {
2738     Toolkit::ImageView imageView;
2739     imageView = Toolkit::ImageView::New();
2740     imageView.SetImage("https://dev.w3.org/SVG/tools/svgweb/samples/svg-files/check.svg");
2741     imageView.SetProperty(Actor::Property::PARENT_ORIGIN, ParentOrigin::TOP_LEFT);
2742     imageView.SetProperty(Actor::Property::ANCHOR_POINT, AnchorPoint::TOP_LEFT);
2743     imageView.SetProperty(Actor::Property::SIZE, Vector2(300, 300));
2744     imageView.SetProperty(Actor::Property::POSITION, Vector3(150.0f, 150.0f, 0.0f));
2745
2746     application.GetScene().Add(imageView);
2747
2748     DALI_TEST_CHECK(imageView);
2749
2750     DALI_TEST_EQUALS(imageView.GetRendererCount(), 0u, TEST_LOCATION);
2751
2752     application.SendNotification();
2753
2754     // Wait for loading & rasterization
2755     DALI_TEST_EQUALS(Test::WaitForEventThreadTrigger(2), true, TEST_LOCATION);
2756
2757     application.SendNotification();
2758     application.Render();
2759
2760     DALI_TEST_EQUALS(imageView.GetRendererCount(), 1u, TEST_LOCATION);
2761   }
2762
2763   // Without size set
2764   {
2765     Toolkit::ImageView imageView;
2766     imageView = Toolkit::ImageView::New();
2767     imageView.SetImage("https://dev.w3.org/SVG/tools/svgweb/samples/svg-files/check.svg");
2768     imageView.SetProperty(Actor::Property::PARENT_ORIGIN, ParentOrigin::TOP_LEFT);
2769     imageView.SetProperty(Actor::Property::ANCHOR_POINT, AnchorPoint::TOP_LEFT);
2770     imageView.SetProperty(Actor::Property::POSITION, Vector3(150.0f, 150.0f, 0.0f));
2771
2772     application.GetScene().Add(imageView);
2773
2774     DALI_TEST_CHECK(imageView);
2775
2776     DALI_TEST_EQUALS(imageView.GetRendererCount(), 0u, TEST_LOCATION);
2777
2778     application.SendNotification();
2779
2780     // Wait for loading & rasterization
2781     DALI_TEST_EQUALS(Test::WaitForEventThreadTrigger(2), true, TEST_LOCATION);
2782
2783     application.SendNotification();
2784     application.Render();
2785
2786     DALI_TEST_EQUALS(imageView.GetRendererCount(), 1u, TEST_LOCATION);
2787   }
2788
2789   END_TEST;
2790 }
2791
2792 int UtcDaliImageViewSyncSVGLoading(void)
2793 {
2794   ToolkitTestApplication application;
2795
2796   tet_infoline("ImageView Testing SVG image sync loading");
2797
2798   {
2799     ImageView imageView = ImageView::New();
2800
2801     // Sync loading is used
2802     Property::Map syncLoadingMap;
2803     syncLoadingMap.Insert(Toolkit::Visual::Property::TYPE, Toolkit::Visual::IMAGE);
2804     syncLoadingMap.Insert(Toolkit::ImageVisual::Property::URL, TEST_RESOURCE_DIR "/svg1.svg");
2805     syncLoadingMap.Insert(Toolkit::ImageVisual::Property::SYNCHRONOUS_LOADING, true);
2806     imageView.SetProperty(ImageView::Property::IMAGE, syncLoadingMap);
2807
2808     application.GetScene().Add(imageView);
2809     DALI_TEST_CHECK(imageView);
2810
2811     application.SendNotification();
2812     Vector3 naturalSize = imageView.GetNaturalSize();
2813
2814     DALI_TEST_EQUALS(naturalSize.width, 100.0f, TEST_LOCATION);
2815     DALI_TEST_EQUALS(naturalSize.height, 100.0f, TEST_LOCATION);
2816   }
2817   END_TEST;
2818 }
2819
2820 int UtcDaliImageViewSyncSVGLoading02(void)
2821 {
2822   ToolkitTestApplication application;
2823
2824   tet_infoline("ImageView Testing SVG image sync loading");
2825
2826   {
2827     ImageView imageView = ImageView::New();
2828
2829     // Sync loading is used
2830     Property::Map syncLoadingMap;
2831     syncLoadingMap.Insert(Toolkit::Visual::Property::TYPE, Toolkit::Visual::IMAGE);
2832     syncLoadingMap.Insert(Toolkit::ImageVisual::Property::URL, TEST_RESOURCE_DIR "/svg1.svg");
2833     syncLoadingMap.Insert(Toolkit::ImageVisual::Property::SYNCHRONOUS_LOADING, true);
2834     syncLoadingMap.Insert(DevelVisual::Property::VISUAL_FITTING_MODE, Toolkit::DevelVisual::FIT_KEEP_ASPECT_RATIO);
2835     imageView.SetProperty(ImageView::Property::IMAGE, syncLoadingMap);
2836     imageView.ResourceReadySignal().Connect(&OnResourceReadySignalSVG);
2837
2838     application.GetScene().Add(imageView);
2839     DALI_TEST_CHECK(imageView);
2840
2841     application.SendNotification();
2842     application.Render();
2843
2844     // Check whether Image Visual transforms on ImageVieiw::OnRelayout()
2845     Toolkit::Internal::Control& controlImpl = Toolkit::Internal::GetImplementation(imageView);
2846     Toolkit::Visual::Base       imageVisual = DevelControl::GetVisual(controlImpl, ImageView::Property::IMAGE);
2847     Property::Map               resultMap;
2848     imageVisual.CreatePropertyMap(resultMap);
2849
2850     Property::Value* transformValue = resultMap.Find(Visual::Property::TRANSFORM);
2851     DALI_TEST_CHECK(transformValue);
2852     Property::Map* retMap = transformValue->GetMap();
2853     DALI_TEST_CHECK(retMap);
2854
2855     // Image Visual should be positioned depending on ImageView's padding
2856     DALI_TEST_EQUALS(retMap->Find(Visual::Transform::Property::SIZE)->Get<Vector2>(), Vector2(100, 100), TEST_LOCATION);
2857
2858     Vector3 naturalSize = imageView.GetNaturalSize();
2859     DALI_TEST_EQUALS(naturalSize.width, 100.0f, TEST_LOCATION);
2860     DALI_TEST_EQUALS(naturalSize.height, 100.0f, TEST_LOCATION);
2861   }
2862   END_TEST;
2863 }
2864
2865 int UtcDaliImageViewAsyncSVGLoading(void)
2866 {
2867   ToolkitTestApplication application;
2868
2869   tet_infoline("ImageView Testing SVG image async loading");
2870
2871   {
2872     ImageView imageView = ImageView::New();
2873
2874     // Async loading is used - default value of SYNCHRONOUS_LOADING is false.
2875     Property::Map propertyMap;
2876     propertyMap.Insert(Toolkit::Visual::Property::TYPE, Toolkit::Visual::IMAGE);
2877     propertyMap.Insert(Toolkit::ImageVisual::Property::URL, TEST_RESOURCE_DIR "/svg1.svg");
2878     imageView.SetProperty(ImageView::Property::IMAGE, propertyMap);
2879
2880     application.GetScene().Add(imageView);
2881     DALI_TEST_CHECK(imageView);
2882
2883     application.SendNotification();
2884
2885     // Wait for loading
2886     DALI_TEST_EQUALS(Test::WaitForEventThreadTrigger(1), true, TEST_LOCATION);
2887
2888     application.SendNotification();
2889     application.Render(16);
2890
2891     Vector3 naturalSize = imageView.GetNaturalSize();
2892     DALI_TEST_EQUALS(naturalSize.width, 100.0f, TEST_LOCATION);
2893     DALI_TEST_EQUALS(naturalSize.height, 100.0f, TEST_LOCATION);
2894   }
2895   END_TEST;
2896 }
2897
2898 int UtcDaliImageViewSVGLoadingSyncSetInvalidValue(void)
2899 {
2900   ToolkitTestApplication application;
2901
2902   tet_infoline("ImageView Testing SVG image async loading");
2903
2904   // Sync loading
2905   {
2906     ImageView imageView = ImageView::New();
2907
2908     // Sync loading is used
2909     Property::Map syncLoadingMap;
2910     syncLoadingMap.Insert(Toolkit::Visual::Property::TYPE, Toolkit::Visual::IMAGE);
2911     syncLoadingMap.Insert(Toolkit::ImageVisual::Property::URL, TEST_RESOURCE_DIR "/svg1.svg");
2912
2913     // Check to set invalid value
2914     // The SYNCHRONOUS_LOADING property must be set to the bool value.
2915     // Check if error log is outputted when setting other value like string.
2916     // Even if the wrong value is set, the image will be shown normally, and the synchronous value should be the default value(false).
2917     syncLoadingMap.Insert(Toolkit::ImageVisual::Property::SYNCHRONOUS_LOADING, std::to_string(5));
2918     imageView.SetProperty(ImageView::Property::IMAGE, syncLoadingMap);
2919
2920     application.GetScene().Add(imageView);
2921     DALI_TEST_CHECK(imageView);
2922
2923     application.SendNotification();
2924
2925     // Wait for loading
2926     DALI_TEST_EQUALS(Test::WaitForEventThreadTrigger(1), true, TEST_LOCATION);
2927
2928     application.SendNotification();
2929     application.Render(16);
2930
2931     Vector3 naturalSize = imageView.GetNaturalSize();
2932     DALI_TEST_EQUALS(naturalSize.width, 100.0f, TEST_LOCATION);
2933     DALI_TEST_EQUALS(naturalSize.height, 100.0f, TEST_LOCATION);
2934
2935     Property::Value value = imageView.GetProperty(ImageView::Property::IMAGE);
2936     Property::Map*  map   = value.GetMap();
2937     DALI_TEST_CHECK(map);
2938
2939     Property::Value* sync = map->Find(Toolkit::ImageVisual::Property::SYNCHRONOUS_LOADING);
2940     DALI_TEST_CHECK(sync);
2941     DALI_TEST_EQUALS(false, sync->Get<bool>(), TEST_LOCATION);
2942   }
2943   END_TEST;
2944 }
2945
2946 int UtcDaliImageViewSvgLoadingFailureLocalFile(void)
2947 {
2948   // Local svg file - invalid file path
2949   {
2950     ToolkitTestApplication application;
2951
2952     TestGlAbstraction& gl           = application.GetGlAbstraction();
2953     TraceCallStack&    textureTrace = gl.GetTextureTrace();
2954     textureTrace.Enable(true);
2955
2956     gResourceReadySignalFired = false;
2957
2958     ImageView imageView = ImageView::New(TEST_RESOURCE_DIR "/foo.svg");
2959     imageView.SetProperty(Actor::Property::SIZE, Vector2(200.f, 200.f));
2960     imageView.ResourceReadySignal().Connect(&ResourceReadySignal);
2961
2962     DALI_TEST_EQUALS(imageView.IsResourceReady(), false, TEST_LOCATION);
2963
2964     application.GetScene().Add(imageView);
2965
2966     application.SendNotification();
2967
2968     // loading started, this waits for the loader thread - load
2969     DALI_TEST_EQUALS(Test::WaitForEventThreadTrigger(1), true, TEST_LOCATION);
2970
2971     application.SendNotification();
2972     application.Render(16);
2973
2974     DALI_TEST_EQUALS(gResourceReadySignalFired, true, TEST_LOCATION);
2975     DALI_TEST_EQUALS(imageView.IsResourceReady(), true, TEST_LOCATION);
2976     DALI_TEST_EQUALS(imageView.GetVisualResourceStatus(ImageView::Property::IMAGE), Visual::ResourceStatus::FAILED, TEST_LOCATION);
2977
2978     // Should be shown a broken image
2979     DALI_TEST_EQUALS(imageView.GetRendererCount(), 1u, TEST_LOCATION);
2980     DALI_TEST_EQUALS(textureTrace.FindMethod("BindTexture"), true, TEST_LOCATION);
2981   }
2982
2983   // Local svg file - invalid file path without size set
2984   {
2985     ToolkitTestApplication application;
2986
2987     TestGlAbstraction& gl           = application.GetGlAbstraction();
2988     TraceCallStack&    textureTrace = gl.GetTextureTrace();
2989     textureTrace.Enable(true);
2990
2991     gResourceReadySignalFired = false;
2992     textureTrace.Reset();
2993
2994     ImageView imageView = ImageView::New(TEST_RESOURCE_DIR "/foo.svg");
2995     imageView.ResourceReadySignal().Connect(&ResourceReadySignal);
2996
2997     DALI_TEST_EQUALS(imageView.IsResourceReady(), false, TEST_LOCATION);
2998
2999     application.GetScene().Add(imageView);
3000
3001     application.SendNotification();
3002
3003     // loading started, this waits for the loader thread - load & rasterize
3004     DALI_TEST_EQUALS(Test::WaitForEventThreadTrigger(1), true, TEST_LOCATION);
3005
3006     application.SendNotification();
3007     application.Render(16);
3008
3009     DALI_TEST_EQUALS(gResourceReadySignalFired, true, TEST_LOCATION);
3010     DALI_TEST_EQUALS(imageView.IsResourceReady(), true, TEST_LOCATION);
3011     DALI_TEST_EQUALS(imageView.GetVisualResourceStatus(ImageView::Property::IMAGE), Visual::ResourceStatus::FAILED, TEST_LOCATION);
3012
3013     // Should be shown a broken image
3014     DALI_TEST_EQUALS(imageView.GetRendererCount(), 1u, TEST_LOCATION);
3015     DALI_TEST_EQUALS(textureTrace.FindMethod("BindTexture"), true, TEST_LOCATION);
3016   }
3017
3018   // Local svg file - invalid file
3019   {
3020     ToolkitTestApplication application;
3021
3022     TestGlAbstraction& gl           = application.GetGlAbstraction();
3023     TraceCallStack&    textureTrace = gl.GetTextureTrace();
3024     textureTrace.Enable(true);
3025
3026     gResourceReadySignalFired = false;
3027     textureTrace.Reset();
3028
3029     ImageView imageView = ImageView::New(TEST_RESOURCE_DIR "/invalid.svg");
3030     imageView.SetProperty(Actor::Property::SIZE, Vector2(200.f, 200.f));
3031     imageView.ResourceReadySignal().Connect(&ResourceReadySignal);
3032
3033     DALI_TEST_EQUALS(imageView.IsResourceReady(), false, TEST_LOCATION);
3034
3035     application.GetScene().Add(imageView);
3036
3037     application.SendNotification();
3038
3039     // loading started, this waits for the loader thread - load & rasterize
3040     DALI_TEST_EQUALS(Test::WaitForEventThreadTrigger(1), true, TEST_LOCATION);
3041
3042     application.SendNotification();
3043     application.Render(16);
3044
3045     DALI_TEST_EQUALS(gResourceReadySignalFired, true, TEST_LOCATION);
3046     DALI_TEST_EQUALS(imageView.IsResourceReady(), true, TEST_LOCATION);
3047     DALI_TEST_EQUALS(imageView.GetVisualResourceStatus(ImageView::Property::IMAGE), Visual::ResourceStatus::FAILED, TEST_LOCATION);
3048
3049     // Should be shown a broken image
3050     DALI_TEST_EQUALS(imageView.GetRendererCount(), 1u, TEST_LOCATION);
3051     DALI_TEST_EQUALS(textureTrace.FindMethod("BindTexture"), true, TEST_LOCATION);
3052   }
3053
3054   END_TEST;
3055 }
3056
3057 int UtcDaliImageViewSvgLoadingFailureRemoteFile01(void)
3058 {
3059   // Remote svg file
3060   {
3061     ToolkitTestApplication application;
3062
3063     TestGlAbstraction& gl           = application.GetGlAbstraction();
3064     TraceCallStack&    textureTrace = gl.GetTextureTrace();
3065     textureTrace.Enable(true);
3066
3067     gResourceReadySignalFired = false;
3068
3069     ImageView imageView = ImageView::New("https://127.0.0.1/foobar.svg");
3070     imageView.SetProperty(Actor::Property::SIZE, Vector2(200.f, 200.f));
3071     imageView.ResourceReadySignal().Connect(&ResourceReadySignal);
3072
3073     DALI_TEST_EQUALS(imageView.IsResourceReady(), false, TEST_LOCATION);
3074
3075     application.GetScene().Add(imageView);
3076
3077     application.SendNotification();
3078
3079     // loading started, this waits for the loader thread - load & rasterize
3080     DALI_TEST_EQUALS(Test::WaitForEventThreadTrigger(1), true, TEST_LOCATION);
3081
3082     application.SendNotification();
3083     application.Render(16);
3084
3085     DALI_TEST_EQUALS(gResourceReadySignalFired, true, TEST_LOCATION);
3086     DALI_TEST_EQUALS(imageView.IsResourceReady(), true, TEST_LOCATION);
3087     DALI_TEST_EQUALS(imageView.GetVisualResourceStatus(ImageView::Property::IMAGE), Visual::ResourceStatus::FAILED, TEST_LOCATION);
3088
3089     // Should be shown a broken image
3090     DALI_TEST_EQUALS(imageView.GetRendererCount(), 1u, TEST_LOCATION);
3091     DALI_TEST_EQUALS(textureTrace.FindMethod("BindTexture"), true, TEST_LOCATION);
3092   }
3093
3094   END_TEST;
3095 }
3096
3097 int UtcDaliImageViewSvgLoadingFailureRemoteFile02(void)
3098 {
3099   // Remote svg file without size set
3100   {
3101     ToolkitTestApplication application;
3102
3103     TestGlAbstraction& gl           = application.GetGlAbstraction();
3104     TraceCallStack&    textureTrace = gl.GetTextureTrace();
3105     textureTrace.Enable(true);
3106
3107     gResourceReadySignalFired = false;
3108
3109     ImageView imageView = ImageView::New("https://127.0.0.1/foobar.svg");
3110     imageView.ResourceReadySignal().Connect(&ResourceReadySignal);
3111
3112     DALI_TEST_EQUALS(imageView.IsResourceReady(), false, TEST_LOCATION);
3113
3114     application.GetScene().Add(imageView);
3115
3116     application.SendNotification();
3117
3118     // loading started, this waits for the loader thread - load & rasterize
3119     DALI_TEST_EQUALS(Test::WaitForEventThreadTrigger(1), true, TEST_LOCATION);
3120
3121     application.SendNotification();
3122     application.Render(16);
3123
3124     DALI_TEST_EQUALS(gResourceReadySignalFired, true, TEST_LOCATION);
3125     DALI_TEST_EQUALS(imageView.IsResourceReady(), true, TEST_LOCATION);
3126     DALI_TEST_EQUALS(imageView.GetVisualResourceStatus(ImageView::Property::IMAGE), Visual::ResourceStatus::FAILED, TEST_LOCATION);
3127
3128     // Should be shown a broken image
3129     DALI_TEST_EQUALS(imageView.GetRendererCount(), 1u, TEST_LOCATION);
3130     DALI_TEST_EQUALS(textureTrace.FindMethod("BindTexture"), true, TEST_LOCATION);
3131   }
3132
3133   END_TEST;
3134 }
3135
3136 int UtcDaliImageViewSvgRasterizationFailure(void)
3137 {
3138   ToolkitTestApplication application;
3139
3140   gResourceReadySignalFired = false;
3141
3142   TestGlAbstraction& gl           = application.GetGlAbstraction();
3143   TraceCallStack&    textureTrace = gl.GetTextureTrace();
3144   textureTrace.Enable(true);
3145
3146   ImageView imageView = ImageView::New(TEST_RESOURCE_DIR "/invalid1.svg");
3147   imageView.SetProperty(Actor::Property::SIZE, Vector2(200.f, 200.f));
3148   imageView.ResourceReadySignal().Connect(&ResourceReadySignal);
3149
3150   DALI_TEST_EQUALS(imageView.IsResourceReady(), false, TEST_LOCATION);
3151
3152   application.GetScene().Add(imageView);
3153
3154   application.SendNotification();
3155
3156   // Wait for loading & rasterization
3157   DALI_TEST_EQUALS(Test::WaitForEventThreadTrigger(2), true, TEST_LOCATION);
3158
3159   application.SendNotification();
3160   application.Render(16);
3161
3162   DALI_TEST_EQUALS(gResourceReadySignalFired, true, TEST_LOCATION);
3163   DALI_TEST_EQUALS(imageView.IsResourceReady(), true, TEST_LOCATION);
3164   DALI_TEST_EQUALS(imageView.GetVisualResourceStatus(ImageView::Property::IMAGE), Visual::ResourceStatus::FAILED, TEST_LOCATION);
3165
3166   // Should be shown a broken image
3167   DALI_TEST_EQUALS(imageView.GetRendererCount(), 1u, TEST_LOCATION);
3168   DALI_TEST_EQUALS(textureTrace.FindMethod("BindTexture"), true, TEST_LOCATION);
3169
3170   END_TEST;
3171 }
3172
3173 int UtcDaliImageViewSvgChageSize(void)
3174 {
3175   ToolkitTestApplication application;
3176
3177   TestGlAbstraction& gl           = application.GetGlAbstraction();
3178   TraceCallStack&    textureTrace = gl.GetTextureTrace();
3179   textureTrace.Enable(true);
3180
3181   ImageView imageView = ImageView::New(TEST_SVG_FILE_NAME);
3182   application.GetScene().Add(imageView);
3183
3184   application.SendNotification();
3185
3186   // Wait for loading & rasterization
3187   DALI_TEST_EQUALS(Test::WaitForEventThreadTrigger(2), true, TEST_LOCATION);
3188
3189   application.SendNotification();
3190   application.Render(16);
3191
3192   DALI_TEST_EQUALS(Test::VectorImageRenderer::GetLoadCount(), 1, TEST_LOCATION);
3193
3194   // Change actor size, then rasterization should be done again
3195   imageView.SetProperty(Actor::Property::SIZE, Vector2(200.f, 200.f));
3196
3197   application.SendNotification();
3198
3199   // Wait for rasterization
3200   DALI_TEST_EQUALS(Test::WaitForEventThreadTrigger(1), true, TEST_LOCATION);
3201
3202   application.SendNotification();
3203   application.Render(16);
3204
3205   // We should not load the file again.
3206   DALI_TEST_EQUALS(Test::VectorImageRenderer::GetLoadCount(), 1, TEST_LOCATION);
3207
3208   END_TEST;
3209 }
3210
3211 int UtcDaliImageViewSvgAtlasing(void)
3212 {
3213   ToolkitTestApplication application;
3214
3215   TraceCallStack& callStack = application.GetGlAbstraction().GetTextureTrace();
3216   callStack.Reset();
3217   callStack.Enable(true);
3218
3219   Property::Map propertyMap;
3220   propertyMap["url"]      = TEST_SVG_FILE_NAME;
3221   propertyMap["atlasing"] = true;
3222
3223   ImageView imageView = ImageView::New();
3224   imageView.SetProperty(ImageView::Property::IMAGE, propertyMap);
3225   imageView.SetProperty(Actor::Property::SIZE, Vector2(100.f, 100.f));
3226   application.GetScene().Add(imageView);
3227
3228   application.SendNotification();
3229
3230   // Wait for loading & rasterization
3231   DALI_TEST_EQUALS(Test::WaitForEventThreadTrigger(2), true, TEST_LOCATION);
3232
3233   application.SendNotification();
3234   application.Render(16);
3235
3236   // use atlas
3237   TraceCallStack::NamedParams params1;
3238   params1["width"] << 100;
3239   params1["height"] << 100;
3240   DALI_TEST_EQUALS(callStack.FindMethodAndParams("TexSubImage2D", params1), true, TEST_LOCATION);
3241
3242   imageView.SetProperty(Actor::Property::SIZE, Vector2(600.f, 600.f));
3243
3244   application.SendNotification();
3245
3246   // Wait for rasterization
3247   DALI_TEST_EQUALS(Test::WaitForEventThreadTrigger(1), true, TEST_LOCATION);
3248
3249   callStack.Reset();
3250
3251   application.SendNotification();
3252   application.Render(16);
3253
3254   // not use atlas
3255   TraceCallStack::NamedParams params2;
3256   params2["width"] << 600;
3257   params2["height"] << 600;
3258   DALI_TEST_EQUALS(callStack.FindMethodAndParams("TexImage2D", params2), true, TEST_LOCATION);
3259
3260   END_TEST;
3261 }
3262
3263 int UtcDaliImageViewTVGLoading(void)
3264 {
3265   ToolkitTestApplication application;
3266
3267   tet_infoline("ImageView Testing TVG image loading");
3268
3269   {
3270     ImageView imageView = ImageView::New(TEST_RESOURCE_DIR "/test.tvg");
3271     application.GetScene().Add(imageView);
3272     DALI_TEST_CHECK(imageView);
3273
3274     application.SendNotification();
3275
3276     DALI_TEST_EQUALS(Test::WaitForEventThreadTrigger(1), true, TEST_LOCATION);
3277
3278     application.SendNotification();
3279     application.Render(16);
3280
3281     Vector3 naturalSize = imageView.GetNaturalSize();
3282
3283     DALI_TEST_EQUALS(naturalSize.width, 100.0f, TEST_LOCATION);
3284     DALI_TEST_EQUALS(naturalSize.height, 100.0f, TEST_LOCATION);
3285   }
3286   END_TEST;
3287 }
3288
3289 int UtcDaliImageViewSvgDesiredSize01(void)
3290 {
3291   ToolkitTestApplication application;
3292
3293   TestGlAbstraction& gl           = application.GetGlAbstraction();
3294   TraceCallStack&    textureTrace = gl.GetTextureTrace();
3295   textureTrace.Enable(true);
3296
3297   int       desiredWidth = 100, desiredHeight = 150;
3298   ImageView imageView = ImageView::New(TEST_SVG_FILE_NAME, ImageDimensions(desiredWidth, desiredHeight));
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   {
3311     std::stringstream out;
3312     out << GL_TEXTURE_2D << ", " << 0u << ", " << desiredWidth << ", " << desiredHeight;
3313     DALI_TEST_CHECK(textureTrace.FindMethodAndParams("TexImage2D", out.str().c_str()));
3314   }
3315
3316   END_TEST;
3317 }
3318
3319 int UtcDaliImageViewSvgDesiredSize02(void)
3320 {
3321   ToolkitTestApplication application;
3322
3323   TestGlAbstraction& gl           = application.GetGlAbstraction();
3324   TraceCallStack&    textureTrace = gl.GetTextureTrace();
3325   textureTrace.Enable(true);
3326
3327   int       desiredWidth = 150, desiredHeight = 100;
3328   ImageView imageView                   = ImageView::New();
3329   imageView[ImageView::Property::IMAGE] = Property::Map().Add("url", TEST_SVG_FILE_NAME).Add("desiredWidth", desiredWidth).Add("desiredHeight", desiredHeight);
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   {
3341     std::stringstream out;
3342     out << GL_TEXTURE_2D << ", " << 0u << ", " << desiredWidth << ", " << desiredHeight;
3343     DALI_TEST_CHECK(textureTrace.FindMethodAndParams("TexImage2D", out.str().c_str()));
3344   }
3345
3346   END_TEST;
3347 }
3348
3349 int UtcDaliImageViewImageLoadFailure01(void)
3350 {
3351   ToolkitTestApplication application;
3352
3353   Toolkit::StyleManager styleManager = Toolkit::StyleManager::Get();
3354   DevelStyleManager::SetBrokenImageUrl(styleManager, DevelStyleManager::BrokenImageType::SMALL, TEST_BROKEN_IMAGE_S);
3355   DevelStyleManager::SetBrokenImageUrl(styleManager, DevelStyleManager::BrokenImageType::NORMAL, TEST_BROKEN_IMAGE_M);
3356   DevelStyleManager::SetBrokenImageUrl(styleManager, DevelStyleManager::BrokenImageType::LARGE, TEST_BROKEN_IMAGE_L);
3357
3358   std::string brokenUrl;
3359   brokenUrl = DevelStyleManager::GetBrokenImageUrl(styleManager, DevelStyleManager::BrokenImageType::SMALL);
3360   DALI_TEST_EQUALS(TEST_BROKEN_IMAGE_S, brokenUrl, TEST_LOCATION);
3361
3362   brokenUrl = DevelStyleManager::GetBrokenImageUrl(styleManager, DevelStyleManager::BrokenImageType::NORMAL);
3363   DALI_TEST_EQUALS(TEST_BROKEN_IMAGE_M, brokenUrl, TEST_LOCATION);
3364
3365   brokenUrl = DevelStyleManager::GetBrokenImageUrl(styleManager, DevelStyleManager::BrokenImageType::LARGE);
3366   DALI_TEST_EQUALS(TEST_BROKEN_IMAGE_L, brokenUrl, TEST_LOCATION);
3367
3368   ImageView imageView = ImageView::New("invalidUrl.png");
3369   imageView.SetProperty(Actor::Property::SIZE, Vector2(200.f, 200.f));
3370
3371   application.GetScene().Add(imageView);
3372   application.SendNotification();
3373   application.Render(16);
3374
3375   // loading started, this waits for the loader thread
3376   DALI_TEST_EQUALS(Test::WaitForEventThreadTrigger(1), true, TEST_LOCATION);
3377
3378   END_TEST;
3379 }
3380
3381 int UtcDaliImageViewImageLoadFailure02(void)
3382 {
3383   ToolkitTestApplication application;
3384
3385   Toolkit::StyleManager styleManager = Toolkit::StyleManager::Get();
3386   DevelStyleManager::SetBrokenImageUrl(styleManager, DevelStyleManager::BrokenImageType::SMALL, TEST_BROKEN_IMAGE_DEFAULT);
3387   DevelStyleManager::SetBrokenImageUrl(styleManager, DevelStyleManager::BrokenImageType::NORMAL, TEST_BROKEN_IMAGE_M);
3388   DevelStyleManager::SetBrokenImageUrl(styleManager, DevelStyleManager::BrokenImageType::LARGE, TEST_BROKEN_IMAGE_L);
3389
3390   std::string brokenUrl;
3391   brokenUrl = DevelStyleManager::GetBrokenImageUrl(styleManager, DevelStyleManager::BrokenImageType::SMALL);
3392   DALI_TEST_EQUALS(TEST_BROKEN_IMAGE_DEFAULT, brokenUrl, TEST_LOCATION);
3393
3394   brokenUrl = DevelStyleManager::GetBrokenImageUrl(styleManager, DevelStyleManager::BrokenImageType::NORMAL);
3395   DALI_TEST_EQUALS(TEST_BROKEN_IMAGE_M, brokenUrl, TEST_LOCATION);
3396
3397   brokenUrl = DevelStyleManager::GetBrokenImageUrl(styleManager, DevelStyleManager::BrokenImageType::LARGE);
3398   DALI_TEST_EQUALS(TEST_BROKEN_IMAGE_L, brokenUrl, TEST_LOCATION);
3399
3400   ImageView imageView = ImageView::New("invalidUrl.png");
3401   imageView.SetProperty(Actor::Property::SIZE, Vector2(30.f, 30.f));
3402   application.GetScene().Add(imageView);
3403   application.SendNotification();
3404   application.Render(16);
3405
3406   // loading started, this waits for the loader thread
3407   DALI_TEST_EQUALS(Test::WaitForEventThreadTrigger(1), true, TEST_LOCATION);
3408
3409   END_TEST;
3410 }
3411
3412 int UtcDaliImageViewImageLoadFailure03(void)
3413 {
3414   ToolkitTestApplication application;
3415
3416   Toolkit::StyleManager styleManager = Toolkit::StyleManager::Get();
3417   DevelStyleManager::SetBrokenImageUrl(styleManager, DevelStyleManager::BrokenImageType::SMALL, TEST_BROKEN_IMAGE_01);
3418   DevelStyleManager::SetBrokenImageUrl(styleManager, DevelStyleManager::BrokenImageType::NORMAL, TEST_BROKEN_IMAGE_02);
3419
3420   std::string brokenUrl;
3421   brokenUrl = DevelStyleManager::GetBrokenImageUrl(styleManager, DevelStyleManager::BrokenImageType::SMALL);
3422   DALI_TEST_EQUALS(TEST_BROKEN_IMAGE_01, brokenUrl, TEST_LOCATION);
3423
3424   brokenUrl = DevelStyleManager::GetBrokenImageUrl(styleManager, DevelStyleManager::BrokenImageType::NORMAL);
3425   DALI_TEST_EQUALS(TEST_BROKEN_IMAGE_02, brokenUrl, TEST_LOCATION);
3426
3427   ImageView imageView = ImageView::New("invalidUrl.png");
3428   imageView.SetProperty(Actor::Property::SIZE, Vector2(100.f, 100.f));
3429   application.GetScene().Add(imageView);
3430   application.SendNotification();
3431   application.Render(16);
3432
3433   // loading started, this waits for the loader thread
3434   DALI_TEST_EQUALS(Test::WaitForEventThreadTrigger(1), true, TEST_LOCATION);
3435
3436   END_TEST;
3437 }
3438
3439 int UtcDaliImageViewImageLoadFailure04(void)
3440 {
3441   ToolkitTestApplication application;
3442
3443   ImageView imageView = ImageView::New("invalidUrl.png");
3444   imageView.SetProperty(Actor::Property::SIZE, Vector2(100.f, 100.f));
3445   application.GetScene().Add(imageView);
3446   application.SendNotification();
3447   application.Render(16);
3448
3449   // loading started, this waits for the loader thread
3450   DALI_TEST_EQUALS(Test::WaitForEventThreadTrigger(1), true, TEST_LOCATION);
3451
3452   Toolkit::StyleManager styleManager = Toolkit::StyleManager::Get();
3453   DevelStyleManager::SetBrokenImageUrl(styleManager, DevelStyleManager::BrokenImageType::SMALL, TEST_BROKEN_IMAGE_S);
3454   DevelStyleManager::SetBrokenImageUrl(styleManager, DevelStyleManager::BrokenImageType::NORMAL, "invalidBroken.png");
3455   DevelStyleManager::SetBrokenImageUrl(styleManager, DevelStyleManager::BrokenImageType::LARGE, TEST_BROKEN_IMAGE_L);
3456
3457   ImageView imageView2 = ImageView::New("invalidUrl.png");
3458   imageView2.SetProperty(Actor::Property::SIZE, Vector2(100.f, 100.f));
3459   application.GetScene().Add(imageView2);
3460
3461   std::string brokenUrl;
3462   brokenUrl = DevelStyleManager::GetBrokenImageUrl(styleManager, DevelStyleManager::BrokenImageType::SMALL);
3463   DALI_TEST_EQUALS(TEST_BROKEN_IMAGE_S, brokenUrl, TEST_LOCATION);
3464
3465   brokenUrl = DevelStyleManager::GetBrokenImageUrl(styleManager, DevelStyleManager::BrokenImageType::LARGE);
3466   DALI_TEST_EQUALS(TEST_BROKEN_IMAGE_L, brokenUrl, TEST_LOCATION);
3467
3468   application.SendNotification();
3469   application.Render(16);
3470
3471   // loading started, this waits for the loader thread
3472   DALI_TEST_EQUALS(Test::WaitForEventThreadTrigger(1), true, TEST_LOCATION);
3473
3474   DevelStyleManager::SetBrokenImageUrl(styleManager, DevelStyleManager::BrokenImageType::NORMAL, "invalidBroken.9.png");
3475
3476   ImageView imageView3 = ImageView::New("invalidUrl.png");
3477   imageView3.SetProperty(Actor::Property::SIZE, Vector2(100.f, 100.f));
3478   application.GetScene().Add(imageView3);
3479
3480   application.SendNotification();
3481   application.Render(16);
3482
3483   // loading started, this waits for the loader thread
3484   DALI_TEST_EQUALS(Test::WaitForEventThreadTrigger(1), true, TEST_LOCATION);
3485
3486   END_TEST;
3487 }
3488
3489 namespace
3490 {
3491 static int gResourceReadySignalCounter = 0;
3492
3493 void OnResourceReadySignal01(Control control)
3494 {
3495   gResourceReadySignalCounter++;
3496
3497   if(control.GetVisualResourceStatus(ImageView::Property::IMAGE) == Visual::ResourceStatus::READY)
3498   {
3499     if(gResourceReadySignalCounter == 1)
3500     {
3501       // Set image twice
3502       // It makes the first new visual be deleted immediately
3503       ImageView::DownCast(control).SetImage(gImage_34_RGBA);
3504       ImageView::DownCast(control).SetImage(gImage_34_RGBA);
3505     }
3506   }
3507   else if(control.GetVisualResourceStatus(ImageView::Property::IMAGE) == Visual::ResourceStatus::FAILED)
3508   {
3509     // Make the resource ready immediately
3510     control[ImageView::Property::IMAGE] = gImage_600_RGB;
3511   }
3512 }
3513
3514 void OnResourceReadySignal02(Control control)
3515 {
3516   if(++gResourceReadySignalCounter == 1)
3517   {
3518     // It makes the first new visual be deleted immediately
3519     // The first image will not be loaded.
3520     control[ImageView::Property::IMAGE] = Property::Map().Add(ImageVisual::Property::URL, gImage_600_RGB).Add(ImageVisual::Property::RELEASE_POLICY, ImageVisual::ReleasePolicy::NEVER);
3521     control[ImageView::Property::IMAGE] = TEST_IMAGE_1;
3522   }
3523 }
3524
3525 ImageView gImageView1;
3526 ImageView gImageView2;
3527 ImageView gImageView3;
3528 ImageView gImageView4;
3529
3530 void OnResourceReadySignal03(Control control)
3531 {
3532   if(gResourceReadySignalCounter == 0)
3533   {
3534     // Queue loading
3535     // 1. Use cached image, then LoadComplete will be called right after OnResourceReadySignal03.
3536     gImageView2[ImageView::Property::IMAGE] = gImage_34_RGBA;
3537
3538     // 2. Load a new image
3539     gImageView3[ImageView::Property::IMAGE] = TEST_IMAGE_1;
3540
3541     // 3. Use the new image again
3542     gImageView1[ImageView::Property::IMAGE] = TEST_IMAGE_1;
3543     gImageView1.ResourceReadySignal().Connect(&OnResourceReadySignal03);
3544   }
3545   else if(gResourceReadySignalCounter == 1)
3546   {
3547     // This is called from TextureManager::ProcessQueuedTextures().
3548     gImageView1.Unparent();
3549     gImageView1.Reset();
3550   }
3551   gResourceReadySignalCounter++;
3552 }
3553
3554 void OnSimpleResourceReadySignal(Control control)
3555 {
3556   // simply increate counter
3557   gResourceReadySignalCounter++;
3558 }
3559
3560 int gResourceReadySignal04ComesOrder = 0;
3561
3562 void OnResourceReadySignal04(Control control)
3563 {
3564   gResourceReadySignalCounter++;
3565   tet_printf("rc %d\n", gResourceReadySignalCounter);
3566   if(gResourceReadySignalCounter == 1)
3567   {
3568     auto scene = gImageView1.GetParent();
3569
3570     // Request load something
3571     // We hope this request result is return later than gImageView2.
3572     gImageView3 = ImageView::New(TEST_IMAGE_1);
3573     gImageView3.ResourceReadySignal().Connect(&OnResourceReadySignal04);
3574     scene.Add(gImageView3);
3575     gImageView4 = ImageView::New(TEST_IMAGE_2);
3576     gImageView4.ResourceReadySignal().Connect(&OnResourceReadySignal04);
3577     scene.Add(gImageView4);
3578
3579     if(control == gImageView1)
3580     {
3581       gResourceReadySignal04ComesOrder = 1;
3582     }
3583     else
3584     {
3585       gResourceReadySignal04ComesOrder = 2;
3586     }
3587   }
3588   if(gResourceReadySignalCounter == 2)
3589   {
3590     if(gResourceReadySignal04ComesOrder == 1 && control == gImageView2)
3591     {
3592       // Scene off first one.
3593       gImageView1.Unparent();
3594
3595       // Scene off second one.
3596       gImageView2.Unparent();
3597     }
3598     else if(gResourceReadySignal04ComesOrder == 2 && control == gImageView1)
3599     {
3600       // Scene off first one.
3601       gImageView2.Unparent();
3602
3603       // Scene off second one.
3604       gImageView1.Unparent();
3605     }
3606     else
3607     {
3608       // We can't check that this utc fail case. just pass always when we come here.
3609       gResourceReadySignal04ComesOrder = -1;
3610     }
3611
3612     // If we don't seperate index of FreeList area
3613     // and if we don't queue remove during obversing,
3614     // cache index become something invalid data.
3615     // In this case, some strange observer can be called.
3616     // For example, gImageView4.LoadComplete will be called.
3617   }
3618 }
3619
3620 void OnResourceReadySignal05(Control control)
3621 {
3622   gResourceReadySignalCounter++;
3623
3624   // Request load with same image
3625   // NOTE : The url must not be same as gImageView1
3626   const int viewCount = 4;
3627   for(int i = 0; i < viewCount; ++i)
3628   {
3629     gImageView1.Add(ImageView::New("invalid2.jpg"));
3630   }
3631 }
3632
3633 int gResourceReadySignal06ComesOrder = 0;
3634
3635 void OnResourceReadySignal06(Control control)
3636 {
3637   gResourceReadySignalCounter++;
3638   if(gResourceReadySignalCounter == 1)
3639   {
3640     auto scene = gImageView1.GetParent();
3641
3642     // Request load something
3643     // We hope this request result is return later than gImageView2.
3644
3645     Property::Map map1;
3646     map1[Toolkit::ImageVisual::Property::URL]            = TEST_IMAGE_1;
3647     map1[Toolkit::ImageVisual::Property::ALPHA_MASK_URL] = TEST_BROKEN_IMAGE_DEFAULT;
3648
3649     gImageView3 = ImageView::New();
3650     gImageView3.SetProperty(Toolkit::ImageView::Property::IMAGE, map1);
3651     gImageView3.ResourceReadySignal().Connect(&OnResourceReadySignal06);
3652
3653     Property::Map map2;
3654     map2[Toolkit::ImageVisual::Property::URL]            = TEST_IMAGE_2;
3655     map2[Toolkit::ImageVisual::Property::ALPHA_MASK_URL] = TEST_BROKEN_IMAGE_S;
3656     gImageView4                                          = ImageView::New();
3657     gImageView4.SetProperty(Toolkit::ImageView::Property::IMAGE, map2);
3658     gImageView4.ResourceReadySignal().Connect(&OnResourceReadySignal06);
3659
3660     if(control == gImageView1)
3661     {
3662       gResourceReadySignal06ComesOrder = 1;
3663     }
3664     else
3665     {
3666       gResourceReadySignal06ComesOrder = 2;
3667     }
3668   }
3669   if(gResourceReadySignalCounter == 2)
3670   {
3671     if(gResourceReadySignal06ComesOrder == 1 && control == gImageView2)
3672     {
3673       // Scene off first one.
3674       gImageView1.Unparent();
3675
3676       // Scene off second one.
3677       gImageView2.Unparent();
3678     }
3679     else if(gResourceReadySignal06ComesOrder == 2 && control == gImageView1)
3680     {
3681       // Scene off first one.
3682       gImageView2.Unparent();
3683
3684       // Scene off second one.
3685       gImageView1.Unparent();
3686     }
3687     else
3688     {
3689       // We can't check that this utc fail case. just pass always when we come here.
3690       gResourceReadySignal06ComesOrder = -1;
3691     }
3692
3693     // If we don't seperate index of FreeList area
3694     // and if we don't queue remove during obversing,
3695     // cache index become something invalid data.
3696     // In this case, some strange observer can be called.
3697     // For example, gImageView4.LoadComplete will be called.
3698   }
3699 }
3700
3701 void OnResourceReadySignal07(Control control)
3702 {
3703   gResourceReadySignalCounter++;
3704   // Load masked image
3705   tet_printf("rc %d %d\n", gResourceReadySignalCounter, static_cast<bool>(gImageView2));
3706
3707   if(!gImageView2)
3708   {
3709     auto scene = gImageView1.GetParent();
3710
3711     Property::Map map1;
3712     map1[Toolkit::ImageVisual::Property::URL]            = TEST_IMAGE_1;
3713     map1[Toolkit::ImageVisual::Property::ALPHA_MASK_URL] = TEST_BROKEN_IMAGE_DEFAULT;
3714
3715     gImageView2 = ImageView::New();
3716     gImageView2.SetProperty(Toolkit::ImageView::Property::IMAGE, map1);
3717     gImageView2.ResourceReadySignal().Connect(&OnResourceReadySignal07);
3718
3719     scene.Add(gImageView2);
3720   }
3721 }
3722
3723 void OnResourceReadySignal08(Control control)
3724 {
3725   gResourceReadySignalCounter++;
3726
3727   if(gImageView1)
3728   {
3729     gImageView1.Unparent();
3730     gImageView1.Reset();
3731   }
3732   if(gImageView2)
3733   {
3734     gImageView2.Unparent();
3735     gImageView2.Reset();
3736   }
3737 }
3738
3739 std::size_t gResourceReadySignal09Emitted = false;
3740
3741 void OnResourceReadySignal09(Control control)
3742 {
3743   gResourceReadySignalCounter++;
3744
3745   if(gImageView1 && !gResourceReadySignal09Emitted)
3746   {
3747     gResourceReadySignal09Emitted = true;
3748     gImageView1.ResourceReadySignal().Disconnect(&OnResourceReadySignal09);
3749
3750     // Try to load cached invalid nine patch image. It will request load now.
3751     gImageView1.SetImage(TEST_INVALID_NPATCH_FILE_NAME_01);
3752     gImageView2.SetImage(TEST_INVALID_NPATCH_FILE_NAME_01);
3753
3754     // Destroy all visuals immediatly.
3755     gImageView1.Unparent();
3756     gImageView1.Reset();
3757     gImageView2.Unparent();
3758     gImageView2.Reset();
3759   }
3760 }
3761 constexpr int gResourceReadySignal10MaxCounter = 5;
3762
3763 void OnResourceReadySignal10(Control control)
3764 {
3765   gResourceReadySignalCounter++;
3766
3767   tet_printf("OnResourceReadySignal10 comes!\n");
3768   if(gResourceReadySignalCounter < gResourceReadySignal10MaxCounter)
3769   {
3770     tet_printf("OnResourceReadySignal10 Set image\n");
3771     gImageView1.SetProperty(Toolkit::ImageView::Property::IMAGE, gImage_34_RGBA);
3772     tet_printf("OnResourceReadySignal10 Set image done\n");
3773   }
3774 }
3775
3776 } // namespace
3777
3778 int UtcDaliImageViewSetImageOnResourceReadySignal01(void)
3779 {
3780   tet_infoline("Test setting image from within signal handler.");
3781
3782   ToolkitTestApplication application;
3783
3784   gResourceReadySignalCounter = 0;
3785
3786   ImageView imageView = ImageView::New(gImage_34_RGBA);
3787   imageView.ResourceReadySignal().Connect(&OnResourceReadySignal01);
3788
3789   application.GetScene().Add(imageView);
3790
3791   DALI_TEST_EQUALS(Test::WaitForEventThreadTrigger(1), true, TEST_LOCATION);
3792
3793   application.SendNotification();
3794   application.Render();
3795
3796   DALI_TEST_EQUALS(gResourceReadySignalCounter, 2, TEST_LOCATION);
3797
3798   DALI_TEST_EQUALS(imageView.IsResourceReady(), true, TEST_LOCATION);
3799
3800   // Create a new ImageView to cache the image
3801   ImageView imageView1 = ImageView::New(gImage_600_RGB);
3802   application.GetScene().Add(imageView1);
3803
3804   DALI_TEST_EQUALS(Test::WaitForEventThreadTrigger(1), true, TEST_LOCATION);
3805
3806   application.SendNotification();
3807   application.Render();
3808
3809   // Reset count
3810   gResourceReadySignalCounter = 0;
3811
3812   imageView[ImageView::Property::IMAGE] = "invalid.jpg";
3813
3814   DALI_TEST_EQUALS(Test::WaitForEventThreadTrigger(1), true, TEST_LOCATION);
3815
3816   application.SendNotification();
3817   application.Render();
3818
3819   // Run idle callback
3820   application.RunIdles();
3821
3822   DALI_TEST_EQUALS(gResourceReadySignalCounter, 2, TEST_LOCATION);
3823
3824   DALI_TEST_EQUALS(imageView.IsResourceReady(), true, TEST_LOCATION);
3825
3826   END_TEST;
3827 }
3828
3829 int UtcDaliImageViewSetImageOnResourceReadySignal02(void)
3830 {
3831   tet_infoline("Test setting image from within signal handler.");
3832
3833   ToolkitTestApplication application;
3834
3835   gResourceReadySignalCounter = 0;
3836
3837   ImageView imageView = ImageView::New(gImage_34_RGBA);
3838   imageView.ResourceReadySignal().Connect(&OnResourceReadySignal02);
3839
3840   application.GetScene().Add(imageView);
3841
3842   DALI_TEST_EQUALS(Test::WaitForEventThreadTrigger(1), true, TEST_LOCATION);
3843
3844   application.SendNotification();
3845   application.Render();
3846
3847   // Wait for loading an image
3848   DALI_TEST_EQUALS(Test::WaitForEventThreadTrigger(1), true, TEST_LOCATION);
3849
3850   DALI_TEST_EQUALS(gResourceReadySignalCounter, 2, TEST_LOCATION);
3851
3852   DALI_TEST_EQUALS(imageView.IsResourceReady(), true, TEST_LOCATION);
3853
3854   END_TEST;
3855 }
3856
3857 int UtcDaliImageViewSetImageOnResourceReadySignal03(void)
3858 {
3859   tet_infoline("Test setting image from within signal handler.");
3860
3861   ToolkitTestApplication application;
3862
3863   gResourceReadySignalCounter = 0;
3864
3865   gImageView1 = ImageView::New(gImage_34_RGBA);
3866   application.GetScene().Add(gImageView1);
3867
3868   // Wait for loading
3869   DALI_TEST_EQUALS(Test::WaitForEventThreadTrigger(1), true, TEST_LOCATION);
3870
3871   gImageView2 = ImageView::New(gImage_600_RGB);
3872   gImageView2.ResourceReadySignal().Connect(&OnResourceReadySignal03);
3873   application.GetScene().Add(gImageView2);
3874
3875   gImageView3 = ImageView::New();
3876   application.GetScene().Add(gImageView3);
3877
3878   DALI_TEST_EQUALS(Test::WaitForEventThreadTrigger(2), true, TEST_LOCATION);
3879
3880   application.SendNotification();
3881   application.Render();
3882
3883   END_TEST;
3884 }
3885
3886 int UtcDaliImageViewOnResourceReadySignalWithBrokenAlphaMask01(void)
3887 {
3888   tet_infoline("Test signal handler when image / mask image is broken.");
3889
3890   ToolkitTestApplication application;
3891
3892   auto TestResourceReadyUrl = [&application](int eventTriggerCount, bool isSynchronous, const std::string& url, const std::string& mask, const char* location) {
3893     gResourceReadySignalCounter = 0;
3894
3895     Property::Map map;
3896     map[Toolkit::ImageVisual::Property::URL] = url;
3897     if(!mask.empty())
3898     {
3899       map[Toolkit::ImageVisual::Property::ALPHA_MASK_URL] = mask;
3900     }
3901     map[Toolkit::ImageVisual::Property::SYNCHRONOUS_LOADING] = isSynchronous;
3902
3903     ImageView imageView                            = ImageView::New();
3904     imageView[Toolkit::ImageView::Property::IMAGE] = map;
3905     imageView[Actor::Property::SIZE]               = Vector2(100.0f, 200.0f);
3906     imageView.ResourceReadySignal().Connect(&OnSimpleResourceReadySignal);
3907
3908     application.GetScene().Add(imageView);
3909     application.SendNotification();
3910     application.Render();
3911
3912     if(!isSynchronous)
3913     {
3914       // Wait for loading
3915       DALI_TEST_EQUALS(Test::WaitForEventThreadTrigger(eventTriggerCount), true, location);
3916     }
3917     tet_printf("test %s [sync:%d] signal fired\n", url.c_str(), isSynchronous ? 1 : 0);
3918     DALI_TEST_EQUALS(gResourceReadySignalCounter, 1, location);
3919
3920     imageView.Unparent();
3921   };
3922
3923   for(int synchronous = 0; synchronous <= 1; synchronous++)
3924   {
3925     tet_printf("Test normal case (sync:%d)\n", synchronous);
3926     TestResourceReadyUrl(1, synchronous, gImage_600_RGB, "", TEST_LOCATION);
3927     TestResourceReadyUrl(3, synchronous, gImage_600_RGB, gImage_34_RGBA, TEST_LOCATION); // 3 event trigger required : 2 image load + 1 apply mask
3928
3929     tet_printf("Test broken image case (sync:%d)\n", synchronous);
3930     TestResourceReadyUrl(1, synchronous, "invalid.jpg", "", TEST_LOCATION);
3931     TestResourceReadyUrl(2, synchronous, "invalid.jpg", gImage_34_RGBA, TEST_LOCATION);
3932
3933     tet_printf("Test broken mask image case (sync:%d)\n", synchronous);
3934     TestResourceReadyUrl(2, synchronous, gImage_600_RGB, "invalid.png", TEST_LOCATION);
3935
3936     tet_printf("Test broken both image, mask image case (sync:%d)\n", synchronous);
3937     TestResourceReadyUrl(2, synchronous, "invalid.jpg", "invalid.png", TEST_LOCATION);
3938   }
3939
3940   END_TEST;
3941 }
3942
3943 int UtcDaliImageViewOnResourceReadySignalWithBrokenAlphaMask02(void)
3944 {
3945   tet_infoline("Test signal handler when image try to use cached-and-broken mask image.");
3946
3947   ToolkitTestApplication application;
3948
3949   gResourceReadySignalCounter = 0;
3950
3951   auto TestBrokenMaskResourceReadyUrl = [&application](const std::string& url, const char* location) {
3952     Property::Map map;
3953     map[Toolkit::ImageVisual::Property::URL] = url;
3954     // Use invalid mask url
3955     map[Toolkit::ImageVisual::Property::ALPHA_MASK_URL] = "invalid.png";
3956
3957     ImageView imageView                            = ImageView::New();
3958     imageView[Toolkit::ImageView::Property::IMAGE] = map;
3959     imageView[Actor::Property::SIZE]               = Vector2(100.0f, 200.0f);
3960     imageView.ResourceReadySignal().Connect(&OnSimpleResourceReadySignal);
3961
3962     application.GetScene().Add(imageView);
3963
3964     // Don't unparent imageView, for keep the cache.
3965   };
3966
3967   // Use more than 4 images (The number of LocalImageLoadThread)
3968   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};
3969
3970   int expectResourceReadySignalCounter = 0;
3971
3972   for(auto& url : testUrlList)
3973   {
3974     TestBrokenMaskResourceReadyUrl(url, TEST_LOCATION);
3975     expectResourceReadySignalCounter++;
3976   }
3977
3978   // Remain 1 signal due to we use #URL + 1 mask image.
3979   DALI_TEST_EQUALS(Test::WaitForEventThreadTrigger(expectResourceReadySignalCounter + 1), true, TEST_LOCATION);
3980   application.SendNotification();
3981   application.Render();
3982   DALI_TEST_EQUALS(gResourceReadySignalCounter, expectResourceReadySignalCounter, TEST_LOCATION);
3983
3984   END_TEST;
3985 }
3986
3987 int UtcDaliImageViewCheckVariousCaseSendOnResourceReadySignal(void)
3988 {
3989   tet_infoline("Test signal handler various case.");
3990
3991   auto TestResourceReadyUrl = [](int eventTriggerCount, bool isSynchronous, bool loadSuccess, const std::string& url, const std::string& mask, const char* location) {
3992     ToolkitTestApplication application;
3993
3994     gResourceReadySignalCounter = 0;
3995
3996     Property::Map map;
3997     map[Toolkit::ImageVisual::Property::URL] = url;
3998     if(!mask.empty())
3999     {
4000       map[Toolkit::ImageVisual::Property::ALPHA_MASK_URL] = mask;
4001     }
4002     map[Toolkit::ImageVisual::Property::SYNCHRONOUS_LOADING] = isSynchronous;
4003
4004     ImageView imageView                            = ImageView::New();
4005     imageView[Toolkit::ImageView::Property::IMAGE] = map;
4006     imageView[Actor::Property::SIZE]               = Vector2(100.0f, 200.0f);
4007     imageView.ResourceReadySignal().Connect(&OnSimpleResourceReadySignal);
4008
4009     application.GetScene().Add(imageView);
4010     application.SendNotification();
4011     application.Render();
4012
4013     // Wait for loading
4014     DALI_TEST_EQUALS(Test::WaitForEventThreadTrigger(eventTriggerCount), true, location);
4015
4016     tet_printf("test %s [sync:%d] signal fired\n", url.c_str(), isSynchronous ? 1 : 0);
4017     DALI_TEST_EQUALS(gResourceReadySignalCounter, 1, location);
4018     DALI_TEST_EQUALS(imageView.GetVisualResourceStatus(Toolkit::ImageView::Property::IMAGE), loadSuccess ? Toolkit::Visual::ResourceStatus::READY : Toolkit::Visual::ResourceStatus::FAILED, location);
4019
4020     imageView.Unparent();
4021   };
4022
4023   auto TestAuxiliaryResourceReadyUrl = [](bool isSynchronous, bool loadSuccess, const std::string& url, const std::string& auxiliaryUrl, const char* location) {
4024     ToolkitTestApplication application;
4025
4026     gResourceReadySignalCounter = 0;
4027
4028     Property::Map map;
4029     map[Toolkit::ImageVisual::Property::URL]                        = url;
4030     map[Toolkit::DevelImageVisual::Property::AUXILIARY_IMAGE]       = auxiliaryUrl;
4031     map[Toolkit::DevelImageVisual::Property::AUXILIARY_IMAGE_ALPHA] = 0.5f;
4032     map[Toolkit::ImageVisual::Property::SYNCHRONOUS_LOADING]        = isSynchronous;
4033
4034     ImageView imageView = ImageView::New();
4035     imageView.SetProperty(Toolkit::ImageView::Property::IMAGE, map);
4036     imageView.SetProperty(Actor::Property::SIZE, Vector2(100.0f, 200.0f));
4037     imageView.ResourceReadySignal().Connect(&OnSimpleResourceReadySignal);
4038     application.GetScene().Add(imageView);
4039
4040     application.SendNotification();
4041     application.Render();
4042
4043     if(!isSynchronous)
4044     {
4045       // Wait for loading
4046       DALI_TEST_EQUALS(Test::WaitForEventThreadTrigger(2), true, location);
4047     }
4048
4049     tet_printf("test %s [sync:%d] signal fired\n", url.c_str(), isSynchronous ? 1 : 0);
4050     DALI_TEST_EQUALS(gResourceReadySignalCounter, 1, location);
4051     DALI_TEST_EQUALS(imageView.GetVisualResourceStatus(Toolkit::ImageView::Property::IMAGE), loadSuccess ? Toolkit::Visual::ResourceStatus::READY : Toolkit::Visual::ResourceStatus::FAILED, TEST_LOCATION);
4052
4053     imageView.Unparent();
4054   };
4055
4056   // Case 1 : asynchronous loading
4057   tet_printf("Test invalid single simple image Asynchronous\n");
4058
4059   // Test normal case
4060   TestResourceReadyUrl(1, 0, 1, gImage_600_RGB, "", TEST_LOCATION);
4061   TestResourceReadyUrl(2, 0, 1, TEST_SVG_FILE_NAME, "", TEST_LOCATION); // load & rasterize
4062   TestResourceReadyUrl(1, 0, 1, TEST_BROKEN_IMAGE_L, "", TEST_LOCATION);
4063
4064   TestResourceReadyUrl(2, 0, 1, TEST_GIF_FILE_NAME, "", TEST_LOCATION);                   // 2 image loading - batch size
4065   TestResourceReadyUrl(2, 0, 1, TEST_ANIMATED_VECTOR_IMAGE_FILE_NAME, "", TEST_LOCATION); // load & rasterize
4066
4067   TestResourceReadyUrl(3, 0, 1, gImage_600_RGB, gImage_34_RGBA, TEST_LOCATION); // 2 image loading + 1 applymask
4068
4069   TestAuxiliaryResourceReadyUrl(0, 1, TEST_BROKEN_IMAGE_L, gImage_34_RGBA, TEST_LOCATION);
4070
4071   // Test broken case
4072   TestResourceReadyUrl(1, 0, 0, "invalid.jpg", "", TEST_LOCATION);
4073   TestResourceReadyUrl(1, 0, 0, "invalid.svg", "", TEST_LOCATION);
4074   TestResourceReadyUrl(1, 0, 0, "invalid.9.png", "", TEST_LOCATION);
4075   TestResourceReadyUrl(1, 0, 0, "invalid.gif", "", TEST_LOCATION);  // 1 image loading
4076   TestResourceReadyUrl(1, 0, 0, "invalid.json", "", TEST_LOCATION); // 0 rasterize
4077
4078   TestResourceReadyUrl(2, 0, 0, "invalid.jpg", "invalid.png", TEST_LOCATION);  // 2 image loading
4079   TestResourceReadyUrl(2, 0, 1, gImage_600_RGB, "invalid.png", TEST_LOCATION); // 2 image loading
4080   TestResourceReadyUrl(2, 0, 0, "invalid.jpg", gImage_34_RGBA, TEST_LOCATION); // 2 image loading
4081
4082   TestAuxiliaryResourceReadyUrl(0, 0, "invalid.9.png", "invalid.png", TEST_LOCATION);
4083   TestAuxiliaryResourceReadyUrl(0, 1, TEST_BROKEN_IMAGE_L, "invalid.png", TEST_LOCATION);
4084   TestAuxiliaryResourceReadyUrl(0, 0, "invalid.9.png", gImage_34_RGBA, TEST_LOCATION);
4085
4086   // Case 2 : Synchronous loading
4087   tet_printf("Test invalid single simple image Synchronous\n");
4088
4089   // Test normal case
4090   TestResourceReadyUrl(0, 1, 1, gImage_600_RGB, "", TEST_LOCATION);
4091   TestResourceReadyUrl(0, 1, 1, TEST_SVG_FILE_NAME, "", TEST_LOCATION); // synchronous rasterize
4092   TestResourceReadyUrl(0, 1, 1, TEST_BROKEN_IMAGE_L, "", TEST_LOCATION);
4093
4094   TestResourceReadyUrl(1, 1, 1, TEST_GIF_FILE_NAME, "", TEST_LOCATION); // first frame image loading sync + second frame image loading async
4095
4096   TestResourceReadyUrl(0, 1, 1, gImage_600_RGB, gImage_34_RGBA, TEST_LOCATION);
4097
4098   TestAuxiliaryResourceReadyUrl(1, 1, TEST_BROKEN_IMAGE_L, gImage_34_RGBA, TEST_LOCATION);
4099
4100   // Test broken case
4101   TestResourceReadyUrl(0, 1, 0, "invalid.jpg", "", TEST_LOCATION);
4102   TestResourceReadyUrl(0, 1, 0, "invalid.svg", "", TEST_LOCATION);
4103   TestResourceReadyUrl(0, 1, 0, "invalid.9.png", "", TEST_LOCATION);
4104   TestResourceReadyUrl(0, 1, 0, "invalid.gif", "", TEST_LOCATION);
4105
4106   TestResourceReadyUrl(0, 1, 0, "invalid.jpg", "invalid.png", TEST_LOCATION);
4107   TestResourceReadyUrl(0, 1, 1, gImage_600_RGB, "invalid.png", TEST_LOCATION);
4108   TestResourceReadyUrl(0, 1, 0, "invalid.jpg", gImage_34_RGBA, TEST_LOCATION);
4109
4110   TestAuxiliaryResourceReadyUrl(1, 0, "invalid.9.png", "invalid.png", TEST_LOCATION);
4111   TestAuxiliaryResourceReadyUrl(1, 1, TEST_BROKEN_IMAGE_L, "invalid.png", TEST_LOCATION);
4112   TestAuxiliaryResourceReadyUrl(1, 0, "invalid.9.png", gImage_34_RGBA, TEST_LOCATION);
4113
4114   END_TEST;
4115 }
4116
4117 int UtcDaliImageViewSetImageOnResourceReadySignal04(void)
4118 {
4119   tet_infoline("Test texturemanager's remove queue works well within signal handler.");
4120
4121   ToolkitTestApplication application;
4122
4123   gResourceReadySignalCounter      = 0;
4124   gResourceReadySignal04ComesOrder = 0;
4125
4126   gImageView1 = ImageView::New("invalid.jpg"); // request invalid image, to make loading failed fast.
4127   gImageView1.ResourceReadySignal().Connect(&OnResourceReadySignal04);
4128   application.GetScene().Add(gImageView1);
4129
4130   gImageView2 = ImageView::New("invalid.png"); // request invalid image, to make loading failed fast.
4131   gImageView2.ResourceReadySignal().Connect(&OnResourceReadySignal04);
4132   application.GetScene().Add(gImageView2);
4133
4134   application.SendNotification();
4135   application.Render();
4136
4137   tet_infoline("Try to load 2 invalid image");
4138
4139   DALI_TEST_EQUALS(Test::WaitForEventThreadTrigger(2), true, TEST_LOCATION);
4140   DALI_TEST_EQUALS(gResourceReadySignalCounter, 2, TEST_LOCATION);
4141
4142   tet_infoline("load done");
4143
4144   // We can test this UTC only if gImageView1 and gImageView2 loaded done.
4145   if(gResourceReadySignal04ComesOrder == -1)
4146   {
4147     tet_infoline("Bad news.. gImageView3 or gImageView4 loaded faster than others. just skip this UTC");
4148   }
4149   else
4150   {
4151     // gImageView3 and gImageView4 load must not be successed yet.
4152     DALI_TEST_EQUALS(gImageView3.GetRendererCount(), 0u, TEST_LOCATION);
4153     DALI_TEST_EQUALS(gImageView4.GetRendererCount(), 0u, TEST_LOCATION);
4154
4155     application.SendNotification();
4156     application.Render();
4157
4158     tet_infoline("Try to load 2 valid image");
4159
4160     DALI_TEST_EQUALS(Test::WaitForEventThreadTrigger(2), true, TEST_LOCATION);
4161     DALI_TEST_EQUALS(gResourceReadySignalCounter, 4, TEST_LOCATION);
4162
4163     tet_infoline("load done");
4164
4165     // gImageView3 and gImageView4 load must be successed now.
4166     DALI_TEST_EQUALS(gImageView3.GetRendererAt(0).GetTextures().GetTextureCount(), 1u, TEST_LOCATION);
4167     DALI_TEST_EQUALS(gImageView4.GetRendererAt(0).GetTextures().GetTextureCount(), 1u, TEST_LOCATION);
4168   }
4169
4170   END_TEST;
4171 }
4172 int UtcDaliImageViewSetImageOnResourceReadySignal05(void)
4173 {
4174   tet_infoline("Test multiple views with same image during ResourceReady load the image only 1 times");
4175
4176   ToolkitTestApplication application;
4177
4178   gResourceReadySignalCounter = 0;
4179
4180   gImageView1 = ImageView::New("invalid.jpg"); // request invalid image, to make loading failed fast.
4181   gImageView1.ResourceReadySignal().Connect(&OnResourceReadySignal05);
4182   application.GetScene().Add(gImageView1);
4183
4184   application.SendNotification();
4185   application.Render();
4186
4187   tet_infoline("Try to load 1 invalid.jpg image");
4188   DALI_TEST_EQUALS(Test::WaitForEventThreadTrigger(1), true, TEST_LOCATION);
4189   DALI_TEST_EQUALS(gResourceReadySignalCounter, 1, TEST_LOCATION);
4190
4191   tet_infoline("Try to load 1 invalid2.jpg image");
4192   DALI_TEST_EQUALS(Test::WaitForEventThreadTrigger(1), true, TEST_LOCATION);
4193
4194   tet_infoline("Now we don't have any image to be loaded. Check event thread trigger failed.");
4195   DALI_TEST_EQUALS(Test::WaitForEventThreadTrigger(1, 1), false, TEST_LOCATION);
4196
4197   gImageView1.Unparent();
4198   gImageView1.Reset();
4199
4200   END_TEST;
4201 }
4202 int UtcDaliImageViewSetImageOnResourceReadySignal06(void)
4203 {
4204   tet_infoline("Test texturemanager's remove image & mask queue works well within signal handler.");
4205
4206   ToolkitTestApplication application;
4207
4208   gResourceReadySignalCounter      = 0;
4209   gResourceReadySignal06ComesOrder = 0;
4210
4211   Property::Map map;
4212   map[Toolkit::ImageVisual::Property::URL]            = "invalid.jpg";
4213   map[Toolkit::ImageVisual::Property::ALPHA_MASK_URL] = "invalid.png";
4214
4215   gImageView1 = ImageView::New(); // request invalid image, to make loading failed fast.
4216   gImageView1.SetProperty(Toolkit::ImageView::Property::IMAGE, map);
4217   gImageView1.ResourceReadySignal().Connect(&OnResourceReadySignal06);
4218   application.GetScene().Add(gImageView1);
4219
4220   gImageView2 = ImageView::New(); // request invalid image, to make loading failed fast.
4221   gImageView2.SetProperty(Toolkit::ImageView::Property::IMAGE, map);
4222   gImageView2.ResourceReadySignal().Connect(&OnResourceReadySignal06);
4223   application.GetScene().Add(gImageView2);
4224
4225   application.SendNotification();
4226   application.Render();
4227
4228   tet_infoline("Try to load 2 invalid image");
4229
4230   DALI_TEST_EQUALS(Test::WaitForEventThreadTrigger(2), true, TEST_LOCATION);
4231   DALI_TEST_EQUALS(gResourceReadySignalCounter, 2, TEST_LOCATION);
4232
4233   tet_infoline("load done");
4234
4235   // We can test this UTC only if gImageView1 and gImageView2 loaded done.
4236   if(gResourceReadySignal06ComesOrder == -1)
4237   {
4238     tet_infoline("Bad news.. gImageView3 or gImageView4 loaded faster than others. just skip this UTC");
4239   }
4240   else
4241   {
4242     // gImageView3 and gImageView4 load must not be successed yet.
4243     DALI_TEST_EQUALS(gImageView3.GetRendererCount(), 0u, TEST_LOCATION);
4244     DALI_TEST_EQUALS(gImageView4.GetRendererCount(), 0u, TEST_LOCATION);
4245
4246     application.GetScene().Add(gImageView3);
4247     application.GetScene().Add(gImageView4);
4248     application.SendNotification();
4249     application.Render();
4250
4251     tet_infoline("Try to load 2 valid image");
4252
4253     DALI_TEST_EQUALS(Test::WaitForEventThreadTrigger(2), true, TEST_LOCATION);
4254     DALI_TEST_EQUALS(gResourceReadySignalCounter, 2, TEST_LOCATION);
4255
4256     tet_infoline("load done");
4257   }
4258   END_TEST;
4259 }
4260
4261 int UtcDaliImageViewSetImageOnResourceReadySignal07(void)
4262 {
4263   tet_infoline("Test texturemanager's remove image & mask queue works well within signal handler 02.");
4264
4265   ToolkitTestApplication application;
4266
4267   gResourceReadySignalCounter = 0;
4268
4269   Property::Map map;
4270   map[Toolkit::ImageVisual::Property::URL] = TEST_IMAGE_1;
4271
4272   // Clear image view for clear test
4273
4274   if(gImageView1)
4275   {
4276     gImageView1.Reset();
4277   }
4278   if(gImageView2)
4279   {
4280     gImageView2.Reset();
4281   }
4282
4283   gImageView1 = ImageView::New();
4284   gImageView1.SetProperty(Toolkit::ImageView::Property::IMAGE, map);
4285   gImageView1.ResourceReadySignal().Connect(&OnResourceReadySignal07);
4286   application.GetScene().Add(gImageView1);
4287
4288   application.SendNotification();
4289   application.Render();
4290
4291   // Load gImageView1
4292
4293   DALI_TEST_EQUALS(Test::WaitForEventThreadTrigger(1), true, TEST_LOCATION);
4294   DALI_TEST_EQUALS(gResourceReadySignalCounter, 1, TEST_LOCATION);
4295
4296   tet_infoline("load image1 done");
4297
4298   // Load gImageView2 and mask
4299
4300   DALI_TEST_EQUALS(Test::WaitForEventThreadTrigger(2), true, TEST_LOCATION);
4301   DALI_TEST_EQUALS(gResourceReadySignalCounter, 1, TEST_LOCATION);
4302
4303   // gImageView2 mask apply done
4304
4305   DALI_TEST_EQUALS(Test::WaitForEventThreadTrigger(1), true, TEST_LOCATION);
4306   DALI_TEST_EQUALS(gResourceReadySignalCounter, 2, TEST_LOCATION);
4307
4308   tet_infoline("load image2 done");
4309   END_TEST;
4310 }
4311
4312 int UtcDaliImageViewSetImageOnResourceReadySignal08(void)
4313 {
4314   tet_infoline("Test remove npatch images during resource ready");
4315
4316   ToolkitTestApplication application;
4317
4318   gResourceReadySignalCounter = 0;
4319
4320   Property::Map map;
4321   map[Toolkit::ImageVisual::Property::URL] = TEST_BROKEN_IMAGE_M;
4322
4323   // Clear image view for clear test
4324
4325   if(gImageView1)
4326   {
4327     gImageView1.Reset();
4328   }
4329   if(gImageView2)
4330   {
4331     gImageView2.Reset();
4332   }
4333
4334   // Case 1 : Remove all images during resource ready.
4335   try
4336   {
4337     gImageView1 = ImageView::New();
4338     gImageView1.SetProperty(Toolkit::ImageView::Property::IMAGE, map);
4339     gImageView1.ResourceReadySignal().Connect(&OnResourceReadySignal08);
4340     application.GetScene().Add(gImageView1);
4341
4342     application.SendNotification();
4343     application.Render();
4344
4345     // Load gImageView1
4346     DALI_TEST_EQUALS(Test::WaitForEventThreadTrigger(1), true, TEST_LOCATION);
4347     DALI_TEST_EQUALS(gResourceReadySignalCounter, 1, TEST_LOCATION);
4348
4349     application.SendNotification();
4350     application.Render();
4351
4352     DALI_TEST_CHECK(true);
4353   }
4354   catch(...)
4355   {
4356     // Exception should not happened
4357     DALI_TEST_CHECK(false);
4358   }
4359
4360   // Clear cache.
4361   application.SendNotification();
4362   application.Render();
4363
4364   gResourceReadySignalCounter = 0;
4365
4366   // Case 2 : Remove all images when we use cached resource.
4367   try
4368   {
4369     gImageView1 = ImageView::New();
4370     gImageView1.SetProperty(Toolkit::ImageView::Property::IMAGE, map);
4371     gImageView1.ResourceReadySignal().Connect(&OnSimpleResourceReadySignal);
4372     application.GetScene().Add(gImageView1);
4373
4374     application.SendNotification();
4375     application.Render();
4376
4377     // Load gImageView1
4378     DALI_TEST_EQUALS(Test::WaitForEventThreadTrigger(1), true, TEST_LOCATION);
4379     DALI_TEST_EQUALS(gResourceReadySignalCounter, 1, TEST_LOCATION);
4380
4381     application.SendNotification();
4382     application.Render();
4383
4384     gImageView2 = ImageView::New();
4385     gImageView2.SetProperty(Toolkit::ImageView::Property::IMAGE, map);
4386     gImageView2.ResourceReadySignal().Connect(&OnResourceReadySignal08);
4387     application.GetScene().Add(gImageView2);
4388     DALI_TEST_EQUALS(gResourceReadySignalCounter, 2, TEST_LOCATION);
4389
4390     application.SendNotification();
4391     application.Render();
4392
4393     DALI_TEST_CHECK(true);
4394   }
4395   catch(...)
4396   {
4397     // Exception should not happened
4398     DALI_TEST_CHECK(false);
4399   }
4400   gResourceReadySignalCounter = 0;
4401
4402   // Clear image view for clear test
4403
4404   if(gImageView1)
4405   {
4406     gImageView1.Reset();
4407   }
4408   if(gImageView2)
4409   {
4410     gImageView2.Reset();
4411   }
4412
4413   END_TEST;
4414 }
4415
4416 int UtcDaliImageViewSetImageOnResourceReadySignal09(void)
4417 {
4418   tet_infoline("Test load invalid npatch images during invalid resource ready");
4419
4420   ToolkitTestApplication application;
4421
4422   gResourceReadySignalCounter = 0;
4423
4424   Property::Map map;
4425   map[Toolkit::ImageVisual::Property::URL] = TEST_INVALID_NPATCH_FILE_NAME_01;
4426
4427   // Clear image view for clear test
4428
4429   if(gImageView1)
4430   {
4431     gImageView1.Reset();
4432   }
4433   if(gImageView2)
4434   {
4435     gImageView2.Reset();
4436   }
4437   if(gImageView3)
4438   {
4439     gImageView3.Reset();
4440   }
4441
4442   // Dummy view with npatch image
4443   ImageView dummyView = ImageView::New(TEST_BROKEN_IMAGE_M);
4444   application.GetScene().Add(dummyView);
4445
4446   application.SendNotification();
4447   application.Render();
4448   DALI_TEST_EQUALS(Test::WaitForEventThreadTrigger(1), true, TEST_LOCATION);
4449   application.SendNotification();
4450   application.Render();
4451
4452   // Case 1 : Reload images during resource ready.
4453   try
4454   {
4455     gResourceReadySignal09Emitted = false;
4456
4457     gImageView1 = ImageView::New();
4458     gImageView1.SetProperty(Toolkit::ImageView::Property::IMAGE, map);
4459     gImageView1.ResourceReadySignal().Connect(&OnResourceReadySignal09);
4460     application.GetScene().Add(gImageView1);
4461
4462     gImageView2 = ImageView::New();
4463     application.GetScene().Add(gImageView2);
4464
4465     // Load TEST_INVALID_NPATCH_FILE_NAME_01
4466     DALI_TEST_EQUALS(Test::WaitForEventThreadTrigger(1), true, TEST_LOCATION);
4467
4468     // Load TEST_INVALID_NPATCH_FILE_NAME_01 one more times.
4469     DALI_TEST_EQUALS(Test::WaitForEventThreadTrigger(1), true, TEST_LOCATION);
4470
4471     application.SendNotification();
4472     application.Render();
4473
4474     DALI_TEST_CHECK(true);
4475   }
4476   catch(...)
4477   {
4478     // Exception should not happened
4479     DALI_TEST_CHECK(false);
4480   }
4481
4482   // Clear cache.
4483   application.SendNotification();
4484   application.Render();
4485
4486   gResourceReadySignalCounter = 0;
4487
4488   // Case 2 : Remove all images when we use cached resource.
4489   try
4490   {
4491     gResourceReadySignal09Emitted = false;
4492
4493     gImageView3 = ImageView::New();
4494     gImageView3.SetProperty(Toolkit::ImageView::Property::IMAGE, map);
4495     gImageView3.ResourceReadySignal().Connect(&OnSimpleResourceReadySignal);
4496     application.GetScene().Add(gImageView3);
4497
4498     gImageView2 = ImageView::New();
4499     application.GetScene().Add(gImageView2);
4500
4501     // Load gImageView2
4502     DALI_TEST_EQUALS(Test::WaitForEventThreadTrigger(1), true, TEST_LOCATION);
4503
4504     gImageView1 = ImageView::New();
4505     gImageView1.SetProperty(Toolkit::ImageView::Property::IMAGE, map);
4506     gImageView1.ResourceReadySignal().Connect(&OnResourceReadySignal09);
4507     application.GetScene().Add(gImageView1);
4508
4509     // Load gImageView1
4510     DALI_TEST_EQUALS(Test::WaitForEventThreadTrigger(1), true, TEST_LOCATION);
4511
4512     // Load TEST_INVALID_NPATCH_FILE_NAME_01 one more times.
4513     DALI_TEST_EQUALS(Test::WaitForEventThreadTrigger(1), true, TEST_LOCATION);
4514
4515     application.SendNotification();
4516     application.Render();
4517
4518     DALI_TEST_CHECK(true);
4519   }
4520   catch(...)
4521   {
4522     // Exception should not happened
4523     DALI_TEST_CHECK(false);
4524   }
4525   gResourceReadySignalCounter = 0;
4526
4527   // Clear image view for clear test
4528
4529   if(gImageView1)
4530   {
4531     gImageView1.Reset();
4532   }
4533   if(gImageView2)
4534   {
4535     gImageView2.Reset();
4536   }
4537   if(gImageView3)
4538   {
4539     gImageView3.Reset();
4540   }
4541
4542   END_TEST;
4543 }
4544
4545 int UtcDaliImageViewSetImageOnResourceReadySignal10(void)
4546 {
4547   tet_infoline("Test ResourceReady signal comes more than 2 times.");
4548
4549   ToolkitTestApplication application;
4550
4551   gResourceReadySignalCounter = 0;
4552
4553   // Clear image view for clear test
4554
4555   if(gImageView1)
4556   {
4557     gImageView1.Reset();
4558   }
4559
4560   // Dummy view to cache image.
4561   ImageView dummyView = ImageView::New(gImage_34_RGBA);
4562   application.GetScene().Add(dummyView);
4563
4564   application.SendNotification();
4565   application.Render();
4566   DALI_TEST_EQUALS(Test::WaitForEventThreadTrigger(1), true, TEST_LOCATION);
4567   application.SendNotification();
4568   application.Render();
4569
4570   try
4571   {
4572     gImageView1 = ImageView::New();
4573     gImageView1.SetProperty(Toolkit::ImageView::Property::IMAGE, gImage_34_RGBA);
4574     gImageView1.ResourceReadySignal().Connect(&OnResourceReadySignal10);
4575     application.GetScene().Add(gImageView1); // It will call resourceReady signal 1 time.
4576
4577     tet_printf("ResourceReady called %d times\n", gResourceReadySignalCounter);
4578
4579     DALI_TEST_GREATER(gResourceReadySignal10MaxCounter, gResourceReadySignalCounter, TEST_LOCATION); // Check whether resource ready call too much.
4580
4581     for(int i = 0; i < gResourceReadySignal10MaxCounter; ++i)
4582     {
4583       tet_printf("RunIdles\n");
4584       // Executes the idle callbacks.
4585       application.RunIdles();
4586       application.SendNotification();
4587       application.Render();
4588       tet_printf("RunIdles done\n");
4589     }
4590     tet_printf("ResourceReady called %d times\n", gResourceReadySignalCounter);
4591
4592     DALI_TEST_EQUALS(gResourceReadySignalCounter, gResourceReadySignal10MaxCounter, TEST_LOCATION);
4593
4594     DALI_TEST_CHECK(true);
4595   }
4596   catch(...)
4597   {
4598     // Exception should not happened
4599     DALI_TEST_CHECK(false);
4600   }
4601
4602   // Clear cache.
4603   application.SendNotification();
4604   application.Render();
4605
4606   gResourceReadySignalCounter = 0;
4607
4608   gResourceReadySignalCounter = 0;
4609
4610   // Clear image view for clear test
4611
4612   if(gImageView1)
4613   {
4614     gImageView1.Reset();
4615   }
4616
4617   END_TEST;
4618 }
4619
4620 int UtcDaliImageViewUseSameUrlWithAnimatedImageVisual(void)
4621 {
4622   tet_infoline("Test multiple views with same image in animated image visual");
4623   ToolkitTestApplication application;
4624
4625   gImageView1 = ImageView::New(TEST_WEBP_FILE_NAME);
4626   application.GetScene().Add(gImageView1);
4627
4628   tet_infoline("Remove imageView and Create new imageView with same url");
4629   application.GetScene().Remove(gImageView1);
4630   gImageView2 = ImageView::New(TEST_WEBP_FILE_NAME);
4631   application.GetScene().Add(gImageView2);
4632
4633   application.SendNotification();
4634   application.Render();
4635
4636   tet_infoline("Check the ImageView load image successfully");
4637   DALI_TEST_EQUALS(Test::WaitForEventThreadTrigger(1), true, TEST_LOCATION);
4638   END_TEST;
4639 }
4640
4641 int UtcDaliImageViewNpatchImageCacheTest01(void)
4642 {
4643   tet_infoline("Test npatch image cached");
4644
4645   ToolkitTestApplication application;
4646   ImageView              imageView[2];
4647
4648   auto& gl = application.GetGlAbstraction();
4649   gl.EnableTextureCallTrace(true);
4650   auto& textureCallStack = gl.GetTextureTrace();
4651   textureCallStack.Enable(true);
4652   textureCallStack.EnableLogging(true);
4653
4654   auto TestNPatch = [&](int index, const std::string& nPatchImageUrl, const char* location) {
4655     if(imageView[index])
4656     {
4657       imageView[index].Unparent();
4658     }
4659
4660     // Ensure remove npatch cache if required.
4661     application.SendNotification();
4662     application.Render();
4663
4664     imageView[index] = ImageView::New(nPatchImageUrl);
4665     imageView[index].SetProperty(Actor::Property::SIZE, Vector2(100.0f, 200.0f));
4666     application.GetScene().Add(imageView[index]);
4667   };
4668
4669   TestNPatch(0, TEST_BROKEN_IMAGE_M, TEST_LOCATION);
4670   DALI_TEST_EQUALS(Test::WaitForEventThreadTrigger(1), true, TEST_LOCATION);
4671
4672   application.SendNotification();
4673   application.Render();
4674
4675   tet_printf("trace : \n%s\n", textureCallStack.GetTraceString().c_str());
4676
4677   // Check we gen only 1 textures
4678   DALI_TEST_EQUALS(textureCallStack.CountMethod("GenTextures"), 1, TEST_LOCATION);
4679   textureCallStack.Reset();
4680
4681   // Let we use cached textures
4682   for(int i = 0; i < 10; i++)
4683   {
4684     TestNPatch(1, TEST_BROKEN_IMAGE_M, TEST_LOCATION);
4685     TestNPatch(0, TEST_BROKEN_IMAGE_M, TEST_LOCATION);
4686   }
4687
4688   application.SendNotification();
4689   application.Render();
4690   // Check we use cached npatch data so we don't generate new texture textures
4691   DALI_TEST_EQUALS(textureCallStack.CountMethod("GenTextures"), 0, TEST_LOCATION);
4692
4693   // Clear all cached
4694   imageView[0].Unparent();
4695   imageView[0].Reset();
4696   imageView[1].Unparent();
4697   imageView[1].Reset();
4698
4699   application.SendNotification();
4700   application.Render();
4701
4702   textureCallStack.Reset();
4703   // Let we use deference textures
4704   TestNPatch(1, TEST_BROKEN_IMAGE_S, TEST_LOCATION);
4705   DALI_TEST_EQUALS(Test::WaitForEventThreadTrigger(1), true, TEST_LOCATION);
4706
4707   application.SendNotification();
4708   application.Render();
4709   // Try to load multiple times.
4710   for(int i = 0; i < 3; i++)
4711   {
4712     TestNPatch(0, TEST_BROKEN_IMAGE_M, TEST_LOCATION);
4713     DALI_TEST_EQUALS(Test::WaitForEventThreadTrigger(1), true, TEST_LOCATION);
4714     TestNPatch(1, TEST_BROKEN_IMAGE_S, TEST_LOCATION);
4715     DALI_TEST_EQUALS(Test::WaitForEventThreadTrigger(1), true, TEST_LOCATION);
4716   }
4717   application.SendNotification();
4718   application.Render();
4719
4720   imageView[0].Unparent();
4721   imageView[0].Reset();
4722   imageView[1].Unparent();
4723   imageView[1].Reset();
4724
4725   application.SendNotification();
4726   application.Render();
4727
4728   // Check memory leak
4729   DALI_TEST_EQUALS(textureCallStack.CountMethod("GenTextures"), textureCallStack.CountMethod("DeleteTextures"), TEST_LOCATION);
4730
4731   END_TEST;
4732 }
4733
4734 int UtcDaliImageViewNpatchImageCacheTest02(void)
4735 {
4736   tet_infoline("Test npatch image cached with border");
4737
4738   ToolkitTestApplication application;
4739   ImageView              imageView[2];
4740
4741   auto& gl = application.GetGlAbstraction();
4742   gl.EnableTextureCallTrace(true);
4743   auto& textureCallStack = gl.GetTextureTrace();
4744   textureCallStack.Enable(true);
4745   textureCallStack.EnableLogging(true);
4746
4747   auto TestBorderImage = [&](int index, const std::string& normalImageUrl, const Rect<int> border, const char* location) {
4748     Property::Map map;
4749     map[Toolkit::Visual::Property::TYPE]        = Toolkit::Visual::N_PATCH;
4750     map[Toolkit::ImageVisual::Property::URL]    = normalImageUrl;
4751     map[Toolkit::ImageVisual::Property::BORDER] = border;
4752
4753     imageView[index] = ImageView::New();
4754     imageView[index].SetProperty(Toolkit::ImageView::Property::IMAGE, map);
4755     imageView[index].SetProperty(Actor::Property::SIZE, Vector2(100.0f, 200.0f));
4756     application.GetScene().Add(imageView[index]);
4757   };
4758
4759   TestBorderImage(0, gImage_34_RGBA, Rect<int>(0, 0, 0, 0), TEST_LOCATION);
4760   DALI_TEST_EQUALS(Test::WaitForEventThreadTrigger(1), true, TEST_LOCATION);
4761
4762   application.SendNotification();
4763   application.Render();
4764
4765   tet_printf("trace : \n%s\n", textureCallStack.GetTraceString().c_str());
4766
4767   // Check we gen only 1 textures
4768   DALI_TEST_EQUALS(textureCallStack.CountMethod("GenTextures"), 1, TEST_LOCATION);
4769   textureCallStack.Reset();
4770
4771   // Let we use cached textures
4772   for(int i = 0; i < 10; i++)
4773   {
4774     TestBorderImage(0, gImage_34_RGBA, Rect<int>(i, i + 1, i + 2, i + 3), TEST_LOCATION);
4775     TestBorderImage(1, gImage_34_RGBA, Rect<int>(i + 1, i, i + 3, i + 2), TEST_LOCATION);
4776   }
4777
4778   application.SendNotification();
4779   application.Render();
4780
4781   // Check we use cached npatch data so we don't generate new texture textures
4782   DALI_TEST_EQUALS(textureCallStack.CountMethod("GenTextures"), 0, TEST_LOCATION);
4783
4784   END_TEST;
4785 }
4786
4787 int UtcDaliImageViewPlaceholderImage01(void)
4788 {
4789   tet_infoline("Test imageView use placeholder image");
4790
4791   ToolkitTestApplication application;
4792   Property::Map          map;
4793   map[Toolkit::ImageVisual::Property::URL] = gImage_600_RGB;
4794
4795   ImageView imageView = ImageView::New();
4796   imageView.SetProperty(Toolkit::ImageView::Property::IMAGE, map);
4797   imageView.SetProperty(Actor::Property::SIZE, Vector2(100.0f, 200.0f));
4798   application.GetScene().Add(imageView);
4799
4800   Property::Value value = imageView.GetProperty(ImageView::Property::PLACEHOLDER_IMAGE);
4801   std::string     url;
4802   DALI_TEST_CHECK(value.Get(url));
4803   DALI_TEST_CHECK(url.empty());
4804   imageView.SetProperty(Toolkit::ImageView::Property::PLACEHOLDER_IMAGE, gImage_34_RGBA);
4805
4806   application.SendNotification();
4807   application.Render();
4808
4809   value = imageView.GetProperty(ImageView::Property::PLACEHOLDER_IMAGE);
4810   DALI_TEST_CHECK(value.Get(url));
4811   DALI_TEST_CHECK(url == gImage_34_RGBA);
4812
4813   imageView.SetProperty(Toolkit::ImageView::Property::IMAGE, map);
4814   application.SendNotification();
4815   application.Render();
4816
4817   // Replace Image test
4818   map[Toolkit::ImageVisual::Property::URL]    = TEST_IMAGE_1;
4819   map[ImageView::Property::PLACEHOLDER_IMAGE] = gImage_34_RGBA;
4820   imageView.SetProperty(Toolkit::ImageView::Property::IMAGE, map);
4821   application.SendNotification();
4822   application.Render();
4823
4824   map[Toolkit::ImageVisual::Property::URL] = "";
4825   imageView.SetProperty(Toolkit::ImageView::Property::IMAGE, map);
4826   application.SendNotification();
4827   application.Render();
4828
4829   map[Toolkit::ImageVisual::Property::URL] = TEST_IMAGE_2;
4830   imageView.SetProperty(Toolkit::ImageView::Property::IMAGE, map);
4831   application.SendNotification();
4832   application.Render();
4833
4834   // Replace Image test2
4835   map[Toolkit::ImageVisual::Property::URL] = TEST_IMAGE_1;
4836   imageView.SetProperty(Toolkit::ImageView::Property::IMAGE, map);
4837   application.SendNotification();
4838   application.Render();
4839
4840   map[Toolkit::ImageVisual::Property::URL] = TEST_IMAGE_2;
4841   imageView.SetProperty(Toolkit::ImageView::Property::IMAGE, map);
4842   application.SendNotification();
4843   application.Render();
4844
4845   map[Toolkit::ImageVisual::Property::URL] = gImage_600_RGB;
4846   imageView.SetProperty(Toolkit::ImageView::Property::IMAGE, map);
4847   application.SendNotification();
4848   application.Render(900);
4849
4850   map[Toolkit::ImageVisual::Property::URL] = "";
4851   imageView.SetProperty(Toolkit::ImageView::Property::IMAGE, map);
4852   application.SendNotification();
4853   application.Render();
4854
4855   map[Toolkit::ImageVisual::Property::URL] = TEST_IMAGE_1;
4856   imageView.SetProperty(Toolkit::ImageView::Property::IMAGE, map);
4857   application.SendNotification();
4858   application.Render();
4859
4860   END_TEST;
4861 }
4862
4863 int UtcDaliImageViewPlaceholderImage02(void)
4864 {
4865   tet_infoline("Test imageView use placeholder image without resource ready");
4866
4867   ToolkitTestApplication application;
4868
4869   Property::Map map;
4870   map[Toolkit::ImageVisual::Property::URL] = gImage_600_RGB;
4871
4872   ImageView imageView = ImageView::New();
4873   imageView.SetProperty(Toolkit::ImageView::Property::IMAGE, map);
4874   imageView.SetProperty(Actor::Property::SIZE, Vector2(100.0f, 200.0f));
4875   DALI_TEST_EQUALS(imageView.IsResourceReady(), false, TEST_LOCATION);
4876   imageView.ResourceReadySignal().Connect(&ResourceReadySignal);
4877   application.GetScene().Add(imageView);
4878
4879   Property::Value value = imageView.GetProperty(ImageView::Property::PLACEHOLDER_IMAGE);
4880   std::string     url;
4881   DALI_TEST_CHECK(value.Get(url));
4882   DALI_TEST_CHECK(url.empty());
4883
4884   imageView.SetProperty(Toolkit::ImageView::Property::PLACEHOLDER_IMAGE, gImage_34_RGBA);
4885   application.SendNotification();
4886   application.Render();
4887
4888   DALI_TEST_EQUALS(Test::WaitForEventThreadTrigger(1), true, TEST_LOCATION);
4889
4890   value = imageView.GetProperty(ImageView::Property::PLACEHOLDER_IMAGE);
4891   DALI_TEST_CHECK(value.Get(url));
4892   DALI_TEST_CHECK(url == gImage_34_RGBA);
4893
4894   DALI_TEST_EQUALS(imageView.IsResourceReady(), true, TEST_LOCATION);
4895   DALI_TEST_EQUALS(gResourceReadySignalFired, true, TEST_LOCATION);
4896
4897   gResourceReadySignalFired                = false;
4898   map[Toolkit::ImageVisual::Property::URL] = "";
4899   imageView.SetProperty(Toolkit::ImageView::Property::IMAGE, map);
4900   application.SendNotification();
4901   application.Render();
4902
4903   DALI_TEST_EQUALS(imageView.IsResourceReady(), true, TEST_LOCATION);
4904   DALI_TEST_EQUALS(gResourceReadySignalFired, false, TEST_LOCATION);
4905
4906   END_TEST;
4907 }
4908
4909 int UtcDaliImageViewTransitionEffect01(void)
4910 {
4911   tet_infoline("Test imageView use transition effect");
4912
4913   ToolkitTestApplication application;
4914   Property::Map          map;
4915   map[Toolkit::ImageVisual::Property::URL] = gImage_600_RGB;
4916   map[Toolkit::Visual::Property::OPACITY]  = 0.9f;
4917
4918   ImageView imageView = ImageView::New();
4919   imageView.SetProperty(Toolkit::ImageView::Property::IMAGE, map);
4920   imageView.SetProperty(Actor::Property::SIZE, Vector2(100.0f, 200.0f));
4921   application.GetScene().Add(imageView);
4922
4923   Property::Value value = imageView.GetProperty(ImageView::Property::ENABLE_TRANSITION_EFFECT);
4924   bool            transition;
4925   DALI_TEST_CHECK(value.Get(transition));
4926   DALI_TEST_CHECK(transition == false);
4927   imageView.SetProperty(Toolkit::ImageView::Property::ENABLE_TRANSITION_EFFECT, true);
4928
4929   application.SendNotification();
4930   application.Render();
4931
4932   value = imageView.GetProperty(ImageView::Property::ENABLE_TRANSITION_EFFECT);
4933   DALI_TEST_CHECK(value.Get(transition));
4934   DALI_TEST_CHECK(transition == true);
4935
4936   imageView.SetProperty(Toolkit::ImageView::Property::IMAGE, map);
4937   DALI_TEST_EQUALS(Test::WaitForEventThreadTrigger(1), true, TEST_LOCATION);
4938   application.SendNotification();
4939   application.Render();
4940
4941   // Test transition effect with placeholder
4942   map[Toolkit::ImageVisual::Property::URL] = TEST_IMAGE_1;
4943   imageView.SetProperty(Toolkit::ImageView::Property::IMAGE, map);
4944   imageView.SetProperty(Toolkit::ImageView::Property::PLACEHOLDER_IMAGE, gImage_34_RGBA);
4945   DALI_TEST_EQUALS(Test::WaitForEventThreadTrigger(1), true, TEST_LOCATION);
4946   application.SendNotification();
4947   application.Render();
4948
4949   map[Toolkit::ImageVisual::Property::URL] = "";
4950   imageView.SetProperty(Toolkit::ImageView::Property::IMAGE, map);
4951   imageView.SetProperty(Toolkit::ImageView::Property::PLACEHOLDER_IMAGE, gImage_34_RGBA);
4952   application.SendNotification();
4953   application.Render();
4954
4955   map[Toolkit::ImageVisual::Property::URL] = gImage_600_RGB;
4956   imageView.SetProperty(Toolkit::ImageView::Property::IMAGE, map);
4957   imageView.SetProperty(Toolkit::ImageView::Property::PLACEHOLDER_IMAGE, gImage_34_RGBA);
4958   application.SendNotification();
4959   application.Render();
4960
4961   map[Toolkit::ImageVisual::Property::URL] = TEST_IMAGE_1;
4962   imageView.SetProperty(Toolkit::ImageView::Property::IMAGE, map);
4963   imageView.SetProperty(Toolkit::ImageView::Property::PLACEHOLDER_IMAGE, gImage_34_RGBA);
4964   application.SendNotification();
4965
4966   map[Toolkit::ImageVisual::Property::URL] = "";
4967   imageView.SetProperty(Toolkit::ImageView::Property::IMAGE, map);
4968   imageView.SetProperty(Toolkit::ImageView::Property::PLACEHOLDER_IMAGE, gImage_34_RGBA);
4969   application.SendNotification();
4970   application.Render();
4971
4972   map[Toolkit::ImageVisual::Property::URL] = gImage_600_RGB;
4973   imageView.SetProperty(Toolkit::ImageView::Property::IMAGE, map);
4974   imageView.SetProperty(Toolkit::ImageView::Property::PLACEHOLDER_IMAGE, "");
4975   application.SendNotification();
4976   application.Render();
4977
4978   map[Toolkit::ImageVisual::Property::URL] = gImage_600_RGB;
4979   imageView.SetProperty(Toolkit::ImageView::Property::IMAGE, map);
4980   application.SendNotification();
4981   application.Render();
4982
4983   map[Toolkit::ImageVisual::Property::URL] = "";
4984   imageView.SetProperty(Toolkit::ImageView::Property::IMAGE, map);
4985   application.SendNotification();
4986   application.Render();
4987
4988   // Test transition effect without placeholder
4989   map[Toolkit::ImageVisual::Property::URL] = TEST_IMAGE_1;
4990   imageView.SetProperty(Toolkit::ImageView::Property::IMAGE, map);
4991   application.SendNotification();
4992   application.Render();
4993
4994   map[Toolkit::ImageVisual::Property::URL] = gImage_600_RGB;
4995   imageView.SetProperty(Toolkit::ImageView::Property::IMAGE, map);
4996   application.SendNotification();
4997   application.Render();
4998
4999   map[Toolkit::ImageVisual::Property::URL] = "";
5000   imageView.SetProperty(Toolkit::ImageView::Property::IMAGE, map);
5001   application.SendNotification();
5002   application.Render();
5003
5004   map[Toolkit::ImageVisual::Property::URL] = gImage_600_RGB;
5005   imageView.SetProperty(Toolkit::ImageView::Property::IMAGE, map);
5006   application.SendNotification();
5007   application.Render();
5008
5009   imageView.SetImage(TEST_IMAGE_1);
5010   application.SendNotification();
5011   application.Render();
5012
5013   imageView.SetImage(gImage_600_RGB);
5014   application.SendNotification();
5015   application.Render(9000);
5016
5017   imageView.SetImage("");
5018   application.SendNotification();
5019   application.Render();
5020
5021   imageView.SetImage(TEST_IMAGE_1);
5022   application.SendNotification();
5023   application.Render();
5024
5025   // Clear all cached
5026   imageView.Unparent();
5027   imageView.Reset();
5028
5029   END_TEST;
5030 }
5031
5032 int UtcDaliImageViewTransitionEffect02(void)
5033 {
5034   tet_infoline("Test imageView use transition effect with replace image");
5035
5036   ToolkitTestApplication application;
5037
5038   Property::Map map;
5039
5040   ImageView imageView = ImageView::New();
5041   imageView.SetProperty(Toolkit::ImageView::Property::IMAGE, map);
5042   imageView.SetProperty(Actor::Property::SIZE, Vector2(100.0f, 200.0f));
5043   application.GetScene().Add(imageView);
5044
5045   Property::Value value;
5046   value = imageView.GetProperty(ImageView::Property::ENABLE_TRANSITION_EFFECT);
5047   bool transition;
5048   DALI_TEST_CHECK(value.Get(transition));
5049   DALI_TEST_CHECK(transition == false);
5050   imageView.SetProperty(Toolkit::ImageView::Property::ENABLE_TRANSITION_EFFECT, true);
5051
5052   value = imageView.GetProperty(ImageView::Property::PLACEHOLDER_IMAGE);
5053   std::string url;
5054   DALI_TEST_CHECK(value.Get(url));
5055   DALI_TEST_CHECK(url.empty());
5056   imageView.SetProperty(Toolkit::ImageView::Property::PLACEHOLDER_IMAGE, gImage_34_RGBA);
5057   application.SendNotification();
5058   application.Render();
5059
5060   imageView.SetProperty(Toolkit::ImageView::Property::PLACEHOLDER_IMAGE, "");
5061   application.SendNotification();
5062   application.Render();
5063
5064   imageView.SetProperty(Toolkit::ImageView::Property::PLACEHOLDER_IMAGE, gImage_34_RGBA);
5065   application.SendNotification();
5066   application.Render();
5067
5068   value = imageView.GetProperty(ImageView::Property::ENABLE_TRANSITION_EFFECT);
5069   DALI_TEST_CHECK(value.Get(transition));
5070   DALI_TEST_CHECK(transition == true);
5071
5072   value = imageView.GetProperty(ImageView::Property::PLACEHOLDER_IMAGE);
5073   DALI_TEST_CHECK(value.Get(url));
5074   DALI_TEST_CHECK(url == gImage_34_RGBA);
5075
5076   imageView.SetProperty(Toolkit::ImageView::Property::IMAGE, map);
5077   application.SendNotification();
5078   application.Render();
5079
5080   // Clear all cached
5081   imageView.Unparent();
5082   imageView.Reset();
5083
5084   END_TEST;
5085 }
5086
5087 int UtcDaliImageViewTransitionEffect03(void)
5088 {
5089   tet_infoline("Test imageView use transition effect with placeholder");
5090
5091   ToolkitTestApplication application;
5092   Property::Map          map;
5093
5094   ImageView imageView = ImageView::New();
5095   imageView.SetImage("");
5096   imageView.SetProperty(Actor::Property::SIZE, Vector2(100.0f, 200.0f));
5097   imageView.SetProperty(ImageView::Property::PLACEHOLDER_IMAGE, gImage_34_RGBA);
5098   imageView.SetProperty(ImageView::Property::ENABLE_TRANSITION_EFFECT, true);
5099   application.GetScene().Add(imageView);
5100
5101   //DALI_TEST_EQUALS(Test::WaitForEventThreadTrigger(1), true, TEST_LOCATION);
5102
5103   application.SendNotification();
5104   application.Render(16);
5105
5106   tet_infoline("(1)");
5107   imageView.SetImage(gImage_600_RGB);
5108   imageView.SetProperty(ImageView::Property::PLACEHOLDER_IMAGE, gImage_34_RGBA);
5109   DALI_TEST_EQUALS(Test::WaitForEventThreadTrigger(2), true, TEST_LOCATION);
5110   application.SendNotification();
5111   application.Render(16);
5112
5113   Property::Value value;
5114   value = imageView.GetProperty(ImageView::Property::ENABLE_TRANSITION_EFFECT);
5115   bool transition;
5116   DALI_TEST_CHECK(value.Get(transition));
5117   DALI_TEST_CHECK(transition == true);
5118
5119   value = imageView.GetProperty(ImageView::Property::PLACEHOLDER_IMAGE);
5120   std::string url;
5121   DALI_TEST_CHECK(value.Get(url));
5122   DALI_TEST_CHECK(url == gImage_34_RGBA);
5123
5124   imageView.SetImage("");
5125   application.SendNotification();
5126   application.Render(16);
5127
5128   imageView.SetImage(TEST_IMAGE_1);
5129   imageView.SetProperty(ImageView::Property::PLACEHOLDER_IMAGE, gImage_34_RGBA);
5130   DALI_TEST_EQUALS(Test::WaitForEventThreadTrigger(1), true, TEST_LOCATION);
5131   application.SendNotification();
5132   application.Render(16);
5133
5134   // Clear all cached
5135   imageView.Unparent();
5136   imageView.Reset();
5137
5138   END_TEST;
5139 }