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