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