1
Fork 0
mirror of https://github.com/RGBCube/serenity synced 2025-07-25 18:47:34 +00:00

Tests: Convert LibGfx image decoder test to be LibTest based.

This commit is contained in:
Brian Gianforcaro 2021-04-28 18:38:16 -07:00 committed by Andreas Kling
parent d2b4ea69ab
commit 6b5bbf9464
2 changed files with 52 additions and 69 deletions

View file

@ -1,5 +1,6 @@
file(GLOB CMD_SOURCES CONFIGURE_DEPENDS "*.cpp")
list(REMOVE_ITEM CMD_SOURCES ${CMAKE_CURRENT_SOURCE_DIR}/BenchmarkGfxPainter.cpp)
list(REMOVE_ITEM CMD_SOURCES ${CMAKE_CURRENT_SOURCE_DIR}/TestImageDecoder.cpp)
# FIXME These tests do not use LibTest
foreach(CMD_SRC ${CMD_SOURCES})
@ -9,4 +10,5 @@ foreach(CMD_SRC ${CMD_SOURCES})
install(TARGETS ${CMD_NAME} RUNTIME DESTINATION usr/Tests/LibGfx)
endforeach()
serenity_test(TestImageDecoder.cpp LibGfx LIBS LibGUI)
serenity_test(BenchmarkGfxPainter.cpp LibGfx LIBS LibGUI)

View file

@ -1,5 +1,6 @@
/*
* Copyright (c) 2021, the SerenityOS developers.
* Copyright (c) 2021, Brian Gianforcaro <bgianf@serenityos.org>
*
* SPDX-License-Identifier: BSD-2-Clause
*/
@ -14,142 +15,122 @@
#include <LibGfx/PGMLoader.h>
#include <LibGfx/PNGLoader.h>
#include <LibGfx/PPMLoader.h>
#include <LibTest/TestCase.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
static void test_bmp()
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));
assert(bmp.frame_count());
EXPECT(bmp.frame_count());
assert(!bmp.sniff());
assert(!bmp.is_animated());
assert(!bmp.loop_count());
EXPECT(!bmp.sniff());
EXPECT(!bmp.is_animated());
EXPECT(!bmp.loop_count());
auto frame = bmp.frame(1);
assert(frame.duration == 0);
EXPECT(frame.duration == 0);
}
static void test_gif()
TEST_CASE(test_gif)
{
auto image = Gfx::load_gif("/res/graphics/download-animation.gif");
auto gif = Gfx::GIFImageDecoderPlugin((const u8*)&image, sizeof(*image));
assert(gif.frame_count());
EXPECT(gif.frame_count());
assert(!gif.sniff());
EXPECT(!gif.sniff());
// FIXME: is_animated() should return true
// LibGfx::load_gif() returns a bitmap and lies about is_animated()
assert(!gif.is_animated());
assert(!gif.loop_count());
EXPECT(!gif.is_animated());
EXPECT(!gif.loop_count());
auto frame = gif.frame(1);
assert(frame.duration == 0);
EXPECT(frame.duration == 0);
}
static void test_ico()
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));
assert(ico.frame_count());
EXPECT(ico.frame_count());
assert(!ico.sniff());
assert(!ico.is_animated());
assert(!ico.loop_count());
EXPECT(!ico.sniff());
EXPECT(!ico.is_animated());
EXPECT(!ico.loop_count());
auto frame = ico.frame(1);
assert(frame.duration == 0);
EXPECT(frame.duration == 0);
}
static void test_jpg()
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));
assert(jpg.frame_count());
EXPECT(jpg.frame_count());
assert(!jpg.sniff());
assert(!jpg.is_animated());
assert(!jpg.loop_count());
EXPECT(!jpg.sniff());
EXPECT(!jpg.is_animated());
EXPECT(!jpg.loop_count());
auto frame = jpg.frame(1);
assert(frame.duration == 0);
EXPECT(frame.duration == 0);
}
static void test_pbm()
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));
assert(pbm.frame_count());
EXPECT(pbm.frame_count());
assert(!pbm.sniff());
assert(!pbm.is_animated());
assert(!pbm.loop_count());
EXPECT(!pbm.sniff());
EXPECT(!pbm.is_animated());
EXPECT(!pbm.loop_count());
auto frame = pbm.frame(1);
assert(frame.duration == 0);
EXPECT(frame.duration == 0);
}
static void test_pgm()
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));
assert(pgm.frame_count());
EXPECT(pgm.frame_count());
assert(!pgm.sniff());
assert(!pgm.is_animated());
assert(!pgm.loop_count());
EXPECT(!pgm.sniff());
EXPECT(!pgm.is_animated());
EXPECT(!pgm.loop_count());
auto frame = pgm.frame(1);
assert(frame.duration == 0);
EXPECT(frame.duration == 0);
}
static void test_png()
TEST_CASE(test_png)
{
auto image = Gfx::load_png("/res/graphics/buggie.png");
auto png = Gfx::PNGImageDecoderPlugin((const u8*)&image, sizeof(*image));
assert(png.frame_count());
EXPECT(png.frame_count());
assert(!png.sniff());
assert(!png.is_animated());
assert(!png.loop_count());
EXPECT(!png.sniff());
EXPECT(!png.is_animated());
EXPECT(!png.loop_count());
auto frame = png.frame(1);
assert(frame.duration == 0);
EXPECT(frame.duration == 0);
}
static void test_ppm()
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));
assert(ppm.frame_count());
EXPECT(ppm.frame_count());
assert(!ppm.sniff());
assert(!ppm.is_animated());
assert(!ppm.loop_count());
EXPECT(!ppm.sniff());
EXPECT(!ppm.is_animated());
EXPECT(!ppm.loop_count());
auto frame = ppm.frame(1);
assert(frame.duration == 0);
}
int main(int, char**)
{
#define RUNTEST(x) \
{ \
printf("Running " #x " ...\n"); \
x(); \
printf("Success!\n"); \
}
RUNTEST(test_bmp);
RUNTEST(test_gif);
RUNTEST(test_ico);
RUNTEST(test_jpg);
RUNTEST(test_pbm);
RUNTEST(test_pgm);
RUNTEST(test_png);
RUNTEST(test_ppm);
printf("PASS\n");
return 0;
EXPECT(frame.duration == 0);
}