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