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