X-Git-Url: http://review.tizen.org/git/?a=blobdiff_plain;f=automated-tests%2Fsrc%2Fdali%2Futc-Dali-Geometry.cpp;h=ab99c5964f2b070ab7743ca9e5121e4274e137fe;hb=910059be77e79b5f788c04ff7b9eb066a712ee26;hp=cddb8b4d8d20a0fb71ee6f0850feca24a2f67a0c;hpb=b2d687369c19f14d76be52ced7f1dcc30116d2c1;p=platform%2Fcore%2Fuifw%2Fdali-core.git diff --git a/automated-tests/src/dali/utc-Dali-Geometry.cpp b/automated-tests/src/dali/utc-Dali-Geometry.cpp index cddb8b4..ab99c59 100644 --- a/automated-tests/src/dali/utc-Dali-Geometry.cpp +++ b/automated-tests/src/dali/utc-Dali-Geometry.cpp @@ -1,5 +1,5 @@ /* - * Copyright (c) 2015 Samsung Electronics Co., Ltd. + * Copyright (c) 2016 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. @@ -34,6 +34,29 @@ void geometry_test_cleanup(void) namespace { + +struct TexturedQuadVertex { Vector2 position; Vector2 textureCoordinates; }; + +PropertyBuffer CreateVertexBuffer( const std::string& aPosition, const std::string& aTexCoord ) +{ + const float halfQuadSize = .5f; + TexturedQuadVertex texturedQuadVertexData[4] = { + { Vector2(-halfQuadSize, -halfQuadSize), Vector2(0.f, 0.f) }, + { Vector2( halfQuadSize, -halfQuadSize), Vector2(1.f, 0.f) }, + { Vector2(-halfQuadSize, halfQuadSize), Vector2(0.f, 1.f) }, + { Vector2( halfQuadSize, halfQuadSize), Vector2(1.f, 1.f) } }; + + Property::Map vertexFormat; + vertexFormat[aPosition] = Property::VECTOR2; + vertexFormat[aTexCoord] = Property::VECTOR2; + + PropertyBuffer vertexData = PropertyBuffer::New( vertexFormat ); + vertexData.SetData( texturedQuadVertexData, 4 ); + + return vertexData; +} + + } @@ -55,6 +78,33 @@ int UtcDaliGeometryNew02(void) END_TEST; } +int UtcDaliGeometryCopyConstructor(void) +{ + TestApplication application; + + Geometry geometry = Geometry::New(); + + Geometry geometryCopy(geometry); + + DALI_TEST_EQUALS( (bool)geometryCopy, true, TEST_LOCATION ); + END_TEST; +} + +int UtcDaliGeometryAssignmentOperator(void) +{ + TestApplication application; + + Geometry geometry = Geometry::New(); + + Geometry geometry2; + DALI_TEST_EQUALS( (bool)geometry2, false, TEST_LOCATION ); + + geometry2 = geometry; + DALI_TEST_EQUALS( (bool)geometry2, true, TEST_LOCATION ); + + END_TEST; +} + int UtcDaliGeometryDownCast01(void) { TestApplication application; @@ -76,3 +126,426 @@ int UtcDaliGeometryDownCast02(void) DALI_TEST_EQUALS( (bool)geometry, false, TEST_LOCATION ); END_TEST; } + +int UtcDaliGeometryAddVertexBuffer(void) +{ + TestApplication application; + + tet_infoline("Test AddVertexBuffer"); + + PropertyBuffer vertexBuffer1 = CreateVertexBuffer("aPosition1", "aTexCoord1" ); + Geometry geometry = Geometry::New(); + geometry.AddVertexBuffer( vertexBuffer1 ); + + Shader shader = CreateShader(); + Renderer renderer = Renderer::New(geometry, shader); + Actor actor = Actor::New(); + actor.SetProperty( Actor::Property::SIZE,Vector3::ONE * 100.f); + actor.AddRenderer(renderer); + Stage::GetCurrent().Add(actor); + + application.SendNotification(); + application.Render(0); + application.Render(); + application.SendNotification(); + + { + const TestGlAbstraction::BufferDataCalls& bufferDataCalls = + application.GetGlAbstraction().GetBufferDataCalls(); + + DALI_TEST_EQUALS( bufferDataCalls.size(), 1u, TEST_LOCATION ); + + DALI_TEST_EQUALS( bufferDataCalls[0], 4*sizeof( TexturedQuadVertex ), TEST_LOCATION ); + } + + // add the second vertex buffer + application.GetGlAbstraction().ResetBufferDataCalls(); + + PropertyBuffer vertexBuffer2 = CreateVertexBuffer( "aPosition2", "aTexCoord2" ); + geometry.AddVertexBuffer( vertexBuffer2 ); + application.SendNotification(); + application.Render(0); + application.Render(); + application.SendNotification(); + + { + const TestGlAbstraction::BufferDataCalls& bufferDataCalls = + application.GetGlAbstraction().GetBufferDataCalls(); + + //Check that only the new buffer gets uploaded + DALI_TEST_EQUALS( bufferDataCalls.size(), 1u, TEST_LOCATION ); + DALI_TEST_EQUALS( bufferDataCalls[0], 4*sizeof( TexturedQuadVertex ), TEST_LOCATION ); + } + + END_TEST; +} + +int UtcDaliGeometryGetNumberOfVertexBuffers(void) +{ + TestApplication application; + + tet_infoline("Test GetNumberOfVertexBuffers"); + PropertyBuffer vertexBuffer1 = CreateVertexBuffer("aPosition1", "aTexCoord1" ); + PropertyBuffer vertexBuffer2 = CreateVertexBuffer("aPosition2", "aTexCoord2" ); + PropertyBuffer vertexBuffer3 = CreateVertexBuffer("aPosition3", "aTexCoord3" ); + + Geometry geometry = Geometry::New(); + geometry.AddVertexBuffer( vertexBuffer1 ); + DALI_TEST_EQUALS( geometry.GetNumberOfVertexBuffers(), 1u, TEST_LOCATION ); + + geometry.AddVertexBuffer( vertexBuffer2 ); + geometry.AddVertexBuffer( vertexBuffer3 ); + DALI_TEST_EQUALS( geometry.GetNumberOfVertexBuffers(), 3u, TEST_LOCATION ); + + geometry.RemoveVertexBuffer( 2u ); + DALI_TEST_EQUALS( geometry.GetNumberOfVertexBuffers(), 2u, TEST_LOCATION ); + + END_TEST; +} + +int UtcDaliGeometryRemoveVertexBuffer(void) +{ + TestApplication application; + + tet_infoline("Test RemoveVertexBuffer"); + + PropertyBuffer vertexBuffer1 = CreateVertexBuffer("aPosition1", "aTexCoord1" ); + PropertyBuffer vertexBuffer2 = CreateVertexBuffer("aPosition2", "aTexCoord2" ); + + Geometry geometry = Geometry::New(); + geometry.AddVertexBuffer( vertexBuffer1 ); + + Shader shader = CreateShader(); + Renderer renderer = Renderer::New(geometry, shader); + Actor actor = Actor::New(); + actor.SetProperty( Actor::Property::SIZE,Vector3::ONE * 100.f); + actor.AddRenderer(renderer); + Stage::GetCurrent().Add(actor); + + DALI_TEST_EQUALS( geometry.GetNumberOfVertexBuffers(), 1u, TEST_LOCATION ); + + geometry.RemoveVertexBuffer( 0 ); + geometry.AddVertexBuffer( vertexBuffer2 ); + DALI_TEST_EQUALS( geometry.GetNumberOfVertexBuffers(), 1u, TEST_LOCATION ); + + geometry.RemoveVertexBuffer( 0 ); + DALI_TEST_EQUALS( geometry.GetNumberOfVertexBuffers(), 0u, TEST_LOCATION ); + + //Todo: test by checking the BufferDataCalls + // make sure the vertex buffer in actually removed from gl + + END_TEST; +} + +int UtcDaliGeometrySetIndexBuffer(void) +{ + TestApplication application; + + tet_infoline("Test SetIndexBuffer"); + + PropertyBuffer vertexBuffer = CreateVertexBuffer("aPosition", "aTexCoord" ); + + Geometry geometry = Geometry::New(); + geometry.AddVertexBuffer( vertexBuffer ); + + Shader shader = CreateShader(); + Renderer renderer = Renderer::New(geometry, shader); + Actor actor = Actor::New(); + actor.SetProperty( Actor::Property::SIZE,Vector3::ONE * 100.f); + actor.AddRenderer(renderer); + Stage::GetCurrent().Add(actor); + + application.SendNotification(); + application.Render(0); + application.Render(); + application.SendNotification(); + + { + const TestGlAbstraction::BufferDataCalls& bufferDataCalls = + application.GetGlAbstraction().GetBufferDataCalls(); + + DALI_TEST_EQUALS( bufferDataCalls.size(), 1u, TEST_LOCATION ); + + DALI_TEST_EQUALS( bufferDataCalls[0], 4*sizeof( TexturedQuadVertex ), TEST_LOCATION ); + } + + // Set index buffer + application.GetGlAbstraction().ResetBufferDataCalls(); + + const unsigned short indexData[6] = { 0, 3, 1, 0, 2, 3 }; + geometry.SetIndexBuffer( indexData, sizeof(indexData)/sizeof(indexData[0]) ); + application.SendNotification(); + application.Render(0); + application.Render(); + application.SendNotification(); + + { + const TestGlAbstraction::BufferDataCalls& bufferDataCalls = + application.GetGlAbstraction().GetBufferDataCalls(); + + //Only the index buffer should be uploaded + DALI_TEST_EQUALS( bufferDataCalls.size(), 1u, TEST_LOCATION ); + + // should be unsigned short instead of unsigned int + DALI_TEST_EQUALS( bufferDataCalls[0], 6*sizeof( unsigned short ), TEST_LOCATION ); + } + + + END_TEST; +} + +int UtcDaliGeometrySetGetGeometryType01(void) +{ + TestApplication application; + + tet_infoline("Test SetType and GetType: without index buffer"); + + unsigned int numVertex = 4u; + PropertyBuffer vertexBuffer = CreateVertexBuffer("aPosition", "aTexCoord" ); + + Geometry geometry = Geometry::New(); + geometry.AddVertexBuffer( vertexBuffer ); + + Shader shader = CreateShader(); + Renderer renderer = Renderer::New(geometry, shader); + Actor actor = Actor::New(); + actor.SetProperty( Actor::Property::SIZE,Vector3::ONE * 100.f); + actor.AddRenderer(renderer); + Stage::GetCurrent().Add(actor); + + TestGlAbstraction& glAbstraction = application.GetGlAbstraction(); + TraceCallStack& drawTrace = glAbstraction.GetDrawTrace(); + + /****************************************************/ + // Default (TRIANGLES), no index buffer + drawTrace.Reset(); + drawTrace.Enable(true); + application.SendNotification(); + application.Render(0); + application.Render(); + application.SendNotification(); + drawTrace.Enable( false ); + + // Test the default geometry type is GL_TRIANGLE + // no index buffer, call glDrawArrays, + DALI_TEST_EQUALS( drawTrace.CountMethod( "DrawArrays" ), 2, TEST_LOCATION); + std::stringstream out; + out << GL_TRIANGLES << ", " << 0 << ", " << numVertex; + DALI_TEST_EQUALS( drawTrace.TestMethodAndParams(1, "DrawArrays", out.str()), true, TEST_LOCATION); + + DALI_TEST_EQUALS( geometry.GetType(), Geometry::TRIANGLES, TEST_LOCATION); + + /*********************************************************/ + // LINES, no index buffer + geometry.SetType( Geometry::LINES ); + + drawTrace.Reset(); + drawTrace.Enable(true); + application.SendNotification(); + application.Render(0); + application.Render(); + application.SendNotification(); + drawTrace.Enable( false ); + + // geometry type is set as GL_LINES + // no index buffer, call glDrawArrays, + DALI_TEST_EQUALS( drawTrace.CountMethod( "DrawArrays" ), 2, TEST_LOCATION); + out.str(""); + out << GL_LINES << ", " << 0 << ", " << numVertex; + DALI_TEST_EQUALS( drawTrace.TestMethodAndParams(1, "DrawArrays", out.str()), true, TEST_LOCATION); + + DALI_TEST_EQUALS( geometry.GetType(), Geometry::LINES, TEST_LOCATION); + + /*****************************************************/ + //POINTS + geometry.SetType( Geometry::POINTS ); + + drawTrace.Reset(); + drawTrace.Enable(true); + application.SendNotification(); + application.Render(0); + application.Render(); + application.SendNotification(); + drawTrace.Enable( false ); + + // geometry type is set as GL_POINTS + // no index buffer, call glDrawArrays, + DALI_TEST_EQUALS( drawTrace.CountMethod( "DrawArrays" ), 2, TEST_LOCATION); + out.str(""); + out << GL_POINTS << ", " << 0 << ", " << numVertex; + DALI_TEST_EQUALS( drawTrace.TestMethodAndParams(1, "DrawArrays", out.str()), true, TEST_LOCATION); + + DALI_TEST_EQUALS( geometry.GetType(), Geometry::POINTS, TEST_LOCATION); + + /*****************************************************/ + //TRIANGLE_STRIP, no index buffer + geometry.SetType( Geometry::TRIANGLE_STRIP ); + + drawTrace.Reset(); + drawTrace.Enable(true); + application.SendNotification(); + application.Render(0); + application.Render(); + application.SendNotification(); + drawTrace.Enable( false ); + + // geometry type is set as GL_TRIANGLE_STRIP + // no index buffer, call glDrawArrays, + DALI_TEST_EQUALS( drawTrace.CountMethod( "DrawArrays" ), 2, TEST_LOCATION); + out.str(""); + out << GL_TRIANGLE_STRIP << ", " << 0 << ", " << numVertex; + DALI_TEST_EQUALS( drawTrace.TestMethodAndParams(1, "DrawArrays", out.str()), true, TEST_LOCATION); + + DALI_TEST_EQUALS( geometry.GetType(), Geometry::TRIANGLE_STRIP, TEST_LOCATION); + + /*****************************************************/ + //TRIANGLE_FAN, no index buffer + geometry.SetType( Geometry::TRIANGLE_FAN ); + + drawTrace.Reset(); + drawTrace.Enable(true); + application.SendNotification(); + application.Render(0); + application.Render(); + application.SendNotification(); + drawTrace.Enable( false ); + + // geometry type is set as GL_TRIANGLE_FAN + // no index buffer, call glDrawArrays, + DALI_TEST_EQUALS( drawTrace.CountMethod( "DrawArrays" ), 2, TEST_LOCATION); + out.str(""); + out << GL_TRIANGLE_FAN << ", " << 0 << ", " << numVertex; + DALI_TEST_EQUALS( drawTrace.TestMethodAndParams(1, "DrawArrays", out.str()), true, TEST_LOCATION); + + DALI_TEST_EQUALS( geometry.GetType(), Geometry::TRIANGLE_FAN, TEST_LOCATION); + + END_TEST; +} + +int UtcDaliGeometrySetGetGeometryType02(void) +{ + TestApplication application; + + tet_infoline("Test SetType and GetType: with index buffer"); + + unsigned int numVertex = 4u; + unsigned int numIndex = 6u; // 6 unsigned short + PropertyBuffer vertexBuffer = CreateVertexBuffer("aPosition", "aTexCoord" ); + + + Geometry geometry = Geometry::New(); + geometry.AddVertexBuffer( vertexBuffer ); + const unsigned short indexData[6] = { 0, 3, 1, 0, 2, 3 }; + geometry.SetIndexBuffer( indexData, sizeof(indexData)/sizeof(indexData[0]) ); + + Shader shader = CreateShader(); + Renderer renderer = Renderer::New(geometry, shader); + Actor actor = Actor::New(); + actor.SetProperty( Actor::Property::SIZE,Vector3::ONE * 100.f); + actor.AddRenderer(renderer); + Stage::GetCurrent().Add(actor); + + TestGlAbstraction& glAbstraction = application.GetGlAbstraction(); + TraceCallStack& drawTrace = glAbstraction.GetDrawTrace(); + + /****************************************************/ + // Default (TRIANGLES), with index buffer + drawTrace.Reset(); + drawTrace.Enable(true); + application.SendNotification(); + application.Render(0); + application.Render(); + application.SendNotification(); + drawTrace.Enable( false ); + + // Test the default geometry type is GL_TRIANGLE + DALI_TEST_EQUALS( drawTrace.CountMethod( "DrawElements" ), 2, TEST_LOCATION); + std::stringstream out; + out << GL_TRIANGLES << ", " << numIndex << ", " << GL_UNSIGNED_SHORT<<", "<<"indices"; + DALI_TEST_EQUALS( drawTrace.TestMethodAndParams(1, "DrawElements", out.str()), true, TEST_LOCATION); + + DALI_TEST_EQUALS( geometry.GetType(), Geometry::TRIANGLES, TEST_LOCATION); + + /*********************************************************/ + // LINES, with index buffer + geometry.SetType( Geometry::LINES ); + + drawTrace.Reset(); + drawTrace.Enable(true); + application.SendNotification(); + application.Render(0); + application.Render(); + application.SendNotification(); + drawTrace.Enable( false ); + + // geometry type is set as GL_LINES + DALI_TEST_EQUALS( drawTrace.CountMethod( "DrawElements" ), 2, TEST_LOCATION); + out.str(""); + out << GL_LINES << ", " << numIndex << ", " << GL_UNSIGNED_SHORT<<", "<<"indices"; + DALI_TEST_EQUALS( drawTrace.TestMethodAndParams(1, "DrawElements", out.str()), true, TEST_LOCATION); + + DALI_TEST_EQUALS( geometry.GetType(), Geometry::LINES, TEST_LOCATION); + + /*****************************************************/ + //POINTS + geometry.SetType( Geometry::POINTS ); + + drawTrace.Reset(); + drawTrace.Enable(true); + application.SendNotification(); + application.Render(0); + application.Render(); + application.SendNotification(); + drawTrace.Enable( false ); + + // geometry type is set as GL_POINTS + // As Points does not use the index buffer, call glDrawArrays, + DALI_TEST_EQUALS( drawTrace.CountMethod( "DrawArrays" ), 2, TEST_LOCATION); + out.str(""); + out << GL_POINTS << ", " << 0 << ", " << numVertex; + DALI_TEST_EQUALS( drawTrace.TestMethodAndParams(1, "DrawArrays", out.str()), true, TEST_LOCATION); + + DALI_TEST_EQUALS( geometry.GetType(), Geometry::POINTS, TEST_LOCATION); + + /*****************************************************/ + //TRIANGLE_STRIP + geometry.SetType( Geometry::TRIANGLE_STRIP ); + + drawTrace.Reset(); + drawTrace.Enable(true); + application.SendNotification(); + application.Render(0); + application.Render(); + application.SendNotification(); + drawTrace.Enable( false ); + + // geometry type is set as GL_TRIANGLE_STRIP + DALI_TEST_EQUALS( drawTrace.CountMethod( "DrawElements" ), 2, TEST_LOCATION); + out.str(""); + out << GL_TRIANGLE_STRIP << ", " << numIndex << ", " << GL_UNSIGNED_SHORT<<", "<<"indices"; + DALI_TEST_EQUALS( drawTrace.TestMethodAndParams(1, "DrawElements", out.str()), true, TEST_LOCATION); + + DALI_TEST_EQUALS( geometry.GetType(), Geometry::TRIANGLE_STRIP, TEST_LOCATION); + + /*****************************************************/ + //TRIANGLE_FAN + geometry.SetType( Geometry::TRIANGLE_FAN ); + + drawTrace.Reset(); + drawTrace.Enable(true); + application.SendNotification(); + application.Render(0); + application.Render(); + application.SendNotification(); + drawTrace.Enable( false ); + + // geometry type is set as GL_TRIANGLE_FAN + DALI_TEST_EQUALS( drawTrace.CountMethod( "DrawElements" ), 2, TEST_LOCATION); + out.str(""); + out << GL_TRIANGLE_FAN << ", " << numIndex << ", " << GL_UNSIGNED_SHORT<<", "<<"indices"; + DALI_TEST_EQUALS( drawTrace.TestMethodAndParams(1, "DrawElements", out.str()), true, TEST_LOCATION); + + DALI_TEST_EQUALS( geometry.GetType(), Geometry::TRIANGLE_FAN, TEST_LOCATION); + + END_TEST; +}