From 365f501f72dede50c1aa3b150c2a2fad409540a9 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Vladim=C3=ADr=20Vondru=C5=A1?= Date: Mon, 16 Jul 2018 15:53:27 +0200 Subject: [PATCH] Trade: debug output for AbstractImporter::Feature and Features. --- doc/changelog.dox | 2 ++ src/Magnum/Trade/AbstractImporter.cpp | 18 +++++++++++++++ src/Magnum/Trade/AbstractImporter.h | 6 +++++ .../Trade/Test/AbstractImporterTest.cpp | 23 ++++++++++++++++++- 4 files changed, 48 insertions(+), 1 deletion(-) diff --git a/doc/changelog.dox b/doc/changelog.dox index f8692c8dd..65f197657 100644 --- a/doc/changelog.dox +++ b/doc/changelog.dox @@ -74,6 +74,8 @@ See also: separate translation / rotation / scaling specification instead of a combined transformation matrix. See @ref Trade::ObjectData2D::transformation() and @ref Trade::ObjectData3D::transformation() for more information. +- Debug output for @ref Trade::AbstractImporter::Feature enum and + @ref Trade::AbstractImporter::Features enum set @subsection changelog-latest-changes Changes and improvements diff --git a/src/Magnum/Trade/AbstractImporter.cpp b/src/Magnum/Trade/AbstractImporter.cpp index 03ae5be26..81aa3e020 100644 --- a/src/Magnum/Trade/AbstractImporter.cpp +++ b/src/Magnum/Trade/AbstractImporter.cpp @@ -26,6 +26,7 @@ #include "AbstractImporter.h" #include +#include #include #include #include @@ -496,4 +497,21 @@ const void* AbstractImporter::importerState() const { const void* AbstractImporter::doImporterState() const { return nullptr; } +Debug& operator<<(Debug& debug, const AbstractImporter::Feature value) { + switch(value) { + #define _c(v) case AbstractImporter::Feature::v: return debug << "Trade::AbstractImporter::Feature::" #v; + _c(OpenData) + _c(OpenState) + #undef _c + } + + return debug << "Trade::AbstractImporter::Feature(" << Debug::nospace << reinterpret_cast(UnsignedByte(value)) << Debug::nospace << ")"; +} + +Debug& operator<<(Debug& debug, const AbstractImporter::Features value) { + return Containers::enumSetDebugOutput(debug, value, "Trade::AbstractImporter::Features{}", { + AbstractImporter::Feature::OpenData, + AbstractImporter::Feature::OpenState}); +} + }} diff --git a/src/Magnum/Trade/AbstractImporter.h b/src/Magnum/Trade/AbstractImporter.h index 912ec2a26..c641527fc 100644 --- a/src/Magnum/Trade/AbstractImporter.h +++ b/src/Magnum/Trade/AbstractImporter.h @@ -872,6 +872,12 @@ class MAGNUM_TRADE_EXPORT AbstractImporter: public PluginManager::AbstractManagi CORRADE_ENUMSET_OPERATORS(AbstractImporter::Features) +/** @debugoperatorclassenum{AbstractImporter,AbstractImporter::Feature} */ +MAGNUM_TRADE_EXPORT Debug& operator<<(Debug& debug, AbstractImporter::Feature value); + +/** @debugoperatorclassenum{AbstractImporter,AbstractImporter::Features} */ +MAGNUM_TRADE_EXPORT Debug& operator<<(Debug& debug, AbstractImporter::Features value); + }} #endif diff --git a/src/Magnum/Trade/Test/AbstractImporterTest.cpp b/src/Magnum/Trade/Test/AbstractImporterTest.cpp index 53d107a97..b5843ea83 100644 --- a/src/Magnum/Trade/Test/AbstractImporterTest.cpp +++ b/src/Magnum/Trade/Test/AbstractImporterTest.cpp @@ -23,6 +23,7 @@ DEALINGS IN THE SOFTWARE. */ +#include #include #include #include @@ -38,10 +39,16 @@ class AbstractImporterTest: public TestSuite::Tester { explicit AbstractImporterTest(); void openFile(); + + void debugFeature(); + void debugFeatures(); }; AbstractImporterTest::AbstractImporterTest() { - addTests({&AbstractImporterTest::openFile}); + addTests({&AbstractImporterTest::openFile, + + &AbstractImporterTest::debugFeature, + &AbstractImporterTest::debugFeatures}); } void AbstractImporterTest::openFile() { @@ -68,6 +75,20 @@ void AbstractImporterTest::openFile() { CORRADE_VERIFY(importer.isOpened()); } +void AbstractImporterTest::debugFeature() { + std::ostringstream out; + + Debug{&out} << AbstractImporter::Feature::OpenData << AbstractImporter::Feature(0xf0); + CORRADE_COMPARE(out.str(), "Trade::AbstractImporter::Feature::OpenData Trade::AbstractImporter::Feature(0xf0)\n"); +} + +void AbstractImporterTest::debugFeatures() { + std::ostringstream out; + + Debug{&out} << (AbstractImporter::Feature::OpenData|AbstractImporter::Feature::OpenState) << AbstractImporter::Features{}; + CORRADE_COMPARE(out.str(), "Trade::AbstractImporter::Feature::OpenData|Trade::AbstractImporter::Feature::OpenState Trade::AbstractImporter::Features{}\n"); +} + }}} CORRADE_TEST_MAIN(Magnum::Trade::Test::AbstractImporterTest)