Update README for dali-swig
[platform/core/uifw/dali-toolkit.git] / automated-tests / src / dali-toolkit / utc-Dali-VisualFactory.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 #include <iostream>
18 #include <stdlib.h>
19 #include <dali-toolkit-test-suite-utils.h>
20 #include <toolkit-bitmap-loader.h>
21 #include <toolkit-event-thread-callback.h>
22 #include <dali/public-api/rendering/renderer.h>
23 #include <dali/public-api/rendering/texture-set.h>
24 #include <dali/public-api/rendering/shader.h>
25 #include <dali/devel-api/images/nine-patch-image.h>
26 #include <dali-toolkit/devel-api/visual-factory/visual-factory.h>
27 #include <dali-toolkit/dali-toolkit.h>
28 #include "dummy-control.h"
29
30 using namespace Dali;
31 using namespace Dali::Toolkit;
32
33 namespace
34 {
35 typedef NinePatchImage::StretchRanges StretchRanges;
36
37 const char* TEST_IMAGE_FILE_NAME =  "gallery_image_01.jpg";
38 const char* TEST_NPATCH_FILE_NAME =  "gallery_image_01.9.png";
39 const char* TEST_SVG_FILE_NAME = TEST_RESOURCE_DIR "/svg1.svg";
40 const char* TEST_OBJ_FILE_NAME = TEST_RESOURCE_DIR "/Cube.obj";
41 const char* TEST_MTL_FILE_NAME = TEST_RESOURCE_DIR "/ToyRobot-Metal.mtl";
42 const char* TEST_SIMPLE_OBJ_FILE_NAME = TEST_RESOURCE_DIR "/Cube-Points-Only.obj";
43 const char* TEST_SIMPLE_MTL_FILE_NAME = TEST_RESOURCE_DIR "/ToyRobot-Metal-Simple.mtl";
44
45 // resolution: 34*34, pixel format: RGBA8888
46 static const char* gImage_34_RGBA = TEST_RESOURCE_DIR "/icon-edit.png";
47 // resolution: 600*600, pixel format: RGB888
48 static const char* gImage_600_RGB = TEST_RESOURCE_DIR "/test-image-600.jpg";
49
50 Integration::Bitmap* CreateBitmap( unsigned int imageWidth, unsigned int imageHeight, unsigned int initialColor, Pixel::Format pixelFormat )
51 {
52   Integration::Bitmap* bitmap = Integration::Bitmap::New( Integration::Bitmap::BITMAP_2D_PACKED_PIXELS, ResourcePolicy::OWNED_RETAIN );
53   Integration::PixelBuffer* pixbuffer = bitmap->GetPackedPixelsProfile()->ReserveBuffer( pixelFormat, imageWidth, imageHeight, imageWidth, imageHeight );
54   unsigned int bytesPerPixel = GetBytesPerPixel( pixelFormat );
55
56   memset( pixbuffer, initialColor, imageHeight * imageWidth * bytesPerPixel );
57
58   return bitmap;
59 }
60
61 void InitialiseRegionsToZeroAlpha( Integration::Bitmap* image, unsigned int imageWidth, unsigned int imageHeight, Pixel::Format pixelFormat )
62 {
63   PixelBuffer* pixbuffer = image->GetBuffer();
64   unsigned int bytesPerPixel = GetBytesPerPixel( pixelFormat );
65
66   for( unsigned int row = 0; row < imageWidth; ++row )
67   {
68     unsigned int pixelOffset = row * bytesPerPixel;
69     pixbuffer[ pixelOffset + 3 ] = 0x00;
70     pixelOffset += ( imageHeight - 1 ) * imageWidth * bytesPerPixel;
71     pixbuffer[ pixelOffset + 3 ] = 0x00;
72   }
73
74   for ( unsigned int column = 0; column < imageHeight; ++column )
75   {
76     unsigned int pixelOffset = column * imageWidth * bytesPerPixel;
77     pixbuffer[ pixelOffset + 3 ] = 0x00;
78     pixelOffset += ( imageWidth -1 ) * bytesPerPixel;
79     pixbuffer[ pixelOffset + 3 ] = 0x00;
80   }
81 }
82
83 void AddStretchRegionsToImage( Integration::Bitmap* image, unsigned int imageWidth, unsigned int imageHeight, const StretchRanges& stretchRangesX, const StretchRanges& stretchRangesY, Pixel::Format pixelFormat )
84 {
85   PixelBuffer* pixbuffer = image->GetBuffer();
86   unsigned int bytesPerPixel = GetBytesPerPixel( pixelFormat );
87
88   for(StretchRanges::ConstIterator it = stretchRangesX.Begin(); it != stretchRangesX.End(); ++it)
89   {
90     const Uint16Pair& range = *it;
91     //since the stretch range is in the cropped image space, we need to offset by 1 to get it to the uncropped image space
92     for( unsigned int column = range.GetX() + 1u; column < range.GetY() + 1u; ++column )
93     {
94       unsigned int pixelOffset = column * bytesPerPixel;
95       pixbuffer[ pixelOffset ] = 0x00;
96       pixbuffer[ pixelOffset + 1 ] = 0x00;
97       pixbuffer[ pixelOffset + 2 ] = 0x00;
98       pixbuffer[ pixelOffset + 3 ] = 0xFF;
99     }
100   }
101
102
103   for(StretchRanges::ConstIterator it = stretchRangesY.Begin(); it != stretchRangesY.End(); ++it)
104   {
105     const Uint16Pair& range = *it;
106     //since the stretch range is in the cropped image space, we need to offset by 1 to get it to the uncropped image space
107     for( unsigned int row = range.GetX() + 1u; row < range.GetY() + 1u; ++row )
108     {
109       unsigned int pixelOffset = row * imageWidth * bytesPerPixel;
110       pixbuffer[ pixelOffset ] = 0x00;
111       pixbuffer[ pixelOffset + 1 ] = 0x00;
112       pixbuffer[ pixelOffset + 2 ] = 0x00;
113       pixbuffer[ pixelOffset + 3 ] = 0xFF;
114     }
115   }
116 }
117
118 void AddChildRegionsToImage( Integration::Bitmap* image, unsigned int imageWidth, unsigned int imageHeight, const Vector4& requiredChildRegion, Pixel::Format pixelFormat )
119 {
120   PixelBuffer* pixbuffer = image->GetBuffer();
121   unsigned int bytesPerPixel = GetBytesPerPixel( pixelFormat );
122
123   Integration::Bitmap::PackedPixelsProfile* srcProfile = image->GetPackedPixelsProfile();
124   unsigned int bufferStride = srcProfile->GetBufferStride();
125
126   // Add bottom child region
127   for( unsigned int column = requiredChildRegion.x; column < imageWidth - requiredChildRegion.z; ++column )
128   {
129     unsigned int pixelOffset = column * bytesPerPixel;
130     pixelOffset += ( imageHeight - 1 ) * bufferStride;
131     pixbuffer[ pixelOffset ] = 0x00;
132     pixbuffer[ pixelOffset + 1 ] = 0x00;
133     pixbuffer[ pixelOffset + 2 ] = 0x00;
134     pixbuffer[ pixelOffset + 3 ] = 0xFF;
135   }
136
137   // Add right child region
138   for ( unsigned int row = requiredChildRegion.y; row < imageHeight - requiredChildRegion.w; ++row )
139   {
140     unsigned int pixelOffset = row * bufferStride + ( imageWidth - 1 ) * bytesPerPixel;
141     pixbuffer[ pixelOffset ] = 0x00;
142     pixbuffer[ pixelOffset + 1 ] = 0x00;
143     pixbuffer[ pixelOffset + 2 ] = 0x00;
144     pixbuffer[ pixelOffset + 3 ] = 0xFF;
145   }
146 }
147
148 Integration::ResourcePointer CustomizeNinePatch( TestApplication& application,
149                                                  unsigned int ninePatchImageWidth,
150                                                  unsigned int ninePatchImageHeight,
151                                                  const StretchRanges& stretchRangesX,
152                                                  const StretchRanges& stretchRangesY,
153                                                  bool addChildRegion = false,
154                                                  Vector4 requiredChildRegion = Vector4::ZERO )
155 {
156   TestPlatformAbstraction& platform = application.GetPlatform();
157
158   Pixel::Format pixelFormat = Pixel::RGBA8888;
159
160   tet_infoline("Create Bitmap");
161   platform.SetClosestImageSize(Vector2( ninePatchImageWidth, ninePatchImageHeight));
162   Integration::Bitmap* bitmap = CreateBitmap( ninePatchImageWidth, ninePatchImageHeight, 0xFF, pixelFormat );
163
164   tet_infoline("Clear border regions");
165   InitialiseRegionsToZeroAlpha( bitmap, ninePatchImageWidth, ninePatchImageHeight, pixelFormat );
166
167   tet_infoline("Add Stretch regions to Bitmap");
168   AddStretchRegionsToImage( bitmap, ninePatchImageWidth, ninePatchImageHeight, stretchRangesX, stretchRangesY, pixelFormat );
169
170   if( addChildRegion )
171   {
172     tet_infoline("Add Child regions to Bitmap");
173     AddChildRegionsToImage( bitmap, ninePatchImageWidth, ninePatchImageHeight, requiredChildRegion, pixelFormat );
174   }
175
176   tet_infoline("Getting resource");
177   Integration::ResourcePointer resourcePtr(bitmap);
178   //platform.SetResourceLoaded( 0, Dali::Integration::ResourceBitmap, resourcePtr );
179   platform.SetSynchronouslyLoadedResource( resourcePtr);
180
181   return resourcePtr;
182 }
183
184 void TestVisualRender( ToolkitTestApplication& application,
185                        DummyControl& actor,
186                        Visual::Base& visual,
187                        std::size_t expectedSamplers = 0,
188                        ImageDimensions imageDimensions = ImageDimensions(),
189                        Integration::ResourcePointer resourcePtr = Integration::ResourcePointer())
190 {
191   DummyControlImpl& dummyImpl = static_cast<DummyControlImpl&>(actor.GetImplementation());
192   dummyImpl.RegisterVisual( Control::CONTROL_PROPERTY_END_INDEX + 1, visual );
193
194   if( resourcePtr )
195   {
196     // set the image size, for test case, this needs to be set before loading started
197     application.GetPlatform().SetClosestImageSize(  Vector2(imageDimensions.GetWidth(), imageDimensions.GetHeight()) );
198   }
199
200   actor.SetSize( 200.f, 200.f );
201   DALI_TEST_EQUALS( actor.GetRendererCount(), 0u, TEST_LOCATION );
202
203   Stage::GetCurrent().Add( actor );
204
205   application.SendNotification();
206   application.Render();
207
208   if( resourcePtr )
209   {
210     Integration::ResourceRequest* request = application.GetPlatform().GetRequest();
211     if(request)
212     {
213       application.GetPlatform().SetResourceLoaded(request->GetId(), request->GetType()->id, resourcePtr );
214     }
215   }
216
217   application.Render();
218   application.SendNotification();
219
220   if( resourcePtr )
221   {
222     DALI_TEST_EQUALS( application.GetPlatform().WasCalled(TestPlatformAbstraction::LoadResourceFunc) ||
223                       application.GetPlatform().WasCalled(TestPlatformAbstraction::LoadResourceSynchronouslyFunc ), true, TEST_LOCATION);
224   }
225
226   DALI_TEST_EQUALS( actor.GetRendererCount(), 1u, TEST_LOCATION );
227
228 }
229
230 } // namespace
231
232
233 void dali_visual_factory_startup(void)
234 {
235   test_return_value = TET_UNDEF;
236 }
237
238 void dali_visual_factory_cleanup(void)
239 {
240   test_return_value = TET_PASS;
241 }
242
243 int UtcDaliVisualFactoryGet(void)
244 {
245   ToolkitTestApplication application;
246   tet_infoline( "UtcDaliVisualFactory" );
247
248   //Register type
249   TypeInfo type;
250   type = TypeRegistry::Get().GetTypeInfo( "VisualFactory" );
251   DALI_TEST_CHECK( type );
252   BaseHandle handle = type.CreateInstance();
253   DALI_TEST_CHECK( handle );
254
255   VisualFactory factory;
256   factory = VisualFactory::Get();
257   DALI_TEST_CHECK( factory );
258
259   VisualFactory newFactory = VisualFactory::Get();
260   DALI_TEST_CHECK( newFactory );
261
262   // Check that visual factory is a singleton
263   DALI_TEST_CHECK(factory == newFactory);
264
265   END_TEST;
266 }
267
268 int UtcDaliVisualFactoryCopyAndAssignment(void)
269 {
270   ToolkitTestApplication application;
271   tet_infoline( "UtcDaliVisualFactoryCopyAndAssignment" );
272   VisualFactory factory = VisualFactory::Get();
273
274   VisualFactory factoryCopy( factory );
275   DALI_TEST_CHECK(factory == factoryCopy);
276
277   VisualFactory emptyFactory;
278   VisualFactory emptyFactoryCopy( emptyFactory );
279   DALI_TEST_CHECK(emptyFactory == emptyFactoryCopy);
280
281   VisualFactory factoryEquals;
282   factoryEquals = factory;
283   DALI_TEST_CHECK(factory == factoryEquals);
284
285   VisualFactory emptyFactoryEquals;
286   emptyFactoryEquals = emptyFactory;
287   DALI_TEST_CHECK( emptyFactory == emptyFactoryEquals );
288
289   //self assignment
290   factory = factory;
291   DALI_TEST_CHECK( factory = factoryCopy );
292
293   END_TEST;
294 }
295
296 int UtcDaliVisualFactoryGetColorVisual1(void)
297 {
298   ToolkitTestApplication application;
299   tet_infoline( "UtcDaliVisualFactoryGetColorVisual1:  Request color visual with a Property::Map" );
300
301   VisualFactory factory = VisualFactory::Get();
302   DALI_TEST_CHECK( factory );
303
304   Property::Map propertyMap;
305   Vector4 testColor( 1.f, 0.5f, 0.3f, 0.2f );
306   propertyMap.Insert(Visual::Property::TYPE,  Visual::COLOR);
307   propertyMap.Insert(ColorVisual::Property::MIX_COLOR,  testColor);
308
309   Visual::Base visual = factory.CreateVisual(propertyMap);
310   DALI_TEST_CHECK( visual );
311
312   DummyControl actor = DummyControl::New();
313   TestVisualRender( application, actor, visual );
314
315   Vector4 actualValue(Vector4::ZERO);
316   TestGlAbstraction& gl = application.GetGlAbstraction();
317   DALI_TEST_CHECK( gl.GetUniformValue<Vector4>( "mixColor", actualValue ) );
318   DALI_TEST_EQUALS( actualValue, testColor, TEST_LOCATION );
319
320   END_TEST;
321 }
322
323 int UtcDaliVisualFactoryGetColorVisual2(void)
324 {
325   ToolkitTestApplication application;
326   tet_infoline( "UtcDaliVisualFactoryGetColorVisual2: Request color visual with a Vector4" );
327
328   VisualFactory factory = VisualFactory::Get();
329   DALI_TEST_CHECK( factory );
330
331   Vector4 testColor( 1.f, 0.5f, 0.3f, 0.2f );
332   Dali::Property::Map map;
333   map[ Visual::Property::TYPE ] = Visual::COLOR;
334   map[ ColorVisual::Property::MIX_COLOR ] = testColor;
335   Visual::Base visual = factory.CreateVisual( map );
336   DALI_TEST_CHECK( visual );
337
338   DummyControl actor = DummyControl::New();
339   TestVisualRender( application, actor, visual );
340
341   Vector4 actualValue(Vector4::ZERO);
342   TestGlAbstraction& gl = application.GetGlAbstraction();
343   DALI_TEST_CHECK( gl.GetUniformValue<Vector4>( "mixColor", actualValue ) );
344   DALI_TEST_EQUALS( actualValue, testColor, TEST_LOCATION );
345
346   Stage::GetCurrent().Remove(actor);
347   DALI_TEST_CHECK( actor.GetRendererCount() == 0u );
348
349   END_TEST;
350 }
351
352 int UtcDaliVisualFactoryGetBorderVisual1(void)
353 {
354   ToolkitTestApplication application;
355   tet_infoline( "UtcDaliVisualFactoryGetBorderVisual1:  Request border visual with a Property::Map" );
356
357   VisualFactory factory = VisualFactory::Get();
358   DALI_TEST_CHECK( factory );
359
360   Property::Map propertyMap;
361   Vector4 testColor( 1.f, 0.5f, 0.3f, 0.2f );
362   float testSize = 5.f;
363   propertyMap.Insert(Visual::Property::TYPE,  Visual::BORDER);
364   propertyMap.Insert(BorderVisual::Property::COLOR,  testColor);
365   propertyMap.Insert(BorderVisual::Property::SIZE,  testSize);
366
367   Visual::Base visual = factory.CreateVisual(propertyMap);
368   DALI_TEST_CHECK( visual );
369
370   DummyControl actor = DummyControl::New();
371   DummyControlImpl& dummyImpl = static_cast<DummyControlImpl&>(actor.GetImplementation());
372   dummyImpl.RegisterVisual( Control::CONTROL_PROPERTY_END_INDEX + 1, visual );
373   actor.SetSize(200.f, 200.f);
374   Stage::GetCurrent().Add( actor );
375   visual.SetSize(Vector2(200.f, 200.f));
376
377   DALI_TEST_CHECK( actor.GetRendererCount() == 1u );
378   int blendMode = actor.GetRendererAt(0u).GetProperty<int>( Renderer::Property::BLEND_MODE );
379   DALI_TEST_EQUALS( static_cast<BlendMode::Type>(blendMode), BlendMode::ON, TEST_LOCATION );
380
381   TestGlAbstraction& gl = application.GetGlAbstraction();
382
383   application.SendNotification();
384   application.Render(0);
385
386   Vector4 actualColor(Vector4::ZERO);
387   DALI_TEST_CHECK( gl.GetUniformValue<Vector4>( "borderColor", actualColor ) );
388   DALI_TEST_EQUALS( actualColor, testColor, TEST_LOCATION );
389
390   float actualSize = 0.f;
391   DALI_TEST_CHECK( gl.GetUniformValue<float>( "borderSize", actualSize ) );
392   DALI_TEST_EQUALS( actualSize, testSize, TEST_LOCATION );
393
394   actor.Unparent();
395   DALI_TEST_CHECK( actor.GetRendererCount() == 0u );
396
397   END_TEST;
398 }
399
400 int UtcDaliVisualFactoryGetBorderVisual2(void)
401 {
402   ToolkitTestApplication application;
403   tet_infoline( "UtcDaliVisualFactoryGetBorderVisual2:  Request border visual with a borderSize and a borderColor" );
404
405   VisualFactory factory = VisualFactory::Get();
406   DALI_TEST_CHECK( factory );
407
408   Vector4 testColor( 1.f, 0.5f, 0.3f, 1.f );
409   float testSize = 5.f;
410
411   Dali::Property::Map propertyMap;
412   propertyMap[ Visual::Property::TYPE ] = Visual::BORDER;
413   propertyMap[ BorderVisual::Property::COLOR  ] = testColor;
414   propertyMap[ BorderVisual::Property::SIZE   ] = testSize;
415   Visual::Base visual = factory.CreateVisual( propertyMap );
416   DALI_TEST_CHECK( visual );
417
418   DummyControl actor = DummyControl::New();
419   DummyControlImpl& dummyImpl = static_cast<DummyControlImpl&>(actor.GetImplementation());
420   dummyImpl.RegisterVisual( Control::CONTROL_PROPERTY_END_INDEX + 1, visual );
421   actor.SetSize(200.f, 200.f);
422   Stage::GetCurrent().Add( actor );
423   visual.SetSize(Vector2(200.f, 200.f));
424
425   DALI_TEST_CHECK( actor.GetRendererCount() == 1u );
426
427   TestGlAbstraction& gl = application.GetGlAbstraction();
428
429   application.SendNotification();
430   application.Render(0);
431
432   int blendMode = actor.GetRendererAt(0u).GetProperty<int>( Renderer::Property::BLEND_MODE );
433   DALI_TEST_EQUALS( static_cast<BlendMode::Type>(blendMode), BlendMode::AUTO, TEST_LOCATION );
434
435   Vector4 actualColor(Vector4::ZERO);
436   DALI_TEST_CHECK( gl.GetUniformValue<Vector4>( "borderColor", actualColor ) );
437   DALI_TEST_EQUALS( actualColor, testColor, TEST_LOCATION );
438
439   float actualSize = 0.f;
440   DALI_TEST_CHECK( gl.GetUniformValue<float>( "borderSize", actualSize ) );
441   DALI_TEST_EQUALS( actualSize, testSize, TEST_LOCATION );
442
443   actor.Unparent();
444
445   // enable the anti-aliasing
446   Dali::Property::Map map;
447   map[ Visual::Property::TYPE ] = Visual::BORDER;
448   map[ BorderVisual::Property::COLOR  ] = testColor;
449   map[ BorderVisual::Property::SIZE   ] = testSize;
450   map[ BorderVisual::Property::ANTI_ALIASING   ] = true;
451   visual = factory.CreateVisual( map );
452
453   dummyImpl.RegisterVisual( Control::CONTROL_PROPERTY_END_INDEX + 1, visual );
454   Stage::GetCurrent().Add( actor );
455
456   blendMode = actor.GetRendererAt(0u).GetProperty<int>( Renderer::Property::BLEND_MODE );
457   DALI_TEST_EQUALS( static_cast<BlendMode::Type>(blendMode), BlendMode::ON, TEST_LOCATION );
458
459   END_TEST;
460 }
461
462 int UtcDaliVisualFactoryGetLinearGradientVisual(void)
463 {
464   ToolkitTestApplication application;
465   tet_infoline("UtcDaliVisualFactoryGetRadialGradientVisual");
466
467   VisualFactory factory = VisualFactory::Get();
468   DALI_TEST_CHECK( factory );
469
470   Property::Map propertyMap;
471   propertyMap.Insert(Visual::Property::TYPE,  Visual::GRADIENT);
472
473   Vector2 start(-1.f, -1.f);
474   Vector2 end(1.f, 1.f);
475   propertyMap.Insert(GradientVisual::Property::START_POSITION, start);
476   propertyMap.Insert(GradientVisual::Property::END_POSITION, end);
477   propertyMap.Insert(GradientVisual::Property::SPREAD_METHOD, GradientVisual::SpreadMethod::REPEAT);
478
479   Property::Array stopOffsets;
480   stopOffsets.PushBack( 0.2f );
481   stopOffsets.PushBack( 0.8f );
482   propertyMap.Insert(GradientVisual::Property::STOP_OFFSET, stopOffsets);
483
484   Property::Array stopColors;
485   stopColors.PushBack( Color::RED );
486   stopColors.PushBack( Color::GREEN );
487   propertyMap.Insert(GradientVisual::Property::STOP_COLOR, stopColors);
488
489   Visual::Base visual = factory.CreateVisual(propertyMap);
490   DALI_TEST_CHECK( visual );
491
492   // A lookup texture is generated and pass to shader as sampler
493   DummyControl actor = DummyControl::New();
494   TestVisualRender( application, actor, visual, 1u);
495
496   END_TEST;
497 }
498
499 int UtcDaliVisualFactoryGetRadialGradientVisual(void)
500 {
501   ToolkitTestApplication application;
502   tet_infoline("UtcDaliVisualFactoryGetRadialGradientVisual");
503
504   VisualFactory factory = VisualFactory::Get();
505   DALI_TEST_CHECK( factory );
506
507   Property::Map propertyMap;
508   propertyMap.Insert(Visual::Property::TYPE,  Visual::GRADIENT);
509
510   Vector2 center(100.f, 100.f);
511   float radius = 100.f;
512   propertyMap.Insert(GradientVisual::Property::UNITS,  GradientVisual::Units::USER_SPACE);
513   propertyMap.Insert(GradientVisual::Property::CENTER,  center);
514   propertyMap.Insert(GradientVisual::Property::RADIUS,  radius);
515
516   Property::Array stopOffsets;
517   stopOffsets.PushBack( 0.0f );
518   stopOffsets.PushBack( 1.f );
519   propertyMap.Insert(GradientVisual::Property::STOP_OFFSET,   stopOffsets);
520
521   Property::Array stopColors;
522   stopColors.PushBack( Color::RED );
523   stopColors.PushBack( Color::GREEN );
524   propertyMap.Insert(GradientVisual::Property::STOP_COLOR,   stopColors);
525
526   Visual::Base visual = factory.CreateVisual(propertyMap);
527   DALI_TEST_CHECK( visual );
528
529   // A lookup texture is generated and pass to shader as sampler
530   DummyControl actor = DummyControl::New();
531   TestVisualRender( application, actor, visual, 1u );
532
533   Matrix3 alignMatrix( radius, 0.f, 0.f, 0.f, radius, 0.f, center.x, center.y, 1.f );
534   alignMatrix.Invert();
535
536   Matrix3 actualValue( Matrix3::IDENTITY );
537   TestGlAbstraction& gl = application.GetGlAbstraction();
538   DALI_TEST_CHECK( gl.GetUniformValue<Matrix3>( "uAlignmentMatrix", actualValue ) );
539   DALI_TEST_EQUALS( actualValue, alignMatrix, Math::MACHINE_EPSILON_100, TEST_LOCATION );
540
541   END_TEST;
542 }
543
544 int UtcDaliVisualFactoryDefaultOffsetsGradientVisual(void)
545 {
546   ToolkitTestApplication application;
547   tet_infoline("UtcDaliVisualFactoryGetRadialGradientVisual");
548
549   VisualFactory factory = VisualFactory::Get();
550   DALI_TEST_CHECK( factory );
551
552   Property::Map propertyMap;
553   propertyMap.Insert(Visual::Property::TYPE,  Visual::GRADIENT);
554
555   Vector2 start(-1.f, -1.f);
556   Vector2 end(1.f, 1.f);
557   propertyMap.Insert(GradientVisual::Property::START_POSITION, start);
558   propertyMap.Insert(GradientVisual::Property::END_POSITION, end);
559   propertyMap.Insert(GradientVisual::Property::SPREAD_METHOD, GradientVisual::SpreadMethod::REPEAT);
560
561   Property::Array stopColors;
562   stopColors.PushBack( Color::RED );
563   stopColors.PushBack( Color::GREEN );
564   propertyMap.Insert(GradientVisual::Property::STOP_COLOR, stopColors);
565
566   Visual::Base visual = factory.CreateVisual(propertyMap);
567   DALI_TEST_CHECK( visual );
568
569   // A lookup texture is generated and pass to shader as sampler
570   DummyControl actor = DummyControl::New();
571   TestVisualRender( application, actor, visual, 1u );
572
573   Stage::GetCurrent().Remove( actor );
574   DALI_TEST_CHECK( actor.GetRendererCount() == 0u );
575
576   END_TEST;
577 }
578
579 int UtcDaliVisualFactoryGetImageVisual1(void)
580 {
581   ToolkitTestApplication application;
582   tet_infoline( "UtcDaliVisualFactoryGetImageVisual1: Request image visual with a Property::Map" );
583
584   VisualFactory factory = VisualFactory::Get();
585   DALI_TEST_CHECK( factory );
586
587   Property::Map propertyMap;
588   propertyMap.Insert( Visual::Property::TYPE,  Visual::IMAGE );
589   propertyMap.Insert( ImageVisual::Property::URL,  TEST_IMAGE_FILE_NAME );
590
591   Visual::Base visual = factory.CreateVisual( propertyMap );
592   DALI_TEST_CHECK( visual );
593
594   // For tesing the LoadResourceFunc is called, a big image size should be set, so the atlasing is not applied.
595   // Image with a size smaller than 512*512 will be uploaded as a part of the atlas.
596
597   const int width=512;
598   const int height=513;
599   TestGlAbstraction& gl = application.GetGlAbstraction();
600   TraceCallStack& textureTrace = gl.GetTextureTrace();
601   textureTrace.Enable(true);
602
603   Integration::Bitmap* bitmap = Integration::Bitmap::New( Integration::Bitmap::BITMAP_2D_PACKED_PIXELS, ResourcePolicy::OWNED_DISCARD );
604   bitmap->GetPackedPixelsProfile()->ReserveBuffer( Pixel::RGBA8888, width, height,width, height );
605
606   DummyControl actor = DummyControl::New();
607   TestVisualRender( application, actor, visual, 1u,
608                     ImageDimensions(width, height),
609                     Integration::ResourcePointer( bitmap ) );
610
611   DALI_TEST_EQUALS( textureTrace.FindMethod("BindTexture"), true, TEST_LOCATION );
612
613   Stage::GetCurrent().Remove( actor );
614   DALI_TEST_CHECK( actor.GetRendererCount() == 0u );
615
616   END_TEST;
617 }
618
619 int UtcDaliVisualFactoryGetImageVisual2(void)
620 {
621   ToolkitTestApplication application;
622   tet_infoline( "UtcDaliVisualFactoryGetImageVisual2: Request image visual with an image handle" );
623
624   VisualFactory factory = VisualFactory::Get();
625   DALI_TEST_CHECK( factory );
626
627   Image image = ResourceImage::New(TEST_IMAGE_FILE_NAME);
628   Visual::Base visual = factory.CreateVisual( image );
629
630   // For tesing the LoadResourceFunc is called, a big image size should be set, so the atlasing is not applied.
631   // Image with a size smaller than 512*512 will be uploaded as a part of the atlas.
632
633   const int width=512;
634   const int height=513;
635
636   Integration::Bitmap* bitmap = Integration::Bitmap::New( Integration::Bitmap::BITMAP_2D_PACKED_PIXELS, ResourcePolicy::OWNED_DISCARD );
637   bitmap->GetPackedPixelsProfile()->ReserveBuffer( Pixel::RGBA8888, width, height,width, height );
638
639   TestGlAbstraction& gl = application.GetGlAbstraction();
640   TraceCallStack& textureTrace = gl.GetTextureTrace();
641   textureTrace.Enable(true);
642
643   DummyControl actor = DummyControl::New();
644   TestVisualRender( application, actor, visual, 1u,
645                     ImageDimensions(width, height),
646                     Integration::ResourcePointer(bitmap) );
647
648   DALI_TEST_EQUALS( textureTrace.FindMethod("BindTexture"), true, TEST_LOCATION );
649   END_TEST;
650 }
651
652 int UtcDaliVisualFactoryGetImageVisual3(void)
653 {
654   ToolkitTestApplication application;
655   tet_infoline( "UtcDaliVisualFactoryGetImageVisual3: Request image visual with a Property::Map, test custom wrap mode and pixel area with atlasing" );
656
657   VisualFactory factory = VisualFactory::Get();
658   DALI_TEST_CHECK( factory );
659
660   // Test wrap mode with atlasing. Image with a size smaller than 512*512 will be uploaded as a part of the atlas.
661   const int width=34;
662   const int height=34;
663   const Vector4 pixelArea(-0.5f, -0.5f, 2.f, 2.f);
664
665   Property::Map propertyMap;
666   propertyMap.Insert( Visual::Property::TYPE,  Visual::IMAGE );
667   propertyMap.Insert( ImageVisual::Property::URL,  gImage_34_RGBA );
668   propertyMap.Insert( ImageVisual::Property::DESIRED_WIDTH, width );
669   propertyMap.Insert( ImageVisual::Property::DESIRED_HEIGHT, height );
670   propertyMap.Insert( ImageVisual::Property::SYNCHRONOUS_LOADING, true );
671   propertyMap.Insert( ImageVisual::Property::PIXEL_AREA, pixelArea );
672   propertyMap.Insert( ImageVisual::Property::WRAP_MODE_U, WrapMode::MIRRORED_REPEAT );
673   propertyMap.Insert( ImageVisual::Property::WRAP_MODE_V, WrapMode::REPEAT );
674
675   Visual::Base visual = factory.CreateVisual( propertyMap );
676   DALI_TEST_CHECK( visual );
677
678   TestGlAbstraction& gl = application.GetGlAbstraction();
679   TraceCallStack& textureTrace = gl.GetTextureTrace();
680   textureTrace.Enable(true);
681   TraceCallStack& texParameterTrace = gl.GetTexParameterTrace();
682   texParameterTrace.Enable( true );
683
684   DummyControl actor = DummyControl::New();
685   DummyControlImpl& dummyImpl = static_cast<DummyControlImpl&>(actor.GetImplementation());
686   dummyImpl.RegisterVisual( Control::CONTROL_PROPERTY_END_INDEX + 1, visual );
687   actor.SetSize(2000, 2000);
688   actor.SetParentOrigin(ParentOrigin::CENTER);
689   Stage::GetCurrent().Add( actor );
690
691   // loading started
692   application.SendNotification();
693   application.Render();
694   application.Render();
695   application.SendNotification();
696   BitmapLoader loader = BitmapLoader::GetLatestCreated();
697   DALI_TEST_CHECK( loader );
698   loader.WaitForLoading();// waiting until the image to be loaded
699   DALI_TEST_CHECK( loader.IsLoaded() );
700
701   DALI_TEST_CHECK( actor.GetRendererCount() == 1u );
702
703   DALI_TEST_EQUALS( textureTrace.FindMethod("BindTexture"), true, TEST_LOCATION );
704
705   // WITH atlasing, the wrapping is handled manually in shader, so the following gl function should not be called
706   std::stringstream out;
707   out << GL_TEXTURE_2D << ", " << GL_TEXTURE_WRAP_S << ", " << GL_MIRRORED_REPEAT;
708   DALI_TEST_CHECK( !texParameterTrace.FindMethodAndParams("TexParameteri", out.str()) );
709   out.str("");
710   out << GL_TEXTURE_2D << ", " << GL_TEXTURE_WRAP_T << ", " << GL_REPEAT;
711   DALI_TEST_CHECK( !texParameterTrace.FindMethodAndParams("TexParameteri", out.str()) );
712
713   // test the uniforms which used to handle the wrap mode
714   Renderer renderer = actor.GetRendererAt( 0u );
715   DALI_TEST_CHECK( renderer );
716
717   Property::Value pixelAreaValue = renderer.GetProperty( renderer.GetPropertyIndex( "pixelArea" ) );
718   DALI_TEST_EQUALS( pixelAreaValue.Get<Vector4>(), pixelArea, TEST_LOCATION );
719   Vector4 pixelAreaUniform;
720   DALI_TEST_CHECK( gl.GetUniformValue<Vector4>( "pixelArea", pixelAreaUniform ) );
721   DALI_TEST_EQUALS( pixelArea, pixelAreaUniform, Math::MACHINE_EPSILON_100, TEST_LOCATION );
722
723   Property::Value wrapModeValue = renderer.GetProperty( renderer.GetPropertyIndex( "wrapMode" ) );
724   Vector2 wrapMode( WrapMode::MIRRORED_REPEAT-1, WrapMode::REPEAT-1 );
725   DALI_TEST_EQUALS( wrapModeValue.Get<Vector2>(), wrapMode, TEST_LOCATION );
726   Vector2 wrapModeUniform;
727   DALI_TEST_CHECK( gl.GetUniformValue<Vector2>( "wrapMode", wrapModeUniform ) );
728   DALI_TEST_EQUALS( wrapMode, wrapModeUniform, Math::MACHINE_EPSILON_100, TEST_LOCATION );
729
730   actor.Unparent( );
731   DALI_TEST_CHECK( actor.GetRendererCount() == 0u );
732
733   END_TEST;
734 }
735
736 int UtcDaliVisualFactoryGetImageVisual4(void)
737 {
738   ToolkitTestApplication application;
739   tet_infoline( "UtcDaliVisualFactoryGetImageVisual4: Request image visual with a Property::Map, test custom wrap mode and pixel area without atlasing" );
740
741   VisualFactory factory = VisualFactory::Get();
742   DALI_TEST_CHECK( factory );
743
744   // Test wrap mode without atlasing. Image with a size bigger than 512*512 will NOT be uploaded as a part of the atlas.
745   const int width=600;
746   const int height=600;
747   const Vector4 pixelArea(-0.5f, -0.5f, 2.f, 2.f);
748
749   Property::Map propertyMap;
750   propertyMap.Insert( Visual::Property::TYPE,  Visual::IMAGE );
751   propertyMap.Insert( ImageVisual::Property::URL,  gImage_600_RGB );
752   propertyMap.Insert( ImageVisual::Property::DESIRED_WIDTH, width );
753   propertyMap.Insert( ImageVisual::Property::DESIRED_HEIGHT, height );
754   propertyMap.Insert( ImageVisual::Property::SYNCHRONOUS_LOADING, true );
755   propertyMap.Insert( ImageVisual::Property::PIXEL_AREA, pixelArea );
756   propertyMap.Insert( ImageVisual::Property::WRAP_MODE_U, WrapMode::MIRRORED_REPEAT );
757   propertyMap.Insert( ImageVisual::Property::WRAP_MODE_V, WrapMode::REPEAT );
758
759   Visual::Base visual = factory.CreateVisual( propertyMap );
760   DALI_TEST_CHECK( visual );
761
762   TestGlAbstraction& gl = application.GetGlAbstraction();
763   TraceCallStack& textureTrace = gl.GetTextureTrace();
764   textureTrace.Enable(true);
765   TraceCallStack& texParameterTrace = gl.GetTexParameterTrace();
766   texParameterTrace.Enable( true );
767
768   DummyControl actor = DummyControl::New();
769   DummyControlImpl& dummyImpl = static_cast<DummyControlImpl&>(actor.GetImplementation());
770   dummyImpl.RegisterVisual( Control::CONTROL_PROPERTY_END_INDEX + 1, visual );
771   actor.SetSize(2000, 2000);
772   actor.SetParentOrigin(ParentOrigin::CENTER);
773   Stage::GetCurrent().Add( actor );
774
775   // loading started
776   application.SendNotification();
777   application.Render();
778   application.Render();
779   application.SendNotification();
780   BitmapLoader loader = BitmapLoader::GetLatestCreated();
781   DALI_TEST_CHECK( loader );
782   loader.WaitForLoading();// waiting until the image to be loaded
783   DALI_TEST_CHECK( loader.IsLoaded() );
784
785   DALI_TEST_CHECK( actor.GetRendererCount() == 1u );
786
787   DALI_TEST_EQUALS( textureTrace.FindMethod("BindTexture"), true, TEST_LOCATION );
788
789   // WITHOUT atlasing, the wrapping is handled by setting gl texture parameters
790   std::stringstream out;
791   out << GL_TEXTURE_2D << ", " << GL_TEXTURE_WRAP_S << ", " << GL_MIRRORED_REPEAT;
792   DALI_TEST_CHECK( texParameterTrace.FindMethodAndParams("TexParameteri", out.str()) );
793   out.str("");
794   out << GL_TEXTURE_2D << ", " << GL_TEXTURE_WRAP_T << ", " << GL_REPEAT;
795   DALI_TEST_CHECK( texParameterTrace.FindMethodAndParams("TexParameteri", out.str()) );
796
797   // test the uniforms which used to handle the wrap mode
798   Renderer renderer = actor.GetRendererAt( 0u );
799   DALI_TEST_CHECK( renderer );
800
801   Property::Value pixelAreaValue = renderer.GetProperty( renderer.GetPropertyIndex( "pixelArea" ) );
802   DALI_TEST_EQUALS( pixelAreaValue.Get<Vector4>(), pixelArea, TEST_LOCATION );
803   Vector4 pixelAreaUniform;
804   DALI_TEST_CHECK( gl.GetUniformValue<Vector4>( "pixelArea", pixelAreaUniform ) );
805   DALI_TEST_EQUALS( pixelArea, pixelAreaUniform, Math::MACHINE_EPSILON_100, TEST_LOCATION );
806
807   Property::Index wrapModeIndex = renderer.GetPropertyIndex( "wrapMode" );
808   DALI_TEST_CHECK(wrapModeIndex == Property::INVALID_INDEX);
809
810   actor.Unparent();
811   DALI_TEST_CHECK( actor.GetRendererCount() == 0u );
812
813   END_TEST;
814 }
815
816 int UtcDaliVisualFactoryGetNPatchVisual1(void)
817 {
818   ToolkitTestApplication application;
819   tet_infoline( "UtcDaliVisualFactoryGetNPatchVisual1: Request 9-patch visual with a Property::Map" );
820
821   VisualFactory factory = VisualFactory::Get();
822   DALI_TEST_CHECK( factory );
823
824   const unsigned int ninePatchImageHeight = 18;
825   const unsigned int ninePatchImageWidth = 28;
826   StretchRanges stretchRangesX;
827   stretchRangesX.PushBack( Uint16Pair( 2, 3 ) );
828   StretchRanges stretchRangesY;
829   stretchRangesY.PushBack( Uint16Pair( 4, 5 ) );
830   Integration::ResourcePointer ninePatchResource = CustomizeNinePatch( application, ninePatchImageWidth, ninePatchImageHeight, stretchRangesX, stretchRangesY );
831
832   Property::Map propertyMap;
833   propertyMap.Insert( Visual::Property::TYPE,  Visual::IMAGE );
834   propertyMap.Insert( ImageVisual::Property::URL,  TEST_NPATCH_FILE_NAME );
835   {
836     tet_infoline( "whole grid" );
837     Visual::Base visual = factory.CreateVisual( propertyMap );
838     DALI_TEST_CHECK( visual );
839
840
841     TestGlAbstraction& gl = application.GetGlAbstraction();
842     TraceCallStack& textureTrace = gl.GetTextureTrace();
843     textureTrace.Enable(true);
844
845     DummyControl actor = DummyControl::New();
846     TestVisualRender( application, actor, visual, 1u,
847                       ImageDimensions(ninePatchImageWidth, ninePatchImageHeight),
848                       ninePatchResource );
849
850     DALI_TEST_EQUALS( textureTrace.FindMethod("BindTexture"), true, TEST_LOCATION );
851   }
852
853   propertyMap.Insert( ImageVisual::Property::BORDER_ONLY,  true );
854   {
855     tet_infoline( "border only" );
856     Visual::Base visual = factory.CreateVisual( propertyMap );
857     DALI_TEST_CHECK( visual );
858
859     TestGlAbstraction& gl = application.GetGlAbstraction();
860     TraceCallStack& textureTrace = gl.GetTextureTrace();
861     textureTrace.Enable(true);
862
863     DummyControl actor = DummyControl::New();
864     TestVisualRender( application, actor, visual, 1u,
865                       ImageDimensions(ninePatchImageWidth, ninePatchImageHeight),
866                       ninePatchResource );
867
868     DALI_TEST_EQUALS( textureTrace.FindMethod("BindTexture"), true, TEST_LOCATION );
869   }
870
871   END_TEST;
872 }
873
874 int UtcDaliVisualFactoryGetNPatchVisual2(void)
875 {
876   ToolkitTestApplication application;
877   tet_infoline( "UtcDaliVisualFactoryGetNPatchVisual2: Request n-patch visual with a Property::Map" );
878
879   VisualFactory factory = VisualFactory::Get();
880   DALI_TEST_CHECK( factory );
881
882   const unsigned int ninePatchImageWidth = 18;
883   const unsigned int ninePatchImageHeight = 28;
884   StretchRanges stretchRangesX;
885   stretchRangesX.PushBack( Uint16Pair( 2, 3 ) );
886   stretchRangesX.PushBack( Uint16Pair( 5, 7 ) );
887   stretchRangesX.PushBack( Uint16Pair( 12, 15 ) );
888   StretchRanges stretchRangesY;
889   stretchRangesY.PushBack( Uint16Pair( 4, 5 ) );
890   stretchRangesY.PushBack( Uint16Pair( 8, 12 ) );
891   stretchRangesY.PushBack( Uint16Pair( 15, 16 ) );
892   stretchRangesY.PushBack( Uint16Pair( 25, 27 ) );
893   Integration::ResourcePointer ninePatchResource = CustomizeNinePatch( application, ninePatchImageWidth, ninePatchImageHeight, stretchRangesX, stretchRangesY );
894
895   Property::Map propertyMap;
896   propertyMap.Insert( Visual::Property::TYPE,  Visual::IMAGE );
897   propertyMap.Insert( ImageVisual::Property::URL,  TEST_NPATCH_FILE_NAME );
898   {
899     Visual::Base visual = factory.CreateVisual( propertyMap );
900     DALI_TEST_CHECK( visual );
901
902     TestGlAbstraction& gl = application.GetGlAbstraction();
903     TraceCallStack& textureTrace = gl.GetTextureTrace();
904     textureTrace.Enable(true);
905
906     DummyControl actor = DummyControl::New();
907     TestVisualRender( application, actor, visual, 1u,
908                       ImageDimensions(ninePatchImageWidth, ninePatchImageHeight),
909                       ninePatchResource );
910
911     DALI_TEST_EQUALS( textureTrace.FindMethod("BindTexture"), true, TEST_LOCATION );
912
913     Stage::GetCurrent().Remove( actor );
914     DALI_TEST_CHECK( actor.GetRendererCount() == 0u );
915   }
916
917   propertyMap.Insert( ImageVisual::Property::BORDER_ONLY,  true );
918   {
919     tet_infoline( "border only" );
920     Visual::Base visual = factory.CreateVisual( propertyMap );
921     DALI_TEST_CHECK( visual );
922
923     TestGlAbstraction& gl = application.GetGlAbstraction();
924     TraceCallStack& textureTrace = gl.GetTextureTrace();
925     textureTrace.Enable(true);
926     DummyControl actor = DummyControl::New();
927     TestVisualRender( application, actor, visual, 1u,
928                       ImageDimensions(ninePatchImageWidth, ninePatchImageHeight),
929                       ninePatchResource );
930
931
932     DALI_TEST_EQUALS( textureTrace.FindMethod("BindTexture"), true, TEST_LOCATION );
933
934     Stage::GetCurrent().Remove( actor );
935     DALI_TEST_CHECK( actor.GetRendererCount() == 0u );
936   }
937
938   END_TEST;
939 }
940
941 int UtcDaliVisualFactoryGetNPatchVisual3(void)
942 {
943   ToolkitTestApplication application;
944   tet_infoline( "UtcDaliVisualFactoryGetNPatchVisual3: Request 9-patch visual with an image url" );
945
946   VisualFactory factory = VisualFactory::Get();
947   DALI_TEST_CHECK( factory );
948
949   const unsigned int ninePatchImageHeight = 18;
950   const unsigned int ninePatchImageWidth = 28;
951   StretchRanges stretchRangesX;
952   stretchRangesX.PushBack( Uint16Pair( 2, 3 ) );
953   StretchRanges stretchRangesY;
954   stretchRangesY.PushBack( Uint16Pair( 4, 5 ) );
955   Integration::ResourcePointer ninePatchResource = CustomizeNinePatch( application, ninePatchImageWidth, ninePatchImageHeight, stretchRangesX, stretchRangesY );
956
957   Visual::Base visual = factory.CreateVisual( TEST_NPATCH_FILE_NAME, ImageDimensions() );
958   DALI_TEST_CHECK( visual );
959
960   TestGlAbstraction& gl = application.GetGlAbstraction();
961   TraceCallStack& textureTrace = gl.GetTextureTrace();
962   textureTrace.Enable(true);
963
964   DummyControl actor = DummyControl::New();
965   TestVisualRender( application, actor, visual, 1u,
966                     ImageDimensions(ninePatchImageWidth, ninePatchImageHeight),
967                     ninePatchResource );
968
969   DALI_TEST_EQUALS( textureTrace.FindMethod("BindTexture"), true, TEST_LOCATION );
970
971
972   ResourceImage image = ResourceImage::New(TEST_NPATCH_FILE_NAME);
973   Visual::Base nPatchVisual = factory.CreateVisual( image );
974   Vector2 visualSize( 20.f, 30.f ), naturalSize(0,0);
975   nPatchVisual.SetSize( visualSize );
976   DALI_TEST_EQUALS( nPatchVisual.GetSize(), visualSize, TEST_LOCATION );
977   nPatchVisual.GetNaturalSize( naturalSize );
978   DALI_TEST_EQUALS( naturalSize, Vector2( ninePatchImageWidth-2, ninePatchImageHeight-2 ), TEST_LOCATION );
979
980   END_TEST;
981 }
982
983 int UtcDaliVisualFactoryGetNPatchVisual4(void)
984 {
985   ToolkitTestApplication application;
986   tet_infoline( "UtcDaliVisualFactoryGetNPatchVisual4: Request n-patch visual with an image url" );
987
988   VisualFactory factory = VisualFactory::Get();
989   DALI_TEST_CHECK( factory );
990
991   const unsigned int ninePatchImageHeight = 18;
992   const unsigned int ninePatchImageWidth = 28;
993   StretchRanges stretchRangesX;
994   stretchRangesX.PushBack( Uint16Pair( 2, 3 ) );
995   stretchRangesX.PushBack( Uint16Pair( 5, 7 ) );
996   stretchRangesX.PushBack( Uint16Pair( 12, 15 ) );
997   StretchRanges stretchRangesY;
998   stretchRangesY.PushBack( Uint16Pair( 4, 5 ) );
999   stretchRangesY.PushBack( Uint16Pair( 8, 12 ) );
1000   stretchRangesY.PushBack( Uint16Pair( 15, 16 ) );
1001   stretchRangesY.PushBack( Uint16Pair( 25, 27 ) );
1002   Integration::ResourcePointer ninePatchResource = CustomizeNinePatch( application, ninePatchImageWidth, ninePatchImageHeight, stretchRangesX, stretchRangesY );
1003
1004   Visual::Base visual = factory.CreateVisual( TEST_NPATCH_FILE_NAME, ImageDimensions() );
1005   DALI_TEST_CHECK( visual );
1006
1007   TestGlAbstraction& gl = application.GetGlAbstraction();
1008   TraceCallStack& textureTrace = gl.GetTextureTrace();
1009   textureTrace.Enable(true);
1010
1011   DummyControl actor = DummyControl::New();
1012   TestVisualRender( application, actor, visual, 1u,
1013                     ImageDimensions(ninePatchImageWidth, ninePatchImageHeight),
1014                     ninePatchResource );
1015
1016   DALI_TEST_EQUALS( textureTrace.FindMethod("BindTexture"), true, TEST_LOCATION );
1017
1018   END_TEST;
1019 }
1020
1021 int UtcDaliVisualFactoryGetNPatchVisualN1(void)
1022 {
1023   //This should still load but display an error image
1024
1025   ToolkitTestApplication application;
1026   tet_infoline( "UtcDaliVisualFactoryGetNPatchVisualN: Request n-patch visual with an invalid image url" );
1027
1028   VisualFactory factory = VisualFactory::Get();
1029   DALI_TEST_CHECK( factory );
1030
1031   Visual::Base visual = factory.CreateVisual( "ERROR.9.jpg", ImageDimensions() );
1032   DALI_TEST_CHECK( visual );
1033
1034   //The testkit still has to load a bitmap for the broken renderer image
1035   Integration::Bitmap* bitmap = Integration::Bitmap::New(Integration::Bitmap::BITMAP_2D_PACKED_PIXELS, ResourcePolicy::OWNED_DISCARD);
1036   bitmap->GetPackedPixelsProfile()->ReserveBuffer( Pixel::RGBA8888, 100, 100, 100, 100 );
1037
1038   TestGlAbstraction& gl = application.GetGlAbstraction();
1039   TraceCallStack& textureTrace = gl.GetTextureTrace();
1040   textureTrace.Enable(true);
1041
1042   DummyControl actor = DummyControl::New();
1043   TestVisualRender( application, actor, visual, 1u,
1044                     ImageDimensions(),
1045                     Integration::ResourcePointer(bitmap) );
1046
1047   DALI_TEST_EQUALS( textureTrace.FindMethod("BindTexture"), true, TEST_LOCATION );
1048
1049   END_TEST;
1050 }
1051
1052 int UtcDaliVisualFactoryGetNPatchVisualN2(void)
1053 {
1054   //This should still load but display an error image
1055
1056   ToolkitTestApplication application;
1057   tet_infoline( "UtcDaliVisualFactoryGetNPatchVisualN: Request n-patch visual with an invalid URL" );
1058
1059   VisualFactory factory = VisualFactory::Get();
1060   DALI_TEST_CHECK( factory );
1061
1062   Property::Map propertyMap;
1063   propertyMap.Insert( Visual::Property::TYPE,  Visual::IMAGE );
1064   propertyMap.Insert( ImageVisual::Property::URL,  "ERROR.9.jpg" );
1065
1066   Visual::Base visual = factory.CreateVisual( propertyMap );
1067   DALI_TEST_CHECK( visual );
1068
1069   //The testkit still has to load a bitmap for the broken renderer image
1070   Integration::Bitmap* bitmap = Integration::Bitmap::New(Integration::Bitmap::BITMAP_2D_PACKED_PIXELS, ResourcePolicy::OWNED_DISCARD);
1071   bitmap->GetPackedPixelsProfile()->ReserveBuffer( Pixel::RGBA8888, 100, 100, 100, 100 );
1072
1073   TestGlAbstraction& gl = application.GetGlAbstraction();
1074   TraceCallStack& textureTrace = gl.GetTextureTrace();
1075   textureTrace.Enable(true);
1076   TraceCallStack& drawTrace = gl.GetDrawTrace();
1077   drawTrace.Enable(true);
1078
1079   DummyControl actor = DummyControl::New();
1080   TestVisualRender( application, actor, visual, 1u,
1081                     ImageDimensions(),
1082                     Integration::ResourcePointer(bitmap) );
1083
1084   DALI_TEST_EQUALS( textureTrace.FindMethod("BindTexture"), true, TEST_LOCATION );
1085
1086   END_TEST;
1087 }
1088
1089 int UtcDaliVisualFactoryGetNPatchVisualN3(void)
1090 {
1091   // Passing in an invalid visual type so we should not get a visual
1092
1093   ToolkitTestApplication application;
1094   tet_infoline( "UtcDaliVisualFactoryGetNPatchVisualN: Request n-patch visual with an invalid visual type" );
1095
1096   VisualFactory factory = VisualFactory::Get();
1097   DALI_TEST_CHECK( factory );
1098
1099   Property::Map propertyMap;
1100   propertyMap.Insert( Visual::Property::TYPE,  111 );
1101   propertyMap.Insert( ImageVisual::Property::URL,  "ERROR.9.jpg" );
1102
1103   Visual::Base visual = factory.CreateVisual( propertyMap );
1104   DALI_TEST_CHECK( !visual );
1105
1106   END_TEST;
1107 }
1108
1109 int UtcDaliVisualFactoryGetSvgVisual(void)
1110 {
1111   ToolkitTestApplication application;
1112   tet_infoline( "UtcDaliVisualFactoryGetSvgVisual: Request svg visual with a svg url" );
1113
1114   VisualFactory factory = VisualFactory::Get();
1115   Visual::Base visual = factory.CreateVisual( TEST_SVG_FILE_NAME, ImageDimensions() );
1116   DALI_TEST_CHECK( visual );
1117
1118   TestGlAbstraction& gl = application.GetGlAbstraction();
1119   TraceCallStack& textureTrace = gl.GetTextureTrace();
1120   textureTrace.Enable(true);
1121
1122   DummyControl actor = DummyControl::New();
1123   DummyControlImpl& dummyImpl = static_cast<DummyControlImpl&>(actor.GetImplementation());
1124   dummyImpl.RegisterVisual( Control::CONTROL_PROPERTY_END_INDEX + 1, visual );
1125   actor.SetSize( 200.f, 200.f );
1126   Stage::GetCurrent().Add( actor );
1127   visual.SetSize( Vector2(200.f, 200.f) );
1128
1129   application.SendNotification();
1130   application.Render();
1131
1132   // renderer is not added to actor until the rasterization is completed.
1133   DALI_TEST_CHECK( actor.GetRendererCount() == 0u );
1134
1135   EventThreadCallback* eventTrigger = EventThreadCallback::Get();
1136   CallbackBase* callback = eventTrigger->GetCallback();
1137
1138   eventTrigger->WaitingForTrigger( 1 );// waiting until the svg image is rasterized.
1139   CallbackBase::Execute( *callback );
1140
1141   // renderer is added to actor
1142   DALI_TEST_CHECK( actor.GetRendererCount() == 1u );
1143
1144   // waiting for the resource uploading
1145   application.SendNotification();
1146   application.Render();
1147
1148   DALI_TEST_EQUALS( textureTrace.FindMethod("BindTexture"), true, TEST_LOCATION );
1149
1150   END_TEST;
1151 }
1152
1153 int UtcDaliVisualFactoryGetSvgVisualLarge(void)
1154 {
1155   ToolkitTestApplication application;
1156   tet_infoline( "UtcDaliVisualFactoryGetSvgVisual: Request svg visual with a svg url" );
1157
1158   VisualFactory factory = VisualFactory::Get();
1159   Visual::Base visual = factory.CreateVisual( TEST_SVG_FILE_NAME, ImageDimensions( 2000, 2000 ) );
1160   DALI_TEST_CHECK( visual );
1161
1162   TestGlAbstraction& gl = application.GetGlAbstraction();
1163   TraceCallStack& textureTrace = gl.GetTextureTrace();
1164   textureTrace.Enable(true);
1165
1166   DummyControl actor = DummyControl::New();
1167   DummyControlImpl& dummyImpl = static_cast<DummyControlImpl&>(actor.GetImplementation());
1168   dummyImpl.RegisterVisual( Control::CONTROL_PROPERTY_END_INDEX + 1, visual );
1169   Stage::GetCurrent().Add( actor );
1170
1171   application.SendNotification();
1172   application.Render();
1173
1174   // renderer is not added to actor until the rasterization is completed.
1175   DALI_TEST_CHECK( actor.GetRendererCount() == 0u );
1176
1177   EventThreadCallback* eventTrigger = EventThreadCallback::Get();
1178   CallbackBase* callback = eventTrigger->GetCallback();
1179
1180   eventTrigger->WaitingForTrigger( 1 );// waiting until the svg image is rasterized.
1181   CallbackBase::Execute( *callback );
1182
1183   // renderer is added to actor
1184   DALI_TEST_CHECK( actor.GetRendererCount() == 1u );
1185
1186   // waiting for the resource uploading
1187   application.SendNotification();
1188   application.Render();
1189
1190   DALI_TEST_EQUALS( textureTrace.FindMethod("BindTexture"), true, TEST_LOCATION );
1191
1192   END_TEST;
1193 }
1194
1195 //Creates a mesh visual from the given propertyMap and tries to load it on stage in the given application.
1196 //This is expected to succeed, which will then pass the test.
1197 void MeshVisualLoadsCorrectlyTest( Property::Map& propertyMap, ToolkitTestApplication& application )
1198 {
1199   VisualFactory factory = VisualFactory::Get();
1200   DALI_TEST_CHECK( factory );
1201
1202   //Create a mesh visual.
1203   Visual::Base visual = factory.CreateVisual( propertyMap );
1204   DALI_TEST_CHECK( visual );
1205
1206   //Create an actor on stage to house the visual.
1207   DummyControl actor = DummyControl::New();
1208   DummyControlImpl& dummyImpl = static_cast<DummyControlImpl&>(actor.GetImplementation());
1209   dummyImpl.RegisterVisual( Control::CONTROL_PROPERTY_END_INDEX + 1, visual );
1210   actor.SetSize( 200.f, 200.f );
1211   Stage::GetCurrent().Add( actor );
1212   visual.SetSize( Vector2( 200.f, 200.f ) );
1213
1214   //Ensure set on stage.
1215   DALI_TEST_EQUALS( actor.GetRendererCount(), 1u, TEST_LOCATION );
1216
1217   //Attempt to render to queue resource load requests.
1218   application.SendNotification();
1219   application.Render( 0 );
1220
1221   //Tell the platform abstraction that the required resources have been loaded.
1222   TestPlatformAbstraction& platform = application.GetPlatform();
1223   platform.SetAllResourceRequestsAsLoaded();
1224
1225   //Render again to upload the now-loaded textures.
1226   application.SendNotification();
1227   application.Render( 0 );
1228
1229   Matrix testScaleMatrix;
1230   testScaleMatrix.SetIdentityAndScale( Vector3( 1.0, -1.0, 1.0 ) );
1231   Matrix actualScaleMatrix;
1232
1233   //Test to see if the object has been successfully loaded.
1234   DALI_TEST_CHECK( application.GetGlAbstraction().GetUniformValue<Matrix>( "uObjectMatrix", actualScaleMatrix ) );
1235   DALI_TEST_EQUALS( actualScaleMatrix, testScaleMatrix, Math::MACHINE_EPSILON_100, TEST_LOCATION );
1236
1237   //Finish by setting off stage, and ensuring this was successful.
1238   actor.Unparent();
1239   DALI_TEST_EQUALS( actor.GetRendererCount(), 0u, TEST_LOCATION );
1240 }
1241
1242 //Creates a mesh visual from the given propertyMap and tries to load it on stage in the given application.
1243 //This is expected to fail, which will then pass the test.
1244 void MeshVisualDoesNotLoadCorrectlyTest( Property::Map& propertyMap, ToolkitTestApplication& application )
1245 {
1246   VisualFactory factory = VisualFactory::Get();
1247   DALI_TEST_CHECK( factory );
1248
1249   //Create a mesh visual.
1250   Visual::Base visual = factory.CreateVisual( propertyMap );
1251   DALI_TEST_CHECK( visual );
1252
1253   //Create an actor on stage to house the visual.
1254   DummyControl actor = DummyControl::New();
1255   DummyControlImpl& dummyImpl = static_cast<DummyControlImpl&>(actor.GetImplementation());
1256   dummyImpl.RegisterVisual( Control::CONTROL_PROPERTY_END_INDEX + 1, visual );
1257   actor.SetSize( 200.f, 200.f );
1258   Stage::GetCurrent().Add( actor );
1259   visual.SetSize( Vector2( 200.f, 200.f ) );
1260
1261   //Ensure set on stage.
1262   DALI_TEST_EQUALS( actor.GetRendererCount(), 1u, TEST_LOCATION );
1263
1264   //Attempt to render to queue resource load requests.
1265   application.SendNotification();
1266   application.Render( 0 );
1267
1268   //Tell the platform abstraction that the required resources have been loaded.
1269   TestPlatformAbstraction& platform = application.GetPlatform();
1270   platform.SetAllResourceRequestsAsLoaded();
1271
1272   //Render again to upload the now-loaded textures.
1273   application.SendNotification();
1274   application.Render( 0 );
1275
1276   //Test to see if the object has not been loaded, as expected.
1277   Matrix scaleMatrix;
1278   DALI_TEST_CHECK( !application.GetGlAbstraction().GetUniformValue<Matrix>( "uObjectMatrix", scaleMatrix ) );
1279
1280   //Finish by setting off stage, and ensuring this was successful.
1281   actor.Unparent();
1282   DALI_TEST_EQUALS( actor.GetRendererCount(), 0u, TEST_LOCATION );
1283 }
1284
1285 //Test if mesh loads correctly when supplied with only the bare minimum requirements, an object file.
1286 int UtcDaliVisualFactoryGetMeshVisual1(void)
1287 {
1288   //Set up test application first, so everything else can be handled.
1289   ToolkitTestApplication application;
1290
1291   tet_infoline( "UtcDaliVisualFactoryGetMeshVisual1:  Request mesh visual with a valid object file only" );
1292
1293
1294   //Set up visual properties.
1295   Property::Map propertyMap;
1296   propertyMap.Insert( Visual::Property::TYPE,  Visual::MESH );
1297   propertyMap.Insert( MeshVisual::Property::OBJECT_URL, TEST_OBJ_FILE_NAME );
1298
1299   //Test to see if mesh loads correctly.
1300   MeshVisualLoadsCorrectlyTest( propertyMap, application );
1301
1302   END_TEST;
1303 }
1304
1305
1306 //Test if mesh loads correctly when supplied with an object file as well as a blank material file and images directory.
1307 int UtcDaliVisualFactoryGetMeshVisual2(void)
1308 {
1309   //Set up test application first, so everything else can be handled.
1310   ToolkitTestApplication application;
1311
1312   tet_infoline( "UtcDaliVisualFactoryGetMeshVisual2:  Request mesh visual with blank material file and images directory" );
1313
1314   //Set up visual properties.
1315   Property::Map propertyMap;
1316   propertyMap.Insert( Visual::Property::TYPE, Visual::MESH );
1317   propertyMap.Insert( MeshVisual::Property::OBJECT_URL, TEST_OBJ_FILE_NAME );
1318   propertyMap.Insert( MeshVisual::Property::MATERIAL_URL, "" );
1319   propertyMap.Insert( MeshVisual::Property::TEXTURES_PATH, "" );
1320
1321   //Test to see if mesh loads correctly.
1322   MeshVisualLoadsCorrectlyTest( propertyMap, application );
1323
1324   END_TEST;
1325 }
1326
1327 //Test if mesh loads correctly when supplied with all main parameters, an object file, a material file and a directory location.
1328 int UtcDaliVisualFactoryGetMeshVisual3(void)
1329 {
1330   //Set up test application first, so everything else can be handled.
1331   ToolkitTestApplication application;
1332
1333   tet_infoline( "UtcDaliVisualFactoryGetMeshVisual3:  Request mesh visual with all parameters correct" );
1334
1335   //Set up visual properties.
1336   Property::Map propertyMap;
1337   propertyMap.Insert( Visual::Property::TYPE, Visual::MESH );
1338   propertyMap.Insert( MeshVisual::Property::OBJECT_URL, TEST_OBJ_FILE_NAME );
1339   propertyMap.Insert( MeshVisual::Property::MATERIAL_URL, TEST_MTL_FILE_NAME );
1340   propertyMap.Insert( MeshVisual::Property::TEXTURES_PATH, TEST_RESOURCE_DIR "/" );
1341
1342   //Test to see if mesh loads correctly.
1343   MeshVisualLoadsCorrectlyTest( propertyMap, application );
1344
1345   END_TEST;
1346 }
1347
1348 //Test if mesh visual can load a correctly supplied mesh without a normal map or gloss map in the material file.
1349 int UtcDaliVisualFactoryGetMeshVisual4(void)
1350 {
1351   //Set up test application first, so everything else can be handled.
1352   ToolkitTestApplication application;
1353
1354   tet_infoline( "UtcDaliVisualFactoryGetMeshVisual4:  Request mesh visual with diffuse texture but not normal or gloss." );
1355
1356
1357   //Set up visual properties.
1358   Property::Map propertyMap;
1359   propertyMap.Insert( Visual::Property::TYPE, Visual::MESH );
1360   propertyMap.Insert( MeshVisual::Property::OBJECT_URL, TEST_OBJ_FILE_NAME );
1361   propertyMap.Insert( MeshVisual::Property::MATERIAL_URL, TEST_SIMPLE_MTL_FILE_NAME );
1362   propertyMap.Insert( MeshVisual::Property::TEXTURES_PATH, TEST_RESOURCE_DIR "/" );
1363
1364   //Test to see if mesh loads correctly.
1365   MeshVisualLoadsCorrectlyTest( propertyMap, application );
1366
1367
1368   END_TEST;
1369 }
1370
1371 //Test if mesh visual can load when made to use diffuse textures only.
1372 int UtcDaliVisualFactoryGetMeshVisual5(void)
1373 {
1374   //Set up test application first, so everything else can be handled.
1375   ToolkitTestApplication application;
1376
1377   tet_infoline( "UtcDaliVisualFactoryGetMeshVisual5:  Request mesh visual and make it only use diffuse textures." );
1378
1379   //Set up visual properties.
1380   Property::Map propertyMap;
1381   propertyMap.Insert( Visual::Property::TYPE, Visual::MESH );
1382   propertyMap.Insert( MeshVisual::Property::OBJECT_URL, TEST_OBJ_FILE_NAME );
1383   propertyMap.Insert( MeshVisual::Property::MATERIAL_URL, TEST_MTL_FILE_NAME );
1384   propertyMap.Insert( MeshVisual::Property::TEXTURES_PATH, TEST_RESOURCE_DIR "/" );
1385   propertyMap.Insert( MeshVisual::Property::SHADING_MODE, MeshVisual::ShadingMode::TEXTURED_WITH_SPECULAR_LIGHTING );
1386
1387   //Test to see if mesh loads correctly.
1388   MeshVisualLoadsCorrectlyTest( propertyMap, application );
1389
1390
1391   END_TEST;
1392 }
1393
1394 //Test if mesh visual can load when made to not use the supplied textures.
1395 int UtcDaliVisualFactoryGetMeshVisual6(void)
1396 {
1397   //Set up test application first, so everything else can be handled.
1398   ToolkitTestApplication application;
1399
1400   tet_infoline( "UtcDaliVisualFactoryGetMeshVisual6:  Request mesh visual and make it not use any textures." );
1401
1402   //Set up visual properties.
1403   Property::Map propertyMap;
1404   propertyMap.Insert( Visual::Property::TYPE, Visual::MESH );
1405   propertyMap.Insert( MeshVisual::Property::OBJECT_URL, TEST_OBJ_FILE_NAME );
1406   propertyMap.Insert( MeshVisual::Property::MATERIAL_URL, TEST_MTL_FILE_NAME );
1407   propertyMap.Insert( MeshVisual::Property::TEXTURES_PATH, TEST_RESOURCE_DIR "/" );
1408   propertyMap.Insert( MeshVisual::Property::SHADING_MODE, MeshVisual::ShadingMode::TEXTURELESS_WITH_DIFFUSE_LIGHTING );
1409
1410   //Test to see if mesh loads correctly.
1411   MeshVisualLoadsCorrectlyTest( propertyMap, application );
1412
1413   END_TEST;
1414 }
1415 //Test if mesh visual loads correctly when light position is manually set.
1416 int UtcDaliVisualFactoryGetMeshVisual7(void)
1417 {
1418   //Set up test application first, so everything else can be handled.
1419   ToolkitTestApplication application;
1420
1421
1422   tet_infoline( "UtcDaliVisualFactoryGetMeshVisual7:  Request mesh visual with custom light position." );
1423
1424   //Set up visual properties.
1425   Property::Map propertyMap;
1426   propertyMap.Insert( Visual::Property::TYPE, Visual::MESH );
1427   propertyMap.Insert( MeshVisual::Property::OBJECT_URL, TEST_OBJ_FILE_NAME );
1428   propertyMap.Insert( MeshVisual::Property::MATERIAL_URL, TEST_MTL_FILE_NAME );
1429   propertyMap.Insert( MeshVisual::Property::TEXTURES_PATH, TEST_RESOURCE_DIR "/" );
1430   propertyMap.Insert( MeshVisual::Property::LIGHT_POSITION, Vector3( 0.0, 1.0, 2.0 ) );
1431
1432   //Test to see if mesh loads correctly.
1433   MeshVisualLoadsCorrectlyTest( propertyMap, application );
1434
1435   END_TEST;
1436 }
1437
1438 //Test if mesh visual loads correctly when supplied an object file without face normals or texture points.
1439 //Note that this notably tests object loader functionality.
1440 int UtcDaliVisualFactoryGetMeshVisual8(void)
1441 {
1442   //Set up test application first, so everything else can be handled.
1443   ToolkitTestApplication application;
1444
1445   tet_infoline( "UtcDaliVisualFactoryGetMeshVisual5:  Request mesh visual with normal-less object file." );
1446
1447   //Set up visual properties.
1448   Property::Map propertyMap;
1449   propertyMap.Insert( Visual::Property::TYPE, Visual::MESH );
1450   propertyMap.Insert( MeshVisual::Property::OBJECT_URL, TEST_SIMPLE_OBJ_FILE_NAME );
1451   propertyMap.Insert( MeshVisual::Property::MATERIAL_URL, TEST_MTL_FILE_NAME );
1452   propertyMap.Insert( MeshVisual::Property::TEXTURES_PATH, TEST_RESOURCE_DIR "/" );
1453
1454   //Test to see if mesh loads correctly.
1455   MeshVisualLoadsCorrectlyTest( propertyMap, application );
1456
1457   END_TEST;
1458 }
1459
1460 //Test if mesh visual handles the case of lacking an object file.
1461 int UtcDaliVisualFactoryGetMeshVisualN1(void)
1462 {
1463   //Set up test application first, so everything else can be handled.
1464   ToolkitTestApplication application;
1465
1466   tet_infoline( "UtcDaliVisualFactoryGetMeshVisualN1:  Request mesh visual without object file" );
1467
1468   //Set up visual properties.
1469   Property::Map propertyMap;
1470   propertyMap.Insert( Visual::Property::TYPE, Visual::MESH );
1471   propertyMap.Insert( MeshVisual::Property::MATERIAL_URL, TEST_MTL_FILE_NAME );
1472   propertyMap.Insert( MeshVisual::Property::TEXTURES_PATH, TEST_RESOURCE_DIR "/" );
1473
1474   //Test to see if mesh doesn't load with these properties, as expected.
1475   MeshVisualDoesNotLoadCorrectlyTest( propertyMap, application );
1476
1477
1478   END_TEST;
1479 }
1480
1481 //Test if mesh visual handles the case of being passed invalid material and images urls.
1482 int UtcDaliVisualFactoryGetMeshVisualN2(void)
1483 {
1484   //Set up test application first, so everything else can be handled.
1485   ToolkitTestApplication application;
1486
1487   tet_infoline( "UtcDaliVisualFactoryGetMeshVisualN2:  Request mesh visual with invalid material and images urls" );
1488
1489   //Set up visual properties.
1490   Property::Map propertyMap;
1491   propertyMap.Insert( Visual::Property::TYPE, Visual::MESH );
1492   propertyMap.Insert( MeshVisual::Property::OBJECT_URL, TEST_OBJ_FILE_NAME );
1493   propertyMap.Insert( MeshVisual::Property::MATERIAL_URL, "invalid" );
1494   propertyMap.Insert( MeshVisual::Property::TEXTURES_PATH, "also invalid" );
1495
1496   //Test to see if mesh doesn't load with these properties, as expected.
1497   MeshVisualDoesNotLoadCorrectlyTest( propertyMap, application );
1498
1499
1500   END_TEST;
1501 }
1502
1503 //Test if mesh visual handles the case of being passed an invalid object url
1504 int UtcDaliVisualFactoryGetMeshVisualN3(void)
1505 {
1506   //Set up test application first, so everything else can be handled.
1507   ToolkitTestApplication application;
1508   tet_infoline( "UtcDaliVisualFactoryGetMeshVisualN3:  Request mesh visual with invalid object url" );
1509
1510
1511   //Set up visual properties.
1512   Property::Map propertyMap;
1513   propertyMap.Insert( Visual::Property::TYPE, Visual::MESH );
1514   propertyMap.Insert( MeshVisual::Property::OBJECT_URL, "invalid" );
1515   propertyMap.Insert( MeshVisual::Property::MATERIAL_URL, TEST_MTL_FILE_NAME );
1516   propertyMap.Insert( MeshVisual::Property::TEXTURES_PATH, TEST_RESOURCE_DIR "/" );
1517
1518   //Test to see if mesh doesn't load with these properties, as expected.
1519   MeshVisualDoesNotLoadCorrectlyTest( propertyMap, application );
1520
1521   END_TEST;
1522 }
1523
1524 //Creates a primitive visual with the given property map and tests to see if it correctly loads in the given application.
1525 void TestPrimitiveVisualWithProperties( Property::Map& propertyMap, ToolkitTestApplication& application )
1526 {
1527   VisualFactory factory = VisualFactory::Get();
1528   DALI_TEST_CHECK( factory );
1529
1530   //Create a primitive visual.
1531   Visual::Base visual = factory.CreateVisual( propertyMap );
1532   DALI_TEST_CHECK( visual );
1533
1534   //Create an actor on stage to house the visual.
1535   DummyControl actor = DummyControl::New();
1536   DummyControlImpl& dummyImpl = static_cast<DummyControlImpl&>(actor.GetImplementation());
1537   dummyImpl.RegisterVisual( Control::CONTROL_PROPERTY_END_INDEX + 1, visual );
1538
1539   actor.SetSize( 200.f, 200.f );
1540   Stage::GetCurrent().Add( actor );
1541   visual.SetSize( Vector2( 200.f, 200.f ) );
1542
1543   //Ensure set on stage.
1544   DALI_TEST_EQUALS( actor.GetRendererCount(), 1u, TEST_LOCATION );
1545
1546   //Tell test application to load the visual.
1547   application.SendNotification();
1548   application.Render(0);
1549
1550   Matrix testScaleMatrix;
1551   testScaleMatrix.SetIdentityAndScale( Vector3( 1.0, -1.0, 1.0 ) );
1552   Matrix actualScaleMatrix;
1553
1554   //Test to see if the object has been successfully loaded.
1555   DALI_TEST_CHECK( application.GetGlAbstraction().GetUniformValue<Matrix>( "uObjectMatrix", actualScaleMatrix ) );
1556   DALI_TEST_EQUALS( actualScaleMatrix, testScaleMatrix, Math::MACHINE_EPSILON_100, TEST_LOCATION );
1557
1558   //Finish by setting off stage, and ensuring this was successful.
1559   actor.Unparent();
1560   DALI_TEST_EQUALS( actor.GetRendererCount(), 0u, TEST_LOCATION );
1561 }
1562
1563 //Test if primitive shape loads correctly when supplied with only the bare minimum requirements, the shape to use.
1564 int UtcDaliVisualFactoryGetPrimitiveVisual1(void)
1565 {
1566   //Set up test application first, so everything else can be handled.
1567   ToolkitTestApplication application;
1568
1569   tet_infoline( "UtcDaliVisualFactoryGetPrimitiveVisual1:  Request primitive visual with a shape only" );
1570
1571   //Set up visual properties.
1572   Property::Map propertyMap;
1573   propertyMap.Insert( Visual::Property::TYPE, Visual::PRIMITIVE );
1574   propertyMap.Insert( PrimitiveVisual::Property::SHAPE, PrimitiveVisual::Shape::CUBE );
1575
1576   //Test to see if shape loads correctly.
1577   TestPrimitiveVisualWithProperties( propertyMap, application );
1578
1579   END_TEST;
1580 }
1581
1582 //Test if primitive shape loads correctly when supplied with all possible parameters
1583 int UtcDaliVisualFactoryGetPrimitiveVisual2(void)
1584 {
1585   //Set up test application first, so everything else can be handled.
1586   ToolkitTestApplication application;
1587
1588   tet_infoline( "UtcDaliVisualFactoryGetPrimitiveVisual2:  Request primitive visual with everything" );
1589
1590   //Set up visual properties.
1591   Property::Map propertyMap;
1592   propertyMap.Insert( Visual::Property::TYPE, Visual::PRIMITIVE );
1593   propertyMap.Insert( PrimitiveVisual::Property::SHAPE, PrimitiveVisual::Shape::CUBE );
1594   propertyMap.Insert( PrimitiveVisual::Property::MIX_COLOR, Vector4( 0.5, 0.5, 0.5, 1.0 ) );
1595   propertyMap.Insert( PrimitiveVisual::Property::SLICES, 10 );
1596   propertyMap.Insert( PrimitiveVisual::Property::STACKS, 20 );
1597   propertyMap.Insert( PrimitiveVisual::Property::SCALE_TOP_RADIUS, 30.0f );
1598   propertyMap.Insert( PrimitiveVisual::Property::SCALE_BOTTOM_RADIUS, 40.0f );
1599   propertyMap.Insert( PrimitiveVisual::Property::SCALE_HEIGHT, 50.0f );
1600   propertyMap.Insert( PrimitiveVisual::Property::SCALE_RADIUS, 60.0f );
1601   propertyMap.Insert( PrimitiveVisual::Property::BEVEL_PERCENTAGE, 0.7f );
1602   propertyMap.Insert( PrimitiveVisual::Property::BEVEL_SMOOTHNESS, 0.8f );
1603   propertyMap.Insert( MeshVisual::Property::LIGHT_POSITION, Vector3( 0.9, 1.0, 1.1 ) );
1604
1605   //Test to see if shape loads correctly.
1606   TestPrimitiveVisualWithProperties( propertyMap, application );
1607
1608   END_TEST;
1609 }
1610
1611 //Test if primitive shape loads a sphere correctly.
1612 int UtcDaliVisualFactoryGetPrimitiveVisual3(void)
1613 {
1614   //Set up test application first, so everything else can be handled.
1615   ToolkitTestApplication application;
1616
1617   tet_infoline( "UtcDaliVisualFactoryGetPrimitiveVisual3:  Request primitive visual to display a sphere" );
1618
1619   //Set up visual properties.
1620   Property::Map propertyMap;
1621   propertyMap.Insert( Visual::Property::TYPE, Visual::PRIMITIVE );
1622   propertyMap.Insert( PrimitiveVisual::Property::SHAPE, PrimitiveVisual::Shape::SPHERE );
1623   propertyMap.Insert( PrimitiveVisual::Property::MIX_COLOR, Vector4( 0.5, 0.5, 0.5, 1.0 ) );
1624   propertyMap.Insert( PrimitiveVisual::Property::SLICES, 10 );
1625   propertyMap.Insert( PrimitiveVisual::Property::STACKS, 20 );
1626
1627   //Test to see if shape loads correctly.
1628   TestPrimitiveVisualWithProperties( propertyMap, application );
1629
1630   END_TEST;
1631 }
1632
1633 //Test if primitive shape loads a conic section correctly.
1634 int UtcDaliVisualFactoryGetPrimitiveVisual4(void)
1635 {
1636   //Set up test application first, so everything else can be handled.
1637   ToolkitTestApplication application;
1638
1639   tet_infoline( "UtcDaliVisualFactoryGetPrimitiveVisual4:  Request primitive visual to display a conic section" );
1640
1641   //Set up visual properties.
1642   Property::Map propertyMap;
1643   propertyMap.Insert( Visual::Property::TYPE, Visual::PRIMITIVE );
1644   propertyMap.Insert( PrimitiveVisual::Property::SHAPE, PrimitiveVisual::Shape::CONICAL_FRUSTRUM );
1645   propertyMap.Insert( PrimitiveVisual::Property::MIX_COLOR, Vector4( 0.5, 0.5, 0.5, 1.0 ) );
1646   propertyMap.Insert( PrimitiveVisual::Property::SLICES, 10 );
1647   propertyMap.Insert( PrimitiveVisual::Property::SCALE_TOP_RADIUS, 30.0f );
1648   propertyMap.Insert( PrimitiveVisual::Property::SCALE_BOTTOM_RADIUS, 40.0f );
1649   propertyMap.Insert( PrimitiveVisual::Property::SCALE_HEIGHT, 50.0f );
1650
1651   //Test to see if shape loads correctly.
1652   TestPrimitiveVisualWithProperties( propertyMap, application );
1653
1654   END_TEST;
1655 }
1656
1657 //Test if primitive shape loads a bevelled cube correctly.
1658 int UtcDaliVisualFactoryGetPrimitiveVisual5(void)
1659 {
1660   //Set up test application first, so everything else can be handled.
1661   ToolkitTestApplication application;
1662
1663   tet_infoline( "UtcDaliVisualFactoryGetPrimitiveVisual5:  Request primitive visual to display a bevelled cube" );
1664
1665   //Set up visual properties.
1666   Property::Map propertyMap;
1667   propertyMap.Insert( Visual::Property::TYPE, Visual::PRIMITIVE );
1668   propertyMap.Insert( PrimitiveVisual::Property::SHAPE, PrimitiveVisual::Shape::BEVELLED_CUBE );
1669   propertyMap.Insert( PrimitiveVisual::Property::MIX_COLOR, Vector4( 0.5, 0.5, 0.5, 1.0 ) );
1670   propertyMap.Insert( PrimitiveVisual::Property::BEVEL_PERCENTAGE, 0.7f );
1671
1672   //Test to see if shape loads correctly.
1673   TestPrimitiveVisualWithProperties( propertyMap, application );
1674
1675   END_TEST;
1676 }
1677
1678 //Test if primitive shape loads an octahedron correctly.
1679 int UtcDaliVisualFactoryGetPrimitiveVisual6(void)
1680 {
1681   //Set up test application first, so everything else can be handled.
1682   ToolkitTestApplication application;
1683
1684   tet_infoline( "UtcDaliVisualFactoryGetPrimitiveVisual6:  Request primitive visual to display an octahedron" );
1685
1686   //Set up visual properties.
1687   Property::Map propertyMap;
1688   propertyMap.Insert( Visual::Property::TYPE, Visual::PRIMITIVE );
1689   propertyMap.Insert( PrimitiveVisual::Property::SHAPE, PrimitiveVisual::Shape::OCTAHEDRON );
1690   propertyMap.Insert( PrimitiveVisual::Property::MIX_COLOR, Vector4( 0.5, 0.5, 0.5, 1.0 ) );
1691
1692   //Test to see if shape loads correctly.
1693   TestPrimitiveVisualWithProperties( propertyMap, application );
1694
1695   END_TEST;
1696 }
1697
1698 //Test if primitive shape loads a cone correctly.
1699 int UtcDaliVisualFactoryGetPrimitiveVisual7(void)
1700 {
1701   //Set up test application first, so everything else can be handled.
1702   ToolkitTestApplication application;
1703
1704   tet_infoline( "UtcDaliVisualFactoryGetPrimitiveVisual7:  Request primitive visual to display a cone" );
1705
1706   //Set up visual properties.
1707   Property::Map propertyMap;
1708   propertyMap.Insert( Visual::Property::TYPE, Visual::PRIMITIVE );
1709   propertyMap.Insert( PrimitiveVisual::Property::SHAPE, PrimitiveVisual::Shape::CONE );
1710   propertyMap.Insert( PrimitiveVisual::Property::MIX_COLOR, Vector4( 0.5, 0.5, 0.5, 1.0 ) );
1711   propertyMap.Insert( PrimitiveVisual::Property::SLICES, 10 );
1712   propertyMap.Insert( PrimitiveVisual::Property::SCALE_TOP_RADIUS, 30.0f );
1713   propertyMap.Insert( PrimitiveVisual::Property::SCALE_HEIGHT, 50.0f );
1714
1715   //Test to see if shape loads correctly.
1716   TestPrimitiveVisualWithProperties( propertyMap, application );
1717
1718   END_TEST;
1719 }
1720
1721 //Test if primitive shape loads correctly when light position is manually set.
1722 int UtcDaliVisualFactoryGetPrimitiveVisual8(void)
1723 {
1724   //Set up test application first, so everything else can be handled.
1725   ToolkitTestApplication application;
1726
1727   tet_infoline( "UtcDaliVisualFactoryGetPrimitiveVisual8:  Request primitive visual with set light position" );
1728
1729   //Set up visual properties.
1730   Property::Map propertyMap;
1731   propertyMap.Insert( Visual::Property::TYPE, Visual::PRIMITIVE );
1732   propertyMap.Insert( PrimitiveVisual::Property::SHAPE, PrimitiveVisual::Shape::SPHERE );
1733   propertyMap.Insert( PrimitiveVisual::Property::MIX_COLOR, Vector4( 0.5, 0.5, 0.5, 1.0 ) );
1734   propertyMap.Insert( MeshVisual::Property::LIGHT_POSITION, Vector3( 0.0, 1.0, 2.0 ) );
1735
1736   //Test to see if shape loads correctly.
1737   TestPrimitiveVisualWithProperties( propertyMap, application );
1738
1739   END_TEST;
1740 }
1741
1742 //Test if primitive shape loads correctly when told to use too many slices.
1743 int UtcDaliVisualFactoryGetPrimitiveVisual9(void)
1744 {
1745   //Set up test application first, so everything else can be handled.
1746   ToolkitTestApplication application;
1747
1748   tet_infoline( "UtcDaliVisualFactoryGetPrimitiveVisual9:  Request primitive visual with above-cap slices." );
1749
1750   //Set up visual properties.
1751   Property::Map propertyMap;
1752   propertyMap.Insert( Visual::Property::TYPE, Visual::PRIMITIVE );
1753   propertyMap.Insert( PrimitiveVisual::Property::SHAPE, PrimitiveVisual::Shape::SPHERE );
1754   propertyMap.Insert( PrimitiveVisual::Property::SLICES, Property::Value( 1000000 ) );
1755
1756   //Test to see if shape loads correctly.
1757   TestPrimitiveVisualWithProperties( propertyMap, application );
1758
1759   END_TEST;
1760 }
1761
1762 //Test if primitive shape loads correctly when told to use too few slices. (2 slices or less.)
1763 int UtcDaliVisualFactoryGetPrimitiveVisual10(void)
1764 {
1765   //Set up test application first, so everything else can be handled.
1766   ToolkitTestApplication application;
1767
1768   tet_infoline( "UtcDaliVisualFactoryGetPrimitiveVisual10:  Request primitive visual with too few slices." );
1769
1770   //Set up visual properties.
1771   Property::Map propertyMap;
1772   propertyMap.Insert( Visual::Property::TYPE, Visual::PRIMITIVE );
1773   propertyMap.Insert( PrimitiveVisual::Property::SHAPE, PrimitiveVisual::Shape::SPHERE );
1774   propertyMap.Insert( PrimitiveVisual::Property::SLICES, Property::Value( 2 ) );
1775
1776   //Test to see if shape loads correctly.
1777   TestPrimitiveVisualWithProperties( propertyMap, application );
1778
1779   END_TEST;
1780 }
1781
1782 //Test if primitive shape loads correctly when told to use too many stacks.
1783 int UtcDaliVisualFactoryGetPrimitiveVisual11(void)
1784 {
1785   //Set up test application first, so everything else can be handled.
1786   ToolkitTestApplication application;
1787
1788   tet_infoline( "UtcDaliVisualFactoryGetPrimitiveVisual11:  Request primitive visual with too many stacks." );
1789
1790   //Set up visual properties.
1791   Property::Map propertyMap;
1792   propertyMap.Insert( Visual::Property::TYPE, Visual::PRIMITIVE );
1793   propertyMap.Insert( PrimitiveVisual::Property::SHAPE, PrimitiveVisual::Shape::SPHERE );
1794   propertyMap.Insert( PrimitiveVisual::Property::STACKS, Property::Value( 1000000 ) );
1795
1796   //Test to see if shape loads correctly.
1797   TestPrimitiveVisualWithProperties( propertyMap, application );
1798
1799   END_TEST;
1800 }
1801
1802 //Test if primitive shape loads correctly when told to use too few stacks. (1 stack or less.)
1803 int UtcDaliVisualFactoryGetPrimitiveVisual12(void)
1804 {
1805   //Set up test application first, so everything else can be handled.
1806   ToolkitTestApplication application;
1807
1808   tet_infoline( "UtcDaliVisualFactoryGetPrimitiveVisual12:  Request primitive visual with too few stacks." );
1809
1810   //Set up visual properties.
1811   Property::Map propertyMap;
1812   propertyMap.Insert( Visual::Property::TYPE, Visual::PRIMITIVE );
1813   propertyMap.Insert( PrimitiveVisual::Property::SHAPE, PrimitiveVisual::Shape::SPHERE );
1814   propertyMap.Insert( PrimitiveVisual::Property::STACKS, Property::Value( 1 ) );
1815
1816   //Test to see if shape loads correctly.
1817   TestPrimitiveVisualWithProperties( propertyMap, application );
1818
1819   END_TEST;
1820 }
1821
1822 //Test if primitive shape loads correctly when told to use invalid (zero or negative) dimensions.
1823 int UtcDaliVisualFactoryGetPrimitiveVisual13(void)
1824 {
1825   //Set up test application first, so everything else can be handled.
1826   ToolkitTestApplication application;
1827
1828   tet_infoline( "UtcDaliVisualFactoryGetPrimitiveVisual13:  Request primitive visual with invalid scale dimensions." );
1829
1830   //Set up visual properties.
1831   Property::Map propertyMap;
1832   propertyMap.Insert( Visual::Property::TYPE, Visual::PRIMITIVE );
1833   propertyMap.Insert( PrimitiveVisual::Property::SHAPE, PrimitiveVisual::Shape::SPHERE );
1834   propertyMap.Insert( PrimitiveVisual::Property::SCALE_DIMENSIONS, Vector3::ZERO );
1835
1836   //Test to see if shape loads correctly.
1837   TestPrimitiveVisualWithProperties( propertyMap, application );
1838
1839   END_TEST;
1840 }
1841
1842 //Test if primitive shape loads correctly when told to use too low a bevel percentage.
1843 int UtcDaliVisualFactoryGetPrimitiveVisual14(void)
1844 {
1845   //Set up test application first, so everything else can be handled.
1846   ToolkitTestApplication application;
1847
1848   tet_infoline( "UtcDaliVisualFactoryGetPrimitiveVisual14:  Request primitive visual with too low a bevel percentage." );
1849
1850   //Set up visual properties.
1851   Property::Map propertyMap;
1852   propertyMap.Insert( Visual::Property::TYPE, Visual::PRIMITIVE );
1853   propertyMap.Insert( PrimitiveVisual::Property::SHAPE, PrimitiveVisual::Shape::SPHERE );
1854   propertyMap.Insert( PrimitiveVisual::Property::BEVEL_PERCENTAGE, Property::Value( -1.0f ) );
1855
1856   //Test to see if shape loads correctly.
1857   TestPrimitiveVisualWithProperties( propertyMap, application );
1858
1859   END_TEST;
1860 }
1861
1862 //Test if primitive shape loads correctly when told to use too high a bevel percentage.
1863 int UtcDaliVisualFactoryGetPrimitiveVisual15(void)
1864 {
1865   //Set up test application first, so everything else can be handled.
1866   ToolkitTestApplication application;
1867
1868   tet_infoline( "UtcDaliVisualFactoryGetPrimitiveVisual15:  Request primitive visual with too high a bevel percentage." );
1869
1870   //Set up visual properties.
1871   Property::Map propertyMap;
1872   propertyMap.Insert( Visual::Property::TYPE, Visual::PRIMITIVE );
1873   propertyMap.Insert( PrimitiveVisual::Property::SHAPE, PrimitiveVisual::Shape::SPHERE );
1874   propertyMap.Insert( PrimitiveVisual::Property::BEVEL_PERCENTAGE, Property::Value( 2.0f ) );
1875
1876   //Test to see if shape loads correctly.
1877   TestPrimitiveVisualWithProperties( propertyMap, application );
1878
1879   END_TEST;
1880 }
1881
1882 //Test if primitive shape loads correctly when told to use too low a bevel smoothness.
1883 int UtcDaliVisualFactoryGetPrimitiveVisual16(void)
1884 {
1885   //Set up test application first, so everything else can be handled.
1886   ToolkitTestApplication application;
1887
1888   tet_infoline( "UtcDaliVisualFactoryGetPrimitiveVisual16:  Request primitive visual with too low a bevel smoothness." );
1889
1890   //Set up visual properties.
1891   Property::Map propertyMap;
1892   propertyMap.Insert( Visual::Property::TYPE, Visual::PRIMITIVE );
1893   propertyMap.Insert( PrimitiveVisual::Property::SHAPE, PrimitiveVisual::Shape::SPHERE );
1894   propertyMap.Insert( PrimitiveVisual::Property::BEVEL_SMOOTHNESS, Property::Value( -1.0f ) );
1895
1896   //Test to see if shape loads correctly.
1897   TestPrimitiveVisualWithProperties( propertyMap, application );
1898
1899   END_TEST;
1900 }
1901
1902 //Test if primitive shape loads correctly when told to use too high a bevel smoothness.
1903 int UtcDaliVisualFactoryGetPrimitiveVisual17(void)
1904 {
1905   //Set up test application first, so everything else can be handled.
1906   ToolkitTestApplication application;
1907
1908   tet_infoline( "UtcDaliVisualFactoryGetPrimitiveVisual17:  Request primitive visual with too high a bevel smoothness." );
1909
1910   //Set up visual properties.
1911   Property::Map propertyMap;
1912   propertyMap.Insert( Visual::Property::TYPE, Visual::PRIMITIVE );
1913   propertyMap.Insert( PrimitiveVisual::Property::SHAPE, PrimitiveVisual::Shape::SPHERE );
1914   propertyMap.Insert( PrimitiveVisual::Property::BEVEL_SMOOTHNESS, Property::Value( 2.0f ) );
1915
1916   //Test to see if shape loads correctly.
1917   TestPrimitiveVisualWithProperties( propertyMap, application );
1918
1919   END_TEST;
1920 }
1921
1922 //Test if primitive shape visual handles the case of not being passed a specific shape to use.
1923 int UtcDaliVisualFactoryGetPrimitiveVisualN1(void)
1924 {
1925   //Set up test application first, so everything else can be handled.
1926   ToolkitTestApplication application;
1927
1928   tet_infoline( "UtcDaliVisualFactoryGetPrimitiveVisualN1:  Request primitive visual without shape" );
1929
1930   //Set up visual properties, without supplying shape.
1931   Property::Map propertyMap;
1932   propertyMap.Insert( Visual::Property::TYPE, Visual::PRIMITIVE );
1933
1934   //Test to see if shape loads regardless of missing input.
1935   TestPrimitiveVisualWithProperties( propertyMap, application );
1936
1937   END_TEST;
1938 }
1939
1940 int UtcDaliVisualFactoryGetBatchImageVisual1(void)
1941 {
1942   ToolkitTestApplication application;
1943   tet_infoline( "UtcDaliVisualFactoryGetBatchImageVisual1: Request a Batch Image visual with a Property::Map" );
1944
1945   VisualFactory factory = VisualFactory::Get();
1946   DALI_TEST_CHECK( factory );
1947
1948   Property::Map propertyMap;
1949   propertyMap.Insert( Visual::Property::TYPE, Visual::IMAGE );
1950   propertyMap.Insert( ImageVisual::Property::BATCHING_ENABLED, true );
1951   propertyMap.Insert( ImageVisual::Property::URL, TEST_IMAGE_FILE_NAME );
1952
1953   Visual::Base visual = factory.CreateVisual( propertyMap );
1954   DALI_TEST_CHECK( visual );
1955
1956   DummyControl actor = DummyControl::New();
1957   DummyControlImpl& dummyImpl = static_cast<DummyControlImpl&>(actor.GetImplementation());
1958   dummyImpl.RegisterVisual( Control::CONTROL_PROPERTY_END_INDEX + 1, visual );
1959
1960   actor.SetSize( 200.0f, 200.0f );
1961   Stage::GetCurrent().Add( actor );
1962   visual.SetSize( Vector2( 200.0f, 200.0f ) );
1963
1964   // Test SetOnStage().
1965   DALI_TEST_CHECK( actor.GetRendererCount() == 1u );
1966
1967   application.SendNotification();
1968   application.Render();
1969
1970   // Test SetOffStage().
1971   actor.Unparent();
1972   DALI_TEST_CHECK( actor.GetRendererCount() == 0u );
1973
1974   END_TEST;
1975 }
1976
1977 int UtcDaliVisualFactoryGetBatchImageVisual2(void)
1978 {
1979   ToolkitTestApplication application;
1980   tet_infoline( "UtcDaliVisualFactoryGetBatchImageVisual2: Request Batch Image visual from an Image Visual with batchingEnabled set" );
1981
1982   VisualFactory factory = VisualFactory::Get();
1983   DALI_TEST_CHECK( factory );
1984
1985   Property::Map propertyMap;
1986   // Create a normal Image Visual.
1987   propertyMap.Insert( Visual::Property::TYPE, Visual::IMAGE );
1988   // Instruct the factory to change Image Visuals to Batch-Image Visuals.
1989   propertyMap.Insert( ImageVisual::Property::BATCHING_ENABLED, true );
1990
1991   // Properties for the Batch-Image Visual.
1992   propertyMap.Insert( ImageVisual::Property::URL, TEST_IMAGE_FILE_NAME );
1993
1994   Visual::Base visual = factory.CreateVisual( propertyMap );
1995   DALI_TEST_CHECK( visual );
1996
1997   // Check that a Batch-Image visual was created instead of an Image visual.
1998   Property::Map resultMap;
1999   visual.CreatePropertyMap( resultMap );
2000
2001   Property::Value* value = resultMap.Find( Visual::Property::TYPE, Property::INTEGER );
2002   DALI_TEST_CHECK( value );
2003   DALI_TEST_EQUALS( value->Get<int>(), (int)Visual::IMAGE, TEST_LOCATION );
2004
2005   DummyControl actor = DummyControl::New();
2006   DummyControlImpl& dummyImpl = static_cast<DummyControlImpl&>(actor.GetImplementation());
2007   dummyImpl.RegisterVisual( Control::CONTROL_PROPERTY_END_INDEX + 1, visual );
2008
2009   actor.SetSize( 200.0f, 200.0f );
2010   Stage::GetCurrent().Add( actor );
2011   visual.SetSize( Vector2( 200.0f, 200.0f ) );
2012
2013   // Test SetOnStage().
2014   DALI_TEST_CHECK( actor.GetRendererCount() == 1u );
2015
2016   application.SendNotification();
2017   application.Render();
2018
2019   // Test SetOffStage().
2020   actor.Unparent();
2021   DALI_TEST_CHECK( actor.GetRendererCount() == 0u );
2022
2023   END_TEST;
2024 }
2025
2026 int UtcDaliVisualFactoryGetBatchImageVisual3(void)
2027 {
2028   ToolkitTestApplication application;
2029   tet_infoline( "UtcDaliVisualFactoryGetBatchImageVisual3: Create an ImageView that uses a batched visual internally" );
2030
2031   VisualFactory factory = VisualFactory::Get();
2032   DALI_TEST_CHECK( factory );
2033
2034   // Create a property-map that enables batching.
2035   Property::Map propertyMap;
2036   propertyMap.Insert( Dali::Toolkit::ImageVisual::Property::URL, TEST_IMAGE_FILE_NAME );
2037   propertyMap.Insert( ImageVisual::Property::BATCHING_ENABLED, true );
2038
2039   // Create an ImageView, passing the property-map in to instruct it to use batching.
2040   Toolkit::ImageView imageView = Toolkit::ImageView::New();
2041   imageView.SetProperty( Toolkit::ImageView::Property::IMAGE, propertyMap );
2042
2043   imageView.SetSize( 200.0f, 200.0f );
2044   Stage::GetCurrent().Add( imageView );
2045
2046   END_TEST;
2047 }