Browse Source

MeshTools: don't use STL for no reason in tests.

Ancient code, ancient problems. Eugh.
pull/659/head
Vladimír Vondruš 1 year ago
parent
commit
0fd0457366
  1. 85
      src/Magnum/MeshTools/Test/InterleaveTest.cpp
  2. 30
      src/Magnum/MeshTools/Test/TransformTest.cpp

85
src/Magnum/MeshTools/Test/InterleaveTest.cpp

@ -25,7 +25,6 @@
*/ */
#include <sstream> #include <sstream>
#include <vector>
#include <Corrade/Containers/Optional.h> #include <Corrade/Containers/Optional.h>
#include <Corrade/Containers/StringStl.h> /** @todo remove once Debug is stream-free */ #include <Corrade/Containers/StringStl.h> /** @todo remove once Debug is stream-free */
#include <Corrade/TestSuite/Tester.h> #include <Corrade/TestSuite/Tester.h>
@ -209,13 +208,17 @@ InterleaveTest::InterleaveTest() {
} }
void InterleaveTest::attributeCount() { void InterleaveTest::attributeCount() {
CORRADE_COMPARE((Implementation::AttributeCount{}(std::vector<Byte>{0, 1, 2}, CORRADE_COMPARE(Implementation::AttributeCount{}(
std::vector<Byte>{3, 4, 5})), std::size_t(3)); Containers::arrayView<Byte>({0, 1, 2}),
Containers::arrayView<Byte>({3, 4, 5})
), std::size_t(3));
} }
void InterleaveTest::attributeCountGaps() { void InterleaveTest::attributeCountGaps() {
CORRADE_COMPARE((Implementation::AttributeCount{}(std::vector<Byte>{0, 1, 2}, 3, CORRADE_COMPARE(Implementation::AttributeCount{}(
std::vector<Byte>{3, 4, 5}, 5)), std::size_t(3)); Containers::arrayView<Byte>({0, 1, 2}), 3,
Containers::arrayView<Byte>({3, 4, 5}), 5
), std::size_t(3));
/* No arrays from which to get size */ /* No arrays from which to get size */
CORRADE_COMPARE(Implementation::AttributeCount{}(3, 5), ~std::size_t(0)); CORRADE_COMPARE(Implementation::AttributeCount{}(3, 5), ~std::size_t(0));
@ -226,67 +229,77 @@ void InterleaveTest::attributeCountInvalid() {
std::stringstream ss; std::stringstream ss;
Error redirectError{&ss}; Error redirectError{&ss};
CORRADE_COMPARE((Implementation::AttributeCount{}(std::vector<Byte>{0, 1, 2}, CORRADE_COMPARE(Implementation::AttributeCount{}(
std::vector<Byte>{0, 1, 2, 3, 4, 5})), std::size_t(0)); Containers::arrayView<Byte>({0, 1, 2}),
Containers::arrayView<Byte>({0, 1, 2, 3, 4, 5})
), std::size_t(0));
CORRADE_COMPARE(ss.str(), "MeshTools::interleave(): attribute arrays don't have the same length, expected 3 but got 6\n"); CORRADE_COMPARE(ss.str(), "MeshTools::interleave(): attribute arrays don't have the same length, expected 3 but got 6\n");
} }
void InterleaveTest::stride() { void InterleaveTest::stride() {
CORRADE_COMPARE(Implementation::Stride{}(std::vector<Byte>()), std::size_t(1)); CORRADE_COMPARE(Implementation::Stride{}(Containers::ArrayView<Byte>{}), std::size_t(1));
CORRADE_COMPARE(Implementation::Stride{}(std::vector<Int>()), std::size_t(4)); CORRADE_COMPARE(Implementation::Stride{}(Containers::ArrayView<Int>{}), std::size_t(4));
CORRADE_COMPARE((Implementation::Stride{}(std::vector<Byte>(), std::vector<Int>())), std::size_t(5)); CORRADE_COMPARE(Implementation::Stride{}(
Containers::ArrayView<Byte>{},
Containers::ArrayView<Int>{}
), std::size_t(5));
} }
void InterleaveTest::strideGaps() { void InterleaveTest::strideGaps() {
CORRADE_COMPARE((Implementation::Stride{}(2, std::vector<Byte>(), 1, std::vector<Int>(), 12)), std::size_t(20)); CORRADE_COMPARE(Implementation::Stride{}(
2, Containers::ArrayView<Byte>{},
1, Containers::ArrayView<Int>{}, 12
), std::size_t(20));
} }
void InterleaveTest::interleave() { void InterleaveTest::interleave() {
const Containers::Array<char> data = MeshTools::interleave( const Containers::Array<char> data = MeshTools::interleave(
std::vector<Byte>{0, 1, 2}, Containers::arrayView<Byte>({0, 1, 2}),
std::vector<Int>{3, 4, 5}, Containers::arrayView<Int>({3, 4, 5}),
std::vector<Short>{6, 7, 8}); Containers::arrayView<Short>({6, 7, 8})
);
if(!Utility::Endianness::isBigEndian()) { if(!Utility::Endianness::isBigEndian()) {
CORRADE_COMPARE(std::vector<char>(data.begin(), data.end()), (std::vector<char>{ CORRADE_COMPARE_AS(data, Containers::arrayView<char>({
0x00, 0x03, 0x00, 0x00, 0x00, 0x06, 0x00, 0x00, 0x03, 0x00, 0x00, 0x00, 0x06, 0x00,
0x01, 0x04, 0x00, 0x00, 0x00, 0x07, 0x00, 0x01, 0x04, 0x00, 0x00, 0x00, 0x07, 0x00,
0x02, 0x05, 0x00, 0x00, 0x00, 0x08, 0x00 0x02, 0x05, 0x00, 0x00, 0x00, 0x08, 0x00
})); }), TestSuite::Compare::Container);
} else { } else {
CORRADE_COMPARE(std::vector<char>(data.begin(), data.end()), (std::vector<char>{ CORRADE_COMPARE_AS(data, Containers::arrayView<char>({
0x00, 0x00, 0x00, 0x00, 0x03, 0x00, 0x06, 0x00, 0x00, 0x00, 0x00, 0x03, 0x00, 0x06,
0x01, 0x00, 0x00, 0x00, 0x04, 0x00, 0x07, 0x01, 0x00, 0x00, 0x00, 0x04, 0x00, 0x07,
0x02, 0x00, 0x00, 0x00, 0x05, 0x00, 0x08 0x02, 0x00, 0x00, 0x00, 0x05, 0x00, 0x08
})); }), TestSuite::Compare::Container);
} }
} }
void InterleaveTest::interleaveGaps() { void InterleaveTest::interleaveGaps() {
const Containers::Array<char> data = MeshTools::interleave( const Containers::Array<char> data = MeshTools::interleave(
std::vector<Byte>{0, 1, 2}, 3, Containers::arrayView<Byte>({0, 1, 2}), 3,
std::vector<Int>{3, 4, 5}, Containers::arrayView<Int>({3, 4, 5}),
std::vector<Short>{6, 7, 8}, 2); Containers::arrayView<Short>({6, 7, 8}), 2
);
if(!Utility::Endianness::isBigEndian()) { if(!Utility::Endianness::isBigEndian()) {
/* byte, _____________gap, int___________________, short_____, _______gap */ /* byte, _____________gap, int___________________, short_____, _______gap */
CORRADE_COMPARE(std::vector<char>(data.begin(), data.end()), (std::vector<char>{ CORRADE_COMPARE_AS(data, Containers::arrayView<char>({
0x00, 0x00, 0x00, 0x00, 0x03, 0x00, 0x00, 0x00, 0x06, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x03, 0x00, 0x00, 0x00, 0x06, 0x00, 0x00, 0x00,
0x01, 0x00, 0x00, 0x00, 0x04, 0x00, 0x00, 0x00, 0x07, 0x00, 0x00, 0x00, 0x01, 0x00, 0x00, 0x00, 0x04, 0x00, 0x00, 0x00, 0x07, 0x00, 0x00, 0x00,
0x02, 0x00, 0x00, 0x00, 0x05, 0x00, 0x00, 0x00, 0x08, 0x00, 0x00, 0x00 0x02, 0x00, 0x00, 0x00, 0x05, 0x00, 0x00, 0x00, 0x08, 0x00, 0x00, 0x00
})); }), TestSuite::Compare::Container);
} else { } else {
/* byte, _____________gap, ___________________int, _____short, _______gap */ /* byte, _____________gap, ___________________int, _____short, _______gap */
CORRADE_COMPARE(std::vector<char>(data.begin(), data.end()), (std::vector<char>{ CORRADE_COMPARE_AS(data, Containers::arrayView<char>({
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x03, 0x00, 0x06, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x03, 0x00, 0x06, 0x00, 0x00,
0x01, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x04, 0x00, 0x07, 0x00, 0x00, 0x01, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x04, 0x00, 0x07, 0x00, 0x00,
0x02, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x05, 0x00, 0x08, 0x00, 0x00 0x02, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x05, 0x00, 0x08, 0x00, 0x00
})); }), TestSuite::Compare::Container);
} }
} }
void InterleaveTest::interleaveEmpty() { void InterleaveTest::interleaveEmpty() {
const Containers::Array<char> data = MeshTools::interleave(std::vector<Byte>{}, 2); const Containers::Array<char> data = MeshTools::interleave(Containers::ArrayView<Byte>{}, 2);
CORRADE_COMPARE(data.size(), 0); CORRADE_COMPARE(data.size(), 0);
} }
@ -298,24 +311,24 @@ void InterleaveTest::interleaveInto() {
0x11, 0x33, 0x55, 0x77, 0x11, 0x33, 0x55, 0x77, 0x11, 0x33, 0x55, 0x77}}; 0x11, 0x33, 0x55, 0x77, 0x11, 0x33, 0x55, 0x77, 0x11, 0x33, 0x55, 0x77}};
CORRADE_COMPARE(data.size(), 48); CORRADE_COMPARE(data.size(), 48);
CORRADE_COMPARE(MeshTools::interleaveInto(data, 2, std::vector<Int>{4, 5, 6, 7}, 1, std::vector<Short>{0, 1, 2, 3}, 3), 48); CORRADE_COMPARE(MeshTools::interleaveInto(data, 2, Containers::arrayView<Int>({4, 5, 6, 7}), 1, Containers::arrayView<Short>({0, 1, 2, 3}), 3), 48);
if(!Utility::Endianness::isBigEndian()) { if(!Utility::Endianness::isBigEndian()) {
/* _______gap, int___________________, _gap, short_____, _____________gap */ /* _______gap, int___________________, _gap, short_____, _____________gap */
CORRADE_COMPARE(std::vector<char>(data.begin(), data.end()), (std::vector<char>{ CORRADE_COMPARE_AS(data, Containers::arrayView<char>({
0x11, 0x33, 0x04, 0x00, 0x00, 0x00, 0x55, 0x00, 0x00, 0x33, 0x55, 0x77, 0x11, 0x33, 0x04, 0x00, 0x00, 0x00, 0x55, 0x00, 0x00, 0x33, 0x55, 0x77,
0x11, 0x33, 0x05, 0x00, 0x00, 0x00, 0x55, 0x01, 0x00, 0x33, 0x55, 0x77, 0x11, 0x33, 0x05, 0x00, 0x00, 0x00, 0x55, 0x01, 0x00, 0x33, 0x55, 0x77,
0x11, 0x33, 0x06, 0x00, 0x00, 0x00, 0x55, 0x02, 0x00, 0x33, 0x55, 0x77, 0x11, 0x33, 0x06, 0x00, 0x00, 0x00, 0x55, 0x02, 0x00, 0x33, 0x55, 0x77,
0x11, 0x33, 0x07, 0x00, 0x00, 0x00, 0x55, 0x03, 0x00, 0x33, 0x55, 0x77 0x11, 0x33, 0x07, 0x00, 0x00, 0x00, 0x55, 0x03, 0x00, 0x33, 0x55, 0x77
})); }), TestSuite::Compare::Container);
} else { } else {
/* _______gap, ___________________int, _gap, _____short, _____________gap */ /* _______gap, ___________________int, _gap, _____short, _____________gap */
CORRADE_COMPARE(std::vector<char>(data.begin(), data.end()), (std::vector<char>{ CORRADE_COMPARE_AS(data, Containers::arrayView<char>({
0x11, 0x33, 0x00, 0x00, 0x00, 0x04, 0x55, 0x00, 0x00, 0x33, 0x55, 0x77, 0x11, 0x33, 0x00, 0x00, 0x00, 0x04, 0x55, 0x00, 0x00, 0x33, 0x55, 0x77,
0x11, 0x33, 0x00, 0x00, 0x00, 0x05, 0x55, 0x00, 0x01, 0x33, 0x55, 0x77, 0x11, 0x33, 0x00, 0x00, 0x00, 0x05, 0x55, 0x00, 0x01, 0x33, 0x55, 0x77,
0x11, 0x33, 0x00, 0x00, 0x00, 0x06, 0x55, 0x00, 0x02, 0x33, 0x55, 0x77, 0x11, 0x33, 0x00, 0x00, 0x00, 0x06, 0x55, 0x00, 0x02, 0x33, 0x55, 0x77,
0x11, 0x33, 0x00, 0x00, 0x00, 0x07, 0x55, 0x00, 0x03, 0x33, 0x55, 0x77 0x11, 0x33, 0x00, 0x00, 0x00, 0x07, 0x55, 0x00, 0x03, 0x33, 0x55, 0x77
})); }), TestSuite::Compare::Container);
} }
} }
@ -329,26 +342,26 @@ void InterleaveTest::interleaveIntoLarger() {
0x11, 0x33, 0x55, 0x77, 0x11, 0x33, 0x55, 0x77, 0x11, 0x33, 0x55, 0x77, 0x11}}; 0x11, 0x33, 0x55, 0x77, 0x11, 0x33, 0x55, 0x77, 0x11, 0x33, 0x55, 0x77, 0x11}};
CORRADE_COMPARE(data.size(), 49); CORRADE_COMPARE(data.size(), 49);
CORRADE_COMPARE(MeshTools::interleaveInto(data, 2, std::vector<Int>{4, 5, 6, 7}, 1, std::vector<Short>{0, 1, 2, 3}, 3), 48); CORRADE_COMPARE(MeshTools::interleaveInto(data, 2, Containers::arrayView<Int>({4, 5, 6, 7}), 1, Containers::arrayView<Short>({0, 1, 2, 3}), 3), 48);
if(!Utility::Endianness::isBigEndian()) { if(!Utility::Endianness::isBigEndian()) {
/* _______gap, int___________________, _gap, short_____, _____________gap */ /* _______gap, int___________________, _gap, short_____, _____________gap */
CORRADE_COMPARE(std::vector<char>(data.begin(), data.end()), (std::vector<char>{ CORRADE_COMPARE_AS(data, Containers::arrayView<char>({
0x11, 0x33, 0x04, 0x00, 0x00, 0x00, 0x55, 0x00, 0x00, 0x33, 0x55, 0x77, 0x11, 0x33, 0x04, 0x00, 0x00, 0x00, 0x55, 0x00, 0x00, 0x33, 0x55, 0x77,
0x11, 0x33, 0x05, 0x00, 0x00, 0x00, 0x55, 0x01, 0x00, 0x33, 0x55, 0x77, 0x11, 0x33, 0x05, 0x00, 0x00, 0x00, 0x55, 0x01, 0x00, 0x33, 0x55, 0x77,
0x11, 0x33, 0x06, 0x00, 0x00, 0x00, 0x55, 0x02, 0x00, 0x33, 0x55, 0x77, 0x11, 0x33, 0x06, 0x00, 0x00, 0x00, 0x55, 0x02, 0x00, 0x33, 0x55, 0x77,
0x11, 0x33, 0x07, 0x00, 0x00, 0x00, 0x55, 0x03, 0x00, 0x33, 0x55, 0x77, 0x11, 0x33, 0x07, 0x00, 0x00, 0x00, 0x55, 0x03, 0x00, 0x33, 0x55, 0x77,
0x11 0x11
})); }), TestSuite::Compare::Container);
} else { } else {
/* _______gap, ___________________int, _gap, _____short, _____________gap */ /* _______gap, ___________________int, _gap, _____short, _____________gap */
CORRADE_COMPARE(std::vector<char>(data.begin(), data.end()), (std::vector<char>{ CORRADE_COMPARE_AS(data, Containers::arrayView<char>({
0x11, 0x33, 0x00, 0x00, 0x00, 0x04, 0x55, 0x00, 0x00, 0x33, 0x55, 0x77, 0x11, 0x33, 0x00, 0x00, 0x00, 0x04, 0x55, 0x00, 0x00, 0x33, 0x55, 0x77,
0x11, 0x33, 0x00, 0x00, 0x00, 0x05, 0x55, 0x00, 0x01, 0x33, 0x55, 0x77, 0x11, 0x33, 0x00, 0x00, 0x00, 0x05, 0x55, 0x00, 0x01, 0x33, 0x55, 0x77,
0x11, 0x33, 0x00, 0x00, 0x00, 0x06, 0x55, 0x00, 0x02, 0x33, 0x55, 0x77, 0x11, 0x33, 0x00, 0x00, 0x00, 0x06, 0x55, 0x00, 0x02, 0x33, 0x55, 0x77,
0x11, 0x33, 0x00, 0x00, 0x00, 0x07, 0x55, 0x00, 0x03, 0x33, 0x55, 0x77, 0x11, 0x33, 0x00, 0x00, 0x00, 0x07, 0x55, 0x00, 0x03, 0x33, 0x55, 0x77,
0x11 0x11
})); }), TestSuite::Compare::Container);
} }
} }

30
src/Magnum/MeshTools/Test/TransformTest.cpp

@ -24,10 +24,10 @@
DEALINGS IN THE SOFTWARE. DEALINGS IN THE SOFTWARE.
*/ */
#include <array>
#include <sstream> #include <sstream>
#include <Corrade/Containers/ArrayView.h> #include <Corrade/Containers/ArrayView.h>
#include <Corrade/Containers/GrowableArray.h> #include <Corrade/Containers/GrowableArray.h>
#include <Corrade/Containers/StaticArray.h>
#include <Corrade/TestSuite/Tester.h> #include <Corrade/TestSuite/Tester.h>
#include <Corrade/TestSuite/Compare/Container.h> #include <Corrade/TestSuite/Compare/Container.h>
#include <Corrade/Utility/Algorithms.h> #include <Corrade/Utility/Algorithms.h>
@ -413,32 +413,32 @@ TransformTest::TransformTest() {
addTests({&TransformTest::meshDataTextureCoordinates2DInPlaceWrongFormat}); addTests({&TransformTest::meshDataTextureCoordinates2DInPlaceWrongFormat});
} }
constexpr static std::array<Vector2, 2> points2D{{ constexpr Containers::Array2<Vector2> points2D{{
{-3.0f, 4.0f}, {-3.0f, 4.0f},
{ 2.5f, -15.0f} { 2.5f, -15.0f}
}}; }};
constexpr static std::array<Vector2, 2> points2DRotated{{ constexpr Containers::Array2<Vector2> points2DRotated{{
{-4.0f, -3.0f}, {-4.0f, -3.0f},
{15.0f, 2.5f} {15.0f, 2.5f}
}}; }};
constexpr static std::array<Vector2, 2> points2DRotatedTranslated{{ constexpr Containers::Array2<Vector2> points2DRotatedTranslated{{
{-4.0f, -4.0f}, {-4.0f, -4.0f},
{15.0f, 1.5f} {15.0f, 1.5f}
}}; }};
constexpr static std::array<Vector3, 2> points3D{{ constexpr Containers::Array2<Vector3> points3D{{
{-3.0f, 4.0f, 34.0f}, {-3.0f, 4.0f, 34.0f},
{ 2.5f, -15.0f, 1.5f} { 2.5f, -15.0f, 1.5f}
}}; }};
constexpr static std::array<Vector3, 2> points3DRotated{{ constexpr Containers::Array2<Vector3> points3DRotated{{
{-4.0f, -3.0f, 34.0f}, {-4.0f, -3.0f, 34.0f},
{15.0f, 2.5f, 1.5f} {15.0f, 2.5f, 1.5f}
}}; }};
constexpr static std::array<Vector3, 2> points3DRotatedTranslated{{ constexpr Containers::Array2<Vector3> points3DRotatedTranslated{{
{-4.0f, -4.0f, 34.0f}, {-4.0f, -4.0f, 34.0f},
{15.0f, 1.5f, 1.5f} {15.0f, 1.5f, 1.5f}
}}; }};
@ -447,16 +447,16 @@ void TransformTest::transformVectors2D() {
auto matrix = transformVectors(Matrix3::rotation(Deg(90.0f)), points2D); auto matrix = transformVectors(Matrix3::rotation(Deg(90.0f)), points2D);
auto complex = transformVectors(Complex::rotation(Deg(90.0f)), points2D); auto complex = transformVectors(Complex::rotation(Deg(90.0f)), points2D);
CORRADE_COMPARE(matrix, points2DRotated); CORRADE_COMPARE_AS(matrix, points2DRotated, TestSuite::Compare::Container);
CORRADE_COMPARE(complex, points2DRotated); CORRADE_COMPARE_AS(complex, points2DRotated, TestSuite::Compare::Container);
} }
void TransformTest::transformVectors3D() { void TransformTest::transformVectors3D() {
auto matrix = transformVectors(Matrix4::rotationZ(Deg(90.0f)), points3D); auto matrix = transformVectors(Matrix4::rotationZ(Deg(90.0f)), points3D);
auto quaternion = transformVectors(Quaternion::rotation(Deg(90.0f), Vector3::zAxis()), points3D); auto quaternion = transformVectors(Quaternion::rotation(Deg(90.0f), Vector3::zAxis()), points3D);
CORRADE_COMPARE(matrix, points3DRotated); CORRADE_COMPARE_AS(matrix, points3DRotated, TestSuite::Compare::Container);
CORRADE_COMPARE(quaternion, points3DRotated); CORRADE_COMPARE_AS(quaternion, points3DRotated, TestSuite::Compare::Container);
} }
void TransformTest::transformPoints2D() { void TransformTest::transformPoints2D() {
@ -465,8 +465,8 @@ void TransformTest::transformPoints2D() {
auto complex = transformPoints( auto complex = transformPoints(
DualComplex::translation(Vector2::yAxis(-1.0f))*DualComplex::rotation(Deg(90.0f)), points2D); DualComplex::translation(Vector2::yAxis(-1.0f))*DualComplex::rotation(Deg(90.0f)), points2D);
CORRADE_COMPARE(matrix, points2DRotatedTranslated); CORRADE_COMPARE_AS(matrix, points2DRotatedTranslated, TestSuite::Compare::Container);
CORRADE_COMPARE(complex, points2DRotatedTranslated); CORRADE_COMPARE_AS(complex, points2DRotatedTranslated, TestSuite::Compare::Container);
} }
void TransformTest::transformPoints3D() { void TransformTest::transformPoints3D() {
@ -475,8 +475,8 @@ void TransformTest::transformPoints3D() {
auto quaternion = transformPoints( auto quaternion = transformPoints(
DualQuaternion::translation(Vector3::yAxis(-1.0f))*DualQuaternion::rotation(Deg(90.0f), Vector3::zAxis()), points3D); DualQuaternion::translation(Vector3::yAxis(-1.0f))*DualQuaternion::rotation(Deg(90.0f), Vector3::zAxis()), points3D);
CORRADE_COMPARE(matrix, points3DRotatedTranslated); CORRADE_COMPARE_AS(matrix, points3DRotatedTranslated, TestSuite::Compare::Container);
CORRADE_COMPARE(quaternion, points3DRotatedTranslated); CORRADE_COMPARE_AS(quaternion, points3DRotatedTranslated, TestSuite::Compare::Container);
} }
template<class T> void TransformTest::meshData2D() { template<class T> void TransformTest::meshData2D() {

Loading…
Cancel
Save