Replace registered visuals only when replacement is ready
[platform/core/uifw/dali-toolkit.git] / automated-tests / src / dali-toolkit / utc-Dali-ImageView.cpp
1 /*
2  * Copyright (c) 2017 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/visuals/image-visual-properties-devel.h>
26 #include <dali-toolkit/devel-api/controls/control-devel.h>
27 #include <dali/public-api/rendering/renderer.h>
28
29 #include <test-native-image.h>
30 #include <sstream>
31 #include <unistd.h>
32
33 using namespace Dali;
34 using namespace Toolkit;
35
36 void utc_dali_toolkit_image_view_startup(void)
37 {
38   test_return_value = TET_UNDEF;
39 }
40
41 void utc_dali_toolkit_image_view_cleanup(void)
42 {
43   test_return_value = TET_PASS;
44 }
45
46 namespace
47 {
48
49 const char* VERTEX_SHADER = DALI_COMPOSE_SHADER(
50   attribute mediump vec2 aPosition;\n
51   varying mediump vec2 vTexCoord;\n
52   uniform mediump mat4 uMvpMatrix;\n
53   uniform mediump vec3 uSize;\n
54   \n
55   void main()\n
56   {\n
57     mediump vec4 vertexPosition = vec4(aPosition, 0.0, 1.0);\n
58     vertexPosition.xyz *= uSize;\n
59     vertexPosition = uMvpMatrix * vertexPosition;\n
60     \n
61     vTexCoord = aPosition + vec2(0.5);\n
62     gl_Position = vertexPosition;\n
63   }\n
64 );
65
66 const char* FRAGMENT_SHADER = DALI_COMPOSE_SHADER(
67   varying mediump vec2 vTexCoord;\n
68   uniform sampler2D sTexture;\n
69   uniform lowp vec4 uColor;\n
70   \n
71   void main()\n
72   {\n
73     gl_FragColor = texture2D( sTexture, vTexCoord ) * uColor;\n
74   }\n
75 );
76
77 const char* TEST_IMAGE_FILE_NAME =  "gallery_image_01.jpg";
78 const char* TEST_IMAGE_FILE_NAME2 =  "gallery_image_02.jpg";
79
80 const char* TEST_IMAGE_1 = TEST_RESOURCE_DIR "/TB-gloss.png";
81 const char* TEST_IMAGE_2 = TEST_RESOURCE_DIR "/tb-norm.png";
82
83 // resolution: 34*34, pixel format: RGBA8888
84 static const char* gImage_34_RGBA = TEST_RESOURCE_DIR "/icon-edit.png";
85 // resolution: 600*600, pixel format: RGB888
86 static const char* gImage_600_RGB = TEST_RESOURCE_DIR "/test-image-600.jpg";
87
88 // resolution: 50*50, frame count: 4, frame delay: 0.2 second for each frame
89 const char* TEST_GIF_FILE_NAME = TEST_RESOURCE_DIR "/anim.gif";
90
91 void TestImage( ImageView imageView, BufferImage image )
92 {
93   Property::Value value = imageView.GetProperty( imageView.GetPropertyIndex( "image" ) );
94
95   Property::Map map;
96   DALI_TEST_CHECK( value.Get( map ) );
97
98   DALI_TEST_CHECK( map.Find( "width" ) );
99   DALI_TEST_CHECK( map.Find( "height" ) );
100   DALI_TEST_CHECK( map.Find( "type" ) );
101
102   int width = 0;
103   DALI_TEST_CHECK( map[ "width" ].Get( width ) );
104   DALI_TEST_EQUALS( (unsigned int)width, image.GetWidth(), TEST_LOCATION );
105
106   int height = 0;
107   DALI_TEST_CHECK( map[ "height" ].Get( height ) );
108   DALI_TEST_EQUALS( (unsigned int)height, image.GetHeight(), TEST_LOCATION );
109
110   std::string type;
111   DALI_TEST_CHECK( map[ "type" ].Get( type ) );
112   DALI_TEST_EQUALS( type, "BufferImage", TEST_LOCATION );
113 }
114
115 void TestImage( ImageView imageView, ResourceImage image )
116 {
117   Property::Value value = imageView.GetProperty( imageView.GetPropertyIndex( "image" ) );
118
119   Property::Map map;
120   DALI_TEST_CHECK( value.Get( map ) );
121
122   if( map.Find( "width" ) )
123   {
124     int width = 0;
125     DALI_TEST_CHECK( map[ "width" ].Get( width ) );
126     DALI_TEST_EQUALS( (unsigned int)width, image.GetWidth(), TEST_LOCATION );
127   }
128
129   if( map.Find( "height" ) )
130   {
131     int height = 0;
132     DALI_TEST_CHECK( map[ "height" ].Get( height ) );
133     DALI_TEST_EQUALS( (unsigned int)height, image.GetHeight(), TEST_LOCATION );
134   }
135
136   DALI_TEST_CHECK( map.Find( "type" ) );
137
138   std::string type;
139   DALI_TEST_CHECK( map[ "type" ].Get( type ) );
140   DALI_TEST_EQUALS( type, "ResourceImage", TEST_LOCATION );
141
142   std::string filename;
143   DALI_TEST_CHECK( map[ "filename" ].Get( filename ) );
144   DALI_TEST_EQUALS( filename, image.GetUrl(), TEST_LOCATION );
145 }
146
147 void TestUrl( ImageView imageView, const std::string url )
148 {
149   Property::Value value = imageView.GetProperty( imageView.GetPropertyIndex( "image" ) );
150
151   std::string urlActual;
152   DALI_TEST_CHECK( value.Get( urlActual ) );
153   DALI_TEST_EQUALS( urlActual, url, TEST_LOCATION );
154 }
155
156 } // namespace
157
158 int UtcDaliImageViewNewP(void)
159 {
160   TestApplication application;
161
162   ImageView imageView = ImageView::New();
163
164   DALI_TEST_CHECK( imageView );
165
166   END_TEST;
167 }
168
169 int UtcDaliImageViewNewImageP(void)
170 {
171   TestApplication application;
172
173   BufferImage image = CreateBufferImage( 100, 200, Vector4( 1.f, 1.f, 1.f, 1.f ) );
174   ImageView imageView = ImageView::New( image );
175
176   DALI_TEST_CHECK( imageView );
177   TestImage( imageView, image );
178
179   END_TEST;
180 }
181
182 int UtcDaliImageViewNewUrlP(void)
183 {
184   TestApplication application;
185
186   ImageView imageView = ImageView::New( TEST_IMAGE_FILE_NAME );
187   DALI_TEST_CHECK( imageView );
188
189   TestUrl( imageView, TEST_IMAGE_FILE_NAME );
190
191   END_TEST;
192 }
193
194 int UtcDaliImageViewConstructorP(void)
195 {
196   TestApplication application;
197
198   ImageView imageView;
199
200   DALI_TEST_CHECK( !imageView );
201
202   END_TEST;
203 }
204
205 int UtcDaliImageViewCopyConstructorP(void)
206 {
207   TestApplication application;
208
209   // Initialize an object, ref count == 1
210   ImageView imageView = ImageView::New();
211
212   ImageView copy( imageView );
213   DALI_TEST_CHECK( copy );
214
215   END_TEST;
216 }
217
218 int UtcDaliImageViewAssignmentOperatorP(void)
219 {
220   TestApplication application;
221
222   ImageView imageView = ImageView::New();
223
224   ImageView copy( imageView );
225   DALI_TEST_CHECK( copy );
226   DALI_TEST_EQUALS( imageView, copy, TEST_LOCATION );
227
228   END_TEST;
229 }
230
231 int UtcDaliImageViewDownCastP(void)
232 {
233   TestApplication application;
234
235   ImageView imageView = ImageView::New();
236
237   BaseHandle object(imageView);
238
239   ImageView imageView2 = ImageView::DownCast( object );
240   DALI_TEST_CHECK(imageView2);
241
242   ImageView imageView3 = DownCast< ImageView >( object );
243   DALI_TEST_CHECK(imageView3);
244
245   END_TEST;
246 }
247
248 int UtcDaliImageViewDownCastN(void)
249 {
250   TestApplication application;
251
252   BaseHandle unInitializedObject;
253
254   ImageView imageView1 = ImageView::DownCast( unInitializedObject );
255   DALI_TEST_CHECK( !imageView1 );
256
257   ImageView imageView2 = DownCast< ImageView >( unInitializedObject );
258   DALI_TEST_CHECK( !imageView2 );
259
260   END_TEST;
261 }
262
263 int UtcDaliImageViewTypeRegistry(void)
264 {
265   ToolkitTestApplication application;
266
267   TypeRegistry typeRegistry = TypeRegistry::Get();
268   DALI_TEST_CHECK( typeRegistry );
269
270   TypeInfo typeInfo = typeRegistry.GetTypeInfo( "ImageView" );
271   DALI_TEST_CHECK( typeInfo );
272
273   BaseHandle handle = typeInfo.CreateInstance();
274   DALI_TEST_CHECK( handle );
275
276   ImageView imageView = ImageView::DownCast( handle );
277   DALI_TEST_CHECK( imageView );
278
279   END_TEST;
280 }
281
282 int UtcDaliImageViewSetGetProperty01(void)
283 {
284   ToolkitTestApplication application;
285
286   ImageView imageView = ImageView::New();
287
288   Property::Index idx = imageView.GetPropertyIndex( "image" );
289   DALI_TEST_EQUALS( idx, (Property::Index)ImageView::Property::IMAGE, TEST_LOCATION );
290
291   imageView.SetProperty( idx, TEST_IMAGE_FILE_NAME );
292   TestUrl( imageView, TEST_IMAGE_FILE_NAME );
293
294   END_TEST;
295 }
296
297 int UtcDaliImageViewSetGetProperty02(void)
298 {
299   ToolkitTestApplication application;
300
301   Image image = CreateBufferImage( 10, 10, Color::WHITE );
302   ImageView imageView = ImageView::New(image);
303   Vector4 fullImageRect( 0.f, 0.f, 1.f, 1.f );
304
305   Stage::GetCurrent().Add( imageView );
306
307   application.SendNotification();
308   application.Render();
309   TestGlAbstraction& gl = application.GetGlAbstraction();
310
311   Vector4 pixelAreaUniform;
312   DALI_TEST_CHECK( gl.GetUniformValue<Vector4>( "pixelArea", pixelAreaUniform ) );
313   DALI_TEST_EQUALS( pixelAreaUniform, fullImageRect, TEST_LOCATION );
314
315   Property::Value value = imageView.GetProperty( ImageView::Property::PIXEL_AREA );
316   Vector4 pixelAreaValue;
317   DALI_TEST_CHECK( value.Get(pixelAreaValue) );
318   DALI_TEST_EQUALS( pixelAreaValue, fullImageRect, TEST_LOCATION );
319
320   Vector4 pixelAreaSet( 0.2f, 0.2f, 0.3f, 0.3f );
321   imageView.SetProperty( ImageView::Property::PIXEL_AREA, pixelAreaSet);
322
323   application.SendNotification();
324   application.Render();
325
326   value = imageView.GetProperty( ImageView::Property::PIXEL_AREA );
327   value.Get(pixelAreaValue);
328   DALI_TEST_EQUALS( pixelAreaValue, pixelAreaSet, TEST_LOCATION );
329
330   DALI_TEST_CHECK( gl.GetUniformValue<Vector4>( "pixelArea", pixelAreaUniform ) );
331   DALI_TEST_EQUALS( pixelAreaUniform, pixelAreaSet, TEST_LOCATION );
332
333   END_TEST;
334 }
335
336 int UtcDaliImageViewSetGetProperty03(void)
337 {
338   ToolkitTestApplication application;
339
340   Image image = CreateBufferImage( 10, 10, Color::WHITE );
341   ImageView imageView = ImageView::New(image);
342   Stage::GetCurrent().Add( imageView );
343   application.SendNotification();
344   application.Render();
345
346   // conventional alpha blending
347   Renderer renderer = imageView.GetRendererAt( 0 );
348   Property::Value value = renderer.GetProperty( Renderer::Property::BLEND_PRE_MULTIPLIED_ALPHA );
349   bool enable;
350   DALI_TEST_CHECK( value.Get( enable ) );
351   DALI_TEST_CHECK( !enable );
352
353   // pre-multiplied alpha blending
354   imageView.SetProperty( Toolkit::ImageView::Property::PRE_MULTIPLIED_ALPHA, true );
355   application.SendNotification();
356   application.Render();
357
358   int srcFactorRgb    = renderer.GetProperty<int>( Renderer::Property::BLEND_FACTOR_SRC_RGB );
359   int destFactorRgb   = renderer.GetProperty<int>( Renderer::Property::BLEND_FACTOR_DEST_RGB );
360   int srcFactorAlpha  = renderer.GetProperty<int>( Renderer::Property::BLEND_FACTOR_SRC_ALPHA );
361   int destFactorAlpha = renderer.GetProperty<int>( Renderer::Property::BLEND_FACTOR_DEST_ALPHA );
362   DALI_TEST_CHECK( srcFactorRgb == BlendFactor::ONE );
363   DALI_TEST_CHECK( destFactorRgb == BlendFactor::ONE_MINUS_SRC_ALPHA );
364   DALI_TEST_CHECK( srcFactorAlpha == BlendFactor::ONE );
365   DALI_TEST_CHECK( destFactorAlpha == BlendFactor::ONE );
366
367   value = renderer.GetProperty( Renderer::Property::BLEND_PRE_MULTIPLIED_ALPHA );
368   DALI_TEST_CHECK( value.Get( enable ) );
369   DALI_TEST_CHECK( enable );
370
371   END_TEST;
372 }
373
374 int UtcDaliImageViewPixelArea(void)
375 {
376   // Test pixel area property
377   ToolkitTestApplication application;
378
379   // Gif image, use AnimatedImageVisual internally
380   // Atlasing is applied to pack multiple frames, use custom wrap mode
381   ImageView gifView = ImageView::New();
382   const Vector4 pixelAreaVisual( 0.f, 0.f, 2.f, 2.f );
383   gifView.SetProperty( ImageView::Property::IMAGE,
384                        Property::Map().Add( ImageVisual::Property::URL, TEST_GIF_FILE_NAME )
385                                       .Add( ImageVisual::Property::PIXEL_AREA, pixelAreaVisual ) );
386
387   // Add to stage
388   Stage stage = Stage::GetCurrent();
389   stage.Add( gifView );
390
391   // loading started
392   application.SendNotification();
393   application.Render(16);
394   DALI_TEST_CHECK( gifView.GetRendererCount() == 1u );
395
396   const Vector4 fullTextureRect( 0.f, 0.f, 1.f, 1.f );
397   // test that the pixel area value defined in the visual property map is registered on renderer
398   Renderer renderer = gifView.GetRendererAt(0);
399   Property::Value pixelAreaValue = renderer.GetProperty( renderer.GetPropertyIndex( "pixelArea" ) );
400   DALI_TEST_EQUALS( pixelAreaValue.Get<Vector4>(), pixelAreaVisual, TEST_LOCATION );
401
402   // test that the shader has the default pixel area value registered.
403   Shader shader = renderer.GetShader();
404   pixelAreaValue = shader.GetProperty( shader.GetPropertyIndex( "pixelArea" ) );
405   DALI_TEST_EQUALS( pixelAreaValue.Get<Vector4>(), fullTextureRect, TEST_LOCATION );
406
407   // test that the uniform uses the pixelArea property on the renderer.
408   TestGlAbstraction& gl = application.GetGlAbstraction();
409   Vector4 pixelAreaUniform;
410   DALI_TEST_CHECK( gl.GetUniformValue<Vector4>( "pixelArea", pixelAreaUniform ) );
411   DALI_TEST_EQUALS( pixelAreaVisual, pixelAreaUniform, Math::MACHINE_EPSILON_100, TEST_LOCATION );
412
413   // set the pixelArea property on the control
414   const Vector4 pixelAreaControl( -1.f, -1.f, 3.f, 3.f );
415   gifView.SetProperty( ImageView::Property::PIXEL_AREA, pixelAreaControl );
416   application.SendNotification();
417   application.Render(16);
418
419   // check the pixelArea property on the control
420   pixelAreaValue = gifView.GetProperty( gifView.GetPropertyIndex( "pixelArea" ) );
421   DALI_TEST_EQUALS( pixelAreaValue.Get<Vector4>(), pixelAreaControl, TEST_LOCATION );
422   // test that the uniform uses the pixelArea property on the control.
423   DALI_TEST_CHECK( gl.GetUniformValue<Vector4>( "pixelArea", pixelAreaUniform ) );
424   DALI_TEST_EQUALS( pixelAreaControl, pixelAreaUniform, Math::MACHINE_EPSILON_100, TEST_LOCATION );
425
426
427   END_TEST;
428 }
429
430 int UtcDaliImageViewAsyncLoadingWithoutAltasing(void)
431 {
432   ToolkitTestApplication application;
433   TestGlAbstraction& gl = application.GetGlAbstraction();
434   const std::vector<GLuint>& textures = gl.GetBoundTextures();
435   size_t numTextures = textures.size();
436
437   // Async loading, no atlasing for big size image
438   ImageView imageView = ImageView::New( gImage_600_RGB );
439
440   // By default, Aysnc loading is used
441   Stage::GetCurrent().Add( imageView );
442   imageView.SetSize(100, 100);
443   imageView.SetParentOrigin( ParentOrigin::CENTER );
444
445   DALI_TEST_EQUALS( Test::WaitForEventThreadTrigger( 1 ), true, TEST_LOCATION );
446
447   application.SendNotification();
448   application.Render(16);
449   application.SendNotification();
450
451   const std::vector<GLuint>& textures2 = gl.GetBoundTextures();
452   DALI_TEST_GREATER( textures2.size(), numTextures, TEST_LOCATION );
453
454
455
456   END_TEST;
457 }
458
459 int UtcDaliImageViewAsyncLoadingWithAtlasing(void)
460 {
461   ToolkitTestApplication application;
462
463   //Async loading, automatic atlasing for small size image
464   TraceCallStack& callStack = application.GetGlAbstraction().GetTextureTrace();
465   callStack.Reset();
466   callStack.Enable(true);
467
468   Property::Map imageMap;
469
470   imageMap[ ImageVisual::Property::URL ] = gImage_34_RGBA;
471   imageMap[ ImageVisual::Property::DESIRED_HEIGHT ] = 34;
472   imageMap[ ImageVisual::Property::DESIRED_WIDTH ] = 34;
473   imageMap[ DevelImageVisual::Property::ATLASING] = true;
474
475   ImageView imageView = ImageView::New();
476   imageView.SetProperty( ImageView::Property::IMAGE, imageMap );
477
478   // By default, Aysnc loading is used
479   // loading is not started if the actor is offStage
480
481   Stage::GetCurrent().Add( imageView );
482   application.SendNotification();
483   application.Render(16);
484   application.Render(16);
485   application.SendNotification();
486
487   // loading started, this waits for the loader thread for max 30 seconds
488   DALI_TEST_EQUALS( Test::WaitForEventThreadTrigger( 1 ), true, TEST_LOCATION );
489
490   application.SendNotification();
491   application.Render(16);
492
493   callStack.Enable(false);
494
495   TraceCallStack::NamedParams params;
496   params["width"] = ToString(34);
497   params["height"] = ToString(34);
498   DALI_TEST_EQUALS( callStack.FindMethodAndParams( "TexSubImage2D", params ), true, TEST_LOCATION );
499
500   END_TEST;
501 }
502
503 int UtcDaliImageViewAsyncLoadingWithAtlasing02(void)
504 {
505   ToolkitTestApplication application;
506
507   //Async loading, automatic atlasing for small size image
508   TraceCallStack& callStack = application.GetGlAbstraction().GetTextureTrace();
509   callStack.Reset();
510   callStack.Enable(true);
511
512   Property::Map asyncLoadingMap;
513   asyncLoadingMap[ "url" ] = gImage_34_RGBA;
514   asyncLoadingMap[ "desiredHeight" ] = 34;
515   asyncLoadingMap[ "desiredWidth" ] = 34;
516   asyncLoadingMap[ "synchronousLoading" ] = false;
517   asyncLoadingMap[ "atlasing" ] = true;
518
519   ImageView imageView = ImageView::New();
520   imageView.SetProperty( ImageView::Property::IMAGE, asyncLoadingMap );
521
522   Stage::GetCurrent().Add( imageView );
523   application.SendNotification();
524   application.Render(16);
525   application.Render(16);
526   application.SendNotification();
527
528   // loading started, this waits for the loader thread for max 30 seconds
529   DALI_TEST_EQUALS( Test::WaitForEventThreadTrigger( 1 ), true, TEST_LOCATION );
530
531   application.SendNotification();
532   application.Render(16);
533
534   callStack.Enable(false);
535
536   TraceCallStack::NamedParams params;
537   params["width"] = ToString(34);
538   params["height"] = ToString(34);
539   DALI_TEST_EQUALS( callStack.FindMethodAndParams( "TexSubImage2D", params ), true, TEST_LOCATION );
540
541   END_TEST;
542 }
543
544 int UtcDaliImageViewSyncLoading(void)
545 {
546   ToolkitTestApplication application;
547
548   tet_infoline("ImageView Testing sync loading and size using index key property map");
549
550   Property::Map syncLoadingMap;
551   syncLoadingMap[ ImageVisual::Property::SYNCHRONOUS_LOADING ] = true;
552   syncLoadingMap[ DevelImageVisual::Property::ATLASING ] = true;
553
554   // Sync loading, no atlasing for big size image
555   {
556     ImageView imageView = ImageView::New();
557
558     // Sync loading is used
559     syncLoadingMap[ ImageVisual::Property::URL ] = gImage_600_RGB;
560     imageView.SetProperty( ImageView::Property::IMAGE, syncLoadingMap );
561   }
562
563   // Sync loading, automatic atlasing for small size image
564   {
565     TraceCallStack& callStack = application.GetGlAbstraction().GetTextureTrace();
566     callStack.Reset();
567     callStack.Enable(true);
568
569     ImageView imageView = ImageView::New( );
570
571     // Sync loading is used
572     syncLoadingMap[ ImageVisual::Property::URL ] = gImage_34_RGBA;
573     syncLoadingMap[ ImageVisual::Property::DESIRED_HEIGHT ] = 34;
574     syncLoadingMap[ ImageVisual::Property::DESIRED_WIDTH ] = 34;
575     imageView.SetProperty( ImageView::Property::IMAGE, syncLoadingMap );
576
577     Stage::GetCurrent().Add( imageView );
578     application.SendNotification();
579     application.Render(16);
580
581     TraceCallStack::NamedParams params;
582     params["width"] = ToString(34);
583     params["height"] = ToString(34);
584     DALI_TEST_EQUALS( callStack.FindMethodAndParams( "TexSubImage2D", params ),
585                       true, TEST_LOCATION );
586   }
587   END_TEST;
588 }
589
590
591 int UtcDaliImageViewSyncLoading02(void)
592 {
593   ToolkitTestApplication application;
594
595   tet_infoline("ImageView Testing sync loading and size using string key property map");
596
597   // Sync loading, automatic atlasing for small size image
598   {
599     TraceCallStack& callStack = application.GetGlAbstraction().GetTextureTrace();
600     callStack.Reset();
601     callStack.Enable(true);
602
603     ImageView imageView = ImageView::New( );
604
605     // Sync loading is used
606     Property::Map syncLoadingMap;
607     syncLoadingMap[ "url" ] = gImage_34_RGBA;
608     syncLoadingMap[ "desiredHeight" ] = 34;
609     syncLoadingMap[ "desiredWidth" ] = 34;
610     syncLoadingMap[ "synchronousLoading" ] = true;
611     syncLoadingMap[ "atlasing" ] = true;
612     imageView.SetProperty( ImageView::Property::IMAGE, syncLoadingMap );
613
614     Stage::GetCurrent().Add( imageView );
615     application.SendNotification();
616     application.Render(16);
617
618     TraceCallStack::NamedParams params;
619     params["width"] = ToString(34);
620     params["height"] = ToString(34);
621     DALI_TEST_EQUALS( callStack.FindMethodAndParams( "TexSubImage2D", params ),
622                       true, TEST_LOCATION );
623   }
624   END_TEST;
625 }
626
627 int UtcDaliImageViewSizeWithBackground(void)
628 {
629   ToolkitTestApplication application;
630
631   int width = 100;
632   int height = 200;
633   Image image = CreateBufferImage( width, height, Vector4(1.f, 1.f, 1.f, 1.f) );
634   ImageView imageView = ImageView::New();
635   imageView.SetBackgroundImage( image );
636
637   Stage::GetCurrent().Add( imageView );
638   application.SendNotification();
639   application.Render();
640
641   DALI_TEST_EQUALS( imageView.GetCurrentSize().width, (float)width, TEST_LOCATION );
642   DALI_TEST_EQUALS( imageView.GetCurrentSize().height, (float)height, TEST_LOCATION );
643
644   END_TEST;
645 }
646
647 int UtcDaliImageViewSizeWithBackgroundAndImage(void)
648 {
649   ToolkitTestApplication application;
650
651   int widthBackground = 100;
652   int heightBackground = 200;
653   int width = 300;
654   int height = 400;
655   Image imageBackground = CreateBufferImage( widthBackground, heightBackground, Vector4(1.f, 1.f, 1.f, 1.f) );
656   Image image = CreateBufferImage( width, height, Vector4(1.f, 1.f, 1.f, 1.f) );
657
658   ImageView imageView = ImageView::New();
659   imageView.SetBackgroundImage( imageBackground );
660   imageView.SetImage( image );
661
662   Stage::GetCurrent().Add( imageView );
663   application.SendNotification();
664   application.Render();
665
666   DALI_TEST_EQUALS( imageView.GetCurrentSize().width, (float)width, TEST_LOCATION );
667   DALI_TEST_EQUALS( imageView.GetCurrentSize().height, (float)height, TEST_LOCATION );
668
669   END_TEST;
670 }
671
672 int UtcDaliImageViewHeightForWidthBackground(void)
673 {
674   ToolkitTestApplication application;
675
676   int widthBackground = 100;
677   int heightBackground = 200;
678   Image imageBackground = CreateBufferImage( widthBackground, heightBackground, Vector4(1.f, 1.f, 1.f, 1.f) );
679
680   ImageView imageView = ImageView::New();
681   imageView.SetBackgroundImage( imageBackground );
682
683   Stage::GetCurrent().Add( imageView );
684   application.SendNotification();
685   application.Render();
686
687   Control control = Control::DownCast( imageView );
688   DALI_TEST_CHECK( control );
689   DALI_TEST_EQUALS( imageView.GetHeightForWidth( 123.f ), control.GetHeightForWidth( 123.f ), TEST_LOCATION );
690   DALI_TEST_EQUALS( imageView.GetWidthForHeight( 321.f ), control.GetWidthForHeight( 321.f ), TEST_LOCATION );
691
692   END_TEST;
693 }
694
695 int UtcDaliImageViewHeightForWidthBackgroundAndImage(void)
696 {
697   ToolkitTestApplication application;
698
699   int widthBackground = 100;
700   int heightBackground = 200;
701   int width = 300;
702   int height = 400;
703   Image imageBackground = CreateBufferImage( widthBackground, heightBackground, Vector4(1.f, 1.f, 1.f, 1.f) );
704   Image image = CreateBufferImage( width, height, Vector4(1.f, 1.f, 1.f, 1.f) );
705
706   ImageView imageView = ImageView::New();
707   imageView.SetBackgroundImage( imageBackground );
708   imageView.SetImage( image );
709
710   Stage::GetCurrent().Add( imageView );
711   application.SendNotification();
712   application.Render();
713
714   DALI_TEST_EQUALS( imageView.GetHeightForWidth( width ), (float)height, TEST_LOCATION );
715   DALI_TEST_EQUALS( imageView.GetWidthForHeight( height ), (float)width, TEST_LOCATION );
716
717   END_TEST;
718 }
719
720 int UtcDaliImageViewSetBufferImage(void)
721 {
722   ToolkitTestApplication application;
723
724   int width1 = 300;
725   int height1 = 400;
726   BufferImage image1 = CreateBufferImage( width1, height1, Vector4( 1.f, 1.f, 1.f, 1.f ) );
727   ImageView imageView = ImageView::New();
728   imageView.SetImage( image1 );
729
730   TestImage( imageView, image1 );
731
732   int width2 = 600;
733   int height2 = 500;
734   BufferImage image2 = CreateBufferImage( width2, height2, Vector4( 1.f, 1.f, 1.f, 1.f ) );
735   imageView.SetImage( image2 );
736
737   TestImage( imageView, image2 );
738
739   END_TEST;
740 }
741
742 int UtcDaliImageViewSetImageUrl(void)
743 {
744   ToolkitTestApplication application;
745
746   ImageView imageView = ImageView::New();
747   imageView.SetImage( TEST_IMAGE_FILE_NAME );
748   TestUrl( imageView, TEST_IMAGE_FILE_NAME );
749
750
751   imageView.SetImage( TEST_IMAGE_FILE_NAME2 );
752   TestUrl( imageView, TEST_IMAGE_FILE_NAME2 );
753
754   END_TEST;
755 }
756
757 int UtcDaliImageViewSetImageOnstageP(void)
758 {
759   ToolkitTestApplication application;
760
761   ImageView imageView = ImageView::New();
762
763   Stage::GetCurrent().Add( imageView );
764   application.SendNotification();
765   application.Render();
766
767   ResourceImage image1 = ResourceImage::New( TEST_IMAGE_FILE_NAME );
768   imageView.SetImage( image1 );
769   TestImage( imageView, image1 );
770
771   int width = 300;
772   int height = 400;
773   BufferImage image2 = CreateBufferImage( width, height, Vector4( 1.f, 1.f, 1.f, 1.f ) );
774   imageView.SetImage( image2 );
775   TestImage( imageView, image2 );
776
777   END_TEST;
778 }
779
780 int UtcDaliImageViewSetImageOnstageN(void)
781 {
782   ToolkitTestApplication application;
783
784   ImageView imageView = ImageView::New();
785
786   Stage::GetCurrent().Add( imageView );
787   application.SendNotification();
788   application.Render();
789
790   ResourceImage image1 = ResourceImage::New( TEST_IMAGE_FILE_NAME );
791   imageView.SetImage( image1 );
792   TestImage( imageView, image1 );
793
794   Image image2;
795   imageView.SetImage( image2 );
796
797   Property::Value value = imageView.GetProperty( imageView.GetPropertyIndex( "image" ) );
798
799   //the value should be empty
800   std::string url;
801   DALI_TEST_CHECK( !value.Get( url ) );
802
803   Property::Map map;
804   DALI_TEST_CHECK( !value.Get( map ) );
805
806   END_TEST;
807 }
808
809 int UtcDaliImageViewSetImageOffstageP(void)
810 {
811   ToolkitTestApplication application;
812
813   ImageView imageView = ImageView::New();
814
815   Stage::GetCurrent().Add( imageView );
816   application.SendNotification();
817   application.Render();
818   Stage::GetCurrent().Remove( imageView );
819
820   ResourceImage image1 = ResourceImage::New( TEST_IMAGE_FILE_NAME );
821   imageView.SetImage( image1 );
822   TestImage( imageView, image1 );
823
824   int width = 300;
825   int height = 400;
826   BufferImage image2 = CreateBufferImage( width, height, Vector4( 1.f, 1.f, 1.f, 1.f ) );
827   imageView.SetImage( image2 );
828   TestImage( imageView, image2 );
829
830   END_TEST;
831 }
832
833 bool gResourceReadySignalFired = false;
834
835 void ResourceReadySignal( Control control )
836 {
837   gResourceReadySignalFired = true;
838 }
839
840 int UtcDaliImageViewCheckResourceReady(void)
841 {
842   ToolkitTestApplication application;
843
844   gResourceReadySignalFired = false;
845
846
847   int width = 100;
848   int height = 200;
849   Image image = CreateBufferImage( width, height, Vector4(1.f, 1.f, 1.f, 1.f) );
850
851   // Check ImageView with background and main image, to ensure both visuals are marked as loaded
852   ImageView imageView = ImageView::New( TEST_GIF_FILE_NAME );
853
854   imageView.SetBackgroundImage( image );
855
856   DALI_TEST_EQUALS( Toolkit::DevelControl::IsResourceReady( imageView ), false, TEST_LOCATION );
857
858   Toolkit::DevelControl::ResourceReadySignal( imageView ).Connect( &ResourceReadySignal);
859
860   Stage::GetCurrent().Add( imageView );
861
862   application.SendNotification();
863   application.Render(16);
864
865
866   DALI_TEST_EQUALS( Toolkit::DevelControl::IsResourceReady( imageView ), true, TEST_LOCATION );
867
868   DALI_TEST_EQUALS( gResourceReadySignalFired, true, TEST_LOCATION );
869
870   END_TEST;
871 }
872
873 int UtcDaliImageViewSetImageOffstageN(void)
874 {
875   ToolkitTestApplication application;
876
877   ImageView imageView = ImageView::New();
878
879   Stage::GetCurrent().Add( imageView );
880   application.SendNotification();
881   application.Render();
882   Stage::GetCurrent().Remove( imageView );
883
884   ResourceImage image1 = ResourceImage::New( TEST_IMAGE_FILE_NAME );
885   imageView.SetImage( image1 );
886   TestImage( imageView, image1 );
887
888   Image image2;
889   imageView.SetImage( image2 );
890
891   Property::Value value = imageView.GetProperty( imageView.GetPropertyIndex( "image" ) );
892
893   //the value should be empty
894   std::string url;
895   DALI_TEST_CHECK( !value.Get( url ) );
896
897   Property::Map map;
898   DALI_TEST_CHECK( !value.Get( map ) );
899
900   END_TEST;
901 }
902
903 int UtcDaliImageViewSetImageN(void)
904 {
905   ToolkitTestApplication application;
906
907   Image image1;
908   ImageView imageView = ImageView::New();
909   imageView.SetImage( image1 );
910
911   Property::Value value = imageView.GetProperty( imageView.GetPropertyIndex( "image" ) );
912
913   //the value should be empty
914   std::string url;
915   DALI_TEST_CHECK( !value.Get( url ) );
916
917   Property::Map map;
918   DALI_TEST_CHECK( !value.Get( map ) );
919
920   std::string resource_url;
921   Property::Value val = imageView.GetProperty( imageView.GetPropertyIndex( "image" ) );
922   DALI_TEST_CHECK( !val.Get( resource_url ) );
923
924   END_TEST;
925 }
926
927 int UtcDaliImageViewSetImageTypeChangesP(void)
928 {
929   ToolkitTestApplication application;
930
931   ImageView imageView = ImageView::New();
932
933
934   std::string url;
935   Property::Map map;
936
937   Property::Value value = imageView.GetProperty( imageView.GetPropertyIndex( "image" ) );
938   DALI_TEST_CHECK( ! value.Get( url ) ); // Value should be empty
939   DALI_TEST_CHECK( ! value.Get( map ) ); // Value should be empty
940
941   // Set a URL
942   imageView.SetImage( "TEST_URL" );
943   value = imageView.GetProperty( imageView.GetPropertyIndex( "image" ) );
944
945   DALI_TEST_CHECK( value.Get( url ) );   // Value should NOT be empty
946   DALI_TEST_CHECK( ! value.Get( map ) ); // Value should be empty
947
948   // Set an empty Image
949   imageView.SetImage( Image() );
950   value = imageView.GetProperty( imageView.GetPropertyIndex( "image" ) );
951
952   DALI_TEST_CHECK( ! value.Get( url ) ); // Value should be empty
953   DALI_TEST_CHECK( ! value.Get( map ) ); // Value should be empty
954
955   // Set an Image
956   ResourceImage image1 = ResourceImage::New( TEST_IMAGE_FILE_NAME );
957   imageView.SetImage( image1 );
958   value = imageView.GetProperty( imageView.GetPropertyIndex( "image" ) );
959
960   DALI_TEST_CHECK( ! value.Get( url ) ); // Value should be empty
961   DALI_TEST_CHECK( value.Get( map ) );   // Value should NOT be empty
962
963   // Set an empty URL
964   imageView.SetImage( "" );
965   value = imageView.GetProperty( imageView.GetPropertyIndex( "image" ) );
966
967   DALI_TEST_CHECK( ! value.Get( url ) ); // Value should be empty
968   DALI_TEST_CHECK( ! value.Get( map ) ); // Value should be empty
969
970   END_TEST;
971 }
972
973 int UtcDaliImageViewResourceUrlP(void)
974 {
975   ToolkitTestApplication application;
976
977   ImageView imageView = ImageView::New();
978   DALI_TEST_CHECK( imageView.GetProperty( ImageView::Property::RESOURCE_URL ).Get< std::string >().empty() );
979
980   imageView.SetProperty( ImageView::Property::RESOURCE_URL, "TestString" );
981   DALI_TEST_EQUALS( imageView.GetProperty( ImageView::Property::RESOURCE_URL ).Get< std::string >(), "TestString", TEST_LOCATION );
982
983   END_TEST;
984 }
985
986 // Scenarios 1: ImageView from regular image
987 int UtcDaliImageViewSetImageBufferImage(void)
988 {
989   ToolkitTestApplication application;
990
991   ImageView imageView = ImageView::New();
992   Stage::GetCurrent().Add( imageView );
993
994   TestGlAbstraction& gl = application.GetGlAbstraction();
995   gl.EnableTextureCallTrace( true );
996
997   std::vector< GLuint > ids;
998   ids.push_back( 23 );
999   application.GetGlAbstraction().SetNextTextureIds( ids );
1000
1001   int width = 300;
1002   int height = 400;
1003   BufferImage image = CreateBufferImage( width, height, Color::WHITE );
1004
1005   imageView.SetImage( image );
1006
1007   application.SendNotification();
1008   application.Render();
1009
1010   DALI_TEST_CHECK( gl.GetTextureTrace().FindMethod("BindTexture") );
1011
1012   std::stringstream params;
1013   params << GL_TEXTURE_2D << ", " << 23;
1014   DALI_TEST_CHECK( gl.GetTextureTrace().FindMethodAndParams("BindTexture", params.str()) );
1015
1016   END_TEST;
1017 }
1018
1019 // Scenarios 2: ImageView from Native image
1020 int UtcDaliImageViewSetImageNativeImage(void)
1021 {
1022   ToolkitTestApplication application;
1023
1024   ImageView imageView = ImageView::New();
1025   Stage::GetCurrent().Add( imageView );
1026
1027   TestGlAbstraction& gl = application.GetGlAbstraction();
1028   gl.EnableTextureCallTrace( true );
1029
1030   std::vector< GLuint > ids;
1031   ids.push_back( 23 );
1032   application.GetGlAbstraction().SetNextTextureIds( ids );
1033
1034   int width = 200;
1035   int height = 500;
1036   TestNativeImagePointer nativeImageInterface = TestNativeImage::New( width, height );
1037   NativeImage nativeImage = NativeImage::New( *(nativeImageInterface.Get()) );
1038
1039   imageView.SetImage( nativeImage );
1040   application.SendNotification();
1041   application.Render();
1042
1043   DALI_TEST_CHECK( gl.GetTextureTrace().FindMethod("BindTexture") );
1044
1045   std::stringstream params;
1046   params << GL_TEXTURE_EXTERNAL_OES << ", " << 23;
1047   DALI_TEST_CHECK( gl.GetTextureTrace().FindMethodAndParams("BindTexture", params.str()) );
1048
1049   END_TEST;
1050 }
1051
1052 // Scenarios 3: ImageView initially from regular image but then SetImage called with Native image
1053 int UtcDaliImageViewSetImageBufferImageToNativeImage(void)
1054 {
1055   ToolkitTestApplication application;
1056
1057   int width = 300;
1058   int height = 400;
1059   BufferImage image = CreateBufferImage( width, height, Color::WHITE );
1060
1061   ImageView imageView = ImageView::New( image );
1062   Stage::GetCurrent().Add( imageView );
1063
1064   TestGlAbstraction& gl = application.GetGlAbstraction();
1065   gl.EnableTextureCallTrace( true );
1066
1067   std::vector< GLuint > ids;
1068   ids.push_back( 23 );
1069   application.GetGlAbstraction().SetNextTextureIds( ids );
1070
1071   application.SendNotification();
1072   application.Render();
1073
1074   DALI_TEST_CHECK( gl.GetTextureTrace().FindMethod("BindTexture") );
1075
1076   std::stringstream params;
1077   params << GL_TEXTURE_2D << ", " << 23;
1078   DALI_TEST_CHECK( gl.GetTextureTrace().FindMethodAndParams("BindTexture", params.str()) );
1079
1080   width = 200;
1081   height = 500;
1082   TestNativeImagePointer nativeImageInterface = TestNativeImage::New( width, height );
1083   NativeImage nativeImage = NativeImage::New( *(nativeImageInterface.Get()) );
1084   imageView.SetImage( nativeImage );
1085
1086   ids.clear();
1087   ids.push_back( 24 );
1088   application.GetGlAbstraction().SetNextTextureIds( ids );
1089
1090   application.SendNotification();
1091   application.Render();
1092
1093   DALI_TEST_CHECK( gl.GetTextureTrace().FindMethod("BindTexture") );
1094
1095   std::stringstream nextTextureParams;
1096   nextTextureParams << GL_TEXTURE_EXTERNAL_OES << ", " << 24;
1097   DALI_TEST_CHECK( gl.GetTextureTrace().FindMethodAndParams("BindTexture", nextTextureParams.str()) );
1098
1099   END_TEST;
1100 }
1101
1102 // Scenarios 4: ImageView initially from Native image but then SetImage called with regular image
1103 int UtcDaliImageViewSetImageNativeImageToBufferImage(void)
1104 {
1105   ToolkitTestApplication application;
1106
1107   int width = 300;
1108   int height = 400;
1109   TestNativeImagePointer nativeImageInterface = TestNativeImage::New( width, height );
1110   NativeImage nativeImage = NativeImage::New( *(nativeImageInterface.Get()) );
1111
1112   ImageView imageView = ImageView::New( nativeImage );
1113   Stage::GetCurrent().Add( imageView );
1114
1115   TestGlAbstraction& gl = application.GetGlAbstraction();
1116   gl.EnableTextureCallTrace( true );
1117
1118   std::vector< GLuint > ids;
1119   ids.push_back( 23 );
1120   application.GetGlAbstraction().SetNextTextureIds( ids );
1121
1122   application.SendNotification();
1123   application.Render();
1124
1125   DALI_TEST_CHECK( gl.GetTextureTrace().FindMethod("BindTexture") );
1126
1127   std::stringstream params;
1128   params << GL_TEXTURE_EXTERNAL_OES << ", " << 23;
1129   DALI_TEST_CHECK( gl.GetTextureTrace().FindMethodAndParams("BindTexture", params.str()) );
1130
1131   width = 200;
1132   height = 500;
1133   BufferImage image = CreateBufferImage( width, height, Color::WHITE );
1134   imageView.SetImage( image );
1135
1136   ids.clear();
1137   ids.push_back( 24 );
1138   application.GetGlAbstraction().SetNextTextureIds( ids );
1139
1140   application.SendNotification();
1141   application.Render();
1142
1143   DALI_TEST_CHECK( gl.GetTextureTrace().FindMethod("BindTexture") );
1144
1145   std::stringstream nextTextureParams;
1146   nextTextureParams << GL_TEXTURE_2D << ", " << 24;
1147   DALI_TEST_CHECK( gl.GetTextureTrace().FindMethodAndParams("BindTexture", nextTextureParams.str()) );
1148
1149   END_TEST;
1150 }
1151
1152 // Scenarios 5: ImageView from Native image with custom shader
1153 int UtcDaliImageViewSetImageNativeImageWithCustomShader(void)
1154 {
1155   ToolkitTestApplication application;
1156
1157   int width = 300;
1158   int height = 400;
1159
1160   Property::Map customShader;
1161   customShader.Insert( "vertexShader", VERTEX_SHADER );
1162   customShader.Insert( "fragmentShader", FRAGMENT_SHADER );
1163
1164   Property::Array shaderHints;
1165   shaderHints.PushBack( "requiresSelfDepthTest" );
1166   shaderHints.PushBack( "outputIsTransparent" );
1167   shaderHints.PushBack( "outputIsOpaque" );
1168   shaderHints.PushBack( "modifiesGeometry" );
1169
1170   customShader.Insert( "hints", shaderHints );
1171
1172   Property::Map map;
1173   map.Insert( "shader", customShader );
1174
1175   TestNativeImagePointer nativeImageInterface = TestNativeImage::New( width, height );
1176   NativeImage nativeImage = NativeImage::New( *(nativeImageInterface.Get()) );
1177
1178   ImageView imageView = ImageView::New( nativeImage );
1179   imageView.SetProperty( ImageView::Property::IMAGE, map );
1180   Stage::GetCurrent().Add( imageView );
1181
1182   TestGlAbstraction& gl = application.GetGlAbstraction();
1183   gl.EnableTextureCallTrace( true );
1184
1185   std::vector< GLuint > ids;
1186   ids.push_back( 23 );
1187   application.GetGlAbstraction().SetNextTextureIds( ids );
1188
1189   application.SendNotification();
1190   application.Render();
1191
1192   DALI_TEST_CHECK( gl.GetTextureTrace().FindMethod("BindTexture") );
1193
1194   std::stringstream params;
1195   params << GL_TEXTURE_EXTERNAL_OES << ", " << 23;
1196   DALI_TEST_CHECK( gl.GetTextureTrace().FindMethodAndParams("BindTexture", params.str()) );
1197
1198   END_TEST;
1199 }
1200
1201 // Scenarios 6: ImageView initially from regular image with custom shader but then SetImage called with Native
1202 int UtcDaliImageViewSetImageBufferImageWithCustomShaderToNativeImage(void)
1203 {
1204   ToolkitTestApplication application;
1205
1206   int width = 300;
1207   int height = 400;
1208
1209   Property::Map customShader;
1210   customShader.Insert( "vertexShader", VERTEX_SHADER );
1211   customShader.Insert( "fragmentShader", FRAGMENT_SHADER );
1212
1213   Property::Array shaderHints;
1214   shaderHints.PushBack( "requiresSelfDepthTest" );
1215   shaderHints.PushBack( "outputIsTransparent" );
1216   shaderHints.PushBack( "outputIsOpaque" );
1217   shaderHints.PushBack( "modifiesGeometry" );
1218
1219   customShader.Insert( "hints", shaderHints );
1220
1221   Property::Map map;
1222   map.Insert( "shader", customShader );
1223
1224   BufferImage image = CreateBufferImage( width, height, Color::WHITE );
1225
1226   ImageView imageView = ImageView::New( image );
1227   imageView.SetProperty( ImageView::Property::IMAGE, map );
1228   Stage::GetCurrent().Add( imageView );
1229
1230   TestGlAbstraction& gl = application.GetGlAbstraction();
1231   gl.EnableTextureCallTrace( true );
1232
1233   std::vector< GLuint > ids;
1234   ids.push_back( 23 );
1235   application.GetGlAbstraction().SetNextTextureIds( ids );
1236
1237   application.SendNotification();
1238   application.Render();
1239
1240   DALI_TEST_CHECK( gl.GetTextureTrace().FindMethod("BindTexture") );
1241
1242   std::stringstream params;
1243   params << GL_TEXTURE_2D << ", " << 23;
1244   DALI_TEST_CHECK( gl.GetTextureTrace().FindMethodAndParams("BindTexture", params.str()) );
1245
1246   TestNativeImagePointer nativeImageInterface = TestNativeImage::New( width, height );
1247   NativeImage nativeImage = NativeImage::New( *(nativeImageInterface.Get()) );
1248   imageView.SetImage( nativeImage );
1249
1250   ids.clear();
1251   ids.push_back( 24 );
1252   application.GetGlAbstraction().SetNextTextureIds( ids );
1253
1254   application.SendNotification();
1255   application.Render();
1256
1257   DALI_TEST_CHECK( gl.GetTextureTrace().FindMethod("BindTexture") );
1258
1259   std::stringstream nativeImageParams;
1260   nativeImageParams << GL_TEXTURE_EXTERNAL_OES << ", " << 24;
1261   DALI_TEST_CHECK( gl.GetTextureTrace().FindMethodAndParams("BindTexture", nativeImageParams.str()) );
1262
1263
1264   END_TEST;
1265 }
1266
1267 int UtcDaliImageViewGetImageP1(void)
1268 {
1269   ToolkitTestApplication application;
1270
1271   ImageView imageView = ImageView::New();
1272   DALI_TEST_CHECK( ! imageView.GetImage() );
1273
1274   Image image = CreateBufferImage();
1275   imageView.SetImage( image );
1276   DALI_TEST_CHECK( imageView.GetImage() == image );
1277
1278   END_TEST;
1279 }
1280
1281 int UtcDaliImageViewGetImageP2(void)
1282 {
1283   ToolkitTestApplication application;
1284
1285   BufferImage image = CreateBufferImage();
1286   ImageView imageView = ImageView::New( image );
1287   DALI_TEST_CHECK( imageView.GetImage() == image );
1288
1289   END_TEST;
1290 }
1291
1292 int UtcDaliImageViewGetImageN(void)
1293 {
1294   ToolkitTestApplication application;
1295
1296   ImageView imageView = ImageView::New( TEST_IMAGE_FILE_NAME );
1297   DALI_TEST_CHECK( ! imageView.GetImage() );
1298
1299   Image image = CreateBufferImage();
1300   imageView.SetImage( image );
1301   DALI_TEST_CHECK( imageView.GetImage() == image );
1302
1303   imageView.SetImage( TEST_IMAGE_FILE_NAME );
1304   DALI_TEST_CHECK( ! imageView.GetImage() );
1305
1306   END_TEST;
1307 }
1308
1309
1310 int UtcDaliImageViewReplaceImage(void)
1311 {
1312   ToolkitTestApplication application;
1313
1314   gResourceReadySignalFired = false;
1315
1316   int width = 100;
1317   int height = 200;
1318   Image image = CreateBufferImage( width, height, Vector4(1.f, 1.f, 1.f, 1.f) );
1319
1320   // Check ImageView with background and main image, to ensure both visuals are marked as loaded
1321   ImageView imageView = ImageView::New( TEST_IMAGE_1 );
1322
1323   DALI_TEST_EQUALS( Toolkit::DevelControl::IsResourceReady( imageView ), false, TEST_LOCATION );
1324
1325   Toolkit::DevelControl::ResourceReadySignal( imageView ).Connect( &ResourceReadySignal);
1326
1327   Stage::GetCurrent().Add( imageView );
1328
1329   application.SendNotification();
1330   application.Render(16);
1331
1332   // loading started, this waits for the loader thread for max 30 seconds
1333   DALI_TEST_EQUALS( Test::WaitForEventThreadTrigger( 1 ), true, TEST_LOCATION );
1334
1335   DALI_TEST_EQUALS( imageView.GetRendererCount(), 1u, TEST_LOCATION );
1336
1337   DALI_TEST_EQUALS( gResourceReadySignalFired, true, TEST_LOCATION );
1338
1339   gResourceReadySignalFired = false;
1340
1341   imageView.SetImage(TEST_IMAGE_2);
1342
1343   application.SendNotification();
1344   application.Render(16);
1345
1346   // loading started, this waits for the loader thread for max 30 seconds
1347   DALI_TEST_EQUALS( Test::WaitForEventThreadTrigger( 1 ), true, TEST_LOCATION );
1348
1349   DALI_TEST_EQUALS( imageView.GetRendererCount(), 1u, TEST_LOCATION );
1350
1351   DALI_TEST_EQUALS( Toolkit::DevelControl::IsResourceReady( imageView ), true, TEST_LOCATION );
1352
1353   DALI_TEST_EQUALS( gResourceReadySignalFired, true, TEST_LOCATION );
1354
1355   END_TEST;
1356 }