From 50ac6d1a13e6d67b37a90c016adf4c6ab4dc20d1 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Vladim=C3=ADr=20Vondru=C5=A1?= Date: Wed, 8 Jan 2020 21:40:16 +0100 Subject: [PATCH] Test: fix false sense of security in pixel/mesh enum mapping tests. The stripped-down versions didn't actually test for correct order because there was no external API result to check against expected output. That's fixed now, plus clarified some comments and removed copypasted nonsense. --- src/Magnum/GL/Test/PixelFormatTest.cpp | 8 ++++---- src/Magnum/Test/MeshTest.cpp | 10 ++++++---- src/Magnum/Test/PixelFormatTest.cpp | 18 ++++++++---------- src/Magnum/Vk/Test/EnumsTest.cpp | 8 ++++---- 4 files changed, 22 insertions(+), 22 deletions(-) diff --git a/src/Magnum/GL/Test/PixelFormatTest.cpp b/src/Magnum/GL/Test/PixelFormatTest.cpp index 7bf017366..ec39b6037 100644 --- a/src/Magnum/GL/Test/PixelFormatTest.cpp +++ b/src/Magnum/GL/Test/PixelFormatTest.cpp @@ -117,8 +117,8 @@ void PixelFormatTest::mapFormatTypeTextureFormat() { for(UnsignedInt i = 1; i <= 0xffff; ++i) { const auto format = Magnum::PixelFormat(i); /* Each case verifies: - - that the cases are ordered by number (so insertion here is done in - proper place) + - that the entries are ordered by number by comparing a function to + expected result (so insertion here is done in proper place) - that there was no gap (unhandled value inside the range) - that a particular pixel format maps to a particular GL format - that a particular pixel type maps to a particular GL type */ @@ -327,8 +327,8 @@ void PixelFormatTest::mapCompressedFormatTextureFormat() { for(UnsignedInt i = 1; i <= 0xffff; ++i) { const auto format = Magnum::CompressedPixelFormat(i); /* Each case verifies: - - that the cases are ordered by number (so insertion here is done in - proper place) + - that the entries are ordered by number by comparing a function to + expected result (so insertion here is done in proper place) - that there was no gap (unhandled value inside the range) - that a particular pixel format maps to a particular GL format - that a particular pixel type maps to a particular GL type */ diff --git a/src/Magnum/Test/MeshTest.cpp b/src/Magnum/Test/MeshTest.cpp index 517ad4440..d212d4bf5 100644 --- a/src/Magnum/Test/MeshTest.cpp +++ b/src/Magnum/Test/MeshTest.cpp @@ -67,8 +67,8 @@ void MeshTest::primitiveMapping() { for(UnsignedInt i = 0; i <= 0xff; ++i) { const auto primitive = MeshPrimitive(i); /* Each case verifies: - - that the cases are ordered by number (so insertion here is done in - proper place) + - that the entries are ordered by number by comparing a function to + expected result (so insertion here is done in proper place) - that there was no gap (unhandled value inside the range) */ #ifdef __GNUC__ #pragma GCC diagnostic push @@ -77,6 +77,7 @@ void MeshTest::primitiveMapping() { switch(primitive) { #define _c(primitive) \ case MeshPrimitive::primitive: \ + CORRADE_COMPARE(Utility::ConfigurationValue::toString(MeshPrimitive::primitive, {}), #primitive); \ CORRADE_COMPARE(nextHandled, i); \ CORRADE_COMPARE(firstUnhandled, 0xff); \ ++nextHandled; \ @@ -104,8 +105,8 @@ void MeshTest::indexTypeMapping() { for(UnsignedInt i = 0; i <= 0xff; ++i) { const auto type = MeshIndexType(i); /* Each case verifies: - - that the cases are ordered by number (so insertion here is done in - proper place) + - that the entries are ordered by number by comparing a function to + expected result (so insertion here is done in proper place) - that there was no gap (unhandled value inside the range) */ #ifdef __GNUC__ #pragma GCC diagnostic push @@ -114,6 +115,7 @@ void MeshTest::indexTypeMapping() { switch(type) { #define _c(type) \ case MeshIndexType::type: \ + CORRADE_COMPARE(Utility::ConfigurationValue::toString(MeshIndexType::type, {}), #type); \ CORRADE_COMPARE(nextHandled, i); \ CORRADE_COMPARE(firstUnhandled, 0xff); \ ++nextHandled; \ diff --git a/src/Magnum/Test/PixelFormatTest.cpp b/src/Magnum/Test/PixelFormatTest.cpp index 749d2ccf3..bdd8bbcdc 100644 --- a/src/Magnum/Test/PixelFormatTest.cpp +++ b/src/Magnum/Test/PixelFormatTest.cpp @@ -112,11 +112,9 @@ void PixelFormatTest::mapping() { for(UnsignedInt i = 1; i <= 0xffff; ++i) { const auto format = PixelFormat(i); /* Each case verifies: - - that the cases are ordered by number (so insertion here is done in - proper place) - - that there was no gap (unhandled value inside the range) - - that a particular pixel format maps to a particular GL format - - that a particular pixel type maps to a particular GL type */ + - that the entries are ordered by number by comparing a function to + expected result (so insertion here is done in proper place) + - that there was no gap (unhandled value inside the range) */ #ifdef __GNUC__ #pragma GCC diagnostic push #pragma GCC diagnostic error "-Wswitch" @@ -124,6 +122,7 @@ void PixelFormatTest::mapping() { switch(format) { #define _c(format) \ case PixelFormat::format: \ + CORRADE_COMPARE(Utility::ConfigurationValue::toString(PixelFormat::format, {}), #format); \ CORRADE_COMPARE(nextHandled, i); \ CORRADE_COMPARE(firstUnhandled, 0xffff); \ ++nextHandled; \ @@ -152,11 +151,9 @@ void PixelFormatTest::compressedMapping() { for(UnsignedInt i = 1; i <= 0xffff; ++i) { const auto format = CompressedPixelFormat(i); /* Each case verifies: - - that the cases are ordered by number (so insertion here is done in - proper place) - - that there was no gap (unhandled value inside the range) - - that a particular pixel format maps to a particular GL format - - that a particular pixel type maps to a particular GL type */ + - that the entries are ordered by number by comparing a function to + expected result (so insertion here is done in proper place) + - that there was no gap (unhandled value inside the range) */ #ifdef __GNUC__ #pragma GCC diagnostic push #pragma GCC diagnostic error "-Wswitch" @@ -164,6 +161,7 @@ void PixelFormatTest::compressedMapping() { switch(format) { #define _c(format, width, height, depth, size) \ case CompressedPixelFormat::format: \ + CORRADE_COMPARE(Utility::ConfigurationValue::toString(CompressedPixelFormat::format, {}), #format); \ CORRADE_COMPARE(nextHandled, i); \ CORRADE_COMPARE(firstUnhandled, 0xffff); \ CORRADE_COMPARE(Magnum::compressedBlockSize(CompressedPixelFormat::format), (Vector3i{width, height, depth})); \ diff --git a/src/Magnum/Vk/Test/EnumsTest.cpp b/src/Magnum/Vk/Test/EnumsTest.cpp index 081f22e2b..0e8e8cb02 100644 --- a/src/Magnum/Vk/Test/EnumsTest.cpp +++ b/src/Magnum/Vk/Test/EnumsTest.cpp @@ -185,8 +185,8 @@ void EnumsTest::mapVkFormat() { for(UnsignedInt i = 1; i <= 0xffff; ++i) { const auto format = Magnum::PixelFormat(i); /* Each case verifies: - - that the cases are ordered by number (so insertion here is done in - proper place) + - that the entries are ordered by number by comparing a function to + expected result (so insertion here is done in proper place) - that there was no gap (unhandled value inside the range) - that a particular pixel format maps to a particular GL format - that a particular pixel type maps to a particular GL type */ @@ -273,8 +273,8 @@ void EnumsTest::mapVkFormatCompressed() { for(UnsignedInt i = 1; i <= 0xffff; ++i) { const auto format = Magnum::CompressedPixelFormat(i); /* Each case verifies: - - that the cases are ordered by number (so insertion here is done in - proper place) + - that the entries are ordered by number by comparing a function to + expected result (so insertion here is done in proper place) - that there was no gap (unhandled value inside the range) - that a particular pixel format maps to a particular GL format - that a particular pixel type maps to a particular GL type */