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