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