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