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