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