Usage of CustomeView for ScrollContainer and code refactoring accordingly. Also added...
[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   BitmapLoader::ResetLatestCreated();
397   ImageView imageView = ImageView::New( gImage_34_RGBA, ImageDimensions( 34, 34 ) );
398
399   // By default, Aysnc loading is used
400   // loading is not started if the actor is offStage
401   BitmapLoader loader = BitmapLoader::GetLatestCreated();
402   DALI_TEST_CHECK( !loader );
403
404   Stage::GetCurrent().Add( imageView );
405   application.SendNotification();
406   application.Render(16);
407   application.Render(16);
408   application.SendNotification();
409
410   // loading started
411   loader = BitmapLoader::GetLatestCreated();
412   DALI_TEST_CHECK( loader );
413
414   // worker thread is created
415   EventThreadCallback* eventTrigger = EventThreadCallback::Get();
416   DALI_TEST_CHECK( eventTrigger );
417
418   loader.WaitForLoading();// waiting until the image to be loaded
419   DALI_TEST_CHECK( loader.IsLoaded() );
420
421   eventTrigger->WaitingForTrigger( 1 );
422   CallbackBase* callback = eventTrigger->GetCallback();
423   CallbackBase::Execute( *callback );
424
425   application.SendNotification();
426   application.Render(16);
427
428   callStack.Enable(false);
429
430   TraceCallStack::NamedParams params;
431   params["width"] = ToString(34);
432   params["height"] = ToString(34);
433   DALI_TEST_EQUALS( callStack.FindMethodAndParams( "TexSubImage2D", params ), true, TEST_LOCATION );
434
435   END_TEST;
436 }
437
438 int UtcDaliImageViewSyncLoading(void)
439 {
440   ToolkitTestApplication application;
441
442   Property::Map syncLoadingMap;
443   syncLoadingMap[ "synchronousLoading" ] = true;
444
445   // Sync loading, no atlasing for big size image
446   {
447     ImageView imageView = ImageView::New();
448
449     // Sync loading is used
450     syncLoadingMap[ ImageVisual::Property::URL ] = gImage_600_RGB;
451     imageView.SetProperty( ImageView::Property::IMAGE, syncLoadingMap );
452
453     // BitmapLoader is used, and the loading is started immediately even the actor is not on stage.
454     BitmapLoader loader = BitmapLoader::GetLatestCreated();
455     DALI_TEST_CHECK( loader );
456   }
457
458   // Sync loading, automatic atlasing for small size image
459   {
460     BitmapLoader::ResetLatestCreated();
461     TraceCallStack& callStack = application.GetGlAbstraction().GetTextureTrace();
462     callStack.Reset();
463     callStack.Enable(true);
464
465     ImageView imageView = ImageView::New( );
466     // Sync loading is used
467     syncLoadingMap[ ImageVisual::Property::URL ] = gImage_34_RGBA;
468     syncLoadingMap[ ImageVisual::Property::DESIRED_HEIGHT ] = 34;
469     syncLoadingMap[ ImageVisual::Property::DESIRED_WIDTH ] = 34;
470     imageView.SetProperty( ImageView::Property::IMAGE, syncLoadingMap );
471
472     // loading is started even if the actor is offStage
473     BitmapLoader loader = BitmapLoader::GetLatestCreated();
474     DALI_TEST_CHECK( loader );
475
476     loader.WaitForLoading();
477
478     DALI_TEST_CHECK( loader.IsLoaded() );
479
480     Stage::GetCurrent().Add( imageView );
481     application.SendNotification();
482     application.Render(16);
483
484     TraceCallStack::NamedParams params;
485     params["width"] = ToString(34);
486     params["height"] = ToString(34);
487     DALI_TEST_EQUALS( callStack.FindMethodAndParams( "TexSubImage2D", params ),
488                       true, TEST_LOCATION );
489   }
490   END_TEST;
491 }
492
493 int UtcDaliImageViewSizeWithBackground(void)
494 {
495   ToolkitTestApplication application;
496
497   int width = 100;
498   int height = 200;
499   Image image = CreateBufferImage( width, height, Vector4(1.f, 1.f, 1.f, 1.f) );
500   ImageView imageView = ImageView::New();
501   imageView.SetBackgroundImage( image );
502
503   Stage::GetCurrent().Add( imageView );
504   application.SendNotification();
505   application.Render();
506
507   DALI_TEST_EQUALS( imageView.GetCurrentSize().width, (float)width, TEST_LOCATION );
508   DALI_TEST_EQUALS( imageView.GetCurrentSize().height, (float)height, TEST_LOCATION );
509
510   END_TEST;
511 }
512
513 int UtcDaliImageViewSizeWithBackgroundAndImage(void)
514 {
515   ToolkitTestApplication application;
516
517   int widthBackground = 100;
518   int heightBackground = 200;
519   int width = 300;
520   int height = 400;
521   Image imageBackground = CreateBufferImage( widthBackground, heightBackground, Vector4(1.f, 1.f, 1.f, 1.f) );
522   Image image = CreateBufferImage( width, height, Vector4(1.f, 1.f, 1.f, 1.f) );
523
524   ImageView imageView = ImageView::New();
525   imageView.SetBackgroundImage( imageBackground );
526   imageView.SetImage( image );
527
528   Stage::GetCurrent().Add( imageView );
529   application.SendNotification();
530   application.Render();
531
532   DALI_TEST_EQUALS( imageView.GetCurrentSize().width, (float)width, TEST_LOCATION );
533   DALI_TEST_EQUALS( imageView.GetCurrentSize().height, (float)height, TEST_LOCATION );
534
535   END_TEST;
536 }
537
538 int UtcDaliImageViewHeightForWidthBackground(void)
539 {
540   ToolkitTestApplication application;
541
542   int widthBackground = 100;
543   int heightBackground = 200;
544   Image imageBackground = CreateBufferImage( widthBackground, heightBackground, Vector4(1.f, 1.f, 1.f, 1.f) );
545
546   ImageView imageView = ImageView::New();
547   imageView.SetBackgroundImage( imageBackground );
548
549   Stage::GetCurrent().Add( imageView );
550   application.SendNotification();
551   application.Render();
552
553   Control control = Control::DownCast( imageView );
554   DALI_TEST_CHECK( control );
555   DALI_TEST_EQUALS( imageView.GetHeightForWidth( 123.f ), control.GetHeightForWidth( 123.f ), TEST_LOCATION );
556   DALI_TEST_EQUALS( imageView.GetWidthForHeight( 321.f ), control.GetWidthForHeight( 321.f ), TEST_LOCATION );
557
558   END_TEST;
559 }
560
561 int UtcDaliImageViewHeightForWidthBackgroundAndImage(void)
562 {
563   ToolkitTestApplication application;
564
565   int widthBackground = 100;
566   int heightBackground = 200;
567   int width = 300;
568   int height = 400;
569   Image imageBackground = CreateBufferImage( widthBackground, heightBackground, Vector4(1.f, 1.f, 1.f, 1.f) );
570   Image image = CreateBufferImage( width, height, Vector4(1.f, 1.f, 1.f, 1.f) );
571
572   ImageView imageView = ImageView::New();
573   imageView.SetBackgroundImage( imageBackground );
574   imageView.SetImage( image );
575
576   Stage::GetCurrent().Add( imageView );
577   application.SendNotification();
578   application.Render();
579
580   DALI_TEST_EQUALS( imageView.GetHeightForWidth( width ), (float)height, TEST_LOCATION );
581   DALI_TEST_EQUALS( imageView.GetWidthForHeight( height ), (float)width, TEST_LOCATION );
582
583   END_TEST;
584 }
585
586 int UtcDaliImageViewSetBufferImage(void)
587 {
588   ToolkitTestApplication application;
589
590   int width1 = 300;
591   int height1 = 400;
592   BufferImage image1 = CreateBufferImage( width1, height1, Vector4( 1.f, 1.f, 1.f, 1.f ) );
593   ImageView imageView = ImageView::New();
594   imageView.SetImage( image1 );
595
596   TestImage( imageView, image1 );
597
598   int width2 = 600;
599   int height2 = 500;
600   BufferImage image2 = CreateBufferImage( width2, height2, Vector4( 1.f, 1.f, 1.f, 1.f ) );
601   imageView.SetImage( image2 );
602
603   TestImage( imageView, image2 );
604
605   END_TEST;
606 }
607
608 int UtcDaliImageViewSetImageUrl(void)
609 {
610   ToolkitTestApplication application;
611
612   ImageView imageView = ImageView::New();
613   imageView.SetImage( TEST_IMAGE_FILE_NAME );
614   TestUrl( imageView, TEST_IMAGE_FILE_NAME );
615
616
617   imageView.SetImage( TEST_IMAGE_FILE_NAME2 );
618   TestUrl( imageView, TEST_IMAGE_FILE_NAME2 );
619
620   END_TEST;
621 }
622
623 int UtcDaliImageViewSetImageOnstageP(void)
624 {
625   ToolkitTestApplication application;
626
627   ImageView imageView = ImageView::New();
628
629   Stage::GetCurrent().Add( imageView );
630   application.SendNotification();
631   application.Render();
632
633   ResourceImage image1 = ResourceImage::New( TEST_IMAGE_FILE_NAME );
634   imageView.SetImage( image1 );
635   TestImage( imageView, image1 );
636
637   int width = 300;
638   int height = 400;
639   BufferImage image2 = CreateBufferImage( width, height, Vector4( 1.f, 1.f, 1.f, 1.f ) );
640   imageView.SetImage( image2 );
641   TestImage( imageView, image2 );
642
643   END_TEST;
644 }
645
646 int UtcDaliImageViewSetImageOnstageN(void)
647 {
648   ToolkitTestApplication application;
649
650   ImageView imageView = ImageView::New();
651
652   Stage::GetCurrent().Add( imageView );
653   application.SendNotification();
654   application.Render();
655
656   ResourceImage image1 = ResourceImage::New( TEST_IMAGE_FILE_NAME );
657   imageView.SetImage( image1 );
658   TestImage( imageView, image1 );
659
660   Image image2;
661   imageView.SetImage( image2 );
662
663   Property::Value value = imageView.GetProperty( imageView.GetPropertyIndex( "image" ) );
664
665   //the value should be empty
666   std::string url;
667   DALI_TEST_CHECK( !value.Get( url ) );
668
669   Property::Map map;
670   DALI_TEST_CHECK( !value.Get( map ) );
671
672   END_TEST;
673 }
674
675 int UtcDaliImageViewSetImageOffstageP(void)
676 {
677   ToolkitTestApplication application;
678
679   ImageView imageView = ImageView::New();
680
681   Stage::GetCurrent().Add( imageView );
682   application.SendNotification();
683   application.Render();
684   Stage::GetCurrent().Remove( imageView );
685
686   ResourceImage image1 = ResourceImage::New( TEST_IMAGE_FILE_NAME );
687   imageView.SetImage( image1 );
688   TestImage( imageView, image1 );
689
690   int width = 300;
691   int height = 400;
692   BufferImage image2 = CreateBufferImage( width, height, Vector4( 1.f, 1.f, 1.f, 1.f ) );
693   imageView.SetImage( image2 );
694   TestImage( imageView, image2 );
695
696   END_TEST;
697 }
698
699 int UtcDaliImageViewSetImageOffstageN(void)
700 {
701   ToolkitTestApplication application;
702
703   ImageView imageView = ImageView::New();
704
705   Stage::GetCurrent().Add( imageView );
706   application.SendNotification();
707   application.Render();
708   Stage::GetCurrent().Remove( imageView );
709
710   ResourceImage image1 = ResourceImage::New( TEST_IMAGE_FILE_NAME );
711   imageView.SetImage( image1 );
712   TestImage( imageView, image1 );
713
714   Image image2;
715   imageView.SetImage( image2 );
716
717   Property::Value value = imageView.GetProperty( imageView.GetPropertyIndex( "image" ) );
718
719   //the value should be empty
720   std::string url;
721   DALI_TEST_CHECK( !value.Get( url ) );
722
723   Property::Map map;
724   DALI_TEST_CHECK( !value.Get( map ) );
725
726   END_TEST;
727 }
728
729 int UtcDaliImageViewSetImageN(void)
730 {
731   ToolkitTestApplication application;
732
733   Image image1;
734   ImageView imageView = ImageView::New();
735   imageView.SetImage( image1 );
736
737   Property::Value value = imageView.GetProperty( imageView.GetPropertyIndex( "image" ) );
738
739   //the value should be empty
740   std::string url;
741   DALI_TEST_CHECK( !value.Get( url ) );
742
743   Property::Map map;
744   DALI_TEST_CHECK( !value.Get( map ) );
745
746   std::string resource_url;
747   Property::Value val = imageView.GetProperty( imageView.GetPropertyIndex( "image" ) );
748   DALI_TEST_CHECK( !val.Get( resource_url ) );
749
750   END_TEST;
751 }
752
753 int UtcDaliImageViewSetImageTypeChangesP(void)
754 {
755   ToolkitTestApplication application;
756
757   ImageView imageView = ImageView::New();
758
759
760   std::string url;
761   Property::Map map;
762
763   Property::Value value = imageView.GetProperty( imageView.GetPropertyIndex( "image" ) );
764   DALI_TEST_CHECK( ! value.Get( url ) ); // Value should be empty
765   DALI_TEST_CHECK( ! value.Get( map ) ); // Value should be empty
766
767   // Set a URL
768   imageView.SetImage( "TEST_URL" );
769   value = imageView.GetProperty( imageView.GetPropertyIndex( "image" ) );
770
771   DALI_TEST_CHECK( value.Get( url ) );   // Value should NOT be empty
772   DALI_TEST_CHECK( ! value.Get( map ) ); // Value should be empty
773
774   // Set an empty Image
775   imageView.SetImage( Image() );
776   value = imageView.GetProperty( imageView.GetPropertyIndex( "image" ) );
777
778   DALI_TEST_CHECK( ! value.Get( url ) ); // Value should be empty
779   DALI_TEST_CHECK( ! value.Get( map ) ); // Value should be empty
780
781   // Set an Image
782   ResourceImage image1 = ResourceImage::New( TEST_IMAGE_FILE_NAME );
783   imageView.SetImage( image1 );
784   value = imageView.GetProperty( imageView.GetPropertyIndex( "image" ) );
785
786   DALI_TEST_CHECK( ! value.Get( url ) ); // Value should be empty
787   DALI_TEST_CHECK( value.Get( map ) );   // Value should NOT be empty
788
789   // Set an empty URL
790   imageView.SetImage( "" );
791   value = imageView.GetProperty( imageView.GetPropertyIndex( "image" ) );
792
793   DALI_TEST_CHECK( ! value.Get( url ) ); // Value should be empty
794   DALI_TEST_CHECK( ! value.Get( map ) ); // Value should be empty
795
796   END_TEST;
797 }
798
799 int UtcDaliImageViewResourceUrlP(void)
800 {
801   ToolkitTestApplication application;
802
803   ImageView imageView = ImageView::New();
804   DALI_TEST_CHECK( imageView.GetProperty( ImageView::Property::RESOURCE_URL ).Get< std::string >().empty() );
805
806   imageView.SetProperty( ImageView::Property::RESOURCE_URL, "TestString" );
807   DALI_TEST_EQUALS( imageView.GetProperty( ImageView::Property::RESOURCE_URL ).Get< std::string >(), "TestString", TEST_LOCATION );
808
809   END_TEST;
810 }
811
812 // Scenarios 1: ImageView from regular image
813 int UtcDaliImageViewSetImageBufferImage(void)
814 {
815   ToolkitTestApplication application;
816
817   ImageView imageView = ImageView::New();
818   Stage::GetCurrent().Add( imageView );
819
820   TestGlAbstraction& gl = application.GetGlAbstraction();
821   gl.EnableTextureCallTrace( true );
822
823   std::vector< GLuint > ids;
824   ids.push_back( 23 );
825   application.GetGlAbstraction().SetNextTextureIds( ids );
826
827   int width = 300;
828   int height = 400;
829   BufferImage image = CreateBufferImage( width, height, Color::WHITE );
830
831   imageView.SetImage( image );
832
833   application.SendNotification();
834   application.Render();
835
836   DALI_TEST_CHECK( gl.GetTextureTrace().FindMethod("BindTexture") );
837
838   std::stringstream params;
839   params << GL_TEXTURE_2D << ", " << 23;
840   DALI_TEST_CHECK( gl.GetTextureTrace().FindMethodAndParams("BindTexture", params.str()) );
841
842   END_TEST;
843 }
844
845 // Scenarios 2: ImageView from Native image
846 int UtcDaliImageViewSetImageNativeImage(void)
847 {
848   ToolkitTestApplication application;
849
850   ImageView imageView = ImageView::New();
851   Stage::GetCurrent().Add( imageView );
852
853   TestGlAbstraction& gl = application.GetGlAbstraction();
854   gl.EnableTextureCallTrace( true );
855
856   std::vector< GLuint > ids;
857   ids.push_back( 23 );
858   application.GetGlAbstraction().SetNextTextureIds( ids );
859
860   int width = 200;
861   int height = 500;
862   TestNativeImagePointer nativeImageInterface = TestNativeImage::New( width, height );
863   NativeImage nativeImage = NativeImage::New( *(nativeImageInterface.Get()) );
864
865   imageView.SetImage( nativeImage );
866   application.SendNotification();
867   application.Render();
868
869   DALI_TEST_CHECK( gl.GetTextureTrace().FindMethod("BindTexture") );
870
871   std::stringstream params;
872   params << GL_TEXTURE_2D << ", " << 23;
873   DALI_TEST_CHECK( gl.GetTextureTrace().FindMethodAndParams("BindTexture", params.str()) );
874
875   END_TEST;
876 }
877
878 // Scenarios 3: ImageView initially from regular image but then SetImage called with Native image
879 int UtcDaliImageViewSetImageBufferImageToNativeImage(void)
880 {
881   ToolkitTestApplication application;
882
883   int width = 300;
884   int height = 400;
885   BufferImage image = CreateBufferImage( width, height, Color::WHITE );
886
887   ImageView imageView = ImageView::New( image );
888   Stage::GetCurrent().Add( imageView );
889
890   TestGlAbstraction& gl = application.GetGlAbstraction();
891   gl.EnableTextureCallTrace( true );
892
893   std::vector< GLuint > ids;
894   ids.push_back( 23 );
895   application.GetGlAbstraction().SetNextTextureIds( ids );
896
897   application.SendNotification();
898   application.Render();
899
900   DALI_TEST_CHECK( gl.GetTextureTrace().FindMethod("BindTexture") );
901
902   std::stringstream params;
903   params << GL_TEXTURE_2D << ", " << 23;
904   DALI_TEST_CHECK( gl.GetTextureTrace().FindMethodAndParams("BindTexture", params.str()) );
905
906   width = 200;
907   height = 500;
908   TestNativeImagePointer nativeImageInterface = TestNativeImage::New( width, height );
909   NativeImage nativeImage = NativeImage::New( *(nativeImageInterface.Get()) );
910   imageView.SetImage( nativeImage );
911
912   ids.clear();
913   ids.push_back( 24 );
914   application.GetGlAbstraction().SetNextTextureIds( ids );
915
916   application.SendNotification();
917   application.Render();
918
919   DALI_TEST_CHECK( gl.GetTextureTrace().FindMethod("BindTexture") );
920
921   std::stringstream nextTextureParams;
922   nextTextureParams << GL_TEXTURE_2D << ", " << 24;
923   DALI_TEST_CHECK( gl.GetTextureTrace().FindMethodAndParams("BindTexture", nextTextureParams.str()) );
924
925   END_TEST;
926 }
927
928 // Scenarios 4: ImageView initially from Native image but then SetImage called with regular image
929 int UtcDaliImageViewSetImageNativeImageToBufferImage(void)
930 {
931   ToolkitTestApplication application;
932
933   int width = 300;
934   int height = 400;
935   TestNativeImagePointer nativeImageInterface = TestNativeImage::New( width, height );
936   NativeImage nativeImage = NativeImage::New( *(nativeImageInterface.Get()) );
937
938   ImageView imageView = ImageView::New( nativeImage );
939   Stage::GetCurrent().Add( imageView );
940
941   TestGlAbstraction& gl = application.GetGlAbstraction();
942   gl.EnableTextureCallTrace( true );
943
944   std::vector< GLuint > ids;
945   ids.push_back( 23 );
946   application.GetGlAbstraction().SetNextTextureIds( ids );
947
948   application.SendNotification();
949   application.Render();
950
951   DALI_TEST_CHECK( gl.GetTextureTrace().FindMethod("BindTexture") );
952
953   std::stringstream params;
954   params << GL_TEXTURE_2D << ", " << 23;
955   DALI_TEST_CHECK( gl.GetTextureTrace().FindMethodAndParams("BindTexture", params.str()) );
956
957   width = 200;
958   height = 500;
959   BufferImage image = CreateBufferImage( width, height, Color::WHITE );
960   imageView.SetImage( image );
961
962   ids.clear();
963   ids.push_back( 24 );
964   application.GetGlAbstraction().SetNextTextureIds( ids );
965
966   application.SendNotification();
967   application.Render();
968
969   DALI_TEST_CHECK( gl.GetTextureTrace().FindMethod("BindTexture") );
970
971   std::stringstream nextTextureParams;
972   nextTextureParams << GL_TEXTURE_2D << ", " << 24;
973   DALI_TEST_CHECK( gl.GetTextureTrace().FindMethodAndParams("BindTexture", nextTextureParams.str()) );
974
975   END_TEST;
976 }
977
978 // Scenarios 5: ImageView from Native image with custom shader
979 int UtcDaliImageViewSetImageNativeImageWithCustomShader(void)
980 {
981   ToolkitTestApplication application;
982
983   int width = 300;
984   int height = 400;
985
986   Property::Map customShader;
987   customShader.Insert( "vertexShader", VERTEX_SHADER );
988   customShader.Insert( "fragmentShader", FRAGMENT_SHADER );
989
990   Property::Array shaderHints;
991   shaderHints.PushBack( "requiresSelfDepthTest" );
992   shaderHints.PushBack( "outputIsTransparent" );
993   shaderHints.PushBack( "outputIsOpaque" );
994   shaderHints.PushBack( "modifiesGeometry" );
995
996   customShader.Insert( "hints", shaderHints );
997
998   Property::Map map;
999   map.Insert( "shader", customShader );
1000
1001   TestNativeImagePointer nativeImageInterface = TestNativeImage::New( width, height );
1002   NativeImage nativeImage = NativeImage::New( *(nativeImageInterface.Get()) );
1003
1004   ImageView imageView = ImageView::New( nativeImage );
1005   imageView.SetProperty( ImageView::Property::IMAGE, map );
1006   Stage::GetCurrent().Add( imageView );
1007
1008   TestGlAbstraction& gl = application.GetGlAbstraction();
1009   gl.EnableTextureCallTrace( true );
1010
1011   std::vector< GLuint > ids;
1012   ids.push_back( 23 );
1013   application.GetGlAbstraction().SetNextTextureIds( ids );
1014
1015   application.SendNotification();
1016   application.Render();
1017
1018   DALI_TEST_CHECK( gl.GetTextureTrace().FindMethod("BindTexture") );
1019
1020   std::stringstream params;
1021   params << GL_TEXTURE_2D << ", " << 23;
1022   DALI_TEST_CHECK( gl.GetTextureTrace().FindMethodAndParams("BindTexture", params.str()) );
1023
1024   END_TEST;
1025 }
1026
1027 // Scenarios 6: ImageView initially from regular image with custom shader but then SetImage called with Native
1028 int UtcDaliImageViewSetImageBufferImageWithCustomShaderToNativeImage(void)
1029 {
1030   ToolkitTestApplication application;
1031
1032   int width = 300;
1033   int height = 400;
1034
1035   Property::Map customShader;
1036   customShader.Insert( "vertexShader", VERTEX_SHADER );
1037   customShader.Insert( "fragmentShader", FRAGMENT_SHADER );
1038
1039   Property::Array shaderHints;
1040   shaderHints.PushBack( "requiresSelfDepthTest" );
1041   shaderHints.PushBack( "outputIsTransparent" );
1042   shaderHints.PushBack( "outputIsOpaque" );
1043   shaderHints.PushBack( "modifiesGeometry" );
1044
1045   customShader.Insert( "hints", shaderHints );
1046
1047   Property::Map map;
1048   map.Insert( "shader", customShader );
1049
1050   BufferImage image = CreateBufferImage( width, height, Color::WHITE );
1051
1052   ImageView imageView = ImageView::New( image );
1053   imageView.SetProperty( ImageView::Property::IMAGE, map );
1054   Stage::GetCurrent().Add( imageView );
1055
1056   TestGlAbstraction& gl = application.GetGlAbstraction();
1057   gl.EnableTextureCallTrace( true );
1058
1059   std::vector< GLuint > ids;
1060   ids.push_back( 23 );
1061   application.GetGlAbstraction().SetNextTextureIds( ids );
1062
1063   application.SendNotification();
1064   application.Render();
1065
1066   DALI_TEST_CHECK( gl.GetTextureTrace().FindMethod("BindTexture") );
1067
1068   std::stringstream params;
1069   params << GL_TEXTURE_2D << ", " << 23;
1070   DALI_TEST_CHECK( gl.GetTextureTrace().FindMethodAndParams("BindTexture", params.str()) );
1071
1072   TestNativeImagePointer nativeImageInterface = TestNativeImage::New( width, height );
1073   NativeImage nativeImage = NativeImage::New( *(nativeImageInterface.Get()) );
1074   imageView.SetImage( nativeImage );
1075
1076   ids.clear();
1077   ids.push_back( 24 );
1078   application.GetGlAbstraction().SetNextTextureIds( ids );
1079
1080   application.SendNotification();
1081   application.Render();
1082
1083   DALI_TEST_CHECK( gl.GetTextureTrace().FindMethod("BindTexture") );
1084
1085   std::stringstream nativeImageParams;
1086   nativeImageParams << GL_TEXTURE_2D << ", " << 24;
1087   DALI_TEST_CHECK( gl.GetTextureTrace().FindMethodAndParams("BindTexture", nativeImageParams.str()) );
1088
1089
1090   END_TEST;
1091 }
1092
1093 int UtcDaliImageViewGetImageP1(void)
1094 {
1095   ToolkitTestApplication application;
1096
1097   ImageView imageView = ImageView::New();
1098   DALI_TEST_CHECK( ! imageView.GetImage() );
1099
1100   Image image = CreateBufferImage();
1101   imageView.SetImage( image );
1102   DALI_TEST_CHECK( imageView.GetImage() == image );
1103
1104   END_TEST;
1105 }
1106
1107 int UtcDaliImageViewGetImageP2(void)
1108 {
1109   ToolkitTestApplication application;
1110
1111   BufferImage image = CreateBufferImage();
1112   ImageView imageView = ImageView::New( image );
1113   DALI_TEST_CHECK( imageView.GetImage() == image );
1114
1115   END_TEST;
1116 }
1117
1118 int UtcDaliImageViewGetImageN(void)
1119 {
1120   ToolkitTestApplication application;
1121
1122   ImageView imageView = ImageView::New( TEST_IMAGE_FILE_NAME );
1123   DALI_TEST_CHECK( ! imageView.GetImage() );
1124
1125   Image image = CreateBufferImage();
1126   imageView.SetImage( image );
1127   DALI_TEST_CHECK( imageView.GetImage() == image );
1128
1129   imageView.SetImage( TEST_IMAGE_FILE_NAME );
1130   DALI_TEST_CHECK( ! imageView.GetImage() );
1131
1132   END_TEST;
1133 }