From 06a7677fbe3ce176f8ebf50185a171e045f6fc6e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Vladim=C3=ADr=20Vondru=C5=A1?= Date: Tue, 11 Apr 2017 13:07:45 +0200 Subject: [PATCH] Math: test underflow/overflow when parsing vector/matrix from Configuration. Fails as overflow is not handled. --- src/Magnum/Math/Test/RectangularMatrixTest.cpp | 14 ++++++++++++++ src/Magnum/Math/Test/VectorTest.cpp | 8 ++++++++ 2 files changed, 22 insertions(+) diff --git a/src/Magnum/Math/Test/RectangularMatrixTest.cpp b/src/Magnum/Math/Test/RectangularMatrixTest.cpp index 253453474..20c2963b5 100644 --- a/src/Magnum/Math/Test/RectangularMatrixTest.cpp +++ b/src/Magnum/Math/Test/RectangularMatrixTest.cpp @@ -707,6 +707,20 @@ void RectangularMatrixTest::configuration() { CORRADE_COMPARE(c.value("matrix"), value); CORRADE_COMPARE(c.value("matrix"), m); + + /* Underflow */ + c.setValue("underflow", "2.1 8.9 1.3 1 5 7 1.5"); + CORRADE_COMPARE(c.value("underflow"), (Matrix3x4{ + Vector4{2.1f, 1.0f, 1.5f, 0.0f}, + Vector4{8.9f, 5.0f, 0.0f, 0.0f}, + Vector4{1.3f, 7.0f, 0.0f, 0.0f}})); + + /* Overflow */ + c.setValue("overflow", "2 1 8 9 1 3 1 5 7 1 6 3 3 1.5 23 17"); + CORRADE_COMPARE(c.value("overflow"), (Matrix3x4{ + Vector4{2.0f, 9.0f, 1.0f, 1.0f}, + Vector4{1.0f, 1.0f, 5.0f, 6.0f}, + Vector4{8.0f, 3.0f, 7.0f, 3.0f}})); } }}} diff --git a/src/Magnum/Math/Test/VectorTest.cpp b/src/Magnum/Math/Test/VectorTest.cpp index 4f3bde0a9..773359952 100644 --- a/src/Magnum/Math/Test/VectorTest.cpp +++ b/src/Magnum/Math/Test/VectorTest.cpp @@ -702,6 +702,14 @@ void VectorTest::configuration() { c.setValue("vector", vec); CORRADE_COMPARE(c.value("vector"), value); CORRADE_COMPARE(c.value("vector"), vec); + + /* Underflow */ + c.setValue("underflow", "2.1 8.9"); + CORRADE_COMPARE(c.value("underflow"), (Vector4{2.1f, 8.9f, 0.0f, 0.0f})); + + /* Overflow */ + c.setValue("overflow", "2 1 8 9 16 33"); + CORRADE_COMPARE(c.value("overflow"), (Vector4{2.0f, 1.0f, 8.0f, 9.0f})); } }}}