97a4b1d0afb004875ffeb5603cf6de4c25f9e4a1
[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   imageView.SetProperty( Dali::Actor::Property::LAYOUT_DIRECTION,  Dali::LayoutDirection::RIGHT_TO_LEFT );
493   application.SendNotification();
494   application.Render(16);
495   application.Render(16);
496   application.SendNotification();
497
498   // loading started, this waits for the loader thread for max 30 seconds
499   DALI_TEST_EQUALS( Test::WaitForEventThreadTrigger( 1 ), true, TEST_LOCATION );
500
501   application.SendNotification();
502   application.Render(16);
503
504   callStack.Enable(false);
505
506   TraceCallStack::NamedParams params;
507   params["width"] = ToString(34);
508   params["height"] = ToString(34);
509   DALI_TEST_EQUALS( callStack.FindMethodAndParams( "TexSubImage2D", params ), true, TEST_LOCATION );
510
511   END_TEST;
512 }
513
514 int UtcDaliImageViewAsyncLoadingWithAtlasing02(void)
515 {
516   ToolkitTestApplication application;
517
518   //Async loading, automatic atlasing for small size image
519   TraceCallStack& callStack = application.GetGlAbstraction().GetTextureTrace();
520   callStack.Reset();
521   callStack.Enable(true);
522
523   Property::Map asyncLoadingMap;
524   asyncLoadingMap[ "url" ] = gImage_34_RGBA;
525   asyncLoadingMap[ "desiredHeight" ] = 34;
526   asyncLoadingMap[ "desiredWidth" ] = 34;
527   asyncLoadingMap[ "synchronousLoading" ] = false;
528   asyncLoadingMap[ "atlasing" ] = true;
529
530   ImageView imageView = ImageView::New();
531   imageView.SetProperty( ImageView::Property::IMAGE, asyncLoadingMap );
532
533   Stage::GetCurrent().Add( imageView );
534   application.SendNotification();
535   application.Render(16);
536   application.Render(16);
537   application.SendNotification();
538
539   // loading started, this waits for the loader thread for max 30 seconds
540   DALI_TEST_EQUALS( Test::WaitForEventThreadTrigger( 1 ), true, TEST_LOCATION );
541
542   application.SendNotification();
543   application.Render(16);
544
545   callStack.Enable(false);
546
547   TraceCallStack::NamedParams params;
548   params["width"] = ToString(34);
549   params["height"] = ToString(34);
550   DALI_TEST_EQUALS( callStack.FindMethodAndParams( "TexSubImage2D", params ), true, TEST_LOCATION );
551
552   END_TEST;
553 }
554
555 int UtcDaliImageViewSyncLoading(void)
556 {
557   ToolkitTestApplication application;
558
559   tet_infoline("ImageView Testing sync loading and size using index key property map");
560
561   Property::Map syncLoadingMap;
562   syncLoadingMap[ ImageVisual::Property::SYNCHRONOUS_LOADING ] = true;
563   syncLoadingMap[ ImageVisual::Property::ATLASING ] = true;
564
565   // Sync loading, no atlasing for big size image
566   {
567     ImageView imageView = ImageView::New();
568
569     // Sync loading is used
570     syncLoadingMap[ ImageVisual::Property::URL ] = gImage_600_RGB;
571     imageView.SetProperty( ImageView::Property::IMAGE, syncLoadingMap );
572   }
573
574   // Sync loading, automatic atlasing for small size image
575   {
576     TraceCallStack& callStack = application.GetGlAbstraction().GetTextureTrace();
577     callStack.Reset();
578     callStack.Enable(true);
579
580     ImageView imageView = ImageView::New( );
581
582     // Sync loading is used
583     syncLoadingMap[ ImageVisual::Property::URL ] = gImage_34_RGBA;
584     syncLoadingMap[ ImageVisual::Property::DESIRED_HEIGHT ] = 34;
585     syncLoadingMap[ ImageVisual::Property::DESIRED_WIDTH ] = 34;
586     imageView.SetProperty( ImageView::Property::IMAGE, syncLoadingMap );
587
588     Stage::GetCurrent().Add( imageView );
589     application.SendNotification();
590     application.Render(16);
591
592     TraceCallStack::NamedParams params;
593     params["width"] = ToString(34);
594     params["height"] = ToString(34);
595     DALI_TEST_EQUALS( callStack.FindMethodAndParams( "TexSubImage2D", params ),
596                       true, TEST_LOCATION );
597   }
598   END_TEST;
599 }
600
601 int UtcDaliImageViewSyncLoading02(void)
602 {
603   ToolkitTestApplication application;
604
605   tet_infoline("ImageView Testing sync loading and size using string key property map");
606
607   // Sync loading, automatic atlasing for small size image
608   {
609     TraceCallStack& callStack = application.GetGlAbstraction().GetTextureTrace();
610     callStack.Reset();
611     callStack.Enable(true);
612
613     ImageView imageView = ImageView::New( );
614
615     // Sync loading is used
616     Property::Map syncLoadingMap;
617     syncLoadingMap[ "url" ] = gImage_34_RGBA;
618     syncLoadingMap[ "desiredHeight" ] = 34;
619     syncLoadingMap[ "desiredWidth" ] = 34;
620     syncLoadingMap[ "synchronousLoading" ] = true;
621     syncLoadingMap[ "atlasing" ] = true;
622     imageView.SetProperty( ImageView::Property::IMAGE, syncLoadingMap );
623
624     Stage::GetCurrent().Add( imageView );
625     application.SendNotification();
626     application.Render(16);
627
628     TraceCallStack::NamedParams params;
629     params["width"] = ToString(34);
630     params["height"] = ToString(34);
631     DALI_TEST_EQUALS( callStack.FindMethodAndParams( "TexSubImage2D", params ),
632                       true, TEST_LOCATION );
633   }
634   END_TEST;
635 }
636
637 int UtcDaliImageViewAddedTexture(void)
638 {
639   ToolkitTestApplication application;
640
641   tet_infoline("ImageView Testing image view with texture provided manager url");
642
643   ImageView imageView = ImageView::New();
644
645   // empty texture is ok, though pointless from app point of view
646   TextureSet  empty;
647   std::string url = TextureManager::AddTexture(empty);
648   DALI_TEST_CHECK(url.size() > 0u);
649
650   Property::Map propertyMap;
651   propertyMap[ImageVisual::Property::URL] = url;
652   imageView.SetProperty(ImageView::Property::IMAGE, propertyMap);
653
654   Stage::GetCurrent().Add( imageView );
655   application.SendNotification();
656   application.Render();
657
658   END_TEST;
659 }
660
661 int UtcDaliImageViewSizeWithBackground(void)
662 {
663   ToolkitTestApplication application;
664
665   int width = 100;
666   int height = 200;
667   Image image = CreateBufferImage( width, height, Vector4(1.f, 1.f, 1.f, 1.f) );
668   ImageView imageView = ImageView::New();
669   imageView.SetBackgroundImage( image );
670
671   Stage::GetCurrent().Add( imageView );
672   application.SendNotification();
673   application.Render();
674
675   DALI_TEST_EQUALS( imageView.GetCurrentSize().width, (float)width, TEST_LOCATION );
676   DALI_TEST_EQUALS( imageView.GetCurrentSize().height, (float)height, TEST_LOCATION );
677
678   END_TEST;
679 }
680
681 int UtcDaliImageViewSizeWithBackgroundAndImage(void)
682 {
683   ToolkitTestApplication application;
684
685   int widthBackground = 100;
686   int heightBackground = 200;
687   int width = 300;
688   int height = 400;
689   Image imageBackground = CreateBufferImage( widthBackground, heightBackground, Vector4(1.f, 1.f, 1.f, 1.f) );
690   Image image = CreateBufferImage( width, height, Vector4(1.f, 1.f, 1.f, 1.f) );
691
692   ImageView imageView = ImageView::New();
693   imageView.SetBackgroundImage( imageBackground );
694   imageView.SetImage( image );
695
696   Stage::GetCurrent().Add( imageView );
697   application.SendNotification();
698   application.Render();
699
700   DALI_TEST_EQUALS( imageView.GetCurrentSize().width, (float)width, TEST_LOCATION );
701   DALI_TEST_EQUALS( imageView.GetCurrentSize().height, (float)height, TEST_LOCATION );
702
703   END_TEST;
704 }
705
706 int UtcDaliImageViewHeightForWidthBackground(void)
707 {
708   ToolkitTestApplication application;
709
710   int widthBackground = 100;
711   int heightBackground = 200;
712   Image imageBackground = CreateBufferImage( widthBackground, heightBackground, Vector4(1.f, 1.f, 1.f, 1.f) );
713
714   ImageView imageView = ImageView::New();
715   imageView.SetBackgroundImage( imageBackground );
716
717   Stage::GetCurrent().Add( imageView );
718   application.SendNotification();
719   application.Render();
720
721   Control control = Control::DownCast( imageView );
722   DALI_TEST_CHECK( control );
723   DALI_TEST_EQUALS( imageView.GetHeightForWidth( 123.f ), control.GetHeightForWidth( 123.f ), TEST_LOCATION );
724   DALI_TEST_EQUALS( imageView.GetWidthForHeight( 321.f ), control.GetWidthForHeight( 321.f ), TEST_LOCATION );
725
726   END_TEST;
727 }
728
729 int UtcDaliImageViewHeightForWidthBackgroundAndImage(void)
730 {
731   ToolkitTestApplication application;
732
733   int widthBackground = 100;
734   int heightBackground = 200;
735   int width = 300;
736   int height = 400;
737   Image imageBackground = CreateBufferImage( widthBackground, heightBackground, Vector4(1.f, 1.f, 1.f, 1.f) );
738   Image image = CreateBufferImage( width, height, Vector4(1.f, 1.f, 1.f, 1.f) );
739
740   ImageView imageView = ImageView::New();
741   imageView.SetBackgroundImage( imageBackground );
742   imageView.SetImage( image );
743
744   Stage::GetCurrent().Add( imageView );
745   application.SendNotification();
746   application.Render();
747
748   DALI_TEST_EQUALS( imageView.GetHeightForWidth( width ), (float)height, TEST_LOCATION );
749   DALI_TEST_EQUALS( imageView.GetWidthForHeight( height ), (float)width, TEST_LOCATION );
750
751   END_TEST;
752 }
753
754 int UtcDaliImageViewSetBufferImage(void)
755 {
756   ToolkitTestApplication application;
757
758   int width1 = 300;
759   int height1 = 400;
760   BufferImage image1 = CreateBufferImage( width1, height1, Vector4( 1.f, 1.f, 1.f, 1.f ) );
761   ImageView imageView = ImageView::New();
762   imageView.SetImage( image1 );
763
764   TestImage( imageView, image1 );
765
766   int width2 = 600;
767   int height2 = 500;
768   BufferImage image2 = CreateBufferImage( width2, height2, Vector4( 1.f, 1.f, 1.f, 1.f ) );
769   imageView.SetImage( image2 );
770
771   TestImage( imageView, image2 );
772
773   END_TEST;
774 }
775
776 int UtcDaliImageViewSetImageUrl(void)
777 {
778   ToolkitTestApplication application;
779
780   ImageView imageView = ImageView::New();
781   imageView.SetImage( TEST_IMAGE_FILE_NAME );
782   TestUrl( imageView, TEST_IMAGE_FILE_NAME );
783
784
785   imageView.SetImage( TEST_IMAGE_FILE_NAME2 );
786   TestUrl( imageView, TEST_IMAGE_FILE_NAME2 );
787
788   END_TEST;
789 }
790
791 int UtcDaliImageViewSetImageOnstageP(void)
792 {
793   ToolkitTestApplication application;
794
795   ImageView imageView = ImageView::New();
796
797   Stage::GetCurrent().Add( imageView );
798   application.SendNotification();
799   application.Render();
800
801   ResourceImage image1 = ResourceImage::New( TEST_IMAGE_FILE_NAME );
802   imageView.SetImage( image1 );
803   TestImage( imageView, image1 );
804
805   int width = 300;
806   int height = 400;
807   BufferImage image2 = CreateBufferImage( width, height, Vector4( 1.f, 1.f, 1.f, 1.f ) );
808   imageView.SetImage( image2 );
809   TestImage( imageView, image2 );
810
811   END_TEST;
812 }
813
814 int UtcDaliImageViewSetImageOnstageN(void)
815 {
816   ToolkitTestApplication application;
817
818   ImageView imageView = ImageView::New();
819
820   Stage::GetCurrent().Add( imageView );
821   application.SendNotification();
822   application.Render();
823
824   ResourceImage image1 = ResourceImage::New( TEST_IMAGE_FILE_NAME );
825   imageView.SetImage( image1 );
826   TestImage( imageView, image1 );
827
828   Image image2;
829   imageView.SetImage( image2 );
830
831   Property::Value value = imageView.GetProperty( imageView.GetPropertyIndex( "image" ) );
832
833   //the value should be empty
834   std::string url;
835   DALI_TEST_CHECK( !value.Get( url ) );
836
837   Property::Map map;
838   DALI_TEST_CHECK( !value.Get( map ) );
839
840   END_TEST;
841 }
842
843 int UtcDaliImageViewSetImageOffstageP(void)
844 {
845   ToolkitTestApplication application;
846
847   ImageView imageView = ImageView::New();
848
849   Stage::GetCurrent().Add( imageView );
850   application.SendNotification();
851   application.Render();
852   Stage::GetCurrent().Remove( imageView );
853
854   ResourceImage image1 = ResourceImage::New( TEST_IMAGE_FILE_NAME );
855   imageView.SetImage( image1 );
856   TestImage( imageView, image1 );
857
858   int width = 300;
859   int height = 400;
860   BufferImage image2 = CreateBufferImage( width, height, Vector4( 1.f, 1.f, 1.f, 1.f ) );
861   imageView.SetImage( image2 );
862   TestImage( imageView, image2 );
863
864   END_TEST;
865 }
866
867 bool gResourceReadySignalFired = false;
868 Vector3 gNaturalSize;
869
870 void ResourceReadySignal( Control control )
871 {
872   gResourceReadySignalFired = true;
873 }
874
875 int UtcDaliImageViewCheckResourceReady(void)
876 {
877   ToolkitTestApplication application;
878
879   gResourceReadySignalFired = false;
880
881
882   int width = 100;
883   int height = 200;
884   Image image = CreateBufferImage( width, height, Vector4(1.f, 1.f, 1.f, 1.f) );
885
886   // Check ImageView with background and main image, to ensure both visuals are marked as loaded
887   ImageView imageView = ImageView::New( TEST_GIF_FILE_NAME );
888
889   imageView.SetBackgroundImage( image );
890
891   DALI_TEST_EQUALS( imageView.IsResourceReady(), false, TEST_LOCATION );
892
893   imageView.ResourceReadySignal().Connect( &ResourceReadySignal);
894
895   Stage::GetCurrent().Add( imageView );
896
897   application.SendNotification();
898   application.Render(16);
899
900
901   DALI_TEST_EQUALS( imageView.IsResourceReady(), true, TEST_LOCATION );
902
903   DALI_TEST_EQUALS( gResourceReadySignalFired, true, TEST_LOCATION );
904
905   END_TEST;
906 }
907
908 int UtcDaliImageViewSetImageOffstageN(void)
909 {
910   ToolkitTestApplication application;
911
912   ImageView imageView = ImageView::New();
913
914   Stage::GetCurrent().Add( imageView );
915   application.SendNotification();
916   application.Render();
917   Stage::GetCurrent().Remove( imageView );
918
919   ResourceImage image1 = ResourceImage::New( TEST_IMAGE_FILE_NAME );
920   imageView.SetImage( image1 );
921   TestImage( imageView, image1 );
922
923   Image image2;
924   imageView.SetImage( image2 );
925
926   Property::Value value = imageView.GetProperty( imageView.GetPropertyIndex( "image" ) );
927
928   //the value should be empty
929   std::string url;
930   DALI_TEST_CHECK( !value.Get( url ) );
931
932   Property::Map map;
933   DALI_TEST_CHECK( !value.Get( map ) );
934
935   END_TEST;
936 }
937
938 int UtcDaliImageViewSetImageN(void)
939 {
940   ToolkitTestApplication application;
941
942   Image image1;
943   ImageView imageView = ImageView::New();
944   imageView.SetImage( image1 );
945
946   Property::Value value = imageView.GetProperty( imageView.GetPropertyIndex( "image" ) );
947
948   //the value should be empty
949   std::string url;
950   DALI_TEST_CHECK( !value.Get( url ) );
951
952   Property::Map map;
953   DALI_TEST_CHECK( !value.Get( map ) );
954
955   std::string resource_url;
956   Property::Value val = imageView.GetProperty( imageView.GetPropertyIndex( "image" ) );
957   DALI_TEST_CHECK( !val.Get( resource_url ) );
958
959   END_TEST;
960 }
961
962 int UtcDaliImageViewSetImageTypeChangesP(void)
963 {
964   ToolkitTestApplication application;
965
966   ImageView imageView = ImageView::New();
967   Toolkit::Internal::Control& controlImpl = Toolkit::Internal::GetImplementation( imageView );
968
969   Stage::GetCurrent().Add( imageView );
970
971   std::string url;
972   Property::Map map;
973   Toolkit::Visual::Base visual;
974
975   Property::Value value = imageView.GetProperty( imageView.GetPropertyIndex( "image" ) );
976   visual = DevelControl::GetVisual( controlImpl, ImageView::Property::IMAGE );
977
978   application.SendNotification();
979   application.Render( 16 );
980
981   DALI_TEST_CHECK( ! value.Get( url ) ); // Value should be empty
982   DALI_TEST_CHECK( ! value.Get( map ) ); // Value should be empty
983   DALI_TEST_CHECK( ! visual );           // Visual should be invalid
984
985   // Set a URL
986   imageView.SetImage( "TEST_URL" );
987
988   application.SendNotification();
989   application.Render( 16 );
990
991   value = imageView.GetProperty( imageView.GetPropertyIndex( "image" ) );
992   visual = DevelControl::GetVisual( controlImpl, ImageView::Property::IMAGE );
993
994   DALI_TEST_CHECK( value.Get( url ) );   // Value should NOT be empty
995   DALI_TEST_CHECK( ! value.Get( map ) ); // Value should be empty
996   DALI_TEST_CHECK( visual );             // Visual should be valid
997
998   // Set an empty Image
999   imageView.SetImage( Image() );
1000
1001   application.SendNotification();
1002   application.Render( 16 );
1003
1004   value = imageView.GetProperty( imageView.GetPropertyIndex( "image" ) );
1005   visual = DevelControl::GetVisual( controlImpl, ImageView::Property::IMAGE );
1006
1007   DALI_TEST_CHECK( ! value.Get( url ) ); // Value should be empty
1008   DALI_TEST_CHECK( ! value.Get( map ) ); // Value should be empty
1009   DALI_TEST_CHECK( ! visual );           // Visual should be invalid
1010
1011   // Set an Image
1012   ResourceImage image1 = ResourceImage::New( TEST_IMAGE_FILE_NAME );
1013   imageView.SetImage( image1 );
1014
1015   application.SendNotification();
1016   application.Render( 16 );
1017
1018   value = imageView.GetProperty( imageView.GetPropertyIndex( "image" ) );
1019   visual = DevelControl::GetVisual( controlImpl, ImageView::Property::IMAGE );
1020
1021   DALI_TEST_CHECK( ! value.Get( url ) ); // Value should be empty
1022   DALI_TEST_CHECK( value.Get( map ) );   // Value should NOT be empty
1023   DALI_TEST_CHECK( visual );             // Visual should be valid
1024
1025   // Set an empty URL
1026   imageView.SetImage( "" );
1027
1028   application.SendNotification();
1029   application.Render( 16 );
1030
1031   value = imageView.GetProperty( imageView.GetPropertyIndex( "image" ) );
1032   visual = DevelControl::GetVisual( controlImpl, ImageView::Property::IMAGE );
1033
1034   DALI_TEST_CHECK( ! value.Get( url ) ); // Value should be empty
1035   DALI_TEST_CHECK( ! value.Get( map ) ); // Value should be empty
1036   DALI_TEST_CHECK( ! visual );           // Visual should be invalid
1037
1038   // Set a URL in property map
1039   Property::Map propertyMap;
1040   propertyMap[ImageVisual::Property::URL] = TEST_IMAGE_FILE_NAME;
1041   imageView.SetProperty( ImageView::Property::IMAGE, propertyMap );
1042
1043   application.SendNotification();
1044   application.Render( 16 );
1045
1046   value = imageView.GetProperty( imageView.GetPropertyIndex( "image" ) );
1047   visual = DevelControl::GetVisual( controlImpl, ImageView::Property::IMAGE );
1048
1049   DALI_TEST_CHECK( ! value.Get( url ) ); // Value should be empty
1050   DALI_TEST_CHECK( value.Get( map ) );   // Value should NOT be empty
1051   DALI_TEST_CHECK( visual );             // Visual should be valid
1052
1053   // Set a URL in property map again
1054   propertyMap[ImageVisual::Property::URL] = gImage_34_RGBA;
1055   imageView.SetProperty( ImageView::Property::IMAGE, propertyMap );
1056
1057   application.SendNotification();
1058   application.Render( 16 );
1059
1060   value = imageView.GetProperty( imageView.GetPropertyIndex( "image" ) );
1061   visual = DevelControl::GetVisual( controlImpl, ImageView::Property::IMAGE );
1062
1063   DALI_TEST_CHECK( ! value.Get( url ) ); // Value should be empty
1064   DALI_TEST_CHECK( value.Get( map ) );   // Value should NOT be empty
1065   DALI_TEST_CHECK( visual );             // Visual should be valid
1066
1067   // Set an empty URL in property map
1068   propertyMap[ImageVisual::Property::URL] = std::string();
1069   imageView.SetProperty( ImageView::Property::IMAGE, propertyMap );
1070
1071   application.SendNotification();
1072   application.Render( 16 );
1073
1074   value = imageView.GetProperty( imageView.GetPropertyIndex( "image" ) );
1075   visual = DevelControl::GetVisual( controlImpl, ImageView::Property::IMAGE );
1076
1077   DALI_TEST_CHECK( ! value.Get( url ) ); // Value should be empty
1078   DALI_TEST_CHECK( value.Get( map ) );   // Value should NOT be empty
1079   DALI_TEST_CHECK( ! visual );           // Visual should be invalid
1080
1081   END_TEST;
1082 }
1083
1084 int UtcDaliImageViewResourceUrlP(void)
1085 {
1086   ToolkitTestApplication application;
1087
1088   ImageView imageView = ImageView::New();
1089   DALI_TEST_CHECK( imageView.GetProperty( ImageView::Property::RESOURCE_URL ).Get< std::string >().empty() );
1090
1091   imageView.SetProperty( ImageView::Property::RESOURCE_URL, "TestString" );
1092   DALI_TEST_EQUALS( imageView.GetProperty( ImageView::Property::RESOURCE_URL ).Get< std::string >(), "TestString", TEST_LOCATION );
1093
1094   END_TEST;
1095 }
1096
1097 // Scenarios 1: ImageView from regular image
1098 int UtcDaliImageViewSetImageBufferImage(void)
1099 {
1100   ToolkitTestApplication application;
1101
1102   ImageView imageView = ImageView::New();
1103   Stage::GetCurrent().Add( imageView );
1104
1105   TestGlAbstraction& gl = application.GetGlAbstraction();
1106   gl.EnableTextureCallTrace( true );
1107
1108   std::vector< GLuint > ids;
1109   ids.push_back( 23 );
1110   application.GetGlAbstraction().SetNextTextureIds( ids );
1111
1112   int width = 300;
1113   int height = 400;
1114   BufferImage image = CreateBufferImage( width, height, Color::WHITE );
1115
1116   imageView.SetImage( image );
1117
1118   application.SendNotification();
1119   application.Render();
1120
1121   DALI_TEST_CHECK( gl.GetTextureTrace().FindMethod("BindTexture") );
1122
1123   std::stringstream params;
1124   params << GL_TEXTURE_2D << ", " << 23;
1125   DALI_TEST_CHECK( gl.GetTextureTrace().FindMethodAndParams("BindTexture", params.str()) );
1126
1127   END_TEST;
1128 }
1129
1130 // Scenarios 2: ImageView from Native image
1131 int UtcDaliImageViewSetImageNativeImage(void)
1132 {
1133   ToolkitTestApplication application;
1134
1135   ImageView imageView = ImageView::New();
1136   Stage::GetCurrent().Add( imageView );
1137
1138   TestGlAbstraction& gl = application.GetGlAbstraction();
1139   gl.EnableTextureCallTrace( true );
1140
1141   std::vector< GLuint > ids;
1142   ids.push_back( 23 );
1143   application.GetGlAbstraction().SetNextTextureIds( ids );
1144
1145   int width = 200;
1146   int height = 500;
1147   TestNativeImagePointer nativeImageInterface = TestNativeImage::New( width, height );
1148   NativeImage nativeImage = NativeImage::New( *(nativeImageInterface.Get()) );
1149
1150   imageView.SetImage( nativeImage );
1151   application.SendNotification();
1152   application.Render();
1153
1154   DALI_TEST_CHECK( gl.GetTextureTrace().FindMethod("BindTexture") );
1155
1156   std::stringstream params;
1157   params << GL_TEXTURE_EXTERNAL_OES << ", " << 23;
1158   DALI_TEST_CHECK( gl.GetTextureTrace().FindMethodAndParams("BindTexture", params.str()) );
1159
1160   END_TEST;
1161 }
1162
1163 // Scenarios 3: ImageView initially from regular image but then SetImage called with Native image
1164 int UtcDaliImageViewSetImageBufferImageToNativeImage(void)
1165 {
1166   ToolkitTestApplication application;
1167
1168   int width = 300;
1169   int height = 400;
1170   BufferImage image = CreateBufferImage( width, height, Color::WHITE );
1171
1172   ImageView imageView = ImageView::New( image );
1173   Stage::GetCurrent().Add( imageView );
1174
1175   TestGlAbstraction& gl = application.GetGlAbstraction();
1176   gl.EnableTextureCallTrace( true );
1177
1178   std::vector< GLuint > ids;
1179   ids.push_back( 23 );
1180   application.GetGlAbstraction().SetNextTextureIds( ids );
1181
1182   application.SendNotification();
1183   application.Render();
1184
1185   DALI_TEST_CHECK( gl.GetTextureTrace().FindMethod("BindTexture") );
1186
1187   std::stringstream params;
1188   params << GL_TEXTURE_2D << ", " << 23;
1189   DALI_TEST_CHECK( gl.GetTextureTrace().FindMethodAndParams("BindTexture", params.str()) );
1190
1191   width = 200;
1192   height = 500;
1193   TestNativeImagePointer nativeImageInterface = TestNativeImage::New( width, height );
1194   NativeImage nativeImage = NativeImage::New( *(nativeImageInterface.Get()) );
1195   imageView.SetImage( nativeImage );
1196
1197   ids.clear();
1198   ids.push_back( 24 );
1199   application.GetGlAbstraction().SetNextTextureIds( ids );
1200
1201   application.SendNotification();
1202   application.Render();
1203
1204   DALI_TEST_CHECK( gl.GetTextureTrace().FindMethod("BindTexture") );
1205
1206   std::stringstream nextTextureParams;
1207   nextTextureParams << GL_TEXTURE_EXTERNAL_OES << ", " << 24;
1208   DALI_TEST_CHECK( gl.GetTextureTrace().FindMethodAndParams("BindTexture", nextTextureParams.str()) );
1209
1210   END_TEST;
1211 }
1212
1213 // Scenarios 4: ImageView initially from Native image but then SetImage called with regular image
1214 int UtcDaliImageViewSetImageNativeImageToBufferImage(void)
1215 {
1216   ToolkitTestApplication application;
1217
1218   int width = 300;
1219   int height = 400;
1220   TestNativeImagePointer nativeImageInterface = TestNativeImage::New( width, height );
1221   NativeImage nativeImage = NativeImage::New( *(nativeImageInterface.Get()) );
1222
1223   ImageView imageView = ImageView::New( nativeImage );
1224   Stage::GetCurrent().Add( imageView );
1225
1226   TestGlAbstraction& gl = application.GetGlAbstraction();
1227   gl.EnableTextureCallTrace( true );
1228
1229   std::vector< GLuint > ids;
1230   ids.push_back( 23 );
1231   application.GetGlAbstraction().SetNextTextureIds( ids );
1232
1233   application.SendNotification();
1234   application.Render();
1235
1236   DALI_TEST_CHECK( gl.GetTextureTrace().FindMethod("BindTexture") );
1237
1238   std::stringstream params;
1239   params << GL_TEXTURE_EXTERNAL_OES << ", " << 23;
1240   DALI_TEST_CHECK( gl.GetTextureTrace().FindMethodAndParams("BindTexture", params.str()) );
1241
1242   width = 200;
1243   height = 500;
1244   BufferImage image = CreateBufferImage( width, height, Color::WHITE );
1245   imageView.SetImage( image );
1246
1247   ids.clear();
1248   ids.push_back( 24 );
1249   application.GetGlAbstraction().SetNextTextureIds( ids );
1250
1251   application.SendNotification();
1252   application.Render();
1253
1254   DALI_TEST_CHECK( gl.GetTextureTrace().FindMethod("BindTexture") );
1255
1256   std::stringstream nextTextureParams;
1257   nextTextureParams << GL_TEXTURE_2D << ", " << 24;
1258   DALI_TEST_CHECK( gl.GetTextureTrace().FindMethodAndParams("BindTexture", nextTextureParams.str()) );
1259
1260   END_TEST;
1261 }
1262
1263 // Scenarios 5: ImageView from Native image with custom shader
1264 int UtcDaliImageViewSetImageNativeImageWithCustomShader(void)
1265 {
1266   ToolkitTestApplication application;
1267
1268   int width = 300;
1269   int height = 400;
1270
1271   Property::Map customShader;
1272   customShader.Insert( "vertexShader", VERTEX_SHADER );
1273   customShader.Insert( "fragmentShader", FRAGMENT_SHADER );
1274
1275   Property::Array shaderHints;
1276   shaderHints.PushBack( "requiresSelfDepthTest" );
1277   shaderHints.PushBack( "outputIsTransparent" );
1278   shaderHints.PushBack( "outputIsOpaque" );
1279   shaderHints.PushBack( "modifiesGeometry" );
1280
1281   customShader.Insert( "hints", shaderHints );
1282
1283   Property::Map map;
1284   map.Insert( "shader", customShader );
1285
1286   TestNativeImagePointer nativeImageInterface = TestNativeImage::New( width, height );
1287   NativeImage nativeImage = NativeImage::New( *(nativeImageInterface.Get()) );
1288
1289   ImageView imageView = ImageView::New( nativeImage );
1290   imageView.SetProperty( ImageView::Property::IMAGE, map );
1291   Stage::GetCurrent().Add( imageView );
1292
1293   TestGlAbstraction& gl = application.GetGlAbstraction();
1294   gl.EnableTextureCallTrace( true );
1295
1296   std::vector< GLuint > ids;
1297   ids.push_back( 23 );
1298   application.GetGlAbstraction().SetNextTextureIds( ids );
1299
1300   application.SendNotification();
1301   application.Render();
1302
1303   DALI_TEST_CHECK( gl.GetTextureTrace().FindMethod("BindTexture") );
1304
1305   std::stringstream params;
1306   params << GL_TEXTURE_EXTERNAL_OES << ", " << 23;
1307   DALI_TEST_CHECK( gl.GetTextureTrace().FindMethodAndParams("BindTexture", params.str()) );
1308
1309   END_TEST;
1310 }
1311
1312 // Scenarios 6: ImageView initially from regular image with custom shader but then SetImage called with Native
1313 int UtcDaliImageViewSetImageBufferImageWithCustomShaderToNativeImage(void)
1314 {
1315   ToolkitTestApplication application;
1316
1317   int width = 300;
1318   int height = 400;
1319
1320   Property::Map customShader;
1321   customShader.Insert( "vertexShader", VERTEX_SHADER );
1322   customShader.Insert( "fragmentShader", FRAGMENT_SHADER );
1323
1324   Property::Array shaderHints;
1325   shaderHints.PushBack( "requiresSelfDepthTest" );
1326   shaderHints.PushBack( "outputIsTransparent" );
1327   shaderHints.PushBack( "outputIsOpaque" );
1328   shaderHints.PushBack( "modifiesGeometry" );
1329
1330   customShader.Insert( "hints", shaderHints );
1331
1332   Property::Map map;
1333   map.Insert( "shader", customShader );
1334
1335   BufferImage image = CreateBufferImage( width, height, Color::WHITE );
1336
1337   ImageView imageView = ImageView::New( image );
1338   imageView.SetProperty( ImageView::Property::IMAGE, map );
1339   Stage::GetCurrent().Add( imageView );
1340
1341   TestGlAbstraction& gl = application.GetGlAbstraction();
1342   gl.EnableTextureCallTrace( true );
1343
1344   std::vector< GLuint > ids;
1345   ids.push_back( 23 );
1346   application.GetGlAbstraction().SetNextTextureIds( ids );
1347
1348   application.SendNotification();
1349   application.Render();
1350
1351   DALI_TEST_CHECK( gl.GetTextureTrace().FindMethod("BindTexture") );
1352
1353   std::stringstream params;
1354   params << GL_TEXTURE_2D << ", " << 23;
1355   DALI_TEST_CHECK( gl.GetTextureTrace().FindMethodAndParams("BindTexture", params.str()) );
1356
1357   TestNativeImagePointer nativeImageInterface = TestNativeImage::New( width, height );
1358   NativeImage nativeImage = NativeImage::New( *(nativeImageInterface.Get()) );
1359   imageView.SetImage( nativeImage );
1360
1361   ids.clear();
1362   ids.push_back( 24 );
1363   application.GetGlAbstraction().SetNextTextureIds( ids );
1364
1365   application.SendNotification();
1366   application.Render();
1367
1368   DALI_TEST_CHECK( gl.GetTextureTrace().FindMethod("BindTexture") );
1369
1370   std::stringstream nativeImageParams;
1371   nativeImageParams << GL_TEXTURE_EXTERNAL_OES << ", " << 24;
1372   DALI_TEST_CHECK( gl.GetTextureTrace().FindMethodAndParams("BindTexture", nativeImageParams.str()) );
1373
1374
1375   END_TEST;
1376 }
1377
1378 int UtcDaliImageViewGetImageP1(void)
1379 {
1380   ToolkitTestApplication application;
1381
1382   ImageView imageView = ImageView::New();
1383   DALI_TEST_CHECK( ! imageView.GetImage() );
1384
1385   Image image = CreateBufferImage();
1386   imageView.SetImage( image );
1387   DALI_TEST_CHECK( imageView.GetImage() == image );
1388
1389   END_TEST;
1390 }
1391
1392 int UtcDaliImageViewGetImageP2(void)
1393 {
1394   ToolkitTestApplication application;
1395
1396   BufferImage image = CreateBufferImage();
1397   ImageView imageView = ImageView::New( image );
1398   DALI_TEST_CHECK( imageView.GetImage() == image );
1399
1400   END_TEST;
1401 }
1402
1403 int UtcDaliImageViewGetImageN(void)
1404 {
1405   ToolkitTestApplication application;
1406
1407   ImageView imageView = ImageView::New( TEST_IMAGE_FILE_NAME );
1408   DALI_TEST_CHECK( ! imageView.GetImage() );
1409
1410   Image image = CreateBufferImage();
1411   imageView.SetImage( image );
1412   DALI_TEST_CHECK( imageView.GetImage() == image );
1413
1414   imageView.SetImage( TEST_IMAGE_FILE_NAME );
1415   DALI_TEST_CHECK( ! imageView.GetImage() );
1416
1417   END_TEST;
1418 }
1419
1420
1421 int UtcDaliImageViewReplaceImage(void)
1422 {
1423   ToolkitTestApplication application;
1424
1425   gResourceReadySignalFired = false;
1426
1427   int width = 100;
1428   int height = 200;
1429   Image image = CreateBufferImage( width, height, Vector4(1.f, 1.f, 1.f, 1.f) );
1430
1431   // Check ImageView with background and main image, to ensure both visuals are marked as loaded
1432   ImageView imageView = ImageView::New( TEST_IMAGE_1 );
1433
1434   DALI_TEST_EQUALS( imageView.IsResourceReady(), false, TEST_LOCATION );
1435
1436   imageView.ResourceReadySignal().Connect( &ResourceReadySignal);
1437
1438   Stage::GetCurrent().Add( imageView );
1439
1440   application.SendNotification();
1441   application.Render(16);
1442
1443   // loading started, this waits for the loader thread for max 30 seconds
1444   DALI_TEST_EQUALS( Test::WaitForEventThreadTrigger( 1 ), true, TEST_LOCATION );
1445
1446   DALI_TEST_EQUALS( imageView.GetRendererCount(), 1u, TEST_LOCATION );
1447
1448   DALI_TEST_EQUALS( gResourceReadySignalFired, true, TEST_LOCATION );
1449
1450   gResourceReadySignalFired = false;
1451
1452   imageView.SetImage(TEST_IMAGE_2);
1453
1454   application.SendNotification();
1455   application.Render(16);
1456
1457   // loading started, this waits for the loader thread for max 30 seconds
1458   DALI_TEST_EQUALS( Test::WaitForEventThreadTrigger( 1 ), true, TEST_LOCATION );
1459
1460   DALI_TEST_EQUALS( imageView.GetRendererCount(), 1u, TEST_LOCATION );
1461
1462   DALI_TEST_EQUALS( imageView.IsResourceReady(), true, TEST_LOCATION );
1463
1464   DALI_TEST_EQUALS( gResourceReadySignalFired, true, TEST_LOCATION );
1465
1466   END_TEST;
1467 }
1468
1469 void OnRelayoutOverride( Size size )
1470 {
1471   gNaturalSize = size; // Size Relayout is using
1472 }
1473
1474 int UtcDaliImageViewReplaceImageAndGetNaturalSize(void)
1475 {
1476   ToolkitTestApplication application;
1477
1478   // Check ImageView with background and main image, to ensure both visuals are marked as loaded
1479   ImageView imageView = ImageView::New( TEST_IMAGE_1 );
1480   imageView.SetResizePolicy( ResizePolicy::USE_NATURAL_SIZE, Dimension::ALL_DIMENSIONS );
1481
1482   DummyControl dummyControl = DummyControl::New( true );
1483   Impl::DummyControl& dummyImpl = static_cast<Impl::DummyControl&>(dummyControl.GetImplementation());
1484   dummyControl.SetResizePolicy( ResizePolicy::FIT_TO_CHILDREN, Dimension::ALL_DIMENSIONS );
1485
1486   dummyControl.Add( imageView );
1487   dummyImpl.SetRelayoutCallback( &OnRelayoutOverride );
1488   Stage::GetCurrent().Add( dummyControl );
1489
1490   application.SendNotification();
1491   application.Render();
1492
1493   // loading started, this waits for the loader thread for max 30 seconds
1494   DALI_TEST_EQUALS( Test::WaitForEventThreadTrigger( 1 ), true, TEST_LOCATION );
1495
1496   DALI_TEST_EQUALS( gNaturalSize.width, 1024.0f, TEST_LOCATION );
1497   DALI_TEST_EQUALS( gNaturalSize.height, 1024.0f, TEST_LOCATION );
1498
1499   gNaturalSize = Vector3::ZERO;
1500
1501   imageView.SetImage(gImage_600_RGB);
1502
1503   // Waiting for resourceReady so SendNotifcation not called here.
1504
1505   // loading started, this waits for the loader thread for max 30 seconds
1506   DALI_TEST_EQUALS( Test::WaitForEventThreadTrigger( 1 ), true, TEST_LOCATION );
1507
1508   // Trigger a potential relayout
1509   application.SendNotification();
1510   application.Render();
1511
1512   DALI_TEST_EQUALS( gNaturalSize.width, 600.0f, TEST_LOCATION );
1513   DALI_TEST_EQUALS( gNaturalSize.height, 600.0f, TEST_LOCATION );
1514
1515   END_TEST;
1516 }
1517
1518 int UtcDaliImageViewResourceReadySignalWithImmediateLoad(void)
1519 {
1520   tet_infoline("Test Setting Image with IMMEDIATE load and receving ResourceReadySignal before staged.");
1521
1522   ToolkitTestApplication application;
1523
1524   gResourceReadySignalFired = false;
1525
1526   Property::Map imageMap;
1527
1528   imageMap[ ImageVisual::Property::URL ] = gImage_34_RGBA;
1529   imageMap[ DevelImageVisual::Property::LOAD_POLICY ] =  DevelImageVisual::LoadPolicy::IMMEDIATE;
1530
1531   tet_infoline("Creating ImageView without URL so image does not start loading");
1532   ImageView imageView = ImageView::New();
1533   tet_infoline("Connect to image loaded signal before setting image");
1534   imageView.ResourceReadySignal().Connect( &ResourceReadySignal);
1535   tet_infoline("Setting Image with IMMEDIATE load, signal already connected so will be triggered.");
1536   imageView.SetProperty( ImageView::Property::IMAGE, imageMap );
1537
1538   // loading started, this waits for the loader thread
1539   DALI_TEST_EQUALS( Test::WaitForEventThreadTrigger( 1 ), true, TEST_LOCATION );
1540
1541   application.SendNotification();
1542   application.Render(16);
1543
1544   DALI_TEST_EQUALS( gResourceReadySignalFired, true, TEST_LOCATION );
1545
1546   END_TEST;
1547 }
1548
1549 int UtcDaliImageViewResourceReadySignalWithReusedImage(void)
1550 {
1551   tet_infoline("Test Setting Image that was already loaded by another ImageView and still getting ResourceReadySignal.");
1552
1553   ToolkitTestApplication application;
1554
1555   gResourceReadySignalFired = false;
1556
1557   Property::Map imageMap;
1558
1559   imageMap[ ImageVisual::Property::URL ] = gImage_34_RGBA;
1560   imageMap[ DevelImageVisual::Property::LOAD_POLICY ] =  DevelImageVisual::LoadPolicy::IMMEDIATE;
1561
1562   ImageView imageView = ImageView::New();
1563   imageView.ResourceReadySignal().Connect( &ResourceReadySignal);
1564   imageView.SetProperty( ImageView::Property::IMAGE, imageMap );
1565
1566   // loading started, this waits for the loader thread
1567   DALI_TEST_EQUALS( Test::WaitForEventThreadTrigger( 1 ), true, TEST_LOCATION );
1568
1569   application.SendNotification();
1570   application.Render(16);
1571
1572   DALI_TEST_EQUALS( gResourceReadySignalFired, true, TEST_LOCATION );
1573   gResourceReadySignalFired = false;
1574
1575   ImageView imageViewWithExistingImage = ImageView::New();
1576   imageViewWithExistingImage.ResourceReadySignal().Connect( &ResourceReadySignal);
1577   imageViewWithExistingImage.SetProperty( ImageView::Property::IMAGE, imageMap );
1578
1579   DALI_TEST_EQUALS( gResourceReadySignalFired, true, TEST_LOCATION );
1580
1581   END_TEST;
1582 }
1583
1584 int UtcDaliImageViewResourceReadySignalWithReusedImage02(void)
1585 {
1586   tet_infoline("Test Setting Image that was already loaded by another ImageView and still getting ResourceReadySignal when staged.");
1587
1588   ToolkitTestApplication application;
1589
1590   gResourceReadySignalFired = false;
1591
1592   Property::Map imageImmediateLoadingMap;
1593   imageImmediateLoadingMap[ ImageVisual::Property::URL ] = gImage_34_RGBA;
1594   imageImmediateLoadingMap[ DevelImageVisual::Property::LOAD_POLICY ] =  DevelImageVisual::LoadPolicy::IMMEDIATE;
1595
1596   tet_infoline("Immediate load an image");
1597   ImageView imageView = ImageView::New();
1598   imageView.ResourceReadySignal().Connect( &ResourceReadySignal);
1599   imageView.SetProperty( ImageView::Property::IMAGE, imageImmediateLoadingMap );
1600
1601   // loading started, this waits for the loader thread
1602   DALI_TEST_EQUALS( Test::WaitForEventThreadTrigger( 1 ), true, TEST_LOCATION );
1603
1604   application.SendNotification();
1605   application.Render(16);
1606
1607   tet_infoline("Check image loaded");
1608   DALI_TEST_EQUALS( gResourceReadySignalFired, true, TEST_LOCATION );
1609   gResourceReadySignalFired = false;
1610
1611   tet_infoline("Create another ImageView with the same URL");
1612   ImageView imageViewWithExistingImage = ImageView::New( gImage_34_RGBA );
1613   tet_infoline("Connect to ResourceReady signal for second ImageView, it should still fire as resource is ready");
1614   imageViewWithExistingImage.ResourceReadySignal().Connect( &ResourceReadySignal);
1615
1616   Stage::GetCurrent().Add( imageViewWithExistingImage );
1617
1618   DALI_TEST_EQUALS( gResourceReadySignalFired, true, TEST_LOCATION );
1619
1620   END_TEST;
1621 }