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 DALI_TEST_CHECK( actor.GetRendererCount() == 1u );
1122 EventThreadCallback* eventTrigger = EventThreadCallback::Get();
1123 CallbackBase* callback = eventTrigger->GetCallback();
1125 eventTrigger->WaitingForTrigger( 1 );// waiting until the svg image is rasterized.
1126 CallbackBase::Execute( *callback );
1128 DALI_TEST_CHECK( actor.GetRendererCount() == 1u );
1130 // waiting for the resource uploading
1131 application.SendNotification();
1132 application.Render();
1134 DALI_TEST_EQUALS( textureTrace.FindMethod("BindTexture"), true, TEST_LOCATION );
1139 //Creates a mesh visual from the given propertyMap and tries to load it on stage in the given application.
1140 //This is expected to succeed, which will then pass the test.
1141 void MeshVisualLoadsCorrectlyTest( Property::Map& propertyMap, ToolkitTestApplication& application )
1143 VisualFactory factory = VisualFactory::Get();
1144 DALI_TEST_CHECK( factory );
1146 //Create a mesh visual.
1147 Visual::Base visual = factory.CreateVisual( propertyMap );
1148 DALI_TEST_CHECK( visual );
1150 //Create an actor on stage to house the visual.
1151 Actor actor = Actor::New();
1152 actor.SetSize( 200.f, 200.f );
1153 Stage::GetCurrent().Add( actor );
1154 visual.SetSize( Vector2( 200.f, 200.f ) );
1155 visual.SetOnStage( actor );
1157 //Ensure set on stage.
1158 DALI_TEST_EQUALS( actor.GetRendererCount(), 1u, TEST_LOCATION );
1160 //Attempt to render to queue resource load requests.
1161 application.SendNotification();
1162 application.Render( 0 );
1164 //Tell the platform abstraction that the required resources have been loaded.
1165 TestPlatformAbstraction& platform = application.GetPlatform();
1166 platform.SetAllResourceRequestsAsLoaded();
1168 //Render again to upload the now-loaded textures.
1169 application.SendNotification();
1170 application.Render( 0 );
1172 Matrix testScaleMatrix;
1173 testScaleMatrix.SetIdentityAndScale( Vector3( 1.0, -1.0, 1.0 ) );
1174 Matrix actualScaleMatrix;
1176 //Test to see if the object has been successfully loaded.
1177 DALI_TEST_CHECK( application.GetGlAbstraction().GetUniformValue<Matrix>( "uObjectMatrix", actualScaleMatrix ) );
1178 DALI_TEST_EQUALS( actualScaleMatrix, testScaleMatrix, Math::MACHINE_EPSILON_100, TEST_LOCATION );
1180 //Finish by setting off stage, and ensuring this was successful.
1181 visual.SetOffStage( actor );
1182 DALI_TEST_EQUALS( actor.GetRendererCount(), 0u, TEST_LOCATION );
1185 //Creates a mesh visual from the given propertyMap and tries to load it on stage in the given application.
1186 //This is expected to fail, which will then pass the test.
1187 void MeshVisualDoesNotLoadCorrectlyTest( Property::Map& propertyMap, ToolkitTestApplication& application )
1189 VisualFactory factory = VisualFactory::Get();
1190 DALI_TEST_CHECK( factory );
1192 //Create a mesh visual.
1193 Visual::Base visual = factory.CreateVisual( propertyMap );
1194 DALI_TEST_CHECK( visual );
1196 //Create an actor on stage to house the visual.
1197 Actor actor = Actor::New();
1198 actor.SetSize( 200.f, 200.f );
1199 Stage::GetCurrent().Add( actor );
1200 visual.SetSize( Vector2( 200.f, 200.f ) );
1201 visual.SetOnStage( actor );
1203 //Ensure set on stage.
1204 DALI_TEST_EQUALS( actor.GetRendererCount(), 1u, TEST_LOCATION );
1206 //Attempt to render to queue resource load requests.
1207 application.SendNotification();
1208 application.Render( 0 );
1210 //Tell the platform abstraction that the required resources have been loaded.
1211 TestPlatformAbstraction& platform = application.GetPlatform();
1212 platform.SetAllResourceRequestsAsLoaded();
1214 //Render again to upload the now-loaded textures.
1215 application.SendNotification();
1216 application.Render( 0 );
1218 //Test to see if the object has not been loaded, as expected.
1220 DALI_TEST_CHECK( !application.GetGlAbstraction().GetUniformValue<Matrix>( "uObjectMatrix", scaleMatrix ) );
1222 //Finish by setting off stage, and ensuring this was successful.
1223 visual.SetOffStage( actor );
1224 DALI_TEST_EQUALS( actor.GetRendererCount(), 0u, TEST_LOCATION );
1227 //Test if mesh loads correctly when supplied with only the bare minimum requirements, an object file.
1228 int UtcDaliVisualFactoryGetMeshVisual1(void)
1230 //Set up test application first, so everything else can be handled.
1231 ToolkitTestApplication application;
1233 tet_infoline( "UtcDaliVisualFactoryGetMeshVisual1: Request mesh visual with a valid object file only" );
1236 //Set up visual properties.
1237 Property::Map propertyMap;
1238 propertyMap.Insert( Visual::Property::TYPE, Visual::MESH );
1239 propertyMap.Insert( MeshVisual::Property::OBJECT_URL, TEST_OBJ_FILE_NAME );
1241 //Test to see if mesh loads correctly.
1242 MeshVisualLoadsCorrectlyTest( propertyMap, application );
1248 //Test if mesh loads correctly when supplied with an object file as well as a blank material file and images directory.
1249 int UtcDaliVisualFactoryGetMeshVisual2(void)
1251 //Set up test application first, so everything else can be handled.
1252 ToolkitTestApplication application;
1254 tet_infoline( "UtcDaliVisualFactoryGetMeshVisual2: Request mesh visual with blank material file and images directory" );
1256 //Set up visual properties.
1257 Property::Map propertyMap;
1258 propertyMap.Insert( Visual::Property::TYPE, Visual::MESH );
1259 propertyMap.Insert( MeshVisual::Property::OBJECT_URL, TEST_OBJ_FILE_NAME );
1260 propertyMap.Insert( MeshVisual::Property::MATERIAL_URL, "" );
1261 propertyMap.Insert( MeshVisual::Property::TEXTURES_PATH, "" );
1263 //Test to see if mesh loads correctly.
1264 MeshVisualLoadsCorrectlyTest( propertyMap, application );
1269 //Test if mesh loads correctly when supplied with all main parameters, an object file, a material file and a directory location.
1270 int UtcDaliVisualFactoryGetMeshVisual3(void)
1272 //Set up test application first, so everything else can be handled.
1273 ToolkitTestApplication application;
1275 tet_infoline( "UtcDaliVisualFactoryGetMeshVisual3: Request mesh visual with all parameters correct" );
1277 //Set up visual properties.
1278 Property::Map propertyMap;
1279 propertyMap.Insert( Visual::Property::TYPE, Visual::MESH );
1280 propertyMap.Insert( MeshVisual::Property::OBJECT_URL, TEST_OBJ_FILE_NAME );
1281 propertyMap.Insert( MeshVisual::Property::MATERIAL_URL, TEST_MTL_FILE_NAME );
1282 propertyMap.Insert( MeshVisual::Property::TEXTURES_PATH, TEST_RESOURCE_DIR "/" );
1284 //Test to see if mesh loads correctly.
1285 MeshVisualLoadsCorrectlyTest( propertyMap, application );
1290 //Test if mesh visual can load a correctly supplied mesh without a normal map or gloss map in the material file.
1291 int UtcDaliVisualFactoryGetMeshVisual4(void)
1293 //Set up test application first, so everything else can be handled.
1294 ToolkitTestApplication application;
1296 tet_infoline( "UtcDaliVisualFactoryGetMeshVisual4: Request mesh visual with diffuse texture but not normal or gloss." );
1299 //Set up visual properties.
1300 Property::Map propertyMap;
1301 propertyMap.Insert( Visual::Property::TYPE, Visual::MESH );
1302 propertyMap.Insert( MeshVisual::Property::OBJECT_URL, TEST_OBJ_FILE_NAME );
1303 propertyMap.Insert( MeshVisual::Property::MATERIAL_URL, TEST_SIMPLE_MTL_FILE_NAME );
1304 propertyMap.Insert( MeshVisual::Property::TEXTURES_PATH, TEST_RESOURCE_DIR "/" );
1306 //Test to see if mesh loads correctly.
1307 MeshVisualLoadsCorrectlyTest( propertyMap, application );
1313 //Test if mesh visual can load when made to use diffuse textures only.
1314 int UtcDaliVisualFactoryGetMeshVisual5(void)
1316 //Set up test application first, so everything else can be handled.
1317 ToolkitTestApplication application;
1319 tet_infoline( "UtcDaliVisualFactoryGetMeshVisual5: Request mesh visual and make it only use diffuse textures." );
1321 //Set up visual properties.
1322 Property::Map propertyMap;
1323 propertyMap.Insert( Visual::Property::TYPE, Visual::MESH );
1324 propertyMap.Insert( MeshVisual::Property::OBJECT_URL, TEST_OBJ_FILE_NAME );
1325 propertyMap.Insert( MeshVisual::Property::MATERIAL_URL, TEST_MTL_FILE_NAME );
1326 propertyMap.Insert( MeshVisual::Property::TEXTURES_PATH, TEST_RESOURCE_DIR "/" );
1327 propertyMap.Insert( MeshVisual::Property::SHADING_MODE, MeshVisual::ShadingMode::TEXTURED_WITH_SPECULAR_LIGHTING );
1329 //Test to see if mesh loads correctly.
1330 MeshVisualLoadsCorrectlyTest( propertyMap, application );
1336 //Test if mesh visual can load when made to not use the supplied textures.
1337 int UtcDaliVisualFactoryGetMeshVisual6(void)
1339 //Set up test application first, so everything else can be handled.
1340 ToolkitTestApplication application;
1342 tet_infoline( "UtcDaliVisualFactoryGetMeshVisual6: Request mesh visual and make it not use any textures." );
1344 //Set up visual properties.
1345 Property::Map propertyMap;
1346 propertyMap.Insert( Visual::Property::TYPE, Visual::MESH );
1347 propertyMap.Insert( MeshVisual::Property::OBJECT_URL, TEST_OBJ_FILE_NAME );
1348 propertyMap.Insert( MeshVisual::Property::MATERIAL_URL, TEST_MTL_FILE_NAME );
1349 propertyMap.Insert( MeshVisual::Property::TEXTURES_PATH, TEST_RESOURCE_DIR "/" );
1350 propertyMap.Insert( MeshVisual::Property::SHADING_MODE, MeshVisual::ShadingMode::TEXTURELESS_WITH_DIFFUSE_LIGHTING );
1352 //Test to see if mesh loads correctly.
1353 MeshVisualLoadsCorrectlyTest( propertyMap, application );
1357 //Test if mesh visual loads correctly when light position is manually set.
1358 int UtcDaliVisualFactoryGetMeshVisual7(void)
1360 //Set up test application first, so everything else can be handled.
1361 ToolkitTestApplication application;
1364 tet_infoline( "UtcDaliVisualFactoryGetMeshVisual7: Request mesh visual with custom light position." );
1366 //Set up visual properties.
1367 Property::Map propertyMap;
1368 propertyMap.Insert( Visual::Property::TYPE, Visual::MESH );
1369 propertyMap.Insert( MeshVisual::Property::OBJECT_URL, TEST_OBJ_FILE_NAME );
1370 propertyMap.Insert( MeshVisual::Property::MATERIAL_URL, TEST_MTL_FILE_NAME );
1371 propertyMap.Insert( MeshVisual::Property::TEXTURES_PATH, TEST_RESOURCE_DIR "/" );
1372 propertyMap.Insert( MeshVisual::Property::LIGHT_POSITION, Vector3( 0.0, 1.0, 2.0 ) );
1374 //Test to see if mesh loads correctly.
1375 MeshVisualLoadsCorrectlyTest( propertyMap, application );
1380 //Test if mesh visual loads correctly when supplied an object file without face normals or texture points.
1381 //Note that this notably tests object loader functionality.
1382 int UtcDaliVisualFactoryGetMeshVisual8(void)
1384 //Set up test application first, so everything else can be handled.
1385 ToolkitTestApplication application;
1387 tet_infoline( "UtcDaliVisualFactoryGetMeshVisual5: Request mesh visual with normal-less object file." );
1389 //Set up visual properties.
1390 Property::Map propertyMap;
1391 propertyMap.Insert( Visual::Property::TYPE, Visual::MESH );
1392 propertyMap.Insert( MeshVisual::Property::OBJECT_URL, TEST_SIMPLE_OBJ_FILE_NAME );
1393 propertyMap.Insert( MeshVisual::Property::MATERIAL_URL, TEST_MTL_FILE_NAME );
1394 propertyMap.Insert( MeshVisual::Property::TEXTURES_PATH, TEST_RESOURCE_DIR "/" );
1396 //Test to see if mesh loads correctly.
1397 MeshVisualLoadsCorrectlyTest( propertyMap, application );
1402 //Test if mesh visual handles the case of lacking an object file.
1403 int UtcDaliVisualFactoryGetMeshVisualN1(void)
1405 //Set up test application first, so everything else can be handled.
1406 ToolkitTestApplication application;
1408 tet_infoline( "UtcDaliVisualFactoryGetMeshVisualN1: Request mesh visual without object file" );
1410 //Set up visual properties.
1411 Property::Map propertyMap;
1412 propertyMap.Insert( Visual::Property::TYPE, Visual::MESH );
1413 propertyMap.Insert( MeshVisual::Property::MATERIAL_URL, TEST_MTL_FILE_NAME );
1414 propertyMap.Insert( MeshVisual::Property::TEXTURES_PATH, TEST_RESOURCE_DIR "/" );
1416 //Test to see if mesh doesn't load with these properties, as expected.
1417 MeshVisualDoesNotLoadCorrectlyTest( propertyMap, application );
1423 //Test if mesh visual handles the case of being passed invalid material and images urls.
1424 int UtcDaliVisualFactoryGetMeshVisualN2(void)
1426 //Set up test application first, so everything else can be handled.
1427 ToolkitTestApplication application;
1429 tet_infoline( "UtcDaliVisualFactoryGetMeshVisualN2: Request mesh visual with invalid material and images urls" );
1431 //Set up visual properties.
1432 Property::Map propertyMap;
1433 propertyMap.Insert( Visual::Property::TYPE, Visual::MESH );
1434 propertyMap.Insert( MeshVisual::Property::OBJECT_URL, TEST_OBJ_FILE_NAME );
1435 propertyMap.Insert( MeshVisual::Property::MATERIAL_URL, "invalid" );
1436 propertyMap.Insert( MeshVisual::Property::TEXTURES_PATH, "also invalid" );
1438 //Test to see if mesh doesn't load with these properties, as expected.
1439 MeshVisualDoesNotLoadCorrectlyTest( propertyMap, application );
1445 //Test if mesh visual handles the case of being passed an invalid object url
1446 int UtcDaliVisualFactoryGetMeshVisualN3(void)
1448 //Set up test application first, so everything else can be handled.
1449 ToolkitTestApplication application;
1450 tet_infoline( "UtcDaliVisualFactoryGetMeshVisualN3: Request mesh visual with invalid object url" );
1453 //Set up visual properties.
1454 Property::Map propertyMap;
1455 propertyMap.Insert( Visual::Property::TYPE, Visual::MESH );
1456 propertyMap.Insert( MeshVisual::Property::OBJECT_URL, "invalid" );
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 doesn't load with these properties, as expected.
1461 MeshVisualDoesNotLoadCorrectlyTest( propertyMap, application );
1466 //Creates a primitive visual with the given property map and tests to see if it correctly loads in the given application.
1467 void TestPrimitiveVisualWithProperties( Property::Map& propertyMap, ToolkitTestApplication& application )
1469 VisualFactory factory = VisualFactory::Get();
1470 DALI_TEST_CHECK( factory );
1472 //Create a primitive visual.
1473 Visual::Base visual = factory.CreateVisual( propertyMap );
1474 DALI_TEST_CHECK( visual );
1476 //Create an actor on stage to house the visual.
1477 Actor actor = Actor::New();
1478 actor.SetSize( 200.f, 200.f );
1479 Stage::GetCurrent().Add( actor );
1480 visual.SetSize( Vector2( 200.f, 200.f ) );
1481 visual.SetOnStage( actor );
1483 //Ensure set on stage.
1484 DALI_TEST_EQUALS( actor.GetRendererCount(), 1u, TEST_LOCATION );
1486 //Tell test application to load the visual.
1487 application.SendNotification();
1488 application.Render(0);
1490 Matrix testScaleMatrix;
1491 testScaleMatrix.SetIdentityAndScale( Vector3( 1.0, -1.0, 1.0 ) );
1492 Matrix actualScaleMatrix;
1494 //Test to see if the object has been successfully loaded.
1495 DALI_TEST_CHECK( application.GetGlAbstraction().GetUniformValue<Matrix>( "uObjectMatrix", actualScaleMatrix ) );
1496 DALI_TEST_EQUALS( actualScaleMatrix, testScaleMatrix, Math::MACHINE_EPSILON_100, TEST_LOCATION );
1498 //Finish by setting off stage, and ensuring this was successful.
1499 visual.SetOffStage( actor );
1500 DALI_TEST_EQUALS( actor.GetRendererCount(), 0u, TEST_LOCATION );
1503 //Test if primitive shape loads correctly when supplied with only the bare minimum requirements, the shape to use.
1504 int UtcDaliVisualFactoryGetPrimitiveVisual1(void)
1506 //Set up test application first, so everything else can be handled.
1507 ToolkitTestApplication application;
1509 tet_infoline( "UtcDaliVisualFactoryGetPrimitiveVisual1: Request primitive visual with a shape only" );
1511 //Set up visual properties.
1512 Property::Map propertyMap;
1513 propertyMap.Insert( Visual::Property::TYPE, Visual::PRIMITIVE );
1514 propertyMap.Insert( PrimitiveVisual::Property::SHAPE, PrimitiveVisual::Shape::CUBE );
1516 //Test to see if shape loads correctly.
1517 TestPrimitiveVisualWithProperties( propertyMap, application );
1522 //Test if primitive shape loads correctly when supplied with all possible parameters
1523 int UtcDaliVisualFactoryGetPrimitiveVisual2(void)
1525 //Set up test application first, so everything else can be handled.
1526 ToolkitTestApplication application;
1528 tet_infoline( "UtcDaliVisualFactoryGetPrimitiveVisual2: Request primitive visual with everything" );
1530 //Set up visual properties.
1531 Property::Map propertyMap;
1532 propertyMap.Insert( Visual::Property::TYPE, Visual::PRIMITIVE );
1533 propertyMap.Insert( PrimitiveVisual::Property::SHAPE, PrimitiveVisual::Shape::CUBE );
1534 propertyMap.Insert( PrimitiveVisual::Property::COLOR, Vector4( 0.5, 0.5, 0.5, 1.0 ) );
1535 propertyMap.Insert( PrimitiveVisual::Property::SLICES, 10 );
1536 propertyMap.Insert( PrimitiveVisual::Property::STACKS, 20 );
1537 propertyMap.Insert( PrimitiveVisual::Property::SCALE_TOP_RADIUS, 30.0f );
1538 propertyMap.Insert( PrimitiveVisual::Property::SCALE_BOTTOM_RADIUS, 40.0f );
1539 propertyMap.Insert( PrimitiveVisual::Property::SCALE_HEIGHT, 50.0f );
1540 propertyMap.Insert( PrimitiveVisual::Property::SCALE_RADIUS, 60.0f );
1541 propertyMap.Insert( PrimitiveVisual::Property::BEVEL_PERCENTAGE, 0.7f );
1542 propertyMap.Insert( PrimitiveVisual::Property::BEVEL_SMOOTHNESS, 0.8f );
1543 propertyMap.Insert( MeshVisual::Property::LIGHT_POSITION, Vector3( 0.9, 1.0, 1.1 ) );
1545 //Test to see if shape loads correctly.
1546 TestPrimitiveVisualWithProperties( propertyMap, application );
1551 //Test if primitive shape loads a sphere correctly.
1552 int UtcDaliVisualFactoryGetPrimitiveVisual3(void)
1554 //Set up test application first, so everything else can be handled.
1555 ToolkitTestApplication application;
1557 tet_infoline( "UtcDaliVisualFactoryGetPrimitiveVisual3: Request primitive visual to display a sphere" );
1559 //Set up visual properties.
1560 Property::Map propertyMap;
1561 propertyMap.Insert( Visual::Property::TYPE, Visual::PRIMITIVE );
1562 propertyMap.Insert( PrimitiveVisual::Property::SHAPE, PrimitiveVisual::Shape::SPHERE );
1563 propertyMap.Insert( PrimitiveVisual::Property::COLOR, Vector4( 0.5, 0.5, 0.5, 1.0 ) );
1564 propertyMap.Insert( PrimitiveVisual::Property::SLICES, 10 );
1565 propertyMap.Insert( PrimitiveVisual::Property::STACKS, 20 );
1567 //Test to see if shape loads correctly.
1568 TestPrimitiveVisualWithProperties( propertyMap, application );
1573 //Test if primitive shape loads a conic section correctly.
1574 int UtcDaliVisualFactoryGetPrimitiveVisual4(void)
1576 //Set up test application first, so everything else can be handled.
1577 ToolkitTestApplication application;
1579 tet_infoline( "UtcDaliVisualFactoryGetPrimitiveVisual4: Request primitive visual to display a conic section" );
1581 //Set up visual properties.
1582 Property::Map propertyMap;
1583 propertyMap.Insert( Visual::Property::TYPE, Visual::PRIMITIVE );
1584 propertyMap.Insert( PrimitiveVisual::Property::SHAPE, PrimitiveVisual::Shape::CONICAL_FRUSTRUM );
1585 propertyMap.Insert( PrimitiveVisual::Property::COLOR, Vector4( 0.5, 0.5, 0.5, 1.0 ) );
1586 propertyMap.Insert( PrimitiveVisual::Property::SLICES, 10 );
1587 propertyMap.Insert( PrimitiveVisual::Property::SCALE_TOP_RADIUS, 30.0f );
1588 propertyMap.Insert( PrimitiveVisual::Property::SCALE_BOTTOM_RADIUS, 40.0f );
1589 propertyMap.Insert( PrimitiveVisual::Property::SCALE_HEIGHT, 50.0f );
1591 //Test to see if shape loads correctly.
1592 TestPrimitiveVisualWithProperties( propertyMap, application );
1597 //Test if primitive shape loads a bevelled cube correctly.
1598 int UtcDaliVisualFactoryGetPrimitiveVisual5(void)
1600 //Set up test application first, so everything else can be handled.
1601 ToolkitTestApplication application;
1603 tet_infoline( "UtcDaliVisualFactoryGetPrimitiveVisual5: Request primitive visual to display a bevelled cube" );
1605 //Set up visual properties.
1606 Property::Map propertyMap;
1607 propertyMap.Insert( Visual::Property::TYPE, Visual::PRIMITIVE );
1608 propertyMap.Insert( PrimitiveVisual::Property::SHAPE, PrimitiveVisual::Shape::BEVELLED_CUBE );
1609 propertyMap.Insert( PrimitiveVisual::Property::COLOR, Vector4( 0.5, 0.5, 0.5, 1.0 ) );
1610 propertyMap.Insert( PrimitiveVisual::Property::BEVEL_PERCENTAGE, 0.7f );
1612 //Test to see if shape loads correctly.
1613 TestPrimitiveVisualWithProperties( propertyMap, application );
1618 //Test if primitive shape loads an octahedron correctly.
1619 int UtcDaliVisualFactoryGetPrimitiveVisual6(void)
1621 //Set up test application first, so everything else can be handled.
1622 ToolkitTestApplication application;
1624 tet_infoline( "UtcDaliVisualFactoryGetPrimitiveVisual6: Request primitive visual to display an octahedron" );
1626 //Set up visual properties.
1627 Property::Map propertyMap;
1628 propertyMap.Insert( Visual::Property::TYPE, Visual::PRIMITIVE );
1629 propertyMap.Insert( PrimitiveVisual::Property::SHAPE, PrimitiveVisual::Shape::OCTAHEDRON );
1630 propertyMap.Insert( PrimitiveVisual::Property::COLOR, Vector4( 0.5, 0.5, 0.5, 1.0 ) );
1632 //Test to see if shape loads correctly.
1633 TestPrimitiveVisualWithProperties( propertyMap, application );
1638 //Test if primitive shape loads a cone correctly.
1639 int UtcDaliVisualFactoryGetPrimitiveVisual7(void)
1641 //Set up test application first, so everything else can be handled.
1642 ToolkitTestApplication application;
1644 tet_infoline( "UtcDaliVisualFactoryGetPrimitiveVisual7: Request primitive visual to display a cone" );
1646 //Set up visual properties.
1647 Property::Map propertyMap;
1648 propertyMap.Insert( Visual::Property::TYPE, Visual::PRIMITIVE );
1649 propertyMap.Insert( PrimitiveVisual::Property::SHAPE, PrimitiveVisual::Shape::CONE );
1650 propertyMap.Insert( PrimitiveVisual::Property::COLOR, Vector4( 0.5, 0.5, 0.5, 1.0 ) );
1651 propertyMap.Insert( PrimitiveVisual::Property::SLICES, 10 );
1652 propertyMap.Insert( PrimitiveVisual::Property::SCALE_TOP_RADIUS, 30.0f );
1653 propertyMap.Insert( PrimitiveVisual::Property::SCALE_HEIGHT, 50.0f );
1655 //Test to see if shape loads correctly.
1656 TestPrimitiveVisualWithProperties( propertyMap, application );
1661 //Test if primitive shape loads correctly when light position is manually set.
1662 int UtcDaliVisualFactoryGetPrimitiveVisual8(void)
1664 //Set up test application first, so everything else can be handled.
1665 ToolkitTestApplication application;
1667 tet_infoline( "UtcDaliVisualFactoryGetPrimitiveVisual8: Request primitive visual with set light position" );
1669 //Set up visual properties.
1670 Property::Map propertyMap;
1671 propertyMap.Insert( Visual::Property::TYPE, Visual::PRIMITIVE );
1672 propertyMap.Insert( PrimitiveVisual::Property::SHAPE, PrimitiveVisual::Shape::SPHERE );
1673 propertyMap.Insert( PrimitiveVisual::Property::COLOR, Vector4( 0.5, 0.5, 0.5, 1.0 ) );
1674 propertyMap.Insert( MeshVisual::Property::LIGHT_POSITION, Vector3( 0.0, 1.0, 2.0 ) );
1676 //Test to see if shape loads correctly.
1677 TestPrimitiveVisualWithProperties( propertyMap, application );
1682 //Test if primitive shape visual handles the case of not being passed a specific shape to use.
1683 int UtcDaliVisualFactoryGetPrimitiveVisualN1(void)
1685 //Set up test application first, so everything else can be handled.
1686 ToolkitTestApplication application;
1688 tet_infoline( "UtcDaliVisualFactoryGetPrimitiveVisualN1: Request primitive visual without shape" );
1690 //Set up visual properties, without supplying shape.
1691 Property::Map propertyMap;
1692 propertyMap.Insert( Visual::Property::TYPE, Visual::PRIMITIVE );
1694 //Test to see if shape loads regardless of missing input.
1695 TestPrimitiveVisualWithProperties( propertyMap, application );
1700 int UtcDaliVisualFactoryGetBatchImageVisual1(void)
1702 ToolkitTestApplication application;
1703 tet_infoline( "UtcDaliVisualFactoryGetBatchImageVisual1: Request a Batch Image visual with a Property::Map" );
1705 VisualFactory factory = VisualFactory::Get();
1706 DALI_TEST_CHECK( factory );
1708 Property::Map propertyMap;
1709 propertyMap.Insert( Visual::Property::TYPE, Visual::IMAGE );
1710 propertyMap.Insert( ImageVisual::Property::BATCHING_ENABLED, true );
1711 propertyMap.Insert( ImageVisual::Property::URL, TEST_IMAGE_FILE_NAME );
1713 Visual::Base visual = factory.CreateVisual( propertyMap );
1714 DALI_TEST_CHECK( visual );
1716 Actor actor = Actor::New();
1718 actor.SetSize( 200.0f, 200.0f );
1719 Stage::GetCurrent().Add( actor );
1720 visual.SetSize( Vector2( 200.0f, 200.0f ) );
1722 // Test SetOnStage().
1723 visual.SetOnStage( actor );
1724 DALI_TEST_CHECK( actor.GetRendererCount() == 1u );
1726 application.SendNotification();
1727 application.Render();
1729 // Test SetOffStage().
1730 visual.SetOffStage( actor );
1731 DALI_TEST_CHECK( actor.GetRendererCount() == 0u );
1736 int UtcDaliVisualFactoryGetBatchImageVisual2(void)
1738 ToolkitTestApplication application;
1739 tet_infoline( "UtcDaliVisualFactoryGetBatchImageVisual2: Request Batch Image visual from an Image Visual with batchingEnabled set" );
1741 VisualFactory factory = VisualFactory::Get();
1742 DALI_TEST_CHECK( factory );
1744 Property::Map propertyMap;
1745 // Create a normal Image Visual.
1746 propertyMap.Insert( Visual::Property::TYPE, Visual::IMAGE );
1747 // Instruct the factory to change Image Visuals to Batch-Image Visuals.
1748 propertyMap.Insert( ImageVisual::Property::BATCHING_ENABLED, true );
1750 // Properties for the Batch-Image Visual.
1751 propertyMap.Insert( ImageVisual::Property::URL, TEST_IMAGE_FILE_NAME );
1753 Visual::Base visual = factory.CreateVisual( propertyMap );
1754 DALI_TEST_CHECK( visual );
1756 // Check that a Batch-Image visual was created instead of an Image visual.
1757 Property::Map resultMap;
1758 visual.CreatePropertyMap( resultMap );
1760 Property::Value* value = resultMap.Find( Visual::Property::TYPE, Property::INTEGER );
1761 DALI_TEST_CHECK( value );
1762 DALI_TEST_EQUALS( value->Get<int>(), (int)Visual::IMAGE, TEST_LOCATION );
1764 Actor actor = Actor::New();
1766 actor.SetSize( 200.0f, 200.0f );
1767 Stage::GetCurrent().Add( actor );
1768 visual.SetSize( Vector2( 200.0f, 200.0f ) );
1770 // Test SetOnStage().
1771 visual.SetOnStage( actor );
1772 DALI_TEST_CHECK( actor.GetRendererCount() == 1u );
1774 application.SendNotification();
1775 application.Render();
1777 // Test SetOffStage().
1778 visual.SetOffStage( actor );
1779 DALI_TEST_CHECK( actor.GetRendererCount() == 0u );
1784 int UtcDaliVisualFactoryGetBatchImageVisual3(void)
1786 ToolkitTestApplication application;
1787 tet_infoline( "UtcDaliVisualFactoryGetBatchImageVisual3: Create an ImageView that uses a batched visual internally" );
1789 VisualFactory factory = VisualFactory::Get();
1790 DALI_TEST_CHECK( factory );
1792 // Create a property-map that enables batching.
1793 Property::Map propertyMap;
1794 propertyMap.Insert( Dali::Toolkit::ImageVisual::Property::URL, TEST_IMAGE_FILE_NAME );
1795 propertyMap.Insert( ImageVisual::Property::BATCHING_ENABLED, true );
1797 // Create an ImageView, passing the property-map in to instruct it to use batching.
1798 Toolkit::ImageView imageView = Toolkit::ImageView::New();
1799 imageView.SetProperty( Toolkit::ImageView::Property::IMAGE, propertyMap );
1801 imageView.SetSize( 200.0f, 200.0f );
1802 Stage::GetCurrent().Add( imageView );