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