From 0a26831a103b7d2e57c26bf864af44036a6eb623 Mon Sep 17 00:00:00 2001 From: Nico Weber Date: Sat, 4 May 2024 21:50:14 -0400 Subject: [PATCH] TestImageWriter: Add a PNG roundtrip test --- Tests/LibGfx/TestImageWriter.cpp | 19 ++++++++++++++++--- 1 file changed, 16 insertions(+), 3 deletions(-) diff --git a/Tests/LibGfx/TestImageWriter.cpp b/Tests/LibGfx/TestImageWriter.cpp index d92b345e97d..0582b95337b 100644 --- a/Tests/LibGfx/TestImageWriter.cpp +++ b/Tests/LibGfx/TestImageWriter.cpp @@ -6,6 +6,8 @@ #include #include +#include +#include #include #include #include @@ -32,9 +34,14 @@ static ErrorOr> expect_single_frame_of_size(Gfx::Imag template static ErrorOr test_roundtrip(Gfx::Bitmap const& bitmap) { - AllocatingMemoryStream stream; - TRY(Writer::encode(stream, bitmap)); - auto encoded_data = TRY(stream.read_until_eof()); + ByteBuffer encoded_data; + if constexpr (requires(AllocatingMemoryStream stream) { Writer::encode(stream, bitmap); }) { + AllocatingMemoryStream stream; + TRY(Writer::encode(stream, bitmap)); + encoded_data = TRY(stream.read_until_eof()); + } else { + encoded_data = TRY(Writer::encode(bitmap)); + } auto plugin = TRY(Loader::create(encoded_data)); auto decoded = TRY(expect_single_frame_of_size(*plugin, bitmap.size())); @@ -72,6 +79,12 @@ static ErrorOr> create_test_rgba_bitmap() return bitmap; } +TEST_CASE(test_png) +{ + TRY_OR_FAIL((test_roundtrip(TRY_OR_FAIL(create_test_rgb_bitmap())))); + TRY_OR_FAIL((test_roundtrip(TRY_OR_FAIL(create_test_rgba_bitmap())))); +} + TEST_CASE(test_webp) { TRY_OR_FAIL((test_roundtrip(TRY_OR_FAIL(create_test_rgb_bitmap()))));