2 * Copyright (c) 2016 Samsung Electronics Co., Ltd.
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
8 * http://www.apache.org/licenses/LICENSE-2.0
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.
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>
27 using namespace Dali::Toolkit;
31 typedef NinePatchImage::StretchRanges StretchRanges;
33 const char* TEST_IMAGE_FILE_NAME = "gallery_image_01.jpg";
34 const char* TEST_NPATCH_FILE_NAME = "gallery_image_01.9.png";
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";
42 Integration::Bitmap* CreateBitmap( unsigned int imageWidth, unsigned int imageHeight, unsigned int initialColor, Pixel::Format pixelFormat )
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 );
48 memset( pixbuffer, initialColor, imageHeight * imageWidth * bytesPerPixel );
53 void InitialiseRegionsToZeroAlpha( Integration::Bitmap* image, unsigned int imageWidth, unsigned int imageHeight, Pixel::Format pixelFormat )
55 PixelBuffer* pixbuffer = image->GetBuffer();
56 unsigned int bytesPerPixel = GetBytesPerPixel( pixelFormat );
58 for( unsigned int row = 0; row < imageWidth; ++row )
60 unsigned int pixelOffset = row * bytesPerPixel;
61 pixbuffer[ pixelOffset + 3 ] = 0x00;
62 pixelOffset += ( imageHeight - 1 ) * imageWidth * bytesPerPixel;
63 pixbuffer[ pixelOffset + 3 ] = 0x00;
66 for ( unsigned int column = 0; column < imageHeight; ++column )
68 unsigned int pixelOffset = column * imageWidth * bytesPerPixel;
69 pixbuffer[ pixelOffset + 3 ] = 0x00;
70 pixelOffset += ( imageWidth -1 ) * bytesPerPixel;
71 pixbuffer[ pixelOffset + 3 ] = 0x00;
75 void AddStretchRegionsToImage( Integration::Bitmap* image, unsigned int imageWidth, unsigned int imageHeight, const StretchRanges& stretchRangesX, const StretchRanges& stretchRangesY, Pixel::Format pixelFormat )
77 PixelBuffer* pixbuffer = image->GetBuffer();
78 unsigned int bytesPerPixel = GetBytesPerPixel( pixelFormat );
80 for(StretchRanges::ConstIterator it = stretchRangesX.Begin(); it != stretchRangesX.End(); ++it)
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 )
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;
95 for(StretchRanges::ConstIterator it = stretchRangesY.Begin(); it != stretchRangesY.End(); ++it)
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 )
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;
110 void AddChildRegionsToImage( Integration::Bitmap* image, unsigned int imageWidth, unsigned int imageHeight, const Vector4& requiredChildRegion, Pixel::Format pixelFormat )
112 PixelBuffer* pixbuffer = image->GetBuffer();
113 unsigned int bytesPerPixel = GetBytesPerPixel( pixelFormat );
115 Integration::Bitmap::PackedPixelsProfile* srcProfile = image->GetPackedPixelsProfile();
116 unsigned int bufferStride = srcProfile->GetBufferStride();
118 // Add bottom child region
119 for( unsigned int column = requiredChildRegion.x; column < imageWidth - requiredChildRegion.z; ++column )
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;
129 // Add right child region
130 for ( unsigned int row = requiredChildRegion.y; row < imageHeight - requiredChildRegion.w; ++row )
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;
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 )
148 TestPlatformAbstraction& platform = application.GetPlatform();
150 Pixel::Format pixelFormat = Pixel::RGBA8888;
152 tet_infoline("Create Bitmap");
153 platform.SetClosestImageSize(Vector2( ninePatchImageWidth, ninePatchImageHeight));
154 Integration::Bitmap* bitmap = CreateBitmap( ninePatchImageWidth, ninePatchImageHeight, 0xFF, pixelFormat );
156 tet_infoline("Clear border regions");
157 InitialiseRegionsToZeroAlpha( bitmap, ninePatchImageWidth, ninePatchImageHeight, pixelFormat );
159 tet_infoline("Add Stretch regions to Bitmap");
160 AddStretchRegionsToImage( bitmap, ninePatchImageWidth, ninePatchImageHeight, stretchRangesX, stretchRangesY, pixelFormat );
164 tet_infoline("Add Child regions to Bitmap");
165 AddChildRegionsToImage( bitmap, ninePatchImageWidth, ninePatchImageHeight, requiredChildRegion, pixelFormat );
168 tet_infoline("Getting resource");
169 Integration::ResourcePointer resourcePtr(bitmap);
170 //platform.SetResourceLoaded( 0, Dali::Integration::ResourceBitmap, resourcePtr );
171 platform.SetSynchronouslyLoadedResource( resourcePtr);
176 void TestControlRendererRender( ToolkitTestApplication& application,
178 ControlRenderer& controlRenderer,
179 std::size_t expectedSamplers = 0,
180 ImageDimensions imageDimensions = ImageDimensions(),
181 Integration::ResourcePointer resourcePtr = Integration::ResourcePointer())
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()) );
189 actor.SetSize( 200.f, 200.f );
190 Stage::GetCurrent().Add( actor );
191 controlRenderer.SetSize( Vector2(200.f, 200.f) );
192 controlRenderer.SetOnStage( actor );
194 DALI_TEST_CHECK( actor.GetRendererCount() == 1u );
196 application.SendNotification();
197 application.Render();
201 Integration::ResourceRequest* request = application.GetPlatform().GetRequest();
204 application.GetPlatform().SetResourceLoaded(request->GetId(), request->GetType()->id, resourcePtr );
208 application.Render();
209 application.SendNotification();
213 DALI_TEST_CHECK( application.GetPlatform().WasCalled(TestPlatformAbstraction::LoadResourceFunc) ||
214 application.GetPlatform().WasCalled(TestPlatformAbstraction::LoadResourceSynchronouslyFunc ));
217 DALI_TEST_CHECK( actor.GetRendererCount() == 1u );
224 void dali_renderer_factory_startup(void)
226 test_return_value = TET_UNDEF;
229 void dali_renderer_factory_cleanup(void)
231 test_return_value = TET_PASS;
234 int UtcDaliRendererFactoryGet(void)
236 ToolkitTestApplication application;
237 tet_infoline( "UtcDaliRendererFactory" );
241 type = TypeRegistry::Get().GetTypeInfo( "RendererFactory" );
242 DALI_TEST_CHECK( type );
243 BaseHandle handle = type.CreateInstance();
244 DALI_TEST_CHECK( handle );
246 RendererFactory factory;
247 factory = RendererFactory::Get();
248 DALI_TEST_CHECK( factory );
250 RendererFactory newFactory = RendererFactory::Get();
251 DALI_TEST_CHECK( newFactory );
253 // Check that renderer factory is a singleton
254 DALI_TEST_CHECK(factory == newFactory);
259 int UtcDaliRendererFactoryCopyAndAssignment(void)
261 ToolkitTestApplication application;
262 tet_infoline( "UtcDaliRendererFactoryCopyAndAssignment" );
263 RendererFactory factory = RendererFactory::Get();
265 RendererFactory factoryCopy( factory );
266 DALI_TEST_CHECK(factory == factoryCopy);
268 RendererFactory emptyFactory;
269 RendererFactory emptyFactoryCopy( emptyFactory );
270 DALI_TEST_CHECK(emptyFactory == emptyFactoryCopy);
272 RendererFactory factoryEquals;
273 factoryEquals = factory;
274 DALI_TEST_CHECK(factory == factoryEquals);
276 RendererFactory emptyFactoryEquals;
277 emptyFactoryEquals = emptyFactory;
278 DALI_TEST_CHECK( emptyFactory == emptyFactoryEquals );
282 DALI_TEST_CHECK( factory = factoryCopy );
287 int UtcDaliRendererFactoryGetColorRenderer1(void)
289 ToolkitTestApplication application;
290 tet_infoline( "UtcDaliRendererFactoryGetColorRenderer1: Request color renderer with a Property::Map" );
292 RendererFactory factory = RendererFactory::Get();
293 DALI_TEST_CHECK( factory );
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);
300 ControlRenderer controlRenderer = factory.CreateControlRenderer(propertyMap);
301 DALI_TEST_CHECK( controlRenderer );
303 Actor actor = Actor::New();
304 TestControlRendererRender( application, actor, controlRenderer );
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 );
314 int UtcDaliRendererFactoryGetColorRenderer2(void)
316 ToolkitTestApplication application;
317 tet_infoline( "UtcDaliRendererFactoryGetColorRenderer2: Request color renderer with a Vector4" );
319 RendererFactory factory = RendererFactory::Get();
320 DALI_TEST_CHECK( factory );
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 );
329 Actor actor = Actor::New();
330 TestControlRendererRender( application, actor, controlRenderer );
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 );
337 controlRenderer.SetOffStage( actor );
338 DALI_TEST_CHECK( actor.GetRendererCount() == 0u );
343 int UtcDaliRendererFactoryGetBorderRenderer1(void)
345 ToolkitTestApplication application;
346 tet_infoline( "UtcDaliRendererFactoryGetBorderRenderer1: Request border renderer with a Property::Map" );
348 RendererFactory factory = RendererFactory::Get();
349 DALI_TEST_CHECK( factory );
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);
358 ControlRenderer controlRenderer = factory.CreateControlRenderer(propertyMap);
359 DALI_TEST_CHECK( controlRenderer );
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 );
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 );
371 TestGlAbstraction& gl = application.GetGlAbstraction();
373 application.SendNotification();
374 application.Render(0);
376 Vector4 actualColor(Vector4::ZERO);
377 DALI_TEST_CHECK( gl.GetUniformValue<Vector4>( "borderColor", actualColor ) );
378 DALI_TEST_EQUALS( actualColor, testColor, TEST_LOCATION );
380 float actualSize = 0.f;
381 DALI_TEST_CHECK( gl.GetUniformValue<float>( "borderSize", actualSize ) );
382 DALI_TEST_EQUALS( actualSize, testSize, TEST_LOCATION );
384 controlRenderer.SetOffStage( actor );
385 DALI_TEST_CHECK( actor.GetRendererCount() == 0u );
390 int UtcDaliRendererFactoryGetBorderRenderer2(void)
392 ToolkitTestApplication application;
393 tet_infoline( "UtcDaliRendererFactoryGetBorderRenderer2: Request border renderer with a borderSize and a borderColor" );
395 RendererFactory factory = RendererFactory::Get();
396 DALI_TEST_CHECK( factory );
398 Vector4 testColor( 1.f, 0.5f, 0.3f, 1.f );
399 float testSize = 5.f;
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 );
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 );
414 DALI_TEST_CHECK( actor.GetRendererCount() == 1u );
416 TestGlAbstraction& gl = application.GetGlAbstraction();
418 application.SendNotification();
419 application.Render(0);
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 );
424 Vector4 actualColor(Vector4::ZERO);
425 DALI_TEST_CHECK( gl.GetUniformValue<Vector4>( "borderColor", actualColor ) );
426 DALI_TEST_EQUALS( actualColor, testColor, TEST_LOCATION );
428 float actualSize = 0.f;
429 DALI_TEST_CHECK( gl.GetUniformValue<float>( "borderSize", actualSize ) );
430 DALI_TEST_EQUALS( actualSize, testSize, TEST_LOCATION );
432 controlRenderer.SetOffStage( actor );
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 );
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 );
451 int UtcDaliRendererFactoryGetLinearGradientRenderer(void)
453 ToolkitTestApplication application;
454 tet_infoline("UtcDaliRendererFactoryGetRadialGradientRenderer");
456 RendererFactory factory = RendererFactory::Get();
457 DALI_TEST_CHECK( factory );
459 Property::Map propertyMap;
460 propertyMap.Insert("rendererType", "GRADIENT");
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");
468 Property::Array stopOffsets;
469 stopOffsets.PushBack( 0.2f );
470 stopOffsets.PushBack( 0.8f );
471 propertyMap.Insert("stopOffset", stopOffsets);
473 Property::Array stopColors;
474 stopColors.PushBack( Color::RED );
475 stopColors.PushBack( Color::GREEN );
476 propertyMap.Insert("stopColor", stopColors);
478 ControlRenderer controlRenderer = factory.CreateControlRenderer(propertyMap);
479 DALI_TEST_CHECK( controlRenderer );
481 // A lookup texture is generated and pass to shader as sampler
482 Actor actor = Actor::New();
483 TestControlRendererRender( application, actor, controlRenderer, 1u );
485 controlRenderer.SetOffStage( actor );
486 DALI_TEST_CHECK( actor.GetRendererCount() == 0u );
491 int UtcDaliRendererFactoryGetRadialGradientRenderer(void)
493 ToolkitTestApplication application;
494 tet_infoline("UtcDaliRendererFactoryGetRadialGradientRenderer");
496 RendererFactory factory = RendererFactory::Get();
497 DALI_TEST_CHECK( factory );
499 Property::Map propertyMap;
500 propertyMap.Insert("rendererType", "GRADIENT");
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);
508 Property::Array stopOffsets;
509 stopOffsets.PushBack( 0.0f );
510 stopOffsets.PushBack( 1.f );
511 propertyMap.Insert("stopOffset", stopOffsets);
513 Property::Array stopColors;
514 stopColors.PushBack( Color::RED );
515 stopColors.PushBack( Color::GREEN );
516 propertyMap.Insert("stopColor", stopColors);
518 ControlRenderer controlRenderer = factory.CreateControlRenderer(propertyMap);
519 DALI_TEST_CHECK( controlRenderer );
521 // A lookup texture is generated and pass to shader as sampler
522 Actor actor = Actor::New();
523 TestControlRendererRender( application, actor, controlRenderer, 1u );
525 Matrix3 alignMatrix( radius, 0.f, 0.f, 0.f, radius, 0.f, center.x, center.y, 1.f );
526 alignMatrix.Invert();
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 );
536 int UtcDaliRendererFactoryDefaultOffsetsGradientRenderer(void)
538 ToolkitTestApplication application;
539 tet_infoline("UtcDaliRendererFactoryGetRadialGradientRenderer");
541 RendererFactory factory = RendererFactory::Get();
542 DALI_TEST_CHECK( factory );
544 Property::Map propertyMap;
545 propertyMap.Insert("rendererType", "GRADIENT");
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");
553 Property::Array stopColors;
554 stopColors.PushBack( Color::RED );
555 stopColors.PushBack( Color::GREEN );
556 propertyMap.Insert("stopColor", stopColors);
558 ControlRenderer controlRenderer = factory.CreateControlRenderer(propertyMap);
559 DALI_TEST_CHECK( controlRenderer );
561 // A lookup texture is generated and pass to shader as sampler
562 Actor actor = Actor::New();
563 TestControlRendererRender( application, actor, controlRenderer, 1u );
565 controlRenderer.SetOffStage( actor );
566 DALI_TEST_CHECK( actor.GetRendererCount() == 0u );
571 int UtcDaliRendererFactoryGetImageRenderer1(void)
573 ToolkitTestApplication application;
574 tet_infoline( "UtcDaliRendererFactoryGetImageRenderer1: Request image renderer with a Property::Map" );
576 RendererFactory factory = RendererFactory::Get();
577 DALI_TEST_CHECK( factory );
579 Property::Map propertyMap;
580 propertyMap.Insert( "rendererType", "IMAGE" );
581 propertyMap.Insert( "url", TEST_IMAGE_FILE_NAME );
583 ControlRenderer controlRenderer = factory.CreateControlRenderer( propertyMap );
584 DALI_TEST_CHECK( controlRenderer );
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.
591 const int height=513;
592 TestGlAbstraction& gl = application.GetGlAbstraction();
593 TraceCallStack& textureTrace = gl.GetTextureTrace();
594 textureTrace.Enable(true);
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 );
599 TestControlRendererRender( application, actor, controlRenderer, 1u,
600 ImageDimensions(width, height),
601 Integration::ResourcePointer( bitmap ) );
603 DALI_TEST_EQUALS( textureTrace.FindMethod("BindTexture"), true, TEST_LOCATION );
605 controlRenderer.SetOffStage( actor );
606 DALI_TEST_CHECK( actor.GetRendererCount() == 0u );
611 int UtcDaliRendererFactoryGetImageRenderer2(void)
613 ToolkitTestApplication application;
614 tet_infoline( "UtcDaliRendererFactoryGetImageRenderer2: Request image renderer with an image handle" );
616 RendererFactory factory = RendererFactory::Get();
617 DALI_TEST_CHECK( factory );
619 Image image = ResourceImage::New(TEST_IMAGE_FILE_NAME);
620 ControlRenderer controlRenderer = factory.CreateControlRenderer( image );
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.
627 const int height=513;
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 );
632 TestGlAbstraction& gl = application.GetGlAbstraction();
633 TraceCallStack& textureTrace = gl.GetTextureTrace();
634 textureTrace.Enable(true);
636 TestControlRendererRender( application, actor, controlRenderer, 1u,
637 ImageDimensions(width, height),
638 Integration::ResourcePointer(bitmap) );
640 DALI_TEST_EQUALS( textureTrace.FindMethod("BindTexture"), true, TEST_LOCATION );
645 int UtcDaliRendererFactoryGetNPatchRenderer1(void)
647 ToolkitTestApplication application;
648 tet_infoline( "UtcDaliRendererFactoryGetNPatchRenderer1: Request 9-patch renderer with a Property::Map" );
650 RendererFactory factory = RendererFactory::Get();
651 DALI_TEST_CHECK( factory );
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 );
661 Property::Map propertyMap;
662 propertyMap.Insert( "rendererType", "IMAGE" );
663 propertyMap.Insert( "url", TEST_NPATCH_FILE_NAME );
665 tet_infoline( "whole grid" );
666 ControlRenderer controlRenderer = factory.CreateControlRenderer( propertyMap );
667 DALI_TEST_CHECK( controlRenderer );
669 Actor actor = Actor::New();
671 TestGlAbstraction& gl = application.GetGlAbstraction();
672 TraceCallStack& textureTrace = gl.GetTextureTrace();
673 textureTrace.Enable(true);
675 TestControlRendererRender( application, actor, controlRenderer, 1u,
676 ImageDimensions(ninePatchImageWidth, ninePatchImageHeight),
679 DALI_TEST_EQUALS( textureTrace.FindMethod("BindTexture"), true, TEST_LOCATION );
682 propertyMap.Insert( "borderOnly", true );
684 tet_infoline( "border only" );
685 ControlRenderer controlRenderer = factory.CreateControlRenderer( propertyMap );
686 DALI_TEST_CHECK( controlRenderer );
688 Actor actor = Actor::New();
690 TestGlAbstraction& gl = application.GetGlAbstraction();
691 TraceCallStack& textureTrace = gl.GetTextureTrace();
692 textureTrace.Enable(true);
694 TestControlRendererRender( application, actor, controlRenderer, 1u,
695 ImageDimensions(ninePatchImageWidth, ninePatchImageHeight),
698 DALI_TEST_EQUALS( textureTrace.FindMethod("BindTexture"), true, TEST_LOCATION );
704 int UtcDaliRendererFactoryGetNPatchRenderer2(void)
706 ToolkitTestApplication application;
707 tet_infoline( "UtcDaliRendererFactoryGetNPatchRenderer2: Request n-patch renderer with a Property::Map" );
709 RendererFactory factory = RendererFactory::Get();
710 DALI_TEST_CHECK( factory );
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 );
725 Property::Map propertyMap;
726 propertyMap.Insert( "rendererType", "IMAGE" );
727 propertyMap.Insert( "url", TEST_NPATCH_FILE_NAME );
729 ControlRenderer controlRenderer = factory.CreateControlRenderer( propertyMap );
730 DALI_TEST_CHECK( controlRenderer );
732 Actor actor = Actor::New();
733 TestGlAbstraction& gl = application.GetGlAbstraction();
734 TraceCallStack& textureTrace = gl.GetTextureTrace();
735 textureTrace.Enable(true);
737 TestControlRendererRender( application, actor, controlRenderer, 1u,
738 ImageDimensions(ninePatchImageWidth, ninePatchImageHeight),
742 DALI_TEST_EQUALS( textureTrace.FindMethod("BindTexture"), true, TEST_LOCATION );
744 controlRenderer.SetOffStage( actor );
745 DALI_TEST_CHECK( actor.GetRendererCount() == 0u );
748 propertyMap.Insert( "borderOnly", true );
750 tet_infoline( "border only" );
751 ControlRenderer controlRenderer = factory.CreateControlRenderer( propertyMap );
752 DALI_TEST_CHECK( controlRenderer );
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),
763 DALI_TEST_EQUALS( textureTrace.FindMethod("BindTexture"), true, TEST_LOCATION );
765 controlRenderer.SetOffStage( actor );
766 DALI_TEST_CHECK( actor.GetRendererCount() == 0u );
772 int UtcDaliRendererFactoryGetNPatchRenderer3(void)
774 ToolkitTestApplication application;
775 tet_infoline( "UtcDaliRendererFactoryGetNPatchRenderer3: Request 9-patch renderer with an image url" );
777 RendererFactory factory = RendererFactory::Get();
778 DALI_TEST_CHECK( factory );
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 );
788 ControlRenderer controlRenderer = factory.CreateControlRenderer( TEST_NPATCH_FILE_NAME, ImageDimensions() );
789 DALI_TEST_CHECK( controlRenderer );
791 Actor actor = Actor::New();
793 TestGlAbstraction& gl = application.GetGlAbstraction();
794 TraceCallStack& textureTrace = gl.GetTextureTrace();
795 textureTrace.Enable(true);
797 TestControlRendererRender( application, actor, controlRenderer, 1u,
798 ImageDimensions(ninePatchImageWidth, ninePatchImageHeight),
801 DALI_TEST_EQUALS( textureTrace.FindMethod("BindTexture"), true, TEST_LOCATION );
806 int UtcDaliRendererFactoryGetNPatchRenderer4(void)
808 ToolkitTestApplication application;
809 tet_infoline( "UtcDaliRendererFactoryGetNPatchRenderer4: Request n-patch renderer with an image url" );
811 RendererFactory factory = RendererFactory::Get();
812 DALI_TEST_CHECK( factory );
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 );
827 ControlRenderer controlRenderer = factory.CreateControlRenderer( TEST_NPATCH_FILE_NAME, ImageDimensions() );
828 DALI_TEST_CHECK( controlRenderer );
830 Actor actor = Actor::New();
832 TestGlAbstraction& gl = application.GetGlAbstraction();
833 TraceCallStack& textureTrace = gl.GetTextureTrace();
834 textureTrace.Enable(true);
836 TestControlRendererRender( application, actor, controlRenderer, 1u,
837 ImageDimensions(ninePatchImageWidth, ninePatchImageHeight),
840 DALI_TEST_EQUALS( textureTrace.FindMethod("BindTexture"), true, TEST_LOCATION );
845 int UtcDaliRendererFactoryGetNPatchRendererN1(void)
847 //This should still load but display an error image
849 ToolkitTestApplication application;
850 tet_infoline( "UtcDaliRendererFactoryGetNPatchRendererN: Request n-patch renderer with an invalid image url" );
852 RendererFactory factory = RendererFactory::Get();
853 DALI_TEST_CHECK( factory );
855 ControlRenderer controlRenderer = factory.CreateControlRenderer( "ERROR.9.jpg", ImageDimensions() );
856 DALI_TEST_CHECK( controlRenderer );
858 Actor actor = Actor::New();
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 );
864 TestGlAbstraction& gl = application.GetGlAbstraction();
865 TraceCallStack& textureTrace = gl.GetTextureTrace();
866 textureTrace.Enable(true);
868 TestControlRendererRender( application, actor, controlRenderer, 1u,
870 Integration::ResourcePointer(bitmap) );
872 DALI_TEST_EQUALS( textureTrace.FindMethod("BindTexture"), true, TEST_LOCATION );
877 int UtcDaliRendererFactoryGetNPatchRendererN2(void)
879 //This should still load but display an error image
881 ToolkitTestApplication application;
882 tet_infoline( "UtcDaliRendererFactoryGetNPatchRendererN: Request n-patch renderer with an invalid Property::Map" );
884 RendererFactory factory = RendererFactory::Get();
885 DALI_TEST_CHECK( factory );
887 Property::Map propertyMap;
888 propertyMap.Insert( "rendererType", 111 );
889 propertyMap.Insert( "url", "ERROR.9.jpg" );
891 ControlRenderer controlRenderer = factory.CreateControlRenderer( propertyMap );
892 DALI_TEST_CHECK( controlRenderer );
894 Actor actor = Actor::New();
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 );
900 TestGlAbstraction& gl = application.GetGlAbstraction();
901 TraceCallStack& textureTrace = gl.GetTextureTrace();
902 textureTrace.Enable(true);
904 TestControlRendererRender( application, actor, controlRenderer, 1u,
906 Integration::ResourcePointer(bitmap) );
908 DALI_TEST_EQUALS( textureTrace.FindMethod("BindTexture"), true, TEST_LOCATION );
913 int UtcDaliRendererFactoryGetSvgRenderer(void)
915 ToolkitTestApplication application;
916 tet_infoline( "UtcDaliRendererFactoryGetSvgRenderer: Request svg renderer with a svg url" );
918 RendererFactory factory = RendererFactory::Get();
919 ControlRenderer controlRenderer = factory.CreateControlRenderer( TEST_SVG_FILE_NAME, ImageDimensions() );
920 DALI_TEST_CHECK( controlRenderer );
922 TestGlAbstraction& gl = application.GetGlAbstraction();
923 TraceCallStack& textureTrace = gl.GetTextureTrace();
924 textureTrace.Enable(true);
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();
934 DALI_TEST_CHECK( actor.GetRendererCount() == 1u );
936 EventThreadCallback* eventTrigger = EventThreadCallback::Get();
937 CallbackBase* callback = eventTrigger->GetCallback();
939 eventTrigger->WaitingForTrigger( 1 );// waiting until the svg image is rasterized.
940 CallbackBase::Execute( *callback );
942 DALI_TEST_CHECK( actor.GetRendererCount() == 1u );
944 // waiting for the resource uploading
945 application.SendNotification();
946 application.Render();
948 DALI_TEST_EQUALS( textureTrace.FindMethod("BindTexture"), true, TEST_LOCATION );
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 )
957 RendererFactory factory = RendererFactory::Get();
958 DALI_TEST_CHECK( factory );
960 //Create a mesh renderer.
961 ControlRenderer controlRenderer = factory.CreateControlRenderer( propertyMap );
962 DALI_TEST_CHECK( controlRenderer );
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 );
971 //Ensure set on stage.
972 DALI_TEST_EQUALS( actor.GetRendererCount(), 1u, TEST_LOCATION );
974 //Attempt to render to queue resource load requests.
975 application.SendNotification();
976 application.Render( 0 );
978 //Tell the platform abstraction that the required resources have been loaded.
979 TestPlatformAbstraction& platform = application.GetPlatform();
980 platform.SetAllResourceRequestsAsLoaded();
982 //Render again to upload the now-loaded textures.
983 application.SendNotification();
984 application.Render( 0 );
986 Matrix testScaleMatrix;
987 testScaleMatrix.SetIdentityAndScale( Vector3( 1.0, -1.0, 1.0 ) );
988 Matrix actualScaleMatrix;
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 );
994 //Finish by setting off stage, and ensuring this was successful.
995 controlRenderer.SetOffStage( actor );
996 DALI_TEST_EQUALS( actor.GetRendererCount(), 0u, TEST_LOCATION );
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 )
1003 RendererFactory factory = RendererFactory::Get();
1004 DALI_TEST_CHECK( factory );
1006 //Create a mesh renderer.
1007 ControlRenderer controlRenderer = factory.CreateControlRenderer( propertyMap );
1008 DALI_TEST_CHECK( controlRenderer );
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 );
1017 //Ensure set on stage.
1018 DALI_TEST_EQUALS( actor.GetRendererCount(), 1u, TEST_LOCATION );
1020 //Attempt to render to queue resource load requests.
1021 application.SendNotification();
1022 application.Render( 0 );
1024 //Tell the platform abstraction that the required resources have been loaded.
1025 TestPlatformAbstraction& platform = application.GetPlatform();
1026 platform.SetAllResourceRequestsAsLoaded();
1028 //Render again to upload the now-loaded textures.
1029 application.SendNotification();
1030 application.Render( 0 );
1032 //Test to see if the object has not been loaded, as expected.
1034 DALI_TEST_CHECK( !application.GetGlAbstraction().GetUniformValue<Matrix>( "uObjectMatrix", scaleMatrix ) );
1036 //Finish by setting off stage, and ensuring this was successful.
1037 controlRenderer.SetOffStage( actor );
1038 DALI_TEST_EQUALS( actor.GetRendererCount(), 0u, TEST_LOCATION );
1041 //Test if mesh loads correctly when supplied with only the bare minimum requirements, an object file.
1042 int UtcDaliRendererFactoryGetMeshRenderer1(void)
1044 //Set up test application first, so everything else can be handled.
1045 ToolkitTestApplication application;
1047 tet_infoline( "UtcDaliRendererFactoryGetMeshRenderer1: Request mesh renderer with a valid object file only" );
1049 //Set up renderer properties.
1050 Property::Map propertyMap;
1051 propertyMap.Insert( "rendererType", "MESH" );
1052 propertyMap.Insert( "objectUrl", TEST_OBJ_FILE_NAME );
1054 //Test to see if mesh loads correctly.
1055 MeshRendererLoadsCorrectlyTest( propertyMap, application );
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)
1063 //Set up test application first, so everything else can be handled.
1064 ToolkitTestApplication application;
1066 tet_infoline( "UtcDaliRendererFactoryGetMeshRenderer2: Request mesh renderer with blank material file and images directory" );
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", "" );
1075 //Test to see if mesh loads correctly.
1076 MeshRendererLoadsCorrectlyTest( propertyMap, application );
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)
1084 //Set up test application first, so everything else can be handled.
1085 ToolkitTestApplication application;
1087 tet_infoline( "UtcDaliRendererFactoryGetMeshRenderer3: Request mesh renderer with all parameters correct" );
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 "/" );
1096 //Test to see if mesh loads correctly.
1097 MeshRendererLoadsCorrectlyTest( propertyMap, application );
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)
1105 //Set up test application first, so everything else can be handled.
1106 ToolkitTestApplication application;
1108 tet_infoline( "UtcDaliRendererFactoryGetMeshRenderer4: Request mesh renderer with diffuse texture but not normal or gloss." );
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 "/" );
1117 //Test to see if mesh loads correctly.
1118 MeshRendererLoadsCorrectlyTest( propertyMap, application );
1123 //Test if mesh renderer can load when made to use diffuse textures only.
1124 int UtcDaliRendererFactoryGetMeshRenderer5(void)
1126 //Set up test application first, so everything else can be handled.
1127 ToolkitTestApplication application;
1129 tet_infoline( "UtcDaliRendererFactoryGetMeshRenderer5: Request mesh renderer and make it only use diffuse textures." );
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" );
1139 //Test to see if mesh loads correctly.
1140 MeshRendererLoadsCorrectlyTest( propertyMap, application );
1145 //Test if mesh renderer can load when made to not use the supplied textures.
1146 int UtcDaliRendererFactoryGetMeshRenderer6(void)
1148 //Set up test application first, so everything else can be handled.
1149 ToolkitTestApplication application;
1151 tet_infoline( "UtcDaliRendererFactoryGetMeshRenderer6: Request mesh renderer and make it not use any textures." );
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" );
1161 //Test to see if mesh loads correctly.
1162 MeshRendererLoadsCorrectlyTest( propertyMap, application );
1166 //Test if mesh renderer loads correctly when light position is manually set.
1167 int UtcDaliRendererFactoryGetMeshRenderer7(void)
1169 //Set up test application first, so everything else can be handled.
1170 ToolkitTestApplication application;
1172 tet_infoline( "UtcDaliRendererFactoryGetMeshRenderer7: Request mesh renderer with custom light position." );
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 ) );
1182 //Test to see if mesh loads correctly.
1183 MeshRendererLoadsCorrectlyTest( propertyMap, application );
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)
1192 //Set up test application first, so everything else can be handled.
1193 ToolkitTestApplication application;
1195 tet_infoline( "UtcDaliRendererFactoryGetMeshRenderer5: Request mesh renderer with normal-less object file." );
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 "/" );
1204 //Test to see if mesh loads correctly.
1205 MeshRendererLoadsCorrectlyTest( propertyMap, application );
1210 //Test if mesh renderer handles the case of lacking an object file.
1211 int UtcDaliRendererFactoryGetMeshRendererN1(void)
1213 //Set up test application first, so everything else can be handled.
1214 ToolkitTestApplication application;
1216 tet_infoline( "UtcDaliRendererFactoryGetMeshRendererN1: Request mesh renderer without object file" );
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 "/" );
1224 //Test to see if mesh doesn't load with these properties, as expected.
1225 MeshRendererDoesNotLoadCorrectlyTest( propertyMap, application );
1230 //Test if mesh renderer handles the case of being passed invalid material and images urls.
1231 int UtcDaliRendererFactoryGetMeshRendererN2(void)
1233 //Set up test application first, so everything else can be handled.
1234 ToolkitTestApplication application;
1236 tet_infoline( "UtcDaliRendererFactoryGetMeshRendererN2: Request mesh renderer with invalid material and images urls" );
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" );
1245 //Test to see if mesh doesn't load with these properties, as expected.
1246 MeshRendererDoesNotLoadCorrectlyTest( propertyMap, application );
1251 //Test if mesh renderer handles the case of being passed an invalid object url
1252 int UtcDaliRendererFactoryGetMeshRendererN3(void)
1254 //Set up test application first, so everything else can be handled.
1255 ToolkitTestApplication application;
1257 tet_infoline( "UtcDaliRendererFactoryGetMeshRendererN3: Request mesh renderer with invalid object url" );
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 "/" );
1266 //Test to see if mesh doesn't load with these properties, as expected.
1267 MeshRendererDoesNotLoadCorrectlyTest( propertyMap, application );
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 )
1275 RendererFactory factory = RendererFactory::Get();
1276 DALI_TEST_CHECK( factory );
1278 //Create a primitive renderer.
1279 ControlRenderer controlRenderer = factory.CreateControlRenderer( propertyMap );
1280 DALI_TEST_CHECK( controlRenderer );
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 );
1289 //Ensure set on stage.
1290 DALI_TEST_EQUALS( actor.GetRendererCount(), 1u, TEST_LOCATION );
1292 //Tell test application to load the renderer.
1293 application.SendNotification();
1294 application.Render(0);
1296 Matrix testScaleMatrix;
1297 testScaleMatrix.SetIdentityAndScale( Vector3( 1.0, -1.0, 1.0 ) );
1298 Matrix actualScaleMatrix;
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 );
1304 //Finish by setting off stage, and ensuring this was successful.
1305 controlRenderer.SetOffStage( actor );
1306 DALI_TEST_EQUALS( actor.GetRendererCount(), 0u, TEST_LOCATION );
1309 //Test if primitive shape loads correctly when supplied with only the bare minimum requirements, the shape to use.
1310 int UtcDaliRendererFactoryGetPrimitiveRenderer1(void)
1312 //Set up test application first, so everything else can be handled.
1313 ToolkitTestApplication application;
1315 tet_infoline( "UtcDaliRendererFactoryGetPrimitiveRenderer1: Request primitive renderer with a shape only" );
1317 //Set up renderer properties.
1318 Property::Map propertyMap;
1319 propertyMap.Insert( "rendererType", "PRIMITIVE" );
1320 propertyMap.Insert( "shape", "CUBE" );
1322 //Test to see if shape loads correctly.
1323 TestPrimitiveRendererWithProperties( propertyMap, application );
1328 //Test if primitive shape loads correctly when supplied with all possible parameters
1329 int UtcDaliRendererFactoryGetPrimitiveRenderer2(void)
1331 //Set up test application first, so everything else can be handled.
1332 ToolkitTestApplication application;
1334 tet_infoline( "UtcDaliRendererFactoryGetPrimitiveRenderer2: Request primitive renderer with everything" );
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 ) );
1351 //Test to see if shape loads correctly.
1352 TestPrimitiveRendererWithProperties( propertyMap, application );
1357 //Test if primitive shape loads a sphere correctly.
1358 int UtcDaliRendererFactoryGetPrimitiveRenderer3(void)
1360 //Set up test application first, so everything else can be handled.
1361 ToolkitTestApplication application;
1363 tet_infoline( "UtcDaliRendererFactoryGetPrimitiveRenderer3: Request primitive renderer to display a sphere" );
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 );
1373 //Test to see if shape loads correctly.
1374 TestPrimitiveRendererWithProperties( propertyMap, application );
1379 //Test if primitive shape loads a conic section correctly.
1380 int UtcDaliRendererFactoryGetPrimitiveRenderer4(void)
1382 //Set up test application first, so everything else can be handled.
1383 ToolkitTestApplication application;
1385 tet_infoline( "UtcDaliRendererFactoryGetPrimitiveRenderer4: Request primitive renderer to display a conic section" );
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 );
1397 //Test to see if shape loads correctly.
1398 TestPrimitiveRendererWithProperties( propertyMap, application );
1403 //Test if primitive shape loads a bevelled cube correctly.
1404 int UtcDaliRendererFactoryGetPrimitiveRenderer5(void)
1406 //Set up test application first, so everything else can be handled.
1407 ToolkitTestApplication application;
1409 tet_infoline( "UtcDaliRendererFactoryGetPrimitiveRenderer5: Request primitive renderer to display a bevelled cube" );
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 );
1418 //Test to see if shape loads correctly.
1419 TestPrimitiveRendererWithProperties( propertyMap, application );
1424 //Test if primitive shape loads an octahedron correctly.
1425 int UtcDaliRendererFactoryGetPrimitiveRenderer6(void)
1427 //Set up test application first, so everything else can be handled.
1428 ToolkitTestApplication application;
1430 tet_infoline( "UtcDaliRendererFactoryGetPrimitiveRenderer6: Request primitive renderer to display an octahedron" );
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 ) );
1438 //Test to see if shape loads correctly.
1439 TestPrimitiveRendererWithProperties( propertyMap, application );
1444 //Test if primitive shape loads a cone correctly.
1445 int UtcDaliRendererFactoryGetPrimitiveRenderer7(void)
1447 //Set up test application first, so everything else can be handled.
1448 ToolkitTestApplication application;
1450 tet_infoline( "UtcDaliRendererFactoryGetPrimitiveRenderer7: Request primitive renderer to display a cone" );
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 );
1461 //Test to see if shape loads correctly.
1462 TestPrimitiveRendererWithProperties( propertyMap, application );
1467 //Test if primitive shape loads correctly when light position is manually set.
1468 int UtcDaliRendererFactoryGetPrimitiveRenderer8(void)
1470 //Set up test application first, so everything else can be handled.
1471 ToolkitTestApplication application;
1473 tet_infoline( "UtcDaliRendererFactoryGetPrimitiveRenderer8: Request primitive renderer with set light position" );
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 ) );
1482 //Test to see if shape loads correctly.
1483 TestPrimitiveRendererWithProperties( propertyMap, application );
1488 //Test if primitive shape renderer handles the case of not being passed a specific shape to use.
1489 int UtcDaliRendererFactoryGetPrimitiveRendererN1(void)
1491 //Set up test application first, so everything else can be handled.
1492 ToolkitTestApplication application;
1494 tet_infoline( "UtcDaliRendererFactoryGetPrimitiveRendererN1: Request primitive renderer without shape" );
1496 //Set up renderer properties, without supplying shape.
1497 Property::Map propertyMap;
1498 propertyMap.Insert( "rendererType", "PRIMITIVE" );
1500 //Test to see if shape loads regardless of missing input.
1501 TestPrimitiveRendererWithProperties( propertyMap, application );