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