Browse Source

Debug output and configuration parser for Mesh::Primitive.

pull/7/head
Vladimír Vondruš 14 years ago
parent
commit
35d8905790
  1. 51
      src/Mesh.cpp
  2. 24
      src/Mesh.h
  3. 1
      src/Test/CMakeLists.txt
  4. 47
      src/Test/MeshTest.cpp
  5. 32
      src/Test/MeshTest.h

51
src/Mesh.cpp

@ -265,4 +265,55 @@ void Mesh::unbindImplementationDefault() {
void Mesh::unbindImplementationVAO() {}
#ifndef DOXYGEN_GENERATING_OUTPUT
Debug operator<<(Debug debug, Mesh::Primitive value) {
switch(value) {
#define _c(value) case Mesh::Primitive::value: return debug << "Mesh::Primitive::" #value;
_c(Points)
_c(Lines)
_c(LineStrip)
_c(LineLoop)
_c(Triangles)
_c(TriangleStrip)
_c(TriangleFan)
#undef _c
}
return debug << "Mesh::Primitive::(invalid)";
}
#endif
}
namespace Corrade { namespace Utility {
std::string ConfigurationValue<Magnum::Mesh::Primitive>::toString(Magnum::Mesh::Primitive value, ConfigurationValueFlags) {
switch(value) {
#define _c(value) case Magnum::Mesh::Primitive::value: return #value;
_c(Points)
_c(Lines)
_c(LineStrip)
_c(LineLoop)
_c(Triangles)
_c(TriangleStrip)
_c(TriangleFan)
#undef _c
}
return "";
}
Magnum::Mesh::Primitive ConfigurationValue<Magnum::Mesh::Primitive>::fromString(const std::string& stringValue, ConfigurationValueFlags) {
#define _c(value) if(stringValue == #value) return Magnum::Mesh::Primitive::value;
_c(Lines)
_c(LineStrip)
_c(LineLoop)
_c(Triangles)
_c(TriangleStrip)
_c(TriangleFan)
#undef _c
return Magnum::Mesh::Primitive::Points;
}
}}

24
src/Mesh.h

@ -742,6 +742,30 @@ class MAGNUM_EXPORT Mesh {
#endif
};
/** @debugoperator{Magnum::Mesh} */
Debug MAGNUM_EXPORT operator<<(Debug debug, Mesh::Primitive value);
}
namespace Corrade { namespace Utility {
/** @configurationvalue{Magnum::Mesh} */
template<> struct MAGNUM_EXPORT ConfigurationValue<Magnum::Mesh::Primitive> {
/**
* @brief Writes enum value as string
*
* If the value is invalid, returns empty string.
*/
static std::string toString(Magnum::Mesh::Primitive value, ConfigurationValueFlags);
/**
* @brief Reads enum value as string
*
* If the value is invalid, returns @ref Magnum::Mesh::Primitive "Mesh::Primitive::Points".
*/
static Magnum::Mesh::Primitive fromString(const std::string& stringValue, ConfigurationValueFlags);
};
}}
#endif

1
src/Test/CMakeLists.txt

@ -1,4 +1,5 @@
corrade_add_test2(ColorTest ColorTest.cpp LIBRARIES MagnumMathTestLib)
corrade_add_test2(MeshTest MeshTest.cpp LIBRARIES Magnum)
corrade_add_test2(ResourceManagerTest ResourceManagerTest.cpp LIBRARIES MagnumTestLib)
corrade_add_test2(SwizzleTest SwizzleTest.cpp LIBRARIES MagnumMathTestLib)
corrade_add_test2(TypeTraitsTest TypeTraitsTest.cpp LIBRARIES Magnum)

47
src/Test/MeshTest.cpp

@ -0,0 +1,47 @@
/*
Copyright © 2010, 2011, 2012 Vladimír Vondruš <mosra@centrum.cz>
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 "MeshTest.h"
#include <Utility/Configuration.h>
#include "Mesh.h"
CORRADE_TEST_MAIN(Magnum::Test::MeshTest)
using namespace Corrade::Utility;
namespace Magnum { namespace Test {
MeshTest::MeshTest() {
addTests(&MeshTest::debug,
&MeshTest::configuration);
}
void MeshTest::debug() {
std::ostringstream o;
Debug(&o) << Mesh::Primitive::TriangleFan;
CORRADE_COMPARE(o.str(), "Mesh::Primitive::TriangleFan\n");
}
void MeshTest::configuration() {
Configuration c;
c.setValue("primitive", Mesh::Primitive::LineStrip);
CORRADE_COMPARE(c.value<std::string>("primitive"), "LineStrip");
CORRADE_COMPARE(c.value<Mesh::Primitive>("primitive"), Mesh::Primitive::LineStrip);
}
}}

32
src/Test/MeshTest.h

@ -0,0 +1,32 @@
#ifndef Magnum_Test_MeshTest_h
#define Magnum_Test_MeshTest_h
/*
Copyright © 2010, 2011, 2012 Vladimír Vondruš <mosra@centrum.cz>
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 <TestSuite/Tester.h>
namespace Magnum { namespace Test {
class MeshTest: public Corrade::TestSuite::Tester<MeshTest> {
public:
MeshTest();
void debug();
void configuration();
};
}}
#endif
Loading…
Cancel
Save