Browse Source

Trade: test that MeshData::*AsArray() APIs pick the right attribute.

Instead of always testing with exactly one attribute. Now the test cases
are back to the original verbosity, but doing something actually useful.
pull/582/merge
Vladimír Vondruš 4 years ago
parent
commit
8d138295ee
  1. 223
      src/Magnum/Trade/Test/MeshDataTest.cpp

223
src/Magnum/Trade/Test/MeshDataTest.cpp

@ -2624,17 +2624,25 @@ void MeshDataTest::indicesIntoArrayInvalidSize() {
template<class T> void MeshDataTest::positions2DAsArray() { template<class T> void MeshDataTest::positions2DAsArray() {
setTestCaseTemplateName(NameTraits<T>::name()); setTestCaseTemplateName(NameTraits<T>::name());
/* Testing also that it picks the correct attribute */
typedef typename T::Type TT; typedef typename T::Type TT;
T positions[]{ struct Vertex {
T::pad(Math::Vector2<TT>{TT(2.0f), TT(1.0f)}), Vector2 otherPosition;
T::pad(Math::Vector2<TT>{TT(0.0f), TT(-1.0f)}), UnsignedShort objectId;
T::pad(Math::Vector2<TT>{TT(-2.0f), TT(3.0f)}) T position;
} vertices[]{
{{}, 0, T::pad(Math::Vector2<TT>{TT(2.0f), TT(1.0f)})},
{{}, 0, T::pad(Math::Vector2<TT>{TT(0.0f), TT(-1.0f)})},
{{}, 0, T::pad(Math::Vector2<TT>{TT(-2.0f), TT(3.0f)})}
}; };
auto view = Containers::stridedArrayView(vertices);
MeshData data{MeshPrimitive::Points, {}, positions, { MeshData data{MeshPrimitive::Points, {}, vertices, {
MeshAttributeData{MeshAttribute::Position, Containers::arrayView(positions)} MeshAttributeData{MeshAttribute::Position, view.slice(&Vertex::otherPosition)},
MeshAttributeData{MeshAttribute::ObjectId, view.slice(&Vertex::objectId)},
MeshAttributeData{MeshAttribute::Position, view.slice(&Vertex::position)}
}}; }};
CORRADE_COMPARE_AS(data.positions2DAsArray(), Containers::arrayView<Vector2>({ CORRADE_COMPARE_AS(data.positions2DAsArray(1), Containers::arrayView<Vector2>({
{2.0f, 1.0f}, {0.0f, -1.0f}, {-2.0f, 3.0f} {2.0f, 1.0f}, {0.0f, -1.0f}, {-2.0f, 3.0f}
}), TestSuite::Compare::Container); }), TestSuite::Compare::Container);
} }
@ -2732,19 +2740,27 @@ void MeshDataTest::positions2DIntoArrayInvalidSize() {
template<class T> void MeshDataTest::positions3DAsArray() { template<class T> void MeshDataTest::positions3DAsArray() {
setTestCaseTemplateName(NameTraits<T>::name()); setTestCaseTemplateName(NameTraits<T>::name());
/* Needs to be sufficiently representable to have the test work also for /* Testing also that it picks the correct attribute. Needs to be
half floats */ sufficiently representable to have the test work also for half
floats. */
typedef typename T::Type TT; typedef typename T::Type TT;
T positions[]{ struct Vertex {
T::pad(Math::Vector3<TT>{TT(2.0f), TT(1.0f), TT(0.75f)}), Vector3 otherPosition;
T::pad(Math::Vector3<TT>{TT(0.0f), TT(-1.0f), TT(1.25f)}), UnsignedShort objectId;
T::pad(Math::Vector3<TT>{TT(-2.0f), TT(3.0f), TT(2.5f)}) T position;
} vertices[]{
{{}, 0, T::pad(Math::Vector3<TT>{TT(2.0f), TT(1.0f), TT(0.75f)})},
{{}, 0, T::pad(Math::Vector3<TT>{TT(0.0f), TT(-1.0f), TT(1.25f)})},
{{}, 0, T::pad(Math::Vector3<TT>{TT(-2.0f), TT(3.0f), TT(2.5f)})}
}; };
auto view = Containers::stridedArrayView(vertices);
MeshData data{MeshPrimitive::Points, {}, positions, { MeshData data{MeshPrimitive::Points, {}, vertices, {
MeshAttributeData{MeshAttribute::Position, Containers::arrayView(positions)} MeshAttributeData{MeshAttribute::Position, view.slice(&Vertex::otherPosition)},
MeshAttributeData{MeshAttribute::ObjectId, view.slice(&Vertex::objectId)},
MeshAttributeData{MeshAttribute::Position, view.slice(&Vertex::position)}
}}; }};
CORRADE_COMPARE_AS(data.positions3DAsArray(), Containers::arrayView<Vector3>({ CORRADE_COMPARE_AS(data.positions3DAsArray(1), Containers::arrayView<Vector3>({
Vector3::pad(Math::Vector<T::Size, Float>::pad(Vector3{2.0f, 1.0f, 0.75f})), Vector3::pad(Math::Vector<T::Size, Float>::pad(Vector3{2.0f, 1.0f, 0.75f})),
Vector3::pad(Math::Vector<T::Size, Float>::pad(Vector3{0.0f, -1.0f, 1.25f})), Vector3::pad(Math::Vector<T::Size, Float>::pad(Vector3{0.0f, -1.0f, 1.25f})),
Vector3::pad(Math::Vector<T::Size, Float>::pad(Vector3{-2.0f, 3.0f, 2.5f})) Vector3::pad(Math::Vector<T::Size, Float>::pad(Vector3{-2.0f, 3.0f, 2.5f}))
@ -2850,19 +2866,27 @@ void MeshDataTest::positions3DIntoArrayInvalidSize() {
template<class T> void MeshDataTest::tangentsAsArray() { template<class T> void MeshDataTest::tangentsAsArray() {
setTestCaseTemplateName(NameTraits<T>::name()); setTestCaseTemplateName(NameTraits<T>::name());
/* Needs to be sufficiently representable to have the test work also for /* Testing also that it picks the correct attribute. Needs to be
half floats */ sufficiently representable to have the test work also for half
floats. */
typedef typename T::Type TT; typedef typename T::Type TT;
T tangents[]{ struct Vertex {
T::pad(Math::Vector3<TT>{TT(2.0f), TT(1.0f), TT(0.75f)}), Vector3 otherTangent;
T::pad(Math::Vector3<TT>{TT(0.0f), TT(-1.0f), TT(1.25f)}), UnsignedShort objectId;
T::pad(Math::Vector3<TT>{TT(-2.0f), TT(3.0f), TT(2.5f)}) T tangent;
} vertices[]{
{{}, 0, T::pad(Math::Vector3<TT>{TT(2.0f), TT(1.0f), TT(0.75f)})},
{{}, 0, T::pad(Math::Vector3<TT>{TT(0.0f), TT(-1.0f), TT(1.25f)})},
{{}, 0, T::pad(Math::Vector3<TT>{TT(-2.0f), TT(3.0f), TT(2.5f)})}
}; };
auto view = Containers::stridedArrayView(vertices);
MeshData data{MeshPrimitive::Points, {}, tangents, { MeshData data{MeshPrimitive::Points, {}, vertices, {
MeshAttributeData{MeshAttribute::Tangent, Containers::arrayView(tangents)} MeshAttributeData{MeshAttribute::Tangent, view.slice(&Vertex::otherTangent)},
MeshAttributeData{MeshAttribute::ObjectId, view.slice(&Vertex::objectId)},
MeshAttributeData{MeshAttribute::Tangent, view.slice(&Vertex::tangent)}
}}; }};
CORRADE_COMPARE_AS(data.tangentsAsArray(), Containers::arrayView<Vector3>({ CORRADE_COMPARE_AS(data.tangentsAsArray(1), Containers::arrayView<Vector3>({
{2.0f, 1.0f, 0.75f}, {0.0f, -1.0f, 1.25f}, {-2.0f, 3.0f, 2.5f}, {2.0f, 1.0f, 0.75f}, {0.0f, -1.0f, 1.25f}, {-2.0f, 3.0f, 2.5f},
}), TestSuite::Compare::Container); }), TestSuite::Compare::Container);
} }
@ -2905,18 +2929,26 @@ void MeshDataTest::tangentsIntoArrayInvalidSize() {
template<class T> void MeshDataTest::bitangentSignsAsArray() { template<class T> void MeshDataTest::bitangentSignsAsArray() {
setTestCaseTemplateName(Math::TypeTraits<T>::name()); setTestCaseTemplateName(Math::TypeTraits<T>::name());
/* Needs to be sufficiently representable to have the test work also for /* Testing also that it picks the correct attribute. Needs to be
half floats */ sufficiently representable to have the test work also for half
Math::Vector4<T> tangents[]{ floats. */
{T(2.0f), T(1.0f), T(0.75f), T(-1.0f)}, struct Vertex {
{T(0.0f), T(-1.0f), T(1.25f), T(1.0f)}, Vector3 otherTangent;
{T(-2.0f), T(3.0f), T(2.5f), T(-1.0f)} UnsignedShort objectId;
Math::Vector4<T> tangent;
} vertices[]{
{{}, 0, {T(2.0f), T(1.0f), T(0.75f), T(-1.0f)}},
{{}, 0, {T(0.0f), T(-1.0f), T(1.25f), T(1.0f)}},
{{}, 0, {T(-2.0f), T(3.0f), T(2.5f), T(-1.0f)}}
}; };
auto view = Containers::stridedArrayView(vertices);
MeshData data{MeshPrimitive::Points, {}, tangents, { MeshData data{MeshPrimitive::Points, {}, vertices, {
MeshAttributeData{MeshAttribute::Tangent, Containers::arrayView(tangents)} MeshAttributeData{MeshAttribute::Tangent, view.slice(&Vertex::otherTangent)},
MeshAttributeData{MeshAttribute::ObjectId, view.slice(&Vertex::objectId)},
MeshAttributeData{MeshAttribute::Tangent, view.slice(&Vertex::tangent)}
}}; }};
CORRADE_COMPARE_AS(data.bitangentSignsAsArray(), Containers::arrayView<Float>({ CORRADE_COMPARE_AS(data.bitangentSignsAsArray(1), Containers::arrayView<Float>({
-1.0f, 1.0f, -1.0f -1.0f, 1.0f, -1.0f
}), TestSuite::Compare::Container); }), TestSuite::Compare::Container);
} }
@ -2974,19 +3006,27 @@ void MeshDataTest::bitangentSignsIntoArrayInvalidSize() {
template<class T> void MeshDataTest::bitangentsAsArray() { template<class T> void MeshDataTest::bitangentsAsArray() {
setTestCaseTemplateName(NameTraits<T>::name()); setTestCaseTemplateName(NameTraits<T>::name());
/* Needs to be sufficiently representable to have the test work also for /* Testing also that it picks the correct attribute. Needs to be
half floats */ sufficiently representable to have the test work also for half
floats. */
typedef typename T::Type TT; typedef typename T::Type TT;
T bitangents[]{ struct Vertex {
{TT(2.0f), TT(1.0f), TT(0.75f)}, Vector3 otherBitangent;
{TT(0.0f), TT(-1.0f), TT(1.25f)}, UnsignedShort objectId;
{TT(-2.0f), TT(3.0f), TT(2.5f)} T bitangent;
} vertices[]{
{{}, 0, {TT(2.0f), TT(1.0f), TT(0.75f)}},
{{}, 0, {TT(0.0f), TT(-1.0f), TT(1.25f)}},
{{}, 0, {TT(-2.0f), TT(3.0f), TT(2.5f)}}
}; };
auto view = Containers::stridedArrayView(vertices);
MeshData data{MeshPrimitive::Points, {}, bitangents, { MeshData data{MeshPrimitive::Points, {}, vertices, {
MeshAttributeData{MeshAttribute::Bitangent, Containers::arrayView(bitangents)} MeshAttributeData{MeshAttribute::Bitangent, view.slice(&Vertex::otherBitangent)},
MeshAttributeData{MeshAttribute::ObjectId, view.slice(&Vertex::objectId)},
MeshAttributeData{MeshAttribute::Bitangent, view.slice(&Vertex::bitangent)}
}}; }};
CORRADE_COMPARE_AS(data.bitangentsAsArray(), Containers::arrayView<Vector3>({ CORRADE_COMPARE_AS(data.bitangentsAsArray(1), Containers::arrayView<Vector3>({
{2.0f, 1.0f, 0.75f}, {0.0f, -1.0f, 1.25f}, {-2.0f, 3.0f, 2.5f}, {2.0f, 1.0f, 0.75f}, {0.0f, -1.0f, 1.25f}, {-2.0f, 3.0f, 2.5f},
}), TestSuite::Compare::Container); }), TestSuite::Compare::Container);
} }
@ -3029,19 +3069,27 @@ void MeshDataTest::bitangentsIntoArrayInvalidSize() {
template<class T> void MeshDataTest::normalsAsArray() { template<class T> void MeshDataTest::normalsAsArray() {
setTestCaseTemplateName(NameTraits<T>::name()); setTestCaseTemplateName(NameTraits<T>::name());
/* Needs to be sufficiently representable to have the test work also for /* Testing also that it picks the correct attribute. Needs to be
half floats */ sufficiently representable to have the test work also for half
floats. */
typedef typename T::Type TT; typedef typename T::Type TT;
T normals[]{ struct Vertex {
{TT(2.0f), TT(1.0f), TT(0.75f)}, Vector3 otherNormal;
{TT(0.0f), TT(-1.0f), TT(1.25f)}, UnsignedShort objectId;
{TT(-2.0f), TT(3.0f), TT(2.5f)} T normal;
} vertices[]{
{{}, 0, {TT(2.0f), TT(1.0f), TT(0.75f)}},
{{}, 0, {TT(0.0f), TT(-1.0f), TT(1.25f)}},
{{}, 0, {TT(-2.0f), TT(3.0f), TT(2.5f)}}
}; };
auto view = Containers::stridedArrayView(vertices);
MeshData data{MeshPrimitive::Points, {}, normals, { MeshData data{MeshPrimitive::Points, {}, vertices, {
MeshAttributeData{MeshAttribute::Normal, Containers::arrayView(normals)} MeshAttributeData{MeshAttribute::Normal, view.slice(&Vertex::otherNormal)},
MeshAttributeData{MeshAttribute::ObjectId, view.slice(&Vertex::objectId)},
MeshAttributeData{MeshAttribute::Normal, view.slice(&Vertex::normal)}
}}; }};
CORRADE_COMPARE_AS(data.normalsAsArray(), Containers::arrayView<Vector3>({ CORRADE_COMPARE_AS(data.normalsAsArray(1), Containers::arrayView<Vector3>({
{2.0f, 1.0f, 0.75f}, {0.0f, -1.0f, 1.25f}, {-2.0f, 3.0f, 2.5f}, {2.0f, 1.0f, 0.75f}, {0.0f, -1.0f, 1.25f}, {-2.0f, 3.0f, 2.5f},
}), TestSuite::Compare::Container); }), TestSuite::Compare::Container);
} }
@ -3084,17 +3132,27 @@ void MeshDataTest::normalsIntoArrayInvalidSize() {
template<class T> void MeshDataTest::textureCoordinates2DAsArray() { template<class T> void MeshDataTest::textureCoordinates2DAsArray() {
setTestCaseTemplateName(NameTraits<T>::name()); setTestCaseTemplateName(NameTraits<T>::name());
/* Testing also that it picks the correct attribute. Needs to be
sufficiently representable to have the test work also for half
floats. */
typedef typename T::Type TT; typedef typename T::Type TT;
T textureCoordinates[]{ struct Vertex {
{TT(2.0f), TT(1.0f)}, Vector2 otherTextureCoordinate;
{TT(0.0f), TT(-1.0f)}, UnsignedShort objectId;
{TT(-2.0f), TT(3.0f)} T textureCoordinate;
} vertices[]{
{{}, 0, {TT(2.0f), TT(1.0f)}},
{{}, 0, {TT(0.0f), TT(-1.0f)}},
{{}, 0, {TT(-2.0f), TT(3.0f)}}
}; };
auto view = Containers::stridedArrayView(vertices);
MeshData data{MeshPrimitive::Points, {}, textureCoordinates, { MeshData data{MeshPrimitive::Points, {}, vertices, {
MeshAttributeData{MeshAttribute::TextureCoordinates, Containers::arrayView(textureCoordinates)} MeshAttributeData{MeshAttribute::TextureCoordinates, view.slice(&Vertex::otherTextureCoordinate)},
MeshAttributeData{MeshAttribute::ObjectId, view.slice(&Vertex::objectId)},
MeshAttributeData{MeshAttribute::TextureCoordinates, view.slice(&Vertex::textureCoordinate)}
}}; }};
CORRADE_COMPARE_AS(data.textureCoordinates2DAsArray(), Containers::arrayView<Vector2>({ CORRADE_COMPARE_AS(data.textureCoordinates2DAsArray(1), Containers::arrayView<Vector2>({
{2.0f, 1.0f}, {0.0f, -1.0f}, {-2.0f, 3.0f}, {2.0f, 1.0f}, {0.0f, -1.0f}, {-2.0f, 3.0f},
}), TestSuite::Compare::Container); }), TestSuite::Compare::Container);
} }
@ -3190,19 +3248,26 @@ void MeshDataTest::textureCoordinates2DIntoArrayInvalidSize() {
template<class T> void MeshDataTest::colorsAsArray() { template<class T> void MeshDataTest::colorsAsArray() {
setTestCaseTemplateName(NameTraits<T>::name()); setTestCaseTemplateName(NameTraits<T>::name());
/* Can't use e.g. 0xff3366_rgbf because that's not representable in /* Testing also that it picks the correct attribute. Can't use e.g.
half-floats */ 0xff3366_rgbf because that's not representable in half-floats. */
typedef typename T::Type TT; typedef typename T::Type TT;
T colors[]{ struct Vertex {
{TT(2.0f), TT(1.0f), TT(0.75f)}, Color4 otherColor;
{TT(0.0f), TT(-1.0f), TT(1.25f)}, UnsignedShort objectId;
{TT(-2.0f), TT(3.0f), TT(2.5f)} T color;
} vertices[]{
{{}, 0, {TT(2.0f), TT(1.0f), TT(0.75f)}},
{{}, 0, {TT(0.0f), TT(-1.0f), TT(1.25f)}},
{{}, 0, {TT(-2.0f), TT(3.0f), TT(2.5f)}}
}; };
auto view = Containers::stridedArrayView(vertices);
MeshData data{MeshPrimitive::Points, {}, colors, { MeshData data{MeshPrimitive::Points, {}, vertices, {
MeshAttributeData{MeshAttribute::Color, Containers::arrayView(colors)} MeshAttributeData{MeshAttribute::Color, view.slice(&Vertex::otherColor)},
MeshAttributeData{MeshAttribute::ObjectId, view.slice(&Vertex::objectId)},
MeshAttributeData{MeshAttribute::Color, view.slice(&Vertex::color)}
}}; }};
CORRADE_COMPARE_AS(data.colorsAsArray(), Containers::arrayView<Color4>({ CORRADE_COMPARE_AS(data.colorsAsArray(1), Containers::arrayView<Color4>({
{2.0f, 1.0f, 0.75f}, {0.0f, -1.0f, 1.25f}, {-2.0f, 3.0f, 2.5f}, {2.0f, 1.0f, 0.75f}, {0.0f, -1.0f, 1.25f}, {-2.0f, 3.0f, 2.5f},
}), TestSuite::Compare::Container); }), TestSuite::Compare::Container);
} }
@ -3244,16 +3309,24 @@ void MeshDataTest::colorsIntoArrayInvalidSize() {
template<class T> void MeshDataTest::objectIdsAsArray() { template<class T> void MeshDataTest::objectIdsAsArray() {
setTestCaseTemplateName(Math::TypeTraits<T>::name()); setTestCaseTemplateName(Math::TypeTraits<T>::name());
T objectIds[]{ /* Testing also that it picks the correct attribute */
157, struct Vertex {
24, UnsignedByte otherObjectId;
1 Vector2 position;
T objectId;
} vertices[]{
{0, {}, 157},
{0, {}, 24},
{0, {}, 1}
}; };
auto view = Containers::stridedArrayView(vertices);
MeshData data{MeshPrimitive::Points, {}, objectIds, { MeshData data{MeshPrimitive::Points, {}, vertices, {
MeshAttributeData{MeshAttribute::ObjectId, Containers::arrayView(objectIds)} MeshAttributeData{MeshAttribute::ObjectId, view.slice(&Vertex::otherObjectId)},
MeshAttributeData{MeshAttribute::Position, view.slice(&Vertex::position)},
MeshAttributeData{MeshAttribute::ObjectId, view.slice(&Vertex::objectId)}
}}; }};
CORRADE_COMPARE_AS(data.objectIdsAsArray(), Containers::arrayView<UnsignedInt>({ CORRADE_COMPARE_AS(data.objectIdsAsArray(1), Containers::arrayView<UnsignedInt>({
157, 24, 1 157, 24, 1
}), TestSuite::Compare::Container); }), TestSuite::Compare::Container);
} }

Loading…
Cancel
Save