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