Blending enum clean-up
[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   Property::Value value = renderer.GetProperty( Renderer::Property::BLEND_PRE_MULTIPLIED_ALPHA );
334   bool enable;
335   DALI_TEST_CHECK( value.Get( enable ) );
336   DALI_TEST_CHECK( !enable );
337
338   // pre-multiplied alpha blending
339   imageView.SetProperty( Toolkit::ImageView::Property::PRE_MULTIPLIED_ALPHA, true );
340   application.SendNotification();
341   application.Render();
342
343   int srcFactorRgb    = renderer.GetProperty<int>( Renderer::Property::BLEND_FACTOR_SRC_RGB );
344   int destFactorRgb   = renderer.GetProperty<int>( Renderer::Property::BLEND_FACTOR_DEST_RGB );
345   int srcFactorAlpha  = renderer.GetProperty<int>( Renderer::Property::BLEND_FACTOR_SRC_ALPHA );
346   int destFactorAlpha = renderer.GetProperty<int>( Renderer::Property::BLEND_FACTOR_DEST_ALPHA );
347   DALI_TEST_CHECK( srcFactorRgb == BlendingFactor::ONE );
348   DALI_TEST_CHECK( destFactorRgb == BlendingFactor::ONE_MINUS_SRC_ALPHA );
349   DALI_TEST_CHECK( srcFactorAlpha == BlendingFactor::ONE );
350   DALI_TEST_CHECK( destFactorAlpha == BlendingFactor::ONE );
351
352   value = renderer.GetProperty( Renderer::Property::BLEND_PRE_MULTIPLIED_ALPHA );
353   DALI_TEST_CHECK( value.Get( enable ) );
354   DALI_TEST_CHECK( enable );
355
356   END_TEST;
357 }
358
359 int UtcDaliImageViewSizeWithBackground(void)
360 {
361   ToolkitTestApplication application;
362
363   int width = 100;
364   int height = 200;
365   Image image = CreateBufferImage( width, height, Vector4(1.f, 1.f, 1.f, 1.f) );
366   ImageView imageView = ImageView::New();
367   imageView.SetBackgroundImage( image );
368
369   Stage::GetCurrent().Add( imageView );
370   application.SendNotification();
371   application.Render();
372
373   DALI_TEST_EQUALS( imageView.GetCurrentSize().width, (float)width, TEST_LOCATION );
374   DALI_TEST_EQUALS( imageView.GetCurrentSize().height, (float)height, TEST_LOCATION );
375
376   END_TEST;
377 }
378
379 int UtcDaliImageViewSizeWithBackgroundAndImage(void)
380 {
381   ToolkitTestApplication application;
382
383   int widthBackground = 100;
384   int heightBackground = 200;
385   int width = 300;
386   int height = 400;
387   Image imageBackground = CreateBufferImage( widthBackground, heightBackground, Vector4(1.f, 1.f, 1.f, 1.f) );
388   Image image = CreateBufferImage( width, height, Vector4(1.f, 1.f, 1.f, 1.f) );
389
390   ImageView imageView = ImageView::New();
391   imageView.SetBackgroundImage( imageBackground );
392   imageView.SetImage( image );
393
394   Stage::GetCurrent().Add( imageView );
395   application.SendNotification();
396   application.Render();
397
398   DALI_TEST_EQUALS( imageView.GetCurrentSize().width, (float)width, TEST_LOCATION );
399   DALI_TEST_EQUALS( imageView.GetCurrentSize().height, (float)height, TEST_LOCATION );
400
401   END_TEST;
402 }
403
404 int UtcDaliImageViewHeightForWidthBackground(void)
405 {
406   ToolkitTestApplication application;
407
408   int widthBackground = 100;
409   int heightBackground = 200;
410   Image imageBackground = CreateBufferImage( widthBackground, heightBackground, Vector4(1.f, 1.f, 1.f, 1.f) );
411
412   ImageView imageView = ImageView::New();
413   imageView.SetBackgroundImage( imageBackground );
414
415   Stage::GetCurrent().Add( imageView );
416   application.SendNotification();
417   application.Render();
418
419   Control control = Control::DownCast( imageView );
420   DALI_TEST_CHECK( control );
421   DALI_TEST_EQUALS( imageView.GetHeightForWidth( 123.f ), control.GetHeightForWidth( 123.f ), TEST_LOCATION );
422   DALI_TEST_EQUALS( imageView.GetWidthForHeight( 321.f ), control.GetWidthForHeight( 321.f ), TEST_LOCATION );
423
424   END_TEST;
425 }
426
427 int UtcDaliImageViewHeightForWidthBackgroundAndImage(void)
428 {
429   ToolkitTestApplication application;
430
431   int widthBackground = 100;
432   int heightBackground = 200;
433   int width = 300;
434   int height = 400;
435   Image imageBackground = CreateBufferImage( widthBackground, heightBackground, Vector4(1.f, 1.f, 1.f, 1.f) );
436   Image image = CreateBufferImage( width, height, Vector4(1.f, 1.f, 1.f, 1.f) );
437
438   ImageView imageView = ImageView::New();
439   imageView.SetBackgroundImage( imageBackground );
440   imageView.SetImage( image );
441
442   Stage::GetCurrent().Add( imageView );
443   application.SendNotification();
444   application.Render();
445
446   DALI_TEST_EQUALS( imageView.GetHeightForWidth( width ), (float)height, TEST_LOCATION );
447   DALI_TEST_EQUALS( imageView.GetWidthForHeight( height ), (float)width, TEST_LOCATION );
448
449   END_TEST;
450 }
451
452 int UtcDaliImageViewSetBufferImage(void)
453 {
454   ToolkitTestApplication application;
455
456   int width1 = 300;
457   int height1 = 400;
458   BufferImage image1 = CreateBufferImage( width1, height1, Vector4( 1.f, 1.f, 1.f, 1.f ) );
459   ImageView imageView = ImageView::New();
460   imageView.SetImage( image1 );
461
462   TestImage( imageView, image1 );
463
464   int width2 = 600;
465   int height2 = 500;
466   BufferImage image2 = CreateBufferImage( width2, height2, Vector4( 1.f, 1.f, 1.f, 1.f ) );
467   imageView.SetImage( image2 );
468
469   TestImage( imageView, image2 );
470
471   END_TEST;
472 }
473
474 int UtcDaliImageViewSetImageUrl(void)
475 {
476   ToolkitTestApplication application;
477
478   ImageView imageView = ImageView::New();
479   imageView.SetImage( TEST_IMAGE_FILE_NAME );
480   TestUrl( imageView, TEST_IMAGE_FILE_NAME );
481
482
483   imageView.SetImage( TEST_IMAGE_FILE_NAME2 );
484   TestUrl( imageView, TEST_IMAGE_FILE_NAME2 );
485
486   END_TEST;
487 }
488
489 int UtcDaliImageViewSetImageOnstageP(void)
490 {
491   ToolkitTestApplication application;
492
493   ImageView imageView = ImageView::New();
494
495   Stage::GetCurrent().Add( imageView );
496   application.SendNotification();
497   application.Render();
498
499   ResourceImage image1 = ResourceImage::New( TEST_IMAGE_FILE_NAME );
500   imageView.SetImage( image1 );
501   TestImage( imageView, image1 );
502
503   int width = 300;
504   int height = 400;
505   BufferImage image2 = CreateBufferImage( width, height, Vector4( 1.f, 1.f, 1.f, 1.f ) );
506   imageView.SetImage( image2 );
507   TestImage( imageView, image2 );
508
509   END_TEST;
510 }
511
512 int UtcDaliImageViewSetImageOnstageN(void)
513 {
514   ToolkitTestApplication application;
515
516   ImageView imageView = ImageView::New();
517
518   Stage::GetCurrent().Add( imageView );
519   application.SendNotification();
520   application.Render();
521
522   ResourceImage image1 = ResourceImage::New( TEST_IMAGE_FILE_NAME );
523   imageView.SetImage( image1 );
524   TestImage( imageView, image1 );
525
526   Image image2;
527   imageView.SetImage( image2 );
528
529   Property::Value value = imageView.GetProperty( imageView.GetPropertyIndex( "image" ) );
530
531   //the value should be empty
532   std::string url;
533   DALI_TEST_CHECK( !value.Get( url ) );
534
535   Property::Map map;
536   DALI_TEST_CHECK( !value.Get( map ) );
537
538   END_TEST;
539 }
540
541 int UtcDaliImageViewSetImageOffstageP(void)
542 {
543   ToolkitTestApplication application;
544
545   ImageView imageView = ImageView::New();
546
547   Stage::GetCurrent().Add( imageView );
548   application.SendNotification();
549   application.Render();
550   Stage::GetCurrent().Remove( imageView );
551
552   ResourceImage image1 = ResourceImage::New( TEST_IMAGE_FILE_NAME );
553   imageView.SetImage( image1 );
554   TestImage( imageView, image1 );
555
556   int width = 300;
557   int height = 400;
558   BufferImage image2 = CreateBufferImage( width, height, Vector4( 1.f, 1.f, 1.f, 1.f ) );
559   imageView.SetImage( image2 );
560   TestImage( imageView, image2 );
561
562   END_TEST;
563 }
564
565 int UtcDaliImageViewSetImageOffstageN(void)
566 {
567   ToolkitTestApplication application;
568
569   ImageView imageView = ImageView::New();
570
571   Stage::GetCurrent().Add( imageView );
572   application.SendNotification();
573   application.Render();
574   Stage::GetCurrent().Remove( imageView );
575
576   ResourceImage image1 = ResourceImage::New( TEST_IMAGE_FILE_NAME );
577   imageView.SetImage( image1 );
578   TestImage( imageView, image1 );
579
580   Image image2;
581   imageView.SetImage( image2 );
582
583   Property::Value value = imageView.GetProperty( imageView.GetPropertyIndex( "image" ) );
584
585   //the value should be empty
586   std::string url;
587   DALI_TEST_CHECK( !value.Get( url ) );
588
589   Property::Map map;
590   DALI_TEST_CHECK( !value.Get( map ) );
591
592   END_TEST;
593 }
594
595 int UtcDaliImageViewSetImageN(void)
596 {
597   ToolkitTestApplication application;
598
599   Image image1;
600   ImageView imageView = ImageView::New();
601   imageView.SetImage( image1 );
602
603   Property::Value value = imageView.GetProperty( imageView.GetPropertyIndex( "image" ) );
604
605   //the value should be empty
606   std::string url;
607   DALI_TEST_CHECK( !value.Get( url ) );
608
609   Property::Map map;
610   DALI_TEST_CHECK( !value.Get( map ) );
611
612   std::string resource_url;
613   Property::Value val = imageView.GetProperty( imageView.GetPropertyIndex( "image" ) );
614   DALI_TEST_CHECK( !val.Get( resource_url ) );
615
616   END_TEST;
617 }
618
619 int UtcDaliImageViewSetImageTypeChangesP(void)
620 {
621   ToolkitTestApplication application;
622
623   ImageView imageView = ImageView::New();
624
625
626   std::string url;
627   Property::Map map;
628
629   Property::Value value = imageView.GetProperty( imageView.GetPropertyIndex( "image" ) );
630   DALI_TEST_CHECK( ! value.Get( url ) ); // Value should be empty
631   DALI_TEST_CHECK( ! value.Get( map ) ); // Value should be empty
632
633   // Set a URL
634   imageView.SetImage( "TEST_URL" );
635   value = imageView.GetProperty( imageView.GetPropertyIndex( "image" ) );
636
637   DALI_TEST_CHECK( value.Get( url ) );   // Value should NOT be empty
638   DALI_TEST_CHECK( ! value.Get( map ) ); // Value should be empty
639
640   // Set an empty Image
641   imageView.SetImage( Image() );
642   value = imageView.GetProperty( imageView.GetPropertyIndex( "image" ) );
643
644   DALI_TEST_CHECK( ! value.Get( url ) ); // Value should be empty
645   DALI_TEST_CHECK( ! value.Get( map ) ); // Value should be empty
646
647   // Set an Image
648   ResourceImage image1 = ResourceImage::New( TEST_IMAGE_FILE_NAME );
649   imageView.SetImage( image1 );
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 NOT be empty
654
655   // Set an empty URL
656   imageView.SetImage( "" );
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 be empty
661
662   END_TEST;
663 }
664
665 int UtcDaliImageViewResourceUrlP(void)
666 {
667   ToolkitTestApplication application;
668
669   ImageView imageView = ImageView::New();
670   DALI_TEST_CHECK( imageView.GetProperty( ImageView::Property::RESOURCE_URL ).Get< std::string >().empty() );
671
672   imageView.SetProperty( ImageView::Property::RESOURCE_URL, "TestString" );
673   DALI_TEST_EQUALS( imageView.GetProperty( ImageView::Property::RESOURCE_URL ).Get< std::string >(), "TestString", TEST_LOCATION );
674
675   END_TEST;
676 }
677
678 // Scenarios 1: ImageView from regular image
679 int UtcDaliImageViewSetImageBufferImage(void)
680 {
681   ToolkitTestApplication application;
682
683   ImageView imageView = ImageView::New();
684   Stage::GetCurrent().Add( imageView );
685
686   TestGlAbstraction& gl = application.GetGlAbstraction();
687   gl.EnableTextureCallTrace( true );
688
689   std::vector< GLuint > ids;
690   ids.push_back( 23 );
691   application.GetGlAbstraction().SetNextTextureIds( ids );
692
693   int width = 300;
694   int height = 400;
695   BufferImage image = CreateBufferImage( width, height, Color::WHITE );
696
697   imageView.SetImage( image );
698
699   application.SendNotification();
700   application.Render();
701
702   DALI_TEST_CHECK( gl.GetTextureTrace().FindMethod("BindTexture") );
703
704   std::stringstream params;
705   params << GL_TEXTURE_2D << ", " << 23;
706   DALI_TEST_CHECK( gl.GetTextureTrace().FindMethodAndParams("BindTexture", params.str()) );
707
708   END_TEST;
709 }
710
711 // Scenarios 2: ImageView from Native image
712 int UtcDaliImageViewSetImageNativeImage(void)
713 {
714   ToolkitTestApplication application;
715
716   ImageView imageView = ImageView::New();
717   Stage::GetCurrent().Add( imageView );
718
719   TestGlAbstraction& gl = application.GetGlAbstraction();
720   gl.EnableTextureCallTrace( true );
721
722   std::vector< GLuint > ids;
723   ids.push_back( 23 );
724   application.GetGlAbstraction().SetNextTextureIds( ids );
725
726   int width = 200;
727   int height = 500;
728   TestNativeImagePointer nativeImageInterface = TestNativeImage::New( width, height );
729   NativeImage nativeImage = NativeImage::New( *(nativeImageInterface.Get()) );
730
731   imageView.SetImage( nativeImage );
732   application.SendNotification();
733   application.Render();
734
735   DALI_TEST_CHECK( gl.GetTextureTrace().FindMethod("BindTexture") );
736
737   std::stringstream params;
738   params << GL_TEXTURE_2D << ", " << 23;
739   DALI_TEST_CHECK( gl.GetTextureTrace().FindMethodAndParams("BindTexture", params.str()) );
740
741   END_TEST;
742 }
743
744 // Scenarios 3: ImageView initially from regular image but then SetImage called with Native image
745 int UtcDaliImageViewSetImageBufferImageToNativeImage(void)
746 {
747   ToolkitTestApplication application;
748
749   int width = 300;
750   int height = 400;
751   BufferImage image = CreateBufferImage( width, height, Color::WHITE );
752
753   ImageView imageView = ImageView::New( image );
754   Stage::GetCurrent().Add( imageView );
755
756   TestGlAbstraction& gl = application.GetGlAbstraction();
757   gl.EnableTextureCallTrace( true );
758
759   std::vector< GLuint > ids;
760   ids.push_back( 23 );
761   application.GetGlAbstraction().SetNextTextureIds( ids );
762
763   application.SendNotification();
764   application.Render();
765
766   DALI_TEST_CHECK( gl.GetTextureTrace().FindMethod("BindTexture") );
767
768   std::stringstream params;
769   params << GL_TEXTURE_2D << ", " << 23;
770   DALI_TEST_CHECK( gl.GetTextureTrace().FindMethodAndParams("BindTexture", params.str()) );
771
772   width = 200;
773   height = 500;
774   TestNativeImagePointer nativeImageInterface = TestNativeImage::New( width, height );
775   NativeImage nativeImage = NativeImage::New( *(nativeImageInterface.Get()) );
776   imageView.SetImage( nativeImage );
777
778   ids.clear();
779   ids.push_back( 24 );
780   application.GetGlAbstraction().SetNextTextureIds( ids );
781
782   application.SendNotification();
783   application.Render();
784
785   DALI_TEST_CHECK( gl.GetTextureTrace().FindMethod("BindTexture") );
786
787   std::stringstream nextTextureParams;
788   nextTextureParams << GL_TEXTURE_2D << ", " << 24;
789   DALI_TEST_CHECK( gl.GetTextureTrace().FindMethodAndParams("BindTexture", nextTextureParams.str()) );
790
791   END_TEST;
792 }
793
794 // Scenarios 4: ImageView initially from Native image but then SetImage called with regular image
795 int UtcDaliImageViewSetImageNativeImageToBufferImage(void)
796 {
797   ToolkitTestApplication application;
798
799   int width = 300;
800   int height = 400;
801   TestNativeImagePointer nativeImageInterface = TestNativeImage::New( width, height );
802   NativeImage nativeImage = NativeImage::New( *(nativeImageInterface.Get()) );
803
804   ImageView imageView = ImageView::New( nativeImage );
805   Stage::GetCurrent().Add( imageView );
806
807   TestGlAbstraction& gl = application.GetGlAbstraction();
808   gl.EnableTextureCallTrace( true );
809
810   std::vector< GLuint > ids;
811   ids.push_back( 23 );
812   application.GetGlAbstraction().SetNextTextureIds( ids );
813
814   application.SendNotification();
815   application.Render();
816
817   DALI_TEST_CHECK( gl.GetTextureTrace().FindMethod("BindTexture") );
818
819   std::stringstream params;
820   params << GL_TEXTURE_2D << ", " << 23;
821   DALI_TEST_CHECK( gl.GetTextureTrace().FindMethodAndParams("BindTexture", params.str()) );
822
823   width = 200;
824   height = 500;
825   BufferImage image = CreateBufferImage( width, height, Color::WHITE );
826   imageView.SetImage( image );
827
828   ids.clear();
829   ids.push_back( 24 );
830   application.GetGlAbstraction().SetNextTextureIds( ids );
831
832   application.SendNotification();
833   application.Render();
834
835   DALI_TEST_CHECK( gl.GetTextureTrace().FindMethod("BindTexture") );
836
837   std::stringstream nextTextureParams;
838   nextTextureParams << GL_TEXTURE_2D << ", " << 24;
839   DALI_TEST_CHECK( gl.GetTextureTrace().FindMethodAndParams("BindTexture", nextTextureParams.str()) );
840
841   END_TEST;
842 }
843
844 // Scenarios 5: ImageView from Native image with custom shader
845 int UtcDaliImageViewSetImageNativeImageWithCustomShader(void)
846 {
847   ToolkitTestApplication application;
848
849   int width = 300;
850   int height = 400;
851
852   Property::Map customShader;
853   customShader.Insert( "vertexShader", VERTEX_SHADER );
854   customShader.Insert( "fragmentShader", FRAGMENT_SHADER );
855
856   Property::Array shaderHints;
857   shaderHints.PushBack( "requiresSelfDepthTest" );
858   shaderHints.PushBack( "outputIsTransparent" );
859   shaderHints.PushBack( "outputIsOpaque" );
860   shaderHints.PushBack( "modifiesGeometry" );
861
862   customShader.Insert( "hints", shaderHints );
863
864   Property::Map map;
865   map.Insert( "rendererType", "image" );
866   map.Insert( "shader", customShader );
867
868   TestNativeImagePointer nativeImageInterface = TestNativeImage::New( width, height );
869   NativeImage nativeImage = NativeImage::New( *(nativeImageInterface.Get()) );
870
871   ImageView imageView = ImageView::New( nativeImage );
872   imageView.SetProperty( ImageView::Property::IMAGE, map );
873   Stage::GetCurrent().Add( imageView );
874
875   imageView.SetProperty( ImageView::Property::IMAGE, map );
876
877   TestGlAbstraction& gl = application.GetGlAbstraction();
878   gl.EnableTextureCallTrace( true );
879
880   std::vector< GLuint > ids;
881   ids.push_back( 23 );
882   application.GetGlAbstraction().SetNextTextureIds( ids );
883
884   application.SendNotification();
885   application.Render();
886
887   DALI_TEST_CHECK( gl.GetTextureTrace().FindMethod("BindTexture") );
888
889   std::stringstream params;
890   params << GL_TEXTURE_2D << ", " << 23;
891   DALI_TEST_CHECK( gl.GetTextureTrace().FindMethodAndParams("BindTexture", params.str()) );
892
893   END_TEST;
894 }
895
896 // Scenarios 6: ImageView initially from regular image with custom shader but then SetImage called with Native
897 int UtcDaliImageViewSetImageBufferImageWithCustomShaderToNativeImage(void)
898 {
899   ToolkitTestApplication application;
900
901   int width = 300;
902   int height = 400;
903
904   Property::Map customShader;
905   customShader.Insert( "vertexShader", VERTEX_SHADER );
906   customShader.Insert( "fragmentShader", FRAGMENT_SHADER );
907
908   Property::Array shaderHints;
909   shaderHints.PushBack( "requiresSelfDepthTest" );
910   shaderHints.PushBack( "outputIsTransparent" );
911   shaderHints.PushBack( "outputIsOpaque" );
912   shaderHints.PushBack( "modifiesGeometry" );
913
914   customShader.Insert( "hints", shaderHints );
915
916   Property::Map map;
917   map.Insert( "rendererType", "image" );
918   map.Insert( "shader", customShader );
919
920   BufferImage image = CreateBufferImage( width, height, Color::WHITE );
921
922   ImageView imageView = ImageView::New( image );
923   imageView.SetProperty( ImageView::Property::IMAGE, map );
924   Stage::GetCurrent().Add( imageView );
925
926   imageView.SetProperty( ImageView::Property::IMAGE, map );
927
928   TestGlAbstraction& gl = application.GetGlAbstraction();
929   gl.EnableTextureCallTrace( true );
930
931   std::vector< GLuint > ids;
932   ids.push_back( 23 );
933   application.GetGlAbstraction().SetNextTextureIds( ids );
934
935   application.SendNotification();
936   application.Render();
937
938   DALI_TEST_CHECK( gl.GetTextureTrace().FindMethod("BindTexture") );
939
940   std::stringstream params;
941   params << GL_TEXTURE_2D << ", " << 23;
942   DALI_TEST_CHECK( gl.GetTextureTrace().FindMethodAndParams("BindTexture", params.str()) );
943
944   TestNativeImagePointer nativeImageInterface = TestNativeImage::New( width, height );
945   NativeImage nativeImage = NativeImage::New( *(nativeImageInterface.Get()) );
946   imageView.SetImage( nativeImage );
947
948   ids.clear();
949   ids.push_back( 24 );
950   application.GetGlAbstraction().SetNextTextureIds( ids );
951
952   application.SendNotification();
953   application.Render();
954
955   DALI_TEST_CHECK( gl.GetTextureTrace().FindMethod("BindTexture") );
956
957   std::stringstream nativeImageParams;
958   nativeImageParams << GL_TEXTURE_2D << ", " << 24;
959   DALI_TEST_CHECK( gl.GetTextureTrace().FindMethodAndParams("BindTexture", nativeImageParams.str()) );
960
961
962   END_TEST;
963 }
964
965 int UtcDaliImageViewGetImageP1(void)
966 {
967   ToolkitTestApplication application;
968
969   ImageView imageView = ImageView::New();
970   DALI_TEST_CHECK( ! imageView.GetImage() );
971
972   Image image = CreateBufferImage();
973   imageView.SetImage( image );
974   DALI_TEST_CHECK( imageView.GetImage() == image );
975
976   END_TEST;
977 }
978
979 int UtcDaliImageViewGetImageP2(void)
980 {
981   ToolkitTestApplication application;
982
983   BufferImage image = CreateBufferImage();
984   ImageView imageView = ImageView::New( image );
985   DALI_TEST_CHECK( imageView.GetImage() == image );
986
987   END_TEST;
988 }
989
990 int UtcDaliImageViewGetImageN(void)
991 {
992   ToolkitTestApplication application;
993
994   ImageView imageView = ImageView::New( TEST_IMAGE_FILE_NAME );
995   DALI_TEST_CHECK( ! imageView.GetImage() );
996
997   Image image = CreateBufferImage();
998   imageView.SetImage( image );
999   DALI_TEST_CHECK( imageView.GetImage() == image );
1000
1001   imageView.SetImage( TEST_IMAGE_FILE_NAME );
1002   DALI_TEST_CHECK( ! imageView.GetImage() );
1003
1004   END_TEST;
1005 }
1006