Merge "Remove ResourceReady before rasterization in SvgVisual" into devel/master
[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] = 34;
788   imageMap[ImageVisual::Property::DESIRED_WIDTH]  = 34;
789   imageMap[ImageVisual::Property::ATLASING]       = true;
790
791   ImageView imageView = ImageView::New();
792   imageView.SetProperty(ImageView::Property::IMAGE, imageMap);
793   imageView.SetProperty(Toolkit::Control::Property::PADDING, Extents(10u, 10u, 10u, 10u));
794
795   // By default, Aysnc loading is used
796   // loading is not started if the actor is offScene
797
798   application.GetScene().Add(imageView);
799   application.SendNotification();
800   application.Render(16);
801   application.Render(16);
802   application.SendNotification();
803
804   // Change url to url2
805   imageMap[ImageVisual::Property::URL] = url2.GetUrl();
806   imageView.SetProperty(ImageView::Property::IMAGE, imageMap);
807
808   imageView.SetProperty(Dali::Actor::Property::LAYOUT_DIRECTION, Dali::LayoutDirection::RIGHT_TO_LEFT);
809   application.SendNotification();
810   application.Render(16);
811   application.Render(16);
812   application.SendNotification();
813
814   // loading started, this waits for the loader thread for max 30 seconds
815   DALI_TEST_EQUALS(Test::WaitForEventThreadTrigger(1), true, TEST_LOCATION);
816
817   application.SendNotification();
818   application.Render(16);
819
820   callStack.Enable(false);
821
822   TraceCallStack::NamedParams params;
823   params["width"] << 34;
824   params["height"] << 34;
825   DALI_TEST_EQUALS(callStack.FindMethodAndParams("TexSubImage2D", params), true, TEST_LOCATION);
826
827   END_TEST;
828 }
829
830 int UtcDaliImageViewSyncLoadingEncodedBuffer(void)
831 {
832   ToolkitTestApplication application;
833
834   tet_infoline("ImageView Testing sync loading from EncodedImageBuffer");
835
836   // Get encoded raw-buffer image and generate url
837   EncodedImageBuffer buffer = ConvertFileToEncodedImageBuffer(gImage_34_RGBA);
838   ImageUrl           url    = Toolkit::Image::GenerateUrl(buffer);
839
840   // Sync loading, automatic atlasing for small size image
841   {
842     TraceCallStack& callStack = application.GetGlAbstraction().GetTextureTrace();
843     callStack.Reset();
844     callStack.Enable(true);
845
846     ImageView imageView = ImageView::New();
847
848     // Sync loading is used
849     Property::Map syncLoadingMap;
850     syncLoadingMap["url"]                = url.GetUrl();
851     syncLoadingMap["desiredHeight"]      = 34;
852     syncLoadingMap["desiredWidth"]       = 34;
853     syncLoadingMap["synchronousLoading"] = true;
854     syncLoadingMap["atlasing"]           = true;
855     imageView.SetProperty(ImageView::Property::IMAGE, syncLoadingMap);
856
857     application.GetScene().Add(imageView);
858     application.SendNotification();
859     application.Render(16);
860
861     TraceCallStack::NamedParams params;
862     params["width"] << 34;
863     params["height"] << 34;
864     DALI_TEST_EQUALS(callStack.FindMethodAndParams("TexSubImage2D", params),
865                      true,
866                      TEST_LOCATION);
867   }
868
869   END_TEST;
870 }
871
872 int UtcDaliImageViewAddedTexture(void)
873 {
874   ToolkitTestApplication application;
875
876   tet_infoline("ImageView Testing image view with texture provided manager url");
877
878   ImageView imageView = ImageView::New();
879
880   // empty texture is ok, though pointless from app point of view
881   TextureSet  empty;
882   std::string url = TextureManager::AddTexture(empty);
883   DALI_TEST_CHECK(url.size() > 0u);
884
885   Property::Map propertyMap;
886   propertyMap[ImageVisual::Property::URL] = url;
887   imageView.SetProperty(ImageView::Property::IMAGE, propertyMap);
888
889   application.GetScene().Add(imageView);
890   application.SendNotification();
891   application.Render();
892
893   END_TEST;
894 }
895
896 int UtcDaliImageViewSizeWithBackground(void)
897 {
898   ToolkitTestApplication application;
899
900   int       width     = 100;
901   int       height    = 200;
902   ImageView imageView = ImageView::New();
903
904   imageView.SetProperty(Control::Property::BACKGROUND,
905                         {
906                           {Toolkit::Visual::Property::TYPE, Toolkit::Visual::IMAGE},
907                           {Toolkit::ImageVisual::Property::URL, TEST_RESOURCE_DIR "/gallery-small-1.jpg"},
908                           {ImageVisual::Property::DESIRED_WIDTH, width},
909                           {ImageVisual::Property::DESIRED_HEIGHT, height},
910                         });
911
912   application.GetScene().Add(imageView);
913   application.SendNotification();
914   application.Render();
915
916   DALI_TEST_EQUALS(imageView.GetCurrentProperty<Vector3>(Actor::Property::SIZE).width, (float)width, TEST_LOCATION);
917   DALI_TEST_EQUALS(imageView.GetCurrentProperty<Vector3>(Actor::Property::SIZE).height, (float)height, TEST_LOCATION);
918
919   END_TEST;
920 }
921
922 int UtcDaliImageViewSizeWithBackgroundAndImage(void)
923 {
924   ToolkitTestApplication application;
925
926   int widthBackground  = 100;
927   int heightBackground = 200;
928   int width            = 600;
929   int height           = 600;
930
931   ImageView imageView = ImageView::New();
932
933   imageView.SetProperty(Control::Property::BACKGROUND,
934                         {
935                           {Toolkit::Visual::Property::TYPE, Toolkit::Visual::IMAGE},
936                           {Toolkit::ImageVisual::Property::URL, TEST_RESOURCE_DIR "/gallery-small-1.jpg"},
937                           {ImageVisual::Property::DESIRED_WIDTH, widthBackground},
938                           {ImageVisual::Property::DESIRED_HEIGHT, heightBackground},
939                         });
940
941   imageView.SetImage(gImage_600_RGB); // 1 to 1 ratio, 600x600 pixels
942
943   application.GetScene().Add(imageView);
944   application.SendNotification();
945   application.Render();
946
947   DALI_TEST_EQUALS(imageView.GetCurrentProperty<Vector3>(Actor::Property::SIZE).width, (float)width, TEST_LOCATION);
948   DALI_TEST_EQUALS(imageView.GetCurrentProperty<Vector3>(Actor::Property::SIZE).height, (float)height, TEST_LOCATION);
949
950   END_TEST;
951 }
952
953 int UtcDaliImageViewHeightForWidthBackground(void)
954 {
955   ToolkitTestApplication application;
956
957   int widthBackground  = 100;
958   int heightBackground = 200;
959
960   ImageView imageView = ImageView::New();
961
962   imageView.SetProperty(Control::Property::BACKGROUND,
963                         {{Toolkit::Visual::Property::TYPE, Toolkit::Visual::IMAGE},
964                          {Toolkit::ImageVisual::Property::URL, TEST_RESOURCE_DIR "/gallery-small-1.jpg"},
965                          {ImageVisual::Property::DESIRED_WIDTH, widthBackground},
966                          {ImageVisual::Property::DESIRED_HEIGHT, heightBackground}});
967
968   application.GetScene().Add(imageView);
969   application.SendNotification();
970   application.Render();
971
972   Control control = Control::DownCast(imageView);
973   DALI_TEST_CHECK(control);
974   DALI_TEST_EQUALS(imageView.GetHeightForWidth(123.f), control.GetHeightForWidth(123.f), TEST_LOCATION);
975   DALI_TEST_EQUALS(imageView.GetWidthForHeight(321.f), control.GetWidthForHeight(321.f), TEST_LOCATION);
976
977   END_TEST;
978 }
979
980 int UtcDaliImageViewHeightForWidthBackgroundAndImage(void)
981 {
982   ToolkitTestApplication application;
983
984   int widthBackground  = 100;
985   int heightBackground = 200;
986   int width            = 300;
987   int height           = 300;
988
989   ImageView imageView = ImageView::New();
990
991   imageView.SetProperty(Control::Property::BACKGROUND,
992                         {{Toolkit::Visual::Property::TYPE, Toolkit::Visual::IMAGE},
993                          {Toolkit::ImageVisual::Property::URL, TEST_RESOURCE_DIR "/gallery-small-1.jpg"},
994                          {ImageVisual::Property::DESIRED_WIDTH, widthBackground},
995                          {ImageVisual::Property::DESIRED_HEIGHT, heightBackground}}); // 1 to 2 ratio
996
997   imageView.SetImage(gImage_600_RGB); // 1 to 1 ratio
998
999   application.GetScene().Add(imageView);
1000   application.SendNotification();
1001   application.Render();
1002
1003   DALI_TEST_EQUALS(imageView.GetHeightForWidth(width), (float)height, TEST_LOCATION);
1004   DALI_TEST_EQUALS(imageView.GetWidthForHeight(height), (float)width, TEST_LOCATION);
1005
1006   END_TEST;
1007 }
1008
1009 int UtcDaliImageViewSetImageUrl(void)
1010 {
1011   ToolkitTestApplication application;
1012
1013   ImageView imageView = ImageView::New();
1014   imageView.SetImage(TEST_IMAGE_FILE_NAME);
1015   TestUrl(imageView, TEST_IMAGE_FILE_NAME);
1016
1017   imageView.SetImage(TEST_IMAGE_FILE_NAME2);
1018   TestUrl(imageView, TEST_IMAGE_FILE_NAME2);
1019
1020   END_TEST;
1021 }
1022
1023 bool    gResourceReadySignalFired = false;
1024 Vector3 gNaturalSize;
1025
1026 void ResourceReadySignal(Control control)
1027 {
1028   gResourceReadySignalFired = true;
1029 }
1030
1031 int UtcDaliImageViewCheckResourceReady(void)
1032 {
1033   ToolkitTestApplication application;
1034
1035   gResourceReadySignalFired = false;
1036
1037   // Check ImageView with background and main image, to ensure both visuals are marked as loaded
1038   ImageView imageView = ImageView::New(TEST_GIF_FILE_NAME);
1039
1040   imageView.SetProperty(Control::Property::BACKGROUND,
1041                         {{Toolkit::Visual::Property::TYPE, Toolkit::Visual::IMAGE},
1042                          {Toolkit::ImageVisual::Property::URL, TEST_RESOURCE_DIR "/gallery-small-1.jpg"},
1043                          {ImageVisual::Property::DESIRED_WIDTH, 100},
1044                          {ImageVisual::Property::DESIRED_HEIGHT, 200}});
1045
1046   DALI_TEST_EQUALS(imageView.IsResourceReady(), false, TEST_LOCATION);
1047
1048   imageView.ResourceReadySignal().Connect(&ResourceReadySignal);
1049
1050   application.GetScene().Add(imageView);
1051
1052   // loading started, this waits for the loader thread
1053   DALI_TEST_EQUALS(Test::WaitForEventThreadTrigger(1), true, TEST_LOCATION);
1054
1055   application.SendNotification();
1056   application.Render(16);
1057
1058   DALI_TEST_EQUALS(Test::WaitForEventThreadTrigger(2), true, TEST_LOCATION);
1059
1060   application.SendNotification();
1061   application.Render();
1062
1063   DALI_TEST_EQUALS(imageView.IsResourceReady(), true, TEST_LOCATION);
1064
1065   DALI_TEST_EQUALS(gResourceReadySignalFired, true, TEST_LOCATION);
1066
1067   END_TEST;
1068 }
1069
1070 int UtcDaliImageViewSetImageTypeChangesP(void)
1071 {
1072   ToolkitTestApplication application;
1073
1074   ImageView                   imageView   = ImageView::New();
1075   Toolkit::Internal::Control& controlImpl = Toolkit::Internal::GetImplementation(imageView);
1076
1077   application.GetScene().Add(imageView);
1078
1079   std::string           url;
1080   Property::Map         map;
1081   Toolkit::Visual::Base visual;
1082
1083   Property::Value value = imageView.GetProperty(imageView.GetPropertyIndex("image"));
1084   visual                = DevelControl::GetVisual(controlImpl, ImageView::Property::IMAGE);
1085
1086   application.SendNotification();
1087   application.Render(16);
1088
1089   DALI_TEST_CHECK(!value.Get(url)); // Value should be empty
1090   value.Get(map);
1091   DALI_TEST_CHECK(map.Empty()); // Value should be empty
1092   DALI_TEST_CHECK(!visual);     // Visual should be invalid
1093
1094   // Set a URL
1095   imageView.SetImage("TEST_URL");
1096
1097   application.SendNotification();
1098   application.Render(16);
1099
1100   value  = imageView.GetProperty(imageView.GetPropertyIndex("image"));
1101   visual = DevelControl::GetVisual(controlImpl, ImageView::Property::IMAGE);
1102
1103   DALI_TEST_CHECK(value.Get(url));  // Value should NOT be empty
1104   DALI_TEST_CHECK(!value.Get(map)); // Value should be empty
1105   DALI_TEST_CHECK(visual);          // Visual should be valid
1106
1107   // Set an empty URL
1108   imageView.SetImage("");
1109
1110   application.SendNotification();
1111   application.Render(16);
1112
1113   value  = imageView.GetProperty(imageView.GetPropertyIndex("image"));
1114   visual = DevelControl::GetVisual(controlImpl, ImageView::Property::IMAGE);
1115
1116   DALI_TEST_CHECK(!value.Get(url)); // Value should be empty
1117   value.Get(map);
1118   DALI_TEST_CHECK(map.Empty()); // Value should be empty
1119   DALI_TEST_CHECK(!visual);     // Visual should be invalid
1120
1121   // Set a URL in property map
1122   Property::Map propertyMap;
1123   propertyMap[ImageVisual::Property::URL] = TEST_IMAGE_FILE_NAME;
1124   imageView.SetProperty(ImageView::Property::IMAGE, propertyMap);
1125
1126   application.SendNotification();
1127   application.Render(16);
1128
1129   value  = imageView.GetProperty(imageView.GetPropertyIndex("image"));
1130   visual = DevelControl::GetVisual(controlImpl, ImageView::Property::IMAGE);
1131
1132   DALI_TEST_CHECK(!value.Get(url)); // Value should be empty
1133   DALI_TEST_CHECK(value.Get(map));  // Value should NOT be empty
1134   DALI_TEST_CHECK(visual);          // Visual should be valid
1135
1136   // Set a URL in property map again
1137   propertyMap[ImageVisual::Property::URL] = gImage_34_RGBA;
1138   imageView.SetProperty(ImageView::Property::IMAGE, propertyMap);
1139
1140   application.SendNotification();
1141   application.Render(16);
1142
1143   value  = imageView.GetProperty(imageView.GetPropertyIndex("image"));
1144   visual = DevelControl::GetVisual(controlImpl, ImageView::Property::IMAGE);
1145
1146   DALI_TEST_CHECK(!value.Get(url)); // Value should be empty
1147   DALI_TEST_CHECK(value.Get(map));  // Value should NOT be empty
1148   DALI_TEST_CHECK(visual);          // Visual should be valid
1149
1150   // Set an empty URL in property map
1151   propertyMap[ImageVisual::Property::URL] = std::string();
1152   imageView.SetProperty(ImageView::Property::IMAGE, propertyMap);
1153
1154   application.SendNotification();
1155   application.Render(16);
1156
1157   value  = imageView.GetProperty(imageView.GetPropertyIndex("image"));
1158   visual = DevelControl::GetVisual(controlImpl, ImageView::Property::IMAGE);
1159
1160   DALI_TEST_CHECK(!value.Get(url)); // Value should be empty
1161   DALI_TEST_CHECK(value.Get(map));  // Value should NOT be empty
1162   DALI_TEST_CHECK(!visual);         // Visual should be invalid
1163
1164   // Set a URL in property map again
1165   propertyMap[ImageVisual::Property::URL] = gImage_34_RGBA;
1166   imageView.SetProperty(ImageView::Property::IMAGE, propertyMap);
1167
1168   application.SendNotification();
1169   application.Render(16);
1170
1171   value  = imageView.GetProperty(imageView.GetPropertyIndex("image"));
1172   visual = DevelControl::GetVisual(controlImpl, ImageView::Property::IMAGE);
1173
1174   DALI_TEST_CHECK(!value.Get(url)); // Value should be empty
1175   DALI_TEST_CHECK(value.Get(map));  // Value should NOT be empty
1176   DALI_TEST_CHECK(visual);          // Visual should be valid
1177
1178   // Set an empty property map
1179   propertyMap.Clear();
1180   imageView.SetProperty(ImageView::Property::IMAGE, propertyMap);
1181
1182   application.SendNotification();
1183   application.Render(16);
1184
1185   value  = imageView.GetProperty(imageView.GetPropertyIndex("image"));
1186   visual = DevelControl::GetVisual(controlImpl, ImageView::Property::IMAGE);
1187
1188   DALI_TEST_CHECK(!value.Get(url)); // Value should be empty
1189   DALI_TEST_CHECK(value.Get(map));  // Value should NOT be empty
1190   DALI_TEST_CHECK(map.Empty());     // But PropertyMap should be empty
1191   DALI_TEST_CHECK(!visual);         // Visual should be invalid
1192
1193   END_TEST;
1194 }
1195
1196 int UtcDaliImageViewResourceUrlP(void)
1197 {
1198   ToolkitTestApplication application;
1199
1200   ImageView imageView = ImageView::New();
1201   DALI_TEST_CHECK(imageView.GetProperty(ImageView::Property::IMAGE).Get<std::string>().empty());
1202
1203   imageView.SetProperty(ImageView::Property::IMAGE, "TestString");
1204   DALI_TEST_EQUALS(imageView.GetProperty(ImageView::Property::IMAGE).Get<std::string>(), "TestString", TEST_LOCATION);
1205
1206   END_TEST;
1207 }
1208
1209 int UtcDaliImageViewReplaceImage(void)
1210 {
1211   ToolkitTestApplication application;
1212
1213   gResourceReadySignalFired = false;
1214
1215   // Check ImageView with background and main image, to ensure both visuals are marked as loaded
1216   ImageView imageView = ImageView::New(TEST_IMAGE_1);
1217
1218   DALI_TEST_EQUALS(imageView.IsResourceReady(), false, TEST_LOCATION);
1219
1220   imageView.ResourceReadySignal().Connect(&ResourceReadySignal);
1221
1222   application.GetScene().Add(imageView);
1223
1224   application.SendNotification();
1225   application.Render(16);
1226
1227   // loading started, this waits for the loader thread for max 30 seconds
1228   DALI_TEST_EQUALS(Test::WaitForEventThreadTrigger(1), true, TEST_LOCATION);
1229
1230   DALI_TEST_EQUALS(imageView.GetRendererCount(), 1u, TEST_LOCATION);
1231
1232   DALI_TEST_EQUALS(gResourceReadySignalFired, true, TEST_LOCATION);
1233
1234   gResourceReadySignalFired = false;
1235
1236   imageView.SetImage(TEST_IMAGE_2);
1237
1238   application.SendNotification();
1239   application.Render(16);
1240
1241   // loading started, this waits for the loader thread for max 30 seconds
1242   DALI_TEST_EQUALS(Test::WaitForEventThreadTrigger(1), true, TEST_LOCATION);
1243
1244   DALI_TEST_EQUALS(imageView.GetRendererCount(), 1u, TEST_LOCATION);
1245
1246   DALI_TEST_EQUALS(imageView.IsResourceReady(), true, TEST_LOCATION);
1247
1248   DALI_TEST_EQUALS(gResourceReadySignalFired, true, TEST_LOCATION);
1249
1250   END_TEST;
1251 }
1252
1253 void OnRelayoutOverride(Size size)
1254 {
1255   gNaturalSize = size; // Size Relayout is using
1256 }
1257
1258 int UtcDaliImageViewReplaceImageAndGetNaturalSize(void)
1259 {
1260   ToolkitTestApplication application;
1261
1262   // Check ImageView with background and main image, to ensure both visuals are marked as loaded
1263   ImageView imageView = ImageView::New(TEST_IMAGE_1);
1264   imageView.SetResizePolicy(ResizePolicy::USE_NATURAL_SIZE, Dimension::ALL_DIMENSIONS);
1265
1266   DummyControl        dummyControl = DummyControl::New(true);
1267   Impl::DummyControl& dummyImpl    = static_cast<Impl::DummyControl&>(dummyControl.GetImplementation());
1268   dummyControl.SetResizePolicy(ResizePolicy::FIT_TO_CHILDREN, Dimension::ALL_DIMENSIONS);
1269
1270   dummyControl.Add(imageView);
1271   dummyImpl.SetRelayoutCallback(&OnRelayoutOverride);
1272   application.GetScene().Add(dummyControl);
1273
1274   application.SendNotification();
1275   application.Render();
1276
1277   // loading started, this waits for the loader thread for max 30 seconds
1278   DALI_TEST_EQUALS(Test::WaitForEventThreadTrigger(1), true, TEST_LOCATION);
1279
1280   DALI_TEST_EQUALS(gNaturalSize.width, 1024.0f, TEST_LOCATION);
1281   DALI_TEST_EQUALS(gNaturalSize.height, 1024.0f, TEST_LOCATION);
1282
1283   gNaturalSize = Vector3::ZERO;
1284
1285   imageView.SetImage(gImage_600_RGB);
1286
1287   // Waiting for resourceReady so SendNotifcation not called here.
1288
1289   // loading started, this waits for the loader thread for max 30 seconds
1290   DALI_TEST_EQUALS(Test::WaitForEventThreadTrigger(1), true, TEST_LOCATION);
1291
1292   // Trigger a potential relayout
1293   application.SendNotification();
1294   application.Render();
1295
1296   DALI_TEST_EQUALS(gNaturalSize.width, 600.0f, TEST_LOCATION);
1297   DALI_TEST_EQUALS(gNaturalSize.height, 600.0f, TEST_LOCATION);
1298
1299   END_TEST;
1300 }
1301
1302 int UtcDaliImageViewResourceReadySignalWithImmediateLoad(void)
1303 {
1304   tet_infoline("Test Setting Image with IMMEDIATE load and receving ResourceReadySignal before staged.");
1305
1306   ToolkitTestApplication application;
1307
1308   gResourceReadySignalFired = false;
1309
1310   Property::Map imageMap;
1311
1312   imageMap[ImageVisual::Property::URL]         = gImage_34_RGBA;
1313   imageMap[ImageVisual::Property::LOAD_POLICY] = ImageVisual::LoadPolicy::IMMEDIATE;
1314
1315   tet_infoline("Creating ImageView without URL so image does not start loading");
1316   ImageView imageView = ImageView::New();
1317   tet_infoline("Connect to image loaded signal before setting image");
1318   imageView.ResourceReadySignal().Connect(&ResourceReadySignal);
1319   tet_infoline("Setting Image with IMMEDIATE load, signal already connected so will be triggered.");
1320   imageView.SetProperty(ImageView::Property::IMAGE, imageMap);
1321
1322   // loading started, this waits for the loader thread
1323   DALI_TEST_EQUALS(Test::WaitForEventThreadTrigger(1), true, TEST_LOCATION);
1324
1325   application.SendNotification();
1326   application.Render(16);
1327
1328   DALI_TEST_EQUALS(gResourceReadySignalFired, true, TEST_LOCATION);
1329
1330   END_TEST;
1331 }
1332
1333 int UtcDaliImageViewResourceReadySignalWithReusedImage(void)
1334 {
1335   tet_infoline("Test Setting Image that was already loaded by another ImageView and still getting ResourceReadySignal.");
1336
1337   ToolkitTestApplication application;
1338
1339   gResourceReadySignalFired = false;
1340
1341   Property::Map imageMap;
1342
1343   imageMap[ImageVisual::Property::URL]         = gImage_34_RGBA;
1344   imageMap[ImageVisual::Property::LOAD_POLICY] = ImageVisual::LoadPolicy::IMMEDIATE;
1345
1346   ImageView imageView = ImageView::New();
1347   imageView.ResourceReadySignal().Connect(&ResourceReadySignal);
1348   imageView.SetProperty(ImageView::Property::IMAGE, imageMap);
1349
1350   // loading started, this waits for the loader thread
1351   DALI_TEST_EQUALS(Test::WaitForEventThreadTrigger(1), true, TEST_LOCATION);
1352
1353   application.SendNotification();
1354   application.Render(16);
1355
1356   DALI_TEST_EQUALS(gResourceReadySignalFired, true, TEST_LOCATION);
1357   gResourceReadySignalFired = false;
1358
1359   ImageView imageViewWithExistingImage = ImageView::New();
1360   imageViewWithExistingImage.ResourceReadySignal().Connect(&ResourceReadySignal);
1361   imageViewWithExistingImage.SetProperty(ImageView::Property::IMAGE, imageMap);
1362
1363   DALI_TEST_EQUALS(gResourceReadySignalFired, true, TEST_LOCATION);
1364
1365   END_TEST;
1366 }
1367
1368 int UtcDaliImageViewResourceReadySignalWithReusedImage02(void)
1369 {
1370   tet_infoline("Test Setting Image that was already loaded by another ImageView and still getting ResourceReadySignal when staged.");
1371
1372   ToolkitTestApplication application;
1373
1374   gResourceReadySignalFired = false;
1375
1376   Property::Map imageImmediateLoadingMap;
1377   imageImmediateLoadingMap[ImageVisual::Property::URL]         = gImage_34_RGBA;
1378   imageImmediateLoadingMap[ImageVisual::Property::LOAD_POLICY] = ImageVisual::LoadPolicy::IMMEDIATE;
1379
1380   tet_infoline("Immediate load an image");
1381   ImageView imageView = ImageView::New();
1382   imageView.ResourceReadySignal().Connect(&ResourceReadySignal);
1383   imageView.SetProperty(ImageView::Property::IMAGE, imageImmediateLoadingMap);
1384
1385   // loading started, this waits for the loader thread
1386   DALI_TEST_EQUALS(Test::WaitForEventThreadTrigger(1), true, TEST_LOCATION);
1387
1388   application.SendNotification();
1389   application.Render(16);
1390
1391   tet_infoline("Check image loaded");
1392   DALI_TEST_EQUALS(gResourceReadySignalFired, true, TEST_LOCATION);
1393   gResourceReadySignalFired = false;
1394
1395   tet_infoline("Create another ImageView with the same URL");
1396   ImageView imageViewWithExistingImage = ImageView::New(gImage_34_RGBA);
1397   tet_infoline("Connect to ResourceReady signal for second ImageView, it should still fire as resource is ready");
1398   imageViewWithExistingImage.ResourceReadySignal().Connect(&ResourceReadySignal);
1399
1400   application.GetScene().Add(imageViewWithExistingImage);
1401
1402   DALI_TEST_EQUALS(gResourceReadySignalFired, true, TEST_LOCATION);
1403
1404   END_TEST;
1405 }
1406
1407 int UtcDaliImageViewPaddingProperty(void)
1408 {
1409   ToolkitTestApplication application;
1410
1411   ImageView     imageView = ImageView::New();
1412   Property::Map imagePropertyMap;
1413   imagePropertyMap[Toolkit::Visual::Property::TYPE]       = Toolkit::Visual::IMAGE;
1414   imagePropertyMap[Toolkit::ImageVisual::Property::URL]   = TEST_RESOURCE_DIR "/gallery-small-1.jpg";
1415   imagePropertyMap[ImageVisual::Property::DESIRED_WIDTH]  = 128;
1416   imagePropertyMap[ImageVisual::Property::DESIRED_HEIGHT] = 128;
1417   imageView.SetProperty(Toolkit::ImageView::Property::IMAGE, imagePropertyMap);
1418   imageView.SetProperty(Actor::Property::ANCHOR_POINT, AnchorPoint::TOP_LEFT);
1419   imageView.SetProperty(Actor::Property::PARENT_ORIGIN, ParentOrigin::TOP_LEFT);
1420   imageView.SetProperty(Control::Property::PADDING, Extents(15, 10, 5, 10));
1421   application.GetScene().Add(imageView);
1422
1423   application.SendNotification();
1424   application.Render();
1425
1426   DALI_TEST_EQUALS(imageView.GetProperty<Extents>(Control::Property::PADDING), Extents(15, 10, 5, 10), TEST_LOCATION);
1427
1428   ImageView childImage = ImageView::New();
1429   childImage.SetBackgroundColor(Color::BLACK);
1430   childImage.SetProperty(Actor::Property::SIZE, Vector2(10.f, 10.f));
1431   imageView.Add(childImage);
1432
1433   application.SendNotification();
1434   application.Render();
1435
1436   // Child ImageView should be positioned dependinig on Parent ImageView's Padding value
1437   DALI_TEST_EQUALS(childImage.GetProperty<Vector3>(Dali::Actor::Property::POSITION), Vector3(15, 5, 0), TEST_LOCATION);
1438
1439   // Check whether Image Visual transforms on ImageVieiw::OnRelayout()
1440   Toolkit::Internal::Control& controlImpl = Toolkit::Internal::GetImplementation(imageView);
1441   Toolkit::Visual::Base       imageVisual = DevelControl::GetVisual(controlImpl, ImageView::Property::IMAGE);
1442   Property::Map               resultMap;
1443   imageVisual.CreatePropertyMap(resultMap);
1444
1445   Property::Value* transformValue = resultMap.Find(Visual::Property::TRANSFORM);
1446   DALI_TEST_CHECK(transformValue);
1447   Property::Map* retMap = transformValue->GetMap();
1448   DALI_TEST_CHECK(retMap);
1449
1450   // Image Visual should be positioned depending on ImageView's padding
1451   DALI_TEST_EQUALS(retMap->Find(Visual::Transform::Property::OFFSET)->Get<Vector2>(), Vector2(15, 5), TEST_LOCATION);
1452
1453   END_TEST;
1454 }
1455
1456 int UtcDaliImageViewPaddingProperty02(void)
1457 {
1458   ToolkitTestApplication application;
1459
1460   ImageView     imageView = ImageView::New();
1461   Property::Map imagePropertyMap;
1462   imagePropertyMap[Toolkit::Visual::Property::TYPE]            = Toolkit::Visual::IMAGE;
1463   imagePropertyMap[Toolkit::ImageVisual::Property::URL]        = TEST_RESOURCE_DIR "/Kid1.svg";
1464   imagePropertyMap[ImageVisual::Property::DESIRED_WIDTH]       = 128;
1465   imagePropertyMap[ImageVisual::Property::DESIRED_HEIGHT]      = 128;
1466   imagePropertyMap[DevelVisual::Property::VISUAL_FITTING_MODE] = Toolkit::DevelVisual::FIT_KEEP_ASPECT_RATIO;
1467   imageView.SetProperty(Toolkit::ImageView::Property::IMAGE, imagePropertyMap);
1468   imageView.SetProperty(Actor::Property::ANCHOR_POINT, AnchorPoint::TOP_LEFT);
1469   imageView.SetProperty(Actor::Property::PARENT_ORIGIN, ParentOrigin::TOP_LEFT);
1470   imageView.SetProperty(Control::Property::PADDING, Extents(15, 10, 5, 10));
1471   application.GetScene().Add(imageView);
1472
1473   application.SendNotification();
1474   application.Render();
1475
1476   DALI_TEST_EQUALS(imageView.GetProperty<Extents>(Control::Property::PADDING), Extents(15, 10, 5, 10), TEST_LOCATION);
1477
1478   // Check whether Image Visual transforms on ImageVieiw::OnRelayout()
1479   Toolkit::Internal::Control& controlImpl = Toolkit::Internal::GetImplementation(imageView);
1480   Toolkit::Visual::Base       imageVisual = DevelControl::GetVisual(controlImpl, ImageView::Property::IMAGE);
1481   Property::Map               resultMap;
1482   imageVisual.CreatePropertyMap(resultMap);
1483
1484   Property::Value* transformValue = resultMap.Find(Visual::Property::TRANSFORM);
1485   DALI_TEST_CHECK(transformValue);
1486   Property::Map* retMap = transformValue->GetMap();
1487   DALI_TEST_CHECK(retMap);
1488
1489   // Image Visual should be positioned depending on ImageView's padding
1490   DALI_TEST_EQUALS(retMap->Find(Visual::Transform::Property::OFFSET)->Get<Vector2>(), Vector2(15, 5), TEST_LOCATION);
1491
1492   END_TEST;
1493 }
1494
1495 int UtcDaliImageViewPaddingProperty03(void)
1496 {
1497   tet_infoline("Test Setting Image Padding then removing it.");
1498
1499   ToolkitTestApplication application;
1500
1501   ImageView     imageView = ImageView::New();
1502   Property::Map imagePropertyMap;
1503   imagePropertyMap[Toolkit::Visual::Property::TYPE]            = Toolkit::Visual::IMAGE;
1504   imagePropertyMap[Toolkit::ImageVisual::Property::URL]        = TEST_RESOURCE_DIR "/Kid1.svg";
1505   imagePropertyMap[ImageVisual::Property::DESIRED_WIDTH]       = 128;
1506   imagePropertyMap[ImageVisual::Property::DESIRED_HEIGHT]      = 128;
1507   imagePropertyMap[DevelVisual::Property::VISUAL_FITTING_MODE] = Toolkit::DevelVisual::FIT_KEEP_ASPECT_RATIO;
1508   imageView.SetProperty(Toolkit::ImageView::Property::IMAGE, imagePropertyMap);
1509   imageView.SetProperty(Actor::Property::ANCHOR_POINT, AnchorPoint::TOP_LEFT);
1510   imageView.SetProperty(Actor::Property::PARENT_ORIGIN, ParentOrigin::TOP_LEFT);
1511   imageView.SetProperty(Control::Property::PADDING, Extents(15, 10, 5, 10));
1512   application.GetScene().Add(imageView);
1513
1514   application.SendNotification();
1515   application.Render();
1516
1517   DALI_TEST_EQUALS(imageView.GetProperty<Extents>(Control::Property::PADDING), Extents(15, 10, 5, 10), TEST_LOCATION);
1518
1519   tet_infoline("Remove Padding and test Visual is position correctly");
1520
1521   imageView.SetProperty(Control::Property::PADDING, Extents(0, 0, 0, 0));
1522
1523   application.SendNotification();
1524   application.Render();
1525
1526   // Check whether Image Visual transforms on ImageVieiw::OnRelayout()
1527   Toolkit::Internal::Control& controlImpl = Toolkit::Internal::GetImplementation(imageView);
1528   Toolkit::Visual::Base       imageVisual = DevelControl::GetVisual(controlImpl, ImageView::Property::IMAGE);
1529   Property::Map               resultMap;
1530   imageVisual.CreatePropertyMap(resultMap);
1531
1532   Property::Value* transformValue = resultMap.Find(Visual::Property::TRANSFORM);
1533   DALI_TEST_CHECK(transformValue);
1534   Property::Map* retMap = transformValue->GetMap();
1535   DALI_TEST_CHECK(retMap);
1536
1537   // Image Visual should be positioned depending on ImageView's padding
1538   DALI_TEST_EQUALS(retMap->Find(Visual::Transform::Property::OFFSET)->Get<Vector2>(), Vector2(0, 0), TEST_LOCATION);
1539
1540   END_TEST;
1541 }
1542
1543 int UtcDaliImageViewPaddingProperty04(void)
1544 {
1545   tet_infoline("Test Setting Image Padding then removing it. Visual Fitting Mode as Fill");
1546
1547   ToolkitTestApplication application;
1548
1549   ImageView     imageView = ImageView::New();
1550   Property::Map imagePropertyMap;
1551   imagePropertyMap[Toolkit::Visual::Property::TYPE]            = Toolkit::Visual::IMAGE;
1552   imagePropertyMap[Toolkit::ImageVisual::Property::URL]        = TEST_RESOURCE_DIR "/Kid1.svg";
1553   imagePropertyMap[ImageVisual::Property::DESIRED_WIDTH]       = 128;
1554   imagePropertyMap[ImageVisual::Property::DESIRED_HEIGHT]      = 128;
1555   imagePropertyMap[DevelVisual::Property::VISUAL_FITTING_MODE] = Toolkit::DevelVisual::FILL;
1556   imageView.SetProperty(Toolkit::ImageView::Property::IMAGE, imagePropertyMap);
1557   imageView.SetProperty(Actor::Property::ANCHOR_POINT, AnchorPoint::TOP_LEFT);
1558   imageView.SetProperty(Actor::Property::PARENT_ORIGIN, ParentOrigin::TOP_LEFT);
1559   imageView.SetProperty(Control::Property::PADDING, Extents(15, 10, 5, 10));
1560   application.GetScene().Add(imageView);
1561
1562   application.SendNotification();
1563   application.Render();
1564
1565   DALI_TEST_EQUALS(imageView.GetProperty<Extents>(Control::Property::PADDING), Extents(15, 10, 5, 10), TEST_LOCATION);
1566
1567   tet_infoline("Remove Padding and test Visual is position correctly");
1568
1569   imageView.SetProperty(Control::Property::PADDING, Extents(0, 0, 0, 0));
1570
1571   application.SendNotification();
1572   application.Render();
1573
1574   // Check whether Image Visual transforms on ImageVieiw::OnRelayout()
1575   Toolkit::Internal::Control& controlImpl = Toolkit::Internal::GetImplementation(imageView);
1576   Toolkit::Visual::Base       imageVisual = DevelControl::GetVisual(controlImpl, ImageView::Property::IMAGE);
1577   Property::Map               resultMap;
1578   imageVisual.CreatePropertyMap(resultMap);
1579
1580   Property::Value* transformValue = resultMap.Find(Visual::Property::TRANSFORM);
1581   DALI_TEST_CHECK(transformValue);
1582   Property::Map* retMap = transformValue->GetMap();
1583   DALI_TEST_CHECK(retMap);
1584
1585   // Image Visual should be positioned depending on ImageView's padding
1586   DALI_TEST_EQUALS(retMap->Find(Visual::Transform::Property::OFFSET)->Get<Vector2>(), Vector2(0, 0), TEST_LOCATION);
1587
1588   END_TEST;
1589 }
1590
1591 int UtcDaliImageViewTransformTest01(void)
1592 {
1593   tet_infoline("Test Setting a offset transform on the ImageView");
1594
1595   ToolkitTestApplication application;
1596
1597   ImageView     imageView = ImageView::New();
1598   Property::Map imagePropertyMap;
1599   imagePropertyMap.Add(Toolkit::Visual::Property::TYPE, Toolkit::Visual::IMAGE)
1600     .Add(Toolkit::ImageVisual::Property::URL, TEST_RESOURCE_DIR "/Kid1.svg")
1601     .Add(ImageVisual::Property::DESIRED_WIDTH, 120)
1602     .Add(ImageVisual::Property::DESIRED_HEIGHT, 120)
1603     .Add(DevelVisual::Property::VISUAL_FITTING_MODE, Toolkit::DevelVisual::FILL)
1604     .Add(Visual::Property::TRANSFORM,
1605          Property::Map().Add(Toolkit::Visual::Transform::Property::OFFSET_POLICY,
1606                              Vector2(Visual::Transform::Policy::ABSOLUTE, Visual::Transform::Policy::ABSOLUTE))
1607            .Add(Toolkit::Visual::Transform::Property::OFFSET, Vector2(8, 8)));
1608
1609   imageView.SetProperty(Toolkit::ImageView::Property::IMAGE, imagePropertyMap);
1610   imageView.SetProperty(Actor::Property::ANCHOR_POINT, AnchorPoint::TOP_LEFT);
1611   imageView.SetProperty(Actor::Property::PARENT_ORIGIN, ParentOrigin::TOP_LEFT);
1612   application.GetScene().Add(imageView);
1613
1614   application.SendNotification();
1615   application.Render();
1616
1617   // Check whether Image Visual transforms on ImageVieiw::OnRelayout()
1618   Toolkit::Internal::Control& controlImpl = Toolkit::Internal::GetImplementation(imageView);
1619   Toolkit::Visual::Base       imageVisual = DevelControl::GetVisual(controlImpl, ImageView::Property::IMAGE);
1620   Property::Map               resultMap;
1621   imageVisual.CreatePropertyMap(resultMap);
1622
1623   Property::Value* transformValue = resultMap.Find(Visual::Property::TRANSFORM);
1624   DALI_TEST_CHECK(transformValue);
1625   Property::Map* retMap = transformValue->GetMap();
1626   DALI_TEST_CHECK(retMap);
1627
1628   // Image Visual should be positioned depending on ImageView's padding
1629   DALI_TEST_EQUALS(retMap->Find(Visual::Transform::Property::OFFSET)->Get<Vector2>(), Vector2(8, 8), TEST_LOCATION);
1630   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);
1631
1632   END_TEST;
1633 }
1634
1635 int UtcDaliImageViewUsingAtlasAndGetNaturalSize(void)
1636 {
1637   ToolkitTestApplication application;
1638
1639   // Check ImageView with background and main image, to ensure both visuals are marked as loaded
1640   ImageView     imageView = ImageView::New();
1641   Property::Map imageMap;
1642   imageMap[Toolkit::Visual::Property::TYPE]          = Toolkit::Visual::IMAGE;
1643   imageMap[Toolkit::ImageVisual::Property::URL]      = gImage_34_RGBA;
1644   imageMap[Toolkit::ImageVisual::Property::ATLASING] = true;
1645   imageView.SetProperty(Toolkit::ImageView::Property::IMAGE, imageMap);
1646   application.GetScene().Add(imageView);
1647
1648   // Trigger a potential relayout
1649   application.SendNotification();
1650   application.Render();
1651
1652   Vector3 naturalSize = imageView.GetNaturalSize();
1653
1654   DALI_TEST_EQUALS(naturalSize.width, 34.0f, TEST_LOCATION);
1655   DALI_TEST_EQUALS(naturalSize.height, 34.0f, TEST_LOCATION);
1656
1657   END_TEST;
1658 }
1659
1660 int UtcDaliImageViewFillMode(void)
1661 {
1662   ToolkitTestApplication application;
1663
1664   tet_infoline("Create an ImageVisual without padding and set the fill-mode to fill");
1665
1666   ImageView     imageView = ImageView::New();
1667   Property::Map imageMap;
1668   imageMap.Add(Toolkit::Visual::Property::TYPE, Toolkit::Visual::IMAGE);
1669   imageMap.Add(Toolkit::ImageVisual::Property::URL, gImage_600_RGB);
1670   imageMap.Add(DevelVisual::Property::VISUAL_FITTING_MODE, DevelVisual::FittingMode::FILL);
1671
1672   imageView.SetProperty(Toolkit::ImageView::Property::IMAGE, imageMap);
1673
1674   application.GetScene().Add(imageView);
1675
1676   // Trigger a potential relayout
1677   application.SendNotification();
1678   application.Render();
1679
1680   Toolkit::Visual::Base visual = DevelControl::GetVisual(Toolkit::Internal::GetImplementation(imageView), Toolkit::ImageView::Property::IMAGE);
1681   Property::Map         returnedMap;
1682   visual.CreatePropertyMap(returnedMap);
1683
1684   Property::Value* value = returnedMap.Find(Toolkit::Visual::Property::TRANSFORM);
1685   DALI_TEST_CHECK(value);
1686   Property::Map* map = value->GetMap();
1687   DALI_TEST_CHECK(map);
1688
1689   value = map->Find(Toolkit::Visual::Transform::Property::SIZE);
1690   DALI_TEST_CHECK(value);
1691   DALI_TEST_EQUALS(value->Get<Vector2>(), Vector2::ONE, TEST_LOCATION);
1692
1693   value = map->Find(Toolkit::Visual::Transform::Property::SIZE_POLICY);
1694   DALI_TEST_CHECK(value);
1695   DALI_TEST_CHECK(value->Get<int>() == Toolkit::Visual::Transform::Policy::RELATIVE);
1696
1697   END_TEST;
1698 }
1699
1700 int UtcDaliImageViewFittingModeFitKeepAspectRatio(void)
1701 {
1702   ToolkitTestApplication application;
1703
1704   tet_infoline("Create an ImageVisual using FitKeepAspectRatio ( image: [600,600], view: [600,700] )");
1705   tet_infoline("  There should be need to change the transform, offset is adjusted to fit inside");
1706
1707   ImageView     imageView = ImageView::New();
1708   Property::Map imageMap;
1709   imageMap.Add(Toolkit::Visual::Property::TYPE, Toolkit::Visual::IMAGE);
1710   imageMap.Add(Toolkit::ImageVisual::Property::URL, gImage_600_RGB); // 600x600 image
1711   imageMap.Add(DevelVisual::Property::VISUAL_FITTING_MODE, Toolkit::DevelVisual::FIT_KEEP_ASPECT_RATIO);
1712
1713   imageView.SetProperty(Toolkit::ImageView::Property::IMAGE, imageMap);
1714   imageView.SetProperty(Actor::Property::SIZE, Vector2(600, 700));
1715
1716   application.GetScene().Add(imageView);
1717
1718   // Trigger a potential relayout
1719   application.SendNotification();
1720   application.Render();
1721
1722   Toolkit::Visual::Base visual = DevelControl::GetVisual(Toolkit::Internal::GetImplementation(imageView), Toolkit::ImageView::Property::IMAGE);
1723   Property::Map         returnedMap;
1724   visual.CreatePropertyMap(returnedMap);
1725
1726   Property::Value* value = returnedMap.Find(Toolkit::Visual::Property::TRANSFORM);
1727   DALI_TEST_CHECK(value);
1728   Property::Map* map = value->GetMap();
1729   DALI_TEST_CHECK(map);
1730
1731   // If there's
1732   value = map->Find(Toolkit::Visual::Transform::Property::SIZE);
1733   DALI_TEST_CHECK(value);
1734   DALI_TEST_EQUALS(value->Get<Vector2>(), Vector2(600, 600), TEST_LOCATION);
1735
1736   value = map->Find(Toolkit::Visual::Transform::Property::SIZE_POLICY);
1737   DALI_TEST_CHECK(value);
1738   DALI_TEST_EQUALS(value->Get<Vector2>(), Vector2(Toolkit::Visual::Transform::Policy::ABSOLUTE, Toolkit::Visual::Transform::Policy::ABSOLUTE), TEST_LOCATION);
1739
1740   value = map->Find(Toolkit::Visual::Transform::Property::OFFSET);
1741   DALI_TEST_CHECK(value);
1742   DALI_TEST_EQUALS(value->Get<Vector2>(), Vector2(0, 50), TEST_LOCATION);
1743
1744   END_TEST;
1745 }
1746
1747 int UtcDaliImageViewFittingModesFill(void)
1748 {
1749   ToolkitTestApplication application;
1750
1751   tet_infoline("Create an ImageVisual using Fill ( image: [600,600], view: [600,700] )");
1752   tet_infoline("  There should be no need to change the transform, only size is changed to fit view");
1753
1754   ImageView     imageView = ImageView::New();
1755   Property::Map imageMap;
1756   imageMap.Add(Toolkit::Visual::Property::TYPE, Toolkit::Visual::IMAGE);
1757   imageMap.Add(Toolkit::ImageVisual::Property::URL, gImage_600_RGB); // 600x600 image
1758   imageMap.Add(DevelVisual::Property::VISUAL_FITTING_MODE, Toolkit::DevelVisual::FILL);
1759
1760   imageView.SetProperty(Toolkit::ImageView::Property::IMAGE, imageMap);
1761   imageView.SetProperty(Actor::Property::SIZE, Vector2(600, 700));
1762
1763   application.GetScene().Add(imageView);
1764
1765   // Trigger a potential relayout
1766   application.SendNotification();
1767   application.Render();
1768
1769   Toolkit::Visual::Base visual = DevelControl::GetVisual(Toolkit::Internal::GetImplementation(imageView), Toolkit::ImageView::Property::IMAGE);
1770   Property::Map         returnedMap;
1771   visual.CreatePropertyMap(returnedMap);
1772
1773   Property::Value* value = returnedMap.Find(Toolkit::Visual::Property::TRANSFORM);
1774   DALI_TEST_CHECK(value);
1775   Property::Map* map = value->GetMap();
1776   DALI_TEST_CHECK(map);
1777
1778   value = map->Find(Toolkit::Visual::Transform::Property::SIZE);
1779   DALI_TEST_CHECK(value);
1780   DALI_TEST_EQUALS(value->Get<Vector2>(), Vector2::ONE, TEST_LOCATION); // Change the internal size according to the image view size
1781
1782   value = map->Find(Toolkit::Visual::Transform::Property::SIZE_POLICY);
1783   DALI_TEST_CHECK(value);
1784   DALI_TEST_CHECK(value->Get<int>() == Toolkit::Visual::Transform::Policy::RELATIVE);
1785
1786   value = map->Find(Toolkit::Visual::Transform::Property::OFFSET);
1787   DALI_TEST_CHECK(value);
1788   DALI_TEST_EQUALS(value->Get<Vector2>(), Vector2(0, 0), TEST_LOCATION); // OFFSET is zero
1789
1790   END_TEST;
1791 }
1792
1793 int UtcDaliImageViewFittingModesOverfitKeepAspectRatio(void)
1794 {
1795   ToolkitTestApplication application;
1796
1797   tet_infoline("Create an ImageVisual using OverFitKeepAspectRatio ( image: [600,600], view: [600,500] )");
1798   tet_infoline("  offset or size is the same as view, but adjust internally using pixelArea ");
1799
1800   ImageView     imageView = ImageView::New();
1801   Property::Map imageMap;
1802   imageMap.Add(Toolkit::Visual::Property::TYPE, Toolkit::Visual::IMAGE);
1803   imageMap.Add(Toolkit::ImageVisual::Property::URL, gImage_600_RGB); // 600x600 image
1804   imageMap.Add(DevelVisual::Property::VISUAL_FITTING_MODE, Toolkit::DevelVisual::OVER_FIT_KEEP_ASPECT_RATIO);
1805
1806   imageView.SetProperty(Toolkit::ImageView::Property::IMAGE, imageMap);
1807   imageView.SetProperty(Actor::Property::SIZE, Vector2(600, 500));
1808
1809   application.GetScene().Add(imageView);
1810
1811   // Trigger a potential relayout
1812   application.SendNotification();
1813   application.Render();
1814
1815   Toolkit::Visual::Base visual = DevelControl::GetVisual(Toolkit::Internal::GetImplementation(imageView), Toolkit::ImageView::Property::IMAGE);
1816   Property::Map         returnedMap;
1817   visual.CreatePropertyMap(returnedMap);
1818
1819   Property::Value* value = returnedMap.Find(Toolkit::Visual::Property::TRANSFORM);
1820   DALI_TEST_CHECK(value);
1821   Property::Map* map = value->GetMap();
1822   DALI_TEST_CHECK(map);
1823
1824   // If there's
1825   value = map->Find(Toolkit::Visual::Transform::Property::SIZE);
1826   DALI_TEST_CHECK(value);
1827   DALI_TEST_EQUALS(value->Get<Vector2>(), Vector2(600, 500), TEST_LOCATION); // Change the internal size according to the image view size
1828
1829   value = map->Find(Toolkit::Visual::Transform::Property::SIZE_POLICY);
1830   DALI_TEST_CHECK(value);
1831   DALI_TEST_EQUALS(value->Get<Vector2>(), Vector2(Toolkit::Visual::Transform::Policy::ABSOLUTE, Toolkit::Visual::Transform::Policy::ABSOLUTE), TEST_LOCATION);
1832
1833   value = map->Find(Toolkit::Visual::Transform::Property::OFFSET);
1834   DALI_TEST_CHECK(value);
1835   DALI_TEST_EQUALS(value->Get<Vector2>(), Vector2(0, 0), TEST_LOCATION); // OFFSET is zero
1836
1837   END_TEST;
1838 }
1839
1840 int UtcDaliImageViewFittingModesCenter01(void)
1841 {
1842   ToolkitTestApplication application;
1843
1844   tet_infoline("Create an ImageVisual using Center ( image: [600,600], view: [700,700] )");
1845   tet_infoline("  There should be need to change the transform, offset is adjusted to fit inside");
1846
1847   ImageView     imageView = ImageView::New();
1848   Property::Map imageMap;
1849   imageMap.Add(Toolkit::Visual::Property::TYPE, Toolkit::Visual::IMAGE);
1850   imageMap.Add(Toolkit::ImageVisual::Property::URL, gImage_600_RGB); // 600x600 image
1851   imageMap.Add(DevelVisual::Property::VISUAL_FITTING_MODE, Toolkit::DevelVisual::CENTER);
1852
1853   imageView.SetProperty(Toolkit::ImageView::Property::IMAGE, imageMap);
1854   imageView.SetProperty(Actor::Property::SIZE, Vector2(700, 700));
1855
1856   application.GetScene().Add(imageView);
1857
1858   // Trigger a potential relayout
1859   application.SendNotification();
1860   application.Render();
1861
1862   Toolkit::Visual::Base visual = DevelControl::GetVisual(Toolkit::Internal::GetImplementation(imageView), Toolkit::ImageView::Property::IMAGE);
1863   Property::Map         returnedMap;
1864   visual.CreatePropertyMap(returnedMap);
1865
1866   Property::Value* value = returnedMap.Find(Toolkit::Visual::Property::TRANSFORM);
1867   DALI_TEST_CHECK(value);
1868   Property::Map* map = value->GetMap();
1869   DALI_TEST_CHECK(map);
1870
1871   value = map->Find(Toolkit::Visual::Transform::Property::SIZE);
1872   DALI_TEST_CHECK(value);
1873   DALI_TEST_EQUALS(value->Get<Vector2>(), Vector2(600, 600), TEST_LOCATION); // Change the internal size according to the image view size
1874
1875   value = map->Find(Toolkit::Visual::Transform::Property::SIZE_POLICY);
1876   DALI_TEST_CHECK(value);
1877   DALI_TEST_EQUALS(value->Get<Vector2>(), Vector2(Toolkit::Visual::Transform::Policy::ABSOLUTE, Toolkit::Visual::Transform::Policy::ABSOLUTE), TEST_LOCATION);
1878
1879   value = map->Find(Toolkit::Visual::Transform::Property::OFFSET);
1880   DALI_TEST_CHECK(value);
1881   DALI_TEST_EQUALS(value->Get<Vector2>(), Vector2(50, 50), TEST_LOCATION);
1882
1883   END_TEST;
1884 }
1885
1886 int UtcDaliImageViewFittingModesCenter02(void)
1887 {
1888   ToolkitTestApplication application;
1889
1890   tet_infoline("Create an ImageVisual using Center ( image: [600,600], view: [500,500] )");
1891   tet_infoline("  There should be need to change the transform, offset is adjusted to fit inside");
1892
1893   ImageView     imageView = ImageView::New();
1894   Property::Map imageMap;
1895   imageMap.Add(Toolkit::Visual::Property::TYPE, Toolkit::Visual::IMAGE);
1896   imageMap.Add(Toolkit::ImageVisual::Property::URL, gImage_600_RGB); // 600x600 image
1897   imageMap.Add(DevelVisual::Property::VISUAL_FITTING_MODE, Toolkit::DevelVisual::CENTER);
1898
1899   imageView.SetProperty(Toolkit::ImageView::Property::IMAGE, imageMap);
1900   imageView.SetProperty(Actor::Property::SIZE, Vector2(700, 700));
1901
1902   application.GetScene().Add(imageView);
1903
1904   // Trigger a potential relayout
1905   application.SendNotification();
1906   application.Render();
1907
1908   Toolkit::Visual::Base visual = DevelControl::GetVisual(Toolkit::Internal::GetImplementation(imageView), Toolkit::ImageView::Property::IMAGE);
1909   Property::Map         returnedMap;
1910   visual.CreatePropertyMap(returnedMap);
1911
1912   Property::Value* value = returnedMap.Find(Toolkit::Visual::Property::TRANSFORM);
1913   DALI_TEST_CHECK(value);
1914   Property::Map* map = value->GetMap();
1915   DALI_TEST_CHECK(map);
1916
1917   value = map->Find(Toolkit::Visual::Transform::Property::SIZE);
1918   DALI_TEST_CHECK(value);
1919   DALI_TEST_EQUALS(value->Get<Vector2>(), Vector2(600, 600), TEST_LOCATION); // Change the internal size according to the image view size
1920
1921   value = map->Find(Toolkit::Visual::Transform::Property::SIZE_POLICY);
1922   DALI_TEST_CHECK(value);
1923   DALI_TEST_EQUALS(value->Get<Vector2>(), Vector2(Toolkit::Visual::Transform::Policy::ABSOLUTE, Toolkit::Visual::Transform::Policy::ABSOLUTE), TEST_LOCATION);
1924
1925   value = map->Find(Toolkit::Visual::Transform::Property::OFFSET);
1926   DALI_TEST_CHECK(value);
1927   DALI_TEST_EQUALS(value->Get<Vector2>(), Vector2(50, 50), TEST_LOCATION);
1928
1929   END_TEST;
1930 }
1931
1932 int UtcDaliImageViewFittingModesFitHeight01(void)
1933 {
1934   ToolkitTestApplication application;
1935
1936   tet_infoline("Create an ImageVisual using FitHeight ( image: [600,600], view: [600,700] )");
1937
1938   ImageView     imageView = ImageView::New();
1939   Property::Map imageMap;
1940   imageMap.Add(Toolkit::Visual::Property::TYPE, Toolkit::Visual::IMAGE);
1941   imageMap.Add(Toolkit::ImageVisual::Property::URL, gImage_600_RGB); // 600x600 image
1942   imageMap.Add(DevelVisual::Property::VISUAL_FITTING_MODE, Toolkit::DevelVisual::FIT_HEIGHT);
1943
1944   imageView.SetProperty(Toolkit::ImageView::Property::IMAGE, imageMap);
1945   imageView.SetProperty(Actor::Property::SIZE, Vector2(600, 700));
1946
1947   application.GetScene().Add(imageView);
1948
1949   // Trigger a potential relayout
1950   application.SendNotification();
1951   application.Render();
1952
1953   Toolkit::Visual::Base visual = DevelControl::GetVisual(Toolkit::Internal::GetImplementation(imageView), Toolkit::ImageView::Property::IMAGE);
1954   Property::Map         returnedMap;
1955   visual.CreatePropertyMap(returnedMap);
1956
1957   Property::Value* value = returnedMap.Find(Toolkit::Visual::Property::TRANSFORM);
1958   DALI_TEST_CHECK(value);
1959   Property::Map* map = value->GetMap();
1960   DALI_TEST_CHECK(map);
1961
1962   value = map->Find(Toolkit::Visual::Transform::Property::SIZE);
1963   DALI_TEST_CHECK(value);
1964   DALI_TEST_EQUALS(value->Get<Vector2>(), Vector2(600, 700), TEST_LOCATION); // Change the internal size according to the image view size
1965
1966   value = map->Find(Toolkit::Visual::Transform::Property::SIZE_POLICY);
1967   DALI_TEST_CHECK(value);
1968   DALI_TEST_EQUALS(value->Get<Vector2>(), Vector2(Toolkit::Visual::Transform::Policy::ABSOLUTE, Toolkit::Visual::Transform::Policy::ABSOLUTE), TEST_LOCATION);
1969
1970   value = map->Find(Toolkit::Visual::Transform::Property::OFFSET);
1971   DALI_TEST_CHECK(value);
1972   DALI_TEST_EQUALS(value->Get<Vector2>(), Vector2(0, 0), TEST_LOCATION); // OFFSET is zero
1973
1974   END_TEST;
1975 }
1976
1977 int UtcDaliImageViewFittingModesFitHeight02(void)
1978 {
1979   ToolkitTestApplication application;
1980
1981   tet_infoline("Create an ImageVisual using FitHeight ( image: [600,600], view: [700,600] )");
1982
1983   ImageView     imageView = ImageView::New();
1984   Property::Map imageMap;
1985   imageMap.Add(Toolkit::Visual::Property::TYPE, Toolkit::Visual::IMAGE);
1986   imageMap.Add(Toolkit::ImageVisual::Property::URL, gImage_600_RGB); // 249x169 image
1987   imageMap.Add(DevelVisual::Property::VISUAL_FITTING_MODE, Toolkit::DevelVisual::FIT_HEIGHT);
1988
1989   imageView.SetProperty(Toolkit::ImageView::Property::IMAGE, imageMap);
1990   imageView.SetProperty(Actor::Property::SIZE, Vector2(700, 600));
1991
1992   application.GetScene().Add(imageView);
1993
1994   // Trigger a potential relayout
1995   application.SendNotification();
1996   application.Render();
1997
1998   Toolkit::Visual::Base visual = DevelControl::GetVisual(Toolkit::Internal::GetImplementation(imageView), Toolkit::ImageView::Property::IMAGE);
1999   Property::Map         returnedMap;
2000   visual.CreatePropertyMap(returnedMap);
2001
2002   Property::Value* value = returnedMap.Find(Toolkit::Visual::Property::TRANSFORM);
2003   DALI_TEST_CHECK(value);
2004   Property::Map* map = value->GetMap();
2005   DALI_TEST_CHECK(map);
2006
2007   value = map->Find(Toolkit::Visual::Transform::Property::SIZE);
2008   DALI_TEST_CHECK(value);
2009   DALI_TEST_EQUALS(value->Get<Vector2>(), Vector2(600, 600), TEST_LOCATION); // Change the internal size according to the image view size
2010
2011   value = map->Find(Toolkit::Visual::Transform::Property::SIZE_POLICY);
2012   DALI_TEST_CHECK(value);
2013   DALI_TEST_EQUALS(value->Get<Vector2>(), Vector2(Toolkit::Visual::Transform::Policy::ABSOLUTE, Toolkit::Visual::Transform::Policy::ABSOLUTE), TEST_LOCATION);
2014
2015   value = map->Find(Toolkit::Visual::Transform::Property::OFFSET);
2016   DALI_TEST_CHECK(value);
2017   DALI_TEST_EQUALS(value->Get<Vector2>(), Vector2(50, 0), TEST_LOCATION);
2018
2019   END_TEST;
2020 }
2021
2022 int UtcDaliImageViewFittingModesFitWidth01(void)
2023 {
2024   ToolkitTestApplication application;
2025
2026   tet_infoline("Create an ImageVisual using FitWidth ( image: [600,600], view: [600,700] )");
2027
2028   ImageView     imageView = ImageView::New();
2029   Property::Map imageMap;
2030   imageMap.Add(Toolkit::Visual::Property::TYPE, Toolkit::Visual::IMAGE);
2031   imageMap.Add(Toolkit::ImageVisual::Property::URL, gImage_600_RGB); // 600x600 image
2032   imageMap.Add(DevelVisual::Property::VISUAL_FITTING_MODE, Toolkit::DevelVisual::FIT_WIDTH);
2033
2034   imageView.SetProperty(Toolkit::ImageView::Property::IMAGE, imageMap);
2035   imageView.SetProperty(Actor::Property::SIZE, Vector2(600, 700));
2036
2037   application.GetScene().Add(imageView);
2038
2039   // Trigger a potential relayout
2040   application.SendNotification();
2041   application.Render();
2042
2043   Toolkit::Visual::Base visual = DevelControl::GetVisual(Toolkit::Internal::GetImplementation(imageView), Toolkit::ImageView::Property::IMAGE);
2044   Property::Map         returnedMap;
2045   visual.CreatePropertyMap(returnedMap);
2046
2047   Property::Value* value = returnedMap.Find(Toolkit::Visual::Property::TRANSFORM);
2048   DALI_TEST_CHECK(value);
2049   Property::Map* map = value->GetMap();
2050   DALI_TEST_CHECK(map);
2051
2052   value = map->Find(Toolkit::Visual::Transform::Property::SIZE);
2053   DALI_TEST_CHECK(value);
2054   DALI_TEST_EQUALS(value->Get<Vector2>(), Vector2(600, 600), TEST_LOCATION); // Change the internal size according to the image view size
2055
2056   value = map->Find(Toolkit::Visual::Transform::Property::SIZE_POLICY);
2057   DALI_TEST_CHECK(value);
2058   DALI_TEST_EQUALS(value->Get<Vector2>(), Vector2(Toolkit::Visual::Transform::Policy::ABSOLUTE, Toolkit::Visual::Transform::Policy::ABSOLUTE), TEST_LOCATION);
2059
2060   value = map->Find(Toolkit::Visual::Transform::Property::OFFSET);
2061   DALI_TEST_CHECK(value);
2062   DALI_TEST_EQUALS(value->Get<Vector2>(), Vector2(0, 50), TEST_LOCATION);
2063
2064   END_TEST;
2065 }
2066
2067 int UtcDaliImageViewFittingModesFitWidth02(void)
2068 {
2069   ToolkitTestApplication application;
2070
2071   tet_infoline("Create an ImageVisual using FitWidth ( image: [600,600], view:[700,600] )");
2072
2073   ImageView     imageView = ImageView::New();
2074   Property::Map imageMap;
2075   imageMap.Add(Toolkit::Visual::Property::TYPE, Toolkit::Visual::IMAGE);
2076   imageMap.Add(Toolkit::ImageVisual::Property::URL, gImage_600_RGB); // 249x169 image
2077   imageMap.Add(DevelVisual::Property::VISUAL_FITTING_MODE, Toolkit::DevelVisual::FIT_WIDTH);
2078
2079   imageView.SetProperty(Toolkit::ImageView::Property::IMAGE, imageMap);
2080   imageView.SetProperty(Actor::Property::SIZE, Vector2(700, 600));
2081
2082   application.GetScene().Add(imageView);
2083
2084   // Trigger a potential relayout
2085   application.SendNotification();
2086   application.Render();
2087
2088   Toolkit::Visual::Base visual = DevelControl::GetVisual(Toolkit::Internal::GetImplementation(imageView), Toolkit::ImageView::Property::IMAGE);
2089   Property::Map         returnedMap;
2090   visual.CreatePropertyMap(returnedMap);
2091
2092   Property::Value* value = returnedMap.Find(Toolkit::Visual::Property::TRANSFORM);
2093   DALI_TEST_CHECK(value);
2094   Property::Map* map = value->GetMap();
2095   DALI_TEST_CHECK(map);
2096
2097   value = map->Find(Toolkit::Visual::Transform::Property::SIZE);
2098   DALI_TEST_CHECK(value);
2099   DALI_TEST_EQUALS(value->Get<Vector2>(), Vector2(700, 600), TEST_LOCATION); // Change the internal size according to the image view size
2100
2101   value = map->Find(Toolkit::Visual::Transform::Property::SIZE_POLICY);
2102   DALI_TEST_CHECK(value);
2103   DALI_TEST_EQUALS(value->Get<Vector2>(), Vector2(Toolkit::Visual::Transform::Policy::ABSOLUTE, Toolkit::Visual::Transform::Policy::ABSOLUTE), TEST_LOCATION);
2104
2105   value = map->Find(Toolkit::Visual::Transform::Property::OFFSET);
2106   DALI_TEST_CHECK(value);
2107   DALI_TEST_EQUALS(value->Get<Vector2>(), Vector2(0, 0), TEST_LOCATION); // OFFSET is zero
2108
2109   END_TEST;
2110 }
2111
2112 int UtcDaliImageViewFittingModesChangeFittingMode01(void)
2113 {
2114   ToolkitTestApplication application;
2115
2116   tet_infoline("UtcDaliImageViewFittingModesChangeFittingMode, image: [600,600], view:[800,700]");
2117
2118   ImageView imageView = ImageView::New();
2119
2120   // 1. Render using FittingMode::SHRINK_TO_FIT
2121   Property::Map imageMap;
2122   imageMap[Toolkit::Visual::Property::TYPE]            = Toolkit::Visual::IMAGE;
2123   imageMap[Toolkit::ImageVisual::Property::URL]        = gImage_600_RGB;
2124   imageMap[DevelVisual::Property::VISUAL_FITTING_MODE] = Toolkit::DevelVisual::FIT_KEEP_ASPECT_RATIO;
2125
2126   imageView.SetProperty(Toolkit::ImageView::Property::IMAGE, imageMap);
2127   imageView.SetProperty(Actor::Property::SIZE, Vector2(800, 700));
2128
2129   application.GetScene().Add(imageView);
2130
2131   // Trigger a potential relayout
2132   application.SendNotification();
2133   application.Render();
2134
2135   Toolkit::Visual::Base visual = DevelControl::GetVisual(Toolkit::Internal::GetImplementation(imageView), Toolkit::ImageView::Property::IMAGE);
2136   Property::Map         returnedMap;
2137   visual.CreatePropertyMap(returnedMap);
2138
2139   Property::Value* value = returnedMap.Find(Toolkit::Visual::Property::TRANSFORM);
2140   DALI_TEST_CHECK(value);
2141   Property::Map* map = value->GetMap();
2142   DALI_TEST_CHECK(map);
2143
2144   value = map->Find(Toolkit::Visual::Transform::Property::SIZE);
2145   DALI_TEST_CHECK(value);
2146   DALI_TEST_EQUALS(value->Get<Vector2>(), Vector2(700, 700), TEST_LOCATION); // Change the internal size according to the image view size
2147
2148   value = map->Find(Toolkit::Visual::Transform::Property::SIZE_POLICY);
2149   DALI_TEST_CHECK(value);
2150   DALI_TEST_EQUALS(value->Get<Vector2>(), Vector2(Toolkit::Visual::Transform::Policy::ABSOLUTE, Toolkit::Visual::Transform::Policy::ABSOLUTE), TEST_LOCATION);
2151
2152   value = map->Find(Toolkit::Visual::Transform::Property::OFFSET);
2153   DALI_TEST_CHECK(value);
2154   DALI_TEST_EQUALS(value->Get<Vector2>(), Vector2(50, 0), TEST_LOCATION);
2155
2156   // 2. Render again using DevelVisaul::CENTER
2157   Property::Map imageMap2;
2158   imageMap2[Toolkit::Visual::Property::TYPE]            = Toolkit::Visual::IMAGE;
2159   imageMap2[Toolkit::ImageVisual::Property::URL]        = gImage_600_RGB;
2160   imageMap2[DevelVisual::Property::VISUAL_FITTING_MODE] = Toolkit::DevelVisual::CENTER;
2161
2162   imageView.SetProperty(Toolkit::ImageView::Property::IMAGE, imageMap2);
2163   imageView.SetProperty(Actor::Property::SIZE, Vector2(800, 700));
2164
2165   application.GetScene().Add(imageView);
2166
2167   DALI_TEST_EQUALS(Test::WaitForEventThreadTrigger(1), true, TEST_LOCATION);
2168
2169   // Trigger a potential relayout
2170   application.SendNotification();
2171   application.Render();
2172
2173   returnedMap.Clear();
2174   visual = DevelControl::GetVisual(Toolkit::Internal::GetImplementation(imageView), Toolkit::ImageView::Property::IMAGE);
2175
2176   visual.CreatePropertyMap(returnedMap);
2177
2178   value = returnedMap.Find(Toolkit::Visual::Property::TRANSFORM);
2179   DALI_TEST_CHECK(value);
2180   map = value->GetMap();
2181   DALI_TEST_CHECK(map);
2182
2183   value = map->Find(Toolkit::Visual::Transform::Property::SIZE);
2184   DALI_TEST_CHECK(value);
2185   DALI_TEST_EQUALS(value->Get<Vector2>(), Vector2(600, 600), TEST_LOCATION); // Change the internal size according to the image view size
2186
2187   value = map->Find(Toolkit::Visual::Transform::Property::SIZE_POLICY);
2188   DALI_TEST_CHECK(value);
2189   DALI_TEST_EQUALS(value->Get<Vector2>(), Vector2(Toolkit::Visual::Transform::Policy::ABSOLUTE, Toolkit::Visual::Transform::Policy::ABSOLUTE), TEST_LOCATION);
2190
2191   value = map->Find(Toolkit::Visual::Transform::Property::OFFSET);
2192   DALI_TEST_CHECK(value);
2193   DALI_TEST_EQUALS(value->Get<Vector2>(), Vector2(100, 50), TEST_LOCATION);
2194
2195   // 3. Render again using before fittingMode
2196   Property::Map imageMap3;
2197   imageMap3[Toolkit::Visual::Property::TYPE]            = Toolkit::Visual::IMAGE;
2198   imageMap3[Toolkit::ImageVisual::Property::URL]        = gImage_600_RGB;
2199   imageMap3[DevelVisual::Property::VISUAL_FITTING_MODE] = Toolkit::DevelVisual::FIT_KEEP_ASPECT_RATIO;
2200
2201   imageView.SetProperty(Toolkit::ImageView::Property::IMAGE, imageMap3);
2202   imageView.SetProperty(Actor::Property::SIZE, Vector2(800, 700));
2203
2204   application.GetScene().Add(imageView);
2205
2206   // Trigger a potential relayout
2207   application.SendNotification();
2208   application.Render();
2209
2210   returnedMap.Clear();
2211   visual = DevelControl::GetVisual(Toolkit::Internal::GetImplementation(imageView), Toolkit::ImageView::Property::IMAGE);
2212   visual.CreatePropertyMap(returnedMap);
2213
2214   value = returnedMap.Find(Toolkit::Visual::Property::TRANSFORM);
2215   DALI_TEST_CHECK(value);
2216   map = value->GetMap();
2217   DALI_TEST_CHECK(map);
2218
2219   value = map->Find(Toolkit::Visual::Transform::Property::SIZE);
2220   DALI_TEST_CHECK(value);
2221   DALI_TEST_EQUALS(value->Get<Vector2>(), Vector2(700, 700), TEST_LOCATION); // Change the internal size according to the image view size
2222
2223   value = map->Find(Toolkit::Visual::Transform::Property::SIZE_POLICY);
2224   DALI_TEST_CHECK(value);
2225   DALI_TEST_EQUALS(value->Get<Vector2>(), Vector2(Toolkit::Visual::Transform::Policy::ABSOLUTE, Toolkit::Visual::Transform::Policy::ABSOLUTE), TEST_LOCATION);
2226
2227   value = map->Find(Toolkit::Visual::Transform::Property::OFFSET);
2228   DALI_TEST_CHECK(value);
2229   DALI_TEST_EQUALS(value->Get<Vector2>(), Vector2(50, 0), TEST_LOCATION);
2230
2231   END_TEST;
2232 }
2233
2234 int UtcDaliImageViewFittingModesChangeFittingMode02(void)
2235 {
2236   ToolkitTestApplication application;
2237
2238   tet_infoline("UtcDaliImageViewFittingModesChangeFittingMode, image: [600,600], view:[800,700]");
2239
2240   ImageView imageView = ImageView::New();
2241
2242   // 1. Render using FittingMode::OVER_FIT_KEEP_ASPECT_RATIO
2243   Property::Map imageMap;
2244   imageMap[Toolkit::Visual::Property::TYPE]            = Toolkit::Visual::IMAGE;
2245   imageMap[Toolkit::ImageVisual::Property::URL]        = gImage_600_RGB;
2246   imageMap[DevelVisual::Property::VISUAL_FITTING_MODE] = Toolkit::DevelVisual::OVER_FIT_KEEP_ASPECT_RATIO;
2247
2248   imageView.SetProperty(Toolkit::ImageView::Property::IMAGE, imageMap);
2249   imageView.SetProperty(Actor::Property::SIZE, Vector2(800, 700));
2250
2251   application.GetScene().Add(imageView);
2252
2253   // Trigger a potential relayout
2254   application.SendNotification();
2255   application.Render();
2256
2257   Toolkit::Visual::Base visual = DevelControl::GetVisual(Toolkit::Internal::GetImplementation(imageView), Toolkit::ImageView::Property::IMAGE);
2258   Property::Map         returnedMap;
2259   visual.CreatePropertyMap(returnedMap);
2260
2261   Property::Value* value = returnedMap.Find(Toolkit::Visual::Property::TRANSFORM);
2262   DALI_TEST_CHECK(value);
2263   Property::Map* map = value->GetMap();
2264   DALI_TEST_CHECK(map);
2265
2266   value = map->Find(Toolkit::Visual::Transform::Property::SIZE);
2267   DALI_TEST_CHECK(value);
2268   DALI_TEST_EQUALS(value->Get<Vector2>(), Vector2(800, 700), TEST_LOCATION); // Change the internal size according to the image view size
2269
2270   value = map->Find(Toolkit::Visual::Transform::Property::SIZE_POLICY);
2271   DALI_TEST_CHECK(value);
2272   DALI_TEST_EQUALS(value->Get<Vector2>(), Vector2(Toolkit::Visual::Transform::Policy::ABSOLUTE, Toolkit::Visual::Transform::Policy::ABSOLUTE), TEST_LOCATION);
2273
2274   value = map->Find(Toolkit::Visual::Transform::Property::OFFSET);
2275   DALI_TEST_CHECK(value);
2276   DALI_TEST_EQUALS(value->Get<Vector2>(), Vector2(0, 0), TEST_LOCATION);
2277
2278   // 2. Render again using DevelVisaul::CENTER
2279   Property::Map imageMap2;
2280   imageMap2[Toolkit::Visual::Property::TYPE]            = Toolkit::Visual::IMAGE;
2281   imageMap2[Toolkit::ImageVisual::Property::URL]        = gImage_600_RGB;
2282   imageMap2[DevelVisual::Property::VISUAL_FITTING_MODE] = Toolkit::DevelVisual::CENTER;
2283
2284   imageView.SetProperty(Toolkit::ImageView::Property::IMAGE, imageMap2);
2285   imageView.SetProperty(Actor::Property::SIZE, Vector2(800, 700));
2286
2287   application.GetScene().Add(imageView);
2288
2289   DALI_TEST_EQUALS(Test::WaitForEventThreadTrigger(1), true, TEST_LOCATION);
2290
2291   // Trigger a potential relayout
2292   application.SendNotification();
2293   application.Render();
2294
2295   returnedMap.Clear();
2296   visual = DevelControl::GetVisual(Toolkit::Internal::GetImplementation(imageView), Toolkit::ImageView::Property::IMAGE);
2297
2298   visual.CreatePropertyMap(returnedMap);
2299
2300   value = returnedMap.Find(Toolkit::Visual::Property::TRANSFORM);
2301   DALI_TEST_CHECK(value);
2302   map = value->GetMap();
2303   DALI_TEST_CHECK(map);
2304
2305   value = map->Find(Toolkit::Visual::Transform::Property::SIZE);
2306   DALI_TEST_CHECK(value);
2307   DALI_TEST_EQUALS(value->Get<Vector2>(), Vector2(600, 600), TEST_LOCATION); // Change the internal size according to the image view size
2308
2309   value = map->Find(Toolkit::Visual::Transform::Property::SIZE_POLICY);
2310   DALI_TEST_CHECK(value);
2311   DALI_TEST_EQUALS(value->Get<Vector2>(), Vector2(Toolkit::Visual::Transform::Policy::ABSOLUTE, Toolkit::Visual::Transform::Policy::ABSOLUTE), TEST_LOCATION);
2312
2313   value = map->Find(Toolkit::Visual::Transform::Property::OFFSET);
2314   DALI_TEST_CHECK(value);
2315   DALI_TEST_EQUALS(value->Get<Vector2>(), Vector2(100, 50), TEST_LOCATION);
2316
2317   // 3. Render again using before fittingMode
2318   Property::Map imageMap3;
2319   imageMap3[Toolkit::Visual::Property::TYPE]            = Toolkit::Visual::IMAGE;
2320   imageMap3[Toolkit::ImageVisual::Property::URL]        = gImage_600_RGB;
2321   imageMap3[DevelVisual::Property::VISUAL_FITTING_MODE] = Toolkit::DevelVisual::OVER_FIT_KEEP_ASPECT_RATIO;
2322
2323   imageView.SetProperty(Toolkit::ImageView::Property::IMAGE, imageMap3);
2324   imageView.SetProperty(Actor::Property::SIZE, Vector2(800, 700));
2325
2326   application.GetScene().Add(imageView);
2327
2328   // Trigger a potential relayout
2329   application.SendNotification();
2330   application.Render();
2331
2332   returnedMap.Clear();
2333   visual = DevelControl::GetVisual(Toolkit::Internal::GetImplementation(imageView), Toolkit::ImageView::Property::IMAGE);
2334   visual.CreatePropertyMap(returnedMap);
2335
2336   value = returnedMap.Find(Toolkit::Visual::Property::TRANSFORM);
2337   DALI_TEST_CHECK(value);
2338   map = value->GetMap();
2339   DALI_TEST_CHECK(map);
2340
2341   value = map->Find(Toolkit::Visual::Transform::Property::SIZE);
2342   DALI_TEST_CHECK(value);
2343   DALI_TEST_EQUALS(value->Get<Vector2>(), Vector2(800, 700), TEST_LOCATION); // Change the internal size according to the image view size
2344
2345   value = map->Find(Toolkit::Visual::Transform::Property::SIZE_POLICY);
2346   DALI_TEST_CHECK(value);
2347   DALI_TEST_EQUALS(value->Get<Vector2>(), Vector2(Toolkit::Visual::Transform::Policy::ABSOLUTE, Toolkit::Visual::Transform::Policy::ABSOLUTE), TEST_LOCATION);
2348
2349   value = map->Find(Toolkit::Visual::Transform::Property::OFFSET);
2350   DALI_TEST_CHECK(value);
2351   DALI_TEST_EQUALS(value->Get<Vector2>(), Vector2(0, 0), TEST_LOCATION);
2352
2353   END_TEST;
2354 }
2355
2356 int UtcDaliImageViewFittingModesWithAnimatedVectorImageVisual(void)
2357 {
2358   ToolkitTestApplication application;
2359
2360   tet_infoline("Create an ImageVisual using SCALE_TO_FILL and animated vector image ( image: [600,600], view:[600,600] )");
2361
2362   ImageView     imageView = ImageView::New();
2363   Property::Map imageMap;
2364   imageMap.Add(Toolkit::Visual::Property::TYPE, DevelVisual::ANIMATED_VECTOR_IMAGE);
2365   imageMap.Add(Toolkit::ImageVisual::Property::URL, TEST_ANIMATED_VECTOR_IMAGE_FILE_NAME); // 249x169 image
2366
2367   imageView.SetProperty(Toolkit::ImageView::Property::IMAGE, imageMap);
2368   imageView.SetProperty(Actor::Property::SIZE, Vector2(600, 600));
2369
2370   application.GetScene().Add(imageView);
2371
2372   // Trigger a potential relayout
2373   application.SendNotification();
2374   application.Render();
2375
2376   Toolkit::Visual::Base visual = DevelControl::GetVisual(Toolkit::Internal::GetImplementation(imageView), Toolkit::ImageView::Property::IMAGE);
2377   Property::Map         returnedMap;
2378   visual.CreatePropertyMap(returnedMap);
2379
2380   Property::Value* value = returnedMap.Find(Toolkit::Visual::Property::TRANSFORM);
2381   DALI_TEST_CHECK(value);
2382   Property::Map* map = value->GetMap();
2383   DALI_TEST_CHECK(map);
2384
2385   value = map->Find(Toolkit::Visual::Transform::Property::SIZE);
2386   DALI_TEST_CHECK(value);
2387   DALI_TEST_EQUALS(value->Get<Vector2>(), Vector2::ONE, TEST_LOCATION); // Relative size so will take up 100%
2388
2389   value = map->Find(Toolkit::Visual::Transform::Property::SIZE_POLICY);
2390   DALI_TEST_CHECK(value);
2391   DALI_TEST_CHECK(value->Get<int>() == Toolkit::Visual::Transform::Policy::RELATIVE);
2392
2393   value = map->Find(Toolkit::Visual::Transform::Property::OFFSET);
2394   DALI_TEST_CHECK(value);
2395   DALI_TEST_EQUALS(value->Get<Vector2>(), Vector2(0, 0), TEST_LOCATION); // OFFSET is zero
2396
2397   END_TEST;
2398 }
2399
2400 int UtcDaliImageViewCustomShader(void)
2401 {
2402   ToolkitTestApplication application;
2403
2404   // Set a custom shader with an image url
2405   {
2406     Property::Map     properties;
2407     Property::Map     shader;
2408     const std::string vertexShader                    = "Foobar";
2409     const std::string fragmentShader                  = "Foobar";
2410     shader[Visual::Shader::Property::FRAGMENT_SHADER] = fragmentShader;
2411     shader[Visual::Shader::Property::VERTEX_SHADER]   = vertexShader;
2412
2413     properties[Visual::Property::TYPE]     = Visual::IMAGE;
2414     properties[Visual::Property::SHADER]   = shader;
2415     properties[ImageVisual::Property::URL] = TEST_IMAGE_FILE_NAME;
2416
2417     ImageView imageView = ImageView::New();
2418     imageView.SetProperty(ImageView::Property::IMAGE, properties);
2419
2420     application.GetScene().Add(imageView);
2421
2422     application.SendNotification();
2423     application.Render();
2424
2425     DALI_TEST_EQUALS(Test::WaitForEventThreadTrigger(1), true, TEST_LOCATION);
2426
2427     Renderer        renderer = imageView.GetRendererAt(0);
2428     Shader          shader2  = renderer.GetShader();
2429     Property::Value value    = shader2.GetProperty(Shader::Property::PROGRAM);
2430     Property::Map*  map      = value.GetMap();
2431     DALI_TEST_CHECK(map);
2432
2433     Property::Value* fragment = map->Find("fragment"); // fragment key name from shader-impl.cpp
2434     DALI_TEST_EQUALS(fragmentShader, fragment->Get<std::string>(), TEST_LOCATION);
2435
2436     Property::Value* vertex = map->Find("vertex"); // vertex key name from shader-impl.cpp
2437     DALI_TEST_EQUALS(vertexShader, vertex->Get<std::string>(), TEST_LOCATION);
2438   }
2439
2440   // Set a custom shader after setting an image url
2441   {
2442     Property::Map     properties;
2443     Property::Map     shader;
2444     const std::string vertexShader                    = "Foobar";
2445     const std::string fragmentShader                  = "Foobar";
2446     shader[Visual::Shader::Property::FRAGMENT_SHADER] = fragmentShader;
2447     shader[Visual::Shader::Property::VERTEX_SHADER]   = vertexShader;
2448
2449     properties[Visual::Property::SHADER] = shader;
2450
2451     ImageView imageView = ImageView::New(TEST_IMAGE_FILE_NAME);
2452     imageView.SetProperty(ImageView::Property::IMAGE, properties);
2453
2454     application.GetScene().Add(imageView);
2455
2456     application.SendNotification();
2457     application.Render();
2458
2459     DALI_TEST_EQUALS(Test::WaitForEventThreadTrigger(1), true, TEST_LOCATION);
2460
2461     Renderer        renderer = imageView.GetRendererAt(0);
2462     Shader          shader2  = renderer.GetShader();
2463     Property::Value value    = shader2.GetProperty(Shader::Property::PROGRAM);
2464     Property::Map*  map      = value.GetMap();
2465     DALI_TEST_CHECK(map);
2466
2467     Property::Value* fragment = map->Find("fragment"); // fragment key name from shader-impl.cpp
2468     DALI_TEST_EQUALS(fragmentShader, fragment->Get<std::string>(), TEST_LOCATION);
2469
2470     Property::Value* vertex = map->Find("vertex"); // vertex key name from shader-impl.cpp
2471     DALI_TEST_EQUALS(vertexShader, vertex->Get<std::string>(), TEST_LOCATION);
2472   }
2473
2474   // Set a custom shader before setting an image url
2475   {
2476     Property::Map     properties;
2477     Property::Map     shader;
2478     const std::string vertexShader                    = "Foobar";
2479     const std::string fragmentShader                  = "Foobar";
2480     shader[Visual::Shader::Property::FRAGMENT_SHADER] = fragmentShader;
2481     shader[Visual::Shader::Property::VERTEX_SHADER]   = vertexShader;
2482
2483     properties[Visual::Property::SHADER] = shader;
2484
2485     ImageView imageView = ImageView::New();
2486     imageView.SetProperty(ImageView::Property::IMAGE, properties);
2487     imageView.SetProperty(ImageView::Property::IMAGE, TEST_IMAGE_FILE_NAME);
2488
2489     application.GetScene().Add(imageView);
2490
2491     application.SendNotification();
2492     application.Render();
2493     DALI_TEST_EQUALS(Test::WaitForEventThreadTrigger(1), true, TEST_LOCATION);
2494
2495     Renderer        renderer = imageView.GetRendererAt(0);
2496     Shader          shader2  = renderer.GetShader();
2497     Property::Value value    = shader2.GetProperty(Shader::Property::PROGRAM);
2498     Property::Map*  map      = value.GetMap();
2499     DALI_TEST_CHECK(map);
2500
2501     Property::Value* fragment = map->Find("fragment"); // fragment key name from shader-impl.cpp
2502     DALI_TEST_EQUALS(fragmentShader, fragment->Get<std::string>(), TEST_LOCATION);
2503
2504     Property::Value* vertex = map->Find("vertex"); // vertex key name from shader-impl.cpp
2505     DALI_TEST_EQUALS(vertexShader, vertex->Get<std::string>(), TEST_LOCATION);
2506   }
2507
2508   // Set a custom shader after setting a property map
2509   {
2510     Property::Map     properties;
2511     Property::Map     shader;
2512     const std::string vertexShader                    = "Foobar";
2513     const std::string fragmentShader                  = "Foobar";
2514     shader[Visual::Shader::Property::FRAGMENT_SHADER] = fragmentShader;
2515     shader[Visual::Shader::Property::VERTEX_SHADER]   = vertexShader;
2516
2517     properties[Visual::Property::SHADER] = shader;
2518
2519     Property::Map properties1;
2520     properties1[Visual::Property::TYPE]     = Visual::IMAGE;
2521     properties1[ImageVisual::Property::URL] = TEST_IMAGE_FILE_NAME;
2522
2523     ImageView imageView = ImageView::New();
2524     imageView.SetProperty(ImageView::Property::IMAGE, properties1);
2525     imageView.SetProperty(ImageView::Property::IMAGE, properties);
2526
2527     application.GetScene().Add(imageView);
2528
2529     application.SendNotification();
2530     application.Render();
2531     DALI_TEST_EQUALS(Test::WaitForEventThreadTrigger(1), true, TEST_LOCATION);
2532
2533     Renderer        renderer = imageView.GetRendererAt(0);
2534     Shader          shader2  = renderer.GetShader();
2535     Property::Value value    = shader2.GetProperty(Shader::Property::PROGRAM);
2536     Property::Map*  map      = value.GetMap();
2537     DALI_TEST_CHECK(map);
2538
2539     Property::Value* fragment = map->Find("fragment"); // fragment key name from shader-impl.cpp
2540     DALI_TEST_EQUALS(fragmentShader, fragment->Get<std::string>(), TEST_LOCATION);
2541
2542     Property::Value* vertex = map->Find("vertex"); // vertex key name from shader-impl.cpp
2543     DALI_TEST_EQUALS(vertexShader, vertex->Get<std::string>(), TEST_LOCATION);
2544   }
2545
2546   // Set a custom shader before setting a property map
2547   {
2548     Property::Map     properties;
2549     Property::Map     shader;
2550     const std::string vertexShader                    = "Foobar";
2551     const std::string fragmentShader                  = "Foobar";
2552     shader[Visual::Shader::Property::FRAGMENT_SHADER] = fragmentShader;
2553     shader[Visual::Shader::Property::VERTEX_SHADER]   = vertexShader;
2554
2555     properties[Visual::Property::SHADER] = shader;
2556
2557     Property::Map properties1;
2558     properties1[Visual::Property::TYPE]     = Visual::IMAGE;
2559     properties1[ImageVisual::Property::URL] = TEST_IMAGE_FILE_NAME;
2560
2561     ImageView imageView = ImageView::New();
2562     imageView.SetProperty(ImageView::Property::IMAGE, properties);
2563     imageView.SetProperty(ImageView::Property::IMAGE, properties1);
2564
2565     application.GetScene().Add(imageView);
2566
2567     application.SendNotification();
2568     application.Render();
2569     DALI_TEST_EQUALS(Test::WaitForEventThreadTrigger(1), true, TEST_LOCATION);
2570
2571     Renderer        renderer = imageView.GetRendererAt(0);
2572     Shader          shader2  = renderer.GetShader();
2573     Property::Value value    = shader2.GetProperty(Shader::Property::PROGRAM);
2574     Property::Map*  map      = value.GetMap();
2575     DALI_TEST_CHECK(map);
2576
2577     Property::Value* fragment = map->Find("fragment"); // fragment key name from shader-impl.cpp
2578     DALI_TEST_EQUALS(fragmentShader, fragment->Get<std::string>(), TEST_LOCATION);
2579
2580     Property::Value* vertex = map->Find("vertex"); // vertex key name from shader-impl.cpp
2581     DALI_TEST_EQUALS(vertexShader, vertex->Get<std::string>(), TEST_LOCATION);
2582   }
2583
2584   END_TEST;
2585 }
2586
2587 namespace
2588 {
2589 static int gFailCounter = 0;
2590 const int  MAX_RETRIES(3);
2591
2592 void ReloadImage(ImageView imageView)
2593 {
2594   Property::Map imageImmediateLoadingMap;
2595   imageImmediateLoadingMap[ImageVisual::Property::URL]         = "Non-existant-image.jpg";
2596   imageImmediateLoadingMap[ImageVisual::Property::LOAD_POLICY] = ImageVisual::LoadPolicy::IMMEDIATE;
2597
2598   tet_infoline("Immediate load an image");
2599   imageView.SetProperty(ImageView::Property::IMAGE, imageImmediateLoadingMap);
2600 }
2601
2602 void ResourceFailedReload(Control control)
2603 {
2604   gFailCounter++;
2605   if(gFailCounter < MAX_RETRIES)
2606   {
2607     ReloadImage(ImageView::DownCast(control));
2608   }
2609 }
2610 } // namespace
2611
2612 int UtcDaliImageViewReloadFailedOnResourceReadySignal(void)
2613 {
2614   tet_infoline("Test reloading failed image from within signal handler.");
2615
2616   ToolkitTestApplication application;
2617
2618   gFailCounter = 0;
2619
2620   ImageView imageView = ImageView::New();
2621   imageView.ResourceReadySignal().Connect(&ResourceFailedReload);
2622   DALI_TEST_EQUALS(gFailCounter, 0, TEST_LOCATION);
2623   ReloadImage(imageView);
2624
2625   // loading started, this waits for the loader thread to complete
2626   DALI_TEST_EQUALS(Test::WaitForEventThreadTrigger(1), true, TEST_LOCATION);
2627   application.SendNotification();
2628
2629   DALI_TEST_EQUALS(gFailCounter, 1, TEST_LOCATION);
2630
2631   DALI_TEST_EQUALS(Test::WaitForEventThreadTrigger(1), true, TEST_LOCATION);
2632   application.SendNotification();
2633
2634   DALI_TEST_EQUALS(gFailCounter, 2, TEST_LOCATION);
2635
2636   DALI_TEST_EQUALS(Test::WaitForEventThreadTrigger(1), true, TEST_LOCATION);
2637   application.SendNotification();
2638   DALI_TEST_EQUALS(gFailCounter, 3, TEST_LOCATION);
2639
2640   END_TEST;
2641 }
2642
2643 int UtcDaliImageViewLoadRemoteSVG(void)
2644 {
2645   tet_infoline("Test load from a remote server.");
2646
2647   ToolkitTestApplication application;
2648
2649   {
2650     Toolkit::ImageView imageView;
2651     imageView = Toolkit::ImageView::New();
2652     imageView.SetImage("https://dev.w3.org/SVG/tools/svgweb/samples/svg-files/check.svg");
2653     imageView.SetProperty(Actor::Property::PARENT_ORIGIN, ParentOrigin::TOP_LEFT);
2654     imageView.SetProperty(Actor::Property::ANCHOR_POINT, AnchorPoint::TOP_LEFT);
2655     imageView.SetProperty(Actor::Property::SIZE, Vector2(300, 300));
2656     imageView.SetProperty(Actor::Property::POSITION, Vector3(150.0f, 150.0f, 0.0f));
2657
2658     application.GetScene().Add(imageView);
2659
2660     DALI_TEST_CHECK(imageView);
2661
2662     DALI_TEST_EQUALS(imageView.GetRendererCount(), 0u, TEST_LOCATION);
2663
2664     application.SendNotification();
2665
2666     DALI_TEST_EQUALS(Test::WaitForEventThreadTrigger(1), true, TEST_LOCATION);
2667
2668     application.SendNotification();
2669     application.Render();
2670
2671     DALI_TEST_EQUALS(imageView.GetRendererCount(), 1u, TEST_LOCATION);
2672   }
2673
2674   // Without size set
2675   {
2676     Toolkit::ImageView imageView;
2677     imageView = Toolkit::ImageView::New();
2678     imageView.SetImage("https://dev.w3.org/SVG/tools/svgweb/samples/svg-files/check.svg");
2679     imageView.SetProperty(Actor::Property::PARENT_ORIGIN, ParentOrigin::TOP_LEFT);
2680     imageView.SetProperty(Actor::Property::ANCHOR_POINT, AnchorPoint::TOP_LEFT);
2681     imageView.SetProperty(Actor::Property::POSITION, Vector3(150.0f, 150.0f, 0.0f));
2682
2683     application.GetScene().Add(imageView);
2684
2685     DALI_TEST_CHECK(imageView);
2686
2687     DALI_TEST_EQUALS(imageView.GetRendererCount(), 0u, TEST_LOCATION);
2688
2689     application.SendNotification();
2690
2691     DALI_TEST_EQUALS(Test::WaitForEventThreadTrigger(1), true, TEST_LOCATION);
2692
2693     application.SendNotification();
2694     application.Render();
2695
2696     DALI_TEST_EQUALS(imageView.GetRendererCount(), 1u, TEST_LOCATION);
2697   }
2698
2699   END_TEST;
2700 }
2701
2702 int UtcDaliImageViewSyncSVGLoading(void)
2703 {
2704   ToolkitTestApplication application;
2705
2706   tet_infoline("ImageView Testing SVG image sync loading");
2707
2708   // Sync loading, automatic atlasing for small size image
2709   {
2710     TraceCallStack& callStack = application.GetGlAbstraction().GetTextureTrace();
2711     callStack.Reset();
2712     callStack.Enable(true);
2713
2714     ImageView imageView = ImageView::New();
2715
2716     // Sync loading is used
2717     Property::Map syncLoadingMap;
2718     syncLoadingMap.Insert(Toolkit::Visual::Property::TYPE, Toolkit::Visual::IMAGE);
2719     syncLoadingMap.Insert(Toolkit::ImageVisual::Property::URL, TEST_RESOURCE_DIR "/svg1.svg");
2720     syncLoadingMap.Insert(Toolkit::ImageVisual::Property::SYNCHRONOUS_LOADING, true);
2721     imageView.SetProperty(ImageView::Property::IMAGE, syncLoadingMap);
2722
2723     application.GetScene().Add(imageView);
2724     DALI_TEST_CHECK(imageView);
2725
2726     application.SendNotification();
2727     application.Render(16);
2728     Vector3 naturalSize = imageView.GetNaturalSize();
2729
2730     DALI_TEST_EQUALS(naturalSize.width, 100.0f, TEST_LOCATION);
2731     DALI_TEST_EQUALS(naturalSize.height, 100.0f, TEST_LOCATION);
2732   }
2733   END_TEST;
2734 }
2735
2736 int UtcDaliImageViewAsyncSVGLoading(void)
2737 {
2738   ToolkitTestApplication application;
2739
2740   tet_infoline("ImageView Testing SVG image async loading");
2741
2742   // Sync loading, automatic atlasing for small size image
2743   {
2744     TraceCallStack& callStack = application.GetGlAbstraction().GetTextureTrace();
2745     callStack.Reset();
2746     callStack.Enable(true);
2747
2748     ImageView imageView = ImageView::New();
2749
2750     // Sync loading is used
2751     Property::Map syncLoadingMap;
2752     syncLoadingMap.Insert(Toolkit::Visual::Property::TYPE, Toolkit::Visual::IMAGE);
2753     syncLoadingMap.Insert(Toolkit::ImageVisual::Property::URL, TEST_RESOURCE_DIR "/svg1.svg");
2754     syncLoadingMap.Insert(Toolkit::ImageVisual::Property::SYNCHRONOUS_LOADING, false);
2755     imageView.SetProperty(ImageView::Property::IMAGE, syncLoadingMap);
2756
2757     application.GetScene().Add(imageView);
2758     DALI_TEST_CHECK(imageView);
2759
2760     application.SendNotification();
2761     application.Render(16);
2762     Vector3 naturalSize = imageView.GetNaturalSize();
2763
2764     DALI_TEST_EQUALS(naturalSize.width, 100.0f, TEST_LOCATION);
2765     DALI_TEST_EQUALS(naturalSize.height, 100.0f, TEST_LOCATION);
2766   }
2767   END_TEST;
2768 }
2769
2770 int UtcDaliImageViewSVGLoadingSyncSetInvalidValue(void)
2771 {
2772   ToolkitTestApplication application;
2773
2774   tet_infoline("ImageView Testing SVG image async loading");
2775
2776   // Sync loading, automatic atlasing for small size image
2777   {
2778     TraceCallStack& callStack = application.GetGlAbstraction().GetTextureTrace();
2779     callStack.Reset();
2780     callStack.Enable(true);
2781
2782     ImageView imageView = ImageView::New();
2783
2784     // Sync loading is used
2785     Property::Map syncLoadingMap;
2786     syncLoadingMap.Insert(Toolkit::Visual::Property::TYPE, Toolkit::Visual::IMAGE);
2787     syncLoadingMap.Insert(Toolkit::ImageVisual::Property::URL, TEST_RESOURCE_DIR "/svg1.svg");
2788
2789     // Check to set invalid value
2790     // The SYNCHRONOUS_LOADING property must be set to the bool value.
2791     // Check if error log is outputted when setting other value like string.
2792     // Even if the wrong value is set, the image will be shown normally, and the synchronous value should be the default value(false).
2793     syncLoadingMap.Insert(Toolkit::ImageVisual::Property::SYNCHRONOUS_LOADING, std::to_string(5));
2794     imageView.SetProperty(ImageView::Property::IMAGE, syncLoadingMap);
2795
2796     application.GetScene().Add(imageView);
2797     DALI_TEST_CHECK(imageView);
2798
2799     application.SendNotification();
2800     application.Render(16);
2801     Vector3 naturalSize = imageView.GetNaturalSize();
2802     DALI_TEST_EQUALS(naturalSize.width, 100.0f, TEST_LOCATION);
2803     DALI_TEST_EQUALS(naturalSize.height, 100.0f, TEST_LOCATION);
2804
2805     Property::Value value = imageView.GetProperty(ImageView::Property::IMAGE);
2806     Property::Map*  map   = value.GetMap();
2807     DALI_TEST_CHECK(map);
2808
2809     Property::Value* sync = map->Find(Toolkit::ImageVisual::Property::SYNCHRONOUS_LOADING);
2810     DALI_TEST_CHECK(sync);
2811     DALI_TEST_EQUALS(false, sync->Get<bool>(), TEST_LOCATION);
2812   }
2813   END_TEST;
2814 }
2815
2816 int UtcDaliImageViewSvgLoadingFailure(void)
2817 {
2818   ToolkitTestApplication application;
2819
2820   TestGlAbstraction& gl           = application.GetGlAbstraction();
2821   TraceCallStack&    textureTrace = gl.GetTextureTrace();
2822   textureTrace.Enable(true);
2823
2824   // Local svg file - invalid file path
2825   {
2826     gResourceReadySignalFired = false;
2827
2828     ImageView imageView = ImageView::New(TEST_RESOURCE_DIR "/foo.svg");
2829     imageView.SetProperty(Actor::Property::SIZE, Vector2(200.f, 200.f));
2830     imageView.ResourceReadySignal().Connect(&ResourceReadySignal);
2831
2832     DALI_TEST_EQUALS(imageView.IsResourceReady(), false, TEST_LOCATION);
2833
2834     application.GetScene().Add(imageView);
2835
2836     application.SendNotification();
2837     application.Render(16);
2838
2839     DALI_TEST_EQUALS(gResourceReadySignalFired, true, TEST_LOCATION);
2840     DALI_TEST_EQUALS(imageView.IsResourceReady(), true, TEST_LOCATION);
2841     DALI_TEST_EQUALS(imageView.GetVisualResourceStatus(ImageView::Property::IMAGE), Visual::ResourceStatus::FAILED, TEST_LOCATION);
2842
2843     // Should be shown a broken image
2844     DALI_TEST_EQUALS(imageView.GetRendererCount(), 1u, TEST_LOCATION);
2845     DALI_TEST_EQUALS(textureTrace.FindMethod("BindTexture"), true, TEST_LOCATION);
2846   }
2847
2848   // Local svg file - invalid file path without size set
2849   {
2850     gResourceReadySignalFired = false;
2851     textureTrace.Reset();
2852
2853     ImageView imageView = ImageView::New(TEST_RESOURCE_DIR "/foo.svg");
2854     imageView.ResourceReadySignal().Connect(&ResourceReadySignal);
2855
2856     DALI_TEST_EQUALS(imageView.IsResourceReady(), false, TEST_LOCATION);
2857
2858     application.GetScene().Add(imageView);
2859
2860     application.SendNotification();
2861     application.Render(16);
2862
2863     DALI_TEST_EQUALS(gResourceReadySignalFired, true, TEST_LOCATION);
2864     DALI_TEST_EQUALS(imageView.IsResourceReady(), true, TEST_LOCATION);
2865     DALI_TEST_EQUALS(imageView.GetVisualResourceStatus(ImageView::Property::IMAGE), Visual::ResourceStatus::FAILED, TEST_LOCATION);
2866
2867     // Should be shown a broken image
2868     DALI_TEST_EQUALS(imageView.GetRendererCount(), 1u, TEST_LOCATION);
2869     DALI_TEST_EQUALS(textureTrace.FindMethod("BindTexture"), true, TEST_LOCATION);
2870   }
2871
2872   // Local svg file - invalid file
2873   {
2874     gResourceReadySignalFired = false;
2875     textureTrace.Reset();
2876
2877     ImageView imageView = ImageView::New(TEST_RESOURCE_DIR "/invalid.svg");
2878     imageView.SetProperty(Actor::Property::SIZE, Vector2(200.f, 200.f));
2879     imageView.ResourceReadySignal().Connect(&ResourceReadySignal);
2880
2881     DALI_TEST_EQUALS(imageView.IsResourceReady(), false, TEST_LOCATION);
2882
2883     application.GetScene().Add(imageView);
2884
2885     application.SendNotification();
2886     application.Render(16);
2887
2888     DALI_TEST_EQUALS(gResourceReadySignalFired, true, TEST_LOCATION);
2889     DALI_TEST_EQUALS(imageView.IsResourceReady(), true, TEST_LOCATION);
2890     DALI_TEST_EQUALS(imageView.GetVisualResourceStatus(ImageView::Property::IMAGE), Visual::ResourceStatus::FAILED, TEST_LOCATION);
2891
2892     // Should be shown a broken image
2893     DALI_TEST_EQUALS(imageView.GetRendererCount(), 1u, TEST_LOCATION);
2894     DALI_TEST_EQUALS(textureTrace.FindMethod("BindTexture"), true, TEST_LOCATION);
2895   }
2896
2897   // Remote svg file
2898   {
2899     gResourceReadySignalFired = false;
2900     textureTrace.Reset();
2901
2902     ImageView imageView = ImageView::New("https://bar.org/foobar.svg");
2903     imageView.SetProperty(Actor::Property::SIZE, Vector2(200.f, 200.f));
2904     imageView.ResourceReadySignal().Connect(&ResourceReadySignal);
2905
2906     DALI_TEST_EQUALS(imageView.IsResourceReady(), false, TEST_LOCATION);
2907
2908     application.GetScene().Add(imageView);
2909
2910     application.SendNotification();
2911
2912     // loading started, this waits for the loader thread
2913     DALI_TEST_EQUALS(Test::WaitForEventThreadTrigger(1), true, TEST_LOCATION);
2914
2915     application.SendNotification();
2916     application.Render(16);
2917
2918     DALI_TEST_EQUALS(gResourceReadySignalFired, true, TEST_LOCATION);
2919     DALI_TEST_EQUALS(imageView.IsResourceReady(), true, TEST_LOCATION);
2920     DALI_TEST_EQUALS(imageView.GetVisualResourceStatus(ImageView::Property::IMAGE), Visual::ResourceStatus::FAILED, TEST_LOCATION);
2921
2922     // Should be shown a broken image
2923     DALI_TEST_EQUALS(imageView.GetRendererCount(), 1u, TEST_LOCATION);
2924     DALI_TEST_EQUALS(textureTrace.FindMethod("BindTexture"), true, TEST_LOCATION);
2925   }
2926
2927   // Remote svg file without size set
2928   {
2929     gResourceReadySignalFired = false;
2930     textureTrace.Reset();
2931
2932     ImageView imageView = ImageView::New("https://bar.org/foobar.svg");
2933     imageView.ResourceReadySignal().Connect(&ResourceReadySignal);
2934
2935     DALI_TEST_EQUALS(imageView.IsResourceReady(), false, TEST_LOCATION);
2936
2937     application.GetScene().Add(imageView);
2938
2939     application.SendNotification();
2940
2941     // loading started, this waits for the loader thread
2942     DALI_TEST_EQUALS(Test::WaitForEventThreadTrigger(1), true, TEST_LOCATION);
2943
2944     application.SendNotification();
2945     application.Render(16);
2946
2947     DALI_TEST_EQUALS(gResourceReadySignalFired, true, TEST_LOCATION);
2948     DALI_TEST_EQUALS(imageView.IsResourceReady(), true, TEST_LOCATION);
2949     DALI_TEST_EQUALS(imageView.GetVisualResourceStatus(ImageView::Property::IMAGE), Visual::ResourceStatus::FAILED, TEST_LOCATION);
2950
2951     // Should be shown a broken image
2952     DALI_TEST_EQUALS(imageView.GetRendererCount(), 1u, TEST_LOCATION);
2953     DALI_TEST_EQUALS(textureTrace.FindMethod("BindTexture"), true, TEST_LOCATION);
2954   }
2955
2956   END_TEST;
2957 }
2958
2959 int UtcDaliImageViewSvgRasterizationFailure(void)
2960 {
2961   ToolkitTestApplication application;
2962
2963   gResourceReadySignalFired = false;
2964
2965   TestGlAbstraction& gl           = application.GetGlAbstraction();
2966   TraceCallStack&    textureTrace = gl.GetTextureTrace();
2967   textureTrace.Enable(true);
2968
2969   ImageView imageView = ImageView::New(TEST_RESOURCE_DIR "/invalid1.svg");
2970   imageView.SetProperty(Actor::Property::SIZE, Vector2(200.f, 200.f));
2971   imageView.ResourceReadySignal().Connect(&ResourceReadySignal);
2972
2973   DALI_TEST_EQUALS(imageView.IsResourceReady(), false, TEST_LOCATION);
2974
2975   application.GetScene().Add(imageView);
2976
2977   application.SendNotification();
2978
2979   // loading started, this waits for the loader thread
2980   DALI_TEST_EQUALS(Test::WaitForEventThreadTrigger(1), true, TEST_LOCATION);
2981
2982   application.SendNotification();
2983   application.Render(16);
2984
2985   DALI_TEST_EQUALS(gResourceReadySignalFired, true, TEST_LOCATION);
2986   DALI_TEST_EQUALS(imageView.IsResourceReady(), true, TEST_LOCATION);
2987   DALI_TEST_EQUALS(imageView.GetVisualResourceStatus(ImageView::Property::IMAGE), Visual::ResourceStatus::FAILED, TEST_LOCATION);
2988
2989   // Should be shown a broken image
2990   DALI_TEST_EQUALS(imageView.GetRendererCount(), 1u, TEST_LOCATION);
2991   DALI_TEST_EQUALS(textureTrace.FindMethod("BindTexture"), true, TEST_LOCATION);
2992
2993   END_TEST;
2994 }
2995
2996 int UtcDaliImageViewTVGLoading(void)
2997 {
2998   ToolkitTestApplication application;
2999
3000   tet_infoline("ImageView Testing TVG image loading");
3001
3002   {
3003     ImageView imageView = ImageView::New();
3004
3005     imageView.SetImage(TEST_RESOURCE_DIR "/test.tvg");
3006
3007     application.GetScene().Add(imageView);
3008     DALI_TEST_CHECK(imageView);
3009     Vector3 naturalSize = imageView.GetNaturalSize();
3010
3011     DALI_TEST_EQUALS(naturalSize.width, 100.0f, TEST_LOCATION);
3012     DALI_TEST_EQUALS(naturalSize.height, 100.0f, TEST_LOCATION);
3013   }
3014   END_TEST;
3015 }
3016
3017 int UtcDaliImageViewImageLoadFailure01(void)
3018 {
3019   ToolkitTestApplication application;
3020
3021   Toolkit::StyleManager styleManager = Toolkit::StyleManager::Get();
3022   DevelStyleManager::SetBrokenImageUrl(styleManager, DevelStyleManager::BrokenImageType::SMALL, TEST_BROKEN_IMAGE_S);
3023   DevelStyleManager::SetBrokenImageUrl(styleManager, DevelStyleManager::BrokenImageType::NORMAL, TEST_BROKEN_IMAGE_M);
3024   DevelStyleManager::SetBrokenImageUrl(styleManager, DevelStyleManager::BrokenImageType::LARGE, TEST_BROKEN_IMAGE_L);
3025
3026   std::string brokenUrl;
3027   brokenUrl = DevelStyleManager::GetBrokenImageUrl(styleManager, DevelStyleManager::BrokenImageType::SMALL);
3028   DALI_TEST_EQUALS(TEST_BROKEN_IMAGE_S, brokenUrl, TEST_LOCATION);
3029
3030   brokenUrl = DevelStyleManager::GetBrokenImageUrl(styleManager, DevelStyleManager::BrokenImageType::NORMAL);
3031   DALI_TEST_EQUALS(TEST_BROKEN_IMAGE_M, brokenUrl, TEST_LOCATION);
3032
3033   brokenUrl = DevelStyleManager::GetBrokenImageUrl(styleManager, DevelStyleManager::BrokenImageType::LARGE);
3034   DALI_TEST_EQUALS(TEST_BROKEN_IMAGE_L, brokenUrl, TEST_LOCATION);
3035
3036   ImageView imageView = ImageView::New("invalidUrl.png");
3037   imageView.SetProperty(Actor::Property::SIZE, Vector2(200.f, 200.f));
3038
3039   application.GetScene().Add(imageView);
3040   application.SendNotification();
3041   application.Render(16);
3042
3043   // loading started, this waits for the loader thread
3044   DALI_TEST_EQUALS(Test::WaitForEventThreadTrigger(1), true, TEST_LOCATION);
3045
3046   END_TEST;
3047 }
3048
3049 int UtcDaliImageViewImageLoadFailure02(void)
3050 {
3051   ToolkitTestApplication application;
3052
3053   Toolkit::StyleManager styleManager = Toolkit::StyleManager::Get();
3054   DevelStyleManager::SetBrokenImageUrl(styleManager, DevelStyleManager::BrokenImageType::SMALL, TEST_BROKEN_IMAGE_DEFAULT);
3055   DevelStyleManager::SetBrokenImageUrl(styleManager, DevelStyleManager::BrokenImageType::NORMAL, TEST_BROKEN_IMAGE_M);
3056   DevelStyleManager::SetBrokenImageUrl(styleManager, DevelStyleManager::BrokenImageType::LARGE, TEST_BROKEN_IMAGE_L);
3057
3058   std::string brokenUrl;
3059   brokenUrl = DevelStyleManager::GetBrokenImageUrl(styleManager, DevelStyleManager::BrokenImageType::SMALL);
3060   DALI_TEST_EQUALS(TEST_BROKEN_IMAGE_DEFAULT, brokenUrl, TEST_LOCATION);
3061
3062   brokenUrl = DevelStyleManager::GetBrokenImageUrl(styleManager, DevelStyleManager::BrokenImageType::NORMAL);
3063   DALI_TEST_EQUALS(TEST_BROKEN_IMAGE_M, brokenUrl, TEST_LOCATION);
3064
3065   brokenUrl = DevelStyleManager::GetBrokenImageUrl(styleManager, DevelStyleManager::BrokenImageType::LARGE);
3066   DALI_TEST_EQUALS(TEST_BROKEN_IMAGE_L, brokenUrl, TEST_LOCATION);
3067
3068   ImageView imageView = ImageView::New("invalidUrl.png");
3069   imageView.SetProperty(Actor::Property::SIZE, Vector2(30.f, 30.f));
3070   application.GetScene().Add(imageView);
3071   application.SendNotification();
3072   application.Render(16);
3073
3074   // loading started, this waits for the loader thread
3075   DALI_TEST_EQUALS(Test::WaitForEventThreadTrigger(1), true, TEST_LOCATION);
3076
3077   END_TEST;
3078 }
3079
3080 int UtcDaliImageViewImageLoadFailure03(void)
3081 {
3082   ToolkitTestApplication application;
3083
3084   Toolkit::StyleManager styleManager = Toolkit::StyleManager::Get();
3085   DevelStyleManager::SetBrokenImageUrl(styleManager, DevelStyleManager::BrokenImageType::SMALL, TEST_BROKEN_IMAGE_01);
3086   DevelStyleManager::SetBrokenImageUrl(styleManager, DevelStyleManager::BrokenImageType::NORMAL, TEST_BROKEN_IMAGE_02);
3087
3088   std::string brokenUrl;
3089   brokenUrl = DevelStyleManager::GetBrokenImageUrl(styleManager, DevelStyleManager::BrokenImageType::SMALL);
3090   DALI_TEST_EQUALS(TEST_BROKEN_IMAGE_01, brokenUrl, TEST_LOCATION);
3091
3092   brokenUrl = DevelStyleManager::GetBrokenImageUrl(styleManager, DevelStyleManager::BrokenImageType::NORMAL);
3093   DALI_TEST_EQUALS(TEST_BROKEN_IMAGE_02, brokenUrl, TEST_LOCATION);
3094
3095   ImageView imageView = ImageView::New("invalidUrl.png");
3096   imageView.SetProperty(Actor::Property::SIZE, Vector2(100.f, 100.f));
3097   application.GetScene().Add(imageView);
3098   application.SendNotification();
3099   application.Render(16);
3100
3101   // loading started, this waits for the loader thread
3102   DALI_TEST_EQUALS(Test::WaitForEventThreadTrigger(1), true, TEST_LOCATION);
3103
3104   END_TEST;
3105 }
3106
3107 int UtcDaliImageViewImageLoadFailure04(void)
3108 {
3109   ToolkitTestApplication application;
3110
3111   ImageView imageView = ImageView::New("invalidUrl.png");
3112   imageView.SetProperty(Actor::Property::SIZE, Vector2(100.f, 100.f));
3113   application.GetScene().Add(imageView);
3114   application.SendNotification();
3115   application.Render(16);
3116
3117   // loading started, this waits for the loader thread
3118   DALI_TEST_EQUALS(Test::WaitForEventThreadTrigger(1), true, TEST_LOCATION);
3119
3120   Toolkit::StyleManager styleManager = Toolkit::StyleManager::Get();
3121   DevelStyleManager::SetBrokenImageUrl(styleManager, DevelStyleManager::BrokenImageType::SMALL, TEST_BROKEN_IMAGE_S);
3122   DevelStyleManager::SetBrokenImageUrl(styleManager, DevelStyleManager::BrokenImageType::NORMAL, "invalidBroken.png");
3123   DevelStyleManager::SetBrokenImageUrl(styleManager, DevelStyleManager::BrokenImageType::LARGE, TEST_BROKEN_IMAGE_L);
3124
3125   ImageView imageView2 = ImageView::New("invalidUrl.png");
3126   imageView2.SetProperty(Actor::Property::SIZE, Vector2(100.f, 100.f));
3127   application.GetScene().Add(imageView2);
3128
3129   std::string brokenUrl;
3130   brokenUrl = DevelStyleManager::GetBrokenImageUrl(styleManager, DevelStyleManager::BrokenImageType::SMALL);
3131   DALI_TEST_EQUALS(TEST_BROKEN_IMAGE_S, brokenUrl, TEST_LOCATION);
3132
3133   brokenUrl = DevelStyleManager::GetBrokenImageUrl(styleManager, DevelStyleManager::BrokenImageType::LARGE);
3134   DALI_TEST_EQUALS(TEST_BROKEN_IMAGE_L, brokenUrl, TEST_LOCATION);
3135
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   DevelStyleManager::SetBrokenImageUrl(styleManager, DevelStyleManager::BrokenImageType::NORMAL, "invalidBroken.9.png");
3143
3144   ImageView imageView3 = ImageView::New("invalidUrl.png");
3145   imageView3.SetProperty(Actor::Property::SIZE, Vector2(100.f, 100.f));
3146   application.GetScene().Add(imageView3);
3147
3148   application.SendNotification();
3149   application.Render(16);
3150
3151   // loading started, this waits for the loader thread
3152   DALI_TEST_EQUALS(Test::WaitForEventThreadTrigger(1), true, TEST_LOCATION);
3153
3154   END_TEST;
3155 }
3156
3157 namespace
3158 {
3159 static int gResourceReadySignalCounter = 0;
3160
3161 void OnResourceReadySignal01(Control control)
3162 {
3163   gResourceReadySignalCounter++;
3164
3165   if(control.GetVisualResourceStatus(ImageView::Property::IMAGE) == Visual::ResourceStatus::READY)
3166   {
3167     if(gResourceReadySignalCounter == 1)
3168     {
3169       // Set image twice
3170       // It makes the first new visual be deleted immediately
3171       ImageView::DownCast(control).SetImage(gImage_34_RGBA);
3172       ImageView::DownCast(control).SetImage(gImage_34_RGBA);
3173     }
3174   }
3175   else if(control.GetVisualResourceStatus(ImageView::Property::IMAGE) == Visual::ResourceStatus::FAILED)
3176   {
3177     // Make the resource ready immediately
3178     control[ImageView::Property::IMAGE] = gImage_600_RGB;
3179   }
3180 }
3181
3182 void OnResourceReadySignal02(Control control)
3183 {
3184   if(++gResourceReadySignalCounter == 1)
3185   {
3186     // It makes the first new visual be deleted immediately
3187     // The first image will not be loaded.
3188     control[ImageView::Property::IMAGE] = Property::Map().Add(ImageVisual::Property::URL, gImage_600_RGB).Add(ImageVisual::Property::RELEASE_POLICY, ImageVisual::ReleasePolicy::NEVER);
3189     control[ImageView::Property::IMAGE] = TEST_IMAGE_1;
3190   }
3191 }
3192
3193 ImageView gImageView1;
3194 ImageView gImageView2;
3195 ImageView gImageView3;
3196 ImageView gImageView4;
3197
3198 void OnResourceReadySignal03(Control control)
3199 {
3200   if(gResourceReadySignalCounter == 0)
3201   {
3202     // Queue loading
3203     // 1. Use cached image, then LoadComplete will be called right after OnResourceReadySignal03.
3204     gImageView2[ImageView::Property::IMAGE] = gImage_34_RGBA;
3205
3206     // 2. Load a new image
3207     gImageView3[ImageView::Property::IMAGE] = TEST_IMAGE_1;
3208
3209     // 3. Use the new image again
3210     gImageView1[ImageView::Property::IMAGE] = TEST_IMAGE_1;
3211     gImageView1.ResourceReadySignal().Connect(&OnResourceReadySignal03);
3212   }
3213   else if(gResourceReadySignalCounter == 1)
3214   {
3215     // This is called from TextureManager::ProcessQueuedTextures().
3216     gImageView1.Unparent();
3217     gImageView1.Reset();
3218   }
3219   gResourceReadySignalCounter++;
3220 }
3221
3222 void OnSimpleResourceReadySignal(Control control)
3223 {
3224   // simply increate counter
3225   gResourceReadySignalCounter++;
3226 }
3227
3228 int gResourceReadySignal04ComesOrder = 0;
3229
3230 void OnResourceReadySignal04(Control control)
3231 {
3232   gResourceReadySignalCounter++;
3233   tet_printf("rc %d\n", gResourceReadySignalCounter);
3234   if(gResourceReadySignalCounter == 1)
3235   {
3236     auto scene = gImageView1.GetParent();
3237
3238     // Request load something
3239     // We hope this request result is return later than gImageView2.
3240     gImageView3 = ImageView::New(TEST_IMAGE_1);
3241     gImageView3.ResourceReadySignal().Connect(&OnResourceReadySignal04);
3242     scene.Add(gImageView3);
3243     gImageView4 = ImageView::New(TEST_IMAGE_2);
3244     gImageView4.ResourceReadySignal().Connect(&OnResourceReadySignal04);
3245     scene.Add(gImageView4);
3246
3247     if(control == gImageView1)
3248     {
3249       gResourceReadySignal04ComesOrder = 1;
3250     }
3251     else
3252     {
3253       gResourceReadySignal04ComesOrder = 2;
3254     }
3255   }
3256   if(gResourceReadySignalCounter == 2)
3257   {
3258     if(gResourceReadySignal04ComesOrder == 1 && control == gImageView2)
3259     {
3260       // Scene off first one.
3261       gImageView1.Unparent();
3262
3263       // Scene off second one.
3264       gImageView2.Unparent();
3265     }
3266     else if(gResourceReadySignal04ComesOrder == 2 && control == gImageView1)
3267     {
3268       // Scene off first one.
3269       gImageView2.Unparent();
3270
3271       // Scene off second one.
3272       gImageView1.Unparent();
3273     }
3274     else
3275     {
3276       // We can't check that this utc fail case. just pass always when we come here.
3277       gResourceReadySignal04ComesOrder = -1;
3278     }
3279
3280     // If we don't seperate index of FreeList area
3281     // and if we don't queue remove during obversing,
3282     // cache index become something invalid data.
3283     // In this case, some strange observer can be called.
3284     // For example, gImageView4.LoadComplete will be called.
3285   }
3286 }
3287
3288 } // namespace
3289
3290 int UtcDaliImageViewSetImageOnResourceReadySignal01(void)
3291 {
3292   tet_infoline("Test setting image from within signal handler.");
3293
3294   ToolkitTestApplication application;
3295
3296   gResourceReadySignalCounter = 0;
3297
3298   ImageView imageView = ImageView::New(gImage_34_RGBA);
3299   imageView.ResourceReadySignal().Connect(&OnResourceReadySignal01);
3300
3301   application.GetScene().Add(imageView);
3302
3303   DALI_TEST_EQUALS(Test::WaitForEventThreadTrigger(1), true, TEST_LOCATION);
3304
3305   application.SendNotification();
3306   application.Render();
3307
3308   DALI_TEST_EQUALS(gResourceReadySignalCounter, 2, TEST_LOCATION);
3309
3310   DALI_TEST_EQUALS(imageView.IsResourceReady(), true, TEST_LOCATION);
3311
3312   // Create a new ImageView to cache the image
3313   ImageView imageView1 = ImageView::New(gImage_600_RGB);
3314   application.GetScene().Add(imageView1);
3315
3316   DALI_TEST_EQUALS(Test::WaitForEventThreadTrigger(1), true, TEST_LOCATION);
3317
3318   application.SendNotification();
3319   application.Render();
3320
3321   // Reset count
3322   gResourceReadySignalCounter = 0;
3323
3324   imageView[ImageView::Property::IMAGE] = "invalid.jpg";
3325
3326   DALI_TEST_EQUALS(Test::WaitForEventThreadTrigger(1), true, TEST_LOCATION);
3327
3328   application.SendNotification();
3329   application.Render();
3330
3331   // Run idle callback
3332   application.RunIdles();
3333
3334   DALI_TEST_EQUALS(gResourceReadySignalCounter, 2, TEST_LOCATION);
3335
3336   DALI_TEST_EQUALS(imageView.IsResourceReady(), true, TEST_LOCATION);
3337
3338   END_TEST;
3339 }
3340
3341 int UtcDaliImageViewSetImageOnResourceReadySignal02(void)
3342 {
3343   tet_infoline("Test setting image from within signal handler.");
3344
3345   ToolkitTestApplication application;
3346
3347   gResourceReadySignalCounter = 0;
3348
3349   ImageView imageView = ImageView::New(gImage_34_RGBA);
3350   imageView.ResourceReadySignal().Connect(&OnResourceReadySignal02);
3351
3352   application.GetScene().Add(imageView);
3353
3354   DALI_TEST_EQUALS(Test::WaitForEventThreadTrigger(1), true, TEST_LOCATION);
3355
3356   application.SendNotification();
3357   application.Render();
3358
3359   // Wait for loading an image
3360   DALI_TEST_EQUALS(Test::WaitForEventThreadTrigger(1), true, TEST_LOCATION);
3361
3362   DALI_TEST_EQUALS(gResourceReadySignalCounter, 2, TEST_LOCATION);
3363
3364   DALI_TEST_EQUALS(imageView.IsResourceReady(), true, TEST_LOCATION);
3365
3366   END_TEST;
3367 }
3368
3369 int UtcDaliImageViewSetImageOnResourceReadySignal03(void)
3370 {
3371   tet_infoline("Test setting image from within signal handler.");
3372
3373   ToolkitTestApplication application;
3374
3375   gResourceReadySignalCounter = 0;
3376
3377   gImageView1 = ImageView::New(gImage_34_RGBA);
3378   application.GetScene().Add(gImageView1);
3379
3380   // Wait for loading
3381   DALI_TEST_EQUALS(Test::WaitForEventThreadTrigger(1), true, TEST_LOCATION);
3382
3383   gImageView2 = ImageView::New(gImage_600_RGB);
3384   gImageView2.ResourceReadySignal().Connect(&OnResourceReadySignal03);
3385   application.GetScene().Add(gImageView2);
3386
3387   gImageView3 = ImageView::New();
3388   application.GetScene().Add(gImageView3);
3389
3390   DALI_TEST_EQUALS(Test::WaitForEventThreadTrigger(2), true, TEST_LOCATION);
3391
3392   application.SendNotification();
3393   application.Render();
3394
3395   END_TEST;
3396 }
3397
3398 int UtcDaliImageViewOnResourceReadySignalWithBrokenAlphaMask01(void)
3399 {
3400   tet_infoline("Test signal handler when image / mask image is broken.");
3401
3402   ToolkitTestApplication application;
3403
3404   auto TestResourceReadyUrl = [&application](int eventTriggerCount, bool isSynchronous, const std::string& url, const std::string& mask, const char* location) {
3405     gResourceReadySignalCounter = 0;
3406
3407     Property::Map map;
3408     map[Toolkit::ImageVisual::Property::URL] = url;
3409     if(!mask.empty())
3410     {
3411       map[Toolkit::ImageVisual::Property::ALPHA_MASK_URL] = mask;
3412     }
3413     map[Toolkit::ImageVisual::Property::SYNCHRONOUS_LOADING] = isSynchronous;
3414
3415     ImageView imageView                            = ImageView::New();
3416     imageView[Toolkit::ImageView::Property::IMAGE] = map;
3417     imageView[Actor::Property::SIZE]               = Vector2(100.0f, 200.0f);
3418     imageView.ResourceReadySignal().Connect(&OnSimpleResourceReadySignal);
3419
3420     application.GetScene().Add(imageView);
3421     application.SendNotification();
3422     application.Render();
3423
3424     if(!isSynchronous)
3425     {
3426       // Wait for loading
3427       DALI_TEST_EQUALS(Test::WaitForEventThreadTrigger(eventTriggerCount), true, location);
3428     }
3429     tet_printf("test %s [sync:%d] signal fired\n", url.c_str(), isSynchronous ? 1 : 0);
3430     DALI_TEST_EQUALS(gResourceReadySignalCounter, 1, location);
3431
3432     imageView.Unparent();
3433   };
3434
3435   for(int synchronous = 0; synchronous <= 1; synchronous++)
3436   {
3437     tet_printf("Test normal case (sync:%d)\n", synchronous);
3438     TestResourceReadyUrl(1, synchronous, gImage_600_RGB, "", TEST_LOCATION);
3439     TestResourceReadyUrl(3, synchronous, gImage_600_RGB, gImage_34_RGBA, TEST_LOCATION); // 3 event trigger required : 2 image load + 1 apply mask
3440
3441     tet_printf("Test broken image case (sync:%d)\n", synchronous);
3442     TestResourceReadyUrl(1, synchronous, "invalid.jpg", "", TEST_LOCATION);
3443     TestResourceReadyUrl(2, synchronous, "invalid.jpg", gImage_34_RGBA, TEST_LOCATION);
3444
3445     tet_printf("Test broken mask image case (sync:%d)\n", synchronous);
3446     TestResourceReadyUrl(2, synchronous, gImage_600_RGB, "invalid.png", TEST_LOCATION);
3447
3448     tet_printf("Test broken both image, mask image case (sync:%d)\n", synchronous);
3449     TestResourceReadyUrl(2, synchronous, "invalid.jpg", "invalid.png", TEST_LOCATION);
3450   }
3451
3452   END_TEST;
3453 }
3454
3455 int UtcDaliImageViewOnResourceReadySignalWithBrokenAlphaMask02(void)
3456 {
3457   tet_infoline("Test signal handler when image try to use cached-and-broken mask image.");
3458
3459   ToolkitTestApplication application;
3460
3461   gResourceReadySignalCounter = 0;
3462
3463   auto TestBrokenMaskResourceReadyUrl = [&application](const std::string& url, const char* location) {
3464     Property::Map map;
3465     map[Toolkit::ImageVisual::Property::URL] = url;
3466     // Use invalid mask url
3467     map[Toolkit::ImageVisual::Property::ALPHA_MASK_URL] = "invalid.png";
3468
3469     ImageView imageView                            = ImageView::New();
3470     imageView[Toolkit::ImageView::Property::IMAGE] = map;
3471     imageView[Actor::Property::SIZE]               = Vector2(100.0f, 200.0f);
3472     imageView.ResourceReadySignal().Connect(&OnSimpleResourceReadySignal);
3473
3474     application.GetScene().Add(imageView);
3475     application.SendNotification();
3476     application.Render();
3477
3478     // Don't unparent imageView, for keep the cache.
3479   };
3480
3481   // Use more than 4 images (The number of LocalImageLoadThread)
3482   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};
3483
3484   int expectResourceReadySignalCounter = 0;
3485
3486   for(auto& url : testUrlList)
3487   {
3488     TestBrokenMaskResourceReadyUrl(url, TEST_LOCATION);
3489     expectResourceReadySignalCounter++;
3490   }
3491
3492   // Remain 1 signal due to we use #URL + 1 mask image.
3493   DALI_TEST_EQUALS(Test::WaitForEventThreadTrigger(expectResourceReadySignalCounter + 1), true, TEST_LOCATION);
3494
3495   DALI_TEST_EQUALS(gResourceReadySignalCounter, expectResourceReadySignalCounter, TEST_LOCATION);
3496
3497   END_TEST;
3498 }
3499
3500 int UtcDaliImageViewCheckVariousCaseSendOnResourceReadySignal(void)
3501 {
3502   tet_infoline("Test signal handler various case.");
3503
3504   ToolkitTestApplication application;
3505
3506   auto TestResourceReadyUrl = [&application](int eventTriggerCount, bool isSynchronous, bool loadSuccess, const std::string& url, const std::string& mask, const char* location) {
3507     gResourceReadySignalCounter = 0;
3508
3509     Property::Map map;
3510     map[Toolkit::ImageVisual::Property::URL] = url;
3511     if(!mask.empty())
3512     {
3513       map[Toolkit::ImageVisual::Property::ALPHA_MASK_URL] = mask;
3514     }
3515     map[Toolkit::ImageVisual::Property::SYNCHRONOUS_LOADING] = isSynchronous;
3516
3517     ImageView imageView                            = ImageView::New();
3518     imageView[Toolkit::ImageView::Property::IMAGE] = map;
3519     imageView[Actor::Property::SIZE]               = Vector2(100.0f, 200.0f);
3520     imageView.ResourceReadySignal().Connect(&OnSimpleResourceReadySignal);
3521
3522     application.GetScene().Add(imageView);
3523     application.SendNotification();
3524     application.Render();
3525
3526     // Wait for loading
3527     DALI_TEST_EQUALS(Test::WaitForEventThreadTrigger(eventTriggerCount), true, location);
3528
3529     tet_printf("test %s [sync:%d] signal fired\n", url.c_str(), isSynchronous ? 1 : 0);
3530     DALI_TEST_EQUALS(gResourceReadySignalCounter, 1, location);
3531     DALI_TEST_EQUALS(imageView.GetVisualResourceStatus(Toolkit::ImageView::Property::IMAGE), loadSuccess ? Toolkit::Visual::ResourceStatus::READY : Toolkit::Visual::ResourceStatus::FAILED, TEST_LOCATION);
3532
3533     imageView.Unparent();
3534   };
3535
3536   auto TestAuxiliaryResourceReadyUrl = [&application](bool isSynchronous, bool loadSuccess, const std::string& url, const std::string& auxiliaryUrl, const char* location) {
3537     gResourceReadySignalCounter = 0;
3538
3539     Property::Map map;
3540     map[Toolkit::ImageVisual::Property::URL]                        = url;
3541     map[Toolkit::DevelImageVisual::Property::AUXILIARY_IMAGE]       = auxiliaryUrl;
3542     map[Toolkit::DevelImageVisual::Property::AUXILIARY_IMAGE_ALPHA] = 0.5f;
3543     map[Toolkit::ImageVisual::Property::SYNCHRONOUS_LOADING]        = isSynchronous;
3544
3545     ImageView imageView = ImageView::New();
3546     imageView.SetProperty(Toolkit::ImageView::Property::IMAGE, map);
3547     imageView.SetProperty(Actor::Property::SIZE, Vector2(100.0f, 200.0f));
3548     imageView.ResourceReadySignal().Connect(&OnSimpleResourceReadySignal);
3549     application.GetScene().Add(imageView);
3550
3551     application.SendNotification();
3552     application.Render();
3553
3554     if(!isSynchronous)
3555     {
3556       // Wait for loading
3557       DALI_TEST_EQUALS(Test::WaitForEventThreadTrigger(2), true, location);
3558     }
3559
3560     tet_printf("test %s [sync:%d] signal fired\n", url.c_str(), isSynchronous ? 1 : 0);
3561     DALI_TEST_EQUALS(gResourceReadySignalCounter, 1, location);
3562     DALI_TEST_EQUALS(imageView.GetVisualResourceStatus(Toolkit::ImageView::Property::IMAGE), loadSuccess ? Toolkit::Visual::ResourceStatus::READY : Toolkit::Visual::ResourceStatus::FAILED, TEST_LOCATION);
3563
3564     imageView.Unparent();
3565   };
3566
3567   // Case 1 : asynchronous loading
3568   tet_printf("Test invalid single simple image Asynchronous\n");
3569
3570   // Test normal case
3571   TestResourceReadyUrl(1, 0, 1, gImage_600_RGB, "", TEST_LOCATION);
3572   TestResourceReadyUrl(1, 0, 1, TEST_SVG_FILE_NAME, "", TEST_LOCATION); // 1 rasterize
3573   TestResourceReadyUrl(1, 0, 1, TEST_BROKEN_IMAGE_L, "", TEST_LOCATION);
3574
3575   TestResourceReadyUrl(2, 0, 1, TEST_GIF_FILE_NAME, "", TEST_LOCATION);                   // 2 image loading - batch size
3576   TestResourceReadyUrl(1, 0, 1, TEST_ANIMATED_VECTOR_IMAGE_FILE_NAME, "", TEST_LOCATION); // 1 rasterize
3577
3578   TestResourceReadyUrl(3, 0, 1, gImage_600_RGB, gImage_34_RGBA, TEST_LOCATION); // 2 image loading + 1 applymask
3579
3580   TestAuxiliaryResourceReadyUrl(0, 1, TEST_BROKEN_IMAGE_L, gImage_34_RGBA, TEST_LOCATION);
3581
3582   // Test broken case
3583   TestResourceReadyUrl(1, 0, 0, "invalid.jpg", "", TEST_LOCATION);
3584   TestResourceReadyUrl(0, 0, 0, "invalid.svg", "", TEST_LOCATION); // 0 rasterize
3585   TestResourceReadyUrl(1, 0, 0, "invalid.9.png", "", TEST_LOCATION);
3586   TestResourceReadyUrl(1, 0, 0, "invalid.gif", "", TEST_LOCATION);  // 1 image loading
3587   TestResourceReadyUrl(0, 0, 0, "invalid.json", "", TEST_LOCATION); // 0 rasterize
3588
3589   TestResourceReadyUrl(2, 0, 0, "invalid.jpg", "invalid.png", TEST_LOCATION);  // 2 image loading
3590   TestResourceReadyUrl(2, 0, 1, gImage_600_RGB, "invalid.png", TEST_LOCATION); // 2 image loading
3591   TestResourceReadyUrl(2, 0, 0, "invalid.jpg", gImage_34_RGBA, TEST_LOCATION); // 2 image loading
3592
3593   TestAuxiliaryResourceReadyUrl(0, 0, "invalid.9.png", "invalid.png", TEST_LOCATION);
3594   TestAuxiliaryResourceReadyUrl(0, 1, TEST_BROKEN_IMAGE_L, "invalid.png", TEST_LOCATION);
3595   TestAuxiliaryResourceReadyUrl(0, 0, "invalid.9.png", gImage_34_RGBA, TEST_LOCATION);
3596
3597   // Case 2 : Synchronous loading
3598   tet_printf("Test invalid single simple image Synchronous\n");
3599
3600   // Test normal case
3601   TestResourceReadyUrl(0, 1, 1, gImage_600_RGB, "", TEST_LOCATION);
3602   TestResourceReadyUrl(0, 1, 1, TEST_SVG_FILE_NAME, "", TEST_LOCATION); // synchronous rasterize
3603   TestResourceReadyUrl(0, 1, 1, TEST_BROKEN_IMAGE_L, "", TEST_LOCATION);
3604
3605   TestResourceReadyUrl(1, 1, 1, TEST_GIF_FILE_NAME, "", TEST_LOCATION);                   // first frame image loading sync + second frame image loading async
3606   TestResourceReadyUrl(0, 1, 1, TEST_ANIMATED_VECTOR_IMAGE_FILE_NAME, "", TEST_LOCATION); // synchronous rasterize
3607
3608   TestResourceReadyUrl(0, 1, 1, gImage_600_RGB, gImage_34_RGBA, TEST_LOCATION);
3609
3610   TestAuxiliaryResourceReadyUrl(1, 1, TEST_BROKEN_IMAGE_L, gImage_34_RGBA, TEST_LOCATION);
3611
3612   // Test broken case
3613   TestResourceReadyUrl(0, 1, 0, "invalid.jpg", "", TEST_LOCATION);
3614   TestResourceReadyUrl(0, 1, 0, "invalid.svg", "", TEST_LOCATION); // 0 rasterize
3615   TestResourceReadyUrl(0, 1, 0, "invalid.9.png", "", TEST_LOCATION);
3616   TestResourceReadyUrl(0, 1, 0, "invalid.gif", "", TEST_LOCATION);
3617   TestResourceReadyUrl(0, 1, 0, "invalid.json", "", TEST_LOCATION); // 0 rasterize
3618
3619   TestResourceReadyUrl(0, 1, 0, "invalid.jpg", "invalid.png", TEST_LOCATION);
3620   TestResourceReadyUrl(0, 1, 1, gImage_600_RGB, "invalid.png", TEST_LOCATION);
3621   TestResourceReadyUrl(0, 1, 0, "invalid.jpg", gImage_34_RGBA, TEST_LOCATION);
3622
3623   TestAuxiliaryResourceReadyUrl(1, 0, "invalid.9.png", "invalid.png", TEST_LOCATION);
3624   TestAuxiliaryResourceReadyUrl(1, 1, TEST_BROKEN_IMAGE_L, "invalid.png", TEST_LOCATION);
3625   TestAuxiliaryResourceReadyUrl(1, 0, "invalid.9.png", gImage_34_RGBA, TEST_LOCATION);
3626
3627   END_TEST;
3628 }
3629
3630 int UtcDaliImageViewSetImageOnResourceReadySignal04(void)
3631 {
3632   tet_infoline("Test texturemanager's remove queue works well within signal handler.");
3633
3634   ToolkitTestApplication application;
3635
3636   gResourceReadySignalCounter      = 0;
3637   gResourceReadySignal04ComesOrder = 0;
3638
3639   gImageView1 = ImageView::New("invalid.jpg"); // request invalid image, to make loading failed fast.
3640   gImageView1.ResourceReadySignal().Connect(&OnResourceReadySignal04);
3641   application.GetScene().Add(gImageView1);
3642
3643   gImageView2 = ImageView::New("invalid.png"); // request invalid image, to make loading failed fast.
3644   gImageView2.ResourceReadySignal().Connect(&OnResourceReadySignal04);
3645   application.GetScene().Add(gImageView2);
3646
3647   application.SendNotification();
3648   application.Render();
3649
3650   tet_infoline("Try to load 2 invalid image");
3651
3652   DALI_TEST_EQUALS(Test::WaitForEventThreadTrigger(2), true, TEST_LOCATION);
3653   DALI_TEST_EQUALS(gResourceReadySignalCounter, 2, TEST_LOCATION);
3654
3655   tet_infoline("load done");
3656
3657   // We can test this UTC only if gImageView1 and gImageView2 loaded done.
3658   if(gResourceReadySignal04ComesOrder == -1)
3659   {
3660     tet_infoline("Bad news.. gImageView3 or gImageView4 loaded faster than others. just skip this UTC");
3661   }
3662   else
3663   {
3664     // gImageView3 and gImageView4 load must not be successed yet.
3665     DALI_TEST_EQUALS(gImageView3.GetRendererCount(), 0u, TEST_LOCATION);
3666     DALI_TEST_EQUALS(gImageView4.GetRendererCount(), 0u, TEST_LOCATION);
3667
3668     application.SendNotification();
3669     application.Render();
3670
3671     tet_infoline("Try to load 2 valid image");
3672
3673     DALI_TEST_EQUALS(Test::WaitForEventThreadTrigger(2), true, TEST_LOCATION);
3674     DALI_TEST_EQUALS(gResourceReadySignalCounter, 4, TEST_LOCATION);
3675
3676     tet_infoline("load done");
3677
3678     // gImageView3 and gImageView4 load must be successed now.
3679     DALI_TEST_EQUALS(gImageView3.GetRendererAt(0).GetTextures().GetTextureCount(), 1u, TEST_LOCATION);
3680     DALI_TEST_EQUALS(gImageView4.GetRendererAt(0).GetTextures().GetTextureCount(), 1u, TEST_LOCATION);
3681   }
3682
3683   END_TEST;
3684 }