1
Fork 0
mirror of https://github.com/RGBCube/serenity synced 2025-07-26 01:37:35 +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,155 +0,0 @@
/*
* Copyright (c) 2021, the SerenityOS developers.
*
* SPDX-License-Identifier: BSD-2-Clause
*/
#include <AK/String.h>
#include <LibGfx/BMPLoader.h>
#include <LibGfx/GIFLoader.h>
#include <LibGfx/ICOLoader.h>
#include <LibGfx/ImageDecoder.h>
#include <LibGfx/JPGLoader.h>
#include <LibGfx/PBMLoader.h>
#include <LibGfx/PGMLoader.h>
#include <LibGfx/PNGLoader.h>
#include <LibGfx/PPMLoader.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
static void 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());
assert(!bmp.sniff());
assert(!bmp.is_animated());
assert(!bmp.loop_count());
auto frame = bmp.frame(1);
assert(frame.duration == 0);
}
static void 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());
assert(!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());
auto frame = gif.frame(1);
assert(frame.duration == 0);
}
static void 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());
assert(!ico.sniff());
assert(!ico.is_animated());
assert(!ico.loop_count());
auto frame = ico.frame(1);
assert(frame.duration == 0);
}
static void 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());
assert(!jpg.sniff());
assert(!jpg.is_animated());
assert(!jpg.loop_count());
auto frame = jpg.frame(1);
assert(frame.duration == 0);
}
static void 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());
assert(!pbm.sniff());
assert(!pbm.is_animated());
assert(!pbm.loop_count());
auto frame = pbm.frame(1);
assert(frame.duration == 0);
}
static void 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());
assert(!pgm.sniff());
assert(!pgm.is_animated());
assert(!pgm.loop_count());
auto frame = pgm.frame(1);
assert(frame.duration == 0);
}
static void test_png()
{
auto image = Gfx::load_png("/res/graphics/buggie.png");
auto png = Gfx::PNGImageDecoderPlugin((const u8*)&image, sizeof(*image));
assert(png.frame_count());
assert(!png.sniff());
assert(!png.is_animated());
assert(!png.loop_count());
auto frame = png.frame(1);
assert(frame.duration == 0);
}
static void 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());
assert(!ppm.sniff());
assert(!ppm.is_animated());
assert(!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;
}