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