2 * Copyright (c) 2017 Samsung Electronics Co., Ltd.
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
8 * http://www.apache.org/licenses/LICENSE-2.0
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
19 #include <dali-toolkit-test-suite-utils.h>
20 #include <toolkit-timer.h>
21 #include <toolkit-bitmap-loader.h>
22 #include <toolkit-event-thread-callback.h>
23 #include <dali/public-api/rendering/renderer.h>
24 #include <dali/public-api/rendering/texture-set.h>
25 #include <dali/public-api/rendering/shader.h>
26 #include <dali/devel-api/images/nine-patch-image.h>
27 #include <dali-toolkit/devel-api/align-enums.h>
28 #include <dali-toolkit/devel-api/visuals/visual-properties-devel.h>
29 #include <dali-toolkit/devel-api/visuals/image-visual-properties-devel.h>
30 #include <dali-toolkit/devel-api/visual-factory/visual-factory.h>
31 #include <dali-toolkit/dali-toolkit.h>
32 #include "dummy-control.h"
35 using namespace Dali::Toolkit;
39 typedef NinePatchImage::StretchRanges StretchRanges;
41 const char* TEST_NPATCH_FILE_NAME = TEST_RESOURCE_DIR "/button-up-1.9.png";
42 const char* TEST_SVG_FILE_NAME = TEST_RESOURCE_DIR "/svg1.svg";
43 const char* TEST_OBJ_FILE_NAME = TEST_RESOURCE_DIR "/Cube.obj";
44 const char* TEST_MTL_FILE_NAME = TEST_RESOURCE_DIR "/ToyRobot-Metal.mtl";
45 const char* TEST_SIMPLE_OBJ_FILE_NAME = TEST_RESOURCE_DIR "/Cube-Points-Only.obj";
46 const char* TEST_SIMPLE_MTL_FILE_NAME = TEST_RESOURCE_DIR "/ToyRobot-Metal-Simple.mtl";
48 // resolution: 50*50, frame count: 4, frame delay: 0.2 second for each frame
49 const char* TEST_GIF_FILE_NAME = TEST_RESOURCE_DIR "/anim.gif";
51 // resolution: 34*34, pixel format: RGBA8888
52 static const char* gImage_34_RGBA = TEST_RESOURCE_DIR "/icon-edit.png";
55 Property::Map DefaultTransform()
57 Property::Map transformMap;
59 .Add( Toolkit::DevelVisual::Transform::Property::OFFSET, Vector2(0.0f, 0.0f) )
60 .Add( Toolkit::DevelVisual::Transform::Property::SIZE, Vector2(1.0f, 1.0f) )
61 .Add( Toolkit::DevelVisual::Transform::Property::ORIGIN, Toolkit::Align::CENTER )
62 .Add( Toolkit::DevelVisual::Transform::Property::ANCHOR_POINT, Toolkit::Align::CENTER )
63 .Add( Toolkit::DevelVisual::Transform::Property::OFFSET_POLICY, Vector2( Toolkit::DevelVisual::Transform::Policy::RELATIVE, Toolkit::DevelVisual::Transform::Policy::RELATIVE ) )
64 .Add( Toolkit::DevelVisual::Transform::Property::SIZE_POLICY, Vector2( Toolkit::DevelVisual::Transform::Policy::RELATIVE, Toolkit::DevelVisual::Transform::Policy::RELATIVE ) );
68 Integration::Bitmap* CreateBitmap( unsigned int imageWidth, unsigned int imageHeight, unsigned int initialColor, Pixel::Format pixelFormat )
70 Integration::Bitmap* bitmap = Integration::Bitmap::New( Integration::Bitmap::BITMAP_2D_PACKED_PIXELS, ResourcePolicy::OWNED_RETAIN );
71 Integration::PixelBuffer* pixbuffer = bitmap->GetPackedPixelsProfile()->ReserveBuffer( pixelFormat, imageWidth, imageHeight, imageWidth, imageHeight );
72 unsigned int bytesPerPixel = GetBytesPerPixel( pixelFormat );
74 memset( pixbuffer, initialColor, imageHeight * imageWidth * bytesPerPixel );
79 void InitialiseRegionsToZeroAlpha( Integration::Bitmap* image, unsigned int imageWidth, unsigned int imageHeight, Pixel::Format pixelFormat )
81 PixelBuffer* pixbuffer = image->GetBuffer();
82 unsigned int bytesPerPixel = GetBytesPerPixel( pixelFormat );
84 for( unsigned int row = 0; row < imageWidth; ++row )
86 unsigned int pixelOffset = row * bytesPerPixel;
87 pixbuffer[ pixelOffset + 3 ] = 0x00;
88 pixelOffset += ( imageHeight - 1 ) * imageWidth * bytesPerPixel;
89 pixbuffer[ pixelOffset + 3 ] = 0x00;
92 for ( unsigned int column = 0; column < imageHeight; ++column )
94 unsigned int pixelOffset = column * imageWidth * bytesPerPixel;
95 pixbuffer[ pixelOffset + 3 ] = 0x00;
96 pixelOffset += ( imageWidth -1 ) * bytesPerPixel;
97 pixbuffer[ pixelOffset + 3 ] = 0x00;
101 void AddStretchRegionsToImage( Integration::Bitmap* image, unsigned int imageWidth, unsigned int imageHeight, const StretchRanges& stretchRangesX, const StretchRanges& stretchRangesY, Pixel::Format pixelFormat )
103 PixelBuffer* pixbuffer = image->GetBuffer();
104 unsigned int bytesPerPixel = GetBytesPerPixel( pixelFormat );
106 for(StretchRanges::ConstIterator it = stretchRangesX.Begin(); it != stretchRangesX.End(); ++it)
108 const Uint16Pair& range = *it;
109 //since the stretch range is in the cropped image space, we need to offset by 1 to get it to the uncropped image space
110 for( unsigned int column = range.GetX() + 1u; column < range.GetY() + 1u; ++column )
112 unsigned int pixelOffset = column * bytesPerPixel;
113 pixbuffer[ pixelOffset ] = 0x00;
114 pixbuffer[ pixelOffset + 1 ] = 0x00;
115 pixbuffer[ pixelOffset + 2 ] = 0x00;
116 pixbuffer[ pixelOffset + 3 ] = 0xFF;
121 for(StretchRanges::ConstIterator it = stretchRangesY.Begin(); it != stretchRangesY.End(); ++it)
123 const Uint16Pair& range = *it;
124 //since the stretch range is in the cropped image space, we need to offset by 1 to get it to the uncropped image space
125 for( unsigned int row = range.GetX() + 1u; row < range.GetY() + 1u; ++row )
127 unsigned int pixelOffset = row * imageWidth * bytesPerPixel;
128 pixbuffer[ pixelOffset ] = 0x00;
129 pixbuffer[ pixelOffset + 1 ] = 0x00;
130 pixbuffer[ pixelOffset + 2 ] = 0x00;
131 pixbuffer[ pixelOffset + 3 ] = 0xFF;
136 void AddChildRegionsToImage( Integration::Bitmap* image, unsigned int imageWidth, unsigned int imageHeight, const Vector4& requiredChildRegion, Pixel::Format pixelFormat )
138 PixelBuffer* pixbuffer = image->GetBuffer();
139 unsigned int bytesPerPixel = GetBytesPerPixel( pixelFormat );
141 Integration::Bitmap::PackedPixelsProfile* srcProfile = image->GetPackedPixelsProfile();
142 unsigned int bufferStride = srcProfile->GetBufferStride();
144 // Add bottom child region
145 for( unsigned int column = requiredChildRegion.x; column < imageWidth - requiredChildRegion.z; ++column )
147 unsigned int pixelOffset = column * bytesPerPixel;
148 pixelOffset += ( imageHeight - 1 ) * bufferStride;
149 pixbuffer[ pixelOffset ] = 0x00;
150 pixbuffer[ pixelOffset + 1 ] = 0x00;
151 pixbuffer[ pixelOffset + 2 ] = 0x00;
152 pixbuffer[ pixelOffset + 3 ] = 0xFF;
155 // Add right child region
156 for ( unsigned int row = requiredChildRegion.y; row < imageHeight - requiredChildRegion.w; ++row )
158 unsigned int pixelOffset = row * bufferStride + ( imageWidth - 1 ) * bytesPerPixel;
159 pixbuffer[ pixelOffset ] = 0x00;
160 pixbuffer[ pixelOffset + 1 ] = 0x00;
161 pixbuffer[ pixelOffset + 2 ] = 0x00;
162 pixbuffer[ pixelOffset + 3 ] = 0xFF;
166 Integration::ResourcePointer CustomizeNinePatch( TestApplication& application,
167 unsigned int ninePatchImageWidth,
168 unsigned int ninePatchImageHeight,
169 const StretchRanges& stretchRangesX,
170 const StretchRanges& stretchRangesY,
171 bool addChildRegion = false,
172 Vector4 requiredChildRegion = Vector4::ZERO )
174 TestPlatformAbstraction& platform = application.GetPlatform();
176 Pixel::Format pixelFormat = Pixel::RGBA8888;
178 tet_infoline("Create Bitmap");
179 platform.SetClosestImageSize(Vector2( ninePatchImageWidth, ninePatchImageHeight));
180 Integration::Bitmap* bitmap = CreateBitmap( ninePatchImageWidth, ninePatchImageHeight, 0xFF, pixelFormat );
182 tet_infoline("Clear border regions");
183 InitialiseRegionsToZeroAlpha( bitmap, ninePatchImageWidth, ninePatchImageHeight, pixelFormat );
185 tet_infoline("Add Stretch regions to Bitmap");
186 AddStretchRegionsToImage( bitmap, ninePatchImageWidth, ninePatchImageHeight, stretchRangesX, stretchRangesY, pixelFormat );
190 tet_infoline("Add Child regions to Bitmap");
191 AddChildRegionsToImage( bitmap, ninePatchImageWidth, ninePatchImageHeight, requiredChildRegion, pixelFormat );
194 tet_infoline("Getting resource");
195 Integration::ResourcePointer resourcePtr(bitmap);
196 //platform.SetResourceLoaded( 0, Dali::Integration::ResourceBitmap, resourcePtr );
197 platform.SetSynchronouslyLoadedResource( resourcePtr);
202 void TestVisualRender( ToolkitTestApplication& application,
204 Visual::Base& visual,
205 std::size_t expectedSamplers = 0,
206 ImageDimensions imageDimensions = ImageDimensions(),
207 Integration::ResourcePointer resourcePtr = Integration::ResourcePointer())
209 DummyControlImpl& dummyImpl = static_cast<DummyControlImpl&>(actor.GetImplementation());
210 dummyImpl.RegisterVisual( Control::CONTROL_PROPERTY_END_INDEX + 1, visual );
214 // set the image size, for test case, this needs to be set before loading started
215 application.GetPlatform().SetClosestImageSize( Vector2(imageDimensions.GetWidth(), imageDimensions.GetHeight()) );
218 actor.SetSize( 200.f, 200.f );
219 DALI_TEST_EQUALS( actor.GetRendererCount(), 0u, TEST_LOCATION );
221 Stage::GetCurrent().Add( actor );
223 application.SendNotification();
224 application.Render();
226 application.Render();
227 application.SendNotification();
231 DALI_TEST_EQUALS( application.GetPlatform().WasCalled(TestPlatformAbstraction::LoadResourceSynchronouslyFunc ), true, TEST_LOCATION);
234 DALI_TEST_EQUALS( actor.GetRendererCount(), 1u, TEST_LOCATION );
241 void dali_visual_factory_startup(void)
243 test_return_value = TET_UNDEF;
246 void dali_visual_factory_cleanup(void)
248 test_return_value = TET_PASS;
251 int UtcDaliVisualFactoryGet(void)
253 ToolkitTestApplication application;
254 tet_infoline( "UtcDaliVisualFactory" );
258 type = TypeRegistry::Get().GetTypeInfo( "VisualFactory" );
259 DALI_TEST_CHECK( type );
260 BaseHandle handle = type.CreateInstance();
261 DALI_TEST_CHECK( handle );
263 VisualFactory factory;
264 factory = VisualFactory::Get();
265 DALI_TEST_CHECK( factory );
267 VisualFactory newFactory = VisualFactory::Get();
268 DALI_TEST_CHECK( newFactory );
270 // Check that visual factory is a singleton
271 DALI_TEST_CHECK(factory == newFactory);
276 int UtcDaliVisualFactoryCopyAndAssignment(void)
278 ToolkitTestApplication application;
279 tet_infoline( "UtcDaliVisualFactoryCopyAndAssignment" );
280 VisualFactory factory = VisualFactory::Get();
282 VisualFactory factoryCopy( factory );
283 DALI_TEST_CHECK(factory == factoryCopy);
285 VisualFactory emptyFactory;
286 VisualFactory emptyFactoryCopy( emptyFactory );
287 DALI_TEST_CHECK(emptyFactory == emptyFactoryCopy);
289 VisualFactory factoryEquals;
290 factoryEquals = factory;
291 DALI_TEST_CHECK(factory == factoryEquals);
293 VisualFactory emptyFactoryEquals;
294 emptyFactoryEquals = emptyFactory;
295 DALI_TEST_CHECK( emptyFactory == emptyFactoryEquals );
299 DALI_TEST_CHECK( factory = factoryCopy );
304 int UtcDaliVisualFactoryGetColorVisual1(void)
306 ToolkitTestApplication application;
307 tet_infoline( "UtcDaliVisualFactoryGetColorVisual1: Request color visual with a Property::Map" );
309 VisualFactory factory = VisualFactory::Get();
310 DALI_TEST_CHECK( factory );
312 Property::Map propertyMap;
313 Vector4 testColor( 1.f, 0.5f, 0.3f, 0.2f );
314 propertyMap.Insert(Visual::Property::TYPE, Visual::COLOR);
315 propertyMap.Insert(ColorVisual::Property::MIX_COLOR, testColor);
317 Visual::Base visual = factory.CreateVisual(propertyMap);
318 DALI_TEST_CHECK( visual );
320 DummyControl actor = DummyControl::New();
321 TestVisualRender( application, actor, visual );
323 Vector3 actualValue(Vector4::ZERO);
325 TestGlAbstraction& gl = application.GetGlAbstraction();
326 DALI_TEST_CHECK( gl.GetUniformValue<Vector3>( "mixColor", actualValue ) );
327 DALI_TEST_CHECK( gl.GetUniformValue<float>( "opacity", opacity ) );
328 DALI_TEST_EQUALS( actualValue, Vector3(testColor), TEST_LOCATION );
329 DALI_TEST_EQUALS( opacity, testColor.a, TEST_LOCATION );
334 int UtcDaliVisualFactoryGetColorVisual2(void)
336 ToolkitTestApplication application;
337 tet_infoline( "UtcDaliVisualFactoryGetColorVisual2: Request color visual with a Vector4" );
339 VisualFactory factory = VisualFactory::Get();
340 DALI_TEST_CHECK( factory );
342 Vector4 testColor( 1.f, 0.5f, 0.3f, 0.2f );
343 Dali::Property::Map map;
344 map[ Visual::Property::TYPE ] = Visual::COLOR;
345 map[ ColorVisual::Property::MIX_COLOR ] = testColor;
346 Visual::Base visual = factory.CreateVisual( map );
347 DALI_TEST_CHECK( visual );
349 DummyControl actor = DummyControl::New();
350 TestVisualRender( application, actor, visual );
354 TestGlAbstraction& gl = application.GetGlAbstraction();
355 DALI_TEST_CHECK( gl.GetUniformValue<Vector3>( "mixColor", actualValue ) );
356 DALI_TEST_CHECK( gl.GetUniformValue<float>( "opacity", opacity ) );
357 DALI_TEST_EQUALS( actualValue, Vector3(testColor), TEST_LOCATION );
358 DALI_TEST_EQUALS( opacity, testColor.a, TEST_LOCATION );
360 Stage::GetCurrent().Remove(actor);
361 DALI_TEST_CHECK( actor.GetRendererCount() == 0u );
366 int UtcDaliVisualFactoryGetBorderVisual1(void)
368 ToolkitTestApplication application;
369 tet_infoline( "UtcDaliVisualFactoryGetBorderVisual1: Request border visual with a Property::Map" );
371 VisualFactory factory = VisualFactory::Get();
372 DALI_TEST_CHECK( factory );
374 Property::Map propertyMap;
375 Vector4 testColor( 1.f, 0.5f, 0.3f, 0.2f );
376 float testSize = 5.f;
377 propertyMap.Insert(Visual::Property::TYPE, Visual::BORDER);
378 propertyMap.Insert(BorderVisual::Property::COLOR, testColor);
379 propertyMap.Insert(BorderVisual::Property::SIZE, testSize);
381 Visual::Base visual = factory.CreateVisual(propertyMap);
382 DALI_TEST_CHECK( visual );
384 DummyControl actor = DummyControl::New();
385 DummyControlImpl& dummyImpl = static_cast<DummyControlImpl&>(actor.GetImplementation());
386 dummyImpl.RegisterVisual( Control::CONTROL_PROPERTY_END_INDEX + 1, visual );
387 actor.SetSize(200.f, 200.f);
388 Stage::GetCurrent().Add( actor );
389 visual.SetTransformAndSize(DefaultTransform(), Vector2(200.f, 200.f));
391 DALI_TEST_CHECK( actor.GetRendererCount() == 1u );
392 int blendMode = actor.GetRendererAt(0u).GetProperty<int>( Renderer::Property::BLEND_MODE );
393 DALI_TEST_EQUALS( static_cast<BlendMode::Type>(blendMode), BlendMode::ON, TEST_LOCATION );
395 TestGlAbstraction& gl = application.GetGlAbstraction();
397 application.SendNotification();
398 application.Render(0);
400 Vector4 actualColor(Vector4::ZERO);
401 DALI_TEST_CHECK( gl.GetUniformValue<Vector4>( "borderColor", actualColor ) );
402 DALI_TEST_EQUALS( actualColor, testColor, TEST_LOCATION );
404 float actualSize = 0.f;
405 DALI_TEST_CHECK( gl.GetUniformValue<float>( "borderSize", actualSize ) );
406 DALI_TEST_EQUALS( actualSize, testSize, TEST_LOCATION );
409 DALI_TEST_CHECK( actor.GetRendererCount() == 0u );
414 int UtcDaliVisualFactoryGetBorderVisual2(void)
416 ToolkitTestApplication application;
417 tet_infoline( "UtcDaliVisualFactoryGetBorderVisual2: Request border visual with a borderSize and a borderColor" );
419 VisualFactory factory = VisualFactory::Get();
420 DALI_TEST_CHECK( factory );
422 Vector4 testColor( 1.f, 0.5f, 0.3f, 1.f );
423 float testSize = 5.f;
425 Dali::Property::Map propertyMap;
426 propertyMap[ Visual::Property::TYPE ] = Visual::BORDER;
427 propertyMap[ BorderVisual::Property::COLOR ] = testColor;
428 propertyMap[ BorderVisual::Property::SIZE ] = testSize;
429 Visual::Base visual = factory.CreateVisual( propertyMap );
430 DALI_TEST_CHECK( visual );
432 DummyControl actor = DummyControl::New();
433 DummyControlImpl& dummyImpl = static_cast<DummyControlImpl&>(actor.GetImplementation());
434 dummyImpl.RegisterVisual( Control::CONTROL_PROPERTY_END_INDEX + 1, visual );
435 actor.SetSize(200.f, 200.f);
436 Stage::GetCurrent().Add( actor );
437 visual.SetTransformAndSize(DefaultTransform(), Vector2(200.f, 200.f));
439 DALI_TEST_CHECK( actor.GetRendererCount() == 1u );
441 TestGlAbstraction& gl = application.GetGlAbstraction();
443 application.SendNotification();
444 application.Render(0);
446 int blendMode = actor.GetRendererAt(0u).GetProperty<int>( Renderer::Property::BLEND_MODE );
447 DALI_TEST_EQUALS( static_cast<BlendMode::Type>(blendMode), BlendMode::AUTO, TEST_LOCATION );
449 Vector4 actualColor(Vector4::ZERO);
450 DALI_TEST_CHECK( gl.GetUniformValue<Vector4>( "borderColor", actualColor ) );
451 DALI_TEST_EQUALS( actualColor, testColor, TEST_LOCATION );
453 float actualSize = 0.f;
454 DALI_TEST_CHECK( gl.GetUniformValue<float>( "borderSize", actualSize ) );
455 DALI_TEST_EQUALS( actualSize, testSize, TEST_LOCATION );
459 // enable the anti-aliasing
460 Dali::Property::Map map;
461 map[ Visual::Property::TYPE ] = Visual::BORDER;
462 map[ BorderVisual::Property::COLOR ] = testColor;
463 map[ BorderVisual::Property::SIZE ] = testSize;
464 map[ BorderVisual::Property::ANTI_ALIASING ] = true;
465 visual = factory.CreateVisual( map );
467 dummyImpl.RegisterVisual( Control::CONTROL_PROPERTY_END_INDEX + 1, visual );
468 Stage::GetCurrent().Add( actor );
470 blendMode = actor.GetRendererAt(0u).GetProperty<int>( Renderer::Property::BLEND_MODE );
471 DALI_TEST_EQUALS( static_cast<BlendMode::Type>(blendMode), BlendMode::ON, TEST_LOCATION );
476 int UtcDaliVisualFactoryGetLinearGradientVisual(void)
478 ToolkitTestApplication application;
479 tet_infoline("UtcDaliVisualFactoryGetRadialGradientVisual");
481 VisualFactory factory = VisualFactory::Get();
482 DALI_TEST_CHECK( factory );
484 Property::Map propertyMap;
485 propertyMap.Insert(Visual::Property::TYPE, Visual::GRADIENT);
487 Vector2 start(-1.f, -1.f);
488 Vector2 end(1.f, 1.f);
489 propertyMap.Insert(GradientVisual::Property::START_POSITION, start);
490 propertyMap.Insert(GradientVisual::Property::END_POSITION, end);
491 propertyMap.Insert(GradientVisual::Property::SPREAD_METHOD, GradientVisual::SpreadMethod::REPEAT);
493 Property::Array stopOffsets;
494 stopOffsets.PushBack( 0.2f );
495 stopOffsets.PushBack( 0.8f );
496 propertyMap.Insert(GradientVisual::Property::STOP_OFFSET, stopOffsets);
498 Property::Array stopColors;
499 stopColors.PushBack( Color::RED );
500 stopColors.PushBack( Color::GREEN );
501 propertyMap.Insert(GradientVisual::Property::STOP_COLOR, stopColors);
503 Visual::Base visual = factory.CreateVisual(propertyMap);
504 DALI_TEST_CHECK( visual );
506 // A lookup texture is generated and pass to shader as sampler
507 DummyControl actor = DummyControl::New();
508 TestVisualRender( application, actor, visual, 1u);
513 int UtcDaliVisualFactoryGetRadialGradientVisual(void)
515 ToolkitTestApplication application;
516 tet_infoline("UtcDaliVisualFactoryGetRadialGradientVisual");
518 VisualFactory factory = VisualFactory::Get();
519 DALI_TEST_CHECK( factory );
521 Property::Map propertyMap;
522 propertyMap.Insert(Visual::Property::TYPE, Visual::GRADIENT);
524 Vector2 center(100.f, 100.f);
525 float radius = 100.f;
526 propertyMap.Insert(GradientVisual::Property::UNITS, GradientVisual::Units::USER_SPACE);
527 propertyMap.Insert(GradientVisual::Property::CENTER, center);
528 propertyMap.Insert(GradientVisual::Property::RADIUS, radius);
530 Property::Array stopOffsets;
531 stopOffsets.PushBack( 0.0f );
532 stopOffsets.PushBack( 1.f );
533 propertyMap.Insert(GradientVisual::Property::STOP_OFFSET, stopOffsets);
535 Property::Array stopColors;
536 stopColors.PushBack( Color::RED );
537 stopColors.PushBack( Color::GREEN );
538 propertyMap.Insert(GradientVisual::Property::STOP_COLOR, stopColors);
540 Visual::Base visual = factory.CreateVisual(propertyMap);
541 DALI_TEST_CHECK( visual );
543 // A lookup texture is generated and pass to shader as sampler
544 DummyControl actor = DummyControl::New();
545 TestVisualRender( application, actor, visual, 1u );
547 Matrix3 alignMatrix( radius, 0.f, 0.f, 0.f, radius, 0.f, center.x, center.y, 1.f );
548 alignMatrix.Invert();
550 Matrix3 actualValue( Matrix3::IDENTITY );
551 TestGlAbstraction& gl = application.GetGlAbstraction();
552 DALI_TEST_CHECK( gl.GetUniformValue<Matrix3>( "uAlignmentMatrix", actualValue ) );
553 DALI_TEST_EQUALS( actualValue, alignMatrix, Math::MACHINE_EPSILON_100, TEST_LOCATION );
558 int UtcDaliVisualFactoryDefaultOffsetsGradientVisual(void)
560 ToolkitTestApplication application;
561 tet_infoline("UtcDaliVisualFactoryGetRadialGradientVisual");
563 VisualFactory factory = VisualFactory::Get();
564 DALI_TEST_CHECK( factory );
566 Property::Map propertyMap;
567 propertyMap.Insert(Visual::Property::TYPE, Visual::GRADIENT);
569 Vector2 start(-1.f, -1.f);
570 Vector2 end(1.f, 1.f);
571 propertyMap.Insert(GradientVisual::Property::START_POSITION, start);
572 propertyMap.Insert(GradientVisual::Property::END_POSITION, end);
573 propertyMap.Insert(GradientVisual::Property::SPREAD_METHOD, GradientVisual::SpreadMethod::REPEAT);
575 Property::Array stopColors;
576 stopColors.PushBack( Color::RED );
577 stopColors.PushBack( Color::GREEN );
578 propertyMap.Insert(GradientVisual::Property::STOP_COLOR, stopColors);
580 Visual::Base visual = factory.CreateVisual(propertyMap);
581 DALI_TEST_CHECK( visual );
583 // A lookup texture is generated and pass to shader as sampler
584 DummyControl actor = DummyControl::New();
585 TestVisualRender( application, actor, visual, 1u );
587 Stage::GetCurrent().Remove( actor );
588 DALI_TEST_CHECK( actor.GetRendererCount() == 0u );
597 int UtcDaliVisualFactoryGetNPatchVisual1(void)
599 ToolkitTestApplication application;
600 tet_infoline( "UtcDaliVisualFactoryGetNPatchVisual1: Request 9-patch visual with a Property::Map" );
602 VisualFactory factory = VisualFactory::Get();
603 DALI_TEST_CHECK( factory );
605 const unsigned int ninePatchImageHeight = 18;
606 const unsigned int ninePatchImageWidth = 28;
607 StretchRanges stretchRangesX;
608 stretchRangesX.PushBack( Uint16Pair( 2, 3 ) );
609 StretchRanges stretchRangesY;
610 stretchRangesY.PushBack( Uint16Pair( 4, 5 ) );
611 Integration::ResourcePointer ninePatchResource = CustomizeNinePatch( application, ninePatchImageWidth, ninePatchImageHeight, stretchRangesX, stretchRangesY );
613 Property::Map propertyMap;
614 propertyMap.Insert( Visual::Property::TYPE, DevelVisual::N_PATCH );
615 propertyMap.Insert( ImageVisual::Property::URL, TEST_NPATCH_FILE_NAME );
617 tet_infoline( "whole grid" );
618 Visual::Base visual = factory.CreateVisual( propertyMap );
619 DALI_TEST_CHECK( visual );
622 TestGlAbstraction& gl = application.GetGlAbstraction();
623 TraceCallStack& textureTrace = gl.GetTextureTrace();
624 textureTrace.Enable(true);
626 DummyControl actor = DummyControl::New();
627 TestVisualRender( application, actor, visual, 1u,
628 ImageDimensions(ninePatchImageWidth, ninePatchImageHeight),
631 DALI_TEST_EQUALS( textureTrace.FindMethod("BindTexture"), true, TEST_LOCATION );
634 propertyMap.Insert( ImageVisual::Property::BORDER_ONLY, true );
636 tet_infoline( "border only" );
637 Visual::Base visual = factory.CreateVisual( propertyMap );
638 DALI_TEST_CHECK( visual );
640 TestGlAbstraction& gl = application.GetGlAbstraction();
641 TraceCallStack& textureTrace = gl.GetTextureTrace();
642 textureTrace.Enable(true);
644 DummyControl actor = DummyControl::New();
645 TestVisualRender( application, actor, visual, 1u,
646 ImageDimensions(ninePatchImageWidth, ninePatchImageHeight),
649 DALI_TEST_EQUALS( textureTrace.FindMethod("BindTexture"), true, TEST_LOCATION );
655 int UtcDaliVisualFactoryGetNPatchVisual2(void)
657 ToolkitTestApplication application;
658 tet_infoline( "UtcDaliVisualFactoryGetNPatchVisual1: Request 9-patch visual with a Property::Map including border" );
660 VisualFactory factory = VisualFactory::Get();
661 DALI_TEST_CHECK( factory );
663 Property::Map propertyMap;
664 propertyMap.Insert( Visual::Property::TYPE, DevelVisual::N_PATCH );
665 propertyMap.Insert( ImageVisual::Property::URL, gImage_34_RGBA );
666 propertyMap.Insert( DevelImageVisual::Property::BORDER, Rect< int >( 2, 2, 2, 2 ) );
668 tet_infoline( "whole grid" );
669 Visual::Base visual = factory.CreateVisual( propertyMap );
670 DALI_TEST_CHECK( visual );
672 TestGlAbstraction& gl = application.GetGlAbstraction();
673 TraceCallStack& textureTrace = gl.GetTextureTrace();
674 textureTrace.Enable(true);
676 DummyControl actor = DummyControl::New();
677 TestVisualRender( application, actor, visual, 1u );
679 DALI_TEST_EQUALS( textureTrace.FindMethod("BindTexture"), true, TEST_LOCATION );
682 propertyMap.Insert( ImageVisual::Property::BORDER_ONLY, true );
684 tet_infoline( "border only" );
685 Visual::Base visual = factory.CreateVisual( propertyMap );
686 DALI_TEST_CHECK( visual );
688 TestGlAbstraction& gl = application.GetGlAbstraction();
689 TraceCallStack& textureTrace = gl.GetTextureTrace();
690 textureTrace.Enable(true);
692 DummyControl actor = DummyControl::New();
693 TestVisualRender( application, actor, visual, 1u );
695 DALI_TEST_EQUALS( textureTrace.FindMethod("BindTexture"), true, TEST_LOCATION );
701 int UtcDaliVisualFactoryGetNPatchVisual3(void)
703 ToolkitTestApplication application;
704 tet_infoline( "UtcDaliVisualFactoryGetNPatchVisual2: Request n-patch visual with a Property::Map" );
706 VisualFactory factory = VisualFactory::Get();
707 DALI_TEST_CHECK( factory );
709 const unsigned int ninePatchImageWidth = 18;
710 const unsigned int ninePatchImageHeight = 28;
711 StretchRanges stretchRangesX;
712 stretchRangesX.PushBack( Uint16Pair( 2, 3 ) );
713 stretchRangesX.PushBack( Uint16Pair( 5, 7 ) );
714 stretchRangesX.PushBack( Uint16Pair( 12, 15 ) );
715 StretchRanges stretchRangesY;
716 stretchRangesY.PushBack( Uint16Pair( 4, 5 ) );
717 stretchRangesY.PushBack( Uint16Pair( 8, 12 ) );
718 stretchRangesY.PushBack( Uint16Pair( 15, 16 ) );
719 stretchRangesY.PushBack( Uint16Pair( 25, 27 ) );
720 Integration::ResourcePointer ninePatchResource = CustomizeNinePatch( application, ninePatchImageWidth, ninePatchImageHeight, stretchRangesX, stretchRangesY );
722 Property::Map propertyMap;
723 propertyMap.Insert( Visual::Property::TYPE, DevelVisual::N_PATCH );
724 propertyMap.Insert( ImageVisual::Property::URL, TEST_NPATCH_FILE_NAME );
726 Visual::Base visual = factory.CreateVisual( propertyMap );
727 DALI_TEST_CHECK( visual );
729 TestGlAbstraction& gl = application.GetGlAbstraction();
730 TraceCallStack& textureTrace = gl.GetTextureTrace();
731 textureTrace.Enable(true);
733 DummyControl actor = DummyControl::New();
734 TestVisualRender( application, actor, visual, 1u,
735 ImageDimensions(ninePatchImageWidth, ninePatchImageHeight),
738 DALI_TEST_EQUALS( textureTrace.FindMethod("BindTexture"), true, TEST_LOCATION );
740 Stage::GetCurrent().Remove( actor );
741 DALI_TEST_CHECK( actor.GetRendererCount() == 0u );
744 propertyMap.Insert( ImageVisual::Property::BORDER_ONLY, true );
746 tet_infoline( "border only" );
747 Visual::Base visual = factory.CreateVisual( propertyMap );
748 DALI_TEST_CHECK( visual );
750 TestGlAbstraction& gl = application.GetGlAbstraction();
751 TraceCallStack& textureTrace = gl.GetTextureTrace();
752 textureTrace.Enable(true);
753 DummyControl actor = DummyControl::New();
754 TestVisualRender( application, actor, visual, 1u,
755 ImageDimensions(ninePatchImageWidth, ninePatchImageHeight),
759 DALI_TEST_EQUALS( textureTrace.FindMethod("BindTexture"), true, TEST_LOCATION );
761 Stage::GetCurrent().Remove( actor );
762 DALI_TEST_CHECK( actor.GetRendererCount() == 0u );
768 int UtcDaliVisualFactoryGetNPatchVisual4(void)
770 ToolkitTestApplication application;
771 tet_infoline( "UtcDaliVisualFactoryGetNPatchVisual3: Request 9-patch visual with an image url" );
773 VisualFactory factory = VisualFactory::Get();
774 DALI_TEST_CHECK( factory );
776 const unsigned int ninePatchImageHeight = 18;
777 const unsigned int ninePatchImageWidth = 28;
778 StretchRanges stretchRangesX;
779 stretchRangesX.PushBack( Uint16Pair( 2, 3 ) );
780 StretchRanges stretchRangesY;
781 stretchRangesY.PushBack( Uint16Pair( 4, 5 ) );
782 Integration::ResourcePointer ninePatchResource = CustomizeNinePatch( application, ninePatchImageWidth, ninePatchImageHeight, stretchRangesX, stretchRangesY );
784 Visual::Base visual = factory.CreateVisual( TEST_NPATCH_FILE_NAME, ImageDimensions() );
785 DALI_TEST_CHECK( visual );
787 TestGlAbstraction& gl = application.GetGlAbstraction();
788 TraceCallStack& textureTrace = gl.GetTextureTrace();
789 textureTrace.Enable(true);
791 DummyControl actor = DummyControl::New();
792 TestVisualRender( application, actor, visual, 1u,
793 ImageDimensions(ninePatchImageWidth, ninePatchImageHeight),
796 DALI_TEST_EQUALS( textureTrace.FindMethod("BindTexture"), true, TEST_LOCATION );
799 ResourceImage image = ResourceImage::New(TEST_NPATCH_FILE_NAME);
800 Visual::Base nPatchVisual = factory.CreateVisual( image );
801 Vector2 controlSize( 20.f, 30.f ), naturalSize(0,0);
802 nPatchVisual.SetTransformAndSize(DefaultTransform(), controlSize );
803 nPatchVisual.GetNaturalSize( naturalSize );
804 DALI_TEST_EQUALS( naturalSize, Vector2( ninePatchImageWidth-2, ninePatchImageHeight-2 ), TEST_LOCATION );
809 int UtcDaliVisualFactoryGetNPatchVisual5(void)
811 ToolkitTestApplication application;
812 tet_infoline( "UtcDaliVisualFactoryGetNPatchVisual4: Request n-patch visual with an image url" );
814 VisualFactory factory = VisualFactory::Get();
815 DALI_TEST_CHECK( factory );
817 const unsigned int ninePatchImageHeight = 18;
818 const unsigned int ninePatchImageWidth = 28;
819 StretchRanges stretchRangesX;
820 stretchRangesX.PushBack( Uint16Pair( 2, 3 ) );
821 stretchRangesX.PushBack( Uint16Pair( 5, 7 ) );
822 stretchRangesX.PushBack( Uint16Pair( 12, 15 ) );
823 StretchRanges stretchRangesY;
824 stretchRangesY.PushBack( Uint16Pair( 4, 5 ) );
825 stretchRangesY.PushBack( Uint16Pair( 8, 12 ) );
826 stretchRangesY.PushBack( Uint16Pair( 15, 16 ) );
827 stretchRangesY.PushBack( Uint16Pair( 25, 27 ) );
828 Integration::ResourcePointer ninePatchResource = CustomizeNinePatch( application, ninePatchImageWidth, ninePatchImageHeight, stretchRangesX, stretchRangesY );
830 Visual::Base visual = factory.CreateVisual( TEST_NPATCH_FILE_NAME, ImageDimensions() );
831 DALI_TEST_CHECK( visual );
833 TestGlAbstraction& gl = application.GetGlAbstraction();
834 TraceCallStack& textureTrace = gl.GetTextureTrace();
835 textureTrace.Enable(true);
837 DummyControl actor = DummyControl::New();
838 TestVisualRender( application, actor, visual, 1u,
839 ImageDimensions(ninePatchImageWidth, ninePatchImageHeight),
842 DALI_TEST_EQUALS( textureTrace.FindMethod("BindTexture"), true, TEST_LOCATION );
847 int UtcDaliVisualFactoryGetNPatchVisualN1(void)
849 //This should still load but display an error image
851 ToolkitTestApplication application;
852 tet_infoline( "UtcDaliVisualFactoryGetNPatchVisualN: Request n-patch visual with an invalid image url" );
854 VisualFactory factory = VisualFactory::Get();
855 DALI_TEST_CHECK( factory );
857 Visual::Base visual = factory.CreateVisual( "ERROR.9.jpg", ImageDimensions() );
858 DALI_TEST_CHECK( visual );
860 //The testkit still has to load a bitmap for the broken renderer image
861 Integration::Bitmap* bitmap = Integration::Bitmap::New(Integration::Bitmap::BITMAP_2D_PACKED_PIXELS, ResourcePolicy::OWNED_DISCARD);
862 bitmap->GetPackedPixelsProfile()->ReserveBuffer( Pixel::RGBA8888, 100, 100, 100, 100 );
864 TestGlAbstraction& gl = application.GetGlAbstraction();
865 TraceCallStack& textureTrace = gl.GetTextureTrace();
866 textureTrace.Enable(true);
868 DummyControl actor = DummyControl::New();
869 TestVisualRender( application, actor, visual, 1u,
871 Integration::ResourcePointer(bitmap) );
873 DALI_TEST_EQUALS( textureTrace.FindMethod("BindTexture"), true, TEST_LOCATION );
878 int UtcDaliVisualFactoryGetNPatchVisualN2(void)
880 //This should still load but display an error image
882 ToolkitTestApplication application;
883 tet_infoline( "UtcDaliVisualFactoryGetNPatchVisualN: Request n-patch visual with an invalid URL" );
885 VisualFactory factory = VisualFactory::Get();
886 DALI_TEST_CHECK( factory );
888 Property::Map propertyMap;
889 propertyMap.Insert( Visual::Property::TYPE, DevelVisual::N_PATCH );
890 propertyMap.Insert( ImageVisual::Property::URL, "ERROR.9.jpg" );
892 Visual::Base visual = factory.CreateVisual( propertyMap );
893 DALI_TEST_CHECK( visual );
895 //The testkit still has to load a bitmap for the broken renderer image
896 Integration::Bitmap* bitmap = Integration::Bitmap::New(Integration::Bitmap::BITMAP_2D_PACKED_PIXELS, ResourcePolicy::OWNED_DISCARD);
897 bitmap->GetPackedPixelsProfile()->ReserveBuffer( Pixel::RGBA8888, 100, 100, 100, 100 );
899 TestGlAbstraction& gl = application.GetGlAbstraction();
900 TraceCallStack& textureTrace = gl.GetTextureTrace();
901 textureTrace.Enable(true);
902 TraceCallStack& drawTrace = gl.GetDrawTrace();
903 drawTrace.Enable(true);
905 DummyControl actor = DummyControl::New();
906 TestVisualRender( application, actor, visual, 1u,
908 Integration::ResourcePointer(bitmap) );
910 DALI_TEST_EQUALS( textureTrace.FindMethod("BindTexture"), true, TEST_LOCATION );
915 int UtcDaliVisualFactoryGetNPatchVisualN3(void)
917 // Passing in an invalid visual type so we should not get a visual
919 ToolkitTestApplication application;
920 tet_infoline( "UtcDaliVisualFactoryGetNPatchVisualN: Request n-patch visual with an invalid visual type" );
922 VisualFactory factory = VisualFactory::Get();
923 DALI_TEST_CHECK( factory );
925 Property::Map propertyMap;
926 propertyMap.Insert( Visual::Property::TYPE, 111 );
927 propertyMap.Insert( ImageVisual::Property::URL, "ERROR.9.jpg" );
929 Visual::Base visual = factory.CreateVisual( propertyMap );
930 DALI_TEST_CHECK( !visual );
935 int UtcDaliVisualFactoryGetSvgVisual(void)
937 ToolkitTestApplication application;
938 tet_infoline( "UtcDaliVisualFactoryGetSvgVisual: Request svg visual with a svg url" );
940 VisualFactory factory = VisualFactory::Get();
941 Visual::Base visual = factory.CreateVisual( TEST_SVG_FILE_NAME, ImageDimensions() );
942 DALI_TEST_CHECK( visual );
944 TestGlAbstraction& gl = application.GetGlAbstraction();
945 TraceCallStack& textureTrace = gl.GetTextureTrace();
946 textureTrace.Enable(true);
948 DummyControl actor = DummyControl::New();
949 DummyControlImpl& dummyImpl = static_cast<DummyControlImpl&>(actor.GetImplementation());
950 dummyImpl.RegisterVisual( Control::CONTROL_PROPERTY_END_INDEX + 1, visual );
951 actor.SetSize( 200.f, 200.f );
952 Stage::GetCurrent().Add( actor );
953 visual.SetTransformAndSize(DefaultTransform(), Vector2(200.f, 200.f) );
955 application.SendNotification();
956 application.Render();
958 // renderer is not added to actor until the rasterization is completed.
959 DALI_TEST_CHECK( actor.GetRendererCount() == 0u );
961 DALI_TEST_EQUALS( Test::WaitForEventThreadTrigger( 1 ), true, TEST_LOCATION );
963 // renderer is added to actor
964 DALI_TEST_CHECK( actor.GetRendererCount() == 1u );
966 // waiting for the resource uploading
967 application.SendNotification();
968 application.Render();
970 DALI_TEST_EQUALS( textureTrace.FindMethod("BindTexture"), true, TEST_LOCATION );
975 int UtcDaliVisualFactoryGetSvgVisualLarge(void)
977 ToolkitTestApplication application;
978 tet_infoline( "UtcDaliVisualFactoryGetSvgVisual: Request svg visual with a svg url" );
980 VisualFactory factory = VisualFactory::Get();
981 Visual::Base visual = factory.CreateVisual( TEST_SVG_FILE_NAME, ImageDimensions( 2000, 2000 ) );
982 DALI_TEST_CHECK( visual );
984 TestGlAbstraction& gl = application.GetGlAbstraction();
985 TraceCallStack& textureTrace = gl.GetTextureTrace();
986 textureTrace.Enable(true);
988 DummyControl actor = DummyControl::New(true);
989 DummyControlImpl& dummyImpl = static_cast<DummyControlImpl&>(actor.GetImplementation());
990 actor.SetResizePolicy( ResizePolicy::FILL_TO_PARENT, Dimension::ALL_DIMENSIONS ); // Only rasterizes when it knows control size.
991 dummyImpl.RegisterVisual( Control::CONTROL_PROPERTY_END_INDEX + 1, visual );
992 Stage::GetCurrent().Add( actor );
994 application.SendNotification();
995 application.Render();
997 // renderer is not added to actor until the rasterization is completed.
998 DALI_TEST_CHECK( actor.GetRendererCount() == 0u );
1000 DALI_TEST_EQUALS( Test::WaitForEventThreadTrigger( 1 ), true, TEST_LOCATION );
1002 // renderer is added to actor
1003 DALI_TEST_CHECK( actor.GetRendererCount() == 1u );
1005 // waiting for the resource uploading
1006 application.SendNotification();
1007 application.Render();
1009 DALI_TEST_EQUALS( textureTrace.FindMethod("BindTexture"), true, TEST_LOCATION );
1014 //Creates a mesh visual from the given propertyMap and tries to load it on stage in the given application.
1015 //This is expected to succeed, which will then pass the test.
1016 void MeshVisualLoadsCorrectlyTest( Property::Map& propertyMap, ToolkitTestApplication& application )
1018 VisualFactory factory = VisualFactory::Get();
1019 DALI_TEST_CHECK( factory );
1021 //Create a mesh visual.
1022 Visual::Base visual = factory.CreateVisual( propertyMap );
1023 DALI_TEST_CHECK( visual );
1025 //Create an actor on stage to house the visual.
1026 DummyControl actor = DummyControl::New();
1027 DummyControlImpl& dummyImpl = static_cast<DummyControlImpl&>(actor.GetImplementation());
1028 dummyImpl.RegisterVisual( Control::CONTROL_PROPERTY_END_INDEX + 1, visual );
1029 actor.SetSize( 200.f, 200.f );
1030 Stage::GetCurrent().Add( actor );
1031 visual.SetTransformAndSize(DefaultTransform(), Vector2( 200.f, 200.f ) );
1033 //Ensure set on stage.
1034 DALI_TEST_EQUALS( actor.GetRendererCount(), 1u, TEST_LOCATION );
1036 //Attempt to render to queue resource load requests.
1037 application.SendNotification();
1038 application.Render( 0 );
1040 //Render again to upload the now-loaded textures.
1041 application.SendNotification();
1042 application.Render( 0 );
1044 Matrix testScaleMatrix;
1045 testScaleMatrix.SetIdentityAndScale( Vector3( 1.0, -1.0, 1.0 ) );
1046 Matrix actualScaleMatrix;
1048 //Test to see if the object has been successfully loaded.
1049 DALI_TEST_CHECK( application.GetGlAbstraction().GetUniformValue<Matrix>( "uObjectMatrix", actualScaleMatrix ) );
1050 DALI_TEST_EQUALS( actualScaleMatrix, testScaleMatrix, Math::MACHINE_EPSILON_100, TEST_LOCATION );
1052 //Finish by setting off stage, and ensuring this was successful.
1054 DALI_TEST_EQUALS( actor.GetRendererCount(), 0u, TEST_LOCATION );
1057 //Creates a mesh visual from the given propertyMap and tries to load it on stage in the given application.
1058 //This is expected to fail, which will then pass the test.
1059 void MeshVisualDoesNotLoadCorrectlyTest( Property::Map& propertyMap, ToolkitTestApplication& application )
1061 VisualFactory factory = VisualFactory::Get();
1062 DALI_TEST_CHECK( factory );
1064 //Create a mesh visual.
1065 Visual::Base visual = factory.CreateVisual( propertyMap );
1066 DALI_TEST_CHECK( visual );
1068 //Create an actor on stage to house the visual.
1069 DummyControl actor = DummyControl::New();
1070 DummyControlImpl& dummyImpl = static_cast<DummyControlImpl&>(actor.GetImplementation());
1071 dummyImpl.RegisterVisual( Control::CONTROL_PROPERTY_END_INDEX + 1, visual );
1072 actor.SetSize( 200.f, 200.f );
1073 Stage::GetCurrent().Add( actor );
1074 visual.SetTransformAndSize(DefaultTransform(), Vector2( 200.f, 200.f ) );
1076 //Ensure set on stage.
1077 DALI_TEST_EQUALS( actor.GetRendererCount(), 1u, TEST_LOCATION );
1079 //Attempt to render to queue resource load requests.
1080 application.SendNotification();
1081 application.Render( 0 );
1083 //Render again to upload the now-loaded textures.
1084 application.SendNotification();
1085 application.Render( 0 );
1087 //Test to see if the object has not been loaded, as expected.
1089 DALI_TEST_CHECK( !application.GetGlAbstraction().GetUniformValue<Matrix>( "uObjectMatrix", scaleMatrix ) );
1091 //Finish by setting off stage, and ensuring this was successful.
1093 DALI_TEST_EQUALS( actor.GetRendererCount(), 0u, TEST_LOCATION );
1096 //Test if mesh loads correctly when supplied with only the bare minimum requirements, an object file.
1097 int UtcDaliVisualFactoryGetMeshVisual1(void)
1099 //Set up test application first, so everything else can be handled.
1100 ToolkitTestApplication application;
1102 tet_infoline( "UtcDaliVisualFactoryGetMeshVisual1: Request mesh visual with a valid object file only" );
1105 //Set up visual properties.
1106 Property::Map propertyMap;
1107 propertyMap.Insert( Visual::Property::TYPE, Visual::MESH );
1108 propertyMap.Insert( MeshVisual::Property::OBJECT_URL, TEST_OBJ_FILE_NAME );
1110 //Test to see if mesh loads correctly.
1111 MeshVisualLoadsCorrectlyTest( propertyMap, application );
1117 //Test if mesh loads correctly when supplied with an object file as well as a blank material file and images directory.
1118 int UtcDaliVisualFactoryGetMeshVisual2(void)
1120 //Set up test application first, so everything else can be handled.
1121 ToolkitTestApplication application;
1123 tet_infoline( "UtcDaliVisualFactoryGetMeshVisual2: Request mesh visual with blank material file and images directory" );
1125 //Set up visual properties.
1126 Property::Map propertyMap;
1127 propertyMap.Insert( Visual::Property::TYPE, Visual::MESH );
1128 propertyMap.Insert( MeshVisual::Property::OBJECT_URL, TEST_OBJ_FILE_NAME );
1129 propertyMap.Insert( MeshVisual::Property::MATERIAL_URL, "" );
1130 propertyMap.Insert( MeshVisual::Property::TEXTURES_PATH, "" );
1132 //Test to see if mesh loads correctly.
1133 MeshVisualLoadsCorrectlyTest( propertyMap, application );
1138 //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
1139 int UtcDaliVisualFactoryGetMeshVisual3b(void)
1141 //Set up test application first, so everything else can be handled.
1142 ToolkitTestApplication application;
1144 tet_infoline( "UtcDaliVisualFactoryGetMeshVisual3: Request mesh visual with all parameters correct" );
1146 //Set up visual properties.
1147 Property::Map propertyMap;
1148 propertyMap.Insert( Visual::Property::TYPE, Visual::MESH );
1149 propertyMap.Insert( MeshVisual::Property::OBJECT_URL, TEST_OBJ_FILE_NAME );
1150 propertyMap.Insert( MeshVisual::Property::MATERIAL_URL, TEST_MTL_FILE_NAME );
1151 propertyMap.Insert( MeshVisual::Property::USE_MIPMAPPING, Color::GREEN ); // Test that wrong property types don't prevent the object load
1152 propertyMap.Insert( MeshVisual::Property::USE_SOFT_NORMALS, 1.0f );
1153 propertyMap.Insert( MeshVisual::Property::LIGHT_POSITION, 1.0f );
1154 propertyMap.Insert( MeshVisual::Property::TEXTURES_PATH, TEST_RESOURCE_DIR "/" );
1156 //Test to see if mesh loads correctly.
1157 MeshVisualLoadsCorrectlyTest( propertyMap, application );
1162 //Test if mesh loads correctly when supplied with all main parameters, an object file, a material file and a directory location.
1163 int UtcDaliVisualFactoryGetMeshVisual3(void)
1165 //Set up test application first, so everything else can be handled.
1166 ToolkitTestApplication application;
1168 tet_infoline( "UtcDaliVisualFactoryGetMeshVisual3: Request mesh visual with all parameters correct" );
1170 //Set up visual properties.
1171 Property::Map propertyMap;
1172 propertyMap.Insert( Visual::Property::TYPE, Visual::MESH );
1173 propertyMap.Insert( MeshVisual::Property::OBJECT_URL, TEST_OBJ_FILE_NAME );
1174 propertyMap.Insert( MeshVisual::Property::MATERIAL_URL, TEST_MTL_FILE_NAME );
1175 propertyMap.Insert( MeshVisual::Property::USE_MIPMAPPING, false );
1176 propertyMap.Insert( MeshVisual::Property::USE_SOFT_NORMALS, false );
1177 propertyMap.Insert( MeshVisual::Property::LIGHT_POSITION, Vector3::XAXIS );
1178 propertyMap.Insert( MeshVisual::Property::TEXTURES_PATH, TEST_RESOURCE_DIR "/" );
1180 //Test to see if mesh loads correctly.
1181 MeshVisualLoadsCorrectlyTest( propertyMap, application );
1186 //Test if mesh visual can load a correctly supplied mesh without a normal map or gloss map in the material file.
1187 int UtcDaliVisualFactoryGetMeshVisual4(void)
1189 //Set up test application first, so everything else can be handled.
1190 ToolkitTestApplication application;
1192 tet_infoline( "UtcDaliVisualFactoryGetMeshVisual4: Request mesh visual with diffuse texture but not normal or gloss." );
1195 //Set up visual properties.
1196 Property::Map propertyMap;
1197 propertyMap.Insert( Visual::Property::TYPE, Visual::MESH );
1198 propertyMap.Insert( MeshVisual::Property::OBJECT_URL, TEST_OBJ_FILE_NAME );
1199 propertyMap.Insert( MeshVisual::Property::MATERIAL_URL, TEST_SIMPLE_MTL_FILE_NAME );
1200 propertyMap.Insert( MeshVisual::Property::TEXTURES_PATH, TEST_RESOURCE_DIR "/" );
1202 //Test to see if mesh loads correctly.
1203 MeshVisualLoadsCorrectlyTest( propertyMap, application );
1208 //Test if mesh visual can load when made to use diffuse textures only.
1209 int UtcDaliVisualFactoryGetMeshVisual5(void)
1211 //Set up test application first, so everything else can be handled.
1212 ToolkitTestApplication application;
1214 tet_infoline( "UtcDaliVisualFactoryGetMeshVisual5: Request mesh visual and make it only use diffuse textures." );
1216 //Set up visual properties.
1217 Property::Map propertyMap;
1218 propertyMap.Insert( Visual::Property::TYPE, Visual::MESH );
1219 propertyMap.Insert( "objectUrl", TEST_OBJ_FILE_NAME );
1220 propertyMap.Insert( "materialUrl", TEST_MTL_FILE_NAME );
1221 propertyMap.Insert( "texturesPath", TEST_RESOURCE_DIR "/" );
1222 propertyMap.Insert( "useMipmapping", false );
1223 propertyMap.Insert( "useSoftNormals", false );
1224 propertyMap.Insert( "lightPosition", Vector3::ZAXIS );
1225 propertyMap.Insert( "shadingMode", MeshVisual::ShadingMode::TEXTURED_WITH_SPECULAR_LIGHTING );
1227 //Test to see if mesh loads correctly.
1228 MeshVisualLoadsCorrectlyTest( propertyMap, application );
1234 //Test if mesh visual can load when made to not use the supplied textures.
1235 int UtcDaliVisualFactoryGetMeshVisual6(void)
1237 //Set up test application first, so everything else can be handled.
1238 ToolkitTestApplication application;
1240 tet_infoline( "UtcDaliVisualFactoryGetMeshVisual6: Request mesh visual and make it not use any textures." );
1242 //Set up visual properties.
1243 Property::Map propertyMap;
1244 propertyMap.Insert( Visual::Property::TYPE, Visual::MESH );
1245 propertyMap.Insert( MeshVisual::Property::OBJECT_URL, TEST_OBJ_FILE_NAME );
1246 propertyMap.Insert( MeshVisual::Property::MATERIAL_URL, TEST_MTL_FILE_NAME );
1247 propertyMap.Insert( MeshVisual::Property::TEXTURES_PATH, TEST_RESOURCE_DIR "/" );
1248 propertyMap.Insert( MeshVisual::Property::SHADING_MODE, MeshVisual::ShadingMode::TEXTURELESS_WITH_DIFFUSE_LIGHTING );
1250 //Test to see if mesh loads correctly.
1251 MeshVisualLoadsCorrectlyTest( propertyMap, application );
1255 //Test if mesh visual loads correctly when light position is manually set.
1256 int UtcDaliVisualFactoryGetMeshVisual7(void)
1258 //Set up test application first, so everything else can be handled.
1259 ToolkitTestApplication application;
1262 tet_infoline( "UtcDaliVisualFactoryGetMeshVisual7: Request mesh visual with custom light position." );
1264 //Set up visual properties.
1265 Property::Map propertyMap;
1266 propertyMap.Insert( Visual::Property::TYPE, Visual::MESH );
1267 propertyMap.Insert( MeshVisual::Property::OBJECT_URL, TEST_OBJ_FILE_NAME );
1268 propertyMap.Insert( MeshVisual::Property::MATERIAL_URL, TEST_MTL_FILE_NAME );
1269 propertyMap.Insert( MeshVisual::Property::TEXTURES_PATH, TEST_RESOURCE_DIR "/" );
1270 propertyMap.Insert( MeshVisual::Property::LIGHT_POSITION, Vector3( 0.0, 1.0, 2.0 ) );
1272 //Test to see if mesh loads correctly.
1273 MeshVisualLoadsCorrectlyTest( propertyMap, application );
1278 //Test if mesh visual loads correctly when supplied an object file without face normals or texture points.
1279 //Note that this notably tests object loader functionality.
1280 int UtcDaliVisualFactoryGetMeshVisual8(void)
1282 //Set up test application first, so everything else can be handled.
1283 ToolkitTestApplication application;
1285 tet_infoline( "UtcDaliVisualFactoryGetMeshVisual5: Request mesh visual with normal-less object file." );
1287 //Set up visual properties.
1288 Property::Map propertyMap;
1289 propertyMap.Insert( Visual::Property::TYPE, Visual::MESH );
1290 propertyMap.Insert( MeshVisual::Property::OBJECT_URL, TEST_SIMPLE_OBJ_FILE_NAME );
1291 propertyMap.Insert( MeshVisual::Property::MATERIAL_URL, TEST_MTL_FILE_NAME );
1292 propertyMap.Insert( MeshVisual::Property::TEXTURES_PATH, TEST_RESOURCE_DIR "/" );
1294 //Test to see if mesh loads correctly.
1295 MeshVisualLoadsCorrectlyTest( propertyMap, application );
1300 //Test if mesh visual handles the case of lacking an object file.
1301 int UtcDaliVisualFactoryGetMeshVisualN1(void)
1303 //Set up test application first, so everything else can be handled.
1304 ToolkitTestApplication application;
1306 tet_infoline( "UtcDaliVisualFactoryGetMeshVisualN1: Request mesh visual without object file" );
1308 //Set up visual properties.
1309 Property::Map propertyMap;
1310 propertyMap.Insert( Visual::Property::TYPE, Visual::MESH );
1311 propertyMap.Insert( MeshVisual::Property::MATERIAL_URL, TEST_MTL_FILE_NAME );
1312 propertyMap.Insert( MeshVisual::Property::TEXTURES_PATH, TEST_RESOURCE_DIR "/" );
1314 //Test to see if mesh doesn't load with these properties, as expected.
1315 MeshVisualDoesNotLoadCorrectlyTest( propertyMap, application );
1321 //Test if mesh visual handles the case of being passed invalid material and images urls.
1322 int UtcDaliVisualFactoryGetMeshVisualN2(void)
1324 //Set up test application first, so everything else can be handled.
1325 ToolkitTestApplication application;
1327 tet_infoline( "UtcDaliVisualFactoryGetMeshVisualN2: Request mesh visual with invalid material and images urls" );
1329 //Set up visual properties.
1330 Property::Map propertyMap;
1331 propertyMap.Insert( Visual::Property::TYPE, Visual::MESH );
1332 propertyMap.Insert( MeshVisual::Property::OBJECT_URL, TEST_OBJ_FILE_NAME );
1333 propertyMap.Insert( MeshVisual::Property::MATERIAL_URL, "invalid" );
1334 propertyMap.Insert( MeshVisual::Property::TEXTURES_PATH, "also invalid" );
1336 //Test to see if mesh doesn't load with these properties, as expected.
1337 MeshVisualDoesNotLoadCorrectlyTest( propertyMap, application );
1343 //Test if mesh visual handles the case of being passed an invalid object url
1344 int UtcDaliVisualFactoryGetMeshVisualN3(void)
1346 //Set up test application first, so everything else can be handled.
1347 ToolkitTestApplication application;
1348 tet_infoline( "UtcDaliVisualFactoryGetMeshVisualN3: Request mesh visual with invalid object url" );
1351 //Set up visual properties.
1352 Property::Map propertyMap;
1353 propertyMap.Insert( Visual::Property::TYPE, Visual::MESH );
1354 propertyMap.Insert( MeshVisual::Property::OBJECT_URL, "invalid" );
1355 propertyMap.Insert( MeshVisual::Property::MATERIAL_URL, TEST_MTL_FILE_NAME );
1356 propertyMap.Insert( MeshVisual::Property::TEXTURES_PATH, TEST_RESOURCE_DIR "/" );
1358 //Test to see if mesh doesn't load with these properties, as expected.
1359 MeshVisualDoesNotLoadCorrectlyTest( propertyMap, application );
1364 //Creates a primitive visual with the given property map and tests to see if it correctly loads in the given application.
1365 void TestPrimitiveVisualWithProperties( Property::Map& propertyMap, ToolkitTestApplication& application )
1367 VisualFactory factory = VisualFactory::Get();
1368 DALI_TEST_CHECK( factory );
1370 //Create a primitive visual.
1371 Visual::Base visual = factory.CreateVisual( propertyMap );
1372 DALI_TEST_CHECK( visual );
1374 //Create an actor on stage to house the visual.
1375 DummyControl actor = DummyControl::New();
1376 DummyControlImpl& dummyImpl = static_cast<DummyControlImpl&>(actor.GetImplementation());
1377 dummyImpl.RegisterVisual( Control::CONTROL_PROPERTY_END_INDEX + 1, visual );
1379 actor.SetSize( 200.f, 200.f );
1380 Stage::GetCurrent().Add( actor );
1381 visual.SetTransformAndSize(DefaultTransform(), Vector2( 200.f, 200.f ) );
1383 //Ensure set on stage.
1384 DALI_TEST_EQUALS( actor.GetRendererCount(), 1u, TEST_LOCATION );
1386 //Tell test application to load the visual.
1387 application.SendNotification();
1388 application.Render(0);
1390 Matrix testScaleMatrix;
1391 testScaleMatrix.SetIdentityAndScale( Vector3( 1.0, -1.0, 1.0 ) );
1392 Matrix actualScaleMatrix;
1394 //Test to see if the object has been successfully loaded.
1395 DALI_TEST_CHECK( application.GetGlAbstraction().GetUniformValue<Matrix>( "uObjectMatrix", actualScaleMatrix ) );
1396 DALI_TEST_EQUALS( actualScaleMatrix, testScaleMatrix, Math::MACHINE_EPSILON_100, TEST_LOCATION );
1398 //Finish by setting off stage, and ensuring this was successful.
1400 DALI_TEST_EQUALS( actor.GetRendererCount(), 0u, TEST_LOCATION );
1403 //Test if primitive shape loads correctly when supplied with only the bare minimum requirements, the shape to use.
1404 int UtcDaliVisualFactoryGetPrimitiveVisual1(void)
1406 //Set up test application first, so everything else can be handled.
1407 ToolkitTestApplication application;
1409 tet_infoline( "UtcDaliVisualFactoryGetPrimitiveVisual1: Request primitive visual with a shape only" );
1411 //Set up visual properties.
1412 Property::Map propertyMap;
1413 propertyMap.Insert( Visual::Property::TYPE, Visual::PRIMITIVE );
1414 propertyMap.Insert( PrimitiveVisual::Property::SHAPE, PrimitiveVisual::Shape::CUBE );
1416 //Test to see if shape loads correctly.
1417 TestPrimitiveVisualWithProperties( propertyMap, application );
1422 //Test if primitive shape loads correctly when supplied with all possible parameters
1423 int UtcDaliVisualFactoryGetPrimitiveVisual2(void)
1425 //Set up test application first, so everything else can be handled.
1426 ToolkitTestApplication application;
1428 tet_infoline( "UtcDaliVisualFactoryGetPrimitiveVisual2: Request primitive visual with everything" );
1430 //Set up visual properties.
1431 Property::Map propertyMap;
1432 propertyMap.Insert( Visual::Property::TYPE, Visual::PRIMITIVE );
1433 propertyMap.Insert( PrimitiveVisual::Property::SHAPE, PrimitiveVisual::Shape::CUBE );
1434 propertyMap.Insert( PrimitiveVisual::Property::MIX_COLOR, Vector4( 0.5, 0.5, 0.5, 1.0 ) );
1435 propertyMap.Insert( PrimitiveVisual::Property::SLICES, 10 );
1436 propertyMap.Insert( PrimitiveVisual::Property::STACKS, 20 );
1437 propertyMap.Insert( PrimitiveVisual::Property::SCALE_TOP_RADIUS, 30.0f );
1438 propertyMap.Insert( PrimitiveVisual::Property::SCALE_BOTTOM_RADIUS, 40.0f );
1439 propertyMap.Insert( PrimitiveVisual::Property::SCALE_HEIGHT, 50.0f );
1440 propertyMap.Insert( PrimitiveVisual::Property::SCALE_RADIUS, 60.0f );
1441 propertyMap.Insert( PrimitiveVisual::Property::BEVEL_PERCENTAGE, 0.7f );
1442 propertyMap.Insert( PrimitiveVisual::Property::BEVEL_SMOOTHNESS, 0.8f );
1443 propertyMap.Insert( MeshVisual::Property::LIGHT_POSITION, Vector3( 0.9, 1.0, 1.1 ) );
1445 //Test to see if shape loads correctly.
1446 TestPrimitiveVisualWithProperties( propertyMap, application );
1451 //Test if primitive shape loads a sphere correctly.
1452 int UtcDaliVisualFactoryGetPrimitiveVisual3(void)
1454 //Set up test application first, so everything else can be handled.
1455 ToolkitTestApplication application;
1457 tet_infoline( "UtcDaliVisualFactoryGetPrimitiveVisual3: Request primitive visual to display a sphere" );
1459 //Set up visual properties.
1460 Property::Map propertyMap;
1461 propertyMap.Insert( Visual::Property::TYPE, Visual::PRIMITIVE );
1462 propertyMap.Insert( PrimitiveVisual::Property::SHAPE, PrimitiveVisual::Shape::SPHERE );
1463 propertyMap.Insert( PrimitiveVisual::Property::MIX_COLOR, Vector4( 0.5, 0.5, 0.5, 1.0 ) );
1464 propertyMap.Insert( PrimitiveVisual::Property::SLICES, 10 );
1465 propertyMap.Insert( PrimitiveVisual::Property::STACKS, 20 );
1467 //Test to see if shape loads correctly.
1468 TestPrimitiveVisualWithProperties( propertyMap, application );
1473 //Test if primitive shape loads a conic section correctly.
1474 int UtcDaliVisualFactoryGetPrimitiveVisual4(void)
1476 //Set up test application first, so everything else can be handled.
1477 ToolkitTestApplication application;
1479 tet_infoline( "UtcDaliVisualFactoryGetPrimitiveVisual4: Request primitive visual to display a conic section" );
1481 //Set up visual properties.
1482 Property::Map propertyMap;
1483 propertyMap.Insert( Visual::Property::TYPE, Visual::PRIMITIVE );
1484 propertyMap.Insert( PrimitiveVisual::Property::SHAPE, PrimitiveVisual::Shape::CONICAL_FRUSTRUM );
1485 propertyMap.Insert( PrimitiveVisual::Property::MIX_COLOR, Vector4( 0.5, 0.5, 0.5, 1.0 ) );
1486 propertyMap.Insert( PrimitiveVisual::Property::SLICES, 10 );
1487 propertyMap.Insert( PrimitiveVisual::Property::SCALE_TOP_RADIUS, 30.0f );
1488 propertyMap.Insert( PrimitiveVisual::Property::SCALE_BOTTOM_RADIUS, 40.0f );
1489 propertyMap.Insert( PrimitiveVisual::Property::SCALE_HEIGHT, 50.0f );
1491 //Test to see if shape loads correctly.
1492 TestPrimitiveVisualWithProperties( propertyMap, application );
1497 //Test if primitive shape loads a bevelled cube correctly.
1498 int UtcDaliVisualFactoryGetPrimitiveVisual5(void)
1500 //Set up test application first, so everything else can be handled.
1501 ToolkitTestApplication application;
1503 tet_infoline( "UtcDaliVisualFactoryGetPrimitiveVisual5: Request primitive visual to display a bevelled cube" );
1505 //Set up visual properties.
1506 Property::Map propertyMap;
1507 propertyMap.Insert( Visual::Property::TYPE, Visual::PRIMITIVE );
1508 propertyMap.Insert( PrimitiveVisual::Property::SHAPE, PrimitiveVisual::Shape::BEVELLED_CUBE );
1509 propertyMap.Insert( PrimitiveVisual::Property::MIX_COLOR, Vector4( 0.5, 0.5, 0.5, 1.0 ) );
1510 propertyMap.Insert( PrimitiveVisual::Property::BEVEL_PERCENTAGE, 0.7f );
1512 //Test to see if shape loads correctly.
1513 TestPrimitiveVisualWithProperties( propertyMap, application );
1518 //Test if primitive shape loads an octahedron correctly.
1519 int UtcDaliVisualFactoryGetPrimitiveVisual6(void)
1521 //Set up test application first, so everything else can be handled.
1522 ToolkitTestApplication application;
1524 tet_infoline( "UtcDaliVisualFactoryGetPrimitiveVisual6: Request primitive visual to display an octahedron" );
1526 //Set up visual properties.
1527 Property::Map propertyMap;
1528 propertyMap.Insert( Visual::Property::TYPE, Visual::PRIMITIVE );
1529 propertyMap.Insert( PrimitiveVisual::Property::SHAPE, PrimitiveVisual::Shape::OCTAHEDRON );
1530 propertyMap.Insert( PrimitiveVisual::Property::MIX_COLOR, Vector4( 0.5, 0.5, 0.5, 1.0 ) );
1532 //Test to see if shape loads correctly.
1533 TestPrimitiveVisualWithProperties( propertyMap, application );
1538 //Test if primitive shape loads a cone correctly.
1539 int UtcDaliVisualFactoryGetPrimitiveVisual7(void)
1541 //Set up test application first, so everything else can be handled.
1542 ToolkitTestApplication application;
1544 tet_infoline( "UtcDaliVisualFactoryGetPrimitiveVisual7: Request primitive visual to display a cone" );
1546 //Set up visual properties.
1547 Property::Map propertyMap;
1548 propertyMap.Insert( Visual::Property::TYPE, Visual::PRIMITIVE );
1549 propertyMap.Insert( PrimitiveVisual::Property::SHAPE, PrimitiveVisual::Shape::CONE );
1550 propertyMap.Insert( PrimitiveVisual::Property::MIX_COLOR, Vector4( 0.5, 0.5, 0.5, 1.0 ) );
1551 propertyMap.Insert( PrimitiveVisual::Property::SLICES, 10 );
1552 propertyMap.Insert( PrimitiveVisual::Property::SCALE_TOP_RADIUS, 30.0f );
1553 propertyMap.Insert( PrimitiveVisual::Property::SCALE_HEIGHT, 50.0f );
1555 //Test to see if shape loads correctly.
1556 TestPrimitiveVisualWithProperties( propertyMap, application );
1561 //Test if primitive shape loads correctly when light position is manually set.
1562 int UtcDaliVisualFactoryGetPrimitiveVisual8(void)
1564 //Set up test application first, so everything else can be handled.
1565 ToolkitTestApplication application;
1567 tet_infoline( "UtcDaliVisualFactoryGetPrimitiveVisual8: Request primitive visual with set light position" );
1569 //Set up visual properties.
1570 Property::Map propertyMap;
1571 propertyMap.Insert( Visual::Property::TYPE, Visual::PRIMITIVE );
1572 propertyMap.Insert( PrimitiveVisual::Property::SHAPE, PrimitiveVisual::Shape::SPHERE );
1573 propertyMap.Insert( PrimitiveVisual::Property::MIX_COLOR, Vector4( 0.5, 0.5, 0.5, 1.0 ) );
1574 propertyMap.Insert( MeshVisual::Property::LIGHT_POSITION, Vector3( 0.0, 1.0, 2.0 ) );
1576 //Test to see if shape loads correctly.
1577 TestPrimitiveVisualWithProperties( propertyMap, application );
1582 //Test if primitive shape loads correctly when told to use too many slices.
1583 int UtcDaliVisualFactoryGetPrimitiveVisual9(void)
1585 //Set up test application first, so everything else can be handled.
1586 ToolkitTestApplication application;
1588 tet_infoline( "UtcDaliVisualFactoryGetPrimitiveVisual9: Request primitive visual with above-cap slices." );
1590 //Set up visual properties.
1591 Property::Map propertyMap;
1592 propertyMap.Insert( Visual::Property::TYPE, Visual::PRIMITIVE );
1593 propertyMap.Insert( PrimitiveVisual::Property::SHAPE, PrimitiveVisual::Shape::SPHERE );
1594 propertyMap.Insert( PrimitiveVisual::Property::SLICES, Property::Value( 1000000 ) );
1596 //Test to see if shape loads correctly.
1597 TestPrimitiveVisualWithProperties( propertyMap, application );
1602 //Test if primitive shape loads correctly when told to use too few slices. (2 slices or less.)
1603 int UtcDaliVisualFactoryGetPrimitiveVisual10(void)
1605 //Set up test application first, so everything else can be handled.
1606 ToolkitTestApplication application;
1608 tet_infoline( "UtcDaliVisualFactoryGetPrimitiveVisual10: Request primitive visual with too few slices." );
1610 //Set up visual properties.
1611 Property::Map propertyMap;
1612 propertyMap.Insert( Visual::Property::TYPE, Visual::PRIMITIVE );
1613 propertyMap.Insert( PrimitiveVisual::Property::SHAPE, PrimitiveVisual::Shape::SPHERE );
1614 propertyMap.Insert( PrimitiveVisual::Property::SLICES, Property::Value( 2 ) );
1616 //Test to see if shape loads correctly.
1617 TestPrimitiveVisualWithProperties( propertyMap, application );
1622 //Test if primitive shape loads correctly when told to use too many stacks.
1623 int UtcDaliVisualFactoryGetPrimitiveVisual11(void)
1625 //Set up test application first, so everything else can be handled.
1626 ToolkitTestApplication application;
1628 tet_infoline( "UtcDaliVisualFactoryGetPrimitiveVisual11: Request primitive visual with too many stacks." );
1630 //Set up visual properties.
1631 Property::Map propertyMap;
1632 propertyMap.Insert( Visual::Property::TYPE, Visual::PRIMITIVE );
1633 propertyMap.Insert( PrimitiveVisual::Property::SHAPE, PrimitiveVisual::Shape::SPHERE );
1634 propertyMap.Insert( PrimitiveVisual::Property::STACKS, Property::Value( 1000000 ) );
1636 //Test to see if shape loads correctly.
1637 TestPrimitiveVisualWithProperties( propertyMap, application );
1642 //Test if primitive shape loads correctly when told to use too few stacks. (1 stack or less.)
1643 int UtcDaliVisualFactoryGetPrimitiveVisual12(void)
1645 //Set up test application first, so everything else can be handled.
1646 ToolkitTestApplication application;
1648 tet_infoline( "UtcDaliVisualFactoryGetPrimitiveVisual12: Request primitive visual with too few stacks." );
1650 //Set up visual properties.
1651 Property::Map propertyMap;
1652 propertyMap.Insert( Visual::Property::TYPE, Visual::PRIMITIVE );
1653 propertyMap.Insert( PrimitiveVisual::Property::SHAPE, PrimitiveVisual::Shape::SPHERE );
1654 propertyMap.Insert( PrimitiveVisual::Property::STACKS, Property::Value( 1 ) );
1656 //Test to see if shape loads correctly.
1657 TestPrimitiveVisualWithProperties( propertyMap, application );
1662 //Test if primitive shape loads correctly when told to use invalid (zero or negative) dimensions.
1663 int UtcDaliVisualFactoryGetPrimitiveVisual13(void)
1665 //Set up test application first, so everything else can be handled.
1666 ToolkitTestApplication application;
1668 tet_infoline( "UtcDaliVisualFactoryGetPrimitiveVisual13: Request primitive visual with invalid scale dimensions." );
1670 //Set up visual properties.
1671 Property::Map propertyMap;
1672 propertyMap.Insert( Visual::Property::TYPE, Visual::PRIMITIVE );
1673 propertyMap.Insert( PrimitiveVisual::Property::SHAPE, PrimitiveVisual::Shape::SPHERE );
1674 propertyMap.Insert( PrimitiveVisual::Property::SCALE_DIMENSIONS, Vector3::ZERO );
1676 //Test to see if shape loads correctly.
1677 TestPrimitiveVisualWithProperties( propertyMap, application );
1682 //Test if primitive shape loads correctly when told to use too low a bevel percentage.
1683 int UtcDaliVisualFactoryGetPrimitiveVisual14(void)
1685 //Set up test application first, so everything else can be handled.
1686 ToolkitTestApplication application;
1688 tet_infoline( "UtcDaliVisualFactoryGetPrimitiveVisual14: Request primitive visual with too low a bevel percentage." );
1690 //Set up visual properties.
1691 Property::Map propertyMap;
1692 propertyMap.Insert( Visual::Property::TYPE, Visual::PRIMITIVE );
1693 propertyMap.Insert( PrimitiveVisual::Property::SHAPE, PrimitiveVisual::Shape::SPHERE );
1694 propertyMap.Insert( PrimitiveVisual::Property::BEVEL_PERCENTAGE, Property::Value( -1.0f ) );
1696 //Test to see if shape loads correctly.
1697 TestPrimitiveVisualWithProperties( propertyMap, application );
1702 //Test if primitive shape loads correctly when told to use too high a bevel percentage.
1703 int UtcDaliVisualFactoryGetPrimitiveVisual15(void)
1705 //Set up test application first, so everything else can be handled.
1706 ToolkitTestApplication application;
1708 tet_infoline( "UtcDaliVisualFactoryGetPrimitiveVisual15: Request primitive visual with too high a bevel percentage." );
1710 //Set up visual properties.
1711 Property::Map propertyMap;
1712 propertyMap.Insert( Visual::Property::TYPE, Visual::PRIMITIVE );
1713 propertyMap.Insert( PrimitiveVisual::Property::SHAPE, PrimitiveVisual::Shape::SPHERE );
1714 propertyMap.Insert( PrimitiveVisual::Property::BEVEL_PERCENTAGE, Property::Value( 2.0f ) );
1716 //Test to see if shape loads correctly.
1717 TestPrimitiveVisualWithProperties( propertyMap, application );
1722 //Test if primitive shape loads correctly when told to use too low a bevel smoothness.
1723 int UtcDaliVisualFactoryGetPrimitiveVisual16(void)
1725 //Set up test application first, so everything else can be handled.
1726 ToolkitTestApplication application;
1728 tet_infoline( "UtcDaliVisualFactoryGetPrimitiveVisual16: Request primitive visual with too low a bevel smoothness." );
1730 //Set up visual properties.
1731 Property::Map propertyMap;
1732 propertyMap.Insert( Visual::Property::TYPE, Visual::PRIMITIVE );
1733 propertyMap.Insert( PrimitiveVisual::Property::SHAPE, PrimitiveVisual::Shape::SPHERE );
1734 propertyMap.Insert( PrimitiveVisual::Property::BEVEL_SMOOTHNESS, Property::Value( -1.0f ) );
1736 //Test to see if shape loads correctly.
1737 TestPrimitiveVisualWithProperties( propertyMap, application );
1742 //Test if primitive shape loads correctly when told to use too high a bevel smoothness.
1743 int UtcDaliVisualFactoryGetPrimitiveVisual17(void)
1745 //Set up test application first, so everything else can be handled.
1746 ToolkitTestApplication application;
1748 tet_infoline( "UtcDaliVisualFactoryGetPrimitiveVisual17: Request primitive visual with too high a bevel smoothness." );
1750 //Set up visual properties.
1751 Property::Map propertyMap;
1752 propertyMap.Insert( Visual::Property::TYPE, Visual::PRIMITIVE );
1753 propertyMap.Insert( PrimitiveVisual::Property::SHAPE, PrimitiveVisual::Shape::SPHERE );
1754 propertyMap.Insert( PrimitiveVisual::Property::BEVEL_SMOOTHNESS, Property::Value( 2.0f ) );
1756 //Test to see if shape loads correctly.
1757 TestPrimitiveVisualWithProperties( propertyMap, application );
1762 //Test if primitive shape visual handles the case of not being passed a specific shape to use.
1763 int UtcDaliVisualFactoryGetPrimitiveVisualN1(void)
1765 //Set up test application first, so everything else can be handled.
1766 ToolkitTestApplication application;
1768 tet_infoline( "UtcDaliVisualFactoryGetPrimitiveVisualN1: Request primitive visual without shape" );
1770 //Set up visual properties, without supplying shape.
1771 Property::Map propertyMap;
1772 propertyMap.Insert( Visual::Property::TYPE, Visual::PRIMITIVE );
1774 //Test to see if shape loads regardless of missing input.
1775 TestPrimitiveVisualWithProperties( propertyMap, application );
1780 int UtcDaliVisualFactoryGetAnimatedImageVisual1(void)
1782 ToolkitTestApplication application;
1783 tet_infoline( "UtcDaliVisualFactoryGetAnimatedImageVisual1: Request animated image visual with a gif url" );
1785 VisualFactory factory = VisualFactory::Get();
1786 Visual::Base visual = factory.CreateVisual( TEST_GIF_FILE_NAME, ImageDimensions() );
1787 DALI_TEST_CHECK( visual );
1789 TestGlAbstraction& gl = application.GetGlAbstraction();
1790 TraceCallStack& textureTrace = gl.GetTextureTrace();
1791 textureTrace.Enable(true);
1793 DummyControl actor = DummyControl::New();
1794 DummyControlImpl& dummyImpl = static_cast<DummyControlImpl&>(actor.GetImplementation());
1795 dummyImpl.RegisterVisual( Control::CONTROL_PROPERTY_END_INDEX + 1, visual );
1796 actor.SetSize( 200.0f, 200.0f );
1797 Stage::GetCurrent().Add( actor );
1799 application.SendNotification();
1800 application.Render();
1802 // renderer is added to actor
1803 DALI_TEST_CHECK( actor.GetRendererCount() == 1u );
1805 // test the uniforms which used to handle the atlas rect
1806 // the four frames should be located inside atlas as follows: atlas size 100*100
1815 Renderer renderer = actor.GetRendererAt( 0u );
1816 DALI_TEST_CHECK( renderer );
1818 Property::Value atlasRectValue = renderer.GetProperty( renderer.GetPropertyIndex( "uAtlasRect" ) );
1819 // take into consideration the half pixel correction
1820 DALI_TEST_EQUALS( atlasRectValue.Get<Vector4>(), Vector4(0.5f, 0.5f, 49.5f, 49.5f)/100.f, Math::MACHINE_EPSILON_100, TEST_LOCATION );
1822 // waiting for the resource uploading
1823 application.SendNotification();
1824 application.Render();
1826 DALI_TEST_EQUALS( textureTrace.FindMethod("BindTexture"), true, TEST_LOCATION );
1828 // Force the timer used by the animatedImageVisual to tick,
1829 Dali::Timer timer = Timer::New( 0 );
1830 timer.MockEmitSignal();
1831 application.SendNotification();
1832 application.Render();
1833 atlasRectValue = renderer.GetProperty( renderer.GetPropertyIndex( "uAtlasRect" ) );
1834 // take into consideration the half pixel correction
1835 DALI_TEST_EQUALS( atlasRectValue.Get<Vector4>(), Vector4(50.5f, 0.5f, 99.5f, 49.5f)/100.f, Math::MACHINE_EPSILON_100, TEST_LOCATION );
1837 // Force the timer used by the animatedImageVisual to tick,
1838 timer.MockEmitSignal();
1839 application.SendNotification();
1840 application.Render();
1841 atlasRectValue = renderer.GetProperty( renderer.GetPropertyIndex( "uAtlasRect" ) );
1842 // take into consideration the half pixel correction
1843 DALI_TEST_EQUALS( atlasRectValue.Get<Vector4>(), Vector4(0.5f, 50.5f, 49.5f, 99.5f)/100.f, Math::MACHINE_EPSILON_100, TEST_LOCATION );
1845 // Force the timer used by the animatedImageVisual to tick,
1846 timer.MockEmitSignal();
1847 application.SendNotification();
1848 application.Render();
1849 atlasRectValue = renderer.GetProperty( renderer.GetPropertyIndex( "uAtlasRect" ) );
1850 // take into consideration the half pixel correction
1851 DALI_TEST_EQUALS( atlasRectValue.Get<Vector4>(), Vector4(50.5f, 50.5f, 99.5f, 99.5f)/100.f, Math::MACHINE_EPSILON_100, TEST_LOCATION );
1853 // Test SetOffStage().
1855 DALI_TEST_CHECK( actor.GetRendererCount() == 0u );
1860 int UtcDaliVisualFactoryGetAnimatedImageVisual2(void)
1862 ToolkitTestApplication application;
1863 tet_infoline( "UtcDaliVisualFactoryGetAnimatedImageVisual2: Request animated image visual with a Property::Map, test custom wrap mode and pixel area" );
1865 const Vector4 pixelArea(-0.5f, -0.5f, 2.f, 2.f);
1866 Property::Map propertyMap;
1867 propertyMap.Add( Visual::Property::TYPE, Visual::IMAGE )
1868 .Add( ImageVisual::Property::URL, TEST_GIF_FILE_NAME )
1869 .Add( ImageVisual::Property::PIXEL_AREA, pixelArea )
1870 .Add( ImageVisual::Property::WRAP_MODE_U, WrapMode::MIRRORED_REPEAT )
1871 .Add( ImageVisual::Property::WRAP_MODE_V, WrapMode::REPEAT );
1873 Visual::Base visual = VisualFactory::Get().CreateVisual( propertyMap );
1874 DALI_TEST_CHECK( visual );
1876 TestGlAbstraction& gl = application.GetGlAbstraction();
1877 TraceCallStack& textureTrace = gl.GetTextureTrace();
1878 textureTrace.Enable(true);
1879 TraceCallStack& texParameterTrace = gl.GetTexParameterTrace();
1880 texParameterTrace.Enable( true );
1882 DummyControl actor = DummyControl::New();
1883 DummyControlImpl& dummyImpl = static_cast<DummyControlImpl&>(actor.GetImplementation());
1884 dummyImpl.RegisterVisual( Control::CONTROL_PROPERTY_END_INDEX + 1, visual );
1885 actor.SetSize( 200.0f, 200.0f );
1886 Stage::GetCurrent().Add( actor );
1888 application.SendNotification();
1889 application.Render();
1891 DALI_TEST_CHECK( actor.GetRendererCount() == 1u );
1893 DALI_TEST_EQUALS( textureTrace.FindMethod("BindTexture"), true, TEST_LOCATION );
1895 // For animated image visual, the wrapping is handled manually in shader, so the following gl function should not be called
1896 std::stringstream out;
1897 out << GL_TEXTURE_2D << ", " << GL_TEXTURE_WRAP_S << ", " << GL_MIRRORED_REPEAT;
1898 DALI_TEST_CHECK( !texParameterTrace.FindMethodAndParams("TexParameteri", out.str()) );
1900 out << GL_TEXTURE_2D << ", " << GL_TEXTURE_WRAP_T << ", " << GL_REPEAT;
1901 DALI_TEST_CHECK( !texParameterTrace.FindMethodAndParams("TexParameteri", out.str()) );
1903 // test the uniforms which used to handle the wrap mode
1904 Renderer renderer = actor.GetRendererAt( 0u );
1905 DALI_TEST_CHECK( renderer );
1907 Property::Value pixelAreaValue = renderer.GetProperty( renderer.GetPropertyIndex( "pixelArea" ) );
1908 DALI_TEST_EQUALS( pixelAreaValue.Get<Vector4>(), pixelArea, TEST_LOCATION );
1909 Vector4 pixelAreaUniform;
1910 DALI_TEST_CHECK( gl.GetUniformValue<Vector4>( "pixelArea", pixelAreaUniform ) );
1911 DALI_TEST_EQUALS( pixelArea, pixelAreaUniform, Math::MACHINE_EPSILON_100, TEST_LOCATION );
1913 Property::Value wrapModeValue = renderer.GetProperty( renderer.GetPropertyIndex( "wrapMode" ) );
1914 Vector2 wrapMode( WrapMode::MIRRORED_REPEAT-1, WrapMode::REPEAT-1 );
1915 DALI_TEST_EQUALS( wrapModeValue.Get<Vector2>(), wrapMode, TEST_LOCATION );
1916 Vector2 wrapModeUniform;
1917 DALI_TEST_CHECK( gl.GetUniformValue<Vector2>( "wrapMode", wrapModeUniform ) );
1918 DALI_TEST_EQUALS( wrapMode, wrapModeUniform, Math::MACHINE_EPSILON_100, TEST_LOCATION );
1921 DALI_TEST_CHECK( actor.GetRendererCount() == 0u );