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