Merge "Geometry Batching" into devel/master
[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-event-thread-callback.h>
21 #include <dali/public-api/rendering/renderer.h>
22 #include <dali/public-api/rendering/texture-set.h>
23 #include <dali/public-api/rendering/shader.h>
24 #include <dali-toolkit/devel-api/visual-factory/visual-factory.h>
25 #include <dali-toolkit/dali-toolkit.h>
26
27 using namespace Dali;
28 using namespace Dali::Toolkit;
29
30 namespace
31 {
32 typedef NinePatchImage::StretchRanges StretchRanges;
33
34 const char* TEST_IMAGE_FILE_NAME =  "gallery_image_01.jpg";
35 const char* TEST_NPATCH_FILE_NAME =  "gallery_image_01.9.png";
36
37 const char* TEST_SVG_FILE_NAME = TEST_RESOURCE_DIR "/svg1.svg";
38 const char* TEST_OBJ_FILE_NAME = TEST_RESOURCE_DIR "/Cube.obj";
39 const char* TEST_MTL_FILE_NAME = TEST_RESOURCE_DIR "/ToyRobot-Metal.mtl";
40 const char* TEST_SIMPLE_OBJ_FILE_NAME = TEST_RESOURCE_DIR "/Cube-Points-Only.obj";
41 const char* TEST_SIMPLE_MTL_FILE_NAME = TEST_RESOURCE_DIR "/ToyRobot-Metal-Simple.mtl";
42
43 Integration::Bitmap* CreateBitmap( unsigned int imageWidth, unsigned int imageHeight, unsigned int initialColor, Pixel::Format pixelFormat )
44 {
45   Integration::Bitmap* bitmap = Integration::Bitmap::New( Integration::Bitmap::BITMAP_2D_PACKED_PIXELS, ResourcePolicy::OWNED_RETAIN );
46   Integration::PixelBuffer* pixbuffer = bitmap->GetPackedPixelsProfile()->ReserveBuffer( pixelFormat, imageWidth, imageHeight, imageWidth, imageHeight );
47   unsigned int bytesPerPixel = GetBytesPerPixel( pixelFormat );
48
49   memset( pixbuffer, initialColor, imageHeight * imageWidth * bytesPerPixel );
50
51   return bitmap;
52 }
53
54 void InitialiseRegionsToZeroAlpha( Integration::Bitmap* image, unsigned int imageWidth, unsigned int imageHeight, Pixel::Format pixelFormat )
55 {
56   PixelBuffer* pixbuffer = image->GetBuffer();
57   unsigned int bytesPerPixel = GetBytesPerPixel( pixelFormat );
58
59   for( unsigned int row = 0; row < imageWidth; ++row )
60   {
61     unsigned int pixelOffset = row * bytesPerPixel;
62     pixbuffer[ pixelOffset + 3 ] = 0x00;
63     pixelOffset += ( imageHeight - 1 ) * imageWidth * bytesPerPixel;
64     pixbuffer[ pixelOffset + 3 ] = 0x00;
65   }
66
67   for ( unsigned int column = 0; column < imageHeight; ++column )
68   {
69     unsigned int pixelOffset = column * imageWidth * bytesPerPixel;
70     pixbuffer[ pixelOffset + 3 ] = 0x00;
71     pixelOffset += ( imageWidth -1 ) * bytesPerPixel;
72     pixbuffer[ pixelOffset + 3 ] = 0x00;
73   }
74 }
75
76 void AddStretchRegionsToImage( Integration::Bitmap* image, unsigned int imageWidth, unsigned int imageHeight, const StretchRanges& stretchRangesX, const StretchRanges& stretchRangesY, Pixel::Format pixelFormat )
77 {
78   PixelBuffer* pixbuffer = image->GetBuffer();
79   unsigned int bytesPerPixel = GetBytesPerPixel( pixelFormat );
80
81   for(StretchRanges::ConstIterator it = stretchRangesX.Begin(); it != stretchRangesX.End(); ++it)
82   {
83     const Uint16Pair& range = *it;
84     //since the stretch range is in the cropped image space, we need to offset by 1 to get it to the uncropped image space
85     for( unsigned int column = range.GetX() + 1u; column < range.GetY() + 1u; ++column )
86     {
87       unsigned int pixelOffset = column * bytesPerPixel;
88       pixbuffer[ pixelOffset ] = 0x00;
89       pixbuffer[ pixelOffset + 1 ] = 0x00;
90       pixbuffer[ pixelOffset + 2 ] = 0x00;
91       pixbuffer[ pixelOffset + 3 ] = 0xFF;
92     }
93   }
94
95
96   for(StretchRanges::ConstIterator it = stretchRangesY.Begin(); it != stretchRangesY.End(); ++it)
97   {
98     const Uint16Pair& range = *it;
99     //since the stretch range is in the cropped image space, we need to offset by 1 to get it to the uncropped image space
100     for( unsigned int row = range.GetX() + 1u; row < range.GetY() + 1u; ++row )
101     {
102       unsigned int pixelOffset = row * imageWidth * bytesPerPixel;
103       pixbuffer[ pixelOffset ] = 0x00;
104       pixbuffer[ pixelOffset + 1 ] = 0x00;
105       pixbuffer[ pixelOffset + 2 ] = 0x00;
106       pixbuffer[ pixelOffset + 3 ] = 0xFF;
107     }
108   }
109 }
110
111 void AddChildRegionsToImage( Integration::Bitmap* image, unsigned int imageWidth, unsigned int imageHeight, const Vector4& requiredChildRegion, Pixel::Format pixelFormat )
112 {
113   PixelBuffer* pixbuffer = image->GetBuffer();
114   unsigned int bytesPerPixel = GetBytesPerPixel( pixelFormat );
115
116   Integration::Bitmap::PackedPixelsProfile* srcProfile = image->GetPackedPixelsProfile();
117   unsigned int bufferStride = srcProfile->GetBufferStride();
118
119   // Add bottom child region
120   for( unsigned int column = requiredChildRegion.x; column < imageWidth - requiredChildRegion.z; ++column )
121   {
122     unsigned int pixelOffset = column * bytesPerPixel;
123     pixelOffset += ( imageHeight - 1 ) * bufferStride;
124     pixbuffer[ pixelOffset ] = 0x00;
125     pixbuffer[ pixelOffset + 1 ] = 0x00;
126     pixbuffer[ pixelOffset + 2 ] = 0x00;
127     pixbuffer[ pixelOffset + 3 ] = 0xFF;
128   }
129
130   // Add right child region
131   for ( unsigned int row = requiredChildRegion.y; row < imageHeight - requiredChildRegion.w; ++row )
132   {
133     unsigned int pixelOffset = row * bufferStride + ( imageWidth - 1 ) * bytesPerPixel;
134     pixbuffer[ pixelOffset ] = 0x00;
135     pixbuffer[ pixelOffset + 1 ] = 0x00;
136     pixbuffer[ pixelOffset + 2 ] = 0x00;
137     pixbuffer[ pixelOffset + 3 ] = 0xFF;
138   }
139 }
140
141 Integration::ResourcePointer CustomizeNinePatch( TestApplication& application,
142                                                  unsigned int ninePatchImageWidth,
143                                                  unsigned int ninePatchImageHeight,
144                                                  const StretchRanges& stretchRangesX,
145                                                  const StretchRanges& stretchRangesY,
146                                                  bool addChildRegion = false,
147                                                  Vector4 requiredChildRegion = Vector4::ZERO )
148 {
149   TestPlatformAbstraction& platform = application.GetPlatform();
150
151   Pixel::Format pixelFormat = Pixel::RGBA8888;
152
153   tet_infoline("Create Bitmap");
154   platform.SetClosestImageSize(Vector2( ninePatchImageWidth, ninePatchImageHeight));
155   Integration::Bitmap* bitmap = CreateBitmap( ninePatchImageWidth, ninePatchImageHeight, 0xFF, pixelFormat );
156
157   tet_infoline("Clear border regions");
158   InitialiseRegionsToZeroAlpha( bitmap, ninePatchImageWidth, ninePatchImageHeight, pixelFormat );
159
160   tet_infoline("Add Stretch regions to Bitmap");
161   AddStretchRegionsToImage( bitmap, ninePatchImageWidth, ninePatchImageHeight, stretchRangesX, stretchRangesY, pixelFormat );
162
163   if( addChildRegion )
164   {
165     tet_infoline("Add Child regions to Bitmap");
166     AddChildRegionsToImage( bitmap, ninePatchImageWidth, ninePatchImageHeight, requiredChildRegion, pixelFormat );
167   }
168
169   tet_infoline("Getting resource");
170   Integration::ResourcePointer resourcePtr(bitmap);
171   //platform.SetResourceLoaded( 0, Dali::Integration::ResourceBitmap, resourcePtr );
172   platform.SetSynchronouslyLoadedResource( resourcePtr);
173
174   return resourcePtr;
175 }
176
177 void TestVisualRender( ToolkitTestApplication& application,
178                                 Actor& actor,
179                                 Visual::Base& visual,
180                                 std::size_t expectedSamplers = 0,
181                                 ImageDimensions imageDimensions = ImageDimensions(),
182                                 Integration::ResourcePointer resourcePtr = Integration::ResourcePointer())
183 {
184   if( resourcePtr )
185   {
186     // set the image size, for test case, this needs to be set before loading started
187     application.GetPlatform().SetClosestImageSize(  Vector2(imageDimensions.GetWidth(), imageDimensions.GetHeight()) );
188   }
189
190   actor.SetSize( 200.f, 200.f );
191   Stage::GetCurrent().Add( actor );
192   visual.SetSize( Vector2(200.f, 200.f) );
193   visual.SetOnStage( actor );
194
195   DALI_TEST_CHECK( actor.GetRendererCount() == 1u );
196
197   application.SendNotification();
198   application.Render();
199
200   if( resourcePtr )
201   {
202     Integration::ResourceRequest* request = application.GetPlatform().GetRequest();
203     if(request)
204     {
205       application.GetPlatform().SetResourceLoaded(request->GetId(), request->GetType()->id, resourcePtr );
206     }
207   }
208
209   application.Render();
210   application.SendNotification();
211
212   if( resourcePtr )
213   {
214     DALI_TEST_CHECK( application.GetPlatform().WasCalled(TestPlatformAbstraction::LoadResourceFunc) ||
215                      application.GetPlatform().WasCalled(TestPlatformAbstraction::LoadResourceSynchronouslyFunc ));
216   }
217
218   DALI_TEST_CHECK( actor.GetRendererCount() == 1u );
219
220 }
221
222 } // namespace
223
224
225 void dali_visual_factory_startup(void)
226 {
227   test_return_value = TET_UNDEF;
228 }
229
230 void dali_visual_factory_cleanup(void)
231 {
232   test_return_value = TET_PASS;
233 }
234
235 int UtcDaliVisualFactoryGet(void)
236 {
237   ToolkitTestApplication application;
238   tet_infoline( "UtcDaliVisualFactory" );
239
240   //Register type
241   TypeInfo type;
242   type = TypeRegistry::Get().GetTypeInfo( "VisualFactory" );
243   DALI_TEST_CHECK( type );
244   BaseHandle handle = type.CreateInstance();
245   DALI_TEST_CHECK( handle );
246
247   VisualFactory factory;
248   factory = VisualFactory::Get();
249   DALI_TEST_CHECK( factory );
250
251   VisualFactory newFactory = VisualFactory::Get();
252   DALI_TEST_CHECK( newFactory );
253
254   // Check that renderer factory is a singleton
255   DALI_TEST_CHECK(factory == newFactory);
256
257   END_TEST;
258 }
259
260 int UtcDaliVisualFactoryCopyAndAssignment(void)
261 {
262   ToolkitTestApplication application;
263   tet_infoline( "UtcDaliVisualFactoryCopyAndAssignment" );
264   VisualFactory factory = VisualFactory::Get();
265
266   VisualFactory factoryCopy( factory );
267   DALI_TEST_CHECK(factory == factoryCopy);
268
269   VisualFactory emptyFactory;
270   VisualFactory emptyFactoryCopy( emptyFactory );
271   DALI_TEST_CHECK(emptyFactory == emptyFactoryCopy);
272
273   VisualFactory factoryEquals;
274   factoryEquals = factory;
275   DALI_TEST_CHECK(factory == factoryEquals);
276
277   VisualFactory emptyFactoryEquals;
278   emptyFactoryEquals = emptyFactory;
279   DALI_TEST_CHECK( emptyFactory == emptyFactoryEquals );
280
281   //self assignment
282   factory = factory;
283   DALI_TEST_CHECK( factory = factoryCopy );
284
285   END_TEST;
286 }
287
288 int UtcDaliVisualFactoryGetColorVisual1(void)
289 {
290   ToolkitTestApplication application;
291   tet_infoline( "UtcDaliVisualFactoryGetColorVisual1:  Request color visual with a Property::Map" );
292
293   VisualFactory factory = VisualFactory::Get();
294   DALI_TEST_CHECK( factory );
295
296   Property::Map propertyMap;
297   Vector4 testColor( 1.f, 0.5f, 0.3f, 0.2f );
298   propertyMap.Insert(Visual::Property::TYPE,  Visual::COLOR);
299   propertyMap.Insert(ColorVisual::Property::MIX_COLOR,  testColor);
300
301   Visual::Base visual = factory.CreateVisual(propertyMap);
302   DALI_TEST_CHECK( visual );
303
304   Actor actor = Actor::New();
305   TestVisualRender( application, actor, visual );
306
307   Vector4 actualValue(Vector4::ZERO);
308   TestGlAbstraction& gl = application.GetGlAbstraction();
309   DALI_TEST_CHECK( gl.GetUniformValue<Vector4>( "mixColor", actualValue ) );
310   DALI_TEST_EQUALS( actualValue, testColor, TEST_LOCATION );
311
312   END_TEST;
313 }
314
315 int UtcDaliVisualFactoryGetColorVisual2(void)
316 {
317   ToolkitTestApplication application;
318   tet_infoline( "UtcDaliVisualFactoryGetColorVisual2: Request color visual with a Vector4" );
319
320   VisualFactory factory = VisualFactory::Get();
321   DALI_TEST_CHECK( factory );
322
323   Vector4 testColor( 1.f, 0.5f, 0.3f, 0.2f );
324   Dali::Property::Map map;
325   map[ Visual::Property::TYPE ] = Visual::COLOR;
326   map[ ColorVisual::Property::MIX_COLOR ] = testColor;
327   Visual::Base visual = factory.CreateVisual( map );
328   DALI_TEST_CHECK( visual );
329
330   Actor actor = Actor::New();
331   TestVisualRender( application, actor, visual );
332
333   Vector4 actualValue(Vector4::ZERO);
334   TestGlAbstraction& gl = application.GetGlAbstraction();
335   DALI_TEST_CHECK( gl.GetUniformValue<Vector4>( "mixColor", actualValue ) );
336   DALI_TEST_EQUALS( actualValue, testColor, TEST_LOCATION );
337
338   visual.SetOffStage( actor );
339   DALI_TEST_CHECK( actor.GetRendererCount() == 0u );
340
341   END_TEST;
342 }
343
344 int UtcDaliVisualFactoryGetBorderVisual1(void)
345 {
346   ToolkitTestApplication application;
347   tet_infoline( "UtcDaliVisualFactoryGetBorderVisual1:  Request border visual with a Property::Map" );
348
349   VisualFactory factory = VisualFactory::Get();
350   DALI_TEST_CHECK( factory );
351
352   Property::Map propertyMap;
353   Vector4 testColor( 1.f, 0.5f, 0.3f, 0.2f );
354   float testSize = 5.f;
355   propertyMap.Insert(Visual::Property::TYPE,  Visual::BORDER);
356   propertyMap.Insert(BorderVisual::Property::COLOR,  testColor);
357   propertyMap.Insert(BorderVisual::Property::SIZE,  testSize);
358
359   Visual::Base visual = factory.CreateVisual(propertyMap);
360   DALI_TEST_CHECK( visual );
361
362   Actor actor = Actor::New();
363   actor.SetSize(200.f, 200.f);
364   Stage::GetCurrent().Add( actor );
365   visual.SetSize(Vector2(200.f, 200.f));
366   visual.SetOnStage( actor );
367
368   DALI_TEST_CHECK( actor.GetRendererCount() == 1u );
369   int blendMode = actor.GetRendererAt(0u).GetProperty<int>( Renderer::Property::BLEND_MODE );
370   DALI_TEST_EQUALS( static_cast<BlendingMode::Type>(blendMode), BlendingMode::ON, TEST_LOCATION );
371
372   TestGlAbstraction& gl = application.GetGlAbstraction();
373
374   application.SendNotification();
375   application.Render(0);
376
377   Vector4 actualColor(Vector4::ZERO);
378   DALI_TEST_CHECK( gl.GetUniformValue<Vector4>( "borderColor", actualColor ) );
379   DALI_TEST_EQUALS( actualColor, testColor, TEST_LOCATION );
380
381   float actualSize = 0.f;
382   DALI_TEST_CHECK( gl.GetUniformValue<float>( "borderSize", actualSize ) );
383   DALI_TEST_EQUALS( actualSize, testSize, TEST_LOCATION );
384
385   visual.SetOffStage( actor );
386   DALI_TEST_CHECK( actor.GetRendererCount() == 0u );
387
388   END_TEST;
389 }
390
391 int UtcDaliVisualFactoryGetBorderVisual2(void)
392 {
393   ToolkitTestApplication application;
394   tet_infoline( "UtcDaliVisualFactoryGetBorderVisual2:  Request border visual with a borderSize and a borderColor" );
395
396   VisualFactory factory = VisualFactory::Get();
397   DALI_TEST_CHECK( factory );
398
399   Vector4 testColor( 1.f, 0.5f, 0.3f, 1.f );
400   float testSize = 5.f;
401
402   Dali::Property::Map propertyMap;
403   propertyMap[ Visual::Property::TYPE ] = Visual::BORDER;
404   propertyMap[ BorderVisual::Property::COLOR  ] = testColor;
405   propertyMap[ BorderVisual::Property::SIZE   ] = testSize;
406   Visual::Base visual = factory.CreateVisual( propertyMap );
407   DALI_TEST_CHECK( visual );
408
409   Actor actor = Actor::New();
410   actor.SetSize(200.f, 200.f);
411   Stage::GetCurrent().Add( actor );
412   visual.SetSize(Vector2(200.f, 200.f));
413   visual.SetOnStage( actor );
414
415   DALI_TEST_CHECK( actor.GetRendererCount() == 1u );
416
417   TestGlAbstraction& gl = application.GetGlAbstraction();
418
419   application.SendNotification();
420   application.Render(0);
421
422   int blendMode = actor.GetRendererAt(0u).GetProperty<int>( Renderer::Property::BLEND_MODE );
423   DALI_TEST_EQUALS( static_cast<BlendingMode::Type>(blendMode), BlendingMode::AUTO, TEST_LOCATION );
424
425   Vector4 actualColor(Vector4::ZERO);
426   DALI_TEST_CHECK( gl.GetUniformValue<Vector4>( "borderColor", actualColor ) );
427   DALI_TEST_EQUALS( actualColor, testColor, TEST_LOCATION );
428
429   float actualSize = 0.f;
430   DALI_TEST_CHECK( gl.GetUniformValue<float>( "borderSize", actualSize ) );
431   DALI_TEST_EQUALS( actualSize, testSize, TEST_LOCATION );
432
433   visual.SetOffStage( actor );
434
435   // enable the anti-aliasing
436   Dali::Property::Map map;
437   map[ Visual::Property::TYPE ] = Visual::BORDER;
438   map[ BorderVisual::Property::COLOR  ] = testColor;
439   map[ BorderVisual::Property::SIZE   ] = testSize;
440   map[ BorderVisual::Property::ANTI_ALIASING   ] = true;
441   visual = factory.CreateVisual( map );
442   visual.SetOnStage( actor );
443
444   application.SendNotification();
445   application.Render(0);
446   blendMode = actor.GetRendererAt(0u).GetProperty<int>( Renderer::Property::BLEND_MODE );
447   DALI_TEST_EQUALS( static_cast<BlendingMode::Type>(blendMode), BlendingMode::ON, TEST_LOCATION );
448
449   END_TEST;
450 }
451
452 int UtcDaliVisualFactoryGetLinearGradientVisual(void)
453 {
454   ToolkitTestApplication application;
455   tet_infoline("UtcDaliVisualFactoryGetRadialGradientVisual");
456
457   VisualFactory factory = VisualFactory::Get();
458   DALI_TEST_CHECK( factory );
459
460   Property::Map propertyMap;
461   propertyMap.Insert(Visual::Property::TYPE,  Visual::GRADIENT);
462
463   Vector2 start(-1.f, -1.f);
464   Vector2 end(1.f, 1.f);
465   propertyMap.Insert(GradientVisual::Property::START_POSITION, start);
466   propertyMap.Insert(GradientVisual::Property::END_POSITION, end);
467   propertyMap.Insert(GradientVisual::Property::SPREAD_METHOD, GradientVisual::SpreadMethod::REPEAT);
468
469   Property::Array stopOffsets;
470   stopOffsets.PushBack( 0.2f );
471   stopOffsets.PushBack( 0.8f );
472   propertyMap.Insert(GradientVisual::Property::STOP_OFFSET, stopOffsets);
473
474   Property::Array stopColors;
475   stopColors.PushBack( Color::RED );
476   stopColors.PushBack( Color::GREEN );
477   propertyMap.Insert(GradientVisual::Property::STOP_COLOR, stopColors);
478
479   Visual::Base visual = factory.CreateVisual(propertyMap);
480   DALI_TEST_CHECK( visual );
481
482   // A lookup texture is generated and pass to shader as sampler
483   Actor actor = Actor::New();
484   TestVisualRender( application, actor, visual, 1u );
485
486   visual.SetOffStage( actor );
487   DALI_TEST_CHECK( actor.GetRendererCount() == 0u );
488
489   END_TEST;
490 }
491
492 int UtcDaliVisualFactoryGetRadialGradientVisual(void)
493 {
494   ToolkitTestApplication application;
495   tet_infoline("UtcDaliVisualFactoryGetRadialGradientVisual");
496
497   VisualFactory factory = VisualFactory::Get();
498   DALI_TEST_CHECK( factory );
499
500   Property::Map propertyMap;
501   propertyMap.Insert(Visual::Property::TYPE,  Visual::GRADIENT);
502
503   Vector2 center(100.f, 100.f);
504   float radius = 100.f;
505   propertyMap.Insert(GradientVisual::Property::UNITS,  GradientVisual::Units::USER_SPACE);
506   propertyMap.Insert(GradientVisual::Property::CENTER,  center);
507   propertyMap.Insert(GradientVisual::Property::RADIUS,  radius);
508
509   Property::Array stopOffsets;
510   stopOffsets.PushBack( 0.0f );
511   stopOffsets.PushBack( 1.f );
512   propertyMap.Insert(GradientVisual::Property::STOP_OFFSET,   stopOffsets);
513
514   Property::Array stopColors;
515   stopColors.PushBack( Color::RED );
516   stopColors.PushBack( Color::GREEN );
517   propertyMap.Insert(GradientVisual::Property::STOP_COLOR,   stopColors);
518
519   Visual::Base visual = factory.CreateVisual(propertyMap);
520   DALI_TEST_CHECK( visual );
521
522   // A lookup texture is generated and pass to shader as sampler
523   Actor actor = Actor::New();
524   TestVisualRender( application, actor, visual, 1u );
525
526   Matrix3 alignMatrix( radius, 0.f, 0.f, 0.f, radius, 0.f, center.x, center.y, 1.f );
527   alignMatrix.Invert();
528
529   Matrix3 actualValue( Matrix3::IDENTITY );
530   TestGlAbstraction& gl = application.GetGlAbstraction();
531   DALI_TEST_CHECK( gl.GetUniformValue<Matrix3>( "uAlignmentMatrix", actualValue ) );
532   DALI_TEST_EQUALS( actualValue, alignMatrix, Math::MACHINE_EPSILON_100, TEST_LOCATION );
533
534   END_TEST;
535 }
536
537 int UtcDaliVisualFactoryDefaultOffsetsGradientVisual(void)
538 {
539   ToolkitTestApplication application;
540   tet_infoline("UtcDaliVisualFactoryGetRadialGradientVisual");
541
542   VisualFactory factory = VisualFactory::Get();
543   DALI_TEST_CHECK( factory );
544
545   Property::Map propertyMap;
546   propertyMap.Insert(Visual::Property::TYPE,  Visual::GRADIENT);
547
548   Vector2 start(-1.f, -1.f);
549   Vector2 end(1.f, 1.f);
550   propertyMap.Insert(GradientVisual::Property::START_POSITION, start);
551   propertyMap.Insert(GradientVisual::Property::END_POSITION, end);
552   propertyMap.Insert(GradientVisual::Property::SPREAD_METHOD, GradientVisual::SpreadMethod::REPEAT);
553
554   Property::Array stopColors;
555   stopColors.PushBack( Color::RED );
556   stopColors.PushBack( Color::GREEN );
557   propertyMap.Insert(GradientVisual::Property::STOP_COLOR, stopColors);
558
559   Visual::Base visual = factory.CreateVisual(propertyMap);
560   DALI_TEST_CHECK( visual );
561
562   // A lookup texture is generated and pass to shader as sampler
563   Actor actor = Actor::New();
564   TestVisualRender( application, actor, visual, 1u );
565
566   visual.SetOffStage( actor );
567   DALI_TEST_CHECK( actor.GetRendererCount() == 0u );
568
569   END_TEST;
570 }
571
572 int UtcDaliVisualFactoryGetImageVisual1(void)
573 {
574   ToolkitTestApplication application;
575   tet_infoline( "UtcDaliVisualFactoryGetImageVisual1: Request image renderer with a Property::Map" );
576
577   VisualFactory factory = VisualFactory::Get();
578   DALI_TEST_CHECK( factory );
579
580   Property::Map propertyMap;
581   propertyMap.Insert( Visual::Property::TYPE,  Visual::IMAGE );
582   propertyMap.Insert( ImageVisual::Property::URL,  TEST_IMAGE_FILE_NAME );
583
584   Visual::Base visual = factory.CreateVisual( propertyMap );
585   DALI_TEST_CHECK( visual );
586
587   Actor actor = Actor::New();
588   // For tesing the LoadResourceFunc is called, a big image size should be set, so the atlasing is not applied.
589   // Image with a size smaller than 512*512 will be uploaded as a part of the atlas.
590
591   const int width=512;
592   const int height=513;
593   TestGlAbstraction& gl = application.GetGlAbstraction();
594   TraceCallStack& textureTrace = gl.GetTextureTrace();
595   textureTrace.Enable(true);
596
597   Integration::Bitmap* bitmap = Integration::Bitmap::New( Integration::Bitmap::BITMAP_2D_PACKED_PIXELS, ResourcePolicy::OWNED_DISCARD );
598   bitmap->GetPackedPixelsProfile()->ReserveBuffer( Pixel::RGBA8888, width, height,width, height );
599
600   TestVisualRender( application, actor, visual, 1u,
601                              ImageDimensions(width, height),
602                              Integration::ResourcePointer( bitmap ) );
603
604   DALI_TEST_EQUALS( textureTrace.FindMethod("BindTexture"), true, TEST_LOCATION );
605
606   visual.SetOffStage( actor );
607   DALI_TEST_CHECK( actor.GetRendererCount() == 0u );
608
609   END_TEST;
610 }
611
612 int UtcDaliVisualFactoryGetImageVisual2(void)
613 {
614   ToolkitTestApplication application;
615   tet_infoline( "UtcDaliVisualFactoryGetImageVisual2: Request image renderer with an image handle" );
616
617   VisualFactory factory = VisualFactory::Get();
618   DALI_TEST_CHECK( factory );
619
620   Image image = ResourceImage::New(TEST_IMAGE_FILE_NAME);
621   Visual::Base visual = factory.CreateVisual( image );
622
623   Actor actor = Actor::New();
624   // For tesing the LoadResourceFunc is called, a big image size should be set, so the atlasing is not applied.
625   // Image with a size smaller than 512*512 will be uploaded as a part of the atlas.
626
627   const int width=512;
628   const int height=513;
629
630   Integration::Bitmap* bitmap = Integration::Bitmap::New( Integration::Bitmap::BITMAP_2D_PACKED_PIXELS, ResourcePolicy::OWNED_DISCARD );
631   bitmap->GetPackedPixelsProfile()->ReserveBuffer( Pixel::RGBA8888, width, height,width, height );
632
633   TestGlAbstraction& gl = application.GetGlAbstraction();
634   TraceCallStack& textureTrace = gl.GetTextureTrace();
635   textureTrace.Enable(true);
636
637   TestVisualRender( application, actor, visual, 1u,
638                              ImageDimensions(width, height),
639                              Integration::ResourcePointer(bitmap) );
640
641   DALI_TEST_EQUALS( textureTrace.FindMethod("BindTexture"), true, TEST_LOCATION );
642
643   END_TEST;
644 }
645
646 int UtcDaliVisualFactoryGetNPatchVisual1(void)
647 {
648   ToolkitTestApplication application;
649   tet_infoline( "UtcDaliVisualFactoryGetNPatchVisual1: Request 9-patch renderer with a Property::Map" );
650
651   VisualFactory factory = VisualFactory::Get();
652   DALI_TEST_CHECK( factory );
653
654   const unsigned int ninePatchImageHeight = 18;
655   const unsigned int ninePatchImageWidth = 28;
656   StretchRanges stretchRangesX;
657   stretchRangesX.PushBack( Uint16Pair( 2, 3 ) );
658   StretchRanges stretchRangesY;
659   stretchRangesY.PushBack( Uint16Pair( 4, 5 ) );
660   Integration::ResourcePointer ninePatchResource = CustomizeNinePatch( application, ninePatchImageWidth, ninePatchImageHeight, stretchRangesX, stretchRangesY );
661
662   Property::Map propertyMap;
663   propertyMap.Insert( Visual::Property::TYPE,  Visual::IMAGE );
664   propertyMap.Insert( ImageVisual::Property::URL,  TEST_NPATCH_FILE_NAME );
665   {
666     tet_infoline( "whole grid" );
667     Visual::Base visual = factory.CreateVisual( propertyMap );
668     DALI_TEST_CHECK( visual );
669
670     Actor actor = Actor::New();
671
672     TestGlAbstraction& gl = application.GetGlAbstraction();
673     TraceCallStack& textureTrace = gl.GetTextureTrace();
674     textureTrace.Enable(true);
675
676     TestVisualRender( application, actor, visual, 1u,
677                                ImageDimensions(ninePatchImageWidth, ninePatchImageHeight),
678                                ninePatchResource );
679
680     DALI_TEST_EQUALS( textureTrace.FindMethod("BindTexture"), true, TEST_LOCATION );
681   }
682
683   propertyMap.Insert( ImageVisual::Property::BORDER_ONLY,  true );
684   {
685     tet_infoline( "border only" );
686     Visual::Base visual = factory.CreateVisual( propertyMap );
687     DALI_TEST_CHECK( visual );
688
689     Actor actor = Actor::New();
690
691     TestGlAbstraction& gl = application.GetGlAbstraction();
692     TraceCallStack& textureTrace = gl.GetTextureTrace();
693     textureTrace.Enable(true);
694
695     TestVisualRender( application, actor, visual, 1u,
696                                ImageDimensions(ninePatchImageWidth, ninePatchImageHeight),
697                                ninePatchResource );
698
699     DALI_TEST_EQUALS( textureTrace.FindMethod("BindTexture"), true, TEST_LOCATION );
700   }
701
702   END_TEST;
703 }
704
705 int UtcDaliVisualFactoryGetNPatchVisual2(void)
706 {
707   ToolkitTestApplication application;
708   tet_infoline( "UtcDaliVisualFactoryGetNPatchVisual2: Request n-patch renderer with a Property::Map" );
709
710   VisualFactory factory = VisualFactory::Get();
711   DALI_TEST_CHECK( factory );
712
713   const unsigned int ninePatchImageWidth = 18;
714   const unsigned int ninePatchImageHeight = 28;
715   StretchRanges stretchRangesX;
716   stretchRangesX.PushBack( Uint16Pair( 2, 3 ) );
717   stretchRangesX.PushBack( Uint16Pair( 5, 7 ) );
718   stretchRangesX.PushBack( Uint16Pair( 12, 15 ) );
719   StretchRanges stretchRangesY;
720   stretchRangesY.PushBack( Uint16Pair( 4, 5 ) );
721   stretchRangesY.PushBack( Uint16Pair( 8, 12 ) );
722   stretchRangesY.PushBack( Uint16Pair( 15, 16 ) );
723   stretchRangesY.PushBack( Uint16Pair( 25, 27 ) );
724   Integration::ResourcePointer ninePatchResource = CustomizeNinePatch( application, ninePatchImageWidth, ninePatchImageHeight, stretchRangesX, stretchRangesY );
725
726   Property::Map propertyMap;
727   propertyMap.Insert( Visual::Property::TYPE,  Visual::IMAGE );
728   propertyMap.Insert( ImageVisual::Property::URL,  TEST_NPATCH_FILE_NAME );
729   {
730     Visual::Base visual = factory.CreateVisual( propertyMap );
731     DALI_TEST_CHECK( visual );
732
733     Actor actor = Actor::New();
734     TestGlAbstraction& gl = application.GetGlAbstraction();
735     TraceCallStack& textureTrace = gl.GetTextureTrace();
736     textureTrace.Enable(true);
737
738     TestVisualRender( application, actor, visual, 1u,
739                                ImageDimensions(ninePatchImageWidth, ninePatchImageHeight),
740                                ninePatchResource );
741
742
743     DALI_TEST_EQUALS( textureTrace.FindMethod("BindTexture"), true, TEST_LOCATION );
744
745     visual.SetOffStage( actor );
746     DALI_TEST_CHECK( actor.GetRendererCount() == 0u );
747   }
748
749   propertyMap.Insert( ImageVisual::Property::BORDER_ONLY,  true );
750   {
751     tet_infoline( "border only" );
752     Visual::Base visual = factory.CreateVisual( propertyMap );
753     DALI_TEST_CHECK( visual );
754
755     TestGlAbstraction& gl = application.GetGlAbstraction();
756     TraceCallStack& textureTrace = gl.GetTextureTrace();
757     textureTrace.Enable(true);
758     Actor actor = Actor::New();
759     TestVisualRender( application, actor, visual, 1u,
760                                ImageDimensions(ninePatchImageWidth, ninePatchImageHeight),
761                                ninePatchResource );
762
763
764     DALI_TEST_EQUALS( textureTrace.FindMethod("BindTexture"), true, TEST_LOCATION );
765
766     visual.SetOffStage( actor );
767     DALI_TEST_CHECK( actor.GetRendererCount() == 0u );
768   }
769
770   END_TEST;
771 }
772
773 int UtcDaliVisualFactoryGetNPatchVisual3(void)
774 {
775   ToolkitTestApplication application;
776   tet_infoline( "UtcDaliVisualFactoryGetNPatchVisual3: Request 9-patch renderer with an image url" );
777
778   VisualFactory factory = VisualFactory::Get();
779   DALI_TEST_CHECK( factory );
780
781   const unsigned int ninePatchImageHeight = 18;
782   const unsigned int ninePatchImageWidth = 28;
783   StretchRanges stretchRangesX;
784   stretchRangesX.PushBack( Uint16Pair( 2, 3 ) );
785   StretchRanges stretchRangesY;
786   stretchRangesY.PushBack( Uint16Pair( 4, 5 ) );
787   Integration::ResourcePointer ninePatchResource = CustomizeNinePatch( application, ninePatchImageWidth, ninePatchImageHeight, stretchRangesX, stretchRangesY );
788
789   Visual::Base visual = factory.CreateVisual( TEST_NPATCH_FILE_NAME, ImageDimensions() );
790   DALI_TEST_CHECK( visual );
791
792   Actor actor = Actor::New();
793
794   TestGlAbstraction& gl = application.GetGlAbstraction();
795   TraceCallStack& textureTrace = gl.GetTextureTrace();
796   textureTrace.Enable(true);
797
798   TestVisualRender( application, actor, visual, 1u,
799                              ImageDimensions(ninePatchImageWidth, ninePatchImageHeight),
800                              ninePatchResource );
801
802   DALI_TEST_EQUALS( textureTrace.FindMethod("BindTexture"), true, TEST_LOCATION );
803
804   END_TEST;
805 }
806
807 int UtcDaliVisualFactoryGetNPatchVisual4(void)
808 {
809   ToolkitTestApplication application;
810   tet_infoline( "UtcDaliVisualFactoryGetNPatchVisual4: Request n-patch visual with an image url" );
811
812   VisualFactory factory = VisualFactory::Get();
813   DALI_TEST_CHECK( factory );
814
815   const unsigned int ninePatchImageHeight = 18;
816   const unsigned int ninePatchImageWidth = 28;
817   StretchRanges stretchRangesX;
818   stretchRangesX.PushBack( Uint16Pair( 2, 3 ) );
819   stretchRangesX.PushBack( Uint16Pair( 5, 7 ) );
820   stretchRangesX.PushBack( Uint16Pair( 12, 15 ) );
821   StretchRanges stretchRangesY;
822   stretchRangesY.PushBack( Uint16Pair( 4, 5 ) );
823   stretchRangesY.PushBack( Uint16Pair( 8, 12 ) );
824   stretchRangesY.PushBack( Uint16Pair( 15, 16 ) );
825   stretchRangesY.PushBack( Uint16Pair( 25, 27 ) );
826   Integration::ResourcePointer ninePatchResource = CustomizeNinePatch( application, ninePatchImageWidth, ninePatchImageHeight, stretchRangesX, stretchRangesY );
827
828   Visual::Base visual = factory.CreateVisual( TEST_NPATCH_FILE_NAME, ImageDimensions() );
829   DALI_TEST_CHECK( visual );
830
831   Actor actor = Actor::New();
832
833   TestGlAbstraction& gl = application.GetGlAbstraction();
834   TraceCallStack& textureTrace = gl.GetTextureTrace();
835   textureTrace.Enable(true);
836
837   TestVisualRender( application, actor, visual, 1u,
838                              ImageDimensions(ninePatchImageWidth, ninePatchImageHeight),
839                              ninePatchResource );
840
841   DALI_TEST_EQUALS( textureTrace.FindMethod("BindTexture"), true, TEST_LOCATION );
842
843   END_TEST;
844 }
845
846 int UtcDaliVisualFactoryGetNPatchVisualN1(void)
847 {
848   //This should still load but display an error image
849
850   ToolkitTestApplication application;
851   tet_infoline( "UtcDaliVisualFactoryGetNPatchVisualN: Request n-patch visual with an invalid image url" );
852
853   VisualFactory factory = VisualFactory::Get();
854   DALI_TEST_CHECK( factory );
855
856   Visual::Base visual = factory.CreateVisual( "ERROR.9.jpg", ImageDimensions() );
857   DALI_TEST_CHECK( visual );
858
859   Actor actor = Actor::New();
860
861   //The testkit still has to load a bitmap for the broken renderer image
862   Integration::Bitmap* bitmap = Integration::Bitmap::New(Integration::Bitmap::BITMAP_2D_PACKED_PIXELS, ResourcePolicy::OWNED_DISCARD);
863   bitmap->GetPackedPixelsProfile()->ReserveBuffer( Pixel::RGBA8888, 100, 100, 100, 100 );
864
865   TestGlAbstraction& gl = application.GetGlAbstraction();
866   TraceCallStack& textureTrace = gl.GetTextureTrace();
867   textureTrace.Enable(true);
868
869   TestVisualRender( application, actor, visual, 1u,
870                              ImageDimensions(),
871                              Integration::ResourcePointer(bitmap) );
872
873   DALI_TEST_EQUALS( textureTrace.FindMethod("BindTexture"), true, TEST_LOCATION );
874
875   END_TEST;
876 }
877
878 int UtcDaliVisualFactoryGetNPatchVisualN2(void)
879 {
880   //This should still load but display an error image
881
882   ToolkitTestApplication application;
883   tet_infoline( "UtcDaliVisualFactoryGetNPatchVisualN: Request n-patch visual with an invalid Property::Map" );
884
885   VisualFactory factory = VisualFactory::Get();
886   DALI_TEST_CHECK( factory );
887
888   Property::Map propertyMap;
889   propertyMap.Insert( Visual::Property::TYPE,  111 );
890   propertyMap.Insert( ImageVisual::Property::URL,  "ERROR.9.jpg" );
891
892   Visual::Base visual = factory.CreateVisual( propertyMap );
893   DALI_TEST_CHECK( visual );
894
895   Actor actor = Actor::New();
896
897   //The testkit still has to load a bitmap for the broken renderer image
898   Integration::Bitmap* bitmap = Integration::Bitmap::New(Integration::Bitmap::BITMAP_2D_PACKED_PIXELS, ResourcePolicy::OWNED_DISCARD);
899   bitmap->GetPackedPixelsProfile()->ReserveBuffer( Pixel::RGBA8888, 100, 100, 100, 100 );
900
901   TestGlAbstraction& gl = application.GetGlAbstraction();
902   TraceCallStack& textureTrace = gl.GetTextureTrace();
903   textureTrace.Enable(true);
904
905   TestVisualRender( application, actor, visual, 1u,
906                              ImageDimensions(),
907                              Integration::ResourcePointer(bitmap) );
908
909   DALI_TEST_EQUALS( textureTrace.FindMethod("BindTexture"), true, TEST_LOCATION );
910
911   END_TEST;
912 }
913
914 int UtcDaliVisualFactoryGetSvgVisual(void)
915 {
916   ToolkitTestApplication application;
917   tet_infoline( "UtcDaliVisualFactoryGetSvgVisual: Request svg visual with a svg url" );
918
919   VisualFactory factory = VisualFactory::Get();
920   Visual::Base visual = factory.CreateVisual( TEST_SVG_FILE_NAME, ImageDimensions() );
921   DALI_TEST_CHECK( visual );
922
923   TestGlAbstraction& gl = application.GetGlAbstraction();
924   TraceCallStack& textureTrace = gl.GetTextureTrace();
925   textureTrace.Enable(true);
926
927   Actor actor = Actor::New();
928   actor.SetSize( 200.f, 200.f );
929   Stage::GetCurrent().Add( actor );
930   visual.SetSize( Vector2(200.f, 200.f) );
931   visual.SetOnStage( actor );
932   application.SendNotification();
933   application.Render();
934
935   DALI_TEST_CHECK( actor.GetRendererCount() == 1u );
936
937   EventThreadCallback* eventTrigger = EventThreadCallback::Get();
938   CallbackBase* callback = eventTrigger->GetCallback();
939
940   eventTrigger->WaitingForTrigger( 1 );// waiting until the svg image is rasterized.
941   CallbackBase::Execute( *callback );
942
943   DALI_TEST_CHECK( actor.GetRendererCount() == 1u );
944
945   // waiting for the resource uploading
946   application.SendNotification();
947   application.Render();
948
949   DALI_TEST_EQUALS( textureTrace.FindMethod("BindTexture"), true, TEST_LOCATION );
950
951   END_TEST;
952 }
953
954 //Creates a mesh renderer from the given propertyMap and tries to load it on stage in the given application.
955 //This is expected to succeed, which will then pass the test.
956 void MeshVisualLoadsCorrectlyTest( Property::Map& propertyMap, ToolkitTestApplication& application )
957 {
958   VisualFactory factory = VisualFactory::Get();
959   DALI_TEST_CHECK( factory );
960
961   //Create a mesh visual.
962   Visual::Base visual = factory.CreateVisual( propertyMap );
963   DALI_TEST_CHECK( visual );
964
965   //Create an actor on stage to house the visual.
966   Actor actor = Actor::New();
967   actor.SetSize( 200.f, 200.f );
968   Stage::GetCurrent().Add( actor );
969   visual.SetSize( Vector2( 200.f, 200.f ) );
970   visual.SetOnStage( actor );
971
972   //Ensure set on stage.
973   DALI_TEST_EQUALS( actor.GetRendererCount(), 1u, TEST_LOCATION );
974
975   //Attempt to render to queue resource load requests.
976   application.SendNotification();
977   application.Render( 0 );
978
979   //Tell the platform abstraction that the required resources have been loaded.
980   TestPlatformAbstraction& platform = application.GetPlatform();
981   platform.SetAllResourceRequestsAsLoaded();
982
983   //Render again to upload the now-loaded textures.
984   application.SendNotification();
985   application.Render( 0 );
986
987   Matrix testScaleMatrix;
988   testScaleMatrix.SetIdentityAndScale( Vector3( 1.0, -1.0, 1.0 ) );
989   Matrix actualScaleMatrix;
990
991   //Test to see if the object has been successfully loaded.
992   DALI_TEST_CHECK( application.GetGlAbstraction().GetUniformValue<Matrix>( "uObjectMatrix", actualScaleMatrix ) );
993   DALI_TEST_EQUALS( actualScaleMatrix, testScaleMatrix, Math::MACHINE_EPSILON_100, TEST_LOCATION );
994
995   //Finish by setting off stage, and ensuring this was successful.
996   visual.SetOffStage( actor );
997   DALI_TEST_EQUALS( actor.GetRendererCount(), 0u, TEST_LOCATION );
998 }
999
1000 //Creates a mesh visual from the given propertyMap and tries to load it on stage in the given application.
1001 //This is expected to fail, which will then pass the test.
1002 void MeshVisualDoesNotLoadCorrectlyTest( Property::Map& propertyMap, ToolkitTestApplication& application )
1003 {
1004   VisualFactory factory = VisualFactory::Get();
1005   DALI_TEST_CHECK( factory );
1006
1007   //Create a mesh visual.
1008   Visual::Base visual = factory.CreateVisual( propertyMap );
1009   DALI_TEST_CHECK( visual );
1010
1011   //Create an actor on stage to house the visual.
1012   Actor actor = Actor::New();
1013   actor.SetSize( 200.f, 200.f );
1014   Stage::GetCurrent().Add( actor );
1015   visual.SetSize( Vector2( 200.f, 200.f ) );
1016   visual.SetOnStage( actor );
1017
1018   //Ensure set on stage.
1019   DALI_TEST_EQUALS( actor.GetRendererCount(), 1u, TEST_LOCATION );
1020
1021   //Attempt to render to queue resource load requests.
1022   application.SendNotification();
1023   application.Render( 0 );
1024
1025   //Tell the platform abstraction that the required resources have been loaded.
1026   TestPlatformAbstraction& platform = application.GetPlatform();
1027   platform.SetAllResourceRequestsAsLoaded();
1028
1029   //Render again to upload the now-loaded textures.
1030   application.SendNotification();
1031   application.Render( 0 );
1032
1033   //Test to see if the object has not been loaded, as expected.
1034   Matrix scaleMatrix;
1035   DALI_TEST_CHECK( !application.GetGlAbstraction().GetUniformValue<Matrix>( "uObjectMatrix", scaleMatrix ) );
1036
1037   //Finish by setting off stage, and ensuring this was successful.
1038   visual.SetOffStage( actor );
1039   DALI_TEST_EQUALS( actor.GetRendererCount(), 0u, TEST_LOCATION );
1040 }
1041
1042 //Test if mesh loads correctly when supplied with only the bare minimum requirements, an object file.
1043 int UtcDaliVisualFactoryGetMeshVisual1(void)
1044 {
1045   //Set up test application first, so everything else can be handled.
1046   ToolkitTestApplication application;
1047
1048   tet_infoline( "UtcDaliVisualFactoryGetMeshVisual1:  Request mesh visual with a valid object file only" );
1049
1050
1051   //Set up visual properties.
1052   Property::Map propertyMap;
1053   propertyMap.Insert( Visual::Property::TYPE,  Visual::MESH );
1054   propertyMap.Insert( MeshVisual::Property::OBJECT_URL, TEST_OBJ_FILE_NAME );
1055
1056   //Test to see if mesh loads correctly.
1057   MeshVisualLoadsCorrectlyTest( propertyMap, application );
1058
1059   END_TEST;
1060 }
1061
1062
1063 //Test if mesh loads correctly when supplied with an object file as well as a blank material file and images directory.
1064 int UtcDaliVisualFactoryGetMeshVisual2(void)
1065 {
1066   //Set up test application first, so everything else can be handled.
1067   ToolkitTestApplication application;
1068
1069   tet_infoline( "UtcDaliVisualFactoryGetMeshVisual2:  Request mesh visual with blank material file and images directory" );
1070
1071   //Set up visual properties.
1072   Property::Map propertyMap;
1073   propertyMap.Insert( Visual::Property::TYPE, Visual::MESH );
1074   propertyMap.Insert( MeshVisual::Property::OBJECT_URL, TEST_OBJ_FILE_NAME );
1075   propertyMap.Insert( MeshVisual::Property::MATERIAL_URL, "" );
1076   propertyMap.Insert( MeshVisual::Property::TEXTURES_PATH, "" );
1077
1078   //Test to see if mesh loads correctly.
1079   MeshVisualLoadsCorrectlyTest( propertyMap, application );
1080
1081   END_TEST;
1082 }
1083
1084 //Test if mesh loads correctly when supplied with all main parameters, an object file, a material file and a directory location.
1085 int UtcDaliVisualFactoryGetMeshVisual3(void)
1086 {
1087   //Set up test application first, so everything else can be handled.
1088   ToolkitTestApplication application;
1089
1090   tet_infoline( "UtcDaliVisualFactoryGetMeshVisual3:  Request mesh visual with all parameters correct" );
1091
1092   //Set up visual properties.
1093   Property::Map propertyMap;
1094   propertyMap.Insert( Visual::Property::TYPE, Visual::MESH );
1095   propertyMap.Insert( MeshVisual::Property::OBJECT_URL, TEST_OBJ_FILE_NAME );
1096   propertyMap.Insert( MeshVisual::Property::MATERIAL_URL, TEST_MTL_FILE_NAME );
1097   propertyMap.Insert( MeshVisual::Property::TEXTURES_PATH, TEST_RESOURCE_DIR "/" );
1098
1099   //Test to see if mesh loads correctly.
1100   MeshVisualLoadsCorrectlyTest( propertyMap, application );
1101
1102   END_TEST;
1103 }
1104
1105 //Test if mesh visual can load a correctly supplied mesh without a normal map or gloss map in the material file.
1106 int UtcDaliVisualFactoryGetMeshVisual4(void)
1107 {
1108   //Set up test application first, so everything else can be handled.
1109   ToolkitTestApplication application;
1110
1111   tet_infoline( "UtcDaliVisualFactoryGetMeshVisual4:  Request mesh visual with diffuse texture but not normal or gloss." );
1112
1113
1114   //Set up visual properties.
1115   Property::Map propertyMap;
1116   propertyMap.Insert( Visual::Property::TYPE, Visual::MESH );
1117   propertyMap.Insert( MeshVisual::Property::OBJECT_URL, TEST_OBJ_FILE_NAME );
1118   propertyMap.Insert( MeshVisual::Property::MATERIAL_URL, TEST_SIMPLE_MTL_FILE_NAME );
1119   propertyMap.Insert( MeshVisual::Property::TEXTURES_PATH, TEST_RESOURCE_DIR "/" );
1120
1121   //Test to see if mesh loads correctly.
1122   MeshVisualLoadsCorrectlyTest( propertyMap, application );
1123
1124
1125   END_TEST;
1126 }
1127
1128 //Test if mesh visual can load when made to use diffuse textures only.
1129 int UtcDaliVisualFactoryGetMeshVisual5(void)
1130 {
1131   //Set up test application first, so everything else can be handled.
1132   ToolkitTestApplication application;
1133
1134   tet_infoline( "UtcDaliVisualFactoryGetMeshVisual5:  Request mesh visual and make it only use diffuse textures." );
1135
1136   //Set up visual properties.
1137   Property::Map propertyMap;
1138   propertyMap.Insert( Visual::Property::TYPE, Visual::MESH );
1139   propertyMap.Insert( MeshVisual::Property::OBJECT_URL, TEST_OBJ_FILE_NAME );
1140   propertyMap.Insert( MeshVisual::Property::MATERIAL_URL, TEST_MTL_FILE_NAME );
1141   propertyMap.Insert( MeshVisual::Property::TEXTURES_PATH, TEST_RESOURCE_DIR "/" );
1142   propertyMap.Insert( MeshVisual::Property::SHADING_MODE, MeshVisual::ShadingMode::TEXTURED_WITH_SPECULAR_LIGHTING );
1143
1144   //Test to see if mesh loads correctly.
1145   MeshVisualLoadsCorrectlyTest( propertyMap, application );
1146
1147
1148   END_TEST;
1149 }
1150
1151 //Test if mesh visual can load when made to not use the supplied textures.
1152 int UtcDaliVisualFactoryGetMeshVisual6(void)
1153 {
1154   //Set up test application first, so everything else can be handled.
1155   ToolkitTestApplication application;
1156
1157   tet_infoline( "UtcDaliVisualFactoryGetMeshVisual6:  Request mesh visual and make it not use any textures." );
1158
1159   //Set up visual properties.
1160   Property::Map propertyMap;
1161   propertyMap.Insert( Visual::Property::TYPE, Visual::MESH );
1162   propertyMap.Insert( MeshVisual::Property::OBJECT_URL, TEST_OBJ_FILE_NAME );
1163   propertyMap.Insert( MeshVisual::Property::MATERIAL_URL, TEST_MTL_FILE_NAME );
1164   propertyMap.Insert( MeshVisual::Property::TEXTURES_PATH, TEST_RESOURCE_DIR "/" );
1165   propertyMap.Insert( MeshVisual::Property::SHADING_MODE, MeshVisual::ShadingMode::TEXTURELESS_WITH_DIFFUSE_LIGHTING );
1166
1167   //Test to see if mesh loads correctly.
1168   MeshVisualLoadsCorrectlyTest( propertyMap, application );
1169
1170   END_TEST;
1171 }
1172 //Test if mesh visual loads correctly when light position is manually set.
1173 int UtcDaliVisualFactoryGetMeshVisual7(void)
1174 {
1175   //Set up test application first, so everything else can be handled.
1176   ToolkitTestApplication application;
1177
1178
1179   tet_infoline( "UtcDaliVisualFactoryGetMeshVisual7:  Request mesh visual with custom light position." );
1180
1181   //Set up visual properties.
1182   Property::Map propertyMap;
1183   propertyMap.Insert( Visual::Property::TYPE, Visual::MESH );
1184   propertyMap.Insert( MeshVisual::Property::OBJECT_URL, TEST_OBJ_FILE_NAME );
1185   propertyMap.Insert( MeshVisual::Property::MATERIAL_URL, TEST_MTL_FILE_NAME );
1186   propertyMap.Insert( MeshVisual::Property::TEXTURES_PATH, TEST_RESOURCE_DIR "/" );
1187   propertyMap.Insert( MeshVisual::Property::LIGHT_POSITION, Vector3( 0.0, 1.0, 2.0 ) );
1188
1189   //Test to see if mesh loads correctly.
1190   MeshVisualLoadsCorrectlyTest( propertyMap, application );
1191
1192   END_TEST;
1193 }
1194
1195 //Test if mesh visual loads correctly when supplied an object file without face normals or texture points.
1196 //Note that this notably tests object loader functionality.
1197 int UtcDaliVisualFactoryGetMeshVisual8(void)
1198 {
1199   //Set up test application first, so everything else can be handled.
1200   ToolkitTestApplication application;
1201
1202   tet_infoline( "UtcDaliVisualFactoryGetMeshVisual5:  Request mesh visual with normal-less object file." );
1203
1204   //Set up visual properties.
1205   Property::Map propertyMap;
1206   propertyMap.Insert( Visual::Property::TYPE, Visual::MESH );
1207   propertyMap.Insert( MeshVisual::Property::OBJECT_URL, TEST_SIMPLE_OBJ_FILE_NAME );
1208   propertyMap.Insert( MeshVisual::Property::MATERIAL_URL, TEST_MTL_FILE_NAME );
1209   propertyMap.Insert( MeshVisual::Property::TEXTURES_PATH, TEST_RESOURCE_DIR "/" );
1210
1211   //Test to see if mesh loads correctly.
1212   MeshVisualLoadsCorrectlyTest( propertyMap, application );
1213
1214   END_TEST;
1215 }
1216
1217 //Test if mesh visual handles the case of lacking an object file.
1218 int UtcDaliVisualFactoryGetMeshVisualN1(void)
1219 {
1220   //Set up test application first, so everything else can be handled.
1221   ToolkitTestApplication application;
1222
1223   tet_infoline( "UtcDaliVisualFactoryGetMeshVisualN1:  Request mesh visual without object file" );
1224
1225   //Set up visual properties.
1226   Property::Map propertyMap;
1227   propertyMap.Insert( Visual::Property::TYPE, Visual::MESH );
1228   propertyMap.Insert( MeshVisual::Property::MATERIAL_URL, TEST_MTL_FILE_NAME );
1229   propertyMap.Insert( MeshVisual::Property::TEXTURES_PATH, TEST_RESOURCE_DIR "/" );
1230
1231   //Test to see if mesh doesn't load with these properties, as expected.
1232   MeshVisualDoesNotLoadCorrectlyTest( propertyMap, application );
1233
1234
1235   END_TEST;
1236 }
1237
1238 //Test if mesh visual handles the case of being passed invalid material and images urls.
1239 int UtcDaliVisualFactoryGetMeshVisualN2(void)
1240 {
1241   //Set up test application first, so everything else can be handled.
1242   ToolkitTestApplication application;
1243
1244   tet_infoline( "UtcDaliVisualFactoryGetMeshVisualN2:  Request mesh visual with invalid material and images urls" );
1245
1246   //Set up visual properties.
1247   Property::Map propertyMap;
1248   propertyMap.Insert( Visual::Property::TYPE, Visual::MESH );
1249   propertyMap.Insert( MeshVisual::Property::OBJECT_URL, TEST_OBJ_FILE_NAME );
1250   propertyMap.Insert( MeshVisual::Property::MATERIAL_URL, "invalid" );
1251   propertyMap.Insert( MeshVisual::Property::TEXTURES_PATH, "also invalid" );
1252
1253   //Test to see if mesh doesn't load with these properties, as expected.
1254   MeshVisualDoesNotLoadCorrectlyTest( propertyMap, application );
1255
1256
1257   END_TEST;
1258 }
1259
1260 //Test if mesh visual handles the case of being passed an invalid object url
1261 int UtcDaliVisualFactoryGetMeshVisualN3(void)
1262 {
1263   //Set up test application first, so everything else can be handled.
1264   ToolkitTestApplication application;
1265   tet_infoline( "UtcDaliVisualFactoryGetMeshVisualN3:  Request mesh visual with invalid object url" );
1266
1267
1268   //Set up visual properties.
1269   Property::Map propertyMap;
1270   propertyMap.Insert( Visual::Property::TYPE, Visual::MESH );
1271   propertyMap.Insert( MeshVisual::Property::OBJECT_URL, "invalid" );
1272   propertyMap.Insert( MeshVisual::Property::MATERIAL_URL, TEST_MTL_FILE_NAME );
1273   propertyMap.Insert( MeshVisual::Property::TEXTURES_PATH, TEST_RESOURCE_DIR "/" );
1274
1275   //Test to see if mesh doesn't load with these properties, as expected.
1276   MeshVisualDoesNotLoadCorrectlyTest( propertyMap, application );
1277
1278   END_TEST;
1279 }
1280
1281 //Creates a primitive visual with the given property map and tests to see if it correctly loads in the given application.
1282 void TestPrimitiveVisualWithProperties( Property::Map& propertyMap, ToolkitTestApplication& application )
1283 {
1284   VisualFactory factory = VisualFactory::Get();
1285   DALI_TEST_CHECK( factory );
1286
1287   //Create a primitive visual.
1288   Visual::Base visual = factory.CreateVisual( propertyMap );
1289   DALI_TEST_CHECK( visual );
1290
1291   //Create an actor on stage to house the visual.
1292   Actor actor = Actor::New();
1293   actor.SetSize( 200.f, 200.f );
1294   Stage::GetCurrent().Add( actor );
1295   visual.SetSize( Vector2( 200.f, 200.f ) );
1296   visual.SetOnStage( actor );
1297
1298   //Ensure set on stage.
1299   DALI_TEST_EQUALS( actor.GetRendererCount(), 1u, TEST_LOCATION );
1300
1301   //Tell test application to load the visual.
1302   application.SendNotification();
1303   application.Render(0);
1304
1305   Matrix testScaleMatrix;
1306   testScaleMatrix.SetIdentityAndScale( Vector3( 1.0, -1.0, 1.0 ) );
1307   Matrix actualScaleMatrix;
1308
1309   //Test to see if the object has been successfully loaded.
1310   DALI_TEST_CHECK( application.GetGlAbstraction().GetUniformValue<Matrix>( "uObjectMatrix", actualScaleMatrix ) );
1311   DALI_TEST_EQUALS( actualScaleMatrix, testScaleMatrix, Math::MACHINE_EPSILON_100, TEST_LOCATION );
1312
1313   //Finish by setting off stage, and ensuring this was successful.
1314   visual.SetOffStage( actor );
1315   DALI_TEST_EQUALS( actor.GetRendererCount(), 0u, TEST_LOCATION );
1316 }
1317
1318 //Test if primitive shape loads correctly when supplied with only the bare minimum requirements, the shape to use.
1319 int UtcDaliVisualFactoryGetPrimitiveVisual1(void)
1320 {
1321   //Set up test application first, so everything else can be handled.
1322   ToolkitTestApplication application;
1323
1324   tet_infoline( "UtcDaliVisualFactoryGetPrimitiveVisual1:  Request primitive visual with a shape only" );
1325
1326   //Set up visual properties.
1327   Property::Map propertyMap;
1328   propertyMap.Insert( Visual::Property::TYPE, Visual::PRIMITIVE );
1329   propertyMap.Insert( PrimitiveVisual::Property::SHAPE, PrimitiveVisual::Shape::CUBE );
1330
1331   //Test to see if shape loads correctly.
1332   TestPrimitiveVisualWithProperties( propertyMap, application );
1333
1334   END_TEST;
1335 }
1336
1337 //Test if primitive shape loads correctly when supplied with all possible parameters
1338 int UtcDaliVisualFactoryGetPrimitiveVisual2(void)
1339 {
1340   //Set up test application first, so everything else can be handled.
1341   ToolkitTestApplication application;
1342
1343   tet_infoline( "UtcDaliVisualFactoryGetPrimitiveVisual2:  Request primitive visual with everything" );
1344
1345   //Set up visual properties.
1346   Property::Map propertyMap;
1347   propertyMap.Insert( Visual::Property::TYPE, Visual::PRIMITIVE );
1348   propertyMap.Insert( PrimitiveVisual::Property::SHAPE, PrimitiveVisual::Shape::CUBE );
1349   propertyMap.Insert( PrimitiveVisual::Property::COLOR, Vector4( 0.5, 0.5, 0.5, 1.0 ) );
1350   propertyMap.Insert( PrimitiveVisual::Property::SLICES, 10 );
1351   propertyMap.Insert( PrimitiveVisual::Property::STACKS, 20 );
1352   propertyMap.Insert( PrimitiveVisual::Property::SCALE_TOP_RADIUS, 30.0f );
1353   propertyMap.Insert( PrimitiveVisual::Property::SCALE_BOTTOM_RADIUS, 40.0f );
1354   propertyMap.Insert( PrimitiveVisual::Property::SCALE_HEIGHT, 50.0f );
1355   propertyMap.Insert( PrimitiveVisual::Property::SCALE_RADIUS, 60.0f );
1356   propertyMap.Insert( PrimitiveVisual::Property::BEVEL_PERCENTAGE, 0.7f );
1357   propertyMap.Insert( PrimitiveVisual::Property::BEVEL_SMOOTHNESS, 0.8f );
1358   propertyMap.Insert( MeshVisual::Property::LIGHT_POSITION, Vector3( 0.9, 1.0, 1.1 ) );
1359
1360   //Test to see if shape loads correctly.
1361   TestPrimitiveVisualWithProperties( propertyMap, application );
1362
1363   END_TEST;
1364 }
1365
1366 //Test if primitive shape loads a sphere correctly.
1367 int UtcDaliVisualFactoryGetPrimitiveVisual3(void)
1368 {
1369   //Set up test application first, so everything else can be handled.
1370   ToolkitTestApplication application;
1371
1372   tet_infoline( "UtcDaliVisualFactoryGetPrimitiveVisual3:  Request primitive visual to display a sphere" );
1373
1374   //Set up visual properties.
1375   Property::Map propertyMap;
1376   propertyMap.Insert( Visual::Property::TYPE, Visual::PRIMITIVE );
1377   propertyMap.Insert( PrimitiveVisual::Property::SHAPE, PrimitiveVisual::Shape::SPHERE );
1378   propertyMap.Insert( PrimitiveVisual::Property::COLOR, Vector4( 0.5, 0.5, 0.5, 1.0 ) );
1379   propertyMap.Insert( PrimitiveVisual::Property::SLICES, 10 );
1380   propertyMap.Insert( PrimitiveVisual::Property::STACKS, 20 );
1381
1382   //Test to see if shape loads correctly.
1383   TestPrimitiveVisualWithProperties( propertyMap, application );
1384
1385   END_TEST;
1386 }
1387
1388 //Test if primitive shape loads a conic section correctly.
1389 int UtcDaliVisualFactoryGetPrimitiveVisual4(void)
1390 {
1391   //Set up test application first, so everything else can be handled.
1392   ToolkitTestApplication application;
1393
1394   tet_infoline( "UtcDaliVisualFactoryGetPrimitiveVisual4:  Request primitive visual to display a conic section" );
1395
1396   //Set up visual properties.
1397   Property::Map propertyMap;
1398   propertyMap.Insert( Visual::Property::TYPE, Visual::PRIMITIVE );
1399   propertyMap.Insert( PrimitiveVisual::Property::SHAPE, PrimitiveVisual::Shape::CONICAL_FRUSTRUM );
1400   propertyMap.Insert( PrimitiveVisual::Property::COLOR, Vector4( 0.5, 0.5, 0.5, 1.0 ) );
1401   propertyMap.Insert( PrimitiveVisual::Property::SLICES, 10 );
1402   propertyMap.Insert( PrimitiveVisual::Property::SCALE_TOP_RADIUS, 30.0f );
1403   propertyMap.Insert( PrimitiveVisual::Property::SCALE_BOTTOM_RADIUS, 40.0f );
1404   propertyMap.Insert( PrimitiveVisual::Property::SCALE_HEIGHT, 50.0f );
1405
1406   //Test to see if shape loads correctly.
1407   TestPrimitiveVisualWithProperties( propertyMap, application );
1408
1409   END_TEST;
1410 }
1411
1412 //Test if primitive shape loads a bevelled cube correctly.
1413 int UtcDaliVisualFactoryGetPrimitiveVisual5(void)
1414 {
1415   //Set up test application first, so everything else can be handled.
1416   ToolkitTestApplication application;
1417
1418   tet_infoline( "UtcDaliVisualFactoryGetPrimitiveVisual5:  Request primitive visual to display a bevelled cube" );
1419
1420   //Set up visual properties.
1421   Property::Map propertyMap;
1422   propertyMap.Insert( Visual::Property::TYPE, Visual::PRIMITIVE );
1423   propertyMap.Insert( PrimitiveVisual::Property::SHAPE, PrimitiveVisual::Shape::BEVELLED_CUBE );
1424   propertyMap.Insert( PrimitiveVisual::Property::COLOR, Vector4( 0.5, 0.5, 0.5, 1.0 ) );
1425   propertyMap.Insert( PrimitiveVisual::Property::BEVEL_PERCENTAGE, 0.7f );
1426
1427   //Test to see if shape loads correctly.
1428   TestPrimitiveVisualWithProperties( propertyMap, application );
1429
1430   END_TEST;
1431 }
1432
1433 //Test if primitive shape loads an octahedron correctly.
1434 int UtcDaliVisualFactoryGetPrimitiveVisual6(void)
1435 {
1436   //Set up test application first, so everything else can be handled.
1437   ToolkitTestApplication application;
1438
1439   tet_infoline( "UtcDaliVisualFactoryGetPrimitiveVisual6:  Request primitive visual to display an octahedron" );
1440
1441   //Set up visual properties.
1442   Property::Map propertyMap;
1443   propertyMap.Insert( Visual::Property::TYPE, Visual::PRIMITIVE );
1444   propertyMap.Insert( PrimitiveVisual::Property::SHAPE, PrimitiveVisual::Shape::OCTAHEDRON );
1445   propertyMap.Insert( PrimitiveVisual::Property::COLOR, Vector4( 0.5, 0.5, 0.5, 1.0 ) );
1446
1447   //Test to see if shape loads correctly.
1448   TestPrimitiveVisualWithProperties( propertyMap, application );
1449
1450   END_TEST;
1451 }
1452
1453 //Test if primitive shape loads a cone correctly.
1454 int UtcDaliVisualFactoryGetPrimitiveVisual7(void)
1455 {
1456   //Set up test application first, so everything else can be handled.
1457   ToolkitTestApplication application;
1458
1459   tet_infoline( "UtcDaliVisualFactoryGetPrimitiveVisual7:  Request primitive visual to display a cone" );
1460
1461   //Set up visual properties.
1462   Property::Map propertyMap;
1463   propertyMap.Insert( Visual::Property::TYPE, Visual::PRIMITIVE );
1464   propertyMap.Insert( PrimitiveVisual::Property::SHAPE, PrimitiveVisual::Shape::CONE );
1465   propertyMap.Insert( PrimitiveVisual::Property::COLOR, Vector4( 0.5, 0.5, 0.5, 1.0 ) );
1466   propertyMap.Insert( PrimitiveVisual::Property::SLICES, 10 );
1467   propertyMap.Insert( PrimitiveVisual::Property::SCALE_TOP_RADIUS, 30.0f );
1468   propertyMap.Insert( PrimitiveVisual::Property::SCALE_HEIGHT, 50.0f );
1469
1470   //Test to see if shape loads correctly.
1471   TestPrimitiveVisualWithProperties( propertyMap, application );
1472
1473   END_TEST;
1474 }
1475
1476 //Test if primitive shape loads correctly when light position is manually set.
1477 int UtcDaliVisualFactoryGetPrimitiveVisual8(void)
1478 {
1479   //Set up test application first, so everything else can be handled.
1480   ToolkitTestApplication application;
1481
1482   tet_infoline( "UtcDaliVisualFactoryGetPrimitiveVisual8:  Request primitive visual with set light position" );
1483
1484   //Set up visual properties.
1485   Property::Map propertyMap;
1486   propertyMap.Insert( Visual::Property::TYPE, Visual::PRIMITIVE );
1487   propertyMap.Insert( PrimitiveVisual::Property::SHAPE, PrimitiveVisual::Shape::SPHERE );
1488   propertyMap.Insert( PrimitiveVisual::Property::COLOR, Vector4( 0.5, 0.5, 0.5, 1.0 ) );
1489   propertyMap.Insert( MeshVisual::Property::LIGHT_POSITION, Vector3( 0.0, 1.0, 2.0 ) );
1490
1491   //Test to see if shape loads correctly.
1492   TestPrimitiveVisualWithProperties( propertyMap, application );
1493
1494   END_TEST;
1495 }
1496
1497 //Test if primitive shape renderer handles the case of not being passed a specific shape to use.
1498 int UtcDaliVisualFactoryGetPrimitiveVisualN1(void)
1499 {
1500   //Set up test application first, so everything else can be handled.
1501   ToolkitTestApplication application;
1502
1503   tet_infoline( "UtcDaliVisualFactoryGetPrimitiveVisualN1:  Request primitive visual without shape" );
1504
1505   //Set up visual properties, without supplying shape.
1506   Property::Map propertyMap;
1507   propertyMap.Insert( Visual::Property::TYPE, Visual::PRIMITIVE );
1508
1509   //Test to see if shape loads regardless of missing input.
1510   TestPrimitiveVisualWithProperties( propertyMap, application );
1511
1512   END_TEST;
1513 }
1514
1515 int UtcDaliVisualFactoryGetBatchImageVisual1(void)
1516 {
1517   ToolkitTestApplication application;
1518   tet_infoline( "UtcDaliVisualFactoryGetBatchImageVisual1: Request a Batch Image visual with a Property::Map" );
1519
1520   VisualFactory factory = VisualFactory::Get();
1521   DALI_TEST_CHECK( factory );
1522
1523   Property::Map propertyMap;
1524   propertyMap.Insert( Visual::Property::TYPE, Visual::BATCH_IMAGE );
1525   propertyMap.Insert( BatchImageVisual::Property::URL, TEST_IMAGE_FILE_NAME );
1526
1527   Visual::Base visual = factory.CreateVisual( propertyMap );
1528   DALI_TEST_CHECK( visual );
1529
1530   Actor actor = Actor::New();
1531
1532   actor.SetSize( 200.0f, 200.0f );
1533   Stage::GetCurrent().Add( actor );
1534   visual.SetSize( Vector2( 200.0f, 200.0f ) );
1535
1536   // Test SetOnStage().
1537   visual.SetOnStage( actor );
1538   DALI_TEST_CHECK( actor.GetRendererCount() == 1u );
1539
1540   application.SendNotification();
1541   application.Render();
1542
1543   // Test SetOffStage().
1544   visual.SetOffStage( actor );
1545   DALI_TEST_CHECK( actor.GetRendererCount() == 0u );
1546
1547   END_TEST;
1548 }
1549
1550 int UtcDaliVisualFactoryGetBatchImageVisual2(void)
1551 {
1552   ToolkitTestApplication application;
1553   tet_infoline( "UtcDaliVisualFactoryGetBatchImageVisual2: Request Batch Image visual from an Image Visual with batchingEnabled set" );
1554
1555   VisualFactory factory = VisualFactory::Get();
1556   DALI_TEST_CHECK( factory );
1557
1558   Property::Map propertyMap;
1559   // Create a normal Image Visual.
1560   propertyMap.Insert( Visual::Property::TYPE, Visual::IMAGE );
1561   // Instruct the factory to change Image Visuals to Batch-Image Visuals.
1562   propertyMap.Insert( Visual::Property::BATCHING_ENABLED, true );
1563
1564   // Properties for the Batch-Image Visual.
1565   propertyMap.Insert( BatchImageVisual::Property::URL, TEST_IMAGE_FILE_NAME );
1566
1567   Visual::Base visual = factory.CreateVisual( propertyMap );
1568   DALI_TEST_CHECK( visual );
1569
1570   // Check that a Batch-Image visual was created instead of an Image visual.
1571   Property::Map resultMap;
1572   visual.CreatePropertyMap( resultMap );
1573
1574   Property::Value* value = resultMap.Find( Visual::Property::TYPE, Property::INTEGER );
1575   DALI_TEST_CHECK( value );
1576   DALI_TEST_EQUALS( value->Get<int>(), (int)Visual::BATCH_IMAGE, TEST_LOCATION );
1577
1578   Actor actor = Actor::New();
1579
1580   actor.SetSize( 200.0f, 200.0f );
1581   Stage::GetCurrent().Add( actor );
1582   visual.SetSize( Vector2( 200.0f, 200.0f ) );
1583
1584   // Test SetOnStage().
1585   visual.SetOnStage( actor );
1586   DALI_TEST_CHECK( actor.GetRendererCount() == 1u );
1587
1588   application.SendNotification();
1589   application.Render();
1590
1591   // Test SetOffStage().
1592   visual.SetOffStage( actor );
1593   DALI_TEST_CHECK( actor.GetRendererCount() == 0u );
1594
1595   END_TEST;
1596 }
1597
1598 int UtcDaliVisualFactoryGetBatchImageVisual3(void)
1599 {
1600   ToolkitTestApplication application;
1601   tet_infoline( "UtcDaliVisualFactoryGetBatchImageVisual3: Create an ImageView that uses a batched visual internally" );
1602
1603   VisualFactory factory = VisualFactory::Get();
1604   DALI_TEST_CHECK( factory );
1605
1606   // Create a property-map that enables batching.
1607   Property::Map propertyMap;
1608   propertyMap.Insert( Dali::Toolkit::BatchImageVisual::Property::URL, TEST_IMAGE_FILE_NAME );
1609   propertyMap.Insert( Visual::Property::BATCHING_ENABLED, true );
1610
1611   // Create an ImageView, passing the property-map in to instruct it to use batching.
1612   Toolkit::ImageView imageView = Toolkit::ImageView::New();
1613   imageView.SetProperty( Toolkit::ImageView::Property::IMAGE, propertyMap );
1614
1615   imageView.SetSize( 200.0f, 200.0f );
1616   Stage::GetCurrent().Add( imageView );
1617
1618   END_TEST;
1619 }