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