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/align-enums.h>
27 #include <dali-toolkit/devel-api/visual-factory/devel-visual-properties.h>
28 #include <dali-toolkit/devel-api/visual-factory/visual-factory.h>
29 #include <dali-toolkit/dali-toolkit.h>
30 #include "dummy-control.h"
33 using namespace Dali::Toolkit;
37 typedef NinePatchImage::StretchRanges StretchRanges;
39 const char* TEST_IMAGE_FILE_NAME = "gallery_image_01.jpg";
40 const char* TEST_NPATCH_FILE_NAME = "gallery_image_01.9.png";
41 const char* TEST_SVG_FILE_NAME = TEST_RESOURCE_DIR "/svg1.svg";
42 const char* TEST_OBJ_FILE_NAME = TEST_RESOURCE_DIR "/Cube.obj";
43 const char* TEST_MTL_FILE_NAME = TEST_RESOURCE_DIR "/ToyRobot-Metal.mtl";
44 const char* TEST_SIMPLE_OBJ_FILE_NAME = TEST_RESOURCE_DIR "/Cube-Points-Only.obj";
45 const char* TEST_SIMPLE_MTL_FILE_NAME = TEST_RESOURCE_DIR "/ToyRobot-Metal-Simple.mtl";
47 // resolution: 34*34, pixel format: RGBA8888
48 static const char* gImage_34_RGBA = TEST_RESOURCE_DIR "/icon-edit.png";
49 // resolution: 600*600, pixel format: RGB888
50 static const char* gImage_600_RGB = TEST_RESOURCE_DIR "/test-image-600.jpg";
52 Property::Map DefaultTransform()
54 Property::Map transformMap;
56 .Add( Toolkit::VisualProperty::Transform::Property::OFFSET, Vector2(0.0f, 0.0f) )
57 .Add( Toolkit::VisualProperty::Transform::Property::SIZE, Vector2(1.0f, 1.0f) )
58 .Add( Toolkit::VisualProperty::Transform::Property::ORIGIN, Toolkit::Align::CENTER )
59 .Add( Toolkit::VisualProperty::Transform::Property::ANCHOR_POINT, Toolkit::Align::CENTER )
60 .Add( Toolkit::VisualProperty::Transform::Property::OFFSET_SIZE_MODE, Vector4::ZERO );
64 Integration::Bitmap* CreateBitmap( unsigned int imageWidth, unsigned int imageHeight, unsigned int initialColor, Pixel::Format pixelFormat )
66 Integration::Bitmap* bitmap = Integration::Bitmap::New( Integration::Bitmap::BITMAP_2D_PACKED_PIXELS, ResourcePolicy::OWNED_RETAIN );
67 Integration::PixelBuffer* pixbuffer = bitmap->GetPackedPixelsProfile()->ReserveBuffer( pixelFormat, imageWidth, imageHeight, imageWidth, imageHeight );
68 unsigned int bytesPerPixel = GetBytesPerPixel( pixelFormat );
70 memset( pixbuffer, initialColor, imageHeight * imageWidth * bytesPerPixel );
75 void InitialiseRegionsToZeroAlpha( Integration::Bitmap* image, unsigned int imageWidth, unsigned int imageHeight, Pixel::Format pixelFormat )
77 PixelBuffer* pixbuffer = image->GetBuffer();
78 unsigned int bytesPerPixel = GetBytesPerPixel( pixelFormat );
80 for( unsigned int row = 0; row < imageWidth; ++row )
82 unsigned int pixelOffset = row * bytesPerPixel;
83 pixbuffer[ pixelOffset + 3 ] = 0x00;
84 pixelOffset += ( imageHeight - 1 ) * imageWidth * bytesPerPixel;
85 pixbuffer[ pixelOffset + 3 ] = 0x00;
88 for ( unsigned int column = 0; column < imageHeight; ++column )
90 unsigned int pixelOffset = column * imageWidth * bytesPerPixel;
91 pixbuffer[ pixelOffset + 3 ] = 0x00;
92 pixelOffset += ( imageWidth -1 ) * bytesPerPixel;
93 pixbuffer[ pixelOffset + 3 ] = 0x00;
97 void AddStretchRegionsToImage( Integration::Bitmap* image, unsigned int imageWidth, unsigned int imageHeight, const StretchRanges& stretchRangesX, const StretchRanges& stretchRangesY, Pixel::Format pixelFormat )
99 PixelBuffer* pixbuffer = image->GetBuffer();
100 unsigned int bytesPerPixel = GetBytesPerPixel( pixelFormat );
102 for(StretchRanges::ConstIterator it = stretchRangesX.Begin(); it != stretchRangesX.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 column = range.GetX() + 1u; column < range.GetY() + 1u; ++column )
108 unsigned int pixelOffset = column * bytesPerPixel;
109 pixbuffer[ pixelOffset ] = 0x00;
110 pixbuffer[ pixelOffset + 1 ] = 0x00;
111 pixbuffer[ pixelOffset + 2 ] = 0x00;
112 pixbuffer[ pixelOffset + 3 ] = 0xFF;
117 for(StretchRanges::ConstIterator it = stretchRangesY.Begin(); it != stretchRangesY.End(); ++it)
119 const Uint16Pair& range = *it;
120 //since the stretch range is in the cropped image space, we need to offset by 1 to get it to the uncropped image space
121 for( unsigned int row = range.GetX() + 1u; row < range.GetY() + 1u; ++row )
123 unsigned int pixelOffset = row * imageWidth * bytesPerPixel;
124 pixbuffer[ pixelOffset ] = 0x00;
125 pixbuffer[ pixelOffset + 1 ] = 0x00;
126 pixbuffer[ pixelOffset + 2 ] = 0x00;
127 pixbuffer[ pixelOffset + 3 ] = 0xFF;
132 void AddChildRegionsToImage( Integration::Bitmap* image, unsigned int imageWidth, unsigned int imageHeight, const Vector4& requiredChildRegion, Pixel::Format pixelFormat )
134 PixelBuffer* pixbuffer = image->GetBuffer();
135 unsigned int bytesPerPixel = GetBytesPerPixel( pixelFormat );
137 Integration::Bitmap::PackedPixelsProfile* srcProfile = image->GetPackedPixelsProfile();
138 unsigned int bufferStride = srcProfile->GetBufferStride();
140 // Add bottom child region
141 for( unsigned int column = requiredChildRegion.x; column < imageWidth - requiredChildRegion.z; ++column )
143 unsigned int pixelOffset = column * bytesPerPixel;
144 pixelOffset += ( imageHeight - 1 ) * bufferStride;
145 pixbuffer[ pixelOffset ] = 0x00;
146 pixbuffer[ pixelOffset + 1 ] = 0x00;
147 pixbuffer[ pixelOffset + 2 ] = 0x00;
148 pixbuffer[ pixelOffset + 3 ] = 0xFF;
151 // Add right child region
152 for ( unsigned int row = requiredChildRegion.y; row < imageHeight - requiredChildRegion.w; ++row )
154 unsigned int pixelOffset = row * bufferStride + ( imageWidth - 1 ) * bytesPerPixel;
155 pixbuffer[ pixelOffset ] = 0x00;
156 pixbuffer[ pixelOffset + 1 ] = 0x00;
157 pixbuffer[ pixelOffset + 2 ] = 0x00;
158 pixbuffer[ pixelOffset + 3 ] = 0xFF;
162 Integration::ResourcePointer CustomizeNinePatch( TestApplication& application,
163 unsigned int ninePatchImageWidth,
164 unsigned int ninePatchImageHeight,
165 const StretchRanges& stretchRangesX,
166 const StretchRanges& stretchRangesY,
167 bool addChildRegion = false,
168 Vector4 requiredChildRegion = Vector4::ZERO )
170 TestPlatformAbstraction& platform = application.GetPlatform();
172 Pixel::Format pixelFormat = Pixel::RGBA8888;
174 tet_infoline("Create Bitmap");
175 platform.SetClosestImageSize(Vector2( ninePatchImageWidth, ninePatchImageHeight));
176 Integration::Bitmap* bitmap = CreateBitmap( ninePatchImageWidth, ninePatchImageHeight, 0xFF, pixelFormat );
178 tet_infoline("Clear border regions");
179 InitialiseRegionsToZeroAlpha( bitmap, ninePatchImageWidth, ninePatchImageHeight, pixelFormat );
181 tet_infoline("Add Stretch regions to Bitmap");
182 AddStretchRegionsToImage( bitmap, ninePatchImageWidth, ninePatchImageHeight, stretchRangesX, stretchRangesY, pixelFormat );
186 tet_infoline("Add Child regions to Bitmap");
187 AddChildRegionsToImage( bitmap, ninePatchImageWidth, ninePatchImageHeight, requiredChildRegion, pixelFormat );
190 tet_infoline("Getting resource");
191 Integration::ResourcePointer resourcePtr(bitmap);
192 //platform.SetResourceLoaded( 0, Dali::Integration::ResourceBitmap, resourcePtr );
193 platform.SetSynchronouslyLoadedResource( resourcePtr);
198 void TestVisualRender( ToolkitTestApplication& application,
200 Visual::Base& visual,
201 std::size_t expectedSamplers = 0,
202 ImageDimensions imageDimensions = ImageDimensions(),
203 Integration::ResourcePointer resourcePtr = Integration::ResourcePointer())
205 DummyControlImpl& dummyImpl = static_cast<DummyControlImpl&>(actor.GetImplementation());
206 dummyImpl.RegisterVisual( Control::CONTROL_PROPERTY_END_INDEX + 1, visual );
210 // set the image size, for test case, this needs to be set before loading started
211 application.GetPlatform().SetClosestImageSize( Vector2(imageDimensions.GetWidth(), imageDimensions.GetHeight()) );
214 actor.SetSize( 200.f, 200.f );
215 DALI_TEST_EQUALS( actor.GetRendererCount(), 0u, TEST_LOCATION );
217 Stage::GetCurrent().Add( actor );
219 application.SendNotification();
220 application.Render();
224 Integration::ResourceRequest* request = application.GetPlatform().GetRequest();
227 application.GetPlatform().SetResourceLoaded(request->GetId(), request->GetType()->id, resourcePtr );
231 application.Render();
232 application.SendNotification();
236 DALI_TEST_EQUALS( application.GetPlatform().WasCalled(TestPlatformAbstraction::LoadResourceFunc) ||
237 application.GetPlatform().WasCalled(TestPlatformAbstraction::LoadResourceSynchronouslyFunc ), true, TEST_LOCATION);
240 DALI_TEST_EQUALS( actor.GetRendererCount(), 1u, TEST_LOCATION );
247 void dali_visual_factory_startup(void)
249 test_return_value = TET_UNDEF;
252 void dali_visual_factory_cleanup(void)
254 test_return_value = TET_PASS;
257 int UtcDaliVisualFactoryGet(void)
259 ToolkitTestApplication application;
260 tet_infoline( "UtcDaliVisualFactory" );
264 type = TypeRegistry::Get().GetTypeInfo( "VisualFactory" );
265 DALI_TEST_CHECK( type );
266 BaseHandle handle = type.CreateInstance();
267 DALI_TEST_CHECK( handle );
269 VisualFactory factory;
270 factory = VisualFactory::Get();
271 DALI_TEST_CHECK( factory );
273 VisualFactory newFactory = VisualFactory::Get();
274 DALI_TEST_CHECK( newFactory );
276 // Check that visual factory is a singleton
277 DALI_TEST_CHECK(factory == newFactory);
282 int UtcDaliVisualFactoryCopyAndAssignment(void)
284 ToolkitTestApplication application;
285 tet_infoline( "UtcDaliVisualFactoryCopyAndAssignment" );
286 VisualFactory factory = VisualFactory::Get();
288 VisualFactory factoryCopy( factory );
289 DALI_TEST_CHECK(factory == factoryCopy);
291 VisualFactory emptyFactory;
292 VisualFactory emptyFactoryCopy( emptyFactory );
293 DALI_TEST_CHECK(emptyFactory == emptyFactoryCopy);
295 VisualFactory factoryEquals;
296 factoryEquals = factory;
297 DALI_TEST_CHECK(factory == factoryEquals);
299 VisualFactory emptyFactoryEquals;
300 emptyFactoryEquals = emptyFactory;
301 DALI_TEST_CHECK( emptyFactory == emptyFactoryEquals );
305 DALI_TEST_CHECK( factory = factoryCopy );
310 int UtcDaliVisualFactoryGetColorVisual1(void)
312 ToolkitTestApplication application;
313 tet_infoline( "UtcDaliVisualFactoryGetColorVisual1: Request color visual with a Property::Map" );
315 VisualFactory factory = VisualFactory::Get();
316 DALI_TEST_CHECK( factory );
318 Property::Map propertyMap;
319 Vector4 testColor( 1.f, 0.5f, 0.3f, 0.2f );
320 propertyMap.Insert(Visual::Property::TYPE, Visual::COLOR);
321 propertyMap.Insert(ColorVisual::Property::MIX_COLOR, testColor);
323 Visual::Base visual = factory.CreateVisual(propertyMap);
324 DALI_TEST_CHECK( visual );
326 DummyControl actor = DummyControl::New();
327 TestVisualRender( application, actor, visual );
329 Vector4 actualValue(Vector4::ZERO);
330 TestGlAbstraction& gl = application.GetGlAbstraction();
331 DALI_TEST_CHECK( gl.GetUniformValue<Vector4>( "mixColor", actualValue ) );
332 DALI_TEST_EQUALS( actualValue, testColor, TEST_LOCATION );
337 int UtcDaliVisualFactoryGetColorVisual2(void)
339 ToolkitTestApplication application;
340 tet_infoline( "UtcDaliVisualFactoryGetColorVisual2: Request color visual with a Vector4" );
342 VisualFactory factory = VisualFactory::Get();
343 DALI_TEST_CHECK( factory );
345 Vector4 testColor( 1.f, 0.5f, 0.3f, 0.2f );
346 Dali::Property::Map map;
347 map[ Visual::Property::TYPE ] = Visual::COLOR;
348 map[ ColorVisual::Property::MIX_COLOR ] = testColor;
349 Visual::Base visual = factory.CreateVisual( map );
350 DALI_TEST_CHECK( visual );
352 DummyControl actor = DummyControl::New();
353 TestVisualRender( application, actor, visual );
355 Vector4 actualValue(Vector4::ZERO);
356 TestGlAbstraction& gl = application.GetGlAbstraction();
357 DALI_TEST_CHECK( gl.GetUniformValue<Vector4>( "mixColor", actualValue ) );
358 DALI_TEST_EQUALS( actualValue, testColor, TEST_LOCATION );
360 Stage::GetCurrent().Remove(actor);
361 DALI_TEST_CHECK( actor.GetRendererCount() == 0u );
366 int UtcDaliVisualFactoryGetBorderVisual1(void)
368 ToolkitTestApplication application;
369 tet_infoline( "UtcDaliVisualFactoryGetBorderVisual1: Request border visual with a Property::Map" );
371 VisualFactory factory = VisualFactory::Get();
372 DALI_TEST_CHECK( factory );
374 Property::Map propertyMap;
375 Vector4 testColor( 1.f, 0.5f, 0.3f, 0.2f );
376 float testSize = 5.f;
377 propertyMap.Insert(Visual::Property::TYPE, Visual::BORDER);
378 propertyMap.Insert(BorderVisual::Property::COLOR, testColor);
379 propertyMap.Insert(BorderVisual::Property::SIZE, testSize);
381 Visual::Base visual = factory.CreateVisual(propertyMap);
382 DALI_TEST_CHECK( visual );
384 DummyControl actor = DummyControl::New();
385 DummyControlImpl& dummyImpl = static_cast<DummyControlImpl&>(actor.GetImplementation());
386 dummyImpl.RegisterVisual( Control::CONTROL_PROPERTY_END_INDEX + 1, visual );
387 actor.SetSize(200.f, 200.f);
388 Stage::GetCurrent().Add( actor );
389 visual.SetTransformAndSize(DefaultTransform(), Vector2(200.f, 200.f));
391 DALI_TEST_CHECK( actor.GetRendererCount() == 1u );
392 int blendMode = actor.GetRendererAt(0u).GetProperty<int>( Renderer::Property::BLEND_MODE );
393 DALI_TEST_EQUALS( static_cast<BlendMode::Type>(blendMode), BlendMode::ON, TEST_LOCATION );
395 TestGlAbstraction& gl = application.GetGlAbstraction();
397 application.SendNotification();
398 application.Render(0);
400 Vector4 actualColor(Vector4::ZERO);
401 DALI_TEST_CHECK( gl.GetUniformValue<Vector4>( "borderColor", actualColor ) );
402 DALI_TEST_EQUALS( actualColor, testColor, TEST_LOCATION );
404 float actualSize = 0.f;
405 DALI_TEST_CHECK( gl.GetUniformValue<float>( "borderSize", actualSize ) );
406 DALI_TEST_EQUALS( actualSize, testSize, TEST_LOCATION );
409 DALI_TEST_CHECK( actor.GetRendererCount() == 0u );
414 int UtcDaliVisualFactoryGetBorderVisual2(void)
416 ToolkitTestApplication application;
417 tet_infoline( "UtcDaliVisualFactoryGetBorderVisual2: Request border visual with a borderSize and a borderColor" );
419 VisualFactory factory = VisualFactory::Get();
420 DALI_TEST_CHECK( factory );
422 Vector4 testColor( 1.f, 0.5f, 0.3f, 1.f );
423 float testSize = 5.f;
425 Dali::Property::Map propertyMap;
426 propertyMap[ Visual::Property::TYPE ] = Visual::BORDER;
427 propertyMap[ BorderVisual::Property::COLOR ] = testColor;
428 propertyMap[ BorderVisual::Property::SIZE ] = testSize;
429 Visual::Base visual = factory.CreateVisual( propertyMap );
430 DALI_TEST_CHECK( visual );
432 DummyControl actor = DummyControl::New();
433 DummyControlImpl& dummyImpl = static_cast<DummyControlImpl&>(actor.GetImplementation());
434 dummyImpl.RegisterVisual( Control::CONTROL_PROPERTY_END_INDEX + 1, visual );
435 actor.SetSize(200.f, 200.f);
436 Stage::GetCurrent().Add( actor );
437 visual.SetTransformAndSize(DefaultTransform(), Vector2(200.f, 200.f));
439 DALI_TEST_CHECK( actor.GetRendererCount() == 1u );
441 TestGlAbstraction& gl = application.GetGlAbstraction();
443 application.SendNotification();
444 application.Render(0);
446 int blendMode = actor.GetRendererAt(0u).GetProperty<int>( Renderer::Property::BLEND_MODE );
447 DALI_TEST_EQUALS( static_cast<BlendMode::Type>(blendMode), BlendMode::AUTO, TEST_LOCATION );
449 Vector4 actualColor(Vector4::ZERO);
450 DALI_TEST_CHECK( gl.GetUniformValue<Vector4>( "borderColor", actualColor ) );
451 DALI_TEST_EQUALS( actualColor, testColor, TEST_LOCATION );
453 float actualSize = 0.f;
454 DALI_TEST_CHECK( gl.GetUniformValue<float>( "borderSize", actualSize ) );
455 DALI_TEST_EQUALS( actualSize, testSize, TEST_LOCATION );
459 // enable the anti-aliasing
460 Dali::Property::Map map;
461 map[ Visual::Property::TYPE ] = Visual::BORDER;
462 map[ BorderVisual::Property::COLOR ] = testColor;
463 map[ BorderVisual::Property::SIZE ] = testSize;
464 map[ BorderVisual::Property::ANTI_ALIASING ] = true;
465 visual = factory.CreateVisual( map );
467 dummyImpl.RegisterVisual( Control::CONTROL_PROPERTY_END_INDEX + 1, visual );
468 Stage::GetCurrent().Add( actor );
470 blendMode = actor.GetRendererAt(0u).GetProperty<int>( Renderer::Property::BLEND_MODE );
471 DALI_TEST_EQUALS( static_cast<BlendMode::Type>(blendMode), BlendMode::ON, TEST_LOCATION );
476 int UtcDaliVisualFactoryGetLinearGradientVisual(void)
478 ToolkitTestApplication application;
479 tet_infoline("UtcDaliVisualFactoryGetRadialGradientVisual");
481 VisualFactory factory = VisualFactory::Get();
482 DALI_TEST_CHECK( factory );
484 Property::Map propertyMap;
485 propertyMap.Insert(Visual::Property::TYPE, Visual::GRADIENT);
487 Vector2 start(-1.f, -1.f);
488 Vector2 end(1.f, 1.f);
489 propertyMap.Insert(GradientVisual::Property::START_POSITION, start);
490 propertyMap.Insert(GradientVisual::Property::END_POSITION, end);
491 propertyMap.Insert(GradientVisual::Property::SPREAD_METHOD, GradientVisual::SpreadMethod::REPEAT);
493 Property::Array stopOffsets;
494 stopOffsets.PushBack( 0.2f );
495 stopOffsets.PushBack( 0.8f );
496 propertyMap.Insert(GradientVisual::Property::STOP_OFFSET, stopOffsets);
498 Property::Array stopColors;
499 stopColors.PushBack( Color::RED );
500 stopColors.PushBack( Color::GREEN );
501 propertyMap.Insert(GradientVisual::Property::STOP_COLOR, stopColors);
503 Visual::Base visual = factory.CreateVisual(propertyMap);
504 DALI_TEST_CHECK( visual );
506 // A lookup texture is generated and pass to shader as sampler
507 DummyControl actor = DummyControl::New();
508 TestVisualRender( application, actor, visual, 1u);
513 int UtcDaliVisualFactoryGetRadialGradientVisual(void)
515 ToolkitTestApplication application;
516 tet_infoline("UtcDaliVisualFactoryGetRadialGradientVisual");
518 VisualFactory factory = VisualFactory::Get();
519 DALI_TEST_CHECK( factory );
521 Property::Map propertyMap;
522 propertyMap.Insert(Visual::Property::TYPE, Visual::GRADIENT);
524 Vector2 center(100.f, 100.f);
525 float radius = 100.f;
526 propertyMap.Insert(GradientVisual::Property::UNITS, GradientVisual::Units::USER_SPACE);
527 propertyMap.Insert(GradientVisual::Property::CENTER, center);
528 propertyMap.Insert(GradientVisual::Property::RADIUS, radius);
530 Property::Array stopOffsets;
531 stopOffsets.PushBack( 0.0f );
532 stopOffsets.PushBack( 1.f );
533 propertyMap.Insert(GradientVisual::Property::STOP_OFFSET, stopOffsets);
535 Property::Array stopColors;
536 stopColors.PushBack( Color::RED );
537 stopColors.PushBack( Color::GREEN );
538 propertyMap.Insert(GradientVisual::Property::STOP_COLOR, stopColors);
540 Visual::Base visual = factory.CreateVisual(propertyMap);
541 DALI_TEST_CHECK( visual );
543 // A lookup texture is generated and pass to shader as sampler
544 DummyControl actor = DummyControl::New();
545 TestVisualRender( application, actor, visual, 1u );
547 Matrix3 alignMatrix( radius, 0.f, 0.f, 0.f, radius, 0.f, center.x, center.y, 1.f );
548 alignMatrix.Invert();
550 Matrix3 actualValue( Matrix3::IDENTITY );
551 TestGlAbstraction& gl = application.GetGlAbstraction();
552 DALI_TEST_CHECK( gl.GetUniformValue<Matrix3>( "uAlignmentMatrix", actualValue ) );
553 DALI_TEST_EQUALS( actualValue, alignMatrix, Math::MACHINE_EPSILON_100, TEST_LOCATION );
558 int UtcDaliVisualFactoryDefaultOffsetsGradientVisual(void)
560 ToolkitTestApplication application;
561 tet_infoline("UtcDaliVisualFactoryGetRadialGradientVisual");
563 VisualFactory factory = VisualFactory::Get();
564 DALI_TEST_CHECK( factory );
566 Property::Map propertyMap;
567 propertyMap.Insert(Visual::Property::TYPE, Visual::GRADIENT);
569 Vector2 start(-1.f, -1.f);
570 Vector2 end(1.f, 1.f);
571 propertyMap.Insert(GradientVisual::Property::START_POSITION, start);
572 propertyMap.Insert(GradientVisual::Property::END_POSITION, end);
573 propertyMap.Insert(GradientVisual::Property::SPREAD_METHOD, GradientVisual::SpreadMethod::REPEAT);
575 Property::Array stopColors;
576 stopColors.PushBack( Color::RED );
577 stopColors.PushBack( Color::GREEN );
578 propertyMap.Insert(GradientVisual::Property::STOP_COLOR, stopColors);
580 Visual::Base visual = factory.CreateVisual(propertyMap);
581 DALI_TEST_CHECK( visual );
583 // A lookup texture is generated and pass to shader as sampler
584 DummyControl actor = DummyControl::New();
585 TestVisualRender( application, actor, visual, 1u );
587 Stage::GetCurrent().Remove( actor );
588 DALI_TEST_CHECK( actor.GetRendererCount() == 0u );
593 int UtcDaliVisualFactoryGetImageVisual1(void)
595 ToolkitTestApplication application;
596 tet_infoline( "UtcDaliVisualFactoryGetImageVisual1: Request image visual with a Property::Map" );
598 VisualFactory factory = VisualFactory::Get();
599 DALI_TEST_CHECK( factory );
601 Property::Map propertyMap;
602 propertyMap.Insert( Visual::Property::TYPE, Visual::IMAGE );
603 propertyMap.Insert( ImageVisual::Property::URL, TEST_IMAGE_FILE_NAME );
605 Visual::Base visual = factory.CreateVisual( propertyMap );
606 DALI_TEST_CHECK( visual );
608 // For tesing the LoadResourceFunc is called, a big image size should be set, so the atlasing is not applied.
609 // Image with a size smaller than 512*512 will be uploaded as a part of the atlas.
612 const int height=513;
613 TestGlAbstraction& gl = application.GetGlAbstraction();
614 TraceCallStack& textureTrace = gl.GetTextureTrace();
615 textureTrace.Enable(true);
617 Integration::Bitmap* bitmap = Integration::Bitmap::New( Integration::Bitmap::BITMAP_2D_PACKED_PIXELS, ResourcePolicy::OWNED_DISCARD );
618 bitmap->GetPackedPixelsProfile()->ReserveBuffer( Pixel::RGBA8888, width, height,width, height );
620 DummyControl actor = DummyControl::New();
621 TestVisualRender( application, actor, visual, 1u,
622 ImageDimensions(width, height),
623 Integration::ResourcePointer( bitmap ) );
625 DALI_TEST_EQUALS( textureTrace.FindMethod("BindTexture"), true, TEST_LOCATION );
627 Stage::GetCurrent().Remove( actor );
628 DALI_TEST_CHECK( actor.GetRendererCount() == 0u );
633 int UtcDaliVisualFactoryGetImageVisual2(void)
635 ToolkitTestApplication application;
636 tet_infoline( "UtcDaliVisualFactoryGetImageVisual2: Request image visual with an image handle" );
638 VisualFactory factory = VisualFactory::Get();
639 DALI_TEST_CHECK( factory );
641 Image image = ResourceImage::New(TEST_IMAGE_FILE_NAME);
642 Visual::Base visual = factory.CreateVisual( image );
644 // For tesing the LoadResourceFunc is called, a big image size should be set, so the atlasing is not applied.
645 // Image with a size smaller than 512*512 will be uploaded as a part of the atlas.
648 const int height=513;
650 Integration::Bitmap* bitmap = Integration::Bitmap::New( Integration::Bitmap::BITMAP_2D_PACKED_PIXELS, ResourcePolicy::OWNED_DISCARD );
651 bitmap->GetPackedPixelsProfile()->ReserveBuffer( Pixel::RGBA8888, width, height,width, height );
653 TestGlAbstraction& gl = application.GetGlAbstraction();
654 TraceCallStack& textureTrace = gl.GetTextureTrace();
655 textureTrace.Enable(true);
657 DummyControl actor = DummyControl::New();
658 TestVisualRender( application, actor, visual, 1u,
659 ImageDimensions(width, height),
660 Integration::ResourcePointer(bitmap) );
662 DALI_TEST_EQUALS( textureTrace.FindMethod("BindTexture"), true, TEST_LOCATION );
666 int UtcDaliVisualFactoryGetImageVisual3(void)
668 ToolkitTestApplication application;
669 tet_infoline( "UtcDaliVisualFactoryGetImageVisual3: Request image visual with a Property::Map, test custom wrap mode and pixel area with atlasing" );
671 VisualFactory factory = VisualFactory::Get();
672 DALI_TEST_CHECK( factory );
674 // Test wrap mode with atlasing. Image with a size smaller than 512*512 will be uploaded as a part of the atlas.
677 const Vector4 pixelArea(-0.5f, -0.5f, 2.f, 2.f);
679 Property::Map propertyMap;
680 propertyMap.Insert( Visual::Property::TYPE, Visual::IMAGE );
681 propertyMap.Insert( ImageVisual::Property::URL, gImage_34_RGBA );
682 propertyMap.Insert( ImageVisual::Property::DESIRED_WIDTH, width );
683 propertyMap.Insert( ImageVisual::Property::DESIRED_HEIGHT, height );
684 propertyMap.Insert( ImageVisual::Property::SYNCHRONOUS_LOADING, true );
685 propertyMap.Insert( ImageVisual::Property::PIXEL_AREA, pixelArea );
686 propertyMap.Insert( ImageVisual::Property::WRAP_MODE_U, WrapMode::MIRRORED_REPEAT );
687 propertyMap.Insert( ImageVisual::Property::WRAP_MODE_V, WrapMode::REPEAT );
689 Visual::Base visual = factory.CreateVisual( propertyMap );
690 DALI_TEST_CHECK( visual );
692 TestGlAbstraction& gl = application.GetGlAbstraction();
693 TraceCallStack& textureTrace = gl.GetTextureTrace();
694 textureTrace.Enable(true);
695 TraceCallStack& texParameterTrace = gl.GetTexParameterTrace();
696 texParameterTrace.Enable( true );
698 DummyControl actor = DummyControl::New();
699 DummyControlImpl& dummyImpl = static_cast<DummyControlImpl&>(actor.GetImplementation());
700 dummyImpl.RegisterVisual( Control::CONTROL_PROPERTY_END_INDEX + 1, visual );
701 actor.SetSize(2000, 2000);
702 actor.SetParentOrigin(ParentOrigin::CENTER);
703 Stage::GetCurrent().Add( actor );
706 application.SendNotification();
707 application.Render();
708 application.Render();
709 application.SendNotification();
710 BitmapLoader loader = BitmapLoader::GetLatestCreated();
711 DALI_TEST_CHECK( loader );
712 loader.WaitForLoading();// waiting until the image to be loaded
713 DALI_TEST_CHECK( loader.IsLoaded() );
715 DALI_TEST_CHECK( actor.GetRendererCount() == 1u );
717 DALI_TEST_EQUALS( textureTrace.FindMethod("BindTexture"), true, TEST_LOCATION );
719 // WITH atlasing, the wrapping is handled manually in shader, so the following gl function should not be called
720 std::stringstream out;
721 out << GL_TEXTURE_2D << ", " << GL_TEXTURE_WRAP_S << ", " << GL_MIRRORED_REPEAT;
722 DALI_TEST_CHECK( !texParameterTrace.FindMethodAndParams("TexParameteri", out.str()) );
724 out << GL_TEXTURE_2D << ", " << GL_TEXTURE_WRAP_T << ", " << GL_REPEAT;
725 DALI_TEST_CHECK( !texParameterTrace.FindMethodAndParams("TexParameteri", out.str()) );
727 // test the uniforms which used to handle the wrap mode
728 Renderer renderer = actor.GetRendererAt( 0u );
729 DALI_TEST_CHECK( renderer );
731 Property::Value pixelAreaValue = renderer.GetProperty( renderer.GetPropertyIndex( "pixelArea" ) );
732 DALI_TEST_EQUALS( pixelAreaValue.Get<Vector4>(), pixelArea, TEST_LOCATION );
733 Vector4 pixelAreaUniform;
734 DALI_TEST_CHECK( gl.GetUniformValue<Vector4>( "pixelArea", pixelAreaUniform ) );
735 DALI_TEST_EQUALS( pixelArea, pixelAreaUniform, Math::MACHINE_EPSILON_100, TEST_LOCATION );
737 Property::Value wrapModeValue = renderer.GetProperty( renderer.GetPropertyIndex( "wrapMode" ) );
738 Vector2 wrapMode( WrapMode::MIRRORED_REPEAT-1, WrapMode::REPEAT-1 );
739 DALI_TEST_EQUALS( wrapModeValue.Get<Vector2>(), wrapMode, TEST_LOCATION );
740 Vector2 wrapModeUniform;
741 DALI_TEST_CHECK( gl.GetUniformValue<Vector2>( "wrapMode", wrapModeUniform ) );
742 DALI_TEST_EQUALS( wrapMode, wrapModeUniform, Math::MACHINE_EPSILON_100, TEST_LOCATION );
745 DALI_TEST_CHECK( actor.GetRendererCount() == 0u );
750 int UtcDaliVisualFactoryGetImageVisual4(void)
752 ToolkitTestApplication application;
753 tet_infoline( "UtcDaliVisualFactoryGetImageVisual4: Request image visual with a Property::Map, test custom wrap mode and pixel area without atlasing" );
755 VisualFactory factory = VisualFactory::Get();
756 DALI_TEST_CHECK( factory );
758 // Test wrap mode without atlasing. Image with a size bigger than 512*512 will NOT be uploaded as a part of the atlas.
760 const int height=600;
761 const Vector4 pixelArea(-0.5f, -0.5f, 2.f, 2.f);
763 Property::Map propertyMap;
764 propertyMap.Insert( Visual::Property::TYPE, Visual::IMAGE );
765 propertyMap.Insert( ImageVisual::Property::URL, gImage_600_RGB );
766 propertyMap.Insert( ImageVisual::Property::DESIRED_WIDTH, width );
767 propertyMap.Insert( ImageVisual::Property::DESIRED_HEIGHT, height );
768 propertyMap.Insert( ImageVisual::Property::SYNCHRONOUS_LOADING, true );
769 propertyMap.Insert( ImageVisual::Property::PIXEL_AREA, pixelArea );
770 propertyMap.Insert( ImageVisual::Property::WRAP_MODE_U, WrapMode::MIRRORED_REPEAT );
771 propertyMap.Insert( ImageVisual::Property::WRAP_MODE_V, WrapMode::REPEAT );
773 Visual::Base visual = factory.CreateVisual( propertyMap );
774 DALI_TEST_CHECK( visual );
776 TestGlAbstraction& gl = application.GetGlAbstraction();
777 TraceCallStack& textureTrace = gl.GetTextureTrace();
778 textureTrace.Enable(true);
779 TraceCallStack& texParameterTrace = gl.GetTexParameterTrace();
780 texParameterTrace.Enable( true );
782 DummyControl actor = DummyControl::New();
783 DummyControlImpl& dummyImpl = static_cast<DummyControlImpl&>(actor.GetImplementation());
784 dummyImpl.RegisterVisual( Control::CONTROL_PROPERTY_END_INDEX + 1, visual );
785 actor.SetSize(2000, 2000);
786 actor.SetParentOrigin(ParentOrigin::CENTER);
787 Stage::GetCurrent().Add( actor );
790 application.SendNotification();
791 application.Render();
792 application.Render();
793 application.SendNotification();
794 BitmapLoader loader = BitmapLoader::GetLatestCreated();
795 DALI_TEST_CHECK( loader );
796 loader.WaitForLoading();// waiting until the image to be loaded
797 DALI_TEST_CHECK( loader.IsLoaded() );
799 DALI_TEST_CHECK( actor.GetRendererCount() == 1u );
801 DALI_TEST_EQUALS( textureTrace.FindMethod("BindTexture"), true, TEST_LOCATION );
803 // WITHOUT atlasing, the wrapping is handled by setting gl texture parameters
804 std::stringstream out;
805 out << GL_TEXTURE_2D << ", " << GL_TEXTURE_WRAP_S << ", " << GL_MIRRORED_REPEAT;
806 DALI_TEST_CHECK( texParameterTrace.FindMethodAndParams("TexParameteri", out.str()) );
808 out << GL_TEXTURE_2D << ", " << GL_TEXTURE_WRAP_T << ", " << GL_REPEAT;
809 DALI_TEST_CHECK( texParameterTrace.FindMethodAndParams("TexParameteri", out.str()) );
811 // test the uniforms which used to handle the wrap mode
812 Renderer renderer = actor.GetRendererAt( 0u );
813 DALI_TEST_CHECK( renderer );
815 Property::Value pixelAreaValue = renderer.GetProperty( renderer.GetPropertyIndex( "pixelArea" ) );
816 DALI_TEST_EQUALS( pixelAreaValue.Get<Vector4>(), pixelArea, TEST_LOCATION );
817 Vector4 pixelAreaUniform;
818 DALI_TEST_CHECK( gl.GetUniformValue<Vector4>( "pixelArea", pixelAreaUniform ) );
819 DALI_TEST_EQUALS( pixelArea, pixelAreaUniform, Math::MACHINE_EPSILON_100, TEST_LOCATION );
821 Property::Index wrapModeIndex = renderer.GetPropertyIndex( "wrapMode" );
822 DALI_TEST_CHECK(wrapModeIndex == Property::INVALID_INDEX);
825 DALI_TEST_CHECK( actor.GetRendererCount() == 0u );
830 int UtcDaliVisualFactoryGetNPatchVisual1(void)
832 ToolkitTestApplication application;
833 tet_infoline( "UtcDaliVisualFactoryGetNPatchVisual1: Request 9-patch visual with a Property::Map" );
835 VisualFactory factory = VisualFactory::Get();
836 DALI_TEST_CHECK( factory );
838 const unsigned int ninePatchImageHeight = 18;
839 const unsigned int ninePatchImageWidth = 28;
840 StretchRanges stretchRangesX;
841 stretchRangesX.PushBack( Uint16Pair( 2, 3 ) );
842 StretchRanges stretchRangesY;
843 stretchRangesY.PushBack( Uint16Pair( 4, 5 ) );
844 Integration::ResourcePointer ninePatchResource = CustomizeNinePatch( application, ninePatchImageWidth, ninePatchImageHeight, stretchRangesX, stretchRangesY );
846 Property::Map propertyMap;
847 propertyMap.Insert( Visual::Property::TYPE, Visual::IMAGE );
848 propertyMap.Insert( ImageVisual::Property::URL, TEST_NPATCH_FILE_NAME );
850 tet_infoline( "whole grid" );
851 Visual::Base visual = factory.CreateVisual( propertyMap );
852 DALI_TEST_CHECK( visual );
855 TestGlAbstraction& gl = application.GetGlAbstraction();
856 TraceCallStack& textureTrace = gl.GetTextureTrace();
857 textureTrace.Enable(true);
859 DummyControl actor = DummyControl::New();
860 TestVisualRender( application, actor, visual, 1u,
861 ImageDimensions(ninePatchImageWidth, ninePatchImageHeight),
864 DALI_TEST_EQUALS( textureTrace.FindMethod("BindTexture"), true, TEST_LOCATION );
867 propertyMap.Insert( ImageVisual::Property::BORDER_ONLY, true );
869 tet_infoline( "border only" );
870 Visual::Base visual = factory.CreateVisual( propertyMap );
871 DALI_TEST_CHECK( visual );
873 TestGlAbstraction& gl = application.GetGlAbstraction();
874 TraceCallStack& textureTrace = gl.GetTextureTrace();
875 textureTrace.Enable(true);
877 DummyControl actor = DummyControl::New();
878 TestVisualRender( application, actor, visual, 1u,
879 ImageDimensions(ninePatchImageWidth, ninePatchImageHeight),
882 DALI_TEST_EQUALS( textureTrace.FindMethod("BindTexture"), true, TEST_LOCATION );
888 int UtcDaliVisualFactoryGetNPatchVisual2(void)
890 ToolkitTestApplication application;
891 tet_infoline( "UtcDaliVisualFactoryGetNPatchVisual2: Request n-patch visual with a Property::Map" );
893 VisualFactory factory = VisualFactory::Get();
894 DALI_TEST_CHECK( factory );
896 const unsigned int ninePatchImageWidth = 18;
897 const unsigned int ninePatchImageHeight = 28;
898 StretchRanges stretchRangesX;
899 stretchRangesX.PushBack( Uint16Pair( 2, 3 ) );
900 stretchRangesX.PushBack( Uint16Pair( 5, 7 ) );
901 stretchRangesX.PushBack( Uint16Pair( 12, 15 ) );
902 StretchRanges stretchRangesY;
903 stretchRangesY.PushBack( Uint16Pair( 4, 5 ) );
904 stretchRangesY.PushBack( Uint16Pair( 8, 12 ) );
905 stretchRangesY.PushBack( Uint16Pair( 15, 16 ) );
906 stretchRangesY.PushBack( Uint16Pair( 25, 27 ) );
907 Integration::ResourcePointer ninePatchResource = CustomizeNinePatch( application, ninePatchImageWidth, ninePatchImageHeight, stretchRangesX, stretchRangesY );
909 Property::Map propertyMap;
910 propertyMap.Insert( Visual::Property::TYPE, Visual::IMAGE );
911 propertyMap.Insert( ImageVisual::Property::URL, TEST_NPATCH_FILE_NAME );
913 Visual::Base visual = factory.CreateVisual( propertyMap );
914 DALI_TEST_CHECK( visual );
916 TestGlAbstraction& gl = application.GetGlAbstraction();
917 TraceCallStack& textureTrace = gl.GetTextureTrace();
918 textureTrace.Enable(true);
920 DummyControl actor = DummyControl::New();
921 TestVisualRender( application, actor, visual, 1u,
922 ImageDimensions(ninePatchImageWidth, ninePatchImageHeight),
925 DALI_TEST_EQUALS( textureTrace.FindMethod("BindTexture"), true, TEST_LOCATION );
927 Stage::GetCurrent().Remove( actor );
928 DALI_TEST_CHECK( actor.GetRendererCount() == 0u );
931 propertyMap.Insert( ImageVisual::Property::BORDER_ONLY, true );
933 tet_infoline( "border only" );
934 Visual::Base visual = factory.CreateVisual( propertyMap );
935 DALI_TEST_CHECK( visual );
937 TestGlAbstraction& gl = application.GetGlAbstraction();
938 TraceCallStack& textureTrace = gl.GetTextureTrace();
939 textureTrace.Enable(true);
940 DummyControl actor = DummyControl::New();
941 TestVisualRender( application, actor, visual, 1u,
942 ImageDimensions(ninePatchImageWidth, ninePatchImageHeight),
946 DALI_TEST_EQUALS( textureTrace.FindMethod("BindTexture"), true, TEST_LOCATION );
948 Stage::GetCurrent().Remove( actor );
949 DALI_TEST_CHECK( actor.GetRendererCount() == 0u );
955 int UtcDaliVisualFactoryGetNPatchVisual3(void)
957 ToolkitTestApplication application;
958 tet_infoline( "UtcDaliVisualFactoryGetNPatchVisual3: Request 9-patch visual with an image url" );
960 VisualFactory factory = VisualFactory::Get();
961 DALI_TEST_CHECK( factory );
963 const unsigned int ninePatchImageHeight = 18;
964 const unsigned int ninePatchImageWidth = 28;
965 StretchRanges stretchRangesX;
966 stretchRangesX.PushBack( Uint16Pair( 2, 3 ) );
967 StretchRanges stretchRangesY;
968 stretchRangesY.PushBack( Uint16Pair( 4, 5 ) );
969 Integration::ResourcePointer ninePatchResource = CustomizeNinePatch( application, ninePatchImageWidth, ninePatchImageHeight, stretchRangesX, stretchRangesY );
971 Visual::Base visual = factory.CreateVisual( TEST_NPATCH_FILE_NAME, ImageDimensions() );
972 DALI_TEST_CHECK( visual );
974 TestGlAbstraction& gl = application.GetGlAbstraction();
975 TraceCallStack& textureTrace = gl.GetTextureTrace();
976 textureTrace.Enable(true);
978 DummyControl actor = DummyControl::New();
979 TestVisualRender( application, actor, visual, 1u,
980 ImageDimensions(ninePatchImageWidth, ninePatchImageHeight),
983 DALI_TEST_EQUALS( textureTrace.FindMethod("BindTexture"), true, TEST_LOCATION );
986 ResourceImage image = ResourceImage::New(TEST_NPATCH_FILE_NAME);
987 Visual::Base nPatchVisual = factory.CreateVisual( image );
988 Vector2 controlSize( 20.f, 30.f ), naturalSize(0,0);
989 nPatchVisual.SetTransformAndSize(DefaultTransform(), controlSize );
990 nPatchVisual.GetNaturalSize( naturalSize );
991 DALI_TEST_EQUALS( naturalSize, Vector2( ninePatchImageWidth-2, ninePatchImageHeight-2 ), TEST_LOCATION );
996 int UtcDaliVisualFactoryGetNPatchVisual4(void)
998 ToolkitTestApplication application;
999 tet_infoline( "UtcDaliVisualFactoryGetNPatchVisual4: Request n-patch visual with an image url" );
1001 VisualFactory factory = VisualFactory::Get();
1002 DALI_TEST_CHECK( factory );
1004 const unsigned int ninePatchImageHeight = 18;
1005 const unsigned int ninePatchImageWidth = 28;
1006 StretchRanges stretchRangesX;
1007 stretchRangesX.PushBack( Uint16Pair( 2, 3 ) );
1008 stretchRangesX.PushBack( Uint16Pair( 5, 7 ) );
1009 stretchRangesX.PushBack( Uint16Pair( 12, 15 ) );
1010 StretchRanges stretchRangesY;
1011 stretchRangesY.PushBack( Uint16Pair( 4, 5 ) );
1012 stretchRangesY.PushBack( Uint16Pair( 8, 12 ) );
1013 stretchRangesY.PushBack( Uint16Pair( 15, 16 ) );
1014 stretchRangesY.PushBack( Uint16Pair( 25, 27 ) );
1015 Integration::ResourcePointer ninePatchResource = CustomizeNinePatch( application, ninePatchImageWidth, ninePatchImageHeight, stretchRangesX, stretchRangesY );
1017 Visual::Base visual = factory.CreateVisual( TEST_NPATCH_FILE_NAME, ImageDimensions() );
1018 DALI_TEST_CHECK( visual );
1020 TestGlAbstraction& gl = application.GetGlAbstraction();
1021 TraceCallStack& textureTrace = gl.GetTextureTrace();
1022 textureTrace.Enable(true);
1024 DummyControl actor = DummyControl::New();
1025 TestVisualRender( application, actor, visual, 1u,
1026 ImageDimensions(ninePatchImageWidth, ninePatchImageHeight),
1027 ninePatchResource );
1029 DALI_TEST_EQUALS( textureTrace.FindMethod("BindTexture"), true, TEST_LOCATION );
1034 int UtcDaliVisualFactoryGetNPatchVisualN1(void)
1036 //This should still load but display an error image
1038 ToolkitTestApplication application;
1039 tet_infoline( "UtcDaliVisualFactoryGetNPatchVisualN: Request n-patch visual with an invalid image url" );
1041 VisualFactory factory = VisualFactory::Get();
1042 DALI_TEST_CHECK( factory );
1044 Visual::Base visual = factory.CreateVisual( "ERROR.9.jpg", ImageDimensions() );
1045 DALI_TEST_CHECK( visual );
1047 //The testkit still has to load a bitmap for the broken renderer image
1048 Integration::Bitmap* bitmap = Integration::Bitmap::New(Integration::Bitmap::BITMAP_2D_PACKED_PIXELS, ResourcePolicy::OWNED_DISCARD);
1049 bitmap->GetPackedPixelsProfile()->ReserveBuffer( Pixel::RGBA8888, 100, 100, 100, 100 );
1051 TestGlAbstraction& gl = application.GetGlAbstraction();
1052 TraceCallStack& textureTrace = gl.GetTextureTrace();
1053 textureTrace.Enable(true);
1055 DummyControl actor = DummyControl::New();
1056 TestVisualRender( application, actor, visual, 1u,
1058 Integration::ResourcePointer(bitmap) );
1060 DALI_TEST_EQUALS( textureTrace.FindMethod("BindTexture"), true, TEST_LOCATION );
1065 int UtcDaliVisualFactoryGetNPatchVisualN2(void)
1067 //This should still load but display an error image
1069 ToolkitTestApplication application;
1070 tet_infoline( "UtcDaliVisualFactoryGetNPatchVisualN: Request n-patch visual with an invalid URL" );
1072 VisualFactory factory = VisualFactory::Get();
1073 DALI_TEST_CHECK( factory );
1075 Property::Map propertyMap;
1076 propertyMap.Insert( Visual::Property::TYPE, Visual::IMAGE );
1077 propertyMap.Insert( ImageVisual::Property::URL, "ERROR.9.jpg" );
1079 Visual::Base visual = factory.CreateVisual( propertyMap );
1080 DALI_TEST_CHECK( visual );
1082 //The testkit still has to load a bitmap for the broken renderer image
1083 Integration::Bitmap* bitmap = Integration::Bitmap::New(Integration::Bitmap::BITMAP_2D_PACKED_PIXELS, ResourcePolicy::OWNED_DISCARD);
1084 bitmap->GetPackedPixelsProfile()->ReserveBuffer( Pixel::RGBA8888, 100, 100, 100, 100 );
1086 TestGlAbstraction& gl = application.GetGlAbstraction();
1087 TraceCallStack& textureTrace = gl.GetTextureTrace();
1088 textureTrace.Enable(true);
1089 TraceCallStack& drawTrace = gl.GetDrawTrace();
1090 drawTrace.Enable(true);
1092 DummyControl actor = DummyControl::New();
1093 TestVisualRender( application, actor, visual, 1u,
1095 Integration::ResourcePointer(bitmap) );
1097 DALI_TEST_EQUALS( textureTrace.FindMethod("BindTexture"), true, TEST_LOCATION );
1102 int UtcDaliVisualFactoryGetNPatchVisualN3(void)
1104 // Passing in an invalid visual type so we should not get a visual
1106 ToolkitTestApplication application;
1107 tet_infoline( "UtcDaliVisualFactoryGetNPatchVisualN: Request n-patch visual with an invalid visual type" );
1109 VisualFactory factory = VisualFactory::Get();
1110 DALI_TEST_CHECK( factory );
1112 Property::Map propertyMap;
1113 propertyMap.Insert( Visual::Property::TYPE, 111 );
1114 propertyMap.Insert( ImageVisual::Property::URL, "ERROR.9.jpg" );
1116 Visual::Base visual = factory.CreateVisual( propertyMap );
1117 DALI_TEST_CHECK( !visual );
1122 int UtcDaliVisualFactoryGetSvgVisual(void)
1124 ToolkitTestApplication application;
1125 tet_infoline( "UtcDaliVisualFactoryGetSvgVisual: Request svg visual with a svg url" );
1127 VisualFactory factory = VisualFactory::Get();
1128 Visual::Base visual = factory.CreateVisual( TEST_SVG_FILE_NAME, ImageDimensions() );
1129 DALI_TEST_CHECK( visual );
1131 TestGlAbstraction& gl = application.GetGlAbstraction();
1132 TraceCallStack& textureTrace = gl.GetTextureTrace();
1133 textureTrace.Enable(true);
1135 DummyControl actor = DummyControl::New();
1136 DummyControlImpl& dummyImpl = static_cast<DummyControlImpl&>(actor.GetImplementation());
1137 dummyImpl.RegisterVisual( Control::CONTROL_PROPERTY_END_INDEX + 1, visual );
1138 actor.SetSize( 200.f, 200.f );
1139 Stage::GetCurrent().Add( actor );
1140 visual.SetTransformAndSize(DefaultTransform(), Vector2(200.f, 200.f) );
1142 application.SendNotification();
1143 application.Render();
1145 // renderer is not added to actor until the rasterization is completed.
1146 DALI_TEST_CHECK( actor.GetRendererCount() == 0u );
1148 DALI_TEST_EQUALS( Test::WaitForEventThreadTrigger( 1 ), true, TEST_LOCATION );
1150 // renderer is added to actor
1151 DALI_TEST_CHECK( actor.GetRendererCount() == 1u );
1153 // waiting for the resource uploading
1154 application.SendNotification();
1155 application.Render();
1157 DALI_TEST_EQUALS( textureTrace.FindMethod("BindTexture"), true, TEST_LOCATION );
1162 int UtcDaliVisualFactoryGetSvgVisualLarge(void)
1164 ToolkitTestApplication application;
1165 tet_infoline( "UtcDaliVisualFactoryGetSvgVisual: Request svg visual with a svg url" );
1167 VisualFactory factory = VisualFactory::Get();
1168 Visual::Base visual = factory.CreateVisual( TEST_SVG_FILE_NAME, ImageDimensions( 2000, 2000 ) );
1169 DALI_TEST_CHECK( visual );
1171 TestGlAbstraction& gl = application.GetGlAbstraction();
1172 TraceCallStack& textureTrace = gl.GetTextureTrace();
1173 textureTrace.Enable(true);
1175 DummyControl actor = DummyControl::New(true);
1176 DummyControlImpl& dummyImpl = static_cast<DummyControlImpl&>(actor.GetImplementation());
1177 actor.SetResizePolicy( ResizePolicy::FILL_TO_PARENT, Dimension::ALL_DIMENSIONS ); // Only rasterizes when it knows control size.
1178 dummyImpl.RegisterVisual( Control::CONTROL_PROPERTY_END_INDEX + 1, visual );
1179 Stage::GetCurrent().Add( actor );
1181 application.SendNotification();
1182 application.Render();
1184 // renderer is not added to actor until the rasterization is completed.
1185 DALI_TEST_CHECK( actor.GetRendererCount() == 0u );
1187 DALI_TEST_EQUALS( Test::WaitForEventThreadTrigger( 1 ), true, TEST_LOCATION );
1189 // renderer is added to actor
1190 DALI_TEST_CHECK( actor.GetRendererCount() == 1u );
1192 // waiting for the resource uploading
1193 application.SendNotification();
1194 application.Render();
1196 DALI_TEST_EQUALS( textureTrace.FindMethod("BindTexture"), true, TEST_LOCATION );
1201 //Creates a mesh visual from the given propertyMap and tries to load it on stage in the given application.
1202 //This is expected to succeed, which will then pass the test.
1203 void MeshVisualLoadsCorrectlyTest( Property::Map& propertyMap, ToolkitTestApplication& application )
1205 VisualFactory factory = VisualFactory::Get();
1206 DALI_TEST_CHECK( factory );
1208 //Create a mesh visual.
1209 Visual::Base visual = factory.CreateVisual( propertyMap );
1210 DALI_TEST_CHECK( visual );
1212 //Create an actor on stage to house the visual.
1213 DummyControl actor = DummyControl::New();
1214 DummyControlImpl& dummyImpl = static_cast<DummyControlImpl&>(actor.GetImplementation());
1215 dummyImpl.RegisterVisual( Control::CONTROL_PROPERTY_END_INDEX + 1, visual );
1216 actor.SetSize( 200.f, 200.f );
1217 Stage::GetCurrent().Add( actor );
1218 visual.SetTransformAndSize(DefaultTransform(), Vector2( 200.f, 200.f ) );
1220 //Ensure set on stage.
1221 DALI_TEST_EQUALS( actor.GetRendererCount(), 1u, TEST_LOCATION );
1223 //Attempt to render to queue resource load requests.
1224 application.SendNotification();
1225 application.Render( 0 );
1227 //Tell the platform abstraction that the required resources have been loaded.
1228 TestPlatformAbstraction& platform = application.GetPlatform();
1229 platform.SetAllResourceRequestsAsLoaded();
1231 //Render again to upload the now-loaded textures.
1232 application.SendNotification();
1233 application.Render( 0 );
1235 Matrix testScaleMatrix;
1236 testScaleMatrix.SetIdentityAndScale( Vector3( 1.0, -1.0, 1.0 ) );
1237 Matrix actualScaleMatrix;
1239 //Test to see if the object has been successfully loaded.
1240 DALI_TEST_CHECK( application.GetGlAbstraction().GetUniformValue<Matrix>( "uObjectMatrix", actualScaleMatrix ) );
1241 DALI_TEST_EQUALS( actualScaleMatrix, testScaleMatrix, Math::MACHINE_EPSILON_100, TEST_LOCATION );
1243 //Finish by setting off stage, and ensuring this was successful.
1245 DALI_TEST_EQUALS( actor.GetRendererCount(), 0u, TEST_LOCATION );
1248 //Creates a mesh visual from the given propertyMap and tries to load it on stage in the given application.
1249 //This is expected to fail, which will then pass the test.
1250 void MeshVisualDoesNotLoadCorrectlyTest( Property::Map& propertyMap, ToolkitTestApplication& application )
1252 VisualFactory factory = VisualFactory::Get();
1253 DALI_TEST_CHECK( factory );
1255 //Create a mesh visual.
1256 Visual::Base visual = factory.CreateVisual( propertyMap );
1257 DALI_TEST_CHECK( visual );
1259 //Create an actor on stage to house the visual.
1260 DummyControl actor = DummyControl::New();
1261 DummyControlImpl& dummyImpl = static_cast<DummyControlImpl&>(actor.GetImplementation());
1262 dummyImpl.RegisterVisual( Control::CONTROL_PROPERTY_END_INDEX + 1, visual );
1263 actor.SetSize( 200.f, 200.f );
1264 Stage::GetCurrent().Add( actor );
1265 visual.SetTransformAndSize(DefaultTransform(), Vector2( 200.f, 200.f ) );
1267 //Ensure set on stage.
1268 DALI_TEST_EQUALS( actor.GetRendererCount(), 1u, TEST_LOCATION );
1270 //Attempt to render to queue resource load requests.
1271 application.SendNotification();
1272 application.Render( 0 );
1274 //Tell the platform abstraction that the required resources have been loaded.
1275 TestPlatformAbstraction& platform = application.GetPlatform();
1276 platform.SetAllResourceRequestsAsLoaded();
1278 //Render again to upload the now-loaded textures.
1279 application.SendNotification();
1280 application.Render( 0 );
1282 //Test to see if the object has not been loaded, as expected.
1284 DALI_TEST_CHECK( !application.GetGlAbstraction().GetUniformValue<Matrix>( "uObjectMatrix", scaleMatrix ) );
1286 //Finish by setting off stage, and ensuring this was successful.
1288 DALI_TEST_EQUALS( actor.GetRendererCount(), 0u, TEST_LOCATION );
1291 //Test if mesh loads correctly when supplied with only the bare minimum requirements, an object file.
1292 int UtcDaliVisualFactoryGetMeshVisual1(void)
1294 //Set up test application first, so everything else can be handled.
1295 ToolkitTestApplication application;
1297 tet_infoline( "UtcDaliVisualFactoryGetMeshVisual1: Request mesh visual with a valid object file only" );
1300 //Set up visual properties.
1301 Property::Map propertyMap;
1302 propertyMap.Insert( Visual::Property::TYPE, Visual::MESH );
1303 propertyMap.Insert( MeshVisual::Property::OBJECT_URL, TEST_OBJ_FILE_NAME );
1305 //Test to see if mesh loads correctly.
1306 MeshVisualLoadsCorrectlyTest( propertyMap, application );
1312 //Test if mesh loads correctly when supplied with an object file as well as a blank material file and images directory.
1313 int UtcDaliVisualFactoryGetMeshVisual2(void)
1315 //Set up test application first, so everything else can be handled.
1316 ToolkitTestApplication application;
1318 tet_infoline( "UtcDaliVisualFactoryGetMeshVisual2: Request mesh visual with blank material file and images directory" );
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, "" );
1325 propertyMap.Insert( MeshVisual::Property::TEXTURES_PATH, "" );
1327 //Test to see if mesh loads correctly.
1328 MeshVisualLoadsCorrectlyTest( propertyMap, application );
1333 //Test if mesh loads correctly when supplied with all main parameters, an object file, a material file and a directory location.
1334 int UtcDaliVisualFactoryGetMeshVisual3(void)
1336 //Set up test application first, so everything else can be handled.
1337 ToolkitTestApplication application;
1339 tet_infoline( "UtcDaliVisualFactoryGetMeshVisual3: Request mesh visual with all parameters correct" );
1341 //Set up visual properties.
1342 Property::Map propertyMap;
1343 propertyMap.Insert( Visual::Property::TYPE, Visual::MESH );
1344 propertyMap.Insert( MeshVisual::Property::OBJECT_URL, TEST_OBJ_FILE_NAME );
1345 propertyMap.Insert( MeshVisual::Property::MATERIAL_URL, TEST_MTL_FILE_NAME );
1346 propertyMap.Insert( MeshVisual::Property::TEXTURES_PATH, TEST_RESOURCE_DIR "/" );
1348 //Test to see if mesh loads correctly.
1349 MeshVisualLoadsCorrectlyTest( propertyMap, application );
1354 //Test if mesh visual can load a correctly supplied mesh without a normal map or gloss map in the material file.
1355 int UtcDaliVisualFactoryGetMeshVisual4(void)
1357 //Set up test application first, so everything else can be handled.
1358 ToolkitTestApplication application;
1360 tet_infoline( "UtcDaliVisualFactoryGetMeshVisual4: Request mesh visual with diffuse texture but not normal or gloss." );
1363 //Set up visual properties.
1364 Property::Map propertyMap;
1365 propertyMap.Insert( Visual::Property::TYPE, Visual::MESH );
1366 propertyMap.Insert( MeshVisual::Property::OBJECT_URL, TEST_OBJ_FILE_NAME );
1367 propertyMap.Insert( MeshVisual::Property::MATERIAL_URL, TEST_SIMPLE_MTL_FILE_NAME );
1368 propertyMap.Insert( MeshVisual::Property::TEXTURES_PATH, TEST_RESOURCE_DIR "/" );
1370 //Test to see if mesh loads correctly.
1371 MeshVisualLoadsCorrectlyTest( propertyMap, application );
1377 //Test if mesh visual can load when made to use diffuse textures only.
1378 int UtcDaliVisualFactoryGetMeshVisual5(void)
1380 //Set up test application first, so everything else can be handled.
1381 ToolkitTestApplication application;
1383 tet_infoline( "UtcDaliVisualFactoryGetMeshVisual5: Request mesh visual and make it only use diffuse textures." );
1385 //Set up visual properties.
1386 Property::Map propertyMap;
1387 propertyMap.Insert( Visual::Property::TYPE, Visual::MESH );
1388 propertyMap.Insert( MeshVisual::Property::OBJECT_URL, TEST_OBJ_FILE_NAME );
1389 propertyMap.Insert( MeshVisual::Property::MATERIAL_URL, TEST_MTL_FILE_NAME );
1390 propertyMap.Insert( MeshVisual::Property::TEXTURES_PATH, TEST_RESOURCE_DIR "/" );
1391 propertyMap.Insert( MeshVisual::Property::SHADING_MODE, MeshVisual::ShadingMode::TEXTURED_WITH_SPECULAR_LIGHTING );
1393 //Test to see if mesh loads correctly.
1394 MeshVisualLoadsCorrectlyTest( propertyMap, application );
1400 //Test if mesh visual can load when made to not use the supplied textures.
1401 int UtcDaliVisualFactoryGetMeshVisual6(void)
1403 //Set up test application first, so everything else can be handled.
1404 ToolkitTestApplication application;
1406 tet_infoline( "UtcDaliVisualFactoryGetMeshVisual6: Request mesh visual and make it not use any textures." );
1408 //Set up visual properties.
1409 Property::Map propertyMap;
1410 propertyMap.Insert( Visual::Property::TYPE, Visual::MESH );
1411 propertyMap.Insert( MeshVisual::Property::OBJECT_URL, TEST_OBJ_FILE_NAME );
1412 propertyMap.Insert( MeshVisual::Property::MATERIAL_URL, TEST_MTL_FILE_NAME );
1413 propertyMap.Insert( MeshVisual::Property::TEXTURES_PATH, TEST_RESOURCE_DIR "/" );
1414 propertyMap.Insert( MeshVisual::Property::SHADING_MODE, MeshVisual::ShadingMode::TEXTURELESS_WITH_DIFFUSE_LIGHTING );
1416 //Test to see if mesh loads correctly.
1417 MeshVisualLoadsCorrectlyTest( propertyMap, application );
1421 //Test if mesh visual loads correctly when light position is manually set.
1422 int UtcDaliVisualFactoryGetMeshVisual7(void)
1424 //Set up test application first, so everything else can be handled.
1425 ToolkitTestApplication application;
1428 tet_infoline( "UtcDaliVisualFactoryGetMeshVisual7: Request mesh visual with custom light position." );
1430 //Set up visual properties.
1431 Property::Map propertyMap;
1432 propertyMap.Insert( Visual::Property::TYPE, Visual::MESH );
1433 propertyMap.Insert( MeshVisual::Property::OBJECT_URL, TEST_OBJ_FILE_NAME );
1434 propertyMap.Insert( MeshVisual::Property::MATERIAL_URL, TEST_MTL_FILE_NAME );
1435 propertyMap.Insert( MeshVisual::Property::TEXTURES_PATH, TEST_RESOURCE_DIR "/" );
1436 propertyMap.Insert( MeshVisual::Property::LIGHT_POSITION, Vector3( 0.0, 1.0, 2.0 ) );
1438 //Test to see if mesh loads correctly.
1439 MeshVisualLoadsCorrectlyTest( propertyMap, application );
1444 //Test if mesh visual loads correctly when supplied an object file without face normals or texture points.
1445 //Note that this notably tests object loader functionality.
1446 int UtcDaliVisualFactoryGetMeshVisual8(void)
1448 //Set up test application first, so everything else can be handled.
1449 ToolkitTestApplication application;
1451 tet_infoline( "UtcDaliVisualFactoryGetMeshVisual5: Request mesh visual with normal-less object file." );
1453 //Set up visual properties.
1454 Property::Map propertyMap;
1455 propertyMap.Insert( Visual::Property::TYPE, Visual::MESH );
1456 propertyMap.Insert( MeshVisual::Property::OBJECT_URL, TEST_SIMPLE_OBJ_FILE_NAME );
1457 propertyMap.Insert( MeshVisual::Property::MATERIAL_URL, TEST_MTL_FILE_NAME );
1458 propertyMap.Insert( MeshVisual::Property::TEXTURES_PATH, TEST_RESOURCE_DIR "/" );
1460 //Test to see if mesh loads correctly.
1461 MeshVisualLoadsCorrectlyTest( propertyMap, application );
1466 //Test if mesh visual handles the case of lacking an object file.
1467 int UtcDaliVisualFactoryGetMeshVisualN1(void)
1469 //Set up test application first, so everything else can be handled.
1470 ToolkitTestApplication application;
1472 tet_infoline( "UtcDaliVisualFactoryGetMeshVisualN1: Request mesh visual without object file" );
1474 //Set up visual properties.
1475 Property::Map propertyMap;
1476 propertyMap.Insert( Visual::Property::TYPE, Visual::MESH );
1477 propertyMap.Insert( MeshVisual::Property::MATERIAL_URL, TEST_MTL_FILE_NAME );
1478 propertyMap.Insert( MeshVisual::Property::TEXTURES_PATH, TEST_RESOURCE_DIR "/" );
1480 //Test to see if mesh doesn't load with these properties, as expected.
1481 MeshVisualDoesNotLoadCorrectlyTest( propertyMap, application );
1487 //Test if mesh visual handles the case of being passed invalid material and images urls.
1488 int UtcDaliVisualFactoryGetMeshVisualN2(void)
1490 //Set up test application first, so everything else can be handled.
1491 ToolkitTestApplication application;
1493 tet_infoline( "UtcDaliVisualFactoryGetMeshVisualN2: Request mesh visual with invalid material and images urls" );
1495 //Set up visual properties.
1496 Property::Map propertyMap;
1497 propertyMap.Insert( Visual::Property::TYPE, Visual::MESH );
1498 propertyMap.Insert( MeshVisual::Property::OBJECT_URL, TEST_OBJ_FILE_NAME );
1499 propertyMap.Insert( MeshVisual::Property::MATERIAL_URL, "invalid" );
1500 propertyMap.Insert( MeshVisual::Property::TEXTURES_PATH, "also invalid" );
1502 //Test to see if mesh doesn't load with these properties, as expected.
1503 MeshVisualDoesNotLoadCorrectlyTest( propertyMap, application );
1509 //Test if mesh visual handles the case of being passed an invalid object url
1510 int UtcDaliVisualFactoryGetMeshVisualN3(void)
1512 //Set up test application first, so everything else can be handled.
1513 ToolkitTestApplication application;
1514 tet_infoline( "UtcDaliVisualFactoryGetMeshVisualN3: Request mesh visual with invalid object url" );
1517 //Set up visual properties.
1518 Property::Map propertyMap;
1519 propertyMap.Insert( Visual::Property::TYPE, Visual::MESH );
1520 propertyMap.Insert( MeshVisual::Property::OBJECT_URL, "invalid" );
1521 propertyMap.Insert( MeshVisual::Property::MATERIAL_URL, TEST_MTL_FILE_NAME );
1522 propertyMap.Insert( MeshVisual::Property::TEXTURES_PATH, TEST_RESOURCE_DIR "/" );
1524 //Test to see if mesh doesn't load with these properties, as expected.
1525 MeshVisualDoesNotLoadCorrectlyTest( propertyMap, application );
1530 //Creates a primitive visual with the given property map and tests to see if it correctly loads in the given application.
1531 void TestPrimitiveVisualWithProperties( Property::Map& propertyMap, ToolkitTestApplication& application )
1533 VisualFactory factory = VisualFactory::Get();
1534 DALI_TEST_CHECK( factory );
1536 //Create a primitive visual.
1537 Visual::Base visual = factory.CreateVisual( propertyMap );
1538 DALI_TEST_CHECK( visual );
1540 //Create an actor on stage to house the visual.
1541 DummyControl actor = DummyControl::New();
1542 DummyControlImpl& dummyImpl = static_cast<DummyControlImpl&>(actor.GetImplementation());
1543 dummyImpl.RegisterVisual( Control::CONTROL_PROPERTY_END_INDEX + 1, visual );
1545 actor.SetSize( 200.f, 200.f );
1546 Stage::GetCurrent().Add( actor );
1547 visual.SetTransformAndSize(DefaultTransform(), Vector2( 200.f, 200.f ) );
1549 //Ensure set on stage.
1550 DALI_TEST_EQUALS( actor.GetRendererCount(), 1u, TEST_LOCATION );
1552 //Tell test application to load the visual.
1553 application.SendNotification();
1554 application.Render(0);
1556 Matrix testScaleMatrix;
1557 testScaleMatrix.SetIdentityAndScale( Vector3( 1.0, -1.0, 1.0 ) );
1558 Matrix actualScaleMatrix;
1560 //Test to see if the object has been successfully loaded.
1561 DALI_TEST_CHECK( application.GetGlAbstraction().GetUniformValue<Matrix>( "uObjectMatrix", actualScaleMatrix ) );
1562 DALI_TEST_EQUALS( actualScaleMatrix, testScaleMatrix, Math::MACHINE_EPSILON_100, TEST_LOCATION );
1564 //Finish by setting off stage, and ensuring this was successful.
1566 DALI_TEST_EQUALS( actor.GetRendererCount(), 0u, TEST_LOCATION );
1569 //Test if primitive shape loads correctly when supplied with only the bare minimum requirements, the shape to use.
1570 int UtcDaliVisualFactoryGetPrimitiveVisual1(void)
1572 //Set up test application first, so everything else can be handled.
1573 ToolkitTestApplication application;
1575 tet_infoline( "UtcDaliVisualFactoryGetPrimitiveVisual1: Request primitive visual with a shape only" );
1577 //Set up visual properties.
1578 Property::Map propertyMap;
1579 propertyMap.Insert( Visual::Property::TYPE, Visual::PRIMITIVE );
1580 propertyMap.Insert( PrimitiveVisual::Property::SHAPE, PrimitiveVisual::Shape::CUBE );
1582 //Test to see if shape loads correctly.
1583 TestPrimitiveVisualWithProperties( propertyMap, application );
1588 //Test if primitive shape loads correctly when supplied with all possible parameters
1589 int UtcDaliVisualFactoryGetPrimitiveVisual2(void)
1591 //Set up test application first, so everything else can be handled.
1592 ToolkitTestApplication application;
1594 tet_infoline( "UtcDaliVisualFactoryGetPrimitiveVisual2: Request primitive visual with everything" );
1596 //Set up visual properties.
1597 Property::Map propertyMap;
1598 propertyMap.Insert( Visual::Property::TYPE, Visual::PRIMITIVE );
1599 propertyMap.Insert( PrimitiveVisual::Property::SHAPE, PrimitiveVisual::Shape::CUBE );
1600 propertyMap.Insert( PrimitiveVisual::Property::MIX_COLOR, Vector4( 0.5, 0.5, 0.5, 1.0 ) );
1601 propertyMap.Insert( PrimitiveVisual::Property::SLICES, 10 );
1602 propertyMap.Insert( PrimitiveVisual::Property::STACKS, 20 );
1603 propertyMap.Insert( PrimitiveVisual::Property::SCALE_TOP_RADIUS, 30.0f );
1604 propertyMap.Insert( PrimitiveVisual::Property::SCALE_BOTTOM_RADIUS, 40.0f );
1605 propertyMap.Insert( PrimitiveVisual::Property::SCALE_HEIGHT, 50.0f );
1606 propertyMap.Insert( PrimitiveVisual::Property::SCALE_RADIUS, 60.0f );
1607 propertyMap.Insert( PrimitiveVisual::Property::BEVEL_PERCENTAGE, 0.7f );
1608 propertyMap.Insert( PrimitiveVisual::Property::BEVEL_SMOOTHNESS, 0.8f );
1609 propertyMap.Insert( MeshVisual::Property::LIGHT_POSITION, Vector3( 0.9, 1.0, 1.1 ) );
1611 //Test to see if shape loads correctly.
1612 TestPrimitiveVisualWithProperties( propertyMap, application );
1617 //Test if primitive shape loads a sphere correctly.
1618 int UtcDaliVisualFactoryGetPrimitiveVisual3(void)
1620 //Set up test application first, so everything else can be handled.
1621 ToolkitTestApplication application;
1623 tet_infoline( "UtcDaliVisualFactoryGetPrimitiveVisual3: Request primitive visual to display a sphere" );
1625 //Set up visual properties.
1626 Property::Map propertyMap;
1627 propertyMap.Insert( Visual::Property::TYPE, Visual::PRIMITIVE );
1628 propertyMap.Insert( PrimitiveVisual::Property::SHAPE, PrimitiveVisual::Shape::SPHERE );
1629 propertyMap.Insert( PrimitiveVisual::Property::MIX_COLOR, Vector4( 0.5, 0.5, 0.5, 1.0 ) );
1630 propertyMap.Insert( PrimitiveVisual::Property::SLICES, 10 );
1631 propertyMap.Insert( PrimitiveVisual::Property::STACKS, 20 );
1633 //Test to see if shape loads correctly.
1634 TestPrimitiveVisualWithProperties( propertyMap, application );
1639 //Test if primitive shape loads a conic section correctly.
1640 int UtcDaliVisualFactoryGetPrimitiveVisual4(void)
1642 //Set up test application first, so everything else can be handled.
1643 ToolkitTestApplication application;
1645 tet_infoline( "UtcDaliVisualFactoryGetPrimitiveVisual4: Request primitive visual to display a conic section" );
1647 //Set up visual properties.
1648 Property::Map propertyMap;
1649 propertyMap.Insert( Visual::Property::TYPE, Visual::PRIMITIVE );
1650 propertyMap.Insert( PrimitiveVisual::Property::SHAPE, PrimitiveVisual::Shape::CONICAL_FRUSTRUM );
1651 propertyMap.Insert( PrimitiveVisual::Property::MIX_COLOR, Vector4( 0.5, 0.5, 0.5, 1.0 ) );
1652 propertyMap.Insert( PrimitiveVisual::Property::SLICES, 10 );
1653 propertyMap.Insert( PrimitiveVisual::Property::SCALE_TOP_RADIUS, 30.0f );
1654 propertyMap.Insert( PrimitiveVisual::Property::SCALE_BOTTOM_RADIUS, 40.0f );
1655 propertyMap.Insert( PrimitiveVisual::Property::SCALE_HEIGHT, 50.0f );
1657 //Test to see if shape loads correctly.
1658 TestPrimitiveVisualWithProperties( propertyMap, application );
1663 //Test if primitive shape loads a bevelled cube correctly.
1664 int UtcDaliVisualFactoryGetPrimitiveVisual5(void)
1666 //Set up test application first, so everything else can be handled.
1667 ToolkitTestApplication application;
1669 tet_infoline( "UtcDaliVisualFactoryGetPrimitiveVisual5: Request primitive visual to display a bevelled cube" );
1671 //Set up visual properties.
1672 Property::Map propertyMap;
1673 propertyMap.Insert( Visual::Property::TYPE, Visual::PRIMITIVE );
1674 propertyMap.Insert( PrimitiveVisual::Property::SHAPE, PrimitiveVisual::Shape::BEVELLED_CUBE );
1675 propertyMap.Insert( PrimitiveVisual::Property::MIX_COLOR, Vector4( 0.5, 0.5, 0.5, 1.0 ) );
1676 propertyMap.Insert( PrimitiveVisual::Property::BEVEL_PERCENTAGE, 0.7f );
1678 //Test to see if shape loads correctly.
1679 TestPrimitiveVisualWithProperties( propertyMap, application );
1684 //Test if primitive shape loads an octahedron correctly.
1685 int UtcDaliVisualFactoryGetPrimitiveVisual6(void)
1687 //Set up test application first, so everything else can be handled.
1688 ToolkitTestApplication application;
1690 tet_infoline( "UtcDaliVisualFactoryGetPrimitiveVisual6: Request primitive visual to display an octahedron" );
1692 //Set up visual properties.
1693 Property::Map propertyMap;
1694 propertyMap.Insert( Visual::Property::TYPE, Visual::PRIMITIVE );
1695 propertyMap.Insert( PrimitiveVisual::Property::SHAPE, PrimitiveVisual::Shape::OCTAHEDRON );
1696 propertyMap.Insert( PrimitiveVisual::Property::MIX_COLOR, Vector4( 0.5, 0.5, 0.5, 1.0 ) );
1698 //Test to see if shape loads correctly.
1699 TestPrimitiveVisualWithProperties( propertyMap, application );
1704 //Test if primitive shape loads a cone correctly.
1705 int UtcDaliVisualFactoryGetPrimitiveVisual7(void)
1707 //Set up test application first, so everything else can be handled.
1708 ToolkitTestApplication application;
1710 tet_infoline( "UtcDaliVisualFactoryGetPrimitiveVisual7: Request primitive visual to display a cone" );
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::CONE );
1716 propertyMap.Insert( PrimitiveVisual::Property::MIX_COLOR, Vector4( 0.5, 0.5, 0.5, 1.0 ) );
1717 propertyMap.Insert( PrimitiveVisual::Property::SLICES, 10 );
1718 propertyMap.Insert( PrimitiveVisual::Property::SCALE_TOP_RADIUS, 30.0f );
1719 propertyMap.Insert( PrimitiveVisual::Property::SCALE_HEIGHT, 50.0f );
1721 //Test to see if shape loads correctly.
1722 TestPrimitiveVisualWithProperties( propertyMap, application );
1727 //Test if primitive shape loads correctly when light position is manually set.
1728 int UtcDaliVisualFactoryGetPrimitiveVisual8(void)
1730 //Set up test application first, so everything else can be handled.
1731 ToolkitTestApplication application;
1733 tet_infoline( "UtcDaliVisualFactoryGetPrimitiveVisual8: Request primitive visual with set light position" );
1735 //Set up visual properties.
1736 Property::Map propertyMap;
1737 propertyMap.Insert( Visual::Property::TYPE, Visual::PRIMITIVE );
1738 propertyMap.Insert( PrimitiveVisual::Property::SHAPE, PrimitiveVisual::Shape::SPHERE );
1739 propertyMap.Insert( PrimitiveVisual::Property::MIX_COLOR, Vector4( 0.5, 0.5, 0.5, 1.0 ) );
1740 propertyMap.Insert( MeshVisual::Property::LIGHT_POSITION, Vector3( 0.0, 1.0, 2.0 ) );
1742 //Test to see if shape loads correctly.
1743 TestPrimitiveVisualWithProperties( propertyMap, application );
1748 //Test if primitive shape loads correctly when told to use too many slices.
1749 int UtcDaliVisualFactoryGetPrimitiveVisual9(void)
1751 //Set up test application first, so everything else can be handled.
1752 ToolkitTestApplication application;
1754 tet_infoline( "UtcDaliVisualFactoryGetPrimitiveVisual9: Request primitive visual with above-cap slices." );
1756 //Set up visual properties.
1757 Property::Map propertyMap;
1758 propertyMap.Insert( Visual::Property::TYPE, Visual::PRIMITIVE );
1759 propertyMap.Insert( PrimitiveVisual::Property::SHAPE, PrimitiveVisual::Shape::SPHERE );
1760 propertyMap.Insert( PrimitiveVisual::Property::SLICES, Property::Value( 1000000 ) );
1762 //Test to see if shape loads correctly.
1763 TestPrimitiveVisualWithProperties( propertyMap, application );
1768 //Test if primitive shape loads correctly when told to use too few slices. (2 slices or less.)
1769 int UtcDaliVisualFactoryGetPrimitiveVisual10(void)
1771 //Set up test application first, so everything else can be handled.
1772 ToolkitTestApplication application;
1774 tet_infoline( "UtcDaliVisualFactoryGetPrimitiveVisual10: Request primitive visual with too few slices." );
1776 //Set up visual properties.
1777 Property::Map propertyMap;
1778 propertyMap.Insert( Visual::Property::TYPE, Visual::PRIMITIVE );
1779 propertyMap.Insert( PrimitiveVisual::Property::SHAPE, PrimitiveVisual::Shape::SPHERE );
1780 propertyMap.Insert( PrimitiveVisual::Property::SLICES, Property::Value( 2 ) );
1782 //Test to see if shape loads correctly.
1783 TestPrimitiveVisualWithProperties( propertyMap, application );
1788 //Test if primitive shape loads correctly when told to use too many stacks.
1789 int UtcDaliVisualFactoryGetPrimitiveVisual11(void)
1791 //Set up test application first, so everything else can be handled.
1792 ToolkitTestApplication application;
1794 tet_infoline( "UtcDaliVisualFactoryGetPrimitiveVisual11: Request primitive visual with too many stacks." );
1796 //Set up visual properties.
1797 Property::Map propertyMap;
1798 propertyMap.Insert( Visual::Property::TYPE, Visual::PRIMITIVE );
1799 propertyMap.Insert( PrimitiveVisual::Property::SHAPE, PrimitiveVisual::Shape::SPHERE );
1800 propertyMap.Insert( PrimitiveVisual::Property::STACKS, Property::Value( 1000000 ) );
1802 //Test to see if shape loads correctly.
1803 TestPrimitiveVisualWithProperties( propertyMap, application );
1808 //Test if primitive shape loads correctly when told to use too few stacks. (1 stack or less.)
1809 int UtcDaliVisualFactoryGetPrimitiveVisual12(void)
1811 //Set up test application first, so everything else can be handled.
1812 ToolkitTestApplication application;
1814 tet_infoline( "UtcDaliVisualFactoryGetPrimitiveVisual12: Request primitive visual with too few stacks." );
1816 //Set up visual properties.
1817 Property::Map propertyMap;
1818 propertyMap.Insert( Visual::Property::TYPE, Visual::PRIMITIVE );
1819 propertyMap.Insert( PrimitiveVisual::Property::SHAPE, PrimitiveVisual::Shape::SPHERE );
1820 propertyMap.Insert( PrimitiveVisual::Property::STACKS, Property::Value( 1 ) );
1822 //Test to see if shape loads correctly.
1823 TestPrimitiveVisualWithProperties( propertyMap, application );
1828 //Test if primitive shape loads correctly when told to use invalid (zero or negative) dimensions.
1829 int UtcDaliVisualFactoryGetPrimitiveVisual13(void)
1831 //Set up test application first, so everything else can be handled.
1832 ToolkitTestApplication application;
1834 tet_infoline( "UtcDaliVisualFactoryGetPrimitiveVisual13: Request primitive visual with invalid scale dimensions." );
1836 //Set up visual properties.
1837 Property::Map propertyMap;
1838 propertyMap.Insert( Visual::Property::TYPE, Visual::PRIMITIVE );
1839 propertyMap.Insert( PrimitiveVisual::Property::SHAPE, PrimitiveVisual::Shape::SPHERE );
1840 propertyMap.Insert( PrimitiveVisual::Property::SCALE_DIMENSIONS, Vector3::ZERO );
1842 //Test to see if shape loads correctly.
1843 TestPrimitiveVisualWithProperties( propertyMap, application );
1848 //Test if primitive shape loads correctly when told to use too low a bevel percentage.
1849 int UtcDaliVisualFactoryGetPrimitiveVisual14(void)
1851 //Set up test application first, so everything else can be handled.
1852 ToolkitTestApplication application;
1854 tet_infoline( "UtcDaliVisualFactoryGetPrimitiveVisual14: Request primitive visual with too low a bevel percentage." );
1856 //Set up visual properties.
1857 Property::Map propertyMap;
1858 propertyMap.Insert( Visual::Property::TYPE, Visual::PRIMITIVE );
1859 propertyMap.Insert( PrimitiveVisual::Property::SHAPE, PrimitiveVisual::Shape::SPHERE );
1860 propertyMap.Insert( PrimitiveVisual::Property::BEVEL_PERCENTAGE, Property::Value( -1.0f ) );
1862 //Test to see if shape loads correctly.
1863 TestPrimitiveVisualWithProperties( propertyMap, application );
1868 //Test if primitive shape loads correctly when told to use too high a bevel percentage.
1869 int UtcDaliVisualFactoryGetPrimitiveVisual15(void)
1871 //Set up test application first, so everything else can be handled.
1872 ToolkitTestApplication application;
1874 tet_infoline( "UtcDaliVisualFactoryGetPrimitiveVisual15: Request primitive visual with too high a bevel percentage." );
1876 //Set up visual properties.
1877 Property::Map propertyMap;
1878 propertyMap.Insert( Visual::Property::TYPE, Visual::PRIMITIVE );
1879 propertyMap.Insert( PrimitiveVisual::Property::SHAPE, PrimitiveVisual::Shape::SPHERE );
1880 propertyMap.Insert( PrimitiveVisual::Property::BEVEL_PERCENTAGE, Property::Value( 2.0f ) );
1882 //Test to see if shape loads correctly.
1883 TestPrimitiveVisualWithProperties( propertyMap, application );
1888 //Test if primitive shape loads correctly when told to use too low a bevel smoothness.
1889 int UtcDaliVisualFactoryGetPrimitiveVisual16(void)
1891 //Set up test application first, so everything else can be handled.
1892 ToolkitTestApplication application;
1894 tet_infoline( "UtcDaliVisualFactoryGetPrimitiveVisual16: Request primitive visual with too low a bevel smoothness." );
1896 //Set up visual properties.
1897 Property::Map propertyMap;
1898 propertyMap.Insert( Visual::Property::TYPE, Visual::PRIMITIVE );
1899 propertyMap.Insert( PrimitiveVisual::Property::SHAPE, PrimitiveVisual::Shape::SPHERE );
1900 propertyMap.Insert( PrimitiveVisual::Property::BEVEL_SMOOTHNESS, Property::Value( -1.0f ) );
1902 //Test to see if shape loads correctly.
1903 TestPrimitiveVisualWithProperties( propertyMap, application );
1908 //Test if primitive shape loads correctly when told to use too high a bevel smoothness.
1909 int UtcDaliVisualFactoryGetPrimitiveVisual17(void)
1911 //Set up test application first, so everything else can be handled.
1912 ToolkitTestApplication application;
1914 tet_infoline( "UtcDaliVisualFactoryGetPrimitiveVisual17: Request primitive visual with too high a bevel smoothness." );
1916 //Set up visual properties.
1917 Property::Map propertyMap;
1918 propertyMap.Insert( Visual::Property::TYPE, Visual::PRIMITIVE );
1919 propertyMap.Insert( PrimitiveVisual::Property::SHAPE, PrimitiveVisual::Shape::SPHERE );
1920 propertyMap.Insert( PrimitiveVisual::Property::BEVEL_SMOOTHNESS, Property::Value( 2.0f ) );
1922 //Test to see if shape loads correctly.
1923 TestPrimitiveVisualWithProperties( propertyMap, application );
1928 //Test if primitive shape visual handles the case of not being passed a specific shape to use.
1929 int UtcDaliVisualFactoryGetPrimitiveVisualN1(void)
1931 //Set up test application first, so everything else can be handled.
1932 ToolkitTestApplication application;
1934 tet_infoline( "UtcDaliVisualFactoryGetPrimitiveVisualN1: Request primitive visual without shape" );
1936 //Set up visual properties, without supplying shape.
1937 Property::Map propertyMap;
1938 propertyMap.Insert( Visual::Property::TYPE, Visual::PRIMITIVE );
1940 //Test to see if shape loads regardless of missing input.
1941 TestPrimitiveVisualWithProperties( propertyMap, application );
1946 int UtcDaliVisualFactoryGetBatchImageVisual1(void)
1948 ToolkitTestApplication application;
1949 tet_infoline( "UtcDaliVisualFactoryGetBatchImageVisual1: Request a Batch Image visual with a Property::Map" );
1951 VisualFactory factory = VisualFactory::Get();
1952 DALI_TEST_CHECK( factory );
1954 Property::Map propertyMap;
1955 propertyMap.Insert( Visual::Property::TYPE, Visual::IMAGE );
1956 propertyMap.Insert( ImageVisual::Property::BATCHING_ENABLED, true );
1957 propertyMap.Insert( ImageVisual::Property::URL, TEST_IMAGE_FILE_NAME );
1959 Visual::Base visual = factory.CreateVisual( propertyMap );
1960 DALI_TEST_CHECK( visual );
1962 DummyControl actor = DummyControl::New();
1963 DummyControlImpl& dummyImpl = static_cast<DummyControlImpl&>(actor.GetImplementation());
1964 dummyImpl.RegisterVisual( Control::CONTROL_PROPERTY_END_INDEX + 1, visual );
1966 actor.SetSize( 200.0f, 200.0f );
1967 Stage::GetCurrent().Add( actor );
1968 visual.SetTransformAndSize(DefaultTransform(), Vector2( 200.0f, 200.0f ) );
1970 // Test SetOnStage().
1971 DALI_TEST_CHECK( actor.GetRendererCount() == 1u );
1973 application.SendNotification();
1974 application.Render();
1976 // Test SetOffStage().
1978 DALI_TEST_CHECK( actor.GetRendererCount() == 0u );
1983 int UtcDaliVisualFactoryGetBatchImageVisual2(void)
1985 ToolkitTestApplication application;
1986 tet_infoline( "UtcDaliVisualFactoryGetBatchImageVisual2: Request Batch Image visual from an Image Visual with batchingEnabled set" );
1988 VisualFactory factory = VisualFactory::Get();
1989 DALI_TEST_CHECK( factory );
1991 Property::Map propertyMap;
1992 // Create a normal Image Visual.
1993 propertyMap.Insert( Visual::Property::TYPE, Visual::IMAGE );
1994 // Instruct the factory to change Image Visuals to Batch-Image Visuals.
1995 propertyMap.Insert( ImageVisual::Property::BATCHING_ENABLED, true );
1997 // Properties for the Batch-Image Visual.
1998 propertyMap.Insert( ImageVisual::Property::URL, TEST_IMAGE_FILE_NAME );
2000 Visual::Base visual = factory.CreateVisual( propertyMap );
2001 DALI_TEST_CHECK( visual );
2003 // Check that a Batch-Image visual was created instead of an Image visual.
2004 Property::Map resultMap;
2005 visual.CreatePropertyMap( resultMap );
2007 Property::Value* value = resultMap.Find( Visual::Property::TYPE, Property::INTEGER );
2008 DALI_TEST_CHECK( value );
2009 DALI_TEST_EQUALS( value->Get<int>(), (int)Visual::IMAGE, TEST_LOCATION );
2011 DummyControl actor = DummyControl::New();
2012 DummyControlImpl& dummyImpl = static_cast<DummyControlImpl&>(actor.GetImplementation());
2013 dummyImpl.RegisterVisual( Control::CONTROL_PROPERTY_END_INDEX + 1, visual );
2015 actor.SetSize( 200.0f, 200.0f );
2016 Stage::GetCurrent().Add( actor );
2017 visual.SetTransformAndSize(DefaultTransform(), Vector2( 200.0f, 200.0f ) );
2019 // Test SetOnStage().
2020 DALI_TEST_CHECK( actor.GetRendererCount() == 1u );
2022 application.SendNotification();
2023 application.Render();
2025 // Test SetOffStage().
2027 DALI_TEST_CHECK( actor.GetRendererCount() == 0u );
2032 int UtcDaliVisualFactoryGetBatchImageVisual3(void)
2034 ToolkitTestApplication application;
2035 tet_infoline( "UtcDaliVisualFactoryGetBatchImageVisual3: Create an ImageView that uses a batched visual internally" );
2037 VisualFactory factory = VisualFactory::Get();
2038 DALI_TEST_CHECK( factory );
2040 // Create a property-map that enables batching.
2041 Property::Map propertyMap;
2042 propertyMap.Insert( Dali::Toolkit::ImageVisual::Property::URL, TEST_IMAGE_FILE_NAME );
2043 propertyMap.Insert( ImageVisual::Property::BATCHING_ENABLED, true );
2045 // Create an ImageView, passing the property-map in to instruct it to use batching.
2046 Toolkit::ImageView imageView = Toolkit::ImageView::New();
2047 imageView.SetProperty( Toolkit::ImageView::Property::IMAGE, propertyMap );
2049 imageView.SetSize( 200.0f, 200.0f );
2050 Stage::GetCurrent().Add( imageView );