X-Git-Url: http://review.tizen.org/git/?a=blobdiff_plain;f=automated-tests%2Fsrc%2Fdali-toolkit%2Futc-Dali-VisualFactory.cpp;h=c1f7d0094e922255524cb12a459c689b998d6b1a;hb=98de7da7b7768f266b3e9579ede04ec421bfe596;hp=ae8761fb46c8cac67e9e345a1b3e89c84cd75afd;hpb=be7711b99f7e5db0b712194636745045d4da1154;p=platform%2Fcore%2Fuifw%2Fdali-toolkit.git diff --git a/automated-tests/src/dali-toolkit/utc-Dali-VisualFactory.cpp b/automated-tests/src/dali-toolkit/utc-Dali-VisualFactory.cpp index ae8761f..c1f7d00 100644 --- a/automated-tests/src/dali-toolkit/utc-Dali-VisualFactory.cpp +++ b/automated-tests/src/dali-toolkit/utc-Dali-VisualFactory.cpp @@ -1,5 +1,5 @@ /* - * Copyright (c) 2016 Samsung Electronics Co., Ltd. + * Copyright (c) 2017 Samsung Electronics Co., Ltd. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -17,6 +17,7 @@ #include #include #include +#include #include #include #include @@ -24,7 +25,7 @@ #include #include #include -#include +#include #include #include #include "dummy-control.h" @@ -44,6 +45,9 @@ const char* TEST_MTL_FILE_NAME = TEST_RESOURCE_DIR "/ToyRobot-Metal.mtl"; const char* TEST_SIMPLE_OBJ_FILE_NAME = TEST_RESOURCE_DIR "/Cube-Points-Only.obj"; const char* TEST_SIMPLE_MTL_FILE_NAME = TEST_RESOURCE_DIR "/ToyRobot-Metal-Simple.mtl"; +// resolution: 50*50, frame count: 4, frame delay: 0.2 second for each frame +const char* TEST_GIF_FILE_NAME = TEST_RESOURCE_DIR "/anim.gif"; + // resolution: 34*34, pixel format: RGBA8888 static const char* gImage_34_RGBA = TEST_RESOURCE_DIR "/icon-edit.png"; // resolution: 600*600, pixel format: RGB888 @@ -53,11 +57,12 @@ Property::Map DefaultTransform() { Property::Map transformMap; transformMap - .Add( Toolkit::VisualProperty::Transform::Property::OFFSET, Vector2(0.0f, 0.0f) ) - .Add( Toolkit::VisualProperty::Transform::Property::SIZE, Vector2(1.0f, 1.0f) ) - .Add( Toolkit::VisualProperty::Transform::Property::ORIGIN, Toolkit::Align::CENTER ) - .Add( Toolkit::VisualProperty::Transform::Property::ANCHOR_POINT, Toolkit::Align::CENTER ) - .Add( Toolkit::VisualProperty::Transform::Property::OFFSET_SIZE_MODE, Vector4::ZERO ); + .Add( Toolkit::DevelVisual::Transform::Property::OFFSET, Vector2(0.0f, 0.0f) ) + .Add( Toolkit::DevelVisual::Transform::Property::SIZE, Vector2(1.0f, 1.0f) ) + .Add( Toolkit::DevelVisual::Transform::Property::ORIGIN, Toolkit::Align::CENTER ) + .Add( Toolkit::DevelVisual::Transform::Property::ANCHOR_POINT, Toolkit::Align::CENTER ) + .Add( Toolkit::DevelVisual::Transform::Property::OFFSET_POLICY, Vector2( Toolkit::DevelVisual::Transform::Policy::RELATIVE, Toolkit::DevelVisual::Transform::Policy::RELATIVE ) ) + .Add( Toolkit::DevelVisual::Transform::Property::SIZE_POLICY, Vector2( Toolkit::DevelVisual::Transform::Policy::RELATIVE, Toolkit::DevelVisual::Transform::Policy::RELATIVE ) ); return transformMap; } @@ -219,22 +224,12 @@ void TestVisualRender( ToolkitTestApplication& application, application.SendNotification(); application.Render(); - if( resourcePtr ) - { - Integration::ResourceRequest* request = application.GetPlatform().GetRequest(); - if(request) - { - application.GetPlatform().SetResourceLoaded(request->GetId(), request->GetType()->id, resourcePtr ); - } - } - application.Render(); application.SendNotification(); if( resourcePtr ) { - DALI_TEST_EQUALS( application.GetPlatform().WasCalled(TestPlatformAbstraction::LoadResourceFunc) || - application.GetPlatform().WasCalled(TestPlatformAbstraction::LoadResourceSynchronouslyFunc ), true, TEST_LOCATION); + DALI_TEST_EQUALS( application.GetPlatform().WasCalled(TestPlatformAbstraction::LoadResourceSynchronouslyFunc ), true, TEST_LOCATION); } DALI_TEST_EQUALS( actor.GetRendererCount(), 1u, TEST_LOCATION ); @@ -326,10 +321,13 @@ int UtcDaliVisualFactoryGetColorVisual1(void) DummyControl actor = DummyControl::New(); TestVisualRender( application, actor, visual ); - Vector4 actualValue(Vector4::ZERO); + Vector3 actualValue(Vector4::ZERO); + float opacity=0.0f; TestGlAbstraction& gl = application.GetGlAbstraction(); - DALI_TEST_CHECK( gl.GetUniformValue( "mixColor", actualValue ) ); - DALI_TEST_EQUALS( actualValue, testColor, TEST_LOCATION ); + DALI_TEST_CHECK( gl.GetUniformValue( "mixColor", actualValue ) ); + DALI_TEST_CHECK( gl.GetUniformValue( "opacity", opacity ) ); + DALI_TEST_EQUALS( actualValue, Vector3(testColor), TEST_LOCATION ); + DALI_TEST_EQUALS( opacity, testColor.a, TEST_LOCATION ); END_TEST; } @@ -352,10 +350,13 @@ int UtcDaliVisualFactoryGetColorVisual2(void) DummyControl actor = DummyControl::New(); TestVisualRender( application, actor, visual ); - Vector4 actualValue(Vector4::ZERO); + Vector3 actualValue; + float opacity; TestGlAbstraction& gl = application.GetGlAbstraction(); - DALI_TEST_CHECK( gl.GetUniformValue( "mixColor", actualValue ) ); - DALI_TEST_EQUALS( actualValue, testColor, TEST_LOCATION ); + DALI_TEST_CHECK( gl.GetUniformValue( "mixColor", actualValue ) ); + DALI_TEST_CHECK( gl.GetUniformValue( "opacity", opacity ) ); + DALI_TEST_EQUALS( actualValue, Vector3(testColor), TEST_LOCATION ); + DALI_TEST_EQUALS( opacity, testColor.a, TEST_LOCATION ); Stage::GetCurrent().Remove(actor); DALI_TEST_CHECK( actor.GetRendererCount() == 0u ); @@ -1224,10 +1225,6 @@ void MeshVisualLoadsCorrectlyTest( Property::Map& propertyMap, ToolkitTestApplic application.SendNotification(); application.Render( 0 ); - //Tell the platform abstraction that the required resources have been loaded. - TestPlatformAbstraction& platform = application.GetPlatform(); - platform.SetAllResourceRequestsAsLoaded(); - //Render again to upload the now-loaded textures. application.SendNotification(); application.Render( 0 ); @@ -1271,10 +1268,6 @@ void MeshVisualDoesNotLoadCorrectlyTest( Property::Map& propertyMap, ToolkitTest application.SendNotification(); application.Render( 0 ); - //Tell the platform abstraction that the required resources have been loaded. - TestPlatformAbstraction& platform = application.GetPlatform(); - platform.SetAllResourceRequestsAsLoaded(); - //Render again to upload the now-loaded textures. application.SendNotification(); application.Render( 0 ); @@ -1330,6 +1323,30 @@ int UtcDaliVisualFactoryGetMeshVisual2(void) END_TEST; } +//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 +int UtcDaliVisualFactoryGetMeshVisual3b(void) +{ + //Set up test application first, so everything else can be handled. + ToolkitTestApplication application; + + tet_infoline( "UtcDaliVisualFactoryGetMeshVisual3: Request mesh visual with all parameters correct" ); + + //Set up visual properties. + Property::Map propertyMap; + propertyMap.Insert( Visual::Property::TYPE, Visual::MESH ); + propertyMap.Insert( MeshVisual::Property::OBJECT_URL, TEST_OBJ_FILE_NAME ); + propertyMap.Insert( MeshVisual::Property::MATERIAL_URL, TEST_MTL_FILE_NAME ); + propertyMap.Insert( MeshVisual::Property::USE_MIPMAPPING, Color::GREEN ); // Test that wrong property types don't prevent the object load + propertyMap.Insert( MeshVisual::Property::USE_SOFT_NORMALS, 1.0f ); + propertyMap.Insert( MeshVisual::Property::LIGHT_POSITION, 1.0f ); + propertyMap.Insert( MeshVisual::Property::TEXTURES_PATH, TEST_RESOURCE_DIR "/" ); + + //Test to see if mesh loads correctly. + MeshVisualLoadsCorrectlyTest( propertyMap, application ); + + END_TEST; +} + //Test if mesh loads correctly when supplied with all main parameters, an object file, a material file and a directory location. int UtcDaliVisualFactoryGetMeshVisual3(void) { @@ -1343,6 +1360,9 @@ int UtcDaliVisualFactoryGetMeshVisual3(void) propertyMap.Insert( Visual::Property::TYPE, Visual::MESH ); propertyMap.Insert( MeshVisual::Property::OBJECT_URL, TEST_OBJ_FILE_NAME ); propertyMap.Insert( MeshVisual::Property::MATERIAL_URL, TEST_MTL_FILE_NAME ); + propertyMap.Insert( MeshVisual::Property::USE_MIPMAPPING, false ); + propertyMap.Insert( MeshVisual::Property::USE_SOFT_NORMALS, false ); + propertyMap.Insert( MeshVisual::Property::LIGHT_POSITION, Vector3::XAXIS ); propertyMap.Insert( MeshVisual::Property::TEXTURES_PATH, TEST_RESOURCE_DIR "/" ); //Test to see if mesh loads correctly. @@ -1370,7 +1390,6 @@ int UtcDaliVisualFactoryGetMeshVisual4(void) //Test to see if mesh loads correctly. MeshVisualLoadsCorrectlyTest( propertyMap, application ); - END_TEST; } @@ -1385,10 +1404,13 @@ int UtcDaliVisualFactoryGetMeshVisual5(void) //Set up visual properties. Property::Map propertyMap; propertyMap.Insert( Visual::Property::TYPE, Visual::MESH ); - propertyMap.Insert( MeshVisual::Property::OBJECT_URL, TEST_OBJ_FILE_NAME ); - propertyMap.Insert( MeshVisual::Property::MATERIAL_URL, TEST_MTL_FILE_NAME ); - propertyMap.Insert( MeshVisual::Property::TEXTURES_PATH, TEST_RESOURCE_DIR "/" ); - propertyMap.Insert( MeshVisual::Property::SHADING_MODE, MeshVisual::ShadingMode::TEXTURED_WITH_SPECULAR_LIGHTING ); + propertyMap.Insert( "objectUrl", TEST_OBJ_FILE_NAME ); + propertyMap.Insert( "materialUrl", TEST_MTL_FILE_NAME ); + propertyMap.Insert( "texturesPath", TEST_RESOURCE_DIR "/" ); + propertyMap.Insert( "useMipmapping", false ); + propertyMap.Insert( "useSoftNormals", false ); + propertyMap.Insert( "lightPosition", Vector3::ZAXIS ); + propertyMap.Insert( "shadingMode", MeshVisual::ShadingMode::TEXTURED_WITH_SPECULAR_LIGHTING ); //Test to see if mesh loads correctly. MeshVisualLoadsCorrectlyTest( propertyMap, application ); @@ -1943,35 +1965,78 @@ int UtcDaliVisualFactoryGetPrimitiveVisualN1(void) END_TEST; } -int UtcDaliVisualFactoryGetBatchImageVisual1(void) +int UtcDaliVisualFactoryGetAnimatedImageVisual1(void) { ToolkitTestApplication application; - tet_infoline( "UtcDaliVisualFactoryGetBatchImageVisual1: Request a Batch Image visual with a Property::Map" ); + tet_infoline( "UtcDaliVisualFactoryGetAnimatedImageVisual1: Request animated image visual with a gif url" ); VisualFactory factory = VisualFactory::Get(); - DALI_TEST_CHECK( factory ); - - Property::Map propertyMap; - propertyMap.Insert( Visual::Property::TYPE, Visual::IMAGE ); - propertyMap.Insert( ImageVisual::Property::BATCHING_ENABLED, true ); - propertyMap.Insert( ImageVisual::Property::URL, TEST_IMAGE_FILE_NAME ); - - Visual::Base visual = factory.CreateVisual( propertyMap ); + Visual::Base visual = factory.CreateVisual( TEST_GIF_FILE_NAME, ImageDimensions() ); DALI_TEST_CHECK( visual ); + TestGlAbstraction& gl = application.GetGlAbstraction(); + TraceCallStack& textureTrace = gl.GetTextureTrace(); + textureTrace.Enable(true); + DummyControl actor = DummyControl::New(); DummyControlImpl& dummyImpl = static_cast(actor.GetImplementation()); dummyImpl.RegisterVisual( Control::CONTROL_PROPERTY_END_INDEX + 1, visual ); - actor.SetSize( 200.0f, 200.0f ); Stage::GetCurrent().Add( actor ); - visual.SetTransformAndSize(DefaultTransform(), Vector2( 200.0f, 200.0f ) ); - // Test SetOnStage(). + application.SendNotification(); + application.Render(); + + // renderer is added to actor DALI_TEST_CHECK( actor.GetRendererCount() == 1u ); + // test the uniforms which used to handle the atlas rect + // the four frames should be located inside atlas as follows: atlas size 100*100 + // ------------- + // | | | + // | 0 | 1 | + // ------------- + // | | | + // | 2 | 3 | + // ------------- + + Renderer renderer = actor.GetRendererAt( 0u ); + DALI_TEST_CHECK( renderer ); + + Property::Value atlasRectValue = renderer.GetProperty( renderer.GetPropertyIndex( "uAtlasRect" ) ); + // take into consideration the half pixel correction + DALI_TEST_EQUALS( atlasRectValue.Get(), Vector4(0.5f, 0.5f, 49.5f, 49.5f)/100.f, Math::MACHINE_EPSILON_100, TEST_LOCATION ); + + // waiting for the resource uploading + application.SendNotification(); + application.Render(); + + DALI_TEST_EQUALS( textureTrace.FindMethod("BindTexture"), true, TEST_LOCATION ); + + // Force the timer used by the animatedImageVisual to tick, + Dali::Timer timer = Timer::New( 0 ); + timer.MockEmitSignal(); + application.SendNotification(); + application.Render(); + atlasRectValue = renderer.GetProperty( renderer.GetPropertyIndex( "uAtlasRect" ) ); + // take into consideration the half pixel correction + DALI_TEST_EQUALS( atlasRectValue.Get(), Vector4(50.5f, 0.5f, 99.5f, 49.5f)/100.f, Math::MACHINE_EPSILON_100, TEST_LOCATION ); + + // Force the timer used by the animatedImageVisual to tick, + timer.MockEmitSignal(); + application.SendNotification(); + application.Render(); + atlasRectValue = renderer.GetProperty( renderer.GetPropertyIndex( "uAtlasRect" ) ); + // take into consideration the half pixel correction + DALI_TEST_EQUALS( atlasRectValue.Get(), Vector4(0.5f, 50.5f, 49.5f, 99.5f)/100.f, Math::MACHINE_EPSILON_100, TEST_LOCATION ); + + // Force the timer used by the animatedImageVisual to tick, + timer.MockEmitSignal(); application.SendNotification(); application.Render(); + atlasRectValue = renderer.GetProperty( renderer.GetPropertyIndex( "uAtlasRect" ) ); + // take into consideration the half pixel correction + DALI_TEST_EQUALS( atlasRectValue.Get(), Vector4(50.5f, 50.5f, 99.5f, 99.5f)/100.f, Math::MACHINE_EPSILON_100, TEST_LOCATION ); // Test SetOffStage(). actor.Unparent(); @@ -1980,74 +2045,68 @@ int UtcDaliVisualFactoryGetBatchImageVisual1(void) END_TEST; } -int UtcDaliVisualFactoryGetBatchImageVisual2(void) +int UtcDaliVisualFactoryGetAnimatedImageVisual2(void) { ToolkitTestApplication application; - tet_infoline( "UtcDaliVisualFactoryGetBatchImageVisual2: Request Batch Image visual from an Image Visual with batchingEnabled set" ); - - VisualFactory factory = VisualFactory::Get(); - DALI_TEST_CHECK( factory ); + tet_infoline( "UtcDaliVisualFactoryGetAnimatedImageVisual2: Request animated image visual with a Property::Map, test custom wrap mode and pixel area" ); + const Vector4 pixelArea(-0.5f, -0.5f, 2.f, 2.f); Property::Map propertyMap; - // Create a normal Image Visual. - propertyMap.Insert( Visual::Property::TYPE, Visual::IMAGE ); - // Instruct the factory to change Image Visuals to Batch-Image Visuals. - propertyMap.Insert( ImageVisual::Property::BATCHING_ENABLED, true ); + propertyMap.Add( Visual::Property::TYPE, Visual::IMAGE ) + .Add( ImageVisual::Property::URL, TEST_GIF_FILE_NAME ) + .Add( ImageVisual::Property::PIXEL_AREA, pixelArea ) + .Add( ImageVisual::Property::WRAP_MODE_U, WrapMode::MIRRORED_REPEAT ) + .Add( ImageVisual::Property::WRAP_MODE_V, WrapMode::REPEAT ); - // Properties for the Batch-Image Visual. - propertyMap.Insert( ImageVisual::Property::URL, TEST_IMAGE_FILE_NAME ); - - Visual::Base visual = factory.CreateVisual( propertyMap ); + Visual::Base visual = VisualFactory::Get().CreateVisual( propertyMap ); DALI_TEST_CHECK( visual ); - // Check that a Batch-Image visual was created instead of an Image visual. - Property::Map resultMap; - visual.CreatePropertyMap( resultMap ); - - Property::Value* value = resultMap.Find( Visual::Property::TYPE, Property::INTEGER ); - DALI_TEST_CHECK( value ); - DALI_TEST_EQUALS( value->Get(), (int)Visual::IMAGE, TEST_LOCATION ); + TestGlAbstraction& gl = application.GetGlAbstraction(); + TraceCallStack& textureTrace = gl.GetTextureTrace(); + textureTrace.Enable(true); + TraceCallStack& texParameterTrace = gl.GetTexParameterTrace(); + texParameterTrace.Enable( true ); DummyControl actor = DummyControl::New(); DummyControlImpl& dummyImpl = static_cast(actor.GetImplementation()); dummyImpl.RegisterVisual( Control::CONTROL_PROPERTY_END_INDEX + 1, visual ); - actor.SetSize( 200.0f, 200.0f ); Stage::GetCurrent().Add( actor ); - visual.SetTransformAndSize(DefaultTransform(), Vector2( 200.0f, 200.0f ) ); - - // Test SetOnStage(). - DALI_TEST_CHECK( actor.GetRendererCount() == 1u ); application.SendNotification(); application.Render(); - // Test SetOffStage(). - actor.Unparent(); - DALI_TEST_CHECK( actor.GetRendererCount() == 0u ); + DALI_TEST_CHECK( actor.GetRendererCount() == 1u ); - END_TEST; -} + DALI_TEST_EQUALS( textureTrace.FindMethod("BindTexture"), true, TEST_LOCATION ); -int UtcDaliVisualFactoryGetBatchImageVisual3(void) -{ - ToolkitTestApplication application; - tet_infoline( "UtcDaliVisualFactoryGetBatchImageVisual3: Create an ImageView that uses a batched visual internally" ); + // For animated image visual, the wrapping is handled manually in shader, so the following gl function should not be called + std::stringstream out; + out << GL_TEXTURE_2D << ", " << GL_TEXTURE_WRAP_S << ", " << GL_MIRRORED_REPEAT; + DALI_TEST_CHECK( !texParameterTrace.FindMethodAndParams("TexParameteri", out.str()) ); + out.str(""); + out << GL_TEXTURE_2D << ", " << GL_TEXTURE_WRAP_T << ", " << GL_REPEAT; + DALI_TEST_CHECK( !texParameterTrace.FindMethodAndParams("TexParameteri", out.str()) ); - VisualFactory factory = VisualFactory::Get(); - DALI_TEST_CHECK( factory ); + // test the uniforms which used to handle the wrap mode + Renderer renderer = actor.GetRendererAt( 0u ); + DALI_TEST_CHECK( renderer ); - // Create a property-map that enables batching. - Property::Map propertyMap; - propertyMap.Insert( Dali::Toolkit::ImageVisual::Property::URL, TEST_IMAGE_FILE_NAME ); - propertyMap.Insert( ImageVisual::Property::BATCHING_ENABLED, true ); + Property::Value pixelAreaValue = renderer.GetProperty( renderer.GetPropertyIndex( "pixelArea" ) ); + DALI_TEST_EQUALS( pixelAreaValue.Get(), pixelArea, TEST_LOCATION ); + Vector4 pixelAreaUniform; + DALI_TEST_CHECK( gl.GetUniformValue( "pixelArea", pixelAreaUniform ) ); + DALI_TEST_EQUALS( pixelArea, pixelAreaUniform, Math::MACHINE_EPSILON_100, TEST_LOCATION ); - // Create an ImageView, passing the property-map in to instruct it to use batching. - Toolkit::ImageView imageView = Toolkit::ImageView::New(); - imageView.SetProperty( Toolkit::ImageView::Property::IMAGE, propertyMap ); + Property::Value wrapModeValue = renderer.GetProperty( renderer.GetPropertyIndex( "wrapMode" ) ); + Vector2 wrapMode( WrapMode::MIRRORED_REPEAT-1, WrapMode::REPEAT-1 ); + DALI_TEST_EQUALS( wrapModeValue.Get(), wrapMode, TEST_LOCATION ); + Vector2 wrapModeUniform; + DALI_TEST_CHECK( gl.GetUniformValue( "wrapMode", wrapModeUniform ) ); + DALI_TEST_EQUALS( wrapMode, wrapModeUniform, Math::MACHINE_EPSILON_100, TEST_LOCATION ); - imageView.SetSize( 200.0f, 200.0f ); - Stage::GetCurrent().Add( imageView ); + actor.Unparent( ); + DALI_TEST_CHECK( actor.GetRendererCount() == 0u ); END_TEST; }