/* * Copyright (c) 2021, the SerenityOS developers. * * SPDX-License-Identifier: BSD-2-Clause */ #include #include #include #include #include #include #include #include #include #include #include #include #include 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; }