Remove mask internally in texture manager
[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 void OnRelayoutOverride(Size size)
1278 {
1279   gNaturalSize = size; // Size Relayout is using
1280 }
1281
1282 int UtcDaliImageViewReplaceImageAndGetNaturalSize(void)
1283 {
1284   ToolkitTestApplication application;
1285
1286   // Check ImageView with background and main image, to ensure both visuals are marked as loaded
1287   ImageView imageView = ImageView::New(TEST_IMAGE_1);
1288   imageView.SetResizePolicy(ResizePolicy::USE_NATURAL_SIZE, Dimension::ALL_DIMENSIONS);
1289
1290   DummyControl        dummyControl = DummyControl::New(true);
1291   Impl::DummyControl& dummyImpl    = static_cast<Impl::DummyControl&>(dummyControl.GetImplementation());
1292   dummyControl.SetResizePolicy(ResizePolicy::FIT_TO_CHILDREN, Dimension::ALL_DIMENSIONS);
1293
1294   dummyControl.Add(imageView);
1295   dummyImpl.SetRelayoutCallback(&OnRelayoutOverride);
1296   application.GetScene().Add(dummyControl);
1297
1298   application.SendNotification();
1299   application.Render();
1300
1301   // loading started, this waits for the loader thread for max 30 seconds
1302   DALI_TEST_EQUALS(Test::WaitForEventThreadTrigger(1), true, TEST_LOCATION);
1303
1304   DALI_TEST_EQUALS(gNaturalSize.width, 1024.0f, TEST_LOCATION);
1305   DALI_TEST_EQUALS(gNaturalSize.height, 1024.0f, TEST_LOCATION);
1306
1307   gNaturalSize = Vector3::ZERO;
1308
1309   imageView.SetImage(gImage_600_RGB);
1310
1311   // Waiting for resourceReady so SendNotifcation not called here.
1312
1313   // loading started, this waits for the loader thread for max 30 seconds
1314   DALI_TEST_EQUALS(Test::WaitForEventThreadTrigger(1), true, TEST_LOCATION);
1315
1316   // Trigger a potential relayout
1317   application.SendNotification();
1318   application.Render();
1319
1320   DALI_TEST_EQUALS(gNaturalSize.width, 600.0f, TEST_LOCATION);
1321   DALI_TEST_EQUALS(gNaturalSize.height, 600.0f, TEST_LOCATION);
1322
1323   END_TEST;
1324 }
1325
1326 int UtcDaliImageViewResourceReadySignalWithImmediateLoad(void)
1327 {
1328   tet_infoline("Test Setting Image with IMMEDIATE load and receving ResourceReadySignal before staged.");
1329
1330   ToolkitTestApplication application;
1331
1332   gResourceReadySignalFired = false;
1333
1334   Property::Map imageMap;
1335
1336   imageMap[ImageVisual::Property::URL]         = gImage_34_RGBA;
1337   imageMap[ImageVisual::Property::LOAD_POLICY] = ImageVisual::LoadPolicy::IMMEDIATE;
1338
1339   tet_infoline("Creating ImageView without URL so image does not start loading");
1340   ImageView imageView = ImageView::New();
1341   tet_infoline("Connect to image loaded signal before setting image");
1342   imageView.ResourceReadySignal().Connect(&ResourceReadySignal);
1343   tet_infoline("Setting Image with IMMEDIATE load, signal already connected so will be triggered.");
1344   imageView.SetProperty(ImageView::Property::IMAGE, imageMap);
1345
1346   // loading started, this waits for the loader thread
1347   DALI_TEST_EQUALS(Test::WaitForEventThreadTrigger(1), true, TEST_LOCATION);
1348
1349   application.SendNotification();
1350   application.Render(16);
1351
1352   DALI_TEST_EQUALS(gResourceReadySignalFired, true, TEST_LOCATION);
1353
1354   END_TEST;
1355 }
1356
1357 int UtcDaliImageViewResourceReadySignalWithReusedImage(void)
1358 {
1359   tet_infoline("Test Setting Image that was already loaded by another ImageView and still getting ResourceReadySignal.");
1360
1361   ToolkitTestApplication application;
1362
1363   gResourceReadySignalFired = false;
1364
1365   Property::Map imageMap;
1366
1367   imageMap[ImageVisual::Property::URL]         = gImage_34_RGBA;
1368   imageMap[ImageVisual::Property::LOAD_POLICY] = ImageVisual::LoadPolicy::IMMEDIATE;
1369
1370   ImageView imageView = ImageView::New();
1371   imageView.ResourceReadySignal().Connect(&ResourceReadySignal);
1372   imageView.SetProperty(ImageView::Property::IMAGE, imageMap);
1373
1374   // loading started, this waits for the loader thread
1375   DALI_TEST_EQUALS(Test::WaitForEventThreadTrigger(1), true, TEST_LOCATION);
1376
1377   application.SendNotification();
1378   application.Render(16);
1379
1380   DALI_TEST_EQUALS(gResourceReadySignalFired, true, TEST_LOCATION);
1381   gResourceReadySignalFired = false;
1382
1383   ImageView imageViewWithExistingImage = ImageView::New();
1384   imageViewWithExistingImage.ResourceReadySignal().Connect(&ResourceReadySignal);
1385   imageViewWithExistingImage.SetProperty(ImageView::Property::IMAGE, imageMap);
1386
1387   DALI_TEST_EQUALS(gResourceReadySignalFired, true, TEST_LOCATION);
1388
1389   END_TEST;
1390 }
1391
1392 int UtcDaliImageViewResourceReadySignalWithReusedImage02(void)
1393 {
1394   tet_infoline("Test Setting Image that was already loaded by another ImageView and still getting ResourceReadySignal when staged.");
1395
1396   ToolkitTestApplication application;
1397
1398   gResourceReadySignalFired = false;
1399
1400   Property::Map imageImmediateLoadingMap;
1401   imageImmediateLoadingMap[ImageVisual::Property::URL]         = gImage_34_RGBA;
1402   imageImmediateLoadingMap[ImageVisual::Property::LOAD_POLICY] = ImageVisual::LoadPolicy::IMMEDIATE;
1403
1404   tet_infoline("Immediate load an image");
1405   ImageView imageView = ImageView::New();
1406   imageView.ResourceReadySignal().Connect(&ResourceReadySignal);
1407   imageView.SetProperty(ImageView::Property::IMAGE, imageImmediateLoadingMap);
1408
1409   // loading started, this waits for the loader thread
1410   DALI_TEST_EQUALS(Test::WaitForEventThreadTrigger(1), true, TEST_LOCATION);
1411
1412   application.SendNotification();
1413   application.Render(16);
1414
1415   tet_infoline("Check image loaded");
1416   DALI_TEST_EQUALS(gResourceReadySignalFired, true, TEST_LOCATION);
1417   gResourceReadySignalFired = false;
1418
1419   tet_infoline("Create another ImageView with the same URL");
1420   ImageView imageViewWithExistingImage = ImageView::New(gImage_34_RGBA);
1421   tet_infoline("Connect to ResourceReady signal for second ImageView, it should still fire as resource is ready");
1422   imageViewWithExistingImage.ResourceReadySignal().Connect(&ResourceReadySignal);
1423
1424   application.GetScene().Add(imageViewWithExistingImage);
1425
1426   DALI_TEST_EQUALS(gResourceReadySignalFired, true, TEST_LOCATION);
1427
1428   END_TEST;
1429 }
1430
1431 int UtcDaliImageViewPaddingProperty(void)
1432 {
1433   ToolkitTestApplication application;
1434
1435   ImageView     imageView = ImageView::New();
1436   Property::Map imagePropertyMap;
1437   imagePropertyMap[Toolkit::Visual::Property::TYPE]       = Toolkit::Visual::IMAGE;
1438   imagePropertyMap[Toolkit::ImageVisual::Property::URL]   = TEST_RESOURCE_DIR "/gallery-small-1.jpg";
1439   imagePropertyMap[ImageVisual::Property::DESIRED_WIDTH]  = 128;
1440   imagePropertyMap[ImageVisual::Property::DESIRED_HEIGHT] = 128;
1441   imageView.SetProperty(Toolkit::ImageView::Property::IMAGE, imagePropertyMap);
1442   imageView.SetProperty(Actor::Property::ANCHOR_POINT, AnchorPoint::TOP_LEFT);
1443   imageView.SetProperty(Actor::Property::PARENT_ORIGIN, ParentOrigin::TOP_LEFT);
1444   imageView.SetProperty(Control::Property::PADDING, Extents(15, 10, 5, 10));
1445   application.GetScene().Add(imageView);
1446
1447   application.SendNotification();
1448   application.Render();
1449
1450   DALI_TEST_EQUALS(imageView.GetProperty<Extents>(Control::Property::PADDING), Extents(15, 10, 5, 10), TEST_LOCATION);
1451
1452   ImageView childImage = ImageView::New();
1453   childImage.SetBackgroundColor(Color::BLACK);
1454   childImage.SetProperty(Actor::Property::SIZE, Vector2(10.f, 10.f));
1455   imageView.Add(childImage);
1456
1457   application.SendNotification();
1458   application.Render();
1459
1460   // Child ImageView should be positioned dependinig on Parent ImageView's Padding value
1461   DALI_TEST_EQUALS(childImage.GetProperty<Vector3>(Dali::Actor::Property::POSITION), Vector3(15, 5, 0), TEST_LOCATION);
1462
1463   // Check whether Image Visual transforms on ImageVieiw::OnRelayout()
1464   Toolkit::Internal::Control& controlImpl = Toolkit::Internal::GetImplementation(imageView);
1465   Toolkit::Visual::Base       imageVisual = DevelControl::GetVisual(controlImpl, ImageView::Property::IMAGE);
1466   Property::Map               resultMap;
1467   imageVisual.CreatePropertyMap(resultMap);
1468
1469   Property::Value* transformValue = resultMap.Find(Visual::Property::TRANSFORM);
1470   DALI_TEST_CHECK(transformValue);
1471   Property::Map* retMap = transformValue->GetMap();
1472   DALI_TEST_CHECK(retMap);
1473
1474   // Image Visual should be positioned depending on ImageView's padding
1475   DALI_TEST_EQUALS(retMap->Find(Visual::Transform::Property::OFFSET)->Get<Vector2>(), Vector2(15, 5), TEST_LOCATION);
1476
1477   END_TEST;
1478 }
1479
1480 int UtcDaliImageViewPaddingProperty02(void)
1481 {
1482   ToolkitTestApplication application;
1483
1484   ImageView     imageView = ImageView::New();
1485   Property::Map imagePropertyMap;
1486   imagePropertyMap[Toolkit::Visual::Property::TYPE]            = Toolkit::Visual::IMAGE;
1487   imagePropertyMap[Toolkit::ImageVisual::Property::URL]        = TEST_RESOURCE_DIR "/Kid1.svg";
1488   imagePropertyMap[ImageVisual::Property::DESIRED_WIDTH]       = 128;
1489   imagePropertyMap[ImageVisual::Property::DESIRED_HEIGHT]      = 128;
1490   imagePropertyMap[DevelVisual::Property::VISUAL_FITTING_MODE] = Toolkit::DevelVisual::FIT_KEEP_ASPECT_RATIO;
1491   imageView.SetProperty(Toolkit::ImageView::Property::IMAGE, imagePropertyMap);
1492   imageView.SetProperty(Actor::Property::ANCHOR_POINT, AnchorPoint::TOP_LEFT);
1493   imageView.SetProperty(Actor::Property::PARENT_ORIGIN, ParentOrigin::TOP_LEFT);
1494   imageView.SetProperty(Control::Property::PADDING, Extents(15, 10, 5, 10));
1495   application.GetScene().Add(imageView);
1496
1497   application.SendNotification();
1498   application.Render();
1499
1500   DALI_TEST_EQUALS(imageView.GetProperty<Extents>(Control::Property::PADDING), Extents(15, 10, 5, 10), TEST_LOCATION);
1501
1502   // Check whether Image Visual transforms on ImageVieiw::OnRelayout()
1503   Toolkit::Internal::Control& controlImpl = Toolkit::Internal::GetImplementation(imageView);
1504   Toolkit::Visual::Base       imageVisual = DevelControl::GetVisual(controlImpl, ImageView::Property::IMAGE);
1505   Property::Map               resultMap;
1506   imageVisual.CreatePropertyMap(resultMap);
1507
1508   Property::Value* transformValue = resultMap.Find(Visual::Property::TRANSFORM);
1509   DALI_TEST_CHECK(transformValue);
1510   Property::Map* retMap = transformValue->GetMap();
1511   DALI_TEST_CHECK(retMap);
1512
1513   // Image Visual should be positioned depending on ImageView's padding
1514   DALI_TEST_EQUALS(retMap->Find(Visual::Transform::Property::OFFSET)->Get<Vector2>(), Vector2(15, 5), TEST_LOCATION);
1515
1516   END_TEST;
1517 }
1518
1519 int UtcDaliImageViewPaddingProperty03(void)
1520 {
1521   tet_infoline("Test Setting Image Padding then removing it.");
1522
1523   ToolkitTestApplication application;
1524
1525   ImageView     imageView = ImageView::New();
1526   Property::Map imagePropertyMap;
1527   imagePropertyMap[Toolkit::Visual::Property::TYPE]            = Toolkit::Visual::IMAGE;
1528   imagePropertyMap[Toolkit::ImageVisual::Property::URL]        = TEST_RESOURCE_DIR "/Kid1.svg";
1529   imagePropertyMap[ImageVisual::Property::DESIRED_WIDTH]       = 128;
1530   imagePropertyMap[ImageVisual::Property::DESIRED_HEIGHT]      = 128;
1531   imagePropertyMap[DevelVisual::Property::VISUAL_FITTING_MODE] = Toolkit::DevelVisual::FIT_KEEP_ASPECT_RATIO;
1532   imageView.SetProperty(Toolkit::ImageView::Property::IMAGE, imagePropertyMap);
1533   imageView.SetProperty(Actor::Property::ANCHOR_POINT, AnchorPoint::TOP_LEFT);
1534   imageView.SetProperty(Actor::Property::PARENT_ORIGIN, ParentOrigin::TOP_LEFT);
1535   imageView.SetProperty(Control::Property::PADDING, Extents(15, 10, 5, 10));
1536   application.GetScene().Add(imageView);
1537
1538   application.SendNotification();
1539   application.Render();
1540
1541   DALI_TEST_EQUALS(imageView.GetProperty<Extents>(Control::Property::PADDING), Extents(15, 10, 5, 10), TEST_LOCATION);
1542
1543   tet_infoline("Remove Padding and test Visual is position correctly");
1544
1545   imageView.SetProperty(Control::Property::PADDING, Extents(0, 0, 0, 0));
1546
1547   application.SendNotification();
1548   application.Render();
1549
1550   // Check whether Image Visual transforms on ImageVieiw::OnRelayout()
1551   Toolkit::Internal::Control& controlImpl = Toolkit::Internal::GetImplementation(imageView);
1552   Toolkit::Visual::Base       imageVisual = DevelControl::GetVisual(controlImpl, ImageView::Property::IMAGE);
1553   Property::Map               resultMap;
1554   imageVisual.CreatePropertyMap(resultMap);
1555
1556   Property::Value* transformValue = resultMap.Find(Visual::Property::TRANSFORM);
1557   DALI_TEST_CHECK(transformValue);
1558   Property::Map* retMap = transformValue->GetMap();
1559   DALI_TEST_CHECK(retMap);
1560
1561   // Image Visual should be positioned depending on ImageView's padding
1562   DALI_TEST_EQUALS(retMap->Find(Visual::Transform::Property::OFFSET)->Get<Vector2>(), Vector2(0, 0), TEST_LOCATION);
1563
1564   END_TEST;
1565 }
1566
1567 int UtcDaliImageViewPaddingProperty04(void)
1568 {
1569   tet_infoline("Test Setting Image Padding then removing it. Visual Fitting Mode as Fill");
1570
1571   ToolkitTestApplication application;
1572
1573   ImageView     imageView = ImageView::New();
1574   Property::Map imagePropertyMap;
1575   imagePropertyMap[Toolkit::Visual::Property::TYPE]            = Toolkit::Visual::IMAGE;
1576   imagePropertyMap[Toolkit::ImageVisual::Property::URL]        = TEST_RESOURCE_DIR "/Kid1.svg";
1577   imagePropertyMap[ImageVisual::Property::DESIRED_WIDTH]       = 128;
1578   imagePropertyMap[ImageVisual::Property::DESIRED_HEIGHT]      = 128;
1579   imagePropertyMap[DevelVisual::Property::VISUAL_FITTING_MODE] = Toolkit::DevelVisual::FILL;
1580   imageView.SetProperty(Toolkit::ImageView::Property::IMAGE, imagePropertyMap);
1581   imageView.SetProperty(Actor::Property::ANCHOR_POINT, AnchorPoint::TOP_LEFT);
1582   imageView.SetProperty(Actor::Property::PARENT_ORIGIN, ParentOrigin::TOP_LEFT);
1583   imageView.SetProperty(Control::Property::PADDING, Extents(15, 10, 5, 10));
1584   application.GetScene().Add(imageView);
1585
1586   application.SendNotification();
1587   application.Render();
1588
1589   DALI_TEST_EQUALS(imageView.GetProperty<Extents>(Control::Property::PADDING), Extents(15, 10, 5, 10), TEST_LOCATION);
1590
1591   tet_infoline("Remove Padding and test Visual is position correctly");
1592
1593   imageView.SetProperty(Control::Property::PADDING, Extents(0, 0, 0, 0));
1594
1595   application.SendNotification();
1596   application.Render();
1597
1598   // Check whether Image Visual transforms on ImageVieiw::OnRelayout()
1599   Toolkit::Internal::Control& controlImpl = Toolkit::Internal::GetImplementation(imageView);
1600   Toolkit::Visual::Base       imageVisual = DevelControl::GetVisual(controlImpl, ImageView::Property::IMAGE);
1601   Property::Map               resultMap;
1602   imageVisual.CreatePropertyMap(resultMap);
1603
1604   Property::Value* transformValue = resultMap.Find(Visual::Property::TRANSFORM);
1605   DALI_TEST_CHECK(transformValue);
1606   Property::Map* retMap = transformValue->GetMap();
1607   DALI_TEST_CHECK(retMap);
1608
1609   // Image Visual should be positioned depending on ImageView's padding
1610   DALI_TEST_EQUALS(retMap->Find(Visual::Transform::Property::OFFSET)->Get<Vector2>(), Vector2(0, 0), TEST_LOCATION);
1611
1612   END_TEST;
1613 }
1614
1615 int UtcDaliImageViewTransformTest01(void)
1616 {
1617   tet_infoline("Test Setting a offset transform on the ImageView");
1618
1619   ToolkitTestApplication application;
1620
1621   ImageView     imageView = ImageView::New();
1622   Property::Map imagePropertyMap;
1623   imagePropertyMap.Add(Toolkit::Visual::Property::TYPE, Toolkit::Visual::IMAGE)
1624     .Add(Toolkit::ImageVisual::Property::URL, TEST_RESOURCE_DIR "/Kid1.svg")
1625     .Add(ImageVisual::Property::DESIRED_WIDTH, 120)
1626     .Add(ImageVisual::Property::DESIRED_HEIGHT, 120)
1627     .Add(DevelVisual::Property::VISUAL_FITTING_MODE, Toolkit::DevelVisual::FILL)
1628     .Add(Visual::Property::TRANSFORM,
1629          Property::Map().Add(Toolkit::Visual::Transform::Property::OFFSET_POLICY,
1630                              Vector2(Visual::Transform::Policy::ABSOLUTE, Visual::Transform::Policy::ABSOLUTE))
1631            .Add(Toolkit::Visual::Transform::Property::OFFSET, Vector2(8, 8)));
1632
1633   imageView.SetProperty(Toolkit::ImageView::Property::IMAGE, imagePropertyMap);
1634   imageView.SetProperty(Actor::Property::ANCHOR_POINT, AnchorPoint::TOP_LEFT);
1635   imageView.SetProperty(Actor::Property::PARENT_ORIGIN, ParentOrigin::TOP_LEFT);
1636   application.GetScene().Add(imageView);
1637
1638   application.SendNotification();
1639   application.Render();
1640
1641   // Check whether Image Visual transforms on ImageVieiw::OnRelayout()
1642   Toolkit::Internal::Control& controlImpl = Toolkit::Internal::GetImplementation(imageView);
1643   Toolkit::Visual::Base       imageVisual = DevelControl::GetVisual(controlImpl, ImageView::Property::IMAGE);
1644   Property::Map               resultMap;
1645   imageVisual.CreatePropertyMap(resultMap);
1646
1647   Property::Value* transformValue = resultMap.Find(Visual::Property::TRANSFORM);
1648   DALI_TEST_CHECK(transformValue);
1649   Property::Map* retMap = transformValue->GetMap();
1650   DALI_TEST_CHECK(retMap);
1651
1652   // Image Visual should be positioned depending on ImageView's padding
1653   DALI_TEST_EQUALS(retMap->Find(Visual::Transform::Property::OFFSET)->Get<Vector2>(), Vector2(8, 8), TEST_LOCATION);
1654   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);
1655
1656   END_TEST;
1657 }
1658
1659 int UtcDaliImageViewUsingAtlasAndGetNaturalSize(void)
1660 {
1661   ToolkitTestApplication application;
1662
1663   // Check ImageView with background and main image, to ensure both visuals are marked as loaded
1664   ImageView     imageView = ImageView::New();
1665   Property::Map imageMap;
1666   imageMap[Toolkit::Visual::Property::TYPE]          = Toolkit::Visual::IMAGE;
1667   imageMap[Toolkit::ImageVisual::Property::URL]      = gImage_34_RGBA;
1668   imageMap[Toolkit::ImageVisual::Property::ATLASING] = true;
1669   imageView.SetProperty(Toolkit::ImageView::Property::IMAGE, imageMap);
1670   application.GetScene().Add(imageView);
1671
1672   // Trigger a potential relayout
1673   application.SendNotification();
1674   application.Render();
1675
1676   Vector3 naturalSize = imageView.GetNaturalSize();
1677
1678   DALI_TEST_EQUALS(naturalSize.width, 34.0f, TEST_LOCATION);
1679   DALI_TEST_EQUALS(naturalSize.height, 34.0f, TEST_LOCATION);
1680
1681   END_TEST;
1682 }
1683
1684 int UtcDaliImageViewFillMode(void)
1685 {
1686   ToolkitTestApplication application;
1687
1688   tet_infoline("Create an ImageVisual without padding and set the fill-mode to fill");
1689
1690   ImageView     imageView = ImageView::New();
1691   Property::Map imageMap;
1692   imageMap.Add(Toolkit::Visual::Property::TYPE, Toolkit::Visual::IMAGE);
1693   imageMap.Add(Toolkit::ImageVisual::Property::URL, gImage_600_RGB);
1694   imageMap.Add(DevelVisual::Property::VISUAL_FITTING_MODE, DevelVisual::FittingMode::FILL);
1695
1696   imageView.SetProperty(Toolkit::ImageView::Property::IMAGE, imageMap);
1697
1698   application.GetScene().Add(imageView);
1699
1700   // Trigger a potential relayout
1701   application.SendNotification();
1702   application.Render();
1703
1704   Toolkit::Visual::Base visual = DevelControl::GetVisual(Toolkit::Internal::GetImplementation(imageView), Toolkit::ImageView::Property::IMAGE);
1705   Property::Map         returnedMap;
1706   visual.CreatePropertyMap(returnedMap);
1707
1708   Property::Value* value = returnedMap.Find(Toolkit::Visual::Property::TRANSFORM);
1709   DALI_TEST_CHECK(value);
1710   Property::Map* map = value->GetMap();
1711   DALI_TEST_CHECK(map);
1712
1713   value = map->Find(Toolkit::Visual::Transform::Property::SIZE);
1714   DALI_TEST_CHECK(value);
1715   DALI_TEST_EQUALS(value->Get<Vector2>(), Vector2::ONE, TEST_LOCATION);
1716
1717   value = map->Find(Toolkit::Visual::Transform::Property::SIZE_POLICY);
1718   DALI_TEST_CHECK(value);
1719   DALI_TEST_CHECK(value->Get<int>() == Toolkit::Visual::Transform::Policy::RELATIVE);
1720
1721   END_TEST;
1722 }
1723
1724 int UtcDaliImageViewFittingModeFitKeepAspectRatio(void)
1725 {
1726   ToolkitTestApplication application;
1727
1728   tet_infoline("Create an ImageVisual using FitKeepAspectRatio ( image: [600,600], view: [600,700] )");
1729   tet_infoline("  There should be need to change the transform, offset is adjusted to fit inside");
1730
1731   ImageView     imageView = ImageView::New();
1732   Property::Map imageMap;
1733   imageMap.Add(Toolkit::Visual::Property::TYPE, Toolkit::Visual::IMAGE);
1734   imageMap.Add(Toolkit::ImageVisual::Property::URL, gImage_600_RGB); // 600x600 image
1735   imageMap.Add(DevelVisual::Property::VISUAL_FITTING_MODE, Toolkit::DevelVisual::FIT_KEEP_ASPECT_RATIO);
1736
1737   imageView.SetProperty(Toolkit::ImageView::Property::IMAGE, imageMap);
1738   imageView.SetProperty(Actor::Property::SIZE, Vector2(600, 700));
1739
1740   application.GetScene().Add(imageView);
1741
1742   // Trigger a potential relayout
1743   application.SendNotification();
1744   application.Render();
1745
1746   Toolkit::Visual::Base visual = DevelControl::GetVisual(Toolkit::Internal::GetImplementation(imageView), Toolkit::ImageView::Property::IMAGE);
1747   Property::Map         returnedMap;
1748   visual.CreatePropertyMap(returnedMap);
1749
1750   Property::Value* value = returnedMap.Find(Toolkit::Visual::Property::TRANSFORM);
1751   DALI_TEST_CHECK(value);
1752   Property::Map* map = value->GetMap();
1753   DALI_TEST_CHECK(map);
1754
1755   // If there's
1756   value = map->Find(Toolkit::Visual::Transform::Property::SIZE);
1757   DALI_TEST_CHECK(value);
1758   DALI_TEST_EQUALS(value->Get<Vector2>(), Vector2(600, 600), TEST_LOCATION);
1759
1760   value = map->Find(Toolkit::Visual::Transform::Property::SIZE_POLICY);
1761   DALI_TEST_CHECK(value);
1762   DALI_TEST_EQUALS(value->Get<Vector2>(), Vector2(Toolkit::Visual::Transform::Policy::ABSOLUTE, Toolkit::Visual::Transform::Policy::ABSOLUTE), TEST_LOCATION);
1763
1764   value = map->Find(Toolkit::Visual::Transform::Property::OFFSET);
1765   DALI_TEST_CHECK(value);
1766   DALI_TEST_EQUALS(value->Get<Vector2>(), Vector2(0, 50), TEST_LOCATION);
1767
1768   END_TEST;
1769 }
1770
1771 int UtcDaliImageViewFittingModesFill(void)
1772 {
1773   ToolkitTestApplication application;
1774
1775   tet_infoline("Create an ImageVisual using Fill ( image: [600,600], view: [600,700] )");
1776   tet_infoline("  There should be no need to change the transform, only size is changed to fit view");
1777
1778   ImageView     imageView = ImageView::New();
1779   Property::Map imageMap;
1780   imageMap.Add(Toolkit::Visual::Property::TYPE, Toolkit::Visual::IMAGE);
1781   imageMap.Add(Toolkit::ImageVisual::Property::URL, gImage_600_RGB); // 600x600 image
1782   imageMap.Add(DevelVisual::Property::VISUAL_FITTING_MODE, Toolkit::DevelVisual::FILL);
1783
1784   imageView.SetProperty(Toolkit::ImageView::Property::IMAGE, imageMap);
1785   imageView.SetProperty(Actor::Property::SIZE, Vector2(600, 700));
1786
1787   application.GetScene().Add(imageView);
1788
1789   // Trigger a potential relayout
1790   application.SendNotification();
1791   application.Render();
1792
1793   Toolkit::Visual::Base visual = DevelControl::GetVisual(Toolkit::Internal::GetImplementation(imageView), Toolkit::ImageView::Property::IMAGE);
1794   Property::Map         returnedMap;
1795   visual.CreatePropertyMap(returnedMap);
1796
1797   Property::Value* value = returnedMap.Find(Toolkit::Visual::Property::TRANSFORM);
1798   DALI_TEST_CHECK(value);
1799   Property::Map* map = value->GetMap();
1800   DALI_TEST_CHECK(map);
1801
1802   value = map->Find(Toolkit::Visual::Transform::Property::SIZE);
1803   DALI_TEST_CHECK(value);
1804   DALI_TEST_EQUALS(value->Get<Vector2>(), Vector2::ONE, TEST_LOCATION); // Change the internal size according to the image view size
1805
1806   value = map->Find(Toolkit::Visual::Transform::Property::SIZE_POLICY);
1807   DALI_TEST_CHECK(value);
1808   DALI_TEST_CHECK(value->Get<int>() == Toolkit::Visual::Transform::Policy::RELATIVE);
1809
1810   value = map->Find(Toolkit::Visual::Transform::Property::OFFSET);
1811   DALI_TEST_CHECK(value);
1812   DALI_TEST_EQUALS(value->Get<Vector2>(), Vector2(0, 0), TEST_LOCATION); // OFFSET is zero
1813
1814   END_TEST;
1815 }
1816
1817 int UtcDaliImageViewFittingModesOverfitKeepAspectRatio(void)
1818 {
1819   ToolkitTestApplication application;
1820
1821   tet_infoline("Create an ImageVisual using OverFitKeepAspectRatio ( image: [600,600], view: [600,500] )");
1822   tet_infoline("  offset or size is the same as view, but adjust internally using pixelArea ");
1823
1824   ImageView     imageView = ImageView::New();
1825   Property::Map imageMap;
1826   imageMap.Add(Toolkit::Visual::Property::TYPE, Toolkit::Visual::IMAGE);
1827   imageMap.Add(Toolkit::ImageVisual::Property::URL, gImage_600_RGB); // 600x600 image
1828   imageMap.Add(DevelVisual::Property::VISUAL_FITTING_MODE, Toolkit::DevelVisual::OVER_FIT_KEEP_ASPECT_RATIO);
1829
1830   imageView.SetProperty(Toolkit::ImageView::Property::IMAGE, imageMap);
1831   imageView.SetProperty(Actor::Property::SIZE, Vector2(600, 500));
1832
1833   application.GetScene().Add(imageView);
1834
1835   // Trigger a potential relayout
1836   application.SendNotification();
1837   application.Render();
1838
1839   Toolkit::Visual::Base visual = DevelControl::GetVisual(Toolkit::Internal::GetImplementation(imageView), Toolkit::ImageView::Property::IMAGE);
1840   Property::Map         returnedMap;
1841   visual.CreatePropertyMap(returnedMap);
1842
1843   Property::Value* value = returnedMap.Find(Toolkit::Visual::Property::TRANSFORM);
1844   DALI_TEST_CHECK(value);
1845   Property::Map* map = value->GetMap();
1846   DALI_TEST_CHECK(map);
1847
1848   // If there's
1849   value = map->Find(Toolkit::Visual::Transform::Property::SIZE);
1850   DALI_TEST_CHECK(value);
1851   DALI_TEST_EQUALS(value->Get<Vector2>(), Vector2(600, 500), TEST_LOCATION); // Change the internal size according to the image view size
1852
1853   value = map->Find(Toolkit::Visual::Transform::Property::SIZE_POLICY);
1854   DALI_TEST_CHECK(value);
1855   DALI_TEST_EQUALS(value->Get<Vector2>(), Vector2(Toolkit::Visual::Transform::Policy::ABSOLUTE, Toolkit::Visual::Transform::Policy::ABSOLUTE), TEST_LOCATION);
1856
1857   value = map->Find(Toolkit::Visual::Transform::Property::OFFSET);
1858   DALI_TEST_CHECK(value);
1859   DALI_TEST_EQUALS(value->Get<Vector2>(), Vector2(0, 0), TEST_LOCATION); // OFFSET is zero
1860
1861   END_TEST;
1862 }
1863
1864 int UtcDaliImageViewFittingModesCenter01(void)
1865 {
1866   ToolkitTestApplication application;
1867
1868   tet_infoline("Create an ImageVisual using Center ( image: [600,600], view: [700,700] )");
1869   tet_infoline("  There should be need to change the transform, offset is adjusted to fit inside");
1870
1871   ImageView     imageView = ImageView::New();
1872   Property::Map imageMap;
1873   imageMap.Add(Toolkit::Visual::Property::TYPE, Toolkit::Visual::IMAGE);
1874   imageMap.Add(Toolkit::ImageVisual::Property::URL, gImage_600_RGB); // 600x600 image
1875   imageMap.Add(DevelVisual::Property::VISUAL_FITTING_MODE, Toolkit::DevelVisual::CENTER);
1876
1877   imageView.SetProperty(Toolkit::ImageView::Property::IMAGE, imageMap);
1878   imageView.SetProperty(Actor::Property::SIZE, Vector2(700, 700));
1879
1880   application.GetScene().Add(imageView);
1881
1882   // Trigger a potential relayout
1883   application.SendNotification();
1884   application.Render();
1885
1886   Toolkit::Visual::Base visual = DevelControl::GetVisual(Toolkit::Internal::GetImplementation(imageView), Toolkit::ImageView::Property::IMAGE);
1887   Property::Map         returnedMap;
1888   visual.CreatePropertyMap(returnedMap);
1889
1890   Property::Value* value = returnedMap.Find(Toolkit::Visual::Property::TRANSFORM);
1891   DALI_TEST_CHECK(value);
1892   Property::Map* map = value->GetMap();
1893   DALI_TEST_CHECK(map);
1894
1895   value = map->Find(Toolkit::Visual::Transform::Property::SIZE);
1896   DALI_TEST_CHECK(value);
1897   DALI_TEST_EQUALS(value->Get<Vector2>(), Vector2(600, 600), TEST_LOCATION); // Change the internal size according to the image view size
1898
1899   value = map->Find(Toolkit::Visual::Transform::Property::SIZE_POLICY);
1900   DALI_TEST_CHECK(value);
1901   DALI_TEST_EQUALS(value->Get<Vector2>(), Vector2(Toolkit::Visual::Transform::Policy::ABSOLUTE, Toolkit::Visual::Transform::Policy::ABSOLUTE), TEST_LOCATION);
1902
1903   value = map->Find(Toolkit::Visual::Transform::Property::OFFSET);
1904   DALI_TEST_CHECK(value);
1905   DALI_TEST_EQUALS(value->Get<Vector2>(), Vector2(50, 50), TEST_LOCATION);
1906
1907   END_TEST;
1908 }
1909
1910 int UtcDaliImageViewFittingModesCenter02(void)
1911 {
1912   ToolkitTestApplication application;
1913
1914   tet_infoline("Create an ImageVisual using Center ( image: [600,600], view: [500,500] )");
1915   tet_infoline("  There should be need to change the transform, offset is adjusted to fit inside");
1916
1917   ImageView     imageView = ImageView::New();
1918   Property::Map imageMap;
1919   imageMap.Add(Toolkit::Visual::Property::TYPE, Toolkit::Visual::IMAGE);
1920   imageMap.Add(Toolkit::ImageVisual::Property::URL, gImage_600_RGB); // 600x600 image
1921   imageMap.Add(DevelVisual::Property::VISUAL_FITTING_MODE, Toolkit::DevelVisual::CENTER);
1922
1923   imageView.SetProperty(Toolkit::ImageView::Property::IMAGE, imageMap);
1924   imageView.SetProperty(Actor::Property::SIZE, Vector2(700, 700));
1925
1926   application.GetScene().Add(imageView);
1927
1928   // Trigger a potential relayout
1929   application.SendNotification();
1930   application.Render();
1931
1932   Toolkit::Visual::Base visual = DevelControl::GetVisual(Toolkit::Internal::GetImplementation(imageView), Toolkit::ImageView::Property::IMAGE);
1933   Property::Map         returnedMap;
1934   visual.CreatePropertyMap(returnedMap);
1935
1936   Property::Value* value = returnedMap.Find(Toolkit::Visual::Property::TRANSFORM);
1937   DALI_TEST_CHECK(value);
1938   Property::Map* map = value->GetMap();
1939   DALI_TEST_CHECK(map);
1940
1941   value = map->Find(Toolkit::Visual::Transform::Property::SIZE);
1942   DALI_TEST_CHECK(value);
1943   DALI_TEST_EQUALS(value->Get<Vector2>(), Vector2(600, 600), TEST_LOCATION); // Change the internal size according to the image view size
1944
1945   value = map->Find(Toolkit::Visual::Transform::Property::SIZE_POLICY);
1946   DALI_TEST_CHECK(value);
1947   DALI_TEST_EQUALS(value->Get<Vector2>(), Vector2(Toolkit::Visual::Transform::Policy::ABSOLUTE, Toolkit::Visual::Transform::Policy::ABSOLUTE), TEST_LOCATION);
1948
1949   value = map->Find(Toolkit::Visual::Transform::Property::OFFSET);
1950   DALI_TEST_CHECK(value);
1951   DALI_TEST_EQUALS(value->Get<Vector2>(), Vector2(50, 50), TEST_LOCATION);
1952
1953   END_TEST;
1954 }
1955
1956 int UtcDaliImageViewFittingModesFitHeight01(void)
1957 {
1958   ToolkitTestApplication application;
1959
1960   tet_infoline("Create an ImageVisual using FitHeight ( image: [600,600], view: [600,700] )");
1961
1962   ImageView     imageView = ImageView::New();
1963   Property::Map imageMap;
1964   imageMap.Add(Toolkit::Visual::Property::TYPE, Toolkit::Visual::IMAGE);
1965   imageMap.Add(Toolkit::ImageVisual::Property::URL, gImage_600_RGB); // 600x600 image
1966   imageMap.Add(DevelVisual::Property::VISUAL_FITTING_MODE, Toolkit::DevelVisual::FIT_HEIGHT);
1967
1968   imageView.SetProperty(Toolkit::ImageView::Property::IMAGE, imageMap);
1969   imageView.SetProperty(Actor::Property::SIZE, Vector2(600, 700));
1970
1971   application.GetScene().Add(imageView);
1972
1973   // Trigger a potential relayout
1974   application.SendNotification();
1975   application.Render();
1976
1977   Toolkit::Visual::Base visual = DevelControl::GetVisual(Toolkit::Internal::GetImplementation(imageView), Toolkit::ImageView::Property::IMAGE);
1978   Property::Map         returnedMap;
1979   visual.CreatePropertyMap(returnedMap);
1980
1981   Property::Value* value = returnedMap.Find(Toolkit::Visual::Property::TRANSFORM);
1982   DALI_TEST_CHECK(value);
1983   Property::Map* map = value->GetMap();
1984   DALI_TEST_CHECK(map);
1985
1986   value = map->Find(Toolkit::Visual::Transform::Property::SIZE);
1987   DALI_TEST_CHECK(value);
1988   DALI_TEST_EQUALS(value->Get<Vector2>(), Vector2(600, 700), TEST_LOCATION); // Change the internal size according to the image view size
1989
1990   value = map->Find(Toolkit::Visual::Transform::Property::SIZE_POLICY);
1991   DALI_TEST_CHECK(value);
1992   DALI_TEST_EQUALS(value->Get<Vector2>(), Vector2(Toolkit::Visual::Transform::Policy::ABSOLUTE, Toolkit::Visual::Transform::Policy::ABSOLUTE), TEST_LOCATION);
1993
1994   value = map->Find(Toolkit::Visual::Transform::Property::OFFSET);
1995   DALI_TEST_CHECK(value);
1996   DALI_TEST_EQUALS(value->Get<Vector2>(), Vector2(0, 0), TEST_LOCATION); // OFFSET is zero
1997
1998   END_TEST;
1999 }
2000
2001 int UtcDaliImageViewFittingModesFitHeight02(void)
2002 {
2003   ToolkitTestApplication application;
2004
2005   tet_infoline("Create an ImageVisual using FitHeight ( image: [600,600], view: [700,600] )");
2006
2007   ImageView     imageView = ImageView::New();
2008   Property::Map imageMap;
2009   imageMap.Add(Toolkit::Visual::Property::TYPE, Toolkit::Visual::IMAGE);
2010   imageMap.Add(Toolkit::ImageVisual::Property::URL, gImage_600_RGB); // 249x169 image
2011   imageMap.Add(DevelVisual::Property::VISUAL_FITTING_MODE, Toolkit::DevelVisual::FIT_HEIGHT);
2012
2013   imageView.SetProperty(Toolkit::ImageView::Property::IMAGE, imageMap);
2014   imageView.SetProperty(Actor::Property::SIZE, Vector2(700, 600));
2015
2016   application.GetScene().Add(imageView);
2017
2018   // Trigger a potential relayout
2019   application.SendNotification();
2020   application.Render();
2021
2022   Toolkit::Visual::Base visual = DevelControl::GetVisual(Toolkit::Internal::GetImplementation(imageView), Toolkit::ImageView::Property::IMAGE);
2023   Property::Map         returnedMap;
2024   visual.CreatePropertyMap(returnedMap);
2025
2026   Property::Value* value = returnedMap.Find(Toolkit::Visual::Property::TRANSFORM);
2027   DALI_TEST_CHECK(value);
2028   Property::Map* map = value->GetMap();
2029   DALI_TEST_CHECK(map);
2030
2031   value = map->Find(Toolkit::Visual::Transform::Property::SIZE);
2032   DALI_TEST_CHECK(value);
2033   DALI_TEST_EQUALS(value->Get<Vector2>(), Vector2(600, 600), TEST_LOCATION); // Change the internal size according to the image view size
2034
2035   value = map->Find(Toolkit::Visual::Transform::Property::SIZE_POLICY);
2036   DALI_TEST_CHECK(value);
2037   DALI_TEST_EQUALS(value->Get<Vector2>(), Vector2(Toolkit::Visual::Transform::Policy::ABSOLUTE, Toolkit::Visual::Transform::Policy::ABSOLUTE), TEST_LOCATION);
2038
2039   value = map->Find(Toolkit::Visual::Transform::Property::OFFSET);
2040   DALI_TEST_CHECK(value);
2041   DALI_TEST_EQUALS(value->Get<Vector2>(), Vector2(50, 0), TEST_LOCATION);
2042
2043   END_TEST;
2044 }
2045
2046 int UtcDaliImageViewFittingModesFitWidth01(void)
2047 {
2048   ToolkitTestApplication application;
2049
2050   tet_infoline("Create an ImageVisual using FitWidth ( image: [600,600], view: [600,700] )");
2051
2052   ImageView     imageView = ImageView::New();
2053   Property::Map imageMap;
2054   imageMap.Add(Toolkit::Visual::Property::TYPE, Toolkit::Visual::IMAGE);
2055   imageMap.Add(Toolkit::ImageVisual::Property::URL, gImage_600_RGB); // 600x600 image
2056   imageMap.Add(DevelVisual::Property::VISUAL_FITTING_MODE, Toolkit::DevelVisual::FIT_WIDTH);
2057
2058   imageView.SetProperty(Toolkit::ImageView::Property::IMAGE, imageMap);
2059   imageView.SetProperty(Actor::Property::SIZE, Vector2(600, 700));
2060
2061   application.GetScene().Add(imageView);
2062
2063   // Trigger a potential relayout
2064   application.SendNotification();
2065   application.Render();
2066
2067   Toolkit::Visual::Base visual = DevelControl::GetVisual(Toolkit::Internal::GetImplementation(imageView), Toolkit::ImageView::Property::IMAGE);
2068   Property::Map         returnedMap;
2069   visual.CreatePropertyMap(returnedMap);
2070
2071   Property::Value* value = returnedMap.Find(Toolkit::Visual::Property::TRANSFORM);
2072   DALI_TEST_CHECK(value);
2073   Property::Map* map = value->GetMap();
2074   DALI_TEST_CHECK(map);
2075
2076   value = map->Find(Toolkit::Visual::Transform::Property::SIZE);
2077   DALI_TEST_CHECK(value);
2078   DALI_TEST_EQUALS(value->Get<Vector2>(), Vector2(600, 600), TEST_LOCATION); // Change the internal size according to the image view size
2079
2080   value = map->Find(Toolkit::Visual::Transform::Property::SIZE_POLICY);
2081   DALI_TEST_CHECK(value);
2082   DALI_TEST_EQUALS(value->Get<Vector2>(), Vector2(Toolkit::Visual::Transform::Policy::ABSOLUTE, Toolkit::Visual::Transform::Policy::ABSOLUTE), TEST_LOCATION);
2083
2084   value = map->Find(Toolkit::Visual::Transform::Property::OFFSET);
2085   DALI_TEST_CHECK(value);
2086   DALI_TEST_EQUALS(value->Get<Vector2>(), Vector2(0, 50), TEST_LOCATION);
2087
2088   END_TEST;
2089 }
2090
2091 int UtcDaliImageViewFittingModesFitWidth02(void)
2092 {
2093   ToolkitTestApplication application;
2094
2095   tet_infoline("Create an ImageVisual using FitWidth ( image: [600,600], view:[700,600] )");
2096
2097   ImageView     imageView = ImageView::New();
2098   Property::Map imageMap;
2099   imageMap.Add(Toolkit::Visual::Property::TYPE, Toolkit::Visual::IMAGE);
2100   imageMap.Add(Toolkit::ImageVisual::Property::URL, gImage_600_RGB); // 249x169 image
2101   imageMap.Add(DevelVisual::Property::VISUAL_FITTING_MODE, Toolkit::DevelVisual::FIT_WIDTH);
2102
2103   imageView.SetProperty(Toolkit::ImageView::Property::IMAGE, imageMap);
2104   imageView.SetProperty(Actor::Property::SIZE, Vector2(700, 600));
2105
2106   application.GetScene().Add(imageView);
2107
2108   // Trigger a potential relayout
2109   application.SendNotification();
2110   application.Render();
2111
2112   Toolkit::Visual::Base visual = DevelControl::GetVisual(Toolkit::Internal::GetImplementation(imageView), Toolkit::ImageView::Property::IMAGE);
2113   Property::Map         returnedMap;
2114   visual.CreatePropertyMap(returnedMap);
2115
2116   Property::Value* value = returnedMap.Find(Toolkit::Visual::Property::TRANSFORM);
2117   DALI_TEST_CHECK(value);
2118   Property::Map* map = value->GetMap();
2119   DALI_TEST_CHECK(map);
2120
2121   value = map->Find(Toolkit::Visual::Transform::Property::SIZE);
2122   DALI_TEST_CHECK(value);
2123   DALI_TEST_EQUALS(value->Get<Vector2>(), Vector2(700, 600), TEST_LOCATION); // Change the internal size according to the image view size
2124
2125   value = map->Find(Toolkit::Visual::Transform::Property::SIZE_POLICY);
2126   DALI_TEST_CHECK(value);
2127   DALI_TEST_EQUALS(value->Get<Vector2>(), Vector2(Toolkit::Visual::Transform::Policy::ABSOLUTE, Toolkit::Visual::Transform::Policy::ABSOLUTE), TEST_LOCATION);
2128
2129   value = map->Find(Toolkit::Visual::Transform::Property::OFFSET);
2130   DALI_TEST_CHECK(value);
2131   DALI_TEST_EQUALS(value->Get<Vector2>(), Vector2(0, 0), TEST_LOCATION); // OFFSET is zero
2132
2133   END_TEST;
2134 }
2135
2136 int UtcDaliImageViewFittingModesChangeFittingMode01(void)
2137 {
2138   ToolkitTestApplication application;
2139
2140   tet_infoline("UtcDaliImageViewFittingModesChangeFittingMode, image: [600,600], view:[800,700]");
2141
2142   ImageView imageView = ImageView::New();
2143
2144   // 1. Render using FittingMode::SHRINK_TO_FIT
2145   Property::Map imageMap;
2146   imageMap[Toolkit::Visual::Property::TYPE]            = Toolkit::Visual::IMAGE;
2147   imageMap[Toolkit::ImageVisual::Property::URL]        = gImage_600_RGB;
2148   imageMap[DevelVisual::Property::VISUAL_FITTING_MODE] = Toolkit::DevelVisual::FIT_KEEP_ASPECT_RATIO;
2149
2150   imageView.SetProperty(Toolkit::ImageView::Property::IMAGE, imageMap);
2151   imageView.SetProperty(Actor::Property::SIZE, Vector2(800, 700));
2152
2153   application.GetScene().Add(imageView);
2154
2155   // Trigger a potential relayout
2156   application.SendNotification();
2157   application.Render();
2158
2159   Toolkit::Visual::Base visual = DevelControl::GetVisual(Toolkit::Internal::GetImplementation(imageView), Toolkit::ImageView::Property::IMAGE);
2160   Property::Map         returnedMap;
2161   visual.CreatePropertyMap(returnedMap);
2162
2163   Property::Value* value = returnedMap.Find(Toolkit::Visual::Property::TRANSFORM);
2164   DALI_TEST_CHECK(value);
2165   Property::Map* map = value->GetMap();
2166   DALI_TEST_CHECK(map);
2167
2168   value = map->Find(Toolkit::Visual::Transform::Property::SIZE);
2169   DALI_TEST_CHECK(value);
2170   DALI_TEST_EQUALS(value->Get<Vector2>(), Vector2(700, 700), TEST_LOCATION); // Change the internal size according to the image view size
2171
2172   value = map->Find(Toolkit::Visual::Transform::Property::SIZE_POLICY);
2173   DALI_TEST_CHECK(value);
2174   DALI_TEST_EQUALS(value->Get<Vector2>(), Vector2(Toolkit::Visual::Transform::Policy::ABSOLUTE, Toolkit::Visual::Transform::Policy::ABSOLUTE), TEST_LOCATION);
2175
2176   value = map->Find(Toolkit::Visual::Transform::Property::OFFSET);
2177   DALI_TEST_CHECK(value);
2178   DALI_TEST_EQUALS(value->Get<Vector2>(), Vector2(50, 0), TEST_LOCATION);
2179
2180   // 2. Render again using DevelVisaul::CENTER
2181   Property::Map imageMap2;
2182   imageMap2[Toolkit::Visual::Property::TYPE]            = Toolkit::Visual::IMAGE;
2183   imageMap2[Toolkit::ImageVisual::Property::URL]        = gImage_600_RGB;
2184   imageMap2[DevelVisual::Property::VISUAL_FITTING_MODE] = Toolkit::DevelVisual::CENTER;
2185
2186   imageView.SetProperty(Toolkit::ImageView::Property::IMAGE, imageMap2);
2187   imageView.SetProperty(Actor::Property::SIZE, Vector2(800, 700));
2188
2189   application.GetScene().Add(imageView);
2190
2191   DALI_TEST_EQUALS(Test::WaitForEventThreadTrigger(1), true, TEST_LOCATION);
2192
2193   // Trigger a potential relayout
2194   application.SendNotification();
2195   application.Render();
2196
2197   returnedMap.Clear();
2198   visual = DevelControl::GetVisual(Toolkit::Internal::GetImplementation(imageView), Toolkit::ImageView::Property::IMAGE);
2199
2200   visual.CreatePropertyMap(returnedMap);
2201
2202   value = returnedMap.Find(Toolkit::Visual::Property::TRANSFORM);
2203   DALI_TEST_CHECK(value);
2204   map = value->GetMap();
2205   DALI_TEST_CHECK(map);
2206
2207   value = map->Find(Toolkit::Visual::Transform::Property::SIZE);
2208   DALI_TEST_CHECK(value);
2209   DALI_TEST_EQUALS(value->Get<Vector2>(), Vector2(600, 600), TEST_LOCATION); // Change the internal size according to the image view size
2210
2211   value = map->Find(Toolkit::Visual::Transform::Property::SIZE_POLICY);
2212   DALI_TEST_CHECK(value);
2213   DALI_TEST_EQUALS(value->Get<Vector2>(), Vector2(Toolkit::Visual::Transform::Policy::ABSOLUTE, Toolkit::Visual::Transform::Policy::ABSOLUTE), TEST_LOCATION);
2214
2215   value = map->Find(Toolkit::Visual::Transform::Property::OFFSET);
2216   DALI_TEST_CHECK(value);
2217   DALI_TEST_EQUALS(value->Get<Vector2>(), Vector2(100, 50), TEST_LOCATION);
2218
2219   // 3. Render again using before fittingMode
2220   Property::Map imageMap3;
2221   imageMap3[Toolkit::Visual::Property::TYPE]            = Toolkit::Visual::IMAGE;
2222   imageMap3[Toolkit::ImageVisual::Property::URL]        = gImage_600_RGB;
2223   imageMap3[DevelVisual::Property::VISUAL_FITTING_MODE] = Toolkit::DevelVisual::FIT_KEEP_ASPECT_RATIO;
2224
2225   imageView.SetProperty(Toolkit::ImageView::Property::IMAGE, imageMap3);
2226   imageView.SetProperty(Actor::Property::SIZE, Vector2(800, 700));
2227
2228   application.GetScene().Add(imageView);
2229
2230   // Trigger a potential relayout
2231   application.SendNotification();
2232   application.Render();
2233
2234   returnedMap.Clear();
2235   visual = DevelControl::GetVisual(Toolkit::Internal::GetImplementation(imageView), Toolkit::ImageView::Property::IMAGE);
2236   visual.CreatePropertyMap(returnedMap);
2237
2238   value = returnedMap.Find(Toolkit::Visual::Property::TRANSFORM);
2239   DALI_TEST_CHECK(value);
2240   map = value->GetMap();
2241   DALI_TEST_CHECK(map);
2242
2243   value = map->Find(Toolkit::Visual::Transform::Property::SIZE);
2244   DALI_TEST_CHECK(value);
2245   DALI_TEST_EQUALS(value->Get<Vector2>(), Vector2(700, 700), TEST_LOCATION); // Change the internal size according to the image view size
2246
2247   value = map->Find(Toolkit::Visual::Transform::Property::SIZE_POLICY);
2248   DALI_TEST_CHECK(value);
2249   DALI_TEST_EQUALS(value->Get<Vector2>(), Vector2(Toolkit::Visual::Transform::Policy::ABSOLUTE, Toolkit::Visual::Transform::Policy::ABSOLUTE), TEST_LOCATION);
2250
2251   value = map->Find(Toolkit::Visual::Transform::Property::OFFSET);
2252   DALI_TEST_CHECK(value);
2253   DALI_TEST_EQUALS(value->Get<Vector2>(), Vector2(50, 0), TEST_LOCATION);
2254
2255   END_TEST;
2256 }
2257
2258 int UtcDaliImageViewFittingModesChangeFittingMode02(void)
2259 {
2260   ToolkitTestApplication application;
2261
2262   tet_infoline("UtcDaliImageViewFittingModesChangeFittingMode, image: [600,600], view:[800,700]");
2263
2264   ImageView imageView = ImageView::New();
2265
2266   // 1. Render using FittingMode::OVER_FIT_KEEP_ASPECT_RATIO
2267   Property::Map imageMap;
2268   imageMap[Toolkit::Visual::Property::TYPE]            = Toolkit::Visual::IMAGE;
2269   imageMap[Toolkit::ImageVisual::Property::URL]        = gImage_600_RGB;
2270   imageMap[DevelVisual::Property::VISUAL_FITTING_MODE] = Toolkit::DevelVisual::OVER_FIT_KEEP_ASPECT_RATIO;
2271
2272   imageView.SetProperty(Toolkit::ImageView::Property::IMAGE, imageMap);
2273   imageView.SetProperty(Actor::Property::SIZE, Vector2(800, 700));
2274
2275   application.GetScene().Add(imageView);
2276
2277   // Trigger a potential relayout
2278   application.SendNotification();
2279   application.Render();
2280
2281   Toolkit::Visual::Base visual = DevelControl::GetVisual(Toolkit::Internal::GetImplementation(imageView), Toolkit::ImageView::Property::IMAGE);
2282   Property::Map         returnedMap;
2283   visual.CreatePropertyMap(returnedMap);
2284
2285   Property::Value* value = returnedMap.Find(Toolkit::Visual::Property::TRANSFORM);
2286   DALI_TEST_CHECK(value);
2287   Property::Map* map = value->GetMap();
2288   DALI_TEST_CHECK(map);
2289
2290   value = map->Find(Toolkit::Visual::Transform::Property::SIZE);
2291   DALI_TEST_CHECK(value);
2292   DALI_TEST_EQUALS(value->Get<Vector2>(), Vector2(800, 700), TEST_LOCATION); // Change the internal size according to the image view size
2293
2294   value = map->Find(Toolkit::Visual::Transform::Property::SIZE_POLICY);
2295   DALI_TEST_CHECK(value);
2296   DALI_TEST_EQUALS(value->Get<Vector2>(), Vector2(Toolkit::Visual::Transform::Policy::ABSOLUTE, Toolkit::Visual::Transform::Policy::ABSOLUTE), TEST_LOCATION);
2297
2298   value = map->Find(Toolkit::Visual::Transform::Property::OFFSET);
2299   DALI_TEST_CHECK(value);
2300   DALI_TEST_EQUALS(value->Get<Vector2>(), Vector2(0, 0), TEST_LOCATION);
2301
2302   // 2. Render again using DevelVisaul::CENTER
2303   Property::Map imageMap2;
2304   imageMap2[Toolkit::Visual::Property::TYPE]            = Toolkit::Visual::IMAGE;
2305   imageMap2[Toolkit::ImageVisual::Property::URL]        = gImage_600_RGB;
2306   imageMap2[DevelVisual::Property::VISUAL_FITTING_MODE] = Toolkit::DevelVisual::CENTER;
2307
2308   imageView.SetProperty(Toolkit::ImageView::Property::IMAGE, imageMap2);
2309   imageView.SetProperty(Actor::Property::SIZE, Vector2(800, 700));
2310
2311   application.GetScene().Add(imageView);
2312
2313   DALI_TEST_EQUALS(Test::WaitForEventThreadTrigger(1), true, TEST_LOCATION);
2314
2315   // Trigger a potential relayout
2316   application.SendNotification();
2317   application.Render();
2318
2319   returnedMap.Clear();
2320   visual = DevelControl::GetVisual(Toolkit::Internal::GetImplementation(imageView), Toolkit::ImageView::Property::IMAGE);
2321
2322   visual.CreatePropertyMap(returnedMap);
2323
2324   value = returnedMap.Find(Toolkit::Visual::Property::TRANSFORM);
2325   DALI_TEST_CHECK(value);
2326   map = value->GetMap();
2327   DALI_TEST_CHECK(map);
2328
2329   value = map->Find(Toolkit::Visual::Transform::Property::SIZE);
2330   DALI_TEST_CHECK(value);
2331   DALI_TEST_EQUALS(value->Get<Vector2>(), Vector2(600, 600), TEST_LOCATION); // Change the internal size according to the image view size
2332
2333   value = map->Find(Toolkit::Visual::Transform::Property::SIZE_POLICY);
2334   DALI_TEST_CHECK(value);
2335   DALI_TEST_EQUALS(value->Get<Vector2>(), Vector2(Toolkit::Visual::Transform::Policy::ABSOLUTE, Toolkit::Visual::Transform::Policy::ABSOLUTE), TEST_LOCATION);
2336
2337   value = map->Find(Toolkit::Visual::Transform::Property::OFFSET);
2338   DALI_TEST_CHECK(value);
2339   DALI_TEST_EQUALS(value->Get<Vector2>(), Vector2(100, 50), TEST_LOCATION);
2340
2341   // 3. Render again using before fittingMode
2342   Property::Map imageMap3;
2343   imageMap3[Toolkit::Visual::Property::TYPE]            = Toolkit::Visual::IMAGE;
2344   imageMap3[Toolkit::ImageVisual::Property::URL]        = gImage_600_RGB;
2345   imageMap3[DevelVisual::Property::VISUAL_FITTING_MODE] = Toolkit::DevelVisual::OVER_FIT_KEEP_ASPECT_RATIO;
2346
2347   imageView.SetProperty(Toolkit::ImageView::Property::IMAGE, imageMap3);
2348   imageView.SetProperty(Actor::Property::SIZE, Vector2(800, 700));
2349
2350   application.GetScene().Add(imageView);
2351
2352   // Trigger a potential relayout
2353   application.SendNotification();
2354   application.Render();
2355
2356   returnedMap.Clear();
2357   visual = DevelControl::GetVisual(Toolkit::Internal::GetImplementation(imageView), Toolkit::ImageView::Property::IMAGE);
2358   visual.CreatePropertyMap(returnedMap);
2359
2360   value = returnedMap.Find(Toolkit::Visual::Property::TRANSFORM);
2361   DALI_TEST_CHECK(value);
2362   map = value->GetMap();
2363   DALI_TEST_CHECK(map);
2364
2365   value = map->Find(Toolkit::Visual::Transform::Property::SIZE);
2366   DALI_TEST_CHECK(value);
2367   DALI_TEST_EQUALS(value->Get<Vector2>(), Vector2(800, 700), TEST_LOCATION); // Change the internal size according to the image view size
2368
2369   value = map->Find(Toolkit::Visual::Transform::Property::SIZE_POLICY);
2370   DALI_TEST_CHECK(value);
2371   DALI_TEST_EQUALS(value->Get<Vector2>(), Vector2(Toolkit::Visual::Transform::Policy::ABSOLUTE, Toolkit::Visual::Transform::Policy::ABSOLUTE), TEST_LOCATION);
2372
2373   value = map->Find(Toolkit::Visual::Transform::Property::OFFSET);
2374   DALI_TEST_CHECK(value);
2375   DALI_TEST_EQUALS(value->Get<Vector2>(), Vector2(0, 0), TEST_LOCATION);
2376
2377   END_TEST;
2378 }
2379
2380 int UtcDaliImageViewFittingModesWithAnimatedVectorImageVisual(void)
2381 {
2382   ToolkitTestApplication application;
2383
2384   tet_infoline("Create an ImageVisual using SCALE_TO_FILL and animated vector image ( image: [600,600], view:[600,600] )");
2385
2386   ImageView     imageView = ImageView::New();
2387   Property::Map imageMap;
2388   imageMap.Add(Toolkit::Visual::Property::TYPE, DevelVisual::ANIMATED_VECTOR_IMAGE);
2389   imageMap.Add(Toolkit::ImageVisual::Property::URL, TEST_ANIMATED_VECTOR_IMAGE_FILE_NAME); // 249x169 image
2390
2391   imageView.SetProperty(Toolkit::ImageView::Property::IMAGE, imageMap);
2392   imageView.SetProperty(Actor::Property::SIZE, Vector2(600, 600));
2393
2394   application.GetScene().Add(imageView);
2395
2396   // Trigger a potential relayout
2397   application.SendNotification();
2398   application.Render();
2399
2400   Toolkit::Visual::Base visual = DevelControl::GetVisual(Toolkit::Internal::GetImplementation(imageView), Toolkit::ImageView::Property::IMAGE);
2401   Property::Map         returnedMap;
2402   visual.CreatePropertyMap(returnedMap);
2403
2404   Property::Value* value = returnedMap.Find(Toolkit::Visual::Property::TRANSFORM);
2405   DALI_TEST_CHECK(value);
2406   Property::Map* map = value->GetMap();
2407   DALI_TEST_CHECK(map);
2408
2409   value = map->Find(Toolkit::Visual::Transform::Property::SIZE);
2410   DALI_TEST_CHECK(value);
2411   DALI_TEST_EQUALS(value->Get<Vector2>(), Vector2::ONE, TEST_LOCATION); // Relative size so will take up 100%
2412
2413   value = map->Find(Toolkit::Visual::Transform::Property::SIZE_POLICY);
2414   DALI_TEST_CHECK(value);
2415   DALI_TEST_CHECK(value->Get<int>() == Toolkit::Visual::Transform::Policy::RELATIVE);
2416
2417   value = map->Find(Toolkit::Visual::Transform::Property::OFFSET);
2418   DALI_TEST_CHECK(value);
2419   DALI_TEST_EQUALS(value->Get<Vector2>(), Vector2(0, 0), TEST_LOCATION); // OFFSET is zero
2420
2421   END_TEST;
2422 }
2423
2424 int UtcDaliImageViewCustomShader(void)
2425 {
2426   ToolkitTestApplication application;
2427
2428   // Set a custom shader with an image url
2429   {
2430     Property::Map     properties;
2431     Property::Map     shader;
2432     const std::string vertexShader                    = "Foobar";
2433     const std::string fragmentShader                  = "Foobar";
2434     shader[Visual::Shader::Property::FRAGMENT_SHADER] = fragmentShader;
2435     shader[Visual::Shader::Property::VERTEX_SHADER]   = vertexShader;
2436
2437     properties[Visual::Property::TYPE]     = Visual::IMAGE;
2438     properties[Visual::Property::SHADER]   = shader;
2439     properties[ImageVisual::Property::URL] = TEST_IMAGE_FILE_NAME;
2440
2441     ImageView imageView = ImageView::New();
2442     imageView.SetProperty(ImageView::Property::IMAGE, properties);
2443
2444     application.GetScene().Add(imageView);
2445
2446     application.SendNotification();
2447     application.Render();
2448
2449     DALI_TEST_EQUALS(Test::WaitForEventThreadTrigger(1), true, TEST_LOCATION);
2450
2451     Renderer        renderer = imageView.GetRendererAt(0);
2452     Shader          shader2  = renderer.GetShader();
2453     Property::Value value    = shader2.GetProperty(Shader::Property::PROGRAM);
2454     Property::Map*  map      = value.GetMap();
2455     DALI_TEST_CHECK(map);
2456
2457     Property::Value* fragment = map->Find("fragment"); // fragment key name from shader-impl.cpp
2458     DALI_TEST_EQUALS(fragmentShader, fragment->Get<std::string>(), TEST_LOCATION);
2459
2460     Property::Value* vertex = map->Find("vertex"); // vertex key name from shader-impl.cpp
2461     DALI_TEST_EQUALS(vertexShader, vertex->Get<std::string>(), TEST_LOCATION);
2462   }
2463
2464   // Set a custom shader after setting an image url
2465   {
2466     Property::Map     properties;
2467     Property::Map     shader;
2468     const std::string vertexShader                    = "Foobar";
2469     const std::string fragmentShader                  = "Foobar";
2470     shader[Visual::Shader::Property::FRAGMENT_SHADER] = fragmentShader;
2471     shader[Visual::Shader::Property::VERTEX_SHADER]   = vertexShader;
2472
2473     properties[Visual::Property::SHADER] = shader;
2474
2475     ImageView imageView = ImageView::New(TEST_IMAGE_FILE_NAME);
2476     imageView.SetProperty(ImageView::Property::IMAGE, properties);
2477
2478     application.GetScene().Add(imageView);
2479
2480     application.SendNotification();
2481     application.Render();
2482
2483     DALI_TEST_EQUALS(Test::WaitForEventThreadTrigger(1), true, TEST_LOCATION);
2484
2485     Renderer        renderer = imageView.GetRendererAt(0);
2486     Shader          shader2  = renderer.GetShader();
2487     Property::Value value    = shader2.GetProperty(Shader::Property::PROGRAM);
2488     Property::Map*  map      = value.GetMap();
2489     DALI_TEST_CHECK(map);
2490
2491     Property::Value* fragment = map->Find("fragment"); // fragment key name from shader-impl.cpp
2492     DALI_TEST_EQUALS(fragmentShader, fragment->Get<std::string>(), TEST_LOCATION);
2493
2494     Property::Value* vertex = map->Find("vertex"); // vertex key name from shader-impl.cpp
2495     DALI_TEST_EQUALS(vertexShader, vertex->Get<std::string>(), TEST_LOCATION);
2496   }
2497
2498   // Set a custom shader before setting an image url
2499   {
2500     Property::Map     properties;
2501     Property::Map     shader;
2502     const std::string vertexShader                    = "Foobar";
2503     const std::string fragmentShader                  = "Foobar";
2504     shader[Visual::Shader::Property::FRAGMENT_SHADER] = fragmentShader;
2505     shader[Visual::Shader::Property::VERTEX_SHADER]   = vertexShader;
2506
2507     properties[Visual::Property::SHADER] = shader;
2508
2509     ImageView imageView = ImageView::New();
2510     imageView.SetProperty(ImageView::Property::IMAGE, properties);
2511     imageView.SetProperty(ImageView::Property::IMAGE, TEST_IMAGE_FILE_NAME);
2512
2513     application.GetScene().Add(imageView);
2514
2515     application.SendNotification();
2516     application.Render();
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 a property map
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     Property::Map properties1;
2544     properties1[Visual::Property::TYPE]     = Visual::IMAGE;
2545     properties1[ImageVisual::Property::URL] = TEST_IMAGE_FILE_NAME;
2546
2547     ImageView imageView = ImageView::New();
2548     imageView.SetProperty(ImageView::Property::IMAGE, properties1);
2549     imageView.SetProperty(ImageView::Property::IMAGE, properties);
2550
2551     application.GetScene().Add(imageView);
2552
2553     application.SendNotification();
2554     application.Render();
2555     DALI_TEST_EQUALS(Test::WaitForEventThreadTrigger(1), true, TEST_LOCATION);
2556
2557     Renderer        renderer = imageView.GetRendererAt(0);
2558     Shader          shader2  = renderer.GetShader();
2559     Property::Value value    = shader2.GetProperty(Shader::Property::PROGRAM);
2560     Property::Map*  map      = value.GetMap();
2561     DALI_TEST_CHECK(map);
2562
2563     Property::Value* fragment = map->Find("fragment"); // fragment key name from shader-impl.cpp
2564     DALI_TEST_EQUALS(fragmentShader, fragment->Get<std::string>(), TEST_LOCATION);
2565
2566     Property::Value* vertex = map->Find("vertex"); // vertex key name from shader-impl.cpp
2567     DALI_TEST_EQUALS(vertexShader, vertex->Get<std::string>(), TEST_LOCATION);
2568   }
2569
2570   // Set a custom shader before setting a property map
2571   {
2572     Property::Map     properties;
2573     Property::Map     shader;
2574     const std::string vertexShader                    = "Foobar";
2575     const std::string fragmentShader                  = "Foobar";
2576     shader[Visual::Shader::Property::FRAGMENT_SHADER] = fragmentShader;
2577     shader[Visual::Shader::Property::VERTEX_SHADER]   = vertexShader;
2578
2579     properties[Visual::Property::SHADER] = shader;
2580
2581     Property::Map properties1;
2582     properties1[Visual::Property::TYPE]     = Visual::IMAGE;
2583     properties1[ImageVisual::Property::URL] = TEST_IMAGE_FILE_NAME;
2584
2585     ImageView imageView = ImageView::New();
2586     imageView.SetProperty(ImageView::Property::IMAGE, properties);
2587     imageView.SetProperty(ImageView::Property::IMAGE, properties1);
2588
2589     application.GetScene().Add(imageView);
2590
2591     application.SendNotification();
2592     application.Render();
2593     DALI_TEST_EQUALS(Test::WaitForEventThreadTrigger(1), true, TEST_LOCATION);
2594
2595     Renderer        renderer = imageView.GetRendererAt(0);
2596     Shader          shader2  = renderer.GetShader();
2597     Property::Value value    = shader2.GetProperty(Shader::Property::PROGRAM);
2598     Property::Map*  map      = value.GetMap();
2599     DALI_TEST_CHECK(map);
2600
2601     Property::Value* fragment = map->Find("fragment"); // fragment key name from shader-impl.cpp
2602     DALI_TEST_EQUALS(fragmentShader, fragment->Get<std::string>(), TEST_LOCATION);
2603
2604     Property::Value* vertex = map->Find("vertex"); // vertex key name from shader-impl.cpp
2605     DALI_TEST_EQUALS(vertexShader, vertex->Get<std::string>(), TEST_LOCATION);
2606   }
2607
2608   END_TEST;
2609 }
2610
2611 namespace
2612 {
2613 static int gFailCounter = 0;
2614 const int  MAX_RETRIES(3);
2615
2616 void ReloadImage(ImageView imageView)
2617 {
2618   Property::Map imageImmediateLoadingMap;
2619   imageImmediateLoadingMap[ImageVisual::Property::URL]         = "Non-existant-image.jpg";
2620   imageImmediateLoadingMap[ImageVisual::Property::LOAD_POLICY] = ImageVisual::LoadPolicy::IMMEDIATE;
2621
2622   tet_infoline("Immediate load an image");
2623   imageView.SetProperty(ImageView::Property::IMAGE, imageImmediateLoadingMap);
2624 }
2625
2626 void ResourceFailedReload(Control control)
2627 {
2628   gFailCounter++;
2629   if(gFailCounter < MAX_RETRIES)
2630   {
2631     ReloadImage(ImageView::DownCast(control));
2632   }
2633 }
2634 } // namespace
2635
2636 int UtcDaliImageViewReloadFailedOnResourceReadySignal(void)
2637 {
2638   tet_infoline("Test reloading failed image from within signal handler.");
2639
2640   ToolkitTestApplication application;
2641
2642   gFailCounter = 0;
2643
2644   ImageView imageView = ImageView::New();
2645   imageView.ResourceReadySignal().Connect(&ResourceFailedReload);
2646   DALI_TEST_EQUALS(gFailCounter, 0, TEST_LOCATION);
2647   ReloadImage(imageView);
2648
2649   // loading started, this waits for the loader thread to complete
2650   DALI_TEST_EQUALS(Test::WaitForEventThreadTrigger(1), true, TEST_LOCATION);
2651   application.SendNotification();
2652
2653   DALI_TEST_EQUALS(gFailCounter, 1, TEST_LOCATION);
2654
2655   DALI_TEST_EQUALS(Test::WaitForEventThreadTrigger(1), true, TEST_LOCATION);
2656   application.SendNotification();
2657
2658   DALI_TEST_EQUALS(gFailCounter, 2, TEST_LOCATION);
2659
2660   DALI_TEST_EQUALS(Test::WaitForEventThreadTrigger(1), true, TEST_LOCATION);
2661   application.SendNotification();
2662   DALI_TEST_EQUALS(gFailCounter, 3, TEST_LOCATION);
2663
2664   END_TEST;
2665 }
2666
2667 int UtcDaliImageViewLoadRemoteSVG(void)
2668 {
2669   tet_infoline("Test load from a remote server.");
2670
2671   ToolkitTestApplication application;
2672
2673   {
2674     Toolkit::ImageView imageView;
2675     imageView = Toolkit::ImageView::New();
2676     imageView.SetImage("https://dev.w3.org/SVG/tools/svgweb/samples/svg-files/check.svg");
2677     imageView.SetProperty(Actor::Property::PARENT_ORIGIN, ParentOrigin::TOP_LEFT);
2678     imageView.SetProperty(Actor::Property::ANCHOR_POINT, AnchorPoint::TOP_LEFT);
2679     imageView.SetProperty(Actor::Property::SIZE, Vector2(300, 300));
2680     imageView.SetProperty(Actor::Property::POSITION, Vector3(150.0f, 150.0f, 0.0f));
2681
2682     application.GetScene().Add(imageView);
2683
2684     DALI_TEST_CHECK(imageView);
2685
2686     DALI_TEST_EQUALS(imageView.GetRendererCount(), 0u, TEST_LOCATION);
2687
2688     application.SendNotification();
2689
2690     // Wait for loading & rasterization
2691     DALI_TEST_EQUALS(Test::WaitForEventThreadTrigger(2), true, TEST_LOCATION);
2692
2693     application.SendNotification();
2694     application.Render();
2695
2696     DALI_TEST_EQUALS(imageView.GetRendererCount(), 1u, TEST_LOCATION);
2697   }
2698
2699   // Without size set
2700   {
2701     Toolkit::ImageView imageView;
2702     imageView = Toolkit::ImageView::New();
2703     imageView.SetImage("https://dev.w3.org/SVG/tools/svgweb/samples/svg-files/check.svg");
2704     imageView.SetProperty(Actor::Property::PARENT_ORIGIN, ParentOrigin::TOP_LEFT);
2705     imageView.SetProperty(Actor::Property::ANCHOR_POINT, AnchorPoint::TOP_LEFT);
2706     imageView.SetProperty(Actor::Property::POSITION, Vector3(150.0f, 150.0f, 0.0f));
2707
2708     application.GetScene().Add(imageView);
2709
2710     DALI_TEST_CHECK(imageView);
2711
2712     DALI_TEST_EQUALS(imageView.GetRendererCount(), 0u, TEST_LOCATION);
2713
2714     application.SendNotification();
2715
2716     // Wait for loading & rasterization
2717     DALI_TEST_EQUALS(Test::WaitForEventThreadTrigger(2), true, TEST_LOCATION);
2718
2719     application.SendNotification();
2720     application.Render();
2721
2722     DALI_TEST_EQUALS(imageView.GetRendererCount(), 1u, TEST_LOCATION);
2723   }
2724
2725   END_TEST;
2726 }
2727
2728 int UtcDaliImageViewSyncSVGLoading(void)
2729 {
2730   ToolkitTestApplication application;
2731
2732   tet_infoline("ImageView Testing SVG image sync loading");
2733
2734   {
2735     ImageView imageView = ImageView::New();
2736
2737     // Sync loading is used
2738     Property::Map syncLoadingMap;
2739     syncLoadingMap.Insert(Toolkit::Visual::Property::TYPE, Toolkit::Visual::IMAGE);
2740     syncLoadingMap.Insert(Toolkit::ImageVisual::Property::URL, TEST_RESOURCE_DIR "/svg1.svg");
2741     syncLoadingMap.Insert(Toolkit::ImageVisual::Property::SYNCHRONOUS_LOADING, true);
2742     imageView.SetProperty(ImageView::Property::IMAGE, syncLoadingMap);
2743
2744     application.GetScene().Add(imageView);
2745     DALI_TEST_CHECK(imageView);
2746
2747     application.SendNotification();
2748     Vector3 naturalSize = imageView.GetNaturalSize();
2749
2750     DALI_TEST_EQUALS(naturalSize.width, 100.0f, TEST_LOCATION);
2751     DALI_TEST_EQUALS(naturalSize.height, 100.0f, TEST_LOCATION);
2752   }
2753   END_TEST;
2754 }
2755
2756 int UtcDaliImageViewAsyncSVGLoading(void)
2757 {
2758   ToolkitTestApplication application;
2759
2760   tet_infoline("ImageView Testing SVG image async loading");
2761
2762   {
2763     ImageView imageView = ImageView::New();
2764
2765     // Async loading is used - default value of SYNCHRONOUS_LOADING is false.
2766     Property::Map propertyMap;
2767     propertyMap.Insert(Toolkit::Visual::Property::TYPE, Toolkit::Visual::IMAGE);
2768     propertyMap.Insert(Toolkit::ImageVisual::Property::URL, TEST_RESOURCE_DIR "/svg1.svg");
2769     imageView.SetProperty(ImageView::Property::IMAGE, propertyMap);
2770
2771     application.GetScene().Add(imageView);
2772     DALI_TEST_CHECK(imageView);
2773
2774     application.SendNotification();
2775
2776     // Wait for loading
2777     DALI_TEST_EQUALS(Test::WaitForEventThreadTrigger(1), true, TEST_LOCATION);
2778
2779     application.SendNotification();
2780     application.Render(16);
2781
2782     Vector3 naturalSize = imageView.GetNaturalSize();
2783     DALI_TEST_EQUALS(naturalSize.width, 100.0f, TEST_LOCATION);
2784     DALI_TEST_EQUALS(naturalSize.height, 100.0f, TEST_LOCATION);
2785   }
2786   END_TEST;
2787 }
2788
2789 int UtcDaliImageViewSVGLoadingSyncSetInvalidValue(void)
2790 {
2791   ToolkitTestApplication application;
2792
2793   tet_infoline("ImageView Testing SVG image async loading");
2794
2795   // Sync loading
2796   {
2797     ImageView imageView = ImageView::New();
2798
2799     // Sync loading is used
2800     Property::Map syncLoadingMap;
2801     syncLoadingMap.Insert(Toolkit::Visual::Property::TYPE, Toolkit::Visual::IMAGE);
2802     syncLoadingMap.Insert(Toolkit::ImageVisual::Property::URL, TEST_RESOURCE_DIR "/svg1.svg");
2803
2804     // Check to set invalid value
2805     // The SYNCHRONOUS_LOADING property must be set to the bool value.
2806     // Check if error log is outputted when setting other value like string.
2807     // Even if the wrong value is set, the image will be shown normally, and the synchronous value should be the default value(false).
2808     syncLoadingMap.Insert(Toolkit::ImageVisual::Property::SYNCHRONOUS_LOADING, std::to_string(5));
2809     imageView.SetProperty(ImageView::Property::IMAGE, syncLoadingMap);
2810
2811     application.GetScene().Add(imageView);
2812     DALI_TEST_CHECK(imageView);
2813
2814     application.SendNotification();
2815
2816     // Wait for loading
2817     DALI_TEST_EQUALS(Test::WaitForEventThreadTrigger(1), true, TEST_LOCATION);
2818
2819     application.SendNotification();
2820     application.Render(16);
2821
2822     Vector3 naturalSize = imageView.GetNaturalSize();
2823     DALI_TEST_EQUALS(naturalSize.width, 100.0f, TEST_LOCATION);
2824     DALI_TEST_EQUALS(naturalSize.height, 100.0f, TEST_LOCATION);
2825
2826     Property::Value value = imageView.GetProperty(ImageView::Property::IMAGE);
2827     Property::Map*  map   = value.GetMap();
2828     DALI_TEST_CHECK(map);
2829
2830     Property::Value* sync = map->Find(Toolkit::ImageVisual::Property::SYNCHRONOUS_LOADING);
2831     DALI_TEST_CHECK(sync);
2832     DALI_TEST_EQUALS(false, sync->Get<bool>(), TEST_LOCATION);
2833   }
2834   END_TEST;
2835 }
2836
2837 int UtcDaliImageViewSvgLoadingFailureLocalFile(void)
2838 {
2839   // Local svg file - invalid file path
2840   {
2841     ToolkitTestApplication application;
2842
2843     TestGlAbstraction& gl           = application.GetGlAbstraction();
2844     TraceCallStack&    textureTrace = gl.GetTextureTrace();
2845     textureTrace.Enable(true);
2846
2847     gResourceReadySignalFired = false;
2848
2849     ImageView imageView = ImageView::New(TEST_RESOURCE_DIR "/foo.svg");
2850     imageView.SetProperty(Actor::Property::SIZE, Vector2(200.f, 200.f));
2851     imageView.ResourceReadySignal().Connect(&ResourceReadySignal);
2852
2853     DALI_TEST_EQUALS(imageView.IsResourceReady(), false, TEST_LOCATION);
2854
2855     application.GetScene().Add(imageView);
2856
2857     application.SendNotification();
2858
2859     // loading started, this waits for the loader thread - load
2860     DALI_TEST_EQUALS(Test::WaitForEventThreadTrigger(1), true, TEST_LOCATION);
2861
2862     application.SendNotification();
2863     application.Render(16);
2864
2865     DALI_TEST_EQUALS(gResourceReadySignalFired, true, TEST_LOCATION);
2866     DALI_TEST_EQUALS(imageView.IsResourceReady(), true, TEST_LOCATION);
2867     DALI_TEST_EQUALS(imageView.GetVisualResourceStatus(ImageView::Property::IMAGE), Visual::ResourceStatus::FAILED, TEST_LOCATION);
2868
2869     // Should be shown a broken image
2870     DALI_TEST_EQUALS(imageView.GetRendererCount(), 1u, TEST_LOCATION);
2871     DALI_TEST_EQUALS(textureTrace.FindMethod("BindTexture"), true, TEST_LOCATION);
2872   }
2873
2874   // Local svg file - invalid file path without size set
2875   {
2876     ToolkitTestApplication application;
2877
2878     TestGlAbstraction& gl           = application.GetGlAbstraction();
2879     TraceCallStack&    textureTrace = gl.GetTextureTrace();
2880     textureTrace.Enable(true);
2881
2882     gResourceReadySignalFired = false;
2883     textureTrace.Reset();
2884
2885     ImageView imageView = ImageView::New(TEST_RESOURCE_DIR "/foo.svg");
2886     imageView.ResourceReadySignal().Connect(&ResourceReadySignal);
2887
2888     DALI_TEST_EQUALS(imageView.IsResourceReady(), false, TEST_LOCATION);
2889
2890     application.GetScene().Add(imageView);
2891
2892     application.SendNotification();
2893
2894     // loading started, this waits for the loader thread - load & rasterize
2895     DALI_TEST_EQUALS(Test::WaitForEventThreadTrigger(1), true, TEST_LOCATION);
2896
2897     application.SendNotification();
2898     application.Render(16);
2899
2900     DALI_TEST_EQUALS(gResourceReadySignalFired, true, TEST_LOCATION);
2901     DALI_TEST_EQUALS(imageView.IsResourceReady(), true, TEST_LOCATION);
2902     DALI_TEST_EQUALS(imageView.GetVisualResourceStatus(ImageView::Property::IMAGE), Visual::ResourceStatus::FAILED, TEST_LOCATION);
2903
2904     // Should be shown a broken image
2905     DALI_TEST_EQUALS(imageView.GetRendererCount(), 1u, TEST_LOCATION);
2906     DALI_TEST_EQUALS(textureTrace.FindMethod("BindTexture"), true, TEST_LOCATION);
2907   }
2908
2909   // Local svg file - invalid file
2910   {
2911     ToolkitTestApplication application;
2912
2913     TestGlAbstraction& gl           = application.GetGlAbstraction();
2914     TraceCallStack&    textureTrace = gl.GetTextureTrace();
2915     textureTrace.Enable(true);
2916
2917     gResourceReadySignalFired = false;
2918     textureTrace.Reset();
2919
2920     ImageView imageView = ImageView::New(TEST_RESOURCE_DIR "/invalid.svg");
2921     imageView.SetProperty(Actor::Property::SIZE, Vector2(200.f, 200.f));
2922     imageView.ResourceReadySignal().Connect(&ResourceReadySignal);
2923
2924     DALI_TEST_EQUALS(imageView.IsResourceReady(), false, TEST_LOCATION);
2925
2926     application.GetScene().Add(imageView);
2927
2928     application.SendNotification();
2929
2930     // loading started, this waits for the loader thread - load & rasterize
2931     DALI_TEST_EQUALS(Test::WaitForEventThreadTrigger(1), true, TEST_LOCATION);
2932
2933     application.SendNotification();
2934     application.Render(16);
2935
2936     DALI_TEST_EQUALS(gResourceReadySignalFired, true, TEST_LOCATION);
2937     DALI_TEST_EQUALS(imageView.IsResourceReady(), true, TEST_LOCATION);
2938     DALI_TEST_EQUALS(imageView.GetVisualResourceStatus(ImageView::Property::IMAGE), Visual::ResourceStatus::FAILED, TEST_LOCATION);
2939
2940     // Should be shown a broken image
2941     DALI_TEST_EQUALS(imageView.GetRendererCount(), 1u, TEST_LOCATION);
2942     DALI_TEST_EQUALS(textureTrace.FindMethod("BindTexture"), true, TEST_LOCATION);
2943   }
2944
2945   END_TEST;
2946 }
2947
2948 int UtcDaliImageViewSvgLoadingFailureRemoteFile01(void)
2949 {
2950   // Remote svg file
2951   {
2952     ToolkitTestApplication application;
2953
2954     TestGlAbstraction& gl           = application.GetGlAbstraction();
2955     TraceCallStack&    textureTrace = gl.GetTextureTrace();
2956     textureTrace.Enable(true);
2957
2958     gResourceReadySignalFired = false;
2959
2960     ImageView imageView = ImageView::New("https://127.0.0.1/foobar.svg");
2961     imageView.SetProperty(Actor::Property::SIZE, Vector2(200.f, 200.f));
2962     imageView.ResourceReadySignal().Connect(&ResourceReadySignal);
2963
2964     DALI_TEST_EQUALS(imageView.IsResourceReady(), false, TEST_LOCATION);
2965
2966     application.GetScene().Add(imageView);
2967
2968     application.SendNotification();
2969
2970     // loading started, this waits for the loader thread - load & rasterize
2971     DALI_TEST_EQUALS(Test::WaitForEventThreadTrigger(1), true, TEST_LOCATION);
2972
2973     application.SendNotification();
2974     application.Render(16);
2975
2976     DALI_TEST_EQUALS(gResourceReadySignalFired, true, TEST_LOCATION);
2977     DALI_TEST_EQUALS(imageView.IsResourceReady(), true, TEST_LOCATION);
2978     DALI_TEST_EQUALS(imageView.GetVisualResourceStatus(ImageView::Property::IMAGE), Visual::ResourceStatus::FAILED, TEST_LOCATION);
2979
2980     // Should be shown a broken image
2981     DALI_TEST_EQUALS(imageView.GetRendererCount(), 1u, TEST_LOCATION);
2982     DALI_TEST_EQUALS(textureTrace.FindMethod("BindTexture"), true, TEST_LOCATION);
2983   }
2984
2985   END_TEST;
2986 }
2987
2988 int UtcDaliImageViewSvgLoadingFailureRemoteFile02(void)
2989 {
2990   // Remote svg file without size set
2991   {
2992     ToolkitTestApplication application;
2993
2994     TestGlAbstraction& gl           = application.GetGlAbstraction();
2995     TraceCallStack&    textureTrace = gl.GetTextureTrace();
2996     textureTrace.Enable(true);
2997
2998     gResourceReadySignalFired = false;
2999
3000     ImageView imageView = ImageView::New("https://127.0.0.1/foobar.svg");
3001     imageView.ResourceReadySignal().Connect(&ResourceReadySignal);
3002
3003     DALI_TEST_EQUALS(imageView.IsResourceReady(), false, TEST_LOCATION);
3004
3005     application.GetScene().Add(imageView);
3006
3007     application.SendNotification();
3008
3009     // loading started, this waits for the loader thread - load & rasterize
3010     DALI_TEST_EQUALS(Test::WaitForEventThreadTrigger(1), true, TEST_LOCATION);
3011
3012     application.SendNotification();
3013     application.Render(16);
3014
3015     DALI_TEST_EQUALS(gResourceReadySignalFired, true, TEST_LOCATION);
3016     DALI_TEST_EQUALS(imageView.IsResourceReady(), true, TEST_LOCATION);
3017     DALI_TEST_EQUALS(imageView.GetVisualResourceStatus(ImageView::Property::IMAGE), Visual::ResourceStatus::FAILED, TEST_LOCATION);
3018
3019     // Should be shown a broken image
3020     DALI_TEST_EQUALS(imageView.GetRendererCount(), 1u, TEST_LOCATION);
3021     DALI_TEST_EQUALS(textureTrace.FindMethod("BindTexture"), true, TEST_LOCATION);
3022   }
3023
3024   END_TEST;
3025 }
3026
3027 int UtcDaliImageViewSvgRasterizationFailure(void)
3028 {
3029   ToolkitTestApplication application;
3030
3031   gResourceReadySignalFired = false;
3032
3033   TestGlAbstraction& gl           = application.GetGlAbstraction();
3034   TraceCallStack&    textureTrace = gl.GetTextureTrace();
3035   textureTrace.Enable(true);
3036
3037   ImageView imageView = ImageView::New(TEST_RESOURCE_DIR "/invalid1.svg");
3038   imageView.SetProperty(Actor::Property::SIZE, Vector2(200.f, 200.f));
3039   imageView.ResourceReadySignal().Connect(&ResourceReadySignal);
3040
3041   DALI_TEST_EQUALS(imageView.IsResourceReady(), false, TEST_LOCATION);
3042
3043   application.GetScene().Add(imageView);
3044
3045   application.SendNotification();
3046
3047   // Wait for loading & rasterization
3048   DALI_TEST_EQUALS(Test::WaitForEventThreadTrigger(2), true, TEST_LOCATION);
3049
3050   application.SendNotification();
3051   application.Render(16);
3052
3053   DALI_TEST_EQUALS(gResourceReadySignalFired, true, TEST_LOCATION);
3054   DALI_TEST_EQUALS(imageView.IsResourceReady(), true, TEST_LOCATION);
3055   DALI_TEST_EQUALS(imageView.GetVisualResourceStatus(ImageView::Property::IMAGE), Visual::ResourceStatus::FAILED, TEST_LOCATION);
3056
3057   // Should be shown a broken image
3058   DALI_TEST_EQUALS(imageView.GetRendererCount(), 1u, TEST_LOCATION);
3059   DALI_TEST_EQUALS(textureTrace.FindMethod("BindTexture"), true, TEST_LOCATION);
3060
3061   END_TEST;
3062 }
3063
3064 int UtcDaliImageViewSvgChageSize(void)
3065 {
3066   ToolkitTestApplication application;
3067
3068   TestGlAbstraction& gl           = application.GetGlAbstraction();
3069   TraceCallStack&    textureTrace = gl.GetTextureTrace();
3070   textureTrace.Enable(true);
3071
3072   ImageView imageView = ImageView::New(TEST_SVG_FILE_NAME);
3073   application.GetScene().Add(imageView);
3074
3075   application.SendNotification();
3076
3077   // Wait for loading & rasterization
3078   DALI_TEST_EQUALS(Test::WaitForEventThreadTrigger(2), true, TEST_LOCATION);
3079
3080   application.SendNotification();
3081   application.Render(16);
3082
3083   DALI_TEST_EQUALS(Test::VectorImageRenderer::GetLoadCount(), 1, TEST_LOCATION);
3084
3085   // Change actor size, then rasterization should be done again
3086   imageView.SetProperty(Actor::Property::SIZE, Vector2(200.f, 200.f));
3087
3088   application.SendNotification();
3089
3090   // Wait for rasterization
3091   DALI_TEST_EQUALS(Test::WaitForEventThreadTrigger(1), true, TEST_LOCATION);
3092
3093   application.SendNotification();
3094   application.Render(16);
3095
3096   // We should not load the file again.
3097   DALI_TEST_EQUALS(Test::VectorImageRenderer::GetLoadCount(), 1, TEST_LOCATION);
3098
3099   END_TEST;
3100 }
3101
3102 int UtcDaliImageViewSvgAtlasing(void)
3103 {
3104   ToolkitTestApplication application;
3105
3106   TraceCallStack& callStack = application.GetGlAbstraction().GetTextureTrace();
3107   callStack.Reset();
3108   callStack.Enable(true);
3109
3110   Property::Map propertyMap;
3111   propertyMap["url"]      = TEST_SVG_FILE_NAME;
3112   propertyMap["atlasing"] = true;
3113
3114   ImageView imageView = ImageView::New();
3115   imageView.SetProperty(ImageView::Property::IMAGE, propertyMap);
3116   imageView.SetProperty(Actor::Property::SIZE, Vector2(100.f, 100.f));
3117   application.GetScene().Add(imageView);
3118
3119   application.SendNotification();
3120
3121   // Wait for loading & rasterization
3122   DALI_TEST_EQUALS(Test::WaitForEventThreadTrigger(2), true, TEST_LOCATION);
3123
3124   application.SendNotification();
3125   application.Render(16);
3126
3127   // use atlas
3128   TraceCallStack::NamedParams params1;
3129   params1["width"] << 100;
3130   params1["height"] << 100;
3131   DALI_TEST_EQUALS(callStack.FindMethodAndParams("TexSubImage2D", params1), true, TEST_LOCATION);
3132
3133   imageView.SetProperty(Actor::Property::SIZE, Vector2(600.f, 600.f));
3134
3135   application.SendNotification();
3136
3137   // Wait for rasterization
3138   DALI_TEST_EQUALS(Test::WaitForEventThreadTrigger(1), true, TEST_LOCATION);
3139
3140   callStack.Reset();
3141
3142   application.SendNotification();
3143   application.Render(16);
3144
3145   // not use atlas
3146   TraceCallStack::NamedParams params2;
3147   params2["width"] << 600;
3148   params2["height"] << 600;
3149   DALI_TEST_EQUALS(callStack.FindMethodAndParams("TexImage2D", params2), true, TEST_LOCATION);
3150
3151   END_TEST;
3152 }
3153
3154 int UtcDaliImageViewTVGLoading(void)
3155 {
3156   ToolkitTestApplication application;
3157
3158   tet_infoline("ImageView Testing TVG image loading");
3159
3160   {
3161     ImageView imageView = ImageView::New(TEST_RESOURCE_DIR "/test.tvg");
3162     application.GetScene().Add(imageView);
3163     DALI_TEST_CHECK(imageView);
3164
3165     application.SendNotification();
3166
3167     DALI_TEST_EQUALS(Test::WaitForEventThreadTrigger(1), true, TEST_LOCATION);
3168
3169     application.SendNotification();
3170     application.Render(16);
3171
3172     Vector3 naturalSize = imageView.GetNaturalSize();
3173
3174     DALI_TEST_EQUALS(naturalSize.width, 100.0f, TEST_LOCATION);
3175     DALI_TEST_EQUALS(naturalSize.height, 100.0f, TEST_LOCATION);
3176   }
3177   END_TEST;
3178 }
3179
3180 int UtcDaliImageViewImageLoadFailure01(void)
3181 {
3182   ToolkitTestApplication application;
3183
3184   Toolkit::StyleManager styleManager = Toolkit::StyleManager::Get();
3185   DevelStyleManager::SetBrokenImageUrl(styleManager, DevelStyleManager::BrokenImageType::SMALL, TEST_BROKEN_IMAGE_S);
3186   DevelStyleManager::SetBrokenImageUrl(styleManager, DevelStyleManager::BrokenImageType::NORMAL, TEST_BROKEN_IMAGE_M);
3187   DevelStyleManager::SetBrokenImageUrl(styleManager, DevelStyleManager::BrokenImageType::LARGE, TEST_BROKEN_IMAGE_L);
3188
3189   std::string brokenUrl;
3190   brokenUrl = DevelStyleManager::GetBrokenImageUrl(styleManager, DevelStyleManager::BrokenImageType::SMALL);
3191   DALI_TEST_EQUALS(TEST_BROKEN_IMAGE_S, brokenUrl, TEST_LOCATION);
3192
3193   brokenUrl = DevelStyleManager::GetBrokenImageUrl(styleManager, DevelStyleManager::BrokenImageType::NORMAL);
3194   DALI_TEST_EQUALS(TEST_BROKEN_IMAGE_M, brokenUrl, TEST_LOCATION);
3195
3196   brokenUrl = DevelStyleManager::GetBrokenImageUrl(styleManager, DevelStyleManager::BrokenImageType::LARGE);
3197   DALI_TEST_EQUALS(TEST_BROKEN_IMAGE_L, brokenUrl, TEST_LOCATION);
3198
3199   ImageView imageView = ImageView::New("invalidUrl.png");
3200   imageView.SetProperty(Actor::Property::SIZE, Vector2(200.f, 200.f));
3201
3202   application.GetScene().Add(imageView);
3203   application.SendNotification();
3204   application.Render(16);
3205
3206   // loading started, this waits for the loader thread
3207   DALI_TEST_EQUALS(Test::WaitForEventThreadTrigger(1), true, TEST_LOCATION);
3208
3209   END_TEST;
3210 }
3211
3212 int UtcDaliImageViewImageLoadFailure02(void)
3213 {
3214   ToolkitTestApplication application;
3215
3216   Toolkit::StyleManager styleManager = Toolkit::StyleManager::Get();
3217   DevelStyleManager::SetBrokenImageUrl(styleManager, DevelStyleManager::BrokenImageType::SMALL, TEST_BROKEN_IMAGE_DEFAULT);
3218   DevelStyleManager::SetBrokenImageUrl(styleManager, DevelStyleManager::BrokenImageType::NORMAL, TEST_BROKEN_IMAGE_M);
3219   DevelStyleManager::SetBrokenImageUrl(styleManager, DevelStyleManager::BrokenImageType::LARGE, TEST_BROKEN_IMAGE_L);
3220
3221   std::string brokenUrl;
3222   brokenUrl = DevelStyleManager::GetBrokenImageUrl(styleManager, DevelStyleManager::BrokenImageType::SMALL);
3223   DALI_TEST_EQUALS(TEST_BROKEN_IMAGE_DEFAULT, brokenUrl, TEST_LOCATION);
3224
3225   brokenUrl = DevelStyleManager::GetBrokenImageUrl(styleManager, DevelStyleManager::BrokenImageType::NORMAL);
3226   DALI_TEST_EQUALS(TEST_BROKEN_IMAGE_M, brokenUrl, TEST_LOCATION);
3227
3228   brokenUrl = DevelStyleManager::GetBrokenImageUrl(styleManager, DevelStyleManager::BrokenImageType::LARGE);
3229   DALI_TEST_EQUALS(TEST_BROKEN_IMAGE_L, brokenUrl, TEST_LOCATION);
3230
3231   ImageView imageView = ImageView::New("invalidUrl.png");
3232   imageView.SetProperty(Actor::Property::SIZE, Vector2(30.f, 30.f));
3233   application.GetScene().Add(imageView);
3234   application.SendNotification();
3235   application.Render(16);
3236
3237   // loading started, this waits for the loader thread
3238   DALI_TEST_EQUALS(Test::WaitForEventThreadTrigger(1), true, TEST_LOCATION);
3239
3240   END_TEST;
3241 }
3242
3243 int UtcDaliImageViewImageLoadFailure03(void)
3244 {
3245   ToolkitTestApplication application;
3246
3247   Toolkit::StyleManager styleManager = Toolkit::StyleManager::Get();
3248   DevelStyleManager::SetBrokenImageUrl(styleManager, DevelStyleManager::BrokenImageType::SMALL, TEST_BROKEN_IMAGE_01);
3249   DevelStyleManager::SetBrokenImageUrl(styleManager, DevelStyleManager::BrokenImageType::NORMAL, TEST_BROKEN_IMAGE_02);
3250
3251   std::string brokenUrl;
3252   brokenUrl = DevelStyleManager::GetBrokenImageUrl(styleManager, DevelStyleManager::BrokenImageType::SMALL);
3253   DALI_TEST_EQUALS(TEST_BROKEN_IMAGE_01, brokenUrl, TEST_LOCATION);
3254
3255   brokenUrl = DevelStyleManager::GetBrokenImageUrl(styleManager, DevelStyleManager::BrokenImageType::NORMAL);
3256   DALI_TEST_EQUALS(TEST_BROKEN_IMAGE_02, brokenUrl, TEST_LOCATION);
3257
3258   ImageView imageView = ImageView::New("invalidUrl.png");
3259   imageView.SetProperty(Actor::Property::SIZE, Vector2(100.f, 100.f));
3260   application.GetScene().Add(imageView);
3261   application.SendNotification();
3262   application.Render(16);
3263
3264   // loading started, this waits for the loader thread
3265   DALI_TEST_EQUALS(Test::WaitForEventThreadTrigger(1), true, TEST_LOCATION);
3266
3267   END_TEST;
3268 }
3269
3270 int UtcDaliImageViewImageLoadFailure04(void)
3271 {
3272   ToolkitTestApplication application;
3273
3274   ImageView imageView = ImageView::New("invalidUrl.png");
3275   imageView.SetProperty(Actor::Property::SIZE, Vector2(100.f, 100.f));
3276   application.GetScene().Add(imageView);
3277   application.SendNotification();
3278   application.Render(16);
3279
3280   // loading started, this waits for the loader thread
3281   DALI_TEST_EQUALS(Test::WaitForEventThreadTrigger(1), true, TEST_LOCATION);
3282
3283   Toolkit::StyleManager styleManager = Toolkit::StyleManager::Get();
3284   DevelStyleManager::SetBrokenImageUrl(styleManager, DevelStyleManager::BrokenImageType::SMALL, TEST_BROKEN_IMAGE_S);
3285   DevelStyleManager::SetBrokenImageUrl(styleManager, DevelStyleManager::BrokenImageType::NORMAL, "invalidBroken.png");
3286   DevelStyleManager::SetBrokenImageUrl(styleManager, DevelStyleManager::BrokenImageType::LARGE, TEST_BROKEN_IMAGE_L);
3287
3288   ImageView imageView2 = ImageView::New("invalidUrl.png");
3289   imageView2.SetProperty(Actor::Property::SIZE, Vector2(100.f, 100.f));
3290   application.GetScene().Add(imageView2);
3291
3292   std::string brokenUrl;
3293   brokenUrl = DevelStyleManager::GetBrokenImageUrl(styleManager, DevelStyleManager::BrokenImageType::SMALL);
3294   DALI_TEST_EQUALS(TEST_BROKEN_IMAGE_S, brokenUrl, TEST_LOCATION);
3295
3296   brokenUrl = DevelStyleManager::GetBrokenImageUrl(styleManager, DevelStyleManager::BrokenImageType::LARGE);
3297   DALI_TEST_EQUALS(TEST_BROKEN_IMAGE_L, brokenUrl, TEST_LOCATION);
3298
3299   application.SendNotification();
3300   application.Render(16);
3301
3302   // loading started, this waits for the loader thread
3303   DALI_TEST_EQUALS(Test::WaitForEventThreadTrigger(1), true, TEST_LOCATION);
3304
3305   DevelStyleManager::SetBrokenImageUrl(styleManager, DevelStyleManager::BrokenImageType::NORMAL, "invalidBroken.9.png");
3306
3307   ImageView imageView3 = ImageView::New("invalidUrl.png");
3308   imageView3.SetProperty(Actor::Property::SIZE, Vector2(100.f, 100.f));
3309   application.GetScene().Add(imageView3);
3310
3311   application.SendNotification();
3312   application.Render(16);
3313
3314   // loading started, this waits for the loader thread
3315   DALI_TEST_EQUALS(Test::WaitForEventThreadTrigger(1), true, TEST_LOCATION);
3316
3317   END_TEST;
3318 }
3319
3320 namespace
3321 {
3322 static int gResourceReadySignalCounter = 0;
3323
3324 void OnResourceReadySignal01(Control control)
3325 {
3326   gResourceReadySignalCounter++;
3327
3328   if(control.GetVisualResourceStatus(ImageView::Property::IMAGE) == Visual::ResourceStatus::READY)
3329   {
3330     if(gResourceReadySignalCounter == 1)
3331     {
3332       // Set image twice
3333       // It makes the first new visual be deleted immediately
3334       ImageView::DownCast(control).SetImage(gImage_34_RGBA);
3335       ImageView::DownCast(control).SetImage(gImage_34_RGBA);
3336     }
3337   }
3338   else if(control.GetVisualResourceStatus(ImageView::Property::IMAGE) == Visual::ResourceStatus::FAILED)
3339   {
3340     // Make the resource ready immediately
3341     control[ImageView::Property::IMAGE] = gImage_600_RGB;
3342   }
3343 }
3344
3345 void OnResourceReadySignal02(Control control)
3346 {
3347   if(++gResourceReadySignalCounter == 1)
3348   {
3349     // It makes the first new visual be deleted immediately
3350     // The first image will not be loaded.
3351     control[ImageView::Property::IMAGE] = Property::Map().Add(ImageVisual::Property::URL, gImage_600_RGB).Add(ImageVisual::Property::RELEASE_POLICY, ImageVisual::ReleasePolicy::NEVER);
3352     control[ImageView::Property::IMAGE] = TEST_IMAGE_1;
3353   }
3354 }
3355
3356 ImageView gImageView1;
3357 ImageView gImageView2;
3358 ImageView gImageView3;
3359 ImageView gImageView4;
3360
3361 void OnResourceReadySignal03(Control control)
3362 {
3363   if(gResourceReadySignalCounter == 0)
3364   {
3365     // Queue loading
3366     // 1. Use cached image, then LoadComplete will be called right after OnResourceReadySignal03.
3367     gImageView2[ImageView::Property::IMAGE] = gImage_34_RGBA;
3368
3369     // 2. Load a new image
3370     gImageView3[ImageView::Property::IMAGE] = TEST_IMAGE_1;
3371
3372     // 3. Use the new image again
3373     gImageView1[ImageView::Property::IMAGE] = TEST_IMAGE_1;
3374     gImageView1.ResourceReadySignal().Connect(&OnResourceReadySignal03);
3375   }
3376   else if(gResourceReadySignalCounter == 1)
3377   {
3378     // This is called from TextureManager::ProcessQueuedTextures().
3379     gImageView1.Unparent();
3380     gImageView1.Reset();
3381   }
3382   gResourceReadySignalCounter++;
3383 }
3384
3385 void OnSimpleResourceReadySignal(Control control)
3386 {
3387   // simply increate counter
3388   gResourceReadySignalCounter++;
3389 }
3390
3391 int gResourceReadySignal04ComesOrder = 0;
3392
3393 void OnResourceReadySignal04(Control control)
3394 {
3395   gResourceReadySignalCounter++;
3396   tet_printf("rc %d\n", gResourceReadySignalCounter);
3397   if(gResourceReadySignalCounter == 1)
3398   {
3399     auto scene = gImageView1.GetParent();
3400
3401     // Request load something
3402     // We hope this request result is return later than gImageView2.
3403     gImageView3 = ImageView::New(TEST_IMAGE_1);
3404     gImageView3.ResourceReadySignal().Connect(&OnResourceReadySignal04);
3405     scene.Add(gImageView3);
3406     gImageView4 = ImageView::New(TEST_IMAGE_2);
3407     gImageView4.ResourceReadySignal().Connect(&OnResourceReadySignal04);
3408     scene.Add(gImageView4);
3409
3410     if(control == gImageView1)
3411     {
3412       gResourceReadySignal04ComesOrder = 1;
3413     }
3414     else
3415     {
3416       gResourceReadySignal04ComesOrder = 2;
3417     }
3418   }
3419   if(gResourceReadySignalCounter == 2)
3420   {
3421     if(gResourceReadySignal04ComesOrder == 1 && control == gImageView2)
3422     {
3423       // Scene off first one.
3424       gImageView1.Unparent();
3425
3426       // Scene off second one.
3427       gImageView2.Unparent();
3428     }
3429     else if(gResourceReadySignal04ComesOrder == 2 && control == gImageView1)
3430     {
3431       // Scene off first one.
3432       gImageView2.Unparent();
3433
3434       // Scene off second one.
3435       gImageView1.Unparent();
3436     }
3437     else
3438     {
3439       // We can't check that this utc fail case. just pass always when we come here.
3440       gResourceReadySignal04ComesOrder = -1;
3441     }
3442
3443     // If we don't seperate index of FreeList area
3444     // and if we don't queue remove during obversing,
3445     // cache index become something invalid data.
3446     // In this case, some strange observer can be called.
3447     // For example, gImageView4.LoadComplete will be called.
3448   }
3449 }
3450
3451 void OnResourceReadySignal05(Control control)
3452 {
3453   gResourceReadySignalCounter++;
3454
3455   // Request load with same image
3456   // NOTE : The url must not be same as gImageView1
3457   const int viewCount = 4;
3458   for(int i = 0; i < viewCount; ++i)
3459   {
3460     gImageView1.Add(ImageView::New("invalid2.jpg"));
3461   }
3462 }
3463
3464 int gResourceReadySignal06ComesOrder = 0;
3465
3466 void OnResourceReadySignal06(Control control)
3467 {
3468   gResourceReadySignalCounter++;
3469   if(gResourceReadySignalCounter == 1)
3470   {
3471     auto scene = gImageView1.GetParent();
3472
3473     // Request load something
3474     // We hope this request result is return later than gImageView2.
3475
3476     Property::Map map1;
3477     map1[Toolkit::ImageVisual::Property::URL] = TEST_IMAGE_1;
3478     map1[Toolkit::ImageVisual::Property::ALPHA_MASK_URL] = TEST_BROKEN_IMAGE_DEFAULT;
3479
3480     gImageView3 = ImageView::New();
3481     gImageView3.SetProperty(Toolkit::ImageView::Property::IMAGE, map1);
3482     gImageView3.ResourceReadySignal().Connect(&OnResourceReadySignal06);
3483
3484     Property::Map map2;
3485     map2[Toolkit::ImageVisual::Property::URL] = TEST_IMAGE_2;
3486     map2[Toolkit::ImageVisual::Property::ALPHA_MASK_URL] = TEST_BROKEN_IMAGE_S;
3487     gImageView4 = ImageView::New();
3488     gImageView4.SetProperty(Toolkit::ImageView::Property::IMAGE, map2);
3489     gImageView4.ResourceReadySignal().Connect(&OnResourceReadySignal06);
3490
3491     if(control == gImageView1)
3492     {
3493       gResourceReadySignal06ComesOrder = 1;
3494     }
3495     else
3496     {
3497       gResourceReadySignal06ComesOrder = 2;
3498     }
3499   }
3500   if(gResourceReadySignalCounter == 2)
3501   {
3502     if(gResourceReadySignal06ComesOrder == 1 && control == gImageView2)
3503     {
3504       // Scene off first one.
3505       gImageView1.Unparent();
3506
3507       // Scene off second one.
3508       gImageView2.Unparent();
3509     }
3510     else if(gResourceReadySignal06ComesOrder == 2 && control == gImageView1)
3511     {
3512       // Scene off first one.
3513       gImageView2.Unparent();
3514
3515       // Scene off second one.
3516       gImageView1.Unparent();
3517     }
3518     else
3519     {
3520       // We can't check that this utc fail case. just pass always when we come here.
3521       gResourceReadySignal06ComesOrder = -1;
3522     }
3523
3524     // If we don't seperate index of FreeList area
3525     // and if we don't queue remove during obversing,
3526     // cache index become something invalid data.
3527     // In this case, some strange observer can be called.
3528     // For example, gImageView4.LoadComplete will be called.
3529   }
3530 }
3531
3532 } // namespace
3533
3534 int UtcDaliImageViewSetImageOnResourceReadySignal01(void)
3535 {
3536   tet_infoline("Test setting image from within signal handler.");
3537
3538   ToolkitTestApplication application;
3539
3540   gResourceReadySignalCounter = 0;
3541
3542   ImageView imageView = ImageView::New(gImage_34_RGBA);
3543   imageView.ResourceReadySignal().Connect(&OnResourceReadySignal01);
3544
3545   application.GetScene().Add(imageView);
3546
3547   DALI_TEST_EQUALS(Test::WaitForEventThreadTrigger(1), true, TEST_LOCATION);
3548
3549   application.SendNotification();
3550   application.Render();
3551
3552   DALI_TEST_EQUALS(gResourceReadySignalCounter, 2, TEST_LOCATION);
3553
3554   DALI_TEST_EQUALS(imageView.IsResourceReady(), true, TEST_LOCATION);
3555
3556   // Create a new ImageView to cache the image
3557   ImageView imageView1 = ImageView::New(gImage_600_RGB);
3558   application.GetScene().Add(imageView1);
3559
3560   DALI_TEST_EQUALS(Test::WaitForEventThreadTrigger(1), true, TEST_LOCATION);
3561
3562   application.SendNotification();
3563   application.Render();
3564
3565   // Reset count
3566   gResourceReadySignalCounter = 0;
3567
3568   imageView[ImageView::Property::IMAGE] = "invalid.jpg";
3569
3570   DALI_TEST_EQUALS(Test::WaitForEventThreadTrigger(1), true, TEST_LOCATION);
3571
3572   application.SendNotification();
3573   application.Render();
3574
3575   // Run idle callback
3576   application.RunIdles();
3577
3578   DALI_TEST_EQUALS(gResourceReadySignalCounter, 2, TEST_LOCATION);
3579
3580   DALI_TEST_EQUALS(imageView.IsResourceReady(), true, TEST_LOCATION);
3581
3582   END_TEST;
3583 }
3584
3585 int UtcDaliImageViewSetImageOnResourceReadySignal02(void)
3586 {
3587   tet_infoline("Test setting image from within signal handler.");
3588
3589   ToolkitTestApplication application;
3590
3591   gResourceReadySignalCounter = 0;
3592
3593   ImageView imageView = ImageView::New(gImage_34_RGBA);
3594   imageView.ResourceReadySignal().Connect(&OnResourceReadySignal02);
3595
3596   application.GetScene().Add(imageView);
3597
3598   DALI_TEST_EQUALS(Test::WaitForEventThreadTrigger(1), true, TEST_LOCATION);
3599
3600   application.SendNotification();
3601   application.Render();
3602
3603   // Wait for loading an image
3604   DALI_TEST_EQUALS(Test::WaitForEventThreadTrigger(1), true, TEST_LOCATION);
3605
3606   DALI_TEST_EQUALS(gResourceReadySignalCounter, 2, TEST_LOCATION);
3607
3608   DALI_TEST_EQUALS(imageView.IsResourceReady(), true, TEST_LOCATION);
3609
3610   END_TEST;
3611 }
3612
3613 int UtcDaliImageViewSetImageOnResourceReadySignal03(void)
3614 {
3615   tet_infoline("Test setting image from within signal handler.");
3616
3617   ToolkitTestApplication application;
3618
3619   gResourceReadySignalCounter = 0;
3620
3621   gImageView1 = ImageView::New(gImage_34_RGBA);
3622   application.GetScene().Add(gImageView1);
3623
3624   // Wait for loading
3625   DALI_TEST_EQUALS(Test::WaitForEventThreadTrigger(1), true, TEST_LOCATION);
3626
3627   gImageView2 = ImageView::New(gImage_600_RGB);
3628   gImageView2.ResourceReadySignal().Connect(&OnResourceReadySignal03);
3629   application.GetScene().Add(gImageView2);
3630
3631   gImageView3 = ImageView::New();
3632   application.GetScene().Add(gImageView3);
3633
3634   DALI_TEST_EQUALS(Test::WaitForEventThreadTrigger(2), true, TEST_LOCATION);
3635
3636   application.SendNotification();
3637   application.Render();
3638
3639   END_TEST;
3640 }
3641
3642 int UtcDaliImageViewOnResourceReadySignalWithBrokenAlphaMask01(void)
3643 {
3644   tet_infoline("Test signal handler when image / mask image is broken.");
3645
3646   ToolkitTestApplication application;
3647
3648   auto TestResourceReadyUrl = [&application](int eventTriggerCount, bool isSynchronous, const std::string& url, const std::string& mask, const char* location) {
3649     gResourceReadySignalCounter = 0;
3650
3651     Property::Map map;
3652     map[Toolkit::ImageVisual::Property::URL] = url;
3653     if(!mask.empty())
3654     {
3655       map[Toolkit::ImageVisual::Property::ALPHA_MASK_URL] = mask;
3656     }
3657     map[Toolkit::ImageVisual::Property::SYNCHRONOUS_LOADING] = isSynchronous;
3658
3659     ImageView imageView                            = ImageView::New();
3660     imageView[Toolkit::ImageView::Property::IMAGE] = map;
3661     imageView[Actor::Property::SIZE]               = Vector2(100.0f, 200.0f);
3662     imageView.ResourceReadySignal().Connect(&OnSimpleResourceReadySignal);
3663
3664     application.GetScene().Add(imageView);
3665     application.SendNotification();
3666     application.Render();
3667
3668     if(!isSynchronous)
3669     {
3670       // Wait for loading
3671       DALI_TEST_EQUALS(Test::WaitForEventThreadTrigger(eventTriggerCount), true, location);
3672     }
3673     tet_printf("test %s [sync:%d] signal fired\n", url.c_str(), isSynchronous ? 1 : 0);
3674     DALI_TEST_EQUALS(gResourceReadySignalCounter, 1, location);
3675
3676     imageView.Unparent();
3677   };
3678
3679   for(int synchronous = 0; synchronous <= 1; synchronous++)
3680   {
3681     tet_printf("Test normal case (sync:%d)\n", synchronous);
3682     TestResourceReadyUrl(1, synchronous, gImage_600_RGB, "", TEST_LOCATION);
3683     TestResourceReadyUrl(3, synchronous, gImage_600_RGB, gImage_34_RGBA, TEST_LOCATION); // 3 event trigger required : 2 image load + 1 apply mask
3684
3685     tet_printf("Test broken image case (sync:%d)\n", synchronous);
3686     TestResourceReadyUrl(1, synchronous, "invalid.jpg", "", TEST_LOCATION);
3687     TestResourceReadyUrl(2, synchronous, "invalid.jpg", gImage_34_RGBA, TEST_LOCATION);
3688
3689     tet_printf("Test broken mask image case (sync:%d)\n", synchronous);
3690     TestResourceReadyUrl(2, synchronous, gImage_600_RGB, "invalid.png", TEST_LOCATION);
3691
3692     tet_printf("Test broken both image, mask image case (sync:%d)\n", synchronous);
3693     TestResourceReadyUrl(2, synchronous, "invalid.jpg", "invalid.png", TEST_LOCATION);
3694   }
3695
3696   END_TEST;
3697 }
3698
3699 int UtcDaliImageViewOnResourceReadySignalWithBrokenAlphaMask02(void)
3700 {
3701   tet_infoline("Test signal handler when image try to use cached-and-broken mask image.");
3702
3703   ToolkitTestApplication application;
3704
3705   gResourceReadySignalCounter = 0;
3706
3707   auto TestBrokenMaskResourceReadyUrl = [&application](const std::string& url, const char* location) {
3708     Property::Map map;
3709     map[Toolkit::ImageVisual::Property::URL] = url;
3710     // Use invalid mask url
3711     map[Toolkit::ImageVisual::Property::ALPHA_MASK_URL] = "invalid.png";
3712
3713     ImageView imageView                            = ImageView::New();
3714     imageView[Toolkit::ImageView::Property::IMAGE] = map;
3715     imageView[Actor::Property::SIZE]               = Vector2(100.0f, 200.0f);
3716     imageView.ResourceReadySignal().Connect(&OnSimpleResourceReadySignal);
3717
3718     application.GetScene().Add(imageView);
3719     application.SendNotification();
3720     application.Render();
3721
3722     // Don't unparent imageView, for keep the cache.
3723   };
3724
3725   // Use more than 4 images (The number of LocalImageLoadThread)
3726   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};
3727
3728   int expectResourceReadySignalCounter = 0;
3729
3730   for(auto& url : testUrlList)
3731   {
3732     TestBrokenMaskResourceReadyUrl(url, TEST_LOCATION);
3733     expectResourceReadySignalCounter++;
3734   }
3735
3736   // Remain 1 signal due to we use #URL + 1 mask image.
3737   DALI_TEST_EQUALS(Test::WaitForEventThreadTrigger(expectResourceReadySignalCounter + 1), true, TEST_LOCATION);
3738
3739   DALI_TEST_EQUALS(gResourceReadySignalCounter, expectResourceReadySignalCounter, TEST_LOCATION);
3740
3741   END_TEST;
3742 }
3743
3744 int UtcDaliImageViewCheckVariousCaseSendOnResourceReadySignal(void)
3745 {
3746   tet_infoline("Test signal handler various case.");
3747
3748   auto TestResourceReadyUrl = [](int eventTriggerCount, bool isSynchronous, bool loadSuccess, const std::string& url, const std::string& mask, const char* location) {
3749     ToolkitTestApplication application;
3750
3751     gResourceReadySignalCounter = 0;
3752
3753     Property::Map map;
3754     map[Toolkit::ImageVisual::Property::URL] = url;
3755     if(!mask.empty())
3756     {
3757       map[Toolkit::ImageVisual::Property::ALPHA_MASK_URL] = mask;
3758     }
3759     map[Toolkit::ImageVisual::Property::SYNCHRONOUS_LOADING] = isSynchronous;
3760
3761     ImageView imageView                            = ImageView::New();
3762     imageView[Toolkit::ImageView::Property::IMAGE] = map;
3763     imageView[Actor::Property::SIZE]               = Vector2(100.0f, 200.0f);
3764     imageView.ResourceReadySignal().Connect(&OnSimpleResourceReadySignal);
3765
3766     application.GetScene().Add(imageView);
3767     application.SendNotification();
3768     application.Render();
3769
3770     // Wait for loading
3771     DALI_TEST_EQUALS(Test::WaitForEventThreadTrigger(eventTriggerCount), true, location);
3772
3773     tet_printf("test %s [sync:%d] signal fired\n", url.c_str(), isSynchronous ? 1 : 0);
3774     DALI_TEST_EQUALS(gResourceReadySignalCounter, 1, location);
3775     DALI_TEST_EQUALS(imageView.GetVisualResourceStatus(Toolkit::ImageView::Property::IMAGE), loadSuccess ? Toolkit::Visual::ResourceStatus::READY : Toolkit::Visual::ResourceStatus::FAILED, location);
3776
3777     imageView.Unparent();
3778   };
3779
3780   auto TestAuxiliaryResourceReadyUrl = [](bool isSynchronous, bool loadSuccess, const std::string& url, const std::string& auxiliaryUrl, const char* location) {
3781     ToolkitTestApplication application;
3782
3783     gResourceReadySignalCounter = 0;
3784
3785     Property::Map map;
3786     map[Toolkit::ImageVisual::Property::URL]                        = url;
3787     map[Toolkit::DevelImageVisual::Property::AUXILIARY_IMAGE]       = auxiliaryUrl;
3788     map[Toolkit::DevelImageVisual::Property::AUXILIARY_IMAGE_ALPHA] = 0.5f;
3789     map[Toolkit::ImageVisual::Property::SYNCHRONOUS_LOADING]        = isSynchronous;
3790
3791     ImageView imageView = ImageView::New();
3792     imageView.SetProperty(Toolkit::ImageView::Property::IMAGE, map);
3793     imageView.SetProperty(Actor::Property::SIZE, Vector2(100.0f, 200.0f));
3794     imageView.ResourceReadySignal().Connect(&OnSimpleResourceReadySignal);
3795     application.GetScene().Add(imageView);
3796
3797     application.SendNotification();
3798     application.Render();
3799
3800     if(!isSynchronous)
3801     {
3802       // Wait for loading
3803       DALI_TEST_EQUALS(Test::WaitForEventThreadTrigger(2), true, location);
3804     }
3805
3806     tet_printf("test %s [sync:%d] signal fired\n", url.c_str(), isSynchronous ? 1 : 0);
3807     DALI_TEST_EQUALS(gResourceReadySignalCounter, 1, location);
3808     DALI_TEST_EQUALS(imageView.GetVisualResourceStatus(Toolkit::ImageView::Property::IMAGE), loadSuccess ? Toolkit::Visual::ResourceStatus::READY : Toolkit::Visual::ResourceStatus::FAILED, TEST_LOCATION);
3809
3810     imageView.Unparent();
3811   };
3812
3813   // Case 1 : asynchronous loading
3814   tet_printf("Test invalid single simple image Asynchronous\n");
3815
3816   // Test normal case
3817   TestResourceReadyUrl(1, 0, 1, gImage_600_RGB, "", TEST_LOCATION);
3818   TestResourceReadyUrl(2, 0, 1, TEST_SVG_FILE_NAME, "", TEST_LOCATION); // load & rasterize
3819   TestResourceReadyUrl(1, 0, 1, TEST_BROKEN_IMAGE_L, "", TEST_LOCATION);
3820
3821   TestResourceReadyUrl(2, 0, 1, TEST_GIF_FILE_NAME, "", TEST_LOCATION);                   // 2 image loading - batch size
3822   TestResourceReadyUrl(2, 0, 1, TEST_ANIMATED_VECTOR_IMAGE_FILE_NAME, "", TEST_LOCATION); // load & rasterize
3823
3824   TestResourceReadyUrl(3, 0, 1, gImage_600_RGB, gImage_34_RGBA, TEST_LOCATION); // 2 image loading + 1 applymask
3825
3826   TestAuxiliaryResourceReadyUrl(0, 1, TEST_BROKEN_IMAGE_L, gImage_34_RGBA, TEST_LOCATION);
3827
3828   // Test broken case
3829   TestResourceReadyUrl(1, 0, 0, "invalid.jpg", "", TEST_LOCATION);
3830   TestResourceReadyUrl(1, 0, 0, "invalid.svg", "", TEST_LOCATION);
3831   TestResourceReadyUrl(1, 0, 0, "invalid.9.png", "", TEST_LOCATION);
3832   TestResourceReadyUrl(1, 0, 0, "invalid.gif", "", TEST_LOCATION);  // 1 image loading
3833   TestResourceReadyUrl(1, 0, 0, "invalid.json", "", TEST_LOCATION); // 0 rasterize
3834
3835   TestResourceReadyUrl(2, 0, 0, "invalid.jpg", "invalid.png", TEST_LOCATION);  // 2 image loading
3836   TestResourceReadyUrl(2, 0, 1, gImage_600_RGB, "invalid.png", TEST_LOCATION); // 2 image loading
3837   TestResourceReadyUrl(2, 0, 0, "invalid.jpg", gImage_34_RGBA, TEST_LOCATION); // 2 image loading
3838
3839   TestAuxiliaryResourceReadyUrl(0, 0, "invalid.9.png", "invalid.png", TEST_LOCATION);
3840   TestAuxiliaryResourceReadyUrl(0, 1, TEST_BROKEN_IMAGE_L, "invalid.png", TEST_LOCATION);
3841   TestAuxiliaryResourceReadyUrl(0, 0, "invalid.9.png", gImage_34_RGBA, TEST_LOCATION);
3842
3843   // Case 2 : Synchronous loading
3844   tet_printf("Test invalid single simple image Synchronous\n");
3845
3846   // Test normal case
3847   TestResourceReadyUrl(0, 1, 1, gImage_600_RGB, "", TEST_LOCATION);
3848   TestResourceReadyUrl(0, 1, 1, TEST_SVG_FILE_NAME, "", TEST_LOCATION); // synchronous rasterize
3849   TestResourceReadyUrl(0, 1, 1, TEST_BROKEN_IMAGE_L, "", TEST_LOCATION);
3850
3851   TestResourceReadyUrl(1, 1, 1, TEST_GIF_FILE_NAME, "", TEST_LOCATION); // first frame image loading sync + second frame image loading async
3852
3853   TestResourceReadyUrl(0, 1, 1, gImage_600_RGB, gImage_34_RGBA, TEST_LOCATION);
3854
3855   TestAuxiliaryResourceReadyUrl(1, 1, TEST_BROKEN_IMAGE_L, gImage_34_RGBA, TEST_LOCATION);
3856
3857   // Test broken case
3858   TestResourceReadyUrl(0, 1, 0, "invalid.jpg", "", TEST_LOCATION);
3859   TestResourceReadyUrl(0, 1, 0, "invalid.svg", "", TEST_LOCATION);
3860   TestResourceReadyUrl(0, 1, 0, "invalid.9.png", "", TEST_LOCATION);
3861   TestResourceReadyUrl(0, 1, 0, "invalid.gif", "", TEST_LOCATION);
3862
3863   TestResourceReadyUrl(0, 1, 0, "invalid.jpg", "invalid.png", TEST_LOCATION);
3864   TestResourceReadyUrl(0, 1, 1, gImage_600_RGB, "invalid.png", TEST_LOCATION);
3865   TestResourceReadyUrl(0, 1, 0, "invalid.jpg", gImage_34_RGBA, TEST_LOCATION);
3866
3867   TestAuxiliaryResourceReadyUrl(1, 0, "invalid.9.png", "invalid.png", TEST_LOCATION);
3868   TestAuxiliaryResourceReadyUrl(1, 1, TEST_BROKEN_IMAGE_L, "invalid.png", TEST_LOCATION);
3869   TestAuxiliaryResourceReadyUrl(1, 0, "invalid.9.png", gImage_34_RGBA, TEST_LOCATION);
3870
3871   END_TEST;
3872 }
3873
3874 int UtcDaliImageViewSetImageOnResourceReadySignal04(void)
3875 {
3876   tet_infoline("Test texturemanager's remove queue works well within signal handler.");
3877
3878   ToolkitTestApplication application;
3879
3880   gResourceReadySignalCounter      = 0;
3881   gResourceReadySignal04ComesOrder = 0;
3882
3883   gImageView1 = ImageView::New("invalid.jpg"); // request invalid image, to make loading failed fast.
3884   gImageView1.ResourceReadySignal().Connect(&OnResourceReadySignal04);
3885   application.GetScene().Add(gImageView1);
3886
3887   gImageView2 = ImageView::New("invalid.png"); // request invalid image, to make loading failed fast.
3888   gImageView2.ResourceReadySignal().Connect(&OnResourceReadySignal04);
3889   application.GetScene().Add(gImageView2);
3890
3891   application.SendNotification();
3892   application.Render();
3893
3894   tet_infoline("Try to load 2 invalid image");
3895
3896   DALI_TEST_EQUALS(Test::WaitForEventThreadTrigger(2), true, TEST_LOCATION);
3897   DALI_TEST_EQUALS(gResourceReadySignalCounter, 2, TEST_LOCATION);
3898
3899   tet_infoline("load done");
3900
3901   // We can test this UTC only if gImageView1 and gImageView2 loaded done.
3902   if(gResourceReadySignal04ComesOrder == -1)
3903   {
3904     tet_infoline("Bad news.. gImageView3 or gImageView4 loaded faster than others. just skip this UTC");
3905   }
3906   else
3907   {
3908     // gImageView3 and gImageView4 load must not be successed yet.
3909     DALI_TEST_EQUALS(gImageView3.GetRendererCount(), 0u, TEST_LOCATION);
3910     DALI_TEST_EQUALS(gImageView4.GetRendererCount(), 0u, TEST_LOCATION);
3911
3912     application.SendNotification();
3913     application.Render();
3914
3915     tet_infoline("Try to load 2 valid image");
3916
3917     DALI_TEST_EQUALS(Test::WaitForEventThreadTrigger(2), true, TEST_LOCATION);
3918     DALI_TEST_EQUALS(gResourceReadySignalCounter, 4, TEST_LOCATION);
3919
3920     tet_infoline("load done");
3921
3922     // gImageView3 and gImageView4 load must be successed now.
3923     DALI_TEST_EQUALS(gImageView3.GetRendererAt(0).GetTextures().GetTextureCount(), 1u, TEST_LOCATION);
3924     DALI_TEST_EQUALS(gImageView4.GetRendererAt(0).GetTextures().GetTextureCount(), 1u, TEST_LOCATION);
3925   }
3926
3927   END_TEST;
3928 }
3929 int UtcDaliImageViewSetImageOnResourceReadySignal05(void)
3930 {
3931   tet_infoline("Test multiple views with same image during ResourceReady load the image only 1 times");
3932
3933   ToolkitTestApplication application;
3934
3935   gResourceReadySignalCounter = 0;
3936
3937   gImageView1 = ImageView::New("invalid.jpg"); // request invalid image, to make loading failed fast.
3938   gImageView1.ResourceReadySignal().Connect(&OnResourceReadySignal05);
3939   application.GetScene().Add(gImageView1);
3940
3941   application.SendNotification();
3942   application.Render();
3943
3944   tet_infoline("Try to load 1 invalid.jpg image");
3945   DALI_TEST_EQUALS(Test::WaitForEventThreadTrigger(1), true, TEST_LOCATION);
3946   DALI_TEST_EQUALS(gResourceReadySignalCounter, 1, TEST_LOCATION);
3947
3948   tet_infoline("Try to load 1 invalid2.jpg image");
3949   DALI_TEST_EQUALS(Test::WaitForEventThreadTrigger(1), true, TEST_LOCATION);
3950
3951   tet_infoline("Now we don't have any image to be loaded. Check event thread trigger failed.");
3952   DALI_TEST_EQUALS(Test::WaitForEventThreadTrigger(1, 1), false, TEST_LOCATION);
3953
3954   gImageView1.Unparent();
3955   gImageView1.Reset();
3956
3957   END_TEST;
3958 }
3959 int UtcDaliImageViewSetImageOnResourceReadySignal06(void)
3960 {
3961   tet_infoline("Test texturemanager's remove image & mask queue works well within signal handler.");
3962
3963   ToolkitTestApplication application;
3964
3965   gResourceReadySignalCounter      = 0;
3966   gResourceReadySignal06ComesOrder = 0;
3967
3968   Property::Map map;
3969   map[Toolkit::ImageVisual::Property::URL] = "invalid.jpg";
3970   map[Toolkit::ImageVisual::Property::ALPHA_MASK_URL] = "invalid.png";
3971
3972   gImageView1 = ImageView::New(); // request invalid image, to make loading failed fast.
3973   gImageView1.SetProperty(Toolkit::ImageView::Property::IMAGE, map);
3974   gImageView1.ResourceReadySignal().Connect(&OnResourceReadySignal06);
3975   application.GetScene().Add(gImageView1);
3976
3977   gImageView2 = ImageView::New(); // request invalid image, to make loading failed fast.
3978   gImageView2.SetProperty(Toolkit::ImageView::Property::IMAGE, map);
3979   gImageView2.ResourceReadySignal().Connect(&OnResourceReadySignal06);
3980   application.GetScene().Add(gImageView2);
3981
3982   application.SendNotification();
3983   application.Render();
3984
3985   tet_infoline("Try to load 2 invalid image");
3986
3987   DALI_TEST_EQUALS(Test::WaitForEventThreadTrigger(2), true, TEST_LOCATION);
3988   DALI_TEST_EQUALS(gResourceReadySignalCounter, 2, TEST_LOCATION);
3989
3990   tet_infoline("load done");
3991
3992   // We can test this UTC only if gImageView1 and gImageView2 loaded done.
3993   if(gResourceReadySignal06ComesOrder == -1)
3994   {
3995     tet_infoline("Bad news.. gImageView3 or gImageView4 loaded faster than others. just skip this UTC");
3996   }
3997   else
3998   {
3999     // gImageView3 and gImageView4 load must not be successed yet.
4000     DALI_TEST_EQUALS(gImageView3.GetRendererCount(), 0u, TEST_LOCATION);
4001     DALI_TEST_EQUALS(gImageView4.GetRendererCount(), 0u, TEST_LOCATION);
4002
4003     application.GetScene().Add(gImageView3);
4004     application.GetScene().Add(gImageView4);
4005     application.SendNotification();
4006     application.Render();
4007
4008     tet_infoline("Try to load 2 valid image");
4009
4010     DALI_TEST_EQUALS(Test::WaitForEventThreadTrigger(2), true, TEST_LOCATION);
4011     DALI_TEST_EQUALS(gResourceReadySignalCounter, 2, TEST_LOCATION);
4012
4013     tet_infoline("load done");
4014   }
4015   END_TEST;
4016 }
4017
4018 int UtcDaliImageViewUseSameUrlWithAnimatedImageVisual(void)
4019 {
4020   tet_infoline("Test multiple views with same image in animated image visual");
4021   ToolkitTestApplication application;
4022
4023   gImageView1 = ImageView::New(TEST_WEBP_FILE_NAME);
4024   application.GetScene().Add(gImageView1);
4025
4026   tet_infoline("Remove imageView and Create new imageView with same url");
4027   application.GetScene().Remove(gImageView1);
4028   gImageView2 = ImageView::New(TEST_WEBP_FILE_NAME);
4029   application.GetScene().Add(gImageView2);
4030
4031   application.SendNotification();
4032   application.Render();
4033
4034   tet_infoline("Check the ImageView load image successfully");
4035   DALI_TEST_EQUALS(Test::WaitForEventThreadTrigger(1), true, TEST_LOCATION);
4036   END_TEST;
4037 }