Merge "Install default-feedback-theme.json files in styles folder" into devel/master
[platform/core/uifw/dali-toolkit.git] / automated-tests / src / dali-toolkit / utc-Dali-ImageView.cpp
1 /*
2  * Copyright (c) 2016 Samsung Electronics Co., Ltd.
3  *
4  * Licensed under the Apache License, Version 2.0 (the "License");
5  * you may not use this file except in compliance with the License.
6  * You may obtain a copy of the License at
7  *
8  * http://www.apache.org/licenses/LICENSE-2.0
9  *
10  * Unless required by applicable law or agreed to in writing, software
11  * distributed under the License is distributed on an "AS IS" BASIS,
12  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13  * See the License for the specific language governing permissions and
14  * limitations under the License.
15  *
16  */
17
18 // Need to override adaptor classes for toolkit test harness, so include
19 // test harness headers before dali headers.
20 #include <dali-toolkit-test-suite-utils.h>
21 #include <toolkit-bitmap-loader.h>
22 #include <toolkit-event-thread-callback.h>
23
24 #include <dali-toolkit/dali-toolkit.h>
25 #include <dali/devel-api/scripting/scripting.h>
26 #include <dali/public-api/rendering/renderer.h>
27
28 #include <test-native-image.h>
29 #include <sstream>
30
31 using namespace Dali;
32 using namespace Toolkit;
33
34 void utc_dali_toolkit_image_view_startup(void)
35 {
36   test_return_value = TET_UNDEF;
37 }
38
39 void utc_dali_toolkit_image_view_cleanup(void)
40 {
41   test_return_value = TET_PASS;
42 }
43
44 namespace
45 {
46
47 const char* VERTEX_SHADER = DALI_COMPOSE_SHADER(
48   attribute mediump vec2 aPosition;\n
49   varying mediump vec2 vTexCoord;\n
50   uniform mediump mat4 uMvpMatrix;\n
51   uniform mediump vec3 uSize;\n
52   \n
53   void main()\n
54   {\n
55     mediump vec4 vertexPosition = vec4(aPosition, 0.0, 1.0);\n
56     vertexPosition.xyz *= uSize;\n
57     vertexPosition = uMvpMatrix * vertexPosition;\n
58     \n
59     vTexCoord = aPosition + vec2(0.5);\n
60     gl_Position = vertexPosition;\n
61   }\n
62 );
63
64 const char* FRAGMENT_SHADER = DALI_COMPOSE_SHADER(
65   varying mediump vec2 vTexCoord;\n
66   uniform sampler2D sTexture;\n
67   uniform lowp vec4 uColor;\n
68   \n
69   void main()\n
70   {\n
71     gl_FragColor = texture2D( sTexture, vTexCoord ) * uColor;\n
72   }\n
73 );
74
75 const char* TEST_IMAGE_FILE_NAME =  "gallery_image_01.jpg";
76 const char* TEST_IMAGE_FILE_NAME2 =  "gallery_image_02.jpg";
77
78 // resolution: 34*34, pixel format: RGBA8888
79 static const char* gImage_34_RGBA = TEST_RESOURCE_DIR "/icon-edit.png";
80 // resolution: 600*600, pixel format: RGB888
81 static const char* gImage_600_RGB = TEST_RESOURCE_DIR "/test-image-600.jpg";
82
83 void TestImage( ImageView imageView, BufferImage image )
84 {
85   Property::Value value = imageView.GetProperty( imageView.GetPropertyIndex( "image" ) );
86
87   Property::Map map;
88   DALI_TEST_CHECK( value.Get( map ) );
89
90   DALI_TEST_CHECK( map.Find( "width" ) );
91   DALI_TEST_CHECK( map.Find( "height" ) );
92   DALI_TEST_CHECK( map.Find( "type" ) );
93
94   int width = 0;
95   DALI_TEST_CHECK( map[ "width" ].Get( width ) );
96   DALI_TEST_EQUALS( (unsigned int)width, image.GetWidth(), TEST_LOCATION );
97
98   int height = 0;
99   DALI_TEST_CHECK( map[ "height" ].Get( height ) );
100   DALI_TEST_EQUALS( (unsigned int)height, image.GetHeight(), TEST_LOCATION );
101
102   std::string type;
103   DALI_TEST_CHECK( map[ "type" ].Get( type ) );
104   DALI_TEST_EQUALS( type, "BufferImage", TEST_LOCATION );
105 }
106
107 void TestImage( ImageView imageView, ResourceImage image )
108 {
109   Property::Value value = imageView.GetProperty( imageView.GetPropertyIndex( "image" ) );
110
111   Property::Map map;
112   DALI_TEST_CHECK( value.Get( map ) );
113
114   if( map.Find( "width" ) )
115   {
116     int width = 0;
117     DALI_TEST_CHECK( map[ "width" ].Get( width ) );
118     DALI_TEST_EQUALS( (unsigned int)width, image.GetWidth(), TEST_LOCATION );
119   }
120
121   if( map.Find( "height" ) )
122   {
123     int height = 0;
124     DALI_TEST_CHECK( map[ "height" ].Get( height ) );
125     DALI_TEST_EQUALS( (unsigned int)height, image.GetHeight(), TEST_LOCATION );
126   }
127
128   DALI_TEST_CHECK( map.Find( "type" ) );
129
130   std::string type;
131   DALI_TEST_CHECK( map[ "type" ].Get( type ) );
132   DALI_TEST_EQUALS( type, "ResourceImage", TEST_LOCATION );
133
134   std::string filename;
135   DALI_TEST_CHECK( map[ "filename" ].Get( filename ) );
136   DALI_TEST_EQUALS( filename, image.GetUrl(), TEST_LOCATION );
137 }
138
139 void TestUrl( ImageView imageView, const std::string url )
140 {
141   Property::Value value = imageView.GetProperty( imageView.GetPropertyIndex( "image" ) );
142
143   std::string urlActual;
144   DALI_TEST_CHECK( value.Get( urlActual ) );
145   DALI_TEST_EQUALS( urlActual, url, TEST_LOCATION );
146 }
147
148 } // namespace
149
150 int UtcDaliImageViewNewP(void)
151 {
152   TestApplication application;
153
154   ImageView imageView = ImageView::New();
155
156   DALI_TEST_CHECK( imageView );
157
158   END_TEST;
159 }
160
161 int UtcDaliImageViewNewImageP(void)
162 {
163   TestApplication application;
164
165   BufferImage image = CreateBufferImage( 100, 200, Vector4( 1.f, 1.f, 1.f, 1.f ) );
166   ImageView imageView = ImageView::New( image );
167
168   DALI_TEST_CHECK( imageView );
169   TestImage( imageView, image );
170
171   END_TEST;
172 }
173
174 int UtcDaliImageViewNewUrlP(void)
175 {
176   TestApplication application;
177
178   ImageView imageView = ImageView::New( TEST_IMAGE_FILE_NAME );
179   DALI_TEST_CHECK( imageView );
180
181   TestUrl( imageView, TEST_IMAGE_FILE_NAME );
182
183   END_TEST;
184 }
185
186 int UtcDaliImageViewConstructorP(void)
187 {
188   TestApplication application;
189
190   ImageView imageView;
191
192   DALI_TEST_CHECK( !imageView );
193
194   END_TEST;
195 }
196
197 int UtcDaliImageViewCopyConstructorP(void)
198 {
199   TestApplication application;
200
201   // Initialize an object, ref count == 1
202   ImageView imageView = ImageView::New();
203
204   ImageView copy( imageView );
205   DALI_TEST_CHECK( copy );
206
207   END_TEST;
208 }
209
210 int UtcDaliImageViewAssignmentOperatorP(void)
211 {
212   TestApplication application;
213
214   ImageView imageView = ImageView::New();
215
216   ImageView copy( imageView );
217   DALI_TEST_CHECK( copy );
218   DALI_TEST_EQUALS( imageView, copy, TEST_LOCATION );
219
220   END_TEST;
221 }
222
223 int UtcDaliImageViewDownCastP(void)
224 {
225   TestApplication application;
226
227   ImageView imageView = ImageView::New();
228
229   BaseHandle object(imageView);
230
231   ImageView imageView2 = ImageView::DownCast( object );
232   DALI_TEST_CHECK(imageView2);
233
234   ImageView imageView3 = DownCast< ImageView >( object );
235   DALI_TEST_CHECK(imageView3);
236
237   END_TEST;
238 }
239
240 int UtcDaliImageViewDownCastN(void)
241 {
242   TestApplication application;
243
244   BaseHandle unInitializedObject;
245
246   ImageView imageView1 = ImageView::DownCast( unInitializedObject );
247   DALI_TEST_CHECK( !imageView1 );
248
249   ImageView imageView2 = DownCast< ImageView >( unInitializedObject );
250   DALI_TEST_CHECK( !imageView2 );
251
252   END_TEST;
253 }
254
255 int UtcDaliImageViewTypeRegistry(void)
256 {
257   ToolkitTestApplication application;
258
259   TypeRegistry typeRegistry = TypeRegistry::Get();
260   DALI_TEST_CHECK( typeRegistry );
261
262   TypeInfo typeInfo = typeRegistry.GetTypeInfo( "ImageView" );
263   DALI_TEST_CHECK( typeInfo );
264
265   BaseHandle handle = typeInfo.CreateInstance();
266   DALI_TEST_CHECK( handle );
267
268   ImageView imageView = ImageView::DownCast( handle );
269   DALI_TEST_CHECK( imageView );
270
271   END_TEST;
272 }
273
274 int UtcDaliImageViewSetGetProperty01(void)
275 {
276   ToolkitTestApplication application;
277
278   ImageView imageView = ImageView::New();
279
280   Property::Index idx = imageView.GetPropertyIndex( "image" );
281   DALI_TEST_EQUALS( idx, (Property::Index)ImageView::Property::IMAGE, TEST_LOCATION );
282
283   imageView.SetProperty( idx, TEST_IMAGE_FILE_NAME );
284   TestUrl( imageView, TEST_IMAGE_FILE_NAME );
285
286   END_TEST;
287 }
288
289 int UtcDaliImageViewSetGetProperty02(void)
290 {
291   ToolkitTestApplication application;
292
293   Image image = CreateBufferImage( 10, 10, Color::WHITE );
294   ImageView imageView = ImageView::New(image);
295   Vector4 fullImageRect( 0.f, 0.f, 1.f, 1.f );
296
297   Stage::GetCurrent().Add( imageView );
298
299   application.SendNotification();
300   application.Render();
301   TestGlAbstraction& gl = application.GetGlAbstraction();
302
303   Vector4 pixelAreaUniform;
304   DALI_TEST_CHECK( gl.GetUniformValue<Vector4>( "pixelArea", pixelAreaUniform ) );
305   DALI_TEST_EQUALS( pixelAreaUniform, fullImageRect, TEST_LOCATION );
306
307   Property::Value value = imageView.GetProperty( ImageView::Property::PIXEL_AREA );
308   Vector4 pixelAreaValue;
309   DALI_TEST_CHECK( value.Get(pixelAreaValue) );
310   DALI_TEST_EQUALS( pixelAreaValue, fullImageRect, TEST_LOCATION );
311
312   Vector4 pixelAreaSet( 0.2f, 0.2f, 0.3f, 0.3f );
313   imageView.SetProperty( ImageView::Property::PIXEL_AREA, pixelAreaSet);
314
315   application.SendNotification();
316   application.Render();
317
318   value = imageView.GetProperty( ImageView::Property::PIXEL_AREA );
319   value.Get(pixelAreaValue);
320   DALI_TEST_EQUALS( pixelAreaValue, pixelAreaSet, TEST_LOCATION );
321
322   DALI_TEST_CHECK( gl.GetUniformValue<Vector4>( "pixelArea", pixelAreaUniform ) );
323   DALI_TEST_EQUALS( pixelAreaUniform, pixelAreaSet, TEST_LOCATION );
324
325   END_TEST;
326 }
327
328 int UtcDaliImageViewSetGetProperty03(void)
329 {
330   ToolkitTestApplication application;
331
332   Image image = CreateBufferImage( 10, 10, Color::WHITE );
333   ImageView imageView = ImageView::New(image);
334   Stage::GetCurrent().Add( imageView );
335   application.SendNotification();
336   application.Render();
337
338   // conventional alpha blending
339   Renderer renderer = imageView.GetRendererAt( 0 );
340   Property::Value value = renderer.GetProperty( Renderer::Property::BLEND_PRE_MULTIPLIED_ALPHA );
341   bool enable;
342   DALI_TEST_CHECK( value.Get( enable ) );
343   DALI_TEST_CHECK( !enable );
344
345   // pre-multiplied alpha blending
346   imageView.SetProperty( Toolkit::ImageView::Property::PRE_MULTIPLIED_ALPHA, true );
347   application.SendNotification();
348   application.Render();
349
350   int srcFactorRgb    = renderer.GetProperty<int>( Renderer::Property::BLEND_FACTOR_SRC_RGB );
351   int destFactorRgb   = renderer.GetProperty<int>( Renderer::Property::BLEND_FACTOR_DEST_RGB );
352   int srcFactorAlpha  = renderer.GetProperty<int>( Renderer::Property::BLEND_FACTOR_SRC_ALPHA );
353   int destFactorAlpha = renderer.GetProperty<int>( Renderer::Property::BLEND_FACTOR_DEST_ALPHA );
354   DALI_TEST_CHECK( srcFactorRgb == BlendFactor::ONE );
355   DALI_TEST_CHECK( destFactorRgb == BlendFactor::ONE_MINUS_SRC_ALPHA );
356   DALI_TEST_CHECK( srcFactorAlpha == BlendFactor::ONE );
357   DALI_TEST_CHECK( destFactorAlpha == BlendFactor::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 UtcDaliImageViewAsyncLoadingWithoutAltasing(void)
367 {
368   ToolkitTestApplication application;
369
370   // Async loading, no atlasing for big size image
371   ImageView imageView = ImageView::New( gImage_600_RGB );
372
373   // By default, Aysnc loading is used
374   Stage::GetCurrent().Add( imageView );
375   application.SendNotification();
376   application.Render(16);
377   application.Render(16);
378   application.SendNotification();
379
380   // BitmapLoader is not used
381   BitmapLoader loader = BitmapLoader::GetLatestCreated();
382   DALI_TEST_CHECK( !loader );
383
384   END_TEST;
385 }
386
387 int UtcDaliImageViewAsyncLoadingWithAltasing(void)
388 {
389   ToolkitTestApplication application;
390
391   //Async loading, automatic atlasing for small size image
392   TraceCallStack& callStack = application.GetGlAbstraction().GetTextureTrace();
393   callStack.Reset();
394   callStack.Enable(true);
395
396   ImageView imageView = ImageView::New( gImage_34_RGBA, ImageDimensions( 34, 34 ) );
397
398   // By default, Aysnc loading is used
399   // loading is not started if the actor is offStage
400   BitmapLoader loader = BitmapLoader::GetLatestCreated();
401   DALI_TEST_CHECK( !loader );
402
403   Stage::GetCurrent().Add( imageView );
404   application.SendNotification();
405   application.Render(16);
406   application.Render(16);
407   application.SendNotification();
408
409   // loading started
410   loader = BitmapLoader::GetLatestCreated();
411   DALI_TEST_CHECK( loader );
412
413   // worker thread is created
414   EventThreadCallback* eventTrigger = EventThreadCallback::Get();
415   DALI_TEST_CHECK( eventTrigger );
416
417   loader.WaitForLoading();// waiting until the image to be loaded
418   DALI_TEST_CHECK( loader.IsLoaded() );
419
420   eventTrigger->WaitingForTrigger( 1 );
421   CallbackBase* callback = eventTrigger->GetCallback();
422   CallbackBase::Execute( *callback );
423
424   application.SendNotification();
425   application.Render(16);
426
427   callStack.Enable(false);
428
429   TraceCallStack::NamedParams params;
430   params["width"] = ToString(34);
431   params["height"] = ToString(34);
432   DALI_TEST_EQUALS( callStack.FindMethodAndParams( "TexSubImage2D", params ), true, TEST_LOCATION );
433
434   END_TEST;
435 }
436
437 int UtcDaliImageViewSyncLoading(void)
438 {
439   ToolkitTestApplication application;
440
441   Property::Map syncLoadingMap;
442   syncLoadingMap[ "synchronousLoading" ] = true;
443
444   // Sync loading, no atlasing for big size image
445   {
446     ImageView imageView = ImageView::New();
447
448     // Sync loading is used
449     syncLoadingMap[ ImageVisual::Property::URL ] = gImage_600_RGB;
450     imageView.SetProperty( ImageView::Property::IMAGE, syncLoadingMap );
451
452     // BitmapLoader is used, and the loading is started immediately even the actor is not on stage.
453     BitmapLoader loader = BitmapLoader::GetLatestCreated();
454     DALI_TEST_CHECK( loader );
455   }
456
457   // Sync loading, automatic atlasing for small size image
458   {
459     BitmapLoader::ResetLatestCreated();
460     TraceCallStack& callStack = application.GetGlAbstraction().GetTextureTrace();
461     callStack.Reset();
462     callStack.Enable(true);
463
464     ImageView imageView = ImageView::New( );
465     // Sync loading is used
466     syncLoadingMap[ ImageVisual::Property::URL ] = gImage_34_RGBA;
467     syncLoadingMap[ ImageVisual::Property::DESIRED_HEIGHT ] = 34;
468     syncLoadingMap[ ImageVisual::Property::DESIRED_WIDTH ] = 34;
469     imageView.SetProperty( ImageView::Property::IMAGE, syncLoadingMap );
470
471     // loading is started even if the actor is offStage
472     BitmapLoader loader = BitmapLoader::GetLatestCreated();
473     DALI_TEST_CHECK( loader );
474
475     loader.WaitForLoading();
476
477     DALI_TEST_CHECK( loader.IsLoaded() );
478
479     Stage::GetCurrent().Add( imageView );
480     application.SendNotification();
481     application.Render(16);
482
483     TraceCallStack::NamedParams params;
484     params["width"] = ToString(34);
485     params["height"] = ToString(34);
486     DALI_TEST_EQUALS( callStack.FindMethodAndParams( "TexSubImage2D", params ),
487                       true, TEST_LOCATION );
488   }
489   END_TEST;
490 }
491
492 int UtcDaliImageViewSizeWithBackground(void)
493 {
494   ToolkitTestApplication application;
495
496   int width = 100;
497   int height = 200;
498   Image image = CreateBufferImage( width, height, Vector4(1.f, 1.f, 1.f, 1.f) );
499   ImageView imageView = ImageView::New();
500   imageView.SetBackgroundImage( image );
501
502   Stage::GetCurrent().Add( imageView );
503   application.SendNotification();
504   application.Render();
505
506   DALI_TEST_EQUALS( imageView.GetCurrentSize().width, (float)width, TEST_LOCATION );
507   DALI_TEST_EQUALS( imageView.GetCurrentSize().height, (float)height, TEST_LOCATION );
508
509   END_TEST;
510 }
511
512 int UtcDaliImageViewSizeWithBackgroundAndImage(void)
513 {
514   ToolkitTestApplication application;
515
516   int widthBackground = 100;
517   int heightBackground = 200;
518   int width = 300;
519   int height = 400;
520   Image imageBackground = CreateBufferImage( widthBackground, heightBackground, Vector4(1.f, 1.f, 1.f, 1.f) );
521   Image image = CreateBufferImage( width, height, Vector4(1.f, 1.f, 1.f, 1.f) );
522
523   ImageView imageView = ImageView::New();
524   imageView.SetBackgroundImage( imageBackground );
525   imageView.SetImage( image );
526
527   Stage::GetCurrent().Add( imageView );
528   application.SendNotification();
529   application.Render();
530
531   DALI_TEST_EQUALS( imageView.GetCurrentSize().width, (float)width, TEST_LOCATION );
532   DALI_TEST_EQUALS( imageView.GetCurrentSize().height, (float)height, TEST_LOCATION );
533
534   END_TEST;
535 }
536
537 int UtcDaliImageViewHeightForWidthBackground(void)
538 {
539   ToolkitTestApplication application;
540
541   int widthBackground = 100;
542   int heightBackground = 200;
543   Image imageBackground = CreateBufferImage( widthBackground, heightBackground, Vector4(1.f, 1.f, 1.f, 1.f) );
544
545   ImageView imageView = ImageView::New();
546   imageView.SetBackgroundImage( imageBackground );
547
548   Stage::GetCurrent().Add( imageView );
549   application.SendNotification();
550   application.Render();
551
552   Control control = Control::DownCast( imageView );
553   DALI_TEST_CHECK( control );
554   DALI_TEST_EQUALS( imageView.GetHeightForWidth( 123.f ), control.GetHeightForWidth( 123.f ), TEST_LOCATION );
555   DALI_TEST_EQUALS( imageView.GetWidthForHeight( 321.f ), control.GetWidthForHeight( 321.f ), TEST_LOCATION );
556
557   END_TEST;
558 }
559
560 int UtcDaliImageViewHeightForWidthBackgroundAndImage(void)
561 {
562   ToolkitTestApplication application;
563
564   int widthBackground = 100;
565   int heightBackground = 200;
566   int width = 300;
567   int height = 400;
568   Image imageBackground = CreateBufferImage( widthBackground, heightBackground, Vector4(1.f, 1.f, 1.f, 1.f) );
569   Image image = CreateBufferImage( width, height, Vector4(1.f, 1.f, 1.f, 1.f) );
570
571   ImageView imageView = ImageView::New();
572   imageView.SetBackgroundImage( imageBackground );
573   imageView.SetImage( image );
574
575   Stage::GetCurrent().Add( imageView );
576   application.SendNotification();
577   application.Render();
578
579   DALI_TEST_EQUALS( imageView.GetHeightForWidth( width ), (float)height, TEST_LOCATION );
580   DALI_TEST_EQUALS( imageView.GetWidthForHeight( height ), (float)width, TEST_LOCATION );
581
582   END_TEST;
583 }
584
585 int UtcDaliImageViewSetBufferImage(void)
586 {
587   ToolkitTestApplication application;
588
589   int width1 = 300;
590   int height1 = 400;
591   BufferImage image1 = CreateBufferImage( width1, height1, Vector4( 1.f, 1.f, 1.f, 1.f ) );
592   ImageView imageView = ImageView::New();
593   imageView.SetImage( image1 );
594
595   TestImage( imageView, image1 );
596
597   int width2 = 600;
598   int height2 = 500;
599   BufferImage image2 = CreateBufferImage( width2, height2, Vector4( 1.f, 1.f, 1.f, 1.f ) );
600   imageView.SetImage( image2 );
601
602   TestImage( imageView, image2 );
603
604   END_TEST;
605 }
606
607 int UtcDaliImageViewSetImageUrl(void)
608 {
609   ToolkitTestApplication application;
610
611   ImageView imageView = ImageView::New();
612   imageView.SetImage( TEST_IMAGE_FILE_NAME );
613   TestUrl( imageView, TEST_IMAGE_FILE_NAME );
614
615
616   imageView.SetImage( TEST_IMAGE_FILE_NAME2 );
617   TestUrl( imageView, TEST_IMAGE_FILE_NAME2 );
618
619   END_TEST;
620 }
621
622 int UtcDaliImageViewSetImageOnstageP(void)
623 {
624   ToolkitTestApplication application;
625
626   ImageView imageView = ImageView::New();
627
628   Stage::GetCurrent().Add( imageView );
629   application.SendNotification();
630   application.Render();
631
632   ResourceImage image1 = ResourceImage::New( TEST_IMAGE_FILE_NAME );
633   imageView.SetImage( image1 );
634   TestImage( imageView, image1 );
635
636   int width = 300;
637   int height = 400;
638   BufferImage image2 = CreateBufferImage( width, height, Vector4( 1.f, 1.f, 1.f, 1.f ) );
639   imageView.SetImage( image2 );
640   TestImage( imageView, image2 );
641
642   END_TEST;
643 }
644
645 int UtcDaliImageViewSetImageOnstageN(void)
646 {
647   ToolkitTestApplication application;
648
649   ImageView imageView = ImageView::New();
650
651   Stage::GetCurrent().Add( imageView );
652   application.SendNotification();
653   application.Render();
654
655   ResourceImage image1 = ResourceImage::New( TEST_IMAGE_FILE_NAME );
656   imageView.SetImage( image1 );
657   TestImage( imageView, image1 );
658
659   Image image2;
660   imageView.SetImage( image2 );
661
662   Property::Value value = imageView.GetProperty( imageView.GetPropertyIndex( "image" ) );
663
664   //the value should be empty
665   std::string url;
666   DALI_TEST_CHECK( !value.Get( url ) );
667
668   Property::Map map;
669   DALI_TEST_CHECK( !value.Get( map ) );
670
671   END_TEST;
672 }
673
674 int UtcDaliImageViewSetImageOffstageP(void)
675 {
676   ToolkitTestApplication application;
677
678   ImageView imageView = ImageView::New();
679
680   Stage::GetCurrent().Add( imageView );
681   application.SendNotification();
682   application.Render();
683   Stage::GetCurrent().Remove( imageView );
684
685   ResourceImage image1 = ResourceImage::New( TEST_IMAGE_FILE_NAME );
686   imageView.SetImage( image1 );
687   TestImage( imageView, image1 );
688
689   int width = 300;
690   int height = 400;
691   BufferImage image2 = CreateBufferImage( width, height, Vector4( 1.f, 1.f, 1.f, 1.f ) );
692   imageView.SetImage( image2 );
693   TestImage( imageView, image2 );
694
695   END_TEST;
696 }
697
698 int UtcDaliImageViewSetImageOffstageN(void)
699 {
700   ToolkitTestApplication application;
701
702   ImageView imageView = ImageView::New();
703
704   Stage::GetCurrent().Add( imageView );
705   application.SendNotification();
706   application.Render();
707   Stage::GetCurrent().Remove( imageView );
708
709   ResourceImage image1 = ResourceImage::New( TEST_IMAGE_FILE_NAME );
710   imageView.SetImage( image1 );
711   TestImage( imageView, image1 );
712
713   Image image2;
714   imageView.SetImage( image2 );
715
716   Property::Value value = imageView.GetProperty( imageView.GetPropertyIndex( "image" ) );
717
718   //the value should be empty
719   std::string url;
720   DALI_TEST_CHECK( !value.Get( url ) );
721
722   Property::Map map;
723   DALI_TEST_CHECK( !value.Get( map ) );
724
725   END_TEST;
726 }
727
728 int UtcDaliImageViewSetImageN(void)
729 {
730   ToolkitTestApplication application;
731
732   Image image1;
733   ImageView imageView = ImageView::New();
734   imageView.SetImage( image1 );
735
736   Property::Value value = imageView.GetProperty( imageView.GetPropertyIndex( "image" ) );
737
738   //the value should be empty
739   std::string url;
740   DALI_TEST_CHECK( !value.Get( url ) );
741
742   Property::Map map;
743   DALI_TEST_CHECK( !value.Get( map ) );
744
745   std::string resource_url;
746   Property::Value val = imageView.GetProperty( imageView.GetPropertyIndex( "image" ) );
747   DALI_TEST_CHECK( !val.Get( resource_url ) );
748
749   END_TEST;
750 }
751
752 int UtcDaliImageViewSetImageTypeChangesP(void)
753 {
754   ToolkitTestApplication application;
755
756   ImageView imageView = ImageView::New();
757
758
759   std::string url;
760   Property::Map map;
761
762   Property::Value value = imageView.GetProperty( imageView.GetPropertyIndex( "image" ) );
763   DALI_TEST_CHECK( ! value.Get( url ) ); // Value should be empty
764   DALI_TEST_CHECK( ! value.Get( map ) ); // Value should be empty
765
766   // Set a URL
767   imageView.SetImage( "TEST_URL" );
768   value = imageView.GetProperty( imageView.GetPropertyIndex( "image" ) );
769
770   DALI_TEST_CHECK( value.Get( url ) );   // Value should NOT be empty
771   DALI_TEST_CHECK( ! value.Get( map ) ); // Value should be empty
772
773   // Set an empty Image
774   imageView.SetImage( Image() );
775   value = imageView.GetProperty( imageView.GetPropertyIndex( "image" ) );
776
777   DALI_TEST_CHECK( ! value.Get( url ) ); // Value should be empty
778   DALI_TEST_CHECK( ! value.Get( map ) ); // Value should be empty
779
780   // Set an Image
781   ResourceImage image1 = ResourceImage::New( TEST_IMAGE_FILE_NAME );
782   imageView.SetImage( image1 );
783   value = imageView.GetProperty( imageView.GetPropertyIndex( "image" ) );
784
785   DALI_TEST_CHECK( ! value.Get( url ) ); // Value should be empty
786   DALI_TEST_CHECK( value.Get( map ) );   // Value should NOT be empty
787
788   // Set an empty URL
789   imageView.SetImage( "" );
790   value = imageView.GetProperty( imageView.GetPropertyIndex( "image" ) );
791
792   DALI_TEST_CHECK( ! value.Get( url ) ); // Value should be empty
793   DALI_TEST_CHECK( ! value.Get( map ) ); // Value should be empty
794
795   END_TEST;
796 }
797
798 int UtcDaliImageViewResourceUrlP(void)
799 {
800   ToolkitTestApplication application;
801
802   ImageView imageView = ImageView::New();
803   DALI_TEST_CHECK( imageView.GetProperty( ImageView::Property::RESOURCE_URL ).Get< std::string >().empty() );
804
805   imageView.SetProperty( ImageView::Property::RESOURCE_URL, "TestString" );
806   DALI_TEST_EQUALS( imageView.GetProperty( ImageView::Property::RESOURCE_URL ).Get< std::string >(), "TestString", TEST_LOCATION );
807
808   END_TEST;
809 }
810
811 // Scenarios 1: ImageView from regular image
812 int UtcDaliImageViewSetImageBufferImage(void)
813 {
814   ToolkitTestApplication application;
815
816   ImageView imageView = ImageView::New();
817   Stage::GetCurrent().Add( imageView );
818
819   TestGlAbstraction& gl = application.GetGlAbstraction();
820   gl.EnableTextureCallTrace( true );
821
822   std::vector< GLuint > ids;
823   ids.push_back( 23 );
824   application.GetGlAbstraction().SetNextTextureIds( ids );
825
826   int width = 300;
827   int height = 400;
828   BufferImage image = CreateBufferImage( width, height, Color::WHITE );
829
830   imageView.SetImage( image );
831
832   application.SendNotification();
833   application.Render();
834
835   DALI_TEST_CHECK( gl.GetTextureTrace().FindMethod("BindTexture") );
836
837   std::stringstream params;
838   params << GL_TEXTURE_2D << ", " << 23;
839   DALI_TEST_CHECK( gl.GetTextureTrace().FindMethodAndParams("BindTexture", params.str()) );
840
841   END_TEST;
842 }
843
844 // Scenarios 2: ImageView from Native image
845 int UtcDaliImageViewSetImageNativeImage(void)
846 {
847   ToolkitTestApplication application;
848
849   ImageView imageView = ImageView::New();
850   Stage::GetCurrent().Add( imageView );
851
852   TestGlAbstraction& gl = application.GetGlAbstraction();
853   gl.EnableTextureCallTrace( true );
854
855   std::vector< GLuint > ids;
856   ids.push_back( 23 );
857   application.GetGlAbstraction().SetNextTextureIds( ids );
858
859   int width = 200;
860   int height = 500;
861   TestNativeImagePointer nativeImageInterface = TestNativeImage::New( width, height );
862   NativeImage nativeImage = NativeImage::New( *(nativeImageInterface.Get()) );
863
864   imageView.SetImage( nativeImage );
865   application.SendNotification();
866   application.Render();
867
868   DALI_TEST_CHECK( gl.GetTextureTrace().FindMethod("BindTexture") );
869
870   std::stringstream params;
871   params << GL_TEXTURE_2D << ", " << 23;
872   DALI_TEST_CHECK( gl.GetTextureTrace().FindMethodAndParams("BindTexture", params.str()) );
873
874   END_TEST;
875 }
876
877 // Scenarios 3: ImageView initially from regular image but then SetImage called with Native image
878 int UtcDaliImageViewSetImageBufferImageToNativeImage(void)
879 {
880   ToolkitTestApplication application;
881
882   int width = 300;
883   int height = 400;
884   BufferImage image = CreateBufferImage( width, height, Color::WHITE );
885
886   ImageView imageView = ImageView::New( image );
887   Stage::GetCurrent().Add( imageView );
888
889   TestGlAbstraction& gl = application.GetGlAbstraction();
890   gl.EnableTextureCallTrace( true );
891
892   std::vector< GLuint > ids;
893   ids.push_back( 23 );
894   application.GetGlAbstraction().SetNextTextureIds( ids );
895
896   application.SendNotification();
897   application.Render();
898
899   DALI_TEST_CHECK( gl.GetTextureTrace().FindMethod("BindTexture") );
900
901   std::stringstream params;
902   params << GL_TEXTURE_2D << ", " << 23;
903   DALI_TEST_CHECK( gl.GetTextureTrace().FindMethodAndParams("BindTexture", params.str()) );
904
905   width = 200;
906   height = 500;
907   TestNativeImagePointer nativeImageInterface = TestNativeImage::New( width, height );
908   NativeImage nativeImage = NativeImage::New( *(nativeImageInterface.Get()) );
909   imageView.SetImage( nativeImage );
910
911   ids.clear();
912   ids.push_back( 24 );
913   application.GetGlAbstraction().SetNextTextureIds( ids );
914
915   application.SendNotification();
916   application.Render();
917
918   DALI_TEST_CHECK( gl.GetTextureTrace().FindMethod("BindTexture") );
919
920   std::stringstream nextTextureParams;
921   nextTextureParams << GL_TEXTURE_2D << ", " << 24;
922   DALI_TEST_CHECK( gl.GetTextureTrace().FindMethodAndParams("BindTexture", nextTextureParams.str()) );
923
924   END_TEST;
925 }
926
927 // Scenarios 4: ImageView initially from Native image but then SetImage called with regular image
928 int UtcDaliImageViewSetImageNativeImageToBufferImage(void)
929 {
930   ToolkitTestApplication application;
931
932   int width = 300;
933   int height = 400;
934   TestNativeImagePointer nativeImageInterface = TestNativeImage::New( width, height );
935   NativeImage nativeImage = NativeImage::New( *(nativeImageInterface.Get()) );
936
937   ImageView imageView = ImageView::New( nativeImage );
938   Stage::GetCurrent().Add( imageView );
939
940   TestGlAbstraction& gl = application.GetGlAbstraction();
941   gl.EnableTextureCallTrace( true );
942
943   std::vector< GLuint > ids;
944   ids.push_back( 23 );
945   application.GetGlAbstraction().SetNextTextureIds( ids );
946
947   application.SendNotification();
948   application.Render();
949
950   DALI_TEST_CHECK( gl.GetTextureTrace().FindMethod("BindTexture") );
951
952   std::stringstream params;
953   params << GL_TEXTURE_2D << ", " << 23;
954   DALI_TEST_CHECK( gl.GetTextureTrace().FindMethodAndParams("BindTexture", params.str()) );
955
956   width = 200;
957   height = 500;
958   BufferImage image = CreateBufferImage( width, height, Color::WHITE );
959   imageView.SetImage( image );
960
961   ids.clear();
962   ids.push_back( 24 );
963   application.GetGlAbstraction().SetNextTextureIds( ids );
964
965   application.SendNotification();
966   application.Render();
967
968   DALI_TEST_CHECK( gl.GetTextureTrace().FindMethod("BindTexture") );
969
970   std::stringstream nextTextureParams;
971   nextTextureParams << GL_TEXTURE_2D << ", " << 24;
972   DALI_TEST_CHECK( gl.GetTextureTrace().FindMethodAndParams("BindTexture", nextTextureParams.str()) );
973
974   END_TEST;
975 }
976
977 // Scenarios 5: ImageView from Native image with custom shader
978 int UtcDaliImageViewSetImageNativeImageWithCustomShader(void)
979 {
980   ToolkitTestApplication application;
981
982   int width = 300;
983   int height = 400;
984
985   Property::Map customShader;
986   customShader.Insert( "vertexShader", VERTEX_SHADER );
987   customShader.Insert( "fragmentShader", FRAGMENT_SHADER );
988
989   Property::Array shaderHints;
990   shaderHints.PushBack( "requiresSelfDepthTest" );
991   shaderHints.PushBack( "outputIsTransparent" );
992   shaderHints.PushBack( "outputIsOpaque" );
993   shaderHints.PushBack( "modifiesGeometry" );
994
995   customShader.Insert( "hints", shaderHints );
996
997   Property::Map map;
998   map.Insert( "shader", customShader );
999
1000   TestNativeImagePointer nativeImageInterface = TestNativeImage::New( width, height );
1001   NativeImage nativeImage = NativeImage::New( *(nativeImageInterface.Get()) );
1002
1003   ImageView imageView = ImageView::New( nativeImage );
1004   imageView.SetProperty( ImageView::Property::IMAGE, map );
1005   Stage::GetCurrent().Add( imageView );
1006
1007   TestGlAbstraction& gl = application.GetGlAbstraction();
1008   gl.EnableTextureCallTrace( true );
1009
1010   std::vector< GLuint > ids;
1011   ids.push_back( 23 );
1012   application.GetGlAbstraction().SetNextTextureIds( ids );
1013
1014   application.SendNotification();
1015   application.Render();
1016
1017   DALI_TEST_CHECK( gl.GetTextureTrace().FindMethod("BindTexture") );
1018
1019   std::stringstream params;
1020   params << GL_TEXTURE_2D << ", " << 23;
1021   DALI_TEST_CHECK( gl.GetTextureTrace().FindMethodAndParams("BindTexture", params.str()) );
1022
1023   END_TEST;
1024 }
1025
1026 // Scenarios 6: ImageView initially from regular image with custom shader but then SetImage called with Native
1027 int UtcDaliImageViewSetImageBufferImageWithCustomShaderToNativeImage(void)
1028 {
1029   ToolkitTestApplication application;
1030
1031   int width = 300;
1032   int height = 400;
1033
1034   Property::Map customShader;
1035   customShader.Insert( "vertexShader", VERTEX_SHADER );
1036   customShader.Insert( "fragmentShader", FRAGMENT_SHADER );
1037
1038   Property::Array shaderHints;
1039   shaderHints.PushBack( "requiresSelfDepthTest" );
1040   shaderHints.PushBack( "outputIsTransparent" );
1041   shaderHints.PushBack( "outputIsOpaque" );
1042   shaderHints.PushBack( "modifiesGeometry" );
1043
1044   customShader.Insert( "hints", shaderHints );
1045
1046   Property::Map map;
1047   map.Insert( "shader", customShader );
1048
1049   BufferImage image = CreateBufferImage( width, height, Color::WHITE );
1050
1051   ImageView imageView = ImageView::New( image );
1052   imageView.SetProperty( ImageView::Property::IMAGE, map );
1053   Stage::GetCurrent().Add( imageView );
1054
1055   TestGlAbstraction& gl = application.GetGlAbstraction();
1056   gl.EnableTextureCallTrace( true );
1057
1058   std::vector< GLuint > ids;
1059   ids.push_back( 23 );
1060   application.GetGlAbstraction().SetNextTextureIds( ids );
1061
1062   application.SendNotification();
1063   application.Render();
1064
1065   DALI_TEST_CHECK( gl.GetTextureTrace().FindMethod("BindTexture") );
1066
1067   std::stringstream params;
1068   params << GL_TEXTURE_2D << ", " << 23;
1069   DALI_TEST_CHECK( gl.GetTextureTrace().FindMethodAndParams("BindTexture", params.str()) );
1070
1071   TestNativeImagePointer nativeImageInterface = TestNativeImage::New( width, height );
1072   NativeImage nativeImage = NativeImage::New( *(nativeImageInterface.Get()) );
1073   imageView.SetImage( nativeImage );
1074
1075   ids.clear();
1076   ids.push_back( 24 );
1077   application.GetGlAbstraction().SetNextTextureIds( ids );
1078
1079   application.SendNotification();
1080   application.Render();
1081
1082   DALI_TEST_CHECK( gl.GetTextureTrace().FindMethod("BindTexture") );
1083
1084   std::stringstream nativeImageParams;
1085   nativeImageParams << GL_TEXTURE_2D << ", " << 24;
1086   DALI_TEST_CHECK( gl.GetTextureTrace().FindMethodAndParams("BindTexture", nativeImageParams.str()) );
1087
1088
1089   END_TEST;
1090 }
1091
1092 int UtcDaliImageViewGetImageP1(void)
1093 {
1094   ToolkitTestApplication application;
1095
1096   ImageView imageView = ImageView::New();
1097   DALI_TEST_CHECK( ! imageView.GetImage() );
1098
1099   Image image = CreateBufferImage();
1100   imageView.SetImage( image );
1101   DALI_TEST_CHECK( imageView.GetImage() == image );
1102
1103   END_TEST;
1104 }
1105
1106 int UtcDaliImageViewGetImageP2(void)
1107 {
1108   ToolkitTestApplication application;
1109
1110   BufferImage image = CreateBufferImage();
1111   ImageView imageView = ImageView::New( image );
1112   DALI_TEST_CHECK( imageView.GetImage() == image );
1113
1114   END_TEST;
1115 }
1116
1117 int UtcDaliImageViewGetImageN(void)
1118 {
1119   ToolkitTestApplication application;
1120
1121   ImageView imageView = ImageView::New( TEST_IMAGE_FILE_NAME );
1122   DALI_TEST_CHECK( ! imageView.GetImage() );
1123
1124   Image image = CreateBufferImage();
1125   imageView.SetImage( image );
1126   DALI_TEST_CHECK( imageView.GetImage() == image );
1127
1128   imageView.SetImage( TEST_IMAGE_FILE_NAME );
1129   DALI_TEST_CHECK( ! imageView.GetImage() );
1130
1131   END_TEST;
1132 }