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