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