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