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