2 * Copyright (c) 2017 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-timer.h>
21 #include <toolkit-bitmap-loader.h>
22 #include <toolkit-event-thread-callback.h>
23 #include <dali/public-api/rendering/renderer.h>
24 #include <dali/public-api/rendering/texture-set.h>
25 #include <dali/public-api/rendering/shader.h>
26 #include <dali/devel-api/images/nine-patch-image.h>
27 #include <dali-toolkit/devel-api/align-enums.h>
28 #include <dali-toolkit/devel-api/visuals/visual-properties-devel.h>
29 #include <dali-toolkit/devel-api/visuals/image-visual-properties-devel.h>
30 #include <dali-toolkit/devel-api/visual-factory/visual-factory.h>
31 #include <dali-toolkit/dali-toolkit.h>
32 #include "dummy-control.h"
35 using namespace Dali::Toolkit;
39 typedef NinePatchImage::StretchRanges StretchRanges;
41 const char* TEST_NPATCH_FILE_NAME = TEST_RESOURCE_DIR "/button-up-1.9.png";
42 const char* TEST_SVG_FILE_NAME = TEST_RESOURCE_DIR "/svg1.svg";
43 const char* TEST_OBJ_FILE_NAME = TEST_RESOURCE_DIR "/Cube.obj";
44 const char* TEST_MTL_FILE_NAME = TEST_RESOURCE_DIR "/ToyRobot-Metal.mtl";
45 const char* TEST_SIMPLE_OBJ_FILE_NAME = TEST_RESOURCE_DIR "/Cube-Points-Only.obj";
46 const char* TEST_SIMPLE_MTL_FILE_NAME = TEST_RESOURCE_DIR "/ToyRobot-Metal-Simple.mtl";
48 // resolution: 50*50, frame count: 4, frame delay: 0.2 second for each frame
49 const char* TEST_GIF_FILE_NAME = TEST_RESOURCE_DIR "/anim.gif";
51 // resolution: 34*34, pixel format: RGBA8888
52 static const char* gImage_34_RGBA = TEST_RESOURCE_DIR "/icon-edit.png";
55 Property::Map DefaultTransform()
57 Property::Map transformMap;
59 .Add( Toolkit::DevelVisual::Transform::Property::OFFSET, Vector2(0.0f, 0.0f) )
60 .Add( Toolkit::DevelVisual::Transform::Property::SIZE, Vector2(1.0f, 1.0f) )
61 .Add( Toolkit::DevelVisual::Transform::Property::ORIGIN, Toolkit::Align::CENTER )
62 .Add( Toolkit::DevelVisual::Transform::Property::ANCHOR_POINT, Toolkit::Align::CENTER )
63 .Add( Toolkit::DevelVisual::Transform::Property::OFFSET_POLICY, Vector2( Toolkit::DevelVisual::Transform::Policy::RELATIVE, Toolkit::DevelVisual::Transform::Policy::RELATIVE ) )
64 .Add( Toolkit::DevelVisual::Transform::Property::SIZE_POLICY, Vector2( Toolkit::DevelVisual::Transform::Policy::RELATIVE, Toolkit::DevelVisual::Transform::Policy::RELATIVE ) );
68 Integration::Bitmap* CreateBitmap( unsigned int imageWidth, unsigned int imageHeight, unsigned int initialColor, Pixel::Format pixelFormat )
70 Integration::Bitmap* bitmap = Integration::Bitmap::New( Integration::Bitmap::BITMAP_2D_PACKED_PIXELS, ResourcePolicy::OWNED_RETAIN );
71 Integration::PixelBuffer* pixbuffer = bitmap->GetPackedPixelsProfile()->ReserveBuffer( pixelFormat, imageWidth, imageHeight, imageWidth, imageHeight );
72 unsigned int bytesPerPixel = GetBytesPerPixel( pixelFormat );
74 memset( pixbuffer, initialColor, imageHeight * imageWidth * bytesPerPixel );
79 void InitialiseRegionsToZeroAlpha( Integration::Bitmap* image, unsigned int imageWidth, unsigned int imageHeight, Pixel::Format pixelFormat )
81 PixelBuffer* pixbuffer = image->GetBuffer();
82 unsigned int bytesPerPixel = GetBytesPerPixel( pixelFormat );
84 for( unsigned int row = 0; row < imageWidth; ++row )
86 unsigned int pixelOffset = row * bytesPerPixel;
87 pixbuffer[ pixelOffset + 3 ] = 0x00;
88 pixelOffset += ( imageHeight - 1 ) * imageWidth * bytesPerPixel;
89 pixbuffer[ pixelOffset + 3 ] = 0x00;
92 for ( unsigned int column = 0; column < imageHeight; ++column )
94 unsigned int pixelOffset = column * imageWidth * bytesPerPixel;
95 pixbuffer[ pixelOffset + 3 ] = 0x00;
96 pixelOffset += ( imageWidth -1 ) * bytesPerPixel;
97 pixbuffer[ pixelOffset + 3 ] = 0x00;
101 void AddStretchRegionsToImage( Integration::Bitmap* image, unsigned int imageWidth, unsigned int imageHeight, const StretchRanges& stretchRangesX, const StretchRanges& stretchRangesY, Pixel::Format pixelFormat )
103 PixelBuffer* pixbuffer = image->GetBuffer();
104 unsigned int bytesPerPixel = GetBytesPerPixel( pixelFormat );
106 for(StretchRanges::ConstIterator it = stretchRangesX.Begin(); it != stretchRangesX.End(); ++it)
108 const Uint16Pair& range = *it;
109 //since the stretch range is in the cropped image space, we need to offset by 1 to get it to the uncropped image space
110 for( unsigned int column = range.GetX() + 1u; column < range.GetY() + 1u; ++column )
112 unsigned int pixelOffset = column * bytesPerPixel;
113 pixbuffer[ pixelOffset ] = 0x00;
114 pixbuffer[ pixelOffset + 1 ] = 0x00;
115 pixbuffer[ pixelOffset + 2 ] = 0x00;
116 pixbuffer[ pixelOffset + 3 ] = 0xFF;
121 for(StretchRanges::ConstIterator it = stretchRangesY.Begin(); it != stretchRangesY.End(); ++it)
123 const Uint16Pair& range = *it;
124 //since the stretch range is in the cropped image space, we need to offset by 1 to get it to the uncropped image space
125 for( unsigned int row = range.GetX() + 1u; row < range.GetY() + 1u; ++row )
127 unsigned int pixelOffset = row * imageWidth * bytesPerPixel;
128 pixbuffer[ pixelOffset ] = 0x00;
129 pixbuffer[ pixelOffset + 1 ] = 0x00;
130 pixbuffer[ pixelOffset + 2 ] = 0x00;
131 pixbuffer[ pixelOffset + 3 ] = 0xFF;
136 void AddChildRegionsToImage( Integration::Bitmap* image, unsigned int imageWidth, unsigned int imageHeight, const Vector4& requiredChildRegion, Pixel::Format pixelFormat )
138 PixelBuffer* pixbuffer = image->GetBuffer();
139 unsigned int bytesPerPixel = GetBytesPerPixel( pixelFormat );
141 Integration::Bitmap::PackedPixelsProfile* srcProfile = image->GetPackedPixelsProfile();
142 unsigned int bufferStride = srcProfile->GetBufferStride();
144 // Add bottom child region
145 for( unsigned int column = requiredChildRegion.x; column < imageWidth - requiredChildRegion.z; ++column )
147 unsigned int pixelOffset = column * bytesPerPixel;
148 pixelOffset += ( imageHeight - 1 ) * bufferStride;
149 pixbuffer[ pixelOffset ] = 0x00;
150 pixbuffer[ pixelOffset + 1 ] = 0x00;
151 pixbuffer[ pixelOffset + 2 ] = 0x00;
152 pixbuffer[ pixelOffset + 3 ] = 0xFF;
155 // Add right child region
156 for ( unsigned int row = requiredChildRegion.y; row < imageHeight - requiredChildRegion.w; ++row )
158 unsigned int pixelOffset = row * bufferStride + ( imageWidth - 1 ) * bytesPerPixel;
159 pixbuffer[ pixelOffset ] = 0x00;
160 pixbuffer[ pixelOffset + 1 ] = 0x00;
161 pixbuffer[ pixelOffset + 2 ] = 0x00;
162 pixbuffer[ pixelOffset + 3 ] = 0xFF;
166 Integration::ResourcePointer CustomizeNinePatch( TestApplication& application,
167 unsigned int ninePatchImageWidth,
168 unsigned int ninePatchImageHeight,
169 const StretchRanges& stretchRangesX,
170 const StretchRanges& stretchRangesY,
171 bool addChildRegion = false,
172 Vector4 requiredChildRegion = Vector4::ZERO )
174 TestPlatformAbstraction& platform = application.GetPlatform();
176 Pixel::Format pixelFormat = Pixel::RGBA8888;
178 tet_infoline("Create Bitmap");
179 platform.SetClosestImageSize(Vector2( ninePatchImageWidth, ninePatchImageHeight));
180 Integration::Bitmap* bitmap = CreateBitmap( ninePatchImageWidth, ninePatchImageHeight, 0xFF, pixelFormat );
182 tet_infoline("Clear border regions");
183 InitialiseRegionsToZeroAlpha( bitmap, ninePatchImageWidth, ninePatchImageHeight, pixelFormat );
185 tet_infoline("Add Stretch regions to Bitmap");
186 AddStretchRegionsToImage( bitmap, ninePatchImageWidth, ninePatchImageHeight, stretchRangesX, stretchRangesY, pixelFormat );
190 tet_infoline("Add Child regions to Bitmap");
191 AddChildRegionsToImage( bitmap, ninePatchImageWidth, ninePatchImageHeight, requiredChildRegion, pixelFormat );
194 tet_infoline("Getting resource");
195 Integration::ResourcePointer resourcePtr(bitmap);
196 //platform.SetResourceLoaded( 0, Dali::Integration::ResourceBitmap, resourcePtr );
197 platform.SetSynchronouslyLoadedResource( resourcePtr);
202 void TestVisualRender( ToolkitTestApplication& application,
204 Visual::Base& visual,
205 std::size_t expectedSamplers = 0,
206 ImageDimensions imageDimensions = ImageDimensions(),
207 Integration::ResourcePointer resourcePtr = Integration::ResourcePointer())
209 DummyControlImpl& dummyImpl = static_cast<DummyControlImpl&>(actor.GetImplementation());
210 dummyImpl.RegisterVisual( Control::CONTROL_PROPERTY_END_INDEX + 1, visual );
214 // set the image size, for test case, this needs to be set before loading started
215 application.GetPlatform().SetClosestImageSize( Vector2(imageDimensions.GetWidth(), imageDimensions.GetHeight()) );
218 actor.SetSize( 200.f, 200.f );
219 DALI_TEST_EQUALS( actor.GetRendererCount(), 0u, TEST_LOCATION );
221 Stage::GetCurrent().Add( actor );
223 application.SendNotification();
224 application.Render();
226 application.Render();
227 application.SendNotification();
231 DALI_TEST_EQUALS( application.GetPlatform().WasCalled(TestPlatformAbstraction::LoadResourceSynchronouslyFunc ), true, TEST_LOCATION);
234 DALI_TEST_EQUALS( actor.GetRendererCount(), 1u, TEST_LOCATION );
241 void dali_visual_factory_startup(void)
243 test_return_value = TET_UNDEF;
246 void dali_visual_factory_cleanup(void)
248 test_return_value = TET_PASS;
251 int UtcDaliVisualFactoryGet(void)
253 ToolkitTestApplication application;
254 tet_infoline( "UtcDaliVisualFactory" );
258 type = TypeRegistry::Get().GetTypeInfo( "VisualFactory" );
259 DALI_TEST_CHECK( type );
260 BaseHandle handle = type.CreateInstance();
261 DALI_TEST_CHECK( handle );
263 VisualFactory factory;
264 factory = VisualFactory::Get();
265 DALI_TEST_CHECK( factory );
267 VisualFactory newFactory = VisualFactory::Get();
268 DALI_TEST_CHECK( newFactory );
270 // Check that visual factory is a singleton
271 DALI_TEST_CHECK(factory == newFactory);
276 int UtcDaliVisualFactoryCopyAndAssignment(void)
278 ToolkitTestApplication application;
279 tet_infoline( "UtcDaliVisualFactoryCopyAndAssignment" );
280 VisualFactory factory = VisualFactory::Get();
282 VisualFactory factoryCopy( factory );
283 DALI_TEST_CHECK(factory == factoryCopy);
285 VisualFactory emptyFactory;
286 VisualFactory emptyFactoryCopy( emptyFactory );
287 DALI_TEST_CHECK(emptyFactory == emptyFactoryCopy);
289 VisualFactory factoryEquals;
290 factoryEquals = factory;
291 DALI_TEST_CHECK(factory == factoryEquals);
293 VisualFactory emptyFactoryEquals;
294 emptyFactoryEquals = emptyFactory;
295 DALI_TEST_CHECK( emptyFactory == emptyFactoryEquals );
299 DALI_TEST_CHECK( factory = factoryCopy );
304 int UtcDaliVisualFactoryGetColorVisual1(void)
306 ToolkitTestApplication application;
307 tet_infoline( "UtcDaliVisualFactoryGetColorVisual1: Request color visual with a Property::Map" );
309 VisualFactory factory = VisualFactory::Get();
310 DALI_TEST_CHECK( factory );
312 Property::Map propertyMap;
313 Vector4 testColor( 1.f, 0.5f, 0.3f, 0.2f );
314 propertyMap.Insert(Visual::Property::TYPE, Visual::COLOR);
315 propertyMap.Insert(ColorVisual::Property::MIX_COLOR, testColor);
317 Visual::Base visual = factory.CreateVisual(propertyMap);
318 DALI_TEST_CHECK( visual );
320 DummyControl actor = DummyControl::New();
321 TestVisualRender( application, actor, visual );
323 Vector3 actualValue(Vector4::ZERO);
325 TestGlAbstraction& gl = application.GetGlAbstraction();
326 DALI_TEST_CHECK( gl.GetUniformValue<Vector3>( "mixColor", actualValue ) );
327 DALI_TEST_CHECK( gl.GetUniformValue<float>( "opacity", opacity ) );
328 DALI_TEST_EQUALS( actualValue, Vector3(testColor), TEST_LOCATION );
329 DALI_TEST_EQUALS( opacity, testColor.a, TEST_LOCATION );
334 int UtcDaliVisualFactoryGetColorVisual2(void)
336 ToolkitTestApplication application;
337 tet_infoline( "UtcDaliVisualFactoryGetColorVisual2: Request color visual with a Vector4" );
339 VisualFactory factory = VisualFactory::Get();
340 DALI_TEST_CHECK( factory );
342 Vector4 testColor( 1.f, 0.5f, 0.3f, 0.2f );
343 Dali::Property::Map map;
344 map[ Visual::Property::TYPE ] = Visual::COLOR;
345 map[ ColorVisual::Property::MIX_COLOR ] = testColor;
346 Visual::Base visual = factory.CreateVisual( map );
347 DALI_TEST_CHECK( visual );
349 DummyControl actor = DummyControl::New();
350 TestVisualRender( application, actor, visual );
354 TestGlAbstraction& gl = application.GetGlAbstraction();
355 DALI_TEST_CHECK( gl.GetUniformValue<Vector3>( "mixColor", actualValue ) );
356 DALI_TEST_CHECK( gl.GetUniformValue<float>( "opacity", opacity ) );
357 DALI_TEST_EQUALS( actualValue, Vector3(testColor), TEST_LOCATION );
358 DALI_TEST_EQUALS( opacity, testColor.a, TEST_LOCATION );
360 Stage::GetCurrent().Remove(actor);
361 DALI_TEST_CHECK( actor.GetRendererCount() == 0u );
366 int UtcDaliVisualFactoryGetBorderVisual1(void)
368 ToolkitTestApplication application;
369 tet_infoline( "UtcDaliVisualFactoryGetBorderVisual1: Request border visual with a Property::Map" );
371 VisualFactory factory = VisualFactory::Get();
372 DALI_TEST_CHECK( factory );
374 Property::Map propertyMap;
375 Vector4 testColor( 1.f, 0.5f, 0.3f, 0.2f );
376 float testSize = 5.f;
377 propertyMap.Insert(Visual::Property::TYPE, Visual::BORDER);
378 propertyMap.Insert(BorderVisual::Property::COLOR, testColor);
379 propertyMap.Insert(BorderVisual::Property::SIZE, testSize);
381 Visual::Base visual = factory.CreateVisual(propertyMap);
382 DALI_TEST_CHECK( visual );
384 DummyControl actor = DummyControl::New();
385 DummyControlImpl& dummyImpl = static_cast<DummyControlImpl&>(actor.GetImplementation());
386 dummyImpl.RegisterVisual( Control::CONTROL_PROPERTY_END_INDEX + 1, visual );
387 actor.SetSize(200.f, 200.f);
388 Stage::GetCurrent().Add( actor );
389 visual.SetTransformAndSize(DefaultTransform(), Vector2(200.f, 200.f));
391 DALI_TEST_CHECK( actor.GetRendererCount() == 1u );
392 int blendMode = actor.GetRendererAt(0u).GetProperty<int>( Renderer::Property::BLEND_MODE );
393 DALI_TEST_EQUALS( static_cast<BlendMode::Type>(blendMode), BlendMode::ON, TEST_LOCATION );
395 TestGlAbstraction& gl = application.GetGlAbstraction();
397 application.SendNotification();
398 application.Render(0);
400 Vector4 actualColor(Vector4::ZERO);
401 DALI_TEST_CHECK( gl.GetUniformValue<Vector4>( "borderColor", actualColor ) );
402 DALI_TEST_EQUALS( actualColor, testColor, TEST_LOCATION );
404 float actualSize = 0.f;
405 DALI_TEST_CHECK( gl.GetUniformValue<float>( "borderSize", actualSize ) );
406 DALI_TEST_EQUALS( actualSize, testSize, TEST_LOCATION );
409 DALI_TEST_CHECK( actor.GetRendererCount() == 0u );
414 int UtcDaliVisualFactoryGetBorderVisual2(void)
416 ToolkitTestApplication application;
417 tet_infoline( "UtcDaliVisualFactoryGetBorderVisual2: Request border visual with a borderSize and a borderColor" );
419 VisualFactory factory = VisualFactory::Get();
420 DALI_TEST_CHECK( factory );
422 Vector4 testColor( 1.f, 0.5f, 0.3f, 1.f );
423 float testSize = 5.f;
425 Dali::Property::Map propertyMap;
426 propertyMap[ Visual::Property::TYPE ] = Visual::BORDER;
427 propertyMap[ BorderVisual::Property::COLOR ] = testColor;
428 propertyMap[ BorderVisual::Property::SIZE ] = testSize;
429 Visual::Base visual = factory.CreateVisual( propertyMap );
430 DALI_TEST_CHECK( visual );
432 DummyControl actor = DummyControl::New();
433 DummyControlImpl& dummyImpl = static_cast<DummyControlImpl&>(actor.GetImplementation());
434 dummyImpl.RegisterVisual( Control::CONTROL_PROPERTY_END_INDEX + 1, visual );
435 actor.SetSize(200.f, 200.f);
436 Stage::GetCurrent().Add( actor );
437 visual.SetTransformAndSize(DefaultTransform(), Vector2(200.f, 200.f));
439 DALI_TEST_CHECK( actor.GetRendererCount() == 1u );
441 TestGlAbstraction& gl = application.GetGlAbstraction();
443 application.SendNotification();
444 application.Render(0);
446 int blendMode = actor.GetRendererAt(0u).GetProperty<int>( Renderer::Property::BLEND_MODE );
447 DALI_TEST_EQUALS( static_cast<BlendMode::Type>(blendMode), BlendMode::AUTO, TEST_LOCATION );
449 Vector4 actualColor(Vector4::ZERO);
450 DALI_TEST_CHECK( gl.GetUniformValue<Vector4>( "borderColor", actualColor ) );
451 DALI_TEST_EQUALS( actualColor, testColor, TEST_LOCATION );
453 float actualSize = 0.f;
454 DALI_TEST_CHECK( gl.GetUniformValue<float>( "borderSize", actualSize ) );
455 DALI_TEST_EQUALS( actualSize, testSize, TEST_LOCATION );
459 // enable the anti-aliasing
460 Dali::Property::Map map;
461 map[ Visual::Property::TYPE ] = Visual::BORDER;
462 map[ BorderVisual::Property::COLOR ] = testColor;
463 map[ BorderVisual::Property::SIZE ] = testSize;
464 map[ BorderVisual::Property::ANTI_ALIASING ] = true;
465 visual = factory.CreateVisual( map );
467 dummyImpl.RegisterVisual( Control::CONTROL_PROPERTY_END_INDEX + 1, visual );
468 Stage::GetCurrent().Add( actor );
470 blendMode = actor.GetRendererAt(0u).GetProperty<int>( Renderer::Property::BLEND_MODE );
471 DALI_TEST_EQUALS( static_cast<BlendMode::Type>(blendMode), BlendMode::ON, TEST_LOCATION );
476 int UtcDaliVisualFactoryGetLinearGradientVisual(void)
478 ToolkitTestApplication application;
479 tet_infoline("UtcDaliVisualFactoryGetRadialGradientVisual");
481 VisualFactory factory = VisualFactory::Get();
482 DALI_TEST_CHECK( factory );
484 Property::Map propertyMap;
485 propertyMap.Insert(Visual::Property::TYPE, Visual::GRADIENT);
487 Vector2 start(-1.f, -1.f);
488 Vector2 end(1.f, 1.f);
489 propertyMap.Insert(GradientVisual::Property::START_POSITION, start);
490 propertyMap.Insert(GradientVisual::Property::END_POSITION, end);
491 propertyMap.Insert(GradientVisual::Property::SPREAD_METHOD, GradientVisual::SpreadMethod::REPEAT);
493 Property::Array stopOffsets;
494 stopOffsets.PushBack( 0.2f );
495 stopOffsets.PushBack( 0.8f );
496 propertyMap.Insert(GradientVisual::Property::STOP_OFFSET, stopOffsets);
498 Property::Array stopColors;
499 stopColors.PushBack( Color::RED );
500 stopColors.PushBack( Color::GREEN );
501 propertyMap.Insert(GradientVisual::Property::STOP_COLOR, stopColors);
503 Visual::Base visual = factory.CreateVisual(propertyMap);
504 DALI_TEST_CHECK( visual );
506 // A lookup texture is generated and pass to shader as sampler
507 DummyControl actor = DummyControl::New();
508 TestVisualRender( application, actor, visual, 1u);
513 int UtcDaliVisualFactoryGetRadialGradientVisual(void)
515 ToolkitTestApplication application;
516 tet_infoline("UtcDaliVisualFactoryGetRadialGradientVisual");
518 VisualFactory factory = VisualFactory::Get();
519 DALI_TEST_CHECK( factory );
521 Property::Map propertyMap;
522 propertyMap.Insert(Visual::Property::TYPE, Visual::GRADIENT);
524 Vector2 center(100.f, 100.f);
525 float radius = 100.f;
526 propertyMap.Insert(GradientVisual::Property::UNITS, GradientVisual::Units::USER_SPACE);
527 propertyMap.Insert(GradientVisual::Property::CENTER, center);
528 propertyMap.Insert(GradientVisual::Property::RADIUS, radius);
530 Property::Array stopOffsets;
531 stopOffsets.PushBack( 0.0f );
532 stopOffsets.PushBack( 1.f );
533 propertyMap.Insert(GradientVisual::Property::STOP_OFFSET, stopOffsets);
535 Property::Array stopColors;
536 stopColors.PushBack( Color::RED );
537 stopColors.PushBack( Color::GREEN );
538 propertyMap.Insert(GradientVisual::Property::STOP_COLOR, stopColors);
540 Visual::Base visual = factory.CreateVisual(propertyMap);
541 DALI_TEST_CHECK( visual );
543 // A lookup texture is generated and pass to shader as sampler
544 DummyControl actor = DummyControl::New();
545 TestVisualRender( application, actor, visual, 1u );
547 Matrix3 alignMatrix( radius, 0.f, 0.f, 0.f, radius, 0.f, center.x, center.y, 1.f );
548 alignMatrix.Invert();
550 Matrix3 actualValue( Matrix3::IDENTITY );
551 TestGlAbstraction& gl = application.GetGlAbstraction();
552 DALI_TEST_CHECK( gl.GetUniformValue<Matrix3>( "uAlignmentMatrix", actualValue ) );
553 DALI_TEST_EQUALS( actualValue, alignMatrix, Math::MACHINE_EPSILON_100, TEST_LOCATION );
558 int UtcDaliVisualFactoryDefaultOffsetsGradientVisual(void)
560 ToolkitTestApplication application;
561 tet_infoline("UtcDaliVisualFactoryGetRadialGradientVisual");
563 VisualFactory factory = VisualFactory::Get();
564 DALI_TEST_CHECK( factory );
566 Property::Map propertyMap;
567 propertyMap.Insert(Visual::Property::TYPE, Visual::GRADIENT);
569 Vector2 start(-1.f, -1.f);
570 Vector2 end(1.f, 1.f);
571 propertyMap.Insert(GradientVisual::Property::START_POSITION, start);
572 propertyMap.Insert(GradientVisual::Property::END_POSITION, end);
573 propertyMap.Insert(GradientVisual::Property::SPREAD_METHOD, GradientVisual::SpreadMethod::REPEAT);
575 Property::Array stopColors;
576 stopColors.PushBack( Color::RED );
577 stopColors.PushBack( Color::GREEN );
578 propertyMap.Insert(GradientVisual::Property::STOP_COLOR, stopColors);
580 Visual::Base visual = factory.CreateVisual(propertyMap);
581 DALI_TEST_CHECK( visual );
583 // A lookup texture is generated and pass to shader as sampler
584 DummyControl actor = DummyControl::New();
585 TestVisualRender( application, actor, visual, 1u );
587 Stage::GetCurrent().Remove( actor );
588 DALI_TEST_CHECK( actor.GetRendererCount() == 0u );
597 int UtcDaliVisualFactoryGetNPatchVisual1(void)
599 ToolkitTestApplication application;
600 tet_infoline( "UtcDaliVisualFactoryGetNPatchVisual1: Request 9-patch visual with a Property::Map" );
602 VisualFactory factory = VisualFactory::Get();
603 DALI_TEST_CHECK( factory );
605 const unsigned int ninePatchImageHeight = 18;
606 const unsigned int ninePatchImageWidth = 28;
607 StretchRanges stretchRangesX;
608 stretchRangesX.PushBack( Uint16Pair( 2, 3 ) );
609 StretchRanges stretchRangesY;
610 stretchRangesY.PushBack( Uint16Pair( 4, 5 ) );
611 Integration::ResourcePointer ninePatchResource = CustomizeNinePatch( application, ninePatchImageWidth, ninePatchImageHeight, stretchRangesX, stretchRangesY );
613 Property::Map propertyMap;
614 propertyMap.Insert( Visual::Property::TYPE, DevelVisual::N_PATCH );
615 propertyMap.Insert( ImageVisual::Property::URL, TEST_NPATCH_FILE_NAME );
617 tet_infoline( "whole grid" );
618 Visual::Base visual = factory.CreateVisual( propertyMap );
619 DALI_TEST_CHECK( visual );
622 TestGlAbstraction& gl = application.GetGlAbstraction();
623 TraceCallStack& textureTrace = gl.GetTextureTrace();
624 textureTrace.Enable(true);
626 DummyControl actor = DummyControl::New();
627 TestVisualRender( application, actor, visual, 1u,
628 ImageDimensions(ninePatchImageWidth, ninePatchImageHeight),
631 DALI_TEST_EQUALS( textureTrace.FindMethod("BindTexture"), true, TEST_LOCATION );
634 propertyMap.Insert( ImageVisual::Property::BORDER_ONLY, true );
636 tet_infoline( "border only" );
637 Visual::Base visual = factory.CreateVisual( propertyMap );
638 DALI_TEST_CHECK( visual );
640 TestGlAbstraction& gl = application.GetGlAbstraction();
641 TraceCallStack& textureTrace = gl.GetTextureTrace();
642 textureTrace.Enable(true);
644 DummyControl actor = DummyControl::New();
645 TestVisualRender( application, actor, visual, 1u,
646 ImageDimensions(ninePatchImageWidth, ninePatchImageHeight),
649 DALI_TEST_EQUALS( textureTrace.FindMethod("BindTexture"), true, TEST_LOCATION );
655 int UtcDaliVisualFactoryGetNPatchVisual2(void)
657 ToolkitTestApplication application;
658 tet_infoline( "UtcDaliVisualFactoryGetNPatchVisual1: Request 9-patch visual with a Property::Map including border" );
660 VisualFactory factory = VisualFactory::Get();
661 DALI_TEST_CHECK( factory );
663 Property::Map propertyMap;
664 propertyMap.Insert( Visual::Property::TYPE, DevelVisual::N_PATCH );
665 propertyMap.Insert( ImageVisual::Property::URL, gImage_34_RGBA );
666 propertyMap.Insert( DevelImageVisual::Property::BORDER, Rect< int >( 2, 2, 2, 2 ) );
668 tet_infoline( "whole grid" );
669 Visual::Base visual = factory.CreateVisual( propertyMap );
670 DALI_TEST_CHECK( visual );
672 TestGlAbstraction& gl = application.GetGlAbstraction();
673 TraceCallStack& textureTrace = gl.GetTextureTrace();
674 textureTrace.Enable(true);
676 DummyControl actor = DummyControl::New();
677 TestVisualRender( application, actor, visual, 1u );
679 DALI_TEST_EQUALS( textureTrace.FindMethod("BindTexture"), true, TEST_LOCATION );
682 propertyMap.Insert( ImageVisual::Property::BORDER_ONLY, true );
684 tet_infoline( "border only" );
685 Visual::Base visual = factory.CreateVisual( propertyMap );
686 DALI_TEST_CHECK( visual );
688 TestGlAbstraction& gl = application.GetGlAbstraction();
689 TraceCallStack& textureTrace = gl.GetTextureTrace();
690 textureTrace.Enable(true);
692 DummyControl actor = DummyControl::New();
693 TestVisualRender( application, actor, visual, 1u );
695 DALI_TEST_EQUALS( textureTrace.FindMethod("BindTexture"), true, TEST_LOCATION );
699 propertyMap.Insert( Visual::Property::TYPE, DevelVisual::N_PATCH );
700 propertyMap.Insert( ImageVisual::Property::URL, gImage_34_RGBA );
701 propertyMap.Insert( DevelImageVisual::Property::BORDER, Rect< int >( 1, 1, 1, 1 ) );
703 tet_infoline( "whole grid" );
704 Visual::Base visual = factory.CreateVisual( propertyMap );
705 DALI_TEST_CHECK( visual );
707 TestGlAbstraction& gl = application.GetGlAbstraction();
708 TraceCallStack& textureTrace = gl.GetTextureTrace();
709 textureTrace.Enable(true);
711 DummyControl actor = DummyControl::New();
712 TestVisualRender( application, actor, visual, 1u );
714 DALI_TEST_EQUALS( textureTrace.FindMethod("BindTexture"), true, TEST_LOCATION );
720 int UtcDaliVisualFactoryGetNPatchVisual3(void)
722 ToolkitTestApplication application;
723 tet_infoline( "UtcDaliVisualFactoryGetNPatchVisual2: Request n-patch visual with a Property::Map" );
725 VisualFactory factory = VisualFactory::Get();
726 DALI_TEST_CHECK( factory );
728 const unsigned int ninePatchImageWidth = 18;
729 const unsigned int ninePatchImageHeight = 28;
730 StretchRanges stretchRangesX;
731 stretchRangesX.PushBack( Uint16Pair( 2, 3 ) );
732 stretchRangesX.PushBack( Uint16Pair( 5, 7 ) );
733 stretchRangesX.PushBack( Uint16Pair( 12, 15 ) );
734 StretchRanges stretchRangesY;
735 stretchRangesY.PushBack( Uint16Pair( 4, 5 ) );
736 stretchRangesY.PushBack( Uint16Pair( 8, 12 ) );
737 stretchRangesY.PushBack( Uint16Pair( 15, 16 ) );
738 stretchRangesY.PushBack( Uint16Pair( 25, 27 ) );
739 Integration::ResourcePointer ninePatchResource = CustomizeNinePatch( application, ninePatchImageWidth, ninePatchImageHeight, stretchRangesX, stretchRangesY );
741 Property::Map propertyMap;
742 propertyMap.Insert( Visual::Property::TYPE, DevelVisual::N_PATCH );
743 propertyMap.Insert( ImageVisual::Property::URL, TEST_NPATCH_FILE_NAME );
745 Visual::Base visual = factory.CreateVisual( propertyMap );
746 DALI_TEST_CHECK( visual );
748 TestGlAbstraction& gl = application.GetGlAbstraction();
749 TraceCallStack& textureTrace = gl.GetTextureTrace();
750 textureTrace.Enable(true);
752 DummyControl actor = DummyControl::New();
753 TestVisualRender( application, actor, visual, 1u,
754 ImageDimensions(ninePatchImageWidth, ninePatchImageHeight),
757 DALI_TEST_EQUALS( textureTrace.FindMethod("BindTexture"), true, TEST_LOCATION );
759 Stage::GetCurrent().Remove( actor );
760 DALI_TEST_CHECK( actor.GetRendererCount() == 0u );
763 propertyMap.Insert( ImageVisual::Property::BORDER_ONLY, true );
765 tet_infoline( "border only" );
766 Visual::Base visual = factory.CreateVisual( propertyMap );
767 DALI_TEST_CHECK( visual );
769 TestGlAbstraction& gl = application.GetGlAbstraction();
770 TraceCallStack& textureTrace = gl.GetTextureTrace();
771 textureTrace.Enable(true);
772 DummyControl actor = DummyControl::New();
773 TestVisualRender( application, actor, visual, 1u,
774 ImageDimensions(ninePatchImageWidth, ninePatchImageHeight),
778 DALI_TEST_EQUALS( textureTrace.FindMethod("BindTexture"), true, TEST_LOCATION );
780 Stage::GetCurrent().Remove( actor );
781 DALI_TEST_CHECK( actor.GetRendererCount() == 0u );
787 int UtcDaliVisualFactoryGetNPatchVisual4(void)
789 ToolkitTestApplication application;
790 tet_infoline( "UtcDaliVisualFactoryGetNPatchVisual3: Request 9-patch visual with an image url" );
792 VisualFactory factory = VisualFactory::Get();
793 DALI_TEST_CHECK( factory );
795 const unsigned int ninePatchImageHeight = 18;
796 const unsigned int ninePatchImageWidth = 28;
797 StretchRanges stretchRangesX;
798 stretchRangesX.PushBack( Uint16Pair( 2, 3 ) );
799 StretchRanges stretchRangesY;
800 stretchRangesY.PushBack( Uint16Pair( 4, 5 ) );
801 Integration::ResourcePointer ninePatchResource = CustomizeNinePatch( application, ninePatchImageWidth, ninePatchImageHeight, stretchRangesX, stretchRangesY );
803 Visual::Base visual = factory.CreateVisual( TEST_NPATCH_FILE_NAME, ImageDimensions() );
804 DALI_TEST_CHECK( visual );
806 TestGlAbstraction& gl = application.GetGlAbstraction();
807 TraceCallStack& textureTrace = gl.GetTextureTrace();
808 textureTrace.Enable(true);
810 DummyControl actor = DummyControl::New();
811 TestVisualRender( application, actor, visual, 1u,
812 ImageDimensions(ninePatchImageWidth, ninePatchImageHeight),
815 DALI_TEST_EQUALS( textureTrace.FindMethod("BindTexture"), true, TEST_LOCATION );
818 ResourceImage image = ResourceImage::New(TEST_NPATCH_FILE_NAME);
819 Visual::Base nPatchVisual = factory.CreateVisual( image );
820 Vector2 controlSize( 20.f, 30.f ), naturalSize(0,0);
821 nPatchVisual.SetTransformAndSize(DefaultTransform(), controlSize );
822 nPatchVisual.GetNaturalSize( naturalSize );
823 DALI_TEST_EQUALS( naturalSize, Vector2( ninePatchImageWidth-2, ninePatchImageHeight-2 ), TEST_LOCATION );
828 int UtcDaliVisualFactoryGetNPatchVisual5(void)
830 ToolkitTestApplication application;
831 tet_infoline( "UtcDaliVisualFactoryGetNPatchVisual4: Request n-patch visual with an image url" );
833 VisualFactory factory = VisualFactory::Get();
834 DALI_TEST_CHECK( factory );
836 const unsigned int ninePatchImageHeight = 18;
837 const unsigned int ninePatchImageWidth = 28;
838 StretchRanges stretchRangesX;
839 stretchRangesX.PushBack( Uint16Pair( 2, 3 ) );
840 stretchRangesX.PushBack( Uint16Pair( 5, 7 ) );
841 stretchRangesX.PushBack( Uint16Pair( 12, 15 ) );
842 StretchRanges stretchRangesY;
843 stretchRangesY.PushBack( Uint16Pair( 4, 5 ) );
844 stretchRangesY.PushBack( Uint16Pair( 8, 12 ) );
845 stretchRangesY.PushBack( Uint16Pair( 15, 16 ) );
846 stretchRangesY.PushBack( Uint16Pair( 25, 27 ) );
847 Integration::ResourcePointer ninePatchResource = CustomizeNinePatch( application, ninePatchImageWidth, ninePatchImageHeight, stretchRangesX, stretchRangesY );
849 Visual::Base visual = factory.CreateVisual( TEST_NPATCH_FILE_NAME, ImageDimensions() );
850 DALI_TEST_CHECK( visual );
852 TestGlAbstraction& gl = application.GetGlAbstraction();
853 TraceCallStack& textureTrace = gl.GetTextureTrace();
854 textureTrace.Enable(true);
856 DummyControl actor = DummyControl::New();
857 TestVisualRender( application, actor, visual, 1u,
858 ImageDimensions(ninePatchImageWidth, ninePatchImageHeight),
861 DALI_TEST_EQUALS( textureTrace.FindMethod("BindTexture"), true, TEST_LOCATION );
866 int UtcDaliVisualFactoryGetNPatchVisualN1(void)
868 //This should still load but display an error image
870 ToolkitTestApplication application;
871 tet_infoline( "UtcDaliVisualFactoryGetNPatchVisualN: Request n-patch visual with an invalid image url" );
873 VisualFactory factory = VisualFactory::Get();
874 DALI_TEST_CHECK( factory );
876 Visual::Base visual = factory.CreateVisual( "ERROR.9.jpg", ImageDimensions() );
877 DALI_TEST_CHECK( visual );
879 //The testkit still has to load a bitmap for the broken renderer image
880 Integration::Bitmap* bitmap = Integration::Bitmap::New(Integration::Bitmap::BITMAP_2D_PACKED_PIXELS, ResourcePolicy::OWNED_DISCARD);
881 bitmap->GetPackedPixelsProfile()->ReserveBuffer( Pixel::RGBA8888, 100, 100, 100, 100 );
883 TestGlAbstraction& gl = application.GetGlAbstraction();
884 TraceCallStack& textureTrace = gl.GetTextureTrace();
885 textureTrace.Enable(true);
887 DummyControl actor = DummyControl::New();
888 TestVisualRender( application, actor, visual, 1u,
890 Integration::ResourcePointer(bitmap) );
892 DALI_TEST_EQUALS( textureTrace.FindMethod("BindTexture"), true, TEST_LOCATION );
897 int UtcDaliVisualFactoryGetNPatchVisualN2(void)
899 //This should still load but display an error image
901 ToolkitTestApplication application;
902 tet_infoline( "UtcDaliVisualFactoryGetNPatchVisualN: Request n-patch visual with an invalid URL" );
904 VisualFactory factory = VisualFactory::Get();
905 DALI_TEST_CHECK( factory );
907 Property::Map propertyMap;
908 propertyMap.Insert( Visual::Property::TYPE, DevelVisual::N_PATCH );
909 propertyMap.Insert( ImageVisual::Property::URL, "ERROR.9.jpg" );
911 Visual::Base visual = factory.CreateVisual( propertyMap );
912 DALI_TEST_CHECK( visual );
914 //The testkit still has to load a bitmap for the broken renderer image
915 Integration::Bitmap* bitmap = Integration::Bitmap::New(Integration::Bitmap::BITMAP_2D_PACKED_PIXELS, ResourcePolicy::OWNED_DISCARD);
916 bitmap->GetPackedPixelsProfile()->ReserveBuffer( Pixel::RGBA8888, 100, 100, 100, 100 );
918 TestGlAbstraction& gl = application.GetGlAbstraction();
919 TraceCallStack& textureTrace = gl.GetTextureTrace();
920 textureTrace.Enable(true);
921 TraceCallStack& drawTrace = gl.GetDrawTrace();
922 drawTrace.Enable(true);
924 DummyControl actor = DummyControl::New();
925 TestVisualRender( application, actor, visual, 1u,
927 Integration::ResourcePointer(bitmap) );
929 DALI_TEST_EQUALS( textureTrace.FindMethod("BindTexture"), true, TEST_LOCATION );
934 int UtcDaliVisualFactoryGetNPatchVisualN3(void)
936 // Passing in an invalid visual type so we should not get a visual
938 ToolkitTestApplication application;
939 tet_infoline( "UtcDaliVisualFactoryGetNPatchVisualN: Request n-patch visual with an invalid visual type" );
941 VisualFactory factory = VisualFactory::Get();
942 DALI_TEST_CHECK( factory );
944 Property::Map propertyMap;
945 propertyMap.Insert( Visual::Property::TYPE, 111 );
946 propertyMap.Insert( ImageVisual::Property::URL, "ERROR.9.jpg" );
948 Visual::Base visual = factory.CreateVisual( propertyMap );
949 DALI_TEST_CHECK( !visual );
954 int UtcDaliVisualFactoryGetSvgVisual(void)
956 ToolkitTestApplication application;
957 tet_infoline( "UtcDaliVisualFactoryGetSvgVisual: Request svg visual with a svg url" );
959 VisualFactory factory = VisualFactory::Get();
960 Visual::Base visual = factory.CreateVisual( TEST_SVG_FILE_NAME, ImageDimensions() );
961 DALI_TEST_CHECK( visual );
963 TestGlAbstraction& gl = application.GetGlAbstraction();
964 TraceCallStack& textureTrace = gl.GetTextureTrace();
965 textureTrace.Enable(true);
967 DummyControl actor = DummyControl::New();
968 DummyControlImpl& dummyImpl = static_cast<DummyControlImpl&>(actor.GetImplementation());
969 dummyImpl.RegisterVisual( Control::CONTROL_PROPERTY_END_INDEX + 1, visual );
970 actor.SetSize( 200.f, 200.f );
971 Stage::GetCurrent().Add( actor );
972 visual.SetTransformAndSize(DefaultTransform(), Vector2(200.f, 200.f) );
974 application.SendNotification();
975 application.Render();
977 // renderer is not added to actor until the rasterization is completed.
978 DALI_TEST_CHECK( actor.GetRendererCount() == 0u );
980 DALI_TEST_EQUALS( Test::WaitForEventThreadTrigger( 1 ), true, TEST_LOCATION );
982 // renderer is added to actor
983 DALI_TEST_CHECK( actor.GetRendererCount() == 1u );
985 // waiting for the resource uploading
986 application.SendNotification();
987 application.Render();
989 DALI_TEST_EQUALS( textureTrace.FindMethod("BindTexture"), true, TEST_LOCATION );
994 int UtcDaliVisualFactoryGetSvgVisualLarge(void)
996 ToolkitTestApplication application;
997 tet_infoline( "UtcDaliVisualFactoryGetSvgVisual: Request svg visual with a svg url" );
999 VisualFactory factory = VisualFactory::Get();
1000 Visual::Base visual = factory.CreateVisual( TEST_SVG_FILE_NAME, ImageDimensions( 2000, 2000 ) );
1001 DALI_TEST_CHECK( visual );
1003 TestGlAbstraction& gl = application.GetGlAbstraction();
1004 TraceCallStack& textureTrace = gl.GetTextureTrace();
1005 textureTrace.Enable(true);
1007 DummyControl actor = DummyControl::New(true);
1008 DummyControlImpl& dummyImpl = static_cast<DummyControlImpl&>(actor.GetImplementation());
1009 actor.SetResizePolicy( ResizePolicy::FILL_TO_PARENT, Dimension::ALL_DIMENSIONS ); // Only rasterizes when it knows control size.
1010 dummyImpl.RegisterVisual( Control::CONTROL_PROPERTY_END_INDEX + 1, visual );
1011 Stage::GetCurrent().Add( actor );
1013 application.SendNotification();
1014 application.Render();
1016 // renderer is not added to actor until the rasterization is completed.
1017 DALI_TEST_CHECK( actor.GetRendererCount() == 0u );
1019 DALI_TEST_EQUALS( Test::WaitForEventThreadTrigger( 1 ), true, TEST_LOCATION );
1021 // renderer is added to actor
1022 DALI_TEST_CHECK( actor.GetRendererCount() == 1u );
1024 // waiting for the resource uploading
1025 application.SendNotification();
1026 application.Render();
1028 DALI_TEST_EQUALS( textureTrace.FindMethod("BindTexture"), true, TEST_LOCATION );
1033 //Creates a mesh visual from the given propertyMap and tries to load it on stage in the given application.
1034 //This is expected to succeed, which will then pass the test.
1035 void MeshVisualLoadsCorrectlyTest( Property::Map& propertyMap, ToolkitTestApplication& application )
1037 VisualFactory factory = VisualFactory::Get();
1038 DALI_TEST_CHECK( factory );
1040 //Create a mesh visual.
1041 Visual::Base visual = factory.CreateVisual( propertyMap );
1042 DALI_TEST_CHECK( visual );
1044 //Create an actor on stage to house the visual.
1045 DummyControl actor = DummyControl::New();
1046 DummyControlImpl& dummyImpl = static_cast<DummyControlImpl&>(actor.GetImplementation());
1047 dummyImpl.RegisterVisual( Control::CONTROL_PROPERTY_END_INDEX + 1, visual );
1048 actor.SetSize( 200.f, 200.f );
1049 Stage::GetCurrent().Add( actor );
1050 visual.SetTransformAndSize(DefaultTransform(), Vector2( 200.f, 200.f ) );
1052 //Ensure set on stage.
1053 DALI_TEST_EQUALS( actor.GetRendererCount(), 1u, TEST_LOCATION );
1055 //Attempt to render to queue resource load requests.
1056 application.SendNotification();
1057 application.Render( 0 );
1059 //Render again to upload the now-loaded textures.
1060 application.SendNotification();
1061 application.Render( 0 );
1063 Matrix testScaleMatrix;
1064 testScaleMatrix.SetIdentityAndScale( Vector3( 1.0, -1.0, 1.0 ) );
1065 Matrix actualScaleMatrix;
1067 //Test to see if the object has been successfully loaded.
1068 DALI_TEST_CHECK( application.GetGlAbstraction().GetUniformValue<Matrix>( "uObjectMatrix", actualScaleMatrix ) );
1069 DALI_TEST_EQUALS( actualScaleMatrix, testScaleMatrix, Math::MACHINE_EPSILON_100, TEST_LOCATION );
1071 //Finish by setting off stage, and ensuring this was successful.
1073 DALI_TEST_EQUALS( actor.GetRendererCount(), 0u, TEST_LOCATION );
1076 //Creates a mesh visual from the given propertyMap and tries to load it on stage in the given application.
1077 //This is expected to fail, which will then pass the test.
1078 void MeshVisualDoesNotLoadCorrectlyTest( Property::Map& propertyMap, ToolkitTestApplication& application )
1080 VisualFactory factory = VisualFactory::Get();
1081 DALI_TEST_CHECK( factory );
1083 //Create a mesh visual.
1084 Visual::Base visual = factory.CreateVisual( propertyMap );
1085 DALI_TEST_CHECK( visual );
1087 //Create an actor on stage to house the visual.
1088 DummyControl actor = DummyControl::New();
1089 DummyControlImpl& dummyImpl = static_cast<DummyControlImpl&>(actor.GetImplementation());
1090 dummyImpl.RegisterVisual( Control::CONTROL_PROPERTY_END_INDEX + 1, visual );
1091 actor.SetSize( 200.f, 200.f );
1092 Stage::GetCurrent().Add( actor );
1093 visual.SetTransformAndSize(DefaultTransform(), Vector2( 200.f, 200.f ) );
1095 //Ensure set on stage.
1096 DALI_TEST_EQUALS( actor.GetRendererCount(), 1u, TEST_LOCATION );
1098 //Attempt to render to queue resource load requests.
1099 application.SendNotification();
1100 application.Render( 0 );
1102 //Render again to upload the now-loaded textures.
1103 application.SendNotification();
1104 application.Render( 0 );
1106 //Test to see if the object has not been loaded, as expected.
1108 DALI_TEST_CHECK( !application.GetGlAbstraction().GetUniformValue<Matrix>( "uObjectMatrix", scaleMatrix ) );
1110 //Finish by setting off stage, and ensuring this was successful.
1112 DALI_TEST_EQUALS( actor.GetRendererCount(), 0u, TEST_LOCATION );
1115 //Test if mesh loads correctly when supplied with only the bare minimum requirements, an object file.
1116 int UtcDaliVisualFactoryGetMeshVisual1(void)
1118 //Set up test application first, so everything else can be handled.
1119 ToolkitTestApplication application;
1121 tet_infoline( "UtcDaliVisualFactoryGetMeshVisual1: Request mesh visual with a valid object file only" );
1124 //Set up visual properties.
1125 Property::Map propertyMap;
1126 propertyMap.Insert( Visual::Property::TYPE, Visual::MESH );
1127 propertyMap.Insert( MeshVisual::Property::OBJECT_URL, TEST_OBJ_FILE_NAME );
1129 //Test to see if mesh loads correctly.
1130 MeshVisualLoadsCorrectlyTest( propertyMap, application );
1136 //Test if mesh loads correctly when supplied with an object file as well as a blank material file and images directory.
1137 int UtcDaliVisualFactoryGetMeshVisual2(void)
1139 //Set up test application first, so everything else can be handled.
1140 ToolkitTestApplication application;
1142 tet_infoline( "UtcDaliVisualFactoryGetMeshVisual2: Request mesh visual with blank material file and images directory" );
1144 //Set up visual properties.
1145 Property::Map propertyMap;
1146 propertyMap.Insert( Visual::Property::TYPE, Visual::MESH );
1147 propertyMap.Insert( MeshVisual::Property::OBJECT_URL, TEST_OBJ_FILE_NAME );
1148 propertyMap.Insert( MeshVisual::Property::MATERIAL_URL, "" );
1149 propertyMap.Insert( MeshVisual::Property::TEXTURES_PATH, "" );
1151 //Test to see if mesh loads correctly.
1152 MeshVisualLoadsCorrectlyTest( propertyMap, application );
1157 //Test if mesh loads correctly when supplied with all main parameters, an object file, a material file and a directory location, but duff optional parameters
1158 int UtcDaliVisualFactoryGetMeshVisual3b(void)
1160 //Set up test application first, so everything else can be handled.
1161 ToolkitTestApplication application;
1163 tet_infoline( "UtcDaliVisualFactoryGetMeshVisual3: Request mesh visual with all parameters correct" );
1165 //Set up visual properties.
1166 Property::Map propertyMap;
1167 propertyMap.Insert( Visual::Property::TYPE, Visual::MESH );
1168 propertyMap.Insert( MeshVisual::Property::OBJECT_URL, TEST_OBJ_FILE_NAME );
1169 propertyMap.Insert( MeshVisual::Property::MATERIAL_URL, TEST_MTL_FILE_NAME );
1170 propertyMap.Insert( MeshVisual::Property::USE_MIPMAPPING, Color::GREEN ); // Test that wrong property types don't prevent the object load
1171 propertyMap.Insert( MeshVisual::Property::USE_SOFT_NORMALS, 1.0f );
1172 propertyMap.Insert( MeshVisual::Property::LIGHT_POSITION, 1.0f );
1173 propertyMap.Insert( MeshVisual::Property::TEXTURES_PATH, TEST_RESOURCE_DIR "/" );
1175 //Test to see if mesh loads correctly.
1176 MeshVisualLoadsCorrectlyTest( propertyMap, application );
1181 //Test if mesh loads correctly when supplied with all main parameters, an object file, a material file and a directory location.
1182 int UtcDaliVisualFactoryGetMeshVisual3(void)
1184 //Set up test application first, so everything else can be handled.
1185 ToolkitTestApplication application;
1187 tet_infoline( "UtcDaliVisualFactoryGetMeshVisual3: Request mesh visual with all parameters correct" );
1189 //Set up visual properties.
1190 Property::Map propertyMap;
1191 propertyMap.Insert( Visual::Property::TYPE, Visual::MESH );
1192 propertyMap.Insert( MeshVisual::Property::OBJECT_URL, TEST_OBJ_FILE_NAME );
1193 propertyMap.Insert( MeshVisual::Property::MATERIAL_URL, TEST_MTL_FILE_NAME );
1194 propertyMap.Insert( MeshVisual::Property::USE_MIPMAPPING, false );
1195 propertyMap.Insert( MeshVisual::Property::USE_SOFT_NORMALS, false );
1196 propertyMap.Insert( MeshVisual::Property::LIGHT_POSITION, Vector3::XAXIS );
1197 propertyMap.Insert( MeshVisual::Property::TEXTURES_PATH, TEST_RESOURCE_DIR "/" );
1199 //Test to see if mesh loads correctly.
1200 MeshVisualLoadsCorrectlyTest( propertyMap, application );
1205 //Test if mesh visual can load a correctly supplied mesh without a normal map or gloss map in the material file.
1206 int UtcDaliVisualFactoryGetMeshVisual4(void)
1208 //Set up test application first, so everything else can be handled.
1209 ToolkitTestApplication application;
1211 tet_infoline( "UtcDaliVisualFactoryGetMeshVisual4: Request mesh visual with diffuse texture but not normal or gloss." );
1214 //Set up visual properties.
1215 Property::Map propertyMap;
1216 propertyMap.Insert( Visual::Property::TYPE, Visual::MESH );
1217 propertyMap.Insert( MeshVisual::Property::OBJECT_URL, TEST_OBJ_FILE_NAME );
1218 propertyMap.Insert( MeshVisual::Property::MATERIAL_URL, TEST_SIMPLE_MTL_FILE_NAME );
1219 propertyMap.Insert( MeshVisual::Property::TEXTURES_PATH, TEST_RESOURCE_DIR "/" );
1221 //Test to see if mesh loads correctly.
1222 MeshVisualLoadsCorrectlyTest( propertyMap, application );
1227 //Test if mesh visual can load when made to use diffuse textures only.
1228 int UtcDaliVisualFactoryGetMeshVisual5(void)
1230 //Set up test application first, so everything else can be handled.
1231 ToolkitTestApplication application;
1233 tet_infoline( "UtcDaliVisualFactoryGetMeshVisual5: Request mesh visual and make it only use diffuse textures." );
1235 //Set up visual properties.
1236 Property::Map propertyMap;
1237 propertyMap.Insert( Visual::Property::TYPE, Visual::MESH );
1238 propertyMap.Insert( "objectUrl", TEST_OBJ_FILE_NAME );
1239 propertyMap.Insert( "materialUrl", TEST_MTL_FILE_NAME );
1240 propertyMap.Insert( "texturesPath", TEST_RESOURCE_DIR "/" );
1241 propertyMap.Insert( "useMipmapping", false );
1242 propertyMap.Insert( "useSoftNormals", false );
1243 propertyMap.Insert( "lightPosition", Vector3::ZAXIS );
1244 propertyMap.Insert( "shadingMode", MeshVisual::ShadingMode::TEXTURED_WITH_SPECULAR_LIGHTING );
1246 //Test to see if mesh loads correctly.
1247 MeshVisualLoadsCorrectlyTest( propertyMap, application );
1253 //Test if mesh visual can load when made to not use the supplied textures.
1254 int UtcDaliVisualFactoryGetMeshVisual6(void)
1256 //Set up test application first, so everything else can be handled.
1257 ToolkitTestApplication application;
1259 tet_infoline( "UtcDaliVisualFactoryGetMeshVisual6: Request mesh visual and make it not use any textures." );
1261 //Set up visual properties.
1262 Property::Map propertyMap;
1263 propertyMap.Insert( Visual::Property::TYPE, Visual::MESH );
1264 propertyMap.Insert( MeshVisual::Property::OBJECT_URL, TEST_OBJ_FILE_NAME );
1265 propertyMap.Insert( MeshVisual::Property::MATERIAL_URL, TEST_MTL_FILE_NAME );
1266 propertyMap.Insert( MeshVisual::Property::TEXTURES_PATH, TEST_RESOURCE_DIR "/" );
1267 propertyMap.Insert( MeshVisual::Property::SHADING_MODE, MeshVisual::ShadingMode::TEXTURELESS_WITH_DIFFUSE_LIGHTING );
1269 //Test to see if mesh loads correctly.
1270 MeshVisualLoadsCorrectlyTest( propertyMap, application );
1274 //Test if mesh visual loads correctly when light position is manually set.
1275 int UtcDaliVisualFactoryGetMeshVisual7(void)
1277 //Set up test application first, so everything else can be handled.
1278 ToolkitTestApplication application;
1281 tet_infoline( "UtcDaliVisualFactoryGetMeshVisual7: Request mesh visual with custom light position." );
1283 //Set up visual properties.
1284 Property::Map propertyMap;
1285 propertyMap.Insert( Visual::Property::TYPE, Visual::MESH );
1286 propertyMap.Insert( MeshVisual::Property::OBJECT_URL, TEST_OBJ_FILE_NAME );
1287 propertyMap.Insert( MeshVisual::Property::MATERIAL_URL, TEST_MTL_FILE_NAME );
1288 propertyMap.Insert( MeshVisual::Property::TEXTURES_PATH, TEST_RESOURCE_DIR "/" );
1289 propertyMap.Insert( MeshVisual::Property::LIGHT_POSITION, Vector3( 0.0, 1.0, 2.0 ) );
1291 //Test to see if mesh loads correctly.
1292 MeshVisualLoadsCorrectlyTest( propertyMap, application );
1297 //Test if mesh visual loads correctly when supplied an object file without face normals or texture points.
1298 //Note that this notably tests object loader functionality.
1299 int UtcDaliVisualFactoryGetMeshVisual8(void)
1301 //Set up test application first, so everything else can be handled.
1302 ToolkitTestApplication application;
1304 tet_infoline( "UtcDaliVisualFactoryGetMeshVisual5: Request mesh visual with normal-less object file." );
1306 //Set up visual properties.
1307 Property::Map propertyMap;
1308 propertyMap.Insert( Visual::Property::TYPE, Visual::MESH );
1309 propertyMap.Insert( MeshVisual::Property::OBJECT_URL, TEST_SIMPLE_OBJ_FILE_NAME );
1310 propertyMap.Insert( MeshVisual::Property::MATERIAL_URL, TEST_MTL_FILE_NAME );
1311 propertyMap.Insert( MeshVisual::Property::TEXTURES_PATH, TEST_RESOURCE_DIR "/" );
1313 //Test to see if mesh loads correctly.
1314 MeshVisualLoadsCorrectlyTest( propertyMap, application );
1319 //Test if mesh visual handles the case of lacking an object file.
1320 int UtcDaliVisualFactoryGetMeshVisualN1(void)
1322 //Set up test application first, so everything else can be handled.
1323 ToolkitTestApplication application;
1325 tet_infoline( "UtcDaliVisualFactoryGetMeshVisualN1: Request mesh visual without object file" );
1327 //Set up visual properties.
1328 Property::Map propertyMap;
1329 propertyMap.Insert( Visual::Property::TYPE, Visual::MESH );
1330 propertyMap.Insert( MeshVisual::Property::MATERIAL_URL, TEST_MTL_FILE_NAME );
1331 propertyMap.Insert( MeshVisual::Property::TEXTURES_PATH, TEST_RESOURCE_DIR "/" );
1333 //Test to see if mesh doesn't load with these properties, as expected.
1334 MeshVisualDoesNotLoadCorrectlyTest( propertyMap, application );
1340 //Test if mesh visual handles the case of being passed invalid material and images urls.
1341 int UtcDaliVisualFactoryGetMeshVisualN2(void)
1343 //Set up test application first, so everything else can be handled.
1344 ToolkitTestApplication application;
1346 tet_infoline( "UtcDaliVisualFactoryGetMeshVisualN2: Request mesh visual with invalid material and images urls" );
1348 //Set up visual properties.
1349 Property::Map propertyMap;
1350 propertyMap.Insert( Visual::Property::TYPE, Visual::MESH );
1351 propertyMap.Insert( MeshVisual::Property::OBJECT_URL, TEST_OBJ_FILE_NAME );
1352 propertyMap.Insert( MeshVisual::Property::MATERIAL_URL, "invalid" );
1353 propertyMap.Insert( MeshVisual::Property::TEXTURES_PATH, "also invalid" );
1355 //Test to see if mesh doesn't load with these properties, as expected.
1356 MeshVisualDoesNotLoadCorrectlyTest( propertyMap, application );
1362 //Test if mesh visual handles the case of being passed an invalid object url
1363 int UtcDaliVisualFactoryGetMeshVisualN3(void)
1365 //Set up test application first, so everything else can be handled.
1366 ToolkitTestApplication application;
1367 tet_infoline( "UtcDaliVisualFactoryGetMeshVisualN3: Request mesh visual with invalid object url" );
1370 //Set up visual properties.
1371 Property::Map propertyMap;
1372 propertyMap.Insert( Visual::Property::TYPE, Visual::MESH );
1373 propertyMap.Insert( MeshVisual::Property::OBJECT_URL, "invalid" );
1374 propertyMap.Insert( MeshVisual::Property::MATERIAL_URL, TEST_MTL_FILE_NAME );
1375 propertyMap.Insert( MeshVisual::Property::TEXTURES_PATH, TEST_RESOURCE_DIR "/" );
1377 //Test to see if mesh doesn't load with these properties, as expected.
1378 MeshVisualDoesNotLoadCorrectlyTest( propertyMap, application );
1383 //Creates a primitive visual with the given property map and tests to see if it correctly loads in the given application.
1384 void TestPrimitiveVisualWithProperties( Property::Map& propertyMap, ToolkitTestApplication& application )
1386 VisualFactory factory = VisualFactory::Get();
1387 DALI_TEST_CHECK( factory );
1389 //Create a primitive visual.
1390 Visual::Base visual = factory.CreateVisual( propertyMap );
1391 DALI_TEST_CHECK( visual );
1393 //Create an actor on stage to house the visual.
1394 DummyControl actor = DummyControl::New();
1395 DummyControlImpl& dummyImpl = static_cast<DummyControlImpl&>(actor.GetImplementation());
1396 dummyImpl.RegisterVisual( Control::CONTROL_PROPERTY_END_INDEX + 1, visual );
1398 actor.SetSize( 200.f, 200.f );
1399 Stage::GetCurrent().Add( actor );
1400 visual.SetTransformAndSize(DefaultTransform(), Vector2( 200.f, 200.f ) );
1402 //Ensure set on stage.
1403 DALI_TEST_EQUALS( actor.GetRendererCount(), 1u, TEST_LOCATION );
1405 //Tell test application to load the visual.
1406 application.SendNotification();
1407 application.Render(0);
1409 Matrix testScaleMatrix;
1410 testScaleMatrix.SetIdentityAndScale( Vector3( 1.0, -1.0, 1.0 ) );
1411 Matrix actualScaleMatrix;
1413 //Test to see if the object has been successfully loaded.
1414 DALI_TEST_CHECK( application.GetGlAbstraction().GetUniformValue<Matrix>( "uObjectMatrix", actualScaleMatrix ) );
1415 DALI_TEST_EQUALS( actualScaleMatrix, testScaleMatrix, Math::MACHINE_EPSILON_100, TEST_LOCATION );
1417 //Finish by setting off stage, and ensuring this was successful.
1419 DALI_TEST_EQUALS( actor.GetRendererCount(), 0u, TEST_LOCATION );
1422 //Test if primitive shape loads correctly when supplied with only the bare minimum requirements, the shape to use.
1423 int UtcDaliVisualFactoryGetPrimitiveVisual1(void)
1425 //Set up test application first, so everything else can be handled.
1426 ToolkitTestApplication application;
1428 tet_infoline( "UtcDaliVisualFactoryGetPrimitiveVisual1: Request primitive visual with a shape only" );
1430 //Set up visual properties.
1431 Property::Map propertyMap;
1432 propertyMap.Insert( Visual::Property::TYPE, Visual::PRIMITIVE );
1433 propertyMap.Insert( PrimitiveVisual::Property::SHAPE, PrimitiveVisual::Shape::CUBE );
1435 //Test to see if shape loads correctly.
1436 TestPrimitiveVisualWithProperties( propertyMap, application );
1441 //Test if primitive shape loads correctly when supplied with all possible parameters
1442 int UtcDaliVisualFactoryGetPrimitiveVisual2(void)
1444 //Set up test application first, so everything else can be handled.
1445 ToolkitTestApplication application;
1447 tet_infoline( "UtcDaliVisualFactoryGetPrimitiveVisual2: Request primitive visual with everything" );
1449 //Set up visual properties.
1450 Property::Map propertyMap;
1451 propertyMap.Insert( Visual::Property::TYPE, Visual::PRIMITIVE );
1452 propertyMap.Insert( PrimitiveVisual::Property::SHAPE, PrimitiveVisual::Shape::CUBE );
1453 propertyMap.Insert( PrimitiveVisual::Property::MIX_COLOR, Vector4( 0.5, 0.5, 0.5, 1.0 ) );
1454 propertyMap.Insert( PrimitiveVisual::Property::SLICES, 10 );
1455 propertyMap.Insert( PrimitiveVisual::Property::STACKS, 20 );
1456 propertyMap.Insert( PrimitiveVisual::Property::SCALE_TOP_RADIUS, 30.0f );
1457 propertyMap.Insert( PrimitiveVisual::Property::SCALE_BOTTOM_RADIUS, 40.0f );
1458 propertyMap.Insert( PrimitiveVisual::Property::SCALE_HEIGHT, 50.0f );
1459 propertyMap.Insert( PrimitiveVisual::Property::SCALE_RADIUS, 60.0f );
1460 propertyMap.Insert( PrimitiveVisual::Property::BEVEL_PERCENTAGE, 0.7f );
1461 propertyMap.Insert( PrimitiveVisual::Property::BEVEL_SMOOTHNESS, 0.8f );
1462 propertyMap.Insert( MeshVisual::Property::LIGHT_POSITION, Vector3( 0.9, 1.0, 1.1 ) );
1464 //Test to see if shape loads correctly.
1465 TestPrimitiveVisualWithProperties( propertyMap, application );
1470 //Test if primitive shape loads a sphere correctly.
1471 int UtcDaliVisualFactoryGetPrimitiveVisual3(void)
1473 //Set up test application first, so everything else can be handled.
1474 ToolkitTestApplication application;
1476 tet_infoline( "UtcDaliVisualFactoryGetPrimitiveVisual3: Request primitive visual to display a sphere" );
1478 //Set up visual properties.
1479 Property::Map propertyMap;
1480 propertyMap.Insert( Visual::Property::TYPE, Visual::PRIMITIVE );
1481 propertyMap.Insert( PrimitiveVisual::Property::SHAPE, PrimitiveVisual::Shape::SPHERE );
1482 propertyMap.Insert( PrimitiveVisual::Property::MIX_COLOR, Vector4( 0.5, 0.5, 0.5, 1.0 ) );
1483 propertyMap.Insert( PrimitiveVisual::Property::SLICES, 10 );
1484 propertyMap.Insert( PrimitiveVisual::Property::STACKS, 20 );
1486 //Test to see if shape loads correctly.
1487 TestPrimitiveVisualWithProperties( propertyMap, application );
1492 //Test if primitive shape loads a conic section correctly.
1493 int UtcDaliVisualFactoryGetPrimitiveVisual4(void)
1495 //Set up test application first, so everything else can be handled.
1496 ToolkitTestApplication application;
1498 tet_infoline( "UtcDaliVisualFactoryGetPrimitiveVisual4: Request primitive visual to display a conic section" );
1500 //Set up visual properties.
1501 Property::Map propertyMap;
1502 propertyMap.Insert( Visual::Property::TYPE, Visual::PRIMITIVE );
1503 propertyMap.Insert( PrimitiveVisual::Property::SHAPE, PrimitiveVisual::Shape::CONICAL_FRUSTRUM );
1504 propertyMap.Insert( PrimitiveVisual::Property::MIX_COLOR, Vector4( 0.5, 0.5, 0.5, 1.0 ) );
1505 propertyMap.Insert( PrimitiveVisual::Property::SLICES, 10 );
1506 propertyMap.Insert( PrimitiveVisual::Property::SCALE_TOP_RADIUS, 30.0f );
1507 propertyMap.Insert( PrimitiveVisual::Property::SCALE_BOTTOM_RADIUS, 40.0f );
1508 propertyMap.Insert( PrimitiveVisual::Property::SCALE_HEIGHT, 50.0f );
1510 //Test to see if shape loads correctly.
1511 TestPrimitiveVisualWithProperties( propertyMap, application );
1516 //Test if primitive shape loads a bevelled cube correctly.
1517 int UtcDaliVisualFactoryGetPrimitiveVisual5(void)
1519 //Set up test application first, so everything else can be handled.
1520 ToolkitTestApplication application;
1522 tet_infoline( "UtcDaliVisualFactoryGetPrimitiveVisual5: Request primitive visual to display a bevelled cube" );
1524 //Set up visual properties.
1525 Property::Map propertyMap;
1526 propertyMap.Insert( Visual::Property::TYPE, Visual::PRIMITIVE );
1527 propertyMap.Insert( PrimitiveVisual::Property::SHAPE, PrimitiveVisual::Shape::BEVELLED_CUBE );
1528 propertyMap.Insert( PrimitiveVisual::Property::MIX_COLOR, Vector4( 0.5, 0.5, 0.5, 1.0 ) );
1529 propertyMap.Insert( PrimitiveVisual::Property::BEVEL_PERCENTAGE, 0.7f );
1531 //Test to see if shape loads correctly.
1532 TestPrimitiveVisualWithProperties( propertyMap, application );
1537 //Test if primitive shape loads an octahedron correctly.
1538 int UtcDaliVisualFactoryGetPrimitiveVisual6(void)
1540 //Set up test application first, so everything else can be handled.
1541 ToolkitTestApplication application;
1543 tet_infoline( "UtcDaliVisualFactoryGetPrimitiveVisual6: Request primitive visual to display an octahedron" );
1545 //Set up visual properties.
1546 Property::Map propertyMap;
1547 propertyMap.Insert( Visual::Property::TYPE, Visual::PRIMITIVE );
1548 propertyMap.Insert( PrimitiveVisual::Property::SHAPE, PrimitiveVisual::Shape::OCTAHEDRON );
1549 propertyMap.Insert( PrimitiveVisual::Property::MIX_COLOR, Vector4( 0.5, 0.5, 0.5, 1.0 ) );
1551 //Test to see if shape loads correctly.
1552 TestPrimitiveVisualWithProperties( propertyMap, application );
1557 //Test if primitive shape loads a cone correctly.
1558 int UtcDaliVisualFactoryGetPrimitiveVisual7(void)
1560 //Set up test application first, so everything else can be handled.
1561 ToolkitTestApplication application;
1563 tet_infoline( "UtcDaliVisualFactoryGetPrimitiveVisual7: Request primitive visual to display a cone" );
1565 //Set up visual properties.
1566 Property::Map propertyMap;
1567 propertyMap.Insert( Visual::Property::TYPE, Visual::PRIMITIVE );
1568 propertyMap.Insert( PrimitiveVisual::Property::SHAPE, PrimitiveVisual::Shape::CONE );
1569 propertyMap.Insert( PrimitiveVisual::Property::MIX_COLOR, Vector4( 0.5, 0.5, 0.5, 1.0 ) );
1570 propertyMap.Insert( PrimitiveVisual::Property::SLICES, 10 );
1571 propertyMap.Insert( PrimitiveVisual::Property::SCALE_TOP_RADIUS, 30.0f );
1572 propertyMap.Insert( PrimitiveVisual::Property::SCALE_HEIGHT, 50.0f );
1574 //Test to see if shape loads correctly.
1575 TestPrimitiveVisualWithProperties( propertyMap, application );
1580 //Test if primitive shape loads correctly when light position is manually set.
1581 int UtcDaliVisualFactoryGetPrimitiveVisual8(void)
1583 //Set up test application first, so everything else can be handled.
1584 ToolkitTestApplication application;
1586 tet_infoline( "UtcDaliVisualFactoryGetPrimitiveVisual8: Request primitive visual with set light position" );
1588 //Set up visual properties.
1589 Property::Map propertyMap;
1590 propertyMap.Insert( Visual::Property::TYPE, Visual::PRIMITIVE );
1591 propertyMap.Insert( PrimitiveVisual::Property::SHAPE, PrimitiveVisual::Shape::SPHERE );
1592 propertyMap.Insert( PrimitiveVisual::Property::MIX_COLOR, Vector4( 0.5, 0.5, 0.5, 1.0 ) );
1593 propertyMap.Insert( MeshVisual::Property::LIGHT_POSITION, Vector3( 0.0, 1.0, 2.0 ) );
1595 //Test to see if shape loads correctly.
1596 TestPrimitiveVisualWithProperties( propertyMap, application );
1601 //Test if primitive shape loads correctly when told to use too many slices.
1602 int UtcDaliVisualFactoryGetPrimitiveVisual9(void)
1604 //Set up test application first, so everything else can be handled.
1605 ToolkitTestApplication application;
1607 tet_infoline( "UtcDaliVisualFactoryGetPrimitiveVisual9: Request primitive visual with above-cap slices." );
1609 //Set up visual properties.
1610 Property::Map propertyMap;
1611 propertyMap.Insert( Visual::Property::TYPE, Visual::PRIMITIVE );
1612 propertyMap.Insert( PrimitiveVisual::Property::SHAPE, PrimitiveVisual::Shape::SPHERE );
1613 propertyMap.Insert( PrimitiveVisual::Property::SLICES, Property::Value( 1000000 ) );
1615 //Test to see if shape loads correctly.
1616 TestPrimitiveVisualWithProperties( propertyMap, application );
1621 //Test if primitive shape loads correctly when told to use too few slices. (2 slices or less.)
1622 int UtcDaliVisualFactoryGetPrimitiveVisual10(void)
1624 //Set up test application first, so everything else can be handled.
1625 ToolkitTestApplication application;
1627 tet_infoline( "UtcDaliVisualFactoryGetPrimitiveVisual10: Request primitive visual with too few slices." );
1629 //Set up visual properties.
1630 Property::Map propertyMap;
1631 propertyMap.Insert( Visual::Property::TYPE, Visual::PRIMITIVE );
1632 propertyMap.Insert( PrimitiveVisual::Property::SHAPE, PrimitiveVisual::Shape::SPHERE );
1633 propertyMap.Insert( PrimitiveVisual::Property::SLICES, Property::Value( 2 ) );
1635 //Test to see if shape loads correctly.
1636 TestPrimitiveVisualWithProperties( propertyMap, application );
1641 //Test if primitive shape loads correctly when told to use too many stacks.
1642 int UtcDaliVisualFactoryGetPrimitiveVisual11(void)
1644 //Set up test application first, so everything else can be handled.
1645 ToolkitTestApplication application;
1647 tet_infoline( "UtcDaliVisualFactoryGetPrimitiveVisual11: Request primitive visual with too many stacks." );
1649 //Set up visual properties.
1650 Property::Map propertyMap;
1651 propertyMap.Insert( Visual::Property::TYPE, Visual::PRIMITIVE );
1652 propertyMap.Insert( PrimitiveVisual::Property::SHAPE, PrimitiveVisual::Shape::SPHERE );
1653 propertyMap.Insert( PrimitiveVisual::Property::STACKS, Property::Value( 1000000 ) );
1655 //Test to see if shape loads correctly.
1656 TestPrimitiveVisualWithProperties( propertyMap, application );
1661 //Test if primitive shape loads correctly when told to use too few stacks. (1 stack or less.)
1662 int UtcDaliVisualFactoryGetPrimitiveVisual12(void)
1664 //Set up test application first, so everything else can be handled.
1665 ToolkitTestApplication application;
1667 tet_infoline( "UtcDaliVisualFactoryGetPrimitiveVisual12: Request primitive visual with too few stacks." );
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::STACKS, Property::Value( 1 ) );
1675 //Test to see if shape loads correctly.
1676 TestPrimitiveVisualWithProperties( propertyMap, application );
1681 //Test if primitive shape loads correctly when told to use invalid (zero or negative) dimensions.
1682 int UtcDaliVisualFactoryGetPrimitiveVisual13(void)
1684 //Set up test application first, so everything else can be handled.
1685 ToolkitTestApplication application;
1687 tet_infoline( "UtcDaliVisualFactoryGetPrimitiveVisual13: Request primitive visual with invalid scale dimensions." );
1689 //Set up visual properties.
1690 Property::Map propertyMap;
1691 propertyMap.Insert( Visual::Property::TYPE, Visual::PRIMITIVE );
1692 propertyMap.Insert( PrimitiveVisual::Property::SHAPE, PrimitiveVisual::Shape::SPHERE );
1693 propertyMap.Insert( PrimitiveVisual::Property::SCALE_DIMENSIONS, Vector3::ZERO );
1695 //Test to see if shape loads correctly.
1696 TestPrimitiveVisualWithProperties( propertyMap, application );
1701 //Test if primitive shape loads correctly when told to use too low a bevel percentage.
1702 int UtcDaliVisualFactoryGetPrimitiveVisual14(void)
1704 //Set up test application first, so everything else can be handled.
1705 ToolkitTestApplication application;
1707 tet_infoline( "UtcDaliVisualFactoryGetPrimitiveVisual14: Request primitive visual with too low a bevel percentage." );
1709 //Set up visual properties.
1710 Property::Map propertyMap;
1711 propertyMap.Insert( Visual::Property::TYPE, Visual::PRIMITIVE );
1712 propertyMap.Insert( PrimitiveVisual::Property::SHAPE, PrimitiveVisual::Shape::SPHERE );
1713 propertyMap.Insert( PrimitiveVisual::Property::BEVEL_PERCENTAGE, Property::Value( -1.0f ) );
1715 //Test to see if shape loads correctly.
1716 TestPrimitiveVisualWithProperties( propertyMap, application );
1721 //Test if primitive shape loads correctly when told to use too high a bevel percentage.
1722 int UtcDaliVisualFactoryGetPrimitiveVisual15(void)
1724 //Set up test application first, so everything else can be handled.
1725 ToolkitTestApplication application;
1727 tet_infoline( "UtcDaliVisualFactoryGetPrimitiveVisual15: Request primitive visual with too high a bevel percentage." );
1729 //Set up visual properties.
1730 Property::Map propertyMap;
1731 propertyMap.Insert( Visual::Property::TYPE, Visual::PRIMITIVE );
1732 propertyMap.Insert( PrimitiveVisual::Property::SHAPE, PrimitiveVisual::Shape::SPHERE );
1733 propertyMap.Insert( PrimitiveVisual::Property::BEVEL_PERCENTAGE, Property::Value( 2.0f ) );
1735 //Test to see if shape loads correctly.
1736 TestPrimitiveVisualWithProperties( propertyMap, application );
1741 //Test if primitive shape loads correctly when told to use too low a bevel smoothness.
1742 int UtcDaliVisualFactoryGetPrimitiveVisual16(void)
1744 //Set up test application first, so everything else can be handled.
1745 ToolkitTestApplication application;
1747 tet_infoline( "UtcDaliVisualFactoryGetPrimitiveVisual16: Request primitive visual with too low a bevel smoothness." );
1749 //Set up visual properties.
1750 Property::Map propertyMap;
1751 propertyMap.Insert( Visual::Property::TYPE, Visual::PRIMITIVE );
1752 propertyMap.Insert( PrimitiveVisual::Property::SHAPE, PrimitiveVisual::Shape::SPHERE );
1753 propertyMap.Insert( PrimitiveVisual::Property::BEVEL_SMOOTHNESS, Property::Value( -1.0f ) );
1755 //Test to see if shape loads correctly.
1756 TestPrimitiveVisualWithProperties( propertyMap, application );
1761 //Test if primitive shape loads correctly when told to use too high a bevel smoothness.
1762 int UtcDaliVisualFactoryGetPrimitiveVisual17(void)
1764 //Set up test application first, so everything else can be handled.
1765 ToolkitTestApplication application;
1767 tet_infoline( "UtcDaliVisualFactoryGetPrimitiveVisual17: Request primitive visual with too high a bevel smoothness." );
1769 //Set up visual properties.
1770 Property::Map propertyMap;
1771 propertyMap.Insert( Visual::Property::TYPE, Visual::PRIMITIVE );
1772 propertyMap.Insert( PrimitiveVisual::Property::SHAPE, PrimitiveVisual::Shape::SPHERE );
1773 propertyMap.Insert( PrimitiveVisual::Property::BEVEL_SMOOTHNESS, Property::Value( 2.0f ) );
1775 //Test to see if shape loads correctly.
1776 TestPrimitiveVisualWithProperties( propertyMap, application );
1781 //Test if primitive shape visual handles the case of not being passed a specific shape to use.
1782 int UtcDaliVisualFactoryGetPrimitiveVisualN1(void)
1784 //Set up test application first, so everything else can be handled.
1785 ToolkitTestApplication application;
1787 tet_infoline( "UtcDaliVisualFactoryGetPrimitiveVisualN1: Request primitive visual without shape" );
1789 //Set up visual properties, without supplying shape.
1790 Property::Map propertyMap;
1791 propertyMap.Insert( Visual::Property::TYPE, Visual::PRIMITIVE );
1793 //Test to see if shape loads regardless of missing input.
1794 TestPrimitiveVisualWithProperties( propertyMap, application );
1799 int UtcDaliVisualFactoryGetAnimatedImageVisual1(void)
1801 ToolkitTestApplication application;
1802 tet_infoline( "UtcDaliVisualFactoryGetAnimatedImageVisual1: Request animated image visual with a gif url" );
1804 VisualFactory factory = VisualFactory::Get();
1805 Visual::Base visual = factory.CreateVisual( TEST_GIF_FILE_NAME, ImageDimensions() );
1806 DALI_TEST_CHECK( visual );
1808 TestGlAbstraction& gl = application.GetGlAbstraction();
1809 TraceCallStack& textureTrace = gl.GetTextureTrace();
1810 textureTrace.Enable(true);
1812 DummyControl actor = DummyControl::New();
1813 DummyControlImpl& dummyImpl = static_cast<DummyControlImpl&>(actor.GetImplementation());
1814 dummyImpl.RegisterVisual( Control::CONTROL_PROPERTY_END_INDEX + 1, visual );
1815 actor.SetSize( 200.0f, 200.0f );
1816 Stage::GetCurrent().Add( actor );
1818 application.SendNotification();
1819 application.Render();
1821 // renderer is added to actor
1822 DALI_TEST_CHECK( actor.GetRendererCount() == 1u );
1824 // test the uniforms which used to handle the atlas rect
1825 // the four frames should be located inside atlas as follows: atlas size 100*100
1834 Renderer renderer = actor.GetRendererAt( 0u );
1835 DALI_TEST_CHECK( renderer );
1837 Property::Value atlasRectValue = renderer.GetProperty( renderer.GetPropertyIndex( "uAtlasRect" ) );
1838 // take into consideration the half pixel correction
1839 DALI_TEST_EQUALS( atlasRectValue.Get<Vector4>(), Vector4(0.5f, 0.5f, 49.5f, 49.5f)/100.f, Math::MACHINE_EPSILON_100, TEST_LOCATION );
1841 // waiting for the resource uploading
1842 application.SendNotification();
1843 application.Render();
1845 DALI_TEST_EQUALS( textureTrace.FindMethod("BindTexture"), true, TEST_LOCATION );
1847 // Force the timer used by the animatedImageVisual to tick,
1848 Dali::Timer timer = Timer::New( 0 );
1849 timer.MockEmitSignal();
1850 application.SendNotification();
1851 application.Render();
1852 atlasRectValue = renderer.GetProperty( renderer.GetPropertyIndex( "uAtlasRect" ) );
1853 // take into consideration the half pixel correction
1854 DALI_TEST_EQUALS( atlasRectValue.Get<Vector4>(), Vector4(50.5f, 0.5f, 99.5f, 49.5f)/100.f, Math::MACHINE_EPSILON_100, TEST_LOCATION );
1856 // Force the timer used by the animatedImageVisual to tick,
1857 timer.MockEmitSignal();
1858 application.SendNotification();
1859 application.Render();
1860 atlasRectValue = renderer.GetProperty( renderer.GetPropertyIndex( "uAtlasRect" ) );
1861 // take into consideration the half pixel correction
1862 DALI_TEST_EQUALS( atlasRectValue.Get<Vector4>(), Vector4(0.5f, 50.5f, 49.5f, 99.5f)/100.f, Math::MACHINE_EPSILON_100, TEST_LOCATION );
1864 // Force the timer used by the animatedImageVisual to tick,
1865 timer.MockEmitSignal();
1866 application.SendNotification();
1867 application.Render();
1868 atlasRectValue = renderer.GetProperty( renderer.GetPropertyIndex( "uAtlasRect" ) );
1869 // take into consideration the half pixel correction
1870 DALI_TEST_EQUALS( atlasRectValue.Get<Vector4>(), Vector4(50.5f, 50.5f, 99.5f, 99.5f)/100.f, Math::MACHINE_EPSILON_100, TEST_LOCATION );
1872 // Test SetOffStage().
1874 DALI_TEST_CHECK( actor.GetRendererCount() == 0u );
1879 int UtcDaliVisualFactoryGetAnimatedImageVisual2(void)
1881 ToolkitTestApplication application;
1882 tet_infoline( "UtcDaliVisualFactoryGetAnimatedImageVisual2: Request animated image visual with a Property::Map, test custom wrap mode and pixel area" );
1884 const Vector4 pixelArea(-0.5f, -0.5f, 2.f, 2.f);
1885 Property::Map propertyMap;
1886 propertyMap.Add( Visual::Property::TYPE, Visual::IMAGE )
1887 .Add( ImageVisual::Property::URL, TEST_GIF_FILE_NAME )
1888 .Add( ImageVisual::Property::PIXEL_AREA, pixelArea )
1889 .Add( ImageVisual::Property::WRAP_MODE_U, WrapMode::MIRRORED_REPEAT )
1890 .Add( ImageVisual::Property::WRAP_MODE_V, WrapMode::REPEAT );
1892 Visual::Base visual = VisualFactory::Get().CreateVisual( propertyMap );
1893 DALI_TEST_CHECK( visual );
1895 TestGlAbstraction& gl = application.GetGlAbstraction();
1896 TraceCallStack& textureTrace = gl.GetTextureTrace();
1897 textureTrace.Enable(true);
1898 TraceCallStack& texParameterTrace = gl.GetTexParameterTrace();
1899 texParameterTrace.Enable( true );
1901 DummyControl actor = DummyControl::New();
1902 DummyControlImpl& dummyImpl = static_cast<DummyControlImpl&>(actor.GetImplementation());
1903 dummyImpl.RegisterVisual( Control::CONTROL_PROPERTY_END_INDEX + 1, visual );
1904 actor.SetSize( 200.0f, 200.0f );
1905 Stage::GetCurrent().Add( actor );
1907 application.SendNotification();
1908 application.Render();
1910 DALI_TEST_CHECK( actor.GetRendererCount() == 1u );
1912 DALI_TEST_EQUALS( textureTrace.FindMethod("BindTexture"), true, TEST_LOCATION );
1914 // For animated image visual, the wrapping is handled manually in shader, so the following gl function should not be called
1915 std::stringstream out;
1916 out << GL_TEXTURE_2D << ", " << GL_TEXTURE_WRAP_S << ", " << GL_MIRRORED_REPEAT;
1917 DALI_TEST_CHECK( !texParameterTrace.FindMethodAndParams("TexParameteri", out.str()) );
1919 out << GL_TEXTURE_2D << ", " << GL_TEXTURE_WRAP_T << ", " << GL_REPEAT;
1920 DALI_TEST_CHECK( !texParameterTrace.FindMethodAndParams("TexParameteri", out.str()) );
1922 // test the uniforms which used to handle the wrap mode
1923 Renderer renderer = actor.GetRendererAt( 0u );
1924 DALI_TEST_CHECK( renderer );
1926 Property::Value pixelAreaValue = renderer.GetProperty( renderer.GetPropertyIndex( "pixelArea" ) );
1927 DALI_TEST_EQUALS( pixelAreaValue.Get<Vector4>(), pixelArea, TEST_LOCATION );
1928 Vector4 pixelAreaUniform;
1929 DALI_TEST_CHECK( gl.GetUniformValue<Vector4>( "pixelArea", pixelAreaUniform ) );
1930 DALI_TEST_EQUALS( pixelArea, pixelAreaUniform, Math::MACHINE_EPSILON_100, TEST_LOCATION );
1932 Property::Value wrapModeValue = renderer.GetProperty( renderer.GetPropertyIndex( "wrapMode" ) );
1933 Vector2 wrapMode( WrapMode::MIRRORED_REPEAT-1, WrapMode::REPEAT-1 );
1934 DALI_TEST_EQUALS( wrapModeValue.Get<Vector2>(), wrapMode, TEST_LOCATION );
1935 Vector2 wrapModeUniform;
1936 DALI_TEST_CHECK( gl.GetUniformValue<Vector2>( "wrapMode", wrapModeUniform ) );
1937 DALI_TEST_EQUALS( wrapMode, wrapModeUniform, Math::MACHINE_EPSILON_100, TEST_LOCATION );
1940 DALI_TEST_CHECK( actor.GetRendererCount() == 0u );