Browse Source

Preserve space before and after printing Matrix/Vector to Debug output.

Modified unit tests to check that.
vectorfields
Vladimír Vondruš 15 years ago
parent
commit
9f8bb86dbb
  1. 6
      src/Math/Matrix.h
  2. 10
      src/Math/Test/MatrixTest.cpp
  3. 4
      src/Math/Test/VectorTest.cpp
  4. 6
      src/Math/Vector.h

6
src/Math/Matrix.h

@ -233,8 +233,8 @@ template<class T> class Matrix<T, 2> {
#ifndef DOXYGEN_GENERATING_OUTPUT
template<class T, size_t size> Corrade::Utility::Debug operator<<(Corrade::Utility::Debug debug, const Magnum::Math::Matrix<T, size>& value) {
debug.setFlag(Corrade::Utility::Debug::SpaceAfterEachValue, false);
debug << "Matrix(";
debug.setFlag(Corrade::Utility::Debug::SpaceAfterEachValue, false);
for(size_t row = 0; row != size; ++row) {
if(row != 0) debug << ",\n ";
for(size_t col = 0; col != size; ++col) {
@ -242,7 +242,9 @@ template<class T, size_t size> Corrade::Utility::Debug operator<<(Corrade::Utili
debug << value.at(row, col);
}
}
return debug << ')';
debug << ')';
debug.setFlag(Corrade::Utility::Debug::SpaceAfterEachValue, true);
return debug;
}
#endif

10
src/Math/Test/MatrixTest.cpp

@ -247,6 +247,16 @@ void MatrixTest::debug() {
" 5, 4, -1, 4,\n"
" 8, 7, 8, 5,\n"
" 4, 3, 0, 9)\n"));
o.str("");
Debug(&o) << "a" << Matrix4() << "b" << Matrix4();
QCOMPARE(QString::fromStdString(o.str()), QString("a Matrix(1, 0, 0, 0,\n"
" 0, 1, 0, 0,\n"
" 0, 0, 1, 0,\n"
" 0, 0, 0, 1) b Matrix(1, 0, 0, 0,\n"
" 0, 1, 0, 0,\n"
" 0, 0, 1, 0,\n"
" 0, 0, 0, 1)\n"));
}
}}}

4
src/Math/Test/VectorTest.cpp

@ -140,6 +140,10 @@ void VectorTest::debug() {
ostringstream o;
Debug(&o) << Vector4(vec);
QCOMPARE(QString::fromStdString(o.str()), QString("Vector(0.5, 15, 1, 1)\n"));
o.str("");
Debug(&o) << "a" << Vector4() << "b" << Vector4();
QCOMPARE(QString::fromStdString(o.str()), QString("a Vector(0, 0, 0, 0) b Vector(0, 0, 0, 0)\n"));
}
}}}

6
src/Math/Vector.h

@ -179,13 +179,15 @@ template<class T, size_t size> class Vector {
#ifndef DOXYGEN_GENERATING_OUTPUT
template<class T, size_t size> Corrade::Utility::Debug operator<<(Corrade::Utility::Debug debug, const Magnum::Math::Vector<T, size>& value) {
debug.setFlag(Corrade::Utility::Debug::SpaceAfterEachValue, false);
debug << "Vector(";
debug.setFlag(Corrade::Utility::Debug::SpaceAfterEachValue, false);
for(size_t i = 0; i != size; ++i) {
if(i != 0) debug << ", ";
debug << value.at(i);
}
return debug << ')';
debug << ')';
debug.setFlag(Corrade::Utility::Debug::SpaceAfterEachValue, true);
return debug;
}
#endif

Loading…
Cancel
Save