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