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