Merge "Fix ZWJ, ZWNJ issues" into devel/master
[platform/core/uifw/dali-toolkit.git] / automated-tests / src / dali-toolkit / utc-Dali-ImageView.cpp
1 /*
2  * Copyright (c) 2021 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 #include <dali-toolkit/public-api/image-loader/image.h>
32 #include <dali-toolkit/public-api/image-loader/image-url.h>
33 #include <dali-toolkit/devel-api/styling/style-manager-devel.h>
34
35 #include <test-native-image.h>
36 #include <test-encoded-image-buffer.h>
37 #include <sstream>
38 #include <unistd.h>
39
40
41 #include "dummy-control.h"
42
43 using namespace Dali;
44 using namespace Toolkit;
45
46 void utc_dali_toolkit_image_view_startup(void)
47 {
48   test_return_value = TET_UNDEF;
49 }
50
51 void utc_dali_toolkit_image_view_cleanup(void)
52 {
53   test_return_value = TET_PASS;
54 }
55
56 namespace
57 {
58
59 const char* TEST_IMAGE_FILE_NAME =  "gallery_image_01.jpg";
60 const char* TEST_IMAGE_FILE_NAME2 =  "gallery_image_02.jpg";
61
62 const char* TEST_IMAGE_1 = TEST_RESOURCE_DIR "/TB-gloss.png";
63 const char* TEST_IMAGE_2 = TEST_RESOURCE_DIR "/tb-norm.png";
64
65 const char* TEST_BROKEN_IMAGE_DEFAULT = TEST_RESOURCE_DIR "/broken.png";
66 const char* TEST_BROKEN_IMAGE_S = TEST_RESOURCE_DIR "/broken_s.9.png";
67 const char* TEST_BROKEN_IMAGE_M = TEST_RESOURCE_DIR "/broken_m.9.png";
68 const char* TEST_BROKEN_IMAGE_L = TEST_RESOURCE_DIR "/broken_l.9.png";
69 const char* TEST_BROKEN_IMAGE_01 =  TEST_RESOURCE_DIR "/button-up.9.png";
70 const char* TEST_BROKEN_IMAGE_02 =  TEST_RESOURCE_DIR "/heartsframe.9.png";
71
72 // resolution: 34*34, pixel format: RGBA8888
73 static const char* gImage_34_RGBA = TEST_RESOURCE_DIR "/icon-edit.png";
74 // resolution: 600*600, pixel format: RGB888
75 static const char* gImage_600_RGB = TEST_RESOURCE_DIR "/test-image-600.jpg";
76
77 // resolution: 50*50, frame count: 4, frame delay: 0.2 second for each frame
78 const char* TEST_GIF_FILE_NAME = TEST_RESOURCE_DIR "/anim.gif";
79
80 const char* TEST_VECTOR_IMAGE_FILE_NAME =  TEST_RESOURCE_DIR  "/insta_camera.json";
81
82 void TestUrl( ImageView imageView, const std::string url )
83 {
84   Property::Value value = imageView.GetProperty( imageView.GetPropertyIndex( "image" ) );
85
86   std::string urlActual;
87   DALI_TEST_CHECK( value.Get( urlActual ) );
88   DALI_TEST_EQUALS( urlActual, url, TEST_LOCATION );
89 }
90
91 } // namespace
92
93 int UtcDaliImageViewNewP(void)
94 {
95   ToolkitTestApplication application;
96
97   ImageView imageView = ImageView::New();
98
99   DALI_TEST_CHECK( imageView );
100
101   END_TEST;
102 }
103
104 int UtcDaliImageViewNewUrlP(void)
105 {
106   ToolkitTestApplication application;
107
108   ImageView imageView = ImageView::New( TEST_IMAGE_FILE_NAME );
109   DALI_TEST_CHECK( imageView );
110
111   TestUrl( imageView, TEST_IMAGE_FILE_NAME );
112
113   END_TEST;
114 }
115
116 int UtcDaliImageViewConstructorP(void)
117 {
118   ToolkitTestApplication application;
119
120   ImageView imageView;
121
122   DALI_TEST_CHECK( !imageView );
123
124   END_TEST;
125 }
126
127 int UtcDaliImageViewCopyConstructorP(void)
128 {
129   ToolkitTestApplication application;
130
131   // Initialize an object, ref count == 1
132   ImageView imageView = ImageView::New();
133
134   ImageView copy( imageView );
135   DALI_TEST_CHECK( copy );
136
137   END_TEST;
138 }
139
140 int UtcDaliImageViewMoveConstructor(void)
141 {
142   ToolkitTestApplication application;
143
144   ImageView imageView = ImageView::New();
145   DALI_TEST_EQUALS( 1, imageView.GetBaseObject().ReferenceCount(), TEST_LOCATION );
146   imageView.SetProperty( Actor::Property::SENSITIVE, false );
147   DALI_TEST_CHECK( false == imageView.GetProperty< bool >( Actor::Property::SENSITIVE ) );
148
149   ImageView moved = std::move( imageView );
150   DALI_TEST_CHECK( moved );
151   DALI_TEST_EQUALS( 1, moved.GetBaseObject().ReferenceCount(), TEST_LOCATION );
152   DALI_TEST_CHECK( false == moved.GetProperty< bool >( Actor::Property::SENSITIVE ) );
153   DALI_TEST_CHECK( !imageView );
154
155   END_TEST;
156 }
157
158 int UtcDaliImageViewAssignmentOperatorP(void)
159 {
160   ToolkitTestApplication application;
161
162   ImageView imageView = ImageView::New();
163
164   ImageView copy( imageView );
165   DALI_TEST_CHECK( copy );
166   DALI_TEST_EQUALS( imageView, copy, TEST_LOCATION );
167
168   END_TEST;
169 }
170
171 int UtcDaliImageViewMoveAssignment(void)
172 {
173   ToolkitTestApplication application;
174
175   ImageView imageView = ImageView::New();
176   DALI_TEST_EQUALS( 1, imageView.GetBaseObject().ReferenceCount(), TEST_LOCATION );
177   imageView.SetProperty( Actor::Property::SENSITIVE, false );
178   DALI_TEST_CHECK( false == imageView.GetProperty< bool >( Actor::Property::SENSITIVE ) );
179
180   ImageView moved;
181   moved = std::move( imageView );
182   DALI_TEST_CHECK( moved );
183   DALI_TEST_EQUALS( 1, moved.GetBaseObject().ReferenceCount(), TEST_LOCATION );
184   DALI_TEST_CHECK( false == moved.GetProperty< bool >( Actor::Property::SENSITIVE ) );
185   DALI_TEST_CHECK( !imageView );
186
187   END_TEST;
188 }
189
190 int UtcDaliImageViewDownCastP(void)
191 {
192   ToolkitTestApplication application;
193
194   ImageView imageView = ImageView::New();
195
196   BaseHandle object(imageView);
197
198   ImageView imageView2 = ImageView::DownCast( object );
199   DALI_TEST_CHECK(imageView2);
200
201   ImageView imageView3 = DownCast< ImageView >( object );
202   DALI_TEST_CHECK(imageView3);
203
204   END_TEST;
205 }
206
207 int UtcDaliImageViewDownCastN(void)
208 {
209   ToolkitTestApplication application;
210
211   BaseHandle unInitializedObject;
212
213   ImageView imageView1 = ImageView::DownCast( unInitializedObject );
214   DALI_TEST_CHECK( !imageView1 );
215
216   ImageView imageView2 = DownCast< ImageView >( unInitializedObject );
217   DALI_TEST_CHECK( !imageView2 );
218
219   END_TEST;
220 }
221
222 int UtcDaliImageViewTypeRegistry(void)
223 {
224   ToolkitTestApplication application;
225
226   TypeRegistry typeRegistry = TypeRegistry::Get();
227   DALI_TEST_CHECK( typeRegistry );
228
229   TypeInfo typeInfo = typeRegistry.GetTypeInfo( "ImageView" );
230   DALI_TEST_CHECK( typeInfo );
231
232   BaseHandle handle = typeInfo.CreateInstance();
233   DALI_TEST_CHECK( handle );
234
235   ImageView imageView = ImageView::DownCast( handle );
236   DALI_TEST_CHECK( imageView );
237
238   END_TEST;
239 }
240
241 int UtcDaliImageViewSetGetProperty01(void)
242 {
243   ToolkitTestApplication application;
244
245   ImageView imageView = ImageView::New();
246
247   Property::Index idx = imageView.GetPropertyIndex( "image" );
248   DALI_TEST_EQUALS( idx, (Property::Index)ImageView::Property::IMAGE, TEST_LOCATION );
249
250   imageView.SetProperty( idx, TEST_IMAGE_FILE_NAME );
251   TestUrl( imageView, TEST_IMAGE_FILE_NAME );
252
253   END_TEST;
254 }
255
256 int UtcDaliImageViewPreMultipliedAlphaPng(void)
257 {
258   ToolkitTestApplication application;
259
260   // Set up trace debug
261   TestGlAbstraction& gl = application.GetGlAbstraction();
262   TraceCallStack& textureTrace = gl.GetTextureTrace();
263   textureTrace.Enable( true );
264
265   Property::Map imageMap;
266   imageMap[ ImageVisual::Property::URL ] = gImage_34_RGBA;
267   imageMap[ ImageVisual::Property::RELEASE_POLICY] = ImageVisual::ReleasePolicy::NEVER;   // To keep the texture cache
268
269   ImageView imageView1 = ImageView::New();
270   imageView1.SetProperty( ImageView::Property::IMAGE, imageMap );
271
272   application.GetScene().Add( imageView1 );
273
274   Property::Value value = imageView1.GetProperty( ImageView::Property::PRE_MULTIPLIED_ALPHA );
275   bool enable;
276   DALI_TEST_CHECK( value.Get( enable ) );
277   DALI_TEST_CHECK( enable );    // Default value is true
278
279   // loading started, this waits for the loader thread for max 30 seconds
280   DALI_TEST_EQUALS( Test::WaitForEventThreadTrigger( 1 ), true, TEST_LOCATION );
281
282   application.SendNotification();
283   application.Render();
284
285   value = imageView1.GetProperty( ImageView::Property::PRE_MULTIPLIED_ALPHA );
286   DALI_TEST_CHECK( value.Get( enable ) );
287   DALI_TEST_CHECK( enable );    // Keep true
288
289   // conventional alpha blending
290   Renderer renderer1 = imageView1.GetRendererAt( 0 );
291   value = renderer1.GetProperty( Renderer::Property::BLEND_PRE_MULTIPLIED_ALPHA );
292   DALI_TEST_CHECK( value.Get( enable ) );
293   DALI_TEST_CHECK( enable );
294
295   int srcFactorRgb    = renderer1.GetProperty<int>( Renderer::Property::BLEND_FACTOR_SRC_RGB );
296   int destFactorRgb   = renderer1.GetProperty<int>( Renderer::Property::BLEND_FACTOR_DEST_RGB );
297   int srcFactorAlpha  = renderer1.GetProperty<int>( Renderer::Property::BLEND_FACTOR_SRC_ALPHA );
298   int destFactorAlpha = renderer1.GetProperty<int>( Renderer::Property::BLEND_FACTOR_DEST_ALPHA );
299   DALI_TEST_CHECK( srcFactorRgb == BlendFactor::ONE );
300   DALI_TEST_CHECK( destFactorRgb == BlendFactor::ONE_MINUS_SRC_ALPHA );
301   DALI_TEST_CHECK( srcFactorAlpha == BlendFactor::ONE );
302   DALI_TEST_CHECK( destFactorAlpha == BlendFactor::ONE_MINUS_SRC_ALPHA );
303
304   DALI_TEST_EQUALS( textureTrace.FindMethod("GenTextures"), true, TEST_LOCATION );  // A new texture should be generated.
305   textureTrace.Reset();
306
307   // Disable pre-multiplied alpha blending
308   imageView1.SetProperty( ImageView::Property::PRE_MULTIPLIED_ALPHA, false );
309
310   // Reload the image
311   Property::Map attributes;
312   DevelControl::DoAction( imageView1, ImageView::Property::IMAGE, DevelImageVisual::Action::RELOAD, attributes );
313
314   // loading started, this waits for the loader thread for max 30 seconds
315   DALI_TEST_EQUALS( Test::WaitForEventThreadTrigger( 1 ), true, TEST_LOCATION );
316
317   application.SendNotification();
318   application.Render();
319
320   value = imageView1.GetProperty( ImageView::Property::PRE_MULTIPLIED_ALPHA );
321   DALI_TEST_CHECK( value.Get( enable ) );
322   DALI_TEST_CHECK( !enable );
323
324   // conventional alpha blending
325   value = renderer1.GetProperty( Renderer::Property::BLEND_PRE_MULTIPLIED_ALPHA );
326   DALI_TEST_CHECK( value.Get( enable ) );
327   DALI_TEST_CHECK( !enable );
328
329   srcFactorRgb    = renderer1.GetProperty<int>( Renderer::Property::BLEND_FACTOR_SRC_RGB );
330   destFactorRgb   = renderer1.GetProperty<int>( Renderer::Property::BLEND_FACTOR_DEST_RGB );
331   srcFactorAlpha  = renderer1.GetProperty<int>( Renderer::Property::BLEND_FACTOR_SRC_ALPHA );
332   destFactorAlpha = renderer1.GetProperty<int>( Renderer::Property::BLEND_FACTOR_DEST_ALPHA );
333   DALI_TEST_CHECK( srcFactorRgb == BlendFactor::SRC_ALPHA );
334   DALI_TEST_CHECK( destFactorRgb == BlendFactor::ONE_MINUS_SRC_ALPHA );
335   DALI_TEST_CHECK( srcFactorAlpha == BlendFactor::ONE );
336   DALI_TEST_CHECK( destFactorAlpha == BlendFactor::ONE_MINUS_SRC_ALPHA );
337
338   DALI_TEST_EQUALS( textureTrace.FindMethod("GenTextures"), true, TEST_LOCATION );  // A new texture should be generated.
339   textureTrace.Reset();
340
341   // Make a new ImageView using the same image
342   ImageView imageView2 = ImageView::New();
343   imageView2.SetProperty( ImageView::Property::IMAGE, imageMap );
344
345   application.GetScene().Add( imageView2 );
346
347   application.SendNotification();
348   application.Render();
349
350   Renderer renderer2 = imageView2.GetRendererAt( 0 );
351   value = renderer2.GetProperty( Renderer::Property::BLEND_PRE_MULTIPLIED_ALPHA );
352   DALI_TEST_CHECK( value.Get( enable ) );
353   DALI_TEST_CHECK( enable );
354
355   srcFactorRgb    = renderer2.GetProperty<int>( Renderer::Property::BLEND_FACTOR_SRC_RGB );
356   destFactorRgb   = renderer2.GetProperty<int>( Renderer::Property::BLEND_FACTOR_DEST_RGB );
357   srcFactorAlpha  = renderer2.GetProperty<int>( Renderer::Property::BLEND_FACTOR_SRC_ALPHA );
358   destFactorAlpha = renderer2.GetProperty<int>( Renderer::Property::BLEND_FACTOR_DEST_ALPHA );
359   DALI_TEST_CHECK( srcFactorRgb == BlendFactor::ONE );
360   DALI_TEST_CHECK( destFactorRgb == BlendFactor::ONE_MINUS_SRC_ALPHA );
361   DALI_TEST_CHECK( srcFactorAlpha == BlendFactor::ONE );
362   DALI_TEST_CHECK( destFactorAlpha == BlendFactor::ONE_MINUS_SRC_ALPHA );
363
364   DALI_TEST_EQUALS( textureTrace.FindMethod("GenTextures"), false, TEST_LOCATION ); // The cached texture should be used.
365
366   END_TEST;
367 }
368
369 int UtcDaliImageViewPreMultipliedAlphaJpg(void)
370 {
371   ToolkitTestApplication application;
372
373   // Set up trace debug
374   TestGlAbstraction& gl = application.GetGlAbstraction();
375   TraceCallStack& textureTrace = gl.GetTextureTrace();
376   textureTrace.Enable( true );
377
378   Property::Map imageMap;
379   imageMap[ ImageVisual::Property::URL ] = gImage_600_RGB;
380   imageMap[ ImageVisual::Property::RELEASE_POLICY] = ImageVisual::ReleasePolicy::NEVER;   // To keep the texture cache
381
382   ImageView imageView1 = ImageView::New();
383   imageView1.SetProperty( ImageView::Property::IMAGE, imageMap );
384
385   application.GetScene().Add( imageView1 );
386
387   Property::Value value = imageView1.GetProperty( ImageView::Property::PRE_MULTIPLIED_ALPHA );
388   bool enable;
389   DALI_TEST_CHECK( value.Get( enable ) );
390   DALI_TEST_CHECK( enable );    // Default value is true
391
392   // loading started, this waits for the loader thread for max 30 seconds
393   DALI_TEST_EQUALS( Test::WaitForEventThreadTrigger( 1 ), true, TEST_LOCATION );
394
395   application.SendNotification();
396   application.Render();
397
398   value = imageView1.GetProperty( ImageView::Property::PRE_MULTIPLIED_ALPHA );
399   DALI_TEST_CHECK( value.Get( enable ) );
400   DALI_TEST_CHECK( !enable );    // Should be false after loading
401
402   // conventional alpha blending
403   Renderer renderer1 = imageView1.GetRendererAt( 0 );
404   value = renderer1.GetProperty( Renderer::Property::BLEND_PRE_MULTIPLIED_ALPHA );
405   DALI_TEST_CHECK( value.Get( enable ) );
406   DALI_TEST_CHECK( !enable );
407
408   int srcFactorRgb    = renderer1.GetProperty<int>( Renderer::Property::BLEND_FACTOR_SRC_RGB );
409   int destFactorRgb   = renderer1.GetProperty<int>( Renderer::Property::BLEND_FACTOR_DEST_RGB );
410   int srcFactorAlpha  = renderer1.GetProperty<int>( Renderer::Property::BLEND_FACTOR_SRC_ALPHA );
411   int destFactorAlpha = renderer1.GetProperty<int>( Renderer::Property::BLEND_FACTOR_DEST_ALPHA );
412   DALI_TEST_CHECK( srcFactorRgb == BlendFactor::SRC_ALPHA );
413   DALI_TEST_CHECK( destFactorRgb == BlendFactor::ONE_MINUS_SRC_ALPHA );
414   DALI_TEST_CHECK( srcFactorAlpha == BlendFactor::ONE );
415   DALI_TEST_CHECK( destFactorAlpha == BlendFactor::ONE_MINUS_SRC_ALPHA );
416
417   DALI_TEST_EQUALS( textureTrace.FindMethod("GenTextures"), true, TEST_LOCATION );  // A new texture should be generated.
418   textureTrace.Reset();
419
420   ImageView imageView2 = ImageView::New();
421   imageView2.SetProperty( ImageView::Property::IMAGE, imageMap );
422
423   // Disable pre-multiplied alpha blending
424   imageView2.SetProperty( ImageView::Property::PRE_MULTIPLIED_ALPHA, false );
425
426   application.GetScene().Add( imageView2 );
427
428   application.SendNotification();
429   application.Render();
430
431   value = imageView2.GetProperty( ImageView::Property::PRE_MULTIPLIED_ALPHA );
432   DALI_TEST_CHECK( value.Get( enable ) );
433   DALI_TEST_CHECK( !enable );
434
435   // conventional alpha blending
436   Renderer renderer2 = imageView2.GetRendererAt( 0 );
437   value = renderer2.GetProperty( Renderer::Property::BLEND_PRE_MULTIPLIED_ALPHA );
438   DALI_TEST_CHECK( value.Get( enable ) );
439   DALI_TEST_CHECK( !enable );
440
441   srcFactorRgb    = renderer2.GetProperty<int>( Renderer::Property::BLEND_FACTOR_SRC_RGB );
442   destFactorRgb   = renderer2.GetProperty<int>( Renderer::Property::BLEND_FACTOR_DEST_RGB );
443   srcFactorAlpha  = renderer2.GetProperty<int>( Renderer::Property::BLEND_FACTOR_SRC_ALPHA );
444   destFactorAlpha = renderer2.GetProperty<int>( Renderer::Property::BLEND_FACTOR_DEST_ALPHA );
445   DALI_TEST_CHECK( srcFactorRgb == BlendFactor::SRC_ALPHA );
446   DALI_TEST_CHECK( destFactorRgb == BlendFactor::ONE_MINUS_SRC_ALPHA );
447   DALI_TEST_CHECK( srcFactorAlpha == BlendFactor::ONE );
448   DALI_TEST_CHECK( destFactorAlpha == BlendFactor::ONE_MINUS_SRC_ALPHA );
449
450   DALI_TEST_EQUALS( textureTrace.FindMethod("GenTextures"), false, TEST_LOCATION ); // The cached texture should be used.
451
452   END_TEST;
453 }
454
455 int UtcDaliImageViewPixelArea(void)
456 {
457   // Test pixel area property
458   ToolkitTestApplication application;
459
460   static std::vector<UniformData> customUniforms =
461   {
462     UniformData("pixelArea", Property::Type::VECTOR4),
463   };
464
465   TestGraphicsController& graphics = application.GetGraphicsController();
466   graphics.AddCustomUniforms(customUniforms);
467
468   // Gif image, use AnimatedImageVisual internally
469   // Atlasing is applied to pack multiple frames, use custom wrap mode
470   ImageView gifView = ImageView::New();
471   const Vector4 pixelAreaVisual( 0.f, 0.f, 2.f, 2.f );
472   gifView.SetProperty( ImageView::Property::IMAGE,
473                        Property::Map().Add( ImageVisual::Property::URL, TEST_GIF_FILE_NAME )
474                                       .Add( ImageVisual::Property::PIXEL_AREA, pixelAreaVisual ) );
475
476   // Add to stage
477   Integration::Scene stage = application.GetScene();
478   stage.Add( gifView );
479
480   // loading started
481   application.SendNotification();
482   application.Render(16);
483
484   DALI_TEST_EQUALS( Test::WaitForEventThreadTrigger( 2 ), true, TEST_LOCATION );
485
486   application.SendNotification();
487   application.Render();
488   DALI_TEST_CHECK( gifView.GetRendererCount() == 1u );
489
490   const Vector4 fullTextureRect( 0.f, 0.f, 1.f, 1.f );
491   // test that the pixel area value defined in the visual property map is registered on renderer
492   Renderer renderer = gifView.GetRendererAt(0);
493   Property::Value pixelAreaValue = renderer.GetProperty( renderer.GetPropertyIndex( "pixelArea" ) );
494   DALI_TEST_EQUALS( pixelAreaValue.Get<Vector4>(), pixelAreaVisual, TEST_LOCATION );
495
496   // test that the shader has the default pixel area value registered.
497   Shader shader = renderer.GetShader();
498   pixelAreaValue = shader.GetProperty( shader.GetPropertyIndex( "pixelArea" ) );
499   DALI_TEST_EQUALS( pixelAreaValue.Get<Vector4>(), fullTextureRect, TEST_LOCATION );
500
501   // test that the uniform uses the pixelArea property on the renderer.
502   TestGlAbstraction& gl = application.GetGlAbstraction();
503   Vector4 pixelAreaUniform;
504   DALI_TEST_CHECK( gl.GetUniformValue<Vector4>( "pixelArea", pixelAreaUniform ) );
505   DALI_TEST_EQUALS( pixelAreaVisual, pixelAreaUniform, Math::MACHINE_EPSILON_100, TEST_LOCATION );
506
507   // set the pixelArea property on the control
508   const Vector4 pixelAreaControl( -1.f, -1.f, 3.f, 3.f );
509   gifView.SetProperty( ImageView::Property::PIXEL_AREA, pixelAreaControl );
510   application.SendNotification();
511   application.Render(16);
512
513   // check the pixelArea property on the control
514   pixelAreaValue = gifView.GetProperty( gifView.GetPropertyIndex( "pixelArea" ) );
515   DALI_TEST_EQUALS( pixelAreaValue.Get<Vector4>(), pixelAreaControl, TEST_LOCATION );
516   // test that the uniform uses the pixelArea property on the control.
517   DALI_TEST_CHECK( gl.GetUniformValue<Vector4>( "pixelArea", pixelAreaUniform ) );
518   DALI_TEST_EQUALS( pixelAreaControl, pixelAreaUniform, Math::MACHINE_EPSILON_100, TEST_LOCATION );
519
520
521   END_TEST;
522 }
523
524 int UtcDaliImageViewAsyncLoadingWithoutAltasing(void)
525 {
526   ToolkitTestApplication application;
527   TestGlAbstraction& gl = application.GetGlAbstraction();
528   const std::vector<GLuint>& textures = gl.GetBoundTextures();
529   size_t numTextures = textures.size();
530
531   // Async loading, no atlasing for big size image
532   ImageView imageView = ImageView::New( gImage_600_RGB );
533
534   // By default, Aysnc loading is used
535   application.GetScene().Add( imageView );
536   imageView.SetProperty( Actor::Property::SIZE, Vector2(100, 100) );
537   imageView.SetProperty( Actor::Property::PARENT_ORIGIN, ParentOrigin::CENTER );
538
539   DALI_TEST_EQUALS( Test::WaitForEventThreadTrigger( 1 ), true, TEST_LOCATION );
540
541   application.SendNotification();
542   application.Render(16);
543   application.SendNotification();
544
545   const std::vector<GLuint>& textures2 = gl.GetBoundTextures();
546   DALI_TEST_GREATER( textures2.size(), numTextures, TEST_LOCATION );
547
548   END_TEST;
549 }
550
551 int UtcDaliImageViewAsyncLoadingWithAtlasing(void)
552 {
553   ToolkitTestApplication application;
554
555   //Async loading, automatic atlasing for small size image
556   TraceCallStack& callStack = application.GetGlAbstraction().GetTextureTrace();
557   callStack.Reset();
558   callStack.Enable(true);
559
560   Property::Map imageMap;
561
562   imageMap[ ImageVisual::Property::URL ] = gImage_34_RGBA;
563   imageMap[ ImageVisual::Property::DESIRED_HEIGHT ] = 34;
564   imageMap[ ImageVisual::Property::DESIRED_WIDTH ] = 34;
565   imageMap[ ImageVisual::Property::ATLASING] = true;
566
567   ImageView imageView = ImageView::New();
568   imageView.SetProperty( ImageView::Property::IMAGE, imageMap );
569   imageView.SetProperty( Toolkit::Control::Property::PADDING, Extents( 10u, 10u, 10u, 10u ) );
570
571   // By default, Aysnc loading is used
572   // loading is not started if the actor is offScene
573
574   application.GetScene().Add( imageView );
575   application.SendNotification();
576   application.Render(16);
577   application.Render(16);
578   application.SendNotification();
579
580   imageView.SetProperty( Dali::Actor::Property::LAYOUT_DIRECTION,  Dali::LayoutDirection::RIGHT_TO_LEFT );
581   application.SendNotification();
582   application.Render(16);
583   application.Render(16);
584   application.SendNotification();
585
586   // loading started, this waits for the loader thread for max 30 seconds
587   DALI_TEST_EQUALS( Test::WaitForEventThreadTrigger( 1 ), true, TEST_LOCATION );
588
589   application.SendNotification();
590   application.Render(16);
591
592   callStack.Enable(false);
593
594   TraceCallStack::NamedParams params;
595   params["width"] << 34;
596   params["height"] << 34;
597 DALI_TEST_EQUALS( callStack.FindMethodAndParams( "TexSubImage2D", params ), true, TEST_LOCATION );
598
599   END_TEST;
600 }
601
602 int UtcDaliImageViewAsyncLoadingWithAtlasing02(void)
603 {
604   ToolkitTestApplication application;
605
606   //Async loading, automatic atlasing for small size image
607   TraceCallStack& callStack = application.GetGlAbstraction().GetTextureTrace();
608   callStack.Reset();
609   callStack.Enable(true);
610
611   Property::Map asyncLoadingMap;
612   asyncLoadingMap[ "url" ] = gImage_34_RGBA;
613   asyncLoadingMap[ "desiredHeight" ] = 34;
614   asyncLoadingMap[ "desiredWidth" ] = 34;
615   asyncLoadingMap[ "synchronousLoading" ] = false;
616   asyncLoadingMap[ "atlasing" ] = true;
617
618   ImageView imageView = ImageView::New();
619   imageView.SetProperty( ImageView::Property::IMAGE, asyncLoadingMap );
620
621   application.GetScene().Add( imageView );
622   application.SendNotification();
623   application.Render(16);
624   application.Render(16);
625   application.SendNotification();
626
627   // loading started, this waits for the loader thread for max 30 seconds
628   DALI_TEST_EQUALS( Test::WaitForEventThreadTrigger( 1 ), true, TEST_LOCATION );
629
630   application.SendNotification();
631   application.Render(16);
632
633   callStack.Enable(false);
634
635   TraceCallStack::NamedParams params;
636   params["width"] << 34;
637   params["height"] << 34;
638   DALI_TEST_EQUALS( callStack.FindMethodAndParams( "TexSubImage2D", params ), true, TEST_LOCATION );
639
640   END_TEST;
641 }
642
643 int UtcDaliImageViewSyncLoading(void)
644 {
645   ToolkitTestApplication application;
646
647   tet_infoline("ImageView Testing sync loading and size using index key property map");
648
649   Property::Map syncLoadingMap;
650   syncLoadingMap[ ImageVisual::Property::SYNCHRONOUS_LOADING ] = true;
651   syncLoadingMap[ ImageVisual::Property::ATLASING ] = true;
652
653   // Sync loading, no atlasing for big size image
654   {
655     ImageView imageView = ImageView::New();
656
657     // Sync loading is used
658     syncLoadingMap[ ImageVisual::Property::URL ] = gImage_600_RGB;
659     imageView.SetProperty( ImageView::Property::IMAGE, syncLoadingMap );
660   }
661
662   // Sync loading, automatic atlasing for small size image
663   {
664     TraceCallStack& callStack = application.GetGlAbstraction().GetTextureTrace();
665     callStack.Reset();
666     callStack.Enable(true);
667
668     ImageView imageView = ImageView::New( );
669
670     // Sync loading is used
671     syncLoadingMap[ ImageVisual::Property::URL ] = gImage_34_RGBA;
672     syncLoadingMap[ ImageVisual::Property::DESIRED_HEIGHT ] = 34;
673     syncLoadingMap[ ImageVisual::Property::DESIRED_WIDTH ] = 34;
674     imageView.SetProperty( ImageView::Property::IMAGE, syncLoadingMap );
675
676     application.GetScene().Add( imageView );
677     application.SendNotification();
678     application.Render(16);
679
680     TraceCallStack::NamedParams params;
681     params["width"] << 34;
682     params["height"] << 34;
683     DALI_TEST_EQUALS( callStack.FindMethodAndParams( "TexSubImage2D", params ),
684                       true, TEST_LOCATION );
685   }
686   END_TEST;
687 }
688
689 int UtcDaliImageViewSyncLoading02(void)
690 {
691   ToolkitTestApplication application;
692
693   tet_infoline("ImageView Testing sync loading and size using string key property map");
694
695   // Sync loading, automatic atlasing for small size image
696   {
697     TraceCallStack& callStack = application.GetGlAbstraction().GetTextureTrace();
698     callStack.Reset();
699     callStack.Enable(true);
700
701     ImageView imageView = ImageView::New( );
702
703     // Sync loading is used
704     Property::Map syncLoadingMap;
705     syncLoadingMap[ "url" ] = gImage_34_RGBA;
706     syncLoadingMap[ "desiredHeight" ] = 34;
707     syncLoadingMap[ "desiredWidth" ] = 34;
708     syncLoadingMap[ "synchronousLoading" ] = true;
709     syncLoadingMap[ "atlasing" ] = true;
710     imageView.SetProperty( ImageView::Property::IMAGE, syncLoadingMap );
711
712     application.GetScene().Add( imageView );
713     application.SendNotification();
714     application.Render(16);
715
716     TraceCallStack::NamedParams params;
717     params["width"] << 34;
718     params["height"] << 34;
719     DALI_TEST_EQUALS( callStack.FindMethodAndParams( "TexSubImage2D", params ),
720                       true, TEST_LOCATION );
721   }
722   END_TEST;
723 }
724
725 int UtcDaliImageViewAsyncLoadingEncodedBuffer(void)
726 {
727   ToolkitTestApplication application;
728   TestGlAbstraction& gl = application.GetGlAbstraction();
729   const std::vector<GLuint>& textures = gl.GetBoundTextures();
730   size_t numTextures = textures.size();
731
732   // Get encoded raw-buffer image and generate url
733   EncodedImageBuffer buffer = ConvertFileToEncodedImageBuffer(gImage_600_RGB);
734   ImageUrl           url    = Toolkit::Image::GenerateUrl(buffer);
735
736   // Async loading, no atlasing for big size image
737   ImageView imageView = ImageView::New(url.GetUrl());
738
739   // By default, Aysnc loading is used
740   application.GetScene().Add(imageView);
741   imageView.SetProperty( Actor::Property::SIZE, Vector2(100, 100) );
742   imageView.SetProperty( Actor::Property::PARENT_ORIGIN, ParentOrigin::CENTER );
743
744   DALI_TEST_EQUALS( Test::WaitForEventThreadTrigger( 1 ), true, TEST_LOCATION );
745
746   application.SendNotification();
747   application.Render(16);
748   application.SendNotification();
749
750   const std::vector<GLuint>& textures2 = gl.GetBoundTextures();
751   DALI_TEST_GREATER( textures2.size(), numTextures, TEST_LOCATION );
752
753   END_TEST;
754 }
755
756 int UtcDaliImageViewAsyncLoadingEncodedBufferWithAtlasing(void)
757 {
758   ToolkitTestApplication application;
759
760   // Get encoded raw-buffer image and generate url
761   EncodedImageBuffer buffer = ConvertFileToEncodedImageBuffer(gImage_600_RGB);
762   ImageUrl           url    = Toolkit::Image::GenerateUrl(buffer);
763   ImageUrl           url2   = Toolkit::Image::GenerateUrl(buffer);
764
765   // Generate url is not equal to url2
766   // NOTE : This behavior may changed when ImageUrl compare operator changed.
767   DALI_TEST_CHECK(url != url2);
768   // Generate url's string is equal to url2's string
769   DALI_TEST_CHECK(url.GetUrl() == url2.GetUrl());
770
771   EncodedImageBuffer buffer2 = ConvertFileToEncodedImageBuffer(gImage_600_RGB);
772   url2 = Toolkit::Image::GenerateUrl(buffer2);
773
774   // Check whethere two url are not equal
775   DALI_TEST_CHECK(url.GetUrl() != url2.GetUrl());
776
777   // Async loading, automatic atlasing for small size image
778   TraceCallStack& callStack = application.GetGlAbstraction().GetTextureTrace();
779   callStack.Reset();
780   callStack.Enable(true);
781
782   Property::Map imageMap;
783
784   imageMap[ ImageVisual::Property::URL ] = url.GetUrl();
785   imageMap[ ImageVisual::Property::DESIRED_HEIGHT ] = 34;
786   imageMap[ ImageVisual::Property::DESIRED_WIDTH ] = 34;
787   imageMap[ ImageVisual::Property::ATLASING] = true;
788
789   ImageView imageView = ImageView::New();
790   imageView.SetProperty( ImageView::Property::IMAGE, imageMap );
791   imageView.SetProperty( Toolkit::Control::Property::PADDING, Extents( 10u, 10u, 10u, 10u ) );
792
793   // By default, Aysnc loading is used
794   // loading is not started if the actor is offScene
795
796   application.GetScene().Add( imageView );
797   application.SendNotification();
798   application.Render(16);
799   application.Render(16);
800   application.SendNotification();
801
802   // Change url to url2
803   imageMap[ ImageVisual::Property::URL ] = url2.GetUrl();
804   imageView.SetProperty( ImageView::Property::IMAGE, imageMap );
805
806   imageView.SetProperty( Dali::Actor::Property::LAYOUT_DIRECTION,  Dali::LayoutDirection::RIGHT_TO_LEFT );
807   application.SendNotification();
808   application.Render(16);
809   application.Render(16);
810   application.SendNotification();
811
812   // loading started, this waits for the loader thread for max 30 seconds
813   DALI_TEST_EQUALS( Test::WaitForEventThreadTrigger( 1 ), true, TEST_LOCATION );
814
815   application.SendNotification();
816   application.Render(16);
817
818   callStack.Enable(false);
819
820   TraceCallStack::NamedParams params;
821   params["width"] << 34;
822   params["height"] << 34;
823   DALI_TEST_EQUALS( callStack.FindMethodAndParams( "TexSubImage2D", params ), true, TEST_LOCATION );
824
825   END_TEST;
826 }
827
828 int UtcDaliImageViewSyncLoadingEncodedBuffer(void)
829 {
830   ToolkitTestApplication application;
831
832   tet_infoline("ImageView Testing sync loading from EncodedImageBuffer");
833
834   // Get encoded raw-buffer image and generate url
835   EncodedImageBuffer buffer = ConvertFileToEncodedImageBuffer(gImage_34_RGBA);
836   ImageUrl           url    = Toolkit::Image::GenerateUrl(buffer);
837
838   // Sync loading, automatic atlasing for small size image
839   {
840     TraceCallStack& callStack = application.GetGlAbstraction().GetTextureTrace();
841     callStack.Reset();
842     callStack.Enable(true);
843
844     ImageView imageView = ImageView::New( );
845
846     // Sync loading is used
847     Property::Map syncLoadingMap;
848     syncLoadingMap[ "url" ] = url.GetUrl();
849     syncLoadingMap[ "desiredHeight" ] = 34;
850     syncLoadingMap[ "desiredWidth" ] = 34;
851     syncLoadingMap[ "synchronousLoading" ] = true;
852     syncLoadingMap[ "atlasing" ] = true;
853     imageView.SetProperty( ImageView::Property::IMAGE, syncLoadingMap );
854
855     application.GetScene().Add( imageView );
856     application.SendNotification();
857     application.Render(16);
858
859     TraceCallStack::NamedParams params;
860     params["width"] << 34;
861     params["height"] << 34;
862     DALI_TEST_EQUALS( callStack.FindMethodAndParams( "TexSubImage2D", params ),
863                       true, TEST_LOCATION );
864   }
865
866   END_TEST;
867 }
868
869 int UtcDaliImageViewAddedTexture(void)
870 {
871   ToolkitTestApplication application;
872
873   tet_infoline("ImageView Testing image view with texture provided manager url");
874
875   ImageView imageView = ImageView::New();
876
877   // empty texture is ok, though pointless from app point of view
878   TextureSet  empty;
879   std::string url = TextureManager::AddTexture(empty);
880   DALI_TEST_CHECK(url.size() > 0u);
881
882   Property::Map propertyMap;
883   propertyMap[ImageVisual::Property::URL] = url;
884   imageView.SetProperty(ImageView::Property::IMAGE, propertyMap);
885
886   application.GetScene().Add( imageView );
887   application.SendNotification();
888   application.Render();
889
890   END_TEST;
891 }
892
893 int UtcDaliImageViewSizeWithBackground(void)
894 {
895   ToolkitTestApplication application;
896
897   int width = 100;
898   int height = 200;
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, width },
906                            { ImageVisual::Property::DESIRED_HEIGHT, height },
907                          }
908                        );
909
910   application.GetScene().Add( imageView );
911   application.SendNotification();
912   application.Render();
913
914   DALI_TEST_EQUALS( imageView.GetCurrentProperty< Vector3 >( Actor::Property::SIZE ).width, (float)width, TEST_LOCATION );
915   DALI_TEST_EQUALS( imageView.GetCurrentProperty< Vector3 >( Actor::Property::SIZE ).height, (float)height, TEST_LOCATION );
916
917   END_TEST;
918 }
919
920 int UtcDaliImageViewSizeWithBackgroundAndImage(void)
921 {
922   ToolkitTestApplication application;
923
924   int widthBackground = 100;
925   int heightBackground = 200;
926   int width = 600;
927   int height = 600;
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   imageView.SetImage( gImage_600_RGB ); // 1 to 1 ratio, 600x600 pixels
941
942   application.GetScene().Add( imageView );
943   application.SendNotification();
944   application.Render();
945
946   DALI_TEST_EQUALS( imageView.GetCurrentProperty< Vector3 >( Actor::Property::SIZE ).width, (float)width, TEST_LOCATION );
947   DALI_TEST_EQUALS( imageView.GetCurrentProperty< Vector3 >( Actor::Property::SIZE ).height, (float)height, TEST_LOCATION );
948
949   END_TEST;
950 }
951
952 int UtcDaliImageViewHeightForWidthBackground(void)
953 {
954   ToolkitTestApplication application;
955
956   int widthBackground = 100;
957   int heightBackground = 200;
958
959   ImageView imageView = ImageView::New();
960
961   imageView.SetProperty( Control::Property::BACKGROUND,
962                          {
963                            { Toolkit::Visual::Property::TYPE, Toolkit::Visual::IMAGE },
964                            { Toolkit::ImageVisual::Property::URL, TEST_RESOURCE_DIR "/gallery-small-1.jpg" },
965                            { ImageVisual::Property::DESIRED_WIDTH, widthBackground },
966                            { ImageVisual::Property::DESIRED_HEIGHT, heightBackground }
967                          }
968                        );
969
970   application.GetScene().Add( imageView );
971   application.SendNotification();
972   application.Render();
973
974   Control control = Control::DownCast( imageView );
975   DALI_TEST_CHECK( control );
976   DALI_TEST_EQUALS( imageView.GetHeightForWidth( 123.f ), control.GetHeightForWidth( 123.f ), TEST_LOCATION );
977   DALI_TEST_EQUALS( imageView.GetWidthForHeight( 321.f ), control.GetWidthForHeight( 321.f ), TEST_LOCATION );
978
979   END_TEST;
980 }
981
982 int UtcDaliImageViewHeightForWidthBackgroundAndImage(void)
983 {
984   ToolkitTestApplication application;
985
986   int widthBackground = 100;
987   int heightBackground = 200;
988   int width = 300;
989   int height = 300;
990
991   ImageView imageView = ImageView::New();
992
993   imageView.SetProperty( Control::Property::BACKGROUND,
994                          {
995                            { Toolkit::Visual::Property::TYPE, Toolkit::Visual::IMAGE },
996                            { Toolkit::ImageVisual::Property::URL, TEST_RESOURCE_DIR "/gallery-small-1.jpg" },
997                            { ImageVisual::Property::DESIRED_WIDTH, widthBackground },
998                            { ImageVisual::Property::DESIRED_HEIGHT, heightBackground }
999                          }
1000                        ); // 1 to 2 ratio
1001
1002   imageView.SetImage( gImage_600_RGB ); // 1 to 1 ratio
1003
1004   application.GetScene().Add( imageView );
1005   application.SendNotification();
1006   application.Render();
1007
1008   DALI_TEST_EQUALS( imageView.GetHeightForWidth( width ), (float)height, TEST_LOCATION );
1009   DALI_TEST_EQUALS( imageView.GetWidthForHeight( height ), (float)width, TEST_LOCATION );
1010
1011   END_TEST;
1012 }
1013
1014 int UtcDaliImageViewSetImageUrl(void)
1015 {
1016   ToolkitTestApplication application;
1017
1018   ImageView imageView = ImageView::New();
1019   imageView.SetImage( TEST_IMAGE_FILE_NAME );
1020   TestUrl( imageView, TEST_IMAGE_FILE_NAME );
1021
1022
1023   imageView.SetImage( TEST_IMAGE_FILE_NAME2 );
1024   TestUrl( imageView, TEST_IMAGE_FILE_NAME2 );
1025
1026   END_TEST;
1027 }
1028
1029 bool gResourceReadySignalFired = false;
1030 Vector3 gNaturalSize;
1031
1032 void ResourceReadySignal( Control control )
1033 {
1034   gResourceReadySignalFired = true;
1035 }
1036
1037 int UtcDaliImageViewCheckResourceReady(void)
1038 {
1039   ToolkitTestApplication application;
1040
1041   gResourceReadySignalFired = false;
1042
1043   // Check ImageView with background and main image, to ensure both visuals are marked as loaded
1044   ImageView imageView = ImageView::New( TEST_GIF_FILE_NAME );
1045
1046   imageView.SetProperty( Control::Property::BACKGROUND,
1047                          {
1048                            { Toolkit::Visual::Property::TYPE, Toolkit::Visual::IMAGE },
1049                            { Toolkit::ImageVisual::Property::URL, TEST_RESOURCE_DIR "/gallery-small-1.jpg" },
1050                            { ImageVisual::Property::DESIRED_WIDTH, 100 },
1051                            { ImageVisual::Property::DESIRED_HEIGHT, 200 }
1052                           }
1053                        );
1054
1055   DALI_TEST_EQUALS( imageView.IsResourceReady(), false, TEST_LOCATION );
1056
1057   imageView.ResourceReadySignal().Connect( &ResourceReadySignal);
1058
1059   application.GetScene().Add( imageView );
1060
1061   // loading started, this waits for the loader thread
1062   DALI_TEST_EQUALS( Test::WaitForEventThreadTrigger( 1 ), true, TEST_LOCATION );
1063
1064   application.SendNotification();
1065   application.Render(16);
1066
1067   DALI_TEST_EQUALS( Test::WaitForEventThreadTrigger( 2 ), true, TEST_LOCATION );
1068
1069   application.SendNotification();
1070   application.Render();
1071
1072   DALI_TEST_EQUALS( imageView.IsResourceReady(), true, TEST_LOCATION );
1073
1074   DALI_TEST_EQUALS( gResourceReadySignalFired, true, TEST_LOCATION );
1075
1076   END_TEST;
1077 }
1078
1079 int UtcDaliImageViewSetImageTypeChangesP(void)
1080 {
1081   ToolkitTestApplication application;
1082
1083   ImageView imageView = ImageView::New();
1084   Toolkit::Internal::Control& controlImpl = Toolkit::Internal::GetImplementation( imageView );
1085
1086   application.GetScene().Add( imageView );
1087
1088   std::string url;
1089   Property::Map map;
1090   Toolkit::Visual::Base visual;
1091
1092   Property::Value value = imageView.GetProperty( imageView.GetPropertyIndex( "image" ) );
1093   visual = DevelControl::GetVisual( controlImpl, ImageView::Property::IMAGE );
1094
1095   application.SendNotification();
1096   application.Render( 16 );
1097
1098   DALI_TEST_CHECK( ! value.Get( url ) ); // Value should be empty
1099   value.Get( map );
1100   DALI_TEST_CHECK( map.Empty() );        // Value should be empty
1101   DALI_TEST_CHECK( ! visual );           // Visual should be invalid
1102
1103   // Set a URL
1104   imageView.SetImage( "TEST_URL" );
1105
1106   application.SendNotification();
1107   application.Render( 16 );
1108
1109   value = imageView.GetProperty( imageView.GetPropertyIndex( "image" ) );
1110   visual = DevelControl::GetVisual( controlImpl, ImageView::Property::IMAGE );
1111
1112   DALI_TEST_CHECK( value.Get( url ) );   // Value should NOT be empty
1113   DALI_TEST_CHECK( ! value.Get( map ) ); // Value should be empty
1114   DALI_TEST_CHECK( visual );             // Visual should be valid
1115
1116   // Set an empty URL
1117   imageView.SetImage( "" );
1118
1119   application.SendNotification();
1120   application.Render( 16 );
1121
1122   value = imageView.GetProperty( imageView.GetPropertyIndex( "image" ) );
1123   visual = DevelControl::GetVisual( controlImpl, ImageView::Property::IMAGE );
1124
1125   DALI_TEST_CHECK( ! value.Get( url ) ); // Value should be empty
1126   value.Get( map );
1127   DALI_TEST_CHECK( map.Empty() );        // Value should be empty
1128   DALI_TEST_CHECK( ! visual );           // Visual should be invalid
1129
1130   // Set a URL in property map
1131   Property::Map propertyMap;
1132   propertyMap[ImageVisual::Property::URL] = TEST_IMAGE_FILE_NAME;
1133   imageView.SetProperty( ImageView::Property::IMAGE, propertyMap );
1134
1135   application.SendNotification();
1136   application.Render( 16 );
1137
1138   value = imageView.GetProperty( imageView.GetPropertyIndex( "image" ) );
1139   visual = DevelControl::GetVisual( controlImpl, ImageView::Property::IMAGE );
1140
1141   DALI_TEST_CHECK( ! value.Get( url ) ); // Value should be empty
1142   DALI_TEST_CHECK( value.Get( map ) );   // Value should NOT be empty
1143   DALI_TEST_CHECK( visual );             // Visual should be valid
1144
1145   // Set a URL in property map again
1146   propertyMap[ImageVisual::Property::URL] = gImage_34_RGBA;
1147   imageView.SetProperty( ImageView::Property::IMAGE, propertyMap );
1148
1149   application.SendNotification();
1150   application.Render( 16 );
1151
1152   value = imageView.GetProperty( imageView.GetPropertyIndex( "image" ) );
1153   visual = DevelControl::GetVisual( controlImpl, ImageView::Property::IMAGE );
1154
1155   DALI_TEST_CHECK( ! value.Get( url ) ); // Value should be empty
1156   DALI_TEST_CHECK( value.Get( map ) );   // Value should NOT be empty
1157   DALI_TEST_CHECK( visual );             // Visual should be valid
1158
1159   // Set an empty URL in property map
1160   propertyMap[ImageVisual::Property::URL] = std::string();
1161   imageView.SetProperty( ImageView::Property::IMAGE, propertyMap );
1162
1163   application.SendNotification();
1164   application.Render( 16 );
1165
1166   value = imageView.GetProperty( imageView.GetPropertyIndex( "image" ) );
1167   visual = DevelControl::GetVisual( controlImpl, ImageView::Property::IMAGE );
1168
1169   DALI_TEST_CHECK( ! value.Get( url ) ); // Value should be empty
1170   DALI_TEST_CHECK( value.Get( map ) );   // Value should NOT be empty
1171   DALI_TEST_CHECK( ! visual );           // Visual should be invalid
1172
1173   END_TEST;
1174 }
1175
1176 int UtcDaliImageViewResourceUrlP(void)
1177 {
1178   ToolkitTestApplication application;
1179
1180   ImageView imageView = ImageView::New();
1181   DALI_TEST_CHECK( imageView.GetProperty( ImageView::Property::IMAGE ).Get< std::string >().empty() );
1182
1183   imageView.SetProperty( ImageView::Property::IMAGE, "TestString" );
1184   DALI_TEST_EQUALS( imageView.GetProperty( ImageView::Property::IMAGE ).Get< std::string >(), "TestString", TEST_LOCATION );
1185
1186   END_TEST;
1187 }
1188
1189 int UtcDaliImageViewReplaceImage(void)
1190 {
1191   ToolkitTestApplication application;
1192
1193   gResourceReadySignalFired = false;
1194
1195   // Check ImageView with background and main image, to ensure both visuals are marked as loaded
1196   ImageView imageView = ImageView::New( TEST_IMAGE_1 );
1197
1198   DALI_TEST_EQUALS( imageView.IsResourceReady(), false, TEST_LOCATION );
1199
1200   imageView.ResourceReadySignal().Connect( &ResourceReadySignal);
1201
1202   application.GetScene().Add( imageView );
1203
1204   application.SendNotification();
1205   application.Render(16);
1206
1207   // loading started, this waits for the loader thread for max 30 seconds
1208   DALI_TEST_EQUALS( Test::WaitForEventThreadTrigger( 1 ), true, TEST_LOCATION );
1209
1210   DALI_TEST_EQUALS( imageView.GetRendererCount(), 1u, TEST_LOCATION );
1211
1212   DALI_TEST_EQUALS( gResourceReadySignalFired, true, TEST_LOCATION );
1213
1214   gResourceReadySignalFired = false;
1215
1216   imageView.SetImage(TEST_IMAGE_2);
1217
1218   application.SendNotification();
1219   application.Render(16);
1220
1221   // loading started, this waits for the loader thread for max 30 seconds
1222   DALI_TEST_EQUALS( Test::WaitForEventThreadTrigger( 1 ), true, TEST_LOCATION );
1223
1224   DALI_TEST_EQUALS( imageView.GetRendererCount(), 1u, TEST_LOCATION );
1225
1226   DALI_TEST_EQUALS( imageView.IsResourceReady(), true, TEST_LOCATION );
1227
1228   DALI_TEST_EQUALS( gResourceReadySignalFired, true, TEST_LOCATION );
1229
1230   END_TEST;
1231 }
1232
1233 void OnRelayoutOverride( Size size )
1234 {
1235   gNaturalSize = size; // Size Relayout is using
1236 }
1237
1238 int UtcDaliImageViewReplaceImageAndGetNaturalSize(void)
1239 {
1240   ToolkitTestApplication application;
1241
1242   // Check ImageView with background and main image, to ensure both visuals are marked as loaded
1243   ImageView imageView = ImageView::New( TEST_IMAGE_1 );
1244   imageView.SetResizePolicy( ResizePolicy::USE_NATURAL_SIZE, Dimension::ALL_DIMENSIONS );
1245
1246   DummyControl dummyControl = DummyControl::New( true );
1247   Impl::DummyControl& dummyImpl = static_cast<Impl::DummyControl&>(dummyControl.GetImplementation());
1248   dummyControl.SetResizePolicy( ResizePolicy::FIT_TO_CHILDREN, Dimension::ALL_DIMENSIONS );
1249
1250   dummyControl.Add( imageView );
1251   dummyImpl.SetRelayoutCallback( &OnRelayoutOverride );
1252   application.GetScene().Add( dummyControl );
1253
1254   application.SendNotification();
1255   application.Render();
1256
1257   // loading started, this waits for the loader thread for max 30 seconds
1258   DALI_TEST_EQUALS( Test::WaitForEventThreadTrigger( 1 ), true, TEST_LOCATION );
1259
1260   DALI_TEST_EQUALS( gNaturalSize.width, 1024.0f, TEST_LOCATION );
1261   DALI_TEST_EQUALS( gNaturalSize.height, 1024.0f, TEST_LOCATION );
1262
1263   gNaturalSize = Vector3::ZERO;
1264
1265   imageView.SetImage(gImage_600_RGB);
1266
1267   // Waiting for resourceReady so SendNotifcation not called here.
1268
1269   // loading started, this waits for the loader thread for max 30 seconds
1270   DALI_TEST_EQUALS( Test::WaitForEventThreadTrigger( 1 ), true, TEST_LOCATION );
1271
1272   // Trigger a potential relayout
1273   application.SendNotification();
1274   application.Render();
1275
1276   DALI_TEST_EQUALS( gNaturalSize.width, 600.0f, TEST_LOCATION );
1277   DALI_TEST_EQUALS( gNaturalSize.height, 600.0f, TEST_LOCATION );
1278
1279   END_TEST;
1280 }
1281
1282 int UtcDaliImageViewResourceReadySignalWithImmediateLoad(void)
1283 {
1284   tet_infoline("Test Setting Image with IMMEDIATE load and receving ResourceReadySignal before staged.");
1285
1286   ToolkitTestApplication application;
1287
1288   gResourceReadySignalFired = false;
1289
1290   Property::Map imageMap;
1291
1292   imageMap[ ImageVisual::Property::URL ] = gImage_34_RGBA;
1293   imageMap[ ImageVisual::Property::LOAD_POLICY ] =  ImageVisual::LoadPolicy::IMMEDIATE;
1294
1295   tet_infoline("Creating ImageView without URL so image does not start loading");
1296   ImageView imageView = ImageView::New();
1297   tet_infoline("Connect to image loaded signal before setting image");
1298   imageView.ResourceReadySignal().Connect( &ResourceReadySignal);
1299   tet_infoline("Setting Image with IMMEDIATE load, signal already connected so will be triggered.");
1300   imageView.SetProperty( ImageView::Property::IMAGE, imageMap );
1301
1302   // loading started, this waits for the loader thread
1303   DALI_TEST_EQUALS( Test::WaitForEventThreadTrigger( 1 ), true, TEST_LOCATION );
1304
1305   application.SendNotification();
1306   application.Render(16);
1307
1308   DALI_TEST_EQUALS( gResourceReadySignalFired, true, TEST_LOCATION );
1309
1310   END_TEST;
1311 }
1312
1313 int UtcDaliImageViewResourceReadySignalWithReusedImage(void)
1314 {
1315   tet_infoline("Test Setting Image that was already loaded by another ImageView and still getting ResourceReadySignal.");
1316
1317   ToolkitTestApplication application;
1318
1319   gResourceReadySignalFired = false;
1320
1321   Property::Map imageMap;
1322
1323   imageMap[ ImageVisual::Property::URL ] = gImage_34_RGBA;
1324   imageMap[ ImageVisual::Property::LOAD_POLICY ] =  ImageVisual::LoadPolicy::IMMEDIATE;
1325
1326   ImageView imageView = ImageView::New();
1327   imageView.ResourceReadySignal().Connect( &ResourceReadySignal);
1328   imageView.SetProperty( ImageView::Property::IMAGE, imageMap );
1329
1330   // loading started, this waits for the loader thread
1331   DALI_TEST_EQUALS( Test::WaitForEventThreadTrigger( 1 ), true, TEST_LOCATION );
1332
1333   application.SendNotification();
1334   application.Render(16);
1335
1336   DALI_TEST_EQUALS( gResourceReadySignalFired, true, TEST_LOCATION );
1337   gResourceReadySignalFired = false;
1338
1339   ImageView imageViewWithExistingImage = ImageView::New();
1340   imageViewWithExistingImage.ResourceReadySignal().Connect( &ResourceReadySignal);
1341   imageViewWithExistingImage.SetProperty( ImageView::Property::IMAGE, imageMap );
1342
1343   DALI_TEST_EQUALS( gResourceReadySignalFired, true, TEST_LOCATION );
1344
1345   END_TEST;
1346 }
1347
1348 int UtcDaliImageViewResourceReadySignalWithReusedImage02(void)
1349 {
1350   tet_infoline("Test Setting Image that was already loaded by another ImageView and still getting ResourceReadySignal when staged.");
1351
1352   ToolkitTestApplication application;
1353
1354   gResourceReadySignalFired = false;
1355
1356   Property::Map imageImmediateLoadingMap;
1357   imageImmediateLoadingMap[ ImageVisual::Property::URL ] = gImage_34_RGBA;
1358   imageImmediateLoadingMap[ ImageVisual::Property::LOAD_POLICY ] =  ImageVisual::LoadPolicy::IMMEDIATE;
1359
1360   tet_infoline("Immediate load an image");
1361   ImageView imageView = ImageView::New();
1362   imageView.ResourceReadySignal().Connect( &ResourceReadySignal);
1363   imageView.SetProperty( ImageView::Property::IMAGE, imageImmediateLoadingMap );
1364
1365   // loading started, this waits for the loader thread
1366   DALI_TEST_EQUALS( Test::WaitForEventThreadTrigger( 1 ), true, TEST_LOCATION );
1367
1368   application.SendNotification();
1369   application.Render(16);
1370
1371   tet_infoline("Check image loaded");
1372   DALI_TEST_EQUALS( gResourceReadySignalFired, true, TEST_LOCATION );
1373   gResourceReadySignalFired = false;
1374
1375   tet_infoline("Create another ImageView with the same URL");
1376   ImageView imageViewWithExistingImage = ImageView::New( gImage_34_RGBA );
1377   tet_infoline("Connect to ResourceReady signal for second ImageView, it should still fire as resource is ready");
1378   imageViewWithExistingImage.ResourceReadySignal().Connect( &ResourceReadySignal);
1379
1380   application.GetScene().Add( imageViewWithExistingImage );
1381
1382   DALI_TEST_EQUALS( gResourceReadySignalFired, true, TEST_LOCATION );
1383
1384   END_TEST;
1385 }
1386
1387 int UtcDaliImageViewPaddingProperty(void)
1388 {
1389   ToolkitTestApplication application;
1390
1391   ImageView imageView = ImageView::New();
1392   Property::Map imagePropertyMap;
1393   imagePropertyMap[ Toolkit::Visual::Property::TYPE ] = Toolkit::Visual::IMAGE;
1394   imagePropertyMap[ Toolkit::ImageVisual::Property::URL ] = TEST_RESOURCE_DIR "/gallery-small-1.jpg" ;
1395   imagePropertyMap[ ImageVisual::Property::DESIRED_WIDTH ] = 128;
1396   imagePropertyMap[ ImageVisual::Property::DESIRED_HEIGHT ] = 128;
1397   imageView.SetProperty( Toolkit::ImageView::Property::IMAGE , imagePropertyMap );
1398   imageView.SetProperty( Actor::Property::ANCHOR_POINT, AnchorPoint::TOP_LEFT );
1399   imageView.SetProperty( Actor::Property::PARENT_ORIGIN, ParentOrigin::TOP_LEFT );
1400   imageView.SetProperty( Control::Property::PADDING, Extents( 15, 10, 5, 10 ) );
1401   application.GetScene().Add( imageView );
1402
1403   application.SendNotification();
1404   application.Render();
1405
1406   DALI_TEST_EQUALS( imageView.GetProperty<Extents>( Control::Property::PADDING ), Extents( 15, 10, 5, 10 ), TEST_LOCATION );
1407
1408   ImageView childImage = ImageView::New();
1409   childImage.SetBackgroundColor( Color::BLACK );
1410   childImage.SetProperty( Actor::Property::SIZE, Vector2( 10.f, 10.f ) );
1411   imageView.Add( childImage );
1412
1413   application.SendNotification();
1414   application.Render();
1415
1416   // Child ImageView should be positioned dependinig on Parent ImageView's Padding value
1417   DALI_TEST_EQUALS( childImage.GetProperty<Vector3>( Dali::Actor::Property::POSITION ), Vector3( 15, 5, 0 ), TEST_LOCATION );
1418
1419   // Check whether Image Visual transforms on ImageVieiw::OnRelayout()
1420   Toolkit::Internal::Control& controlImpl = Toolkit::Internal::GetImplementation( imageView );
1421   Toolkit::Visual::Base imageVisual = DevelControl::GetVisual( controlImpl, ImageView::Property::IMAGE );
1422   Property::Map resultMap;
1423   imageVisual.CreatePropertyMap( resultMap );
1424
1425   Property::Value* transformValue = resultMap.Find( Visual::Property::TRANSFORM );
1426   DALI_TEST_CHECK( transformValue );
1427   Property::Map* retMap = transformValue->GetMap();
1428   DALI_TEST_CHECK( retMap );
1429
1430   // Image Visual should be positioned depending on ImageView's padding
1431   DALI_TEST_EQUALS( retMap->Find( Visual::Transform::Property::OFFSET )->Get< Vector2 >(), Vector2( 15, 5 ), TEST_LOCATION );
1432
1433   END_TEST;
1434 }
1435
1436 int UtcDaliImageViewPaddingProperty02(void)
1437 {
1438   ToolkitTestApplication application;
1439
1440   ImageView imageView = ImageView::New();
1441   Property::Map imagePropertyMap;
1442   imagePropertyMap[ Toolkit::Visual::Property::TYPE ] = Toolkit::Visual::IMAGE;
1443   imagePropertyMap[ Toolkit::ImageVisual::Property::URL ] = TEST_RESOURCE_DIR "/Kid1.svg" ;
1444   imagePropertyMap[ ImageVisual::Property::DESIRED_WIDTH ] = 128;
1445   imagePropertyMap[ ImageVisual::Property::DESIRED_HEIGHT ] = 128;
1446   imagePropertyMap[ DevelVisual::Property::VISUAL_FITTING_MODE ] = Toolkit::DevelVisual::FIT_KEEP_ASPECT_RATIO;
1447   imageView.SetProperty( Toolkit::ImageView::Property::IMAGE , imagePropertyMap );
1448   imageView.SetProperty( Actor::Property::ANCHOR_POINT, AnchorPoint::TOP_LEFT );
1449   imageView.SetProperty( Actor::Property::PARENT_ORIGIN, ParentOrigin::TOP_LEFT );
1450   imageView.SetProperty( Control::Property::PADDING, Extents( 15, 10, 5, 10 ) );
1451   application.GetScene().Add( imageView );
1452
1453   application.SendNotification();
1454   application.Render();
1455
1456   DALI_TEST_EQUALS( imageView.GetProperty<Extents>( Control::Property::PADDING ), Extents( 15, 10, 5, 10 ), TEST_LOCATION );
1457
1458   // Check whether Image Visual transforms on ImageVieiw::OnRelayout()
1459   Toolkit::Internal::Control& controlImpl = Toolkit::Internal::GetImplementation( imageView );
1460   Toolkit::Visual::Base imageVisual = DevelControl::GetVisual( controlImpl, ImageView::Property::IMAGE );
1461   Property::Map resultMap;
1462   imageVisual.CreatePropertyMap( resultMap );
1463
1464   Property::Value* transformValue = resultMap.Find( Visual::Property::TRANSFORM );
1465   DALI_TEST_CHECK( transformValue );
1466   Property::Map* retMap = transformValue->GetMap();
1467   DALI_TEST_CHECK( retMap );
1468
1469   // Image Visual should be positioned depending on ImageView's padding
1470   DALI_TEST_EQUALS( retMap->Find( Visual::Transform::Property::OFFSET )->Get< Vector2 >(), Vector2( 15, 5 ), TEST_LOCATION );
1471
1472   END_TEST;
1473 }
1474
1475 int UtcDaliImageViewPaddingProperty03(void)
1476 {
1477   tet_infoline("Test Setting Image Padding then removing it.");
1478
1479   ToolkitTestApplication application;
1480
1481   ImageView imageView = ImageView::New();
1482   Property::Map imagePropertyMap;
1483   imagePropertyMap[ Toolkit::Visual::Property::TYPE ] = Toolkit::Visual::IMAGE;
1484   imagePropertyMap[ Toolkit::ImageVisual::Property::URL ] = TEST_RESOURCE_DIR "/Kid1.svg" ;
1485   imagePropertyMap[ ImageVisual::Property::DESIRED_WIDTH ] = 128;
1486   imagePropertyMap[ ImageVisual::Property::DESIRED_HEIGHT ] = 128;
1487   imagePropertyMap[ DevelVisual::Property::VISUAL_FITTING_MODE ] = Toolkit::DevelVisual::FIT_KEEP_ASPECT_RATIO;
1488   imageView.SetProperty( Toolkit::ImageView::Property::IMAGE , imagePropertyMap );
1489   imageView.SetProperty( Actor::Property::ANCHOR_POINT, AnchorPoint::TOP_LEFT );
1490   imageView.SetProperty( Actor::Property::PARENT_ORIGIN, ParentOrigin::TOP_LEFT );
1491   imageView.SetProperty( Control::Property::PADDING, Extents( 15, 10, 5, 10 ) );
1492   application.GetScene().Add( imageView );
1493
1494   application.SendNotification();
1495   application.Render();
1496
1497   DALI_TEST_EQUALS( imageView.GetProperty<Extents>( Control::Property::PADDING ), Extents( 15, 10, 5, 10 ), TEST_LOCATION );
1498
1499   tet_infoline("Remove Padding and test Visual is position correctly");
1500
1501   imageView.SetProperty( Control::Property::PADDING, Extents( 0, 0, 0, 0 ) );
1502
1503   application.SendNotification();
1504   application.Render();
1505
1506   // Check whether Image Visual transforms on ImageVieiw::OnRelayout()
1507   Toolkit::Internal::Control& controlImpl = Toolkit::Internal::GetImplementation( imageView );
1508   Toolkit::Visual::Base imageVisual = DevelControl::GetVisual( controlImpl, ImageView::Property::IMAGE );
1509   Property::Map resultMap;
1510   imageVisual.CreatePropertyMap( resultMap );
1511
1512   Property::Value* transformValue = resultMap.Find( Visual::Property::TRANSFORM );
1513   DALI_TEST_CHECK( transformValue );
1514   Property::Map* retMap = transformValue->GetMap();
1515   DALI_TEST_CHECK( retMap );
1516
1517   // Image Visual should be positioned depending on ImageView's padding
1518   DALI_TEST_EQUALS( retMap->Find( Visual::Transform::Property::OFFSET )->Get< Vector2 >(), Vector2( 0, 0 ), TEST_LOCATION );
1519
1520   END_TEST;
1521 }
1522
1523 int UtcDaliImageViewPaddingProperty04(void)
1524 {
1525   tet_infoline("Test Setting Image Padding then removing it. Visual Fitting Mode as Fill");
1526
1527   ToolkitTestApplication application;
1528
1529   ImageView imageView = ImageView::New();
1530   Property::Map imagePropertyMap;
1531   imagePropertyMap[ Toolkit::Visual::Property::TYPE ] = Toolkit::Visual::IMAGE;
1532   imagePropertyMap[ Toolkit::ImageVisual::Property::URL ] = TEST_RESOURCE_DIR "/Kid1.svg" ;
1533   imagePropertyMap[ ImageVisual::Property::DESIRED_WIDTH ] = 128;
1534   imagePropertyMap[ ImageVisual::Property::DESIRED_HEIGHT ] = 128;
1535   imagePropertyMap[ DevelVisual::Property::VISUAL_FITTING_MODE ] = Toolkit::DevelVisual::FILL;
1536   imageView.SetProperty( Toolkit::ImageView::Property::IMAGE , imagePropertyMap );
1537   imageView.SetProperty( Actor::Property::ANCHOR_POINT, AnchorPoint::TOP_LEFT );
1538   imageView.SetProperty( Actor::Property::PARENT_ORIGIN, ParentOrigin::TOP_LEFT );
1539   imageView.SetProperty( Control::Property::PADDING, Extents( 15, 10, 5, 10 ) );
1540   application.GetScene().Add( imageView );
1541
1542   application.SendNotification();
1543   application.Render();
1544
1545   DALI_TEST_EQUALS( imageView.GetProperty<Extents>( Control::Property::PADDING ), Extents( 15, 10, 5, 10 ), TEST_LOCATION );
1546
1547   tet_infoline("Remove Padding and test Visual is position correctly");
1548
1549   imageView.SetProperty( Control::Property::PADDING, Extents( 0, 0, 0, 0 ) );
1550
1551   application.SendNotification();
1552   application.Render();
1553
1554   // Check whether Image Visual transforms on ImageVieiw::OnRelayout()
1555   Toolkit::Internal::Control& controlImpl = Toolkit::Internal::GetImplementation( imageView );
1556   Toolkit::Visual::Base imageVisual = DevelControl::GetVisual( controlImpl, ImageView::Property::IMAGE );
1557   Property::Map resultMap;
1558   imageVisual.CreatePropertyMap( resultMap );
1559
1560   Property::Value* transformValue = resultMap.Find( Visual::Property::TRANSFORM );
1561   DALI_TEST_CHECK( transformValue );
1562   Property::Map* retMap = transformValue->GetMap();
1563   DALI_TEST_CHECK( retMap );
1564
1565   // Image Visual should be positioned depending on ImageView's padding
1566   DALI_TEST_EQUALS( retMap->Find( Visual::Transform::Property::OFFSET )->Get< Vector2 >(), Vector2( 0, 0 ), TEST_LOCATION );
1567
1568   END_TEST;
1569 }
1570
1571 int UtcDaliImageViewTransformTest01(void)
1572 {
1573   tet_infoline("Test Setting a offset transform on the ImageView");
1574
1575   ToolkitTestApplication application;
1576
1577   ImageView imageView = ImageView::New();
1578   Property::Map imagePropertyMap;
1579   imagePropertyMap.Add( Toolkit::Visual::Property::TYPE,Toolkit::Visual::IMAGE )
1580                   .Add( Toolkit::ImageVisual::Property::URL,TEST_RESOURCE_DIR "/Kid1.svg" )
1581                   .Add( ImageVisual::Property::DESIRED_WIDTH,120 )
1582                   .Add( ImageVisual::Property::DESIRED_HEIGHT,120 )
1583                   .Add( DevelVisual::Property::VISUAL_FITTING_MODE, Toolkit::DevelVisual::FILL )
1584                   .Add( Visual::Property::TRANSFORM,
1585                         Property::Map().Add( Toolkit::Visual::Transform::Property::OFFSET_POLICY,
1586                                              Vector2( Visual::Transform::Policy::ABSOLUTE, Visual::Transform::Policy::ABSOLUTE ) )
1587                                        .Add( Toolkit::Visual::Transform::Property::OFFSET, Vector2( 8, 8 ) ) );
1588
1589   imageView.SetProperty( Toolkit::ImageView::Property::IMAGE , imagePropertyMap );
1590   imageView.SetProperty( Actor::Property::ANCHOR_POINT, AnchorPoint::TOP_LEFT );
1591   imageView.SetProperty( Actor::Property::PARENT_ORIGIN, ParentOrigin::TOP_LEFT );
1592   application.GetScene().Add( imageView );
1593
1594   application.SendNotification();
1595   application.Render();
1596
1597   // Check whether Image Visual transforms on ImageVieiw::OnRelayout()
1598   Toolkit::Internal::Control& controlImpl = Toolkit::Internal::GetImplementation( imageView );
1599   Toolkit::Visual::Base imageVisual = DevelControl::GetVisual( controlImpl, ImageView::Property::IMAGE );
1600   Property::Map resultMap;
1601   imageVisual.CreatePropertyMap( resultMap );
1602
1603   Property::Value* transformValue = resultMap.Find( Visual::Property::TRANSFORM );
1604   DALI_TEST_CHECK( transformValue );
1605   Property::Map* retMap = transformValue->GetMap();
1606   DALI_TEST_CHECK( retMap );
1607
1608   // Image Visual should be positioned depending on ImageView's padding
1609   DALI_TEST_EQUALS( retMap->Find( Visual::Transform::Property::OFFSET )->Get< Vector2 >(), Vector2( 8, 8 ), TEST_LOCATION );
1610   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 );
1611
1612   END_TEST;
1613 }
1614
1615 int UtcDaliImageViewUsingAtlasAndGetNaturalSize(void)
1616 {
1617   ToolkitTestApplication application;
1618
1619   // Check ImageView with background and main image, to ensure both visuals are marked as loaded
1620   ImageView imageView = ImageView::New();
1621   Property::Map imageMap;
1622   imageMap[ Toolkit::Visual::Property::TYPE ] = Toolkit::Visual::IMAGE;
1623   imageMap[ Toolkit::ImageVisual::Property::URL ] = gImage_34_RGBA;
1624   imageMap[ Toolkit::ImageVisual::Property::ATLASING ] = true;
1625   imageView.SetProperty( Toolkit::ImageView::Property::IMAGE, imageMap );
1626   application.GetScene().Add( imageView );
1627
1628   // Trigger a potential relayout
1629   application.SendNotification();
1630   application.Render();
1631
1632   Vector3 naturalSize = imageView.GetNaturalSize();
1633
1634   DALI_TEST_EQUALS( naturalSize.width, 34.0f, TEST_LOCATION );
1635   DALI_TEST_EQUALS( naturalSize.height, 34.0f, TEST_LOCATION );
1636
1637   END_TEST;
1638 }
1639
1640 int UtcDaliImageViewFillMode(void)
1641 {
1642   ToolkitTestApplication application;
1643
1644   tet_infoline( "Create an ImageVisual without padding and set the fill-mode to fill" );
1645
1646   ImageView imageView = ImageView::New();
1647   Property::Map imageMap;
1648   imageMap.Add( Toolkit::Visual::Property::TYPE, Toolkit::Visual::IMAGE );
1649   imageMap.Add( Toolkit::ImageVisual::Property::URL, gImage_600_RGB );
1650   imageMap.Add( DevelVisual::Property::VISUAL_FITTING_MODE, DevelVisual::FittingMode::FILL );
1651
1652   imageView.SetProperty( Toolkit::ImageView::Property::IMAGE, imageMap );
1653
1654   application.GetScene().Add( imageView );
1655
1656   // Trigger a potential relayout
1657   application.SendNotification();
1658   application.Render();
1659
1660   Toolkit::Visual::Base visual = DevelControl::GetVisual( Toolkit::Internal::GetImplementation( imageView ), Toolkit::ImageView::Property::IMAGE );
1661   Property::Map returnedMap;
1662   visual.CreatePropertyMap( returnedMap );
1663
1664   Property::Value* value = returnedMap.Find( Toolkit::Visual::Property::TRANSFORM );
1665   DALI_TEST_CHECK( value );
1666   Property::Map* map = value->GetMap();
1667   DALI_TEST_CHECK( map );
1668
1669   value = map->Find( Toolkit::Visual::Transform::Property::SIZE );
1670   DALI_TEST_CHECK( value );
1671   DALI_TEST_EQUALS( value->Get< Vector2 >(), Vector2::ONE, TEST_LOCATION );
1672
1673   value = map->Find( Toolkit::Visual::Transform::Property::SIZE_POLICY );
1674   DALI_TEST_CHECK( value );
1675   DALI_TEST_CHECK( value->Get< int >() == Toolkit::Visual::Transform::Policy::RELATIVE );
1676
1677   END_TEST;
1678 }
1679
1680 int UtcDaliImageViewFittingModeFitKeepAspectRatio(void)
1681 {
1682   ToolkitTestApplication application;
1683
1684   tet_infoline( "Create an ImageVisual using FitKeepAspectRatio ( image: [600,600], view: [600,700] )" );
1685   tet_infoline( "  There should be need to change the transform, offset is adjusted to fit inside");
1686
1687   ImageView imageView = ImageView::New();
1688   Property::Map imageMap;
1689   imageMap.Add( Toolkit::Visual::Property::TYPE, Toolkit::Visual::IMAGE );
1690   imageMap.Add( Toolkit::ImageVisual::Property::URL, gImage_600_RGB ); // 600x600 image
1691   imageMap.Add( DevelVisual::Property::VISUAL_FITTING_MODE , Toolkit::DevelVisual::FIT_KEEP_ASPECT_RATIO );
1692
1693   imageView.SetProperty( Toolkit::ImageView::Property::IMAGE, imageMap );
1694   imageView.SetProperty( Actor::Property::SIZE, Vector2(600,700) );
1695
1696   application.GetScene().Add( imageView );
1697
1698   // Trigger a potential relayout
1699   application.SendNotification();
1700   application.Render();
1701
1702   Toolkit::Visual::Base visual = DevelControl::GetVisual( Toolkit::Internal::GetImplementation( imageView ), Toolkit::ImageView::Property::IMAGE );
1703   Property::Map returnedMap;
1704   visual.CreatePropertyMap( returnedMap );
1705
1706   Property::Value* value = returnedMap.Find( Toolkit::Visual::Property::TRANSFORM );
1707   DALI_TEST_CHECK( value );
1708   Property::Map* map = value->GetMap();
1709   DALI_TEST_CHECK( map );
1710
1711   // If there's
1712   value = map->Find( Toolkit::Visual::Transform::Property::SIZE );
1713   DALI_TEST_CHECK( value );
1714   DALI_TEST_EQUALS( value->Get< Vector2 >(), Vector2( 600, 600 ), TEST_LOCATION );
1715
1716   value = map->Find( Toolkit::Visual::Transform::Property::SIZE_POLICY );
1717   DALI_TEST_CHECK( value );
1718   DALI_TEST_EQUALS( value->Get< Vector2 >(), Vector2( Toolkit::Visual::Transform::Policy::ABSOLUTE, Toolkit::Visual::Transform::Policy::ABSOLUTE ), TEST_LOCATION );
1719
1720   value = map->Find( Toolkit::Visual::Transform::Property::OFFSET );
1721   DALI_TEST_CHECK( value );
1722   DALI_TEST_EQUALS( value->Get< Vector2 >(), Vector2( 0, 50 ), TEST_LOCATION );
1723
1724   END_TEST;
1725 }
1726
1727 int UtcDaliImageViewFittingModesFill(void)
1728 {
1729   ToolkitTestApplication application;
1730
1731   tet_infoline( "Create an ImageVisual using Fill ( image: [600,600], view: [600,700] )" );
1732   tet_infoline( "  There should be no need to change the transform, only size is changed to fit view");
1733
1734   ImageView imageView = ImageView::New();
1735   Property::Map imageMap;
1736   imageMap.Add( Toolkit::Visual::Property::TYPE, Toolkit::Visual::IMAGE );
1737   imageMap.Add( Toolkit::ImageVisual::Property::URL, gImage_600_RGB ); // 600x600 image
1738   imageMap.Add( DevelVisual::Property::VISUAL_FITTING_MODE , Toolkit::DevelVisual::FILL );
1739
1740   imageView.SetProperty( Toolkit::ImageView::Property::IMAGE, imageMap );
1741   imageView.SetProperty( Actor::Property::SIZE, Vector2(600,700) );
1742
1743   application.GetScene().Add( imageView );
1744
1745   // Trigger a potential relayout
1746   application.SendNotification();
1747   application.Render();
1748
1749   Toolkit::Visual::Base visual = DevelControl::GetVisual( Toolkit::Internal::GetImplementation( imageView ), Toolkit::ImageView::Property::IMAGE );
1750   Property::Map returnedMap;
1751   visual.CreatePropertyMap( returnedMap );
1752
1753   Property::Value* value = returnedMap.Find( Toolkit::Visual::Property::TRANSFORM );
1754   DALI_TEST_CHECK( value );
1755   Property::Map* map = value->GetMap();
1756   DALI_TEST_CHECK( map );
1757
1758   value = map->Find( Toolkit::Visual::Transform::Property::SIZE );
1759   DALI_TEST_CHECK( value );
1760   DALI_TEST_EQUALS( value->Get< Vector2 >(), Vector2::ONE, TEST_LOCATION ); // Change the internal size according to the image view size
1761
1762   value = map->Find( Toolkit::Visual::Transform::Property::SIZE_POLICY );
1763   DALI_TEST_CHECK( value );
1764   DALI_TEST_CHECK( value->Get< int >() == Toolkit::Visual::Transform::Policy::RELATIVE );
1765
1766   value = map->Find( Toolkit::Visual::Transform::Property::OFFSET );
1767   DALI_TEST_CHECK( value );
1768   DALI_TEST_EQUALS( value->Get< Vector2 >(), Vector2( 0, 0 ), TEST_LOCATION ); // OFFSET is zero
1769
1770   END_TEST;
1771 }
1772
1773 int UtcDaliImageViewFittingModesOverfitKeepAspectRatio(void)
1774 {
1775   ToolkitTestApplication application;
1776
1777   tet_infoline( "Create an ImageVisual using OverFitKeepAspectRatio ( image: [600,600], view: [600,500] )" );
1778   tet_infoline( "  offset or size is the same as view, but adjust internally using pixelArea ");
1779
1780   ImageView imageView = ImageView::New();
1781   Property::Map imageMap;
1782   imageMap.Add( Toolkit::Visual::Property::TYPE, Toolkit::Visual::IMAGE );
1783   imageMap.Add( Toolkit::ImageVisual::Property::URL, gImage_600_RGB ); // 600x600 image
1784   imageMap.Add( DevelVisual::Property::VISUAL_FITTING_MODE , Toolkit::DevelVisual::OVER_FIT_KEEP_ASPECT_RATIO );
1785
1786   imageView.SetProperty( Toolkit::ImageView::Property::IMAGE, imageMap );
1787   imageView.SetProperty( Actor::Property::SIZE, Vector2(600,500) );
1788
1789   application.GetScene().Add( imageView );
1790
1791   // Trigger a potential relayout
1792   application.SendNotification();
1793   application.Render();
1794
1795   Toolkit::Visual::Base visual = DevelControl::GetVisual( Toolkit::Internal::GetImplementation( imageView ), Toolkit::ImageView::Property::IMAGE );
1796   Property::Map returnedMap;
1797   visual.CreatePropertyMap( returnedMap );
1798
1799   Property::Value* value = returnedMap.Find( Toolkit::Visual::Property::TRANSFORM );
1800   DALI_TEST_CHECK( value );
1801   Property::Map* map = value->GetMap();
1802   DALI_TEST_CHECK( map );
1803
1804   // If there's
1805   value = map->Find( Toolkit::Visual::Transform::Property::SIZE );
1806   DALI_TEST_CHECK( value );
1807   DALI_TEST_EQUALS( value->Get< Vector2 >(), Vector2( 600, 500 ), TEST_LOCATION ); // Change the internal size according to the image view size
1808
1809   value = map->Find( Toolkit::Visual::Transform::Property::SIZE_POLICY );
1810   DALI_TEST_CHECK( value );
1811   DALI_TEST_EQUALS( value->Get< Vector2 >(), Vector2( Toolkit::Visual::Transform::Policy::ABSOLUTE, Toolkit::Visual::Transform::Policy::ABSOLUTE ), TEST_LOCATION );
1812
1813   value = map->Find( Toolkit::Visual::Transform::Property::OFFSET );
1814   DALI_TEST_CHECK( value );
1815   DALI_TEST_EQUALS( value->Get< Vector2 >(), Vector2( 0, 0 ), TEST_LOCATION ); // OFFSET is zero
1816
1817   END_TEST;
1818 }
1819
1820 int UtcDaliImageViewFittingModesCenter01(void)
1821 {
1822   ToolkitTestApplication application;
1823
1824   tet_infoline( "Create an ImageVisual using Center ( image: [600,600], view: [700,700] )" );
1825   tet_infoline( "  There should be need to change the transform, offset is adjusted to fit inside");
1826
1827   ImageView imageView = ImageView::New();
1828   Property::Map imageMap;
1829   imageMap.Add( Toolkit::Visual::Property::TYPE, Toolkit::Visual::IMAGE );
1830   imageMap.Add( Toolkit::ImageVisual::Property::URL, gImage_600_RGB ); // 600x600 image
1831   imageMap.Add( DevelVisual::Property::VISUAL_FITTING_MODE, Toolkit::DevelVisual::CENTER);
1832
1833   imageView.SetProperty( Toolkit::ImageView::Property::IMAGE, imageMap );
1834   imageView.SetProperty( Actor::Property::SIZE, Vector2(700,700) );
1835
1836   application.GetScene().Add( imageView );
1837
1838   // Trigger a potential relayout
1839   application.SendNotification();
1840   application.Render();
1841
1842   Toolkit::Visual::Base visual = DevelControl::GetVisual( Toolkit::Internal::GetImplementation( imageView ), Toolkit::ImageView::Property::IMAGE );
1843   Property::Map returnedMap;
1844   visual.CreatePropertyMap( returnedMap );
1845
1846   Property::Value* value = returnedMap.Find( Toolkit::Visual::Property::TRANSFORM );
1847   DALI_TEST_CHECK( value );
1848   Property::Map* map = value->GetMap();
1849   DALI_TEST_CHECK( map );
1850
1851   value = map->Find( Toolkit::Visual::Transform::Property::SIZE );
1852   DALI_TEST_CHECK( value );
1853   DALI_TEST_EQUALS( value->Get< Vector2 >(), Vector2( 600, 600 ), TEST_LOCATION ); // Change the internal size according to the image view size
1854
1855   value = map->Find( Toolkit::Visual::Transform::Property::SIZE_POLICY );
1856   DALI_TEST_CHECK( value );
1857   DALI_TEST_EQUALS( value->Get< Vector2 >(), Vector2( Toolkit::Visual::Transform::Policy::ABSOLUTE, Toolkit::Visual::Transform::Policy::ABSOLUTE ), TEST_LOCATION );
1858
1859   value = map->Find( Toolkit::Visual::Transform::Property::OFFSET );
1860   DALI_TEST_CHECK( value );
1861   DALI_TEST_EQUALS( value->Get< Vector2 >(), Vector2( 50, 50 ), TEST_LOCATION );
1862
1863   END_TEST;
1864 }
1865
1866 int UtcDaliImageViewFittingModesCenter02(void)
1867 {
1868   ToolkitTestApplication application;
1869
1870   tet_infoline( "Create an ImageVisual using Center ( image: [600,600], view: [500,500] )" );
1871   tet_infoline( "  There should be need to change the transform, offset is adjusted to fit inside");
1872
1873   ImageView imageView = ImageView::New();
1874   Property::Map imageMap;
1875   imageMap.Add( Toolkit::Visual::Property::TYPE, Toolkit::Visual::IMAGE );
1876   imageMap.Add( Toolkit::ImageVisual::Property::URL, gImage_600_RGB ); // 600x600 image
1877   imageMap.Add( DevelVisual::Property::VISUAL_FITTING_MODE, Toolkit::DevelVisual::CENTER);
1878
1879   imageView.SetProperty( Toolkit::ImageView::Property::IMAGE, imageMap );
1880   imageView.SetProperty( Actor::Property::SIZE, Vector2(700,700) );
1881
1882   application.GetScene().Add( imageView );
1883
1884   // Trigger a potential relayout
1885   application.SendNotification();
1886   application.Render();
1887
1888   Toolkit::Visual::Base visual = DevelControl::GetVisual( Toolkit::Internal::GetImplementation( imageView ), Toolkit::ImageView::Property::IMAGE );
1889   Property::Map returnedMap;
1890   visual.CreatePropertyMap( returnedMap );
1891
1892   Property::Value* value = returnedMap.Find( Toolkit::Visual::Property::TRANSFORM );
1893   DALI_TEST_CHECK( value );
1894   Property::Map* map = value->GetMap();
1895   DALI_TEST_CHECK( map );
1896
1897   value = map->Find( Toolkit::Visual::Transform::Property::SIZE );
1898   DALI_TEST_CHECK( value );
1899   DALI_TEST_EQUALS( value->Get< Vector2 >(), Vector2( 600, 600 ), TEST_LOCATION ); // Change the internal size according to the image view size
1900
1901   value = map->Find( Toolkit::Visual::Transform::Property::SIZE_POLICY );
1902   DALI_TEST_CHECK( value );
1903   DALI_TEST_EQUALS( value->Get< Vector2 >(), Vector2( Toolkit::Visual::Transform::Policy::ABSOLUTE, Toolkit::Visual::Transform::Policy::ABSOLUTE ), TEST_LOCATION );
1904
1905   value = map->Find( Toolkit::Visual::Transform::Property::OFFSET );
1906   DALI_TEST_CHECK( value );
1907   DALI_TEST_EQUALS( value->Get< Vector2 >(), Vector2( 50, 50 ), TEST_LOCATION );
1908
1909   END_TEST;
1910 }
1911
1912 int UtcDaliImageViewFittingModesFitHeight01(void)
1913 {
1914   ToolkitTestApplication application;
1915
1916   tet_infoline( "Create an ImageVisual using FitHeight ( image: [600,600], view: [600,700] )" );
1917
1918   ImageView imageView = ImageView::New();
1919   Property::Map imageMap;
1920   imageMap.Add( Toolkit::Visual::Property::TYPE, Toolkit::Visual::IMAGE );
1921   imageMap.Add( Toolkit::ImageVisual::Property::URL, gImage_600_RGB ); // 600x600 image
1922   imageMap.Add( DevelVisual::Property::VISUAL_FITTING_MODE, Toolkit::DevelVisual::FIT_HEIGHT);
1923
1924   imageView.SetProperty( Toolkit::ImageView::Property::IMAGE, imageMap );
1925   imageView.SetProperty( Actor::Property::SIZE, Vector2(600,700) );
1926
1927   application.GetScene().Add( imageView );
1928
1929   // Trigger a potential relayout
1930   application.SendNotification();
1931   application.Render();
1932
1933   Toolkit::Visual::Base visual = DevelControl::GetVisual( Toolkit::Internal::GetImplementation( imageView ), Toolkit::ImageView::Property::IMAGE );
1934   Property::Map returnedMap;
1935   visual.CreatePropertyMap( returnedMap );
1936
1937   Property::Value* value = returnedMap.Find( Toolkit::Visual::Property::TRANSFORM );
1938   DALI_TEST_CHECK( value );
1939   Property::Map* map = value->GetMap();
1940   DALI_TEST_CHECK( map );
1941
1942   value = map->Find( Toolkit::Visual::Transform::Property::SIZE );
1943   DALI_TEST_CHECK( value );
1944   DALI_TEST_EQUALS( value->Get< Vector2 >(), Vector2( 600, 700 ), TEST_LOCATION ); // Change the internal size according to the image view size
1945
1946   value = map->Find( Toolkit::Visual::Transform::Property::SIZE_POLICY );
1947   DALI_TEST_CHECK( value );
1948   DALI_TEST_EQUALS( value->Get< Vector2 >(), Vector2( Toolkit::Visual::Transform::Policy::ABSOLUTE, Toolkit::Visual::Transform::Policy::ABSOLUTE ), TEST_LOCATION );
1949
1950   value = map->Find( Toolkit::Visual::Transform::Property::OFFSET );
1951   DALI_TEST_CHECK( value );
1952   DALI_TEST_EQUALS( value->Get< Vector2 >(), Vector2( 0, 0 ), TEST_LOCATION ); // OFFSET is zero
1953
1954   END_TEST;
1955 }
1956
1957 int UtcDaliImageViewFittingModesFitHeight02(void)
1958 {
1959   ToolkitTestApplication application;
1960
1961   tet_infoline( "Create an ImageVisual using FitHeight ( image: [600,600], view: [700,600] )" );
1962
1963   ImageView imageView = ImageView::New();
1964   Property::Map imageMap;
1965   imageMap.Add( Toolkit::Visual::Property::TYPE, Toolkit::Visual::IMAGE );
1966   imageMap.Add( Toolkit::ImageVisual::Property::URL, gImage_600_RGB ); // 249x169 image
1967   imageMap.Add( DevelVisual::Property::VISUAL_FITTING_MODE, Toolkit::DevelVisual::FIT_HEIGHT);
1968
1969   imageView.SetProperty( Toolkit::ImageView::Property::IMAGE, imageMap );
1970   imageView.SetProperty( Actor::Property::SIZE, Vector2(700,600) );
1971
1972   application.GetScene().Add( imageView );
1973
1974   // Trigger a potential relayout
1975   application.SendNotification();
1976   application.Render();
1977
1978   Toolkit::Visual::Base visual = DevelControl::GetVisual( Toolkit::Internal::GetImplementation( imageView ), Toolkit::ImageView::Property::IMAGE );
1979   Property::Map returnedMap;
1980   visual.CreatePropertyMap( returnedMap );
1981
1982   Property::Value* value = returnedMap.Find( Toolkit::Visual::Property::TRANSFORM );
1983   DALI_TEST_CHECK( value );
1984   Property::Map* map = value->GetMap();
1985   DALI_TEST_CHECK( map );
1986
1987   value = map->Find( Toolkit::Visual::Transform::Property::SIZE );
1988   DALI_TEST_CHECK( value );
1989   DALI_TEST_EQUALS( value->Get< Vector2 >(), Vector2( 600, 600 ), TEST_LOCATION ); // Change the internal size according to the image view size
1990
1991   value = map->Find( Toolkit::Visual::Transform::Property::SIZE_POLICY );
1992   DALI_TEST_CHECK( value );
1993   DALI_TEST_EQUALS( value->Get< Vector2 >(), Vector2( Toolkit::Visual::Transform::Policy::ABSOLUTE, Toolkit::Visual::Transform::Policy::ABSOLUTE ), TEST_LOCATION );
1994
1995   value = map->Find( Toolkit::Visual::Transform::Property::OFFSET );
1996   DALI_TEST_CHECK( value );
1997   DALI_TEST_EQUALS( value->Get< Vector2 >(), Vector2( 50, 0 ), TEST_LOCATION );
1998
1999   END_TEST;
2000 }
2001
2002 int UtcDaliImageViewFittingModesFitWidth01(void)
2003 {
2004   ToolkitTestApplication application;
2005
2006   tet_infoline( "Create an ImageVisual using FitWidth ( image: [600,600], view: [600,700] )" );
2007
2008   ImageView imageView = ImageView::New();
2009   Property::Map imageMap;
2010   imageMap.Add( Toolkit::Visual::Property::TYPE, Toolkit::Visual::IMAGE );
2011   imageMap.Add( Toolkit::ImageVisual::Property::URL, gImage_600_RGB ); // 600x600 image
2012   imageMap.Add( DevelVisual::Property::VISUAL_FITTING_MODE, Toolkit::DevelVisual::FIT_WIDTH);
2013
2014   imageView.SetProperty( Toolkit::ImageView::Property::IMAGE, imageMap );
2015   imageView.SetProperty( Actor::Property::SIZE, Vector2(600,700) );
2016
2017   application.GetScene().Add( imageView );
2018
2019   // Trigger a potential relayout
2020   application.SendNotification();
2021   application.Render();
2022
2023   Toolkit::Visual::Base visual = DevelControl::GetVisual( Toolkit::Internal::GetImplementation( imageView ), Toolkit::ImageView::Property::IMAGE );
2024   Property::Map returnedMap;
2025   visual.CreatePropertyMap( returnedMap );
2026
2027   Property::Value* value = returnedMap.Find( Toolkit::Visual::Property::TRANSFORM );
2028   DALI_TEST_CHECK( value );
2029   Property::Map* map = value->GetMap();
2030   DALI_TEST_CHECK( map );
2031
2032   value = map->Find( Toolkit::Visual::Transform::Property::SIZE );
2033   DALI_TEST_CHECK( value );
2034   DALI_TEST_EQUALS( value->Get< Vector2 >(), Vector2( 600, 600 ), TEST_LOCATION ); // Change the internal size according to the image view size
2035
2036   value = map->Find( Toolkit::Visual::Transform::Property::SIZE_POLICY );
2037   DALI_TEST_CHECK( value );
2038   DALI_TEST_EQUALS( value->Get< Vector2 >(), Vector2( Toolkit::Visual::Transform::Policy::ABSOLUTE, Toolkit::Visual::Transform::Policy::ABSOLUTE ), TEST_LOCATION );
2039
2040   value = map->Find( Toolkit::Visual::Transform::Property::OFFSET );
2041   DALI_TEST_CHECK( value );
2042   DALI_TEST_EQUALS( value->Get< Vector2 >(), Vector2( 0, 50 ), TEST_LOCATION );
2043
2044   END_TEST;
2045 }
2046
2047 int UtcDaliImageViewFittingModesFitWidth02(void)
2048 {
2049   ToolkitTestApplication application;
2050
2051   tet_infoline( "Create an ImageVisual using FitWidth ( image: [600,600], view:[700,600] )" );
2052
2053   ImageView imageView = ImageView::New();
2054   Property::Map imageMap;
2055   imageMap.Add( Toolkit::Visual::Property::TYPE, Toolkit::Visual::IMAGE );
2056   imageMap.Add( Toolkit::ImageVisual::Property::URL, gImage_600_RGB ); // 249x169 image
2057   imageMap.Add( DevelVisual::Property::VISUAL_FITTING_MODE, Toolkit::DevelVisual::FIT_WIDTH);
2058
2059   imageView.SetProperty( Toolkit::ImageView::Property::IMAGE, imageMap );
2060   imageView.SetProperty( Actor::Property::SIZE, Vector2(700,600) );
2061
2062   application.GetScene().Add( imageView );
2063
2064   // Trigger a potential relayout
2065   application.SendNotification();
2066   application.Render();
2067
2068   Toolkit::Visual::Base visual = DevelControl::GetVisual( Toolkit::Internal::GetImplementation( imageView ), Toolkit::ImageView::Property::IMAGE );
2069   Property::Map returnedMap;
2070   visual.CreatePropertyMap( returnedMap );
2071
2072   Property::Value* value = returnedMap.Find( Toolkit::Visual::Property::TRANSFORM );
2073   DALI_TEST_CHECK( value );
2074   Property::Map* map = value->GetMap();
2075   DALI_TEST_CHECK( map );
2076
2077   value = map->Find( Toolkit::Visual::Transform::Property::SIZE );
2078   DALI_TEST_CHECK( value );
2079   DALI_TEST_EQUALS( value->Get< Vector2 >(), Vector2( 700, 600 ), TEST_LOCATION ); // Change the internal size according to the image view size
2080
2081   value = map->Find( Toolkit::Visual::Transform::Property::SIZE_POLICY );
2082   DALI_TEST_CHECK( value );
2083   DALI_TEST_EQUALS( value->Get< Vector2 >(), Vector2( Toolkit::Visual::Transform::Policy::ABSOLUTE, Toolkit::Visual::Transform::Policy::ABSOLUTE ), TEST_LOCATION );
2084
2085   value = map->Find( Toolkit::Visual::Transform::Property::OFFSET );
2086   DALI_TEST_CHECK( value );
2087   DALI_TEST_EQUALS( value->Get< Vector2 >(), Vector2( 0, 0 ), TEST_LOCATION ); // OFFSET is zero
2088
2089   END_TEST;
2090 }
2091
2092 int UtcDaliImageViewFittingModesChangeFittingMode01(void)
2093 {
2094   ToolkitTestApplication application;
2095
2096   tet_infoline( "UtcDaliImageViewFittingModesChangeFittingMode, image: [600,600], view:[800,700]" );
2097
2098   ImageView imageView = ImageView::New();
2099
2100   // 1. Render using FittingMode::SHRINK_TO_FIT
2101   Property::Map imageMap;
2102   imageMap[ Toolkit::Visual::Property::TYPE ] = Toolkit::Visual::IMAGE;
2103   imageMap[ Toolkit::ImageVisual::Property::URL ] = gImage_600_RGB;
2104   imageMap[ DevelVisual::Property::VISUAL_FITTING_MODE ] =  Toolkit::DevelVisual::FIT_KEEP_ASPECT_RATIO;
2105
2106   imageView.SetProperty( Toolkit::ImageView::Property::IMAGE, imageMap );
2107   imageView.SetProperty( Actor::Property::SIZE, Vector2(800,700) );
2108
2109   application.GetScene().Add( imageView );
2110
2111   // Trigger a potential relayout
2112   application.SendNotification();
2113   application.Render();
2114
2115   Toolkit::Visual::Base visual = DevelControl::GetVisual( Toolkit::Internal::GetImplementation( imageView ), Toolkit::ImageView::Property::IMAGE );
2116   Property::Map returnedMap;
2117   visual.CreatePropertyMap( returnedMap );
2118
2119   Property::Value* value = returnedMap.Find( Toolkit::Visual::Property::TRANSFORM );
2120   DALI_TEST_CHECK( value );
2121   Property::Map* map = value->GetMap();
2122   DALI_TEST_CHECK( map );
2123
2124   value = map->Find( Toolkit::Visual::Transform::Property::SIZE );
2125   DALI_TEST_CHECK( value );
2126   DALI_TEST_EQUALS( value->Get< Vector2 >(), Vector2( 700, 700 ), TEST_LOCATION ); // Change the internal size according to the image view size
2127
2128   value = map->Find( Toolkit::Visual::Transform::Property::SIZE_POLICY );
2129   DALI_TEST_CHECK( value );
2130   DALI_TEST_EQUALS( value->Get< Vector2 >(), Vector2( Toolkit::Visual::Transform::Policy::ABSOLUTE, Toolkit::Visual::Transform::Policy::ABSOLUTE ), TEST_LOCATION );
2131
2132   value = map->Find( Toolkit::Visual::Transform::Property::OFFSET );
2133   DALI_TEST_CHECK( value );
2134   DALI_TEST_EQUALS( value->Get< Vector2 >(), Vector2( 50, 0 ), TEST_LOCATION );
2135
2136   // 2. Render again using DevelVisaul::CENTER
2137   Property::Map imageMap2;
2138   imageMap2[ Toolkit::Visual::Property::TYPE ] = Toolkit::Visual::IMAGE;
2139   imageMap2[ Toolkit::ImageVisual::Property::URL ] = gImage_600_RGB;
2140   imageMap2[ DevelVisual::Property::VISUAL_FITTING_MODE ] = Toolkit::DevelVisual::CENTER;
2141
2142   imageView.SetProperty( Toolkit::ImageView::Property::IMAGE, imageMap2 );
2143   imageView.SetProperty( Actor::Property::SIZE, Vector2(800,700) );
2144
2145   application.GetScene().Add( imageView );
2146
2147   DALI_TEST_EQUALS( Test::WaitForEventThreadTrigger( 1 ), true, TEST_LOCATION );
2148
2149   // Trigger a potential relayout
2150   application.SendNotification();
2151   application.Render();
2152
2153   returnedMap.Clear();
2154   visual = DevelControl::GetVisual( Toolkit::Internal::GetImplementation( imageView ), Toolkit::ImageView::Property::IMAGE );
2155
2156   visual.CreatePropertyMap( returnedMap );
2157
2158   value = returnedMap.Find( Toolkit::Visual::Property::TRANSFORM );
2159   DALI_TEST_CHECK( value );
2160   map = value->GetMap();
2161   DALI_TEST_CHECK( map );
2162
2163   value = map->Find( Toolkit::Visual::Transform::Property::SIZE );
2164   DALI_TEST_CHECK( value );
2165   DALI_TEST_EQUALS( value->Get< Vector2 >(), Vector2( 600, 600 ), TEST_LOCATION ); // Change the internal size according to the image view size
2166
2167   value = map->Find( Toolkit::Visual::Transform::Property::SIZE_POLICY );
2168   DALI_TEST_CHECK( value );
2169   DALI_TEST_EQUALS( value->Get< Vector2 >(), Vector2( Toolkit::Visual::Transform::Policy::ABSOLUTE, Toolkit::Visual::Transform::Policy::ABSOLUTE ), TEST_LOCATION );
2170
2171   value = map->Find( Toolkit::Visual::Transform::Property::OFFSET );
2172   DALI_TEST_CHECK( value );
2173   DALI_TEST_EQUALS( value->Get< Vector2 >(), Vector2( 100, 50 ), TEST_LOCATION );
2174
2175   // 3. Render again using before fittingMode
2176   Property::Map imageMap3;
2177   imageMap3[ Toolkit::Visual::Property::TYPE ] = Toolkit::Visual::IMAGE;
2178   imageMap3[ Toolkit::ImageVisual::Property::URL ] = gImage_600_RGB;
2179   imageMap3[ DevelVisual::Property::VISUAL_FITTING_MODE ] =  Toolkit::DevelVisual::FIT_KEEP_ASPECT_RATIO;
2180
2181   imageView.SetProperty( Toolkit::ImageView::Property::IMAGE, imageMap3 );
2182   imageView.SetProperty( Actor::Property::SIZE, Vector2(800,700) );
2183
2184   application.GetScene().Add( imageView );
2185
2186   // Trigger a potential relayout
2187   application.SendNotification();
2188   application.Render();
2189
2190   returnedMap.Clear();
2191   visual = DevelControl::GetVisual( Toolkit::Internal::GetImplementation( imageView ), Toolkit::ImageView::Property::IMAGE );
2192   visual.CreatePropertyMap( returnedMap );
2193
2194   value = returnedMap.Find( Toolkit::Visual::Property::TRANSFORM );
2195   DALI_TEST_CHECK( value );
2196   map = value->GetMap();
2197   DALI_TEST_CHECK( map );
2198
2199   value = map->Find( Toolkit::Visual::Transform::Property::SIZE );
2200   DALI_TEST_CHECK( value );
2201   DALI_TEST_EQUALS( value->Get< Vector2 >(), Vector2( 700, 700 ), TEST_LOCATION ); // Change the internal size according to the image view size
2202
2203   value = map->Find( Toolkit::Visual::Transform::Property::SIZE_POLICY );
2204   DALI_TEST_CHECK( value );
2205   DALI_TEST_EQUALS( value->Get< Vector2 >(), Vector2( Toolkit::Visual::Transform::Policy::ABSOLUTE, Toolkit::Visual::Transform::Policy::ABSOLUTE ), TEST_LOCATION );
2206
2207   value = map->Find( Toolkit::Visual::Transform::Property::OFFSET );
2208   DALI_TEST_CHECK( value );
2209   DALI_TEST_EQUALS( value->Get< Vector2 >(), Vector2( 50, 0 ), TEST_LOCATION );
2210
2211   END_TEST;
2212 }
2213
2214 int UtcDaliImageViewFittingModesChangeFittingMode02(void)
2215 {
2216   ToolkitTestApplication application;
2217
2218   tet_infoline( "UtcDaliImageViewFittingModesChangeFittingMode, image: [600,600], view:[800,700]" );
2219
2220   ImageView imageView = ImageView::New();
2221
2222   // 1. Render using FittingMode::OVER_FIT_KEEP_ASPECT_RATIO
2223   Property::Map imageMap;
2224   imageMap[ Toolkit::Visual::Property::TYPE ] = Toolkit::Visual::IMAGE;
2225   imageMap[ Toolkit::ImageVisual::Property::URL ] = gImage_600_RGB;
2226   imageMap[ DevelVisual::Property::VISUAL_FITTING_MODE ] =  Toolkit::DevelVisual::OVER_FIT_KEEP_ASPECT_RATIO;
2227
2228   imageView.SetProperty( Toolkit::ImageView::Property::IMAGE, imageMap );
2229   imageView.SetProperty( Actor::Property::SIZE, Vector2(800,700) );
2230
2231   application.GetScene().Add( imageView );
2232
2233   // Trigger a potential relayout
2234   application.SendNotification();
2235   application.Render();
2236
2237   Toolkit::Visual::Base visual = DevelControl::GetVisual( Toolkit::Internal::GetImplementation( imageView ), Toolkit::ImageView::Property::IMAGE );
2238   Property::Map returnedMap;
2239   visual.CreatePropertyMap( returnedMap );
2240
2241   Property::Value* value = returnedMap.Find( Toolkit::Visual::Property::TRANSFORM );
2242   DALI_TEST_CHECK( value );
2243   Property::Map* map = value->GetMap();
2244   DALI_TEST_CHECK( map );
2245
2246   value = map->Find( Toolkit::Visual::Transform::Property::SIZE );
2247   DALI_TEST_CHECK( value );
2248   DALI_TEST_EQUALS( value->Get< Vector2 >(), Vector2( 800, 700 ), TEST_LOCATION ); // Change the internal size according to the image view size
2249
2250   value = map->Find( Toolkit::Visual::Transform::Property::SIZE_POLICY );
2251   DALI_TEST_CHECK( value );
2252   DALI_TEST_EQUALS( value->Get< Vector2 >(), Vector2( Toolkit::Visual::Transform::Policy::ABSOLUTE, Toolkit::Visual::Transform::Policy::ABSOLUTE ), TEST_LOCATION );
2253
2254   value = map->Find( Toolkit::Visual::Transform::Property::OFFSET );
2255   DALI_TEST_CHECK( value );
2256   DALI_TEST_EQUALS( value->Get< Vector2 >(), Vector2( 0, 0 ), TEST_LOCATION );
2257
2258   // 2. Render again using DevelVisaul::CENTER
2259   Property::Map imageMap2;
2260   imageMap2[ Toolkit::Visual::Property::TYPE ] = Toolkit::Visual::IMAGE;
2261   imageMap2[ Toolkit::ImageVisual::Property::URL ] = gImage_600_RGB;
2262   imageMap2[ DevelVisual::Property::VISUAL_FITTING_MODE ] = Toolkit::DevelVisual::CENTER;
2263
2264   imageView.SetProperty( Toolkit::ImageView::Property::IMAGE, imageMap2 );
2265   imageView.SetProperty( Actor::Property::SIZE, Vector2(800,700) );
2266
2267   application.GetScene().Add( imageView );
2268
2269   DALI_TEST_EQUALS( Test::WaitForEventThreadTrigger( 1 ), true, TEST_LOCATION );
2270
2271   // Trigger a potential relayout
2272   application.SendNotification();
2273   application.Render();
2274
2275   returnedMap.Clear();
2276   visual = DevelControl::GetVisual( Toolkit::Internal::GetImplementation( imageView ), Toolkit::ImageView::Property::IMAGE );
2277
2278   visual.CreatePropertyMap( returnedMap );
2279
2280   value = returnedMap.Find( Toolkit::Visual::Property::TRANSFORM );
2281   DALI_TEST_CHECK( value );
2282   map = value->GetMap();
2283   DALI_TEST_CHECK( map );
2284
2285   value = map->Find( Toolkit::Visual::Transform::Property::SIZE );
2286   DALI_TEST_CHECK( value );
2287   DALI_TEST_EQUALS( value->Get< Vector2 >(), Vector2( 600, 600 ), TEST_LOCATION ); // Change the internal size according to the image view size
2288
2289   value = map->Find( Toolkit::Visual::Transform::Property::SIZE_POLICY );
2290   DALI_TEST_CHECK( value );
2291   DALI_TEST_EQUALS( value->Get< Vector2 >(), Vector2( Toolkit::Visual::Transform::Policy::ABSOLUTE, Toolkit::Visual::Transform::Policy::ABSOLUTE ), TEST_LOCATION );
2292
2293   value = map->Find( Toolkit::Visual::Transform::Property::OFFSET );
2294   DALI_TEST_CHECK( value );
2295   DALI_TEST_EQUALS( value->Get< Vector2 >(), Vector2( 100, 50 ), TEST_LOCATION );
2296
2297   // 3. Render again using before fittingMode
2298   Property::Map imageMap3;
2299   imageMap3[ Toolkit::Visual::Property::TYPE ] = Toolkit::Visual::IMAGE;
2300   imageMap3[ Toolkit::ImageVisual::Property::URL ] = gImage_600_RGB;
2301   imageMap3[ DevelVisual::Property::VISUAL_FITTING_MODE ] =  Toolkit::DevelVisual::OVER_FIT_KEEP_ASPECT_RATIO;
2302
2303   imageView.SetProperty( Toolkit::ImageView::Property::IMAGE, imageMap3 );
2304   imageView.SetProperty( Actor::Property::SIZE, Vector2(800,700) );
2305
2306   application.GetScene().Add( imageView );
2307
2308   // Trigger a potential relayout
2309   application.SendNotification();
2310   application.Render();
2311
2312   returnedMap.Clear();
2313   visual = DevelControl::GetVisual( Toolkit::Internal::GetImplementation( imageView ), Toolkit::ImageView::Property::IMAGE );
2314   visual.CreatePropertyMap( returnedMap );
2315
2316   value = returnedMap.Find( Toolkit::Visual::Property::TRANSFORM );
2317   DALI_TEST_CHECK( value );
2318   map = value->GetMap();
2319   DALI_TEST_CHECK( map );
2320
2321   value = map->Find( Toolkit::Visual::Transform::Property::SIZE );
2322   DALI_TEST_CHECK( value );
2323   DALI_TEST_EQUALS( value->Get< Vector2 >(), Vector2( 800, 700 ), TEST_LOCATION ); // Change the internal size according to the image view size
2324
2325   value = map->Find( Toolkit::Visual::Transform::Property::SIZE_POLICY );
2326   DALI_TEST_CHECK( value );
2327   DALI_TEST_EQUALS( value->Get< Vector2 >(), Vector2( Toolkit::Visual::Transform::Policy::ABSOLUTE, Toolkit::Visual::Transform::Policy::ABSOLUTE ), TEST_LOCATION );
2328
2329   value = map->Find( Toolkit::Visual::Transform::Property::OFFSET );
2330   DALI_TEST_CHECK( value );
2331   DALI_TEST_EQUALS( value->Get< Vector2 >(), Vector2( 0, 0 ), TEST_LOCATION );
2332
2333   END_TEST;
2334 }
2335
2336 int UtcDaliImageViewFittingModesWithAnimatedVectorImageVisual(void)
2337 {
2338   ToolkitTestApplication application;
2339
2340   tet_infoline( "Create an ImageVisual using SCALE_TO_FILL and animated vector image ( image: [600,600], view:[600,600] )" );
2341
2342   ImageView imageView = ImageView::New();
2343   Property::Map imageMap;
2344   imageMap.Add( Toolkit::Visual::Property::TYPE, DevelVisual::ANIMATED_VECTOR_IMAGE );
2345   imageMap.Add( Toolkit::ImageVisual::Property::URL, TEST_VECTOR_IMAGE_FILE_NAME ); // 249x169 image
2346
2347   imageView.SetProperty( Toolkit::ImageView::Property::IMAGE, imageMap );
2348   imageView.SetProperty( Actor::Property::SIZE, Vector2(600,600) );
2349
2350   application.GetScene().Add( imageView );
2351
2352   // Trigger a potential relayout
2353   application.SendNotification();
2354   application.Render();
2355
2356   Toolkit::Visual::Base visual = DevelControl::GetVisual( Toolkit::Internal::GetImplementation( imageView ), Toolkit::ImageView::Property::IMAGE );
2357   Property::Map returnedMap;
2358   visual.CreatePropertyMap( returnedMap );
2359
2360   Property::Value* value = returnedMap.Find( Toolkit::Visual::Property::TRANSFORM );
2361   DALI_TEST_CHECK( value );
2362   Property::Map* map = value->GetMap();
2363   DALI_TEST_CHECK( map );
2364
2365   value = map->Find( Toolkit::Visual::Transform::Property::SIZE );
2366   DALI_TEST_CHECK( value );
2367   DALI_TEST_EQUALS( value->Get< Vector2 >(), Vector2::ONE, TEST_LOCATION ); // Relative size so will take up 100%
2368
2369   value = map->Find( Toolkit::Visual::Transform::Property::SIZE_POLICY );
2370   DALI_TEST_CHECK( value );
2371   DALI_TEST_CHECK( value->Get< int >() == Toolkit::Visual::Transform::Policy::RELATIVE );
2372
2373   value = map->Find( Toolkit::Visual::Transform::Property::OFFSET );
2374   DALI_TEST_CHECK( value );
2375   DALI_TEST_EQUALS( value->Get< Vector2 >(), Vector2( 0, 0 ), TEST_LOCATION ); // OFFSET is zero
2376
2377   END_TEST;
2378 }
2379
2380
2381 int UtcDaliImageViewCustomShader(void)
2382 {
2383   ToolkitTestApplication application;
2384
2385   // Set a custom shader with an image url
2386   {
2387     Property::Map properties;
2388     Property::Map shader;
2389     const std::string vertexShader = "Foobar";
2390     const std::string fragmentShader = "Foobar";
2391     shader[Visual::Shader::Property::FRAGMENT_SHADER] = fragmentShader;
2392     shader[Visual::Shader::Property::VERTEX_SHADER] = vertexShader;
2393
2394     properties[Visual::Property::TYPE] = Visual::IMAGE;
2395     properties[Visual::Property::SHADER] = shader;
2396     properties[ImageVisual::Property::URL] = TEST_IMAGE_FILE_NAME;
2397
2398     ImageView imageView = ImageView::New();
2399     imageView.SetProperty( ImageView::Property::IMAGE, properties );
2400
2401     application.GetScene().Add( imageView );
2402
2403     application.SendNotification();
2404     application.Render();
2405
2406     DALI_TEST_EQUALS( Test::WaitForEventThreadTrigger( 1 ), true, TEST_LOCATION );
2407
2408     Renderer renderer = imageView.GetRendererAt( 0 );
2409     Shader shader2 = renderer.GetShader();
2410     Property::Value value = shader2.GetProperty( Shader::Property::PROGRAM );
2411     Property::Map* map = value.GetMap();
2412     DALI_TEST_CHECK( map );
2413
2414     Property::Value* fragment = map->Find( "fragment" ); // fragment key name from shader-impl.cpp
2415     DALI_TEST_EQUALS( fragmentShader, fragment->Get< std::string >(), TEST_LOCATION );
2416
2417     Property::Value* vertex = map->Find( "vertex" ); // vertex key name from shader-impl.cpp
2418     DALI_TEST_EQUALS( vertexShader, vertex->Get< std::string >(), TEST_LOCATION );
2419   }
2420
2421   // Set a custom shader after setting an image url
2422   {
2423     Property::Map properties;
2424     Property::Map shader;
2425     const std::string vertexShader = "Foobar";
2426     const std::string fragmentShader = "Foobar";
2427     shader[Visual::Shader::Property::FRAGMENT_SHADER] = fragmentShader;
2428     shader[Visual::Shader::Property::VERTEX_SHADER] = vertexShader;
2429
2430     properties[Visual::Property::SHADER] = shader;
2431
2432     ImageView imageView = ImageView::New( TEST_IMAGE_FILE_NAME );
2433     imageView.SetProperty( ImageView::Property::IMAGE, properties );
2434
2435     application.GetScene().Add( imageView );
2436
2437     application.SendNotification();
2438     application.Render();
2439
2440     DALI_TEST_EQUALS( Test::WaitForEventThreadTrigger( 1 ), true, TEST_LOCATION );
2441
2442     Renderer renderer = imageView.GetRendererAt( 0 );
2443     Shader shader2 = renderer.GetShader();
2444     Property::Value value = shader2.GetProperty( Shader::Property::PROGRAM );
2445     Property::Map* map = value.GetMap();
2446     DALI_TEST_CHECK( map );
2447
2448     Property::Value* fragment = map->Find( "fragment" ); // fragment key name from shader-impl.cpp
2449     DALI_TEST_EQUALS( fragmentShader, fragment->Get< std::string >(), TEST_LOCATION );
2450
2451     Property::Value* vertex = map->Find( "vertex" ); // vertex key name from shader-impl.cpp
2452     DALI_TEST_EQUALS( vertexShader, vertex->Get< std::string >(), TEST_LOCATION );
2453   }
2454
2455   // Set a custom shader before setting an image url
2456   {
2457     Property::Map properties;
2458     Property::Map shader;
2459     const std::string vertexShader = "Foobar";
2460     const std::string fragmentShader = "Foobar";
2461     shader[Visual::Shader::Property::FRAGMENT_SHADER] = fragmentShader;
2462     shader[Visual::Shader::Property::VERTEX_SHADER] = vertexShader;
2463
2464     properties[Visual::Property::SHADER] = shader;
2465
2466     ImageView imageView = ImageView::New();
2467     imageView.SetProperty( ImageView::Property::IMAGE, properties );
2468     imageView.SetProperty( ImageView::Property::IMAGE, TEST_IMAGE_FILE_NAME );
2469
2470     application.GetScene().Add( imageView );
2471
2472     application.SendNotification();
2473     application.Render();
2474     DALI_TEST_EQUALS( Test::WaitForEventThreadTrigger( 1 ), true, TEST_LOCATION );
2475
2476     Renderer renderer = imageView.GetRendererAt( 0 );
2477     Shader shader2 = renderer.GetShader();
2478     Property::Value value = shader2.GetProperty( Shader::Property::PROGRAM );
2479     Property::Map* map = value.GetMap();
2480     DALI_TEST_CHECK( map );
2481
2482     Property::Value* fragment = map->Find( "fragment" ); // fragment key name from shader-impl.cpp
2483     DALI_TEST_EQUALS( fragmentShader, fragment->Get< std::string >(), TEST_LOCATION );
2484
2485     Property::Value* vertex = map->Find( "vertex" ); // vertex key name from shader-impl.cpp
2486     DALI_TEST_EQUALS( vertexShader, vertex->Get< std::string >(), TEST_LOCATION );
2487   }
2488
2489   // Set a custom shader after setting a property map
2490   {
2491     Property::Map properties;
2492     Property::Map shader;
2493     const std::string vertexShader = "Foobar";
2494     const std::string fragmentShader = "Foobar";
2495     shader[Visual::Shader::Property::FRAGMENT_SHADER] = fragmentShader;
2496     shader[Visual::Shader::Property::VERTEX_SHADER] = vertexShader;
2497
2498     properties[Visual::Property::SHADER] = shader;
2499
2500     Property::Map properties1;
2501     properties1[Visual::Property::TYPE] = Visual::IMAGE;
2502     properties1[ImageVisual::Property::URL] = TEST_IMAGE_FILE_NAME;
2503
2504     ImageView imageView = ImageView::New();
2505     imageView.SetProperty( ImageView::Property::IMAGE, properties1 );
2506     imageView.SetProperty( ImageView::Property::IMAGE, properties );
2507
2508     application.GetScene().Add( imageView );
2509
2510     application.SendNotification();
2511     application.Render();
2512     DALI_TEST_EQUALS( Test::WaitForEventThreadTrigger( 1 ), true, TEST_LOCATION );
2513
2514     Renderer renderer = imageView.GetRendererAt( 0 );
2515     Shader shader2 = renderer.GetShader();
2516     Property::Value value = shader2.GetProperty( Shader::Property::PROGRAM );
2517     Property::Map* map = value.GetMap();
2518     DALI_TEST_CHECK( map );
2519
2520     Property::Value* fragment = map->Find( "fragment" ); // fragment key name from shader-impl.cpp
2521     DALI_TEST_EQUALS( fragmentShader, fragment->Get< std::string >(), TEST_LOCATION );
2522
2523     Property::Value* vertex = map->Find( "vertex" ); // vertex key name from shader-impl.cpp
2524     DALI_TEST_EQUALS( vertexShader, vertex->Get< std::string >(), TEST_LOCATION );
2525   }
2526
2527   // Set a custom shader before setting a property map
2528   {
2529     Property::Map properties;
2530     Property::Map shader;
2531     const std::string vertexShader = "Foobar";
2532     const std::string fragmentShader = "Foobar";
2533     shader[Visual::Shader::Property::FRAGMENT_SHADER] = fragmentShader;
2534     shader[Visual::Shader::Property::VERTEX_SHADER] = vertexShader;
2535
2536     properties[Visual::Property::SHADER] = shader;
2537
2538     Property::Map properties1;
2539     properties1[Visual::Property::TYPE] = Visual::IMAGE;
2540     properties1[ImageVisual::Property::URL] = TEST_IMAGE_FILE_NAME;
2541
2542     ImageView imageView = ImageView::New();
2543     imageView.SetProperty( ImageView::Property::IMAGE, properties );
2544     imageView.SetProperty( ImageView::Property::IMAGE, properties1 );
2545
2546     application.GetScene().Add( imageView );
2547
2548     application.SendNotification();
2549     application.Render();
2550     DALI_TEST_EQUALS( Test::WaitForEventThreadTrigger( 1 ), true, TEST_LOCATION );
2551
2552     Renderer renderer = imageView.GetRendererAt( 0 );
2553     Shader shader2 = renderer.GetShader();
2554     Property::Value value = shader2.GetProperty( Shader::Property::PROGRAM );
2555     Property::Map* map = value.GetMap();
2556     DALI_TEST_CHECK( map );
2557
2558     Property::Value* fragment = map->Find( "fragment" ); // fragment key name from shader-impl.cpp
2559     DALI_TEST_EQUALS( fragmentShader, fragment->Get< std::string >(), TEST_LOCATION );
2560
2561     Property::Value* vertex = map->Find( "vertex" ); // vertex key name from shader-impl.cpp
2562     DALI_TEST_EQUALS( vertexShader, vertex->Get< std::string >(), TEST_LOCATION );
2563   }
2564
2565   END_TEST;
2566 }
2567
2568
2569 namespace
2570 {
2571 static int gFailCounter = 0;
2572 const int MAX_RETRIES(3);
2573
2574 void ReloadImage(ImageView imageView)
2575 {
2576   Property::Map imageImmediateLoadingMap;
2577   imageImmediateLoadingMap[ ImageVisual::Property::URL ] = "Non-existant-image.jpg";
2578   imageImmediateLoadingMap[ ImageVisual::Property::LOAD_POLICY ] =  ImageVisual::LoadPolicy::IMMEDIATE;
2579
2580   tet_infoline("Immediate load an image");
2581   imageView.SetProperty( ImageView::Property::IMAGE, imageImmediateLoadingMap );
2582 }
2583
2584 void ResourceFailedReload( Control control )
2585 {
2586   gFailCounter++;
2587   if( gFailCounter < MAX_RETRIES )
2588   {
2589     ReloadImage(ImageView::DownCast(control));
2590   }
2591 }
2592 }
2593
2594 int UtcDaliImageViewReloadFailedOnResourceReadySignal(void)
2595 {
2596   tet_infoline("Test reloading failed image from within signal handler.");
2597
2598   ToolkitTestApplication application;
2599
2600   gFailCounter = 0;
2601
2602   ImageView imageView = ImageView::New();
2603   imageView.ResourceReadySignal().Connect( &ResourceFailedReload );
2604   DALI_TEST_EQUALS( gFailCounter, 0, TEST_LOCATION );
2605   ReloadImage(imageView);
2606
2607   // loading started, this waits for the loader thread to complete
2608   DALI_TEST_EQUALS( Test::WaitForEventThreadTrigger( 1 ), true, TEST_LOCATION );
2609   application.SendNotification();
2610
2611   DALI_TEST_EQUALS( gFailCounter, 1, TEST_LOCATION );
2612
2613   DALI_TEST_EQUALS( Test::WaitForEventThreadTrigger( 1 ), true, TEST_LOCATION );
2614   application.SendNotification();
2615
2616   DALI_TEST_EQUALS( gFailCounter, 2, TEST_LOCATION );
2617
2618   DALI_TEST_EQUALS( Test::WaitForEventThreadTrigger( 1 ), true, TEST_LOCATION );
2619   application.SendNotification();
2620   DALI_TEST_EQUALS( gFailCounter, 3, TEST_LOCATION );
2621
2622   END_TEST;
2623 }
2624
2625 int UtcDaliImageViewLoadRemoteSVG(void)
2626 {
2627   tet_infoline("Test load from a remote server.");
2628
2629   ToolkitTestApplication application;
2630   Toolkit::ImageView imageView;
2631   imageView = Toolkit::ImageView::New();
2632   imageView.SetImage("https://dev.w3.org/SVG/tools/svgweb/samples/svg-files/check.svg");
2633   // Victor. Temporary (or permanent?) update as the url above seems not to work from time to time ...
2634 //  imageView.SetImage("https://upload.wikimedia.org/wikipedia/commons/thumb/0/02/SVG_logo.svg/64px-SVG_logo.svg.png");
2635   imageView.SetProperty( Actor::Property::PARENT_ORIGIN, ParentOrigin::TOP_LEFT );
2636   imageView.SetProperty( Actor::Property::ANCHOR_POINT, AnchorPoint::TOP_LEFT );
2637   imageView.SetProperty( Actor::Property::SIZE, Vector2(300, 300) );
2638   imageView.SetProperty( Actor::Property::POSITION, Vector3( 150.0f , 150.0f , 0.0f ) );
2639
2640   application.GetScene().Add( imageView );
2641
2642   DALI_TEST_CHECK( imageView );
2643
2644   DALI_TEST_EQUALS( imageView.GetRendererCount(), 0u, TEST_LOCATION );
2645
2646   application.SendNotification();
2647
2648   DALI_TEST_EQUALS( Test::WaitForEventThreadTrigger( 1 ), true, TEST_LOCATION );
2649
2650   application.SendNotification();
2651   application.Render();
2652
2653   DALI_TEST_EQUALS( imageView.GetRendererCount(), 1u, TEST_LOCATION );
2654
2655   END_TEST;
2656 }
2657
2658 int UtcDaliImageViewSyncSVGLoading(void)
2659 {
2660   ToolkitTestApplication application;
2661
2662   tet_infoline("ImageView Testing SVG image sync loading");
2663
2664   // Sync loading, automatic atlasing for small size image
2665   {
2666     TraceCallStack& callStack = application.GetGlAbstraction().GetTextureTrace();
2667     callStack.Reset();
2668     callStack.Enable(true);
2669
2670     ImageView imageView = ImageView::New( );
2671
2672     // Sync loading is used
2673     Property::Map syncLoadingMap;
2674     syncLoadingMap.Insert( Toolkit::Visual::Property::TYPE,  Toolkit::Visual::IMAGE );
2675     syncLoadingMap.Insert( Toolkit::ImageVisual::Property::URL,  TEST_RESOURCE_DIR "/svg1.svg"  );
2676     syncLoadingMap.Insert( Toolkit::ImageVisual::Property::SYNCHRONOUS_LOADING,  true);
2677     imageView.SetProperty( ImageView::Property::IMAGE, syncLoadingMap );
2678
2679     application.GetScene().Add( imageView );
2680     DALI_TEST_CHECK( imageView );
2681
2682     application.SendNotification();
2683     application.Render(16);
2684     Vector3 naturalSize = imageView.GetNaturalSize();
2685
2686     DALI_TEST_EQUALS( naturalSize.width, 100.0f, TEST_LOCATION );
2687     DALI_TEST_EQUALS( naturalSize.height, 100.0f, TEST_LOCATION );
2688
2689   }
2690   END_TEST;
2691 }
2692
2693 int UtcDaliImageViewAsyncSVGLoading(void)
2694 {
2695   ToolkitTestApplication application;
2696
2697   tet_infoline("ImageView Testing SVG image async loading");
2698
2699   // Sync loading, automatic atlasing for small size image
2700   {
2701     TraceCallStack& callStack = application.GetGlAbstraction().GetTextureTrace();
2702     callStack.Reset();
2703     callStack.Enable(true);
2704
2705     ImageView imageView = ImageView::New( );
2706
2707     // Sync loading is used
2708     Property::Map syncLoadingMap;
2709     syncLoadingMap.Insert( Toolkit::Visual::Property::TYPE,  Toolkit::Visual::IMAGE );
2710     syncLoadingMap.Insert( Toolkit::ImageVisual::Property::URL,  TEST_RESOURCE_DIR "/svg1.svg"  );
2711     syncLoadingMap.Insert( Toolkit::ImageVisual::Property::SYNCHRONOUS_LOADING,  false);
2712     imageView.SetProperty( ImageView::Property::IMAGE, syncLoadingMap );
2713
2714     application.GetScene().Add( imageView );
2715     DALI_TEST_CHECK( imageView );
2716
2717     application.SendNotification();
2718     application.Render(16);
2719     Vector3 naturalSize = imageView.GetNaturalSize();
2720
2721     DALI_TEST_EQUALS( naturalSize.width, 100.0f, TEST_LOCATION );
2722     DALI_TEST_EQUALS( naturalSize.height, 100.0f, TEST_LOCATION );
2723   }
2724   END_TEST;
2725 }
2726
2727 int UtcDaliImageViewSVGLoadingSyncSetInvalidValue(void)
2728 {
2729   ToolkitTestApplication application;
2730
2731   tet_infoline("ImageView Testing SVG image async loading");
2732
2733   // Sync loading, automatic atlasing for small size image
2734   {
2735     TraceCallStack& callStack = application.GetGlAbstraction().GetTextureTrace();
2736     callStack.Reset();
2737     callStack.Enable(true);
2738
2739     ImageView imageView = ImageView::New( );
2740
2741     // Sync loading is used
2742     Property::Map syncLoadingMap;
2743     syncLoadingMap.Insert( Toolkit::Visual::Property::TYPE,  Toolkit::Visual::IMAGE );
2744     syncLoadingMap.Insert( Toolkit::ImageVisual::Property::URL,  TEST_RESOURCE_DIR "/svg1.svg"  );
2745
2746     // Check to set invalid value
2747     // The SYNCHRONOUS_LOADING property must be set to the bool value.
2748     // Check if error log is outputted when setting other value like string.
2749     // Even if the wrong value is set, the image will be shown normally, and the synchronous value should be the default value(false).
2750     syncLoadingMap.Insert( Toolkit::ImageVisual::Property::SYNCHRONOUS_LOADING, std::to_string(5) );
2751     imageView.SetProperty( ImageView::Property::IMAGE, syncLoadingMap );
2752
2753     application.GetScene().Add( imageView );
2754     DALI_TEST_CHECK( imageView );
2755
2756     application.SendNotification();
2757     application.Render(16);
2758     Vector3 naturalSize = imageView.GetNaturalSize();
2759     DALI_TEST_EQUALS( naturalSize.width, 100.0f, TEST_LOCATION );
2760     DALI_TEST_EQUALS( naturalSize.height, 100.0f, TEST_LOCATION );
2761
2762     Property::Value value = imageView.GetProperty( ImageView::Property::IMAGE );
2763     Property::Map* map = value.GetMap();
2764     DALI_TEST_CHECK( map );
2765
2766     Property::Value* sync = map->Find( Toolkit::ImageVisual::Property::SYNCHRONOUS_LOADING );
2767     DALI_TEST_CHECK( sync );
2768     DALI_TEST_EQUALS( false, sync->Get< bool >(), TEST_LOCATION );
2769
2770   }
2771   END_TEST;
2772 }
2773
2774 int UtcDaliImageViewSvgLoadingFailure(void)
2775 {
2776   ToolkitTestApplication application;
2777
2778   // Local svg file - invalid file path
2779   {
2780     gResourceReadySignalFired = false;
2781
2782     ImageView imageView = ImageView::New( TEST_RESOURCE_DIR "/foo.svg" );
2783     imageView.SetProperty( Actor::Property::SIZE, Vector2( 200.f, 200.f ) );
2784     imageView.ResourceReadySignal().Connect( &ResourceReadySignal);
2785
2786     DALI_TEST_EQUALS( imageView.IsResourceReady(), false, TEST_LOCATION );
2787
2788     application.GetScene().Add( imageView );
2789
2790     application.SendNotification();
2791     application.Render(16);
2792
2793     DALI_TEST_EQUALS( gResourceReadySignalFired, true, TEST_LOCATION );
2794     DALI_TEST_EQUALS( imageView.IsResourceReady(), true, TEST_LOCATION );
2795     DALI_TEST_EQUALS( imageView.GetVisualResourceStatus( ImageView::Property::IMAGE ), Visual::ResourceStatus::FAILED, TEST_LOCATION );
2796   }
2797
2798   // Local svg file - invalid file
2799   {
2800     gResourceReadySignalFired = false;
2801
2802     ImageView imageView = ImageView::New( TEST_RESOURCE_DIR "/invalid.svg" );
2803     imageView.SetProperty( Actor::Property::SIZE, Vector2( 200.f, 200.f ) );
2804     imageView.ResourceReadySignal().Connect( &ResourceReadySignal);
2805
2806     DALI_TEST_EQUALS( imageView.IsResourceReady(), false, TEST_LOCATION );
2807
2808     application.GetScene().Add( imageView );
2809
2810     application.SendNotification();
2811     application.Render(16);
2812
2813     DALI_TEST_EQUALS( gResourceReadySignalFired, true, TEST_LOCATION );
2814     DALI_TEST_EQUALS( imageView.IsResourceReady(), true, TEST_LOCATION );
2815     DALI_TEST_EQUALS( imageView.GetVisualResourceStatus( ImageView::Property::IMAGE ), Visual::ResourceStatus::FAILED, TEST_LOCATION );
2816   }
2817
2818   // Remote svg file
2819   {
2820     gResourceReadySignalFired = false;
2821
2822     ImageView imageView = ImageView::New( "https://bar.org/foobar.svg" );
2823     imageView.SetProperty( Actor::Property::SIZE, Vector2( 200.f, 200.f ) );
2824     imageView.ResourceReadySignal().Connect( &ResourceReadySignal);
2825
2826     DALI_TEST_EQUALS( imageView.IsResourceReady(), false, TEST_LOCATION );
2827
2828     application.GetScene().Add( imageView );
2829
2830     application.SendNotification();
2831
2832     // loading started, this waits for the loader thread
2833     DALI_TEST_EQUALS( Test::WaitForEventThreadTrigger( 1 ), true, TEST_LOCATION );
2834
2835     application.SendNotification();
2836     application.Render(16);
2837
2838     DALI_TEST_EQUALS( gResourceReadySignalFired, true, TEST_LOCATION );
2839     DALI_TEST_EQUALS( imageView.IsResourceReady(), true, TEST_LOCATION );
2840     DALI_TEST_EQUALS( imageView.GetVisualResourceStatus( ImageView::Property::IMAGE ), Visual::ResourceStatus::FAILED, TEST_LOCATION );
2841   }
2842
2843   END_TEST;
2844 }
2845
2846 int UtcDaliImageViewSvgRasterizationFailure(void)
2847 {
2848   ToolkitTestApplication application;
2849
2850   gResourceReadySignalFired = false;
2851
2852   ImageView imageView = ImageView::New( TEST_RESOURCE_DIR "/svg1.svg" );
2853   imageView.SetProperty( Actor::Property::SIZE, Vector2( 200.f, 200.f ) );
2854   imageView.ResourceReadySignal().Connect( &ResourceReadySignal);
2855
2856   DALI_TEST_EQUALS( imageView.IsResourceReady(), false, TEST_LOCATION );
2857
2858   application.GetScene().Add( imageView );
2859
2860   application.SendNotification();
2861
2862   // loading started, this waits for the loader thread
2863   DALI_TEST_EQUALS( Test::WaitForEventThreadTrigger( 1 ), true, TEST_LOCATION );
2864
2865   application.SendNotification();
2866   application.Render(16);
2867
2868   DALI_TEST_EQUALS( gResourceReadySignalFired, true, TEST_LOCATION );
2869   DALI_TEST_EQUALS( imageView.IsResourceReady(), true, TEST_LOCATION );
2870   DALI_TEST_EQUALS( imageView.GetVisualResourceStatus( ImageView::Property::IMAGE ), Visual::ResourceStatus::READY, TEST_LOCATION );
2871
2872   // Reset flag
2873   gResourceReadySignalFired = false;
2874
2875   // Change size
2876   imageView.SetProperty( Actor::Property::SIZE, Vector2( 0.f, 0.f ) );
2877
2878   application.SendNotification();
2879
2880   // rasterization started, this waits for the rasterize thread
2881   DALI_TEST_EQUALS( Test::WaitForEventThreadTrigger( 1 ), true, TEST_LOCATION );
2882
2883   application.SendNotification();
2884   application.Render(16);
2885
2886   DALI_TEST_EQUALS( gResourceReadySignalFired, true, TEST_LOCATION );
2887   DALI_TEST_EQUALS( imageView.IsResourceReady(), true, TEST_LOCATION );
2888   // Fail to rasterize because the size is 0.
2889   DALI_TEST_EQUALS( imageView.GetVisualResourceStatus( ImageView::Property::IMAGE ), Visual::ResourceStatus::FAILED, TEST_LOCATION );
2890
2891   END_TEST;
2892 }
2893
2894 int UtcDaliImageViewTVGLoading(void)
2895 {
2896   ToolkitTestApplication application;
2897
2898   tet_infoline("ImageView Testing TVG image loading");
2899
2900   {
2901     ImageView imageView = ImageView::New( );
2902
2903     imageView.SetImage( TEST_RESOURCE_DIR "/test.tvg" );
2904
2905     application.GetScene().Add( imageView );
2906     DALI_TEST_CHECK( imageView );
2907     Vector3 naturalSize = imageView.GetNaturalSize();
2908
2909     DALI_TEST_EQUALS( naturalSize.width, 100.0f, TEST_LOCATION );
2910     DALI_TEST_EQUALS( naturalSize.height, 100.0f, TEST_LOCATION );
2911   }
2912   END_TEST;
2913 }
2914 int UtcDaliImageViewImageLoadFailure01(void)
2915 {
2916   ToolkitTestApplication application;
2917
2918   Toolkit::StyleManager styleManager = Toolkit::StyleManager::Get();
2919   DevelStyleManager::SetBrokenImageUrl(styleManager, DevelStyleManager::BrokenImageType::SMALL, TEST_BROKEN_IMAGE_S);
2920   DevelStyleManager::SetBrokenImageUrl(styleManager, DevelStyleManager::BrokenImageType::NORMAL, TEST_BROKEN_IMAGE_M);
2921   DevelStyleManager::SetBrokenImageUrl(styleManager, DevelStyleManager::BrokenImageType::LARGE, TEST_BROKEN_IMAGE_L);
2922
2923   std::string brokenUrl;
2924   brokenUrl = DevelStyleManager::GetBrokenImageUrl(styleManager, DevelStyleManager::BrokenImageType::SMALL);
2925   DALI_TEST_EQUALS( TEST_BROKEN_IMAGE_S, brokenUrl, TEST_LOCATION);
2926
2927   brokenUrl = DevelStyleManager::GetBrokenImageUrl(styleManager, DevelStyleManager::BrokenImageType::NORMAL);
2928   DALI_TEST_EQUALS( TEST_BROKEN_IMAGE_M, brokenUrl, TEST_LOCATION);
2929
2930   brokenUrl = DevelStyleManager::GetBrokenImageUrl(styleManager, DevelStyleManager::BrokenImageType::LARGE);
2931   DALI_TEST_EQUALS( TEST_BROKEN_IMAGE_L, brokenUrl, TEST_LOCATION);
2932
2933   ImageView imageView = ImageView::New("invalidUrl.png");
2934   imageView.SetProperty( Actor::Property::SIZE, Vector2( 200.f, 200.f ) );
2935
2936   application.GetScene().Add( imageView );
2937   application.SendNotification();
2938   application.Render(16);
2939
2940   // loading started, this waits for the loader thread
2941   DALI_TEST_EQUALS( Test::WaitForEventThreadTrigger( 1 ), true, TEST_LOCATION );
2942
2943   END_TEST;
2944 }
2945
2946 int UtcDaliImageViewImageLoadFailure02(void)
2947 {
2948   ToolkitTestApplication application;
2949
2950   Toolkit::StyleManager styleManager = Toolkit::StyleManager::Get();
2951   DevelStyleManager::SetBrokenImageUrl(styleManager, DevelStyleManager::BrokenImageType::SMALL, TEST_BROKEN_IMAGE_DEFAULT);
2952   DevelStyleManager::SetBrokenImageUrl(styleManager, DevelStyleManager::BrokenImageType::NORMAL, TEST_BROKEN_IMAGE_M);
2953   DevelStyleManager::SetBrokenImageUrl(styleManager, DevelStyleManager::BrokenImageType::LARGE, TEST_BROKEN_IMAGE_L);
2954
2955   std::string brokenUrl;
2956   brokenUrl = DevelStyleManager::GetBrokenImageUrl(styleManager, DevelStyleManager::BrokenImageType::SMALL);
2957   DALI_TEST_EQUALS( TEST_BROKEN_IMAGE_DEFAULT, brokenUrl, TEST_LOCATION);
2958
2959   brokenUrl = DevelStyleManager::GetBrokenImageUrl(styleManager, DevelStyleManager::BrokenImageType::NORMAL);
2960   DALI_TEST_EQUALS( TEST_BROKEN_IMAGE_M, brokenUrl, TEST_LOCATION);
2961
2962   brokenUrl = DevelStyleManager::GetBrokenImageUrl(styleManager, DevelStyleManager::BrokenImageType::LARGE);
2963   DALI_TEST_EQUALS( TEST_BROKEN_IMAGE_L, brokenUrl, TEST_LOCATION);
2964
2965   ImageView imageView = ImageView::New("invalidUrl.png");
2966   imageView.SetProperty( Actor::Property::SIZE, Vector2( 30.f, 30.f ) );
2967   application.GetScene().Add( imageView );
2968   application.SendNotification();
2969   application.Render(16);
2970
2971   // loading started, this waits for the loader thread
2972   DALI_TEST_EQUALS( Test::WaitForEventThreadTrigger( 1 ), true, TEST_LOCATION );
2973
2974   END_TEST;
2975 }
2976
2977 int UtcDaliImageViewImageLoadFailure03(void)
2978 {
2979   ToolkitTestApplication application;
2980
2981   Toolkit::StyleManager styleManager = Toolkit::StyleManager::Get();
2982   DevelStyleManager::SetBrokenImageUrl(styleManager, DevelStyleManager::BrokenImageType::SMALL, TEST_BROKEN_IMAGE_01);
2983   DevelStyleManager::SetBrokenImageUrl(styleManager, DevelStyleManager::BrokenImageType::NORMAL, TEST_BROKEN_IMAGE_02);
2984
2985   std::string brokenUrl;
2986   brokenUrl = DevelStyleManager::GetBrokenImageUrl(styleManager, DevelStyleManager::BrokenImageType::SMALL);
2987   DALI_TEST_EQUALS( TEST_BROKEN_IMAGE_01, brokenUrl, TEST_LOCATION);
2988
2989   brokenUrl = DevelStyleManager::GetBrokenImageUrl(styleManager, DevelStyleManager::BrokenImageType::NORMAL);
2990   DALI_TEST_EQUALS( TEST_BROKEN_IMAGE_02, brokenUrl, TEST_LOCATION);
2991
2992   ImageView imageView = ImageView::New("invalidUrl.png");
2993   imageView.SetProperty( Actor::Property::SIZE, Vector2( 100.f, 100.f ) );
2994   application.GetScene().Add( imageView );
2995   application.SendNotification();
2996   application.Render(16);
2997
2998   // loading started, this waits for the loader thread
2999   DALI_TEST_EQUALS( Test::WaitForEventThreadTrigger( 1 ), true, TEST_LOCATION );
3000
3001   END_TEST;
3002 }
3003
3004 namespace
3005 {
3006
3007 static int gResourceReadySignalCounter = 0;
3008
3009 void OnResourceReadySignal01( Control control )
3010 {
3011   gResourceReadySignalCounter++;
3012
3013   if(control.GetVisualResourceStatus(ImageView::Property::IMAGE) == Visual::ResourceStatus::READY)
3014   {
3015     if( gResourceReadySignalCounter == 1 )
3016     {
3017       // Set image twice
3018       // It makes the first new visual be deleted immediately
3019       ImageView::DownCast( control ).SetImage( gImage_34_RGBA );
3020       ImageView::DownCast( control ).SetImage( gImage_34_RGBA );
3021     }
3022   }
3023   else if(control.GetVisualResourceStatus(ImageView::Property::IMAGE) == Visual::ResourceStatus::FAILED)
3024   {
3025     // Make the resource ready immediately
3026     control[ImageView::Property::IMAGE] = TEST_RESOURCE_DIR "/svg1.svg";
3027   }
3028 }
3029
3030 void OnResourceReadySignal02( Control control )
3031 {
3032   if(++gResourceReadySignalCounter == 1)
3033   {
3034     // It makes the first new visual be deleted immediately
3035     // The first image will not be loaded.
3036     control[ImageView::Property::IMAGE] = Property::Map().Add(ImageVisual::Property::URL, gImage_600_RGB)
3037                                                          .Add(ImageVisual::Property::RELEASE_POLICY, ImageVisual::ReleasePolicy::NEVER);
3038     control[ImageView::Property::IMAGE] = TEST_IMAGE_1;
3039   }
3040 }
3041
3042 ImageView gImageView1;
3043 ImageView gImageView2;
3044 ImageView gImageView3;
3045
3046 void OnResourceReadySignal03( Control control )
3047 {
3048   if(gResourceReadySignalCounter == 0)
3049   {
3050     // Queue loading
3051     // 1. Use cached image, then UploadComplete will be called right after OnResourceReadySignal03.
3052     gImageView2[ImageView::Property::IMAGE] = gImage_34_RGBA;
3053
3054     // 2. Load a new image
3055     gImageView3[ImageView::Property::IMAGE] = TEST_IMAGE_1;
3056
3057     // 3. Use the new image again
3058     gImageView1[ImageView::Property::IMAGE] = TEST_IMAGE_1;
3059     gImageView1.ResourceReadySignal().Connect(&OnResourceReadySignal03);
3060   }
3061   else if(gResourceReadySignalCounter == 1)
3062   {
3063     // This is called from TextureManager::ProcessQueuedTextures().
3064     gImageView1.Unparent();
3065     gImageView1.Reset();
3066   }
3067   gResourceReadySignalCounter++;
3068 }
3069
3070 }
3071
3072 int UtcDaliImageViewSetImageOnResourceReadySignal01(void)
3073 {
3074   tet_infoline("Test setting image from within signal handler.");
3075
3076   ToolkitTestApplication application;
3077
3078   gResourceReadySignalCounter = 0;
3079
3080   ImageView imageView = ImageView::New( gImage_34_RGBA );
3081   imageView.ResourceReadySignal().Connect( &OnResourceReadySignal01 );
3082
3083   application.GetScene().Add( imageView );
3084
3085   DALI_TEST_EQUALS( Test::WaitForEventThreadTrigger( 1 ), true, TEST_LOCATION );
3086
3087   application.SendNotification();
3088   application.Render();
3089
3090   DALI_TEST_EQUALS( gResourceReadySignalCounter, 2, TEST_LOCATION );
3091
3092   DALI_TEST_EQUALS( imageView.IsResourceReady(), true, TEST_LOCATION );
3093
3094   // Reset count
3095   gResourceReadySignalCounter = 0;
3096
3097   imageView[ImageView::Property::IMAGE] = "invalid.jpg";
3098
3099   DALI_TEST_EQUALS( Test::WaitForEventThreadTrigger( 1 ), true, TEST_LOCATION );
3100
3101   application.SendNotification();
3102   application.Render();
3103
3104   // Run idle callback
3105   application.RunIdles();
3106
3107   DALI_TEST_EQUALS( gResourceReadySignalCounter, 2, TEST_LOCATION );
3108
3109   DALI_TEST_EQUALS( imageView.IsResourceReady(), true, TEST_LOCATION );
3110
3111   END_TEST;
3112 }
3113
3114 int UtcDaliImageViewSetImageOnResourceReadySignal02(void)
3115 {
3116   tet_infoline("Test setting image from within signal handler.");
3117
3118   ToolkitTestApplication application;
3119
3120   gResourceReadySignalCounter = 0;
3121
3122   ImageView imageView = ImageView::New( gImage_34_RGBA );
3123   imageView.ResourceReadySignal().Connect( &OnResourceReadySignal02 );
3124
3125   application.GetScene().Add( imageView );
3126
3127   DALI_TEST_EQUALS( Test::WaitForEventThreadTrigger( 1 ), true, TEST_LOCATION );
3128
3129   application.SendNotification();
3130   application.Render();
3131
3132   // Wait for loading an image
3133   DALI_TEST_EQUALS( Test::WaitForEventThreadTrigger( 1 ), true, TEST_LOCATION );
3134
3135   DALI_TEST_EQUALS( gResourceReadySignalCounter, 2, TEST_LOCATION );
3136
3137   DALI_TEST_EQUALS( imageView.IsResourceReady(), true, TEST_LOCATION );
3138
3139   END_TEST;
3140 }
3141
3142 int UtcDaliImageViewSetImageOnResourceReadySignal03(void)
3143 {
3144   tet_infoline("Test setting image from within signal handler.");
3145
3146   ToolkitTestApplication application;
3147
3148   gResourceReadySignalCounter = 0;
3149
3150   gImageView1 = ImageView::New(gImage_34_RGBA);
3151   application.GetScene().Add(gImageView1);
3152
3153   // Wait for loading
3154   DALI_TEST_EQUALS(Test::WaitForEventThreadTrigger(1), true, TEST_LOCATION);
3155
3156   gImageView2 = ImageView::New(gImage_600_RGB);
3157   gImageView2.ResourceReadySignal().Connect(&OnResourceReadySignal03);
3158   application.GetScene().Add(gImageView2);
3159
3160   gImageView3 = ImageView::New();
3161   application.GetScene().Add(gImageView3);
3162
3163   DALI_TEST_EQUALS(Test::WaitForEventThreadTrigger(2), true, TEST_LOCATION);
3164
3165   application.SendNotification();
3166   application.Render();
3167
3168   END_TEST;
3169 }