From 7fefac955a537da27e86f547a8c2450cc344d66f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Vladim=C3=ADr=20Vondru=C5=A1?= Date: Fri, 8 Mar 2019 23:04:11 +0100 Subject: [PATCH] Text: debug output for AbstractFont::Feature[s]. --- src/Magnum/Text/AbstractFont.cpp | 21 +++++++++++++++++++++ src/Magnum/Text/AbstractFont.h | 6 ++++++ src/Magnum/Text/Test/AbstractFontTest.cpp | 22 +++++++++++++++++++++- 3 files changed, 48 insertions(+), 1 deletion(-) diff --git a/src/Magnum/Text/AbstractFont.cpp b/src/Magnum/Text/AbstractFont.cpp index 7142be758..0c67e9093 100644 --- a/src/Magnum/Text/AbstractFont.cpp +++ b/src/Magnum/Text/AbstractFont.cpp @@ -238,6 +238,27 @@ Containers::Pointer AbstractFont::layout(const AbstractGlyphCa return doLayout(cache, size, text); } +Debug& operator<<(Debug& debug, const AbstractFont::Feature value) { + switch(value) { + /* LCOV_EXCL_START */ + #define _c(v) case AbstractFont::Feature::v: return debug << "Text::AbstractFont::Feature::" #v; + _c(OpenData) + _c(FileCallback) + _c(PreparedGlyphCache) + #undef _c + /* LCOV_EXCL_STOP */ + } + + return debug << "Text::AbstractFont::Feature(" << Debug::nospace << reinterpret_cast(UnsignedByte(value)) << Debug::nospace << ")"; +} + +Debug& operator<<(Debug& debug, const AbstractFont::Features value) { + return Containers::enumSetDebugOutput(debug, value, "Text::AbstractFont::Features{}", { + AbstractFont::Feature::OpenData, + AbstractFont::Feature::FileCallback, + AbstractFont::Feature::PreparedGlyphCache}); +} + AbstractLayouter::AbstractLayouter(UnsignedInt glyphCount): _glyphCount(glyphCount) {} AbstractLayouter::~AbstractLayouter() = default; diff --git a/src/Magnum/Text/AbstractFont.h b/src/Magnum/Text/AbstractFont.h index ebe160363..519574aeb 100644 --- a/src/Magnum/Text/AbstractFont.h +++ b/src/Magnum/Text/AbstractFont.h @@ -528,6 +528,12 @@ class MAGNUM_TEXT_EXPORT AbstractFont: public PluginManager::AbstractPlugin { CORRADE_ENUMSET_OPERATORS(AbstractFont::Features) +/** @debugoperatorclassenum{AbstractFont,AbstractFont::Feature} */ +MAGNUM_TEXT_EXPORT Debug& operator<<(Debug& debug, AbstractFont::Feature value); + +/** @debugoperatorclassenum{AbstractFont,AbstractFont::Features} */ +MAGNUM_TEXT_EXPORT Debug& operator<<(Debug& debug, AbstractFont::Features value); + /** @brief Base for text layouters diff --git a/src/Magnum/Text/Test/AbstractFontTest.cpp b/src/Magnum/Text/Test/AbstractFontTest.cpp index 4628427b9..72b634f5d 100644 --- a/src/Magnum/Text/Test/AbstractFontTest.cpp +++ b/src/Magnum/Text/Test/AbstractFontTest.cpp @@ -85,6 +85,9 @@ struct AbstractFontTest: TestSuite::Tester { void createGlyphCacheNotSupported(); void createGlyphCacheNotImplemented(); void createGlyphCacheNoFont(); + + void debugFeature(); + void debugFeatures(); }; AbstractFontTest::AbstractFontTest() { @@ -131,7 +134,10 @@ AbstractFontTest::AbstractFontTest() { &AbstractFontTest::createGlyphCache, &AbstractFontTest::createGlyphCacheNotSupported, &AbstractFontTest::createGlyphCacheNotImplemented, - &AbstractFontTest::createGlyphCacheNoFont}); + &AbstractFontTest::createGlyphCacheNoFont, + + &AbstractFontTest::debugFeature, + &AbstractFontTest::debugFeatures}); } void AbstractFontTest::openData() { @@ -1022,6 +1028,20 @@ void AbstractFontTest::createGlyphCacheNoFont() { CORRADE_COMPARE(out.str(), "Text::AbstractFont::createGlyphCache(): no font opened\n"); } +void AbstractFontTest::debugFeature() { + std::ostringstream out; + + Debug{&out} << AbstractFont::Feature::OpenData << AbstractFont::Feature(0xf0); + CORRADE_COMPARE(out.str(), "Text::AbstractFont::Feature::OpenData Text::AbstractFont::Feature(0xf0)\n"); +} + +void AbstractFontTest::debugFeatures() { + std::ostringstream out; + + Debug{&out} << (AbstractFont::Feature::OpenData|AbstractFont::Feature::PreparedGlyphCache) << AbstractFont::Features{}; + CORRADE_COMPARE(out.str(), "Text::AbstractFont::Feature::OpenData|Text::AbstractFont::Feature::PreparedGlyphCache Text::AbstractFont::Features{}\n"); +} + }}}} CORRADE_TEST_MAIN(Magnum::Text::Test::AbstractFontTest)