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