From 6c98d10be56dc6c1e494cafaad33ee6a033bf2fc Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Vladim=C3=ADr=20Vondru=C5=A1?= Date: Tue, 18 Feb 2020 18:28:46 +0100 Subject: [PATCH] Make various PixelFormat assertions print the actual value. Otherwise they are pretty useless. --- src/Magnum/PixelFormat.cpp | 8 ++++---- src/Magnum/PixelFormat.h | 8 ++++---- src/Magnum/Test/PixelFormatTest.cpp | 18 +++++++++--------- 3 files changed, 17 insertions(+), 17 deletions(-) diff --git a/src/Magnum/PixelFormat.cpp b/src/Magnum/PixelFormat.cpp index e2416c1b6..04c379065 100644 --- a/src/Magnum/PixelFormat.cpp +++ b/src/Magnum/PixelFormat.cpp @@ -35,8 +35,8 @@ namespace Magnum { UnsignedInt pixelSize(const PixelFormat format) { - CORRADE_ASSERT(!(UnsignedInt(format) & (1 << 31)), - "pixelSize(): can't determine size of an implementation-specific format", {}); + CORRADE_ASSERT(!isPixelFormatImplementationSpecific(format), + "pixelSize(): can't determine size of an implementation-specific format" << reinterpret_cast(pixelFormatUnwrap(format)), {}); #ifdef __GNUC__ #pragma GCC diagnostic push @@ -168,7 +168,7 @@ constexpr UnsignedShort CompressedBlockData[] { Vector3i compressedBlockSize(const CompressedPixelFormat format) { CORRADE_ASSERT(!(UnsignedInt(format) & (1 << 31)), - "compressedBlockSize(): can't determine size of an implementation-specific format", {}); + "compressedBlockSize(): can't determine size of an implementation-specific format" << reinterpret_cast(compressedPixelFormatUnwrap(format)), {}); CORRADE_ASSERT(UnsignedInt(format) - 1 < Containers::arraySize(CompressedBlockData), "compressedBlockSize(): invalid format" << format, {}); @@ -182,7 +182,7 @@ Vector3i compressedBlockSize(const CompressedPixelFormat format) { UnsignedInt compressedBlockDataSize(const CompressedPixelFormat format) { CORRADE_ASSERT(!(UnsignedInt(format) & (1 << 31)), - "compressedBlockDataSize(): can't determine size of an implementation-specific format", {}); + "compressedBlockDataSize(): can't determine size of an implementation-specific format" << reinterpret_cast(compressedPixelFormatUnwrap(format)), {}); CORRADE_ASSERT(UnsignedInt(format) - 1 < Containers::arraySize(CompressedBlockData), "compressedBlockDataSize(): invalid format" << format, {}); diff --git a/src/Magnum/PixelFormat.h b/src/Magnum/PixelFormat.h index e8a49840e..dc42e4bfc 100644 --- a/src/Magnum/PixelFormat.h +++ b/src/Magnum/PixelFormat.h @@ -712,7 +712,7 @@ template constexpr PixelFormat pixelFormatWrap(T implementationSpecific static_assert(sizeof(T) <= 4, "format types larger than 32bits are not supported"); return CORRADE_CONSTEXPR_ASSERT(!(UnsignedInt(implementationSpecific) & (1u << 31)), - "pixelFormatWrap(): implementation-specific value already wrapped or too large"), + "pixelFormatWrap(): implementation-specific value" << reinterpret_cast(implementationSpecific) << "already wrapped or too large"), PixelFormat((1u << 31)|UnsignedInt(implementationSpecific)); } @@ -726,7 +726,7 @@ inverse operation. */ template constexpr T pixelFormatUnwrap(PixelFormat format) { return CORRADE_CONSTEXPR_ASSERT(UnsignedInt(format) & (1u << 31), - "pixelFormatUnwrap(): format doesn't contain a wrapped implementation-specific value"), + "pixelFormatUnwrap():" << format << "isn't a wrapped implementation-specific value"), T(UnsignedInt(format) & ~(1u << 31)); } @@ -2286,7 +2286,7 @@ template constexpr CompressedPixelFormat compressedPixelFormatWrap(T im static_assert(sizeof(T) <= 4, "format types larger than 32bits are not supported"); return CORRADE_CONSTEXPR_ASSERT(!(UnsignedInt(implementationSpecific) & (1u << 31)), - "compressedPixelFormatWrap(): implementation-specific value already wrapped or too large"), + "compressedPixelFormatWrap(): implementation-specific value" << reinterpret_cast(implementationSpecific) << "already wrapped or too large"), CompressedPixelFormat((1u << 31)|UnsignedInt(implementationSpecific)); } @@ -2300,7 +2300,7 @@ inverse operation. */ template constexpr T compressedPixelFormatUnwrap(CompressedPixelFormat format) { return CORRADE_CONSTEXPR_ASSERT(UnsignedInt(format) & (1u << 31), - "compressedPixelFormatUnwrap(): format doesn't contain a wrapped implementation-specific value"), + "compressedPixelFormatUnwrap():" << format << "isn't a wrapped implementation-specific value"), T(UnsignedInt(format) & ~(1u << 31)); } diff --git a/src/Magnum/Test/PixelFormatTest.cpp b/src/Magnum/Test/PixelFormatTest.cpp index bdd8bbcdc..a0d56c5b1 100644 --- a/src/Magnum/Test/PixelFormatTest.cpp +++ b/src/Magnum/Test/PixelFormatTest.cpp @@ -218,7 +218,7 @@ void PixelFormatTest::sizeImplementationSpecific() { pixelSize(pixelFormatWrap(0xdead)); - CORRADE_COMPARE(out.str(), "pixelSize(): can't determine size of an implementation-specific format\n"); + CORRADE_COMPARE(out.str(), "pixelSize(): can't determine size of an implementation-specific format 0xdead\n"); } void PixelFormatTest::compressedBlockSize() { @@ -258,8 +258,8 @@ void PixelFormatTest::compressedBlockSizeImplementationSpecific() { compressedBlockDataSize(compressedPixelFormatWrap(0xdead)); CORRADE_COMPARE(out.str(), - "compressedBlockSize(): can't determine size of an implementation-specific format\n" - "compressedBlockDataSize(): can't determine size of an implementation-specific format\n"); + "compressedBlockSize(): can't determine size of an implementation-specific format 0xdead\n" + "compressedBlockDataSize(): can't determine size of an implementation-specific format 0xdead\n"); } void PixelFormatTest::isImplementationSpecific() { @@ -280,7 +280,7 @@ void PixelFormatTest::wrapInvalid() { pixelFormatWrap(0xdeadbeef); - CORRADE_COMPARE(out.str(), "pixelFormatWrap(): implementation-specific value already wrapped or too large\n"); + CORRADE_COMPARE(out.str(), "pixelFormatWrap(): implementation-specific value 0xdeadbeef already wrapped or too large\n"); } void PixelFormatTest::unwrap() { @@ -292,9 +292,9 @@ void PixelFormatTest::unwrapInvalid() { std::ostringstream out; Error redirectError{&out}; - pixelFormatUnwrap(PixelFormat(0xdead)); + pixelFormatUnwrap(PixelFormat::R8Snorm); - CORRADE_COMPARE(out.str(), "pixelFormatUnwrap(): format doesn't contain a wrapped implementation-specific value\n"); + CORRADE_COMPARE(out.str(), "pixelFormatUnwrap(): PixelFormat::R8Snorm isn't a wrapped implementation-specific value\n"); } void PixelFormatTest::compressedIsImplementationSpecific() { @@ -312,7 +312,7 @@ void PixelFormatTest::compressedWrapInvalid() { compressedPixelFormatWrap(0xdeadbeef); - CORRADE_COMPARE(out.str(), "compressedPixelFormatWrap(): implementation-specific value already wrapped or too large\n"); + CORRADE_COMPARE(out.str(), "compressedPixelFormatWrap(): implementation-specific value 0xdeadbeef already wrapped or too large\n"); } void PixelFormatTest::compressedUnwrap() { @@ -323,9 +323,9 @@ void PixelFormatTest::compressedUnwrapInvalid() { std::ostringstream out; Error redirectError{&out}; - compressedPixelFormatUnwrap(CompressedPixelFormat(0xdead)); + compressedPixelFormatUnwrap(CompressedPixelFormat::EacR11Snorm); - CORRADE_COMPARE(out.str(), "compressedPixelFormatUnwrap(): format doesn't contain a wrapped implementation-specific value\n"); + CORRADE_COMPARE(out.str(), "compressedPixelFormatUnwrap(): CompressedPixelFormat::EacR11Snorm isn't a wrapped implementation-specific value\n"); } void PixelFormatTest::debug() {