DALi Version 2.2.11
[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 }
2698 } // namespace
2699
2700 int UtcDaliImageViewReloadFailedOnResourceReadySignal(void)
2701 {
2702   tet_infoline("Test reloading failed image from within signal handler.");
2703
2704   ToolkitTestApplication application;
2705
2706   gFailCounter = 0;
2707
2708   ImageView imageView = ImageView::New();
2709   imageView.ResourceReadySignal().Connect(&ResourceFailedReload);
2710   DALI_TEST_EQUALS(gFailCounter, 0, TEST_LOCATION);
2711   ReloadImage(imageView);
2712
2713   // loading started, this waits for the loader thread to complete
2714   DALI_TEST_EQUALS(Test::WaitForEventThreadTrigger(1), true, TEST_LOCATION);
2715   DALI_TEST_EQUALS(gFailCounter, 1, TEST_LOCATION);
2716
2717   ReloadImage(imageView);
2718   DALI_TEST_EQUALS(Test::WaitForEventThreadTrigger(1), true, TEST_LOCATION);
2719   DALI_TEST_EQUALS(gFailCounter, 2, TEST_LOCATION);
2720
2721   ReloadImage(imageView);
2722   DALI_TEST_EQUALS(Test::WaitForEventThreadTrigger(1), true, TEST_LOCATION);
2723   DALI_TEST_EQUALS(gFailCounter, 3, TEST_LOCATION);
2724
2725   END_TEST;
2726 }
2727
2728 int UtcDaliImageViewLoadRemoteSVG(void)
2729 {
2730   tet_infoline("Test load from a remote server.");
2731
2732   ToolkitTestApplication application;
2733
2734   {
2735     Toolkit::ImageView imageView;
2736     imageView = Toolkit::ImageView::New();
2737     imageView.SetImage("https://dev.w3.org/SVG/tools/svgweb/samples/svg-files/check.svg");
2738     imageView.SetProperty(Actor::Property::PARENT_ORIGIN, ParentOrigin::TOP_LEFT);
2739     imageView.SetProperty(Actor::Property::ANCHOR_POINT, AnchorPoint::TOP_LEFT);
2740     imageView.SetProperty(Actor::Property::SIZE, Vector2(300, 300));
2741     imageView.SetProperty(Actor::Property::POSITION, Vector3(150.0f, 150.0f, 0.0f));
2742
2743     application.GetScene().Add(imageView);
2744
2745     DALI_TEST_CHECK(imageView);
2746
2747     DALI_TEST_EQUALS(imageView.GetRendererCount(), 0u, TEST_LOCATION);
2748
2749     application.SendNotification();
2750
2751     // Wait for loading & rasterization
2752     DALI_TEST_EQUALS(Test::WaitForEventThreadTrigger(2), true, TEST_LOCATION);
2753
2754     application.SendNotification();
2755     application.Render();
2756
2757     DALI_TEST_EQUALS(imageView.GetRendererCount(), 1u, TEST_LOCATION);
2758   }
2759
2760   // Without size set
2761   {
2762     Toolkit::ImageView imageView;
2763     imageView = Toolkit::ImageView::New();
2764     imageView.SetImage("https://dev.w3.org/SVG/tools/svgweb/samples/svg-files/check.svg");
2765     imageView.SetProperty(Actor::Property::PARENT_ORIGIN, ParentOrigin::TOP_LEFT);
2766     imageView.SetProperty(Actor::Property::ANCHOR_POINT, AnchorPoint::TOP_LEFT);
2767     imageView.SetProperty(Actor::Property::POSITION, Vector3(150.0f, 150.0f, 0.0f));
2768
2769     application.GetScene().Add(imageView);
2770
2771     DALI_TEST_CHECK(imageView);
2772
2773     DALI_TEST_EQUALS(imageView.GetRendererCount(), 0u, TEST_LOCATION);
2774
2775     application.SendNotification();
2776
2777     // Wait for loading & rasterization
2778     DALI_TEST_EQUALS(Test::WaitForEventThreadTrigger(2), true, TEST_LOCATION);
2779
2780     application.SendNotification();
2781     application.Render();
2782
2783     DALI_TEST_EQUALS(imageView.GetRendererCount(), 1u, TEST_LOCATION);
2784   }
2785
2786   END_TEST;
2787 }
2788
2789 int UtcDaliImageViewSyncSVGLoading(void)
2790 {
2791   ToolkitTestApplication application;
2792
2793   tet_infoline("ImageView Testing SVG image sync loading");
2794
2795   {
2796     ImageView imageView = ImageView::New();
2797
2798     // Sync loading is used
2799     Property::Map syncLoadingMap;
2800     syncLoadingMap.Insert(Toolkit::Visual::Property::TYPE, Toolkit::Visual::IMAGE);
2801     syncLoadingMap.Insert(Toolkit::ImageVisual::Property::URL, TEST_RESOURCE_DIR "/svg1.svg");
2802     syncLoadingMap.Insert(Toolkit::ImageVisual::Property::SYNCHRONOUS_LOADING, true);
2803     imageView.SetProperty(ImageView::Property::IMAGE, syncLoadingMap);
2804
2805     application.GetScene().Add(imageView);
2806     DALI_TEST_CHECK(imageView);
2807
2808     application.SendNotification();
2809     Vector3 naturalSize = imageView.GetNaturalSize();
2810
2811     DALI_TEST_EQUALS(naturalSize.width, 100.0f, TEST_LOCATION);
2812     DALI_TEST_EQUALS(naturalSize.height, 100.0f, TEST_LOCATION);
2813   }
2814   END_TEST;
2815 }
2816
2817 int UtcDaliImageViewAsyncSVGLoading(void)
2818 {
2819   ToolkitTestApplication application;
2820
2821   tet_infoline("ImageView Testing SVG image async loading");
2822
2823   {
2824     ImageView imageView = ImageView::New();
2825
2826     // Async loading is used - default value of SYNCHRONOUS_LOADING is false.
2827     Property::Map propertyMap;
2828     propertyMap.Insert(Toolkit::Visual::Property::TYPE, Toolkit::Visual::IMAGE);
2829     propertyMap.Insert(Toolkit::ImageVisual::Property::URL, TEST_RESOURCE_DIR "/svg1.svg");
2830     imageView.SetProperty(ImageView::Property::IMAGE, propertyMap);
2831
2832     application.GetScene().Add(imageView);
2833     DALI_TEST_CHECK(imageView);
2834
2835     application.SendNotification();
2836
2837     // Wait for loading
2838     DALI_TEST_EQUALS(Test::WaitForEventThreadTrigger(1), true, TEST_LOCATION);
2839
2840     application.SendNotification();
2841     application.Render(16);
2842
2843     Vector3 naturalSize = imageView.GetNaturalSize();
2844     DALI_TEST_EQUALS(naturalSize.width, 100.0f, TEST_LOCATION);
2845     DALI_TEST_EQUALS(naturalSize.height, 100.0f, TEST_LOCATION);
2846   }
2847   END_TEST;
2848 }
2849
2850 int UtcDaliImageViewSVGLoadingSyncSetInvalidValue(void)
2851 {
2852   ToolkitTestApplication application;
2853
2854   tet_infoline("ImageView Testing SVG image async loading");
2855
2856   // Sync loading
2857   {
2858     ImageView imageView = ImageView::New();
2859
2860     // Sync loading is used
2861     Property::Map syncLoadingMap;
2862     syncLoadingMap.Insert(Toolkit::Visual::Property::TYPE, Toolkit::Visual::IMAGE);
2863     syncLoadingMap.Insert(Toolkit::ImageVisual::Property::URL, TEST_RESOURCE_DIR "/svg1.svg");
2864
2865     // Check to set invalid value
2866     // The SYNCHRONOUS_LOADING property must be set to the bool value.
2867     // Check if error log is outputted when setting other value like string.
2868     // Even if the wrong value is set, the image will be shown normally, and the synchronous value should be the default value(false).
2869     syncLoadingMap.Insert(Toolkit::ImageVisual::Property::SYNCHRONOUS_LOADING, std::to_string(5));
2870     imageView.SetProperty(ImageView::Property::IMAGE, syncLoadingMap);
2871
2872     application.GetScene().Add(imageView);
2873     DALI_TEST_CHECK(imageView);
2874
2875     application.SendNotification();
2876
2877     // Wait for loading
2878     DALI_TEST_EQUALS(Test::WaitForEventThreadTrigger(1), true, TEST_LOCATION);
2879
2880     application.SendNotification();
2881     application.Render(16);
2882
2883     Vector3 naturalSize = imageView.GetNaturalSize();
2884     DALI_TEST_EQUALS(naturalSize.width, 100.0f, TEST_LOCATION);
2885     DALI_TEST_EQUALS(naturalSize.height, 100.0f, TEST_LOCATION);
2886
2887     Property::Value value = imageView.GetProperty(ImageView::Property::IMAGE);
2888     Property::Map*  map   = value.GetMap();
2889     DALI_TEST_CHECK(map);
2890
2891     Property::Value* sync = map->Find(Toolkit::ImageVisual::Property::SYNCHRONOUS_LOADING);
2892     DALI_TEST_CHECK(sync);
2893     DALI_TEST_EQUALS(false, sync->Get<bool>(), TEST_LOCATION);
2894   }
2895   END_TEST;
2896 }
2897
2898 int UtcDaliImageViewSvgLoadingFailureLocalFile(void)
2899 {
2900   // Local svg file - invalid file path
2901   {
2902     ToolkitTestApplication application;
2903
2904     TestGlAbstraction& gl           = application.GetGlAbstraction();
2905     TraceCallStack&    textureTrace = gl.GetTextureTrace();
2906     textureTrace.Enable(true);
2907
2908     gResourceReadySignalFired = false;
2909
2910     ImageView imageView = ImageView::New(TEST_RESOURCE_DIR "/foo.svg");
2911     imageView.SetProperty(Actor::Property::SIZE, Vector2(200.f, 200.f));
2912     imageView.ResourceReadySignal().Connect(&ResourceReadySignal);
2913
2914     DALI_TEST_EQUALS(imageView.IsResourceReady(), false, TEST_LOCATION);
2915
2916     application.GetScene().Add(imageView);
2917
2918     application.SendNotification();
2919
2920     // loading started, this waits for the loader thread - load
2921     DALI_TEST_EQUALS(Test::WaitForEventThreadTrigger(1), true, TEST_LOCATION);
2922
2923     application.SendNotification();
2924     application.Render(16);
2925
2926     DALI_TEST_EQUALS(gResourceReadySignalFired, true, TEST_LOCATION);
2927     DALI_TEST_EQUALS(imageView.IsResourceReady(), true, TEST_LOCATION);
2928     DALI_TEST_EQUALS(imageView.GetVisualResourceStatus(ImageView::Property::IMAGE), Visual::ResourceStatus::FAILED, TEST_LOCATION);
2929
2930     // Should be shown a broken image
2931     DALI_TEST_EQUALS(imageView.GetRendererCount(), 1u, TEST_LOCATION);
2932     DALI_TEST_EQUALS(textureTrace.FindMethod("BindTexture"), true, TEST_LOCATION);
2933   }
2934
2935   // Local svg file - invalid file path without size set
2936   {
2937     ToolkitTestApplication application;
2938
2939     TestGlAbstraction& gl           = application.GetGlAbstraction();
2940     TraceCallStack&    textureTrace = gl.GetTextureTrace();
2941     textureTrace.Enable(true);
2942
2943     gResourceReadySignalFired = false;
2944     textureTrace.Reset();
2945
2946     ImageView imageView = ImageView::New(TEST_RESOURCE_DIR "/foo.svg");
2947     imageView.ResourceReadySignal().Connect(&ResourceReadySignal);
2948
2949     DALI_TEST_EQUALS(imageView.IsResourceReady(), false, TEST_LOCATION);
2950
2951     application.GetScene().Add(imageView);
2952
2953     application.SendNotification();
2954
2955     // loading started, this waits for the loader thread - load & rasterize
2956     DALI_TEST_EQUALS(Test::WaitForEventThreadTrigger(1), true, TEST_LOCATION);
2957
2958     application.SendNotification();
2959     application.Render(16);
2960
2961     DALI_TEST_EQUALS(gResourceReadySignalFired, true, TEST_LOCATION);
2962     DALI_TEST_EQUALS(imageView.IsResourceReady(), true, TEST_LOCATION);
2963     DALI_TEST_EQUALS(imageView.GetVisualResourceStatus(ImageView::Property::IMAGE), Visual::ResourceStatus::FAILED, TEST_LOCATION);
2964
2965     // Should be shown a broken image
2966     DALI_TEST_EQUALS(imageView.GetRendererCount(), 1u, TEST_LOCATION);
2967     DALI_TEST_EQUALS(textureTrace.FindMethod("BindTexture"), true, TEST_LOCATION);
2968   }
2969
2970   // Local svg file - invalid file
2971   {
2972     ToolkitTestApplication application;
2973
2974     TestGlAbstraction& gl           = application.GetGlAbstraction();
2975     TraceCallStack&    textureTrace = gl.GetTextureTrace();
2976     textureTrace.Enable(true);
2977
2978     gResourceReadySignalFired = false;
2979     textureTrace.Reset();
2980
2981     ImageView imageView = ImageView::New(TEST_RESOURCE_DIR "/invalid.svg");
2982     imageView.SetProperty(Actor::Property::SIZE, Vector2(200.f, 200.f));
2983     imageView.ResourceReadySignal().Connect(&ResourceReadySignal);
2984
2985     DALI_TEST_EQUALS(imageView.IsResourceReady(), false, TEST_LOCATION);
2986
2987     application.GetScene().Add(imageView);
2988
2989     application.SendNotification();
2990
2991     // loading started, this waits for the loader thread - load & rasterize
2992     DALI_TEST_EQUALS(Test::WaitForEventThreadTrigger(1), true, TEST_LOCATION);
2993
2994     application.SendNotification();
2995     application.Render(16);
2996
2997     DALI_TEST_EQUALS(gResourceReadySignalFired, true, TEST_LOCATION);
2998     DALI_TEST_EQUALS(imageView.IsResourceReady(), true, TEST_LOCATION);
2999     DALI_TEST_EQUALS(imageView.GetVisualResourceStatus(ImageView::Property::IMAGE), Visual::ResourceStatus::FAILED, TEST_LOCATION);
3000
3001     // Should be shown a broken image
3002     DALI_TEST_EQUALS(imageView.GetRendererCount(), 1u, TEST_LOCATION);
3003     DALI_TEST_EQUALS(textureTrace.FindMethod("BindTexture"), true, TEST_LOCATION);
3004   }
3005
3006   END_TEST;
3007 }
3008
3009 int UtcDaliImageViewSvgLoadingFailureRemoteFile01(void)
3010 {
3011   // Remote svg file
3012   {
3013     ToolkitTestApplication application;
3014
3015     TestGlAbstraction& gl           = application.GetGlAbstraction();
3016     TraceCallStack&    textureTrace = gl.GetTextureTrace();
3017     textureTrace.Enable(true);
3018
3019     gResourceReadySignalFired = false;
3020
3021     ImageView imageView = ImageView::New("https://127.0.0.1/foobar.svg");
3022     imageView.SetProperty(Actor::Property::SIZE, Vector2(200.f, 200.f));
3023     imageView.ResourceReadySignal().Connect(&ResourceReadySignal);
3024
3025     DALI_TEST_EQUALS(imageView.IsResourceReady(), false, TEST_LOCATION);
3026
3027     application.GetScene().Add(imageView);
3028
3029     application.SendNotification();
3030
3031     // loading started, this waits for the loader thread - load & rasterize
3032     DALI_TEST_EQUALS(Test::WaitForEventThreadTrigger(1), true, TEST_LOCATION);
3033
3034     application.SendNotification();
3035     application.Render(16);
3036
3037     DALI_TEST_EQUALS(gResourceReadySignalFired, true, TEST_LOCATION);
3038     DALI_TEST_EQUALS(imageView.IsResourceReady(), true, TEST_LOCATION);
3039     DALI_TEST_EQUALS(imageView.GetVisualResourceStatus(ImageView::Property::IMAGE), Visual::ResourceStatus::FAILED, TEST_LOCATION);
3040
3041     // Should be shown a broken image
3042     DALI_TEST_EQUALS(imageView.GetRendererCount(), 1u, TEST_LOCATION);
3043     DALI_TEST_EQUALS(textureTrace.FindMethod("BindTexture"), true, TEST_LOCATION);
3044   }
3045
3046   END_TEST;
3047 }
3048
3049 int UtcDaliImageViewSvgLoadingFailureRemoteFile02(void)
3050 {
3051   // Remote svg file without size set
3052   {
3053     ToolkitTestApplication application;
3054
3055     TestGlAbstraction& gl           = application.GetGlAbstraction();
3056     TraceCallStack&    textureTrace = gl.GetTextureTrace();
3057     textureTrace.Enable(true);
3058
3059     gResourceReadySignalFired = false;
3060
3061     ImageView imageView = ImageView::New("https://127.0.0.1/foobar.svg");
3062     imageView.ResourceReadySignal().Connect(&ResourceReadySignal);
3063
3064     DALI_TEST_EQUALS(imageView.IsResourceReady(), false, TEST_LOCATION);
3065
3066     application.GetScene().Add(imageView);
3067
3068     application.SendNotification();
3069
3070     // loading started, this waits for the loader thread - load & rasterize
3071     DALI_TEST_EQUALS(Test::WaitForEventThreadTrigger(1), true, TEST_LOCATION);
3072
3073     application.SendNotification();
3074     application.Render(16);
3075
3076     DALI_TEST_EQUALS(gResourceReadySignalFired, true, TEST_LOCATION);
3077     DALI_TEST_EQUALS(imageView.IsResourceReady(), true, TEST_LOCATION);
3078     DALI_TEST_EQUALS(imageView.GetVisualResourceStatus(ImageView::Property::IMAGE), Visual::ResourceStatus::FAILED, TEST_LOCATION);
3079
3080     // Should be shown a broken image
3081     DALI_TEST_EQUALS(imageView.GetRendererCount(), 1u, TEST_LOCATION);
3082     DALI_TEST_EQUALS(textureTrace.FindMethod("BindTexture"), true, TEST_LOCATION);
3083   }
3084
3085   END_TEST;
3086 }
3087
3088 int UtcDaliImageViewSvgRasterizationFailure(void)
3089 {
3090   ToolkitTestApplication application;
3091
3092   gResourceReadySignalFired = false;
3093
3094   TestGlAbstraction& gl           = application.GetGlAbstraction();
3095   TraceCallStack&    textureTrace = gl.GetTextureTrace();
3096   textureTrace.Enable(true);
3097
3098   ImageView imageView = ImageView::New(TEST_RESOURCE_DIR "/invalid1.svg");
3099   imageView.SetProperty(Actor::Property::SIZE, Vector2(200.f, 200.f));
3100   imageView.ResourceReadySignal().Connect(&ResourceReadySignal);
3101
3102   DALI_TEST_EQUALS(imageView.IsResourceReady(), false, TEST_LOCATION);
3103
3104   application.GetScene().Add(imageView);
3105
3106   application.SendNotification();
3107
3108   // Wait for loading & rasterization
3109   DALI_TEST_EQUALS(Test::WaitForEventThreadTrigger(2), true, TEST_LOCATION);
3110
3111   application.SendNotification();
3112   application.Render(16);
3113
3114   DALI_TEST_EQUALS(gResourceReadySignalFired, true, TEST_LOCATION);
3115   DALI_TEST_EQUALS(imageView.IsResourceReady(), true, TEST_LOCATION);
3116   DALI_TEST_EQUALS(imageView.GetVisualResourceStatus(ImageView::Property::IMAGE), Visual::ResourceStatus::FAILED, TEST_LOCATION);
3117
3118   // Should be shown a broken image
3119   DALI_TEST_EQUALS(imageView.GetRendererCount(), 1u, TEST_LOCATION);
3120   DALI_TEST_EQUALS(textureTrace.FindMethod("BindTexture"), true, TEST_LOCATION);
3121
3122   END_TEST;
3123 }
3124
3125 int UtcDaliImageViewSvgChageSize(void)
3126 {
3127   ToolkitTestApplication application;
3128
3129   TestGlAbstraction& gl           = application.GetGlAbstraction();
3130   TraceCallStack&    textureTrace = gl.GetTextureTrace();
3131   textureTrace.Enable(true);
3132
3133   ImageView imageView = ImageView::New(TEST_SVG_FILE_NAME);
3134   application.GetScene().Add(imageView);
3135
3136   application.SendNotification();
3137
3138   // Wait for loading & rasterization
3139   DALI_TEST_EQUALS(Test::WaitForEventThreadTrigger(2), true, TEST_LOCATION);
3140
3141   application.SendNotification();
3142   application.Render(16);
3143
3144   DALI_TEST_EQUALS(Test::VectorImageRenderer::GetLoadCount(), 1, TEST_LOCATION);
3145
3146   // Change actor size, then rasterization should be done again
3147   imageView.SetProperty(Actor::Property::SIZE, Vector2(200.f, 200.f));
3148
3149   application.SendNotification();
3150
3151   // Wait for rasterization
3152   DALI_TEST_EQUALS(Test::WaitForEventThreadTrigger(1), true, TEST_LOCATION);
3153
3154   application.SendNotification();
3155   application.Render(16);
3156
3157   // We should not load the file again.
3158   DALI_TEST_EQUALS(Test::VectorImageRenderer::GetLoadCount(), 1, TEST_LOCATION);
3159
3160   END_TEST;
3161 }
3162
3163 int UtcDaliImageViewSvgAtlasing(void)
3164 {
3165   ToolkitTestApplication application;
3166
3167   TraceCallStack& callStack = application.GetGlAbstraction().GetTextureTrace();
3168   callStack.Reset();
3169   callStack.Enable(true);
3170
3171   Property::Map propertyMap;
3172   propertyMap["url"]      = TEST_SVG_FILE_NAME;
3173   propertyMap["atlasing"] = true;
3174
3175   ImageView imageView = ImageView::New();
3176   imageView.SetProperty(ImageView::Property::IMAGE, propertyMap);
3177   imageView.SetProperty(Actor::Property::SIZE, Vector2(100.f, 100.f));
3178   application.GetScene().Add(imageView);
3179
3180   application.SendNotification();
3181
3182   // Wait for loading & rasterization
3183   DALI_TEST_EQUALS(Test::WaitForEventThreadTrigger(2), true, TEST_LOCATION);
3184
3185   application.SendNotification();
3186   application.Render(16);
3187
3188   // use atlas
3189   TraceCallStack::NamedParams params1;
3190   params1["width"] << 100;
3191   params1["height"] << 100;
3192   DALI_TEST_EQUALS(callStack.FindMethodAndParams("TexSubImage2D", params1), true, TEST_LOCATION);
3193
3194   imageView.SetProperty(Actor::Property::SIZE, Vector2(600.f, 600.f));
3195
3196   application.SendNotification();
3197
3198   // Wait for rasterization
3199   DALI_TEST_EQUALS(Test::WaitForEventThreadTrigger(1), true, TEST_LOCATION);
3200
3201   callStack.Reset();
3202
3203   application.SendNotification();
3204   application.Render(16);
3205
3206   // not use atlas
3207   TraceCallStack::NamedParams params2;
3208   params2["width"] << 600;
3209   params2["height"] << 600;
3210   DALI_TEST_EQUALS(callStack.FindMethodAndParams("TexImage2D", params2), true, TEST_LOCATION);
3211
3212   END_TEST;
3213 }
3214
3215 int UtcDaliImageViewTVGLoading(void)
3216 {
3217   ToolkitTestApplication application;
3218
3219   tet_infoline("ImageView Testing TVG image loading");
3220
3221   {
3222     ImageView imageView = ImageView::New(TEST_RESOURCE_DIR "/test.tvg");
3223     application.GetScene().Add(imageView);
3224     DALI_TEST_CHECK(imageView);
3225
3226     application.SendNotification();
3227
3228     DALI_TEST_EQUALS(Test::WaitForEventThreadTrigger(1), true, TEST_LOCATION);
3229
3230     application.SendNotification();
3231     application.Render(16);
3232
3233     Vector3 naturalSize = imageView.GetNaturalSize();
3234
3235     DALI_TEST_EQUALS(naturalSize.width, 100.0f, TEST_LOCATION);
3236     DALI_TEST_EQUALS(naturalSize.height, 100.0f, TEST_LOCATION);
3237   }
3238   END_TEST;
3239 }
3240
3241 int UtcDaliImageViewSvgDesiredSize01(void)
3242 {
3243   ToolkitTestApplication application;
3244
3245   TestGlAbstraction& gl           = application.GetGlAbstraction();
3246   TraceCallStack&    textureTrace = gl.GetTextureTrace();
3247   textureTrace.Enable(true);
3248
3249   int       desiredWidth = 100, desiredHeight = 150;
3250   ImageView imageView = ImageView::New(TEST_SVG_FILE_NAME, ImageDimensions(desiredWidth, desiredHeight));
3251
3252   application.GetScene().Add(imageView);
3253
3254   application.SendNotification();
3255
3256   // Wait for loading & rasterization
3257   DALI_TEST_EQUALS(Test::WaitForEventThreadTrigger(2), true, TEST_LOCATION);
3258
3259   application.SendNotification();
3260   application.Render(16);
3261
3262   {
3263     std::stringstream out;
3264     out << GL_TEXTURE_2D << ", " << 0u << ", " << desiredWidth << ", " << desiredHeight;
3265     DALI_TEST_CHECK(textureTrace.FindMethodAndParams("TexImage2D", out.str().c_str()));
3266   }
3267
3268   END_TEST;
3269 }
3270
3271 int UtcDaliImageViewSvgDesiredSize02(void)
3272 {
3273   ToolkitTestApplication application;
3274
3275   TestGlAbstraction& gl           = application.GetGlAbstraction();
3276   TraceCallStack&    textureTrace = gl.GetTextureTrace();
3277   textureTrace.Enable(true);
3278
3279   int       desiredWidth = 150, desiredHeight = 100;
3280   ImageView imageView                   = ImageView::New();
3281   imageView[ImageView::Property::IMAGE] = Property::Map().Add("url", TEST_SVG_FILE_NAME).Add("desiredWidth", desiredWidth).Add("desiredHeight", desiredHeight);
3282   application.GetScene().Add(imageView);
3283
3284   application.SendNotification();
3285
3286   // Wait for loading & rasterization
3287   DALI_TEST_EQUALS(Test::WaitForEventThreadTrigger(2), true, TEST_LOCATION);
3288
3289   application.SendNotification();
3290   application.Render(16);
3291
3292   {
3293     std::stringstream out;
3294     out << GL_TEXTURE_2D << ", " << 0u << ", " << desiredWidth << ", " << desiredHeight;
3295     DALI_TEST_CHECK(textureTrace.FindMethodAndParams("TexImage2D", out.str().c_str()));
3296   }
3297
3298   END_TEST;
3299 }
3300
3301 int UtcDaliImageViewImageLoadFailure01(void)
3302 {
3303   ToolkitTestApplication application;
3304
3305   Toolkit::StyleManager styleManager = Toolkit::StyleManager::Get();
3306   DevelStyleManager::SetBrokenImageUrl(styleManager, DevelStyleManager::BrokenImageType::SMALL, TEST_BROKEN_IMAGE_S);
3307   DevelStyleManager::SetBrokenImageUrl(styleManager, DevelStyleManager::BrokenImageType::NORMAL, TEST_BROKEN_IMAGE_M);
3308   DevelStyleManager::SetBrokenImageUrl(styleManager, DevelStyleManager::BrokenImageType::LARGE, TEST_BROKEN_IMAGE_L);
3309
3310   std::string brokenUrl;
3311   brokenUrl = DevelStyleManager::GetBrokenImageUrl(styleManager, DevelStyleManager::BrokenImageType::SMALL);
3312   DALI_TEST_EQUALS(TEST_BROKEN_IMAGE_S, brokenUrl, TEST_LOCATION);
3313
3314   brokenUrl = DevelStyleManager::GetBrokenImageUrl(styleManager, DevelStyleManager::BrokenImageType::NORMAL);
3315   DALI_TEST_EQUALS(TEST_BROKEN_IMAGE_M, brokenUrl, TEST_LOCATION);
3316
3317   brokenUrl = DevelStyleManager::GetBrokenImageUrl(styleManager, DevelStyleManager::BrokenImageType::LARGE);
3318   DALI_TEST_EQUALS(TEST_BROKEN_IMAGE_L, brokenUrl, TEST_LOCATION);
3319
3320   ImageView imageView = ImageView::New("invalidUrl.png");
3321   imageView.SetProperty(Actor::Property::SIZE, Vector2(200.f, 200.f));
3322
3323   application.GetScene().Add(imageView);
3324   application.SendNotification();
3325   application.Render(16);
3326
3327   // loading started, this waits for the loader thread
3328   DALI_TEST_EQUALS(Test::WaitForEventThreadTrigger(1), true, TEST_LOCATION);
3329
3330   END_TEST;
3331 }
3332
3333 int UtcDaliImageViewImageLoadFailure02(void)
3334 {
3335   ToolkitTestApplication application;
3336
3337   Toolkit::StyleManager styleManager = Toolkit::StyleManager::Get();
3338   DevelStyleManager::SetBrokenImageUrl(styleManager, DevelStyleManager::BrokenImageType::SMALL, TEST_BROKEN_IMAGE_DEFAULT);
3339   DevelStyleManager::SetBrokenImageUrl(styleManager, DevelStyleManager::BrokenImageType::NORMAL, TEST_BROKEN_IMAGE_M);
3340   DevelStyleManager::SetBrokenImageUrl(styleManager, DevelStyleManager::BrokenImageType::LARGE, TEST_BROKEN_IMAGE_L);
3341
3342   std::string brokenUrl;
3343   brokenUrl = DevelStyleManager::GetBrokenImageUrl(styleManager, DevelStyleManager::BrokenImageType::SMALL);
3344   DALI_TEST_EQUALS(TEST_BROKEN_IMAGE_DEFAULT, brokenUrl, TEST_LOCATION);
3345
3346   brokenUrl = DevelStyleManager::GetBrokenImageUrl(styleManager, DevelStyleManager::BrokenImageType::NORMAL);
3347   DALI_TEST_EQUALS(TEST_BROKEN_IMAGE_M, brokenUrl, TEST_LOCATION);
3348
3349   brokenUrl = DevelStyleManager::GetBrokenImageUrl(styleManager, DevelStyleManager::BrokenImageType::LARGE);
3350   DALI_TEST_EQUALS(TEST_BROKEN_IMAGE_L, brokenUrl, TEST_LOCATION);
3351
3352   ImageView imageView = ImageView::New("invalidUrl.png");
3353   imageView.SetProperty(Actor::Property::SIZE, Vector2(30.f, 30.f));
3354   application.GetScene().Add(imageView);
3355   application.SendNotification();
3356   application.Render(16);
3357
3358   // loading started, this waits for the loader thread
3359   DALI_TEST_EQUALS(Test::WaitForEventThreadTrigger(1), true, TEST_LOCATION);
3360
3361   END_TEST;
3362 }
3363
3364 int UtcDaliImageViewImageLoadFailure03(void)
3365 {
3366   ToolkitTestApplication application;
3367
3368   Toolkit::StyleManager styleManager = Toolkit::StyleManager::Get();
3369   DevelStyleManager::SetBrokenImageUrl(styleManager, DevelStyleManager::BrokenImageType::SMALL, TEST_BROKEN_IMAGE_01);
3370   DevelStyleManager::SetBrokenImageUrl(styleManager, DevelStyleManager::BrokenImageType::NORMAL, TEST_BROKEN_IMAGE_02);
3371
3372   std::string brokenUrl;
3373   brokenUrl = DevelStyleManager::GetBrokenImageUrl(styleManager, DevelStyleManager::BrokenImageType::SMALL);
3374   DALI_TEST_EQUALS(TEST_BROKEN_IMAGE_01, brokenUrl, TEST_LOCATION);
3375
3376   brokenUrl = DevelStyleManager::GetBrokenImageUrl(styleManager, DevelStyleManager::BrokenImageType::NORMAL);
3377   DALI_TEST_EQUALS(TEST_BROKEN_IMAGE_02, brokenUrl, TEST_LOCATION);
3378
3379   ImageView imageView = ImageView::New("invalidUrl.png");
3380   imageView.SetProperty(Actor::Property::SIZE, Vector2(100.f, 100.f));
3381   application.GetScene().Add(imageView);
3382   application.SendNotification();
3383   application.Render(16);
3384
3385   // loading started, this waits for the loader thread
3386   DALI_TEST_EQUALS(Test::WaitForEventThreadTrigger(1), true, TEST_LOCATION);
3387
3388   END_TEST;
3389 }
3390
3391 int UtcDaliImageViewImageLoadFailure04(void)
3392 {
3393   ToolkitTestApplication application;
3394
3395   ImageView imageView = ImageView::New("invalidUrl.png");
3396   imageView.SetProperty(Actor::Property::SIZE, Vector2(100.f, 100.f));
3397   application.GetScene().Add(imageView);
3398   application.SendNotification();
3399   application.Render(16);
3400
3401   // loading started, this waits for the loader thread
3402   DALI_TEST_EQUALS(Test::WaitForEventThreadTrigger(1), true, TEST_LOCATION);
3403
3404   Toolkit::StyleManager styleManager = Toolkit::StyleManager::Get();
3405   DevelStyleManager::SetBrokenImageUrl(styleManager, DevelStyleManager::BrokenImageType::SMALL, TEST_BROKEN_IMAGE_S);
3406   DevelStyleManager::SetBrokenImageUrl(styleManager, DevelStyleManager::BrokenImageType::NORMAL, "invalidBroken.png");
3407   DevelStyleManager::SetBrokenImageUrl(styleManager, DevelStyleManager::BrokenImageType::LARGE, TEST_BROKEN_IMAGE_L);
3408
3409   ImageView imageView2 = ImageView::New("invalidUrl.png");
3410   imageView2.SetProperty(Actor::Property::SIZE, Vector2(100.f, 100.f));
3411   application.GetScene().Add(imageView2);
3412
3413   std::string brokenUrl;
3414   brokenUrl = DevelStyleManager::GetBrokenImageUrl(styleManager, DevelStyleManager::BrokenImageType::SMALL);
3415   DALI_TEST_EQUALS(TEST_BROKEN_IMAGE_S, brokenUrl, TEST_LOCATION);
3416
3417   brokenUrl = DevelStyleManager::GetBrokenImageUrl(styleManager, DevelStyleManager::BrokenImageType::LARGE);
3418   DALI_TEST_EQUALS(TEST_BROKEN_IMAGE_L, brokenUrl, TEST_LOCATION);
3419
3420   application.SendNotification();
3421   application.Render(16);
3422
3423   // loading started, this waits for the loader thread
3424   DALI_TEST_EQUALS(Test::WaitForEventThreadTrigger(1), true, TEST_LOCATION);
3425
3426   DevelStyleManager::SetBrokenImageUrl(styleManager, DevelStyleManager::BrokenImageType::NORMAL, "invalidBroken.9.png");
3427
3428   ImageView imageView3 = ImageView::New("invalidUrl.png");
3429   imageView3.SetProperty(Actor::Property::SIZE, Vector2(100.f, 100.f));
3430   application.GetScene().Add(imageView3);
3431
3432   application.SendNotification();
3433   application.Render(16);
3434
3435   // loading started, this waits for the loader thread
3436   DALI_TEST_EQUALS(Test::WaitForEventThreadTrigger(1), true, TEST_LOCATION);
3437
3438   END_TEST;
3439 }
3440
3441 namespace
3442 {
3443 static int gResourceReadySignalCounter = 0;
3444
3445 void OnResourceReadySignal01(Control control)
3446 {
3447   gResourceReadySignalCounter++;
3448
3449   if(control.GetVisualResourceStatus(ImageView::Property::IMAGE) == Visual::ResourceStatus::READY)
3450   {
3451     if(gResourceReadySignalCounter == 1)
3452     {
3453       // Set image twice
3454       // It makes the first new visual be deleted immediately
3455       ImageView::DownCast(control).SetImage(gImage_34_RGBA);
3456       ImageView::DownCast(control).SetImage(gImage_34_RGBA);
3457     }
3458   }
3459   else if(control.GetVisualResourceStatus(ImageView::Property::IMAGE) == Visual::ResourceStatus::FAILED)
3460   {
3461     // Make the resource ready immediately
3462     control[ImageView::Property::IMAGE] = gImage_600_RGB;
3463   }
3464 }
3465
3466 void OnResourceReadySignal02(Control control)
3467 {
3468   if(++gResourceReadySignalCounter == 1)
3469   {
3470     // It makes the first new visual be deleted immediately
3471     // The first image will not be loaded.
3472     control[ImageView::Property::IMAGE] = Property::Map().Add(ImageVisual::Property::URL, gImage_600_RGB).Add(ImageVisual::Property::RELEASE_POLICY, ImageVisual::ReleasePolicy::NEVER);
3473     control[ImageView::Property::IMAGE] = TEST_IMAGE_1;
3474   }
3475 }
3476
3477 ImageView gImageView1;
3478 ImageView gImageView2;
3479 ImageView gImageView3;
3480 ImageView gImageView4;
3481
3482 void OnResourceReadySignal03(Control control)
3483 {
3484   if(gResourceReadySignalCounter == 0)
3485   {
3486     // Queue loading
3487     // 1. Use cached image, then LoadComplete will be called right after OnResourceReadySignal03.
3488     gImageView2[ImageView::Property::IMAGE] = gImage_34_RGBA;
3489
3490     // 2. Load a new image
3491     gImageView3[ImageView::Property::IMAGE] = TEST_IMAGE_1;
3492
3493     // 3. Use the new image again
3494     gImageView1[ImageView::Property::IMAGE] = TEST_IMAGE_1;
3495     gImageView1.ResourceReadySignal().Connect(&OnResourceReadySignal03);
3496   }
3497   else if(gResourceReadySignalCounter == 1)
3498   {
3499     // This is called from TextureManager::ProcessQueuedTextures().
3500     gImageView1.Unparent();
3501     gImageView1.Reset();
3502   }
3503   gResourceReadySignalCounter++;
3504 }
3505
3506 void OnSimpleResourceReadySignal(Control control)
3507 {
3508   // simply increate counter
3509   gResourceReadySignalCounter++;
3510 }
3511
3512 int gResourceReadySignal04ComesOrder = 0;
3513
3514 void OnResourceReadySignal04(Control control)
3515 {
3516   gResourceReadySignalCounter++;
3517   tet_printf("rc %d\n", gResourceReadySignalCounter);
3518   if(gResourceReadySignalCounter == 1)
3519   {
3520     auto scene = gImageView1.GetParent();
3521
3522     // Request load something
3523     // We hope this request result is return later than gImageView2.
3524     gImageView3 = ImageView::New(TEST_IMAGE_1);
3525     gImageView3.ResourceReadySignal().Connect(&OnResourceReadySignal04);
3526     scene.Add(gImageView3);
3527     gImageView4 = ImageView::New(TEST_IMAGE_2);
3528     gImageView4.ResourceReadySignal().Connect(&OnResourceReadySignal04);
3529     scene.Add(gImageView4);
3530
3531     if(control == gImageView1)
3532     {
3533       gResourceReadySignal04ComesOrder = 1;
3534     }
3535     else
3536     {
3537       gResourceReadySignal04ComesOrder = 2;
3538     }
3539   }
3540   if(gResourceReadySignalCounter == 2)
3541   {
3542     if(gResourceReadySignal04ComesOrder == 1 && control == gImageView2)
3543     {
3544       // Scene off first one.
3545       gImageView1.Unparent();
3546
3547       // Scene off second one.
3548       gImageView2.Unparent();
3549     }
3550     else if(gResourceReadySignal04ComesOrder == 2 && control == gImageView1)
3551     {
3552       // Scene off first one.
3553       gImageView2.Unparent();
3554
3555       // Scene off second one.
3556       gImageView1.Unparent();
3557     }
3558     else
3559     {
3560       // We can't check that this utc fail case. just pass always when we come here.
3561       gResourceReadySignal04ComesOrder = -1;
3562     }
3563
3564     // If we don't seperate index of FreeList area
3565     // and if we don't queue remove during obversing,
3566     // cache index become something invalid data.
3567     // In this case, some strange observer can be called.
3568     // For example, gImageView4.LoadComplete will be called.
3569   }
3570 }
3571
3572 void OnResourceReadySignal05(Control control)
3573 {
3574   gResourceReadySignalCounter++;
3575
3576   // Request load with same image
3577   // NOTE : The url must not be same as gImageView1
3578   const int viewCount = 4;
3579   for(int i = 0; i < viewCount; ++i)
3580   {
3581     gImageView1.Add(ImageView::New("invalid2.jpg"));
3582   }
3583 }
3584
3585 int gResourceReadySignal06ComesOrder = 0;
3586
3587 void OnResourceReadySignal06(Control control)
3588 {
3589   gResourceReadySignalCounter++;
3590   if(gResourceReadySignalCounter == 1)
3591   {
3592     auto scene = gImageView1.GetParent();
3593
3594     // Request load something
3595     // We hope this request result is return later than gImageView2.
3596
3597     Property::Map map1;
3598     map1[Toolkit::ImageVisual::Property::URL]            = TEST_IMAGE_1;
3599     map1[Toolkit::ImageVisual::Property::ALPHA_MASK_URL] = TEST_BROKEN_IMAGE_DEFAULT;
3600
3601     gImageView3 = ImageView::New();
3602     gImageView3.SetProperty(Toolkit::ImageView::Property::IMAGE, map1);
3603     gImageView3.ResourceReadySignal().Connect(&OnResourceReadySignal06);
3604
3605     Property::Map map2;
3606     map2[Toolkit::ImageVisual::Property::URL]            = TEST_IMAGE_2;
3607     map2[Toolkit::ImageVisual::Property::ALPHA_MASK_URL] = TEST_BROKEN_IMAGE_S;
3608     gImageView4                                          = ImageView::New();
3609     gImageView4.SetProperty(Toolkit::ImageView::Property::IMAGE, map2);
3610     gImageView4.ResourceReadySignal().Connect(&OnResourceReadySignal06);
3611
3612     if(control == gImageView1)
3613     {
3614       gResourceReadySignal06ComesOrder = 1;
3615     }
3616     else
3617     {
3618       gResourceReadySignal06ComesOrder = 2;
3619     }
3620   }
3621   if(gResourceReadySignalCounter == 2)
3622   {
3623     if(gResourceReadySignal06ComesOrder == 1 && control == gImageView2)
3624     {
3625       // Scene off first one.
3626       gImageView1.Unparent();
3627
3628       // Scene off second one.
3629       gImageView2.Unparent();
3630     }
3631     else if(gResourceReadySignal06ComesOrder == 2 && control == gImageView1)
3632     {
3633       // Scene off first one.
3634       gImageView2.Unparent();
3635
3636       // Scene off second one.
3637       gImageView1.Unparent();
3638     }
3639     else
3640     {
3641       // We can't check that this utc fail case. just pass always when we come here.
3642       gResourceReadySignal06ComesOrder = -1;
3643     }
3644
3645     // If we don't seperate index of FreeList area
3646     // and if we don't queue remove during obversing,
3647     // cache index become something invalid data.
3648     // In this case, some strange observer can be called.
3649     // For example, gImageView4.LoadComplete will be called.
3650   }
3651 }
3652
3653 void OnResourceReadySignal07(Control control)
3654 {
3655   gResourceReadySignalCounter++;
3656   // Load masked image
3657   tet_printf("rc %d %d\n", gResourceReadySignalCounter, static_cast<bool>(gImageView2));
3658
3659   if(!gImageView2)
3660   {
3661     auto scene = gImageView1.GetParent();
3662
3663     Property::Map map1;
3664     map1[Toolkit::ImageVisual::Property::URL]            = TEST_IMAGE_1;
3665     map1[Toolkit::ImageVisual::Property::ALPHA_MASK_URL] = TEST_BROKEN_IMAGE_DEFAULT;
3666
3667     gImageView2 = ImageView::New();
3668     gImageView2.SetProperty(Toolkit::ImageView::Property::IMAGE, map1);
3669     gImageView2.ResourceReadySignal().Connect(&OnResourceReadySignal07);
3670
3671     scene.Add(gImageView2);
3672   }
3673 }
3674
3675 } // namespace
3676
3677 int UtcDaliImageViewSetImageOnResourceReadySignal01(void)
3678 {
3679   tet_infoline("Test setting image from within signal handler.");
3680
3681   ToolkitTestApplication application;
3682
3683   gResourceReadySignalCounter = 0;
3684
3685   ImageView imageView = ImageView::New(gImage_34_RGBA);
3686   imageView.ResourceReadySignal().Connect(&OnResourceReadySignal01);
3687
3688   application.GetScene().Add(imageView);
3689
3690   DALI_TEST_EQUALS(Test::WaitForEventThreadTrigger(1), true, TEST_LOCATION);
3691
3692   application.SendNotification();
3693   application.Render();
3694
3695   DALI_TEST_EQUALS(gResourceReadySignalCounter, 2, TEST_LOCATION);
3696
3697   DALI_TEST_EQUALS(imageView.IsResourceReady(), true, TEST_LOCATION);
3698
3699   // Create a new ImageView to cache the image
3700   ImageView imageView1 = ImageView::New(gImage_600_RGB);
3701   application.GetScene().Add(imageView1);
3702
3703   DALI_TEST_EQUALS(Test::WaitForEventThreadTrigger(1), true, TEST_LOCATION);
3704
3705   application.SendNotification();
3706   application.Render();
3707
3708   // Reset count
3709   gResourceReadySignalCounter = 0;
3710
3711   imageView[ImageView::Property::IMAGE] = "invalid.jpg";
3712
3713   DALI_TEST_EQUALS(Test::WaitForEventThreadTrigger(1), true, TEST_LOCATION);
3714
3715   application.SendNotification();
3716   application.Render();
3717
3718   // Run idle callback
3719   application.RunIdles();
3720
3721   DALI_TEST_EQUALS(gResourceReadySignalCounter, 2, TEST_LOCATION);
3722
3723   DALI_TEST_EQUALS(imageView.IsResourceReady(), true, TEST_LOCATION);
3724
3725   END_TEST;
3726 }
3727
3728 int UtcDaliImageViewSetImageOnResourceReadySignal02(void)
3729 {
3730   tet_infoline("Test setting image from within signal handler.");
3731
3732   ToolkitTestApplication application;
3733
3734   gResourceReadySignalCounter = 0;
3735
3736   ImageView imageView = ImageView::New(gImage_34_RGBA);
3737   imageView.ResourceReadySignal().Connect(&OnResourceReadySignal02);
3738
3739   application.GetScene().Add(imageView);
3740
3741   DALI_TEST_EQUALS(Test::WaitForEventThreadTrigger(1), true, TEST_LOCATION);
3742
3743   application.SendNotification();
3744   application.Render();
3745
3746   // Wait for loading an image
3747   DALI_TEST_EQUALS(Test::WaitForEventThreadTrigger(1), true, TEST_LOCATION);
3748
3749   DALI_TEST_EQUALS(gResourceReadySignalCounter, 2, TEST_LOCATION);
3750
3751   DALI_TEST_EQUALS(imageView.IsResourceReady(), true, TEST_LOCATION);
3752
3753   END_TEST;
3754 }
3755
3756 int UtcDaliImageViewSetImageOnResourceReadySignal03(void)
3757 {
3758   tet_infoline("Test setting image from within signal handler.");
3759
3760   ToolkitTestApplication application;
3761
3762   gResourceReadySignalCounter = 0;
3763
3764   gImageView1 = ImageView::New(gImage_34_RGBA);
3765   application.GetScene().Add(gImageView1);
3766
3767   // Wait for loading
3768   DALI_TEST_EQUALS(Test::WaitForEventThreadTrigger(1), true, TEST_LOCATION);
3769
3770   gImageView2 = ImageView::New(gImage_600_RGB);
3771   gImageView2.ResourceReadySignal().Connect(&OnResourceReadySignal03);
3772   application.GetScene().Add(gImageView2);
3773
3774   gImageView3 = ImageView::New();
3775   application.GetScene().Add(gImageView3);
3776
3777   DALI_TEST_EQUALS(Test::WaitForEventThreadTrigger(2), true, TEST_LOCATION);
3778
3779   application.SendNotification();
3780   application.Render();
3781
3782   END_TEST;
3783 }
3784
3785 int UtcDaliImageViewOnResourceReadySignalWithBrokenAlphaMask01(void)
3786 {
3787   tet_infoline("Test signal handler when image / mask image is broken.");
3788
3789   ToolkitTestApplication application;
3790
3791   auto TestResourceReadyUrl = [&application](int eventTriggerCount, bool isSynchronous, const std::string& url, const std::string& mask, const char* location) {
3792     gResourceReadySignalCounter = 0;
3793
3794     Property::Map map;
3795     map[Toolkit::ImageVisual::Property::URL] = url;
3796     if(!mask.empty())
3797     {
3798       map[Toolkit::ImageVisual::Property::ALPHA_MASK_URL] = mask;
3799     }
3800     map[Toolkit::ImageVisual::Property::SYNCHRONOUS_LOADING] = isSynchronous;
3801
3802     ImageView imageView                            = ImageView::New();
3803     imageView[Toolkit::ImageView::Property::IMAGE] = map;
3804     imageView[Actor::Property::SIZE]               = Vector2(100.0f, 200.0f);
3805     imageView.ResourceReadySignal().Connect(&OnSimpleResourceReadySignal);
3806
3807     application.GetScene().Add(imageView);
3808     application.SendNotification();
3809     application.Render();
3810
3811     if(!isSynchronous)
3812     {
3813       // Wait for loading
3814       DALI_TEST_EQUALS(Test::WaitForEventThreadTrigger(eventTriggerCount), true, location);
3815     }
3816     tet_printf("test %s [sync:%d] signal fired\n", url.c_str(), isSynchronous ? 1 : 0);
3817     DALI_TEST_EQUALS(gResourceReadySignalCounter, 1, location);
3818
3819     imageView.Unparent();
3820   };
3821
3822   for(int synchronous = 0; synchronous <= 1; synchronous++)
3823   {
3824     tet_printf("Test normal case (sync:%d)\n", synchronous);
3825     TestResourceReadyUrl(1, synchronous, gImage_600_RGB, "", TEST_LOCATION);
3826     TestResourceReadyUrl(3, synchronous, gImage_600_RGB, gImage_34_RGBA, TEST_LOCATION); // 3 event trigger required : 2 image load + 1 apply mask
3827
3828     tet_printf("Test broken image case (sync:%d)\n", synchronous);
3829     TestResourceReadyUrl(1, synchronous, "invalid.jpg", "", TEST_LOCATION);
3830     TestResourceReadyUrl(2, synchronous, "invalid.jpg", gImage_34_RGBA, TEST_LOCATION);
3831
3832     tet_printf("Test broken mask image case (sync:%d)\n", synchronous);
3833     TestResourceReadyUrl(2, synchronous, gImage_600_RGB, "invalid.png", TEST_LOCATION);
3834
3835     tet_printf("Test broken both image, mask image case (sync:%d)\n", synchronous);
3836     TestResourceReadyUrl(2, synchronous, "invalid.jpg", "invalid.png", TEST_LOCATION);
3837   }
3838
3839   END_TEST;
3840 }
3841
3842 int UtcDaliImageViewOnResourceReadySignalWithBrokenAlphaMask02(void)
3843 {
3844   tet_infoline("Test signal handler when image try to use cached-and-broken mask image.");
3845
3846   ToolkitTestApplication application;
3847
3848   gResourceReadySignalCounter = 0;
3849
3850   auto TestBrokenMaskResourceReadyUrl = [&application](const std::string& url, const char* location) {
3851     Property::Map map;
3852     map[Toolkit::ImageVisual::Property::URL] = url;
3853     // Use invalid mask url
3854     map[Toolkit::ImageVisual::Property::ALPHA_MASK_URL] = "invalid.png";
3855
3856     ImageView imageView                            = ImageView::New();
3857     imageView[Toolkit::ImageView::Property::IMAGE] = map;
3858     imageView[Actor::Property::SIZE]               = Vector2(100.0f, 200.0f);
3859     imageView.ResourceReadySignal().Connect(&OnSimpleResourceReadySignal);
3860
3861     application.GetScene().Add(imageView);
3862
3863     // Don't unparent imageView, for keep the cache.
3864   };
3865
3866   // Use more than 4 images (The number of LocalImageLoadThread)
3867   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};
3868
3869   int expectResourceReadySignalCounter = 0;
3870
3871   for(auto& url : testUrlList)
3872   {
3873     TestBrokenMaskResourceReadyUrl(url, TEST_LOCATION);
3874     expectResourceReadySignalCounter++;
3875   }
3876
3877   // Remain 1 signal due to we use #URL + 1 mask image.
3878   DALI_TEST_EQUALS(Test::WaitForEventThreadTrigger(expectResourceReadySignalCounter + 1), true, TEST_LOCATION);
3879   application.SendNotification();
3880   application.Render();
3881   DALI_TEST_EQUALS(gResourceReadySignalCounter, expectResourceReadySignalCounter, TEST_LOCATION);
3882
3883   END_TEST;
3884 }
3885
3886 int UtcDaliImageViewCheckVariousCaseSendOnResourceReadySignal(void)
3887 {
3888   tet_infoline("Test signal handler various case.");
3889
3890   auto TestResourceReadyUrl = [](int eventTriggerCount, bool isSynchronous, bool loadSuccess, const std::string& url, const std::string& mask, const char* location) {
3891     ToolkitTestApplication application;
3892
3893     gResourceReadySignalCounter = 0;
3894
3895     Property::Map map;
3896     map[Toolkit::ImageVisual::Property::URL] = url;
3897     if(!mask.empty())
3898     {
3899       map[Toolkit::ImageVisual::Property::ALPHA_MASK_URL] = mask;
3900     }
3901     map[Toolkit::ImageVisual::Property::SYNCHRONOUS_LOADING] = isSynchronous;
3902
3903     ImageView imageView                            = ImageView::New();
3904     imageView[Toolkit::ImageView::Property::IMAGE] = map;
3905     imageView[Actor::Property::SIZE]               = Vector2(100.0f, 200.0f);
3906     imageView.ResourceReadySignal().Connect(&OnSimpleResourceReadySignal);
3907
3908     application.GetScene().Add(imageView);
3909     application.SendNotification();
3910     application.Render();
3911
3912     // Wait for loading
3913     DALI_TEST_EQUALS(Test::WaitForEventThreadTrigger(eventTriggerCount), true, location);
3914
3915     tet_printf("test %s [sync:%d] signal fired\n", url.c_str(), isSynchronous ? 1 : 0);
3916     DALI_TEST_EQUALS(gResourceReadySignalCounter, 1, location);
3917     DALI_TEST_EQUALS(imageView.GetVisualResourceStatus(Toolkit::ImageView::Property::IMAGE), loadSuccess ? Toolkit::Visual::ResourceStatus::READY : Toolkit::Visual::ResourceStatus::FAILED, location);
3918
3919     imageView.Unparent();
3920   };
3921
3922   auto TestAuxiliaryResourceReadyUrl = [](bool isSynchronous, bool loadSuccess, const std::string& url, const std::string& auxiliaryUrl, const char* location) {
3923     ToolkitTestApplication application;
3924
3925     gResourceReadySignalCounter = 0;
3926
3927     Property::Map map;
3928     map[Toolkit::ImageVisual::Property::URL]                        = url;
3929     map[Toolkit::DevelImageVisual::Property::AUXILIARY_IMAGE]       = auxiliaryUrl;
3930     map[Toolkit::DevelImageVisual::Property::AUXILIARY_IMAGE_ALPHA] = 0.5f;
3931     map[Toolkit::ImageVisual::Property::SYNCHRONOUS_LOADING]        = isSynchronous;
3932
3933     ImageView imageView = ImageView::New();
3934     imageView.SetProperty(Toolkit::ImageView::Property::IMAGE, map);
3935     imageView.SetProperty(Actor::Property::SIZE, Vector2(100.0f, 200.0f));
3936     imageView.ResourceReadySignal().Connect(&OnSimpleResourceReadySignal);
3937     application.GetScene().Add(imageView);
3938
3939     application.SendNotification();
3940     application.Render();
3941
3942     if(!isSynchronous)
3943     {
3944       // Wait for loading
3945       DALI_TEST_EQUALS(Test::WaitForEventThreadTrigger(2), true, location);
3946     }
3947
3948     tet_printf("test %s [sync:%d] signal fired\n", url.c_str(), isSynchronous ? 1 : 0);
3949     DALI_TEST_EQUALS(gResourceReadySignalCounter, 1, location);
3950     DALI_TEST_EQUALS(imageView.GetVisualResourceStatus(Toolkit::ImageView::Property::IMAGE), loadSuccess ? Toolkit::Visual::ResourceStatus::READY : Toolkit::Visual::ResourceStatus::FAILED, TEST_LOCATION);
3951
3952     imageView.Unparent();
3953   };
3954
3955   // Case 1 : asynchronous loading
3956   tet_printf("Test invalid single simple image Asynchronous\n");
3957
3958   // Test normal case
3959   TestResourceReadyUrl(1, 0, 1, gImage_600_RGB, "", TEST_LOCATION);
3960   TestResourceReadyUrl(2, 0, 1, TEST_SVG_FILE_NAME, "", TEST_LOCATION); // load & rasterize
3961   TestResourceReadyUrl(1, 0, 1, TEST_BROKEN_IMAGE_L, "", TEST_LOCATION);
3962
3963   TestResourceReadyUrl(2, 0, 1, TEST_GIF_FILE_NAME, "", TEST_LOCATION);                   // 2 image loading - batch size
3964   TestResourceReadyUrl(2, 0, 1, TEST_ANIMATED_VECTOR_IMAGE_FILE_NAME, "", TEST_LOCATION); // load & rasterize
3965
3966   TestResourceReadyUrl(3, 0, 1, gImage_600_RGB, gImage_34_RGBA, TEST_LOCATION); // 2 image loading + 1 applymask
3967
3968   TestAuxiliaryResourceReadyUrl(0, 1, TEST_BROKEN_IMAGE_L, gImage_34_RGBA, TEST_LOCATION);
3969
3970   // Test broken case
3971   TestResourceReadyUrl(1, 0, 0, "invalid.jpg", "", TEST_LOCATION);
3972   TestResourceReadyUrl(1, 0, 0, "invalid.svg", "", TEST_LOCATION);
3973   TestResourceReadyUrl(1, 0, 0, "invalid.9.png", "", TEST_LOCATION);
3974   TestResourceReadyUrl(1, 0, 0, "invalid.gif", "", TEST_LOCATION);  // 1 image loading
3975   TestResourceReadyUrl(1, 0, 0, "invalid.json", "", TEST_LOCATION); // 0 rasterize
3976
3977   TestResourceReadyUrl(2, 0, 0, "invalid.jpg", "invalid.png", TEST_LOCATION);  // 2 image loading
3978   TestResourceReadyUrl(2, 0, 1, gImage_600_RGB, "invalid.png", TEST_LOCATION); // 2 image loading
3979   TestResourceReadyUrl(2, 0, 0, "invalid.jpg", gImage_34_RGBA, TEST_LOCATION); // 2 image loading
3980
3981   TestAuxiliaryResourceReadyUrl(0, 0, "invalid.9.png", "invalid.png", TEST_LOCATION);
3982   TestAuxiliaryResourceReadyUrl(0, 1, TEST_BROKEN_IMAGE_L, "invalid.png", TEST_LOCATION);
3983   TestAuxiliaryResourceReadyUrl(0, 0, "invalid.9.png", gImage_34_RGBA, TEST_LOCATION);
3984
3985   // Case 2 : Synchronous loading
3986   tet_printf("Test invalid single simple image Synchronous\n");
3987
3988   // Test normal case
3989   TestResourceReadyUrl(0, 1, 1, gImage_600_RGB, "", TEST_LOCATION);
3990   TestResourceReadyUrl(0, 1, 1, TEST_SVG_FILE_NAME, "", TEST_LOCATION); // synchronous rasterize
3991   TestResourceReadyUrl(0, 1, 1, TEST_BROKEN_IMAGE_L, "", TEST_LOCATION);
3992
3993   TestResourceReadyUrl(1, 1, 1, TEST_GIF_FILE_NAME, "", TEST_LOCATION); // first frame image loading sync + second frame image loading async
3994
3995   TestResourceReadyUrl(0, 1, 1, gImage_600_RGB, gImage_34_RGBA, TEST_LOCATION);
3996
3997   TestAuxiliaryResourceReadyUrl(1, 1, TEST_BROKEN_IMAGE_L, gImage_34_RGBA, TEST_LOCATION);
3998
3999   // Test broken case
4000   TestResourceReadyUrl(0, 1, 0, "invalid.jpg", "", TEST_LOCATION);
4001   TestResourceReadyUrl(0, 1, 0, "invalid.svg", "", TEST_LOCATION);
4002   TestResourceReadyUrl(0, 1, 0, "invalid.9.png", "", TEST_LOCATION);
4003   TestResourceReadyUrl(0, 1, 0, "invalid.gif", "", TEST_LOCATION);
4004
4005   TestResourceReadyUrl(0, 1, 0, "invalid.jpg", "invalid.png", TEST_LOCATION);
4006   TestResourceReadyUrl(0, 1, 1, gImage_600_RGB, "invalid.png", TEST_LOCATION);
4007   TestResourceReadyUrl(0, 1, 0, "invalid.jpg", gImage_34_RGBA, TEST_LOCATION);
4008
4009   TestAuxiliaryResourceReadyUrl(1, 0, "invalid.9.png", "invalid.png", TEST_LOCATION);
4010   TestAuxiliaryResourceReadyUrl(1, 1, TEST_BROKEN_IMAGE_L, "invalid.png", TEST_LOCATION);
4011   TestAuxiliaryResourceReadyUrl(1, 0, "invalid.9.png", gImage_34_RGBA, TEST_LOCATION);
4012
4013   END_TEST;
4014 }
4015
4016 int UtcDaliImageViewSetImageOnResourceReadySignal04(void)
4017 {
4018   tet_infoline("Test texturemanager's remove queue works well within signal handler.");
4019
4020   ToolkitTestApplication application;
4021
4022   gResourceReadySignalCounter      = 0;
4023   gResourceReadySignal04ComesOrder = 0;
4024
4025   gImageView1 = ImageView::New("invalid.jpg"); // request invalid image, to make loading failed fast.
4026   gImageView1.ResourceReadySignal().Connect(&OnResourceReadySignal04);
4027   application.GetScene().Add(gImageView1);
4028
4029   gImageView2 = ImageView::New("invalid.png"); // request invalid image, to make loading failed fast.
4030   gImageView2.ResourceReadySignal().Connect(&OnResourceReadySignal04);
4031   application.GetScene().Add(gImageView2);
4032
4033   application.SendNotification();
4034   application.Render();
4035
4036   tet_infoline("Try to load 2 invalid image");
4037
4038   DALI_TEST_EQUALS(Test::WaitForEventThreadTrigger(2), true, TEST_LOCATION);
4039   DALI_TEST_EQUALS(gResourceReadySignalCounter, 2, TEST_LOCATION);
4040
4041   tet_infoline("load done");
4042
4043   // We can test this UTC only if gImageView1 and gImageView2 loaded done.
4044   if(gResourceReadySignal04ComesOrder == -1)
4045   {
4046     tet_infoline("Bad news.. gImageView3 or gImageView4 loaded faster than others. just skip this UTC");
4047   }
4048   else
4049   {
4050     // gImageView3 and gImageView4 load must not be successed yet.
4051     DALI_TEST_EQUALS(gImageView3.GetRendererCount(), 0u, TEST_LOCATION);
4052     DALI_TEST_EQUALS(gImageView4.GetRendererCount(), 0u, TEST_LOCATION);
4053
4054     application.SendNotification();
4055     application.Render();
4056
4057     tet_infoline("Try to load 2 valid image");
4058
4059     DALI_TEST_EQUALS(Test::WaitForEventThreadTrigger(2), true, TEST_LOCATION);
4060     DALI_TEST_EQUALS(gResourceReadySignalCounter, 4, TEST_LOCATION);
4061
4062     tet_infoline("load done");
4063
4064     // gImageView3 and gImageView4 load must be successed now.
4065     DALI_TEST_EQUALS(gImageView3.GetRendererAt(0).GetTextures().GetTextureCount(), 1u, TEST_LOCATION);
4066     DALI_TEST_EQUALS(gImageView4.GetRendererAt(0).GetTextures().GetTextureCount(), 1u, TEST_LOCATION);
4067   }
4068
4069   END_TEST;
4070 }
4071 int UtcDaliImageViewSetImageOnResourceReadySignal05(void)
4072 {
4073   tet_infoline("Test multiple views with same image during ResourceReady load the image only 1 times");
4074
4075   ToolkitTestApplication application;
4076
4077   gResourceReadySignalCounter = 0;
4078
4079   gImageView1 = ImageView::New("invalid.jpg"); // request invalid image, to make loading failed fast.
4080   gImageView1.ResourceReadySignal().Connect(&OnResourceReadySignal05);
4081   application.GetScene().Add(gImageView1);
4082
4083   application.SendNotification();
4084   application.Render();
4085
4086   tet_infoline("Try to load 1 invalid.jpg image");
4087   DALI_TEST_EQUALS(Test::WaitForEventThreadTrigger(1), true, TEST_LOCATION);
4088   DALI_TEST_EQUALS(gResourceReadySignalCounter, 1, TEST_LOCATION);
4089
4090   tet_infoline("Try to load 1 invalid2.jpg image");
4091   DALI_TEST_EQUALS(Test::WaitForEventThreadTrigger(1), true, TEST_LOCATION);
4092
4093   tet_infoline("Now we don't have any image to be loaded. Check event thread trigger failed.");
4094   DALI_TEST_EQUALS(Test::WaitForEventThreadTrigger(1, 1), false, TEST_LOCATION);
4095
4096   gImageView1.Unparent();
4097   gImageView1.Reset();
4098
4099   END_TEST;
4100 }
4101 int UtcDaliImageViewSetImageOnResourceReadySignal06(void)
4102 {
4103   tet_infoline("Test texturemanager's remove image & mask queue works well within signal handler.");
4104
4105   ToolkitTestApplication application;
4106
4107   gResourceReadySignalCounter      = 0;
4108   gResourceReadySignal06ComesOrder = 0;
4109
4110   Property::Map map;
4111   map[Toolkit::ImageVisual::Property::URL]            = "invalid.jpg";
4112   map[Toolkit::ImageVisual::Property::ALPHA_MASK_URL] = "invalid.png";
4113
4114   gImageView1 = ImageView::New(); // request invalid image, to make loading failed fast.
4115   gImageView1.SetProperty(Toolkit::ImageView::Property::IMAGE, map);
4116   gImageView1.ResourceReadySignal().Connect(&OnResourceReadySignal06);
4117   application.GetScene().Add(gImageView1);
4118
4119   gImageView2 = ImageView::New(); // request invalid image, to make loading failed fast.
4120   gImageView2.SetProperty(Toolkit::ImageView::Property::IMAGE, map);
4121   gImageView2.ResourceReadySignal().Connect(&OnResourceReadySignal06);
4122   application.GetScene().Add(gImageView2);
4123
4124   application.SendNotification();
4125   application.Render();
4126
4127   tet_infoline("Try to load 2 invalid image");
4128
4129   DALI_TEST_EQUALS(Test::WaitForEventThreadTrigger(2), true, TEST_LOCATION);
4130   DALI_TEST_EQUALS(gResourceReadySignalCounter, 2, TEST_LOCATION);
4131
4132   tet_infoline("load done");
4133
4134   // We can test this UTC only if gImageView1 and gImageView2 loaded done.
4135   if(gResourceReadySignal06ComesOrder == -1)
4136   {
4137     tet_infoline("Bad news.. gImageView3 or gImageView4 loaded faster than others. just skip this UTC");
4138   }
4139   else
4140   {
4141     // gImageView3 and gImageView4 load must not be successed yet.
4142     DALI_TEST_EQUALS(gImageView3.GetRendererCount(), 0u, TEST_LOCATION);
4143     DALI_TEST_EQUALS(gImageView4.GetRendererCount(), 0u, TEST_LOCATION);
4144
4145     application.GetScene().Add(gImageView3);
4146     application.GetScene().Add(gImageView4);
4147     application.SendNotification();
4148     application.Render();
4149
4150     tet_infoline("Try to load 2 valid image");
4151
4152     DALI_TEST_EQUALS(Test::WaitForEventThreadTrigger(2), true, TEST_LOCATION);
4153     DALI_TEST_EQUALS(gResourceReadySignalCounter, 2, TEST_LOCATION);
4154
4155     tet_infoline("load done");
4156   }
4157   END_TEST;
4158 }
4159
4160 int UtcDaliImageViewSetImageOnResourceReadySignal07(void)
4161 {
4162   tet_infoline("Test texturemanager's remove image & mask queue works well within signal handler 02.");
4163
4164   ToolkitTestApplication application;
4165
4166   gResourceReadySignalCounter = 0;
4167
4168   Property::Map map;
4169   map[Toolkit::ImageVisual::Property::URL] = TEST_IMAGE_1;
4170
4171   // Clear image view for clear test
4172
4173   if(gImageView1)
4174   {
4175     gImageView1.Reset();
4176   }
4177   if(gImageView2)
4178   {
4179     gImageView2.Reset();
4180   }
4181
4182   gImageView1 = ImageView::New();
4183   gImageView1.SetProperty(Toolkit::ImageView::Property::IMAGE, map);
4184   gImageView1.ResourceReadySignal().Connect(&OnResourceReadySignal07);
4185   application.GetScene().Add(gImageView1);
4186
4187   application.SendNotification();
4188   application.Render();
4189
4190   // Load gImageView1
4191
4192   DALI_TEST_EQUALS(Test::WaitForEventThreadTrigger(1), true, TEST_LOCATION);
4193   DALI_TEST_EQUALS(gResourceReadySignalCounter, 1, TEST_LOCATION);
4194
4195   tet_infoline("load image1 done");
4196
4197   // Load gImageView2 and mask
4198
4199   DALI_TEST_EQUALS(Test::WaitForEventThreadTrigger(2), true, TEST_LOCATION);
4200   DALI_TEST_EQUALS(gResourceReadySignalCounter, 1, TEST_LOCATION);
4201
4202   // gImageView2 mask apply done
4203
4204   DALI_TEST_EQUALS(Test::WaitForEventThreadTrigger(1), true, TEST_LOCATION);
4205   DALI_TEST_EQUALS(gResourceReadySignalCounter, 2, TEST_LOCATION);
4206
4207   tet_infoline("load image2 done");
4208   END_TEST;
4209 }
4210
4211 int UtcDaliImageViewUseSameUrlWithAnimatedImageVisual(void)
4212 {
4213   tet_infoline("Test multiple views with same image in animated image visual");
4214   ToolkitTestApplication application;
4215
4216   gImageView1 = ImageView::New(TEST_WEBP_FILE_NAME);
4217   application.GetScene().Add(gImageView1);
4218
4219   tet_infoline("Remove imageView and Create new imageView with same url");
4220   application.GetScene().Remove(gImageView1);
4221   gImageView2 = ImageView::New(TEST_WEBP_FILE_NAME);
4222   application.GetScene().Add(gImageView2);
4223
4224   application.SendNotification();
4225   application.Render();
4226
4227   tet_infoline("Check the ImageView load image successfully");
4228   DALI_TEST_EQUALS(Test::WaitForEventThreadTrigger(1), true, TEST_LOCATION);
4229   END_TEST;
4230 }
4231
4232 int UtcDaliImageViewNpatchImageCacheTest01(void)
4233 {
4234   tet_infoline("Test npatch image cached");
4235
4236   ToolkitTestApplication application;
4237   ImageView              imageView[2];
4238
4239   auto& gl = application.GetGlAbstraction();
4240   gl.EnableTextureCallTrace(true);
4241   auto& textureCallStack = gl.GetTextureTrace();
4242   textureCallStack.Enable(true);
4243   textureCallStack.EnableLogging(true);
4244
4245   auto TestNPatch = [&](int index, const std::string& nPatchImageUrl, const char* location) {
4246     if(imageView[index])
4247     {
4248       imageView[index].Unparent();
4249     }
4250     imageView[index] = ImageView::New(nPatchImageUrl);
4251     imageView[index].SetProperty(Actor::Property::SIZE, Vector2(100.0f, 200.0f));
4252     application.GetScene().Add(imageView[index]);
4253   };
4254
4255   TestNPatch(0, TEST_BROKEN_IMAGE_M, TEST_LOCATION);
4256   DALI_TEST_EQUALS(Test::WaitForEventThreadTrigger(1), true, TEST_LOCATION);
4257
4258   application.SendNotification();
4259   application.Render();
4260
4261   tet_printf("trace : \n%s\n", textureCallStack.GetTraceString().c_str());
4262
4263   // Check we gen only 1 textures
4264   DALI_TEST_EQUALS(textureCallStack.CountMethod("GenTextures"), 1, TEST_LOCATION);
4265   textureCallStack.Reset();
4266
4267   // Let we use cached textures
4268   for(int i = 0; i < 10; i++)
4269   {
4270     TestNPatch(1, TEST_BROKEN_IMAGE_M, TEST_LOCATION);
4271     TestNPatch(0, TEST_BROKEN_IMAGE_M, TEST_LOCATION);
4272   }
4273
4274   application.SendNotification();
4275   application.Render();
4276   // Check we use cached npatch data so we don't generate new texture textures
4277   DALI_TEST_EQUALS(textureCallStack.CountMethod("GenTextures"), 0, TEST_LOCATION);
4278
4279   // Clear all cached
4280   imageView[0].Unparent();
4281   imageView[0].Reset();
4282   imageView[1].Unparent();
4283   imageView[1].Reset();
4284
4285   application.SendNotification();
4286   application.Render();
4287
4288   textureCallStack.Reset();
4289   // Let we use deference textures
4290   TestNPatch(1, TEST_BROKEN_IMAGE_S, TEST_LOCATION);
4291   DALI_TEST_EQUALS(Test::WaitForEventThreadTrigger(1), true, TEST_LOCATION);
4292
4293   application.SendNotification();
4294   application.Render();
4295   // Try to load multiple times.
4296   for(int i = 0; i < 3; i++)
4297   {
4298     TestNPatch(0, TEST_BROKEN_IMAGE_M, TEST_LOCATION);
4299     DALI_TEST_EQUALS(Test::WaitForEventThreadTrigger(1), true, TEST_LOCATION);
4300     TestNPatch(1, TEST_BROKEN_IMAGE_S, TEST_LOCATION);
4301     DALI_TEST_EQUALS(Test::WaitForEventThreadTrigger(1), true, TEST_LOCATION);
4302   }
4303   application.SendNotification();
4304   application.Render();
4305
4306   imageView[0].Unparent();
4307   imageView[0].Reset();
4308   imageView[1].Unparent();
4309   imageView[1].Reset();
4310
4311   application.SendNotification();
4312   application.Render();
4313
4314   // Check memory leak
4315   DALI_TEST_EQUALS(textureCallStack.CountMethod("GenTextures"), textureCallStack.CountMethod("DeleteTextures"), TEST_LOCATION);
4316
4317   END_TEST;
4318 }
4319
4320 int UtcDaliImageViewNpatchImageCacheTest02(void)
4321 {
4322   tet_infoline("Test npatch image cached with border");
4323
4324   ToolkitTestApplication application;
4325   ImageView              imageView[2];
4326
4327   auto& gl = application.GetGlAbstraction();
4328   gl.EnableTextureCallTrace(true);
4329   auto& textureCallStack = gl.GetTextureTrace();
4330   textureCallStack.Enable(true);
4331   textureCallStack.EnableLogging(true);
4332
4333   auto TestBorderImage = [&](int index, const std::string& normalImageUrl, const Rect<int> border, const char* location) {
4334     Property::Map map;
4335     map[Toolkit::Visual::Property::TYPE]        = Toolkit::Visual::N_PATCH;
4336     map[Toolkit::ImageVisual::Property::URL]    = normalImageUrl;
4337     map[Toolkit::ImageVisual::Property::BORDER] = border;
4338
4339     imageView[index] = ImageView::New();
4340     imageView[index].SetProperty(Toolkit::ImageView::Property::IMAGE, map);
4341     imageView[index].SetProperty(Actor::Property::SIZE, Vector2(100.0f, 200.0f));
4342     application.GetScene().Add(imageView[index]);
4343   };
4344
4345   TestBorderImage(0, gImage_34_RGBA, Rect<int>(0, 0, 0, 0), TEST_LOCATION);
4346   DALI_TEST_EQUALS(Test::WaitForEventThreadTrigger(1), true, TEST_LOCATION);
4347
4348   application.SendNotification();
4349   application.Render();
4350
4351   tet_printf("trace : \n%s\n", textureCallStack.GetTraceString().c_str());
4352
4353   // Check we gen only 1 textures
4354   DALI_TEST_EQUALS(textureCallStack.CountMethod("GenTextures"), 1, TEST_LOCATION);
4355   textureCallStack.Reset();
4356
4357   // Let we use cached textures
4358   for(int i = 0; i < 10; i++)
4359   {
4360     TestBorderImage(0, gImage_34_RGBA, Rect<int>(i, i + 1, i + 2, i + 3), TEST_LOCATION);
4361     TestBorderImage(1, gImage_34_RGBA, Rect<int>(i + 1, i, i + 3, i + 2), TEST_LOCATION);
4362   }
4363
4364   application.SendNotification();
4365   application.Render();
4366
4367   // Check we use cached npatch data so we don't generate new texture textures
4368   DALI_TEST_EQUALS(textureCallStack.CountMethod("GenTextures"), 0, TEST_LOCATION);
4369
4370   END_TEST;
4371 }