6fb05ab4a50fc024aa3581862e371b60eb1f54d4
[platform/core/uifw/dali-toolkit.git] / automated-tests / src / dali-toolkit / utc-Dali-ImageView.cpp
1 /*
2  * Copyright (c) 2023 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 const char* TEST_INVALID_NPATCH_FILE_NAME_01 = "invalid1.9.png";
75
76 // resolution: 34*34, pixel format: RGBA8888
77 static const char* gImage_34_RGBA = TEST_RESOURCE_DIR "/icon-edit.png";
78 // resolution: 600*600, pixel format: RGB888
79 static const char* gImage_600_RGB = TEST_RESOURCE_DIR "/test-image-600.jpg";
80
81 // resolution: 50*50, frame count: 4, frame delay: 0.2 second for each frame
82 const char* TEST_GIF_FILE_NAME = TEST_RESOURCE_DIR "/anim.gif";
83
84 const char* TEST_SVG_FILE_NAME                   = TEST_RESOURCE_DIR "/svg1.svg";
85 const char* TEST_ANIMATED_VECTOR_IMAGE_FILE_NAME = TEST_RESOURCE_DIR "/insta_camera.json";
86 const char* TEST_WEBP_FILE_NAME                  = TEST_RESOURCE_DIR "/dali-logo.webp";
87
88 void TestUrl(ImageView imageView, const std::string url)
89 {
90   Property::Value value = imageView.GetProperty(imageView.GetPropertyIndex("image"));
91
92   std::string urlActual;
93   DALI_TEST_CHECK(value.Get(urlActual));
94   DALI_TEST_EQUALS(urlActual, url, TEST_LOCATION);
95 }
96
97 } // namespace
98
99 int UtcDaliImageViewNewP(void)
100 {
101   ToolkitTestApplication application;
102
103   ImageView imageView = ImageView::New();
104
105   DALI_TEST_CHECK(imageView);
106
107   END_TEST;
108 }
109
110 int UtcDaliImageViewNewUrlP(void)
111 {
112   ToolkitTestApplication application;
113
114   ImageView imageView = ImageView::New(TEST_IMAGE_FILE_NAME);
115   DALI_TEST_CHECK(imageView);
116
117   TestUrl(imageView, TEST_IMAGE_FILE_NAME);
118
119   END_TEST;
120 }
121
122 int UtcDaliImageViewConstructorP(void)
123 {
124   ToolkitTestApplication application;
125
126   ImageView imageView;
127
128   DALI_TEST_CHECK(!imageView);
129
130   END_TEST;
131 }
132
133 int UtcDaliImageViewCopyConstructorP(void)
134 {
135   ToolkitTestApplication application;
136
137   // Initialize an object, ref count == 1
138   ImageView imageView = ImageView::New();
139
140   ImageView copy(imageView);
141   DALI_TEST_CHECK(copy);
142
143   END_TEST;
144 }
145
146 int UtcDaliImageViewMoveConstructor(void)
147 {
148   ToolkitTestApplication application;
149
150   ImageView imageView = ImageView::New();
151   DALI_TEST_EQUALS(1, imageView.GetBaseObject().ReferenceCount(), TEST_LOCATION);
152   imageView.SetProperty(Actor::Property::SENSITIVE, false);
153   DALI_TEST_CHECK(false == imageView.GetProperty<bool>(Actor::Property::SENSITIVE));
154
155   ImageView moved = std::move(imageView);
156   DALI_TEST_CHECK(moved);
157   DALI_TEST_EQUALS(1, moved.GetBaseObject().ReferenceCount(), TEST_LOCATION);
158   DALI_TEST_CHECK(false == moved.GetProperty<bool>(Actor::Property::SENSITIVE));
159   DALI_TEST_CHECK(!imageView);
160
161   END_TEST;
162 }
163
164 int UtcDaliImageViewAssignmentOperatorP(void)
165 {
166   ToolkitTestApplication application;
167
168   ImageView imageView = ImageView::New();
169
170   ImageView copy(imageView);
171   DALI_TEST_CHECK(copy);
172   DALI_TEST_EQUALS(imageView, copy, TEST_LOCATION);
173
174   END_TEST;
175 }
176
177 int UtcDaliImageViewMoveAssignment(void)
178 {
179   ToolkitTestApplication application;
180
181   ImageView imageView = ImageView::New();
182   DALI_TEST_EQUALS(1, imageView.GetBaseObject().ReferenceCount(), TEST_LOCATION);
183   imageView.SetProperty(Actor::Property::SENSITIVE, false);
184   DALI_TEST_CHECK(false == imageView.GetProperty<bool>(Actor::Property::SENSITIVE));
185
186   ImageView moved;
187   moved = std::move(imageView);
188   DALI_TEST_CHECK(moved);
189   DALI_TEST_EQUALS(1, moved.GetBaseObject().ReferenceCount(), TEST_LOCATION);
190   DALI_TEST_CHECK(false == moved.GetProperty<bool>(Actor::Property::SENSITIVE));
191   DALI_TEST_CHECK(!imageView);
192
193   END_TEST;
194 }
195
196 int UtcDaliImageViewDownCastP(void)
197 {
198   ToolkitTestApplication application;
199
200   ImageView imageView = ImageView::New();
201
202   BaseHandle object(imageView);
203
204   ImageView imageView2 = ImageView::DownCast(object);
205   DALI_TEST_CHECK(imageView2);
206
207   ImageView imageView3 = DownCast<ImageView>(object);
208   DALI_TEST_CHECK(imageView3);
209
210   END_TEST;
211 }
212
213 int UtcDaliImageViewDownCastN(void)
214 {
215   ToolkitTestApplication application;
216
217   BaseHandle unInitializedObject;
218
219   ImageView imageView1 = ImageView::DownCast(unInitializedObject);
220   DALI_TEST_CHECK(!imageView1);
221
222   ImageView imageView2 = DownCast<ImageView>(unInitializedObject);
223   DALI_TEST_CHECK(!imageView2);
224
225   END_TEST;
226 }
227
228 int UtcDaliImageViewTypeRegistry(void)
229 {
230   ToolkitTestApplication application;
231
232   TypeRegistry typeRegistry = TypeRegistry::Get();
233   DALI_TEST_CHECK(typeRegistry);
234
235   TypeInfo typeInfo = typeRegistry.GetTypeInfo("ImageView");
236   DALI_TEST_CHECK(typeInfo);
237
238   BaseHandle handle = typeInfo.CreateInstance();
239   DALI_TEST_CHECK(handle);
240
241   ImageView imageView = ImageView::DownCast(handle);
242   DALI_TEST_CHECK(imageView);
243
244   END_TEST;
245 }
246
247 int UtcDaliImageViewSetGetProperty01(void)
248 {
249   ToolkitTestApplication application;
250
251   ImageView imageView = ImageView::New();
252
253   Property::Index idx = imageView.GetPropertyIndex("image");
254   DALI_TEST_EQUALS(idx, (Property::Index)ImageView::Property::IMAGE, TEST_LOCATION);
255
256   imageView.SetProperty(idx, TEST_IMAGE_FILE_NAME);
257   TestUrl(imageView, TEST_IMAGE_FILE_NAME);
258
259   END_TEST;
260 }
261
262 int UtcDaliImageViewPreMultipliedAlphaPng(void)
263 {
264   ToolkitTestApplication application;
265
266   // Set up trace debug
267   TestGlAbstraction& gl           = application.GetGlAbstraction();
268   TraceCallStack&    textureTrace = gl.GetTextureTrace();
269   textureTrace.Enable(true);
270
271   Property::Map imageMap;
272   imageMap[ImageVisual::Property::URL]            = gImage_34_RGBA;
273   imageMap[ImageVisual::Property::RELEASE_POLICY] = ImageVisual::ReleasePolicy::NEVER; // To keep the texture cache
274
275   ImageView imageView1 = ImageView::New();
276   imageView1.SetProperty(ImageView::Property::IMAGE, imageMap);
277
278   application.GetScene().Add(imageView1);
279
280   Property::Value value = imageView1.GetProperty(ImageView::Property::PRE_MULTIPLIED_ALPHA);
281   bool            enable;
282   DALI_TEST_CHECK(value.Get(enable));
283   DALI_TEST_CHECK(enable); // Default value is true
284
285   // loading started, this waits for the loader thread for max 30 seconds
286   DALI_TEST_EQUALS(Test::WaitForEventThreadTrigger(1), true, TEST_LOCATION);
287
288   application.SendNotification();
289   application.Render();
290
291   value = imageView1.GetProperty(ImageView::Property::PRE_MULTIPLIED_ALPHA);
292   DALI_TEST_CHECK(value.Get(enable));
293   DALI_TEST_CHECK(enable); // Keep true
294
295   // conventional alpha blending
296   Renderer renderer1 = imageView1.GetRendererAt(0);
297   value              = renderer1.GetProperty(Renderer::Property::BLEND_PRE_MULTIPLIED_ALPHA);
298   DALI_TEST_CHECK(value.Get(enable));
299   DALI_TEST_CHECK(enable);
300
301   int srcFactorRgb    = renderer1.GetProperty<int>(Renderer::Property::BLEND_FACTOR_SRC_RGB);
302   int destFactorRgb   = renderer1.GetProperty<int>(Renderer::Property::BLEND_FACTOR_DEST_RGB);
303   int srcFactorAlpha  = renderer1.GetProperty<int>(Renderer::Property::BLEND_FACTOR_SRC_ALPHA);
304   int destFactorAlpha = renderer1.GetProperty<int>(Renderer::Property::BLEND_FACTOR_DEST_ALPHA);
305   DALI_TEST_CHECK(srcFactorRgb == BlendFactor::ONE);
306   DALI_TEST_CHECK(destFactorRgb == BlendFactor::ONE_MINUS_SRC_ALPHA);
307   DALI_TEST_CHECK(srcFactorAlpha == BlendFactor::ONE);
308   DALI_TEST_CHECK(destFactorAlpha == BlendFactor::ONE_MINUS_SRC_ALPHA);
309
310   DALI_TEST_EQUALS(textureTrace.FindMethod("GenTextures"), true, TEST_LOCATION); // A new texture should be generated.
311   textureTrace.Reset();
312
313   // Disable pre-multiplied alpha blending
314   imageView1.SetProperty(ImageView::Property::PRE_MULTIPLIED_ALPHA, false);
315
316   // Reload the image
317   Property::Map attributes;
318   DevelControl::DoAction(imageView1, ImageView::Property::IMAGE, DevelImageVisual::Action::RELOAD, attributes);
319
320   // loading started, this waits for the loader thread for max 30 seconds
321   DALI_TEST_EQUALS(Test::WaitForEventThreadTrigger(1), true, TEST_LOCATION);
322
323   application.SendNotification();
324   application.Render();
325
326   value = imageView1.GetProperty(ImageView::Property::PRE_MULTIPLIED_ALPHA);
327   DALI_TEST_CHECK(value.Get(enable));
328   DALI_TEST_CHECK(!enable);
329
330   // conventional alpha blending
331   value = renderer1.GetProperty(Renderer::Property::BLEND_PRE_MULTIPLIED_ALPHA);
332   DALI_TEST_CHECK(value.Get(enable));
333   DALI_TEST_CHECK(!enable);
334
335   srcFactorRgb    = renderer1.GetProperty<int>(Renderer::Property::BLEND_FACTOR_SRC_RGB);
336   destFactorRgb   = renderer1.GetProperty<int>(Renderer::Property::BLEND_FACTOR_DEST_RGB);
337   srcFactorAlpha  = renderer1.GetProperty<int>(Renderer::Property::BLEND_FACTOR_SRC_ALPHA);
338   destFactorAlpha = renderer1.GetProperty<int>(Renderer::Property::BLEND_FACTOR_DEST_ALPHA);
339   DALI_TEST_CHECK(srcFactorRgb == BlendFactor::SRC_ALPHA);
340   DALI_TEST_CHECK(destFactorRgb == BlendFactor::ONE_MINUS_SRC_ALPHA);
341   DALI_TEST_CHECK(srcFactorAlpha == BlendFactor::ONE);
342   DALI_TEST_CHECK(destFactorAlpha == BlendFactor::ONE_MINUS_SRC_ALPHA);
343
344   DALI_TEST_EQUALS(textureTrace.FindMethod("GenTextures"), true, TEST_LOCATION); // A new texture should be generated.
345   textureTrace.Reset();
346
347   // Make a new ImageView using the same image
348   ImageView imageView2 = ImageView::New();
349   imageView2.SetProperty(ImageView::Property::IMAGE, imageMap);
350
351   application.GetScene().Add(imageView2);
352
353   application.SendNotification();
354   application.Render();
355
356   Renderer renderer2 = imageView2.GetRendererAt(0);
357   value              = renderer2.GetProperty(Renderer::Property::BLEND_PRE_MULTIPLIED_ALPHA);
358   DALI_TEST_CHECK(value.Get(enable));
359   DALI_TEST_CHECK(enable);
360
361   srcFactorRgb    = renderer2.GetProperty<int>(Renderer::Property::BLEND_FACTOR_SRC_RGB);
362   destFactorRgb   = renderer2.GetProperty<int>(Renderer::Property::BLEND_FACTOR_DEST_RGB);
363   srcFactorAlpha  = renderer2.GetProperty<int>(Renderer::Property::BLEND_FACTOR_SRC_ALPHA);
364   destFactorAlpha = renderer2.GetProperty<int>(Renderer::Property::BLEND_FACTOR_DEST_ALPHA);
365   DALI_TEST_CHECK(srcFactorRgb == BlendFactor::ONE);
366   DALI_TEST_CHECK(destFactorRgb == BlendFactor::ONE_MINUS_SRC_ALPHA);
367   DALI_TEST_CHECK(srcFactorAlpha == BlendFactor::ONE);
368   DALI_TEST_CHECK(destFactorAlpha == BlendFactor::ONE_MINUS_SRC_ALPHA);
369
370   DALI_TEST_EQUALS(textureTrace.FindMethod("GenTextures"), false, TEST_LOCATION); // The cached texture should be used.
371
372   END_TEST;
373 }
374
375 int UtcDaliImageViewPreMultipliedAlphaJpg(void)
376 {
377   ToolkitTestApplication application;
378
379   // Set up trace debug
380   TestGlAbstraction& gl           = application.GetGlAbstraction();
381   TraceCallStack&    textureTrace = gl.GetTextureTrace();
382   textureTrace.Enable(true);
383
384   Property::Map imageMap;
385   imageMap[ImageVisual::Property::URL]            = gImage_600_RGB;
386   imageMap[ImageVisual::Property::RELEASE_POLICY] = ImageVisual::ReleasePolicy::NEVER; // To keep the texture cache
387
388   ImageView imageView1 = ImageView::New();
389   imageView1.SetProperty(ImageView::Property::IMAGE, imageMap);
390
391   application.GetScene().Add(imageView1);
392
393   Property::Value value = imageView1.GetProperty(ImageView::Property::PRE_MULTIPLIED_ALPHA);
394   bool            enable;
395   DALI_TEST_CHECK(value.Get(enable));
396   DALI_TEST_CHECK(enable); // Default value is true
397
398   // loading started, this waits for the loader thread for max 30 seconds
399   DALI_TEST_EQUALS(Test::WaitForEventThreadTrigger(1), true, TEST_LOCATION);
400
401   application.SendNotification();
402   application.Render();
403
404   value = imageView1.GetProperty(ImageView::Property::PRE_MULTIPLIED_ALPHA);
405   DALI_TEST_CHECK(value.Get(enable));
406   DALI_TEST_CHECK(!enable); // Should be false after loading
407
408   // conventional alpha blending
409   Renderer renderer1 = imageView1.GetRendererAt(0);
410   value              = renderer1.GetProperty(Renderer::Property::BLEND_PRE_MULTIPLIED_ALPHA);
411   DALI_TEST_CHECK(value.Get(enable));
412   DALI_TEST_CHECK(!enable);
413
414   int srcFactorRgb    = renderer1.GetProperty<int>(Renderer::Property::BLEND_FACTOR_SRC_RGB);
415   int destFactorRgb   = renderer1.GetProperty<int>(Renderer::Property::BLEND_FACTOR_DEST_RGB);
416   int srcFactorAlpha  = renderer1.GetProperty<int>(Renderer::Property::BLEND_FACTOR_SRC_ALPHA);
417   int destFactorAlpha = renderer1.GetProperty<int>(Renderer::Property::BLEND_FACTOR_DEST_ALPHA);
418   DALI_TEST_CHECK(srcFactorRgb == BlendFactor::SRC_ALPHA);
419   DALI_TEST_CHECK(destFactorRgb == BlendFactor::ONE_MINUS_SRC_ALPHA);
420   DALI_TEST_CHECK(srcFactorAlpha == BlendFactor::ONE);
421   DALI_TEST_CHECK(destFactorAlpha == BlendFactor::ONE_MINUS_SRC_ALPHA);
422
423   DALI_TEST_EQUALS(textureTrace.FindMethod("GenTextures"), true, TEST_LOCATION); // A new texture should be generated.
424   textureTrace.Reset();
425
426   ImageView imageView2 = ImageView::New();
427   imageView2.SetProperty(ImageView::Property::IMAGE, imageMap);
428
429   // Disable pre-multiplied alpha blending
430   imageView2.SetProperty(ImageView::Property::PRE_MULTIPLIED_ALPHA, false);
431
432   application.GetScene().Add(imageView2);
433
434   application.SendNotification();
435   application.Render();
436
437   value = imageView2.GetProperty(ImageView::Property::PRE_MULTIPLIED_ALPHA);
438   DALI_TEST_CHECK(value.Get(enable));
439   DALI_TEST_CHECK(!enable);
440
441   // conventional alpha blending
442   Renderer renderer2 = imageView2.GetRendererAt(0);
443   value              = renderer2.GetProperty(Renderer::Property::BLEND_PRE_MULTIPLIED_ALPHA);
444   DALI_TEST_CHECK(value.Get(enable));
445   DALI_TEST_CHECK(!enable);
446
447   srcFactorRgb    = renderer2.GetProperty<int>(Renderer::Property::BLEND_FACTOR_SRC_RGB);
448   destFactorRgb   = renderer2.GetProperty<int>(Renderer::Property::BLEND_FACTOR_DEST_RGB);
449   srcFactorAlpha  = renderer2.GetProperty<int>(Renderer::Property::BLEND_FACTOR_SRC_ALPHA);
450   destFactorAlpha = renderer2.GetProperty<int>(Renderer::Property::BLEND_FACTOR_DEST_ALPHA);
451   DALI_TEST_CHECK(srcFactorRgb == BlendFactor::SRC_ALPHA);
452   DALI_TEST_CHECK(destFactorRgb == BlendFactor::ONE_MINUS_SRC_ALPHA);
453   DALI_TEST_CHECK(srcFactorAlpha == BlendFactor::ONE);
454   DALI_TEST_CHECK(destFactorAlpha == BlendFactor::ONE_MINUS_SRC_ALPHA);
455
456   DALI_TEST_EQUALS(textureTrace.FindMethod("GenTextures"), false, TEST_LOCATION); // The cached texture should be used.
457
458   END_TEST;
459 }
460
461 int UtcDaliImageViewPixelArea(void)
462 {
463   // Test pixel area property
464   ToolkitTestApplication application;
465
466   static std::vector<UniformData> customUniforms =
467     {
468       UniformData("pixelArea", Property::Type::VECTOR4),
469     };
470
471   TestGraphicsController& graphics = application.GetGraphicsController();
472   graphics.AddCustomUniforms(customUniforms);
473
474   // Gif image, use AnimatedImageVisual internally
475   // Atlasing is applied to pack multiple frames, use custom wrap mode
476   ImageView     gifView = ImageView::New();
477   const Vector4 pixelAreaVisual(0.f, 0.f, 2.f, 2.f);
478   gifView.SetProperty(ImageView::Property::IMAGE,
479                       Property::Map().Add(ImageVisual::Property::URL, TEST_GIF_FILE_NAME).Add(ImageVisual::Property::PIXEL_AREA, pixelAreaVisual));
480
481   // Add to stage
482   Integration::Scene stage = application.GetScene();
483   stage.Add(gifView);
484
485   // loading started
486   application.SendNotification();
487   application.Render(16);
488
489   DALI_TEST_EQUALS(Test::WaitForEventThreadTrigger(2), true, TEST_LOCATION);
490
491   application.SendNotification();
492   application.Render();
493   DALI_TEST_CHECK(gifView.GetRendererCount() == 1u);
494
495   const Vector4 fullTextureRect(0.f, 0.f, 1.f, 1.f);
496   // test that the pixel area value defined in the visual property map is registered on renderer
497   Renderer        renderer       = gifView.GetRendererAt(0);
498   Property::Value pixelAreaValue = renderer.GetProperty(renderer.GetPropertyIndex("pixelArea"));
499   DALI_TEST_EQUALS(pixelAreaValue.Get<Vector4>(), pixelAreaVisual, TEST_LOCATION);
500
501   // test that the shader has the default pixel area value registered.
502   Shader shader  = renderer.GetShader();
503   pixelAreaValue = shader.GetProperty(shader.GetPropertyIndex("pixelArea"));
504   DALI_TEST_EQUALS(pixelAreaValue.Get<Vector4>(), fullTextureRect, TEST_LOCATION);
505
506   // test that the uniform uses the pixelArea property on the renderer.
507   TestGlAbstraction& gl = application.GetGlAbstraction();
508   Vector4            pixelAreaUniform;
509   DALI_TEST_CHECK(gl.GetUniformValue<Vector4>("pixelArea", pixelAreaUniform));
510   DALI_TEST_EQUALS(pixelAreaVisual, pixelAreaUniform, Math::MACHINE_EPSILON_100, TEST_LOCATION);
511
512   // set the pixelArea property on the control
513   const Vector4 pixelAreaControl(-1.f, -1.f, 3.f, 3.f);
514   gifView.SetProperty(ImageView::Property::PIXEL_AREA, pixelAreaControl);
515   application.SendNotification();
516   application.Render(16);
517
518   // check the pixelArea property on the control
519   pixelAreaValue = gifView.GetProperty(gifView.GetPropertyIndex("pixelArea"));
520   DALI_TEST_EQUALS(pixelAreaValue.Get<Vector4>(), pixelAreaControl, TEST_LOCATION);
521   // test that the uniform uses the pixelArea property on the control.
522   DALI_TEST_CHECK(gl.GetUniformValue<Vector4>("pixelArea", pixelAreaUniform));
523   DALI_TEST_EQUALS(pixelAreaControl, pixelAreaUniform, Math::MACHINE_EPSILON_100, TEST_LOCATION);
524
525   END_TEST;
526 }
527
528 int UtcDaliImageViewAsyncLoadingWithoutAltasing(void)
529 {
530   ToolkitTestApplication     application;
531   TestGlAbstraction&         gl          = application.GetGlAbstraction();
532   const std::vector<GLuint>& textures    = gl.GetBoundTextures();
533   size_t                     numTextures = textures.size();
534
535   // Async loading, no atlasing for big size image
536   ImageView imageView = ImageView::New(gImage_600_RGB);
537
538   // By default, Aysnc loading is used
539   application.GetScene().Add(imageView);
540   imageView.SetProperty(Actor::Property::SIZE, Vector2(100, 100));
541   imageView.SetProperty(Actor::Property::PARENT_ORIGIN, ParentOrigin::CENTER);
542
543   DALI_TEST_EQUALS(Test::WaitForEventThreadTrigger(1), true, TEST_LOCATION);
544
545   application.SendNotification();
546   application.Render(16);
547   application.SendNotification();
548
549   const std::vector<GLuint>& textures2 = gl.GetBoundTextures();
550   DALI_TEST_GREATER(textures2.size(), numTextures, TEST_LOCATION);
551
552   END_TEST;
553 }
554
555 int UtcDaliImageViewAsyncLoadingWithAtlasing(void)
556 {
557   ToolkitTestApplication application;
558
559   //Async loading, automatic atlasing for small size image
560   TraceCallStack& callStack = application.GetGlAbstraction().GetTextureTrace();
561   callStack.Reset();
562   callStack.Enable(true);
563
564   Property::Map imageMap;
565
566   imageMap[ImageVisual::Property::URL]            = gImage_34_RGBA;
567   imageMap[ImageVisual::Property::DESIRED_HEIGHT] = 34;
568   imageMap[ImageVisual::Property::DESIRED_WIDTH]  = 34;
569   imageMap[ImageVisual::Property::ATLASING]       = true;
570
571   ImageView imageView = ImageView::New();
572   imageView.SetProperty(ImageView::Property::IMAGE, imageMap);
573   imageView.SetProperty(Toolkit::Control::Property::PADDING, Extents(10u, 10u, 10u, 10u));
574
575   // By default, Aysnc loading is used
576   // loading is not started if the actor is offScene
577
578   application.GetScene().Add(imageView);
579   application.SendNotification();
580   application.Render(16);
581   application.Render(16);
582   application.SendNotification();
583
584   imageView.SetProperty(Dali::Actor::Property::LAYOUT_DIRECTION, Dali::LayoutDirection::RIGHT_TO_LEFT);
585   application.SendNotification();
586   application.Render(16);
587   application.Render(16);
588   application.SendNotification();
589
590   // loading started, this waits for the loader thread for max 30 seconds
591   DALI_TEST_EQUALS(Test::WaitForEventThreadTrigger(1), true, TEST_LOCATION);
592
593   application.SendNotification();
594   application.Render(16);
595
596   callStack.Enable(false);
597
598   TraceCallStack::NamedParams params;
599   params["width"] << 34;
600   params["height"] << 34;
601   DALI_TEST_EQUALS(callStack.FindMethodAndParams("TexSubImage2D", params), true, TEST_LOCATION);
602
603   END_TEST;
604 }
605
606 int UtcDaliImageViewAsyncLoadingWithAtlasing02(void)
607 {
608   ToolkitTestApplication application;
609
610   //Async loading, automatic atlasing for small size image
611   TraceCallStack& callStack = application.GetGlAbstraction().GetTextureTrace();
612   callStack.Reset();
613   callStack.Enable(true);
614
615   Property::Map asyncLoadingMap;
616   asyncLoadingMap["url"]                = gImage_34_RGBA;
617   asyncLoadingMap["desiredHeight"]      = 34;
618   asyncLoadingMap["desiredWidth"]       = 34;
619   asyncLoadingMap["synchronousLoading"] = false;
620   asyncLoadingMap["atlasing"]           = true;
621
622   ImageView imageView = ImageView::New();
623   imageView.SetProperty(ImageView::Property::IMAGE, asyncLoadingMap);
624
625   application.GetScene().Add(imageView);
626   application.SendNotification();
627   application.Render(16);
628   application.Render(16);
629   application.SendNotification();
630
631   // loading started, this waits for the loader thread for max 30 seconds
632   DALI_TEST_EQUALS(Test::WaitForEventThreadTrigger(1), true, TEST_LOCATION);
633
634   application.SendNotification();
635   application.Render(16);
636
637   callStack.Enable(false);
638
639   TraceCallStack::NamedParams params;
640   params["width"] << 34;
641   params["height"] << 34;
642   DALI_TEST_EQUALS(callStack.FindMethodAndParams("TexSubImage2D", params), true, TEST_LOCATION);
643
644   END_TEST;
645 }
646
647 int UtcDaliImageViewSyncLoading(void)
648 {
649   ToolkitTestApplication application;
650
651   tet_infoline("ImageView Testing sync loading and size using index key property map");
652
653   Property::Map syncLoadingMap;
654   syncLoadingMap[ImageVisual::Property::SYNCHRONOUS_LOADING] = true;
655   syncLoadingMap[ImageVisual::Property::ATLASING]            = true;
656
657   // Sync loading, no atlasing for big size image
658   {
659     ImageView imageView = ImageView::New();
660
661     // Sync loading is used
662     syncLoadingMap[ImageVisual::Property::URL] = gImage_600_RGB;
663     imageView.SetProperty(ImageView::Property::IMAGE, syncLoadingMap);
664   }
665
666   // Sync loading, automatic atlasing for small size image
667   {
668     TraceCallStack& callStack = application.GetGlAbstraction().GetTextureTrace();
669     callStack.Reset();
670     callStack.Enable(true);
671
672     ImageView imageView = ImageView::New();
673
674     // Sync loading is used
675     syncLoadingMap[ImageVisual::Property::URL]            = gImage_34_RGBA;
676     syncLoadingMap[ImageVisual::Property::DESIRED_HEIGHT] = 34;
677     syncLoadingMap[ImageVisual::Property::DESIRED_WIDTH]  = 34;
678     imageView.SetProperty(ImageView::Property::IMAGE, syncLoadingMap);
679
680     application.GetScene().Add(imageView);
681     application.SendNotification();
682     application.Render(16);
683
684     TraceCallStack::NamedParams params;
685     params["width"] << 34;
686     params["height"] << 34;
687     DALI_TEST_EQUALS(callStack.FindMethodAndParams("TexSubImage2D", params),
688                      true,
689                      TEST_LOCATION);
690   }
691   END_TEST;
692 }
693
694 int UtcDaliImageViewSyncLoading02(void)
695 {
696   ToolkitTestApplication application;
697
698   tet_infoline("ImageView Testing sync loading and size using string key property map");
699
700   // Sync loading, automatic atlasing for small size image
701   {
702     TraceCallStack& callStack = application.GetGlAbstraction().GetTextureTrace();
703     callStack.Reset();
704     callStack.Enable(true);
705
706     ImageView imageView = ImageView::New();
707
708     // Sync loading is used
709     Property::Map syncLoadingMap;
710     syncLoadingMap["url"]                = gImage_34_RGBA;
711     syncLoadingMap["desiredHeight"]      = 34;
712     syncLoadingMap["desiredWidth"]       = 34;
713     syncLoadingMap["synchronousLoading"] = true;
714     syncLoadingMap["atlasing"]           = true;
715     imageView.SetProperty(ImageView::Property::IMAGE, syncLoadingMap);
716
717     application.GetScene().Add(imageView);
718     application.SendNotification();
719     application.Render(16);
720
721     TraceCallStack::NamedParams params;
722     params["width"] << 34;
723     params["height"] << 34;
724     DALI_TEST_EQUALS(callStack.FindMethodAndParams("TexSubImage2D", params),
725                      true,
726                      TEST_LOCATION);
727   }
728   END_TEST;
729 }
730
731 int UtcDaliImageViewAsyncLoadingEncodedBuffer(void)
732 {
733   ToolkitTestApplication     application;
734   TestGlAbstraction&         gl          = application.GetGlAbstraction();
735   const std::vector<GLuint>& textures    = gl.GetBoundTextures();
736   size_t                     numTextures = textures.size();
737
738   // Get encoded raw-buffer image and generate url
739   EncodedImageBuffer buffer = ConvertFileToEncodedImageBuffer(gImage_600_RGB);
740   ImageUrl           url    = Toolkit::Image::GenerateUrl(buffer);
741
742   // Async loading, no atlasing for big size image
743   ImageView imageView = ImageView::New(url.GetUrl());
744
745   // By default, Aysnc loading is used
746   application.GetScene().Add(imageView);
747   imageView.SetProperty(Actor::Property::SIZE, Vector2(100, 100));
748   imageView.SetProperty(Actor::Property::PARENT_ORIGIN, ParentOrigin::CENTER);
749
750   DALI_TEST_EQUALS(Test::WaitForEventThreadTrigger(1), true, TEST_LOCATION);
751
752   application.SendNotification();
753   application.Render(16);
754   application.SendNotification();
755
756   const std::vector<GLuint>& textures2 = gl.GetBoundTextures();
757   DALI_TEST_GREATER(textures2.size(), numTextures, TEST_LOCATION);
758
759   END_TEST;
760 }
761
762 int UtcDaliImageViewAsyncLoadingEncodedBufferWithAtlasing(void)
763 {
764   ToolkitTestApplication application;
765
766   // Get encoded raw-buffer image and generate url
767   EncodedImageBuffer buffer = ConvertFileToEncodedImageBuffer(gImage_600_RGB);
768   ImageUrl           url    = Toolkit::Image::GenerateUrl(buffer);
769   ImageUrl           url2   = Toolkit::Image::GenerateUrl(buffer);
770
771   // Generate url is not equal to url2
772   // NOTE : This behavior may changed when ImageUrl compare operator changed.
773   DALI_TEST_CHECK(url != url2);
774   // Generate url's string is equal to url2's string
775   DALI_TEST_CHECK(url.GetUrl() == url2.GetUrl());
776
777   EncodedImageBuffer buffer2 = ConvertFileToEncodedImageBuffer(gImage_600_RGB);
778   url2                       = Toolkit::Image::GenerateUrl(buffer2);
779
780   // Check whethere two url are not equal
781   DALI_TEST_CHECK(url.GetUrl() != url2.GetUrl());
782
783   // Async loading, automatic atlasing for small size image
784   TraceCallStack& callStack = application.GetGlAbstraction().GetTextureTrace();
785   callStack.Reset();
786   callStack.Enable(true);
787
788   Property::Map imageMap;
789
790   imageMap[ImageVisual::Property::URL]            = url.GetUrl();
791   imageMap[ImageVisual::Property::DESIRED_HEIGHT] = 600;
792   imageMap[ImageVisual::Property::DESIRED_WIDTH]  = 600;
793   imageMap[ImageVisual::Property::ATLASING]       = true;
794
795   // No atlasing with big image
796   ImageView imageView_bigdesired = ImageView::New();
797   imageView_bigdesired.SetProperty(ImageView::Property::IMAGE, imageMap);
798   imageView_bigdesired.SetProperty(Toolkit::Control::Property::PADDING, Extents(10u, 10u, 10u, 10u));
799
800   imageMap[ImageVisual::Property::DESIRED_HEIGHT] = 0;
801   imageMap[ImageVisual::Property::DESIRED_WIDTH]  = 0;
802
803   // No atlasing with zero desired size
804   ImageView imageView_nodesired = ImageView::New();
805   imageView_nodesired.SetProperty(ImageView::Property::IMAGE, imageMap);
806   imageView_nodesired.SetProperty(Toolkit::Control::Property::PADDING, Extents(10u, 10u, 10u, 10u));
807
808   imageMap[ImageVisual::Property::DESIRED_HEIGHT] = 34;
809   imageMap[ImageVisual::Property::DESIRED_WIDTH]  = 34;
810
811   ImageView imageView = ImageView::New();
812   imageView.SetProperty(ImageView::Property::IMAGE, imageMap);
813   imageView.SetProperty(Toolkit::Control::Property::PADDING, Extents(10u, 10u, 10u, 10u));
814
815   // By default, Aysnc loading is used
816   // loading is not started if the actor is offScene
817   application.GetScene().Add(imageView);
818   application.GetScene().Add(imageView_bigdesired);
819   application.GetScene().Add(imageView_nodesired);
820   application.SendNotification();
821   application.Render(16);
822
823   // loading started, this waits for the loader thread for max 30 seconds
824   DALI_TEST_EQUALS(Test::WaitForEventThreadTrigger(1), true, TEST_LOCATION);
825
826   application.Render(16);
827   application.SendNotification();
828
829   // Change url to url2
830   imageMap[ImageVisual::Property::URL] = url2.GetUrl();
831   imageView.SetProperty(ImageView::Property::IMAGE, imageMap);
832
833   imageView.SetProperty(Dali::Actor::Property::LAYOUT_DIRECTION, Dali::LayoutDirection::RIGHT_TO_LEFT);
834   application.SendNotification();
835   application.Render(16);
836   application.Render(16);
837   application.SendNotification();
838
839   // loading started, this waits for the loader thread for max 30 seconds
840   DALI_TEST_EQUALS(Test::WaitForEventThreadTrigger(1), true, TEST_LOCATION);
841
842   application.SendNotification();
843   application.Render(16);
844
845   callStack.Enable(false);
846
847   TraceCallStack::NamedParams params;
848   params["width"] << 34;
849   params["height"] << 34;
850   DALI_TEST_EQUALS(callStack.FindMethodAndParams("TexSubImage2D", params), true, TEST_LOCATION);
851
852   END_TEST;
853 }
854
855 int UtcDaliImageViewSyncLoadingEncodedBuffer(void)
856 {
857   ToolkitTestApplication application;
858
859   tet_infoline("ImageView Testing sync loading from EncodedImageBuffer");
860
861   // Get encoded raw-buffer image and generate url
862   EncodedImageBuffer buffer = ConvertFileToEncodedImageBuffer(gImage_34_RGBA);
863   ImageUrl           url    = Toolkit::Image::GenerateUrl(buffer);
864
865   // Sync loading, automatic atlasing for small size image
866   {
867     TraceCallStack& callStack = application.GetGlAbstraction().GetTextureTrace();
868     callStack.Reset();
869     callStack.Enable(true);
870
871     ImageView imageView = ImageView::New();
872
873     // Sync loading is used
874     Property::Map syncLoadingMap;
875     syncLoadingMap["url"]                = url.GetUrl();
876     syncLoadingMap["alphaMaskUrl"]       = gImage_34_RGBA;
877     syncLoadingMap["desiredHeight"]      = 34;
878     syncLoadingMap["desiredWidth"]       = 34;
879     syncLoadingMap["synchronousLoading"] = true;
880     syncLoadingMap["atlasing"]           = true;
881     imageView.SetProperty(ImageView::Property::IMAGE, syncLoadingMap);
882
883     application.GetScene().Add(imageView);
884     application.SendNotification();
885     application.Render(16);
886
887     TraceCallStack::NamedParams params;
888     params["width"] << 34;
889     params["height"] << 34;
890     DALI_TEST_EQUALS(callStack.FindMethodAndParams("TexSubImage2D", params),
891                      true,
892                      TEST_LOCATION);
893   }
894
895   END_TEST;
896 }
897
898 int UtcDaliImageViewAddedTexture(void)
899 {
900   ToolkitTestApplication application;
901
902   tet_infoline("ImageView Testing image view with texture provided manager url");
903
904   ImageView imageView = ImageView::New();
905
906   // empty texture is ok, though pointless from app point of view
907   TextureSet  empty;
908   std::string url = TextureManager::AddTexture(empty);
909   DALI_TEST_CHECK(url.size() > 0u);
910
911   Property::Map propertyMap;
912   propertyMap[ImageVisual::Property::URL] = url;
913   imageView.SetProperty(ImageView::Property::IMAGE, propertyMap);
914
915   application.GetScene().Add(imageView);
916   application.SendNotification();
917   application.Render();
918
919   END_TEST;
920 }
921
922 int UtcDaliImageViewSizeWithBackground(void)
923 {
924   ToolkitTestApplication application;
925
926   int       width     = 100;
927   int       height    = 200;
928   ImageView imageView = ImageView::New();
929
930   imageView.SetProperty(Control::Property::BACKGROUND,
931                         {
932                           {Toolkit::Visual::Property::TYPE, Toolkit::Visual::IMAGE},
933                           {Toolkit::ImageVisual::Property::URL, TEST_RESOURCE_DIR "/gallery-small-1.jpg"},
934                           {ImageVisual::Property::DESIRED_WIDTH, width},
935                           {ImageVisual::Property::DESIRED_HEIGHT, height},
936                         });
937
938   application.GetScene().Add(imageView);
939   application.SendNotification();
940   application.Render();
941
942   DALI_TEST_EQUALS(imageView.GetCurrentProperty<Vector3>(Actor::Property::SIZE).width, (float)width, TEST_LOCATION);
943   DALI_TEST_EQUALS(imageView.GetCurrentProperty<Vector3>(Actor::Property::SIZE).height, (float)height, TEST_LOCATION);
944
945   END_TEST;
946 }
947
948 int UtcDaliImageViewSizeWithBackgroundAndImage(void)
949 {
950   ToolkitTestApplication application;
951
952   int widthBackground  = 100;
953   int heightBackground = 200;
954   int width            = 600;
955   int height           = 600;
956
957   ImageView imageView = ImageView::New();
958
959   imageView.SetProperty(Control::Property::BACKGROUND,
960                         {
961                           {Toolkit::Visual::Property::TYPE, Toolkit::Visual::IMAGE},
962                           {Toolkit::ImageVisual::Property::URL, TEST_RESOURCE_DIR "/gallery-small-1.jpg"},
963                           {ImageVisual::Property::DESIRED_WIDTH, widthBackground},
964                           {ImageVisual::Property::DESIRED_HEIGHT, heightBackground},
965                         });
966
967   imageView.SetImage(gImage_600_RGB); // 1 to 1 ratio, 600x600 pixels
968
969   application.GetScene().Add(imageView);
970   application.SendNotification();
971   application.Render();
972
973   DALI_TEST_EQUALS(imageView.GetCurrentProperty<Vector3>(Actor::Property::SIZE).width, (float)width, TEST_LOCATION);
974   DALI_TEST_EQUALS(imageView.GetCurrentProperty<Vector3>(Actor::Property::SIZE).height, (float)height, TEST_LOCATION);
975
976   END_TEST;
977 }
978
979 int UtcDaliImageViewHeightForWidthBackground(void)
980 {
981   ToolkitTestApplication application;
982
983   int widthBackground  = 100;
984   int heightBackground = 200;
985
986   ImageView imageView = ImageView::New();
987
988   imageView.SetProperty(Control::Property::BACKGROUND,
989                         {{Toolkit::Visual::Property::TYPE, Toolkit::Visual::IMAGE},
990                          {Toolkit::ImageVisual::Property::URL, TEST_RESOURCE_DIR "/gallery-small-1.jpg"},
991                          {ImageVisual::Property::DESIRED_WIDTH, widthBackground},
992                          {ImageVisual::Property::DESIRED_HEIGHT, heightBackground}});
993
994   application.GetScene().Add(imageView);
995   application.SendNotification();
996   application.Render();
997
998   Control control = Control::DownCast(imageView);
999   DALI_TEST_CHECK(control);
1000   DALI_TEST_EQUALS(imageView.GetHeightForWidth(123.f), control.GetHeightForWidth(123.f), TEST_LOCATION);
1001   DALI_TEST_EQUALS(imageView.GetWidthForHeight(321.f), control.GetWidthForHeight(321.f), TEST_LOCATION);
1002
1003   END_TEST;
1004 }
1005
1006 int UtcDaliImageViewHeightForWidthBackgroundAndImage(void)
1007 {
1008   ToolkitTestApplication application;
1009
1010   int widthBackground  = 100;
1011   int heightBackground = 200;
1012   int width            = 300;
1013   int height           = 300;
1014
1015   ImageView imageView = ImageView::New();
1016
1017   imageView.SetProperty(Control::Property::BACKGROUND,
1018                         {{Toolkit::Visual::Property::TYPE, Toolkit::Visual::IMAGE},
1019                          {Toolkit::ImageVisual::Property::URL, TEST_RESOURCE_DIR "/gallery-small-1.jpg"},
1020                          {ImageVisual::Property::DESIRED_WIDTH, widthBackground},
1021                          {ImageVisual::Property::DESIRED_HEIGHT, heightBackground}}); // 1 to 2 ratio
1022
1023   imageView.SetImage(gImage_600_RGB); // 1 to 1 ratio
1024
1025   application.GetScene().Add(imageView);
1026   application.SendNotification();
1027   application.Render();
1028
1029   DALI_TEST_EQUALS(imageView.GetHeightForWidth(width), (float)height, TEST_LOCATION);
1030   DALI_TEST_EQUALS(imageView.GetWidthForHeight(height), (float)width, TEST_LOCATION);
1031
1032   END_TEST;
1033 }
1034
1035 int UtcDaliImageViewSetImageUrl(void)
1036 {
1037   ToolkitTestApplication application;
1038
1039   ImageView imageView = ImageView::New();
1040   imageView.SetImage(TEST_IMAGE_FILE_NAME);
1041   TestUrl(imageView, TEST_IMAGE_FILE_NAME);
1042
1043   imageView.SetImage(TEST_IMAGE_FILE_NAME2);
1044   TestUrl(imageView, TEST_IMAGE_FILE_NAME2);
1045
1046   END_TEST;
1047 }
1048
1049 bool    gResourceReadySignalFired = false;
1050 Vector3 gNaturalSize;
1051
1052 void ResourceReadySignal(Control control)
1053 {
1054   gResourceReadySignalFired = true;
1055 }
1056
1057 int UtcDaliImageViewCheckResourceReady(void)
1058 {
1059   ToolkitTestApplication application;
1060
1061   gResourceReadySignalFired = false;
1062
1063   // Check ImageView with background and main image, to ensure both visuals are marked as loaded
1064   ImageView imageView = ImageView::New(TEST_GIF_FILE_NAME);
1065
1066   imageView.SetProperty(Control::Property::BACKGROUND,
1067                         {{Toolkit::Visual::Property::TYPE, Toolkit::Visual::IMAGE},
1068                          {Toolkit::ImageVisual::Property::URL, TEST_RESOURCE_DIR "/gallery-small-1.jpg"},
1069                          {ImageVisual::Property::DESIRED_WIDTH, 100},
1070                          {ImageVisual::Property::DESIRED_HEIGHT, 200}});
1071
1072   DALI_TEST_EQUALS(imageView.IsResourceReady(), false, TEST_LOCATION);
1073
1074   imageView.ResourceReadySignal().Connect(&ResourceReadySignal);
1075
1076   application.GetScene().Add(imageView);
1077
1078   // loading started, this waits for the loader thread
1079   DALI_TEST_EQUALS(Test::WaitForEventThreadTrigger(1), true, TEST_LOCATION);
1080
1081   application.SendNotification();
1082   application.Render(16);
1083
1084   DALI_TEST_EQUALS(Test::WaitForEventThreadTrigger(2), true, TEST_LOCATION);
1085
1086   application.SendNotification();
1087   application.Render();
1088
1089   DALI_TEST_EQUALS(imageView.IsResourceReady(), true, TEST_LOCATION);
1090
1091   DALI_TEST_EQUALS(gResourceReadySignalFired, true, TEST_LOCATION);
1092
1093   END_TEST;
1094 }
1095
1096 int UtcDaliImageViewSetImageTypeChangesP(void)
1097 {
1098   ToolkitTestApplication application;
1099
1100   ImageView                   imageView   = ImageView::New();
1101   Toolkit::Internal::Control& controlImpl = Toolkit::Internal::GetImplementation(imageView);
1102
1103   application.GetScene().Add(imageView);
1104
1105   std::string           url;
1106   Property::Map         map;
1107   Toolkit::Visual::Base visual;
1108
1109   Property::Value value = imageView.GetProperty(imageView.GetPropertyIndex("image"));
1110   visual                = DevelControl::GetVisual(controlImpl, ImageView::Property::IMAGE);
1111
1112   application.SendNotification();
1113   application.Render(16);
1114
1115   DALI_TEST_CHECK(!value.Get(url)); // Value should be empty
1116   value.Get(map);
1117   DALI_TEST_CHECK(map.Empty()); // Value should be empty
1118   DALI_TEST_CHECK(!visual);     // Visual should be invalid
1119
1120   // Set a URL
1121   imageView.SetImage("TEST_URL");
1122
1123   application.SendNotification();
1124   application.Render(16);
1125
1126   value  = imageView.GetProperty(imageView.GetPropertyIndex("image"));
1127   visual = DevelControl::GetVisual(controlImpl, ImageView::Property::IMAGE);
1128
1129   DALI_TEST_CHECK(value.Get(url));  // Value should NOT be empty
1130   DALI_TEST_CHECK(!value.Get(map)); // Value should be empty
1131   DALI_TEST_CHECK(visual);          // Visual should be valid
1132
1133   // Set an empty URL
1134   imageView.SetImage("");
1135
1136   application.SendNotification();
1137   application.Render(16);
1138
1139   value  = imageView.GetProperty(imageView.GetPropertyIndex("image"));
1140   visual = DevelControl::GetVisual(controlImpl, ImageView::Property::IMAGE);
1141
1142   DALI_TEST_CHECK(!value.Get(url)); // Value should be empty
1143   value.Get(map);
1144   DALI_TEST_CHECK(map.Empty()); // Value should be empty
1145   DALI_TEST_CHECK(!visual);     // Visual should be invalid
1146
1147   // Set a URL in property map
1148   Property::Map propertyMap;
1149   propertyMap[ImageVisual::Property::URL] = TEST_IMAGE_FILE_NAME;
1150   imageView.SetProperty(ImageView::Property::IMAGE, propertyMap);
1151
1152   application.SendNotification();
1153   application.Render(16);
1154
1155   value  = imageView.GetProperty(imageView.GetPropertyIndex("image"));
1156   visual = DevelControl::GetVisual(controlImpl, ImageView::Property::IMAGE);
1157
1158   DALI_TEST_CHECK(!value.Get(url)); // Value should be empty
1159   DALI_TEST_CHECK(value.Get(map));  // Value should NOT be empty
1160   DALI_TEST_CHECK(visual);          // Visual should be valid
1161
1162   // Set a URL in property map again
1163   propertyMap[ImageVisual::Property::URL] = gImage_34_RGBA;
1164   imageView.SetProperty(ImageView::Property::IMAGE, propertyMap);
1165
1166   application.SendNotification();
1167   application.Render(16);
1168
1169   value  = imageView.GetProperty(imageView.GetPropertyIndex("image"));
1170   visual = DevelControl::GetVisual(controlImpl, ImageView::Property::IMAGE);
1171
1172   DALI_TEST_CHECK(!value.Get(url)); // Value should be empty
1173   DALI_TEST_CHECK(value.Get(map));  // Value should NOT be empty
1174   DALI_TEST_CHECK(visual);          // Visual should be valid
1175
1176   // Set an empty URL in property map
1177   propertyMap[ImageVisual::Property::URL] = std::string();
1178   imageView.SetProperty(ImageView::Property::IMAGE, propertyMap);
1179
1180   application.SendNotification();
1181   application.Render(16);
1182
1183   value  = imageView.GetProperty(imageView.GetPropertyIndex("image"));
1184   visual = DevelControl::GetVisual(controlImpl, ImageView::Property::IMAGE);
1185
1186   DALI_TEST_CHECK(!value.Get(url)); // Value should be empty
1187   DALI_TEST_CHECK(value.Get(map));  // Value should NOT be empty
1188   DALI_TEST_CHECK(!visual);         // Visual should be invalid
1189
1190   // Set a URL in property map again
1191   propertyMap[ImageVisual::Property::URL] = gImage_34_RGBA;
1192   imageView.SetProperty(ImageView::Property::IMAGE, propertyMap);
1193
1194   application.SendNotification();
1195   application.Render(16);
1196
1197   value  = imageView.GetProperty(imageView.GetPropertyIndex("image"));
1198   visual = DevelControl::GetVisual(controlImpl, ImageView::Property::IMAGE);
1199
1200   DALI_TEST_CHECK(!value.Get(url)); // Value should be empty
1201   DALI_TEST_CHECK(value.Get(map));  // Value should NOT be empty
1202   DALI_TEST_CHECK(visual);          // Visual should be valid
1203
1204   // Set an empty property map
1205   propertyMap.Clear();
1206   imageView.SetProperty(ImageView::Property::IMAGE, propertyMap);
1207
1208   application.SendNotification();
1209   application.Render(16);
1210
1211   value  = imageView.GetProperty(imageView.GetPropertyIndex("image"));
1212   visual = DevelControl::GetVisual(controlImpl, ImageView::Property::IMAGE);
1213
1214   DALI_TEST_CHECK(!value.Get(url)); // Value should be empty
1215   DALI_TEST_CHECK(value.Get(map));  // Value should NOT be empty
1216   DALI_TEST_CHECK(map.Empty());     // But PropertyMap should be empty
1217   DALI_TEST_CHECK(!visual);         // Visual should be invalid
1218
1219   END_TEST;
1220 }
1221
1222 int UtcDaliImageViewResourceUrlP(void)
1223 {
1224   ToolkitTestApplication application;
1225
1226   ImageView imageView = ImageView::New();
1227   DALI_TEST_CHECK(imageView.GetProperty(ImageView::Property::IMAGE).Get<std::string>().empty());
1228
1229   imageView.SetProperty(ImageView::Property::IMAGE, "TestString");
1230   DALI_TEST_EQUALS(imageView.GetProperty(ImageView::Property::IMAGE).Get<std::string>(), "TestString", TEST_LOCATION);
1231
1232   END_TEST;
1233 }
1234
1235 int UtcDaliImageViewReplaceImage(void)
1236 {
1237   ToolkitTestApplication application;
1238
1239   gResourceReadySignalFired = false;
1240
1241   // Check ImageView with background and main image, to ensure both visuals are marked as loaded
1242   ImageView imageView = ImageView::New(TEST_IMAGE_1);
1243
1244   DALI_TEST_EQUALS(imageView.IsResourceReady(), false, TEST_LOCATION);
1245
1246   imageView.ResourceReadySignal().Connect(&ResourceReadySignal);
1247
1248   application.GetScene().Add(imageView);
1249
1250   application.SendNotification();
1251   application.Render(16);
1252
1253   // loading started, this waits for the loader thread for max 30 seconds
1254   DALI_TEST_EQUALS(Test::WaitForEventThreadTrigger(1), true, TEST_LOCATION);
1255
1256   DALI_TEST_EQUALS(imageView.GetRendererCount(), 1u, TEST_LOCATION);
1257
1258   DALI_TEST_EQUALS(gResourceReadySignalFired, true, TEST_LOCATION);
1259
1260   gResourceReadySignalFired = false;
1261
1262   imageView.SetImage(TEST_IMAGE_2);
1263
1264   application.SendNotification();
1265   application.Render(16);
1266
1267   // loading started, this waits for the loader thread for max 30 seconds
1268   DALI_TEST_EQUALS(Test::WaitForEventThreadTrigger(1), true, TEST_LOCATION);
1269
1270   DALI_TEST_EQUALS(imageView.GetRendererCount(), 1u, TEST_LOCATION);
1271
1272   DALI_TEST_EQUALS(imageView.IsResourceReady(), true, TEST_LOCATION);
1273
1274   DALI_TEST_EQUALS(gResourceReadySignalFired, true, TEST_LOCATION);
1275
1276   END_TEST;
1277 }
1278
1279 int UtcDaliImageViewReloadAlphaMaskImage(void)
1280 {
1281   ToolkitTestApplication application;
1282
1283   gResourceReadySignalFired = false;
1284
1285   ImageView     dummy     = ImageView::New();
1286   ImageView     imageView = ImageView::New();
1287   Property::Map propertyMap;
1288
1289   // To keep alpha mask cached, scene on some dummy image.
1290   // Note : If we don't cache alpha mask image, the reference count of mask image become zero.
1291   // In this case, we might need to wait mask image loading, which is not neccesary & can be changed behavior.
1292   propertyMap[ImageVisual::Property::URL]            = gImage_600_RGB;
1293   propertyMap[ImageVisual::Property::ALPHA_MASK_URL] = TEST_BROKEN_IMAGE_DEFAULT;
1294   dummy.SetProperty(ImageView::Property::IMAGE, propertyMap);
1295
1296   application.GetScene().Add(dummy);
1297
1298   application.SendNotification();
1299   application.Render(16);
1300
1301   DALI_TEST_EQUALS(Test::WaitForEventThreadTrigger(3), true, TEST_LOCATION);
1302
1303   application.SendNotification();
1304   application.Render(16);
1305
1306   propertyMap.Clear();
1307   propertyMap[ImageVisual::Property::URL]            = gImage_34_RGBA;
1308   propertyMap[ImageVisual::Property::ALPHA_MASK_URL] = TEST_BROKEN_IMAGE_DEFAULT;
1309   imageView.SetProperty(ImageView::Property::IMAGE, propertyMap);
1310
1311   DALI_TEST_EQUALS(imageView.IsResourceReady(), false, TEST_LOCATION);
1312
1313   imageView.ResourceReadySignal().Connect(&ResourceReadySignal);
1314
1315   application.GetScene().Add(imageView);
1316
1317   application.SendNotification();
1318   application.Render(16);
1319
1320   // Load image and use cached mask. Now we try to apply masking.
1321   DALI_TEST_EQUALS(Test::WaitForEventThreadTrigger(1), true, TEST_LOCATION);
1322
1323   DALI_TEST_EQUALS(gResourceReadySignalFired, false, TEST_LOCATION);
1324
1325   // Cancel apply masking.
1326   imageView.Unparent();
1327
1328   application.SendNotification();
1329   application.Render(16);
1330
1331   // Reload same image again.
1332   application.GetScene().Add(imageView);
1333
1334   application.SendNotification();
1335   application.Render(16);
1336
1337   // Finish apply masking.
1338   DALI_TEST_EQUALS(Test::WaitForEventThreadTrigger(1), true, TEST_LOCATION);
1339
1340   DALI_TEST_EQUALS(imageView.GetRendererCount(), 1u, TEST_LOCATION);
1341   DALI_TEST_EQUALS(imageView.IsResourceReady(), true, TEST_LOCATION);
1342   DALI_TEST_EQUALS(gResourceReadySignalFired, true, TEST_LOCATION);
1343
1344   END_TEST;
1345 }
1346
1347 void OnRelayoutOverride(Size size)
1348 {
1349   gNaturalSize = size; // Size Relayout is using
1350 }
1351
1352 int UtcDaliImageViewReplaceImageAndGetNaturalSize(void)
1353 {
1354   ToolkitTestApplication application;
1355
1356   // Check ImageView with background and main image, to ensure both visuals are marked as loaded
1357   ImageView imageView = ImageView::New(TEST_IMAGE_1);
1358   imageView.SetResizePolicy(ResizePolicy::USE_NATURAL_SIZE, Dimension::ALL_DIMENSIONS);
1359
1360   DummyControl        dummyControl = DummyControl::New(true);
1361   Impl::DummyControl& dummyImpl    = static_cast<Impl::DummyControl&>(dummyControl.GetImplementation());
1362   dummyControl.SetResizePolicy(ResizePolicy::FIT_TO_CHILDREN, Dimension::ALL_DIMENSIONS);
1363
1364   dummyControl.Add(imageView);
1365   dummyImpl.SetRelayoutCallback(&OnRelayoutOverride);
1366   application.GetScene().Add(dummyControl);
1367
1368   application.SendNotification();
1369   application.Render();
1370
1371   // loading started, this waits for the loader thread for max 30 seconds
1372   DALI_TEST_EQUALS(Test::WaitForEventThreadTrigger(1), true, TEST_LOCATION);
1373
1374   DALI_TEST_EQUALS(gNaturalSize.width, 1024.0f, TEST_LOCATION);
1375   DALI_TEST_EQUALS(gNaturalSize.height, 1024.0f, TEST_LOCATION);
1376
1377   gNaturalSize = Vector3::ZERO;
1378
1379   imageView.SetImage(gImage_600_RGB);
1380
1381   // Waiting for resourceReady so SendNotifcation not called here.
1382
1383   // loading started, this waits for the loader thread for max 30 seconds
1384   DALI_TEST_EQUALS(Test::WaitForEventThreadTrigger(1), true, TEST_LOCATION);
1385
1386   // Trigger a potential relayout
1387   application.SendNotification();
1388   application.Render();
1389
1390   DALI_TEST_EQUALS(gNaturalSize.width, 600.0f, TEST_LOCATION);
1391   DALI_TEST_EQUALS(gNaturalSize.height, 600.0f, TEST_LOCATION);
1392
1393   END_TEST;
1394 }
1395
1396 int UtcDaliImageViewResourceReadySignalWithImmediateLoad(void)
1397 {
1398   tet_infoline("Test Setting Image with IMMEDIATE load and receving ResourceReadySignal before staged.");
1399
1400   ToolkitTestApplication application;
1401
1402   gResourceReadySignalFired = false;
1403
1404   Property::Map imageMap;
1405
1406   imageMap[ImageVisual::Property::URL]         = gImage_34_RGBA;
1407   imageMap[ImageVisual::Property::LOAD_POLICY] = ImageVisual::LoadPolicy::IMMEDIATE;
1408
1409   tet_infoline("Creating ImageView without URL so image does not start loading");
1410   ImageView imageView = ImageView::New();
1411   tet_infoline("Connect to image loaded signal before setting image");
1412   imageView.ResourceReadySignal().Connect(&ResourceReadySignal);
1413   tet_infoline("Setting Image with IMMEDIATE load, signal already connected so will be triggered.");
1414   imageView.SetProperty(ImageView::Property::IMAGE, imageMap);
1415
1416   // loading started, this waits for the loader thread
1417   DALI_TEST_EQUALS(Test::WaitForEventThreadTrigger(1), true, TEST_LOCATION);
1418
1419   application.SendNotification();
1420   application.Render(16);
1421
1422   DALI_TEST_EQUALS(gResourceReadySignalFired, true, TEST_LOCATION);
1423
1424   END_TEST;
1425 }
1426
1427 int UtcDaliImageViewResourceReadySignalWithReusedImage(void)
1428 {
1429   tet_infoline("Test Setting Image that was already loaded by another ImageView and still getting ResourceReadySignal.");
1430
1431   ToolkitTestApplication application;
1432
1433   gResourceReadySignalFired = false;
1434
1435   Property::Map imageMap;
1436
1437   imageMap[ImageVisual::Property::URL]         = gImage_34_RGBA;
1438   imageMap[ImageVisual::Property::LOAD_POLICY] = ImageVisual::LoadPolicy::IMMEDIATE;
1439
1440   ImageView imageView = ImageView::New();
1441   imageView.ResourceReadySignal().Connect(&ResourceReadySignal);
1442   imageView.SetProperty(ImageView::Property::IMAGE, imageMap);
1443
1444   // loading started, this waits for the loader thread
1445   DALI_TEST_EQUALS(Test::WaitForEventThreadTrigger(1), true, TEST_LOCATION);
1446
1447   application.SendNotification();
1448   application.Render(16);
1449
1450   DALI_TEST_EQUALS(gResourceReadySignalFired, true, TEST_LOCATION);
1451   gResourceReadySignalFired = false;
1452
1453   ImageView imageViewWithExistingImage = ImageView::New();
1454   imageViewWithExistingImage.ResourceReadySignal().Connect(&ResourceReadySignal);
1455   imageViewWithExistingImage.SetProperty(ImageView::Property::IMAGE, imageMap);
1456
1457   DALI_TEST_EQUALS(gResourceReadySignalFired, true, TEST_LOCATION);
1458
1459   END_TEST;
1460 }
1461
1462 int UtcDaliImageViewResourceReadySignalWithReusedImage02(void)
1463 {
1464   tet_infoline("Test Setting Image that was already loaded by another ImageView and still getting ResourceReadySignal when staged.");
1465
1466   ToolkitTestApplication application;
1467
1468   gResourceReadySignalFired = false;
1469
1470   Property::Map imageImmediateLoadingMap;
1471   imageImmediateLoadingMap[ImageVisual::Property::URL]         = gImage_34_RGBA;
1472   imageImmediateLoadingMap[ImageVisual::Property::LOAD_POLICY] = ImageVisual::LoadPolicy::IMMEDIATE;
1473
1474   tet_infoline("Immediate load an image");
1475   ImageView imageView = ImageView::New();
1476   imageView.ResourceReadySignal().Connect(&ResourceReadySignal);
1477   imageView.SetProperty(ImageView::Property::IMAGE, imageImmediateLoadingMap);
1478
1479   // loading started, this waits for the loader thread
1480   DALI_TEST_EQUALS(Test::WaitForEventThreadTrigger(1), true, TEST_LOCATION);
1481
1482   application.SendNotification();
1483   application.Render(16);
1484
1485   tet_infoline("Check image loaded");
1486   DALI_TEST_EQUALS(gResourceReadySignalFired, true, TEST_LOCATION);
1487   gResourceReadySignalFired = false;
1488
1489   tet_infoline("Create another ImageView with the same URL");
1490   ImageView imageViewWithExistingImage = ImageView::New(gImage_34_RGBA);
1491   tet_infoline("Connect to ResourceReady signal for second ImageView, it should still fire as resource is ready");
1492   imageViewWithExistingImage.ResourceReadySignal().Connect(&ResourceReadySignal);
1493
1494   application.GetScene().Add(imageViewWithExistingImage);
1495
1496   DALI_TEST_EQUALS(gResourceReadySignalFired, true, TEST_LOCATION);
1497
1498   END_TEST;
1499 }
1500
1501 int UtcDaliImageViewPaddingProperty(void)
1502 {
1503   ToolkitTestApplication application;
1504
1505   ImageView     imageView = ImageView::New();
1506   Property::Map imagePropertyMap;
1507   imagePropertyMap[Toolkit::Visual::Property::TYPE]       = Toolkit::Visual::IMAGE;
1508   imagePropertyMap[Toolkit::ImageVisual::Property::URL]   = TEST_RESOURCE_DIR "/gallery-small-1.jpg";
1509   imagePropertyMap[ImageVisual::Property::DESIRED_WIDTH]  = 128;
1510   imagePropertyMap[ImageVisual::Property::DESIRED_HEIGHT] = 128;
1511   imageView.SetProperty(Toolkit::ImageView::Property::IMAGE, imagePropertyMap);
1512   imageView.SetProperty(Actor::Property::ANCHOR_POINT, AnchorPoint::TOP_LEFT);
1513   imageView.SetProperty(Actor::Property::PARENT_ORIGIN, ParentOrigin::TOP_LEFT);
1514   imageView.SetProperty(Control::Property::PADDING, Extents(15, 10, 5, 10));
1515   application.GetScene().Add(imageView);
1516
1517   application.SendNotification();
1518   application.Render();
1519
1520   DALI_TEST_EQUALS(imageView.GetProperty<Extents>(Control::Property::PADDING), Extents(15, 10, 5, 10), TEST_LOCATION);
1521
1522   ImageView childImage = ImageView::New();
1523   childImage.SetBackgroundColor(Color::BLACK);
1524   childImage.SetProperty(Actor::Property::SIZE, Vector2(10.f, 10.f));
1525   imageView.Add(childImage);
1526
1527   application.SendNotification();
1528   application.Render();
1529
1530   // Child ImageView should be positioned dependinig on Parent ImageView's Padding value
1531   DALI_TEST_EQUALS(childImage.GetProperty<Vector3>(Dali::Actor::Property::POSITION), Vector3(15, 5, 0), TEST_LOCATION);
1532
1533   // Check whether Image Visual transforms on ImageVieiw::OnRelayout()
1534   Toolkit::Internal::Control& controlImpl = Toolkit::Internal::GetImplementation(imageView);
1535   Toolkit::Visual::Base       imageVisual = DevelControl::GetVisual(controlImpl, ImageView::Property::IMAGE);
1536   Property::Map               resultMap;
1537   imageVisual.CreatePropertyMap(resultMap);
1538
1539   Property::Value* transformValue = resultMap.Find(Visual::Property::TRANSFORM);
1540   DALI_TEST_CHECK(transformValue);
1541   Property::Map* retMap = transformValue->GetMap();
1542   DALI_TEST_CHECK(retMap);
1543
1544   // Image Visual should be positioned depending on ImageView's padding
1545   DALI_TEST_EQUALS(retMap->Find(Visual::Transform::Property::OFFSET)->Get<Vector2>(), Vector2(15, 5), TEST_LOCATION);
1546
1547   END_TEST;
1548 }
1549
1550 int UtcDaliImageViewPaddingProperty02(void)
1551 {
1552   ToolkitTestApplication application;
1553
1554   ImageView     imageView = ImageView::New();
1555   Property::Map imagePropertyMap;
1556   imagePropertyMap[Toolkit::Visual::Property::TYPE]            = Toolkit::Visual::IMAGE;
1557   imagePropertyMap[Toolkit::ImageVisual::Property::URL]        = TEST_RESOURCE_DIR "/Kid1.svg";
1558   imagePropertyMap[ImageVisual::Property::DESIRED_WIDTH]       = 128;
1559   imagePropertyMap[ImageVisual::Property::DESIRED_HEIGHT]      = 128;
1560   imagePropertyMap[DevelVisual::Property::VISUAL_FITTING_MODE] = Toolkit::DevelVisual::FIT_KEEP_ASPECT_RATIO;
1561   imageView.SetProperty(Toolkit::ImageView::Property::IMAGE, imagePropertyMap);
1562   imageView.SetProperty(Actor::Property::ANCHOR_POINT, AnchorPoint::TOP_LEFT);
1563   imageView.SetProperty(Actor::Property::PARENT_ORIGIN, ParentOrigin::TOP_LEFT);
1564   imageView.SetProperty(Control::Property::PADDING, Extents(15, 10, 5, 10));
1565   application.GetScene().Add(imageView);
1566
1567   application.SendNotification();
1568   application.Render();
1569
1570   DALI_TEST_EQUALS(imageView.GetProperty<Extents>(Control::Property::PADDING), Extents(15, 10, 5, 10), TEST_LOCATION);
1571
1572   // Check whether Image Visual transforms on ImageVieiw::OnRelayout()
1573   Toolkit::Internal::Control& controlImpl = Toolkit::Internal::GetImplementation(imageView);
1574   Toolkit::Visual::Base       imageVisual = DevelControl::GetVisual(controlImpl, ImageView::Property::IMAGE);
1575   Property::Map               resultMap;
1576   imageVisual.CreatePropertyMap(resultMap);
1577
1578   Property::Value* transformValue = resultMap.Find(Visual::Property::TRANSFORM);
1579   DALI_TEST_CHECK(transformValue);
1580   Property::Map* retMap = transformValue->GetMap();
1581   DALI_TEST_CHECK(retMap);
1582
1583   // Image Visual should be positioned depending on ImageView's padding
1584   DALI_TEST_EQUALS(retMap->Find(Visual::Transform::Property::OFFSET)->Get<Vector2>(), Vector2(15, 5), TEST_LOCATION);
1585
1586   END_TEST;
1587 }
1588
1589 int UtcDaliImageViewPaddingProperty03(void)
1590 {
1591   tet_infoline("Test Setting Image Padding then removing it.");
1592
1593   ToolkitTestApplication application;
1594
1595   ImageView     imageView = ImageView::New();
1596   Property::Map imagePropertyMap;
1597   imagePropertyMap[Toolkit::Visual::Property::TYPE]            = Toolkit::Visual::IMAGE;
1598   imagePropertyMap[Toolkit::ImageVisual::Property::URL]        = TEST_RESOURCE_DIR "/Kid1.svg";
1599   imagePropertyMap[ImageVisual::Property::DESIRED_WIDTH]       = 128;
1600   imagePropertyMap[ImageVisual::Property::DESIRED_HEIGHT]      = 128;
1601   imagePropertyMap[DevelVisual::Property::VISUAL_FITTING_MODE] = Toolkit::DevelVisual::FIT_KEEP_ASPECT_RATIO;
1602   imageView.SetProperty(Toolkit::ImageView::Property::IMAGE, imagePropertyMap);
1603   imageView.SetProperty(Actor::Property::ANCHOR_POINT, AnchorPoint::TOP_LEFT);
1604   imageView.SetProperty(Actor::Property::PARENT_ORIGIN, ParentOrigin::TOP_LEFT);
1605   imageView.SetProperty(Control::Property::PADDING, Extents(15, 10, 5, 10));
1606   application.GetScene().Add(imageView);
1607
1608   application.SendNotification();
1609   application.Render();
1610
1611   DALI_TEST_EQUALS(imageView.GetProperty<Extents>(Control::Property::PADDING), Extents(15, 10, 5, 10), TEST_LOCATION);
1612
1613   tet_infoline("Remove Padding and test Visual is position correctly");
1614
1615   imageView.SetProperty(Control::Property::PADDING, Extents(0, 0, 0, 0));
1616
1617   application.SendNotification();
1618   application.Render();
1619
1620   // Check whether Image Visual transforms on ImageVieiw::OnRelayout()
1621   Toolkit::Internal::Control& controlImpl = Toolkit::Internal::GetImplementation(imageView);
1622   Toolkit::Visual::Base       imageVisual = DevelControl::GetVisual(controlImpl, ImageView::Property::IMAGE);
1623   Property::Map               resultMap;
1624   imageVisual.CreatePropertyMap(resultMap);
1625
1626   Property::Value* transformValue = resultMap.Find(Visual::Property::TRANSFORM);
1627   DALI_TEST_CHECK(transformValue);
1628   Property::Map* retMap = transformValue->GetMap();
1629   DALI_TEST_CHECK(retMap);
1630
1631   // Image Visual should be positioned depending on ImageView's padding
1632   DALI_TEST_EQUALS(retMap->Find(Visual::Transform::Property::OFFSET)->Get<Vector2>(), Vector2(0, 0), TEST_LOCATION);
1633
1634   END_TEST;
1635 }
1636
1637 int UtcDaliImageViewPaddingProperty04(void)
1638 {
1639   tet_infoline("Test Setting Image Padding then removing it. Visual Fitting Mode as Fill");
1640
1641   ToolkitTestApplication application;
1642
1643   ImageView     imageView = ImageView::New();
1644   Property::Map imagePropertyMap;
1645   imagePropertyMap[Toolkit::Visual::Property::TYPE]            = Toolkit::Visual::IMAGE;
1646   imagePropertyMap[Toolkit::ImageVisual::Property::URL]        = TEST_RESOURCE_DIR "/Kid1.svg";
1647   imagePropertyMap[ImageVisual::Property::DESIRED_WIDTH]       = 128;
1648   imagePropertyMap[ImageVisual::Property::DESIRED_HEIGHT]      = 128;
1649   imagePropertyMap[DevelVisual::Property::VISUAL_FITTING_MODE] = Toolkit::DevelVisual::FILL;
1650   imageView.SetProperty(Toolkit::ImageView::Property::IMAGE, imagePropertyMap);
1651   imageView.SetProperty(Actor::Property::ANCHOR_POINT, AnchorPoint::TOP_LEFT);
1652   imageView.SetProperty(Actor::Property::PARENT_ORIGIN, ParentOrigin::TOP_LEFT);
1653   imageView.SetProperty(Control::Property::PADDING, Extents(15, 10, 5, 10));
1654   application.GetScene().Add(imageView);
1655
1656   application.SendNotification();
1657   application.Render();
1658
1659   DALI_TEST_EQUALS(imageView.GetProperty<Extents>(Control::Property::PADDING), Extents(15, 10, 5, 10), TEST_LOCATION);
1660
1661   tet_infoline("Remove Padding and test Visual is position correctly");
1662
1663   imageView.SetProperty(Control::Property::PADDING, Extents(0, 0, 0, 0));
1664
1665   application.SendNotification();
1666   application.Render();
1667
1668   // Check whether Image Visual transforms on ImageVieiw::OnRelayout()
1669   Toolkit::Internal::Control& controlImpl = Toolkit::Internal::GetImplementation(imageView);
1670   Toolkit::Visual::Base       imageVisual = DevelControl::GetVisual(controlImpl, ImageView::Property::IMAGE);
1671   Property::Map               resultMap;
1672   imageVisual.CreatePropertyMap(resultMap);
1673
1674   Property::Value* transformValue = resultMap.Find(Visual::Property::TRANSFORM);
1675   DALI_TEST_CHECK(transformValue);
1676   Property::Map* retMap = transformValue->GetMap();
1677   DALI_TEST_CHECK(retMap);
1678
1679   // Image Visual should be positioned depending on ImageView's padding
1680   DALI_TEST_EQUALS(retMap->Find(Visual::Transform::Property::OFFSET)->Get<Vector2>(), Vector2(0, 0), TEST_LOCATION);
1681
1682   END_TEST;
1683 }
1684
1685 int UtcDaliImageViewTransformTest01(void)
1686 {
1687   tet_infoline("Test Setting a offset transform on the ImageView");
1688
1689   ToolkitTestApplication application;
1690
1691   ImageView     imageView = ImageView::New();
1692   Property::Map imagePropertyMap;
1693   imagePropertyMap.Add(Toolkit::Visual::Property::TYPE, Toolkit::Visual::IMAGE)
1694     .Add(Toolkit::ImageVisual::Property::URL, TEST_RESOURCE_DIR "/Kid1.svg")
1695     .Add(ImageVisual::Property::DESIRED_WIDTH, 120)
1696     .Add(ImageVisual::Property::DESIRED_HEIGHT, 120)
1697     .Add(DevelVisual::Property::VISUAL_FITTING_MODE, Toolkit::DevelVisual::FILL)
1698     .Add(Visual::Property::TRANSFORM,
1699          Property::Map().Add(Toolkit::Visual::Transform::Property::OFFSET_POLICY,
1700                              Vector2(Visual::Transform::Policy::ABSOLUTE, Visual::Transform::Policy::ABSOLUTE))
1701            .Add(Toolkit::Visual::Transform::Property::OFFSET, Vector2(8, 8)));
1702
1703   imageView.SetProperty(Toolkit::ImageView::Property::IMAGE, imagePropertyMap);
1704   imageView.SetProperty(Actor::Property::ANCHOR_POINT, AnchorPoint::TOP_LEFT);
1705   imageView.SetProperty(Actor::Property::PARENT_ORIGIN, ParentOrigin::TOP_LEFT);
1706   application.GetScene().Add(imageView);
1707
1708   application.SendNotification();
1709   application.Render();
1710
1711   // Check whether Image Visual transforms on ImageVieiw::OnRelayout()
1712   Toolkit::Internal::Control& controlImpl = Toolkit::Internal::GetImplementation(imageView);
1713   Toolkit::Visual::Base       imageVisual = DevelControl::GetVisual(controlImpl, ImageView::Property::IMAGE);
1714   Property::Map               resultMap;
1715   imageVisual.CreatePropertyMap(resultMap);
1716
1717   Property::Value* transformValue = resultMap.Find(Visual::Property::TRANSFORM);
1718   DALI_TEST_CHECK(transformValue);
1719   Property::Map* retMap = transformValue->GetMap();
1720   DALI_TEST_CHECK(retMap);
1721
1722   // Image Visual should be positioned depending on ImageView's padding
1723   DALI_TEST_EQUALS(retMap->Find(Visual::Transform::Property::OFFSET)->Get<Vector2>(), Vector2(8, 8), TEST_LOCATION);
1724   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);
1725
1726   END_TEST;
1727 }
1728
1729 int UtcDaliImageViewUsingAtlasAndGetNaturalSize(void)
1730 {
1731   ToolkitTestApplication application;
1732
1733   // Check ImageView with background and main image, to ensure both visuals are marked as loaded
1734   ImageView     imageView = ImageView::New();
1735   Property::Map imageMap;
1736   imageMap[Toolkit::Visual::Property::TYPE]          = Toolkit::Visual::IMAGE;
1737   imageMap[Toolkit::ImageVisual::Property::URL]      = gImage_34_RGBA;
1738   imageMap[Toolkit::ImageVisual::Property::ATLASING] = true;
1739   imageView.SetProperty(Toolkit::ImageView::Property::IMAGE, imageMap);
1740   application.GetScene().Add(imageView);
1741
1742   // Trigger a potential relayout
1743   application.SendNotification();
1744   application.Render();
1745
1746   Vector3 naturalSize = imageView.GetNaturalSize();
1747
1748   DALI_TEST_EQUALS(naturalSize.width, 34.0f, TEST_LOCATION);
1749   DALI_TEST_EQUALS(naturalSize.height, 34.0f, TEST_LOCATION);
1750
1751   END_TEST;
1752 }
1753
1754 int UtcDaliImageViewFillMode(void)
1755 {
1756   ToolkitTestApplication application;
1757
1758   tet_infoline("Create an ImageVisual without padding and set the fill-mode to fill");
1759
1760   ImageView     imageView = ImageView::New();
1761   Property::Map imageMap;
1762   imageMap.Add(Toolkit::Visual::Property::TYPE, Toolkit::Visual::IMAGE);
1763   imageMap.Add(Toolkit::ImageVisual::Property::URL, gImage_600_RGB);
1764   imageMap.Add(DevelVisual::Property::VISUAL_FITTING_MODE, DevelVisual::FittingMode::FILL);
1765
1766   imageView.SetProperty(Toolkit::ImageView::Property::IMAGE, imageMap);
1767
1768   application.GetScene().Add(imageView);
1769
1770   // Trigger a potential relayout
1771   application.SendNotification();
1772   application.Render();
1773
1774   Toolkit::Visual::Base visual = DevelControl::GetVisual(Toolkit::Internal::GetImplementation(imageView), Toolkit::ImageView::Property::IMAGE);
1775   Property::Map         returnedMap;
1776   visual.CreatePropertyMap(returnedMap);
1777
1778   Property::Value* value = returnedMap.Find(Toolkit::Visual::Property::TRANSFORM);
1779   DALI_TEST_CHECK(value);
1780   Property::Map* map = value->GetMap();
1781   DALI_TEST_CHECK(map);
1782
1783   value = map->Find(Toolkit::Visual::Transform::Property::SIZE);
1784   DALI_TEST_CHECK(value);
1785   DALI_TEST_EQUALS(value->Get<Vector2>(), Vector2::ONE, TEST_LOCATION);
1786
1787   value = map->Find(Toolkit::Visual::Transform::Property::SIZE_POLICY);
1788   DALI_TEST_CHECK(value);
1789   DALI_TEST_CHECK(value->Get<int>() == Toolkit::Visual::Transform::Policy::RELATIVE);
1790
1791   END_TEST;
1792 }
1793
1794 int UtcDaliImageViewFittingModeFitKeepAspectRatio(void)
1795 {
1796   ToolkitTestApplication application;
1797
1798   tet_infoline("Create an ImageVisual using FitKeepAspectRatio ( image: [600,600], view: [600,700] )");
1799   tet_infoline("  There should be need to change the transform, offset is adjusted to fit inside");
1800
1801   ImageView     imageView = ImageView::New();
1802   Property::Map imageMap;
1803   imageMap.Add(Toolkit::Visual::Property::TYPE, Toolkit::Visual::IMAGE);
1804   imageMap.Add(Toolkit::ImageVisual::Property::URL, gImage_600_RGB); // 600x600 image
1805   imageMap.Add(DevelVisual::Property::VISUAL_FITTING_MODE, Toolkit::DevelVisual::FIT_KEEP_ASPECT_RATIO);
1806
1807   imageView.SetProperty(Toolkit::ImageView::Property::IMAGE, imageMap);
1808   imageView.SetProperty(Actor::Property::SIZE, Vector2(600, 700));
1809
1810   application.GetScene().Add(imageView);
1811
1812   // Trigger a potential relayout
1813   application.SendNotification();
1814   application.Render();
1815
1816   Toolkit::Visual::Base visual = DevelControl::GetVisual(Toolkit::Internal::GetImplementation(imageView), Toolkit::ImageView::Property::IMAGE);
1817   Property::Map         returnedMap;
1818   visual.CreatePropertyMap(returnedMap);
1819
1820   Property::Value* value = returnedMap.Find(Toolkit::Visual::Property::TRANSFORM);
1821   DALI_TEST_CHECK(value);
1822   Property::Map* map = value->GetMap();
1823   DALI_TEST_CHECK(map);
1824
1825   // If there's
1826   value = map->Find(Toolkit::Visual::Transform::Property::SIZE);
1827   DALI_TEST_CHECK(value);
1828   DALI_TEST_EQUALS(value->Get<Vector2>(), Vector2(600, 600), TEST_LOCATION);
1829
1830   value = map->Find(Toolkit::Visual::Transform::Property::SIZE_POLICY);
1831   DALI_TEST_CHECK(value);
1832   DALI_TEST_EQUALS(value->Get<Vector2>(), Vector2(Toolkit::Visual::Transform::Policy::ABSOLUTE, Toolkit::Visual::Transform::Policy::ABSOLUTE), TEST_LOCATION);
1833
1834   value = map->Find(Toolkit::Visual::Transform::Property::OFFSET);
1835   DALI_TEST_CHECK(value);
1836   DALI_TEST_EQUALS(value->Get<Vector2>(), Vector2(0, 50), TEST_LOCATION);
1837
1838   END_TEST;
1839 }
1840
1841 int UtcDaliImageViewFittingModesFill(void)
1842 {
1843   ToolkitTestApplication application;
1844
1845   tet_infoline("Create an ImageVisual using Fill ( image: [600,600], view: [600,700] )");
1846   tet_infoline("  There should be no need to change the transform, only size is changed to fit view");
1847
1848   ImageView     imageView = ImageView::New();
1849   Property::Map imageMap;
1850   imageMap.Add(Toolkit::Visual::Property::TYPE, Toolkit::Visual::IMAGE);
1851   imageMap.Add(Toolkit::ImageVisual::Property::URL, gImage_600_RGB); // 600x600 image
1852   imageMap.Add(DevelVisual::Property::VISUAL_FITTING_MODE, Toolkit::DevelVisual::FILL);
1853
1854   imageView.SetProperty(Toolkit::ImageView::Property::IMAGE, imageMap);
1855   imageView.SetProperty(Actor::Property::SIZE, Vector2(600, 700));
1856
1857   application.GetScene().Add(imageView);
1858
1859   // Trigger a potential relayout
1860   application.SendNotification();
1861   application.Render();
1862
1863   Toolkit::Visual::Base visual = DevelControl::GetVisual(Toolkit::Internal::GetImplementation(imageView), Toolkit::ImageView::Property::IMAGE);
1864   Property::Map         returnedMap;
1865   visual.CreatePropertyMap(returnedMap);
1866
1867   Property::Value* value = returnedMap.Find(Toolkit::Visual::Property::TRANSFORM);
1868   DALI_TEST_CHECK(value);
1869   Property::Map* map = value->GetMap();
1870   DALI_TEST_CHECK(map);
1871
1872   value = map->Find(Toolkit::Visual::Transform::Property::SIZE);
1873   DALI_TEST_CHECK(value);
1874   DALI_TEST_EQUALS(value->Get<Vector2>(), Vector2::ONE, TEST_LOCATION); // Change the internal size according to the image view size
1875
1876   value = map->Find(Toolkit::Visual::Transform::Property::SIZE_POLICY);
1877   DALI_TEST_CHECK(value);
1878   DALI_TEST_CHECK(value->Get<int>() == Toolkit::Visual::Transform::Policy::RELATIVE);
1879
1880   value = map->Find(Toolkit::Visual::Transform::Property::OFFSET);
1881   DALI_TEST_CHECK(value);
1882   DALI_TEST_EQUALS(value->Get<Vector2>(), Vector2(0, 0), TEST_LOCATION); // OFFSET is zero
1883
1884   END_TEST;
1885 }
1886
1887 int UtcDaliImageViewFittingModesOverfitKeepAspectRatio(void)
1888 {
1889   ToolkitTestApplication application;
1890
1891   tet_infoline("Create an ImageVisual using OverFitKeepAspectRatio ( image: [600,600], view: [600,500] )");
1892   tet_infoline("  offset or size is the same as view, but adjust internally using pixelArea ");
1893
1894   ImageView     imageView = ImageView::New();
1895   Property::Map imageMap;
1896   imageMap.Add(Toolkit::Visual::Property::TYPE, Toolkit::Visual::IMAGE);
1897   imageMap.Add(Toolkit::ImageVisual::Property::URL, gImage_600_RGB); // 600x600 image
1898   imageMap.Add(DevelVisual::Property::VISUAL_FITTING_MODE, Toolkit::DevelVisual::OVER_FIT_KEEP_ASPECT_RATIO);
1899
1900   imageView.SetProperty(Toolkit::ImageView::Property::IMAGE, imageMap);
1901   imageView.SetProperty(Actor::Property::SIZE, Vector2(600, 500));
1902
1903   application.GetScene().Add(imageView);
1904
1905   // Trigger a potential relayout
1906   application.SendNotification();
1907   application.Render();
1908
1909   Toolkit::Visual::Base visual = DevelControl::GetVisual(Toolkit::Internal::GetImplementation(imageView), Toolkit::ImageView::Property::IMAGE);
1910   Property::Map         returnedMap;
1911   visual.CreatePropertyMap(returnedMap);
1912
1913   Property::Value* value = returnedMap.Find(Toolkit::Visual::Property::TRANSFORM);
1914   DALI_TEST_CHECK(value);
1915   Property::Map* map = value->GetMap();
1916   DALI_TEST_CHECK(map);
1917
1918   // If there's
1919   value = map->Find(Toolkit::Visual::Transform::Property::SIZE);
1920   DALI_TEST_CHECK(value);
1921   DALI_TEST_EQUALS(value->Get<Vector2>(), Vector2(600, 500), TEST_LOCATION); // Change the internal size according to the image view size
1922
1923   value = map->Find(Toolkit::Visual::Transform::Property::SIZE_POLICY);
1924   DALI_TEST_CHECK(value);
1925   DALI_TEST_EQUALS(value->Get<Vector2>(), Vector2(Toolkit::Visual::Transform::Policy::ABSOLUTE, Toolkit::Visual::Transform::Policy::ABSOLUTE), TEST_LOCATION);
1926
1927   value = map->Find(Toolkit::Visual::Transform::Property::OFFSET);
1928   DALI_TEST_CHECK(value);
1929   DALI_TEST_EQUALS(value->Get<Vector2>(), Vector2(0, 0), TEST_LOCATION); // OFFSET is zero
1930
1931   END_TEST;
1932 }
1933
1934 int UtcDaliImageViewFittingModesCenter01(void)
1935 {
1936   ToolkitTestApplication application;
1937
1938   tet_infoline("Create an ImageVisual using Center ( image: [600,600], view: [700,700] )");
1939   tet_infoline("  There should be need to change the transform, offset is adjusted to fit inside");
1940
1941   ImageView     imageView = ImageView::New();
1942   Property::Map imageMap;
1943   imageMap.Add(Toolkit::Visual::Property::TYPE, Toolkit::Visual::IMAGE);
1944   imageMap.Add(Toolkit::ImageVisual::Property::URL, gImage_600_RGB); // 600x600 image
1945   imageMap.Add(DevelVisual::Property::VISUAL_FITTING_MODE, Toolkit::DevelVisual::CENTER);
1946
1947   imageView.SetProperty(Toolkit::ImageView::Property::IMAGE, imageMap);
1948   imageView.SetProperty(Actor::Property::SIZE, Vector2(700, 700));
1949
1950   application.GetScene().Add(imageView);
1951
1952   // Trigger a potential relayout
1953   application.SendNotification();
1954   application.Render();
1955
1956   Toolkit::Visual::Base visual = DevelControl::GetVisual(Toolkit::Internal::GetImplementation(imageView), Toolkit::ImageView::Property::IMAGE);
1957   Property::Map         returnedMap;
1958   visual.CreatePropertyMap(returnedMap);
1959
1960   Property::Value* value = returnedMap.Find(Toolkit::Visual::Property::TRANSFORM);
1961   DALI_TEST_CHECK(value);
1962   Property::Map* map = value->GetMap();
1963   DALI_TEST_CHECK(map);
1964
1965   value = map->Find(Toolkit::Visual::Transform::Property::SIZE);
1966   DALI_TEST_CHECK(value);
1967   DALI_TEST_EQUALS(value->Get<Vector2>(), Vector2(600, 600), TEST_LOCATION); // Change the internal size according to the image view size
1968
1969   value = map->Find(Toolkit::Visual::Transform::Property::SIZE_POLICY);
1970   DALI_TEST_CHECK(value);
1971   DALI_TEST_EQUALS(value->Get<Vector2>(), Vector2(Toolkit::Visual::Transform::Policy::ABSOLUTE, Toolkit::Visual::Transform::Policy::ABSOLUTE), TEST_LOCATION);
1972
1973   value = map->Find(Toolkit::Visual::Transform::Property::OFFSET);
1974   DALI_TEST_CHECK(value);
1975   DALI_TEST_EQUALS(value->Get<Vector2>(), Vector2(50, 50), TEST_LOCATION);
1976
1977   END_TEST;
1978 }
1979
1980 int UtcDaliImageViewFittingModesCenter02(void)
1981 {
1982   ToolkitTestApplication application;
1983
1984   tet_infoline("Create an ImageVisual using Center ( image: [600,600], view: [500,500] )");
1985   tet_infoline("  There should be need to change the transform, offset is adjusted to fit inside");
1986
1987   ImageView     imageView = ImageView::New();
1988   Property::Map imageMap;
1989   imageMap.Add(Toolkit::Visual::Property::TYPE, Toolkit::Visual::IMAGE);
1990   imageMap.Add(Toolkit::ImageVisual::Property::URL, gImage_600_RGB); // 600x600 image
1991   imageMap.Add(DevelVisual::Property::VISUAL_FITTING_MODE, Toolkit::DevelVisual::CENTER);
1992
1993   imageView.SetProperty(Toolkit::ImageView::Property::IMAGE, imageMap);
1994   imageView.SetProperty(Actor::Property::SIZE, Vector2(700, 700));
1995
1996   application.GetScene().Add(imageView);
1997
1998   // Trigger a potential relayout
1999   application.SendNotification();
2000   application.Render();
2001
2002   Toolkit::Visual::Base visual = DevelControl::GetVisual(Toolkit::Internal::GetImplementation(imageView), Toolkit::ImageView::Property::IMAGE);
2003   Property::Map         returnedMap;
2004   visual.CreatePropertyMap(returnedMap);
2005
2006   Property::Value* value = returnedMap.Find(Toolkit::Visual::Property::TRANSFORM);
2007   DALI_TEST_CHECK(value);
2008   Property::Map* map = value->GetMap();
2009   DALI_TEST_CHECK(map);
2010
2011   value = map->Find(Toolkit::Visual::Transform::Property::SIZE);
2012   DALI_TEST_CHECK(value);
2013   DALI_TEST_EQUALS(value->Get<Vector2>(), Vector2(600, 600), TEST_LOCATION); // Change the internal size according to the image view size
2014
2015   value = map->Find(Toolkit::Visual::Transform::Property::SIZE_POLICY);
2016   DALI_TEST_CHECK(value);
2017   DALI_TEST_EQUALS(value->Get<Vector2>(), Vector2(Toolkit::Visual::Transform::Policy::ABSOLUTE, Toolkit::Visual::Transform::Policy::ABSOLUTE), TEST_LOCATION);
2018
2019   value = map->Find(Toolkit::Visual::Transform::Property::OFFSET);
2020   DALI_TEST_CHECK(value);
2021   DALI_TEST_EQUALS(value->Get<Vector2>(), Vector2(50, 50), TEST_LOCATION);
2022
2023   END_TEST;
2024 }
2025
2026 int UtcDaliImageViewFittingModesFitHeight01(void)
2027 {
2028   ToolkitTestApplication application;
2029
2030   tet_infoline("Create an ImageVisual using FitHeight ( image: [600,600], view: [600,700] )");
2031
2032   ImageView     imageView = ImageView::New();
2033   Property::Map imageMap;
2034   imageMap.Add(Toolkit::Visual::Property::TYPE, Toolkit::Visual::IMAGE);
2035   imageMap.Add(Toolkit::ImageVisual::Property::URL, gImage_600_RGB); // 600x600 image
2036   imageMap.Add(DevelVisual::Property::VISUAL_FITTING_MODE, Toolkit::DevelVisual::FIT_HEIGHT);
2037
2038   imageView.SetProperty(Toolkit::ImageView::Property::IMAGE, imageMap);
2039   imageView.SetProperty(Actor::Property::SIZE, Vector2(600, 700));
2040
2041   application.GetScene().Add(imageView);
2042
2043   // Trigger a potential relayout
2044   application.SendNotification();
2045   application.Render();
2046
2047   Toolkit::Visual::Base visual = DevelControl::GetVisual(Toolkit::Internal::GetImplementation(imageView), Toolkit::ImageView::Property::IMAGE);
2048   Property::Map         returnedMap;
2049   visual.CreatePropertyMap(returnedMap);
2050
2051   Property::Value* value = returnedMap.Find(Toolkit::Visual::Property::TRANSFORM);
2052   DALI_TEST_CHECK(value);
2053   Property::Map* map = value->GetMap();
2054   DALI_TEST_CHECK(map);
2055
2056   value = map->Find(Toolkit::Visual::Transform::Property::SIZE);
2057   DALI_TEST_CHECK(value);
2058   DALI_TEST_EQUALS(value->Get<Vector2>(), Vector2(600, 700), TEST_LOCATION); // Change the internal size according to the image view size
2059
2060   value = map->Find(Toolkit::Visual::Transform::Property::SIZE_POLICY);
2061   DALI_TEST_CHECK(value);
2062   DALI_TEST_EQUALS(value->Get<Vector2>(), Vector2(Toolkit::Visual::Transform::Policy::ABSOLUTE, Toolkit::Visual::Transform::Policy::ABSOLUTE), TEST_LOCATION);
2063
2064   value = map->Find(Toolkit::Visual::Transform::Property::OFFSET);
2065   DALI_TEST_CHECK(value);
2066   DALI_TEST_EQUALS(value->Get<Vector2>(), Vector2(0, 0), TEST_LOCATION); // OFFSET is zero
2067
2068   END_TEST;
2069 }
2070
2071 int UtcDaliImageViewFittingModesFitHeight02(void)
2072 {
2073   ToolkitTestApplication application;
2074
2075   tet_infoline("Create an ImageVisual using FitHeight ( image: [600,600], view: [700,600] )");
2076
2077   ImageView     imageView = ImageView::New();
2078   Property::Map imageMap;
2079   imageMap.Add(Toolkit::Visual::Property::TYPE, Toolkit::Visual::IMAGE);
2080   imageMap.Add(Toolkit::ImageVisual::Property::URL, gImage_600_RGB); // 249x169 image
2081   imageMap.Add(DevelVisual::Property::VISUAL_FITTING_MODE, Toolkit::DevelVisual::FIT_HEIGHT);
2082
2083   imageView.SetProperty(Toolkit::ImageView::Property::IMAGE, imageMap);
2084   imageView.SetProperty(Actor::Property::SIZE, Vector2(700, 600));
2085
2086   application.GetScene().Add(imageView);
2087
2088   // Trigger a potential relayout
2089   application.SendNotification();
2090   application.Render();
2091
2092   Toolkit::Visual::Base visual = DevelControl::GetVisual(Toolkit::Internal::GetImplementation(imageView), Toolkit::ImageView::Property::IMAGE);
2093   Property::Map         returnedMap;
2094   visual.CreatePropertyMap(returnedMap);
2095
2096   Property::Value* value = returnedMap.Find(Toolkit::Visual::Property::TRANSFORM);
2097   DALI_TEST_CHECK(value);
2098   Property::Map* map = value->GetMap();
2099   DALI_TEST_CHECK(map);
2100
2101   value = map->Find(Toolkit::Visual::Transform::Property::SIZE);
2102   DALI_TEST_CHECK(value);
2103   DALI_TEST_EQUALS(value->Get<Vector2>(), Vector2(600, 600), TEST_LOCATION); // Change the internal size according to the image view size
2104
2105   value = map->Find(Toolkit::Visual::Transform::Property::SIZE_POLICY);
2106   DALI_TEST_CHECK(value);
2107   DALI_TEST_EQUALS(value->Get<Vector2>(), Vector2(Toolkit::Visual::Transform::Policy::ABSOLUTE, Toolkit::Visual::Transform::Policy::ABSOLUTE), TEST_LOCATION);
2108
2109   value = map->Find(Toolkit::Visual::Transform::Property::OFFSET);
2110   DALI_TEST_CHECK(value);
2111   DALI_TEST_EQUALS(value->Get<Vector2>(), Vector2(50, 0), TEST_LOCATION);
2112
2113   END_TEST;
2114 }
2115
2116 int UtcDaliImageViewFittingModesFitWidth01(void)
2117 {
2118   ToolkitTestApplication application;
2119
2120   tet_infoline("Create an ImageVisual using FitWidth ( image: [600,600], view: [600,700] )");
2121
2122   ImageView     imageView = ImageView::New();
2123   Property::Map imageMap;
2124   imageMap.Add(Toolkit::Visual::Property::TYPE, Toolkit::Visual::IMAGE);
2125   imageMap.Add(Toolkit::ImageVisual::Property::URL, gImage_600_RGB); // 600x600 image
2126   imageMap.Add(DevelVisual::Property::VISUAL_FITTING_MODE, Toolkit::DevelVisual::FIT_WIDTH);
2127
2128   imageView.SetProperty(Toolkit::ImageView::Property::IMAGE, imageMap);
2129   imageView.SetProperty(Actor::Property::SIZE, Vector2(600, 700));
2130
2131   application.GetScene().Add(imageView);
2132
2133   // Trigger a potential relayout
2134   application.SendNotification();
2135   application.Render();
2136
2137   Toolkit::Visual::Base visual = DevelControl::GetVisual(Toolkit::Internal::GetImplementation(imageView), Toolkit::ImageView::Property::IMAGE);
2138   Property::Map         returnedMap;
2139   visual.CreatePropertyMap(returnedMap);
2140
2141   Property::Value* value = returnedMap.Find(Toolkit::Visual::Property::TRANSFORM);
2142   DALI_TEST_CHECK(value);
2143   Property::Map* map = value->GetMap();
2144   DALI_TEST_CHECK(map);
2145
2146   value = map->Find(Toolkit::Visual::Transform::Property::SIZE);
2147   DALI_TEST_CHECK(value);
2148   DALI_TEST_EQUALS(value->Get<Vector2>(), Vector2(600, 600), TEST_LOCATION); // Change the internal size according to the image view size
2149
2150   value = map->Find(Toolkit::Visual::Transform::Property::SIZE_POLICY);
2151   DALI_TEST_CHECK(value);
2152   DALI_TEST_EQUALS(value->Get<Vector2>(), Vector2(Toolkit::Visual::Transform::Policy::ABSOLUTE, Toolkit::Visual::Transform::Policy::ABSOLUTE), TEST_LOCATION);
2153
2154   value = map->Find(Toolkit::Visual::Transform::Property::OFFSET);
2155   DALI_TEST_CHECK(value);
2156   DALI_TEST_EQUALS(value->Get<Vector2>(), Vector2(0, 50), TEST_LOCATION);
2157
2158   END_TEST;
2159 }
2160
2161 int UtcDaliImageViewFittingModesFitWidth02(void)
2162 {
2163   ToolkitTestApplication application;
2164
2165   tet_infoline("Create an ImageVisual using FitWidth ( image: [600,600], view:[700,600] )");
2166
2167   ImageView     imageView = ImageView::New();
2168   Property::Map imageMap;
2169   imageMap.Add(Toolkit::Visual::Property::TYPE, Toolkit::Visual::IMAGE);
2170   imageMap.Add(Toolkit::ImageVisual::Property::URL, gImage_600_RGB); // 249x169 image
2171   imageMap.Add(DevelVisual::Property::VISUAL_FITTING_MODE, Toolkit::DevelVisual::FIT_WIDTH);
2172
2173   imageView.SetProperty(Toolkit::ImageView::Property::IMAGE, imageMap);
2174   imageView.SetProperty(Actor::Property::SIZE, Vector2(700, 600));
2175
2176   application.GetScene().Add(imageView);
2177
2178   // Trigger a potential relayout
2179   application.SendNotification();
2180   application.Render();
2181
2182   Toolkit::Visual::Base visual = DevelControl::GetVisual(Toolkit::Internal::GetImplementation(imageView), Toolkit::ImageView::Property::IMAGE);
2183   Property::Map         returnedMap;
2184   visual.CreatePropertyMap(returnedMap);
2185
2186   Property::Value* value = returnedMap.Find(Toolkit::Visual::Property::TRANSFORM);
2187   DALI_TEST_CHECK(value);
2188   Property::Map* map = value->GetMap();
2189   DALI_TEST_CHECK(map);
2190
2191   value = map->Find(Toolkit::Visual::Transform::Property::SIZE);
2192   DALI_TEST_CHECK(value);
2193   DALI_TEST_EQUALS(value->Get<Vector2>(), Vector2(700, 600), TEST_LOCATION); // Change the internal size according to the image view size
2194
2195   value = map->Find(Toolkit::Visual::Transform::Property::SIZE_POLICY);
2196   DALI_TEST_CHECK(value);
2197   DALI_TEST_EQUALS(value->Get<Vector2>(), Vector2(Toolkit::Visual::Transform::Policy::ABSOLUTE, Toolkit::Visual::Transform::Policy::ABSOLUTE), TEST_LOCATION);
2198
2199   value = map->Find(Toolkit::Visual::Transform::Property::OFFSET);
2200   DALI_TEST_CHECK(value);
2201   DALI_TEST_EQUALS(value->Get<Vector2>(), Vector2(0, 0), TEST_LOCATION); // OFFSET is zero
2202
2203   END_TEST;
2204 }
2205
2206 int UtcDaliImageViewFittingModesChangeFittingMode01(void)
2207 {
2208   ToolkitTestApplication application;
2209
2210   tet_infoline("UtcDaliImageViewFittingModesChangeFittingMode, image: [600,600], view:[800,700]");
2211
2212   ImageView imageView = ImageView::New();
2213
2214   // 1. Render using FittingMode::SHRINK_TO_FIT
2215   Property::Map imageMap;
2216   imageMap[Toolkit::Visual::Property::TYPE]            = Toolkit::Visual::IMAGE;
2217   imageMap[Toolkit::ImageVisual::Property::URL]        = gImage_600_RGB;
2218   imageMap[DevelVisual::Property::VISUAL_FITTING_MODE] = Toolkit::DevelVisual::FIT_KEEP_ASPECT_RATIO;
2219
2220   imageView.SetProperty(Toolkit::ImageView::Property::IMAGE, imageMap);
2221   imageView.SetProperty(Actor::Property::SIZE, Vector2(800, 700));
2222
2223   application.GetScene().Add(imageView);
2224
2225   // Trigger a potential relayout
2226   application.SendNotification();
2227   application.Render();
2228
2229   Toolkit::Visual::Base visual = DevelControl::GetVisual(Toolkit::Internal::GetImplementation(imageView), Toolkit::ImageView::Property::IMAGE);
2230   Property::Map         returnedMap;
2231   visual.CreatePropertyMap(returnedMap);
2232
2233   Property::Value* value = returnedMap.Find(Toolkit::Visual::Property::TRANSFORM);
2234   DALI_TEST_CHECK(value);
2235   Property::Map* map = value->GetMap();
2236   DALI_TEST_CHECK(map);
2237
2238   value = map->Find(Toolkit::Visual::Transform::Property::SIZE);
2239   DALI_TEST_CHECK(value);
2240   DALI_TEST_EQUALS(value->Get<Vector2>(), Vector2(700, 700), TEST_LOCATION); // Change the internal size according to the image view size
2241
2242   value = map->Find(Toolkit::Visual::Transform::Property::SIZE_POLICY);
2243   DALI_TEST_CHECK(value);
2244   DALI_TEST_EQUALS(value->Get<Vector2>(), Vector2(Toolkit::Visual::Transform::Policy::ABSOLUTE, Toolkit::Visual::Transform::Policy::ABSOLUTE), TEST_LOCATION);
2245
2246   value = map->Find(Toolkit::Visual::Transform::Property::OFFSET);
2247   DALI_TEST_CHECK(value);
2248   DALI_TEST_EQUALS(value->Get<Vector2>(), Vector2(50, 0), TEST_LOCATION);
2249
2250   // 2. Render again using DevelVisaul::CENTER
2251   Property::Map imageMap2;
2252   imageMap2[Toolkit::Visual::Property::TYPE]            = Toolkit::Visual::IMAGE;
2253   imageMap2[Toolkit::ImageVisual::Property::URL]        = gImage_600_RGB;
2254   imageMap2[DevelVisual::Property::VISUAL_FITTING_MODE] = Toolkit::DevelVisual::CENTER;
2255
2256   imageView.SetProperty(Toolkit::ImageView::Property::IMAGE, imageMap2);
2257   imageView.SetProperty(Actor::Property::SIZE, Vector2(800, 700));
2258
2259   application.GetScene().Add(imageView);
2260
2261   DALI_TEST_EQUALS(Test::WaitForEventThreadTrigger(1), true, TEST_LOCATION);
2262
2263   // Trigger a potential relayout
2264   application.SendNotification();
2265   application.Render();
2266
2267   returnedMap.Clear();
2268   visual = DevelControl::GetVisual(Toolkit::Internal::GetImplementation(imageView), Toolkit::ImageView::Property::IMAGE);
2269
2270   visual.CreatePropertyMap(returnedMap);
2271
2272   value = returnedMap.Find(Toolkit::Visual::Property::TRANSFORM);
2273   DALI_TEST_CHECK(value);
2274   map = value->GetMap();
2275   DALI_TEST_CHECK(map);
2276
2277   value = map->Find(Toolkit::Visual::Transform::Property::SIZE);
2278   DALI_TEST_CHECK(value);
2279   DALI_TEST_EQUALS(value->Get<Vector2>(), Vector2(600, 600), TEST_LOCATION); // Change the internal size according to the image view size
2280
2281   value = map->Find(Toolkit::Visual::Transform::Property::SIZE_POLICY);
2282   DALI_TEST_CHECK(value);
2283   DALI_TEST_EQUALS(value->Get<Vector2>(), Vector2(Toolkit::Visual::Transform::Policy::ABSOLUTE, Toolkit::Visual::Transform::Policy::ABSOLUTE), TEST_LOCATION);
2284
2285   value = map->Find(Toolkit::Visual::Transform::Property::OFFSET);
2286   DALI_TEST_CHECK(value);
2287   DALI_TEST_EQUALS(value->Get<Vector2>(), Vector2(100, 50), TEST_LOCATION);
2288
2289   // 3. Render again using before fittingMode
2290   Property::Map imageMap3;
2291   imageMap3[Toolkit::Visual::Property::TYPE]            = Toolkit::Visual::IMAGE;
2292   imageMap3[Toolkit::ImageVisual::Property::URL]        = gImage_600_RGB;
2293   imageMap3[DevelVisual::Property::VISUAL_FITTING_MODE] = Toolkit::DevelVisual::FIT_KEEP_ASPECT_RATIO;
2294
2295   imageView.SetProperty(Toolkit::ImageView::Property::IMAGE, imageMap3);
2296   imageView.SetProperty(Actor::Property::SIZE, Vector2(800, 700));
2297
2298   application.GetScene().Add(imageView);
2299
2300   // Trigger a potential relayout
2301   application.SendNotification();
2302   application.Render();
2303
2304   returnedMap.Clear();
2305   visual = DevelControl::GetVisual(Toolkit::Internal::GetImplementation(imageView), Toolkit::ImageView::Property::IMAGE);
2306   visual.CreatePropertyMap(returnedMap);
2307
2308   value = returnedMap.Find(Toolkit::Visual::Property::TRANSFORM);
2309   DALI_TEST_CHECK(value);
2310   map = value->GetMap();
2311   DALI_TEST_CHECK(map);
2312
2313   value = map->Find(Toolkit::Visual::Transform::Property::SIZE);
2314   DALI_TEST_CHECK(value);
2315   DALI_TEST_EQUALS(value->Get<Vector2>(), Vector2(700, 700), TEST_LOCATION); // Change the internal size according to the image view size
2316
2317   value = map->Find(Toolkit::Visual::Transform::Property::SIZE_POLICY);
2318   DALI_TEST_CHECK(value);
2319   DALI_TEST_EQUALS(value->Get<Vector2>(), Vector2(Toolkit::Visual::Transform::Policy::ABSOLUTE, Toolkit::Visual::Transform::Policy::ABSOLUTE), TEST_LOCATION);
2320
2321   value = map->Find(Toolkit::Visual::Transform::Property::OFFSET);
2322   DALI_TEST_CHECK(value);
2323   DALI_TEST_EQUALS(value->Get<Vector2>(), Vector2(50, 0), TEST_LOCATION);
2324
2325   END_TEST;
2326 }
2327
2328 int UtcDaliImageViewFittingModesChangeFittingMode02(void)
2329 {
2330   ToolkitTestApplication application;
2331
2332   tet_infoline("UtcDaliImageViewFittingModesChangeFittingMode, image: [600,600], view:[800,700]");
2333
2334   ImageView imageView = ImageView::New();
2335
2336   // 1. Render using FittingMode::OVER_FIT_KEEP_ASPECT_RATIO
2337   Property::Map imageMap;
2338   imageMap[Toolkit::Visual::Property::TYPE]            = Toolkit::Visual::IMAGE;
2339   imageMap[Toolkit::ImageVisual::Property::URL]        = gImage_600_RGB;
2340   imageMap[DevelVisual::Property::VISUAL_FITTING_MODE] = Toolkit::DevelVisual::OVER_FIT_KEEP_ASPECT_RATIO;
2341
2342   imageView.SetProperty(Toolkit::ImageView::Property::IMAGE, imageMap);
2343   imageView.SetProperty(Actor::Property::SIZE, Vector2(800, 700));
2344
2345   application.GetScene().Add(imageView);
2346
2347   // Trigger a potential relayout
2348   application.SendNotification();
2349   application.Render();
2350
2351   Toolkit::Visual::Base visual = DevelControl::GetVisual(Toolkit::Internal::GetImplementation(imageView), Toolkit::ImageView::Property::IMAGE);
2352   Property::Map         returnedMap;
2353   visual.CreatePropertyMap(returnedMap);
2354
2355   Property::Value* value = returnedMap.Find(Toolkit::Visual::Property::TRANSFORM);
2356   DALI_TEST_CHECK(value);
2357   Property::Map* map = value->GetMap();
2358   DALI_TEST_CHECK(map);
2359
2360   value = map->Find(Toolkit::Visual::Transform::Property::SIZE);
2361   DALI_TEST_CHECK(value);
2362   DALI_TEST_EQUALS(value->Get<Vector2>(), Vector2(800, 700), TEST_LOCATION); // Change the internal size according to the image view size
2363
2364   value = map->Find(Toolkit::Visual::Transform::Property::SIZE_POLICY);
2365   DALI_TEST_CHECK(value);
2366   DALI_TEST_EQUALS(value->Get<Vector2>(), Vector2(Toolkit::Visual::Transform::Policy::ABSOLUTE, Toolkit::Visual::Transform::Policy::ABSOLUTE), TEST_LOCATION);
2367
2368   value = map->Find(Toolkit::Visual::Transform::Property::OFFSET);
2369   DALI_TEST_CHECK(value);
2370   DALI_TEST_EQUALS(value->Get<Vector2>(), Vector2(0, 0), TEST_LOCATION);
2371
2372   // 2. Render again using DevelVisaul::CENTER
2373   Property::Map imageMap2;
2374   imageMap2[Toolkit::Visual::Property::TYPE]            = Toolkit::Visual::IMAGE;
2375   imageMap2[Toolkit::ImageVisual::Property::URL]        = gImage_600_RGB;
2376   imageMap2[DevelVisual::Property::VISUAL_FITTING_MODE] = Toolkit::DevelVisual::CENTER;
2377
2378   imageView.SetProperty(Toolkit::ImageView::Property::IMAGE, imageMap2);
2379   imageView.SetProperty(Actor::Property::SIZE, Vector2(800, 700));
2380
2381   application.GetScene().Add(imageView);
2382
2383   DALI_TEST_EQUALS(Test::WaitForEventThreadTrigger(1), true, TEST_LOCATION);
2384
2385   // Trigger a potential relayout
2386   application.SendNotification();
2387   application.Render();
2388
2389   returnedMap.Clear();
2390   visual = DevelControl::GetVisual(Toolkit::Internal::GetImplementation(imageView), Toolkit::ImageView::Property::IMAGE);
2391
2392   visual.CreatePropertyMap(returnedMap);
2393
2394   value = returnedMap.Find(Toolkit::Visual::Property::TRANSFORM);
2395   DALI_TEST_CHECK(value);
2396   map = value->GetMap();
2397   DALI_TEST_CHECK(map);
2398
2399   value = map->Find(Toolkit::Visual::Transform::Property::SIZE);
2400   DALI_TEST_CHECK(value);
2401   DALI_TEST_EQUALS(value->Get<Vector2>(), Vector2(600, 600), TEST_LOCATION); // Change the internal size according to the image view size
2402
2403   value = map->Find(Toolkit::Visual::Transform::Property::SIZE_POLICY);
2404   DALI_TEST_CHECK(value);
2405   DALI_TEST_EQUALS(value->Get<Vector2>(), Vector2(Toolkit::Visual::Transform::Policy::ABSOLUTE, Toolkit::Visual::Transform::Policy::ABSOLUTE), TEST_LOCATION);
2406
2407   value = map->Find(Toolkit::Visual::Transform::Property::OFFSET);
2408   DALI_TEST_CHECK(value);
2409   DALI_TEST_EQUALS(value->Get<Vector2>(), Vector2(100, 50), TEST_LOCATION);
2410
2411   // 3. Render again using before fittingMode
2412   Property::Map imageMap3;
2413   imageMap3[Toolkit::Visual::Property::TYPE]            = Toolkit::Visual::IMAGE;
2414   imageMap3[Toolkit::ImageVisual::Property::URL]        = gImage_600_RGB;
2415   imageMap3[DevelVisual::Property::VISUAL_FITTING_MODE] = Toolkit::DevelVisual::OVER_FIT_KEEP_ASPECT_RATIO;
2416
2417   imageView.SetProperty(Toolkit::ImageView::Property::IMAGE, imageMap3);
2418   imageView.SetProperty(Actor::Property::SIZE, Vector2(800, 700));
2419
2420   application.GetScene().Add(imageView);
2421
2422   // Trigger a potential relayout
2423   application.SendNotification();
2424   application.Render();
2425
2426   returnedMap.Clear();
2427   visual = DevelControl::GetVisual(Toolkit::Internal::GetImplementation(imageView), Toolkit::ImageView::Property::IMAGE);
2428   visual.CreatePropertyMap(returnedMap);
2429
2430   value = returnedMap.Find(Toolkit::Visual::Property::TRANSFORM);
2431   DALI_TEST_CHECK(value);
2432   map = value->GetMap();
2433   DALI_TEST_CHECK(map);
2434
2435   value = map->Find(Toolkit::Visual::Transform::Property::SIZE);
2436   DALI_TEST_CHECK(value);
2437   DALI_TEST_EQUALS(value->Get<Vector2>(), Vector2(800, 700), TEST_LOCATION); // Change the internal size according to the image view size
2438
2439   value = map->Find(Toolkit::Visual::Transform::Property::SIZE_POLICY);
2440   DALI_TEST_CHECK(value);
2441   DALI_TEST_EQUALS(value->Get<Vector2>(), Vector2(Toolkit::Visual::Transform::Policy::ABSOLUTE, Toolkit::Visual::Transform::Policy::ABSOLUTE), TEST_LOCATION);
2442
2443   value = map->Find(Toolkit::Visual::Transform::Property::OFFSET);
2444   DALI_TEST_CHECK(value);
2445   DALI_TEST_EQUALS(value->Get<Vector2>(), Vector2(0, 0), TEST_LOCATION);
2446
2447   END_TEST;
2448 }
2449
2450 int UtcDaliImageViewFittingModesWithAnimatedVectorImageVisual(void)
2451 {
2452   ToolkitTestApplication application;
2453
2454   tet_infoline("Create an ImageVisual using SCALE_TO_FILL and animated vector image ( image: [600,600], view:[600,600] )");
2455
2456   ImageView     imageView = ImageView::New();
2457   Property::Map imageMap;
2458   imageMap.Add(Toolkit::Visual::Property::TYPE, DevelVisual::ANIMATED_VECTOR_IMAGE);
2459   imageMap.Add(Toolkit::ImageVisual::Property::URL, TEST_ANIMATED_VECTOR_IMAGE_FILE_NAME); // 249x169 image
2460
2461   imageView.SetProperty(Toolkit::ImageView::Property::IMAGE, imageMap);
2462   imageView.SetProperty(Actor::Property::SIZE, Vector2(600, 600));
2463
2464   application.GetScene().Add(imageView);
2465
2466   // Trigger a potential relayout
2467   application.SendNotification();
2468   application.Render();
2469
2470   Toolkit::Visual::Base visual = DevelControl::GetVisual(Toolkit::Internal::GetImplementation(imageView), Toolkit::ImageView::Property::IMAGE);
2471   Property::Map         returnedMap;
2472   visual.CreatePropertyMap(returnedMap);
2473
2474   Property::Value* value = returnedMap.Find(Toolkit::Visual::Property::TRANSFORM);
2475   DALI_TEST_CHECK(value);
2476   Property::Map* map = value->GetMap();
2477   DALI_TEST_CHECK(map);
2478
2479   value = map->Find(Toolkit::Visual::Transform::Property::SIZE);
2480   DALI_TEST_CHECK(value);
2481   DALI_TEST_EQUALS(value->Get<Vector2>(), Vector2::ONE, TEST_LOCATION); // Relative size so will take up 100%
2482
2483   value = map->Find(Toolkit::Visual::Transform::Property::SIZE_POLICY);
2484   DALI_TEST_CHECK(value);
2485   DALI_TEST_CHECK(value->Get<int>() == Toolkit::Visual::Transform::Policy::RELATIVE);
2486
2487   value = map->Find(Toolkit::Visual::Transform::Property::OFFSET);
2488   DALI_TEST_CHECK(value);
2489   DALI_TEST_EQUALS(value->Get<Vector2>(), Vector2(0, 0), TEST_LOCATION); // OFFSET is zero
2490
2491   END_TEST;
2492 }
2493
2494 int UtcDaliImageViewCustomShader(void)
2495 {
2496   ToolkitTestApplication application;
2497
2498   // Set a custom shader with an image url
2499   {
2500     Property::Map     properties;
2501     Property::Map     shader;
2502     const std::string vertexShader                    = "Foobar";
2503     const std::string fragmentShader                  = "Foobar";
2504     shader[Visual::Shader::Property::FRAGMENT_SHADER] = fragmentShader;
2505     shader[Visual::Shader::Property::VERTEX_SHADER]   = vertexShader;
2506
2507     properties[Visual::Property::TYPE]     = Visual::IMAGE;
2508     properties[Visual::Property::SHADER]   = shader;
2509     properties[ImageVisual::Property::URL] = TEST_IMAGE_FILE_NAME;
2510
2511     ImageView imageView = ImageView::New();
2512     imageView.SetProperty(ImageView::Property::IMAGE, properties);
2513
2514     application.GetScene().Add(imageView);
2515
2516     application.SendNotification();
2517     application.Render();
2518
2519     DALI_TEST_EQUALS(Test::WaitForEventThreadTrigger(1), true, TEST_LOCATION);
2520
2521     Renderer        renderer = imageView.GetRendererAt(0);
2522     Shader          shader2  = renderer.GetShader();
2523     Property::Value value    = shader2.GetProperty(Shader::Property::PROGRAM);
2524     Property::Map*  map      = value.GetMap();
2525     DALI_TEST_CHECK(map);
2526
2527     Property::Value* fragment = map->Find("fragment"); // fragment key name from shader-impl.cpp
2528     DALI_TEST_EQUALS(fragmentShader, fragment->Get<std::string>(), TEST_LOCATION);
2529
2530     Property::Value* vertex = map->Find("vertex"); // vertex key name from shader-impl.cpp
2531     DALI_TEST_EQUALS(vertexShader, vertex->Get<std::string>(), TEST_LOCATION);
2532   }
2533
2534   // Set a custom shader after setting an image url
2535   {
2536     Property::Map     properties;
2537     Property::Map     shader;
2538     const std::string vertexShader                    = "Foobar";
2539     const std::string fragmentShader                  = "Foobar";
2540     shader[Visual::Shader::Property::FRAGMENT_SHADER] = fragmentShader;
2541     shader[Visual::Shader::Property::VERTEX_SHADER]   = vertexShader;
2542
2543     properties[Visual::Property::SHADER] = shader;
2544
2545     ImageView imageView = ImageView::New(TEST_IMAGE_FILE_NAME);
2546     imageView.SetProperty(ImageView::Property::IMAGE, properties);
2547
2548     application.GetScene().Add(imageView);
2549
2550     application.SendNotification();
2551     application.Render();
2552
2553     DALI_TEST_EQUALS(Test::WaitForEventThreadTrigger(1), true, TEST_LOCATION);
2554
2555     Renderer        renderer = imageView.GetRendererAt(0);
2556     Shader          shader2  = renderer.GetShader();
2557     Property::Value value    = shader2.GetProperty(Shader::Property::PROGRAM);
2558     Property::Map*  map      = value.GetMap();
2559     DALI_TEST_CHECK(map);
2560
2561     Property::Value* fragment = map->Find("fragment"); // fragment key name from shader-impl.cpp
2562     DALI_TEST_EQUALS(fragmentShader, fragment->Get<std::string>(), TEST_LOCATION);
2563
2564     Property::Value* vertex = map->Find("vertex"); // vertex key name from shader-impl.cpp
2565     DALI_TEST_EQUALS(vertexShader, vertex->Get<std::string>(), TEST_LOCATION);
2566   }
2567
2568   // Set a custom shader before setting an image url
2569   {
2570     Property::Map     properties;
2571     Property::Map     shader;
2572     const std::string vertexShader                    = "Foobar";
2573     const std::string fragmentShader                  = "Foobar";
2574     shader[Visual::Shader::Property::FRAGMENT_SHADER] = fragmentShader;
2575     shader[Visual::Shader::Property::VERTEX_SHADER]   = vertexShader;
2576
2577     properties[Visual::Property::SHADER] = shader;
2578
2579     ImageView imageView = ImageView::New();
2580     imageView.SetProperty(ImageView::Property::IMAGE, properties);
2581     imageView.SetProperty(ImageView::Property::IMAGE, TEST_IMAGE_FILE_NAME);
2582
2583     application.GetScene().Add(imageView);
2584
2585     application.SendNotification();
2586     application.Render();
2587     DALI_TEST_EQUALS(Test::WaitForEventThreadTrigger(1), true, TEST_LOCATION);
2588
2589     Renderer        renderer = imageView.GetRendererAt(0);
2590     Shader          shader2  = renderer.GetShader();
2591     Property::Value value    = shader2.GetProperty(Shader::Property::PROGRAM);
2592     Property::Map*  map      = value.GetMap();
2593     DALI_TEST_CHECK(map);
2594
2595     Property::Value* fragment = map->Find("fragment"); // fragment key name from shader-impl.cpp
2596     DALI_TEST_EQUALS(fragmentShader, fragment->Get<std::string>(), TEST_LOCATION);
2597
2598     Property::Value* vertex = map->Find("vertex"); // vertex key name from shader-impl.cpp
2599     DALI_TEST_EQUALS(vertexShader, vertex->Get<std::string>(), TEST_LOCATION);
2600   }
2601
2602   // Set a custom shader after setting a property map
2603   {
2604     Property::Map     properties;
2605     Property::Map     shader;
2606     const std::string vertexShader                    = "Foobar";
2607     const std::string fragmentShader                  = "Foobar";
2608     shader[Visual::Shader::Property::FRAGMENT_SHADER] = fragmentShader;
2609     shader[Visual::Shader::Property::VERTEX_SHADER]   = vertexShader;
2610
2611     properties[Visual::Property::SHADER] = shader;
2612
2613     Property::Map properties1;
2614     properties1[Visual::Property::TYPE]     = Visual::IMAGE;
2615     properties1[ImageVisual::Property::URL] = TEST_IMAGE_FILE_NAME;
2616
2617     ImageView imageView = ImageView::New();
2618     imageView.SetProperty(ImageView::Property::IMAGE, properties1);
2619     imageView.SetProperty(ImageView::Property::IMAGE, properties);
2620
2621     application.GetScene().Add(imageView);
2622
2623     application.SendNotification();
2624     application.Render();
2625     DALI_TEST_EQUALS(Test::WaitForEventThreadTrigger(1), true, TEST_LOCATION);
2626
2627     Renderer        renderer = imageView.GetRendererAt(0);
2628     Shader          shader2  = renderer.GetShader();
2629     Property::Value value    = shader2.GetProperty(Shader::Property::PROGRAM);
2630     Property::Map*  map      = value.GetMap();
2631     DALI_TEST_CHECK(map);
2632
2633     Property::Value* fragment = map->Find("fragment"); // fragment key name from shader-impl.cpp
2634     DALI_TEST_EQUALS(fragmentShader, fragment->Get<std::string>(), TEST_LOCATION);
2635
2636     Property::Value* vertex = map->Find("vertex"); // vertex key name from shader-impl.cpp
2637     DALI_TEST_EQUALS(vertexShader, vertex->Get<std::string>(), TEST_LOCATION);
2638   }
2639
2640   // Set a custom shader before setting a property map
2641   {
2642     Property::Map     properties;
2643     Property::Map     shader;
2644     const std::string vertexShader                    = "Foobar";
2645     const std::string fragmentShader                  = "Foobar";
2646     shader[Visual::Shader::Property::FRAGMENT_SHADER] = fragmentShader;
2647     shader[Visual::Shader::Property::VERTEX_SHADER]   = vertexShader;
2648
2649     properties[Visual::Property::SHADER] = shader;
2650
2651     Property::Map properties1;
2652     properties1[Visual::Property::TYPE]     = Visual::IMAGE;
2653     properties1[ImageVisual::Property::URL] = TEST_IMAGE_FILE_NAME;
2654
2655     ImageView imageView = ImageView::New();
2656     imageView.SetProperty(ImageView::Property::IMAGE, properties);
2657     imageView.SetProperty(ImageView::Property::IMAGE, properties1);
2658
2659     application.GetScene().Add(imageView);
2660
2661     application.SendNotification();
2662     application.Render();
2663     DALI_TEST_EQUALS(Test::WaitForEventThreadTrigger(1), true, TEST_LOCATION);
2664
2665     Renderer        renderer = imageView.GetRendererAt(0);
2666     Shader          shader2  = renderer.GetShader();
2667     Property::Value value    = shader2.GetProperty(Shader::Property::PROGRAM);
2668     Property::Map*  map      = value.GetMap();
2669     DALI_TEST_CHECK(map);
2670
2671     Property::Value* fragment = map->Find("fragment"); // fragment key name from shader-impl.cpp
2672     DALI_TEST_EQUALS(fragmentShader, fragment->Get<std::string>(), TEST_LOCATION);
2673
2674     Property::Value* vertex = map->Find("vertex"); // vertex key name from shader-impl.cpp
2675     DALI_TEST_EQUALS(vertexShader, vertex->Get<std::string>(), TEST_LOCATION);
2676   }
2677
2678   END_TEST;
2679 }
2680
2681 namespace
2682 {
2683 static int gFailCounter = 0;
2684 const int  MAX_RETRIES(3);
2685
2686 void ReloadImage(ImageView imageView)
2687 {
2688   Property::Map imageImmediateLoadingMap;
2689   imageImmediateLoadingMap[ImageVisual::Property::URL]         = "Non-existant-image.jpg";
2690   imageImmediateLoadingMap[ImageVisual::Property::LOAD_POLICY] = ImageVisual::LoadPolicy::IMMEDIATE;
2691
2692   tet_infoline("Immediate load an image");
2693   imageView.SetProperty(ImageView::Property::IMAGE, imageImmediateLoadingMap);
2694 }
2695
2696 void ResourceFailedReload(Control control)
2697 {
2698   gFailCounter++;
2699 }
2700 } // namespace
2701
2702 int UtcDaliImageViewReloadFailedOnResourceReadySignal(void)
2703 {
2704   tet_infoline("Test reloading failed image from within signal handler.");
2705
2706   ToolkitTestApplication application;
2707
2708   gFailCounter = 0;
2709
2710   ImageView imageView = ImageView::New();
2711   imageView.ResourceReadySignal().Connect(&ResourceFailedReload);
2712   DALI_TEST_EQUALS(gFailCounter, 0, TEST_LOCATION);
2713   ReloadImage(imageView);
2714
2715   // loading started, this waits for the loader thread to complete
2716   DALI_TEST_EQUALS(Test::WaitForEventThreadTrigger(1), true, TEST_LOCATION);
2717   DALI_TEST_EQUALS(gFailCounter, 1, TEST_LOCATION);
2718
2719   ReloadImage(imageView);
2720   DALI_TEST_EQUALS(Test::WaitForEventThreadTrigger(1), true, TEST_LOCATION);
2721   DALI_TEST_EQUALS(gFailCounter, 2, TEST_LOCATION);
2722
2723   ReloadImage(imageView);
2724   DALI_TEST_EQUALS(Test::WaitForEventThreadTrigger(1), true, TEST_LOCATION);
2725   DALI_TEST_EQUALS(gFailCounter, 3, TEST_LOCATION);
2726
2727   END_TEST;
2728 }
2729
2730 int UtcDaliImageViewLoadRemoteSVG(void)
2731 {
2732   tet_infoline("Test load from a remote server.");
2733
2734   ToolkitTestApplication application;
2735
2736   {
2737     Toolkit::ImageView imageView;
2738     imageView = Toolkit::ImageView::New();
2739     imageView.SetImage("https://dev.w3.org/SVG/tools/svgweb/samples/svg-files/check.svg");
2740     imageView.SetProperty(Actor::Property::PARENT_ORIGIN, ParentOrigin::TOP_LEFT);
2741     imageView.SetProperty(Actor::Property::ANCHOR_POINT, AnchorPoint::TOP_LEFT);
2742     imageView.SetProperty(Actor::Property::SIZE, Vector2(300, 300));
2743     imageView.SetProperty(Actor::Property::POSITION, Vector3(150.0f, 150.0f, 0.0f));
2744
2745     application.GetScene().Add(imageView);
2746
2747     DALI_TEST_CHECK(imageView);
2748
2749     DALI_TEST_EQUALS(imageView.GetRendererCount(), 0u, TEST_LOCATION);
2750
2751     application.SendNotification();
2752
2753     // Wait for loading & rasterization
2754     DALI_TEST_EQUALS(Test::WaitForEventThreadTrigger(2), true, TEST_LOCATION);
2755
2756     application.SendNotification();
2757     application.Render();
2758
2759     DALI_TEST_EQUALS(imageView.GetRendererCount(), 1u, TEST_LOCATION);
2760   }
2761
2762   // Without size set
2763   {
2764     Toolkit::ImageView imageView;
2765     imageView = Toolkit::ImageView::New();
2766     imageView.SetImage("https://dev.w3.org/SVG/tools/svgweb/samples/svg-files/check.svg");
2767     imageView.SetProperty(Actor::Property::PARENT_ORIGIN, ParentOrigin::TOP_LEFT);
2768     imageView.SetProperty(Actor::Property::ANCHOR_POINT, AnchorPoint::TOP_LEFT);
2769     imageView.SetProperty(Actor::Property::POSITION, Vector3(150.0f, 150.0f, 0.0f));
2770
2771     application.GetScene().Add(imageView);
2772
2773     DALI_TEST_CHECK(imageView);
2774
2775     DALI_TEST_EQUALS(imageView.GetRendererCount(), 0u, TEST_LOCATION);
2776
2777     application.SendNotification();
2778
2779     // Wait for loading & rasterization
2780     DALI_TEST_EQUALS(Test::WaitForEventThreadTrigger(2), true, TEST_LOCATION);
2781
2782     application.SendNotification();
2783     application.Render();
2784
2785     DALI_TEST_EQUALS(imageView.GetRendererCount(), 1u, TEST_LOCATION);
2786   }
2787
2788   END_TEST;
2789 }
2790
2791 int UtcDaliImageViewSyncSVGLoading(void)
2792 {
2793   ToolkitTestApplication application;
2794
2795   tet_infoline("ImageView Testing SVG image sync loading");
2796
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     syncLoadingMap.Insert(Toolkit::ImageVisual::Property::SYNCHRONOUS_LOADING, true);
2805     imageView.SetProperty(ImageView::Property::IMAGE, syncLoadingMap);
2806
2807     application.GetScene().Add(imageView);
2808     DALI_TEST_CHECK(imageView);
2809
2810     application.SendNotification();
2811     Vector3 naturalSize = imageView.GetNaturalSize();
2812
2813     DALI_TEST_EQUALS(naturalSize.width, 100.0f, TEST_LOCATION);
2814     DALI_TEST_EQUALS(naturalSize.height, 100.0f, TEST_LOCATION);
2815   }
2816   END_TEST;
2817 }
2818
2819 int UtcDaliImageViewAsyncSVGLoading(void)
2820 {
2821   ToolkitTestApplication application;
2822
2823   tet_infoline("ImageView Testing SVG image async loading");
2824
2825   {
2826     ImageView imageView = ImageView::New();
2827
2828     // Async loading is used - default value of SYNCHRONOUS_LOADING is false.
2829     Property::Map propertyMap;
2830     propertyMap.Insert(Toolkit::Visual::Property::TYPE, Toolkit::Visual::IMAGE);
2831     propertyMap.Insert(Toolkit::ImageVisual::Property::URL, TEST_RESOURCE_DIR "/svg1.svg");
2832     imageView.SetProperty(ImageView::Property::IMAGE, propertyMap);
2833
2834     application.GetScene().Add(imageView);
2835     DALI_TEST_CHECK(imageView);
2836
2837     application.SendNotification();
2838
2839     // Wait for loading
2840     DALI_TEST_EQUALS(Test::WaitForEventThreadTrigger(1), true, TEST_LOCATION);
2841
2842     application.SendNotification();
2843     application.Render(16);
2844
2845     Vector3 naturalSize = imageView.GetNaturalSize();
2846     DALI_TEST_EQUALS(naturalSize.width, 100.0f, TEST_LOCATION);
2847     DALI_TEST_EQUALS(naturalSize.height, 100.0f, TEST_LOCATION);
2848   }
2849   END_TEST;
2850 }
2851
2852 int UtcDaliImageViewSVGLoadingSyncSetInvalidValue(void)
2853 {
2854   ToolkitTestApplication application;
2855
2856   tet_infoline("ImageView Testing SVG image async loading");
2857
2858   // Sync loading
2859   {
2860     ImageView imageView = ImageView::New();
2861
2862     // Sync loading is used
2863     Property::Map syncLoadingMap;
2864     syncLoadingMap.Insert(Toolkit::Visual::Property::TYPE, Toolkit::Visual::IMAGE);
2865     syncLoadingMap.Insert(Toolkit::ImageVisual::Property::URL, TEST_RESOURCE_DIR "/svg1.svg");
2866
2867     // Check to set invalid value
2868     // The SYNCHRONOUS_LOADING property must be set to the bool value.
2869     // Check if error log is outputted when setting other value like string.
2870     // Even if the wrong value is set, the image will be shown normally, and the synchronous value should be the default value(false).
2871     syncLoadingMap.Insert(Toolkit::ImageVisual::Property::SYNCHRONOUS_LOADING, std::to_string(5));
2872     imageView.SetProperty(ImageView::Property::IMAGE, syncLoadingMap);
2873
2874     application.GetScene().Add(imageView);
2875     DALI_TEST_CHECK(imageView);
2876
2877     application.SendNotification();
2878
2879     // Wait for loading
2880     DALI_TEST_EQUALS(Test::WaitForEventThreadTrigger(1), true, TEST_LOCATION);
2881
2882     application.SendNotification();
2883     application.Render(16);
2884
2885     Vector3 naturalSize = imageView.GetNaturalSize();
2886     DALI_TEST_EQUALS(naturalSize.width, 100.0f, TEST_LOCATION);
2887     DALI_TEST_EQUALS(naturalSize.height, 100.0f, TEST_LOCATION);
2888
2889     Property::Value value = imageView.GetProperty(ImageView::Property::IMAGE);
2890     Property::Map*  map   = value.GetMap();
2891     DALI_TEST_CHECK(map);
2892
2893     Property::Value* sync = map->Find(Toolkit::ImageVisual::Property::SYNCHRONOUS_LOADING);
2894     DALI_TEST_CHECK(sync);
2895     DALI_TEST_EQUALS(false, sync->Get<bool>(), TEST_LOCATION);
2896   }
2897   END_TEST;
2898 }
2899
2900 int UtcDaliImageViewSvgLoadingFailureLocalFile(void)
2901 {
2902   // Local svg file - invalid file path
2903   {
2904     ToolkitTestApplication application;
2905
2906     TestGlAbstraction& gl           = application.GetGlAbstraction();
2907     TraceCallStack&    textureTrace = gl.GetTextureTrace();
2908     textureTrace.Enable(true);
2909
2910     gResourceReadySignalFired = false;
2911
2912     ImageView imageView = ImageView::New(TEST_RESOURCE_DIR "/foo.svg");
2913     imageView.SetProperty(Actor::Property::SIZE, Vector2(200.f, 200.f));
2914     imageView.ResourceReadySignal().Connect(&ResourceReadySignal);
2915
2916     DALI_TEST_EQUALS(imageView.IsResourceReady(), false, TEST_LOCATION);
2917
2918     application.GetScene().Add(imageView);
2919
2920     application.SendNotification();
2921
2922     // loading started, this waits for the loader thread - load
2923     DALI_TEST_EQUALS(Test::WaitForEventThreadTrigger(1), true, TEST_LOCATION);
2924
2925     application.SendNotification();
2926     application.Render(16);
2927
2928     DALI_TEST_EQUALS(gResourceReadySignalFired, true, TEST_LOCATION);
2929     DALI_TEST_EQUALS(imageView.IsResourceReady(), true, TEST_LOCATION);
2930     DALI_TEST_EQUALS(imageView.GetVisualResourceStatus(ImageView::Property::IMAGE), Visual::ResourceStatus::FAILED, TEST_LOCATION);
2931
2932     // Should be shown a broken image
2933     DALI_TEST_EQUALS(imageView.GetRendererCount(), 1u, TEST_LOCATION);
2934     DALI_TEST_EQUALS(textureTrace.FindMethod("BindTexture"), true, TEST_LOCATION);
2935   }
2936
2937   // Local svg file - invalid file path without size set
2938   {
2939     ToolkitTestApplication application;
2940
2941     TestGlAbstraction& gl           = application.GetGlAbstraction();
2942     TraceCallStack&    textureTrace = gl.GetTextureTrace();
2943     textureTrace.Enable(true);
2944
2945     gResourceReadySignalFired = false;
2946     textureTrace.Reset();
2947
2948     ImageView imageView = ImageView::New(TEST_RESOURCE_DIR "/foo.svg");
2949     imageView.ResourceReadySignal().Connect(&ResourceReadySignal);
2950
2951     DALI_TEST_EQUALS(imageView.IsResourceReady(), false, TEST_LOCATION);
2952
2953     application.GetScene().Add(imageView);
2954
2955     application.SendNotification();
2956
2957     // loading started, this waits for the loader thread - load & rasterize
2958     DALI_TEST_EQUALS(Test::WaitForEventThreadTrigger(1), true, TEST_LOCATION);
2959
2960     application.SendNotification();
2961     application.Render(16);
2962
2963     DALI_TEST_EQUALS(gResourceReadySignalFired, true, TEST_LOCATION);
2964     DALI_TEST_EQUALS(imageView.IsResourceReady(), true, TEST_LOCATION);
2965     DALI_TEST_EQUALS(imageView.GetVisualResourceStatus(ImageView::Property::IMAGE), Visual::ResourceStatus::FAILED, TEST_LOCATION);
2966
2967     // Should be shown a broken image
2968     DALI_TEST_EQUALS(imageView.GetRendererCount(), 1u, TEST_LOCATION);
2969     DALI_TEST_EQUALS(textureTrace.FindMethod("BindTexture"), true, TEST_LOCATION);
2970   }
2971
2972   // Local svg file - invalid file
2973   {
2974     ToolkitTestApplication application;
2975
2976     TestGlAbstraction& gl           = application.GetGlAbstraction();
2977     TraceCallStack&    textureTrace = gl.GetTextureTrace();
2978     textureTrace.Enable(true);
2979
2980     gResourceReadySignalFired = false;
2981     textureTrace.Reset();
2982
2983     ImageView imageView = ImageView::New(TEST_RESOURCE_DIR "/invalid.svg");
2984     imageView.SetProperty(Actor::Property::SIZE, Vector2(200.f, 200.f));
2985     imageView.ResourceReadySignal().Connect(&ResourceReadySignal);
2986
2987     DALI_TEST_EQUALS(imageView.IsResourceReady(), false, TEST_LOCATION);
2988
2989     application.GetScene().Add(imageView);
2990
2991     application.SendNotification();
2992
2993     // loading started, this waits for the loader thread - load & rasterize
2994     DALI_TEST_EQUALS(Test::WaitForEventThreadTrigger(1), true, TEST_LOCATION);
2995
2996     application.SendNotification();
2997     application.Render(16);
2998
2999     DALI_TEST_EQUALS(gResourceReadySignalFired, true, TEST_LOCATION);
3000     DALI_TEST_EQUALS(imageView.IsResourceReady(), true, TEST_LOCATION);
3001     DALI_TEST_EQUALS(imageView.GetVisualResourceStatus(ImageView::Property::IMAGE), Visual::ResourceStatus::FAILED, TEST_LOCATION);
3002
3003     // Should be shown a broken image
3004     DALI_TEST_EQUALS(imageView.GetRendererCount(), 1u, TEST_LOCATION);
3005     DALI_TEST_EQUALS(textureTrace.FindMethod("BindTexture"), true, TEST_LOCATION);
3006   }
3007
3008   END_TEST;
3009 }
3010
3011 int UtcDaliImageViewSvgLoadingFailureRemoteFile01(void)
3012 {
3013   // Remote svg file
3014   {
3015     ToolkitTestApplication application;
3016
3017     TestGlAbstraction& gl           = application.GetGlAbstraction();
3018     TraceCallStack&    textureTrace = gl.GetTextureTrace();
3019     textureTrace.Enable(true);
3020
3021     gResourceReadySignalFired = false;
3022
3023     ImageView imageView = ImageView::New("https://127.0.0.1/foobar.svg");
3024     imageView.SetProperty(Actor::Property::SIZE, Vector2(200.f, 200.f));
3025     imageView.ResourceReadySignal().Connect(&ResourceReadySignal);
3026
3027     DALI_TEST_EQUALS(imageView.IsResourceReady(), false, TEST_LOCATION);
3028
3029     application.GetScene().Add(imageView);
3030
3031     application.SendNotification();
3032
3033     // loading started, this waits for the loader thread - load & rasterize
3034     DALI_TEST_EQUALS(Test::WaitForEventThreadTrigger(1), true, TEST_LOCATION);
3035
3036     application.SendNotification();
3037     application.Render(16);
3038
3039     DALI_TEST_EQUALS(gResourceReadySignalFired, true, TEST_LOCATION);
3040     DALI_TEST_EQUALS(imageView.IsResourceReady(), true, TEST_LOCATION);
3041     DALI_TEST_EQUALS(imageView.GetVisualResourceStatus(ImageView::Property::IMAGE), Visual::ResourceStatus::FAILED, TEST_LOCATION);
3042
3043     // Should be shown a broken image
3044     DALI_TEST_EQUALS(imageView.GetRendererCount(), 1u, TEST_LOCATION);
3045     DALI_TEST_EQUALS(textureTrace.FindMethod("BindTexture"), true, TEST_LOCATION);
3046   }
3047
3048   END_TEST;
3049 }
3050
3051 int UtcDaliImageViewSvgLoadingFailureRemoteFile02(void)
3052 {
3053   // Remote svg file without size set
3054   {
3055     ToolkitTestApplication application;
3056
3057     TestGlAbstraction& gl           = application.GetGlAbstraction();
3058     TraceCallStack&    textureTrace = gl.GetTextureTrace();
3059     textureTrace.Enable(true);
3060
3061     gResourceReadySignalFired = false;
3062
3063     ImageView imageView = ImageView::New("https://127.0.0.1/foobar.svg");
3064     imageView.ResourceReadySignal().Connect(&ResourceReadySignal);
3065
3066     DALI_TEST_EQUALS(imageView.IsResourceReady(), false, TEST_LOCATION);
3067
3068     application.GetScene().Add(imageView);
3069
3070     application.SendNotification();
3071
3072     // loading started, this waits for the loader thread - load & rasterize
3073     DALI_TEST_EQUALS(Test::WaitForEventThreadTrigger(1), true, TEST_LOCATION);
3074
3075     application.SendNotification();
3076     application.Render(16);
3077
3078     DALI_TEST_EQUALS(gResourceReadySignalFired, true, TEST_LOCATION);
3079     DALI_TEST_EQUALS(imageView.IsResourceReady(), true, TEST_LOCATION);
3080     DALI_TEST_EQUALS(imageView.GetVisualResourceStatus(ImageView::Property::IMAGE), Visual::ResourceStatus::FAILED, TEST_LOCATION);
3081
3082     // Should be shown a broken image
3083     DALI_TEST_EQUALS(imageView.GetRendererCount(), 1u, TEST_LOCATION);
3084     DALI_TEST_EQUALS(textureTrace.FindMethod("BindTexture"), true, TEST_LOCATION);
3085   }
3086
3087   END_TEST;
3088 }
3089
3090 int UtcDaliImageViewSvgRasterizationFailure(void)
3091 {
3092   ToolkitTestApplication application;
3093
3094   gResourceReadySignalFired = false;
3095
3096   TestGlAbstraction& gl           = application.GetGlAbstraction();
3097   TraceCallStack&    textureTrace = gl.GetTextureTrace();
3098   textureTrace.Enable(true);
3099
3100   ImageView imageView = ImageView::New(TEST_RESOURCE_DIR "/invalid1.svg");
3101   imageView.SetProperty(Actor::Property::SIZE, Vector2(200.f, 200.f));
3102   imageView.ResourceReadySignal().Connect(&ResourceReadySignal);
3103
3104   DALI_TEST_EQUALS(imageView.IsResourceReady(), false, TEST_LOCATION);
3105
3106   application.GetScene().Add(imageView);
3107
3108   application.SendNotification();
3109
3110   // Wait for loading & rasterization
3111   DALI_TEST_EQUALS(Test::WaitForEventThreadTrigger(2), true, TEST_LOCATION);
3112
3113   application.SendNotification();
3114   application.Render(16);
3115
3116   DALI_TEST_EQUALS(gResourceReadySignalFired, true, TEST_LOCATION);
3117   DALI_TEST_EQUALS(imageView.IsResourceReady(), true, TEST_LOCATION);
3118   DALI_TEST_EQUALS(imageView.GetVisualResourceStatus(ImageView::Property::IMAGE), Visual::ResourceStatus::FAILED, TEST_LOCATION);
3119
3120   // Should be shown a broken image
3121   DALI_TEST_EQUALS(imageView.GetRendererCount(), 1u, TEST_LOCATION);
3122   DALI_TEST_EQUALS(textureTrace.FindMethod("BindTexture"), true, TEST_LOCATION);
3123
3124   END_TEST;
3125 }
3126
3127 int UtcDaliImageViewSvgChageSize(void)
3128 {
3129   ToolkitTestApplication application;
3130
3131   TestGlAbstraction& gl           = application.GetGlAbstraction();
3132   TraceCallStack&    textureTrace = gl.GetTextureTrace();
3133   textureTrace.Enable(true);
3134
3135   ImageView imageView = ImageView::New(TEST_SVG_FILE_NAME);
3136   application.GetScene().Add(imageView);
3137
3138   application.SendNotification();
3139
3140   // Wait for loading & rasterization
3141   DALI_TEST_EQUALS(Test::WaitForEventThreadTrigger(2), true, TEST_LOCATION);
3142
3143   application.SendNotification();
3144   application.Render(16);
3145
3146   DALI_TEST_EQUALS(Test::VectorImageRenderer::GetLoadCount(), 1, TEST_LOCATION);
3147
3148   // Change actor size, then rasterization should be done again
3149   imageView.SetProperty(Actor::Property::SIZE, Vector2(200.f, 200.f));
3150
3151   application.SendNotification();
3152
3153   // Wait for rasterization
3154   DALI_TEST_EQUALS(Test::WaitForEventThreadTrigger(1), true, TEST_LOCATION);
3155
3156   application.SendNotification();
3157   application.Render(16);
3158
3159   // We should not load the file again.
3160   DALI_TEST_EQUALS(Test::VectorImageRenderer::GetLoadCount(), 1, TEST_LOCATION);
3161
3162   END_TEST;
3163 }
3164
3165 int UtcDaliImageViewSvgAtlasing(void)
3166 {
3167   ToolkitTestApplication application;
3168
3169   TraceCallStack& callStack = application.GetGlAbstraction().GetTextureTrace();
3170   callStack.Reset();
3171   callStack.Enable(true);
3172
3173   Property::Map propertyMap;
3174   propertyMap["url"]      = TEST_SVG_FILE_NAME;
3175   propertyMap["atlasing"] = true;
3176
3177   ImageView imageView = ImageView::New();
3178   imageView.SetProperty(ImageView::Property::IMAGE, propertyMap);
3179   imageView.SetProperty(Actor::Property::SIZE, Vector2(100.f, 100.f));
3180   application.GetScene().Add(imageView);
3181
3182   application.SendNotification();
3183
3184   // Wait for loading & rasterization
3185   DALI_TEST_EQUALS(Test::WaitForEventThreadTrigger(2), true, TEST_LOCATION);
3186
3187   application.SendNotification();
3188   application.Render(16);
3189
3190   // use atlas
3191   TraceCallStack::NamedParams params1;
3192   params1["width"] << 100;
3193   params1["height"] << 100;
3194   DALI_TEST_EQUALS(callStack.FindMethodAndParams("TexSubImage2D", params1), true, TEST_LOCATION);
3195
3196   imageView.SetProperty(Actor::Property::SIZE, Vector2(600.f, 600.f));
3197
3198   application.SendNotification();
3199
3200   // Wait for rasterization
3201   DALI_TEST_EQUALS(Test::WaitForEventThreadTrigger(1), true, TEST_LOCATION);
3202
3203   callStack.Reset();
3204
3205   application.SendNotification();
3206   application.Render(16);
3207
3208   // not use atlas
3209   TraceCallStack::NamedParams params2;
3210   params2["width"] << 600;
3211   params2["height"] << 600;
3212   DALI_TEST_EQUALS(callStack.FindMethodAndParams("TexImage2D", params2), true, TEST_LOCATION);
3213
3214   END_TEST;
3215 }
3216
3217 int UtcDaliImageViewTVGLoading(void)
3218 {
3219   ToolkitTestApplication application;
3220
3221   tet_infoline("ImageView Testing TVG image loading");
3222
3223   {
3224     ImageView imageView = ImageView::New(TEST_RESOURCE_DIR "/test.tvg");
3225     application.GetScene().Add(imageView);
3226     DALI_TEST_CHECK(imageView);
3227
3228     application.SendNotification();
3229
3230     DALI_TEST_EQUALS(Test::WaitForEventThreadTrigger(1), true, TEST_LOCATION);
3231
3232     application.SendNotification();
3233     application.Render(16);
3234
3235     Vector3 naturalSize = imageView.GetNaturalSize();
3236
3237     DALI_TEST_EQUALS(naturalSize.width, 100.0f, TEST_LOCATION);
3238     DALI_TEST_EQUALS(naturalSize.height, 100.0f, TEST_LOCATION);
3239   }
3240   END_TEST;
3241 }
3242
3243 int UtcDaliImageViewSvgDesiredSize01(void)
3244 {
3245   ToolkitTestApplication application;
3246
3247   TestGlAbstraction& gl           = application.GetGlAbstraction();
3248   TraceCallStack&    textureTrace = gl.GetTextureTrace();
3249   textureTrace.Enable(true);
3250
3251   int       desiredWidth = 100, desiredHeight = 150;
3252   ImageView imageView = ImageView::New(TEST_SVG_FILE_NAME, ImageDimensions(desiredWidth, desiredHeight));
3253
3254   application.GetScene().Add(imageView);
3255
3256   application.SendNotification();
3257
3258   // Wait for loading & rasterization
3259   DALI_TEST_EQUALS(Test::WaitForEventThreadTrigger(2), true, TEST_LOCATION);
3260
3261   application.SendNotification();
3262   application.Render(16);
3263
3264   {
3265     std::stringstream out;
3266     out << GL_TEXTURE_2D << ", " << 0u << ", " << desiredWidth << ", " << desiredHeight;
3267     DALI_TEST_CHECK(textureTrace.FindMethodAndParams("TexImage2D", out.str().c_str()));
3268   }
3269
3270   END_TEST;
3271 }
3272
3273 int UtcDaliImageViewSvgDesiredSize02(void)
3274 {
3275   ToolkitTestApplication application;
3276
3277   TestGlAbstraction& gl           = application.GetGlAbstraction();
3278   TraceCallStack&    textureTrace = gl.GetTextureTrace();
3279   textureTrace.Enable(true);
3280
3281   int       desiredWidth = 150, desiredHeight = 100;
3282   ImageView imageView                   = ImageView::New();
3283   imageView[ImageView::Property::IMAGE] = Property::Map().Add("url", TEST_SVG_FILE_NAME).Add("desiredWidth", desiredWidth).Add("desiredHeight", desiredHeight);
3284   application.GetScene().Add(imageView);
3285
3286   application.SendNotification();
3287
3288   // Wait for loading & rasterization
3289   DALI_TEST_EQUALS(Test::WaitForEventThreadTrigger(2), true, TEST_LOCATION);
3290
3291   application.SendNotification();
3292   application.Render(16);
3293
3294   {
3295     std::stringstream out;
3296     out << GL_TEXTURE_2D << ", " << 0u << ", " << desiredWidth << ", " << desiredHeight;
3297     DALI_TEST_CHECK(textureTrace.FindMethodAndParams("TexImage2D", out.str().c_str()));
3298   }
3299
3300   END_TEST;
3301 }
3302
3303 int UtcDaliImageViewImageLoadFailure01(void)
3304 {
3305   ToolkitTestApplication application;
3306
3307   Toolkit::StyleManager styleManager = Toolkit::StyleManager::Get();
3308   DevelStyleManager::SetBrokenImageUrl(styleManager, DevelStyleManager::BrokenImageType::SMALL, TEST_BROKEN_IMAGE_S);
3309   DevelStyleManager::SetBrokenImageUrl(styleManager, DevelStyleManager::BrokenImageType::NORMAL, TEST_BROKEN_IMAGE_M);
3310   DevelStyleManager::SetBrokenImageUrl(styleManager, DevelStyleManager::BrokenImageType::LARGE, TEST_BROKEN_IMAGE_L);
3311
3312   std::string brokenUrl;
3313   brokenUrl = DevelStyleManager::GetBrokenImageUrl(styleManager, DevelStyleManager::BrokenImageType::SMALL);
3314   DALI_TEST_EQUALS(TEST_BROKEN_IMAGE_S, brokenUrl, TEST_LOCATION);
3315
3316   brokenUrl = DevelStyleManager::GetBrokenImageUrl(styleManager, DevelStyleManager::BrokenImageType::NORMAL);
3317   DALI_TEST_EQUALS(TEST_BROKEN_IMAGE_M, brokenUrl, TEST_LOCATION);
3318
3319   brokenUrl = DevelStyleManager::GetBrokenImageUrl(styleManager, DevelStyleManager::BrokenImageType::LARGE);
3320   DALI_TEST_EQUALS(TEST_BROKEN_IMAGE_L, brokenUrl, TEST_LOCATION);
3321
3322   ImageView imageView = ImageView::New("invalidUrl.png");
3323   imageView.SetProperty(Actor::Property::SIZE, Vector2(200.f, 200.f));
3324
3325   application.GetScene().Add(imageView);
3326   application.SendNotification();
3327   application.Render(16);
3328
3329   // loading started, this waits for the loader thread
3330   DALI_TEST_EQUALS(Test::WaitForEventThreadTrigger(1), true, TEST_LOCATION);
3331
3332   END_TEST;
3333 }
3334
3335 int UtcDaliImageViewImageLoadFailure02(void)
3336 {
3337   ToolkitTestApplication application;
3338
3339   Toolkit::StyleManager styleManager = Toolkit::StyleManager::Get();
3340   DevelStyleManager::SetBrokenImageUrl(styleManager, DevelStyleManager::BrokenImageType::SMALL, TEST_BROKEN_IMAGE_DEFAULT);
3341   DevelStyleManager::SetBrokenImageUrl(styleManager, DevelStyleManager::BrokenImageType::NORMAL, TEST_BROKEN_IMAGE_M);
3342   DevelStyleManager::SetBrokenImageUrl(styleManager, DevelStyleManager::BrokenImageType::LARGE, TEST_BROKEN_IMAGE_L);
3343
3344   std::string brokenUrl;
3345   brokenUrl = DevelStyleManager::GetBrokenImageUrl(styleManager, DevelStyleManager::BrokenImageType::SMALL);
3346   DALI_TEST_EQUALS(TEST_BROKEN_IMAGE_DEFAULT, brokenUrl, TEST_LOCATION);
3347
3348   brokenUrl = DevelStyleManager::GetBrokenImageUrl(styleManager, DevelStyleManager::BrokenImageType::NORMAL);
3349   DALI_TEST_EQUALS(TEST_BROKEN_IMAGE_M, brokenUrl, TEST_LOCATION);
3350
3351   brokenUrl = DevelStyleManager::GetBrokenImageUrl(styleManager, DevelStyleManager::BrokenImageType::LARGE);
3352   DALI_TEST_EQUALS(TEST_BROKEN_IMAGE_L, brokenUrl, TEST_LOCATION);
3353
3354   ImageView imageView = ImageView::New("invalidUrl.png");
3355   imageView.SetProperty(Actor::Property::SIZE, Vector2(30.f, 30.f));
3356   application.GetScene().Add(imageView);
3357   application.SendNotification();
3358   application.Render(16);
3359
3360   // loading started, this waits for the loader thread
3361   DALI_TEST_EQUALS(Test::WaitForEventThreadTrigger(1), true, TEST_LOCATION);
3362
3363   END_TEST;
3364 }
3365
3366 int UtcDaliImageViewImageLoadFailure03(void)
3367 {
3368   ToolkitTestApplication application;
3369
3370   Toolkit::StyleManager styleManager = Toolkit::StyleManager::Get();
3371   DevelStyleManager::SetBrokenImageUrl(styleManager, DevelStyleManager::BrokenImageType::SMALL, TEST_BROKEN_IMAGE_01);
3372   DevelStyleManager::SetBrokenImageUrl(styleManager, DevelStyleManager::BrokenImageType::NORMAL, TEST_BROKEN_IMAGE_02);
3373
3374   std::string brokenUrl;
3375   brokenUrl = DevelStyleManager::GetBrokenImageUrl(styleManager, DevelStyleManager::BrokenImageType::SMALL);
3376   DALI_TEST_EQUALS(TEST_BROKEN_IMAGE_01, brokenUrl, TEST_LOCATION);
3377
3378   brokenUrl = DevelStyleManager::GetBrokenImageUrl(styleManager, DevelStyleManager::BrokenImageType::NORMAL);
3379   DALI_TEST_EQUALS(TEST_BROKEN_IMAGE_02, brokenUrl, TEST_LOCATION);
3380
3381   ImageView imageView = ImageView::New("invalidUrl.png");
3382   imageView.SetProperty(Actor::Property::SIZE, Vector2(100.f, 100.f));
3383   application.GetScene().Add(imageView);
3384   application.SendNotification();
3385   application.Render(16);
3386
3387   // loading started, this waits for the loader thread
3388   DALI_TEST_EQUALS(Test::WaitForEventThreadTrigger(1), true, TEST_LOCATION);
3389
3390   END_TEST;
3391 }
3392
3393 int UtcDaliImageViewImageLoadFailure04(void)
3394 {
3395   ToolkitTestApplication application;
3396
3397   ImageView imageView = ImageView::New("invalidUrl.png");
3398   imageView.SetProperty(Actor::Property::SIZE, Vector2(100.f, 100.f));
3399   application.GetScene().Add(imageView);
3400   application.SendNotification();
3401   application.Render(16);
3402
3403   // loading started, this waits for the loader thread
3404   DALI_TEST_EQUALS(Test::WaitForEventThreadTrigger(1), true, TEST_LOCATION);
3405
3406   Toolkit::StyleManager styleManager = Toolkit::StyleManager::Get();
3407   DevelStyleManager::SetBrokenImageUrl(styleManager, DevelStyleManager::BrokenImageType::SMALL, TEST_BROKEN_IMAGE_S);
3408   DevelStyleManager::SetBrokenImageUrl(styleManager, DevelStyleManager::BrokenImageType::NORMAL, "invalidBroken.png");
3409   DevelStyleManager::SetBrokenImageUrl(styleManager, DevelStyleManager::BrokenImageType::LARGE, TEST_BROKEN_IMAGE_L);
3410
3411   ImageView imageView2 = ImageView::New("invalidUrl.png");
3412   imageView2.SetProperty(Actor::Property::SIZE, Vector2(100.f, 100.f));
3413   application.GetScene().Add(imageView2);
3414
3415   std::string brokenUrl;
3416   brokenUrl = DevelStyleManager::GetBrokenImageUrl(styleManager, DevelStyleManager::BrokenImageType::SMALL);
3417   DALI_TEST_EQUALS(TEST_BROKEN_IMAGE_S, brokenUrl, TEST_LOCATION);
3418
3419   brokenUrl = DevelStyleManager::GetBrokenImageUrl(styleManager, DevelStyleManager::BrokenImageType::LARGE);
3420   DALI_TEST_EQUALS(TEST_BROKEN_IMAGE_L, brokenUrl, TEST_LOCATION);
3421
3422   application.SendNotification();
3423   application.Render(16);
3424
3425   // loading started, this waits for the loader thread
3426   DALI_TEST_EQUALS(Test::WaitForEventThreadTrigger(1), true, TEST_LOCATION);
3427
3428   DevelStyleManager::SetBrokenImageUrl(styleManager, DevelStyleManager::BrokenImageType::NORMAL, "invalidBroken.9.png");
3429
3430   ImageView imageView3 = ImageView::New("invalidUrl.png");
3431   imageView3.SetProperty(Actor::Property::SIZE, Vector2(100.f, 100.f));
3432   application.GetScene().Add(imageView3);
3433
3434   application.SendNotification();
3435   application.Render(16);
3436
3437   // loading started, this waits for the loader thread
3438   DALI_TEST_EQUALS(Test::WaitForEventThreadTrigger(1), true, TEST_LOCATION);
3439
3440   END_TEST;
3441 }
3442
3443 namespace
3444 {
3445 static int gResourceReadySignalCounter = 0;
3446
3447 void OnResourceReadySignal01(Control control)
3448 {
3449   gResourceReadySignalCounter++;
3450
3451   if(control.GetVisualResourceStatus(ImageView::Property::IMAGE) == Visual::ResourceStatus::READY)
3452   {
3453     if(gResourceReadySignalCounter == 1)
3454     {
3455       // Set image twice
3456       // It makes the first new visual be deleted immediately
3457       ImageView::DownCast(control).SetImage(gImage_34_RGBA);
3458       ImageView::DownCast(control).SetImage(gImage_34_RGBA);
3459     }
3460   }
3461   else if(control.GetVisualResourceStatus(ImageView::Property::IMAGE) == Visual::ResourceStatus::FAILED)
3462   {
3463     // Make the resource ready immediately
3464     control[ImageView::Property::IMAGE] = gImage_600_RGB;
3465   }
3466 }
3467
3468 void OnResourceReadySignal02(Control control)
3469 {
3470   if(++gResourceReadySignalCounter == 1)
3471   {
3472     // It makes the first new visual be deleted immediately
3473     // The first image will not be loaded.
3474     control[ImageView::Property::IMAGE] = Property::Map().Add(ImageVisual::Property::URL, gImage_600_RGB).Add(ImageVisual::Property::RELEASE_POLICY, ImageVisual::ReleasePolicy::NEVER);
3475     control[ImageView::Property::IMAGE] = TEST_IMAGE_1;
3476   }
3477 }
3478
3479 ImageView gImageView1;
3480 ImageView gImageView2;
3481 ImageView gImageView3;
3482 ImageView gImageView4;
3483
3484 void OnResourceReadySignal03(Control control)
3485 {
3486   if(gResourceReadySignalCounter == 0)
3487   {
3488     // Queue loading
3489     // 1. Use cached image, then LoadComplete will be called right after OnResourceReadySignal03.
3490     gImageView2[ImageView::Property::IMAGE] = gImage_34_RGBA;
3491
3492     // 2. Load a new image
3493     gImageView3[ImageView::Property::IMAGE] = TEST_IMAGE_1;
3494
3495     // 3. Use the new image again
3496     gImageView1[ImageView::Property::IMAGE] = TEST_IMAGE_1;
3497     gImageView1.ResourceReadySignal().Connect(&OnResourceReadySignal03);
3498   }
3499   else if(gResourceReadySignalCounter == 1)
3500   {
3501     // This is called from TextureManager::ProcessQueuedTextures().
3502     gImageView1.Unparent();
3503     gImageView1.Reset();
3504   }
3505   gResourceReadySignalCounter++;
3506 }
3507
3508 void OnSimpleResourceReadySignal(Control control)
3509 {
3510   // simply increate counter
3511   gResourceReadySignalCounter++;
3512 }
3513
3514 int gResourceReadySignal04ComesOrder = 0;
3515
3516 void OnResourceReadySignal04(Control control)
3517 {
3518   gResourceReadySignalCounter++;
3519   tet_printf("rc %d\n", gResourceReadySignalCounter);
3520   if(gResourceReadySignalCounter == 1)
3521   {
3522     auto scene = gImageView1.GetParent();
3523
3524     // Request load something
3525     // We hope this request result is return later than gImageView2.
3526     gImageView3 = ImageView::New(TEST_IMAGE_1);
3527     gImageView3.ResourceReadySignal().Connect(&OnResourceReadySignal04);
3528     scene.Add(gImageView3);
3529     gImageView4 = ImageView::New(TEST_IMAGE_2);
3530     gImageView4.ResourceReadySignal().Connect(&OnResourceReadySignal04);
3531     scene.Add(gImageView4);
3532
3533     if(control == gImageView1)
3534     {
3535       gResourceReadySignal04ComesOrder = 1;
3536     }
3537     else
3538     {
3539       gResourceReadySignal04ComesOrder = 2;
3540     }
3541   }
3542   if(gResourceReadySignalCounter == 2)
3543   {
3544     if(gResourceReadySignal04ComesOrder == 1 && control == gImageView2)
3545     {
3546       // Scene off first one.
3547       gImageView1.Unparent();
3548
3549       // Scene off second one.
3550       gImageView2.Unparent();
3551     }
3552     else if(gResourceReadySignal04ComesOrder == 2 && control == gImageView1)
3553     {
3554       // Scene off first one.
3555       gImageView2.Unparent();
3556
3557       // Scene off second one.
3558       gImageView1.Unparent();
3559     }
3560     else
3561     {
3562       // We can't check that this utc fail case. just pass always when we come here.
3563       gResourceReadySignal04ComesOrder = -1;
3564     }
3565
3566     // If we don't seperate index of FreeList area
3567     // and if we don't queue remove during obversing,
3568     // cache index become something invalid data.
3569     // In this case, some strange observer can be called.
3570     // For example, gImageView4.LoadComplete will be called.
3571   }
3572 }
3573
3574 void OnResourceReadySignal05(Control control)
3575 {
3576   gResourceReadySignalCounter++;
3577
3578   // Request load with same image
3579   // NOTE : The url must not be same as gImageView1
3580   const int viewCount = 4;
3581   for(int i = 0; i < viewCount; ++i)
3582   {
3583     gImageView1.Add(ImageView::New("invalid2.jpg"));
3584   }
3585 }
3586
3587 int gResourceReadySignal06ComesOrder = 0;
3588
3589 void OnResourceReadySignal06(Control control)
3590 {
3591   gResourceReadySignalCounter++;
3592   if(gResourceReadySignalCounter == 1)
3593   {
3594     auto scene = gImageView1.GetParent();
3595
3596     // Request load something
3597     // We hope this request result is return later than gImageView2.
3598
3599     Property::Map map1;
3600     map1[Toolkit::ImageVisual::Property::URL]            = TEST_IMAGE_1;
3601     map1[Toolkit::ImageVisual::Property::ALPHA_MASK_URL] = TEST_BROKEN_IMAGE_DEFAULT;
3602
3603     gImageView3 = ImageView::New();
3604     gImageView3.SetProperty(Toolkit::ImageView::Property::IMAGE, map1);
3605     gImageView3.ResourceReadySignal().Connect(&OnResourceReadySignal06);
3606
3607     Property::Map map2;
3608     map2[Toolkit::ImageVisual::Property::URL]            = TEST_IMAGE_2;
3609     map2[Toolkit::ImageVisual::Property::ALPHA_MASK_URL] = TEST_BROKEN_IMAGE_S;
3610     gImageView4                                          = ImageView::New();
3611     gImageView4.SetProperty(Toolkit::ImageView::Property::IMAGE, map2);
3612     gImageView4.ResourceReadySignal().Connect(&OnResourceReadySignal06);
3613
3614     if(control == gImageView1)
3615     {
3616       gResourceReadySignal06ComesOrder = 1;
3617     }
3618     else
3619     {
3620       gResourceReadySignal06ComesOrder = 2;
3621     }
3622   }
3623   if(gResourceReadySignalCounter == 2)
3624   {
3625     if(gResourceReadySignal06ComesOrder == 1 && control == gImageView2)
3626     {
3627       // Scene off first one.
3628       gImageView1.Unparent();
3629
3630       // Scene off second one.
3631       gImageView2.Unparent();
3632     }
3633     else if(gResourceReadySignal06ComesOrder == 2 && control == gImageView1)
3634     {
3635       // Scene off first one.
3636       gImageView2.Unparent();
3637
3638       // Scene off second one.
3639       gImageView1.Unparent();
3640     }
3641     else
3642     {
3643       // We can't check that this utc fail case. just pass always when we come here.
3644       gResourceReadySignal06ComesOrder = -1;
3645     }
3646
3647     // If we don't seperate index of FreeList area
3648     // and if we don't queue remove during obversing,
3649     // cache index become something invalid data.
3650     // In this case, some strange observer can be called.
3651     // For example, gImageView4.LoadComplete will be called.
3652   }
3653 }
3654
3655 void OnResourceReadySignal07(Control control)
3656 {
3657   gResourceReadySignalCounter++;
3658   // Load masked image
3659   tet_printf("rc %d %d\n", gResourceReadySignalCounter, static_cast<bool>(gImageView2));
3660
3661   if(!gImageView2)
3662   {
3663     auto scene = gImageView1.GetParent();
3664
3665     Property::Map map1;
3666     map1[Toolkit::ImageVisual::Property::URL]            = TEST_IMAGE_1;
3667     map1[Toolkit::ImageVisual::Property::ALPHA_MASK_URL] = TEST_BROKEN_IMAGE_DEFAULT;
3668
3669     gImageView2 = ImageView::New();
3670     gImageView2.SetProperty(Toolkit::ImageView::Property::IMAGE, map1);
3671     gImageView2.ResourceReadySignal().Connect(&OnResourceReadySignal07);
3672
3673     scene.Add(gImageView2);
3674   }
3675 }
3676
3677 void OnResourceReadySignal08(Control control)
3678 {
3679   gResourceReadySignalCounter++;
3680
3681   if(gImageView1)
3682   {
3683     gImageView1.Unparent();
3684     gImageView1.Reset();
3685   }
3686   if(gImageView2)
3687   {
3688     gImageView2.Unparent();
3689     gImageView2.Reset();
3690   }
3691 }
3692
3693 std::size_t gResourceReadySignal09Emitted = false;
3694
3695 void OnResourceReadySignal09(Control control)
3696 {
3697   gResourceReadySignalCounter++;
3698
3699   if(gImageView1 && !gResourceReadySignal09Emitted)
3700   {
3701     gResourceReadySignal09Emitted = true;
3702     gImageView1.ResourceReadySignal().Disconnect(&OnResourceReadySignal09);
3703
3704     // Try to load cached invalid nine patch image. It will request load now.
3705     gImageView1.SetImage(TEST_INVALID_NPATCH_FILE_NAME_01);
3706     gImageView2.SetImage(TEST_INVALID_NPATCH_FILE_NAME_01);
3707
3708     // Destroy all visuals immediatly.
3709     gImageView1.Unparent();
3710     gImageView1.Reset();
3711     gImageView2.Unparent();
3712     gImageView2.Reset();
3713   }
3714 }
3715
3716 } // namespace
3717
3718 int UtcDaliImageViewSetImageOnResourceReadySignal01(void)
3719 {
3720   tet_infoline("Test setting image from within signal handler.");
3721
3722   ToolkitTestApplication application;
3723
3724   gResourceReadySignalCounter = 0;
3725
3726   ImageView imageView = ImageView::New(gImage_34_RGBA);
3727   imageView.ResourceReadySignal().Connect(&OnResourceReadySignal01);
3728
3729   application.GetScene().Add(imageView);
3730
3731   DALI_TEST_EQUALS(Test::WaitForEventThreadTrigger(1), true, TEST_LOCATION);
3732
3733   application.SendNotification();
3734   application.Render();
3735
3736   DALI_TEST_EQUALS(gResourceReadySignalCounter, 2, TEST_LOCATION);
3737
3738   DALI_TEST_EQUALS(imageView.IsResourceReady(), true, TEST_LOCATION);
3739
3740   // Create a new ImageView to cache the image
3741   ImageView imageView1 = ImageView::New(gImage_600_RGB);
3742   application.GetScene().Add(imageView1);
3743
3744   DALI_TEST_EQUALS(Test::WaitForEventThreadTrigger(1), true, TEST_LOCATION);
3745
3746   application.SendNotification();
3747   application.Render();
3748
3749   // Reset count
3750   gResourceReadySignalCounter = 0;
3751
3752   imageView[ImageView::Property::IMAGE] = "invalid.jpg";
3753
3754   DALI_TEST_EQUALS(Test::WaitForEventThreadTrigger(1), true, TEST_LOCATION);
3755
3756   application.SendNotification();
3757   application.Render();
3758
3759   // Run idle callback
3760   application.RunIdles();
3761
3762   DALI_TEST_EQUALS(gResourceReadySignalCounter, 2, TEST_LOCATION);
3763
3764   DALI_TEST_EQUALS(imageView.IsResourceReady(), true, TEST_LOCATION);
3765
3766   END_TEST;
3767 }
3768
3769 int UtcDaliImageViewSetImageOnResourceReadySignal02(void)
3770 {
3771   tet_infoline("Test setting image from within signal handler.");
3772
3773   ToolkitTestApplication application;
3774
3775   gResourceReadySignalCounter = 0;
3776
3777   ImageView imageView = ImageView::New(gImage_34_RGBA);
3778   imageView.ResourceReadySignal().Connect(&OnResourceReadySignal02);
3779
3780   application.GetScene().Add(imageView);
3781
3782   DALI_TEST_EQUALS(Test::WaitForEventThreadTrigger(1), true, TEST_LOCATION);
3783
3784   application.SendNotification();
3785   application.Render();
3786
3787   // Wait for loading an image
3788   DALI_TEST_EQUALS(Test::WaitForEventThreadTrigger(1), true, TEST_LOCATION);
3789
3790   DALI_TEST_EQUALS(gResourceReadySignalCounter, 2, TEST_LOCATION);
3791
3792   DALI_TEST_EQUALS(imageView.IsResourceReady(), true, TEST_LOCATION);
3793
3794   END_TEST;
3795 }
3796
3797 int UtcDaliImageViewSetImageOnResourceReadySignal03(void)
3798 {
3799   tet_infoline("Test setting image from within signal handler.");
3800
3801   ToolkitTestApplication application;
3802
3803   gResourceReadySignalCounter = 0;
3804
3805   gImageView1 = ImageView::New(gImage_34_RGBA);
3806   application.GetScene().Add(gImageView1);
3807
3808   // Wait for loading
3809   DALI_TEST_EQUALS(Test::WaitForEventThreadTrigger(1), true, TEST_LOCATION);
3810
3811   gImageView2 = ImageView::New(gImage_600_RGB);
3812   gImageView2.ResourceReadySignal().Connect(&OnResourceReadySignal03);
3813   application.GetScene().Add(gImageView2);
3814
3815   gImageView3 = ImageView::New();
3816   application.GetScene().Add(gImageView3);
3817
3818   DALI_TEST_EQUALS(Test::WaitForEventThreadTrigger(2), true, TEST_LOCATION);
3819
3820   application.SendNotification();
3821   application.Render();
3822
3823   END_TEST;
3824 }
3825
3826 int UtcDaliImageViewOnResourceReadySignalWithBrokenAlphaMask01(void)
3827 {
3828   tet_infoline("Test signal handler when image / mask image is broken.");
3829
3830   ToolkitTestApplication application;
3831
3832   auto TestResourceReadyUrl = [&application](int eventTriggerCount, bool isSynchronous, const std::string& url, const std::string& mask, const char* location) {
3833     gResourceReadySignalCounter = 0;
3834
3835     Property::Map map;
3836     map[Toolkit::ImageVisual::Property::URL] = url;
3837     if(!mask.empty())
3838     {
3839       map[Toolkit::ImageVisual::Property::ALPHA_MASK_URL] = mask;
3840     }
3841     map[Toolkit::ImageVisual::Property::SYNCHRONOUS_LOADING] = isSynchronous;
3842
3843     ImageView imageView                            = ImageView::New();
3844     imageView[Toolkit::ImageView::Property::IMAGE] = map;
3845     imageView[Actor::Property::SIZE]               = Vector2(100.0f, 200.0f);
3846     imageView.ResourceReadySignal().Connect(&OnSimpleResourceReadySignal);
3847
3848     application.GetScene().Add(imageView);
3849     application.SendNotification();
3850     application.Render();
3851
3852     if(!isSynchronous)
3853     {
3854       // Wait for loading
3855       DALI_TEST_EQUALS(Test::WaitForEventThreadTrigger(eventTriggerCount), true, location);
3856     }
3857     tet_printf("test %s [sync:%d] signal fired\n", url.c_str(), isSynchronous ? 1 : 0);
3858     DALI_TEST_EQUALS(gResourceReadySignalCounter, 1, location);
3859
3860     imageView.Unparent();
3861   };
3862
3863   for(int synchronous = 0; synchronous <= 1; synchronous++)
3864   {
3865     tet_printf("Test normal case (sync:%d)\n", synchronous);
3866     TestResourceReadyUrl(1, synchronous, gImage_600_RGB, "", TEST_LOCATION);
3867     TestResourceReadyUrl(3, synchronous, gImage_600_RGB, gImage_34_RGBA, TEST_LOCATION); // 3 event trigger required : 2 image load + 1 apply mask
3868
3869     tet_printf("Test broken image case (sync:%d)\n", synchronous);
3870     TestResourceReadyUrl(1, synchronous, "invalid.jpg", "", TEST_LOCATION);
3871     TestResourceReadyUrl(2, synchronous, "invalid.jpg", gImage_34_RGBA, TEST_LOCATION);
3872
3873     tet_printf("Test broken mask image case (sync:%d)\n", synchronous);
3874     TestResourceReadyUrl(2, synchronous, gImage_600_RGB, "invalid.png", TEST_LOCATION);
3875
3876     tet_printf("Test broken both image, mask image case (sync:%d)\n", synchronous);
3877     TestResourceReadyUrl(2, synchronous, "invalid.jpg", "invalid.png", TEST_LOCATION);
3878   }
3879
3880   END_TEST;
3881 }
3882
3883 int UtcDaliImageViewOnResourceReadySignalWithBrokenAlphaMask02(void)
3884 {
3885   tet_infoline("Test signal handler when image try to use cached-and-broken mask image.");
3886
3887   ToolkitTestApplication application;
3888
3889   gResourceReadySignalCounter = 0;
3890
3891   auto TestBrokenMaskResourceReadyUrl = [&application](const std::string& url, const char* location) {
3892     Property::Map map;
3893     map[Toolkit::ImageVisual::Property::URL] = url;
3894     // Use invalid mask url
3895     map[Toolkit::ImageVisual::Property::ALPHA_MASK_URL] = "invalid.png";
3896
3897     ImageView imageView                            = ImageView::New();
3898     imageView[Toolkit::ImageView::Property::IMAGE] = map;
3899     imageView[Actor::Property::SIZE]               = Vector2(100.0f, 200.0f);
3900     imageView.ResourceReadySignal().Connect(&OnSimpleResourceReadySignal);
3901
3902     application.GetScene().Add(imageView);
3903
3904     // Don't unparent imageView, for keep the cache.
3905   };
3906
3907   // Use more than 4 images (The number of LocalImageLoadThread)
3908   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};
3909
3910   int expectResourceReadySignalCounter = 0;
3911
3912   for(auto& url : testUrlList)
3913   {
3914     TestBrokenMaskResourceReadyUrl(url, TEST_LOCATION);
3915     expectResourceReadySignalCounter++;
3916   }
3917
3918   // Remain 1 signal due to we use #URL + 1 mask image.
3919   DALI_TEST_EQUALS(Test::WaitForEventThreadTrigger(expectResourceReadySignalCounter + 1), true, TEST_LOCATION);
3920   application.SendNotification();
3921   application.Render();
3922   DALI_TEST_EQUALS(gResourceReadySignalCounter, expectResourceReadySignalCounter, TEST_LOCATION);
3923
3924   END_TEST;
3925 }
3926
3927 int UtcDaliImageViewCheckVariousCaseSendOnResourceReadySignal(void)
3928 {
3929   tet_infoline("Test signal handler various case.");
3930
3931   auto TestResourceReadyUrl = [](int eventTriggerCount, bool isSynchronous, bool loadSuccess, const std::string& url, const std::string& mask, const char* location) {
3932     ToolkitTestApplication application;
3933
3934     gResourceReadySignalCounter = 0;
3935
3936     Property::Map map;
3937     map[Toolkit::ImageVisual::Property::URL] = url;
3938     if(!mask.empty())
3939     {
3940       map[Toolkit::ImageVisual::Property::ALPHA_MASK_URL] = mask;
3941     }
3942     map[Toolkit::ImageVisual::Property::SYNCHRONOUS_LOADING] = isSynchronous;
3943
3944     ImageView imageView                            = ImageView::New();
3945     imageView[Toolkit::ImageView::Property::IMAGE] = map;
3946     imageView[Actor::Property::SIZE]               = Vector2(100.0f, 200.0f);
3947     imageView.ResourceReadySignal().Connect(&OnSimpleResourceReadySignal);
3948
3949     application.GetScene().Add(imageView);
3950     application.SendNotification();
3951     application.Render();
3952
3953     // Wait for loading
3954     DALI_TEST_EQUALS(Test::WaitForEventThreadTrigger(eventTriggerCount), true, location);
3955
3956     tet_printf("test %s [sync:%d] signal fired\n", url.c_str(), isSynchronous ? 1 : 0);
3957     DALI_TEST_EQUALS(gResourceReadySignalCounter, 1, location);
3958     DALI_TEST_EQUALS(imageView.GetVisualResourceStatus(Toolkit::ImageView::Property::IMAGE), loadSuccess ? Toolkit::Visual::ResourceStatus::READY : Toolkit::Visual::ResourceStatus::FAILED, location);
3959
3960     imageView.Unparent();
3961   };
3962
3963   auto TestAuxiliaryResourceReadyUrl = [](bool isSynchronous, bool loadSuccess, const std::string& url, const std::string& auxiliaryUrl, const char* location) {
3964     ToolkitTestApplication application;
3965
3966     gResourceReadySignalCounter = 0;
3967
3968     Property::Map map;
3969     map[Toolkit::ImageVisual::Property::URL]                        = url;
3970     map[Toolkit::DevelImageVisual::Property::AUXILIARY_IMAGE]       = auxiliaryUrl;
3971     map[Toolkit::DevelImageVisual::Property::AUXILIARY_IMAGE_ALPHA] = 0.5f;
3972     map[Toolkit::ImageVisual::Property::SYNCHRONOUS_LOADING]        = isSynchronous;
3973
3974     ImageView imageView = ImageView::New();
3975     imageView.SetProperty(Toolkit::ImageView::Property::IMAGE, map);
3976     imageView.SetProperty(Actor::Property::SIZE, Vector2(100.0f, 200.0f));
3977     imageView.ResourceReadySignal().Connect(&OnSimpleResourceReadySignal);
3978     application.GetScene().Add(imageView);
3979
3980     application.SendNotification();
3981     application.Render();
3982
3983     if(!isSynchronous)
3984     {
3985       // Wait for loading
3986       DALI_TEST_EQUALS(Test::WaitForEventThreadTrigger(2), true, location);
3987     }
3988
3989     tet_printf("test %s [sync:%d] signal fired\n", url.c_str(), isSynchronous ? 1 : 0);
3990     DALI_TEST_EQUALS(gResourceReadySignalCounter, 1, location);
3991     DALI_TEST_EQUALS(imageView.GetVisualResourceStatus(Toolkit::ImageView::Property::IMAGE), loadSuccess ? Toolkit::Visual::ResourceStatus::READY : Toolkit::Visual::ResourceStatus::FAILED, TEST_LOCATION);
3992
3993     imageView.Unparent();
3994   };
3995
3996   // Case 1 : asynchronous loading
3997   tet_printf("Test invalid single simple image Asynchronous\n");
3998
3999   // Test normal case
4000   TestResourceReadyUrl(1, 0, 1, gImage_600_RGB, "", TEST_LOCATION);
4001   TestResourceReadyUrl(2, 0, 1, TEST_SVG_FILE_NAME, "", TEST_LOCATION); // load & rasterize
4002   TestResourceReadyUrl(1, 0, 1, TEST_BROKEN_IMAGE_L, "", TEST_LOCATION);
4003
4004   TestResourceReadyUrl(2, 0, 1, TEST_GIF_FILE_NAME, "", TEST_LOCATION);                   // 2 image loading - batch size
4005   TestResourceReadyUrl(2, 0, 1, TEST_ANIMATED_VECTOR_IMAGE_FILE_NAME, "", TEST_LOCATION); // load & rasterize
4006
4007   TestResourceReadyUrl(3, 0, 1, gImage_600_RGB, gImage_34_RGBA, TEST_LOCATION); // 2 image loading + 1 applymask
4008
4009   TestAuxiliaryResourceReadyUrl(0, 1, TEST_BROKEN_IMAGE_L, gImage_34_RGBA, TEST_LOCATION);
4010
4011   // Test broken case
4012   TestResourceReadyUrl(1, 0, 0, "invalid.jpg", "", TEST_LOCATION);
4013   TestResourceReadyUrl(1, 0, 0, "invalid.svg", "", TEST_LOCATION);
4014   TestResourceReadyUrl(1, 0, 0, "invalid.9.png", "", TEST_LOCATION);
4015   TestResourceReadyUrl(1, 0, 0, "invalid.gif", "", TEST_LOCATION);  // 1 image loading
4016   TestResourceReadyUrl(1, 0, 0, "invalid.json", "", TEST_LOCATION); // 0 rasterize
4017
4018   TestResourceReadyUrl(2, 0, 0, "invalid.jpg", "invalid.png", TEST_LOCATION);  // 2 image loading
4019   TestResourceReadyUrl(2, 0, 1, gImage_600_RGB, "invalid.png", TEST_LOCATION); // 2 image loading
4020   TestResourceReadyUrl(2, 0, 0, "invalid.jpg", gImage_34_RGBA, TEST_LOCATION); // 2 image loading
4021
4022   TestAuxiliaryResourceReadyUrl(0, 0, "invalid.9.png", "invalid.png", TEST_LOCATION);
4023   TestAuxiliaryResourceReadyUrl(0, 1, TEST_BROKEN_IMAGE_L, "invalid.png", TEST_LOCATION);
4024   TestAuxiliaryResourceReadyUrl(0, 0, "invalid.9.png", gImage_34_RGBA, TEST_LOCATION);
4025
4026   // Case 2 : Synchronous loading
4027   tet_printf("Test invalid single simple image Synchronous\n");
4028
4029   // Test normal case
4030   TestResourceReadyUrl(0, 1, 1, gImage_600_RGB, "", TEST_LOCATION);
4031   TestResourceReadyUrl(0, 1, 1, TEST_SVG_FILE_NAME, "", TEST_LOCATION); // synchronous rasterize
4032   TestResourceReadyUrl(0, 1, 1, TEST_BROKEN_IMAGE_L, "", TEST_LOCATION);
4033
4034   TestResourceReadyUrl(1, 1, 1, TEST_GIF_FILE_NAME, "", TEST_LOCATION); // first frame image loading sync + second frame image loading async
4035
4036   TestResourceReadyUrl(0, 1, 1, gImage_600_RGB, gImage_34_RGBA, TEST_LOCATION);
4037
4038   TestAuxiliaryResourceReadyUrl(1, 1, TEST_BROKEN_IMAGE_L, gImage_34_RGBA, TEST_LOCATION);
4039
4040   // Test broken case
4041   TestResourceReadyUrl(0, 1, 0, "invalid.jpg", "", TEST_LOCATION);
4042   TestResourceReadyUrl(0, 1, 0, "invalid.svg", "", TEST_LOCATION);
4043   TestResourceReadyUrl(0, 1, 0, "invalid.9.png", "", TEST_LOCATION);
4044   TestResourceReadyUrl(0, 1, 0, "invalid.gif", "", TEST_LOCATION);
4045
4046   TestResourceReadyUrl(0, 1, 0, "invalid.jpg", "invalid.png", TEST_LOCATION);
4047   TestResourceReadyUrl(0, 1, 1, gImage_600_RGB, "invalid.png", TEST_LOCATION);
4048   TestResourceReadyUrl(0, 1, 0, "invalid.jpg", gImage_34_RGBA, TEST_LOCATION);
4049
4050   TestAuxiliaryResourceReadyUrl(1, 0, "invalid.9.png", "invalid.png", TEST_LOCATION);
4051   TestAuxiliaryResourceReadyUrl(1, 1, TEST_BROKEN_IMAGE_L, "invalid.png", TEST_LOCATION);
4052   TestAuxiliaryResourceReadyUrl(1, 0, "invalid.9.png", gImage_34_RGBA, TEST_LOCATION);
4053
4054   END_TEST;
4055 }
4056
4057 int UtcDaliImageViewSetImageOnResourceReadySignal04(void)
4058 {
4059   tet_infoline("Test texturemanager's remove queue works well within signal handler.");
4060
4061   ToolkitTestApplication application;
4062
4063   gResourceReadySignalCounter      = 0;
4064   gResourceReadySignal04ComesOrder = 0;
4065
4066   gImageView1 = ImageView::New("invalid.jpg"); // request invalid image, to make loading failed fast.
4067   gImageView1.ResourceReadySignal().Connect(&OnResourceReadySignal04);
4068   application.GetScene().Add(gImageView1);
4069
4070   gImageView2 = ImageView::New("invalid.png"); // request invalid image, to make loading failed fast.
4071   gImageView2.ResourceReadySignal().Connect(&OnResourceReadySignal04);
4072   application.GetScene().Add(gImageView2);
4073
4074   application.SendNotification();
4075   application.Render();
4076
4077   tet_infoline("Try to load 2 invalid image");
4078
4079   DALI_TEST_EQUALS(Test::WaitForEventThreadTrigger(2), true, TEST_LOCATION);
4080   DALI_TEST_EQUALS(gResourceReadySignalCounter, 2, TEST_LOCATION);
4081
4082   tet_infoline("load done");
4083
4084   // We can test this UTC only if gImageView1 and gImageView2 loaded done.
4085   if(gResourceReadySignal04ComesOrder == -1)
4086   {
4087     tet_infoline("Bad news.. gImageView3 or gImageView4 loaded faster than others. just skip this UTC");
4088   }
4089   else
4090   {
4091     // gImageView3 and gImageView4 load must not be successed yet.
4092     DALI_TEST_EQUALS(gImageView3.GetRendererCount(), 0u, TEST_LOCATION);
4093     DALI_TEST_EQUALS(gImageView4.GetRendererCount(), 0u, TEST_LOCATION);
4094
4095     application.SendNotification();
4096     application.Render();
4097
4098     tet_infoline("Try to load 2 valid image");
4099
4100     DALI_TEST_EQUALS(Test::WaitForEventThreadTrigger(2), true, TEST_LOCATION);
4101     DALI_TEST_EQUALS(gResourceReadySignalCounter, 4, TEST_LOCATION);
4102
4103     tet_infoline("load done");
4104
4105     // gImageView3 and gImageView4 load must be successed now.
4106     DALI_TEST_EQUALS(gImageView3.GetRendererAt(0).GetTextures().GetTextureCount(), 1u, TEST_LOCATION);
4107     DALI_TEST_EQUALS(gImageView4.GetRendererAt(0).GetTextures().GetTextureCount(), 1u, TEST_LOCATION);
4108   }
4109
4110   END_TEST;
4111 }
4112 int UtcDaliImageViewSetImageOnResourceReadySignal05(void)
4113 {
4114   tet_infoline("Test multiple views with same image during ResourceReady load the image only 1 times");
4115
4116   ToolkitTestApplication application;
4117
4118   gResourceReadySignalCounter = 0;
4119
4120   gImageView1 = ImageView::New("invalid.jpg"); // request invalid image, to make loading failed fast.
4121   gImageView1.ResourceReadySignal().Connect(&OnResourceReadySignal05);
4122   application.GetScene().Add(gImageView1);
4123
4124   application.SendNotification();
4125   application.Render();
4126
4127   tet_infoline("Try to load 1 invalid.jpg image");
4128   DALI_TEST_EQUALS(Test::WaitForEventThreadTrigger(1), true, TEST_LOCATION);
4129   DALI_TEST_EQUALS(gResourceReadySignalCounter, 1, TEST_LOCATION);
4130
4131   tet_infoline("Try to load 1 invalid2.jpg image");
4132   DALI_TEST_EQUALS(Test::WaitForEventThreadTrigger(1), true, TEST_LOCATION);
4133
4134   tet_infoline("Now we don't have any image to be loaded. Check event thread trigger failed.");
4135   DALI_TEST_EQUALS(Test::WaitForEventThreadTrigger(1, 1), false, TEST_LOCATION);
4136
4137   gImageView1.Unparent();
4138   gImageView1.Reset();
4139
4140   END_TEST;
4141 }
4142 int UtcDaliImageViewSetImageOnResourceReadySignal06(void)
4143 {
4144   tet_infoline("Test texturemanager's remove image & mask queue works well within signal handler.");
4145
4146   ToolkitTestApplication application;
4147
4148   gResourceReadySignalCounter      = 0;
4149   gResourceReadySignal06ComesOrder = 0;
4150
4151   Property::Map map;
4152   map[Toolkit::ImageVisual::Property::URL]            = "invalid.jpg";
4153   map[Toolkit::ImageVisual::Property::ALPHA_MASK_URL] = "invalid.png";
4154
4155   gImageView1 = ImageView::New(); // request invalid image, to make loading failed fast.
4156   gImageView1.SetProperty(Toolkit::ImageView::Property::IMAGE, map);
4157   gImageView1.ResourceReadySignal().Connect(&OnResourceReadySignal06);
4158   application.GetScene().Add(gImageView1);
4159
4160   gImageView2 = ImageView::New(); // request invalid image, to make loading failed fast.
4161   gImageView2.SetProperty(Toolkit::ImageView::Property::IMAGE, map);
4162   gImageView2.ResourceReadySignal().Connect(&OnResourceReadySignal06);
4163   application.GetScene().Add(gImageView2);
4164
4165   application.SendNotification();
4166   application.Render();
4167
4168   tet_infoline("Try to load 2 invalid image");
4169
4170   DALI_TEST_EQUALS(Test::WaitForEventThreadTrigger(2), true, TEST_LOCATION);
4171   DALI_TEST_EQUALS(gResourceReadySignalCounter, 2, TEST_LOCATION);
4172
4173   tet_infoline("load done");
4174
4175   // We can test this UTC only if gImageView1 and gImageView2 loaded done.
4176   if(gResourceReadySignal06ComesOrder == -1)
4177   {
4178     tet_infoline("Bad news.. gImageView3 or gImageView4 loaded faster than others. just skip this UTC");
4179   }
4180   else
4181   {
4182     // gImageView3 and gImageView4 load must not be successed yet.
4183     DALI_TEST_EQUALS(gImageView3.GetRendererCount(), 0u, TEST_LOCATION);
4184     DALI_TEST_EQUALS(gImageView4.GetRendererCount(), 0u, TEST_LOCATION);
4185
4186     application.GetScene().Add(gImageView3);
4187     application.GetScene().Add(gImageView4);
4188     application.SendNotification();
4189     application.Render();
4190
4191     tet_infoline("Try to load 2 valid image");
4192
4193     DALI_TEST_EQUALS(Test::WaitForEventThreadTrigger(2), true, TEST_LOCATION);
4194     DALI_TEST_EQUALS(gResourceReadySignalCounter, 2, TEST_LOCATION);
4195
4196     tet_infoline("load done");
4197   }
4198   END_TEST;
4199 }
4200
4201 int UtcDaliImageViewSetImageOnResourceReadySignal07(void)
4202 {
4203   tet_infoline("Test texturemanager's remove image & mask queue works well within signal handler 02.");
4204
4205   ToolkitTestApplication application;
4206
4207   gResourceReadySignalCounter = 0;
4208
4209   Property::Map map;
4210   map[Toolkit::ImageVisual::Property::URL] = TEST_IMAGE_1;
4211
4212   // Clear image view for clear test
4213
4214   if(gImageView1)
4215   {
4216     gImageView1.Reset();
4217   }
4218   if(gImageView2)
4219   {
4220     gImageView2.Reset();
4221   }
4222
4223   gImageView1 = ImageView::New();
4224   gImageView1.SetProperty(Toolkit::ImageView::Property::IMAGE, map);
4225   gImageView1.ResourceReadySignal().Connect(&OnResourceReadySignal07);
4226   application.GetScene().Add(gImageView1);
4227
4228   application.SendNotification();
4229   application.Render();
4230
4231   // Load gImageView1
4232
4233   DALI_TEST_EQUALS(Test::WaitForEventThreadTrigger(1), true, TEST_LOCATION);
4234   DALI_TEST_EQUALS(gResourceReadySignalCounter, 1, TEST_LOCATION);
4235
4236   tet_infoline("load image1 done");
4237
4238   // Load gImageView2 and mask
4239
4240   DALI_TEST_EQUALS(Test::WaitForEventThreadTrigger(2), true, TEST_LOCATION);
4241   DALI_TEST_EQUALS(gResourceReadySignalCounter, 1, TEST_LOCATION);
4242
4243   // gImageView2 mask apply done
4244
4245   DALI_TEST_EQUALS(Test::WaitForEventThreadTrigger(1), true, TEST_LOCATION);
4246   DALI_TEST_EQUALS(gResourceReadySignalCounter, 2, TEST_LOCATION);
4247
4248   tet_infoline("load image2 done");
4249   END_TEST;
4250 }
4251
4252 int UtcDaliImageViewSetImageOnResourceReadySignal08(void)
4253 {
4254   tet_infoline("Test remove npatch images during resource ready");
4255
4256   ToolkitTestApplication application;
4257
4258   gResourceReadySignalCounter = 0;
4259
4260   Property::Map map;
4261   map[Toolkit::ImageVisual::Property::URL] = TEST_BROKEN_IMAGE_M;
4262
4263   // Clear image view for clear test
4264
4265   if(gImageView1)
4266   {
4267     gImageView1.Reset();
4268   }
4269   if(gImageView2)
4270   {
4271     gImageView2.Reset();
4272   }
4273
4274   // Case 1 : Remove all images during resource ready.
4275   try
4276   {
4277     gImageView1 = ImageView::New();
4278     gImageView1.SetProperty(Toolkit::ImageView::Property::IMAGE, map);
4279     gImageView1.ResourceReadySignal().Connect(&OnResourceReadySignal08);
4280     application.GetScene().Add(gImageView1);
4281
4282     application.SendNotification();
4283     application.Render();
4284
4285     // Load gImageView1
4286     DALI_TEST_EQUALS(Test::WaitForEventThreadTrigger(1), true, TEST_LOCATION);
4287     DALI_TEST_EQUALS(gResourceReadySignalCounter, 1, TEST_LOCATION);
4288
4289     application.SendNotification();
4290     application.Render();
4291
4292     DALI_TEST_CHECK(true);
4293   }
4294   catch(...)
4295   {
4296     // Exception should not happened
4297     DALI_TEST_CHECK(false);
4298   }
4299
4300   // Clear cache.
4301   application.SendNotification();
4302   application.Render();
4303
4304   gResourceReadySignalCounter = 0;
4305
4306   // Case 2 : Remove all images when we use cached resource.
4307   try
4308   {
4309     gImageView1 = ImageView::New();
4310     gImageView1.SetProperty(Toolkit::ImageView::Property::IMAGE, map);
4311     gImageView1.ResourceReadySignal().Connect(&OnSimpleResourceReadySignal);
4312     application.GetScene().Add(gImageView1);
4313
4314     application.SendNotification();
4315     application.Render();
4316
4317     // Load gImageView1
4318     DALI_TEST_EQUALS(Test::WaitForEventThreadTrigger(1), true, TEST_LOCATION);
4319     DALI_TEST_EQUALS(gResourceReadySignalCounter, 1, TEST_LOCATION);
4320
4321     application.SendNotification();
4322     application.Render();
4323
4324     gImageView2 = ImageView::New();
4325     gImageView2.SetProperty(Toolkit::ImageView::Property::IMAGE, map);
4326     gImageView2.ResourceReadySignal().Connect(&OnResourceReadySignal08);
4327     application.GetScene().Add(gImageView2);
4328     DALI_TEST_EQUALS(gResourceReadySignalCounter, 2, TEST_LOCATION);
4329
4330     application.SendNotification();
4331     application.Render();
4332
4333     DALI_TEST_CHECK(true);
4334   }
4335   catch(...)
4336   {
4337     // Exception should not happened
4338     DALI_TEST_CHECK(false);
4339   }
4340   gResourceReadySignalCounter = 0;
4341
4342   // Clear image view for clear test
4343
4344   if(gImageView1)
4345   {
4346     gImageView1.Reset();
4347   }
4348   if(gImageView2)
4349   {
4350     gImageView2.Reset();
4351   }
4352
4353   END_TEST;
4354 }
4355
4356 int UtcDaliImageViewSetImageOnResourceReadySignal09(void)
4357 {
4358   tet_infoline("Test load invalid npatch images during invalid resource ready");
4359
4360   ToolkitTestApplication application;
4361
4362   gResourceReadySignalCounter = 0;
4363
4364   Property::Map map;
4365   map[Toolkit::ImageVisual::Property::URL] = TEST_INVALID_NPATCH_FILE_NAME_01;
4366
4367   // Clear image view for clear test
4368
4369   if(gImageView1)
4370   {
4371     gImageView1.Reset();
4372   }
4373   if(gImageView2)
4374   {
4375     gImageView2.Reset();
4376   }
4377   if(gImageView3)
4378   {
4379     gImageView3.Reset();
4380   }
4381
4382   // Dummy view with npatch image
4383   ImageView dummyView = ImageView::New(TEST_BROKEN_IMAGE_M);
4384   application.GetScene().Add(dummyView);
4385
4386   application.SendNotification();
4387   application.Render();
4388   DALI_TEST_EQUALS(Test::WaitForEventThreadTrigger(1), true, TEST_LOCATION);
4389   application.SendNotification();
4390   application.Render();
4391
4392   // Case 1 : Reload images during resource ready.
4393   try
4394   {
4395     gResourceReadySignal09Emitted = false;
4396
4397     gImageView1 = ImageView::New();
4398     gImageView1.SetProperty(Toolkit::ImageView::Property::IMAGE, map);
4399     gImageView1.ResourceReadySignal().Connect(&OnResourceReadySignal09);
4400     application.GetScene().Add(gImageView1);
4401
4402     gImageView2 = ImageView::New();
4403     application.GetScene().Add(gImageView2);
4404
4405     // Load TEST_INVALID_NPATCH_FILE_NAME_01
4406     DALI_TEST_EQUALS(Test::WaitForEventThreadTrigger(1), true, TEST_LOCATION);
4407
4408     // Load TEST_INVALID_NPATCH_FILE_NAME_01 one more times.
4409     DALI_TEST_EQUALS(Test::WaitForEventThreadTrigger(1), true, TEST_LOCATION);
4410
4411     application.SendNotification();
4412     application.Render();
4413
4414     DALI_TEST_CHECK(true);
4415   }
4416   catch(...)
4417   {
4418     // Exception should not happened
4419     DALI_TEST_CHECK(false);
4420   }
4421
4422   // Clear cache.
4423   application.SendNotification();
4424   application.Render();
4425
4426   gResourceReadySignalCounter = 0;
4427
4428   // Case 2 : Remove all images when we use cached resource.
4429   try
4430   {
4431     gResourceReadySignal09Emitted = false;
4432
4433     gImageView3 = ImageView::New();
4434     gImageView3.SetProperty(Toolkit::ImageView::Property::IMAGE, map);
4435     gImageView3.ResourceReadySignal().Connect(&OnSimpleResourceReadySignal);
4436     application.GetScene().Add(gImageView3);
4437
4438     gImageView2 = ImageView::New();
4439     application.GetScene().Add(gImageView2);
4440
4441     // Load gImageView2
4442     DALI_TEST_EQUALS(Test::WaitForEventThreadTrigger(1), true, TEST_LOCATION);
4443
4444     gImageView1 = ImageView::New();
4445     gImageView1.SetProperty(Toolkit::ImageView::Property::IMAGE, map);
4446     gImageView1.ResourceReadySignal().Connect(&OnResourceReadySignal09);
4447     application.GetScene().Add(gImageView1);
4448
4449     // Load gImageView1
4450     DALI_TEST_EQUALS(Test::WaitForEventThreadTrigger(1), true, TEST_LOCATION);
4451
4452     // Load TEST_INVALID_NPATCH_FILE_NAME_01 one more times.
4453     DALI_TEST_EQUALS(Test::WaitForEventThreadTrigger(1), true, TEST_LOCATION);
4454
4455     application.SendNotification();
4456     application.Render();
4457
4458     DALI_TEST_CHECK(true);
4459   }
4460   catch(...)
4461   {
4462     // Exception should not happened
4463     DALI_TEST_CHECK(false);
4464   }
4465   gResourceReadySignalCounter = 0;
4466
4467   // Clear image view for clear test
4468
4469   if(gImageView1)
4470   {
4471     gImageView1.Reset();
4472   }
4473   if(gImageView2)
4474   {
4475     gImageView2.Reset();
4476   }
4477   if(gImageView3)
4478   {
4479     gImageView3.Reset();
4480   }
4481
4482   END_TEST;
4483 }
4484
4485 int UtcDaliImageViewUseSameUrlWithAnimatedImageVisual(void)
4486 {
4487   tet_infoline("Test multiple views with same image in animated image visual");
4488   ToolkitTestApplication application;
4489
4490   gImageView1 = ImageView::New(TEST_WEBP_FILE_NAME);
4491   application.GetScene().Add(gImageView1);
4492
4493   tet_infoline("Remove imageView and Create new imageView with same url");
4494   application.GetScene().Remove(gImageView1);
4495   gImageView2 = ImageView::New(TEST_WEBP_FILE_NAME);
4496   application.GetScene().Add(gImageView2);
4497
4498   application.SendNotification();
4499   application.Render();
4500
4501   tet_infoline("Check the ImageView load image successfully");
4502   DALI_TEST_EQUALS(Test::WaitForEventThreadTrigger(1), true, TEST_LOCATION);
4503   END_TEST;
4504 }
4505
4506 int UtcDaliImageViewNpatchImageCacheTest01(void)
4507 {
4508   tet_infoline("Test npatch image cached");
4509
4510   ToolkitTestApplication application;
4511   ImageView              imageView[2];
4512
4513   auto& gl = application.GetGlAbstraction();
4514   gl.EnableTextureCallTrace(true);
4515   auto& textureCallStack = gl.GetTextureTrace();
4516   textureCallStack.Enable(true);
4517   textureCallStack.EnableLogging(true);
4518
4519   auto TestNPatch = [&](int index, const std::string& nPatchImageUrl, const char* location) {
4520     if(imageView[index])
4521     {
4522       imageView[index].Unparent();
4523     }
4524
4525     // Ensure remove npatch cache if required.
4526     application.SendNotification();
4527     application.Render();
4528
4529     imageView[index] = ImageView::New(nPatchImageUrl);
4530     imageView[index].SetProperty(Actor::Property::SIZE, Vector2(100.0f, 200.0f));
4531     application.GetScene().Add(imageView[index]);
4532   };
4533
4534   TestNPatch(0, TEST_BROKEN_IMAGE_M, TEST_LOCATION);
4535   DALI_TEST_EQUALS(Test::WaitForEventThreadTrigger(1), true, TEST_LOCATION);
4536
4537   application.SendNotification();
4538   application.Render();
4539
4540   tet_printf("trace : \n%s\n", textureCallStack.GetTraceString().c_str());
4541
4542   // Check we gen only 1 textures
4543   DALI_TEST_EQUALS(textureCallStack.CountMethod("GenTextures"), 1, TEST_LOCATION);
4544   textureCallStack.Reset();
4545
4546   // Let we use cached textures
4547   for(int i = 0; i < 10; i++)
4548   {
4549     TestNPatch(1, TEST_BROKEN_IMAGE_M, TEST_LOCATION);
4550     TestNPatch(0, TEST_BROKEN_IMAGE_M, TEST_LOCATION);
4551   }
4552
4553   application.SendNotification();
4554   application.Render();
4555   // Check we use cached npatch data so we don't generate new texture textures
4556   DALI_TEST_EQUALS(textureCallStack.CountMethod("GenTextures"), 0, TEST_LOCATION);
4557
4558   // Clear all cached
4559   imageView[0].Unparent();
4560   imageView[0].Reset();
4561   imageView[1].Unparent();
4562   imageView[1].Reset();
4563
4564   application.SendNotification();
4565   application.Render();
4566
4567   textureCallStack.Reset();
4568   // Let we use deference textures
4569   TestNPatch(1, TEST_BROKEN_IMAGE_S, TEST_LOCATION);
4570   DALI_TEST_EQUALS(Test::WaitForEventThreadTrigger(1), true, TEST_LOCATION);
4571
4572   application.SendNotification();
4573   application.Render();
4574   // Try to load multiple times.
4575   for(int i = 0; i < 3; i++)
4576   {
4577     TestNPatch(0, TEST_BROKEN_IMAGE_M, TEST_LOCATION);
4578     DALI_TEST_EQUALS(Test::WaitForEventThreadTrigger(1), true, TEST_LOCATION);
4579     TestNPatch(1, TEST_BROKEN_IMAGE_S, TEST_LOCATION);
4580     DALI_TEST_EQUALS(Test::WaitForEventThreadTrigger(1), true, TEST_LOCATION);
4581   }
4582   application.SendNotification();
4583   application.Render();
4584
4585   imageView[0].Unparent();
4586   imageView[0].Reset();
4587   imageView[1].Unparent();
4588   imageView[1].Reset();
4589
4590   application.SendNotification();
4591   application.Render();
4592
4593   // Check memory leak
4594   DALI_TEST_EQUALS(textureCallStack.CountMethod("GenTextures"), textureCallStack.CountMethod("DeleteTextures"), TEST_LOCATION);
4595
4596   END_TEST;
4597 }
4598
4599 int UtcDaliImageViewNpatchImageCacheTest02(void)
4600 {
4601   tet_infoline("Test npatch image cached with border");
4602
4603   ToolkitTestApplication application;
4604   ImageView              imageView[2];
4605
4606   auto& gl = application.GetGlAbstraction();
4607   gl.EnableTextureCallTrace(true);
4608   auto& textureCallStack = gl.GetTextureTrace();
4609   textureCallStack.Enable(true);
4610   textureCallStack.EnableLogging(true);
4611
4612   auto TestBorderImage = [&](int index, const std::string& normalImageUrl, const Rect<int> border, const char* location) {
4613     Property::Map map;
4614     map[Toolkit::Visual::Property::TYPE]        = Toolkit::Visual::N_PATCH;
4615     map[Toolkit::ImageVisual::Property::URL]    = normalImageUrl;
4616     map[Toolkit::ImageVisual::Property::BORDER] = border;
4617
4618     imageView[index] = ImageView::New();
4619     imageView[index].SetProperty(Toolkit::ImageView::Property::IMAGE, map);
4620     imageView[index].SetProperty(Actor::Property::SIZE, Vector2(100.0f, 200.0f));
4621     application.GetScene().Add(imageView[index]);
4622   };
4623
4624   TestBorderImage(0, gImage_34_RGBA, Rect<int>(0, 0, 0, 0), TEST_LOCATION);
4625   DALI_TEST_EQUALS(Test::WaitForEventThreadTrigger(1), true, TEST_LOCATION);
4626
4627   application.SendNotification();
4628   application.Render();
4629
4630   tet_printf("trace : \n%s\n", textureCallStack.GetTraceString().c_str());
4631
4632   // Check we gen only 1 textures
4633   DALI_TEST_EQUALS(textureCallStack.CountMethod("GenTextures"), 1, TEST_LOCATION);
4634   textureCallStack.Reset();
4635
4636   // Let we use cached textures
4637   for(int i = 0; i < 10; i++)
4638   {
4639     TestBorderImage(0, gImage_34_RGBA, Rect<int>(i, i + 1, i + 2, i + 3), TEST_LOCATION);
4640     TestBorderImage(1, gImage_34_RGBA, Rect<int>(i + 1, i, i + 3, i + 2), TEST_LOCATION);
4641   }
4642
4643   application.SendNotification();
4644   application.Render();
4645
4646   // Check we use cached npatch data so we don't generate new texture textures
4647   DALI_TEST_EQUALS(textureCallStack.CountMethod("GenTextures"), 0, TEST_LOCATION);
4648
4649   END_TEST;
4650 }
4651
4652 int UtcDaliImageViewPlaceholderImage01(void)
4653 {
4654   tet_infoline("Test imageView use placeholder image");
4655
4656   ToolkitTestApplication application;
4657   Property::Map          map;
4658   map[Toolkit::ImageVisual::Property::URL] = gImage_600_RGB;
4659
4660   ImageView imageView = ImageView::New();
4661   imageView.SetProperty(Toolkit::ImageView::Property::IMAGE, map);
4662   imageView.SetProperty(Actor::Property::SIZE, Vector2(100.0f, 200.0f));
4663   application.GetScene().Add(imageView);
4664
4665   Property::Value value = imageView.GetProperty(ImageView::Property::PLACEHOLDER_IMAGE);
4666   std::string     url;
4667   DALI_TEST_CHECK(value.Get(url));
4668   DALI_TEST_CHECK(url.empty());
4669   imageView.SetProperty(Toolkit::ImageView::Property::PLACEHOLDER_IMAGE, gImage_34_RGBA);
4670
4671   application.SendNotification();
4672   application.Render();
4673
4674   value = imageView.GetProperty(ImageView::Property::PLACEHOLDER_IMAGE);
4675   DALI_TEST_CHECK(value.Get(url));
4676   DALI_TEST_CHECK(url == gImage_34_RGBA);
4677
4678   imageView.SetProperty(Toolkit::ImageView::Property::IMAGE, map);
4679   application.SendNotification();
4680   application.Render();
4681
4682   // Replace Image test
4683   map[Toolkit::ImageVisual::Property::URL]    = TEST_IMAGE_1;
4684   map[ImageView::Property::PLACEHOLDER_IMAGE] = gImage_34_RGBA;
4685   imageView.SetProperty(Toolkit::ImageView::Property::IMAGE, map);
4686   application.SendNotification();
4687   application.Render();
4688
4689   map[Toolkit::ImageVisual::Property::URL] = "";
4690   imageView.SetProperty(Toolkit::ImageView::Property::IMAGE, map);
4691   application.SendNotification();
4692   application.Render();
4693
4694   map[Toolkit::ImageVisual::Property::URL] = TEST_IMAGE_2;
4695   imageView.SetProperty(Toolkit::ImageView::Property::IMAGE, map);
4696   application.SendNotification();
4697   application.Render();
4698
4699   // Replace Image test2
4700   map[Toolkit::ImageVisual::Property::URL] = TEST_IMAGE_1;
4701   imageView.SetProperty(Toolkit::ImageView::Property::IMAGE, map);
4702   application.SendNotification();
4703   application.Render();
4704
4705   map[Toolkit::ImageVisual::Property::URL] = TEST_IMAGE_2;
4706   imageView.SetProperty(Toolkit::ImageView::Property::IMAGE, map);
4707   application.SendNotification();
4708   application.Render();
4709
4710   map[Toolkit::ImageVisual::Property::URL] = gImage_600_RGB;
4711   imageView.SetProperty(Toolkit::ImageView::Property::IMAGE, map);
4712   application.SendNotification();
4713   application.Render(900);
4714
4715   map[Toolkit::ImageVisual::Property::URL] = "";
4716   imageView.SetProperty(Toolkit::ImageView::Property::IMAGE, map);
4717   application.SendNotification();
4718   application.Render();
4719
4720   map[Toolkit::ImageVisual::Property::URL] = TEST_IMAGE_1;
4721   imageView.SetProperty(Toolkit::ImageView::Property::IMAGE, map);
4722   application.SendNotification();
4723   application.Render();
4724
4725   END_TEST;
4726 }
4727
4728 int UtcDaliImageViewPlaceholderImage02(void)
4729 {
4730   tet_infoline("Test imageView use placeholder image without resource ready");
4731
4732   ToolkitTestApplication application;
4733
4734   Property::Map map;
4735   map[Toolkit::ImageVisual::Property::URL] = gImage_600_RGB;
4736
4737   ImageView imageView = ImageView::New();
4738   imageView.SetProperty(Toolkit::ImageView::Property::IMAGE, map);
4739   imageView.SetProperty(Actor::Property::SIZE, Vector2(100.0f, 200.0f));
4740   DALI_TEST_EQUALS(imageView.IsResourceReady(), false, TEST_LOCATION);
4741   imageView.ResourceReadySignal().Connect(&ResourceReadySignal);
4742   application.GetScene().Add(imageView);
4743
4744   Property::Value value = imageView.GetProperty(ImageView::Property::PLACEHOLDER_IMAGE);
4745   std::string     url;
4746   DALI_TEST_CHECK(value.Get(url));
4747   DALI_TEST_CHECK(url.empty());
4748
4749   imageView.SetProperty(Toolkit::ImageView::Property::PLACEHOLDER_IMAGE, gImage_34_RGBA);
4750   application.SendNotification();
4751   application.Render();
4752
4753   DALI_TEST_EQUALS(Test::WaitForEventThreadTrigger(1), true, TEST_LOCATION);
4754
4755   value = imageView.GetProperty(ImageView::Property::PLACEHOLDER_IMAGE);
4756   DALI_TEST_CHECK(value.Get(url));
4757   DALI_TEST_CHECK(url == gImage_34_RGBA);
4758
4759   DALI_TEST_EQUALS(imageView.IsResourceReady(), true, TEST_LOCATION);
4760   DALI_TEST_EQUALS(gResourceReadySignalFired, true, TEST_LOCATION);
4761
4762   gResourceReadySignalFired                = false;
4763   map[Toolkit::ImageVisual::Property::URL] = "";
4764   imageView.SetProperty(Toolkit::ImageView::Property::IMAGE, map);
4765   application.SendNotification();
4766   application.Render();
4767
4768   DALI_TEST_EQUALS(imageView.IsResourceReady(), true, TEST_LOCATION);
4769   DALI_TEST_EQUALS(gResourceReadySignalFired, false, TEST_LOCATION);
4770
4771   END_TEST;
4772 }
4773
4774 int UtcDaliImageViewTransitionEffect01(void)
4775 {
4776   tet_infoline("Test imageView use transition effect");
4777
4778   ToolkitTestApplication application;
4779   Property::Map          map;
4780   map[Toolkit::ImageVisual::Property::URL] = gImage_600_RGB;
4781   map[Toolkit::Visual::Property::OPACITY]  = 0.9f;
4782
4783   ImageView imageView = ImageView::New();
4784   imageView.SetProperty(Toolkit::ImageView::Property::IMAGE, map);
4785   imageView.SetProperty(Actor::Property::SIZE, Vector2(100.0f, 200.0f));
4786   application.GetScene().Add(imageView);
4787
4788   Property::Value value = imageView.GetProperty(ImageView::Property::ENABLE_TRANSITION_EFFECT);
4789   bool            transition;
4790   DALI_TEST_CHECK(value.Get(transition));
4791   DALI_TEST_CHECK(transition == false);
4792   imageView.SetProperty(Toolkit::ImageView::Property::ENABLE_TRANSITION_EFFECT, true);
4793
4794   application.SendNotification();
4795   application.Render();
4796
4797   value = imageView.GetProperty(ImageView::Property::ENABLE_TRANSITION_EFFECT);
4798   DALI_TEST_CHECK(value.Get(transition));
4799   DALI_TEST_CHECK(transition == true);
4800
4801   imageView.SetProperty(Toolkit::ImageView::Property::IMAGE, map);
4802   DALI_TEST_EQUALS(Test::WaitForEventThreadTrigger(1), true, TEST_LOCATION);
4803   application.SendNotification();
4804   application.Render();
4805
4806   // Test transition effect with placeholder
4807   map[Toolkit::ImageVisual::Property::URL] = TEST_IMAGE_1;
4808   imageView.SetProperty(Toolkit::ImageView::Property::IMAGE, map);
4809   imageView.SetProperty(Toolkit::ImageView::Property::PLACEHOLDER_IMAGE, gImage_34_RGBA);
4810   DALI_TEST_EQUALS(Test::WaitForEventThreadTrigger(1), true, TEST_LOCATION);
4811   application.SendNotification();
4812   application.Render();
4813
4814   map[Toolkit::ImageVisual::Property::URL] = "";
4815   imageView.SetProperty(Toolkit::ImageView::Property::IMAGE, map);
4816   imageView.SetProperty(Toolkit::ImageView::Property::PLACEHOLDER_IMAGE, gImage_34_RGBA);
4817   application.SendNotification();
4818   application.Render();
4819
4820   map[Toolkit::ImageVisual::Property::URL] = gImage_600_RGB;
4821   imageView.SetProperty(Toolkit::ImageView::Property::IMAGE, map);
4822   imageView.SetProperty(Toolkit::ImageView::Property::PLACEHOLDER_IMAGE, gImage_34_RGBA);
4823   application.SendNotification();
4824   application.Render();
4825
4826   map[Toolkit::ImageVisual::Property::URL] = TEST_IMAGE_1;
4827   imageView.SetProperty(Toolkit::ImageView::Property::IMAGE, map);
4828   imageView.SetProperty(Toolkit::ImageView::Property::PLACEHOLDER_IMAGE, gImage_34_RGBA);
4829   application.SendNotification();
4830
4831   map[Toolkit::ImageVisual::Property::URL] = "";
4832   imageView.SetProperty(Toolkit::ImageView::Property::IMAGE, map);
4833   imageView.SetProperty(Toolkit::ImageView::Property::PLACEHOLDER_IMAGE, gImage_34_RGBA);
4834   application.SendNotification();
4835   application.Render();
4836
4837   map[Toolkit::ImageVisual::Property::URL] = gImage_600_RGB;
4838   imageView.SetProperty(Toolkit::ImageView::Property::IMAGE, map);
4839   imageView.SetProperty(Toolkit::ImageView::Property::PLACEHOLDER_IMAGE, "");
4840   application.SendNotification();
4841   application.Render();
4842
4843   map[Toolkit::ImageVisual::Property::URL] = gImage_600_RGB;
4844   imageView.SetProperty(Toolkit::ImageView::Property::IMAGE, map);
4845   application.SendNotification();
4846   application.Render();
4847
4848   map[Toolkit::ImageVisual::Property::URL] = "";
4849   imageView.SetProperty(Toolkit::ImageView::Property::IMAGE, map);
4850   application.SendNotification();
4851   application.Render();
4852
4853   // Test transition effect without placeholder
4854   map[Toolkit::ImageVisual::Property::URL] = TEST_IMAGE_1;
4855   imageView.SetProperty(Toolkit::ImageView::Property::IMAGE, map);
4856   application.SendNotification();
4857   application.Render();
4858
4859   map[Toolkit::ImageVisual::Property::URL] = gImage_600_RGB;
4860   imageView.SetProperty(Toolkit::ImageView::Property::IMAGE, map);
4861   application.SendNotification();
4862   application.Render();
4863
4864   map[Toolkit::ImageVisual::Property::URL] = "";
4865   imageView.SetProperty(Toolkit::ImageView::Property::IMAGE, map);
4866   application.SendNotification();
4867   application.Render();
4868
4869   map[Toolkit::ImageVisual::Property::URL] = gImage_600_RGB;
4870   imageView.SetProperty(Toolkit::ImageView::Property::IMAGE, map);
4871   application.SendNotification();
4872   application.Render();
4873
4874   imageView.SetImage(TEST_IMAGE_1);
4875   application.SendNotification();
4876   application.Render();
4877
4878   imageView.SetImage(gImage_600_RGB);
4879   application.SendNotification();
4880   application.Render(9000);
4881
4882   imageView.SetImage("");
4883   application.SendNotification();
4884   application.Render();
4885
4886   imageView.SetImage(TEST_IMAGE_1);
4887   application.SendNotification();
4888   application.Render();
4889
4890   // Clear all cached
4891   imageView.Unparent();
4892   imageView.Reset();
4893
4894   END_TEST;
4895 }
4896
4897 int UtcDaliImageViewTransitionEffect02(void)
4898 {
4899   tet_infoline("Test imageView use transition effect with replace image");
4900
4901   ToolkitTestApplication application;
4902
4903   Property::Map map;
4904
4905   ImageView imageView = ImageView::New();
4906   imageView.SetProperty(Toolkit::ImageView::Property::IMAGE, map);
4907   imageView.SetProperty(Actor::Property::SIZE, Vector2(100.0f, 200.0f));
4908   application.GetScene().Add(imageView);
4909
4910   Property::Value value;
4911   value = imageView.GetProperty(ImageView::Property::ENABLE_TRANSITION_EFFECT);
4912   bool transition;
4913   DALI_TEST_CHECK(value.Get(transition));
4914   DALI_TEST_CHECK(transition == false);
4915   imageView.SetProperty(Toolkit::ImageView::Property::ENABLE_TRANSITION_EFFECT, true);
4916
4917   value = imageView.GetProperty(ImageView::Property::PLACEHOLDER_IMAGE);
4918   std::string url;
4919   DALI_TEST_CHECK(value.Get(url));
4920   DALI_TEST_CHECK(url.empty());
4921   imageView.SetProperty(Toolkit::ImageView::Property::PLACEHOLDER_IMAGE, gImage_34_RGBA);
4922   application.SendNotification();
4923   application.Render();
4924
4925   imageView.SetProperty(Toolkit::ImageView::Property::PLACEHOLDER_IMAGE, "");
4926   application.SendNotification();
4927   application.Render();
4928
4929   imageView.SetProperty(Toolkit::ImageView::Property::PLACEHOLDER_IMAGE, gImage_34_RGBA);
4930   application.SendNotification();
4931   application.Render();
4932
4933   value = imageView.GetProperty(ImageView::Property::ENABLE_TRANSITION_EFFECT);
4934   DALI_TEST_CHECK(value.Get(transition));
4935   DALI_TEST_CHECK(transition == true);
4936
4937   value = imageView.GetProperty(ImageView::Property::PLACEHOLDER_IMAGE);
4938   DALI_TEST_CHECK(value.Get(url));
4939   DALI_TEST_CHECK(url == gImage_34_RGBA);
4940
4941   imageView.SetProperty(Toolkit::ImageView::Property::IMAGE, map);
4942   application.SendNotification();
4943   application.Render();
4944
4945   // Clear all cached
4946   imageView.Unparent();
4947   imageView.Reset();
4948
4949   END_TEST;
4950 }
4951
4952 int UtcDaliImageViewTransitionEffect03(void)
4953 {
4954   tet_infoline("Test imageView use transition effect with placeholder");
4955
4956   ToolkitTestApplication application;
4957   Property::Map          map;
4958
4959   ImageView imageView = ImageView::New();
4960   imageView.SetImage("");
4961   imageView.SetProperty(Actor::Property::SIZE, Vector2(100.0f, 200.0f));
4962   imageView.SetProperty(ImageView::Property::PLACEHOLDER_IMAGE, gImage_34_RGBA);
4963   imageView.SetProperty(ImageView::Property::ENABLE_TRANSITION_EFFECT, true);
4964   application.GetScene().Add(imageView);
4965
4966   //DALI_TEST_EQUALS(Test::WaitForEventThreadTrigger(1), true, TEST_LOCATION);
4967
4968   application.SendNotification();
4969   application.Render(16);
4970
4971   tet_infoline("(1)");
4972   imageView.SetImage(gImage_600_RGB);
4973   imageView.SetProperty(ImageView::Property::PLACEHOLDER_IMAGE, gImage_34_RGBA);
4974   DALI_TEST_EQUALS(Test::WaitForEventThreadTrigger(2), true, TEST_LOCATION);
4975   application.SendNotification();
4976   application.Render(16);
4977
4978   Property::Value value;
4979   value = imageView.GetProperty(ImageView::Property::ENABLE_TRANSITION_EFFECT);
4980   bool transition;
4981   DALI_TEST_CHECK(value.Get(transition));
4982   DALI_TEST_CHECK(transition == true);
4983
4984   value = imageView.GetProperty(ImageView::Property::PLACEHOLDER_IMAGE);
4985   std::string url;
4986   DALI_TEST_CHECK(value.Get(url));
4987   DALI_TEST_CHECK(url == gImage_34_RGBA);
4988
4989   imageView.SetImage("");
4990   application.SendNotification();
4991   application.Render(16);
4992
4993   imageView.SetImage(TEST_IMAGE_1);
4994   imageView.SetProperty(ImageView::Property::PLACEHOLDER_IMAGE, gImage_34_RGBA);
4995   DALI_TEST_EQUALS(Test::WaitForEventThreadTrigger(1), true, TEST_LOCATION);
4996   application.SendNotification();
4997   application.Render(16);
4998
4999   // Clear all cached
5000   imageView.Unparent();
5001   imageView.Reset();
5002
5003   END_TEST;
5004 }