diff --git a/src/Magnum/GL/Test/BufferImageGLTest.cpp b/src/Magnum/GL/Test/BufferImageGLTest.cpp index 00749de40..fc6b1d72d 100644 --- a/src/Magnum/GL/Test/BufferImageGLTest.cpp +++ b/src/Magnum/GL/Test/BufferImageGLTest.cpp @@ -27,6 +27,7 @@ #include #include #include +#include #include /** @todo remove once dataProperties() std::pair is gone */ #include "Magnum/PixelFormat.h" @@ -63,6 +64,8 @@ struct BufferImageGLTest: OpenGLTester { void setDataGeneric(); void setDataCompressed(); void setDataCompressedGeneric(); + void setDataInvalidSize(); + void setDataCompressedInvalidSize(); void release(); void releaseCompressed(); @@ -93,6 +96,8 @@ BufferImageGLTest::BufferImageGLTest() { &BufferImageGLTest::setDataGeneric, &BufferImageGLTest::setDataCompressed, &BufferImageGLTest::setDataCompressedGeneric, + &BufferImageGLTest::setDataInvalidSize, + &BufferImageGLTest::setDataCompressedInvalidSize, &BufferImageGLTest::release, &BufferImageGLTest::releaseCompressed}); @@ -399,28 +404,38 @@ void BufferImageGLTest::constructInvalidSize() { Containers::String out; Error redirectError{&out}; - - /* Doesn't consider alignment */ - BufferImage2D{Magnum::PixelFormat::RGB8Unorm, {1, 3}, Containers::Array{3*3}, BufferUsage::StaticDraw}; - CORRADE_COMPARE(out, "GL::BufferImage: data too small, got 9 but expected at least 12 bytes\n"); + BufferImage2D{Magnum::PixelFormat::RGB8Unorm, {1, 3}, Containers::Array{11}, BufferUsage::StaticDraw}; + CORRADE_COMPARE(out, "GL::BufferImage: data too small, got 11 but expected at least 12 bytes\n"); } void BufferImageGLTest::constructCompressedInvalidSize() { + CORRADE_SKIP_IF_NO_ASSERT(); + CORRADE_EXPECT_FAIL("Size checking for compressed image data is not implemented yet."); /* Too small for given format */ { Containers::String out; Error redirectError{&out}; - CompressedBufferImage2D{Magnum::CompressedPixelFormat::Bc2RGBAUnorm, {4, 4}, Containers::Array{2}, BufferUsage::StaticDraw}; - CORRADE_COMPARE(out, "GL::CompressedBufferImage::CompressedBufferImage(): data too small, got 2 but expected at least 4 bytes\n"); + CompressedBufferImage2D{Magnum::CompressedPixelFormat::Bc2RGBAUnorm, {4, 4}, Containers::Array{15}, BufferUsage::StaticDraw}; + /* Here it's assuming the buffer is already filled, of given size */ + CompressedBufferImage2D{Magnum::CompressedPixelFormat::Bc2RGBAUnorm, {4, 4}, GL::Buffer{}, 15}; + CORRADE_COMPARE_AS(out, + "GL::CompressedBufferImage: data too small, got 15 but expected at least 16 bytes\n" + "GL::CompressedBufferImage: data too small, got 15 but expected at least 16 bytes\n", + TestSuite::Compare::String); /* Size should be rounded up even if the image size is not full block */ } { Containers::String out; Error redirectError{&out}; - CompressedBufferImage2D{Magnum::CompressedPixelFormat::Bc2RGBAUnorm, {2, 2}, Containers::Array{2}, BufferUsage::StaticDraw}; - CORRADE_COMPARE(out, "GL::CompressedBufferImage::CompressedBufferImage(): data too small, got 2 but expected at least 4 bytes\n"); + CompressedBufferImage2D{Magnum::CompressedPixelFormat::Bc2RGBAUnorm, {2, 2}, Containers::Array{15}, BufferUsage::StaticDraw}; + /* Here it's assuming the buffer is already filled, of given size */ + CompressedBufferImage2D{Magnum::CompressedPixelFormat::Bc2RGBAUnorm, {2, 2}, GL::Buffer{}, 15}; + CORRADE_COMPARE_AS(out, + "GL::CompressedBufferImage: data too small, got 15 but expected at least 16 bytes\n" + "GL::CompressedBufferImage: data too small, got 15 but expected at least 16 bytes\n", + TestSuite::Compare::String); } } @@ -663,6 +678,57 @@ void BufferImageGLTest::setDataCompressedGeneric() { #endif } +void BufferImageGLTest::setDataInvalidSize() { + CORRADE_SKIP_IF_NO_ASSERT(); + + BufferImage2D image{PixelFormat::Red, PixelType::UnsignedByte, {}, {nullptr, 7}, BufferUsage::StaticDraw}; + + Containers::String out; + Error redirectError{&out}; + image.setData(PixelFormat::RGB, PixelType::UnsignedByte, {1, 3}, Containers::Array{11}, BufferUsage::StaticDraw); + /* Keeping current storage */ + image.setData(PixelFormat::RGBA, PixelType::UnsignedByte, {2, 1}, nullptr, BufferUsage::StaticDraw); + CORRADE_COMPARE_AS(out, + "GL::BufferImage::setData(): data too small, got 11 but expected at least 12 bytes\n" + "GL::BufferImage::setData(): current storage too small, got 7 but expected at least 8 bytes\n", + TestSuite::Compare::String); +} + +void BufferImageGLTest::setDataCompressedInvalidSize() { + CORRADE_SKIP_IF_NO_ASSERT(); + + /* Fits almost two blocks, but only almost */ + CompressedBufferImage2D a{CompressedPixelFormat::RGBAS3tcDxt1, {4, 4}, "helloheyhellhe", BufferUsage::StaticDraw}; + CORRADE_COMPARE(a.dataSize(), 15); + + CORRADE_EXPECT_FAIL("Size checking for compressed image data is not implemented yet."); + + /* Too small for given format */ + { + Containers::String out; + Error redirectError{&out}; + a.setData(CompressedPixelFormat::RGBAS3tcDxt3, {8, 4}, "helloheyhelloheyhelloheyhellhe", BufferUsage::StaticDraw); + /* Keeping current storage */ + a.setData(CompressedPixelFormat::RGBAS3tcDxt1, {8, 4}, nullptr, BufferUsage::StaticDraw); + CORRADE_COMPARE_AS(out, + "GL::CompressedBufferImage::setData(): data too small, got 31 but expected at least 32 bytes\n" + "GL::CompressedBufferImage::setData(): current storage too small, got 15 but expected at least 16 bytes\n", + TestSuite::Compare::String); + + /* Size should be rounded up even if the image size is not that big */ + } { + Containers::String out; + Error redirectError{&out}; + a.setData(CompressedPixelFormat::RGBAS3tcDxt3, {5, 2}, "helloheyhelloheyhelloheyhellhe", BufferUsage::StaticDraw); + /* Keeping current storage */ + a.setData(CompressedPixelFormat::RGBAS3tcDxt1, {5, 2}, nullptr, BufferUsage::StaticDraw); + CORRADE_COMPARE_AS(out, + "GL::CompressedBufferImage::setData(): data too small, got 31 but expected at least 32 bytes\n" + "GL::CompressedBufferImage::setData(): current storage too small, got 15 but expected at least 16 bytes\n", + TestSuite::Compare::String); + } +} + void BufferImageGLTest::release() { BufferImage2D a{PixelFormat::RGBA, PixelType::UnsignedByte}; const UnsignedInt id = a.buffer().id(); diff --git a/src/Magnum/Test/ImageTest.cpp b/src/Magnum/Test/ImageTest.cpp index 25087052d..43dbdbc27 100644 --- a/src/Magnum/Test/ImageTest.cpp +++ b/src/Magnum/Test/ImageTest.cpp @@ -540,21 +540,23 @@ void ImageTest::constructInvalidCubeMap() { } void ImageTest::constructCompressedInvalidSize() { + CORRADE_SKIP_IF_NO_ASSERT(); + CORRADE_EXPECT_FAIL("Size checking for compressed image data is not implemented yet."); /* Too small for given format */ { Containers::String out; Error redirectError{&out}; - CompressedImage2D{CompressedPixelFormat::Bc2RGBAUnorm, {4, 4}, Containers::Array{2}}; - CORRADE_COMPARE(out, "CompressedImage: data too small, got 2 but expected at least 4 bytes\n"); + CompressedImage2D{CompressedPixelFormat::Bc2RGBAUnorm, {4, 4}, Containers::Array{15}}; + CORRADE_COMPARE(out, "CompressedImage: data too small, got 15 but expected at least 16 bytes\n"); /* Size should be rounded up even if the image size is not full block */ } { Containers::String out; Error redirectError{&out}; - CompressedImage2D{CompressedPixelFormat::Bc2RGBAUnorm, {2, 2}, Containers::Array{2}}; - CORRADE_COMPARE(out, "CompressedImage: data too small, got 2 but expected at least 4 bytes\n"); + CompressedImage2D{CompressedPixelFormat::Bc2RGBAUnorm, {2, 2}, Containers::Array{15}}; + CORRADE_COMPARE(out, "CompressedImage: data too small, got 15 but expected at least 16 bytes\n"); } } diff --git a/src/Magnum/Test/ImageViewTest.cpp b/src/Magnum/Test/ImageViewTest.cpp index 0499829d4..4a8176b3e 100644 --- a/src/Magnum/Test/ImageViewTest.cpp +++ b/src/Magnum/Test/ImageViewTest.cpp @@ -700,13 +700,12 @@ void ImageViewTest::constructInvalidPixelSize() { void ImageViewTest::constructInvalidSize() { CORRADE_SKIP_IF_NO_ASSERT(); + const char data[11]{}; + Containers::String out; Error redirectError{&out}; - - /* Doesn't consider alignment */ - const char data[3*3]{}; ImageView2D{PixelFormat::RGB8Unorm, {1, 3}, data}; - CORRADE_COMPARE(out, "ImageView: data too small, got 9 but expected at least 12 bytes\n"); + CORRADE_COMPARE(out, "ImageView: data too small, got 11 but expected at least 12 bytes\n"); } void ImageViewTest::constructInvalidCubeMap() { @@ -731,23 +730,25 @@ void ImageViewTest::constructInvalidCubeMap() { } void ImageViewTest::constructCompressedInvalidSize() { + CORRADE_SKIP_IF_NO_ASSERT(); + CORRADE_EXPECT_FAIL("Size checking for compressed image data is not implemented yet."); - const char data[2]{}; + const char data[15]{}; /* Too small for given format */ { Containers::String out; Error redirectError{&out}; CompressedImageView2D{CompressedPixelFormat::Bc2RGBAUnorm, {4, 4}, data}; - CORRADE_COMPARE(out, "CompressedImageView: data too small, got 2 but expected at least 4 bytes\n"); + CORRADE_COMPARE(out, "CompressedImageView: data too small, got 15 but expected at least 16 bytes\n"); /* Size should be rounded up even if the image size is not full block */ } { Containers::String out; Error redirectError{&out}; CompressedImageView2D{CompressedPixelFormat::Bc2RGBAUnorm, {2, 2}, data}; - CORRADE_COMPARE(out, "CompressedImageView: data too small, got 2 but expected at least 4 bytes\n"); + CORRADE_COMPARE(out, "CompressedImageView: data too small, got 15 but expected at least 16 bytes\n"); } } @@ -832,35 +833,39 @@ template void ImageViewTest::setDataCompressed() { void ImageViewTest::setDataInvalidSize() { CORRADE_SKIP_IF_NO_ASSERT(); - Containers::String out; - Error redirectError{&out}; - ImageView2D image{PixelFormat::RGB8Unorm, {1, 3}}; - const char data[3*3]{}; + const char data[11]{}; - /* Doesn't consider alignment */ + Containers::String out; + Error redirectError{&out}; image.setData(data); - CORRADE_COMPARE(out, "ImageView::setData(): data too small, got 9 but expected at least 12 bytes\n"); + CORRADE_COMPARE(out, "ImageView::setData(): data too small, got 11 but expected at least 12 bytes\n"); } void ImageViewTest::setDataCompressedInvalidSize() { + CORRADE_SKIP_IF_NO_ASSERT(); + CORRADE_EXPECT_FAIL("Size checking for compressed image data is not implemented yet."); - const char data[2]{}; + const char data[11]{}; /* Too small for given format */ { + CompressedImageView2D image{CompressedPixelFormat::Bc2RGBAUnorm, {4, 4}}; + Containers::String out; Error redirectError{&out}; - CompressedImageView2D{CompressedPixelFormat::Bc2RGBAUnorm, {4, 4}, data}; - CORRADE_COMPARE(out, "CompressedImageView::setData(): data too small, got 2 but expected at least 4 bytes\n"); + image.setData(data); + CORRADE_COMPARE(out, "CompressedImageView::setData(): data too small, got 11 but expected at least 16 bytes\n"); /* Size should be rounded up even if the image size is not that big */ } { + CompressedImageView2D image{CompressedPixelFormat::Bc2RGBAUnorm, {2, 2}}; + Containers::String out; Error redirectError{&out}; - CompressedImageView2D{CompressedPixelFormat::Bc2RGBAUnorm, {2, 2}, data}; - CORRADE_COMPARE(out, "CompressedImageView::setData(): data too small, got 2 but expected at least 4 bytes\n"); + image.setData(data); + CORRADE_COMPARE(out, "CompressedImageView::setData(): data too small, got 11 but expected at least 16 bytes\n"); } } diff --git a/src/Magnum/Trade/Test/ImageDataTest.cpp b/src/Magnum/Trade/Test/ImageDataTest.cpp index ddd94a19d..329743f8e 100644 --- a/src/Magnum/Trade/Test/ImageDataTest.cpp +++ b/src/Magnum/Trade/Test/ImageDataTest.cpp @@ -724,21 +724,23 @@ void ImageDataTest::constructInvalidCubeMap() { } void ImageDataTest::constructCompressedInvalidSize() { + CORRADE_SKIP_IF_NO_ASSERT(); + CORRADE_EXPECT_FAIL("Size checking for compressed image data is not implemented yet."); /* Too small for given format */ { Containers::String out; Error redirectError{&out}; - ImageData2D{CompressedPixelFormat::Bc2RGBAUnorm, {4, 4}, Containers::Array{2}}; - CORRADE_COMPARE(out, "Trade::ImageData::ImageData(): data too small, got 2 but expected at least 4 bytes\n"); + ImageData2D{CompressedPixelFormat::Bc2RGBAUnorm, {4, 4}, Containers::Array{15}}; + CORRADE_COMPARE(out, "Trade::ImageData: data too small, got 15 but expected at least 16 bytes\n"); /* Size should be rounded up even if the image size is not full block */ } { Containers::String out; Error redirectError{&out}; - ImageData2D{CompressedPixelFormat::Bc2RGBAUnorm, {2, 2}, Containers::Array{2}}; - CORRADE_COMPARE(out, "Trade::ImageData::ImageData(): data too small, got 2 but expected at least 4 bytes\n"); + ImageData2D{CompressedPixelFormat::Bc2RGBAUnorm, {2, 2}, Containers::Array{15}}; + CORRADE_COMPARE(out, "Trade::ImageData: data too small, got 15 but expected at least 16 bytes\n"); } }