32d987f5e9e3fef76a6f5add2c2014ffe775edd0
[platform/core/uifw/dali-toolkit.git] / automated-tests / src / dali-toolkit / utc-Dali-ImageView.cpp
1 /*
2  * Copyright (c) 2014 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
22 #include <dali-toolkit/dali-toolkit.h>
23 #include <dali/devel-api/scripting/scripting.h>
24 #include <dali/devel-api/rendering/material.h>
25 #include <dali/devel-api/rendering/renderer.h>
26
27 #include <test-native-image.h>
28 #include <sstream>
29
30 using namespace Dali;
31 using namespace Toolkit;
32
33 void utc_dali_toolkit_image_view_startup(void)
34 {
35   test_return_value = TET_UNDEF;
36 }
37
38 void utc_dali_toolkit_image_view_cleanup(void)
39 {
40   test_return_value = TET_PASS;
41 }
42
43 namespace
44 {
45
46 const char* VERTEX_SHADER = DALI_COMPOSE_SHADER(
47   attribute mediump vec2 aPosition;\n
48   varying mediump vec2 vTexCoord;\n
49   uniform mediump mat4 uMvpMatrix;\n
50   uniform mediump vec3 uSize;\n
51   \n
52   void main()\n
53   {\n
54     mediump vec4 vertexPosition = vec4(aPosition, 0.0, 1.0);\n
55     vertexPosition.xyz *= uSize;\n
56     vertexPosition = uMvpMatrix * vertexPosition;\n
57     \n
58     vTexCoord = aPosition + vec2(0.5);\n
59     gl_Position = vertexPosition;\n
60   }\n
61 );
62
63 const char* FRAGMENT_SHADER = DALI_COMPOSE_SHADER(
64   varying mediump vec2 vTexCoord;\n
65   uniform sampler2D sTexture;\n
66   uniform lowp vec4 uColor;\n
67   \n
68   void main()\n
69   {\n
70     gl_FragColor = texture2D( sTexture, vTexCoord ) * uColor;\n
71   }\n
72 );
73
74 const char* TEST_IMAGE_FILE_NAME =  "gallery_image_01.jpg";
75 const char* TEST_IMAGE_FILE_NAME2 =  "gallery_image_02.jpg";
76
77 void TestImage( ImageView imageView, BufferImage image )
78 {
79   Property::Value value = imageView.GetProperty( imageView.GetPropertyIndex( "image" ) );
80
81   Property::Map map;
82   DALI_TEST_CHECK( value.Get( map ) );
83
84   DALI_TEST_CHECK( map.Find( "width" ) );
85   DALI_TEST_CHECK( map.Find( "height" ) );
86   DALI_TEST_CHECK( map.Find( "type" ) );
87
88   int width = 0;
89   DALI_TEST_CHECK( map[ "width" ].Get( width ) );
90   DALI_TEST_EQUALS( (unsigned int)width, image.GetWidth(), TEST_LOCATION );
91
92   int height = 0;
93   DALI_TEST_CHECK( map[ "height" ].Get( height ) );
94   DALI_TEST_EQUALS( (unsigned int)height, image.GetHeight(), TEST_LOCATION );
95
96   std::string type;
97   DALI_TEST_CHECK( map[ "type" ].Get( type ) );
98   DALI_TEST_EQUALS( type, "BufferImage", TEST_LOCATION );
99 }
100
101 void TestImage( ImageView imageView, ResourceImage image )
102 {
103   Property::Value value = imageView.GetProperty( imageView.GetPropertyIndex( "image" ) );
104
105   Property::Map map;
106   DALI_TEST_CHECK( value.Get( map ) );
107
108   if( map.Find( "width" ) )
109   {
110     int width = 0;
111     DALI_TEST_CHECK( map[ "width" ].Get( width ) );
112     DALI_TEST_EQUALS( (unsigned int)width, image.GetWidth(), TEST_LOCATION );
113   }
114
115   if( map.Find( "height" ) )
116   {
117     int height = 0;
118     DALI_TEST_CHECK( map[ "height" ].Get( height ) );
119     DALI_TEST_EQUALS( (unsigned int)height, image.GetHeight(), TEST_LOCATION );
120   }
121
122   DALI_TEST_CHECK( map.Find( "type" ) );
123
124   std::string type;
125   DALI_TEST_CHECK( map[ "type" ].Get( type ) );
126   DALI_TEST_EQUALS( type, "ResourceImage", TEST_LOCATION );
127
128   std::string filename;
129   DALI_TEST_CHECK( map[ "filename" ].Get( filename ) );
130   DALI_TEST_EQUALS( filename, image.GetUrl(), TEST_LOCATION );
131 }
132
133 void TestUrl( ImageView imageView, const std::string url )
134 {
135   Property::Value value = imageView.GetProperty( imageView.GetPropertyIndex( "image" ) );
136
137   std::string urlActual;
138   DALI_TEST_CHECK( value.Get( urlActual ) );
139   DALI_TEST_EQUALS( urlActual, url, TEST_LOCATION );
140 }
141
142 } // namespace
143
144 int UtcDaliImageViewNewP(void)
145 {
146   TestApplication application;
147
148   ImageView imageView = ImageView::New();
149
150   DALI_TEST_CHECK( imageView );
151
152   END_TEST;
153 }
154
155 int UtcDaliImageViewNewImageP(void)
156 {
157   TestApplication application;
158
159   BufferImage image = CreateBufferImage( 100, 200, Vector4( 1.f, 1.f, 1.f, 1.f ) );
160   ImageView imageView = ImageView::New( image );
161
162   DALI_TEST_CHECK( imageView );
163   TestImage( imageView, image );
164
165   END_TEST;
166 }
167
168 int UtcDaliImageViewNewUrlP(void)
169 {
170   TestApplication application;
171
172   ImageView imageView = ImageView::New( TEST_IMAGE_FILE_NAME );
173   DALI_TEST_CHECK( imageView );
174
175   TestUrl( imageView, TEST_IMAGE_FILE_NAME );
176
177   END_TEST;
178 }
179
180 int UtcDaliImageViewConstructorP(void)
181 {
182   TestApplication application;
183
184   ImageView imageView;
185
186   DALI_TEST_CHECK( !imageView );
187
188   END_TEST;
189 }
190
191 int UtcDaliImageViewCopyConstructorP(void)
192 {
193   TestApplication application;
194
195   // Initialize an object, ref count == 1
196   ImageView imageView = ImageView::New();
197
198   ImageView copy( imageView );
199   DALI_TEST_CHECK( copy );
200
201   END_TEST;
202 }
203
204 int UtcDaliImageViewAssignmentOperatorP(void)
205 {
206   TestApplication application;
207
208   ImageView imageView = ImageView::New();
209
210   ImageView copy( imageView );
211   DALI_TEST_CHECK( copy );
212   DALI_TEST_EQUALS( imageView, copy, TEST_LOCATION );
213
214   END_TEST;
215 }
216
217 int UtcDaliImageViewDownCastP(void)
218 {
219   TestApplication application;
220
221   ImageView imageView = ImageView::New();
222
223   BaseHandle object(imageView);
224
225   ImageView imageView2 = ImageView::DownCast( object );
226   DALI_TEST_CHECK(imageView2);
227
228   ImageView imageView3 = DownCast< ImageView >( object );
229   DALI_TEST_CHECK(imageView3);
230
231   END_TEST;
232 }
233
234 int UtcDaliImageViewDownCastN(void)
235 {
236   TestApplication application;
237
238   BaseHandle unInitializedObject;
239
240   ImageView imageView1 = ImageView::DownCast( unInitializedObject );
241   DALI_TEST_CHECK( !imageView1 );
242
243   ImageView imageView2 = DownCast< ImageView >( unInitializedObject );
244   DALI_TEST_CHECK( !imageView2 );
245
246   END_TEST;
247 }
248
249 int UtcDaliImageViewTypeRegistry(void)
250 {
251   ToolkitTestApplication application;
252
253   TypeRegistry typeRegistry = TypeRegistry::Get();
254   DALI_TEST_CHECK( typeRegistry );
255
256   TypeInfo typeInfo = typeRegistry.GetTypeInfo( "ImageView" );
257   DALI_TEST_CHECK( typeInfo );
258
259   BaseHandle handle = typeInfo.CreateInstance();
260   DALI_TEST_CHECK( handle );
261
262   ImageView imageView = ImageView::DownCast( handle );
263   DALI_TEST_CHECK( imageView );
264
265   END_TEST;
266 }
267
268 int UtcDaliImageViewSetGetProperty01(void)
269 {
270   ToolkitTestApplication application;
271
272   ImageView imageView = ImageView::New();
273
274   Property::Index idx = imageView.GetPropertyIndex( "image" );
275   DALI_TEST_EQUALS( idx, (Property::Index)ImageView::Property::IMAGE, TEST_LOCATION );
276
277   imageView.SetProperty( idx, TEST_IMAGE_FILE_NAME );
278   TestUrl( imageView, TEST_IMAGE_FILE_NAME );
279
280   END_TEST;
281 }
282
283 int UtcDaliImageViewSetGetProperty02(void)
284 {
285   ToolkitTestApplication application;
286
287   Image image = CreateBufferImage( 10, 10, Color::WHITE );
288   ImageView imageView = ImageView::New(image);
289   Vector4 fullImageRect( 0.f, 0.f, 1.f, 1.f );
290
291   Stage::GetCurrent().Add( imageView );
292
293   application.SendNotification();
294   application.Render();
295   TestGlAbstraction& gl = application.GetGlAbstraction();
296
297   Vector4 pixelAreaUniform;
298   DALI_TEST_CHECK( gl.GetUniformValue<Vector4>( "pixelArea", pixelAreaUniform ) );
299   DALI_TEST_EQUALS( pixelAreaUniform, fullImageRect, TEST_LOCATION );
300
301   Property::Value value = imageView.GetProperty( ImageView::Property::PIXEL_AREA );
302   Vector4 pixelAreaValue;
303   DALI_TEST_CHECK( value.Get(pixelAreaValue) );
304   DALI_TEST_EQUALS( pixelAreaValue, fullImageRect, TEST_LOCATION );
305
306   Vector4 pixelAreaSet( 0.2f, 0.2f, 0.3f, 0.3f );
307   imageView.SetProperty( ImageView::Property::PIXEL_AREA, pixelAreaSet);
308
309   application.SendNotification();
310   application.Render();
311
312   value = imageView.GetProperty( ImageView::Property::PIXEL_AREA );
313   value.Get(pixelAreaValue);
314   DALI_TEST_EQUALS( pixelAreaValue, pixelAreaSet, TEST_LOCATION );
315
316   DALI_TEST_CHECK( gl.GetUniformValue<Vector4>( "pixelArea", pixelAreaUniform ) );
317   DALI_TEST_EQUALS( pixelAreaUniform, pixelAreaSet, TEST_LOCATION );
318
319   END_TEST;
320 }
321
322 int UtcDaliImageViewSetGetProperty03(void)
323 {
324   ToolkitTestApplication application;
325
326   Image image = CreateBufferImage( 10, 10, Color::WHITE );
327   ImageView imageView = ImageView::New(image);
328   Stage::GetCurrent().Add( imageView );
329   application.SendNotification();
330   application.Render();
331
332  // conventional alpha blending
333   Material material = imageView.GetRendererAt( 0 ).GetMaterial();
334   BlendingFactor::Type srcFactorRgb;
335   BlendingFactor::Type destFactorRgb;
336   BlendingFactor::Type srcFactorAlpha;
337   BlendingFactor::Type destFactorAlpha;
338   material.GetBlendFunc(srcFactorRgb, destFactorRgb, srcFactorAlpha, destFactorAlpha);
339   DALI_TEST_CHECK( srcFactorRgb == BlendingFactor::SRC_ALPHA );
340   DALI_TEST_CHECK( destFactorRgb == BlendingFactor::ONE_MINUS_SRC_ALPHA );
341   DALI_TEST_CHECK( srcFactorAlpha == BlendingFactor::ONE );
342   DALI_TEST_CHECK( destFactorAlpha == BlendingFactor::ONE_MINUS_SRC_ALPHA );
343
344   TestGlAbstraction& gl = application.GetGlAbstraction();
345
346   float alphaBlendingUniform;
347   DALI_TEST_CHECK( gl.GetUniformValue<float>( "uAlphaBlending", alphaBlendingUniform ) );
348   DALI_TEST_EQUALS( alphaBlendingUniform, 1.f, TEST_LOCATION );
349
350   // pre-multiplied alpha blending
351   imageView.SetProperty( Toolkit::ImageView::Property::PRE_MULTIPLIED_ALPHA, true );
352   application.SendNotification();
353   application.Render();
354
355   material.GetBlendFunc(srcFactorRgb, destFactorRgb, srcFactorAlpha, destFactorAlpha);
356   DALI_TEST_CHECK( srcFactorRgb == BlendingFactor::ONE );
357   DALI_TEST_CHECK( destFactorRgb == BlendingFactor::ONE_MINUS_SRC_ALPHA );
358   DALI_TEST_CHECK( srcFactorAlpha == BlendingFactor::ONE );
359   DALI_TEST_CHECK( destFactorAlpha == BlendingFactor::ONE );
360
361   DALI_TEST_CHECK( gl.GetUniformValue<float>( "uAlphaBlending", alphaBlendingUniform ) );
362   DALI_TEST_EQUALS( alphaBlendingUniform, 0.f, TEST_LOCATION );
363
364   END_TEST;
365 }
366
367 int UtcDaliImageViewSizeWithBackground(void)
368 {
369   ToolkitTestApplication application;
370
371   int width = 100;
372   int height = 200;
373   Image image = CreateBufferImage( width, height, Vector4(1.f, 1.f, 1.f, 1.f) );
374   ImageView imageView = ImageView::New();
375   imageView.SetBackgroundImage( image );
376
377   Stage::GetCurrent().Add( imageView );
378   application.SendNotification();
379   application.Render();
380
381   DALI_TEST_EQUALS( imageView.GetCurrentSize().width, (float)width, TEST_LOCATION );
382   DALI_TEST_EQUALS( imageView.GetCurrentSize().height, (float)height, TEST_LOCATION );
383
384   END_TEST;
385 }
386
387 int UtcDaliImageViewSizeWithBackgroundAndImage(void)
388 {
389   ToolkitTestApplication application;
390
391   int widthBackground = 100;
392   int heightBackground = 200;
393   int width = 300;
394   int height = 400;
395   Image imageBackground = CreateBufferImage( widthBackground, heightBackground, Vector4(1.f, 1.f, 1.f, 1.f) );
396   Image image = CreateBufferImage( width, height, Vector4(1.f, 1.f, 1.f, 1.f) );
397
398   ImageView imageView = ImageView::New();
399   imageView.SetBackgroundImage( imageBackground );
400   imageView.SetImage( image );
401
402   Stage::GetCurrent().Add( imageView );
403   application.SendNotification();
404   application.Render();
405
406   DALI_TEST_EQUALS( imageView.GetCurrentSize().width, (float)width, TEST_LOCATION );
407   DALI_TEST_EQUALS( imageView.GetCurrentSize().height, (float)height, TEST_LOCATION );
408
409   END_TEST;
410 }
411
412 int UtcDaliImageViewHeightForWidthBackground(void)
413 {
414   ToolkitTestApplication application;
415
416   int widthBackground = 100;
417   int heightBackground = 200;
418   Image imageBackground = CreateBufferImage( widthBackground, heightBackground, Vector4(1.f, 1.f, 1.f, 1.f) );
419
420   ImageView imageView = ImageView::New();
421   imageView.SetBackgroundImage( imageBackground );
422
423   Stage::GetCurrent().Add( imageView );
424   application.SendNotification();
425   application.Render();
426
427   Control control = Control::DownCast( imageView );
428   DALI_TEST_CHECK( control );
429   DALI_TEST_EQUALS( imageView.GetHeightForWidth( 123.f ), control.GetHeightForWidth( 123.f ), TEST_LOCATION );
430   DALI_TEST_EQUALS( imageView.GetWidthForHeight( 321.f ), control.GetWidthForHeight( 321.f ), TEST_LOCATION );
431
432   END_TEST;
433 }
434
435 int UtcDaliImageViewHeightForWidthBackgroundAndImage(void)
436 {
437   ToolkitTestApplication application;
438
439   int widthBackground = 100;
440   int heightBackground = 200;
441   int width = 300;
442   int height = 400;
443   Image imageBackground = CreateBufferImage( widthBackground, heightBackground, Vector4(1.f, 1.f, 1.f, 1.f) );
444   Image image = CreateBufferImage( width, height, Vector4(1.f, 1.f, 1.f, 1.f) );
445
446   ImageView imageView = ImageView::New();
447   imageView.SetBackgroundImage( imageBackground );
448   imageView.SetImage( image );
449
450   Stage::GetCurrent().Add( imageView );
451   application.SendNotification();
452   application.Render();
453
454   DALI_TEST_EQUALS( imageView.GetHeightForWidth( width ), (float)height, TEST_LOCATION );
455   DALI_TEST_EQUALS( imageView.GetWidthForHeight( height ), (float)width, TEST_LOCATION );
456
457   END_TEST;
458 }
459
460 int UtcDaliImageViewSetBufferImage(void)
461 {
462   ToolkitTestApplication application;
463
464   int width1 = 300;
465   int height1 = 400;
466   BufferImage image1 = CreateBufferImage( width1, height1, Vector4( 1.f, 1.f, 1.f, 1.f ) );
467   ImageView imageView = ImageView::New();
468   imageView.SetImage( image1 );
469
470   TestImage( imageView, image1 );
471
472   int width2 = 600;
473   int height2 = 500;
474   BufferImage image2 = CreateBufferImage( width2, height2, Vector4( 1.f, 1.f, 1.f, 1.f ) );
475   imageView.SetImage( image2 );
476
477   TestImage( imageView, image2 );
478
479   END_TEST;
480 }
481
482 int UtcDaliImageViewSetImageUrl(void)
483 {
484   ToolkitTestApplication application;
485
486   ImageView imageView = ImageView::New();
487   imageView.SetImage( TEST_IMAGE_FILE_NAME );
488   TestUrl( imageView, TEST_IMAGE_FILE_NAME );
489
490
491   imageView.SetImage( TEST_IMAGE_FILE_NAME2 );
492   TestUrl( imageView, TEST_IMAGE_FILE_NAME2 );
493
494   END_TEST;
495 }
496
497 int UtcDaliImageViewSetImageOnstageP(void)
498 {
499   ToolkitTestApplication application;
500
501   ImageView imageView = ImageView::New();
502
503   Stage::GetCurrent().Add( imageView );
504   application.SendNotification();
505   application.Render();
506
507   ResourceImage image1 = ResourceImage::New( TEST_IMAGE_FILE_NAME );
508   imageView.SetImage( image1 );
509   TestImage( imageView, image1 );
510
511   int width = 300;
512   int height = 400;
513   BufferImage image2 = CreateBufferImage( width, height, Vector4( 1.f, 1.f, 1.f, 1.f ) );
514   imageView.SetImage( image2 );
515   TestImage( imageView, image2 );
516
517   END_TEST;
518 }
519
520 int UtcDaliImageViewSetImageOnstageN(void)
521 {
522   ToolkitTestApplication application;
523
524   ImageView imageView = ImageView::New();
525
526   Stage::GetCurrent().Add( imageView );
527   application.SendNotification();
528   application.Render();
529
530   ResourceImage image1 = ResourceImage::New( TEST_IMAGE_FILE_NAME );
531   imageView.SetImage( image1 );
532   TestImage( imageView, image1 );
533
534   Image image2;
535   imageView.SetImage( image2 );
536
537   Property::Value value = imageView.GetProperty( imageView.GetPropertyIndex( "image" ) );
538
539   //the value should be empty
540   std::string url;
541   DALI_TEST_CHECK( !value.Get( url ) );
542
543   Property::Map map;
544   DALI_TEST_CHECK( !value.Get( map ) );
545
546   END_TEST;
547 }
548
549 int UtcDaliImageViewSetImageOffstageP(void)
550 {
551   ToolkitTestApplication application;
552
553   ImageView imageView = ImageView::New();
554
555   Stage::GetCurrent().Add( imageView );
556   application.SendNotification();
557   application.Render();
558   Stage::GetCurrent().Remove( imageView );
559
560   ResourceImage image1 = ResourceImage::New( TEST_IMAGE_FILE_NAME );
561   imageView.SetImage( image1 );
562   TestImage( imageView, image1 );
563
564   int width = 300;
565   int height = 400;
566   BufferImage image2 = CreateBufferImage( width, height, Vector4( 1.f, 1.f, 1.f, 1.f ) );
567   imageView.SetImage( image2 );
568   TestImage( imageView, image2 );
569
570   END_TEST;
571 }
572
573 int UtcDaliImageViewSetImageOffstageN(void)
574 {
575   ToolkitTestApplication application;
576
577   ImageView imageView = ImageView::New();
578
579   Stage::GetCurrent().Add( imageView );
580   application.SendNotification();
581   application.Render();
582   Stage::GetCurrent().Remove( imageView );
583
584   ResourceImage image1 = ResourceImage::New( TEST_IMAGE_FILE_NAME );
585   imageView.SetImage( image1 );
586   TestImage( imageView, image1 );
587
588   Image image2;
589   imageView.SetImage( image2 );
590
591   Property::Value value = imageView.GetProperty( imageView.GetPropertyIndex( "image" ) );
592
593   //the value should be empty
594   std::string url;
595   DALI_TEST_CHECK( !value.Get( url ) );
596
597   Property::Map map;
598   DALI_TEST_CHECK( !value.Get( map ) );
599
600   END_TEST;
601 }
602
603 int UtcDaliImageViewSetImageN(void)
604 {
605   ToolkitTestApplication application;
606
607   Image image1;
608   ImageView imageView = ImageView::New();
609   imageView.SetImage( image1 );
610
611   Property::Value value = imageView.GetProperty( imageView.GetPropertyIndex( "image" ) );
612
613   //the value should be empty
614   std::string url;
615   DALI_TEST_CHECK( !value.Get( url ) );
616
617   Property::Map map;
618   DALI_TEST_CHECK( !value.Get( map ) );
619
620   std::string resource_url;
621   Property::Value val = imageView.GetProperty( imageView.GetPropertyIndex( "image" ) );
622   DALI_TEST_CHECK( !val.Get( resource_url ) );
623
624   END_TEST;
625 }
626
627 int UtcDaliImageViewSetImageTypeChangesP(void)
628 {
629   ToolkitTestApplication application;
630
631   ImageView imageView = ImageView::New();
632
633
634   std::string url;
635   Property::Map map;
636
637   Property::Value value = imageView.GetProperty( imageView.GetPropertyIndex( "image" ) );
638   DALI_TEST_CHECK( ! value.Get( url ) ); // Value should be empty
639   DALI_TEST_CHECK( ! value.Get( map ) ); // Value should be empty
640
641   // Set a URL
642   imageView.SetImage( "TEST_URL" );
643   value = imageView.GetProperty( imageView.GetPropertyIndex( "image" ) );
644
645   DALI_TEST_CHECK( value.Get( url ) );   // Value should NOT be empty
646   DALI_TEST_CHECK( ! value.Get( map ) ); // Value should be empty
647
648   // Set an empty Image
649   imageView.SetImage( Image() );
650   value = imageView.GetProperty( imageView.GetPropertyIndex( "image" ) );
651
652   DALI_TEST_CHECK( ! value.Get( url ) ); // Value should be empty
653   DALI_TEST_CHECK( ! value.Get( map ) ); // Value should be empty
654
655   // Set an Image
656   ResourceImage image1 = ResourceImage::New( TEST_IMAGE_FILE_NAME );
657   imageView.SetImage( image1 );
658   value = imageView.GetProperty( imageView.GetPropertyIndex( "image" ) );
659
660   DALI_TEST_CHECK( ! value.Get( url ) ); // Value should be empty
661   DALI_TEST_CHECK( value.Get( map ) );   // Value should NOT be empty
662
663   // Set an empty URL
664   imageView.SetImage( "" );
665   value = imageView.GetProperty( imageView.GetPropertyIndex( "image" ) );
666
667   DALI_TEST_CHECK( ! value.Get( url ) ); // Value should be empty
668   DALI_TEST_CHECK( ! value.Get( map ) ); // Value should be empty
669
670   END_TEST;
671 }
672
673 int UtcDaliImageViewResourceUrlP(void)
674 {
675   ToolkitTestApplication application;
676
677   ImageView imageView = ImageView::New();
678   DALI_TEST_CHECK( imageView.GetProperty( ImageView::Property::RESOURCE_URL ).Get< std::string >().empty() );
679
680   imageView.SetProperty( ImageView::Property::RESOURCE_URL, "TestString" );
681   DALI_TEST_EQUALS( imageView.GetProperty( ImageView::Property::RESOURCE_URL ).Get< std::string >(), "TestString", TEST_LOCATION );
682
683   END_TEST;
684 }
685
686 // Scenarios 1: ImageView from regular image
687 int UtcDaliImageViewSetImageBufferImage(void)
688 {
689   ToolkitTestApplication application;
690
691   ImageView imageView = ImageView::New();
692   Stage::GetCurrent().Add( imageView );
693
694   TestGlAbstraction& gl = application.GetGlAbstraction();
695   gl.EnableTextureCallTrace( true );
696
697   std::vector< GLuint > ids;
698   ids.push_back( 23 );
699   application.GetGlAbstraction().SetNextTextureIds( ids );
700
701   int width = 300;
702   int height = 400;
703   BufferImage image = CreateBufferImage( width, height, Color::WHITE );
704
705   imageView.SetImage( image );
706
707   application.SendNotification();
708   application.Render();
709
710   DALI_TEST_CHECK( gl.GetTextureTrace().FindMethod("BindTexture") );
711
712   std::stringstream params;
713   params << GL_TEXTURE_2D << ", " << 23;
714   DALI_TEST_CHECK( gl.GetTextureTrace().FindMethodAndParams("BindTexture", params.str()) );
715
716   END_TEST;
717 }
718
719 // Scenarios 2: ImageView from Native image
720 int UtcDaliImageViewSetImageNativeImage(void)
721 {
722   ToolkitTestApplication application;
723
724   ImageView imageView = ImageView::New();
725   Stage::GetCurrent().Add( imageView );
726
727   TestGlAbstraction& gl = application.GetGlAbstraction();
728   gl.EnableTextureCallTrace( true );
729
730   std::vector< GLuint > ids;
731   ids.push_back( 23 );
732   application.GetGlAbstraction().SetNextTextureIds( ids );
733
734   int width = 200;
735   int height = 500;
736   TestNativeImagePointer nativeImageInterface = TestNativeImage::New( width, height );
737   NativeImage nativeImage = NativeImage::New( *(nativeImageInterface.Get()) );
738
739   imageView.SetImage( nativeImage );
740   application.SendNotification();
741   application.Render();
742
743   DALI_TEST_CHECK( gl.GetTextureTrace().FindMethod("BindTexture") );
744
745   std::stringstream params;
746   params << GL_TEXTURE_2D << ", " << 23;
747   DALI_TEST_CHECK( gl.GetTextureTrace().FindMethodAndParams("BindTexture", params.str()) );
748
749   END_TEST;
750 }
751
752 // Scenarios 3: ImageView initially from regular image but then SetImage called with Native image
753 int UtcDaliImageViewSetImageBufferImageToNativeImage(void)
754 {
755   ToolkitTestApplication application;
756
757   int width = 300;
758   int height = 400;
759   BufferImage image = CreateBufferImage( width, height, Color::WHITE );
760
761   ImageView imageView = ImageView::New( image );
762   Stage::GetCurrent().Add( imageView );
763
764   TestGlAbstraction& gl = application.GetGlAbstraction();
765   gl.EnableTextureCallTrace( true );
766
767   std::vector< GLuint > ids;
768   ids.push_back( 23 );
769   application.GetGlAbstraction().SetNextTextureIds( ids );
770
771   application.SendNotification();
772   application.Render();
773
774   DALI_TEST_CHECK( gl.GetTextureTrace().FindMethod("BindTexture") );
775
776   std::stringstream params;
777   params << GL_TEXTURE_2D << ", " << 23;
778   DALI_TEST_CHECK( gl.GetTextureTrace().FindMethodAndParams("BindTexture", params.str()) );
779
780   width = 200;
781   height = 500;
782   TestNativeImagePointer nativeImageInterface = TestNativeImage::New( width, height );
783   NativeImage nativeImage = NativeImage::New( *(nativeImageInterface.Get()) );
784   imageView.SetImage( nativeImage );
785
786   ids.clear();
787   ids.push_back( 24 );
788   application.GetGlAbstraction().SetNextTextureIds( ids );
789
790   application.SendNotification();
791   application.Render();
792
793   DALI_TEST_CHECK( gl.GetTextureTrace().FindMethod("BindTexture") );
794
795   std::stringstream nextTextureParams;
796   nextTextureParams << GL_TEXTURE_2D << ", " << 24;
797   DALI_TEST_CHECK( gl.GetTextureTrace().FindMethodAndParams("BindTexture", nextTextureParams.str()) );
798
799   END_TEST;
800 }
801
802 // Scenarios 4: ImageView initially from Native image but then SetImage called with regular image
803 int UtcDaliImageViewSetImageNativeImageToBufferImage(void)
804 {
805   ToolkitTestApplication application;
806
807   int width = 300;
808   int height = 400;
809   TestNativeImagePointer nativeImageInterface = TestNativeImage::New( width, height );
810   NativeImage nativeImage = NativeImage::New( *(nativeImageInterface.Get()) );
811
812   ImageView imageView = ImageView::New( nativeImage );
813   Stage::GetCurrent().Add( imageView );
814
815   TestGlAbstraction& gl = application.GetGlAbstraction();
816   gl.EnableTextureCallTrace( true );
817
818   std::vector< GLuint > ids;
819   ids.push_back( 23 );
820   application.GetGlAbstraction().SetNextTextureIds( ids );
821
822   application.SendNotification();
823   application.Render();
824
825   DALI_TEST_CHECK( gl.GetTextureTrace().FindMethod("BindTexture") );
826
827   std::stringstream params;
828   params << GL_TEXTURE_2D << ", " << 23;
829   DALI_TEST_CHECK( gl.GetTextureTrace().FindMethodAndParams("BindTexture", params.str()) );
830
831   width = 200;
832   height = 500;
833   BufferImage image = CreateBufferImage( width, height, Color::WHITE );
834   imageView.SetImage( image );
835
836   ids.clear();
837   ids.push_back( 24 );
838   application.GetGlAbstraction().SetNextTextureIds( ids );
839
840   application.SendNotification();
841   application.Render();
842
843   DALI_TEST_CHECK( gl.GetTextureTrace().FindMethod("BindTexture") );
844
845   std::stringstream nextTextureParams;
846   nextTextureParams << GL_TEXTURE_2D << ", " << 24;
847   DALI_TEST_CHECK( gl.GetTextureTrace().FindMethodAndParams("BindTexture", nextTextureParams.str()) );
848
849   END_TEST;
850 }
851
852 // Scenarios 5: ImageView from Native image with custom shader
853 int UtcDaliImageViewSetImageNativeImageWithCustomShader(void)
854 {
855   ToolkitTestApplication application;
856
857   int width = 300;
858   int height = 400;
859
860   Property::Map customShader;
861   customShader.Insert( "vertexShader", VERTEX_SHADER );
862   customShader.Insert( "fragmentShader", FRAGMENT_SHADER );
863
864   Property::Array shaderHints;
865   shaderHints.PushBack( "requiresSelfDepthTest" );
866   shaderHints.PushBack( "outputIsTransparent" );
867   shaderHints.PushBack( "outputIsOpaque" );
868   shaderHints.PushBack( "modifiesGeometry" );
869
870   customShader.Insert( "hints", shaderHints );
871
872   Property::Map map;
873   map.Insert( "rendererType", "imageRenderer" );
874   map.Insert( "shader", customShader );
875
876   TestNativeImagePointer nativeImageInterface = TestNativeImage::New( width, height );
877   NativeImage nativeImage = NativeImage::New( *(nativeImageInterface.Get()) );
878
879   ImageView imageView = ImageView::New( nativeImage );
880   imageView.SetProperty( ImageView::Property::IMAGE, map );
881   Stage::GetCurrent().Add( imageView );
882
883   imageView.SetProperty( ImageView::Property::IMAGE, map );
884
885   TestGlAbstraction& gl = application.GetGlAbstraction();
886   gl.EnableTextureCallTrace( true );
887
888   std::vector< GLuint > ids;
889   ids.push_back( 23 );
890   application.GetGlAbstraction().SetNextTextureIds( ids );
891
892   application.SendNotification();
893   application.Render();
894
895   DALI_TEST_CHECK( gl.GetTextureTrace().FindMethod("BindTexture") );
896
897   std::stringstream params;
898   params << GL_TEXTURE_2D << ", " << 23;
899   DALI_TEST_CHECK( gl.GetTextureTrace().FindMethodAndParams("BindTexture", params.str()) );
900
901   END_TEST;
902 }
903
904 // Scenarios 6: ImageView initially from regular image with custom shader but then SetImage called with Native
905 int UtcDaliImageViewSetImageBufferImageWithCustomShaderToNativeImage(void)
906 {
907   ToolkitTestApplication application;
908
909   int width = 300;
910   int height = 400;
911
912   Property::Map customShader;
913   customShader.Insert( "vertexShader", VERTEX_SHADER );
914   customShader.Insert( "fragmentShader", FRAGMENT_SHADER );
915
916   Property::Array shaderHints;
917   shaderHints.PushBack( "requiresSelfDepthTest" );
918   shaderHints.PushBack( "outputIsTransparent" );
919   shaderHints.PushBack( "outputIsOpaque" );
920   shaderHints.PushBack( "modifiesGeometry" );
921
922   customShader.Insert( "hints", shaderHints );
923
924   Property::Map map;
925   map.Insert( "rendererType", "imageRenderer" );
926   map.Insert( "shader", customShader );
927
928   BufferImage image = CreateBufferImage( width, height, Color::WHITE );
929
930   ImageView imageView = ImageView::New( image );
931   imageView.SetProperty( ImageView::Property::IMAGE, map );
932   Stage::GetCurrent().Add( imageView );
933
934   imageView.SetProperty( ImageView::Property::IMAGE, map );
935
936   TestGlAbstraction& gl = application.GetGlAbstraction();
937   gl.EnableTextureCallTrace( true );
938
939   std::vector< GLuint > ids;
940   ids.push_back( 23 );
941   application.GetGlAbstraction().SetNextTextureIds( ids );
942
943   application.SendNotification();
944   application.Render();
945
946   DALI_TEST_CHECK( gl.GetTextureTrace().FindMethod("BindTexture") );
947
948   std::stringstream params;
949   params << GL_TEXTURE_2D << ", " << 23;
950   DALI_TEST_CHECK( gl.GetTextureTrace().FindMethodAndParams("BindTexture", params.str()) );
951
952   TestNativeImagePointer nativeImageInterface = TestNativeImage::New( width, height );
953   NativeImage nativeImage = NativeImage::New( *(nativeImageInterface.Get()) );
954   imageView.SetImage( nativeImage );
955
956   ids.clear();
957   ids.push_back( 24 );
958   application.GetGlAbstraction().SetNextTextureIds( ids );
959
960   application.SendNotification();
961   application.Render();
962
963   DALI_TEST_CHECK( gl.GetTextureTrace().FindMethod("BindTexture") );
964
965   std::stringstream nativeImageParams;
966   nativeImageParams << GL_TEXTURE_2D << ", " << 24;
967   DALI_TEST_CHECK( gl.GetTextureTrace().FindMethodAndParams("BindTexture", nativeImageParams.str()) );
968
969
970   END_TEST;
971 }