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