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