15058d9f0dc61ed7b444fd8624d5a18421eba5da
[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   // renderer is not added to actor until the rasterization is completed.
957   DALI_TEST_CHECK( actor.GetRendererCount() == 0u );
958
959   EventThreadCallback* eventTrigger = EventThreadCallback::Get();
960   CallbackBase* callback = eventTrigger->GetCallback();
961
962   eventTrigger->WaitingForTrigger( 1 );// waiting until the svg image is rasterized.
963   CallbackBase::Execute( *callback );
964
965   // renderer is added to actor
966   DALI_TEST_CHECK( actor.GetRendererCount() == 1u );
967
968   // waiting for the resource uploading
969   application.SendNotification();
970   application.Render();
971
972   DALI_TEST_EQUALS( textureTrace.FindMethod("BindTexture"), true, TEST_LOCATION );
973
974   END_TEST;
975 }
976
977 //Creates a mesh renderer from the given propertyMap and tries to load it on stage in the given application.
978 //This is expected to succeed, which will then pass the test.
979 void MeshVisualLoadsCorrectlyTest( Property::Map& propertyMap, ToolkitTestApplication& application )
980 {
981   VisualFactory factory = VisualFactory::Get();
982   DALI_TEST_CHECK( factory );
983
984   //Create a mesh visual.
985   Visual::Base visual = factory.CreateVisual( propertyMap );
986   DALI_TEST_CHECK( visual );
987
988   //Create an actor on stage to house the visual.
989   Actor actor = Actor::New();
990   actor.SetSize( 200.f, 200.f );
991   Stage::GetCurrent().Add( actor );
992   visual.SetSize( Vector2( 200.f, 200.f ) );
993   visual.SetOnStage( actor );
994
995   //Ensure set on stage.
996   DALI_TEST_EQUALS( actor.GetRendererCount(), 1u, TEST_LOCATION );
997
998   //Attempt to render to queue resource load requests.
999   application.SendNotification();
1000   application.Render( 0 );
1001
1002   //Tell the platform abstraction that the required resources have been loaded.
1003   TestPlatformAbstraction& platform = application.GetPlatform();
1004   platform.SetAllResourceRequestsAsLoaded();
1005
1006   //Render again to upload the now-loaded textures.
1007   application.SendNotification();
1008   application.Render( 0 );
1009
1010   Matrix testScaleMatrix;
1011   testScaleMatrix.SetIdentityAndScale( Vector3( 1.0, -1.0, 1.0 ) );
1012   Matrix actualScaleMatrix;
1013
1014   //Test to see if the object has been successfully loaded.
1015   DALI_TEST_CHECK( application.GetGlAbstraction().GetUniformValue<Matrix>( "uObjectMatrix", actualScaleMatrix ) );
1016   DALI_TEST_EQUALS( actualScaleMatrix, testScaleMatrix, Math::MACHINE_EPSILON_100, TEST_LOCATION );
1017
1018   //Finish by setting off stage, and ensuring this was successful.
1019   visual.SetOffStage( actor );
1020   DALI_TEST_EQUALS( actor.GetRendererCount(), 0u, TEST_LOCATION );
1021 }
1022
1023 //Creates a mesh visual from the given propertyMap and tries to load it on stage in the given application.
1024 //This is expected to fail, which will then pass the test.
1025 void MeshVisualDoesNotLoadCorrectlyTest( Property::Map& propertyMap, ToolkitTestApplication& application )
1026 {
1027   VisualFactory factory = VisualFactory::Get();
1028   DALI_TEST_CHECK( factory );
1029
1030   //Create a mesh visual.
1031   Visual::Base visual = factory.CreateVisual( propertyMap );
1032   DALI_TEST_CHECK( visual );
1033
1034   //Create an actor on stage to house the visual.
1035   Actor actor = Actor::New();
1036   actor.SetSize( 200.f, 200.f );
1037   Stage::GetCurrent().Add( actor );
1038   visual.SetSize( Vector2( 200.f, 200.f ) );
1039   visual.SetOnStage( actor );
1040
1041   //Ensure set on stage.
1042   DALI_TEST_EQUALS( actor.GetRendererCount(), 1u, TEST_LOCATION );
1043
1044   //Attempt to render to queue resource load requests.
1045   application.SendNotification();
1046   application.Render( 0 );
1047
1048   //Tell the platform abstraction that the required resources have been loaded.
1049   TestPlatformAbstraction& platform = application.GetPlatform();
1050   platform.SetAllResourceRequestsAsLoaded();
1051
1052   //Render again to upload the now-loaded textures.
1053   application.SendNotification();
1054   application.Render( 0 );
1055
1056   //Test to see if the object has not been loaded, as expected.
1057   Matrix scaleMatrix;
1058   DALI_TEST_CHECK( !application.GetGlAbstraction().GetUniformValue<Matrix>( "uObjectMatrix", scaleMatrix ) );
1059
1060   //Finish by setting off stage, and ensuring this was successful.
1061   visual.SetOffStage( actor );
1062   DALI_TEST_EQUALS( actor.GetRendererCount(), 0u, TEST_LOCATION );
1063 }
1064
1065 //Test if mesh loads correctly when supplied with only the bare minimum requirements, an object file.
1066 int UtcDaliVisualFactoryGetMeshVisual1(void)
1067 {
1068   //Set up test application first, so everything else can be handled.
1069   ToolkitTestApplication application;
1070
1071   tet_infoline( "UtcDaliVisualFactoryGetMeshVisual1:  Request mesh visual with a valid object file only" );
1072
1073
1074   //Set up visual properties.
1075   Property::Map propertyMap;
1076   propertyMap.Insert( Visual::Property::TYPE,  Visual::MESH );
1077   propertyMap.Insert( MeshVisual::Property::OBJECT_URL, TEST_OBJ_FILE_NAME );
1078
1079   //Test to see if mesh loads correctly.
1080   MeshVisualLoadsCorrectlyTest( propertyMap, application );
1081
1082   END_TEST;
1083 }
1084
1085
1086 //Test if mesh loads correctly when supplied with an object file as well as a blank material file and images directory.
1087 int UtcDaliVisualFactoryGetMeshVisual2(void)
1088 {
1089   //Set up test application first, so everything else can be handled.
1090   ToolkitTestApplication application;
1091
1092   tet_infoline( "UtcDaliVisualFactoryGetMeshVisual2:  Request mesh visual with blank material file and images directory" );
1093
1094   //Set up visual properties.
1095   Property::Map propertyMap;
1096   propertyMap.Insert( Visual::Property::TYPE, Visual::MESH );
1097   propertyMap.Insert( MeshVisual::Property::OBJECT_URL, TEST_OBJ_FILE_NAME );
1098   propertyMap.Insert( MeshVisual::Property::MATERIAL_URL, "" );
1099   propertyMap.Insert( MeshVisual::Property::TEXTURES_PATH, "" );
1100
1101   //Test to see if mesh loads correctly.
1102   MeshVisualLoadsCorrectlyTest( propertyMap, application );
1103
1104   END_TEST;
1105 }
1106
1107 //Test if mesh loads correctly when supplied with all main parameters, an object file, a material file and a directory location.
1108 int UtcDaliVisualFactoryGetMeshVisual3(void)
1109 {
1110   //Set up test application first, so everything else can be handled.
1111   ToolkitTestApplication application;
1112
1113   tet_infoline( "UtcDaliVisualFactoryGetMeshVisual3:  Request mesh visual with all parameters correct" );
1114
1115   //Set up visual properties.
1116   Property::Map propertyMap;
1117   propertyMap.Insert( Visual::Property::TYPE, Visual::MESH );
1118   propertyMap.Insert( MeshVisual::Property::OBJECT_URL, TEST_OBJ_FILE_NAME );
1119   propertyMap.Insert( MeshVisual::Property::MATERIAL_URL, TEST_MTL_FILE_NAME );
1120   propertyMap.Insert( MeshVisual::Property::TEXTURES_PATH, TEST_RESOURCE_DIR "/" );
1121
1122   //Test to see if mesh loads correctly.
1123   MeshVisualLoadsCorrectlyTest( propertyMap, application );
1124
1125   END_TEST;
1126 }
1127
1128 //Test if mesh visual can load a correctly supplied mesh without a normal map or gloss map in the material file.
1129 int UtcDaliVisualFactoryGetMeshVisual4(void)
1130 {
1131   //Set up test application first, so everything else can be handled.
1132   ToolkitTestApplication application;
1133
1134   tet_infoline( "UtcDaliVisualFactoryGetMeshVisual4:  Request mesh visual with diffuse texture but not normal or gloss." );
1135
1136
1137   //Set up visual properties.
1138   Property::Map propertyMap;
1139   propertyMap.Insert( Visual::Property::TYPE, Visual::MESH );
1140   propertyMap.Insert( MeshVisual::Property::OBJECT_URL, TEST_OBJ_FILE_NAME );
1141   propertyMap.Insert( MeshVisual::Property::MATERIAL_URL, TEST_SIMPLE_MTL_FILE_NAME );
1142   propertyMap.Insert( MeshVisual::Property::TEXTURES_PATH, TEST_RESOURCE_DIR "/" );
1143
1144   //Test to see if mesh loads correctly.
1145   MeshVisualLoadsCorrectlyTest( propertyMap, application );
1146
1147
1148   END_TEST;
1149 }
1150
1151 //Test if mesh visual can load when made to use diffuse textures only.
1152 int UtcDaliVisualFactoryGetMeshVisual5(void)
1153 {
1154   //Set up test application first, so everything else can be handled.
1155   ToolkitTestApplication application;
1156
1157   tet_infoline( "UtcDaliVisualFactoryGetMeshVisual5:  Request mesh visual and make it only use diffuse textures." );
1158
1159   //Set up visual properties.
1160   Property::Map propertyMap;
1161   propertyMap.Insert( Visual::Property::TYPE, Visual::MESH );
1162   propertyMap.Insert( MeshVisual::Property::OBJECT_URL, TEST_OBJ_FILE_NAME );
1163   propertyMap.Insert( MeshVisual::Property::MATERIAL_URL, TEST_MTL_FILE_NAME );
1164   propertyMap.Insert( MeshVisual::Property::TEXTURES_PATH, TEST_RESOURCE_DIR "/" );
1165   propertyMap.Insert( MeshVisual::Property::SHADING_MODE, MeshVisual::ShadingMode::TEXTURED_WITH_SPECULAR_LIGHTING );
1166
1167   //Test to see if mesh loads correctly.
1168   MeshVisualLoadsCorrectlyTest( propertyMap, application );
1169
1170
1171   END_TEST;
1172 }
1173
1174 //Test if mesh visual can load when made to not use the supplied textures.
1175 int UtcDaliVisualFactoryGetMeshVisual6(void)
1176 {
1177   //Set up test application first, so everything else can be handled.
1178   ToolkitTestApplication application;
1179
1180   tet_infoline( "UtcDaliVisualFactoryGetMeshVisual6:  Request mesh visual and make it not use any textures." );
1181
1182   //Set up visual properties.
1183   Property::Map propertyMap;
1184   propertyMap.Insert( Visual::Property::TYPE, Visual::MESH );
1185   propertyMap.Insert( MeshVisual::Property::OBJECT_URL, TEST_OBJ_FILE_NAME );
1186   propertyMap.Insert( MeshVisual::Property::MATERIAL_URL, TEST_MTL_FILE_NAME );
1187   propertyMap.Insert( MeshVisual::Property::TEXTURES_PATH, TEST_RESOURCE_DIR "/" );
1188   propertyMap.Insert( MeshVisual::Property::SHADING_MODE, MeshVisual::ShadingMode::TEXTURELESS_WITH_DIFFUSE_LIGHTING );
1189
1190   //Test to see if mesh loads correctly.
1191   MeshVisualLoadsCorrectlyTest( propertyMap, application );
1192
1193   END_TEST;
1194 }
1195 //Test if mesh visual loads correctly when light position is manually set.
1196 int UtcDaliVisualFactoryGetMeshVisual7(void)
1197 {
1198   //Set up test application first, so everything else can be handled.
1199   ToolkitTestApplication application;
1200
1201
1202   tet_infoline( "UtcDaliVisualFactoryGetMeshVisual7:  Request mesh visual with custom light position." );
1203
1204   //Set up visual properties.
1205   Property::Map propertyMap;
1206   propertyMap.Insert( Visual::Property::TYPE, Visual::MESH );
1207   propertyMap.Insert( MeshVisual::Property::OBJECT_URL, TEST_OBJ_FILE_NAME );
1208   propertyMap.Insert( MeshVisual::Property::MATERIAL_URL, TEST_MTL_FILE_NAME );
1209   propertyMap.Insert( MeshVisual::Property::TEXTURES_PATH, TEST_RESOURCE_DIR "/" );
1210   propertyMap.Insert( MeshVisual::Property::LIGHT_POSITION, Vector3( 0.0, 1.0, 2.0 ) );
1211
1212   //Test to see if mesh loads correctly.
1213   MeshVisualLoadsCorrectlyTest( propertyMap, application );
1214
1215   END_TEST;
1216 }
1217
1218 //Test if mesh visual loads correctly when supplied an object file without face normals or texture points.
1219 //Note that this notably tests object loader functionality.
1220 int UtcDaliVisualFactoryGetMeshVisual8(void)
1221 {
1222   //Set up test application first, so everything else can be handled.
1223   ToolkitTestApplication application;
1224
1225   tet_infoline( "UtcDaliVisualFactoryGetMeshVisual5:  Request mesh visual with normal-less object file." );
1226
1227   //Set up visual properties.
1228   Property::Map propertyMap;
1229   propertyMap.Insert( Visual::Property::TYPE, Visual::MESH );
1230   propertyMap.Insert( MeshVisual::Property::OBJECT_URL, TEST_SIMPLE_OBJ_FILE_NAME );
1231   propertyMap.Insert( MeshVisual::Property::MATERIAL_URL, TEST_MTL_FILE_NAME );
1232   propertyMap.Insert( MeshVisual::Property::TEXTURES_PATH, TEST_RESOURCE_DIR "/" );
1233
1234   //Test to see if mesh loads correctly.
1235   MeshVisualLoadsCorrectlyTest( propertyMap, application );
1236
1237   END_TEST;
1238 }
1239
1240 //Test if mesh visual handles the case of lacking an object file.
1241 int UtcDaliVisualFactoryGetMeshVisualN1(void)
1242 {
1243   //Set up test application first, so everything else can be handled.
1244   ToolkitTestApplication application;
1245
1246   tet_infoline( "UtcDaliVisualFactoryGetMeshVisualN1:  Request mesh visual without object file" );
1247
1248   //Set up visual properties.
1249   Property::Map propertyMap;
1250   propertyMap.Insert( Visual::Property::TYPE, Visual::MESH );
1251   propertyMap.Insert( MeshVisual::Property::MATERIAL_URL, TEST_MTL_FILE_NAME );
1252   propertyMap.Insert( MeshVisual::Property::TEXTURES_PATH, TEST_RESOURCE_DIR "/" );
1253
1254   //Test to see if mesh doesn't load with these properties, as expected.
1255   MeshVisualDoesNotLoadCorrectlyTest( propertyMap, application );
1256
1257
1258   END_TEST;
1259 }
1260
1261 //Test if mesh visual handles the case of being passed invalid material and images urls.
1262 int UtcDaliVisualFactoryGetMeshVisualN2(void)
1263 {
1264   //Set up test application first, so everything else can be handled.
1265   ToolkitTestApplication application;
1266
1267   tet_infoline( "UtcDaliVisualFactoryGetMeshVisualN2:  Request mesh visual with invalid material and images urls" );
1268
1269   //Set up visual properties.
1270   Property::Map propertyMap;
1271   propertyMap.Insert( Visual::Property::TYPE, Visual::MESH );
1272   propertyMap.Insert( MeshVisual::Property::OBJECT_URL, TEST_OBJ_FILE_NAME );
1273   propertyMap.Insert( MeshVisual::Property::MATERIAL_URL, "invalid" );
1274   propertyMap.Insert( MeshVisual::Property::TEXTURES_PATH, "also invalid" );
1275
1276   //Test to see if mesh doesn't load with these properties, as expected.
1277   MeshVisualDoesNotLoadCorrectlyTest( propertyMap, application );
1278
1279
1280   END_TEST;
1281 }
1282
1283 //Test if mesh visual handles the case of being passed an invalid object url
1284 int UtcDaliVisualFactoryGetMeshVisualN3(void)
1285 {
1286   //Set up test application first, so everything else can be handled.
1287   ToolkitTestApplication application;
1288   tet_infoline( "UtcDaliVisualFactoryGetMeshVisualN3:  Request mesh visual with invalid object url" );
1289
1290
1291   //Set up visual properties.
1292   Property::Map propertyMap;
1293   propertyMap.Insert( Visual::Property::TYPE, Visual::MESH );
1294   propertyMap.Insert( MeshVisual::Property::OBJECT_URL, "invalid" );
1295   propertyMap.Insert( MeshVisual::Property::MATERIAL_URL, TEST_MTL_FILE_NAME );
1296   propertyMap.Insert( MeshVisual::Property::TEXTURES_PATH, TEST_RESOURCE_DIR "/" );
1297
1298   //Test to see if mesh doesn't load with these properties, as expected.
1299   MeshVisualDoesNotLoadCorrectlyTest( propertyMap, application );
1300
1301   END_TEST;
1302 }
1303
1304 //Creates a primitive visual with the given property map and tests to see if it correctly loads in the given application.
1305 void TestPrimitiveVisualWithProperties( Property::Map& propertyMap, ToolkitTestApplication& application )
1306 {
1307   VisualFactory factory = VisualFactory::Get();
1308   DALI_TEST_CHECK( factory );
1309
1310   //Create a primitive visual.
1311   Visual::Base visual = factory.CreateVisual( propertyMap );
1312   DALI_TEST_CHECK( visual );
1313
1314   //Create an actor on stage to house the visual.
1315   Actor actor = Actor::New();
1316   actor.SetSize( 200.f, 200.f );
1317   Stage::GetCurrent().Add( actor );
1318   visual.SetSize( Vector2( 200.f, 200.f ) );
1319   visual.SetOnStage( actor );
1320
1321   //Ensure set on stage.
1322   DALI_TEST_EQUALS( actor.GetRendererCount(), 1u, TEST_LOCATION );
1323
1324   //Tell test application to load the visual.
1325   application.SendNotification();
1326   application.Render(0);
1327
1328   Matrix testScaleMatrix;
1329   testScaleMatrix.SetIdentityAndScale( Vector3( 1.0, -1.0, 1.0 ) );
1330   Matrix actualScaleMatrix;
1331
1332   //Test to see if the object has been successfully loaded.
1333   DALI_TEST_CHECK( application.GetGlAbstraction().GetUniformValue<Matrix>( "uObjectMatrix", actualScaleMatrix ) );
1334   DALI_TEST_EQUALS( actualScaleMatrix, testScaleMatrix, Math::MACHINE_EPSILON_100, TEST_LOCATION );
1335
1336   //Finish by setting off stage, and ensuring this was successful.
1337   visual.SetOffStage( actor );
1338   DALI_TEST_EQUALS( actor.GetRendererCount(), 0u, TEST_LOCATION );
1339 }
1340
1341 //Test if primitive shape loads correctly when supplied with only the bare minimum requirements, the shape to use.
1342 int UtcDaliVisualFactoryGetPrimitiveVisual1(void)
1343 {
1344   //Set up test application first, so everything else can be handled.
1345   ToolkitTestApplication application;
1346
1347   tet_infoline( "UtcDaliVisualFactoryGetPrimitiveVisual1:  Request primitive visual with a shape only" );
1348
1349   //Set up visual properties.
1350   Property::Map propertyMap;
1351   propertyMap.Insert( Visual::Property::TYPE, Visual::PRIMITIVE );
1352   propertyMap.Insert( PrimitiveVisual::Property::SHAPE, PrimitiveVisual::Shape::CUBE );
1353
1354   //Test to see if shape loads correctly.
1355   TestPrimitiveVisualWithProperties( propertyMap, application );
1356
1357   END_TEST;
1358 }
1359
1360 //Test if primitive shape loads correctly when supplied with all possible parameters
1361 int UtcDaliVisualFactoryGetPrimitiveVisual2(void)
1362 {
1363   //Set up test application first, so everything else can be handled.
1364   ToolkitTestApplication application;
1365
1366   tet_infoline( "UtcDaliVisualFactoryGetPrimitiveVisual2:  Request primitive visual with everything" );
1367
1368   //Set up visual properties.
1369   Property::Map propertyMap;
1370   propertyMap.Insert( Visual::Property::TYPE, Visual::PRIMITIVE );
1371   propertyMap.Insert( PrimitiveVisual::Property::SHAPE, PrimitiveVisual::Shape::CUBE );
1372   propertyMap.Insert( PrimitiveVisual::Property::MIX_COLOR, Vector4( 0.5, 0.5, 0.5, 1.0 ) );
1373   propertyMap.Insert( PrimitiveVisual::Property::SLICES, 10 );
1374   propertyMap.Insert( PrimitiveVisual::Property::STACKS, 20 );
1375   propertyMap.Insert( PrimitiveVisual::Property::SCALE_TOP_RADIUS, 30.0f );
1376   propertyMap.Insert( PrimitiveVisual::Property::SCALE_BOTTOM_RADIUS, 40.0f );
1377   propertyMap.Insert( PrimitiveVisual::Property::SCALE_HEIGHT, 50.0f );
1378   propertyMap.Insert( PrimitiveVisual::Property::SCALE_RADIUS, 60.0f );
1379   propertyMap.Insert( PrimitiveVisual::Property::BEVEL_PERCENTAGE, 0.7f );
1380   propertyMap.Insert( PrimitiveVisual::Property::BEVEL_SMOOTHNESS, 0.8f );
1381   propertyMap.Insert( MeshVisual::Property::LIGHT_POSITION, Vector3( 0.9, 1.0, 1.1 ) );
1382
1383   //Test to see if shape loads correctly.
1384   TestPrimitiveVisualWithProperties( propertyMap, application );
1385
1386   END_TEST;
1387 }
1388
1389 //Test if primitive shape loads a sphere correctly.
1390 int UtcDaliVisualFactoryGetPrimitiveVisual3(void)
1391 {
1392   //Set up test application first, so everything else can be handled.
1393   ToolkitTestApplication application;
1394
1395   tet_infoline( "UtcDaliVisualFactoryGetPrimitiveVisual3:  Request primitive visual to display a sphere" );
1396
1397   //Set up visual properties.
1398   Property::Map propertyMap;
1399   propertyMap.Insert( Visual::Property::TYPE, Visual::PRIMITIVE );
1400   propertyMap.Insert( PrimitiveVisual::Property::SHAPE, PrimitiveVisual::Shape::SPHERE );
1401   propertyMap.Insert( PrimitiveVisual::Property::MIX_COLOR, Vector4( 0.5, 0.5, 0.5, 1.0 ) );
1402   propertyMap.Insert( PrimitiveVisual::Property::SLICES, 10 );
1403   propertyMap.Insert( PrimitiveVisual::Property::STACKS, 20 );
1404
1405   //Test to see if shape loads correctly.
1406   TestPrimitiveVisualWithProperties( propertyMap, application );
1407
1408   END_TEST;
1409 }
1410
1411 //Test if primitive shape loads a conic section correctly.
1412 int UtcDaliVisualFactoryGetPrimitiveVisual4(void)
1413 {
1414   //Set up test application first, so everything else can be handled.
1415   ToolkitTestApplication application;
1416
1417   tet_infoline( "UtcDaliVisualFactoryGetPrimitiveVisual4:  Request primitive visual to display a conic section" );
1418
1419   //Set up visual properties.
1420   Property::Map propertyMap;
1421   propertyMap.Insert( Visual::Property::TYPE, Visual::PRIMITIVE );
1422   propertyMap.Insert( PrimitiveVisual::Property::SHAPE, PrimitiveVisual::Shape::CONICAL_FRUSTRUM );
1423   propertyMap.Insert( PrimitiveVisual::Property::MIX_COLOR, Vector4( 0.5, 0.5, 0.5, 1.0 ) );
1424   propertyMap.Insert( PrimitiveVisual::Property::SLICES, 10 );
1425   propertyMap.Insert( PrimitiveVisual::Property::SCALE_TOP_RADIUS, 30.0f );
1426   propertyMap.Insert( PrimitiveVisual::Property::SCALE_BOTTOM_RADIUS, 40.0f );
1427   propertyMap.Insert( PrimitiveVisual::Property::SCALE_HEIGHT, 50.0f );
1428
1429   //Test to see if shape loads correctly.
1430   TestPrimitiveVisualWithProperties( propertyMap, application );
1431
1432   END_TEST;
1433 }
1434
1435 //Test if primitive shape loads a bevelled cube correctly.
1436 int UtcDaliVisualFactoryGetPrimitiveVisual5(void)
1437 {
1438   //Set up test application first, so everything else can be handled.
1439   ToolkitTestApplication application;
1440
1441   tet_infoline( "UtcDaliVisualFactoryGetPrimitiveVisual5:  Request primitive visual to display a bevelled cube" );
1442
1443   //Set up visual properties.
1444   Property::Map propertyMap;
1445   propertyMap.Insert( Visual::Property::TYPE, Visual::PRIMITIVE );
1446   propertyMap.Insert( PrimitiveVisual::Property::SHAPE, PrimitiveVisual::Shape::BEVELLED_CUBE );
1447   propertyMap.Insert( PrimitiveVisual::Property::MIX_COLOR, Vector4( 0.5, 0.5, 0.5, 1.0 ) );
1448   propertyMap.Insert( PrimitiveVisual::Property::BEVEL_PERCENTAGE, 0.7f );
1449
1450   //Test to see if shape loads correctly.
1451   TestPrimitiveVisualWithProperties( propertyMap, application );
1452
1453   END_TEST;
1454 }
1455
1456 //Test if primitive shape loads an octahedron correctly.
1457 int UtcDaliVisualFactoryGetPrimitiveVisual6(void)
1458 {
1459   //Set up test application first, so everything else can be handled.
1460   ToolkitTestApplication application;
1461
1462   tet_infoline( "UtcDaliVisualFactoryGetPrimitiveVisual6:  Request primitive visual to display an octahedron" );
1463
1464   //Set up visual properties.
1465   Property::Map propertyMap;
1466   propertyMap.Insert( Visual::Property::TYPE, Visual::PRIMITIVE );
1467   propertyMap.Insert( PrimitiveVisual::Property::SHAPE, PrimitiveVisual::Shape::OCTAHEDRON );
1468   propertyMap.Insert( PrimitiveVisual::Property::MIX_COLOR, Vector4( 0.5, 0.5, 0.5, 1.0 ) );
1469
1470   //Test to see if shape loads correctly.
1471   TestPrimitiveVisualWithProperties( propertyMap, application );
1472
1473   END_TEST;
1474 }
1475
1476 //Test if primitive shape loads a cone correctly.
1477 int UtcDaliVisualFactoryGetPrimitiveVisual7(void)
1478 {
1479   //Set up test application first, so everything else can be handled.
1480   ToolkitTestApplication application;
1481
1482   tet_infoline( "UtcDaliVisualFactoryGetPrimitiveVisual7:  Request primitive visual to display a cone" );
1483
1484   //Set up visual properties.
1485   Property::Map propertyMap;
1486   propertyMap.Insert( Visual::Property::TYPE, Visual::PRIMITIVE );
1487   propertyMap.Insert( PrimitiveVisual::Property::SHAPE, PrimitiveVisual::Shape::CONE );
1488   propertyMap.Insert( PrimitiveVisual::Property::MIX_COLOR, Vector4( 0.5, 0.5, 0.5, 1.0 ) );
1489   propertyMap.Insert( PrimitiveVisual::Property::SLICES, 10 );
1490   propertyMap.Insert( PrimitiveVisual::Property::SCALE_TOP_RADIUS, 30.0f );
1491   propertyMap.Insert( PrimitiveVisual::Property::SCALE_HEIGHT, 50.0f );
1492
1493   //Test to see if shape loads correctly.
1494   TestPrimitiveVisualWithProperties( propertyMap, application );
1495
1496   END_TEST;
1497 }
1498
1499 //Test if primitive shape loads correctly when light position is manually set.
1500 int UtcDaliVisualFactoryGetPrimitiveVisual8(void)
1501 {
1502   //Set up test application first, so everything else can be handled.
1503   ToolkitTestApplication application;
1504
1505   tet_infoline( "UtcDaliVisualFactoryGetPrimitiveVisual8:  Request primitive visual with set light position" );
1506
1507   //Set up visual properties.
1508   Property::Map propertyMap;
1509   propertyMap.Insert( Visual::Property::TYPE, Visual::PRIMITIVE );
1510   propertyMap.Insert( PrimitiveVisual::Property::SHAPE, PrimitiveVisual::Shape::SPHERE );
1511   propertyMap.Insert( PrimitiveVisual::Property::MIX_COLOR, Vector4( 0.5, 0.5, 0.5, 1.0 ) );
1512   propertyMap.Insert( MeshVisual::Property::LIGHT_POSITION, Vector3( 0.0, 1.0, 2.0 ) );
1513
1514   //Test to see if shape loads correctly.
1515   TestPrimitiveVisualWithProperties( propertyMap, application );
1516
1517   END_TEST;
1518 }
1519
1520 //Test if primitive shape loads correctly when told to use too many slices.
1521 int UtcDaliVisualFactoryGetPrimitiveVisual9(void)
1522 {
1523   //Set up test application first, so everything else can be handled.
1524   ToolkitTestApplication application;
1525
1526   tet_infoline( "UtcDaliVisualFactoryGetPrimitiveVisual9:  Request primitive visual with above-cap slices." );
1527
1528   //Set up visual properties.
1529   Property::Map propertyMap;
1530   propertyMap.Insert( Visual::Property::TYPE, Visual::PRIMITIVE );
1531   propertyMap.Insert( PrimitiveVisual::Property::SHAPE, PrimitiveVisual::Shape::SPHERE );
1532   propertyMap.Insert( PrimitiveVisual::Property::SLICES, Property::Value( 1000000 ) );
1533
1534   //Test to see if shape loads correctly.
1535   TestPrimitiveVisualWithProperties( propertyMap, application );
1536
1537   END_TEST;
1538 }
1539
1540 //Test if primitive shape loads correctly when told to use too few slices. (2 slices or less.)
1541 int UtcDaliVisualFactoryGetPrimitiveVisual10(void)
1542 {
1543   //Set up test application first, so everything else can be handled.
1544   ToolkitTestApplication application;
1545
1546   tet_infoline( "UtcDaliVisualFactoryGetPrimitiveVisual10:  Request primitive visual with too few slices." );
1547
1548   //Set up visual properties.
1549   Property::Map propertyMap;
1550   propertyMap.Insert( Visual::Property::TYPE, Visual::PRIMITIVE );
1551   propertyMap.Insert( PrimitiveVisual::Property::SHAPE, PrimitiveVisual::Shape::SPHERE );
1552   propertyMap.Insert( PrimitiveVisual::Property::SLICES, Property::Value( 2 ) );
1553
1554   //Test to see if shape loads correctly.
1555   TestPrimitiveVisualWithProperties( propertyMap, application );
1556
1557   END_TEST;
1558 }
1559
1560 //Test if primitive shape loads correctly when told to use too many stacks.
1561 int UtcDaliVisualFactoryGetPrimitiveVisual11(void)
1562 {
1563   //Set up test application first, so everything else can be handled.
1564   ToolkitTestApplication application;
1565
1566   tet_infoline( "UtcDaliVisualFactoryGetPrimitiveVisual11:  Request primitive visual with too many stacks." );
1567
1568   //Set up visual properties.
1569   Property::Map propertyMap;
1570   propertyMap.Insert( Visual::Property::TYPE, Visual::PRIMITIVE );
1571   propertyMap.Insert( PrimitiveVisual::Property::SHAPE, PrimitiveVisual::Shape::SPHERE );
1572   propertyMap.Insert( PrimitiveVisual::Property::STACKS, Property::Value( 1000000 ) );
1573
1574   //Test to see if shape loads correctly.
1575   TestPrimitiveVisualWithProperties( propertyMap, application );
1576
1577   END_TEST;
1578 }
1579
1580 //Test if primitive shape loads correctly when told to use too few stacks. (1 stack or less.)
1581 int UtcDaliVisualFactoryGetPrimitiveVisual12(void)
1582 {
1583   //Set up test application first, so everything else can be handled.
1584   ToolkitTestApplication application;
1585
1586   tet_infoline( "UtcDaliVisualFactoryGetPrimitiveVisual12:  Request primitive visual with too few stacks." );
1587
1588   //Set up visual properties.
1589   Property::Map propertyMap;
1590   propertyMap.Insert( Visual::Property::TYPE, Visual::PRIMITIVE );
1591   propertyMap.Insert( PrimitiveVisual::Property::SHAPE, PrimitiveVisual::Shape::SPHERE );
1592   propertyMap.Insert( PrimitiveVisual::Property::STACKS, Property::Value( 1 ) );
1593
1594   //Test to see if shape loads correctly.
1595   TestPrimitiveVisualWithProperties( propertyMap, application );
1596
1597   END_TEST;
1598 }
1599
1600 //Test if primitive shape loads correctly when told to use invalid (zero or negative) dimensions.
1601 int UtcDaliVisualFactoryGetPrimitiveVisual13(void)
1602 {
1603   //Set up test application first, so everything else can be handled.
1604   ToolkitTestApplication application;
1605
1606   tet_infoline( "UtcDaliVisualFactoryGetPrimitiveVisual13:  Request primitive visual with invalid scale dimensions." );
1607
1608   //Set up visual properties.
1609   Property::Map propertyMap;
1610   propertyMap.Insert( Visual::Property::TYPE, Visual::PRIMITIVE );
1611   propertyMap.Insert( PrimitiveVisual::Property::SHAPE, PrimitiveVisual::Shape::SPHERE );
1612   propertyMap.Insert( PrimitiveVisual::Property::SCALE_DIMENSIONS, Vector3::ZERO );
1613
1614   //Test to see if shape loads correctly.
1615   TestPrimitiveVisualWithProperties( propertyMap, application );
1616
1617   END_TEST;
1618 }
1619
1620 //Test if primitive shape loads correctly when told to use too low a bevel percentage.
1621 int UtcDaliVisualFactoryGetPrimitiveVisual14(void)
1622 {
1623   //Set up test application first, so everything else can be handled.
1624   ToolkitTestApplication application;
1625
1626   tet_infoline( "UtcDaliVisualFactoryGetPrimitiveVisual14:  Request primitive visual with too low a bevel percentage." );
1627
1628   //Set up visual properties.
1629   Property::Map propertyMap;
1630   propertyMap.Insert( Visual::Property::TYPE, Visual::PRIMITIVE );
1631   propertyMap.Insert( PrimitiveVisual::Property::SHAPE, PrimitiveVisual::Shape::SPHERE );
1632   propertyMap.Insert( PrimitiveVisual::Property::BEVEL_PERCENTAGE, Property::Value( -1.0f ) );
1633
1634   //Test to see if shape loads correctly.
1635   TestPrimitiveVisualWithProperties( propertyMap, application );
1636
1637   END_TEST;
1638 }
1639
1640 //Test if primitive shape loads correctly when told to use too high a bevel percentage.
1641 int UtcDaliVisualFactoryGetPrimitiveVisual15(void)
1642 {
1643   //Set up test application first, so everything else can be handled.
1644   ToolkitTestApplication application;
1645
1646   tet_infoline( "UtcDaliVisualFactoryGetPrimitiveVisual15:  Request primitive visual with too high a bevel percentage." );
1647
1648   //Set up visual properties.
1649   Property::Map propertyMap;
1650   propertyMap.Insert( Visual::Property::TYPE, Visual::PRIMITIVE );
1651   propertyMap.Insert( PrimitiveVisual::Property::SHAPE, PrimitiveVisual::Shape::SPHERE );
1652   propertyMap.Insert( PrimitiveVisual::Property::BEVEL_PERCENTAGE, Property::Value( 2.0f ) );
1653
1654   //Test to see if shape loads correctly.
1655   TestPrimitiveVisualWithProperties( propertyMap, application );
1656
1657   END_TEST;
1658 }
1659
1660 //Test if primitive shape loads correctly when told to use too low a bevel smoothness.
1661 int UtcDaliVisualFactoryGetPrimitiveVisual16(void)
1662 {
1663   //Set up test application first, so everything else can be handled.
1664   ToolkitTestApplication application;
1665
1666   tet_infoline( "UtcDaliVisualFactoryGetPrimitiveVisual16:  Request primitive visual with too low a bevel smoothness." );
1667
1668   //Set up visual properties.
1669   Property::Map propertyMap;
1670   propertyMap.Insert( Visual::Property::TYPE, Visual::PRIMITIVE );
1671   propertyMap.Insert( PrimitiveVisual::Property::SHAPE, PrimitiveVisual::Shape::SPHERE );
1672   propertyMap.Insert( PrimitiveVisual::Property::BEVEL_SMOOTHNESS, Property::Value( -1.0f ) );
1673
1674   //Test to see if shape loads correctly.
1675   TestPrimitiveVisualWithProperties( propertyMap, application );
1676
1677   END_TEST;
1678 }
1679
1680 //Test if primitive shape loads correctly when told to use too high a bevel smoothness.
1681 int UtcDaliVisualFactoryGetPrimitiveVisual17(void)
1682 {
1683   //Set up test application first, so everything else can be handled.
1684   ToolkitTestApplication application;
1685
1686   tet_infoline( "UtcDaliVisualFactoryGetPrimitiveVisual17:  Request primitive visual with too high a bevel smoothness." );
1687
1688   //Set up visual properties.
1689   Property::Map propertyMap;
1690   propertyMap.Insert( Visual::Property::TYPE, Visual::PRIMITIVE );
1691   propertyMap.Insert( PrimitiveVisual::Property::SHAPE, PrimitiveVisual::Shape::SPHERE );
1692   propertyMap.Insert( PrimitiveVisual::Property::BEVEL_SMOOTHNESS, Property::Value( 2.0f ) );
1693
1694   //Test to see if shape loads correctly.
1695   TestPrimitiveVisualWithProperties( propertyMap, application );
1696
1697   END_TEST;
1698 }
1699
1700 //Test if primitive shape renderer handles the case of not being passed a specific shape to use.
1701 int UtcDaliVisualFactoryGetPrimitiveVisualN1(void)
1702 {
1703   //Set up test application first, so everything else can be handled.
1704   ToolkitTestApplication application;
1705
1706   tet_infoline( "UtcDaliVisualFactoryGetPrimitiveVisualN1:  Request primitive visual without shape" );
1707
1708   //Set up visual properties, without supplying shape.
1709   Property::Map propertyMap;
1710   propertyMap.Insert( Visual::Property::TYPE, Visual::PRIMITIVE );
1711
1712   //Test to see if shape loads regardless of missing input.
1713   TestPrimitiveVisualWithProperties( propertyMap, application );
1714
1715   END_TEST;
1716 }