Merge "Added support for setting light position in mesh renderer." into devel/master
[platform/core/uifw/dali-toolkit.git] / automated-tests / src / dali-toolkit / utc-Dali-RendererFactory.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/renderer-factory/renderer-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 TestControlRendererRender( ToolkitTestApplication& application,
177                                 Actor& actor,
178                                 ControlRenderer& controlRenderer,
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   controlRenderer.SetSize( Vector2(200.f, 200.f) );
192   controlRenderer.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_renderer_factory_startup(void)
225 {
226   test_return_value = TET_UNDEF;
227 }
228
229 void dali_renderer_factory_cleanup(void)
230 {
231   test_return_value = TET_PASS;
232 }
233
234 int UtcDaliRendererFactoryGet(void)
235 {
236   ToolkitTestApplication application;
237   tet_infoline( "UtcDaliRendererFactory" );
238
239   //Register type
240   TypeInfo type;
241   type = TypeRegistry::Get().GetTypeInfo( "RendererFactory" );
242   DALI_TEST_CHECK( type );
243   BaseHandle handle = type.CreateInstance();
244   DALI_TEST_CHECK( handle );
245
246   RendererFactory factory;
247   factory = RendererFactory::Get();
248   DALI_TEST_CHECK( factory );
249
250   RendererFactory newFactory = RendererFactory::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 UtcDaliRendererFactoryCopyAndAssignment(void)
260 {
261   ToolkitTestApplication application;
262   tet_infoline( "UtcDaliRendererFactoryCopyAndAssignment" );
263   RendererFactory factory = RendererFactory::Get();
264
265   RendererFactory factoryCopy( factory );
266   DALI_TEST_CHECK(factory == factoryCopy);
267
268   RendererFactory emptyFactory;
269   RendererFactory emptyFactoryCopy( emptyFactory );
270   DALI_TEST_CHECK(emptyFactory == emptyFactoryCopy);
271
272   RendererFactory factoryEquals;
273   factoryEquals = factory;
274   DALI_TEST_CHECK(factory == factoryEquals);
275
276   RendererFactory 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 UtcDaliRendererFactoryGetColorRenderer1(void)
288 {
289   ToolkitTestApplication application;
290   tet_infoline( "UtcDaliRendererFactoryGetColorRenderer1:  Request color renderer with a Property::Map" );
291
292   RendererFactory factory = RendererFactory::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   ControlRenderer controlRenderer = factory.CreateControlRenderer(propertyMap);
301   DALI_TEST_CHECK( controlRenderer );
302
303   Actor actor = Actor::New();
304   TestControlRendererRender( application, actor, controlRenderer );
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 UtcDaliRendererFactoryGetColorRenderer2(void)
315 {
316   ToolkitTestApplication application;
317   tet_infoline( "UtcDaliRendererFactoryGetColorRenderer2: Request color renderer with a Vector4" );
318
319   RendererFactory factory = RendererFactory::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   ControlRenderer controlRenderer = factory.CreateControlRenderer( map );
327   DALI_TEST_CHECK( controlRenderer );
328
329   Actor actor = Actor::New();
330   TestControlRendererRender( application, actor, controlRenderer );
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   controlRenderer.SetOffStage( actor );
338   DALI_TEST_CHECK( actor.GetRendererCount() == 0u );
339
340   END_TEST;
341 }
342
343 int UtcDaliRendererFactoryGetBorderRenderer1(void)
344 {
345   ToolkitTestApplication application;
346   tet_infoline( "UtcDaliRendererFactoryGetBorderRenderer1:  Request border renderer with a Property::Map" );
347
348   RendererFactory factory = RendererFactory::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   ControlRenderer controlRenderer = factory.CreateControlRenderer(propertyMap);
359   DALI_TEST_CHECK( controlRenderer );
360
361   Actor actor = Actor::New();
362   actor.SetSize(200.f, 200.f);
363   Stage::GetCurrent().Add( actor );
364   controlRenderer.SetSize(Vector2(200.f, 200.f));
365   controlRenderer.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   controlRenderer.SetOffStage( actor );
385   DALI_TEST_CHECK( actor.GetRendererCount() == 0u );
386
387   END_TEST;
388 }
389
390 int UtcDaliRendererFactoryGetBorderRenderer2(void)
391 {
392   ToolkitTestApplication application;
393   tet_infoline( "UtcDaliRendererFactoryGetBorderRenderer2:  Request border renderer with a borderSize and a borderColor" );
394
395   RendererFactory factory = RendererFactory::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   ControlRenderer controlRenderer = factory.CreateControlRenderer( propertyMap );
406   DALI_TEST_CHECK( controlRenderer );
407
408   Actor actor = Actor::New();
409   actor.SetSize(200.f, 200.f);
410   Stage::GetCurrent().Add( actor );
411   controlRenderer.SetSize(Vector2(200.f, 200.f));
412   controlRenderer.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   controlRenderer.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   controlRenderer = factory.CreateControlRenderer( map );
441   controlRenderer.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 UtcDaliRendererFactoryGetLinearGradientRenderer(void)
452 {
453   ToolkitTestApplication application;
454   tet_infoline("UtcDaliRendererFactoryGetRadialGradientRenderer");
455
456   RendererFactory factory = RendererFactory::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   ControlRenderer controlRenderer = factory.CreateControlRenderer(propertyMap);
479   DALI_TEST_CHECK( controlRenderer );
480
481   // A lookup texture is generated and pass to shader as sampler
482   Actor actor = Actor::New();
483   TestControlRendererRender( application, actor, controlRenderer, 1u );
484
485   controlRenderer.SetOffStage( actor );
486   DALI_TEST_CHECK( actor.GetRendererCount() == 0u );
487
488   END_TEST;
489 }
490
491 int UtcDaliRendererFactoryGetRadialGradientRenderer(void)
492 {
493   ToolkitTestApplication application;
494   tet_infoline("UtcDaliRendererFactoryGetRadialGradientRenderer");
495
496   RendererFactory factory = RendererFactory::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   ControlRenderer controlRenderer = factory.CreateControlRenderer(propertyMap);
519   DALI_TEST_CHECK( controlRenderer );
520
521   // A lookup texture is generated and pass to shader as sampler
522   Actor actor = Actor::New();
523   TestControlRendererRender( application, actor, controlRenderer, 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 UtcDaliRendererFactoryDefaultOffsetsGradientRenderer(void)
537 {
538   ToolkitTestApplication application;
539   tet_infoline("UtcDaliRendererFactoryGetRadialGradientRenderer");
540
541   RendererFactory factory = RendererFactory::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   ControlRenderer controlRenderer = factory.CreateControlRenderer(propertyMap);
559   DALI_TEST_CHECK( controlRenderer );
560
561   // A lookup texture is generated and pass to shader as sampler
562   Actor actor = Actor::New();
563   TestControlRendererRender( application, actor, controlRenderer, 1u );
564
565   controlRenderer.SetOffStage( actor );
566   DALI_TEST_CHECK( actor.GetRendererCount() == 0u );
567
568   END_TEST;
569 }
570
571 int UtcDaliRendererFactoryGetImageRenderer1(void)
572 {
573   ToolkitTestApplication application;
574   tet_infoline( "UtcDaliRendererFactoryGetImageRenderer1: Request image renderer with a Property::Map" );
575
576   RendererFactory factory = RendererFactory::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   ControlRenderer controlRenderer = factory.CreateControlRenderer( propertyMap );
584   DALI_TEST_CHECK( controlRenderer );
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   TestControlRendererRender( application, actor, controlRenderer, 1u,
600                              ImageDimensions(width, height),
601                              Integration::ResourcePointer( bitmap ) );
602
603   DALI_TEST_EQUALS( textureTrace.FindMethod("BindTexture"), true, TEST_LOCATION );
604
605   controlRenderer.SetOffStage( actor );
606   DALI_TEST_CHECK( actor.GetRendererCount() == 0u );
607
608   END_TEST;
609 }
610
611 int UtcDaliRendererFactoryGetImageRenderer2(void)
612 {
613   ToolkitTestApplication application;
614   tet_infoline( "UtcDaliRendererFactoryGetImageRenderer2: Request image renderer with an image handle" );
615
616   RendererFactory factory = RendererFactory::Get();
617   DALI_TEST_CHECK( factory );
618
619   Image image = ResourceImage::New(TEST_IMAGE_FILE_NAME);
620   ControlRenderer controlRenderer = factory.CreateControlRenderer( 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   TestControlRendererRender( application, actor, controlRenderer, 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 UtcDaliRendererFactoryGetNPatchRenderer1(void)
646 {
647   ToolkitTestApplication application;
648   tet_infoline( "UtcDaliRendererFactoryGetNPatchRenderer1: Request 9-patch renderer with a Property::Map" );
649
650   RendererFactory factory = RendererFactory::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     ControlRenderer controlRenderer = factory.CreateControlRenderer( propertyMap );
667     DALI_TEST_CHECK( controlRenderer );
668
669     Actor actor = Actor::New();
670
671     TestGlAbstraction& gl = application.GetGlAbstraction();
672     TraceCallStack& textureTrace = gl.GetTextureTrace();
673     textureTrace.Enable(true);
674
675     TestControlRendererRender( application, actor, controlRenderer, 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     ControlRenderer controlRenderer = factory.CreateControlRenderer( propertyMap );
686     DALI_TEST_CHECK( controlRenderer );
687
688     Actor actor = Actor::New();
689
690     TestGlAbstraction& gl = application.GetGlAbstraction();
691     TraceCallStack& textureTrace = gl.GetTextureTrace();
692     textureTrace.Enable(true);
693
694     TestControlRendererRender( application, actor, controlRenderer, 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 UtcDaliRendererFactoryGetNPatchRenderer2(void)
705 {
706   ToolkitTestApplication application;
707   tet_infoline( "UtcDaliRendererFactoryGetNPatchRenderer2: Request n-patch renderer with a Property::Map" );
708
709   RendererFactory factory = RendererFactory::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     ControlRenderer controlRenderer = factory.CreateControlRenderer( propertyMap );
730     DALI_TEST_CHECK( controlRenderer );
731
732     Actor actor = Actor::New();
733     TestGlAbstraction& gl = application.GetGlAbstraction();
734     TraceCallStack& textureTrace = gl.GetTextureTrace();
735     textureTrace.Enable(true);
736
737     TestControlRendererRender( application, actor, controlRenderer, 1u,
738                                ImageDimensions(ninePatchImageWidth, ninePatchImageHeight),
739                                ninePatchResource );
740
741
742     DALI_TEST_EQUALS( textureTrace.FindMethod("BindTexture"), true, TEST_LOCATION );
743
744     controlRenderer.SetOffStage( actor );
745     DALI_TEST_CHECK( actor.GetRendererCount() == 0u );
746   }
747
748   propertyMap.Insert( "borderOnly",  true );
749   {
750     tet_infoline( "border only" );
751     ControlRenderer controlRenderer = factory.CreateControlRenderer( propertyMap );
752     DALI_TEST_CHECK( controlRenderer );
753
754     TestGlAbstraction& gl = application.GetGlAbstraction();
755     TraceCallStack& textureTrace = gl.GetTextureTrace();
756     textureTrace.Enable(true);
757     Actor actor = Actor::New();
758     TestControlRendererRender( application, actor, controlRenderer, 1u,
759                                ImageDimensions(ninePatchImageWidth, ninePatchImageHeight),
760                                ninePatchResource );
761
762
763     DALI_TEST_EQUALS( textureTrace.FindMethod("BindTexture"), true, TEST_LOCATION );
764
765     controlRenderer.SetOffStage( actor );
766     DALI_TEST_CHECK( actor.GetRendererCount() == 0u );
767   }
768
769   END_TEST;
770 }
771
772 int UtcDaliRendererFactoryGetNPatchRenderer3(void)
773 {
774   ToolkitTestApplication application;
775   tet_infoline( "UtcDaliRendererFactoryGetNPatchRenderer3: Request 9-patch renderer with an image url" );
776
777   RendererFactory factory = RendererFactory::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   ControlRenderer controlRenderer = factory.CreateControlRenderer( TEST_NPATCH_FILE_NAME, ImageDimensions() );
789   DALI_TEST_CHECK( controlRenderer );
790
791   Actor actor = Actor::New();
792
793   TestGlAbstraction& gl = application.GetGlAbstraction();
794   TraceCallStack& textureTrace = gl.GetTextureTrace();
795   textureTrace.Enable(true);
796
797   TestControlRendererRender( application, actor, controlRenderer, 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 UtcDaliRendererFactoryGetNPatchRenderer4(void)
807 {
808   ToolkitTestApplication application;
809   tet_infoline( "UtcDaliRendererFactoryGetNPatchRenderer4: Request n-patch renderer with an image url" );
810
811   RendererFactory factory = RendererFactory::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   ControlRenderer controlRenderer = factory.CreateControlRenderer( TEST_NPATCH_FILE_NAME, ImageDimensions() );
828   DALI_TEST_CHECK( controlRenderer );
829
830   Actor actor = Actor::New();
831
832   TestGlAbstraction& gl = application.GetGlAbstraction();
833   TraceCallStack& textureTrace = gl.GetTextureTrace();
834   textureTrace.Enable(true);
835
836   TestControlRendererRender( application, actor, controlRenderer, 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 UtcDaliRendererFactoryGetNPatchRendererN1(void)
846 {
847   //This should still load but display an error image
848
849   ToolkitTestApplication application;
850   tet_infoline( "UtcDaliRendererFactoryGetNPatchRendererN: Request n-patch renderer with an invalid image url" );
851
852   RendererFactory factory = RendererFactory::Get();
853   DALI_TEST_CHECK( factory );
854
855   ControlRenderer controlRenderer = factory.CreateControlRenderer( "ERROR.9.jpg", ImageDimensions() );
856   DALI_TEST_CHECK( controlRenderer );
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   TestControlRendererRender( application, actor, controlRenderer, 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 UtcDaliRendererFactoryGetNPatchRendererN2(void)
878 {
879   //This should still load but display an error image
880
881   ToolkitTestApplication application;
882   tet_infoline( "UtcDaliRendererFactoryGetNPatchRendererN: Request n-patch renderer with an invalid Property::Map" );
883
884   RendererFactory factory = RendererFactory::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   ControlRenderer controlRenderer = factory.CreateControlRenderer( propertyMap );
892   DALI_TEST_CHECK( controlRenderer );
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   TestControlRendererRender( application, actor, controlRenderer, 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 UtcDaliRendererFactoryGetSvgRenderer(void)
914 {
915   ToolkitTestApplication application;
916   tet_infoline( "UtcDaliRendererFactoryGetSvgRenderer: Request svg renderer with a svg url" );
917
918   RendererFactory factory = RendererFactory::Get();
919   ControlRenderer controlRenderer = factory.CreateControlRenderer( TEST_SVG_FILE_NAME, ImageDimensions() );
920   DALI_TEST_CHECK( controlRenderer );
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   controlRenderer.SetSize( Vector2(200.f, 200.f) );
930   controlRenderer.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 MeshRendererLoadsCorrectlyTest( Property::Map& propertyMap, ToolkitTestApplication& application )
956 {
957   RendererFactory factory = RendererFactory::Get();
958   DALI_TEST_CHECK( factory );
959
960   //Create a mesh renderer.
961   ControlRenderer controlRenderer = factory.CreateControlRenderer( propertyMap );
962   DALI_TEST_CHECK( controlRenderer );
963
964   //Create an actor on stage to house the renderer.
965   Actor actor = Actor::New();
966   actor.SetSize( 200.f, 200.f );
967   Stage::GetCurrent().Add( actor );
968   controlRenderer.SetSize( Vector2( 200.f, 200.f ) );
969   controlRenderer.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   controlRenderer.SetOffStage( actor );
996   DALI_TEST_EQUALS( actor.GetRendererCount(), 0u, TEST_LOCATION );
997 }
998
999 //Creates a mesh renderer 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 MeshRendererDoesNotLoadCorrectlyTest( Property::Map& propertyMap, ToolkitTestApplication& application )
1002 {
1003   RendererFactory factory = RendererFactory::Get();
1004   DALI_TEST_CHECK( factory );
1005
1006   //Create a mesh renderer.
1007   ControlRenderer controlRenderer = factory.CreateControlRenderer( propertyMap );
1008   DALI_TEST_CHECK( controlRenderer );
1009
1010   //Create an actor on stage to house the renderer.
1011   Actor actor = Actor::New();
1012   actor.SetSize( 200.f, 200.f );
1013   Stage::GetCurrent().Add( actor );
1014   controlRenderer.SetSize( Vector2( 200.f, 200.f ) );
1015   controlRenderer.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   controlRenderer.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 UtcDaliRendererFactoryGetMeshRenderer1(void)
1043 {
1044   //Set up test application first, so everything else can be handled.
1045   ToolkitTestApplication application;
1046
1047   tet_infoline( "UtcDaliRendererFactoryGetMeshRenderer1:  Request mesh renderer with a valid object file only" );
1048
1049   //Set up renderer properties.
1050   Property::Map propertyMap;
1051   propertyMap.Insert( "rendererType",  "MESH" );
1052   propertyMap.Insert( "objectUrl", TEST_OBJ_FILE_NAME );
1053
1054   //Test to see if mesh loads correctly.
1055   MeshRendererLoadsCorrectlyTest( propertyMap, application );
1056
1057   END_TEST;
1058 }
1059
1060 //Test if mesh loads correctly when supplied with an object file as well as a blank material file and images directory.
1061 int UtcDaliRendererFactoryGetMeshRenderer2(void)
1062 {
1063   //Set up test application first, so everything else can be handled.
1064   ToolkitTestApplication application;
1065
1066   tet_infoline( "UtcDaliRendererFactoryGetMeshRenderer2:  Request mesh renderer with blank material file and images directory" );
1067
1068   //Set up renderer properties.
1069   Property::Map propertyMap;
1070   propertyMap.Insert( "rendererType", "MESH" );
1071   propertyMap.Insert( "objectUrl", TEST_OBJ_FILE_NAME );
1072   propertyMap.Insert( "materialUrl", "" );
1073   propertyMap.Insert( "texturesPath", "" );
1074
1075   //Test to see if mesh loads correctly.
1076   MeshRendererLoadsCorrectlyTest( propertyMap, application );
1077
1078   END_TEST;
1079 }
1080
1081 //Test if mesh loads correctly when supplied with all main parameters, an object file, a material file and a directory location.
1082 int UtcDaliRendererFactoryGetMeshRenderer3(void)
1083 {
1084   //Set up test application first, so everything else can be handled.
1085   ToolkitTestApplication application;
1086
1087   tet_infoline( "UtcDaliRendererFactoryGetMeshRenderer3:  Request mesh renderer with all parameters correct" );
1088
1089   //Set up renderer properties.
1090   Property::Map propertyMap;
1091   propertyMap.Insert( "rendererType", "MESH" );
1092   propertyMap.Insert( "objectUrl", TEST_OBJ_FILE_NAME );
1093   propertyMap.Insert( "materialUrl", TEST_MTL_FILE_NAME );
1094   propertyMap.Insert( "texturesPath", TEST_RESOURCE_DIR "/" );
1095
1096   //Test to see if mesh loads correctly.
1097   MeshRendererLoadsCorrectlyTest( propertyMap, application );
1098
1099   END_TEST;
1100 }
1101
1102 //Test if mesh renderer can load a correctly supplied mesh without a normal map or gloss map in the material file.
1103 int UtcDaliRendererFactoryGetMeshRenderer4(void)
1104 {
1105   //Set up test application first, so everything else can be handled.
1106   ToolkitTestApplication application;
1107
1108   tet_infoline( "UtcDaliRendererFactoryGetMeshRenderer4:  Request mesh renderer with diffuse texture but not normal or gloss." );
1109
1110   //Set up renderer properties.
1111   Property::Map propertyMap;
1112   propertyMap.Insert( "rendererType", "MESH" );
1113   propertyMap.Insert( "objectUrl", TEST_OBJ_FILE_NAME );
1114   propertyMap.Insert( "materialUrl", TEST_SIMPLE_MTL_FILE_NAME );
1115   propertyMap.Insert( "texturesPath", TEST_RESOURCE_DIR "/" );
1116
1117   //Test to see if mesh loads correctly.
1118   MeshRendererLoadsCorrectlyTest( propertyMap, application );
1119
1120   END_TEST;
1121 }
1122
1123 //Test if mesh renderer can load when made to use diffuse textures only.
1124 int UtcDaliRendererFactoryGetMeshRenderer5(void)
1125 {
1126   //Set up test application first, so everything else can be handled.
1127   ToolkitTestApplication application;
1128
1129   tet_infoline( "UtcDaliRendererFactoryGetMeshRenderer5:  Request mesh renderer and make it only use diffuse textures." );
1130
1131   //Set up renderer properties.
1132   Property::Map propertyMap;
1133   propertyMap.Insert( "rendererType", "MESH" );
1134   propertyMap.Insert( "objectUrl", TEST_OBJ_FILE_NAME );
1135   propertyMap.Insert( "materialUrl", TEST_MTL_FILE_NAME );
1136   propertyMap.Insert( "texturesPath", TEST_RESOURCE_DIR "/" );
1137   propertyMap.Insert( "shaderType", "DIFFUSE_TEXTURE" );
1138
1139   //Test to see if mesh loads correctly.
1140   MeshRendererLoadsCorrectlyTest( propertyMap, application );
1141
1142   END_TEST;
1143 }
1144
1145 //Test if mesh renderer can load when made to not use the supplied textures.
1146 int UtcDaliRendererFactoryGetMeshRenderer6(void)
1147 {
1148   //Set up test application first, so everything else can be handled.
1149   ToolkitTestApplication application;
1150
1151   tet_infoline( "UtcDaliRendererFactoryGetMeshRenderer6:  Request mesh renderer and make it not use any textures." );
1152
1153   //Set up renderer properties.
1154   Property::Map propertyMap;
1155   propertyMap.Insert( "rendererType", "MESH" );
1156   propertyMap.Insert( "objectUrl", TEST_OBJ_FILE_NAME );
1157   propertyMap.Insert( "materialUrl", TEST_MTL_FILE_NAME );
1158   propertyMap.Insert( "texturesPath", TEST_RESOURCE_DIR "/" );
1159   propertyMap.Insert( "shaderType", "TEXTURELESS" );
1160
1161   //Test to see if mesh loads correctly.
1162   MeshRendererLoadsCorrectlyTest( propertyMap, application );
1163
1164   END_TEST;
1165 }
1166 //Test if mesh renderer loads correctly when light position is manually set.
1167 int UtcDaliRendererFactoryGetMeshRenderer7(void)
1168 {
1169   //Set up test application first, so everything else can be handled.
1170   ToolkitTestApplication application;
1171
1172   tet_infoline( "UtcDaliRendererFactoryGetMeshRenderer7:  Request mesh renderer with custom light position." );
1173
1174   //Set up renderer properties.
1175   Property::Map propertyMap;
1176   propertyMap.Insert( "rendererType", "MESH" );
1177   propertyMap.Insert( "objectUrl", TEST_OBJ_FILE_NAME );
1178   propertyMap.Insert( "materialUrl", TEST_MTL_FILE_NAME );
1179   propertyMap.Insert( "texturesPath", TEST_RESOURCE_DIR "/" );
1180   propertyMap.Insert( "lightPosition", Vector3( 0.0, 1.0, 2.0 ) );
1181
1182   //Test to see if mesh loads correctly.
1183   MeshRendererLoadsCorrectlyTest( propertyMap, application );
1184
1185   END_TEST;
1186 }
1187
1188 //Test if mesh renderer loads correctly when supplied an object file without face normals or texture points.
1189 //Note that this notably tests object loader functionality.
1190 int UtcDaliRendererFactoryGetMeshRenderer8(void)
1191 {
1192   //Set up test application first, so everything else can be handled.
1193   ToolkitTestApplication application;
1194
1195   tet_infoline( "UtcDaliRendererFactoryGetMeshRenderer5:  Request mesh renderer with normal-less object file." );
1196
1197   //Set up renderer properties.
1198   Property::Map propertyMap;
1199   propertyMap.Insert( "rendererType", "MESH" );
1200   propertyMap.Insert( "objectUrl", TEST_SIMPLE_OBJ_FILE_NAME );
1201   propertyMap.Insert( "materialUrl", TEST_MTL_FILE_NAME );
1202   propertyMap.Insert( "texturesPath", TEST_RESOURCE_DIR "/" );
1203
1204   //Test to see if mesh loads correctly.
1205   MeshRendererLoadsCorrectlyTest( propertyMap, application );
1206
1207   END_TEST;
1208 }
1209
1210 //Test if mesh renderer handles the case of lacking an object file.
1211 int UtcDaliRendererFactoryGetMeshRendererN1(void)
1212 {
1213   //Set up test application first, so everything else can be handled.
1214   ToolkitTestApplication application;
1215
1216   tet_infoline( "UtcDaliRendererFactoryGetMeshRendererN1:  Request mesh renderer without object file" );
1217
1218   //Set up renderer properties.
1219   Property::Map propertyMap;
1220   propertyMap.Insert( "rendererType", "MESH" );
1221   propertyMap.Insert( "materialUrl", TEST_MTL_FILE_NAME );
1222   propertyMap.Insert( "texturesPath", TEST_RESOURCE_DIR "/" );
1223
1224   //Test to see if mesh doesn't load with these properties, as expected.
1225   MeshRendererDoesNotLoadCorrectlyTest( propertyMap, application );
1226
1227   END_TEST;
1228 }
1229
1230 //Test if mesh renderer handles the case of being passed invalid material and images urls.
1231 int UtcDaliRendererFactoryGetMeshRendererN2(void)
1232 {
1233   //Set up test application first, so everything else can be handled.
1234   ToolkitTestApplication application;
1235
1236   tet_infoline( "UtcDaliRendererFactoryGetMeshRendererN2:  Request mesh renderer with invalid material and images urls" );
1237
1238   //Set up renderer properties.
1239   Property::Map propertyMap;
1240   propertyMap.Insert( "rendererType", "MESH" );
1241   propertyMap.Insert( "objectUrl", TEST_OBJ_FILE_NAME );
1242   propertyMap.Insert( "materialUrl", "invalid" );
1243   propertyMap.Insert( "texturesPath", "also invalid" );
1244
1245   //Test to see if mesh doesn't load with these properties, as expected.
1246   MeshRendererDoesNotLoadCorrectlyTest( propertyMap, application );
1247
1248   END_TEST;
1249 }
1250
1251 //Test if mesh renderer handles the case of being passed an invalid object url
1252 int UtcDaliRendererFactoryGetMeshRendererN3(void)
1253 {
1254   //Set up test application first, so everything else can be handled.
1255   ToolkitTestApplication application;
1256
1257   tet_infoline( "UtcDaliRendererFactoryGetMeshRendererN3:  Request mesh renderer with invalid object url" );
1258
1259   //Set up renderer properties.
1260   Property::Map propertyMap;
1261   propertyMap.Insert( "rendererType", "MESH" );
1262   propertyMap.Insert( "objectUrl", "invalid" );
1263   propertyMap.Insert( "materialUrl", TEST_MTL_FILE_NAME );
1264   propertyMap.Insert( "texturesPath", TEST_RESOURCE_DIR "/" );
1265
1266   //Test to see if mesh doesn't load with these properties, as expected.
1267   MeshRendererDoesNotLoadCorrectlyTest( propertyMap, application );
1268
1269   END_TEST;
1270 }
1271
1272 //Creates a primitive renderer with the given property map and tests to see if it correctly loads in the given application.
1273 void TestPrimitiveRendererWithProperties( Property::Map& propertyMap, ToolkitTestApplication& application )
1274 {
1275   RendererFactory factory = RendererFactory::Get();
1276   DALI_TEST_CHECK( factory );
1277
1278   //Create a primitive renderer.
1279   ControlRenderer controlRenderer = factory.CreateControlRenderer( propertyMap );
1280   DALI_TEST_CHECK( controlRenderer );
1281
1282   //Create an actor on stage to house the renderer.
1283   Actor actor = Actor::New();
1284   actor.SetSize( 200.f, 200.f );
1285   Stage::GetCurrent().Add( actor );
1286   controlRenderer.SetSize( Vector2( 200.f, 200.f ) );
1287   controlRenderer.SetOnStage( actor );
1288
1289   //Ensure set on stage.
1290   DALI_TEST_EQUALS( actor.GetRendererCount(), 1u, TEST_LOCATION );
1291
1292   //Tell test application to load the renderer.
1293   application.SendNotification();
1294   application.Render(0);
1295
1296   Matrix testScaleMatrix;
1297   testScaleMatrix.SetIdentityAndScale( Vector3( 1.0, -1.0, 1.0 ) );
1298   Matrix actualScaleMatrix;
1299
1300   //Test to see if the object has been successfully loaded.
1301   DALI_TEST_CHECK( application.GetGlAbstraction().GetUniformValue<Matrix>( "uObjectMatrix", actualScaleMatrix ) );
1302   DALI_TEST_EQUALS( actualScaleMatrix, testScaleMatrix, Math::MACHINE_EPSILON_100, TEST_LOCATION );
1303
1304   //Finish by setting off stage, and ensuring this was successful.
1305   controlRenderer.SetOffStage( actor );
1306   DALI_TEST_EQUALS( actor.GetRendererCount(), 0u, TEST_LOCATION );
1307 }
1308
1309 //Test if primitive shape loads correctly when supplied with only the bare minimum requirements, the shape to use.
1310 int UtcDaliRendererFactoryGetPrimitiveRenderer1(void)
1311 {
1312   //Set up test application first, so everything else can be handled.
1313   ToolkitTestApplication application;
1314
1315   tet_infoline( "UtcDaliRendererFactoryGetPrimitiveRenderer1:  Request primitive renderer with a shape only" );
1316
1317   //Set up renderer properties.
1318   Property::Map propertyMap;
1319   propertyMap.Insert( "rendererType", "PRIMITIVE" );
1320   propertyMap.Insert( "shape", "CUBE" );
1321
1322   //Test to see if shape loads correctly.
1323   TestPrimitiveRendererWithProperties( propertyMap, application );
1324
1325   END_TEST;
1326 }
1327
1328 //Test if primitive shape loads correctly when supplied with all possible parameters
1329 int UtcDaliRendererFactoryGetPrimitiveRenderer2(void)
1330 {
1331   //Set up test application first, so everything else can be handled.
1332   ToolkitTestApplication application;
1333
1334   tet_infoline( "UtcDaliRendererFactoryGetPrimitiveRenderer2:  Request primitive renderer with everything" );
1335
1336   //Set up renderer properties.
1337   Property::Map propertyMap;
1338   propertyMap.Insert( "rendererType", "PRIMITIVE" );
1339   propertyMap.Insert( "shape", "CUBE" );
1340   propertyMap.Insert( "shapeColor", Vector4( 0.5, 0.5, 0.5, 1.0 ) );
1341   propertyMap.Insert( "slices", 10 );
1342   propertyMap.Insert( "stacks", 20 );
1343   propertyMap.Insert( "scaleTopRadius", 30.0f );
1344   propertyMap.Insert( "scaleBottomRadius", 40.0f );
1345   propertyMap.Insert( "scaleHeight", 50.0f );
1346   propertyMap.Insert( "scaleRadius", 60.0f );
1347   propertyMap.Insert( "bevelPercentage", 0.7f );
1348   propertyMap.Insert( "bevelSmoothness", 0.8f );
1349   propertyMap.Insert( "lightPosition", Vector3( 0.9, 1.0, 1.1 ) );
1350
1351   //Test to see if shape loads correctly.
1352   TestPrimitiveRendererWithProperties( propertyMap, application );
1353
1354   END_TEST;
1355 }
1356
1357 //Test if primitive shape loads a sphere correctly.
1358 int UtcDaliRendererFactoryGetPrimitiveRenderer3(void)
1359 {
1360   //Set up test application first, so everything else can be handled.
1361   ToolkitTestApplication application;
1362
1363   tet_infoline( "UtcDaliRendererFactoryGetPrimitiveRenderer3:  Request primitive renderer to display a sphere" );
1364
1365   //Set up renderer properties.
1366   Property::Map propertyMap;
1367   propertyMap.Insert( "rendererType", "PRIMITIVE" );
1368   propertyMap.Insert( "shape", "SPHERE" );
1369   propertyMap.Insert( "shapeColor", Vector4( 0.5, 0.5, 0.5, 1.0 ) );
1370   propertyMap.Insert( "slices", 10 );
1371   propertyMap.Insert( "stacks", 20 );
1372
1373   //Test to see if shape loads correctly.
1374   TestPrimitiveRendererWithProperties( propertyMap, application );
1375
1376   END_TEST;
1377 }
1378
1379 //Test if primitive shape loads a conic section correctly.
1380 int UtcDaliRendererFactoryGetPrimitiveRenderer4(void)
1381 {
1382   //Set up test application first, so everything else can be handled.
1383   ToolkitTestApplication application;
1384
1385   tet_infoline( "UtcDaliRendererFactoryGetPrimitiveRenderer4:  Request primitive renderer to display a conic section" );
1386
1387   //Set up renderer properties.
1388   Property::Map propertyMap;
1389   propertyMap.Insert( "rendererType", "PRIMITIVE" );
1390   propertyMap.Insert( "shape", "CONICAL_FRUSTRUM" );
1391   propertyMap.Insert( "shapeColor", Vector4( 0.5, 0.5, 0.5, 1.0 ) );
1392   propertyMap.Insert( "slices", 10 );
1393   propertyMap.Insert( "scaleTopRadius", 30.0f );
1394   propertyMap.Insert( "scaleBottomRadius", 40.0f );
1395   propertyMap.Insert( "scaleHeight", 50.0f );
1396
1397   //Test to see if shape loads correctly.
1398   TestPrimitiveRendererWithProperties( propertyMap, application );
1399
1400   END_TEST;
1401 }
1402
1403 //Test if primitive shape loads a bevelled cube correctly.
1404 int UtcDaliRendererFactoryGetPrimitiveRenderer5(void)
1405 {
1406   //Set up test application first, so everything else can be handled.
1407   ToolkitTestApplication application;
1408
1409   tet_infoline( "UtcDaliRendererFactoryGetPrimitiveRenderer5:  Request primitive renderer to display a bevelled cube" );
1410
1411   //Set up renderer properties.
1412   Property::Map propertyMap;
1413   propertyMap.Insert( "rendererType", "PRIMITIVE" );
1414   propertyMap.Insert( "shape", "BEVELLED_CUBE" );
1415   propertyMap.Insert( "shapeColor", Vector4( 0.5, 0.5, 0.5, 1.0 ) );
1416   propertyMap.Insert( "bevelPercentage", 0.7f );
1417
1418   //Test to see if shape loads correctly.
1419   TestPrimitiveRendererWithProperties( propertyMap, application );
1420
1421   END_TEST;
1422 }
1423
1424 //Test if primitive shape loads an octahedron correctly.
1425 int UtcDaliRendererFactoryGetPrimitiveRenderer6(void)
1426 {
1427   //Set up test application first, so everything else can be handled.
1428   ToolkitTestApplication application;
1429
1430   tet_infoline( "UtcDaliRendererFactoryGetPrimitiveRenderer6:  Request primitive renderer to display an octahedron" );
1431
1432   //Set up renderer properties.
1433   Property::Map propertyMap;
1434   propertyMap.Insert( "rendererType", "PRIMITIVE" );
1435   propertyMap.Insert( "shape", "OCTAHEDRON" );
1436   propertyMap.Insert( "shapeColor", Vector4( 0.5, 0.5, 0.5, 1.0 ) );
1437
1438   //Test to see if shape loads correctly.
1439   TestPrimitiveRendererWithProperties( propertyMap, application );
1440
1441   END_TEST;
1442 }
1443
1444 //Test if primitive shape loads a cone correctly.
1445 int UtcDaliRendererFactoryGetPrimitiveRenderer7(void)
1446 {
1447   //Set up test application first, so everything else can be handled.
1448   ToolkitTestApplication application;
1449
1450   tet_infoline( "UtcDaliRendererFactoryGetPrimitiveRenderer7:  Request primitive renderer to display a cone" );
1451
1452   //Set up renderer properties.
1453   Property::Map propertyMap;
1454   propertyMap.Insert( "rendererType", "PRIMITIVE" );
1455   propertyMap.Insert( "shape", "CONE" );
1456   propertyMap.Insert( "shapeColor", Vector4( 0.5, 0.5, 0.5, 1.0 ) );
1457   propertyMap.Insert( "slices", 10 );
1458   propertyMap.Insert( "scaleTopRadius", 30.0f );
1459   propertyMap.Insert( "scaleHeight", 50.0f );
1460
1461   //Test to see if shape loads correctly.
1462   TestPrimitiveRendererWithProperties( propertyMap, application );
1463
1464   END_TEST;
1465 }
1466
1467 //Test if primitive shape loads correctly when light position is manually set.
1468 int UtcDaliRendererFactoryGetPrimitiveRenderer8(void)
1469 {
1470   //Set up test application first, so everything else can be handled.
1471   ToolkitTestApplication application;
1472
1473   tet_infoline( "UtcDaliRendererFactoryGetPrimitiveRenderer8:  Request primitive renderer with set light position" );
1474
1475   //Set up renderer properties.
1476   Property::Map propertyMap;
1477   propertyMap.Insert( "rendererType", "PRIMITIVE" );
1478   propertyMap.Insert( "shape", "SPHERE" );
1479   propertyMap.Insert( "shapeColor", Vector4( 0.5, 0.5, 0.5, 1.0 ) );
1480   propertyMap.Insert( "lightPosition", Vector3( 0.0, 1.0, 2.0 ) );
1481
1482   //Test to see if shape loads correctly.
1483   TestPrimitiveRendererWithProperties( propertyMap, application );
1484
1485   END_TEST;
1486 }
1487
1488 //Test if primitive shape renderer handles the case of not being passed a specific shape to use.
1489 int UtcDaliRendererFactoryGetPrimitiveRendererN1(void)
1490 {
1491   //Set up test application first, so everything else can be handled.
1492   ToolkitTestApplication application;
1493
1494   tet_infoline( "UtcDaliRendererFactoryGetPrimitiveRendererN1:  Request primitive renderer without shape" );
1495
1496   //Set up renderer properties, without supplying shape.
1497   Property::Map propertyMap;
1498   propertyMap.Insert( "rendererType", "PRIMITIVE" );
1499
1500   //Test to see if shape loads regardless of missing input.
1501   TestPrimitiveRendererWithProperties( propertyMap, application );
1502
1503   END_TEST;
1504 }