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