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