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