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/devel-api/images/nine-patch-image.h>
23 #include <dali-toolkit/devel-api/visual-factory/visual-factory.h>
24 #include <dali-toolkit/dali-toolkit.h>
25 #include "dummy-control.h"
28 using namespace Dali::Toolkit;
32 typedef NinePatchImage::StretchRanges StretchRanges;
34 const char* TEST_NPATCH_FILE_NAME = TEST_RESOURCE_DIR "/button-up-1.9.png";
35 const char* TEST_SVG_FILE_NAME = TEST_RESOURCE_DIR "/svg1.svg";
36 const char* TEST_OBJ_FILE_NAME = TEST_RESOURCE_DIR "/Cube.obj";
37 const char* TEST_MTL_FILE_NAME = TEST_RESOURCE_DIR "/ToyRobot-Metal.mtl";
38 const char* TEST_SIMPLE_OBJ_FILE_NAME = TEST_RESOURCE_DIR "/Cube-Points-Only.obj";
39 const char* TEST_SIMPLE_MTL_FILE_NAME = TEST_RESOURCE_DIR "/ToyRobot-Metal-Simple.mtl";
41 // resolution: 50*50, frame count: 4, frame delay: 0.2 second for each frame
42 const char* TEST_GIF_FILE_NAME = TEST_RESOURCE_DIR "/anim.gif";
44 // resolution: 34*34, pixel format: RGBA8888
45 static const char* gImage_34_RGBA = TEST_RESOURCE_DIR "/icon-edit.png";
48 Property::Map DefaultTransform()
50 Property::Map transformMap;
52 .Add( Toolkit::Visual::Transform::Property::OFFSET, Vector2(0.0f, 0.0f) )
53 .Add( Toolkit::Visual::Transform::Property::SIZE, Vector2(1.0f, 1.0f) )
54 .Add( Toolkit::Visual::Transform::Property::ORIGIN, Toolkit::Align::CENTER )
55 .Add( Toolkit::Visual::Transform::Property::ANCHOR_POINT, Toolkit::Align::CENTER )
56 .Add( Toolkit::Visual::Transform::Property::OFFSET_POLICY, Vector2( Toolkit::Visual::Transform::Policy::RELATIVE, Toolkit::Visual::Transform::Policy::RELATIVE ) )
57 .Add( Toolkit::Visual::Transform::Property::SIZE_POLICY, Vector2( Toolkit::Visual::Transform::Policy::RELATIVE, Toolkit::Visual::Transform::Policy::RELATIVE ) );
61 Integration::Bitmap* CreateBitmap( unsigned int imageWidth, unsigned int imageHeight, unsigned int initialColor, Pixel::Format pixelFormat )
63 Integration::Bitmap* bitmap = Integration::Bitmap::New( Integration::Bitmap::BITMAP_2D_PACKED_PIXELS, ResourcePolicy::OWNED_RETAIN );
64 Integration::PixelBuffer* pixbuffer = bitmap->GetPackedPixelsProfile()->ReserveBuffer( pixelFormat, imageWidth, imageHeight, imageWidth, imageHeight );
65 unsigned int bytesPerPixel = GetBytesPerPixel( pixelFormat );
67 memset( pixbuffer, initialColor, imageHeight * imageWidth * bytesPerPixel );
72 void InitialiseRegionsToZeroAlpha( Integration::Bitmap* image, unsigned int imageWidth, unsigned int imageHeight, Pixel::Format pixelFormat )
74 PixelBuffer* pixbuffer = image->GetBuffer();
75 unsigned int bytesPerPixel = GetBytesPerPixel( pixelFormat );
77 for( unsigned int row = 0; row < imageWidth; ++row )
79 unsigned int pixelOffset = row * bytesPerPixel;
80 pixbuffer[ pixelOffset + 3 ] = 0x00;
81 pixelOffset += ( imageHeight - 1 ) * imageWidth * bytesPerPixel;
82 pixbuffer[ pixelOffset + 3 ] = 0x00;
85 for ( unsigned int column = 0; column < imageHeight; ++column )
87 unsigned int pixelOffset = column * imageWidth * bytesPerPixel;
88 pixbuffer[ pixelOffset + 3 ] = 0x00;
89 pixelOffset += ( imageWidth -1 ) * bytesPerPixel;
90 pixbuffer[ pixelOffset + 3 ] = 0x00;
94 void AddStretchRegionsToImage( Integration::Bitmap* image, unsigned int imageWidth, unsigned int imageHeight, const StretchRanges& stretchRangesX, const StretchRanges& stretchRangesY, Pixel::Format pixelFormat )
96 PixelBuffer* pixbuffer = image->GetBuffer();
97 unsigned int bytesPerPixel = GetBytesPerPixel( pixelFormat );
99 for(StretchRanges::ConstIterator it = stretchRangesX.Begin(); it != stretchRangesX.End(); ++it)
101 const Uint16Pair& range = *it;
102 //since the stretch range is in the cropped image space, we need to offset by 1 to get it to the uncropped image space
103 for( unsigned int column = range.GetX() + 1u; column < range.GetY() + 1u; ++column )
105 unsigned int pixelOffset = column * bytesPerPixel;
106 pixbuffer[ pixelOffset ] = 0x00;
107 pixbuffer[ pixelOffset + 1 ] = 0x00;
108 pixbuffer[ pixelOffset + 2 ] = 0x00;
109 pixbuffer[ pixelOffset + 3 ] = 0xFF;
114 for(StretchRanges::ConstIterator it = stretchRangesY.Begin(); it != stretchRangesY.End(); ++it)
116 const Uint16Pair& range = *it;
117 //since the stretch range is in the cropped image space, we need to offset by 1 to get it to the uncropped image space
118 for( unsigned int row = range.GetX() + 1u; row < range.GetY() + 1u; ++row )
120 unsigned int pixelOffset = row * imageWidth * bytesPerPixel;
121 pixbuffer[ pixelOffset ] = 0x00;
122 pixbuffer[ pixelOffset + 1 ] = 0x00;
123 pixbuffer[ pixelOffset + 2 ] = 0x00;
124 pixbuffer[ pixelOffset + 3 ] = 0xFF;
129 void AddChildRegionsToImage( Integration::Bitmap* image, unsigned int imageWidth, unsigned int imageHeight, const Vector4& requiredChildRegion, Pixel::Format pixelFormat )
131 PixelBuffer* pixbuffer = image->GetBuffer();
132 unsigned int bytesPerPixel = GetBytesPerPixel( pixelFormat );
134 Integration::Bitmap::PackedPixelsProfile* srcProfile = image->GetPackedPixelsProfile();
135 unsigned int bufferStride = srcProfile->GetBufferStride();
137 // Add bottom child region
138 for( unsigned int column = requiredChildRegion.x; column < imageWidth - requiredChildRegion.z; ++column )
140 unsigned int pixelOffset = column * bytesPerPixel;
141 pixelOffset += ( imageHeight - 1 ) * bufferStride;
142 pixbuffer[ pixelOffset ] = 0x00;
143 pixbuffer[ pixelOffset + 1 ] = 0x00;
144 pixbuffer[ pixelOffset + 2 ] = 0x00;
145 pixbuffer[ pixelOffset + 3 ] = 0xFF;
148 // Add right child region
149 for ( unsigned int row = requiredChildRegion.y; row < imageHeight - requiredChildRegion.w; ++row )
151 unsigned int pixelOffset = row * bufferStride + ( imageWidth - 1 ) * bytesPerPixel;
152 pixbuffer[ pixelOffset ] = 0x00;
153 pixbuffer[ pixelOffset + 1 ] = 0x00;
154 pixbuffer[ pixelOffset + 2 ] = 0x00;
155 pixbuffer[ pixelOffset + 3 ] = 0xFF;
159 Integration::ResourcePointer CustomizeNinePatch( TestApplication& application,
160 unsigned int ninePatchImageWidth,
161 unsigned int ninePatchImageHeight,
162 const StretchRanges& stretchRangesX,
163 const StretchRanges& stretchRangesY,
164 bool addChildRegion = false,
165 Vector4 requiredChildRegion = Vector4::ZERO )
167 TestPlatformAbstraction& platform = application.GetPlatform();
169 Pixel::Format pixelFormat = Pixel::RGBA8888;
171 tet_infoline("Create Bitmap");
172 platform.SetClosestImageSize(Vector2( ninePatchImageWidth, ninePatchImageHeight));
173 Integration::Bitmap* bitmap = CreateBitmap( ninePatchImageWidth, ninePatchImageHeight, 0xFF, pixelFormat );
175 tet_infoline("Clear border regions");
176 InitialiseRegionsToZeroAlpha( bitmap, ninePatchImageWidth, ninePatchImageHeight, pixelFormat );
178 tet_infoline("Add Stretch regions to Bitmap");
179 AddStretchRegionsToImage( bitmap, ninePatchImageWidth, ninePatchImageHeight, stretchRangesX, stretchRangesY, pixelFormat );
183 tet_infoline("Add Child regions to Bitmap");
184 AddChildRegionsToImage( bitmap, ninePatchImageWidth, ninePatchImageHeight, requiredChildRegion, pixelFormat );
187 tet_infoline("Getting resource");
188 Integration::ResourcePointer resourcePtr(bitmap);
189 //platform.SetResourceLoaded( 0, Dali::Integration::ResourceBitmap, resourcePtr );
190 platform.SetSynchronouslyLoadedResource( resourcePtr);
195 void TestVisualRender( ToolkitTestApplication& application,
197 Visual::Base& visual,
198 std::size_t expectedSamplers = 0,
199 ImageDimensions imageDimensions = ImageDimensions(),
200 Integration::ResourcePointer resourcePtr = Integration::ResourcePointer())
202 DummyControlImpl& dummyImpl = static_cast<DummyControlImpl&>(actor.GetImplementation());
203 dummyImpl.RegisterVisual( DummyControl::Property::TEST_VISUAL, visual );
207 // set the image size, for test case, this needs to be set before loading started
208 application.GetPlatform().SetClosestImageSize( Vector2(imageDimensions.GetWidth(), imageDimensions.GetHeight()) );
211 actor.SetSize( 200.f, 200.f );
212 DALI_TEST_EQUALS( actor.GetRendererCount(), 0u, TEST_LOCATION );
214 Stage::GetCurrent().Add( actor );
216 application.SendNotification();
217 application.Render();
219 application.Render();
220 application.SendNotification();
224 DALI_TEST_EQUALS( application.GetPlatform().WasCalled(TestPlatformAbstraction::LoadResourceSynchronouslyFunc ), true, TEST_LOCATION);
227 DALI_TEST_EQUALS( actor.GetRendererCount(), 1u, TEST_LOCATION );
234 void dali_visual_factory_startup(void)
236 test_return_value = TET_UNDEF;
239 void dali_visual_factory_cleanup(void)
241 test_return_value = TET_PASS;
244 int UtcDaliVisualFactoryGet(void)
246 ToolkitTestApplication application;
247 tet_infoline( "UtcDaliVisualFactory" );
251 type = TypeRegistry::Get().GetTypeInfo( "VisualFactory" );
252 DALI_TEST_CHECK( type );
253 BaseHandle handle = type.CreateInstance();
254 DALI_TEST_CHECK( handle );
256 VisualFactory factory;
257 factory = VisualFactory::Get();
258 DALI_TEST_CHECK( factory );
260 VisualFactory newFactory = VisualFactory::Get();
261 DALI_TEST_CHECK( newFactory );
263 // Check that visual factory is a singleton
264 DALI_TEST_CHECK(factory == newFactory);
269 int UtcDaliVisualFactoryCopyAndAssignment(void)
271 ToolkitTestApplication application;
272 tet_infoline( "UtcDaliVisualFactoryCopyAndAssignment" );
273 VisualFactory factory = VisualFactory::Get();
275 VisualFactory factoryCopy( factory );
276 DALI_TEST_CHECK(factory == factoryCopy);
278 VisualFactory emptyFactory;
279 VisualFactory emptyFactoryCopy( emptyFactory );
280 DALI_TEST_CHECK(emptyFactory == emptyFactoryCopy);
282 VisualFactory factoryEquals;
283 factoryEquals = factory;
284 DALI_TEST_CHECK(factory == factoryEquals);
286 VisualFactory emptyFactoryEquals;
287 emptyFactoryEquals = emptyFactory;
288 DALI_TEST_CHECK( emptyFactory == emptyFactoryEquals );
292 DALI_TEST_CHECK( factory = factoryCopy );
297 int UtcDaliVisualFactoryGetColorVisual1(void)
299 ToolkitTestApplication application;
300 tet_infoline( "UtcDaliVisualFactoryGetColorVisual1: Request color visual with a Property::Map" );
302 VisualFactory factory = VisualFactory::Get();
303 DALI_TEST_CHECK( factory );
305 Property::Map propertyMap;
306 Vector4 testColor( 1.f, 0.5f, 0.3f, 0.2f );
307 propertyMap.Insert(Visual::Property::TYPE, Visual::COLOR);
308 propertyMap.Insert(ColorVisual::Property::MIX_COLOR, testColor);
310 Visual::Base visual = factory.CreateVisual(propertyMap);
311 DALI_TEST_CHECK( visual );
313 DummyControl actor = DummyControl::New(true);
314 TestVisualRender( application, actor, visual );
316 Vector3 actualValue(Vector4::ZERO);
318 TestGlAbstraction& gl = application.GetGlAbstraction();
319 DALI_TEST_CHECK( gl.GetUniformValue<Vector3>( "mixColor", actualValue ) );
320 DALI_TEST_CHECK( gl.GetUniformValue<float>( "opacity", opacity ) );
321 DALI_TEST_EQUALS( actualValue, Vector3(testColor), TEST_LOCATION );
322 DALI_TEST_EQUALS( opacity, testColor.a, TEST_LOCATION );
327 int UtcDaliVisualFactoryGetColorVisual2(void)
329 ToolkitTestApplication application;
330 tet_infoline( "UtcDaliVisualFactoryGetColorVisual2: Request color visual with a Vector4" );
332 VisualFactory factory = VisualFactory::Get();
333 DALI_TEST_CHECK( factory );
335 Vector4 testColor( 1.f, 0.5f, 0.3f, 0.2f );
336 Dali::Property::Map map;
337 map[ Toolkit::Visual::Property::TYPE ] = Visual::COLOR;
338 map[ ColorVisual::Property::MIX_COLOR ] = testColor;
339 Visual::Base visual = factory.CreateVisual( map );
340 DALI_TEST_CHECK( visual );
342 DummyControl actor = DummyControl::New(true);
343 TestVisualRender( application, actor, visual );
347 TestGlAbstraction& gl = application.GetGlAbstraction();
348 DALI_TEST_CHECK( gl.GetUniformValue<Vector3>( "mixColor", actualValue ) );
349 DALI_TEST_CHECK( gl.GetUniformValue<float>( "opacity", opacity ) );
350 DALI_TEST_EQUALS( actualValue, Vector3(testColor), TEST_LOCATION );
351 DALI_TEST_EQUALS( opacity, testColor.a, TEST_LOCATION );
353 Stage::GetCurrent().Remove(actor);
354 DALI_TEST_CHECK( actor.GetRendererCount() == 0u );
359 int UtcDaliVisualFactoryGetBorderVisual1(void)
361 ToolkitTestApplication application;
362 tet_infoline( "UtcDaliVisualFactoryGetBorderVisual1: Request border visual with a Property::Map" );
364 VisualFactory factory = VisualFactory::Get();
365 DALI_TEST_CHECK( factory );
367 Property::Map propertyMap;
368 Vector4 testColor( 1.f, 0.5f, 0.3f, 0.2f );
369 float testSize = 5.f;
370 propertyMap.Insert(Visual::Property::TYPE, Visual::BORDER);
371 propertyMap.Insert(BorderVisual::Property::COLOR, testColor);
372 propertyMap.Insert(BorderVisual::Property::SIZE, testSize);
374 Visual::Base visual = factory.CreateVisual(propertyMap);
375 DALI_TEST_CHECK( visual );
377 DummyControl actor = DummyControl::New(true);
378 DummyControlImpl& dummyImpl = static_cast<DummyControlImpl&>(actor.GetImplementation());
379 dummyImpl.RegisterVisual( DummyControl::Property::TEST_VISUAL, visual );
380 actor.SetSize(200.f, 200.f);
381 Stage::GetCurrent().Add( actor );
382 visual.SetTransformAndSize(DefaultTransform(), Vector2(200.f, 200.f));
384 DALI_TEST_CHECK( actor.GetRendererCount() == 1u );
385 int blendMode = actor.GetRendererAt(0u).GetProperty<int>( Renderer::Property::BLEND_MODE );
386 DALI_TEST_EQUALS( static_cast<BlendMode::Type>(blendMode), BlendMode::ON, TEST_LOCATION );
388 TestGlAbstraction& gl = application.GetGlAbstraction();
390 application.SendNotification();
391 application.Render(0);
393 Vector4 actualColor(Vector4::ZERO);
394 DALI_TEST_CHECK( gl.GetUniformValue<Vector4>( "borderColor", actualColor ) );
395 DALI_TEST_EQUALS( actualColor, testColor, TEST_LOCATION );
397 float actualSize = 0.f;
398 DALI_TEST_CHECK( gl.GetUniformValue<float>( "borderSize", actualSize ) );
399 DALI_TEST_EQUALS( actualSize, testSize, TEST_LOCATION );
402 DALI_TEST_CHECK( actor.GetRendererCount() == 0u );
407 int UtcDaliVisualFactoryGetBorderVisual2(void)
409 ToolkitTestApplication application;
410 tet_infoline( "UtcDaliVisualFactoryGetBorderVisual2: Request border visual with a borderSize and a borderColor" );
412 VisualFactory factory = VisualFactory::Get();
413 DALI_TEST_CHECK( factory );
415 Vector4 testColor( 1.f, 0.5f, 0.3f, 1.f );
416 float testSize = 5.f;
418 Dali::Property::Map propertyMap;
419 propertyMap[ Toolkit::Visual::Property::TYPE ] = Visual::BORDER;
420 propertyMap[ BorderVisual::Property::COLOR ] = testColor;
421 propertyMap[ BorderVisual::Property::SIZE ] = testSize;
422 Visual::Base visual = factory.CreateVisual( propertyMap );
423 DALI_TEST_CHECK( visual );
425 DummyControl actor = DummyControl::New(true);
426 DummyControlImpl& dummyImpl = static_cast<DummyControlImpl&>(actor.GetImplementation());
427 dummyImpl.RegisterVisual( DummyControl::Property::TEST_VISUAL, visual );
428 actor.SetSize(200.f, 200.f);
429 Stage::GetCurrent().Add( actor );
430 visual.SetTransformAndSize(DefaultTransform(), Vector2(200.f, 200.f));
432 DALI_TEST_CHECK( actor.GetRendererCount() == 1u );
434 TestGlAbstraction& gl = application.GetGlAbstraction();
436 application.SendNotification();
437 application.Render(0);
439 int blendMode = actor.GetRendererAt(0u).GetProperty<int>( Renderer::Property::BLEND_MODE );
440 DALI_TEST_EQUALS( static_cast<BlendMode::Type>(blendMode), BlendMode::AUTO, TEST_LOCATION );
442 Vector4 actualColor(Vector4::ZERO);
443 DALI_TEST_CHECK( gl.GetUniformValue<Vector4>( "borderColor", actualColor ) );
444 DALI_TEST_EQUALS( actualColor, testColor, TEST_LOCATION );
446 float actualSize = 0.f;
447 DALI_TEST_CHECK( gl.GetUniformValue<float>( "borderSize", actualSize ) );
448 DALI_TEST_EQUALS( actualSize, testSize, TEST_LOCATION );
452 // enable the anti-aliasing
453 Dali::Property::Map map;
454 map[ Toolkit::Visual::Property::TYPE ] = Visual::BORDER;
455 map[ BorderVisual::Property::COLOR ] = testColor;
456 map[ BorderVisual::Property::SIZE ] = testSize;
457 map[ BorderVisual::Property::ANTI_ALIASING ] = true;
458 visual = factory.CreateVisual( map );
460 dummyImpl.RegisterVisual( Control::CONTROL_PROPERTY_END_INDEX + 1, visual );
461 Stage::GetCurrent().Add( actor );
463 blendMode = actor.GetRendererAt(0u).GetProperty<int>( Renderer::Property::BLEND_MODE );
464 DALI_TEST_EQUALS( static_cast<BlendMode::Type>(blendMode), BlendMode::ON, TEST_LOCATION );
469 int UtcDaliVisualFactoryGetLinearGradientVisual(void)
471 ToolkitTestApplication application;
472 tet_infoline("UtcDaliVisualFactoryGetRadialGradientVisual");
474 VisualFactory factory = VisualFactory::Get();
475 DALI_TEST_CHECK( factory );
477 Property::Map propertyMap;
478 propertyMap.Insert(Visual::Property::TYPE, Visual::GRADIENT);
480 Vector2 start(-1.f, -1.f);
481 Vector2 end(1.f, 1.f);
482 propertyMap.Insert(GradientVisual::Property::START_POSITION, start);
483 propertyMap.Insert(GradientVisual::Property::END_POSITION, end);
484 propertyMap.Insert(GradientVisual::Property::SPREAD_METHOD, GradientVisual::SpreadMethod::REPEAT);
486 Property::Array stopOffsets;
487 stopOffsets.PushBack( 0.2f );
488 stopOffsets.PushBack( 0.8f );
489 propertyMap.Insert(GradientVisual::Property::STOP_OFFSET, stopOffsets);
491 Property::Array stopColors;
492 stopColors.PushBack( Color::RED );
493 stopColors.PushBack( Color::GREEN );
494 propertyMap.Insert(GradientVisual::Property::STOP_COLOR, stopColors);
496 Visual::Base visual = factory.CreateVisual(propertyMap);
497 DALI_TEST_CHECK( visual );
499 // A lookup texture is generated and pass to shader as sampler
500 DummyControl actor = DummyControl::New(true);
501 TestVisualRender( application, actor, visual, 1u);
506 int UtcDaliVisualFactoryGetRadialGradientVisual(void)
508 ToolkitTestApplication application;
509 tet_infoline("UtcDaliVisualFactoryGetRadialGradientVisual");
511 VisualFactory factory = VisualFactory::Get();
512 DALI_TEST_CHECK( factory );
514 Property::Map propertyMap;
515 propertyMap.Insert(Visual::Property::TYPE, Visual::GRADIENT);
517 Vector2 center(100.f, 100.f);
518 float radius = 100.f;
519 propertyMap.Insert(GradientVisual::Property::UNITS, GradientVisual::Units::USER_SPACE);
520 propertyMap.Insert(GradientVisual::Property::CENTER, center);
521 propertyMap.Insert(GradientVisual::Property::RADIUS, radius);
523 Property::Array stopOffsets;
524 stopOffsets.PushBack( 0.0f );
525 stopOffsets.PushBack( 1.f );
526 propertyMap.Insert(GradientVisual::Property::STOP_OFFSET, stopOffsets);
528 Property::Array stopColors;
529 stopColors.PushBack( Color::RED );
530 stopColors.PushBack( Color::GREEN );
531 propertyMap.Insert(GradientVisual::Property::STOP_COLOR, stopColors);
533 Visual::Base visual = factory.CreateVisual(propertyMap);
534 DALI_TEST_CHECK( visual );
536 // A lookup texture is generated and pass to shader as sampler
537 DummyControl actor = DummyControl::New(true);
538 TestVisualRender( application, actor, visual, 1u );
540 Matrix3 alignMatrix( radius, 0.f, 0.f, 0.f, radius, 0.f, center.x, center.y, 1.f );
541 alignMatrix.Invert();
543 Matrix3 actualValue( Matrix3::IDENTITY );
544 TestGlAbstraction& gl = application.GetGlAbstraction();
545 DALI_TEST_CHECK( gl.GetUniformValue<Matrix3>( "uAlignmentMatrix", actualValue ) );
546 DALI_TEST_EQUALS( actualValue, alignMatrix, Math::MACHINE_EPSILON_100, TEST_LOCATION );
551 int UtcDaliVisualFactoryDefaultOffsetsGradientVisual(void)
553 ToolkitTestApplication application;
554 tet_infoline("UtcDaliVisualFactoryGetRadialGradientVisual");
556 VisualFactory factory = VisualFactory::Get();
557 DALI_TEST_CHECK( factory );
559 Property::Map propertyMap;
560 propertyMap.Insert(Visual::Property::TYPE, Visual::GRADIENT);
562 Vector2 start(-1.f, -1.f);
563 Vector2 end(1.f, 1.f);
564 propertyMap.Insert(GradientVisual::Property::START_POSITION, start);
565 propertyMap.Insert(GradientVisual::Property::END_POSITION, end);
566 propertyMap.Insert(GradientVisual::Property::SPREAD_METHOD, GradientVisual::SpreadMethod::REPEAT);
568 Property::Array stopColors;
569 stopColors.PushBack( Color::RED );
570 stopColors.PushBack( Color::GREEN );
571 propertyMap.Insert(GradientVisual::Property::STOP_COLOR, stopColors);
573 Visual::Base visual = factory.CreateVisual(propertyMap);
574 DALI_TEST_CHECK( visual );
576 // A lookup texture is generated and pass to shader as sampler
577 DummyControl actor = DummyControl::New(true);
578 TestVisualRender( application, actor, visual, 1u );
580 Stage::GetCurrent().Remove( actor );
581 DALI_TEST_CHECK( actor.GetRendererCount() == 0u );
590 int UtcDaliVisualFactoryGetNPatchVisual1(void)
592 ToolkitTestApplication application;
593 tet_infoline( "UtcDaliVisualFactoryGetNPatchVisual1: Request 9-patch visual with a Property::Map" );
595 VisualFactory factory = VisualFactory::Get();
596 DALI_TEST_CHECK( factory );
598 const unsigned int ninePatchImageHeight = 18;
599 const unsigned int ninePatchImageWidth = 28;
600 StretchRanges stretchRangesX;
601 stretchRangesX.PushBack( Uint16Pair( 2, 3 ) );
602 StretchRanges stretchRangesY;
603 stretchRangesY.PushBack( Uint16Pair( 4, 5 ) );
604 Integration::ResourcePointer ninePatchResource = CustomizeNinePatch( application, ninePatchImageWidth, ninePatchImageHeight, stretchRangesX, stretchRangesY );
606 Property::Map propertyMap;
607 propertyMap.Insert( Toolkit::Visual::Property::TYPE, Visual::N_PATCH );
608 propertyMap.Insert( ImageVisual::Property::URL, TEST_NPATCH_FILE_NAME );
610 tet_infoline( "whole grid" );
611 Visual::Base visual = factory.CreateVisual( propertyMap );
612 DALI_TEST_CHECK( visual );
615 TestGlAbstraction& gl = application.GetGlAbstraction();
616 TraceCallStack& textureTrace = gl.GetTextureTrace();
617 textureTrace.Enable(true);
619 DummyControl actor = DummyControl::New(true);
620 TestVisualRender( application, actor, visual, 1u,
621 ImageDimensions(ninePatchImageWidth, ninePatchImageHeight),
624 DALI_TEST_EQUALS( textureTrace.FindMethod("BindTexture"), true, TEST_LOCATION );
627 propertyMap.Insert( ImageVisual::Property::BORDER_ONLY, true );
629 tet_infoline( "border only" );
630 Visual::Base visual = factory.CreateVisual( propertyMap );
631 DALI_TEST_CHECK( visual );
633 TestGlAbstraction& gl = application.GetGlAbstraction();
634 TraceCallStack& textureTrace = gl.GetTextureTrace();
635 textureTrace.Enable(true);
637 DummyControl actor = DummyControl::New(true);
638 TestVisualRender( application, actor, visual, 1u,
639 ImageDimensions(ninePatchImageWidth, ninePatchImageHeight),
642 DALI_TEST_EQUALS( textureTrace.FindMethod("BindTexture"), true, TEST_LOCATION );
648 int UtcDaliVisualFactoryGetNPatchVisual2(void)
650 ToolkitTestApplication application;
651 tet_infoline( "UtcDaliVisualFactoryGetNPatchVisual1: Request 9-patch visual with a Property::Map including border" );
653 VisualFactory factory = VisualFactory::Get();
654 DALI_TEST_CHECK( factory );
656 Property::Map propertyMap;
657 propertyMap.Insert( Toolkit::Visual::Property::TYPE, Visual::N_PATCH );
658 propertyMap.Insert( ImageVisual::Property::URL, gImage_34_RGBA );
659 propertyMap.Insert( ImageVisual::Property::BORDER, Rect< int >( 2, 2, 2, 2 ) );
661 tet_infoline( "whole grid" );
662 Visual::Base visual = factory.CreateVisual( propertyMap );
663 DALI_TEST_CHECK( visual );
665 TestGlAbstraction& gl = application.GetGlAbstraction();
666 TraceCallStack& textureTrace = gl.GetTextureTrace();
667 textureTrace.Enable(true);
669 DummyControl actor = DummyControl::New(true);
670 TestVisualRender( application, actor, visual, 1u );
672 DALI_TEST_EQUALS( textureTrace.FindMethod("BindTexture"), true, TEST_LOCATION );
675 propertyMap.Insert( ImageVisual::Property::BORDER_ONLY, true );
677 tet_infoline( "border only" );
678 Visual::Base visual = factory.CreateVisual( propertyMap );
679 DALI_TEST_CHECK( visual );
681 TestGlAbstraction& gl = application.GetGlAbstraction();
682 TraceCallStack& textureTrace = gl.GetTextureTrace();
683 textureTrace.Enable(true);
685 DummyControl actor = DummyControl::New(true);
686 TestVisualRender( application, actor, visual, 1u );
688 DALI_TEST_EQUALS( textureTrace.FindMethod("BindTexture"), true, TEST_LOCATION );
692 propertyMap.Insert( Toolkit::Visual::Property::TYPE, Visual::N_PATCH );
693 propertyMap.Insert( ImageVisual::Property::URL, gImage_34_RGBA );
694 propertyMap.Insert( ImageVisual::Property::BORDER, Rect< int >( 1, 1, 1, 1 ) );
696 tet_infoline( "whole grid" );
697 Visual::Base visual = factory.CreateVisual( propertyMap );
698 DALI_TEST_CHECK( visual );
700 TestGlAbstraction& gl = application.GetGlAbstraction();
701 TraceCallStack& textureTrace = gl.GetTextureTrace();
702 textureTrace.Enable(true);
704 DummyControl actor = DummyControl::New(true);
705 TestVisualRender( application, actor, visual, 1u );
707 DALI_TEST_EQUALS( textureTrace.FindMethod("BindTexture"), true, TEST_LOCATION );
713 int UtcDaliVisualFactoryGetNPatchVisual3(void)
715 ToolkitTestApplication application;
716 tet_infoline( "UtcDaliVisualFactoryGetNPatchVisual2: Request n-patch visual with a Property::Map" );
718 VisualFactory factory = VisualFactory::Get();
719 DALI_TEST_CHECK( factory );
721 const unsigned int ninePatchImageWidth = 18;
722 const unsigned int ninePatchImageHeight = 28;
723 StretchRanges stretchRangesX;
724 stretchRangesX.PushBack( Uint16Pair( 2, 3 ) );
725 stretchRangesX.PushBack( Uint16Pair( 5, 7 ) );
726 stretchRangesX.PushBack( Uint16Pair( 12, 15 ) );
727 StretchRanges stretchRangesY;
728 stretchRangesY.PushBack( Uint16Pair( 4, 5 ) );
729 stretchRangesY.PushBack( Uint16Pair( 8, 12 ) );
730 stretchRangesY.PushBack( Uint16Pair( 15, 16 ) );
731 stretchRangesY.PushBack( Uint16Pair( 25, 27 ) );
732 Integration::ResourcePointer ninePatchResource = CustomizeNinePatch( application, ninePatchImageWidth, ninePatchImageHeight, stretchRangesX, stretchRangesY );
734 Property::Map propertyMap;
735 propertyMap.Insert( Toolkit::Visual::Property::TYPE, Visual::N_PATCH );
736 propertyMap.Insert( ImageVisual::Property::URL, TEST_NPATCH_FILE_NAME );
738 Visual::Base visual = factory.CreateVisual( propertyMap );
739 DALI_TEST_CHECK( visual );
741 TestGlAbstraction& gl = application.GetGlAbstraction();
742 TraceCallStack& textureTrace = gl.GetTextureTrace();
743 textureTrace.Enable(true);
745 DummyControl actor = DummyControl::New(true);
746 TestVisualRender( application, actor, visual, 1u,
747 ImageDimensions(ninePatchImageWidth, ninePatchImageHeight),
750 DALI_TEST_EQUALS( textureTrace.FindMethod("BindTexture"), true, TEST_LOCATION );
752 Stage::GetCurrent().Remove( actor );
753 DALI_TEST_CHECK( actor.GetRendererCount() == 0u );
756 propertyMap.Insert( ImageVisual::Property::BORDER_ONLY, true );
758 tet_infoline( "border only" );
759 Visual::Base visual = factory.CreateVisual( propertyMap );
760 DALI_TEST_CHECK( visual );
762 TestGlAbstraction& gl = application.GetGlAbstraction();
763 TraceCallStack& textureTrace = gl.GetTextureTrace();
764 textureTrace.Enable(true);
765 DummyControl actor = DummyControl::New(true);
766 TestVisualRender( application, actor, visual, 1u,
767 ImageDimensions(ninePatchImageWidth, ninePatchImageHeight),
771 DALI_TEST_EQUALS( textureTrace.FindMethod("BindTexture"), true, TEST_LOCATION );
773 Stage::GetCurrent().Remove( actor );
774 DALI_TEST_CHECK( actor.GetRendererCount() == 0u );
780 int UtcDaliVisualFactoryGetNPatchVisual4(void)
782 ToolkitTestApplication application;
783 tet_infoline( "UtcDaliVisualFactoryGetNPatchVisual3: Request 9-patch visual with an image url" );
785 VisualFactory factory = VisualFactory::Get();
786 DALI_TEST_CHECK( factory );
788 const unsigned int ninePatchImageHeight = 18;
789 const unsigned int ninePatchImageWidth = 28;
790 StretchRanges stretchRangesX;
791 stretchRangesX.PushBack( Uint16Pair( 2, 3 ) );
792 StretchRanges stretchRangesY;
793 stretchRangesY.PushBack( Uint16Pair( 4, 5 ) );
794 Integration::ResourcePointer ninePatchResource = CustomizeNinePatch( application, ninePatchImageWidth, ninePatchImageHeight, stretchRangesX, stretchRangesY );
796 Visual::Base visual = factory.CreateVisual( TEST_NPATCH_FILE_NAME, ImageDimensions() );
797 DALI_TEST_CHECK( visual );
799 TestGlAbstraction& gl = application.GetGlAbstraction();
800 TraceCallStack& textureTrace = gl.GetTextureTrace();
801 textureTrace.Enable(true);
803 DummyControl actor = DummyControl::New(true);
804 TestVisualRender( application, actor, visual, 1u,
805 ImageDimensions(ninePatchImageWidth, ninePatchImageHeight),
808 DALI_TEST_EQUALS( textureTrace.FindMethod("BindTexture"), true, TEST_LOCATION );
811 ResourceImage image = ResourceImage::New(TEST_NPATCH_FILE_NAME);
812 Visual::Base nPatchVisual = factory.CreateVisual( image );
813 Vector2 controlSize( 20.f, 30.f ), naturalSize(0,0);
814 nPatchVisual.SetTransformAndSize(DefaultTransform(), controlSize );
815 nPatchVisual.GetNaturalSize( naturalSize );
816 DALI_TEST_EQUALS( naturalSize, Vector2( ninePatchImageWidth-2, ninePatchImageHeight-2 ), TEST_LOCATION );
821 int UtcDaliVisualFactoryGetNPatchVisual5(void)
823 ToolkitTestApplication application;
824 tet_infoline( "UtcDaliVisualFactoryGetNPatchVisual4: Request n-patch visual with an image url" );
826 VisualFactory factory = VisualFactory::Get();
827 DALI_TEST_CHECK( factory );
829 const unsigned int ninePatchImageHeight = 18;
830 const unsigned int ninePatchImageWidth = 28;
831 StretchRanges stretchRangesX;
832 stretchRangesX.PushBack( Uint16Pair( 2, 3 ) );
833 stretchRangesX.PushBack( Uint16Pair( 5, 7 ) );
834 stretchRangesX.PushBack( Uint16Pair( 12, 15 ) );
835 StretchRanges stretchRangesY;
836 stretchRangesY.PushBack( Uint16Pair( 4, 5 ) );
837 stretchRangesY.PushBack( Uint16Pair( 8, 12 ) );
838 stretchRangesY.PushBack( Uint16Pair( 15, 16 ) );
839 stretchRangesY.PushBack( Uint16Pair( 25, 27 ) );
840 Integration::ResourcePointer ninePatchResource = CustomizeNinePatch( application, ninePatchImageWidth, ninePatchImageHeight, stretchRangesX, stretchRangesY );
842 Visual::Base visual = factory.CreateVisual( TEST_NPATCH_FILE_NAME, ImageDimensions() );
843 DALI_TEST_CHECK( visual );
845 TestGlAbstraction& gl = application.GetGlAbstraction();
846 TraceCallStack& textureTrace = gl.GetTextureTrace();
847 textureTrace.Enable(true);
849 DummyControl actor = DummyControl::New(true);
850 TestVisualRender( application, actor, visual, 1u,
851 ImageDimensions(ninePatchImageWidth, ninePatchImageHeight),
854 DALI_TEST_EQUALS( textureTrace.FindMethod("BindTexture"), true, TEST_LOCATION );
859 int UtcDaliVisualFactoryGetNPatchVisualN1(void)
861 //This should still load but display an error image
863 ToolkitTestApplication application;
864 tet_infoline( "UtcDaliVisualFactoryGetNPatchVisualN: Request n-patch visual with an invalid image url" );
866 VisualFactory factory = VisualFactory::Get();
867 DALI_TEST_CHECK( factory );
869 Visual::Base visual = factory.CreateVisual( "ERROR.9.jpg", ImageDimensions() );
870 DALI_TEST_CHECK( visual );
872 //The testkit still has to load a bitmap for the broken renderer image
873 Integration::Bitmap* bitmap = Integration::Bitmap::New(Integration::Bitmap::BITMAP_2D_PACKED_PIXELS, ResourcePolicy::OWNED_DISCARD);
874 bitmap->GetPackedPixelsProfile()->ReserveBuffer( Pixel::RGBA8888, 100, 100, 100, 100 );
876 TestGlAbstraction& gl = application.GetGlAbstraction();
877 TraceCallStack& textureTrace = gl.GetTextureTrace();
878 textureTrace.Enable(true);
880 DummyControl actor = DummyControl::New(true);
881 TestVisualRender( application, actor, visual, 1u,
883 Integration::ResourcePointer(bitmap) );
885 DALI_TEST_EQUALS( textureTrace.FindMethod("BindTexture"), true, TEST_LOCATION );
890 int UtcDaliVisualFactoryGetNPatchVisualN2(void)
892 //This should still load but display an error image
894 ToolkitTestApplication application;
895 tet_infoline( "UtcDaliVisualFactoryGetNPatchVisualN: Request n-patch visual with an invalid URL" );
897 VisualFactory factory = VisualFactory::Get();
898 DALI_TEST_CHECK( factory );
900 Property::Map propertyMap;
901 propertyMap.Insert( Toolkit::Visual::Property::TYPE, Visual::N_PATCH );
902 propertyMap.Insert( ImageVisual::Property::URL, "ERROR.9.jpg" );
904 Visual::Base visual = factory.CreateVisual( propertyMap );
905 DALI_TEST_CHECK( visual );
907 //The testkit still has to load a bitmap for the broken renderer image
908 Integration::Bitmap* bitmap = Integration::Bitmap::New(Integration::Bitmap::BITMAP_2D_PACKED_PIXELS, ResourcePolicy::OWNED_DISCARD);
909 bitmap->GetPackedPixelsProfile()->ReserveBuffer( Pixel::RGBA8888, 100, 100, 100, 100 );
911 TestGlAbstraction& gl = application.GetGlAbstraction();
912 TraceCallStack& textureTrace = gl.GetTextureTrace();
913 textureTrace.Enable(true);
914 TraceCallStack& drawTrace = gl.GetDrawTrace();
915 drawTrace.Enable(true);
917 DummyControl actor = DummyControl::New(true);
918 TestVisualRender( application, actor, visual, 1u,
920 Integration::ResourcePointer(bitmap) );
922 DALI_TEST_EQUALS( textureTrace.FindMethod("BindTexture"), true, TEST_LOCATION );
927 int UtcDaliVisualFactoryGetNPatchVisualN3(void)
929 // Passing in an invalid visual type so we should not get a visual
931 ToolkitTestApplication application;
932 tet_infoline( "UtcDaliVisualFactoryGetNPatchVisualN: Request n-patch visual with an invalid visual type" );
934 VisualFactory factory = VisualFactory::Get();
935 DALI_TEST_CHECK( factory );
937 Property::Map propertyMap;
938 propertyMap.Insert( Toolkit::Visual::Property::TYPE, 111 );
939 propertyMap.Insert( ImageVisual::Property::URL, "ERROR.9.jpg" );
941 Visual::Base visual = factory.CreateVisual( propertyMap );
942 DALI_TEST_CHECK( !visual );
947 int UtcDaliVisualFactoryGetSvgVisual(void)
949 ToolkitTestApplication application;
950 tet_infoline( "UtcDaliVisualFactoryGetSvgVisual: Request svg visual with a svg url" );
952 VisualFactory factory = VisualFactory::Get();
953 Visual::Base visual = factory.CreateVisual( TEST_SVG_FILE_NAME, ImageDimensions() );
954 DALI_TEST_CHECK( visual );
956 TestGlAbstraction& gl = application.GetGlAbstraction();
957 TraceCallStack& textureTrace = gl.GetTextureTrace();
958 textureTrace.Enable(true);
960 DummyControl actor = DummyControl::New(true);
961 DummyControlImpl& dummyImpl = static_cast<DummyControlImpl&>(actor.GetImplementation());
962 dummyImpl.RegisterVisual( DummyControl::Property::TEST_VISUAL, visual );
963 actor.SetSize( 200.f, 200.f );
964 Stage::GetCurrent().Add( actor );
965 visual.SetTransformAndSize(DefaultTransform(), Vector2(200.f, 200.f) );
967 application.SendNotification();
968 application.Render();
970 // renderer is not added to actor until the rasterization is completed.
971 DALI_TEST_CHECK( actor.GetRendererCount() == 0u );
973 DALI_TEST_EQUALS( Test::WaitForEventThreadTrigger( 1 ), true, TEST_LOCATION );
975 // renderer is added to actor
976 DALI_TEST_CHECK( actor.GetRendererCount() == 1u );
978 // waiting for the resource uploading
979 application.SendNotification();
980 application.Render();
982 DALI_TEST_EQUALS( textureTrace.FindMethod("BindTexture"), true, TEST_LOCATION );
987 int UtcDaliVisualFactoryGetSvgVisualLarge(void)
989 ToolkitTestApplication application;
990 tet_infoline( "UtcDaliVisualFactoryGetSvgVisual: Request svg visual with a svg url" );
992 VisualFactory factory = VisualFactory::Get();
993 Visual::Base visual = factory.CreateVisual( TEST_SVG_FILE_NAME, ImageDimensions( 2000, 2000 ) );
994 DALI_TEST_CHECK( visual );
996 TestGlAbstraction& gl = application.GetGlAbstraction();
997 TraceCallStack& textureTrace = gl.GetTextureTrace();
998 textureTrace.Enable(true);
1000 DummyControl actor = DummyControl::New(true);
1001 DummyControlImpl& dummyImpl = static_cast<DummyControlImpl&>(actor.GetImplementation());
1002 actor.SetResizePolicy( ResizePolicy::FILL_TO_PARENT, Dimension::ALL_DIMENSIONS ); // Only rasterizes when it knows control size.
1003 dummyImpl.RegisterVisual( DummyControl::Property::TEST_VISUAL, visual );
1004 Stage::GetCurrent().Add( actor );
1006 application.SendNotification();
1007 application.Render();
1009 // renderer is not added to actor until the rasterization is completed.
1010 DALI_TEST_CHECK( actor.GetRendererCount() == 0u );
1012 DALI_TEST_EQUALS( Test::WaitForEventThreadTrigger( 1 ), true, TEST_LOCATION );
1014 // renderer is added to actor
1015 DALI_TEST_CHECK( actor.GetRendererCount() == 1u );
1017 // waiting for the resource uploading
1018 application.SendNotification();
1019 application.Render();
1021 DALI_TEST_EQUALS( textureTrace.FindMethod("BindTexture"), true, TEST_LOCATION );
1026 int UtcDaliVisualFactoryGetSvgVisualAtlas(void)
1028 ToolkitTestApplication application;
1029 tet_infoline( "UtcDaliVisualFactoryGetSvgVisual: Request svg visual with enabled atlas" );
1031 VisualFactory factory = VisualFactory::Get();
1033 Property::Map propertyMap;
1034 propertyMap.Insert( Toolkit::Visual::Property::TYPE, Visual::SVG );
1035 propertyMap.Insert( ImageVisual::Property::URL, TEST_SVG_FILE_NAME );
1036 propertyMap.Insert( ImageVisual::Property::ATLASING, true );
1038 Visual::Base visual = factory.CreateVisual( propertyMap );
1039 DALI_TEST_CHECK( visual );
1041 TestGlAbstraction& gl = application.GetGlAbstraction();
1042 TraceCallStack& textureTrace = gl.GetTextureTrace();
1043 textureTrace.Enable(true);
1045 DummyControl actor = DummyControl::New(true);
1046 DummyControlImpl& dummyImpl = static_cast<DummyControlImpl&>(actor.GetImplementation());
1047 dummyImpl.RegisterVisual( DummyControl::Property::TEST_VISUAL, visual );
1048 actor.SetSize( 200.f, 200.f );
1049 Stage::GetCurrent().Add( actor );
1050 visual.SetTransformAndSize(DefaultTransform(), Vector2(200.f, 200.f) );
1052 application.SendNotification();
1053 application.Render();
1055 // renderer is not added to actor until the rasterization is completed.
1056 DALI_TEST_CHECK( actor.GetRendererCount() == 0u );
1058 DALI_TEST_EQUALS( Test::WaitForEventThreadTrigger( 1 ), true, TEST_LOCATION );
1060 // renderer is added to actor
1061 DALI_TEST_CHECK( actor.GetRendererCount() == 1u );
1063 // waiting for the resource uploading
1064 application.SendNotification();
1065 application.Render();
1067 DALI_TEST_EQUALS( textureTrace.FindMethod("BindTexture"), true, TEST_LOCATION );
1072 //Creates a mesh visual from the given propertyMap and tries to load it on stage in the given application.
1073 //This is expected to succeed, which will then pass the test.
1074 void MeshVisualLoadsCorrectlyTest( Property::Map& propertyMap, ToolkitTestApplication& application )
1076 VisualFactory factory = VisualFactory::Get();
1077 DALI_TEST_CHECK( factory );
1079 //Create a mesh visual.
1080 Visual::Base visual = factory.CreateVisual( propertyMap );
1081 DALI_TEST_CHECK( visual );
1083 //Create an actor on stage to house the visual.
1084 DummyControl actor = DummyControl::New(true);
1085 DummyControlImpl& dummyImpl = static_cast<DummyControlImpl&>(actor.GetImplementation());
1086 dummyImpl.RegisterVisual( DummyControl::Property::TEST_VISUAL, visual );
1087 actor.SetSize( 200.f, 200.f );
1088 Stage::GetCurrent().Add( actor );
1089 visual.SetTransformAndSize(DefaultTransform(), Vector2( 200.f, 200.f ) );
1091 //Ensure set on stage.
1092 DALI_TEST_EQUALS( actor.GetRendererCount(), 1u, TEST_LOCATION );
1094 //Attempt to render to queue resource load requests.
1095 application.SendNotification();
1096 application.Render( 0 );
1098 //Render again to upload the now-loaded textures.
1099 application.SendNotification();
1100 application.Render( 0 );
1102 Matrix testScaleMatrix;
1103 testScaleMatrix.SetIdentityAndScale( Vector3( 1.0, -1.0, 1.0 ) );
1104 Matrix actualScaleMatrix;
1106 //Test to see if the object has been successfully loaded.
1107 DALI_TEST_CHECK( application.GetGlAbstraction().GetUniformValue<Matrix>( "uObjectMatrix", actualScaleMatrix ) );
1108 DALI_TEST_EQUALS( actualScaleMatrix, testScaleMatrix, Math::MACHINE_EPSILON_100, TEST_LOCATION );
1110 //Finish by setting off stage, and ensuring this was successful.
1112 DALI_TEST_EQUALS( actor.GetRendererCount(), 0u, TEST_LOCATION );
1115 //Creates a mesh visual from the given propertyMap and tries to load it on stage in the given application.
1116 //This is expected to fail, which will then pass the test.
1117 void MeshVisualDoesNotLoadCorrectlyTest( Property::Map& propertyMap, ToolkitTestApplication& application )
1119 VisualFactory factory = VisualFactory::Get();
1120 DALI_TEST_CHECK( factory );
1122 //Create a mesh visual.
1123 Visual::Base visual = factory.CreateVisual( propertyMap );
1124 DALI_TEST_CHECK( visual );
1126 //Create an actor on stage to house the visual.
1127 DummyControl actor = DummyControl::New(true);
1128 DummyControlImpl& dummyImpl = static_cast<DummyControlImpl&>(actor.GetImplementation());
1129 dummyImpl.RegisterVisual( DummyControl::Property::TEST_VISUAL, visual );
1130 actor.SetSize( 200.f, 200.f );
1131 Stage::GetCurrent().Add( actor );
1132 visual.SetTransformAndSize(DefaultTransform(), Vector2( 200.f, 200.f ) );
1134 //Ensure set on stage.
1135 DALI_TEST_EQUALS( actor.GetRendererCount(), 1u, TEST_LOCATION );
1137 //Attempt to render to queue resource load requests.
1138 application.SendNotification();
1139 application.Render( 0 );
1141 //Render again to upload the now-loaded textures.
1142 application.SendNotification();
1143 application.Render( 0 );
1145 //Test to see if the object has not been loaded, as expected.
1147 DALI_TEST_CHECK( !application.GetGlAbstraction().GetUniformValue<Matrix>( "uObjectMatrix", scaleMatrix ) );
1149 //Finish by setting off stage, and ensuring this was successful.
1151 DALI_TEST_EQUALS( actor.GetRendererCount(), 0u, TEST_LOCATION );
1154 //Test if mesh loads correctly when supplied with only the bare minimum requirements, an object file.
1155 int UtcDaliVisualFactoryGetMeshVisual1(void)
1157 //Set up test application first, so everything else can be handled.
1158 ToolkitTestApplication application;
1160 tet_infoline( "UtcDaliVisualFactoryGetMeshVisual1: Request mesh visual with a valid object file only" );
1163 //Set up visual properties.
1164 Property::Map propertyMap;
1165 propertyMap.Insert( Toolkit::Visual::Property::TYPE, Visual::MESH );
1166 propertyMap.Insert( MeshVisual::Property::OBJECT_URL, TEST_OBJ_FILE_NAME );
1168 //Test to see if mesh loads correctly.
1169 MeshVisualLoadsCorrectlyTest( propertyMap, application );
1175 //Test if mesh loads correctly when supplied with an object file as well as a blank material file and images directory.
1176 int UtcDaliVisualFactoryGetMeshVisual2(void)
1178 //Set up test application first, so everything else can be handled.
1179 ToolkitTestApplication application;
1181 tet_infoline( "UtcDaliVisualFactoryGetMeshVisual2: Request mesh visual with blank material file and images directory" );
1183 //Set up visual properties.
1184 Property::Map propertyMap;
1185 propertyMap.Insert( Toolkit::Visual::Property::TYPE, Visual::MESH );
1186 propertyMap.Insert( MeshVisual::Property::OBJECT_URL, TEST_OBJ_FILE_NAME );
1187 propertyMap.Insert( MeshVisual::Property::MATERIAL_URL, "" );
1188 propertyMap.Insert( MeshVisual::Property::TEXTURES_PATH, "" );
1190 //Test to see if mesh loads correctly.
1191 MeshVisualLoadsCorrectlyTest( propertyMap, application );
1196 //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
1197 int UtcDaliVisualFactoryGetMeshVisual3b(void)
1199 //Set up test application first, so everything else can be handled.
1200 ToolkitTestApplication application;
1202 tet_infoline( "UtcDaliVisualFactoryGetMeshVisual3: Request mesh visual with all parameters correct" );
1204 //Set up visual properties.
1205 Property::Map propertyMap;
1206 propertyMap.Insert( Toolkit::Visual::Property::TYPE, Visual::MESH );
1207 propertyMap.Insert( MeshVisual::Property::OBJECT_URL, TEST_OBJ_FILE_NAME );
1208 propertyMap.Insert( MeshVisual::Property::MATERIAL_URL, TEST_MTL_FILE_NAME );
1209 propertyMap.Insert( MeshVisual::Property::USE_MIPMAPPING, Color::GREEN ); // Test that wrong property types don't prevent the object load
1210 propertyMap.Insert( MeshVisual::Property::USE_SOFT_NORMALS, 1.0f );
1211 propertyMap.Insert( MeshVisual::Property::LIGHT_POSITION, 1.0f );
1212 propertyMap.Insert( MeshVisual::Property::TEXTURES_PATH, TEST_RESOURCE_DIR "/" );
1214 //Test to see if mesh loads correctly.
1215 MeshVisualLoadsCorrectlyTest( propertyMap, application );
1220 //Test if mesh loads correctly when supplied with all main parameters, an object file, a material file and a directory location.
1221 int UtcDaliVisualFactoryGetMeshVisual3(void)
1223 //Set up test application first, so everything else can be handled.
1224 ToolkitTestApplication application;
1226 tet_infoline( "UtcDaliVisualFactoryGetMeshVisual3: Request mesh visual with all parameters correct" );
1228 //Set up visual properties.
1229 Property::Map propertyMap;
1230 propertyMap.Insert( Toolkit::Visual::Property::TYPE, Visual::MESH );
1231 propertyMap.Insert( MeshVisual::Property::OBJECT_URL, TEST_OBJ_FILE_NAME );
1232 propertyMap.Insert( MeshVisual::Property::MATERIAL_URL, TEST_MTL_FILE_NAME );
1233 propertyMap.Insert( MeshVisual::Property::USE_MIPMAPPING, false );
1234 propertyMap.Insert( MeshVisual::Property::USE_SOFT_NORMALS, false );
1235 propertyMap.Insert( MeshVisual::Property::LIGHT_POSITION, Vector3::XAXIS );
1236 propertyMap.Insert( MeshVisual::Property::TEXTURES_PATH, TEST_RESOURCE_DIR "/" );
1238 //Test to see if mesh loads correctly.
1239 MeshVisualLoadsCorrectlyTest( propertyMap, application );
1244 //Test if mesh visual can load a correctly supplied mesh without a normal map or gloss map in the material file.
1245 int UtcDaliVisualFactoryGetMeshVisual4(void)
1247 //Set up test application first, so everything else can be handled.
1248 ToolkitTestApplication application;
1250 tet_infoline( "UtcDaliVisualFactoryGetMeshVisual4: Request mesh visual with diffuse texture but not normal or gloss." );
1253 //Set up visual properties.
1254 Property::Map propertyMap;
1255 propertyMap.Insert( Toolkit::Visual::Property::TYPE, Visual::MESH );
1256 propertyMap.Insert( MeshVisual::Property::OBJECT_URL, TEST_OBJ_FILE_NAME );
1257 propertyMap.Insert( MeshVisual::Property::MATERIAL_URL, TEST_SIMPLE_MTL_FILE_NAME );
1258 propertyMap.Insert( MeshVisual::Property::TEXTURES_PATH, TEST_RESOURCE_DIR "/" );
1260 //Test to see if mesh loads correctly.
1261 MeshVisualLoadsCorrectlyTest( propertyMap, application );
1266 //Test if mesh visual can load when made to use diffuse textures only.
1267 int UtcDaliVisualFactoryGetMeshVisual5(void)
1269 //Set up test application first, so everything else can be handled.
1270 ToolkitTestApplication application;
1272 tet_infoline( "UtcDaliVisualFactoryGetMeshVisual5: Request mesh visual and make it only use diffuse textures." );
1274 //Set up visual properties.
1275 Property::Map propertyMap;
1276 propertyMap.Insert( Toolkit::Visual::Property::TYPE, Visual::MESH );
1277 propertyMap.Insert( "objectUrl", TEST_OBJ_FILE_NAME );
1278 propertyMap.Insert( "materialUrl", TEST_MTL_FILE_NAME );
1279 propertyMap.Insert( "texturesPath", TEST_RESOURCE_DIR "/" );
1280 propertyMap.Insert( "useMipmapping", false );
1281 propertyMap.Insert( "useSoftNormals", false );
1282 propertyMap.Insert( "lightPosition", Vector3::ZAXIS );
1283 propertyMap.Insert( "shadingMode", MeshVisual::ShadingMode::TEXTURED_WITH_SPECULAR_LIGHTING );
1285 //Test to see if mesh loads correctly.
1286 MeshVisualLoadsCorrectlyTest( propertyMap, application );
1292 //Test if mesh visual can load when made to not use the supplied textures.
1293 int UtcDaliVisualFactoryGetMeshVisual6(void)
1295 //Set up test application first, so everything else can be handled.
1296 ToolkitTestApplication application;
1298 tet_infoline( "UtcDaliVisualFactoryGetMeshVisual6: Request mesh visual and make it not use any textures." );
1300 //Set up visual properties.
1301 Property::Map propertyMap;
1302 propertyMap.Insert( Toolkit::Visual::Property::TYPE, Visual::MESH );
1303 propertyMap.Insert( MeshVisual::Property::OBJECT_URL, TEST_OBJ_FILE_NAME );
1304 propertyMap.Insert( MeshVisual::Property::MATERIAL_URL, TEST_MTL_FILE_NAME );
1305 propertyMap.Insert( MeshVisual::Property::TEXTURES_PATH, TEST_RESOURCE_DIR "/" );
1306 propertyMap.Insert( MeshVisual::Property::SHADING_MODE, MeshVisual::ShadingMode::TEXTURELESS_WITH_DIFFUSE_LIGHTING );
1308 //Test to see if mesh loads correctly.
1309 MeshVisualLoadsCorrectlyTest( propertyMap, application );
1313 //Test if mesh visual loads correctly when light position is manually set.
1314 int UtcDaliVisualFactoryGetMeshVisual7(void)
1316 //Set up test application first, so everything else can be handled.
1317 ToolkitTestApplication application;
1320 tet_infoline( "UtcDaliVisualFactoryGetMeshVisual7: Request mesh visual with custom light position." );
1322 //Set up visual properties.
1323 Property::Map propertyMap;
1324 propertyMap.Insert( Toolkit::Visual::Property::TYPE, Visual::MESH );
1325 propertyMap.Insert( MeshVisual::Property::OBJECT_URL, TEST_OBJ_FILE_NAME );
1326 propertyMap.Insert( MeshVisual::Property::MATERIAL_URL, TEST_MTL_FILE_NAME );
1327 propertyMap.Insert( MeshVisual::Property::TEXTURES_PATH, TEST_RESOURCE_DIR "/" );
1328 propertyMap.Insert( MeshVisual::Property::LIGHT_POSITION, Vector3( 0.0, 1.0, 2.0 ) );
1330 //Test to see if mesh loads correctly.
1331 MeshVisualLoadsCorrectlyTest( propertyMap, application );
1336 //Test if mesh visual loads correctly when supplied an object file without face normals or texture points.
1337 //Note that this notably tests object loader functionality.
1338 int UtcDaliVisualFactoryGetMeshVisual8(void)
1340 //Set up test application first, so everything else can be handled.
1341 ToolkitTestApplication application;
1343 tet_infoline( "UtcDaliVisualFactoryGetMeshVisual5: Request mesh visual with normal-less object file." );
1345 //Set up visual properties.
1346 Property::Map propertyMap;
1347 propertyMap.Insert( Toolkit::Visual::Property::TYPE, Visual::MESH );
1348 propertyMap.Insert( MeshVisual::Property::OBJECT_URL, TEST_SIMPLE_OBJ_FILE_NAME );
1349 propertyMap.Insert( MeshVisual::Property::MATERIAL_URL, TEST_MTL_FILE_NAME );
1350 propertyMap.Insert( MeshVisual::Property::TEXTURES_PATH, TEST_RESOURCE_DIR "/" );
1352 //Test to see if mesh loads correctly.
1353 MeshVisualLoadsCorrectlyTest( propertyMap, application );
1358 //Test if mesh visual handles the case of lacking an object file.
1359 int UtcDaliVisualFactoryGetMeshVisualN1(void)
1361 //Set up test application first, so everything else can be handled.
1362 ToolkitTestApplication application;
1364 tet_infoline( "UtcDaliVisualFactoryGetMeshVisualN1: Request mesh visual without object file" );
1366 //Set up visual properties.
1367 Property::Map propertyMap;
1368 propertyMap.Insert( Toolkit::Visual::Property::TYPE, Visual::MESH );
1369 propertyMap.Insert( MeshVisual::Property::MATERIAL_URL, TEST_MTL_FILE_NAME );
1370 propertyMap.Insert( MeshVisual::Property::TEXTURES_PATH, TEST_RESOURCE_DIR "/" );
1372 //Test to see if mesh doesn't load with these properties, as expected.
1373 MeshVisualDoesNotLoadCorrectlyTest( propertyMap, application );
1379 //Test if mesh visual handles the case of being passed invalid material and images urls.
1380 int UtcDaliVisualFactoryGetMeshVisualN2(void)
1382 //Set up test application first, so everything else can be handled.
1383 ToolkitTestApplication application;
1385 tet_infoline( "UtcDaliVisualFactoryGetMeshVisualN2: Request mesh visual with invalid material and images urls" );
1387 //Set up visual properties.
1388 Property::Map propertyMap;
1389 propertyMap.Insert( Toolkit::Visual::Property::TYPE, Visual::MESH );
1390 propertyMap.Insert( MeshVisual::Property::OBJECT_URL, TEST_OBJ_FILE_NAME );
1391 propertyMap.Insert( MeshVisual::Property::MATERIAL_URL, "invalid" );
1392 propertyMap.Insert( MeshVisual::Property::TEXTURES_PATH, "also invalid" );
1394 //Test to see if mesh doesn't load with these properties, as expected.
1395 MeshVisualDoesNotLoadCorrectlyTest( propertyMap, application );
1401 //Test if mesh visual handles the case of being passed an invalid object url
1402 int UtcDaliVisualFactoryGetMeshVisualN3(void)
1404 //Set up test application first, so everything else can be handled.
1405 ToolkitTestApplication application;
1406 tet_infoline( "UtcDaliVisualFactoryGetMeshVisualN3: Request mesh visual with invalid object url" );
1409 //Set up visual properties.
1410 Property::Map propertyMap;
1411 propertyMap.Insert( Toolkit::Visual::Property::TYPE, Visual::MESH );
1412 propertyMap.Insert( MeshVisual::Property::OBJECT_URL, "invalid" );
1413 propertyMap.Insert( MeshVisual::Property::MATERIAL_URL, TEST_MTL_FILE_NAME );
1414 propertyMap.Insert( MeshVisual::Property::TEXTURES_PATH, TEST_RESOURCE_DIR "/" );
1416 //Test to see if mesh doesn't load with these properties, as expected.
1417 MeshVisualDoesNotLoadCorrectlyTest( propertyMap, application );
1422 //Creates a primitive visual with the given property map and tests to see if it correctly loads in the given application.
1423 void TestPrimitiveVisualWithProperties( Property::Map& propertyMap, ToolkitTestApplication& application )
1425 VisualFactory factory = VisualFactory::Get();
1426 DALI_TEST_CHECK( factory );
1428 //Create a primitive visual.
1429 Visual::Base visual = factory.CreateVisual( propertyMap );
1430 DALI_TEST_CHECK( visual );
1432 //Create an actor on stage to house the visual.
1433 DummyControl actor = DummyControl::New(true);
1434 DummyControlImpl& dummyImpl = static_cast<DummyControlImpl&>(actor.GetImplementation());
1435 dummyImpl.RegisterVisual( DummyControl::Property::TEST_VISUAL, visual );
1437 actor.SetSize( 200.f, 200.f );
1438 Stage::GetCurrent().Add( actor );
1439 visual.SetTransformAndSize(DefaultTransform(), Vector2( 200.f, 200.f ) );
1441 //Ensure set on stage.
1442 DALI_TEST_EQUALS( actor.GetRendererCount(), 1u, TEST_LOCATION );
1444 //Tell test application to load the visual.
1445 application.SendNotification();
1446 application.Render(0);
1448 Matrix testScaleMatrix;
1449 testScaleMatrix.SetIdentityAndScale( Vector3( 1.0, -1.0, 1.0 ) );
1450 Matrix actualScaleMatrix;
1452 //Test to see if the object has been successfully loaded.
1453 DALI_TEST_CHECK( application.GetGlAbstraction().GetUniformValue<Matrix>( "uObjectMatrix", actualScaleMatrix ) );
1454 DALI_TEST_EQUALS( actualScaleMatrix, testScaleMatrix, Math::MACHINE_EPSILON_100, TEST_LOCATION );
1456 //Finish by setting off stage, and ensuring this was successful.
1458 DALI_TEST_EQUALS( actor.GetRendererCount(), 0u, TEST_LOCATION );
1461 //Test if primitive shape loads correctly when supplied with only the bare minimum requirements, the shape to use.
1462 int UtcDaliVisualFactoryGetPrimitiveVisual1(void)
1464 //Set up test application first, so everything else can be handled.
1465 ToolkitTestApplication application;
1467 tet_infoline( "UtcDaliVisualFactoryGetPrimitiveVisual1: Request primitive visual with a shape only" );
1469 //Set up visual properties.
1470 Property::Map propertyMap;
1471 propertyMap.Insert( Toolkit::Visual::Property::TYPE, Visual::PRIMITIVE );
1472 propertyMap.Insert( PrimitiveVisual::Property::SHAPE, PrimitiveVisual::Shape::CUBE );
1474 //Test to see if shape loads correctly.
1475 TestPrimitiveVisualWithProperties( propertyMap, application );
1480 //Test if primitive shape loads correctly when supplied with all possible parameters
1481 int UtcDaliVisualFactoryGetPrimitiveVisual2(void)
1483 //Set up test application first, so everything else can be handled.
1484 ToolkitTestApplication application;
1486 tet_infoline( "UtcDaliVisualFactoryGetPrimitiveVisual2: Request primitive visual with everything" );
1488 //Set up visual properties.
1489 Property::Map propertyMap;
1490 propertyMap.Insert( Toolkit::Visual::Property::TYPE, Visual::PRIMITIVE );
1491 propertyMap.Insert( PrimitiveVisual::Property::SHAPE, PrimitiveVisual::Shape::CUBE );
1492 propertyMap.Insert( PrimitiveVisual::Property::MIX_COLOR, Vector4( 0.5, 0.5, 0.5, 1.0 ) );
1493 propertyMap.Insert( PrimitiveVisual::Property::SLICES, 10 );
1494 propertyMap.Insert( PrimitiveVisual::Property::STACKS, 20 );
1495 propertyMap.Insert( PrimitiveVisual::Property::SCALE_TOP_RADIUS, 30.0f );
1496 propertyMap.Insert( PrimitiveVisual::Property::SCALE_BOTTOM_RADIUS, 40.0f );
1497 propertyMap.Insert( PrimitiveVisual::Property::SCALE_HEIGHT, 50.0f );
1498 propertyMap.Insert( PrimitiveVisual::Property::SCALE_RADIUS, 60.0f );
1499 propertyMap.Insert( PrimitiveVisual::Property::BEVEL_PERCENTAGE, 0.7f );
1500 propertyMap.Insert( PrimitiveVisual::Property::BEVEL_SMOOTHNESS, 0.8f );
1501 propertyMap.Insert( MeshVisual::Property::LIGHT_POSITION, Vector3( 0.9, 1.0, 1.1 ) );
1503 //Test to see if shape loads correctly.
1504 TestPrimitiveVisualWithProperties( propertyMap, application );
1509 //Test if primitive shape loads a sphere correctly.
1510 int UtcDaliVisualFactoryGetPrimitiveVisual3(void)
1512 //Set up test application first, so everything else can be handled.
1513 ToolkitTestApplication application;
1515 tet_infoline( "UtcDaliVisualFactoryGetPrimitiveVisual3: Request primitive visual to display a sphere" );
1517 //Set up visual properties.
1518 Property::Map propertyMap;
1519 propertyMap.Insert( Toolkit::Visual::Property::TYPE, Visual::PRIMITIVE );
1520 propertyMap.Insert( PrimitiveVisual::Property::SHAPE, PrimitiveVisual::Shape::SPHERE );
1521 propertyMap.Insert( PrimitiveVisual::Property::MIX_COLOR, Vector4( 0.5, 0.5, 0.5, 1.0 ) );
1522 propertyMap.Insert( PrimitiveVisual::Property::SLICES, 10 );
1523 propertyMap.Insert( PrimitiveVisual::Property::STACKS, 20 );
1525 //Test to see if shape loads correctly.
1526 TestPrimitiveVisualWithProperties( propertyMap, application );
1531 //Test if primitive shape loads a conic section correctly.
1532 int UtcDaliVisualFactoryGetPrimitiveVisual4(void)
1534 //Set up test application first, so everything else can be handled.
1535 ToolkitTestApplication application;
1537 tet_infoline( "UtcDaliVisualFactoryGetPrimitiveVisual4: Request primitive visual to display a conic section" );
1539 //Set up visual properties.
1540 Property::Map propertyMap;
1541 propertyMap.Insert( Toolkit::Visual::Property::TYPE, Visual::PRIMITIVE );
1542 propertyMap.Insert( PrimitiveVisual::Property::SHAPE, PrimitiveVisual::Shape::CONICAL_FRUSTRUM );
1543 propertyMap.Insert( PrimitiveVisual::Property::MIX_COLOR, Vector4( 0.5, 0.5, 0.5, 1.0 ) );
1544 propertyMap.Insert( PrimitiveVisual::Property::SLICES, 10 );
1545 propertyMap.Insert( PrimitiveVisual::Property::SCALE_TOP_RADIUS, 30.0f );
1546 propertyMap.Insert( PrimitiveVisual::Property::SCALE_BOTTOM_RADIUS, 40.0f );
1547 propertyMap.Insert( PrimitiveVisual::Property::SCALE_HEIGHT, 50.0f );
1549 //Test to see if shape loads correctly.
1550 TestPrimitiveVisualWithProperties( propertyMap, application );
1555 //Test if primitive shape loads a bevelled cube correctly.
1556 int UtcDaliVisualFactoryGetPrimitiveVisual5(void)
1558 //Set up test application first, so everything else can be handled.
1559 ToolkitTestApplication application;
1561 tet_infoline( "UtcDaliVisualFactoryGetPrimitiveVisual5: Request primitive visual to display a bevelled cube" );
1563 //Set up visual properties.
1564 Property::Map propertyMap;
1565 propertyMap.Insert( Toolkit::Visual::Property::TYPE, Visual::PRIMITIVE );
1566 propertyMap.Insert( PrimitiveVisual::Property::SHAPE, PrimitiveVisual::Shape::BEVELLED_CUBE );
1567 propertyMap.Insert( PrimitiveVisual::Property::MIX_COLOR, Vector4( 0.5, 0.5, 0.5, 1.0 ) );
1568 propertyMap.Insert( PrimitiveVisual::Property::BEVEL_PERCENTAGE, 0.7f );
1570 //Test to see if shape loads correctly.
1571 TestPrimitiveVisualWithProperties( propertyMap, application );
1576 //Test if primitive shape loads an octahedron correctly.
1577 int UtcDaliVisualFactoryGetPrimitiveVisual6(void)
1579 //Set up test application first, so everything else can be handled.
1580 ToolkitTestApplication application;
1582 tet_infoline( "UtcDaliVisualFactoryGetPrimitiveVisual6: Request primitive visual to display an octahedron" );
1584 //Set up visual properties.
1585 Property::Map propertyMap;
1586 propertyMap.Insert( Toolkit::Visual::Property::TYPE, Visual::PRIMITIVE );
1587 propertyMap.Insert( PrimitiveVisual::Property::SHAPE, PrimitiveVisual::Shape::OCTAHEDRON );
1588 propertyMap.Insert( PrimitiveVisual::Property::MIX_COLOR, Vector4( 0.5, 0.5, 0.5, 1.0 ) );
1590 //Test to see if shape loads correctly.
1591 TestPrimitiveVisualWithProperties( propertyMap, application );
1596 //Test if primitive shape loads a cone correctly.
1597 int UtcDaliVisualFactoryGetPrimitiveVisual7(void)
1599 //Set up test application first, so everything else can be handled.
1600 ToolkitTestApplication application;
1602 tet_infoline( "UtcDaliVisualFactoryGetPrimitiveVisual7: Request primitive visual to display a cone" );
1604 //Set up visual properties.
1605 Property::Map propertyMap;
1606 propertyMap.Insert( Toolkit::Visual::Property::TYPE, Visual::PRIMITIVE );
1607 propertyMap.Insert( PrimitiveVisual::Property::SHAPE, PrimitiveVisual::Shape::CONE );
1608 propertyMap.Insert( PrimitiveVisual::Property::MIX_COLOR, Vector4( 0.5, 0.5, 0.5, 1.0 ) );
1609 propertyMap.Insert( PrimitiveVisual::Property::SLICES, 10 );
1610 propertyMap.Insert( PrimitiveVisual::Property::SCALE_TOP_RADIUS, 30.0f );
1611 propertyMap.Insert( PrimitiveVisual::Property::SCALE_HEIGHT, 50.0f );
1613 //Test to see if shape loads correctly.
1614 TestPrimitiveVisualWithProperties( propertyMap, application );
1619 //Test if primitive shape loads correctly when light position is manually set.
1620 int UtcDaliVisualFactoryGetPrimitiveVisual8(void)
1622 //Set up test application first, so everything else can be handled.
1623 ToolkitTestApplication application;
1625 tet_infoline( "UtcDaliVisualFactoryGetPrimitiveVisual8: Request primitive visual with set light position" );
1627 //Set up visual properties.
1628 Property::Map propertyMap;
1629 propertyMap.Insert( Toolkit::Visual::Property::TYPE, Visual::PRIMITIVE );
1630 propertyMap.Insert( PrimitiveVisual::Property::SHAPE, PrimitiveVisual::Shape::SPHERE );
1631 propertyMap.Insert( PrimitiveVisual::Property::MIX_COLOR, Vector4( 0.5, 0.5, 0.5, 1.0 ) );
1632 propertyMap.Insert( MeshVisual::Property::LIGHT_POSITION, Vector3( 0.0, 1.0, 2.0 ) );
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 slices.
1641 int UtcDaliVisualFactoryGetPrimitiveVisual9(void)
1643 //Set up test application first, so everything else can be handled.
1644 ToolkitTestApplication application;
1646 tet_infoline( "UtcDaliVisualFactoryGetPrimitiveVisual9: Request primitive visual with above-cap slices." );
1648 //Set up visual properties.
1649 Property::Map propertyMap;
1650 propertyMap.Insert( Toolkit::Visual::Property::TYPE, Visual::PRIMITIVE );
1651 propertyMap.Insert( PrimitiveVisual::Property::SHAPE, PrimitiveVisual::Shape::SPHERE );
1652 propertyMap.Insert( PrimitiveVisual::Property::SLICES, 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 slices. (2 slices or less.)
1661 int UtcDaliVisualFactoryGetPrimitiveVisual10(void)
1663 //Set up test application first, so everything else can be handled.
1664 ToolkitTestApplication application;
1666 tet_infoline( "UtcDaliVisualFactoryGetPrimitiveVisual10: Request primitive visual with too few slices." );
1668 //Set up visual properties.
1669 Property::Map propertyMap;
1670 propertyMap.Insert( Toolkit::Visual::Property::TYPE, Visual::PRIMITIVE );
1671 propertyMap.Insert( PrimitiveVisual::Property::SHAPE, PrimitiveVisual::Shape::SPHERE );
1672 propertyMap.Insert( PrimitiveVisual::Property::SLICES, Property::Value( 2 ) );
1674 //Test to see if shape loads correctly.
1675 TestPrimitiveVisualWithProperties( propertyMap, application );
1680 //Test if primitive shape loads correctly when told to use too many stacks.
1681 int UtcDaliVisualFactoryGetPrimitiveVisual11(void)
1683 //Set up test application first, so everything else can be handled.
1684 ToolkitTestApplication application;
1686 tet_infoline( "UtcDaliVisualFactoryGetPrimitiveVisual11: Request primitive visual with too many stacks." );
1688 //Set up visual properties.
1689 Property::Map propertyMap;
1690 propertyMap.Insert( Toolkit::Visual::Property::TYPE, Visual::PRIMITIVE );
1691 propertyMap.Insert( PrimitiveVisual::Property::SHAPE, PrimitiveVisual::Shape::SPHERE );
1692 propertyMap.Insert( PrimitiveVisual::Property::STACKS, Property::Value( 1000000 ) );
1694 //Test to see if shape loads correctly.
1695 TestPrimitiveVisualWithProperties( propertyMap, application );
1700 //Test if primitive shape loads correctly when told to use too few stacks. (1 stack or less.)
1701 int UtcDaliVisualFactoryGetPrimitiveVisual12(void)
1703 //Set up test application first, so everything else can be handled.
1704 ToolkitTestApplication application;
1706 tet_infoline( "UtcDaliVisualFactoryGetPrimitiveVisual12: Request primitive visual with too few stacks." );
1708 //Set up visual properties.
1709 Property::Map propertyMap;
1710 propertyMap.Insert( Toolkit::Visual::Property::TYPE, Visual::PRIMITIVE );
1711 propertyMap.Insert( PrimitiveVisual::Property::SHAPE, PrimitiveVisual::Shape::SPHERE );
1712 propertyMap.Insert( PrimitiveVisual::Property::STACKS, Property::Value( 1 ) );
1714 //Test to see if shape loads correctly.
1715 TestPrimitiveVisualWithProperties( propertyMap, application );
1720 //Test if primitive shape loads correctly when told to use invalid (zero or negative) dimensions.
1721 int UtcDaliVisualFactoryGetPrimitiveVisual13(void)
1723 //Set up test application first, so everything else can be handled.
1724 ToolkitTestApplication application;
1726 tet_infoline( "UtcDaliVisualFactoryGetPrimitiveVisual13: Request primitive visual with invalid scale dimensions." );
1728 //Set up visual properties.
1729 Property::Map propertyMap;
1730 propertyMap.Insert( Toolkit::Visual::Property::TYPE, Visual::PRIMITIVE );
1731 propertyMap.Insert( PrimitiveVisual::Property::SHAPE, PrimitiveVisual::Shape::SPHERE );
1732 propertyMap.Insert( PrimitiveVisual::Property::SCALE_DIMENSIONS, Vector3::ZERO );
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 percentage.
1741 int UtcDaliVisualFactoryGetPrimitiveVisual14(void)
1743 //Set up test application first, so everything else can be handled.
1744 ToolkitTestApplication application;
1746 tet_infoline( "UtcDaliVisualFactoryGetPrimitiveVisual14: Request primitive visual with too low a bevel percentage." );
1748 //Set up visual properties.
1749 Property::Map propertyMap;
1750 propertyMap.Insert( Toolkit::Visual::Property::TYPE, Visual::PRIMITIVE );
1751 propertyMap.Insert( PrimitiveVisual::Property::SHAPE, PrimitiveVisual::Shape::SPHERE );
1752 propertyMap.Insert( PrimitiveVisual::Property::BEVEL_PERCENTAGE, 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 percentage.
1761 int UtcDaliVisualFactoryGetPrimitiveVisual15(void)
1763 //Set up test application first, so everything else can be handled.
1764 ToolkitTestApplication application;
1766 tet_infoline( "UtcDaliVisualFactoryGetPrimitiveVisual15: Request primitive visual with too high a bevel percentage." );
1768 //Set up visual properties.
1769 Property::Map propertyMap;
1770 propertyMap.Insert( Toolkit::Visual::Property::TYPE, Visual::PRIMITIVE );
1771 propertyMap.Insert( PrimitiveVisual::Property::SHAPE, PrimitiveVisual::Shape::SPHERE );
1772 propertyMap.Insert( PrimitiveVisual::Property::BEVEL_PERCENTAGE, Property::Value( 2.0f ) );
1774 //Test to see if shape loads correctly.
1775 TestPrimitiveVisualWithProperties( propertyMap, application );
1780 //Test if primitive shape loads correctly when told to use too low a bevel smoothness.
1781 int UtcDaliVisualFactoryGetPrimitiveVisual16(void)
1783 //Set up test application first, so everything else can be handled.
1784 ToolkitTestApplication application;
1786 tet_infoline( "UtcDaliVisualFactoryGetPrimitiveVisual16: Request primitive visual with too low a bevel smoothness." );
1788 //Set up visual properties.
1789 Property::Map propertyMap;
1790 propertyMap.Insert( Toolkit::Visual::Property::TYPE, Visual::PRIMITIVE );
1791 propertyMap.Insert( PrimitiveVisual::Property::SHAPE, PrimitiveVisual::Shape::SPHERE );
1792 propertyMap.Insert( PrimitiveVisual::Property::BEVEL_SMOOTHNESS, Property::Value( -1.0f ) );
1794 //Test to see if shape loads correctly.
1795 TestPrimitiveVisualWithProperties( propertyMap, application );
1800 //Test if primitive shape loads correctly when told to use too high a bevel smoothness.
1801 int UtcDaliVisualFactoryGetPrimitiveVisual17(void)
1803 //Set up test application first, so everything else can be handled.
1804 ToolkitTestApplication application;
1806 tet_infoline( "UtcDaliVisualFactoryGetPrimitiveVisual17: Request primitive visual with too high a bevel smoothness." );
1808 //Set up visual properties.
1809 Property::Map propertyMap;
1810 propertyMap.Insert( Toolkit::Visual::Property::TYPE, Visual::PRIMITIVE );
1811 propertyMap.Insert( PrimitiveVisual::Property::SHAPE, PrimitiveVisual::Shape::SPHERE );
1812 propertyMap.Insert( PrimitiveVisual::Property::BEVEL_SMOOTHNESS, Property::Value( 2.0f ) );
1814 //Test to see if shape loads correctly.
1815 TestPrimitiveVisualWithProperties( propertyMap, application );
1820 //Test if primitive shape visual handles the case of not being passed a specific shape to use.
1821 int UtcDaliVisualFactoryGetPrimitiveVisualN1(void)
1823 //Set up test application first, so everything else can be handled.
1824 ToolkitTestApplication application;
1826 tet_infoline( "UtcDaliVisualFactoryGetPrimitiveVisualN1: Request primitive visual without shape" );
1828 //Set up visual properties, without supplying shape.
1829 Property::Map propertyMap;
1830 propertyMap.Insert( Toolkit::Visual::Property::TYPE, Visual::PRIMITIVE );
1832 //Test to see if shape loads regardless of missing input.
1833 TestPrimitiveVisualWithProperties( propertyMap, application );
1838 int UtcDaliVisualFactoryGetAnimatedImageVisual1(void)
1840 ToolkitTestApplication application;
1841 tet_infoline( "UtcDaliVisualFactoryGetAnimatedImageVisual1: Request animated image visual with a gif url" );
1843 VisualFactory factory = VisualFactory::Get();
1844 Visual::Base visual = factory.CreateVisual( TEST_GIF_FILE_NAME, ImageDimensions() );
1845 DALI_TEST_CHECK( visual );
1847 TestGlAbstraction& gl = application.GetGlAbstraction();
1848 TraceCallStack& textureTrace = gl.GetTextureTrace();
1849 textureTrace.Enable(true);
1851 DummyControl actor = DummyControl::New(true);
1852 DummyControlImpl& dummyImpl = static_cast<DummyControlImpl&>(actor.GetImplementation());
1853 dummyImpl.RegisterVisual( DummyControl::Property::TEST_VISUAL, visual );
1854 actor.SetSize( 200.0f, 200.0f );
1855 Stage::GetCurrent().Add( actor );
1857 application.SendNotification();
1858 application.Render();
1860 // renderer is added to actor
1861 DALI_TEST_CHECK( actor.GetRendererCount() == 1u );
1863 // test the uniforms which used to handle the atlas rect
1864 // the four frames should be located inside atlas as follows: atlas size 100*100
1873 Renderer renderer = actor.GetRendererAt( 0u );
1874 DALI_TEST_CHECK( renderer );
1876 Property::Value atlasRectValue = renderer.GetProperty( renderer.GetPropertyIndex( "uAtlasRect" ) );
1877 // take into consideration the half pixel correction
1878 DALI_TEST_EQUALS( atlasRectValue.Get<Vector4>(), Vector4(0.5f, 0.5f, 49.5f, 49.5f)/100.f, Math::MACHINE_EPSILON_100, TEST_LOCATION );
1880 // waiting for the resource uploading
1881 application.SendNotification();
1882 application.Render();
1884 DALI_TEST_EQUALS( textureTrace.FindMethod("BindTexture"), true, TEST_LOCATION );
1886 // Force the timer used by the animatedImageVisual to tick,
1887 Dali::Timer timer = Timer::New( 0 );
1888 timer.MockEmitSignal();
1889 application.SendNotification();
1890 application.Render();
1891 atlasRectValue = renderer.GetProperty( renderer.GetPropertyIndex( "uAtlasRect" ) );
1892 // take into consideration the half pixel correction
1893 DALI_TEST_EQUALS( atlasRectValue.Get<Vector4>(), Vector4(50.5f, 0.5f, 99.5f, 49.5f)/100.f, Math::MACHINE_EPSILON_100, TEST_LOCATION );
1895 // Force the timer used by the animatedImageVisual to tick,
1896 timer.MockEmitSignal();
1897 application.SendNotification();
1898 application.Render();
1899 atlasRectValue = renderer.GetProperty( renderer.GetPropertyIndex( "uAtlasRect" ) );
1900 // take into consideration the half pixel correction
1901 DALI_TEST_EQUALS( atlasRectValue.Get<Vector4>(), Vector4(0.5f, 50.5f, 49.5f, 99.5f)/100.f, Math::MACHINE_EPSILON_100, TEST_LOCATION );
1903 // Force the timer used by the animatedImageVisual to tick,
1904 timer.MockEmitSignal();
1905 application.SendNotification();
1906 application.Render();
1907 atlasRectValue = renderer.GetProperty( renderer.GetPropertyIndex( "uAtlasRect" ) );
1908 // take into consideration the half pixel correction
1909 DALI_TEST_EQUALS( atlasRectValue.Get<Vector4>(), Vector4(50.5f, 50.5f, 99.5f, 99.5f)/100.f, Math::MACHINE_EPSILON_100, TEST_LOCATION );
1911 // Test SetOffStage().
1913 DALI_TEST_CHECK( actor.GetRendererCount() == 0u );
1918 int UtcDaliVisualFactoryGetAnimatedImageVisual2(void)
1920 ToolkitTestApplication application;
1921 tet_infoline( "UtcDaliVisualFactoryGetAnimatedImageVisual2: Request animated image visual with a Property::Map, test custom wrap mode and pixel area" );
1923 const Vector4 pixelArea(-0.5f, -0.5f, 2.f, 2.f);
1924 Property::Map propertyMap;
1925 propertyMap.Add( Toolkit::Visual::Property::TYPE, Visual::IMAGE )
1926 .Add( ImageVisual::Property::URL, TEST_GIF_FILE_NAME )
1927 .Add( ImageVisual::Property::PIXEL_AREA, pixelArea )
1928 .Add( ImageVisual::Property::WRAP_MODE_U, WrapMode::MIRRORED_REPEAT )
1929 .Add( ImageVisual::Property::WRAP_MODE_V, WrapMode::REPEAT );
1931 Visual::Base visual = VisualFactory::Get().CreateVisual( propertyMap );
1932 DALI_TEST_CHECK( visual );
1934 TestGlAbstraction& gl = application.GetGlAbstraction();
1935 TraceCallStack& textureTrace = gl.GetTextureTrace();
1936 textureTrace.Enable(true);
1937 TraceCallStack& texParameterTrace = gl.GetTexParameterTrace();
1938 texParameterTrace.Enable( true );
1940 DummyControl actor = DummyControl::New(true);
1941 DummyControlImpl& dummyImpl = static_cast<DummyControlImpl&>(actor.GetImplementation());
1942 dummyImpl.RegisterVisual( Control::CONTROL_PROPERTY_END_INDEX + 1, visual );
1943 actor.SetSize( 200.0f, 200.0f );
1944 Stage::GetCurrent().Add( actor );
1946 application.SendNotification();
1947 application.Render();
1949 DALI_TEST_CHECK( actor.GetRendererCount() == 1u );
1951 DALI_TEST_EQUALS( textureTrace.FindMethod("BindTexture"), true, TEST_LOCATION );
1953 // For animated image visual, the wrapping is handled manually in shader, so the following gl function should not be called
1954 std::stringstream out;
1955 out << GL_TEXTURE_2D << ", " << GL_TEXTURE_WRAP_S << ", " << GL_MIRRORED_REPEAT;
1956 DALI_TEST_CHECK( !texParameterTrace.FindMethodAndParams("TexParameteri", out.str()) );
1958 out << GL_TEXTURE_2D << ", " << GL_TEXTURE_WRAP_T << ", " << GL_REPEAT;
1959 DALI_TEST_CHECK( !texParameterTrace.FindMethodAndParams("TexParameteri", out.str()) );
1961 // test the uniforms which used to handle the wrap mode
1962 Renderer renderer = actor.GetRendererAt( 0u );
1963 DALI_TEST_CHECK( renderer );
1965 Property::Value pixelAreaValue = renderer.GetProperty( renderer.GetPropertyIndex( "pixelArea" ) );
1966 DALI_TEST_EQUALS( pixelAreaValue.Get<Vector4>(), pixelArea, TEST_LOCATION );
1967 Vector4 pixelAreaUniform;
1968 DALI_TEST_CHECK( gl.GetUniformValue<Vector4>( "pixelArea", pixelAreaUniform ) );
1969 DALI_TEST_EQUALS( pixelArea, pixelAreaUniform, Math::MACHINE_EPSILON_100, TEST_LOCATION );
1971 Property::Value wrapModeValue = renderer.GetProperty( renderer.GetPropertyIndex( "wrapMode" ) );
1972 Vector2 wrapMode( WrapMode::MIRRORED_REPEAT-1, WrapMode::REPEAT-1 );
1973 DALI_TEST_EQUALS( wrapModeValue.Get<Vector2>(), wrapMode, TEST_LOCATION );
1974 Vector2 wrapModeUniform;
1975 DALI_TEST_CHECK( gl.GetUniformValue<Vector2>( "wrapMode", wrapModeUniform ) );
1976 DALI_TEST_EQUALS( wrapMode, wrapModeUniform, Math::MACHINE_EPSILON_100, TEST_LOCATION );
1979 DALI_TEST_CHECK( actor.GetRendererCount() == 0u );