New propagation rule for KeyEvent
[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   END_TEST;
699 }
700
701 int UtcDaliVisualFactoryGetNPatchVisual3(void)
702 {
703   ToolkitTestApplication application;
704   tet_infoline( "UtcDaliVisualFactoryGetNPatchVisual2: Request n-patch visual with a Property::Map" );
705
706   VisualFactory factory = VisualFactory::Get();
707   DALI_TEST_CHECK( factory );
708
709   const unsigned int ninePatchImageWidth = 18;
710   const unsigned int ninePatchImageHeight = 28;
711   StretchRanges stretchRangesX;
712   stretchRangesX.PushBack( Uint16Pair( 2, 3 ) );
713   stretchRangesX.PushBack( Uint16Pair( 5, 7 ) );
714   stretchRangesX.PushBack( Uint16Pair( 12, 15 ) );
715   StretchRanges stretchRangesY;
716   stretchRangesY.PushBack( Uint16Pair( 4, 5 ) );
717   stretchRangesY.PushBack( Uint16Pair( 8, 12 ) );
718   stretchRangesY.PushBack( Uint16Pair( 15, 16 ) );
719   stretchRangesY.PushBack( Uint16Pair( 25, 27 ) );
720   Integration::ResourcePointer ninePatchResource = CustomizeNinePatch( application, ninePatchImageWidth, ninePatchImageHeight, stretchRangesX, stretchRangesY );
721
722   Property::Map propertyMap;
723   propertyMap.Insert( Visual::Property::TYPE, DevelVisual::N_PATCH );
724   propertyMap.Insert( ImageVisual::Property::URL,  TEST_NPATCH_FILE_NAME );
725   {
726     Visual::Base visual = factory.CreateVisual( propertyMap );
727     DALI_TEST_CHECK( visual );
728
729     TestGlAbstraction& gl = application.GetGlAbstraction();
730     TraceCallStack& textureTrace = gl.GetTextureTrace();
731     textureTrace.Enable(true);
732
733     DummyControl actor = DummyControl::New();
734     TestVisualRender( application, actor, visual, 1u,
735                       ImageDimensions(ninePatchImageWidth, ninePatchImageHeight),
736                       ninePatchResource );
737
738     DALI_TEST_EQUALS( textureTrace.FindMethod("BindTexture"), true, TEST_LOCATION );
739
740     Stage::GetCurrent().Remove( actor );
741     DALI_TEST_CHECK( actor.GetRendererCount() == 0u );
742   }
743
744   propertyMap.Insert( ImageVisual::Property::BORDER_ONLY,  true );
745   {
746     tet_infoline( "border only" );
747     Visual::Base visual = factory.CreateVisual( propertyMap );
748     DALI_TEST_CHECK( visual );
749
750     TestGlAbstraction& gl = application.GetGlAbstraction();
751     TraceCallStack& textureTrace = gl.GetTextureTrace();
752     textureTrace.Enable(true);
753     DummyControl actor = DummyControl::New();
754     TestVisualRender( application, actor, visual, 1u,
755                       ImageDimensions(ninePatchImageWidth, ninePatchImageHeight),
756                       ninePatchResource );
757
758
759     DALI_TEST_EQUALS( textureTrace.FindMethod("BindTexture"), true, TEST_LOCATION );
760
761     Stage::GetCurrent().Remove( actor );
762     DALI_TEST_CHECK( actor.GetRendererCount() == 0u );
763   }
764
765   END_TEST;
766 }
767
768 int UtcDaliVisualFactoryGetNPatchVisual4(void)
769 {
770   ToolkitTestApplication application;
771   tet_infoline( "UtcDaliVisualFactoryGetNPatchVisual3: Request 9-patch visual with an image url" );
772
773   VisualFactory factory = VisualFactory::Get();
774   DALI_TEST_CHECK( factory );
775
776   const unsigned int ninePatchImageHeight = 18;
777   const unsigned int ninePatchImageWidth = 28;
778   StretchRanges stretchRangesX;
779   stretchRangesX.PushBack( Uint16Pair( 2, 3 ) );
780   StretchRanges stretchRangesY;
781   stretchRangesY.PushBack( Uint16Pair( 4, 5 ) );
782   Integration::ResourcePointer ninePatchResource = CustomizeNinePatch( application, ninePatchImageWidth, ninePatchImageHeight, stretchRangesX, stretchRangesY );
783
784   Visual::Base visual = factory.CreateVisual( TEST_NPATCH_FILE_NAME, ImageDimensions() );
785   DALI_TEST_CHECK( visual );
786
787   TestGlAbstraction& gl = application.GetGlAbstraction();
788   TraceCallStack& textureTrace = gl.GetTextureTrace();
789   textureTrace.Enable(true);
790
791   DummyControl actor = DummyControl::New();
792   TestVisualRender( application, actor, visual, 1u,
793                     ImageDimensions(ninePatchImageWidth, ninePatchImageHeight),
794                     ninePatchResource );
795
796   DALI_TEST_EQUALS( textureTrace.FindMethod("BindTexture"), true, TEST_LOCATION );
797
798
799   ResourceImage image = ResourceImage::New(TEST_NPATCH_FILE_NAME);
800   Visual::Base nPatchVisual = factory.CreateVisual( image );
801   Vector2 controlSize( 20.f, 30.f ), naturalSize(0,0);
802   nPatchVisual.SetTransformAndSize(DefaultTransform(), controlSize );
803   nPatchVisual.GetNaturalSize( naturalSize );
804   DALI_TEST_EQUALS( naturalSize, Vector2( ninePatchImageWidth-2, ninePatchImageHeight-2 ), TEST_LOCATION );
805
806   END_TEST;
807 }
808
809 int UtcDaliVisualFactoryGetNPatchVisual5(void)
810 {
811   ToolkitTestApplication application;
812   tet_infoline( "UtcDaliVisualFactoryGetNPatchVisual4: Request n-patch visual with an image url" );
813
814   VisualFactory factory = VisualFactory::Get();
815   DALI_TEST_CHECK( factory );
816
817   const unsigned int ninePatchImageHeight = 18;
818   const unsigned int ninePatchImageWidth = 28;
819   StretchRanges stretchRangesX;
820   stretchRangesX.PushBack( Uint16Pair( 2, 3 ) );
821   stretchRangesX.PushBack( Uint16Pair( 5, 7 ) );
822   stretchRangesX.PushBack( Uint16Pair( 12, 15 ) );
823   StretchRanges stretchRangesY;
824   stretchRangesY.PushBack( Uint16Pair( 4, 5 ) );
825   stretchRangesY.PushBack( Uint16Pair( 8, 12 ) );
826   stretchRangesY.PushBack( Uint16Pair( 15, 16 ) );
827   stretchRangesY.PushBack( Uint16Pair( 25, 27 ) );
828   Integration::ResourcePointer ninePatchResource = CustomizeNinePatch( application, ninePatchImageWidth, ninePatchImageHeight, stretchRangesX, stretchRangesY );
829
830   Visual::Base visual = factory.CreateVisual( TEST_NPATCH_FILE_NAME, ImageDimensions() );
831   DALI_TEST_CHECK( visual );
832
833   TestGlAbstraction& gl = application.GetGlAbstraction();
834   TraceCallStack& textureTrace = gl.GetTextureTrace();
835   textureTrace.Enable(true);
836
837   DummyControl actor = DummyControl::New();
838   TestVisualRender( application, actor, visual, 1u,
839                     ImageDimensions(ninePatchImageWidth, ninePatchImageHeight),
840                     ninePatchResource );
841
842   DALI_TEST_EQUALS( textureTrace.FindMethod("BindTexture"), true, TEST_LOCATION );
843
844   END_TEST;
845 }
846
847 int UtcDaliVisualFactoryGetNPatchVisualN1(void)
848 {
849   //This should still load but display an error image
850
851   ToolkitTestApplication application;
852   tet_infoline( "UtcDaliVisualFactoryGetNPatchVisualN: Request n-patch visual with an invalid image url" );
853
854   VisualFactory factory = VisualFactory::Get();
855   DALI_TEST_CHECK( factory );
856
857   Visual::Base visual = factory.CreateVisual( "ERROR.9.jpg", ImageDimensions() );
858   DALI_TEST_CHECK( visual );
859
860   //The testkit still has to load a bitmap for the broken renderer image
861   Integration::Bitmap* bitmap = Integration::Bitmap::New(Integration::Bitmap::BITMAP_2D_PACKED_PIXELS, ResourcePolicy::OWNED_DISCARD);
862   bitmap->GetPackedPixelsProfile()->ReserveBuffer( Pixel::RGBA8888, 100, 100, 100, 100 );
863
864   TestGlAbstraction& gl = application.GetGlAbstraction();
865   TraceCallStack& textureTrace = gl.GetTextureTrace();
866   textureTrace.Enable(true);
867
868   DummyControl actor = DummyControl::New();
869   TestVisualRender( application, actor, visual, 1u,
870                     ImageDimensions(),
871                     Integration::ResourcePointer(bitmap) );
872
873   DALI_TEST_EQUALS( textureTrace.FindMethod("BindTexture"), true, TEST_LOCATION );
874
875   END_TEST;
876 }
877
878 int UtcDaliVisualFactoryGetNPatchVisualN2(void)
879 {
880   //This should still load but display an error image
881
882   ToolkitTestApplication application;
883   tet_infoline( "UtcDaliVisualFactoryGetNPatchVisualN: Request n-patch visual with an invalid URL" );
884
885   VisualFactory factory = VisualFactory::Get();
886   DALI_TEST_CHECK( factory );
887
888   Property::Map propertyMap;
889   propertyMap.Insert( Visual::Property::TYPE, DevelVisual::N_PATCH );
890   propertyMap.Insert( ImageVisual::Property::URL,  "ERROR.9.jpg" );
891
892   Visual::Base visual = factory.CreateVisual( propertyMap );
893   DALI_TEST_CHECK( visual );
894
895   //The testkit still has to load a bitmap for the broken renderer image
896   Integration::Bitmap* bitmap = Integration::Bitmap::New(Integration::Bitmap::BITMAP_2D_PACKED_PIXELS, ResourcePolicy::OWNED_DISCARD);
897   bitmap->GetPackedPixelsProfile()->ReserveBuffer( Pixel::RGBA8888, 100, 100, 100, 100 );
898
899   TestGlAbstraction& gl = application.GetGlAbstraction();
900   TraceCallStack& textureTrace = gl.GetTextureTrace();
901   textureTrace.Enable(true);
902   TraceCallStack& drawTrace = gl.GetDrawTrace();
903   drawTrace.Enable(true);
904
905   DummyControl actor = DummyControl::New();
906   TestVisualRender( application, actor, visual, 1u,
907                     ImageDimensions(),
908                     Integration::ResourcePointer(bitmap) );
909
910   DALI_TEST_EQUALS( textureTrace.FindMethod("BindTexture"), true, TEST_LOCATION );
911
912   END_TEST;
913 }
914
915 int UtcDaliVisualFactoryGetNPatchVisualN3(void)
916 {
917   // Passing in an invalid visual type so we should not get a visual
918
919   ToolkitTestApplication application;
920   tet_infoline( "UtcDaliVisualFactoryGetNPatchVisualN: Request n-patch visual with an invalid visual type" );
921
922   VisualFactory factory = VisualFactory::Get();
923   DALI_TEST_CHECK( factory );
924
925   Property::Map propertyMap;
926   propertyMap.Insert( Visual::Property::TYPE,  111 );
927   propertyMap.Insert( ImageVisual::Property::URL,  "ERROR.9.jpg" );
928
929   Visual::Base visual = factory.CreateVisual( propertyMap );
930   DALI_TEST_CHECK( !visual );
931
932   END_TEST;
933 }
934
935 int UtcDaliVisualFactoryGetSvgVisual(void)
936 {
937   ToolkitTestApplication application;
938   tet_infoline( "UtcDaliVisualFactoryGetSvgVisual: Request svg visual with a svg url" );
939
940   VisualFactory factory = VisualFactory::Get();
941   Visual::Base visual = factory.CreateVisual( TEST_SVG_FILE_NAME, ImageDimensions() );
942   DALI_TEST_CHECK( visual );
943
944   TestGlAbstraction& gl = application.GetGlAbstraction();
945   TraceCallStack& textureTrace = gl.GetTextureTrace();
946   textureTrace.Enable(true);
947
948   DummyControl actor = DummyControl::New();
949   DummyControlImpl& dummyImpl = static_cast<DummyControlImpl&>(actor.GetImplementation());
950   dummyImpl.RegisterVisual( Control::CONTROL_PROPERTY_END_INDEX + 1, visual );
951   actor.SetSize( 200.f, 200.f );
952   Stage::GetCurrent().Add( actor );
953   visual.SetTransformAndSize(DefaultTransform(), Vector2(200.f, 200.f) );
954
955   application.SendNotification();
956   application.Render();
957
958   // renderer is not added to actor until the rasterization is completed.
959   DALI_TEST_CHECK( actor.GetRendererCount() == 0u );
960
961   DALI_TEST_EQUALS( Test::WaitForEventThreadTrigger( 1 ), true, TEST_LOCATION );
962
963   // renderer is added to actor
964   DALI_TEST_CHECK( actor.GetRendererCount() == 1u );
965
966   // waiting for the resource uploading
967   application.SendNotification();
968   application.Render();
969
970   DALI_TEST_EQUALS( textureTrace.FindMethod("BindTexture"), true, TEST_LOCATION );
971
972   END_TEST;
973 }
974
975 int UtcDaliVisualFactoryGetSvgVisualLarge(void)
976 {
977   ToolkitTestApplication application;
978   tet_infoline( "UtcDaliVisualFactoryGetSvgVisual: Request svg visual with a svg url" );
979
980   VisualFactory factory = VisualFactory::Get();
981   Visual::Base visual = factory.CreateVisual( TEST_SVG_FILE_NAME, ImageDimensions( 2000, 2000 ) );
982   DALI_TEST_CHECK( visual );
983
984   TestGlAbstraction& gl = application.GetGlAbstraction();
985   TraceCallStack& textureTrace = gl.GetTextureTrace();
986   textureTrace.Enable(true);
987
988   DummyControl actor = DummyControl::New(true);
989   DummyControlImpl& dummyImpl = static_cast<DummyControlImpl&>(actor.GetImplementation());
990   actor.SetResizePolicy( ResizePolicy::FILL_TO_PARENT, Dimension::ALL_DIMENSIONS ); // Only rasterizes when it knows control size.
991   dummyImpl.RegisterVisual( Control::CONTROL_PROPERTY_END_INDEX + 1, visual );
992   Stage::GetCurrent().Add( actor );
993
994   application.SendNotification();
995   application.Render();
996
997   // renderer is not added to actor until the rasterization is completed.
998   DALI_TEST_CHECK( actor.GetRendererCount() == 0u );
999
1000   DALI_TEST_EQUALS( Test::WaitForEventThreadTrigger( 1 ), true, TEST_LOCATION );
1001
1002   // renderer is added to actor
1003   DALI_TEST_CHECK( actor.GetRendererCount() == 1u );
1004
1005   // waiting for the resource uploading
1006   application.SendNotification();
1007   application.Render();
1008
1009   DALI_TEST_EQUALS( textureTrace.FindMethod("BindTexture"), true, TEST_LOCATION );
1010
1011   END_TEST;
1012 }
1013
1014 //Creates a mesh visual from the given propertyMap and tries to load it on stage in the given application.
1015 //This is expected to succeed, which will then pass the test.
1016 void MeshVisualLoadsCorrectlyTest( Property::Map& propertyMap, ToolkitTestApplication& application )
1017 {
1018   VisualFactory factory = VisualFactory::Get();
1019   DALI_TEST_CHECK( factory );
1020
1021   //Create a mesh visual.
1022   Visual::Base visual = factory.CreateVisual( propertyMap );
1023   DALI_TEST_CHECK( visual );
1024
1025   //Create an actor on stage to house the visual.
1026   DummyControl actor = DummyControl::New();
1027   DummyControlImpl& dummyImpl = static_cast<DummyControlImpl&>(actor.GetImplementation());
1028   dummyImpl.RegisterVisual( Control::CONTROL_PROPERTY_END_INDEX + 1, visual );
1029   actor.SetSize( 200.f, 200.f );
1030   Stage::GetCurrent().Add( actor );
1031   visual.SetTransformAndSize(DefaultTransform(), Vector2( 200.f, 200.f ) );
1032
1033   //Ensure set on stage.
1034   DALI_TEST_EQUALS( actor.GetRendererCount(), 1u, TEST_LOCATION );
1035
1036   //Attempt to render to queue resource load requests.
1037   application.SendNotification();
1038   application.Render( 0 );
1039
1040   //Render again to upload the now-loaded textures.
1041   application.SendNotification();
1042   application.Render( 0 );
1043
1044   Matrix testScaleMatrix;
1045   testScaleMatrix.SetIdentityAndScale( Vector3( 1.0, -1.0, 1.0 ) );
1046   Matrix actualScaleMatrix;
1047
1048   //Test to see if the object has been successfully loaded.
1049   DALI_TEST_CHECK( application.GetGlAbstraction().GetUniformValue<Matrix>( "uObjectMatrix", actualScaleMatrix ) );
1050   DALI_TEST_EQUALS( actualScaleMatrix, testScaleMatrix, Math::MACHINE_EPSILON_100, TEST_LOCATION );
1051
1052   //Finish by setting off stage, and ensuring this was successful.
1053   actor.Unparent();
1054   DALI_TEST_EQUALS( actor.GetRendererCount(), 0u, TEST_LOCATION );
1055 }
1056
1057 //Creates a mesh visual from the given propertyMap and tries to load it on stage in the given application.
1058 //This is expected to fail, which will then pass the test.
1059 void MeshVisualDoesNotLoadCorrectlyTest( Property::Map& propertyMap, ToolkitTestApplication& application )
1060 {
1061   VisualFactory factory = VisualFactory::Get();
1062   DALI_TEST_CHECK( factory );
1063
1064   //Create a mesh visual.
1065   Visual::Base visual = factory.CreateVisual( propertyMap );
1066   DALI_TEST_CHECK( visual );
1067
1068   //Create an actor on stage to house the visual.
1069   DummyControl actor = DummyControl::New();
1070   DummyControlImpl& dummyImpl = static_cast<DummyControlImpl&>(actor.GetImplementation());
1071   dummyImpl.RegisterVisual( Control::CONTROL_PROPERTY_END_INDEX + 1, visual );
1072   actor.SetSize( 200.f, 200.f );
1073   Stage::GetCurrent().Add( actor );
1074   visual.SetTransformAndSize(DefaultTransform(),  Vector2( 200.f, 200.f ) );
1075
1076   //Ensure set on stage.
1077   DALI_TEST_EQUALS( actor.GetRendererCount(), 1u, TEST_LOCATION );
1078
1079   //Attempt to render to queue resource load requests.
1080   application.SendNotification();
1081   application.Render( 0 );
1082
1083   //Render again to upload the now-loaded textures.
1084   application.SendNotification();
1085   application.Render( 0 );
1086
1087   //Test to see if the object has not been loaded, as expected.
1088   Matrix scaleMatrix;
1089   DALI_TEST_CHECK( !application.GetGlAbstraction().GetUniformValue<Matrix>( "uObjectMatrix", scaleMatrix ) );
1090
1091   //Finish by setting off stage, and ensuring this was successful.
1092   actor.Unparent();
1093   DALI_TEST_EQUALS( actor.GetRendererCount(), 0u, TEST_LOCATION );
1094 }
1095
1096 //Test if mesh loads correctly when supplied with only the bare minimum requirements, an object file.
1097 int UtcDaliVisualFactoryGetMeshVisual1(void)
1098 {
1099   //Set up test application first, so everything else can be handled.
1100   ToolkitTestApplication application;
1101
1102   tet_infoline( "UtcDaliVisualFactoryGetMeshVisual1:  Request mesh visual with a valid object file only" );
1103
1104
1105   //Set up visual properties.
1106   Property::Map propertyMap;
1107   propertyMap.Insert( Visual::Property::TYPE,  Visual::MESH );
1108   propertyMap.Insert( MeshVisual::Property::OBJECT_URL, TEST_OBJ_FILE_NAME );
1109
1110   //Test to see if mesh loads correctly.
1111   MeshVisualLoadsCorrectlyTest( propertyMap, application );
1112
1113   END_TEST;
1114 }
1115
1116
1117 //Test if mesh loads correctly when supplied with an object file as well as a blank material file and images directory.
1118 int UtcDaliVisualFactoryGetMeshVisual2(void)
1119 {
1120   //Set up test application first, so everything else can be handled.
1121   ToolkitTestApplication application;
1122
1123   tet_infoline( "UtcDaliVisualFactoryGetMeshVisual2:  Request mesh visual with blank material file and images directory" );
1124
1125   //Set up visual properties.
1126   Property::Map propertyMap;
1127   propertyMap.Insert( Visual::Property::TYPE, Visual::MESH );
1128   propertyMap.Insert( MeshVisual::Property::OBJECT_URL, TEST_OBJ_FILE_NAME );
1129   propertyMap.Insert( MeshVisual::Property::MATERIAL_URL, "" );
1130   propertyMap.Insert( MeshVisual::Property::TEXTURES_PATH, "" );
1131
1132   //Test to see if mesh loads correctly.
1133   MeshVisualLoadsCorrectlyTest( propertyMap, application );
1134
1135   END_TEST;
1136 }
1137
1138 //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
1139 int UtcDaliVisualFactoryGetMeshVisual3b(void)
1140 {
1141   //Set up test application first, so everything else can be handled.
1142   ToolkitTestApplication application;
1143
1144   tet_infoline( "UtcDaliVisualFactoryGetMeshVisual3:  Request mesh visual with all parameters correct" );
1145
1146   //Set up visual properties.
1147   Property::Map propertyMap;
1148   propertyMap.Insert( Visual::Property::TYPE, Visual::MESH );
1149   propertyMap.Insert( MeshVisual::Property::OBJECT_URL, TEST_OBJ_FILE_NAME );
1150   propertyMap.Insert( MeshVisual::Property::MATERIAL_URL, TEST_MTL_FILE_NAME );
1151   propertyMap.Insert( MeshVisual::Property::USE_MIPMAPPING, Color::GREEN ); // Test that wrong property types don't prevent the object load
1152   propertyMap.Insert( MeshVisual::Property::USE_SOFT_NORMALS, 1.0f );
1153   propertyMap.Insert( MeshVisual::Property::LIGHT_POSITION, 1.0f );
1154   propertyMap.Insert( MeshVisual::Property::TEXTURES_PATH, TEST_RESOURCE_DIR "/" );
1155
1156   //Test to see if mesh loads correctly.
1157   MeshVisualLoadsCorrectlyTest( propertyMap, application );
1158
1159   END_TEST;
1160 }
1161
1162 //Test if mesh loads correctly when supplied with all main parameters, an object file, a material file and a directory location.
1163 int UtcDaliVisualFactoryGetMeshVisual3(void)
1164 {
1165   //Set up test application first, so everything else can be handled.
1166   ToolkitTestApplication application;
1167
1168   tet_infoline( "UtcDaliVisualFactoryGetMeshVisual3:  Request mesh visual with all parameters correct" );
1169
1170   //Set up visual properties.
1171   Property::Map propertyMap;
1172   propertyMap.Insert( Visual::Property::TYPE, Visual::MESH );
1173   propertyMap.Insert( MeshVisual::Property::OBJECT_URL, TEST_OBJ_FILE_NAME );
1174   propertyMap.Insert( MeshVisual::Property::MATERIAL_URL, TEST_MTL_FILE_NAME );
1175   propertyMap.Insert( MeshVisual::Property::USE_MIPMAPPING, false );
1176   propertyMap.Insert( MeshVisual::Property::USE_SOFT_NORMALS, false );
1177   propertyMap.Insert( MeshVisual::Property::LIGHT_POSITION, Vector3::XAXIS );
1178   propertyMap.Insert( MeshVisual::Property::TEXTURES_PATH, TEST_RESOURCE_DIR "/" );
1179
1180   //Test to see if mesh loads correctly.
1181   MeshVisualLoadsCorrectlyTest( propertyMap, application );
1182
1183   END_TEST;
1184 }
1185
1186 //Test if mesh visual can load a correctly supplied mesh without a normal map or gloss map in the material file.
1187 int UtcDaliVisualFactoryGetMeshVisual4(void)
1188 {
1189   //Set up test application first, so everything else can be handled.
1190   ToolkitTestApplication application;
1191
1192   tet_infoline( "UtcDaliVisualFactoryGetMeshVisual4:  Request mesh visual with diffuse texture but not normal or gloss." );
1193
1194
1195   //Set up visual properties.
1196   Property::Map propertyMap;
1197   propertyMap.Insert( Visual::Property::TYPE, Visual::MESH );
1198   propertyMap.Insert( MeshVisual::Property::OBJECT_URL, TEST_OBJ_FILE_NAME );
1199   propertyMap.Insert( MeshVisual::Property::MATERIAL_URL, TEST_SIMPLE_MTL_FILE_NAME );
1200   propertyMap.Insert( MeshVisual::Property::TEXTURES_PATH, TEST_RESOURCE_DIR "/" );
1201
1202   //Test to see if mesh loads correctly.
1203   MeshVisualLoadsCorrectlyTest( propertyMap, application );
1204
1205   END_TEST;
1206 }
1207
1208 //Test if mesh visual can load when made to use diffuse textures only.
1209 int UtcDaliVisualFactoryGetMeshVisual5(void)
1210 {
1211   //Set up test application first, so everything else can be handled.
1212   ToolkitTestApplication application;
1213
1214   tet_infoline( "UtcDaliVisualFactoryGetMeshVisual5:  Request mesh visual and make it only use diffuse textures." );
1215
1216   //Set up visual properties.
1217   Property::Map propertyMap;
1218   propertyMap.Insert( Visual::Property::TYPE, Visual::MESH );
1219   propertyMap.Insert( "objectUrl", TEST_OBJ_FILE_NAME );
1220   propertyMap.Insert( "materialUrl", TEST_MTL_FILE_NAME );
1221   propertyMap.Insert( "texturesPath", TEST_RESOURCE_DIR "/" );
1222   propertyMap.Insert( "useMipmapping", false );
1223   propertyMap.Insert( "useSoftNormals", false );
1224   propertyMap.Insert( "lightPosition", Vector3::ZAXIS );
1225   propertyMap.Insert( "shadingMode", MeshVisual::ShadingMode::TEXTURED_WITH_SPECULAR_LIGHTING );
1226
1227   //Test to see if mesh loads correctly.
1228   MeshVisualLoadsCorrectlyTest( propertyMap, application );
1229
1230
1231   END_TEST;
1232 }
1233
1234 //Test if mesh visual can load when made to not use the supplied textures.
1235 int UtcDaliVisualFactoryGetMeshVisual6(void)
1236 {
1237   //Set up test application first, so everything else can be handled.
1238   ToolkitTestApplication application;
1239
1240   tet_infoline( "UtcDaliVisualFactoryGetMeshVisual6:  Request mesh visual and make it not use any textures." );
1241
1242   //Set up visual properties.
1243   Property::Map propertyMap;
1244   propertyMap.Insert( Visual::Property::TYPE, Visual::MESH );
1245   propertyMap.Insert( MeshVisual::Property::OBJECT_URL, TEST_OBJ_FILE_NAME );
1246   propertyMap.Insert( MeshVisual::Property::MATERIAL_URL, TEST_MTL_FILE_NAME );
1247   propertyMap.Insert( MeshVisual::Property::TEXTURES_PATH, TEST_RESOURCE_DIR "/" );
1248   propertyMap.Insert( MeshVisual::Property::SHADING_MODE, MeshVisual::ShadingMode::TEXTURELESS_WITH_DIFFUSE_LIGHTING );
1249
1250   //Test to see if mesh loads correctly.
1251   MeshVisualLoadsCorrectlyTest( propertyMap, application );
1252
1253   END_TEST;
1254 }
1255 //Test if mesh visual loads correctly when light position is manually set.
1256 int UtcDaliVisualFactoryGetMeshVisual7(void)
1257 {
1258   //Set up test application first, so everything else can be handled.
1259   ToolkitTestApplication application;
1260
1261
1262   tet_infoline( "UtcDaliVisualFactoryGetMeshVisual7:  Request mesh visual with custom light position." );
1263
1264   //Set up visual properties.
1265   Property::Map propertyMap;
1266   propertyMap.Insert( Visual::Property::TYPE, Visual::MESH );
1267   propertyMap.Insert( MeshVisual::Property::OBJECT_URL, TEST_OBJ_FILE_NAME );
1268   propertyMap.Insert( MeshVisual::Property::MATERIAL_URL, TEST_MTL_FILE_NAME );
1269   propertyMap.Insert( MeshVisual::Property::TEXTURES_PATH, TEST_RESOURCE_DIR "/" );
1270   propertyMap.Insert( MeshVisual::Property::LIGHT_POSITION, Vector3( 0.0, 1.0, 2.0 ) );
1271
1272   //Test to see if mesh loads correctly.
1273   MeshVisualLoadsCorrectlyTest( propertyMap, application );
1274
1275   END_TEST;
1276 }
1277
1278 //Test if mesh visual loads correctly when supplied an object file without face normals or texture points.
1279 //Note that this notably tests object loader functionality.
1280 int UtcDaliVisualFactoryGetMeshVisual8(void)
1281 {
1282   //Set up test application first, so everything else can be handled.
1283   ToolkitTestApplication application;
1284
1285   tet_infoline( "UtcDaliVisualFactoryGetMeshVisual5:  Request mesh visual with normal-less object file." );
1286
1287   //Set up visual properties.
1288   Property::Map propertyMap;
1289   propertyMap.Insert( Visual::Property::TYPE, Visual::MESH );
1290   propertyMap.Insert( MeshVisual::Property::OBJECT_URL, TEST_SIMPLE_OBJ_FILE_NAME );
1291   propertyMap.Insert( MeshVisual::Property::MATERIAL_URL, TEST_MTL_FILE_NAME );
1292   propertyMap.Insert( MeshVisual::Property::TEXTURES_PATH, TEST_RESOURCE_DIR "/" );
1293
1294   //Test to see if mesh loads correctly.
1295   MeshVisualLoadsCorrectlyTest( propertyMap, application );
1296
1297   END_TEST;
1298 }
1299
1300 //Test if mesh visual handles the case of lacking an object file.
1301 int UtcDaliVisualFactoryGetMeshVisualN1(void)
1302 {
1303   //Set up test application first, so everything else can be handled.
1304   ToolkitTestApplication application;
1305
1306   tet_infoline( "UtcDaliVisualFactoryGetMeshVisualN1:  Request mesh visual without object file" );
1307
1308   //Set up visual properties.
1309   Property::Map propertyMap;
1310   propertyMap.Insert( Visual::Property::TYPE, Visual::MESH );
1311   propertyMap.Insert( MeshVisual::Property::MATERIAL_URL, TEST_MTL_FILE_NAME );
1312   propertyMap.Insert( MeshVisual::Property::TEXTURES_PATH, TEST_RESOURCE_DIR "/" );
1313
1314   //Test to see if mesh doesn't load with these properties, as expected.
1315   MeshVisualDoesNotLoadCorrectlyTest( propertyMap, application );
1316
1317
1318   END_TEST;
1319 }
1320
1321 //Test if mesh visual handles the case of being passed invalid material and images urls.
1322 int UtcDaliVisualFactoryGetMeshVisualN2(void)
1323 {
1324   //Set up test application first, so everything else can be handled.
1325   ToolkitTestApplication application;
1326
1327   tet_infoline( "UtcDaliVisualFactoryGetMeshVisualN2:  Request mesh visual with invalid material and images urls" );
1328
1329   //Set up visual properties.
1330   Property::Map propertyMap;
1331   propertyMap.Insert( Visual::Property::TYPE, Visual::MESH );
1332   propertyMap.Insert( MeshVisual::Property::OBJECT_URL, TEST_OBJ_FILE_NAME );
1333   propertyMap.Insert( MeshVisual::Property::MATERIAL_URL, "invalid" );
1334   propertyMap.Insert( MeshVisual::Property::TEXTURES_PATH, "also invalid" );
1335
1336   //Test to see if mesh doesn't load with these properties, as expected.
1337   MeshVisualDoesNotLoadCorrectlyTest( propertyMap, application );
1338
1339
1340   END_TEST;
1341 }
1342
1343 //Test if mesh visual handles the case of being passed an invalid object url
1344 int UtcDaliVisualFactoryGetMeshVisualN3(void)
1345 {
1346   //Set up test application first, so everything else can be handled.
1347   ToolkitTestApplication application;
1348   tet_infoline( "UtcDaliVisualFactoryGetMeshVisualN3:  Request mesh visual with invalid object url" );
1349
1350
1351   //Set up visual properties.
1352   Property::Map propertyMap;
1353   propertyMap.Insert( Visual::Property::TYPE, Visual::MESH );
1354   propertyMap.Insert( MeshVisual::Property::OBJECT_URL, "invalid" );
1355   propertyMap.Insert( MeshVisual::Property::MATERIAL_URL, TEST_MTL_FILE_NAME );
1356   propertyMap.Insert( MeshVisual::Property::TEXTURES_PATH, TEST_RESOURCE_DIR "/" );
1357
1358   //Test to see if mesh doesn't load with these properties, as expected.
1359   MeshVisualDoesNotLoadCorrectlyTest( propertyMap, application );
1360
1361   END_TEST;
1362 }
1363
1364 //Creates a primitive visual with the given property map and tests to see if it correctly loads in the given application.
1365 void TestPrimitiveVisualWithProperties( Property::Map& propertyMap, ToolkitTestApplication& application )
1366 {
1367   VisualFactory factory = VisualFactory::Get();
1368   DALI_TEST_CHECK( factory );
1369
1370   //Create a primitive visual.
1371   Visual::Base visual = factory.CreateVisual( propertyMap );
1372   DALI_TEST_CHECK( visual );
1373
1374   //Create an actor on stage to house the visual.
1375   DummyControl actor = DummyControl::New();
1376   DummyControlImpl& dummyImpl = static_cast<DummyControlImpl&>(actor.GetImplementation());
1377   dummyImpl.RegisterVisual( Control::CONTROL_PROPERTY_END_INDEX + 1, visual );
1378
1379   actor.SetSize( 200.f, 200.f );
1380   Stage::GetCurrent().Add( actor );
1381   visual.SetTransformAndSize(DefaultTransform(),  Vector2( 200.f, 200.f ) );
1382
1383   //Ensure set on stage.
1384   DALI_TEST_EQUALS( actor.GetRendererCount(), 1u, TEST_LOCATION );
1385
1386   //Tell test application to load the visual.
1387   application.SendNotification();
1388   application.Render(0);
1389
1390   Matrix testScaleMatrix;
1391   testScaleMatrix.SetIdentityAndScale( Vector3( 1.0, -1.0, 1.0 ) );
1392   Matrix actualScaleMatrix;
1393
1394   //Test to see if the object has been successfully loaded.
1395   DALI_TEST_CHECK( application.GetGlAbstraction().GetUniformValue<Matrix>( "uObjectMatrix", actualScaleMatrix ) );
1396   DALI_TEST_EQUALS( actualScaleMatrix, testScaleMatrix, Math::MACHINE_EPSILON_100, TEST_LOCATION );
1397
1398   //Finish by setting off stage, and ensuring this was successful.
1399   actor.Unparent();
1400   DALI_TEST_EQUALS( actor.GetRendererCount(), 0u, TEST_LOCATION );
1401 }
1402
1403 //Test if primitive shape loads correctly when supplied with only the bare minimum requirements, the shape to use.
1404 int UtcDaliVisualFactoryGetPrimitiveVisual1(void)
1405 {
1406   //Set up test application first, so everything else can be handled.
1407   ToolkitTestApplication application;
1408
1409   tet_infoline( "UtcDaliVisualFactoryGetPrimitiveVisual1:  Request primitive visual with a shape only" );
1410
1411   //Set up visual properties.
1412   Property::Map propertyMap;
1413   propertyMap.Insert( Visual::Property::TYPE, Visual::PRIMITIVE );
1414   propertyMap.Insert( PrimitiveVisual::Property::SHAPE, PrimitiveVisual::Shape::CUBE );
1415
1416   //Test to see if shape loads correctly.
1417   TestPrimitiveVisualWithProperties( propertyMap, application );
1418
1419   END_TEST;
1420 }
1421
1422 //Test if primitive shape loads correctly when supplied with all possible parameters
1423 int UtcDaliVisualFactoryGetPrimitiveVisual2(void)
1424 {
1425   //Set up test application first, so everything else can be handled.
1426   ToolkitTestApplication application;
1427
1428   tet_infoline( "UtcDaliVisualFactoryGetPrimitiveVisual2:  Request primitive visual with everything" );
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   propertyMap.Insert( PrimitiveVisual::Property::MIX_COLOR, Vector4( 0.5, 0.5, 0.5, 1.0 ) );
1435   propertyMap.Insert( PrimitiveVisual::Property::SLICES, 10 );
1436   propertyMap.Insert( PrimitiveVisual::Property::STACKS, 20 );
1437   propertyMap.Insert( PrimitiveVisual::Property::SCALE_TOP_RADIUS, 30.0f );
1438   propertyMap.Insert( PrimitiveVisual::Property::SCALE_BOTTOM_RADIUS, 40.0f );
1439   propertyMap.Insert( PrimitiveVisual::Property::SCALE_HEIGHT, 50.0f );
1440   propertyMap.Insert( PrimitiveVisual::Property::SCALE_RADIUS, 60.0f );
1441   propertyMap.Insert( PrimitiveVisual::Property::BEVEL_PERCENTAGE, 0.7f );
1442   propertyMap.Insert( PrimitiveVisual::Property::BEVEL_SMOOTHNESS, 0.8f );
1443   propertyMap.Insert( MeshVisual::Property::LIGHT_POSITION, Vector3( 0.9, 1.0, 1.1 ) );
1444
1445   //Test to see if shape loads correctly.
1446   TestPrimitiveVisualWithProperties( propertyMap, application );
1447
1448   END_TEST;
1449 }
1450
1451 //Test if primitive shape loads a sphere correctly.
1452 int UtcDaliVisualFactoryGetPrimitiveVisual3(void)
1453 {
1454   //Set up test application first, so everything else can be handled.
1455   ToolkitTestApplication application;
1456
1457   tet_infoline( "UtcDaliVisualFactoryGetPrimitiveVisual3:  Request primitive visual to display a sphere" );
1458
1459   //Set up visual properties.
1460   Property::Map propertyMap;
1461   propertyMap.Insert( Visual::Property::TYPE, Visual::PRIMITIVE );
1462   propertyMap.Insert( PrimitiveVisual::Property::SHAPE, PrimitiveVisual::Shape::SPHERE );
1463   propertyMap.Insert( PrimitiveVisual::Property::MIX_COLOR, Vector4( 0.5, 0.5, 0.5, 1.0 ) );
1464   propertyMap.Insert( PrimitiveVisual::Property::SLICES, 10 );
1465   propertyMap.Insert( PrimitiveVisual::Property::STACKS, 20 );
1466
1467   //Test to see if shape loads correctly.
1468   TestPrimitiveVisualWithProperties( propertyMap, application );
1469
1470   END_TEST;
1471 }
1472
1473 //Test if primitive shape loads a conic section correctly.
1474 int UtcDaliVisualFactoryGetPrimitiveVisual4(void)
1475 {
1476   //Set up test application first, so everything else can be handled.
1477   ToolkitTestApplication application;
1478
1479   tet_infoline( "UtcDaliVisualFactoryGetPrimitiveVisual4:  Request primitive visual to display a conic section" );
1480
1481   //Set up visual properties.
1482   Property::Map propertyMap;
1483   propertyMap.Insert( Visual::Property::TYPE, Visual::PRIMITIVE );
1484   propertyMap.Insert( PrimitiveVisual::Property::SHAPE, PrimitiveVisual::Shape::CONICAL_FRUSTRUM );
1485   propertyMap.Insert( PrimitiveVisual::Property::MIX_COLOR, Vector4( 0.5, 0.5, 0.5, 1.0 ) );
1486   propertyMap.Insert( PrimitiveVisual::Property::SLICES, 10 );
1487   propertyMap.Insert( PrimitiveVisual::Property::SCALE_TOP_RADIUS, 30.0f );
1488   propertyMap.Insert( PrimitiveVisual::Property::SCALE_BOTTOM_RADIUS, 40.0f );
1489   propertyMap.Insert( PrimitiveVisual::Property::SCALE_HEIGHT, 50.0f );
1490
1491   //Test to see if shape loads correctly.
1492   TestPrimitiveVisualWithProperties( propertyMap, application );
1493
1494   END_TEST;
1495 }
1496
1497 //Test if primitive shape loads a bevelled cube correctly.
1498 int UtcDaliVisualFactoryGetPrimitiveVisual5(void)
1499 {
1500   //Set up test application first, so everything else can be handled.
1501   ToolkitTestApplication application;
1502
1503   tet_infoline( "UtcDaliVisualFactoryGetPrimitiveVisual5:  Request primitive visual to display a bevelled cube" );
1504
1505   //Set up visual properties.
1506   Property::Map propertyMap;
1507   propertyMap.Insert( Visual::Property::TYPE, Visual::PRIMITIVE );
1508   propertyMap.Insert( PrimitiveVisual::Property::SHAPE, PrimitiveVisual::Shape::BEVELLED_CUBE );
1509   propertyMap.Insert( PrimitiveVisual::Property::MIX_COLOR, Vector4( 0.5, 0.5, 0.5, 1.0 ) );
1510   propertyMap.Insert( PrimitiveVisual::Property::BEVEL_PERCENTAGE, 0.7f );
1511
1512   //Test to see if shape loads correctly.
1513   TestPrimitiveVisualWithProperties( propertyMap, application );
1514
1515   END_TEST;
1516 }
1517
1518 //Test if primitive shape loads an octahedron correctly.
1519 int UtcDaliVisualFactoryGetPrimitiveVisual6(void)
1520 {
1521   //Set up test application first, so everything else can be handled.
1522   ToolkitTestApplication application;
1523
1524   tet_infoline( "UtcDaliVisualFactoryGetPrimitiveVisual6:  Request primitive visual to display an octahedron" );
1525
1526   //Set up visual properties.
1527   Property::Map propertyMap;
1528   propertyMap.Insert( Visual::Property::TYPE, Visual::PRIMITIVE );
1529   propertyMap.Insert( PrimitiveVisual::Property::SHAPE, PrimitiveVisual::Shape::OCTAHEDRON );
1530   propertyMap.Insert( PrimitiveVisual::Property::MIX_COLOR, Vector4( 0.5, 0.5, 0.5, 1.0 ) );
1531
1532   //Test to see if shape loads correctly.
1533   TestPrimitiveVisualWithProperties( propertyMap, application );
1534
1535   END_TEST;
1536 }
1537
1538 //Test if primitive shape loads a cone correctly.
1539 int UtcDaliVisualFactoryGetPrimitiveVisual7(void)
1540 {
1541   //Set up test application first, so everything else can be handled.
1542   ToolkitTestApplication application;
1543
1544   tet_infoline( "UtcDaliVisualFactoryGetPrimitiveVisual7:  Request primitive visual to display a cone" );
1545
1546   //Set up visual properties.
1547   Property::Map propertyMap;
1548   propertyMap.Insert( Visual::Property::TYPE, Visual::PRIMITIVE );
1549   propertyMap.Insert( PrimitiveVisual::Property::SHAPE, PrimitiveVisual::Shape::CONE );
1550   propertyMap.Insert( PrimitiveVisual::Property::MIX_COLOR, Vector4( 0.5, 0.5, 0.5, 1.0 ) );
1551   propertyMap.Insert( PrimitiveVisual::Property::SLICES, 10 );
1552   propertyMap.Insert( PrimitiveVisual::Property::SCALE_TOP_RADIUS, 30.0f );
1553   propertyMap.Insert( PrimitiveVisual::Property::SCALE_HEIGHT, 50.0f );
1554
1555   //Test to see if shape loads correctly.
1556   TestPrimitiveVisualWithProperties( propertyMap, application );
1557
1558   END_TEST;
1559 }
1560
1561 //Test if primitive shape loads correctly when light position is manually set.
1562 int UtcDaliVisualFactoryGetPrimitiveVisual8(void)
1563 {
1564   //Set up test application first, so everything else can be handled.
1565   ToolkitTestApplication application;
1566
1567   tet_infoline( "UtcDaliVisualFactoryGetPrimitiveVisual8:  Request primitive visual with set light position" );
1568
1569   //Set up visual properties.
1570   Property::Map propertyMap;
1571   propertyMap.Insert( Visual::Property::TYPE, Visual::PRIMITIVE );
1572   propertyMap.Insert( PrimitiveVisual::Property::SHAPE, PrimitiveVisual::Shape::SPHERE );
1573   propertyMap.Insert( PrimitiveVisual::Property::MIX_COLOR, Vector4( 0.5, 0.5, 0.5, 1.0 ) );
1574   propertyMap.Insert( MeshVisual::Property::LIGHT_POSITION, Vector3( 0.0, 1.0, 2.0 ) );
1575
1576   //Test to see if shape loads correctly.
1577   TestPrimitiveVisualWithProperties( propertyMap, application );
1578
1579   END_TEST;
1580 }
1581
1582 //Test if primitive shape loads correctly when told to use too many slices.
1583 int UtcDaliVisualFactoryGetPrimitiveVisual9(void)
1584 {
1585   //Set up test application first, so everything else can be handled.
1586   ToolkitTestApplication application;
1587
1588   tet_infoline( "UtcDaliVisualFactoryGetPrimitiveVisual9:  Request primitive visual with above-cap slices." );
1589
1590   //Set up visual properties.
1591   Property::Map propertyMap;
1592   propertyMap.Insert( Visual::Property::TYPE, Visual::PRIMITIVE );
1593   propertyMap.Insert( PrimitiveVisual::Property::SHAPE, PrimitiveVisual::Shape::SPHERE );
1594   propertyMap.Insert( PrimitiveVisual::Property::SLICES, Property::Value( 1000000 ) );
1595
1596   //Test to see if shape loads correctly.
1597   TestPrimitiveVisualWithProperties( propertyMap, application );
1598
1599   END_TEST;
1600 }
1601
1602 //Test if primitive shape loads correctly when told to use too few slices. (2 slices or less.)
1603 int UtcDaliVisualFactoryGetPrimitiveVisual10(void)
1604 {
1605   //Set up test application first, so everything else can be handled.
1606   ToolkitTestApplication application;
1607
1608   tet_infoline( "UtcDaliVisualFactoryGetPrimitiveVisual10:  Request primitive visual with too few slices." );
1609
1610   //Set up visual properties.
1611   Property::Map propertyMap;
1612   propertyMap.Insert( Visual::Property::TYPE, Visual::PRIMITIVE );
1613   propertyMap.Insert( PrimitiveVisual::Property::SHAPE, PrimitiveVisual::Shape::SPHERE );
1614   propertyMap.Insert( PrimitiveVisual::Property::SLICES, Property::Value( 2 ) );
1615
1616   //Test to see if shape loads correctly.
1617   TestPrimitiveVisualWithProperties( propertyMap, application );
1618
1619   END_TEST;
1620 }
1621
1622 //Test if primitive shape loads correctly when told to use too many stacks.
1623 int UtcDaliVisualFactoryGetPrimitiveVisual11(void)
1624 {
1625   //Set up test application first, so everything else can be handled.
1626   ToolkitTestApplication application;
1627
1628   tet_infoline( "UtcDaliVisualFactoryGetPrimitiveVisual11:  Request primitive visual with too many stacks." );
1629
1630   //Set up visual properties.
1631   Property::Map propertyMap;
1632   propertyMap.Insert( Visual::Property::TYPE, Visual::PRIMITIVE );
1633   propertyMap.Insert( PrimitiveVisual::Property::SHAPE, PrimitiveVisual::Shape::SPHERE );
1634   propertyMap.Insert( PrimitiveVisual::Property::STACKS, Property::Value( 1000000 ) );
1635
1636   //Test to see if shape loads correctly.
1637   TestPrimitiveVisualWithProperties( propertyMap, application );
1638
1639   END_TEST;
1640 }
1641
1642 //Test if primitive shape loads correctly when told to use too few stacks. (1 stack or less.)
1643 int UtcDaliVisualFactoryGetPrimitiveVisual12(void)
1644 {
1645   //Set up test application first, so everything else can be handled.
1646   ToolkitTestApplication application;
1647
1648   tet_infoline( "UtcDaliVisualFactoryGetPrimitiveVisual12:  Request primitive visual with too few stacks." );
1649
1650   //Set up visual properties.
1651   Property::Map propertyMap;
1652   propertyMap.Insert( Visual::Property::TYPE, Visual::PRIMITIVE );
1653   propertyMap.Insert( PrimitiveVisual::Property::SHAPE, PrimitiveVisual::Shape::SPHERE );
1654   propertyMap.Insert( PrimitiveVisual::Property::STACKS, Property::Value( 1 ) );
1655
1656   //Test to see if shape loads correctly.
1657   TestPrimitiveVisualWithProperties( propertyMap, application );
1658
1659   END_TEST;
1660 }
1661
1662 //Test if primitive shape loads correctly when told to use invalid (zero or negative) dimensions.
1663 int UtcDaliVisualFactoryGetPrimitiveVisual13(void)
1664 {
1665   //Set up test application first, so everything else can be handled.
1666   ToolkitTestApplication application;
1667
1668   tet_infoline( "UtcDaliVisualFactoryGetPrimitiveVisual13:  Request primitive visual with invalid scale dimensions." );
1669
1670   //Set up visual properties.
1671   Property::Map propertyMap;
1672   propertyMap.Insert( Visual::Property::TYPE, Visual::PRIMITIVE );
1673   propertyMap.Insert( PrimitiveVisual::Property::SHAPE, PrimitiveVisual::Shape::SPHERE );
1674   propertyMap.Insert( PrimitiveVisual::Property::SCALE_DIMENSIONS, Vector3::ZERO );
1675
1676   //Test to see if shape loads correctly.
1677   TestPrimitiveVisualWithProperties( propertyMap, application );
1678
1679   END_TEST;
1680 }
1681
1682 //Test if primitive shape loads correctly when told to use too low a bevel percentage.
1683 int UtcDaliVisualFactoryGetPrimitiveVisual14(void)
1684 {
1685   //Set up test application first, so everything else can be handled.
1686   ToolkitTestApplication application;
1687
1688   tet_infoline( "UtcDaliVisualFactoryGetPrimitiveVisual14:  Request primitive visual with too low a bevel percentage." );
1689
1690   //Set up visual properties.
1691   Property::Map propertyMap;
1692   propertyMap.Insert( Visual::Property::TYPE, Visual::PRIMITIVE );
1693   propertyMap.Insert( PrimitiveVisual::Property::SHAPE, PrimitiveVisual::Shape::SPHERE );
1694   propertyMap.Insert( PrimitiveVisual::Property::BEVEL_PERCENTAGE, Property::Value( -1.0f ) );
1695
1696   //Test to see if shape loads correctly.
1697   TestPrimitiveVisualWithProperties( propertyMap, application );
1698
1699   END_TEST;
1700 }
1701
1702 //Test if primitive shape loads correctly when told to use too high a bevel percentage.
1703 int UtcDaliVisualFactoryGetPrimitiveVisual15(void)
1704 {
1705   //Set up test application first, so everything else can be handled.
1706   ToolkitTestApplication application;
1707
1708   tet_infoline( "UtcDaliVisualFactoryGetPrimitiveVisual15:  Request primitive visual with too high a bevel percentage." );
1709
1710   //Set up visual properties.
1711   Property::Map propertyMap;
1712   propertyMap.Insert( Visual::Property::TYPE, Visual::PRIMITIVE );
1713   propertyMap.Insert( PrimitiveVisual::Property::SHAPE, PrimitiveVisual::Shape::SPHERE );
1714   propertyMap.Insert( PrimitiveVisual::Property::BEVEL_PERCENTAGE, Property::Value( 2.0f ) );
1715
1716   //Test to see if shape loads correctly.
1717   TestPrimitiveVisualWithProperties( propertyMap, application );
1718
1719   END_TEST;
1720 }
1721
1722 //Test if primitive shape loads correctly when told to use too low a bevel smoothness.
1723 int UtcDaliVisualFactoryGetPrimitiveVisual16(void)
1724 {
1725   //Set up test application first, so everything else can be handled.
1726   ToolkitTestApplication application;
1727
1728   tet_infoline( "UtcDaliVisualFactoryGetPrimitiveVisual16:  Request primitive visual with too low a bevel smoothness." );
1729
1730   //Set up visual properties.
1731   Property::Map propertyMap;
1732   propertyMap.Insert( Visual::Property::TYPE, Visual::PRIMITIVE );
1733   propertyMap.Insert( PrimitiveVisual::Property::SHAPE, PrimitiveVisual::Shape::SPHERE );
1734   propertyMap.Insert( PrimitiveVisual::Property::BEVEL_SMOOTHNESS, Property::Value( -1.0f ) );
1735
1736   //Test to see if shape loads correctly.
1737   TestPrimitiveVisualWithProperties( propertyMap, application );
1738
1739   END_TEST;
1740 }
1741
1742 //Test if primitive shape loads correctly when told to use too high a bevel smoothness.
1743 int UtcDaliVisualFactoryGetPrimitiveVisual17(void)
1744 {
1745   //Set up test application first, so everything else can be handled.
1746   ToolkitTestApplication application;
1747
1748   tet_infoline( "UtcDaliVisualFactoryGetPrimitiveVisual17:  Request primitive visual with too high a bevel smoothness." );
1749
1750   //Set up visual properties.
1751   Property::Map propertyMap;
1752   propertyMap.Insert( Visual::Property::TYPE, Visual::PRIMITIVE );
1753   propertyMap.Insert( PrimitiveVisual::Property::SHAPE, PrimitiveVisual::Shape::SPHERE );
1754   propertyMap.Insert( PrimitiveVisual::Property::BEVEL_SMOOTHNESS, Property::Value( 2.0f ) );
1755
1756   //Test to see if shape loads correctly.
1757   TestPrimitiveVisualWithProperties( propertyMap, application );
1758
1759   END_TEST;
1760 }
1761
1762 //Test if primitive shape visual handles the case of not being passed a specific shape to use.
1763 int UtcDaliVisualFactoryGetPrimitiveVisualN1(void)
1764 {
1765   //Set up test application first, so everything else can be handled.
1766   ToolkitTestApplication application;
1767
1768   tet_infoline( "UtcDaliVisualFactoryGetPrimitiveVisualN1:  Request primitive visual without shape" );
1769
1770   //Set up visual properties, without supplying shape.
1771   Property::Map propertyMap;
1772   propertyMap.Insert( Visual::Property::TYPE, Visual::PRIMITIVE );
1773
1774   //Test to see if shape loads regardless of missing input.
1775   TestPrimitiveVisualWithProperties( propertyMap, application );
1776
1777   END_TEST;
1778 }
1779
1780 int UtcDaliVisualFactoryGetAnimatedImageVisual1(void)
1781 {
1782   ToolkitTestApplication application;
1783   tet_infoline( "UtcDaliVisualFactoryGetAnimatedImageVisual1: Request animated image visual with a gif url" );
1784
1785   VisualFactory factory = VisualFactory::Get();
1786   Visual::Base visual = factory.CreateVisual( TEST_GIF_FILE_NAME, ImageDimensions() );
1787   DALI_TEST_CHECK( visual );
1788
1789   TestGlAbstraction& gl = application.GetGlAbstraction();
1790   TraceCallStack& textureTrace = gl.GetTextureTrace();
1791   textureTrace.Enable(true);
1792
1793   DummyControl actor = DummyControl::New();
1794   DummyControlImpl& dummyImpl = static_cast<DummyControlImpl&>(actor.GetImplementation());
1795   dummyImpl.RegisterVisual( Control::CONTROL_PROPERTY_END_INDEX + 1, visual );
1796   actor.SetSize( 200.0f, 200.0f );
1797   Stage::GetCurrent().Add( actor );
1798
1799   application.SendNotification();
1800   application.Render();
1801
1802   // renderer is added to actor
1803   DALI_TEST_CHECK( actor.GetRendererCount() == 1u );
1804
1805   // test the uniforms which used to handle the atlas rect
1806   // the four frames should be located inside atlas as follows: atlas size 100*100
1807   // -------------
1808   // |     |     |
1809   // |  0  |  1  |
1810   // -------------
1811   // |     |     |
1812   // |  2  |  3  |
1813   // -------------
1814
1815   Renderer renderer = actor.GetRendererAt( 0u );
1816   DALI_TEST_CHECK( renderer );
1817
1818   Property::Value atlasRectValue = renderer.GetProperty( renderer.GetPropertyIndex( "uAtlasRect" ) );
1819   // take into consideration the half pixel correction
1820   DALI_TEST_EQUALS( atlasRectValue.Get<Vector4>(), Vector4(0.5f, 0.5f, 49.5f, 49.5f)/100.f, Math::MACHINE_EPSILON_100, TEST_LOCATION );
1821
1822   // waiting for the resource uploading
1823   application.SendNotification();
1824   application.Render();
1825
1826   DALI_TEST_EQUALS( textureTrace.FindMethod("BindTexture"), true, TEST_LOCATION );
1827
1828   // Force the timer used by the animatedImageVisual to tick,
1829   Dali::Timer timer = Timer::New( 0 );
1830   timer.MockEmitSignal();
1831   application.SendNotification();
1832   application.Render();
1833   atlasRectValue = renderer.GetProperty( renderer.GetPropertyIndex( "uAtlasRect" ) );
1834   // take into consideration the half pixel correction
1835   DALI_TEST_EQUALS( atlasRectValue.Get<Vector4>(), Vector4(50.5f, 0.5f, 99.5f, 49.5f)/100.f, Math::MACHINE_EPSILON_100, TEST_LOCATION );
1836
1837   // Force the timer used by the animatedImageVisual to tick,
1838   timer.MockEmitSignal();
1839   application.SendNotification();
1840   application.Render();
1841   atlasRectValue = renderer.GetProperty( renderer.GetPropertyIndex( "uAtlasRect" ) );
1842   // take into consideration the half pixel correction
1843   DALI_TEST_EQUALS( atlasRectValue.Get<Vector4>(), Vector4(0.5f, 50.5f, 49.5f, 99.5f)/100.f, Math::MACHINE_EPSILON_100, TEST_LOCATION );
1844
1845   // Force the timer used by the animatedImageVisual to tick,
1846   timer.MockEmitSignal();
1847   application.SendNotification();
1848   application.Render();
1849   atlasRectValue = renderer.GetProperty( renderer.GetPropertyIndex( "uAtlasRect" ) );
1850   // take into consideration the half pixel correction
1851   DALI_TEST_EQUALS( atlasRectValue.Get<Vector4>(), Vector4(50.5f, 50.5f, 99.5f, 99.5f)/100.f, Math::MACHINE_EPSILON_100, TEST_LOCATION );
1852
1853   // Test SetOffStage().
1854   actor.Unparent();
1855   DALI_TEST_CHECK( actor.GetRendererCount() == 0u );
1856
1857   END_TEST;
1858 }
1859
1860 int UtcDaliVisualFactoryGetAnimatedImageVisual2(void)
1861 {
1862   ToolkitTestApplication application;
1863   tet_infoline( "UtcDaliVisualFactoryGetAnimatedImageVisual2: Request animated image visual with a Property::Map, test custom wrap mode and pixel area" );
1864
1865   const Vector4 pixelArea(-0.5f, -0.5f, 2.f, 2.f);
1866   Property::Map propertyMap;
1867   propertyMap.Add( Visual::Property::TYPE,  Visual::IMAGE  )
1868              .Add( ImageVisual::Property::URL, TEST_GIF_FILE_NAME  )
1869              .Add( ImageVisual::Property::PIXEL_AREA, pixelArea )
1870              .Add( ImageVisual::Property::WRAP_MODE_U, WrapMode::MIRRORED_REPEAT )
1871              .Add( ImageVisual::Property::WRAP_MODE_V, WrapMode::REPEAT );
1872
1873   Visual::Base visual = VisualFactory::Get().CreateVisual( propertyMap );
1874   DALI_TEST_CHECK( visual );
1875
1876   TestGlAbstraction& gl = application.GetGlAbstraction();
1877   TraceCallStack& textureTrace = gl.GetTextureTrace();
1878   textureTrace.Enable(true);
1879   TraceCallStack& texParameterTrace = gl.GetTexParameterTrace();
1880   texParameterTrace.Enable( true );
1881
1882   DummyControl actor = DummyControl::New();
1883   DummyControlImpl& dummyImpl = static_cast<DummyControlImpl&>(actor.GetImplementation());
1884   dummyImpl.RegisterVisual( Control::CONTROL_PROPERTY_END_INDEX + 1, visual );
1885   actor.SetSize( 200.0f, 200.0f );
1886   Stage::GetCurrent().Add( actor );
1887
1888   application.SendNotification();
1889   application.Render();
1890
1891   DALI_TEST_CHECK( actor.GetRendererCount() == 1u );
1892
1893   DALI_TEST_EQUALS( textureTrace.FindMethod("BindTexture"), true, TEST_LOCATION );
1894
1895   // For animated image visual, the wrapping is handled manually in shader, so the following gl function should not be called
1896   std::stringstream out;
1897   out << GL_TEXTURE_2D << ", " << GL_TEXTURE_WRAP_S << ", " << GL_MIRRORED_REPEAT;
1898   DALI_TEST_CHECK( !texParameterTrace.FindMethodAndParams("TexParameteri", out.str()) );
1899   out.str("");
1900   out << GL_TEXTURE_2D << ", " << GL_TEXTURE_WRAP_T << ", " << GL_REPEAT;
1901   DALI_TEST_CHECK( !texParameterTrace.FindMethodAndParams("TexParameteri", out.str()) );
1902
1903   // test the uniforms which used to handle the wrap mode
1904   Renderer renderer = actor.GetRendererAt( 0u );
1905   DALI_TEST_CHECK( renderer );
1906
1907   Property::Value pixelAreaValue = renderer.GetProperty( renderer.GetPropertyIndex( "pixelArea" ) );
1908   DALI_TEST_EQUALS( pixelAreaValue.Get<Vector4>(), pixelArea, TEST_LOCATION );
1909   Vector4 pixelAreaUniform;
1910   DALI_TEST_CHECK( gl.GetUniformValue<Vector4>( "pixelArea", pixelAreaUniform ) );
1911   DALI_TEST_EQUALS( pixelArea, pixelAreaUniform, Math::MACHINE_EPSILON_100, TEST_LOCATION );
1912
1913   Property::Value wrapModeValue = renderer.GetProperty( renderer.GetPropertyIndex( "wrapMode" ) );
1914   Vector2 wrapMode( WrapMode::MIRRORED_REPEAT-1, WrapMode::REPEAT-1 );
1915   DALI_TEST_EQUALS( wrapModeValue.Get<Vector2>(), wrapMode, TEST_LOCATION );
1916   Vector2 wrapModeUniform;
1917   DALI_TEST_CHECK( gl.GetUniformValue<Vector2>( "wrapMode", wrapModeUniform ) );
1918   DALI_TEST_EQUALS( wrapMode, wrapModeUniform, Math::MACHINE_EPSILON_100, TEST_LOCATION );
1919
1920   actor.Unparent( );
1921   DALI_TEST_CHECK( actor.GetRendererCount() == 0u );
1922
1923   END_TEST;
1924 }