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/visual-factory/visual-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 TestVisualRender( ToolkitTestApplication& application,
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 visual.SetSize( Vector2(200.f, 200.f) );
192 visual.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_visual_factory_startup(void)
226 test_return_value = TET_UNDEF;
229 void dali_visual_factory_cleanup(void)
231 test_return_value = TET_PASS;
234 int UtcDaliVisualFactoryGet(void)
236 ToolkitTestApplication application;
237 tet_infoline( "UtcDaliVisualFactory" );
241 type = TypeRegistry::Get().GetTypeInfo( "VisualFactory" );
242 DALI_TEST_CHECK( type );
243 BaseHandle handle = type.CreateInstance();
244 DALI_TEST_CHECK( handle );
246 VisualFactory factory;
247 factory = VisualFactory::Get();
248 DALI_TEST_CHECK( factory );
250 VisualFactory newFactory = VisualFactory::Get();
251 DALI_TEST_CHECK( newFactory );
253 // Check that renderer factory is a singleton
254 DALI_TEST_CHECK(factory == newFactory);
259 int UtcDaliVisualFactoryCopyAndAssignment(void)
261 ToolkitTestApplication application;
262 tet_infoline( "UtcDaliVisualFactoryCopyAndAssignment" );
263 VisualFactory factory = VisualFactory::Get();
265 VisualFactory factoryCopy( factory );
266 DALI_TEST_CHECK(factory == factoryCopy);
268 VisualFactory emptyFactory;
269 VisualFactory emptyFactoryCopy( emptyFactory );
270 DALI_TEST_CHECK(emptyFactory == emptyFactoryCopy);
272 VisualFactory factoryEquals;
273 factoryEquals = factory;
274 DALI_TEST_CHECK(factory == factoryEquals);
276 VisualFactory emptyFactoryEquals;
277 emptyFactoryEquals = emptyFactory;
278 DALI_TEST_CHECK( emptyFactory == emptyFactoryEquals );
282 DALI_TEST_CHECK( factory = factoryCopy );
287 int UtcDaliVisualFactoryGetColorVisual1(void)
289 ToolkitTestApplication application;
290 tet_infoline( "UtcDaliVisualFactoryGetColorVisual1: Request color visual with a Property::Map" );
292 VisualFactory factory = VisualFactory::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 Visual visual = factory.CreateVisual(propertyMap);
301 DALI_TEST_CHECK( visual );
303 Actor actor = Actor::New();
304 TestVisualRender( application, actor, visual );
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 UtcDaliVisualFactoryGetColorVisual2(void)
316 ToolkitTestApplication application;
317 tet_infoline( "UtcDaliVisualFactoryGetColorVisual2: Request color visual with a Vector4" );
319 VisualFactory factory = VisualFactory::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 Visual visual = factory.CreateVisual( map );
327 DALI_TEST_CHECK( visual );
329 Actor actor = Actor::New();
330 TestVisualRender( application, actor, visual );
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 visual.SetOffStage( actor );
338 DALI_TEST_CHECK( actor.GetRendererCount() == 0u );
343 int UtcDaliVisualFactoryGetBorderVisual1(void)
345 ToolkitTestApplication application;
346 tet_infoline( "UtcDaliVisualFactoryGetBorderVisual1: Request border visual with a Property::Map" );
348 VisualFactory factory = VisualFactory::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 Visual visual = factory.CreateVisual(propertyMap);
359 DALI_TEST_CHECK( visual );
361 Actor actor = Actor::New();
362 actor.SetSize(200.f, 200.f);
363 Stage::GetCurrent().Add( actor );
364 visual.SetSize(Vector2(200.f, 200.f));
365 visual.SetOnStage( actor );
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 visual.SetOffStage( actor );
385 DALI_TEST_CHECK( actor.GetRendererCount() == 0u );
390 int UtcDaliVisualFactoryGetBorderVisual2(void)
392 ToolkitTestApplication application;
393 tet_infoline( "UtcDaliVisualFactoryGetBorderVisual2: Request border visual with a borderSize and a borderColor" );
395 VisualFactory factory = VisualFactory::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 Visual visual = factory.CreateVisual( propertyMap );
406 DALI_TEST_CHECK( visual );
408 Actor actor = Actor::New();
409 actor.SetSize(200.f, 200.f);
410 Stage::GetCurrent().Add( actor );
411 visual.SetSize(Vector2(200.f, 200.f));
412 visual.SetOnStage( actor );
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 visual.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 visual = factory.CreateVisual( map );
441 visual.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 UtcDaliVisualFactoryGetLinearGradientVisual(void)
453 ToolkitTestApplication application;
454 tet_infoline("UtcDaliVisualFactoryGetRadialGradientVisual");
456 VisualFactory factory = VisualFactory::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 Visual visual = factory.CreateVisual(propertyMap);
479 DALI_TEST_CHECK( visual );
481 // A lookup texture is generated and pass to shader as sampler
482 Actor actor = Actor::New();
483 TestVisualRender( application, actor, visual, 1u );
485 visual.SetOffStage( actor );
486 DALI_TEST_CHECK( actor.GetRendererCount() == 0u );
491 int UtcDaliVisualFactoryGetRadialGradientVisual(void)
493 ToolkitTestApplication application;
494 tet_infoline("UtcDaliVisualFactoryGetRadialGradientVisual");
496 VisualFactory factory = VisualFactory::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 Visual visual = factory.CreateVisual(propertyMap);
519 DALI_TEST_CHECK( visual );
521 // A lookup texture is generated and pass to shader as sampler
522 Actor actor = Actor::New();
523 TestVisualRender( application, actor, visual, 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 UtcDaliVisualFactoryDefaultOffsetsGradientVisual(void)
538 ToolkitTestApplication application;
539 tet_infoline("UtcDaliVisualFactoryGetRadialGradientVisual");
541 VisualFactory factory = VisualFactory::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 Visual visual = factory.CreateVisual(propertyMap);
559 DALI_TEST_CHECK( visual );
561 // A lookup texture is generated and pass to shader as sampler
562 Actor actor = Actor::New();
563 TestVisualRender( application, actor, visual, 1u );
565 visual.SetOffStage( actor );
566 DALI_TEST_CHECK( actor.GetRendererCount() == 0u );
571 int UtcDaliVisualFactoryGetImageVisual1(void)
573 ToolkitTestApplication application;
574 tet_infoline( "UtcDaliVisualFactoryGetImageVisual1: Request image renderer with a Property::Map" );
576 VisualFactory factory = VisualFactory::Get();
577 DALI_TEST_CHECK( factory );
579 Property::Map propertyMap;
580 propertyMap.Insert( "rendererType", "IMAGE" );
581 propertyMap.Insert( "url", TEST_IMAGE_FILE_NAME );
583 Visual visual = factory.CreateVisual( propertyMap );
584 DALI_TEST_CHECK( visual );
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 TestVisualRender( application, actor, visual, 1u,
600 ImageDimensions(width, height),
601 Integration::ResourcePointer( bitmap ) );
603 DALI_TEST_EQUALS( textureTrace.FindMethod("BindTexture"), true, TEST_LOCATION );
605 visual.SetOffStage( actor );
606 DALI_TEST_CHECK( actor.GetRendererCount() == 0u );
611 int UtcDaliVisualFactoryGetImageVisual2(void)
613 ToolkitTestApplication application;
614 tet_infoline( "UtcDaliVisualFactoryGetImageVisual2: Request image renderer with an image handle" );
616 VisualFactory factory = VisualFactory::Get();
617 DALI_TEST_CHECK( factory );
619 Image image = ResourceImage::New(TEST_IMAGE_FILE_NAME);
620 Visual visual = factory.CreateVisual( 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 TestVisualRender( application, actor, visual, 1u,
637 ImageDimensions(width, height),
638 Integration::ResourcePointer(bitmap) );
640 DALI_TEST_EQUALS( textureTrace.FindMethod("BindTexture"), true, TEST_LOCATION );
645 int UtcDaliVisualFactoryGetNPatchVisual1(void)
647 ToolkitTestApplication application;
648 tet_infoline( "UtcDaliVisualFactoryGetNPatchVisual1: Request 9-patch renderer with a Property::Map" );
650 VisualFactory factory = VisualFactory::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 Visual visual = factory.CreateVisual( propertyMap );
667 DALI_TEST_CHECK( visual );
669 Actor actor = Actor::New();
671 TestGlAbstraction& gl = application.GetGlAbstraction();
672 TraceCallStack& textureTrace = gl.GetTextureTrace();
673 textureTrace.Enable(true);
675 TestVisualRender( application, actor, visual, 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 Visual visual = factory.CreateVisual( propertyMap );
686 DALI_TEST_CHECK( visual );
688 Actor actor = Actor::New();
690 TestGlAbstraction& gl = application.GetGlAbstraction();
691 TraceCallStack& textureTrace = gl.GetTextureTrace();
692 textureTrace.Enable(true);
694 TestVisualRender( application, actor, visual, 1u,
695 ImageDimensions(ninePatchImageWidth, ninePatchImageHeight),
698 DALI_TEST_EQUALS( textureTrace.FindMethod("BindTexture"), true, TEST_LOCATION );
704 int UtcDaliVisualFactoryGetNPatchVisual2(void)
706 ToolkitTestApplication application;
707 tet_infoline( "UtcDaliVisualFactoryGetNPatchVisual2: Request n-patch renderer with a Property::Map" );
709 VisualFactory factory = VisualFactory::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 Visual visual = factory.CreateVisual( propertyMap );
730 DALI_TEST_CHECK( visual );
732 Actor actor = Actor::New();
733 TestGlAbstraction& gl = application.GetGlAbstraction();
734 TraceCallStack& textureTrace = gl.GetTextureTrace();
735 textureTrace.Enable(true);
737 TestVisualRender( application, actor, visual, 1u,
738 ImageDimensions(ninePatchImageWidth, ninePatchImageHeight),
742 DALI_TEST_EQUALS( textureTrace.FindMethod("BindTexture"), true, TEST_LOCATION );
744 visual.SetOffStage( actor );
745 DALI_TEST_CHECK( actor.GetRendererCount() == 0u );
748 propertyMap.Insert( "borderOnly", true );
750 tet_infoline( "border only" );
751 Visual visual = factory.CreateVisual( propertyMap );
752 DALI_TEST_CHECK( visual );
754 TestGlAbstraction& gl = application.GetGlAbstraction();
755 TraceCallStack& textureTrace = gl.GetTextureTrace();
756 textureTrace.Enable(true);
757 Actor actor = Actor::New();
758 TestVisualRender( application, actor, visual, 1u,
759 ImageDimensions(ninePatchImageWidth, ninePatchImageHeight),
763 DALI_TEST_EQUALS( textureTrace.FindMethod("BindTexture"), true, TEST_LOCATION );
765 visual.SetOffStage( actor );
766 DALI_TEST_CHECK( actor.GetRendererCount() == 0u );
772 int UtcDaliVisualFactoryGetNPatchVisual3(void)
774 ToolkitTestApplication application;
775 tet_infoline( "UtcDaliVisualFactoryGetNPatchVisual3: Request 9-patch renderer with an image url" );
777 VisualFactory factory = VisualFactory::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 Visual visual = factory.CreateVisual( TEST_NPATCH_FILE_NAME, ImageDimensions() );
789 DALI_TEST_CHECK( visual );
791 Actor actor = Actor::New();
793 TestGlAbstraction& gl = application.GetGlAbstraction();
794 TraceCallStack& textureTrace = gl.GetTextureTrace();
795 textureTrace.Enable(true);
797 TestVisualRender( application, actor, visual, 1u,
798 ImageDimensions(ninePatchImageWidth, ninePatchImageHeight),
801 DALI_TEST_EQUALS( textureTrace.FindMethod("BindTexture"), true, TEST_LOCATION );
806 int UtcDaliVisualFactoryGetNPatchVisual4(void)
808 ToolkitTestApplication application;
809 tet_infoline( "UtcDaliVisualFactoryGetNPatchVisual4: Request n-patch visual with an image url" );
811 VisualFactory factory = VisualFactory::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 Visual visual = factory.CreateVisual( TEST_NPATCH_FILE_NAME, ImageDimensions() );
828 DALI_TEST_CHECK( visual );
830 Actor actor = Actor::New();
832 TestGlAbstraction& gl = application.GetGlAbstraction();
833 TraceCallStack& textureTrace = gl.GetTextureTrace();
834 textureTrace.Enable(true);
836 TestVisualRender( application, actor, visual, 1u,
837 ImageDimensions(ninePatchImageWidth, ninePatchImageHeight),
840 DALI_TEST_EQUALS( textureTrace.FindMethod("BindTexture"), true, TEST_LOCATION );
845 int UtcDaliVisualFactoryGetNPatchVisualN1(void)
847 //This should still load but display an error image
849 ToolkitTestApplication application;
850 tet_infoline( "UtcDaliVisualFactoryGetNPatchVisualN: Request n-patch visual with an invalid image url" );
852 VisualFactory factory = VisualFactory::Get();
853 DALI_TEST_CHECK( factory );
855 Visual visual = factory.CreateVisual( "ERROR.9.jpg", ImageDimensions() );
856 DALI_TEST_CHECK( visual );
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 TestVisualRender( application, actor, visual, 1u,
870 Integration::ResourcePointer(bitmap) );
872 DALI_TEST_EQUALS( textureTrace.FindMethod("BindTexture"), true, TEST_LOCATION );
877 int UtcDaliVisualFactoryGetNPatchVisualN2(void)
879 //This should still load but display an error image
881 ToolkitTestApplication application;
882 tet_infoline( "UtcDaliVisualFactoryGetNPatchVisualN: Request n-patch visual with an invalid Property::Map" );
884 VisualFactory factory = VisualFactory::Get();
885 DALI_TEST_CHECK( factory );
887 Property::Map propertyMap;
888 propertyMap.Insert( "rendererType", 111 );
889 propertyMap.Insert( "url", "ERROR.9.jpg" );
891 Visual visual = factory.CreateVisual( propertyMap );
892 DALI_TEST_CHECK( visual );
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 TestVisualRender( application, actor, visual, 1u,
906 Integration::ResourcePointer(bitmap) );
908 DALI_TEST_EQUALS( textureTrace.FindMethod("BindTexture"), true, TEST_LOCATION );
913 int UtcDaliVisualFactoryGetSvgVisual(void)
915 ToolkitTestApplication application;
916 tet_infoline( "UtcDaliVisualFactoryGetSvgVisual: Request svg visual with a svg url" );
918 VisualFactory factory = VisualFactory::Get();
919 Visual visual = factory.CreateVisual( TEST_SVG_FILE_NAME, ImageDimensions() );
920 DALI_TEST_CHECK( visual );
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 visual.SetSize( Vector2(200.f, 200.f) );
930 visual.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 MeshVisualLoadsCorrectlyTest( Property::Map& propertyMap, ToolkitTestApplication& application )
957 VisualFactory factory = VisualFactory::Get();
958 DALI_TEST_CHECK( factory );
960 //Create a mesh visual.
961 Visual visual = factory.CreateVisual( propertyMap );
962 DALI_TEST_CHECK( visual );
964 //Create an actor on stage to house the visual.
965 Actor actor = Actor::New();
966 actor.SetSize( 200.f, 200.f );
967 Stage::GetCurrent().Add( actor );
968 visual.SetSize( Vector2( 200.f, 200.f ) );
969 visual.SetOnStage( actor );
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 visual.SetOffStage( actor );
996 DALI_TEST_EQUALS( actor.GetRendererCount(), 0u, TEST_LOCATION );
999 //Creates a mesh visual from the given propertyMap and tries to load it on stage in the given application.
1000 //This is expected to fail, which will then pass the test.
1001 void MeshVisualDoesNotLoadCorrectlyTest( Property::Map& propertyMap, ToolkitTestApplication& application )
1003 VisualFactory factory = VisualFactory::Get();
1004 DALI_TEST_CHECK( factory );
1006 //Create a mesh visual.
1007 Visual visual = factory.CreateVisual( propertyMap );
1008 DALI_TEST_CHECK( visual );
1010 //Create an actor on stage to house the visual.
1011 Actor actor = Actor::New();
1012 actor.SetSize( 200.f, 200.f );
1013 Stage::GetCurrent().Add( actor );
1014 visual.SetSize( Vector2( 200.f, 200.f ) );
1015 visual.SetOnStage( actor );
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 visual.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 UtcDaliVisualFactoryGetMeshVisual1(void)
1044 //Set up test application first, so everything else can be handled.
1045 ToolkitTestApplication application;
1047 tet_infoline( "UtcDaliVisualFactoryGetMeshVisual1: Request mesh visual with a valid object file only" );
1050 //Set up visual properties.
1051 Property::Map propertyMap;
1052 propertyMap.Insert( "rendererType", "MESH" );
1053 propertyMap.Insert( "objectUrl", TEST_OBJ_FILE_NAME );
1055 //Test to see if mesh loads correctly.
1056 MeshVisualLoadsCorrectlyTest( propertyMap, application );
1062 //Test if mesh loads correctly when supplied with an object file as well as a blank material file and images directory.
1063 int UtcDaliVisualFactoryGetMeshVisual2(void)
1065 //Set up test application first, so everything else can be handled.
1066 ToolkitTestApplication application;
1068 tet_infoline( "UtcDaliVisualFactoryGetMeshVisual2: Request mesh visual with blank material file and images directory" );
1070 //Set up visual properties.
1071 Property::Map propertyMap;
1072 propertyMap.Insert( "rendererType", "MESH" );
1073 propertyMap.Insert( "objectUrl", TEST_OBJ_FILE_NAME );
1074 propertyMap.Insert( "materialUrl", "" );
1075 propertyMap.Insert( "texturesPath", "" );
1077 //Test to see if mesh loads correctly.
1078 MeshVisualLoadsCorrectlyTest( propertyMap, application );
1083 //Test if mesh loads correctly when supplied with all main parameters, an object file, a material file and a directory location.
1084 int UtcDaliVisualFactoryGetMeshVisual3(void)
1086 //Set up test application first, so everything else can be handled.
1087 ToolkitTestApplication application;
1089 tet_infoline( "UtcDaliVisualFactoryGetMeshVisual3: Request mesh visual with all parameters correct" );
1091 //Set up visual properties.
1092 Property::Map propertyMap;
1093 propertyMap.Insert( "rendererType", "MESH" );
1094 propertyMap.Insert( "objectUrl", TEST_OBJ_FILE_NAME );
1095 propertyMap.Insert( "materialUrl", TEST_MTL_FILE_NAME );
1096 propertyMap.Insert( "texturesPath", TEST_RESOURCE_DIR "/" );
1098 //Test to see if mesh loads correctly.
1099 MeshVisualLoadsCorrectlyTest( propertyMap, application );
1104 //Test if mesh visual can load a correctly supplied mesh without a normal map or gloss map in the material file.
1105 int UtcDaliVisualFactoryGetMeshVisual4(void)
1107 //Set up test application first, so everything else can be handled.
1108 ToolkitTestApplication application;
1110 tet_infoline( "UtcDaliVisualFactoryGetMeshVisual4: Request mesh visual with diffuse texture but not normal or gloss." );
1113 //Set up visual properties.
1114 Property::Map propertyMap;
1115 propertyMap.Insert( "rendererType", "MESH" );
1116 propertyMap.Insert( "objectUrl", TEST_OBJ_FILE_NAME );
1117 propertyMap.Insert( "materialUrl", TEST_SIMPLE_MTL_FILE_NAME );
1118 propertyMap.Insert( "texturesPath", TEST_RESOURCE_DIR "/" );
1120 //Test to see if mesh loads correctly.
1121 MeshVisualLoadsCorrectlyTest( propertyMap, application );
1127 //Test if mesh visual can load when made to use diffuse textures only.
1128 int UtcDaliVisualFactoryGetMeshVisual5(void)
1130 //Set up test application first, so everything else can be handled.
1131 ToolkitTestApplication application;
1133 tet_infoline( "UtcDaliVisualFactoryGetMeshVisual5: Request mesh visual and make it only use diffuse textures." );
1135 //Set up visual properties.
1136 Property::Map propertyMap;
1137 propertyMap.Insert( "rendererType", "MESH" );
1138 propertyMap.Insert( "objectUrl", TEST_OBJ_FILE_NAME );
1139 propertyMap.Insert( "materialUrl", TEST_MTL_FILE_NAME );
1140 propertyMap.Insert( "texturesPath", TEST_RESOURCE_DIR "/" );
1141 propertyMap.Insert( "shaderType", "DIFFUSE_TEXTURE" );
1143 //Test to see if mesh loads correctly.
1144 MeshVisualLoadsCorrectlyTest( propertyMap, application );
1150 //Test if mesh visual can load when made to not use the supplied textures.
1151 int UtcDaliVisualFactoryGetMeshVisual6(void)
1153 //Set up test application first, so everything else can be handled.
1154 ToolkitTestApplication application;
1156 tet_infoline( "UtcDaliVisualFactoryGetMeshVisual6: Request mesh visual and make it not use any textures." );
1158 //Set up visual properties.
1159 Property::Map propertyMap;
1160 propertyMap.Insert( "rendererType", "MESH" );
1161 propertyMap.Insert( "objectUrl", TEST_OBJ_FILE_NAME );
1162 propertyMap.Insert( "materialUrl", TEST_MTL_FILE_NAME );
1163 propertyMap.Insert( "texturesPath", TEST_RESOURCE_DIR "/" );
1164 propertyMap.Insert( "shaderType", "TEXTURELESS" );
1166 //Test to see if mesh loads correctly.
1167 MeshVisualLoadsCorrectlyTest( propertyMap, application );
1171 //Test if mesh visual loads correctly when light position is manually set.
1172 int UtcDaliVisualFactoryGetMeshVisual7(void)
1174 //Set up test application first, so everything else can be handled.
1175 ToolkitTestApplication application;
1178 tet_infoline( "UtcDaliVisualFactoryGetMeshVisual7: Request mesh visual with custom light position." );
1180 //Set up visual properties.
1181 Property::Map propertyMap;
1182 propertyMap.Insert( "rendererType", "MESH" );
1183 propertyMap.Insert( "objectUrl", TEST_OBJ_FILE_NAME );
1184 propertyMap.Insert( "materialUrl", TEST_MTL_FILE_NAME );
1185 propertyMap.Insert( "texturesPath", TEST_RESOURCE_DIR "/" );
1186 propertyMap.Insert( "lightPosition", Vector3( 0.0, 1.0, 2.0 ) );
1188 //Test to see if mesh loads correctly.
1189 MeshVisualLoadsCorrectlyTest( propertyMap, application );
1194 //Test if mesh visual loads correctly when supplied an object file without face normals or texture points.
1195 //Note that this notably tests object loader functionality.
1196 int UtcDaliVisualFactoryGetMeshVisual8(void)
1198 //Set up test application first, so everything else can be handled.
1199 ToolkitTestApplication application;
1201 tet_infoline( "UtcDaliVisualFactoryGetMeshVisual5: Request mesh visual with normal-less object file." );
1203 //Set up visual properties.
1204 Property::Map propertyMap;
1205 propertyMap.Insert( "rendererType", "MESH" );
1206 propertyMap.Insert( "objectUrl", TEST_SIMPLE_OBJ_FILE_NAME );
1207 propertyMap.Insert( "materialUrl", TEST_MTL_FILE_NAME );
1208 propertyMap.Insert( "texturesPath", TEST_RESOURCE_DIR "/" );
1210 //Test to see if mesh loads correctly.
1211 MeshVisualLoadsCorrectlyTest( propertyMap, application );
1216 //Test if mesh visual handles the case of lacking an object file.
1217 int UtcDaliVisualFactoryGetMeshVisualN1(void)
1219 //Set up test application first, so everything else can be handled.
1220 ToolkitTestApplication application;
1222 tet_infoline( "UtcDaliVisualFactoryGetMeshVisualN1: Request mesh visual without object file" );
1224 //Set up visual properties.
1225 Property::Map propertyMap;
1226 propertyMap.Insert( "rendererType", "MESH" );
1227 propertyMap.Insert( "materialUrl", TEST_MTL_FILE_NAME );
1228 propertyMap.Insert( "texturesPath", TEST_RESOURCE_DIR "/" );
1230 //Test to see if mesh doesn't load with these properties, as expected.
1231 MeshVisualDoesNotLoadCorrectlyTest( propertyMap, application );
1237 //Test if mesh visual handles the case of being passed invalid material and images urls.
1238 int UtcDaliVisualFactoryGetMeshVisualN2(void)
1240 //Set up test application first, so everything else can be handled.
1241 ToolkitTestApplication application;
1243 tet_infoline( "UtcDaliVisualFactoryGetMeshVisualN2: Request mesh visual with invalid material and images urls" );
1245 //Set up visual properties.
1246 Property::Map propertyMap;
1247 propertyMap.Insert( "rendererType", "MESH" );
1248 propertyMap.Insert( "objectUrl", TEST_OBJ_FILE_NAME );
1249 propertyMap.Insert( "materialUrl", "invalid" );
1250 propertyMap.Insert( "texturesPath", "also invalid" );
1252 //Test to see if mesh doesn't load with these properties, as expected.
1253 MeshVisualDoesNotLoadCorrectlyTest( propertyMap, application );
1259 //Test if mesh visual handles the case of being passed an invalid object url
1260 int UtcDaliVisualFactoryGetMeshVisualN3(void)
1262 //Set up test application first, so everything else can be handled.
1263 ToolkitTestApplication application;
1264 tet_infoline( "UtcDaliVisualFactoryGetMeshVisualN3: Request mesh visual with invalid object url" );
1267 //Set up visual properties.
1268 Property::Map propertyMap;
1269 propertyMap.Insert( "rendererType", "MESH" );
1270 propertyMap.Insert( "objectUrl", "invalid" );
1271 propertyMap.Insert( "materialUrl", TEST_MTL_FILE_NAME );
1272 propertyMap.Insert( "texturesPath", TEST_RESOURCE_DIR "/" );
1274 //Test to see if mesh doesn't load with these properties, as expected.
1275 MeshVisualDoesNotLoadCorrectlyTest( propertyMap, application );
1280 //Creates a primitive visual with the given property map and tests to see if it correctly loads in the given application.
1281 void TestPrimitiveVisualWithProperties( Property::Map& propertyMap, ToolkitTestApplication& application )
1283 VisualFactory factory = VisualFactory::Get();
1284 DALI_TEST_CHECK( factory );
1286 //Create a primitive visual.
1287 Visual visual = factory.CreateVisual( propertyMap );
1288 DALI_TEST_CHECK( visual );
1290 //Create an actor on stage to house the visual.
1291 Actor actor = Actor::New();
1292 actor.SetSize( 200.f, 200.f );
1293 Stage::GetCurrent().Add( actor );
1294 visual.SetSize( Vector2( 200.f, 200.f ) );
1295 visual.SetOnStage( actor );
1297 //Ensure set on stage.
1298 DALI_TEST_EQUALS( actor.GetRendererCount(), 1u, TEST_LOCATION );
1300 //Tell test application to load the visual.
1301 application.SendNotification();
1302 application.Render(0);
1304 Matrix testScaleMatrix;
1305 testScaleMatrix.SetIdentityAndScale( Vector3( 1.0, -1.0, 1.0 ) );
1306 Matrix actualScaleMatrix;
1308 //Test to see if the object has been successfully loaded.
1309 DALI_TEST_CHECK( application.GetGlAbstraction().GetUniformValue<Matrix>( "uObjectMatrix", actualScaleMatrix ) );
1310 DALI_TEST_EQUALS( actualScaleMatrix, testScaleMatrix, Math::MACHINE_EPSILON_100, TEST_LOCATION );
1312 //Finish by setting off stage, and ensuring this was successful.
1313 visual.SetOffStage( actor );
1314 DALI_TEST_EQUALS( actor.GetRendererCount(), 0u, TEST_LOCATION );
1317 //Test if primitive shape loads correctly when supplied with only the bare minimum requirements, the shape to use.
1318 int UtcDaliVisualFactoryGetPrimitiveVisual1(void)
1320 //Set up test application first, so everything else can be handled.
1321 ToolkitTestApplication application;
1323 tet_infoline( "UtcDaliVisualFactoryGetPrimitiveVisual1: Request primitive visual with a shape only" );
1325 //Set up visual properties.
1326 Property::Map propertyMap;
1327 propertyMap.Insert( "rendererType", "PRIMITIVE" );
1328 propertyMap.Insert( "shape", "CUBE" );
1330 //Test to see if shape loads correctly.
1331 TestPrimitiveVisualWithProperties( propertyMap, application );
1336 //Test if primitive shape loads correctly when supplied with all possible parameters
1337 int UtcDaliVisualFactoryGetPrimitiveVisual2(void)
1339 //Set up test application first, so everything else can be handled.
1340 ToolkitTestApplication application;
1342 tet_infoline( "UtcDaliVisualFactoryGetPrimitiveVisual2: Request primitive visual with everything" );
1344 //Set up visual properties.
1345 Property::Map propertyMap;
1346 propertyMap.Insert( "rendererType", "PRIMITIVE" );
1347 propertyMap.Insert( "shape", "CUBE" );
1348 propertyMap.Insert( "shapeColor", Vector4( 0.5, 0.5, 0.5, 1.0 ) );
1349 propertyMap.Insert( "slices", 10 );
1350 propertyMap.Insert( "stacks", 20 );
1351 propertyMap.Insert( "scaleTopRadius", 30.0f );
1352 propertyMap.Insert( "scaleBottomRadius", 40.0f );
1353 propertyMap.Insert( "scaleHeight", 50.0f );
1354 propertyMap.Insert( "scaleRadius", 60.0f );
1355 propertyMap.Insert( "bevelPercentage", 0.7f );
1356 propertyMap.Insert( "bevelSmoothness", 0.8f );
1357 propertyMap.Insert( "lightPosition", Vector3( 0.9, 1.0, 1.1 ) );
1359 //Test to see if shape loads correctly.
1360 TestPrimitiveVisualWithProperties( propertyMap, application );
1365 //Test if primitive shape loads a sphere correctly.
1366 int UtcDaliVisualFactoryGetPrimitiveVisual3(void)
1368 //Set up test application first, so everything else can be handled.
1369 ToolkitTestApplication application;
1371 tet_infoline( "UtcDaliVisualFactoryGetPrimitiveVisual3: Request primitive visual to display a sphere" );
1373 //Set up visual properties.
1374 Property::Map propertyMap;
1375 propertyMap.Insert( "rendererType", "PRIMITIVE" );
1376 propertyMap.Insert( "shape", "SPHERE" );
1377 propertyMap.Insert( "shapeColor", Vector4( 0.5, 0.5, 0.5, 1.0 ) );
1378 propertyMap.Insert( "slices", 10 );
1379 propertyMap.Insert( "stacks", 20 );
1381 //Test to see if shape loads correctly.
1382 TestPrimitiveVisualWithProperties( propertyMap, application );
1387 //Test if primitive shape loads a conic section correctly.
1388 int UtcDaliVisualFactoryGetPrimitiveVisual4(void)
1390 //Set up test application first, so everything else can be handled.
1391 ToolkitTestApplication application;
1393 tet_infoline( "UtcDaliVisualFactoryGetPrimitiveVisual4: Request primitive visual to display a conic section" );
1395 //Set up visual properties.
1396 Property::Map propertyMap;
1397 propertyMap.Insert( "rendererType", "PRIMITIVE" );
1398 propertyMap.Insert( "shape", "CONICAL_FRUSTRUM" );
1399 propertyMap.Insert( "shapeColor", Vector4( 0.5, 0.5, 0.5, 1.0 ) );
1400 propertyMap.Insert( "slices", 10 );
1401 propertyMap.Insert( "scaleTopRadius", 30.0f );
1402 propertyMap.Insert( "scaleBottomRadius", 40.0f );
1403 propertyMap.Insert( "scaleHeight", 50.0f );
1405 //Test to see if shape loads correctly.
1406 TestPrimitiveVisualWithProperties( propertyMap, application );
1411 //Test if primitive shape loads a bevelled cube correctly.
1412 int UtcDaliVisualFactoryGetPrimitiveVisual5(void)
1414 //Set up test application first, so everything else can be handled.
1415 ToolkitTestApplication application;
1417 tet_infoline( "UtcDaliVisualFactoryGetPrimitiveVisual5: Request primitive visual to display a bevelled cube" );
1419 //Set up visual properties.
1420 Property::Map propertyMap;
1421 propertyMap.Insert( "rendererType", "PRIMITIVE" );
1422 propertyMap.Insert( "shape", "BEVELLED_CUBE" );
1423 propertyMap.Insert( "shapeColor", Vector4( 0.5, 0.5, 0.5, 1.0 ) );
1424 propertyMap.Insert( "bevelPercentage", 0.7f );
1426 //Test to see if shape loads correctly.
1427 TestPrimitiveVisualWithProperties( propertyMap, application );
1432 //Test if primitive shape loads an octahedron correctly.
1433 int UtcDaliVisualFactoryGetPrimitiveVisual6(void)
1435 //Set up test application first, so everything else can be handled.
1436 ToolkitTestApplication application;
1438 tet_infoline( "UtcDaliVisualFactoryGetPrimitiveVisual6: Request primitive visual to display an octahedron" );
1440 //Set up visual properties.
1441 Property::Map propertyMap;
1442 propertyMap.Insert( "rendererType", "PRIMITIVE" );
1443 propertyMap.Insert( "shape", "OCTAHEDRON" );
1444 propertyMap.Insert( "shapeColor", Vector4( 0.5, 0.5, 0.5, 1.0 ) );
1446 //Test to see if shape loads correctly.
1447 TestPrimitiveVisualWithProperties( propertyMap, application );
1452 //Test if primitive shape loads a cone correctly.
1453 int UtcDaliVisualFactoryGetPrimitiveVisual7(void)
1455 //Set up test application first, so everything else can be handled.
1456 ToolkitTestApplication application;
1458 tet_infoline( "UtcDaliVisualFactoryGetPrimitiveVisual7: Request primitive visual to display a cone" );
1460 //Set up visual properties.
1461 Property::Map propertyMap;
1462 propertyMap.Insert( "rendererType", "PRIMITIVE" );
1463 propertyMap.Insert( "shape", "CONE" );
1464 propertyMap.Insert( "shapeColor", Vector4( 0.5, 0.5, 0.5, 1.0 ) );
1465 propertyMap.Insert( "slices", 10 );
1466 propertyMap.Insert( "scaleTopRadius", 30.0f );
1467 propertyMap.Insert( "scaleHeight", 50.0f );
1469 //Test to see if shape loads correctly.
1470 TestPrimitiveVisualWithProperties( propertyMap, application );
1475 //Test if primitive shape loads correctly when light position is manually set.
1476 int UtcDaliVisualFactoryGetPrimitiveVisual8(void)
1478 //Set up test application first, so everything else can be handled.
1479 ToolkitTestApplication application;
1481 tet_infoline( "UtcDaliVisualFactoryGetPrimitiveVisual8: Request primitive visual with set light position" );
1483 //Set up visual properties.
1484 Property::Map propertyMap;
1485 propertyMap.Insert( "rendererType", "PRIMITIVE" );
1486 propertyMap.Insert( "shape", "SPHERE" );
1487 propertyMap.Insert( "shapeColor", Vector4( 0.5, 0.5, 0.5, 1.0 ) );
1488 propertyMap.Insert( "lightPosition", Vector3( 0.0, 1.0, 2.0 ) );
1490 //Test to see if shape loads correctly.
1491 TestPrimitiveVisualWithProperties( propertyMap, application );
1496 //Test if primitive shape renderer handles the case of not being passed a specific shape to use.
1497 int UtcDaliVisualFactoryGetPrimitiveVisualN1(void)
1499 //Set up test application first, so everything else can be handled.
1500 ToolkitTestApplication application;
1502 tet_infoline( "UtcDaliVisualFactoryGetPrimitiveVisualN1: Request primitive visual without shape" );
1504 //Set up visual properties, without supplying shape.
1505 Property::Map propertyMap;
1506 propertyMap.Insert( "rendererType", "PRIMITIVE" );
1508 //Test to see if shape loads regardless of missing input.
1509 TestPrimitiveVisualWithProperties( propertyMap, application );