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