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