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-event-thread-callback.h>
22 #include <dali/public-api/rendering/renderer.h>
23 #include <dali/public-api/rendering/texture-set.h>
24 #include <dali/public-api/rendering/shader.h>
25 #include <dali/devel-api/images/nine-patch-image.h>
26 #include <dali-toolkit/devel-api/align-enums.h>
27 #include <dali-toolkit/devel-api/visuals/visual-properties-devel.h>
28 #include <dali-toolkit/devel-api/visuals/image-visual-properties-devel.h>
29 #include <dali-toolkit/devel-api/visual-factory/visual-factory.h>
30 #include <dali-toolkit/dali-toolkit.h>
31 #include "dummy-control.h"
34 using namespace Dali::Toolkit;
38 typedef NinePatchImage::StretchRanges StretchRanges;
40 const char* TEST_NPATCH_FILE_NAME = TEST_RESOURCE_DIR "/button-up-1.9.png";
41 const char* TEST_SVG_FILE_NAME = TEST_RESOURCE_DIR "/svg1.svg";
42 const char* TEST_OBJ_FILE_NAME = TEST_RESOURCE_DIR "/Cube.obj";
43 const char* TEST_MTL_FILE_NAME = TEST_RESOURCE_DIR "/ToyRobot-Metal.mtl";
44 const char* TEST_SIMPLE_OBJ_FILE_NAME = TEST_RESOURCE_DIR "/Cube-Points-Only.obj";
45 const char* TEST_SIMPLE_MTL_FILE_NAME = TEST_RESOURCE_DIR "/ToyRobot-Metal-Simple.mtl";
47 // resolution: 50*50, frame count: 4, frame delay: 0.2 second for each frame
48 const char* TEST_GIF_FILE_NAME = TEST_RESOURCE_DIR "/anim.gif";
50 // resolution: 34*34, pixel format: RGBA8888
51 static const char* gImage_34_RGBA = TEST_RESOURCE_DIR "/icon-edit.png";
54 Property::Map DefaultTransform()
56 Property::Map transformMap;
58 .Add( Toolkit::DevelVisual::Transform::Property::OFFSET, Vector2(0.0f, 0.0f) )
59 .Add( Toolkit::DevelVisual::Transform::Property::SIZE, Vector2(1.0f, 1.0f) )
60 .Add( Toolkit::DevelVisual::Transform::Property::ORIGIN, Toolkit::Align::CENTER )
61 .Add( Toolkit::DevelVisual::Transform::Property::ANCHOR_POINT, Toolkit::Align::CENTER )
62 .Add( Toolkit::DevelVisual::Transform::Property::OFFSET_POLICY, Vector2( Toolkit::DevelVisual::Transform::Policy::RELATIVE, Toolkit::DevelVisual::Transform::Policy::RELATIVE ) )
63 .Add( Toolkit::DevelVisual::Transform::Property::SIZE_POLICY, Vector2( Toolkit::DevelVisual::Transform::Policy::RELATIVE, Toolkit::DevelVisual::Transform::Policy::RELATIVE ) );
67 Integration::Bitmap* CreateBitmap( unsigned int imageWidth, unsigned int imageHeight, unsigned int initialColor, Pixel::Format pixelFormat )
69 Integration::Bitmap* bitmap = Integration::Bitmap::New( Integration::Bitmap::BITMAP_2D_PACKED_PIXELS, ResourcePolicy::OWNED_RETAIN );
70 Integration::PixelBuffer* pixbuffer = bitmap->GetPackedPixelsProfile()->ReserveBuffer( pixelFormat, imageWidth, imageHeight, imageWidth, imageHeight );
71 unsigned int bytesPerPixel = GetBytesPerPixel( pixelFormat );
73 memset( pixbuffer, initialColor, imageHeight * imageWidth * bytesPerPixel );
78 void InitialiseRegionsToZeroAlpha( Integration::Bitmap* image, unsigned int imageWidth, unsigned int imageHeight, Pixel::Format pixelFormat )
80 PixelBuffer* pixbuffer = image->GetBuffer();
81 unsigned int bytesPerPixel = GetBytesPerPixel( pixelFormat );
83 for( unsigned int row = 0; row < imageWidth; ++row )
85 unsigned int pixelOffset = row * bytesPerPixel;
86 pixbuffer[ pixelOffset + 3 ] = 0x00;
87 pixelOffset += ( imageHeight - 1 ) * imageWidth * bytesPerPixel;
88 pixbuffer[ pixelOffset + 3 ] = 0x00;
91 for ( unsigned int column = 0; column < imageHeight; ++column )
93 unsigned int pixelOffset = column * imageWidth * bytesPerPixel;
94 pixbuffer[ pixelOffset + 3 ] = 0x00;
95 pixelOffset += ( imageWidth -1 ) * bytesPerPixel;
96 pixbuffer[ pixelOffset + 3 ] = 0x00;
100 void AddStretchRegionsToImage( Integration::Bitmap* image, unsigned int imageWidth, unsigned int imageHeight, const StretchRanges& stretchRangesX, const StretchRanges& stretchRangesY, Pixel::Format pixelFormat )
102 PixelBuffer* pixbuffer = image->GetBuffer();
103 unsigned int bytesPerPixel = GetBytesPerPixel( pixelFormat );
105 for(StretchRanges::ConstIterator it = stretchRangesX.Begin(); it != stretchRangesX.End(); ++it)
107 const Uint16Pair& range = *it;
108 //since the stretch range is in the cropped image space, we need to offset by 1 to get it to the uncropped image space
109 for( unsigned int column = range.GetX() + 1u; column < range.GetY() + 1u; ++column )
111 unsigned int pixelOffset = column * bytesPerPixel;
112 pixbuffer[ pixelOffset ] = 0x00;
113 pixbuffer[ pixelOffset + 1 ] = 0x00;
114 pixbuffer[ pixelOffset + 2 ] = 0x00;
115 pixbuffer[ pixelOffset + 3 ] = 0xFF;
120 for(StretchRanges::ConstIterator it = stretchRangesY.Begin(); it != stretchRangesY.End(); ++it)
122 const Uint16Pair& range = *it;
123 //since the stretch range is in the cropped image space, we need to offset by 1 to get it to the uncropped image space
124 for( unsigned int row = range.GetX() + 1u; row < range.GetY() + 1u; ++row )
126 unsigned int pixelOffset = row * imageWidth * bytesPerPixel;
127 pixbuffer[ pixelOffset ] = 0x00;
128 pixbuffer[ pixelOffset + 1 ] = 0x00;
129 pixbuffer[ pixelOffset + 2 ] = 0x00;
130 pixbuffer[ pixelOffset + 3 ] = 0xFF;
135 void AddChildRegionsToImage( Integration::Bitmap* image, unsigned int imageWidth, unsigned int imageHeight, const Vector4& requiredChildRegion, Pixel::Format pixelFormat )
137 PixelBuffer* pixbuffer = image->GetBuffer();
138 unsigned int bytesPerPixel = GetBytesPerPixel( pixelFormat );
140 Integration::Bitmap::PackedPixelsProfile* srcProfile = image->GetPackedPixelsProfile();
141 unsigned int bufferStride = srcProfile->GetBufferStride();
143 // Add bottom child region
144 for( unsigned int column = requiredChildRegion.x; column < imageWidth - requiredChildRegion.z; ++column )
146 unsigned int pixelOffset = column * bytesPerPixel;
147 pixelOffset += ( imageHeight - 1 ) * bufferStride;
148 pixbuffer[ pixelOffset ] = 0x00;
149 pixbuffer[ pixelOffset + 1 ] = 0x00;
150 pixbuffer[ pixelOffset + 2 ] = 0x00;
151 pixbuffer[ pixelOffset + 3 ] = 0xFF;
154 // Add right child region
155 for ( unsigned int row = requiredChildRegion.y; row < imageHeight - requiredChildRegion.w; ++row )
157 unsigned int pixelOffset = row * bufferStride + ( imageWidth - 1 ) * bytesPerPixel;
158 pixbuffer[ pixelOffset ] = 0x00;
159 pixbuffer[ pixelOffset + 1 ] = 0x00;
160 pixbuffer[ pixelOffset + 2 ] = 0x00;
161 pixbuffer[ pixelOffset + 3 ] = 0xFF;
165 Integration::ResourcePointer CustomizeNinePatch( TestApplication& application,
166 unsigned int ninePatchImageWidth,
167 unsigned int ninePatchImageHeight,
168 const StretchRanges& stretchRangesX,
169 const StretchRanges& stretchRangesY,
170 bool addChildRegion = false,
171 Vector4 requiredChildRegion = Vector4::ZERO )
173 TestPlatformAbstraction& platform = application.GetPlatform();
175 Pixel::Format pixelFormat = Pixel::RGBA8888;
177 tet_infoline("Create Bitmap");
178 platform.SetClosestImageSize(Vector2( ninePatchImageWidth, ninePatchImageHeight));
179 Integration::Bitmap* bitmap = CreateBitmap( ninePatchImageWidth, ninePatchImageHeight, 0xFF, pixelFormat );
181 tet_infoline("Clear border regions");
182 InitialiseRegionsToZeroAlpha( bitmap, ninePatchImageWidth, ninePatchImageHeight, pixelFormat );
184 tet_infoline("Add Stretch regions to Bitmap");
185 AddStretchRegionsToImage( bitmap, ninePatchImageWidth, ninePatchImageHeight, stretchRangesX, stretchRangesY, pixelFormat );
189 tet_infoline("Add Child regions to Bitmap");
190 AddChildRegionsToImage( bitmap, ninePatchImageWidth, ninePatchImageHeight, requiredChildRegion, pixelFormat );
193 tet_infoline("Getting resource");
194 Integration::ResourcePointer resourcePtr(bitmap);
195 //platform.SetResourceLoaded( 0, Dali::Integration::ResourceBitmap, resourcePtr );
196 platform.SetSynchronouslyLoadedResource( resourcePtr);
201 void TestVisualRender( ToolkitTestApplication& application,
203 Visual::Base& visual,
204 std::size_t expectedSamplers = 0,
205 ImageDimensions imageDimensions = ImageDimensions(),
206 Integration::ResourcePointer resourcePtr = Integration::ResourcePointer())
208 DummyControlImpl& dummyImpl = static_cast<DummyControlImpl&>(actor.GetImplementation());
209 dummyImpl.RegisterVisual( DummyControl::Property::TEST_VISUAL, visual );
213 // set the image size, for test case, this needs to be set before loading started
214 application.GetPlatform().SetClosestImageSize( Vector2(imageDimensions.GetWidth(), imageDimensions.GetHeight()) );
217 actor.SetSize( 200.f, 200.f );
218 DALI_TEST_EQUALS( actor.GetRendererCount(), 0u, TEST_LOCATION );
220 Stage::GetCurrent().Add( actor );
222 application.SendNotification();
223 application.Render();
225 application.Render();
226 application.SendNotification();
230 DALI_TEST_EQUALS( application.GetPlatform().WasCalled(TestPlatformAbstraction::LoadResourceSynchronouslyFunc ), true, TEST_LOCATION);
233 DALI_TEST_EQUALS( actor.GetRendererCount(), 1u, TEST_LOCATION );
240 void dali_visual_factory_startup(void)
242 test_return_value = TET_UNDEF;
245 void dali_visual_factory_cleanup(void)
247 test_return_value = TET_PASS;
250 int UtcDaliVisualFactoryGet(void)
252 ToolkitTestApplication application;
253 tet_infoline( "UtcDaliVisualFactory" );
257 type = TypeRegistry::Get().GetTypeInfo( "VisualFactory" );
258 DALI_TEST_CHECK( type );
259 BaseHandle handle = type.CreateInstance();
260 DALI_TEST_CHECK( handle );
262 VisualFactory factory;
263 factory = VisualFactory::Get();
264 DALI_TEST_CHECK( factory );
266 VisualFactory newFactory = VisualFactory::Get();
267 DALI_TEST_CHECK( newFactory );
269 // Check that visual factory is a singleton
270 DALI_TEST_CHECK(factory == newFactory);
275 int UtcDaliVisualFactoryCopyAndAssignment(void)
277 ToolkitTestApplication application;
278 tet_infoline( "UtcDaliVisualFactoryCopyAndAssignment" );
279 VisualFactory factory = VisualFactory::Get();
281 VisualFactory factoryCopy( factory );
282 DALI_TEST_CHECK(factory == factoryCopy);
284 VisualFactory emptyFactory;
285 VisualFactory emptyFactoryCopy( emptyFactory );
286 DALI_TEST_CHECK(emptyFactory == emptyFactoryCopy);
288 VisualFactory factoryEquals;
289 factoryEquals = factory;
290 DALI_TEST_CHECK(factory == factoryEquals);
292 VisualFactory emptyFactoryEquals;
293 emptyFactoryEquals = emptyFactory;
294 DALI_TEST_CHECK( emptyFactory == emptyFactoryEquals );
298 DALI_TEST_CHECK( factory = factoryCopy );
303 int UtcDaliVisualFactoryGetColorVisual1(void)
305 ToolkitTestApplication application;
306 tet_infoline( "UtcDaliVisualFactoryGetColorVisual1: Request color visual with a Property::Map" );
308 VisualFactory factory = VisualFactory::Get();
309 DALI_TEST_CHECK( factory );
311 Property::Map propertyMap;
312 Vector4 testColor( 1.f, 0.5f, 0.3f, 0.2f );
313 propertyMap.Insert(Visual::Property::TYPE, Visual::COLOR);
314 propertyMap.Insert(ColorVisual::Property::MIX_COLOR, testColor);
316 Visual::Base visual = factory.CreateVisual(propertyMap);
317 DALI_TEST_CHECK( visual );
319 DummyControl actor = DummyControl::New(true);
320 TestVisualRender( application, actor, visual );
322 Vector3 actualValue(Vector4::ZERO);
324 TestGlAbstraction& gl = application.GetGlAbstraction();
325 DALI_TEST_CHECK( gl.GetUniformValue<Vector3>( "mixColor", actualValue ) );
326 DALI_TEST_CHECK( gl.GetUniformValue<float>( "opacity", opacity ) );
327 DALI_TEST_EQUALS( actualValue, Vector3(testColor), TEST_LOCATION );
328 DALI_TEST_EQUALS( opacity, testColor.a, TEST_LOCATION );
333 int UtcDaliVisualFactoryGetColorVisual2(void)
335 ToolkitTestApplication application;
336 tet_infoline( "UtcDaliVisualFactoryGetColorVisual2: Request color visual with a Vector4" );
338 VisualFactory factory = VisualFactory::Get();
339 DALI_TEST_CHECK( factory );
341 Vector4 testColor( 1.f, 0.5f, 0.3f, 0.2f );
342 Dali::Property::Map map;
343 map[ Visual::Property::TYPE ] = Visual::COLOR;
344 map[ ColorVisual::Property::MIX_COLOR ] = testColor;
345 Visual::Base visual = factory.CreateVisual( map );
346 DALI_TEST_CHECK( visual );
348 DummyControl actor = DummyControl::New(true);
349 TestVisualRender( application, actor, visual );
353 TestGlAbstraction& gl = application.GetGlAbstraction();
354 DALI_TEST_CHECK( gl.GetUniformValue<Vector3>( "mixColor", actualValue ) );
355 DALI_TEST_CHECK( gl.GetUniformValue<float>( "opacity", opacity ) );
356 DALI_TEST_EQUALS( actualValue, Vector3(testColor), TEST_LOCATION );
357 DALI_TEST_EQUALS( opacity, testColor.a, TEST_LOCATION );
359 Stage::GetCurrent().Remove(actor);
360 DALI_TEST_CHECK( actor.GetRendererCount() == 0u );
365 int UtcDaliVisualFactoryGetBorderVisual1(void)
367 ToolkitTestApplication application;
368 tet_infoline( "UtcDaliVisualFactoryGetBorderVisual1: Request border visual with a Property::Map" );
370 VisualFactory factory = VisualFactory::Get();
371 DALI_TEST_CHECK( factory );
373 Property::Map propertyMap;
374 Vector4 testColor( 1.f, 0.5f, 0.3f, 0.2f );
375 float testSize = 5.f;
376 propertyMap.Insert(Visual::Property::TYPE, Visual::BORDER);
377 propertyMap.Insert(BorderVisual::Property::COLOR, testColor);
378 propertyMap.Insert(BorderVisual::Property::SIZE, testSize);
380 Visual::Base visual = factory.CreateVisual(propertyMap);
381 DALI_TEST_CHECK( visual );
383 DummyControl actor = DummyControl::New(true);
384 DummyControlImpl& dummyImpl = static_cast<DummyControlImpl&>(actor.GetImplementation());
385 dummyImpl.RegisterVisual( DummyControl::Property::TEST_VISUAL, visual );
386 actor.SetSize(200.f, 200.f);
387 Stage::GetCurrent().Add( actor );
388 visual.SetTransformAndSize(DefaultTransform(), Vector2(200.f, 200.f));
390 DALI_TEST_CHECK( actor.GetRendererCount() == 1u );
391 int blendMode = actor.GetRendererAt(0u).GetProperty<int>( Renderer::Property::BLEND_MODE );
392 DALI_TEST_EQUALS( static_cast<BlendMode::Type>(blendMode), BlendMode::ON, TEST_LOCATION );
394 TestGlAbstraction& gl = application.GetGlAbstraction();
396 application.SendNotification();
397 application.Render(0);
399 Vector4 actualColor(Vector4::ZERO);
400 DALI_TEST_CHECK( gl.GetUniformValue<Vector4>( "borderColor", actualColor ) );
401 DALI_TEST_EQUALS( actualColor, testColor, TEST_LOCATION );
403 float actualSize = 0.f;
404 DALI_TEST_CHECK( gl.GetUniformValue<float>( "borderSize", actualSize ) );
405 DALI_TEST_EQUALS( actualSize, testSize, TEST_LOCATION );
408 DALI_TEST_CHECK( actor.GetRendererCount() == 0u );
413 int UtcDaliVisualFactoryGetBorderVisual2(void)
415 ToolkitTestApplication application;
416 tet_infoline( "UtcDaliVisualFactoryGetBorderVisual2: Request border visual with a borderSize and a borderColor" );
418 VisualFactory factory = VisualFactory::Get();
419 DALI_TEST_CHECK( factory );
421 Vector4 testColor( 1.f, 0.5f, 0.3f, 1.f );
422 float testSize = 5.f;
424 Dali::Property::Map propertyMap;
425 propertyMap[ Visual::Property::TYPE ] = Visual::BORDER;
426 propertyMap[ BorderVisual::Property::COLOR ] = testColor;
427 propertyMap[ BorderVisual::Property::SIZE ] = testSize;
428 Visual::Base visual = factory.CreateVisual( propertyMap );
429 DALI_TEST_CHECK( visual );
431 DummyControl actor = DummyControl::New(true);
432 DummyControlImpl& dummyImpl = static_cast<DummyControlImpl&>(actor.GetImplementation());
433 dummyImpl.RegisterVisual( DummyControl::Property::TEST_VISUAL, visual );
434 actor.SetSize(200.f, 200.f);
435 Stage::GetCurrent().Add( actor );
436 visual.SetTransformAndSize(DefaultTransform(), Vector2(200.f, 200.f));
438 DALI_TEST_CHECK( actor.GetRendererCount() == 1u );
440 TestGlAbstraction& gl = application.GetGlAbstraction();
442 application.SendNotification();
443 application.Render(0);
445 int blendMode = actor.GetRendererAt(0u).GetProperty<int>( Renderer::Property::BLEND_MODE );
446 DALI_TEST_EQUALS( static_cast<BlendMode::Type>(blendMode), BlendMode::AUTO, TEST_LOCATION );
448 Vector4 actualColor(Vector4::ZERO);
449 DALI_TEST_CHECK( gl.GetUniformValue<Vector4>( "borderColor", actualColor ) );
450 DALI_TEST_EQUALS( actualColor, testColor, TEST_LOCATION );
452 float actualSize = 0.f;
453 DALI_TEST_CHECK( gl.GetUniformValue<float>( "borderSize", actualSize ) );
454 DALI_TEST_EQUALS( actualSize, testSize, TEST_LOCATION );
458 // enable the anti-aliasing
459 Dali::Property::Map map;
460 map[ Visual::Property::TYPE ] = Visual::BORDER;
461 map[ BorderVisual::Property::COLOR ] = testColor;
462 map[ BorderVisual::Property::SIZE ] = testSize;
463 map[ BorderVisual::Property::ANTI_ALIASING ] = true;
464 visual = factory.CreateVisual( map );
466 dummyImpl.RegisterVisual( Control::CONTROL_PROPERTY_END_INDEX + 1, visual );
467 Stage::GetCurrent().Add( actor );
469 blendMode = actor.GetRendererAt(0u).GetProperty<int>( Renderer::Property::BLEND_MODE );
470 DALI_TEST_EQUALS( static_cast<BlendMode::Type>(blendMode), BlendMode::ON, TEST_LOCATION );
475 int UtcDaliVisualFactoryGetLinearGradientVisual(void)
477 ToolkitTestApplication application;
478 tet_infoline("UtcDaliVisualFactoryGetRadialGradientVisual");
480 VisualFactory factory = VisualFactory::Get();
481 DALI_TEST_CHECK( factory );
483 Property::Map propertyMap;
484 propertyMap.Insert(Visual::Property::TYPE, Visual::GRADIENT);
486 Vector2 start(-1.f, -1.f);
487 Vector2 end(1.f, 1.f);
488 propertyMap.Insert(GradientVisual::Property::START_POSITION, start);
489 propertyMap.Insert(GradientVisual::Property::END_POSITION, end);
490 propertyMap.Insert(GradientVisual::Property::SPREAD_METHOD, GradientVisual::SpreadMethod::REPEAT);
492 Property::Array stopOffsets;
493 stopOffsets.PushBack( 0.2f );
494 stopOffsets.PushBack( 0.8f );
495 propertyMap.Insert(GradientVisual::Property::STOP_OFFSET, stopOffsets);
497 Property::Array stopColors;
498 stopColors.PushBack( Color::RED );
499 stopColors.PushBack( Color::GREEN );
500 propertyMap.Insert(GradientVisual::Property::STOP_COLOR, stopColors);
502 Visual::Base visual = factory.CreateVisual(propertyMap);
503 DALI_TEST_CHECK( visual );
505 // A lookup texture is generated and pass to shader as sampler
506 DummyControl actor = DummyControl::New(true);
507 TestVisualRender( application, actor, visual, 1u);
512 int UtcDaliVisualFactoryGetRadialGradientVisual(void)
514 ToolkitTestApplication application;
515 tet_infoline("UtcDaliVisualFactoryGetRadialGradientVisual");
517 VisualFactory factory = VisualFactory::Get();
518 DALI_TEST_CHECK( factory );
520 Property::Map propertyMap;
521 propertyMap.Insert(Visual::Property::TYPE, Visual::GRADIENT);
523 Vector2 center(100.f, 100.f);
524 float radius = 100.f;
525 propertyMap.Insert(GradientVisual::Property::UNITS, GradientVisual::Units::USER_SPACE);
526 propertyMap.Insert(GradientVisual::Property::CENTER, center);
527 propertyMap.Insert(GradientVisual::Property::RADIUS, radius);
529 Property::Array stopOffsets;
530 stopOffsets.PushBack( 0.0f );
531 stopOffsets.PushBack( 1.f );
532 propertyMap.Insert(GradientVisual::Property::STOP_OFFSET, stopOffsets);
534 Property::Array stopColors;
535 stopColors.PushBack( Color::RED );
536 stopColors.PushBack( Color::GREEN );
537 propertyMap.Insert(GradientVisual::Property::STOP_COLOR, stopColors);
539 Visual::Base visual = factory.CreateVisual(propertyMap);
540 DALI_TEST_CHECK( visual );
542 // A lookup texture is generated and pass to shader as sampler
543 DummyControl actor = DummyControl::New(true);
544 TestVisualRender( application, actor, visual, 1u );
546 Matrix3 alignMatrix( radius, 0.f, 0.f, 0.f, radius, 0.f, center.x, center.y, 1.f );
547 alignMatrix.Invert();
549 Matrix3 actualValue( Matrix3::IDENTITY );
550 TestGlAbstraction& gl = application.GetGlAbstraction();
551 DALI_TEST_CHECK( gl.GetUniformValue<Matrix3>( "uAlignmentMatrix", actualValue ) );
552 DALI_TEST_EQUALS( actualValue, alignMatrix, Math::MACHINE_EPSILON_100, TEST_LOCATION );
557 int UtcDaliVisualFactoryDefaultOffsetsGradientVisual(void)
559 ToolkitTestApplication application;
560 tet_infoline("UtcDaliVisualFactoryGetRadialGradientVisual");
562 VisualFactory factory = VisualFactory::Get();
563 DALI_TEST_CHECK( factory );
565 Property::Map propertyMap;
566 propertyMap.Insert(Visual::Property::TYPE, Visual::GRADIENT);
568 Vector2 start(-1.f, -1.f);
569 Vector2 end(1.f, 1.f);
570 propertyMap.Insert(GradientVisual::Property::START_POSITION, start);
571 propertyMap.Insert(GradientVisual::Property::END_POSITION, end);
572 propertyMap.Insert(GradientVisual::Property::SPREAD_METHOD, GradientVisual::SpreadMethod::REPEAT);
574 Property::Array stopColors;
575 stopColors.PushBack( Color::RED );
576 stopColors.PushBack( Color::GREEN );
577 propertyMap.Insert(GradientVisual::Property::STOP_COLOR, stopColors);
579 Visual::Base visual = factory.CreateVisual(propertyMap);
580 DALI_TEST_CHECK( visual );
582 // A lookup texture is generated and pass to shader as sampler
583 DummyControl actor = DummyControl::New(true);
584 TestVisualRender( application, actor, visual, 1u );
586 Stage::GetCurrent().Remove( actor );
587 DALI_TEST_CHECK( actor.GetRendererCount() == 0u );
596 int UtcDaliVisualFactoryGetNPatchVisual1(void)
598 ToolkitTestApplication application;
599 tet_infoline( "UtcDaliVisualFactoryGetNPatchVisual1: Request 9-patch visual with a Property::Map" );
601 VisualFactory factory = VisualFactory::Get();
602 DALI_TEST_CHECK( factory );
604 const unsigned int ninePatchImageHeight = 18;
605 const unsigned int ninePatchImageWidth = 28;
606 StretchRanges stretchRangesX;
607 stretchRangesX.PushBack( Uint16Pair( 2, 3 ) );
608 StretchRanges stretchRangesY;
609 stretchRangesY.PushBack( Uint16Pair( 4, 5 ) );
610 Integration::ResourcePointer ninePatchResource = CustomizeNinePatch( application, ninePatchImageWidth, ninePatchImageHeight, stretchRangesX, stretchRangesY );
612 Property::Map propertyMap;
613 propertyMap.Insert( Visual::Property::TYPE, DevelVisual::N_PATCH );
614 propertyMap.Insert( ImageVisual::Property::URL, TEST_NPATCH_FILE_NAME );
616 tet_infoline( "whole grid" );
617 Visual::Base visual = factory.CreateVisual( propertyMap );
618 DALI_TEST_CHECK( visual );
621 TestGlAbstraction& gl = application.GetGlAbstraction();
622 TraceCallStack& textureTrace = gl.GetTextureTrace();
623 textureTrace.Enable(true);
625 DummyControl actor = DummyControl::New(true);
626 TestVisualRender( application, actor, visual, 1u,
627 ImageDimensions(ninePatchImageWidth, ninePatchImageHeight),
630 DALI_TEST_EQUALS( textureTrace.FindMethod("BindTexture"), true, TEST_LOCATION );
633 propertyMap.Insert( ImageVisual::Property::BORDER_ONLY, true );
635 tet_infoline( "border only" );
636 Visual::Base visual = factory.CreateVisual( propertyMap );
637 DALI_TEST_CHECK( visual );
639 TestGlAbstraction& gl = application.GetGlAbstraction();
640 TraceCallStack& textureTrace = gl.GetTextureTrace();
641 textureTrace.Enable(true);
643 DummyControl actor = DummyControl::New(true);
644 TestVisualRender( application, actor, visual, 1u,
645 ImageDimensions(ninePatchImageWidth, ninePatchImageHeight),
648 DALI_TEST_EQUALS( textureTrace.FindMethod("BindTexture"), true, TEST_LOCATION );
654 int UtcDaliVisualFactoryGetNPatchVisual2(void)
656 ToolkitTestApplication application;
657 tet_infoline( "UtcDaliVisualFactoryGetNPatchVisual1: Request 9-patch visual with a Property::Map including border" );
659 VisualFactory factory = VisualFactory::Get();
660 DALI_TEST_CHECK( factory );
662 Property::Map propertyMap;
663 propertyMap.Insert( Visual::Property::TYPE, DevelVisual::N_PATCH );
664 propertyMap.Insert( ImageVisual::Property::URL, gImage_34_RGBA );
665 propertyMap.Insert( DevelImageVisual::Property::BORDER, Rect< int >( 2, 2, 2, 2 ) );
667 tet_infoline( "whole grid" );
668 Visual::Base visual = factory.CreateVisual( propertyMap );
669 DALI_TEST_CHECK( visual );
671 TestGlAbstraction& gl = application.GetGlAbstraction();
672 TraceCallStack& textureTrace = gl.GetTextureTrace();
673 textureTrace.Enable(true);
675 DummyControl actor = DummyControl::New(true);
676 TestVisualRender( application, actor, visual, 1u );
678 DALI_TEST_EQUALS( textureTrace.FindMethod("BindTexture"), true, TEST_LOCATION );
681 propertyMap.Insert( ImageVisual::Property::BORDER_ONLY, true );
683 tet_infoline( "border only" );
684 Visual::Base visual = factory.CreateVisual( propertyMap );
685 DALI_TEST_CHECK( visual );
687 TestGlAbstraction& gl = application.GetGlAbstraction();
688 TraceCallStack& textureTrace = gl.GetTextureTrace();
689 textureTrace.Enable(true);
691 DummyControl actor = DummyControl::New(true);
692 TestVisualRender( application, actor, visual, 1u );
694 DALI_TEST_EQUALS( textureTrace.FindMethod("BindTexture"), true, TEST_LOCATION );
698 propertyMap.Insert( Visual::Property::TYPE, DevelVisual::N_PATCH );
699 propertyMap.Insert( ImageVisual::Property::URL, gImage_34_RGBA );
700 propertyMap.Insert( DevelImageVisual::Property::BORDER, Rect< int >( 1, 1, 1, 1 ) );
702 tet_infoline( "whole grid" );
703 Visual::Base visual = factory.CreateVisual( propertyMap );
704 DALI_TEST_CHECK( visual );
706 TestGlAbstraction& gl = application.GetGlAbstraction();
707 TraceCallStack& textureTrace = gl.GetTextureTrace();
708 textureTrace.Enable(true);
710 DummyControl actor = DummyControl::New(true);
711 TestVisualRender( application, actor, visual, 1u );
713 DALI_TEST_EQUALS( textureTrace.FindMethod("BindTexture"), true, TEST_LOCATION );
719 int UtcDaliVisualFactoryGetNPatchVisual3(void)
721 ToolkitTestApplication application;
722 tet_infoline( "UtcDaliVisualFactoryGetNPatchVisual2: Request n-patch visual with a Property::Map" );
724 VisualFactory factory = VisualFactory::Get();
725 DALI_TEST_CHECK( factory );
727 const unsigned int ninePatchImageWidth = 18;
728 const unsigned int ninePatchImageHeight = 28;
729 StretchRanges stretchRangesX;
730 stretchRangesX.PushBack( Uint16Pair( 2, 3 ) );
731 stretchRangesX.PushBack( Uint16Pair( 5, 7 ) );
732 stretchRangesX.PushBack( Uint16Pair( 12, 15 ) );
733 StretchRanges stretchRangesY;
734 stretchRangesY.PushBack( Uint16Pair( 4, 5 ) );
735 stretchRangesY.PushBack( Uint16Pair( 8, 12 ) );
736 stretchRangesY.PushBack( Uint16Pair( 15, 16 ) );
737 stretchRangesY.PushBack( Uint16Pair( 25, 27 ) );
738 Integration::ResourcePointer ninePatchResource = CustomizeNinePatch( application, ninePatchImageWidth, ninePatchImageHeight, stretchRangesX, stretchRangesY );
740 Property::Map propertyMap;
741 propertyMap.Insert( Visual::Property::TYPE, DevelVisual::N_PATCH );
742 propertyMap.Insert( ImageVisual::Property::URL, TEST_NPATCH_FILE_NAME );
744 Visual::Base visual = factory.CreateVisual( propertyMap );
745 DALI_TEST_CHECK( visual );
747 TestGlAbstraction& gl = application.GetGlAbstraction();
748 TraceCallStack& textureTrace = gl.GetTextureTrace();
749 textureTrace.Enable(true);
751 DummyControl actor = DummyControl::New(true);
752 TestVisualRender( application, actor, visual, 1u,
753 ImageDimensions(ninePatchImageWidth, ninePatchImageHeight),
756 DALI_TEST_EQUALS( textureTrace.FindMethod("BindTexture"), true, TEST_LOCATION );
758 Stage::GetCurrent().Remove( actor );
759 DALI_TEST_CHECK( actor.GetRendererCount() == 0u );
762 propertyMap.Insert( ImageVisual::Property::BORDER_ONLY, true );
764 tet_infoline( "border only" );
765 Visual::Base visual = factory.CreateVisual( propertyMap );
766 DALI_TEST_CHECK( visual );
768 TestGlAbstraction& gl = application.GetGlAbstraction();
769 TraceCallStack& textureTrace = gl.GetTextureTrace();
770 textureTrace.Enable(true);
771 DummyControl actor = DummyControl::New(true);
772 TestVisualRender( application, actor, visual, 1u,
773 ImageDimensions(ninePatchImageWidth, ninePatchImageHeight),
777 DALI_TEST_EQUALS( textureTrace.FindMethod("BindTexture"), true, TEST_LOCATION );
779 Stage::GetCurrent().Remove( actor );
780 DALI_TEST_CHECK( actor.GetRendererCount() == 0u );
786 int UtcDaliVisualFactoryGetNPatchVisual4(void)
788 ToolkitTestApplication application;
789 tet_infoline( "UtcDaliVisualFactoryGetNPatchVisual3: Request 9-patch visual with an image url" );
791 VisualFactory factory = VisualFactory::Get();
792 DALI_TEST_CHECK( factory );
794 const unsigned int ninePatchImageHeight = 18;
795 const unsigned int ninePatchImageWidth = 28;
796 StretchRanges stretchRangesX;
797 stretchRangesX.PushBack( Uint16Pair( 2, 3 ) );
798 StretchRanges stretchRangesY;
799 stretchRangesY.PushBack( Uint16Pair( 4, 5 ) );
800 Integration::ResourcePointer ninePatchResource = CustomizeNinePatch( application, ninePatchImageWidth, ninePatchImageHeight, stretchRangesX, stretchRangesY );
802 Visual::Base visual = factory.CreateVisual( TEST_NPATCH_FILE_NAME, ImageDimensions() );
803 DALI_TEST_CHECK( visual );
805 TestGlAbstraction& gl = application.GetGlAbstraction();
806 TraceCallStack& textureTrace = gl.GetTextureTrace();
807 textureTrace.Enable(true);
809 DummyControl actor = DummyControl::New(true);
810 TestVisualRender( application, actor, visual, 1u,
811 ImageDimensions(ninePatchImageWidth, ninePatchImageHeight),
814 DALI_TEST_EQUALS( textureTrace.FindMethod("BindTexture"), true, TEST_LOCATION );
817 ResourceImage image = ResourceImage::New(TEST_NPATCH_FILE_NAME);
818 Visual::Base nPatchVisual = factory.CreateVisual( image );
819 Vector2 controlSize( 20.f, 30.f ), naturalSize(0,0);
820 nPatchVisual.SetTransformAndSize(DefaultTransform(), controlSize );
821 nPatchVisual.GetNaturalSize( naturalSize );
822 DALI_TEST_EQUALS( naturalSize, Vector2( ninePatchImageWidth-2, ninePatchImageHeight-2 ), TEST_LOCATION );
827 int UtcDaliVisualFactoryGetNPatchVisual5(void)
829 ToolkitTestApplication application;
830 tet_infoline( "UtcDaliVisualFactoryGetNPatchVisual4: Request n-patch visual with an image url" );
832 VisualFactory factory = VisualFactory::Get();
833 DALI_TEST_CHECK( factory );
835 const unsigned int ninePatchImageHeight = 18;
836 const unsigned int ninePatchImageWidth = 28;
837 StretchRanges stretchRangesX;
838 stretchRangesX.PushBack( Uint16Pair( 2, 3 ) );
839 stretchRangesX.PushBack( Uint16Pair( 5, 7 ) );
840 stretchRangesX.PushBack( Uint16Pair( 12, 15 ) );
841 StretchRanges stretchRangesY;
842 stretchRangesY.PushBack( Uint16Pair( 4, 5 ) );
843 stretchRangesY.PushBack( Uint16Pair( 8, 12 ) );
844 stretchRangesY.PushBack( Uint16Pair( 15, 16 ) );
845 stretchRangesY.PushBack( Uint16Pair( 25, 27 ) );
846 Integration::ResourcePointer ninePatchResource = CustomizeNinePatch( application, ninePatchImageWidth, ninePatchImageHeight, stretchRangesX, stretchRangesY );
848 Visual::Base visual = factory.CreateVisual( TEST_NPATCH_FILE_NAME, ImageDimensions() );
849 DALI_TEST_CHECK( visual );
851 TestGlAbstraction& gl = application.GetGlAbstraction();
852 TraceCallStack& textureTrace = gl.GetTextureTrace();
853 textureTrace.Enable(true);
855 DummyControl actor = DummyControl::New(true);
856 TestVisualRender( application, actor, visual, 1u,
857 ImageDimensions(ninePatchImageWidth, ninePatchImageHeight),
860 DALI_TEST_EQUALS( textureTrace.FindMethod("BindTexture"), true, TEST_LOCATION );
865 int UtcDaliVisualFactoryGetNPatchVisualN1(void)
867 //This should still load but display an error image
869 ToolkitTestApplication application;
870 tet_infoline( "UtcDaliVisualFactoryGetNPatchVisualN: Request n-patch visual with an invalid image url" );
872 VisualFactory factory = VisualFactory::Get();
873 DALI_TEST_CHECK( factory );
875 Visual::Base visual = factory.CreateVisual( "ERROR.9.jpg", ImageDimensions() );
876 DALI_TEST_CHECK( visual );
878 //The testkit still has to load a bitmap for the broken renderer image
879 Integration::Bitmap* bitmap = Integration::Bitmap::New(Integration::Bitmap::BITMAP_2D_PACKED_PIXELS, ResourcePolicy::OWNED_DISCARD);
880 bitmap->GetPackedPixelsProfile()->ReserveBuffer( Pixel::RGBA8888, 100, 100, 100, 100 );
882 TestGlAbstraction& gl = application.GetGlAbstraction();
883 TraceCallStack& textureTrace = gl.GetTextureTrace();
884 textureTrace.Enable(true);
886 DummyControl actor = DummyControl::New(true);
887 TestVisualRender( application, actor, visual, 1u,
889 Integration::ResourcePointer(bitmap) );
891 DALI_TEST_EQUALS( textureTrace.FindMethod("BindTexture"), true, TEST_LOCATION );
896 int UtcDaliVisualFactoryGetNPatchVisualN2(void)
898 //This should still load but display an error image
900 ToolkitTestApplication application;
901 tet_infoline( "UtcDaliVisualFactoryGetNPatchVisualN: Request n-patch visual with an invalid URL" );
903 VisualFactory factory = VisualFactory::Get();
904 DALI_TEST_CHECK( factory );
906 Property::Map propertyMap;
907 propertyMap.Insert( Visual::Property::TYPE, DevelVisual::N_PATCH );
908 propertyMap.Insert( ImageVisual::Property::URL, "ERROR.9.jpg" );
910 Visual::Base visual = factory.CreateVisual( propertyMap );
911 DALI_TEST_CHECK( visual );
913 //The testkit still has to load a bitmap for the broken renderer image
914 Integration::Bitmap* bitmap = Integration::Bitmap::New(Integration::Bitmap::BITMAP_2D_PACKED_PIXELS, ResourcePolicy::OWNED_DISCARD);
915 bitmap->GetPackedPixelsProfile()->ReserveBuffer( Pixel::RGBA8888, 100, 100, 100, 100 );
917 TestGlAbstraction& gl = application.GetGlAbstraction();
918 TraceCallStack& textureTrace = gl.GetTextureTrace();
919 textureTrace.Enable(true);
920 TraceCallStack& drawTrace = gl.GetDrawTrace();
921 drawTrace.Enable(true);
923 DummyControl actor = DummyControl::New(true);
924 TestVisualRender( application, actor, visual, 1u,
926 Integration::ResourcePointer(bitmap) );
928 DALI_TEST_EQUALS( textureTrace.FindMethod("BindTexture"), true, TEST_LOCATION );
933 int UtcDaliVisualFactoryGetNPatchVisualN3(void)
935 // Passing in an invalid visual type so we should not get a visual
937 ToolkitTestApplication application;
938 tet_infoline( "UtcDaliVisualFactoryGetNPatchVisualN: Request n-patch visual with an invalid visual type" );
940 VisualFactory factory = VisualFactory::Get();
941 DALI_TEST_CHECK( factory );
943 Property::Map propertyMap;
944 propertyMap.Insert( Visual::Property::TYPE, 111 );
945 propertyMap.Insert( ImageVisual::Property::URL, "ERROR.9.jpg" );
947 Visual::Base visual = factory.CreateVisual( propertyMap );
948 DALI_TEST_CHECK( !visual );
953 int UtcDaliVisualFactoryGetSvgVisual(void)
955 ToolkitTestApplication application;
956 tet_infoline( "UtcDaliVisualFactoryGetSvgVisual: Request svg visual with a svg url" );
958 VisualFactory factory = VisualFactory::Get();
959 Visual::Base visual = factory.CreateVisual( TEST_SVG_FILE_NAME, ImageDimensions() );
960 DALI_TEST_CHECK( visual );
962 TestGlAbstraction& gl = application.GetGlAbstraction();
963 TraceCallStack& textureTrace = gl.GetTextureTrace();
964 textureTrace.Enable(true);
966 DummyControl actor = DummyControl::New(true);
967 DummyControlImpl& dummyImpl = static_cast<DummyControlImpl&>(actor.GetImplementation());
968 dummyImpl.RegisterVisual( DummyControl::Property::TEST_VISUAL, visual );
969 actor.SetSize( 200.f, 200.f );
970 Stage::GetCurrent().Add( actor );
971 visual.SetTransformAndSize(DefaultTransform(), Vector2(200.f, 200.f) );
973 application.SendNotification();
974 application.Render();
976 // renderer is not added to actor until the rasterization is completed.
977 DALI_TEST_CHECK( actor.GetRendererCount() == 0u );
979 DALI_TEST_EQUALS( Test::WaitForEventThreadTrigger( 1 ), true, TEST_LOCATION );
981 // renderer is added to actor
982 DALI_TEST_CHECK( actor.GetRendererCount() == 1u );
984 // waiting for the resource uploading
985 application.SendNotification();
986 application.Render();
988 DALI_TEST_EQUALS( textureTrace.FindMethod("BindTexture"), true, TEST_LOCATION );
993 int UtcDaliVisualFactoryGetSvgVisualLarge(void)
995 ToolkitTestApplication application;
996 tet_infoline( "UtcDaliVisualFactoryGetSvgVisual: Request svg visual with a svg url" );
998 VisualFactory factory = VisualFactory::Get();
999 Visual::Base visual = factory.CreateVisual( TEST_SVG_FILE_NAME, ImageDimensions( 2000, 2000 ) );
1000 DALI_TEST_CHECK( visual );
1002 TestGlAbstraction& gl = application.GetGlAbstraction();
1003 TraceCallStack& textureTrace = gl.GetTextureTrace();
1004 textureTrace.Enable(true);
1006 DummyControl actor = DummyControl::New(true);
1007 DummyControlImpl& dummyImpl = static_cast<DummyControlImpl&>(actor.GetImplementation());
1008 actor.SetResizePolicy( ResizePolicy::FILL_TO_PARENT, Dimension::ALL_DIMENSIONS ); // Only rasterizes when it knows control size.
1009 dummyImpl.RegisterVisual( DummyControl::Property::TEST_VISUAL, visual );
1010 Stage::GetCurrent().Add( actor );
1012 application.SendNotification();
1013 application.Render();
1015 // renderer is not added to actor until the rasterization is completed.
1016 DALI_TEST_CHECK( actor.GetRendererCount() == 0u );
1018 DALI_TEST_EQUALS( Test::WaitForEventThreadTrigger( 1 ), true, TEST_LOCATION );
1020 // renderer is added to actor
1021 DALI_TEST_CHECK( actor.GetRendererCount() == 1u );
1023 // waiting for the resource uploading
1024 application.SendNotification();
1025 application.Render();
1027 DALI_TEST_EQUALS( textureTrace.FindMethod("BindTexture"), true, TEST_LOCATION );
1032 //Creates a mesh visual from the given propertyMap and tries to load it on stage in the given application.
1033 //This is expected to succeed, which will then pass the test.
1034 void MeshVisualLoadsCorrectlyTest( Property::Map& propertyMap, ToolkitTestApplication& application )
1036 VisualFactory factory = VisualFactory::Get();
1037 DALI_TEST_CHECK( factory );
1039 //Create a mesh visual.
1040 Visual::Base visual = factory.CreateVisual( propertyMap );
1041 DALI_TEST_CHECK( visual );
1043 //Create an actor on stage to house the visual.
1044 DummyControl actor = DummyControl::New(true);
1045 DummyControlImpl& dummyImpl = static_cast<DummyControlImpl&>(actor.GetImplementation());
1046 dummyImpl.RegisterVisual( DummyControl::Property::TEST_VISUAL, visual );
1047 actor.SetSize( 200.f, 200.f );
1048 Stage::GetCurrent().Add( actor );
1049 visual.SetTransformAndSize(DefaultTransform(), Vector2( 200.f, 200.f ) );
1051 //Ensure set on stage.
1052 DALI_TEST_EQUALS( actor.GetRendererCount(), 1u, TEST_LOCATION );
1054 //Attempt to render to queue resource load requests.
1055 application.SendNotification();
1056 application.Render( 0 );
1058 //Render again to upload the now-loaded textures.
1059 application.SendNotification();
1060 application.Render( 0 );
1062 Matrix testScaleMatrix;
1063 testScaleMatrix.SetIdentityAndScale( Vector3( 1.0, -1.0, 1.0 ) );
1064 Matrix actualScaleMatrix;
1066 //Test to see if the object has been successfully loaded.
1067 DALI_TEST_CHECK( application.GetGlAbstraction().GetUniformValue<Matrix>( "uObjectMatrix", actualScaleMatrix ) );
1068 DALI_TEST_EQUALS( actualScaleMatrix, testScaleMatrix, Math::MACHINE_EPSILON_100, TEST_LOCATION );
1070 //Finish by setting off stage, and ensuring this was successful.
1072 DALI_TEST_EQUALS( actor.GetRendererCount(), 0u, TEST_LOCATION );
1075 //Creates a mesh visual from the given propertyMap and tries to load it on stage in the given application.
1076 //This is expected to fail, which will then pass the test.
1077 void MeshVisualDoesNotLoadCorrectlyTest( Property::Map& propertyMap, ToolkitTestApplication& application )
1079 VisualFactory factory = VisualFactory::Get();
1080 DALI_TEST_CHECK( factory );
1082 //Create a mesh visual.
1083 Visual::Base visual = factory.CreateVisual( propertyMap );
1084 DALI_TEST_CHECK( visual );
1086 //Create an actor on stage to house the visual.
1087 DummyControl actor = DummyControl::New(true);
1088 DummyControlImpl& dummyImpl = static_cast<DummyControlImpl&>(actor.GetImplementation());
1089 dummyImpl.RegisterVisual( DummyControl::Property::TEST_VISUAL, visual );
1090 actor.SetSize( 200.f, 200.f );
1091 Stage::GetCurrent().Add( actor );
1092 visual.SetTransformAndSize(DefaultTransform(), Vector2( 200.f, 200.f ) );
1094 //Ensure set on stage.
1095 DALI_TEST_EQUALS( actor.GetRendererCount(), 1u, TEST_LOCATION );
1097 //Attempt to render to queue resource load requests.
1098 application.SendNotification();
1099 application.Render( 0 );
1101 //Render again to upload the now-loaded textures.
1102 application.SendNotification();
1103 application.Render( 0 );
1105 //Test to see if the object has not been loaded, as expected.
1107 DALI_TEST_CHECK( !application.GetGlAbstraction().GetUniformValue<Matrix>( "uObjectMatrix", scaleMatrix ) );
1109 //Finish by setting off stage, and ensuring this was successful.
1111 DALI_TEST_EQUALS( actor.GetRendererCount(), 0u, TEST_LOCATION );
1114 //Test if mesh loads correctly when supplied with only the bare minimum requirements, an object file.
1115 int UtcDaliVisualFactoryGetMeshVisual1(void)
1117 //Set up test application first, so everything else can be handled.
1118 ToolkitTestApplication application;
1120 tet_infoline( "UtcDaliVisualFactoryGetMeshVisual1: Request mesh visual with a valid object file only" );
1123 //Set up visual properties.
1124 Property::Map propertyMap;
1125 propertyMap.Insert( Visual::Property::TYPE, Visual::MESH );
1126 propertyMap.Insert( MeshVisual::Property::OBJECT_URL, TEST_OBJ_FILE_NAME );
1128 //Test to see if mesh loads correctly.
1129 MeshVisualLoadsCorrectlyTest( propertyMap, application );
1135 //Test if mesh loads correctly when supplied with an object file as well as a blank material file and images directory.
1136 int UtcDaliVisualFactoryGetMeshVisual2(void)
1138 //Set up test application first, so everything else can be handled.
1139 ToolkitTestApplication application;
1141 tet_infoline( "UtcDaliVisualFactoryGetMeshVisual2: Request mesh visual with blank material file and images directory" );
1143 //Set up visual properties.
1144 Property::Map propertyMap;
1145 propertyMap.Insert( Visual::Property::TYPE, Visual::MESH );
1146 propertyMap.Insert( MeshVisual::Property::OBJECT_URL, TEST_OBJ_FILE_NAME );
1147 propertyMap.Insert( MeshVisual::Property::MATERIAL_URL, "" );
1148 propertyMap.Insert( MeshVisual::Property::TEXTURES_PATH, "" );
1150 //Test to see if mesh loads correctly.
1151 MeshVisualLoadsCorrectlyTest( propertyMap, application );
1156 //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
1157 int UtcDaliVisualFactoryGetMeshVisual3b(void)
1159 //Set up test application first, so everything else can be handled.
1160 ToolkitTestApplication application;
1162 tet_infoline( "UtcDaliVisualFactoryGetMeshVisual3: Request mesh visual with all parameters correct" );
1164 //Set up visual properties.
1165 Property::Map propertyMap;
1166 propertyMap.Insert( Visual::Property::TYPE, Visual::MESH );
1167 propertyMap.Insert( MeshVisual::Property::OBJECT_URL, TEST_OBJ_FILE_NAME );
1168 propertyMap.Insert( MeshVisual::Property::MATERIAL_URL, TEST_MTL_FILE_NAME );
1169 propertyMap.Insert( MeshVisual::Property::USE_MIPMAPPING, Color::GREEN ); // Test that wrong property types don't prevent the object load
1170 propertyMap.Insert( MeshVisual::Property::USE_SOFT_NORMALS, 1.0f );
1171 propertyMap.Insert( MeshVisual::Property::LIGHT_POSITION, 1.0f );
1172 propertyMap.Insert( MeshVisual::Property::TEXTURES_PATH, TEST_RESOURCE_DIR "/" );
1174 //Test to see if mesh loads correctly.
1175 MeshVisualLoadsCorrectlyTest( propertyMap, application );
1180 //Test if mesh loads correctly when supplied with all main parameters, an object file, a material file and a directory location.
1181 int UtcDaliVisualFactoryGetMeshVisual3(void)
1183 //Set up test application first, so everything else can be handled.
1184 ToolkitTestApplication application;
1186 tet_infoline( "UtcDaliVisualFactoryGetMeshVisual3: Request mesh visual with all parameters correct" );
1188 //Set up visual properties.
1189 Property::Map propertyMap;
1190 propertyMap.Insert( Visual::Property::TYPE, Visual::MESH );
1191 propertyMap.Insert( MeshVisual::Property::OBJECT_URL, TEST_OBJ_FILE_NAME );
1192 propertyMap.Insert( MeshVisual::Property::MATERIAL_URL, TEST_MTL_FILE_NAME );
1193 propertyMap.Insert( MeshVisual::Property::USE_MIPMAPPING, false );
1194 propertyMap.Insert( MeshVisual::Property::USE_SOFT_NORMALS, false );
1195 propertyMap.Insert( MeshVisual::Property::LIGHT_POSITION, Vector3::XAXIS );
1196 propertyMap.Insert( MeshVisual::Property::TEXTURES_PATH, TEST_RESOURCE_DIR "/" );
1198 //Test to see if mesh loads correctly.
1199 MeshVisualLoadsCorrectlyTest( propertyMap, application );
1204 //Test if mesh visual can load a correctly supplied mesh without a normal map or gloss map in the material file.
1205 int UtcDaliVisualFactoryGetMeshVisual4(void)
1207 //Set up test application first, so everything else can be handled.
1208 ToolkitTestApplication application;
1210 tet_infoline( "UtcDaliVisualFactoryGetMeshVisual4: Request mesh visual with diffuse texture but not normal or gloss." );
1213 //Set up visual properties.
1214 Property::Map propertyMap;
1215 propertyMap.Insert( Visual::Property::TYPE, Visual::MESH );
1216 propertyMap.Insert( MeshVisual::Property::OBJECT_URL, TEST_OBJ_FILE_NAME );
1217 propertyMap.Insert( MeshVisual::Property::MATERIAL_URL, TEST_SIMPLE_MTL_FILE_NAME );
1218 propertyMap.Insert( MeshVisual::Property::TEXTURES_PATH, TEST_RESOURCE_DIR "/" );
1220 //Test to see if mesh loads correctly.
1221 MeshVisualLoadsCorrectlyTest( propertyMap, application );
1226 //Test if mesh visual can load when made to use diffuse textures only.
1227 int UtcDaliVisualFactoryGetMeshVisual5(void)
1229 //Set up test application first, so everything else can be handled.
1230 ToolkitTestApplication application;
1232 tet_infoline( "UtcDaliVisualFactoryGetMeshVisual5: Request mesh visual and make it only use diffuse textures." );
1234 //Set up visual properties.
1235 Property::Map propertyMap;
1236 propertyMap.Insert( Visual::Property::TYPE, Visual::MESH );
1237 propertyMap.Insert( "objectUrl", TEST_OBJ_FILE_NAME );
1238 propertyMap.Insert( "materialUrl", TEST_MTL_FILE_NAME );
1239 propertyMap.Insert( "texturesPath", TEST_RESOURCE_DIR "/" );
1240 propertyMap.Insert( "useMipmapping", false );
1241 propertyMap.Insert( "useSoftNormals", false );
1242 propertyMap.Insert( "lightPosition", Vector3::ZAXIS );
1243 propertyMap.Insert( "shadingMode", MeshVisual::ShadingMode::TEXTURED_WITH_SPECULAR_LIGHTING );
1245 //Test to see if mesh loads correctly.
1246 MeshVisualLoadsCorrectlyTest( propertyMap, application );
1252 //Test if mesh visual can load when made to not use the supplied textures.
1253 int UtcDaliVisualFactoryGetMeshVisual6(void)
1255 //Set up test application first, so everything else can be handled.
1256 ToolkitTestApplication application;
1258 tet_infoline( "UtcDaliVisualFactoryGetMeshVisual6: Request mesh visual and make it not use any textures." );
1260 //Set up visual properties.
1261 Property::Map propertyMap;
1262 propertyMap.Insert( Visual::Property::TYPE, Visual::MESH );
1263 propertyMap.Insert( MeshVisual::Property::OBJECT_URL, TEST_OBJ_FILE_NAME );
1264 propertyMap.Insert( MeshVisual::Property::MATERIAL_URL, TEST_MTL_FILE_NAME );
1265 propertyMap.Insert( MeshVisual::Property::TEXTURES_PATH, TEST_RESOURCE_DIR "/" );
1266 propertyMap.Insert( MeshVisual::Property::SHADING_MODE, MeshVisual::ShadingMode::TEXTURELESS_WITH_DIFFUSE_LIGHTING );
1268 //Test to see if mesh loads correctly.
1269 MeshVisualLoadsCorrectlyTest( propertyMap, application );
1273 //Test if mesh visual loads correctly when light position is manually set.
1274 int UtcDaliVisualFactoryGetMeshVisual7(void)
1276 //Set up test application first, so everything else can be handled.
1277 ToolkitTestApplication application;
1280 tet_infoline( "UtcDaliVisualFactoryGetMeshVisual7: Request mesh visual with custom light position." );
1282 //Set up visual properties.
1283 Property::Map propertyMap;
1284 propertyMap.Insert( Visual::Property::TYPE, Visual::MESH );
1285 propertyMap.Insert( MeshVisual::Property::OBJECT_URL, TEST_OBJ_FILE_NAME );
1286 propertyMap.Insert( MeshVisual::Property::MATERIAL_URL, TEST_MTL_FILE_NAME );
1287 propertyMap.Insert( MeshVisual::Property::TEXTURES_PATH, TEST_RESOURCE_DIR "/" );
1288 propertyMap.Insert( MeshVisual::Property::LIGHT_POSITION, Vector3( 0.0, 1.0, 2.0 ) );
1290 //Test to see if mesh loads correctly.
1291 MeshVisualLoadsCorrectlyTest( propertyMap, application );
1296 //Test if mesh visual loads correctly when supplied an object file without face normals or texture points.
1297 //Note that this notably tests object loader functionality.
1298 int UtcDaliVisualFactoryGetMeshVisual8(void)
1300 //Set up test application first, so everything else can be handled.
1301 ToolkitTestApplication application;
1303 tet_infoline( "UtcDaliVisualFactoryGetMeshVisual5: Request mesh visual with normal-less object file." );
1305 //Set up visual properties.
1306 Property::Map propertyMap;
1307 propertyMap.Insert( Visual::Property::TYPE, Visual::MESH );
1308 propertyMap.Insert( MeshVisual::Property::OBJECT_URL, TEST_SIMPLE_OBJ_FILE_NAME );
1309 propertyMap.Insert( MeshVisual::Property::MATERIAL_URL, TEST_MTL_FILE_NAME );
1310 propertyMap.Insert( MeshVisual::Property::TEXTURES_PATH, TEST_RESOURCE_DIR "/" );
1312 //Test to see if mesh loads correctly.
1313 MeshVisualLoadsCorrectlyTest( propertyMap, application );
1318 //Test if mesh visual handles the case of lacking an object file.
1319 int UtcDaliVisualFactoryGetMeshVisualN1(void)
1321 //Set up test application first, so everything else can be handled.
1322 ToolkitTestApplication application;
1324 tet_infoline( "UtcDaliVisualFactoryGetMeshVisualN1: Request mesh visual without object file" );
1326 //Set up visual properties.
1327 Property::Map propertyMap;
1328 propertyMap.Insert( Visual::Property::TYPE, Visual::MESH );
1329 propertyMap.Insert( MeshVisual::Property::MATERIAL_URL, TEST_MTL_FILE_NAME );
1330 propertyMap.Insert( MeshVisual::Property::TEXTURES_PATH, TEST_RESOURCE_DIR "/" );
1332 //Test to see if mesh doesn't load with these properties, as expected.
1333 MeshVisualDoesNotLoadCorrectlyTest( propertyMap, application );
1339 //Test if mesh visual handles the case of being passed invalid material and images urls.
1340 int UtcDaliVisualFactoryGetMeshVisualN2(void)
1342 //Set up test application first, so everything else can be handled.
1343 ToolkitTestApplication application;
1345 tet_infoline( "UtcDaliVisualFactoryGetMeshVisualN2: Request mesh visual with invalid material and images urls" );
1347 //Set up visual properties.
1348 Property::Map propertyMap;
1349 propertyMap.Insert( Visual::Property::TYPE, Visual::MESH );
1350 propertyMap.Insert( MeshVisual::Property::OBJECT_URL, TEST_OBJ_FILE_NAME );
1351 propertyMap.Insert( MeshVisual::Property::MATERIAL_URL, "invalid" );
1352 propertyMap.Insert( MeshVisual::Property::TEXTURES_PATH, "also invalid" );
1354 //Test to see if mesh doesn't load with these properties, as expected.
1355 MeshVisualDoesNotLoadCorrectlyTest( propertyMap, application );
1361 //Test if mesh visual handles the case of being passed an invalid object url
1362 int UtcDaliVisualFactoryGetMeshVisualN3(void)
1364 //Set up test application first, so everything else can be handled.
1365 ToolkitTestApplication application;
1366 tet_infoline( "UtcDaliVisualFactoryGetMeshVisualN3: Request mesh visual with invalid object url" );
1369 //Set up visual properties.
1370 Property::Map propertyMap;
1371 propertyMap.Insert( Visual::Property::TYPE, Visual::MESH );
1372 propertyMap.Insert( MeshVisual::Property::OBJECT_URL, "invalid" );
1373 propertyMap.Insert( MeshVisual::Property::MATERIAL_URL, TEST_MTL_FILE_NAME );
1374 propertyMap.Insert( MeshVisual::Property::TEXTURES_PATH, TEST_RESOURCE_DIR "/" );
1376 //Test to see if mesh doesn't load with these properties, as expected.
1377 MeshVisualDoesNotLoadCorrectlyTest( propertyMap, application );
1382 //Creates a primitive visual with the given property map and tests to see if it correctly loads in the given application.
1383 void TestPrimitiveVisualWithProperties( Property::Map& propertyMap, ToolkitTestApplication& application )
1385 VisualFactory factory = VisualFactory::Get();
1386 DALI_TEST_CHECK( factory );
1388 //Create a primitive visual.
1389 Visual::Base visual = factory.CreateVisual( propertyMap );
1390 DALI_TEST_CHECK( visual );
1392 //Create an actor on stage to house the visual.
1393 DummyControl actor = DummyControl::New(true);
1394 DummyControlImpl& dummyImpl = static_cast<DummyControlImpl&>(actor.GetImplementation());
1395 dummyImpl.RegisterVisual( DummyControl::Property::TEST_VISUAL, visual );
1397 actor.SetSize( 200.f, 200.f );
1398 Stage::GetCurrent().Add( actor );
1399 visual.SetTransformAndSize(DefaultTransform(), Vector2( 200.f, 200.f ) );
1401 //Ensure set on stage.
1402 DALI_TEST_EQUALS( actor.GetRendererCount(), 1u, TEST_LOCATION );
1404 //Tell test application to load the visual.
1405 application.SendNotification();
1406 application.Render(0);
1408 Matrix testScaleMatrix;
1409 testScaleMatrix.SetIdentityAndScale( Vector3( 1.0, -1.0, 1.0 ) );
1410 Matrix actualScaleMatrix;
1412 //Test to see if the object has been successfully loaded.
1413 DALI_TEST_CHECK( application.GetGlAbstraction().GetUniformValue<Matrix>( "uObjectMatrix", actualScaleMatrix ) );
1414 DALI_TEST_EQUALS( actualScaleMatrix, testScaleMatrix, Math::MACHINE_EPSILON_100, TEST_LOCATION );
1416 //Finish by setting off stage, and ensuring this was successful.
1418 DALI_TEST_EQUALS( actor.GetRendererCount(), 0u, TEST_LOCATION );
1421 //Test if primitive shape loads correctly when supplied with only the bare minimum requirements, the shape to use.
1422 int UtcDaliVisualFactoryGetPrimitiveVisual1(void)
1424 //Set up test application first, so everything else can be handled.
1425 ToolkitTestApplication application;
1427 tet_infoline( "UtcDaliVisualFactoryGetPrimitiveVisual1: Request primitive visual with a shape only" );
1429 //Set up visual properties.
1430 Property::Map propertyMap;
1431 propertyMap.Insert( Visual::Property::TYPE, Visual::PRIMITIVE );
1432 propertyMap.Insert( PrimitiveVisual::Property::SHAPE, PrimitiveVisual::Shape::CUBE );
1434 //Test to see if shape loads correctly.
1435 TestPrimitiveVisualWithProperties( propertyMap, application );
1440 //Test if primitive shape loads correctly when supplied with all possible parameters
1441 int UtcDaliVisualFactoryGetPrimitiveVisual2(void)
1443 //Set up test application first, so everything else can be handled.
1444 ToolkitTestApplication application;
1446 tet_infoline( "UtcDaliVisualFactoryGetPrimitiveVisual2: Request primitive visual with everything" );
1448 //Set up visual properties.
1449 Property::Map propertyMap;
1450 propertyMap.Insert( Visual::Property::TYPE, Visual::PRIMITIVE );
1451 propertyMap.Insert( PrimitiveVisual::Property::SHAPE, PrimitiveVisual::Shape::CUBE );
1452 propertyMap.Insert( PrimitiveVisual::Property::MIX_COLOR, Vector4( 0.5, 0.5, 0.5, 1.0 ) );
1453 propertyMap.Insert( PrimitiveVisual::Property::SLICES, 10 );
1454 propertyMap.Insert( PrimitiveVisual::Property::STACKS, 20 );
1455 propertyMap.Insert( PrimitiveVisual::Property::SCALE_TOP_RADIUS, 30.0f );
1456 propertyMap.Insert( PrimitiveVisual::Property::SCALE_BOTTOM_RADIUS, 40.0f );
1457 propertyMap.Insert( PrimitiveVisual::Property::SCALE_HEIGHT, 50.0f );
1458 propertyMap.Insert( PrimitiveVisual::Property::SCALE_RADIUS, 60.0f );
1459 propertyMap.Insert( PrimitiveVisual::Property::BEVEL_PERCENTAGE, 0.7f );
1460 propertyMap.Insert( PrimitiveVisual::Property::BEVEL_SMOOTHNESS, 0.8f );
1461 propertyMap.Insert( MeshVisual::Property::LIGHT_POSITION, Vector3( 0.9, 1.0, 1.1 ) );
1463 //Test to see if shape loads correctly.
1464 TestPrimitiveVisualWithProperties( propertyMap, application );
1469 //Test if primitive shape loads a sphere correctly.
1470 int UtcDaliVisualFactoryGetPrimitiveVisual3(void)
1472 //Set up test application first, so everything else can be handled.
1473 ToolkitTestApplication application;
1475 tet_infoline( "UtcDaliVisualFactoryGetPrimitiveVisual3: Request primitive visual to display a sphere" );
1477 //Set up visual properties.
1478 Property::Map propertyMap;
1479 propertyMap.Insert( Visual::Property::TYPE, Visual::PRIMITIVE );
1480 propertyMap.Insert( PrimitiveVisual::Property::SHAPE, PrimitiveVisual::Shape::SPHERE );
1481 propertyMap.Insert( PrimitiveVisual::Property::MIX_COLOR, Vector4( 0.5, 0.5, 0.5, 1.0 ) );
1482 propertyMap.Insert( PrimitiveVisual::Property::SLICES, 10 );
1483 propertyMap.Insert( PrimitiveVisual::Property::STACKS, 20 );
1485 //Test to see if shape loads correctly.
1486 TestPrimitiveVisualWithProperties( propertyMap, application );
1491 //Test if primitive shape loads a conic section correctly.
1492 int UtcDaliVisualFactoryGetPrimitiveVisual4(void)
1494 //Set up test application first, so everything else can be handled.
1495 ToolkitTestApplication application;
1497 tet_infoline( "UtcDaliVisualFactoryGetPrimitiveVisual4: Request primitive visual to display a conic section" );
1499 //Set up visual properties.
1500 Property::Map propertyMap;
1501 propertyMap.Insert( Visual::Property::TYPE, Visual::PRIMITIVE );
1502 propertyMap.Insert( PrimitiveVisual::Property::SHAPE, PrimitiveVisual::Shape::CONICAL_FRUSTRUM );
1503 propertyMap.Insert( PrimitiveVisual::Property::MIX_COLOR, Vector4( 0.5, 0.5, 0.5, 1.0 ) );
1504 propertyMap.Insert( PrimitiveVisual::Property::SLICES, 10 );
1505 propertyMap.Insert( PrimitiveVisual::Property::SCALE_TOP_RADIUS, 30.0f );
1506 propertyMap.Insert( PrimitiveVisual::Property::SCALE_BOTTOM_RADIUS, 40.0f );
1507 propertyMap.Insert( PrimitiveVisual::Property::SCALE_HEIGHT, 50.0f );
1509 //Test to see if shape loads correctly.
1510 TestPrimitiveVisualWithProperties( propertyMap, application );
1515 //Test if primitive shape loads a bevelled cube correctly.
1516 int UtcDaliVisualFactoryGetPrimitiveVisual5(void)
1518 //Set up test application first, so everything else can be handled.
1519 ToolkitTestApplication application;
1521 tet_infoline( "UtcDaliVisualFactoryGetPrimitiveVisual5: Request primitive visual to display a bevelled cube" );
1523 //Set up visual properties.
1524 Property::Map propertyMap;
1525 propertyMap.Insert( Visual::Property::TYPE, Visual::PRIMITIVE );
1526 propertyMap.Insert( PrimitiveVisual::Property::SHAPE, PrimitiveVisual::Shape::BEVELLED_CUBE );
1527 propertyMap.Insert( PrimitiveVisual::Property::MIX_COLOR, Vector4( 0.5, 0.5, 0.5, 1.0 ) );
1528 propertyMap.Insert( PrimitiveVisual::Property::BEVEL_PERCENTAGE, 0.7f );
1530 //Test to see if shape loads correctly.
1531 TestPrimitiveVisualWithProperties( propertyMap, application );
1536 //Test if primitive shape loads an octahedron correctly.
1537 int UtcDaliVisualFactoryGetPrimitiveVisual6(void)
1539 //Set up test application first, so everything else can be handled.
1540 ToolkitTestApplication application;
1542 tet_infoline( "UtcDaliVisualFactoryGetPrimitiveVisual6: Request primitive visual to display an octahedron" );
1544 //Set up visual properties.
1545 Property::Map propertyMap;
1546 propertyMap.Insert( Visual::Property::TYPE, Visual::PRIMITIVE );
1547 propertyMap.Insert( PrimitiveVisual::Property::SHAPE, PrimitiveVisual::Shape::OCTAHEDRON );
1548 propertyMap.Insert( PrimitiveVisual::Property::MIX_COLOR, Vector4( 0.5, 0.5, 0.5, 1.0 ) );
1550 //Test to see if shape loads correctly.
1551 TestPrimitiveVisualWithProperties( propertyMap, application );
1556 //Test if primitive shape loads a cone correctly.
1557 int UtcDaliVisualFactoryGetPrimitiveVisual7(void)
1559 //Set up test application first, so everything else can be handled.
1560 ToolkitTestApplication application;
1562 tet_infoline( "UtcDaliVisualFactoryGetPrimitiveVisual7: Request primitive visual to display a cone" );
1564 //Set up visual properties.
1565 Property::Map propertyMap;
1566 propertyMap.Insert( Visual::Property::TYPE, Visual::PRIMITIVE );
1567 propertyMap.Insert( PrimitiveVisual::Property::SHAPE, PrimitiveVisual::Shape::CONE );
1568 propertyMap.Insert( PrimitiveVisual::Property::MIX_COLOR, Vector4( 0.5, 0.5, 0.5, 1.0 ) );
1569 propertyMap.Insert( PrimitiveVisual::Property::SLICES, 10 );
1570 propertyMap.Insert( PrimitiveVisual::Property::SCALE_TOP_RADIUS, 30.0f );
1571 propertyMap.Insert( PrimitiveVisual::Property::SCALE_HEIGHT, 50.0f );
1573 //Test to see if shape loads correctly.
1574 TestPrimitiveVisualWithProperties( propertyMap, application );
1579 //Test if primitive shape loads correctly when light position is manually set.
1580 int UtcDaliVisualFactoryGetPrimitiveVisual8(void)
1582 //Set up test application first, so everything else can be handled.
1583 ToolkitTestApplication application;
1585 tet_infoline( "UtcDaliVisualFactoryGetPrimitiveVisual8: Request primitive visual with set light position" );
1587 //Set up visual properties.
1588 Property::Map propertyMap;
1589 propertyMap.Insert( Visual::Property::TYPE, Visual::PRIMITIVE );
1590 propertyMap.Insert( PrimitiveVisual::Property::SHAPE, PrimitiveVisual::Shape::SPHERE );
1591 propertyMap.Insert( PrimitiveVisual::Property::MIX_COLOR, Vector4( 0.5, 0.5, 0.5, 1.0 ) );
1592 propertyMap.Insert( MeshVisual::Property::LIGHT_POSITION, Vector3( 0.0, 1.0, 2.0 ) );
1594 //Test to see if shape loads correctly.
1595 TestPrimitiveVisualWithProperties( propertyMap, application );
1600 //Test if primitive shape loads correctly when told to use too many slices.
1601 int UtcDaliVisualFactoryGetPrimitiveVisual9(void)
1603 //Set up test application first, so everything else can be handled.
1604 ToolkitTestApplication application;
1606 tet_infoline( "UtcDaliVisualFactoryGetPrimitiveVisual9: Request primitive visual with above-cap slices." );
1608 //Set up visual properties.
1609 Property::Map propertyMap;
1610 propertyMap.Insert( Visual::Property::TYPE, Visual::PRIMITIVE );
1611 propertyMap.Insert( PrimitiveVisual::Property::SHAPE, PrimitiveVisual::Shape::SPHERE );
1612 propertyMap.Insert( PrimitiveVisual::Property::SLICES, Property::Value( 1000000 ) );
1614 //Test to see if shape loads correctly.
1615 TestPrimitiveVisualWithProperties( propertyMap, application );
1620 //Test if primitive shape loads correctly when told to use too few slices. (2 slices or less.)
1621 int UtcDaliVisualFactoryGetPrimitiveVisual10(void)
1623 //Set up test application first, so everything else can be handled.
1624 ToolkitTestApplication application;
1626 tet_infoline( "UtcDaliVisualFactoryGetPrimitiveVisual10: Request primitive visual with too few slices." );
1628 //Set up visual properties.
1629 Property::Map propertyMap;
1630 propertyMap.Insert( Visual::Property::TYPE, Visual::PRIMITIVE );
1631 propertyMap.Insert( PrimitiveVisual::Property::SHAPE, PrimitiveVisual::Shape::SPHERE );
1632 propertyMap.Insert( PrimitiveVisual::Property::SLICES, Property::Value( 2 ) );
1634 //Test to see if shape loads correctly.
1635 TestPrimitiveVisualWithProperties( propertyMap, application );
1640 //Test if primitive shape loads correctly when told to use too many stacks.
1641 int UtcDaliVisualFactoryGetPrimitiveVisual11(void)
1643 //Set up test application first, so everything else can be handled.
1644 ToolkitTestApplication application;
1646 tet_infoline( "UtcDaliVisualFactoryGetPrimitiveVisual11: Request primitive visual with too many stacks." );
1648 //Set up visual properties.
1649 Property::Map propertyMap;
1650 propertyMap.Insert( Visual::Property::TYPE, Visual::PRIMITIVE );
1651 propertyMap.Insert( PrimitiveVisual::Property::SHAPE, PrimitiveVisual::Shape::SPHERE );
1652 propertyMap.Insert( PrimitiveVisual::Property::STACKS, Property::Value( 1000000 ) );
1654 //Test to see if shape loads correctly.
1655 TestPrimitiveVisualWithProperties( propertyMap, application );
1660 //Test if primitive shape loads correctly when told to use too few stacks. (1 stack or less.)
1661 int UtcDaliVisualFactoryGetPrimitiveVisual12(void)
1663 //Set up test application first, so everything else can be handled.
1664 ToolkitTestApplication application;
1666 tet_infoline( "UtcDaliVisualFactoryGetPrimitiveVisual12: Request primitive visual with too few stacks." );
1668 //Set up visual properties.
1669 Property::Map propertyMap;
1670 propertyMap.Insert( Visual::Property::TYPE, Visual::PRIMITIVE );
1671 propertyMap.Insert( PrimitiveVisual::Property::SHAPE, PrimitiveVisual::Shape::SPHERE );
1672 propertyMap.Insert( PrimitiveVisual::Property::STACKS, Property::Value( 1 ) );
1674 //Test to see if shape loads correctly.
1675 TestPrimitiveVisualWithProperties( propertyMap, application );
1680 //Test if primitive shape loads correctly when told to use invalid (zero or negative) dimensions.
1681 int UtcDaliVisualFactoryGetPrimitiveVisual13(void)
1683 //Set up test application first, so everything else can be handled.
1684 ToolkitTestApplication application;
1686 tet_infoline( "UtcDaliVisualFactoryGetPrimitiveVisual13: Request primitive visual with invalid scale dimensions." );
1688 //Set up visual properties.
1689 Property::Map propertyMap;
1690 propertyMap.Insert( Visual::Property::TYPE, Visual::PRIMITIVE );
1691 propertyMap.Insert( PrimitiveVisual::Property::SHAPE, PrimitiveVisual::Shape::SPHERE );
1692 propertyMap.Insert( PrimitiveVisual::Property::SCALE_DIMENSIONS, Vector3::ZERO );
1694 //Test to see if shape loads correctly.
1695 TestPrimitiveVisualWithProperties( propertyMap, application );
1700 //Test if primitive shape loads correctly when told to use too low a bevel percentage.
1701 int UtcDaliVisualFactoryGetPrimitiveVisual14(void)
1703 //Set up test application first, so everything else can be handled.
1704 ToolkitTestApplication application;
1706 tet_infoline( "UtcDaliVisualFactoryGetPrimitiveVisual14: Request primitive visual with too low a bevel percentage." );
1708 //Set up visual properties.
1709 Property::Map propertyMap;
1710 propertyMap.Insert( Visual::Property::TYPE, Visual::PRIMITIVE );
1711 propertyMap.Insert( PrimitiveVisual::Property::SHAPE, PrimitiveVisual::Shape::SPHERE );
1712 propertyMap.Insert( PrimitiveVisual::Property::BEVEL_PERCENTAGE, Property::Value( -1.0f ) );
1714 //Test to see if shape loads correctly.
1715 TestPrimitiveVisualWithProperties( propertyMap, application );
1720 //Test if primitive shape loads correctly when told to use too high a bevel percentage.
1721 int UtcDaliVisualFactoryGetPrimitiveVisual15(void)
1723 //Set up test application first, so everything else can be handled.
1724 ToolkitTestApplication application;
1726 tet_infoline( "UtcDaliVisualFactoryGetPrimitiveVisual15: Request primitive visual with too high a bevel percentage." );
1728 //Set up visual properties.
1729 Property::Map propertyMap;
1730 propertyMap.Insert( Visual::Property::TYPE, Visual::PRIMITIVE );
1731 propertyMap.Insert( PrimitiveVisual::Property::SHAPE, PrimitiveVisual::Shape::SPHERE );
1732 propertyMap.Insert( PrimitiveVisual::Property::BEVEL_PERCENTAGE, Property::Value( 2.0f ) );
1734 //Test to see if shape loads correctly.
1735 TestPrimitiveVisualWithProperties( propertyMap, application );
1740 //Test if primitive shape loads correctly when told to use too low a bevel smoothness.
1741 int UtcDaliVisualFactoryGetPrimitiveVisual16(void)
1743 //Set up test application first, so everything else can be handled.
1744 ToolkitTestApplication application;
1746 tet_infoline( "UtcDaliVisualFactoryGetPrimitiveVisual16: Request primitive visual with too low a bevel smoothness." );
1748 //Set up visual properties.
1749 Property::Map propertyMap;
1750 propertyMap.Insert( Visual::Property::TYPE, Visual::PRIMITIVE );
1751 propertyMap.Insert( PrimitiveVisual::Property::SHAPE, PrimitiveVisual::Shape::SPHERE );
1752 propertyMap.Insert( PrimitiveVisual::Property::BEVEL_SMOOTHNESS, Property::Value( -1.0f ) );
1754 //Test to see if shape loads correctly.
1755 TestPrimitiveVisualWithProperties( propertyMap, application );
1760 //Test if primitive shape loads correctly when told to use too high a bevel smoothness.
1761 int UtcDaliVisualFactoryGetPrimitiveVisual17(void)
1763 //Set up test application first, so everything else can be handled.
1764 ToolkitTestApplication application;
1766 tet_infoline( "UtcDaliVisualFactoryGetPrimitiveVisual17: Request primitive visual with too high a bevel smoothness." );
1768 //Set up visual properties.
1769 Property::Map propertyMap;
1770 propertyMap.Insert( Visual::Property::TYPE, Visual::PRIMITIVE );
1771 propertyMap.Insert( PrimitiveVisual::Property::SHAPE, PrimitiveVisual::Shape::SPHERE );
1772 propertyMap.Insert( PrimitiveVisual::Property::BEVEL_SMOOTHNESS, Property::Value( 2.0f ) );
1774 //Test to see if shape loads correctly.
1775 TestPrimitiveVisualWithProperties( propertyMap, application );
1780 //Test if primitive shape visual handles the case of not being passed a specific shape to use.
1781 int UtcDaliVisualFactoryGetPrimitiveVisualN1(void)
1783 //Set up test application first, so everything else can be handled.
1784 ToolkitTestApplication application;
1786 tet_infoline( "UtcDaliVisualFactoryGetPrimitiveVisualN1: Request primitive visual without shape" );
1788 //Set up visual properties, without supplying shape.
1789 Property::Map propertyMap;
1790 propertyMap.Insert( Visual::Property::TYPE, Visual::PRIMITIVE );
1792 //Test to see if shape loads regardless of missing input.
1793 TestPrimitiveVisualWithProperties( propertyMap, application );
1798 int UtcDaliVisualFactoryGetAnimatedImageVisual1(void)
1800 ToolkitTestApplication application;
1801 tet_infoline( "UtcDaliVisualFactoryGetAnimatedImageVisual1: Request animated image visual with a gif url" );
1803 VisualFactory factory = VisualFactory::Get();
1804 Visual::Base visual = factory.CreateVisual( TEST_GIF_FILE_NAME, ImageDimensions() );
1805 DALI_TEST_CHECK( visual );
1807 TestGlAbstraction& gl = application.GetGlAbstraction();
1808 TraceCallStack& textureTrace = gl.GetTextureTrace();
1809 textureTrace.Enable(true);
1811 DummyControl actor = DummyControl::New(true);
1812 DummyControlImpl& dummyImpl = static_cast<DummyControlImpl&>(actor.GetImplementation());
1813 dummyImpl.RegisterVisual( DummyControl::Property::TEST_VISUAL, visual );
1814 actor.SetSize( 200.0f, 200.0f );
1815 Stage::GetCurrent().Add( actor );
1817 application.SendNotification();
1818 application.Render();
1820 // renderer is added to actor
1821 DALI_TEST_CHECK( actor.GetRendererCount() == 1u );
1823 // test the uniforms which used to handle the atlas rect
1824 // the four frames should be located inside atlas as follows: atlas size 100*100
1833 Renderer renderer = actor.GetRendererAt( 0u );
1834 DALI_TEST_CHECK( renderer );
1836 Property::Value atlasRectValue = renderer.GetProperty( renderer.GetPropertyIndex( "uAtlasRect" ) );
1837 // take into consideration the half pixel correction
1838 DALI_TEST_EQUALS( atlasRectValue.Get<Vector4>(), Vector4(0.5f, 0.5f, 49.5f, 49.5f)/100.f, Math::MACHINE_EPSILON_100, TEST_LOCATION );
1840 // waiting for the resource uploading
1841 application.SendNotification();
1842 application.Render();
1844 DALI_TEST_EQUALS( textureTrace.FindMethod("BindTexture"), true, TEST_LOCATION );
1846 // Force the timer used by the animatedImageVisual to tick,
1847 Dali::Timer timer = Timer::New( 0 );
1848 timer.MockEmitSignal();
1849 application.SendNotification();
1850 application.Render();
1851 atlasRectValue = renderer.GetProperty( renderer.GetPropertyIndex( "uAtlasRect" ) );
1852 // take into consideration the half pixel correction
1853 DALI_TEST_EQUALS( atlasRectValue.Get<Vector4>(), Vector4(50.5f, 0.5f, 99.5f, 49.5f)/100.f, Math::MACHINE_EPSILON_100, TEST_LOCATION );
1855 // Force the timer used by the animatedImageVisual to tick,
1856 timer.MockEmitSignal();
1857 application.SendNotification();
1858 application.Render();
1859 atlasRectValue = renderer.GetProperty( renderer.GetPropertyIndex( "uAtlasRect" ) );
1860 // take into consideration the half pixel correction
1861 DALI_TEST_EQUALS( atlasRectValue.Get<Vector4>(), Vector4(0.5f, 50.5f, 49.5f, 99.5f)/100.f, Math::MACHINE_EPSILON_100, TEST_LOCATION );
1863 // Force the timer used by the animatedImageVisual to tick,
1864 timer.MockEmitSignal();
1865 application.SendNotification();
1866 application.Render();
1867 atlasRectValue = renderer.GetProperty( renderer.GetPropertyIndex( "uAtlasRect" ) );
1868 // take into consideration the half pixel correction
1869 DALI_TEST_EQUALS( atlasRectValue.Get<Vector4>(), Vector4(50.5f, 50.5f, 99.5f, 99.5f)/100.f, Math::MACHINE_EPSILON_100, TEST_LOCATION );
1871 // Test SetOffStage().
1873 DALI_TEST_CHECK( actor.GetRendererCount() == 0u );
1878 int UtcDaliVisualFactoryGetAnimatedImageVisual2(void)
1880 ToolkitTestApplication application;
1881 tet_infoline( "UtcDaliVisualFactoryGetAnimatedImageVisual2: Request animated image visual with a Property::Map, test custom wrap mode and pixel area" );
1883 const Vector4 pixelArea(-0.5f, -0.5f, 2.f, 2.f);
1884 Property::Map propertyMap;
1885 propertyMap.Add( Visual::Property::TYPE, Visual::IMAGE )
1886 .Add( ImageVisual::Property::URL, TEST_GIF_FILE_NAME )
1887 .Add( ImageVisual::Property::PIXEL_AREA, pixelArea )
1888 .Add( ImageVisual::Property::WRAP_MODE_U, WrapMode::MIRRORED_REPEAT )
1889 .Add( ImageVisual::Property::WRAP_MODE_V, WrapMode::REPEAT );
1891 Visual::Base visual = VisualFactory::Get().CreateVisual( propertyMap );
1892 DALI_TEST_CHECK( visual );
1894 TestGlAbstraction& gl = application.GetGlAbstraction();
1895 TraceCallStack& textureTrace = gl.GetTextureTrace();
1896 textureTrace.Enable(true);
1897 TraceCallStack& texParameterTrace = gl.GetTexParameterTrace();
1898 texParameterTrace.Enable( true );
1900 DummyControl actor = DummyControl::New(true);
1901 DummyControlImpl& dummyImpl = static_cast<DummyControlImpl&>(actor.GetImplementation());
1902 dummyImpl.RegisterVisual( Control::CONTROL_PROPERTY_END_INDEX + 1, visual );
1903 actor.SetSize( 200.0f, 200.0f );
1904 Stage::GetCurrent().Add( actor );
1906 application.SendNotification();
1907 application.Render();
1909 DALI_TEST_CHECK( actor.GetRendererCount() == 1u );
1911 DALI_TEST_EQUALS( textureTrace.FindMethod("BindTexture"), true, TEST_LOCATION );
1913 // For animated image visual, the wrapping is handled manually in shader, so the following gl function should not be called
1914 std::stringstream out;
1915 out << GL_TEXTURE_2D << ", " << GL_TEXTURE_WRAP_S << ", " << GL_MIRRORED_REPEAT;
1916 DALI_TEST_CHECK( !texParameterTrace.FindMethodAndParams("TexParameteri", out.str()) );
1918 out << GL_TEXTURE_2D << ", " << GL_TEXTURE_WRAP_T << ", " << GL_REPEAT;
1919 DALI_TEST_CHECK( !texParameterTrace.FindMethodAndParams("TexParameteri", out.str()) );
1921 // test the uniforms which used to handle the wrap mode
1922 Renderer renderer = actor.GetRendererAt( 0u );
1923 DALI_TEST_CHECK( renderer );
1925 Property::Value pixelAreaValue = renderer.GetProperty( renderer.GetPropertyIndex( "pixelArea" ) );
1926 DALI_TEST_EQUALS( pixelAreaValue.Get<Vector4>(), pixelArea, TEST_LOCATION );
1927 Vector4 pixelAreaUniform;
1928 DALI_TEST_CHECK( gl.GetUniformValue<Vector4>( "pixelArea", pixelAreaUniform ) );
1929 DALI_TEST_EQUALS( pixelArea, pixelAreaUniform, Math::MACHINE_EPSILON_100, TEST_LOCATION );
1931 Property::Value wrapModeValue = renderer.GetProperty( renderer.GetPropertyIndex( "wrapMode" ) );
1932 Vector2 wrapMode( WrapMode::MIRRORED_REPEAT-1, WrapMode::REPEAT-1 );
1933 DALI_TEST_EQUALS( wrapModeValue.Get<Vector2>(), wrapMode, TEST_LOCATION );
1934 Vector2 wrapModeUniform;
1935 DALI_TEST_CHECK( gl.GetUniformValue<Vector2>( "wrapMode", wrapModeUniform ) );
1936 DALI_TEST_EQUALS( wrapMode, wrapModeUniform, Math::MACHINE_EPSILON_100, TEST_LOCATION );
1939 DALI_TEST_CHECK( actor.GetRendererCount() == 0u );