Browse Source

Primitives: max out the code coverage.

pull/205/head
Vladimír Vondruš 8 years ago
parent
commit
013f1273f9
  1. 68
      src/Magnum/Primitives/Test/AxisTest.cpp
  2. 12
      src/Magnum/Primitives/Test/CMakeLists.txt
  3. 2
      src/Magnum/Primitives/Test/CircleTest.cpp
  4. 66
      src/Magnum/Primitives/Test/CrosshairTest.cpp
  5. 77
      src/Magnum/Primitives/Test/CubeTest.cpp
  6. 66
      src/Magnum/Primitives/Test/LineTest.cpp
  7. 66
      src/Magnum/Primitives/Test/PlaneTest.cpp
  8. 66
      src/Magnum/Primitives/Test/SquareTest.cpp
  9. 40
      src/Magnum/Primitives/Test/UVSphereTest.cpp

68
src/Magnum/Primitives/Test/AxisTest.cpp

@ -0,0 +1,68 @@
/*
This file is part of Magnum.
Copyright © 2010, 2011, 2012, 2013, 2014, 2015, 2016, 2017, 2018
Vladimír Vondruš <mosra@centrum.cz>
Permission is hereby granted, free of charge, to any person obtaining a
copy of this software and associated documentation files (the "Software"),
to deal in the Software without restriction, including without limitation
the rights to use, copy, modify, merge, publish, distribute, sublicense,
and/or sell copies of the Software, and to permit persons to whom the
Software is furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included
in all copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
DEALINGS IN THE SOFTWARE.
*/
#include <Corrade/TestSuite/Tester.h>
#include "Magnum/Mesh.h"
#include "Magnum/Math/Color.h"
#include "Magnum/Primitives/Axis.h"
#include "Magnum/Trade/MeshData2D.h"
#include "Magnum/Trade/MeshData3D.h"
namespace Magnum { namespace Primitives { namespace Test {
struct AxisTest: TestSuite::Tester {
explicit AxisTest();
void twoDimensions();
void threeDimensions();
};
AxisTest::AxisTest() {
addTests({&AxisTest::twoDimensions,
&AxisTest::threeDimensions});
}
void AxisTest::twoDimensions() {
Trade::MeshData2D axis = Primitives::axis2D();
CORRADE_COMPARE(axis.primitive(), MeshPrimitive::Lines);
CORRADE_COMPARE(axis.indices().size(), 12);
CORRADE_COMPARE(axis.positions(0).size(), 8);
CORRADE_COMPARE(axis.colors(0).size(), 8);
}
void AxisTest::threeDimensions() {
Trade::MeshData3D axis = Primitives::axis3D();
CORRADE_COMPARE(axis.primitive(), MeshPrimitive::Lines);
CORRADE_COMPARE(axis.indices().size(), 18);
CORRADE_COMPARE(axis.positions(0).size(), 12);
CORRADE_COMPARE(axis.colors(0).size(), 12);
}
}}}
CORRADE_TEST_MAIN(Magnum::Primitives::Test::AxisTest)

12
src/Magnum/Primitives/Test/CMakeLists.txt

@ -23,16 +23,28 @@
# DEALINGS IN THE SOFTWARE.
#
corrade_add_test(PrimitivesAxisTest AxisTest.cpp LIBRARIES MagnumPrimitives)
corrade_add_test(PrimitivesCapsuleTest CapsuleTest.cpp LIBRARIES MagnumPrimitives)
corrade_add_test(PrimitivesCircleTest CircleTest.cpp LIBRARIES MagnumPrimitives)
corrade_add_test(PrimitivesCrosshairTest CrosshairTest.cpp LIBRARIES MagnumPrimitives)
corrade_add_test(PrimitivesCubeTest CubeTest.cpp LIBRARIES MagnumPrimitives)
corrade_add_test(PrimitivesCylinderTest CylinderTest.cpp LIBRARIES MagnumPrimitives)
corrade_add_test(PrimitivesIcosphereTest IcosphereTest.cpp LIBRARIES MagnumPrimitives)
corrade_add_test(PrimitivesLineTest LineTest.cpp LIBRARIES MagnumPrimitives)
corrade_add_test(PrimitivesPlaneTest PlaneTest.cpp LIBRARIES MagnumPrimitives)
corrade_add_test(PrimitivesSquareTest SquareTest.cpp LIBRARIES MagnumPrimitives)
corrade_add_test(PrimitivesUVSphereTest UVSphereTest.cpp LIBRARIES MagnumPrimitives)
set_target_properties(
PrimitivesAxisTest
PrimitivesCapsuleTest
PrimitivesCircleTest
PrimitivesCrosshairTest
PrimitivesCubeTest
PrimitivesCylinderTest
PrimitivesIcosphereTest
PrimitivesLineTest
PrimitivesPlaneTest
PrimitivesSquareTest
PrimitivesUVSphereTest
PROPERTIES FOLDER "Magnum/Primitives/Test")

2
src/Magnum/Primitives/Test/CircleTest.cpp

@ -47,6 +47,7 @@ CircleTest::CircleTest() {
void CircleTest::solid() {
Trade::MeshData2D circle = Primitives::Circle::solid(8);
CORRADE_VERIFY(!circle.isIndexed());
CORRADE_COMPARE(circle.primitive(), MeshPrimitive::TriangleFan);
CORRADE_COMPARE(circle.positions(0), (std::vector<Vector2>{
{ 0.0f, 0.0f},
@ -61,6 +62,7 @@ void CircleTest::solid() {
void CircleTest::wireframe() {
Trade::MeshData2D circle = Primitives::Circle::wireframe(8);
CORRADE_VERIFY(!circle.isIndexed());
CORRADE_COMPARE(circle.primitive(), MeshPrimitive::LineLoop);
CORRADE_COMPARE(circle.positions(0), (std::vector<Vector2>{
{ 1.0f, 0.0f}, { Constants::sqrt2()/2.0f, Constants::sqrt2()/2.0f},

66
src/Magnum/Primitives/Test/CrosshairTest.cpp

@ -0,0 +1,66 @@
/*
This file is part of Magnum.
Copyright © 2010, 2011, 2012, 2013, 2014, 2015, 2016, 2017, 2018
Vladimír Vondruš <mosra@centrum.cz>
Permission is hereby granted, free of charge, to any person obtaining a
copy of this software and associated documentation files (the "Software"),
to deal in the Software without restriction, including without limitation
the rights to use, copy, modify, merge, publish, distribute, sublicense,
and/or sell copies of the Software, and to permit persons to whom the
Software is furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included
in all copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
DEALINGS IN THE SOFTWARE.
*/
#include <Corrade/TestSuite/Tester.h>
#include "Magnum/Mesh.h"
#include "Magnum/Math/Vector3.h"
#include "Magnum/Primitives/Crosshair.h"
#include "Magnum/Trade/MeshData2D.h"
#include "Magnum/Trade/MeshData3D.h"
namespace Magnum { namespace Primitives { namespace Test {
struct CrosshairTest: TestSuite::Tester {
explicit CrosshairTest();
void twoDimensions();
void threeDimensions();
};
CrosshairTest::CrosshairTest() {
addTests({&CrosshairTest::twoDimensions,
&CrosshairTest::threeDimensions});
}
void CrosshairTest::twoDimensions() {
Trade::MeshData2D crosshair = Primitives::Crosshair2D::wireframe();
CORRADE_VERIFY(!crosshair.isIndexed());
CORRADE_COMPARE(crosshair.primitive(), MeshPrimitive::Lines);
CORRADE_COMPARE(crosshair.positions(0).size(), 4);
}
void CrosshairTest::threeDimensions() {
Trade::MeshData3D crosshair = Primitives::Crosshair3D::wireframe();
CORRADE_VERIFY(!crosshair.isIndexed());
CORRADE_COMPARE(crosshair.primitive(), MeshPrimitive::Lines);
CORRADE_COMPARE(crosshair.positions(0).size(), 6);
}
}}}
CORRADE_TEST_MAIN(Magnum::Primitives::Test::CrosshairTest)

77
src/Magnum/Primitives/Test/CubeTest.cpp

@ -0,0 +1,77 @@
/*
This file is part of Magnum.
Copyright © 2010, 2011, 2012, 2013, 2014, 2015, 2016, 2017, 2018
Vladimír Vondruš <mosra@centrum.cz>
Permission is hereby granted, free of charge, to any person obtaining a
copy of this software and associated documentation files (the "Software"),
to deal in the Software without restriction, including without limitation
the rights to use, copy, modify, merge, publish, distribute, sublicense,
and/or sell copies of the Software, and to permit persons to whom the
Software is furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included
in all copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
DEALINGS IN THE SOFTWARE.
*/
#include <Corrade/TestSuite/Tester.h>
#include "Magnum/Mesh.h"
#include "Magnum/Math/Vector3.h"
#include "Magnum/Primitives/Cube.h"
#include "Magnum/Trade/MeshData3D.h"
namespace Magnum { namespace Primitives { namespace Test {
struct CubeTest: TestSuite::Tester {
explicit CubeTest();
void solid();
void solidStrip();
void wireframe();
};
CubeTest::CubeTest() {
addTests({&CubeTest::solid,
&CubeTest::solidStrip,
&CubeTest::wireframe});
}
void CubeTest::solid() {
Trade::MeshData3D cube = Primitives::Cube::solid();
CORRADE_COMPARE(cube.primitive(), MeshPrimitive::Triangles);
CORRADE_COMPARE(cube.indices().size(), 36);
CORRADE_COMPARE(cube.positions(0).size(), 24);
CORRADE_COMPARE(cube.normals(0).size(), 24);
}
void CubeTest::solidStrip() {
Trade::MeshData3D cube = Primitives::Cube::solidStrip();
CORRADE_VERIFY(!cube.isIndexed());
CORRADE_COMPARE(cube.primitive(), MeshPrimitive::TriangleStrip);
CORRADE_COMPARE(cube.positions(0).size(), 14);
CORRADE_COMPARE(cube.normalArrayCount(), 0);
}
void CubeTest::wireframe() {
Trade::MeshData3D cube = Primitives::Cube::wireframe();
CORRADE_COMPARE(cube.primitive(), MeshPrimitive::Lines);
CORRADE_COMPARE(cube.indices().size(), 24);
CORRADE_COMPARE(cube.positions(0).size(), 8);
}
}}}
CORRADE_TEST_MAIN(Magnum::Primitives::Test::CubeTest)

66
src/Magnum/Primitives/Test/LineTest.cpp

@ -0,0 +1,66 @@
/*
This file is part of Magnum.
Copyright © 2010, 2011, 2012, 2013, 2014, 2015, 2016, 2017, 2018
Vladimír Vondruš <mosra@centrum.cz>
Permission is hereby granted, free of charge, to any person obtaining a
copy of this software and associated documentation files (the "Software"),
to deal in the Software without restriction, including without limitation
the rights to use, copy, modify, merge, publish, distribute, sublicense,
and/or sell copies of the Software, and to permit persons to whom the
Software is furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included
in all copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
DEALINGS IN THE SOFTWARE.
*/
#include <Corrade/TestSuite/Tester.h>
#include "Magnum/Mesh.h"
#include "Magnum/Math/Vector3.h"
#include "Magnum/Primitives/Line.h"
#include "Magnum/Trade/MeshData2D.h"
#include "Magnum/Trade/MeshData3D.h"
namespace Magnum { namespace Primitives { namespace Test {
struct LineTest: TestSuite::Tester {
explicit LineTest();
void twoDimensions();
void threeDimensions();
};
LineTest::LineTest() {
addTests({&LineTest::twoDimensions,
&LineTest::threeDimensions});
}
void LineTest::twoDimensions() {
Trade::MeshData2D line = Primitives::Line2D::wireframe();
CORRADE_VERIFY(!line.isIndexed());
CORRADE_COMPARE(line.primitive(), MeshPrimitive::Lines);
CORRADE_COMPARE(line.positions(0).size(), 2);
}
void LineTest::threeDimensions() {
Trade::MeshData3D line = Primitives::Line3D::wireframe();
CORRADE_VERIFY(!line.isIndexed());
CORRADE_COMPARE(line.primitive(), MeshPrimitive::Lines);
CORRADE_COMPARE(line.positions(0).size(), 2);
}
}}}
CORRADE_TEST_MAIN(Magnum::Primitives::Test::LineTest)

66
src/Magnum/Primitives/Test/PlaneTest.cpp

@ -0,0 +1,66 @@
/*
This file is part of Magnum.
Copyright © 2010, 2011, 2012, 2013, 2014, 2015, 2016, 2017, 2018
Vladimír Vondruš <mosra@centrum.cz>
Permission is hereby granted, free of charge, to any person obtaining a
copy of this software and associated documentation files (the "Software"),
to deal in the Software without restriction, including without limitation
the rights to use, copy, modify, merge, publish, distribute, sublicense,
and/or sell copies of the Software, and to permit persons to whom the
Software is furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included
in all copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
DEALINGS IN THE SOFTWARE.
*/
#include <Corrade/TestSuite/Tester.h>
#include "Magnum/Mesh.h"
#include "Magnum/Math/Vector3.h"
#include "Magnum/Primitives/Plane.h"
#include "Magnum/Trade/MeshData3D.h"
namespace Magnum { namespace Primitives { namespace Test {
struct PlaneTest: TestSuite::Tester {
explicit PlaneTest();
void solid();
void wireframe();
};
PlaneTest::PlaneTest() {
addTests({&PlaneTest::solid,
&PlaneTest::wireframe});
}
void PlaneTest::solid() {
Trade::MeshData3D plane = Primitives::Plane::solid();
CORRADE_VERIFY(!plane.isIndexed());
CORRADE_COMPARE(plane.primitive(), MeshPrimitive::TriangleStrip);
CORRADE_COMPARE(plane.positions(0).size(), 4);
CORRADE_COMPARE(plane.normals(0).size(), 4);
}
void PlaneTest::wireframe() {
Trade::MeshData3D plane = Primitives::Plane::wireframe();
CORRADE_VERIFY(!plane.isIndexed());
CORRADE_COMPARE(plane.primitive(), MeshPrimitive::LineLoop);
CORRADE_COMPARE(plane.positions(0).size(), 4);
}
}}}
CORRADE_TEST_MAIN(Magnum::Primitives::Test::PlaneTest)

66
src/Magnum/Primitives/Test/SquareTest.cpp

@ -0,0 +1,66 @@
/*
This file is part of Magnum.
Copyright © 2010, 2011, 2012, 2013, 2014, 2015, 2016, 2017, 2018
Vladimír Vondruš <mosra@centrum.cz>
Permission is hereby granted, free of charge, to any person obtaining a
copy of this software and associated documentation files (the "Software"),
to deal in the Software without restriction, including without limitation
the rights to use, copy, modify, merge, publish, distribute, sublicense,
and/or sell copies of the Software, and to permit persons to whom the
Software is furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included
in all copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
DEALINGS IN THE SOFTWARE.
*/
#include <Corrade/TestSuite/Tester.h>
#include "Magnum/Mesh.h"
#include "Magnum/Math/Vector2.h"
#include "Magnum/Primitives/Square.h"
#include "Magnum/Trade/MeshData2D.h"
namespace Magnum { namespace Primitives { namespace Test {
struct SquareTest: TestSuite::Tester {
explicit SquareTest();
void solid();
void wireframe();
};
SquareTest::SquareTest() {
addTests({&SquareTest::solid,
&SquareTest::wireframe});
}
void SquareTest::solid() {
Trade::MeshData2D square = Primitives::Square::solid();
CORRADE_VERIFY(!square.isIndexed());
CORRADE_COMPARE(square.primitive(), MeshPrimitive::TriangleStrip);
CORRADE_COMPARE(square.positions(0).size(), 4);
}
void SquareTest::wireframe() {
Trade::MeshData2D square = Primitives::Square::wireframe();
CORRADE_VERIFY(!square.isIndexed());
CORRADE_COMPARE(square.primitive(), MeshPrimitive::LineLoop);
CORRADE_COMPARE(square.positions(0).size(), 4);
}
}}}
CORRADE_TEST_MAIN(Magnum::Primitives::Test::SquareTest)

40
src/Magnum/Primitives/Test/UVSphereTest.cpp

@ -127,29 +127,42 @@ void UVSphereTest::solidWithTextureCoords() {
}
void UVSphereTest::wireframe() {
Trade::MeshData3D sphere = UVSphere::wireframe(4, 8);
Trade::MeshData3D sphere = UVSphere::wireframe(6, 8);
CORRADE_COMPARE_AS(sphere.positions(0), (std::vector<Vector3>{
{0.0f, -1.0f, 0.0f},
{0.0f, -0.707107f, 0.707107f},
{0.707107f, -0.707107f, 0.0f},
{0.0f, -0.707107f, -0.707107f},
{-0.707107f, -0.707107f, 0.0f},
{0.0f, -0.866025f, 0.5f},
{0.5f, -0.866025f, 0.0f},
{0.0f, -0.866025f, -0.5f},
{-0.5f, -0.866025f, 0.0f},
{0.0f, -0.5f, 0.866025f},
{0.866025f, -0.5f, 0.0f},
{0.0f, -0.5f, -0.866025f},
{-0.866025f, -0.5f, 0.0f},
/* Four "corners" of the center ring */
{0.0f, 0.0f, 1.0f},
{1.0f, 0.0f, 0.0f},
{0.0f, 0.0f, -1.0f},
{-1.0f, 0.0f, 0.0f},
/* In between the four corners of the center ring */
{0.707107f, 0.0f, 0.707107f},
{0.707107f, 0.0f, -0.707107f},
{-0.707107f, 0.0f, -0.707107f},
{-0.707107f, 0.0f, 0.707107f},
{0.0f, 0.707107f, 0.707107f},
{0.707107f, 0.707107f, 0.0f},
{0.0f, 0.707107f, -0.707107f},
{-0.707107f, 0.707107f, 0.0f},
{0.0f, 0.5f, 0.866025f},
{0.866025f, 0.5f, 0.0f},
{0.0f, 0.5f, -0.866025f},
{-0.866025f, 0.5f, 0.0f},
{0.0f, 0.866025f, 0.5f},
{0.5f, 0.866025f, 0.0f},
{0.0f, 0.866025f, -0.5f},
{-0.5f, 0.866025f, 0.0f},
{0.0f, 1.0f, 0.0f}
}), TestSuite::Compare::Container);
@ -161,10 +174,13 @@ void UVSphereTest::wireframe() {
1, 5, 2, 6, 3, 7, 4, 8,
5, 9, 6, 10, 7, 11, 8, 12,
9, 6, 10, 7, 11, 8, 12, 5,
9, 13, 10, 14, 11, 15, 12, 16,
13, 10, 14, 11, 15, 12, 16, 9,
9, 17, 10, 18, 11, 19, 12, 20,
5, 13, 6, 14, 7, 15, 8, 16,
13, 17, 14, 17, 15, 17, 16, 17
17, 21, 18, 22, 19, 23, 20, 24,
21, 25, 22, 25, 23, 25, 24, 25
}), TestSuite::Compare::Container);
}

Loading…
Cancel
Save