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