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>
28 #include "dummy-control.h"
31 using namespace Dali::Toolkit;
35 typedef NinePatchImage::StretchRanges StretchRanges;
37 const char* TEST_IMAGE_FILE_NAME = "gallery_image_01.jpg";
38 const char* TEST_NPATCH_FILE_NAME = "gallery_image_01.9.png";
39 const char* TEST_SVG_FILE_NAME = TEST_RESOURCE_DIR "/svg1.svg";
40 const char* TEST_OBJ_FILE_NAME = TEST_RESOURCE_DIR "/Cube.obj";
41 const char* TEST_MTL_FILE_NAME = TEST_RESOURCE_DIR "/ToyRobot-Metal.mtl";
42 const char* TEST_SIMPLE_OBJ_FILE_NAME = TEST_RESOURCE_DIR "/Cube-Points-Only.obj";
43 const char* TEST_SIMPLE_MTL_FILE_NAME = TEST_RESOURCE_DIR "/ToyRobot-Metal-Simple.mtl";
45 // resolution: 34*34, pixel format: RGBA8888
46 static const char* gImage_34_RGBA = TEST_RESOURCE_DIR "/icon-edit.png";
47 // resolution: 600*600, pixel format: RGB888
48 static const char* gImage_600_RGB = TEST_RESOURCE_DIR "/test-image-600.jpg";
50 Integration::Bitmap* CreateBitmap( unsigned int imageWidth, unsigned int imageHeight, unsigned int initialColor, Pixel::Format pixelFormat )
52 Integration::Bitmap* bitmap = Integration::Bitmap::New( Integration::Bitmap::BITMAP_2D_PACKED_PIXELS, ResourcePolicy::OWNED_RETAIN );
53 Integration::PixelBuffer* pixbuffer = bitmap->GetPackedPixelsProfile()->ReserveBuffer( pixelFormat, imageWidth, imageHeight, imageWidth, imageHeight );
54 unsigned int bytesPerPixel = GetBytesPerPixel( pixelFormat );
56 memset( pixbuffer, initialColor, imageHeight * imageWidth * bytesPerPixel );
61 void InitialiseRegionsToZeroAlpha( Integration::Bitmap* image, unsigned int imageWidth, unsigned int imageHeight, Pixel::Format pixelFormat )
63 PixelBuffer* pixbuffer = image->GetBuffer();
64 unsigned int bytesPerPixel = GetBytesPerPixel( pixelFormat );
66 for( unsigned int row = 0; row < imageWidth; ++row )
68 unsigned int pixelOffset = row * bytesPerPixel;
69 pixbuffer[ pixelOffset + 3 ] = 0x00;
70 pixelOffset += ( imageHeight - 1 ) * imageWidth * bytesPerPixel;
71 pixbuffer[ pixelOffset + 3 ] = 0x00;
74 for ( unsigned int column = 0; column < imageHeight; ++column )
76 unsigned int pixelOffset = column * imageWidth * bytesPerPixel;
77 pixbuffer[ pixelOffset + 3 ] = 0x00;
78 pixelOffset += ( imageWidth -1 ) * bytesPerPixel;
79 pixbuffer[ pixelOffset + 3 ] = 0x00;
83 void AddStretchRegionsToImage( Integration::Bitmap* image, unsigned int imageWidth, unsigned int imageHeight, const StretchRanges& stretchRangesX, const StretchRanges& stretchRangesY, Pixel::Format pixelFormat )
85 PixelBuffer* pixbuffer = image->GetBuffer();
86 unsigned int bytesPerPixel = GetBytesPerPixel( pixelFormat );
88 for(StretchRanges::ConstIterator it = stretchRangesX.Begin(); it != stretchRangesX.End(); ++it)
90 const Uint16Pair& range = *it;
91 //since the stretch range is in the cropped image space, we need to offset by 1 to get it to the uncropped image space
92 for( unsigned int column = range.GetX() + 1u; column < range.GetY() + 1u; ++column )
94 unsigned int pixelOffset = column * bytesPerPixel;
95 pixbuffer[ pixelOffset ] = 0x00;
96 pixbuffer[ pixelOffset + 1 ] = 0x00;
97 pixbuffer[ pixelOffset + 2 ] = 0x00;
98 pixbuffer[ pixelOffset + 3 ] = 0xFF;
103 for(StretchRanges::ConstIterator it = stretchRangesY.Begin(); it != stretchRangesY.End(); ++it)
105 const Uint16Pair& range = *it;
106 //since the stretch range is in the cropped image space, we need to offset by 1 to get it to the uncropped image space
107 for( unsigned int row = range.GetX() + 1u; row < range.GetY() + 1u; ++row )
109 unsigned int pixelOffset = row * imageWidth * bytesPerPixel;
110 pixbuffer[ pixelOffset ] = 0x00;
111 pixbuffer[ pixelOffset + 1 ] = 0x00;
112 pixbuffer[ pixelOffset + 2 ] = 0x00;
113 pixbuffer[ pixelOffset + 3 ] = 0xFF;
118 void AddChildRegionsToImage( Integration::Bitmap* image, unsigned int imageWidth, unsigned int imageHeight, const Vector4& requiredChildRegion, Pixel::Format pixelFormat )
120 PixelBuffer* pixbuffer = image->GetBuffer();
121 unsigned int bytesPerPixel = GetBytesPerPixel( pixelFormat );
123 Integration::Bitmap::PackedPixelsProfile* srcProfile = image->GetPackedPixelsProfile();
124 unsigned int bufferStride = srcProfile->GetBufferStride();
126 // Add bottom child region
127 for( unsigned int column = requiredChildRegion.x; column < imageWidth - requiredChildRegion.z; ++column )
129 unsigned int pixelOffset = column * bytesPerPixel;
130 pixelOffset += ( imageHeight - 1 ) * bufferStride;
131 pixbuffer[ pixelOffset ] = 0x00;
132 pixbuffer[ pixelOffset + 1 ] = 0x00;
133 pixbuffer[ pixelOffset + 2 ] = 0x00;
134 pixbuffer[ pixelOffset + 3 ] = 0xFF;
137 // Add right child region
138 for ( unsigned int row = requiredChildRegion.y; row < imageHeight - requiredChildRegion.w; ++row )
140 unsigned int pixelOffset = row * bufferStride + ( imageWidth - 1 ) * bytesPerPixel;
141 pixbuffer[ pixelOffset ] = 0x00;
142 pixbuffer[ pixelOffset + 1 ] = 0x00;
143 pixbuffer[ pixelOffset + 2 ] = 0x00;
144 pixbuffer[ pixelOffset + 3 ] = 0xFF;
148 Integration::ResourcePointer CustomizeNinePatch( TestApplication& application,
149 unsigned int ninePatchImageWidth,
150 unsigned int ninePatchImageHeight,
151 const StretchRanges& stretchRangesX,
152 const StretchRanges& stretchRangesY,
153 bool addChildRegion = false,
154 Vector4 requiredChildRegion = Vector4::ZERO )
156 TestPlatformAbstraction& platform = application.GetPlatform();
158 Pixel::Format pixelFormat = Pixel::RGBA8888;
160 tet_infoline("Create Bitmap");
161 platform.SetClosestImageSize(Vector2( ninePatchImageWidth, ninePatchImageHeight));
162 Integration::Bitmap* bitmap = CreateBitmap( ninePatchImageWidth, ninePatchImageHeight, 0xFF, pixelFormat );
164 tet_infoline("Clear border regions");
165 InitialiseRegionsToZeroAlpha( bitmap, ninePatchImageWidth, ninePatchImageHeight, pixelFormat );
167 tet_infoline("Add Stretch regions to Bitmap");
168 AddStretchRegionsToImage( bitmap, ninePatchImageWidth, ninePatchImageHeight, stretchRangesX, stretchRangesY, pixelFormat );
172 tet_infoline("Add Child regions to Bitmap");
173 AddChildRegionsToImage( bitmap, ninePatchImageWidth, ninePatchImageHeight, requiredChildRegion, pixelFormat );
176 tet_infoline("Getting resource");
177 Integration::ResourcePointer resourcePtr(bitmap);
178 //platform.SetResourceLoaded( 0, Dali::Integration::ResourceBitmap, resourcePtr );
179 platform.SetSynchronouslyLoadedResource( resourcePtr);
184 void TestVisualRender( ToolkitTestApplication& application,
186 Visual::Base& visual,
187 std::size_t expectedSamplers = 0,
188 ImageDimensions imageDimensions = ImageDimensions(),
189 Integration::ResourcePointer resourcePtr = Integration::ResourcePointer())
191 DummyControlImpl& dummyImpl = static_cast<DummyControlImpl&>(actor.GetImplementation());
192 dummyImpl.RegisterVisual( Control::CONTROL_PROPERTY_END_INDEX + 1, visual );
196 // set the image size, for test case, this needs to be set before loading started
197 application.GetPlatform().SetClosestImageSize( Vector2(imageDimensions.GetWidth(), imageDimensions.GetHeight()) );
200 actor.SetSize( 200.f, 200.f );
201 DALI_TEST_EQUALS( actor.GetRendererCount(), 0u, TEST_LOCATION );
203 Stage::GetCurrent().Add( actor );
205 application.SendNotification();
206 application.Render();
210 Integration::ResourceRequest* request = application.GetPlatform().GetRequest();
213 application.GetPlatform().SetResourceLoaded(request->GetId(), request->GetType()->id, resourcePtr );
217 application.Render();
218 application.SendNotification();
222 DALI_TEST_EQUALS( application.GetPlatform().WasCalled(TestPlatformAbstraction::LoadResourceFunc) ||
223 application.GetPlatform().WasCalled(TestPlatformAbstraction::LoadResourceSynchronouslyFunc ), true, TEST_LOCATION);
226 DALI_TEST_EQUALS( actor.GetRendererCount(), 1u, TEST_LOCATION );
233 void dali_visual_factory_startup(void)
235 test_return_value = TET_UNDEF;
238 void dali_visual_factory_cleanup(void)
240 test_return_value = TET_PASS;
243 int UtcDaliVisualFactoryGet(void)
245 ToolkitTestApplication application;
246 tet_infoline( "UtcDaliVisualFactory" );
250 type = TypeRegistry::Get().GetTypeInfo( "VisualFactory" );
251 DALI_TEST_CHECK( type );
252 BaseHandle handle = type.CreateInstance();
253 DALI_TEST_CHECK( handle );
255 VisualFactory factory;
256 factory = VisualFactory::Get();
257 DALI_TEST_CHECK( factory );
259 VisualFactory newFactory = VisualFactory::Get();
260 DALI_TEST_CHECK( newFactory );
262 // Check that visual factory is a singleton
263 DALI_TEST_CHECK(factory == newFactory);
268 int UtcDaliVisualFactoryCopyAndAssignment(void)
270 ToolkitTestApplication application;
271 tet_infoline( "UtcDaliVisualFactoryCopyAndAssignment" );
272 VisualFactory factory = VisualFactory::Get();
274 VisualFactory factoryCopy( factory );
275 DALI_TEST_CHECK(factory == factoryCopy);
277 VisualFactory emptyFactory;
278 VisualFactory emptyFactoryCopy( emptyFactory );
279 DALI_TEST_CHECK(emptyFactory == emptyFactoryCopy);
281 VisualFactory factoryEquals;
282 factoryEquals = factory;
283 DALI_TEST_CHECK(factory == factoryEquals);
285 VisualFactory emptyFactoryEquals;
286 emptyFactoryEquals = emptyFactory;
287 DALI_TEST_CHECK( emptyFactory == emptyFactoryEquals );
291 DALI_TEST_CHECK( factory = factoryCopy );
296 int UtcDaliVisualFactoryGetColorVisual1(void)
298 ToolkitTestApplication application;
299 tet_infoline( "UtcDaliVisualFactoryGetColorVisual1: Request color visual with a Property::Map" );
301 VisualFactory factory = VisualFactory::Get();
302 DALI_TEST_CHECK( factory );
304 Property::Map propertyMap;
305 Vector4 testColor( 1.f, 0.5f, 0.3f, 0.2f );
306 propertyMap.Insert(Visual::Property::TYPE, Visual::COLOR);
307 propertyMap.Insert(ColorVisual::Property::MIX_COLOR, testColor);
309 Visual::Base visual = factory.CreateVisual(propertyMap);
310 DALI_TEST_CHECK( visual );
312 DummyControl actor = DummyControl::New();
313 TestVisualRender( application, actor, visual );
315 Vector4 actualValue(Vector4::ZERO);
316 TestGlAbstraction& gl = application.GetGlAbstraction();
317 DALI_TEST_CHECK( gl.GetUniformValue<Vector4>( "mixColor", actualValue ) );
318 DALI_TEST_EQUALS( actualValue, testColor, TEST_LOCATION );
323 int UtcDaliVisualFactoryGetColorVisual2(void)
325 ToolkitTestApplication application;
326 tet_infoline( "UtcDaliVisualFactoryGetColorVisual2: Request color visual with a Vector4" );
328 VisualFactory factory = VisualFactory::Get();
329 DALI_TEST_CHECK( factory );
331 Vector4 testColor( 1.f, 0.5f, 0.3f, 0.2f );
332 Dali::Property::Map map;
333 map[ Visual::Property::TYPE ] = Visual::COLOR;
334 map[ ColorVisual::Property::MIX_COLOR ] = testColor;
335 Visual::Base visual = factory.CreateVisual( map );
336 DALI_TEST_CHECK( visual );
338 DummyControl actor = DummyControl::New();
339 TestVisualRender( application, actor, visual );
341 Vector4 actualValue(Vector4::ZERO);
342 TestGlAbstraction& gl = application.GetGlAbstraction();
343 DALI_TEST_CHECK( gl.GetUniformValue<Vector4>( "mixColor", actualValue ) );
344 DALI_TEST_EQUALS( actualValue, testColor, TEST_LOCATION );
346 Stage::GetCurrent().Remove(actor);
347 DALI_TEST_CHECK( actor.GetRendererCount() == 0u );
352 int UtcDaliVisualFactoryGetBorderVisual1(void)
354 ToolkitTestApplication application;
355 tet_infoline( "UtcDaliVisualFactoryGetBorderVisual1: Request border visual with a Property::Map" );
357 VisualFactory factory = VisualFactory::Get();
358 DALI_TEST_CHECK( factory );
360 Property::Map propertyMap;
361 Vector4 testColor( 1.f, 0.5f, 0.3f, 0.2f );
362 float testSize = 5.f;
363 propertyMap.Insert(Visual::Property::TYPE, Visual::BORDER);
364 propertyMap.Insert(BorderVisual::Property::COLOR, testColor);
365 propertyMap.Insert(BorderVisual::Property::SIZE, testSize);
367 Visual::Base visual = factory.CreateVisual(propertyMap);
368 DALI_TEST_CHECK( visual );
370 DummyControl actor = DummyControl::New();
371 DummyControlImpl& dummyImpl = static_cast<DummyControlImpl&>(actor.GetImplementation());
372 dummyImpl.RegisterVisual( Control::CONTROL_PROPERTY_END_INDEX + 1, visual );
373 actor.SetSize(200.f, 200.f);
374 Stage::GetCurrent().Add( actor );
375 visual.SetSize(Vector2(200.f, 200.f));
377 DALI_TEST_CHECK( actor.GetRendererCount() == 1u );
378 int blendMode = actor.GetRendererAt(0u).GetProperty<int>( Renderer::Property::BLEND_MODE );
379 DALI_TEST_EQUALS( static_cast<BlendMode::Type>(blendMode), BlendMode::ON, TEST_LOCATION );
381 TestGlAbstraction& gl = application.GetGlAbstraction();
383 application.SendNotification();
384 application.Render(0);
386 Vector4 actualColor(Vector4::ZERO);
387 DALI_TEST_CHECK( gl.GetUniformValue<Vector4>( "borderColor", actualColor ) );
388 DALI_TEST_EQUALS( actualColor, testColor, TEST_LOCATION );
390 float actualSize = 0.f;
391 DALI_TEST_CHECK( gl.GetUniformValue<float>( "borderSize", actualSize ) );
392 DALI_TEST_EQUALS( actualSize, testSize, TEST_LOCATION );
395 DALI_TEST_CHECK( actor.GetRendererCount() == 0u );
400 int UtcDaliVisualFactoryGetBorderVisual2(void)
402 ToolkitTestApplication application;
403 tet_infoline( "UtcDaliVisualFactoryGetBorderVisual2: Request border visual with a borderSize and a borderColor" );
405 VisualFactory factory = VisualFactory::Get();
406 DALI_TEST_CHECK( factory );
408 Vector4 testColor( 1.f, 0.5f, 0.3f, 1.f );
409 float testSize = 5.f;
411 Dali::Property::Map propertyMap;
412 propertyMap[ Visual::Property::TYPE ] = Visual::BORDER;
413 propertyMap[ BorderVisual::Property::COLOR ] = testColor;
414 propertyMap[ BorderVisual::Property::SIZE ] = testSize;
415 Visual::Base visual = factory.CreateVisual( propertyMap );
416 DALI_TEST_CHECK( visual );
418 DummyControl actor = DummyControl::New();
419 DummyControlImpl& dummyImpl = static_cast<DummyControlImpl&>(actor.GetImplementation());
420 dummyImpl.RegisterVisual( Control::CONTROL_PROPERTY_END_INDEX + 1, visual );
421 actor.SetSize(200.f, 200.f);
422 Stage::GetCurrent().Add( actor );
423 visual.SetSize(Vector2(200.f, 200.f));
425 DALI_TEST_CHECK( actor.GetRendererCount() == 1u );
427 TestGlAbstraction& gl = application.GetGlAbstraction();
429 application.SendNotification();
430 application.Render(0);
432 int blendMode = actor.GetRendererAt(0u).GetProperty<int>( Renderer::Property::BLEND_MODE );
433 DALI_TEST_EQUALS( static_cast<BlendMode::Type>(blendMode), BlendMode::AUTO, TEST_LOCATION );
435 Vector4 actualColor(Vector4::ZERO);
436 DALI_TEST_CHECK( gl.GetUniformValue<Vector4>( "borderColor", actualColor ) );
437 DALI_TEST_EQUALS( actualColor, testColor, TEST_LOCATION );
439 float actualSize = 0.f;
440 DALI_TEST_CHECK( gl.GetUniformValue<float>( "borderSize", actualSize ) );
441 DALI_TEST_EQUALS( actualSize, testSize, TEST_LOCATION );
445 // enable the anti-aliasing
446 Dali::Property::Map map;
447 map[ Visual::Property::TYPE ] = Visual::BORDER;
448 map[ BorderVisual::Property::COLOR ] = testColor;
449 map[ BorderVisual::Property::SIZE ] = testSize;
450 map[ BorderVisual::Property::ANTI_ALIASING ] = true;
451 visual = factory.CreateVisual( map );
453 dummyImpl.RegisterVisual( Control::CONTROL_PROPERTY_END_INDEX + 1, visual );
454 Stage::GetCurrent().Add( actor );
456 blendMode = actor.GetRendererAt(0u).GetProperty<int>( Renderer::Property::BLEND_MODE );
457 DALI_TEST_EQUALS( static_cast<BlendMode::Type>(blendMode), BlendMode::ON, TEST_LOCATION );
462 int UtcDaliVisualFactoryGetLinearGradientVisual(void)
464 ToolkitTestApplication application;
465 tet_infoline("UtcDaliVisualFactoryGetRadialGradientVisual");
467 VisualFactory factory = VisualFactory::Get();
468 DALI_TEST_CHECK( factory );
470 Property::Map propertyMap;
471 propertyMap.Insert(Visual::Property::TYPE, Visual::GRADIENT);
473 Vector2 start(-1.f, -1.f);
474 Vector2 end(1.f, 1.f);
475 propertyMap.Insert(GradientVisual::Property::START_POSITION, start);
476 propertyMap.Insert(GradientVisual::Property::END_POSITION, end);
477 propertyMap.Insert(GradientVisual::Property::SPREAD_METHOD, GradientVisual::SpreadMethod::REPEAT);
479 Property::Array stopOffsets;
480 stopOffsets.PushBack( 0.2f );
481 stopOffsets.PushBack( 0.8f );
482 propertyMap.Insert(GradientVisual::Property::STOP_OFFSET, stopOffsets);
484 Property::Array stopColors;
485 stopColors.PushBack( Color::RED );
486 stopColors.PushBack( Color::GREEN );
487 propertyMap.Insert(GradientVisual::Property::STOP_COLOR, stopColors);
489 Visual::Base visual = factory.CreateVisual(propertyMap);
490 DALI_TEST_CHECK( visual );
492 // A lookup texture is generated and pass to shader as sampler
493 DummyControl actor = DummyControl::New();
494 TestVisualRender( application, actor, visual, 1u);
499 int UtcDaliVisualFactoryGetRadialGradientVisual(void)
501 ToolkitTestApplication application;
502 tet_infoline("UtcDaliVisualFactoryGetRadialGradientVisual");
504 VisualFactory factory = VisualFactory::Get();
505 DALI_TEST_CHECK( factory );
507 Property::Map propertyMap;
508 propertyMap.Insert(Visual::Property::TYPE, Visual::GRADIENT);
510 Vector2 center(100.f, 100.f);
511 float radius = 100.f;
512 propertyMap.Insert(GradientVisual::Property::UNITS, GradientVisual::Units::USER_SPACE);
513 propertyMap.Insert(GradientVisual::Property::CENTER, center);
514 propertyMap.Insert(GradientVisual::Property::RADIUS, radius);
516 Property::Array stopOffsets;
517 stopOffsets.PushBack( 0.0f );
518 stopOffsets.PushBack( 1.f );
519 propertyMap.Insert(GradientVisual::Property::STOP_OFFSET, stopOffsets);
521 Property::Array stopColors;
522 stopColors.PushBack( Color::RED );
523 stopColors.PushBack( Color::GREEN );
524 propertyMap.Insert(GradientVisual::Property::STOP_COLOR, stopColors);
526 Visual::Base visual = factory.CreateVisual(propertyMap);
527 DALI_TEST_CHECK( visual );
529 // A lookup texture is generated and pass to shader as sampler
530 DummyControl actor = DummyControl::New();
531 TestVisualRender( application, actor, visual, 1u );
533 Matrix3 alignMatrix( radius, 0.f, 0.f, 0.f, radius, 0.f, center.x, center.y, 1.f );
534 alignMatrix.Invert();
536 Matrix3 actualValue( Matrix3::IDENTITY );
537 TestGlAbstraction& gl = application.GetGlAbstraction();
538 DALI_TEST_CHECK( gl.GetUniformValue<Matrix3>( "uAlignmentMatrix", actualValue ) );
539 DALI_TEST_EQUALS( actualValue, alignMatrix, Math::MACHINE_EPSILON_100, TEST_LOCATION );
544 int UtcDaliVisualFactoryDefaultOffsetsGradientVisual(void)
546 ToolkitTestApplication application;
547 tet_infoline("UtcDaliVisualFactoryGetRadialGradientVisual");
549 VisualFactory factory = VisualFactory::Get();
550 DALI_TEST_CHECK( factory );
552 Property::Map propertyMap;
553 propertyMap.Insert(Visual::Property::TYPE, Visual::GRADIENT);
555 Vector2 start(-1.f, -1.f);
556 Vector2 end(1.f, 1.f);
557 propertyMap.Insert(GradientVisual::Property::START_POSITION, start);
558 propertyMap.Insert(GradientVisual::Property::END_POSITION, end);
559 propertyMap.Insert(GradientVisual::Property::SPREAD_METHOD, GradientVisual::SpreadMethod::REPEAT);
561 Property::Array stopColors;
562 stopColors.PushBack( Color::RED );
563 stopColors.PushBack( Color::GREEN );
564 propertyMap.Insert(GradientVisual::Property::STOP_COLOR, stopColors);
566 Visual::Base visual = factory.CreateVisual(propertyMap);
567 DALI_TEST_CHECK( visual );
569 // A lookup texture is generated and pass to shader as sampler
570 DummyControl actor = DummyControl::New();
571 TestVisualRender( application, actor, visual, 1u );
573 Stage::GetCurrent().Remove( actor );
574 DALI_TEST_CHECK( actor.GetRendererCount() == 0u );
579 int UtcDaliVisualFactoryGetImageVisual1(void)
581 ToolkitTestApplication application;
582 tet_infoline( "UtcDaliVisualFactoryGetImageVisual1: Request image visual with a Property::Map" );
584 VisualFactory factory = VisualFactory::Get();
585 DALI_TEST_CHECK( factory );
587 Property::Map propertyMap;
588 propertyMap.Insert( Visual::Property::TYPE, Visual::IMAGE );
589 propertyMap.Insert( ImageVisual::Property::URL, TEST_IMAGE_FILE_NAME );
591 Visual::Base visual = factory.CreateVisual( propertyMap );
592 DALI_TEST_CHECK( visual );
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 DummyControl actor = DummyControl::New();
607 TestVisualRender( application, actor, visual, 1u,
608 ImageDimensions(width, height),
609 Integration::ResourcePointer( bitmap ) );
611 DALI_TEST_EQUALS( textureTrace.FindMethod("BindTexture"), true, TEST_LOCATION );
613 Stage::GetCurrent().Remove( actor );
614 DALI_TEST_CHECK( actor.GetRendererCount() == 0u );
619 int UtcDaliVisualFactoryGetImageVisual2(void)
621 ToolkitTestApplication application;
622 tet_infoline( "UtcDaliVisualFactoryGetImageVisual2: Request image visual with an image handle" );
624 VisualFactory factory = VisualFactory::Get();
625 DALI_TEST_CHECK( factory );
627 Image image = ResourceImage::New(TEST_IMAGE_FILE_NAME);
628 Visual::Base visual = factory.CreateVisual( image );
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 DummyControl actor = DummyControl::New();
644 TestVisualRender( application, actor, visual, 1u,
645 ImageDimensions(width, height),
646 Integration::ResourcePointer(bitmap) );
648 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 TestGlAbstraction& gl = application.GetGlAbstraction();
679 TraceCallStack& textureTrace = gl.GetTextureTrace();
680 textureTrace.Enable(true);
681 TraceCallStack& texParameterTrace = gl.GetTexParameterTrace();
682 texParameterTrace.Enable( true );
684 DummyControl actor = DummyControl::New();
685 DummyControlImpl& dummyImpl = static_cast<DummyControlImpl&>(actor.GetImplementation());
686 dummyImpl.RegisterVisual( Control::CONTROL_PROPERTY_END_INDEX + 1, visual );
687 actor.SetSize(2000, 2000);
688 actor.SetParentOrigin(ParentOrigin::CENTER);
689 Stage::GetCurrent().Add( actor );
692 application.SendNotification();
693 application.Render();
694 application.Render();
695 application.SendNotification();
696 BitmapLoader loader = BitmapLoader::GetLatestCreated();
697 DALI_TEST_CHECK( loader );
698 loader.WaitForLoading();// waiting until the image to be loaded
699 DALI_TEST_CHECK( loader.IsLoaded() );
701 DALI_TEST_CHECK( actor.GetRendererCount() == 1u );
703 DALI_TEST_EQUALS( textureTrace.FindMethod("BindTexture"), true, TEST_LOCATION );
705 // WITH atlasing, the wrapping is handled manually in shader, so the following gl function should not be called
706 std::stringstream out;
707 out << GL_TEXTURE_2D << ", " << GL_TEXTURE_WRAP_S << ", " << GL_MIRRORED_REPEAT;
708 DALI_TEST_CHECK( !texParameterTrace.FindMethodAndParams("TexParameteri", out.str()) );
710 out << GL_TEXTURE_2D << ", " << GL_TEXTURE_WRAP_T << ", " << GL_REPEAT;
711 DALI_TEST_CHECK( !texParameterTrace.FindMethodAndParams("TexParameteri", out.str()) );
713 // test the uniforms which used to handle the wrap mode
714 Renderer renderer = actor.GetRendererAt( 0u );
715 DALI_TEST_CHECK( renderer );
717 Property::Value pixelAreaValue = renderer.GetProperty( renderer.GetPropertyIndex( "pixelArea" ) );
718 DALI_TEST_EQUALS( pixelAreaValue.Get<Vector4>(), pixelArea, TEST_LOCATION );
719 Vector4 pixelAreaUniform;
720 DALI_TEST_CHECK( gl.GetUniformValue<Vector4>( "pixelArea", pixelAreaUniform ) );
721 DALI_TEST_EQUALS( pixelArea, pixelAreaUniform, Math::MACHINE_EPSILON_100, TEST_LOCATION );
723 Property::Value wrapModeValue = renderer.GetProperty( renderer.GetPropertyIndex( "wrapMode" ) );
724 Vector2 wrapMode( WrapMode::MIRRORED_REPEAT-1, WrapMode::REPEAT-1 );
725 DALI_TEST_EQUALS( wrapModeValue.Get<Vector2>(), wrapMode, TEST_LOCATION );
726 Vector2 wrapModeUniform;
727 DALI_TEST_CHECK( gl.GetUniformValue<Vector2>( "wrapMode", wrapModeUniform ) );
728 DALI_TEST_EQUALS( wrapMode, wrapModeUniform, Math::MACHINE_EPSILON_100, TEST_LOCATION );
731 DALI_TEST_CHECK( actor.GetRendererCount() == 0u );
736 int UtcDaliVisualFactoryGetImageVisual4(void)
738 ToolkitTestApplication application;
739 tet_infoline( "UtcDaliVisualFactoryGetImageVisual4: Request image visual with a Property::Map, test custom wrap mode and pixel area without atlasing" );
741 VisualFactory factory = VisualFactory::Get();
742 DALI_TEST_CHECK( factory );
744 // Test wrap mode without atlasing. Image with a size bigger than 512*512 will NOT be uploaded as a part of the atlas.
746 const int height=600;
747 const Vector4 pixelArea(-0.5f, -0.5f, 2.f, 2.f);
749 Property::Map propertyMap;
750 propertyMap.Insert( Visual::Property::TYPE, Visual::IMAGE );
751 propertyMap.Insert( ImageVisual::Property::URL, gImage_600_RGB );
752 propertyMap.Insert( ImageVisual::Property::DESIRED_WIDTH, width );
753 propertyMap.Insert( ImageVisual::Property::DESIRED_HEIGHT, height );
754 propertyMap.Insert( ImageVisual::Property::SYNCHRONOUS_LOADING, true );
755 propertyMap.Insert( ImageVisual::Property::PIXEL_AREA, pixelArea );
756 propertyMap.Insert( ImageVisual::Property::WRAP_MODE_U, WrapMode::MIRRORED_REPEAT );
757 propertyMap.Insert( ImageVisual::Property::WRAP_MODE_V, WrapMode::REPEAT );
759 Visual::Base visual = factory.CreateVisual( propertyMap );
760 DALI_TEST_CHECK( visual );
762 TestGlAbstraction& gl = application.GetGlAbstraction();
763 TraceCallStack& textureTrace = gl.GetTextureTrace();
764 textureTrace.Enable(true);
765 TraceCallStack& texParameterTrace = gl.GetTexParameterTrace();
766 texParameterTrace.Enable( true );
768 DummyControl actor = DummyControl::New();
769 DummyControlImpl& dummyImpl = static_cast<DummyControlImpl&>(actor.GetImplementation());
770 dummyImpl.RegisterVisual( Control::CONTROL_PROPERTY_END_INDEX + 1, visual );
771 actor.SetSize(2000, 2000);
772 actor.SetParentOrigin(ParentOrigin::CENTER);
773 Stage::GetCurrent().Add( actor );
776 application.SendNotification();
777 application.Render();
778 application.Render();
779 application.SendNotification();
780 BitmapLoader loader = BitmapLoader::GetLatestCreated();
781 DALI_TEST_CHECK( loader );
782 loader.WaitForLoading();// waiting until the image to be loaded
783 DALI_TEST_CHECK( loader.IsLoaded() );
785 DALI_TEST_CHECK( actor.GetRendererCount() == 1u );
787 DALI_TEST_EQUALS( textureTrace.FindMethod("BindTexture"), true, TEST_LOCATION );
789 // WITHOUT atlasing, the wrapping is handled by setting gl texture parameters
790 std::stringstream out;
791 out << GL_TEXTURE_2D << ", " << GL_TEXTURE_WRAP_S << ", " << GL_MIRRORED_REPEAT;
792 DALI_TEST_CHECK( texParameterTrace.FindMethodAndParams("TexParameteri", out.str()) );
794 out << GL_TEXTURE_2D << ", " << GL_TEXTURE_WRAP_T << ", " << GL_REPEAT;
795 DALI_TEST_CHECK( texParameterTrace.FindMethodAndParams("TexParameteri", out.str()) );
797 // test the uniforms which used to handle the wrap mode
798 Renderer renderer = actor.GetRendererAt( 0u );
799 DALI_TEST_CHECK( renderer );
801 Property::Value pixelAreaValue = renderer.GetProperty( renderer.GetPropertyIndex( "pixelArea" ) );
802 DALI_TEST_EQUALS( pixelAreaValue.Get<Vector4>(), pixelArea, TEST_LOCATION );
803 Vector4 pixelAreaUniform;
804 DALI_TEST_CHECK( gl.GetUniformValue<Vector4>( "pixelArea", pixelAreaUniform ) );
805 DALI_TEST_EQUALS( pixelArea, pixelAreaUniform, Math::MACHINE_EPSILON_100, TEST_LOCATION );
807 Property::Index wrapModeIndex = renderer.GetPropertyIndex( "wrapMode" );
808 DALI_TEST_CHECK(wrapModeIndex == Property::INVALID_INDEX);
811 DALI_TEST_CHECK( actor.GetRendererCount() == 0u );
816 int UtcDaliVisualFactoryGetNPatchVisual1(void)
818 ToolkitTestApplication application;
819 tet_infoline( "UtcDaliVisualFactoryGetNPatchVisual1: Request 9-patch visual with a Property::Map" );
821 VisualFactory factory = VisualFactory::Get();
822 DALI_TEST_CHECK( factory );
824 const unsigned int ninePatchImageHeight = 18;
825 const unsigned int ninePatchImageWidth = 28;
826 StretchRanges stretchRangesX;
827 stretchRangesX.PushBack( Uint16Pair( 2, 3 ) );
828 StretchRanges stretchRangesY;
829 stretchRangesY.PushBack( Uint16Pair( 4, 5 ) );
830 Integration::ResourcePointer ninePatchResource = CustomizeNinePatch( application, ninePatchImageWidth, ninePatchImageHeight, stretchRangesX, stretchRangesY );
832 Property::Map propertyMap;
833 propertyMap.Insert( Visual::Property::TYPE, Visual::IMAGE );
834 propertyMap.Insert( ImageVisual::Property::URL, TEST_NPATCH_FILE_NAME );
836 tet_infoline( "whole grid" );
837 Visual::Base visual = factory.CreateVisual( propertyMap );
838 DALI_TEST_CHECK( visual );
841 TestGlAbstraction& gl = application.GetGlAbstraction();
842 TraceCallStack& textureTrace = gl.GetTextureTrace();
843 textureTrace.Enable(true);
845 DummyControl actor = DummyControl::New();
846 TestVisualRender( application, actor, visual, 1u,
847 ImageDimensions(ninePatchImageWidth, ninePatchImageHeight),
850 DALI_TEST_EQUALS( textureTrace.FindMethod("BindTexture"), true, TEST_LOCATION );
853 propertyMap.Insert( ImageVisual::Property::BORDER_ONLY, true );
855 tet_infoline( "border only" );
856 Visual::Base visual = factory.CreateVisual( propertyMap );
857 DALI_TEST_CHECK( visual );
859 TestGlAbstraction& gl = application.GetGlAbstraction();
860 TraceCallStack& textureTrace = gl.GetTextureTrace();
861 textureTrace.Enable(true);
863 DummyControl actor = DummyControl::New();
864 TestVisualRender( application, actor, visual, 1u,
865 ImageDimensions(ninePatchImageWidth, ninePatchImageHeight),
868 DALI_TEST_EQUALS( textureTrace.FindMethod("BindTexture"), true, TEST_LOCATION );
874 int UtcDaliVisualFactoryGetNPatchVisual2(void)
876 ToolkitTestApplication application;
877 tet_infoline( "UtcDaliVisualFactoryGetNPatchVisual2: Request n-patch visual with a Property::Map" );
879 VisualFactory factory = VisualFactory::Get();
880 DALI_TEST_CHECK( factory );
882 const unsigned int ninePatchImageWidth = 18;
883 const unsigned int ninePatchImageHeight = 28;
884 StretchRanges stretchRangesX;
885 stretchRangesX.PushBack( Uint16Pair( 2, 3 ) );
886 stretchRangesX.PushBack( Uint16Pair( 5, 7 ) );
887 stretchRangesX.PushBack( Uint16Pair( 12, 15 ) );
888 StretchRanges stretchRangesY;
889 stretchRangesY.PushBack( Uint16Pair( 4, 5 ) );
890 stretchRangesY.PushBack( Uint16Pair( 8, 12 ) );
891 stretchRangesY.PushBack( Uint16Pair( 15, 16 ) );
892 stretchRangesY.PushBack( Uint16Pair( 25, 27 ) );
893 Integration::ResourcePointer ninePatchResource = CustomizeNinePatch( application, ninePatchImageWidth, ninePatchImageHeight, stretchRangesX, stretchRangesY );
895 Property::Map propertyMap;
896 propertyMap.Insert( Visual::Property::TYPE, Visual::IMAGE );
897 propertyMap.Insert( ImageVisual::Property::URL, TEST_NPATCH_FILE_NAME );
899 Visual::Base visual = factory.CreateVisual( propertyMap );
900 DALI_TEST_CHECK( visual );
902 TestGlAbstraction& gl = application.GetGlAbstraction();
903 TraceCallStack& textureTrace = gl.GetTextureTrace();
904 textureTrace.Enable(true);
906 DummyControl actor = DummyControl::New();
907 TestVisualRender( application, actor, visual, 1u,
908 ImageDimensions(ninePatchImageWidth, ninePatchImageHeight),
911 DALI_TEST_EQUALS( textureTrace.FindMethod("BindTexture"), true, TEST_LOCATION );
913 Stage::GetCurrent().Remove( actor );
914 DALI_TEST_CHECK( actor.GetRendererCount() == 0u );
917 propertyMap.Insert( ImageVisual::Property::BORDER_ONLY, true );
919 tet_infoline( "border only" );
920 Visual::Base visual = factory.CreateVisual( propertyMap );
921 DALI_TEST_CHECK( visual );
923 TestGlAbstraction& gl = application.GetGlAbstraction();
924 TraceCallStack& textureTrace = gl.GetTextureTrace();
925 textureTrace.Enable(true);
926 DummyControl actor = DummyControl::New();
927 TestVisualRender( application, actor, visual, 1u,
928 ImageDimensions(ninePatchImageWidth, ninePatchImageHeight),
932 DALI_TEST_EQUALS( textureTrace.FindMethod("BindTexture"), true, TEST_LOCATION );
934 Stage::GetCurrent().Remove( actor );
935 DALI_TEST_CHECK( actor.GetRendererCount() == 0u );
941 int UtcDaliVisualFactoryGetNPatchVisual3(void)
943 ToolkitTestApplication application;
944 tet_infoline( "UtcDaliVisualFactoryGetNPatchVisual3: Request 9-patch visual with an image url" );
946 VisualFactory factory = VisualFactory::Get();
947 DALI_TEST_CHECK( factory );
949 const unsigned int ninePatchImageHeight = 18;
950 const unsigned int ninePatchImageWidth = 28;
951 StretchRanges stretchRangesX;
952 stretchRangesX.PushBack( Uint16Pair( 2, 3 ) );
953 StretchRanges stretchRangesY;
954 stretchRangesY.PushBack( Uint16Pair( 4, 5 ) );
955 Integration::ResourcePointer ninePatchResource = CustomizeNinePatch( application, ninePatchImageWidth, ninePatchImageHeight, stretchRangesX, stretchRangesY );
957 Visual::Base visual = factory.CreateVisual( TEST_NPATCH_FILE_NAME, ImageDimensions() );
958 DALI_TEST_CHECK( visual );
960 TestGlAbstraction& gl = application.GetGlAbstraction();
961 TraceCallStack& textureTrace = gl.GetTextureTrace();
962 textureTrace.Enable(true);
964 DummyControl actor = DummyControl::New();
965 TestVisualRender( application, actor, visual, 1u,
966 ImageDimensions(ninePatchImageWidth, ninePatchImageHeight),
969 DALI_TEST_EQUALS( textureTrace.FindMethod("BindTexture"), true, TEST_LOCATION );
972 ResourceImage image = ResourceImage::New(TEST_NPATCH_FILE_NAME);
973 Visual::Base nPatchVisual = factory.CreateVisual( image );
974 Vector2 visualSize( 20.f, 30.f ), naturalSize(0,0);
975 nPatchVisual.SetSize( visualSize );
976 DALI_TEST_EQUALS( nPatchVisual.GetSize(), visualSize, TEST_LOCATION );
977 nPatchVisual.GetNaturalSize( naturalSize );
978 DALI_TEST_EQUALS( naturalSize, Vector2( ninePatchImageWidth-2, ninePatchImageHeight-2 ), TEST_LOCATION );
983 int UtcDaliVisualFactoryGetNPatchVisual4(void)
985 ToolkitTestApplication application;
986 tet_infoline( "UtcDaliVisualFactoryGetNPatchVisual4: Request n-patch visual with an image url" );
988 VisualFactory factory = VisualFactory::Get();
989 DALI_TEST_CHECK( factory );
991 const unsigned int ninePatchImageHeight = 18;
992 const unsigned int ninePatchImageWidth = 28;
993 StretchRanges stretchRangesX;
994 stretchRangesX.PushBack( Uint16Pair( 2, 3 ) );
995 stretchRangesX.PushBack( Uint16Pair( 5, 7 ) );
996 stretchRangesX.PushBack( Uint16Pair( 12, 15 ) );
997 StretchRanges stretchRangesY;
998 stretchRangesY.PushBack( Uint16Pair( 4, 5 ) );
999 stretchRangesY.PushBack( Uint16Pair( 8, 12 ) );
1000 stretchRangesY.PushBack( Uint16Pair( 15, 16 ) );
1001 stretchRangesY.PushBack( Uint16Pair( 25, 27 ) );
1002 Integration::ResourcePointer ninePatchResource = CustomizeNinePatch( application, ninePatchImageWidth, ninePatchImageHeight, stretchRangesX, stretchRangesY );
1004 Visual::Base visual = factory.CreateVisual( TEST_NPATCH_FILE_NAME, ImageDimensions() );
1005 DALI_TEST_CHECK( visual );
1007 TestGlAbstraction& gl = application.GetGlAbstraction();
1008 TraceCallStack& textureTrace = gl.GetTextureTrace();
1009 textureTrace.Enable(true);
1011 DummyControl actor = DummyControl::New();
1012 TestVisualRender( application, actor, visual, 1u,
1013 ImageDimensions(ninePatchImageWidth, ninePatchImageHeight),
1014 ninePatchResource );
1016 DALI_TEST_EQUALS( textureTrace.FindMethod("BindTexture"), true, TEST_LOCATION );
1021 int UtcDaliVisualFactoryGetNPatchVisualN1(void)
1023 //This should still load but display an error image
1025 ToolkitTestApplication application;
1026 tet_infoline( "UtcDaliVisualFactoryGetNPatchVisualN: Request n-patch visual with an invalid image url" );
1028 VisualFactory factory = VisualFactory::Get();
1029 DALI_TEST_CHECK( factory );
1031 Visual::Base visual = factory.CreateVisual( "ERROR.9.jpg", ImageDimensions() );
1032 DALI_TEST_CHECK( visual );
1034 //The testkit still has to load a bitmap for the broken renderer image
1035 Integration::Bitmap* bitmap = Integration::Bitmap::New(Integration::Bitmap::BITMAP_2D_PACKED_PIXELS, ResourcePolicy::OWNED_DISCARD);
1036 bitmap->GetPackedPixelsProfile()->ReserveBuffer( Pixel::RGBA8888, 100, 100, 100, 100 );
1038 TestGlAbstraction& gl = application.GetGlAbstraction();
1039 TraceCallStack& textureTrace = gl.GetTextureTrace();
1040 textureTrace.Enable(true);
1042 DummyControl actor = DummyControl::New();
1043 TestVisualRender( application, actor, visual, 1u,
1045 Integration::ResourcePointer(bitmap) );
1047 DALI_TEST_EQUALS( textureTrace.FindMethod("BindTexture"), true, TEST_LOCATION );
1052 int UtcDaliVisualFactoryGetNPatchVisualN2(void)
1054 //This should still load but display an error image
1056 ToolkitTestApplication application;
1057 tet_infoline( "UtcDaliVisualFactoryGetNPatchVisualN: Request n-patch visual with an invalid URL" );
1059 VisualFactory factory = VisualFactory::Get();
1060 DALI_TEST_CHECK( factory );
1062 Property::Map propertyMap;
1063 propertyMap.Insert( Visual::Property::TYPE, Visual::IMAGE );
1064 propertyMap.Insert( ImageVisual::Property::URL, "ERROR.9.jpg" );
1066 Visual::Base visual = factory.CreateVisual( propertyMap );
1067 DALI_TEST_CHECK( visual );
1069 //The testkit still has to load a bitmap for the broken renderer image
1070 Integration::Bitmap* bitmap = Integration::Bitmap::New(Integration::Bitmap::BITMAP_2D_PACKED_PIXELS, ResourcePolicy::OWNED_DISCARD);
1071 bitmap->GetPackedPixelsProfile()->ReserveBuffer( Pixel::RGBA8888, 100, 100, 100, 100 );
1073 TestGlAbstraction& gl = application.GetGlAbstraction();
1074 TraceCallStack& textureTrace = gl.GetTextureTrace();
1075 textureTrace.Enable(true);
1076 TraceCallStack& drawTrace = gl.GetDrawTrace();
1077 drawTrace.Enable(true);
1079 DummyControl actor = DummyControl::New();
1080 TestVisualRender( application, actor, visual, 1u,
1082 Integration::ResourcePointer(bitmap) );
1084 DALI_TEST_EQUALS( textureTrace.FindMethod("BindTexture"), true, TEST_LOCATION );
1089 int UtcDaliVisualFactoryGetNPatchVisualN3(void)
1091 // Passing in an invalid visual type so we should not get a visual
1093 ToolkitTestApplication application;
1094 tet_infoline( "UtcDaliVisualFactoryGetNPatchVisualN: Request n-patch visual with an invalid visual type" );
1096 VisualFactory factory = VisualFactory::Get();
1097 DALI_TEST_CHECK( factory );
1099 Property::Map propertyMap;
1100 propertyMap.Insert( Visual::Property::TYPE, 111 );
1101 propertyMap.Insert( ImageVisual::Property::URL, "ERROR.9.jpg" );
1103 Visual::Base visual = factory.CreateVisual( propertyMap );
1104 DALI_TEST_CHECK( !visual );
1109 int UtcDaliVisualFactoryGetSvgVisual(void)
1111 ToolkitTestApplication application;
1112 tet_infoline( "UtcDaliVisualFactoryGetSvgVisual: Request svg visual with a svg url" );
1114 VisualFactory factory = VisualFactory::Get();
1115 Visual::Base visual = factory.CreateVisual( TEST_SVG_FILE_NAME, ImageDimensions() );
1116 DALI_TEST_CHECK( visual );
1118 TestGlAbstraction& gl = application.GetGlAbstraction();
1119 TraceCallStack& textureTrace = gl.GetTextureTrace();
1120 textureTrace.Enable(true);
1122 DummyControl actor = DummyControl::New();
1123 DummyControlImpl& dummyImpl = static_cast<DummyControlImpl&>(actor.GetImplementation());
1124 dummyImpl.RegisterVisual( Control::CONTROL_PROPERTY_END_INDEX + 1, visual );
1125 actor.SetSize( 200.f, 200.f );
1126 Stage::GetCurrent().Add( actor );
1127 visual.SetSize( Vector2(200.f, 200.f) );
1129 application.SendNotification();
1130 application.Render();
1132 // renderer is not added to actor until the rasterization is completed.
1133 DALI_TEST_CHECK( actor.GetRendererCount() == 0u );
1135 EventThreadCallback* eventTrigger = EventThreadCallback::Get();
1136 CallbackBase* callback = eventTrigger->GetCallback();
1138 eventTrigger->WaitingForTrigger( 1 );// waiting until the svg image is rasterized.
1139 CallbackBase::Execute( *callback );
1141 // renderer is added to actor
1142 DALI_TEST_CHECK( actor.GetRendererCount() == 1u );
1144 // waiting for the resource uploading
1145 application.SendNotification();
1146 application.Render();
1148 DALI_TEST_EQUALS( textureTrace.FindMethod("BindTexture"), true, TEST_LOCATION );
1153 int UtcDaliVisualFactoryGetSvgVisualLarge(void)
1155 ToolkitTestApplication application;
1156 tet_infoline( "UtcDaliVisualFactoryGetSvgVisual: Request svg visual with a svg url" );
1158 VisualFactory factory = VisualFactory::Get();
1159 Visual::Base visual = factory.CreateVisual( TEST_SVG_FILE_NAME, ImageDimensions( 2000, 2000 ) );
1160 DALI_TEST_CHECK( visual );
1162 TestGlAbstraction& gl = application.GetGlAbstraction();
1163 TraceCallStack& textureTrace = gl.GetTextureTrace();
1164 textureTrace.Enable(true);
1166 DummyControl actor = DummyControl::New();
1167 DummyControlImpl& dummyImpl = static_cast<DummyControlImpl&>(actor.GetImplementation());
1168 dummyImpl.RegisterVisual( Control::CONTROL_PROPERTY_END_INDEX + 1, visual );
1169 Stage::GetCurrent().Add( actor );
1171 application.SendNotification();
1172 application.Render();
1174 // renderer is not added to actor until the rasterization is completed.
1175 DALI_TEST_CHECK( actor.GetRendererCount() == 0u );
1177 EventThreadCallback* eventTrigger = EventThreadCallback::Get();
1178 CallbackBase* callback = eventTrigger->GetCallback();
1180 eventTrigger->WaitingForTrigger( 1 );// waiting until the svg image is rasterized.
1181 CallbackBase::Execute( *callback );
1183 // renderer is added to actor
1184 DALI_TEST_CHECK( actor.GetRendererCount() == 1u );
1186 // waiting for the resource uploading
1187 application.SendNotification();
1188 application.Render();
1190 DALI_TEST_EQUALS( textureTrace.FindMethod("BindTexture"), true, TEST_LOCATION );
1195 //Creates a mesh visual from the given propertyMap and tries to load it on stage in the given application.
1196 //This is expected to succeed, which will then pass the test.
1197 void MeshVisualLoadsCorrectlyTest( Property::Map& propertyMap, ToolkitTestApplication& application )
1199 VisualFactory factory = VisualFactory::Get();
1200 DALI_TEST_CHECK( factory );
1202 //Create a mesh visual.
1203 Visual::Base visual = factory.CreateVisual( propertyMap );
1204 DALI_TEST_CHECK( visual );
1206 //Create an actor on stage to house the visual.
1207 DummyControl actor = DummyControl::New();
1208 DummyControlImpl& dummyImpl = static_cast<DummyControlImpl&>(actor.GetImplementation());
1209 dummyImpl.RegisterVisual( Control::CONTROL_PROPERTY_END_INDEX + 1, visual );
1210 actor.SetSize( 200.f, 200.f );
1211 Stage::GetCurrent().Add( actor );
1212 visual.SetSize( Vector2( 200.f, 200.f ) );
1214 //Ensure set on stage.
1215 DALI_TEST_EQUALS( actor.GetRendererCount(), 1u, TEST_LOCATION );
1217 //Attempt to render to queue resource load requests.
1218 application.SendNotification();
1219 application.Render( 0 );
1221 //Tell the platform abstraction that the required resources have been loaded.
1222 TestPlatformAbstraction& platform = application.GetPlatform();
1223 platform.SetAllResourceRequestsAsLoaded();
1225 //Render again to upload the now-loaded textures.
1226 application.SendNotification();
1227 application.Render( 0 );
1229 Matrix testScaleMatrix;
1230 testScaleMatrix.SetIdentityAndScale( Vector3( 1.0, -1.0, 1.0 ) );
1231 Matrix actualScaleMatrix;
1233 //Test to see if the object has been successfully loaded.
1234 DALI_TEST_CHECK( application.GetGlAbstraction().GetUniformValue<Matrix>( "uObjectMatrix", actualScaleMatrix ) );
1235 DALI_TEST_EQUALS( actualScaleMatrix, testScaleMatrix, Math::MACHINE_EPSILON_100, TEST_LOCATION );
1237 //Finish by setting off stage, and ensuring this was successful.
1239 DALI_TEST_EQUALS( actor.GetRendererCount(), 0u, TEST_LOCATION );
1242 //Creates a mesh visual from the given propertyMap and tries to load it on stage in the given application.
1243 //This is expected to fail, which will then pass the test.
1244 void MeshVisualDoesNotLoadCorrectlyTest( Property::Map& propertyMap, ToolkitTestApplication& application )
1246 VisualFactory factory = VisualFactory::Get();
1247 DALI_TEST_CHECK( factory );
1249 //Create a mesh visual.
1250 Visual::Base visual = factory.CreateVisual( propertyMap );
1251 DALI_TEST_CHECK( visual );
1253 //Create an actor on stage to house the visual.
1254 DummyControl actor = DummyControl::New();
1255 DummyControlImpl& dummyImpl = static_cast<DummyControlImpl&>(actor.GetImplementation());
1256 dummyImpl.RegisterVisual( Control::CONTROL_PROPERTY_END_INDEX + 1, visual );
1257 actor.SetSize( 200.f, 200.f );
1258 Stage::GetCurrent().Add( actor );
1259 visual.SetSize( Vector2( 200.f, 200.f ) );
1261 //Ensure set on stage.
1262 DALI_TEST_EQUALS( actor.GetRendererCount(), 1u, TEST_LOCATION );
1264 //Attempt to render to queue resource load requests.
1265 application.SendNotification();
1266 application.Render( 0 );
1268 //Tell the platform abstraction that the required resources have been loaded.
1269 TestPlatformAbstraction& platform = application.GetPlatform();
1270 platform.SetAllResourceRequestsAsLoaded();
1272 //Render again to upload the now-loaded textures.
1273 application.SendNotification();
1274 application.Render( 0 );
1276 //Test to see if the object has not been loaded, as expected.
1278 DALI_TEST_CHECK( !application.GetGlAbstraction().GetUniformValue<Matrix>( "uObjectMatrix", scaleMatrix ) );
1280 //Finish by setting off stage, and ensuring this was successful.
1282 DALI_TEST_EQUALS( actor.GetRendererCount(), 0u, TEST_LOCATION );
1285 //Test if mesh loads correctly when supplied with only the bare minimum requirements, an object file.
1286 int UtcDaliVisualFactoryGetMeshVisual1(void)
1288 //Set up test application first, so everything else can be handled.
1289 ToolkitTestApplication application;
1291 tet_infoline( "UtcDaliVisualFactoryGetMeshVisual1: Request mesh visual with a valid object file only" );
1294 //Set up visual properties.
1295 Property::Map propertyMap;
1296 propertyMap.Insert( Visual::Property::TYPE, Visual::MESH );
1297 propertyMap.Insert( MeshVisual::Property::OBJECT_URL, TEST_OBJ_FILE_NAME );
1299 //Test to see if mesh loads correctly.
1300 MeshVisualLoadsCorrectlyTest( propertyMap, application );
1306 //Test if mesh loads correctly when supplied with an object file as well as a blank material file and images directory.
1307 int UtcDaliVisualFactoryGetMeshVisual2(void)
1309 //Set up test application first, so everything else can be handled.
1310 ToolkitTestApplication application;
1312 tet_infoline( "UtcDaliVisualFactoryGetMeshVisual2: Request mesh visual with blank material file and images directory" );
1314 //Set up visual properties.
1315 Property::Map propertyMap;
1316 propertyMap.Insert( Visual::Property::TYPE, Visual::MESH );
1317 propertyMap.Insert( MeshVisual::Property::OBJECT_URL, TEST_OBJ_FILE_NAME );
1318 propertyMap.Insert( MeshVisual::Property::MATERIAL_URL, "" );
1319 propertyMap.Insert( MeshVisual::Property::TEXTURES_PATH, "" );
1321 //Test to see if mesh loads correctly.
1322 MeshVisualLoadsCorrectlyTest( propertyMap, application );
1327 //Test if mesh loads correctly when supplied with all main parameters, an object file, a material file and a directory location.
1328 int UtcDaliVisualFactoryGetMeshVisual3(void)
1330 //Set up test application first, so everything else can be handled.
1331 ToolkitTestApplication application;
1333 tet_infoline( "UtcDaliVisualFactoryGetMeshVisual3: Request mesh visual with all parameters correct" );
1335 //Set up visual properties.
1336 Property::Map propertyMap;
1337 propertyMap.Insert( Visual::Property::TYPE, Visual::MESH );
1338 propertyMap.Insert( MeshVisual::Property::OBJECT_URL, TEST_OBJ_FILE_NAME );
1339 propertyMap.Insert( MeshVisual::Property::MATERIAL_URL, TEST_MTL_FILE_NAME );
1340 propertyMap.Insert( MeshVisual::Property::TEXTURES_PATH, TEST_RESOURCE_DIR "/" );
1342 //Test to see if mesh loads correctly.
1343 MeshVisualLoadsCorrectlyTest( propertyMap, application );
1348 //Test if mesh visual can load a correctly supplied mesh without a normal map or gloss map in the material file.
1349 int UtcDaliVisualFactoryGetMeshVisual4(void)
1351 //Set up test application first, so everything else can be handled.
1352 ToolkitTestApplication application;
1354 tet_infoline( "UtcDaliVisualFactoryGetMeshVisual4: Request mesh visual with diffuse texture but not normal or gloss." );
1357 //Set up visual properties.
1358 Property::Map propertyMap;
1359 propertyMap.Insert( Visual::Property::TYPE, Visual::MESH );
1360 propertyMap.Insert( MeshVisual::Property::OBJECT_URL, TEST_OBJ_FILE_NAME );
1361 propertyMap.Insert( MeshVisual::Property::MATERIAL_URL, TEST_SIMPLE_MTL_FILE_NAME );
1362 propertyMap.Insert( MeshVisual::Property::TEXTURES_PATH, TEST_RESOURCE_DIR "/" );
1364 //Test to see if mesh loads correctly.
1365 MeshVisualLoadsCorrectlyTest( propertyMap, application );
1371 //Test if mesh visual can load when made to use diffuse textures only.
1372 int UtcDaliVisualFactoryGetMeshVisual5(void)
1374 //Set up test application first, so everything else can be handled.
1375 ToolkitTestApplication application;
1377 tet_infoline( "UtcDaliVisualFactoryGetMeshVisual5: Request mesh visual and make it only use diffuse textures." );
1379 //Set up visual properties.
1380 Property::Map propertyMap;
1381 propertyMap.Insert( Visual::Property::TYPE, Visual::MESH );
1382 propertyMap.Insert( MeshVisual::Property::OBJECT_URL, TEST_OBJ_FILE_NAME );
1383 propertyMap.Insert( MeshVisual::Property::MATERIAL_URL, TEST_MTL_FILE_NAME );
1384 propertyMap.Insert( MeshVisual::Property::TEXTURES_PATH, TEST_RESOURCE_DIR "/" );
1385 propertyMap.Insert( MeshVisual::Property::SHADING_MODE, MeshVisual::ShadingMode::TEXTURED_WITH_SPECULAR_LIGHTING );
1387 //Test to see if mesh loads correctly.
1388 MeshVisualLoadsCorrectlyTest( propertyMap, application );
1394 //Test if mesh visual can load when made to not use the supplied textures.
1395 int UtcDaliVisualFactoryGetMeshVisual6(void)
1397 //Set up test application first, so everything else can be handled.
1398 ToolkitTestApplication application;
1400 tet_infoline( "UtcDaliVisualFactoryGetMeshVisual6: Request mesh visual and make it not use any textures." );
1402 //Set up visual properties.
1403 Property::Map propertyMap;
1404 propertyMap.Insert( Visual::Property::TYPE, Visual::MESH );
1405 propertyMap.Insert( MeshVisual::Property::OBJECT_URL, TEST_OBJ_FILE_NAME );
1406 propertyMap.Insert( MeshVisual::Property::MATERIAL_URL, TEST_MTL_FILE_NAME );
1407 propertyMap.Insert( MeshVisual::Property::TEXTURES_PATH, TEST_RESOURCE_DIR "/" );
1408 propertyMap.Insert( MeshVisual::Property::SHADING_MODE, MeshVisual::ShadingMode::TEXTURELESS_WITH_DIFFUSE_LIGHTING );
1410 //Test to see if mesh loads correctly.
1411 MeshVisualLoadsCorrectlyTest( propertyMap, application );
1415 //Test if mesh visual loads correctly when light position is manually set.
1416 int UtcDaliVisualFactoryGetMeshVisual7(void)
1418 //Set up test application first, so everything else can be handled.
1419 ToolkitTestApplication application;
1422 tet_infoline( "UtcDaliVisualFactoryGetMeshVisual7: Request mesh visual with custom light position." );
1424 //Set up visual properties.
1425 Property::Map propertyMap;
1426 propertyMap.Insert( Visual::Property::TYPE, Visual::MESH );
1427 propertyMap.Insert( MeshVisual::Property::OBJECT_URL, TEST_OBJ_FILE_NAME );
1428 propertyMap.Insert( MeshVisual::Property::MATERIAL_URL, TEST_MTL_FILE_NAME );
1429 propertyMap.Insert( MeshVisual::Property::TEXTURES_PATH, TEST_RESOURCE_DIR "/" );
1430 propertyMap.Insert( MeshVisual::Property::LIGHT_POSITION, Vector3( 0.0, 1.0, 2.0 ) );
1432 //Test to see if mesh loads correctly.
1433 MeshVisualLoadsCorrectlyTest( propertyMap, application );
1438 //Test if mesh visual loads correctly when supplied an object file without face normals or texture points.
1439 //Note that this notably tests object loader functionality.
1440 int UtcDaliVisualFactoryGetMeshVisual8(void)
1442 //Set up test application first, so everything else can be handled.
1443 ToolkitTestApplication application;
1445 tet_infoline( "UtcDaliVisualFactoryGetMeshVisual5: Request mesh visual with normal-less object file." );
1447 //Set up visual properties.
1448 Property::Map propertyMap;
1449 propertyMap.Insert( Visual::Property::TYPE, Visual::MESH );
1450 propertyMap.Insert( MeshVisual::Property::OBJECT_URL, TEST_SIMPLE_OBJ_FILE_NAME );
1451 propertyMap.Insert( MeshVisual::Property::MATERIAL_URL, TEST_MTL_FILE_NAME );
1452 propertyMap.Insert( MeshVisual::Property::TEXTURES_PATH, TEST_RESOURCE_DIR "/" );
1454 //Test to see if mesh loads correctly.
1455 MeshVisualLoadsCorrectlyTest( propertyMap, application );
1460 //Test if mesh visual handles the case of lacking an object file.
1461 int UtcDaliVisualFactoryGetMeshVisualN1(void)
1463 //Set up test application first, so everything else can be handled.
1464 ToolkitTestApplication application;
1466 tet_infoline( "UtcDaliVisualFactoryGetMeshVisualN1: Request mesh visual without object file" );
1468 //Set up visual properties.
1469 Property::Map propertyMap;
1470 propertyMap.Insert( Visual::Property::TYPE, Visual::MESH );
1471 propertyMap.Insert( MeshVisual::Property::MATERIAL_URL, TEST_MTL_FILE_NAME );
1472 propertyMap.Insert( MeshVisual::Property::TEXTURES_PATH, TEST_RESOURCE_DIR "/" );
1474 //Test to see if mesh doesn't load with these properties, as expected.
1475 MeshVisualDoesNotLoadCorrectlyTest( propertyMap, application );
1481 //Test if mesh visual handles the case of being passed invalid material and images urls.
1482 int UtcDaliVisualFactoryGetMeshVisualN2(void)
1484 //Set up test application first, so everything else can be handled.
1485 ToolkitTestApplication application;
1487 tet_infoline( "UtcDaliVisualFactoryGetMeshVisualN2: Request mesh visual with invalid material and images urls" );
1489 //Set up visual properties.
1490 Property::Map propertyMap;
1491 propertyMap.Insert( Visual::Property::TYPE, Visual::MESH );
1492 propertyMap.Insert( MeshVisual::Property::OBJECT_URL, TEST_OBJ_FILE_NAME );
1493 propertyMap.Insert( MeshVisual::Property::MATERIAL_URL, "invalid" );
1494 propertyMap.Insert( MeshVisual::Property::TEXTURES_PATH, "also invalid" );
1496 //Test to see if mesh doesn't load with these properties, as expected.
1497 MeshVisualDoesNotLoadCorrectlyTest( propertyMap, application );
1503 //Test if mesh visual handles the case of being passed an invalid object url
1504 int UtcDaliVisualFactoryGetMeshVisualN3(void)
1506 //Set up test application first, so everything else can be handled.
1507 ToolkitTestApplication application;
1508 tet_infoline( "UtcDaliVisualFactoryGetMeshVisualN3: Request mesh visual with invalid object url" );
1511 //Set up visual properties.
1512 Property::Map propertyMap;
1513 propertyMap.Insert( Visual::Property::TYPE, Visual::MESH );
1514 propertyMap.Insert( MeshVisual::Property::OBJECT_URL, "invalid" );
1515 propertyMap.Insert( MeshVisual::Property::MATERIAL_URL, TEST_MTL_FILE_NAME );
1516 propertyMap.Insert( MeshVisual::Property::TEXTURES_PATH, TEST_RESOURCE_DIR "/" );
1518 //Test to see if mesh doesn't load with these properties, as expected.
1519 MeshVisualDoesNotLoadCorrectlyTest( propertyMap, application );
1524 //Creates a primitive visual with the given property map and tests to see if it correctly loads in the given application.
1525 void TestPrimitiveVisualWithProperties( Property::Map& propertyMap, ToolkitTestApplication& application )
1527 VisualFactory factory = VisualFactory::Get();
1528 DALI_TEST_CHECK( factory );
1530 //Create a primitive visual.
1531 Visual::Base visual = factory.CreateVisual( propertyMap );
1532 DALI_TEST_CHECK( visual );
1534 //Create an actor on stage to house the visual.
1535 DummyControl actor = DummyControl::New();
1536 DummyControlImpl& dummyImpl = static_cast<DummyControlImpl&>(actor.GetImplementation());
1537 dummyImpl.RegisterVisual( Control::CONTROL_PROPERTY_END_INDEX + 1, visual );
1539 actor.SetSize( 200.f, 200.f );
1540 Stage::GetCurrent().Add( actor );
1541 visual.SetSize( Vector2( 200.f, 200.f ) );
1543 //Ensure set on stage.
1544 DALI_TEST_EQUALS( actor.GetRendererCount(), 1u, TEST_LOCATION );
1546 //Tell test application to load the visual.
1547 application.SendNotification();
1548 application.Render(0);
1550 Matrix testScaleMatrix;
1551 testScaleMatrix.SetIdentityAndScale( Vector3( 1.0, -1.0, 1.0 ) );
1552 Matrix actualScaleMatrix;
1554 //Test to see if the object has been successfully loaded.
1555 DALI_TEST_CHECK( application.GetGlAbstraction().GetUniformValue<Matrix>( "uObjectMatrix", actualScaleMatrix ) );
1556 DALI_TEST_EQUALS( actualScaleMatrix, testScaleMatrix, Math::MACHINE_EPSILON_100, TEST_LOCATION );
1558 //Finish by setting off stage, and ensuring this was successful.
1560 DALI_TEST_EQUALS( actor.GetRendererCount(), 0u, TEST_LOCATION );
1563 //Test if primitive shape loads correctly when supplied with only the bare minimum requirements, the shape to use.
1564 int UtcDaliVisualFactoryGetPrimitiveVisual1(void)
1566 //Set up test application first, so everything else can be handled.
1567 ToolkitTestApplication application;
1569 tet_infoline( "UtcDaliVisualFactoryGetPrimitiveVisual1: Request primitive visual with a shape only" );
1571 //Set up visual properties.
1572 Property::Map propertyMap;
1573 propertyMap.Insert( Visual::Property::TYPE, Visual::PRIMITIVE );
1574 propertyMap.Insert( PrimitiveVisual::Property::SHAPE, PrimitiveVisual::Shape::CUBE );
1576 //Test to see if shape loads correctly.
1577 TestPrimitiveVisualWithProperties( propertyMap, application );
1582 //Test if primitive shape loads correctly when supplied with all possible parameters
1583 int UtcDaliVisualFactoryGetPrimitiveVisual2(void)
1585 //Set up test application first, so everything else can be handled.
1586 ToolkitTestApplication application;
1588 tet_infoline( "UtcDaliVisualFactoryGetPrimitiveVisual2: Request primitive visual with everything" );
1590 //Set up visual properties.
1591 Property::Map propertyMap;
1592 propertyMap.Insert( Visual::Property::TYPE, Visual::PRIMITIVE );
1593 propertyMap.Insert( PrimitiveVisual::Property::SHAPE, PrimitiveVisual::Shape::CUBE );
1594 propertyMap.Insert( PrimitiveVisual::Property::MIX_COLOR, Vector4( 0.5, 0.5, 0.5, 1.0 ) );
1595 propertyMap.Insert( PrimitiveVisual::Property::SLICES, 10 );
1596 propertyMap.Insert( PrimitiveVisual::Property::STACKS, 20 );
1597 propertyMap.Insert( PrimitiveVisual::Property::SCALE_TOP_RADIUS, 30.0f );
1598 propertyMap.Insert( PrimitiveVisual::Property::SCALE_BOTTOM_RADIUS, 40.0f );
1599 propertyMap.Insert( PrimitiveVisual::Property::SCALE_HEIGHT, 50.0f );
1600 propertyMap.Insert( PrimitiveVisual::Property::SCALE_RADIUS, 60.0f );
1601 propertyMap.Insert( PrimitiveVisual::Property::BEVEL_PERCENTAGE, 0.7f );
1602 propertyMap.Insert( PrimitiveVisual::Property::BEVEL_SMOOTHNESS, 0.8f );
1603 propertyMap.Insert( MeshVisual::Property::LIGHT_POSITION, Vector3( 0.9, 1.0, 1.1 ) );
1605 //Test to see if shape loads correctly.
1606 TestPrimitiveVisualWithProperties( propertyMap, application );
1611 //Test if primitive shape loads a sphere correctly.
1612 int UtcDaliVisualFactoryGetPrimitiveVisual3(void)
1614 //Set up test application first, so everything else can be handled.
1615 ToolkitTestApplication application;
1617 tet_infoline( "UtcDaliVisualFactoryGetPrimitiveVisual3: Request primitive visual to display a sphere" );
1619 //Set up visual properties.
1620 Property::Map propertyMap;
1621 propertyMap.Insert( Visual::Property::TYPE, Visual::PRIMITIVE );
1622 propertyMap.Insert( PrimitiveVisual::Property::SHAPE, PrimitiveVisual::Shape::SPHERE );
1623 propertyMap.Insert( PrimitiveVisual::Property::MIX_COLOR, Vector4( 0.5, 0.5, 0.5, 1.0 ) );
1624 propertyMap.Insert( PrimitiveVisual::Property::SLICES, 10 );
1625 propertyMap.Insert( PrimitiveVisual::Property::STACKS, 20 );
1627 //Test to see if shape loads correctly.
1628 TestPrimitiveVisualWithProperties( propertyMap, application );
1633 //Test if primitive shape loads a conic section correctly.
1634 int UtcDaliVisualFactoryGetPrimitiveVisual4(void)
1636 //Set up test application first, so everything else can be handled.
1637 ToolkitTestApplication application;
1639 tet_infoline( "UtcDaliVisualFactoryGetPrimitiveVisual4: Request primitive visual to display a conic section" );
1641 //Set up visual properties.
1642 Property::Map propertyMap;
1643 propertyMap.Insert( Visual::Property::TYPE, Visual::PRIMITIVE );
1644 propertyMap.Insert( PrimitiveVisual::Property::SHAPE, PrimitiveVisual::Shape::CONICAL_FRUSTRUM );
1645 propertyMap.Insert( PrimitiveVisual::Property::MIX_COLOR, Vector4( 0.5, 0.5, 0.5, 1.0 ) );
1646 propertyMap.Insert( PrimitiveVisual::Property::SLICES, 10 );
1647 propertyMap.Insert( PrimitiveVisual::Property::SCALE_TOP_RADIUS, 30.0f );
1648 propertyMap.Insert( PrimitiveVisual::Property::SCALE_BOTTOM_RADIUS, 40.0f );
1649 propertyMap.Insert( PrimitiveVisual::Property::SCALE_HEIGHT, 50.0f );
1651 //Test to see if shape loads correctly.
1652 TestPrimitiveVisualWithProperties( propertyMap, application );
1657 //Test if primitive shape loads a bevelled cube correctly.
1658 int UtcDaliVisualFactoryGetPrimitiveVisual5(void)
1660 //Set up test application first, so everything else can be handled.
1661 ToolkitTestApplication application;
1663 tet_infoline( "UtcDaliVisualFactoryGetPrimitiveVisual5: Request primitive visual to display a bevelled cube" );
1665 //Set up visual properties.
1666 Property::Map propertyMap;
1667 propertyMap.Insert( Visual::Property::TYPE, Visual::PRIMITIVE );
1668 propertyMap.Insert( PrimitiveVisual::Property::SHAPE, PrimitiveVisual::Shape::BEVELLED_CUBE );
1669 propertyMap.Insert( PrimitiveVisual::Property::MIX_COLOR, Vector4( 0.5, 0.5, 0.5, 1.0 ) );
1670 propertyMap.Insert( PrimitiveVisual::Property::BEVEL_PERCENTAGE, 0.7f );
1672 //Test to see if shape loads correctly.
1673 TestPrimitiveVisualWithProperties( propertyMap, application );
1678 //Test if primitive shape loads an octahedron correctly.
1679 int UtcDaliVisualFactoryGetPrimitiveVisual6(void)
1681 //Set up test application first, so everything else can be handled.
1682 ToolkitTestApplication application;
1684 tet_infoline( "UtcDaliVisualFactoryGetPrimitiveVisual6: Request primitive visual to display an octahedron" );
1686 //Set up visual properties.
1687 Property::Map propertyMap;
1688 propertyMap.Insert( Visual::Property::TYPE, Visual::PRIMITIVE );
1689 propertyMap.Insert( PrimitiveVisual::Property::SHAPE, PrimitiveVisual::Shape::OCTAHEDRON );
1690 propertyMap.Insert( PrimitiveVisual::Property::MIX_COLOR, Vector4( 0.5, 0.5, 0.5, 1.0 ) );
1692 //Test to see if shape loads correctly.
1693 TestPrimitiveVisualWithProperties( propertyMap, application );
1698 //Test if primitive shape loads a cone correctly.
1699 int UtcDaliVisualFactoryGetPrimitiveVisual7(void)
1701 //Set up test application first, so everything else can be handled.
1702 ToolkitTestApplication application;
1704 tet_infoline( "UtcDaliVisualFactoryGetPrimitiveVisual7: Request primitive visual to display a cone" );
1706 //Set up visual properties.
1707 Property::Map propertyMap;
1708 propertyMap.Insert( Visual::Property::TYPE, Visual::PRIMITIVE );
1709 propertyMap.Insert( PrimitiveVisual::Property::SHAPE, PrimitiveVisual::Shape::CONE );
1710 propertyMap.Insert( PrimitiveVisual::Property::MIX_COLOR, Vector4( 0.5, 0.5, 0.5, 1.0 ) );
1711 propertyMap.Insert( PrimitiveVisual::Property::SLICES, 10 );
1712 propertyMap.Insert( PrimitiveVisual::Property::SCALE_TOP_RADIUS, 30.0f );
1713 propertyMap.Insert( PrimitiveVisual::Property::SCALE_HEIGHT, 50.0f );
1715 //Test to see if shape loads correctly.
1716 TestPrimitiveVisualWithProperties( propertyMap, application );
1721 //Test if primitive shape loads correctly when light position is manually set.
1722 int UtcDaliVisualFactoryGetPrimitiveVisual8(void)
1724 //Set up test application first, so everything else can be handled.
1725 ToolkitTestApplication application;
1727 tet_infoline( "UtcDaliVisualFactoryGetPrimitiveVisual8: Request primitive visual with set light position" );
1729 //Set up visual properties.
1730 Property::Map propertyMap;
1731 propertyMap.Insert( Visual::Property::TYPE, Visual::PRIMITIVE );
1732 propertyMap.Insert( PrimitiveVisual::Property::SHAPE, PrimitiveVisual::Shape::SPHERE );
1733 propertyMap.Insert( PrimitiveVisual::Property::MIX_COLOR, Vector4( 0.5, 0.5, 0.5, 1.0 ) );
1734 propertyMap.Insert( MeshVisual::Property::LIGHT_POSITION, Vector3( 0.0, 1.0, 2.0 ) );
1736 //Test to see if shape loads correctly.
1737 TestPrimitiveVisualWithProperties( propertyMap, application );
1742 //Test if primitive shape loads correctly when told to use too many slices.
1743 int UtcDaliVisualFactoryGetPrimitiveVisual9(void)
1745 //Set up test application first, so everything else can be handled.
1746 ToolkitTestApplication application;
1748 tet_infoline( "UtcDaliVisualFactoryGetPrimitiveVisual9: Request primitive visual with above-cap slices." );
1750 //Set up visual properties.
1751 Property::Map propertyMap;
1752 propertyMap.Insert( Visual::Property::TYPE, Visual::PRIMITIVE );
1753 propertyMap.Insert( PrimitiveVisual::Property::SHAPE, PrimitiveVisual::Shape::SPHERE );
1754 propertyMap.Insert( PrimitiveVisual::Property::SLICES, Property::Value( 1000000 ) );
1756 //Test to see if shape loads correctly.
1757 TestPrimitiveVisualWithProperties( propertyMap, application );
1762 //Test if primitive shape loads correctly when told to use too few slices. (2 slices or less.)
1763 int UtcDaliVisualFactoryGetPrimitiveVisual10(void)
1765 //Set up test application first, so everything else can be handled.
1766 ToolkitTestApplication application;
1768 tet_infoline( "UtcDaliVisualFactoryGetPrimitiveVisual10: Request primitive visual with too few slices." );
1770 //Set up visual properties.
1771 Property::Map propertyMap;
1772 propertyMap.Insert( Visual::Property::TYPE, Visual::PRIMITIVE );
1773 propertyMap.Insert( PrimitiveVisual::Property::SHAPE, PrimitiveVisual::Shape::SPHERE );
1774 propertyMap.Insert( PrimitiveVisual::Property::SLICES, Property::Value( 2 ) );
1776 //Test to see if shape loads correctly.
1777 TestPrimitiveVisualWithProperties( propertyMap, application );
1782 //Test if primitive shape loads correctly when told to use too many stacks.
1783 int UtcDaliVisualFactoryGetPrimitiveVisual11(void)
1785 //Set up test application first, so everything else can be handled.
1786 ToolkitTestApplication application;
1788 tet_infoline( "UtcDaliVisualFactoryGetPrimitiveVisual11: Request primitive visual with too many stacks." );
1790 //Set up visual properties.
1791 Property::Map propertyMap;
1792 propertyMap.Insert( Visual::Property::TYPE, Visual::PRIMITIVE );
1793 propertyMap.Insert( PrimitiveVisual::Property::SHAPE, PrimitiveVisual::Shape::SPHERE );
1794 propertyMap.Insert( PrimitiveVisual::Property::STACKS, Property::Value( 1000000 ) );
1796 //Test to see if shape loads correctly.
1797 TestPrimitiveVisualWithProperties( propertyMap, application );
1802 //Test if primitive shape loads correctly when told to use too few stacks. (1 stack or less.)
1803 int UtcDaliVisualFactoryGetPrimitiveVisual12(void)
1805 //Set up test application first, so everything else can be handled.
1806 ToolkitTestApplication application;
1808 tet_infoline( "UtcDaliVisualFactoryGetPrimitiveVisual12: Request primitive visual with too few stacks." );
1810 //Set up visual properties.
1811 Property::Map propertyMap;
1812 propertyMap.Insert( Visual::Property::TYPE, Visual::PRIMITIVE );
1813 propertyMap.Insert( PrimitiveVisual::Property::SHAPE, PrimitiveVisual::Shape::SPHERE );
1814 propertyMap.Insert( PrimitiveVisual::Property::STACKS, Property::Value( 1 ) );
1816 //Test to see if shape loads correctly.
1817 TestPrimitiveVisualWithProperties( propertyMap, application );
1822 //Test if primitive shape loads correctly when told to use invalid (zero or negative) dimensions.
1823 int UtcDaliVisualFactoryGetPrimitiveVisual13(void)
1825 //Set up test application first, so everything else can be handled.
1826 ToolkitTestApplication application;
1828 tet_infoline( "UtcDaliVisualFactoryGetPrimitiveVisual13: Request primitive visual with invalid scale dimensions." );
1830 //Set up visual properties.
1831 Property::Map propertyMap;
1832 propertyMap.Insert( Visual::Property::TYPE, Visual::PRIMITIVE );
1833 propertyMap.Insert( PrimitiveVisual::Property::SHAPE, PrimitiveVisual::Shape::SPHERE );
1834 propertyMap.Insert( PrimitiveVisual::Property::SCALE_DIMENSIONS, Vector3::ZERO );
1836 //Test to see if shape loads correctly.
1837 TestPrimitiveVisualWithProperties( propertyMap, application );
1842 //Test if primitive shape loads correctly when told to use too low a bevel percentage.
1843 int UtcDaliVisualFactoryGetPrimitiveVisual14(void)
1845 //Set up test application first, so everything else can be handled.
1846 ToolkitTestApplication application;
1848 tet_infoline( "UtcDaliVisualFactoryGetPrimitiveVisual14: Request primitive visual with too low a bevel percentage." );
1850 //Set up visual properties.
1851 Property::Map propertyMap;
1852 propertyMap.Insert( Visual::Property::TYPE, Visual::PRIMITIVE );
1853 propertyMap.Insert( PrimitiveVisual::Property::SHAPE, PrimitiveVisual::Shape::SPHERE );
1854 propertyMap.Insert( PrimitiveVisual::Property::BEVEL_PERCENTAGE, Property::Value( -1.0f ) );
1856 //Test to see if shape loads correctly.
1857 TestPrimitiveVisualWithProperties( propertyMap, application );
1862 //Test if primitive shape loads correctly when told to use too high a bevel percentage.
1863 int UtcDaliVisualFactoryGetPrimitiveVisual15(void)
1865 //Set up test application first, so everything else can be handled.
1866 ToolkitTestApplication application;
1868 tet_infoline( "UtcDaliVisualFactoryGetPrimitiveVisual15: Request primitive visual with too high a bevel percentage." );
1870 //Set up visual properties.
1871 Property::Map propertyMap;
1872 propertyMap.Insert( Visual::Property::TYPE, Visual::PRIMITIVE );
1873 propertyMap.Insert( PrimitiveVisual::Property::SHAPE, PrimitiveVisual::Shape::SPHERE );
1874 propertyMap.Insert( PrimitiveVisual::Property::BEVEL_PERCENTAGE, Property::Value( 2.0f ) );
1876 //Test to see if shape loads correctly.
1877 TestPrimitiveVisualWithProperties( propertyMap, application );
1882 //Test if primitive shape loads correctly when told to use too low a bevel smoothness.
1883 int UtcDaliVisualFactoryGetPrimitiveVisual16(void)
1885 //Set up test application first, so everything else can be handled.
1886 ToolkitTestApplication application;
1888 tet_infoline( "UtcDaliVisualFactoryGetPrimitiveVisual16: Request primitive visual with too low a bevel smoothness." );
1890 //Set up visual properties.
1891 Property::Map propertyMap;
1892 propertyMap.Insert( Visual::Property::TYPE, Visual::PRIMITIVE );
1893 propertyMap.Insert( PrimitiveVisual::Property::SHAPE, PrimitiveVisual::Shape::SPHERE );
1894 propertyMap.Insert( PrimitiveVisual::Property::BEVEL_SMOOTHNESS, Property::Value( -1.0f ) );
1896 //Test to see if shape loads correctly.
1897 TestPrimitiveVisualWithProperties( propertyMap, application );
1902 //Test if primitive shape loads correctly when told to use too high a bevel smoothness.
1903 int UtcDaliVisualFactoryGetPrimitiveVisual17(void)
1905 //Set up test application first, so everything else can be handled.
1906 ToolkitTestApplication application;
1908 tet_infoline( "UtcDaliVisualFactoryGetPrimitiveVisual17: Request primitive visual with too high a bevel smoothness." );
1910 //Set up visual properties.
1911 Property::Map propertyMap;
1912 propertyMap.Insert( Visual::Property::TYPE, Visual::PRIMITIVE );
1913 propertyMap.Insert( PrimitiveVisual::Property::SHAPE, PrimitiveVisual::Shape::SPHERE );
1914 propertyMap.Insert( PrimitiveVisual::Property::BEVEL_SMOOTHNESS, Property::Value( 2.0f ) );
1916 //Test to see if shape loads correctly.
1917 TestPrimitiveVisualWithProperties( propertyMap, application );
1922 //Test if primitive shape visual handles the case of not being passed a specific shape to use.
1923 int UtcDaliVisualFactoryGetPrimitiveVisualN1(void)
1925 //Set up test application first, so everything else can be handled.
1926 ToolkitTestApplication application;
1928 tet_infoline( "UtcDaliVisualFactoryGetPrimitiveVisualN1: Request primitive visual without shape" );
1930 //Set up visual properties, without supplying shape.
1931 Property::Map propertyMap;
1932 propertyMap.Insert( Visual::Property::TYPE, Visual::PRIMITIVE );
1934 //Test to see if shape loads regardless of missing input.
1935 TestPrimitiveVisualWithProperties( propertyMap, application );
1940 int UtcDaliVisualFactoryGetBatchImageVisual1(void)
1942 ToolkitTestApplication application;
1943 tet_infoline( "UtcDaliVisualFactoryGetBatchImageVisual1: Request a Batch Image visual with a Property::Map" );
1945 VisualFactory factory = VisualFactory::Get();
1946 DALI_TEST_CHECK( factory );
1948 Property::Map propertyMap;
1949 propertyMap.Insert( Visual::Property::TYPE, Visual::IMAGE );
1950 propertyMap.Insert( ImageVisual::Property::BATCHING_ENABLED, true );
1951 propertyMap.Insert( ImageVisual::Property::URL, TEST_IMAGE_FILE_NAME );
1953 Visual::Base visual = factory.CreateVisual( propertyMap );
1954 DALI_TEST_CHECK( visual );
1956 DummyControl actor = DummyControl::New();
1957 DummyControlImpl& dummyImpl = static_cast<DummyControlImpl&>(actor.GetImplementation());
1958 dummyImpl.RegisterVisual( Control::CONTROL_PROPERTY_END_INDEX + 1, visual );
1960 actor.SetSize( 200.0f, 200.0f );
1961 Stage::GetCurrent().Add( actor );
1962 visual.SetSize( Vector2( 200.0f, 200.0f ) );
1964 // Test SetOnStage().
1965 DALI_TEST_CHECK( actor.GetRendererCount() == 1u );
1967 application.SendNotification();
1968 application.Render();
1970 // Test SetOffStage().
1972 DALI_TEST_CHECK( actor.GetRendererCount() == 0u );
1977 int UtcDaliVisualFactoryGetBatchImageVisual2(void)
1979 ToolkitTestApplication application;
1980 tet_infoline( "UtcDaliVisualFactoryGetBatchImageVisual2: Request Batch Image visual from an Image Visual with batchingEnabled set" );
1982 VisualFactory factory = VisualFactory::Get();
1983 DALI_TEST_CHECK( factory );
1985 Property::Map propertyMap;
1986 // Create a normal Image Visual.
1987 propertyMap.Insert( Visual::Property::TYPE, Visual::IMAGE );
1988 // Instruct the factory to change Image Visuals to Batch-Image Visuals.
1989 propertyMap.Insert( ImageVisual::Property::BATCHING_ENABLED, true );
1991 // Properties for the Batch-Image Visual.
1992 propertyMap.Insert( ImageVisual::Property::URL, TEST_IMAGE_FILE_NAME );
1994 Visual::Base visual = factory.CreateVisual( propertyMap );
1995 DALI_TEST_CHECK( visual );
1997 // Check that a Batch-Image visual was created instead of an Image visual.
1998 Property::Map resultMap;
1999 visual.CreatePropertyMap( resultMap );
2001 Property::Value* value = resultMap.Find( Visual::Property::TYPE, Property::INTEGER );
2002 DALI_TEST_CHECK( value );
2003 DALI_TEST_EQUALS( value->Get<int>(), (int)Visual::IMAGE, TEST_LOCATION );
2005 DummyControl actor = DummyControl::New();
2006 DummyControlImpl& dummyImpl = static_cast<DummyControlImpl&>(actor.GetImplementation());
2007 dummyImpl.RegisterVisual( Control::CONTROL_PROPERTY_END_INDEX + 1, visual );
2009 actor.SetSize( 200.0f, 200.0f );
2010 Stage::GetCurrent().Add( actor );
2011 visual.SetSize( Vector2( 200.0f, 200.0f ) );
2013 // Test SetOnStage().
2014 DALI_TEST_CHECK( actor.GetRendererCount() == 1u );
2016 application.SendNotification();
2017 application.Render();
2019 // Test SetOffStage().
2021 DALI_TEST_CHECK( actor.GetRendererCount() == 0u );
2026 int UtcDaliVisualFactoryGetBatchImageVisual3(void)
2028 ToolkitTestApplication application;
2029 tet_infoline( "UtcDaliVisualFactoryGetBatchImageVisual3: Create an ImageView that uses a batched visual internally" );
2031 VisualFactory factory = VisualFactory::Get();
2032 DALI_TEST_CHECK( factory );
2034 // Create a property-map that enables batching.
2035 Property::Map propertyMap;
2036 propertyMap.Insert( Dali::Toolkit::ImageVisual::Property::URL, TEST_IMAGE_FILE_NAME );
2037 propertyMap.Insert( ImageVisual::Property::BATCHING_ENABLED, true );
2039 // Create an ImageView, passing the property-map in to instruct it to use batching.
2040 Toolkit::ImageView imageView = Toolkit::ImageView::New();
2041 imageView.SetProperty( Toolkit::ImageView::Property::IMAGE, propertyMap );
2043 imageView.SetSize( 200.0f, 200.0f );
2044 Stage::GetCurrent().Add( imageView );