Skip to content

Commit 09780ba

Browse files
committed
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.
1 parent ba29798 commit 09780ba

File tree

1 file changed

+26
-27
lines changed

1 file changed

+26
-27
lines changed

Tests/LibGfx/TestImageDecoder.cpp

Lines changed: 26 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
* SPDX-License-Identifier: BSD-2-Clause
66
*/
77

8+
#include <AK/MappedFile.h>
89
#include <AK/String.h>
910
#include <LibGfx/BMPLoader.h>
1011
#include <LibGfx/GIFLoader.h>
@@ -22,11 +23,11 @@
2223

2324
TEST_CASE(test_bmp)
2425
{
25-
auto image = Gfx::load_bmp("/res/html/misc/bmpsuite_files/rgba32-1.bmp");
26-
auto bmp = Gfx::BMPImageDecoderPlugin((const u8*)&image, sizeof(*image));
26+
auto file = MappedFile::map("/res/html/misc/bmpsuite_files/rgba32-1.bmp").release_value();
27+
auto bmp = Gfx::BMPImageDecoderPlugin((u8 const*)file->data(), file->size());
2728
EXPECT(bmp.frame_count());
2829

29-
EXPECT(!bmp.sniff());
30+
EXPECT(bmp.sniff());
3031
EXPECT(!bmp.is_animated());
3132
EXPECT(!bmp.loop_count());
3233

@@ -36,25 +37,23 @@ TEST_CASE(test_bmp)
3637

3738
TEST_CASE(test_gif)
3839
{
39-
auto image = Gfx::load_gif("/res/graphics/download-animation.gif");
40-
auto gif = Gfx::GIFImageDecoderPlugin((const u8*)&image, sizeof(*image));
40+
auto file = MappedFile::map("/res/graphics/download-animation.gif").release_value();
41+
auto gif = Gfx::GIFImageDecoderPlugin((u8 const*)file->data(), file->size());
4142
EXPECT(gif.frame_count());
4243

43-
EXPECT(!gif.sniff());
44-
// FIXME: is_animated() should return true
45-
// LibGfx::load_gif() returns a bitmap and lies about is_animated()
46-
EXPECT(!gif.is_animated());
44+
EXPECT(gif.sniff());
45+
EXPECT(gif.is_animated());
4746
EXPECT(!gif.loop_count());
4847

4948
auto frame = gif.frame(1);
50-
EXPECT(frame.duration == 0);
49+
EXPECT(frame.duration == 400);
5150
}
5251

5352
TEST_CASE(test_ico)
5453
{
5554
// FIXME: Use an ico file
56-
auto image = Gfx::load_ico("/res/graphics/buggie.png");
57-
auto ico = Gfx::ICOImageDecoderPlugin((const u8*)&image, sizeof(*image));
55+
auto file = MappedFile::map("/res/graphics/buggie.png").release_value();
56+
auto ico = Gfx::ICOImageDecoderPlugin((u8 const*)file->data(), file->size());
5857
EXPECT(ico.frame_count());
5958

6059
EXPECT(!ico.sniff());
@@ -67,11 +66,11 @@ TEST_CASE(test_ico)
6766

6867
TEST_CASE(test_jpg)
6968
{
70-
auto image = Gfx::load_jpg("/res/html/misc/bmpsuite_files/rgb24.jpg");
71-
auto jpg = Gfx::JPGImageDecoderPlugin((const u8*)&image, sizeof(*image));
69+
auto file = MappedFile::map("/res/html/misc/bmpsuite_files/rgb24.jpg").release_value();
70+
auto jpg = Gfx::JPGImageDecoderPlugin((u8 const*)file->data(), file->size());
7271
EXPECT(jpg.frame_count());
7372

74-
EXPECT(!jpg.sniff());
73+
EXPECT(jpg.sniff());
7574
EXPECT(!jpg.is_animated());
7675
EXPECT(!jpg.loop_count());
7776

@@ -81,11 +80,11 @@ TEST_CASE(test_jpg)
8180

8281
TEST_CASE(test_pbm)
8382
{
84-
auto image = Gfx::load_pbm("/res/html/misc/pbmsuite_files/buggie-raw.pbm");
85-
auto pbm = Gfx::PBMImageDecoderPlugin((const u8*)&image, sizeof(*image));
83+
auto file = MappedFile::map("/res/html/misc/pbmsuite_files/buggie-raw.pbm").release_value();
84+
auto pbm = Gfx::PBMImageDecoderPlugin((u8 const*)file->data(), file->size());
8685
EXPECT(pbm.frame_count());
8786

88-
EXPECT(!pbm.sniff());
87+
EXPECT(pbm.sniff());
8988
EXPECT(!pbm.is_animated());
9089
EXPECT(!pbm.loop_count());
9190

@@ -95,11 +94,11 @@ TEST_CASE(test_pbm)
9594

9695
TEST_CASE(test_pgm)
9796
{
98-
auto image = Gfx::load_pbm("/res/html/misc/pbmsuite_files/buggie-raw.pbm");
99-
auto pgm = Gfx::PGMImageDecoderPlugin((const u8*)&image, sizeof(*image));
97+
auto file = MappedFile::map("/res/html/misc/pgmsuite_files/buggie-raw.pgm").release_value();
98+
auto pgm = Gfx::PGMImageDecoderPlugin((u8 const*)file->data(), file->size());
10099
EXPECT(pgm.frame_count());
101100

102-
EXPECT(!pgm.sniff());
101+
EXPECT(pgm.sniff());
103102
EXPECT(!pgm.is_animated());
104103
EXPECT(!pgm.loop_count());
105104

@@ -109,11 +108,11 @@ TEST_CASE(test_pgm)
109108

110109
TEST_CASE(test_png)
111110
{
112-
auto image = Gfx::load_png("/res/graphics/buggie.png");
113-
auto png = Gfx::PNGImageDecoderPlugin((const u8*)&image, sizeof(*image));
111+
auto file = MappedFile::map("/res/graphics/buggie.png").release_value();
112+
auto png = Gfx::PNGImageDecoderPlugin((u8 const*)file->data(), file->size());
114113
EXPECT(png.frame_count());
115114

116-
EXPECT(!png.sniff());
115+
EXPECT(png.sniff());
117116
EXPECT(!png.is_animated());
118117
EXPECT(!png.loop_count());
119118

@@ -123,11 +122,11 @@ TEST_CASE(test_png)
123122

124123
TEST_CASE(test_ppm)
125124
{
126-
auto image = Gfx::load_ppm("/res/html/misc/ppmsuite_files/buggie-raw.ppm");
127-
auto ppm = Gfx::PPMImageDecoderPlugin((const u8*)&image, sizeof(*image));
125+
auto file = MappedFile::map("/res/html/misc/ppmsuite_files/buggie-raw.ppm").release_value();
126+
auto ppm = Gfx::PPMImageDecoderPlugin((u8 const*)file->data(), file->size());
128127
EXPECT(ppm.frame_count());
129128

130-
EXPECT(!ppm.sniff());
129+
EXPECT(ppm.sniff());
131130
EXPECT(!ppm.is_animated());
132131
EXPECT(!ppm.loop_count());
133132

0 commit comments

Comments
 (0)