mirror of
https://github.com/RGBCube/serenity
synced 2025-07-28 05:07:35 +00:00
Tests: Establish root Tests directory, move Userland/Tests there
With the goal of centralizing all tests in the system, this is a first step to establish a Tests sub-tree. It will contain all of the unit tests and test harnesses for the various components in the system.
This commit is contained in:
parent
6e641fadfa
commit
fd0dbd1ebf
49 changed files with 1 additions and 1 deletions
53
Tests/LibGfx/BenchmarkGfxPainter.cpp
Normal file
53
Tests/LibGfx/BenchmarkGfxPainter.cpp
Normal file
|
@ -0,0 +1,53 @@
|
|||
/*
|
||||
* Copyright (c) 2021, Oleg Sikorskiy <olegsik@gmail.com>
|
||||
*
|
||||
* SPDX-License-Identifier: BSD-2-Clause
|
||||
*/
|
||||
|
||||
#include <LibTest/TestCase.h>
|
||||
|
||||
#include <LibGfx/Bitmap.h>
|
||||
#include <LibGfx/Painter.h>
|
||||
#include <stdio.h>
|
||||
|
||||
BENCHMARK_CASE(diagonal_lines)
|
||||
{
|
||||
const int run_count = 50;
|
||||
const int bitmap_size = 2000;
|
||||
|
||||
auto bitmap = Gfx::Bitmap::create(Gfx::BitmapFormat::BGRx8888, { bitmap_size, bitmap_size });
|
||||
Gfx::Painter painter(*bitmap);
|
||||
|
||||
for (int run = 0; run < run_count; run++) {
|
||||
for (int i = 0; i < bitmap_size; i++) {
|
||||
painter.draw_line({ 0, 0 }, { i, bitmap_size - 1 }, Color::Blue);
|
||||
painter.draw_line({ 0, 0 }, { bitmap_size - 1, i }, Color::Blue);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
BENCHMARK_CASE(fill)
|
||||
{
|
||||
const int run_count = 1000;
|
||||
const int bitmap_size = 2000;
|
||||
|
||||
auto bitmap = Gfx::Bitmap::create(Gfx::BitmapFormat::BGRx8888, { bitmap_size, bitmap_size });
|
||||
Gfx::Painter painter(*bitmap);
|
||||
|
||||
for (int run = 0; run < run_count; run++) {
|
||||
painter.fill_rect(bitmap->rect(), Color::Blue);
|
||||
}
|
||||
}
|
||||
|
||||
BENCHMARK_CASE(fill_with_gradient)
|
||||
{
|
||||
const int run_count = 50;
|
||||
const int bitmap_size = 2000;
|
||||
|
||||
auto bitmap = Gfx::Bitmap::create(Gfx::BitmapFormat::BGRx8888, { bitmap_size, bitmap_size });
|
||||
Gfx::Painter painter(*bitmap);
|
||||
|
||||
for (int run = 0; run < run_count; run++) {
|
||||
painter.fill_rect_with_gradient(bitmap->rect(), Color::Blue, Color::Red);
|
||||
}
|
||||
}
|
5
Tests/LibGfx/CMakeLists.txt
Normal file
5
Tests/LibGfx/CMakeLists.txt
Normal file
|
@ -0,0 +1,5 @@
|
|||
file(GLOB TEST_SOURCES CONFIGURE_DEPENDS "*.cpp")
|
||||
|
||||
foreach(source ${TEST_SOURCES})
|
||||
serenity_test(${source} LibGfx LIBS LibGUI)
|
||||
endforeach()
|
169
Tests/LibGfx/TestFontHandling.cpp
Normal file
169
Tests/LibGfx/TestFontHandling.cpp
Normal file
|
@ -0,0 +1,169 @@
|
|||
/*
|
||||
* Copyright (c) 2020, the SerenityOS developers.
|
||||
* Copyright (c) 2021, Brian Gianforcaro <bgianf@serenityos.org>
|
||||
*
|
||||
* SPDX-License-Identifier: BSD-2-Clause
|
||||
*/
|
||||
|
||||
#include <LibGfx/BitmapFont.h>
|
||||
#include <LibGfx/FontDatabase.h>
|
||||
#include <LibTest/TestCase.h>
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
#include <unistd.h>
|
||||
|
||||
TEST_CASE(test_fontdatabase_get_by_name)
|
||||
{
|
||||
const char* name = "Liza 10 400";
|
||||
auto& font_database = Gfx::FontDatabase::the();
|
||||
EXPECT(!font_database.get_by_name(name)->name().is_null());
|
||||
}
|
||||
|
||||
TEST_CASE(test_fontdatabase_get)
|
||||
{
|
||||
auto& font_database = Gfx::FontDatabase::the();
|
||||
EXPECT(!font_database.get("Liza", 10, 400)->name().is_null());
|
||||
}
|
||||
|
||||
TEST_CASE(test_fontdatabase_for_each_font)
|
||||
{
|
||||
auto& font_database = Gfx::FontDatabase::the();
|
||||
font_database.for_each_font([&](const Gfx::Font& font) {
|
||||
EXPECT(!font.name().is_null());
|
||||
EXPECT(!font.qualified_name().is_null());
|
||||
EXPECT(!font.family().is_null());
|
||||
EXPECT(font.glyph_count() > 0);
|
||||
});
|
||||
}
|
||||
|
||||
TEST_CASE(test_default_font)
|
||||
{
|
||||
EXPECT(!Gfx::FontDatabase::default_font().name().is_null());
|
||||
}
|
||||
|
||||
TEST_CASE(test_default_fixed_width_font)
|
||||
{
|
||||
EXPECT(!Gfx::FontDatabase::default_fixed_width_font().name().is_null());
|
||||
}
|
||||
|
||||
TEST_CASE(test_default_bold_fixed_width_font)
|
||||
{
|
||||
EXPECT(!Gfx::FontDatabase::default_bold_fixed_width_font().name().is_null());
|
||||
}
|
||||
|
||||
TEST_CASE(test_default_bold_font)
|
||||
{
|
||||
EXPECT(!Gfx::FontDatabase::default_bold_font().name().is_null());
|
||||
}
|
||||
|
||||
TEST_CASE(test_clone)
|
||||
{
|
||||
u8 glyph_height = 1;
|
||||
u8 glyph_width = 1;
|
||||
auto font = Gfx::BitmapFont::create(glyph_height, glyph_width, true, Gfx::FontTypes::Default);
|
||||
|
||||
auto new_font = font->clone();
|
||||
EXPECT(!new_font->name().is_null());
|
||||
EXPECT(!new_font->qualified_name().is_null());
|
||||
EXPECT(!new_font->family().is_null());
|
||||
EXPECT(new_font->glyph_count() > 0);
|
||||
}
|
||||
|
||||
TEST_CASE(test_set_name)
|
||||
{
|
||||
u8 glyph_height = 1;
|
||||
u8 glyph_width = 1;
|
||||
auto font = Gfx::BitmapFont::create(glyph_height, glyph_width, true, Gfx::FontTypes::Default);
|
||||
|
||||
const char* name = "my newly created font";
|
||||
font->set_name(name);
|
||||
|
||||
EXPECT(!font->name().is_null());
|
||||
EXPECT(font->name().contains(name));
|
||||
}
|
||||
|
||||
TEST_CASE(test_set_family)
|
||||
{
|
||||
u8 glyph_height = 1;
|
||||
u8 glyph_width = 1;
|
||||
auto font = Gfx::BitmapFont::create(glyph_height, glyph_width, true, Gfx::FontTypes::Default);
|
||||
|
||||
const char* family = "my newly created font family";
|
||||
font->set_family(family);
|
||||
|
||||
EXPECT(!font->family().is_null());
|
||||
EXPECT(font->family().contains(family));
|
||||
}
|
||||
|
||||
TEST_CASE(test_set_glyph_width)
|
||||
{
|
||||
u8 glyph_height = 1;
|
||||
u8 glyph_width = 1;
|
||||
auto font = Gfx::BitmapFont::create(glyph_height, glyph_width, true, Gfx::FontTypes::Default);
|
||||
|
||||
size_t ch = 123;
|
||||
font->set_glyph_width(ch, glyph_width);
|
||||
|
||||
EXPECT(font->glyph_width(ch) == glyph_width);
|
||||
}
|
||||
|
||||
TEST_CASE(test_set_glyph_spacing)
|
||||
{
|
||||
u8 glyph_height = 1;
|
||||
u8 glyph_width = 1;
|
||||
auto font = Gfx::BitmapFont::create(glyph_height, glyph_width, true, Gfx::FontTypes::Default);
|
||||
|
||||
u8 glyph_spacing = 8;
|
||||
font->set_glyph_spacing(glyph_spacing);
|
||||
|
||||
EXPECT(font->glyph_spacing() == glyph_spacing);
|
||||
}
|
||||
|
||||
TEST_CASE(test_set_type)
|
||||
{
|
||||
u8 glyph_height = 1;
|
||||
u8 glyph_width = 1;
|
||||
auto font = Gfx::BitmapFont::create(glyph_height, glyph_width, true, Gfx::FontTypes::Default);
|
||||
|
||||
auto type = Gfx::FontTypes::Default;
|
||||
font->set_type(type);
|
||||
|
||||
EXPECT(font->type() == type);
|
||||
}
|
||||
|
||||
TEST_CASE(test_width)
|
||||
{
|
||||
u8 glyph_height = 1;
|
||||
u8 glyph_width = 1;
|
||||
auto font = Gfx::BitmapFont::create(glyph_height, glyph_width, true, Gfx::FontTypes::Default);
|
||||
|
||||
EXPECT(font->width("A") == glyph_width);
|
||||
}
|
||||
|
||||
TEST_CASE(test_glyph_or_emoji_width)
|
||||
{
|
||||
u8 glyph_height = 1;
|
||||
u8 glyph_width = 1;
|
||||
auto font = Gfx::BitmapFont::create(glyph_height, glyph_width, true, Gfx::FontTypes::Default);
|
||||
font->set_type(Gfx::FontTypes::Default);
|
||||
|
||||
EXPECT(font->glyph_or_emoji_width(0));
|
||||
}
|
||||
|
||||
TEST_CASE(test_load_from_file)
|
||||
{
|
||||
auto font = Gfx::BitmapFont::load_from_file("/res/fonts/PebbletonBold14.font");
|
||||
EXPECT(!font->name().is_null());
|
||||
}
|
||||
|
||||
TEST_CASE(test_write_to_file)
|
||||
{
|
||||
u8 glyph_height = 1;
|
||||
u8 glyph_width = 1;
|
||||
auto font = Gfx::BitmapFont::create(glyph_height, glyph_width, true, Gfx::FontTypes::Default);
|
||||
|
||||
char path[] = "/tmp/new.font.XXXXXX";
|
||||
EXPECT(mkstemp(path) != -1);
|
||||
EXPECT(font->write_to_file(path));
|
||||
unlink(path);
|
||||
}
|
136
Tests/LibGfx/TestImageDecoder.cpp
Normal file
136
Tests/LibGfx/TestImageDecoder.cpp
Normal file
|
@ -0,0 +1,136 @@
|
|||
/*
|
||||
* Copyright (c) 2021, the SerenityOS developers.
|
||||
* Copyright (c) 2021, Brian Gianforcaro <bgianf@serenityos.org>
|
||||
*
|
||||
* 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 <LibTest/TestCase.h>
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
#include <string.h>
|
||||
|
||||
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));
|
||||
EXPECT(bmp.frame_count());
|
||||
|
||||
EXPECT(!bmp.sniff());
|
||||
EXPECT(!bmp.is_animated());
|
||||
EXPECT(!bmp.loop_count());
|
||||
|
||||
auto frame = bmp.frame(1);
|
||||
EXPECT(frame.duration == 0);
|
||||
}
|
||||
|
||||
TEST_CASE(test_gif)
|
||||
{
|
||||
auto image = Gfx::load_gif("/res/graphics/download-animation.gif");
|
||||
auto gif = Gfx::GIFImageDecoderPlugin((const u8*)&image, sizeof(*image));
|
||||
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.loop_count());
|
||||
|
||||
auto frame = gif.frame(1);
|
||||
EXPECT(frame.duration == 0);
|
||||
}
|
||||
|
||||
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));
|
||||
EXPECT(ico.frame_count());
|
||||
|
||||
EXPECT(!ico.sniff());
|
||||
EXPECT(!ico.is_animated());
|
||||
EXPECT(!ico.loop_count());
|
||||
|
||||
auto frame = ico.frame(1);
|
||||
EXPECT(frame.duration == 0);
|
||||
}
|
||||
|
||||
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));
|
||||
EXPECT(jpg.frame_count());
|
||||
|
||||
EXPECT(!jpg.sniff());
|
||||
EXPECT(!jpg.is_animated());
|
||||
EXPECT(!jpg.loop_count());
|
||||
|
||||
auto frame = jpg.frame(1);
|
||||
EXPECT(frame.duration == 0);
|
||||
}
|
||||
|
||||
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));
|
||||
EXPECT(pbm.frame_count());
|
||||
|
||||
EXPECT(!pbm.sniff());
|
||||
EXPECT(!pbm.is_animated());
|
||||
EXPECT(!pbm.loop_count());
|
||||
|
||||
auto frame = pbm.frame(1);
|
||||
EXPECT(frame.duration == 0);
|
||||
}
|
||||
|
||||
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));
|
||||
EXPECT(pgm.frame_count());
|
||||
|
||||
EXPECT(!pgm.sniff());
|
||||
EXPECT(!pgm.is_animated());
|
||||
EXPECT(!pgm.loop_count());
|
||||
|
||||
auto frame = pgm.frame(1);
|
||||
EXPECT(frame.duration == 0);
|
||||
}
|
||||
|
||||
TEST_CASE(test_png)
|
||||
{
|
||||
auto image = Gfx::load_png("/res/graphics/buggie.png");
|
||||
auto png = Gfx::PNGImageDecoderPlugin((const u8*)&image, sizeof(*image));
|
||||
EXPECT(png.frame_count());
|
||||
|
||||
EXPECT(!png.sniff());
|
||||
EXPECT(!png.is_animated());
|
||||
EXPECT(!png.loop_count());
|
||||
|
||||
auto frame = png.frame(1);
|
||||
EXPECT(frame.duration == 0);
|
||||
}
|
||||
|
||||
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));
|
||||
EXPECT(ppm.frame_count());
|
||||
|
||||
EXPECT(!ppm.sniff());
|
||||
EXPECT(!ppm.is_animated());
|
||||
EXPECT(!ppm.loop_count());
|
||||
|
||||
auto frame = ppm.frame(1);
|
||||
EXPECT(frame.duration == 0);
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue