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