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