summaryrefslogtreecommitdiff
path: root/Tests/LibGfx/TestImageDecoder.cpp
diff options
context:
space:
mode:
authorAndreas Kling <kling@serenityos.org>2021-11-11 11:20:58 +0100
committerAndreas Kling <kling@serenityos.org>2021-11-11 11:20:58 +0100
commit09780ba7a9432891096f009a7092a9c8f753ccea (patch)
tree0c00553fd22945ff36851c0f64007a962d13e904 /Tests/LibGfx/TestImageDecoder.cpp
parentba29798039908e7575f2821fd3141df0daba7a47 (diff)
downloadserenity-09780ba7a9432891096f009a7092a9c8f753ccea.zip
Tests/LibGfx: Actually test image decoders in TestImageDecoder
We were passing raw Gfx::Bitmap objects into the various image decoders instead of encoded image data. This made all of them fail, but the test expectations were set up in a way that aligned with this outcome. With this patch, we now test the codecs for real. Except ICO, since we don't have an ICO file handy. That's a FIXME.
Diffstat (limited to 'Tests/LibGfx/TestImageDecoder.cpp')
-rw-r--r--Tests/LibGfx/TestImageDecoder.cpp53
1 files changed, 26 insertions, 27 deletions
diff --git a/Tests/LibGfx/TestImageDecoder.cpp b/Tests/LibGfx/TestImageDecoder.cpp
index dd5f74feb9..7f2a439786 100644
--- a/Tests/LibGfx/TestImageDecoder.cpp
+++ b/Tests/LibGfx/TestImageDecoder.cpp
@@ -5,6 +5,7 @@
* SPDX-License-Identifier: BSD-2-Clause
*/
+#include <AK/MappedFile.h>
#include <AK/String.h>
#include <LibGfx/BMPLoader.h>
#include <LibGfx/GIFLoader.h>
@@ -22,11 +23,11 @@
TEST_CASE(test_bmp)
{
- auto image = Gfx::load_bmp("/res/html/misc/bmpsuite_files/rgba32-1.bmp");
- auto bmp = Gfx::BMPImageDecoderPlugin((const u8*)&image, sizeof(*image));
+ auto file = MappedFile::map("/res/html/misc/bmpsuite_files/rgba32-1.bmp").release_value();
+ auto bmp = Gfx::BMPImageDecoderPlugin((u8 const*)file->data(), file->size());
EXPECT(bmp.frame_count());
- EXPECT(!bmp.sniff());
+ EXPECT(bmp.sniff());
EXPECT(!bmp.is_animated());
EXPECT(!bmp.loop_count());
@@ -36,25 +37,23 @@ TEST_CASE(test_bmp)
TEST_CASE(test_gif)
{
- auto image = Gfx::load_gif("/res/graphics/download-animation.gif");
- auto gif = Gfx::GIFImageDecoderPlugin((const u8*)&image, sizeof(*image));
+ auto file = MappedFile::map("/res/graphics/download-animation.gif").release_value();
+ auto gif = Gfx::GIFImageDecoderPlugin((u8 const*)file->data(), file->size());
EXPECT(gif.frame_count());
- EXPECT(!gif.sniff());
- // FIXME: is_animated() should return true
- // LibGfx::load_gif() returns a bitmap and lies about is_animated()
- EXPECT(!gif.is_animated());
+ EXPECT(gif.sniff());
+ EXPECT(gif.is_animated());
EXPECT(!gif.loop_count());
auto frame = gif.frame(1);
- EXPECT(frame.duration == 0);
+ EXPECT(frame.duration == 400);
}
TEST_CASE(test_ico)
{
// FIXME: Use an ico file
- auto image = Gfx::load_ico("/res/graphics/buggie.png");
- auto ico = Gfx::ICOImageDecoderPlugin((const u8*)&image, sizeof(*image));
+ auto file = MappedFile::map("/res/graphics/buggie.png").release_value();
+ auto ico = Gfx::ICOImageDecoderPlugin((u8 const*)file->data(), file->size());
EXPECT(ico.frame_count());
EXPECT(!ico.sniff());
@@ -67,11 +66,11 @@ TEST_CASE(test_ico)
TEST_CASE(test_jpg)
{
- auto image = Gfx::load_jpg("/res/html/misc/bmpsuite_files/rgb24.jpg");
- auto jpg = Gfx::JPGImageDecoderPlugin((const u8*)&image, sizeof(*image));
+ auto file = MappedFile::map("/res/html/misc/bmpsuite_files/rgb24.jpg").release_value();
+ auto jpg = Gfx::JPGImageDecoderPlugin((u8 const*)file->data(), file->size());
EXPECT(jpg.frame_count());
- EXPECT(!jpg.sniff());
+ EXPECT(jpg.sniff());
EXPECT(!jpg.is_animated());
EXPECT(!jpg.loop_count());
@@ -81,11 +80,11 @@ TEST_CASE(test_jpg)
TEST_CASE(test_pbm)
{
- auto image = Gfx::load_pbm("/res/html/misc/pbmsuite_files/buggie-raw.pbm");
- auto pbm = Gfx::PBMImageDecoderPlugin((const u8*)&image, sizeof(*image));
+ auto file = MappedFile::map("/res/html/misc/pbmsuite_files/buggie-raw.pbm").release_value();
+ auto pbm = Gfx::PBMImageDecoderPlugin((u8 const*)file->data(), file->size());
EXPECT(pbm.frame_count());
- EXPECT(!pbm.sniff());
+ EXPECT(pbm.sniff());
EXPECT(!pbm.is_animated());
EXPECT(!pbm.loop_count());
@@ -95,11 +94,11 @@ TEST_CASE(test_pbm)
TEST_CASE(test_pgm)
{
- auto image = Gfx::load_pbm("/res/html/misc/pbmsuite_files/buggie-raw.pbm");
- auto pgm = Gfx::PGMImageDecoderPlugin((const u8*)&image, sizeof(*image));
+ auto file = MappedFile::map("/res/html/misc/pgmsuite_files/buggie-raw.pgm").release_value();
+ auto pgm = Gfx::PGMImageDecoderPlugin((u8 const*)file->data(), file->size());
EXPECT(pgm.frame_count());
- EXPECT(!pgm.sniff());
+ EXPECT(pgm.sniff());
EXPECT(!pgm.is_animated());
EXPECT(!pgm.loop_count());
@@ -109,11 +108,11 @@ TEST_CASE(test_pgm)
TEST_CASE(test_png)
{
- auto image = Gfx::load_png("/res/graphics/buggie.png");
- auto png = Gfx::PNGImageDecoderPlugin((const u8*)&image, sizeof(*image));
+ auto file = MappedFile::map("/res/graphics/buggie.png").release_value();
+ auto png = Gfx::PNGImageDecoderPlugin((u8 const*)file->data(), file->size());
EXPECT(png.frame_count());
- EXPECT(!png.sniff());
+ EXPECT(png.sniff());
EXPECT(!png.is_animated());
EXPECT(!png.loop_count());
@@ -123,11 +122,11 @@ TEST_CASE(test_png)
TEST_CASE(test_ppm)
{
- auto image = Gfx::load_ppm("/res/html/misc/ppmsuite_files/buggie-raw.ppm");
- auto ppm = Gfx::PPMImageDecoderPlugin((const u8*)&image, sizeof(*image));
+ auto file = MappedFile::map("/res/html/misc/ppmsuite_files/buggie-raw.ppm").release_value();
+ auto ppm = Gfx::PPMImageDecoderPlugin((u8 const*)file->data(), file->size());
EXPECT(ppm.frame_count());
- EXPECT(!ppm.sniff());
+ EXPECT(ppm.sniff());
EXPECT(!ppm.is_animated());
EXPECT(!ppm.loop_count());