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