Browse Source

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.
pull/482/merge
Vladimír Vondruš 3 weeks ago
parent
commit
479fc2c49f
  1. 31
      src/Magnum/Text/Test/AbstractFontTest.cpp

31
src/Magnum/Text/Test/AbstractFontTest.cpp

@ -57,6 +57,7 @@ struct AbstractFontTest: TestSuite::Tester {
void construct(); void construct();
void openData(); void openData();
void openFile();
void openFileAsData(); void openFileAsData();
void openFileAsDataNotFound(); void openFileAsDataNotFound();
@ -131,6 +132,7 @@ AbstractFontTest::AbstractFontTest() {
addTests({&AbstractFontTest::construct, addTests({&AbstractFontTest::construct,
&AbstractFontTest::openData, &AbstractFontTest::openData,
&AbstractFontTest::openFile,
&AbstractFontTest::openFileAsData, &AbstractFontTest::openFileAsData,
&AbstractFontTest::openFileAsDataNotFound, &AbstractFontTest::openFileAsDataNotFound,
@ -252,6 +254,35 @@ void AbstractFontTest::openData() {
CORRADE_COMPARE(font.glyphCount(), 15); 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 char32_t>&, const Containers::StridedArrayView1D<UnsignedInt>&) override {}
Vector2 doGlyphSize(UnsignedInt) override { return {}; }
Vector2 doGlyphAdvance(UnsignedInt) override { return {}; }
Containers::Pointer<AbstractShaper> 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() { void AbstractFontTest::openFileAsData() {
struct: AbstractFont { struct: AbstractFont {
FontFeatures doFeatures() const override { return FontFeature::OpenData; } FontFeatures doFeatures() const override { return FontFeature::OpenData; }

Loading…
Cancel
Save