Merge "Remove APIs deprecated in Tizen 3.0" 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   ToolkitTestApplication 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   ToolkitTestApplication 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   ToolkitTestApplication 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   ToolkitTestApplication application;
203
204   ImageView imageView;
205
206   DALI_TEST_CHECK( !imageView );
207
208   END_TEST;
209 }
210
211 int UtcDaliImageViewCopyConstructorP(void)
212 {
213   ToolkitTestApplication 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   ToolkitTestApplication 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   ToolkitTestApplication 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   ToolkitTestApplication 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   ImageView imageView = ImageView::New();
869
870   imageView.SetProperty( Control::Property::BACKGROUND,
871                          {
872                            { Toolkit::Visual::Property::TYPE, Toolkit::Visual::IMAGE },
873                            { Toolkit::ImageVisual::Property::URL, TEST_RESOURCE_DIR "/gallery-small-1.jpg" },
874                            { ImageVisual::Property::DESIRED_WIDTH, width },
875                            { ImageVisual::Property::DESIRED_HEIGHT, height },
876                          }
877                        );
878
879   Stage::GetCurrent().Add( imageView );
880   application.SendNotification();
881   application.Render();
882
883   DALI_TEST_EQUALS( imageView.GetCurrentSize().width, (float)width, TEST_LOCATION );
884   DALI_TEST_EQUALS( imageView.GetCurrentSize().height, (float)height, TEST_LOCATION );
885
886   END_TEST;
887 }
888
889 int UtcDaliImageViewSizeWithBackgroundAndImage(void)
890 {
891   ToolkitTestApplication application;
892
893   int widthBackground = 100;
894   int heightBackground = 200;
895   int width = 300;
896   int height = 400;
897   Image image = CreateBufferImage( width, height, Vector4(1.f, 1.f, 1.f, 1.f) );
898
899   ImageView imageView = ImageView::New();
900
901   imageView.SetProperty( Control::Property::BACKGROUND,
902                          {
903                            { Toolkit::Visual::Property::TYPE, Toolkit::Visual::IMAGE },
904                            { Toolkit::ImageVisual::Property::URL, TEST_RESOURCE_DIR "/gallery-small-1.jpg" },
905                            { ImageVisual::Property::DESIRED_WIDTH, widthBackground },
906                            { ImageVisual::Property::DESIRED_HEIGHT, heightBackground },
907                           }
908                        );
909
910   imageView.SetImage( image );
911
912   Stage::GetCurrent().Add( imageView );
913   application.SendNotification();
914   application.Render();
915
916   DALI_TEST_EQUALS( imageView.GetCurrentSize().width, (float)width, TEST_LOCATION );
917   DALI_TEST_EQUALS( imageView.GetCurrentSize().height, (float)height, TEST_LOCATION );
918
919   END_TEST;
920 }
921
922 int UtcDaliImageViewHeightForWidthBackground(void)
923 {
924   ToolkitTestApplication application;
925
926   int widthBackground = 100;
927   int heightBackground = 200;
928
929   ImageView imageView = ImageView::New();
930
931   imageView.SetProperty( Control::Property::BACKGROUND,
932                          {
933                            { Toolkit::Visual::Property::TYPE, Toolkit::Visual::IMAGE },
934                            { Toolkit::ImageVisual::Property::URL, TEST_RESOURCE_DIR "/gallery-small-1.jpg" },
935                            { ImageVisual::Property::DESIRED_WIDTH, widthBackground },
936                            { ImageVisual::Property::DESIRED_HEIGHT, heightBackground }
937                          }
938                        );
939
940   Stage::GetCurrent().Add( imageView );
941   application.SendNotification();
942   application.Render();
943
944   Control control = Control::DownCast( imageView );
945   DALI_TEST_CHECK( control );
946   DALI_TEST_EQUALS( imageView.GetHeightForWidth( 123.f ), control.GetHeightForWidth( 123.f ), TEST_LOCATION );
947   DALI_TEST_EQUALS( imageView.GetWidthForHeight( 321.f ), control.GetWidthForHeight( 321.f ), TEST_LOCATION );
948
949   END_TEST;
950 }
951
952 int UtcDaliImageViewHeightForWidthBackgroundAndImage(void)
953 {
954   ToolkitTestApplication application;
955
956   int widthBackground = 100;
957   int heightBackground = 200;
958   int width = 300;
959   int height = 400;
960
961   Image image = CreateBufferImage( width, height, Vector4(1.f, 1.f, 1.f, 1.f) );
962
963   ImageView imageView = ImageView::New();
964
965   imageView.SetProperty( Control::Property::BACKGROUND,
966                          {
967                            { Toolkit::Visual::Property::TYPE, Toolkit::Visual::IMAGE },
968                            { Toolkit::ImageVisual::Property::URL, TEST_RESOURCE_DIR "/gallery-small-1.jpg" },
969                            { ImageVisual::Property::DESIRED_WIDTH, widthBackground },
970                            { ImageVisual::Property::DESIRED_HEIGHT, heightBackground }
971                          }
972                        );
973
974   imageView.SetImage( image );
975
976   Stage::GetCurrent().Add( imageView );
977   application.SendNotification();
978   application.Render();
979
980   DALI_TEST_EQUALS( imageView.GetHeightForWidth( width ), (float)height, TEST_LOCATION );
981   DALI_TEST_EQUALS( imageView.GetWidthForHeight( height ), (float)width, TEST_LOCATION );
982
983   END_TEST;
984 }
985
986 int UtcDaliImageViewSetBufferImage(void)
987 {
988   ToolkitTestApplication application;
989
990   int width1 = 300;
991   int height1 = 400;
992   BufferImage image1 = CreateBufferImage( width1, height1, Vector4( 1.f, 1.f, 1.f, 1.f ) );
993   ImageView imageView = ImageView::New();
994   imageView.SetImage( image1 );
995
996   TestImage( imageView, image1 );
997
998   int width2 = 600;
999   int height2 = 500;
1000   BufferImage image2 = CreateBufferImage( width2, height2, Vector4( 1.f, 1.f, 1.f, 1.f ) );
1001   imageView.SetImage( image2 );
1002
1003   TestImage( imageView, image2 );
1004
1005   END_TEST;
1006 }
1007
1008 int UtcDaliImageViewSetImageUrl(void)
1009 {
1010   ToolkitTestApplication application;
1011
1012   ImageView imageView = ImageView::New();
1013   imageView.SetImage( TEST_IMAGE_FILE_NAME );
1014   TestUrl( imageView, TEST_IMAGE_FILE_NAME );
1015
1016
1017   imageView.SetImage( TEST_IMAGE_FILE_NAME2 );
1018   TestUrl( imageView, TEST_IMAGE_FILE_NAME2 );
1019
1020   END_TEST;
1021 }
1022
1023 int UtcDaliImageViewSetImageOnstageP(void)
1024 {
1025   ToolkitTestApplication application;
1026
1027   ImageView imageView = ImageView::New();
1028
1029   Stage::GetCurrent().Add( imageView );
1030   application.SendNotification();
1031   application.Render();
1032
1033   ResourceImage image1 = ResourceImage::New( TEST_IMAGE_FILE_NAME );
1034   imageView.SetImage( image1 );
1035   TestImage( imageView, image1 );
1036
1037   int width = 300;
1038   int height = 400;
1039   BufferImage image2 = CreateBufferImage( width, height, Vector4( 1.f, 1.f, 1.f, 1.f ) );
1040   imageView.SetImage( image2 );
1041   TestImage( imageView, image2 );
1042
1043   END_TEST;
1044 }
1045
1046 int UtcDaliImageViewSetImageOnstageN(void)
1047 {
1048   ToolkitTestApplication application;
1049
1050   ImageView imageView = ImageView::New();
1051
1052   Stage::GetCurrent().Add( imageView );
1053   application.SendNotification();
1054   application.Render();
1055
1056   ResourceImage image1 = ResourceImage::New( TEST_IMAGE_FILE_NAME );
1057   imageView.SetImage( image1 );
1058   TestImage( imageView, image1 );
1059
1060   Image image2;
1061   imageView.SetImage( image2 );
1062
1063   Property::Value value = imageView.GetProperty( imageView.GetPropertyIndex( "image" ) );
1064
1065   //the value should be empty
1066   std::string url;
1067   DALI_TEST_CHECK( !value.Get( url ) );
1068
1069   Property::Map map;
1070   value.Get( map );
1071   DALI_TEST_CHECK( map.Empty() );
1072
1073   END_TEST;
1074 }
1075
1076 int UtcDaliImageViewSetImageOffstageP(void)
1077 {
1078   ToolkitTestApplication application;
1079
1080   ImageView imageView = ImageView::New();
1081
1082   Stage::GetCurrent().Add( imageView );
1083   application.SendNotification();
1084   application.Render();
1085   Stage::GetCurrent().Remove( imageView );
1086
1087   ResourceImage image1 = ResourceImage::New( TEST_IMAGE_FILE_NAME );
1088   imageView.SetImage( image1 );
1089   TestImage( imageView, image1 );
1090
1091   int width = 300;
1092   int height = 400;
1093   BufferImage image2 = CreateBufferImage( width, height, Vector4( 1.f, 1.f, 1.f, 1.f ) );
1094   imageView.SetImage( image2 );
1095   TestImage( imageView, image2 );
1096
1097   END_TEST;
1098 }
1099
1100 bool gResourceReadySignalFired = false;
1101 Vector3 gNaturalSize;
1102
1103 void ResourceReadySignal( Control control )
1104 {
1105   gResourceReadySignalFired = true;
1106 }
1107
1108 int UtcDaliImageViewCheckResourceReady(void)
1109 {
1110   ToolkitTestApplication application;
1111
1112   gResourceReadySignalFired = false;
1113
1114   // Check ImageView with background and main image, to ensure both visuals are marked as loaded
1115   ImageView imageView = ImageView::New( TEST_GIF_FILE_NAME );
1116
1117   imageView.SetProperty( Control::Property::BACKGROUND,
1118                          {
1119                            { Toolkit::Visual::Property::TYPE, Toolkit::Visual::IMAGE },
1120                            { Toolkit::ImageVisual::Property::URL, TEST_RESOURCE_DIR "/gallery-small-1.jpg" },
1121                            { ImageVisual::Property::DESIRED_WIDTH, 100 },
1122                            { ImageVisual::Property::DESIRED_HEIGHT, 200 }
1123                           }
1124                        );
1125
1126   DALI_TEST_EQUALS( imageView.IsResourceReady(), false, TEST_LOCATION );
1127
1128   imageView.ResourceReadySignal().Connect( &ResourceReadySignal);
1129
1130   Stage::GetCurrent().Add( imageView );
1131
1132   // loading started, this waits for the loader thread
1133   DALI_TEST_EQUALS( Test::WaitForEventThreadTrigger( 1 ), true, TEST_LOCATION );
1134
1135   application.SendNotification();
1136   application.Render(16);
1137
1138   DALI_TEST_EQUALS( imageView.IsResourceReady(), true, TEST_LOCATION );
1139
1140   DALI_TEST_EQUALS( gResourceReadySignalFired, true, TEST_LOCATION );
1141
1142   END_TEST;
1143 }
1144
1145 int UtcDaliImageViewSetImageOffstageN(void)
1146 {
1147   ToolkitTestApplication application;
1148
1149   ImageView imageView = ImageView::New();
1150
1151   Stage::GetCurrent().Add( imageView );
1152   application.SendNotification();
1153   application.Render();
1154   Stage::GetCurrent().Remove( imageView );
1155
1156   ResourceImage image1 = ResourceImage::New( TEST_IMAGE_FILE_NAME );
1157   imageView.SetImage( image1 );
1158   TestImage( imageView, image1 );
1159
1160   Image image2;
1161   imageView.SetImage( image2 );
1162
1163   Property::Value value = imageView.GetProperty( imageView.GetPropertyIndex( "image" ) );
1164
1165   //the value should be empty
1166   std::string url;
1167   DALI_TEST_CHECK( !value.Get( url ) );
1168
1169   Property::Map map;
1170   value.Get( map );
1171   DALI_TEST_CHECK( map.Empty() );
1172
1173   END_TEST;
1174 }
1175
1176 int UtcDaliImageViewSetImageN(void)
1177 {
1178   ToolkitTestApplication application;
1179
1180   Image image1;
1181   ImageView imageView = ImageView::New();
1182   imageView.SetImage( image1 );
1183
1184   Property::Value value = imageView.GetProperty( imageView.GetPropertyIndex( "image" ) );
1185
1186   //the value should be empty
1187   std::string url;
1188   DALI_TEST_CHECK( !value.Get( url ) );
1189
1190   Property::Map map;
1191   value.Get( map );
1192   DALI_TEST_CHECK( map.Empty() );
1193
1194   std::string resource_url;
1195   Property::Value val = imageView.GetProperty( imageView.GetPropertyIndex( "image" ) );
1196   DALI_TEST_CHECK( !val.Get( resource_url ) );
1197
1198   END_TEST;
1199 }
1200
1201 int UtcDaliImageViewSetImageTypeChangesP(void)
1202 {
1203   ToolkitTestApplication application;
1204
1205   ImageView imageView = ImageView::New();
1206   Toolkit::Internal::Control& controlImpl = Toolkit::Internal::GetImplementation( imageView );
1207
1208   Stage::GetCurrent().Add( imageView );
1209
1210   std::string url;
1211   Property::Map map;
1212   Toolkit::Visual::Base visual;
1213
1214   Property::Value value = imageView.GetProperty( imageView.GetPropertyIndex( "image" ) );
1215   visual = DevelControl::GetVisual( controlImpl, ImageView::Property::IMAGE );
1216
1217   application.SendNotification();
1218   application.Render( 16 );
1219
1220   DALI_TEST_CHECK( ! value.Get( url ) ); // Value should be empty
1221   value.Get( map );
1222   DALI_TEST_CHECK( map.Empty() );        // Value should be empty
1223   DALI_TEST_CHECK( ! visual );           // Visual should be invalid
1224
1225   // Set a URL
1226   imageView.SetImage( "TEST_URL" );
1227
1228   application.SendNotification();
1229   application.Render( 16 );
1230
1231   value = imageView.GetProperty( imageView.GetPropertyIndex( "image" ) );
1232   visual = DevelControl::GetVisual( controlImpl, ImageView::Property::IMAGE );
1233
1234   DALI_TEST_CHECK( value.Get( url ) );   // Value should NOT be empty
1235   DALI_TEST_CHECK( ! value.Get( map ) ); // Value should be empty
1236   DALI_TEST_CHECK( visual );             // Visual should be valid
1237
1238   // Set an empty Image
1239   imageView.SetImage( Image() );
1240
1241   application.SendNotification();
1242   application.Render( 16 );
1243
1244   value = imageView.GetProperty( imageView.GetPropertyIndex( "image" ) );
1245   visual = DevelControl::GetVisual( controlImpl, ImageView::Property::IMAGE );
1246
1247   DALI_TEST_CHECK( ! value.Get( url ) ); // Value should be empty
1248   value.Get( map );
1249   DALI_TEST_CHECK( map.Empty() );        // Value should be empty
1250   DALI_TEST_CHECK( ! visual );           // Visual should be invalid
1251
1252   // Set an Image
1253   ResourceImage image1 = ResourceImage::New( TEST_IMAGE_FILE_NAME );
1254   imageView.SetImage( image1 );
1255
1256   application.SendNotification();
1257   application.Render( 16 );
1258
1259   value = imageView.GetProperty( imageView.GetPropertyIndex( "image" ) );
1260   visual = DevelControl::GetVisual( controlImpl, ImageView::Property::IMAGE );
1261
1262   DALI_TEST_CHECK( ! value.Get( url ) ); // Value should be empty
1263   DALI_TEST_CHECK( value.Get( map ) );   // Value should NOT be empty
1264   DALI_TEST_CHECK( visual );             // Visual should be valid
1265
1266   // Set an empty URL
1267   imageView.SetImage( "" );
1268
1269   application.SendNotification();
1270   application.Render( 16 );
1271
1272   value = imageView.GetProperty( imageView.GetPropertyIndex( "image" ) );
1273   visual = DevelControl::GetVisual( controlImpl, ImageView::Property::IMAGE );
1274
1275   DALI_TEST_CHECK( ! value.Get( url ) ); // Value should be empty
1276   value.Get( map );
1277   DALI_TEST_CHECK( map.Empty() );        // Value should be empty
1278   DALI_TEST_CHECK( ! visual );           // Visual should be invalid
1279
1280   // Set a URL in property map
1281   Property::Map propertyMap;
1282   propertyMap[ImageVisual::Property::URL] = TEST_IMAGE_FILE_NAME;
1283   imageView.SetProperty( ImageView::Property::IMAGE, propertyMap );
1284
1285   application.SendNotification();
1286   application.Render( 16 );
1287
1288   value = imageView.GetProperty( imageView.GetPropertyIndex( "image" ) );
1289   visual = DevelControl::GetVisual( controlImpl, ImageView::Property::IMAGE );
1290
1291   DALI_TEST_CHECK( ! value.Get( url ) ); // Value should be empty
1292   DALI_TEST_CHECK( value.Get( map ) );   // Value should NOT be empty
1293   DALI_TEST_CHECK( visual );             // Visual should be valid
1294
1295   // Set a URL in property map again
1296   propertyMap[ImageVisual::Property::URL] = gImage_34_RGBA;
1297   imageView.SetProperty( ImageView::Property::IMAGE, propertyMap );
1298
1299   application.SendNotification();
1300   application.Render( 16 );
1301
1302   value = imageView.GetProperty( imageView.GetPropertyIndex( "image" ) );
1303   visual = DevelControl::GetVisual( controlImpl, ImageView::Property::IMAGE );
1304
1305   DALI_TEST_CHECK( ! value.Get( url ) ); // Value should be empty
1306   DALI_TEST_CHECK( value.Get( map ) );   // Value should NOT be empty
1307   DALI_TEST_CHECK( visual );             // Visual should be valid
1308
1309   // Set an empty URL in property map
1310   propertyMap[ImageVisual::Property::URL] = std::string();
1311   imageView.SetProperty( ImageView::Property::IMAGE, propertyMap );
1312
1313   application.SendNotification();
1314   application.Render( 16 );
1315
1316   value = imageView.GetProperty( imageView.GetPropertyIndex( "image" ) );
1317   visual = DevelControl::GetVisual( controlImpl, ImageView::Property::IMAGE );
1318
1319   DALI_TEST_CHECK( ! value.Get( url ) ); // Value should be empty
1320   DALI_TEST_CHECK( value.Get( map ) );   // Value should NOT be empty
1321   DALI_TEST_CHECK( ! visual );           // Visual should be invalid
1322
1323   END_TEST;
1324 }
1325
1326 int UtcDaliImageViewResourceUrlP(void)
1327 {
1328   ToolkitTestApplication application;
1329
1330   ImageView imageView = ImageView::New();
1331   DALI_TEST_CHECK( imageView.GetProperty( ImageView::Property::IMAGE ).Get< std::string >().empty() );
1332
1333   imageView.SetProperty( ImageView::Property::IMAGE, "TestString" );
1334   DALI_TEST_EQUALS( imageView.GetProperty( ImageView::Property::IMAGE ).Get< std::string >(), "TestString", TEST_LOCATION );
1335
1336   END_TEST;
1337 }
1338
1339 // Scenarios 1: ImageView from regular image
1340 int UtcDaliImageViewSetImageBufferImage(void)
1341 {
1342   ToolkitTestApplication application;
1343
1344   ImageView imageView = ImageView::New();
1345   Stage::GetCurrent().Add( imageView );
1346
1347   TestGlAbstraction& gl = application.GetGlAbstraction();
1348   gl.EnableTextureCallTrace( true );
1349
1350   std::vector< GLuint > ids;
1351   ids.push_back( 23 );
1352   application.GetGlAbstraction().SetNextTextureIds( ids );
1353
1354   int width = 300;
1355   int height = 400;
1356   BufferImage image = CreateBufferImage( width, height, Color::WHITE );
1357
1358   imageView.SetImage( image );
1359
1360   application.SendNotification();
1361   application.Render();
1362
1363   DALI_TEST_CHECK( gl.GetTextureTrace().FindMethod("BindTexture") );
1364
1365   std::stringstream params;
1366   params << GL_TEXTURE_2D << ", " << 23;
1367   DALI_TEST_CHECK( gl.GetTextureTrace().FindMethodAndParams("BindTexture", params.str()) );
1368
1369   END_TEST;
1370 }
1371
1372 // Scenarios 2: ImageView from Native image
1373 int UtcDaliImageViewSetImageNativeImage(void)
1374 {
1375   ToolkitTestApplication application;
1376
1377   ImageView imageView = ImageView::New();
1378   Stage::GetCurrent().Add( imageView );
1379
1380   TestGlAbstraction& gl = application.GetGlAbstraction();
1381   gl.EnableTextureCallTrace( true );
1382
1383   std::vector< GLuint > ids;
1384   ids.push_back( 23 );
1385   application.GetGlAbstraction().SetNextTextureIds( ids );
1386
1387   int width = 200;
1388   int height = 500;
1389   TestNativeImagePointer nativeImageInterface = TestNativeImage::New( width, height );
1390   NativeImage nativeImage = NativeImage::New( *(nativeImageInterface.Get()) );
1391
1392   imageView.SetImage( nativeImage );
1393   application.SendNotification();
1394   application.Render();
1395
1396   DALI_TEST_CHECK( gl.GetTextureTrace().FindMethod("BindTexture") );
1397
1398   std::stringstream params;
1399   params << GL_TEXTURE_EXTERNAL_OES << ", " << 23;
1400   DALI_TEST_CHECK( gl.GetTextureTrace().FindMethodAndParams("BindTexture", params.str()) );
1401
1402   END_TEST;
1403 }
1404
1405 // Scenarios 3: ImageView initially from regular image but then SetImage called with Native image
1406 int UtcDaliImageViewSetImageBufferImageToNativeImage(void)
1407 {
1408   ToolkitTestApplication application;
1409
1410   int width = 300;
1411   int height = 400;
1412   BufferImage image = CreateBufferImage( width, height, Color::WHITE );
1413
1414   ImageView imageView = ImageView::New( image );
1415   Stage::GetCurrent().Add( imageView );
1416
1417   TestGlAbstraction& gl = application.GetGlAbstraction();
1418   gl.EnableTextureCallTrace( true );
1419
1420   std::vector< GLuint > ids;
1421   ids.push_back( 23 );
1422   application.GetGlAbstraction().SetNextTextureIds( ids );
1423
1424   application.SendNotification();
1425   application.Render();
1426
1427   DALI_TEST_CHECK( gl.GetTextureTrace().FindMethod("BindTexture") );
1428
1429   std::stringstream params;
1430   params << GL_TEXTURE_2D << ", " << 23;
1431   DALI_TEST_CHECK( gl.GetTextureTrace().FindMethodAndParams("BindTexture", params.str()) );
1432
1433   width = 200;
1434   height = 500;
1435   TestNativeImagePointer nativeImageInterface = TestNativeImage::New( width, height );
1436   NativeImage nativeImage = NativeImage::New( *(nativeImageInterface.Get()) );
1437   imageView.SetImage( nativeImage );
1438
1439   ids.clear();
1440   ids.push_back( 24 );
1441   application.GetGlAbstraction().SetNextTextureIds( ids );
1442
1443   application.SendNotification();
1444   application.Render();
1445
1446   DALI_TEST_CHECK( gl.GetTextureTrace().FindMethod("BindTexture") );
1447
1448   std::stringstream nextTextureParams;
1449   nextTextureParams << GL_TEXTURE_EXTERNAL_OES << ", " << 24;
1450   DALI_TEST_CHECK( gl.GetTextureTrace().FindMethodAndParams("BindTexture", nextTextureParams.str()) );
1451
1452   END_TEST;
1453 }
1454
1455 // Scenarios 4: ImageView initially from Native image but then SetImage called with regular image
1456 int UtcDaliImageViewSetImageNativeImageToBufferImage(void)
1457 {
1458   ToolkitTestApplication application;
1459
1460   int width = 300;
1461   int height = 400;
1462   TestNativeImagePointer nativeImageInterface = TestNativeImage::New( width, height );
1463   NativeImage nativeImage = NativeImage::New( *(nativeImageInterface.Get()) );
1464
1465   ImageView imageView = ImageView::New( nativeImage );
1466   Stage::GetCurrent().Add( imageView );
1467
1468   TestGlAbstraction& gl = application.GetGlAbstraction();
1469   gl.EnableTextureCallTrace( true );
1470
1471   std::vector< GLuint > ids;
1472   ids.push_back( 23 );
1473   application.GetGlAbstraction().SetNextTextureIds( ids );
1474
1475   application.SendNotification();
1476   application.Render();
1477
1478   DALI_TEST_CHECK( gl.GetTextureTrace().FindMethod("BindTexture") );
1479
1480   std::stringstream params;
1481   params << GL_TEXTURE_EXTERNAL_OES << ", " << 23;
1482   DALI_TEST_CHECK( gl.GetTextureTrace().FindMethodAndParams("BindTexture", params.str()) );
1483
1484   width = 200;
1485   height = 500;
1486   BufferImage image = CreateBufferImage( width, height, Color::WHITE );
1487   imageView.SetImage( image );
1488
1489   ids.clear();
1490   ids.push_back( 24 );
1491   application.GetGlAbstraction().SetNextTextureIds( ids );
1492
1493   application.SendNotification();
1494   application.Render();
1495
1496   DALI_TEST_CHECK( gl.GetTextureTrace().FindMethod("BindTexture") );
1497
1498   std::stringstream nextTextureParams;
1499   nextTextureParams << GL_TEXTURE_2D << ", " << 24;
1500   DALI_TEST_CHECK( gl.GetTextureTrace().FindMethodAndParams("BindTexture", nextTextureParams.str()) );
1501
1502   END_TEST;
1503 }
1504
1505 // Scenarios 5: ImageView from Native image with custom shader
1506 int UtcDaliImageViewSetImageNativeImageWithCustomShader(void)
1507 {
1508   ToolkitTestApplication application;
1509
1510   int width = 300;
1511   int height = 400;
1512
1513   Property::Map customShader;
1514   customShader.Insert( "vertexShader", VERTEX_SHADER );
1515   customShader.Insert( "fragmentShader", FRAGMENT_SHADER );
1516
1517   Property::Array shaderHints;
1518   shaderHints.PushBack( "requiresSelfDepthTest" );
1519   shaderHints.PushBack( "outputIsTransparent" );
1520   shaderHints.PushBack( "outputIsOpaque" );
1521   shaderHints.PushBack( "modifiesGeometry" );
1522
1523   customShader.Insert( "hints", shaderHints );
1524
1525   Property::Map map;
1526   map.Insert( "shader", customShader );
1527
1528   TestNativeImagePointer nativeImageInterface = TestNativeImage::New( width, height );
1529   NativeImage nativeImage = NativeImage::New( *(nativeImageInterface.Get()) );
1530
1531   ImageView imageView = ImageView::New( nativeImage );
1532   imageView.SetProperty( ImageView::Property::IMAGE, map );
1533   Stage::GetCurrent().Add( imageView );
1534
1535   TestGlAbstraction& gl = application.GetGlAbstraction();
1536   gl.EnableTextureCallTrace( true );
1537
1538   std::vector< GLuint > ids;
1539   ids.push_back( 23 );
1540   application.GetGlAbstraction().SetNextTextureIds( ids );
1541
1542   application.SendNotification();
1543   application.Render();
1544
1545   DALI_TEST_CHECK( gl.GetTextureTrace().FindMethod("BindTexture") );
1546
1547   std::stringstream params;
1548   params << GL_TEXTURE_EXTERNAL_OES << ", " << 23;
1549   DALI_TEST_CHECK( gl.GetTextureTrace().FindMethodAndParams("BindTexture", params.str()) );
1550
1551   END_TEST;
1552 }
1553
1554 // Scenarios 6: ImageView initially from regular image with custom shader but then SetImage called with Native
1555 int UtcDaliImageViewSetImageBufferImageWithCustomShaderToNativeImage(void)
1556 {
1557   ToolkitTestApplication application;
1558
1559   int width = 300;
1560   int height = 400;
1561
1562   Property::Map customShader;
1563   customShader.Insert( "vertexShader", VERTEX_SHADER );
1564   customShader.Insert( "fragmentShader", FRAGMENT_SHADER );
1565
1566   Property::Array shaderHints;
1567   shaderHints.PushBack( "requiresSelfDepthTest" );
1568   shaderHints.PushBack( "outputIsTransparent" );
1569   shaderHints.PushBack( "outputIsOpaque" );
1570   shaderHints.PushBack( "modifiesGeometry" );
1571
1572   customShader.Insert( "hints", shaderHints );
1573
1574   Property::Map map;
1575   map.Insert( "shader", customShader );
1576
1577   BufferImage image = CreateBufferImage( width, height, Color::WHITE );
1578
1579   ImageView imageView = ImageView::New( image );
1580   imageView.SetProperty( ImageView::Property::IMAGE, map );
1581   Stage::GetCurrent().Add( imageView );
1582
1583   TestGlAbstraction& gl = application.GetGlAbstraction();
1584   gl.EnableTextureCallTrace( true );
1585
1586   std::vector< GLuint > ids;
1587   ids.push_back( 23 );
1588   application.GetGlAbstraction().SetNextTextureIds( ids );
1589
1590   application.SendNotification();
1591   application.Render();
1592
1593   DALI_TEST_CHECK( gl.GetTextureTrace().FindMethod("BindTexture") );
1594
1595   std::stringstream params;
1596   params << GL_TEXTURE_2D << ", " << 23;
1597   DALI_TEST_CHECK( gl.GetTextureTrace().FindMethodAndParams("BindTexture", params.str()) );
1598
1599   TestNativeImagePointer nativeImageInterface = TestNativeImage::New( width, height );
1600   NativeImage nativeImage = NativeImage::New( *(nativeImageInterface.Get()) );
1601   imageView.SetImage( nativeImage );
1602
1603   ids.clear();
1604   ids.push_back( 24 );
1605   application.GetGlAbstraction().SetNextTextureIds( ids );
1606
1607   application.SendNotification();
1608   application.Render();
1609
1610   DALI_TEST_CHECK( gl.GetTextureTrace().FindMethod("BindTexture") );
1611
1612   std::stringstream nativeImageParams;
1613   nativeImageParams << GL_TEXTURE_EXTERNAL_OES << ", " << 24;
1614   DALI_TEST_CHECK( gl.GetTextureTrace().FindMethodAndParams("BindTexture", nativeImageParams.str()) );
1615
1616
1617   END_TEST;
1618 }
1619
1620 int UtcDaliImageViewGetImageP1(void)
1621 {
1622   ToolkitTestApplication application;
1623
1624   ImageView imageView = ImageView::New();
1625   DALI_TEST_CHECK( ! imageView.GetImage() );
1626
1627   Image image = CreateBufferImage();
1628   imageView.SetImage( image );
1629   DALI_TEST_CHECK( imageView.GetImage() == image );
1630
1631   END_TEST;
1632 }
1633
1634 int UtcDaliImageViewGetImageP2(void)
1635 {
1636   ToolkitTestApplication application;
1637
1638   BufferImage image = CreateBufferImage();
1639   ImageView imageView = ImageView::New( image );
1640   DALI_TEST_CHECK( imageView.GetImage() == image );
1641
1642   END_TEST;
1643 }
1644
1645 int UtcDaliImageViewGetImageN(void)
1646 {
1647   ToolkitTestApplication application;
1648
1649   ImageView imageView = ImageView::New( TEST_IMAGE_FILE_NAME );
1650   DALI_TEST_CHECK( ! imageView.GetImage() );
1651
1652   Image image = CreateBufferImage();
1653   imageView.SetImage( image );
1654   DALI_TEST_CHECK( imageView.GetImage() == image );
1655
1656   imageView.SetImage( TEST_IMAGE_FILE_NAME );
1657   DALI_TEST_CHECK( ! imageView.GetImage() );
1658
1659   END_TEST;
1660 }
1661
1662
1663 int UtcDaliImageViewReplaceImage(void)
1664 {
1665   ToolkitTestApplication application;
1666
1667   gResourceReadySignalFired = false;
1668
1669   int width = 100;
1670   int height = 200;
1671   Image image = CreateBufferImage( width, height, Vector4(1.f, 1.f, 1.f, 1.f) );
1672
1673   // Check ImageView with background and main image, to ensure both visuals are marked as loaded
1674   ImageView imageView = ImageView::New( TEST_IMAGE_1 );
1675
1676   DALI_TEST_EQUALS( imageView.IsResourceReady(), false, TEST_LOCATION );
1677
1678   imageView.ResourceReadySignal().Connect( &ResourceReadySignal);
1679
1680   Stage::GetCurrent().Add( imageView );
1681
1682   application.SendNotification();
1683   application.Render(16);
1684
1685   // loading started, this waits for the loader thread for max 30 seconds
1686   DALI_TEST_EQUALS( Test::WaitForEventThreadTrigger( 1 ), true, TEST_LOCATION );
1687
1688   DALI_TEST_EQUALS( imageView.GetRendererCount(), 1u, TEST_LOCATION );
1689
1690   DALI_TEST_EQUALS( gResourceReadySignalFired, true, TEST_LOCATION );
1691
1692   gResourceReadySignalFired = false;
1693
1694   imageView.SetImage(TEST_IMAGE_2);
1695
1696   application.SendNotification();
1697   application.Render(16);
1698
1699   // loading started, this waits for the loader thread for max 30 seconds
1700   DALI_TEST_EQUALS( Test::WaitForEventThreadTrigger( 1 ), true, TEST_LOCATION );
1701
1702   DALI_TEST_EQUALS( imageView.GetRendererCount(), 1u, TEST_LOCATION );
1703
1704   DALI_TEST_EQUALS( imageView.IsResourceReady(), true, TEST_LOCATION );
1705
1706   DALI_TEST_EQUALS( gResourceReadySignalFired, true, TEST_LOCATION );
1707
1708   END_TEST;
1709 }
1710
1711 void OnRelayoutOverride( Size size )
1712 {
1713   gNaturalSize = size; // Size Relayout is using
1714 }
1715
1716 int UtcDaliImageViewReplaceImageAndGetNaturalSize(void)
1717 {
1718   ToolkitTestApplication application;
1719
1720   // Check ImageView with background and main image, to ensure both visuals are marked as loaded
1721   ImageView imageView = ImageView::New( TEST_IMAGE_1 );
1722   imageView.SetResizePolicy( ResizePolicy::USE_NATURAL_SIZE, Dimension::ALL_DIMENSIONS );
1723
1724   DummyControl dummyControl = DummyControl::New( true );
1725   Impl::DummyControl& dummyImpl = static_cast<Impl::DummyControl&>(dummyControl.GetImplementation());
1726   dummyControl.SetResizePolicy( ResizePolicy::FIT_TO_CHILDREN, Dimension::ALL_DIMENSIONS );
1727
1728   dummyControl.Add( imageView );
1729   dummyImpl.SetRelayoutCallback( &OnRelayoutOverride );
1730   Stage::GetCurrent().Add( dummyControl );
1731
1732   application.SendNotification();
1733   application.Render();
1734
1735   // loading started, this waits for the loader thread for max 30 seconds
1736   DALI_TEST_EQUALS( Test::WaitForEventThreadTrigger( 1 ), true, TEST_LOCATION );
1737
1738   DALI_TEST_EQUALS( gNaturalSize.width, 1024.0f, TEST_LOCATION );
1739   DALI_TEST_EQUALS( gNaturalSize.height, 1024.0f, TEST_LOCATION );
1740
1741   gNaturalSize = Vector3::ZERO;
1742
1743   imageView.SetImage(gImage_600_RGB);
1744
1745   // Waiting for resourceReady so SendNotifcation not called here.
1746
1747   // loading started, this waits for the loader thread for max 30 seconds
1748   DALI_TEST_EQUALS( Test::WaitForEventThreadTrigger( 1 ), true, TEST_LOCATION );
1749
1750   // Trigger a potential relayout
1751   application.SendNotification();
1752   application.Render();
1753
1754   DALI_TEST_EQUALS( gNaturalSize.width, 600.0f, TEST_LOCATION );
1755   DALI_TEST_EQUALS( gNaturalSize.height, 600.0f, TEST_LOCATION );
1756
1757   END_TEST;
1758 }
1759
1760 int UtcDaliImageViewResourceReadySignalWithImmediateLoad(void)
1761 {
1762   tet_infoline("Test Setting Image with IMMEDIATE load and receving ResourceReadySignal before staged.");
1763
1764   ToolkitTestApplication application;
1765
1766   gResourceReadySignalFired = false;
1767
1768   Property::Map imageMap;
1769
1770   imageMap[ ImageVisual::Property::URL ] = gImage_34_RGBA;
1771   imageMap[ ImageVisual::Property::LOAD_POLICY ] =  ImageVisual::LoadPolicy::IMMEDIATE;
1772
1773   tet_infoline("Creating ImageView without URL so image does not start loading");
1774   ImageView imageView = ImageView::New();
1775   tet_infoline("Connect to image loaded signal before setting image");
1776   imageView.ResourceReadySignal().Connect( &ResourceReadySignal);
1777   tet_infoline("Setting Image with IMMEDIATE load, signal already connected so will be triggered.");
1778   imageView.SetProperty( ImageView::Property::IMAGE, imageMap );
1779
1780   // loading started, this waits for the loader thread
1781   DALI_TEST_EQUALS( Test::WaitForEventThreadTrigger( 1 ), true, TEST_LOCATION );
1782
1783   application.SendNotification();
1784   application.Render(16);
1785
1786   DALI_TEST_EQUALS( gResourceReadySignalFired, true, TEST_LOCATION );
1787
1788   END_TEST;
1789 }
1790
1791 int UtcDaliImageViewResourceReadySignalWithReusedImage(void)
1792 {
1793   tet_infoline("Test Setting Image that was already loaded by another ImageView and still getting ResourceReadySignal.");
1794
1795   ToolkitTestApplication application;
1796
1797   gResourceReadySignalFired = false;
1798
1799   Property::Map imageMap;
1800
1801   imageMap[ ImageVisual::Property::URL ] = gImage_34_RGBA;
1802   imageMap[ ImageVisual::Property::LOAD_POLICY ] =  ImageVisual::LoadPolicy::IMMEDIATE;
1803
1804   ImageView imageView = ImageView::New();
1805   imageView.ResourceReadySignal().Connect( &ResourceReadySignal);
1806   imageView.SetProperty( ImageView::Property::IMAGE, imageMap );
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   DALI_TEST_EQUALS( gResourceReadySignalFired, true, TEST_LOCATION );
1815   gResourceReadySignalFired = false;
1816
1817   ImageView imageViewWithExistingImage = ImageView::New();
1818   imageViewWithExistingImage.ResourceReadySignal().Connect( &ResourceReadySignal);
1819   imageViewWithExistingImage.SetProperty( ImageView::Property::IMAGE, imageMap );
1820
1821   DALI_TEST_EQUALS( gResourceReadySignalFired, true, TEST_LOCATION );
1822
1823   END_TEST;
1824 }
1825
1826 int UtcDaliImageViewResourceReadySignalWithReusedImage02(void)
1827 {
1828   tet_infoline("Test Setting Image that was already loaded by another ImageView and still getting ResourceReadySignal when staged.");
1829
1830   ToolkitTestApplication application;
1831
1832   gResourceReadySignalFired = false;
1833
1834   Property::Map imageImmediateLoadingMap;
1835   imageImmediateLoadingMap[ ImageVisual::Property::URL ] = gImage_34_RGBA;
1836   imageImmediateLoadingMap[ ImageVisual::Property::LOAD_POLICY ] =  ImageVisual::LoadPolicy::IMMEDIATE;
1837
1838   tet_infoline("Immediate load an image");
1839   ImageView imageView = ImageView::New();
1840   imageView.ResourceReadySignal().Connect( &ResourceReadySignal);
1841   imageView.SetProperty( ImageView::Property::IMAGE, imageImmediateLoadingMap );
1842
1843   // loading started, this waits for the loader thread
1844   DALI_TEST_EQUALS( Test::WaitForEventThreadTrigger( 1 ), true, TEST_LOCATION );
1845
1846   application.SendNotification();
1847   application.Render(16);
1848
1849   tet_infoline("Check image loaded");
1850   DALI_TEST_EQUALS( gResourceReadySignalFired, true, TEST_LOCATION );
1851   gResourceReadySignalFired = false;
1852
1853   tet_infoline("Create another ImageView with the same URL");
1854   ImageView imageViewWithExistingImage = ImageView::New( gImage_34_RGBA );
1855   tet_infoline("Connect to ResourceReady signal for second ImageView, it should still fire as resource is ready");
1856   imageViewWithExistingImage.ResourceReadySignal().Connect( &ResourceReadySignal);
1857
1858   Stage::GetCurrent().Add( imageViewWithExistingImage );
1859
1860   DALI_TEST_EQUALS( gResourceReadySignalFired, true, TEST_LOCATION );
1861
1862   END_TEST;
1863 }
1864
1865 int UtcDaliImageViewPaddingProperty(void)
1866 {
1867   ToolkitTestApplication application;
1868
1869   ImageView imageView = ImageView::New();
1870   Property::Map imagePropertyMap;
1871   imagePropertyMap[ Toolkit::Visual::Property::TYPE ] = Toolkit::Visual::IMAGE;
1872   imagePropertyMap[ Toolkit::ImageVisual::Property::URL ] = TEST_RESOURCE_DIR "/gallery-small-1.jpg" ;
1873   imagePropertyMap[ ImageVisual::Property::DESIRED_WIDTH ] = 128;
1874   imagePropertyMap[ ImageVisual::Property::DESIRED_HEIGHT ] = 128;
1875   imageView.SetProperty( Toolkit::ImageView::Property::IMAGE , imagePropertyMap );
1876   imageView.SetAnchorPoint( AnchorPoint::TOP_LEFT );
1877   imageView.SetParentOrigin( ParentOrigin::TOP_LEFT );
1878   imageView.SetProperty( Control::Property::PADDING, Extents( 15, 10, 5, 10 ) );
1879   Stage::GetCurrent().Add( imageView );
1880
1881   application.SendNotification();
1882   application.Render();
1883
1884   DALI_TEST_EQUALS( imageView.GetProperty<Extents>( Control::Property::PADDING ), Extents( 15, 10, 5, 10 ), TEST_LOCATION );
1885
1886   ImageView childImage = ImageView::New();
1887   childImage.SetBackgroundColor( Color::BLACK );
1888   childImage.SetSize( 10.f, 10.f );
1889   imageView.Add( childImage );
1890
1891   application.SendNotification();
1892   application.Render();
1893
1894   // Child ImageView should be positioned dependinig on Parent ImageView's Padding value
1895   DALI_TEST_EQUALS( childImage.GetProperty<Vector3>( Dali::Actor::Property::POSITION ), Vector3( 15, 5, 0 ), TEST_LOCATION );
1896
1897   // Check whether Image Visual transforms on ImageVieiw::OnRelayout()
1898   Toolkit::Internal::Control& controlImpl = Toolkit::Internal::GetImplementation( imageView );
1899   Toolkit::Visual::Base imageVisual = DevelControl::GetVisual( controlImpl, ImageView::Property::IMAGE );
1900   Property::Map resultMap;
1901   imageVisual.CreatePropertyMap( resultMap );
1902
1903   Property::Value* transformValue = resultMap.Find( Visual::Property::TRANSFORM );
1904   DALI_TEST_CHECK( transformValue );
1905   Property::Map* retMap = transformValue->GetMap();
1906   DALI_TEST_CHECK( retMap );
1907
1908   // Image Visual should be positioned depending on ImageView's padding
1909   DALI_TEST_EQUALS( retMap->Find( Visual::Transform::Property::OFFSET )->Get< Vector2 >(), Vector2( 15, 5 ), TEST_LOCATION );
1910
1911   END_TEST;
1912 }
1913
1914 int UtcDaliImageViewPaddingProperty02(void)
1915 {
1916   ToolkitTestApplication application;
1917
1918   ImageView imageView = ImageView::New();
1919   Property::Map imagePropertyMap;
1920   imagePropertyMap[ Toolkit::Visual::Property::TYPE ] = Toolkit::Visual::IMAGE;
1921   imagePropertyMap[ Toolkit::ImageVisual::Property::URL ] = TEST_RESOURCE_DIR "/Kid1.svg" ;
1922   imagePropertyMap[ ImageVisual::Property::DESIRED_WIDTH ] = 128;
1923   imagePropertyMap[ ImageVisual::Property::DESIRED_HEIGHT ] = 128;
1924   imagePropertyMap[ DevelVisual::Property::VISUAL_FITTING_MODE ] = Toolkit::DevelVisual::FIT_KEEP_ASPECT_RATIO;
1925   imageView.SetProperty( Toolkit::ImageView::Property::IMAGE , imagePropertyMap );
1926   imageView.SetAnchorPoint( AnchorPoint::TOP_LEFT );
1927   imageView.SetParentOrigin( ParentOrigin::TOP_LEFT );
1928   imageView.SetProperty( Control::Property::PADDING, Extents( 15, 10, 5, 10 ) );
1929   Stage::GetCurrent().Add( imageView );
1930
1931   application.SendNotification();
1932   application.Render();
1933
1934   DALI_TEST_EQUALS( imageView.GetProperty<Extents>( Control::Property::PADDING ), Extents( 15, 10, 5, 10 ), TEST_LOCATION );
1935
1936   // Check whether Image Visual transforms on ImageVieiw::OnRelayout()
1937   Toolkit::Internal::Control& controlImpl = Toolkit::Internal::GetImplementation( imageView );
1938   Toolkit::Visual::Base imageVisual = DevelControl::GetVisual( controlImpl, ImageView::Property::IMAGE );
1939   Property::Map resultMap;
1940   imageVisual.CreatePropertyMap( resultMap );
1941
1942   Property::Value* transformValue = resultMap.Find( Visual::Property::TRANSFORM );
1943   DALI_TEST_CHECK( transformValue );
1944   Property::Map* retMap = transformValue->GetMap();
1945   DALI_TEST_CHECK( retMap );
1946
1947   // Image Visual should be positioned depending on ImageView's padding
1948   DALI_TEST_EQUALS( retMap->Find( Visual::Transform::Property::OFFSET )->Get< Vector2 >(), Vector2( 15, 5 ), TEST_LOCATION );
1949
1950   END_TEST;
1951 }
1952
1953 int UtcDaliImageViewPaddingProperty03(void)
1954 {
1955   tet_infoline("Test Setting Image Padding then removing it.");
1956
1957   ToolkitTestApplication application;
1958
1959   ImageView imageView = ImageView::New();
1960   Property::Map imagePropertyMap;
1961   imagePropertyMap[ Toolkit::Visual::Property::TYPE ] = Toolkit::Visual::IMAGE;
1962   imagePropertyMap[ Toolkit::ImageVisual::Property::URL ] = TEST_RESOURCE_DIR "/Kid1.svg" ;
1963   imagePropertyMap[ ImageVisual::Property::DESIRED_WIDTH ] = 128;
1964   imagePropertyMap[ ImageVisual::Property::DESIRED_HEIGHT ] = 128;
1965   imagePropertyMap[ DevelVisual::Property::VISUAL_FITTING_MODE ] = Toolkit::DevelVisual::FIT_KEEP_ASPECT_RATIO;
1966   imageView.SetProperty( Toolkit::ImageView::Property::IMAGE , imagePropertyMap );
1967   imageView.SetAnchorPoint( AnchorPoint::TOP_LEFT );
1968   imageView.SetParentOrigin( ParentOrigin::TOP_LEFT );
1969   imageView.SetProperty( Control::Property::PADDING, Extents( 15, 10, 5, 10 ) );
1970   Stage::GetCurrent().Add( imageView );
1971
1972   application.SendNotification();
1973   application.Render();
1974
1975   DALI_TEST_EQUALS( imageView.GetProperty<Extents>( Control::Property::PADDING ), Extents( 15, 10, 5, 10 ), TEST_LOCATION );
1976
1977   tet_infoline("Remove Padding and test Visual is position correctly");
1978
1979   imageView.SetProperty( Control::Property::PADDING, Extents( 0, 0, 0, 0 ) );
1980
1981   application.SendNotification();
1982   application.Render();
1983
1984   // Check whether Image Visual transforms on ImageVieiw::OnRelayout()
1985   Toolkit::Internal::Control& controlImpl = Toolkit::Internal::GetImplementation( imageView );
1986   Toolkit::Visual::Base imageVisual = DevelControl::GetVisual( controlImpl, ImageView::Property::IMAGE );
1987   Property::Map resultMap;
1988   imageVisual.CreatePropertyMap( resultMap );
1989
1990   Property::Value* transformValue = resultMap.Find( Visual::Property::TRANSFORM );
1991   DALI_TEST_CHECK( transformValue );
1992   Property::Map* retMap = transformValue->GetMap();
1993   DALI_TEST_CHECK( retMap );
1994
1995   // Image Visual should be positioned depending on ImageView's padding
1996   DALI_TEST_EQUALS( retMap->Find( Visual::Transform::Property::OFFSET )->Get< Vector2 >(), Vector2( 0, 0 ), TEST_LOCATION );
1997
1998   END_TEST;
1999 }
2000
2001 int UtcDaliImageViewPaddingProperty04(void)
2002 {
2003   tet_infoline("Test Setting Image Padding then removing it. Visual Fitting Mode as Fill");
2004
2005   ToolkitTestApplication application;
2006
2007   ImageView imageView = ImageView::New();
2008   Property::Map imagePropertyMap;
2009   imagePropertyMap[ Toolkit::Visual::Property::TYPE ] = Toolkit::Visual::IMAGE;
2010   imagePropertyMap[ Toolkit::ImageVisual::Property::URL ] = TEST_RESOURCE_DIR "/Kid1.svg" ;
2011   imagePropertyMap[ ImageVisual::Property::DESIRED_WIDTH ] = 128;
2012   imagePropertyMap[ ImageVisual::Property::DESIRED_HEIGHT ] = 128;
2013   imagePropertyMap[ DevelVisual::Property::VISUAL_FITTING_MODE ] = Toolkit::DevelVisual::FILL;
2014   imageView.SetProperty( Toolkit::ImageView::Property::IMAGE , imagePropertyMap );
2015   imageView.SetAnchorPoint( AnchorPoint::TOP_LEFT );
2016   imageView.SetParentOrigin( ParentOrigin::TOP_LEFT );
2017   imageView.SetProperty( Control::Property::PADDING, Extents( 15, 10, 5, 10 ) );
2018   Stage::GetCurrent().Add( imageView );
2019
2020   application.SendNotification();
2021   application.Render();
2022
2023   DALI_TEST_EQUALS( imageView.GetProperty<Extents>( Control::Property::PADDING ), Extents( 15, 10, 5, 10 ), TEST_LOCATION );
2024
2025   tet_infoline("Remove Padding and test Visual is position correctly");
2026
2027   imageView.SetProperty( Control::Property::PADDING, Extents( 0, 0, 0, 0 ) );
2028
2029   application.SendNotification();
2030   application.Render();
2031
2032   // Check whether Image Visual transforms on ImageVieiw::OnRelayout()
2033   Toolkit::Internal::Control& controlImpl = Toolkit::Internal::GetImplementation( imageView );
2034   Toolkit::Visual::Base imageVisual = DevelControl::GetVisual( controlImpl, ImageView::Property::IMAGE );
2035   Property::Map resultMap;
2036   imageVisual.CreatePropertyMap( resultMap );
2037
2038   Property::Value* transformValue = resultMap.Find( Visual::Property::TRANSFORM );
2039   DALI_TEST_CHECK( transformValue );
2040   Property::Map* retMap = transformValue->GetMap();
2041   DALI_TEST_CHECK( retMap );
2042
2043   // Image Visual should be positioned depending on ImageView's padding
2044   DALI_TEST_EQUALS( retMap->Find( Visual::Transform::Property::OFFSET )->Get< Vector2 >(), Vector2( 0, 0 ), TEST_LOCATION );
2045
2046   END_TEST;
2047 }
2048
2049 int UtcDaliImageViewTransformTest01(void)
2050 {
2051   tet_infoline("Test Setting a offset transform on the ImageView");
2052
2053   ToolkitTestApplication application;
2054
2055   ImageView imageView = ImageView::New();
2056   Property::Map imagePropertyMap;
2057   imagePropertyMap.Add( Toolkit::Visual::Property::TYPE,Toolkit::Visual::IMAGE )
2058                   .Add( Toolkit::ImageVisual::Property::URL,TEST_RESOURCE_DIR "/Kid1.svg" )
2059                   .Add( ImageVisual::Property::DESIRED_WIDTH,120 )
2060                   .Add( ImageVisual::Property::DESIRED_HEIGHT,120 )
2061                   .Add( DevelVisual::Property::VISUAL_FITTING_MODE, Toolkit::DevelVisual::FILL )
2062                   .Add( Visual::Property::TRANSFORM,
2063                         Property::Map().Add( Toolkit::Visual::Transform::Property::OFFSET_POLICY,
2064                                              Vector2( Visual::Transform::Policy::ABSOLUTE, Visual::Transform::Policy::ABSOLUTE ) )
2065                                        .Add( Toolkit::Visual::Transform::Property::OFFSET, Vector2( 8, 8 ) ) );
2066
2067   imageView.SetProperty( Toolkit::ImageView::Property::IMAGE , imagePropertyMap );
2068   imageView.SetAnchorPoint( AnchorPoint::TOP_LEFT );
2069   imageView.SetParentOrigin( ParentOrigin::TOP_LEFT );
2070   Stage::GetCurrent().Add( imageView );
2071
2072   application.SendNotification();
2073   application.Render();
2074
2075   // Check whether Image Visual transforms on ImageVieiw::OnRelayout()
2076   Toolkit::Internal::Control& controlImpl = Toolkit::Internal::GetImplementation( imageView );
2077   Toolkit::Visual::Base imageVisual = DevelControl::GetVisual( controlImpl, ImageView::Property::IMAGE );
2078   Property::Map resultMap;
2079   imageVisual.CreatePropertyMap( resultMap );
2080
2081   Property::Value* transformValue = resultMap.Find( Visual::Property::TRANSFORM );
2082   DALI_TEST_CHECK( transformValue );
2083   Property::Map* retMap = transformValue->GetMap();
2084   DALI_TEST_CHECK( retMap );
2085
2086   // Image Visual should be positioned depending on ImageView's padding
2087   DALI_TEST_EQUALS( retMap->Find( Visual::Transform::Property::OFFSET )->Get< Vector2 >(), Vector2( 8, 8 ), TEST_LOCATION );
2088   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 );
2089
2090   END_TEST;
2091 }
2092
2093 int UtcDaliImageViewUsingAtlasAndGetNaturalSize(void)
2094 {
2095   ToolkitTestApplication application;
2096
2097   // Check ImageView with background and main image, to ensure both visuals are marked as loaded
2098   ImageView imageView = ImageView::New();
2099   Property::Map imageMap;
2100   imageMap[ Toolkit::Visual::Property::TYPE ] = Toolkit::Visual::IMAGE;
2101   imageMap[ Toolkit::ImageVisual::Property::URL ] = gImage_34_RGBA;
2102   imageMap[ Toolkit::ImageVisual::Property::ATLASING ] = true;
2103   imageView.SetProperty( Toolkit::ImageView::Property::IMAGE, imageMap );
2104   Stage::GetCurrent().Add( imageView );
2105
2106   // Trigger a potential relayout
2107   application.SendNotification();
2108   application.Render();
2109
2110   Vector3 naturalSize = imageView.GetNaturalSize();
2111
2112   DALI_TEST_EQUALS( naturalSize.width, 34.0f, TEST_LOCATION );
2113   DALI_TEST_EQUALS( naturalSize.height, 34.0f, TEST_LOCATION );
2114
2115   END_TEST;
2116 }
2117
2118 int UtcDaliImageViewFillMode(void)
2119 {
2120   ToolkitTestApplication application;
2121
2122   tet_infoline( "Create an ImageVisual without padding and set the fill-mode to fill" );
2123   tet_infoline( "  There should be no need to change the transform, our size-policy should be relative and size should be [1,1]");
2124
2125   ImageView imageView = ImageView::New();
2126   Property::Map imageMap;
2127   imageMap.Add( Toolkit::Visual::Property::TYPE, Toolkit::Visual::IMAGE );
2128   imageMap.Add( Toolkit::ImageVisual::Property::URL, gImage_600_RGB );
2129   imageMap.Add( DevelVisual::Property::VISUAL_FITTING_MODE, DevelVisual::FittingMode::FILL );
2130
2131   imageView.SetProperty( Toolkit::ImageView::Property::IMAGE, imageMap );
2132
2133   Stage::GetCurrent().Add( imageView );
2134
2135   // Trigger a potential relayout
2136   application.SendNotification();
2137   application.Render();
2138
2139   Toolkit::Visual::Base visual = DevelControl::GetVisual( Toolkit::Internal::GetImplementation( imageView ), Toolkit::ImageView::Property::IMAGE );
2140   Property::Map returnedMap;
2141   visual.CreatePropertyMap( returnedMap );
2142
2143   Property::Value* value = returnedMap.Find( Toolkit::Visual::Property::TRANSFORM );
2144   DALI_TEST_CHECK( value );
2145   Property::Map* map = value->GetMap();
2146   DALI_TEST_CHECK( map );
2147
2148   // If there's
2149   value = map->Find( Toolkit::Visual::Transform::Property::SIZE );
2150   DALI_TEST_CHECK( value );
2151   DALI_TEST_EQUALS( value->Get< Vector2 >(), Vector2::ONE, TEST_LOCATION ); // Relative size so will take up 100%
2152
2153   value = map->Find( Toolkit::Visual::Transform::Property::SIZE_POLICY );
2154   DALI_TEST_CHECK( value );
2155   DALI_TEST_CHECK( value->Get< int >() == Toolkit::Visual::Transform::Policy::RELATIVE );
2156
2157   END_TEST;
2158 }
2159
2160 int UtcDaliImageViewCustomShader(void)
2161 {
2162   ToolkitTestApplication application;
2163
2164   // Set a custom shader with an image url
2165   {
2166     Property::Map properties;
2167     Property::Map shader;
2168     const std::string vertexShader = "Foobar";
2169     const std::string fragmentShader = "Foobar";
2170     shader[Visual::Shader::Property::FRAGMENT_SHADER] = fragmentShader;
2171     shader[Visual::Shader::Property::VERTEX_SHADER] = vertexShader;
2172
2173     properties[Visual::Property::TYPE] = Visual::IMAGE;
2174     properties[Visual::Property::SHADER] = shader;
2175     properties[ImageVisual::Property::URL] = TEST_IMAGE_FILE_NAME;
2176
2177     ImageView imageView = ImageView::New();
2178     imageView.SetProperty( ImageView::Property::IMAGE, properties );
2179
2180     Stage::GetCurrent().Add( imageView );
2181
2182     application.SendNotification();
2183     application.Render();
2184
2185     DALI_TEST_EQUALS( Test::WaitForEventThreadTrigger( 1 ), true, TEST_LOCATION );
2186
2187     Renderer renderer = imageView.GetRendererAt( 0 );
2188     Shader shader2 = renderer.GetShader();
2189     Property::Value value = shader2.GetProperty( Shader::Property::PROGRAM );
2190     Property::Map* map = value.GetMap();
2191     DALI_TEST_CHECK( map );
2192
2193     Property::Value* fragment = map->Find( "fragment" ); // fragment key name from shader-impl.cpp
2194     DALI_TEST_EQUALS( fragmentShader, fragment->Get< std::string >(), TEST_LOCATION );
2195
2196     Property::Value* vertex = map->Find( "vertex" ); // vertex key name from shader-impl.cpp
2197     DALI_TEST_EQUALS( vertexShader, vertex->Get< std::string >(), TEST_LOCATION );
2198   }
2199
2200   // Set a custom shader after setting an image url
2201   {
2202     Property::Map properties;
2203     Property::Map shader;
2204     const std::string vertexShader = "Foobar";
2205     const std::string fragmentShader = "Foobar";
2206     shader[Visual::Shader::Property::FRAGMENT_SHADER] = fragmentShader;
2207     shader[Visual::Shader::Property::VERTEX_SHADER] = vertexShader;
2208
2209     properties[Visual::Property::SHADER] = shader;
2210
2211     ImageView imageView = ImageView::New( TEST_IMAGE_FILE_NAME );
2212     imageView.SetProperty( ImageView::Property::IMAGE, properties );
2213
2214     Stage::GetCurrent().Add( imageView );
2215
2216     application.SendNotification();
2217     application.Render();
2218
2219     DALI_TEST_EQUALS( Test::WaitForEventThreadTrigger( 1 ), true, TEST_LOCATION );
2220
2221     Renderer renderer = imageView.GetRendererAt( 0 );
2222     Shader shader2 = renderer.GetShader();
2223     Property::Value value = shader2.GetProperty( Shader::Property::PROGRAM );
2224     Property::Map* map = value.GetMap();
2225     DALI_TEST_CHECK( map );
2226
2227     Property::Value* fragment = map->Find( "fragment" ); // fragment key name from shader-impl.cpp
2228     DALI_TEST_EQUALS( fragmentShader, fragment->Get< std::string >(), TEST_LOCATION );
2229
2230     Property::Value* vertex = map->Find( "vertex" ); // vertex key name from shader-impl.cpp
2231     DALI_TEST_EQUALS( vertexShader, vertex->Get< std::string >(), TEST_LOCATION );
2232   }
2233
2234   // Set a custom shader before setting an image url
2235   {
2236     Property::Map properties;
2237     Property::Map shader;
2238     const std::string vertexShader = "Foobar";
2239     const std::string fragmentShader = "Foobar";
2240     shader[Visual::Shader::Property::FRAGMENT_SHADER] = fragmentShader;
2241     shader[Visual::Shader::Property::VERTEX_SHADER] = vertexShader;
2242
2243     properties[Visual::Property::SHADER] = shader;
2244
2245     ImageView imageView = ImageView::New();
2246     imageView.SetProperty( ImageView::Property::IMAGE, properties );
2247     imageView.SetProperty( ImageView::Property::IMAGE, TEST_IMAGE_FILE_NAME );
2248
2249     Stage::GetCurrent().Add( imageView );
2250
2251     application.SendNotification();
2252     application.Render();
2253     DALI_TEST_EQUALS( Test::WaitForEventThreadTrigger( 1 ), true, TEST_LOCATION );
2254
2255     Renderer renderer = imageView.GetRendererAt( 0 );
2256     Shader shader2 = renderer.GetShader();
2257     Property::Value value = shader2.GetProperty( Shader::Property::PROGRAM );
2258     Property::Map* map = value.GetMap();
2259     DALI_TEST_CHECK( map );
2260
2261     Property::Value* fragment = map->Find( "fragment" ); // fragment key name from shader-impl.cpp
2262     DALI_TEST_EQUALS( fragmentShader, fragment->Get< std::string >(), TEST_LOCATION );
2263
2264     Property::Value* vertex = map->Find( "vertex" ); // vertex key name from shader-impl.cpp
2265     DALI_TEST_EQUALS( vertexShader, vertex->Get< std::string >(), TEST_LOCATION );
2266   }
2267
2268   // Set a custom shader after setting a property map
2269   {
2270     Property::Map properties;
2271     Property::Map shader;
2272     const std::string vertexShader = "Foobar";
2273     const std::string fragmentShader = "Foobar";
2274     shader[Visual::Shader::Property::FRAGMENT_SHADER] = fragmentShader;
2275     shader[Visual::Shader::Property::VERTEX_SHADER] = vertexShader;
2276
2277     properties[Visual::Property::SHADER] = shader;
2278
2279     Property::Map properties1;
2280     properties1[Visual::Property::TYPE] = Visual::IMAGE;
2281     properties1[ImageVisual::Property::URL] = TEST_IMAGE_FILE_NAME;
2282
2283     ImageView imageView = ImageView::New();
2284     imageView.SetProperty( ImageView::Property::IMAGE, properties1 );
2285     imageView.SetProperty( ImageView::Property::IMAGE, properties );
2286
2287     Stage::GetCurrent().Add( imageView );
2288
2289     application.SendNotification();
2290     application.Render();
2291     DALI_TEST_EQUALS( Test::WaitForEventThreadTrigger( 1 ), true, TEST_LOCATION );
2292
2293     Renderer renderer = imageView.GetRendererAt( 0 );
2294     Shader shader2 = renderer.GetShader();
2295     Property::Value value = shader2.GetProperty( Shader::Property::PROGRAM );
2296     Property::Map* map = value.GetMap();
2297     DALI_TEST_CHECK( map );
2298
2299     Property::Value* fragment = map->Find( "fragment" ); // fragment key name from shader-impl.cpp
2300     DALI_TEST_EQUALS( fragmentShader, fragment->Get< std::string >(), TEST_LOCATION );
2301
2302     Property::Value* vertex = map->Find( "vertex" ); // vertex key name from shader-impl.cpp
2303     DALI_TEST_EQUALS( vertexShader, vertex->Get< std::string >(), TEST_LOCATION );
2304   }
2305
2306   // Set a custom shader before setting a property map
2307   {
2308     Property::Map properties;
2309     Property::Map shader;
2310     const std::string vertexShader = "Foobar";
2311     const std::string fragmentShader = "Foobar";
2312     shader[Visual::Shader::Property::FRAGMENT_SHADER] = fragmentShader;
2313     shader[Visual::Shader::Property::VERTEX_SHADER] = vertexShader;
2314
2315     properties[Visual::Property::SHADER] = shader;
2316
2317     Property::Map properties1;
2318     properties1[Visual::Property::TYPE] = Visual::IMAGE;
2319     properties1[ImageVisual::Property::URL] = TEST_IMAGE_FILE_NAME;
2320
2321     ImageView imageView = ImageView::New();
2322     imageView.SetProperty( ImageView::Property::IMAGE, properties );
2323     imageView.SetProperty( ImageView::Property::IMAGE, properties1 );
2324
2325     Stage::GetCurrent().Add( imageView );
2326
2327     application.SendNotification();
2328     application.Render();
2329     DALI_TEST_EQUALS( Test::WaitForEventThreadTrigger( 1 ), true, TEST_LOCATION );
2330
2331     Renderer renderer = imageView.GetRendererAt( 0 );
2332     Shader shader2 = renderer.GetShader();
2333     Property::Value value = shader2.GetProperty( Shader::Property::PROGRAM );
2334     Property::Map* map = value.GetMap();
2335     DALI_TEST_CHECK( map );
2336
2337     Property::Value* fragment = map->Find( "fragment" ); // fragment key name from shader-impl.cpp
2338     DALI_TEST_EQUALS( fragmentShader, fragment->Get< std::string >(), TEST_LOCATION );
2339
2340     Property::Value* vertex = map->Find( "vertex" ); // vertex key name from shader-impl.cpp
2341     DALI_TEST_EQUALS( vertexShader, vertex->Get< std::string >(), TEST_LOCATION );
2342   }
2343
2344   END_TEST;
2345 }
2346
2347
2348 namespace
2349 {
2350 static int gFailCounter = 0;
2351 const int MAX_RETRIES(3);
2352
2353 void ReloadImage(ImageView imageView)
2354 {
2355   Property::Map imageImmediateLoadingMap;
2356   imageImmediateLoadingMap[ ImageVisual::Property::URL ] = "Non-existant-image.jpg";
2357   imageImmediateLoadingMap[ ImageVisual::Property::LOAD_POLICY ] =  ImageVisual::LoadPolicy::IMMEDIATE;
2358
2359   tet_infoline("Immediate load an image");
2360   imageView.SetProperty( ImageView::Property::IMAGE, imageImmediateLoadingMap );
2361 }
2362
2363 void ResourceFailedReload( Control control )
2364 {
2365   gFailCounter++;
2366   if( gFailCounter < MAX_RETRIES )
2367   {
2368     ReloadImage(ImageView::DownCast(control));
2369   }
2370 }
2371 }
2372
2373 int UtcDaliImageViewReloadFailedOnResourceReadySignal(void)
2374 {
2375   tet_infoline("Test reloading failed image from within signal handler.");
2376
2377   ToolkitTestApplication application;
2378
2379   gFailCounter = 0;
2380
2381   ImageView imageView = ImageView::New();
2382   imageView.ResourceReadySignal().Connect( &ResourceFailedReload );
2383   DALI_TEST_EQUALS( gFailCounter, 0, TEST_LOCATION );
2384   ReloadImage(imageView);
2385
2386   // loading started, this waits for the loader thread to complete
2387   DALI_TEST_EQUALS( Test::WaitForEventThreadTrigger( 1 ), true, TEST_LOCATION );
2388   application.SendNotification();
2389
2390   DALI_TEST_EQUALS( gFailCounter, 1, TEST_LOCATION );
2391
2392   DALI_TEST_EQUALS( Test::WaitForEventThreadTrigger( 1 ), true, TEST_LOCATION );
2393   application.SendNotification();
2394
2395   DALI_TEST_EQUALS( gFailCounter, 2, TEST_LOCATION );
2396
2397   DALI_TEST_EQUALS( Test::WaitForEventThreadTrigger( 1 ), true, TEST_LOCATION );
2398   application.SendNotification();
2399   DALI_TEST_EQUALS( gFailCounter, 3, TEST_LOCATION );
2400
2401   END_TEST;
2402 }