From 8ce184ef7b138077d170abc9bf0b642ec8a02897 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Vladim=C3=ADr=20Vondru=C5=A1?= Date: Fri, 18 Jan 2013 17:16:01 +0100 Subject: [PATCH] Debug output for AbstractImage::Format and AbstractImage::Type enums. --- src/AbstractImage.cpp | 83 ++++++++++++++++++++++++++++++++++ src/AbstractImage.h | 6 +++ src/Test/AbstractImageTest.cpp | 50 ++++++++++++++++++++ src/Test/CMakeLists.txt | 1 + 4 files changed, 140 insertions(+) create mode 100644 src/Test/AbstractImageTest.cpp diff --git a/src/AbstractImage.cpp b/src/AbstractImage.cpp index d7b4373e4..3cc19a3a2 100644 --- a/src/AbstractImage.cpp +++ b/src/AbstractImage.cpp @@ -119,4 +119,87 @@ std::size_t AbstractImage::pixelSize(Format format, Type type) { return 0; } +Debug operator<<(Debug debug, AbstractImage::Format value) { + switch(value) { + #define _c(value) case AbstractImage::Format::value: return debug << "AbstractImage::Format::" #value; + _c(Red) + #ifndef MAGNUM_TARGET_GLES + _c(Green) + _c(Blue) + #endif + _c(RG) + _c(RGB) + _c(RGBA) + #ifndef MAGNUM_TARGET_GLES + _c(BGR) + #endif + _c(BGRA) + #ifndef MAGNUM_TARGET_GLES2 + _c(RedInteger) + _c(GreenInteger) + _c(BlueInteger) + _c(RGInteger) + _c(RGBInteger) + _c(RGBAInteger) + _c(BGRInteger) + _c(BGRAInteger) + #endif + _c(DepthComponent) + _c(StencilIndex) + _c(DepthStencil) + #undef _c + } + + return debug << "AbstractImage::Format::(invalid)"; +} + +Debug operator<<(Debug debug, AbstractImage::Type value) { + switch(value) { + #define _c(value) case AbstractImage::Type::value: return debug << "AbstractImage::Type::" #value; + _c(UnsignedByte) + #ifndef MAGNUM_TARGET_GLES2 + _c(Byte) + #endif + _c(UnsignedShort) + #ifndef MAGNUM_TARGET_GLES2 + _c(Short) + #endif + _c(UnsignedInt) + #ifndef MAGNUM_TARGET_GLES2 + _c(Int) + #endif + _c(HalfFloat) + _c(Float) + #ifndef MAGNUM_TARGET_GLES2 + _c(UnsignedByte332) + _c(UnsignedByte233Rev) + #endif + _c(UnsignedShort565) + #ifndef MAGNUM_TARGET_GLES + _c(UnsignedShort565Rev) + #endif + _c(UnsignedShort4444) + _c(UnsignedShort4444Rev) + _c(UnsignedShort5551) + _c(UnsignedShort1555Rev) + #ifndef MAGNUM_TARGET_GLES + _c(UnsignedInt8888) + _c(UnsignedInt8888Rev) + _c(UnsignedInt1010102) + #endif + _c(UnsignedInt2101010Rev) + #ifndef MAGNUM_TARGET_GLES2 + _c(UnsignedInt10F11F11FRev) + _c(UnsignedInt5999Rev) + #endif + _c(UnsignedInt248) + #ifndef MAGNUM_TARGET_GLES2 + _c(Float32UnsignedInt248Rev) + #endif + #undef _c + } + + return debug << "AbstractImage::Type::(invalid)"; +} + } diff --git a/src/AbstractImage.h b/src/AbstractImage.h index dfbfbaf65..34a21b9cc 100644 --- a/src/AbstractImage.h +++ b/src/AbstractImage.h @@ -456,6 +456,12 @@ class MAGNUM_EXPORT AbstractImage { inline AbstractImage::~AbstractImage() {} +/** @debugoperator{Magnum::AbstractImage} */ +Debug MAGNUM_EXPORT operator<<(Debug debug, AbstractImage::Format value); + +/** @debugoperator{Magnum::AbstractImage} */ +Debug MAGNUM_EXPORT operator<<(Debug debug, AbstractImage::Type value); + } #endif diff --git a/src/Test/AbstractImageTest.cpp b/src/Test/AbstractImageTest.cpp new file mode 100644 index 000000000..405cf26bf --- /dev/null +++ b/src/Test/AbstractImageTest.cpp @@ -0,0 +1,50 @@ +/* + Copyright © 2010, 2011, 2012 Vladimír Vondruš + + This file is part of Magnum. + + Magnum is free software: you can redistribute it and/or modify + it under the terms of the GNU Lesser General Public License version 3 + only, as published by the Free Software Foundation. + + Magnum is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU Lesser General Public License version 3 for more details. +*/ + +#include +#include + +#include "AbstractImage.h" + +namespace Magnum { namespace Test { + +class AbstractImageTest: public Corrade::TestSuite::Tester { + public: + explicit AbstractImageTest(); + + void debugFormat(); + void debugType(); +}; + +AbstractImageTest::AbstractImageTest() { + addTests(&AbstractImageTest::debugFormat, + &AbstractImageTest::debugType); +} + +void AbstractImageTest::debugFormat() { + std::ostringstream o; + Debug(&o) << AbstractImage::Format::RGBA; + CORRADE_COMPARE(o.str(), "AbstractImage::Format::RGBA\n"); +} + +void AbstractImageTest::debugType() { + std::ostringstream o; + Debug(&o) << AbstractImage::Type::UnsignedShort5551; + CORRADE_COMPARE(o.str(), "AbstractImage::Type::UnsignedShort5551\n"); +} + +}} + +CORRADE_TEST_MAIN(Magnum::Test::AbstractImageTest) diff --git a/src/Test/CMakeLists.txt b/src/Test/CMakeLists.txt index 0bd72dd47..4364e87d3 100644 --- a/src/Test/CMakeLists.txt +++ b/src/Test/CMakeLists.txt @@ -1,3 +1,4 @@ +corrade_add_test(AbstractImageTest AbstractImageTest.cpp LIBRARIES Magnum) corrade_add_test(ArrayTest ArrayTest.cpp) corrade_add_test(ColorTest ColorTest.cpp LIBRARIES MagnumMathTestLib) corrade_add_test(MeshTest MeshTest.cpp LIBRARIES Magnum)