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