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