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>
25 #include <dali-toolkit/dali-toolkit.h>
28 using namespace Dali::Toolkit;
32 typedef NinePatchImage::StretchRanges StretchRanges;
34 const char* TEST_IMAGE_FILE_NAME = "gallery_image_01.jpg";
35 const char* TEST_NPATCH_FILE_NAME = "gallery_image_01.9.png";
37 const char* TEST_SVG_FILE_NAME = TEST_RESOURCE_DIR "/svg1.svg";
38 const char* TEST_OBJ_FILE_NAME = TEST_RESOURCE_DIR "/Cube.obj";
39 const char* TEST_MTL_FILE_NAME = TEST_RESOURCE_DIR "/ToyRobot-Metal.mtl";
40 const char* TEST_SIMPLE_OBJ_FILE_NAME = TEST_RESOURCE_DIR "/Cube-Points-Only.obj";
41 const char* TEST_SIMPLE_MTL_FILE_NAME = TEST_RESOURCE_DIR "/ToyRobot-Metal-Simple.mtl";
43 Integration::Bitmap* CreateBitmap( unsigned int imageWidth, unsigned int imageHeight, unsigned int initialColor, Pixel::Format pixelFormat )
45 Integration::Bitmap* bitmap = Integration::Bitmap::New( Integration::Bitmap::BITMAP_2D_PACKED_PIXELS, ResourcePolicy::OWNED_RETAIN );
46 Integration::PixelBuffer* pixbuffer = bitmap->GetPackedPixelsProfile()->ReserveBuffer( pixelFormat, imageWidth, imageHeight, imageWidth, imageHeight );
47 unsigned int bytesPerPixel = GetBytesPerPixel( pixelFormat );
49 memset( pixbuffer, initialColor, imageHeight * imageWidth * bytesPerPixel );
54 void InitialiseRegionsToZeroAlpha( Integration::Bitmap* image, unsigned int imageWidth, unsigned int imageHeight, Pixel::Format pixelFormat )
56 PixelBuffer* pixbuffer = image->GetBuffer();
57 unsigned int bytesPerPixel = GetBytesPerPixel( pixelFormat );
59 for( unsigned int row = 0; row < imageWidth; ++row )
61 unsigned int pixelOffset = row * bytesPerPixel;
62 pixbuffer[ pixelOffset + 3 ] = 0x00;
63 pixelOffset += ( imageHeight - 1 ) * imageWidth * bytesPerPixel;
64 pixbuffer[ pixelOffset + 3 ] = 0x00;
67 for ( unsigned int column = 0; column < imageHeight; ++column )
69 unsigned int pixelOffset = column * imageWidth * bytesPerPixel;
70 pixbuffer[ pixelOffset + 3 ] = 0x00;
71 pixelOffset += ( imageWidth -1 ) * bytesPerPixel;
72 pixbuffer[ pixelOffset + 3 ] = 0x00;
76 void AddStretchRegionsToImage( Integration::Bitmap* image, unsigned int imageWidth, unsigned int imageHeight, const StretchRanges& stretchRangesX, const StretchRanges& stretchRangesY, Pixel::Format pixelFormat )
78 PixelBuffer* pixbuffer = image->GetBuffer();
79 unsigned int bytesPerPixel = GetBytesPerPixel( pixelFormat );
81 for(StretchRanges::ConstIterator it = stretchRangesX.Begin(); it != stretchRangesX.End(); ++it)
83 const Uint16Pair& range = *it;
84 //since the stretch range is in the cropped image space, we need to offset by 1 to get it to the uncropped image space
85 for( unsigned int column = range.GetX() + 1u; column < range.GetY() + 1u; ++column )
87 unsigned int pixelOffset = column * bytesPerPixel;
88 pixbuffer[ pixelOffset ] = 0x00;
89 pixbuffer[ pixelOffset + 1 ] = 0x00;
90 pixbuffer[ pixelOffset + 2 ] = 0x00;
91 pixbuffer[ pixelOffset + 3 ] = 0xFF;
96 for(StretchRanges::ConstIterator it = stretchRangesY.Begin(); it != stretchRangesY.End(); ++it)
98 const Uint16Pair& range = *it;
99 //since the stretch range is in the cropped image space, we need to offset by 1 to get it to the uncropped image space
100 for( unsigned int row = range.GetX() + 1u; row < range.GetY() + 1u; ++row )
102 unsigned int pixelOffset = row * imageWidth * bytesPerPixel;
103 pixbuffer[ pixelOffset ] = 0x00;
104 pixbuffer[ pixelOffset + 1 ] = 0x00;
105 pixbuffer[ pixelOffset + 2 ] = 0x00;
106 pixbuffer[ pixelOffset + 3 ] = 0xFF;
111 void AddChildRegionsToImage( Integration::Bitmap* image, unsigned int imageWidth, unsigned int imageHeight, const Vector4& requiredChildRegion, Pixel::Format pixelFormat )
113 PixelBuffer* pixbuffer = image->GetBuffer();
114 unsigned int bytesPerPixel = GetBytesPerPixel( pixelFormat );
116 Integration::Bitmap::PackedPixelsProfile* srcProfile = image->GetPackedPixelsProfile();
117 unsigned int bufferStride = srcProfile->GetBufferStride();
119 // Add bottom child region
120 for( unsigned int column = requiredChildRegion.x; column < imageWidth - requiredChildRegion.z; ++column )
122 unsigned int pixelOffset = column * bytesPerPixel;
123 pixelOffset += ( imageHeight - 1 ) * bufferStride;
124 pixbuffer[ pixelOffset ] = 0x00;
125 pixbuffer[ pixelOffset + 1 ] = 0x00;
126 pixbuffer[ pixelOffset + 2 ] = 0x00;
127 pixbuffer[ pixelOffset + 3 ] = 0xFF;
130 // Add right child region
131 for ( unsigned int row = requiredChildRegion.y; row < imageHeight - requiredChildRegion.w; ++row )
133 unsigned int pixelOffset = row * bufferStride + ( imageWidth - 1 ) * bytesPerPixel;
134 pixbuffer[ pixelOffset ] = 0x00;
135 pixbuffer[ pixelOffset + 1 ] = 0x00;
136 pixbuffer[ pixelOffset + 2 ] = 0x00;
137 pixbuffer[ pixelOffset + 3 ] = 0xFF;
141 Integration::ResourcePointer CustomizeNinePatch( TestApplication& application,
142 unsigned int ninePatchImageWidth,
143 unsigned int ninePatchImageHeight,
144 const StretchRanges& stretchRangesX,
145 const StretchRanges& stretchRangesY,
146 bool addChildRegion = false,
147 Vector4 requiredChildRegion = Vector4::ZERO )
149 TestPlatformAbstraction& platform = application.GetPlatform();
151 Pixel::Format pixelFormat = Pixel::RGBA8888;
153 tet_infoline("Create Bitmap");
154 platform.SetClosestImageSize(Vector2( ninePatchImageWidth, ninePatchImageHeight));
155 Integration::Bitmap* bitmap = CreateBitmap( ninePatchImageWidth, ninePatchImageHeight, 0xFF, pixelFormat );
157 tet_infoline("Clear border regions");
158 InitialiseRegionsToZeroAlpha( bitmap, ninePatchImageWidth, ninePatchImageHeight, pixelFormat );
160 tet_infoline("Add Stretch regions to Bitmap");
161 AddStretchRegionsToImage( bitmap, ninePatchImageWidth, ninePatchImageHeight, stretchRangesX, stretchRangesY, pixelFormat );
165 tet_infoline("Add Child regions to Bitmap");
166 AddChildRegionsToImage( bitmap, ninePatchImageWidth, ninePatchImageHeight, requiredChildRegion, pixelFormat );
169 tet_infoline("Getting resource");
170 Integration::ResourcePointer resourcePtr(bitmap);
171 //platform.SetResourceLoaded( 0, Dali::Integration::ResourceBitmap, resourcePtr );
172 platform.SetSynchronouslyLoadedResource( resourcePtr);
177 void TestVisualRender( ToolkitTestApplication& application,
179 Visual::Base& visual,
180 std::size_t expectedSamplers = 0,
181 ImageDimensions imageDimensions = ImageDimensions(),
182 Integration::ResourcePointer resourcePtr = Integration::ResourcePointer())
186 // set the image size, for test case, this needs to be set before loading started
187 application.GetPlatform().SetClosestImageSize( Vector2(imageDimensions.GetWidth(), imageDimensions.GetHeight()) );
190 actor.SetSize( 200.f, 200.f );
191 Stage::GetCurrent().Add( actor );
192 visual.SetSize( Vector2(200.f, 200.f) );
193 visual.SetOnStage( actor );
195 DALI_TEST_CHECK( actor.GetRendererCount() == 1u );
197 application.SendNotification();
198 application.Render();
202 Integration::ResourceRequest* request = application.GetPlatform().GetRequest();
205 application.GetPlatform().SetResourceLoaded(request->GetId(), request->GetType()->id, resourcePtr );
209 application.Render();
210 application.SendNotification();
214 DALI_TEST_CHECK( application.GetPlatform().WasCalled(TestPlatformAbstraction::LoadResourceFunc) ||
215 application.GetPlatform().WasCalled(TestPlatformAbstraction::LoadResourceSynchronouslyFunc ));
218 DALI_TEST_CHECK( actor.GetRendererCount() == 1u );
225 void dali_visual_factory_startup(void)
227 test_return_value = TET_UNDEF;
230 void dali_visual_factory_cleanup(void)
232 test_return_value = TET_PASS;
235 int UtcDaliVisualFactoryGet(void)
237 ToolkitTestApplication application;
238 tet_infoline( "UtcDaliVisualFactory" );
242 type = TypeRegistry::Get().GetTypeInfo( "VisualFactory" );
243 DALI_TEST_CHECK( type );
244 BaseHandle handle = type.CreateInstance();
245 DALI_TEST_CHECK( handle );
247 VisualFactory factory;
248 factory = VisualFactory::Get();
249 DALI_TEST_CHECK( factory );
251 VisualFactory newFactory = VisualFactory::Get();
252 DALI_TEST_CHECK( newFactory );
254 // Check that renderer factory is a singleton
255 DALI_TEST_CHECK(factory == newFactory);
260 int UtcDaliVisualFactoryCopyAndAssignment(void)
262 ToolkitTestApplication application;
263 tet_infoline( "UtcDaliVisualFactoryCopyAndAssignment" );
264 VisualFactory factory = VisualFactory::Get();
266 VisualFactory factoryCopy( factory );
267 DALI_TEST_CHECK(factory == factoryCopy);
269 VisualFactory emptyFactory;
270 VisualFactory emptyFactoryCopy( emptyFactory );
271 DALI_TEST_CHECK(emptyFactory == emptyFactoryCopy);
273 VisualFactory factoryEquals;
274 factoryEquals = factory;
275 DALI_TEST_CHECK(factory == factoryEquals);
277 VisualFactory emptyFactoryEquals;
278 emptyFactoryEquals = emptyFactory;
279 DALI_TEST_CHECK( emptyFactory == emptyFactoryEquals );
283 DALI_TEST_CHECK( factory = factoryCopy );
288 int UtcDaliVisualFactoryGetColorVisual1(void)
290 ToolkitTestApplication application;
291 tet_infoline( "UtcDaliVisualFactoryGetColorVisual1: Request color visual with a Property::Map" );
293 VisualFactory factory = VisualFactory::Get();
294 DALI_TEST_CHECK( factory );
296 Property::Map propertyMap;
297 Vector4 testColor( 1.f, 0.5f, 0.3f, 0.2f );
298 propertyMap.Insert(Visual::Property::TYPE, Visual::COLOR);
299 propertyMap.Insert(ColorVisual::Property::MIX_COLOR, testColor);
301 Visual::Base visual = factory.CreateVisual(propertyMap);
302 DALI_TEST_CHECK( visual );
304 Actor actor = Actor::New();
305 TestVisualRender( application, actor, visual );
307 Vector4 actualValue(Vector4::ZERO);
308 TestGlAbstraction& gl = application.GetGlAbstraction();
309 DALI_TEST_CHECK( gl.GetUniformValue<Vector4>( "mixColor", actualValue ) );
310 DALI_TEST_EQUALS( actualValue, testColor, TEST_LOCATION );
315 int UtcDaliVisualFactoryGetColorVisual2(void)
317 ToolkitTestApplication application;
318 tet_infoline( "UtcDaliVisualFactoryGetColorVisual2: Request color visual with a Vector4" );
320 VisualFactory factory = VisualFactory::Get();
321 DALI_TEST_CHECK( factory );
323 Vector4 testColor( 1.f, 0.5f, 0.3f, 0.2f );
324 Dali::Property::Map map;
325 map[ Visual::Property::TYPE ] = Visual::COLOR;
326 map[ ColorVisual::Property::MIX_COLOR ] = testColor;
327 Visual::Base visual = factory.CreateVisual( map );
328 DALI_TEST_CHECK( visual );
330 Actor actor = Actor::New();
331 TestVisualRender( application, actor, visual );
333 Vector4 actualValue(Vector4::ZERO);
334 TestGlAbstraction& gl = application.GetGlAbstraction();
335 DALI_TEST_CHECK( gl.GetUniformValue<Vector4>( "mixColor", actualValue ) );
336 DALI_TEST_EQUALS( actualValue, testColor, TEST_LOCATION );
338 visual.SetOffStage( actor );
339 DALI_TEST_CHECK( actor.GetRendererCount() == 0u );
344 int UtcDaliVisualFactoryGetBorderVisual1(void)
346 ToolkitTestApplication application;
347 tet_infoline( "UtcDaliVisualFactoryGetBorderVisual1: Request border visual with a Property::Map" );
349 VisualFactory factory = VisualFactory::Get();
350 DALI_TEST_CHECK( factory );
352 Property::Map propertyMap;
353 Vector4 testColor( 1.f, 0.5f, 0.3f, 0.2f );
354 float testSize = 5.f;
355 propertyMap.Insert(Visual::Property::TYPE, Visual::BORDER);
356 propertyMap.Insert(BorderVisual::Property::COLOR, testColor);
357 propertyMap.Insert(BorderVisual::Property::SIZE, testSize);
359 Visual::Base visual = factory.CreateVisual(propertyMap);
360 DALI_TEST_CHECK( visual );
362 Actor actor = Actor::New();
363 actor.SetSize(200.f, 200.f);
364 Stage::GetCurrent().Add( actor );
365 visual.SetSize(Vector2(200.f, 200.f));
366 visual.SetOnStage( actor );
368 DALI_TEST_CHECK( actor.GetRendererCount() == 1u );
369 int blendMode = actor.GetRendererAt(0u).GetProperty<int>( Renderer::Property::BLEND_MODE );
370 DALI_TEST_EQUALS( static_cast<BlendingMode::Type>(blendMode), BlendingMode::ON, TEST_LOCATION );
372 TestGlAbstraction& gl = application.GetGlAbstraction();
374 application.SendNotification();
375 application.Render(0);
377 Vector4 actualColor(Vector4::ZERO);
378 DALI_TEST_CHECK( gl.GetUniformValue<Vector4>( "borderColor", actualColor ) );
379 DALI_TEST_EQUALS( actualColor, testColor, TEST_LOCATION );
381 float actualSize = 0.f;
382 DALI_TEST_CHECK( gl.GetUniformValue<float>( "borderSize", actualSize ) );
383 DALI_TEST_EQUALS( actualSize, testSize, TEST_LOCATION );
385 visual.SetOffStage( actor );
386 DALI_TEST_CHECK( actor.GetRendererCount() == 0u );
391 int UtcDaliVisualFactoryGetBorderVisual2(void)
393 ToolkitTestApplication application;
394 tet_infoline( "UtcDaliVisualFactoryGetBorderVisual2: Request border visual with a borderSize and a borderColor" );
396 VisualFactory factory = VisualFactory::Get();
397 DALI_TEST_CHECK( factory );
399 Vector4 testColor( 1.f, 0.5f, 0.3f, 1.f );
400 float testSize = 5.f;
402 Dali::Property::Map propertyMap;
403 propertyMap[ Visual::Property::TYPE ] = Visual::BORDER;
404 propertyMap[ BorderVisual::Property::COLOR ] = testColor;
405 propertyMap[ BorderVisual::Property::SIZE ] = testSize;
406 Visual::Base visual = factory.CreateVisual( propertyMap );
407 DALI_TEST_CHECK( visual );
409 Actor actor = Actor::New();
410 actor.SetSize(200.f, 200.f);
411 Stage::GetCurrent().Add( actor );
412 visual.SetSize(Vector2(200.f, 200.f));
413 visual.SetOnStage( actor );
415 DALI_TEST_CHECK( actor.GetRendererCount() == 1u );
417 TestGlAbstraction& gl = application.GetGlAbstraction();
419 application.SendNotification();
420 application.Render(0);
422 int blendMode = actor.GetRendererAt(0u).GetProperty<int>( Renderer::Property::BLEND_MODE );
423 DALI_TEST_EQUALS( static_cast<BlendingMode::Type>(blendMode), BlendingMode::AUTO, TEST_LOCATION );
425 Vector4 actualColor(Vector4::ZERO);
426 DALI_TEST_CHECK( gl.GetUniformValue<Vector4>( "borderColor", actualColor ) );
427 DALI_TEST_EQUALS( actualColor, testColor, TEST_LOCATION );
429 float actualSize = 0.f;
430 DALI_TEST_CHECK( gl.GetUniformValue<float>( "borderSize", actualSize ) );
431 DALI_TEST_EQUALS( actualSize, testSize, TEST_LOCATION );
433 visual.SetOffStage( actor );
435 // enable the anti-aliasing
436 Dali::Property::Map map;
437 map[ Visual::Property::TYPE ] = Visual::BORDER;
438 map[ BorderVisual::Property::COLOR ] = testColor;
439 map[ BorderVisual::Property::SIZE ] = testSize;
440 map[ BorderVisual::Property::ANTI_ALIASING ] = true;
441 visual = factory.CreateVisual( map );
442 visual.SetOnStage( actor );
444 application.SendNotification();
445 application.Render(0);
446 blendMode = actor.GetRendererAt(0u).GetProperty<int>( Renderer::Property::BLEND_MODE );
447 DALI_TEST_EQUALS( static_cast<BlendingMode::Type>(blendMode), BlendingMode::ON, TEST_LOCATION );
452 int UtcDaliVisualFactoryGetLinearGradientVisual(void)
454 ToolkitTestApplication application;
455 tet_infoline("UtcDaliVisualFactoryGetRadialGradientVisual");
457 VisualFactory factory = VisualFactory::Get();
458 DALI_TEST_CHECK( factory );
460 Property::Map propertyMap;
461 propertyMap.Insert(Visual::Property::TYPE, Visual::GRADIENT);
463 Vector2 start(-1.f, -1.f);
464 Vector2 end(1.f, 1.f);
465 propertyMap.Insert(GradientVisual::Property::START_POSITION, start);
466 propertyMap.Insert(GradientVisual::Property::END_POSITION, end);
467 propertyMap.Insert(GradientVisual::Property::SPREAD_METHOD, GradientVisual::SpreadMethod::REPEAT);
469 Property::Array stopOffsets;
470 stopOffsets.PushBack( 0.2f );
471 stopOffsets.PushBack( 0.8f );
472 propertyMap.Insert(GradientVisual::Property::STOP_OFFSET, stopOffsets);
474 Property::Array stopColors;
475 stopColors.PushBack( Color::RED );
476 stopColors.PushBack( Color::GREEN );
477 propertyMap.Insert(GradientVisual::Property::STOP_COLOR, stopColors);
479 Visual::Base visual = factory.CreateVisual(propertyMap);
480 DALI_TEST_CHECK( visual );
482 // A lookup texture is generated and pass to shader as sampler
483 Actor actor = Actor::New();
484 TestVisualRender( application, actor, visual, 1u );
486 visual.SetOffStage( actor );
487 DALI_TEST_CHECK( actor.GetRendererCount() == 0u );
492 int UtcDaliVisualFactoryGetRadialGradientVisual(void)
494 ToolkitTestApplication application;
495 tet_infoline("UtcDaliVisualFactoryGetRadialGradientVisual");
497 VisualFactory factory = VisualFactory::Get();
498 DALI_TEST_CHECK( factory );
500 Property::Map propertyMap;
501 propertyMap.Insert(Visual::Property::TYPE, Visual::GRADIENT);
503 Vector2 center(100.f, 100.f);
504 float radius = 100.f;
505 propertyMap.Insert(GradientVisual::Property::UNITS, GradientVisual::Units::USER_SPACE);
506 propertyMap.Insert(GradientVisual::Property::CENTER, center);
507 propertyMap.Insert(GradientVisual::Property::RADIUS, radius);
509 Property::Array stopOffsets;
510 stopOffsets.PushBack( 0.0f );
511 stopOffsets.PushBack( 1.f );
512 propertyMap.Insert(GradientVisual::Property::STOP_OFFSET, stopOffsets);
514 Property::Array stopColors;
515 stopColors.PushBack( Color::RED );
516 stopColors.PushBack( Color::GREEN );
517 propertyMap.Insert(GradientVisual::Property::STOP_COLOR, stopColors);
519 Visual::Base visual = factory.CreateVisual(propertyMap);
520 DALI_TEST_CHECK( visual );
522 // A lookup texture is generated and pass to shader as sampler
523 Actor actor = Actor::New();
524 TestVisualRender( application, actor, visual, 1u );
526 Matrix3 alignMatrix( radius, 0.f, 0.f, 0.f, radius, 0.f, center.x, center.y, 1.f );
527 alignMatrix.Invert();
529 Matrix3 actualValue( Matrix3::IDENTITY );
530 TestGlAbstraction& gl = application.GetGlAbstraction();
531 DALI_TEST_CHECK( gl.GetUniformValue<Matrix3>( "uAlignmentMatrix", actualValue ) );
532 DALI_TEST_EQUALS( actualValue, alignMatrix, Math::MACHINE_EPSILON_100, TEST_LOCATION );
537 int UtcDaliVisualFactoryDefaultOffsetsGradientVisual(void)
539 ToolkitTestApplication application;
540 tet_infoline("UtcDaliVisualFactoryGetRadialGradientVisual");
542 VisualFactory factory = VisualFactory::Get();
543 DALI_TEST_CHECK( factory );
545 Property::Map propertyMap;
546 propertyMap.Insert(Visual::Property::TYPE, Visual::GRADIENT);
548 Vector2 start(-1.f, -1.f);
549 Vector2 end(1.f, 1.f);
550 propertyMap.Insert(GradientVisual::Property::START_POSITION, start);
551 propertyMap.Insert(GradientVisual::Property::END_POSITION, end);
552 propertyMap.Insert(GradientVisual::Property::SPREAD_METHOD, GradientVisual::SpreadMethod::REPEAT);
554 Property::Array stopColors;
555 stopColors.PushBack( Color::RED );
556 stopColors.PushBack( Color::GREEN );
557 propertyMap.Insert(GradientVisual::Property::STOP_COLOR, stopColors);
559 Visual::Base visual = factory.CreateVisual(propertyMap);
560 DALI_TEST_CHECK( visual );
562 // A lookup texture is generated and pass to shader as sampler
563 Actor actor = Actor::New();
564 TestVisualRender( application, actor, visual, 1u );
566 visual.SetOffStage( actor );
567 DALI_TEST_CHECK( actor.GetRendererCount() == 0u );
572 int UtcDaliVisualFactoryGetImageVisual1(void)
574 ToolkitTestApplication application;
575 tet_infoline( "UtcDaliVisualFactoryGetImageVisual1: Request image renderer with a Property::Map" );
577 VisualFactory factory = VisualFactory::Get();
578 DALI_TEST_CHECK( factory );
580 Property::Map propertyMap;
581 propertyMap.Insert( Visual::Property::TYPE, Visual::IMAGE );
582 propertyMap.Insert( ImageVisual::Property::URL, TEST_IMAGE_FILE_NAME );
584 Visual::Base visual = factory.CreateVisual( propertyMap );
585 DALI_TEST_CHECK( visual );
587 Actor actor = Actor::New();
588 // For tesing the LoadResourceFunc is called, a big image size should be set, so the atlasing is not applied.
589 // Image with a size smaller than 512*512 will be uploaded as a part of the atlas.
592 const int height=513;
593 TestGlAbstraction& gl = application.GetGlAbstraction();
594 TraceCallStack& textureTrace = gl.GetTextureTrace();
595 textureTrace.Enable(true);
597 Integration::Bitmap* bitmap = Integration::Bitmap::New( Integration::Bitmap::BITMAP_2D_PACKED_PIXELS, ResourcePolicy::OWNED_DISCARD );
598 bitmap->GetPackedPixelsProfile()->ReserveBuffer( Pixel::RGBA8888, width, height,width, height );
600 TestVisualRender( application, actor, visual, 1u,
601 ImageDimensions(width, height),
602 Integration::ResourcePointer( bitmap ) );
604 DALI_TEST_EQUALS( textureTrace.FindMethod("BindTexture"), true, TEST_LOCATION );
606 visual.SetOffStage( actor );
607 DALI_TEST_CHECK( actor.GetRendererCount() == 0u );
612 int UtcDaliVisualFactoryGetImageVisual2(void)
614 ToolkitTestApplication application;
615 tet_infoline( "UtcDaliVisualFactoryGetImageVisual2: Request image renderer with an image handle" );
617 VisualFactory factory = VisualFactory::Get();
618 DALI_TEST_CHECK( factory );
620 Image image = ResourceImage::New(TEST_IMAGE_FILE_NAME);
621 Visual::Base visual = factory.CreateVisual( image );
623 Actor actor = Actor::New();
624 // For tesing the LoadResourceFunc is called, a big image size should be set, so the atlasing is not applied.
625 // Image with a size smaller than 512*512 will be uploaded as a part of the atlas.
628 const int height=513;
630 Integration::Bitmap* bitmap = Integration::Bitmap::New( Integration::Bitmap::BITMAP_2D_PACKED_PIXELS, ResourcePolicy::OWNED_DISCARD );
631 bitmap->GetPackedPixelsProfile()->ReserveBuffer( Pixel::RGBA8888, width, height,width, height );
633 TestGlAbstraction& gl = application.GetGlAbstraction();
634 TraceCallStack& textureTrace = gl.GetTextureTrace();
635 textureTrace.Enable(true);
637 TestVisualRender( application, actor, visual, 1u,
638 ImageDimensions(width, height),
639 Integration::ResourcePointer(bitmap) );
641 DALI_TEST_EQUALS( textureTrace.FindMethod("BindTexture"), true, TEST_LOCATION );
646 int UtcDaliVisualFactoryGetNPatchVisual1(void)
648 ToolkitTestApplication application;
649 tet_infoline( "UtcDaliVisualFactoryGetNPatchVisual1: Request 9-patch renderer with a Property::Map" );
651 VisualFactory factory = VisualFactory::Get();
652 DALI_TEST_CHECK( factory );
654 const unsigned int ninePatchImageHeight = 18;
655 const unsigned int ninePatchImageWidth = 28;
656 StretchRanges stretchRangesX;
657 stretchRangesX.PushBack( Uint16Pair( 2, 3 ) );
658 StretchRanges stretchRangesY;
659 stretchRangesY.PushBack( Uint16Pair( 4, 5 ) );
660 Integration::ResourcePointer ninePatchResource = CustomizeNinePatch( application, ninePatchImageWidth, ninePatchImageHeight, stretchRangesX, stretchRangesY );
662 Property::Map propertyMap;
663 propertyMap.Insert( Visual::Property::TYPE, Visual::IMAGE );
664 propertyMap.Insert( ImageVisual::Property::URL, TEST_NPATCH_FILE_NAME );
666 tet_infoline( "whole grid" );
667 Visual::Base visual = factory.CreateVisual( propertyMap );
668 DALI_TEST_CHECK( visual );
670 Actor actor = Actor::New();
672 TestGlAbstraction& gl = application.GetGlAbstraction();
673 TraceCallStack& textureTrace = gl.GetTextureTrace();
674 textureTrace.Enable(true);
676 TestVisualRender( application, actor, visual, 1u,
677 ImageDimensions(ninePatchImageWidth, ninePatchImageHeight),
680 DALI_TEST_EQUALS( textureTrace.FindMethod("BindTexture"), true, TEST_LOCATION );
683 propertyMap.Insert( ImageVisual::Property::BORDER_ONLY, true );
685 tet_infoline( "border only" );
686 Visual::Base visual = factory.CreateVisual( propertyMap );
687 DALI_TEST_CHECK( visual );
689 Actor actor = Actor::New();
691 TestGlAbstraction& gl = application.GetGlAbstraction();
692 TraceCallStack& textureTrace = gl.GetTextureTrace();
693 textureTrace.Enable(true);
695 TestVisualRender( application, actor, visual, 1u,
696 ImageDimensions(ninePatchImageWidth, ninePatchImageHeight),
699 DALI_TEST_EQUALS( textureTrace.FindMethod("BindTexture"), true, TEST_LOCATION );
705 int UtcDaliVisualFactoryGetNPatchVisual2(void)
707 ToolkitTestApplication application;
708 tet_infoline( "UtcDaliVisualFactoryGetNPatchVisual2: Request n-patch renderer with a Property::Map" );
710 VisualFactory factory = VisualFactory::Get();
711 DALI_TEST_CHECK( factory );
713 const unsigned int ninePatchImageWidth = 18;
714 const unsigned int ninePatchImageHeight = 28;
715 StretchRanges stretchRangesX;
716 stretchRangesX.PushBack( Uint16Pair( 2, 3 ) );
717 stretchRangesX.PushBack( Uint16Pair( 5, 7 ) );
718 stretchRangesX.PushBack( Uint16Pair( 12, 15 ) );
719 StretchRanges stretchRangesY;
720 stretchRangesY.PushBack( Uint16Pair( 4, 5 ) );
721 stretchRangesY.PushBack( Uint16Pair( 8, 12 ) );
722 stretchRangesY.PushBack( Uint16Pair( 15, 16 ) );
723 stretchRangesY.PushBack( Uint16Pair( 25, 27 ) );
724 Integration::ResourcePointer ninePatchResource = CustomizeNinePatch( application, ninePatchImageWidth, ninePatchImageHeight, stretchRangesX, stretchRangesY );
726 Property::Map propertyMap;
727 propertyMap.Insert( Visual::Property::TYPE, Visual::IMAGE );
728 propertyMap.Insert( ImageVisual::Property::URL, TEST_NPATCH_FILE_NAME );
730 Visual::Base visual = factory.CreateVisual( propertyMap );
731 DALI_TEST_CHECK( visual );
733 Actor actor = Actor::New();
734 TestGlAbstraction& gl = application.GetGlAbstraction();
735 TraceCallStack& textureTrace = gl.GetTextureTrace();
736 textureTrace.Enable(true);
738 TestVisualRender( application, actor, visual, 1u,
739 ImageDimensions(ninePatchImageWidth, ninePatchImageHeight),
743 DALI_TEST_EQUALS( textureTrace.FindMethod("BindTexture"), true, TEST_LOCATION );
745 visual.SetOffStage( actor );
746 DALI_TEST_CHECK( actor.GetRendererCount() == 0u );
749 propertyMap.Insert( ImageVisual::Property::BORDER_ONLY, true );
751 tet_infoline( "border only" );
752 Visual::Base visual = factory.CreateVisual( propertyMap );
753 DALI_TEST_CHECK( visual );
755 TestGlAbstraction& gl = application.GetGlAbstraction();
756 TraceCallStack& textureTrace = gl.GetTextureTrace();
757 textureTrace.Enable(true);
758 Actor actor = Actor::New();
759 TestVisualRender( application, actor, visual, 1u,
760 ImageDimensions(ninePatchImageWidth, ninePatchImageHeight),
764 DALI_TEST_EQUALS( textureTrace.FindMethod("BindTexture"), true, TEST_LOCATION );
766 visual.SetOffStage( actor );
767 DALI_TEST_CHECK( actor.GetRendererCount() == 0u );
773 int UtcDaliVisualFactoryGetNPatchVisual3(void)
775 ToolkitTestApplication application;
776 tet_infoline( "UtcDaliVisualFactoryGetNPatchVisual3: Request 9-patch renderer with an image url" );
778 VisualFactory factory = VisualFactory::Get();
779 DALI_TEST_CHECK( factory );
781 const unsigned int ninePatchImageHeight = 18;
782 const unsigned int ninePatchImageWidth = 28;
783 StretchRanges stretchRangesX;
784 stretchRangesX.PushBack( Uint16Pair( 2, 3 ) );
785 StretchRanges stretchRangesY;
786 stretchRangesY.PushBack( Uint16Pair( 4, 5 ) );
787 Integration::ResourcePointer ninePatchResource = CustomizeNinePatch( application, ninePatchImageWidth, ninePatchImageHeight, stretchRangesX, stretchRangesY );
789 Visual::Base visual = factory.CreateVisual( TEST_NPATCH_FILE_NAME, ImageDimensions() );
790 DALI_TEST_CHECK( visual );
792 Actor actor = Actor::New();
794 TestGlAbstraction& gl = application.GetGlAbstraction();
795 TraceCallStack& textureTrace = gl.GetTextureTrace();
796 textureTrace.Enable(true);
798 TestVisualRender( application, actor, visual, 1u,
799 ImageDimensions(ninePatchImageWidth, ninePatchImageHeight),
802 DALI_TEST_EQUALS( textureTrace.FindMethod("BindTexture"), true, TEST_LOCATION );
807 int UtcDaliVisualFactoryGetNPatchVisual4(void)
809 ToolkitTestApplication application;
810 tet_infoline( "UtcDaliVisualFactoryGetNPatchVisual4: Request n-patch visual with an image url" );
812 VisualFactory factory = VisualFactory::Get();
813 DALI_TEST_CHECK( factory );
815 const unsigned int ninePatchImageHeight = 18;
816 const unsigned int ninePatchImageWidth = 28;
817 StretchRanges stretchRangesX;
818 stretchRangesX.PushBack( Uint16Pair( 2, 3 ) );
819 stretchRangesX.PushBack( Uint16Pair( 5, 7 ) );
820 stretchRangesX.PushBack( Uint16Pair( 12, 15 ) );
821 StretchRanges stretchRangesY;
822 stretchRangesY.PushBack( Uint16Pair( 4, 5 ) );
823 stretchRangesY.PushBack( Uint16Pair( 8, 12 ) );
824 stretchRangesY.PushBack( Uint16Pair( 15, 16 ) );
825 stretchRangesY.PushBack( Uint16Pair( 25, 27 ) );
826 Integration::ResourcePointer ninePatchResource = CustomizeNinePatch( application, ninePatchImageWidth, ninePatchImageHeight, stretchRangesX, stretchRangesY );
828 Visual::Base visual = factory.CreateVisual( TEST_NPATCH_FILE_NAME, ImageDimensions() );
829 DALI_TEST_CHECK( visual );
831 Actor actor = Actor::New();
833 TestGlAbstraction& gl = application.GetGlAbstraction();
834 TraceCallStack& textureTrace = gl.GetTextureTrace();
835 textureTrace.Enable(true);
837 TestVisualRender( application, actor, visual, 1u,
838 ImageDimensions(ninePatchImageWidth, ninePatchImageHeight),
841 DALI_TEST_EQUALS( textureTrace.FindMethod("BindTexture"), true, TEST_LOCATION );
846 int UtcDaliVisualFactoryGetNPatchVisualN1(void)
848 //This should still load but display an error image
850 ToolkitTestApplication application;
851 tet_infoline( "UtcDaliVisualFactoryGetNPatchVisualN: Request n-patch visual with an invalid image url" );
853 VisualFactory factory = VisualFactory::Get();
854 DALI_TEST_CHECK( factory );
856 Visual::Base visual = factory.CreateVisual( "ERROR.9.jpg", ImageDimensions() );
857 DALI_TEST_CHECK( visual );
859 Actor actor = Actor::New();
861 //The testkit still has to load a bitmap for the broken renderer image
862 Integration::Bitmap* bitmap = Integration::Bitmap::New(Integration::Bitmap::BITMAP_2D_PACKED_PIXELS, ResourcePolicy::OWNED_DISCARD);
863 bitmap->GetPackedPixelsProfile()->ReserveBuffer( Pixel::RGBA8888, 100, 100, 100, 100 );
865 TestGlAbstraction& gl = application.GetGlAbstraction();
866 TraceCallStack& textureTrace = gl.GetTextureTrace();
867 textureTrace.Enable(true);
869 TestVisualRender( application, actor, visual, 1u,
871 Integration::ResourcePointer(bitmap) );
873 DALI_TEST_EQUALS( textureTrace.FindMethod("BindTexture"), true, TEST_LOCATION );
878 int UtcDaliVisualFactoryGetNPatchVisualN2(void)
880 //This should still load but display an error image
882 ToolkitTestApplication application;
883 tet_infoline( "UtcDaliVisualFactoryGetNPatchVisualN: Request n-patch visual with an invalid Property::Map" );
885 VisualFactory factory = VisualFactory::Get();
886 DALI_TEST_CHECK( factory );
888 Property::Map propertyMap;
889 propertyMap.Insert( Visual::Property::TYPE, 111 );
890 propertyMap.Insert( ImageVisual::Property::URL, "ERROR.9.jpg" );
892 Visual::Base visual = factory.CreateVisual( propertyMap );
893 DALI_TEST_CHECK( visual );
895 Actor actor = Actor::New();
897 //The testkit still has to load a bitmap for the broken renderer image
898 Integration::Bitmap* bitmap = Integration::Bitmap::New(Integration::Bitmap::BITMAP_2D_PACKED_PIXELS, ResourcePolicy::OWNED_DISCARD);
899 bitmap->GetPackedPixelsProfile()->ReserveBuffer( Pixel::RGBA8888, 100, 100, 100, 100 );
901 TestGlAbstraction& gl = application.GetGlAbstraction();
902 TraceCallStack& textureTrace = gl.GetTextureTrace();
903 textureTrace.Enable(true);
905 TestVisualRender( application, actor, visual, 1u,
907 Integration::ResourcePointer(bitmap) );
909 DALI_TEST_EQUALS( textureTrace.FindMethod("BindTexture"), true, TEST_LOCATION );
914 int UtcDaliVisualFactoryGetSvgVisual(void)
916 ToolkitTestApplication application;
917 tet_infoline( "UtcDaliVisualFactoryGetSvgVisual: Request svg visual with a svg url" );
919 VisualFactory factory = VisualFactory::Get();
920 Visual::Base visual = factory.CreateVisual( TEST_SVG_FILE_NAME, ImageDimensions() );
921 DALI_TEST_CHECK( visual );
923 TestGlAbstraction& gl = application.GetGlAbstraction();
924 TraceCallStack& textureTrace = gl.GetTextureTrace();
925 textureTrace.Enable(true);
927 Actor actor = Actor::New();
928 actor.SetSize( 200.f, 200.f );
929 Stage::GetCurrent().Add( actor );
930 visual.SetSize( Vector2(200.f, 200.f) );
931 visual.SetOnStage( actor );
932 application.SendNotification();
933 application.Render();
935 DALI_TEST_CHECK( actor.GetRendererCount() == 1u );
937 EventThreadCallback* eventTrigger = EventThreadCallback::Get();
938 CallbackBase* callback = eventTrigger->GetCallback();
940 eventTrigger->WaitingForTrigger( 1 );// waiting until the svg image is rasterized.
941 CallbackBase::Execute( *callback );
943 DALI_TEST_CHECK( actor.GetRendererCount() == 1u );
945 // waiting for the resource uploading
946 application.SendNotification();
947 application.Render();
949 DALI_TEST_EQUALS( textureTrace.FindMethod("BindTexture"), true, TEST_LOCATION );
954 //Creates a mesh renderer from the given propertyMap and tries to load it on stage in the given application.
955 //This is expected to succeed, which will then pass the test.
956 void MeshVisualLoadsCorrectlyTest( Property::Map& propertyMap, ToolkitTestApplication& application )
958 VisualFactory factory = VisualFactory::Get();
959 DALI_TEST_CHECK( factory );
961 //Create a mesh visual.
962 Visual::Base visual = factory.CreateVisual( propertyMap );
963 DALI_TEST_CHECK( visual );
965 //Create an actor on stage to house the visual.
966 Actor actor = Actor::New();
967 actor.SetSize( 200.f, 200.f );
968 Stage::GetCurrent().Add( actor );
969 visual.SetSize( Vector2( 200.f, 200.f ) );
970 visual.SetOnStage( actor );
972 //Ensure set on stage.
973 DALI_TEST_EQUALS( actor.GetRendererCount(), 1u, TEST_LOCATION );
975 //Attempt to render to queue resource load requests.
976 application.SendNotification();
977 application.Render( 0 );
979 //Tell the platform abstraction that the required resources have been loaded.
980 TestPlatformAbstraction& platform = application.GetPlatform();
981 platform.SetAllResourceRequestsAsLoaded();
983 //Render again to upload the now-loaded textures.
984 application.SendNotification();
985 application.Render( 0 );
987 Matrix testScaleMatrix;
988 testScaleMatrix.SetIdentityAndScale( Vector3( 1.0, -1.0, 1.0 ) );
989 Matrix actualScaleMatrix;
991 //Test to see if the object has been successfully loaded.
992 DALI_TEST_CHECK( application.GetGlAbstraction().GetUniformValue<Matrix>( "uObjectMatrix", actualScaleMatrix ) );
993 DALI_TEST_EQUALS( actualScaleMatrix, testScaleMatrix, Math::MACHINE_EPSILON_100, TEST_LOCATION );
995 //Finish by setting off stage, and ensuring this was successful.
996 visual.SetOffStage( actor );
997 DALI_TEST_EQUALS( actor.GetRendererCount(), 0u, TEST_LOCATION );
1000 //Creates a mesh visual from the given propertyMap and tries to load it on stage in the given application.
1001 //This is expected to fail, which will then pass the test.
1002 void MeshVisualDoesNotLoadCorrectlyTest( Property::Map& propertyMap, ToolkitTestApplication& application )
1004 VisualFactory factory = VisualFactory::Get();
1005 DALI_TEST_CHECK( factory );
1007 //Create a mesh visual.
1008 Visual::Base visual = factory.CreateVisual( propertyMap );
1009 DALI_TEST_CHECK( visual );
1011 //Create an actor on stage to house the visual.
1012 Actor actor = Actor::New();
1013 actor.SetSize( 200.f, 200.f );
1014 Stage::GetCurrent().Add( actor );
1015 visual.SetSize( Vector2( 200.f, 200.f ) );
1016 visual.SetOnStage( actor );
1018 //Ensure set on stage.
1019 DALI_TEST_EQUALS( actor.GetRendererCount(), 1u, TEST_LOCATION );
1021 //Attempt to render to queue resource load requests.
1022 application.SendNotification();
1023 application.Render( 0 );
1025 //Tell the platform abstraction that the required resources have been loaded.
1026 TestPlatformAbstraction& platform = application.GetPlatform();
1027 platform.SetAllResourceRequestsAsLoaded();
1029 //Render again to upload the now-loaded textures.
1030 application.SendNotification();
1031 application.Render( 0 );
1033 //Test to see if the object has not been loaded, as expected.
1035 DALI_TEST_CHECK( !application.GetGlAbstraction().GetUniformValue<Matrix>( "uObjectMatrix", scaleMatrix ) );
1037 //Finish by setting off stage, and ensuring this was successful.
1038 visual.SetOffStage( actor );
1039 DALI_TEST_EQUALS( actor.GetRendererCount(), 0u, TEST_LOCATION );
1042 //Test if mesh loads correctly when supplied with only the bare minimum requirements, an object file.
1043 int UtcDaliVisualFactoryGetMeshVisual1(void)
1045 //Set up test application first, so everything else can be handled.
1046 ToolkitTestApplication application;
1048 tet_infoline( "UtcDaliVisualFactoryGetMeshVisual1: Request mesh visual with a valid object file only" );
1051 //Set up visual properties.
1052 Property::Map propertyMap;
1053 propertyMap.Insert( Visual::Property::TYPE, Visual::MESH );
1054 propertyMap.Insert( MeshVisual::Property::OBJECT_URL, TEST_OBJ_FILE_NAME );
1056 //Test to see if mesh loads correctly.
1057 MeshVisualLoadsCorrectlyTest( propertyMap, application );
1063 //Test if mesh loads correctly when supplied with an object file as well as a blank material file and images directory.
1064 int UtcDaliVisualFactoryGetMeshVisual2(void)
1066 //Set up test application first, so everything else can be handled.
1067 ToolkitTestApplication application;
1069 tet_infoline( "UtcDaliVisualFactoryGetMeshVisual2: Request mesh visual with blank material file and images directory" );
1071 //Set up visual properties.
1072 Property::Map propertyMap;
1073 propertyMap.Insert( Visual::Property::TYPE, Visual::MESH );
1074 propertyMap.Insert( MeshVisual::Property::OBJECT_URL, TEST_OBJ_FILE_NAME );
1075 propertyMap.Insert( MeshVisual::Property::MATERIAL_URL, "" );
1076 propertyMap.Insert( MeshVisual::Property::TEXTURES_PATH, "" );
1078 //Test to see if mesh loads correctly.
1079 MeshVisualLoadsCorrectlyTest( propertyMap, application );
1084 //Test if mesh loads correctly when supplied with all main parameters, an object file, a material file and a directory location.
1085 int UtcDaliVisualFactoryGetMeshVisual3(void)
1087 //Set up test application first, so everything else can be handled.
1088 ToolkitTestApplication application;
1090 tet_infoline( "UtcDaliVisualFactoryGetMeshVisual3: Request mesh visual with all parameters correct" );
1092 //Set up visual properties.
1093 Property::Map propertyMap;
1094 propertyMap.Insert( Visual::Property::TYPE, Visual::MESH );
1095 propertyMap.Insert( MeshVisual::Property::OBJECT_URL, TEST_OBJ_FILE_NAME );
1096 propertyMap.Insert( MeshVisual::Property::MATERIAL_URL, TEST_MTL_FILE_NAME );
1097 propertyMap.Insert( MeshVisual::Property::TEXTURES_PATH, TEST_RESOURCE_DIR "/" );
1099 //Test to see if mesh loads correctly.
1100 MeshVisualLoadsCorrectlyTest( propertyMap, application );
1105 //Test if mesh visual can load a correctly supplied mesh without a normal map or gloss map in the material file.
1106 int UtcDaliVisualFactoryGetMeshVisual4(void)
1108 //Set up test application first, so everything else can be handled.
1109 ToolkitTestApplication application;
1111 tet_infoline( "UtcDaliVisualFactoryGetMeshVisual4: Request mesh visual with diffuse texture but not normal or gloss." );
1114 //Set up visual properties.
1115 Property::Map propertyMap;
1116 propertyMap.Insert( Visual::Property::TYPE, Visual::MESH );
1117 propertyMap.Insert( MeshVisual::Property::OBJECT_URL, TEST_OBJ_FILE_NAME );
1118 propertyMap.Insert( MeshVisual::Property::MATERIAL_URL, TEST_SIMPLE_MTL_FILE_NAME );
1119 propertyMap.Insert( MeshVisual::Property::TEXTURES_PATH, TEST_RESOURCE_DIR "/" );
1121 //Test to see if mesh loads correctly.
1122 MeshVisualLoadsCorrectlyTest( propertyMap, application );
1128 //Test if mesh visual can load when made to use diffuse textures only.
1129 int UtcDaliVisualFactoryGetMeshVisual5(void)
1131 //Set up test application first, so everything else can be handled.
1132 ToolkitTestApplication application;
1134 tet_infoline( "UtcDaliVisualFactoryGetMeshVisual5: Request mesh visual and make it only use diffuse textures." );
1136 //Set up visual properties.
1137 Property::Map propertyMap;
1138 propertyMap.Insert( Visual::Property::TYPE, Visual::MESH );
1139 propertyMap.Insert( MeshVisual::Property::OBJECT_URL, TEST_OBJ_FILE_NAME );
1140 propertyMap.Insert( MeshVisual::Property::MATERIAL_URL, TEST_MTL_FILE_NAME );
1141 propertyMap.Insert( MeshVisual::Property::TEXTURES_PATH, TEST_RESOURCE_DIR "/" );
1142 propertyMap.Insert( MeshVisual::Property::SHADING_MODE, MeshVisual::ShadingMode::TEXTURED_WITH_SPECULAR_LIGHTING );
1144 //Test to see if mesh loads correctly.
1145 MeshVisualLoadsCorrectlyTest( propertyMap, application );
1151 //Test if mesh visual can load when made to not use the supplied textures.
1152 int UtcDaliVisualFactoryGetMeshVisual6(void)
1154 //Set up test application first, so everything else can be handled.
1155 ToolkitTestApplication application;
1157 tet_infoline( "UtcDaliVisualFactoryGetMeshVisual6: Request mesh visual and make it not use any textures." );
1159 //Set up visual properties.
1160 Property::Map propertyMap;
1161 propertyMap.Insert( Visual::Property::TYPE, Visual::MESH );
1162 propertyMap.Insert( MeshVisual::Property::OBJECT_URL, TEST_OBJ_FILE_NAME );
1163 propertyMap.Insert( MeshVisual::Property::MATERIAL_URL, TEST_MTL_FILE_NAME );
1164 propertyMap.Insert( MeshVisual::Property::TEXTURES_PATH, TEST_RESOURCE_DIR "/" );
1165 propertyMap.Insert( MeshVisual::Property::SHADING_MODE, MeshVisual::ShadingMode::TEXTURELESS_WITH_DIFFUSE_LIGHTING );
1167 //Test to see if mesh loads correctly.
1168 MeshVisualLoadsCorrectlyTest( propertyMap, application );
1172 //Test if mesh visual loads correctly when light position is manually set.
1173 int UtcDaliVisualFactoryGetMeshVisual7(void)
1175 //Set up test application first, so everything else can be handled.
1176 ToolkitTestApplication application;
1179 tet_infoline( "UtcDaliVisualFactoryGetMeshVisual7: Request mesh visual with custom light position." );
1181 //Set up visual properties.
1182 Property::Map propertyMap;
1183 propertyMap.Insert( Visual::Property::TYPE, Visual::MESH );
1184 propertyMap.Insert( MeshVisual::Property::OBJECT_URL, TEST_OBJ_FILE_NAME );
1185 propertyMap.Insert( MeshVisual::Property::MATERIAL_URL, TEST_MTL_FILE_NAME );
1186 propertyMap.Insert( MeshVisual::Property::TEXTURES_PATH, TEST_RESOURCE_DIR "/" );
1187 propertyMap.Insert( MeshVisual::Property::LIGHT_POSITION, Vector3( 0.0, 1.0, 2.0 ) );
1189 //Test to see if mesh loads correctly.
1190 MeshVisualLoadsCorrectlyTest( propertyMap, application );
1195 //Test if mesh visual loads correctly when supplied an object file without face normals or texture points.
1196 //Note that this notably tests object loader functionality.
1197 int UtcDaliVisualFactoryGetMeshVisual8(void)
1199 //Set up test application first, so everything else can be handled.
1200 ToolkitTestApplication application;
1202 tet_infoline( "UtcDaliVisualFactoryGetMeshVisual5: Request mesh visual with normal-less object file." );
1204 //Set up visual properties.
1205 Property::Map propertyMap;
1206 propertyMap.Insert( Visual::Property::TYPE, Visual::MESH );
1207 propertyMap.Insert( MeshVisual::Property::OBJECT_URL, TEST_SIMPLE_OBJ_FILE_NAME );
1208 propertyMap.Insert( MeshVisual::Property::MATERIAL_URL, TEST_MTL_FILE_NAME );
1209 propertyMap.Insert( MeshVisual::Property::TEXTURES_PATH, TEST_RESOURCE_DIR "/" );
1211 //Test to see if mesh loads correctly.
1212 MeshVisualLoadsCorrectlyTest( propertyMap, application );
1217 //Test if mesh visual handles the case of lacking an object file.
1218 int UtcDaliVisualFactoryGetMeshVisualN1(void)
1220 //Set up test application first, so everything else can be handled.
1221 ToolkitTestApplication application;
1223 tet_infoline( "UtcDaliVisualFactoryGetMeshVisualN1: Request mesh visual without object file" );
1225 //Set up visual properties.
1226 Property::Map propertyMap;
1227 propertyMap.Insert( Visual::Property::TYPE, Visual::MESH );
1228 propertyMap.Insert( MeshVisual::Property::MATERIAL_URL, TEST_MTL_FILE_NAME );
1229 propertyMap.Insert( MeshVisual::Property::TEXTURES_PATH, TEST_RESOURCE_DIR "/" );
1231 //Test to see if mesh doesn't load with these properties, as expected.
1232 MeshVisualDoesNotLoadCorrectlyTest( propertyMap, application );
1238 //Test if mesh visual handles the case of being passed invalid material and images urls.
1239 int UtcDaliVisualFactoryGetMeshVisualN2(void)
1241 //Set up test application first, so everything else can be handled.
1242 ToolkitTestApplication application;
1244 tet_infoline( "UtcDaliVisualFactoryGetMeshVisualN2: Request mesh visual with invalid material and images urls" );
1246 //Set up visual properties.
1247 Property::Map propertyMap;
1248 propertyMap.Insert( Visual::Property::TYPE, Visual::MESH );
1249 propertyMap.Insert( MeshVisual::Property::OBJECT_URL, TEST_OBJ_FILE_NAME );
1250 propertyMap.Insert( MeshVisual::Property::MATERIAL_URL, "invalid" );
1251 propertyMap.Insert( MeshVisual::Property::TEXTURES_PATH, "also invalid" );
1253 //Test to see if mesh doesn't load with these properties, as expected.
1254 MeshVisualDoesNotLoadCorrectlyTest( propertyMap, application );
1260 //Test if mesh visual handles the case of being passed an invalid object url
1261 int UtcDaliVisualFactoryGetMeshVisualN3(void)
1263 //Set up test application first, so everything else can be handled.
1264 ToolkitTestApplication application;
1265 tet_infoline( "UtcDaliVisualFactoryGetMeshVisualN3: Request mesh visual with invalid object url" );
1268 //Set up visual properties.
1269 Property::Map propertyMap;
1270 propertyMap.Insert( Visual::Property::TYPE, Visual::MESH );
1271 propertyMap.Insert( MeshVisual::Property::OBJECT_URL, "invalid" );
1272 propertyMap.Insert( MeshVisual::Property::MATERIAL_URL, TEST_MTL_FILE_NAME );
1273 propertyMap.Insert( MeshVisual::Property::TEXTURES_PATH, TEST_RESOURCE_DIR "/" );
1275 //Test to see if mesh doesn't load with these properties, as expected.
1276 MeshVisualDoesNotLoadCorrectlyTest( propertyMap, application );
1281 //Creates a primitive visual with the given property map and tests to see if it correctly loads in the given application.
1282 void TestPrimitiveVisualWithProperties( Property::Map& propertyMap, ToolkitTestApplication& application )
1284 VisualFactory factory = VisualFactory::Get();
1285 DALI_TEST_CHECK( factory );
1287 //Create a primitive visual.
1288 Visual::Base visual = factory.CreateVisual( propertyMap );
1289 DALI_TEST_CHECK( visual );
1291 //Create an actor on stage to house the visual.
1292 Actor actor = Actor::New();
1293 actor.SetSize( 200.f, 200.f );
1294 Stage::GetCurrent().Add( actor );
1295 visual.SetSize( Vector2( 200.f, 200.f ) );
1296 visual.SetOnStage( actor );
1298 //Ensure set on stage.
1299 DALI_TEST_EQUALS( actor.GetRendererCount(), 1u, TEST_LOCATION );
1301 //Tell test application to load the visual.
1302 application.SendNotification();
1303 application.Render(0);
1305 Matrix testScaleMatrix;
1306 testScaleMatrix.SetIdentityAndScale( Vector3( 1.0, -1.0, 1.0 ) );
1307 Matrix actualScaleMatrix;
1309 //Test to see if the object has been successfully loaded.
1310 DALI_TEST_CHECK( application.GetGlAbstraction().GetUniformValue<Matrix>( "uObjectMatrix", actualScaleMatrix ) );
1311 DALI_TEST_EQUALS( actualScaleMatrix, testScaleMatrix, Math::MACHINE_EPSILON_100, TEST_LOCATION );
1313 //Finish by setting off stage, and ensuring this was successful.
1314 visual.SetOffStage( actor );
1315 DALI_TEST_EQUALS( actor.GetRendererCount(), 0u, TEST_LOCATION );
1318 //Test if primitive shape loads correctly when supplied with only the bare minimum requirements, the shape to use.
1319 int UtcDaliVisualFactoryGetPrimitiveVisual1(void)
1321 //Set up test application first, so everything else can be handled.
1322 ToolkitTestApplication application;
1324 tet_infoline( "UtcDaliVisualFactoryGetPrimitiveVisual1: Request primitive visual with a shape only" );
1326 //Set up visual properties.
1327 Property::Map propertyMap;
1328 propertyMap.Insert( Visual::Property::TYPE, Visual::PRIMITIVE );
1329 propertyMap.Insert( PrimitiveVisual::Property::SHAPE, PrimitiveVisual::Shape::CUBE );
1331 //Test to see if shape loads correctly.
1332 TestPrimitiveVisualWithProperties( propertyMap, application );
1337 //Test if primitive shape loads correctly when supplied with all possible parameters
1338 int UtcDaliVisualFactoryGetPrimitiveVisual2(void)
1340 //Set up test application first, so everything else can be handled.
1341 ToolkitTestApplication application;
1343 tet_infoline( "UtcDaliVisualFactoryGetPrimitiveVisual2: Request primitive visual with everything" );
1345 //Set up visual properties.
1346 Property::Map propertyMap;
1347 propertyMap.Insert( Visual::Property::TYPE, Visual::PRIMITIVE );
1348 propertyMap.Insert( PrimitiveVisual::Property::SHAPE, PrimitiveVisual::Shape::CUBE );
1349 propertyMap.Insert( PrimitiveVisual::Property::COLOR, Vector4( 0.5, 0.5, 0.5, 1.0 ) );
1350 propertyMap.Insert( PrimitiveVisual::Property::SLICES, 10 );
1351 propertyMap.Insert( PrimitiveVisual::Property::STACKS, 20 );
1352 propertyMap.Insert( PrimitiveVisual::Property::SCALE_TOP_RADIUS, 30.0f );
1353 propertyMap.Insert( PrimitiveVisual::Property::SCALE_BOTTOM_RADIUS, 40.0f );
1354 propertyMap.Insert( PrimitiveVisual::Property::SCALE_HEIGHT, 50.0f );
1355 propertyMap.Insert( PrimitiveVisual::Property::SCALE_RADIUS, 60.0f );
1356 propertyMap.Insert( PrimitiveVisual::Property::BEVEL_PERCENTAGE, 0.7f );
1357 propertyMap.Insert( PrimitiveVisual::Property::BEVEL_SMOOTHNESS, 0.8f );
1358 propertyMap.Insert( MeshVisual::Property::LIGHT_POSITION, Vector3( 0.9, 1.0, 1.1 ) );
1360 //Test to see if shape loads correctly.
1361 TestPrimitiveVisualWithProperties( propertyMap, application );
1366 //Test if primitive shape loads a sphere correctly.
1367 int UtcDaliVisualFactoryGetPrimitiveVisual3(void)
1369 //Set up test application first, so everything else can be handled.
1370 ToolkitTestApplication application;
1372 tet_infoline( "UtcDaliVisualFactoryGetPrimitiveVisual3: Request primitive visual to display a sphere" );
1374 //Set up visual properties.
1375 Property::Map propertyMap;
1376 propertyMap.Insert( Visual::Property::TYPE, Visual::PRIMITIVE );
1377 propertyMap.Insert( PrimitiveVisual::Property::SHAPE, PrimitiveVisual::Shape::SPHERE );
1378 propertyMap.Insert( PrimitiveVisual::Property::COLOR, Vector4( 0.5, 0.5, 0.5, 1.0 ) );
1379 propertyMap.Insert( PrimitiveVisual::Property::SLICES, 10 );
1380 propertyMap.Insert( PrimitiveVisual::Property::STACKS, 20 );
1382 //Test to see if shape loads correctly.
1383 TestPrimitiveVisualWithProperties( propertyMap, application );
1388 //Test if primitive shape loads a conic section correctly.
1389 int UtcDaliVisualFactoryGetPrimitiveVisual4(void)
1391 //Set up test application first, so everything else can be handled.
1392 ToolkitTestApplication application;
1394 tet_infoline( "UtcDaliVisualFactoryGetPrimitiveVisual4: Request primitive visual to display a conic section" );
1396 //Set up visual properties.
1397 Property::Map propertyMap;
1398 propertyMap.Insert( Visual::Property::TYPE, Visual::PRIMITIVE );
1399 propertyMap.Insert( PrimitiveVisual::Property::SHAPE, PrimitiveVisual::Shape::CONICAL_FRUSTRUM );
1400 propertyMap.Insert( PrimitiveVisual::Property::COLOR, Vector4( 0.5, 0.5, 0.5, 1.0 ) );
1401 propertyMap.Insert( PrimitiveVisual::Property::SLICES, 10 );
1402 propertyMap.Insert( PrimitiveVisual::Property::SCALE_TOP_RADIUS, 30.0f );
1403 propertyMap.Insert( PrimitiveVisual::Property::SCALE_BOTTOM_RADIUS, 40.0f );
1404 propertyMap.Insert( PrimitiveVisual::Property::SCALE_HEIGHT, 50.0f );
1406 //Test to see if shape loads correctly.
1407 TestPrimitiveVisualWithProperties( propertyMap, application );
1412 //Test if primitive shape loads a bevelled cube correctly.
1413 int UtcDaliVisualFactoryGetPrimitiveVisual5(void)
1415 //Set up test application first, so everything else can be handled.
1416 ToolkitTestApplication application;
1418 tet_infoline( "UtcDaliVisualFactoryGetPrimitiveVisual5: Request primitive visual to display a bevelled cube" );
1420 //Set up visual properties.
1421 Property::Map propertyMap;
1422 propertyMap.Insert( Visual::Property::TYPE, Visual::PRIMITIVE );
1423 propertyMap.Insert( PrimitiveVisual::Property::SHAPE, PrimitiveVisual::Shape::BEVELLED_CUBE );
1424 propertyMap.Insert( PrimitiveVisual::Property::COLOR, Vector4( 0.5, 0.5, 0.5, 1.0 ) );
1425 propertyMap.Insert( PrimitiveVisual::Property::BEVEL_PERCENTAGE, 0.7f );
1427 //Test to see if shape loads correctly.
1428 TestPrimitiveVisualWithProperties( propertyMap, application );
1433 //Test if primitive shape loads an octahedron correctly.
1434 int UtcDaliVisualFactoryGetPrimitiveVisual6(void)
1436 //Set up test application first, so everything else can be handled.
1437 ToolkitTestApplication application;
1439 tet_infoline( "UtcDaliVisualFactoryGetPrimitiveVisual6: Request primitive visual to display an octahedron" );
1441 //Set up visual properties.
1442 Property::Map propertyMap;
1443 propertyMap.Insert( Visual::Property::TYPE, Visual::PRIMITIVE );
1444 propertyMap.Insert( PrimitiveVisual::Property::SHAPE, PrimitiveVisual::Shape::OCTAHEDRON );
1445 propertyMap.Insert( PrimitiveVisual::Property::COLOR, Vector4( 0.5, 0.5, 0.5, 1.0 ) );
1447 //Test to see if shape loads correctly.
1448 TestPrimitiveVisualWithProperties( propertyMap, application );
1453 //Test if primitive shape loads a cone correctly.
1454 int UtcDaliVisualFactoryGetPrimitiveVisual7(void)
1456 //Set up test application first, so everything else can be handled.
1457 ToolkitTestApplication application;
1459 tet_infoline( "UtcDaliVisualFactoryGetPrimitiveVisual7: Request primitive visual to display a cone" );
1461 //Set up visual properties.
1462 Property::Map propertyMap;
1463 propertyMap.Insert( Visual::Property::TYPE, Visual::PRIMITIVE );
1464 propertyMap.Insert( PrimitiveVisual::Property::SHAPE, PrimitiveVisual::Shape::CONE );
1465 propertyMap.Insert( PrimitiveVisual::Property::COLOR, Vector4( 0.5, 0.5, 0.5, 1.0 ) );
1466 propertyMap.Insert( PrimitiveVisual::Property::SLICES, 10 );
1467 propertyMap.Insert( PrimitiveVisual::Property::SCALE_TOP_RADIUS, 30.0f );
1468 propertyMap.Insert( PrimitiveVisual::Property::SCALE_HEIGHT, 50.0f );
1470 //Test to see if shape loads correctly.
1471 TestPrimitiveVisualWithProperties( propertyMap, application );
1476 //Test if primitive shape loads correctly when light position is manually set.
1477 int UtcDaliVisualFactoryGetPrimitiveVisual8(void)
1479 //Set up test application first, so everything else can be handled.
1480 ToolkitTestApplication application;
1482 tet_infoline( "UtcDaliVisualFactoryGetPrimitiveVisual8: Request primitive visual with set light position" );
1484 //Set up visual properties.
1485 Property::Map propertyMap;
1486 propertyMap.Insert( Visual::Property::TYPE, Visual::PRIMITIVE );
1487 propertyMap.Insert( PrimitiveVisual::Property::SHAPE, PrimitiveVisual::Shape::SPHERE );
1488 propertyMap.Insert( PrimitiveVisual::Property::COLOR, Vector4( 0.5, 0.5, 0.5, 1.0 ) );
1489 propertyMap.Insert( MeshVisual::Property::LIGHT_POSITION, Vector3( 0.0, 1.0, 2.0 ) );
1491 //Test to see if shape loads correctly.
1492 TestPrimitiveVisualWithProperties( propertyMap, application );
1497 //Test if primitive shape renderer handles the case of not being passed a specific shape to use.
1498 int UtcDaliVisualFactoryGetPrimitiveVisualN1(void)
1500 //Set up test application first, so everything else can be handled.
1501 ToolkitTestApplication application;
1503 tet_infoline( "UtcDaliVisualFactoryGetPrimitiveVisualN1: Request primitive visual without shape" );
1505 //Set up visual properties, without supplying shape.
1506 Property::Map propertyMap;
1507 propertyMap.Insert( Visual::Property::TYPE, Visual::PRIMITIVE );
1509 //Test to see if shape loads regardless of missing input.
1510 TestPrimitiveVisualWithProperties( propertyMap, application );