Tests: Load Resources via Core::Resource URIs in FontHandling tests

This commit is contained in:
Andrew Kaster 2023-10-03 15:41:01 -06:00 committed by Andrew Kaster
parent 2e759656de
commit 09e3921ff8

View file

@ -6,6 +6,7 @@
*/
#include <AK/Utf8View.h>
#include <LibCore/ResourceImplementationFile.h>
#include <LibGfx/Font/BitmapFont.h>
#include <LibGfx/Font/FontDatabase.h>
#include <LibTest/TestCase.h>
@ -19,25 +20,32 @@
# define TEST_INPUT(x) ("test-inputs/" x)
#endif
static void init_font_database()
{
Core::ResourceImplementation::install(make<Core::ResourceImplementationFile>(TEST_INPUT(""_string)));
Gfx::FontDatabase::the().load_all_fonts_from_uri("resource:///"sv);
}
TEST_CASE(test_fontdatabase_get_by_name)
{
Gfx::FontDatabase::set_default_fonts_lookup_path(TEST_INPUT(""));
init_font_database();
auto name = "Family 12 400 0"sv;
auto& font_database = Gfx::FontDatabase::the();
auto name = "Family 12 400 0"sv;
EXPECT(!font_database.get_by_name(name)->name().is_empty());
}
TEST_CASE(test_fontdatabase_get)
{
Gfx::FontDatabase::set_default_fonts_lookup_path(TEST_INPUT(""));
init_font_database();
auto& font_database = Gfx::FontDatabase::the();
EXPECT(!font_database.get("Family"_fly_string, 12, 400, Gfx::FontWidth::Normal, 0)->name().is_empty());
}
TEST_CASE(test_fontdatabase_for_each_font)
{
Gfx::FontDatabase::set_default_fonts_lookup_path(TEST_INPUT(""));
init_font_database();
auto& font_database = Gfx::FontDatabase::the();
font_database.for_each_font([&](Gfx::Font const& font) {