From 479fc2c49fdf9a2ec7edf17b1c7a95b42c69bbbd Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Vladim=C3=ADr=20Vondru=C5=A1?= Date: Mon, 1 Jun 2026 18:51:07 +0200 Subject: [PATCH] Text: make sure AbstractFont::openFile() is tested directly as well. Code from 2012 still wants to fight back. Turns out the user implementation of doOpenFile() was never tested, only the fallback paths to doOpenData(). Heh. --- src/Magnum/Text/Test/AbstractFontTest.cpp | 31 +++++++++++++++++++++++ 1 file changed, 31 insertions(+) diff --git a/src/Magnum/Text/Test/AbstractFontTest.cpp b/src/Magnum/Text/Test/AbstractFontTest.cpp index 996c3dcc5..f49ac9404 100644 --- a/src/Magnum/Text/Test/AbstractFontTest.cpp +++ b/src/Magnum/Text/Test/AbstractFontTest.cpp @@ -57,6 +57,7 @@ struct AbstractFontTest: TestSuite::Tester { void construct(); void openData(); + void openFile(); void openFileAsData(); void openFileAsDataNotFound(); @@ -131,6 +132,7 @@ AbstractFontTest::AbstractFontTest() { addTests({&AbstractFontTest::construct, &AbstractFontTest::openData, + &AbstractFontTest::openFile, &AbstractFontTest::openFileAsData, &AbstractFontTest::openFileAsDataNotFound, @@ -252,6 +254,35 @@ void AbstractFontTest::openData() { CORRADE_COMPARE(font.glyphCount(), 15); } +void AbstractFontTest::openFile() { + struct: AbstractFont { + FontFeatures doFeatures() const override { return {}; } + bool doIsOpened() const override { return _opened; } + void doClose() override {} + + Properties doOpenFile(Containers::StringView filename, Float size) override { + _opened = filename == "hello.ttf"; + return {size, 1.0f, 2.0f, 3.0f, 15}; + } + + void doGlyphIdsInto(const Containers::StridedArrayView1D&, const Containers::StridedArrayView1D&) override {} + Vector2 doGlyphSize(UnsignedInt) override { return {}; } + Vector2 doGlyphAdvance(UnsignedInt) override { return {}; } + Containers::Pointer doCreateShaper() override { return {}; } + + bool _opened = false; + } font; + + CORRADE_VERIFY(!font.isOpened()); + font.openFile("hello.ttf", 13.0f); + CORRADE_VERIFY(font.isOpened()); + CORRADE_COMPARE(font.size(), 13.0f); + CORRADE_COMPARE(font.ascent(), 1.0f); + CORRADE_COMPARE(font.descent(), 2.0f); + CORRADE_COMPARE(font.lineHeight(), 3.0f); + CORRADE_COMPARE(font.glyphCount(), 15); +} + void AbstractFontTest::openFileAsData() { struct: AbstractFont { FontFeatures doFeatures() const override { return FontFeature::OpenData; }