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