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-toolkit/devel-api/visual-factory/visual-factory.h>
26 #include <dali-toolkit/dali-toolkit.h>
29 using namespace Dali::Toolkit;
33 typedef NinePatchImage::StretchRanges StretchRanges;
35 const char* TEST_IMAGE_FILE_NAME = "gallery_image_01.jpg";
36 const char* TEST_NPATCH_FILE_NAME = "gallery_image_01.9.png";
37 const char* TEST_SVG_FILE_NAME = TEST_RESOURCE_DIR "/svg1.svg";
38 const char* TEST_OBJ_FILE_NAME = TEST_RESOURCE_DIR "/Cube.obj";
39 const char* TEST_MTL_FILE_NAME = TEST_RESOURCE_DIR "/ToyRobot-Metal.mtl";
40 const char* TEST_SIMPLE_OBJ_FILE_NAME = TEST_RESOURCE_DIR "/Cube-Points-Only.obj";
41 const char* TEST_SIMPLE_MTL_FILE_NAME = TEST_RESOURCE_DIR "/ToyRobot-Metal-Simple.mtl";
43 // resolution: 34*34, pixel format: RGBA8888
44 static const char* gImage_34_RGBA = TEST_RESOURCE_DIR "/icon-edit.png";
45 // resolution: 600*600, pixel format: RGB888
46 static const char* gImage_600_RGB = TEST_RESOURCE_DIR "/test-image-600.jpg";
48 Integration::Bitmap* CreateBitmap( unsigned int imageWidth, unsigned int imageHeight, unsigned int initialColor, Pixel::Format pixelFormat )
50 Integration::Bitmap* bitmap = Integration::Bitmap::New( Integration::Bitmap::BITMAP_2D_PACKED_PIXELS, ResourcePolicy::OWNED_RETAIN );
51 Integration::PixelBuffer* pixbuffer = bitmap->GetPackedPixelsProfile()->ReserveBuffer( pixelFormat, imageWidth, imageHeight, imageWidth, imageHeight );
52 unsigned int bytesPerPixel = GetBytesPerPixel( pixelFormat );
54 memset( pixbuffer, initialColor, imageHeight * imageWidth * bytesPerPixel );
59 void InitialiseRegionsToZeroAlpha( Integration::Bitmap* image, unsigned int imageWidth, unsigned int imageHeight, Pixel::Format pixelFormat )
61 PixelBuffer* pixbuffer = image->GetBuffer();
62 unsigned int bytesPerPixel = GetBytesPerPixel( pixelFormat );
64 for( unsigned int row = 0; row < imageWidth; ++row )
66 unsigned int pixelOffset = row * bytesPerPixel;
67 pixbuffer[ pixelOffset + 3 ] = 0x00;
68 pixelOffset += ( imageHeight - 1 ) * imageWidth * bytesPerPixel;
69 pixbuffer[ pixelOffset + 3 ] = 0x00;
72 for ( unsigned int column = 0; column < imageHeight; ++column )
74 unsigned int pixelOffset = column * imageWidth * bytesPerPixel;
75 pixbuffer[ pixelOffset + 3 ] = 0x00;
76 pixelOffset += ( imageWidth -1 ) * bytesPerPixel;
77 pixbuffer[ pixelOffset + 3 ] = 0x00;
81 void AddStretchRegionsToImage( Integration::Bitmap* image, unsigned int imageWidth, unsigned int imageHeight, const StretchRanges& stretchRangesX, const StretchRanges& stretchRangesY, Pixel::Format pixelFormat )
83 PixelBuffer* pixbuffer = image->GetBuffer();
84 unsigned int bytesPerPixel = GetBytesPerPixel( pixelFormat );
86 for(StretchRanges::ConstIterator it = stretchRangesX.Begin(); it != stretchRangesX.End(); ++it)
88 const Uint16Pair& range = *it;
89 //since the stretch range is in the cropped image space, we need to offset by 1 to get it to the uncropped image space
90 for( unsigned int column = range.GetX() + 1u; column < range.GetY() + 1u; ++column )
92 unsigned int pixelOffset = column * bytesPerPixel;
93 pixbuffer[ pixelOffset ] = 0x00;
94 pixbuffer[ pixelOffset + 1 ] = 0x00;
95 pixbuffer[ pixelOffset + 2 ] = 0x00;
96 pixbuffer[ pixelOffset + 3 ] = 0xFF;
101 for(StretchRanges::ConstIterator it = stretchRangesY.Begin(); it != stretchRangesY.End(); ++it)
103 const Uint16Pair& range = *it;
104 //since the stretch range is in the cropped image space, we need to offset by 1 to get it to the uncropped image space
105 for( unsigned int row = range.GetX() + 1u; row < range.GetY() + 1u; ++row )
107 unsigned int pixelOffset = row * imageWidth * bytesPerPixel;
108 pixbuffer[ pixelOffset ] = 0x00;
109 pixbuffer[ pixelOffset + 1 ] = 0x00;
110 pixbuffer[ pixelOffset + 2 ] = 0x00;
111 pixbuffer[ pixelOffset + 3 ] = 0xFF;
116 void AddChildRegionsToImage( Integration::Bitmap* image, unsigned int imageWidth, unsigned int imageHeight, const Vector4& requiredChildRegion, Pixel::Format pixelFormat )
118 PixelBuffer* pixbuffer = image->GetBuffer();
119 unsigned int bytesPerPixel = GetBytesPerPixel( pixelFormat );
121 Integration::Bitmap::PackedPixelsProfile* srcProfile = image->GetPackedPixelsProfile();
122 unsigned int bufferStride = srcProfile->GetBufferStride();
124 // Add bottom child region
125 for( unsigned int column = requiredChildRegion.x; column < imageWidth - requiredChildRegion.z; ++column )
127 unsigned int pixelOffset = column * bytesPerPixel;
128 pixelOffset += ( imageHeight - 1 ) * bufferStride;
129 pixbuffer[ pixelOffset ] = 0x00;
130 pixbuffer[ pixelOffset + 1 ] = 0x00;
131 pixbuffer[ pixelOffset + 2 ] = 0x00;
132 pixbuffer[ pixelOffset + 3 ] = 0xFF;
135 // Add right child region
136 for ( unsigned int row = requiredChildRegion.y; row < imageHeight - requiredChildRegion.w; ++row )
138 unsigned int pixelOffset = row * bufferStride + ( imageWidth - 1 ) * bytesPerPixel;
139 pixbuffer[ pixelOffset ] = 0x00;
140 pixbuffer[ pixelOffset + 1 ] = 0x00;
141 pixbuffer[ pixelOffset + 2 ] = 0x00;
142 pixbuffer[ pixelOffset + 3 ] = 0xFF;
146 Integration::ResourcePointer CustomizeNinePatch( TestApplication& application,
147 unsigned int ninePatchImageWidth,
148 unsigned int ninePatchImageHeight,
149 const StretchRanges& stretchRangesX,
150 const StretchRanges& stretchRangesY,
151 bool addChildRegion = false,
152 Vector4 requiredChildRegion = Vector4::ZERO )
154 TestPlatformAbstraction& platform = application.GetPlatform();
156 Pixel::Format pixelFormat = Pixel::RGBA8888;
158 tet_infoline("Create Bitmap");
159 platform.SetClosestImageSize(Vector2( ninePatchImageWidth, ninePatchImageHeight));
160 Integration::Bitmap* bitmap = CreateBitmap( ninePatchImageWidth, ninePatchImageHeight, 0xFF, pixelFormat );
162 tet_infoline("Clear border regions");
163 InitialiseRegionsToZeroAlpha( bitmap, ninePatchImageWidth, ninePatchImageHeight, pixelFormat );
165 tet_infoline("Add Stretch regions to Bitmap");
166 AddStretchRegionsToImage( bitmap, ninePatchImageWidth, ninePatchImageHeight, stretchRangesX, stretchRangesY, pixelFormat );
170 tet_infoline("Add Child regions to Bitmap");
171 AddChildRegionsToImage( bitmap, ninePatchImageWidth, ninePatchImageHeight, requiredChildRegion, pixelFormat );
174 tet_infoline("Getting resource");
175 Integration::ResourcePointer resourcePtr(bitmap);
176 //platform.SetResourceLoaded( 0, Dali::Integration::ResourceBitmap, resourcePtr );
177 platform.SetSynchronouslyLoadedResource( resourcePtr);
182 void TestVisualRender( ToolkitTestApplication& application,
184 Visual::Base& visual,
185 std::size_t expectedSamplers = 0,
186 ImageDimensions imageDimensions = ImageDimensions(),
187 Integration::ResourcePointer resourcePtr = Integration::ResourcePointer())
191 // set the image size, for test case, this needs to be set before loading started
192 application.GetPlatform().SetClosestImageSize( Vector2(imageDimensions.GetWidth(), imageDimensions.GetHeight()) );
195 actor.SetSize( 200.f, 200.f );
196 Stage::GetCurrent().Add( actor );
197 visual.SetSize( Vector2(200.f, 200.f) );
198 visual.SetOnStage( actor );
200 DALI_TEST_CHECK( actor.GetRendererCount() == 1u );
202 application.SendNotification();
203 application.Render();
207 Integration::ResourceRequest* request = application.GetPlatform().GetRequest();
210 application.GetPlatform().SetResourceLoaded(request->GetId(), request->GetType()->id, resourcePtr );
214 application.Render();
215 application.SendNotification();
219 DALI_TEST_CHECK( application.GetPlatform().WasCalled(TestPlatformAbstraction::LoadResourceFunc) ||
220 application.GetPlatform().WasCalled(TestPlatformAbstraction::LoadResourceSynchronouslyFunc ));
223 DALI_TEST_CHECK( actor.GetRendererCount() == 1u );
230 void dali_visual_factory_startup(void)
232 test_return_value = TET_UNDEF;
235 void dali_visual_factory_cleanup(void)
237 test_return_value = TET_PASS;
240 int UtcDaliVisualFactoryGet(void)
242 ToolkitTestApplication application;
243 tet_infoline( "UtcDaliVisualFactory" );
247 type = TypeRegistry::Get().GetTypeInfo( "VisualFactory" );
248 DALI_TEST_CHECK( type );
249 BaseHandle handle = type.CreateInstance();
250 DALI_TEST_CHECK( handle );
252 VisualFactory factory;
253 factory = VisualFactory::Get();
254 DALI_TEST_CHECK( factory );
256 VisualFactory newFactory = VisualFactory::Get();
257 DALI_TEST_CHECK( newFactory );
259 // Check that visual factory is a singleton
260 DALI_TEST_CHECK(factory == newFactory);
265 int UtcDaliVisualFactoryCopyAndAssignment(void)
267 ToolkitTestApplication application;
268 tet_infoline( "UtcDaliVisualFactoryCopyAndAssignment" );
269 VisualFactory factory = VisualFactory::Get();
271 VisualFactory factoryCopy( factory );
272 DALI_TEST_CHECK(factory == factoryCopy);
274 VisualFactory emptyFactory;
275 VisualFactory emptyFactoryCopy( emptyFactory );
276 DALI_TEST_CHECK(emptyFactory == emptyFactoryCopy);
278 VisualFactory factoryEquals;
279 factoryEquals = factory;
280 DALI_TEST_CHECK(factory == factoryEquals);
282 VisualFactory emptyFactoryEquals;
283 emptyFactoryEquals = emptyFactory;
284 DALI_TEST_CHECK( emptyFactory == emptyFactoryEquals );
288 DALI_TEST_CHECK( factory = factoryCopy );
293 int UtcDaliVisualFactoryGetColorVisual1(void)
295 ToolkitTestApplication application;
296 tet_infoline( "UtcDaliVisualFactoryGetColorVisual1: Request color visual with a Property::Map" );
298 VisualFactory factory = VisualFactory::Get();
299 DALI_TEST_CHECK( factory );
301 Property::Map propertyMap;
302 Vector4 testColor( 1.f, 0.5f, 0.3f, 0.2f );
303 propertyMap.Insert(Visual::Property::TYPE, Visual::COLOR);
304 propertyMap.Insert(ColorVisual::Property::MIX_COLOR, testColor);
306 Visual::Base visual = factory.CreateVisual(propertyMap);
307 DALI_TEST_CHECK( visual );
309 Actor actor = Actor::New();
310 TestVisualRender( application, actor, visual );
312 Vector4 actualValue(Vector4::ZERO);
313 TestGlAbstraction& gl = application.GetGlAbstraction();
314 DALI_TEST_CHECK( gl.GetUniformValue<Vector4>( "mixColor", actualValue ) );
315 DALI_TEST_EQUALS( actualValue, testColor, TEST_LOCATION );
320 int UtcDaliVisualFactoryGetColorVisual2(void)
322 ToolkitTestApplication application;
323 tet_infoline( "UtcDaliVisualFactoryGetColorVisual2: Request color visual with a Vector4" );
325 VisualFactory factory = VisualFactory::Get();
326 DALI_TEST_CHECK( factory );
328 Vector4 testColor( 1.f, 0.5f, 0.3f, 0.2f );
329 Dali::Property::Map map;
330 map[ Visual::Property::TYPE ] = Visual::COLOR;
331 map[ ColorVisual::Property::MIX_COLOR ] = testColor;
332 Visual::Base visual = factory.CreateVisual( map );
333 DALI_TEST_CHECK( visual );
335 Actor actor = Actor::New();
336 TestVisualRender( application, actor, visual );
338 Vector4 actualValue(Vector4::ZERO);
339 TestGlAbstraction& gl = application.GetGlAbstraction();
340 DALI_TEST_CHECK( gl.GetUniformValue<Vector4>( "mixColor", actualValue ) );
341 DALI_TEST_EQUALS( actualValue, testColor, TEST_LOCATION );
343 visual.SetOffStage( actor );
344 DALI_TEST_CHECK( actor.GetRendererCount() == 0u );
349 int UtcDaliVisualFactoryGetBorderVisual1(void)
351 ToolkitTestApplication application;
352 tet_infoline( "UtcDaliVisualFactoryGetBorderVisual1: Request border visual with a Property::Map" );
354 VisualFactory factory = VisualFactory::Get();
355 DALI_TEST_CHECK( factory );
357 Property::Map propertyMap;
358 Vector4 testColor( 1.f, 0.5f, 0.3f, 0.2f );
359 float testSize = 5.f;
360 propertyMap.Insert(Visual::Property::TYPE, Visual::BORDER);
361 propertyMap.Insert(BorderVisual::Property::COLOR, testColor);
362 propertyMap.Insert(BorderVisual::Property::SIZE, testSize);
364 Visual::Base visual = factory.CreateVisual(propertyMap);
365 DALI_TEST_CHECK( visual );
367 Actor actor = Actor::New();
368 actor.SetSize(200.f, 200.f);
369 Stage::GetCurrent().Add( actor );
370 visual.SetSize(Vector2(200.f, 200.f));
371 visual.SetOnStage( actor );
373 DALI_TEST_CHECK( actor.GetRendererCount() == 1u );
374 int blendMode = actor.GetRendererAt(0u).GetProperty<int>( Renderer::Property::BLEND_MODE );
375 DALI_TEST_EQUALS( static_cast<BlendingMode::Type>(blendMode), BlendingMode::ON, TEST_LOCATION );
377 TestGlAbstraction& gl = application.GetGlAbstraction();
379 application.SendNotification();
380 application.Render(0);
382 Vector4 actualColor(Vector4::ZERO);
383 DALI_TEST_CHECK( gl.GetUniformValue<Vector4>( "borderColor", actualColor ) );
384 DALI_TEST_EQUALS( actualColor, testColor, TEST_LOCATION );
386 float actualSize = 0.f;
387 DALI_TEST_CHECK( gl.GetUniformValue<float>( "borderSize", actualSize ) );
388 DALI_TEST_EQUALS( actualSize, testSize, TEST_LOCATION );
390 visual.SetOffStage( actor );
391 DALI_TEST_CHECK( actor.GetRendererCount() == 0u );
396 int UtcDaliVisualFactoryGetBorderVisual2(void)
398 ToolkitTestApplication application;
399 tet_infoline( "UtcDaliVisualFactoryGetBorderVisual2: Request border visual with a borderSize and a borderColor" );
401 VisualFactory factory = VisualFactory::Get();
402 DALI_TEST_CHECK( factory );
404 Vector4 testColor( 1.f, 0.5f, 0.3f, 1.f );
405 float testSize = 5.f;
407 Dali::Property::Map propertyMap;
408 propertyMap[ Visual::Property::TYPE ] = Visual::BORDER;
409 propertyMap[ BorderVisual::Property::COLOR ] = testColor;
410 propertyMap[ BorderVisual::Property::SIZE ] = testSize;
411 Visual::Base visual = factory.CreateVisual( propertyMap );
412 DALI_TEST_CHECK( visual );
414 Actor actor = Actor::New();
415 actor.SetSize(200.f, 200.f);
416 Stage::GetCurrent().Add( actor );
417 visual.SetSize(Vector2(200.f, 200.f));
418 visual.SetOnStage( actor );
420 DALI_TEST_CHECK( actor.GetRendererCount() == 1u );
422 TestGlAbstraction& gl = application.GetGlAbstraction();
424 application.SendNotification();
425 application.Render(0);
427 int blendMode = actor.GetRendererAt(0u).GetProperty<int>( Renderer::Property::BLEND_MODE );
428 DALI_TEST_EQUALS( static_cast<BlendingMode::Type>(blendMode), BlendingMode::AUTO, TEST_LOCATION );
430 Vector4 actualColor(Vector4::ZERO);
431 DALI_TEST_CHECK( gl.GetUniformValue<Vector4>( "borderColor", actualColor ) );
432 DALI_TEST_EQUALS( actualColor, testColor, TEST_LOCATION );
434 float actualSize = 0.f;
435 DALI_TEST_CHECK( gl.GetUniformValue<float>( "borderSize", actualSize ) );
436 DALI_TEST_EQUALS( actualSize, testSize, TEST_LOCATION );
438 visual.SetOffStage( actor );
440 // enable the anti-aliasing
441 Dali::Property::Map map;
442 map[ Visual::Property::TYPE ] = Visual::BORDER;
443 map[ BorderVisual::Property::COLOR ] = testColor;
444 map[ BorderVisual::Property::SIZE ] = testSize;
445 map[ BorderVisual::Property::ANTI_ALIASING ] = true;
446 visual = factory.CreateVisual( map );
447 visual.SetOnStage( actor );
449 application.SendNotification();
450 application.Render(0);
451 blendMode = actor.GetRendererAt(0u).GetProperty<int>( Renderer::Property::BLEND_MODE );
452 DALI_TEST_EQUALS( static_cast<BlendingMode::Type>(blendMode), BlendingMode::ON, TEST_LOCATION );
457 int UtcDaliVisualFactoryGetLinearGradientVisual(void)
459 ToolkitTestApplication application;
460 tet_infoline("UtcDaliVisualFactoryGetRadialGradientVisual");
462 VisualFactory factory = VisualFactory::Get();
463 DALI_TEST_CHECK( factory );
465 Property::Map propertyMap;
466 propertyMap.Insert(Visual::Property::TYPE, Visual::GRADIENT);
468 Vector2 start(-1.f, -1.f);
469 Vector2 end(1.f, 1.f);
470 propertyMap.Insert(GradientVisual::Property::START_POSITION, start);
471 propertyMap.Insert(GradientVisual::Property::END_POSITION, end);
472 propertyMap.Insert(GradientVisual::Property::SPREAD_METHOD, GradientVisual::SpreadMethod::REPEAT);
474 Property::Array stopOffsets;
475 stopOffsets.PushBack( 0.2f );
476 stopOffsets.PushBack( 0.8f );
477 propertyMap.Insert(GradientVisual::Property::STOP_OFFSET, stopOffsets);
479 Property::Array stopColors;
480 stopColors.PushBack( Color::RED );
481 stopColors.PushBack( Color::GREEN );
482 propertyMap.Insert(GradientVisual::Property::STOP_COLOR, stopColors);
484 Visual::Base visual = factory.CreateVisual(propertyMap);
485 DALI_TEST_CHECK( visual );
487 // A lookup texture is generated and pass to shader as sampler
488 Actor actor = Actor::New();
489 TestVisualRender( application, actor, visual, 1u );
491 visual.SetOffStage( actor );
492 DALI_TEST_CHECK( actor.GetRendererCount() == 0u );
497 int UtcDaliVisualFactoryGetRadialGradientVisual(void)
499 ToolkitTestApplication application;
500 tet_infoline("UtcDaliVisualFactoryGetRadialGradientVisual");
502 VisualFactory factory = VisualFactory::Get();
503 DALI_TEST_CHECK( factory );
505 Property::Map propertyMap;
506 propertyMap.Insert(Visual::Property::TYPE, Visual::GRADIENT);
508 Vector2 center(100.f, 100.f);
509 float radius = 100.f;
510 propertyMap.Insert(GradientVisual::Property::UNITS, GradientVisual::Units::USER_SPACE);
511 propertyMap.Insert(GradientVisual::Property::CENTER, center);
512 propertyMap.Insert(GradientVisual::Property::RADIUS, radius);
514 Property::Array stopOffsets;
515 stopOffsets.PushBack( 0.0f );
516 stopOffsets.PushBack( 1.f );
517 propertyMap.Insert(GradientVisual::Property::STOP_OFFSET, stopOffsets);
519 Property::Array stopColors;
520 stopColors.PushBack( Color::RED );
521 stopColors.PushBack( Color::GREEN );
522 propertyMap.Insert(GradientVisual::Property::STOP_COLOR, stopColors);
524 Visual::Base visual = factory.CreateVisual(propertyMap);
525 DALI_TEST_CHECK( visual );
527 // A lookup texture is generated and pass to shader as sampler
528 Actor actor = Actor::New();
529 TestVisualRender( application, actor, visual, 1u );
531 Matrix3 alignMatrix( radius, 0.f, 0.f, 0.f, radius, 0.f, center.x, center.y, 1.f );
532 alignMatrix.Invert();
534 Matrix3 actualValue( Matrix3::IDENTITY );
535 TestGlAbstraction& gl = application.GetGlAbstraction();
536 DALI_TEST_CHECK( gl.GetUniformValue<Matrix3>( "uAlignmentMatrix", actualValue ) );
537 DALI_TEST_EQUALS( actualValue, alignMatrix, Math::MACHINE_EPSILON_100, TEST_LOCATION );
542 int UtcDaliVisualFactoryDefaultOffsetsGradientVisual(void)
544 ToolkitTestApplication application;
545 tet_infoline("UtcDaliVisualFactoryGetRadialGradientVisual");
547 VisualFactory factory = VisualFactory::Get();
548 DALI_TEST_CHECK( factory );
550 Property::Map propertyMap;
551 propertyMap.Insert(Visual::Property::TYPE, Visual::GRADIENT);
553 Vector2 start(-1.f, -1.f);
554 Vector2 end(1.f, 1.f);
555 propertyMap.Insert(GradientVisual::Property::START_POSITION, start);
556 propertyMap.Insert(GradientVisual::Property::END_POSITION, end);
557 propertyMap.Insert(GradientVisual::Property::SPREAD_METHOD, GradientVisual::SpreadMethod::REPEAT);
559 Property::Array stopColors;
560 stopColors.PushBack( Color::RED );
561 stopColors.PushBack( Color::GREEN );
562 propertyMap.Insert(GradientVisual::Property::STOP_COLOR, stopColors);
564 Visual::Base visual = factory.CreateVisual(propertyMap);
565 DALI_TEST_CHECK( visual );
567 // A lookup texture is generated and pass to shader as sampler
568 Actor actor = Actor::New();
569 TestVisualRender( application, actor, visual, 1u );
571 visual.SetOffStage( actor );
572 DALI_TEST_CHECK( actor.GetRendererCount() == 0u );
577 int UtcDaliVisualFactoryGetImageVisual1(void)
579 ToolkitTestApplication application;
580 tet_infoline( "UtcDaliVisualFactoryGetImageVisual1: Request image visual with a Property::Map" );
582 VisualFactory factory = VisualFactory::Get();
583 DALI_TEST_CHECK( factory );
585 Property::Map propertyMap;
586 propertyMap.Insert( Visual::Property::TYPE, Visual::IMAGE );
587 propertyMap.Insert( ImageVisual::Property::URL, TEST_IMAGE_FILE_NAME );
589 Visual::Base visual = factory.CreateVisual( propertyMap );
590 DALI_TEST_CHECK( visual );
592 Actor actor = Actor::New();
593 // For tesing the LoadResourceFunc is called, a big image size should be set, so the atlasing is not applied.
594 // Image with a size smaller than 512*512 will be uploaded as a part of the atlas.
597 const int height=513;
598 TestGlAbstraction& gl = application.GetGlAbstraction();
599 TraceCallStack& textureTrace = gl.GetTextureTrace();
600 textureTrace.Enable(true);
602 Integration::Bitmap* bitmap = Integration::Bitmap::New( Integration::Bitmap::BITMAP_2D_PACKED_PIXELS, ResourcePolicy::OWNED_DISCARD );
603 bitmap->GetPackedPixelsProfile()->ReserveBuffer( Pixel::RGBA8888, width, height,width, height );
605 TestVisualRender( application, actor, visual, 1u,
606 ImageDimensions(width, height),
607 Integration::ResourcePointer( bitmap ) );
609 DALI_TEST_EQUALS( textureTrace.FindMethod("BindTexture"), true, TEST_LOCATION );
611 visual.SetOffStage( actor );
612 DALI_TEST_CHECK( actor.GetRendererCount() == 0u );
617 int UtcDaliVisualFactoryGetImageVisual2(void)
619 ToolkitTestApplication application;
620 tet_infoline( "UtcDaliVisualFactoryGetImageVisual2: Request image visual with an image handle" );
622 VisualFactory factory = VisualFactory::Get();
623 DALI_TEST_CHECK( factory );
625 Image image = ResourceImage::New(TEST_IMAGE_FILE_NAME);
626 Visual::Base visual = factory.CreateVisual( image );
628 Actor actor = Actor::New();
629 // For tesing the LoadResourceFunc is called, a big image size should be set, so the atlasing is not applied.
630 // Image with a size smaller than 512*512 will be uploaded as a part of the atlas.
633 const int height=513;
635 Integration::Bitmap* bitmap = Integration::Bitmap::New( Integration::Bitmap::BITMAP_2D_PACKED_PIXELS, ResourcePolicy::OWNED_DISCARD );
636 bitmap->GetPackedPixelsProfile()->ReserveBuffer( Pixel::RGBA8888, width, height,width, height );
638 TestGlAbstraction& gl = application.GetGlAbstraction();
639 TraceCallStack& textureTrace = gl.GetTextureTrace();
640 textureTrace.Enable(true);
642 TestVisualRender( application, actor, visual, 1u,
643 ImageDimensions(width, height),
644 Integration::ResourcePointer(bitmap) );
646 DALI_TEST_EQUALS( textureTrace.FindMethod("BindTexture"), true, TEST_LOCATION );
651 int UtcDaliVisualFactoryGetImageVisual3(void)
653 ToolkitTestApplication application;
654 tet_infoline( "UtcDaliVisualFactoryGetImageVisual3: Request image visual with a Property::Map, test custom wrap mode and pixel area with atlasing" );
656 VisualFactory factory = VisualFactory::Get();
657 DALI_TEST_CHECK( factory );
659 // Test wrap mode with atlasing. Image with a size smaller than 512*512 will be uploaded as a part of the atlas.
662 const Vector4 pixelArea(-0.5f, -0.5f, 2.f, 2.f);
664 Property::Map propertyMap;
665 propertyMap.Insert( Visual::Property::TYPE, Visual::IMAGE );
666 propertyMap.Insert( ImageVisual::Property::URL, gImage_34_RGBA );
667 propertyMap.Insert( ImageVisual::Property::DESIRED_WIDTH, width );
668 propertyMap.Insert( ImageVisual::Property::DESIRED_HEIGHT, height );
669 propertyMap.Insert( ImageVisual::Property::SYNCHRONOUS_LOADING, true );
670 propertyMap.Insert( ImageVisual::Property::PIXEL_AREA, pixelArea );
671 propertyMap.Insert( ImageVisual::Property::WRAP_MODE_U, WrapMode::MIRRORED_REPEAT );
672 propertyMap.Insert( ImageVisual::Property::WRAP_MODE_V, WrapMode::REPEAT );
674 Visual::Base visual = factory.CreateVisual( propertyMap );
675 DALI_TEST_CHECK( visual );
677 Actor actor = Actor::New();
678 TestGlAbstraction& gl = application.GetGlAbstraction();
679 TraceCallStack& textureTrace = gl.GetTextureTrace();
680 textureTrace.Enable(true);
681 TraceCallStack& texParameterTrace = gl.GetTexParameterTrace();
682 texParameterTrace.Enable( true );
684 actor.SetSize( 200.f, 200.f );
685 Stage::GetCurrent().Add( actor );
686 visual.SetOnStage( actor );
689 application.SendNotification();
690 application.Render();
691 application.Render();
692 application.SendNotification();
693 BitmapLoader loader = BitmapLoader::GetLatestCreated();
694 DALI_TEST_CHECK( loader );
695 loader.WaitForLoading();// waiting until the image to be loaded
696 DALI_TEST_CHECK( loader.IsLoaded() );
698 DALI_TEST_CHECK( actor.GetRendererCount() == 1u );
700 DALI_TEST_EQUALS( textureTrace.FindMethod("BindTexture"), true, TEST_LOCATION );
702 // WITH atlasing, the wrapping is handled manually in shader, so the following gl function should not be called
703 std::stringstream out;
704 out << GL_TEXTURE_2D << ", " << GL_TEXTURE_WRAP_S << ", " << GL_MIRRORED_REPEAT;
705 DALI_TEST_CHECK( !texParameterTrace.FindMethodAndParams("TexParameteri", out.str()) );
707 out << GL_TEXTURE_2D << ", " << GL_TEXTURE_WRAP_T << ", " << GL_REPEAT;
708 DALI_TEST_CHECK( !texParameterTrace.FindMethodAndParams("TexParameteri", out.str()) );
710 // test the uniforms which used to handle the wrap mode
711 Renderer renderer = actor.GetRendererAt( 0u );
712 DALI_TEST_CHECK( renderer );
714 Property::Value pixelAreaValue = renderer.GetProperty( renderer.GetPropertyIndex( "pixelArea" ) );
715 DALI_TEST_EQUALS( pixelAreaValue.Get<Vector4>(), pixelArea, TEST_LOCATION );
716 Vector4 pixelAreaUniform;
717 DALI_TEST_CHECK( gl.GetUniformValue<Vector4>( "pixelArea", pixelAreaUniform ) );
718 DALI_TEST_EQUALS( pixelArea, pixelAreaUniform, Math::MACHINE_EPSILON_100, TEST_LOCATION );
720 Property::Value wrapModeValue = renderer.GetProperty( renderer.GetPropertyIndex( "wrapMode" ) );
721 Vector2 wrapMode( WrapMode::MIRRORED_REPEAT-1, WrapMode::REPEAT-1 );
722 DALI_TEST_EQUALS( wrapModeValue.Get<Vector2>(), wrapMode, TEST_LOCATION );
723 Vector2 wrapModeUniform;
724 DALI_TEST_CHECK( gl.GetUniformValue<Vector2>( "wrapMode", wrapModeUniform ) );
725 DALI_TEST_EQUALS( wrapMode, wrapModeUniform, Math::MACHINE_EPSILON_100, TEST_LOCATION );
727 visual.SetOffStage( actor );
728 DALI_TEST_CHECK( actor.GetRendererCount() == 0u );
733 int UtcDaliVisualFactoryGetImageVisual4(void)
735 ToolkitTestApplication application;
736 tet_infoline( "UtcDaliVisualFactoryGetImageVisual4: Request image visual with a Property::Map, test custom wrap mode and pixel area without atlasing" );
738 VisualFactory factory = VisualFactory::Get();
739 DALI_TEST_CHECK( factory );
741 // Test wrap mode without atlasing. Image with a size bigger than 512*512 will NOT be uploaded as a part of the atlas.
743 const int height=600;
744 const Vector4 pixelArea(-0.5f, -0.5f, 2.f, 2.f);
746 Property::Map propertyMap;
747 propertyMap.Insert( Visual::Property::TYPE, Visual::IMAGE );
748 propertyMap.Insert( ImageVisual::Property::URL, gImage_600_RGB );
749 propertyMap.Insert( ImageVisual::Property::DESIRED_WIDTH, width );
750 propertyMap.Insert( ImageVisual::Property::DESIRED_HEIGHT, height );
751 propertyMap.Insert( ImageVisual::Property::SYNCHRONOUS_LOADING, true );
752 propertyMap.Insert( ImageVisual::Property::PIXEL_AREA, pixelArea );
753 propertyMap.Insert( ImageVisual::Property::WRAP_MODE_U, WrapMode::MIRRORED_REPEAT );
754 propertyMap.Insert( ImageVisual::Property::WRAP_MODE_V, WrapMode::REPEAT );
756 Visual::Base visual = factory.CreateVisual( propertyMap );
757 DALI_TEST_CHECK( visual );
759 Actor actor = Actor::New();
760 TestGlAbstraction& gl = application.GetGlAbstraction();
761 TraceCallStack& textureTrace = gl.GetTextureTrace();
762 textureTrace.Enable(true);
763 TraceCallStack& texParameterTrace = gl.GetTexParameterTrace();
764 texParameterTrace.Enable( true );
766 actor.SetSize( 200.f, 200.f );
767 Stage::GetCurrent().Add( actor );
768 visual.SetOnStage( actor );
771 application.SendNotification();
772 application.Render();
773 application.Render();
774 application.SendNotification();
775 BitmapLoader loader = BitmapLoader::GetLatestCreated();
776 DALI_TEST_CHECK( loader );
777 loader.WaitForLoading();// waiting until the image to be loaded
778 DALI_TEST_CHECK( loader.IsLoaded() );
780 DALI_TEST_CHECK( actor.GetRendererCount() == 1u );
782 DALI_TEST_EQUALS( textureTrace.FindMethod("BindTexture"), true, TEST_LOCATION );
784 // WITHOUT atlasing, the wrapping is handled by setting gl texture parameters
785 std::stringstream out;
786 out << GL_TEXTURE_2D << ", " << GL_TEXTURE_WRAP_S << ", " << GL_MIRRORED_REPEAT;
787 DALI_TEST_CHECK( texParameterTrace.FindMethodAndParams("TexParameteri", out.str()) );
789 out << GL_TEXTURE_2D << ", " << GL_TEXTURE_WRAP_T << ", " << GL_REPEAT;
790 DALI_TEST_CHECK( texParameterTrace.FindMethodAndParams("TexParameteri", out.str()) );
792 // test the uniforms which used to handle the wrap mode
793 Renderer renderer = actor.GetRendererAt( 0u );
794 DALI_TEST_CHECK( renderer );
796 Property::Value pixelAreaValue = renderer.GetProperty( renderer.GetPropertyIndex( "pixelArea" ) );
797 DALI_TEST_EQUALS( pixelAreaValue.Get<Vector4>(), pixelArea, TEST_LOCATION );
798 Vector4 pixelAreaUniform;
799 DALI_TEST_CHECK( gl.GetUniformValue<Vector4>( "pixelArea", pixelAreaUniform ) );
800 DALI_TEST_EQUALS( pixelArea, pixelAreaUniform, Math::MACHINE_EPSILON_100, TEST_LOCATION );
802 Property::Index wrapModeIndex = renderer.GetPropertyIndex( "wrapMode" );
803 DALI_TEST_CHECK(wrapModeIndex == Property::INVALID_INDEX);
805 visual.SetOffStage( actor );
806 DALI_TEST_CHECK( actor.GetRendererCount() == 0u );
811 int UtcDaliVisualFactoryGetNPatchVisual1(void)
813 ToolkitTestApplication application;
814 tet_infoline( "UtcDaliVisualFactoryGetNPatchVisual1: Request 9-patch visual with a Property::Map" );
816 VisualFactory factory = VisualFactory::Get();
817 DALI_TEST_CHECK( factory );
819 const unsigned int ninePatchImageHeight = 18;
820 const unsigned int ninePatchImageWidth = 28;
821 StretchRanges stretchRangesX;
822 stretchRangesX.PushBack( Uint16Pair( 2, 3 ) );
823 StretchRanges stretchRangesY;
824 stretchRangesY.PushBack( Uint16Pair( 4, 5 ) );
825 Integration::ResourcePointer ninePatchResource = CustomizeNinePatch( application, ninePatchImageWidth, ninePatchImageHeight, stretchRangesX, stretchRangesY );
827 Property::Map propertyMap;
828 propertyMap.Insert( Visual::Property::TYPE, Visual::IMAGE );
829 propertyMap.Insert( ImageVisual::Property::URL, TEST_NPATCH_FILE_NAME );
831 tet_infoline( "whole grid" );
832 Visual::Base visual = factory.CreateVisual( propertyMap );
833 DALI_TEST_CHECK( visual );
835 Actor actor = Actor::New();
837 TestGlAbstraction& gl = application.GetGlAbstraction();
838 TraceCallStack& textureTrace = gl.GetTextureTrace();
839 textureTrace.Enable(true);
841 TestVisualRender( application, actor, visual, 1u,
842 ImageDimensions(ninePatchImageWidth, ninePatchImageHeight),
845 DALI_TEST_EQUALS( textureTrace.FindMethod("BindTexture"), true, TEST_LOCATION );
848 propertyMap.Insert( ImageVisual::Property::BORDER_ONLY, true );
850 tet_infoline( "border only" );
851 Visual::Base visual = factory.CreateVisual( propertyMap );
852 DALI_TEST_CHECK( visual );
854 Actor actor = Actor::New();
856 TestGlAbstraction& gl = application.GetGlAbstraction();
857 TraceCallStack& textureTrace = gl.GetTextureTrace();
858 textureTrace.Enable(true);
860 TestVisualRender( application, actor, visual, 1u,
861 ImageDimensions(ninePatchImageWidth, ninePatchImageHeight),
864 DALI_TEST_EQUALS( textureTrace.FindMethod("BindTexture"), true, TEST_LOCATION );
870 int UtcDaliVisualFactoryGetNPatchVisual2(void)
872 ToolkitTestApplication application;
873 tet_infoline( "UtcDaliVisualFactoryGetNPatchVisual2: Request n-patch visual with a Property::Map" );
875 VisualFactory factory = VisualFactory::Get();
876 DALI_TEST_CHECK( factory );
878 const unsigned int ninePatchImageWidth = 18;
879 const unsigned int ninePatchImageHeight = 28;
880 StretchRanges stretchRangesX;
881 stretchRangesX.PushBack( Uint16Pair( 2, 3 ) );
882 stretchRangesX.PushBack( Uint16Pair( 5, 7 ) );
883 stretchRangesX.PushBack( Uint16Pair( 12, 15 ) );
884 StretchRanges stretchRangesY;
885 stretchRangesY.PushBack( Uint16Pair( 4, 5 ) );
886 stretchRangesY.PushBack( Uint16Pair( 8, 12 ) );
887 stretchRangesY.PushBack( Uint16Pair( 15, 16 ) );
888 stretchRangesY.PushBack( Uint16Pair( 25, 27 ) );
889 Integration::ResourcePointer ninePatchResource = CustomizeNinePatch( application, ninePatchImageWidth, ninePatchImageHeight, stretchRangesX, stretchRangesY );
891 Property::Map propertyMap;
892 propertyMap.Insert( Visual::Property::TYPE, Visual::IMAGE );
893 propertyMap.Insert( ImageVisual::Property::URL, TEST_NPATCH_FILE_NAME );
895 Visual::Base visual = factory.CreateVisual( propertyMap );
896 DALI_TEST_CHECK( visual );
898 Actor actor = Actor::New();
899 TestGlAbstraction& gl = application.GetGlAbstraction();
900 TraceCallStack& textureTrace = gl.GetTextureTrace();
901 textureTrace.Enable(true);
903 TestVisualRender( application, actor, visual, 1u,
904 ImageDimensions(ninePatchImageWidth, ninePatchImageHeight),
908 DALI_TEST_EQUALS( textureTrace.FindMethod("BindTexture"), true, TEST_LOCATION );
910 visual.SetOffStage( actor );
911 DALI_TEST_CHECK( actor.GetRendererCount() == 0u );
914 propertyMap.Insert( ImageVisual::Property::BORDER_ONLY, true );
916 tet_infoline( "border only" );
917 Visual::Base visual = factory.CreateVisual( propertyMap );
918 DALI_TEST_CHECK( visual );
920 TestGlAbstraction& gl = application.GetGlAbstraction();
921 TraceCallStack& textureTrace = gl.GetTextureTrace();
922 textureTrace.Enable(true);
923 Actor actor = Actor::New();
924 TestVisualRender( application, actor, visual, 1u,
925 ImageDimensions(ninePatchImageWidth, ninePatchImageHeight),
929 DALI_TEST_EQUALS( textureTrace.FindMethod("BindTexture"), true, TEST_LOCATION );
931 visual.SetOffStage( actor );
932 DALI_TEST_CHECK( actor.GetRendererCount() == 0u );
938 int UtcDaliVisualFactoryGetNPatchVisual3(void)
940 ToolkitTestApplication application;
941 tet_infoline( "UtcDaliVisualFactoryGetNPatchVisual3: Request 9-patch visual with an image url" );
943 VisualFactory factory = VisualFactory::Get();
944 DALI_TEST_CHECK( factory );
946 const unsigned int ninePatchImageHeight = 18;
947 const unsigned int ninePatchImageWidth = 28;
948 StretchRanges stretchRangesX;
949 stretchRangesX.PushBack( Uint16Pair( 2, 3 ) );
950 StretchRanges stretchRangesY;
951 stretchRangesY.PushBack( Uint16Pair( 4, 5 ) );
952 Integration::ResourcePointer ninePatchResource = CustomizeNinePatch( application, ninePatchImageWidth, ninePatchImageHeight, stretchRangesX, stretchRangesY );
954 Visual::Base visual = factory.CreateVisual( TEST_NPATCH_FILE_NAME, ImageDimensions() );
955 DALI_TEST_CHECK( visual );
957 Actor actor = Actor::New();
959 TestGlAbstraction& gl = application.GetGlAbstraction();
960 TraceCallStack& textureTrace = gl.GetTextureTrace();
961 textureTrace.Enable(true);
963 TestVisualRender( application, actor, visual, 1u,
964 ImageDimensions(ninePatchImageWidth, ninePatchImageHeight),
967 DALI_TEST_EQUALS( textureTrace.FindMethod("BindTexture"), true, TEST_LOCATION );
972 int UtcDaliVisualFactoryGetNPatchVisual4(void)
974 ToolkitTestApplication application;
975 tet_infoline( "UtcDaliVisualFactoryGetNPatchVisual4: Request n-patch visual with an image url" );
977 VisualFactory factory = VisualFactory::Get();
978 DALI_TEST_CHECK( factory );
980 const unsigned int ninePatchImageHeight = 18;
981 const unsigned int ninePatchImageWidth = 28;
982 StretchRanges stretchRangesX;
983 stretchRangesX.PushBack( Uint16Pair( 2, 3 ) );
984 stretchRangesX.PushBack( Uint16Pair( 5, 7 ) );
985 stretchRangesX.PushBack( Uint16Pair( 12, 15 ) );
986 StretchRanges stretchRangesY;
987 stretchRangesY.PushBack( Uint16Pair( 4, 5 ) );
988 stretchRangesY.PushBack( Uint16Pair( 8, 12 ) );
989 stretchRangesY.PushBack( Uint16Pair( 15, 16 ) );
990 stretchRangesY.PushBack( Uint16Pair( 25, 27 ) );
991 Integration::ResourcePointer ninePatchResource = CustomizeNinePatch( application, ninePatchImageWidth, ninePatchImageHeight, stretchRangesX, stretchRangesY );
993 Visual::Base visual = factory.CreateVisual( TEST_NPATCH_FILE_NAME, ImageDimensions() );
994 DALI_TEST_CHECK( visual );
996 Actor actor = Actor::New();
998 TestGlAbstraction& gl = application.GetGlAbstraction();
999 TraceCallStack& textureTrace = gl.GetTextureTrace();
1000 textureTrace.Enable(true);
1002 TestVisualRender( application, actor, visual, 1u,
1003 ImageDimensions(ninePatchImageWidth, ninePatchImageHeight),
1004 ninePatchResource );
1006 DALI_TEST_EQUALS( textureTrace.FindMethod("BindTexture"), true, TEST_LOCATION );
1011 int UtcDaliVisualFactoryGetNPatchVisualN1(void)
1013 //This should still load but display an error image
1015 ToolkitTestApplication application;
1016 tet_infoline( "UtcDaliVisualFactoryGetNPatchVisualN: Request n-patch visual with an invalid image url" );
1018 VisualFactory factory = VisualFactory::Get();
1019 DALI_TEST_CHECK( factory );
1021 Visual::Base visual = factory.CreateVisual( "ERROR.9.jpg", ImageDimensions() );
1022 DALI_TEST_CHECK( visual );
1024 Actor actor = Actor::New();
1026 //The testkit still has to load a bitmap for the broken renderer image
1027 Integration::Bitmap* bitmap = Integration::Bitmap::New(Integration::Bitmap::BITMAP_2D_PACKED_PIXELS, ResourcePolicy::OWNED_DISCARD);
1028 bitmap->GetPackedPixelsProfile()->ReserveBuffer( Pixel::RGBA8888, 100, 100, 100, 100 );
1030 TestGlAbstraction& gl = application.GetGlAbstraction();
1031 TraceCallStack& textureTrace = gl.GetTextureTrace();
1032 textureTrace.Enable(true);
1034 TestVisualRender( application, actor, visual, 1u,
1036 Integration::ResourcePointer(bitmap) );
1038 DALI_TEST_EQUALS( textureTrace.FindMethod("BindTexture"), true, TEST_LOCATION );
1043 int UtcDaliVisualFactoryGetNPatchVisualN2(void)
1045 //This should still load but display an error image
1047 ToolkitTestApplication application;
1048 tet_infoline( "UtcDaliVisualFactoryGetNPatchVisualN: Request n-patch visual with an invalid URL" );
1050 VisualFactory factory = VisualFactory::Get();
1051 DALI_TEST_CHECK( factory );
1053 Property::Map propertyMap;
1054 propertyMap.Insert( Visual::Property::TYPE, Visual::IMAGE );
1055 propertyMap.Insert( ImageVisual::Property::URL, "ERROR.9.jpg" );
1057 Visual::Base visual = factory.CreateVisual( propertyMap );
1058 DALI_TEST_CHECK( visual );
1060 Actor actor = Actor::New();
1062 //The testkit still has to load a bitmap for the broken renderer image
1063 Integration::Bitmap* bitmap = Integration::Bitmap::New(Integration::Bitmap::BITMAP_2D_PACKED_PIXELS, ResourcePolicy::OWNED_DISCARD);
1064 bitmap->GetPackedPixelsProfile()->ReserveBuffer( Pixel::RGBA8888, 100, 100, 100, 100 );
1066 TestGlAbstraction& gl = application.GetGlAbstraction();
1067 TraceCallStack& textureTrace = gl.GetTextureTrace();
1068 textureTrace.Enable(true);
1070 TestVisualRender( application, actor, visual, 1u,
1072 Integration::ResourcePointer(bitmap) );
1074 DALI_TEST_EQUALS( textureTrace.FindMethod("BindTexture"), true, TEST_LOCATION );
1079 int UtcDaliVisualFactoryGetNPatchVisualN3(void)
1081 // Passing in an invalid visual type so we should not get a visual
1083 ToolkitTestApplication application;
1084 tet_infoline( "UtcDaliVisualFactoryGetNPatchVisualN: Request n-patch visual with an invalid visual type" );
1086 VisualFactory factory = VisualFactory::Get();
1087 DALI_TEST_CHECK( factory );
1089 Property::Map propertyMap;
1090 propertyMap.Insert( Visual::Property::TYPE, 111 );
1091 propertyMap.Insert( ImageVisual::Property::URL, "ERROR.9.jpg" );
1093 Visual::Base visual = factory.CreateVisual( propertyMap );
1094 DALI_TEST_CHECK( !visual );
1099 int UtcDaliVisualFactoryGetSvgVisual(void)
1101 ToolkitTestApplication application;
1102 tet_infoline( "UtcDaliVisualFactoryGetSvgVisual: Request svg visual with a svg url" );
1104 VisualFactory factory = VisualFactory::Get();
1105 Visual::Base visual = factory.CreateVisual( TEST_SVG_FILE_NAME, ImageDimensions() );
1106 DALI_TEST_CHECK( visual );
1108 TestGlAbstraction& gl = application.GetGlAbstraction();
1109 TraceCallStack& textureTrace = gl.GetTextureTrace();
1110 textureTrace.Enable(true);
1112 Actor actor = Actor::New();
1113 actor.SetSize( 200.f, 200.f );
1114 Stage::GetCurrent().Add( actor );
1115 visual.SetSize( Vector2(200.f, 200.f) );
1116 visual.SetOnStage( actor );
1117 application.SendNotification();
1118 application.Render();
1120 // renderer is not added to actor until the rasterization is completed.
1121 DALI_TEST_CHECK( actor.GetRendererCount() == 0u );
1123 EventThreadCallback* eventTrigger = EventThreadCallback::Get();
1124 CallbackBase* callback = eventTrigger->GetCallback();
1126 eventTrigger->WaitingForTrigger( 1 );// waiting until the svg image is rasterized.
1127 CallbackBase::Execute( *callback );
1129 // renderer is added to actor
1130 DALI_TEST_CHECK( actor.GetRendererCount() == 1u );
1132 // waiting for the resource uploading
1133 application.SendNotification();
1134 application.Render();
1136 DALI_TEST_EQUALS( textureTrace.FindMethod("BindTexture"), true, TEST_LOCATION );
1141 //Creates a mesh visual from the given propertyMap and tries to load it on stage in the given application.
1142 //This is expected to succeed, which will then pass the test.
1143 void MeshVisualLoadsCorrectlyTest( Property::Map& propertyMap, ToolkitTestApplication& application )
1145 VisualFactory factory = VisualFactory::Get();
1146 DALI_TEST_CHECK( factory );
1148 //Create a mesh visual.
1149 Visual::Base visual = factory.CreateVisual( propertyMap );
1150 DALI_TEST_CHECK( visual );
1152 //Create an actor on stage to house the visual.
1153 Actor actor = Actor::New();
1154 actor.SetSize( 200.f, 200.f );
1155 Stage::GetCurrent().Add( actor );
1156 visual.SetSize( Vector2( 200.f, 200.f ) );
1157 visual.SetOnStage( actor );
1159 //Ensure set on stage.
1160 DALI_TEST_EQUALS( actor.GetRendererCount(), 1u, TEST_LOCATION );
1162 //Attempt to render to queue resource load requests.
1163 application.SendNotification();
1164 application.Render( 0 );
1166 //Tell the platform abstraction that the required resources have been loaded.
1167 TestPlatformAbstraction& platform = application.GetPlatform();
1168 platform.SetAllResourceRequestsAsLoaded();
1170 //Render again to upload the now-loaded textures.
1171 application.SendNotification();
1172 application.Render( 0 );
1174 Matrix testScaleMatrix;
1175 testScaleMatrix.SetIdentityAndScale( Vector3( 1.0, -1.0, 1.0 ) );
1176 Matrix actualScaleMatrix;
1178 //Test to see if the object has been successfully loaded.
1179 DALI_TEST_CHECK( application.GetGlAbstraction().GetUniformValue<Matrix>( "uObjectMatrix", actualScaleMatrix ) );
1180 DALI_TEST_EQUALS( actualScaleMatrix, testScaleMatrix, Math::MACHINE_EPSILON_100, TEST_LOCATION );
1182 //Finish by setting off stage, and ensuring this was successful.
1183 visual.SetOffStage( actor );
1184 DALI_TEST_EQUALS( actor.GetRendererCount(), 0u, TEST_LOCATION );
1187 //Creates a mesh visual from the given propertyMap and tries to load it on stage in the given application.
1188 //This is expected to fail, which will then pass the test.
1189 void MeshVisualDoesNotLoadCorrectlyTest( Property::Map& propertyMap, ToolkitTestApplication& application )
1191 VisualFactory factory = VisualFactory::Get();
1192 DALI_TEST_CHECK( factory );
1194 //Create a mesh visual.
1195 Visual::Base visual = factory.CreateVisual( propertyMap );
1196 DALI_TEST_CHECK( visual );
1198 //Create an actor on stage to house the visual.
1199 Actor actor = Actor::New();
1200 actor.SetSize( 200.f, 200.f );
1201 Stage::GetCurrent().Add( actor );
1202 visual.SetSize( Vector2( 200.f, 200.f ) );
1203 visual.SetOnStage( actor );
1205 //Ensure set on stage.
1206 DALI_TEST_EQUALS( actor.GetRendererCount(), 1u, TEST_LOCATION );
1208 //Attempt to render to queue resource load requests.
1209 application.SendNotification();
1210 application.Render( 0 );
1212 //Tell the platform abstraction that the required resources have been loaded.
1213 TestPlatformAbstraction& platform = application.GetPlatform();
1214 platform.SetAllResourceRequestsAsLoaded();
1216 //Render again to upload the now-loaded textures.
1217 application.SendNotification();
1218 application.Render( 0 );
1220 //Test to see if the object has not been loaded, as expected.
1222 DALI_TEST_CHECK( !application.GetGlAbstraction().GetUniformValue<Matrix>( "uObjectMatrix", scaleMatrix ) );
1224 //Finish by setting off stage, and ensuring this was successful.
1225 visual.SetOffStage( actor );
1226 DALI_TEST_EQUALS( actor.GetRendererCount(), 0u, TEST_LOCATION );
1229 //Test if mesh loads correctly when supplied with only the bare minimum requirements, an object file.
1230 int UtcDaliVisualFactoryGetMeshVisual1(void)
1232 //Set up test application first, so everything else can be handled.
1233 ToolkitTestApplication application;
1235 tet_infoline( "UtcDaliVisualFactoryGetMeshVisual1: Request mesh visual with a valid object file only" );
1238 //Set up visual properties.
1239 Property::Map propertyMap;
1240 propertyMap.Insert( Visual::Property::TYPE, Visual::MESH );
1241 propertyMap.Insert( MeshVisual::Property::OBJECT_URL, TEST_OBJ_FILE_NAME );
1243 //Test to see if mesh loads correctly.
1244 MeshVisualLoadsCorrectlyTest( propertyMap, application );
1250 //Test if mesh loads correctly when supplied with an object file as well as a blank material file and images directory.
1251 int UtcDaliVisualFactoryGetMeshVisual2(void)
1253 //Set up test application first, so everything else can be handled.
1254 ToolkitTestApplication application;
1256 tet_infoline( "UtcDaliVisualFactoryGetMeshVisual2: Request mesh visual with blank material file and images directory" );
1258 //Set up visual properties.
1259 Property::Map propertyMap;
1260 propertyMap.Insert( Visual::Property::TYPE, Visual::MESH );
1261 propertyMap.Insert( MeshVisual::Property::OBJECT_URL, TEST_OBJ_FILE_NAME );
1262 propertyMap.Insert( MeshVisual::Property::MATERIAL_URL, "" );
1263 propertyMap.Insert( MeshVisual::Property::TEXTURES_PATH, "" );
1265 //Test to see if mesh loads correctly.
1266 MeshVisualLoadsCorrectlyTest( propertyMap, application );
1271 //Test if mesh loads correctly when supplied with all main parameters, an object file, a material file and a directory location.
1272 int UtcDaliVisualFactoryGetMeshVisual3(void)
1274 //Set up test application first, so everything else can be handled.
1275 ToolkitTestApplication application;
1277 tet_infoline( "UtcDaliVisualFactoryGetMeshVisual3: Request mesh visual with all parameters correct" );
1279 //Set up visual properties.
1280 Property::Map propertyMap;
1281 propertyMap.Insert( Visual::Property::TYPE, Visual::MESH );
1282 propertyMap.Insert( MeshVisual::Property::OBJECT_URL, TEST_OBJ_FILE_NAME );
1283 propertyMap.Insert( MeshVisual::Property::MATERIAL_URL, TEST_MTL_FILE_NAME );
1284 propertyMap.Insert( MeshVisual::Property::TEXTURES_PATH, TEST_RESOURCE_DIR "/" );
1286 //Test to see if mesh loads correctly.
1287 MeshVisualLoadsCorrectlyTest( propertyMap, application );
1292 //Test if mesh visual can load a correctly supplied mesh without a normal map or gloss map in the material file.
1293 int UtcDaliVisualFactoryGetMeshVisual4(void)
1295 //Set up test application first, so everything else can be handled.
1296 ToolkitTestApplication application;
1298 tet_infoline( "UtcDaliVisualFactoryGetMeshVisual4: Request mesh visual with diffuse texture but not normal or gloss." );
1301 //Set up visual properties.
1302 Property::Map propertyMap;
1303 propertyMap.Insert( Visual::Property::TYPE, Visual::MESH );
1304 propertyMap.Insert( MeshVisual::Property::OBJECT_URL, TEST_OBJ_FILE_NAME );
1305 propertyMap.Insert( MeshVisual::Property::MATERIAL_URL, TEST_SIMPLE_MTL_FILE_NAME );
1306 propertyMap.Insert( MeshVisual::Property::TEXTURES_PATH, TEST_RESOURCE_DIR "/" );
1308 //Test to see if mesh loads correctly.
1309 MeshVisualLoadsCorrectlyTest( propertyMap, application );
1315 //Test if mesh visual can load when made to use diffuse textures only.
1316 int UtcDaliVisualFactoryGetMeshVisual5(void)
1318 //Set up test application first, so everything else can be handled.
1319 ToolkitTestApplication application;
1321 tet_infoline( "UtcDaliVisualFactoryGetMeshVisual5: Request mesh visual and make it only use diffuse textures." );
1323 //Set up visual properties.
1324 Property::Map propertyMap;
1325 propertyMap.Insert( Visual::Property::TYPE, Visual::MESH );
1326 propertyMap.Insert( MeshVisual::Property::OBJECT_URL, TEST_OBJ_FILE_NAME );
1327 propertyMap.Insert( MeshVisual::Property::MATERIAL_URL, TEST_MTL_FILE_NAME );
1328 propertyMap.Insert( MeshVisual::Property::TEXTURES_PATH, TEST_RESOURCE_DIR "/" );
1329 propertyMap.Insert( MeshVisual::Property::SHADING_MODE, MeshVisual::ShadingMode::TEXTURED_WITH_SPECULAR_LIGHTING );
1331 //Test to see if mesh loads correctly.
1332 MeshVisualLoadsCorrectlyTest( propertyMap, application );
1338 //Test if mesh visual can load when made to not use the supplied textures.
1339 int UtcDaliVisualFactoryGetMeshVisual6(void)
1341 //Set up test application first, so everything else can be handled.
1342 ToolkitTestApplication application;
1344 tet_infoline( "UtcDaliVisualFactoryGetMeshVisual6: Request mesh visual and make it not use any textures." );
1346 //Set up visual properties.
1347 Property::Map propertyMap;
1348 propertyMap.Insert( Visual::Property::TYPE, Visual::MESH );
1349 propertyMap.Insert( MeshVisual::Property::OBJECT_URL, TEST_OBJ_FILE_NAME );
1350 propertyMap.Insert( MeshVisual::Property::MATERIAL_URL, TEST_MTL_FILE_NAME );
1351 propertyMap.Insert( MeshVisual::Property::TEXTURES_PATH, TEST_RESOURCE_DIR "/" );
1352 propertyMap.Insert( MeshVisual::Property::SHADING_MODE, MeshVisual::ShadingMode::TEXTURELESS_WITH_DIFFUSE_LIGHTING );
1354 //Test to see if mesh loads correctly.
1355 MeshVisualLoadsCorrectlyTest( propertyMap, application );
1359 //Test if mesh visual loads correctly when light position is manually set.
1360 int UtcDaliVisualFactoryGetMeshVisual7(void)
1362 //Set up test application first, so everything else can be handled.
1363 ToolkitTestApplication application;
1366 tet_infoline( "UtcDaliVisualFactoryGetMeshVisual7: Request mesh visual with custom light position." );
1368 //Set up visual properties.
1369 Property::Map propertyMap;
1370 propertyMap.Insert( Visual::Property::TYPE, Visual::MESH );
1371 propertyMap.Insert( MeshVisual::Property::OBJECT_URL, TEST_OBJ_FILE_NAME );
1372 propertyMap.Insert( MeshVisual::Property::MATERIAL_URL, TEST_MTL_FILE_NAME );
1373 propertyMap.Insert( MeshVisual::Property::TEXTURES_PATH, TEST_RESOURCE_DIR "/" );
1374 propertyMap.Insert( MeshVisual::Property::LIGHT_POSITION, Vector3( 0.0, 1.0, 2.0 ) );
1376 //Test to see if mesh loads correctly.
1377 MeshVisualLoadsCorrectlyTest( propertyMap, application );
1382 //Test if mesh visual loads correctly when supplied an object file without face normals or texture points.
1383 //Note that this notably tests object loader functionality.
1384 int UtcDaliVisualFactoryGetMeshVisual8(void)
1386 //Set up test application first, so everything else can be handled.
1387 ToolkitTestApplication application;
1389 tet_infoline( "UtcDaliVisualFactoryGetMeshVisual5: Request mesh visual with normal-less object file." );
1391 //Set up visual properties.
1392 Property::Map propertyMap;
1393 propertyMap.Insert( Visual::Property::TYPE, Visual::MESH );
1394 propertyMap.Insert( MeshVisual::Property::OBJECT_URL, TEST_SIMPLE_OBJ_FILE_NAME );
1395 propertyMap.Insert( MeshVisual::Property::MATERIAL_URL, TEST_MTL_FILE_NAME );
1396 propertyMap.Insert( MeshVisual::Property::TEXTURES_PATH, TEST_RESOURCE_DIR "/" );
1398 //Test to see if mesh loads correctly.
1399 MeshVisualLoadsCorrectlyTest( propertyMap, application );
1404 //Test if mesh visual handles the case of lacking an object file.
1405 int UtcDaliVisualFactoryGetMeshVisualN1(void)
1407 //Set up test application first, so everything else can be handled.
1408 ToolkitTestApplication application;
1410 tet_infoline( "UtcDaliVisualFactoryGetMeshVisualN1: Request mesh visual without object file" );
1412 //Set up visual properties.
1413 Property::Map propertyMap;
1414 propertyMap.Insert( Visual::Property::TYPE, Visual::MESH );
1415 propertyMap.Insert( MeshVisual::Property::MATERIAL_URL, TEST_MTL_FILE_NAME );
1416 propertyMap.Insert( MeshVisual::Property::TEXTURES_PATH, TEST_RESOURCE_DIR "/" );
1418 //Test to see if mesh doesn't load with these properties, as expected.
1419 MeshVisualDoesNotLoadCorrectlyTest( propertyMap, application );
1425 //Test if mesh visual handles the case of being passed invalid material and images urls.
1426 int UtcDaliVisualFactoryGetMeshVisualN2(void)
1428 //Set up test application first, so everything else can be handled.
1429 ToolkitTestApplication application;
1431 tet_infoline( "UtcDaliVisualFactoryGetMeshVisualN2: Request mesh visual with invalid material and images urls" );
1433 //Set up visual properties.
1434 Property::Map propertyMap;
1435 propertyMap.Insert( Visual::Property::TYPE, Visual::MESH );
1436 propertyMap.Insert( MeshVisual::Property::OBJECT_URL, TEST_OBJ_FILE_NAME );
1437 propertyMap.Insert( MeshVisual::Property::MATERIAL_URL, "invalid" );
1438 propertyMap.Insert( MeshVisual::Property::TEXTURES_PATH, "also invalid" );
1440 //Test to see if mesh doesn't load with these properties, as expected.
1441 MeshVisualDoesNotLoadCorrectlyTest( propertyMap, application );
1447 //Test if mesh visual handles the case of being passed an invalid object url
1448 int UtcDaliVisualFactoryGetMeshVisualN3(void)
1450 //Set up test application first, so everything else can be handled.
1451 ToolkitTestApplication application;
1452 tet_infoline( "UtcDaliVisualFactoryGetMeshVisualN3: Request mesh visual with invalid object url" );
1455 //Set up visual properties.
1456 Property::Map propertyMap;
1457 propertyMap.Insert( Visual::Property::TYPE, Visual::MESH );
1458 propertyMap.Insert( MeshVisual::Property::OBJECT_URL, "invalid" );
1459 propertyMap.Insert( MeshVisual::Property::MATERIAL_URL, TEST_MTL_FILE_NAME );
1460 propertyMap.Insert( MeshVisual::Property::TEXTURES_PATH, TEST_RESOURCE_DIR "/" );
1462 //Test to see if mesh doesn't load with these properties, as expected.
1463 MeshVisualDoesNotLoadCorrectlyTest( propertyMap, application );
1468 //Creates a primitive visual with the given property map and tests to see if it correctly loads in the given application.
1469 void TestPrimitiveVisualWithProperties( Property::Map& propertyMap, ToolkitTestApplication& application )
1471 VisualFactory factory = VisualFactory::Get();
1472 DALI_TEST_CHECK( factory );
1474 //Create a primitive visual.
1475 Visual::Base visual = factory.CreateVisual( propertyMap );
1476 DALI_TEST_CHECK( visual );
1478 //Create an actor on stage to house the visual.
1479 Actor actor = Actor::New();
1480 actor.SetSize( 200.f, 200.f );
1481 Stage::GetCurrent().Add( actor );
1482 visual.SetSize( Vector2( 200.f, 200.f ) );
1483 visual.SetOnStage( actor );
1485 //Ensure set on stage.
1486 DALI_TEST_EQUALS( actor.GetRendererCount(), 1u, TEST_LOCATION );
1488 //Tell test application to load the visual.
1489 application.SendNotification();
1490 application.Render(0);
1492 Matrix testScaleMatrix;
1493 testScaleMatrix.SetIdentityAndScale( Vector3( 1.0, -1.0, 1.0 ) );
1494 Matrix actualScaleMatrix;
1496 //Test to see if the object has been successfully loaded.
1497 DALI_TEST_CHECK( application.GetGlAbstraction().GetUniformValue<Matrix>( "uObjectMatrix", actualScaleMatrix ) );
1498 DALI_TEST_EQUALS( actualScaleMatrix, testScaleMatrix, Math::MACHINE_EPSILON_100, TEST_LOCATION );
1500 //Finish by setting off stage, and ensuring this was successful.
1501 visual.SetOffStage( actor );
1502 DALI_TEST_EQUALS( actor.GetRendererCount(), 0u, TEST_LOCATION );
1505 //Test if primitive shape loads correctly when supplied with only the bare minimum requirements, the shape to use.
1506 int UtcDaliVisualFactoryGetPrimitiveVisual1(void)
1508 //Set up test application first, so everything else can be handled.
1509 ToolkitTestApplication application;
1511 tet_infoline( "UtcDaliVisualFactoryGetPrimitiveVisual1: Request primitive visual with a shape only" );
1513 //Set up visual properties.
1514 Property::Map propertyMap;
1515 propertyMap.Insert( Visual::Property::TYPE, Visual::PRIMITIVE );
1516 propertyMap.Insert( PrimitiveVisual::Property::SHAPE, PrimitiveVisual::Shape::CUBE );
1518 //Test to see if shape loads correctly.
1519 TestPrimitiveVisualWithProperties( propertyMap, application );
1524 //Test if primitive shape loads correctly when supplied with all possible parameters
1525 int UtcDaliVisualFactoryGetPrimitiveVisual2(void)
1527 //Set up test application first, so everything else can be handled.
1528 ToolkitTestApplication application;
1530 tet_infoline( "UtcDaliVisualFactoryGetPrimitiveVisual2: Request primitive visual with everything" );
1532 //Set up visual properties.
1533 Property::Map propertyMap;
1534 propertyMap.Insert( Visual::Property::TYPE, Visual::PRIMITIVE );
1535 propertyMap.Insert( PrimitiveVisual::Property::SHAPE, PrimitiveVisual::Shape::CUBE );
1536 propertyMap.Insert( PrimitiveVisual::Property::MIX_COLOR, Vector4( 0.5, 0.5, 0.5, 1.0 ) );
1537 propertyMap.Insert( PrimitiveVisual::Property::SLICES, 10 );
1538 propertyMap.Insert( PrimitiveVisual::Property::STACKS, 20 );
1539 propertyMap.Insert( PrimitiveVisual::Property::SCALE_TOP_RADIUS, 30.0f );
1540 propertyMap.Insert( PrimitiveVisual::Property::SCALE_BOTTOM_RADIUS, 40.0f );
1541 propertyMap.Insert( PrimitiveVisual::Property::SCALE_HEIGHT, 50.0f );
1542 propertyMap.Insert( PrimitiveVisual::Property::SCALE_RADIUS, 60.0f );
1543 propertyMap.Insert( PrimitiveVisual::Property::BEVEL_PERCENTAGE, 0.7f );
1544 propertyMap.Insert( PrimitiveVisual::Property::BEVEL_SMOOTHNESS, 0.8f );
1545 propertyMap.Insert( MeshVisual::Property::LIGHT_POSITION, Vector3( 0.9, 1.0, 1.1 ) );
1547 //Test to see if shape loads correctly.
1548 TestPrimitiveVisualWithProperties( propertyMap, application );
1553 //Test if primitive shape loads a sphere correctly.
1554 int UtcDaliVisualFactoryGetPrimitiveVisual3(void)
1556 //Set up test application first, so everything else can be handled.
1557 ToolkitTestApplication application;
1559 tet_infoline( "UtcDaliVisualFactoryGetPrimitiveVisual3: Request primitive visual to display a sphere" );
1561 //Set up visual properties.
1562 Property::Map propertyMap;
1563 propertyMap.Insert( Visual::Property::TYPE, Visual::PRIMITIVE );
1564 propertyMap.Insert( PrimitiveVisual::Property::SHAPE, PrimitiveVisual::Shape::SPHERE );
1565 propertyMap.Insert( PrimitiveVisual::Property::MIX_COLOR, Vector4( 0.5, 0.5, 0.5, 1.0 ) );
1566 propertyMap.Insert( PrimitiveVisual::Property::SLICES, 10 );
1567 propertyMap.Insert( PrimitiveVisual::Property::STACKS, 20 );
1569 //Test to see if shape loads correctly.
1570 TestPrimitiveVisualWithProperties( propertyMap, application );
1575 //Test if primitive shape loads a conic section correctly.
1576 int UtcDaliVisualFactoryGetPrimitiveVisual4(void)
1578 //Set up test application first, so everything else can be handled.
1579 ToolkitTestApplication application;
1581 tet_infoline( "UtcDaliVisualFactoryGetPrimitiveVisual4: Request primitive visual to display a conic section" );
1583 //Set up visual properties.
1584 Property::Map propertyMap;
1585 propertyMap.Insert( Visual::Property::TYPE, Visual::PRIMITIVE );
1586 propertyMap.Insert( PrimitiveVisual::Property::SHAPE, PrimitiveVisual::Shape::CONICAL_FRUSTRUM );
1587 propertyMap.Insert( PrimitiveVisual::Property::MIX_COLOR, Vector4( 0.5, 0.5, 0.5, 1.0 ) );
1588 propertyMap.Insert( PrimitiveVisual::Property::SLICES, 10 );
1589 propertyMap.Insert( PrimitiveVisual::Property::SCALE_TOP_RADIUS, 30.0f );
1590 propertyMap.Insert( PrimitiveVisual::Property::SCALE_BOTTOM_RADIUS, 40.0f );
1591 propertyMap.Insert( PrimitiveVisual::Property::SCALE_HEIGHT, 50.0f );
1593 //Test to see if shape loads correctly.
1594 TestPrimitiveVisualWithProperties( propertyMap, application );
1599 //Test if primitive shape loads a bevelled cube correctly.
1600 int UtcDaliVisualFactoryGetPrimitiveVisual5(void)
1602 //Set up test application first, so everything else can be handled.
1603 ToolkitTestApplication application;
1605 tet_infoline( "UtcDaliVisualFactoryGetPrimitiveVisual5: Request primitive visual to display a bevelled cube" );
1607 //Set up visual properties.
1608 Property::Map propertyMap;
1609 propertyMap.Insert( Visual::Property::TYPE, Visual::PRIMITIVE );
1610 propertyMap.Insert( PrimitiveVisual::Property::SHAPE, PrimitiveVisual::Shape::BEVELLED_CUBE );
1611 propertyMap.Insert( PrimitiveVisual::Property::MIX_COLOR, Vector4( 0.5, 0.5, 0.5, 1.0 ) );
1612 propertyMap.Insert( PrimitiveVisual::Property::BEVEL_PERCENTAGE, 0.7f );
1614 //Test to see if shape loads correctly.
1615 TestPrimitiveVisualWithProperties( propertyMap, application );
1620 //Test if primitive shape loads an octahedron correctly.
1621 int UtcDaliVisualFactoryGetPrimitiveVisual6(void)
1623 //Set up test application first, so everything else can be handled.
1624 ToolkitTestApplication application;
1626 tet_infoline( "UtcDaliVisualFactoryGetPrimitiveVisual6: Request primitive visual to display an octahedron" );
1628 //Set up visual properties.
1629 Property::Map propertyMap;
1630 propertyMap.Insert( Visual::Property::TYPE, Visual::PRIMITIVE );
1631 propertyMap.Insert( PrimitiveVisual::Property::SHAPE, PrimitiveVisual::Shape::OCTAHEDRON );
1632 propertyMap.Insert( PrimitiveVisual::Property::MIX_COLOR, Vector4( 0.5, 0.5, 0.5, 1.0 ) );
1634 //Test to see if shape loads correctly.
1635 TestPrimitiveVisualWithProperties( propertyMap, application );
1640 //Test if primitive shape loads a cone correctly.
1641 int UtcDaliVisualFactoryGetPrimitiveVisual7(void)
1643 //Set up test application first, so everything else can be handled.
1644 ToolkitTestApplication application;
1646 tet_infoline( "UtcDaliVisualFactoryGetPrimitiveVisual7: Request primitive visual to display a cone" );
1648 //Set up visual properties.
1649 Property::Map propertyMap;
1650 propertyMap.Insert( Visual::Property::TYPE, Visual::PRIMITIVE );
1651 propertyMap.Insert( PrimitiveVisual::Property::SHAPE, PrimitiveVisual::Shape::CONE );
1652 propertyMap.Insert( PrimitiveVisual::Property::MIX_COLOR, Vector4( 0.5, 0.5, 0.5, 1.0 ) );
1653 propertyMap.Insert( PrimitiveVisual::Property::SLICES, 10 );
1654 propertyMap.Insert( PrimitiveVisual::Property::SCALE_TOP_RADIUS, 30.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 correctly when light position is manually set.
1664 int UtcDaliVisualFactoryGetPrimitiveVisual8(void)
1666 //Set up test application first, so everything else can be handled.
1667 ToolkitTestApplication application;
1669 tet_infoline( "UtcDaliVisualFactoryGetPrimitiveVisual8: Request primitive visual with set light position" );
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::SPHERE );
1675 propertyMap.Insert( PrimitiveVisual::Property::MIX_COLOR, Vector4( 0.5, 0.5, 0.5, 1.0 ) );
1676 propertyMap.Insert( MeshVisual::Property::LIGHT_POSITION, Vector3( 0.0, 1.0, 2.0 ) );
1678 //Test to see if shape loads correctly.
1679 TestPrimitiveVisualWithProperties( propertyMap, application );
1684 //Test if primitive shape loads correctly when told to use too many slices.
1685 int UtcDaliVisualFactoryGetPrimitiveVisual9(void)
1687 //Set up test application first, so everything else can be handled.
1688 ToolkitTestApplication application;
1690 tet_infoline( "UtcDaliVisualFactoryGetPrimitiveVisual9: Request primitive visual with above-cap slices." );
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::SPHERE );
1696 propertyMap.Insert( PrimitiveVisual::Property::SLICES, Property::Value( 1000000 ) );
1698 //Test to see if shape loads correctly.
1699 TestPrimitiveVisualWithProperties( propertyMap, application );
1704 //Test if primitive shape loads correctly when told to use too few slices. (2 slices or less.)
1705 int UtcDaliVisualFactoryGetPrimitiveVisual10(void)
1707 //Set up test application first, so everything else can be handled.
1708 ToolkitTestApplication application;
1710 tet_infoline( "UtcDaliVisualFactoryGetPrimitiveVisual10: Request primitive visual with too few slices." );
1712 //Set up visual properties.
1713 Property::Map propertyMap;
1714 propertyMap.Insert( Visual::Property::TYPE, Visual::PRIMITIVE );
1715 propertyMap.Insert( PrimitiveVisual::Property::SHAPE, PrimitiveVisual::Shape::SPHERE );
1716 propertyMap.Insert( PrimitiveVisual::Property::SLICES, Property::Value( 2 ) );
1718 //Test to see if shape loads correctly.
1719 TestPrimitiveVisualWithProperties( propertyMap, application );
1724 //Test if primitive shape loads correctly when told to use too many stacks.
1725 int UtcDaliVisualFactoryGetPrimitiveVisual11(void)
1727 //Set up test application first, so everything else can be handled.
1728 ToolkitTestApplication application;
1730 tet_infoline( "UtcDaliVisualFactoryGetPrimitiveVisual11: Request primitive visual with too many stacks." );
1732 //Set up visual properties.
1733 Property::Map propertyMap;
1734 propertyMap.Insert( Visual::Property::TYPE, Visual::PRIMITIVE );
1735 propertyMap.Insert( PrimitiveVisual::Property::SHAPE, PrimitiveVisual::Shape::SPHERE );
1736 propertyMap.Insert( PrimitiveVisual::Property::STACKS, Property::Value( 1000000 ) );
1738 //Test to see if shape loads correctly.
1739 TestPrimitiveVisualWithProperties( propertyMap, application );
1744 //Test if primitive shape loads correctly when told to use too few stacks. (1 stack or less.)
1745 int UtcDaliVisualFactoryGetPrimitiveVisual12(void)
1747 //Set up test application first, so everything else can be handled.
1748 ToolkitTestApplication application;
1750 tet_infoline( "UtcDaliVisualFactoryGetPrimitiveVisual12: Request primitive visual with too few stacks." );
1752 //Set up visual properties.
1753 Property::Map propertyMap;
1754 propertyMap.Insert( Visual::Property::TYPE, Visual::PRIMITIVE );
1755 propertyMap.Insert( PrimitiveVisual::Property::SHAPE, PrimitiveVisual::Shape::SPHERE );
1756 propertyMap.Insert( PrimitiveVisual::Property::STACKS, Property::Value( 1 ) );
1758 //Test to see if shape loads correctly.
1759 TestPrimitiveVisualWithProperties( propertyMap, application );
1764 //Test if primitive shape loads correctly when told to use invalid (zero or negative) dimensions.
1765 int UtcDaliVisualFactoryGetPrimitiveVisual13(void)
1767 //Set up test application first, so everything else can be handled.
1768 ToolkitTestApplication application;
1770 tet_infoline( "UtcDaliVisualFactoryGetPrimitiveVisual13: Request primitive visual with invalid scale dimensions." );
1772 //Set up visual properties.
1773 Property::Map propertyMap;
1774 propertyMap.Insert( Visual::Property::TYPE, Visual::PRIMITIVE );
1775 propertyMap.Insert( PrimitiveVisual::Property::SHAPE, PrimitiveVisual::Shape::SPHERE );
1776 propertyMap.Insert( PrimitiveVisual::Property::SCALE_DIMENSIONS, Vector3::ZERO );
1778 //Test to see if shape loads correctly.
1779 TestPrimitiveVisualWithProperties( propertyMap, application );
1784 //Test if primitive shape loads correctly when told to use too low a bevel percentage.
1785 int UtcDaliVisualFactoryGetPrimitiveVisual14(void)
1787 //Set up test application first, so everything else can be handled.
1788 ToolkitTestApplication application;
1790 tet_infoline( "UtcDaliVisualFactoryGetPrimitiveVisual14: Request primitive visual with too low a bevel percentage." );
1792 //Set up visual properties.
1793 Property::Map propertyMap;
1794 propertyMap.Insert( Visual::Property::TYPE, Visual::PRIMITIVE );
1795 propertyMap.Insert( PrimitiveVisual::Property::SHAPE, PrimitiveVisual::Shape::SPHERE );
1796 propertyMap.Insert( PrimitiveVisual::Property::BEVEL_PERCENTAGE, Property::Value( -1.0f ) );
1798 //Test to see if shape loads correctly.
1799 TestPrimitiveVisualWithProperties( propertyMap, application );
1804 //Test if primitive shape loads correctly when told to use too high a bevel percentage.
1805 int UtcDaliVisualFactoryGetPrimitiveVisual15(void)
1807 //Set up test application first, so everything else can be handled.
1808 ToolkitTestApplication application;
1810 tet_infoline( "UtcDaliVisualFactoryGetPrimitiveVisual15: Request primitive visual with too high a bevel percentage." );
1812 //Set up visual properties.
1813 Property::Map propertyMap;
1814 propertyMap.Insert( Visual::Property::TYPE, Visual::PRIMITIVE );
1815 propertyMap.Insert( PrimitiveVisual::Property::SHAPE, PrimitiveVisual::Shape::SPHERE );
1816 propertyMap.Insert( PrimitiveVisual::Property::BEVEL_PERCENTAGE, Property::Value( 2.0f ) );
1818 //Test to see if shape loads correctly.
1819 TestPrimitiveVisualWithProperties( propertyMap, application );
1824 //Test if primitive shape loads correctly when told to use too low a bevel smoothness.
1825 int UtcDaliVisualFactoryGetPrimitiveVisual16(void)
1827 //Set up test application first, so everything else can be handled.
1828 ToolkitTestApplication application;
1830 tet_infoline( "UtcDaliVisualFactoryGetPrimitiveVisual16: Request primitive visual with too low a bevel smoothness." );
1832 //Set up visual properties.
1833 Property::Map propertyMap;
1834 propertyMap.Insert( Visual::Property::TYPE, Visual::PRIMITIVE );
1835 propertyMap.Insert( PrimitiveVisual::Property::SHAPE, PrimitiveVisual::Shape::SPHERE );
1836 propertyMap.Insert( PrimitiveVisual::Property::BEVEL_SMOOTHNESS, Property::Value( -1.0f ) );
1838 //Test to see if shape loads correctly.
1839 TestPrimitiveVisualWithProperties( propertyMap, application );
1844 //Test if primitive shape loads correctly when told to use too high a bevel smoothness.
1845 int UtcDaliVisualFactoryGetPrimitiveVisual17(void)
1847 //Set up test application first, so everything else can be handled.
1848 ToolkitTestApplication application;
1850 tet_infoline( "UtcDaliVisualFactoryGetPrimitiveVisual17: Request primitive visual with too high a bevel smoothness." );
1852 //Set up visual properties.
1853 Property::Map propertyMap;
1854 propertyMap.Insert( Visual::Property::TYPE, Visual::PRIMITIVE );
1855 propertyMap.Insert( PrimitiveVisual::Property::SHAPE, PrimitiveVisual::Shape::SPHERE );
1856 propertyMap.Insert( PrimitiveVisual::Property::BEVEL_SMOOTHNESS, Property::Value( 2.0f ) );
1858 //Test to see if shape loads correctly.
1859 TestPrimitiveVisualWithProperties( propertyMap, application );
1864 //Test if primitive shape visual handles the case of not being passed a specific shape to use.
1865 int UtcDaliVisualFactoryGetPrimitiveVisualN1(void)
1867 //Set up test application first, so everything else can be handled.
1868 ToolkitTestApplication application;
1870 tet_infoline( "UtcDaliVisualFactoryGetPrimitiveVisualN1: Request primitive visual without shape" );
1872 //Set up visual properties, without supplying shape.
1873 Property::Map propertyMap;
1874 propertyMap.Insert( Visual::Property::TYPE, Visual::PRIMITIVE );
1876 //Test to see if shape loads regardless of missing input.
1877 TestPrimitiveVisualWithProperties( propertyMap, application );
1882 int UtcDaliVisualFactoryGetBatchImageVisual1(void)
1884 ToolkitTestApplication application;
1885 tet_infoline( "UtcDaliVisualFactoryGetBatchImageVisual1: Request a Batch Image visual with a Property::Map" );
1887 VisualFactory factory = VisualFactory::Get();
1888 DALI_TEST_CHECK( factory );
1890 Property::Map propertyMap;
1891 propertyMap.Insert( Visual::Property::TYPE, Visual::IMAGE );
1892 propertyMap.Insert( ImageVisual::Property::BATCHING_ENABLED, true );
1893 propertyMap.Insert( ImageVisual::Property::URL, TEST_IMAGE_FILE_NAME );
1895 Visual::Base visual = factory.CreateVisual( propertyMap );
1896 DALI_TEST_CHECK( visual );
1898 Actor actor = Actor::New();
1900 actor.SetSize( 200.0f, 200.0f );
1901 Stage::GetCurrent().Add( actor );
1902 visual.SetSize( Vector2( 200.0f, 200.0f ) );
1904 // Test SetOnStage().
1905 visual.SetOnStage( actor );
1906 DALI_TEST_CHECK( actor.GetRendererCount() == 1u );
1908 application.SendNotification();
1909 application.Render();
1911 // Test SetOffStage().
1912 visual.SetOffStage( actor );
1913 DALI_TEST_CHECK( actor.GetRendererCount() == 0u );
1918 int UtcDaliVisualFactoryGetBatchImageVisual2(void)
1920 ToolkitTestApplication application;
1921 tet_infoline( "UtcDaliVisualFactoryGetBatchImageVisual2: Request Batch Image visual from an Image Visual with batchingEnabled set" );
1923 VisualFactory factory = VisualFactory::Get();
1924 DALI_TEST_CHECK( factory );
1926 Property::Map propertyMap;
1927 // Create a normal Image Visual.
1928 propertyMap.Insert( Visual::Property::TYPE, Visual::IMAGE );
1929 // Instruct the factory to change Image Visuals to Batch-Image Visuals.
1930 propertyMap.Insert( ImageVisual::Property::BATCHING_ENABLED, true );
1932 // Properties for the Batch-Image Visual.
1933 propertyMap.Insert( ImageVisual::Property::URL, TEST_IMAGE_FILE_NAME );
1935 Visual::Base visual = factory.CreateVisual( propertyMap );
1936 DALI_TEST_CHECK( visual );
1938 // Check that a Batch-Image visual was created instead of an Image visual.
1939 Property::Map resultMap;
1940 visual.CreatePropertyMap( resultMap );
1942 Property::Value* value = resultMap.Find( Visual::Property::TYPE, Property::INTEGER );
1943 DALI_TEST_CHECK( value );
1944 DALI_TEST_EQUALS( value->Get<int>(), (int)Visual::IMAGE, TEST_LOCATION );
1946 Actor actor = Actor::New();
1948 actor.SetSize( 200.0f, 200.0f );
1949 Stage::GetCurrent().Add( actor );
1950 visual.SetSize( Vector2( 200.0f, 200.0f ) );
1952 // Test SetOnStage().
1953 visual.SetOnStage( actor );
1954 DALI_TEST_CHECK( actor.GetRendererCount() == 1u );
1956 application.SendNotification();
1957 application.Render();
1959 // Test SetOffStage().
1960 visual.SetOffStage( actor );
1961 DALI_TEST_CHECK( actor.GetRendererCount() == 0u );
1966 int UtcDaliVisualFactoryGetBatchImageVisual3(void)
1968 ToolkitTestApplication application;
1969 tet_infoline( "UtcDaliVisualFactoryGetBatchImageVisual3: Create an ImageView that uses a batched visual internally" );
1971 VisualFactory factory = VisualFactory::Get();
1972 DALI_TEST_CHECK( factory );
1974 // Create a property-map that enables batching.
1975 Property::Map propertyMap;
1976 propertyMap.Insert( Dali::Toolkit::ImageVisual::Property::URL, TEST_IMAGE_FILE_NAME );
1977 propertyMap.Insert( ImageVisual::Property::BATCHING_ENABLED, true );
1979 // Create an ImageView, passing the property-map in to instruct it to use batching.
1980 Toolkit::ImageView imageView = Toolkit::ImageView::New();
1981 imageView.SetProperty( Toolkit::ImageView::Property::IMAGE, propertyMap );
1983 imageView.SetSize( 200.0f, 200.0f );
1984 Stage::GetCurrent().Add( imageView );