[5.0] Fix ImageView issue
[platform/core/uifw/dali-toolkit.git] / automated-tests / src / dali-toolkit / utc-Dali-ImageView.cpp
1 /*
2  * Copyright (c) 2018 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/visual-properties-devel.h>
30
31 #include <test-native-image.h>
32 #include <sstream>
33 #include <unistd.h>
34
35
36 #include "dummy-control.h"
37
38 using namespace Dali;
39 using namespace Toolkit;
40
41 void utc_dali_toolkit_image_view_startup(void)
42 {
43   test_return_value = TET_UNDEF;
44 }
45
46 void utc_dali_toolkit_image_view_cleanup(void)
47 {
48   test_return_value = TET_PASS;
49 }
50
51 namespace
52 {
53
54 const char* VERTEX_SHADER = DALI_COMPOSE_SHADER(
55   attribute mediump vec2 aPosition;\n
56   varying mediump vec2 vTexCoord;\n
57   uniform mediump mat4 uMvpMatrix;\n
58   uniform mediump vec3 uSize;\n
59   \n
60   void main()\n
61   {\n
62     mediump vec4 vertexPosition = vec4(aPosition, 0.0, 1.0);\n
63     vertexPosition.xyz *= uSize;\n
64     vertexPosition = uMvpMatrix * vertexPosition;\n
65     \n
66     vTexCoord = aPosition + vec2(0.5);\n
67     gl_Position = vertexPosition;\n
68   }\n
69 );
70
71 const char* FRAGMENT_SHADER = DALI_COMPOSE_SHADER(
72   varying mediump vec2 vTexCoord;\n
73   uniform sampler2D sTexture;\n
74   uniform lowp vec4 uColor;\n
75   \n
76   void main()\n
77   {\n
78     gl_FragColor = texture2D( sTexture, vTexCoord ) * uColor;\n
79   }\n
80 );
81
82 const char* TEST_IMAGE_FILE_NAME =  "gallery_image_01.jpg";
83 const char* TEST_IMAGE_FILE_NAME2 =  "gallery_image_02.jpg";
84
85 const char* TEST_IMAGE_1 = TEST_RESOURCE_DIR "/TB-gloss.png";
86 const char* TEST_IMAGE_2 = TEST_RESOURCE_DIR "/tb-norm.png";
87
88 // resolution: 34*34, pixel format: RGBA8888
89 static const char* gImage_34_RGBA = TEST_RESOURCE_DIR "/icon-edit.png";
90 // resolution: 600*600, pixel format: RGB888
91 static const char* gImage_600_RGB = TEST_RESOURCE_DIR "/test-image-600.jpg";
92
93 // resolution: 50*50, frame count: 4, frame delay: 0.2 second for each frame
94 const char* TEST_GIF_FILE_NAME = TEST_RESOURCE_DIR "/anim.gif";
95
96 void TestImage( ImageView imageView, BufferImage image )
97 {
98   Property::Value value = imageView.GetProperty( imageView.GetPropertyIndex( "image" ) );
99
100   Property::Map map;
101   DALI_TEST_CHECK( value.Get( map ) );
102
103   DALI_TEST_CHECK( map.Find( "width" ) );
104   DALI_TEST_CHECK( map.Find( "height" ) );
105   DALI_TEST_CHECK( map.Find( "type" ) );
106
107   int width = 0;
108   DALI_TEST_CHECK( map[ "width" ].Get( width ) );
109   DALI_TEST_EQUALS( (unsigned int)width, image.GetWidth(), TEST_LOCATION );
110
111   int height = 0;
112   DALI_TEST_CHECK( map[ "height" ].Get( height ) );
113   DALI_TEST_EQUALS( (unsigned int)height, image.GetHeight(), TEST_LOCATION );
114
115   std::string type;
116   DALI_TEST_CHECK( map[ "type" ].Get( type ) );
117   DALI_TEST_EQUALS( type, "BufferImage", TEST_LOCATION );
118 }
119
120 void TestImage( ImageView imageView, ResourceImage image )
121 {
122   Property::Value value = imageView.GetProperty( imageView.GetPropertyIndex( "image" ) );
123
124   Property::Map map;
125   DALI_TEST_CHECK( value.Get( map ) );
126
127   if( map.Find( "width" ) )
128   {
129     int width = 0;
130     DALI_TEST_CHECK( map[ "width" ].Get( width ) );
131     DALI_TEST_EQUALS( (unsigned int)width, image.GetWidth(), TEST_LOCATION );
132   }
133
134   if( map.Find( "height" ) )
135   {
136     int height = 0;
137     DALI_TEST_CHECK( map[ "height" ].Get( height ) );
138     DALI_TEST_EQUALS( (unsigned int)height, image.GetHeight(), TEST_LOCATION );
139   }
140
141   DALI_TEST_CHECK( map.Find( "type" ) );
142
143   std::string type;
144   DALI_TEST_CHECK( map[ "type" ].Get( type ) );
145   DALI_TEST_EQUALS( type, "ResourceImage", TEST_LOCATION );
146
147   std::string filename;
148   DALI_TEST_CHECK( map[ "filename" ].Get( filename ) );
149   DALI_TEST_EQUALS( filename, image.GetUrl(), TEST_LOCATION );
150 }
151
152 void TestUrl( ImageView imageView, const std::string url )
153 {
154   Property::Value value = imageView.GetProperty( imageView.GetPropertyIndex( "image" ) );
155
156   std::string urlActual;
157   DALI_TEST_CHECK( value.Get( urlActual ) );
158   DALI_TEST_EQUALS( urlActual, url, TEST_LOCATION );
159 }
160
161 } // namespace
162
163 int UtcDaliImageViewNewP(void)
164 {
165   TestApplication application;
166
167   ImageView imageView = ImageView::New();
168
169   DALI_TEST_CHECK( imageView );
170
171   END_TEST;
172 }
173
174 int UtcDaliImageViewNewImageP(void)
175 {
176   TestApplication application;
177
178   BufferImage image = CreateBufferImage( 100, 200, Vector4( 1.f, 1.f, 1.f, 1.f ) );
179   ImageView imageView = ImageView::New( image );
180
181   DALI_TEST_CHECK( imageView );
182   TestImage( imageView, image );
183
184   END_TEST;
185 }
186
187 int UtcDaliImageViewNewUrlP(void)
188 {
189   TestApplication application;
190
191   ImageView imageView = ImageView::New( TEST_IMAGE_FILE_NAME );
192   DALI_TEST_CHECK( imageView );
193
194   TestUrl( imageView, TEST_IMAGE_FILE_NAME );
195
196   END_TEST;
197 }
198
199 int UtcDaliImageViewConstructorP(void)
200 {
201   TestApplication application;
202
203   ImageView imageView;
204
205   DALI_TEST_CHECK( !imageView );
206
207   END_TEST;
208 }
209
210 int UtcDaliImageViewCopyConstructorP(void)
211 {
212   TestApplication application;
213
214   // Initialize an object, ref count == 1
215   ImageView imageView = ImageView::New();
216
217   ImageView copy( imageView );
218   DALI_TEST_CHECK( copy );
219
220   END_TEST;
221 }
222
223 int UtcDaliImageViewAssignmentOperatorP(void)
224 {
225   TestApplication application;
226
227   ImageView imageView = ImageView::New();
228
229   ImageView copy( imageView );
230   DALI_TEST_CHECK( copy );
231   DALI_TEST_EQUALS( imageView, copy, TEST_LOCATION );
232
233   END_TEST;
234 }
235
236 int UtcDaliImageViewDownCastP(void)
237 {
238   TestApplication application;
239
240   ImageView imageView = ImageView::New();
241
242   BaseHandle object(imageView);
243
244   ImageView imageView2 = ImageView::DownCast( object );
245   DALI_TEST_CHECK(imageView2);
246
247   ImageView imageView3 = DownCast< ImageView >( object );
248   DALI_TEST_CHECK(imageView3);
249
250   END_TEST;
251 }
252
253 int UtcDaliImageViewDownCastN(void)
254 {
255   TestApplication application;
256
257   BaseHandle unInitializedObject;
258
259   ImageView imageView1 = ImageView::DownCast( unInitializedObject );
260   DALI_TEST_CHECK( !imageView1 );
261
262   ImageView imageView2 = DownCast< ImageView >( unInitializedObject );
263   DALI_TEST_CHECK( !imageView2 );
264
265   END_TEST;
266 }
267
268 int UtcDaliImageViewTypeRegistry(void)
269 {
270   ToolkitTestApplication application;
271
272   TypeRegistry typeRegistry = TypeRegistry::Get();
273   DALI_TEST_CHECK( typeRegistry );
274
275   TypeInfo typeInfo = typeRegistry.GetTypeInfo( "ImageView" );
276   DALI_TEST_CHECK( typeInfo );
277
278   BaseHandle handle = typeInfo.CreateInstance();
279   DALI_TEST_CHECK( handle );
280
281   ImageView imageView = ImageView::DownCast( handle );
282   DALI_TEST_CHECK( imageView );
283
284   END_TEST;
285 }
286
287 int UtcDaliImageViewSetGetProperty01(void)
288 {
289   ToolkitTestApplication application;
290
291   ImageView imageView = ImageView::New();
292
293   Property::Index idx = imageView.GetPropertyIndex( "image" );
294   DALI_TEST_EQUALS( idx, (Property::Index)ImageView::Property::IMAGE, TEST_LOCATION );
295
296   imageView.SetProperty( idx, TEST_IMAGE_FILE_NAME );
297   TestUrl( imageView, TEST_IMAGE_FILE_NAME );
298
299   END_TEST;
300 }
301
302 int UtcDaliImageViewSetGetProperty02(void)
303 {
304   ToolkitTestApplication application;
305
306   Image image = CreateBufferImage( 10, 10, Color::WHITE );
307   ImageView imageView = ImageView::New(image);
308   Vector4 fullImageRect( 0.f, 0.f, 1.f, 1.f );
309
310   Stage::GetCurrent().Add( imageView );
311
312   application.SendNotification();
313   application.Render();
314   TestGlAbstraction& gl = application.GetGlAbstraction();
315
316   Vector4 pixelAreaUniform;
317   DALI_TEST_CHECK( gl.GetUniformValue<Vector4>( "pixelArea", pixelAreaUniform ) );
318   DALI_TEST_EQUALS( pixelAreaUniform, fullImageRect, TEST_LOCATION );
319
320   Property::Value value = imageView.GetProperty( ImageView::Property::PIXEL_AREA );
321   Vector4 pixelAreaValue;
322   DALI_TEST_CHECK( value.Get(pixelAreaValue) );
323   DALI_TEST_EQUALS( pixelAreaValue, fullImageRect, TEST_LOCATION );
324
325   Vector4 pixelAreaSet( 0.2f, 0.2f, 0.3f, 0.3f );
326   imageView.SetProperty( ImageView::Property::PIXEL_AREA, pixelAreaSet);
327
328   application.SendNotification();
329   application.Render();
330
331   value = imageView.GetProperty( ImageView::Property::PIXEL_AREA );
332   value.Get(pixelAreaValue);
333   DALI_TEST_EQUALS( pixelAreaValue, pixelAreaSet, TEST_LOCATION );
334
335   DALI_TEST_CHECK( gl.GetUniformValue<Vector4>( "pixelArea", pixelAreaUniform ) );
336   DALI_TEST_EQUALS( pixelAreaUniform, pixelAreaSet, TEST_LOCATION );
337
338   END_TEST;
339 }
340
341 int UtcDaliImageViewSetGetProperty03(void)
342 {
343   ToolkitTestApplication application;
344
345   Image image = CreateBufferImage( 10, 10, Color::WHITE );
346   ImageView imageView = ImageView::New(image);
347   Stage::GetCurrent().Add( imageView );
348   application.SendNotification();
349   application.Render();
350
351   // conventional alpha blending
352   Renderer renderer = imageView.GetRendererAt( 0 );
353   Property::Value value = renderer.GetProperty( Renderer::Property::BLEND_PRE_MULTIPLIED_ALPHA );
354   bool enable;
355   DALI_TEST_CHECK( value.Get( enable ) );
356   DALI_TEST_CHECK( enable );
357
358   // pre-multiplied alpha blending
359   imageView.SetProperty( Toolkit::ImageView::Property::PRE_MULTIPLIED_ALPHA, true );
360   application.SendNotification();
361   application.Render();
362
363   int srcFactorRgb    = renderer.GetProperty<int>( Renderer::Property::BLEND_FACTOR_SRC_RGB );
364   int destFactorRgb   = renderer.GetProperty<int>( Renderer::Property::BLEND_FACTOR_DEST_RGB );
365   int srcFactorAlpha  = renderer.GetProperty<int>( Renderer::Property::BLEND_FACTOR_SRC_ALPHA );
366   int destFactorAlpha = renderer.GetProperty<int>( Renderer::Property::BLEND_FACTOR_DEST_ALPHA );
367   DALI_TEST_CHECK( srcFactorRgb == BlendFactor::ONE );
368   DALI_TEST_CHECK( destFactorRgb == BlendFactor::ONE_MINUS_SRC_ALPHA );
369   DALI_TEST_CHECK( srcFactorAlpha == BlendFactor::ONE );
370   DALI_TEST_CHECK( destFactorAlpha == BlendFactor::ONE_MINUS_SRC_ALPHA );
371
372   value = renderer.GetProperty( Renderer::Property::BLEND_PRE_MULTIPLIED_ALPHA );
373   DALI_TEST_CHECK( value.Get( enable ) );
374   DALI_TEST_CHECK( enable );
375
376   END_TEST;
377 }
378
379 int UtcDaliImageViewPreMultipliedAlpha(void)
380 {
381   ToolkitTestApplication application;
382
383   ImageView imageView = ImageView::New( gImage_34_RGBA );
384
385   // Disable pre-multiplied alpha blending
386   imageView.SetProperty( Toolkit::ImageView::Property::PRE_MULTIPLIED_ALPHA, false );
387
388   Stage::GetCurrent().Add( imageView );
389
390   application.SendNotification();
391   application.Render();
392
393   // loading started, this waits for the loader thread for max 30 seconds
394   DALI_TEST_EQUALS( Test::WaitForEventThreadTrigger( 1 ), true, TEST_LOCATION );
395
396   // conventional alpha blending
397   Renderer renderer = imageView.GetRendererAt( 0 );
398   Property::Value value = renderer.GetProperty( Renderer::Property::BLEND_PRE_MULTIPLIED_ALPHA );
399   bool enable;
400   DALI_TEST_CHECK( value.Get( enable ) );
401   DALI_TEST_CHECK( !enable );
402
403   int srcFactorRgb    = renderer.GetProperty<int>( Renderer::Property::BLEND_FACTOR_SRC_RGB );
404   int destFactorRgb   = renderer.GetProperty<int>( Renderer::Property::BLEND_FACTOR_DEST_RGB );
405   int srcFactorAlpha  = renderer.GetProperty<int>( Renderer::Property::BLEND_FACTOR_SRC_ALPHA );
406   int destFactorAlpha = renderer.GetProperty<int>( Renderer::Property::BLEND_FACTOR_DEST_ALPHA );
407   DALI_TEST_CHECK( srcFactorRgb == BlendFactor::SRC_ALPHA );
408   DALI_TEST_CHECK( destFactorRgb == BlendFactor::ONE_MINUS_SRC_ALPHA );
409   DALI_TEST_CHECK( srcFactorAlpha == BlendFactor::ONE );
410   DALI_TEST_CHECK( destFactorAlpha == BlendFactor::ONE_MINUS_SRC_ALPHA );
411
412   value = renderer.GetProperty( Renderer::Property::BLEND_PRE_MULTIPLIED_ALPHA );
413   DALI_TEST_CHECK( value.Get( enable ) );
414   DALI_TEST_CHECK( !enable );
415
416   // Enable pre-multiplied alpha blending
417   imageView.SetProperty( Toolkit::ImageView::Property::PRE_MULTIPLIED_ALPHA, true );
418   application.SendNotification();
419   application.Render();
420
421   srcFactorRgb    = renderer.GetProperty<int>( Renderer::Property::BLEND_FACTOR_SRC_RGB );
422   destFactorRgb   = renderer.GetProperty<int>( Renderer::Property::BLEND_FACTOR_DEST_RGB );
423   srcFactorAlpha  = renderer.GetProperty<int>( Renderer::Property::BLEND_FACTOR_SRC_ALPHA );
424   destFactorAlpha = renderer.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   value = renderer.GetProperty( Renderer::Property::BLEND_PRE_MULTIPLIED_ALPHA );
431   DALI_TEST_CHECK( value.Get( enable ) );
432   DALI_TEST_CHECK( enable );
433
434   END_TEST;
435 }
436
437 int UtcDaliImageViewPixelArea(void)
438 {
439   // Test pixel area property
440   ToolkitTestApplication application;
441
442   // Gif image, use AnimatedImageVisual internally
443   // Atlasing is applied to pack multiple frames, use custom wrap mode
444   ImageView gifView = ImageView::New();
445   const Vector4 pixelAreaVisual( 0.f, 0.f, 2.f, 2.f );
446   gifView.SetProperty( ImageView::Property::IMAGE,
447                        Property::Map().Add( ImageVisual::Property::URL, TEST_GIF_FILE_NAME )
448                                       .Add( ImageVisual::Property::PIXEL_AREA, pixelAreaVisual ) );
449
450   // Add to stage
451   Stage stage = Stage::GetCurrent();
452   stage.Add( gifView );
453
454   // loading started
455   application.SendNotification();
456   application.Render(16);
457   DALI_TEST_CHECK( gifView.GetRendererCount() == 1u );
458
459   const Vector4 fullTextureRect( 0.f, 0.f, 1.f, 1.f );
460   // test that the pixel area value defined in the visual property map is registered on renderer
461   Renderer renderer = gifView.GetRendererAt(0);
462   Property::Value pixelAreaValue = renderer.GetProperty( renderer.GetPropertyIndex( "pixelArea" ) );
463   DALI_TEST_EQUALS( pixelAreaValue.Get<Vector4>(), pixelAreaVisual, TEST_LOCATION );
464
465   // test that the shader has the default pixel area value registered.
466   Shader shader = renderer.GetShader();
467   pixelAreaValue = shader.GetProperty( shader.GetPropertyIndex( "pixelArea" ) );
468   DALI_TEST_EQUALS( pixelAreaValue.Get<Vector4>(), fullTextureRect, TEST_LOCATION );
469
470   // test that the uniform uses the pixelArea property on the renderer.
471   TestGlAbstraction& gl = application.GetGlAbstraction();
472   Vector4 pixelAreaUniform;
473   DALI_TEST_CHECK( gl.GetUniformValue<Vector4>( "pixelArea", pixelAreaUniform ) );
474   DALI_TEST_EQUALS( pixelAreaVisual, pixelAreaUniform, Math::MACHINE_EPSILON_100, TEST_LOCATION );
475
476   // set the pixelArea property on the control
477   const Vector4 pixelAreaControl( -1.f, -1.f, 3.f, 3.f );
478   gifView.SetProperty( ImageView::Property::PIXEL_AREA, pixelAreaControl );
479   application.SendNotification();
480   application.Render(16);
481
482   // check the pixelArea property on the control
483   pixelAreaValue = gifView.GetProperty( gifView.GetPropertyIndex( "pixelArea" ) );
484   DALI_TEST_EQUALS( pixelAreaValue.Get<Vector4>(), pixelAreaControl, TEST_LOCATION );
485   // test that the uniform uses the pixelArea property on the control.
486   DALI_TEST_CHECK( gl.GetUniformValue<Vector4>( "pixelArea", pixelAreaUniform ) );
487   DALI_TEST_EQUALS( pixelAreaControl, pixelAreaUniform, Math::MACHINE_EPSILON_100, TEST_LOCATION );
488
489
490   END_TEST;
491 }
492
493 int UtcDaliImageViewAsyncLoadingWithoutAltasing(void)
494 {
495   ToolkitTestApplication application;
496   TestGlAbstraction& gl = application.GetGlAbstraction();
497   const std::vector<GLuint>& textures = gl.GetBoundTextures();
498   size_t numTextures = textures.size();
499
500   // Async loading, no atlasing for big size image
501   ImageView imageView = ImageView::New( gImage_600_RGB );
502
503   // By default, Aysnc loading is used
504   Stage::GetCurrent().Add( imageView );
505   imageView.SetSize(100, 100);
506   imageView.SetParentOrigin( ParentOrigin::CENTER );
507
508   DALI_TEST_EQUALS( Test::WaitForEventThreadTrigger( 1 ), true, TEST_LOCATION );
509
510   application.SendNotification();
511   application.Render(16);
512   application.SendNotification();
513
514   const std::vector<GLuint>& textures2 = gl.GetBoundTextures();
515   DALI_TEST_GREATER( textures2.size(), numTextures, TEST_LOCATION );
516
517
518
519   END_TEST;
520 }
521
522 int UtcDaliImageViewAsyncLoadingWithAtlasing(void)
523 {
524   ToolkitTestApplication application;
525
526   //Async loading, automatic atlasing for small size image
527   TraceCallStack& callStack = application.GetGlAbstraction().GetTextureTrace();
528   callStack.Reset();
529   callStack.Enable(true);
530
531   Property::Map imageMap;
532
533   imageMap[ ImageVisual::Property::URL ] = gImage_34_RGBA;
534   imageMap[ ImageVisual::Property::DESIRED_HEIGHT ] = 34;
535   imageMap[ ImageVisual::Property::DESIRED_WIDTH ] = 34;
536   imageMap[ ImageVisual::Property::ATLASING] = true;
537
538   ImageView imageView = ImageView::New();
539   imageView.SetProperty( ImageView::Property::IMAGE, imageMap );
540   imageView.SetProperty( Toolkit::Control::Property::PADDING, Extents( 10u, 10u, 10u, 10u ) );
541
542   // By default, Aysnc loading is used
543   // loading is not started if the actor is offStage
544
545   Stage::GetCurrent().Add( imageView );
546   application.SendNotification();
547   application.Render(16);
548   application.Render(16);
549   application.SendNotification();
550
551   imageView.SetProperty( Dali::Actor::Property::LAYOUT_DIRECTION,  Dali::LayoutDirection::RIGHT_TO_LEFT );
552   application.SendNotification();
553   application.Render(16);
554   application.Render(16);
555   application.SendNotification();
556
557   // loading started, this waits for the loader thread for max 30 seconds
558   DALI_TEST_EQUALS( Test::WaitForEventThreadTrigger( 1 ), true, TEST_LOCATION );
559
560   application.SendNotification();
561   application.Render(16);
562
563   callStack.Enable(false);
564
565   TraceCallStack::NamedParams params;
566   params["width"] = ToString(34);
567   params["height"] = ToString(34);
568   DALI_TEST_EQUALS( callStack.FindMethodAndParams( "TexSubImage2D", params ), true, TEST_LOCATION );
569
570   END_TEST;
571 }
572
573 int UtcDaliImageViewAsyncLoadingWithAtlasing02(void)
574 {
575   ToolkitTestApplication application;
576
577   //Async loading, automatic atlasing for small size image
578   TraceCallStack& callStack = application.GetGlAbstraction().GetTextureTrace();
579   callStack.Reset();
580   callStack.Enable(true);
581
582   Property::Map asyncLoadingMap;
583   asyncLoadingMap[ "url" ] = gImage_34_RGBA;
584   asyncLoadingMap[ "desiredHeight" ] = 34;
585   asyncLoadingMap[ "desiredWidth" ] = 34;
586   asyncLoadingMap[ "synchronousLoading" ] = false;
587   asyncLoadingMap[ "atlasing" ] = true;
588
589   ImageView imageView = ImageView::New();
590   imageView.SetProperty( ImageView::Property::IMAGE, asyncLoadingMap );
591
592   Stage::GetCurrent().Add( imageView );
593   application.SendNotification();
594   application.Render(16);
595   application.Render(16);
596   application.SendNotification();
597
598   // loading started, this waits for the loader thread for max 30 seconds
599   DALI_TEST_EQUALS( Test::WaitForEventThreadTrigger( 1 ), true, TEST_LOCATION );
600
601   application.SendNotification();
602   application.Render(16);
603
604   callStack.Enable(false);
605
606   TraceCallStack::NamedParams params;
607   params["width"] = ToString(34);
608   params["height"] = ToString(34);
609   DALI_TEST_EQUALS( callStack.FindMethodAndParams( "TexSubImage2D", params ), true, TEST_LOCATION );
610
611   END_TEST;
612 }
613
614 int UtcDaliImageViewSyncLoading(void)
615 {
616   ToolkitTestApplication application;
617
618   tet_infoline("ImageView Testing sync loading and size using index key property map");
619
620   Property::Map syncLoadingMap;
621   syncLoadingMap[ ImageVisual::Property::SYNCHRONOUS_LOADING ] = true;
622   syncLoadingMap[ ImageVisual::Property::ATLASING ] = true;
623
624   // Sync loading, no atlasing for big size image
625   {
626     ImageView imageView = ImageView::New();
627
628     // Sync loading is used
629     syncLoadingMap[ ImageVisual::Property::URL ] = gImage_600_RGB;
630     imageView.SetProperty( ImageView::Property::IMAGE, syncLoadingMap );
631   }
632
633   // Sync loading, automatic atlasing for small size image
634   {
635     TraceCallStack& callStack = application.GetGlAbstraction().GetTextureTrace();
636     callStack.Reset();
637     callStack.Enable(true);
638
639     ImageView imageView = ImageView::New( );
640
641     // Sync loading is used
642     syncLoadingMap[ ImageVisual::Property::URL ] = gImage_34_RGBA;
643     syncLoadingMap[ ImageVisual::Property::DESIRED_HEIGHT ] = 34;
644     syncLoadingMap[ ImageVisual::Property::DESIRED_WIDTH ] = 34;
645     imageView.SetProperty( ImageView::Property::IMAGE, syncLoadingMap );
646
647     Stage::GetCurrent().Add( imageView );
648     application.SendNotification();
649     application.Render(16);
650
651     TraceCallStack::NamedParams params;
652     params["width"] = ToString(34);
653     params["height"] = ToString(34);
654     DALI_TEST_EQUALS( callStack.FindMethodAndParams( "TexSubImage2D", params ),
655                       true, TEST_LOCATION );
656   }
657   END_TEST;
658 }
659
660 int UtcDaliImageViewSyncLoading02(void)
661 {
662   ToolkitTestApplication application;
663
664   tet_infoline("ImageView Testing sync loading and size using string key property map");
665
666   // Sync loading, automatic atlasing for small size image
667   {
668     TraceCallStack& callStack = application.GetGlAbstraction().GetTextureTrace();
669     callStack.Reset();
670     callStack.Enable(true);
671
672     ImageView imageView = ImageView::New( );
673
674     // Sync loading is used
675     Property::Map syncLoadingMap;
676     syncLoadingMap[ "url" ] = gImage_34_RGBA;
677     syncLoadingMap[ "desiredHeight" ] = 34;
678     syncLoadingMap[ "desiredWidth" ] = 34;
679     syncLoadingMap[ "synchronousLoading" ] = true;
680     syncLoadingMap[ "atlasing" ] = true;
681     imageView.SetProperty( ImageView::Property::IMAGE, syncLoadingMap );
682
683     Stage::GetCurrent().Add( imageView );
684     application.SendNotification();
685     application.Render(16);
686
687     TraceCallStack::NamedParams params;
688     params["width"] = ToString(34);
689     params["height"] = ToString(34);
690     DALI_TEST_EQUALS( callStack.FindMethodAndParams( "TexSubImage2D", params ),
691                       true, TEST_LOCATION );
692   }
693   END_TEST;
694 }
695
696 int UtcDaliImageViewAddedTexture(void)
697 {
698   ToolkitTestApplication application;
699
700   tet_infoline("ImageView Testing image view with texture provided manager url");
701
702   ImageView imageView = ImageView::New();
703
704   // empty texture is ok, though pointless from app point of view
705   TextureSet  empty;
706   std::string url = TextureManager::AddTexture(empty);
707   DALI_TEST_CHECK(url.size() > 0u);
708
709   Property::Map propertyMap;
710   propertyMap[ImageVisual::Property::URL] = url;
711   imageView.SetProperty(ImageView::Property::IMAGE, propertyMap);
712
713   Stage::GetCurrent().Add( imageView );
714   application.SendNotification();
715   application.Render();
716
717   END_TEST;
718 }
719
720 int UtcDaliImageViewSizeWithBackground(void)
721 {
722   ToolkitTestApplication application;
723
724   int width = 100;
725   int height = 200;
726   Image image = CreateBufferImage( width, height, Vector4(1.f, 1.f, 1.f, 1.f) );
727   ImageView imageView = ImageView::New();
728   imageView.SetBackgroundImage( image );
729
730   Stage::GetCurrent().Add( imageView );
731   application.SendNotification();
732   application.Render();
733
734   DALI_TEST_EQUALS( imageView.GetCurrentSize().width, (float)width, TEST_LOCATION );
735   DALI_TEST_EQUALS( imageView.GetCurrentSize().height, (float)height, TEST_LOCATION );
736
737   END_TEST;
738 }
739
740 int UtcDaliImageViewSizeWithBackgroundAndImage(void)
741 {
742   ToolkitTestApplication application;
743
744   int widthBackground = 100;
745   int heightBackground = 200;
746   int width = 300;
747   int height = 400;
748   Image imageBackground = CreateBufferImage( widthBackground, heightBackground, Vector4(1.f, 1.f, 1.f, 1.f) );
749   Image image = CreateBufferImage( width, height, Vector4(1.f, 1.f, 1.f, 1.f) );
750
751   ImageView imageView = ImageView::New();
752   imageView.SetBackgroundImage( imageBackground );
753   imageView.SetImage( image );
754
755   Stage::GetCurrent().Add( imageView );
756   application.SendNotification();
757   application.Render();
758
759   DALI_TEST_EQUALS( imageView.GetCurrentSize().width, (float)width, TEST_LOCATION );
760   DALI_TEST_EQUALS( imageView.GetCurrentSize().height, (float)height, TEST_LOCATION );
761
762   END_TEST;
763 }
764
765 int UtcDaliImageViewHeightForWidthBackground(void)
766 {
767   ToolkitTestApplication application;
768
769   int widthBackground = 100;
770   int heightBackground = 200;
771   Image imageBackground = CreateBufferImage( widthBackground, heightBackground, Vector4(1.f, 1.f, 1.f, 1.f) );
772
773   ImageView imageView = ImageView::New();
774   imageView.SetBackgroundImage( imageBackground );
775
776   Stage::GetCurrent().Add( imageView );
777   application.SendNotification();
778   application.Render();
779
780   Control control = Control::DownCast( imageView );
781   DALI_TEST_CHECK( control );
782   DALI_TEST_EQUALS( imageView.GetHeightForWidth( 123.f ), control.GetHeightForWidth( 123.f ), TEST_LOCATION );
783   DALI_TEST_EQUALS( imageView.GetWidthForHeight( 321.f ), control.GetWidthForHeight( 321.f ), TEST_LOCATION );
784
785   END_TEST;
786 }
787
788 int UtcDaliImageViewHeightForWidthBackgroundAndImage(void)
789 {
790   ToolkitTestApplication application;
791
792   int widthBackground = 100;
793   int heightBackground = 200;
794   int width = 300;
795   int height = 400;
796   Image imageBackground = CreateBufferImage( widthBackground, heightBackground, Vector4(1.f, 1.f, 1.f, 1.f) );
797   Image image = CreateBufferImage( width, height, Vector4(1.f, 1.f, 1.f, 1.f) );
798
799   ImageView imageView = ImageView::New();
800   imageView.SetBackgroundImage( imageBackground );
801   imageView.SetImage( image );
802
803   Stage::GetCurrent().Add( imageView );
804   application.SendNotification();
805   application.Render();
806
807   DALI_TEST_EQUALS( imageView.GetHeightForWidth( width ), (float)height, TEST_LOCATION );
808   DALI_TEST_EQUALS( imageView.GetWidthForHeight( height ), (float)width, TEST_LOCATION );
809
810   END_TEST;
811 }
812
813 int UtcDaliImageViewSetBufferImage(void)
814 {
815   ToolkitTestApplication application;
816
817   int width1 = 300;
818   int height1 = 400;
819   BufferImage image1 = CreateBufferImage( width1, height1, Vector4( 1.f, 1.f, 1.f, 1.f ) );
820   ImageView imageView = ImageView::New();
821   imageView.SetImage( image1 );
822
823   TestImage( imageView, image1 );
824
825   int width2 = 600;
826   int height2 = 500;
827   BufferImage image2 = CreateBufferImage( width2, height2, Vector4( 1.f, 1.f, 1.f, 1.f ) );
828   imageView.SetImage( image2 );
829
830   TestImage( imageView, image2 );
831
832   END_TEST;
833 }
834
835 int UtcDaliImageViewSetImageUrl(void)
836 {
837   ToolkitTestApplication application;
838
839   ImageView imageView = ImageView::New();
840   imageView.SetImage( TEST_IMAGE_FILE_NAME );
841   TestUrl( imageView, TEST_IMAGE_FILE_NAME );
842
843
844   imageView.SetImage( TEST_IMAGE_FILE_NAME2 );
845   TestUrl( imageView, TEST_IMAGE_FILE_NAME2 );
846
847   END_TEST;
848 }
849
850 int UtcDaliImageViewSetImageOnstageP(void)
851 {
852   ToolkitTestApplication application;
853
854   ImageView imageView = ImageView::New();
855
856   Stage::GetCurrent().Add( imageView );
857   application.SendNotification();
858   application.Render();
859
860   ResourceImage image1 = ResourceImage::New( TEST_IMAGE_FILE_NAME );
861   imageView.SetImage( image1 );
862   TestImage( imageView, image1 );
863
864   int width = 300;
865   int height = 400;
866   BufferImage image2 = CreateBufferImage( width, height, Vector4( 1.f, 1.f, 1.f, 1.f ) );
867   imageView.SetImage( image2 );
868   TestImage( imageView, image2 );
869
870   END_TEST;
871 }
872
873 int UtcDaliImageViewSetImageOnstageN(void)
874 {
875   ToolkitTestApplication application;
876
877   ImageView imageView = ImageView::New();
878
879   Stage::GetCurrent().Add( imageView );
880   application.SendNotification();
881   application.Render();
882
883   ResourceImage image1 = ResourceImage::New( TEST_IMAGE_FILE_NAME );
884   imageView.SetImage( image1 );
885   TestImage( imageView, image1 );
886
887   Image image2;
888   imageView.SetImage( image2 );
889
890   Property::Value value = imageView.GetProperty( imageView.GetPropertyIndex( "image" ) );
891
892   //the value should be empty
893   std::string url;
894   DALI_TEST_CHECK( !value.Get( url ) );
895
896   Property::Map map;
897   DALI_TEST_CHECK( !value.Get( map ) );
898
899   END_TEST;
900 }
901
902 int UtcDaliImageViewSetImageOffstageP(void)
903 {
904   ToolkitTestApplication application;
905
906   ImageView imageView = ImageView::New();
907
908   Stage::GetCurrent().Add( imageView );
909   application.SendNotification();
910   application.Render();
911   Stage::GetCurrent().Remove( imageView );
912
913   ResourceImage image1 = ResourceImage::New( TEST_IMAGE_FILE_NAME );
914   imageView.SetImage( image1 );
915   TestImage( imageView, image1 );
916
917   int width = 300;
918   int height = 400;
919   BufferImage image2 = CreateBufferImage( width, height, Vector4( 1.f, 1.f, 1.f, 1.f ) );
920   imageView.SetImage( image2 );
921   TestImage( imageView, image2 );
922
923   END_TEST;
924 }
925
926 bool gResourceReadySignalFired = false;
927 Vector3 gNaturalSize;
928
929 void ResourceReadySignal( Control control )
930 {
931   gResourceReadySignalFired = true;
932 }
933
934 int UtcDaliImageViewCheckResourceReady(void)
935 {
936   ToolkitTestApplication application;
937
938   gResourceReadySignalFired = false;
939
940
941   int width = 100;
942   int height = 200;
943   Image image = CreateBufferImage( width, height, Vector4(1.f, 1.f, 1.f, 1.f) );
944
945   // Check ImageView with background and main image, to ensure both visuals are marked as loaded
946   ImageView imageView = ImageView::New( TEST_GIF_FILE_NAME );
947
948   imageView.SetBackgroundImage( image );
949
950   DALI_TEST_EQUALS( imageView.IsResourceReady(), false, TEST_LOCATION );
951
952   imageView.ResourceReadySignal().Connect( &ResourceReadySignal);
953
954   Stage::GetCurrent().Add( imageView );
955
956   application.SendNotification();
957   application.Render(16);
958
959
960   DALI_TEST_EQUALS( imageView.IsResourceReady(), true, TEST_LOCATION );
961
962   DALI_TEST_EQUALS( gResourceReadySignalFired, true, TEST_LOCATION );
963
964   END_TEST;
965 }
966
967 int UtcDaliImageViewSetImageOffstageN(void)
968 {
969   ToolkitTestApplication application;
970
971   ImageView imageView = ImageView::New();
972
973   Stage::GetCurrent().Add( imageView );
974   application.SendNotification();
975   application.Render();
976   Stage::GetCurrent().Remove( imageView );
977
978   ResourceImage image1 = ResourceImage::New( TEST_IMAGE_FILE_NAME );
979   imageView.SetImage( image1 );
980   TestImage( imageView, image1 );
981
982   Image image2;
983   imageView.SetImage( image2 );
984
985   Property::Value value = imageView.GetProperty( imageView.GetPropertyIndex( "image" ) );
986
987   //the value should be empty
988   std::string url;
989   DALI_TEST_CHECK( !value.Get( url ) );
990
991   Property::Map map;
992   DALI_TEST_CHECK( !value.Get( map ) );
993
994   END_TEST;
995 }
996
997 int UtcDaliImageViewSetImageN(void)
998 {
999   ToolkitTestApplication application;
1000
1001   Image image1;
1002   ImageView imageView = ImageView::New();
1003   imageView.SetImage( image1 );
1004
1005   Property::Value value = imageView.GetProperty( imageView.GetPropertyIndex( "image" ) );
1006
1007   //the value should be empty
1008   std::string url;
1009   DALI_TEST_CHECK( !value.Get( url ) );
1010
1011   Property::Map map;
1012   DALI_TEST_CHECK( !value.Get( map ) );
1013
1014   std::string resource_url;
1015   Property::Value val = imageView.GetProperty( imageView.GetPropertyIndex( "image" ) );
1016   DALI_TEST_CHECK( !val.Get( resource_url ) );
1017
1018   END_TEST;
1019 }
1020
1021 int UtcDaliImageViewSetImageTypeChangesP(void)
1022 {
1023   ToolkitTestApplication application;
1024
1025   ImageView imageView = ImageView::New();
1026   Toolkit::Internal::Control& controlImpl = Toolkit::Internal::GetImplementation( imageView );
1027
1028   Stage::GetCurrent().Add( imageView );
1029
1030   std::string url;
1031   Property::Map map;
1032   Toolkit::Visual::Base visual;
1033
1034   Property::Value value = imageView.GetProperty( imageView.GetPropertyIndex( "image" ) );
1035   visual = DevelControl::GetVisual( controlImpl, ImageView::Property::IMAGE );
1036
1037   application.SendNotification();
1038   application.Render( 16 );
1039
1040   DALI_TEST_CHECK( ! value.Get( url ) ); // Value should be empty
1041   DALI_TEST_CHECK( ! value.Get( map ) ); // Value should be empty
1042   DALI_TEST_CHECK( ! visual );           // Visual should be invalid
1043
1044   // Set a URL
1045   imageView.SetImage( "TEST_URL" );
1046
1047   application.SendNotification();
1048   application.Render( 16 );
1049
1050   value = imageView.GetProperty( imageView.GetPropertyIndex( "image" ) );
1051   visual = DevelControl::GetVisual( controlImpl, ImageView::Property::IMAGE );
1052
1053   DALI_TEST_CHECK( value.Get( url ) );   // Value should NOT be empty
1054   DALI_TEST_CHECK( ! value.Get( map ) ); // Value should be empty
1055   DALI_TEST_CHECK( visual );             // Visual should be valid
1056
1057   // Set an empty Image
1058   imageView.SetImage( Image() );
1059
1060   application.SendNotification();
1061   application.Render( 16 );
1062
1063   value = imageView.GetProperty( imageView.GetPropertyIndex( "image" ) );
1064   visual = DevelControl::GetVisual( controlImpl, ImageView::Property::IMAGE );
1065
1066   DALI_TEST_CHECK( ! value.Get( url ) ); // Value should be empty
1067   DALI_TEST_CHECK( ! value.Get( map ) ); // Value should be empty
1068   DALI_TEST_CHECK( ! visual );           // Visual should be invalid
1069
1070   // Set an Image
1071   ResourceImage image1 = ResourceImage::New( TEST_IMAGE_FILE_NAME );
1072   imageView.SetImage( image1 );
1073
1074   application.SendNotification();
1075   application.Render( 16 );
1076
1077   value = imageView.GetProperty( imageView.GetPropertyIndex( "image" ) );
1078   visual = DevelControl::GetVisual( controlImpl, ImageView::Property::IMAGE );
1079
1080   DALI_TEST_CHECK( ! value.Get( url ) ); // Value should be empty
1081   DALI_TEST_CHECK( value.Get( map ) );   // Value should NOT be empty
1082   DALI_TEST_CHECK( visual );             // Visual should be valid
1083
1084   // Set an empty URL
1085   imageView.SetImage( "" );
1086
1087   application.SendNotification();
1088   application.Render( 16 );
1089
1090   value = imageView.GetProperty( imageView.GetPropertyIndex( "image" ) );
1091   visual = DevelControl::GetVisual( controlImpl, ImageView::Property::IMAGE );
1092
1093   DALI_TEST_CHECK( ! value.Get( url ) ); // Value should be empty
1094   DALI_TEST_CHECK( ! value.Get( map ) ); // Value should be empty
1095   DALI_TEST_CHECK( ! visual );           // Visual should be invalid
1096
1097   // Set a URL in property map
1098   Property::Map propertyMap;
1099   propertyMap[ImageVisual::Property::URL] = TEST_IMAGE_FILE_NAME;
1100   imageView.SetProperty( ImageView::Property::IMAGE, propertyMap );
1101
1102   application.SendNotification();
1103   application.Render( 16 );
1104
1105   value = imageView.GetProperty( imageView.GetPropertyIndex( "image" ) );
1106   visual = DevelControl::GetVisual( controlImpl, ImageView::Property::IMAGE );
1107
1108   DALI_TEST_CHECK( ! value.Get( url ) ); // Value should be empty
1109   DALI_TEST_CHECK( value.Get( map ) );   // Value should NOT be empty
1110   DALI_TEST_CHECK( visual );             // Visual should be valid
1111
1112   // Set a URL in property map again
1113   propertyMap[ImageVisual::Property::URL] = gImage_34_RGBA;
1114   imageView.SetProperty( ImageView::Property::IMAGE, propertyMap );
1115
1116   application.SendNotification();
1117   application.Render( 16 );
1118
1119   value = imageView.GetProperty( imageView.GetPropertyIndex( "image" ) );
1120   visual = DevelControl::GetVisual( controlImpl, ImageView::Property::IMAGE );
1121
1122   DALI_TEST_CHECK( ! value.Get( url ) ); // Value should be empty
1123   DALI_TEST_CHECK( value.Get( map ) );   // Value should NOT be empty
1124   DALI_TEST_CHECK( visual );             // Visual should be valid
1125
1126   // Set an empty URL in property map
1127   propertyMap[ImageVisual::Property::URL] = std::string();
1128   imageView.SetProperty( ImageView::Property::IMAGE, propertyMap );
1129
1130   application.SendNotification();
1131   application.Render( 16 );
1132
1133   value = imageView.GetProperty( imageView.GetPropertyIndex( "image" ) );
1134   visual = DevelControl::GetVisual( controlImpl, ImageView::Property::IMAGE );
1135
1136   DALI_TEST_CHECK( ! value.Get( url ) ); // Value should be empty
1137   DALI_TEST_CHECK( value.Get( map ) );   // Value should NOT be empty
1138   DALI_TEST_CHECK( ! visual );           // Visual should be invalid
1139
1140   END_TEST;
1141 }
1142
1143 int UtcDaliImageViewResourceUrlP(void)
1144 {
1145   ToolkitTestApplication application;
1146
1147   ImageView imageView = ImageView::New();
1148   DALI_TEST_CHECK( imageView.GetProperty( ImageView::Property::RESOURCE_URL ).Get< std::string >().empty() );
1149
1150   imageView.SetProperty( ImageView::Property::RESOURCE_URL, "TestString" );
1151   DALI_TEST_EQUALS( imageView.GetProperty( ImageView::Property::RESOURCE_URL ).Get< std::string >(), "TestString", TEST_LOCATION );
1152
1153   END_TEST;
1154 }
1155
1156 // Scenarios 1: ImageView from regular image
1157 int UtcDaliImageViewSetImageBufferImage(void)
1158 {
1159   ToolkitTestApplication application;
1160
1161   ImageView imageView = ImageView::New();
1162   Stage::GetCurrent().Add( imageView );
1163
1164   TestGlAbstraction& gl = application.GetGlAbstraction();
1165   gl.EnableTextureCallTrace( true );
1166
1167   std::vector< GLuint > ids;
1168   ids.push_back( 23 );
1169   application.GetGlAbstraction().SetNextTextureIds( ids );
1170
1171   int width = 300;
1172   int height = 400;
1173   BufferImage image = CreateBufferImage( width, height, Color::WHITE );
1174
1175   imageView.SetImage( image );
1176
1177   application.SendNotification();
1178   application.Render();
1179
1180   DALI_TEST_CHECK( gl.GetTextureTrace().FindMethod("BindTexture") );
1181
1182   std::stringstream params;
1183   params << GL_TEXTURE_2D << ", " << 23;
1184   DALI_TEST_CHECK( gl.GetTextureTrace().FindMethodAndParams("BindTexture", params.str()) );
1185
1186   END_TEST;
1187 }
1188
1189 // Scenarios 2: ImageView from Native image
1190 int UtcDaliImageViewSetImageNativeImage(void)
1191 {
1192   ToolkitTestApplication application;
1193
1194   ImageView imageView = ImageView::New();
1195   Stage::GetCurrent().Add( imageView );
1196
1197   TestGlAbstraction& gl = application.GetGlAbstraction();
1198   gl.EnableTextureCallTrace( true );
1199
1200   std::vector< GLuint > ids;
1201   ids.push_back( 23 );
1202   application.GetGlAbstraction().SetNextTextureIds( ids );
1203
1204   int width = 200;
1205   int height = 500;
1206   TestNativeImagePointer nativeImageInterface = TestNativeImage::New( width, height );
1207   NativeImage nativeImage = NativeImage::New( *(nativeImageInterface.Get()) );
1208
1209   imageView.SetImage( nativeImage );
1210   application.SendNotification();
1211   application.Render();
1212
1213   DALI_TEST_CHECK( gl.GetTextureTrace().FindMethod("BindTexture") );
1214
1215   std::stringstream params;
1216   params << GL_TEXTURE_EXTERNAL_OES << ", " << 23;
1217   DALI_TEST_CHECK( gl.GetTextureTrace().FindMethodAndParams("BindTexture", params.str()) );
1218
1219   END_TEST;
1220 }
1221
1222 // Scenarios 3: ImageView initially from regular image but then SetImage called with Native image
1223 int UtcDaliImageViewSetImageBufferImageToNativeImage(void)
1224 {
1225   ToolkitTestApplication application;
1226
1227   int width = 300;
1228   int height = 400;
1229   BufferImage image = CreateBufferImage( width, height, Color::WHITE );
1230
1231   ImageView imageView = ImageView::New( image );
1232   Stage::GetCurrent().Add( imageView );
1233
1234   TestGlAbstraction& gl = application.GetGlAbstraction();
1235   gl.EnableTextureCallTrace( true );
1236
1237   std::vector< GLuint > ids;
1238   ids.push_back( 23 );
1239   application.GetGlAbstraction().SetNextTextureIds( ids );
1240
1241   application.SendNotification();
1242   application.Render();
1243
1244   DALI_TEST_CHECK( gl.GetTextureTrace().FindMethod("BindTexture") );
1245
1246   std::stringstream params;
1247   params << GL_TEXTURE_2D << ", " << 23;
1248   DALI_TEST_CHECK( gl.GetTextureTrace().FindMethodAndParams("BindTexture", params.str()) );
1249
1250   width = 200;
1251   height = 500;
1252   TestNativeImagePointer nativeImageInterface = TestNativeImage::New( width, height );
1253   NativeImage nativeImage = NativeImage::New( *(nativeImageInterface.Get()) );
1254   imageView.SetImage( nativeImage );
1255
1256   ids.clear();
1257   ids.push_back( 24 );
1258   application.GetGlAbstraction().SetNextTextureIds( ids );
1259
1260   application.SendNotification();
1261   application.Render();
1262
1263   DALI_TEST_CHECK( gl.GetTextureTrace().FindMethod("BindTexture") );
1264
1265   std::stringstream nextTextureParams;
1266   nextTextureParams << GL_TEXTURE_EXTERNAL_OES << ", " << 24;
1267   DALI_TEST_CHECK( gl.GetTextureTrace().FindMethodAndParams("BindTexture", nextTextureParams.str()) );
1268
1269   END_TEST;
1270 }
1271
1272 // Scenarios 4: ImageView initially from Native image but then SetImage called with regular image
1273 int UtcDaliImageViewSetImageNativeImageToBufferImage(void)
1274 {
1275   ToolkitTestApplication application;
1276
1277   int width = 300;
1278   int height = 400;
1279   TestNativeImagePointer nativeImageInterface = TestNativeImage::New( width, height );
1280   NativeImage nativeImage = NativeImage::New( *(nativeImageInterface.Get()) );
1281
1282   ImageView imageView = ImageView::New( nativeImage );
1283   Stage::GetCurrent().Add( imageView );
1284
1285   TestGlAbstraction& gl = application.GetGlAbstraction();
1286   gl.EnableTextureCallTrace( true );
1287
1288   std::vector< GLuint > ids;
1289   ids.push_back( 23 );
1290   application.GetGlAbstraction().SetNextTextureIds( ids );
1291
1292   application.SendNotification();
1293   application.Render();
1294
1295   DALI_TEST_CHECK( gl.GetTextureTrace().FindMethod("BindTexture") );
1296
1297   std::stringstream params;
1298   params << GL_TEXTURE_EXTERNAL_OES << ", " << 23;
1299   DALI_TEST_CHECK( gl.GetTextureTrace().FindMethodAndParams("BindTexture", params.str()) );
1300
1301   width = 200;
1302   height = 500;
1303   BufferImage image = CreateBufferImage( width, height, Color::WHITE );
1304   imageView.SetImage( image );
1305
1306   ids.clear();
1307   ids.push_back( 24 );
1308   application.GetGlAbstraction().SetNextTextureIds( ids );
1309
1310   application.SendNotification();
1311   application.Render();
1312
1313   DALI_TEST_CHECK( gl.GetTextureTrace().FindMethod("BindTexture") );
1314
1315   std::stringstream nextTextureParams;
1316   nextTextureParams << GL_TEXTURE_2D << ", " << 24;
1317   DALI_TEST_CHECK( gl.GetTextureTrace().FindMethodAndParams("BindTexture", nextTextureParams.str()) );
1318
1319   END_TEST;
1320 }
1321
1322 // Scenarios 5: ImageView from Native image with custom shader
1323 int UtcDaliImageViewSetImageNativeImageWithCustomShader(void)
1324 {
1325   ToolkitTestApplication application;
1326
1327   int width = 300;
1328   int height = 400;
1329
1330   Property::Map customShader;
1331   customShader.Insert( "vertexShader", VERTEX_SHADER );
1332   customShader.Insert( "fragmentShader", FRAGMENT_SHADER );
1333
1334   Property::Array shaderHints;
1335   shaderHints.PushBack( "requiresSelfDepthTest" );
1336   shaderHints.PushBack( "outputIsTransparent" );
1337   shaderHints.PushBack( "outputIsOpaque" );
1338   shaderHints.PushBack( "modifiesGeometry" );
1339
1340   customShader.Insert( "hints", shaderHints );
1341
1342   Property::Map map;
1343   map.Insert( "shader", customShader );
1344
1345   TestNativeImagePointer nativeImageInterface = TestNativeImage::New( width, height );
1346   NativeImage nativeImage = NativeImage::New( *(nativeImageInterface.Get()) );
1347
1348   ImageView imageView = ImageView::New( nativeImage );
1349   imageView.SetProperty( ImageView::Property::IMAGE, map );
1350   Stage::GetCurrent().Add( imageView );
1351
1352   TestGlAbstraction& gl = application.GetGlAbstraction();
1353   gl.EnableTextureCallTrace( true );
1354
1355   std::vector< GLuint > ids;
1356   ids.push_back( 23 );
1357   application.GetGlAbstraction().SetNextTextureIds( ids );
1358
1359   application.SendNotification();
1360   application.Render();
1361
1362   DALI_TEST_CHECK( gl.GetTextureTrace().FindMethod("BindTexture") );
1363
1364   std::stringstream params;
1365   params << GL_TEXTURE_EXTERNAL_OES << ", " << 23;
1366   DALI_TEST_CHECK( gl.GetTextureTrace().FindMethodAndParams("BindTexture", params.str()) );
1367
1368   END_TEST;
1369 }
1370
1371 // Scenarios 6: ImageView initially from regular image with custom shader but then SetImage called with Native
1372 int UtcDaliImageViewSetImageBufferImageWithCustomShaderToNativeImage(void)
1373 {
1374   ToolkitTestApplication application;
1375
1376   int width = 300;
1377   int height = 400;
1378
1379   Property::Map customShader;
1380   customShader.Insert( "vertexShader", VERTEX_SHADER );
1381   customShader.Insert( "fragmentShader", FRAGMENT_SHADER );
1382
1383   Property::Array shaderHints;
1384   shaderHints.PushBack( "requiresSelfDepthTest" );
1385   shaderHints.PushBack( "outputIsTransparent" );
1386   shaderHints.PushBack( "outputIsOpaque" );
1387   shaderHints.PushBack( "modifiesGeometry" );
1388
1389   customShader.Insert( "hints", shaderHints );
1390
1391   Property::Map map;
1392   map.Insert( "shader", customShader );
1393
1394   BufferImage image = CreateBufferImage( width, height, Color::WHITE );
1395
1396   ImageView imageView = ImageView::New( image );
1397   imageView.SetProperty( ImageView::Property::IMAGE, map );
1398   Stage::GetCurrent().Add( imageView );
1399
1400   TestGlAbstraction& gl = application.GetGlAbstraction();
1401   gl.EnableTextureCallTrace( true );
1402
1403   std::vector< GLuint > ids;
1404   ids.push_back( 23 );
1405   application.GetGlAbstraction().SetNextTextureIds( ids );
1406
1407   application.SendNotification();
1408   application.Render();
1409
1410   DALI_TEST_CHECK( gl.GetTextureTrace().FindMethod("BindTexture") );
1411
1412   std::stringstream params;
1413   params << GL_TEXTURE_2D << ", " << 23;
1414   DALI_TEST_CHECK( gl.GetTextureTrace().FindMethodAndParams("BindTexture", params.str()) );
1415
1416   TestNativeImagePointer nativeImageInterface = TestNativeImage::New( width, height );
1417   NativeImage nativeImage = NativeImage::New( *(nativeImageInterface.Get()) );
1418   imageView.SetImage( nativeImage );
1419
1420   ids.clear();
1421   ids.push_back( 24 );
1422   application.GetGlAbstraction().SetNextTextureIds( ids );
1423
1424   application.SendNotification();
1425   application.Render();
1426
1427   DALI_TEST_CHECK( gl.GetTextureTrace().FindMethod("BindTexture") );
1428
1429   std::stringstream nativeImageParams;
1430   nativeImageParams << GL_TEXTURE_EXTERNAL_OES << ", " << 24;
1431   DALI_TEST_CHECK( gl.GetTextureTrace().FindMethodAndParams("BindTexture", nativeImageParams.str()) );
1432
1433
1434   END_TEST;
1435 }
1436
1437 int UtcDaliImageViewGetImageP1(void)
1438 {
1439   ToolkitTestApplication application;
1440
1441   ImageView imageView = ImageView::New();
1442   DALI_TEST_CHECK( ! imageView.GetImage() );
1443
1444   Image image = CreateBufferImage();
1445   imageView.SetImage( image );
1446   DALI_TEST_CHECK( imageView.GetImage() == image );
1447
1448   END_TEST;
1449 }
1450
1451 int UtcDaliImageViewGetImageP2(void)
1452 {
1453   ToolkitTestApplication application;
1454
1455   BufferImage image = CreateBufferImage();
1456   ImageView imageView = ImageView::New( image );
1457   DALI_TEST_CHECK( imageView.GetImage() == image );
1458
1459   END_TEST;
1460 }
1461
1462 int UtcDaliImageViewGetImageN(void)
1463 {
1464   ToolkitTestApplication application;
1465
1466   ImageView imageView = ImageView::New( TEST_IMAGE_FILE_NAME );
1467   DALI_TEST_CHECK( ! imageView.GetImage() );
1468
1469   Image image = CreateBufferImage();
1470   imageView.SetImage( image );
1471   DALI_TEST_CHECK( imageView.GetImage() == image );
1472
1473   imageView.SetImage( TEST_IMAGE_FILE_NAME );
1474   DALI_TEST_CHECK( ! imageView.GetImage() );
1475
1476   END_TEST;
1477 }
1478
1479
1480 int UtcDaliImageViewReplaceImage(void)
1481 {
1482   ToolkitTestApplication application;
1483
1484   gResourceReadySignalFired = false;
1485
1486   int width = 100;
1487   int height = 200;
1488   Image image = CreateBufferImage( width, height, Vector4(1.f, 1.f, 1.f, 1.f) );
1489
1490   // Check ImageView with background and main image, to ensure both visuals are marked as loaded
1491   ImageView imageView = ImageView::New( TEST_IMAGE_1 );
1492
1493   DALI_TEST_EQUALS( imageView.IsResourceReady(), false, TEST_LOCATION );
1494
1495   imageView.ResourceReadySignal().Connect( &ResourceReadySignal);
1496
1497   Stage::GetCurrent().Add( imageView );
1498
1499   application.SendNotification();
1500   application.Render(16);
1501
1502   // loading started, this waits for the loader thread for max 30 seconds
1503   DALI_TEST_EQUALS( Test::WaitForEventThreadTrigger( 1 ), true, TEST_LOCATION );
1504
1505   DALI_TEST_EQUALS( imageView.GetRendererCount(), 1u, TEST_LOCATION );
1506
1507   DALI_TEST_EQUALS( gResourceReadySignalFired, true, TEST_LOCATION );
1508
1509   gResourceReadySignalFired = false;
1510
1511   imageView.SetImage(TEST_IMAGE_2);
1512
1513   application.SendNotification();
1514   application.Render(16);
1515
1516   // loading started, this waits for the loader thread for max 30 seconds
1517   DALI_TEST_EQUALS( Test::WaitForEventThreadTrigger( 1 ), true, TEST_LOCATION );
1518
1519   DALI_TEST_EQUALS( imageView.GetRendererCount(), 1u, TEST_LOCATION );
1520
1521   DALI_TEST_EQUALS( imageView.IsResourceReady(), true, TEST_LOCATION );
1522
1523   DALI_TEST_EQUALS( gResourceReadySignalFired, true, TEST_LOCATION );
1524
1525   END_TEST;
1526 }
1527
1528 void OnRelayoutOverride( Size size )
1529 {
1530   gNaturalSize = size; // Size Relayout is using
1531 }
1532
1533 int UtcDaliImageViewReplaceImageAndGetNaturalSize(void)
1534 {
1535   ToolkitTestApplication application;
1536
1537   // Check ImageView with background and main image, to ensure both visuals are marked as loaded
1538   ImageView imageView = ImageView::New( TEST_IMAGE_1 );
1539   imageView.SetResizePolicy( ResizePolicy::USE_NATURAL_SIZE, Dimension::ALL_DIMENSIONS );
1540
1541   DummyControl dummyControl = DummyControl::New( true );
1542   Impl::DummyControl& dummyImpl = static_cast<Impl::DummyControl&>(dummyControl.GetImplementation());
1543   dummyControl.SetResizePolicy( ResizePolicy::FIT_TO_CHILDREN, Dimension::ALL_DIMENSIONS );
1544
1545   dummyControl.Add( imageView );
1546   dummyImpl.SetRelayoutCallback( &OnRelayoutOverride );
1547   Stage::GetCurrent().Add( dummyControl );
1548
1549   application.SendNotification();
1550   application.Render();
1551
1552   // loading started, this waits for the loader thread for max 30 seconds
1553   DALI_TEST_EQUALS( Test::WaitForEventThreadTrigger( 1 ), true, TEST_LOCATION );
1554
1555   DALI_TEST_EQUALS( gNaturalSize.width, 1024.0f, TEST_LOCATION );
1556   DALI_TEST_EQUALS( gNaturalSize.height, 1024.0f, TEST_LOCATION );
1557
1558   gNaturalSize = Vector3::ZERO;
1559
1560   imageView.SetImage(gImage_600_RGB);
1561
1562   // Waiting for resourceReady so SendNotifcation not called here.
1563
1564   // loading started, this waits for the loader thread for max 30 seconds
1565   DALI_TEST_EQUALS( Test::WaitForEventThreadTrigger( 1 ), true, TEST_LOCATION );
1566
1567   // Trigger a potential relayout
1568   application.SendNotification();
1569   application.Render();
1570
1571   DALI_TEST_EQUALS( gNaturalSize.width, 600.0f, TEST_LOCATION );
1572   DALI_TEST_EQUALS( gNaturalSize.height, 600.0f, TEST_LOCATION );
1573
1574   END_TEST;
1575 }
1576
1577 int UtcDaliImageViewResourceReadySignalWithImmediateLoad(void)
1578 {
1579   tet_infoline("Test Setting Image with IMMEDIATE load and receving ResourceReadySignal before staged.");
1580
1581   ToolkitTestApplication application;
1582
1583   gResourceReadySignalFired = false;
1584
1585   Property::Map imageMap;
1586
1587   imageMap[ ImageVisual::Property::URL ] = gImage_34_RGBA;
1588   imageMap[ ImageVisual::Property::LOAD_POLICY ] =  ImageVisual::LoadPolicy::IMMEDIATE;
1589
1590   tet_infoline("Creating ImageView without URL so image does not start loading");
1591   ImageView imageView = ImageView::New();
1592   tet_infoline("Connect to image loaded signal before setting image");
1593   imageView.ResourceReadySignal().Connect( &ResourceReadySignal);
1594   tet_infoline("Setting Image with IMMEDIATE load, signal already connected so will be triggered.");
1595   imageView.SetProperty( ImageView::Property::IMAGE, imageMap );
1596
1597   // loading started, this waits for the loader thread
1598   DALI_TEST_EQUALS( Test::WaitForEventThreadTrigger( 1 ), true, TEST_LOCATION );
1599
1600   application.SendNotification();
1601   application.Render(16);
1602
1603   DALI_TEST_EQUALS( gResourceReadySignalFired, true, TEST_LOCATION );
1604
1605   END_TEST;
1606 }
1607
1608 int UtcDaliImageViewResourceReadySignalWithReusedImage(void)
1609 {
1610   tet_infoline("Test Setting Image that was already loaded by another ImageView and still getting ResourceReadySignal.");
1611
1612   ToolkitTestApplication application;
1613
1614   gResourceReadySignalFired = false;
1615
1616   Property::Map imageMap;
1617
1618   imageMap[ ImageVisual::Property::URL ] = gImage_34_RGBA;
1619   imageMap[ ImageVisual::Property::LOAD_POLICY ] =  ImageVisual::LoadPolicy::IMMEDIATE;
1620
1621   ImageView imageView = ImageView::New();
1622   imageView.ResourceReadySignal().Connect( &ResourceReadySignal);
1623   imageView.SetProperty( ImageView::Property::IMAGE, imageMap );
1624
1625   // loading started, this waits for the loader thread
1626   DALI_TEST_EQUALS( Test::WaitForEventThreadTrigger( 1 ), true, TEST_LOCATION );
1627
1628   application.SendNotification();
1629   application.Render(16);
1630
1631   DALI_TEST_EQUALS( gResourceReadySignalFired, true, TEST_LOCATION );
1632   gResourceReadySignalFired = false;
1633
1634   ImageView imageViewWithExistingImage = ImageView::New();
1635   imageViewWithExistingImage.ResourceReadySignal().Connect( &ResourceReadySignal);
1636   imageViewWithExistingImage.SetProperty( ImageView::Property::IMAGE, imageMap );
1637
1638   DALI_TEST_EQUALS( gResourceReadySignalFired, true, TEST_LOCATION );
1639
1640   END_TEST;
1641 }
1642
1643 int UtcDaliImageViewResourceReadySignalWithReusedImage02(void)
1644 {
1645   tet_infoline("Test Setting Image that was already loaded by another ImageView and still getting ResourceReadySignal when staged.");
1646
1647   ToolkitTestApplication application;
1648
1649   gResourceReadySignalFired = false;
1650
1651   Property::Map imageImmediateLoadingMap;
1652   imageImmediateLoadingMap[ ImageVisual::Property::URL ] = gImage_34_RGBA;
1653   imageImmediateLoadingMap[ ImageVisual::Property::LOAD_POLICY ] =  ImageVisual::LoadPolicy::IMMEDIATE;
1654
1655   tet_infoline("Immediate load an image");
1656   ImageView imageView = ImageView::New();
1657   imageView.ResourceReadySignal().Connect( &ResourceReadySignal);
1658   imageView.SetProperty( ImageView::Property::IMAGE, imageImmediateLoadingMap );
1659
1660   // loading started, this waits for the loader thread
1661   DALI_TEST_EQUALS( Test::WaitForEventThreadTrigger( 1 ), true, TEST_LOCATION );
1662
1663   application.SendNotification();
1664   application.Render(16);
1665
1666   tet_infoline("Check image loaded");
1667   DALI_TEST_EQUALS( gResourceReadySignalFired, true, TEST_LOCATION );
1668   gResourceReadySignalFired = false;
1669
1670   tet_infoline("Create another ImageView with the same URL");
1671   ImageView imageViewWithExistingImage = ImageView::New( gImage_34_RGBA );
1672   tet_infoline("Connect to ResourceReady signal for second ImageView, it should still fire as resource is ready");
1673   imageViewWithExistingImage.ResourceReadySignal().Connect( &ResourceReadySignal);
1674
1675   Stage::GetCurrent().Add( imageViewWithExistingImage );
1676
1677   DALI_TEST_EQUALS( gResourceReadySignalFired, true, TEST_LOCATION );
1678
1679   END_TEST;
1680 }
1681
1682 int UtcDaliImageViewPaddingProperty(void)
1683 {
1684   ToolkitTestApplication application;
1685
1686   ImageView imageView = ImageView::New();
1687   Property::Map imagePropertyMap;
1688   imagePropertyMap[ Toolkit::Visual::Property::TYPE ] = Toolkit::Visual::IMAGE;
1689   imagePropertyMap[ Toolkit::ImageVisual::Property::URL ] = TEST_RESOURCE_DIR "/gallery-small-1.jpg" ;
1690   imagePropertyMap[ ImageVisual::Property::DESIRED_WIDTH ] = 128;
1691   imagePropertyMap[ ImageVisual::Property::DESIRED_HEIGHT ] = 128;
1692   imageView.SetProperty( Toolkit::ImageView::Property::IMAGE , imagePropertyMap );
1693   imageView.SetAnchorPoint( AnchorPoint::TOP_LEFT );
1694   imageView.SetParentOrigin( ParentOrigin::TOP_LEFT );
1695   imageView.SetProperty( Control::Property::PADDING, Extents( 15, 10, 5, 10 ) );
1696   Stage::GetCurrent().Add( imageView );
1697
1698   application.SendNotification();
1699   application.Render();
1700
1701   DALI_TEST_EQUALS( imageView.GetProperty<Extents>( Control::Property::PADDING ), Extents( 15, 10, 5, 10 ), TEST_LOCATION );
1702
1703   ImageView childImage = ImageView::New();
1704   childImage.SetBackgroundColor( Color::BLACK );
1705   childImage.SetSize( 10.f, 10.f );
1706   imageView.Add( childImage );
1707
1708   application.SendNotification();
1709   application.Render();
1710
1711   // Child ImageView should be positioned dependinig on Parent ImageView's Padding value
1712   DALI_TEST_EQUALS( childImage.GetProperty<Vector3>( Dali::Actor::Property::POSITION ), Vector3( 15, 5, 0 ), TEST_LOCATION );
1713
1714   // Check whether Image Visual transforms on ImageVieiw::OnRelayout()
1715   Toolkit::Internal::Control& controlImpl = Toolkit::Internal::GetImplementation( imageView );
1716   Toolkit::Visual::Base imageVisual = DevelControl::GetVisual( controlImpl, ImageView::Property::IMAGE );
1717   Property::Map resultMap;
1718   imageVisual.CreatePropertyMap( resultMap );
1719
1720   Property::Value* transformValue = resultMap.Find( Visual::Property::TRANSFORM );
1721   DALI_TEST_CHECK( transformValue );
1722   Property::Map* retMap = transformValue->GetMap();
1723   DALI_TEST_CHECK( retMap );
1724
1725   // Image Visual should be positioned depending on ImageView's padding
1726   DALI_TEST_EQUALS( retMap->Find( Visual::Transform::Property::OFFSET )->Get< Vector2 >(), Vector2( 15, 5 ), TEST_LOCATION );
1727
1728   END_TEST;
1729 }
1730
1731 int UtcDaliImageViewPaddingProperty02(void)
1732 {
1733   ToolkitTestApplication application;
1734
1735   ImageView imageView = ImageView::New();
1736   Property::Map imagePropertyMap;
1737   imagePropertyMap[ Toolkit::Visual::Property::TYPE ] = Toolkit::Visual::IMAGE;
1738   imagePropertyMap[ Toolkit::ImageVisual::Property::URL ] = TEST_RESOURCE_DIR "/Kid1.svg" ;
1739   imagePropertyMap[ ImageVisual::Property::DESIRED_WIDTH ] = 128;
1740   imagePropertyMap[ ImageVisual::Property::DESIRED_HEIGHT ] = 128;
1741   imagePropertyMap[ DevelVisual::Property::VISUAL_FITTING_MODE ] = Toolkit::DevelVisual::FIT_KEEP_ASPECT_RATIO;
1742   imageView.SetProperty( Toolkit::ImageView::Property::IMAGE , imagePropertyMap );
1743   imageView.SetAnchorPoint( AnchorPoint::TOP_LEFT );
1744   imageView.SetParentOrigin( ParentOrigin::TOP_LEFT );
1745   imageView.SetProperty( Control::Property::PADDING, Extents( 15, 10, 5, 10 ) );
1746   Stage::GetCurrent().Add( imageView );
1747
1748   application.SendNotification();
1749   application.Render();
1750
1751   DALI_TEST_EQUALS( imageView.GetProperty<Extents>( Control::Property::PADDING ), Extents( 15, 10, 5, 10 ), TEST_LOCATION );
1752
1753   // Check whether Image Visual transforms on ImageVieiw::OnRelayout()
1754   Toolkit::Internal::Control& controlImpl = Toolkit::Internal::GetImplementation( imageView );
1755   Toolkit::Visual::Base imageVisual = DevelControl::GetVisual( controlImpl, ImageView::Property::IMAGE );
1756   Property::Map resultMap;
1757   imageVisual.CreatePropertyMap( resultMap );
1758
1759   Property::Value* transformValue = resultMap.Find( Visual::Property::TRANSFORM );
1760   DALI_TEST_CHECK( transformValue );
1761   Property::Map* retMap = transformValue->GetMap();
1762   DALI_TEST_CHECK( retMap );
1763
1764   // Image Visual should be positioned depending on ImageView's padding
1765   DALI_TEST_EQUALS( retMap->Find( Visual::Transform::Property::OFFSET )->Get< Vector2 >(), Vector2( 15, 5 ), TEST_LOCATION );
1766
1767   END_TEST;
1768 }
1769
1770 int UtcDaliImageViewUsingAtlasAndGetNaturalSize(void)
1771 {
1772   ToolkitTestApplication application;
1773
1774   // Check ImageView with background and main image, to ensure both visuals are marked as loaded
1775   ImageView imageView = ImageView::New();
1776   Property::Map imageMap;
1777   imageMap[ Toolkit::Visual::Property::TYPE ] = Toolkit::Visual::IMAGE;
1778   imageMap[ Toolkit::ImageVisual::Property::URL ] = gImage_34_RGBA;
1779   imageMap[ Toolkit::ImageVisual::Property::ATLASING ] = true;
1780   imageView.SetProperty( Toolkit::ImageView::Property::IMAGE, imageMap );
1781   Stage::GetCurrent().Add( imageView );
1782
1783   // Trigger a potential relayout
1784   application.SendNotification();
1785   application.Render();
1786
1787   Vector3 naturalSize = imageView.GetNaturalSize();
1788
1789   DALI_TEST_EQUALS( naturalSize.width, 34.0f, TEST_LOCATION );
1790   DALI_TEST_EQUALS( naturalSize.height, 34.0f, TEST_LOCATION );
1791
1792   END_TEST;
1793 }
1794
1795 int UtcDaliImageViewFillMode(void)
1796 {
1797   ToolkitTestApplication application;
1798
1799   tet_infoline( "Create an ImageVisual without padding and set the fill-mode to fill" );
1800   tet_infoline( "  There should be no need to change the transform, our size-policy should be relative and size shoudl be [1,1]");
1801
1802   ImageView imageView = ImageView::New();
1803   Property::Map imageMap;
1804   imageMap.Add( Toolkit::Visual::Property::TYPE, Toolkit::Visual::IMAGE );
1805   imageMap.Add( Toolkit::ImageVisual::Property::URL, gImage_600_RGB );
1806   imageMap.Add( DevelVisual::Property::VISUAL_FITTING_MODE, DevelVisual::FittingMode::FILL );
1807
1808   imageView.SetProperty( Toolkit::ImageView::Property::IMAGE, imageMap );
1809
1810   Stage::GetCurrent().Add( imageView );
1811
1812   // Trigger a potential relayout
1813   application.SendNotification();
1814   application.Render();
1815
1816   Toolkit::Visual::Base visual = DevelControl::GetVisual( Toolkit::Internal::GetImplementation( imageView ), Toolkit::ImageView::Property::IMAGE );
1817   Property::Map returnedMap;
1818   visual.CreatePropertyMap( returnedMap );
1819
1820   Property::Value* value = returnedMap.Find( Toolkit::Visual::Property::TRANSFORM );
1821   DALI_TEST_CHECK( value );
1822   Property::Map* map = value->GetMap();
1823   DALI_TEST_CHECK( map );
1824
1825   // If there's
1826   value = map->Find( Toolkit::Visual::Transform::Property::SIZE );
1827   DALI_TEST_CHECK( value );
1828   DALI_TEST_EQUALS( value->Get< Vector2 >(), Vector2::ONE, TEST_LOCATION ); // Relative size so will take up 100%
1829
1830   value = map->Find( Toolkit::Visual::Transform::Property::SIZE_POLICY );
1831   DALI_TEST_CHECK( value );
1832   DALI_TEST_CHECK( value->Get< int >() == Toolkit::Visual::Transform::Policy::RELATIVE );
1833
1834   END_TEST;
1835 }
1836
1837 int UtcDaliImageViewCustomShader(void)
1838 {
1839   ToolkitTestApplication application;
1840
1841   // Set a custom shader with an image url
1842   {
1843     Property::Map properties;
1844     Property::Map shader;
1845     const std::string vertexShader = "Foobar";
1846     const std::string fragmentShader = "Foobar";
1847     shader[Visual::Shader::Property::FRAGMENT_SHADER] = fragmentShader;
1848     shader[Visual::Shader::Property::VERTEX_SHADER] = vertexShader;
1849
1850     properties[Visual::Property::TYPE] = Visual::IMAGE;
1851     properties[Visual::Property::SHADER] = shader;
1852     properties[ImageVisual::Property::URL] = TEST_IMAGE_FILE_NAME;
1853
1854     ImageView imageView = ImageView::New();
1855     imageView.SetProperty( ImageView::Property::IMAGE, properties );
1856
1857     Stage::GetCurrent().Add( imageView );
1858
1859     application.SendNotification();
1860     application.Render();
1861
1862     DALI_TEST_EQUALS( Test::WaitForEventThreadTrigger( 1 ), true, TEST_LOCATION );
1863
1864     Renderer renderer = imageView.GetRendererAt( 0 );
1865     Shader shader2 = renderer.GetShader();
1866     Property::Value value = shader2.GetProperty( Shader::Property::PROGRAM );
1867     Property::Map* map = value.GetMap();
1868     DALI_TEST_CHECK( map );
1869
1870     Property::Value* fragment = map->Find( "fragment" ); // fragment key name from shader-impl.cpp
1871     DALI_TEST_EQUALS( fragmentShader, fragment->Get< std::string >(), TEST_LOCATION );
1872
1873     Property::Value* vertex = map->Find( "vertex" ); // vertex key name from shader-impl.cpp
1874     DALI_TEST_EQUALS( vertexShader, vertex->Get< std::string >(), TEST_LOCATION );
1875   }
1876
1877   // Set a custom shader after setting an image url
1878   {
1879     Property::Map properties;
1880     Property::Map shader;
1881     const std::string vertexShader = "Foobar";
1882     const std::string fragmentShader = "Foobar";
1883     shader[Visual::Shader::Property::FRAGMENT_SHADER] = fragmentShader;
1884     shader[Visual::Shader::Property::VERTEX_SHADER] = vertexShader;
1885
1886     properties[Visual::Property::SHADER] = shader;
1887
1888     ImageView imageView = ImageView::New( TEST_IMAGE_FILE_NAME );
1889     imageView.SetProperty( ImageView::Property::IMAGE, properties );
1890
1891     Stage::GetCurrent().Add( imageView );
1892
1893     application.SendNotification();
1894     application.Render();
1895
1896     Renderer renderer = imageView.GetRendererAt( 0 );
1897     Shader shader2 = renderer.GetShader();
1898     Property::Value value = shader2.GetProperty( Shader::Property::PROGRAM );
1899     Property::Map* map = value.GetMap();
1900     DALI_TEST_CHECK( map );
1901
1902     Property::Value* fragment = map->Find( "fragment" ); // fragment key name from shader-impl.cpp
1903     DALI_TEST_EQUALS( fragmentShader, fragment->Get< std::string >(), TEST_LOCATION );
1904
1905     Property::Value* vertex = map->Find( "vertex" ); // vertex key name from shader-impl.cpp
1906     DALI_TEST_EQUALS( vertexShader, vertex->Get< std::string >(), TEST_LOCATION );
1907   }
1908
1909   // Set a custom shader before setting an image url
1910   {
1911     Property::Map properties;
1912     Property::Map shader;
1913     const std::string vertexShader = "Foobar";
1914     const std::string fragmentShader = "Foobar";
1915     shader[Visual::Shader::Property::FRAGMENT_SHADER] = fragmentShader;
1916     shader[Visual::Shader::Property::VERTEX_SHADER] = vertexShader;
1917
1918     properties[Visual::Property::SHADER] = shader;
1919
1920     ImageView imageView = ImageView::New();
1921     imageView.SetProperty( ImageView::Property::IMAGE, properties );
1922     imageView.SetProperty( ImageView::Property::IMAGE, TEST_IMAGE_FILE_NAME );
1923
1924     Stage::GetCurrent().Add( imageView );
1925
1926     application.SendNotification();
1927     application.Render();
1928
1929     Renderer renderer = imageView.GetRendererAt( 0 );
1930     Shader shader2 = renderer.GetShader();
1931     Property::Value value = shader2.GetProperty( Shader::Property::PROGRAM );
1932     Property::Map* map = value.GetMap();
1933     DALI_TEST_CHECK( map );
1934
1935     Property::Value* fragment = map->Find( "fragment" ); // fragment key name from shader-impl.cpp
1936     DALI_TEST_EQUALS( fragmentShader, fragment->Get< std::string >(), TEST_LOCATION );
1937
1938     Property::Value* vertex = map->Find( "vertex" ); // vertex key name from shader-impl.cpp
1939     DALI_TEST_EQUALS( vertexShader, vertex->Get< std::string >(), TEST_LOCATION );
1940   }
1941
1942   // Set a custom shader after setting a property map
1943   {
1944     Property::Map properties;
1945     Property::Map shader;
1946     const std::string vertexShader = "Foobar";
1947     const std::string fragmentShader = "Foobar";
1948     shader[Visual::Shader::Property::FRAGMENT_SHADER] = fragmentShader;
1949     shader[Visual::Shader::Property::VERTEX_SHADER] = vertexShader;
1950
1951     properties[Visual::Property::SHADER] = shader;
1952
1953     Property::Map properties1;
1954     properties1[Visual::Property::TYPE] = Visual::IMAGE;
1955     properties1[ImageVisual::Property::URL] = TEST_IMAGE_FILE_NAME;
1956
1957     ImageView imageView = ImageView::New();
1958     imageView.SetProperty( ImageView::Property::IMAGE, properties1 );
1959     imageView.SetProperty( ImageView::Property::IMAGE, properties );
1960
1961     Stage::GetCurrent().Add( imageView );
1962
1963     application.SendNotification();
1964     application.Render();
1965
1966     Renderer renderer = imageView.GetRendererAt( 0 );
1967     Shader shader2 = renderer.GetShader();
1968     Property::Value value = shader2.GetProperty( Shader::Property::PROGRAM );
1969     Property::Map* map = value.GetMap();
1970     DALI_TEST_CHECK( map );
1971
1972     Property::Value* fragment = map->Find( "fragment" ); // fragment key name from shader-impl.cpp
1973     DALI_TEST_EQUALS( fragmentShader, fragment->Get< std::string >(), TEST_LOCATION );
1974
1975     Property::Value* vertex = map->Find( "vertex" ); // vertex key name from shader-impl.cpp
1976     DALI_TEST_EQUALS( vertexShader, vertex->Get< std::string >(), TEST_LOCATION );
1977   }
1978
1979   // Set a custom shader before setting a property map
1980   {
1981     Property::Map properties;
1982     Property::Map shader;
1983     const std::string vertexShader = "Foobar";
1984     const std::string fragmentShader = "Foobar";
1985     shader[Visual::Shader::Property::FRAGMENT_SHADER] = fragmentShader;
1986     shader[Visual::Shader::Property::VERTEX_SHADER] = vertexShader;
1987
1988     properties[Visual::Property::SHADER] = shader;
1989
1990     Property::Map properties1;
1991     properties1[Visual::Property::TYPE] = Visual::IMAGE;
1992     properties1[ImageVisual::Property::URL] = TEST_IMAGE_FILE_NAME;
1993
1994     ImageView imageView = ImageView::New();
1995     imageView.SetProperty( ImageView::Property::IMAGE, properties );
1996     imageView.SetProperty( ImageView::Property::IMAGE, properties1 );
1997
1998     Stage::GetCurrent().Add( imageView );
1999
2000     application.SendNotification();
2001     application.Render();
2002
2003     Renderer renderer = imageView.GetRendererAt( 0 );
2004     Shader shader2 = renderer.GetShader();
2005     Property::Value value = shader2.GetProperty( Shader::Property::PROGRAM );
2006     Property::Map* map = value.GetMap();
2007     DALI_TEST_CHECK( map );
2008
2009     Property::Value* fragment = map->Find( "fragment" ); // fragment key name from shader-impl.cpp
2010     DALI_TEST_EQUALS( fragmentShader, fragment->Get< std::string >(), TEST_LOCATION );
2011
2012     Property::Value* vertex = map->Find( "vertex" ); // vertex key name from shader-impl.cpp
2013     DALI_TEST_EQUALS( vertexShader, vertex->Get< std::string >(), TEST_LOCATION );
2014   }
2015
2016   END_TEST;
2017 }