Stop creating image visuals by default
[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 URL" );
884
885   VisualFactory factory = VisualFactory::Get();
886   DALI_TEST_CHECK( factory );
887
888   Property::Map propertyMap;
889   propertyMap.Insert( Visual::Property::TYPE,  Visual::IMAGE );
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 UtcDaliVisualFactoryGetNPatchVisualN3(void)
915 {
916   // Passing in an invalid visual type so we should not get a visual
917
918   ToolkitTestApplication application;
919   tet_infoline( "UtcDaliVisualFactoryGetNPatchVisualN: Request n-patch visual with an invalid visual type" );
920
921   VisualFactory factory = VisualFactory::Get();
922   DALI_TEST_CHECK( factory );
923
924   Property::Map propertyMap;
925   propertyMap.Insert( Visual::Property::TYPE,  111 );
926   propertyMap.Insert( ImageVisual::Property::URL,  "ERROR.9.jpg" );
927
928   Visual::Base visual = factory.CreateVisual( propertyMap );
929   DALI_TEST_CHECK( !visual );
930
931   END_TEST;
932 }
933
934 int UtcDaliVisualFactoryGetSvgVisual(void)
935 {
936   ToolkitTestApplication application;
937   tet_infoline( "UtcDaliVisualFactoryGetSvgVisual: Request svg visual with a svg url" );
938
939   VisualFactory factory = VisualFactory::Get();
940   Visual::Base visual = factory.CreateVisual( TEST_SVG_FILE_NAME, ImageDimensions() );
941   DALI_TEST_CHECK( visual );
942
943   TestGlAbstraction& gl = application.GetGlAbstraction();
944   TraceCallStack& textureTrace = gl.GetTextureTrace();
945   textureTrace.Enable(true);
946
947   Actor actor = Actor::New();
948   actor.SetSize( 200.f, 200.f );
949   Stage::GetCurrent().Add( actor );
950   visual.SetSize( Vector2(200.f, 200.f) );
951   visual.SetOnStage( actor );
952   application.SendNotification();
953   application.Render();
954
955   DALI_TEST_CHECK( actor.GetRendererCount() == 1u );
956
957   EventThreadCallback* eventTrigger = EventThreadCallback::Get();
958   CallbackBase* callback = eventTrigger->GetCallback();
959
960   eventTrigger->WaitingForTrigger( 1 );// waiting until the svg image is rasterized.
961   CallbackBase::Execute( *callback );
962
963   DALI_TEST_CHECK( actor.GetRendererCount() == 1u );
964
965   // waiting for the resource uploading
966   application.SendNotification();
967   application.Render();
968
969   DALI_TEST_EQUALS( textureTrace.FindMethod("BindTexture"), true, TEST_LOCATION );
970
971   END_TEST;
972 }
973
974 //Creates a mesh renderer from the given propertyMap and tries to load it on stage in the given application.
975 //This is expected to succeed, which will then pass the test.
976 void MeshVisualLoadsCorrectlyTest( Property::Map& propertyMap, ToolkitTestApplication& application )
977 {
978   VisualFactory factory = VisualFactory::Get();
979   DALI_TEST_CHECK( factory );
980
981   //Create a mesh visual.
982   Visual::Base visual = factory.CreateVisual( propertyMap );
983   DALI_TEST_CHECK( visual );
984
985   //Create an actor on stage to house the visual.
986   Actor actor = Actor::New();
987   actor.SetSize( 200.f, 200.f );
988   Stage::GetCurrent().Add( actor );
989   visual.SetSize( Vector2( 200.f, 200.f ) );
990   visual.SetOnStage( actor );
991
992   //Ensure set on stage.
993   DALI_TEST_EQUALS( actor.GetRendererCount(), 1u, TEST_LOCATION );
994
995   //Attempt to render to queue resource load requests.
996   application.SendNotification();
997   application.Render( 0 );
998
999   //Tell the platform abstraction that the required resources have been loaded.
1000   TestPlatformAbstraction& platform = application.GetPlatform();
1001   platform.SetAllResourceRequestsAsLoaded();
1002
1003   //Render again to upload the now-loaded textures.
1004   application.SendNotification();
1005   application.Render( 0 );
1006
1007   Matrix testScaleMatrix;
1008   testScaleMatrix.SetIdentityAndScale( Vector3( 1.0, -1.0, 1.0 ) );
1009   Matrix actualScaleMatrix;
1010
1011   //Test to see if the object has been successfully loaded.
1012   DALI_TEST_CHECK( application.GetGlAbstraction().GetUniformValue<Matrix>( "uObjectMatrix", actualScaleMatrix ) );
1013   DALI_TEST_EQUALS( actualScaleMatrix, testScaleMatrix, Math::MACHINE_EPSILON_100, TEST_LOCATION );
1014
1015   //Finish by setting off stage, and ensuring this was successful.
1016   visual.SetOffStage( actor );
1017   DALI_TEST_EQUALS( actor.GetRendererCount(), 0u, TEST_LOCATION );
1018 }
1019
1020 //Creates a mesh visual from the given propertyMap and tries to load it on stage in the given application.
1021 //This is expected to fail, which will then pass the test.
1022 void MeshVisualDoesNotLoadCorrectlyTest( Property::Map& propertyMap, ToolkitTestApplication& application )
1023 {
1024   VisualFactory factory = VisualFactory::Get();
1025   DALI_TEST_CHECK( factory );
1026
1027   //Create a mesh visual.
1028   Visual::Base visual = factory.CreateVisual( propertyMap );
1029   DALI_TEST_CHECK( visual );
1030
1031   //Create an actor on stage to house the visual.
1032   Actor actor = Actor::New();
1033   actor.SetSize( 200.f, 200.f );
1034   Stage::GetCurrent().Add( actor );
1035   visual.SetSize( Vector2( 200.f, 200.f ) );
1036   visual.SetOnStage( actor );
1037
1038   //Ensure set on stage.
1039   DALI_TEST_EQUALS( actor.GetRendererCount(), 1u, TEST_LOCATION );
1040
1041   //Attempt to render to queue resource load requests.
1042   application.SendNotification();
1043   application.Render( 0 );
1044
1045   //Tell the platform abstraction that the required resources have been loaded.
1046   TestPlatformAbstraction& platform = application.GetPlatform();
1047   platform.SetAllResourceRequestsAsLoaded();
1048
1049   //Render again to upload the now-loaded textures.
1050   application.SendNotification();
1051   application.Render( 0 );
1052
1053   //Test to see if the object has not been loaded, as expected.
1054   Matrix scaleMatrix;
1055   DALI_TEST_CHECK( !application.GetGlAbstraction().GetUniformValue<Matrix>( "uObjectMatrix", scaleMatrix ) );
1056
1057   //Finish by setting off stage, and ensuring this was successful.
1058   visual.SetOffStage( actor );
1059   DALI_TEST_EQUALS( actor.GetRendererCount(), 0u, TEST_LOCATION );
1060 }
1061
1062 //Test if mesh loads correctly when supplied with only the bare minimum requirements, an object file.
1063 int UtcDaliVisualFactoryGetMeshVisual1(void)
1064 {
1065   //Set up test application first, so everything else can be handled.
1066   ToolkitTestApplication application;
1067
1068   tet_infoline( "UtcDaliVisualFactoryGetMeshVisual1:  Request mesh visual with a valid object file only" );
1069
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
1076   //Test to see if mesh loads correctly.
1077   MeshVisualLoadsCorrectlyTest( propertyMap, application );
1078
1079   END_TEST;
1080 }
1081
1082
1083 //Test if mesh loads correctly when supplied with an object file as well as a blank material file and images directory.
1084 int UtcDaliVisualFactoryGetMeshVisual2(void)
1085 {
1086   //Set up test application first, so everything else can be handled.
1087   ToolkitTestApplication application;
1088
1089   tet_infoline( "UtcDaliVisualFactoryGetMeshVisual2:  Request mesh visual with blank material file and images directory" );
1090
1091   //Set up visual properties.
1092   Property::Map propertyMap;
1093   propertyMap.Insert( Visual::Property::TYPE, Visual::MESH );
1094   propertyMap.Insert( MeshVisual::Property::OBJECT_URL, TEST_OBJ_FILE_NAME );
1095   propertyMap.Insert( MeshVisual::Property::MATERIAL_URL, "" );
1096   propertyMap.Insert( MeshVisual::Property::TEXTURES_PATH, "" );
1097
1098   //Test to see if mesh loads correctly.
1099   MeshVisualLoadsCorrectlyTest( propertyMap, application );
1100
1101   END_TEST;
1102 }
1103
1104 //Test if mesh loads correctly when supplied with all main parameters, an object file, a material file and a directory location.
1105 int UtcDaliVisualFactoryGetMeshVisual3(void)
1106 {
1107   //Set up test application first, so everything else can be handled.
1108   ToolkitTestApplication application;
1109
1110   tet_infoline( "UtcDaliVisualFactoryGetMeshVisual3:  Request mesh visual with all parameters correct" );
1111
1112   //Set up visual properties.
1113   Property::Map propertyMap;
1114   propertyMap.Insert( Visual::Property::TYPE, Visual::MESH );
1115   propertyMap.Insert( MeshVisual::Property::OBJECT_URL, TEST_OBJ_FILE_NAME );
1116   propertyMap.Insert( MeshVisual::Property::MATERIAL_URL, TEST_MTL_FILE_NAME );
1117   propertyMap.Insert( MeshVisual::Property::TEXTURES_PATH, TEST_RESOURCE_DIR "/" );
1118
1119   //Test to see if mesh loads correctly.
1120   MeshVisualLoadsCorrectlyTest( propertyMap, application );
1121
1122   END_TEST;
1123 }
1124
1125 //Test if mesh visual can load a correctly supplied mesh without a normal map or gloss map in the material file.
1126 int UtcDaliVisualFactoryGetMeshVisual4(void)
1127 {
1128   //Set up test application first, so everything else can be handled.
1129   ToolkitTestApplication application;
1130
1131   tet_infoline( "UtcDaliVisualFactoryGetMeshVisual4:  Request mesh visual with diffuse texture but not normal or gloss." );
1132
1133
1134   //Set up visual properties.
1135   Property::Map propertyMap;
1136   propertyMap.Insert( Visual::Property::TYPE, Visual::MESH );
1137   propertyMap.Insert( MeshVisual::Property::OBJECT_URL, TEST_OBJ_FILE_NAME );
1138   propertyMap.Insert( MeshVisual::Property::MATERIAL_URL, TEST_SIMPLE_MTL_FILE_NAME );
1139   propertyMap.Insert( MeshVisual::Property::TEXTURES_PATH, TEST_RESOURCE_DIR "/" );
1140
1141   //Test to see if mesh loads correctly.
1142   MeshVisualLoadsCorrectlyTest( propertyMap, application );
1143
1144
1145   END_TEST;
1146 }
1147
1148 //Test if mesh visual can load when made to use diffuse textures only.
1149 int UtcDaliVisualFactoryGetMeshVisual5(void)
1150 {
1151   //Set up test application first, so everything else can be handled.
1152   ToolkitTestApplication application;
1153
1154   tet_infoline( "UtcDaliVisualFactoryGetMeshVisual5:  Request mesh visual and make it only use diffuse textures." );
1155
1156   //Set up visual properties.
1157   Property::Map propertyMap;
1158   propertyMap.Insert( Visual::Property::TYPE, Visual::MESH );
1159   propertyMap.Insert( MeshVisual::Property::OBJECT_URL, TEST_OBJ_FILE_NAME );
1160   propertyMap.Insert( MeshVisual::Property::MATERIAL_URL, TEST_MTL_FILE_NAME );
1161   propertyMap.Insert( MeshVisual::Property::TEXTURES_PATH, TEST_RESOURCE_DIR "/" );
1162   propertyMap.Insert( MeshVisual::Property::SHADING_MODE, MeshVisual::ShadingMode::TEXTURED_WITH_SPECULAR_LIGHTING );
1163
1164   //Test to see if mesh loads correctly.
1165   MeshVisualLoadsCorrectlyTest( propertyMap, application );
1166
1167
1168   END_TEST;
1169 }
1170
1171 //Test if mesh visual can load when made to not use the supplied textures.
1172 int UtcDaliVisualFactoryGetMeshVisual6(void)
1173 {
1174   //Set up test application first, so everything else can be handled.
1175   ToolkitTestApplication application;
1176
1177   tet_infoline( "UtcDaliVisualFactoryGetMeshVisual6:  Request mesh visual and make it not use any textures." );
1178
1179   //Set up visual properties.
1180   Property::Map propertyMap;
1181   propertyMap.Insert( Visual::Property::TYPE, Visual::MESH );
1182   propertyMap.Insert( MeshVisual::Property::OBJECT_URL, TEST_OBJ_FILE_NAME );
1183   propertyMap.Insert( MeshVisual::Property::MATERIAL_URL, TEST_MTL_FILE_NAME );
1184   propertyMap.Insert( MeshVisual::Property::TEXTURES_PATH, TEST_RESOURCE_DIR "/" );
1185   propertyMap.Insert( MeshVisual::Property::SHADING_MODE, MeshVisual::ShadingMode::TEXTURELESS_WITH_DIFFUSE_LIGHTING );
1186
1187   //Test to see if mesh loads correctly.
1188   MeshVisualLoadsCorrectlyTest( propertyMap, application );
1189
1190   END_TEST;
1191 }
1192 //Test if mesh visual loads correctly when light position is manually set.
1193 int UtcDaliVisualFactoryGetMeshVisual7(void)
1194 {
1195   //Set up test application first, so everything else can be handled.
1196   ToolkitTestApplication application;
1197
1198
1199   tet_infoline( "UtcDaliVisualFactoryGetMeshVisual7:  Request mesh visual with custom light position." );
1200
1201   //Set up visual properties.
1202   Property::Map propertyMap;
1203   propertyMap.Insert( Visual::Property::TYPE, Visual::MESH );
1204   propertyMap.Insert( MeshVisual::Property::OBJECT_URL, TEST_OBJ_FILE_NAME );
1205   propertyMap.Insert( MeshVisual::Property::MATERIAL_URL, TEST_MTL_FILE_NAME );
1206   propertyMap.Insert( MeshVisual::Property::TEXTURES_PATH, TEST_RESOURCE_DIR "/" );
1207   propertyMap.Insert( MeshVisual::Property::LIGHT_POSITION, Vector3( 0.0, 1.0, 2.0 ) );
1208
1209   //Test to see if mesh loads correctly.
1210   MeshVisualLoadsCorrectlyTest( propertyMap, application );
1211
1212   END_TEST;
1213 }
1214
1215 //Test if mesh visual loads correctly when supplied an object file without face normals or texture points.
1216 //Note that this notably tests object loader functionality.
1217 int UtcDaliVisualFactoryGetMeshVisual8(void)
1218 {
1219   //Set up test application first, so everything else can be handled.
1220   ToolkitTestApplication application;
1221
1222   tet_infoline( "UtcDaliVisualFactoryGetMeshVisual5:  Request mesh visual with normal-less object file." );
1223
1224   //Set up visual properties.
1225   Property::Map propertyMap;
1226   propertyMap.Insert( Visual::Property::TYPE, Visual::MESH );
1227   propertyMap.Insert( MeshVisual::Property::OBJECT_URL, TEST_SIMPLE_OBJ_FILE_NAME );
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 loads correctly.
1232   MeshVisualLoadsCorrectlyTest( propertyMap, application );
1233
1234   END_TEST;
1235 }
1236
1237 //Test if mesh visual handles the case of lacking an object file.
1238 int UtcDaliVisualFactoryGetMeshVisualN1(void)
1239 {
1240   //Set up test application first, so everything else can be handled.
1241   ToolkitTestApplication application;
1242
1243   tet_infoline( "UtcDaliVisualFactoryGetMeshVisualN1:  Request mesh visual without object file" );
1244
1245   //Set up visual properties.
1246   Property::Map propertyMap;
1247   propertyMap.Insert( Visual::Property::TYPE, Visual::MESH );
1248   propertyMap.Insert( MeshVisual::Property::MATERIAL_URL, TEST_MTL_FILE_NAME );
1249   propertyMap.Insert( MeshVisual::Property::TEXTURES_PATH, TEST_RESOURCE_DIR "/" );
1250
1251   //Test to see if mesh doesn't load with these properties, as expected.
1252   MeshVisualDoesNotLoadCorrectlyTest( propertyMap, application );
1253
1254
1255   END_TEST;
1256 }
1257
1258 //Test if mesh visual handles the case of being passed invalid material and images urls.
1259 int UtcDaliVisualFactoryGetMeshVisualN2(void)
1260 {
1261   //Set up test application first, so everything else can be handled.
1262   ToolkitTestApplication application;
1263
1264   tet_infoline( "UtcDaliVisualFactoryGetMeshVisualN2:  Request mesh visual with invalid material and images urls" );
1265
1266   //Set up visual properties.
1267   Property::Map propertyMap;
1268   propertyMap.Insert( Visual::Property::TYPE, Visual::MESH );
1269   propertyMap.Insert( MeshVisual::Property::OBJECT_URL, TEST_OBJ_FILE_NAME );
1270   propertyMap.Insert( MeshVisual::Property::MATERIAL_URL, "invalid" );
1271   propertyMap.Insert( MeshVisual::Property::TEXTURES_PATH, "also invalid" );
1272
1273   //Test to see if mesh doesn't load with these properties, as expected.
1274   MeshVisualDoesNotLoadCorrectlyTest( propertyMap, application );
1275
1276
1277   END_TEST;
1278 }
1279
1280 //Test if mesh visual handles the case of being passed an invalid object url
1281 int UtcDaliVisualFactoryGetMeshVisualN3(void)
1282 {
1283   //Set up test application first, so everything else can be handled.
1284   ToolkitTestApplication application;
1285   tet_infoline( "UtcDaliVisualFactoryGetMeshVisualN3:  Request mesh visual with invalid object url" );
1286
1287
1288   //Set up visual properties.
1289   Property::Map propertyMap;
1290   propertyMap.Insert( Visual::Property::TYPE, Visual::MESH );
1291   propertyMap.Insert( MeshVisual::Property::OBJECT_URL, "invalid" );
1292   propertyMap.Insert( MeshVisual::Property::MATERIAL_URL, TEST_MTL_FILE_NAME );
1293   propertyMap.Insert( MeshVisual::Property::TEXTURES_PATH, TEST_RESOURCE_DIR "/" );
1294
1295   //Test to see if mesh doesn't load with these properties, as expected.
1296   MeshVisualDoesNotLoadCorrectlyTest( propertyMap, application );
1297
1298   END_TEST;
1299 }
1300
1301 //Creates a primitive visual with the given property map and tests to see if it correctly loads in the given application.
1302 void TestPrimitiveVisualWithProperties( Property::Map& propertyMap, ToolkitTestApplication& application )
1303 {
1304   VisualFactory factory = VisualFactory::Get();
1305   DALI_TEST_CHECK( factory );
1306
1307   //Create a primitive visual.
1308   Visual::Base visual = factory.CreateVisual( propertyMap );
1309   DALI_TEST_CHECK( visual );
1310
1311   //Create an actor on stage to house the visual.
1312   Actor actor = Actor::New();
1313   actor.SetSize( 200.f, 200.f );
1314   Stage::GetCurrent().Add( actor );
1315   visual.SetSize( Vector2( 200.f, 200.f ) );
1316   visual.SetOnStage( actor );
1317
1318   //Ensure set on stage.
1319   DALI_TEST_EQUALS( actor.GetRendererCount(), 1u, TEST_LOCATION );
1320
1321   //Tell test application to load the visual.
1322   application.SendNotification();
1323   application.Render(0);
1324
1325   Matrix testScaleMatrix;
1326   testScaleMatrix.SetIdentityAndScale( Vector3( 1.0, -1.0, 1.0 ) );
1327   Matrix actualScaleMatrix;
1328
1329   //Test to see if the object has been successfully loaded.
1330   DALI_TEST_CHECK( application.GetGlAbstraction().GetUniformValue<Matrix>( "uObjectMatrix", actualScaleMatrix ) );
1331   DALI_TEST_EQUALS( actualScaleMatrix, testScaleMatrix, Math::MACHINE_EPSILON_100, TEST_LOCATION );
1332
1333   //Finish by setting off stage, and ensuring this was successful.
1334   visual.SetOffStage( actor );
1335   DALI_TEST_EQUALS( actor.GetRendererCount(), 0u, TEST_LOCATION );
1336 }
1337
1338 //Test if primitive shape loads correctly when supplied with only the bare minimum requirements, the shape to use.
1339 int UtcDaliVisualFactoryGetPrimitiveVisual1(void)
1340 {
1341   //Set up test application first, so everything else can be handled.
1342   ToolkitTestApplication application;
1343
1344   tet_infoline( "UtcDaliVisualFactoryGetPrimitiveVisual1:  Request primitive visual with a shape only" );
1345
1346   //Set up visual properties.
1347   Property::Map propertyMap;
1348   propertyMap.Insert( Visual::Property::TYPE, Visual::PRIMITIVE );
1349   propertyMap.Insert( PrimitiveVisual::Property::SHAPE, PrimitiveVisual::Shape::CUBE );
1350
1351   //Test to see if shape loads correctly.
1352   TestPrimitiveVisualWithProperties( propertyMap, application );
1353
1354   END_TEST;
1355 }
1356
1357 //Test if primitive shape loads correctly when supplied with all possible parameters
1358 int UtcDaliVisualFactoryGetPrimitiveVisual2(void)
1359 {
1360   //Set up test application first, so everything else can be handled.
1361   ToolkitTestApplication application;
1362
1363   tet_infoline( "UtcDaliVisualFactoryGetPrimitiveVisual2:  Request primitive visual with everything" );
1364
1365   //Set up visual properties.
1366   Property::Map propertyMap;
1367   propertyMap.Insert( Visual::Property::TYPE, Visual::PRIMITIVE );
1368   propertyMap.Insert( PrimitiveVisual::Property::SHAPE, PrimitiveVisual::Shape::CUBE );
1369   propertyMap.Insert( PrimitiveVisual::Property::COLOR, Vector4( 0.5, 0.5, 0.5, 1.0 ) );
1370   propertyMap.Insert( PrimitiveVisual::Property::SLICES, 10 );
1371   propertyMap.Insert( PrimitiveVisual::Property::STACKS, 20 );
1372   propertyMap.Insert( PrimitiveVisual::Property::SCALE_TOP_RADIUS, 30.0f );
1373   propertyMap.Insert( PrimitiveVisual::Property::SCALE_BOTTOM_RADIUS, 40.0f );
1374   propertyMap.Insert( PrimitiveVisual::Property::SCALE_HEIGHT, 50.0f );
1375   propertyMap.Insert( PrimitiveVisual::Property::SCALE_RADIUS, 60.0f );
1376   propertyMap.Insert( PrimitiveVisual::Property::BEVEL_PERCENTAGE, 0.7f );
1377   propertyMap.Insert( PrimitiveVisual::Property::BEVEL_SMOOTHNESS, 0.8f );
1378   propertyMap.Insert( MeshVisual::Property::LIGHT_POSITION, Vector3( 0.9, 1.0, 1.1 ) );
1379
1380   //Test to see if shape loads correctly.
1381   TestPrimitiveVisualWithProperties( propertyMap, application );
1382
1383   END_TEST;
1384 }
1385
1386 //Test if primitive shape loads a sphere correctly.
1387 int UtcDaliVisualFactoryGetPrimitiveVisual3(void)
1388 {
1389   //Set up test application first, so everything else can be handled.
1390   ToolkitTestApplication application;
1391
1392   tet_infoline( "UtcDaliVisualFactoryGetPrimitiveVisual3:  Request primitive visual to display a sphere" );
1393
1394   //Set up visual properties.
1395   Property::Map propertyMap;
1396   propertyMap.Insert( Visual::Property::TYPE, Visual::PRIMITIVE );
1397   propertyMap.Insert( PrimitiveVisual::Property::SHAPE, PrimitiveVisual::Shape::SPHERE );
1398   propertyMap.Insert( PrimitiveVisual::Property::COLOR, Vector4( 0.5, 0.5, 0.5, 1.0 ) );
1399   propertyMap.Insert( PrimitiveVisual::Property::SLICES, 10 );
1400   propertyMap.Insert( PrimitiveVisual::Property::STACKS, 20 );
1401
1402   //Test to see if shape loads correctly.
1403   TestPrimitiveVisualWithProperties( propertyMap, application );
1404
1405   END_TEST;
1406 }
1407
1408 //Test if primitive shape loads a conic section correctly.
1409 int UtcDaliVisualFactoryGetPrimitiveVisual4(void)
1410 {
1411   //Set up test application first, so everything else can be handled.
1412   ToolkitTestApplication application;
1413
1414   tet_infoline( "UtcDaliVisualFactoryGetPrimitiveVisual4:  Request primitive visual to display a conic section" );
1415
1416   //Set up visual properties.
1417   Property::Map propertyMap;
1418   propertyMap.Insert( Visual::Property::TYPE, Visual::PRIMITIVE );
1419   propertyMap.Insert( PrimitiveVisual::Property::SHAPE, PrimitiveVisual::Shape::CONICAL_FRUSTRUM );
1420   propertyMap.Insert( PrimitiveVisual::Property::COLOR, Vector4( 0.5, 0.5, 0.5, 1.0 ) );
1421   propertyMap.Insert( PrimitiveVisual::Property::SLICES, 10 );
1422   propertyMap.Insert( PrimitiveVisual::Property::SCALE_TOP_RADIUS, 30.0f );
1423   propertyMap.Insert( PrimitiveVisual::Property::SCALE_BOTTOM_RADIUS, 40.0f );
1424   propertyMap.Insert( PrimitiveVisual::Property::SCALE_HEIGHT, 50.0f );
1425
1426   //Test to see if shape loads correctly.
1427   TestPrimitiveVisualWithProperties( propertyMap, application );
1428
1429   END_TEST;
1430 }
1431
1432 //Test if primitive shape loads a bevelled cube correctly.
1433 int UtcDaliVisualFactoryGetPrimitiveVisual5(void)
1434 {
1435   //Set up test application first, so everything else can be handled.
1436   ToolkitTestApplication application;
1437
1438   tet_infoline( "UtcDaliVisualFactoryGetPrimitiveVisual5:  Request primitive visual to display a bevelled cube" );
1439
1440   //Set up visual properties.
1441   Property::Map propertyMap;
1442   propertyMap.Insert( Visual::Property::TYPE, Visual::PRIMITIVE );
1443   propertyMap.Insert( PrimitiveVisual::Property::SHAPE, PrimitiveVisual::Shape::BEVELLED_CUBE );
1444   propertyMap.Insert( PrimitiveVisual::Property::COLOR, Vector4( 0.5, 0.5, 0.5, 1.0 ) );
1445   propertyMap.Insert( PrimitiveVisual::Property::BEVEL_PERCENTAGE, 0.7f );
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 an octahedron correctly.
1454 int UtcDaliVisualFactoryGetPrimitiveVisual6(void)
1455 {
1456   //Set up test application first, so everything else can be handled.
1457   ToolkitTestApplication application;
1458
1459   tet_infoline( "UtcDaliVisualFactoryGetPrimitiveVisual6:  Request primitive visual to display an octahedron" );
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::OCTAHEDRON );
1465   propertyMap.Insert( PrimitiveVisual::Property::COLOR, Vector4( 0.5, 0.5, 0.5, 1.0 ) );
1466
1467   //Test to see if shape loads correctly.
1468   TestPrimitiveVisualWithProperties( propertyMap, application );
1469
1470   END_TEST;
1471 }
1472
1473 //Test if primitive shape loads a cone correctly.
1474 int UtcDaliVisualFactoryGetPrimitiveVisual7(void)
1475 {
1476   //Set up test application first, so everything else can be handled.
1477   ToolkitTestApplication application;
1478
1479   tet_infoline( "UtcDaliVisualFactoryGetPrimitiveVisual7:  Request primitive visual to display a cone" );
1480
1481   //Set up visual properties.
1482   Property::Map propertyMap;
1483   propertyMap.Insert( Visual::Property::TYPE, Visual::PRIMITIVE );
1484   propertyMap.Insert( PrimitiveVisual::Property::SHAPE, PrimitiveVisual::Shape::CONE );
1485   propertyMap.Insert( PrimitiveVisual::Property::COLOR, Vector4( 0.5, 0.5, 0.5, 1.0 ) );
1486   propertyMap.Insert( PrimitiveVisual::Property::SLICES, 10 );
1487   propertyMap.Insert( PrimitiveVisual::Property::SCALE_TOP_RADIUS, 30.0f );
1488   propertyMap.Insert( PrimitiveVisual::Property::SCALE_HEIGHT, 50.0f );
1489
1490   //Test to see if shape loads correctly.
1491   TestPrimitiveVisualWithProperties( propertyMap, application );
1492
1493   END_TEST;
1494 }
1495
1496 //Test if primitive shape loads correctly when light position is manually set.
1497 int UtcDaliVisualFactoryGetPrimitiveVisual8(void)
1498 {
1499   //Set up test application first, so everything else can be handled.
1500   ToolkitTestApplication application;
1501
1502   tet_infoline( "UtcDaliVisualFactoryGetPrimitiveVisual8:  Request primitive visual with set light position" );
1503
1504   //Set up visual properties.
1505   Property::Map propertyMap;
1506   propertyMap.Insert( Visual::Property::TYPE, Visual::PRIMITIVE );
1507   propertyMap.Insert( PrimitiveVisual::Property::SHAPE, PrimitiveVisual::Shape::SPHERE );
1508   propertyMap.Insert( PrimitiveVisual::Property::COLOR, Vector4( 0.5, 0.5, 0.5, 1.0 ) );
1509   propertyMap.Insert( MeshVisual::Property::LIGHT_POSITION, Vector3( 0.0, 1.0, 2.0 ) );
1510
1511   //Test to see if shape loads correctly.
1512   TestPrimitiveVisualWithProperties( propertyMap, application );
1513
1514   END_TEST;
1515 }
1516
1517 //Test if primitive shape renderer handles the case of not being passed a specific shape to use.
1518 int UtcDaliVisualFactoryGetPrimitiveVisualN1(void)
1519 {
1520   //Set up test application first, so everything else can be handled.
1521   ToolkitTestApplication application;
1522
1523   tet_infoline( "UtcDaliVisualFactoryGetPrimitiveVisualN1:  Request primitive visual without shape" );
1524
1525   //Set up visual properties, without supplying shape.
1526   Property::Map propertyMap;
1527   propertyMap.Insert( Visual::Property::TYPE, Visual::PRIMITIVE );
1528
1529   //Test to see if shape loads regardless of missing input.
1530   TestPrimitiveVisualWithProperties( propertyMap, application );
1531
1532   END_TEST;
1533 }
1534
1535 int UtcDaliVisualFactoryGetBatchImageVisual1(void)
1536 {
1537   ToolkitTestApplication application;
1538   tet_infoline( "UtcDaliVisualFactoryGetBatchImageVisual1: Request a Batch Image visual with a Property::Map" );
1539
1540   VisualFactory factory = VisualFactory::Get();
1541   DALI_TEST_CHECK( factory );
1542
1543   Property::Map propertyMap;
1544   propertyMap.Insert( Visual::Property::TYPE, Visual::IMAGE );
1545   propertyMap.Insert( ImageVisual::Property::BATCHING_ENABLED, true );
1546   propertyMap.Insert( ImageVisual::Property::URL, TEST_IMAGE_FILE_NAME );
1547
1548   Visual::Base visual = factory.CreateVisual( propertyMap );
1549   DALI_TEST_CHECK( visual );
1550
1551   Actor actor = Actor::New();
1552
1553   actor.SetSize( 200.0f, 200.0f );
1554   Stage::GetCurrent().Add( actor );
1555   visual.SetSize( Vector2( 200.0f, 200.0f ) );
1556
1557   // Test SetOnStage().
1558   visual.SetOnStage( actor );
1559   DALI_TEST_CHECK( actor.GetRendererCount() == 1u );
1560
1561   application.SendNotification();
1562   application.Render();
1563
1564   // Test SetOffStage().
1565   visual.SetOffStage( actor );
1566   DALI_TEST_CHECK( actor.GetRendererCount() == 0u );
1567
1568   END_TEST;
1569 }
1570
1571 int UtcDaliVisualFactoryGetBatchImageVisual2(void)
1572 {
1573   ToolkitTestApplication application;
1574   tet_infoline( "UtcDaliVisualFactoryGetBatchImageVisual2: Request Batch Image visual from an Image Visual with batchingEnabled set" );
1575
1576   VisualFactory factory = VisualFactory::Get();
1577   DALI_TEST_CHECK( factory );
1578
1579   Property::Map propertyMap;
1580   // Create a normal Image Visual.
1581   propertyMap.Insert( Visual::Property::TYPE, Visual::IMAGE );
1582   // Instruct the factory to change Image Visuals to Batch-Image Visuals.
1583   propertyMap.Insert( ImageVisual::Property::BATCHING_ENABLED, true );
1584
1585   // Properties for the Batch-Image Visual.
1586   propertyMap.Insert( ImageVisual::Property::URL, TEST_IMAGE_FILE_NAME );
1587
1588   Visual::Base visual = factory.CreateVisual( propertyMap );
1589   DALI_TEST_CHECK( visual );
1590
1591   // Check that a Batch-Image visual was created instead of an Image visual.
1592   Property::Map resultMap;
1593   visual.CreatePropertyMap( resultMap );
1594
1595   Property::Value* value = resultMap.Find( Visual::Property::TYPE, Property::INTEGER );
1596   DALI_TEST_CHECK( value );
1597   DALI_TEST_EQUALS( value->Get<int>(), (int)Visual::IMAGE, TEST_LOCATION );
1598
1599   Actor actor = Actor::New();
1600
1601   actor.SetSize( 200.0f, 200.0f );
1602   Stage::GetCurrent().Add( actor );
1603   visual.SetSize( Vector2( 200.0f, 200.0f ) );
1604
1605   // Test SetOnStage().
1606   visual.SetOnStage( actor );
1607   DALI_TEST_CHECK( actor.GetRendererCount() == 1u );
1608
1609   application.SendNotification();
1610   application.Render();
1611
1612   // Test SetOffStage().
1613   visual.SetOffStage( actor );
1614   DALI_TEST_CHECK( actor.GetRendererCount() == 0u );
1615
1616   END_TEST;
1617 }
1618
1619 int UtcDaliVisualFactoryGetBatchImageVisual3(void)
1620 {
1621   ToolkitTestApplication application;
1622   tet_infoline( "UtcDaliVisualFactoryGetBatchImageVisual3: Create an ImageView that uses a batched visual internally" );
1623
1624   VisualFactory factory = VisualFactory::Get();
1625   DALI_TEST_CHECK( factory );
1626
1627   // Create a property-map that enables batching.
1628   Property::Map propertyMap;
1629   propertyMap.Insert( Dali::Toolkit::ImageVisual::Property::URL, TEST_IMAGE_FILE_NAME );
1630   propertyMap.Insert( ImageVisual::Property::BATCHING_ENABLED, true );
1631
1632   // Create an ImageView, passing the property-map in to instruct it to use batching.
1633   Toolkit::ImageView imageView = Toolkit::ImageView::New();
1634   imageView.SetProperty( Toolkit::ImageView::Property::IMAGE, propertyMap );
1635
1636   imageView.SetSize( 200.0f, 200.0f );
1637   Stage::GetCurrent().Add( imageView );
1638
1639   END_TEST;
1640 }