From b8b5e0f6806f9db596a968f33798c8eac40c1ced Mon Sep 17 00:00:00 2001 From: Nico Weber Date: Tue, 31 Jan 2023 18:19:08 -0500 Subject: [PATCH] LibGfx: Move TestFontHandling over to input file approach in 8cfabbcd933 Rather than reading files out of /res, put them in a subfolder of Tests/LibGfx/ and pick the path based on AK_OS_SERENITY. That way, the tests can also pass when run under lagom. --- Tests/LibGfx/CMakeLists.txt | 2 +- Tests/LibGfx/TestFontHandling.cpp | 19 +++++++++++++++---- Tests/LibGfx/{ => test-inputs}/TestFont.font | Bin 3 files changed, 16 insertions(+), 5 deletions(-) rename Tests/LibGfx/{ => test-inputs}/TestFont.font (100%) diff --git a/Tests/LibGfx/CMakeLists.txt b/Tests/LibGfx/CMakeLists.txt index 71402111d41..9345fa930cf 100644 --- a/Tests/LibGfx/CMakeLists.txt +++ b/Tests/LibGfx/CMakeLists.txt @@ -8,4 +8,4 @@ foreach(source IN LISTS TEST_SOURCES) serenity_test("${source}" LibGfx LIBS LibGfx) endforeach() -install(FILES TestFont.font DESTINATION usr/Tests/LibGfx) +install(DIRECTORY test-inputs DESTINATION usr/Tests/LibGfx) diff --git a/Tests/LibGfx/TestFontHandling.cpp b/Tests/LibGfx/TestFontHandling.cpp index e2917f038c2..ac560b0940d 100644 --- a/Tests/LibGfx/TestFontHandling.cpp +++ b/Tests/LibGfx/TestFontHandling.cpp @@ -12,21 +12,32 @@ #include #include +#ifdef AK_OS_SERENITY +# define TEST_INPUT(x) ("/usr/Tests/LibGfx/test-inputs/" x) +#else +# define TEST_INPUT(x) ("test-inputs/" x) +#endif + TEST_CASE(test_fontdatabase_get_by_name) { - auto name = "Liza 10 400 0"sv; + Gfx::FontDatabase::set_default_fonts_lookup_path(TEST_INPUT("")); + + auto name = "Family 12 400 0"sv; auto& font_database = Gfx::FontDatabase::the(); EXPECT(!font_database.get_by_name(name)->name().is_null()); } TEST_CASE(test_fontdatabase_get) { + Gfx::FontDatabase::set_default_fonts_lookup_path(TEST_INPUT("")); auto& font_database = Gfx::FontDatabase::the(); - EXPECT(!font_database.get("Liza", 10, 400, 0)->name().is_null()); + EXPECT(!font_database.get("Family", 12, 400, 0)->name().is_null()); } TEST_CASE(test_fontdatabase_for_each_font) { + Gfx::FontDatabase::set_default_fonts_lookup_path(TEST_INPUT("")); + auto& font_database = Gfx::FontDatabase::the(); font_database.for_each_font([&](Gfx::Font const& font) { EXPECT(!font.name().is_null()); @@ -119,7 +130,7 @@ TEST_CASE(test_glyph_or_emoji_width) TEST_CASE(test_load_from_file) { - auto font = Gfx::BitmapFont::load_from_file("/res/fonts/PebbletonBold14.font"); + auto font = Gfx::BitmapFont::load_from_file(TEST_INPUT("TestFont.font"sv)); EXPECT(!font->name().is_null()); } @@ -137,7 +148,7 @@ TEST_CASE(test_write_to_file) TEST_CASE(test_character_set_masking) { - auto font = Gfx::BitmapFont::try_load_from_file("/usr/Tests/LibGfx/TestFont.font"); + auto font = Gfx::BitmapFont::try_load_from_file(TEST_INPUT("TestFont.font"sv)); EXPECT(!font.is_error()); auto unmasked_font = font.value()->unmasked_character_set(); diff --git a/Tests/LibGfx/TestFont.font b/Tests/LibGfx/test-inputs/TestFont.font similarity index 100% rename from Tests/LibGfx/TestFont.font rename to Tests/LibGfx/test-inputs/TestFont.font