Apply EncodedImageBuffer with Atlas
[platform/core/uifw/dali-toolkit.git] / automated-tests / src / dali-toolkit / utc-Dali-ImageView.cpp
1 /*
2  * Copyright (c) 2022 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 "dummy-control.h"
27
28 #include <test-encoded-image-buffer.h>
29 #include <test-native-image.h>
30
31 #include <dali-toolkit/dali-toolkit.h>
32 #include <dali-toolkit/devel-api/controls/control-devel.h>
33 #include <dali-toolkit/devel-api/image-loader/texture-manager.h>
34 #include <dali-toolkit/devel-api/styling/style-manager-devel.h>
35 #include <dali-toolkit/devel-api/visual-factory/visual-base.h>
36 #include <dali-toolkit/devel-api/visuals/animated-image-visual-actions-devel.h>
37 #include <dali-toolkit/devel-api/visuals/image-visual-actions-devel.h>
38 #include <dali-toolkit/devel-api/visuals/image-visual-properties-devel.h>
39 #include <dali-toolkit/devel-api/visuals/visual-properties-devel.h>
40 #include <dali-toolkit/public-api/image-loader/image-url.h>
41 #include <dali-toolkit/public-api/image-loader/image.h>
42 #include <dali/devel-api/scripting/scripting.h>
43
44 using namespace Dali;
45 using namespace Toolkit;
46
47 void utc_dali_toolkit_image_view_startup(void)
48 {
49   test_return_value = TET_UNDEF;
50 }
51
52 void utc_dali_toolkit_image_view_cleanup(void)
53 {
54   test_return_value = TET_PASS;
55 }
56
57 namespace
58 {
59 const char* TEST_IMAGE_FILE_NAME  = "gallery_image_01.jpg";
60 const char* TEST_IMAGE_FILE_NAME2 = "gallery_image_02.jpg";
61
62 // resolution: 1024*1024
63 const char* TEST_IMAGE_1 = TEST_RESOURCE_DIR "/TB-gloss.png";
64 const char* TEST_IMAGE_2 = TEST_RESOURCE_DIR "/tb-norm.png";
65
66 const char* TEST_BROKEN_IMAGE_DEFAULT = TEST_RESOURCE_DIR "/broken.png";
67 const char* TEST_BROKEN_IMAGE_S       = TEST_RESOURCE_DIR "/broken_s.9.png";
68 const char* TEST_BROKEN_IMAGE_M       = TEST_RESOURCE_DIR "/broken_m.9.png";
69 const char* TEST_BROKEN_IMAGE_L       = TEST_RESOURCE_DIR "/broken_l.9.png";
70 const char* TEST_BROKEN_IMAGE_01      = TEST_RESOURCE_DIR "/button-up.9.png";
71 const char* TEST_BROKEN_IMAGE_02      = TEST_RESOURCE_DIR "/heartsframe.9.png";
72
73 // resolution: 34*34, pixel format: RGBA8888
74 static const char* gImage_34_RGBA = TEST_RESOURCE_DIR "/icon-edit.png";
75 // resolution: 600*600, pixel format: RGB888
76 static const char* gImage_600_RGB = TEST_RESOURCE_DIR "/test-image-600.jpg";
77
78 // resolution: 50*50, frame count: 4, frame delay: 0.2 second for each frame
79 const char* TEST_GIF_FILE_NAME = TEST_RESOURCE_DIR "/anim.gif";
80
81 const char* TEST_SVG_FILE_NAME                   = TEST_RESOURCE_DIR "/svg1.svg";
82 const char* TEST_ANIMATED_VECTOR_IMAGE_FILE_NAME = TEST_RESOURCE_DIR "/insta_camera.json";
83
84 void TestUrl(ImageView imageView, const std::string url)
85 {
86   Property::Value value = imageView.GetProperty(imageView.GetPropertyIndex("image"));
87
88   std::string urlActual;
89   DALI_TEST_CHECK(value.Get(urlActual));
90   DALI_TEST_EQUALS(urlActual, url, TEST_LOCATION);
91 }
92
93 } // namespace
94
95 int UtcDaliImageViewNewP(void)
96 {
97   ToolkitTestApplication application;
98
99   ImageView imageView = ImageView::New();
100
101   DALI_TEST_CHECK(imageView);
102
103   END_TEST;
104 }
105
106 int UtcDaliImageViewNewUrlP(void)
107 {
108   ToolkitTestApplication application;
109
110   ImageView imageView = ImageView::New(TEST_IMAGE_FILE_NAME);
111   DALI_TEST_CHECK(imageView);
112
113   TestUrl(imageView, TEST_IMAGE_FILE_NAME);
114
115   END_TEST;
116 }
117
118 int UtcDaliImageViewConstructorP(void)
119 {
120   ToolkitTestApplication application;
121
122   ImageView imageView;
123
124   DALI_TEST_CHECK(!imageView);
125
126   END_TEST;
127 }
128
129 int UtcDaliImageViewCopyConstructorP(void)
130 {
131   ToolkitTestApplication application;
132
133   // Initialize an object, ref count == 1
134   ImageView imageView = ImageView::New();
135
136   ImageView copy(imageView);
137   DALI_TEST_CHECK(copy);
138
139   END_TEST;
140 }
141
142 int UtcDaliImageViewMoveConstructor(void)
143 {
144   ToolkitTestApplication application;
145
146   ImageView imageView = ImageView::New();
147   DALI_TEST_EQUALS(1, imageView.GetBaseObject().ReferenceCount(), TEST_LOCATION);
148   imageView.SetProperty(Actor::Property::SENSITIVE, false);
149   DALI_TEST_CHECK(false == imageView.GetProperty<bool>(Actor::Property::SENSITIVE));
150
151   ImageView moved = std::move(imageView);
152   DALI_TEST_CHECK(moved);
153   DALI_TEST_EQUALS(1, moved.GetBaseObject().ReferenceCount(), TEST_LOCATION);
154   DALI_TEST_CHECK(false == moved.GetProperty<bool>(Actor::Property::SENSITIVE));
155   DALI_TEST_CHECK(!imageView);
156
157   END_TEST;
158 }
159
160 int UtcDaliImageViewAssignmentOperatorP(void)
161 {
162   ToolkitTestApplication application;
163
164   ImageView imageView = ImageView::New();
165
166   ImageView copy(imageView);
167   DALI_TEST_CHECK(copy);
168   DALI_TEST_EQUALS(imageView, copy, TEST_LOCATION);
169
170   END_TEST;
171 }
172
173 int UtcDaliImageViewMoveAssignment(void)
174 {
175   ToolkitTestApplication application;
176
177   ImageView imageView = ImageView::New();
178   DALI_TEST_EQUALS(1, imageView.GetBaseObject().ReferenceCount(), TEST_LOCATION);
179   imageView.SetProperty(Actor::Property::SENSITIVE, false);
180   DALI_TEST_CHECK(false == imageView.GetProperty<bool>(Actor::Property::SENSITIVE));
181
182   ImageView moved;
183   moved = std::move(imageView);
184   DALI_TEST_CHECK(moved);
185   DALI_TEST_EQUALS(1, moved.GetBaseObject().ReferenceCount(), TEST_LOCATION);
186   DALI_TEST_CHECK(false == moved.GetProperty<bool>(Actor::Property::SENSITIVE));
187   DALI_TEST_CHECK(!imageView);
188
189   END_TEST;
190 }
191
192 int UtcDaliImageViewDownCastP(void)
193 {
194   ToolkitTestApplication application;
195
196   ImageView imageView = ImageView::New();
197
198   BaseHandle object(imageView);
199
200   ImageView imageView2 = ImageView::DownCast(object);
201   DALI_TEST_CHECK(imageView2);
202
203   ImageView imageView3 = DownCast<ImageView>(object);
204   DALI_TEST_CHECK(imageView3);
205
206   END_TEST;
207 }
208
209 int UtcDaliImageViewDownCastN(void)
210 {
211   ToolkitTestApplication application;
212
213   BaseHandle unInitializedObject;
214
215   ImageView imageView1 = ImageView::DownCast(unInitializedObject);
216   DALI_TEST_CHECK(!imageView1);
217
218   ImageView imageView2 = DownCast<ImageView>(unInitializedObject);
219   DALI_TEST_CHECK(!imageView2);
220
221   END_TEST;
222 }
223
224 int UtcDaliImageViewTypeRegistry(void)
225 {
226   ToolkitTestApplication application;
227
228   TypeRegistry typeRegistry = TypeRegistry::Get();
229   DALI_TEST_CHECK(typeRegistry);
230
231   TypeInfo typeInfo = typeRegistry.GetTypeInfo("ImageView");
232   DALI_TEST_CHECK(typeInfo);
233
234   BaseHandle handle = typeInfo.CreateInstance();
235   DALI_TEST_CHECK(handle);
236
237   ImageView imageView = ImageView::DownCast(handle);
238   DALI_TEST_CHECK(imageView);
239
240   END_TEST;
241 }
242
243 int UtcDaliImageViewSetGetProperty01(void)
244 {
245   ToolkitTestApplication application;
246
247   ImageView imageView = ImageView::New();
248
249   Property::Index idx = imageView.GetPropertyIndex("image");
250   DALI_TEST_EQUALS(idx, (Property::Index)ImageView::Property::IMAGE, TEST_LOCATION);
251
252   imageView.SetProperty(idx, TEST_IMAGE_FILE_NAME);
253   TestUrl(imageView, TEST_IMAGE_FILE_NAME);
254
255   END_TEST;
256 }
257
258 int UtcDaliImageViewPreMultipliedAlphaPng(void)
259 {
260   ToolkitTestApplication application;
261
262   // Set up trace debug
263   TestGlAbstraction& gl           = application.GetGlAbstraction();
264   TraceCallStack&    textureTrace = gl.GetTextureTrace();
265   textureTrace.Enable(true);
266
267   Property::Map imageMap;
268   imageMap[ImageVisual::Property::URL]            = gImage_34_RGBA;
269   imageMap[ImageVisual::Property::RELEASE_POLICY] = ImageVisual::ReleasePolicy::NEVER; // To keep the texture cache
270
271   ImageView imageView1 = ImageView::New();
272   imageView1.SetProperty(ImageView::Property::IMAGE, imageMap);
273
274   application.GetScene().Add(imageView1);
275
276   Property::Value value = imageView1.GetProperty(ImageView::Property::PRE_MULTIPLIED_ALPHA);
277   bool            enable;
278   DALI_TEST_CHECK(value.Get(enable));
279   DALI_TEST_CHECK(enable); // Default value is true
280
281   // loading started, this waits for the loader thread for max 30 seconds
282   DALI_TEST_EQUALS(Test::WaitForEventThreadTrigger(1), true, TEST_LOCATION);
283
284   application.SendNotification();
285   application.Render();
286
287   value = imageView1.GetProperty(ImageView::Property::PRE_MULTIPLIED_ALPHA);
288   DALI_TEST_CHECK(value.Get(enable));
289   DALI_TEST_CHECK(enable); // Keep true
290
291   // conventional alpha blending
292   Renderer renderer1 = imageView1.GetRendererAt(0);
293   value              = renderer1.GetProperty(Renderer::Property::BLEND_PRE_MULTIPLIED_ALPHA);
294   DALI_TEST_CHECK(value.Get(enable));
295   DALI_TEST_CHECK(enable);
296
297   int srcFactorRgb    = renderer1.GetProperty<int>(Renderer::Property::BLEND_FACTOR_SRC_RGB);
298   int destFactorRgb   = renderer1.GetProperty<int>(Renderer::Property::BLEND_FACTOR_DEST_RGB);
299   int srcFactorAlpha  = renderer1.GetProperty<int>(Renderer::Property::BLEND_FACTOR_SRC_ALPHA);
300   int destFactorAlpha = renderer1.GetProperty<int>(Renderer::Property::BLEND_FACTOR_DEST_ALPHA);
301   DALI_TEST_CHECK(srcFactorRgb == BlendFactor::ONE);
302   DALI_TEST_CHECK(destFactorRgb == BlendFactor::ONE_MINUS_SRC_ALPHA);
303   DALI_TEST_CHECK(srcFactorAlpha == BlendFactor::ONE);
304   DALI_TEST_CHECK(destFactorAlpha == BlendFactor::ONE_MINUS_SRC_ALPHA);
305
306   DALI_TEST_EQUALS(textureTrace.FindMethod("GenTextures"), true, TEST_LOCATION); // A new texture should be generated.
307   textureTrace.Reset();
308
309   // Disable pre-multiplied alpha blending
310   imageView1.SetProperty(ImageView::Property::PRE_MULTIPLIED_ALPHA, false);
311
312   // Reload the image
313   Property::Map attributes;
314   DevelControl::DoAction(imageView1, ImageView::Property::IMAGE, DevelImageVisual::Action::RELOAD, attributes);
315
316   // loading started, this waits for the loader thread for max 30 seconds
317   DALI_TEST_EQUALS(Test::WaitForEventThreadTrigger(1), true, TEST_LOCATION);
318
319   application.SendNotification();
320   application.Render();
321
322   value = imageView1.GetProperty(ImageView::Property::PRE_MULTIPLIED_ALPHA);
323   DALI_TEST_CHECK(value.Get(enable));
324   DALI_TEST_CHECK(!enable);
325
326   // conventional alpha blending
327   value = renderer1.GetProperty(Renderer::Property::BLEND_PRE_MULTIPLIED_ALPHA);
328   DALI_TEST_CHECK(value.Get(enable));
329   DALI_TEST_CHECK(!enable);
330
331   srcFactorRgb    = renderer1.GetProperty<int>(Renderer::Property::BLEND_FACTOR_SRC_RGB);
332   destFactorRgb   = renderer1.GetProperty<int>(Renderer::Property::BLEND_FACTOR_DEST_RGB);
333   srcFactorAlpha  = renderer1.GetProperty<int>(Renderer::Property::BLEND_FACTOR_SRC_ALPHA);
334   destFactorAlpha = renderer1.GetProperty<int>(Renderer::Property::BLEND_FACTOR_DEST_ALPHA);
335   DALI_TEST_CHECK(srcFactorRgb == BlendFactor::SRC_ALPHA);
336   DALI_TEST_CHECK(destFactorRgb == BlendFactor::ONE_MINUS_SRC_ALPHA);
337   DALI_TEST_CHECK(srcFactorAlpha == BlendFactor::ONE);
338   DALI_TEST_CHECK(destFactorAlpha == BlendFactor::ONE_MINUS_SRC_ALPHA);
339
340   DALI_TEST_EQUALS(textureTrace.FindMethod("GenTextures"), true, TEST_LOCATION); // A new texture should be generated.
341   textureTrace.Reset();
342
343   // Make a new ImageView using the same image
344   ImageView imageView2 = ImageView::New();
345   imageView2.SetProperty(ImageView::Property::IMAGE, imageMap);
346
347   application.GetScene().Add(imageView2);
348
349   application.SendNotification();
350   application.Render();
351
352   Renderer renderer2 = imageView2.GetRendererAt(0);
353   value              = renderer2.GetProperty(Renderer::Property::BLEND_PRE_MULTIPLIED_ALPHA);
354   DALI_TEST_CHECK(value.Get(enable));
355   DALI_TEST_CHECK(enable);
356
357   srcFactorRgb    = renderer2.GetProperty<int>(Renderer::Property::BLEND_FACTOR_SRC_RGB);
358   destFactorRgb   = renderer2.GetProperty<int>(Renderer::Property::BLEND_FACTOR_DEST_RGB);
359   srcFactorAlpha  = renderer2.GetProperty<int>(Renderer::Property::BLEND_FACTOR_SRC_ALPHA);
360   destFactorAlpha = renderer2.GetProperty<int>(Renderer::Property::BLEND_FACTOR_DEST_ALPHA);
361   DALI_TEST_CHECK(srcFactorRgb == BlendFactor::ONE);
362   DALI_TEST_CHECK(destFactorRgb == BlendFactor::ONE_MINUS_SRC_ALPHA);
363   DALI_TEST_CHECK(srcFactorAlpha == BlendFactor::ONE);
364   DALI_TEST_CHECK(destFactorAlpha == BlendFactor::ONE_MINUS_SRC_ALPHA);
365
366   DALI_TEST_EQUALS(textureTrace.FindMethod("GenTextures"), false, TEST_LOCATION); // The cached texture should be used.
367
368   END_TEST;
369 }
370
371 int UtcDaliImageViewPreMultipliedAlphaJpg(void)
372 {
373   ToolkitTestApplication application;
374
375   // Set up trace debug
376   TestGlAbstraction& gl           = application.GetGlAbstraction();
377   TraceCallStack&    textureTrace = gl.GetTextureTrace();
378   textureTrace.Enable(true);
379
380   Property::Map imageMap;
381   imageMap[ImageVisual::Property::URL]            = gImage_600_RGB;
382   imageMap[ImageVisual::Property::RELEASE_POLICY] = ImageVisual::ReleasePolicy::NEVER; // To keep the texture cache
383
384   ImageView imageView1 = ImageView::New();
385   imageView1.SetProperty(ImageView::Property::IMAGE, imageMap);
386
387   application.GetScene().Add(imageView1);
388
389   Property::Value value = imageView1.GetProperty(ImageView::Property::PRE_MULTIPLIED_ALPHA);
390   bool            enable;
391   DALI_TEST_CHECK(value.Get(enable));
392   DALI_TEST_CHECK(enable); // Default value is true
393
394   // loading started, this waits for the loader thread for max 30 seconds
395   DALI_TEST_EQUALS(Test::WaitForEventThreadTrigger(1), true, TEST_LOCATION);
396
397   application.SendNotification();
398   application.Render();
399
400   value = imageView1.GetProperty(ImageView::Property::PRE_MULTIPLIED_ALPHA);
401   DALI_TEST_CHECK(value.Get(enable));
402   DALI_TEST_CHECK(!enable); // Should be false after loading
403
404   // conventional alpha blending
405   Renderer renderer1 = imageView1.GetRendererAt(0);
406   value              = renderer1.GetProperty(Renderer::Property::BLEND_PRE_MULTIPLIED_ALPHA);
407   DALI_TEST_CHECK(value.Get(enable));
408   DALI_TEST_CHECK(!enable);
409
410   int srcFactorRgb    = renderer1.GetProperty<int>(Renderer::Property::BLEND_FACTOR_SRC_RGB);
411   int destFactorRgb   = renderer1.GetProperty<int>(Renderer::Property::BLEND_FACTOR_DEST_RGB);
412   int srcFactorAlpha  = renderer1.GetProperty<int>(Renderer::Property::BLEND_FACTOR_SRC_ALPHA);
413   int destFactorAlpha = renderer1.GetProperty<int>(Renderer::Property::BLEND_FACTOR_DEST_ALPHA);
414   DALI_TEST_CHECK(srcFactorRgb == BlendFactor::SRC_ALPHA);
415   DALI_TEST_CHECK(destFactorRgb == BlendFactor::ONE_MINUS_SRC_ALPHA);
416   DALI_TEST_CHECK(srcFactorAlpha == BlendFactor::ONE);
417   DALI_TEST_CHECK(destFactorAlpha == BlendFactor::ONE_MINUS_SRC_ALPHA);
418
419   DALI_TEST_EQUALS(textureTrace.FindMethod("GenTextures"), true, TEST_LOCATION); // A new texture should be generated.
420   textureTrace.Reset();
421
422   ImageView imageView2 = ImageView::New();
423   imageView2.SetProperty(ImageView::Property::IMAGE, imageMap);
424
425   // Disable pre-multiplied alpha blending
426   imageView2.SetProperty(ImageView::Property::PRE_MULTIPLIED_ALPHA, false);
427
428   application.GetScene().Add(imageView2);
429
430   application.SendNotification();
431   application.Render();
432
433   value = imageView2.GetProperty(ImageView::Property::PRE_MULTIPLIED_ALPHA);
434   DALI_TEST_CHECK(value.Get(enable));
435   DALI_TEST_CHECK(!enable);
436
437   // conventional alpha blending
438   Renderer renderer2 = imageView2.GetRendererAt(0);
439   value              = renderer2.GetProperty(Renderer::Property::BLEND_PRE_MULTIPLIED_ALPHA);
440   DALI_TEST_CHECK(value.Get(enable));
441   DALI_TEST_CHECK(!enable);
442
443   srcFactorRgb    = renderer2.GetProperty<int>(Renderer::Property::BLEND_FACTOR_SRC_RGB);
444   destFactorRgb   = renderer2.GetProperty<int>(Renderer::Property::BLEND_FACTOR_DEST_RGB);
445   srcFactorAlpha  = renderer2.GetProperty<int>(Renderer::Property::BLEND_FACTOR_SRC_ALPHA);
446   destFactorAlpha = renderer2.GetProperty<int>(Renderer::Property::BLEND_FACTOR_DEST_ALPHA);
447   DALI_TEST_CHECK(srcFactorRgb == BlendFactor::SRC_ALPHA);
448   DALI_TEST_CHECK(destFactorRgb == BlendFactor::ONE_MINUS_SRC_ALPHA);
449   DALI_TEST_CHECK(srcFactorAlpha == BlendFactor::ONE);
450   DALI_TEST_CHECK(destFactorAlpha == BlendFactor::ONE_MINUS_SRC_ALPHA);
451
452   DALI_TEST_EQUALS(textureTrace.FindMethod("GenTextures"), false, TEST_LOCATION); // The cached texture should be used.
453
454   END_TEST;
455 }
456
457 int UtcDaliImageViewPixelArea(void)
458 {
459   // Test pixel area property
460   ToolkitTestApplication application;
461
462   static std::vector<UniformData> customUniforms =
463     {
464       UniformData("pixelArea", Property::Type::VECTOR4),
465     };
466
467   TestGraphicsController& graphics = application.GetGraphicsController();
468   graphics.AddCustomUniforms(customUniforms);
469
470   // Gif image, use AnimatedImageVisual internally
471   // Atlasing is applied to pack multiple frames, use custom wrap mode
472   ImageView     gifView = ImageView::New();
473   const Vector4 pixelAreaVisual(0.f, 0.f, 2.f, 2.f);
474   gifView.SetProperty(ImageView::Property::IMAGE,
475                       Property::Map().Add(ImageVisual::Property::URL, TEST_GIF_FILE_NAME).Add(ImageVisual::Property::PIXEL_AREA, pixelAreaVisual));
476
477   // Add to stage
478   Integration::Scene stage = application.GetScene();
479   stage.Add(gifView);
480
481   // loading started
482   application.SendNotification();
483   application.Render(16);
484
485   DALI_TEST_EQUALS(Test::WaitForEventThreadTrigger(2), true, TEST_LOCATION);
486
487   application.SendNotification();
488   application.Render();
489   DALI_TEST_CHECK(gifView.GetRendererCount() == 1u);
490
491   const Vector4 fullTextureRect(0.f, 0.f, 1.f, 1.f);
492   // test that the pixel area value defined in the visual property map is registered on renderer
493   Renderer        renderer       = gifView.GetRendererAt(0);
494   Property::Value pixelAreaValue = renderer.GetProperty(renderer.GetPropertyIndex("pixelArea"));
495   DALI_TEST_EQUALS(pixelAreaValue.Get<Vector4>(), pixelAreaVisual, TEST_LOCATION);
496
497   // test that the shader has the default pixel area value registered.
498   Shader shader  = renderer.GetShader();
499   pixelAreaValue = shader.GetProperty(shader.GetPropertyIndex("pixelArea"));
500   DALI_TEST_EQUALS(pixelAreaValue.Get<Vector4>(), fullTextureRect, TEST_LOCATION);
501
502   // test that the uniform uses the pixelArea property on the renderer.
503   TestGlAbstraction& gl = application.GetGlAbstraction();
504   Vector4            pixelAreaUniform;
505   DALI_TEST_CHECK(gl.GetUniformValue<Vector4>("pixelArea", pixelAreaUniform));
506   DALI_TEST_EQUALS(pixelAreaVisual, pixelAreaUniform, Math::MACHINE_EPSILON_100, TEST_LOCATION);
507
508   // set the pixelArea property on the control
509   const Vector4 pixelAreaControl(-1.f, -1.f, 3.f, 3.f);
510   gifView.SetProperty(ImageView::Property::PIXEL_AREA, pixelAreaControl);
511   application.SendNotification();
512   application.Render(16);
513
514   // check the pixelArea property on the control
515   pixelAreaValue = gifView.GetProperty(gifView.GetPropertyIndex("pixelArea"));
516   DALI_TEST_EQUALS(pixelAreaValue.Get<Vector4>(), pixelAreaControl, TEST_LOCATION);
517   // test that the uniform uses the pixelArea property on the control.
518   DALI_TEST_CHECK(gl.GetUniformValue<Vector4>("pixelArea", pixelAreaUniform));
519   DALI_TEST_EQUALS(pixelAreaControl, pixelAreaUniform, Math::MACHINE_EPSILON_100, TEST_LOCATION);
520
521   END_TEST;
522 }
523
524 int UtcDaliImageViewAsyncLoadingWithoutAltasing(void)
525 {
526   ToolkitTestApplication     application;
527   TestGlAbstraction&         gl          = application.GetGlAbstraction();
528   const std::vector<GLuint>& textures    = gl.GetBoundTextures();
529   size_t                     numTextures = textures.size();
530
531   // Async loading, no atlasing for big size image
532   ImageView imageView = ImageView::New(gImage_600_RGB);
533
534   // By default, Aysnc loading is used
535   application.GetScene().Add(imageView);
536   imageView.SetProperty(Actor::Property::SIZE, Vector2(100, 100));
537   imageView.SetProperty(Actor::Property::PARENT_ORIGIN, ParentOrigin::CENTER);
538
539   DALI_TEST_EQUALS(Test::WaitForEventThreadTrigger(1), true, TEST_LOCATION);
540
541   application.SendNotification();
542   application.Render(16);
543   application.SendNotification();
544
545   const std::vector<GLuint>& textures2 = gl.GetBoundTextures();
546   DALI_TEST_GREATER(textures2.size(), numTextures, TEST_LOCATION);
547
548   END_TEST;
549 }
550
551 int UtcDaliImageViewAsyncLoadingWithAtlasing(void)
552 {
553   ToolkitTestApplication application;
554
555   //Async loading, automatic atlasing for small size image
556   TraceCallStack& callStack = application.GetGlAbstraction().GetTextureTrace();
557   callStack.Reset();
558   callStack.Enable(true);
559
560   Property::Map imageMap;
561
562   imageMap[ImageVisual::Property::URL]            = gImage_34_RGBA;
563   imageMap[ImageVisual::Property::DESIRED_HEIGHT] = 34;
564   imageMap[ImageVisual::Property::DESIRED_WIDTH]  = 34;
565   imageMap[ImageVisual::Property::ATLASING]       = true;
566
567   ImageView imageView = ImageView::New();
568   imageView.SetProperty(ImageView::Property::IMAGE, imageMap);
569   imageView.SetProperty(Toolkit::Control::Property::PADDING, Extents(10u, 10u, 10u, 10u));
570
571   // By default, Aysnc loading is used
572   // loading is not started if the actor is offScene
573
574   application.GetScene().Add(imageView);
575   application.SendNotification();
576   application.Render(16);
577   application.Render(16);
578   application.SendNotification();
579
580   imageView.SetProperty(Dali::Actor::Property::LAYOUT_DIRECTION, Dali::LayoutDirection::RIGHT_TO_LEFT);
581   application.SendNotification();
582   application.Render(16);
583   application.Render(16);
584   application.SendNotification();
585
586   // loading started, this waits for the loader thread for max 30 seconds
587   DALI_TEST_EQUALS(Test::WaitForEventThreadTrigger(1), true, TEST_LOCATION);
588
589   application.SendNotification();
590   application.Render(16);
591
592   callStack.Enable(false);
593
594   TraceCallStack::NamedParams params;
595   params["width"] << 34;
596   params["height"] << 34;
597   DALI_TEST_EQUALS(callStack.FindMethodAndParams("TexSubImage2D", params), true, TEST_LOCATION);
598
599   END_TEST;
600 }
601
602 int UtcDaliImageViewAsyncLoadingWithAtlasing02(void)
603 {
604   ToolkitTestApplication application;
605
606   //Async loading, automatic atlasing for small size image
607   TraceCallStack& callStack = application.GetGlAbstraction().GetTextureTrace();
608   callStack.Reset();
609   callStack.Enable(true);
610
611   Property::Map asyncLoadingMap;
612   asyncLoadingMap["url"]                = gImage_34_RGBA;
613   asyncLoadingMap["desiredHeight"]      = 34;
614   asyncLoadingMap["desiredWidth"]       = 34;
615   asyncLoadingMap["synchronousLoading"] = false;
616   asyncLoadingMap["atlasing"]           = true;
617
618   ImageView imageView = ImageView::New();
619   imageView.SetProperty(ImageView::Property::IMAGE, asyncLoadingMap);
620
621   application.GetScene().Add(imageView);
622   application.SendNotification();
623   application.Render(16);
624   application.Render(16);
625   application.SendNotification();
626
627   // loading started, this waits for the loader thread for max 30 seconds
628   DALI_TEST_EQUALS(Test::WaitForEventThreadTrigger(1), true, TEST_LOCATION);
629
630   application.SendNotification();
631   application.Render(16);
632
633   callStack.Enable(false);
634
635   TraceCallStack::NamedParams params;
636   params["width"] << 34;
637   params["height"] << 34;
638   DALI_TEST_EQUALS(callStack.FindMethodAndParams("TexSubImage2D", params), true, TEST_LOCATION);
639
640   END_TEST;
641 }
642
643 int UtcDaliImageViewSyncLoading(void)
644 {
645   ToolkitTestApplication application;
646
647   tet_infoline("ImageView Testing sync loading and size using index key property map");
648
649   Property::Map syncLoadingMap;
650   syncLoadingMap[ImageVisual::Property::SYNCHRONOUS_LOADING] = true;
651   syncLoadingMap[ImageVisual::Property::ATLASING]            = true;
652
653   // Sync loading, no atlasing for big size image
654   {
655     ImageView imageView = ImageView::New();
656
657     // Sync loading is used
658     syncLoadingMap[ImageVisual::Property::URL] = gImage_600_RGB;
659     imageView.SetProperty(ImageView::Property::IMAGE, syncLoadingMap);
660   }
661
662   // Sync loading, automatic atlasing for small size image
663   {
664     TraceCallStack& callStack = application.GetGlAbstraction().GetTextureTrace();
665     callStack.Reset();
666     callStack.Enable(true);
667
668     ImageView imageView = ImageView::New();
669
670     // Sync loading is used
671     syncLoadingMap[ImageVisual::Property::URL]            = gImage_34_RGBA;
672     syncLoadingMap[ImageVisual::Property::DESIRED_HEIGHT] = 34;
673     syncLoadingMap[ImageVisual::Property::DESIRED_WIDTH]  = 34;
674     imageView.SetProperty(ImageView::Property::IMAGE, syncLoadingMap);
675
676     application.GetScene().Add(imageView);
677     application.SendNotification();
678     application.Render(16);
679
680     TraceCallStack::NamedParams params;
681     params["width"] << 34;
682     params["height"] << 34;
683     DALI_TEST_EQUALS(callStack.FindMethodAndParams("TexSubImage2D", params),
684                      true,
685                      TEST_LOCATION);
686   }
687   END_TEST;
688 }
689
690 int UtcDaliImageViewSyncLoading02(void)
691 {
692   ToolkitTestApplication application;
693
694   tet_infoline("ImageView Testing sync loading and size using string key property map");
695
696   // Sync loading, automatic atlasing for small size image
697   {
698     TraceCallStack& callStack = application.GetGlAbstraction().GetTextureTrace();
699     callStack.Reset();
700     callStack.Enable(true);
701
702     ImageView imageView = ImageView::New();
703
704     // Sync loading is used
705     Property::Map syncLoadingMap;
706     syncLoadingMap["url"]                = gImage_34_RGBA;
707     syncLoadingMap["desiredHeight"]      = 34;
708     syncLoadingMap["desiredWidth"]       = 34;
709     syncLoadingMap["synchronousLoading"] = true;
710     syncLoadingMap["atlasing"]           = true;
711     imageView.SetProperty(ImageView::Property::IMAGE, syncLoadingMap);
712
713     application.GetScene().Add(imageView);
714     application.SendNotification();
715     application.Render(16);
716
717     TraceCallStack::NamedParams params;
718     params["width"] << 34;
719     params["height"] << 34;
720     DALI_TEST_EQUALS(callStack.FindMethodAndParams("TexSubImage2D", params),
721                      true,
722                      TEST_LOCATION);
723   }
724   END_TEST;
725 }
726
727 int UtcDaliImageViewAsyncLoadingEncodedBuffer(void)
728 {
729   ToolkitTestApplication     application;
730   TestGlAbstraction&         gl          = application.GetGlAbstraction();
731   const std::vector<GLuint>& textures    = gl.GetBoundTextures();
732   size_t                     numTextures = textures.size();
733
734   // Get encoded raw-buffer image and generate url
735   EncodedImageBuffer buffer = ConvertFileToEncodedImageBuffer(gImage_600_RGB);
736   ImageUrl           url    = Toolkit::Image::GenerateUrl(buffer);
737
738   // Async loading, no atlasing for big size image
739   ImageView imageView = ImageView::New(url.GetUrl());
740
741   // By default, Aysnc loading is used
742   application.GetScene().Add(imageView);
743   imageView.SetProperty(Actor::Property::SIZE, Vector2(100, 100));
744   imageView.SetProperty(Actor::Property::PARENT_ORIGIN, ParentOrigin::CENTER);
745
746   DALI_TEST_EQUALS(Test::WaitForEventThreadTrigger(1), true, TEST_LOCATION);
747
748   application.SendNotification();
749   application.Render(16);
750   application.SendNotification();
751
752   const std::vector<GLuint>& textures2 = gl.GetBoundTextures();
753   DALI_TEST_GREATER(textures2.size(), numTextures, TEST_LOCATION);
754
755   END_TEST;
756 }
757
758 int UtcDaliImageViewAsyncLoadingEncodedBufferWithAtlasing(void)
759 {
760   ToolkitTestApplication application;
761
762   // Get encoded raw-buffer image and generate url
763   EncodedImageBuffer buffer = ConvertFileToEncodedImageBuffer(gImage_600_RGB);
764   ImageUrl           url    = Toolkit::Image::GenerateUrl(buffer);
765   ImageUrl           url2   = Toolkit::Image::GenerateUrl(buffer);
766
767   // Generate url is not equal to url2
768   // NOTE : This behavior may changed when ImageUrl compare operator changed.
769   DALI_TEST_CHECK(url != url2);
770   // Generate url's string is equal to url2's string
771   DALI_TEST_CHECK(url.GetUrl() == url2.GetUrl());
772
773   EncodedImageBuffer buffer2 = ConvertFileToEncodedImageBuffer(gImage_600_RGB);
774   url2                       = Toolkit::Image::GenerateUrl(buffer2);
775
776   // Check whethere two url are not equal
777   DALI_TEST_CHECK(url.GetUrl() != url2.GetUrl());
778
779   // Async loading, automatic atlasing for small size image
780   TraceCallStack& callStack = application.GetGlAbstraction().GetTextureTrace();
781   callStack.Reset();
782   callStack.Enable(true);
783
784   Property::Map imageMap;
785
786   imageMap[ImageVisual::Property::URL]            = url.GetUrl();
787   imageMap[ImageVisual::Property::DESIRED_HEIGHT] = 600;
788   imageMap[ImageVisual::Property::DESIRED_WIDTH]  = 600;
789   imageMap[ImageVisual::Property::ATLASING]       = true;
790
791   // No atlasing with big image
792   ImageView imageView_bigdesired = ImageView::New();
793   imageView_bigdesired.SetProperty(ImageView::Property::IMAGE, imageMap);
794   imageView_bigdesired.SetProperty(Toolkit::Control::Property::PADDING, Extents(10u, 10u, 10u, 10u));
795
796   imageMap[ImageVisual::Property::DESIRED_HEIGHT] = 0;
797   imageMap[ImageVisual::Property::DESIRED_WIDTH]  = 0;
798
799   // No atlasing with zero desired size
800   ImageView imageView_nodesired = ImageView::New();
801   imageView_nodesired.SetProperty(ImageView::Property::IMAGE, imageMap);
802   imageView_nodesired.SetProperty(Toolkit::Control::Property::PADDING, Extents(10u, 10u, 10u, 10u));
803
804   imageMap[ImageVisual::Property::DESIRED_HEIGHT] = 34;
805   imageMap[ImageVisual::Property::DESIRED_WIDTH]  = 34;
806
807   ImageView imageView = ImageView::New();
808   imageView.SetProperty(ImageView::Property::IMAGE, imageMap);
809   imageView.SetProperty(Toolkit::Control::Property::PADDING, Extents(10u, 10u, 10u, 10u));
810
811   // By default, Aysnc loading is used
812   // loading is not started if the actor is offScene
813   application.GetScene().Add(imageView);
814   application.GetScene().Add(imageView_bigdesired);
815   application.GetScene().Add(imageView_nodesired);
816   application.SendNotification();
817   application.Render(16);
818
819   // loading started, this waits for the loader thread for max 30 seconds
820   DALI_TEST_EQUALS(Test::WaitForEventThreadTrigger(1), true, TEST_LOCATION);
821
822   application.Render(16);
823   application.SendNotification();
824
825   // Change url to url2
826   imageMap[ImageVisual::Property::URL] = url2.GetUrl();
827   imageView.SetProperty(ImageView::Property::IMAGE, imageMap);
828
829   imageView.SetProperty(Dali::Actor::Property::LAYOUT_DIRECTION, Dali::LayoutDirection::RIGHT_TO_LEFT);
830   application.SendNotification();
831   application.Render(16);
832   application.Render(16);
833   application.SendNotification();
834
835   // loading started, this waits for the loader thread for max 30 seconds
836   DALI_TEST_EQUALS(Test::WaitForEventThreadTrigger(1), true, TEST_LOCATION);
837
838   application.SendNotification();
839   application.Render(16);
840
841   callStack.Enable(false);
842
843   TraceCallStack::NamedParams params;
844   params["width"] << 34;
845   params["height"] << 34;
846   DALI_TEST_EQUALS(callStack.FindMethodAndParams("TexSubImage2D", params), true, TEST_LOCATION);
847
848   END_TEST;
849 }
850
851 int UtcDaliImageViewSyncLoadingEncodedBuffer(void)
852 {
853   ToolkitTestApplication application;
854
855   tet_infoline("ImageView Testing sync loading from EncodedImageBuffer");
856
857   // Get encoded raw-buffer image and generate url
858   EncodedImageBuffer buffer = ConvertFileToEncodedImageBuffer(gImage_34_RGBA);
859   ImageUrl           url    = Toolkit::Image::GenerateUrl(buffer);
860
861   // Sync loading, automatic atlasing for small size image
862   {
863     TraceCallStack& callStack = application.GetGlAbstraction().GetTextureTrace();
864     callStack.Reset();
865     callStack.Enable(true);
866
867     ImageView imageView = ImageView::New();
868
869     // Sync loading is used
870     Property::Map syncLoadingMap;
871     syncLoadingMap["url"]                = url.GetUrl();
872     syncLoadingMap["alphaMaskUrl"]       = gImage_34_RGBA;
873     syncLoadingMap["desiredHeight"]      = 34;
874     syncLoadingMap["desiredWidth"]       = 34;
875     syncLoadingMap["synchronousLoading"] = true;
876     syncLoadingMap["atlasing"]           = true;
877     imageView.SetProperty(ImageView::Property::IMAGE, syncLoadingMap);
878
879     application.GetScene().Add(imageView);
880     application.SendNotification();
881     application.Render(16);
882
883     TraceCallStack::NamedParams params;
884     params["width"] << 34;
885     params["height"] << 34;
886     DALI_TEST_EQUALS(callStack.FindMethodAndParams("TexSubImage2D", params),
887                      true,
888                      TEST_LOCATION);
889   }
890
891   END_TEST;
892 }
893
894 int UtcDaliImageViewAddedTexture(void)
895 {
896   ToolkitTestApplication application;
897
898   tet_infoline("ImageView Testing image view with texture provided manager url");
899
900   ImageView imageView = ImageView::New();
901
902   // empty texture is ok, though pointless from app point of view
903   TextureSet  empty;
904   std::string url = TextureManager::AddTexture(empty);
905   DALI_TEST_CHECK(url.size() > 0u);
906
907   Property::Map propertyMap;
908   propertyMap[ImageVisual::Property::URL] = url;
909   imageView.SetProperty(ImageView::Property::IMAGE, propertyMap);
910
911   application.GetScene().Add(imageView);
912   application.SendNotification();
913   application.Render();
914
915   END_TEST;
916 }
917
918 int UtcDaliImageViewSizeWithBackground(void)
919 {
920   ToolkitTestApplication application;
921
922   int       width     = 100;
923   int       height    = 200;
924   ImageView imageView = ImageView::New();
925
926   imageView.SetProperty(Control::Property::BACKGROUND,
927                         {
928                           {Toolkit::Visual::Property::TYPE, Toolkit::Visual::IMAGE},
929                           {Toolkit::ImageVisual::Property::URL, TEST_RESOURCE_DIR "/gallery-small-1.jpg"},
930                           {ImageVisual::Property::DESIRED_WIDTH, width},
931                           {ImageVisual::Property::DESIRED_HEIGHT, height},
932                         });
933
934   application.GetScene().Add(imageView);
935   application.SendNotification();
936   application.Render();
937
938   DALI_TEST_EQUALS(imageView.GetCurrentProperty<Vector3>(Actor::Property::SIZE).width, (float)width, TEST_LOCATION);
939   DALI_TEST_EQUALS(imageView.GetCurrentProperty<Vector3>(Actor::Property::SIZE).height, (float)height, TEST_LOCATION);
940
941   END_TEST;
942 }
943
944 int UtcDaliImageViewSizeWithBackgroundAndImage(void)
945 {
946   ToolkitTestApplication application;
947
948   int widthBackground  = 100;
949   int heightBackground = 200;
950   int width            = 600;
951   int height           = 600;
952
953   ImageView imageView = ImageView::New();
954
955   imageView.SetProperty(Control::Property::BACKGROUND,
956                         {
957                           {Toolkit::Visual::Property::TYPE, Toolkit::Visual::IMAGE},
958                           {Toolkit::ImageVisual::Property::URL, TEST_RESOURCE_DIR "/gallery-small-1.jpg"},
959                           {ImageVisual::Property::DESIRED_WIDTH, widthBackground},
960                           {ImageVisual::Property::DESIRED_HEIGHT, heightBackground},
961                         });
962
963   imageView.SetImage(gImage_600_RGB); // 1 to 1 ratio, 600x600 pixels
964
965   application.GetScene().Add(imageView);
966   application.SendNotification();
967   application.Render();
968
969   DALI_TEST_EQUALS(imageView.GetCurrentProperty<Vector3>(Actor::Property::SIZE).width, (float)width, TEST_LOCATION);
970   DALI_TEST_EQUALS(imageView.GetCurrentProperty<Vector3>(Actor::Property::SIZE).height, (float)height, TEST_LOCATION);
971
972   END_TEST;
973 }
974
975 int UtcDaliImageViewHeightForWidthBackground(void)
976 {
977   ToolkitTestApplication application;
978
979   int widthBackground  = 100;
980   int heightBackground = 200;
981
982   ImageView imageView = ImageView::New();
983
984   imageView.SetProperty(Control::Property::BACKGROUND,
985                         {{Toolkit::Visual::Property::TYPE, Toolkit::Visual::IMAGE},
986                          {Toolkit::ImageVisual::Property::URL, TEST_RESOURCE_DIR "/gallery-small-1.jpg"},
987                          {ImageVisual::Property::DESIRED_WIDTH, widthBackground},
988                          {ImageVisual::Property::DESIRED_HEIGHT, heightBackground}});
989
990   application.GetScene().Add(imageView);
991   application.SendNotification();
992   application.Render();
993
994   Control control = Control::DownCast(imageView);
995   DALI_TEST_CHECK(control);
996   DALI_TEST_EQUALS(imageView.GetHeightForWidth(123.f), control.GetHeightForWidth(123.f), TEST_LOCATION);
997   DALI_TEST_EQUALS(imageView.GetWidthForHeight(321.f), control.GetWidthForHeight(321.f), TEST_LOCATION);
998
999   END_TEST;
1000 }
1001
1002 int UtcDaliImageViewHeightForWidthBackgroundAndImage(void)
1003 {
1004   ToolkitTestApplication application;
1005
1006   int widthBackground  = 100;
1007   int heightBackground = 200;
1008   int width            = 300;
1009   int height           = 300;
1010
1011   ImageView imageView = ImageView::New();
1012
1013   imageView.SetProperty(Control::Property::BACKGROUND,
1014                         {{Toolkit::Visual::Property::TYPE, Toolkit::Visual::IMAGE},
1015                          {Toolkit::ImageVisual::Property::URL, TEST_RESOURCE_DIR "/gallery-small-1.jpg"},
1016                          {ImageVisual::Property::DESIRED_WIDTH, widthBackground},
1017                          {ImageVisual::Property::DESIRED_HEIGHT, heightBackground}}); // 1 to 2 ratio
1018
1019   imageView.SetImage(gImage_600_RGB); // 1 to 1 ratio
1020
1021   application.GetScene().Add(imageView);
1022   application.SendNotification();
1023   application.Render();
1024
1025   DALI_TEST_EQUALS(imageView.GetHeightForWidth(width), (float)height, TEST_LOCATION);
1026   DALI_TEST_EQUALS(imageView.GetWidthForHeight(height), (float)width, TEST_LOCATION);
1027
1028   END_TEST;
1029 }
1030
1031 int UtcDaliImageViewSetImageUrl(void)
1032 {
1033   ToolkitTestApplication application;
1034
1035   ImageView imageView = ImageView::New();
1036   imageView.SetImage(TEST_IMAGE_FILE_NAME);
1037   TestUrl(imageView, TEST_IMAGE_FILE_NAME);
1038
1039   imageView.SetImage(TEST_IMAGE_FILE_NAME2);
1040   TestUrl(imageView, TEST_IMAGE_FILE_NAME2);
1041
1042   END_TEST;
1043 }
1044
1045 bool    gResourceReadySignalFired = false;
1046 Vector3 gNaturalSize;
1047
1048 void ResourceReadySignal(Control control)
1049 {
1050   gResourceReadySignalFired = true;
1051 }
1052
1053 int UtcDaliImageViewCheckResourceReady(void)
1054 {
1055   ToolkitTestApplication application;
1056
1057   gResourceReadySignalFired = false;
1058
1059   // Check ImageView with background and main image, to ensure both visuals are marked as loaded
1060   ImageView imageView = ImageView::New(TEST_GIF_FILE_NAME);
1061
1062   imageView.SetProperty(Control::Property::BACKGROUND,
1063                         {{Toolkit::Visual::Property::TYPE, Toolkit::Visual::IMAGE},
1064                          {Toolkit::ImageVisual::Property::URL, TEST_RESOURCE_DIR "/gallery-small-1.jpg"},
1065                          {ImageVisual::Property::DESIRED_WIDTH, 100},
1066                          {ImageVisual::Property::DESIRED_HEIGHT, 200}});
1067
1068   DALI_TEST_EQUALS(imageView.IsResourceReady(), false, TEST_LOCATION);
1069
1070   imageView.ResourceReadySignal().Connect(&ResourceReadySignal);
1071
1072   application.GetScene().Add(imageView);
1073
1074   // loading started, this waits for the loader thread
1075   DALI_TEST_EQUALS(Test::WaitForEventThreadTrigger(1), true, TEST_LOCATION);
1076
1077   application.SendNotification();
1078   application.Render(16);
1079
1080   DALI_TEST_EQUALS(Test::WaitForEventThreadTrigger(2), true, TEST_LOCATION);
1081
1082   application.SendNotification();
1083   application.Render();
1084
1085   DALI_TEST_EQUALS(imageView.IsResourceReady(), true, TEST_LOCATION);
1086
1087   DALI_TEST_EQUALS(gResourceReadySignalFired, true, TEST_LOCATION);
1088
1089   END_TEST;
1090 }
1091
1092 int UtcDaliImageViewSetImageTypeChangesP(void)
1093 {
1094   ToolkitTestApplication application;
1095
1096   ImageView                   imageView   = ImageView::New();
1097   Toolkit::Internal::Control& controlImpl = Toolkit::Internal::GetImplementation(imageView);
1098
1099   application.GetScene().Add(imageView);
1100
1101   std::string           url;
1102   Property::Map         map;
1103   Toolkit::Visual::Base visual;
1104
1105   Property::Value value = imageView.GetProperty(imageView.GetPropertyIndex("image"));
1106   visual                = DevelControl::GetVisual(controlImpl, ImageView::Property::IMAGE);
1107
1108   application.SendNotification();
1109   application.Render(16);
1110
1111   DALI_TEST_CHECK(!value.Get(url)); // Value should be empty
1112   value.Get(map);
1113   DALI_TEST_CHECK(map.Empty()); // Value should be empty
1114   DALI_TEST_CHECK(!visual);     // Visual should be invalid
1115
1116   // Set a URL
1117   imageView.SetImage("TEST_URL");
1118
1119   application.SendNotification();
1120   application.Render(16);
1121
1122   value  = imageView.GetProperty(imageView.GetPropertyIndex("image"));
1123   visual = DevelControl::GetVisual(controlImpl, ImageView::Property::IMAGE);
1124
1125   DALI_TEST_CHECK(value.Get(url));  // Value should NOT be empty
1126   DALI_TEST_CHECK(!value.Get(map)); // Value should be empty
1127   DALI_TEST_CHECK(visual);          // Visual should be valid
1128
1129   // Set an empty URL
1130   imageView.SetImage("");
1131
1132   application.SendNotification();
1133   application.Render(16);
1134
1135   value  = imageView.GetProperty(imageView.GetPropertyIndex("image"));
1136   visual = DevelControl::GetVisual(controlImpl, ImageView::Property::IMAGE);
1137
1138   DALI_TEST_CHECK(!value.Get(url)); // Value should be empty
1139   value.Get(map);
1140   DALI_TEST_CHECK(map.Empty()); // Value should be empty
1141   DALI_TEST_CHECK(!visual);     // Visual should be invalid
1142
1143   // Set a URL in property map
1144   Property::Map propertyMap;
1145   propertyMap[ImageVisual::Property::URL] = TEST_IMAGE_FILE_NAME;
1146   imageView.SetProperty(ImageView::Property::IMAGE, propertyMap);
1147
1148   application.SendNotification();
1149   application.Render(16);
1150
1151   value  = imageView.GetProperty(imageView.GetPropertyIndex("image"));
1152   visual = DevelControl::GetVisual(controlImpl, ImageView::Property::IMAGE);
1153
1154   DALI_TEST_CHECK(!value.Get(url)); // Value should be empty
1155   DALI_TEST_CHECK(value.Get(map));  // Value should NOT be empty
1156   DALI_TEST_CHECK(visual);          // Visual should be valid
1157
1158   // Set a URL in property map again
1159   propertyMap[ImageVisual::Property::URL] = gImage_34_RGBA;
1160   imageView.SetProperty(ImageView::Property::IMAGE, propertyMap);
1161
1162   application.SendNotification();
1163   application.Render(16);
1164
1165   value  = imageView.GetProperty(imageView.GetPropertyIndex("image"));
1166   visual = DevelControl::GetVisual(controlImpl, ImageView::Property::IMAGE);
1167
1168   DALI_TEST_CHECK(!value.Get(url)); // Value should be empty
1169   DALI_TEST_CHECK(value.Get(map));  // Value should NOT be empty
1170   DALI_TEST_CHECK(visual);          // Visual should be valid
1171
1172   // Set an empty URL in property map
1173   propertyMap[ImageVisual::Property::URL] = std::string();
1174   imageView.SetProperty(ImageView::Property::IMAGE, propertyMap);
1175
1176   application.SendNotification();
1177   application.Render(16);
1178
1179   value  = imageView.GetProperty(imageView.GetPropertyIndex("image"));
1180   visual = DevelControl::GetVisual(controlImpl, ImageView::Property::IMAGE);
1181
1182   DALI_TEST_CHECK(!value.Get(url)); // Value should be empty
1183   DALI_TEST_CHECK(value.Get(map));  // Value should NOT be empty
1184   DALI_TEST_CHECK(!visual);         // Visual should be invalid
1185
1186   // Set a URL in property map again
1187   propertyMap[ImageVisual::Property::URL] = gImage_34_RGBA;
1188   imageView.SetProperty(ImageView::Property::IMAGE, propertyMap);
1189
1190   application.SendNotification();
1191   application.Render(16);
1192
1193   value  = imageView.GetProperty(imageView.GetPropertyIndex("image"));
1194   visual = DevelControl::GetVisual(controlImpl, ImageView::Property::IMAGE);
1195
1196   DALI_TEST_CHECK(!value.Get(url)); // Value should be empty
1197   DALI_TEST_CHECK(value.Get(map));  // Value should NOT be empty
1198   DALI_TEST_CHECK(visual);          // Visual should be valid
1199
1200   // Set an empty property map
1201   propertyMap.Clear();
1202   imageView.SetProperty(ImageView::Property::IMAGE, propertyMap);
1203
1204   application.SendNotification();
1205   application.Render(16);
1206
1207   value  = imageView.GetProperty(imageView.GetPropertyIndex("image"));
1208   visual = DevelControl::GetVisual(controlImpl, ImageView::Property::IMAGE);
1209
1210   DALI_TEST_CHECK(!value.Get(url)); // Value should be empty
1211   DALI_TEST_CHECK(value.Get(map));  // Value should NOT be empty
1212   DALI_TEST_CHECK(map.Empty());     // But PropertyMap should be empty
1213   DALI_TEST_CHECK(!visual);         // Visual should be invalid
1214
1215   END_TEST;
1216 }
1217
1218 int UtcDaliImageViewResourceUrlP(void)
1219 {
1220   ToolkitTestApplication application;
1221
1222   ImageView imageView = ImageView::New();
1223   DALI_TEST_CHECK(imageView.GetProperty(ImageView::Property::IMAGE).Get<std::string>().empty());
1224
1225   imageView.SetProperty(ImageView::Property::IMAGE, "TestString");
1226   DALI_TEST_EQUALS(imageView.GetProperty(ImageView::Property::IMAGE).Get<std::string>(), "TestString", TEST_LOCATION);
1227
1228   END_TEST;
1229 }
1230
1231 int UtcDaliImageViewReplaceImage(void)
1232 {
1233   ToolkitTestApplication application;
1234
1235   gResourceReadySignalFired = false;
1236
1237   // Check ImageView with background and main image, to ensure both visuals are marked as loaded
1238   ImageView imageView = ImageView::New(TEST_IMAGE_1);
1239
1240   DALI_TEST_EQUALS(imageView.IsResourceReady(), false, TEST_LOCATION);
1241
1242   imageView.ResourceReadySignal().Connect(&ResourceReadySignal);
1243
1244   application.GetScene().Add(imageView);
1245
1246   application.SendNotification();
1247   application.Render(16);
1248
1249   // loading started, this waits for the loader thread for max 30 seconds
1250   DALI_TEST_EQUALS(Test::WaitForEventThreadTrigger(1), true, TEST_LOCATION);
1251
1252   DALI_TEST_EQUALS(imageView.GetRendererCount(), 1u, TEST_LOCATION);
1253
1254   DALI_TEST_EQUALS(gResourceReadySignalFired, true, TEST_LOCATION);
1255
1256   gResourceReadySignalFired = false;
1257
1258   imageView.SetImage(TEST_IMAGE_2);
1259
1260   application.SendNotification();
1261   application.Render(16);
1262
1263   // loading started, this waits for the loader thread for max 30 seconds
1264   DALI_TEST_EQUALS(Test::WaitForEventThreadTrigger(1), true, TEST_LOCATION);
1265
1266   DALI_TEST_EQUALS(imageView.GetRendererCount(), 1u, TEST_LOCATION);
1267
1268   DALI_TEST_EQUALS(imageView.IsResourceReady(), true, TEST_LOCATION);
1269
1270   DALI_TEST_EQUALS(gResourceReadySignalFired, true, TEST_LOCATION);
1271
1272   END_TEST;
1273 }
1274
1275 void OnRelayoutOverride(Size size)
1276 {
1277   gNaturalSize = size; // Size Relayout is using
1278 }
1279
1280 int UtcDaliImageViewReplaceImageAndGetNaturalSize(void)
1281 {
1282   ToolkitTestApplication application;
1283
1284   // Check ImageView with background and main image, to ensure both visuals are marked as loaded
1285   ImageView imageView = ImageView::New(TEST_IMAGE_1);
1286   imageView.SetResizePolicy(ResizePolicy::USE_NATURAL_SIZE, Dimension::ALL_DIMENSIONS);
1287
1288   DummyControl        dummyControl = DummyControl::New(true);
1289   Impl::DummyControl& dummyImpl    = static_cast<Impl::DummyControl&>(dummyControl.GetImplementation());
1290   dummyControl.SetResizePolicy(ResizePolicy::FIT_TO_CHILDREN, Dimension::ALL_DIMENSIONS);
1291
1292   dummyControl.Add(imageView);
1293   dummyImpl.SetRelayoutCallback(&OnRelayoutOverride);
1294   application.GetScene().Add(dummyControl);
1295
1296   application.SendNotification();
1297   application.Render();
1298
1299   // loading started, this waits for the loader thread for max 30 seconds
1300   DALI_TEST_EQUALS(Test::WaitForEventThreadTrigger(1), true, TEST_LOCATION);
1301
1302   DALI_TEST_EQUALS(gNaturalSize.width, 1024.0f, TEST_LOCATION);
1303   DALI_TEST_EQUALS(gNaturalSize.height, 1024.0f, TEST_LOCATION);
1304
1305   gNaturalSize = Vector3::ZERO;
1306
1307   imageView.SetImage(gImage_600_RGB);
1308
1309   // Waiting for resourceReady so SendNotifcation not called here.
1310
1311   // loading started, this waits for the loader thread for max 30 seconds
1312   DALI_TEST_EQUALS(Test::WaitForEventThreadTrigger(1), true, TEST_LOCATION);
1313
1314   // Trigger a potential relayout
1315   application.SendNotification();
1316   application.Render();
1317
1318   DALI_TEST_EQUALS(gNaturalSize.width, 600.0f, TEST_LOCATION);
1319   DALI_TEST_EQUALS(gNaturalSize.height, 600.0f, TEST_LOCATION);
1320
1321   END_TEST;
1322 }
1323
1324 int UtcDaliImageViewResourceReadySignalWithImmediateLoad(void)
1325 {
1326   tet_infoline("Test Setting Image with IMMEDIATE load and receving ResourceReadySignal before staged.");
1327
1328   ToolkitTestApplication application;
1329
1330   gResourceReadySignalFired = false;
1331
1332   Property::Map imageMap;
1333
1334   imageMap[ImageVisual::Property::URL]         = gImage_34_RGBA;
1335   imageMap[ImageVisual::Property::LOAD_POLICY] = ImageVisual::LoadPolicy::IMMEDIATE;
1336
1337   tet_infoline("Creating ImageView without URL so image does not start loading");
1338   ImageView imageView = ImageView::New();
1339   tet_infoline("Connect to image loaded signal before setting image");
1340   imageView.ResourceReadySignal().Connect(&ResourceReadySignal);
1341   tet_infoline("Setting Image with IMMEDIATE load, signal already connected so will be triggered.");
1342   imageView.SetProperty(ImageView::Property::IMAGE, imageMap);
1343
1344   // loading started, this waits for the loader thread
1345   DALI_TEST_EQUALS(Test::WaitForEventThreadTrigger(1), true, TEST_LOCATION);
1346
1347   application.SendNotification();
1348   application.Render(16);
1349
1350   DALI_TEST_EQUALS(gResourceReadySignalFired, true, TEST_LOCATION);
1351
1352   END_TEST;
1353 }
1354
1355 int UtcDaliImageViewResourceReadySignalWithReusedImage(void)
1356 {
1357   tet_infoline("Test Setting Image that was already loaded by another ImageView and still getting ResourceReadySignal.");
1358
1359   ToolkitTestApplication application;
1360
1361   gResourceReadySignalFired = false;
1362
1363   Property::Map imageMap;
1364
1365   imageMap[ImageVisual::Property::URL]         = gImage_34_RGBA;
1366   imageMap[ImageVisual::Property::LOAD_POLICY] = ImageVisual::LoadPolicy::IMMEDIATE;
1367
1368   ImageView imageView = ImageView::New();
1369   imageView.ResourceReadySignal().Connect(&ResourceReadySignal);
1370   imageView.SetProperty(ImageView::Property::IMAGE, imageMap);
1371
1372   // loading started, this waits for the loader thread
1373   DALI_TEST_EQUALS(Test::WaitForEventThreadTrigger(1), true, TEST_LOCATION);
1374
1375   application.SendNotification();
1376   application.Render(16);
1377
1378   DALI_TEST_EQUALS(gResourceReadySignalFired, true, TEST_LOCATION);
1379   gResourceReadySignalFired = false;
1380
1381   ImageView imageViewWithExistingImage = ImageView::New();
1382   imageViewWithExistingImage.ResourceReadySignal().Connect(&ResourceReadySignal);
1383   imageViewWithExistingImage.SetProperty(ImageView::Property::IMAGE, imageMap);
1384
1385   DALI_TEST_EQUALS(gResourceReadySignalFired, true, TEST_LOCATION);
1386
1387   END_TEST;
1388 }
1389
1390 int UtcDaliImageViewResourceReadySignalWithReusedImage02(void)
1391 {
1392   tet_infoline("Test Setting Image that was already loaded by another ImageView and still getting ResourceReadySignal when staged.");
1393
1394   ToolkitTestApplication application;
1395
1396   gResourceReadySignalFired = false;
1397
1398   Property::Map imageImmediateLoadingMap;
1399   imageImmediateLoadingMap[ImageVisual::Property::URL]         = gImage_34_RGBA;
1400   imageImmediateLoadingMap[ImageVisual::Property::LOAD_POLICY] = ImageVisual::LoadPolicy::IMMEDIATE;
1401
1402   tet_infoline("Immediate load an image");
1403   ImageView imageView = ImageView::New();
1404   imageView.ResourceReadySignal().Connect(&ResourceReadySignal);
1405   imageView.SetProperty(ImageView::Property::IMAGE, imageImmediateLoadingMap);
1406
1407   // loading started, this waits for the loader thread
1408   DALI_TEST_EQUALS(Test::WaitForEventThreadTrigger(1), true, TEST_LOCATION);
1409
1410   application.SendNotification();
1411   application.Render(16);
1412
1413   tet_infoline("Check image loaded");
1414   DALI_TEST_EQUALS(gResourceReadySignalFired, true, TEST_LOCATION);
1415   gResourceReadySignalFired = false;
1416
1417   tet_infoline("Create another ImageView with the same URL");
1418   ImageView imageViewWithExistingImage = ImageView::New(gImage_34_RGBA);
1419   tet_infoline("Connect to ResourceReady signal for second ImageView, it should still fire as resource is ready");
1420   imageViewWithExistingImage.ResourceReadySignal().Connect(&ResourceReadySignal);
1421
1422   application.GetScene().Add(imageViewWithExistingImage);
1423
1424   DALI_TEST_EQUALS(gResourceReadySignalFired, true, TEST_LOCATION);
1425
1426   END_TEST;
1427 }
1428
1429 int UtcDaliImageViewPaddingProperty(void)
1430 {
1431   ToolkitTestApplication application;
1432
1433   ImageView     imageView = ImageView::New();
1434   Property::Map imagePropertyMap;
1435   imagePropertyMap[Toolkit::Visual::Property::TYPE]       = Toolkit::Visual::IMAGE;
1436   imagePropertyMap[Toolkit::ImageVisual::Property::URL]   = TEST_RESOURCE_DIR "/gallery-small-1.jpg";
1437   imagePropertyMap[ImageVisual::Property::DESIRED_WIDTH]  = 128;
1438   imagePropertyMap[ImageVisual::Property::DESIRED_HEIGHT] = 128;
1439   imageView.SetProperty(Toolkit::ImageView::Property::IMAGE, imagePropertyMap);
1440   imageView.SetProperty(Actor::Property::ANCHOR_POINT, AnchorPoint::TOP_LEFT);
1441   imageView.SetProperty(Actor::Property::PARENT_ORIGIN, ParentOrigin::TOP_LEFT);
1442   imageView.SetProperty(Control::Property::PADDING, Extents(15, 10, 5, 10));
1443   application.GetScene().Add(imageView);
1444
1445   application.SendNotification();
1446   application.Render();
1447
1448   DALI_TEST_EQUALS(imageView.GetProperty<Extents>(Control::Property::PADDING), Extents(15, 10, 5, 10), TEST_LOCATION);
1449
1450   ImageView childImage = ImageView::New();
1451   childImage.SetBackgroundColor(Color::BLACK);
1452   childImage.SetProperty(Actor::Property::SIZE, Vector2(10.f, 10.f));
1453   imageView.Add(childImage);
1454
1455   application.SendNotification();
1456   application.Render();
1457
1458   // Child ImageView should be positioned dependinig on Parent ImageView's Padding value
1459   DALI_TEST_EQUALS(childImage.GetProperty<Vector3>(Dali::Actor::Property::POSITION), Vector3(15, 5, 0), TEST_LOCATION);
1460
1461   // Check whether Image Visual transforms on ImageVieiw::OnRelayout()
1462   Toolkit::Internal::Control& controlImpl = Toolkit::Internal::GetImplementation(imageView);
1463   Toolkit::Visual::Base       imageVisual = DevelControl::GetVisual(controlImpl, ImageView::Property::IMAGE);
1464   Property::Map               resultMap;
1465   imageVisual.CreatePropertyMap(resultMap);
1466
1467   Property::Value* transformValue = resultMap.Find(Visual::Property::TRANSFORM);
1468   DALI_TEST_CHECK(transformValue);
1469   Property::Map* retMap = transformValue->GetMap();
1470   DALI_TEST_CHECK(retMap);
1471
1472   // Image Visual should be positioned depending on ImageView's padding
1473   DALI_TEST_EQUALS(retMap->Find(Visual::Transform::Property::OFFSET)->Get<Vector2>(), Vector2(15, 5), TEST_LOCATION);
1474
1475   END_TEST;
1476 }
1477
1478 int UtcDaliImageViewPaddingProperty02(void)
1479 {
1480   ToolkitTestApplication application;
1481
1482   ImageView     imageView = ImageView::New();
1483   Property::Map imagePropertyMap;
1484   imagePropertyMap[Toolkit::Visual::Property::TYPE]            = Toolkit::Visual::IMAGE;
1485   imagePropertyMap[Toolkit::ImageVisual::Property::URL]        = TEST_RESOURCE_DIR "/Kid1.svg";
1486   imagePropertyMap[ImageVisual::Property::DESIRED_WIDTH]       = 128;
1487   imagePropertyMap[ImageVisual::Property::DESIRED_HEIGHT]      = 128;
1488   imagePropertyMap[DevelVisual::Property::VISUAL_FITTING_MODE] = Toolkit::DevelVisual::FIT_KEEP_ASPECT_RATIO;
1489   imageView.SetProperty(Toolkit::ImageView::Property::IMAGE, imagePropertyMap);
1490   imageView.SetProperty(Actor::Property::ANCHOR_POINT, AnchorPoint::TOP_LEFT);
1491   imageView.SetProperty(Actor::Property::PARENT_ORIGIN, ParentOrigin::TOP_LEFT);
1492   imageView.SetProperty(Control::Property::PADDING, Extents(15, 10, 5, 10));
1493   application.GetScene().Add(imageView);
1494
1495   application.SendNotification();
1496   application.Render();
1497
1498   DALI_TEST_EQUALS(imageView.GetProperty<Extents>(Control::Property::PADDING), Extents(15, 10, 5, 10), TEST_LOCATION);
1499
1500   // Check whether Image Visual transforms on ImageVieiw::OnRelayout()
1501   Toolkit::Internal::Control& controlImpl = Toolkit::Internal::GetImplementation(imageView);
1502   Toolkit::Visual::Base       imageVisual = DevelControl::GetVisual(controlImpl, ImageView::Property::IMAGE);
1503   Property::Map               resultMap;
1504   imageVisual.CreatePropertyMap(resultMap);
1505
1506   Property::Value* transformValue = resultMap.Find(Visual::Property::TRANSFORM);
1507   DALI_TEST_CHECK(transformValue);
1508   Property::Map* retMap = transformValue->GetMap();
1509   DALI_TEST_CHECK(retMap);
1510
1511   // Image Visual should be positioned depending on ImageView's padding
1512   DALI_TEST_EQUALS(retMap->Find(Visual::Transform::Property::OFFSET)->Get<Vector2>(), Vector2(15, 5), TEST_LOCATION);
1513
1514   END_TEST;
1515 }
1516
1517 int UtcDaliImageViewPaddingProperty03(void)
1518 {
1519   tet_infoline("Test Setting Image Padding then removing it.");
1520
1521   ToolkitTestApplication application;
1522
1523   ImageView     imageView = ImageView::New();
1524   Property::Map imagePropertyMap;
1525   imagePropertyMap[Toolkit::Visual::Property::TYPE]            = Toolkit::Visual::IMAGE;
1526   imagePropertyMap[Toolkit::ImageVisual::Property::URL]        = TEST_RESOURCE_DIR "/Kid1.svg";
1527   imagePropertyMap[ImageVisual::Property::DESIRED_WIDTH]       = 128;
1528   imagePropertyMap[ImageVisual::Property::DESIRED_HEIGHT]      = 128;
1529   imagePropertyMap[DevelVisual::Property::VISUAL_FITTING_MODE] = Toolkit::DevelVisual::FIT_KEEP_ASPECT_RATIO;
1530   imageView.SetProperty(Toolkit::ImageView::Property::IMAGE, imagePropertyMap);
1531   imageView.SetProperty(Actor::Property::ANCHOR_POINT, AnchorPoint::TOP_LEFT);
1532   imageView.SetProperty(Actor::Property::PARENT_ORIGIN, ParentOrigin::TOP_LEFT);
1533   imageView.SetProperty(Control::Property::PADDING, Extents(15, 10, 5, 10));
1534   application.GetScene().Add(imageView);
1535
1536   application.SendNotification();
1537   application.Render();
1538
1539   DALI_TEST_EQUALS(imageView.GetProperty<Extents>(Control::Property::PADDING), Extents(15, 10, 5, 10), TEST_LOCATION);
1540
1541   tet_infoline("Remove Padding and test Visual is position correctly");
1542
1543   imageView.SetProperty(Control::Property::PADDING, Extents(0, 0, 0, 0));
1544
1545   application.SendNotification();
1546   application.Render();
1547
1548   // Check whether Image Visual transforms on ImageVieiw::OnRelayout()
1549   Toolkit::Internal::Control& controlImpl = Toolkit::Internal::GetImplementation(imageView);
1550   Toolkit::Visual::Base       imageVisual = DevelControl::GetVisual(controlImpl, ImageView::Property::IMAGE);
1551   Property::Map               resultMap;
1552   imageVisual.CreatePropertyMap(resultMap);
1553
1554   Property::Value* transformValue = resultMap.Find(Visual::Property::TRANSFORM);
1555   DALI_TEST_CHECK(transformValue);
1556   Property::Map* retMap = transformValue->GetMap();
1557   DALI_TEST_CHECK(retMap);
1558
1559   // Image Visual should be positioned depending on ImageView's padding
1560   DALI_TEST_EQUALS(retMap->Find(Visual::Transform::Property::OFFSET)->Get<Vector2>(), Vector2(0, 0), TEST_LOCATION);
1561
1562   END_TEST;
1563 }
1564
1565 int UtcDaliImageViewPaddingProperty04(void)
1566 {
1567   tet_infoline("Test Setting Image Padding then removing it. Visual Fitting Mode as Fill");
1568
1569   ToolkitTestApplication application;
1570
1571   ImageView     imageView = ImageView::New();
1572   Property::Map imagePropertyMap;
1573   imagePropertyMap[Toolkit::Visual::Property::TYPE]            = Toolkit::Visual::IMAGE;
1574   imagePropertyMap[Toolkit::ImageVisual::Property::URL]        = TEST_RESOURCE_DIR "/Kid1.svg";
1575   imagePropertyMap[ImageVisual::Property::DESIRED_WIDTH]       = 128;
1576   imagePropertyMap[ImageVisual::Property::DESIRED_HEIGHT]      = 128;
1577   imagePropertyMap[DevelVisual::Property::VISUAL_FITTING_MODE] = Toolkit::DevelVisual::FILL;
1578   imageView.SetProperty(Toolkit::ImageView::Property::IMAGE, imagePropertyMap);
1579   imageView.SetProperty(Actor::Property::ANCHOR_POINT, AnchorPoint::TOP_LEFT);
1580   imageView.SetProperty(Actor::Property::PARENT_ORIGIN, ParentOrigin::TOP_LEFT);
1581   imageView.SetProperty(Control::Property::PADDING, Extents(15, 10, 5, 10));
1582   application.GetScene().Add(imageView);
1583
1584   application.SendNotification();
1585   application.Render();
1586
1587   DALI_TEST_EQUALS(imageView.GetProperty<Extents>(Control::Property::PADDING), Extents(15, 10, 5, 10), TEST_LOCATION);
1588
1589   tet_infoline("Remove Padding and test Visual is position correctly");
1590
1591   imageView.SetProperty(Control::Property::PADDING, Extents(0, 0, 0, 0));
1592
1593   application.SendNotification();
1594   application.Render();
1595
1596   // Check whether Image Visual transforms on ImageVieiw::OnRelayout()
1597   Toolkit::Internal::Control& controlImpl = Toolkit::Internal::GetImplementation(imageView);
1598   Toolkit::Visual::Base       imageVisual = DevelControl::GetVisual(controlImpl, ImageView::Property::IMAGE);
1599   Property::Map               resultMap;
1600   imageVisual.CreatePropertyMap(resultMap);
1601
1602   Property::Value* transformValue = resultMap.Find(Visual::Property::TRANSFORM);
1603   DALI_TEST_CHECK(transformValue);
1604   Property::Map* retMap = transformValue->GetMap();
1605   DALI_TEST_CHECK(retMap);
1606
1607   // Image Visual should be positioned depending on ImageView's padding
1608   DALI_TEST_EQUALS(retMap->Find(Visual::Transform::Property::OFFSET)->Get<Vector2>(), Vector2(0, 0), TEST_LOCATION);
1609
1610   END_TEST;
1611 }
1612
1613 int UtcDaliImageViewTransformTest01(void)
1614 {
1615   tet_infoline("Test Setting a offset transform on the ImageView");
1616
1617   ToolkitTestApplication application;
1618
1619   ImageView     imageView = ImageView::New();
1620   Property::Map imagePropertyMap;
1621   imagePropertyMap.Add(Toolkit::Visual::Property::TYPE, Toolkit::Visual::IMAGE)
1622     .Add(Toolkit::ImageVisual::Property::URL, TEST_RESOURCE_DIR "/Kid1.svg")
1623     .Add(ImageVisual::Property::DESIRED_WIDTH, 120)
1624     .Add(ImageVisual::Property::DESIRED_HEIGHT, 120)
1625     .Add(DevelVisual::Property::VISUAL_FITTING_MODE, Toolkit::DevelVisual::FILL)
1626     .Add(Visual::Property::TRANSFORM,
1627          Property::Map().Add(Toolkit::Visual::Transform::Property::OFFSET_POLICY,
1628                              Vector2(Visual::Transform::Policy::ABSOLUTE, Visual::Transform::Policy::ABSOLUTE))
1629            .Add(Toolkit::Visual::Transform::Property::OFFSET, Vector2(8, 8)));
1630
1631   imageView.SetProperty(Toolkit::ImageView::Property::IMAGE, imagePropertyMap);
1632   imageView.SetProperty(Actor::Property::ANCHOR_POINT, AnchorPoint::TOP_LEFT);
1633   imageView.SetProperty(Actor::Property::PARENT_ORIGIN, ParentOrigin::TOP_LEFT);
1634   application.GetScene().Add(imageView);
1635
1636   application.SendNotification();
1637   application.Render();
1638
1639   // Check whether Image Visual transforms on ImageVieiw::OnRelayout()
1640   Toolkit::Internal::Control& controlImpl = Toolkit::Internal::GetImplementation(imageView);
1641   Toolkit::Visual::Base       imageVisual = DevelControl::GetVisual(controlImpl, ImageView::Property::IMAGE);
1642   Property::Map               resultMap;
1643   imageVisual.CreatePropertyMap(resultMap);
1644
1645   Property::Value* transformValue = resultMap.Find(Visual::Property::TRANSFORM);
1646   DALI_TEST_CHECK(transformValue);
1647   Property::Map* retMap = transformValue->GetMap();
1648   DALI_TEST_CHECK(retMap);
1649
1650   // Image Visual should be positioned depending on ImageView's padding
1651   DALI_TEST_EQUALS(retMap->Find(Visual::Transform::Property::OFFSET)->Get<Vector2>(), Vector2(8, 8), TEST_LOCATION);
1652   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);
1653
1654   END_TEST;
1655 }
1656
1657 int UtcDaliImageViewUsingAtlasAndGetNaturalSize(void)
1658 {
1659   ToolkitTestApplication application;
1660
1661   // Check ImageView with background and main image, to ensure both visuals are marked as loaded
1662   ImageView     imageView = ImageView::New();
1663   Property::Map imageMap;
1664   imageMap[Toolkit::Visual::Property::TYPE]          = Toolkit::Visual::IMAGE;
1665   imageMap[Toolkit::ImageVisual::Property::URL]      = gImage_34_RGBA;
1666   imageMap[Toolkit::ImageVisual::Property::ATLASING] = true;
1667   imageView.SetProperty(Toolkit::ImageView::Property::IMAGE, imageMap);
1668   application.GetScene().Add(imageView);
1669
1670   // Trigger a potential relayout
1671   application.SendNotification();
1672   application.Render();
1673
1674   Vector3 naturalSize = imageView.GetNaturalSize();
1675
1676   DALI_TEST_EQUALS(naturalSize.width, 34.0f, TEST_LOCATION);
1677   DALI_TEST_EQUALS(naturalSize.height, 34.0f, TEST_LOCATION);
1678
1679   END_TEST;
1680 }
1681
1682 int UtcDaliImageViewFillMode(void)
1683 {
1684   ToolkitTestApplication application;
1685
1686   tet_infoline("Create an ImageVisual without padding and set the fill-mode to fill");
1687
1688   ImageView     imageView = ImageView::New();
1689   Property::Map imageMap;
1690   imageMap.Add(Toolkit::Visual::Property::TYPE, Toolkit::Visual::IMAGE);
1691   imageMap.Add(Toolkit::ImageVisual::Property::URL, gImage_600_RGB);
1692   imageMap.Add(DevelVisual::Property::VISUAL_FITTING_MODE, DevelVisual::FittingMode::FILL);
1693
1694   imageView.SetProperty(Toolkit::ImageView::Property::IMAGE, imageMap);
1695
1696   application.GetScene().Add(imageView);
1697
1698   // Trigger a potential relayout
1699   application.SendNotification();
1700   application.Render();
1701
1702   Toolkit::Visual::Base visual = DevelControl::GetVisual(Toolkit::Internal::GetImplementation(imageView), Toolkit::ImageView::Property::IMAGE);
1703   Property::Map         returnedMap;
1704   visual.CreatePropertyMap(returnedMap);
1705
1706   Property::Value* value = returnedMap.Find(Toolkit::Visual::Property::TRANSFORM);
1707   DALI_TEST_CHECK(value);
1708   Property::Map* map = value->GetMap();
1709   DALI_TEST_CHECK(map);
1710
1711   value = map->Find(Toolkit::Visual::Transform::Property::SIZE);
1712   DALI_TEST_CHECK(value);
1713   DALI_TEST_EQUALS(value->Get<Vector2>(), Vector2::ONE, TEST_LOCATION);
1714
1715   value = map->Find(Toolkit::Visual::Transform::Property::SIZE_POLICY);
1716   DALI_TEST_CHECK(value);
1717   DALI_TEST_CHECK(value->Get<int>() == Toolkit::Visual::Transform::Policy::RELATIVE);
1718
1719   END_TEST;
1720 }
1721
1722 int UtcDaliImageViewFittingModeFitKeepAspectRatio(void)
1723 {
1724   ToolkitTestApplication application;
1725
1726   tet_infoline("Create an ImageVisual using FitKeepAspectRatio ( image: [600,600], view: [600,700] )");
1727   tet_infoline("  There should be need to change the transform, offset is adjusted to fit inside");
1728
1729   ImageView     imageView = ImageView::New();
1730   Property::Map imageMap;
1731   imageMap.Add(Toolkit::Visual::Property::TYPE, Toolkit::Visual::IMAGE);
1732   imageMap.Add(Toolkit::ImageVisual::Property::URL, gImage_600_RGB); // 600x600 image
1733   imageMap.Add(DevelVisual::Property::VISUAL_FITTING_MODE, Toolkit::DevelVisual::FIT_KEEP_ASPECT_RATIO);
1734
1735   imageView.SetProperty(Toolkit::ImageView::Property::IMAGE, imageMap);
1736   imageView.SetProperty(Actor::Property::SIZE, Vector2(600, 700));
1737
1738   application.GetScene().Add(imageView);
1739
1740   // Trigger a potential relayout
1741   application.SendNotification();
1742   application.Render();
1743
1744   Toolkit::Visual::Base visual = DevelControl::GetVisual(Toolkit::Internal::GetImplementation(imageView), Toolkit::ImageView::Property::IMAGE);
1745   Property::Map         returnedMap;
1746   visual.CreatePropertyMap(returnedMap);
1747
1748   Property::Value* value = returnedMap.Find(Toolkit::Visual::Property::TRANSFORM);
1749   DALI_TEST_CHECK(value);
1750   Property::Map* map = value->GetMap();
1751   DALI_TEST_CHECK(map);
1752
1753   // If there's
1754   value = map->Find(Toolkit::Visual::Transform::Property::SIZE);
1755   DALI_TEST_CHECK(value);
1756   DALI_TEST_EQUALS(value->Get<Vector2>(), Vector2(600, 600), TEST_LOCATION);
1757
1758   value = map->Find(Toolkit::Visual::Transform::Property::SIZE_POLICY);
1759   DALI_TEST_CHECK(value);
1760   DALI_TEST_EQUALS(value->Get<Vector2>(), Vector2(Toolkit::Visual::Transform::Policy::ABSOLUTE, Toolkit::Visual::Transform::Policy::ABSOLUTE), TEST_LOCATION);
1761
1762   value = map->Find(Toolkit::Visual::Transform::Property::OFFSET);
1763   DALI_TEST_CHECK(value);
1764   DALI_TEST_EQUALS(value->Get<Vector2>(), Vector2(0, 50), TEST_LOCATION);
1765
1766   END_TEST;
1767 }
1768
1769 int UtcDaliImageViewFittingModesFill(void)
1770 {
1771   ToolkitTestApplication application;
1772
1773   tet_infoline("Create an ImageVisual using Fill ( image: [600,600], view: [600,700] )");
1774   tet_infoline("  There should be no need to change the transform, only size is changed to fit view");
1775
1776   ImageView     imageView = ImageView::New();
1777   Property::Map imageMap;
1778   imageMap.Add(Toolkit::Visual::Property::TYPE, Toolkit::Visual::IMAGE);
1779   imageMap.Add(Toolkit::ImageVisual::Property::URL, gImage_600_RGB); // 600x600 image
1780   imageMap.Add(DevelVisual::Property::VISUAL_FITTING_MODE, Toolkit::DevelVisual::FILL);
1781
1782   imageView.SetProperty(Toolkit::ImageView::Property::IMAGE, imageMap);
1783   imageView.SetProperty(Actor::Property::SIZE, Vector2(600, 700));
1784
1785   application.GetScene().Add(imageView);
1786
1787   // Trigger a potential relayout
1788   application.SendNotification();
1789   application.Render();
1790
1791   Toolkit::Visual::Base visual = DevelControl::GetVisual(Toolkit::Internal::GetImplementation(imageView), Toolkit::ImageView::Property::IMAGE);
1792   Property::Map         returnedMap;
1793   visual.CreatePropertyMap(returnedMap);
1794
1795   Property::Value* value = returnedMap.Find(Toolkit::Visual::Property::TRANSFORM);
1796   DALI_TEST_CHECK(value);
1797   Property::Map* map = value->GetMap();
1798   DALI_TEST_CHECK(map);
1799
1800   value = map->Find(Toolkit::Visual::Transform::Property::SIZE);
1801   DALI_TEST_CHECK(value);
1802   DALI_TEST_EQUALS(value->Get<Vector2>(), Vector2::ONE, TEST_LOCATION); // Change the internal size according to the image view size
1803
1804   value = map->Find(Toolkit::Visual::Transform::Property::SIZE_POLICY);
1805   DALI_TEST_CHECK(value);
1806   DALI_TEST_CHECK(value->Get<int>() == Toolkit::Visual::Transform::Policy::RELATIVE);
1807
1808   value = map->Find(Toolkit::Visual::Transform::Property::OFFSET);
1809   DALI_TEST_CHECK(value);
1810   DALI_TEST_EQUALS(value->Get<Vector2>(), Vector2(0, 0), TEST_LOCATION); // OFFSET is zero
1811
1812   END_TEST;
1813 }
1814
1815 int UtcDaliImageViewFittingModesOverfitKeepAspectRatio(void)
1816 {
1817   ToolkitTestApplication application;
1818
1819   tet_infoline("Create an ImageVisual using OverFitKeepAspectRatio ( image: [600,600], view: [600,500] )");
1820   tet_infoline("  offset or size is the same as view, but adjust internally using pixelArea ");
1821
1822   ImageView     imageView = ImageView::New();
1823   Property::Map imageMap;
1824   imageMap.Add(Toolkit::Visual::Property::TYPE, Toolkit::Visual::IMAGE);
1825   imageMap.Add(Toolkit::ImageVisual::Property::URL, gImage_600_RGB); // 600x600 image
1826   imageMap.Add(DevelVisual::Property::VISUAL_FITTING_MODE, Toolkit::DevelVisual::OVER_FIT_KEEP_ASPECT_RATIO);
1827
1828   imageView.SetProperty(Toolkit::ImageView::Property::IMAGE, imageMap);
1829   imageView.SetProperty(Actor::Property::SIZE, Vector2(600, 500));
1830
1831   application.GetScene().Add(imageView);
1832
1833   // Trigger a potential relayout
1834   application.SendNotification();
1835   application.Render();
1836
1837   Toolkit::Visual::Base visual = DevelControl::GetVisual(Toolkit::Internal::GetImplementation(imageView), Toolkit::ImageView::Property::IMAGE);
1838   Property::Map         returnedMap;
1839   visual.CreatePropertyMap(returnedMap);
1840
1841   Property::Value* value = returnedMap.Find(Toolkit::Visual::Property::TRANSFORM);
1842   DALI_TEST_CHECK(value);
1843   Property::Map* map = value->GetMap();
1844   DALI_TEST_CHECK(map);
1845
1846   // If there's
1847   value = map->Find(Toolkit::Visual::Transform::Property::SIZE);
1848   DALI_TEST_CHECK(value);
1849   DALI_TEST_EQUALS(value->Get<Vector2>(), Vector2(600, 500), TEST_LOCATION); // Change the internal size according to the image view size
1850
1851   value = map->Find(Toolkit::Visual::Transform::Property::SIZE_POLICY);
1852   DALI_TEST_CHECK(value);
1853   DALI_TEST_EQUALS(value->Get<Vector2>(), Vector2(Toolkit::Visual::Transform::Policy::ABSOLUTE, Toolkit::Visual::Transform::Policy::ABSOLUTE), TEST_LOCATION);
1854
1855   value = map->Find(Toolkit::Visual::Transform::Property::OFFSET);
1856   DALI_TEST_CHECK(value);
1857   DALI_TEST_EQUALS(value->Get<Vector2>(), Vector2(0, 0), TEST_LOCATION); // OFFSET is zero
1858
1859   END_TEST;
1860 }
1861
1862 int UtcDaliImageViewFittingModesCenter01(void)
1863 {
1864   ToolkitTestApplication application;
1865
1866   tet_infoline("Create an ImageVisual using Center ( image: [600,600], view: [700,700] )");
1867   tet_infoline("  There should be need to change the transform, offset is adjusted to fit inside");
1868
1869   ImageView     imageView = ImageView::New();
1870   Property::Map imageMap;
1871   imageMap.Add(Toolkit::Visual::Property::TYPE, Toolkit::Visual::IMAGE);
1872   imageMap.Add(Toolkit::ImageVisual::Property::URL, gImage_600_RGB); // 600x600 image
1873   imageMap.Add(DevelVisual::Property::VISUAL_FITTING_MODE, Toolkit::DevelVisual::CENTER);
1874
1875   imageView.SetProperty(Toolkit::ImageView::Property::IMAGE, imageMap);
1876   imageView.SetProperty(Actor::Property::SIZE, Vector2(700, 700));
1877
1878   application.GetScene().Add(imageView);
1879
1880   // Trigger a potential relayout
1881   application.SendNotification();
1882   application.Render();
1883
1884   Toolkit::Visual::Base visual = DevelControl::GetVisual(Toolkit::Internal::GetImplementation(imageView), Toolkit::ImageView::Property::IMAGE);
1885   Property::Map         returnedMap;
1886   visual.CreatePropertyMap(returnedMap);
1887
1888   Property::Value* value = returnedMap.Find(Toolkit::Visual::Property::TRANSFORM);
1889   DALI_TEST_CHECK(value);
1890   Property::Map* map = value->GetMap();
1891   DALI_TEST_CHECK(map);
1892
1893   value = map->Find(Toolkit::Visual::Transform::Property::SIZE);
1894   DALI_TEST_CHECK(value);
1895   DALI_TEST_EQUALS(value->Get<Vector2>(), Vector2(600, 600), TEST_LOCATION); // Change the internal size according to the image view size
1896
1897   value = map->Find(Toolkit::Visual::Transform::Property::SIZE_POLICY);
1898   DALI_TEST_CHECK(value);
1899   DALI_TEST_EQUALS(value->Get<Vector2>(), Vector2(Toolkit::Visual::Transform::Policy::ABSOLUTE, Toolkit::Visual::Transform::Policy::ABSOLUTE), TEST_LOCATION);
1900
1901   value = map->Find(Toolkit::Visual::Transform::Property::OFFSET);
1902   DALI_TEST_CHECK(value);
1903   DALI_TEST_EQUALS(value->Get<Vector2>(), Vector2(50, 50), TEST_LOCATION);
1904
1905   END_TEST;
1906 }
1907
1908 int UtcDaliImageViewFittingModesCenter02(void)
1909 {
1910   ToolkitTestApplication application;
1911
1912   tet_infoline("Create an ImageVisual using Center ( image: [600,600], view: [500,500] )");
1913   tet_infoline("  There should be need to change the transform, offset is adjusted to fit inside");
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); // 600x600 image
1919   imageMap.Add(DevelVisual::Property::VISUAL_FITTING_MODE, Toolkit::DevelVisual::CENTER);
1920
1921   imageView.SetProperty(Toolkit::ImageView::Property::IMAGE, imageMap);
1922   imageView.SetProperty(Actor::Property::SIZE, Vector2(700, 700));
1923
1924   application.GetScene().Add(imageView);
1925
1926   // Trigger a potential relayout
1927   application.SendNotification();
1928   application.Render();
1929
1930   Toolkit::Visual::Base visual = DevelControl::GetVisual(Toolkit::Internal::GetImplementation(imageView), Toolkit::ImageView::Property::IMAGE);
1931   Property::Map         returnedMap;
1932   visual.CreatePropertyMap(returnedMap);
1933
1934   Property::Value* value = returnedMap.Find(Toolkit::Visual::Property::TRANSFORM);
1935   DALI_TEST_CHECK(value);
1936   Property::Map* map = value->GetMap();
1937   DALI_TEST_CHECK(map);
1938
1939   value = map->Find(Toolkit::Visual::Transform::Property::SIZE);
1940   DALI_TEST_CHECK(value);
1941   DALI_TEST_EQUALS(value->Get<Vector2>(), Vector2(600, 600), TEST_LOCATION); // Change the internal size according to the image view size
1942
1943   value = map->Find(Toolkit::Visual::Transform::Property::SIZE_POLICY);
1944   DALI_TEST_CHECK(value);
1945   DALI_TEST_EQUALS(value->Get<Vector2>(), Vector2(Toolkit::Visual::Transform::Policy::ABSOLUTE, Toolkit::Visual::Transform::Policy::ABSOLUTE), TEST_LOCATION);
1946
1947   value = map->Find(Toolkit::Visual::Transform::Property::OFFSET);
1948   DALI_TEST_CHECK(value);
1949   DALI_TEST_EQUALS(value->Get<Vector2>(), Vector2(50, 50), TEST_LOCATION);
1950
1951   END_TEST;
1952 }
1953
1954 int UtcDaliImageViewFittingModesFitHeight01(void)
1955 {
1956   ToolkitTestApplication application;
1957
1958   tet_infoline("Create an ImageVisual using FitHeight ( image: [600,600], view: [600,700] )");
1959
1960   ImageView     imageView = ImageView::New();
1961   Property::Map imageMap;
1962   imageMap.Add(Toolkit::Visual::Property::TYPE, Toolkit::Visual::IMAGE);
1963   imageMap.Add(Toolkit::ImageVisual::Property::URL, gImage_600_RGB); // 600x600 image
1964   imageMap.Add(DevelVisual::Property::VISUAL_FITTING_MODE, Toolkit::DevelVisual::FIT_HEIGHT);
1965
1966   imageView.SetProperty(Toolkit::ImageView::Property::IMAGE, imageMap);
1967   imageView.SetProperty(Actor::Property::SIZE, Vector2(600, 700));
1968
1969   application.GetScene().Add(imageView);
1970
1971   // Trigger a potential relayout
1972   application.SendNotification();
1973   application.Render();
1974
1975   Toolkit::Visual::Base visual = DevelControl::GetVisual(Toolkit::Internal::GetImplementation(imageView), Toolkit::ImageView::Property::IMAGE);
1976   Property::Map         returnedMap;
1977   visual.CreatePropertyMap(returnedMap);
1978
1979   Property::Value* value = returnedMap.Find(Toolkit::Visual::Property::TRANSFORM);
1980   DALI_TEST_CHECK(value);
1981   Property::Map* map = value->GetMap();
1982   DALI_TEST_CHECK(map);
1983
1984   value = map->Find(Toolkit::Visual::Transform::Property::SIZE);
1985   DALI_TEST_CHECK(value);
1986   DALI_TEST_EQUALS(value->Get<Vector2>(), Vector2(600, 700), TEST_LOCATION); // Change the internal size according to the image view size
1987
1988   value = map->Find(Toolkit::Visual::Transform::Property::SIZE_POLICY);
1989   DALI_TEST_CHECK(value);
1990   DALI_TEST_EQUALS(value->Get<Vector2>(), Vector2(Toolkit::Visual::Transform::Policy::ABSOLUTE, Toolkit::Visual::Transform::Policy::ABSOLUTE), TEST_LOCATION);
1991
1992   value = map->Find(Toolkit::Visual::Transform::Property::OFFSET);
1993   DALI_TEST_CHECK(value);
1994   DALI_TEST_EQUALS(value->Get<Vector2>(), Vector2(0, 0), TEST_LOCATION); // OFFSET is zero
1995
1996   END_TEST;
1997 }
1998
1999 int UtcDaliImageViewFittingModesFitHeight02(void)
2000 {
2001   ToolkitTestApplication application;
2002
2003   tet_infoline("Create an ImageVisual using FitHeight ( image: [600,600], view: [700,600] )");
2004
2005   ImageView     imageView = ImageView::New();
2006   Property::Map imageMap;
2007   imageMap.Add(Toolkit::Visual::Property::TYPE, Toolkit::Visual::IMAGE);
2008   imageMap.Add(Toolkit::ImageVisual::Property::URL, gImage_600_RGB); // 249x169 image
2009   imageMap.Add(DevelVisual::Property::VISUAL_FITTING_MODE, Toolkit::DevelVisual::FIT_HEIGHT);
2010
2011   imageView.SetProperty(Toolkit::ImageView::Property::IMAGE, imageMap);
2012   imageView.SetProperty(Actor::Property::SIZE, Vector2(700, 600));
2013
2014   application.GetScene().Add(imageView);
2015
2016   // Trigger a potential relayout
2017   application.SendNotification();
2018   application.Render();
2019
2020   Toolkit::Visual::Base visual = DevelControl::GetVisual(Toolkit::Internal::GetImplementation(imageView), Toolkit::ImageView::Property::IMAGE);
2021   Property::Map         returnedMap;
2022   visual.CreatePropertyMap(returnedMap);
2023
2024   Property::Value* value = returnedMap.Find(Toolkit::Visual::Property::TRANSFORM);
2025   DALI_TEST_CHECK(value);
2026   Property::Map* map = value->GetMap();
2027   DALI_TEST_CHECK(map);
2028
2029   value = map->Find(Toolkit::Visual::Transform::Property::SIZE);
2030   DALI_TEST_CHECK(value);
2031   DALI_TEST_EQUALS(value->Get<Vector2>(), Vector2(600, 600), TEST_LOCATION); // Change the internal size according to the image view size
2032
2033   value = map->Find(Toolkit::Visual::Transform::Property::SIZE_POLICY);
2034   DALI_TEST_CHECK(value);
2035   DALI_TEST_EQUALS(value->Get<Vector2>(), Vector2(Toolkit::Visual::Transform::Policy::ABSOLUTE, Toolkit::Visual::Transform::Policy::ABSOLUTE), TEST_LOCATION);
2036
2037   value = map->Find(Toolkit::Visual::Transform::Property::OFFSET);
2038   DALI_TEST_CHECK(value);
2039   DALI_TEST_EQUALS(value->Get<Vector2>(), Vector2(50, 0), TEST_LOCATION);
2040
2041   END_TEST;
2042 }
2043
2044 int UtcDaliImageViewFittingModesFitWidth01(void)
2045 {
2046   ToolkitTestApplication application;
2047
2048   tet_infoline("Create an ImageVisual using FitWidth ( image: [600,600], view: [600,700] )");
2049
2050   ImageView     imageView = ImageView::New();
2051   Property::Map imageMap;
2052   imageMap.Add(Toolkit::Visual::Property::TYPE, Toolkit::Visual::IMAGE);
2053   imageMap.Add(Toolkit::ImageVisual::Property::URL, gImage_600_RGB); // 600x600 image
2054   imageMap.Add(DevelVisual::Property::VISUAL_FITTING_MODE, Toolkit::DevelVisual::FIT_WIDTH);
2055
2056   imageView.SetProperty(Toolkit::ImageView::Property::IMAGE, imageMap);
2057   imageView.SetProperty(Actor::Property::SIZE, Vector2(600, 700));
2058
2059   application.GetScene().Add(imageView);
2060
2061   // Trigger a potential relayout
2062   application.SendNotification();
2063   application.Render();
2064
2065   Toolkit::Visual::Base visual = DevelControl::GetVisual(Toolkit::Internal::GetImplementation(imageView), Toolkit::ImageView::Property::IMAGE);
2066   Property::Map         returnedMap;
2067   visual.CreatePropertyMap(returnedMap);
2068
2069   Property::Value* value = returnedMap.Find(Toolkit::Visual::Property::TRANSFORM);
2070   DALI_TEST_CHECK(value);
2071   Property::Map* map = value->GetMap();
2072   DALI_TEST_CHECK(map);
2073
2074   value = map->Find(Toolkit::Visual::Transform::Property::SIZE);
2075   DALI_TEST_CHECK(value);
2076   DALI_TEST_EQUALS(value->Get<Vector2>(), Vector2(600, 600), 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, 50), TEST_LOCATION);
2085
2086   END_TEST;
2087 }
2088
2089 int UtcDaliImageViewFittingModesFitWidth02(void)
2090 {
2091   ToolkitTestApplication application;
2092
2093   tet_infoline("Create an ImageVisual using FitWidth ( image: [600,600], view:[700,600] )");
2094
2095   ImageView     imageView = ImageView::New();
2096   Property::Map imageMap;
2097   imageMap.Add(Toolkit::Visual::Property::TYPE, Toolkit::Visual::IMAGE);
2098   imageMap.Add(Toolkit::ImageVisual::Property::URL, gImage_600_RGB); // 249x169 image
2099   imageMap.Add(DevelVisual::Property::VISUAL_FITTING_MODE, Toolkit::DevelVisual::FIT_WIDTH);
2100
2101   imageView.SetProperty(Toolkit::ImageView::Property::IMAGE, imageMap);
2102   imageView.SetProperty(Actor::Property::SIZE, Vector2(700, 600));
2103
2104   application.GetScene().Add(imageView);
2105
2106   // Trigger a potential relayout
2107   application.SendNotification();
2108   application.Render();
2109
2110   Toolkit::Visual::Base visual = DevelControl::GetVisual(Toolkit::Internal::GetImplementation(imageView), Toolkit::ImageView::Property::IMAGE);
2111   Property::Map         returnedMap;
2112   visual.CreatePropertyMap(returnedMap);
2113
2114   Property::Value* value = returnedMap.Find(Toolkit::Visual::Property::TRANSFORM);
2115   DALI_TEST_CHECK(value);
2116   Property::Map* map = value->GetMap();
2117   DALI_TEST_CHECK(map);
2118
2119   value = map->Find(Toolkit::Visual::Transform::Property::SIZE);
2120   DALI_TEST_CHECK(value);
2121   DALI_TEST_EQUALS(value->Get<Vector2>(), Vector2(700, 600), TEST_LOCATION); // Change the internal size according to the image view size
2122
2123   value = map->Find(Toolkit::Visual::Transform::Property::SIZE_POLICY);
2124   DALI_TEST_CHECK(value);
2125   DALI_TEST_EQUALS(value->Get<Vector2>(), Vector2(Toolkit::Visual::Transform::Policy::ABSOLUTE, Toolkit::Visual::Transform::Policy::ABSOLUTE), TEST_LOCATION);
2126
2127   value = map->Find(Toolkit::Visual::Transform::Property::OFFSET);
2128   DALI_TEST_CHECK(value);
2129   DALI_TEST_EQUALS(value->Get<Vector2>(), Vector2(0, 0), TEST_LOCATION); // OFFSET is zero
2130
2131   END_TEST;
2132 }
2133
2134 int UtcDaliImageViewFittingModesChangeFittingMode01(void)
2135 {
2136   ToolkitTestApplication application;
2137
2138   tet_infoline("UtcDaliImageViewFittingModesChangeFittingMode, image: [600,600], view:[800,700]");
2139
2140   ImageView imageView = ImageView::New();
2141
2142   // 1. Render using FittingMode::SHRINK_TO_FIT
2143   Property::Map imageMap;
2144   imageMap[Toolkit::Visual::Property::TYPE]            = Toolkit::Visual::IMAGE;
2145   imageMap[Toolkit::ImageVisual::Property::URL]        = gImage_600_RGB;
2146   imageMap[DevelVisual::Property::VISUAL_FITTING_MODE] = Toolkit::DevelVisual::FIT_KEEP_ASPECT_RATIO;
2147
2148   imageView.SetProperty(Toolkit::ImageView::Property::IMAGE, imageMap);
2149   imageView.SetProperty(Actor::Property::SIZE, Vector2(800, 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(700, 700), 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, 0), TEST_LOCATION);
2177
2178   // 2. Render again using DevelVisaul::CENTER
2179   Property::Map imageMap2;
2180   imageMap2[Toolkit::Visual::Property::TYPE]            = Toolkit::Visual::IMAGE;
2181   imageMap2[Toolkit::ImageVisual::Property::URL]        = gImage_600_RGB;
2182   imageMap2[DevelVisual::Property::VISUAL_FITTING_MODE] = Toolkit::DevelVisual::CENTER;
2183
2184   imageView.SetProperty(Toolkit::ImageView::Property::IMAGE, imageMap2);
2185   imageView.SetProperty(Actor::Property::SIZE, Vector2(800, 700));
2186
2187   application.GetScene().Add(imageView);
2188
2189   DALI_TEST_EQUALS(Test::WaitForEventThreadTrigger(1), true, TEST_LOCATION);
2190
2191   // Trigger a potential relayout
2192   application.SendNotification();
2193   application.Render();
2194
2195   returnedMap.Clear();
2196   visual = DevelControl::GetVisual(Toolkit::Internal::GetImplementation(imageView), Toolkit::ImageView::Property::IMAGE);
2197
2198   visual.CreatePropertyMap(returnedMap);
2199
2200   value = returnedMap.Find(Toolkit::Visual::Property::TRANSFORM);
2201   DALI_TEST_CHECK(value);
2202   map = value->GetMap();
2203   DALI_TEST_CHECK(map);
2204
2205   value = map->Find(Toolkit::Visual::Transform::Property::SIZE);
2206   DALI_TEST_CHECK(value);
2207   DALI_TEST_EQUALS(value->Get<Vector2>(), Vector2(600, 600), TEST_LOCATION); // Change the internal size according to the image view size
2208
2209   value = map->Find(Toolkit::Visual::Transform::Property::SIZE_POLICY);
2210   DALI_TEST_CHECK(value);
2211   DALI_TEST_EQUALS(value->Get<Vector2>(), Vector2(Toolkit::Visual::Transform::Policy::ABSOLUTE, Toolkit::Visual::Transform::Policy::ABSOLUTE), TEST_LOCATION);
2212
2213   value = map->Find(Toolkit::Visual::Transform::Property::OFFSET);
2214   DALI_TEST_CHECK(value);
2215   DALI_TEST_EQUALS(value->Get<Vector2>(), Vector2(100, 50), TEST_LOCATION);
2216
2217   // 3. Render again using before fittingMode
2218   Property::Map imageMap3;
2219   imageMap3[Toolkit::Visual::Property::TYPE]            = Toolkit::Visual::IMAGE;
2220   imageMap3[Toolkit::ImageVisual::Property::URL]        = gImage_600_RGB;
2221   imageMap3[DevelVisual::Property::VISUAL_FITTING_MODE] = Toolkit::DevelVisual::FIT_KEEP_ASPECT_RATIO;
2222
2223   imageView.SetProperty(Toolkit::ImageView::Property::IMAGE, imageMap3);
2224   imageView.SetProperty(Actor::Property::SIZE, Vector2(800, 700));
2225
2226   application.GetScene().Add(imageView);
2227
2228   // Trigger a potential relayout
2229   application.SendNotification();
2230   application.Render();
2231
2232   returnedMap.Clear();
2233   visual = DevelControl::GetVisual(Toolkit::Internal::GetImplementation(imageView), Toolkit::ImageView::Property::IMAGE);
2234   visual.CreatePropertyMap(returnedMap);
2235
2236   value = returnedMap.Find(Toolkit::Visual::Property::TRANSFORM);
2237   DALI_TEST_CHECK(value);
2238   map = value->GetMap();
2239   DALI_TEST_CHECK(map);
2240
2241   value = map->Find(Toolkit::Visual::Transform::Property::SIZE);
2242   DALI_TEST_CHECK(value);
2243   DALI_TEST_EQUALS(value->Get<Vector2>(), Vector2(700, 700), TEST_LOCATION); // Change the internal size according to the image view size
2244
2245   value = map->Find(Toolkit::Visual::Transform::Property::SIZE_POLICY);
2246   DALI_TEST_CHECK(value);
2247   DALI_TEST_EQUALS(value->Get<Vector2>(), Vector2(Toolkit::Visual::Transform::Policy::ABSOLUTE, Toolkit::Visual::Transform::Policy::ABSOLUTE), TEST_LOCATION);
2248
2249   value = map->Find(Toolkit::Visual::Transform::Property::OFFSET);
2250   DALI_TEST_CHECK(value);
2251   DALI_TEST_EQUALS(value->Get<Vector2>(), Vector2(50, 0), TEST_LOCATION);
2252
2253   END_TEST;
2254 }
2255
2256 int UtcDaliImageViewFittingModesChangeFittingMode02(void)
2257 {
2258   ToolkitTestApplication application;
2259
2260   tet_infoline("UtcDaliImageViewFittingModesChangeFittingMode, image: [600,600], view:[800,700]");
2261
2262   ImageView imageView = ImageView::New();
2263
2264   // 1. Render using FittingMode::OVER_FIT_KEEP_ASPECT_RATIO
2265   Property::Map imageMap;
2266   imageMap[Toolkit::Visual::Property::TYPE]            = Toolkit::Visual::IMAGE;
2267   imageMap[Toolkit::ImageVisual::Property::URL]        = gImage_600_RGB;
2268   imageMap[DevelVisual::Property::VISUAL_FITTING_MODE] = Toolkit::DevelVisual::OVER_FIT_KEEP_ASPECT_RATIO;
2269
2270   imageView.SetProperty(Toolkit::ImageView::Property::IMAGE, imageMap);
2271   imageView.SetProperty(Actor::Property::SIZE, Vector2(800, 700));
2272
2273   application.GetScene().Add(imageView);
2274
2275   // Trigger a potential relayout
2276   application.SendNotification();
2277   application.Render();
2278
2279   Toolkit::Visual::Base visual = DevelControl::GetVisual(Toolkit::Internal::GetImplementation(imageView), Toolkit::ImageView::Property::IMAGE);
2280   Property::Map         returnedMap;
2281   visual.CreatePropertyMap(returnedMap);
2282
2283   Property::Value* value = returnedMap.Find(Toolkit::Visual::Property::TRANSFORM);
2284   DALI_TEST_CHECK(value);
2285   Property::Map* map = value->GetMap();
2286   DALI_TEST_CHECK(map);
2287
2288   value = map->Find(Toolkit::Visual::Transform::Property::SIZE);
2289   DALI_TEST_CHECK(value);
2290   DALI_TEST_EQUALS(value->Get<Vector2>(), Vector2(800, 700), TEST_LOCATION); // Change the internal size according to the image view size
2291
2292   value = map->Find(Toolkit::Visual::Transform::Property::SIZE_POLICY);
2293   DALI_TEST_CHECK(value);
2294   DALI_TEST_EQUALS(value->Get<Vector2>(), Vector2(Toolkit::Visual::Transform::Policy::ABSOLUTE, Toolkit::Visual::Transform::Policy::ABSOLUTE), TEST_LOCATION);
2295
2296   value = map->Find(Toolkit::Visual::Transform::Property::OFFSET);
2297   DALI_TEST_CHECK(value);
2298   DALI_TEST_EQUALS(value->Get<Vector2>(), Vector2(0, 0), TEST_LOCATION);
2299
2300   // 2. Render again using DevelVisaul::CENTER
2301   Property::Map imageMap2;
2302   imageMap2[Toolkit::Visual::Property::TYPE]            = Toolkit::Visual::IMAGE;
2303   imageMap2[Toolkit::ImageVisual::Property::URL]        = gImage_600_RGB;
2304   imageMap2[DevelVisual::Property::VISUAL_FITTING_MODE] = Toolkit::DevelVisual::CENTER;
2305
2306   imageView.SetProperty(Toolkit::ImageView::Property::IMAGE, imageMap2);
2307   imageView.SetProperty(Actor::Property::SIZE, Vector2(800, 700));
2308
2309   application.GetScene().Add(imageView);
2310
2311   DALI_TEST_EQUALS(Test::WaitForEventThreadTrigger(1), true, TEST_LOCATION);
2312
2313   // Trigger a potential relayout
2314   application.SendNotification();
2315   application.Render();
2316
2317   returnedMap.Clear();
2318   visual = DevelControl::GetVisual(Toolkit::Internal::GetImplementation(imageView), Toolkit::ImageView::Property::IMAGE);
2319
2320   visual.CreatePropertyMap(returnedMap);
2321
2322   value = returnedMap.Find(Toolkit::Visual::Property::TRANSFORM);
2323   DALI_TEST_CHECK(value);
2324   map = value->GetMap();
2325   DALI_TEST_CHECK(map);
2326
2327   value = map->Find(Toolkit::Visual::Transform::Property::SIZE);
2328   DALI_TEST_CHECK(value);
2329   DALI_TEST_EQUALS(value->Get<Vector2>(), Vector2(600, 600), TEST_LOCATION); // Change the internal size according to the image view size
2330
2331   value = map->Find(Toolkit::Visual::Transform::Property::SIZE_POLICY);
2332   DALI_TEST_CHECK(value);
2333   DALI_TEST_EQUALS(value->Get<Vector2>(), Vector2(Toolkit::Visual::Transform::Policy::ABSOLUTE, Toolkit::Visual::Transform::Policy::ABSOLUTE), TEST_LOCATION);
2334
2335   value = map->Find(Toolkit::Visual::Transform::Property::OFFSET);
2336   DALI_TEST_CHECK(value);
2337   DALI_TEST_EQUALS(value->Get<Vector2>(), Vector2(100, 50), TEST_LOCATION);
2338
2339   // 3. Render again using before fittingMode
2340   Property::Map imageMap3;
2341   imageMap3[Toolkit::Visual::Property::TYPE]            = Toolkit::Visual::IMAGE;
2342   imageMap3[Toolkit::ImageVisual::Property::URL]        = gImage_600_RGB;
2343   imageMap3[DevelVisual::Property::VISUAL_FITTING_MODE] = Toolkit::DevelVisual::OVER_FIT_KEEP_ASPECT_RATIO;
2344
2345   imageView.SetProperty(Toolkit::ImageView::Property::IMAGE, imageMap3);
2346   imageView.SetProperty(Actor::Property::SIZE, Vector2(800, 700));
2347
2348   application.GetScene().Add(imageView);
2349
2350   // Trigger a potential relayout
2351   application.SendNotification();
2352   application.Render();
2353
2354   returnedMap.Clear();
2355   visual = DevelControl::GetVisual(Toolkit::Internal::GetImplementation(imageView), Toolkit::ImageView::Property::IMAGE);
2356   visual.CreatePropertyMap(returnedMap);
2357
2358   value = returnedMap.Find(Toolkit::Visual::Property::TRANSFORM);
2359   DALI_TEST_CHECK(value);
2360   map = value->GetMap();
2361   DALI_TEST_CHECK(map);
2362
2363   value = map->Find(Toolkit::Visual::Transform::Property::SIZE);
2364   DALI_TEST_CHECK(value);
2365   DALI_TEST_EQUALS(value->Get<Vector2>(), Vector2(800, 700), TEST_LOCATION); // Change the internal size according to the image view size
2366
2367   value = map->Find(Toolkit::Visual::Transform::Property::SIZE_POLICY);
2368   DALI_TEST_CHECK(value);
2369   DALI_TEST_EQUALS(value->Get<Vector2>(), Vector2(Toolkit::Visual::Transform::Policy::ABSOLUTE, Toolkit::Visual::Transform::Policy::ABSOLUTE), TEST_LOCATION);
2370
2371   value = map->Find(Toolkit::Visual::Transform::Property::OFFSET);
2372   DALI_TEST_CHECK(value);
2373   DALI_TEST_EQUALS(value->Get<Vector2>(), Vector2(0, 0), TEST_LOCATION);
2374
2375   END_TEST;
2376 }
2377
2378 int UtcDaliImageViewFittingModesWithAnimatedVectorImageVisual(void)
2379 {
2380   ToolkitTestApplication application;
2381
2382   tet_infoline("Create an ImageVisual using SCALE_TO_FILL and animated vector image ( image: [600,600], view:[600,600] )");
2383
2384   ImageView     imageView = ImageView::New();
2385   Property::Map imageMap;
2386   imageMap.Add(Toolkit::Visual::Property::TYPE, DevelVisual::ANIMATED_VECTOR_IMAGE);
2387   imageMap.Add(Toolkit::ImageVisual::Property::URL, TEST_ANIMATED_VECTOR_IMAGE_FILE_NAME); // 249x169 image
2388
2389   imageView.SetProperty(Toolkit::ImageView::Property::IMAGE, imageMap);
2390   imageView.SetProperty(Actor::Property::SIZE, Vector2(600, 600));
2391
2392   application.GetScene().Add(imageView);
2393
2394   // Trigger a potential relayout
2395   application.SendNotification();
2396   application.Render();
2397
2398   Toolkit::Visual::Base visual = DevelControl::GetVisual(Toolkit::Internal::GetImplementation(imageView), Toolkit::ImageView::Property::IMAGE);
2399   Property::Map         returnedMap;
2400   visual.CreatePropertyMap(returnedMap);
2401
2402   Property::Value* value = returnedMap.Find(Toolkit::Visual::Property::TRANSFORM);
2403   DALI_TEST_CHECK(value);
2404   Property::Map* map = value->GetMap();
2405   DALI_TEST_CHECK(map);
2406
2407   value = map->Find(Toolkit::Visual::Transform::Property::SIZE);
2408   DALI_TEST_CHECK(value);
2409   DALI_TEST_EQUALS(value->Get<Vector2>(), Vector2::ONE, TEST_LOCATION); // Relative size so will take up 100%
2410
2411   value = map->Find(Toolkit::Visual::Transform::Property::SIZE_POLICY);
2412   DALI_TEST_CHECK(value);
2413   DALI_TEST_CHECK(value->Get<int>() == Toolkit::Visual::Transform::Policy::RELATIVE);
2414
2415   value = map->Find(Toolkit::Visual::Transform::Property::OFFSET);
2416   DALI_TEST_CHECK(value);
2417   DALI_TEST_EQUALS(value->Get<Vector2>(), Vector2(0, 0), TEST_LOCATION); // OFFSET is zero
2418
2419   END_TEST;
2420 }
2421
2422 int UtcDaliImageViewCustomShader(void)
2423 {
2424   ToolkitTestApplication application;
2425
2426   // Set a custom shader with an image url
2427   {
2428     Property::Map     properties;
2429     Property::Map     shader;
2430     const std::string vertexShader                    = "Foobar";
2431     const std::string fragmentShader                  = "Foobar";
2432     shader[Visual::Shader::Property::FRAGMENT_SHADER] = fragmentShader;
2433     shader[Visual::Shader::Property::VERTEX_SHADER]   = vertexShader;
2434
2435     properties[Visual::Property::TYPE]     = Visual::IMAGE;
2436     properties[Visual::Property::SHADER]   = shader;
2437     properties[ImageVisual::Property::URL] = TEST_IMAGE_FILE_NAME;
2438
2439     ImageView imageView = ImageView::New();
2440     imageView.SetProperty(ImageView::Property::IMAGE, properties);
2441
2442     application.GetScene().Add(imageView);
2443
2444     application.SendNotification();
2445     application.Render();
2446
2447     DALI_TEST_EQUALS(Test::WaitForEventThreadTrigger(1), true, TEST_LOCATION);
2448
2449     Renderer        renderer = imageView.GetRendererAt(0);
2450     Shader          shader2  = renderer.GetShader();
2451     Property::Value value    = shader2.GetProperty(Shader::Property::PROGRAM);
2452     Property::Map*  map      = value.GetMap();
2453     DALI_TEST_CHECK(map);
2454
2455     Property::Value* fragment = map->Find("fragment"); // fragment key name from shader-impl.cpp
2456     DALI_TEST_EQUALS(fragmentShader, fragment->Get<std::string>(), TEST_LOCATION);
2457
2458     Property::Value* vertex = map->Find("vertex"); // vertex key name from shader-impl.cpp
2459     DALI_TEST_EQUALS(vertexShader, vertex->Get<std::string>(), TEST_LOCATION);
2460   }
2461
2462   // Set a custom shader after setting an image url
2463   {
2464     Property::Map     properties;
2465     Property::Map     shader;
2466     const std::string vertexShader                    = "Foobar";
2467     const std::string fragmentShader                  = "Foobar";
2468     shader[Visual::Shader::Property::FRAGMENT_SHADER] = fragmentShader;
2469     shader[Visual::Shader::Property::VERTEX_SHADER]   = vertexShader;
2470
2471     properties[Visual::Property::SHADER] = shader;
2472
2473     ImageView imageView = ImageView::New(TEST_IMAGE_FILE_NAME);
2474     imageView.SetProperty(ImageView::Property::IMAGE, properties);
2475
2476     application.GetScene().Add(imageView);
2477
2478     application.SendNotification();
2479     application.Render();
2480
2481     DALI_TEST_EQUALS(Test::WaitForEventThreadTrigger(1), true, TEST_LOCATION);
2482
2483     Renderer        renderer = imageView.GetRendererAt(0);
2484     Shader          shader2  = renderer.GetShader();
2485     Property::Value value    = shader2.GetProperty(Shader::Property::PROGRAM);
2486     Property::Map*  map      = value.GetMap();
2487     DALI_TEST_CHECK(map);
2488
2489     Property::Value* fragment = map->Find("fragment"); // fragment key name from shader-impl.cpp
2490     DALI_TEST_EQUALS(fragmentShader, fragment->Get<std::string>(), TEST_LOCATION);
2491
2492     Property::Value* vertex = map->Find("vertex"); // vertex key name from shader-impl.cpp
2493     DALI_TEST_EQUALS(vertexShader, vertex->Get<std::string>(), TEST_LOCATION);
2494   }
2495
2496   // Set a custom shader before setting an image url
2497   {
2498     Property::Map     properties;
2499     Property::Map     shader;
2500     const std::string vertexShader                    = "Foobar";
2501     const std::string fragmentShader                  = "Foobar";
2502     shader[Visual::Shader::Property::FRAGMENT_SHADER] = fragmentShader;
2503     shader[Visual::Shader::Property::VERTEX_SHADER]   = vertexShader;
2504
2505     properties[Visual::Property::SHADER] = shader;
2506
2507     ImageView imageView = ImageView::New();
2508     imageView.SetProperty(ImageView::Property::IMAGE, properties);
2509     imageView.SetProperty(ImageView::Property::IMAGE, TEST_IMAGE_FILE_NAME);
2510
2511     application.GetScene().Add(imageView);
2512
2513     application.SendNotification();
2514     application.Render();
2515     DALI_TEST_EQUALS(Test::WaitForEventThreadTrigger(1), true, TEST_LOCATION);
2516
2517     Renderer        renderer = imageView.GetRendererAt(0);
2518     Shader          shader2  = renderer.GetShader();
2519     Property::Value value    = shader2.GetProperty(Shader::Property::PROGRAM);
2520     Property::Map*  map      = value.GetMap();
2521     DALI_TEST_CHECK(map);
2522
2523     Property::Value* fragment = map->Find("fragment"); // fragment key name from shader-impl.cpp
2524     DALI_TEST_EQUALS(fragmentShader, fragment->Get<std::string>(), TEST_LOCATION);
2525
2526     Property::Value* vertex = map->Find("vertex"); // vertex key name from shader-impl.cpp
2527     DALI_TEST_EQUALS(vertexShader, vertex->Get<std::string>(), TEST_LOCATION);
2528   }
2529
2530   // Set a custom shader after setting a property map
2531   {
2532     Property::Map     properties;
2533     Property::Map     shader;
2534     const std::string vertexShader                    = "Foobar";
2535     const std::string fragmentShader                  = "Foobar";
2536     shader[Visual::Shader::Property::FRAGMENT_SHADER] = fragmentShader;
2537     shader[Visual::Shader::Property::VERTEX_SHADER]   = vertexShader;
2538
2539     properties[Visual::Property::SHADER] = shader;
2540
2541     Property::Map properties1;
2542     properties1[Visual::Property::TYPE]     = Visual::IMAGE;
2543     properties1[ImageVisual::Property::URL] = TEST_IMAGE_FILE_NAME;
2544
2545     ImageView imageView = ImageView::New();
2546     imageView.SetProperty(ImageView::Property::IMAGE, properties1);
2547     imageView.SetProperty(ImageView::Property::IMAGE, properties);
2548
2549     application.GetScene().Add(imageView);
2550
2551     application.SendNotification();
2552     application.Render();
2553     DALI_TEST_EQUALS(Test::WaitForEventThreadTrigger(1), true, TEST_LOCATION);
2554
2555     Renderer        renderer = imageView.GetRendererAt(0);
2556     Shader          shader2  = renderer.GetShader();
2557     Property::Value value    = shader2.GetProperty(Shader::Property::PROGRAM);
2558     Property::Map*  map      = value.GetMap();
2559     DALI_TEST_CHECK(map);
2560
2561     Property::Value* fragment = map->Find("fragment"); // fragment key name from shader-impl.cpp
2562     DALI_TEST_EQUALS(fragmentShader, fragment->Get<std::string>(), TEST_LOCATION);
2563
2564     Property::Value* vertex = map->Find("vertex"); // vertex key name from shader-impl.cpp
2565     DALI_TEST_EQUALS(vertexShader, vertex->Get<std::string>(), TEST_LOCATION);
2566   }
2567
2568   // Set a custom shader before setting a property map
2569   {
2570     Property::Map     properties;
2571     Property::Map     shader;
2572     const std::string vertexShader                    = "Foobar";
2573     const std::string fragmentShader                  = "Foobar";
2574     shader[Visual::Shader::Property::FRAGMENT_SHADER] = fragmentShader;
2575     shader[Visual::Shader::Property::VERTEX_SHADER]   = vertexShader;
2576
2577     properties[Visual::Property::SHADER] = shader;
2578
2579     Property::Map properties1;
2580     properties1[Visual::Property::TYPE]     = Visual::IMAGE;
2581     properties1[ImageVisual::Property::URL] = TEST_IMAGE_FILE_NAME;
2582
2583     ImageView imageView = ImageView::New();
2584     imageView.SetProperty(ImageView::Property::IMAGE, properties);
2585     imageView.SetProperty(ImageView::Property::IMAGE, properties1);
2586
2587     application.GetScene().Add(imageView);
2588
2589     application.SendNotification();
2590     application.Render();
2591     DALI_TEST_EQUALS(Test::WaitForEventThreadTrigger(1), true, TEST_LOCATION);
2592
2593     Renderer        renderer = imageView.GetRendererAt(0);
2594     Shader          shader2  = renderer.GetShader();
2595     Property::Value value    = shader2.GetProperty(Shader::Property::PROGRAM);
2596     Property::Map*  map      = value.GetMap();
2597     DALI_TEST_CHECK(map);
2598
2599     Property::Value* fragment = map->Find("fragment"); // fragment key name from shader-impl.cpp
2600     DALI_TEST_EQUALS(fragmentShader, fragment->Get<std::string>(), TEST_LOCATION);
2601
2602     Property::Value* vertex = map->Find("vertex"); // vertex key name from shader-impl.cpp
2603     DALI_TEST_EQUALS(vertexShader, vertex->Get<std::string>(), TEST_LOCATION);
2604   }
2605
2606   END_TEST;
2607 }
2608
2609 namespace
2610 {
2611 static int gFailCounter = 0;
2612 const int  MAX_RETRIES(3);
2613
2614 void ReloadImage(ImageView imageView)
2615 {
2616   Property::Map imageImmediateLoadingMap;
2617   imageImmediateLoadingMap[ImageVisual::Property::URL]         = "Non-existant-image.jpg";
2618   imageImmediateLoadingMap[ImageVisual::Property::LOAD_POLICY] = ImageVisual::LoadPolicy::IMMEDIATE;
2619
2620   tet_infoline("Immediate load an image");
2621   imageView.SetProperty(ImageView::Property::IMAGE, imageImmediateLoadingMap);
2622 }
2623
2624 void ResourceFailedReload(Control control)
2625 {
2626   gFailCounter++;
2627   if(gFailCounter < MAX_RETRIES)
2628   {
2629     ReloadImage(ImageView::DownCast(control));
2630   }
2631 }
2632 } // namespace
2633
2634 int UtcDaliImageViewReloadFailedOnResourceReadySignal(void)
2635 {
2636   tet_infoline("Test reloading failed image from within signal handler.");
2637
2638   ToolkitTestApplication application;
2639
2640   gFailCounter = 0;
2641
2642   ImageView imageView = ImageView::New();
2643   imageView.ResourceReadySignal().Connect(&ResourceFailedReload);
2644   DALI_TEST_EQUALS(gFailCounter, 0, TEST_LOCATION);
2645   ReloadImage(imageView);
2646
2647   // loading started, this waits for the loader thread to complete
2648   DALI_TEST_EQUALS(Test::WaitForEventThreadTrigger(1), true, TEST_LOCATION);
2649   application.SendNotification();
2650
2651   DALI_TEST_EQUALS(gFailCounter, 1, TEST_LOCATION);
2652
2653   DALI_TEST_EQUALS(Test::WaitForEventThreadTrigger(1), true, TEST_LOCATION);
2654   application.SendNotification();
2655
2656   DALI_TEST_EQUALS(gFailCounter, 2, TEST_LOCATION);
2657
2658   DALI_TEST_EQUALS(Test::WaitForEventThreadTrigger(1), true, TEST_LOCATION);
2659   application.SendNotification();
2660   DALI_TEST_EQUALS(gFailCounter, 3, TEST_LOCATION);
2661
2662   END_TEST;
2663 }
2664
2665 int UtcDaliImageViewLoadRemoteSVG(void)
2666 {
2667   tet_infoline("Test load from a remote server.");
2668
2669   ToolkitTestApplication application;
2670
2671   {
2672     Toolkit::ImageView imageView;
2673     imageView = Toolkit::ImageView::New();
2674     imageView.SetImage("https://dev.w3.org/SVG/tools/svgweb/samples/svg-files/check.svg");
2675     imageView.SetProperty(Actor::Property::PARENT_ORIGIN, ParentOrigin::TOP_LEFT);
2676     imageView.SetProperty(Actor::Property::ANCHOR_POINT, AnchorPoint::TOP_LEFT);
2677     imageView.SetProperty(Actor::Property::SIZE, Vector2(300, 300));
2678     imageView.SetProperty(Actor::Property::POSITION, Vector3(150.0f, 150.0f, 0.0f));
2679
2680     application.GetScene().Add(imageView);
2681
2682     DALI_TEST_CHECK(imageView);
2683
2684     DALI_TEST_EQUALS(imageView.GetRendererCount(), 0u, TEST_LOCATION);
2685
2686     application.SendNotification();
2687
2688     DALI_TEST_EQUALS(Test::WaitForEventThreadTrigger(1), true, TEST_LOCATION);
2689
2690     application.SendNotification();
2691     application.Render();
2692
2693     DALI_TEST_EQUALS(imageView.GetRendererCount(), 1u, TEST_LOCATION);
2694   }
2695
2696   // Without size set
2697   {
2698     Toolkit::ImageView imageView;
2699     imageView = Toolkit::ImageView::New();
2700     imageView.SetImage("https://dev.w3.org/SVG/tools/svgweb/samples/svg-files/check.svg");
2701     imageView.SetProperty(Actor::Property::PARENT_ORIGIN, ParentOrigin::TOP_LEFT);
2702     imageView.SetProperty(Actor::Property::ANCHOR_POINT, AnchorPoint::TOP_LEFT);
2703     imageView.SetProperty(Actor::Property::POSITION, Vector3(150.0f, 150.0f, 0.0f));
2704
2705     application.GetScene().Add(imageView);
2706
2707     DALI_TEST_CHECK(imageView);
2708
2709     DALI_TEST_EQUALS(imageView.GetRendererCount(), 0u, TEST_LOCATION);
2710
2711     application.SendNotification();
2712
2713     DALI_TEST_EQUALS(Test::WaitForEventThreadTrigger(1), true, TEST_LOCATION);
2714
2715     application.SendNotification();
2716     application.Render();
2717
2718     DALI_TEST_EQUALS(imageView.GetRendererCount(), 1u, TEST_LOCATION);
2719   }
2720
2721   END_TEST;
2722 }
2723
2724 int UtcDaliImageViewSyncSVGLoading(void)
2725 {
2726   ToolkitTestApplication application;
2727
2728   tet_infoline("ImageView Testing SVG image sync loading");
2729
2730   // Sync loading, automatic atlasing for small size image
2731   {
2732     TraceCallStack& callStack = application.GetGlAbstraction().GetTextureTrace();
2733     callStack.Reset();
2734     callStack.Enable(true);
2735
2736     ImageView imageView = ImageView::New();
2737
2738     // Sync loading is used
2739     Property::Map syncLoadingMap;
2740     syncLoadingMap.Insert(Toolkit::Visual::Property::TYPE, Toolkit::Visual::IMAGE);
2741     syncLoadingMap.Insert(Toolkit::ImageVisual::Property::URL, TEST_RESOURCE_DIR "/svg1.svg");
2742     syncLoadingMap.Insert(Toolkit::ImageVisual::Property::SYNCHRONOUS_LOADING, true);
2743     imageView.SetProperty(ImageView::Property::IMAGE, syncLoadingMap);
2744
2745     application.GetScene().Add(imageView);
2746     DALI_TEST_CHECK(imageView);
2747
2748     application.SendNotification();
2749     application.Render(16);
2750     Vector3 naturalSize = imageView.GetNaturalSize();
2751
2752     DALI_TEST_EQUALS(naturalSize.width, 100.0f, TEST_LOCATION);
2753     DALI_TEST_EQUALS(naturalSize.height, 100.0f, TEST_LOCATION);
2754   }
2755   END_TEST;
2756 }
2757
2758 int UtcDaliImageViewAsyncSVGLoading(void)
2759 {
2760   ToolkitTestApplication application;
2761
2762   tet_infoline("ImageView Testing SVG image async loading");
2763
2764   // Sync loading, automatic atlasing for small size image
2765   {
2766     TraceCallStack& callStack = application.GetGlAbstraction().GetTextureTrace();
2767     callStack.Reset();
2768     callStack.Enable(true);
2769
2770     ImageView imageView = ImageView::New();
2771
2772     // Sync loading is used
2773     Property::Map syncLoadingMap;
2774     syncLoadingMap.Insert(Toolkit::Visual::Property::TYPE, Toolkit::Visual::IMAGE);
2775     syncLoadingMap.Insert(Toolkit::ImageVisual::Property::URL, TEST_RESOURCE_DIR "/svg1.svg");
2776     syncLoadingMap.Insert(Toolkit::ImageVisual::Property::SYNCHRONOUS_LOADING, false);
2777     imageView.SetProperty(ImageView::Property::IMAGE, syncLoadingMap);
2778
2779     application.GetScene().Add(imageView);
2780     DALI_TEST_CHECK(imageView);
2781
2782     application.SendNotification();
2783     application.Render(16);
2784     Vector3 naturalSize = imageView.GetNaturalSize();
2785
2786     DALI_TEST_EQUALS(naturalSize.width, 100.0f, TEST_LOCATION);
2787     DALI_TEST_EQUALS(naturalSize.height, 100.0f, TEST_LOCATION);
2788   }
2789   END_TEST;
2790 }
2791
2792 int UtcDaliImageViewSVGLoadingSyncSetInvalidValue(void)
2793 {
2794   ToolkitTestApplication application;
2795
2796   tet_infoline("ImageView Testing SVG image async loading");
2797
2798   // Sync loading, automatic atlasing for small size image
2799   {
2800     TraceCallStack& callStack = application.GetGlAbstraction().GetTextureTrace();
2801     callStack.Reset();
2802     callStack.Enable(true);
2803
2804     ImageView imageView = ImageView::New();
2805
2806     // Sync loading is used
2807     Property::Map syncLoadingMap;
2808     syncLoadingMap.Insert(Toolkit::Visual::Property::TYPE, Toolkit::Visual::IMAGE);
2809     syncLoadingMap.Insert(Toolkit::ImageVisual::Property::URL, TEST_RESOURCE_DIR "/svg1.svg");
2810
2811     // Check to set invalid value
2812     // The SYNCHRONOUS_LOADING property must be set to the bool value.
2813     // Check if error log is outputted when setting other value like string.
2814     // Even if the wrong value is set, the image will be shown normally, and the synchronous value should be the default value(false).
2815     syncLoadingMap.Insert(Toolkit::ImageVisual::Property::SYNCHRONOUS_LOADING, std::to_string(5));
2816     imageView.SetProperty(ImageView::Property::IMAGE, syncLoadingMap);
2817
2818     application.GetScene().Add(imageView);
2819     DALI_TEST_CHECK(imageView);
2820
2821     application.SendNotification();
2822     application.Render(16);
2823     Vector3 naturalSize = imageView.GetNaturalSize();
2824     DALI_TEST_EQUALS(naturalSize.width, 100.0f, TEST_LOCATION);
2825     DALI_TEST_EQUALS(naturalSize.height, 100.0f, TEST_LOCATION);
2826
2827     Property::Value value = imageView.GetProperty(ImageView::Property::IMAGE);
2828     Property::Map*  map   = value.GetMap();
2829     DALI_TEST_CHECK(map);
2830
2831     Property::Value* sync = map->Find(Toolkit::ImageVisual::Property::SYNCHRONOUS_LOADING);
2832     DALI_TEST_CHECK(sync);
2833     DALI_TEST_EQUALS(false, sync->Get<bool>(), TEST_LOCATION);
2834   }
2835   END_TEST;
2836 }
2837
2838 int UtcDaliImageViewSvgLoadingFailure(void)
2839 {
2840   ToolkitTestApplication application;
2841
2842   TestGlAbstraction& gl           = application.GetGlAbstraction();
2843   TraceCallStack&    textureTrace = gl.GetTextureTrace();
2844   textureTrace.Enable(true);
2845
2846   // Local svg file - invalid file path
2847   {
2848     gResourceReadySignalFired = false;
2849
2850     ImageView imageView = ImageView::New(TEST_RESOURCE_DIR "/foo.svg");
2851     imageView.SetProperty(Actor::Property::SIZE, Vector2(200.f, 200.f));
2852     imageView.ResourceReadySignal().Connect(&ResourceReadySignal);
2853
2854     DALI_TEST_EQUALS(imageView.IsResourceReady(), false, TEST_LOCATION);
2855
2856     application.GetScene().Add(imageView);
2857
2858     application.SendNotification();
2859     application.Render(16);
2860
2861     DALI_TEST_EQUALS(gResourceReadySignalFired, true, TEST_LOCATION);
2862     DALI_TEST_EQUALS(imageView.IsResourceReady(), true, TEST_LOCATION);
2863     DALI_TEST_EQUALS(imageView.GetVisualResourceStatus(ImageView::Property::IMAGE), Visual::ResourceStatus::FAILED, TEST_LOCATION);
2864
2865     // Should be shown a broken image
2866     DALI_TEST_EQUALS(imageView.GetRendererCount(), 1u, TEST_LOCATION);
2867     DALI_TEST_EQUALS(textureTrace.FindMethod("BindTexture"), true, TEST_LOCATION);
2868   }
2869
2870   // Local svg file - invalid file path without size set
2871   {
2872     gResourceReadySignalFired = false;
2873     textureTrace.Reset();
2874
2875     ImageView imageView = ImageView::New(TEST_RESOURCE_DIR "/foo.svg");
2876     imageView.ResourceReadySignal().Connect(&ResourceReadySignal);
2877
2878     DALI_TEST_EQUALS(imageView.IsResourceReady(), false, TEST_LOCATION);
2879
2880     application.GetScene().Add(imageView);
2881
2882     application.SendNotification();
2883     application.Render(16);
2884
2885     DALI_TEST_EQUALS(gResourceReadySignalFired, true, TEST_LOCATION);
2886     DALI_TEST_EQUALS(imageView.IsResourceReady(), true, TEST_LOCATION);
2887     DALI_TEST_EQUALS(imageView.GetVisualResourceStatus(ImageView::Property::IMAGE), Visual::ResourceStatus::FAILED, TEST_LOCATION);
2888
2889     // Should be shown a broken image
2890     DALI_TEST_EQUALS(imageView.GetRendererCount(), 1u, TEST_LOCATION);
2891     DALI_TEST_EQUALS(textureTrace.FindMethod("BindTexture"), true, TEST_LOCATION);
2892   }
2893
2894   // Local svg file - invalid file
2895   {
2896     gResourceReadySignalFired = false;
2897     textureTrace.Reset();
2898
2899     ImageView imageView = ImageView::New(TEST_RESOURCE_DIR "/invalid.svg");
2900     imageView.SetProperty(Actor::Property::SIZE, Vector2(200.f, 200.f));
2901     imageView.ResourceReadySignal().Connect(&ResourceReadySignal);
2902
2903     DALI_TEST_EQUALS(imageView.IsResourceReady(), false, TEST_LOCATION);
2904
2905     application.GetScene().Add(imageView);
2906
2907     application.SendNotification();
2908     application.Render(16);
2909
2910     DALI_TEST_EQUALS(gResourceReadySignalFired, true, TEST_LOCATION);
2911     DALI_TEST_EQUALS(imageView.IsResourceReady(), true, TEST_LOCATION);
2912     DALI_TEST_EQUALS(imageView.GetVisualResourceStatus(ImageView::Property::IMAGE), Visual::ResourceStatus::FAILED, TEST_LOCATION);
2913
2914     // Should be shown a broken image
2915     DALI_TEST_EQUALS(imageView.GetRendererCount(), 1u, TEST_LOCATION);
2916     DALI_TEST_EQUALS(textureTrace.FindMethod("BindTexture"), true, TEST_LOCATION);
2917   }
2918
2919   // Remote svg file
2920   {
2921     gResourceReadySignalFired = false;
2922     textureTrace.Reset();
2923
2924     ImageView imageView = ImageView::New("https://bar.org/foobar.svg");
2925     imageView.SetProperty(Actor::Property::SIZE, Vector2(200.f, 200.f));
2926     imageView.ResourceReadySignal().Connect(&ResourceReadySignal);
2927
2928     DALI_TEST_EQUALS(imageView.IsResourceReady(), false, TEST_LOCATION);
2929
2930     application.GetScene().Add(imageView);
2931
2932     application.SendNotification();
2933
2934     // loading started, this waits for the loader thread
2935     DALI_TEST_EQUALS(Test::WaitForEventThreadTrigger(1), true, TEST_LOCATION);
2936
2937     application.SendNotification();
2938     application.Render(16);
2939
2940     DALI_TEST_EQUALS(gResourceReadySignalFired, true, TEST_LOCATION);
2941     DALI_TEST_EQUALS(imageView.IsResourceReady(), true, TEST_LOCATION);
2942     DALI_TEST_EQUALS(imageView.GetVisualResourceStatus(ImageView::Property::IMAGE), Visual::ResourceStatus::FAILED, TEST_LOCATION);
2943
2944     // Should be shown a broken image
2945     DALI_TEST_EQUALS(imageView.GetRendererCount(), 1u, TEST_LOCATION);
2946     DALI_TEST_EQUALS(textureTrace.FindMethod("BindTexture"), true, TEST_LOCATION);
2947   }
2948
2949   // Remote svg file without size set
2950   {
2951     gResourceReadySignalFired = false;
2952     textureTrace.Reset();
2953
2954     ImageView imageView = ImageView::New("https://bar.org/foobar.svg");
2955     imageView.ResourceReadySignal().Connect(&ResourceReadySignal);
2956
2957     DALI_TEST_EQUALS(imageView.IsResourceReady(), false, TEST_LOCATION);
2958
2959     application.GetScene().Add(imageView);
2960
2961     application.SendNotification();
2962
2963     // loading started, this waits for the loader thread
2964     DALI_TEST_EQUALS(Test::WaitForEventThreadTrigger(1), true, TEST_LOCATION);
2965
2966     application.SendNotification();
2967     application.Render(16);
2968
2969     DALI_TEST_EQUALS(gResourceReadySignalFired, true, TEST_LOCATION);
2970     DALI_TEST_EQUALS(imageView.IsResourceReady(), true, TEST_LOCATION);
2971     DALI_TEST_EQUALS(imageView.GetVisualResourceStatus(ImageView::Property::IMAGE), Visual::ResourceStatus::FAILED, TEST_LOCATION);
2972
2973     // Should be shown a broken image
2974     DALI_TEST_EQUALS(imageView.GetRendererCount(), 1u, TEST_LOCATION);
2975     DALI_TEST_EQUALS(textureTrace.FindMethod("BindTexture"), true, TEST_LOCATION);
2976   }
2977
2978   END_TEST;
2979 }
2980
2981 int UtcDaliImageViewSvgRasterizationFailure(void)
2982 {
2983   ToolkitTestApplication application;
2984
2985   gResourceReadySignalFired = false;
2986
2987   TestGlAbstraction& gl           = application.GetGlAbstraction();
2988   TraceCallStack&    textureTrace = gl.GetTextureTrace();
2989   textureTrace.Enable(true);
2990
2991   ImageView imageView = ImageView::New(TEST_RESOURCE_DIR "/invalid1.svg");
2992   imageView.SetProperty(Actor::Property::SIZE, Vector2(200.f, 200.f));
2993   imageView.ResourceReadySignal().Connect(&ResourceReadySignal);
2994
2995   DALI_TEST_EQUALS(imageView.IsResourceReady(), false, TEST_LOCATION);
2996
2997   application.GetScene().Add(imageView);
2998
2999   application.SendNotification();
3000
3001   // loading started, this waits for the loader thread
3002   DALI_TEST_EQUALS(Test::WaitForEventThreadTrigger(1), true, TEST_LOCATION);
3003
3004   application.SendNotification();
3005   application.Render(16);
3006
3007   DALI_TEST_EQUALS(gResourceReadySignalFired, true, TEST_LOCATION);
3008   DALI_TEST_EQUALS(imageView.IsResourceReady(), true, TEST_LOCATION);
3009   DALI_TEST_EQUALS(imageView.GetVisualResourceStatus(ImageView::Property::IMAGE), Visual::ResourceStatus::FAILED, TEST_LOCATION);
3010
3011   // Should be shown a broken image
3012   DALI_TEST_EQUALS(imageView.GetRendererCount(), 1u, TEST_LOCATION);
3013   DALI_TEST_EQUALS(textureTrace.FindMethod("BindTexture"), true, TEST_LOCATION);
3014
3015   END_TEST;
3016 }
3017
3018 int UtcDaliImageViewTVGLoading(void)
3019 {
3020   ToolkitTestApplication application;
3021
3022   tet_infoline("ImageView Testing TVG image loading");
3023
3024   {
3025     ImageView imageView = ImageView::New();
3026
3027     imageView.SetImage(TEST_RESOURCE_DIR "/test.tvg");
3028
3029     application.GetScene().Add(imageView);
3030     DALI_TEST_CHECK(imageView);
3031     Vector3 naturalSize = imageView.GetNaturalSize();
3032
3033     DALI_TEST_EQUALS(naturalSize.width, 100.0f, TEST_LOCATION);
3034     DALI_TEST_EQUALS(naturalSize.height, 100.0f, TEST_LOCATION);
3035   }
3036   END_TEST;
3037 }
3038
3039 int UtcDaliImageViewImageLoadFailure01(void)
3040 {
3041   ToolkitTestApplication application;
3042
3043   Toolkit::StyleManager styleManager = Toolkit::StyleManager::Get();
3044   DevelStyleManager::SetBrokenImageUrl(styleManager, DevelStyleManager::BrokenImageType::SMALL, TEST_BROKEN_IMAGE_S);
3045   DevelStyleManager::SetBrokenImageUrl(styleManager, DevelStyleManager::BrokenImageType::NORMAL, TEST_BROKEN_IMAGE_M);
3046   DevelStyleManager::SetBrokenImageUrl(styleManager, DevelStyleManager::BrokenImageType::LARGE, TEST_BROKEN_IMAGE_L);
3047
3048   std::string brokenUrl;
3049   brokenUrl = DevelStyleManager::GetBrokenImageUrl(styleManager, DevelStyleManager::BrokenImageType::SMALL);
3050   DALI_TEST_EQUALS(TEST_BROKEN_IMAGE_S, brokenUrl, TEST_LOCATION);
3051
3052   brokenUrl = DevelStyleManager::GetBrokenImageUrl(styleManager, DevelStyleManager::BrokenImageType::NORMAL);
3053   DALI_TEST_EQUALS(TEST_BROKEN_IMAGE_M, brokenUrl, TEST_LOCATION);
3054
3055   brokenUrl = DevelStyleManager::GetBrokenImageUrl(styleManager, DevelStyleManager::BrokenImageType::LARGE);
3056   DALI_TEST_EQUALS(TEST_BROKEN_IMAGE_L, brokenUrl, TEST_LOCATION);
3057
3058   ImageView imageView = ImageView::New("invalidUrl.png");
3059   imageView.SetProperty(Actor::Property::SIZE, Vector2(200.f, 200.f));
3060
3061   application.GetScene().Add(imageView);
3062   application.SendNotification();
3063   application.Render(16);
3064
3065   // loading started, this waits for the loader thread
3066   DALI_TEST_EQUALS(Test::WaitForEventThreadTrigger(1), true, TEST_LOCATION);
3067
3068   END_TEST;
3069 }
3070
3071 int UtcDaliImageViewImageLoadFailure02(void)
3072 {
3073   ToolkitTestApplication application;
3074
3075   Toolkit::StyleManager styleManager = Toolkit::StyleManager::Get();
3076   DevelStyleManager::SetBrokenImageUrl(styleManager, DevelStyleManager::BrokenImageType::SMALL, TEST_BROKEN_IMAGE_DEFAULT);
3077   DevelStyleManager::SetBrokenImageUrl(styleManager, DevelStyleManager::BrokenImageType::NORMAL, TEST_BROKEN_IMAGE_M);
3078   DevelStyleManager::SetBrokenImageUrl(styleManager, DevelStyleManager::BrokenImageType::LARGE, TEST_BROKEN_IMAGE_L);
3079
3080   std::string brokenUrl;
3081   brokenUrl = DevelStyleManager::GetBrokenImageUrl(styleManager, DevelStyleManager::BrokenImageType::SMALL);
3082   DALI_TEST_EQUALS(TEST_BROKEN_IMAGE_DEFAULT, brokenUrl, TEST_LOCATION);
3083
3084   brokenUrl = DevelStyleManager::GetBrokenImageUrl(styleManager, DevelStyleManager::BrokenImageType::NORMAL);
3085   DALI_TEST_EQUALS(TEST_BROKEN_IMAGE_M, brokenUrl, TEST_LOCATION);
3086
3087   brokenUrl = DevelStyleManager::GetBrokenImageUrl(styleManager, DevelStyleManager::BrokenImageType::LARGE);
3088   DALI_TEST_EQUALS(TEST_BROKEN_IMAGE_L, brokenUrl, TEST_LOCATION);
3089
3090   ImageView imageView = ImageView::New("invalidUrl.png");
3091   imageView.SetProperty(Actor::Property::SIZE, Vector2(30.f, 30.f));
3092   application.GetScene().Add(imageView);
3093   application.SendNotification();
3094   application.Render(16);
3095
3096   // loading started, this waits for the loader thread
3097   DALI_TEST_EQUALS(Test::WaitForEventThreadTrigger(1), true, TEST_LOCATION);
3098
3099   END_TEST;
3100 }
3101
3102 int UtcDaliImageViewImageLoadFailure03(void)
3103 {
3104   ToolkitTestApplication application;
3105
3106   Toolkit::StyleManager styleManager = Toolkit::StyleManager::Get();
3107   DevelStyleManager::SetBrokenImageUrl(styleManager, DevelStyleManager::BrokenImageType::SMALL, TEST_BROKEN_IMAGE_01);
3108   DevelStyleManager::SetBrokenImageUrl(styleManager, DevelStyleManager::BrokenImageType::NORMAL, TEST_BROKEN_IMAGE_02);
3109
3110   std::string brokenUrl;
3111   brokenUrl = DevelStyleManager::GetBrokenImageUrl(styleManager, DevelStyleManager::BrokenImageType::SMALL);
3112   DALI_TEST_EQUALS(TEST_BROKEN_IMAGE_01, brokenUrl, TEST_LOCATION);
3113
3114   brokenUrl = DevelStyleManager::GetBrokenImageUrl(styleManager, DevelStyleManager::BrokenImageType::NORMAL);
3115   DALI_TEST_EQUALS(TEST_BROKEN_IMAGE_02, brokenUrl, TEST_LOCATION);
3116
3117   ImageView imageView = ImageView::New("invalidUrl.png");
3118   imageView.SetProperty(Actor::Property::SIZE, Vector2(100.f, 100.f));
3119   application.GetScene().Add(imageView);
3120   application.SendNotification();
3121   application.Render(16);
3122
3123   // loading started, this waits for the loader thread
3124   DALI_TEST_EQUALS(Test::WaitForEventThreadTrigger(1), true, TEST_LOCATION);
3125
3126   END_TEST;
3127 }
3128
3129 int UtcDaliImageViewImageLoadFailure04(void)
3130 {
3131   ToolkitTestApplication application;
3132
3133   ImageView imageView = ImageView::New("invalidUrl.png");
3134   imageView.SetProperty(Actor::Property::SIZE, Vector2(100.f, 100.f));
3135   application.GetScene().Add(imageView);
3136   application.SendNotification();
3137   application.Render(16);
3138
3139   // loading started, this waits for the loader thread
3140   DALI_TEST_EQUALS(Test::WaitForEventThreadTrigger(1), true, TEST_LOCATION);
3141
3142   Toolkit::StyleManager styleManager = Toolkit::StyleManager::Get();
3143   DevelStyleManager::SetBrokenImageUrl(styleManager, DevelStyleManager::BrokenImageType::SMALL, TEST_BROKEN_IMAGE_S);
3144   DevelStyleManager::SetBrokenImageUrl(styleManager, DevelStyleManager::BrokenImageType::NORMAL, "invalidBroken.png");
3145   DevelStyleManager::SetBrokenImageUrl(styleManager, DevelStyleManager::BrokenImageType::LARGE, TEST_BROKEN_IMAGE_L);
3146
3147   ImageView imageView2 = ImageView::New("invalidUrl.png");
3148   imageView2.SetProperty(Actor::Property::SIZE, Vector2(100.f, 100.f));
3149   application.GetScene().Add(imageView2);
3150
3151   std::string brokenUrl;
3152   brokenUrl = DevelStyleManager::GetBrokenImageUrl(styleManager, DevelStyleManager::BrokenImageType::SMALL);
3153   DALI_TEST_EQUALS(TEST_BROKEN_IMAGE_S, brokenUrl, TEST_LOCATION);
3154
3155   brokenUrl = DevelStyleManager::GetBrokenImageUrl(styleManager, DevelStyleManager::BrokenImageType::LARGE);
3156   DALI_TEST_EQUALS(TEST_BROKEN_IMAGE_L, brokenUrl, TEST_LOCATION);
3157
3158   application.SendNotification();
3159   application.Render(16);
3160
3161   // loading started, this waits for the loader thread
3162   DALI_TEST_EQUALS(Test::WaitForEventThreadTrigger(1), true, TEST_LOCATION);
3163
3164   DevelStyleManager::SetBrokenImageUrl(styleManager, DevelStyleManager::BrokenImageType::NORMAL, "invalidBroken.9.png");
3165
3166   ImageView imageView3 = ImageView::New("invalidUrl.png");
3167   imageView3.SetProperty(Actor::Property::SIZE, Vector2(100.f, 100.f));
3168   application.GetScene().Add(imageView3);
3169
3170   application.SendNotification();
3171   application.Render(16);
3172
3173   // loading started, this waits for the loader thread
3174   DALI_TEST_EQUALS(Test::WaitForEventThreadTrigger(1), true, TEST_LOCATION);
3175
3176   END_TEST;
3177 }
3178
3179 namespace
3180 {
3181 static int gResourceReadySignalCounter = 0;
3182
3183 void OnResourceReadySignal01(Control control)
3184 {
3185   gResourceReadySignalCounter++;
3186
3187   if(control.GetVisualResourceStatus(ImageView::Property::IMAGE) == Visual::ResourceStatus::READY)
3188   {
3189     if(gResourceReadySignalCounter == 1)
3190     {
3191       // Set image twice
3192       // It makes the first new visual be deleted immediately
3193       ImageView::DownCast(control).SetImage(gImage_34_RGBA);
3194       ImageView::DownCast(control).SetImage(gImage_34_RGBA);
3195     }
3196   }
3197   else if(control.GetVisualResourceStatus(ImageView::Property::IMAGE) == Visual::ResourceStatus::FAILED)
3198   {
3199     // Make the resource ready immediately
3200     control[ImageView::Property::IMAGE] = gImage_600_RGB;
3201   }
3202 }
3203
3204 void OnResourceReadySignal02(Control control)
3205 {
3206   if(++gResourceReadySignalCounter == 1)
3207   {
3208     // It makes the first new visual be deleted immediately
3209     // The first image will not be loaded.
3210     control[ImageView::Property::IMAGE] = Property::Map().Add(ImageVisual::Property::URL, gImage_600_RGB).Add(ImageVisual::Property::RELEASE_POLICY, ImageVisual::ReleasePolicy::NEVER);
3211     control[ImageView::Property::IMAGE] = TEST_IMAGE_1;
3212   }
3213 }
3214
3215 ImageView gImageView1;
3216 ImageView gImageView2;
3217 ImageView gImageView3;
3218 ImageView gImageView4;
3219
3220 void OnResourceReadySignal03(Control control)
3221 {
3222   if(gResourceReadySignalCounter == 0)
3223   {
3224     // Queue loading
3225     // 1. Use cached image, then LoadComplete will be called right after OnResourceReadySignal03.
3226     gImageView2[ImageView::Property::IMAGE] = gImage_34_RGBA;
3227
3228     // 2. Load a new image
3229     gImageView3[ImageView::Property::IMAGE] = TEST_IMAGE_1;
3230
3231     // 3. Use the new image again
3232     gImageView1[ImageView::Property::IMAGE] = TEST_IMAGE_1;
3233     gImageView1.ResourceReadySignal().Connect(&OnResourceReadySignal03);
3234   }
3235   else if(gResourceReadySignalCounter == 1)
3236   {
3237     // This is called from TextureManager::ProcessQueuedTextures().
3238     gImageView1.Unparent();
3239     gImageView1.Reset();
3240   }
3241   gResourceReadySignalCounter++;
3242 }
3243
3244 void OnSimpleResourceReadySignal(Control control)
3245 {
3246   // simply increate counter
3247   gResourceReadySignalCounter++;
3248 }
3249
3250 int gResourceReadySignal04ComesOrder = 0;
3251
3252 void OnResourceReadySignal04(Control control)
3253 {
3254   gResourceReadySignalCounter++;
3255   tet_printf("rc %d\n", gResourceReadySignalCounter);
3256   if(gResourceReadySignalCounter == 1)
3257   {
3258     auto scene = gImageView1.GetParent();
3259
3260     // Request load something
3261     // We hope this request result is return later than gImageView2.
3262     gImageView3 = ImageView::New(TEST_IMAGE_1);
3263     gImageView3.ResourceReadySignal().Connect(&OnResourceReadySignal04);
3264     scene.Add(gImageView3);
3265     gImageView4 = ImageView::New(TEST_IMAGE_2);
3266     gImageView4.ResourceReadySignal().Connect(&OnResourceReadySignal04);
3267     scene.Add(gImageView4);
3268
3269     if(control == gImageView1)
3270     {
3271       gResourceReadySignal04ComesOrder = 1;
3272     }
3273     else
3274     {
3275       gResourceReadySignal04ComesOrder = 2;
3276     }
3277   }
3278   if(gResourceReadySignalCounter == 2)
3279   {
3280     if(gResourceReadySignal04ComesOrder == 1 && control == gImageView2)
3281     {
3282       // Scene off first one.
3283       gImageView1.Unparent();
3284
3285       // Scene off second one.
3286       gImageView2.Unparent();
3287     }
3288     else if(gResourceReadySignal04ComesOrder == 2 && control == gImageView1)
3289     {
3290       // Scene off first one.
3291       gImageView2.Unparent();
3292
3293       // Scene off second one.
3294       gImageView1.Unparent();
3295     }
3296     else
3297     {
3298       // We can't check that this utc fail case. just pass always when we come here.
3299       gResourceReadySignal04ComesOrder = -1;
3300     }
3301
3302     // If we don't seperate index of FreeList area
3303     // and if we don't queue remove during obversing,
3304     // cache index become something invalid data.
3305     // In this case, some strange observer can be called.
3306     // For example, gImageView4.LoadComplete will be called.
3307   }
3308 }
3309
3310 } // namespace
3311
3312 int UtcDaliImageViewSetImageOnResourceReadySignal01(void)
3313 {
3314   tet_infoline("Test setting image from within signal handler.");
3315
3316   ToolkitTestApplication application;
3317
3318   gResourceReadySignalCounter = 0;
3319
3320   ImageView imageView = ImageView::New(gImage_34_RGBA);
3321   imageView.ResourceReadySignal().Connect(&OnResourceReadySignal01);
3322
3323   application.GetScene().Add(imageView);
3324
3325   DALI_TEST_EQUALS(Test::WaitForEventThreadTrigger(1), true, TEST_LOCATION);
3326
3327   application.SendNotification();
3328   application.Render();
3329
3330   DALI_TEST_EQUALS(gResourceReadySignalCounter, 2, TEST_LOCATION);
3331
3332   DALI_TEST_EQUALS(imageView.IsResourceReady(), true, TEST_LOCATION);
3333
3334   // Create a new ImageView to cache the image
3335   ImageView imageView1 = ImageView::New(gImage_600_RGB);
3336   application.GetScene().Add(imageView1);
3337
3338   DALI_TEST_EQUALS(Test::WaitForEventThreadTrigger(1), true, TEST_LOCATION);
3339
3340   application.SendNotification();
3341   application.Render();
3342
3343   // Reset count
3344   gResourceReadySignalCounter = 0;
3345
3346   imageView[ImageView::Property::IMAGE] = "invalid.jpg";
3347
3348   DALI_TEST_EQUALS(Test::WaitForEventThreadTrigger(1), true, TEST_LOCATION);
3349
3350   application.SendNotification();
3351   application.Render();
3352
3353   // Run idle callback
3354   application.RunIdles();
3355
3356   DALI_TEST_EQUALS(gResourceReadySignalCounter, 2, TEST_LOCATION);
3357
3358   DALI_TEST_EQUALS(imageView.IsResourceReady(), true, TEST_LOCATION);
3359
3360   END_TEST;
3361 }
3362
3363 int UtcDaliImageViewSetImageOnResourceReadySignal02(void)
3364 {
3365   tet_infoline("Test setting image from within signal handler.");
3366
3367   ToolkitTestApplication application;
3368
3369   gResourceReadySignalCounter = 0;
3370
3371   ImageView imageView = ImageView::New(gImage_34_RGBA);
3372   imageView.ResourceReadySignal().Connect(&OnResourceReadySignal02);
3373
3374   application.GetScene().Add(imageView);
3375
3376   DALI_TEST_EQUALS(Test::WaitForEventThreadTrigger(1), true, TEST_LOCATION);
3377
3378   application.SendNotification();
3379   application.Render();
3380
3381   // Wait for loading an image
3382   DALI_TEST_EQUALS(Test::WaitForEventThreadTrigger(1), true, TEST_LOCATION);
3383
3384   DALI_TEST_EQUALS(gResourceReadySignalCounter, 2, TEST_LOCATION);
3385
3386   DALI_TEST_EQUALS(imageView.IsResourceReady(), true, TEST_LOCATION);
3387
3388   END_TEST;
3389 }
3390
3391 int UtcDaliImageViewSetImageOnResourceReadySignal03(void)
3392 {
3393   tet_infoline("Test setting image from within signal handler.");
3394
3395   ToolkitTestApplication application;
3396
3397   gResourceReadySignalCounter = 0;
3398
3399   gImageView1 = ImageView::New(gImage_34_RGBA);
3400   application.GetScene().Add(gImageView1);
3401
3402   // Wait for loading
3403   DALI_TEST_EQUALS(Test::WaitForEventThreadTrigger(1), true, TEST_LOCATION);
3404
3405   gImageView2 = ImageView::New(gImage_600_RGB);
3406   gImageView2.ResourceReadySignal().Connect(&OnResourceReadySignal03);
3407   application.GetScene().Add(gImageView2);
3408
3409   gImageView3 = ImageView::New();
3410   application.GetScene().Add(gImageView3);
3411
3412   DALI_TEST_EQUALS(Test::WaitForEventThreadTrigger(2), true, TEST_LOCATION);
3413
3414   application.SendNotification();
3415   application.Render();
3416
3417   END_TEST;
3418 }
3419
3420 int UtcDaliImageViewOnResourceReadySignalWithBrokenAlphaMask01(void)
3421 {
3422   tet_infoline("Test signal handler when image / mask image is broken.");
3423
3424   ToolkitTestApplication application;
3425
3426   auto TestResourceReadyUrl = [&application](int eventTriggerCount, bool isSynchronous, const std::string& url, const std::string& mask, const char* location) {
3427     gResourceReadySignalCounter = 0;
3428
3429     Property::Map map;
3430     map[Toolkit::ImageVisual::Property::URL] = url;
3431     if(!mask.empty())
3432     {
3433       map[Toolkit::ImageVisual::Property::ALPHA_MASK_URL] = mask;
3434     }
3435     map[Toolkit::ImageVisual::Property::SYNCHRONOUS_LOADING] = isSynchronous;
3436
3437     ImageView imageView                            = ImageView::New();
3438     imageView[Toolkit::ImageView::Property::IMAGE] = map;
3439     imageView[Actor::Property::SIZE]               = Vector2(100.0f, 200.0f);
3440     imageView.ResourceReadySignal().Connect(&OnSimpleResourceReadySignal);
3441
3442     application.GetScene().Add(imageView);
3443     application.SendNotification();
3444     application.Render();
3445
3446     if(!isSynchronous)
3447     {
3448       // Wait for loading
3449       DALI_TEST_EQUALS(Test::WaitForEventThreadTrigger(eventTriggerCount), true, location);
3450     }
3451     tet_printf("test %s [sync:%d] signal fired\n", url.c_str(), isSynchronous ? 1 : 0);
3452     DALI_TEST_EQUALS(gResourceReadySignalCounter, 1, location);
3453
3454     imageView.Unparent();
3455   };
3456
3457   for(int synchronous = 0; synchronous <= 1; synchronous++)
3458   {
3459     tet_printf("Test normal case (sync:%d)\n", synchronous);
3460     TestResourceReadyUrl(1, synchronous, gImage_600_RGB, "", TEST_LOCATION);
3461     TestResourceReadyUrl(3, synchronous, gImage_600_RGB, gImage_34_RGBA, TEST_LOCATION); // 3 event trigger required : 2 image load + 1 apply mask
3462
3463     tet_printf("Test broken image case (sync:%d)\n", synchronous);
3464     TestResourceReadyUrl(1, synchronous, "invalid.jpg", "", TEST_LOCATION);
3465     TestResourceReadyUrl(2, synchronous, "invalid.jpg", gImage_34_RGBA, TEST_LOCATION);
3466
3467     tet_printf("Test broken mask image case (sync:%d)\n", synchronous);
3468     TestResourceReadyUrl(2, synchronous, gImage_600_RGB, "invalid.png", TEST_LOCATION);
3469
3470     tet_printf("Test broken both image, mask image case (sync:%d)\n", synchronous);
3471     TestResourceReadyUrl(2, synchronous, "invalid.jpg", "invalid.png", TEST_LOCATION);
3472   }
3473
3474   END_TEST;
3475 }
3476
3477 int UtcDaliImageViewOnResourceReadySignalWithBrokenAlphaMask02(void)
3478 {
3479   tet_infoline("Test signal handler when image try to use cached-and-broken mask image.");
3480
3481   ToolkitTestApplication application;
3482
3483   gResourceReadySignalCounter = 0;
3484
3485   auto TestBrokenMaskResourceReadyUrl = [&application](const std::string& url, const char* location) {
3486     Property::Map map;
3487     map[Toolkit::ImageVisual::Property::URL] = url;
3488     // Use invalid mask url
3489     map[Toolkit::ImageVisual::Property::ALPHA_MASK_URL] = "invalid.png";
3490
3491     ImageView imageView                            = ImageView::New();
3492     imageView[Toolkit::ImageView::Property::IMAGE] = map;
3493     imageView[Actor::Property::SIZE]               = Vector2(100.0f, 200.0f);
3494     imageView.ResourceReadySignal().Connect(&OnSimpleResourceReadySignal);
3495
3496     application.GetScene().Add(imageView);
3497     application.SendNotification();
3498     application.Render();
3499
3500     // Don't unparent imageView, for keep the cache.
3501   };
3502
3503   // Use more than 4 images (The number of LocalImageLoadThread)
3504   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};
3505
3506   int expectResourceReadySignalCounter = 0;
3507
3508   for(auto& url : testUrlList)
3509   {
3510     TestBrokenMaskResourceReadyUrl(url, TEST_LOCATION);
3511     expectResourceReadySignalCounter++;
3512   }
3513
3514   // Remain 1 signal due to we use #URL + 1 mask image.
3515   DALI_TEST_EQUALS(Test::WaitForEventThreadTrigger(expectResourceReadySignalCounter + 1), true, TEST_LOCATION);
3516
3517   DALI_TEST_EQUALS(gResourceReadySignalCounter, expectResourceReadySignalCounter, TEST_LOCATION);
3518
3519   END_TEST;
3520 }
3521
3522 int UtcDaliImageViewCheckVariousCaseSendOnResourceReadySignal(void)
3523 {
3524   tet_infoline("Test signal handler various case.");
3525
3526   ToolkitTestApplication application;
3527
3528   auto TestResourceReadyUrl = [&application](int eventTriggerCount, bool isSynchronous, bool loadSuccess, const std::string& url, const std::string& mask, const char* location) {
3529     gResourceReadySignalCounter = 0;
3530
3531     Property::Map map;
3532     map[Toolkit::ImageVisual::Property::URL] = url;
3533     if(!mask.empty())
3534     {
3535       map[Toolkit::ImageVisual::Property::ALPHA_MASK_URL] = mask;
3536     }
3537     map[Toolkit::ImageVisual::Property::SYNCHRONOUS_LOADING] = isSynchronous;
3538
3539     ImageView imageView                            = ImageView::New();
3540     imageView[Toolkit::ImageView::Property::IMAGE] = map;
3541     imageView[Actor::Property::SIZE]               = Vector2(100.0f, 200.0f);
3542     imageView.ResourceReadySignal().Connect(&OnSimpleResourceReadySignal);
3543
3544     application.GetScene().Add(imageView);
3545     application.SendNotification();
3546     application.Render();
3547
3548     // Wait for loading
3549     DALI_TEST_EQUALS(Test::WaitForEventThreadTrigger(eventTriggerCount), true, location);
3550
3551     tet_printf("test %s [sync:%d] signal fired\n", url.c_str(), isSynchronous ? 1 : 0);
3552     DALI_TEST_EQUALS(gResourceReadySignalCounter, 1, location);
3553     DALI_TEST_EQUALS(imageView.GetVisualResourceStatus(Toolkit::ImageView::Property::IMAGE), loadSuccess ? Toolkit::Visual::ResourceStatus::READY : Toolkit::Visual::ResourceStatus::FAILED, TEST_LOCATION);
3554
3555     imageView.Unparent();
3556   };
3557
3558   auto TestAuxiliaryResourceReadyUrl = [&application](bool isSynchronous, bool loadSuccess, const std::string& url, const std::string& auxiliaryUrl, const char* location) {
3559     gResourceReadySignalCounter = 0;
3560
3561     Property::Map map;
3562     map[Toolkit::ImageVisual::Property::URL]                        = url;
3563     map[Toolkit::DevelImageVisual::Property::AUXILIARY_IMAGE]       = auxiliaryUrl;
3564     map[Toolkit::DevelImageVisual::Property::AUXILIARY_IMAGE_ALPHA] = 0.5f;
3565     map[Toolkit::ImageVisual::Property::SYNCHRONOUS_LOADING]        = isSynchronous;
3566
3567     ImageView imageView = ImageView::New();
3568     imageView.SetProperty(Toolkit::ImageView::Property::IMAGE, map);
3569     imageView.SetProperty(Actor::Property::SIZE, Vector2(100.0f, 200.0f));
3570     imageView.ResourceReadySignal().Connect(&OnSimpleResourceReadySignal);
3571     application.GetScene().Add(imageView);
3572
3573     application.SendNotification();
3574     application.Render();
3575
3576     if(!isSynchronous)
3577     {
3578       // Wait for loading
3579       DALI_TEST_EQUALS(Test::WaitForEventThreadTrigger(2), true, location);
3580     }
3581
3582     tet_printf("test %s [sync:%d] signal fired\n", url.c_str(), isSynchronous ? 1 : 0);
3583     DALI_TEST_EQUALS(gResourceReadySignalCounter, 1, location);
3584     DALI_TEST_EQUALS(imageView.GetVisualResourceStatus(Toolkit::ImageView::Property::IMAGE), loadSuccess ? Toolkit::Visual::ResourceStatus::READY : Toolkit::Visual::ResourceStatus::FAILED, TEST_LOCATION);
3585
3586     imageView.Unparent();
3587   };
3588
3589   // Case 1 : asynchronous loading
3590   tet_printf("Test invalid single simple image Asynchronous\n");
3591
3592   // Test normal case
3593   TestResourceReadyUrl(1, 0, 1, gImage_600_RGB, "", TEST_LOCATION);
3594   TestResourceReadyUrl(1, 0, 1, TEST_SVG_FILE_NAME, "", TEST_LOCATION); // 1 rasterize
3595   TestResourceReadyUrl(1, 0, 1, TEST_BROKEN_IMAGE_L, "", TEST_LOCATION);
3596
3597   TestResourceReadyUrl(2, 0, 1, TEST_GIF_FILE_NAME, "", TEST_LOCATION);                   // 2 image loading - batch size
3598   TestResourceReadyUrl(1, 0, 1, TEST_ANIMATED_VECTOR_IMAGE_FILE_NAME, "", TEST_LOCATION); // 1 rasterize
3599
3600   TestResourceReadyUrl(3, 0, 1, gImage_600_RGB, gImage_34_RGBA, TEST_LOCATION); // 2 image loading + 1 applymask
3601
3602   TestAuxiliaryResourceReadyUrl(0, 1, TEST_BROKEN_IMAGE_L, gImage_34_RGBA, TEST_LOCATION);
3603
3604   // Test broken case
3605   TestResourceReadyUrl(1, 0, 0, "invalid.jpg", "", TEST_LOCATION);
3606   TestResourceReadyUrl(0, 0, 0, "invalid.svg", "", TEST_LOCATION); // 0 rasterize
3607   TestResourceReadyUrl(1, 0, 0, "invalid.9.png", "", TEST_LOCATION);
3608   TestResourceReadyUrl(1, 0, 0, "invalid.gif", "", TEST_LOCATION);  // 1 image loading
3609   TestResourceReadyUrl(0, 0, 0, "invalid.json", "", TEST_LOCATION); // 0 rasterize
3610
3611   TestResourceReadyUrl(2, 0, 0, "invalid.jpg", "invalid.png", TEST_LOCATION);  // 2 image loading
3612   TestResourceReadyUrl(2, 0, 1, gImage_600_RGB, "invalid.png", TEST_LOCATION); // 2 image loading
3613   TestResourceReadyUrl(2, 0, 0, "invalid.jpg", gImage_34_RGBA, TEST_LOCATION); // 2 image loading
3614
3615   TestAuxiliaryResourceReadyUrl(0, 0, "invalid.9.png", "invalid.png", TEST_LOCATION);
3616   TestAuxiliaryResourceReadyUrl(0, 1, TEST_BROKEN_IMAGE_L, "invalid.png", TEST_LOCATION);
3617   TestAuxiliaryResourceReadyUrl(0, 0, "invalid.9.png", gImage_34_RGBA, TEST_LOCATION);
3618
3619   // Case 2 : Synchronous loading
3620   tet_printf("Test invalid single simple image Synchronous\n");
3621
3622   // Test normal case
3623   TestResourceReadyUrl(0, 1, 1, gImage_600_RGB, "", TEST_LOCATION);
3624   TestResourceReadyUrl(0, 1, 1, TEST_SVG_FILE_NAME, "", TEST_LOCATION); // synchronous rasterize
3625   TestResourceReadyUrl(0, 1, 1, TEST_BROKEN_IMAGE_L, "", TEST_LOCATION);
3626
3627   TestResourceReadyUrl(1, 1, 1, TEST_GIF_FILE_NAME, "", TEST_LOCATION);                   // first frame image loading sync + second frame image loading async
3628   TestResourceReadyUrl(0, 1, 1, TEST_ANIMATED_VECTOR_IMAGE_FILE_NAME, "", TEST_LOCATION); // synchronous rasterize
3629
3630   TestResourceReadyUrl(0, 1, 1, gImage_600_RGB, gImage_34_RGBA, TEST_LOCATION);
3631
3632   TestAuxiliaryResourceReadyUrl(1, 1, TEST_BROKEN_IMAGE_L, gImage_34_RGBA, TEST_LOCATION);
3633
3634   // Test broken case
3635   TestResourceReadyUrl(0, 1, 0, "invalid.jpg", "", TEST_LOCATION);
3636   TestResourceReadyUrl(0, 1, 0, "invalid.svg", "", TEST_LOCATION); // 0 rasterize
3637   TestResourceReadyUrl(0, 1, 0, "invalid.9.png", "", TEST_LOCATION);
3638   TestResourceReadyUrl(0, 1, 0, "invalid.gif", "", TEST_LOCATION);
3639   TestResourceReadyUrl(0, 1, 0, "invalid.json", "", TEST_LOCATION); // 0 rasterize
3640
3641   TestResourceReadyUrl(0, 1, 0, "invalid.jpg", "invalid.png", TEST_LOCATION);
3642   TestResourceReadyUrl(0, 1, 1, gImage_600_RGB, "invalid.png", TEST_LOCATION);
3643   TestResourceReadyUrl(0, 1, 0, "invalid.jpg", gImage_34_RGBA, TEST_LOCATION);
3644
3645   TestAuxiliaryResourceReadyUrl(1, 0, "invalid.9.png", "invalid.png", TEST_LOCATION);
3646   TestAuxiliaryResourceReadyUrl(1, 1, TEST_BROKEN_IMAGE_L, "invalid.png", TEST_LOCATION);
3647   TestAuxiliaryResourceReadyUrl(1, 0, "invalid.9.png", gImage_34_RGBA, TEST_LOCATION);
3648
3649   END_TEST;
3650 }
3651
3652 int UtcDaliImageViewSetImageOnResourceReadySignal04(void)
3653 {
3654   tet_infoline("Test texturemanager's remove queue works well within signal handler.");
3655
3656   ToolkitTestApplication application;
3657
3658   gResourceReadySignalCounter      = 0;
3659   gResourceReadySignal04ComesOrder = 0;
3660
3661   gImageView1 = ImageView::New("invalid.jpg"); // request invalid image, to make loading failed fast.
3662   gImageView1.ResourceReadySignal().Connect(&OnResourceReadySignal04);
3663   application.GetScene().Add(gImageView1);
3664
3665   gImageView2 = ImageView::New("invalid.png"); // request invalid image, to make loading failed fast.
3666   gImageView2.ResourceReadySignal().Connect(&OnResourceReadySignal04);
3667   application.GetScene().Add(gImageView2);
3668
3669   application.SendNotification();
3670   application.Render();
3671
3672   tet_infoline("Try to load 2 invalid image");
3673
3674   DALI_TEST_EQUALS(Test::WaitForEventThreadTrigger(2), true, TEST_LOCATION);
3675   DALI_TEST_EQUALS(gResourceReadySignalCounter, 2, TEST_LOCATION);
3676
3677   tet_infoline("load done");
3678
3679   // We can test this UTC only if gImageView1 and gImageView2 loaded done.
3680   if(gResourceReadySignal04ComesOrder == -1)
3681   {
3682     tet_infoline("Bad news.. gImageView3 or gImageView4 loaded faster than others. just skip this UTC");
3683   }
3684   else
3685   {
3686     // gImageView3 and gImageView4 load must not be successed yet.
3687     DALI_TEST_EQUALS(gImageView3.GetRendererCount(), 0u, TEST_LOCATION);
3688     DALI_TEST_EQUALS(gImageView4.GetRendererCount(), 0u, TEST_LOCATION);
3689
3690     application.SendNotification();
3691     application.Render();
3692
3693     tet_infoline("Try to load 2 valid image");
3694
3695     DALI_TEST_EQUALS(Test::WaitForEventThreadTrigger(2), true, TEST_LOCATION);
3696     DALI_TEST_EQUALS(gResourceReadySignalCounter, 4, TEST_LOCATION);
3697
3698     tet_infoline("load done");
3699
3700     // gImageView3 and gImageView4 load must be successed now.
3701     DALI_TEST_EQUALS(gImageView3.GetRendererAt(0).GetTextures().GetTextureCount(), 1u, TEST_LOCATION);
3702     DALI_TEST_EQUALS(gImageView4.GetRendererAt(0).GetTextures().GetTextureCount(), 1u, TEST_LOCATION);
3703   }
3704
3705   END_TEST;
3706 }