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