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-bitmap-loader.h>
21 #include <toolkit-event-thread-callback.h>
22 #include <dali/public-api/rendering/renderer.h>
23 #include <dali/public-api/rendering/texture-set.h>
24 #include <dali/public-api/rendering/shader.h>
25 #include <dali/devel-api/images/nine-patch-image.h>
26 #include <dali-toolkit/devel-api/visual-factory/visual-factory.h>
27 #include <dali-toolkit/dali-toolkit.h>
30 using namespace Dali::Toolkit;
34 typedef NinePatchImage::StretchRanges StretchRanges;
36 const char* TEST_IMAGE_FILE_NAME = "gallery_image_01.jpg";
37 const char* TEST_NPATCH_FILE_NAME = "gallery_image_01.9.png";
38 const char* TEST_SVG_FILE_NAME = TEST_RESOURCE_DIR "/svg1.svg";
39 const char* TEST_OBJ_FILE_NAME = TEST_RESOURCE_DIR "/Cube.obj";
40 const char* TEST_MTL_FILE_NAME = TEST_RESOURCE_DIR "/ToyRobot-Metal.mtl";
41 const char* TEST_SIMPLE_OBJ_FILE_NAME = TEST_RESOURCE_DIR "/Cube-Points-Only.obj";
42 const char* TEST_SIMPLE_MTL_FILE_NAME = TEST_RESOURCE_DIR "/ToyRobot-Metal-Simple.mtl";
44 // resolution: 34*34, pixel format: RGBA8888
45 static const char* gImage_34_RGBA = TEST_RESOURCE_DIR "/icon-edit.png";
46 // resolution: 600*600, pixel format: RGB888
47 static const char* gImage_600_RGB = TEST_RESOURCE_DIR "/test-image-600.jpg";
49 Integration::Bitmap* CreateBitmap( unsigned int imageWidth, unsigned int imageHeight, unsigned int initialColor, Pixel::Format pixelFormat )
51 Integration::Bitmap* bitmap = Integration::Bitmap::New( Integration::Bitmap::BITMAP_2D_PACKED_PIXELS, ResourcePolicy::OWNED_RETAIN );
52 Integration::PixelBuffer* pixbuffer = bitmap->GetPackedPixelsProfile()->ReserveBuffer( pixelFormat, imageWidth, imageHeight, imageWidth, imageHeight );
53 unsigned int bytesPerPixel = GetBytesPerPixel( pixelFormat );
55 memset( pixbuffer, initialColor, imageHeight * imageWidth * bytesPerPixel );
60 void InitialiseRegionsToZeroAlpha( Integration::Bitmap* image, unsigned int imageWidth, unsigned int imageHeight, Pixel::Format pixelFormat )
62 PixelBuffer* pixbuffer = image->GetBuffer();
63 unsigned int bytesPerPixel = GetBytesPerPixel( pixelFormat );
65 for( unsigned int row = 0; row < imageWidth; ++row )
67 unsigned int pixelOffset = row * bytesPerPixel;
68 pixbuffer[ pixelOffset + 3 ] = 0x00;
69 pixelOffset += ( imageHeight - 1 ) * imageWidth * bytesPerPixel;
70 pixbuffer[ pixelOffset + 3 ] = 0x00;
73 for ( unsigned int column = 0; column < imageHeight; ++column )
75 unsigned int pixelOffset = column * imageWidth * bytesPerPixel;
76 pixbuffer[ pixelOffset + 3 ] = 0x00;
77 pixelOffset += ( imageWidth -1 ) * bytesPerPixel;
78 pixbuffer[ pixelOffset + 3 ] = 0x00;
82 void AddStretchRegionsToImage( Integration::Bitmap* image, unsigned int imageWidth, unsigned int imageHeight, const StretchRanges& stretchRangesX, const StretchRanges& stretchRangesY, Pixel::Format pixelFormat )
84 PixelBuffer* pixbuffer = image->GetBuffer();
85 unsigned int bytesPerPixel = GetBytesPerPixel( pixelFormat );
87 for(StretchRanges::ConstIterator it = stretchRangesX.Begin(); it != stretchRangesX.End(); ++it)
89 const Uint16Pair& range = *it;
90 //since the stretch range is in the cropped image space, we need to offset by 1 to get it to the uncropped image space
91 for( unsigned int column = range.GetX() + 1u; column < range.GetY() + 1u; ++column )
93 unsigned int pixelOffset = column * bytesPerPixel;
94 pixbuffer[ pixelOffset ] = 0x00;
95 pixbuffer[ pixelOffset + 1 ] = 0x00;
96 pixbuffer[ pixelOffset + 2 ] = 0x00;
97 pixbuffer[ pixelOffset + 3 ] = 0xFF;
102 for(StretchRanges::ConstIterator it = stretchRangesY.Begin(); it != stretchRangesY.End(); ++it)
104 const Uint16Pair& range = *it;
105 //since the stretch range is in the cropped image space, we need to offset by 1 to get it to the uncropped image space
106 for( unsigned int row = range.GetX() + 1u; row < range.GetY() + 1u; ++row )
108 unsigned int pixelOffset = row * imageWidth * bytesPerPixel;
109 pixbuffer[ pixelOffset ] = 0x00;
110 pixbuffer[ pixelOffset + 1 ] = 0x00;
111 pixbuffer[ pixelOffset + 2 ] = 0x00;
112 pixbuffer[ pixelOffset + 3 ] = 0xFF;
117 void AddChildRegionsToImage( Integration::Bitmap* image, unsigned int imageWidth, unsigned int imageHeight, const Vector4& requiredChildRegion, Pixel::Format pixelFormat )
119 PixelBuffer* pixbuffer = image->GetBuffer();
120 unsigned int bytesPerPixel = GetBytesPerPixel( pixelFormat );
122 Integration::Bitmap::PackedPixelsProfile* srcProfile = image->GetPackedPixelsProfile();
123 unsigned int bufferStride = srcProfile->GetBufferStride();
125 // Add bottom child region
126 for( unsigned int column = requiredChildRegion.x; column < imageWidth - requiredChildRegion.z; ++column )
128 unsigned int pixelOffset = column * bytesPerPixel;
129 pixelOffset += ( imageHeight - 1 ) * bufferStride;
130 pixbuffer[ pixelOffset ] = 0x00;
131 pixbuffer[ pixelOffset + 1 ] = 0x00;
132 pixbuffer[ pixelOffset + 2 ] = 0x00;
133 pixbuffer[ pixelOffset + 3 ] = 0xFF;
136 // Add right child region
137 for ( unsigned int row = requiredChildRegion.y; row < imageHeight - requiredChildRegion.w; ++row )
139 unsigned int pixelOffset = row * bufferStride + ( imageWidth - 1 ) * bytesPerPixel;
140 pixbuffer[ pixelOffset ] = 0x00;
141 pixbuffer[ pixelOffset + 1 ] = 0x00;
142 pixbuffer[ pixelOffset + 2 ] = 0x00;
143 pixbuffer[ pixelOffset + 3 ] = 0xFF;
147 Integration::ResourcePointer CustomizeNinePatch( TestApplication& application,
148 unsigned int ninePatchImageWidth,
149 unsigned int ninePatchImageHeight,
150 const StretchRanges& stretchRangesX,
151 const StretchRanges& stretchRangesY,
152 bool addChildRegion = false,
153 Vector4 requiredChildRegion = Vector4::ZERO )
155 TestPlatformAbstraction& platform = application.GetPlatform();
157 Pixel::Format pixelFormat = Pixel::RGBA8888;
159 tet_infoline("Create Bitmap");
160 platform.SetClosestImageSize(Vector2( ninePatchImageWidth, ninePatchImageHeight));
161 Integration::Bitmap* bitmap = CreateBitmap( ninePatchImageWidth, ninePatchImageHeight, 0xFF, pixelFormat );
163 tet_infoline("Clear border regions");
164 InitialiseRegionsToZeroAlpha( bitmap, ninePatchImageWidth, ninePatchImageHeight, pixelFormat );
166 tet_infoline("Add Stretch regions to Bitmap");
167 AddStretchRegionsToImage( bitmap, ninePatchImageWidth, ninePatchImageHeight, stretchRangesX, stretchRangesY, pixelFormat );
171 tet_infoline("Add Child regions to Bitmap");
172 AddChildRegionsToImage( bitmap, ninePatchImageWidth, ninePatchImageHeight, requiredChildRegion, pixelFormat );
175 tet_infoline("Getting resource");
176 Integration::ResourcePointer resourcePtr(bitmap);
177 //platform.SetResourceLoaded( 0, Dali::Integration::ResourceBitmap, resourcePtr );
178 platform.SetSynchronouslyLoadedResource( resourcePtr);
183 void TestVisualRender( ToolkitTestApplication& application,
185 Visual::Base& visual,
186 std::size_t expectedSamplers = 0,
187 ImageDimensions imageDimensions = ImageDimensions(),
188 Integration::ResourcePointer resourcePtr = Integration::ResourcePointer())
192 // set the image size, for test case, this needs to be set before loading started
193 application.GetPlatform().SetClosestImageSize( Vector2(imageDimensions.GetWidth(), imageDimensions.GetHeight()) );
196 actor.SetSize( 200.f, 200.f );
197 Stage::GetCurrent().Add( actor );
198 visual.SetSize( Vector2(200.f, 200.f) );
199 visual.SetOnStage( actor );
201 DALI_TEST_CHECK( actor.GetRendererCount() == 1u );
203 application.SendNotification();
204 application.Render();
208 Integration::ResourceRequest* request = application.GetPlatform().GetRequest();
211 application.GetPlatform().SetResourceLoaded(request->GetId(), request->GetType()->id, resourcePtr );
215 application.Render();
216 application.SendNotification();
220 DALI_TEST_CHECK( application.GetPlatform().WasCalled(TestPlatformAbstraction::LoadResourceFunc) ||
221 application.GetPlatform().WasCalled(TestPlatformAbstraction::LoadResourceSynchronouslyFunc ));
224 DALI_TEST_CHECK( actor.GetRendererCount() == 1u );
231 void dali_visual_factory_startup(void)
233 test_return_value = TET_UNDEF;
236 void dali_visual_factory_cleanup(void)
238 test_return_value = TET_PASS;
241 int UtcDaliVisualFactoryGet(void)
243 ToolkitTestApplication application;
244 tet_infoline( "UtcDaliVisualFactory" );
248 type = TypeRegistry::Get().GetTypeInfo( "VisualFactory" );
249 DALI_TEST_CHECK( type );
250 BaseHandle handle = type.CreateInstance();
251 DALI_TEST_CHECK( handle );
253 VisualFactory factory;
254 factory = VisualFactory::Get();
255 DALI_TEST_CHECK( factory );
257 VisualFactory newFactory = VisualFactory::Get();
258 DALI_TEST_CHECK( newFactory );
260 // Check that visual factory is a singleton
261 DALI_TEST_CHECK(factory == newFactory);
266 int UtcDaliVisualFactoryCopyAndAssignment(void)
268 ToolkitTestApplication application;
269 tet_infoline( "UtcDaliVisualFactoryCopyAndAssignment" );
270 VisualFactory factory = VisualFactory::Get();
272 VisualFactory factoryCopy( factory );
273 DALI_TEST_CHECK(factory == factoryCopy);
275 VisualFactory emptyFactory;
276 VisualFactory emptyFactoryCopy( emptyFactory );
277 DALI_TEST_CHECK(emptyFactory == emptyFactoryCopy);
279 VisualFactory factoryEquals;
280 factoryEquals = factory;
281 DALI_TEST_CHECK(factory == factoryEquals);
283 VisualFactory emptyFactoryEquals;
284 emptyFactoryEquals = emptyFactory;
285 DALI_TEST_CHECK( emptyFactory == emptyFactoryEquals );
289 DALI_TEST_CHECK( factory = factoryCopy );
294 int UtcDaliVisualFactoryGetColorVisual1(void)
296 ToolkitTestApplication application;
297 tet_infoline( "UtcDaliVisualFactoryGetColorVisual1: Request color visual with a Property::Map" );
299 VisualFactory factory = VisualFactory::Get();
300 DALI_TEST_CHECK( factory );
302 Property::Map propertyMap;
303 Vector4 testColor( 1.f, 0.5f, 0.3f, 0.2f );
304 propertyMap.Insert(Visual::Property::TYPE, Visual::COLOR);
305 propertyMap.Insert(ColorVisual::Property::MIX_COLOR, testColor);
307 Visual::Base visual = factory.CreateVisual(propertyMap);
308 DALI_TEST_CHECK( visual );
310 Actor actor = Actor::New();
311 TestVisualRender( application, actor, visual );
313 Vector4 actualValue(Vector4::ZERO);
314 TestGlAbstraction& gl = application.GetGlAbstraction();
315 DALI_TEST_CHECK( gl.GetUniformValue<Vector4>( "mixColor", actualValue ) );
316 DALI_TEST_EQUALS( actualValue, testColor, TEST_LOCATION );
321 int UtcDaliVisualFactoryGetColorVisual2(void)
323 ToolkitTestApplication application;
324 tet_infoline( "UtcDaliVisualFactoryGetColorVisual2: Request color visual with a Vector4" );
326 VisualFactory factory = VisualFactory::Get();
327 DALI_TEST_CHECK( factory );
329 Vector4 testColor( 1.f, 0.5f, 0.3f, 0.2f );
330 Dali::Property::Map map;
331 map[ Visual::Property::TYPE ] = Visual::COLOR;
332 map[ ColorVisual::Property::MIX_COLOR ] = testColor;
333 Visual::Base visual = factory.CreateVisual( map );
334 DALI_TEST_CHECK( visual );
336 Actor actor = Actor::New();
337 TestVisualRender( application, actor, visual );
339 Vector4 actualValue(Vector4::ZERO);
340 TestGlAbstraction& gl = application.GetGlAbstraction();
341 DALI_TEST_CHECK( gl.GetUniformValue<Vector4>( "mixColor", actualValue ) );
342 DALI_TEST_EQUALS( actualValue, testColor, TEST_LOCATION );
344 visual.SetOffStage( actor );
345 DALI_TEST_CHECK( actor.GetRendererCount() == 0u );
350 int UtcDaliVisualFactoryGetBorderVisual1(void)
352 ToolkitTestApplication application;
353 tet_infoline( "UtcDaliVisualFactoryGetBorderVisual1: Request border visual with a Property::Map" );
355 VisualFactory factory = VisualFactory::Get();
356 DALI_TEST_CHECK( factory );
358 Property::Map propertyMap;
359 Vector4 testColor( 1.f, 0.5f, 0.3f, 0.2f );
360 float testSize = 5.f;
361 propertyMap.Insert(Visual::Property::TYPE, Visual::BORDER);
362 propertyMap.Insert(BorderVisual::Property::COLOR, testColor);
363 propertyMap.Insert(BorderVisual::Property::SIZE, testSize);
365 Visual::Base visual = factory.CreateVisual(propertyMap);
366 DALI_TEST_CHECK( visual );
368 Actor actor = Actor::New();
369 actor.SetSize(200.f, 200.f);
370 Stage::GetCurrent().Add( actor );
371 visual.SetSize(Vector2(200.f, 200.f));
372 visual.SetOnStage( actor );
374 DALI_TEST_CHECK( actor.GetRendererCount() == 1u );
375 int blendMode = actor.GetRendererAt(0u).GetProperty<int>( Renderer::Property::BLEND_MODE );
376 DALI_TEST_EQUALS( static_cast<BlendMode::Type>(blendMode), BlendMode::ON, TEST_LOCATION );
378 TestGlAbstraction& gl = application.GetGlAbstraction();
380 application.SendNotification();
381 application.Render(0);
383 Vector4 actualColor(Vector4::ZERO);
384 DALI_TEST_CHECK( gl.GetUniformValue<Vector4>( "borderColor", actualColor ) );
385 DALI_TEST_EQUALS( actualColor, testColor, TEST_LOCATION );
387 float actualSize = 0.f;
388 DALI_TEST_CHECK( gl.GetUniformValue<float>( "borderSize", actualSize ) );
389 DALI_TEST_EQUALS( actualSize, testSize, TEST_LOCATION );
391 visual.SetOffStage( actor );
392 DALI_TEST_CHECK( actor.GetRendererCount() == 0u );
397 int UtcDaliVisualFactoryGetBorderVisual2(void)
399 ToolkitTestApplication application;
400 tet_infoline( "UtcDaliVisualFactoryGetBorderVisual2: Request border visual with a borderSize and a borderColor" );
402 VisualFactory factory = VisualFactory::Get();
403 DALI_TEST_CHECK( factory );
405 Vector4 testColor( 1.f, 0.5f, 0.3f, 1.f );
406 float testSize = 5.f;
408 Dali::Property::Map propertyMap;
409 propertyMap[ Visual::Property::TYPE ] = Visual::BORDER;
410 propertyMap[ BorderVisual::Property::COLOR ] = testColor;
411 propertyMap[ BorderVisual::Property::SIZE ] = testSize;
412 Visual::Base visual = factory.CreateVisual( propertyMap );
413 DALI_TEST_CHECK( visual );
415 Actor actor = Actor::New();
416 actor.SetSize(200.f, 200.f);
417 Stage::GetCurrent().Add( actor );
418 visual.SetSize(Vector2(200.f, 200.f));
419 visual.SetOnStage( actor );
421 DALI_TEST_CHECK( actor.GetRendererCount() == 1u );
423 TestGlAbstraction& gl = application.GetGlAbstraction();
425 application.SendNotification();
426 application.Render(0);
428 int blendMode = actor.GetRendererAt(0u).GetProperty<int>( Renderer::Property::BLEND_MODE );
429 DALI_TEST_EQUALS( static_cast<BlendMode::Type>(blendMode), BlendMode::AUTO, TEST_LOCATION );
431 Vector4 actualColor(Vector4::ZERO);
432 DALI_TEST_CHECK( gl.GetUniformValue<Vector4>( "borderColor", actualColor ) );
433 DALI_TEST_EQUALS( actualColor, testColor, TEST_LOCATION );
435 float actualSize = 0.f;
436 DALI_TEST_CHECK( gl.GetUniformValue<float>( "borderSize", actualSize ) );
437 DALI_TEST_EQUALS( actualSize, testSize, TEST_LOCATION );
439 visual.SetOffStage( actor );
441 // enable the anti-aliasing
442 Dali::Property::Map map;
443 map[ Visual::Property::TYPE ] = Visual::BORDER;
444 map[ BorderVisual::Property::COLOR ] = testColor;
445 map[ BorderVisual::Property::SIZE ] = testSize;
446 map[ BorderVisual::Property::ANTI_ALIASING ] = true;
447 visual = factory.CreateVisual( map );
448 visual.SetOnStage( actor );
450 application.SendNotification();
451 application.Render(0);
452 blendMode = actor.GetRendererAt(0u).GetProperty<int>( Renderer::Property::BLEND_MODE );
453 DALI_TEST_EQUALS( static_cast<BlendMode::Type>(blendMode), BlendMode::ON, TEST_LOCATION );
458 int UtcDaliVisualFactoryGetLinearGradientVisual(void)
460 ToolkitTestApplication application;
461 tet_infoline("UtcDaliVisualFactoryGetRadialGradientVisual");
463 VisualFactory factory = VisualFactory::Get();
464 DALI_TEST_CHECK( factory );
466 Property::Map propertyMap;
467 propertyMap.Insert(Visual::Property::TYPE, Visual::GRADIENT);
469 Vector2 start(-1.f, -1.f);
470 Vector2 end(1.f, 1.f);
471 propertyMap.Insert(GradientVisual::Property::START_POSITION, start);
472 propertyMap.Insert(GradientVisual::Property::END_POSITION, end);
473 propertyMap.Insert(GradientVisual::Property::SPREAD_METHOD, GradientVisual::SpreadMethod::REPEAT);
475 Property::Array stopOffsets;
476 stopOffsets.PushBack( 0.2f );
477 stopOffsets.PushBack( 0.8f );
478 propertyMap.Insert(GradientVisual::Property::STOP_OFFSET, stopOffsets);
480 Property::Array stopColors;
481 stopColors.PushBack( Color::RED );
482 stopColors.PushBack( Color::GREEN );
483 propertyMap.Insert(GradientVisual::Property::STOP_COLOR, stopColors);
485 Visual::Base visual = factory.CreateVisual(propertyMap);
486 DALI_TEST_CHECK( visual );
488 // A lookup texture is generated and pass to shader as sampler
489 Actor actor = Actor::New();
490 TestVisualRender( application, actor, visual, 1u );
492 visual.SetOffStage( actor );
493 DALI_TEST_CHECK( actor.GetRendererCount() == 0u );
498 int UtcDaliVisualFactoryGetRadialGradientVisual(void)
500 ToolkitTestApplication application;
501 tet_infoline("UtcDaliVisualFactoryGetRadialGradientVisual");
503 VisualFactory factory = VisualFactory::Get();
504 DALI_TEST_CHECK( factory );
506 Property::Map propertyMap;
507 propertyMap.Insert(Visual::Property::TYPE, Visual::GRADIENT);
509 Vector2 center(100.f, 100.f);
510 float radius = 100.f;
511 propertyMap.Insert(GradientVisual::Property::UNITS, GradientVisual::Units::USER_SPACE);
512 propertyMap.Insert(GradientVisual::Property::CENTER, center);
513 propertyMap.Insert(GradientVisual::Property::RADIUS, radius);
515 Property::Array stopOffsets;
516 stopOffsets.PushBack( 0.0f );
517 stopOffsets.PushBack( 1.f );
518 propertyMap.Insert(GradientVisual::Property::STOP_OFFSET, stopOffsets);
520 Property::Array stopColors;
521 stopColors.PushBack( Color::RED );
522 stopColors.PushBack( Color::GREEN );
523 propertyMap.Insert(GradientVisual::Property::STOP_COLOR, stopColors);
525 Visual::Base visual = factory.CreateVisual(propertyMap);
526 DALI_TEST_CHECK( visual );
528 // A lookup texture is generated and pass to shader as sampler
529 Actor actor = Actor::New();
530 TestVisualRender( application, actor, visual, 1u );
532 Matrix3 alignMatrix( radius, 0.f, 0.f, 0.f, radius, 0.f, center.x, center.y, 1.f );
533 alignMatrix.Invert();
535 Matrix3 actualValue( Matrix3::IDENTITY );
536 TestGlAbstraction& gl = application.GetGlAbstraction();
537 DALI_TEST_CHECK( gl.GetUniformValue<Matrix3>( "uAlignmentMatrix", actualValue ) );
538 DALI_TEST_EQUALS( actualValue, alignMatrix, Math::MACHINE_EPSILON_100, TEST_LOCATION );
543 int UtcDaliVisualFactoryDefaultOffsetsGradientVisual(void)
545 ToolkitTestApplication application;
546 tet_infoline("UtcDaliVisualFactoryGetRadialGradientVisual");
548 VisualFactory factory = VisualFactory::Get();
549 DALI_TEST_CHECK( factory );
551 Property::Map propertyMap;
552 propertyMap.Insert(Visual::Property::TYPE, Visual::GRADIENT);
554 Vector2 start(-1.f, -1.f);
555 Vector2 end(1.f, 1.f);
556 propertyMap.Insert(GradientVisual::Property::START_POSITION, start);
557 propertyMap.Insert(GradientVisual::Property::END_POSITION, end);
558 propertyMap.Insert(GradientVisual::Property::SPREAD_METHOD, GradientVisual::SpreadMethod::REPEAT);
560 Property::Array stopColors;
561 stopColors.PushBack( Color::RED );
562 stopColors.PushBack( Color::GREEN );
563 propertyMap.Insert(GradientVisual::Property::STOP_COLOR, stopColors);
565 Visual::Base visual = factory.CreateVisual(propertyMap);
566 DALI_TEST_CHECK( visual );
568 // A lookup texture is generated and pass to shader as sampler
569 Actor actor = Actor::New();
570 TestVisualRender( application, actor, visual, 1u );
572 visual.SetOffStage( actor );
573 DALI_TEST_CHECK( actor.GetRendererCount() == 0u );
578 int UtcDaliVisualFactoryGetImageVisual1(void)
580 ToolkitTestApplication application;
581 tet_infoline( "UtcDaliVisualFactoryGetImageVisual1: Request image visual with a Property::Map" );
583 VisualFactory factory = VisualFactory::Get();
584 DALI_TEST_CHECK( factory );
586 Property::Map propertyMap;
587 propertyMap.Insert( Visual::Property::TYPE, Visual::IMAGE );
588 propertyMap.Insert( ImageVisual::Property::URL, TEST_IMAGE_FILE_NAME );
590 Visual::Base visual = factory.CreateVisual( propertyMap );
591 DALI_TEST_CHECK( visual );
593 Actor actor = Actor::New();
594 // For tesing the LoadResourceFunc is called, a big image size should be set, so the atlasing is not applied.
595 // Image with a size smaller than 512*512 will be uploaded as a part of the atlas.
598 const int height=513;
599 TestGlAbstraction& gl = application.GetGlAbstraction();
600 TraceCallStack& textureTrace = gl.GetTextureTrace();
601 textureTrace.Enable(true);
603 Integration::Bitmap* bitmap = Integration::Bitmap::New( Integration::Bitmap::BITMAP_2D_PACKED_PIXELS, ResourcePolicy::OWNED_DISCARD );
604 bitmap->GetPackedPixelsProfile()->ReserveBuffer( Pixel::RGBA8888, width, height,width, height );
606 TestVisualRender( application, actor, visual, 1u,
607 ImageDimensions(width, height),
608 Integration::ResourcePointer( bitmap ) );
610 DALI_TEST_EQUALS( textureTrace.FindMethod("BindTexture"), true, TEST_LOCATION );
612 visual.SetOffStage( actor );
613 DALI_TEST_CHECK( actor.GetRendererCount() == 0u );
618 int UtcDaliVisualFactoryGetImageVisual2(void)
620 ToolkitTestApplication application;
621 tet_infoline( "UtcDaliVisualFactoryGetImageVisual2: Request image visual with an image handle" );
623 VisualFactory factory = VisualFactory::Get();
624 DALI_TEST_CHECK( factory );
626 Image image = ResourceImage::New(TEST_IMAGE_FILE_NAME);
627 Visual::Base visual = factory.CreateVisual( image );
629 Actor actor = Actor::New();
630 // For tesing the LoadResourceFunc is called, a big image size should be set, so the atlasing is not applied.
631 // Image with a size smaller than 512*512 will be uploaded as a part of the atlas.
634 const int height=513;
636 Integration::Bitmap* bitmap = Integration::Bitmap::New( Integration::Bitmap::BITMAP_2D_PACKED_PIXELS, ResourcePolicy::OWNED_DISCARD );
637 bitmap->GetPackedPixelsProfile()->ReserveBuffer( Pixel::RGBA8888, width, height,width, height );
639 TestGlAbstraction& gl = application.GetGlAbstraction();
640 TraceCallStack& textureTrace = gl.GetTextureTrace();
641 textureTrace.Enable(true);
643 TestVisualRender( application, actor, visual, 1u,
644 ImageDimensions(width, height),
645 Integration::ResourcePointer(bitmap) );
647 DALI_TEST_EQUALS( textureTrace.FindMethod("BindTexture"), true, TEST_LOCATION );
652 int UtcDaliVisualFactoryGetImageVisual3(void)
654 ToolkitTestApplication application;
655 tet_infoline( "UtcDaliVisualFactoryGetImageVisual3: Request image visual with a Property::Map, test custom wrap mode and pixel area with atlasing" );
657 VisualFactory factory = VisualFactory::Get();
658 DALI_TEST_CHECK( factory );
660 // Test wrap mode with atlasing. Image with a size smaller than 512*512 will be uploaded as a part of the atlas.
663 const Vector4 pixelArea(-0.5f, -0.5f, 2.f, 2.f);
665 Property::Map propertyMap;
666 propertyMap.Insert( Visual::Property::TYPE, Visual::IMAGE );
667 propertyMap.Insert( ImageVisual::Property::URL, gImage_34_RGBA );
668 propertyMap.Insert( ImageVisual::Property::DESIRED_WIDTH, width );
669 propertyMap.Insert( ImageVisual::Property::DESIRED_HEIGHT, height );
670 propertyMap.Insert( ImageVisual::Property::SYNCHRONOUS_LOADING, true );
671 propertyMap.Insert( ImageVisual::Property::PIXEL_AREA, pixelArea );
672 propertyMap.Insert( ImageVisual::Property::WRAP_MODE_U, WrapMode::MIRRORED_REPEAT );
673 propertyMap.Insert( ImageVisual::Property::WRAP_MODE_V, WrapMode::REPEAT );
675 Visual::Base visual = factory.CreateVisual( propertyMap );
676 DALI_TEST_CHECK( visual );
678 Actor actor = Actor::New();
679 TestGlAbstraction& gl = application.GetGlAbstraction();
680 TraceCallStack& textureTrace = gl.GetTextureTrace();
681 textureTrace.Enable(true);
682 TraceCallStack& texParameterTrace = gl.GetTexParameterTrace();
683 texParameterTrace.Enable( true );
685 actor.SetSize( 200.f, 200.f );
686 Stage::GetCurrent().Add( actor );
687 visual.SetOnStage( actor );
690 application.SendNotification();
691 application.Render();
692 application.Render();
693 application.SendNotification();
694 BitmapLoader loader = BitmapLoader::GetLatestCreated();
695 DALI_TEST_CHECK( loader );
696 loader.WaitForLoading();// waiting until the image to be loaded
697 DALI_TEST_CHECK( loader.IsLoaded() );
699 DALI_TEST_CHECK( actor.GetRendererCount() == 1u );
701 DALI_TEST_EQUALS( textureTrace.FindMethod("BindTexture"), true, TEST_LOCATION );
703 // WITH atlasing, the wrapping is handled manually in shader, so the following gl function should not be called
704 std::stringstream out;
705 out << GL_TEXTURE_2D << ", " << GL_TEXTURE_WRAP_S << ", " << GL_MIRRORED_REPEAT;
706 DALI_TEST_CHECK( !texParameterTrace.FindMethodAndParams("TexParameteri", out.str()) );
708 out << GL_TEXTURE_2D << ", " << GL_TEXTURE_WRAP_T << ", " << GL_REPEAT;
709 DALI_TEST_CHECK( !texParameterTrace.FindMethodAndParams("TexParameteri", out.str()) );
711 // test the uniforms which used to handle the wrap mode
712 Renderer renderer = actor.GetRendererAt( 0u );
713 DALI_TEST_CHECK( renderer );
715 Property::Value pixelAreaValue = renderer.GetProperty( renderer.GetPropertyIndex( "pixelArea" ) );
716 DALI_TEST_EQUALS( pixelAreaValue.Get<Vector4>(), pixelArea, TEST_LOCATION );
717 Vector4 pixelAreaUniform;
718 DALI_TEST_CHECK( gl.GetUniformValue<Vector4>( "pixelArea", pixelAreaUniform ) );
719 DALI_TEST_EQUALS( pixelArea, pixelAreaUniform, Math::MACHINE_EPSILON_100, TEST_LOCATION );
721 Property::Value wrapModeValue = renderer.GetProperty( renderer.GetPropertyIndex( "wrapMode" ) );
722 Vector2 wrapMode( WrapMode::MIRRORED_REPEAT-1, WrapMode::REPEAT-1 );
723 DALI_TEST_EQUALS( wrapModeValue.Get<Vector2>(), wrapMode, TEST_LOCATION );
724 Vector2 wrapModeUniform;
725 DALI_TEST_CHECK( gl.GetUniformValue<Vector2>( "wrapMode", wrapModeUniform ) );
726 DALI_TEST_EQUALS( wrapMode, wrapModeUniform, Math::MACHINE_EPSILON_100, TEST_LOCATION );
728 visual.SetOffStage( actor );
729 DALI_TEST_CHECK( actor.GetRendererCount() == 0u );
734 int UtcDaliVisualFactoryGetImageVisual4(void)
736 ToolkitTestApplication application;
737 tet_infoline( "UtcDaliVisualFactoryGetImageVisual4: Request image visual with a Property::Map, test custom wrap mode and pixel area without atlasing" );
739 VisualFactory factory = VisualFactory::Get();
740 DALI_TEST_CHECK( factory );
742 // Test wrap mode without atlasing. Image with a size bigger than 512*512 will NOT be uploaded as a part of the atlas.
744 const int height=600;
745 const Vector4 pixelArea(-0.5f, -0.5f, 2.f, 2.f);
747 Property::Map propertyMap;
748 propertyMap.Insert( Visual::Property::TYPE, Visual::IMAGE );
749 propertyMap.Insert( ImageVisual::Property::URL, gImage_600_RGB );
750 propertyMap.Insert( ImageVisual::Property::DESIRED_WIDTH, width );
751 propertyMap.Insert( ImageVisual::Property::DESIRED_HEIGHT, height );
752 propertyMap.Insert( ImageVisual::Property::SYNCHRONOUS_LOADING, true );
753 propertyMap.Insert( ImageVisual::Property::PIXEL_AREA, pixelArea );
754 propertyMap.Insert( ImageVisual::Property::WRAP_MODE_U, WrapMode::MIRRORED_REPEAT );
755 propertyMap.Insert( ImageVisual::Property::WRAP_MODE_V, WrapMode::REPEAT );
757 Visual::Base visual = factory.CreateVisual( propertyMap );
758 DALI_TEST_CHECK( visual );
760 Actor actor = Actor::New();
761 TestGlAbstraction& gl = application.GetGlAbstraction();
762 TraceCallStack& textureTrace = gl.GetTextureTrace();
763 textureTrace.Enable(true);
764 TraceCallStack& texParameterTrace = gl.GetTexParameterTrace();
765 texParameterTrace.Enable( true );
767 actor.SetSize( 200.f, 200.f );
768 Stage::GetCurrent().Add( actor );
769 visual.SetOnStage( actor );
772 application.SendNotification();
773 application.Render();
774 application.Render();
775 application.SendNotification();
776 BitmapLoader loader = BitmapLoader::GetLatestCreated();
777 DALI_TEST_CHECK( loader );
778 loader.WaitForLoading();// waiting until the image to be loaded
779 DALI_TEST_CHECK( loader.IsLoaded() );
781 DALI_TEST_CHECK( actor.GetRendererCount() == 1u );
783 DALI_TEST_EQUALS( textureTrace.FindMethod("BindTexture"), true, TEST_LOCATION );
785 // WITHOUT atlasing, the wrapping is handled by setting gl texture parameters
786 std::stringstream out;
787 out << GL_TEXTURE_2D << ", " << GL_TEXTURE_WRAP_S << ", " << GL_MIRRORED_REPEAT;
788 DALI_TEST_CHECK( texParameterTrace.FindMethodAndParams("TexParameteri", out.str()) );
790 out << GL_TEXTURE_2D << ", " << GL_TEXTURE_WRAP_T << ", " << GL_REPEAT;
791 DALI_TEST_CHECK( texParameterTrace.FindMethodAndParams("TexParameteri", out.str()) );
793 // test the uniforms which used to handle the wrap mode
794 Renderer renderer = actor.GetRendererAt( 0u );
795 DALI_TEST_CHECK( renderer );
797 Property::Value pixelAreaValue = renderer.GetProperty( renderer.GetPropertyIndex( "pixelArea" ) );
798 DALI_TEST_EQUALS( pixelAreaValue.Get<Vector4>(), pixelArea, TEST_LOCATION );
799 Vector4 pixelAreaUniform;
800 DALI_TEST_CHECK( gl.GetUniformValue<Vector4>( "pixelArea", pixelAreaUniform ) );
801 DALI_TEST_EQUALS( pixelArea, pixelAreaUniform, Math::MACHINE_EPSILON_100, TEST_LOCATION );
803 Property::Index wrapModeIndex = renderer.GetPropertyIndex( "wrapMode" );
804 DALI_TEST_CHECK(wrapModeIndex == Property::INVALID_INDEX);
806 visual.SetOffStage( actor );
807 DALI_TEST_CHECK( actor.GetRendererCount() == 0u );
812 int UtcDaliVisualFactoryGetNPatchVisual1(void)
814 ToolkitTestApplication application;
815 tet_infoline( "UtcDaliVisualFactoryGetNPatchVisual1: Request 9-patch visual with a Property::Map" );
817 VisualFactory factory = VisualFactory::Get();
818 DALI_TEST_CHECK( factory );
820 const unsigned int ninePatchImageHeight = 18;
821 const unsigned int ninePatchImageWidth = 28;
822 StretchRanges stretchRangesX;
823 stretchRangesX.PushBack( Uint16Pair( 2, 3 ) );
824 StretchRanges stretchRangesY;
825 stretchRangesY.PushBack( Uint16Pair( 4, 5 ) );
826 Integration::ResourcePointer ninePatchResource = CustomizeNinePatch( application, ninePatchImageWidth, ninePatchImageHeight, stretchRangesX, stretchRangesY );
828 Property::Map propertyMap;
829 propertyMap.Insert( Visual::Property::TYPE, Visual::IMAGE );
830 propertyMap.Insert( ImageVisual::Property::URL, TEST_NPATCH_FILE_NAME );
832 tet_infoline( "whole grid" );
833 Visual::Base visual = factory.CreateVisual( propertyMap );
834 DALI_TEST_CHECK( visual );
836 Actor actor = Actor::New();
838 TestGlAbstraction& gl = application.GetGlAbstraction();
839 TraceCallStack& textureTrace = gl.GetTextureTrace();
840 textureTrace.Enable(true);
842 TestVisualRender( application, actor, visual, 1u,
843 ImageDimensions(ninePatchImageWidth, ninePatchImageHeight),
846 DALI_TEST_EQUALS( textureTrace.FindMethod("BindTexture"), true, TEST_LOCATION );
849 propertyMap.Insert( ImageVisual::Property::BORDER_ONLY, true );
851 tet_infoline( "border only" );
852 Visual::Base visual = factory.CreateVisual( propertyMap );
853 DALI_TEST_CHECK( visual );
855 Actor actor = Actor::New();
857 TestGlAbstraction& gl = application.GetGlAbstraction();
858 TraceCallStack& textureTrace = gl.GetTextureTrace();
859 textureTrace.Enable(true);
861 TestVisualRender( application, actor, visual, 1u,
862 ImageDimensions(ninePatchImageWidth, ninePatchImageHeight),
865 DALI_TEST_EQUALS( textureTrace.FindMethod("BindTexture"), true, TEST_LOCATION );
871 int UtcDaliVisualFactoryGetNPatchVisual2(void)
873 ToolkitTestApplication application;
874 tet_infoline( "UtcDaliVisualFactoryGetNPatchVisual2: Request n-patch visual with a Property::Map" );
876 VisualFactory factory = VisualFactory::Get();
877 DALI_TEST_CHECK( factory );
879 const unsigned int ninePatchImageWidth = 18;
880 const unsigned int ninePatchImageHeight = 28;
881 StretchRanges stretchRangesX;
882 stretchRangesX.PushBack( Uint16Pair( 2, 3 ) );
883 stretchRangesX.PushBack( Uint16Pair( 5, 7 ) );
884 stretchRangesX.PushBack( Uint16Pair( 12, 15 ) );
885 StretchRanges stretchRangesY;
886 stretchRangesY.PushBack( Uint16Pair( 4, 5 ) );
887 stretchRangesY.PushBack( Uint16Pair( 8, 12 ) );
888 stretchRangesY.PushBack( Uint16Pair( 15, 16 ) );
889 stretchRangesY.PushBack( Uint16Pair( 25, 27 ) );
890 Integration::ResourcePointer ninePatchResource = CustomizeNinePatch( application, ninePatchImageWidth, ninePatchImageHeight, stretchRangesX, stretchRangesY );
892 Property::Map propertyMap;
893 propertyMap.Insert( Visual::Property::TYPE, Visual::IMAGE );
894 propertyMap.Insert( ImageVisual::Property::URL, TEST_NPATCH_FILE_NAME );
896 Visual::Base visual = factory.CreateVisual( propertyMap );
897 DALI_TEST_CHECK( visual );
899 Actor actor = Actor::New();
900 TestGlAbstraction& gl = application.GetGlAbstraction();
901 TraceCallStack& textureTrace = gl.GetTextureTrace();
902 textureTrace.Enable(true);
904 TestVisualRender( application, actor, visual, 1u,
905 ImageDimensions(ninePatchImageWidth, ninePatchImageHeight),
909 DALI_TEST_EQUALS( textureTrace.FindMethod("BindTexture"), true, TEST_LOCATION );
911 visual.SetOffStage( actor );
912 DALI_TEST_CHECK( actor.GetRendererCount() == 0u );
915 propertyMap.Insert( ImageVisual::Property::BORDER_ONLY, true );
917 tet_infoline( "border only" );
918 Visual::Base visual = factory.CreateVisual( propertyMap );
919 DALI_TEST_CHECK( visual );
921 TestGlAbstraction& gl = application.GetGlAbstraction();
922 TraceCallStack& textureTrace = gl.GetTextureTrace();
923 textureTrace.Enable(true);
924 Actor actor = Actor::New();
925 TestVisualRender( application, actor, visual, 1u,
926 ImageDimensions(ninePatchImageWidth, ninePatchImageHeight),
930 DALI_TEST_EQUALS( textureTrace.FindMethod("BindTexture"), true, TEST_LOCATION );
932 visual.SetOffStage( actor );
933 DALI_TEST_CHECK( actor.GetRendererCount() == 0u );
939 int UtcDaliVisualFactoryGetNPatchVisual3(void)
941 ToolkitTestApplication application;
942 tet_infoline( "UtcDaliVisualFactoryGetNPatchVisual3: Request 9-patch visual with an image url" );
944 VisualFactory factory = VisualFactory::Get();
945 DALI_TEST_CHECK( factory );
947 const unsigned int ninePatchImageHeight = 18;
948 const unsigned int ninePatchImageWidth = 28;
949 StretchRanges stretchRangesX;
950 stretchRangesX.PushBack( Uint16Pair( 2, 3 ) );
951 StretchRanges stretchRangesY;
952 stretchRangesY.PushBack( Uint16Pair( 4, 5 ) );
953 Integration::ResourcePointer ninePatchResource = CustomizeNinePatch( application, ninePatchImageWidth, ninePatchImageHeight, stretchRangesX, stretchRangesY );
955 Visual::Base visual = factory.CreateVisual( TEST_NPATCH_FILE_NAME, ImageDimensions() );
956 DALI_TEST_CHECK( visual );
958 Actor actor = Actor::New();
960 TestGlAbstraction& gl = application.GetGlAbstraction();
961 TraceCallStack& textureTrace = gl.GetTextureTrace();
962 textureTrace.Enable(true);
964 TestVisualRender( application, actor, visual, 1u,
965 ImageDimensions(ninePatchImageWidth, ninePatchImageHeight),
968 DALI_TEST_EQUALS( textureTrace.FindMethod("BindTexture"), true, TEST_LOCATION );
973 int UtcDaliVisualFactoryGetNPatchVisual4(void)
975 ToolkitTestApplication application;
976 tet_infoline( "UtcDaliVisualFactoryGetNPatchVisual4: Request n-patch visual with an image url" );
978 VisualFactory factory = VisualFactory::Get();
979 DALI_TEST_CHECK( factory );
981 const unsigned int ninePatchImageHeight = 18;
982 const unsigned int ninePatchImageWidth = 28;
983 StretchRanges stretchRangesX;
984 stretchRangesX.PushBack( Uint16Pair( 2, 3 ) );
985 stretchRangesX.PushBack( Uint16Pair( 5, 7 ) );
986 stretchRangesX.PushBack( Uint16Pair( 12, 15 ) );
987 StretchRanges stretchRangesY;
988 stretchRangesY.PushBack( Uint16Pair( 4, 5 ) );
989 stretchRangesY.PushBack( Uint16Pair( 8, 12 ) );
990 stretchRangesY.PushBack( Uint16Pair( 15, 16 ) );
991 stretchRangesY.PushBack( Uint16Pair( 25, 27 ) );
992 Integration::ResourcePointer ninePatchResource = CustomizeNinePatch( application, ninePatchImageWidth, ninePatchImageHeight, stretchRangesX, stretchRangesY );
994 Visual::Base visual = factory.CreateVisual( TEST_NPATCH_FILE_NAME, ImageDimensions() );
995 DALI_TEST_CHECK( visual );
997 Actor actor = Actor::New();
999 TestGlAbstraction& gl = application.GetGlAbstraction();
1000 TraceCallStack& textureTrace = gl.GetTextureTrace();
1001 textureTrace.Enable(true);
1003 TestVisualRender( application, actor, visual, 1u,
1004 ImageDimensions(ninePatchImageWidth, ninePatchImageHeight),
1005 ninePatchResource );
1007 DALI_TEST_EQUALS( textureTrace.FindMethod("BindTexture"), true, TEST_LOCATION );
1012 int UtcDaliVisualFactoryGetNPatchVisualN1(void)
1014 //This should still load but display an error image
1016 ToolkitTestApplication application;
1017 tet_infoline( "UtcDaliVisualFactoryGetNPatchVisualN: Request n-patch visual with an invalid image url" );
1019 VisualFactory factory = VisualFactory::Get();
1020 DALI_TEST_CHECK( factory );
1022 Visual::Base visual = factory.CreateVisual( "ERROR.9.jpg", ImageDimensions() );
1023 DALI_TEST_CHECK( visual );
1025 Actor actor = Actor::New();
1027 //The testkit still has to load a bitmap for the broken renderer image
1028 Integration::Bitmap* bitmap = Integration::Bitmap::New(Integration::Bitmap::BITMAP_2D_PACKED_PIXELS, ResourcePolicy::OWNED_DISCARD);
1029 bitmap->GetPackedPixelsProfile()->ReserveBuffer( Pixel::RGBA8888, 100, 100, 100, 100 );
1031 TestGlAbstraction& gl = application.GetGlAbstraction();
1032 TraceCallStack& textureTrace = gl.GetTextureTrace();
1033 textureTrace.Enable(true);
1035 TestVisualRender( application, actor, visual, 1u,
1037 Integration::ResourcePointer(bitmap) );
1039 DALI_TEST_EQUALS( textureTrace.FindMethod("BindTexture"), true, TEST_LOCATION );
1044 int UtcDaliVisualFactoryGetNPatchVisualN2(void)
1046 //This should still load but display an error image
1048 ToolkitTestApplication application;
1049 tet_infoline( "UtcDaliVisualFactoryGetNPatchVisualN: Request n-patch visual with an invalid URL" );
1051 VisualFactory factory = VisualFactory::Get();
1052 DALI_TEST_CHECK( factory );
1054 Property::Map propertyMap;
1055 propertyMap.Insert( Visual::Property::TYPE, Visual::IMAGE );
1056 propertyMap.Insert( ImageVisual::Property::URL, "ERROR.9.jpg" );
1058 Visual::Base visual = factory.CreateVisual( propertyMap );
1059 DALI_TEST_CHECK( visual );
1061 Actor actor = Actor::New();
1063 //The testkit still has to load a bitmap for the broken renderer image
1064 Integration::Bitmap* bitmap = Integration::Bitmap::New(Integration::Bitmap::BITMAP_2D_PACKED_PIXELS, ResourcePolicy::OWNED_DISCARD);
1065 bitmap->GetPackedPixelsProfile()->ReserveBuffer( Pixel::RGBA8888, 100, 100, 100, 100 );
1067 TestGlAbstraction& gl = application.GetGlAbstraction();
1068 TraceCallStack& textureTrace = gl.GetTextureTrace();
1069 textureTrace.Enable(true);
1071 TestVisualRender( application, actor, visual, 1u,
1073 Integration::ResourcePointer(bitmap) );
1075 DALI_TEST_EQUALS( textureTrace.FindMethod("BindTexture"), true, TEST_LOCATION );
1080 int UtcDaliVisualFactoryGetNPatchVisualN3(void)
1082 // Passing in an invalid visual type so we should not get a visual
1084 ToolkitTestApplication application;
1085 tet_infoline( "UtcDaliVisualFactoryGetNPatchVisualN: Request n-patch visual with an invalid visual type" );
1087 VisualFactory factory = VisualFactory::Get();
1088 DALI_TEST_CHECK( factory );
1090 Property::Map propertyMap;
1091 propertyMap.Insert( Visual::Property::TYPE, 111 );
1092 propertyMap.Insert( ImageVisual::Property::URL, "ERROR.9.jpg" );
1094 Visual::Base visual = factory.CreateVisual( propertyMap );
1095 DALI_TEST_CHECK( !visual );
1100 int UtcDaliVisualFactoryGetSvgVisual(void)
1102 ToolkitTestApplication application;
1103 tet_infoline( "UtcDaliVisualFactoryGetSvgVisual: Request svg visual with a svg url" );
1105 VisualFactory factory = VisualFactory::Get();
1106 Visual::Base visual = factory.CreateVisual( TEST_SVG_FILE_NAME, ImageDimensions() );
1107 DALI_TEST_CHECK( visual );
1109 TestGlAbstraction& gl = application.GetGlAbstraction();
1110 TraceCallStack& textureTrace = gl.GetTextureTrace();
1111 textureTrace.Enable(true);
1113 Actor actor = Actor::New();
1114 actor.SetSize( 200.f, 200.f );
1115 Stage::GetCurrent().Add( actor );
1116 visual.SetSize( Vector2(200.f, 200.f) );
1117 visual.SetOnStage( actor );
1118 application.SendNotification();
1119 application.Render();
1121 // renderer is not added to actor until the rasterization is completed.
1122 DALI_TEST_CHECK( actor.GetRendererCount() == 0u );
1124 EventThreadCallback* eventTrigger = EventThreadCallback::Get();
1125 CallbackBase* callback = eventTrigger->GetCallback();
1127 eventTrigger->WaitingForTrigger( 1 );// waiting until the svg image is rasterized.
1128 CallbackBase::Execute( *callback );
1130 // renderer is added to actor
1131 DALI_TEST_CHECK( actor.GetRendererCount() == 1u );
1133 // waiting for the resource uploading
1134 application.SendNotification();
1135 application.Render();
1137 DALI_TEST_EQUALS( textureTrace.FindMethod("BindTexture"), true, TEST_LOCATION );
1142 int UtcDaliVisualFactoryGetSvgVisualLarge(void)
1144 ToolkitTestApplication application;
1145 tet_infoline( "UtcDaliVisualFactoryGetSvgVisual: Request svg visual with a svg url" );
1147 VisualFactory factory = VisualFactory::Get();
1148 Visual::Base visual = factory.CreateVisual( TEST_SVG_FILE_NAME, ImageDimensions( 2000, 2000 ) );
1149 DALI_TEST_CHECK( visual );
1151 TestGlAbstraction& gl = application.GetGlAbstraction();
1152 TraceCallStack& textureTrace = gl.GetTextureTrace();
1153 textureTrace.Enable(true);
1155 Actor actor = Actor::New();
1156 Stage::GetCurrent().Add( actor );
1157 visual.SetOnStage( actor );
1158 application.SendNotification();
1159 application.Render();
1161 // renderer is not added to actor until the rasterization is completed.
1162 DALI_TEST_CHECK( actor.GetRendererCount() == 0u );
1164 EventThreadCallback* eventTrigger = EventThreadCallback::Get();
1165 CallbackBase* callback = eventTrigger->GetCallback();
1167 eventTrigger->WaitingForTrigger( 1 );// waiting until the svg image is rasterized.
1168 CallbackBase::Execute( *callback );
1170 // renderer is added to actor
1171 DALI_TEST_CHECK( actor.GetRendererCount() == 1u );
1173 // waiting for the resource uploading
1174 application.SendNotification();
1175 application.Render();
1177 DALI_TEST_EQUALS( textureTrace.FindMethod("BindTexture"), true, TEST_LOCATION );
1182 //Creates a mesh visual from the given propertyMap and tries to load it on stage in the given application.
1183 //This is expected to succeed, which will then pass the test.
1184 void MeshVisualLoadsCorrectlyTest( Property::Map& propertyMap, ToolkitTestApplication& application )
1186 VisualFactory factory = VisualFactory::Get();
1187 DALI_TEST_CHECK( factory );
1189 //Create a mesh visual.
1190 Visual::Base visual = factory.CreateVisual( propertyMap );
1191 DALI_TEST_CHECK( visual );
1193 //Create an actor on stage to house the visual.
1194 Actor actor = Actor::New();
1195 actor.SetSize( 200.f, 200.f );
1196 Stage::GetCurrent().Add( actor );
1197 visual.SetSize( Vector2( 200.f, 200.f ) );
1198 visual.SetOnStage( actor );
1200 //Ensure set on stage.
1201 DALI_TEST_EQUALS( actor.GetRendererCount(), 1u, TEST_LOCATION );
1203 //Attempt to render to queue resource load requests.
1204 application.SendNotification();
1205 application.Render( 0 );
1207 //Tell the platform abstraction that the required resources have been loaded.
1208 TestPlatformAbstraction& platform = application.GetPlatform();
1209 platform.SetAllResourceRequestsAsLoaded();
1211 //Render again to upload the now-loaded textures.
1212 application.SendNotification();
1213 application.Render( 0 );
1215 Matrix testScaleMatrix;
1216 testScaleMatrix.SetIdentityAndScale( Vector3( 1.0, -1.0, 1.0 ) );
1217 Matrix actualScaleMatrix;
1219 //Test to see if the object has been successfully loaded.
1220 DALI_TEST_CHECK( application.GetGlAbstraction().GetUniformValue<Matrix>( "uObjectMatrix", actualScaleMatrix ) );
1221 DALI_TEST_EQUALS( actualScaleMatrix, testScaleMatrix, Math::MACHINE_EPSILON_100, TEST_LOCATION );
1223 //Finish by setting off stage, and ensuring this was successful.
1224 visual.SetOffStage( actor );
1225 DALI_TEST_EQUALS( actor.GetRendererCount(), 0u, TEST_LOCATION );
1228 //Creates a mesh visual from the given propertyMap and tries to load it on stage in the given application.
1229 //This is expected to fail, which will then pass the test.
1230 void MeshVisualDoesNotLoadCorrectlyTest( Property::Map& propertyMap, ToolkitTestApplication& application )
1232 VisualFactory factory = VisualFactory::Get();
1233 DALI_TEST_CHECK( factory );
1235 //Create a mesh visual.
1236 Visual::Base visual = factory.CreateVisual( propertyMap );
1237 DALI_TEST_CHECK( visual );
1239 //Create an actor on stage to house the visual.
1240 Actor actor = Actor::New();
1241 actor.SetSize( 200.f, 200.f );
1242 Stage::GetCurrent().Add( actor );
1243 visual.SetSize( Vector2( 200.f, 200.f ) );
1244 visual.SetOnStage( actor );
1246 //Ensure set on stage.
1247 DALI_TEST_EQUALS( actor.GetRendererCount(), 1u, TEST_LOCATION );
1249 //Attempt to render to queue resource load requests.
1250 application.SendNotification();
1251 application.Render( 0 );
1253 //Tell the platform abstraction that the required resources have been loaded.
1254 TestPlatformAbstraction& platform = application.GetPlatform();
1255 platform.SetAllResourceRequestsAsLoaded();
1257 //Render again to upload the now-loaded textures.
1258 application.SendNotification();
1259 application.Render( 0 );
1261 //Test to see if the object has not been loaded, as expected.
1263 DALI_TEST_CHECK( !application.GetGlAbstraction().GetUniformValue<Matrix>( "uObjectMatrix", scaleMatrix ) );
1265 //Finish by setting off stage, and ensuring this was successful.
1266 visual.SetOffStage( actor );
1267 DALI_TEST_EQUALS( actor.GetRendererCount(), 0u, TEST_LOCATION );
1270 //Test if mesh loads correctly when supplied with only the bare minimum requirements, an object file.
1271 int UtcDaliVisualFactoryGetMeshVisual1(void)
1273 //Set up test application first, so everything else can be handled.
1274 ToolkitTestApplication application;
1276 tet_infoline( "UtcDaliVisualFactoryGetMeshVisual1: Request mesh visual with a valid object file only" );
1279 //Set up visual properties.
1280 Property::Map propertyMap;
1281 propertyMap.Insert( Visual::Property::TYPE, Visual::MESH );
1282 propertyMap.Insert( MeshVisual::Property::OBJECT_URL, TEST_OBJ_FILE_NAME );
1284 //Test to see if mesh loads correctly.
1285 MeshVisualLoadsCorrectlyTest( propertyMap, application );
1291 //Test if mesh loads correctly when supplied with an object file as well as a blank material file and images directory.
1292 int UtcDaliVisualFactoryGetMeshVisual2(void)
1294 //Set up test application first, so everything else can be handled.
1295 ToolkitTestApplication application;
1297 tet_infoline( "UtcDaliVisualFactoryGetMeshVisual2: Request mesh visual with blank material file and images directory" );
1299 //Set up visual properties.
1300 Property::Map propertyMap;
1301 propertyMap.Insert( Visual::Property::TYPE, Visual::MESH );
1302 propertyMap.Insert( MeshVisual::Property::OBJECT_URL, TEST_OBJ_FILE_NAME );
1303 propertyMap.Insert( MeshVisual::Property::MATERIAL_URL, "" );
1304 propertyMap.Insert( MeshVisual::Property::TEXTURES_PATH, "" );
1306 //Test to see if mesh loads correctly.
1307 MeshVisualLoadsCorrectlyTest( propertyMap, application );
1312 //Test if mesh loads correctly when supplied with all main parameters, an object file, a material file and a directory location.
1313 int UtcDaliVisualFactoryGetMeshVisual3(void)
1315 //Set up test application first, so everything else can be handled.
1316 ToolkitTestApplication application;
1318 tet_infoline( "UtcDaliVisualFactoryGetMeshVisual3: Request mesh visual with all parameters correct" );
1320 //Set up visual properties.
1321 Property::Map propertyMap;
1322 propertyMap.Insert( Visual::Property::TYPE, Visual::MESH );
1323 propertyMap.Insert( MeshVisual::Property::OBJECT_URL, TEST_OBJ_FILE_NAME );
1324 propertyMap.Insert( MeshVisual::Property::MATERIAL_URL, TEST_MTL_FILE_NAME );
1325 propertyMap.Insert( MeshVisual::Property::TEXTURES_PATH, TEST_RESOURCE_DIR "/" );
1327 //Test to see if mesh loads correctly.
1328 MeshVisualLoadsCorrectlyTest( propertyMap, application );
1333 //Test if mesh visual can load a correctly supplied mesh without a normal map or gloss map in the material file.
1334 int UtcDaliVisualFactoryGetMeshVisual4(void)
1336 //Set up test application first, so everything else can be handled.
1337 ToolkitTestApplication application;
1339 tet_infoline( "UtcDaliVisualFactoryGetMeshVisual4: Request mesh visual with diffuse texture but not normal or gloss." );
1342 //Set up visual properties.
1343 Property::Map propertyMap;
1344 propertyMap.Insert( Visual::Property::TYPE, Visual::MESH );
1345 propertyMap.Insert( MeshVisual::Property::OBJECT_URL, TEST_OBJ_FILE_NAME );
1346 propertyMap.Insert( MeshVisual::Property::MATERIAL_URL, TEST_SIMPLE_MTL_FILE_NAME );
1347 propertyMap.Insert( MeshVisual::Property::TEXTURES_PATH, TEST_RESOURCE_DIR "/" );
1349 //Test to see if mesh loads correctly.
1350 MeshVisualLoadsCorrectlyTest( propertyMap, application );
1356 //Test if mesh visual can load when made to use diffuse textures only.
1357 int UtcDaliVisualFactoryGetMeshVisual5(void)
1359 //Set up test application first, so everything else can be handled.
1360 ToolkitTestApplication application;
1362 tet_infoline( "UtcDaliVisualFactoryGetMeshVisual5: Request mesh visual and make it only use diffuse textures." );
1364 //Set up visual properties.
1365 Property::Map propertyMap;
1366 propertyMap.Insert( Visual::Property::TYPE, Visual::MESH );
1367 propertyMap.Insert( MeshVisual::Property::OBJECT_URL, TEST_OBJ_FILE_NAME );
1368 propertyMap.Insert( MeshVisual::Property::MATERIAL_URL, TEST_MTL_FILE_NAME );
1369 propertyMap.Insert( MeshVisual::Property::TEXTURES_PATH, TEST_RESOURCE_DIR "/" );
1370 propertyMap.Insert( MeshVisual::Property::SHADING_MODE, MeshVisual::ShadingMode::TEXTURED_WITH_SPECULAR_LIGHTING );
1372 //Test to see if mesh loads correctly.
1373 MeshVisualLoadsCorrectlyTest( propertyMap, application );
1379 //Test if mesh visual can load when made to not use the supplied textures.
1380 int UtcDaliVisualFactoryGetMeshVisual6(void)
1382 //Set up test application first, so everything else can be handled.
1383 ToolkitTestApplication application;
1385 tet_infoline( "UtcDaliVisualFactoryGetMeshVisual6: Request mesh visual and make it not use any textures." );
1387 //Set up visual properties.
1388 Property::Map propertyMap;
1389 propertyMap.Insert( Visual::Property::TYPE, Visual::MESH );
1390 propertyMap.Insert( MeshVisual::Property::OBJECT_URL, TEST_OBJ_FILE_NAME );
1391 propertyMap.Insert( MeshVisual::Property::MATERIAL_URL, TEST_MTL_FILE_NAME );
1392 propertyMap.Insert( MeshVisual::Property::TEXTURES_PATH, TEST_RESOURCE_DIR "/" );
1393 propertyMap.Insert( MeshVisual::Property::SHADING_MODE, MeshVisual::ShadingMode::TEXTURELESS_WITH_DIFFUSE_LIGHTING );
1395 //Test to see if mesh loads correctly.
1396 MeshVisualLoadsCorrectlyTest( propertyMap, application );
1400 //Test if mesh visual loads correctly when light position is manually set.
1401 int UtcDaliVisualFactoryGetMeshVisual7(void)
1403 //Set up test application first, so everything else can be handled.
1404 ToolkitTestApplication application;
1407 tet_infoline( "UtcDaliVisualFactoryGetMeshVisual7: Request mesh visual with custom light position." );
1409 //Set up visual properties.
1410 Property::Map propertyMap;
1411 propertyMap.Insert( Visual::Property::TYPE, Visual::MESH );
1412 propertyMap.Insert( MeshVisual::Property::OBJECT_URL, TEST_OBJ_FILE_NAME );
1413 propertyMap.Insert( MeshVisual::Property::MATERIAL_URL, TEST_MTL_FILE_NAME );
1414 propertyMap.Insert( MeshVisual::Property::TEXTURES_PATH, TEST_RESOURCE_DIR "/" );
1415 propertyMap.Insert( MeshVisual::Property::LIGHT_POSITION, Vector3( 0.0, 1.0, 2.0 ) );
1417 //Test to see if mesh loads correctly.
1418 MeshVisualLoadsCorrectlyTest( propertyMap, application );
1423 //Test if mesh visual loads correctly when supplied an object file without face normals or texture points.
1424 //Note that this notably tests object loader functionality.
1425 int UtcDaliVisualFactoryGetMeshVisual8(void)
1427 //Set up test application first, so everything else can be handled.
1428 ToolkitTestApplication application;
1430 tet_infoline( "UtcDaliVisualFactoryGetMeshVisual5: Request mesh visual with normal-less object file." );
1432 //Set up visual properties.
1433 Property::Map propertyMap;
1434 propertyMap.Insert( Visual::Property::TYPE, Visual::MESH );
1435 propertyMap.Insert( MeshVisual::Property::OBJECT_URL, TEST_SIMPLE_OBJ_FILE_NAME );
1436 propertyMap.Insert( MeshVisual::Property::MATERIAL_URL, TEST_MTL_FILE_NAME );
1437 propertyMap.Insert( MeshVisual::Property::TEXTURES_PATH, TEST_RESOURCE_DIR "/" );
1439 //Test to see if mesh loads correctly.
1440 MeshVisualLoadsCorrectlyTest( propertyMap, application );
1445 //Test if mesh visual handles the case of lacking an object file.
1446 int UtcDaliVisualFactoryGetMeshVisualN1(void)
1448 //Set up test application first, so everything else can be handled.
1449 ToolkitTestApplication application;
1451 tet_infoline( "UtcDaliVisualFactoryGetMeshVisualN1: Request mesh visual without object file" );
1453 //Set up visual properties.
1454 Property::Map propertyMap;
1455 propertyMap.Insert( Visual::Property::TYPE, Visual::MESH );
1456 propertyMap.Insert( MeshVisual::Property::MATERIAL_URL, TEST_MTL_FILE_NAME );
1457 propertyMap.Insert( MeshVisual::Property::TEXTURES_PATH, TEST_RESOURCE_DIR "/" );
1459 //Test to see if mesh doesn't load with these properties, as expected.
1460 MeshVisualDoesNotLoadCorrectlyTest( propertyMap, application );
1466 //Test if mesh visual handles the case of being passed invalid material and images urls.
1467 int UtcDaliVisualFactoryGetMeshVisualN2(void)
1469 //Set up test application first, so everything else can be handled.
1470 ToolkitTestApplication application;
1472 tet_infoline( "UtcDaliVisualFactoryGetMeshVisualN2: Request mesh visual with invalid material and images urls" );
1474 //Set up visual properties.
1475 Property::Map propertyMap;
1476 propertyMap.Insert( Visual::Property::TYPE, Visual::MESH );
1477 propertyMap.Insert( MeshVisual::Property::OBJECT_URL, TEST_OBJ_FILE_NAME );
1478 propertyMap.Insert( MeshVisual::Property::MATERIAL_URL, "invalid" );
1479 propertyMap.Insert( MeshVisual::Property::TEXTURES_PATH, "also invalid" );
1481 //Test to see if mesh doesn't load with these properties, as expected.
1482 MeshVisualDoesNotLoadCorrectlyTest( propertyMap, application );
1488 //Test if mesh visual handles the case of being passed an invalid object url
1489 int UtcDaliVisualFactoryGetMeshVisualN3(void)
1491 //Set up test application first, so everything else can be handled.
1492 ToolkitTestApplication application;
1493 tet_infoline( "UtcDaliVisualFactoryGetMeshVisualN3: Request mesh visual with invalid object url" );
1496 //Set up visual properties.
1497 Property::Map propertyMap;
1498 propertyMap.Insert( Visual::Property::TYPE, Visual::MESH );
1499 propertyMap.Insert( MeshVisual::Property::OBJECT_URL, "invalid" );
1500 propertyMap.Insert( MeshVisual::Property::MATERIAL_URL, TEST_MTL_FILE_NAME );
1501 propertyMap.Insert( MeshVisual::Property::TEXTURES_PATH, TEST_RESOURCE_DIR "/" );
1503 //Test to see if mesh doesn't load with these properties, as expected.
1504 MeshVisualDoesNotLoadCorrectlyTest( propertyMap, application );
1509 //Creates a primitive visual with the given property map and tests to see if it correctly loads in the given application.
1510 void TestPrimitiveVisualWithProperties( Property::Map& propertyMap, ToolkitTestApplication& application )
1512 VisualFactory factory = VisualFactory::Get();
1513 DALI_TEST_CHECK( factory );
1515 //Create a primitive visual.
1516 Visual::Base visual = factory.CreateVisual( propertyMap );
1517 DALI_TEST_CHECK( visual );
1519 //Create an actor on stage to house the visual.
1520 Actor actor = Actor::New();
1521 actor.SetSize( 200.f, 200.f );
1522 Stage::GetCurrent().Add( actor );
1523 visual.SetSize( Vector2( 200.f, 200.f ) );
1524 visual.SetOnStage( actor );
1526 //Ensure set on stage.
1527 DALI_TEST_EQUALS( actor.GetRendererCount(), 1u, TEST_LOCATION );
1529 //Tell test application to load the visual.
1530 application.SendNotification();
1531 application.Render(0);
1533 Matrix testScaleMatrix;
1534 testScaleMatrix.SetIdentityAndScale( Vector3( 1.0, -1.0, 1.0 ) );
1535 Matrix actualScaleMatrix;
1537 //Test to see if the object has been successfully loaded.
1538 DALI_TEST_CHECK( application.GetGlAbstraction().GetUniformValue<Matrix>( "uObjectMatrix", actualScaleMatrix ) );
1539 DALI_TEST_EQUALS( actualScaleMatrix, testScaleMatrix, Math::MACHINE_EPSILON_100, TEST_LOCATION );
1541 //Finish by setting off stage, and ensuring this was successful.
1542 visual.SetOffStage( actor );
1543 DALI_TEST_EQUALS( actor.GetRendererCount(), 0u, TEST_LOCATION );
1546 //Test if primitive shape loads correctly when supplied with only the bare minimum requirements, the shape to use.
1547 int UtcDaliVisualFactoryGetPrimitiveVisual1(void)
1549 //Set up test application first, so everything else can be handled.
1550 ToolkitTestApplication application;
1552 tet_infoline( "UtcDaliVisualFactoryGetPrimitiveVisual1: Request primitive visual with a shape only" );
1554 //Set up visual properties.
1555 Property::Map propertyMap;
1556 propertyMap.Insert( Visual::Property::TYPE, Visual::PRIMITIVE );
1557 propertyMap.Insert( PrimitiveVisual::Property::SHAPE, PrimitiveVisual::Shape::CUBE );
1559 //Test to see if shape loads correctly.
1560 TestPrimitiveVisualWithProperties( propertyMap, application );
1565 //Test if primitive shape loads correctly when supplied with all possible parameters
1566 int UtcDaliVisualFactoryGetPrimitiveVisual2(void)
1568 //Set up test application first, so everything else can be handled.
1569 ToolkitTestApplication application;
1571 tet_infoline( "UtcDaliVisualFactoryGetPrimitiveVisual2: Request primitive visual with everything" );
1573 //Set up visual properties.
1574 Property::Map propertyMap;
1575 propertyMap.Insert( Visual::Property::TYPE, Visual::PRIMITIVE );
1576 propertyMap.Insert( PrimitiveVisual::Property::SHAPE, PrimitiveVisual::Shape::CUBE );
1577 propertyMap.Insert( PrimitiveVisual::Property::MIX_COLOR, Vector4( 0.5, 0.5, 0.5, 1.0 ) );
1578 propertyMap.Insert( PrimitiveVisual::Property::SLICES, 10 );
1579 propertyMap.Insert( PrimitiveVisual::Property::STACKS, 20 );
1580 propertyMap.Insert( PrimitiveVisual::Property::SCALE_TOP_RADIUS, 30.0f );
1581 propertyMap.Insert( PrimitiveVisual::Property::SCALE_BOTTOM_RADIUS, 40.0f );
1582 propertyMap.Insert( PrimitiveVisual::Property::SCALE_HEIGHT, 50.0f );
1583 propertyMap.Insert( PrimitiveVisual::Property::SCALE_RADIUS, 60.0f );
1584 propertyMap.Insert( PrimitiveVisual::Property::BEVEL_PERCENTAGE, 0.7f );
1585 propertyMap.Insert( PrimitiveVisual::Property::BEVEL_SMOOTHNESS, 0.8f );
1586 propertyMap.Insert( MeshVisual::Property::LIGHT_POSITION, Vector3( 0.9, 1.0, 1.1 ) );
1588 //Test to see if shape loads correctly.
1589 TestPrimitiveVisualWithProperties( propertyMap, application );
1594 //Test if primitive shape loads a sphere correctly.
1595 int UtcDaliVisualFactoryGetPrimitiveVisual3(void)
1597 //Set up test application first, so everything else can be handled.
1598 ToolkitTestApplication application;
1600 tet_infoline( "UtcDaliVisualFactoryGetPrimitiveVisual3: Request primitive visual to display a sphere" );
1602 //Set up visual properties.
1603 Property::Map propertyMap;
1604 propertyMap.Insert( Visual::Property::TYPE, Visual::PRIMITIVE );
1605 propertyMap.Insert( PrimitiveVisual::Property::SHAPE, PrimitiveVisual::Shape::SPHERE );
1606 propertyMap.Insert( PrimitiveVisual::Property::MIX_COLOR, Vector4( 0.5, 0.5, 0.5, 1.0 ) );
1607 propertyMap.Insert( PrimitiveVisual::Property::SLICES, 10 );
1608 propertyMap.Insert( PrimitiveVisual::Property::STACKS, 20 );
1610 //Test to see if shape loads correctly.
1611 TestPrimitiveVisualWithProperties( propertyMap, application );
1616 //Test if primitive shape loads a conic section correctly.
1617 int UtcDaliVisualFactoryGetPrimitiveVisual4(void)
1619 //Set up test application first, so everything else can be handled.
1620 ToolkitTestApplication application;
1622 tet_infoline( "UtcDaliVisualFactoryGetPrimitiveVisual4: Request primitive visual to display a conic section" );
1624 //Set up visual properties.
1625 Property::Map propertyMap;
1626 propertyMap.Insert( Visual::Property::TYPE, Visual::PRIMITIVE );
1627 propertyMap.Insert( PrimitiveVisual::Property::SHAPE, PrimitiveVisual::Shape::CONICAL_FRUSTRUM );
1628 propertyMap.Insert( PrimitiveVisual::Property::MIX_COLOR, Vector4( 0.5, 0.5, 0.5, 1.0 ) );
1629 propertyMap.Insert( PrimitiveVisual::Property::SLICES, 10 );
1630 propertyMap.Insert( PrimitiveVisual::Property::SCALE_TOP_RADIUS, 30.0f );
1631 propertyMap.Insert( PrimitiveVisual::Property::SCALE_BOTTOM_RADIUS, 40.0f );
1632 propertyMap.Insert( PrimitiveVisual::Property::SCALE_HEIGHT, 50.0f );
1634 //Test to see if shape loads correctly.
1635 TestPrimitiveVisualWithProperties( propertyMap, application );
1640 //Test if primitive shape loads a bevelled cube correctly.
1641 int UtcDaliVisualFactoryGetPrimitiveVisual5(void)
1643 //Set up test application first, so everything else can be handled.
1644 ToolkitTestApplication application;
1646 tet_infoline( "UtcDaliVisualFactoryGetPrimitiveVisual5: Request primitive visual to display a bevelled cube" );
1648 //Set up visual properties.
1649 Property::Map propertyMap;
1650 propertyMap.Insert( Visual::Property::TYPE, Visual::PRIMITIVE );
1651 propertyMap.Insert( PrimitiveVisual::Property::SHAPE, PrimitiveVisual::Shape::BEVELLED_CUBE );
1652 propertyMap.Insert( PrimitiveVisual::Property::MIX_COLOR, Vector4( 0.5, 0.5, 0.5, 1.0 ) );
1653 propertyMap.Insert( PrimitiveVisual::Property::BEVEL_PERCENTAGE, 0.7f );
1655 //Test to see if shape loads correctly.
1656 TestPrimitiveVisualWithProperties( propertyMap, application );
1661 //Test if primitive shape loads an octahedron correctly.
1662 int UtcDaliVisualFactoryGetPrimitiveVisual6(void)
1664 //Set up test application first, so everything else can be handled.
1665 ToolkitTestApplication application;
1667 tet_infoline( "UtcDaliVisualFactoryGetPrimitiveVisual6: Request primitive visual to display an octahedron" );
1669 //Set up visual properties.
1670 Property::Map propertyMap;
1671 propertyMap.Insert( Visual::Property::TYPE, Visual::PRIMITIVE );
1672 propertyMap.Insert( PrimitiveVisual::Property::SHAPE, PrimitiveVisual::Shape::OCTAHEDRON );
1673 propertyMap.Insert( PrimitiveVisual::Property::MIX_COLOR, Vector4( 0.5, 0.5, 0.5, 1.0 ) );
1675 //Test to see if shape loads correctly.
1676 TestPrimitiveVisualWithProperties( propertyMap, application );
1681 //Test if primitive shape loads a cone correctly.
1682 int UtcDaliVisualFactoryGetPrimitiveVisual7(void)
1684 //Set up test application first, so everything else can be handled.
1685 ToolkitTestApplication application;
1687 tet_infoline( "UtcDaliVisualFactoryGetPrimitiveVisual7: Request primitive visual to display a cone" );
1689 //Set up visual properties.
1690 Property::Map propertyMap;
1691 propertyMap.Insert( Visual::Property::TYPE, Visual::PRIMITIVE );
1692 propertyMap.Insert( PrimitiveVisual::Property::SHAPE, PrimitiveVisual::Shape::CONE );
1693 propertyMap.Insert( PrimitiveVisual::Property::MIX_COLOR, Vector4( 0.5, 0.5, 0.5, 1.0 ) );
1694 propertyMap.Insert( PrimitiveVisual::Property::SLICES, 10 );
1695 propertyMap.Insert( PrimitiveVisual::Property::SCALE_TOP_RADIUS, 30.0f );
1696 propertyMap.Insert( PrimitiveVisual::Property::SCALE_HEIGHT, 50.0f );
1698 //Test to see if shape loads correctly.
1699 TestPrimitiveVisualWithProperties( propertyMap, application );
1704 //Test if primitive shape loads correctly when light position is manually set.
1705 int UtcDaliVisualFactoryGetPrimitiveVisual8(void)
1707 //Set up test application first, so everything else can be handled.
1708 ToolkitTestApplication application;
1710 tet_infoline( "UtcDaliVisualFactoryGetPrimitiveVisual8: Request primitive visual with set light position" );
1712 //Set up visual properties.
1713 Property::Map propertyMap;
1714 propertyMap.Insert( Visual::Property::TYPE, Visual::PRIMITIVE );
1715 propertyMap.Insert( PrimitiveVisual::Property::SHAPE, PrimitiveVisual::Shape::SPHERE );
1716 propertyMap.Insert( PrimitiveVisual::Property::MIX_COLOR, Vector4( 0.5, 0.5, 0.5, 1.0 ) );
1717 propertyMap.Insert( MeshVisual::Property::LIGHT_POSITION, Vector3( 0.0, 1.0, 2.0 ) );
1719 //Test to see if shape loads correctly.
1720 TestPrimitiveVisualWithProperties( propertyMap, application );
1725 //Test if primitive shape loads correctly when told to use too many slices.
1726 int UtcDaliVisualFactoryGetPrimitiveVisual9(void)
1728 //Set up test application first, so everything else can be handled.
1729 ToolkitTestApplication application;
1731 tet_infoline( "UtcDaliVisualFactoryGetPrimitiveVisual9: Request primitive visual with above-cap slices." );
1733 //Set up visual properties.
1734 Property::Map propertyMap;
1735 propertyMap.Insert( Visual::Property::TYPE, Visual::PRIMITIVE );
1736 propertyMap.Insert( PrimitiveVisual::Property::SHAPE, PrimitiveVisual::Shape::SPHERE );
1737 propertyMap.Insert( PrimitiveVisual::Property::SLICES, Property::Value( 1000000 ) );
1739 //Test to see if shape loads correctly.
1740 TestPrimitiveVisualWithProperties( propertyMap, application );
1745 //Test if primitive shape loads correctly when told to use too few slices. (2 slices or less.)
1746 int UtcDaliVisualFactoryGetPrimitiveVisual10(void)
1748 //Set up test application first, so everything else can be handled.
1749 ToolkitTestApplication application;
1751 tet_infoline( "UtcDaliVisualFactoryGetPrimitiveVisual10: Request primitive visual with too few slices." );
1753 //Set up visual properties.
1754 Property::Map propertyMap;
1755 propertyMap.Insert( Visual::Property::TYPE, Visual::PRIMITIVE );
1756 propertyMap.Insert( PrimitiveVisual::Property::SHAPE, PrimitiveVisual::Shape::SPHERE );
1757 propertyMap.Insert( PrimitiveVisual::Property::SLICES, Property::Value( 2 ) );
1759 //Test to see if shape loads correctly.
1760 TestPrimitiveVisualWithProperties( propertyMap, application );
1765 //Test if primitive shape loads correctly when told to use too many stacks.
1766 int UtcDaliVisualFactoryGetPrimitiveVisual11(void)
1768 //Set up test application first, so everything else can be handled.
1769 ToolkitTestApplication application;
1771 tet_infoline( "UtcDaliVisualFactoryGetPrimitiveVisual11: Request primitive visual with too many stacks." );
1773 //Set up visual properties.
1774 Property::Map propertyMap;
1775 propertyMap.Insert( Visual::Property::TYPE, Visual::PRIMITIVE );
1776 propertyMap.Insert( PrimitiveVisual::Property::SHAPE, PrimitiveVisual::Shape::SPHERE );
1777 propertyMap.Insert( PrimitiveVisual::Property::STACKS, Property::Value( 1000000 ) );
1779 //Test to see if shape loads correctly.
1780 TestPrimitiveVisualWithProperties( propertyMap, application );
1785 //Test if primitive shape loads correctly when told to use too few stacks. (1 stack or less.)
1786 int UtcDaliVisualFactoryGetPrimitiveVisual12(void)
1788 //Set up test application first, so everything else can be handled.
1789 ToolkitTestApplication application;
1791 tet_infoline( "UtcDaliVisualFactoryGetPrimitiveVisual12: Request primitive visual with too few stacks." );
1793 //Set up visual properties.
1794 Property::Map propertyMap;
1795 propertyMap.Insert( Visual::Property::TYPE, Visual::PRIMITIVE );
1796 propertyMap.Insert( PrimitiveVisual::Property::SHAPE, PrimitiveVisual::Shape::SPHERE );
1797 propertyMap.Insert( PrimitiveVisual::Property::STACKS, Property::Value( 1 ) );
1799 //Test to see if shape loads correctly.
1800 TestPrimitiveVisualWithProperties( propertyMap, application );
1805 //Test if primitive shape loads correctly when told to use invalid (zero or negative) dimensions.
1806 int UtcDaliVisualFactoryGetPrimitiveVisual13(void)
1808 //Set up test application first, so everything else can be handled.
1809 ToolkitTestApplication application;
1811 tet_infoline( "UtcDaliVisualFactoryGetPrimitiveVisual13: Request primitive visual with invalid scale dimensions." );
1813 //Set up visual properties.
1814 Property::Map propertyMap;
1815 propertyMap.Insert( Visual::Property::TYPE, Visual::PRIMITIVE );
1816 propertyMap.Insert( PrimitiveVisual::Property::SHAPE, PrimitiveVisual::Shape::SPHERE );
1817 propertyMap.Insert( PrimitiveVisual::Property::SCALE_DIMENSIONS, Vector3::ZERO );
1819 //Test to see if shape loads correctly.
1820 TestPrimitiveVisualWithProperties( propertyMap, application );
1825 //Test if primitive shape loads correctly when told to use too low a bevel percentage.
1826 int UtcDaliVisualFactoryGetPrimitiveVisual14(void)
1828 //Set up test application first, so everything else can be handled.
1829 ToolkitTestApplication application;
1831 tet_infoline( "UtcDaliVisualFactoryGetPrimitiveVisual14: Request primitive visual with too low a bevel percentage." );
1833 //Set up visual properties.
1834 Property::Map propertyMap;
1835 propertyMap.Insert( Visual::Property::TYPE, Visual::PRIMITIVE );
1836 propertyMap.Insert( PrimitiveVisual::Property::SHAPE, PrimitiveVisual::Shape::SPHERE );
1837 propertyMap.Insert( PrimitiveVisual::Property::BEVEL_PERCENTAGE, Property::Value( -1.0f ) );
1839 //Test to see if shape loads correctly.
1840 TestPrimitiveVisualWithProperties( propertyMap, application );
1845 //Test if primitive shape loads correctly when told to use too high a bevel percentage.
1846 int UtcDaliVisualFactoryGetPrimitiveVisual15(void)
1848 //Set up test application first, so everything else can be handled.
1849 ToolkitTestApplication application;
1851 tet_infoline( "UtcDaliVisualFactoryGetPrimitiveVisual15: Request primitive visual with too high a bevel percentage." );
1853 //Set up visual properties.
1854 Property::Map propertyMap;
1855 propertyMap.Insert( Visual::Property::TYPE, Visual::PRIMITIVE );
1856 propertyMap.Insert( PrimitiveVisual::Property::SHAPE, PrimitiveVisual::Shape::SPHERE );
1857 propertyMap.Insert( PrimitiveVisual::Property::BEVEL_PERCENTAGE, Property::Value( 2.0f ) );
1859 //Test to see if shape loads correctly.
1860 TestPrimitiveVisualWithProperties( propertyMap, application );
1865 //Test if primitive shape loads correctly when told to use too low a bevel smoothness.
1866 int UtcDaliVisualFactoryGetPrimitiveVisual16(void)
1868 //Set up test application first, so everything else can be handled.
1869 ToolkitTestApplication application;
1871 tet_infoline( "UtcDaliVisualFactoryGetPrimitiveVisual16: Request primitive visual with too low a bevel smoothness." );
1873 //Set up visual properties.
1874 Property::Map propertyMap;
1875 propertyMap.Insert( Visual::Property::TYPE, Visual::PRIMITIVE );
1876 propertyMap.Insert( PrimitiveVisual::Property::SHAPE, PrimitiveVisual::Shape::SPHERE );
1877 propertyMap.Insert( PrimitiveVisual::Property::BEVEL_SMOOTHNESS, Property::Value( -1.0f ) );
1879 //Test to see if shape loads correctly.
1880 TestPrimitiveVisualWithProperties( propertyMap, application );
1885 //Test if primitive shape loads correctly when told to use too high a bevel smoothness.
1886 int UtcDaliVisualFactoryGetPrimitiveVisual17(void)
1888 //Set up test application first, so everything else can be handled.
1889 ToolkitTestApplication application;
1891 tet_infoline( "UtcDaliVisualFactoryGetPrimitiveVisual17: Request primitive visual with too high a bevel smoothness." );
1893 //Set up visual properties.
1894 Property::Map propertyMap;
1895 propertyMap.Insert( Visual::Property::TYPE, Visual::PRIMITIVE );
1896 propertyMap.Insert( PrimitiveVisual::Property::SHAPE, PrimitiveVisual::Shape::SPHERE );
1897 propertyMap.Insert( PrimitiveVisual::Property::BEVEL_SMOOTHNESS, Property::Value( 2.0f ) );
1899 //Test to see if shape loads correctly.
1900 TestPrimitiveVisualWithProperties( propertyMap, application );
1905 //Test if primitive shape visual handles the case of not being passed a specific shape to use.
1906 int UtcDaliVisualFactoryGetPrimitiveVisualN1(void)
1908 //Set up test application first, so everything else can be handled.
1909 ToolkitTestApplication application;
1911 tet_infoline( "UtcDaliVisualFactoryGetPrimitiveVisualN1: Request primitive visual without shape" );
1913 //Set up visual properties, without supplying shape.
1914 Property::Map propertyMap;
1915 propertyMap.Insert( Visual::Property::TYPE, Visual::PRIMITIVE );
1917 //Test to see if shape loads regardless of missing input.
1918 TestPrimitiveVisualWithProperties( propertyMap, application );
1923 int UtcDaliVisualFactoryGetBatchImageVisual1(void)
1925 ToolkitTestApplication application;
1926 tet_infoline( "UtcDaliVisualFactoryGetBatchImageVisual1: Request a Batch Image visual with a Property::Map" );
1928 VisualFactory factory = VisualFactory::Get();
1929 DALI_TEST_CHECK( factory );
1931 Property::Map propertyMap;
1932 propertyMap.Insert( Visual::Property::TYPE, Visual::IMAGE );
1933 propertyMap.Insert( ImageVisual::Property::BATCHING_ENABLED, true );
1934 propertyMap.Insert( ImageVisual::Property::URL, TEST_IMAGE_FILE_NAME );
1936 Visual::Base visual = factory.CreateVisual( propertyMap );
1937 DALI_TEST_CHECK( visual );
1939 Actor actor = Actor::New();
1941 actor.SetSize( 200.0f, 200.0f );
1942 Stage::GetCurrent().Add( actor );
1943 visual.SetSize( Vector2( 200.0f, 200.0f ) );
1945 // Test SetOnStage().
1946 visual.SetOnStage( actor );
1947 DALI_TEST_CHECK( actor.GetRendererCount() == 1u );
1949 application.SendNotification();
1950 application.Render();
1952 // Test SetOffStage().
1953 visual.SetOffStage( actor );
1954 DALI_TEST_CHECK( actor.GetRendererCount() == 0u );
1959 int UtcDaliVisualFactoryGetBatchImageVisual2(void)
1961 ToolkitTestApplication application;
1962 tet_infoline( "UtcDaliVisualFactoryGetBatchImageVisual2: Request Batch Image visual from an Image Visual with batchingEnabled set" );
1964 VisualFactory factory = VisualFactory::Get();
1965 DALI_TEST_CHECK( factory );
1967 Property::Map propertyMap;
1968 // Create a normal Image Visual.
1969 propertyMap.Insert( Visual::Property::TYPE, Visual::IMAGE );
1970 // Instruct the factory to change Image Visuals to Batch-Image Visuals.
1971 propertyMap.Insert( ImageVisual::Property::BATCHING_ENABLED, true );
1973 // Properties for the Batch-Image Visual.
1974 propertyMap.Insert( ImageVisual::Property::URL, TEST_IMAGE_FILE_NAME );
1976 Visual::Base visual = factory.CreateVisual( propertyMap );
1977 DALI_TEST_CHECK( visual );
1979 // Check that a Batch-Image visual was created instead of an Image visual.
1980 Property::Map resultMap;
1981 visual.CreatePropertyMap( resultMap );
1983 Property::Value* value = resultMap.Find( Visual::Property::TYPE, Property::INTEGER );
1984 DALI_TEST_CHECK( value );
1985 DALI_TEST_EQUALS( value->Get<int>(), (int)Visual::IMAGE, TEST_LOCATION );
1987 Actor actor = Actor::New();
1989 actor.SetSize( 200.0f, 200.0f );
1990 Stage::GetCurrent().Add( actor );
1991 visual.SetSize( Vector2( 200.0f, 200.0f ) );
1993 // Test SetOnStage().
1994 visual.SetOnStage( actor );
1995 DALI_TEST_CHECK( actor.GetRendererCount() == 1u );
1997 application.SendNotification();
1998 application.Render();
2000 // Test SetOffStage().
2001 visual.SetOffStage( actor );
2002 DALI_TEST_CHECK( actor.GetRendererCount() == 0u );
2007 int UtcDaliVisualFactoryGetBatchImageVisual3(void)
2009 ToolkitTestApplication application;
2010 tet_infoline( "UtcDaliVisualFactoryGetBatchImageVisual3: Create an ImageView that uses a batched visual internally" );
2012 VisualFactory factory = VisualFactory::Get();
2013 DALI_TEST_CHECK( factory );
2015 // Create a property-map that enables batching.
2016 Property::Map propertyMap;
2017 propertyMap.Insert( Dali::Toolkit::ImageVisual::Property::URL, TEST_IMAGE_FILE_NAME );
2018 propertyMap.Insert( ImageVisual::Property::BATCHING_ENABLED, true );
2020 // Create an ImageView, passing the property-map in to instruct it to use batching.
2021 Toolkit::ImageView imageView = Toolkit::ImageView::New();
2022 imageView.SetProperty( Toolkit::ImageView::Property::IMAGE, propertyMap );
2024 imageView.SetSize( 200.0f, 200.0f );
2025 Stage::GetCurrent().Add( imageView );