[dali_1.2.60] Merge branch 'devel/master'
[platform/core/uifw/dali-toolkit.git] / automated-tests / src / dali-toolkit / utc-Dali-ImageView.cpp
1 /*
2  * Copyright (c) 2017 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
28 #include <test-native-image.h>
29 #include <sstream>
30 #include <unistd.h>
31
32
33 #include "dummy-control.h"
34
35 using namespace Dali;
36 using namespace Toolkit;
37
38 void utc_dali_toolkit_image_view_startup(void)
39 {
40   test_return_value = TET_UNDEF;
41 }
42
43 void utc_dali_toolkit_image_view_cleanup(void)
44 {
45   test_return_value = TET_PASS;
46 }
47
48 namespace
49 {
50
51 const char* VERTEX_SHADER = DALI_COMPOSE_SHADER(
52   attribute mediump vec2 aPosition;\n
53   varying mediump vec2 vTexCoord;\n
54   uniform mediump mat4 uMvpMatrix;\n
55   uniform mediump vec3 uSize;\n
56   \n
57   void main()\n
58   {\n
59     mediump vec4 vertexPosition = vec4(aPosition, 0.0, 1.0);\n
60     vertexPosition.xyz *= uSize;\n
61     vertexPosition = uMvpMatrix * vertexPosition;\n
62     \n
63     vTexCoord = aPosition + vec2(0.5);\n
64     gl_Position = vertexPosition;\n
65   }\n
66 );
67
68 const char* FRAGMENT_SHADER = DALI_COMPOSE_SHADER(
69   varying mediump vec2 vTexCoord;\n
70   uniform sampler2D sTexture;\n
71   uniform lowp vec4 uColor;\n
72   \n
73   void main()\n
74   {\n
75     gl_FragColor = texture2D( sTexture, vTexCoord ) * uColor;\n
76   }\n
77 );
78
79 const char* TEST_IMAGE_FILE_NAME =  "gallery_image_01.jpg";
80 const char* TEST_IMAGE_FILE_NAME2 =  "gallery_image_02.jpg";
81
82 const char* TEST_IMAGE_1 = TEST_RESOURCE_DIR "/TB-gloss.png";
83 const char* TEST_IMAGE_2 = TEST_RESOURCE_DIR "/tb-norm.png";
84
85 // resolution: 34*34, pixel format: RGBA8888
86 static const char* gImage_34_RGBA = TEST_RESOURCE_DIR "/icon-edit.png";
87 // resolution: 600*600, pixel format: RGB888
88 static const char* gImage_600_RGB = TEST_RESOURCE_DIR "/test-image-600.jpg";
89
90 // resolution: 50*50, frame count: 4, frame delay: 0.2 second for each frame
91 const char* TEST_GIF_FILE_NAME = TEST_RESOURCE_DIR "/anim.gif";
92
93 void TestImage( ImageView imageView, BufferImage image )
94 {
95   Property::Value value = imageView.GetProperty( imageView.GetPropertyIndex( "image" ) );
96
97   Property::Map map;
98   DALI_TEST_CHECK( value.Get( map ) );
99
100   DALI_TEST_CHECK( map.Find( "width" ) );
101   DALI_TEST_CHECK( map.Find( "height" ) );
102   DALI_TEST_CHECK( map.Find( "type" ) );
103
104   int width = 0;
105   DALI_TEST_CHECK( map[ "width" ].Get( width ) );
106   DALI_TEST_EQUALS( (unsigned int)width, image.GetWidth(), TEST_LOCATION );
107
108   int height = 0;
109   DALI_TEST_CHECK( map[ "height" ].Get( height ) );
110   DALI_TEST_EQUALS( (unsigned int)height, image.GetHeight(), TEST_LOCATION );
111
112   std::string type;
113   DALI_TEST_CHECK( map[ "type" ].Get( type ) );
114   DALI_TEST_EQUALS( type, "BufferImage", TEST_LOCATION );
115 }
116
117 void TestImage( ImageView imageView, ResourceImage image )
118 {
119   Property::Value value = imageView.GetProperty( imageView.GetPropertyIndex( "image" ) );
120
121   Property::Map map;
122   DALI_TEST_CHECK( value.Get( map ) );
123
124   if( map.Find( "width" ) )
125   {
126     int width = 0;
127     DALI_TEST_CHECK( map[ "width" ].Get( width ) );
128     DALI_TEST_EQUALS( (unsigned int)width, image.GetWidth(), TEST_LOCATION );
129   }
130
131   if( map.Find( "height" ) )
132   {
133     int height = 0;
134     DALI_TEST_CHECK( map[ "height" ].Get( height ) );
135     DALI_TEST_EQUALS( (unsigned int)height, image.GetHeight(), TEST_LOCATION );
136   }
137
138   DALI_TEST_CHECK( map.Find( "type" ) );
139
140   std::string type;
141   DALI_TEST_CHECK( map[ "type" ].Get( type ) );
142   DALI_TEST_EQUALS( type, "ResourceImage", TEST_LOCATION );
143
144   std::string filename;
145   DALI_TEST_CHECK( map[ "filename" ].Get( filename ) );
146   DALI_TEST_EQUALS( filename, image.GetUrl(), TEST_LOCATION );
147 }
148
149 void TestUrl( ImageView imageView, const std::string url )
150 {
151   Property::Value value = imageView.GetProperty( imageView.GetPropertyIndex( "image" ) );
152
153   std::string urlActual;
154   DALI_TEST_CHECK( value.Get( urlActual ) );
155   DALI_TEST_EQUALS( urlActual, url, TEST_LOCATION );
156 }
157
158 } // namespace
159
160 int UtcDaliImageViewNewP(void)
161 {
162   TestApplication application;
163
164   ImageView imageView = ImageView::New();
165
166   DALI_TEST_CHECK( imageView );
167
168   END_TEST;
169 }
170
171 int UtcDaliImageViewNewImageP(void)
172 {
173   TestApplication application;
174
175   BufferImage image = CreateBufferImage( 100, 200, Vector4( 1.f, 1.f, 1.f, 1.f ) );
176   ImageView imageView = ImageView::New( image );
177
178   DALI_TEST_CHECK( imageView );
179   TestImage( imageView, image );
180
181   END_TEST;
182 }
183
184 int UtcDaliImageViewNewUrlP(void)
185 {
186   TestApplication application;
187
188   ImageView imageView = ImageView::New( TEST_IMAGE_FILE_NAME );
189   DALI_TEST_CHECK( imageView );
190
191   TestUrl( imageView, TEST_IMAGE_FILE_NAME );
192
193   END_TEST;
194 }
195
196 int UtcDaliImageViewConstructorP(void)
197 {
198   TestApplication application;
199
200   ImageView imageView;
201
202   DALI_TEST_CHECK( !imageView );
203
204   END_TEST;
205 }
206
207 int UtcDaliImageViewCopyConstructorP(void)
208 {
209   TestApplication application;
210
211   // Initialize an object, ref count == 1
212   ImageView imageView = ImageView::New();
213
214   ImageView copy( imageView );
215   DALI_TEST_CHECK( copy );
216
217   END_TEST;
218 }
219
220 int UtcDaliImageViewAssignmentOperatorP(void)
221 {
222   TestApplication application;
223
224   ImageView imageView = ImageView::New();
225
226   ImageView copy( imageView );
227   DALI_TEST_CHECK( copy );
228   DALI_TEST_EQUALS( imageView, copy, TEST_LOCATION );
229
230   END_TEST;
231 }
232
233 int UtcDaliImageViewDownCastP(void)
234 {
235   TestApplication application;
236
237   ImageView imageView = ImageView::New();
238
239   BaseHandle object(imageView);
240
241   ImageView imageView2 = ImageView::DownCast( object );
242   DALI_TEST_CHECK(imageView2);
243
244   ImageView imageView3 = DownCast< ImageView >( object );
245   DALI_TEST_CHECK(imageView3);
246
247   END_TEST;
248 }
249
250 int UtcDaliImageViewDownCastN(void)
251 {
252   TestApplication application;
253
254   BaseHandle unInitializedObject;
255
256   ImageView imageView1 = ImageView::DownCast( unInitializedObject );
257   DALI_TEST_CHECK( !imageView1 );
258
259   ImageView imageView2 = DownCast< ImageView >( unInitializedObject );
260   DALI_TEST_CHECK( !imageView2 );
261
262   END_TEST;
263 }
264
265 int UtcDaliImageViewTypeRegistry(void)
266 {
267   ToolkitTestApplication application;
268
269   TypeRegistry typeRegistry = TypeRegistry::Get();
270   DALI_TEST_CHECK( typeRegistry );
271
272   TypeInfo typeInfo = typeRegistry.GetTypeInfo( "ImageView" );
273   DALI_TEST_CHECK( typeInfo );
274
275   BaseHandle handle = typeInfo.CreateInstance();
276   DALI_TEST_CHECK( handle );
277
278   ImageView imageView = ImageView::DownCast( handle );
279   DALI_TEST_CHECK( imageView );
280
281   END_TEST;
282 }
283
284 int UtcDaliImageViewSetGetProperty01(void)
285 {
286   ToolkitTestApplication application;
287
288   ImageView imageView = ImageView::New();
289
290   Property::Index idx = imageView.GetPropertyIndex( "image" );
291   DALI_TEST_EQUALS( idx, (Property::Index)ImageView::Property::IMAGE, TEST_LOCATION );
292
293   imageView.SetProperty( idx, TEST_IMAGE_FILE_NAME );
294   TestUrl( imageView, TEST_IMAGE_FILE_NAME );
295
296   END_TEST;
297 }
298
299 int UtcDaliImageViewSetGetProperty02(void)
300 {
301   ToolkitTestApplication application;
302
303   Image image = CreateBufferImage( 10, 10, Color::WHITE );
304   ImageView imageView = ImageView::New(image);
305   Vector4 fullImageRect( 0.f, 0.f, 1.f, 1.f );
306
307   Stage::GetCurrent().Add( imageView );
308
309   application.SendNotification();
310   application.Render();
311   TestGlAbstraction& gl = application.GetGlAbstraction();
312
313   Vector4 pixelAreaUniform;
314   DALI_TEST_CHECK( gl.GetUniformValue<Vector4>( "pixelArea", pixelAreaUniform ) );
315   DALI_TEST_EQUALS( pixelAreaUniform, fullImageRect, TEST_LOCATION );
316
317   Property::Value value = imageView.GetProperty( ImageView::Property::PIXEL_AREA );
318   Vector4 pixelAreaValue;
319   DALI_TEST_CHECK( value.Get(pixelAreaValue) );
320   DALI_TEST_EQUALS( pixelAreaValue, fullImageRect, TEST_LOCATION );
321
322   Vector4 pixelAreaSet( 0.2f, 0.2f, 0.3f, 0.3f );
323   imageView.SetProperty( ImageView::Property::PIXEL_AREA, pixelAreaSet);
324
325   application.SendNotification();
326   application.Render();
327
328   value = imageView.GetProperty( ImageView::Property::PIXEL_AREA );
329   value.Get(pixelAreaValue);
330   DALI_TEST_EQUALS( pixelAreaValue, pixelAreaSet, TEST_LOCATION );
331
332   DALI_TEST_CHECK( gl.GetUniformValue<Vector4>( "pixelArea", pixelAreaUniform ) );
333   DALI_TEST_EQUALS( pixelAreaUniform, pixelAreaSet, TEST_LOCATION );
334
335   END_TEST;
336 }
337
338 int UtcDaliImageViewSetGetProperty03(void)
339 {
340   ToolkitTestApplication application;
341
342   Image image = CreateBufferImage( 10, 10, Color::WHITE );
343   ImageView imageView = ImageView::New(image);
344   Stage::GetCurrent().Add( imageView );
345   application.SendNotification();
346   application.Render();
347
348   // conventional alpha blending
349   Renderer renderer = imageView.GetRendererAt( 0 );
350   Property::Value value = renderer.GetProperty( Renderer::Property::BLEND_PRE_MULTIPLIED_ALPHA );
351   bool enable;
352   DALI_TEST_CHECK( value.Get( enable ) );
353   DALI_TEST_CHECK( !enable );
354
355   // pre-multiplied alpha blending
356   imageView.SetProperty( Toolkit::ImageView::Property::PRE_MULTIPLIED_ALPHA, true );
357   application.SendNotification();
358   application.Render();
359
360   int srcFactorRgb    = renderer.GetProperty<int>( Renderer::Property::BLEND_FACTOR_SRC_RGB );
361   int destFactorRgb   = renderer.GetProperty<int>( Renderer::Property::BLEND_FACTOR_DEST_RGB );
362   int srcFactorAlpha  = renderer.GetProperty<int>( Renderer::Property::BLEND_FACTOR_SRC_ALPHA );
363   int destFactorAlpha = renderer.GetProperty<int>( Renderer::Property::BLEND_FACTOR_DEST_ALPHA );
364   DALI_TEST_CHECK( srcFactorRgb == BlendFactor::ONE );
365   DALI_TEST_CHECK( destFactorRgb == BlendFactor::ONE_MINUS_SRC_ALPHA );
366   DALI_TEST_CHECK( srcFactorAlpha == BlendFactor::ONE );
367   DALI_TEST_CHECK( destFactorAlpha == BlendFactor::ONE );
368
369   value = renderer.GetProperty( Renderer::Property::BLEND_PRE_MULTIPLIED_ALPHA );
370   DALI_TEST_CHECK( value.Get( enable ) );
371   DALI_TEST_CHECK( enable );
372
373   END_TEST;
374 }
375
376 int UtcDaliImageViewPixelArea(void)
377 {
378   // Test pixel area property
379   ToolkitTestApplication application;
380
381   // Gif image, use AnimatedImageVisual internally
382   // Atlasing is applied to pack multiple frames, use custom wrap mode
383   ImageView gifView = ImageView::New();
384   const Vector4 pixelAreaVisual( 0.f, 0.f, 2.f, 2.f );
385   gifView.SetProperty( ImageView::Property::IMAGE,
386                        Property::Map().Add( ImageVisual::Property::URL, TEST_GIF_FILE_NAME )
387                                       .Add( ImageVisual::Property::PIXEL_AREA, pixelAreaVisual ) );
388
389   // Add to stage
390   Stage stage = Stage::GetCurrent();
391   stage.Add( gifView );
392
393   // loading started
394   application.SendNotification();
395   application.Render(16);
396   DALI_TEST_CHECK( gifView.GetRendererCount() == 1u );
397
398   const Vector4 fullTextureRect( 0.f, 0.f, 1.f, 1.f );
399   // test that the pixel area value defined in the visual property map is registered on renderer
400   Renderer renderer = gifView.GetRendererAt(0);
401   Property::Value pixelAreaValue = renderer.GetProperty( renderer.GetPropertyIndex( "pixelArea" ) );
402   DALI_TEST_EQUALS( pixelAreaValue.Get<Vector4>(), pixelAreaVisual, TEST_LOCATION );
403
404   // test that the shader has the default pixel area value registered.
405   Shader shader = renderer.GetShader();
406   pixelAreaValue = shader.GetProperty( shader.GetPropertyIndex( "pixelArea" ) );
407   DALI_TEST_EQUALS( pixelAreaValue.Get<Vector4>(), fullTextureRect, TEST_LOCATION );
408
409   // test that the uniform uses the pixelArea property on the renderer.
410   TestGlAbstraction& gl = application.GetGlAbstraction();
411   Vector4 pixelAreaUniform;
412   DALI_TEST_CHECK( gl.GetUniformValue<Vector4>( "pixelArea", pixelAreaUniform ) );
413   DALI_TEST_EQUALS( pixelAreaVisual, pixelAreaUniform, Math::MACHINE_EPSILON_100, TEST_LOCATION );
414
415   // set the pixelArea property on the control
416   const Vector4 pixelAreaControl( -1.f, -1.f, 3.f, 3.f );
417   gifView.SetProperty( ImageView::Property::PIXEL_AREA, pixelAreaControl );
418   application.SendNotification();
419   application.Render(16);
420
421   // check the pixelArea property on the control
422   pixelAreaValue = gifView.GetProperty( gifView.GetPropertyIndex( "pixelArea" ) );
423   DALI_TEST_EQUALS( pixelAreaValue.Get<Vector4>(), pixelAreaControl, TEST_LOCATION );
424   // test that the uniform uses the pixelArea property on the control.
425   DALI_TEST_CHECK( gl.GetUniformValue<Vector4>( "pixelArea", pixelAreaUniform ) );
426   DALI_TEST_EQUALS( pixelAreaControl, pixelAreaUniform, Math::MACHINE_EPSILON_100, TEST_LOCATION );
427
428
429   END_TEST;
430 }
431
432 int UtcDaliImageViewAsyncLoadingWithoutAltasing(void)
433 {
434   ToolkitTestApplication application;
435   TestGlAbstraction& gl = application.GetGlAbstraction();
436   const std::vector<GLuint>& textures = gl.GetBoundTextures();
437   size_t numTextures = textures.size();
438
439   // Async loading, no atlasing for big size image
440   ImageView imageView = ImageView::New( gImage_600_RGB );
441
442   // By default, Aysnc loading is used
443   Stage::GetCurrent().Add( imageView );
444   imageView.SetSize(100, 100);
445   imageView.SetParentOrigin( ParentOrigin::CENTER );
446
447   DALI_TEST_EQUALS( Test::WaitForEventThreadTrigger( 1 ), true, TEST_LOCATION );
448
449   application.SendNotification();
450   application.Render(16);
451   application.SendNotification();
452
453   const std::vector<GLuint>& textures2 = gl.GetBoundTextures();
454   DALI_TEST_GREATER( textures2.size(), numTextures, TEST_LOCATION );
455
456
457
458   END_TEST;
459 }
460
461 int UtcDaliImageViewAsyncLoadingWithAtlasing(void)
462 {
463   ToolkitTestApplication application;
464
465   //Async loading, automatic atlasing for small size image
466   TraceCallStack& callStack = application.GetGlAbstraction().GetTextureTrace();
467   callStack.Reset();
468   callStack.Enable(true);
469
470   Property::Map imageMap;
471
472   imageMap[ ImageVisual::Property::URL ] = gImage_34_RGBA;
473   imageMap[ ImageVisual::Property::DESIRED_HEIGHT ] = 34;
474   imageMap[ ImageVisual::Property::DESIRED_WIDTH ] = 34;
475   imageMap[ ImageVisual::Property::ATLASING] = true;
476
477   ImageView imageView = ImageView::New();
478   imageView.SetProperty( ImageView::Property::IMAGE, imageMap );
479
480   // By default, Aysnc loading is used
481   // loading is not started if the actor is offStage
482
483   Stage::GetCurrent().Add( imageView );
484   application.SendNotification();
485   application.Render(16);
486   application.Render(16);
487   application.SendNotification();
488
489   // loading started, this waits for the loader thread for max 30 seconds
490   DALI_TEST_EQUALS( Test::WaitForEventThreadTrigger( 1 ), true, TEST_LOCATION );
491
492   application.SendNotification();
493   application.Render(16);
494
495   callStack.Enable(false);
496
497   TraceCallStack::NamedParams params;
498   params["width"] = ToString(34);
499   params["height"] = ToString(34);
500   DALI_TEST_EQUALS( callStack.FindMethodAndParams( "TexSubImage2D", params ), true, TEST_LOCATION );
501
502   END_TEST;
503 }
504
505 int UtcDaliImageViewAsyncLoadingWithAtlasing02(void)
506 {
507   ToolkitTestApplication application;
508
509   //Async loading, automatic atlasing for small size image
510   TraceCallStack& callStack = application.GetGlAbstraction().GetTextureTrace();
511   callStack.Reset();
512   callStack.Enable(true);
513
514   Property::Map asyncLoadingMap;
515   asyncLoadingMap[ "url" ] = gImage_34_RGBA;
516   asyncLoadingMap[ "desiredHeight" ] = 34;
517   asyncLoadingMap[ "desiredWidth" ] = 34;
518   asyncLoadingMap[ "synchronousLoading" ] = false;
519   asyncLoadingMap[ "atlasing" ] = true;
520
521   ImageView imageView = ImageView::New();
522   imageView.SetProperty( ImageView::Property::IMAGE, asyncLoadingMap );
523
524   Stage::GetCurrent().Add( imageView );
525   application.SendNotification();
526   application.Render(16);
527   application.Render(16);
528   application.SendNotification();
529
530   // loading started, this waits for the loader thread for max 30 seconds
531   DALI_TEST_EQUALS( Test::WaitForEventThreadTrigger( 1 ), true, TEST_LOCATION );
532
533   application.SendNotification();
534   application.Render(16);
535
536   callStack.Enable(false);
537
538   TraceCallStack::NamedParams params;
539   params["width"] = ToString(34);
540   params["height"] = ToString(34);
541   DALI_TEST_EQUALS( callStack.FindMethodAndParams( "TexSubImage2D", params ), true, TEST_LOCATION );
542
543   END_TEST;
544 }
545
546 int UtcDaliImageViewSyncLoading(void)
547 {
548   ToolkitTestApplication application;
549
550   tet_infoline("ImageView Testing sync loading and size using index key property map");
551
552   Property::Map syncLoadingMap;
553   syncLoadingMap[ ImageVisual::Property::SYNCHRONOUS_LOADING ] = true;
554   syncLoadingMap[ ImageVisual::Property::ATLASING ] = true;
555
556   // Sync loading, no atlasing for big size image
557   {
558     ImageView imageView = ImageView::New();
559
560     // Sync loading is used
561     syncLoadingMap[ ImageVisual::Property::URL ] = gImage_600_RGB;
562     imageView.SetProperty( ImageView::Property::IMAGE, syncLoadingMap );
563   }
564
565   // Sync loading, automatic atlasing for small size image
566   {
567     TraceCallStack& callStack = application.GetGlAbstraction().GetTextureTrace();
568     callStack.Reset();
569     callStack.Enable(true);
570
571     ImageView imageView = ImageView::New( );
572
573     // Sync loading is used
574     syncLoadingMap[ ImageVisual::Property::URL ] = gImage_34_RGBA;
575     syncLoadingMap[ ImageVisual::Property::DESIRED_HEIGHT ] = 34;
576     syncLoadingMap[ ImageVisual::Property::DESIRED_WIDTH ] = 34;
577     imageView.SetProperty( ImageView::Property::IMAGE, syncLoadingMap );
578
579     Stage::GetCurrent().Add( imageView );
580     application.SendNotification();
581     application.Render(16);
582
583     TraceCallStack::NamedParams params;
584     params["width"] = ToString(34);
585     params["height"] = ToString(34);
586     DALI_TEST_EQUALS( callStack.FindMethodAndParams( "TexSubImage2D", params ),
587                       true, TEST_LOCATION );
588   }
589   END_TEST;
590 }
591
592 int UtcDaliImageViewSyncLoading02(void)
593 {
594   ToolkitTestApplication application;
595
596   tet_infoline("ImageView Testing sync loading and size using string key property map");
597
598   // Sync loading, automatic atlasing for small size image
599   {
600     TraceCallStack& callStack = application.GetGlAbstraction().GetTextureTrace();
601     callStack.Reset();
602     callStack.Enable(true);
603
604     ImageView imageView = ImageView::New( );
605
606     // Sync loading is used
607     Property::Map syncLoadingMap;
608     syncLoadingMap[ "url" ] = gImage_34_RGBA;
609     syncLoadingMap[ "desiredHeight" ] = 34;
610     syncLoadingMap[ "desiredWidth" ] = 34;
611     syncLoadingMap[ "synchronousLoading" ] = true;
612     syncLoadingMap[ "atlasing" ] = true;
613     imageView.SetProperty( ImageView::Property::IMAGE, syncLoadingMap );
614
615     Stage::GetCurrent().Add( imageView );
616     application.SendNotification();
617     application.Render(16);
618
619     TraceCallStack::NamedParams params;
620     params["width"] = ToString(34);
621     params["height"] = ToString(34);
622     DALI_TEST_EQUALS( callStack.FindMethodAndParams( "TexSubImage2D", params ),
623                       true, TEST_LOCATION );
624   }
625   END_TEST;
626 }
627
628 int UtcDaliImageViewAddedTexture(void)
629 {
630   ToolkitTestApplication application;
631
632   tet_infoline("ImageView Testing image view with texture provided manager url");
633
634   ImageView imageView = ImageView::New();
635
636   // empty texture is ok, though pointless from app point of view
637   TextureSet  empty;
638   std::string url = TextureManager::AddTexture(empty);
639   DALI_TEST_CHECK(url.size() > 0u);
640
641   Property::Map propertyMap;
642   propertyMap[ImageVisual::Property::URL] = url;
643   imageView.SetProperty(ImageView::Property::IMAGE, propertyMap);
644
645   Stage::GetCurrent().Add( imageView );
646   application.SendNotification();
647   application.Render();
648
649   END_TEST;
650 }
651
652 int UtcDaliImageViewSizeWithBackground(void)
653 {
654   ToolkitTestApplication application;
655
656   int width = 100;
657   int height = 200;
658   Image image = CreateBufferImage( width, height, Vector4(1.f, 1.f, 1.f, 1.f) );
659   ImageView imageView = ImageView::New();
660   imageView.SetBackgroundImage( image );
661
662   Stage::GetCurrent().Add( imageView );
663   application.SendNotification();
664   application.Render();
665
666   DALI_TEST_EQUALS( imageView.GetCurrentSize().width, (float)width, TEST_LOCATION );
667   DALI_TEST_EQUALS( imageView.GetCurrentSize().height, (float)height, TEST_LOCATION );
668
669   END_TEST;
670 }
671
672 int UtcDaliImageViewSizeWithBackgroundAndImage(void)
673 {
674   ToolkitTestApplication application;
675
676   int widthBackground = 100;
677   int heightBackground = 200;
678   int width = 300;
679   int height = 400;
680   Image imageBackground = CreateBufferImage( widthBackground, heightBackground, Vector4(1.f, 1.f, 1.f, 1.f) );
681   Image image = CreateBufferImage( width, height, Vector4(1.f, 1.f, 1.f, 1.f) );
682
683   ImageView imageView = ImageView::New();
684   imageView.SetBackgroundImage( imageBackground );
685   imageView.SetImage( image );
686
687   Stage::GetCurrent().Add( imageView );
688   application.SendNotification();
689   application.Render();
690
691   DALI_TEST_EQUALS( imageView.GetCurrentSize().width, (float)width, TEST_LOCATION );
692   DALI_TEST_EQUALS( imageView.GetCurrentSize().height, (float)height, TEST_LOCATION );
693
694   END_TEST;
695 }
696
697 int UtcDaliImageViewHeightForWidthBackground(void)
698 {
699   ToolkitTestApplication application;
700
701   int widthBackground = 100;
702   int heightBackground = 200;
703   Image imageBackground = CreateBufferImage( widthBackground, heightBackground, Vector4(1.f, 1.f, 1.f, 1.f) );
704
705   ImageView imageView = ImageView::New();
706   imageView.SetBackgroundImage( imageBackground );
707
708   Stage::GetCurrent().Add( imageView );
709   application.SendNotification();
710   application.Render();
711
712   Control control = Control::DownCast( imageView );
713   DALI_TEST_CHECK( control );
714   DALI_TEST_EQUALS( imageView.GetHeightForWidth( 123.f ), control.GetHeightForWidth( 123.f ), TEST_LOCATION );
715   DALI_TEST_EQUALS( imageView.GetWidthForHeight( 321.f ), control.GetWidthForHeight( 321.f ), TEST_LOCATION );
716
717   END_TEST;
718 }
719
720 int UtcDaliImageViewHeightForWidthBackgroundAndImage(void)
721 {
722   ToolkitTestApplication application;
723
724   int widthBackground = 100;
725   int heightBackground = 200;
726   int width = 300;
727   int height = 400;
728   Image imageBackground = CreateBufferImage( widthBackground, heightBackground, Vector4(1.f, 1.f, 1.f, 1.f) );
729   Image image = CreateBufferImage( width, height, Vector4(1.f, 1.f, 1.f, 1.f) );
730
731   ImageView imageView = ImageView::New();
732   imageView.SetBackgroundImage( imageBackground );
733   imageView.SetImage( image );
734
735   Stage::GetCurrent().Add( imageView );
736   application.SendNotification();
737   application.Render();
738
739   DALI_TEST_EQUALS( imageView.GetHeightForWidth( width ), (float)height, TEST_LOCATION );
740   DALI_TEST_EQUALS( imageView.GetWidthForHeight( height ), (float)width, TEST_LOCATION );
741
742   END_TEST;
743 }
744
745 int UtcDaliImageViewSetBufferImage(void)
746 {
747   ToolkitTestApplication application;
748
749   int width1 = 300;
750   int height1 = 400;
751   BufferImage image1 = CreateBufferImage( width1, height1, Vector4( 1.f, 1.f, 1.f, 1.f ) );
752   ImageView imageView = ImageView::New();
753   imageView.SetImage( image1 );
754
755   TestImage( imageView, image1 );
756
757   int width2 = 600;
758   int height2 = 500;
759   BufferImage image2 = CreateBufferImage( width2, height2, Vector4( 1.f, 1.f, 1.f, 1.f ) );
760   imageView.SetImage( image2 );
761
762   TestImage( imageView, image2 );
763
764   END_TEST;
765 }
766
767 int UtcDaliImageViewSetImageUrl(void)
768 {
769   ToolkitTestApplication application;
770
771   ImageView imageView = ImageView::New();
772   imageView.SetImage( TEST_IMAGE_FILE_NAME );
773   TestUrl( imageView, TEST_IMAGE_FILE_NAME );
774
775
776   imageView.SetImage( TEST_IMAGE_FILE_NAME2 );
777   TestUrl( imageView, TEST_IMAGE_FILE_NAME2 );
778
779   END_TEST;
780 }
781
782 int UtcDaliImageViewSetImageOnstageP(void)
783 {
784   ToolkitTestApplication application;
785
786   ImageView imageView = ImageView::New();
787
788   Stage::GetCurrent().Add( imageView );
789   application.SendNotification();
790   application.Render();
791
792   ResourceImage image1 = ResourceImage::New( TEST_IMAGE_FILE_NAME );
793   imageView.SetImage( image1 );
794   TestImage( imageView, image1 );
795
796   int width = 300;
797   int height = 400;
798   BufferImage image2 = CreateBufferImage( width, height, Vector4( 1.f, 1.f, 1.f, 1.f ) );
799   imageView.SetImage( image2 );
800   TestImage( imageView, image2 );
801
802   END_TEST;
803 }
804
805 int UtcDaliImageViewSetImageOnstageN(void)
806 {
807   ToolkitTestApplication application;
808
809   ImageView imageView = ImageView::New();
810
811   Stage::GetCurrent().Add( imageView );
812   application.SendNotification();
813   application.Render();
814
815   ResourceImage image1 = ResourceImage::New( TEST_IMAGE_FILE_NAME );
816   imageView.SetImage( image1 );
817   TestImage( imageView, image1 );
818
819   Image image2;
820   imageView.SetImage( image2 );
821
822   Property::Value value = imageView.GetProperty( imageView.GetPropertyIndex( "image" ) );
823
824   //the value should be empty
825   std::string url;
826   DALI_TEST_CHECK( !value.Get( url ) );
827
828   Property::Map map;
829   DALI_TEST_CHECK( !value.Get( map ) );
830
831   END_TEST;
832 }
833
834 int UtcDaliImageViewSetImageOffstageP(void)
835 {
836   ToolkitTestApplication application;
837
838   ImageView imageView = ImageView::New();
839
840   Stage::GetCurrent().Add( imageView );
841   application.SendNotification();
842   application.Render();
843   Stage::GetCurrent().Remove( imageView );
844
845   ResourceImage image1 = ResourceImage::New( TEST_IMAGE_FILE_NAME );
846   imageView.SetImage( image1 );
847   TestImage( imageView, image1 );
848
849   int width = 300;
850   int height = 400;
851   BufferImage image2 = CreateBufferImage( width, height, Vector4( 1.f, 1.f, 1.f, 1.f ) );
852   imageView.SetImage( image2 );
853   TestImage( imageView, image2 );
854
855   END_TEST;
856 }
857
858 bool gResourceReadySignalFired = false;
859 Vector3 gNaturalSize;
860
861 void ResourceReadySignal( Control control )
862 {
863   gResourceReadySignalFired = true;
864 }
865
866 int UtcDaliImageViewCheckResourceReady(void)
867 {
868   ToolkitTestApplication application;
869
870   gResourceReadySignalFired = false;
871
872
873   int width = 100;
874   int height = 200;
875   Image image = CreateBufferImage( width, height, Vector4(1.f, 1.f, 1.f, 1.f) );
876
877   // Check ImageView with background and main image, to ensure both visuals are marked as loaded
878   ImageView imageView = ImageView::New( TEST_GIF_FILE_NAME );
879
880   imageView.SetBackgroundImage( image );
881
882   DALI_TEST_EQUALS( imageView.IsResourceReady(), false, TEST_LOCATION );
883
884   imageView.ResourceReadySignal().Connect( &ResourceReadySignal);
885
886   Stage::GetCurrent().Add( imageView );
887
888   application.SendNotification();
889   application.Render(16);
890
891
892   DALI_TEST_EQUALS( imageView.IsResourceReady(), true, TEST_LOCATION );
893
894   DALI_TEST_EQUALS( gResourceReadySignalFired, true, TEST_LOCATION );
895
896   END_TEST;
897 }
898
899 int UtcDaliImageViewSetImageOffstageN(void)
900 {
901   ToolkitTestApplication application;
902
903   ImageView imageView = ImageView::New();
904
905   Stage::GetCurrent().Add( imageView );
906   application.SendNotification();
907   application.Render();
908   Stage::GetCurrent().Remove( imageView );
909
910   ResourceImage image1 = ResourceImage::New( TEST_IMAGE_FILE_NAME );
911   imageView.SetImage( image1 );
912   TestImage( imageView, image1 );
913
914   Image image2;
915   imageView.SetImage( image2 );
916
917   Property::Value value = imageView.GetProperty( imageView.GetPropertyIndex( "image" ) );
918
919   //the value should be empty
920   std::string url;
921   DALI_TEST_CHECK( !value.Get( url ) );
922
923   Property::Map map;
924   DALI_TEST_CHECK( !value.Get( map ) );
925
926   END_TEST;
927 }
928
929 int UtcDaliImageViewSetImageN(void)
930 {
931   ToolkitTestApplication application;
932
933   Image image1;
934   ImageView imageView = ImageView::New();
935   imageView.SetImage( image1 );
936
937   Property::Value value = imageView.GetProperty( imageView.GetPropertyIndex( "image" ) );
938
939   //the value should be empty
940   std::string url;
941   DALI_TEST_CHECK( !value.Get( url ) );
942
943   Property::Map map;
944   DALI_TEST_CHECK( !value.Get( map ) );
945
946   std::string resource_url;
947   Property::Value val = imageView.GetProperty( imageView.GetPropertyIndex( "image" ) );
948   DALI_TEST_CHECK( !val.Get( resource_url ) );
949
950   END_TEST;
951 }
952
953 int UtcDaliImageViewSetImageTypeChangesP(void)
954 {
955   ToolkitTestApplication application;
956
957   ImageView imageView = ImageView::New();
958
959
960   std::string url;
961   Property::Map map;
962
963   Property::Value value = imageView.GetProperty( imageView.GetPropertyIndex( "image" ) );
964   DALI_TEST_CHECK( ! value.Get( url ) ); // Value should be empty
965   DALI_TEST_CHECK( ! value.Get( map ) ); // Value should be empty
966
967   // Set a URL
968   imageView.SetImage( "TEST_URL" );
969   value = imageView.GetProperty( imageView.GetPropertyIndex( "image" ) );
970
971   DALI_TEST_CHECK( value.Get( url ) );   // Value should NOT be empty
972   DALI_TEST_CHECK( ! value.Get( map ) ); // Value should be empty
973
974   // Set an empty Image
975   imageView.SetImage( Image() );
976   value = imageView.GetProperty( imageView.GetPropertyIndex( "image" ) );
977
978   DALI_TEST_CHECK( ! value.Get( url ) ); // Value should be empty
979   DALI_TEST_CHECK( ! value.Get( map ) ); // Value should be empty
980
981   // Set an Image
982   ResourceImage image1 = ResourceImage::New( TEST_IMAGE_FILE_NAME );
983   imageView.SetImage( image1 );
984   value = imageView.GetProperty( imageView.GetPropertyIndex( "image" ) );
985
986   DALI_TEST_CHECK( ! value.Get( url ) ); // Value should be empty
987   DALI_TEST_CHECK( value.Get( map ) );   // Value should NOT be empty
988
989   // Set an empty URL
990   imageView.SetImage( "" );
991   value = imageView.GetProperty( imageView.GetPropertyIndex( "image" ) );
992
993   DALI_TEST_CHECK( ! value.Get( url ) ); // Value should be empty
994   DALI_TEST_CHECK( ! value.Get( map ) ); // Value should be empty
995
996   END_TEST;
997 }
998
999 int UtcDaliImageViewResourceUrlP(void)
1000 {
1001   ToolkitTestApplication application;
1002
1003   ImageView imageView = ImageView::New();
1004   DALI_TEST_CHECK( imageView.GetProperty( ImageView::Property::RESOURCE_URL ).Get< std::string >().empty() );
1005
1006   imageView.SetProperty( ImageView::Property::RESOURCE_URL, "TestString" );
1007   DALI_TEST_EQUALS( imageView.GetProperty( ImageView::Property::RESOURCE_URL ).Get< std::string >(), "TestString", TEST_LOCATION );
1008
1009   END_TEST;
1010 }
1011
1012 // Scenarios 1: ImageView from regular image
1013 int UtcDaliImageViewSetImageBufferImage(void)
1014 {
1015   ToolkitTestApplication application;
1016
1017   ImageView imageView = ImageView::New();
1018   Stage::GetCurrent().Add( imageView );
1019
1020   TestGlAbstraction& gl = application.GetGlAbstraction();
1021   gl.EnableTextureCallTrace( true );
1022
1023   std::vector< GLuint > ids;
1024   ids.push_back( 23 );
1025   application.GetGlAbstraction().SetNextTextureIds( ids );
1026
1027   int width = 300;
1028   int height = 400;
1029   BufferImage image = CreateBufferImage( width, height, Color::WHITE );
1030
1031   imageView.SetImage( image );
1032
1033   application.SendNotification();
1034   application.Render();
1035
1036   DALI_TEST_CHECK( gl.GetTextureTrace().FindMethod("BindTexture") );
1037
1038   std::stringstream params;
1039   params << GL_TEXTURE_2D << ", " << 23;
1040   DALI_TEST_CHECK( gl.GetTextureTrace().FindMethodAndParams("BindTexture", params.str()) );
1041
1042   END_TEST;
1043 }
1044
1045 // Scenarios 2: ImageView from Native image
1046 int UtcDaliImageViewSetImageNativeImage(void)
1047 {
1048   ToolkitTestApplication application;
1049
1050   ImageView imageView = ImageView::New();
1051   Stage::GetCurrent().Add( imageView );
1052
1053   TestGlAbstraction& gl = application.GetGlAbstraction();
1054   gl.EnableTextureCallTrace( true );
1055
1056   std::vector< GLuint > ids;
1057   ids.push_back( 23 );
1058   application.GetGlAbstraction().SetNextTextureIds( ids );
1059
1060   int width = 200;
1061   int height = 500;
1062   TestNativeImagePointer nativeImageInterface = TestNativeImage::New( width, height );
1063   NativeImage nativeImage = NativeImage::New( *(nativeImageInterface.Get()) );
1064
1065   imageView.SetImage( nativeImage );
1066   application.SendNotification();
1067   application.Render();
1068
1069   DALI_TEST_CHECK( gl.GetTextureTrace().FindMethod("BindTexture") );
1070
1071   std::stringstream params;
1072   params << GL_TEXTURE_EXTERNAL_OES << ", " << 23;
1073   DALI_TEST_CHECK( gl.GetTextureTrace().FindMethodAndParams("BindTexture", params.str()) );
1074
1075   END_TEST;
1076 }
1077
1078 // Scenarios 3: ImageView initially from regular image but then SetImage called with Native image
1079 int UtcDaliImageViewSetImageBufferImageToNativeImage(void)
1080 {
1081   ToolkitTestApplication application;
1082
1083   int width = 300;
1084   int height = 400;
1085   BufferImage image = CreateBufferImage( width, height, Color::WHITE );
1086
1087   ImageView imageView = ImageView::New( image );
1088   Stage::GetCurrent().Add( imageView );
1089
1090   TestGlAbstraction& gl = application.GetGlAbstraction();
1091   gl.EnableTextureCallTrace( true );
1092
1093   std::vector< GLuint > ids;
1094   ids.push_back( 23 );
1095   application.GetGlAbstraction().SetNextTextureIds( ids );
1096
1097   application.SendNotification();
1098   application.Render();
1099
1100   DALI_TEST_CHECK( gl.GetTextureTrace().FindMethod("BindTexture") );
1101
1102   std::stringstream params;
1103   params << GL_TEXTURE_2D << ", " << 23;
1104   DALI_TEST_CHECK( gl.GetTextureTrace().FindMethodAndParams("BindTexture", params.str()) );
1105
1106   width = 200;
1107   height = 500;
1108   TestNativeImagePointer nativeImageInterface = TestNativeImage::New( width, height );
1109   NativeImage nativeImage = NativeImage::New( *(nativeImageInterface.Get()) );
1110   imageView.SetImage( nativeImage );
1111
1112   ids.clear();
1113   ids.push_back( 24 );
1114   application.GetGlAbstraction().SetNextTextureIds( ids );
1115
1116   application.SendNotification();
1117   application.Render();
1118
1119   DALI_TEST_CHECK( gl.GetTextureTrace().FindMethod("BindTexture") );
1120
1121   std::stringstream nextTextureParams;
1122   nextTextureParams << GL_TEXTURE_EXTERNAL_OES << ", " << 24;
1123   DALI_TEST_CHECK( gl.GetTextureTrace().FindMethodAndParams("BindTexture", nextTextureParams.str()) );
1124
1125   END_TEST;
1126 }
1127
1128 // Scenarios 4: ImageView initially from Native image but then SetImage called with regular image
1129 int UtcDaliImageViewSetImageNativeImageToBufferImage(void)
1130 {
1131   ToolkitTestApplication application;
1132
1133   int width = 300;
1134   int height = 400;
1135   TestNativeImagePointer nativeImageInterface = TestNativeImage::New( width, height );
1136   NativeImage nativeImage = NativeImage::New( *(nativeImageInterface.Get()) );
1137
1138   ImageView imageView = ImageView::New( nativeImage );
1139   Stage::GetCurrent().Add( imageView );
1140
1141   TestGlAbstraction& gl = application.GetGlAbstraction();
1142   gl.EnableTextureCallTrace( true );
1143
1144   std::vector< GLuint > ids;
1145   ids.push_back( 23 );
1146   application.GetGlAbstraction().SetNextTextureIds( ids );
1147
1148   application.SendNotification();
1149   application.Render();
1150
1151   DALI_TEST_CHECK( gl.GetTextureTrace().FindMethod("BindTexture") );
1152
1153   std::stringstream params;
1154   params << GL_TEXTURE_EXTERNAL_OES << ", " << 23;
1155   DALI_TEST_CHECK( gl.GetTextureTrace().FindMethodAndParams("BindTexture", params.str()) );
1156
1157   width = 200;
1158   height = 500;
1159   BufferImage image = CreateBufferImage( width, height, Color::WHITE );
1160   imageView.SetImage( image );
1161
1162   ids.clear();
1163   ids.push_back( 24 );
1164   application.GetGlAbstraction().SetNextTextureIds( ids );
1165
1166   application.SendNotification();
1167   application.Render();
1168
1169   DALI_TEST_CHECK( gl.GetTextureTrace().FindMethod("BindTexture") );
1170
1171   std::stringstream nextTextureParams;
1172   nextTextureParams << GL_TEXTURE_2D << ", " << 24;
1173   DALI_TEST_CHECK( gl.GetTextureTrace().FindMethodAndParams("BindTexture", nextTextureParams.str()) );
1174
1175   END_TEST;
1176 }
1177
1178 // Scenarios 5: ImageView from Native image with custom shader
1179 int UtcDaliImageViewSetImageNativeImageWithCustomShader(void)
1180 {
1181   ToolkitTestApplication application;
1182
1183   int width = 300;
1184   int height = 400;
1185
1186   Property::Map customShader;
1187   customShader.Insert( "vertexShader", VERTEX_SHADER );
1188   customShader.Insert( "fragmentShader", FRAGMENT_SHADER );
1189
1190   Property::Array shaderHints;
1191   shaderHints.PushBack( "requiresSelfDepthTest" );
1192   shaderHints.PushBack( "outputIsTransparent" );
1193   shaderHints.PushBack( "outputIsOpaque" );
1194   shaderHints.PushBack( "modifiesGeometry" );
1195
1196   customShader.Insert( "hints", shaderHints );
1197
1198   Property::Map map;
1199   map.Insert( "shader", customShader );
1200
1201   TestNativeImagePointer nativeImageInterface = TestNativeImage::New( width, height );
1202   NativeImage nativeImage = NativeImage::New( *(nativeImageInterface.Get()) );
1203
1204   ImageView imageView = ImageView::New( nativeImage );
1205   imageView.SetProperty( ImageView::Property::IMAGE, map );
1206   Stage::GetCurrent().Add( imageView );
1207
1208   TestGlAbstraction& gl = application.GetGlAbstraction();
1209   gl.EnableTextureCallTrace( true );
1210
1211   std::vector< GLuint > ids;
1212   ids.push_back( 23 );
1213   application.GetGlAbstraction().SetNextTextureIds( ids );
1214
1215   application.SendNotification();
1216   application.Render();
1217
1218   DALI_TEST_CHECK( gl.GetTextureTrace().FindMethod("BindTexture") );
1219
1220   std::stringstream params;
1221   params << GL_TEXTURE_EXTERNAL_OES << ", " << 23;
1222   DALI_TEST_CHECK( gl.GetTextureTrace().FindMethodAndParams("BindTexture", params.str()) );
1223
1224   END_TEST;
1225 }
1226
1227 // Scenarios 6: ImageView initially from regular image with custom shader but then SetImage called with Native
1228 int UtcDaliImageViewSetImageBufferImageWithCustomShaderToNativeImage(void)
1229 {
1230   ToolkitTestApplication application;
1231
1232   int width = 300;
1233   int height = 400;
1234
1235   Property::Map customShader;
1236   customShader.Insert( "vertexShader", VERTEX_SHADER );
1237   customShader.Insert( "fragmentShader", FRAGMENT_SHADER );
1238
1239   Property::Array shaderHints;
1240   shaderHints.PushBack( "requiresSelfDepthTest" );
1241   shaderHints.PushBack( "outputIsTransparent" );
1242   shaderHints.PushBack( "outputIsOpaque" );
1243   shaderHints.PushBack( "modifiesGeometry" );
1244
1245   customShader.Insert( "hints", shaderHints );
1246
1247   Property::Map map;
1248   map.Insert( "shader", customShader );
1249
1250   BufferImage image = CreateBufferImage( width, height, Color::WHITE );
1251
1252   ImageView imageView = ImageView::New( image );
1253   imageView.SetProperty( ImageView::Property::IMAGE, map );
1254   Stage::GetCurrent().Add( imageView );
1255
1256   TestGlAbstraction& gl = application.GetGlAbstraction();
1257   gl.EnableTextureCallTrace( true );
1258
1259   std::vector< GLuint > ids;
1260   ids.push_back( 23 );
1261   application.GetGlAbstraction().SetNextTextureIds( ids );
1262
1263   application.SendNotification();
1264   application.Render();
1265
1266   DALI_TEST_CHECK( gl.GetTextureTrace().FindMethod("BindTexture") );
1267
1268   std::stringstream params;
1269   params << GL_TEXTURE_2D << ", " << 23;
1270   DALI_TEST_CHECK( gl.GetTextureTrace().FindMethodAndParams("BindTexture", params.str()) );
1271
1272   TestNativeImagePointer nativeImageInterface = TestNativeImage::New( width, height );
1273   NativeImage nativeImage = NativeImage::New( *(nativeImageInterface.Get()) );
1274   imageView.SetImage( nativeImage );
1275
1276   ids.clear();
1277   ids.push_back( 24 );
1278   application.GetGlAbstraction().SetNextTextureIds( ids );
1279
1280   application.SendNotification();
1281   application.Render();
1282
1283   DALI_TEST_CHECK( gl.GetTextureTrace().FindMethod("BindTexture") );
1284
1285   std::stringstream nativeImageParams;
1286   nativeImageParams << GL_TEXTURE_EXTERNAL_OES << ", " << 24;
1287   DALI_TEST_CHECK( gl.GetTextureTrace().FindMethodAndParams("BindTexture", nativeImageParams.str()) );
1288
1289
1290   END_TEST;
1291 }
1292
1293 int UtcDaliImageViewGetImageP1(void)
1294 {
1295   ToolkitTestApplication application;
1296
1297   ImageView imageView = ImageView::New();
1298   DALI_TEST_CHECK( ! imageView.GetImage() );
1299
1300   Image image = CreateBufferImage();
1301   imageView.SetImage( image );
1302   DALI_TEST_CHECK( imageView.GetImage() == image );
1303
1304   END_TEST;
1305 }
1306
1307 int UtcDaliImageViewGetImageP2(void)
1308 {
1309   ToolkitTestApplication application;
1310
1311   BufferImage image = CreateBufferImage();
1312   ImageView imageView = ImageView::New( image );
1313   DALI_TEST_CHECK( imageView.GetImage() == image );
1314
1315   END_TEST;
1316 }
1317
1318 int UtcDaliImageViewGetImageN(void)
1319 {
1320   ToolkitTestApplication application;
1321
1322   ImageView imageView = ImageView::New( TEST_IMAGE_FILE_NAME );
1323   DALI_TEST_CHECK( ! imageView.GetImage() );
1324
1325   Image image = CreateBufferImage();
1326   imageView.SetImage( image );
1327   DALI_TEST_CHECK( imageView.GetImage() == image );
1328
1329   imageView.SetImage( TEST_IMAGE_FILE_NAME );
1330   DALI_TEST_CHECK( ! imageView.GetImage() );
1331
1332   END_TEST;
1333 }
1334
1335
1336 int UtcDaliImageViewReplaceImage(void)
1337 {
1338   ToolkitTestApplication application;
1339
1340   gResourceReadySignalFired = false;
1341
1342   int width = 100;
1343   int height = 200;
1344   Image image = CreateBufferImage( width, height, Vector4(1.f, 1.f, 1.f, 1.f) );
1345
1346   // Check ImageView with background and main image, to ensure both visuals are marked as loaded
1347   ImageView imageView = ImageView::New( TEST_IMAGE_1 );
1348
1349   DALI_TEST_EQUALS( imageView.IsResourceReady(), false, TEST_LOCATION );
1350
1351   imageView.ResourceReadySignal().Connect( &ResourceReadySignal);
1352
1353   Stage::GetCurrent().Add( imageView );
1354
1355   application.SendNotification();
1356   application.Render(16);
1357
1358   // loading started, this waits for the loader thread for max 30 seconds
1359   DALI_TEST_EQUALS( Test::WaitForEventThreadTrigger( 1 ), true, TEST_LOCATION );
1360
1361   DALI_TEST_EQUALS( imageView.GetRendererCount(), 1u, TEST_LOCATION );
1362
1363   DALI_TEST_EQUALS( gResourceReadySignalFired, true, TEST_LOCATION );
1364
1365   gResourceReadySignalFired = false;
1366
1367   imageView.SetImage(TEST_IMAGE_2);
1368
1369   application.SendNotification();
1370   application.Render(16);
1371
1372   // loading started, this waits for the loader thread for max 30 seconds
1373   DALI_TEST_EQUALS( Test::WaitForEventThreadTrigger( 1 ), true, TEST_LOCATION );
1374
1375   DALI_TEST_EQUALS( imageView.GetRendererCount(), 1u, TEST_LOCATION );
1376
1377   DALI_TEST_EQUALS( imageView.IsResourceReady(), true, TEST_LOCATION );
1378
1379   DALI_TEST_EQUALS( gResourceReadySignalFired, true, TEST_LOCATION );
1380
1381   END_TEST;
1382 }
1383
1384 void OnRelayoutOverride( Size size )
1385 {
1386   gNaturalSize = size; // Size Relayout is using
1387 }
1388
1389 int UtcDaliImageViewReplaceImageAndGetNaturalSize(void)
1390 {
1391   ToolkitTestApplication application;
1392
1393   // Check ImageView with background and main image, to ensure both visuals are marked as loaded
1394   ImageView imageView = ImageView::New( TEST_IMAGE_1 );
1395   imageView.SetResizePolicy( ResizePolicy::USE_NATURAL_SIZE, Dimension::ALL_DIMENSIONS );
1396
1397   DummyControl dummyControl = DummyControl::New( true );
1398   Impl::DummyControl& dummyImpl = static_cast<Impl::DummyControl&>(dummyControl.GetImplementation());
1399   dummyControl.SetResizePolicy( ResizePolicy::FIT_TO_CHILDREN, Dimension::ALL_DIMENSIONS );
1400
1401   dummyControl.Add( imageView );
1402   dummyImpl.SetRelayoutCallback( &OnRelayoutOverride );
1403   Stage::GetCurrent().Add( dummyControl );
1404
1405   application.SendNotification();
1406   application.Render();
1407
1408   // loading started, this waits for the loader thread for max 30 seconds
1409   DALI_TEST_EQUALS( Test::WaitForEventThreadTrigger( 1 ), true, TEST_LOCATION );
1410
1411   DALI_TEST_EQUALS( gNaturalSize.width, 1024.0f, TEST_LOCATION );
1412   DALI_TEST_EQUALS( gNaturalSize.height, 1024.0f, TEST_LOCATION );
1413
1414   gNaturalSize = Vector3::ZERO;
1415
1416   imageView.SetImage(gImage_600_RGB);
1417
1418   // Waiting for resourceReady so SendNotifcation not called here.
1419
1420   // loading started, this waits for the loader thread for max 30 seconds
1421   DALI_TEST_EQUALS( Test::WaitForEventThreadTrigger( 1 ), true, TEST_LOCATION );
1422
1423   // Trigger a potential relayout
1424   application.SendNotification();
1425   application.Render();
1426
1427   DALI_TEST_EQUALS( gNaturalSize.width, 600.0f, TEST_LOCATION );
1428   DALI_TEST_EQUALS( gNaturalSize.height, 600.0f, TEST_LOCATION );
1429
1430   END_TEST;
1431 }